[Asterisk-code-review] stun: Emit warning message when STUN request times out (asterisk[master])
Friendly Automation
asteriskteam at digium.com
Fri Jul 16 09:53:33 CDT 2021
Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/16144 )
Change subject: stun: Emit warning message when STUN request times out
......................................................................
stun: Emit warning message when STUN request times out
Without this message, it is not obvious that the reason is STUN timeout.
ASTERISK-29507 #close
Change-Id: I26e4853c23a1aed324552e1b9683ea3c05cb1f74
---
M main/stun.c
1 file changed, 21 insertions(+), 1 deletion(-)
Approvals:
Joshua Colp: Looks good to me, but someone else must approve
Sean Bright: Looks good to me, approved
Friendly Automation: Approved for Submit
diff --git a/main/stun.c b/main/stun.c
index e917944..4e9dac1 100644
--- a/main/stun.c
+++ b/main/stun.c
@@ -120,6 +120,8 @@
#define STUN_UNKNOWN_ATTRIBUTES 0x000a
#define STUN_REFLECTED_FROM 0x000b
+#define STUN_MAX_RETRIES 3
+
/*! \brief helper function to print message names */
static const char *stun_msg2str(int msg)
{
@@ -235,6 +237,22 @@
}
}
+static void handle_stun_timeout(int retry, struct sockaddr_in *dst)
+{
+ if (retry < STUN_MAX_RETRIES) {
+ ast_log(LOG_NOTICE,
+ "Attempt %d to send STUN request to '%s' timed out.",
+ retry,
+ ast_inet_ntoa(dst->sin_addr));
+ } else {
+ ast_log(LOG_WARNING,
+ "Attempt %d to send STUN request to '%s' timed out."
+ "Check that the server address is correct and reachable.\n",
+ retry,
+ ast_inet_ntoa(dst->sin_addr));
+ }
+}
+
/*! \brief wrapper to send an STUN message */
static int stun_send(int s, struct sockaddr_in *dst, struct stun_header *resp)
{
@@ -410,7 +428,7 @@
req->msglen = htons(reqlen);
req->msgtype = htons(STUN_BINDREQ);
- for (retry = 0; retry++ < 3;) { /* XXX make retries configurable */
+ for (retry = 0; retry++ < STUN_MAX_RETRIES;) { /* XXX make retries configurable */
/* send request, possibly wait for reply */
struct sockaddr_in src;
socklen_t srclen;
@@ -438,6 +456,7 @@
ms = ast_remaining_ms(start, 3000);
if (ms <= 0) {
/* No response, timeout */
+ handle_stun_timeout(retry, dst);
res = 1;
continue;
}
@@ -448,6 +467,7 @@
}
if (!res) {
/* No response, timeout */
+ handle_stun_timeout(retry, dst);
res = 1;
continue;
}
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/16144
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I26e4853c23a1aed324552e1b9683ea3c05cb1f74
Gerrit-Change-Number: 16144
Gerrit-PatchSet: 4
Gerrit-Owner: Sébastien Duthil <sduthil at wazo.community>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Sean Bright <sean at seanbright.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210716/ae48babb/attachment-0001.html>
More information about the asterisk-code-review
mailing list