<div dir="ltr">Hi,<div>It's not OK to modify the method in that way. That will cause problems with standard implementation. As you cat see function returns explicitly the first via for REQUESTs and the last via for RESPONSEs.</div><div>You should extend the method with parameters or modify it in another way.<br></div><div><br></div><div>BR,</div><div>Aleksandar Yosifov</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Sep 29, 2021 at 1:08 AM ErhanOnur <<a href="mailto:notifications@github.com">notifications@github.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"><p></p>
<h3>Description</h3>
<p>I put a dispatcher between PCSCF and UE.  When I tried to register,  Pcscf's save function saved dispatcher's via IP and via port  instead of UE's via IP and via port.</p>
<p>When I checked save function of ims_registrar_pcscf module , I saw that cscf_get_ue_via function is used for that. And It gives wrong via value. Instead of giving last via , it gives the first via in the via list.</p>
<p>Here is the function:</p>
<p><a href="https://github.com/kamailio/kamailio/blob/master/src/lib/ims/ims_getters.c" target="_blank">https://github.com/kamailio/kamailio/blob/master/src/lib/ims/ims_getters.c</a></p>
<pre><code>/**
 * Looks for the UE Via in First Via header if its a request
 * or in the last if its a response and returns its body
 * @param msg - the SIP message
 * @returns the via of the UE
 */
struct via_body* cscf_get_ue_via(struct sip_msg *msg)
{
        struct via_body *vb=0;

        if (msg->first_line.type==SIP_REQUEST) vb = cscf_get_first_via(msg,0);
        else vb = cscf_get_last_via(msg);

        if (!vb) return 0;

        if (vb->port == 0) vb->port=5060;
        return vb;      
}
</code></pre>
<h3>Troubleshooting</h3>
<p>I corrected the code as below:</p>
<pre><code>/**
 * Looks for the UE Via in Last Via header and returns its body
 * @param msg - the SIP message
 * @returns the via of the UE
 */
struct via_body* cscf_get_ue_via(struct sip_msg *msg)
{
        struct via_body *vb=0;

        vb = cscf_get_last_via(msg);

        if (!vb) return 0;

        if (vb->port == 0) vb->port=5060;
        return vb;      
}
</code></pre>
<h4>Reproduction</h4>
<p>Try to put a dispatcher between PCSCF and UE. save function of ims_registrar_pcscf module saves dispatcher's IP and port as UE's IP and port.</p>
<h4>Debugging Data</h4>
<pre><code>(paste your debugging data here)
</code></pre>
<h4>Log Messages</h4>
<pre><code>(paste your log messages here)
</code></pre>
<h4>SIP Traffic</h4>

<pre><code>(paste your sip traffic here)
</code></pre>
<h3>Possible Solutions</h3>

<h3>Additional Information</h3>
<ul>
<li><strong>Kamailio Version</strong> - output of <code>kamailio -v</code></li>
</ul>
<pre><code>(paste your output here)
</code></pre>
<ul>
<li><strong>Operating System</strong>:</li>
</ul>

<pre><code>(paste your output here)
</code></pre>

<p style="font-size:small;color:rgb(102,102,102)">—<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/issues/2864" target="_blank">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABO7UZM5YHFBFRF73Y4LTFLUEI4DXANCNFSM5E6NWBGA" target="_blank">unsubscribe</a>.<br>Triage notifications on the go with GitHub Mobile for <a href="https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675" target="_blank">iOS</a> or <a href="https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub" target="_blank">Android</a>.
<img src="https://github.com/notifications/beacon/ABO7UZOGIFWC5BNHHDQEC7DUEI4DXA5CNFSM5E6NWBGKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4PBXI6JA.gif" height="1" width="1" alt=""></p>
_______________________________________________<br>
Kamailio (SER) - Development Mailing List<br>
<a href="mailto:sr-dev@lists.kamailio.org" target="_blank">sr-dev@lists.kamailio.org</a><br>
<a href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev" rel="noreferrer" target="_blank">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev</a><br>
</blockquote></div>