### Description
<!-- Explain what you did, what you expected to happen, and what actually happened. -->
We are running Kamailio in front of a backend farm, REGISTERs go directly to the backend. After registration, the backend sends out OPTIONS requests periodically. This worked with 5.8.2. Now when running a 5.8.3 server (taken from your apt repository), I get the following errors in the log:
``` Sep 04 14:41:36 sipproxy /usr/sbin/kamailio[124]: ERROR: tm [ut.h:235]: uri2dst2(): bad_uri: [sip:[[2001:16e0:affe:affe:24a2:55a2:15bf:23d1]]:59580;transport=tls] Sep 04 14:41:36 sipproxy /usr/sbin/kamailio[124]: ERROR: tm [t_fwd.c:1764]: t_forward_nonack(): failure to add branches ```
There are extra square brackets in the URI. I compared the REGISTERs from old and new Kamailio to the backend, and also the OPTIONS packets sent by the backend, the are identical except for the obvious differences.
### Troubleshooting
#### Reproduction
<!-- If the issue can be reproduced, describe how it can be done. -->
* Have a Kamailio with nathelper enabled. * Do something like this for nat detection: ``` def ksr_route_natdetect(self, msg): KSR.force_rport() # Checks if request goes to backend or not if not msg.is_internal_message(): KSR.setbflag(FLB_NATB) KSR.setflag(FLT_NATS) if KSR.textops.is_present_hf("Contact") > 0: if KSR.nathelper.set_contact_alias() < 0: msg.log("Error in aliasing contact") KSR.sl.sl_send_reply(400,"Bad request") return False else: if msg.is_request(): KSR.nathelper.handle_ruri_alias() return 1 ```
* register a phone to the backend (e.g. an Asterisk server) * send an OPTIONS packet from the backend to the registered device.
#### SIP
The REGISTER from Kamailio to the backend looks like this:
``` REGISTER sip:domain;transport=tcp SIP/2.0 Via: SIP/2.0/TCP 100.74.11.1:5063;branch=z9hG4bK6c3e.2cedb59e7724d263255c1996d9d2d4fa.0;i=6 Via: SIP/2.0/TLS [2001:16e0:affe:affe:24a2:55a2:15bf:23d1]:61391;received=2001:16e0:affe:affe:24a2:55a2:15bf:23d1;rport=61391;branch=z9hG4bKPjAB7F905A-A6A2-491D-A456-89C8FD4C5183;alias Max-Forwards: 69 From: sip:dZmIQyb70tzt2J9@sdammone;tag=AAA80708-4968-4B49-95B8-7DBCEFCC5E62 To: sip:dZmIQyb70tzt2J9@sdammone Call-ID: 4922AA11-F4BA-49D0-AE64-EECF49735684 CSeq: 44208 REGISTER User-Agent: foobar Supported: outbound, path Contact: sip:dZmIQyb70tzt2J9@[2001:16e0:affe:affe:24a2:55a2:15bf:23d1]:61391;transport=TLS;p-xs=6eb17056fba34ce6bc7d458a1a7a80ba;ob;alias=[2001:16e0:affe:affe:24a2:55a2:15bf:23d1]~61391~3;reg-id=1;+sip.instance="urn:uuid:00000000-0000-0000-0000-00000c73bfc6" Expires: 300 Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS Content-Length: 0 Path: sip:100.74.11.1:5063;transport=tcp;lr;xep=true ```
The OPTIONS packet from backend to the client looks like this:
``` OPTIONS sip:dZmIQyb70tzt2J9@[2001:16e0:affe:affe:24a2:55a2:15bf:23d1]:61391;transport=TLS;p-xs=6eb17056fba34ce6bc7d458a1a7a80ba;ob;alias=[2001:16e0:affe:affe:24a2:55a2:15bf:23d1]~61391~3 SIP/2.0 Via: SIP/2.0/TCP 100.74.130.66:5060;rport;branch=z9hG4bKPj3e558221-2506-4a2b-9daa-ff7e73d05e8c;alias From: sip:dZmIQyb70tzt2J9@sdammone;tag=18c9809a-4775-4c35-8e88-5c5a7bdcf1fe To: sip:dZmIQyb70tzt2J9@[2001:16e0:affe:affe:24a2:55a2:15bf:23d1];p-xs=6eb17056fba34ce6bc7d458a1a7a80ba;ob;alias=[2001:16e0:affe:affe:24a2:55a2:15bf:23d1]~61391~3 Contact: sip:dZmIQyb70tzt2J9@100.74.130.66:5060;transport=TCP Call-ID: 2e1efbd3-9366-4542-b909-83429266b6ef CSeq: 2989 OPTIONS Supported: path Route: sip:100.74.11.1:5063;transport=tcp;lr;xep=true Max-Forwards: 70 User-Agent: barfoo Content-Length: 0 ```
#### Log Messages
``` Sep 04 14:41:36 sipproxy /usr/sbin/kamailio[124]: ERROR: tm [ut.h:235]: uri2dst2(): bad_uri: [sip:[[2001:16e0:affe:affe:24a2:55a2:15bf:23d1]]:59580;transport=tls] Sep 04 14:41:36 sipproxy /usr/sbin/kamailio[124]: ERROR: tm [t_fwd.c:1764]: t_forward_nonack(): failure to add branches ```
### Possible Solutions
Downgrading to 5.8.2 again works.
I suppose, the problem comes from this commit by @vingarzan: https://github.com/kamailio/kamailio/commit/52ab6f3dcf5ad8d967be8bdecaa64ef3...
### Additional Information
* **Kamailio Version** - output of `kamailio -v`
``` version: kamailio 5.8.3 (x86_64/linux) flags: USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MMAP, PKG_MALLOC, MEM_JOIN_FREE, Q_MALLOC, F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLOCKLIST, HAVE_RESOLV_RES, TLS_PTHREAD_MUTEX_SHARED ADAPTIVE_WAIT_LOOPS 1024, MAX_RECV_BUFFER_SIZE 262144, MAX_SEND_BUFFER_SIZE 262144, MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB poll method support: poll, epoll_lt, epoll_et, sigio_rt, select. id: unknown compiled with gcc 11.4.0 ```
* **Operating System**:
<!-- Details about the operating system, the type: Linux (e.g.,: Debian 8.4, Ubuntu 16.04, CentOS 7.1, ...), MacOS, xBSD, Solaris, ...; Kernel details (output of `lsb_release -a` and `uname -a`) -->
``` Ubuntu Jammy ```