Hello!

I need help understanding how the handle_ruri_alias() function works.
Call-flow: Upstream operator -> Kamailio Proxy -> Edpoint.

The upstream operator in the initial SIP INVITE in the Contact field sends us an alias parameter, in turn, our Kamailio Proxy adds its own too.
The Contact after the Proxy looks something like this:

Contact: <sip:10.0.0.115:5060;alias=10.0.0.115~5060~1;alias=3.3.3.3~5060~1>

When the Endpoint sends us a SIP BYE, then the handle_ruri_alias() absorbs not the last alias, but the first one, and this leads to the incorrect formation of a $du.
The RURI after the Proxy looks something like this:  

Request-Line: BYE sip:10.0.0.115:5060;alias=3.3.3.3~5060~1 SIP/2.0

The first thing that comes to mind is a modification of the original Contact field with storing it's within a dialogue ...

Is it possible to elegantly solve this problem?

--

BR,
Denys Pozniak