<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>The $Rp is intended to give the attribute of the listen socket
      associated with the SIP traffic. It is not taken from the IP
      layer, maybe another variable can be done if people need it.</p>
    <p>I didn't get the chance to look at the logs and the code, but I
      guess that not being an exact match of port with one of listen
      sockets, then the first is selected.</p>
    <p>As I understood in this discussion, a VIP (or advertised/firewall
      IP) is involved, not sure if this has any impact in matching.</p>
    <p>For SIP traffic, there might be ways to improve the matching once
      parsing some headers (e.g., using top Via for replies).</p>
    <p>I am not sure it can be seen as a bug, due to how tcp works and
      what $Rp is intended to do, but can be an enhancement to introduce
      additional matching modes or variables for IP layer for local
      receiving port.</p>
    <p>Cheers,<br>
      Daniel<br>
    </p>
    <div class="moz-cite-prefix">On 24.06.21 19:12, Giacomo Vacca wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAO6UKa3CofZYLpW2sN2iRW-=E8TOjjrY7bJBWCdyvU5m6RLhAw@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">No worries Shahid,
        <div>mine wasn't really a suggestion for a fix, but I wanted to
          verify a suspicion I had, since I saw a similar behaviour with
          a certain number of listen directives for TCP sockets.</div>
        <div><br>
        </div>
        <div>I did notice that, when Kamilio establishes a TCP
          connection, from a port selected from the OS, e.g. 39235 in
          your example, responses or requests received on that same
          connection, instead of showing 39235 for $Rp were showing the
          port of the first listening TCP directive (e.g. 8080 in your
          case, or 5060 once you swapped the listening directives).</div>
        <div><br>
        </div>
        <div>I take this opportunity to ask the community whether this
          behaviour is expected or a symptom of something that needs
          changing in the configuration files or a bug.</div>
        <div><br>
        </div>
        <div>Thanks,</div>
        <div>Giacomo</div>
        <div><br>
        </div>
        <div><br>
        </div>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr" class="gmail_attr">On Thu, 24 Jun 2021 at 18:05,
          Shahid Hussain <<a href="mailto:shnx88@gmail.com"
            moz-do-not-send="true">shnx88@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 dir="ltr">Hi Giacomo,<br>
            <br>
            All of my required test cases are working fine with the
            combination you suggested along with configuring the NON VIP
            address in ds_default_socket parameter of dispatcher. I will
            test the regression suite on this and update if there is any
            issue.<br>
            <br>
            Thank you for your suggestion. Thanks 
            Daniel  as well for looking into this issue.<br>
            <br>
            However I would still be curious to know what was the root
            cause, how the previous combination was taking us into
            strange issues where Kamailio was assuming 8080 as Received
            port. Is it not based on where the OPTION response arrived ?<br>
            <div><br>
            </div>
            <div>Thanks & Regards,</div>
            <div>Shahid</div>
          </div>
          <br>
          <div class="gmail_quote">
            <div dir="ltr" class="gmail_attr">On Thu, Jun 24, 2021 at
              7:39 PM Giacomo Vacca <<a
                href="mailto:giacomo.vacca@gmail.com" target="_blank"
                moz-do-not-send="true">giacomo.vacca@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 dir="ltr">Hi Shahid,
                <div><br>
                </div>
                <div>> This system also listens on port 8080 which is
                  meant for websocket communication [...]</div>
                <div>> [...] but Kamailio considering the response is
                  on websocket port 8080 ,$Rp value is 8080</div>
                <div><br>
                </div>
                <div>Do you see the same behaviour if you set the listen
                  directive for SIP before the one for WS, in
                  kamailio.cfg?</div>
                <div>i.e.</div>
                <div><br>
                </div>
                <div>listen=tcp:<a href="http://172.27.45.219:5060"
                    target="_blank" moz-do-not-send="true">172.27.45.219:5060</a>
                  advertise <a href="http://172.27.45.198:5060"
                    target="_blank" moz-do-not-send="true">172.27.45.198:5060</a><br>
                </div>
                <div><br>
                </div>
                <div>before</div>
                <div><br>
                </div>
                <div>listen=tcp:172.27.45.219:MY_WS_PORT<br>
                </div>
                <div><br>
                </div>
                <div>?</div>
                <div><br>
                </div>
                <div>Thanks,</div>
                <div>Giacomo</div>
                <div><br>
                </div>
                <div><br>
                </div>
                <div><br>
                </div>
                <div><br>
                </div>
                <div><br>
                </div>
                <div><br>
                </div>
                <div><br>
                </div>
              </div>
              <br>
              <div class="gmail_quote">
                <div dir="ltr" class="gmail_attr">On Thu, 24 Jun 2021 at
                  15:28, Shahid Hussain <<a
                    href="mailto:shnx88@gmail.com" target="_blank"
                    moz-do-not-send="true">shnx88@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 dir="ltr">Hi Daniel,
                    <div>Sure, please check as per your availability.<br>
                      <div>I had tried the above option before adding
                        ds_default socket in kamailio .cfg but the
                        result was same.  Now also I have tried, but
                        still kamailio is declaring 8080 as
                        received port .</div>
                    </div>
                    <div>Following is the dispatcher configuration I
                      have tried now.</div>
                    <div>root@localhost ~]# kamcmd dispatcher.list<br>
                      {<br>
                              NRSETS: 1<br>
                              RECORDS: {<br>
                                      SET: {<br>
                                              ID: 1<br>
                                              TARGETS: {<br>
                                                      DEST: {<br>
                                                              URI:
                      <a class="moz-txt-link-freetext" href="sip:172.27.44.125:5060;transport=tcp">sip:172.27.44.125:5060;transport=tcp</a><br>
                                                              FLAGS: AP<br>
                                                              PRIORITY:
                      0<br>
                                                              ATTRS: {<br>
                                                                     
                      BODY: duid=sample-cas;maxload=1000;socket=tcp:<a
                        href="http://172.27.45.219:5060" target="_blank"
                        moz-do-not-send="true">172.27.45.219:5060</a><br>
                                                                     
                      DUID: sample-cas<br>
                                                                     
                      MAXLOAD: 1000<br>
                                                                     
                      WEIGHT: 0<br>
                                                                     
                      RWEIGHT: 0<br>
                                                                     
                      SOCKET: tcp:<a href="http://172.27.45.219:5060"
                        target="_blank" moz-do-not-send="true">172.27.45.219:5060</a><br>
                                                              }<br>
                                                              LATENCY: {<br>
                                                                     
                      AVG: 3.750000<br>
                                                                     
                      STD: 1.500000<br>
                                                                     
                      EST: 3.750000<br>
                                                                     
                      MAX: 6<br>
                                                                     
                      TIMEOUT: 0<br>
                                                              }<br>
                                                              RUNTIME: {<br>
                                                                     
                      DLGLOAD: 0<br>
                                                              }<br>
                                                      }<br>
                                              }<br>
                                      }<br>
                              }<br>
                      }<br>
                    </div>
                    <div><br>
                    </div>
                    <div>Jun 24 21:29:57 localhost
                      /usr/sbin/kamailio[5169]: WARNING: {2 10 OPTIONS <a
href="mailto:0f80e2d95e09aca5-5158@172.27.45.198" target="_blank"
                        moz-do-not-send="true">0f80e2d95e09aca5-5158@172.27.45.198</a>}
                      <script>: SIP response received on 8080
                      protocol:tcp  RIP:172.27.45.219 <a class="moz-txt-link-freetext" href="SIP:172.27.44.125">SIP:172.27.44.125</a>
                      method:OPTIONS <a
                        href="mailto:cid%3A0f80e2d95e09aca5-5158@172.27.45.198"
                        target="_blank" moz-do-not-send="true">cid:0f80e2d95e09aca5-5158@172.27.45.198</a>
                      replystatus:200 len:416<br>
                    </div>
                  </div>
                  <br>
                  <div class="gmail_quote">
                    <div dir="ltr" class="gmail_attr">On Thu, Jun 24,
                      2021 at 6:25 PM 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>I will check the logs once I finish a few
                          other tasks.</p>
                        <p>Meanwhile, maybe you can try to set the
                          socket per destination to see if it makes any
                          difference, like</p>
                        <p>1 <a moz-do-not-send="true">sip:172.27.44.125:5060;transport=tcp</a>
                          0 0 duid=sample-cas;maxload=1000;<b>socket=tcp:<a
                              href="http://172.27.45.219:5060"
                              target="_blank" moz-do-not-send="true">172.27.45.219:5060</a></b></p>
                        <p>Cheers,<br>
                          Daniel<br>
                        </p>
                        <p><br>
                        </p>
                        <div>On 24.06.21 12:48, Shahid Hussain wrote:<br>
                        </div>
                        <blockquote type="cite">
                          <div dir="ltr">Hi Daniel,
                            <div>Please find the debug logs attached.
                              You can refer OPTION message of
                              timestamp 18:43:35 though there are
                              multiple request.</div>
                            <div><br>
                            </div>
                            <div>There is a line in log says tcp worker
                              on 8080 though I have not specified in
                              kamailio.cfg.</div>
                            <div>Jun 24 18:43:35 localhost kamailio:
                              44(11820) DEBUG: <core>
                              [core/tcp_main.c:4517]:
                              handle_tcpconn_ev(): sending to child,
                              events 1<br>
                              Jun 24 18:43:35 localhost kamailio:
                              44(11820) DEBUG: <core>
                              [core/tcp_main.c:4190]: send2child():
                              selected tcp worker idx:6 proc:42
                              pid:11818 for activity on [<span
                                style="background-color:rgb(255,255,0)">tcp:<a
                                  href="http://172.27.45.219:8080"
                                  target="_blank" moz-do-not-send="true">172.27.45.219:8080</a></span>],
                              0x7fca749c2d60<br>
                            </div>
                            <div><br>
                            </div>
                            <div>Attached kamailio.cfg also.</div>
                          </div>
                          <br>
                          <div class="gmail_quote">
                            <div dir="ltr" class="gmail_attr">On Thu,
                              Jun 24, 2021 at 3:31 PM 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>can you set debug=3 in kamailio.cfg
                                  and then reproduce the case and send
                                  here all the syslog message printed by
                                  kamailio?</p>
                                <p>Cheers,<br>
                                  Daniel<br>
                                </p>
                                <div>On 24.06.21 11:37, Shahid Hussain
                                  wrote:<br>
                                </div>
                                <blockquote type="cite">
                                  <div dir="ltr">Hi  Daniel,
                                    <div>Attaching the filtered  pcap
                                      with response for an OPTION
                                      message. </div>
                                    <div>I am also attaching the all
                                      pcap with no filter having all SIP
                                      messages being communicated, there
                                      is no data coming on port 8080. </div>
                                    <div><br>
                                    </div>
                                    <div>Regards,</div>
                                    <div>Shahid</div>
                                  </div>
                                  <br>
                                  <div class="gmail_quote">
                                    <div dir="ltr" class="gmail_attr">On
                                      Thu, Jun 24, 2021 at 1:21 PM
                                      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>the pcap shows only the
                                          OPTIONS requests, not the
                                          replies. Maybe you have to
                                          capture the traffic also on
                                          8080 to catch it. It would
                                          important to see the reply and
                                          where it is sent back to
                                          kamailio.</p>
                                        <p>Cheers,<br>
                                          Daniel<br>
                                        </p>
                                        <div>On 24.06.21 09:24, Shahid
                                          Hussain wrote:<br>
                                        </div>
                                        <blockquote type="cite">
                                          <div dir="ltr">
                                            <div>Hi,<br>
                                              I have configured the
                                              dispatcher default socket
                                              as below IP , the
                                              expectation here is that
                                              kamailio should send all
                                              traffic from this IP (port
                                              will be ephemeral) over
                                              TCP.<br>
                                              modparam("dispatcher",
                                              "ds_default_socket", "tcp:<a
href="http://172.27.45.219:5060" target="_blank" moz-do-not-send="true">172.27.45.219:5060</a>")<br>
                                              <br>
                                              This system also listens
                                              on port 8080 which is
                                              meant for websocket
                                              communication (dispatcher
                                              communication is over non
                                              websocket).<br>
                                              <br>
                                              Kamailio is sending an
                                              OPTION message to
                                              dispatcher IP over TCP on
                                              5060 and getting 200 OK
                                              response but Kamailio
                                              considering the response
                                              is on websocket port 8080
                                              ,$Rp value is 8080.<br>
                                              <br>
                                              onreply_route {<br>
                                                   if (($Rp == 8080 )
                                              && !(proto == WS))<br>
                                                      {<br>
                                                             
                                              xlog("L_WARN", "SIP
                                              response received on $Rp
                                              protocol:proto RIP:$Ri <a
                                                moz-do-not-send="true">SIP:$si</a>
                                              method:$rm <a
                                                moz-do-not-send="true">cid:$ci</a>
                                              replystatus:$rs
                                              len:$ml\n");<br>
                                                             
                                              xlog("L_WARN", "SIP
                                              message received: $mb\n");<br>
                                                              drop;<br>
                                                      }<br>
                                              <br>
                                              .....<br>
                                              ....<br>
                                              }<br>
                                              <br>
                                              Following is the output of
                                              above logs:<br>
                                              Jun 24 15:10:08 localhost
                                              /usr/sbin/kamailio[6223]:
                                              WARNING: {2 10 OPTIONS <a
href="mailto:1ab6573a4640823b-6209@172.27.45.198" target="_blank"
                                                moz-do-not-send="true">1ab6573a4640823b-6209@172.27.45.198</a>}
                                              <script>: SIP
                                              response received on <span
style="background-color:rgb(255,255,0)">8080 protocol:tcp</span>
                                               RIP:172.27.45.219 <a
                                                moz-do-not-send="true">SIP:172.27.44.125</a>
                                              method:OPTIONS <a
                                                href="mailto:cid%3A1ab6573a4640823b-6209@172.27.45.198"
                                                target="_blank"
                                                moz-do-not-send="true">cid:1ab6573a4640823b-6209@172.27.45.198</a>
                                              replystatus:200 len:416<br>
                                              <br>
                                            </div>
                                            <div>Jun 24 15:10:08
                                              localhost
                                              /usr/sbin/kamailio[6223]:
                                              WARNING: {2 10 OPTIONS <a
href="mailto:1ab6573a4640823b-6209@172.27.45.198" target="_blank"
                                                moz-do-not-send="true">1ab6573a4640823b-6209@172.27.45.198</a>}
                                              <script>: SIP
                                              message received: SIP/2.0
                                              200 OK#015#012Via:
                                              SIP/2.0/TCP
172.27.45.198:5060;branch=z9hG4bK4526.92b79f34000000000000000000000000.0;received=172.27.45.219#015#012From:
                                              <a moz-do-not-send="true"><sip:dispatcher@localhost></a>;tag=1ae6c95d92f9ea9ce927f715de5c48c8-eb141029#015#012To:
                                              <a moz-do-not-send="true"><sip:172.27.44.125:5060;transport=tcp></a>;tag=a9d542e0#015#012Call-ID:
                                              <a
                                                href="http://1ab6573a4640823b-6209@172.27.45.198#015%23012CSeq"
                                                target="_blank"
                                                moz-do-not-send="true">1ab6573a4640823b-6209@172.27.45.198#015#012CSeq</a>:
                                              10 OPTIONS#015#012Allow:
                                              INVITE, ACK, BYE, OPTIONS,
                                              CANCEL, INFO, UPDATE,
                                              NOTIFY#015#012Content-Length:
                                              0<br>
                                              <br>
                                              <br>
                                              Also I have attached a
                                              pcap.<br>
                                              <br>
                                              Dispatcher.list
                                              configuration:<br>
                                              1 <a
                                                moz-do-not-send="true">sip:172.27.44.125:5060;transport=tcp</a>
                                              0 0
                                              duid=sample-cas;maxload=1000<br>
                                            </div>
                                            <div><br>
                                            </div>
                                            <div>Thanks,</div>
                                            <div>Shahid</div>
                                          </div>
                                          <br>
                                          <fieldset></fieldset>
                                          <pre>__________________________________________________________
Kamailio - Users Mailing List - Non Commercial Discussions
  * <a href="mailto:sr-users@lists.kamailio.org" target="_blank" moz-do-not-send="true">sr-users@lists.kamailio.org</a>
Important: keep the mailing list in the recipients, do not reply only to the sender!
Edit mailing list options or unsubscribe:
  * <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></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></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></pre>
                      </div>
                    </blockquote>
                  </div>
__________________________________________________________<br>
                  Kamailio - Users Mailing List - Non Commercial
                  Discussions<br>
                    * <a href="mailto:sr-users@lists.kamailio.org"
                    target="_blank" moz-do-not-send="true">sr-users@lists.kamailio.org</a><br>
                  Important: keep the mailing list in the recipients, do
                  not reply only to the sender!<br>
                  Edit mailing list options or unsubscribe:<br>
                    * <a
                    href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users"
                    rel="noreferrer" target="_blank"
                    moz-do-not-send="true">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a><br>
                </blockquote>
              </div>
              __________________________________________________________<br>
              Kamailio - Users Mailing List - Non Commercial Discussions<br>
                * <a href="mailto:sr-users@lists.kamailio.org"
                target="_blank" moz-do-not-send="true">sr-users@lists.kamailio.org</a><br>
              Important: keep the mailing list in the recipients, do not
              reply only to the sender!<br>
              Edit mailing list options or unsubscribe:<br>
                * <a
                href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users"
                rel="noreferrer" target="_blank" moz-do-not-send="true">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a><br>
            </blockquote>
          </div>
          __________________________________________________________<br>
          Kamailio - Users Mailing List - Non Commercial Discussions<br>
            * <a href="mailto:sr-users@lists.kamailio.org"
            target="_blank" moz-do-not-send="true">sr-users@lists.kamailio.org</a><br>
          Important: keep the mailing list in the recipients, do not
          reply only to the sender!<br>
          Edit mailing list options or unsubscribe:<br>
            * <a
            href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users"
            rel="noreferrer" target="_blank" moz-do-not-send="true">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a><br>
        </blockquote>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <pre class="moz-quote-pre" wrap="">__________________________________________________________
Kamailio - Users Mailing List - Non Commercial Discussions
  * <a class="moz-txt-link-abbreviated" href="mailto:sr-users@lists.kamailio.org">sr-users@lists.kamailio.org</a>
Important: keep the mailing list in the recipients, do not reply only to the sender!
Edit mailing list options or unsubscribe:
  * <a class="moz-txt-link-freetext" href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a>
</pre>
    </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></pre>
  </body>
</html>