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


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@345978 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Richard Mudgett 2011-11-22 23:06:11 +00:00
parent d777e15792
commit 2b3e28f88c
2 changed files with 35 additions and 2 deletions

View File

@ -44,6 +44,7 @@ struct ast_dnsmgr_entry;
* \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
@ -55,6 +56,24 @@ struct ast_dnsmgr_entry;
*/
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
*

View File

@ -54,6 +54,8 @@ struct ast_dnsmgr_entry {
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 @@ static struct refresh_info master_refresh_info = {
.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,6 +101,7 @@ struct ast_dnsmgr_entry *ast_dnsmgr_get(const char *name, struct ast_sockaddr *r
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);
@ -107,6 +110,11 @@ struct ast_dnsmgr_entry *ast_dnsmgr_get(const char *name, struct ast_sockaddr *r
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)
{
if (!entry) {
@ -124,6 +132,8 @@ void ast_dnsmgr_release(struct ast_dnsmgr_entry *entry)
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;
}
@ -132,6 +142,9 @@ int ast_dnsmgr_lookup(const char *name, struct ast_sockaddr *result, struct ast_
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
* need for a managed lookup.
@ -151,7 +164,7 @@ int ast_dnsmgr_lookup(const char *name, struct ast_sockaddr *result, struct ast_
}
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 @@ static int dnsmgr_refresh(struct ast_dnsmgr_entry *entry, int verbose)
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));