[Kamailio-Users] Loose Route / Re-Invite

Juha Heinanen jh at tutpro.com
Thu Feb 4 06:51:45 CET 2010


Klaus Darilion writes:

 > * perform NAT traversal always, unless I know for sure that the client 
 > does not support symmetric SIP. For doing NAT traversal you can either 
 > use fix_nated_contact() - which is not standard conform but works - or 
 > use the new add_contact_alias/handle_ruri_alias (kamailio 3.0: 
 > http://sip-router.org/docbook/sip-router/branch/master/modules_k/nathelper/nathelper.html#id2806306)

here are the instructions in case someone missed them earlier.

-- juha

add_contact_alias()/handle_ruri_alias() usage example
-----------------------------------------------------

supports re-use of tcp sessions between proxy and UAs.  supports routing
of requests to UAs behind NATs so that r-uri is always what UAs expect.
proxying of media is not shown, but can be easily added.

NON_REGISTER_INITIAL_REQUESTS
-----------------------------

- call alias_contact() for all non-register initial requests, which
  don't come from another proxy (which takes care of its own UAs).

- if you know that non-register initial request is going to another
  proxy, set TO_PROXY flag before relaying the request.

- in cases, where initial request may go to another proxy, but you are
  not sure about it, store the number of record-route headers in
  incoming request in an AVP that you can then later test in onreply
  route and find out, if next hop was a proxy.

route [NON_REGISTER_INITIAL_REQUESTS] {

    if (!is_present_hf("Record-Route")) {
        route(ADD_CONTACT_ALIAS);
    };
    ...
    if (I_KNOW_FOR_SURE_THAT_NEXT_HOP_IS_ANOTHER_PROXY) {
        setbflag("TO_PROXY");
    };

    if (NEXT_HOP_MAY_BE_ANOTHER_PROXY_BUT_I_DONT_KNOW_FOR_SURE) {
        $avp("rr_count") = $rr_count;
    };
    t_on_reply("REPLY");
    if (!t_relay()) ...

route [ADD_CONTACT_ALIAS] {
    if (!add_contact_alias()) {
        xlog("L_ERR", "Error in aliasing contact <$ct>\n");
        send_reply("400", "Bad request");
        exit;
    };
}

REGISTER_REQUESTS
-----------------

- call fix_nated_register() on register requests, if registering ua is
  behind nat OR is using tcp.

route [REGISTER_REQUESTS] {
    ...
    if (isflagset(FROM_NATED) || (proto == TCP)) {
        fix_nated_register();
	if (isflagset(FROM_NATED)) {
	    setbflag("TO_NATED");
	};
    };
    save("location");
    ...

IN_DIALOG_REQUESTS
------------------

- call alias_contact() for all in-dialog requests that don't come
  from another proxy.

- call handle_ruri_alias() for all in-dialog requests before
  t_relaying them to UAs.  next hop is an UA if loose_route()
  didn't set $du.  if next hop is a proxy, set TO_PROXY flag.

route [IN_DIALOG_REQUESTS] {

    if (@via[2] == "") {
        route(ADD_CONTACT_ALIAS);
    }
    loose_route();
    if ($du == "") {
        handle_ruri_alias();
        switch ($rc) {
        case -1:
            xlog("L_ERR", "Failed to handle alias of R-URI <$ru>\n");
            send_reply("400", "Bad request");
            exit;
        case 1:
            xlog("L_INFO", "Routing in-dialog $rm from <$fu> to <$du>\n");
            break;
        case 2:
            xlog("L_INFO", "Routing in-dialog $rm from <$fu> to <$ru>\n");
            break;
         };
    } else {
        setbflag("TO_PROXY");
    }
    t_on_reply("REPLY");
    if (!t_relay()) {
        ...

REPLIES
-------

- call add_contact_alias() on all replies except the ones that come from
  another proxy.

onreply_route [REPLY] {

    if (!isbflagset("TO_PROXY") {
        if (is_avp_set("$avp(rr_count)")) {
	    if ($rr_count == $avp(rr_count) + $rr_top_count) {
	        route(ADD_CONTACT_ALIAS);
            };
        } else {
	    route(ADD_CONTACT_ALIAS);
	}
    }
    ...

NOTE
----

- do NOT call fix_nated_contact() on anything, because
  add_contact_alias() replaces it.




More information about the sr-users mailing list