nathelper: check if alias ipv6 has already square brackets
authorDaniel-Constantin Mierla <miconda@gmail.com>
Wed, 4 Sep 2024 16:54:22 +0000 (18:54 +0200)
committerVictor Seva <vseva@debian.org>
Tue, 8 Oct 2024 06:56:35 +0000 (08:56 +0200)
- GH #3968

(cherry picked from commit 6e01172a138d395fa3f7c3f25238647934137dba)

Gbp-Pq: Name nathelper-check-if-alias-ipv6-has-already-square-bra.patch

src/modules/nathelper/nathelper.c

index 9c0bebad3a77722d29891c95b285f6fb9b14d75e..9ee73e62a21aed765f27fb679b316a0ebd339eb5 100644 (file)
@@ -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, '[');