Module: sip-router
Branch: master
Commit: cf598f3229b7b381fd4d2a381bafbb8f7c0be0d1
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=cf598f3229b7b381fd4d2a381bafbb8f7c0be0d1

Author: Daniel-Constantin Mierla <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date:   Sat May 28 23:30:43 2011 +0200

kamailio.cfg: reworked nat traversal config

- groupped the nat traversal login in NATDETECT and NATMANAGE route
  blocks, simplifying by using rtpproxy_manage() function
- nat traversal logic for requests is applied in branch_route for proper
  optimization of serial/parallel forking

---

 etc/kamailio.cfg |   90 ++++++++++++++++++++++++++++--------------------------
 1 files changed, 47 insertions(+), 43 deletions(-)

diff --git a/etc/kamailio.cfg b/etc/kamailio.cfg
index 77cdce9..3ee11e4 100644
--- a/etc/kamailio.cfg
+++ b/etc/kamailio.cfg
@@ -423,7 +423,7 @@ route {
        route(REQINIT);
 
        # NAT detection
-       route(NAT);
+       route(NATDETECT);
 
        # handle requests within SIP dialogs
        route(WITHINDLG);
@@ -484,20 +484,15 @@ route {
 
 
 route[RELAY] {
-#!ifdef WITH_NAT
-       if (check_route_param("nat=yes")) {
-               setbflag(FLB_NATB);
-       }
-       if (isflagset(FLT_NATS) || isbflagset(FLB_NATB)) {
-               route(RTPPROXY);
-       }
-#!endif
 
-       /* example how to enable some additional event routes */
+       # enable additional event routes for forwarded requests
+       # - serial forking, RTP relaying handling, a.s.o.
+       if (is_method("INVITE|SUBSCRIBE")) {
+               t_on_branch("MANAGE_BRANCH");
+               t_on_reply("MANAGE_REPLY");
+       }
        if (is_method("INVITE")) {
-               #t_on_branch("BRANCH_ONE");
-               t_on_reply("REPLY_ONE");
-               t_on_failure("FAIL_ONE");
+               t_on_failure("MANAGE_FAILURE");
        }
 
        if (!t_relay()) {
@@ -551,6 +546,10 @@ route[WITHINDLG] {
                                setflag(FLT_ACC); # do accounting ...
                                setflag(FLT_ACCFAILED); # ... even if the 
transaction fails
                        }
+                       if ( is_method("ACK") ) {
+                               # ACK is forwarded statelessy
+                               route(NATMANAGE);
+                       }
                        route(RELAY);
                } else {
                        if (is_method("SUBSCRIBE") && uri == myself) {
@@ -733,11 +732,11 @@ route[AUTH] {
 }
 
 # Caller NAT detection route
-route[NAT] {
+route[NATDETECT] {
 #!ifdef WITH_NAT
        force_rport();
        if (nat_uac_test("19")) {
-               if (method=="REGISTER") {
+               if (is_method("REGISTER")) {
                        fix_nated_register();
                } else {
                        fix_nated_contact();
@@ -749,14 +748,30 @@ route[NAT] {
 }
 
 # RTPProxy control
-route[RTPPROXY] {
+route[NATMANAGE] {
 #!ifdef WITH_NAT
-       if (is_method("BYE")) {
-               unforce_rtp_proxy();
-       } else if (is_method("INVITE")){
-               rtpproxy_offer();
+       if (is_request()) {
+               if(has_totag()) {
+                       if(check_route_param("nat=yes")) {
+                               setbflag(FLB_NATB);
+                       }
+               }
+       }
+       if (!(isflagset(FLT_NATS) || isbflagset(FLB_NATB)))
+               return;
+
+       rtpproxy_manage();
+
+       if (is_request()) {
+               if (!has_totag()) {
+                       add_rr_param(";nat=yes");
+               }
+       }
+       if (is_reply()) {
+               if(isbflagset(FLB_NATB)) {
+                       fix_nated_contact();
+               }
        }
-       if (!has_totag()) add_rr_param(";nat=yes");
 #!endif
        return;
 }
@@ -842,33 +857,22 @@ route[TOVOICEMAIL] {
        return;
 }
 
-# Sample branch router
-branch_route[BRANCH_ONE] {
-       xdbg("new branch at $ru\n");
+# manage outgoing branches
+branch_route[MANAGE_BRANCH] {
+       xdbg("new branch [$T_branch_idx] to $ru\n");
+       route(NATMANAGE);
 }
 
-# Sample onreply route
-onreply_route[REPLY_ONE] {
+# manage incoming replies
+onreply_route[MANAGE_REPLY] {
        xdbg("incoming reply\n");
-#!ifdef WITH_NAT
-       if ((isflagset(FLT_NATS) || isbflagset(FLB_NATB))
-                       && status=~"(183)|(2[0-9][0-9])") {
-               rtpproxy_answer();
-       }
-       if (isbflagset("6")) {
-               fix_nated_contact();
-       }
-#!endif
+       if(status=~"[12][0-9][0-9]")
+               route(NATMANAGE);
 }
 
-# Sample failure route
-failure_route[FAIL_ONE] {
-#!ifdef WITH_NAT
-       if (is_method("INVITE")
-                       && (isbflagset(FLB_NATB) || isflagset(FLT_NATS))) {
-               unforce_rtp_proxy();
-       }
-#!endif
+# manage failure routing cases
+failure_route[MANAGE_FAILURE] {
+       route(NATMANAGE);
 
        if (t_is_canceled()) {
                exit;


_______________________________________________
sr-dev mailing list
[email protected]
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to