[asterisk-commits] elguero: branch 12 r422275 - in /branches/12: ./ channels/chan_iax2.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Aug 28 15:29:49 CDT 2014


Author: elguero
Date: Thu Aug 28 15:29:45 2014
New Revision: 422275

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=422275
Log:
chan_iax2: Fix Dynamic IAX2 Registrations After Temporary DNS Failure

The reporter on the issue found some issues when upgrading from version 10 to 11
on 55 hosts.

Two situations that can occur with dynamic registrations.

1.  With dnsmgr disabled, if the host is not resolvable we are not trying to
    resolve the host again when it is time to attempt to register again.  This
    results in never registering to the host.
2.  With dnsmgr enabled, when the host is temporarily not resolvable the
    address is set to 0.0.0.0:0 and then when the host is resolvable the port
    is not being restored and stays set to 0.

This patch resolves these two issues by:

* Storing the hostname so that it can be used for resolving with DNS.
* Resolve the hostname on the next scheduled attempt to register.
* Storing the port used to reach the host so that when the hostname is
  resolvable again, we can set the port again if the port is still unset after
  looking up the host.

ASTERISK-23767 #close
Reported by: David Herselman
Tested by: David Herselman, Michael L. Young
Patches:
    asterisk-23767-dns_reg_retry_and_set_port_11_v3.diff
                                     uploaded by Michael L. Young (license 5026)

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

Merged revisions 422274 from http://svn.asterisk.org/svn/asterisk/branches/11

Modified:
    branches/12/   (props changed)
    branches/12/channels/chan_iax2.c

Propchange: branches/12/
------------------------------------------------------------------------------
Binary property 'branch-11-merged' - no diff available.

Modified: branches/12/channels/chan_iax2.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/channels/chan_iax2.c?view=diff&rev=422275&r1=422274&r2=422275
==============================================================================
--- branches/12/channels/chan_iax2.c (original)
+++ branches/12/channels/chan_iax2.c Thu Aug 28 15:29:45 2014
@@ -629,6 +629,8 @@
 	struct ast_sockaddr us;			/*!< Who the server thinks we are */
 	struct ast_dnsmgr_entry *dnsmgr;	/*!< DNS refresh manager */
 	AST_LIST_ENTRY(iax2_registry) entry;
+	int port;
+	char hostname[];
 };
 
 static AST_LIST_HEAD_STATIC(registrations, iax2_registry);
@@ -8480,6 +8482,17 @@
 static void __iax2_do_register_s(const void *data)
 {
 	struct iax2_registry *reg = (struct iax2_registry *)data;
+
+	if (ast_sockaddr_isnull(&reg->addr)) {
+		reg->addr.ss.ss_family = AST_AF_UNSPEC;
+		ast_dnsmgr_lookup(reg->hostname, &reg->addr, &reg->dnsmgr, srvlookup ? "_iax._udp" : NULL);
+		if (!ast_sockaddr_port(&reg->addr)) {
+			ast_sockaddr_set_port(&reg->addr, reg->port);
+		} else {
+			reg->port = ast_sockaddr_port(&reg->addr);
+		}
+	}
+
 	reg->expire = -1;
 	iax2_do_register(reg);
 }
@@ -8712,8 +8725,9 @@
 {
 	struct iax2_registry *reg;
 
-	if (!(reg = ast_calloc(1, sizeof(*reg))))
+	if (!(reg = ast_calloc(1, sizeof(*reg) + strlen(hostname) + 1))) {
 		return -1;
+	}
 
 	reg->addr.ss.ss_family = AST_AF_UNSPEC;
 	if (ast_dnsmgr_lookup(hostname, &reg->addr, &reg->dnsmgr, srvlookup ? "_iax._udp" : NULL) < 0) {
@@ -8722,13 +8736,24 @@
 	}
 
 	ast_copy_string(reg->username, username, sizeof(reg->username));
-
-	if (secret)
+	strcpy(reg->hostname, hostname); /* Note: This is safe */
+
+	if (secret) {
 		ast_copy_string(reg->secret, secret, sizeof(reg->secret));
+	}
 
 	reg->expire = -1;
 	reg->refresh = IAX_DEFAULT_REG_EXPIRE;
-	ast_sockaddr_set_port(&reg->addr, porta ? atoi(porta) : IAX_DEFAULT_PORTNO);
+
+	reg->port = ast_sockaddr_port(&reg->addr);
+
+	if (!porta && !reg->port) {
+		reg->port = IAX_DEFAULT_PORTNO;
+	} else if (porta) {
+		sscanf(porta, "%5d", &reg->port);
+	}
+
+	ast_sockaddr_set_port(&reg->addr, reg->port);
 
 	AST_LIST_LOCK(&registrations);
 	AST_LIST_INSERT_HEAD(&registrations, reg, entry);
@@ -12055,6 +12080,9 @@
 			(5 * reg->refresh / 6) * 1000, iax2_do_register_s, reg);
 		return -1;
 	}
+	if (!ast_sockaddr_port(&reg->addr) && reg->port) {
+		ast_sockaddr_set_port(&reg->addr, reg->port);
+	}
 
 	if (!reg->callno) {
 




More information about the asterisk-commits mailing list