### Description
Kamailio v5.5.6 with topos module and postgres DB.
UAC (A) -> Kamailio Registrar (B) -> Kamailio PSTN GW (C) -> PSTN (D) Call goes from A to D, PSTN sends UPDATE, UPDATE is routed from C to A instead to B and then to A.
#### Reproduction
Caller calls callee and receives an UPDATE from callee. In my case it was when the call was routed to voicemail.
#### Log Messages
``` Kamailio takes the wrong route in UPDATE (upstream) case.
May 3 15:23:12 sipproxy /usr/sbin/kamailio[263013]: DEBUG: topos [tps_msg.c:882]: tps_request_received(): r-uri updated to: [sip:1234@<UAC-IP>;uniq=B0EB9A84A278626DA07219E2AE01C] May 3 15:23:12 sipproxy /usr/sbin/kamailio[263013]: DEBUG: topos [tps_msg.c:187]: tps_add_headers(): adding to headers(0) - [Route: sip:<<KamailioPSTNgwIP>>;lr=on;ftag=9945501E2B94B883;did=1fc.42f;nat=yes#015#012] May 3 15:23:12 sipproxy /usr/sbin/kamailio[263013]: DEBUG: topos [tps_msg.c:187]: tps_add_headers(): adding to headers(0) - [P-SR-XUID: atpsh-64527b0a-40362-1#015#012]
The right one would be the x_rr (a_rr), but it takes only the s_rr:
May 3 15:23:12 sipproxy /usr/sbin/kamailio[263013]: DEBUG: db_postgres [km_res.c:234]: db_postgres_convert_rows(): PQgetvalue(0x7fcb4893db50,0,7)=[sip:<KamailioRegistrarIP>;lr=on;ftag=9945501E2B94B883;did=1fc.7b92] May 3 15:23:12 sipproxy /usr/sbin/kamailio[263013]: DEBUG: db_postgres [km_res.c:242]: db_postgres_convert_rows(): [0][7] Column[x_rr]=[sip:<KamailioRegistrarIP>;lr=on;ftag=9945501E2B94B883;did=1fc.7b92]
May 3 15:23:12 sipproxy /usr/sbin/kamailio[263013]: DEBUG: db_postgres [km_res.c:234]: db_postgres_convert_rows(): PQgetvalue(0x7fcb4893db50,0,8)=[sip:<PSTNgw>:5060;transport=udp;lr;Hpt=8ef8_116;CxtId=3;TRC=ffffffff-ffffffff;X-HwB2bUaCookie=18614] May 3 15:23:12 sipproxy /usr/sbin/kamailio[263013]: DEBUG: db_postgres [km_res.c:242]: db_postgres_convert_rows(): [0][8] Column[y_rr]=[sip:<PSTNgw>:5060;transport=udp;lr;Hpt=8ef8_116;CxtId=3;TRC=ffffffff-ffffffff;X-HwB2bUaCookie=18614]
May 3 15:23:12 sipproxy /usr/sbin/kamailio[263013]: DEBUG: db_postgres [km_res.c:234]: db_postgres_convert_rows(): PQgetvalue(0x7fcb4893db50,0,9)=[sip:<<KamailioPSTNgwIP>>;lr=on;ftag=9945501E2B94B883;did=1fc.42f;nat=yes] May 3 15:23:12 sipproxy /usr/sbin/kamailio[263013]: DEBUG: db_postgres [km_res.c:242]: db_postgres_convert_rows(): [0][9] Column[s_rr]=[sip:<<KamailioPSTNgwIP>>;lr=on;ftag=9945501E2B94B883;did=1fc.42f;nat=yes]
May 3 15:23:12 sipproxy /usr/sbin/kamailio[263019]: DEBUG: db_postgres [km_res.c:242]: db_postgres_convert_rows(): [0][10] Column[a_rr]=[sip:<KamailioRegistrarIP>;lr=on;ftag=9945501E2B94B883;did=1fc.7b92] May 3 15:23:12 sipproxy /usr/sbin/kamailio[263019]: DEBUG: db_postgres [km_res.c:234]: db_postgres_convert_rows(): PQgetvalue(0x7fcb4893dbd8,0,11)=[] ```
### Possible Solutions
Respect Route headers for UPDATE messages.
### Additional Information
Current running kamailio 5.5.6 but tried also latest 5.6.4 with same behavior.
``` version: kamailio 5.5.6 (x86_64/linux) 72dbb0 flags: USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MMAP, PKG_MALLOC, 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_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB poll method support: poll, epoll_lt, epoll_et, sigio_rt, select. id: 72dbb0 compiled on 05:48:21 Apr 27 2023 with gcc 11.3.0 ```
* **Operating System**:
``` Distributor ID: Ubuntu Description: Ubuntu 22.04.2 LTS Release: 22.04 Codename: jammy Linux sipproxy 5.15.0-70-generic #77-Ubuntu SMP Tue Mar 21 14:02:37 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux ```
Possibly related bug: https://github.com/kamailio/kamailio/issues/3090
Thanks for the report, will have a look to it.
Fix was created, some more tests are currently done to prevent regressions.
Fixed, will also backport to stable branches
Closed #3437 as completed.
Hello,
I still have this pb on kamailio v5.7.4 (debian buster - packages updated from deb.kamailio.org) topos with redis
Peer A (caller) => SIP PROXY B => [ Kamailio GW C ] => PSTN D
SIP Update coming from D are routed directly from C to A
I had to unload topos module
Example : 
Hi @Antoineb2s
Did you also check kamailio logs for SQL-Errors? I had a same behavior, but it was because our DB was not properly migrated and some text-fields were too short to save all the data which topos needs. In Postgres I changed from varchar to text.
Regards
Hi,
Don't know what expecting from redis but no error message for redis-server
I also noticed a kamailio error message related to this : Mar 27 09:19:09 tcossbcsfr3 /usr/sbin/kamailio[5246]: ERROR: {1 1 UPDATE e806c441901b4f16a2c74df5a379f973} uac [replace.c:660]: restore_uri(): new URI [] shorter than old URI [sip:+33XXXXXXXXX@TSFR.SBC.SFR.NETTSFR.SBC.SFR.NET]
maybe because I have to remove a prefix before forwarding the INVITE to PSTN ($rU and $tU)...dont know if it's related to
Hello, have you tried kamailio-5.8.1-dev (nightly)? It solved the problem for me (see #3757), but it would be good to have another confirmation.
Thks I'll try !
I first started to install v5.8.0 yesterday but was facing #3785