[Asterisk-code-review] stun.c: Fix ast stun request() erratic timeout. (asterisk[13])

Joshua Colp asteriskteam at digium.com
Wed Apr 12 04:55:14 CDT 2017


Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/5435 )

Change subject: stun.c: Fix ast_stun_request() erratic timeout.
......................................................................


stun.c: Fix ast_stun_request() erratic timeout.

If ast_stun_request() receives packets other than a STUN response then we
could conceivably never exit if we continue to receive packets with less
than three seconds between them.

* Fix poll timeout to keep track of the time when we sent the STUN
request.  We will now send a STUN request every three seconds regardless
of how many other packets we receive while waiting for a response until we
have completed three STUN request transmission cycles.

Change-Id: Ib606cb08585e06eb50877f67b8d3bd385a85c266
---
M main/stun.c
1 file changed, 10 insertions(+), 1 deletion(-)

Approvals:
  George Joseph: Looks good to me, approved
  Anonymous Coward #1000019: Verified
  Joshua Colp: Looks good to me, but someone else must approve



diff --git a/main/stun.c b/main/stun.c
index f5bdc9a..fe1afba 100644
--- a/main/stun.c
+++ b/main/stun.c
@@ -413,6 +413,7 @@
 		/* send request, possibly wait for reply */
 		struct sockaddr_in src;
 		socklen_t srclen;
+		struct timeval start;
 
 		/* Send STUN message. */
 		res = stun_send(s, dst, req);
@@ -426,12 +427,20 @@
 			break;
 		}
 
+		start = ast_tvnow();
 try_again:
 		/* Wait for response. */
 		{
 			struct pollfd pfds = { .fd = s, .events = POLLIN };
+			int ms;
 
-			res = ast_poll(&pfds, 1, 3000);
+			ms = ast_remaining_ms(start, 3000);
+			if (ms <= 0) {
+				/* No response, timeout */
+				res = 1;
+				continue;
+			}
+			res = ast_poll(&pfds, 1, ms);
 			if (res < 0) {
 				/* Error */
 				continue;

-- 
To view, visit https://gerrit.asterisk.org/5435
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ib606cb08585e06eb50877f67b8d3bd385a85c266
Gerrit-PatchSet: 2
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>



More information about the asterisk-code-review mailing list