[sr-dev] git:master:6e52c398: Merge pull request #686 from snen/nathelper_branch

GitHub noreply at github.com
Mon Jun 27 15:00:39 CEST 2016


Module: kamailio
Branch: master
Commit: 6e52c398c6d4d5634043dc82adfb2c530ff59156
URL: https://github.com/kamailio/kamailio/commit/6e52c398c6d4d5634043dc82adfb2c530ff59156

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: GitHub <noreply at github.com>
Date: 2016-06-27T15:00:34+02:00

Merge pull request #686 from snen/nathelper_branch

Nathelper/nat_traversal: branch=0

---

Modified: modules/nat_traversal/nat_traversal.c
Modified: modules/nathelper/sip_pinger.h

---

Diff:  https://github.com/kamailio/kamailio/commit/6e52c398c6d4d5634043dc82adfb2c530ff59156.diff
Patch: https://github.com/kamailio/kamailio/commit/6e52c398c6d4d5634043dc82adfb2c530ff59156.patch

---

diff --git a/modules/nat_traversal/nat_traversal.c b/modules/nat_traversal/nat_traversal.c
index 0acdd17..fb1dd30 100644
--- a/modules/nat_traversal/nat_traversal.c
+++ b/modules/nat_traversal/nat_traversal.c
@@ -1508,6 +1508,8 @@ ClientNatTest(struct sip_msg *msg, unsigned int tests)
 
 
 #define FROM_PREFIX "sip:keepalive@"
+#define MAX_BRANCHID 9999999
+#define MIN_BRANCHID 1000000
 
 static void
 send_keepalive(NAT_Contact *contact)
@@ -1536,7 +1538,7 @@ send_keepalive(NAT_Contact *contact)
 
     len = snprintf(buffer, sizeof(buffer),
                    "%s %s SIP/2.0\r\n"
-                   "Via: SIP/2.0/UDP %.*s:%d;branch=0\r\n"
+                   "Via: SIP/2.0/UDP %.*s:%d;branch=z9hG4bK%ld\r\n"
                    "From: %s;tag=%x\r\n"
                    "To: %s\r\n"
                    "Call-ID: %s-%x-%x@%.*s\r\n"
@@ -1546,6 +1548,7 @@ send_keepalive(NAT_Contact *contact)
                    keepalive_params.method, contact->uri,
                    contact->socket->address_str.len,
                    contact->socket->address_str.s, contact->socket->port_no,
+                   (long)(rand()/(float)RAND_MAX * (MAX_BRANCHID-MIN_BRANCHID) + MIN_BRANCHID),
                    from_uri, keepalive_params.from_tag++,
                    contact->uri, keepalive_params.callid_prefix,
                    keepalive_params.callid_counter++, get_ticks(),
diff --git a/modules/nathelper/sip_pinger.h b/modules/nathelper/sip_pinger.h
index 7cd5e0c..5166a75 100644
--- a/modules/nathelper/sip_pinger.h
+++ b/modules/nathelper/sip_pinger.h
@@ -116,6 +116,9 @@ static inline char* build_sipping(str *curi, struct socket_info* s, str *path,
 								str *ruid, unsigned int aorhash, int *len_p)
 {
 #define s_len(_s) (sizeof(_s)-1)
+#define MAX_BRANCHID 9999999
+#define MIN_BRANCHID 1000000
+#define LEN_BRANCHID 7  /* NOTE: this must be sync with the MX and MIN values !! */
 	static char buf[MAX_SIPPING_SIZE];
 	char *p;
 	int len;
@@ -135,7 +138,7 @@ static inline char* build_sipping(str *curi, struct socket_info* s, str *path,
 	if ( sipping_method.len + 1 + curi->len + s_len(" SIP/2.0"CRLF) +
 		s_len("Via: SIP/2.0/UDP ") + vaddr.len +
 				((s->address.af==AF_INET6)?2:0) +
-				1 + vport.len + s_len(";branch=0") +
+				1 + vport.len + s_len(";branch=z9hG4bK") + LEN_BRANCHID +
 		(path->len ? (s_len(CRLF"Route: ") + path->len) : 0) +
 		s_len(CRLF"From: ") +  sipping_from.len + s_len(";tag=") +
 				ruid->len + 1 + 8 + 1 + 8 +
@@ -164,13 +167,16 @@ static inline char* build_sipping(str *curi, struct socket_info* s, str *path,
 	}
 	*(p++) = ':';
 	append_str( p, vport.s, vport.len);
+	append_fix( p, ";branch=z9hG4bK");
+	int2bstr(
+		(long)(rand()/(float)RAND_MAX * (MAX_BRANCHID-MIN_BRANCHID) + MIN_BRANCHID),
+		p+LEN_BRANCHID-INT2STR_MAX_LEN+1, NULL);
+	p += LEN_BRANCHID;
 	if (path->len) {
-		append_fix( p, ";branch=0"CRLF"Route: ");
+		append_fix( p, CRLF"Route: ");
 		append_str( p, path->s, path->len);
-		append_fix( p, CRLF"From: ");
-	} else {
-		append_fix( p, ";branch=0"CRLF"From: ");
 	}
+	append_fix( p, CRLF"From: ");
 	append_str( p, sipping_from.s, sipping_from.len);
 	append_fix( p, ";tag=");
 	append_str( p, ruid->s, ruid->len);




More information about the sr-dev mailing list