Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
tutorials:alias-example [2010/07/09 09:14]
87.93.23.172
tutorials:alias-example [2013/06/08 08:42] (current)
jh [In-Dialog Requests]
Line 3: Line 3:
 ===== Introduction ===== ===== Introduction =====
  
-The benefits of using add_contact_alias() and handle_ruri_alias() functions instead of conventional NAT traversal solutions are: +The benefit of using add_contact_alias() and handle_ruri_alias() functions instead of conventional NAT traversal solutions is that Request-URI in requests to UAs behind NATs is always what UAs expectIn the example below only functions related to signaling are shown.  Proxying of media using either Mediaprxy or RTP Proxy can be easily added.  In addition to handling NAT traversal, the example uses add_contact_alias() and handle_ruri_alias() functions for re-use of tcp/tls sessions between proxy and UAs.
- +
-  * support for re-use of tcp sessions between proxy and UAs +
-  * supports for routing of requests to UAs behind NATs so that r-uri is always what UAs expect +
- +
-In the example below only functions related to signaling are shown.  Proxying of media using either Mediaprxy or RTP Proxy can be easily added. +
 ===== Non-Register Initial Requests ===== ===== Non-Register Initial Requests =====
  
-Call add_contact_alias() for all non-register initial requests, which +Call add_contact_alias() on all non-register initial requests, which 
-don't come from another proxy (which takes care of its own UAs).+come from UAs behind NAT or which don't come via a proxy and transport protocol is not UDP.
 If you know that non-register initial request is going to another If you know that non-register initial request is going to another
 proxy, set TO_PROXY flag before relaying the request. proxy, set TO_PROXY flag before relaying the request.
Line 21: Line 15:
 route and find out, if next hop was a proxy. route and find out, if next hop was a proxy.
  
-  route [NON_REGISTER_INITIAL_REQUESTS] {+<code> 
 +route [NON_REGISTER_INITIAL_REQUESTS] {
  
-      if (!is_present_hf("Record-Route")) { +    if (REQUEST_COMES_FROM_BEHIND_NAT || (!is_present_hf("Record-Route") && (proto != UDP))) { 
-          route(ADD_CONTACT_ALIAS); +        route(ADD_CONTACT_ALIAS); 
-      }; +    }; 
-      ... +    ... 
-      if (I_KNOW_FOR_SURE_THAT_NEXT_HOP_IS_ANOTHER_PROXY) { +    if (I_KNOW_FOR_SURE_THAT_NEXT_HOP_IS_ANOTHER_PROXY) { 
-          setbflag("TO_PROXY"); +        setbflag("TO_PROXY"); 
-      }; +    }; 
-      if (NEXT_HOP_MAY_BE_ANOTHER_PROXY_BUT_I_DONT_KNOW_FOR_SURE) { +    if (NEXT_HOP_MAY_BE_ANOTHER_PROXY_BUT_I_DONT_KNOW_FOR_SURE) { 
-          $avp("rr_count") = $rr_count; +        $avp("rr_count") = $rr_count; 
-      }; +    }; 
-      t_on_reply("REPLY"); +    t_on_reply("REPLY"); 
-      if (!t_relay()) ... +    if (!t_relay()) ... 
-  }+}
  
-  route [ADD_CONTACT_ALIAS] {+route [ADD_CONTACT_ALIAS] {
  
-      if (!add_contact_alias()) { +    if (!add_contact_alias()) { 
-          xlog("L_ERR", "Error in aliasing contact <$ct>\n"); +        xlog("L_ERR", "Error in aliasing contact <$ct>\n"); 
-          send_reply("400", "Bad request"); +        send_reply("400", "Bad request"); 
-          exit; +        exit; 
-      }; +    }; 
-  }+} 
 +</code>
  
 ===== Register Requests ===== ===== Register Requests =====
  
-Call fix_nated_register() on register requests, if registering ua is +Call fix_nated_register() on register requests, if registering UA is 
-behind nat OR is using tcp.+behind NAT or transport protocol is not UDP.
  
 +<code>
 route [REGISTER_REQUESTS] { route [REGISTER_REQUESTS] {
     ...     ...
-    if (isflagset(FROM_NATED) || (proto == TCP)) {+    if (isflagset(FROM_NATED) || (proto !UDP)) {
         fix_nated_register();         fix_nated_register();
         if (isflagset(FROM_NATED)) {         if (isflagset(FROM_NATED)) {
Line 62: Line 59:
     ...     ...
 } }
 +</code>
  
 ===== In-Dialog Requests ===== ===== In-Dialog Requests =====
  
-Call alias_contact() for all in-dialog requests that don't come +Call add_contact_alias() on all in-dialog requests that come from behind NAT or that don't come 
-from another proxy.  Call handle_ruri_alias() for all in-dialog requests before +from another proxy and transport protocol is not UDP.  Call handle_ruri_alias() for all in-dialog requests before 
-t_relaying them to UAs.  next hop is an UA if loose_route() +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.+didn't set $du.  If next hop is a proxy, set TO_PROXY flag.
  
 +<code>
 route [IN_DIALOG_REQUESTS] { route [IN_DIALOG_REQUESTS] {
  
-    if (@via[2] == "") {+    if (REQUEST_COMES_FROM_BEHIND_NAT || (is_first_hop() && (proto !UDP))) {
         route(ADD_CONTACT_ALIAS);         route(ADD_CONTACT_ALIAS);
     }     }
Line 97: Line 96:
         ...         ...
 } }
 +</code>
  
 ===== Replies ===== ===== Replies =====
Line 103: Line 103:
 another proxy. another proxy.
  
 +<code>
 onreply_route [REPLY] { onreply_route [REPLY] {
  
Line 116: Line 117:
     ...     ...
 } }
 +</code>
  
 ===== Notes ===== ===== Notes =====

Navigation

Wiki

Other

QR Code
QR Code tutorials:alias-example (generated for current page)