Ver Fonte

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

- used for nat_uac_test()
- imported from ser flavour
Daniel-Constantin Mierla há 12 anos atrás
pai
commit
bf3acaf089

+ 3 - 0
modules_k/nathelper/README

@@ -503,6 +503,9 @@ fix_nated_register();
      * 32 - test if the source IP address of signaling is a RFC1918
      * 32 - test if the source IP address of signaling is a RFC1918
        address
        address
      * 64 - test if the source connection of signaling is a WebSocket
      * 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
    All flags can be bitwise combined, the test returns true if any of the
    tests identified a NAT.
    tests identified a NAT.

+ 5 - 0
modules_k/nathelper/doc/nathelper_admin.xml

@@ -570,6 +570,11 @@ fix_nated_register();
 			<emphasis>64</emphasis> -  test if the source connection of
 			<emphasis>64</emphasis> -  test if the source connection of
 			signaling is a WebSocket
 			signaling is a WebSocket
 			</para></listitem>
 			</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>
 			</itemizedlist>
 		<para>
 		<para>
 		All flags can be bitwise combined, the test returns true if any of 
 		All flags can be bitwise combined, the test returns true if any of 

+ 30 - 1
modules_k/nathelper/nathelper.c

@@ -244,6 +244,7 @@ MODULE_VERSION
 #define	NAT_UAC_TEST_RPORT	0x10
 #define	NAT_UAC_TEST_RPORT	0x10
 #define	NAT_UAC_TEST_O_1918	0x20
 #define	NAT_UAC_TEST_O_1918	0x20
 #define NAT_UAC_TEST_WS		0x40
 #define NAT_UAC_TEST_WS		0x40
+#define	NAT_UAC_TEST_C_PORT	0x80
 
 
 
 
 #define DEFAULT_RTPP_SET_ID		0
 #define DEFAULT_RTPP_SET_ID		0
@@ -1396,6 +1397,27 @@ contact_1918(struct sip_msg* msg)
 	return (is1918addr(&(uri.host)) == 1) ? 1 : 0;
 	return (is1918addr(&(uri.host)) == 1) ? 1 : 0;
 }
 }
 
 
+/*
+ * 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
  * test for occurrence of RFC1918 IP address in SDP
  */
  */
@@ -1496,12 +1518,19 @@ nat_uac_test_f(struct sip_msg* msg, char* str1, char* str2)
 		return 1;
 		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)
 	if ((tests & NAT_UAC_TEST_WS)
 		&& (msg->rcv.proto == PROTO_WS || msg->rcv.proto == PROTO_WSS))
 		&& (msg->rcv.proto == PROTO_WS || msg->rcv.proto == PROTO_WSS))
 		return 1;
 		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 */
 	/* no test succeeded */
 	return -1;
 	return -1;