[OpenSIPS-Users] issues on CANCEL proxying

Răzvan Crainea razvan at opensips.org
Thu Nov 14 09:01:11 UTC 2024


Hi, Pierre!

CANCEL messages should not be forwarded, they are being sent hop-by-hop. 
All you need to do is to match the CANCEL with the INVITE's transaction, 
something like:

     if (is_method("CANCEL")) {
         if (t_check_trans())
             t_relay();
         exit;
     }

Best regards,

Răzvan Crainea
OpenSIPS Core Developer / SIPhub CTO
http://www.opensips-solutions.com / https://www.siphub.com

On 11/7/24 6:17 PM, pierre cloury wrote:
> Hi,
> I'm working on an emergency server which is basically a proxy for a SIP
> INVITE, but which change request uri (example : from
> urn:service:sos.ambulance to tel:EC00033434678952).
> This part is working correctly, however i have a problem with SIP CANCEL
> gestion. I just want to forward the CANCEL sip message, however I
> understand that the request URI AND the via branch tag must be the same
> than the INVITE sended by my opensips server. For exemple, it must have
> "tel:EC00033434678952" and not "urn:service:sos.ambulance" in request URI.
> 
> Or the only way i found to do that is to cache the generated new request
> URI during request route for INVITE, and the via branch tag on the sip
> reply received by my opensips server (in the sip reply 100 trying... beurk).
> 
> It is ugly, and i'm sure there is a best method. I strongly suspect that it
> is possible with tm module, and i tried statefull behaviour, but i did not
> manage to do it without caching.
> 
> You can find below a simplified version of my current opensips.cfg :
> 
> route {
>        if (is_method("INVITE")) {
>              t_newtran();
>              #determine new request URI, not important. Result is on
> $avp(psap)
>              $avp(psap) = "33434678789"
>              #cache result with call-ID as key
>              cache_store("local:psap_cache", "$hdr(Call-ID)",
> "$avp(psap)",15);
>              forward()
>        }
>        else if (is_method("CANCEL")){
>              #extract from cach both value, modify via and then forward
>              cache_fetch("local:psap_cache","$hdr(Call-ID)", $var(psap));
>              cache_fetch("local:via_branch_cache","$hdr(Call-ID)",
> $var(branch_via))
> 
>              $ru = "tel:" + $var(psap);
>              insert_hf("Via: SIP/2.0/TCP 100.76.22.1:5062
> ;branch=$var(branch_via)\r\n");
>              forward();
> 
>        }
> }
> onreply_route {
> 
>         #extract via branch tag on sip 100 trying answer after INVITE
>         if ($(var(cseq_header){s.select,1, }) == "INVITE" and
> $var(responde_code) == 100 ){
>               $var(branch_via) = "z9..."
>               #cache branch_via
>               cache_store("local:via_branch_cache", "$hdr(Call-ID)",
> "$var(branch_via)",15);
>         }
> }
> 
> Could you please provide the idea to unblock me and find a better method ?
> Regards,
> Pierre
> 
> 
> Hi,
> I'm working on an emergency server which is basically a proxy for a SIP 
> INVITE, but which change request uri (example : from 
> urn:service:sos.ambulance to tel:EC00033434678952).
> This part is working correctly, however i have a problem with SIP CANCEL 
> gestion. I just want to forward the CANCEL sip message, however I 
> understand that the request URI AND the via branch tag must be the same 
> than the INVITE sended by my opensips server. For exemple, it must have 
> "tel:EC00033434678952" and not "urn:service:sos.ambulance" in request URI.
> 
> Or the only way i found to do that is to cache the generated new request 
> URI during request route for INVITE, and the via branch tag on the sip 
> reply received by my opensips server (in the sip reply 100 trying... beurk).
> 
> It is ugly, and i'm sure there is a best method. I strongly suspect that 
> it is possible with tm module, and i tried statefull behaviour, but i 
> did not manage to do it without caching.
> 
> You can find below a simplified version of my current opensips.cfg :
> 
> route {
>        if (is_method("INVITE")) {
>              t_newtran();
>              #determine new request URI, not important. Result is on 
> $avp(psap)
>              $avp(psap) = "33434678789"
>              #cache result with call-ID as key
>              cache_store("local:psap_cache", "$hdr(Call-ID)", 
> "$avp(psap)",15);
>              forward()
>        }
>        else if (is_method("CANCEL")){
>              #extract from cach both value, modify via and then forward
>              cache_fetch("local:psap_cache","$hdr(Call-ID)", $var(psap));
>              cache_fetch("local:via_branch_cache","$hdr(Call-ID)", 
> $var(branch_via))
> 
>              $ru = "tel:" + $var(psap);
>              insert_hf("Via: SIP/2.0/TCP 
> 100.76.22.1:5062;branch=$var(branch_via)\r\n");
>              forward();
> 
>        }
> }
> onreply_route {
> 
>         #extract via branch tag on sip 100 trying answer after INVITE
>         if ($(var(cseq_header){s.select,1, }) == "INVITE" and 
> $var(responde_code) == 100 ){
>               $var(branch_via) = "z9..."
>               #cache branch_via
>               cache_store("local:via_branch_cache", "$hdr(Call-ID)", 
> "$var(branch_via)",15);
>         }
> }
> 
> Could you please provide the idea to unblock me and find a better method ?
> Regards,
> Pierre
> 
> _______________________________________________
> Users mailing list
> Users at lists.opensips.org
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users




More information about the Users mailing list