Hi,

My setup has: (TLS)UAC 77.1.1.1 -> (TLS)Kamailio 17.17.17.211 (UDP) -> (UDP)Kamailio 17.17.17.181 (UDP) -> Carrier(UDP)
Both Kamailio are 4.3 with minor modifications on default cfg, and Topoh and TLS modules are used.

I am having an issue on some outbound calls from nated UACs. On these calls our SBC sometimes receives reverse invites from the carrier side within the call. When this happens, my SBC(17.17.17.211) sends the invite to UAC and the UAC sends back 200 OK (SDP). Unfortunately my SBC(17.17.17.211) sends back the ACK not to the correct UAC public port but instead to the UAC internal port making the call to crash with several retries from my SBC to send 200 OK as ACK was never received from UAC!

If you look the below traces of reverse invite past within the call, the reinvite has port private 20125 and alias the public port 2314 of UAC but the ACK bellow is send to 20125  and not to 2314 

2023/01/26 09:48:30.668634 17.17.17.181:5060 -> 17.17.17.211:5060
INVITE sip:301234567890@77.1.1.1:20125;alias=77.1.1.1~2314~1 SIP/2.0
Via: SIP/2.0/UDP 17.17.17.181;branch=z9hG4bK7b5d.78276307977b5b2776919ce1f1e76d49.0
From: <sip:300987654321@sip.mydomain.com>;tag=gK0e80b4b9
To: "301234567890" <sip:301234567890@sip.mydomain.com>;tag=07ece97c
Call-ID: 1q5nE37RGZ8a8ChI6rqShw..
CSeq: 29227 INVITE
Max-Forwards: 69
Allow: INVITE,ACK,CANCEL,BYE,INFO,PRACK,UPDATE,OPTIONS
Accept: application/sdp, application/isup, application/dtmf, application/dtmf-relay,  multipart/mixed
Supported: timer
Session-Expires: 600;refresher=uas
Min-SE: 90
Content-Length:  297
Content-Disposition: session; handling=required
Content-Type: application/sdp
Route: <sip:17.17.17.211;lr;ftag=07ece97c;vsf=AAAAAFpUAgECBwAACnAGAW5FUF4ZXUdDUUhEX1hRUC5ldQ--;vst=AAAAAAAAAAAAAAAAAAAAAABCXkYAQkdeVEJDQVtSVBRQRTYw;did=5fc.669;nat=yes>
Contact: <sip:atpsh-b5-62dfd3a3-cd5ed-1d354@17.17.17.181>

v=0
o=Sonus_UAC 14218 13519 IN IP4 14.1.1.30
s=SIP Media Capabilities
c=IN IP4 14.1.1.30
t=0 0
m=audio 18600 RTP/AVP 8 18 101
a=maxptime:20
a=rtpmap:8 PCMA/8000
a=rtpmap:18 G729/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:18 annexb=no
a=fmtp:101 0-15
a=sendrecv
a=rtcp:18601


2023/01/26 09:48:30.679743 17.17.17.211:5060 -> 17.17.17.181:5060
SIP/2.0 100 trying -- your call is important to us
Via: SIP/2.0/UDP 17.17.17.181;branch=z9hG4bK7b5d.78276307977b5b2776919ce1f1e76d49.0;rport=5060
From: <sip:300987654321@sip.mydomain.com>;tag=gK0e80b4b9
To: "301234567890" <sip:301234567890@sip.mydomain.com>;tag=07ece97c
Call-ID: 1q5nE37RGZ8a8ChI6rqShw..
CSeq: 29227 INVITE
Server: Supervoice
Content-Length: 0



2023/01/26 09:48:30.740803 17.17.17.211:5060 -> 77.1.1.1:2314
INVITE sip:301234567890@77.1.1.1:20125 SIP/2.0
Via: SIP/2.0/UDP 17.17.17.211;branch=z9hG4bK7b5d.90b692fac0d1cc8a2ac460a67a02aec9.0
Via: SIP/2.0/UDP 17.17.17.181;rport=5060;branch=z9hG4bK7b5d.78276307977b5b2776919ce1f1e76d49.0
From: <sip:300987654321@17.17.17.211:5060>;tag=gK0e80b4b9
To: "301234567890" <sip:MyTrunk@77.1.1.1:20125>;tag=07ece97c
Call-ID: 1q5nE37RGZ8a8ChI6rqShw..
CSeq: 29227 INVITE
Max-Forwards: 68
Allow: INVITE,ACK,CANCEL,BYE,INFO,PRACK,UPDATE,OPTIONS
Accept: application/sdp, application/isup, application/dtmf, application/dtmf-relay,  multipart/mixed
Supported: timer
Session-Expires: 600;refresher=uas
Min-SE: 90
Content-Length:  297
Content-Disposition: session; handling=required
Content-Type: application/sdp
Contact: <sip:atpsh-b5-62dfd3a3-cd5ed-1d354@17.17.17.181>

v=0
o=Sonus_UAC 14218 13519 IN IP4 14.1.1.28
s=SIP Media Capabilities
c=IN IP4 14.1.1.28
t=0 0
m=audio 13288 RTP/AVP 8 18 101
a=maxptime:20
a=rtpmap:8 PCMA/8000
a=rtpmap:18 G729/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:18 annexb=no
a=fmtp:101 0-15
a=sendrecv
a=rtcp:13289


2023/01/26 09:48:30.893512 77.1.1.1:2314 -> 17.17.17.211:5060
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 17.17.17.211;branch=z9hG4bK7b5d.90b692fac0d1cc8a2ac460a67a02aec9.0
Via: SIP/2.0/UDP 17.17.17.181;rport=5060;branch=z9hG4bK7b5d.78276307977b5b2776919ce1f1e76d49.0
To: "301234567890" <sip:MyTrunk@77.1.1.1:20125>;tag=07ece97c
From: <sip:300987654321@17.17.17.211:5060>;tag=gK0e80b4b9
Call-ID: 1q5nE37RGZ8a8ChI6rqShw..
CSeq: 29227 INVITE
Content-Length: 0



2023/01/26 09:48:31.026742 77.1.1.1:2314 -> 17.17.17.211:5060
SIP/2.0 200 OK
Via: SIP/2.0/UDP 17.17.17.211;branch=z9hG4bK7b5d.90b692fac0d1cc8a2ac460a67a02aec9.0
Via: SIP/2.0/UDP 17.17.17.181;rport=5060;branch=z9hG4bK7b5d.78276307977b5b2776919ce1f1e76d49.0
Require: timer
Contact: <sip:301234567890@77.1.1.1:20125>
To: "301234567890"<sip:MyTrunk@77.1.1.1:20125>;tag=07ece97c
From: <sip:300987654321@17.17.17.211:5060>;tag=gK0e80b4b9
Call-ID: 1q5nE37RGZ8a8ChI6rqShw..
CSeq: 29227 INVITE
Session-Expires: 600;refresher=uas
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REGISTER, SUBSCRIBE, NOTIFY, REFER, INFO, MESSAGE, UPDATE
Content-Type: application/sdp
Supported: replaces, timer
User-Agent: 3CXPhoneSystem 18.0.6.905 (905)
Content-Length: 259

v=0
o=3cxPS 792019937001472 2393157908037634 IN IP4 77.1.1.1
s=3cxPS Audio call
c=IN IP4 77.1.1.1
t=0 0
m=audio 9054 RTP/AVP 8 18 101
a=rtpmap:8 PCMA/8000
a=rtpmap:18 G729/8000
a=fmtp:18 annexb=no
a=rtpmap:101 telephone-event/8000
a=sendrecv


2023/01/26 09:48:31.093656 17.17.17.211:5060 -> 17.17.17.181:5060
SIP/2.0 200 OK
Via: SIP/2.0/UDP 17.17.17.181;rport=5060;branch=z9hG4bK7b5d.78276307977b5b2776919ce1f1e76d49.0
Require: timer
Contact: <sip:301234567890@77.1.1.1:20125>
To: "301234567890" <sip:301234567890@sip.mydomain.com>;tag=07ece97c
From: <sip:300987654321@sip.mydomain.com>;tag=gK0e80b4b9
Call-ID: 1q5nE37RGZ8a8ChI6rqShw..
CSeq: 29227 INVITE
Session-Expires: 600;refresher=uas
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REGISTER, SUBSCRIBE, NOTIFY, REFER, INFO, MESSAGE, UPDATE
Content-Type: application/sdp
Supported: replaces, timer
User-Agent: 3CXPhoneSystem 18.0.6.905 (905)
Content-Length: 276

v=0
o=3cxPS 792019937001472 2393157908037634 IN IP4 14.1.1.28
s=3cxPS Audio call
c=IN IP4 14.1.1.28
t=0 0
m=audio 13278 RTP/AVP 8 18 101
a=rtpmap:8 PCMA/8000
a=rtpmap:18 G729/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:18 annexb=no
a=sendrecv
a=rtcp:13279


2023/01/26 09:48:31.254591 17.17.17.181:5060 -> 17.17.17.211:5060
ACK sip:301234567890@77.1.1.1:20125 SIP/2.0
Via: SIP/2.0/UDP 17.17.17.181;branch=z9hG4bK7b5d.48f49235d45a0f6f9efdad9d6d8224bd.0
From: <sip:300987654321@sip.mydomain.com>;tag=gK0e80b4b9
To: "301234567890" <sip:301234567890@sip.mydomain.com>;tag=07ece97c
Call-ID: 1q5nE37RGZ8a8ChI6rqShw..
CSeq: 29227 ACK
Max-Forwards: 69
Content-Length: 0
Route: <sip:17.17.17.211;lr;ftag=07ece97c;vsf=AAAAAFpUAgECBwAACnAGAW5FUF4ZXUdDUUhEX1hRUC5ldQ--;vst=AAAAAAAAAAAAAAAAAAAAAABCXkYAQkdeVEJDQVtSVBRQRTYw;did=5fc.669;nat=yes>
Contact: <sip:atpsh-b5-62dfd3a3-cd5ed-1d354@17.17.17.181>



2023/01/26 09:48:31.260901 17.17.17.211:5060 -> 77.1.1.1:20125
ACK sip:301234567890@77.1.1.1:20125 SIP/2.0
Via: SIP/2.0/UDP 17.17.17.211;branch=z9hG4bK7b5d.e8fb34e79623843d516ae77257014e2d.0
Via: SIP/2.0/UDP 17.17.17.181;rport=5060;branch=z9hG4bK7b5d.48f49235d45a0f6f9efdad9d6d8224bd.0
From: <sip:300987654321@17.17.17.211:5060>;tag=gK0e80b4b9
To: "301234567890" <sip:MyTrunk@77.1.1.1:20125>;tag=07ece97c
Call-ID: 1q5nE37RGZ8a8ChI6rqShw..
CSeq: 29227 ACK
Max-Forwards: 68
Content-Length: 0
Contact: <sip:atpsh-b5-62dfd3a3-cd5ed-1d354@17.17.17.181>

Any help will be much appreciated. 

Thank you!
Regards,
Angelo