Hello,

not sure I understood properly your issue, but if it is that the BYE is not getting to your dispatching/distribution rules, then all should be fine, because BYE (and other requests withing dialog) should be routed with 'record routing', therefore be sure you do record_route() from initial INVITE of the call and loose_route() for requests within dialog. In case you look at default kamailio.cfg, it has this kind of logic in it.

Cheers,
Daniel


On 31.08.17 12:40, Жан Базаров wrote:
Hello! provider trunks registration on kamailio UAC?! it's clear.
but how does asterisk find out through which trunk the call should be made? 
I tried to set the header from asterisk dialplan. 
for example:



 if (is_method("INVITE")) {
                                 #record_route_preset("109.195.102.122");




        route(DIRECTION);


        setflag(FLT_ACC); # do accounting
        }



#        ------ LOADBALANCE ROUTE ------------ #
if(!ds_is_from_list()) {
route(DISPATCH);
}

route[DISPATCH] {
        #round robin dispatching on gateways group '1'
        if(!ds_select_dst("1", "4"))
                {






                send_reply("404", "No destination");
                exit;
        }
        xlog("L_DBG", "--- SCRIPT: going to <$ru> via <$du>\n");
        t_on_failure("RTF_DISPATCH");

route(NATMANAGE);
route(DRELAY);
        exit;
}


route[DIRECTION] {

                 if ($hdr(x-trunk)  != $null) {

                 if (!is_method("BYE")){
                                        $fu="";
                                        t_on_failure("MANAGE_FAILURE");
                                        $dlg_ctx(timeout_route) = "DIALOG_END";
                                        $avp(i:10)=43200;
                                        $dlg_ctx(timeout_bye) = 0;
        sql_pvquery("ca", "select l_uuid, auth_username, auth_password, realm, l_domain, r_domain  from uacreg where id='$hdr(x-trunk)'", "$avp(uuid), $avp(uname), $avp(passwd), $avp(realm), $avp(src_ipaddr), $avp(dst_ipaddr)");
                                        t_on_failure("MANAGE_FAILURE");
                                        $dlg_ctx(timeout_route) = "DIALOG_END";
                                        $avp(i:10)=43200;
                                        $dlg_ctx(timeout_bye) = 0;

                $fu="";
                uac_replace_from("sip:$avp(uname)@$avp(dst_ipaddr)");
                $tu="sip:"+$tU+"@"+$avp(dst_ipaddr);
                $ru="sip:"+$tU+"@"+$avp(dst_ipaddr);
                remove_hf("Contact");
                $var(contact)="sip:"+$avp(uname)+"@10.49.9.2:5060";
                insert_hf("Contact: <$var(contact)>\r\n");
                #insert_hf("Contact:  ");
                msg_apply_changes();
                fix_nated_register();
                xlog("L_INFO","Contact header $var(contact) 111111111111111111111111111111111111111 is $ct {$ct}\n");
                route(RELAY);
 }      #### BYE

}       ### XTRUNK

But in this configuration I do not come bye
but when I register providers trunks on asterisk - problem with BYE not visible. 
but I can not register provider-trunks on all the asterisks, because incoming invite arrives at the link + address, and all the asteriscs ring. All my asterisk's behind nat





_______________________________________________
Kamailio (SER) - Users Mailing List
sr-users@lists.kamailio.org
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users

-- 
Daniel-Constantin Mierla
www.twitter.com/miconda -- www.linkedin.com/in/miconda
Kamailio Advanced Training - www.asipto.com
Kamailio World Conference - www.kamailioworld.com