<div dir="ltr">Hello again,<div><br></div><div>After doing some research I found this: "<b>Asterisk normally matches incoming calls to users based on the From: user name (without domain)</b>. However, if Asterisk can't find a user that matches the incoming call, it will try to match the caller's IP address with the IP addresses of known peers. If there's no match at all, the call will be sent to the context defined in the [general] section of sip.conf." here <a href="https://www.voip-info.org/wiki/view/Asterisk+sip+type">https://www.voip-info.org/wiki/view/Asterisk+sip+type</a>.</div><div>And after replacing <i style="font-size:12.8px">uac_replace_from("sip:<wbr>4444444444@XXX.XXX.XXX.XXX") </i><span style="font-size:12.8px">with</span><i style="font-size:12.8px"> </i><i style="font-size:12.8px">uac_replace_from("sip:<wbr>trunk_name@XXX.XXX.XXX.XXX") </i><span style="font-size:12.8px">everything worked as expected.</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Thanks.</span></div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-06-20 18:00 GMT+03:00 Володимир Іванець <span dir="ltr"><<a href="mailto:volodyaivanets@gmail.com" target="_blank">volodyaivanets@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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(<wbr>socket)))\n");</i></div></div><div><div><i>        if ($(sht(trunks_kamailio=>$var(<wbr>socket))) != $null) {</i></div></div><div><div><i>                xlog("**** From $(sht(trunks_kamailio=>$var(<wbr>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.<wbr>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:<wbr>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>
</blockquote></div><br></div>