[svn-commits] jpeeler: branch jpeeler/sip-dnsmgr r110782 - in /team/jpeeler/sip-dnsmgr: cha...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Tue Mar 25 17:59:17 CDT 2008
Author: jpeeler
Date: Tue Mar 25 17:59:17 2008
New Revision: 110782
URL: http://svn.digium.com/view/asterisk?view=rev&rev=110782
Log:
checkpoint, transitioning dnsmgr to support DNS SRV records
Modified:
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_sip.c
URL: http://svn.digium.com/view/asterisk/team/jpeeler/sip-dnsmgr/channels/chan_sip.c?view=diff&rev=110782&r1=110781&r2=110782
==============================================================================
--- team/jpeeler/sip-dnsmgr/channels/chan_sip.c (original)
+++ team/jpeeler/sip-dnsmgr/channels/chan_sip.c Tue Mar 25 17:59:17 2008
@@ -4103,9 +4103,11 @@
if (global_srvlookup) {
char service[MAXHOSTNAMELEN];
int tportno;
+ ast_log(LOG_DEBUG, "******************************** global_srvlookup=%d host=%s\n", global_srvlookup, host);
snprintf(service, sizeof(service), "_sip._%s.%s", get_transport(dialog->socket.type), peername);
srv_ret = ast_get_srv(NULL, host, sizeof(host), &tportno, service);
+ ast_log(LOG_DEBUG, "******************************** srv_ret=%d host=%s service=%s\n", srv_ret, host, service);
if (srv_ret > 0) {
hostn = host;
portno = tportno;
@@ -9212,7 +9214,21 @@
}
if (r->dnsmgr == NULL) {
- ast_dnsmgr_lookup(r->hostname, &r->us.sin_addr, &r->dnsmgr);
+ /*TODO: need to make a setup function for all this... */
+ char service[MAXHOSTNAMELEN];
+ char peername[256];
+ char *port;
+ //ast_dnsmgr_lookup(r->hostname, &r->us.sin_addr, &r->dnsmgr);
+
+ ast_copy_string(peername, r->hostname, sizeof(peername));
+ port = strchr(peername, ':');
+ if (port)
+ *port++ = '\0';
+
+ snprintf(service, sizeof(service), "_sip._%s.%s", get_transport(r->transport), r->hostname); /* have to use static get_transport function */
+ r->portno = port ? atoi(port) : (r->transport & SIP_TRANSPORT_TLS) ? STANDARD_TLS_PORT : STANDARD_SIP_PORT;
+ 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.sin_addr, &r->portno, &r->dnsmgr, service);
}
if (r->call) { /* We have a registration */
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=110782&r1=110781&r2=110782
==============================================================================
--- team/jpeeler/sip-dnsmgr/include/asterisk/dnsmgr.h (original)
+++ team/jpeeler/sip-dnsmgr/include/asterisk/dnsmgr.h Tue Mar 25 17:59:17 2008
@@ -28,6 +28,7 @@
#endif
#include "asterisk/network.h"
+#include "asterisk/srv.h"
/*!
* \brief A DNS manager entry
@@ -51,6 +52,9 @@
* \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 in_addr *result, int *portno);
+
/*!
* \brief Free a DNS manager entry
@@ -77,6 +81,8 @@
*/
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 in_addr *result_addr, int *result_portno, 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=110782&r1=110781&r2=110782
==============================================================================
--- team/jpeeler/sip-dnsmgr/main/dnsmgr.c (original)
+++ team/jpeeler/sip-dnsmgr/main/dnsmgr.c Tue Mar 25 17:59:17 2008
@@ -48,6 +48,8 @@
struct in_addr *result;
/*! the last result, used to check if address has changed */
struct in_addr last;
+ int result_portno;
+ int last_portno;
/*! Set to 1 if the entry changes */
int changed:1;
ast_mutex_t lock;
@@ -96,6 +98,29 @@
return entry;
}
+
+struct ast_dnsmgr_entry *ast_dnsmgr_get_srv(const char *name, struct in_addr *result, int *portno)
+{
+ struct ast_dnsmgr_entry *entry;
+
+ if (!result || ast_strlen_zero(name) || !(entry = ast_calloc(1, sizeof(*entry) + strlen(name))))
+ return NULL;
+
+ entry->result = result;
+ entry->result_portno = *portno;
+ ast_mutex_init(&entry->lock);
+ strcpy(entry->name, name);
+ memcpy(&entry->last, result, sizeof(entry->last));
+ entry->last_portno = *portno;
+
+ AST_RWLIST_WRLOCK(&entry_list);
+ AST_RWLIST_INSERT_HEAD(&entry_list, entry, list);
+ AST_RWLIST_UNLOCK(&entry_list);
+
+ return entry;
+}
+
+
void ast_dnsmgr_release(struct ast_dnsmgr_entry *entry)
{
if (!entry)
@@ -140,6 +165,53 @@
*dnsmgr = ast_dnsmgr_get(name, result);
return !*dnsmgr;
}
+
+int ast_dnsmgr_lookup_srv(const char *name, struct in_addr *result_addr, int *result_portno, struct ast_dnsmgr_entry **dnsmgr, const char *service)
+{
+ char realhostname[MAXHOSTNAMELEN];
+ int srv_ret;
+ struct hostent *hp;
+ struct ast_hostent ahp;
+
+ if (ast_strlen_zero(name) || !result_addr || !result_portno || !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, result_addr))
+ return 0;
+
+ ast_verb(4, "doing dnsmgr_lookup for '%s'\n", name);
+
+ srv_ret = ast_get_srv(NULL, realhostname, sizeof(realhostname), result_portno, service);
+ if (srv_ret > 0) {
+ char buf[INET_ADDRSTRLEN];
+ hp = ast_gethostbyname(realhostname, &ahp);
+ ast_log(LOG_DEBUG, "name=%s realhostname=%s result_portno=%d hp->h_addr=%s\n", name, realhostname, *result_portno, inet_ntop(AF_INET, hp->h_addr, buf, sizeof(buf)));
+ //result_addr->sin_port = *result_portno;
+ } else {
+ hp = ast_gethostbyname(name, &ahp);
+ ast_log(LOG_DEBUG, "name=%s realhostname=%s result_portno=%d hp->h_addr=%s\n", name, realhostname, *result_portno, hp->h_addr);
+ }
+
+ memcpy(result_addr, hp->h_addr, sizeof(result_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(name, result_addr, );
+ //return !*dnsmgr;
+ return 0;
+}
+
/*
* Refresh a dnsmgr entry
More information about the svn-commits
mailing list