[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
Mon Feb 27 15:02:18 CST 2012
Author: seanbright
Date: Mon Feb 27 15:02:14 2012
New Revision: 357084
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=357084
Log:
Convert peercnts over to ast_sockaddr. Also add AST_SOCKADDR_INIT_VALUE, which I'll
be happy to revert if there is a better way to (quoting from netsock2.h): "always
initialize ast_sockaddr before use."
Modified:
team/seanbright/the_ipv6ification_of_chan_iax2_by_the_coward_sean_bright/channels/chan_iax2.c
team/seanbright/the_ipv6ification_of_chan_iax2_by_the_coward_sean_bright/include/asterisk/netsock2.h
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=357084&r1=357083&r2=357084
==============================================================================
--- 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 Mon Feb 27 15:02:14 2012
@@ -912,7 +912,7 @@
* consumed by a single ip address */
struct peercnt {
/*! ip address consuming call numbers */
- unsigned long addr;
+ struct ast_sockaddr addr;
/*! Number of call numbers currently used by this ip address */
uint16_t cur;
/*! Max call numbers allowed for this ip address */
@@ -2201,28 +2201,25 @@
static int peercnt_hash_cb(const void *obj, const int flags)
{
const struct peercnt *peercnt = obj;
- return abs((int) peercnt->addr);
+ return ast_sockaddr_hash(&peercnt->addr);
}
static int peercnt_cmp_cb(void *obj, void *arg, int flags)
{
struct peercnt *peercnt1 = obj, *peercnt2 = arg;
- return (peercnt1->addr == peercnt2->addr) ? CMP_MATCH | CMP_STOP : 0;
+ return ast_sockaddr_cmp_addr(&peercnt1->addr, &peercnt2->addr) ? 0 : CMP_MATCH | CMP_STOP;
}
static int addr_range_match_address_cb(void *obj, void *arg, int flags)
{
struct addr_range *addr_range = obj;
- struct sockaddr_in *sin = arg;
- struct sockaddr_in ha_netmask_sin;
- struct sockaddr_in ha_addr_sin;
-
- ast_sockaddr_to_sin(&addr_range->ha.netmask, &ha_netmask_sin);
- ast_sockaddr_to_sin(&addr_range->ha.addr, &ha_addr_sin);
-
- if ((sin->sin_addr.s_addr & ha_netmask_sin.sin_addr.s_addr) == ha_addr_sin.sin_addr.s_addr) {
+ struct ast_sockaddr *addr = arg;
+
+ /* SRB: Test this */
+ if (ast_apply_ha(&addr_range->ha, addr) == AST_SENSE_ALLOW) {
return CMP_MATCH | CMP_STOP;
}
+
return 0;
}
@@ -2294,18 +2291,14 @@
{
uint16_t limit = global_maxcallno;
struct addr_range *addr_range;
- struct sockaddr_in sin = {
- .sin_addr.s_addr = peercnt->addr,
- };
-
if (peercnt->reg && peercnt->limit) {
return; /* this peercnt has a custom limit set by a registration */
}
- if ((addr_range = ao2_callback(callno_limits, 0, addr_range_match_address_cb, &sin))) {
+ if ((addr_range = ao2_callback(callno_limits, 0, addr_range_match_address_cb, &peercnt->addr))) {
limit = addr_range->limit;
- ast_debug(1, "custom addr_range %d found for %s\n", limit, ast_inet_ntoa(sin.sin_addr));
+ ast_debug(1, "custom addr_range %d found for %s\n", limit, ast_sockaddr_stringify_addr(&peercnt->addr));
ao2_ref(addr_range, -1);
}
@@ -2346,13 +2339,10 @@
/* this function turns off and on custom callno limits set by peer registration */
struct peercnt *peercnt;
struct peercnt tmp = {
- .addr = 0,
+ .addr = AST_SOCKADDR_INIT_VALUE
};
- struct sockaddr_in sin;
-
- ast_sockaddr_to_sin(sockaddr, &sin);
-
- tmp.addr = sin.sin_addr.s_addr;
+
+ ast_sockaddr_copy(&tmp.addr, sockaddr);
if ((peercnt = ao2_find(peercnts, &tmp, OBJ_POINTER))) {
peercnt->reg = reg;
@@ -2361,7 +2351,10 @@
} else {
set_peercnt_limit(peercnt);
}
- ast_debug(1, "peercnt entry %s modified limit:%d registered:%d", ast_inet_ntoa(sin.sin_addr), peercnt->limit, peercnt->reg);
+ ast_debug(1, "peercnt entry %s modified limit:%d registered:%d",
+ ast_sockaddr_stringify_addr(&peercnt->addr),
+ peercnt->limit,
+ peercnt->reg);
ao2_ref(peercnt, -1); /* decrement ref from find */
}
}
@@ -2377,11 +2370,12 @@
static int peercnt_add(struct sockaddr_in *sin)
{
struct peercnt *peercnt;
- unsigned long addr = sin->sin_addr.s_addr;
int res = 0;
struct peercnt tmp = {
- .addr = addr,
+ .addr = AST_SOCKADDR_INIT_VALUE,
};
+
+ ast_sockaddr_from_sin(&tmp.addr, sin);
/* Reasoning for peercnts container lock: Two identical ip addresses
* could be added by different threads at the "same time". Without the container
@@ -2395,7 +2389,7 @@
} else if ((peercnt = ao2_alloc(sizeof(*peercnt), NULL))) {
ao2_lock(peercnt);
/* create and set defaults */
- peercnt->addr = addr;
+ ast_sockaddr_copy(&peercnt->addr, &tmp.addr);
set_peercnt_limit(peercnt);
/* guarantees it does not go away after unlocking table
* ao2_find automatically adds this */
@@ -2408,9 +2402,13 @@
/* check to see if the address has hit its callno limit. If not increment cur. */
if (peercnt->limit > peercnt->cur) {
peercnt->cur++;
- ast_debug(1, "ip callno count incremented to %d for %s\n", peercnt->cur, ast_inet_ntoa(sin->sin_addr));
+ ast_debug(1, "ip callno count incremented to %d for %s\n",
+ peercnt->cur,
+ ast_sockaddr_stringify_addr(&peercnt->addr));
} else { /* max num call numbers for this peer has been reached! */
- ast_log(LOG_ERROR, "maxcallnumber limit of %d for %s has been reached!\n", peercnt->limit, ast_inet_ntoa(sin->sin_addr));
+ ast_log(LOG_ERROR, "maxcallnumber limit of %d for %s has been reached!\n",
+ peercnt->limit,
+ ast_sockaddr_stringify_addr(&peercnt->addr));
res = -1;
}
@@ -2428,17 +2426,15 @@
*/
static void peercnt_remove(struct peercnt *peercnt)
{
- struct sockaddr_in sin = {
- .sin_addr.s_addr = peercnt->addr,
- };
-
if (peercnt) {
/* Container locked here since peercnt may be unlinked from list. If left unlocked,
* peercnt_add could try and grab this entry from the table and modify it at the
* "same time" this thread attemps to unlink it.*/
ao2_lock(peercnts);
peercnt->cur--;
- ast_debug(1, "ip callno count decremented to %d for %s\n", peercnt->cur, ast_inet_ntoa(sin.sin_addr));
+ ast_debug(1, "ip callno count decremented to %d for %s\n",
+ peercnt->cur,
+ ast_sockaddr_stringify_addr(&peercnt->addr));
/* if this was the last connection from the peer remove it from table */
if (peercnt->cur == 0) {
ao2_unlink(peercnts, peercnt);/* decrements ref from table, last ref is left to scheduler */
@@ -2469,8 +2465,10 @@
{
struct peercnt *peercnt;
struct peercnt tmp = {
- .addr = sin->sin_addr.s_addr,
+ .addr = AST_SOCKADDR_INIT_VALUE
};
+
+ ast_sockaddr_from_sin(&tmp.addr, sin);
if ((peercnt = ao2_find(peercnts, &tmp, OBJ_POINTER))) {
peercnt_remove(peercnt);
@@ -2583,7 +2581,6 @@
{
struct ao2_iterator i;
struct peercnt *peercnt;
- struct sockaddr_in sin;
int found = 0;
switch (cmd) {
@@ -2605,17 +2602,17 @@
i = ao2_iterator_init(peercnts, 0);
while ((peercnt = ao2_iterator_next(&i))) {
- sin.sin_addr.s_addr = peercnt->addr;
if (a->argc == 5) {
- if (!strcasecmp(a->argv[4], ast_inet_ntoa(sin.sin_addr))) {
+ /* SRB: Make the formatting smarter depending on the length of address */
+ if (!strcasecmp(a->argv[4], ast_sockaddr_stringify_addr(&peercnt->addr))) {
ast_cli(a->fd, "%-15s %-12s %-12s\n", "Address", "Callno Usage", "Callno Limit");
- ast_cli(a->fd, "%-15s %-12d %-12d\n", ast_inet_ntoa(sin.sin_addr), peercnt->cur, peercnt->limit);
+ ast_cli(a->fd, "%-15s %-12d %-12d\n", ast_sockaddr_stringify_addr(&peercnt->addr), peercnt->cur, peercnt->limit);
ao2_ref(peercnt, -1);
found = 1;
break;
}
} else {
- ast_cli(a->fd, "%-15s %-12d %-12d\n", ast_inet_ntoa(sin.sin_addr), peercnt->cur, peercnt->limit);
+ ast_cli(a->fd, "%-15s %-12d %-12d\n", ast_sockaddr_stringify_addr(&peercnt->addr), peercnt->cur, peercnt->limit);
}
ao2_ref(peercnt, -1);
}
@@ -2758,12 +2755,16 @@
int i;
struct peercnt *peercnt;
struct peercnt tmp = {
- .addr = sin->sin_addr.s_addr,
+ .addr = AST_SOCKADDR_INIT_VALUE,
};
+
+ ast_sockaddr_from_sin(&tmp.addr, sin);
if ((peercnt = ao2_find(peercnts, &tmp, OBJ_POINTER))) {
/* refcount is incremented with ao2_find. keep that ref for the scheduler */
- ast_debug(1, "schedule decrement of callno used for %s in %d seconds\n", ast_inet_ntoa(sin->sin_addr), MIN_REUSE_TIME);
+ ast_debug(1, "schedule decrement of callno used for %s in %d seconds\n",
+ ast_sockaddr_stringify_addr(&peercnt->addr),
+ MIN_REUSE_TIME);
i = iax2_sched_add(sched, MIN_REUSE_TIME * 1000, peercnt_remove_cb, peercnt);
if (i == -1) {
ao2_ref(peercnt, -1);
Modified: team/seanbright/the_ipv6ification_of_chan_iax2_by_the_coward_sean_bright/include/asterisk/netsock2.h
URL: http://svnview.digium.com/svn/asterisk/team/seanbright/the_ipv6ification_of_chan_iax2_by_the_coward_sean_bright/include/asterisk/netsock2.h?view=diff&rev=357084&r1=357083&r2=357084
==============================================================================
--- team/seanbright/the_ipv6ification_of_chan_iax2_by_the_coward_sean_bright/include/asterisk/netsock2.h (original)
+++ team/seanbright/the_ipv6ification_of_chan_iax2_by_the_coward_sean_bright/include/asterisk/netsock2.h Mon Feb 27 15:02:14 2012
@@ -64,6 +64,8 @@
struct sockaddr_storage ss;
socklen_t len;
};
+
+#define AST_SOCKADDR_INIT_VALUE { { 0 } }
/*!
* \brief
More information about the asterisk-commits
mailing list