[asterisk-commits] jpeeler: branch jpeeler/sip-dnsmgr r110079 - /team/jpeeler/sip-dnsmgr/channels/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Mar 19 15:02:13 CDT 2008


Author: jpeeler
Date: Wed Mar 19 15:02:13 2008
New Revision: 110079

URL: http://svn.digium.com/view/asterisk?view=rev&rev=110079
Log:
fixed dnsmgr for registrations not referencing a peer entry

Modified:
    team/jpeeler/sip-dnsmgr/channels/chan_sip.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=110079&r1=110078&r2=110079
==============================================================================
--- team/jpeeler/sip-dnsmgr/channels/chan_sip.c (original)
+++ team/jpeeler/sip-dnsmgr/channels/chan_sip.c Wed Mar 19 15:02:13 2008
@@ -1303,22 +1303,6 @@
 	struct sip_st_dlg *stimer;		/*!< SIP Session-Timers */              
 };
 
-/* TODO: better placement? */
-struct ast_dnsmgr_entry {
-    /*! where we will store the resulting address */
-    struct in_addr *result;
-    /*! the last result, used to check if address has changed */
-    struct in_addr last;
-    /*! Set to 1 if the entry changes */
-    int changed:1;
-    ast_mutex_t lock;
-    AST_RWLIST_ENTRY(ast_dnsmgr_entry) list;
-    /*! just 1 here, but we use calloc to allocate the correct size */
-    char name[1];
-};
-
-
-
 /*! Max entires in the history list for a sip_pvt */
 #define MAX_HISTORY_ENTRIES 50
 
@@ -1976,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 ast_dnsmgr_entry *dnsmgr);
+static int create_addr(struct sip_pvt *dialog, const char *opeer, struct in_addr *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);
@@ -4074,7 +4058,7 @@
 /*! \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 ast_dnsmgr_entry *dnsmgr)
+static int create_addr(struct sip_pvt *dialog, const char *opeer, struct in_addr *sin)
 {
 	struct hostent *hp;
 	struct ast_hostent ahp;
@@ -4083,8 +4067,7 @@
 	int portno;
 	char host[MAXHOSTNAMELEN], *hostn;
 	char peername[256];
-
-	ast_log(LOG_DEBUG, "Create_addr\n");
+	int srv_ret = 0;
 
 	ast_copy_string(peername, opeer, sizeof(peername));
 	port = strchr(peername, ':');
@@ -4097,22 +4080,8 @@
 
 	if (peer) {
 		int res = create_addr_from_peer(dialog, peer);
-		if (peer->dnsmgr != NULL) {
-			ast_log(LOG_DEBUG, "IP address from peer dnsmgr resolved to %s\n", ast_inet_ntoa(peer->dnsmgr->last));
-		} else {
-			ast_log(LOG_DEBUG, "peer dnsmgr is NULL\n");
-		}
-
-		memcpy(&peer->addr.sin_addr, &dnsmgr->last, sizeof(peer->addr.sin_addr));
-			
 		unref_peer(peer);
 		ast_log(LOG_DEBUG, "Peer found with address of %s\n", ast_inet_ntoa(dialog->sa.sin_addr));
-
-		if (dnsmgr) {
-			memcpy(&dialog->sa.sin_addr, &dnsmgr->last, sizeof(dialog->sa.sin_addr));
-			ast_log(LOG_DEBUG, "IP lookup for hostname=%s, using dnsmgr resolved to %s...\n", peername, ast_inet_ntoa(dnsmgr->last));
-		}
-  
 		return res;
 	} else {
 		/* Setup default parameters for this dialog's socket. Currently we only support regular UDP SIP as the default */
@@ -4131,34 +4100,30 @@
 
 	/* 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;
-		int ret;
 
 		snprintf(service, sizeof(service), "_sip._%s.%s", get_transport(dialog->socket.type), peername);
-		ret = ast_get_srv(NULL, host, sizeof(host), &tportno, service);
-		if (ret > 0) {
+		srv_ret = ast_get_srv(NULL, host, sizeof(host), &tportno, 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);
-		return -1;
-	}
-	memcpy(&dialog->sa.sin_addr, hp->h_addr, sizeof(dialog->sa.sin_addr));
-
-	if (dnsmgr) {
-		memcpy(&dialog->sa.sin_addr, &dnsmgr->last, sizeof(dialog->sa.sin_addr));
-		ast_log(LOG_DEBUG, "IP lookup for hostname=%s, using dnsmgr resolved to %s...\n", peername, ast_inet_ntoa(dnsmgr->last));
+
+	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));
 	} else {
-		ast_log(LOG_DEBUG, "No dnsmgr detected\n");
+		hp = ast_gethostbyname(hostn, &ahp);
+		if (!hp) {
+			ast_log(LOG_WARNING, "No such host: %s\n", peername);
+			return -1;
+		}
+		memcpy(&dialog->sa.sin_addr, hp->h_addr, sizeof(dialog->sa.sin_addr));
 	}
 
 	dialog->sa.sin_port = htons(portno);
@@ -9185,7 +9150,10 @@
 	if (!r)
 		return 0;
 
-	//ast_dnsmgr_refresh(r->dnsmgr);
+	if (r->dnsmgr) {
+		/* If the registration has timed out, maybe the IP changed.  Force a refresh. */
+		ast_dnsmgr_refresh(r->dnsmgr);
+	}
 
 	ast_log(LOG_NOTICE, "   -- Registration for '%s@%s' timed out, trying again (Attempt #%d)\n", r->username, r->hostname, r->regattempts); 
 	/* If the initial tranmission failed, we may not have an existing dialog,
@@ -9236,23 +9204,16 @@
 	char tmp[80];
 	char addr[80];
 	struct sip_pvt *p;
-	struct in_addr sin;
-	int changed = 0;
 
 	/* exit if we are already in process with this registrar ?*/
-	if ( r == NULL || ((auth==NULL) && (r->regstate==REG_STATE_REGSENT || r->regstate==REG_STATE_AUTHSENT))) {
+	if (r == NULL || ((auth == NULL) && (r->regstate == REG_STATE_REGSENT || r->regstate == REG_STATE_AUTHSENT))) {
 		ast_log(LOG_NOTICE, "Strange, trying to register %s@%s when registration already pending\n", r->username, r->hostname);
 		return 0;
 	}
 
 	if (r->dnsmgr == NULL) {
-		ast_dnsmgr_lookup(r->hostname, &sin, &r->dnsmgr);
-		memcpy(&r->us.sin_addr, &sin, sizeof(sin));
-		ast_log(LOG_DEBUG, "dnsmgr was NULL\n");
-	} else {
-		changed = ast_dnsmgr_changed(r->dnsmgr);
-		ast_log(LOG_DEBUG, "Change status = %d\n", changed);
-	}
+		ast_dnsmgr_lookup(r->hostname, &r->us.sin_addr, &r->dnsmgr);
+	} 
 
 	if (r->call) {	/* We have a registration */
 		if (!auth) {
@@ -9283,7 +9244,7 @@
 		p->outboundproxy = obproxy_get(p, NULL);
 
 		/* Find address to hostname */
-		if (create_addr(p, r->hostname, r->dnsmgr)) {
+		if (create_addr(p, r->hostname, &r->us.sin_addr)) {
 			/* we have what we hope is a temporary network error,
 			 * probably DNS.  We need to reschedule a registration try */
 			sip_destroy(p);
@@ -9331,15 +9292,6 @@
 		p->socket.type = r->transport;
 		p->socket.port = htons(r->portno);
 
-/*
-		if (changed) {
-			//struct sockaddr_in real;
-			//real = sip_real_dst(r->call);
-			ast_dnsmgr_get(r->hostname, &sin);
-			ast_log(LOG_DEBUG, "IP change detected for hostname=%s, updating to %s...\n", r->hostname, ast_inet_ntoa(sin));
-			memcpy(&r->call->sa.sin_addr, &sin, sizeof(sin));
-	 	}
-*/
 		/*
 		  check which address we should use in our contact header 
 		  based on whether the remote host is on the external or




More information about the asterisk-commits mailing list