[svn-commits] rizzo: branch rizzo/astobj2 r75587 - /team/rizzo/astobj2/channels/chan_sip.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Jul 18 10:00:04 CDT 2007


Author: rizzo
Date: Wed Jul 18 10:00:04 2007
New Revision: 75587

URL: http://svn.digium.com/view/asterisk?view=rev&rev=75587
Log:
more bits and pieces of stun support


Modified:
    team/rizzo/astobj2/channels/chan_sip.c

Modified: team/rizzo/astobj2/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/astobj2/channels/chan_sip.c?view=diff&rev=75587&r1=75586&r2=75587
==============================================================================
--- team/rizzo/astobj2/channels/chan_sip.c (original)
+++ team/rizzo/astobj2/channels/chan_sip.c Wed Jul 18 10:00:04 2007
@@ -2211,11 +2211,15 @@
 static void ast_sip_ouraddrfor(struct in_addr *them, struct sockaddr_in *us)
 {
 	struct sockaddr_in theirs;
-
-	*us = internip;		/* start from something reasonable */
-	/* Start from the address that the system would use */
-	ast_ouraddrfor(them, &us->sin_addr);
-	theirs.sin_addr = *them;
+	/* Set want_remap to non-zero if we want to remap 'us'.
+	 * Conditions are that we have a localaddr list,
+	 * either stunaddr or externip is set,
+	 * the remote address does not match any of the 'localaddr' entries,
+	 * and (cheched later) some other condition on 'us'.
+	 */
+	int want_remap = localaddr &&
+		(externip.sin_addr.s_addr || stunaddr.sin_addr.s_addr) &&
+		ast_apply_ha(localaddr, &theirs) == AST_SENSE_ALLOW ;
 
 	/* localaddr contains 'internal' addresses marked as 'deny',
 	 * so 'external' addresses will return AST_SENSE_ALLOW.
@@ -2223,18 +2227,27 @@
 	 * address to an externally visible one, and use some appropriate
 	 * mechanism to do that.
 	 */
-	if (localaddr /* have a list of internal addresses */
-		&& externip.sin_addr.s_addr /* can remap to something */
-		&& ast_apply_ha(localaddr, &theirs) == AST_SENSE_ALLOW /* it is indeed internal */
+
+	*us = internip;		/* start from something reasonable */
+	/* Start from the address that the system would use */
+	ast_ouraddrfor(them, &us->sin_addr);
+	theirs.sin_addr = *them;
+
+	if (want_remap
 		&& (!global_matchexterniplocally || !ast_apply_ha(localaddr, us)) /* we want to remap */
 			) { 
-		/* if we used externhost, see if it is time to refresh the info */
+		/* if we used externhost or stun, see if it is time to refresh the info */
 		if (externexpire && time(NULL) >= externexpire) {
+			if (stunaddr.sin_addr.s_addr) {
+				ast_stun_request(sipsock, &stunaddr, NULL, &externip);
+				ast_log(LOG_WARNING, "stun(2) sees us at %s:%d\n",
+						ast_inet_ntoa(externip.sin_addr) , ntohs(externip.sin_port));
+			} else {
+				if (ast_parse_arg(externhost, PARSE_INADDR, &externip))
+					ast_log(LOG_NOTICE, "Warning: Re-lookup of '%s' failed!\n", externhost);
+			}
 			externexpire = time(NULL) + externrefresh;
-			if (ast_parse_arg(externhost, PARSE_INADDR, &externip))
-				ast_log(LOG_NOTICE, "Warning: Re-lookup of '%s' failed!\n", externhost);
-		}
-		/* XXX todo - what if we use stun ? */
+		}
 		*us = externip;
 		if (option_debug) {
 			ast_log(LOG_DEBUG, "Target address %s is not local, substituting externip\n", 




More information about the svn-commits mailing list