<div dir="ltr"><div>Hello,</div><div> </div><div>I&#39;ve been having some issues with the syntax of Kamailio&#39;s config file. I&#39;ve been following the turorial here: <a href="http://kb.asipto.com/asterisk:realtime:kamailio-3.3.x-asterisk-10.7.0-astdb">http://kb.asipto.com/asterisk:realtime:kamailio-3.3.x-asterisk-10.7.0-astdb</a></div>
<div> </div><div>I&#39;d like to setup Kamailio to act as an SBC providing NAT traversal, and security for multiple asterisk boxes on the inside. Currently kamailio has two NIC&#39;s, one public and one private. All traffic hits the external interface and is then forwarded to an Asterisk box on the inside.</div>
<div> </div><div>I&#39;d like to modify the config from the tutorial above to support multiple asterisk boxes. Authentication will be done via MySQL and depending on the user domain, the request get&#39;s forwarded to the proper Asterisk box. Here is what I&#39;ve got so far:</div>
<div> </div><div> if (is_method(&quot;REGISTER&quot;) &amp;&amp; from_uri=~<a href="mailto:.*@10.55.55.5">.*@10.55.55.5</a>)<br>        {<br>                if(isflagset(FLT_NATS))<br>                {<br>                        setbflag(FLB_NATB);<br>
                        # uncomment next line to do SIP NAT pinging<br>                        ## setbflag(FLB_NATSIPPING);<br>                }<br>                if (!save(&quot;location&quot;))<br>                        sl_reply_error();</div>
<div>                route(REGFWD);</div><div>                exit;<br>        }<br>        else if (is_method(&quot;REGISTER&quot;) &amp;&amp; from_uri=~&quot;.*asterisk.domain.tld&quot;)<br>        {<br>                if(isflagset(FLT_NATS))<br>
                {<br>                        setbflag(FLB_NATB);<br>                        # uncomment next line to do SIP NAT pinging<br>                        ## setbflag(FLB_NATSIPPING);<br>                }<br>                if (!save(&quot;location&quot;))<br>
                        sl_reply_error();</div><div>                route(REGFWDCLOUD);</div><div>                exit;<br>        }<br>}</div><div> </div><div>Based on the domain I route the SIP message to another route block which is esentally the same route block as the origional route[FROMASTERISK] route[TOASTERISK] route[REGFWD]. I beleive there&#39;s an easier way of doing this though. Creating separate route blocks per asterisk box would mean creating a new route blocks for each asterisk box. Here&#39;s an example:</div>
<div> </div><div>route[FROMASTERISK] {<br>        if($si==$sel(cfg_get.asterisk.bindip)<br>                        &amp;&amp; $sp==$sel(cfg_get.asterisk.bindport))<br>                return 1;<br>        return -1;</div><div>
<br># Send to Asterisk<br>route[TOASTERISK] {<br>        $du = &quot;sip:&quot; + $sel(cfg_get.asterisk.bindip) + &quot;:&quot;<br>                        + $sel(cfg_get.asterisk.bindport);<br>        route(RELAY);<br>        exit;</div>
<div><br># Forward REGISTER to Asterisk<br>route[REGFWD] {<br>        if(!is_method(&quot;REGISTER&quot;))<br>        {<br>                return;<br>        }<br>        $var(rip) = $sel(cfg_get.asterisk.bindip);<br>        $uac_req(method)=&quot;REGISTER&quot;;<br>
        $uac_req(ruri)=&quot;sip:&quot; + $var(rip) + &quot;:&quot; + $sel(cfg_get.asterisk.bindport);<br>        $uac_req(furi)=&quot;sip:&quot; + $au + &quot;@&quot; + $var(rip);<br>        $uac_req(turi)=&quot;sip:&quot; + $au + &quot;@&quot; + $var(rip);<br>
        $uac_req(hdrs)=&quot;Contact: &lt;sip:&quot; + $au + &quot;@&quot;<br>                                + $sel(cfg_get.kamailio.bindip)<br>                                + &quot;:&quot; + $sel(cfg_get.kamailio.bindport) + &quot;&gt;\r\n&quot;;<br>
        if($sel(contact.expires) != $null)<br>                $uac_req(hdrs)= $uac_req(hdrs) + &quot;Expires: &quot; + $sel(contact.expires) + &quot;\r\n&quot;;<br>        else<br>                $uac_req(hdrs)= $uac_req(hdrs) + &quot;Expires: &quot; + $hdr(Expires) + &quot;\r\n&quot;;<br>
        uac_req_send();<br>}</div><div>route[FROMCLOUD] {<br>        if($si==$sel(cfg_get.cloud.bindip)<br>                        &amp;&amp; $sp==$sel(cfg_get.asterisk.bindport))<br>                return 1;<br>        return -1;<br>
}</div><div>route[TOCLOUD] {<br>        $du = &quot;sip:&quot; + $sel(cfg_get.cloud.bindip) + &quot;:&quot;<br>                        + $sel(cfg_get.asterisk.bindport);<br>        route(RELAY);<br>        exit;<br>}</div>
<div>route[REGFWDCLOUD] {<br>        if(!is_method(&quot;REGISTER&quot;))<br>        {<br>                return;<br>        }<br>        $var(rip) = $sel(cfg_get.cloud.bindip);<br>        $uac_req(method)=&quot;REGISTER&quot;;<br>
        $uac_req(ruri)=&quot;sip:&quot; + $var(rip) + &quot;:&quot; + $sel(cfg_get.asterisk.bindport);<br>        $uac_req(furi)=&quot;sip:&quot; + $au + &quot;@&quot; + $var(rip);<br>        $uac_req(turi)=&quot;sip:&quot; + $au + &quot;@&quot; + $var(rip);<br>
        $uac_req(hdrs)=&quot;Contact: &lt;sip:&quot; + $au + &quot;@&quot;<br>                                + $sel(cfg_get.kamailio.bindip)<br>                                + &quot;:&quot; + $sel(cfg_get.kamailio.bindport) + &quot;&gt;\r\n&quot;;<br>
        if($sel(contact.expires) != $null)<br>                $uac_req(hdrs)= $uac_req(hdrs) + &quot;Expires: &quot; + $sel(contact.expires) + &quot;\r\n&quot;;<br>        else<br>                $uac_req(hdrs)= $uac_req(hdrs) + &quot;Expires: &quot; + $hdr(Expires) + &quot;\r\n&quot;;<br>
        uac_req_send();<br>}</div><div> </div><div>I&#39;m sure their is any easier way of doing this alhthough I&#39;m not sure how. Can anyone point me in the right direction?</div><div> </div><div>Lastly, is there a way to modify the DBURL string on the fly so based on the domain for example, I coudl query a different DB for user credentials?</div>
<div> </div><div> </div><div>Thanks!</div></div>