[Asterisk-code-review] stun: Emit warning message when STUN request times out (asterisk[16])
Joshua Colp
asteriskteam at digium.com
Mon Jul 19 06:54:57 CDT 2021
Joshua Colp has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/16166 )
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; Approved for Submit
Sean Bright: Looks good to me, approved
George Joseph: Looks good to me, but someone else must approve
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/+/16166
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: I26e4853c23a1aed324552e1b9683ea3c05cb1f74
Gerrit-Change-Number: 16166
Gerrit-PatchSet: 5
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/20210719/b27d2807/attachment.html>
More information about the asterisk-code-review
mailing list