<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p>Hello,</p>
    <p>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.</p>
    <p>Cheers,<br>
      Daniel<br>
    </p>
    <br>
    <div class="moz-cite-prefix">On 31.08.17 12:40, Жан Базаров wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAPOwP9zei5aEPM06Vq-c5n+7wOUauO8yAg3O99Hn4jnj5fpoaw@mail.gmail.com">
      <div dir="ltr">
        <div>Hello! provider trunks registration on kamailio UAC?! it's
          clear.</div>
        <div>but how does asterisk find out through which trunk the call
          should be made? </div>
        <div>I tried to set the header from asterisk dialplan. </div>
        <div>for example:</div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div> if (is_method("INVITE")) {</div>
        <div>                               
           #record_route_preset("109.195.102.122");</div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div>        route(DIRECTION);</div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div>        setflag(FLT_ACC); # do accounting</div>
        <div>        }</div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div>#        ------ LOADBALANCE ROUTE ------------ #</div>
        <div>if(!ds_is_from_list()) {</div>
        <div>route(DISPATCH);</div>
        <div>}</div>
        <div><br>
        </div>
        <div>route[DISPATCH] {</div>
        <div>        #round robin dispatching on gateways group '1'</div>
        <div>        if(!ds_select_dst("1", "4"))</div>
        <div>                {</div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div>                send_reply("404", "No destination");</div>
        <div>                exit;</div>
        <div>        }</div>
        <div>        xlog("L_DBG", "--- SCRIPT: going to <$ru> via
          <$du>\n");</div>
        <div>        t_on_failure("RTF_DISPATCH");</div>
        <div><br>
        </div>
        <div>route(NATMANAGE);</div>
        <div>route(DRELAY);</div>
        <div>        exit;</div>
        <div>}</div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div>route[DIRECTION] {</div>
        <div><br>
        </div>
        <div>                 if ($hdr(x-trunk)  != $null) {</div>
        <div><br>
        </div>
        <div>                 if (!is_method("BYE")){</div>
        <div>                                        $fu="";</div>
        <div>                                       
          t_on_failure("MANAGE_FAILURE");</div>
        <div>                                       
          $dlg_ctx(timeout_route) = "DIALOG_END";</div>
        <div>                                        $avp(i:10)=43200;</div>
        <div>                                       
          $dlg_ctx(timeout_bye) = 0;</div>
        <div>        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)");</div>
        <div>                                       
          t_on_failure("MANAGE_FAILURE");</div>
        <div>                                       
          $dlg_ctx(timeout_route) = "DIALOG_END";</div>
        <div>                                        $avp(i:10)=43200;</div>
        <div>                                       
          $dlg_ctx(timeout_bye) = 0;</div>
        <div><br>
        </div>
        <div>                $fu="";</div>
        <div>               
          uac_replace_from(<a class="moz-txt-link-rfc2396E" href="sip:$avp(uname)@$avp(dst_ipaddr)">"sip:$avp(uname)@$avp(dst_ipaddr)"</a>);</div>
        <div>                $tu="sip:"+$tU+"@"+$avp(dst_ipaddr);</div>
        <div>                $ru="sip:"+$tU+"@"+$avp(dst_ipaddr);</div>
        <div>                remove_hf("Contact");</div>
        <div>                $var(contact)="sip:"+$avp(uname)+"@<a
            href="http://10.49.9.2:5060" moz-do-not-send="true">10.49.9.2:5060</a>";</div>
        <div>                insert_hf("Contact:
          <$var(contact)>\r\n");</div>
        <div>                #insert_hf("Contact:  ");</div>
        <div>                msg_apply_changes();</div>
        <div>                fix_nated_register();</div>
        <div>                xlog("L_INFO","Contact header $var(contact)
          111111111111111111111111111111111111111 is $ct {$ct}\n");</div>
        <div>                route(RELAY);</div>
        <div> }      #### BYE</div>
        <div><br>
        </div>
        <div>}       ### XTRUNK<br>
          <br>
          <div>But in this configuration I do not come bye</div>
          <div>but when I register providers trunks on asterisk -
            problem with BYE not visible. <br>
            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</div>
          <br>
          <br>
          <br>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
Kamailio (SER) - Users Mailing List
<a class="moz-txt-link-abbreviated" href="mailto:sr-users@lists.kamailio.org">sr-users@lists.kamailio.org</a>
<a class="moz-txt-link-freetext" href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a>
</pre>
    </blockquote>
    <br>
    <pre class="moz-signature" cols="72">-- 
Daniel-Constantin Mierla
<a class="moz-txt-link-abbreviated" href="http://www.twitter.com/miconda">www.twitter.com/miconda</a> -- <a class="moz-txt-link-abbreviated" href="http://www.linkedin.com/in/miconda">www.linkedin.com/in/miconda</a>
Kamailio Advanced Training - <a class="moz-txt-link-abbreviated" href="http://www.asipto.com">www.asipto.com</a>
Kamailio World Conference - <a class="moz-txt-link-abbreviated" href="http://www.kamailioworld.com">www.kamailioworld.com</a></pre>
  </body>
</html>