[asterisk-commits] seanbright: branch seanbright/the_ipv6ification_of_chan_iax2_by_the_coward_se...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Feb 28 10:05:04 CST 2012
Author: seanbright
Date: Tue Feb 28 10:04:59 2012
New Revision: 357260
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=357260
Log:
Update realtime_peer and realtime_user.
Modified:
team/seanbright/the_ipv6ification_of_chan_iax2_by_the_coward_sean_bright/channels/chan_iax2.c
Modified: team/seanbright/the_ipv6ification_of_chan_iax2_by_the_coward_sean_bright/channels/chan_iax2.c
URL: http://svnview.digium.com/svn/asterisk/team/seanbright/the_ipv6ification_of_chan_iax2_by_the_coward_sean_bright/channels/chan_iax2.c?view=diff&rev=357260&r1=357259&r2=357260
==============================================================================
--- team/seanbright/the_ipv6ification_of_chan_iax2_by_the_coward_sean_bright/channels/chan_iax2.c (original)
+++ team/seanbright/the_ipv6ification_of_chan_iax2_by_the_coward_sean_bright/channels/chan_iax2.c Tue Feb 28 10:04:59 2012
@@ -975,8 +975,8 @@
static AST_LIST_HEAD_STATIC(dpcache, iax2_dpcache);
static void reg_source_db(struct iax2_peer *p);
-static struct iax2_peer *realtime_peer(const char *peername, struct sockaddr_in *sin);
-static struct iax2_user *realtime_user(const char *username, struct sockaddr_in *sin);
+static struct iax2_peer *realtime_peer(const char *peername, struct ast_sockaddr *addr);
+static struct iax2_user *realtime_user(const char *username, struct ast_sockaddr *addr);
static int ast_cli_netstats(struct mansession *s, int fd, int limit_fmt);
static char *complete_iax2_peers(const char *line, const char *word, int pos, int state, uint64_t flags);
@@ -1817,15 +1817,13 @@
struct iax2_peer *peer = NULL;
int res = 0;
struct ao2_iterator i;
+ struct ast_sockaddr addr = AST_SOCKADDR_INIT_VALUE;
+
+ ast_sockaddr_from_sin(&addr, &sin);
i = ao2_iterator_init(peers, 0);
while ((peer = ao2_iterator_next(&i))) {
- struct sockaddr_in peer_addr;
-
- ast_sockaddr_to_sin(&peer->addr, &peer_addr);
-
- if ((peer_addr.sin_addr.s_addr == sin.sin_addr.s_addr) &&
- (peer_addr.sin_port == sin.sin_port)) {
+ if (!ast_sockaddr_cmp(&peer->addr, &addr)) {
ast_copy_string(host, peer->name, len);
peer_unref(peer);
res = 1;
@@ -1836,7 +1834,7 @@
ao2_iterator_destroy(&i);
if (!peer) {
- peer = realtime_peer(NULL, &sin);
+ peer = realtime_peer(NULL, &addr);
if (peer) {
ast_copy_string(host, peer->name, len);
peer_unref(peer);
@@ -2238,6 +2236,10 @@
int res = 1; /* required by default */
int optional = 0;
enum calltoken_peer_enum calltoken_required = CALLTOKEN_DEFAULT;
+ struct ast_sockaddr addr = AST_SOCKADDR_INIT_VALUE;
+
+ ast_sockaddr_from_sin(&addr, sin);
+
/* There are only two cases in which calltoken validation is not required.
* Case 1. sin falls within the list of address ranges specified in the calltoken optional table and
* the peer definition has not set the requirecalltoken option.
@@ -2253,11 +2255,11 @@
/* ----- Case 2 ----- */
if ((subclass == IAX_COMMAND_NEW) && (user = find_user(find))) {
calltoken_required = user->calltoken_required;
- } else if ((subclass == IAX_COMMAND_NEW) && (user = realtime_user(find, sin))) {
+ } else if ((subclass == IAX_COMMAND_NEW) && (user = realtime_user(find, &addr))) {
calltoken_required = user->calltoken_required;
} else if ((subclass != IAX_COMMAND_NEW) && (peer = find_peer(find, 0))) {
calltoken_required = peer->calltoken_required;
- } else if ((subclass != IAX_COMMAND_NEW) && (peer = realtime_peer(find, sin))) {
+ } else if ((subclass != IAX_COMMAND_NEW) && (peer = realtime_peer(find, &addr))) {
calltoken_required = peer->calltoken_required;
}
@@ -4317,7 +4319,7 @@
* \note This function calls reg_source_db -> iax2_poke_peer -> find_callno,
* so do not call this with a pvt lock held.
*/
-static struct iax2_peer *realtime_peer(const char *peername, struct sockaddr_in *sin)
+static struct iax2_peer *realtime_peer(const char *peername, struct ast_sockaddr *addr)
{
struct ast_variable *var = NULL;
struct ast_variable *tmp;
@@ -4327,12 +4329,10 @@
if (peername) {
var = ast_load_realtime("iaxpeers", "name", peername, "host", "dynamic", SENTINEL);
- if (!var && sin)
- var = ast_load_realtime("iaxpeers", "name", peername, "host", ast_inet_ntoa(sin->sin_addr), SENTINEL);
- } else if (sin) {
- char porta[25];
- sprintf(porta, "%d", ntohs(sin->sin_port));
- var = ast_load_realtime("iaxpeers", "ipaddr", ast_inet_ntoa(sin->sin_addr), "port", porta, SENTINEL);
+ if (!var && addr)
+ var = ast_load_realtime("iaxpeers", "name", peername, "host", ast_sockaddr_stringify_addr(addr), SENTINEL);
+ } else if (addr) {
+ var = ast_load_realtime("iaxpeers", "ipaddr", ast_sockaddr_stringify_addr(addr), "port", ast_sockaddr_stringify_port(addr), SENTINEL);
if (var) {
/* We'll need the peer name in order to build the structure! */
for (tmp = var; tmp; tmp = tmp->next) {
@@ -4349,12 +4349,20 @@
* is because we only have the IP address and the host field might be
* set as a name (and the reverse PTR might not match).
*/
- if (var && sin) {
+ if (var && addr) {
for (tmp = var; tmp; tmp = tmp->next) {
if (!strcasecmp(tmp->name, "host")) {
- struct ast_hostent ahp;
- struct hostent *hp;
- if (!(hp = ast_gethostbyname(tmp->value, &ahp)) || (memcmp(hp->h_addr, &sin->sin_addr, sizeof(hp->h_addr)))) {
+ struct ast_sockaddr *addrs;
+ int num_addrs = 0, i = 0;
+ if ((num_addrs = ast_sockaddr_resolve(&addrs, tmp->value, 0, AST_AF_UNSPEC))) {
+ for (i = 0; i < num_addrs; i++) {
+ if (!ast_sockaddr_cmp_addr(addr, &addrs[i])) {
+ break;
+ }
+ }
+ ast_free(addrs);
+ }
+ if (i == num_addrs) {
/* No match */
ast_variables_destroy(var);
var = NULL;
@@ -4437,7 +4445,7 @@
return peer;
}
-static struct iax2_user *realtime_user(const char *username, struct sockaddr_in *sin)
+static struct iax2_user *realtime_user(const char *username, struct ast_sockaddr *addr)
{
struct ast_variable *var;
struct ast_variable *tmp;
@@ -4445,13 +4453,11 @@
var = ast_load_realtime("iaxusers", "name", username, "host", "dynamic", SENTINEL);
if (!var)
- var = ast_load_realtime("iaxusers", "name", username, "host", ast_inet_ntoa(sin->sin_addr), SENTINEL);
- if (!var && sin) {
- char porta[6];
- snprintf(porta, sizeof(porta), "%d", ntohs(sin->sin_port));
- var = ast_load_realtime("iaxusers", "name", username, "ipaddr", ast_inet_ntoa(sin->sin_addr), "port", porta, SENTINEL);
+ var = ast_load_realtime("iaxusers", "name", username, "host", ast_sockaddr_stringify_addr(addr), SENTINEL);
+ if (!var && addr) {
+ var = ast_load_realtime("iaxusers", "name", username, "ipaddr", ast_sockaddr_stringify_addr(addr), "port", ast_sockaddr_stringify_port(addr), SENTINEL);
if (!var)
- var = ast_load_realtime("iaxusers", "ipaddr", ast_inet_ntoa(sin->sin_addr), "port", porta, SENTINEL);
+ var = ast_load_realtime("iaxusers", "ipaddr", ast_sockaddr_stringify_addr(addr), "port", ast_sockaddr_stringify_port(addr), SENTINEL);
}
if (!var) { /* Last ditch effort */
var = ast_load_realtime("iaxusers", "name", username, SENTINEL);
@@ -4464,9 +4470,17 @@
if (var) {
for (tmp = var; tmp; tmp = tmp->next) {
if (!strcasecmp(tmp->name, "host")) {
- struct ast_hostent ahp;
- struct hostent *hp;
- if (!(hp = ast_gethostbyname(tmp->value, &ahp)) || (memcmp(hp->h_addr, &sin->sin_addr, sizeof(hp->h_addr)))) {
+ struct ast_sockaddr *addrs;
+ int num_addrs = 0, i = 0;
+ if ((num_addrs = ast_sockaddr_resolve(&addrs, tmp->value, 0, AST_AF_UNSPEC))) {
+ for (i = 0; i < num_addrs; i++) {
+ if (!ast_sockaddr_cmp_addr(addr, &addrs[i])) {
+ break;
+ }
+ }
+ ast_free(addrs);
+ }
+ if (i == num_addrs) {
/* No match */
ast_variables_destroy(var);
var = NULL;
@@ -7673,7 +7687,7 @@
ao2_iterator_destroy(&i);
user = best;
if (!user && !ast_strlen_zero(iaxs[callno]->username)) {
- user = realtime_user(iaxs[callno]->username, sin);
+ user = realtime_user(iaxs[callno]->username, &addr);
if (user && !ast_strlen_zero(iaxs[callno]->context) && /* No context specified */
!apply_context(user->contexts, iaxs[callno]->context)) { /* Context is permitted */
user = user_unref(user);
More information about the asterisk-commits
mailing list