[asterisk-commits] murf: branch murf/bug11210 r99779 - /team/murf/bug11210/channels/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jan 22 22:45:17 CST 2008


Author: murf
Date: Tue Jan 22 22:45:16 2008
New Revision: 99779

URL: http://svn.digium.com/view/asterisk?view=rev&rev=99779
Log:
checkin: I had table #2's logic conditions a little wrong. Corrected. I't not callno==0 & dcallno == cur->callno, but rather cur->peercallno == 0 & dcallno = cur->callno. So, entries go in findcall iff they have their peercallno field == 0. peercallno becomes one of the keys, so we don't accidentally match elements that have non-zero values in the peercallno field. Now, we get the same behavior as trunk. YAY...

Modified:
    team/murf/bug11210/channels/chan_iax2.c
    team/murf/bug11210/channels/chan_sip.c

Change Statistics:
 0 files changed

Modified: team/murf/bug11210/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug11210/channels/chan_iax2.c?view=diff&rev=99779&r1=99778&r2=99779
==============================================================================
--- team/murf/bug11210/channels/chan_iax2.c (original)
+++ team/murf/bug11210/channels/chan_iax2.c Tue Jan 22 22:45:16 2008
@@ -719,7 +719,7 @@
 */
 
 static struct ao2_container *findcall1; /* keys: pvt->addr & pvt->peercallno */
-static struct ao2_container *findcall2; /* keys: pvt->addr & pvt->callno */
+static struct ao2_container *findcall2; /* keys: pvt->addr & pvt->callno & pvt->peercallno (if 0) */
 static struct ao2_container *findcall3; /* keys: pvt->transfer & pvt->callno */
 static struct ao2_container *findcall4; /* keys: pvt->transfer & pvt->transfercallno */
 
@@ -729,6 +729,53 @@
 be prepared to pay the price... luckily, this is really not a huge price to 
 pay... (famous last words)... */
 
+static void show_findcall1(void)
+{
+	struct ao2_iterator i;
+	struct chan_iax2_pvt *pvt;
+	i = ao2_iterator_init(findcall1, 0);
+	while ( (pvt = ao2_iterator_next(&i))) {
+		ast_log(LOG_NOTICE,"findcall1: addr=%s, port=%d, callno = %d, peercallno=%d\n", 
+				ast_inet_ntoa(pvt->addr.sin_addr), ntohs(pvt->addr.sin_port), pvt->callno, pvt->peercallno);
+		ao2_ref(pvt, -1);
+	}
+}
+
+static void show_findcall2(void)
+{
+	struct ao2_iterator i;
+	struct chan_iax2_pvt *pvt;
+	i = ao2_iterator_init(findcall2, 0);
+	while ( (pvt = ao2_iterator_next(&i))) {
+		ast_log(LOG_NOTICE,"findcall2: addr=%s, port=%d, callno = %d, peercallno=%d\n", 
+				ast_inet_ntoa(pvt->addr.sin_addr), ntohs(pvt->addr.sin_port), pvt->callno, pvt->peercallno);
+		ao2_ref(pvt, -1);
+	}
+}
+
+static void show_findcall3(void)
+{
+	struct ao2_iterator i;
+	struct chan_iax2_pvt *pvt;
+	i = ao2_iterator_init(findcall3, 0);
+	while ( (pvt = ao2_iterator_next(&i))) {
+		ast_log(LOG_NOTICE,"findcall3: transfer=%s, port=%d, callno = %d, transfercallno=%d\n", 
+				ast_inet_ntoa(pvt->addr.sin_addr), ntohs(pvt->addr.sin_port), pvt->callno, pvt->transfercallno);
+		ao2_ref(pvt, -1);
+	}
+}
+
+static void show_findcall4(void)
+{
+	struct ao2_iterator i;
+	struct chan_iax2_pvt *pvt;
+	i = ao2_iterator_init(findcall4, 0);
+	while ( (pvt = ao2_iterator_next(&i))) {
+		ast_log(LOG_NOTICE,"findcall4: transfer=%s, port=%d, callno = %d, transfercallno=%d\n", 
+				ast_inet_ntoa(pvt->addr.sin_addr), ntohs(pvt->addr.sin_port), pvt->callno, pvt->transfercallno);
+		ao2_ref(pvt, -1);
+	}
+}
 
 static AST_LIST_HEAD_STATIC(firmwares, iax_firmware);
 
@@ -928,7 +975,23 @@
  * defined as MIN_REUSE_TIME, with a default of 60 seconds.
  */
 static struct timeval lastused[IAX_MAX_CALLS];
-
+static void show_iaxs(void)
+{
+	int x;
+	ast_log(LOG_NOTICE,"iaxs array:\n");
+	for (x=1; x<maxtrunkcall; x++) {
+		ast_mutex_lock(&iaxsl[x]);
+		if (iaxs[x]) {
+			ast_log(LOG_NOTICE,"iaxs[%d]: addr: %s/%d; callno=%d; peercallno=%d; transfercallno=%d\n",
+					x, ast_inet_ntoa(iaxs[x]->addr.sin_addr), ntohs(iaxs[x]->addr.sin_port), 
+					iaxs[x]->callno, iaxs[x]->peercallno, iaxs[x]->transfercallno);
+		}
+		ast_mutex_unlock(&iaxsl[x]);
+	}
+}
+
+static void iax2_destroy_byptr(void *p2);
+static void iax2_destroy(int callno);
 static enum ast_bridge_result iax2_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc, int timeoutms);
 static int expire_registry(const void *data);
 static int iax2_answer(struct ast_channel *c);
@@ -1347,7 +1410,7 @@
 static int findcall2_hash_cb(const void *obj, const int flags)
 {
 	const struct chan_iax2_pvt *pvt = obj;
-	int x = pvt->addr.sin_addr.s_addr + pvt->addr.sin_port + pvt->callno;
+	int x = pvt->addr.sin_addr.s_addr + pvt->addr.sin_port + pvt->callno + pvt->peercallno;
 	if (x<0)
 		x = -x;
 	
@@ -1364,7 +1427,8 @@
 
 	if (pvt1->addr.sin_addr.s_addr == pvt2->addr.sin_addr.s_addr
 		&& pvt1->addr.sin_port == pvt2->addr.sin_port
-		&& pvt1->callno == pvt2->callno)
+		&& pvt1->callno == pvt2->callno
+		&& pvt1->peercallno == pvt2->peercallno) /* only entered in table if peercallno is zero */
 		return CMP_MATCH;
 	else 
 		return 0;
@@ -1507,7 +1571,7 @@
 	struct chan_iax2_pvt *tmp;
 	jb_conf jbconf;
 
-	if (!(tmp = ast_calloc(1, sizeof(*tmp))))
+	if (!(tmp = ao2_alloc(sizeof(struct chan_iax2_pvt),iax2_destroy_byptr)))
 		return NULL;
 
 	if (ast_string_field_init(tmp, 32)) {
@@ -1515,7 +1579,7 @@
 		tmp = NULL;
 		return NULL;
 	}
-		
+	ast_log(LOG_NOTICE,"New IAX pvt created.\n");
 	tmp->prefs = prefs;
 	tmp->pingid = -1;
 	tmp->lagid = -1;
@@ -1635,10 +1699,10 @@
 			/* put it back in in the new spot */
 #define CHECK_LINK_B  { void *zzq = 
 #define CHECK_LINK_E  if (!zzq) ast_log(LOG_WARNING,"ao2_link failure! Check this out!");}
-			
-			CHECK_LINK_B
-			ao2_t_link(findcall2, iaxs[x], "moved to new pvt callno in trunk range");
-			CHECK_LINK_E
+			if (iaxs[x]->peercallno == 0)
+				CHECK_LINK_B
+				ao2_t_link(findcall2, iaxs[x], "moved to new pvt callno in trunk range");
+				CHECK_LINK_E
 			/* Update the two timers that should have been started */
 			iaxs[x]->pingid = iax2_sched_replace(iaxs[x]->pingid, sched, 
 				ping_time * 1000, send_ping, (void *)(long)x);
@@ -1694,7 +1758,8 @@
 	if (tmp_pvt_ptr == NULL) {
 		tmp_pvt_ptr = new_iax(NULL, "huh"); /* do this ONCE, and we can use it ever after that for hash lookups */
 	}
-	
+	ast_log(LOG_NOTICE,"find_callno called: callno=%d, dcallno=%d, sin=%s/%d, new=%d, sockfd=%d\n",
+			callno, dcallno, ast_inet_ntoa(sin->sin_addr), ntohs(sin->sin_port), new, sockfd);
 #ifdef OLD_CODE
 	if (new <= NEW_ALLOW) {
 		for (x=1;(res < 1) && (x<maxnontrunkcall);x++) {
@@ -1719,31 +1784,46 @@
 		}
 	}
 #endif
-	tmp_pvt_ptr->addr = *sin;
-	tmp_pvt_ptr->peercallno = callno;
-	respvt = ao2_t_find(findcall1, tmp_pvt_ptr, OBJ_POINTER, "Find the pvt in the findcall1 table");
-	/* keep looking ! */
-	if (respvt)
-		res = respvt->callno;
-	if (!res && callno == 0) {
-		tmp_pvt_ptr->callno = dcallno;
-		respvt = ao2_t_find(findcall2, tmp_pvt_ptr, OBJ_POINTER, "Find the pvt in the findcall1 table");
+	if (new <= NEW_ALLOW) {
+		tmp_pvt_ptr->addr.sin_addr.s_addr = sin->sin_addr.s_addr;
+		tmp_pvt_ptr->addr.sin_port = sin->sin_port;
+		tmp_pvt_ptr->peercallno = callno;
+		respvt = ao2_t_find(findcall1, tmp_pvt_ptr, OBJ_POINTER, "Find the pvt in the findcall1 table\n");
+		show_iaxs();
+		ast_log(LOG_NOTICE,"first lookup returns %p\n", respvt);
+		show_findcall1();
+		
+		/* keep looking ! */
 		if (respvt)
 			res = respvt->callno;
-	}
-	if (!res) {
-		tmp_pvt_ptr->callno = dcallno; /* just in case */
-		tmp_pvt_ptr->transfer = *sin;
-		respvt = ao2_t_find(findcall3, tmp_pvt_ptr, OBJ_POINTER, "Find the pvt in the findcall1 table");
-		if (respvt)
-			res = respvt->callno;
-	}
-	if (!res) {
-		tmp_pvt_ptr->transfercallno = dcallno;
-		/* transfer should still be in place from the previous test setup */
-		respvt = ao2_t_find(findcall4, tmp_pvt_ptr, OBJ_POINTER, "Find the pvt in the findcall1 table");
-		if (respvt)
-			res = respvt->callno;
+		if (!res) {
+			tmp_pvt_ptr->callno = dcallno;
+			tmp_pvt_ptr->peercallno = 0;
+			respvt = ao2_t_find(findcall2, tmp_pvt_ptr, OBJ_POINTER, "Find the pvt in the findcall1 table\n");
+			ast_log(LOG_NOTICE,"second lookup returns %p\n", respvt);
+			show_findcall2();
+			if (respvt)
+				res = respvt->callno;
+		}
+		if (!res) {
+			tmp_pvt_ptr->callno = dcallno; /* just in case */
+			tmp_pvt_ptr->transfer.sin_addr.s_addr = sin->sin_addr.s_addr;
+			tmp_pvt_ptr->transfer.sin_port = sin->sin_port;
+			respvt = ao2_t_find(findcall3, tmp_pvt_ptr, OBJ_POINTER, "Find the pvt in the findcall1 table\n");
+			ast_log(LOG_NOTICE,"third lookup returns %p\n", respvt);
+			show_findcall3();
+			if (respvt)
+				res = respvt->callno;
+		}
+		if (!res) {
+			tmp_pvt_ptr->transfercallno = dcallno;
+			/* transfer should still be in place from the previous test setup */
+			respvt = ao2_t_find(findcall4, tmp_pvt_ptr, OBJ_POINTER, "Find the pvt in the findcall1 table\n");
+			ast_log(LOG_NOTICE,"fourth lookup returns %p\n", respvt);
+			show_findcall4();
+			if (respvt)
+				res = respvt->callno;
+		}
 	}
 	
 	if ((res < 1) && (new >= NEW_ALLOW)) {
@@ -1770,6 +1850,8 @@
 		iaxs[x] = new_iax(sin, host);
 		update_max_nontrunk();
 		if (iaxs[x]) {
+			ast_log(LOG_NOTICE,"Creating new pvt structure: callid = %d. reason: not found.\n", x);
+			
 			if (iaxdebug)
 				ast_debug(1, "Creating new call structure %d\n", x);
 			iaxs[x]->sockfd = sockfd;
@@ -1791,9 +1873,10 @@
 			CHECK_LINK_B
 			ao2_t_link(findcall1, iaxs[x], "a new pvt is borne!");
 			CHECK_LINK_E
-			CHECK_LINK_B
-			ao2_t_link(findcall2, iaxs[x], "a new pvt is borne!");
-			CHECK_LINK_E
+			if (iaxs[x]->peercallno == 0)
+				CHECK_LINK_B
+			    ao2_t_link(findcall2, iaxs[x], "a new pvt is borne!");
+			    CHECK_LINK_E
 			/* it appears that findcall3 and findcall4 will not be linked, as the transferring field is 0 */
 		} else {
 			ast_log(LOG_WARNING, "Out of resources\n");
@@ -2326,6 +2409,13 @@
 	}
 
 	return 0;
+}
+
+
+static void iax2_destroy_byptr(void *p2)
+{
+	struct chan_iax2_pvt *pvt = p2;
+	iax2_destroy(pvt->callno);
 }
 
 static void iax2_destroy(int callno)
@@ -6572,9 +6662,10 @@
 			CHECK_LINK_B
 	ao2_t_link(findcall1, pvt, "Adding pvt back to findcall1, we changed addr/peercallno");
 			CHECK_LINK_E
-			CHECK_LINK_B
-	ao2_t_link(findcall2, pvt, "Removing pvt from findcall2, we changed addr");
-			CHECK_LINK_E
+	if (pvt->peercallno == 0)			
+		CHECK_LINK_B
+        ao2_t_link(findcall2, pvt, "Adding pvt back to findcall2, we changed addr");
+		CHECK_LINK_E
 	
 	AST_LIST_LOCK(&frame_queue);
 	AST_LIST_TRAVERSE(&frame_queue, cur, list) {
@@ -7758,6 +7849,7 @@
 		/* Stop if we don't have enough data */
 		if (len > packet_len)
 			break;
+		ast_log(LOG_NOTICE,"Calling find_callno\n");
 		fr->callno = find_callno(callno & ~IAX_FLAG_FULL, 0, sin, NEW_PREVENT, sockfd);
 		if (!fr->callno)
 			continue;
@@ -7943,6 +8035,7 @@
 		}
 
 		/* This is a video frame, get call number */
+		ast_log(LOG_NOTICE,"Calling find_callno\n");
 		fr->callno = find_callno(ntohs(vh->callno) & ~0x8000, dcallno, &sin, new, fd);
 		minivid = 1;
 	} else if ((meta->zeros == 0) && !(ntohs(meta->metacmd) & 0x8000))
@@ -7977,8 +8070,11 @@
 		f.subclass = 0;
 	}
 
-	if (!fr->callno)
+	if (!fr->callno) {
+		ast_log(LOG_NOTICE,"Calling find_callno\n");
 		fr->callno = find_callno(ntohs(mh->callno) & ~IAX_FLAG_FULL, dcallno, &sin, new, fd);
+	}
+	
 
 	if (fr->callno > 0)
 		ast_mutex_lock(&iaxsl[fr->callno]);
@@ -9583,6 +9679,7 @@
 
 	if (!reg->callno) {
 		ast_debug(1, "Allocate call number\n");
+		ast_log(LOG_NOTICE,"Calling find_callno\n");
 		reg->callno = find_callno(0, 0, &reg->addr, NEW_FORCE, defaultsockfd);
 		if (reg->callno < 1) {
 			ast_log(LOG_WARNING, "Unable to create call for registration\n");
@@ -9633,6 +9730,7 @@
 	memset(&ied, 0, sizeof(ied));
 	iax_ie_append_raw(&ied, IAX_IE_PROVISIONING, provdata.buf, provdata.pos);
 
+	ast_log(LOG_NOTICE,"Calling find_callno\n");
 	callno = find_callno(0, 0, &sin, NEW_FORCE, cai.sockfd);
 	if (!callno)
 		return -1;
@@ -9790,6 +9888,7 @@
 	}
 	if (heldcall)
 		ast_mutex_unlock(&iaxsl[heldcall]);
+	ast_log(LOG_NOTICE,"Calling find_callno\n");
 	peer->callno = find_callno(0, 0, &peer->addr, NEW_FORCE, peer->sockfd);
 	if (heldcall)
 		ast_mutex_lock(&iaxsl[heldcall]);
@@ -9870,6 +9969,7 @@
 	if (pds.port)
 		sin.sin_port = htons(atoi(pds.port));
 
+	ast_log(LOG_NOTICE,"Calling find_callno\n");
 	callno = find_callno(0, 0, &sin, NEW_FORCE, cai.sockfd);
 	if (callno < 1) {
 		ast_log(LOG_WARNING, "Unable to create call\n");
@@ -11273,6 +11373,7 @@
 	ast_debug(1, "peer: %s, username: %s, password: %s, context: %s\n",
 		pds.peer, pds.username, pds.password, pds.context);
 
+	ast_log(LOG_NOTICE,"Calling find_callno\n");
 	callno = find_callno(0, 0, &sin, NEW_FORCE, cai.sockfd);
 	if (callno < 1) {
 		ast_log(LOG_WARNING, "Unable to create call\n");
@@ -11992,14 +12093,14 @@
 		return AST_MODULE_LOAD_FAILURE;
 	}
 	findcall2 = ao2_container_alloc(hash_findcallno_size, findcall2_hash_cb, findcall2_cmp_cb);
-	if (!findcall1) {
+	if (!findcall2) {
 		ao2_ref(peers, -1);
 		ao2_ref(users, -1);
 		ao2_ref(findcall1, -1);
 		return AST_MODULE_LOAD_FAILURE;
 	}
 	findcall3 = ao2_container_alloc(hash_findcallno3_size, findcall3_hash_cb, findcall3_cmp_cb);
-	if (!findcall1) {
+	if (!findcall3) {
 		ao2_ref(peers, -1);
 		ao2_ref(users, -1);
 		ao2_ref(findcall1, -1);
@@ -12007,7 +12108,7 @@
 		return AST_MODULE_LOAD_FAILURE;
 	}
 	findcall4 = ao2_container_alloc(hash_findcallno4_size, findcall4_hash_cb, findcall4_cmp_cb);
-	if (!findcall1) {
+	if (!findcall4) {
 		ao2_ref(peers, -1);
 		ao2_ref(users, -1);
 		ao2_ref(findcall1, -1);

Modified: team/murf/bug11210/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug11210/channels/chan_sip.c?view=diff&rev=99779&r1=99778&r2=99779
==============================================================================
--- team/murf/bug11210/channels/chan_sip.c (original)
+++ team/murf/bug11210/channels/chan_sip.c Tue Jan 22 22:45:16 2008
@@ -2655,7 +2655,7 @@
 	int res = 0;
 	const struct sockaddr_in *dst = sip_real_dst(p);
 
-	ast_debug(1, "Trying to put '%.10s' onto %s socket...\n", data, get_transport(p->socket.type));
+	/* ast_log(LOG_DEBUG, "Trying to put '%.10s' onto %s socket...\n", data, get_transport(p->socket.type)); */
 
 	if (sip_prepare_socket(p) < 0)
 		return XMIT_ERROR;




More information about the asterisk-commits mailing list