[asterisk-commits] oej: branch oej/pgtips-srv-and-outbound-stuff-1.8 r421664 - in /team/oej/pgti...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Aug 21 04:41:30 CDT 2014


Author: oej
Date: Thu Aug 21 04:41:13 2014
New Revision: 421664

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=421664
Log:
Trying to understand the old transmit_register() function. Some of the things here
are a mystery. In order to add proper DNS srv failover and lookup a lot of stuff
needs to be re-ordered and changed.

Also implemented a flag that indicates that someone configured a port number. In
that case, SRV should be disabled. That part is a bug fix I think.

Modified:
    team/oej/pgtips-srv-and-outbound-stuff-1.8/channels/chan_sip.c
    team/oej/pgtips-srv-and-outbound-stuff-1.8/channels/sip/config_parser.c
    team/oej/pgtips-srv-and-outbound-stuff-1.8/channels/sip/include/sip.h
    team/oej/pgtips-srv-and-outbound-stuff-1.8/configs/sip.conf.sample

Modified: team/oej/pgtips-srv-and-outbound-stuff-1.8/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/pgtips-srv-and-outbound-stuff-1.8/channels/chan_sip.c?view=diff&rev=421664&r1=421663&r2=421664
==============================================================================
--- team/oej/pgtips-srv-and-outbound-stuff-1.8/channels/chan_sip.c (original)
+++ team/oej/pgtips-srv-and-outbound-stuff-1.8/channels/chan_sip.c Thu Aug 21 04:41:13 2014
@@ -5753,8 +5753,9 @@
 	peername2 = ast_strdupa(opeer);
 	AST_NONSTANDARD_RAW_ARGS(hostport, peername2, ':');
 
-	if (hostport.port)
-		dialog->portinuri = 1;
+	if (hostport.port) {
+		dialog->portinuri = TRUE;
+	}
 
 	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) */
@@ -5804,7 +5805,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 (!hostport.port && sip_cfg.srvlookup) {
+		if (!dialog->portinuri && sip_cfg.srvlookup) {
 			if (dialog->srvcontext) {
 				ast_srv_context_free_list(dialog->srvcontext);
 			}
@@ -13840,12 +13841,19 @@
 		snprintf(transport, sizeof(transport), "_%s._%s", get_srv_service(r->transport), get_srv_protocol(r->transport)); /* have to use static get_transport function */
 		r->us.ss.ss_family = get_address_family_filter(r->transport); /* Filter address family */
 
+#ifdef DISABLE_DUAL_LOOKUP
+		/* OEJ: Disabling this lookup, since create_addr is better at using DNS SRV records for
+		   now. Remind me wy we do the SRV here instead of in the dialog, since we keep the dialog
+		   anyway.
+		*/
 		/* No point in doing a DNS lookup of the register hostname if we're just going to
 		 * end up using an outbound proxy. obproxy_get is safe to call with either of r->call
 		 * or peer NULL. Since we're only concerned with its existence, we're not going to
 		 * bother getting a ref to the proxy*/
 		if (!obproxy_get(r->call, peer)) {
+			/* Why are we doing this when create_addr is doing it for us? */
 			registry_addref(r, "add reg ref for dnsmgr");
+			/* If we have a configured port number, do not do SRV lookups */
 			ast_dnsmgr_lookup_cb(peer ? peer->tohost : r->hostname, &r->us, &r->dnsmgr, sip_cfg.srvlookup ? transport : NULL, on_dns_update_registry, r);
 			if (!r->dnsmgr) {
 				/*dnsmgr refresh disabled, no reference added! */
@@ -13856,6 +13864,7 @@
 			peer = unref_peer(peer, "removing peer ref for dnsmgr_lookup");
 		}
 	}
+#endif
 
 	if (r->call) {	/* We have a registration */
 		if (!auth) {
@@ -13880,6 +13889,9 @@
 
 		/* reset tag to consistent value from registry */
 		ast_string_field_set(p, tag, r->localtag);
+
+		/* If we have a port configured, do not activate SRV record lookup for this host */
+		p->portinuri = r->portconfigured;
 
 		if (p->do_history) {
 			append_history(p, "RegistryInit", "Account: %s@%s", r->username, r->hostname);
@@ -13904,6 +13916,18 @@
 				}
 				peer = unref_peer(peer, "unref after find_peer");
 			}
+		}
+
+		/* Set transport and port so the correct contact is built */
+		set_socket_transport(&p->socket, r->transport);
+		if (r->transport == SIP_TRANSPORT_TLS || r->transport == SIP_TRANSPORT_TCP) {
+			p->socket.port =
+			    htons(ast_sockaddr_port(&sip_tcp_desc.local_address));
+		}
+		if (!r->dnsmgr && r->portno) {
+			ast_sockaddr_set_port(&p->sa, r->portno);
+			ast_sockaddr_set_port(&p->recv, r->portno);
+			ast_debug(2, "Confusing code set port to %d\n", r->portno);
 		}
 
 		/* Find address to hostname */
@@ -13929,11 +13953,6 @@
 		/* Copy back Call-ID in case create_addr changed it */
 		ast_string_field_set(r, callid, p->callid);
 
-		if (!r->dnsmgr && r->portno) {
-			ast_sockaddr_set_port(&p->sa, r->portno);
-			ast_sockaddr_set_port(&p->recv, r->portno);
-			ast_debug(2, "Confusing code set port to %d\n", r->portno);
-		}
 		if (!ast_strlen_zero(p->fromdomain)) {
 			portno = (p->fromdomainport) ? p->fromdomainport : STANDARD_SIP_PORT;
 		} else if (!ast_strlen_zero(r->regdomain)) {
@@ -13968,12 +13987,6 @@
 			ast_string_field_set(p, exten, r->callback);
 		}
 
-		/* Set transport and port so the correct contact is built */
-		set_socket_transport(&p->socket, r->transport);
-		if (r->transport == SIP_TRANSPORT_TLS || r->transport == SIP_TRANSPORT_TCP) {
-			p->socket.port =
-			    htons(ast_sockaddr_port(&sip_tcp_desc.local_address));
-		}
 
 		/*
 		  check which address we should use in our contact header
@@ -14065,11 +14078,11 @@
 
 	initialize_initreq(p, &req);
 	if (sip_debug_test_pvt(p)) {
-		ast_verbose("REGISTER %d headers, %d lines\n", p->initreq.headers, p->initreq.lines);
+		ast_verbose("SIP REGISTER %d headers, %d lines\n", p->initreq.headers, p->initreq.lines);
 	}
 	r->regstate = auth ? REG_STATE_AUTHSENT : REG_STATE_REGSENT;
 	r->regattempts++;	/* Another attempt */
-	ast_debug(4, "REGISTER attempt %d to %s@%s\n", r->regattempts, r->username, r->hostname);
+	ast_debug(4, "SIP REGISTER attempt %d to %s@%s\n", r->regattempts, r->username, r->hostname);
 	res = send_request(p, &req, XMIT_CRITICAL, p->ocseq);
 	dialog_unref(p, "p is finished here at the end of transmit_register");
 	return res;

Modified: team/oej/pgtips-srv-and-outbound-stuff-1.8/channels/sip/config_parser.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/pgtips-srv-and-outbound-stuff-1.8/channels/sip/config_parser.c?view=diff&rev=421664&r1=421663&r2=421664
==============================================================================
--- team/oej/pgtips-srv-and-outbound-stuff-1.8/channels/sip/config_parser.c (original)
+++ team/oej/pgtips-srv-and-outbound-stuff-1.8/channels/sip/config_parser.c Thu Aug 21 04:41:13 2014
@@ -244,11 +244,16 @@
 
 	/* if no portnum specified, set default for transport */
 	if (!portnum) {
+		reg->portconfigured = FALSE;
 		if (transport == SIP_TRANSPORT_TLS) {
 			portnum = STANDARD_TLS_PORT;
 		} else {
 			portnum = STANDARD_SIP_PORT;
 		}
+	} else {
+		/* If any port (including 5060/5061) was configured we should avoid
+		   doing SRV lookups - just like for SIP URI's */
+		reg->portconfigured = TRUE;
 	}
 
 	/* copy into sip_registry object */

Modified: team/oej/pgtips-srv-and-outbound-stuff-1.8/channels/sip/include/sip.h
URL: http://svnview.digium.com/svn/asterisk/team/oej/pgtips-srv-and-outbound-stuff-1.8/channels/sip/include/sip.h?view=diff&rev=421664&r1=421663&r2=421664
==============================================================================
--- team/oej/pgtips-srv-and-outbound-stuff-1.8/channels/sip/include/sip.h (original)
+++ team/oej/pgtips-srv-and-outbound-stuff-1.8/channels/sip/include/sip.h Thu Aug 21 04:41:13 2014
@@ -1352,6 +1352,7 @@
 	);
 	enum sip_transport transport;   /*!< Transport for this registration UDP, TCP or TLS */
 	int portno;                     /*!< Optional port override */
+	int portconfigured;		/*!< If port is configured, disable SRV lookups. */
 	int regdomainport;              /*!< Port override for domainport */
 	int expire;                     /*!< Sched ID of expiration */
 	int configured_expiry;          /*!< Configured value to use for the Expires header */

Modified: team/oej/pgtips-srv-and-outbound-stuff-1.8/configs/sip.conf.sample
URL: http://svnview.digium.com/svn/asterisk/team/oej/pgtips-srv-and-outbound-stuff-1.8/configs/sip.conf.sample?view=diff&rev=421664&r1=421663&r2=421664
==============================================================================
--- team/oej/pgtips-srv-and-outbound-stuff-1.8/configs/sip.conf.sample (original)
+++ team/oej/pgtips-srv-and-outbound-stuff-1.8/configs/sip.conf.sample Thu Aug 21 04:41:13 2014
@@ -704,6 +704,7 @@
 ; to use a port here. That is, you must explicitly provide a "secret" and "authuser" even if
 ; they are blank. See the third example below for an illustration.
 ;
+; If a port number is specified for the host, no SRV lookup will be done. 
 ;
 ; Examples:
 ;




More information about the asterisk-commits mailing list