Getting Asterisk to look at user part of the URI / extension while classifying by IP

So I have a situation where I have an SBC classified in Asterisk by its IP address, and calls that are headed external through the SBC and towards the carrier are working fine. However, when trying to get the internal calls working, it looks like Asterisk is only classifying based on the domain portion of the URI. I see this in the verbose logging:

Setting global variable ‘SIPDOMAIN’ to ‘[SBC IP address]’

What I want to do is then strip off all but the last 5 digits and go to my internal dial plan (Dial-Users). The relevant bit of the configuration is below:

[DID-Extensions]

exten = _[+]155512XXXXX,1,Verbose(1, “External caller dialed inbound to DID ${EXTEN})”)

same = n,Goto(Dial-Users,${EXTEN:7},1)

Unfortunately, I never see the “External caller dialed inbound to DID ${EXTEN})” bit in the verbose logging and it seems that the user part of the URI is just being ignored since I classified based on IP. Can anyone give some insight as to what might solve this problem and if it is even possible to classify based on IP while routing based on extension?

Dialplan routing and endpoint identification (if you are using PJSIP) are separate things and only related in that the context configured on the endpoint is used. What does the actual INVITE request look like? Is the dialed number in the request URI? What extension does it attempt to go to? Does it go to the correct context in the dialplan?

Hi, thanks for the response.

Here’s the INVITE (the crucial parts, at least):

INVITE sip:+15551231212@[Asterisk IP] SIP/2.0
Via: SIP/2.0/UDP [SBC IP]:5060;branch=z9hG4bKac2068768884
Max-Forwards: 60
From: <sip:+16663211212@[SBC IP]>;tag=
To: <sip:+15551231212@[Asterisk IP]>
Call-ID: @[SBC IP]
CSeq: 1 INVITE
Contact: <sip:+16663211212@[SBC IP]:5060>
Supported: sdp-anat
Allow: INVITE,ACK,CANCEL,BYE,OPTIONS,REFER,NOTIFY
Content-Type: application/sdp
Content-Length: 317

v=0
o=root 124784314 1902263811 IN IP4 […]
s=Twilio Media Gateway
c=IN IP4 […]
t=0 0
m=audio 6945 RTP/SAVP 0 101
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
a=sendrecv
a=crypto:1 AES_ inline:

It looks fine to me. It is getting 488 Not Acceptable here from Asterisk and unfortunately, there is nothing helpful in the logging. The only message logged is “Setting global variable ‘SIPDOMAIN’ to ‘[Asterisk IP address]’”. It doesn’t trigger the verbose logging that would be expected by the context:

[DID-Extensions]

exten = _[+]155512XXXXX,1,Verbose(1, “External caller dialed inbound to DID ${EXTEN})”)

same = n,Goto(Dial-Users,${EXTEN:7},1)

So I would expect it to grab the +15551231212 DID based on the match pattern and strip off down to 31212, and then route to the extension that I have registered as 31212. I’m not sure if there is a logical hole that I’m having here, but I seem to be stuck at the moment unfortunately, as I don’t see much discussion or documentation around this bit.

Thanks again!

Here’s the endpoint configuration from pjsip.conf for the SBC:

;sbc

[sbc]
type=endpoint
context=[DID-Extensions]
disallow=all
allow=ulaw
direct_media=yes
aors=sbc

[sbc]
type=identify
endpoint=sbc
match=[SBC IP]

[sbc]
type=aor
contact=sip:[SBC IP]:5060

The endpoint is offering SDES SRTP, and you have not enabled it - so we reject it with a 488.