<p>Joshua Colp <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/6468">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Jenkins2: Verified
  Joshua Colp: Looks good to me, approved; Approved for Submit

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res/res_pjsip: Fix localnet checks in pjsip, part 2.<br><br>In 45744fc53, I mistakenly broke SDP media address rewriting by<br>misinterpreting which address was checked in the localnet comparison.<br><br>Instead of checking the remote peer address to decide whether we need<br>media address rewriting, we check our local media address: if it's<br>local, then we rewrite. This feels awkward, but works and even made<br>directmedia work properly if you set local_net. (For the record: for<br>local peers, the SDP media rewrite code is not called, so the<br>comparison does no harm there.)<br><br>ASTERISK-27248 #close<br><br>Change-Id: I566be1c33f4d0a689567d451ed46bab9c3861d4f<br>---<br>M res/res_pjsip_sdp_rtp.c<br>M res/res_pjsip_session.c<br>M res/res_pjsip_t38.c<br>3 files changed, 21 insertions(+), 11 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/res/res_pjsip_sdp_rtp.c b/res/res_pjsip_sdp_rtp.c<br>index b8ae8c1..16ffaca 100644<br>--- a/res/res_pjsip_sdp_rtp.c<br>+++ b/res/res_pjsip_sdp_rtp.c<br>@@ -1506,7 +1506,7 @@<br> {<br>       RAII_VAR(struct ast_sip_transport_state *, transport_state, ast_sip_get_transport_state(ast_sorcery_object_get_id(transport)), ao2_cleanup);<br>  char host[NI_MAXHOST];<br>-       struct ast_sockaddr addr = { { 0, } };<br>+       struct ast_sockaddr our_sdp_addr = { { 0, } };<br> <br>     /* If the stream has been rejected there will be no connection line */<br>        if (!stream->conn || !transport_state) {<br>@@ -1514,10 +1514,13 @@<br>  }<br> <br>  ast_copy_pj_str(host, &stream->conn->addr, sizeof(host));<br>-  ast_sockaddr_parse(&addr, host, PARSE_PORT_FORBID);<br>+      ast_sockaddr_parse(&our_sdp_addr, host, PARSE_PORT_FORBID);<br> <br>-   /* Is the address within the SDP inside the same network? */<br>- if (ast_sip_transport_is_local(transport_state, &addr)) {<br>+        /* Reversed check here. We don't check the remote endpoint being<br>+  * in our local net, but whether our outgoing session IP is<br>+   * local. If it is not, we won't do rewriting. No localnet<br>+        * configured? Always rewrite. */<br>+    if (ast_sip_transport_is_nonlocal(transport_state, &our_sdp_addr) && transport_state->localnet) {<br>              return;<br>       }<br>     ast_debug(5, "Setting media address to %s\n", ast_sockaddr_stringify_host(&transport_state->external_media_address));<br>diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c<br>index ab6fce2..3d73862 100644<br>--- a/res/res_pjsip_session.c<br>+++ b/res/res_pjsip_session.c<br>@@ -3190,12 +3190,16 @@<br> <br>       if (sdp->conn) {<br>           char host[NI_MAXHOST];<br>-               struct ast_sockaddr addr = { { 0, } };<br>+               struct ast_sockaddr our_sdp_addr = { { 0, } };<br> <br>             ast_copy_pj_str(host, &sdp->conn->addr, sizeof(host));<br>-             ast_sockaddr_parse(&addr, host, PARSE_PORT_FORBID);<br>+              ast_sockaddr_parse(&our_sdp_addr, host, PARSE_PORT_FORBID);<br> <br>-           if (ast_sip_transport_is_nonlocal(transport_state, &addr)) {<br>+             /* Reversed check here. We don't check the remote<br>+                 * endpoint being in our local net, but whether our<br>+           * outgoing session IP is local. If it is, we'll do<br>+               * rewriting. No localnet configured? Always rewrite. */<br>+             if (ast_sip_transport_is_local(transport_state, &our_sdp_addr) || !transport_state->localnet) {<br>                        ast_debug(5, "Setting external media address to %s\n", ast_sockaddr_stringify_host(&transport_state->external_media_address));<br>                       pj_strdup2(tdata->pool, &sdp->conn->addr, ast_sockaddr_stringify_host(&transport_state->external_media_address));<br>                 }<br>diff --git a/res/res_pjsip_t38.c b/res/res_pjsip_t38.c<br>index 58da6a0..5f04f0e 100644<br>--- a/res/res_pjsip_t38.c<br>+++ b/res/res_pjsip_t38.c<br>@@ -871,7 +871,7 @@<br> {<br>       RAII_VAR(struct ast_sip_transport_state *, transport_state, ast_sip_get_transport_state(ast_sorcery_object_get_id(transport)), ao2_cleanup);<br>  char host[NI_MAXHOST];<br>-       struct ast_sockaddr addr = { { 0, } };<br>+       struct ast_sockaddr our_sdp_addr = { { 0, } };<br> <br>     /* If the stream has been rejected there will be no connection line */<br>        if (!stream->conn || !transport_state) {<br>@@ -879,10 +879,13 @@<br>    }<br> <br>  ast_copy_pj_str(host, &stream->conn->addr, sizeof(host));<br>-  ast_sockaddr_parse(&addr, host, PARSE_PORT_FORBID);<br>+      ast_sockaddr_parse(&our_sdp_addr, host, PARSE_PORT_FORBID);<br> <br>-   /* Is the address within the SDP inside the same network? */<br>- if (ast_sip_transport_is_local(transport_state, &addr)) {<br>+        /* Reversed check here. We don't check the remote endpoint being<br>+  * in our local net, but whether our outgoing session IP is<br>+   * local. If it is not, we won't do rewriting. No localnet<br>+        * configured? Always rewrite. */<br>+    if (ast_sip_transport_is_nonlocal(transport_state, &our_sdp_addr) && transport_state->localnet) {<br>              return;<br>       }<br>     ast_debug(5, "Setting media address to %s\n", ast_sockaddr_stringify_host(&transport_state->external_media_address));<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/6468">change 6468</a>. To unsubscribe, 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/6468"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I566be1c33f4d0a689567d451ed46bab9c3861d4f </div>
<div style="display:none"> Gerrit-Change-Number: 6468 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Walter Doekes <walter+asterisk@wjd.nu> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>