Asterisk Sending BYE to wrong IP

Hi I am using Twilio SIP Trunking. In the calls coming from Twilio SIP trunk to Asterisk, the calls are connecting fine and media is flowing just correct. The only issue is when I hangup the call from my Asterisk Server side, Twilio doesn’t respond to the BYE with 200ok. When contacted the Twilio support, Twilio says that the BYE is not addressed to the correct IP.

This was their reply:
The Request-URI of the BYE being incorrect. Your application sent sip:+19706877770@54.172.60.0:5060;transport=udp when it should be the Contact header of the Invite we send i.e. sip:+19706877770@172.25.86.25:5060;transport=udp .

I am not connecting directly to Twilio, I have Kamailio in between. So the scenario is:

PSTN → TWILIO → KAMAILIO → ASTERISK → WEBRTC CLIENT

I have a gut feeling that if Asterisk would send all the VIA headers as it received in the previous ACK along with the BYE, that should also work, but I am not 100% sure that this fault is at Asterisk side.

Here is the PJSIP configuration:

id sbc001
transport transport-udp
aors sbc001
context in_router
disallow all
allow alaw,ulaw
direct_media no
disable_direct_media_on_nat yes
dtmf_mode rfc4733
force_rport no
ice_support yes
rewrite_contact yes
rtp_symmetric yes
send_pai yes
media_encryption dtls
dtls_cert_file /var/example.net/fullchain1.pem
dtls_private_key /var/example.net/privkey1.pem
set_var FROM_TRUNK=sbc001
media_use_received_transport yes
media_encryption_optimistic yes
asymmetric_rtp_codec yes
rtcp_mux yes
allow_overlap yes

[May  9 15:57:55] <--- Received SIP request (1703 bytes) from UDP:10.52.13.195:5061 --->
[May  9 15:57:55] INVITE sip:+18877887788@sip.example.net;edge=ashburn SIP/2.0
[May  9 15:57:55] Record-Route: <sip:10.52.13.195:5061;r2=on;lr=on;ftag=74800861_c3356d0b_24a3f9ca-4fd8-4475-9537-e868913fca13;nat=yes>
[May  9 15:57:55] Record-Route: <sip:sip.example.net;r2=on;lr=on;ftag=74800861_c3356d0b_24a3f9ca-4fd8-4475-9537-e868913fca13;nat=yes>
[May  9 15:57:55] Record-Route: <sip:54.172.60.0;lr>
[May  9 15:57:55] CSeq: 1 INVITE
[May  9 15:57:55] From: <sip:+19706877770@aaa.bbb.twilio.com>;tag=74800861_c3356d0b_24a3f9ca-4fd8-4475-9537-e868913fca13
[May  9 15:57:55] To: <sip:+18877887788@sip.example.net;edge=ashburn>
[May  9 15:57:55] Max-Forwards: 62
[May  9 15:57:55] P-Asserted-Identity: <sip:+19706877770@sip.twilio.com>
[May  9 15:57:55] Diversion: <sip:+18877887788@twilio.com>;reason=unconditional
[May  9 15:57:55] Call-ID: 99d603d45942dc11df32f65603bb25ec@0.0.0.0
[May  9 15:57:55] Via: SIP/2.0/UDP 10.52.13.195:5061;branch=z9hG4bK0846.00fb039875ef6fa08db326dd2593b0ea.0
[May  9 15:57:55] Via: SIP/2.0/UDP 54.172.60.0:5060;rport=5060;branch=z9hG4bK0846.baaf112c4bc7e3b927759ea84359ee37.0
[May  9 15:57:55] Via: SIP/2.0/UDP 172.25.86.25:5060;rport=5060;branch=z9hG4bK24a3f9ca-4fd8-4475-9537-e868913fca13_c3356d0b_740-8053243890324297442
[May  9 15:57:55] Contact: <sip:+19706877770@54.172.60.0:5060;transport=udp>
[May  9 15:57:55] Allow: INVITE,ACK,CANCEL,OPTIONS,BYE,REFER,NOTIFY
[May  9 15:57:55] X-Twilio-VerStat: TN-Validation-Passed-C
[May  9 15:57:55] X-Twilio-AccountSid: ACb116d638171c2365b1623f3d25af789d
[May  9 15:57:55] User-Agent: Twilio Gateway
[May  9 15:57:55] Content-Type: application/sdp
[May  9 15:57:55] X-Twilio-CallSid: CAc0f687bb0d8726113254e67a83d15273
[May  9 15:57:55] Content-Length: 289
[May  9 15:57:55] X-Speridian-SBC: 001
[May  9 15:57:55]
[May  9 15:57:55] v=0
[May  9 15:57:55] o=root 2026399782 2026399782 IN IP4 10.52.13.195
[May  9 15:57:55] s=Twilio Media Gateway
[May  9 15:57:55] c=IN IP4 10.52.13.195
[May  9 15:57:55] t=0 0
[May  9 15:57:55] m=audio 10096 RTP/AVP 0 8 101
[May  9 15:57:55] a=maxptime:20
[May  9 15:57:55] a=rtpmap:0 PCMU/8000
[May  9 15:57:55] a=rtpmap:8 PCMA/8000
[May  9 15:57:55] a=rtpmap:101 telephone-event/8000
[May  9 15:57:55] a=fmtp:101 0-16
[May  9 15:57:55] a=sendrecv
[May  9 15:57:55] a=rtcp:10097
[May  9 15:57:55] a=ptime:20
[May  9 15:57:55]
[May  9 15:57:55] <--- Transmitting SIP response (925 bytes) to UDP:10.52.13.195:5061 --->
[May  9 15:57:55] SIP/2.0 100 Trying
[May  9 15:57:55] Via: SIP/2.0/UDP 10.52.13.195:5061;received=10.52.13.195;branch=z9hG4bK0846.00fb039875ef6fa08db326dd2593b0ea.0
[May  9 15:57:55] Via: SIP/2.0/UDP 54.172.60.0:5060;rport=5060;branch=z9hG4bK0846.baaf112c4bc7e3b927759ea84359ee37.0
[May  9 15:57:55] Via: SIP/2.0/UDP 172.25.86.25:5060;rport=5060;branch=z9hG4bK24a3f9ca-4fd8-4475-9537-e868913fca13_c3356d0b_740-8053243890324297442
[May  9 15:57:55] Record-Route: <sip:10.52.13.195:5061;lr;r2=on;ftag=74800861_c3356d0b_24a3f9ca-4fd8-4475-9537-e868913fca13;nat=yes>
[May  9 15:57:55] Record-Route: <sip:sip.example.net;lr;r2=on;ftag=74800861_c3356d0b_24a3f9ca-4fd8-4475-9537-e868913fca13;nat=yes>
[May  9 15:57:55] Record-Route: <sip:54.172.60.0;lr>
[May  9 15:57:55] Call-ID: 99d603d45942dc11df32f65603bb25ec@0.0.0.0
[May  9 15:57:55] From: <sip:+19706877770@aaa.bbb.twilio.com>;tag=74800861_c3356d0b_24a3f9ca-4fd8-4475-9537-e868913fca13
[May  9 15:57:55] To: <sip:+18877887788@sip.example.net;edge=ashburn>
[May  9 15:57:55] CSeq: 1 INVITE
[May  9 15:57:55] Server: Asterisk PBX 20.6.0
[May  9 15:57:55] Content-Length:  0
[May  9 15:57:55]
[May  9 15:57:55]
[May  9 15:57:55]     -- Executing [+18877887788@in_router:1] Verbose("PJSIP/sbc001-0000018e", "1, Call on Twilio DID") in new stack
[May  9 15:57:55]   Call on Twilio DID
[May  9 15:57:55]     -- Executing [+18877887788@in_router:2] Dial("PJSIP/sbc001-0000018e", "PJSIP/11001@sbc001") in new stack
[May  9 15:57:55]     -- Called PJSIP/11001@sbc001
[May  9 15:57:55] <--- Transmitting SIP request (1376 bytes) to UDP:10.52.13.195:5061 --->
[May  9 15:57:55] INVITE sip:11001@10.52.13.195:5061 SIP/2.0
[May  9 15:57:55] Via: SIP/2.0/UDP 10.52.13.26:5060;rport;branch=z9hG4bKPjf87fc61b-c27e-4dae-acdd-d28ae5358d92
[May  9 15:57:55] From: <sip:+19706877770@10.52.13.26>;tag=c29bc837-3dce-4c98-ad11-ee166f976d09
[May  9 15:57:55] To: <sip:11001@10.52.13.195>
[May  9 15:57:55] Contact: <sip:asterisk@10.52.13.26:5060>
[May  9 15:57:55] Call-ID: ccbc50bb-a8e9-4818-8adb-12611e701c59
[May  9 15:57:55] CSeq: 3334 INVITE
[May  9 15:57:55] Allow: OPTIONS, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, MESSAGE, INFO, REFER
[May  9 15:57:55] Supported: 100rel, timer, replaces, norefersub, histinfo
[May  9 15:57:55] Session-Expires: 1800
[May  9 15:57:55] Min-SE: 90
[May  9 15:57:55] P-Asserted-Identity: <sip:+19706877770@10.52.13.26>
[May  9 15:57:55] Diversion: <sip:+18877887788@10.52.13.26>;reason=unconditional
[May  9 15:57:55] Max-Forwards: 70
[May  9 15:57:55] User-Agent: Asterisk PBX 20.6.0
[May  9 15:57:55] Content-Type: application/sdp
[May  9 15:57:55] Content-Length:   587
[May  9 15:57:55]
[May  9 15:57:55] v=0
[May  9 15:57:55] o=- 321763993 321763993 IN IP4 10.52.13.26
[May  9 15:57:55] s=Asterisk
[May  9 15:57:55] c=IN IP4 10.52.13.26
[May  9 15:57:55] t=0 0
[May  9 15:57:55] m=audio 10168 UDP/TLS/RTP/SAVP 8 0 101
[May  9 15:57:55] a=connection:new
[May  9 15:57:55] a=setup:active
[May  9 15:57:55] a=fingerprint:SHA-256 38:E7:7D:82:A7:3D:46:21:FE:F9:06:2D:B1:52:81:6B:1F:55:56:F5:C1:44:A4:CE:04:67:D5:B6:58:32:AA:97
[May  9 15:57:55] a=ice-ufrag:6c7a26cd131f6be924732a8a79fc355e
[May  9 15:57:55] a=ice-pwd:77899f650ecd12086653733d18fcb08a
[May  9 15:57:55] a=candidate:Ha340d1a 1 UDP 2130706431 10.52.13.26 10168 typ host
[May  9 15:57:55] a=rtpmap:8 PCMA/8000
[May  9 15:57:55] a=rtpmap:0 PCMU/8000
[May  9 15:57:55] a=rtpmap:101 telephone-event/8000
[May  9 15:57:55] a=fmtp:101 0-16
[May  9 15:57:55] a=ptime:20
[May  9 15:57:55] a=maxptime:140
[May  9 15:57:55] a=sendrecv
[May  9 15:57:55] a=rtcp-mux
[May  9 15:57:55]
[May  9 15:57:55] <--- Received SIP response (409 bytes) from UDP:10.52.13.195:5061 --->
[May  9 15:57:55] SIP/2.0 100 trying -- your call is important to us
[May  9 15:57:55] Via: SIP/2.0/UDP 10.52.13.26:5060;rport=5060;branch=z9hG4bKPjf87fc61b-c27e-4dae-acdd-d28ae5358d92;received=10.52.13.26
[May  9 15:57:55] From: <sip:+19706877770@10.52.13.26>;tag=c29bc837-3dce-4c98-ad11-ee166f976d09
[May  9 15:57:55] To: <sip:11001@10.52.13.195>
[May  9 15:57:55] Call-ID: ccbc50bb-a8e9-4818-8adb-12611e701c59
[May  9 15:57:55] CSeq: 3334 INVITE
[May  9 15:57:55] Server: kamailio (5.4.4 (x86_64/linux))
[May  9 15:57:55] Content-Length: 0
[May  9 15:57:55]
[May  9 15:57:55]
[May  9 15:57:55] <--- Received SIP response (686 bytes) from UDP:10.52.13.195:5061 --->
[May  9 15:57:55] SIP/2.0 180 Ringing
[May  9 15:57:55] Via: SIP/2.0/UDP 10.52.13.26:5060;received=10.52.13.26;rport=5060;branch=z9hG4bKPjf87fc61b-c27e-4dae-acdd-d28ae5358d92
[May  9 15:57:55] From: <sip:+19706877770@10.52.13.26>;tag=c29bc837-3dce-4c98-ad11-ee166f976d09
[May  9 15:57:55] To: <sip:11001@10.52.13.195>;tag=d8b9qgku6c
[May  9 15:57:55] CSeq: 3334 INVITE
[May  9 15:57:55] Call-ID: ccbc50bb-a8e9-4818-8adb-12611e701c59
[May  9 15:57:55] Supported: outbound
[May  9 15:57:55] User-Agent: SIP.js/0.21.2
[May  9 15:57:55] Record-Route: <sip:sip.example.net:8443;transport=ws;r2=on;lr=on;ftag=c29bc837-3dce-4c98-ad11-ee166f976d09;nat=yes>
[May  9 15:57:55] Record-Route: <sip:10.52.13.195:5061;r2=on;lr=on;ftag=c29bc837-3dce-4c98-ad11-ee166f976d09;nat=yes>
[May  9 15:57:55] Contact: <sip:iecf6bie@54.157.134.187:62944;transport=ws>
[May  9 15:57:55] Content-Length: 0
[May  9 15:57:55]
[May  9 15:57:55]
[May  9 15:57:55]     -- PJSIP/sbc001-0000018f is ringing
[May  9 15:57:55] <--- Transmitting SIP response (1196 bytes) to UDP:10.52.13.195:5061 --->
[May  9 15:57:55] SIP/2.0 180 Ringing
[May  9 15:57:55] Via: SIP/2.0/UDP 10.52.13.195:5061;received=10.52.13.195;branch=z9hG4bK0846.00fb039875ef6fa08db326dd2593b0ea.0
[May  9 15:57:55] Via: SIP/2.0/UDP 54.172.60.0:5060;rport=5060;branch=z9hG4bK0846.baaf112c4bc7e3b927759ea84359ee37.0
[May  9 15:57:55] Via: SIP/2.0/UDP 172.25.86.25:5060;rport=5060;branch=z9hG4bK24a3f9ca-4fd8-4475-9537-e868913fca13_c3356d0b_740-8053243890324297442
[May  9 15:57:55] Record-Route: <sip:10.52.13.195:5061;lr;r2=on;ftag=74800861_c3356d0b_24a3f9ca-4fd8-4475-9537-e868913fca13;nat=yes>
[May  9 15:57:55] Record-Route: <sip:sip.example.net;lr;r2=on;ftag=74800861_c3356d0b_24a3f9ca-4fd8-4475-9537-e868913fca13;nat=yes>
[May  9 15:57:55] Record-Route: <sip:54.172.60.0;lr>
[May  9 15:57:55] Call-ID: 99d603d45942dc11df32f65603bb25ec@0.0.0.0
[May  9 15:57:55] From: <sip:+19706877770@aaa.bbb.twilio.com>;tag=74800861_c3356d0b_24a3f9ca-4fd8-4475-9537-e868913fca13
[May  9 15:57:55] To: <sip:+18877887788@sip.example.net;edge=ashburn>;tag=06ff048d-a5da-45dc-b44d-c7e051553c79
[May  9 15:57:55] CSeq: 1 INVITE
[May  9 15:57:55] Server: Asterisk PBX 20.6.0
[May  9 15:57:55] Contact: <sip:10.52.13.26:5060>
[May  9 15:57:55] Allow: OPTIONS, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, MESSAGE, INFO, REFER
[May  9 15:57:55] P-Asserted-Identity: <sip:+18877887788@sip.example.net;edge=ashburn>
[May  9 15:57:55] Content-Length:  0
[May  9 15:57:55]
[May  9 15:57:55]
[May  9 15:57:55] <--- Received SIP response (1408 bytes) from UDP:10.52.13.195:5061 --->
[May  9 15:57:55] SIP/2.0 200 OK
[May  9 15:57:55] Via: SIP/2.0/UDP 10.52.13.26:5060;received=10.52.13.26;rport=5060;branch=z9hG4bKPjf87fc61b-c27e-4dae-acdd-d28ae5358d92
[May  9 15:57:55] From: <sip:+19706877770@10.52.13.26>;tag=c29bc837-3dce-4c98-ad11-ee166f976d09
[May  9 15:57:55] To: <sip:11001@10.52.13.195>;tag=d8b9qgku6c
[May  9 15:57:55] CSeq: 3334 INVITE
[May  9 15:57:55] Call-ID: ccbc50bb-a8e9-4818-8adb-12611e701c59
[May  9 15:57:55] Supported: outbound
[May  9 15:57:55] User-Agent: SIP.js/0.21.2
[May  9 15:57:55] Record-Route: <sip:sip.example.net:8443;transport=ws;r2=on;lr=on;ftag=c29bc837-3dce-4c98-ad11-ee166f976d09;nat=yes>
[May  9 15:57:55] Record-Route: <sip:10.52.13.195:5061;r2=on;lr=on;ftag=c29bc837-3dce-4c98-ad11-ee166f976d09;nat=yes>
[May  9 15:57:55] Allow: ACK,BYE,CANCEL,INFO,INVITE,MESSAGE,NOTIFY,OPTIONS,PRACK,REFER,REGISTER,SUBSCRIBE
[May  9 15:57:55] Contact: <sip:iecf6bie@54.157.134.187:62944;transport=ws>
[May  9 15:57:55] Content-Type: application/sdp
[May  9 15:57:55] Content-Length: 605
[May  9 15:57:55]
[May  9 15:57:55] v=0
[May  9 15:57:55] o=- 4426967108324417925 2 IN IP4 10.52.13.195
[May  9 15:57:55] s=-
[May  9 15:57:55] t=0 0
[May  9 15:57:55] m=audio 10020 RTP/SAVPF 8 0 101
[May  9 15:57:55] c=IN IP4 10.52.13.195
[May  9 15:57:55] a=rtpmap:8 PCMA/8000
[May  9 15:57:55] a=rtpmap:0 PCMU/8000
[May  9 15:57:55] a=rtpmap:101 telephone-event/8000
[May  9 15:57:55] a=ssrc:4000389632 cname:LR3p6SXJaBxrypYs
[May  9 15:57:55] a=sendrecv
[May  9 15:57:55] a=rtcp:10020
[May  9 15:57:55] a=rtcp-mux
[May  9 15:57:55] a=setup:passive
[May  9 15:57:55] a=fingerprint:sha-256 6E:30:74:B5:5E:6D:15:42:E2:F9:89:AC:D5:BC:92:17:17:00:BB:2D:DC:BE:D0:23:DB:D7:51:46:E1:A5:BB:8F
[May  9 15:57:55] a=tls-id:9a3d04b591a1d418e41c9d7feff91a8d
[May  9 15:57:55] a=ptime:20
[May  9 15:57:55] a=ice-ufrag:PkxUfI2t
[May  9 15:57:55] a=ice-pwd:2xN3PlHpFSEswSTYxP0842PYtP
[May  9 15:57:55] a=candidate:O08pxpEEKWjZUKwM 1 UDP 2130706431 10.52.13.195 10020 typ host
[May  9 15:57:55]
[May  9 15:57:55] <--- Transmitting SIP request (621 bytes) to UDP:10.52.13.195:5061 --->
[May  9 15:57:55] ACK sip:iecf6bie@54.157.134.187:62944;transport=ws SIP/2.0
[May  9 15:57:55] Via: SIP/2.0/UDP 10.52.13.26:5060;rport;branch=z9hG4bKPj7426e8c3-8397-4340-9bb7-f34d58f68b45
[May  9 15:57:55] From: <sip:+19706877770@10.52.13.26>;tag=c29bc837-3dce-4c98-ad11-ee166f976d09
[May  9 15:57:55] To: <sip:11001@10.52.13.195>;tag=d8b9qgku6c
[May  9 15:57:55] Call-ID: ccbc50bb-a8e9-4818-8adb-12611e701c59
[May  9 15:57:55] CSeq: 3334 ACK
[May  9 15:57:55] Route: <sip:10.52.13.195:5061;lr;r2=on;ftag=c29bc837-3dce-4c98-ad11-ee166f976d09;nat=yes>
[May  9 15:57:55] Route: <sip:sip.example.net:8443;transport=ws;lr;r2=on;ftag=c29bc837-3dce-4c98-ad11-ee166f976d09;nat=yes>
[May  9 15:57:55] Max-Forwards: 70
[May  9 15:57:55] User-Agent: Asterisk PBX 20.6.0
[May  9 15:57:55] Content-Length:  0
[May  9 15:57:55]
[May  9 15:57:55]
[May  9 15:57:55]     -- PJSIP/sbc001-0000018f answered PJSIP/sbc001-0000018e
[May  9 15:57:55] <--- Transmitting SIP response (1685 bytes) to UDP:10.52.13.195:5061 --->
[May  9 15:57:55] SIP/2.0 200 OK
[May  9 15:57:55] Via: SIP/2.0/UDP 10.52.13.195:5061;received=10.52.13.195;branch=z9hG4bK0846.00fb039875ef6fa08db326dd2593b0ea.0
[May  9 15:57:55] Via: SIP/2.0/UDP 54.172.60.0:5060;rport=5060;branch=z9hG4bK0846.baaf112c4bc7e3b927759ea84359ee37.0
[May  9 15:57:55] Via: SIP/2.0/UDP 172.25.86.25:5060;rport=5060;branch=z9hG4bK24a3f9ca-4fd8-4475-9537-e868913fca13_c3356d0b_740-8053243890324297442
[May  9 15:57:55] Record-Route: <sip:10.52.13.195:5061;lr;r2=on;ftag=74800861_c3356d0b_24a3f9ca-4fd8-4475-9537-e868913fca13;nat=yes>
[May  9 15:57:55] Record-Route: <sip:sip.example.net;lr;r2=on;ftag=74800861_c3356d0b_24a3f9ca-4fd8-4475-9537-e868913fca13;nat=yes>
[May  9 15:57:55] Record-Route: <sip:54.172.60.0;lr>
[May  9 15:57:55] Call-ID: 99d603d45942dc11df32f65603bb25ec@0.0.0.0
[May  9 15:57:55] From: <sip:+19706877770@aaa.bbb.twilio.com>;tag=74800861_c3356d0b_24a3f9ca-4fd8-4475-9537-e868913fca13
[May  9 15:57:55] To: <sip:+18877887788@sip.example.net;edge=ashburn>;tag=06ff048d-a5da-45dc-b44d-c7e051553c79
[May  9 15:57:55] CSeq: 1 INVITE
[May  9 15:57:55] Server: Asterisk PBX 20.6.0
[May  9 15:57:55] Allow: OPTIONS, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, MESSAGE, INFO, REFER
[May  9 15:57:55] Contact: <sip:10.52.13.26:5060>
[May  9 15:57:55] Supported: 100rel, timer, replaces, norefersub
[May  9 15:57:55] P-Asserted-Identity: <sip:+18877887788@sip.example.net;edge=ashburn>
[May  9 15:57:55] Content-Type: application/sdp
[May  9 15:57:55] Content-Length:   412
[May  9 15:57:55]
[May  9 15:57:55] v=0
[May  9 15:57:55] o=- 2026399782 2026399784 IN IP4 10.52.13.26
[May  9 15:57:55] s=Asterisk
[May  9 15:57:55] c=IN IP4 10.52.13.26
[May  9 15:57:55] t=0 0
[May  9 15:57:55] m=audio 10182 RTP/AVP 8 0 101
[May  9 15:57:55] a=connection:new
[May  9 15:57:55] a=setup:active
[May  9 15:57:55] a=fingerprint:SHA-256 38:E7:7D:82:A7:3D:46:21:FE:F9:06:2D:B1:52:81:6B:1F:55:56:F5:C1:44:A4:CE:04:67:D5:B6:58:32:AA:97
[May  9 15:57:55] a=rtpmap:8 PCMA/8000
[May  9 15:57:55] a=rtpmap:0 PCMU/8000
[May  9 15:57:55] a=rtpmap:101 telephone-event/8000
[May  9 15:57:55] a=fmtp:101 0-16
[May  9 15:57:55] a=ptime:20
[May  9 15:57:55] a=maxptime:140
[May  9 15:57:55] a=sendrecv
[May  9 15:57:55]
[May  9 15:57:55]     -- Channel PJSIP/sbc001-0000018f joined 'simple_bridge' basic-bridge <3290c8b5-f0aa-47e0-87ea-82c65df5ed79>
[May  9 15:57:55]     -- Channel PJSIP/sbc001-0000018e joined 'simple_bridge' basic-bridge <3290c8b5-f0aa-47e0-87ea-82c65df5ed79>
[May  9 15:57:55] <--- Received SIP request (765 bytes) from UDP:10.52.13.195:5061 --->
[May  9 15:57:55] ACK sip:10.52.13.26:5060 SIP/2.0
[May  9 15:57:55] Call-ID: 99d603d45942dc11df32f65603bb25ec@0.0.0.0
[May  9 15:57:55] CSeq: 1 ACK
[May  9 15:57:55] From: <sip:+19706877770@aaa.bbb.twilio.com>;tag=74800861_c3356d0b_24a3f9ca-4fd8-4475-9537-e868913fca13
[May  9 15:57:55] To: <sip:+18877887788@sip.example.net;edge=ashburn>;tag=06ff048d-a5da-45dc-b44d-c7e051553c79
[May  9 15:57:55] Max-Forwards: 68
[May  9 15:57:55] User-Agent: Twilio
[May  9 15:57:55] X-Twilio-CallSid: CAc0f687bb0d8726113254e67a83d15273
[May  9 15:57:55] Via: SIP/2.0/UDP 10.52.13.195:5061;branch=z9hG4bK0846.fa08892c07306cd775f1bca2ab3992af.0
[May  9 15:57:55] Via: SIP/2.0/UDP 54.172.60.0:5060;rport=5060;branch=z9hG4bK0846.fabaefbef3e4516f13195cee527f378b.0
[May  9 15:57:55] Via: SIP/2.0/UDP 172.25.86.25:5060;rport=5060;received=18.234.207.44;branch=z9hG4bK24a3f9ca-4fd8-4475-9537-e868913fca13_c3356d0b_741-2064803552850238296
[May  9 15:57:55] Content-Length: 0
[May  9 15:57:55]
[May  9 15:57:55]

[May  9 15:58:03] <--- Received SIP request (501 bytes) from UDP:10.52.13.195:5061 --->
[May  9 15:58:03] BYE sip:asterisk@10.52.13.26:5060 SIP/2.0
[May  9 15:58:03] Via: SIP/2.0/UDP 10.52.13.195:5061;branch=z9hG4bKc6ba.717d7e42bd8e76c5b2d9eccec27df507.0
[May  9 15:58:03] Via: SIP/2.0/WSS 63tf7e6mh3j7.invalid;rport=62944;received=54.157.134.187;branch=z9hG4bK7920213
[May  9 15:58:03] To: <sip:+19706877770@10.52.13.26>;tag=c29bc837-3dce-4c98-ad11-ee166f976d09
[May  9 15:58:03] From: <sip:11001@10.52.13.195>;tag=d8b9qgku6c
[May  9 15:58:03] CSeq: 1 BYE
[May  9 15:58:03] Call-ID: ccbc50bb-a8e9-4818-8adb-12611e701c59
[May  9 15:58:03] Max-Forwards: 69
[May  9 15:58:03] Supported: outbound
[May  9 15:58:03] User-Agent: SIP.js/0.21.2
[May  9 15:58:03] Content-Length: 0
[May  9 15:58:03]
[May  9 15:58:03]
[May  9 15:58:03] <--- Transmitting SIP response (460 bytes) to UDP:10.52.13.195:5061 --->
[May  9 15:58:03] SIP/2.0 200 OK
[May  9 15:58:03] Via: SIP/2.0/UDP 10.52.13.195:5061;received=10.52.13.195;branch=z9hG4bKc6ba.717d7e42bd8e76c5b2d9eccec27df507.0
[May  9 15:58:03] Via: SIP/2.0/WSS 63tf7e6mh3j7.invalid;rport=62944;received=54.157.134.187;branch=z9hG4bK7920213
[May  9 15:58:03] Call-ID: ccbc50bb-a8e9-4818-8adb-12611e701c59
[May  9 15:58:03] From: <sip:11001@10.52.13.195>;tag=d8b9qgku6c
[May  9 15:58:03] To: <sip:+19706877770@10.52.13.26>;tag=c29bc837-3dce-4c98-ad11-ee166f976d09
[May  9 15:58:03] CSeq: 1 BYE
[May  9 15:58:03] Server: Asterisk PBX 20.6.0
[May  9 15:58:03] Content-Length:  0
[May  9 15:58:03]
[May  9 15:58:03]
[May  9 15:58:03]     -- Channel PJSIP/sbc001-0000018f left 'simple_bridge' basic-bridge <3290c8b5-f0aa-47e0-87ea-82c65df5ed79>
[May  9 15:58:03]     -- Channel PJSIP/sbc001-0000018e left 'simple_bridge' basic-bridge <3290c8b5-f0aa-47e0-87ea-82c65df5ed79>
[May  9 15:58:03]   == Spawn extension (in_router, +18877887788, 2) exited non-zero on 'PJSIP/sbc001-0000018e'
[May  9 15:58:03] <--- Transmitting SIP request (784 bytes) to UDP:10.52.13.195:5061 --->
[May  9 15:58:03] BYE sip:+19706877770@54.172.60.0:5060;transport=udp SIP/2.0
[May  9 15:58:03] Via: SIP/2.0/UDP 10.52.13.26:5060;rport;branch=z9hG4bKPj33fab81e-90bd-4fc9-950d-64a671d09268
[May  9 15:58:03] From: <sip:+18877887788@sip.example.net;edge=ashburn>;tag=06ff048d-a5da-45dc-b44d-c7e051553c79
[May  9 15:58:03] To: <sip:+19706877770@aaa.bbb.twilio.com>;tag=74800861_c3356d0b_24a3f9ca-4fd8-4475-9537-e868913fca13
[May  9 15:58:03] Call-ID: 99d603d45942dc11df32f65603bb25ec@0.0.0.0
[May  9 15:58:03] CSeq: 20845 BYE
[May  9 15:58:03] Route: <sip:10.52.13.195:5061;lr;r2=on;ftag=74800861_c3356d0b_24a3f9ca-4fd8-4475-9537-e868913fca13;nat=yes>
[May  9 15:58:03] Route: <sip:sip.example.net;lr;r2=on;ftag=74800861_c3356d0b_24a3f9ca-4fd8-4475-9537-e868913fca13;nat=yes>
[May  9 15:58:03] Route: <sip:54.172.60.0;lr>
[May  9 15:58:03] Reason: Q.850;cause=16
[May  9 15:58:03] Max-Forwards: 70
[May  9 15:58:03] User-Agent: Asterisk PBX 20.6.0
[May  9 15:58:03] Content-Length:  0
[May  9 15:58:03]
[May  9 15:58:03]
[May  9 15:58:03] <--- Transmitting SIP request (784 bytes) to UDP:10.52.13.195:5061 --->
[May  9 15:58:03] BYE sip:+19706877770@54.172.60.0:5060;transport=udp SIP/2.0
[May  9 15:58:03] Via: SIP/2.0/UDP 10.52.13.26:5060;rport;branch=z9hG4bKPj33fab81e-90bd-4fc9-950d-64a671d09268
[May  9 15:58:03] From: <sip:+18877887788@sip.example.net;edge=ashburn>;tag=06ff048d-a5da-45dc-b44d-c7e051553c79
[May  9 15:58:03] To: <sip:+19706877770@aaa.bbb.twilio.com>;tag=74800861_c3356d0b_24a3f9ca-4fd8-4475-9537-e868913fca13
[May  9 15:58:03] Call-ID: 99d603d45942dc11df32f65603bb25ec@0.0.0.0
[May  9 15:58:03] CSeq: 20845 BYE
[May  9 15:58:03] Route: <sip:10.52.13.195:5061;lr;r2=on;ftag=74800861_c3356d0b_24a3f9ca-4fd8-4475-9537-e868913fca13;nat=yes>
[May  9 15:58:03] Route: <sip:sip.example.net;lr;r2=on;ftag=74800861_c3356d0b_24a3f9ca-4fd8-4475-9537-e868913fca13;nat=yes>
[May  9 15:58:03] Route: <sip:54.172.60.0;lr>
[May  9 15:58:03] Reason: Q.850;cause=16
[May  9 15:58:03] Max-Forwards: 70
[May  9 15:58:03] User-Agent: Asterisk PBX 20.6.0
[May  9 15:58:03] Content-Length:  0
[May  9 15:58:03]
[May  9 15:58:03]
[May  9 15:58:04] <--- Transmitting SIP request (784 bytes) to UDP:10.52.13.195:5061 --->
[May  9 15:58:04] BYE sip:+19706877770@54.172.60.0:5060;transport=udp SIP/2.0
[May  9 15:58:04] Via: SIP/2.0/UDP 10.52.13.26:5060;rport;branch=z9hG4bKPj33fab81e-90bd-4fc9-950d-64a671d09268
[May  9 15:58:04] From: <sip:+18877887788@sip.example.net;edge=ashburn>;tag=06ff048d-a5da-45dc-b44d-c7e051553c79
[May  9 15:58:04] To: <sip:+19706877770@aaa.bbb.twilio.com>;tag=74800861_c3356d0b_24a3f9ca-4fd8-4475-9537-e868913fca13
[May  9 15:58:04] Call-ID: 99d603d45942dc11df32f65603bb25ec@0.0.0.0
[May  9 15:58:04] CSeq: 20845 BYE
[May  9 15:58:04] Route: <sip:10.52.13.195:5061;lr;r2=on;ftag=74800861_c3356d0b_24a3f9ca-4fd8-4475-9537-e868913fca13;nat=yes>
[May  9 15:58:04] Route: <sip:sip.example.net;lr;r2=on;ftag=74800861_c3356d0b_24a3f9ca-4fd8-4475-9537-e868913fca13;nat=yes>
[May  9 15:58:04] Route: <sip:54.172.60.0;lr>
[May  9 15:58:04] Reason: Q.850;cause=16
[May  9 15:58:04] Max-Forwards: 70
[May  9 15:58:04] User-Agent: Asterisk PBX 20.6.0
[May  9 15:58:04] Content-Length:  0
[May  9 15:58:04]
[May  9 15:58:04]


[May  9 15:58:06]
[May  9 15:58:06] <--- Transmitting SIP request (784 bytes) to UDP:10.52.13.195:5061 --->
[May  9 15:58:06] BYE sip:+19706877770@54.172.60.0:5060;transport=udp SIP/2.0
[May  9 15:58:06] Via: SIP/2.0/UDP 10.52.13.26:5060;rport;branch=z9hG4bKPj33fab81e-90bd-4fc9-950d-64a671d09268
[May  9 15:58:06] From: <sip:+18877887788@sip.example.net;edge=ashburn>;tag=06ff048d-a5da-45dc-b44d-c7e051553c79
[May  9 15:58:06] To: <sip:+19706877770@aaa.bbb.twilio.com>;tag=74800861_c3356d0b_24a3f9ca-4fd8-4475-9537-e868913fca13
[May  9 15:58:06] Call-ID: 99d603d45942dc11df32f65603bb25ec@0.0.0.0
[May  9 15:58:06] CSeq: 20845 BYE
[May  9 15:58:06] Route: <sip:10.52.13.195:5061;lr;r2=on;ftag=74800861_c3356d0b_24a3f9ca-4fd8-4475-9537-e868913fca13;nat=yes>
[May  9 15:58:06] Route: <sip:sip.example.net;lr;r2=on;ftag=74800861_c3356d0b_24a3f9ca-4fd8-4475-9537-e868913fca13;nat=yes>
[May  9 15:58:06] Route: <sip:54.172.60.0;lr>
[May  9 15:58:06] Reason: Q.850;cause=16
[May  9 15:58:06] Max-Forwards: 70
[May  9 15:58:06] User-Agent: Asterisk PBX 20.6.0
[May  9 15:58:06] Content-Length:  0
[May  9 15:58:06]
[May  9 15:58:06]

You can’t configure Asterisk to treat the endpoint as if it is behind NAT if it’s Kamailio and you’re using it as a SIP proxy. Set rewrite_contact to no. You’ve also configured the endpoint for loads of stuff that is not applicable for Twilio or other things. You don’t need ice_support, or rtp_symmetric, or media_encryption, or rtcp_mux, or allow_overlap, or media_use_received_transport.

Why were those set? Start with a simple configuration first.

Additionally, the Contact header from Kamailio for the SIP INVITE from Twilio through it states +19706877770@54.172.60.0:5060 which is what the request URI would be in the BYE. If that doesn’t match what Kamailio received, then that points to your Kamailio configuration.

And to answer my own question, the diagram for the flow appears to be incorrect as you seem to be using Kamailio also for the WebRTC client which is why you have those other things set.

@jcolp yes webrtc is routed via the same kamailio the corrected diagram would be, and I have identified Kamailio is actually editing the contact.
So this I suspect is an issue with a wrongly called fix_natted_contact() function in Kamailio configuration which I need to figure out how to avoid being called in this scenario.

PSTN → TWILIO → KAMAILIO → ASTERISK → KAMAILIO → WEBRTC CLIENT

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.