[svn-commits] oej: branch group/pine-multiple-externip-trunk r288959 - in /team/group/pine-...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Sep 27 13:31:18 CDT 2010


Author: oej
Date: Mon Sep 27 13:31:12 2010
New Revision: 288959

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=288959
Log:
...and the trunk version made in air between France and Sweden...

Modified:
    team/group/pine-multiple-externip-trunk/channels/chan_sip.c
    team/group/pine-multiple-externip-trunk/channels/sip/include/sip.h
    team/group/pine-multiple-externip-trunk/configs/sip.conf.sample

Modified: team/group/pine-multiple-externip-trunk/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/group/pine-multiple-externip-trunk/channels/chan_sip.c?view=diff&rev=288959&r1=288958&r2=288959
==============================================================================
--- team/group/pine-multiple-externip-trunk/channels/chan_sip.c (original)
+++ team/group/pine-multiple-externip-trunk/channels/chan_sip.c Mon Sep 27 13:31:12 2010
@@ -3166,6 +3166,11 @@
 static void ast_sip_ouraddrfor(const struct ast_sockaddr *them, struct ast_sockaddr *us, struct sip_pvt *p)
 {
 	struct ast_sockaddr theirs;
+	struct ast_sockaddr *myexternaddr;
+
+	/* Pick which externaddr to use. If the dialog has one configured, use it.
+	   Otherwise, use the default one. */
+	myexternaddr = !ast_sockaddr_isnull(&p->externaddr) ? &p->externaddr : &externaddr;
 
 	/* Set want_remap to non-zero if we want to remap 'us' to an externally
 	 * reachable IP address and port. This is done if:
@@ -3187,14 +3192,15 @@
 	ast_sockaddr_copy(&theirs, them);
 
 	if (ast_sockaddr_is_ipv6(&theirs)) {
-		if (localaddr && !ast_sockaddr_isnull(&externaddr)) {
+		if (localaddr && !ast_sockaddr_isnull(myexternaddr)) {
 			ast_log(LOG_WARNING, "Address remapping activated in sip.conf "
 				"but we're using IPv6, which doesn't need it. Please "
 				"remove \"localnet\" and/or \"externaddr\" settings.\n");
+				/* THIS IS VERY, VERY WRONG as IPv6 includes IPv4. */
 		}
 	} else {
 		want_remap = localaddr &&
-			!ast_sockaddr_isnull(&externaddr) &&
+			!ast_sockaddr_isnull(myexternaddr) &&
 			ast_apply_ha(localaddr, &theirs) == AST_SENSE_ALLOW ;
 	}
 
@@ -3207,13 +3213,13 @@
 			}
 			externexpire = time(NULL) + externrefresh;
 		}
-		if (!ast_sockaddr_isnull(&externaddr)) {
-			ast_sockaddr_copy(us, &externaddr);
+		if (!ast_sockaddr_isnull(myexternaddr)) {
+			ast_sockaddr_copy(us, myexternaddr);
 			switch (p->socket.type) {
 			case SIP_TRANSPORT_TCP:
-				if (!externtcpport && ast_sockaddr_port(&externaddr)) {
+				if (!externtcpport && ast_sockaddr_port(myexternaddr)) {
 					/* for consistency, default to the externaddr port */
-					externtcpport = ast_sockaddr_port(&externaddr);
+					externtcpport = ast_sockaddr_port(myexternaddr);
 				}
 				ast_sockaddr_set_port(us, externtcpport);
 				break;
@@ -3221,7 +3227,7 @@
 				ast_sockaddr_set_port(us, externtlsport);
 				break;
 			case SIP_TRANSPORT_UDP:
-				if (!ast_sockaddr_port(&externaddr)) {
+				if (!ast_sockaddr_port(myexternaddr)) {
 					ast_sockaddr_set_port(us, ast_sockaddr_port(&bindaddr));
 				}
 				break;
@@ -3229,8 +3235,8 @@
 				break;
 			}
 		}
-		ast_debug(1, "Target address %s is not local, substituting externaddr\n",
-			  ast_sockaddr_stringify(them));
+		ast_debug(1, "Target address %s is not local, substituting to externaddr %s\n",
+			  ast_sockaddr_stringify(them), ast_sockaddr_stringify(myexternaddr));
 	} else if (p) {
 		/* no remapping, but we bind to a specific address, so use it. */
 		switch (p->socket.type) {
@@ -4966,6 +4972,11 @@
 		ast_set_flag(&dialog->flags[0], SIP_CALL_LIMIT);
 	if (!dialog->portinuri)
 		dialog->portinuri = peer->portinuri;
+	if (!ast_sockaddr_isnull(&peer->externaddr)) {
+		ast_sockaddr_copy(&dialog->externaddr, &peer->externaddr);
+	} else {
+		ast_sockaddr_copy(&dialog->externaddr, &externaddr);
+	}
 	dialog->chanvars = copy_vars(peer->chanvars);
 	if (peer->fromdomainport)
 		dialog->fromdomainport = peer->fromdomainport;
@@ -16991,7 +17002,7 @@
 		msg = "Enabled using externaddr";
 	ast_cli(a->fd, "  SIP address remapping:  %s\n", msg);
 	ast_cli(a->fd, "  Externhost:             %s\n", S_OR(externhost, "<none>"));
-	ast_cli(a->fd, "  externaddr:               %s\n", ast_sockaddr_stringify(&externaddr));
+	ast_cli(a->fd, "  Externaddr:             %s\n", ast_sockaddr_stringify(&externaddr));
 	ast_cli(a->fd, "  Externrefresh:          %d\n", externrefresh);
 	{
 		struct ast_ha *d;
@@ -24863,6 +24874,12 @@
 	else
 		ast_string_field_set(p, tohost, ast_sockaddr_stringify_host(&peer->addr));
 
+	if (!ast_sockaddr_isnull(&peer->externaddr)) {
+		ast_sockaddr_copy(&p->externaddr, &peer->externaddr);
+	} else {
+		ast_sockaddr_copy(&p->externaddr, &externaddr);
+	}
+
 	/* Recalculate our side, and recalculate Call ID */
 	ast_sip_ouraddrfor(&p->sa, &p->ourip, p);
 	build_via(p);
@@ -25835,6 +25852,14 @@
 
 					if (!peer->default_outbound_transport) { /*!< The first transport listed should be default outbound */
 						peer->default_outbound_transport = peer->transports;
+					}
+				}
+			} else if (!strcasecmp(v->name, "externaddr")) {
+				if (localaddr == NULL) {
+					ast_log(LOG_ERROR, "Externaddr for peer %s not enabled, since we have no local networks configured in [general]\n", peer->name);
+				} else {
+					if (!ast_strlen_zero(v->value) && ast_parse_arg(v->value, PARSE_ADDR, &peer->externaddr)) {
+						ast_log(LOG_WARNING, "Invalid address for externaddr keyword: %s for peer %s\n", v->value, peer->name);
 					}
 				}
 			} else if (realtime && !strcasecmp(v->name, "regseconds")) {
@@ -26915,7 +26940,7 @@
 			if (ast_parse_arg(v->value, PARSE_ADDR, &media_address))
 				ast_log(LOG_WARNING, "Invalid address for media_address keyword: %s\n", v->value);
 		} else if (!strcasecmp(v->name, "externaddr") || !strcasecmp(v->name, "externip")) {
-			if (ast_parse_arg(v->value, PARSE_ADDR, &externaddr)) {
+			if (!ast_strlen_zero(v->value) && ast_parse_arg(v->value, PARSE_ADDR, &externaddr)) {
 				ast_log(LOG_WARNING,
 					"Invalid address for externaddr keyword: %s\n",
 					v->value);

Modified: team/group/pine-multiple-externip-trunk/channels/sip/include/sip.h
URL: http://svnview.digium.com/svn/asterisk/team/group/pine-multiple-externip-trunk/channels/sip/include/sip.h?view=diff&rev=288959&r1=288958&r2=288959
==============================================================================
--- team/group/pine-multiple-externip-trunk/channels/sip/include/sip.h (original)
+++ team/group/pine-multiple-externip-trunk/channels/sip/include/sip.h Mon Sep 27 13:31:12 2010
@@ -1013,6 +1013,7 @@
 	struct ast_sockaddr redirip;         /*!< Where our RTP should be going if not to us */
 	struct ast_sockaddr vredirip;        /*!< Where our Video RTP should be going if not to us */
 	struct ast_sockaddr tredirip;        /*!< Where our Text RTP should be going if not to us */
+	struct ast_sockaddr externaddr;        /*!<  External IP to use for this dialog */
 	time_t lastrtprx;                   /*!< Last RTP received */
 	time_t lastrtptx;                   /*!< Last RTP sent */
 	int rtptimeout;                     /*!< RTP timeout time */
@@ -1236,6 +1237,7 @@
 	/*XXX Seems like we suddenly have two flags with the same content. Why? To be continued... */
 	enum sip_peer_type type; /*!< Distinguish between "user" and "peer" types. This is used solely for CLI and manager commands */
 	unsigned int disallowed_methods;
+	struct ast_sockaddr externaddr;        /*!<  External IP to use for peer's connections */
 	struct ast_cc_config_params *cc_params;
 };
 

Modified: team/group/pine-multiple-externip-trunk/configs/sip.conf.sample
URL: http://svnview.digium.com/svn/asterisk/team/group/pine-multiple-externip-trunk/configs/sip.conf.sample?view=diff&rev=288959&r1=288958&r2=288959
==============================================================================
--- team/group/pine-multiple-externip-trunk/configs/sip.conf.sample (original)
+++ team/group/pine-multiple-externip-trunk/configs/sip.conf.sample Mon Sep 27 13:31:12 2010
@@ -731,11 +731,16 @@
 ;                               ; externtcpport will default to the externaddr or externhost port if either one is set. 
 ;        externtlsport = 12600  ; The externally mapped tls port, when Asterisk is behind a static NAT or PAT.
 ;                               ; externtlsport port will default to the RFC designated port of 5061.	
+
+; 	The externaddr configuration is also valid for specific peers and is only
+;	used for IPv4 connections. The device configuration overrides the one in the
+;	[general] section of sip.conf
 ;
 ;   b. "externhost = hostname[:port]" is similar to "externaddr" except
 ;      that the hostname is looked up every "externrefresh" seconds
 ;      (default 10s). This can be useful when your NAT device lets you choose
 ;      the port mapping, but the IP address is dynamic.
+;      "externhost" ONLY works in the [general] section of sip.conf.
 ;      Beware, you might suffer from service disruption when the name server
 ;      resolution fails. Examples:
 ;
@@ -1068,6 +1073,7 @@
 ; qualify
 ; defaultip
 ; defaultuser
+; externaddr
 ; rtptimeout
 ; rtpholdtimeout
 ; sendrpid




More information about the svn-commits mailing list