Skip to content

Use heuristic SIP parser by default.#2163

Draft
Dimi1010 wants to merge 4 commits into
seladb:devfrom
Dimi1010:sip/heuristics-by-default
Draft

Use heuristic SIP parser by default.#2163
Dimi1010 wants to merge 4 commits into
seladb:devfrom
Dimi1010:sip/heuristics-by-default

Conversation

@Dimi1010

Copy link
Copy Markdown
Collaborator

The PR deduplicates the parseSipLayer logic by removing the overload that takes a port src / dst pair.

The existing two parser overloads perform effectively identical, with the exception that the port based overload also requires a specific port combination. Port numbers by themselves should generally only be considered hints for the next layer type and not a parsing error by themselves. As such, they shouldn't be part of downstream parsers that validate the data contents. Instead they should only be used during parser dispatch to select the most likely parser candidate.

Dimi1010 added 3 commits June 21, 2026 10:11
The two parseSipLayer methods are functionally identical, except that the removed requires ports.
Port numbers by themselves should not invalidate a parse and should only be used as hints to determine which parser to try first.
@Dimi1010 Dimi1010 requested a review from seladb as a code owner June 21, 2026 07:25
@codecov

codecov Bot commented Jun 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.72%. Comparing base (edd69fb) to head (c5fb83d).
⚠️ Report is 1 commits behind head on dev.

Additional details and impacted files
@@           Coverage Diff           @@
##              dev    #2163   +/-   ##
=======================================
  Coverage   82.72%   82.72%           
=======================================
  Files         332      332           
  Lines       59807    59785   -22     
  Branches    12593    12579   -14     
=======================================
- Hits        49475    49457   -18     
+ Misses       8944     8939    -5     
- Partials     1388     1389    +1     
Flag Coverage Δ
23.11.6 7.32% <50.00%> (+0.03%) ⬆️
24.11.5 7.32% <50.00%> (+0.05%) ⬆️
25.11.1 7.28% <50.00%> (-0.04%) ⬇️
alpine320 76.86% <100.00%> (+<0.01%) ⬆️
fedora42 76.45% <100.00%> (-0.01%) ⬇️
macos-14 82.27% <100.00%> (+<0.01%) ⬆️
macos-15 82.26% <100.00%> (+<0.01%) ⬆️
mingw32 71.11% <100.00%> (-0.01%) ⬇️
mingw64 71.08% <100.00%> (+0.06%) ⬆️
npcap ?
rhel94 76.25% <100.00%> (-0.01%) ⬇️
ubuntu2204 76.26% <100.00%> (-0.01%) ⬇️
ubuntu2204-icpx 59.41% <100.00%> (+0.03%) ⬆️
ubuntu2404 76.55% <100.00%> (-0.03%) ⬇️
ubuntu2404-arm64 76.57% <100.00%> (+0.02%) ⬆️
ubuntu2604 76.46% <100.00%> (-0.01%) ⬇️
unittest 82.72% <100.00%> (+<0.01%) ⬆️
windows-2022 85.80% <100.00%> (+0.11%) ⬆️
windows-2025 85.54% <100.00%> (+0.12%) ⬆️
winpcap 85.83% <100.00%> (+0.20%) ⬆️
xdp 53.14% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@seladb

seladb commented Jun 25, 2026

Copy link
Copy Markdown
Owner

@Dimi1010 the port-based parser does less work compared to the heuristic parser: it checks the port first - if it seems like a request it only tries to parse the method and then determines it's a SIP request. If it seems like a response it only tries to parse the version and then determines it's a SIP response.

The heuristic parser parses the first 3 chars, but then if it seems like a request or a response it parses the entire first line which is more than only checking the method / version.

We had a long discussion in #2024 and decided to build these 2 parsers because in most cases SIP is identified by its port and we'd like to parse it faster in this case.

@Dimi1010

Copy link
Copy Markdown
Collaborator Author

@seladb I see. On closer look, I think version that parses the first line has a higher ceiling of optimization, tho.

  • The port is being checked twice in the port version. Once in UdpLayer / TcpLayer and once in parseSipLayer.
  • The first line is still parsed in its entirety even on the port based parser, it just happens in the SIP layer constructors.
    Since the heuristic parser already parses the entire first line, there is the option to directly forward it to the actual layer, instead of requiring a reparse. This should be less work overall instead of having to do the parsing twice (even partially).

@Dimi1010 Dimi1010 marked this pull request as draft June 25, 2026 07:10
@seladb

seladb commented Jun 25, 2026

Copy link
Copy Markdown
Owner

@Dimi1010 you're right that the first line is parse in the SIP layer constructors, but now with the 2 parsers the first line is actually parsed twice (one in the parser and then again in the constructor). I think that a better optimization could be lazy parsing of the first line, but I don't think it's going to be easy

@Dimi1010

Dimi1010 commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator Author

@seladb yeah, converted this to a draft for now because of that. I will try to implement the the reuse of the first line parse and then revisit. A lazy line parse could be better, but if the line is already needed to validate the parser, it might be of limited benefit.

@seladb

seladb commented Jun 25, 2026

Copy link
Copy Markdown
Owner

@Dimi1010 in the common case where the port is known, it might be better to lazy parse the first line. In the heuristic parser I agree it doesn't add anything because the first line parsing is needed to identify the layer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants