Blame opensips-0026-Fix-IPv6-insertion-in-fix_nated_contact.patch

aa419c
From: Bogdan-Andrei Iancu <bogdan@opensips.org>
aa419c
Date: Fri, 5 Feb 2016 13:31:40 +0200
aa419c
Subject: [PATCH] Fix IPv6 insertion in fix_nated_contact()
aa419c
aa419c
Add the [ ]  around IPv6 in the newly built contact URI.
aa419c
Reported by Jonathan Hunter on the mailing list
aa419c
aa419c
(cherry picked from commit ce89e291e0616d80d555f1e386edde5bbd3922e9)
aa419c
aa419c
diff --git a/modules/nathelper/nathelper.c b/modules/nathelper/nathelper.c
aa419c
index d72abc2..67296c0 100644
aa419c
--- a/modules/nathelper/nathelper.c
aa419c
+++ b/modules/nathelper/nathelper.c
aa419c
@@ -601,6 +601,7 @@ fix_nated_contact_f(struct sip_msg* msg, char* str1, char* str2)
aa419c
 
aa419c
 		cp = ip_addr2a(&msg->rcv.src_ip);
aa419c
 		len = (hostport.s-c->uri.s) + strlen(cp) + 6 /* :port */
aa419c
+			+ 2 /* just in case if IPv6 */
aa419c
 			+ (params?params->len+(is_enclosed?0:2):0)
aa419c
 			+ 1 + left.len + left2.len;
aa419c
 		buf = pkg_malloc(len);
aa419c
@@ -610,15 +611,28 @@ fix_nated_contact_f(struct sip_msg* msg, char* str1, char* str2)
aa419c
 		}
aa419c
 		temp = hostport.s[0]; hostport.s[0] = '\0';
aa419c
 		if (params==NULL) {
aa419c
-			len1 = snprintf(buf, len, "%s%s:%d%.*s%.*s", c->uri.s, cp,
aa419c
-				msg->rcv.src_port,left.len,left.s,left2.len,left2.s);
aa419c
+			if (msg->rcv.src_ip.af==AF_INET6)
aa419c
+				len1 = snprintf(buf, len, "%s[%s]:%d%.*s%.*s", c->uri.s, cp,
aa419c
+					msg->rcv.src_port,left.len,left.s,left2.len,left2.s);
aa419c
+			else
aa419c
+				len1 = snprintf(buf, len, "%s%s:%d%.*s%.*s", c->uri.s, cp,
aa419c
+					msg->rcv.src_port,left.len,left.s,left2.len,left2.s);
aa419c
 		} else if (!is_enclosed) {
aa419c
-			len1 = snprintf(buf, len, "<%s%s:%d%.*s>", c->uri.s, cp,
aa419c
-				msg->rcv.src_port,params->len,params->s);
aa419c
+			if (msg->rcv.src_ip.af==AF_INET6)
aa419c
+				len1 = snprintf(buf, len, "<%s[%s]:%d%.*s>", c->uri.s, cp,
aa419c
+					msg->rcv.src_port,params->len,params->s);
aa419c
+			else
aa419c
+				len1 = snprintf(buf, len, "<%s%s:%d%.*s>", c->uri.s, cp,
aa419c
+					msg->rcv.src_port,params->len,params->s);
aa419c
 		} else {
aa419c
-			len1 = snprintf(buf, len, "%s%s:%d%.*s%.*s%.*s", c->uri.s, cp,
aa419c
-				msg->rcv.src_port,params->len,params->s,
aa419c
-				left.len,left.s,left2.len,left2.s);
aa419c
+			if (msg->rcv.src_ip.af==AF_INET6)
aa419c
+				len1 = snprintf(buf, len, "%s[%s]:%d%.*s%.*s%.*s", c->uri.s, cp,
aa419c
+					msg->rcv.src_port,params->len,params->s,
aa419c
+					left.len,left.s,left2.len,left2.s);
aa419c
+			else
aa419c
+				len1 = snprintf(buf, len, "%s%s:%d%.*s%.*s%.*s", c->uri.s, cp,
aa419c
+					msg->rcv.src_port,params->len,params->s,
aa419c
+					left.len,left.s,left2.len,left2.s);
aa419c
 		}
aa419c
 		if (len1 < len)
aa419c
 			len = len1;