Hello,

On 09.04.24 15:37, James Lipski via sr-users wrote:


Hello,

I have remote users registering/ routing calls through my server. When calls do pass through the server, the server updates the from name, to uri and from uri via updating the pseudovariables $fn, $tu, and $fu respectively. While this is has been working, I do occasionally see calls failing to process as the remote gateway fails the call with a "400 Bad From header". Inspecting the A-leg INVITE and the B-leg INVITE after updating the pseudovariables, I see the following:

A-leg INVITE:
INVITE sip:15551112222@example.com SIP/2.0
Via: SIP/2.0/UDP 79..xx.xx.xx:61379;rport;branch=z9hG4bKPj2b8935f4460447538d0176dcfb5c74a1
Max-Forwards: 70
From: sip:12223334444@example.com;tag=dff3c585a6154f23898e1121918f1752
To: sip:15551112222@example.com
Contact: <sip:12223334444@79..xx.xx.xx:61379;ob>
Call-ID: d793331e066f47bdafc0ad957cb506cc
CSeq: 30770 INVITE
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Supported: replaces, 100rel, timer, norefersub
Session-Expires: 1800
Min-SE: 90
Proxy-Authorization: Digest username="12223334444", realm="example.com", nonce="ZhUw02YVL6cdi51KMymTxGpzCZCZhd8G", uri="sip:15551112222@example.com", response="3a25b4ea0b1154e31caee1184a92f12b"
Content-Type: application/sdp
Content-Length:   627

v=0
o=- 3921660487 3921660487 IN IP4 79..xx.xx.xx
s=pjmedia
b=AS:84
t=0 0
a=X-nat:0
m=audio 4006 RTP/AVP 96 97 98 99 3 0 8 9 120 121 122
c=IN IP4 79..xx.xx.xx
b=TIAS:64000
a=rtcp:4007 IN IP4 79..xx.xx.xx
a=sendrecv
a=rtpmap:96 speex/16000
a=rtpmap:97 speex/8000
a=rtpmap:98 speex/32000
a=rtpmap:99 iLBC/8000
a=fmtp:99 mode=30
a=rtpmap:3 GSM/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:9 G722/8000
a=rtpmap:120 telephone-event/16000
a=fmtp:120 0-16
a=rtpmap:121 telephone-event/8000
a=fmtp:121 0-16
a=rtpmap:122 telephone-event/32000
a=fmtp:122 0-16
a=ssrc:63772004 cname:3ff849bd611036a7



----------------------------------
B-leg INVITE:
INVITE sip:15551112222@togateway.com SIP/2.0
Record-Route: <sip:10.64.54.207;lr;ftag=dff3c585a6154f23898e1121918f1752;did=e21.65c1>
Via: SIP/2.0/UDP 10.64.54.207:5060;branch=z9hG4bK919d.5ca83e030c0879093169546cd80591a6.0
Via: SIP/2.0/UDP 79..xx.xx.xx:61379;received=79..xx.xx.xx;rport=61379;branch=z9hG4bKPj2b8935f4460447538d0176dcfb5c74a1
Max-Forwards: 15
From: sip:12125557777@example.com"Updated Name" ;tag=dff3c585a6154f23898e1121918f1752
To: sip:15551112222@togateway.com
Contact: <sip:12125557777@79..xx.xx.xx:61379;ob>
Call-ID: d793331e066f47bdafc0ad957cb506cc
CSeq: 30770 INVITE
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Supported: replaces, 100rel, timer, norefersub
Session-Expires: 1800
Min-SE: 90
Content-Type: application/sdp
Content-Length:   609

v=0
o=- 3921660487 3921660487 IN IP4 10.64.54.207
s=pjmedia
b=AS:84
t=0 0
a=X-nat:0
m=audio 18400 RTP/AVP 96 97 98 99 3 0 8 9 120 121 122
c=IN IP4 10.64.54.207
b=TIAS:64000
a=ssrc:63772004 cname:3ff849bd611036a7
a=rtpmap:96 speex/16000
a=rtpmap:97 speex/8000
a=rtpmap:98 speex/32000
a=rtpmap:99 iLBC/8000
a=fmtp:99 mode=30
a=rtpmap:3 GSM/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:9 G722/8000
a=rtpmap:120 telephone-event/16000
a=fmtp:120 0-16
a=rtpmap:121 telephone-event/8000
a=fmtp:121 0-16
a=rtpmap:122 telephone-event/32000
a=fmtp:122 0-16
a=sendrecv
a=rtcp:18401

Note that I've updated the following on the B-leg:

$fn = "Updated Name" // originally nothing
$fu = sip:12125557777@example.com // originally sip:12223334444@example.com
$tu = sip:15551112222@togateway.com // originally sip:15551112222@example.com


While the from uri, and to uri do get updated, the from name is injected in the wrong place of the from header. This only seems to happen when the A-leg is missing the "<" and ">" characters enclosing the from headers.

Should I not be updating the pseudo variables in this manner to update the from name, to uri and from uri; is there another way to update these attributes of the header without malforming it?

looks like a bug, you can open an issue on the tracker.

On the other hand, updating directly with variables the To/From attributes is somehow unsafe overall, the option to do it so was made more for testing or particular use cases. It is recommended to use the uac module and its functions uac_replace_from()/_to() for this purpose.

Cheers,
Daniel

-- 
Daniel-Constantin Mierla (@ asipto.com)
twitter.com/miconda -- linkedin.com/in/miconda
Kamailio Consultancy, Training and Development Services -- asipto.com
Kamailio World Conference, April 18-19, 2024, Berlin -- kamailioworld.com