<p></p>
<p><b>@riccardv</b> commented on this pull request.</p>

<hr>

<p>In <a href="https://github.com/kamailio/kamailio/pull/2731#discussion_r629336057">src/modules/ims_ipsec_pcscf/cmd.c</a>:</p>
<pre style='color:#555'>> -        // for Reply and TCP sends from P-CSCF server port, for Reply and UDP sends from P-CSCF client port
-        src_port = dst_proto == PROTO_TCP ? s->port_ps : s->port_pc;
+        // Check send socket
+        struct socket_info * client_sock = grep_sock_info(via_host.af == AF_INET ? &ipsec_listen_addr : &ipsec_listen_addr6, src_port, dst_proto);
+        if(client_sock) {
+            // for Reply and TCP sends from P-CSCF server port, for Reply and UDP sends from P-CSCF client port
+            src_port = dst_proto == PROTO_TCP ? s->port_ps : s->port_pc;
 
-        // for Reply and TCP sends to UE client port, for Reply and UDP sends to UE server port
-        dst_port = dst_proto == PROTO_TCP ? s->port_uc : s->port_us;
+            // for Reply and TCP sends to UE client port, for Reply and UDP sends to UE server port
+            dst_port = dst_proto == PROTO_TCP ? s->port_uc : s->port_us;
+        }
+        else
+        {
+            src_port = s->port_pc;
+            dst_port = s->port_us;
+        }
</pre>
<p>Hi <a class="user-mention" data-hovercard-type="user" data-hovercard-url="/users/alexyosifov/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/alexyosifov">@alexyosifov</a> ,</p>
<p>without the patch the ports in case of TCP are always:<br>
src_port = s->port_ps<br>
dst_port = s->port_uc<br>
That are the ones used in case the user agent open the connection.</p>
<p>A pre check is necessary because if this socket is not already open, the use the ports:<br>
src_port = s->port_pc;<br>
dst_port = s->port_us;<br>
that are the port from Proxy Client (pc) -> User Server (us).<br>
Is a attempt to fallback to the other opened socket.</p>
<p>This case can be happens when INVITE transaction is very long due to long Ringing time phase.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/kamailio/kamailio/pull/2731#discussion_r629336057">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABO7UZNWG6C6YWXWIKW4G2TTM7J4TANCNFSM44PQXWGQ">unsubscribe</a>.<img src="https://github.com/notifications/beacon/ABO7UZMNVSMG2FZRDVESIZDTM7J4TA5CNFSM44PQXWG2YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOE4J5MWQ.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/kamailio/kamailio/pull/2731#discussion_r629336057",
"url": "https://github.com/kamailio/kamailio/pull/2731#discussion_r629336057",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>