<div dir="ltr">

<p class="MsoNormal">Hello.</p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">In a test environment, I've been able to use the
"new_conn_alias_flags" option to solve a NAT problem, but I'm
concerned that the option is not supported/safe.</p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">It seems the option is not documented, and cannot be used in
the config file, because 'cfg.y' doesn't support parsing it. However, it can be
set at runtime using a command such as the following:</p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">kamctl kamcmd cfg.set_now_int tcp new_conn_alias_flags 1</p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">**Question #1**</p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">Is this option experimental and/or risky?</p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">As background, I will now try to describe my NAT problem.
Perhaps there is an alternate way to solve my problem which doesn't require
using "new_conn_alias_flags".</p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">My server architecture uses multiple Kamailio edge proxies,
and a single central Kamailio registrar. The edge proxies listen on multiple
TLS ports. All servers are on version 4.3.3.

</p><p class="MsoNormal"><br></p><p class="MsoNormal">My client app includes a port tester, which periodically
tests whether certain SIP proxy targets are reachable. These test connections
are very brief, and don’t persist.</p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">The problem seems to relate to a behavior of iptables as
follows:</p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">Client A and client B are both behind the same iptables NAT.</p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">Client A has a persistent TLS connection to one of the
proxies.</p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">Client B is doing periodic port testing, and sometimes, the
itpables NAT will assign exactly the same external IP and port for a test
connection as is already being used by client A for its persistent connection,
to the same SIP proxy IP. Only the SIP proxy target port is different.</p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">To better explain, I will list out examples for all the
relevant IPs and ports along the paths. The IPs and ports I've selected are
arbitrary.</p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">Client A persistent TLS connection</p>

<p class="MsoNormal">----------------------------------</p>

<p class="MsoNormal">Internal IP:Port = <a href="http://10.10.10.100:30000">10.10.10.100:30000</a></p>

<p class="MsoNormal">External IP:Port = <a href="http://88.88.88.88:10000">88.88.88.88:10000</a></p>

<p class="MsoNormal">SIP proxy IP:Port = <a href="http://66.66.66.66:5061">66.66.66.66:5061</a></p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">Client B port test connection</p>

<p class="MsoNormal">------------------------------</p>

<p class="MsoNormal">Internal IP:Port = <a href="http://10.10.10.101:35000">10.10.10.101:35000</a></p>

<p class="MsoNormal">External IP:Port = <a href="http://88.88.88.88:10000">88.88.88.88:10000</a> *** Same as above!</p>

<p class="MsoNormal">SIP proxy IP:Port = <a href="http://66.66.66.66:443">66.66.66.66:443</a> *** SIP proxy port being
different is the only thing that makes this a distinct TCP connection from
above.</p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">When this happens, it seems that some of the TCP
connection/alias hash tables inside Kamailio are modified such that future
attempts to call client A may fail. Client B's port test connection seems to overwrite some of
the state which was important for connections into Client A. After client B's test connection has stomped on client A's state, this is what happens:</p><p class="MsoNormal"><br></p><p class="MsoNormal"></p><p class="MsoNormal">When an INVITE sent to client A arrives at the proxy, the
proxy fails to find the matching persistent TLS connection which already exists,
so it tries to open a new outbound TLS connection to client A, but that always fails
because client A's NAT doesn't allow it. Such calls end up failing with a 408
timeout error.</p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">I added some extra logging to the TCP connection/alias hash
code paths, and I can see some of the client A entries being overwritten when
client B makes its test connection.</p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">Did I explain that well enough? I know it's a bit confusing.</p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">Anyway, after doing some code inspection, I noticed that the
"new_conn_alias_flags" option seemed like it might improve this
problem, or at least change the behavior. It turns out that setting
"new_conn_alias_flags" equal to 1 seems to solve my problem. With
that setting, client B's test connections do not overwrite any of the TCP
connection hashes/aliases for client A's persistent TLS connection, and calls
into client A never seem to fail.</p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">**Question #2**</p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">Does setting "new_conn_alias_flags" to 1 seem like
a good way to address my type of problem? If not, is there an alternate way to
solve my problem? Perhaps there are some things I should be doing with the NAT
helper module that could fix the issue without relying on
"new_conn_alias_flags"?</p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">I realize that I may need to provide more information to
answer these questions fully, but I’m initially hoping to just get some
high-level impressions, without going into a ton of details.</p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">Thanks.</p>

</div>