"Incredible" issue with INVITE originating from Twilio

Hello Asterisk Community, begging for your help with this strange Twilio + PJSIP issue with which spent 2 days debugging this and have no clue what happens. Was working fine before with Asterisk 16, I am now on Asterisk 22 with IncrediblePBX

===================

incrediblepbx*CLI> core show version
Asterisk 22.2.0 built by root @ incredible-pbx-2025 on a x86_64 running Linux on 2025-03-20 02:49:57 UTC

====================

The issue: INVITES from calls routed through Twilio SIP trunks seem completely invisible to pjsip.

INVITE “invisible” to PJSIP means that with full debug logging (pjsip set logger on / logger verbose on / logger method on) can see e.g. the SIP OPTIONS being exchanged (always initiated locally) but not the INVITE passed from Twilio when routing external calls through Twilio trunk. But these INVITEs appear just fine in the tcpdump trace (and no firewall set).

These are the 2 scenarios,

External call (me) => Twilio trunk (+1438vvvzzzz) => Asterisk (DID 1438vvvzzzz) : INVITE ignored
Twilio originate test call => Twilio trunk (+1438vvvzzzz) => Asterisk (DID 1438vvvzzzz) : works OK

All trunks (DIDWW, Voip.ms and Twilio) configured similarly with “inbound match” on IP (and based on tcpdump trace the match should happen)

Inbound calls from Voip.ms and DIDWW work fine and they are visible to pjsip debug trage (pjsip set logger on / set logger verbose on)

For twilio only the outbound calls work and sip options originated from Incredible PBX

On the tcpdump trace clearly there is no SIP answer to the INVITEs UDP packets - INVITEs come in every few seconds and nothing happens

My Incredible PBX 2025 works fine outbound /inbound with DIDWW and Voip.ms. Twilio inbound calls work as well fine if initiated from the trunk “Originate test call”.

Only inbound calls routed through the twilio trunk (to msame DIDs on my Incredible PBX) are “invisible” to pjsip

In the pjsip “advanced” for the trunk I am matching on either IP or username (which is defined in the trunk pjsip settings / general as the +1438vvvzzzz visible in the attached traces)

The only 2 INVITE differences I see are the “From:” header and the P-Asserted-Identity header (missing in the working test call)

In the working test call

From: sip:hello@mytrunk-1.pstn.twilio.com;tag=48407581 … etc

In the ignored INVITE

From: sip:+1514xxxyyyy@mytrunk-1.pstn.twilio.com:5060;isup-oli=00;pstn-params=9084818088;tag=76030578_c3356d0b … etc

Thank you in advance for any idea on how to debug and fix this odd behavior

P.S.

  • the FQDNs, IPs, DIDs are anonymized for security
  • the IP filters in trunk / pjsip / advanced were double checked against the source IPs
    (true the test call is coming from a different range but both ranges are covered by the “match IP”)
  • with same logging options the test call INVITE appears just fine in the log

================

Because “new users cannot upload attachments” (sic!) I will inli9ne the traces beloe

=========== external call “invisible” to PJSIP =======

Session Initiation Protocol (INVITE)
Request-Line: INVITE sip:+1438vvvzzzz@sip.mypbx.net SIP/2.0
Method: INVITE
Request-URI: sip:+1438vvvzzzz@sip.mypbx.net
Request-URI User Part: +1438vvvzzz
E.164 number (MSISDN): 1438vvvzzzz
Country Code: Americas (1)
Request-URI Host Part: sip.mypbx.net
[Resent Packet: False]
Message Header
Record-Route: sip:54.244.51.2;lr
Record-Route URI: sip:54.244.51.2;lr
Record-Route Host Part: 54.244.51.2
Record-Route URI parameter: lr
From: sip:+1514xxxyyyy@mytrunk-1.pstn.twilio.com:5060;isup-oli=00;pstn-params=9084818088;tag=76030578_c3356d0b_c0d924a7-b138-4b0f-a18e-2df0133c7434
SIP from address: sip:+1514xxxyyyy@mytrunk-1.pstn.twilio.com:5060;isup-oli=00;pstn-params=9084818088
SIP from address User Part: +1514xxxyyyy
E.164 number (MSISDN): 1514xxxyyyy
Country Code: Americas (1)
SIP from address Host Part: mytrunk-1.pstn.twilio.com
SIP from address Host Port: 5060
SIP From URI parameter: isup-oli=00
SIP From URI parameter: pstn-params=9084818088
SIP from tag: 76030578_c3356d0b_c0d924a7-b138-4b0f-a18e-2df0133c7434
To: sip:+1438vvvzzzz@sip.mypbx.net
SIP to address: sip:+1438vvvzzzz@sip.mypbx.net
SIP to address User Part: +1438vvvzzzz
E.164 number (MSISDN): 1438vvvzzzz
Country Code: Americas (1)
SIP to address Host Part: sip.mypbx.net
CSeq: 557398 INVITE
Sequence Number: 557398
Method: INVITE
Max-Forwards: 63
P-Asserted-Identity: sip:+1514xxxyyyy@216.221.155.195:5060
SIP PAI Address: sip:+1514xxxyyyy@216.221.155.195:5060
SIP PAI User Part: +1514xxxyyyy
E.164 number (MSISDN): 1514xxxyyyy
Country Code: Americas (1)
SIP PAI Host Part: 216.221.155.195
SIP PAI Host Port: 5060
Diversion: sip:+1438vvvzzzz@twilio.com;reason=unconditional
Call-ID: d53eeef5afae6eb32a7fd21a95f8286d@0.0.0.0
[Generated Call-ID: d53eeef5afae6eb32a7fd21a95f8286d@0.0.0.0]
Via: SIP/2.0/UDP 54.244.51.2:5060;branch=z9hG4bKc6ab.cf1da86f4129abe3cf5df73c94bb0f29.0
Transport: UDP
Sent-by Address: 54.244.51.2
Sent-by port: 5060
Branch: z9hG4bKc6ab.cf1da86f4129abe3cf5df73c94bb0f29.0
Via: SIP/2.0/UDP 172.18.78.179:5060;rport=5060;branch=z9hG4bKc0d924a7-b138-4b0f-a18e-2df0133c7434_c3356d0b_639-8206579726522615959
Transport: UDP
Sent-by Address: 172.18.78.179
Sent-by port: 5060
RPort: 5060
Branch: z9hG4bKc0d924a7-b138-4b0f-a18e-2df0133c7434_c3356d0b_639-8206579726522615959
Contact: sip:+1514xxxyyyy@172.18.78.179:5060;transport=udp
Contact URI: sip:+1514xxxyyyy@172.18.78.179:5060;transport=udp
Contact URI User Part: +1514xxxyyyy
E.164 number (MSISDN): 1514xxxyyyy
Country Code: Americas (1)
Contact URI Host Part: 172.18.78.179
Contact URI Host Port: 5060
Contact URI parameter: transport=udp
Allow: INVITE,ACK,CANCEL,BYE,REFER,NOTIFY,OPTIONS
X-Twilio-VerStat: TN-Validation-Passed-C
[Expert Info (Note/Undecoded): Unrecognised SIP header (x-twilio-verstat)]
[Unrecognised SIP header (x-twilio-verstat)]
[Severity level: Note]
[Group: Undecoded]
X-Twilio-AccountSid: ACaae1b0be86b4143c628414283c336d55
[Expert Info (Note/Undecoded): Unrecognised SIP header (x-twilio-accountsid)]
[Unrecognised SIP header (x-twilio-accountsid)]
[Severity level: Note]
[Group: Undecoded]
User-Agent: Twilio Gateway
Content-Type: application/sdp
X-Twilio-CallSid: CAfcb00c550dbe8eb38b5ed85bb8a3708c
[Expert Info (Note/Undecoded): Unrecognised SIP header (x-twilio-callsid)]
[Unrecognised SIP header (x-twilio-callsid)]
[Severity level: Note]
[Group: Undecoded]
Content-Length: 279
Message Body
Session Description Protocol
Session Description Protocol Version (v): 0
Owner/Creator, Session Id (o): root 1889557929 1889557929 IN IP4 172.18.103.242
Owner Username: root
Session ID: 1889557929
Session Version: 1889557929
Owner Network Type: IN
Owner Address Type: IP4
Owner Address: 172.18.103.242
Session Name (s): Twilio Media Gateway
Connection Information (c): IN IP4 168.86.145.243
Connection Network Type: IN
Connection Address Type: IP4
Connection Address: 168.86.145.243
Time Description, active time (t): 0 0
Session Start Time: 0
Session Stop Time: 0
Media Description, name and address (m): audio 12108 RTP/AVP 0 8 101
Media Type: audio
Media Port: 12108
Media Protocol: RTP/AVP
Media Format: ITU-T G.711 PCMU
Media Format: ITU-T G.711 PCMA
Media Format: DynamicRTP-Type-101
Media Attribute (a): rtpmap:0 PCMU/8000
Media Attribute Fieldname: rtpmap
Media Format: 0
MIME Type: PCMU
Sample Rate: 8000
Media Attribute (a): rtpmap:8 PCMA/8000
Media Attribute Fieldname: rtpmap
Media Format: 8
MIME Type: PCMA
Sample Rate: 8000
Media Attribute (a): rtpmap:101 telephone-event/8000
Media Attribute Fieldname: rtpmap
Media Format: 101
MIME Type: telephone-event
Sample Rate: 8000
Media Attribute (a): fmtp:101 0-16
Media Attribute Fieldname: fmtp
Media Format: 101 [telephone-event]
Media format specific parameters: 0-16
Media Attribute (a): ptime:20
Media Attribute Fieldname: ptime
Media Attribute Value: 20
Media Attribute (a): maxptime:20
Media Attribute Fieldname: maxptime
Media Attribute Value: 20
Media Attribute (a): sendrecv
[Generated Call-ID: d53eeef5afae6eb32a7fd21a95f8286d@0.0.0.0]

============== Twilio “originate test call” to same DID working fine

Session Initiation Protocol (INVITE)
Request-Line: INVITE sip:+1438vvvzzzz@sip.mypbx.net SIP/2.0
Method: INVITE
Request-URI: sip:+1438vvvzzzz@sip.mypbx.net
Request-URI User Part: +1438vvvzzzz
E.164 number (MSISDN): 1438vvvzzzz
Country Code: Americas (1)
Request-URI Host Part: sip.mypbx.net
[Resent Packet: False]
Message Header
Record-Route: sip:54.172.60.2;lr
Record-Route URI: sip:54.172.60.2;lr
Record-Route Host Part: 54.172.60.2
Record-Route URI parameter: lr
CSeq: 1 INVITE
Sequence Number: 1
Method: INVITE
From: sip:hello@mytrunk-1.pstn.twilio.com;tag=48407581_c3356d0b_19d15ddc-c3af-4c30-bc1f-63945756f34a
SIP from address: sip:hello@mytrunk-1.pstn.twilio.com
SIP from address User Part: hello
SIP from address Host Part: mytrunk-1.pstn.twilio.com
SIP from tag: 48407581_c3356d0b_19d15ddc-c3af-4c30-bc1f-63945756f34a
To: sip:+1438vvvzzzz@sip.mypbx.net
SIP to address: sip:+1438vvvzzzz@sip.mypbx.net
SIP to address User Part: +1438vvvzzzz
E.164 number (MSISDN): 1438vvvzzzz
Country Code: Americas (1)
SIP to address Host Part: sip.mypbx.net
Max-Forwards: 63
X-OhSip-Sas-Id: 7debdb15-be61-4b06-97be-66abfca89c84
[Expert Info (Note/Undecoded): Unrecognised SIP header (x-ohsip-sas-id)]
[Unrecognised SIP header (x-ohsip-sas-id)]
[Severity level: Note]
[Group: Undecoded]
X-OhSIP-Servlet: SipCallOut
[Expert Info (Note/Undecoded): Unrecognised SIP header (x-ohsip-servlet)]
[Unrecognised SIP header (x-ohsip-servlet)]
[Severity level: Note]
[Group: Undecoded]
X-OhSIP-Remote-Test-Id: sip-call-out_882
[Expert Info (Note/Undecoded): Unrecognised SIP header (x-ohsip-remote-test-id)]
[Unrecognised SIP header (x-ohsip-remote-test-id)]
[Severity level: Note]
[Group: Undecoded]
Diversion: sip:+1438vvvzzzz@twilio.com;reason=unconditional
Call-ID: 786d867ac6796c976c21df017ee0e7a9@0.0.0.0
[Generated Call-ID: 786d867ac6796c976c21df017ee0e7a9@0.0.0.0]
Via: SIP/2.0/UDP 54.172.60.2:5060;branch=z9hG4bKcfa7.e7abeb47db242e6d36bf4778b329fa26.0
Transport: UDP
Sent-by Address: 54.172.60.2
Sent-by port: 5060
Branch: z9hG4bKcfa7.e7abeb47db242e6d36bf4778b329fa26.0
Via: SIP/2.0/UDP 172.25.92.88:5060;rport=5060;branch=z9hG4bK19d15ddc-c3af-4c30-bc1f-63945756f34a_c3356d0b_640-8463151377069485683
Transport: UDP
Sent-by Address: 172.25.92.88
Sent-by port: 5060
RPort: 5060
Branch: z9hG4bK19d15ddc-c3af-4c30-bc1f-63945756f34a_c3356d0b_640-8463151377069485683
Contact: sip:hello@172.25.92.88:5060;transport=udp
Contact URI: sip:hello@172.25.92.88:5060;transport=udp
Contact URI User Part: hello
Contact URI Host Part: 172.25.92.88
Contact URI Host Port: 5060
Contact URI parameter: transport=udp
Allow: INVITE,ACK,CANCEL,OPTIONS,BYE,REFER,NOTIFY
X-Twilio-AccountSid: ACaae1b0be86b4143c628414283c336d55
[Expert Info (Note/Undecoded): Unrecognised SIP header (x-twilio-accountsid)]
[Unrecognised SIP header (x-twilio-accountsid)]
[Severity level: Note]
[Group: Undecoded]
User-Agent: Twilio Gateway
Content-Type: application/sdp
X-Twilio-CallSid: CA6f77783c5c3feea6a06a9a0f83bca809
[Expert Info (Note/Undecoded): Unrecognised SIP header (x-twilio-callsid)]
[Unrecognised SIP header (x-twilio-callsid)]
[Severity level: Note]
[Group: Undecoded]
Content-Length: 279
Message Body
Session Description Protocol
Session Description Protocol Version (v): 0
Owner/Creator, Session Id (o): root 2057151934 2057151934 IN IP4 172.18.160.216
Owner Username: root
Session ID: 2057151934
Session Version: 2057151934
Owner Network Type: IN
Owner Address Type: IP4
Owner Address: 172.18.160.216
Session Name (s): Twilio Media Gateway
Connection Information (c): IN IP4 168.86.137.179
Connection Network Type: IN
Connection Address Type: IP4
Connection Address: 168.86.137.179
Time Description, active time (t): 0 0
Session Start Time: 0
Session Stop Time: 0
Media Description, name and address (m): audio 14854 RTP/AVP 0 8 101
Media Type: audio
Media Port: 14854
Media Protocol: RTP/AVP
Media Format: ITU-T G.711 PCMU
Media Format: ITU-T G.711 PCMA
Media Format: DynamicRTP-Type-101
Media Attribute (a): rtpmap:0 PCMU/8000
Media Attribute Fieldname: rtpmap
Media Format: 0
MIME Type: PCMU
Sample Rate: 8000
Media Attribute (a): rtpmap:8 PCMA/8000
Media Attribute Fieldname: rtpmap
Media Format: 8
MIME Type: PCMA
Sample Rate: 8000
Media Attribute (a): rtpmap:101 telephone-event/8000
Media Attribute Fieldname: rtpmap
Media Format: 101
MIME Type: telephone-event
Sample Rate: 8000
Media Attribute (a): fmtp:101 0-16
Media Attribute Fieldname: fmtp
Media Format: 101 [telephone-event]
Media format specific parameters: 0-16
Media Attribute (a): ptime:20
Media Attribute Fieldname: ptime
Media Attribute Value: 20
Media Attribute (a): maxptime:20
Media Attribute Fieldname: maxptime
Media Attribute Value: 20
Media Attribute (a): sendrecv
[Generated Call-ID: 786d867ac6796c976c21df017ee0e7a9@0.0.0.0]

Session Initiation Protocol (100)
Status-Line: SIP/2.0 100 Trying
Status-Code: 100
[Resent Packet: False]
[Request Frame: 1]
[Response Time (ms): 0]
Message Header
Via: SIP/2.0/UDP 54.172.60.2:5060;rport=5060;received=54.172.60.2;branch=z9hG4bKcfa7.e7abeb47db242e6d36bf4778b329fa26.0
Via: SIP/2.0/UDP 172.25.92.88:5060;rport=5060;branch=z9hG4bK19d15ddc-c3af-4c30-bc1f-63945756f34a_c3356d0b_640-8463151377069485683
Record-Route: sip:54.172.60.2;lr
Call-ID: 786d867ac6796c976c21df017ee0e7a9@0.0.0.0
[Generated Call-ID: 786d867ac6796c976c21df017ee0e7a9@0.0.0.0]
From: sip:hello@mytrunk-1.pstn.twilio.com;tag=48407581_c3356d0b_19d15ddc-c3af-4c30-bc1f-63945756f34a
To: sip:+14387951336@sip.mypbx.net
CSeq: 1 INVITE
Server: FPBX-17.0.19.24(22.2.0)
Content-Length: 0

Session Initiation Protocol (180)
Status-Line: SIP/2.0 180 Ringing
Status-Code: 180
[Resent Packet: False]
[Request Frame: 1]
[Response Time (ms): 238]
Message Header
Via: SIP/2.0/UDP 54.172.60.2:5060;rport=5060;received=54.172.60.2;branch=z9hG4bKcfa7.e7abeb47db242e6d36bf4778b329fa26.0
Via: SIP/2.0/UDP 172.25.92.88:5060;rport=5060;branch=z9hG4bK19d15ddc-c3af-4c30-bc1f-63945756f34a_c3356d0b_640-8463151377069485683
Record-Route: sip:54.172.60.2;lr
Call-ID: 786d867ac6796c976c21df017ee0e7a9@0.0.0.0
[Generated Call-ID: 786d867ac6796c976c21df017ee0e7a9@0.0.0.0]
From: sip:hello@mytrunk-1.pstn.twilio.com;tag=48407581_c3356d0b_19d15ddc-c3af-4c30-bc1f-63945756f34a
To: sip:+14387951336@sip.mypbx.net;tag=ed4a35ce-0dfa-4e22-b914-15f97752073d
CSeq: 1 INVITE
Server: FPBX-17.0.19.24(22.2.0)
Contact: sip:70.24.239.17:5060
Allow: OPTIONS, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, INFO, MESSAGE, REFER
Content-Length: 0