[asterisk-commits] rmudgett: branch 10 r345977 - in /branches/10: ./ include/asterisk/ main/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Nov 22 17:00:35 CST 2011
Author: rmudgett
Date: Tue Nov 22 17:00:31 2011
New Revision: 345977
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=345977
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
Modified:
branches/10/ (props changed)
branches/10/include/asterisk/dnsmgr.h
branches/10/main/dnsmgr.c
Propchange: branches/10/
------------------------------------------------------------------------------
Binary property 'branch-1.8-merged' - no diff available.
Modified: branches/10/include/asterisk/dnsmgr.h
URL: http://svnview.digium.com/svn/asterisk/branches/10/include/asterisk/dnsmgr.h?view=diff&rev=345977&r1=345976&r2=345977
==============================================================================
--- branches/10/include/asterisk/dnsmgr.h (original)
+++ branches/10/include/asterisk/dnsmgr.h Tue Nov 22 17:00:31 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: branches/10/main/dnsmgr.c
URL: http://svnview.digium.com/svn/asterisk/branches/10/main/dnsmgr.c?view=diff&rev=345977&r1=345976&r2=345977
==============================================================================
--- branches/10/main/dnsmgr.c (original)
+++ branches/10/main/dnsmgr.c Tue Nov 22 17:00:31 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)
@@ -123,6 +131,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;
}
@@ -130,6 +140,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
@@ -150,7 +163,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;
}
@@ -168,6 +181,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