[asterisk-commits] russell: trunk r59260 - in /trunk: ./ channels/chan_iax2.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Mar 27 11:09:00 MST 2007


Author: russell
Date: Tue Mar 27 13:08:59 2007
New Revision: 59260

URL: http://svn.digium.com/view/asterisk?view=rev&rev=59260
Log:
Merged revisions 59259 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4

................
r59259 | russell | 2007-03-27 13:05:46 -0500 (Tue, 27 Mar 2007) | 12 lines

Merged revisions 59258 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2

........
r59258 | russell | 2007-03-27 13:04:02 -0500 (Tue, 27 Mar 2007) | 4 lines

Fix the use of the "sourceaddress" option when "bindaddr" is set to 0.0.0.0
instead of having each interface explicitly listed.
(issue #7874, patch by stevens)

........

................

Modified:
    trunk/   (props changed)
    trunk/channels/chan_iax2.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-1.4-merged' - no diff available.

Modified: trunk/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_iax2.c?view=diff&rev=59260&r1=59259&r2=59260
==============================================================================
--- trunk/channels/chan_iax2.c (original)
+++ trunk/channels/chan_iax2.c Tue Mar 27 13:08:59 2007
@@ -185,6 +185,7 @@
 static int timingfd = -1;				/* Timing file descriptor */
 
 static struct ast_netsock_list *netsock;
+static struct ast_netsock_list *outsock;		/*!< used if sourceaddress specified and bindaddr == INADDR_ANY */
 static int defaultsockfd = -1;
 
 int (*iax2_regfunk)(const char *username, int onoff) = NULL;
@@ -8456,20 +8457,40 @@
 		if (res == 0) {
 			/* ip address valid. */
 			sin.sin_port = htons(port);
-			sock = ast_netsock_find(netsock, &sin);
+			if (!(sock = ast_netsock_find(netsock, &sin)))
+				sock = ast_netsock_find(outsock, &sin);
 			if (sock) {
 				sockfd = ast_netsock_sockfd(sock);
 				nonlocal = 0;
+			} else {
+				unsigned int orig_saddr = sin.sin_addr.s_addr;
+				/* INADDR_ANY matches anyway! */
+				sin.sin_addr.s_addr = INADDR_ANY;
+				if (ast_netsock_find(netsock, &sin)) {
+					sin.sin_addr.s_addr = orig_saddr;
+					sock = ast_netsock_bind(outsock, io, srcaddr, port, tos, socket_read, NULL);
+					if (sock) {
+						sockfd = ast_netsock_sockfd(sock);
+						ast_netsock_unref(sock);
+						nonlocal = 0;
+					} else {
+						nonlocal = 2;
+					}
+				}
 			}
 		}
 	}
 		
 	peer->sockfd = sockfd;
 
-	if (nonlocal) {
+	if (nonlocal == 1) {
 		ast_log(LOG_WARNING, "Non-local or unbound address specified (%s) in sourceaddress for '%s', reverting to default\n",
 			srcaddr, peer->name);
 		return -1;
+        } else if (nonlocal == 2) {
+		ast_log(LOG_WARNING, "Unable to bind to sourceaddress '%s' for '%s', reverting to default\n",
+			srcaddr, peer->name);
+			return -1;
 	} else {
 		if (option_debug)
 			ast_log(LOG_DEBUG, "Using sourceaddress %s for '%s'\n", srcaddr, peer->name);
@@ -9274,7 +9295,16 @@
 			ast_netsock_unref(ns);
 		}
 	}
-	
+	if (reload) {
+		ast_netsock_release(outsock);
+		outsock = ast_netsock_list_alloc();
+		if (!outsock) {
+			ast_log(LOG_ERROR, "Could not allocate outsock list.\n");
+			return -1;
+		}
+		ast_netsock_init(outsock);
+	}
+
 	if (min_reg_expire > max_reg_expire) {
 		ast_log(LOG_WARNING, "Minimum registration interval of %d is more than maximum of %d, resetting minimum to %d\n",
 			min_reg_expire, max_reg_expire, max_reg_expire);
@@ -10142,6 +10172,7 @@
 		usleep(10000);
 	
 	ast_netsock_release(netsock);
+	ast_netsock_release(outsock);
 	for (x=0;x<IAX_MAX_CALLS;x++)
 		if (iaxs[x])
 			iax2_destroy(x);
@@ -10224,9 +10255,17 @@
 		sched_context_destroy(sched);
 		return AST_MODULE_LOAD_FAILURE;
 	}
-
 	ast_netsock_init(netsock);
 	
+	outsock = ast_netsock_list_alloc();
+	if (!outsock) {
+		ast_log(LOG_ERROR, "Could not allocate outsock list.\n");
+		io_context_destroy(io);
+		sched_context_destroy(sched);
+		return AST_MODULE_LOAD_FAILURE;
+	}
+	ast_netsock_init(outsock);
+
 	ast_cli_register_multiple(cli_iax2, sizeof(cli_iax2) / sizeof(struct ast_cli_entry));
 
 	ast_register_application(papp, iax2_prov_app, psyn, pdescrip);



More information about the asterisk-commits mailing list