[Home]

Summary:ASTERISK-26955: pjsip: SIP Packets with Via "received=" Containing IPv6 Address Delimited by "[]" Rejected
Reporter:Peter Sokolov (peterdoo)Labels:
Date Opened:2017-04-22 13:56:52Date Closed:2020-02-07 07:06:09.000-0600
Priority:MinorRegression?
Status:Closed/CompleteComponents:pjproject/pjsip
Versions:14.3.0 Frequency of
Occurrence
Related
Issues:
is duplicated byASTERISK-28696 PJSIP exception when parsing 'Via' header
is related toASTERISK-28020 res_pjsip_transport_websocket: Properly set 'received' for IPv6
Environment:using Asterisk on Debian 8.7, built with ./configure --with-pjproject-bundledAttachments:
Description:When using PJSIP and a SIP packet containing Via "received" with an IPv6 address delimited by "[" and "]" is received, PJSIP drops such a packet complaining about the "[" and "]". No calls can be established.

Via: SIP/2.0/UDP [2001:db8::9:1];received=[2001:db8::9:255];branch=z9hG4bKas3-111

RFC5118 sais that even though this is not a valid request based on a strict interpretation of the grammar in [RFC3261], robust implementations must nonetheless be able to parse the topmost Via header field and continue processing the request. I assume that Asterisk should be treated as a robust implementation.

Channel SIP has no problems with SIP packets containing Via received= with the IPv6 address in brackets.

Here is the relevant part of the log. Nothing comes after that. Just like the packet had not been received at all:

{noformat}
[Feb  4 23:21:19] ERROR[26339]: pjproject:0 <?>:        sip_transport. Error processing 503 bytes packet from UDP 2a00:130:1093:2:d7ff:fe39:b8d7:123:5060 : PJSIP syntax error exception when parsing 'Via' header on line 2 col 119:
SIP/2.0 100 Trying
Via: SIP/2.0/UDP [2a00:123:c17:1c3f::5]:5060;rport=5060;branch=z9hG4bKPjb636b737-5c82-4238-b5ba-0d98dbe86f27;received=[2a00:123:c17:1c3f::5]
From: "Phone 202" <sip:202@[2a00:123:c17:1c3f::5]>;tag=98eb3897-57dd-45c8-a9f2-4909c812f0a9
To: <sip:203@[2a00:130:1093:2:d7ff:fe39:b8d7:123];uniq=C09040DC74C0F2A9D6039136CB478>
Call-ID: d82b4318-108b-4b46-8ec9-b4e4e2200a98
CSeq: 1012 INVITE
User-Agent: AVM FRITZ!Box 7330 107.06.50 (Apr  1 2016)
Content-Length: 0
{noformat}

In the file src/asterisk/third-party/pjproject/source/pjsip/src/pjsip/sipparser.c no brackets are included in pconst.pjsip_VIA_PARAM_SPEC and pconst.pjsip_VIA_PARAM_SPEC_ESC. Adding both brackets to both of them using pj_cis_add_str, Asterisk starts accepting SIP packets that include Via: lines as the one mentioned above, however I do not know whether that is a correct solution.
Comments:By: Asterisk Team (asteriskteam) 2017-04-22 13:56:54.153-0500

Thanks for creating a report! The issue has entered the triage process. That means the issue will wait in this status until a Bug Marshal has an opportunity to review the issue. Once the issue has been reviewed you will receive comments regarding the next steps towards resolution.

A good first step is for you to review the [Asterisk Issue Guidelines|https://wiki.asterisk.org/wiki/display/AST/Asterisk+Issue+Guidelines] if you haven't already. The guidelines detail what is expected from an Asterisk issue report.

Then, if you are submitting a patch, please review the [Patch Contribution Process|https://wiki.asterisk.org/wiki/display/AST/Patch+Contribution+Process].

By: Rusty Newton (rnewton) 2017-04-25 15:22:28.999-0500

We require additional debug to continue with triage of your issue. Please follow the instructions on the wiki [1] for how to collect debugging information from Asterisk. For expediency, where possible, attach the debug with a '.txt' file extension so that the debug will be usable for further analysis.

Thanks!

[1] https://wiki.asterisk.org/wiki/display/AST/Collecting+Debug+Information



By: Rusty Newton (rnewton) 2017-04-25 15:22:35.429-0500

Thanks for the report. Can you attach an Asterisk debug log for extra clarity in terms of Asterisk's response and behavior in this case?

Be sure it includes the pjsip logger output of course. Thanks!

By: Peter Sokolov (peterdoo) 2017-04-26 04:37:12.005-0500

Here is the relevant part of the log. Nothing comes after that. Just like the packet had not been received at all:

{noformat}
[Feb  4 23:21:19] ERROR[26339]: pjproject:0 <?>:        sip_transport. Error processing 503 bytes packet from UDP 2a00:130:1093:2:d7ff:fe39:b8d7:123:5060 : PJSIP syntax error exception when parsing 'Via' header on line 2 col 119:
SIP/2.0 100 Trying
Via: SIP/2.0/UDP [2a00:123:c17:1c3f::5]:5060;rport=5060;branch=z9hG4bKPjb636b737-5c82-4238-b5ba-0d98dbe86f27;received=[2a00:123:c17:1c3f::5]
From: "Phone 202" <sip:202@[2a00:123:c17:1c3f::5]>;tag=98eb3897-57dd-45c8-a9f2-4909c812f0a9
To: <sip:203@[2a00:130:1093:2:d7ff:fe39:b8d7:123];uniq=C09040DC74C0F2A9D6039136CB478>
Call-ID: d82b4318-108b-4b46-8ec9-b4e4e2200a98
CSeq: 1012 INVITE
User-Agent: AVM FRITZ!Box 7330 107.06.50 (Apr  1 2016)
Content-Length: 0
{noformat}

In the file src/asterisk/third-party/pjproject/source/pjsip/src/pjsip/sipparser.c no brackets are included in pconst.pjsip_VIA_PARAM_SPEC and pconst.pjsip_VIA_PARAM_SPEC_ESC. Adding both brackets to both of them using pj_cis_add_str, Asterisk starts accepting SIP packets that include Via: lines as the one mentioned above, however I do not know whether that is a correct solution.

By: Rusty Newton (rnewton) 2017-04-26 16:27:10.917-0500

Thanks for the additional information. I added it to the description.

Can you add some additional environment information to the issue? Specifically what pjproject are you using, bundled, or compiled separately and what specific version?


By: Peter Sokolov (peterdoo) 2017-04-26 16:42:08.170-0500

I am using Asterisk on Debian 8.7, built with
./configure --with-pjproject-bundled


By: Sean Bright (seanbright) 2020-01-15 19:23:58.395-0600

Can you tell me what UA is sending these malformed packets to Asterisk?

By: Linus Holzmann (siphony) 2020-01-15 21:28:24.320-0600

@sean bright

i got the brackets IPv6 Address in via line from a server:
{{{noformat}
Sipwise NGCP Proxy 7.X


[2020-01-16 04:07:30] ERROR[2031] pjproject: sip_transport. Error processing 693 bytes packet from TCP 2001:4090:4008::173:5060 : PJSIP syntax error exception when parsing 'Via' header on line 2 col 142:
SIP/2.0 401 Unauthorized
Via: SIP/2.0/TCP [XXXX:XXXX:XXXX:X:XXXX:XXXX:XXXX:XXXX]:5060;rport=51521;branch=a7kD0bBPj6952067c-3811-11ea-bd57-33d5de08ee68;alias;received=[XXXX:XXXX:XXXX:X:XXXX:XXXX:XXXX:XXXX]
From: <sip:XXXXXXXXXXXXXXX@ipv6.sip.easybell.de>;tag=7a12e788-3811-11ea-9289-2728c0f90438
To: <sip:XXXXXXXXXXXXXXX@ipv6.sip.easybell.de>;tag=88a048cc381111ea82ebfbb25023fbb6.7855
Call-ID: 5fdcace6-3811-11ea-80e5-cb1a04e79ebd
CSeq: 2952 REGISTER
P-NGCP-Auth-IP: 192.168.251.44
P-NGCP-Auth-UA: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
WWW-Authenticate: Digest realm="sip.easybell.de", nonce="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
Server: Sipwise NGCP Proxy 7.X
Content-Length: 0

{noformat}}}

By: Peter Sokolov (peterdoo) 2020-01-16 04:01:17.319-0600

All FritzBox models which is one of the most used routers for residential internet access in Germany is sending IPv6 address within brackets in Via: line.

By: Sean Bright (seanbright) 2020-01-16 09:27:43.234-0600

[~peterdoo] and/or [~siphony] - can you confirm that this still occurs with the latest Asterisk 16 release (16.7.0 at the time that I write this)?

By: Sean Bright (seanbright) 2020-01-16 10:09:12.608-0600

I have [a tentative patch against Asterisk 16 for this on Gerrit|https://gerrit.asterisk.org/c/asterisk/+/13599] but I am unable to test it. It is basically the suggestion made before by [~peterdoo]. If someone could test it and report back results, that would be great.

By: Peter Sokolov (peterdoo) 2020-01-31 11:41:49.159-0600

I have tested this patch on Asterisk 16.7.0. As you said, it basically does what I do by hand each time I install a new version.
With your patch applied, the SIP packets with IPv6 address within brackets in Via: line are received correctly by Asterisk and replied.

By: Friendly Automation (friendly-automation) 2020-02-07 07:06:11.842-0600

Change 13765 merged by Joshua Colp:
pjproject_bundled: Allow brackets in via parameters

[https://gerrit.asterisk.org/c/asterisk/+/13765|https://gerrit.asterisk.org/c/asterisk/+/13765]

By: Friendly Automation (friendly-automation) 2020-02-07 07:06:47.196-0600

Change 13766 merged by Joshua Colp:
pjproject_bundled: Allow brackets in via parameters

[https://gerrit.asterisk.org/c/asterisk/+/13766|https://gerrit.asterisk.org/c/asterisk/+/13766]

By: Friendly Automation (friendly-automation) 2020-02-07 07:07:02.494-0600

Change 13599 merged by Joshua Colp:
pjproject_bundled: Allow brackets in via parameters

[https://gerrit.asterisk.org/c/asterisk/+/13599|https://gerrit.asterisk.org/c/asterisk/+/13599]

By: Friendly Automation (friendly-automation) 2020-02-07 07:07:16.901-0600

Change 13767 merged by Joshua Colp:
pjproject_bundled: Allow brackets in via parameters

[https://gerrit.asterisk.org/c/asterisk/+/13767|https://gerrit.asterisk.org/c/asterisk/+/13767]

By: Alexander Traud (traud) 2020-12-20 07:14:03.489-0600

Although the problem was cured with PJProject, lesson learned, never forget to report such issues to the ‘other’ party as well:
* Easybell Germany fixed their issue in November.
* AVM fixed their issue with FRITZ!OS 7.
Unfortunately, AVM did not backport the fix to those FRITZ!Box still in support but on older branches. For example, a FRITZ!Box 7412 with FRITZ!OS 06.86 still faces this software bug today.

Therefore, a big thanks to the reporters and [~seanbright] driving this interoperability change into Asterisk.