Module: sip-router Branch: master Commit: c70f884988c3f9298fa4d40ef12c69eea9da26a5 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=c70f8849...
Author: Juha Heinanen jh@tutpro.com Committer: Juha Heinanen jh@tutpro.com Date: Sun Oct 28 16:07:25 2012 +0200
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 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/modules_k/nathelper/nathelper.c b/modules_k/nathelper/nathelper.c index c0ab7e8..27bc1d2 100644 --- a/modules_k/nathelper/nathelper.c +++ b/modules_k/nathelper/nathelper.c @@ -855,7 +855,8 @@ add_contact_alias_0_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)) && @@ -895,8 +896,8 @@ add_contact_alias_0_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"); @@ -905,12 +906,16 @@ add_contact_alias_0_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);