[Freeswitch-trunk] [commit] r13636 - freeswitch/trunk/src

FreeSWITCH SVN mrene at freeswitch.org
Fri Jun 5 08:01:55 PDT 2009


Author: mrene
Date: Fri Jun  5 10:01:54 2009
New Revision: 13636

Log:
Use a new natpmp_t object for every request

Modified:
   freeswitch/trunk/src/switch_nat.c

Modified: freeswitch/trunk/src/switch_nat.c
==============================================================================
--- freeswitch/trunk/src/switch_nat.c	(original)
+++ freeswitch/trunk/src/switch_nat.c	Fri Jun  5 10:01:54 2009
@@ -41,7 +41,6 @@
 typedef struct {
 	switch_memory_pool_t *pool;
 	switch_nat_type_t nat_type;
-	natpmp_t natpmp;
 	struct UPNPUrls urls;
 	struct IGDdatas data;
 	char pub_addr[16];
@@ -105,10 +104,11 @@
 	natpmpresp_t response;
 	char *pubaddr = NULL;
 	fd_set fds;
+	natpmp_t natpmp;
 
 
-	initnatpmp(&nat_globals.natpmp);
-	r = sendpublicaddressrequest(&nat_globals.natpmp);
+	initnatpmp(&natpmp);
+	r = sendpublicaddressrequest(&natpmp);
 
 	if (r < 0) {
 		goto end;
@@ -120,10 +120,10 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Checking for PMP %d/%d\n", i, max);
 
 		FD_ZERO(&fds);
-		FD_SET(nat_globals.natpmp.s, &fds);
-		getnatpmprequesttimeout(&nat_globals.natpmp, &timeout);
+		FD_SET(natpmp.s, &fds);
+		getnatpmprequesttimeout(&natpmp, &timeout);
 		select(FD_SETSIZE, &fds, NULL, NULL, &timeout);
-		r = readnatpmpresponseorretry(&nat_globals.natpmp, &response);
+		r = readnatpmpresponseorretry(&natpmp, &response);
 	} while(r == NATPMP_TRYAGAIN && i < max);
 
 	if (r < 0) {
@@ -134,9 +134,7 @@
 	switch_set_string(nat_globals.pub_addr, pubaddr);
 	nat_globals.nat_type = SWITCH_NAT_TYPE_PMP;
 	
-	if (r) {
-		closenatpmp(&nat_globals.natpmp);
-	}
+	closenatpmp(&natpmp);
 
  end:
 
@@ -175,21 +173,24 @@
 	switch_status_t status = SWITCH_STATUS_FALSE;
 	natpmpresp_t response;
 	int r;
+	natpmp_t natpmp;
 
+	initnatpmp(&natpmp);
+	
 	if (proto == SWITCH_NAT_TCP) {
-		sendnewportmappingrequest(&nat_globals.natpmp, NATPMP_PROTOCOL_TCP, port, port, 31104000);
+		sendnewportmappingrequest(&natpmp, NATPMP_PROTOCOL_TCP, port, port, 31104000);
 	} else if(proto == SWITCH_NAT_UDP) {
-		sendnewportmappingrequest(&nat_globals.natpmp, NATPMP_PROTOCOL_UDP, port, port, 31104000);
+		sendnewportmappingrequest(&natpmp, NATPMP_PROTOCOL_UDP, port, port, 31104000);
 	}
 
 	do {
 		fd_set fds;
 		struct timeval timeout = { 1, 0 };
 		FD_ZERO(&fds);
-		FD_SET(nat_globals.natpmp.s, &fds);
-		getnatpmprequesttimeout(&nat_globals.natpmp, &timeout);
+		FD_SET(natpmp.s, &fds);
+		getnatpmprequesttimeout(&natpmp, &timeout);
 		select(FD_SETSIZE, &fds, NULL, NULL, &timeout);
-		r = readnatpmpresponseorretry(&nat_globals.natpmp, &response);
+		r = readnatpmpresponseorretry(&natpmp, &response);
 	} while(r == NATPMP_TRYAGAIN);
 
 	if (r == 0) {
@@ -210,7 +211,9 @@
 						
 		status = SWITCH_STATUS_SUCCESS;
 	}
-
+	
+	closenatpmp(&natpmp);
+	
 	return status;
 }
 
@@ -244,21 +247,24 @@
 	switch_status_t status = SWITCH_STATUS_FALSE;
 	natpmpresp_t response;
 	int r;
+	natpmp_t natpmp;
+	
+	initnatpmp(&natpmp);
 
 	if (proto == SWITCH_NAT_TCP) {
-		sendnewportmappingrequest(&nat_globals.natpmp, NATPMP_PROTOCOL_TCP, port, port, 0);
+		sendnewportmappingrequest(&natpmp, NATPMP_PROTOCOL_TCP, port, port, 0);
 	} else if(proto == SWITCH_NAT_UDP) {
-		sendnewportmappingrequest(&nat_globals.natpmp, NATPMP_PROTOCOL_UDP, port, port, 0);
+		sendnewportmappingrequest(&natpmp, NATPMP_PROTOCOL_UDP, port, port, 0);
 	}
 
 	do {
 		fd_set fds;
 		struct timeval timeout;
 		FD_ZERO(&fds);
-		FD_SET(nat_globals.natpmp.s, &fds);
-		getnatpmprequesttimeout(&nat_globals.natpmp, &timeout);
+		FD_SET(natpmp.s, &fds);
+		getnatpmprequesttimeout(&natpmp, &timeout);
 		select(FD_SETSIZE, &fds, NULL, NULL, &timeout);
-		r = readnatpmpresponseorretry(&nat_globals.natpmp, &response);
+		r = readnatpmpresponseorretry(&natpmp, &response);
 	} while(r == NATPMP_TRYAGAIN);
 
 	if (r == 0) {
@@ -269,6 +275,8 @@
 						  response.pnu.newportmapping.privateport);
 		status = SWITCH_STATUS_SUCCESS;
 	}
+	
+	closenatpmp(&natpmp);
 
 	return status;
 }
@@ -337,9 +345,7 @@
 
 SWITCH_DECLARE(void) switch_nat_shutdown(void)
 {
-	if (nat_globals.nat_type == SWITCH_NAT_TYPE_PMP) {
-		closenatpmp(&nat_globals.natpmp);
-	}
+
 }
 
 



More information about the Freeswitch-trunk mailing list