From: Daniel-Constantin Mierla Date: Wed, 4 Sep 2024 16:54:22 +0000 (+0200) Subject: nathelper: check if alias ipv6 has already square brackets X-Git-Tag: archive/raspbian/5.8.3-1+rpi1^2~3 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=7197408445dbc46f72015a728420daba008b45de;p=kamailio.git nathelper: check if alias ipv6 has already square brackets - GH #3968 (cherry picked from commit 6e01172a138d395fa3f7c3f25238647934137dba) Gbp-Pq: Name nathelper-check-if-alias-ipv6-has-already-square-bra.patch --- diff --git a/src/modules/nathelper/nathelper.c b/src/modules/nathelper/nathelper.c index 9c0bebad..9ee73e62 100644 --- a/src/modules/nathelper/nathelper.c +++ b/src/modules/nathelper/nathelper.c @@ -1140,6 +1140,7 @@ static int ki_handle_ruri_alias_mode(struct sip_msg *msg, int mode) *trans, *start; unsigned int len, rest_len, val_len, alias_len, proto_type, cur_uri_len, ip_len, ip_port_len, port_len, i; + int is_ipv6 = 0; if(parse_sip_msg_uri(msg) < 0) { LM_ERR("while parsing Request-URI\n"); @@ -1188,7 +1189,6 @@ static int ki_handle_ruri_alias_mode(struct sip_msg *msg, int mode) // IPv6 needs some [] added when composing a SIP URI, which further // complicates this code. ip_len = port - val; - int is_ipv6 = 0; for(i = 0; i < ip_len; i++) { if(val[i] == ':') { is_ipv6 = 1; @@ -1206,7 +1206,7 @@ static int ki_handle_ruri_alias_mode(struct sip_msg *msg, int mode) append_str(at, "sip:", 4); ip_port_len = trans - val; alias_len = _ksr_contact_salias.len + ip_port_len + 2 /* ~n */; - if(is_ipv6) { + if(is_ipv6 && val[0] != '[') { // IPv6 - add '[' ']' around IP // then append ':' and copy the port append_chr(at, '[');