Home user here, please forgive any imprecision in my terminology.
TL;DR: I want to know whether or not it is possible to have PJSIP rewrite “From” headers based on the transport interface that an outgoing INVITE routes through.
Background: I have a FreePBX on a VLAN behind NAT with half a dozen internal SIP clients that have worked perfectly together for years. Now, I have added a new external SIP client (on a cell phone). I did this by using a second PJSIP transport:
- UDP/TCP on 5060 for the internal clients
- TCP-TLS on 5061 for the external client
There were some false starts implementing all the necessary firewall exceptions, port forwarding, and dynamic DNS entries. But at this point, calls between internal clients, external clients, and my provider trunk all seem to work perfectly. I get stable bidirectional audio with only minor drop-outs when my phone provider’s NAT decides to switch the endpoint IP address mid-call.
The rewrite_contact functionality was critical in making all of this work, particularly the external IP Address and Signalling Port fields:
With everything configured “correctly”, PJSIP now rewrites the “Contact” header with my external IP address (75.XX.XX.XX) and transport when an internal client calls the remote client (147.XX.XX.XX):
INVITE sip:[email protected]:38870;transport=TLS SIP/2.0
Via: SIP/2.0/TLS 75.XX.XX.XX:25061;rport;branch=z9hG4bKPjf173c2ea-6037-43c3-9ce3-71acbd20dc06;alias
From: “simaril” sip:[email protected];tag=a4ee3802-59a9-4791-bc28-9ba3390b1e07
To: sip:[email protected]
Contact: sip:[email protected]:25061;transport=TLS
Call-ID: 1fb190ba-0345-4d4c-aa61-ae4afd1f3694
CSeq: 18474 INVITE
Allow: OPTIONS, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, MESSAGE, REFER
Supported: 100rel, timer, replaces, norefersub, histinfo
Session-Expires: 1800
Min-SE: 90
P-Asserted-Identity: “simaril” sip:[email protected]
Max-Forwards: 70
User-Agent: FPBX-16.0.40.7(18.9)
Content-Type: application/sdp
Content-Length: 476
However, the “From” header continues to show an internal address (10.XX.XX.XX IP). This means that when I redial from the external client, the invite gets lost. It’s a minor annoyance – I can delete the address portion and my SIP client is smart enough to dial “231” directly – but it would be nice to fix
I am aware of this forum thread that proposes setting “from_domain” for each of the affected extensions. But I don’t think the solution would be appropriate here because all of the internal extensions still need to call each other through the internal network interface. Half of my internal extensions are old Cisco phones that don’t even have access to DNS.
It seems logical to me that the “Domain the transport comes from” should be used to rewrite the “From” field, but it doesn’t seem to work that way. I can’t even find where those fields are stored or used by asterisk. My “pjsip.transports.conf” doesn’t even include a field value that matches “internaldomain.example.com”:
[0.0.0.0-udp]
type=transport
protocol=udp
bind=0.0.0.0:5060
allow_reload=no
tos=cs3
cos=3[0.0.0.0-tls]
type=transport
protocol=tls
bind=0.0.0.0:5061
external_media_address=externaldomain.example.com
external_signaling_address=externaldomain.example.com
external_signaling_port=25061
ca_list_file=/etc/pki/tls/certs/ca-bundle.crt
cert_file=/etc/asterisk/keys/example.crt
priv_key_file=/etc/asterisk/keys/example.key
method=tlsv1_2
verify_client=yes
verify_server=yes
allow_reload=no
tos=cs3
cos=3
Is it unreasonable to expect that FreePBX / asterisk can rewrite the “From” header based on the outgoing transport parameters? Am I really the only one silly enough to set up FreePBX with two network interfaces and expect the clients to be able to inter-operate?
Or is it my SIP client application that’s doing the wrong thing? Should it be remembering and preferring the IP address in the “Contact” header (over the IP address in the “From” header) for its redial functionality?
If you got this far, thanks in advance for any light you can shed.