PJSIP: domain for anonymous calls

How not to overwrite From address for incoming anonymous calls?

I have configured anonymous endpoint in pjsip.conf and incoming calls works fine, except domain. If no from_domain is specified for local peer endpoint, calls are shown from external_user@myPBX_IP, if specified – from external_user@mydomain.tld.

pjsip.conf:

[anonymous]
        type=endpoint
        context=anonymous

[localpeer]
        type=endpoint
        transport=tls
        media_encryption=sdes
        context=localpeers
        auth=localpeer
        aors=localpeer
;       from_domain=mydomain.tld

extensions.conf:

[anonymous]
exten => localpeer,1,Dial(PJSIP/localpeer)

pjsip set logger on:

<--- Received SIP request (964 bytes) from UDP:<IP>:5060 --->
INVITE sip:localpeer@mydomain.tld SIP/2.0
Via: SIP/2.0/UDP <IP>:5060;branch=z9hG4bK.-4KmGDKLq;rport
From: <sip:external_user@antisip.com>;tag=AkkSdzsbU
To: sip:localpeer@mydomain.tld
CSeq: 20 INVITE
Call-ID: Mwjo033IRi
Max-Forwards: 70
Supported: replaces, outbound, gruu
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO, PRACK, UPDATE
Content-Type: application/sdp
Content-Length: 358
Contact: <sip:external_user@sip.antisip.com;gr=urn:uuid:14632e70-7f22-4948-adc0-3b86f113c90c>
User-Agent: Linphone Desktop/ (Debian GNU/Linux bullseye/sid, Qt 5.15.2) LinphoneCore/4.4.0

v=0
o=external_user 2882 1457 IN IP4 <IP>
s=Talk
c=IN IP4 <IP>
t=0 0
a=rtcp-xr:rcvr-rtt=all:10000 stat-summary=loss,dup,jitt,TTL voip-metrics
m=audio 7078 RTP/AVP 96 0 8 9 101 97
a=rtpmap:96 opus/48000/2
a=fmtp:96 useinbandfec=1
a=rtpmap:101 telephone-event/48000
a=rtpmap:97 telephone-event/8000
a=rtcp-fb:* trr-int 5000
a=rtcp-fb:* ccm tmmbr

  == Setting global variable 'SIPDOMAIN' to 'mydomain.tld'
<--- Transmitting SIP response (263 bytes) to UDP:<IP>:5060 --->
SIP/2.0 100 Trying
v: SIP/2.0/UDP <IP>:5060;rport=5060;received=<IP>;branch=z9hG4bK.-4KmGDKLq
i: Mwjo033IRi
f: <sip:external_user@antisip.com>;tag=AkkSdzsbU
t: <sip:localpeer@mydomain.tld>
CSeq: 20 INVITE
Server: Asterisk PBX 16.2.1~dfsg-1+deb10u2
l:  0


    -- Executing [localpeer@anonymous:1] Dial("PJSIP/anonymous-00000000", "PJSIP/localpeer") in new stack
    -- Called PJSIP/localpeer
<--- Transmitting SIP request (945 bytes) to TLS:<PEER_IP>:41413 --->
INVITE sip:localpeer@<PEER_IP>:41413;transport=TLS SIP/2.0
v: SIP/2.0/TLS <ASTERISK_IP>:5061;rport;branch=z9hG4bKPj1bae6302-36e6-46fc-813e-102091d13fc0;alias
f: <sip:external_user@<ASTERISK_IP>>;tag=47fcb421-3006-4212-ba4a-acbaa544290d
t: <sip:localpeer@<PEER_IP>>
m: <sip:asterisk@<ASTERISK_IP>:5061;transport=TLS>
i: 04138a93-96b8-48f5-ba6e-e2d61d395f9a
CSeq: 23306 INVITE
Allow: OPTIONS, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, MESSAGE, REFER
k: 100rel, timer, replaces, norefersub
x: 1800
Min-SE: 90
Max-Forwards: 70
User-Agent: Asterisk PBX 16.2.1~dfsg-1+deb10u2
c: application/sdp
l:   324

Asterisk isn’t a SIP proxy, that information is not proxied through to an outgoing leg. It is an independent call originating from Asterisk.

Is there a way to replace From address with an original one with asterisk or the only way is to setup a separate sip proxy?

PJSIP doesn’t support setting such information from the dialplan or passing it through.