From dab16a02fbfc6d92ec79f083fd7a19eebf8db035 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 18 Jun 2013 12:50:52 -0400 Subject: [PATCH] backport c70f884988c3f9298fa4d40ef12c69eea9da26a5 from kamailio modules_k/nathelper: add_contact_alias ipv6 fix - When add_contact_alias() is called without arguments, it now adds brackets around received ipv6 address in order to make $du syntactically valid. --- modules_k/nathelper/nathelper.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/modules_k/nathelper/nathelper.c b/modules_k/nathelper/nathelper.c index a642d657b..9fe74f985 100644 --- a/modules_k/nathelper/nathelper.c +++ b/modules_k/nathelper/nathelper.c @@ -831,7 +831,8 @@ add_contact_alias_f(struct sip_msg* msg, char* str1, char* str2) } /* Compare source ip and port against contact uri */ - if ((ip = str2ip(&(uri.host))) == NULL) { + if (((ip = str2ip(&(uri.host))) == NULL) && + ((ip = str2ip6(&(uri.host))) == NULL)) { LM_DBG("contact uri host is not an ip address\n"); } else { if (ip_addr_cmp(ip, &(msg->rcv.src_ip)) && @@ -871,8 +872,8 @@ add_contact_alias_f(struct sip_msg* msg, char* str1, char* str2) } /* Create ;alias param */ - param_len = SALIAS_LEN + IP6_MAX_STR_SIZE + 1 /* ~ */ + 5 /* port */ + - 1 /* ~ */ + 1 /* proto */ + 1 /* closing > */; + param_len = SALIAS_LEN + 1 /* [ */ + IP6_MAX_STR_SIZE + 1 /* ] */ + + 1 /* ~ */ + 5 /* port */ + 1 /* ~ */ + 1 /* proto */ + 1 /* > */; param = (char*)pkg_malloc(param_len); if (!param) { LM_ERR("no pkg memory left for alias param\n"); @@ -881,12 +882,16 @@ add_contact_alias_f(struct sip_msg* msg, char* str1, char* str2) at = param; /* ip address */ append_str(at, SALIAS, SALIAS_LEN); + if (msg->rcv.src_ip.af == AF_INET6) + append_chr(at, '['); ip_len = ip_addr2sbuf(&(msg->rcv.src_ip), at, param_len - SALIAS_LEN); if (ip_len <= 0) { LM_ERR("failed to copy source ip\n"); goto err; } at = at + ip_len; + if (msg->rcv.src_ip.af == AF_INET6) + append_chr(at, ']'); /* port */ append_chr(at, '~'); port = int2str(msg->rcv.src_port, &len);