Setting address or domain at least of `To:` header in `INVITE`

In a similar fashion and for similar reasons as was done for SendMessage() in res_pjsip_messaging: Refactor outgoing URI processing · asterisk/asterisk@c3654a9 · GitHub I need to be able to influence the value of the (domain at least) in the To: header in an INVITE sent from a Dial() command.

Currently Asterisk seems to use the IP address of the device the INVITE is being sent to but I would like it to use a/the domain of the account the INVITE is being sent to.

Is this currently achievable with PJSIP?

The To is the same as the request URI, there is no ability to independently set them.

By independently set them do you mean there is no way to set the To: to something different than request URI or do you mean they are one and the same and there is no way to set either/both of them to any other value than what Asterisk wants to set them to itself?

Maybe I’m not understanding the significance of pointing out the request URI in this context. Is it perhaps to indicate that by changing the request URI I can change the To: value? If so, how do I set the request URI?

I meant there is no way to set the To without also changing the Request URI.

The Request URI is either the contact specified on an AOR, a registered contact, or the URI specified in the endpoint. It determines the target of the SIP request as well as the Request URI and To URI. You haven’t shown configuration or elaborated on the complete configuration, so I can’t give real specifics unique to your configuration.

If you want to send the SIP request to one address, but have the Request and To URI be something else then you would set an outbound proxy using:

outbound_proxy=sip:target\;lr\;hide

In the configuration file on the endpoint. This would cause the SIP request to be sent to that address, but the Request and To URI be something else.

The SIP client is the Linphone softphone running on a mobile device. Here are the pjsip.conf configuration entries for it:

[my_sip_account]
type=endpoint
context=internal-sip
message_context=messages
ice_support=yes
disallow=all
allow=!all,opus,ulaw,alaw
use_avpf=yes
from_domain=pbx.example.com
auth=my_sip_account
aors=my_sip_account

[my_sip_account]
type=auth
auth_type=userpass
password=[redacted]
username=my_sip_account

[my_sip_account]
type=aor
max_contacts=1
remove_existing=yes
maximum_expiration=31536000

When called, that produced INVITE messages such as:

INVITE sip:my_sip_account@192.168.101.154:39758;transport=tcp;pn-prid==[redacted];pn-provider=fcm;pn-param==[redacted];pn-silent=1;pn-timeout=0 SIP/2.0
Via: SIP/2.0/TCP 7.3.7.255:5060;rport;branch=z9hG4bKPj44ae1d6c-2d05-4259-94a5-143bf16f6368;alias
From: "[redacted]" <sip:[redacted]@pbx.example.com>;tag=9efa1c2d-cad9-44b0-9919-c24b19a141fa
To: <sip:my_sip_account@192.168.101.154;pn-prid==[redacted];pn-provider=fcm;pn-param==[redacted];pn-silent=1;pn-timeout=0>
Contact: <sip:asterisk@7.3.7.255:5060;transport=TCP>

I’d like the To: header instead to be:

To: <sip:my_sip_account@example.com;pn-prid==[redacted];pn-provider=fcm;pn-param==[redacted];pn-silent=1;pn-timeout=0>

Any suggestions would be much appreciated.

Based on what you want to do, there is no ability to do such a thing.

What goes in the request URI will be what was in the Contact header in the REGISTER from the other party. If you wan the domain name there, you must configure the remote entity appropriately.

But doesn’t the Contact: header in the REGISTER need to identify the specific device that is registering? IOW, doesn’t it need to be the IP address of the device otherwise Asterisk doesn’t know how to reach it when it needs to send an INVITE does it?

The exact address is needed in the domain part of the request URI for the call to go to the right device.

It is the address of record that can represent multiple devices, and that goes in the To header of the REGISTER. What goes in the Contact header must uniquely identify the the registering device.

I suppose Asterisk could have been implemented so that it inserts a, purely internal, proxy, when accessing dynamic hosts, but that isn’t how it has been done.

Even if that were done, the simple implementation would result in the domain name being that of the Asterisk UAC, Having the domain name considered when doing AOR lookups would confuse most users (it is possible that chan_pjsip does allow domain names in AOR section names, but dialstrings don’t currently use those).