[asterisk-commits] twilson: branch 1.6.2 r270693 - in /branches/1.6.2: ./ channels/chan_sip.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jun 15 17:16:56 CDT 2010


Author: twilson
Date: Tue Jun 15 17:16:52 2010
New Revision: 270693

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=270693
Log:
Merged revisions 270658 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

........
  r270658 | twilson | 2010-06-15 15:18:04 -0500 (Tue, 15 Jun 2010) | 20 lines
  
  Make contactdeny apply to src ip when nat=yes
  
  chan_sip's "contactdeny" feature screens the "to be registered contact".
  In case of nat=yes it should not use the address information from the
  Contact header (which is not used at all for routing), but the source
  IP address of the request.
  
  Thus, if nat=yes and a client sends a request from a denied IP address
  (e.g. by spoofing the src-IP address) it can bypass the screening.
  
  This commit makes contactdeny apply to the src ip when nat=yes instead.
  
  (closes issue #17276)
  Reported by: klaus3000
  Patches: 
        patch-asterisk-trunk-contactdeny.txt uploaded by klaus3000 (license 65)
  Tested by: klaus3000
  
  Review: [full review board URL with trailing slash]
........

Modified:
    branches/1.6.2/   (props changed)
    branches/1.6.2/channels/chan_sip.c

Propchange: branches/1.6.2/
------------------------------------------------------------------------------
Binary property 'trunk-merged' - no diff available.

Modified: branches/1.6.2/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.6.2/channels/chan_sip.c?view=diff&rev=270693&r1=270692&r2=270693
==============================================================================
--- branches/1.6.2/channels/chan_sip.c (original)
+++ branches/1.6.2/channels/chan_sip.c Tue Jun 15 17:16:52 2010
@@ -12385,35 +12385,36 @@
 		ao2_t_unlink(peers_by_ip, peer, "ao2_unlink of peer from peers_by_ip table");
 	}
 
+	if (!ast_test_flag(&peer->flags[0], SIP_NAT_ROUTE)) {
+		/* use the data provided in the Contact header for call routing */
+		ast_debug(1, "Store REGISTER's Contact header for call routing.\n");
+		/* XXX This could block for a long time XXX */
+		/*! \todo Check NAPTR/SRV if we have not got a port in the URI */
+		hp = ast_gethostbyname(host, &ahp);
+		if (!hp)  {
+			ast_log(LOG_WARNING, "Invalid host '%s'\n", host);
+			ast_string_field_set(peer, fullcontact, "");
+			ast_string_field_set(pvt, our_contact, "");
+			return PARSE_REGISTER_FAILED;
+		}
+		peer->addr.sin_family = AF_INET;
+		memcpy(&peer->addr.sin_addr, hp->h_addr, sizeof(peer->addr.sin_addr));
+		peer->addr.sin_port = htons(port);
+	} else {
+		/* Don't trust the contact field.  Just use what they came to us
+		   with */
+		ast_debug(1, "Store REGISTER's src-IP:port for call routing.\n");
+		peer->addr = pvt->recv;
+	}
+
 	/* Check that they're allowed to register at this IP */
-	/* XXX This could block for a long time XXX */
-	/*! \todo Check NAPTR/SRV if we have not got a port in the URI */
-	hp = ast_gethostbyname(host, &ahp);
-	if (!hp)  {
-		ast_log(LOG_WARNING, "Invalid host '%s'\n", host);
-		ast_string_field_set(peer, fullcontact, "");
-		ast_string_field_set(pvt, our_contact, "");
-		return PARSE_REGISTER_FAILED;
-	}
-	memcpy(&testsin.sin_addr, hp->h_addr, sizeof(testsin.sin_addr));
+	memcpy(&testsin.sin_addr, &peer->addr.sin_addr, sizeof(testsin.sin_addr));
 	if (ast_apply_ha(global_contact_ha, &testsin) != AST_SENSE_ALLOW ||
 			ast_apply_ha(peer->contactha, &testsin) != AST_SENSE_ALLOW) {
 		ast_log(LOG_WARNING, "Host '%s' disallowed by contact ACL (violating IP %s)\n", host, ast_inet_ntoa(testsin.sin_addr));
 		ast_string_field_set(peer, fullcontact, "");
 		ast_string_field_set(pvt, our_contact, "");
 		return PARSE_REGISTER_DENIED;
-	}
-
-	/*! \todo This could come before the checking of DNS earlier on, to avoid 
-		DNS lookups where we don't need it... */
-	if (!ast_test_flag(&peer->flags[0], SIP_NAT_ROUTE)) {
-		peer->addr.sin_family = AF_INET;
-		memcpy(&peer->addr.sin_addr, hp->h_addr, sizeof(peer->addr.sin_addr));
-		peer->addr.sin_port = htons(port);
-	} else {
-		/* Don't trust the contact field.  Just use what they came to us
-		   with */
-		peer->addr = pvt->recv;
 	}
 
 	/* if the Contact header information copied into peer->addr matches the




More information about the asterisk-commits mailing list