<p>Joshua Colp <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/16166">View Change</a></p><div style="white-space:pre-wrap">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
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">stun: Emit warning message when STUN request times out<br><br>Without this message, it is not obvious that the reason is STUN timeout.<br><br>ASTERISK-29507 #close<br><br>Change-Id: I26e4853c23a1aed324552e1b9683ea3c05cb1f74<br>---<br>M main/stun.c<br>1 file changed, 21 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/main/stun.c b/main/stun.c</span><br><span>index e917944..4e9dac1 100644</span><br><span>--- a/main/stun.c</span><br><span>+++ b/main/stun.c</span><br><span>@@ -120,6 +120,8 @@</span><br><span> #define STUN_UNKNOWN_ATTRIBUTES 0x000a</span><br><span> #define STUN_REFLECTED_FROM 0x000b</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+#define STUN_MAX_RETRIES 3</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*! \brief helper function to print message names */</span><br><span> static const char *stun_msg2str(int msg)</span><br><span> {</span><br><span>@@ -235,6 +237,22 @@</span><br><span> }</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static void handle_stun_timeout(int retry, struct sockaddr_in *dst)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ if (retry < STUN_MAX_RETRIES) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_NOTICE,</span><br><span style="color: hsl(120, 100%, 40%);">+ "Attempt %d to send STUN request to '%s' timed out.",</span><br><span style="color: hsl(120, 100%, 40%);">+ retry,</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_inet_ntoa(dst->sin_addr));</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_WARNING,</span><br><span style="color: hsl(120, 100%, 40%);">+ "Attempt %d to send STUN request to '%s' timed out."</span><br><span style="color: hsl(120, 100%, 40%);">+ "Check that the server address is correct and reachable.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ retry,</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_inet_ntoa(dst->sin_addr));</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*! \brief wrapper to send an STUN message */</span><br><span> static int stun_send(int s, struct sockaddr_in *dst, struct stun_header *resp)</span><br><span> {</span><br><span>@@ -410,7 +428,7 @@</span><br><span> req->msglen = htons(reqlen);</span><br><span> req->msgtype = htons(STUN_BINDREQ);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- for (retry = 0; retry++ < 3;) { /* XXX make retries configurable */</span><br><span style="color: hsl(120, 100%, 40%);">+ for (retry = 0; retry++ < STUN_MAX_RETRIES;) { /* XXX make retries configurable */</span><br><span> /* send request, possibly wait for reply */</span><br><span> struct sockaddr_in src;</span><br><span> socklen_t srclen;</span><br><span>@@ -438,6 +456,7 @@</span><br><span> ms = ast_remaining_ms(start, 3000);</span><br><span> if (ms <= 0) {</span><br><span> /* No response, timeout */</span><br><span style="color: hsl(120, 100%, 40%);">+ handle_stun_timeout(retry, dst);</span><br><span> res = 1;</span><br><span> continue;</span><br><span> }</span><br><span>@@ -448,6 +467,7 @@</span><br><span> }</span><br><span> if (!res) {</span><br><span> /* No response, timeout */</span><br><span style="color: hsl(120, 100%, 40%);">+ handle_stun_timeout(retry, dst);</span><br><span> res = 1;</span><br><span> continue;</span><br><span> }</span><br><span></span><br></pre><div style="white-space:pre-wrap"></div><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/16166">change 16166</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/16166"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: I26e4853c23a1aed324552e1b9683ea3c05cb1f74 </div>
<div style="display:none"> Gerrit-Change-Number: 16166 </div>
<div style="display:none"> Gerrit-PatchSet: 5 </div>
<div style="display:none"> Gerrit-Owner: Sébastien Duthil <sduthil@wazo.community> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-Reviewer: Sean Bright <sean@seanbright.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>