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

Author: Daniel-Constantin Mierla <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date:   Sat Dec 22 09:42:35 2012 +0100

nathelper(k): new test 128 to check port in contact against source port

- used for nat_uac_test()
- imported from ser flavour

---

 modules_k/nathelper/README                  |    3 ++
 modules_k/nathelper/doc/nathelper_admin.xml |    5 ++++
 modules_k/nathelper/nathelper.c             |   31 ++++++++++++++++++++++++++-
 3 files changed, 38 insertions(+), 1 deletions(-)

diff --git a/modules_k/nathelper/README b/modules_k/nathelper/README
index a11f2f8..36c4629 100644
--- a/modules_k/nathelper/README
+++ b/modules_k/nathelper/README
@@ -503,6 +503,9 @@ fix_nated_register();
      * 32 - test if the source IP address of signaling is a RFC1918
        address
      * 64 - test if the source connection of signaling is a WebSocket
+     * 128 - test if the Contact URI port differs from the source port of
+       the request (Warning: this is might be legal or even intended
+       combination in non natted scenarios)
 
    All flags can be bitwise combined, the test returns true if any of the
    tests identified a NAT.
diff --git a/modules_k/nathelper/doc/nathelper_admin.xml 
b/modules_k/nathelper/doc/nathelper_admin.xml
index bc4c8d7..ba8f866 100644
--- a/modules_k/nathelper/doc/nathelper_admin.xml
+++ b/modules_k/nathelper/doc/nathelper_admin.xml
@@ -570,6 +570,11 @@ fix_nated_register();
                        <emphasis>64</emphasis> -  test if the source 
connection of
                        signaling is a WebSocket
                        </para></listitem>
+                       <listitem><para>
+                       <emphasis>128</emphasis> -  test if the Contact URI 
port differs
+                       from the source port of the request (Warning: this is 
might be legal
+                       or even intended combination in non natted scenarios)
+                       </para></listitem>
                        </itemizedlist>
                <para>
                All flags can be bitwise combined, the test returns true if any 
of 
diff --git a/modules_k/nathelper/nathelper.c b/modules_k/nathelper/nathelper.c
index 9f72795..a38fea4 100644
--- a/modules_k/nathelper/nathelper.c
+++ b/modules_k/nathelper/nathelper.c
@@ -244,6 +244,7 @@ MODULE_VERSION
 #define        NAT_UAC_TEST_RPORT      0x10
 #define        NAT_UAC_TEST_O_1918     0x20
 #define NAT_UAC_TEST_WS                0x40
+#define        NAT_UAC_TEST_C_PORT     0x80
 
 
 #define DEFAULT_RTPP_SET_ID            0
@@ -1397,6 +1398,27 @@ contact_1918(struct sip_msg* msg)
 }
 
 /*
+ * test if source port of signaling is different from
+ * port advertised in Contact
+ */
+static int
+contact_rport(struct sip_msg* msg)
+{
+       struct sip_uri uri;
+       contact_t* c;
+
+       if (get_contact_uri(msg, &uri, &c) == -1) {
+               return -1;
+       }
+
+       if (msg->rcv.src_port != (uri.port_no ? uri.port_no : SIP_PORT)) {
+               return 1;
+       } else {
+               return 0;
+       }
+}
+
+/*
  * test for occurrence of RFC1918 IP address in SDP
  */
 static int
@@ -1496,12 +1518,19 @@ nat_uac_test_f(struct sip_msg* msg, char* str1, char* 
str2)
                return 1;
 
        /*
-        * tests prototype to check whether the message arrived on a WebSocket
+        * test prototype to check whether the message arrived on a WebSocket
         */
        if ((tests & NAT_UAC_TEST_WS)
                && (msg->rcv.proto == PROTO_WS || msg->rcv.proto == PROTO_WSS))
                return 1;
 
+       /*
+        * test if source port of signaling is different from
+        * port advertised in Contact
+        */
+       if ((tests & NAT_UAC_TEST_C_PORT) && (contact_rport(msg) > 0))
+               return 1;
+
        /* no test succeeded */
        return -1;
 


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

Reply via email to