PJSIP Multi trunks to single host - Multitenant system

I am having a strange problem with incoming calls received on my trunks:

Host:
Dial(“SIP/provider-0001cb65”, “SIP/client1trunk/0123456789”)

The call however shows as received on client2trunk on the PBX:
PBX:
Executing [0123456789@external:1] Goto(“PJSIP/client2trunk-00000028”, “inbound,0123456789,1”) in new stack

The PBX is Realtime PJSIP configuration. Should the trunks from_user be set?

On chan_sip.conf, I believe this can be fixed by insecure=invite


I had the same problem with outgoing calls but the host gives and error on chan_sip.conf:
chan_sip.c: username mismatch, have , digest has

After setting insecure=invite, the problem seams to been resolved.

Does PJSIP have insecure=invite?

If both tenants are using the same SIP provider, it will just use the one that best matches, or the first in the configuration.

I run a multi tenant system as well, where all tenants use the same provider (us). I the PJSIP configuration I’ve made an endpoint that represents our SIP router, which is the first configured, that matches the incoming calls, then I just route them to the appropriate tenant based on what number was called.

Your calls aren’t being rejected. Missing insecure=invite, when needed, would result in the call being rejected (or more precisely asked for authentication that was not available). insecure=invite shouldn’t be needed on most chan_sip configurations, now that remotesecret is available and is best simulated on PJSIP by using outgoing only authentication.

Seems much more likely that you are matching both endpoints by the same IP address, and that is why only one is being used. The line parameter option is designed to handle that, but must be supported by the remote endpoint.

Yes, both trunks are matching to the same IP:

select * from ps_endpoint_id_ips;
±--------------±--------------±----------------±------------±-------------+
| id | endpoint | match | srv_lookups | match_header |
±--------------±--------------±----------------±------------±-------------+
| client2trunk | client2trunk | 192.168.1.1 | NULL | NULL |
| client1trunk | client1trunk | 192.168.1.1 | NULL | NULL |
±--------------±--------------±----------------±------------±-------------+

If I understand you correctly, the line option under registration should resolve this for me:

[client2trunk]
type=registration
outbound_auth=client2trunk
server_uri=sip:192.168.1.1
client_uri=sip:client2trunk@192.168.1.1
line=yes
retry_interval=60

As long as the endpoint returns the line parameter in incoming requests.

The invite from the host provider doesn’t include it. I believe they are still using chan_sip

INVITE sip:0123456789@192.168.1.2 SIP/2.0
Via: SIP/2.0/UDP 192.168.1.1:5060;branch=z9hG4bK71fe5e17;rport
Max-Forwards: 70
From: “Test” sip:0111111111@192.168.1.1;tag=as785daad7
To: sip:0123456789@192.168.1.2
Contact: sip:0111111111@192.168.1.1:5060
Call-ID: 1c860adb5ccbe2c95663a59d14b0bb6c@192.168.1.1:5060
CSeq: 102 INVITE
User-Agent: Asterisk PBX 15.4.1
Date: Wed, 23 Feb 2022 11:18:17 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Content-Type: application/sdp
Content-Length: 266

Everything is working and calls are being received. It’s the reporting that we are having problems with as the channel used doesn’t match the channel allocated to the tenant.

They are almost certainly using a completely different implementation of SIP. You are confusing the implementation with the protocol.

Your remaining option, with chan_pjsip, is to use two transports, with different port numbers.

I am registering to the host. Using different transport ports on the PBX will only affect the devices registering to the PBX.

The problem is the service provider is sending the call to the correct trunk (client1trunk). The PBX using PJSIP is showing it received on the other tenants trunk (client2trunk) “From testing it seams to be alphabetical”. Can nothing be changed on PJSIP to tell it to match the call received from the trunk name and not the IP?

Should I maybe do a match_header and not match IP?

If there is something unique in the INVITE to associate it to the correct endpoint, then you could certainly try using the match_header functionality.

1 Like

If you are registering each trunk to the ITSP you should set line=yes in the registration section. It will allow the incoming calls to match to the proper endpoint.

I have done that but its still selecting the first alphabetical trunk.

From what I can see the provider(host) is not sending any relevant information related to the trunk on the sip invite:
INVITE sip:0123456789@192.168.1.2 SIP/2.0
Via: SIP/2.0/UDP 192.168.1.1:5060;branch=z9hG4bK71fe5e17;rport
Max-Forwards: 70
From: “Test” sip:0111111111@192.168.1.1;tag=as785daad7
To: sip:0123456789@192.168.1.2
Contact: sip:0111111111@192.168.1.1:5060
Call-ID: 1c860adb5ccbe2c95663a59d14b0bb6c@192.168.1.1:5060
CSeq: 102 INVITE
User-Agent: Asterisk PBX 15.4.1
Date: Wed, 23 Feb 2022 11:18:17 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Content-Type: application/sdp
Content-Length: 266

I need to contact the provider to see what info can they send in the invite.

The local port number for the transport should be included in the Contact header for the REGISTER you sent, and that is the port to which the other side should send incoming traffic.

Seriously, Asterisk v15? You are seriously out of date and unsupported. You need to update to something more current in the last 5 years.

It’s the provider on Asterisk 15.

Most of my servers are running Asterisk 16.19 or 16.23. Only a couple left on Asterisk 13.

Then the provider has some problems. Also, why are you registering multiple trunks to the same place? Why are you registering at all? Unless they are going to honor the line=yes setting and send the INVITEs with the proper tags then you need to deal with the fact all the calls are going to be sourcing from the same place and only match on one endpoint.

Your options are to either A) create a general incoming context that will match based on the DID and route to the proper dialplan context. B) Use something like Kamailio between the provider and your Asterisk box so again, you can route based on DID but add custom header(s) that can then be matched by the endpoints on Asterisk.

I run a multi-tenant platform as well and option B is how I do it.

I am not 100% sure were to find or set the local port it should use per registration? I have read through pjsip.conf and can find anything.

Can I set the client_uri with a port:
client_uri=sip:client1trunk@192.168.1.1:1024

I am able to route calls bases on the DID since both trunks are connecting to the same context (This might change in the future).
The tenants want reports based on the number of calls received per trunk. All the headache is related getting the CDR{channel} value split per tenant.

Could you not just set an accountcode on the CHANNEL[1] based on the DID when the call comes in and use that for examining CDRs?

[1] Asterisk 19 Function_CHANNEL - Asterisk Project - Asterisk Project Wiki