<div dir="ltr">Hello everyone,<div><br></div><div>I'm doing some custom Kamailio configuration to achieve few things but seem to be stuck with SIP trunks. I'm currently using Kamailio 4.4.5 and here is what I have at the moment:</div><div><br></div><div><b>1.</b> Asterisk 11.25.1 servers behing Kamailio using RealTime for SIP peers.</div><div><br></div><div><b>2.</b> Route that checks if packet was sent from one of configured SIP trunks. This part works correctly:</div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><i>route[FROMPSTN] {</i></div></div><div><div><i>        xlog("== FROMPSTN ==\n");</i></div></div><div><div><i>        $var(socket) = $si + ":" + $sp;</i></div></div><div><div><i>        xlog("**** $var(socket)\n");</i></div></div><div><div><i>        xlog("**** $(sht(trunks_kamailio=>$var(socket)))\n");</i></div></div><div><div><i>        if ($(sht(trunks_kamailio=>$var(socket))) != $null) {</i></div></div><div><div><i>                xlog("**** From $(sht(trunks_kamailio=>$var(socket))) PSTN\n");</i></div></div><div><div><i>                return 1;</i></div></div><div><div><i>                }</i></div></div><div><div><i>        xlog("**** Not from PSTN\n");</i></div></div><div><div><i>        return -1;</i></div></div><div><div><i>}</i></div></div></blockquote><div><br></div><div><b>3.</b> Here is a fragment that sends INVITE packet to <i>TOASTERISK</i> route if it was received from one of trunks. I have 4444444444@XXX.XXX.XXX.XXX hardcoded for now, and in my configuration 4444444444 and XXX.XXX.XXX.XXX represent my real caller id number and carrier's IP address:</div><div><br></div><div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><i>if(route(FROMPSTN)) {</i></div><div><i>        uac_replace_from("sip:4444444444@XXX.XXX.XXX.XXX");</i></div><div><i>        route(TOASTERISK);</i></div><div><i>}</i></div></blockquote></div><div><br></div><div><b>4.</b> TOASTERISK basically has folloving fragment that load balances traffic between Asterisk nodes:</div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><i>if(!ds_select_dst("0", "4")) {</i></div></div><div><div><i>        xlog("**** Call was not sent to none of Asterisk hosts\n");</i></div></div><div><div><i>        if(!is_method("REGISTER")) {</i></div></div><div><div><i>                xlog("**** Method is not REGISTER\n");</i></div></div><div><div><i>                send_reply("404", "No destination");</i></div></div><div><div><i>        }</i></div></div><div><div><i>        xlog("**** Dispatcher fail\n");</i></div></div><div><div><i>        exit;</i></div></div><div><div><i>}</i></div></div></blockquote><div><br></div><div>So when I'm making a call to my test number, I can see following incomming packet in Asterisk from Kamailio. From header has correct caller id number and carrier's IP address (192.168.88.5 is Kamailio's internal IP address):</div><div><img src="cid:ii_15cc5f83cf4c33b5" alt="Вбудоване зображення 1" width="454" height="334"><br></div><div><br></div><div>And when Asterisk tries to find a maching peer for this incoming call, it is using Kamailio's instead of Carrier's IP address. So it is actually finds one of peers (101-XXXXXXX) that is being authenticated on Kamailio as many others:</div><div><img src="cid:ii_15cc5fd0c724f6a6" alt="Вбудоване зображення 2" width="454" height="163"><br></div><div><br></div><div>I'm not sure if Asterisk is just using packet's source IP to lookup for corresponding peer or something else from it's content. I will really appreciate any help on this.</div><div><br></div><div>Thanks a lot!</div></div>