Asterisk, PJSIP and dual-homing

Hi,
In the process of doing an Asterisk 13->16 migration, and converting to chan_pjsip as part of the project. Running into an issue where the “From:” field in SIP packets is showing the wrong IP.
My setup:
Asterisk 16.4.0 running on Ubuntu 18.04. The server is dual-homed, 10.0.0.2 is the internal IP and 1.2.3.4 is external. I have 2 phones connected, 1234 (10.0.0.3) and 4321 (10.0.0.4). When I.E. 4321 calls 1234, all other addresses in the SIP requests are fine except in the “From:” and “P-Asserted-Identity:” fields:

<--- Received SIP request (906 bytes) from UDP:10.0.0.4:5060 --->
INVITE sip:1234@10.0.0.2 SIP/2.0
Via: SIP/2.0/UDP 10.0.0.4:5060;rport;branch=z9hG4bK423254122
From: <sip:4321@10.0.0.2>;tag=436420747
To: <sip:1234@10.0.0.2>
Call-ID: 1506756316
CSeq: 20 INVITE
Contact: <sip:4321@10.0.0.4>
Content-Type: application/sdp
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO
Max-Forwards: 70
User-Agent: Linphone/3.6.1 (eXosip2/4.1.0)
Subject: Phone call
Content-Length:   434

v=0
o=4321 844 770 IN IP4 10.0.0.4
s=Talk
c=IN IP4 10.0.0.4
t=0 0
m=audio 7078 RTP/AVP 124 111 110 0 8 101
a=rtpmap:124 opus/48000
a=fmtp:124 useinbandfec=1; usedtx=1
a=rtpmap:111 speex/16000
a=fmtp:111 vbr=on
a=rtpmap:110 speex/8000
a=fmtp:110 vbr=on
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-11
m=video 9078 RTP/AVP 103 99
a=rtpmap:103 VP8/90000
a=rtpmap:99 MP4V-ES/90000
a=fmtp:99 profile-level-id=3

<--- Transmitting SIP response (461 bytes) to UDP:10.0.0.4:5060 --->
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 10.0.0.4:5060;rport=5060;received=10.0.0.4;branch=z9hG4bK423254122
Call-ID: 1506756316
From: <sip:4321@10.0.0.2>;tag=436420747
To: <sip:1234@10.0.0.2>;tag=z9hG4bK423254122
CSeq: 20 INVITE
WWW-Authenticate: Digest realm="asterisk",nonce="1570562819/265206636c10f3a8e7a7e62d9df379eb",opaque="52b709ea197637b9",algorithm=md5,qop="auth"
Server: Asterisk PBX 16.4.0~dfsg-0~ppa1
Content-Length:  0


asterisk-test-1*CLI> <--- Received SIP request (252 bytes) from UDP:10.0.0.4:5060 --->
ACK sip:1234@10.0.0.2 SIP/2.0
Via: SIP/2.0/UDP 10.0.0.4:5060;rport;branch=z9hG4bK423254122
From: <sip:4321@10.0.0.2>;tag=436420747
To: <sip:1234@10.0.0.2>;tag=z9hG4bK423254122
Call-ID: 1506756316
CSeq: 20 ACK
Content-Length: 0


asterisk-test-1*CLI> <--- Received SIP request (1173 bytes) from UDP:10.0.0.4:5060 --->
INVITE sip:1234@10.0.0.2 SIP/2.0
Via: SIP/2.0/UDP 10.0.0.4:5060;rport;branch=z9hG4bK55095526
From: <sip:4321@10.0.0.2>;tag=436420747
To: <sip:1234@10.0.0.2>
Call-ID: 1506756316
CSeq: 21 INVITE
Contact: <sip:4321@10.0.0.4>
Authorization: Digest username="4321", realm="asterisk", nonce="1570562819/265206636c10f3a8e7a7e62d9df379eb", uri="sip:1234@10.0.0.2", response="195017b0a1535b5af9887c2b72b8ac5e", algorithm=MD5, cnonce="0a4f113b", opaque="52b709ea197637b9", qop=auth, nc=00000001
Content-Type: application/sdp
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO
Max-Forwards: 70
User-Agent: Linphone/3.6.1 (eXosip2/4.1.0)
Subject: Phone call
Content-Length:   434

v=0
o=4321 844 770 IN IP4 10.0.0.4
s=Talk
c=IN IP4 10.0.0.4
t=0 0
m=audio 7078 RTP/AVP 124 111 110 0 8 101
a=rtpmap:124 opus/48000
a=fmtp:124 useinbandfec=1; usedtx=1
a=rtpmap:111 speex/16000
a=fmtp:111 vbr=on
a=rtpmap:110 speex/8000
a=fmtp:110 vbr=on
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-11
m=video 9078 RTP/AVP 103 99
a=rtpmap:103 VP8/90000
a=rtpmap:99 MP4V-ES/90000
a=fmtp:99 profile-level-id=3

  == Setting global variable 'SIPDOMAIN' to '10.0.0.2'
<--- Transmitting SIP response (287 bytes) to UDP:10.0.0.4:5060 --->
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 10.0.0.4:5060;rport=5060;received=10.0.0.4;branch=z9hG4bK55095526
Call-ID: 1506756316
From: <sip:4321@10.0.0.2>;tag=436420747
To: <sip:1234@10.0.0.2>
CSeq: 21 INVITE
Server: Asterisk PBX 16.4.0~dfsg-0~ppa1
Content-Length:  0


asterisk-test-1*CLI>     -- Executing [1234@from-office:1] Dial("PJSIP/4321-00000000", "PJSIP/1234") in new stack
asterisk-test-1*CLI> <--- Transmitting SIP request (937 bytes) to UDP:10.0.0.3:56429 --->
INVITE sip:1234@10.0.0.3:56429;ob SIP/2.0
Via: SIP/2.0/UDP 10.0.0.2:5060;rport;branch=z9hG4bKPj056376e2-8c5f-4916-99d9-bfe1fb98561f
From: <sip:4321@1.2.3.4>;tag=de2f5e5a-34b1-4f78-81a5-ade719c64562
To: <sip:1234@10.0.0.3;ob>
Contact: <sip:asterisk@10.0.0.2:5060>
Call-ID: 1f18cb03-6753-4eb1-a7e8-81bd99cc91d2
CSeq: 9333 INVITE
Allow: OPTIONS, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, MESSAGE, REFER
Supported: 100rel, timer, replaces, norefersub
Session-Expires: 1800
Min-SE: 90
P-Asserted-Identity: <sip:4321@1.2.3.4>
Max-Forwards: 70
User-Agent: Asterisk PBX 16.4.0~dfsg-0~ppa1
Content-Type: application/sdp
Content-Length:   235

v=0
o=- 394061538 394061538 IN IP4 10.0.0.2
s=Asterisk
c=IN IP4 10.0.0.2
t=0 0
m=audio 19138 RTP/AVP 0 101
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
a=maxptime:150
a=sendrecv

asterisk-test-1*CLI>     -- Called PJSIP/1234
asterisk-test-1*CLI> <--- Received SIP response (328 bytes) from UDP:10.0.0.3:56429 --->
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 10.0.0.2:5060;rport=5060;received=10.0.0.2;branch=z9hG4bKPj056376e2-8c5f-4916-99d9-bfe1fb98561f
Call-ID: 1f18cb03-6753-4eb1-a7e8-81bd99cc91d2
From: <sip:4321@1.2.3.4>;tag=de2f5e5a-34b1-4f78-81a5-ade719c64562
To: <sip:1234@10.0.0.3;ob>
CSeq: 9333 INVITE
Content-Length:  0


asterisk-test-1*CLI> <--- Received SIP response (498 bytes) from UDP:10.0.0.3:56429 --->
SIP/2.0 180 Ringing
Via: SIP/2.0/UDP 10.0.0.2:5060;rport=5060;received=10.0.0.2;branch=z9hG4bKPj056376e2-8c5f-4916-99d9-bfe1fb98561f
Call-ID: 1f18cb03-6753-4eb1-a7e8-81bd99cc91d2
From: <sip:4321@1.2.3.4>;tag=de2f5e5a-34b1-4f78-81a5-ade719c64562
To: <sip:1234@10.0.0.3;ob>;tag=4abe48f2e35642a1995244fb52bbbc4c
CSeq: 9333 INVITE
Contact: <sip:10.0.0.3:56429>
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Content-Length:  0


    -- PJSIP/1234-00000001 is ringing
    -- PJSIP/1234-00000001 is ringing
asterisk-test-1*CLI> <--- Transmitting SIP response (520 bytes) to UDP:10.0.0.4:5060 --->
SIP/2.0 180 Ringing
Via: SIP/2.0/UDP 10.0.0.4:5060;rport=5060;received=10.0.0.4;branch=z9hG4bK55095526
Call-ID: 1506756316
From: <sip:4321@10.0.0.2>;tag=436420747
To: <sip:1234@10.0.0.2>;tag=c1dcf95b-e916-487d-ae12-308ad6eb51f4
CSeq: 21 INVITE
Server: Asterisk PBX 16.4.0~dfsg-0~ppa1
Contact: <sip:10.0.0.2:5060>
Allow: OPTIONS, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, MESSAGE, REFER
P-Asserted-Identity: <sip:1234@10.0.0.2>
Content-Length:  0


asterisk-test-1*CLI> <--- Received SIP response (899 bytes) from UDP:10.0.0.3:56429 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP 10.0.0.2:5060;rport=5060;received=10.0.0.2;branch=z9hG4bKPj056376e2-8c5f-4916-99d9-bfe1fb98561f
Call-ID: 1f18cb03-6753-4eb1-a7e8-81bd99cc91d2
From: <sip:4321@1.2.3.4>;tag=de2f5e5a-34b1-4f78-81a5-ade719c64562
To: <sip:1234@10.0.0.3;ob>;tag=4abe48f2e35642a1995244fb52bbbc4c
CSeq: 9333 INVITE
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Contact: <sip:10.0.0.3:56429>
Supported: replaces, 100rel, timer, norefersub
Session-Expires: 1800;refresher=uac
Require: timer
Content-Type: application/sdp
Content-Length:   271

v=0
o=- 3779537218 3779537219 IN IP4 10.0.0.3
s=pjmedia
b=AS:84
t=0 0
a=X-nat:0
m=audio 4016 RTP/AVP 0 101
c=IN IP4 10.0.0.3
b=TIAS:64000
a=rtcp:4017 IN IP4 10.0.0.3
a=sendrecv
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16

       > 0x7f64740352a0 -- Strict RTP learning after remote address set to: 10.0.0.3:4016
asterisk-test-1*CLI> <--- Transmitting SIP request (413 bytes) to UDP:10.0.0.3:56429 --->
ACK sip:10.0.0.3:56429 SIP/2.0
Via: SIP/2.0/UDP 10.0.0.2:5060;rport;branch=z9hG4bKPjf422128e-acf7-4801-b5e5-ee9145b6b831
From: <sip:4321@1.2.3.4>;tag=de2f5e5a-34b1-4f78-81a5-ade719c64562
To: <sip:1234@10.0.0.3;ob>;tag=4abe48f2e35642a1995244fb52bbbc4c
Call-ID: 1f18cb03-6753-4eb1-a7e8-81bd99cc91d2
CSeq: 9333 ACK
Max-Forwards: 70
User-Agent: Asterisk PBX 16.4.0~dfsg-0~ppa1
Content-Length:  0


    -- PJSIP/1234-00000001 answered PJSIP/4321-00000000
asterisk-test-1*CLI>        > 0x7f647401e6b0 -- Strict RTP learning after remote address set to: 10.0.0.4:7078
<--- Transmitting SIP response (846 bytes) to UDP:10.0.0.4:5060 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP 10.0.0.4:5060;rport=5060;received=10.0.0.4;branch=z9hG4bK55095526
Call-ID: 1506756316
From: <sip:4321@10.0.0.2>;tag=436420747
To: <sip:1234@10.0.0.2>;tag=c1dcf95b-e916-487d-ae12-308ad6eb51f4
CSeq: 21 INVITE
Server: Asterisk PBX 16.4.0~dfsg-0~ppa1
Allow: OPTIONS, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, MESSAGE, REFER
Contact: <sip:10.0.0.2:5060>
Supported: 100rel, timer, replaces, norefersub
P-Asserted-Identity: <sip:1234@10.0.0.2>
Content-Type: application/sdp
Content-Length:   249

v=0
o=- 844 772 IN IP4 10.0.0.2
s=Asterisk
c=IN IP4 10.0.0.2
t=0 0
m=audio 10288 RTP/AVP 0 101
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
a=maxptime:150
a=sendrecv
m=video 0 RTP/AVP 103 99

asterisk-test-1*CLI> <--- Received SIP request (369 bytes) from UDP:10.0.0.4:5060 --->
ACK sip:10.0.0.2:5060 SIP/2.0
Via: SIP/2.0/UDP 10.0.0.4:5060;rport;branch=z9hG4bK1460564227
From: <sip:4321@10.0.0.2>;tag=436420747
To: <sip:1234@10.0.0.2>;tag=c1dcf95b-e916-487d-ae12-308ad6eb51f4
Call-ID: 1506756316
CSeq: 21 ACK
Contact: <sip:4321@10.0.0.4>
Max-Forwards: 70
User-Agent: Linphone/3.6.1 (eXosip2/4.1.0)
Content-Length: 0


asterisk-test-1*CLI>     -- Channel PJSIP/1234-00000001 joined 'simple_bridge' basic-bridge <1a76ff6e-0511-40bc-8b87-df2e3566a871>
asterisk-test-1*CLI>     -- Channel PJSIP/4321-00000000 joined 'simple_bridge' basic-bridge <1a76ff6e-0511-40bc-8b87-df2e3566a871>
       > Bridge 1a76ff6e-0511-40bc-8b87-df2e3566a871: switching from simple_bridge technology to native_rtp
       > Locally RTP bridged 'PJSIP/4321-00000000' and 'PJSIP/1234-00000001' in stack
asterisk-test-1*CLI>        > 0x7f64740352a0 -- Strict RTP switching to RTP target address 10.0.0.3:4016 as source
asterisk-test-1*CLI>        > 0x7f647401e6b0 -- Strict RTP switching to RTP target address 10.0.0.4:7078 as source
asterisk-test-1*CLI> <--- Received SIP request (403 bytes) from UDP:10.0.0.3:56429 --->
BYE sip:asterisk@10.0.0.2:5060 SIP/2.0
Via: SIP/2.0/UDP 10.0.0.3:56429;rport;branch=z9hG4bKPje9c269bc7ff241a1accfd87561752bb1
Max-Forwards: 70
From: <sip:1234@10.0.0.3;ob>;tag=4abe48f2e35642a1995244fb52bbbc4c
To: <sip:4321@1.2.3.4>;tag=de2f5e5a-34b1-4f78-81a5-ade719c64562
Call-ID: 1f18cb03-6753-4eb1-a7e8-81bd99cc91d2
CSeq: 23271 BYE
User-Agent: MicroSIP/3.10.1
Content-Length:  0


<--- Transmitting SIP response (396 bytes) to UDP:10.0.0.3:56429 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP 10.0.0.3:56429;rport=56429;received=10.0.0.3;branch=z9hG4bKPje9c269bc7ff241a1accfd87561752bb1
Call-ID: 1f18cb03-6753-4eb1-a7e8-81bd99cc91d2
From: <sip:1234@10.0.0.3;ob>;tag=4abe48f2e35642a1995244fb52bbbc4c
To: <sip:4321@1.2.3.4>;tag=de2f5e5a-34b1-4f78-81a5-ade719c64562
CSeq: 23271 BYE
Server: Asterisk PBX 16.4.0~dfsg-0~ppa1
Content-Length:  0


asterisk-test-1*CLI>     -- Channel PJSIP/1234-00000001 left 'native_rtp' basic-bridge <1a76ff6e-0511-40bc-8b87-df2e3566a871>
asterisk-test-1*CLI>     -- Channel PJSIP/4321-00000000 left 'native_rtp' basic-bridge <1a76ff6e-0511-40bc-8b87-df2e3566a871>
asterisk-test-1*CLI>   == Spawn extension (from-office, 1234, 1) exited non-zero on 'PJSIP/4321-00000000'
asterisk-test-1*CLI> <--- Transmitting SIP request (392 bytes) to UDP:10.0.0.4:5060 --->
BYE sip:4321@10.0.0.4 SIP/2.0
Via: SIP/2.0/UDP 10.0.0.2:5060;rport;branch=z9hG4bKPjf5c3e718-f15f-4119-9447-50ad6ad4cd80
From: <sip:1234@10.0.0.2>;tag=c1dcf95b-e916-487d-ae12-308ad6eb51f4
To: <sip:4321@10.0.0.2>;tag=436420747
Call-ID: 1506756316
CSeq: 25360 BYE
Reason: Q.850;cause=16
Max-Forwards: 70
User-Agent: Asterisk PBX 16.4.0~dfsg-0~ppa1
Content-Length:  0


<--- Received SIP response (334 bytes) from UDP:10.0.0.4:5060 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP 10.0.0.2:5060;rport=5060;branch=z9hG4bKPjf5c3e718-f15f-4119-9447-50ad6ad4cd80
From: <sip:1234@10.0.0.2>;tag=c1dcf95b-e916-487d-ae12-308ad6eb51f4
To: <sip:4321@10.0.0.2>;tag=436420747
Call-ID: 1506756316
CSeq: 25360 BYE
User-Agent: Linphone/3.6.1 (eXosip2/4.1.0)
Content-Length: 0


asterisk-test-1*CLI> 

This doesn’t actually cause the call to fail, but I have endpoint devices that refuse to display caller ID unless the From: field is showing the IP they’re registering to. This worked fine with chan_sip. Here’s my pjsip.conf:

[aor](!)
type=aor
max_contacts=5

[auth](!)
type=auth
auth_type=userpass
username=1000
password=12345

[default-transport]
type=transport
protocol=udp
bind=0.0.0.0:5060
external_media_address=1.2.3.4
external_signaling_address=1.2.3.4
local_net=10.0.0.0/8

[endpoint](!)
type=endpoint
context=from-office
dtmf_mode=rfc4733
disallow=all
allow=ulaw
direct_media=no
inband_progress=no
send_pai=yes

[1234](aor)
[1234](auth)
username=1234

[1234](endpoint)
context=from-office
auth=1234
outbound_auth=1234
aors=1234

[4321](aor)
[4321](auth)
username=4321

[4321](endpoint)
context=from-office
auth=4321
outbound_auth=4321
aors=4321

This is still seen even if I remove the external_signaling_address and external_media_address params. The right routing decision is definitely being made as traffic is going in and out the right interface. Anyone have any pointers? Do I have to set up separate transports for each interface?

The From and other headers that don’t impact routing aren’t updated currently if the local IP address is different, as it hasn’t been needed for anything else. Changing that would likely require modifying and extending the code.

You’re confusing domain portions of those URI’s with it being an actual IP. That is incorrect. Those headers have a user@domain format. So if the domain was an actual FQDN instead of just being the IP, let’s say pbx.domain.com then you would end up with the following of

INVITE Request: INVITE sip:1234@pbx.domain.com SIP/2.0
From Header: From: "User" <sip:4321@pbx.domain.com>
To Header: To: <sip:1234@pbx.domain.com>

So again, while they look like IPs it is due to you using pure IPs vs FQDN’s and therefore those are correct.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.