]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
stun: Emit warning message when STUN request times out
authorSebastien Duthil <sduthil@wazo.community>
Wed, 30 Jun 2021 22:15:10 +0000 (18:15 -0400)
committerFriendly Automation <jenkins2@gerrit.asterisk.org>
Fri, 16 Jul 2021 14:53:32 +0000 (09:53 -0500)
Without this message, it is not obvious that the reason is STUN timeout.

ASTERISK-29507 #close

Change-Id: I26e4853c23a1aed324552e1b9683ea3c05cb1f74

main/stun.c

index e917944a60a65e80a61b3b9d8d4b5ee246b3dcee..4e9dac18af71839f84ee0f0e4cd4c9e2acefb447 100644 (file)
@@ -120,6 +120,8 @@ struct stun_addr {
 #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 append_attr_address(struct stun_attr **attr, int attrval, struct soc
        }
 }
 
+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 @@ int ast_stun_request(int s, struct sockaddr_in *dst,
        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 @@ try_again:
                        ms = ast_remaining_ms(start, 3000);
                        if (ms <= 0) {
                                /* No response, timeout */
+                               handle_stun_timeout(retry, dst);
                                res = 1;
                                continue;
                        }
@@ -448,6 +467,7 @@ try_again:
                        }
                        if (!res) {
                                /* No response, timeout */
+                               handle_stun_timeout(retry, dst);
                                res = 1;
                                continue;
                        }