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

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Dec 14 06:10:37 CST 2012


Author: oej
Date: Fri Dec 14 06:10:32 2012
New Revision: 378022

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=378022
Log:
Resetting branch to the current state of review 1471

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

Modified: team/oej/pine-multiple-externip-trunk/CHANGES
URL: http://svnview.digium.com/svn/asterisk/team/oej/pine-multiple-externip-trunk/CHANGES?view=diff&rev=378022&r1=378021&r2=378022
==============================================================================
--- team/oej/pine-multiple-externip-trunk/CHANGES (original)
+++ team/oej/pine-multiple-externip-trunk/CHANGES Fri Dec 14 06:10:32 2012
@@ -329,6 +329,7 @@
    name field if CID number exists without a CID name. This change improves
    compatibility with certain device features such as Avaya IP500's directory
    lookup service.
+ * Externaddr is now a valid setting for SIP devices in sip.conf
 
  * A new setting for autocreatepeer (autocreatepeer=persistent) allows peers
    created using that setting to not be removed during SIP reload.

Modified: team/oej/pine-multiple-externip-trunk/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/pine-multiple-externip-trunk/channels/chan_sip.c?view=diff&rev=378022&r1=378021&r2=378022
==============================================================================
--- team/oej/pine-multiple-externip-trunk/channels/chan_sip.c (original)
+++ team/oej/pine-multiple-externip-trunk/channels/chan_sip.c Fri Dec 14 06:10:32 2012
@@ -3948,6 +3948,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:
@@ -3969,14 +3974,14 @@
 	ast_sockaddr_copy(&theirs, them);
 
 	if (ast_sockaddr_is_ipv6(&theirs)) {
-		if (localaddr && !ast_sockaddr_isnull(&externaddr) && !ast_sockaddr_is_any(&bindaddr)) {
+		if (localaddr && !ast_sockaddr_isnull(myexternaddr) && !ast_sockaddr_is_any(&bindaddr)) {
 			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");
 		}
 	} else {
 		want_remap = localaddr &&
-			!ast_sockaddr_isnull(&externaddr) &&
+			!ast_sockaddr_isnull(myexternaddr) &&
 			ast_apply_ha(localaddr, &theirs) == AST_SENSE_ALLOW ;
 	}
 
@@ -3989,13 +3994,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;
@@ -4003,7 +4008,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;
@@ -4011,8 +4016,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 {
 		/* no remapping, but we bind to a specific address, so use it. */
 		switch (p->socket.type) {
@@ -6125,6 +6130,12 @@
 	}
 	if (!dialog->portinuri) {
 		dialog->portinuri = peer->portinuri;
+	}
+	if (!ast_sockaddr_isnull(&peer->externaddr)) {
+		/* Use the peer externaddr first */
+		ast_sockaddr_copy(&dialog->externaddr, &peer->externaddr);
+	} else {
+		ast_sockaddr_copy(&dialog->externaddr, &externaddr);
 	}
 	dialog->chanvars = copy_vars(peer->chanvars);
 	if (peer->fromdomainport) {
@@ -18084,6 +18095,12 @@
 			ao2_t_ref(peer, 1, "copy pointer into (*authpeer)");
 			(*authpeer) = peer;	/* Add a ref to the object here, to keep it in memory a bit longer if it is realtime */
 		}
+		/* Check if we have externip setting for this peer. If so, reset our address */
+		if (!ast_sockaddr_isnull(&peer->externaddr)) {
+			ast_sockaddr_copy(&p->externaddr, &peer->externaddr);
+			/* Recalculate our side, and recalculate Call ID */
+			ast_sip_ouraddrfor(&p->sa, &p->ourip, p);
+		} 
 
 		if (!ast_strlen_zero(peer->username)) {
 			ast_string_field_set(p, username, peer->username);
@@ -29390,6 +29407,12 @@
 		ast_string_field_set(p, tohost, ast_sockaddr_stringify_host_remote(&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);
@@ -30453,6 +30476,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")) {
@@ -31679,7 +31710,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/oej/pine-multiple-externip-trunk/channels/sip/include/sip.h
URL: http://svnview.digium.com/svn/asterisk/team/oej/pine-multiple-externip-trunk/channels/sip/include/sip.h?view=diff&rev=378022&r1=378021&r2=378022
==============================================================================
--- team/oej/pine-multiple-externip-trunk/channels/sip/include/sip.h (original)
+++ team/oej/pine-multiple-externip-trunk/channels/sip/include/sip.h Fri Dec 14 06:10:32 2012
@@ -1129,6 +1129,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 */
@@ -1371,6 +1372,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;
 
 	struct ast_rtp_dtls_cfg dtls_cfg;

Modified: team/oej/pine-multiple-externip-trunk/configs/sip.conf.sample
URL: http://svnview.digium.com/svn/asterisk/team/oej/pine-multiple-externip-trunk/configs/sip.conf.sample?view=diff&rev=378022&r1=378021&r2=378022
==============================================================================
--- team/oej/pine-multiple-externip-trunk/configs/sip.conf.sample (original)
+++ team/oej/pine-multiple-externip-trunk/configs/sip.conf.sample Fri Dec 14 06:10:32 2012
@@ -829,11 +829,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:
 ;
@@ -1227,6 +1232,7 @@
 ; keepalive
 ; defaultip
 ; defaultuser
+; externaddr
 ; rtptimeout
 ; rtpholdtimeout
 ; sendrpid




More information about the svn-commits mailing list