<p>Walter Doekes has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/6470">View Change</a></p><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;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/70/6470/1</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 9110a1c..e095f06 100644<br>--- a/res/res_pjsip_sdp_rtp.c<br>+++ b/res/res_pjsip_sdp_rtp.c<br>@@ -1807,7 +1807,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>@@ -1815,10 +1815,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 b997024..64416a0 100644<br>--- a/res/res_pjsip_session.c<br>+++ b/res/res_pjsip_session.c<br>@@ -3976,12 +3976,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 6dec6ef..48cbab3 100644<br>--- a/res/res_pjsip_t38.c<br>+++ b/res/res_pjsip_t38.c<br>@@ -952,7 +952,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>@@ -960,10 +960,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/6470">change 6470</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/6470"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 15 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I566be1c33f4d0a689567d451ed46bab9c3861d4f </div>
<div style="display:none"> Gerrit-Change-Number: 6470 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Walter Doekes <walter+asterisk@wjd.nu> </div>