Skip to content
Snippets Groups Projects
Commit 4bd975f4 authored by Sebastien Duthil's avatar Sebastien Duthil Committed by Joshua Colp
Browse files

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
parent 76c09b1c
No related branches found
No related tags found
1 merge request!48asterisk uplift to 18.11.2
...@@ -120,6 +120,8 @@ struct stun_addr { ...@@ -120,6 +120,8 @@ struct stun_addr {
#define STUN_UNKNOWN_ATTRIBUTES 0x000a #define STUN_UNKNOWN_ATTRIBUTES 0x000a
#define STUN_REFLECTED_FROM 0x000b #define STUN_REFLECTED_FROM 0x000b
#define STUN_MAX_RETRIES 3
/*! \brief helper function to print message names */ /*! \brief helper function to print message names */
static const char *stun_msg2str(int msg) static const char *stun_msg2str(int msg)
{ {
...@@ -235,6 +237,22 @@ static void append_attr_address(struct stun_attr **attr, int attrval, struct soc ...@@ -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 */ /*! \brief wrapper to send an STUN message */
static int stun_send(int s, struct sockaddr_in *dst, struct stun_header *resp) 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, ...@@ -410,7 +428,7 @@ int ast_stun_request(int s, struct sockaddr_in *dst,
req->msglen = htons(reqlen); req->msglen = htons(reqlen);
req->msgtype = htons(STUN_BINDREQ); 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 */ /* send request, possibly wait for reply */
struct sockaddr_in src; struct sockaddr_in src;
socklen_t srclen; socklen_t srclen;
...@@ -438,6 +456,7 @@ try_again: ...@@ -438,6 +456,7 @@ try_again:
ms = ast_remaining_ms(start, 3000); ms = ast_remaining_ms(start, 3000);
if (ms <= 0) { if (ms <= 0) {
/* No response, timeout */ /* No response, timeout */
handle_stun_timeout(retry, dst);
res = 1; res = 1;
continue; continue;
} }
...@@ -448,6 +467,7 @@ try_again: ...@@ -448,6 +467,7 @@ try_again:
} }
if (!res) { if (!res) {
/* No response, timeout */ /* No response, timeout */
handle_stun_timeout(retry, dst);
res = 1; res = 1;
continue; continue;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment