[asterisk-commits] jpeeler: branch jpeeler/sip-dnsmgr r111942 - in /team/jpeeler/sip-dnsmgr: cha...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Mar 28 19:01:09 CDT 2008
Author: jpeeler
Date: Fri Mar 28 19:01:09 2008
New Revision: 111942
URL: http://svn.digium.com/view/asterisk?view=rev&rev=111942
Log:
merged dnsmgr srv code in dnsmgr.c
Modified:
team/jpeeler/sip-dnsmgr/channels/chan_iax2.c
team/jpeeler/sip-dnsmgr/channels/chan_sip.c
team/jpeeler/sip-dnsmgr/include/asterisk/dnsmgr.h
team/jpeeler/sip-dnsmgr/main/dnsmgr.c
Modified: team/jpeeler/sip-dnsmgr/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/jpeeler/sip-dnsmgr/channels/chan_iax2.c?view=diff&rev=111942&r1=111941&r2=111942
==============================================================================
--- team/jpeeler/sip-dnsmgr/channels/chan_iax2.c (original)
+++ team/jpeeler/sip-dnsmgr/channels/chan_iax2.c Fri Mar 28 19:01:09 2008
@@ -6427,7 +6427,7 @@
if (!(reg = ast_calloc(1, sizeof(*reg))))
return -1;
- if (ast_dnsmgr_lookup(hostname, ®->addr.sin_addr, ®->dnsmgr) < 0) {
+ if (ast_dnsmgr_lookup(hostname, ®->addr.sin_addr, ®->dnsmgr, NULL) < 0) {
ast_free(reg);
return -1;
}
@@ -10095,7 +10095,7 @@
/* Non-dynamic. Make sure we become that way if we're not */
AST_SCHED_DEL(sched, peer->expire);
ast_clear_flag(peer, IAX_DYNAMIC);
- if (ast_dnsmgr_lookup(v->value, &peer->addr.sin_addr, &peer->dnsmgr))
+ if (ast_dnsmgr_lookup(v->value, &peer->addr.sin_addr, &peer->dnsmgr, NULL))
return peer_unref(peer);
if (!peer->addr.sin_port)
peer->addr.sin_port = htons(IAX_DEFAULT_PORTNO);
Modified: team/jpeeler/sip-dnsmgr/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/jpeeler/sip-dnsmgr/channels/chan_sip.c?view=diff&rev=111942&r1=111941&r2=111942
==============================================================================
--- team/jpeeler/sip-dnsmgr/channels/chan_sip.c (original)
+++ team/jpeeler/sip-dnsmgr/channels/chan_sip.c Fri Mar 28 19:01:09 2008
@@ -9232,7 +9232,7 @@
snprintf(transport, sizeof(transport), "_sip._%s", get_transport(r->transport)); /* have to use static get_transport function */
ast_log(LOG_DEBUG, "hostname: %s portno:%d sin_family:%d\n", r->hostname, r->portno, r->us.sin_family);
- ast_dnsmgr_lookup_srv(r->hostname, &r->us, &r->dnsmgr, transport);
+ ast_dnsmgr_lookup(r->hostname, &r->us, &r->dnsmgr, transport);
ast_log(LOG_DEBUG, "after dnsmgr lookup port=%d\n", htons(r->us.sin_port));
} else {
ast_log(LOG_DEBUG, "DNS manager detected, r->us.sin_addr=%s r->us.sin_port=%d r->us.sin_family=%d\n", ast_inet_ntoa(r->us.sin_addr), ntohs(r->us.sin_port), r->us.sin_family);
@@ -19931,9 +19931,12 @@
peer->host_dynamic = FALSE;
srvlookup = v->value;
+ /* TODO: needs to be moved */
+ /*
if (peer->dnsmgr == NULL) {
- ast_dnsmgr_lookup(srvlookup, &peer->addr.sin_addr, &peer->dnsmgr);
+ ast_dnsmgr_lookup(srvlookup, &peer->addr.sin_addr, &peer->dnsmgr, NULL);
}
+ */
}
} else if (!strcasecmp(v->name, "defaultip")) {
if (ast_get_ip(&peer->defaddr, v->value)) {
Modified: team/jpeeler/sip-dnsmgr/include/asterisk/dnsmgr.h
URL: http://svn.digium.com/view/asterisk/team/jpeeler/sip-dnsmgr/include/asterisk/dnsmgr.h?view=diff&rev=111942&r1=111941&r2=111942
==============================================================================
--- team/jpeeler/sip-dnsmgr/include/asterisk/dnsmgr.h (original)
+++ team/jpeeler/sip-dnsmgr/include/asterisk/dnsmgr.h Fri Mar 28 19:01:09 2008
@@ -51,10 +51,7 @@
*
* \return a DNS manager entry
*/
-struct ast_dnsmgr_entry *ast_dnsmgr_get(const char *name, struct in_addr *result);
-
-struct ast_dnsmgr_entry *ast_dnsmgr_get_srv(const char *name, struct sockaddr_in *result, const char *service);
-
+struct ast_dnsmgr_entry *ast_dnsmgr_get(const char *name, struct sockaddr_in *result, const char *service);
/*!
* \brief Free a DNS manager entry
@@ -79,9 +76,7 @@
* \retval 0 success
* \retval non-zero failure
*/
-int ast_dnsmgr_lookup(const char *name, struct in_addr *result, struct ast_dnsmgr_entry **dnsmgr);
-
-int ast_dnsmgr_lookup_srv(const char *name, struct sockaddr_in *sin, struct ast_dnsmgr_entry **dnsmgr, const char *service);
+int ast_dnsmgr_lookup(const char *name, struct sockaddr_in *result, struct ast_dnsmgr_entry **dnsmgr, const char *service);
/*!
* \brief Force a refresh of a dnsmgr entry
Modified: team/jpeeler/sip-dnsmgr/main/dnsmgr.c
URL: http://svn.digium.com/view/asterisk/team/jpeeler/sip-dnsmgr/main/dnsmgr.c?view=diff&rev=111942&r1=111941&r2=111942
==============================================================================
--- team/jpeeler/sip-dnsmgr/main/dnsmgr.c (original)
+++ team/jpeeler/sip-dnsmgr/main/dnsmgr.c Fri Mar 28 19:01:09 2008
@@ -50,10 +50,11 @@
static pthread_t refresh_thread = AST_PTHREADT_NULL;
struct ast_dnsmgr_entry {
- /*! where we will store the resulting address */
+ /*! where we will store the resulting IP address and port number */
struct sockaddr_in *result;
- /*! the last result, used to check if address has changed */
+ /*! the last result, used to check if address/port has changed */
struct sockaddr_in last;
+ /*! SRV record to lookup, if provided. Composed of service, protocol, and domain name: _Service._Proto.Name */
char service[MAXHOSTNAMELEN];
/*! Set to 1 if the entry changes */
int changed:1;
@@ -84,27 +85,7 @@
.verbose = 0,
};
-struct ast_dnsmgr_entry *ast_dnsmgr_get(const char *name, struct in_addr *result)
-{
- struct ast_dnsmgr_entry *entry;
-
- if (!result || ast_strlen_zero(name) || !(entry = ast_calloc(1, sizeof(*entry) + strlen(name))))
- return NULL;
-
- entry->result->sin_addr = *result;
- ast_mutex_init(&entry->lock);
- strcpy(entry->name, name);
- memcpy(&entry->last, result, sizeof(entry->last));
-
- 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_srv(const char *name, struct sockaddr_in *result, const char *service)
+struct ast_dnsmgr_entry *ast_dnsmgr_get(const char *name, struct sockaddr_in *result, const char *service)
{
struct ast_dnsmgr_entry *entry;
@@ -115,7 +96,7 @@
ast_mutex_init(&entry->lock);
strcpy(entry->name, name);
strcpy(entry->service, service);
- memcpy(&entry->last, &result, sizeof(entry->last));
+ memcpy(&entry->last, result, sizeof(entry->last));
AST_RWLIST_WRLOCK(&entry_list);
AST_RWLIST_INSERT_HEAD(&entry_list, entry, list);
@@ -123,7 +104,6 @@
return entry;
}
-
void ast_dnsmgr_release(struct ast_dnsmgr_entry *entry)
{
@@ -139,153 +119,58 @@
ast_free(entry);
}
-int ast_dnsmgr_lookup(const char *name, struct in_addr *result, struct ast_dnsmgr_entry **dnsmgr)
-{
- struct ast_hostent ahp;
- struct hostent *hp;
-
+int ast_dnsmgr_lookup(const char *name, struct sockaddr_in *result, struct ast_dnsmgr_entry **dnsmgr, const char *service)
+{
if (ast_strlen_zero(name) || !result || !dnsmgr)
return -1;
if (*dnsmgr && !strcasecmp((*dnsmgr)->name, name))
return 0;
- ast_verb(4, "doing dnsmgr_lookup for '%s'\n", name);
-
/* if it's actually an IP address and not a name,
there's no need for a managed lookup */
- if (inet_aton(name, result))
+ if (inet_aton(name, &result->sin_addr))
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 */
- if ((hp = ast_gethostbyname(name, &ahp)))
- memcpy(result, hp->h_addr, sizeof(result));
+ ast_get_ip_or_srv(result, name, service);
/* if dnsmgr is not enable don't bother adding an entry */
if (!enabled)
return 0;
ast_verb(3, "adding dns manager for '%s'\n", name);
- *dnsmgr = ast_dnsmgr_get(name, result);
+ *dnsmgr = ast_dnsmgr_get(name, result, service);
return !*dnsmgr;
}
-
-int ast_dnsmgr_lookup_srv(const char *name, struct sockaddr_in *sin, struct ast_dnsmgr_entry **dnsmgr, const char *service)
-{
- /*
- char realhostname[MAXHOSTNAMELEN];
- int real_portno;
- int srv_ret;
- struct hostent *hp;
- struct ast_hostent ahp;
- */
-
- if (ast_strlen_zero(name) || !sin || !dnsmgr || !service) {
- return -1;
- }
-
- 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, &sin->sin_addr))
- return 0;
-
- ast_verb(4, "doing dnsmgr_lookup for '%s'\n", name);
- ast_get_ip_or_srv(sin, name, service);
-
- /*
- srv_ret = ast_get_srv(NULL, realhostname, sizeof(realhostname), &real_portno, service);
- if (srv_ret > 0) {
- char buf[INET_ADDRSTRLEN];
- hp = ast_gethostbyname(realhostname, &ahp);
- sin->sin_port = htons((unsigned short)real_portno);
- ast_log(LOG_DEBUG, "name=%s realhostname=%s result_portno=%d hp->h_addr=%s\n", name, realhostname, ntohs(sin->sin_port), inet_ntop(AF_INET, hp->h_addr, buf, sizeof(buf)));
- } else {
- hp = ast_gethostbyname(name, &ahp);
- }
-
- if (hp) {
- memcpy(&sin->sin_addr, hp->h_addr, sizeof(sin->sin_addr));
- }
- */
-
- /* if dnsmgr is not enabled don't bother adding an entry */
- if (!enabled)
- return 0;
-
- ast_verb(3, "adding dns manager for '%s'\n", name);
- *dnsmgr = ast_dnsmgr_get_srv(name, sin, service);
- return !*dnsmgr;
-}
-
/*
* Refresh a dnsmgr entry
*/
static int dnsmgr_refresh(struct ast_dnsmgr_entry *entry, int verbose)
{
- //struct ast_hostent ahp;
- //struct hostent *hp;
char iabuf[INET_ADDRSTRLEN];
char iabuf2[INET_ADDRSTRLEN];
- //struct in_addr tmp;
+ struct sockaddr_in tmp;
int changed = 0;
- //char realhostname[MAXHOSTNAMELEN];
- //int real_portno;
ast_mutex_lock(&entry->lock);
if (verbose)
ast_verb(3, "refreshing '%s'\n", entry->name);
- ast_get_ip_or_srv(entry->result, entry->name, entry->service);
- if (entry->result->sin_addr.s_addr != entry->last.sin_addr.s_addr || entry->result->sin_port != entry->last.sin_port) {
+ ast_get_ip_or_srv(&tmp, entry->name, entry->service);
+ if (inaddrcmp(&tmp, &entry->last)) {
ast_copy_string(iabuf, ast_inet_ntoa(entry->last.sin_addr), sizeof(iabuf));
- ast_copy_string(iabuf2, ast_inet_ntoa(entry->result->sin_addr), sizeof(iabuf2));
+ 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->last.sin_port), iabuf2, ntohs(entry->result->sin_port));
- entry->last = *entry->result;
+ entry->name, iabuf, ntohs(entry->last.sin_port), iabuf2, ntohs(tmp.sin_port));
+ *entry->result = tmp;
+ entry->last = tmp;
changed = entry->changed = 1;
}
-/*
- if (entry->dnssrv) {
- int srv_ret;
- srv_ret = ast_get_srv(NULL, realhostname, sizeof(realhostname), &real_portno, entry->service);
-
- if (srv_ret > 0) {
- if ((hp = ast_gethostbyname(realhostname, &ahp))) {
- memcpy(&tmp, hp->h_addr, sizeof(tmp));
- if (tmp.s_addr != entry->last.sin_addr.s_addr || real_portno != ntohs(entry->last.sin_port)) {
- ast_copy_string(iabuf, ast_inet_ntoa(entry->last.sin_addr), sizeof(iabuf));
- ast_copy_string(iabuf2, ast_inet_ntoa(tmp), sizeof(iabuf2));
- ast_log(LOG_NOTICE, "dnssrv: host '%s' changed from %s:%d to %s:%d\n",
- entry->name, iabuf, ntohs(entry->last.sin_port), iabuf2, real_portno);
-
- memcpy(&entry->result->sin_addr, hp->h_addr, sizeof(entry->result->sin_addr));
- memcpy(&entry->last.sin_addr, hp->h_addr, sizeof(entry->last.sin_addr));
- entry->result->sin_port = htons((unsigned short)real_portno);
- entry->last.sin_port = htons((unsigned short)real_portno);
- changed = entry->changed = 1;
- }
- }
- }
- } else if ((hp = ast_gethostbyname(entry->name, &ahp))) {
- // check to see if it has changed, do callback if requested (where de callback is defined ????)
- memcpy(&tmp, hp->h_addr, sizeof(tmp));
- if (tmp.s_addr != entry->last.sin_addr.s_addr) {
- ast_copy_string(iabuf, ast_inet_ntoa(entry->last.sin_addr), sizeof(iabuf));
- ast_copy_string(iabuf2, ast_inet_ntoa(tmp), sizeof(iabuf2));
- ast_log(LOG_NOTICE, "host '%s' changed from %s to %s\n",
- entry->name, iabuf, iabuf2);
- memcpy(entry->result, hp->h_addr, sizeof(entry->result));
- memcpy(&entry->last, hp->h_addr, sizeof(entry->last));
- changed = entry->changed = 1;
- }
- }
-*/
ast_mutex_unlock(&entry->lock);
return changed;
}
More information about the asterisk-commits
mailing list