### Description
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.
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.
Here is the function:
https://github.com/kamailio/kamailio/blob/master/src/lib/ims/ims_getters.c
``` /** * 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; } ```
### Troubleshooting
I corrected the code as below:
``` /** * 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; } ```
#### Reproduction
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.
#### Debugging Data
``` (paste your debugging data here) ```
#### Log Messages
``` (paste your log messages here) ```
#### SIP Traffic
<!-- If the issue is exposed by processing specific SIP messages, grab them with ngrep or save in a pcap file, then add them next, or attach to issue, or provide a link to download them (e.g., to a pastebin site). -->
``` (paste your sip traffic here) ```
### Possible Solutions
<!-- If you found a solution or workaround for the issue, describe it. Ideally, provide a pull request with a fix. -->
### Additional Information
* **Kamailio Version** - output of `kamailio -v`
``` (paste your output here) ```
* **Operating System**:
<!-- Details about the operating system, the type: Linux (e.g.,: Debian 8.4, Ubuntu 16.04, CentOS 7.1, ...), MacOS, xBSD, Solaris, ...; Kernel details (output of `lsb_release -a` and `uname -a`) -->
``` (paste your output here) ```
Hi, 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. You should extend the method with parameters or modify it in another way.
BR, Aleksandar Yosifov
On Wed, Sep 29, 2021 at 1:08 AM ErhanOnur notifications@github.com wrote:
Description
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.
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.
Here is the function:
https://github.com/kamailio/kamailio/blob/master/src/lib/ims/ims_getters.c
/**
- 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; }
Troubleshooting
I corrected the code as below:
/**
- 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; }
Reproduction
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. Debugging Data
(paste your debugging data here)
Log Messages
(paste your log messages here)
SIP Traffic
(paste your sip traffic here)
Possible Solutions Additional Information
- *Kamailio Version* - output of kamailio -v
(paste your output here)
- *Operating System*:
(paste your output here)
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/kamailio/kamailio/issues/2864, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABO7UZM5YHFBFRF73Y4LTFLUEI4DXANCNFSM5E6NWBGA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
Kamailio (SER) - Development Mailing List sr-dev@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev
Hi Aleksandar,
According to Kamalio naming, top via is the first via, and bottom via header is the last via. For each request, UAC puts its via header to the top of the list. And for each response, UAC deletes the top via header. So the bottom via (last via) always belongs to the UE's UAC (it doesn't matter if it is Request or Response). Why we use first Via header to identify the UE?
BR, Erhan Sendag
Hi, again and sorry for the late answer. I analyzed some log/pcap files and the source code too. Unfortunately, cscf_get_ue_via is legacy, and I do not know why it is implemented that way. In conclusion, I believe that the changes proposed by you will not affect the current implementation.
On Tue, Oct 5, 2021 at 3:03 PM Erhan Onur Sendag notifications@github.com wrote:
Hi Aleksandar,
According to Kamalio naming, top via is the first via, and bottom via header is the last via. For each request, UAC puts its via header to the top of the list. And for each response, UAC deletes the top via header. So the bottom via (last via) always belongs to the UE's UAC (it doesn't matter if it is Request or Response). Why we use first Via header to identify the UE?
BR, Erhan Sendag
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kamailio/kamailio/issues/2864#issuecomment-934345369, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABO7UZPLYQ5HOGOGCTJOHCLUFLSRBANCNFSM5E6NWBGA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
Kamailio (SER) - Development Mailing List sr-dev@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev
Thanks for the comment @alexyosifov and @ErhanOnur. As the cscf_get_ue_via(struct sip_msg *msg) is used from different modules, the best option would be probably to change the functions like this:
cscf_get_ue_first_via(struct sip_msg *msg) (use the original implementation) cscf_get_ue_last_via(struct sip_msg *msg) (use the proposed implementation)
Then the correct implementation can be used in the ims_registrar_pcscf module.
@ErhanOnur Could you prepare a pull request for this?
Hello @henningw,
I checked usage of cscf_get_ue_via function. And I saw ims_ipsec_pcscf, ims_qos, ims_registrar_pcscf module are using this function.
All of them are pcscf modules.
ims_usrloc_pcscf keeps a hashtable to keep the pcscf contacts. And hash code is calculated with UE's IP address. To get UE's IP address we are currently using cscf_get_ue_via function.
In pull request , we will change the cscf_get_ue_via with cscf_get_ue_last_via in ims_registrar_pcscf_registrar module only. So contact will be saved into hash table with the return value of cscf_get_ue_last_via.
Since we will not change ims_ipsec_pcscf and ims_qos modules, they will query hash table with the return value of cscf_get_ue_via. Since these module will not use the same function to get UE's IP adress, they may get a different value and may not reach the contact in the hash table. because calculated hash code will be different.
This issue is stale because it has been open 6 weeks with no activity. Remove stale label or comment or this will be closed in 2 weeks.
Closed #2864 as not planned.