1

I'm using Kamailio 4.4. I need to overwrite call information: From header domain. sip.twilio.com to pstn.mycompany.io. Example:

From: "+16501112222" <sip:+16501112222@sip.twilio.com>

to

From: "+16501112222" <sip:+16501112222@pstn.mycompany.io>

Call flow:

Twilio (SP1) --> MyCompany --> SP2
Twilio SIP -> Calls: sip:14081112222@sip.mycompany.io -> Kamailio -> Kamailio look up table and convert sip:14081112222@sip.mycompany.io to sip:jdoe@sp2.com using dbaliases to send call to SP2. 

Client in SP2 sees the call coming from Twilio. In order to redirect SIP Call to SP2, Kamailio performs a DNS lookup. I tried the following luck, although I see this code being executed. Using Kamailio default call script.

branch_route[MANAGE_BRANCH] {

        if($fd=~"sip\.twilio\.com") {
           xlog("L_INFO","|Masking Twilio call from: $fu");
           $fd = "pstn.mycompany.io"; 

        }

        xdbg("new branch [$T_branch_idx] to: $ru from: $fu\n");
        route(NATMANAGE);
}

Related: Twilio overwrite callerId with SIP calls

Community
  • 1
  • 1
gogasca
  • 9,283
  • 6
  • 80
  • 125

2 Answers2

5

Changing the From URI inside kamailio.cfg can be done with:

  • uac_replace_from() function from uac module. This can also do the reverse change for replies as well as update the header in subsequent requests of the same dialog

  • assign a string (or variable) to $fu (or $fU/$fd). This option is not taking care of reverse change and follow up requests.

You used the second option, but be aware that the change is not visible immediately. So printing $fu after assigning to $fd is going to print the old value of From URI. Look at the traffic on the network, there the header should be updated. If not, look in the syslog to see if there are any error messages. Also, loading debugger module and setting its parameter cfgtrace to 1 can help to track which configuration file lines are executed.

miconda
  • 1,754
  • 11
  • 14
2

This worked:

# Add uac.so module
loadmodule "uac.so"


# Manage outgoing branches
branch_route[MANAGE_BRANCH] {


        xdbg("New branch [$T_branch_idx] to: $ru from: $fu $fd\n");
        xlog("L_DBG","$mb \n| New branch \n");  
        # Rewrite From Domain for X
        if($fd=~"sip.x.com") {
           xlog("L_DBG","$mb \n| RELAY | Masking X call from: $fu $fd");
           xlog("L_DBG","$mb \n| RELAY | From: $fu $fd"); 
           uac_replace_from("","sip:$fU@pstn.mycompany.io");
           xlog("L_DBG","$mb \n| RELAY | Call masked from: $fu");  
        }
        # We do not trust the user, let's remove the P-Asserted-Identity, if any:
        remove_hf("P-Asserted-Identity");
        remove_hf("P-Preferred-Identity");
        route(NATMANAGE);
}
gogasca
  • 9,283
  • 6
  • 80
  • 125
  • 1
    Cheers for coming back and posting what your final solution was. I wish more people would. Helped me out today when faced with the same problem. – Ryan Dec 06 '18 at 22:11