[svn-commits] jpdionne: branch group/v6-new r273190 - /team/group/v6-new/channels/chan_sip.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Jun 30 09:45:12 CDT 2010


Author: jpdionne
Date: Wed Jun 30 09:45:08 2010
New Revision: 273190

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=273190
Log:
Filter by address family of 'bindaddr' in ast_sockaddr_resolve and bug fix in create_addr.


Modified:
    team/group/v6-new/channels/chan_sip.c

Modified: team/group/v6-new/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/group/v6-new/channels/chan_sip.c?view=diff&rev=273190&r1=273189&r2=273190
==============================================================================
--- team/group/v6-new/channels/chan_sip.c (original)
+++ team/group/v6-new/channels/chan_sip.c Wed Jun 30 09:45:08 2010
@@ -1375,8 +1375,10 @@
 static int sip_addheader(struct ast_channel *chan, const char *data);
 static int sip_do_reload(enum channelreloadreason reason);
 static char *sip_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
+static int ast_sockaddr_resolve_first_af(struct ast_sockaddr *addr,
+				      const char *name, int flag, int family);
 static int ast_sockaddr_resolve_first(struct ast_sockaddr *addr,
-				      const char *name, int flag, int family);
+				      const char *name, int flag);
 
 /*--- Debugging
 	Functions for enabling debug per IP or fully, or enabling history logging for
@@ -3085,8 +3087,7 @@
 				ast_sockaddr_to_sin(&externip, &externip_sin);
 				ast_stun_request(sipsock, &stunaddr, NULL, &externip_sin);
 			} else {
-				if (ast_sockaddr_resolve_first(&externip,
-							       externhost, 0, 0)) {
+				if (ast_sockaddr_resolve_first(&externip, externhost, 0)) {
 					ast_log(LOG_NOTICE, "Warning: Re-lookup of '%s' failed!\n", externhost);
 				}
 				externexpire = time(NULL);
@@ -4255,7 +4256,7 @@
 						if (ast_sockaddr_resolve(&addrs,
 									 tmp->value,
 									 PARSE_PORT_FORBID,
-									 0) <= 0 ||
+									 get_address_family_filter(&bindaddr)) <= 0 ||
 						    ast_sockaddr_cmp(&addrs[0], addr)) {
 							/* No match */
 							ast_variables_destroy(var);
@@ -4797,18 +4798,23 @@
 static int create_addr(struct sip_pvt *dialog, const char *opeer, struct ast_sockaddr *addr, int newdialog, struct ast_sockaddr *remote_address)
 {
 	struct sip_peer *peer;
-	char *peername, *hostn;
+	char *peername, *peername2, *hostn;
 	char host[MAXHOSTNAMELEN];
 	char service[MAXHOSTNAMELEN];
 	int srv_ret = 0;
 	int tportno;
 
+	AST_DECLARE_APP_ARGS(hostport,
+		AST_APP_ARG(host);
+		AST_APP_ARG(port);
+	);
+
 	peername = ast_strdupa(opeer);
-	ast_sockaddr_parse(&dialog->sa, peername, 0);
-
-	if (ast_sockaddr_port(&dialog->sa)) {
+	peername2 = ast_strdupa(opeer);
+	AST_NONSTANDARD_RAW_ARGS(hostport, peername2, ':');
+
+	if (hostport.port)
 		dialog->portinuri = 1;
-	}
 
 	dialog->timer_t1 = global_t1; /* Default SIP retransmission timer T1 (RFC 3261) */
 	dialog->timer_b = global_timer_b; /* Default SIP transaction timer B (RFC 3261) */
@@ -4832,7 +4838,7 @@
 		return -1;
 	}
 
-	ast_string_field_set(dialog, tohost, peername);
+	ast_string_field_set(dialog, tohost, hostport.host);
 	dialog->allowed_methods &= ~sip_cfg.disallowed_methods;
 
 	/* Get the outbound proxy information */
@@ -4852,7 +4858,7 @@
  		/* Section 4.2 of RFC 3263 specifies that if a port number is specified, then
 		 * an A record lookup should be used instead of SRV.
 		 */
-		if (!ast_sockaddr_port(&dialog->sa) && sip_cfg.srvlookup) {
+		if (!hostport.port && sip_cfg.srvlookup) {
 			snprintf(service, sizeof(service), "_sip._%s.%s", get_transport(dialog->socket.type), peername);
 			if ((srv_ret = ast_get_srv(NULL, host, sizeof(host), &tportno,
 						   service)) > 0) {
@@ -4860,8 +4866,7 @@
 			}
 		}
 
-		if (ast_sockaddr_resolve_first(&dialog->sa, hostn,
-					       PARSE_PORT_FORBID, 0)) {
+		if (ast_sockaddr_resolve_first(&dialog->sa, hostn, 0)) {
 			ast_log(LOG_WARNING, "No such host: %s\n", peername);
 		}
 
@@ -7628,7 +7633,7 @@
 		return -1;
 	}
 
-	if (ast_sockaddr_resolve_first(addr, host, 0, af)) {
+	if (ast_sockaddr_resolve_first_af(addr, host, 0, af)) {
 		ast_log(LOG_WARNING, "Could not look up IP address of alternate hostname. Expect %s problems\n", media == SDP_AUDIO? "audio" : "video");
 		return -1;
 	}
@@ -8364,7 +8369,7 @@
 			ast_log(LOG_WARNING, "Unknown protocol '%s'.\n", proto);
 			return FALSE;
 		}
-		if (ast_sockaddr_resolve_first(addr, host, 0, af)) {
+		if (ast_sockaddr_resolve_first_af(addr, host, 0, af)) {
 			ast_log(LOG_WARNING, "Unable to lookup RTP Audio host in c= line, '%s'\n", c);
 			return FALSE;
 		}
@@ -8903,7 +8908,7 @@
 
 	/*! \todo XXX If we have sip_cfg.srvlookup on, then look for NAPTR/SRV,
 	 * otherwise, just look for A records */
-	if (ast_sockaddr_resolve_first(&p->sa, hostname, 0, 0)) {
+	if (ast_sockaddr_resolve_first(&p->sa, hostname, 0)) {
 		ast_log(LOG_WARNING, "Can't find address for host '%s'\n", hostname);
 		return;
 	}
@@ -8924,7 +8929,7 @@
 
 		/*! \todo XXX If we have sip_cfg.srvlookup on, then look for
 		 * NAPTR/SRV, otherwise, just look for A records */
-		if (ast_sockaddr_resolve_first(&p->sa, hostname, PARSE_PORT_FORBID, 0)) {
+		if (ast_sockaddr_resolve_first(&p->sa, hostname, PARSE_PORT_FORBID)) {
 			ast_log(LOG_WARNING, "Can't find address for host '%s'\n", hostname);
 			return;
 		}
@@ -12378,7 +12383,7 @@
 		assume that the domain part is a host name and only look for an A/AAAA record in DNS.
 	*/
 
-	if (ast_sockaddr_resolve_first(addr, domain, 0, 0)) {
+	if (ast_sockaddr_resolve_first(addr, domain, 0)) {
 		ast_log(LOG_WARNING, "Invalid host name in Contact: (can't "
 			"resolve in DNS) : '%s'\n", domain);
 		return -1;
@@ -12512,7 +12517,7 @@
 		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 */
-		if (ast_sockaddr_resolve_first(&testsa, domain, 0, 0)) {
+		if (ast_sockaddr_resolve_first(&testsa, domain, 0)) {
 			ast_log(LOG_WARNING, "Invalid domain '%s'\n", domain);
 			ast_string_field_set(peer, fullcontact, "");
 			ast_string_field_set(pvt, our_contact, "");
@@ -14209,7 +14214,7 @@
 		if (pt)
 			*pt++ = '\0';	/* remember port pointer */
 
-		if (maddr && ast_sockaddr_resolve_first(&p->sa, maddr, 0, 0)) {
+		if (maddr && ast_sockaddr_resolve_first(&p->sa, maddr, 0)) {
 			p->sa = p->recv;
 		}
 
@@ -17103,7 +17108,7 @@
 /*! \brief Enable SIP Debugging for a single IP */
 static char *sip_do_debug_ip(int fd, const char *arg)
 {
-	if (ast_sockaddr_resolve_first(&debugaddr, arg, 0, 0)) {
+	if (ast_sockaddr_resolve_first(&debugaddr, arg, 0)) {
 		return CLI_SHOWUSAGE;
 	}
 
@@ -24534,8 +24539,7 @@
 	}
 
 	if (!ast_strlen_zero(remote_address)) {
-		if (ast_sockaddr_resolve_first(&remote_address_sa,
-					       remote_address, 0, 0)) {
+		if (ast_sockaddr_resolve_first(&remote_address_sa, remote_address, 0)) {
 			ast_log(LOG_WARNING, "Unable to find IP address for host %s. We will not use this remote IP address\n", remote_address);
 		} else {
 			if (!ast_sockaddr_port(&remote_address_sa)) {
@@ -26301,7 +26305,7 @@
 			externexpire = 0;
 		} else if (!strcasecmp(v->name, "externhost")) {
 			ast_copy_string(externhost, v->value, sizeof(externhost));
-			if (ast_sockaddr_resolve_first(&externip, externhost, 0, 0)) {
+			if (ast_sockaddr_resolve_first(&externip, externhost, 0)) {
 				ast_log(LOG_WARNING, "Invalid address for externhost keyword: %s\n", externhost);
 			}
 			externexpire = time(NULL);
@@ -27392,30 +27396,39 @@
 	return 1;
 }
 
-/*! \brief  Return the first entry from ast_sockaddr_resolve.
+/*! \brief  Return the first entry from ast_sockaddr_resolve filtered by address family
+ *
+ * \warn Using this function probably means you have a faulty design.
+ */
+static int ast_sockaddr_resolve_first_af(struct ast_sockaddr *addr,
+				      const char* name, int flag, int family)
+{
+	struct ast_sockaddr *addrs;
+	int addrs_cnt;
+
+	addrs_cnt = ast_sockaddr_resolve(&addrs, name, flag, family);
+	if (addrs_cnt <= 0) {
+		return 1;
+	}
+	if (addrs_cnt > 1) {
+		ast_log(LOG_DEBUG, "Multiple addresses, using the first one only\n");
+	}
+
+	ast_sockaddr_copy(addr, &addrs[0]);
+
+	ast_free(addrs);
+	return 0;
+}
+
+/*! \brief  Return the first entry from ast_sockaddr_resolve filtered by family of binddaddr
  *
  * \warn Using this function probably means you have a faulty design.
  */
 static int ast_sockaddr_resolve_first(struct ast_sockaddr *addr,
-				      const char* name, int flag, int family)
-{
-	struct ast_sockaddr *addrs;
-	int addrs_cnt;
-
-	addrs_cnt = ast_sockaddr_resolve(&addrs, name, flag, family);
-	if (addrs_cnt <= 0) {
-		return 1;
-	}
-	if (addrs_cnt > 1) {
-		ast_log(LOG_DEBUG, "Multiple addresses, using the first one only\n");
-	}
-
-	ast_sockaddr_copy(addr, &addrs[0]);
-
-	ast_free(addrs);
-	return 0;
-}
-
+				      const char* name, int flag)
+{
+	return ast_sockaddr_resolve_first_af(addr, name, flag, get_address_family_filter(&bindaddr));
+}
 
 /*! \brief
  * \note The only member of the peer used here is the name field




More information about the svn-commits mailing list