Kamailio overwrite From domain

1.9k views Asked by At

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:[email protected]>

to

From: "+16501112222" <sip:[email protected]>

Call flow:

Twilio (SP1) --> MyCompany --> SP2
Twilio SIP -> Calls: sip:[email protected] -> Kamailio -> Kamailio look up table and convert sip:[email protected] to sip:[email protected] 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

2

There are 2 answers

0
miconda On BEST ANSWER

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.

1
gogasca On

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:[email protected]");
           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);
}