[asterisk-commits] jpeeler: branch jpeeler/sip-dnsmgr r111244 - in /team/jpeeler/sip-dnsmgr: cha...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Mar 26 17:59:36 CDT 2008


Author: jpeeler
Date: Wed Mar 26 17:59:35 2008
New Revision: 111244

URL: http://svn.digium.com/view/asterisk?view=rev&rev=111244
Log:
checkpoint, still need to get port numbers managed properly by dnsmgr

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=111244&r1=111243&r2=111244
==============================================================================
--- team/jpeeler/sip-dnsmgr/channels/chan_sip.c (original)
+++ team/jpeeler/sip-dnsmgr/channels/chan_sip.c Wed Mar 26 17:59:35 2008
@@ -1960,7 +1960,7 @@
 static const struct sockaddr_in *sip_real_dst(const struct sip_pvt *p);
 static void build_via(struct sip_pvt *p);
 static int create_addr_from_peer(struct sip_pvt *r, struct sip_peer *peer);
-static int create_addr(struct sip_pvt *dialog, const char *opeer, struct in_addr *sin);
+static int create_addr(struct sip_pvt *dialog, const char *opeer, struct sockaddr_in *sin);
 static char *generate_random_string(char *buf, size_t size);
 static void build_callid_pvt(struct sip_pvt *pvt);
 static void build_callid_registry(struct sip_registry *reg, struct in_addr ourip, const char *fromdomain);
@@ -2529,7 +2529,7 @@
 	int res = 0;
 	const struct sockaddr_in *dst = sip_real_dst(p);
 
-	ast_debug(1, "Trying to put '%.10s' onto %s socket destined for %s\n", data->str, get_transport(p->socket.type), ast_inet_ntoa(dst->sin_addr));
+	ast_debug(1, "Trying to put '%.10s' onto %s socket destined for %s:%d\n", data->str, get_transport(p->socket.type), ast_inet_ntoa(dst->sin_addr), htons(dst->sin_port));
 
 	if (sip_prepare_socket(p) < 0)
 		return XMIT_ERROR;
@@ -3934,6 +3934,7 @@
  */
 static int create_addr_from_peer(struct sip_pvt *dialog, struct sip_peer *peer)
 {
+	ast_log(LOG_DEBUG, "peer reference existed\n");
 	dialog->socket = peer->socket;
 
 	if ((peer->addr.sin_addr.s_addr || peer->defaddr.sin_addr.s_addr) &&
@@ -4053,11 +4054,10 @@
 	
 	return 0;
 }
-
 /*! \brief create address structure from peer name
  *      Or, if peer not found, find it in the global DNS 
  *      returns TRUE (-1) on failure, FALSE on success */
-static int create_addr(struct sip_pvt *dialog, const char *opeer, struct in_addr *sin)
+static int create_addr(struct sip_pvt *dialog, const char *opeer, struct sockaddr_in *sin)
 {
 	struct hostent *hp;
 	struct ast_hostent ahp;
@@ -4096,28 +4096,30 @@
 	if (dialog->outboundproxy)
 		return 0;
 
-	/* Let's see if we can find the host in DNS. First try DNS SRV records,
-   	   then hostname lookup */
-	hostn = peername;
-	portno = port ? atoi(port) : (dialog->socket.type & SIP_TRANSPORT_TLS) ? STANDARD_TLS_PORT : STANDARD_SIP_PORT;
-	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;
-		}
-	}
-
-	if (sin && srv_ret <= 0) {
-		memcpy(&dialog->sa.sin_addr, sin, sizeof(dialog->sa.sin_addr));
-		ast_log(LOG_DEBUG, "IP lookup for hostname=%s, using dnsmgr resolved to %s...\n", peername, ast_inet_ntoa(*sin));
+	/* This address should be updated using dnsmgr */
+	if (sin) {
+		memcpy(&dialog->sa.sin_addr, &sin->sin_addr, sizeof(dialog->sa.sin_addr));
+		portno = htons(sin->sin_port);
 	} else {
+
+		/* Let's see if we can find the host in DNS. First try DNS SRV records,
+		   then hostname lookup */
+		hostn = peername;
+		portno = port ? atoi(port) : (dialog->socket.type & SIP_TRANSPORT_TLS) ? STANDARD_TLS_PORT : STANDARD_SIP_PORT;
+		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;
+			}
+		}
+
 		hp = ast_gethostbyname(hostn, &ahp);
 		if (!hp) {
 			ast_log(LOG_WARNING, "No such host: %s\n", peername);
@@ -9214,21 +9216,13 @@
 	}
 
 	if (r->dnsmgr == NULL) {
-		/*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);
+		ast_dnsmgr_lookup_srv(r->hostname, &r->us.sin_addr, &r->us.sin_port, &r->dnsmgr, service);
+		ast_log(LOG_DEBUG, "after dnsmgr lookup port=%d\n", r->us.sin_port);
 	} 
 
 	if (r->call) {	/* We have a registration */
@@ -9258,7 +9252,7 @@
 		p->outboundproxy = obproxy_get(p, NULL);
 
 		/* Find address to hostname */
-		if (create_addr(p, r->hostname, &r->us.sin_addr)) {
+		if (create_addr(p, r->hostname, &r->us)) {
 			/* we have what we hope is a temporary network error,
 			 * probably DNS.  We need to reschedule a registration try */
 			sip_destroy(p);

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=111244&r1=111243&r2=111244
==============================================================================
--- team/jpeeler/sip-dnsmgr/include/asterisk/dnsmgr.h (original)
+++ team/jpeeler/sip-dnsmgr/include/asterisk/dnsmgr.h Wed Mar 26 17:59:35 2008
@@ -53,7 +53,7 @@
  */
 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);
+struct ast_dnsmgr_entry *ast_dnsmgr_get_srv(const char *name, struct in_addr *result, unsigned short *portno);
 
 
 /*!
@@ -81,7 +81,7 @@
  */
 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);
+int ast_dnsmgr_lookup_srv(const char *name, struct in_addr *result_addr, unsigned short *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=111244&r1=111243&r2=111244
==============================================================================
--- team/jpeeler/sip-dnsmgr/main/dnsmgr.c (original)
+++ team/jpeeler/sip-dnsmgr/main/dnsmgr.c Wed Mar 26 17:59:35 2008
@@ -48,8 +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;
+	unsigned short result_portno;
+	unsigned short last_portno;
 	/*! Set to 1 if the entry changes */
 	int changed:1;
 	ast_mutex_t lock;
@@ -99,7 +99,7 @@
 }
 
 
-struct ast_dnsmgr_entry *ast_dnsmgr_get_srv(const char *name, struct in_addr *result, int *portno)
+struct ast_dnsmgr_entry *ast_dnsmgr_get_srv(const char *name, struct in_addr *result, unsigned short *portno)
 {
 	struct ast_dnsmgr_entry *entry;
 
@@ -166,9 +166,10 @@
 	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)
+int ast_dnsmgr_lookup_srv(const char *name, struct in_addr *result_addr, unsigned short *result_portno, struct ast_dnsmgr_entry **dnsmgr, const char *service)
 {
 	char realhostname[MAXHOSTNAMELEN];
+	int real_portno;
 	int srv_ret;
 	struct hostent *hp;
 	struct ast_hostent ahp;
@@ -188,10 +189,11 @@
 
 	ast_verb(4, "doing dnsmgr_lookup for '%s'\n", name);
 
-	srv_ret = ast_get_srv(NULL, realhostname, sizeof(realhostname), result_portno, 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);
+		*result_portno = (unsigned int)real_portno;
 		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 {
@@ -207,9 +209,8 @@
 		return 0;
 	
 	ast_verb(3, "adding dns manager for '%s'\n", name);
-	//*dnsmgr = ast_dnsmgr_get(name, result_addr, );
-	//return !*dnsmgr;
-	return 0;
+	*dnsmgr = ast_dnsmgr_get_srv(name, result_addr, result_portno);
+	return !*dnsmgr;
 }
 
 




More information about the asterisk-commits mailing list