summaryrefslogtreecommitdiff
path: root/main/dnsmgr.c
diff options
context:
space:
mode:
authorMark Michelson <mmichelson@digium.com>2010-07-08 22:08:07 +0000
committerMark Michelson <mmichelson@digium.com>2010-07-08 22:08:07 +0000
commitcd4ebd336f6fdd1fe5d2ad57f06654a9678d88d4 (patch)
treec05335b563c3f7cb9a3edbf3e101d8e1b80e0be4 /main/dnsmgr.c
parent816f26c16ce6cf03cf97b7d0e7af64837283e79d (diff)
Add IPv6 to Asterisk.
This adds a generic API for accommodating IPv6 and IPv4 addresses within Asterisk. While many files have been updated to make use of the API, chan_sip and the RTP code are the files which actually support IPv6 addresses at the time of this commit. The way has been paved for easier upgrading for other files in the near future, though. Big thanks go to Simon Perrault, Marc Blanchet, and Jean-Philippe Dionne for their hard work on this. (closes issue #17565) Reported by: russell Patches: asteriskv6-test-report.pdf uploaded by russell (license 2) Review: https://reviewboard.asterisk.org/r/743 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@274783 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/dnsmgr.c')
-rw-r--r--main/dnsmgr.c43
1 files changed, 17 insertions, 26 deletions
diff --git a/main/dnsmgr.c b/main/dnsmgr.c
index ca181e3f2..29ac4e30f 100644
--- a/main/dnsmgr.c
+++ b/main/dnsmgr.c
@@ -51,7 +51,7 @@ static pthread_t refresh_thread = AST_PTHREADT_NULL;
struct ast_dnsmgr_entry {
/*! where we will store the resulting IP address and port number */
- struct sockaddr_in *result;
+ struct ast_sockaddr *result;
/*! SRV record to lookup, if provided. Composed of service, protocol, and domain name: _Service._Proto.Name */
char *service;
/*! Set to 1 if the entry changes */
@@ -83,7 +83,7 @@ static struct refresh_info master_refresh_info = {
.verbose = 0,
};
-struct ast_dnsmgr_entry *ast_dnsmgr_get(const char *name, struct sockaddr_in *result, const char *service)
+struct ast_dnsmgr_entry *ast_dnsmgr_get(const char *name, struct ast_sockaddr *result, const char *service)
{
struct ast_dnsmgr_entry *entry;
int total_size = sizeof(*entry) + strlen(name) + (service ? strlen(service) + 1 : 0);
@@ -120,10 +120,7 @@ void ast_dnsmgr_release(struct ast_dnsmgr_entry *entry)
ast_free(entry);
}
-/*
- * Allocate a new DNS manager entry and perform the initial lookup before returning
- */
-int ast_dnsmgr_lookup(const char *name, struct sockaddr_in *result, struct ast_dnsmgr_entry **dnsmgr, const char *service)
+int ast_dnsmgr_lookup(const char *name, struct ast_sockaddr *result, struct ast_dnsmgr_entry **dnsmgr, const char *service)
{
if (ast_strlen_zero(name) || !result || !dnsmgr)
return -1;
@@ -131,13 +128,6 @@ int ast_dnsmgr_lookup(const char *name, struct sockaddr_in *result, struct ast_d
if (*dnsmgr && !strcasecmp((*dnsmgr)->name, name))
return 0;
- /* if it's actually an IP address and not a name,
- there's no need for a managed lookup */
- if (inet_aton(name, &result->sin_addr)) {
- result->sin_family = AF_INET;
- return 0;
- }
-
ast_verb(4, "doing dnsmgr_lookup for '%s'\n", name);
/* do a lookup now but add a manager so it will automagically get updated in the background */
@@ -157,25 +147,26 @@ int ast_dnsmgr_lookup(const char *name, struct sockaddr_in *result, struct ast_d
*/
static int dnsmgr_refresh(struct ast_dnsmgr_entry *entry, int verbose)
{
- char iabuf[INET_ADDRSTRLEN];
- char iabuf2[INET_ADDRSTRLEN];
- struct sockaddr_in tmp;
+ struct ast_sockaddr tmp;
int changed = 0;
-
+
ast_mutex_lock(&entry->lock);
if (verbose)
ast_verb(3, "refreshing '%s'\n", entry->name);
memset(&tmp, 0, sizeof(tmp));
- tmp.sin_port = entry->result->sin_port;
-
- if (!ast_get_ip_or_srv(&tmp, entry->name, entry->service) && inaddrcmp(&tmp, entry->result)) {
- ast_copy_string(iabuf, ast_inet_ntoa(entry->result->sin_addr), sizeof(iabuf));
- ast_copy_string(iabuf2, ast_inet_ntoa(tmp.sin_addr), sizeof(iabuf2));
- ast_log(LOG_NOTICE, "dnssrv: host '%s' changed from %s:%d to %s:%d\n",
- entry->name, iabuf, ntohs(entry->result->sin_port), iabuf2, ntohs(tmp.sin_port));
- *entry->result = tmp;
- changed = entry->changed = 1;
+
+ 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));
+ if (ast_sockaddr_cmp(&tmp, entry->result)) {
+ ast_log(LOG_NOTICE, "dnssrv: host '%s' changed from %s to %s\n",
+ entry->name, ast_sockaddr_stringify(entry->result),
+ ast_sockaddr_stringify(&tmp));
+
+ ast_sockaddr_copy(entry->result, &tmp);
+ changed = entry->changed = 1;
+ }
}
ast_mutex_unlock(&entry->lock);