<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Hello,</p>
    <p>can you try with master branch to use sbranch-related functions
      from pv module along with the result from reg_fetch_contact().</p>
    <p>Cheers,<br>
      Daniel<br>
    </p>
    <div class="moz-cite-prefix">On 19.03.21 11:13, Marrold wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAC-Lcd_P7EcEFDgbNBH=w8zCp=DT4cuKZPLCDmbZP7sQP8ky4Q@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">We don't see the issue when using the standard
        lookup() function, only when we start manually appending
        branches with the results from  reg_fetch_contact()
        <div><br>
        </div>
        <div>Thanks</div>
        <div>Matthew</div>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr" class="gmail_attr">On Wed, Mar 17, 2021 at 7:18
          AM Daniel-Constantin Mierla <<a
            href="mailto:miconda@gmail.com" moz-do-not-send="true">miconda@gmail.com</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>
            <p>Hello,</p>
            <p><br>
            </p>
            <div>On 11.03.21 10:55, Marrold wrote:<br>
            </div>
            <blockquote type="cite">
              <div dir="ltr">Hi Daniel,
                <div><br>
                </div>
                <div>I didn't spot those TCPOPs functions, I'll give
                  them a try and let you know how I get on.</div>
                <div><br>
                </div>
                <div>Do you have any idea why Kamailio is
                  intermittently selecting the wrong connection using ID
                  vs peer address? <br>
                </div>
              </div>
            </blockquote>
            <p><br>
            </p>
            <p>have you tried and got that with lookup("location") or
              only with your script-based reg_fetch_contact()?</p>
            <p>Cheers,<br>
              Daniel<br>
            </p>
            <blockquote type="cite">
              <div dir="ltr">
                <div><br>
                </div>
                <div>Thanks for the suggestions.</div>
                <div>Matthew</div>
              </div>
              <br>
              <div class="gmail_quote">
                <div dir="ltr" class="gmail_attr">On Wed, Mar 10, 2021
                  at 7:27 AM Daniel-Constantin Mierla <<a
                    href="mailto:miconda@gmail.com" target="_blank"
                    moz-do-not-send="true">miconda@gmail.com</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>
                    <p>Hello,</p>
                    <p>a while ago I did some work to make possible to
                      specify the outgoing tcp connection id, see:</p>
                    <p>  * <a
href="https://www.kamailio.org/docs/modules/stable/modules/tcpops.html#tcpops.f.tcp_set_otcpid"
                        target="_blank" moz-do-not-send="true">https://www.kamailio.org/docs/modules/stable/modules/tcpops.html#tcpops.f.tcp_set_otcpid</a></p>
                    <p>And the next function after it.</p>
                    <p>However, the testing was minimal, maybe not
                      verifying the entire chain with
                      t_relay()/forward(). Even more, the specifying of
                      the outbound tcp connection was supposed to be
                      done internally by the lookup("location"), the
                      functions from tcpops being added for more config
                      flexibility, suitable for single branch forwarding
                      or branch_route blocks.</p>
                    <p>However, in your seem to do manual processing
                      with reg_fetch_contacts(), not rely on lookup
                      location. You can test with master and use
                      $sbranch(...) and corresponding functions from pv
                      module, instead of setting the r-uri and
                      append_branch().</p>
                    <p>Cheers,<br>
                      Daniel<br>
                    </p>
                    <div>On 10.03.21 06:00, Marrold wrote:<br>
                    </div>
                    <blockquote type="cite">
                      <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" moz-do-not-send="true">sip:442079460000@10.0.130.218:5060</a>
                              du: sip:<a href="http://203.0.113.1:1046"
                                target="_blank" moz-do-not-send="true">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: <a
                                moz-do-not-send="true">sip:442079460000@10.0.130.241:50130;transport=TCP</a>
                              du: <a moz-do-not-send="true">sip:203.0.113.1:50130;transport=tcp</a>
                              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"
                                moz-do-not-send="true">sip:442079460000@10.0.130.218:5060</a>
                              du: sip:<a href="http://203.0.113.1:1046"
                                target="_blank" moz-do-not-send="true">203.0.113.1:1046</a>
                              proto: udp src: <a
                                href="http://185.28.212.61:5060"
                                target="_blank" moz-do-not-send="true">185.28.212.61:5060</a>
                              dest: <a href="http://203.0.113.1:1046"
                                target="_blank" moz-do-not-send="true">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"
                                moz-do-not-send="true">sip:442079460000@10.0.130.218:5060</a>
                              du: sip:<a href="http://203.0.113.1:1046"
                                target="_blank" moz-do-not-send="true">203.0.113.1:1046</a>
                              proto: tcp src: <a
                                href="http://185.28.212.61:5062"
                                target="_blank" moz-do-not-send="true">185.28.212.61:5062</a>
                              dest: <a href="http://203.0.113.1:50130"
                                target="_blank" moz-do-not-send="true">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" moz-do-not-send="true">sip:442079460000@10.0.130.218:5060</a>
                              du: sip:<a href="http://203.0.113.1:1046"
                                target="_blank" moz-do-not-send="true">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: <a
                                moz-do-not-send="true">sip:442079460000@10.0.130.241:50130;transport=TCP</a>
                              du: <a moz-do-not-send="true">sip:203.0.113.1:50130;transport=tcp</a>
                              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"
                                moz-do-not-send="true">sip:442079460000@10.0.130.218:5060</a>
                              du: sip:<a href="http://203.0.113.1:1046"
                                target="_blank" moz-do-not-send="true">203.0.113.1:1046</a>
                              proto: udp src: <a
                                href="http://185.28.212.61:5060"
                                target="_blank" moz-do-not-send="true">185.28.212.61:5060</a>
                              dest: <a href="http://203.0.113.1:1046"
                                target="_blank" moz-do-not-send="true">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"
                                moz-do-not-send="true">sip:442079460000@10.0.130.218:5060</a>
                              du: sip:<a href="http://203.0.113.1:1046"
                                target="_blank" moz-do-not-send="true">203.0.113.1:1046</a>
                              proto: tcp src: <a
                                href="http://185.28.212.61:5062"
                                target="_blank" moz-do-not-send="true">185.28.212.61:5062</a>
                              dest: <a href="http://203.0.113.1:50130"
                                target="_blank" moz-do-not-send="true">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" moz-do-not-send="true">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>
                      <br>
                      <fieldset></fieldset>
                      <pre>_______________________________________________
Kamailio (SER) - Users Mailing List
<a href="mailto:sr-users@lists.kamailio.org" target="_blank" moz-do-not-send="true">sr-users@lists.kamailio.org</a>
<a href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users" target="_blank" moz-do-not-send="true">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a>
</pre>
                    </blockquote>
                    <pre cols="72">-- 
Daniel-Constantin Mierla -- <a href="http://www.asipto.com" target="_blank" moz-do-not-send="true">www.asipto.com</a>
<a href="http://www.twitter.com/miconda" target="_blank" moz-do-not-send="true">www.twitter.com/miconda</a> -- <a href="http://www.linkedin.com/in/miconda" target="_blank" moz-do-not-send="true">www.linkedin.com/in/miconda</a>
Funding: <a href="https://www.paypal.me/dcmierla" target="_blank" moz-do-not-send="true">https://www.paypal.me/dcmierla</a></pre>
                  </div>
                </blockquote>
              </div>
            </blockquote>
            <pre cols="72">-- 
Daniel-Constantin Mierla -- <a href="http://www.asipto.com" target="_blank" moz-do-not-send="true">www.asipto.com</a>
<a href="http://www.twitter.com/miconda" target="_blank" moz-do-not-send="true">www.twitter.com/miconda</a> -- <a href="http://www.linkedin.com/in/miconda" target="_blank" moz-do-not-send="true">www.linkedin.com/in/miconda</a>
Funding: <a href="https://www.paypal.me/dcmierla" target="_blank" moz-do-not-send="true">https://www.paypal.me/dcmierla</a></pre>
          </div>
        </blockquote>
      </div>
    </blockquote>
    <pre class="moz-signature" cols="72">-- 
Daniel-Constantin Mierla -- <a class="moz-txt-link-abbreviated" href="http://www.asipto.com">www.asipto.com</a>
<a class="moz-txt-link-abbreviated" href="http://www.twitter.com/miconda">www.twitter.com/miconda</a> -- <a class="moz-txt-link-abbreviated" href="http://www.linkedin.com/in/miconda">www.linkedin.com/in/miconda</a>
Funding: <a class="moz-txt-link-freetext" href="https://www.paypal.me/dcmierla">https://www.paypal.me/dcmierla</a></pre>
  </body>
</html>