[asterisk-commits] dvossel: branch 1.8 r282302 - in /branches/1.8: ./ channels/ configs/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Aug 13 17:23:49 CDT 2010


Author: dvossel
Date: Fri Aug 13 17:23:38 2010
New Revision: 282302

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=282302
Log:
remove current STUN support from chan_sip.c

This patch removes the current broken/useless stun
support from chan_sip.

(closes issue #17622)
Reported by: philipp2

Review: https://reviewboard.asterisk.org/r/855/

Modified:
    branches/1.8/CHANGES
    branches/1.8/UPGRADE.txt
    branches/1.8/channels/chan_sip.c
    branches/1.8/configs/sip.conf.sample

Modified: branches/1.8/CHANGES
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/CHANGES?view=diff&rev=282302&r1=282301&r2=282302
==============================================================================
--- branches/1.8/CHANGES (original)
+++ branches/1.8/CHANGES Fri Aug 13 17:23:38 2010
@@ -1101,10 +1101,6 @@
     option is enabled, Asterisk will watch for a CNG tone in the incoming audio
     for a received call.  If it is detected, the channel will jump to the 
     'fax' extension in the dialplan.
-  * Improved NAT and STUN support.
-     chan_sip now can use port numbers in bindaddr, externip and externhost
-     options, as well as contact a STUN server to detect its external address
-     for the SIP socket. See sip.conf.sample, 'NAT' section.
   * The default SIP useragent= identifier now includes the Asterisk version
   * A new option, match_auth_username in sip.conf changes the matching of incoming requests.
      If set, and the incoming request carries authentication info,

Modified: branches/1.8/UPGRADE.txt
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/UPGRADE.txt?view=diff&rev=282302&r1=282301&r2=282302
==============================================================================
--- branches/1.8/UPGRADE.txt (original)
+++ branches/1.8/UPGRADE.txt Fri Aug 13 17:23:38 2010
@@ -108,6 +108,11 @@
 * chan_sip will no longer set up a local call forward when receiving a
   482 Loop Detected response. The dialplan will just continue from where it
   left off.
+
+* The 'stunaddr' option has been removed from chan_sip.  This feature did not
+  behave as expected, had no correct use case, and was not RFC compliant. The
+  removal of this feature will hopefully be followed by a correct RFC compliant
+  STUN implementation in chan_sip in the future.
 
 From 1.6.1 to 1.6.2:
 

Modified: branches/1.8/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/channels/chan_sip.c?view=diff&rev=282302&r1=282301&r2=282302
==============================================================================
--- branches/1.8/channels/chan_sip.c (original)
+++ branches/1.8/channels/chan_sip.c Fri Aug 13 17:23:38 2010
@@ -259,7 +259,6 @@
 #include "asterisk/translate.h"
 #include "asterisk/ast_version.h"
 #include "asterisk/event.h"
-#include "asterisk/stun.h"
 #include "asterisk/cel.h"
 #include "asterisk/data.h"
 #include "asterisk/aoc.h"
@@ -1145,9 +1144,6 @@
  *   hostname is stored in externhost, and the hostname->IP mapping
  *   is refreshed every 'externrefresh' seconds;
  *
- * + with "stunaddr = host[:port]" we run queries every externrefresh seconds
- *   to the specified server, and store the result in externaddr.
- *
  * Other variables (externhost, externexpire, externrefresh) are used
  * to support the above functions.
  */
@@ -1157,7 +1153,6 @@
 static char externhost[MAXHOSTNAMELEN];   /*!< External host name */
 static time_t externexpire;             /*!< Expiration counter for re-resolving external host name in dynamic DNS */
 static int externrefresh = 10;          /*!< Refresh timer for DNS-based external address (dyndns) */
-static struct sockaddr_in stunaddr;     /*!< stun server address */
 static uint16_t externtcpport;          /*!< external tcp port */ 
 static uint16_t externtlsport;          /*!< external tls port */
 
@@ -3116,14 +3111,13 @@
 static void ast_sip_ouraddrfor(const struct ast_sockaddr *them, struct ast_sockaddr *us, struct sip_pvt *p)
 {
 	struct ast_sockaddr theirs;
-	struct sockaddr_in externaddr_sin;
 
 	/* Set want_remap to non-zero if we want to remap 'us' to an externally
 	 * reachable IP address and port. This is done if:
 	 * 1. we have a localaddr list (containing 'internal' addresses marked
 	 *    as 'deny', so ast_apply_ha() will return AST_SENSE_DENY on them,
 	 *    and AST_SENSE_ALLOW on 'external' ones);
-	 * 2. either stunaddr or externaddr is set, so we know what to use as the
+	 * 2. externaddr is set, so we know what to use as the
 	 *    externally visible address;
 	 * 3. the remote address, 'them', is external;
 	 * 4. the address returned by ast_ouraddrfor() is 'internal' (AST_SENSE_DENY
@@ -3145,22 +3139,16 @@
 		}
 	} else {
 		want_remap = localaddr &&
-			!(ast_sockaddr_isnull(&externaddr) && stunaddr.sin_addr.s_addr) &&
+			!ast_sockaddr_isnull(&externaddr) &&
 			ast_apply_ha(localaddr, &theirs) == AST_SENSE_ALLOW ;
 	}
 
 	if (want_remap &&
 	    (!sip_cfg.matchexternaddrlocally || !ast_apply_ha(localaddr, us)) ) {
-		/* if we used externhost or stun, see if it is time to refresh the info */
+		/* if we used externhost, see if it is time to refresh the info */
 		if (externexpire && time(NULL) >= externexpire) {
-			if (stunaddr.sin_addr.s_addr) {
-				ast_sockaddr_to_sin(&externaddr, &externaddr_sin);
-				ast_stun_request(sipsock, &stunaddr, NULL, &externaddr_sin);
-			} else {
-				if (ast_sockaddr_resolve_first(&externaddr, externhost, 0)) {
-					ast_log(LOG_NOTICE, "Warning: Re-lookup of '%s' failed!\n", externhost);
-				}
-				externexpire = time(NULL);
+			if (ast_sockaddr_resolve_first(&externaddr, externhost, 0)) {
+				ast_log(LOG_NOTICE, "Warning: Re-lookup of '%s' failed!\n", externhost);
 			}
 			externexpire = time(NULL) + externrefresh;
 		}
@@ -3185,9 +3173,6 @@
 			default:
 				break;
 			}
-		}
-		else {
-			ast_log(LOG_WARNING, "stun failed\n");
 		}
 		ast_debug(1, "Target address %s is not local, substituting externaddr\n",
 			  ast_sockaddr_stringify(them));
@@ -14681,7 +14666,7 @@
  * address and port in the SIP headers without the need for STUN.
  * The address part is also reused for the media sessions.
  * Note that ast_sip_ouraddrfor() still rewrites p->ourip
- * if you specify externaddr/seternaddr/stunaddr.
+ * if you specify externaddr/seternaddr/.
  */
 static attribute_unused void check_via_response(struct sip_pvt *p, struct sip_request *req)
 {
@@ -16872,8 +16857,6 @@
 		msg = "Disabled, no localnet list";
 	else if (ast_sockaddr_isnull(&externaddr))
 		msg = "Disabled";
-	else if (stunaddr.sin_addr.s_addr != 0)
-		msg = "Enabled using STUN";
 	else if (!ast_strlen_zero(externhost))
 		msg = "Enabled using externhost";
 	else
@@ -16893,8 +16876,6 @@
 			    ast_strdupa(ast_sockaddr_stringify_addr(&d->netmask)));
 		}
 	}
-	ast_cli(a->fd, "  STUN server:            %s:%d\n", ast_inet_ntoa(stunaddr.sin_addr), ntohs(stunaddr.sin_port));
-
 	ast_cli(a->fd, "\nGlobal Signalling Settings:\n");
 	ast_cli(a->fd, "---------------------------\n");
 	ast_cli(a->fd, "  Codecs:                 ");
@@ -26147,7 +26128,6 @@
 	int registry_count = 0, peer_count = 0, timerb_set = 0, timert1_set = 0;
 	int subscribe_network_change = 1;
 	time_t run_start, run_end;
-	struct sockaddr_in externaddr_sin;
 	int bindport = 0;
 
 	run_start = time(0);
@@ -26250,7 +26230,6 @@
 
 	/* Reset IP addresses  */
 	ast_sockaddr_parse(&bindaddr, "0.0.0.0:0", 0);
-	memset(&stunaddr, 0, sizeof(stunaddr));
 	memset(&internip, 0, sizeof(internip));
 
 	/* Free memory for local network address mask */
@@ -26636,12 +26615,6 @@
 			}
 		} else if (!strcasecmp(v->name, "registerattempts")) {
 			global_regattempts_max = atoi(v->value);
-		} else if (!strcasecmp(v->name, "stunaddr")) {
-			stunaddr.sin_port = htons(3478);
-			if (ast_parse_arg(v->value, PARSE_INADDR, &stunaddr)) {
-				ast_log(LOG_WARNING, "Invalid STUN server address: %s\n", v->value);
-			}
-			externexpire = time(NULL);
 		} else if (!strcasecmp(v->name, "bindaddr") || !strcasecmp(v->name, "udpbindaddr")) {
 			if (ast_parse_arg(v->value, PARSE_ADDR, &bindaddr)) {
 				ast_log(LOG_WARNING, "Invalid address: %s\n", v->value);
@@ -26955,15 +26928,6 @@
 				ast_set_qos(sipsock, global_tos_sip, global_cos_sip, "SIP");
 			}
 		}
-	}
-	if (stunaddr.sin_addr.s_addr != 0) {
-		ast_debug(1, "stun to %s:%d\n",
-			ast_inet_ntoa(stunaddr.sin_addr) , ntohs(stunaddr.sin_port));
-		ast_sockaddr_to_sin(&externaddr, &externaddr_sin);
-		ast_stun_request(sipsock, &stunaddr,
-			NULL, &externaddr_sin);
-		ast_debug(1, "STUN sees us at %s\n",
-			ast_sockaddr_stringify(&externaddr));
 	}
 	ast_mutex_unlock(&netlock);
 

Modified: branches/1.8/configs/sip.conf.sample
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/configs/sip.conf.sample?view=diff&rev=282302&r1=282301&r2=282302
==============================================================================
--- branches/1.8/configs/sip.conf.sample (original)
+++ branches/1.8/configs/sip.conf.sample Fri Aug 13 17:23:38 2010
@@ -727,31 +727,18 @@
 ;        externhost=foo.dyndns.net       ; refreshed periodically
 ;        externrefresh=180               ; change the refresh interval
 ;
-;   c. "stunaddr = stun.server[:port]" queries the STUN server specified
-;      as an argument to obtain the external address/port.
-;      Queries are also sent periodically every "externrefresh" seconds
-;      (as a side effect, sending the query also acts as a keepalive for
-;      the state entry on the nat box):
-;
-;        stunaddr = foo.stun.com:3478
-;        externrefresh = 15
-;
-;      NOTE: STUN is only implemented for IPv4.
-;
 ;   Note that at the moment all these mechanism work only for the SIP socket.
-;   The IP address discovered with externaddr/externhost/STUN is reused for
+;   The IP address discovered with externaddr/externhost is reused for
 ;   media sessions as well, but the port numbers are not remapped so you
 ;   may still experience problems.
 ;
 ; NOTE 1: in some cases, NAT boxes will use different port numbers in
 ; the internal<->external mapping. In these cases, the "externaddr" and
-; "externhost" might not help you configure addresses properly, and you
-; really need to use STUN.
+; "externhost" might not help you configure addresses properly.
 ;
 ; NOTE 2: when using "externaddr" or "externhost", the address part is
-; also used as the external address for media sessions. Even if you 
-; use "stunaddr", STUN queries will be sent only from the SIP port,
-; not from media sockets. Thus, the port information in the SDP may be wrong!
+; also used as the external address for media sessions. Thus, the port
+; information in the SDP may be wrong!
 ;
 ; In addition to the above, Asterisk has an additional "nat" parameter to
 ; address NAT-related issues in incoming SIP or media sessions.




More information about the asterisk-commits mailing list