<p></p>
<h3>Description</h3>
<p>When specifying a <em>record_route_advertised_address()</em>  before using the uac_replace function (for changing the FROM and TO Header field URIs), the rr param static buffer doesn't get emptied and a fallowing CALL (not a request in the same call) contains the rr params of the first call placed after restarting kamailio (to get the buffer resetted).</p>
<h3>Troubleshooting</h3>
<p>Restarting kamailio will reset the wrong buffer pointer and gets you another functioning call.<br>
Alternatively place the <em>record_route_advertised_address()</em> after using uac_replace function.</p>
<h4>Reproduction</h4>
<p>use record_route_advertised_address()  before doing a uac_replace. This will get the vst and vsf parameters doubled in the rr of the second call after kamailio is restarted. When you place a call the first call proxied will carry only one set of vsf & vst parameters in the RR. The second call will carry the vst & vsf of the first call and a set of vst & vsf of the second call. If the uac_replace is replacing the same URIs the contents of the two sets of vsf and vst parameters in the RR Header will be identical.</p>
<p>uac.so config:<br>
loadmodule "uac.so"<br>
modparam("uac", "restore_mode","auto");</p>
<h4>Analysis</h4>
<p>record_route() empties the RR param static buffer as follows, if it contains other message's params:</p>
<p>if (rr_param_buf.len && rr_param_msg!=_m->id) {<br>
/* rr_params were set for a different message -> reset buffer */<br>
rr_param_buf.len = 0;<br>
}</p>
<p>But unfortunately, record_route_advertised_address() / record_route_preset() does not do this – it does NOT check/clean the buffer before adding RR.</p>
<p>So if the static buffer contains old entries (e.g. from an old call's subsequent request), wrong rr parameters are added.</p>
<p>This happens with uac module: restore_uri() is called for subsequent requests (via callback).<br>
restore_uri() calls (unnecessarily):</p>
<p>if ( uac_rrb.add_rr_param(msg, &add_to_rr)!=0 ) {<br>
LM_ERR("add rr param failed\n");<br>
goto failed;<br>
}</p>
<p>So, if record_route has not yet been performed at this stage, add_rr_param() adds an entry to the static rr param buffer.<br>
(for subsequent request, record_route won't be performed)</p>
<p>If, for a following call, record_route_advertised_address() / record_route_preset() is called, the buffer is not checked/emptied, and old/wrong rr params are added.--></p>
<pre><code>
#### SIP Traffic
</code></pre>
<p>Record-Route URI [truncated]: sip:my.node.com;transport=tls;r2=on;ftag=2ccb63ad;lr;vsf=AAAAAAAAAAAAAAAAAAAAADkIA0Mdsdfsdfhc2guY29tO3VzZXI9cGhvN0LmNvbQbmU-;vst=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMQEEEESwksdfsdfhddCBteAgccAQN0LmNvbQ-<br>
Record-Route Host Part: my.node.com<br>
Record-Route URI parameter: transport=tls<br>
Record-Route URI parameter: r2=on<br>
Record-Route URI parameter: ftag=2ccb63ad<br>
Record-Route URI parameter: lr<br>
Record-Route URI parameter: vsf=AAAAAAAAAAAAAAAAAAAAADkIA0Mdsdfsdfhc2guY29tO3VzZXI9cGhvN0LmNvbQbmU-<br>
Record-Route URI parameter: vst=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMQEEEESwksdfsdfhddCBteAgccAQN0LmNvbQ--<br>
Record-Route URI parameter: vst=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMQEEEESwksdfsdfhddCBteAgccAQN0LmNvbQ--<br>
Record-Route URI parameter: vsf=AAAAAAAAAAAAAAAAAAAAADkIA0Mdsdfsdfhc2guY29tO3VzZXI9cGhvN0LmNvbQbmU-<br>
Record-Route URI parameter: did=4a8.56a2</p>
<p>URI, vsf & vst anonymised</p>
<pre><code>
### Additional Information

  * **Kamailio Version** - output of `kamailio -v`

</code></pre>
<p>version: kamailio 5.2.7 (x86_64/linux)<br>
flags: STATS: Off, USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MEM, 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_BLACKLIST, HAVE_RESOLV_RES, TLS_PTHREAD_MUTEX_SHARED<br>
ADAPTIVE_WAIT_LOOPS=1024, MAX_RECV_BUFFER_SIZE 262144 MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB<br>
poll method support: poll, epoll_lt, epoll_et, sigio_rt, select.<br>
id: unknown<br>
compiled with gcc 8.3.0</p>
<pre><code>
* **Operating System**:

</code></pre>
<p>4.19.0-10-amd64 <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="31891578" data-permission-text="Title is private" data-url="https://github.com/kamailio/kamailio/issues/1" data-hovercard-type="issue" data-hovercard-url="/kamailio/kamailio/issues/1/hovercard" href="https://github.com/kamailio/kamailio/issues/1">#1</a> SMP Debian 4.19.132-1 (2020-07-24) x86_64 GNU/Linux</p>
<pre><code></code></pre>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/kamailio/kamailio/issues/2486">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABO7UZJLTENVXD4NCG4RVO3SIDWRTANCNFSM4R46JBHQ">unsubscribe</a>.<img src="https://github.com/notifications/beacon/ABO7UZOVMNHNB7LV5FEUQRTSIDWRTA5CNFSM4R46JBH2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4KS2GQ7A.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/kamailio/kamailio/issues/2486",
"url": "https://github.com/kamailio/kamailio/issues/2486",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>