<div dir="ltr">Hi,<br><br>I've done a bit more digging and realised that $conid is read-only, and only available for an inbound connection - so I dont think it will achieve what I need.<div><br></div><div>I did a bit more troubleshooting and observed the differences in the debug log between two identical calls:<div><br>This example failed - the INVITEs went out to the incorrect endpoint / TCP connection. The "ulc_conid" from the location table for the TCP endpoint is 13:<br><br></div><div><font face="monospace">Mar  9 10:30:20 proxy-01 /sbin/kamailio[27014]: ERROR: <script>: Adding to main branch. ua: Yealink SIP-T42G 29.83.0.120 ru: <a href="http://sip:442079460000@10.0.130.218:5060" target="_blank">sip:442079460000@10.0.130.218:5060</a> du: sip:<a href="http://203.0.113.1:1046" target="_blank">203.0.113.1:1046</a> ulc_conid: 0 flags: 192 ci: 162e3e84-4036-48d7-a1d1-79cc92b7cea4-2-1@sip-server-01<br>Mar  9 10:30:20 proxy-01 /sbin/kamailio[27014]: ERROR: <script>: Adding to child branch. ua: Yealink SIP-T58 58.85.0.5 ru: sip:442079460000@10.0.130.241:50130;transport=TCP du: sip:203.0.113.1:50130;transport=tcp ulc_conid: 13  flags: 192 ci: 162e3e84-4036-48d7-a1d1-79cc92b7cea4-2-1@sip-server-01<br><br></font>The debug log shows the wrong connection was found <i>by id, </i>which in this case was 2, but should have been 13:</div><div><br><font face="monospace">Mar  9 10:30:21 proxy-01 /sbin/kamailio[27014]: INFO: <script>: ONSEND: rm: INVITE ru: <a href="http://sip:442079460000@10.0.130.218:5060" target="_blank">sip:442079460000@10.0.130.218:5060</a> du: sip:<a href="http://203.0.113.1:1046" target="_blank">203.0.113.1:1046</a> proto: udp src: <a href="http://185.28.212.61:5060" target="_blank">185.28.212.61:5060</a> dest: <a href="http://203.0.113.1:1046" target="_blank">203.0.113.1:1046</a> ci: 162e3e84-4036-48d7-a1d1-79cc92b7cea4-2-1@sip-server-01</font><br><font face="monospace">Mar  9 10:30:21 proxy-01 /sbin/kamailio[27014]: INFO: <script>: ONSEND: rm: INVITE ru: <a href="http://sip:442079460000@10.0.130.218:5060" target="_blank">sip:442079460000@10.0.130.218:5060</a> du: sip:<a href="http://203.0.113.1:1046" target="_blank">203.0.113.1:1046</a> proto: tcp src: <a href="http://185.28.212.61:5062" target="_blank">185.28.212.61:5062</a> dest: <a href="http://203.0.113.1:50130" target="_blank">203.0.113.1:50130</a> ci: 162e3e84-4036-48d7-a1d1-79cc92b7cea4-2-1@sip-server-01</font><br><font face="monospace">Mar  9 10:30:21 proxy-01 /sbin/kamailio[27014]: DEBUG: <core> [core/tcp_main.c:1651]: _tcpconn_find(): found connection by id: 2</font><br><font face="monospace">Mar  9 10:30:21 proxy-01 /sbin/kamailio[27014]: DEBUG: <core> [core/tcp_main.c:2545]: tcpconn_send_put(): found fd in cache (5, 0x7fedc49d2448, 2)</font><br><br>This example worked - the INVITEs went out to the correct endpoints / TCP connections. The "ulc_conid" from the location table for the TCP endpoint is still 13:</div><div><br><font face="monospace">Mar  9 10:42:30 proxy-01 /sbin/kamailio[27016]: ERROR: <script>: Adding to main branch. ua: Yealink SIP-T42G 29.83.0.120 ru: <a href="http://sip:442079460000@10.0.130.218:5060" target="_blank">sip:442079460000@10.0.130.218:5060</a> du: sip:<a href="http://203.0.113.1:1046" target="_blank">203.0.113.1:1046</a> ulc_conid: 0 flags: 192 ci: 95ba0691-bdfc-4293-b99d-d46946cb5180-2-1@sip-server-01<br>Mar  9 10:42:30 proxy-01 /sbin/kamailio[27016]: ERROR: <script>: Adding to child branch. ua: Yealink SIP-T58 58.85.0.5 ru: sip:442079460000@10.0.130.241:50130;transport=TCP du: sip:203.0.113.1:50130;transport=tcp ulc_conid: 13 flags: 192 ci: 95ba0691-bdfc-4293-b99d-d46946cb5180-2-1@sip-server-01</font><br><br>The debug log shows the correct connection was found <i>by peer address </i>and determined the correct connection 13:</div><div><br><font face="monospace">Mar  9 10:42:31 proxy-01 /sbin/kamailio[27016]: INFO: <script>: ONSEND: rm: INVITE ru: <a href="http://sip:442079460000@10.0.130.218:5060" target="_blank">sip:442079460000@10.0.130.218:5060</a> du: sip:<a href="http://203.0.113.1:1046" target="_blank">203.0.113.1:1046</a> proto: udp src: <a href="http://185.28.212.61:5060" target="_blank">185.28.212.61:5060</a> dest: <a href="http://203.0.113.1:1046" target="_blank">203.0.113.1:1046</a> conid: <null> ci: 95ba0691-bdfc-4293-b99d-d46946cb5180-2-1@sip-server-01<br>Mar  9 10:42:31 proxy-01 /sbin/kamailio[27016]: INFO: <script>: ONSEND: rm: INVITE ru: <a href="http://sip:442079460000@10.0.130.218:5060" target="_blank">sip:442079460000@10.0.130.218:5060</a> du: sip:<a href="http://203.0.113.1:1046" target="_blank">203.0.113.1:1046</a> proto: tcp src: <a href="http://185.28.212.61:5062" target="_blank">185.28.212.61:5062</a> dest: <a href="http://203.0.113.1:50130" target="_blank">203.0.113.1:50130</a> conid: <null> ci: 95ba0691-bdfc-4293-b99d-d46946cb5180-2-1@sip-server-01<br>Mar  9 10:42:31 proxy-01 /sbin/kamailio[27016]: DEBUG: <core> [core/tcp_main.c:1670]: _tcpconn_find(): found connection by peer address (id: 13)<br>Mar  9 10:42:31 proxy-01 /sbin/kamailio[27016]: DEBUG: <core> [core/tcp_main.c:2548]: tcpconn_send_put(): tcp connection found (0x7fedc49ce0e8), acquiring fd<br></font><br>Additionally I checked the connection IDs and IPs / Ports before a failed and working call and they had not changed, it was the same TCP connection - so it doesn't appear to be some interaction with a connection closing or changing. We also don't see this issue using <font face="arial, sans-serif">the standard <span style="background-color:rgb(252,255,252);color:rgb(0,0,0)">lookup</span>() function.</font><br><br>Does anyone know why Kamailio is intermittently switching between finding by peer address and id, and why it's using the wrong ID? <br><br>Thanks again<br>Matthew<br><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Mar 9, 2021 at 8:56 AM Marrold <<a href="mailto:kamailio@marrold.co.uk" target="_blank">kamailio@marrold.co.uk</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi all,<div><br></div><div>I'm currently adding a feature to our Kamailio configuration to fork calls based on user agent.</div><div><br></div><div>To do so I'm getting the registered endpoints with reg_fetch_contacts() iterating through and matching on them, then using seturi() / append_branch() and setting the dst-uri and flags as required.</div><div><br></div><div>However, calls are intermittently going to the wrong TCP connection, despite the logs showing the correct destination IP and port in the ONSEND route.</div><div><br></div><div>Looking in the location table I can see each registration has a connection_id, and the debug log indicates it's finding the connection by ID:</div><div><br></div><div> DEBUG: <core> [core/tcp_main.c:1651]: _tcpconn_find(): found connection by id: 3<br></div><div><br></div><div>Is there a way to set the conid per branch? Is it necessary?<br></div><div><br></div><div>We're using kamailio 5.3.3 on Debian 10.</div><div><br></div><div>Thanks</div><div>Matthew</div></div>
</blockquote></div>