[asterisk-commits] rmudgett: trunk r345978 - in /trunk: ./ include/asterisk/dnsmgr.h main/dnsmgr.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Nov 22 17:06:12 CST 2011


Author: rmudgett
Date: Tue Nov 22 17:06:11 2011
New Revision: 345978

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=345978
Log:
Fix dnsmgr entries to ask for the same address family each time.

The dnsmgr refresh would always get the first address found regardless of
the original address family requested.  So if you asked for only IPv4
addresses originally, you might get an IPv6 address on refresh.

* Saved the original address family requested by ast_dnsmgr_lookup() to be
used when the address is refreshed.
........

Merged revisions 345976 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 345977 from http://svn.asterisk.org/svn/asterisk/branches/10

Modified:
    trunk/   (props changed)
    trunk/include/asterisk/dnsmgr.h
    trunk/main/dnsmgr.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-10-merged' - no diff available.

Modified: trunk/include/asterisk/dnsmgr.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/dnsmgr.h?view=diff&rev=345978&r1=345977&r2=345978
==============================================================================
--- trunk/include/asterisk/dnsmgr.h (original)
+++ trunk/include/asterisk/dnsmgr.h Tue Nov 22 17:06:11 2011
@@ -44,6 +44,7 @@
  * \param result where the DNS manager should store the IP address as it refreshes it.
  * \param service
  *
+ * \details
  * This function allocates a new DNS manager entry object, and fills it with the
  * provided hostname and IP address.  This function does not force an initial lookup
  * of the IP address.  So, generally, this should be used when the initial address
@@ -54,6 +55,24 @@
  * \version 1.8.0 result changed from struct ast_sockaddr_in to ast_sockaddr for IPv6 support
  */
 struct ast_dnsmgr_entry *ast_dnsmgr_get(const char *name, struct ast_sockaddr *result, const char *service);
+
+/*!
+ * \brief Allocate a new DNS manager entry
+ *
+ * \param name the hostname
+ * \param result where the DNS manager should store the IP address as it refreshes it.
+ * \param service
+ * \param family Address family to filter DNS addresses.
+ *
+ * \details
+ * This function allocates a new DNS manager entry object, and fills it with the
+ * provided hostname and IP address.  This function does not force an initial lookup
+ * of the IP address.  So, generally, this should be used when the initial address
+ * is already known.
+ *
+ * \return a DNS manager entry
+ */
+struct ast_dnsmgr_entry *ast_dnsmgr_get_family(const char *name, struct ast_sockaddr *result, const char *service, unsigned int family);
 
 /*!
  * \brief Free a DNS manager entry

Modified: trunk/main/dnsmgr.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/dnsmgr.c?view=diff&rev=345978&r1=345977&r2=345978
==============================================================================
--- trunk/main/dnsmgr.c (original)
+++ trunk/main/dnsmgr.c Tue Nov 22 17:06:11 2011
@@ -54,6 +54,8 @@
 	struct ast_sockaddr *result;
 	/*! SRV record to lookup, if provided. Composed of service, protocol, and domain name: _Service._Proto.Name */
 	char *service;
+	/*! Address family to filter DNS responses. */
+	unsigned int family;
 	/*! Set to 1 if the entry changes */
 	unsigned int changed:1;
 	ast_mutex_t lock;
@@ -83,7 +85,7 @@
 	.verbose = 0,
 };
 
-struct ast_dnsmgr_entry *ast_dnsmgr_get(const char *name, struct ast_sockaddr *result, const char *service)
+struct ast_dnsmgr_entry *ast_dnsmgr_get_family(const char *name, struct ast_sockaddr *result, const char *service, unsigned int family)
 {
 	struct ast_dnsmgr_entry *entry;
 	int total_size = sizeof(*entry) + strlen(name) + (service ? strlen(service) + 1 : 0);
@@ -99,12 +101,18 @@
 		entry->service = ((char *) entry) + sizeof(*entry) + strlen(name);
 		strcpy(entry->service, service);
 	}
+	entry->family = family;
 
 	AST_RWLIST_WRLOCK(&entry_list);
 	AST_RWLIST_INSERT_HEAD(&entry_list, entry, list);
 	AST_RWLIST_UNLOCK(&entry_list);
 
 	return entry;
+}
+
+struct ast_dnsmgr_entry *ast_dnsmgr_get(const char *name, struct ast_sockaddr *result, const char *service)
+{
+	return ast_dnsmgr_get_family(name, result, service, 0);
 }
 
 void ast_dnsmgr_release(struct ast_dnsmgr_entry *entry)
@@ -124,6 +132,8 @@
 
 int ast_dnsmgr_lookup(const char *name, struct ast_sockaddr *result, struct ast_dnsmgr_entry **dnsmgr, const char *service)
 {
+	unsigned int family;
+
 	if (ast_strlen_zero(name) || !result || !dnsmgr) {
 		return -1;
 	}
@@ -131,6 +141,9 @@
 	if (*dnsmgr && !strcasecmp((*dnsmgr)->name, name)) {
 		return 0;
 	}
+
+	/* Lookup address family filter. */
+	family = result->ss.ss_family;
 
 	/*
 	 * If it's actually an IP address and not a name, there's no
@@ -151,7 +164,7 @@
 	}
 
 	ast_verb(3, "adding dns manager for '%s'\n", name);
-	*dnsmgr = ast_dnsmgr_get(name, result, service);
+	*dnsmgr = ast_dnsmgr_get_family(name, result, service, family);
 	return !*dnsmgr;
 }
 
@@ -169,6 +182,7 @@
 		ast_verb(3, "refreshing '%s'\n", entry->name);
 	}
 
+	tmp.ss.ss_family = entry->family;
 	if (!ast_get_ip_or_srv(&tmp, entry->name, entry->service)) {
 		if (!ast_sockaddr_port(&tmp)) {
 			ast_sockaddr_set_port(&tmp, ast_sockaddr_port(entry->result));




More information about the asterisk-commits mailing list