Attempt to flatten the `BgpLayer` inheritance chain.
Overview
This PR is a draft attempt to flatten the inheritance chain of BgpLayer and separate the protocol layer parsing logic from the message payload parsing logic.
In the current implementation each BGP message has a dedicated derived BGP layer class. This introduces limitations where the message payload cannot be switched to a different type without destroying the layer object and creating a new one, requiring the layer to be extracted from the stack and then readded to it.
This PR aims to simplify the following operations by providing the following objects:
- "MessageView" proxies - thin wrappers over a
BgpLayerthat parse the payload as a specific message. They exist in two flavors "View" and "ConstView" with the former allowing in-place data modifications and the latter being read-only. - "Message" objects - lightweight struct objects that can be passed to the
BgpLayer's constructor or a dedicated method to completely replace the underlying message with a message of a different type. Similar to the ArpLayer's helper structs.
The "View" object
The view object is a thin wrapper over a BgpLayer that holds a reference to the layer it has been created from. It provides accessors and mutators for reading and writing message specific data directly to the underlying buffer. Each view is intended to be passed by value and should be no larger than a pointer (the reference to the BgpLayer), if possible.
Each view should maintain message integrity. During construction the View should validate a minimally viable message of the type can be parsed from the buffer. Full validation can be deferred until use of accessors and/or mutators of the view object.
BGP Layer Enhancements
Improved support of full length update message path attributes.
The previous version supported path attributes with data up to 32 bytes. The new PathAttribute class supports the full spectrum of variable data lengths a path attribute block can contain specified by RFC 4271 Section 4.3.
The attribute can support a data buffer of:
- standard length attribute - up to 255 bytes
- extended length attribute - unlimited, restricted by total message length of 4096 bytes.
Other enhancements
Addition of utility functions for enum class flags.
This PR adds the header EnumFlagUtils.h to the Common++ package. The header provides operators for bitwise operators and helper functions of enum class objects when they satisfy the trait EnableBitMaskOperators.
In addition the header defines the following macros:
-
PCPP_DECLARE_ENUM_FLAG- to enable the operators to be used for a class. -
PCPP_USING_ENUM_FLAG_OPERATORS- to declare aliases to all templated operators in the scope this macro is used to satisfy ADL.
Codecov Report
Attention: Patch coverage is 0% with 682 lines in your changes missing coverage. Please review.
Project coverage is 81.89%. Comparing base (
59d0b64) to head (7be7843). Report is 36 commits behind head on dev.
Additional details and impacted files
@@ Coverage Diff @@
## dev #1820 +/- ##
==========================================
- Coverage 84.10% 81.89% -2.21%
==========================================
Files 272 285 +13
Lines 47578 49691 +2113
Branches 10344 10548 +204
==========================================
+ Hits 40015 40695 +680
- Misses 6518 8209 +1691
+ Partials 1045 787 -258
| Flag | Coverage Δ | |
|---|---|---|
| alpine320 | 73.79% <0.00%> (-2.56%) |
:arrow_down: |
| fedora42 | 73.89% <0.00%> (-2.54%) |
:arrow_down: |
| macos-13 | 79.50% <0.00%> (-2.15%) |
:arrow_down: |
| macos-14 | 79.50% <0.00%> (-2.15%) |
:arrow_down: |
| macos-15 | 79.52% <0.00%> (-2.11%) |
:arrow_down: |
| mingw32 | 68.63% <0.00%> (-2.10%) |
:arrow_down: |
| mingw64 | 68.61% <0.00%> (-2.08%) |
:arrow_down: |
| npcap | 82.69% <0.00%> (-2.40%) |
:arrow_down: |
| rhel94 | 73.63% <0.00%> (-2.58%) |
:arrow_down: |
| ubuntu2004 | 57.68% <0.00%> (-1.59%) |
:arrow_down: |
| ubuntu2004-zstd | 57.81% <0.00%> (-1.46%) |
:arrow_down: |
| ubuntu2204 | 73.56% <0.00%> (-2.58%) |
:arrow_down: |
| ubuntu2204-icpx | 59.92% <0.00%> (-1.58%) |
:arrow_down: |
| ubuntu2404 | 73.84% <0.00%> (-2.63%) |
:arrow_down: |
| ubuntu2404-arm64 | 73.82% <0.00%> (-2.57%) |
:arrow_down: |
| unittest | 81.89% <0.00%> (-2.21%) |
:arrow_down: |
| windows-2019 | 82.72% <0.00%> (-2.38%) |
:arrow_down: |
| windows-2022 | 82.72% <0.00%> (-2.39%) |
:arrow_down: |
| winpcap | 82.86% <0.00%> (-2.39%) |
:arrow_down: |
| xdp | 49.71% <0.00%> (-2.78%) |
:arrow_down: |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
@seladb @tigercosmos @clementperon @egecetin Can I get some first impressions on the idea of this draft?
@Dimi1010 is it worth it to rewrite BgpLayer? 🤔
@Dimi1010 is it worth it to rewrite
BgpLayer? 🤔
Dunno yet. I have been mostly using it as a test bed for expanding the idea I had in the #1813 about ways it can allow direct read/write of fields of different payloads without having to decode and copy the entire buffer out.
@Dimi1010 Is it possible to split this PR? It seems the PR is too large to review.
@Dimi1010 Is it possible to split this PR? It seems the PR is too large to review.
Possibly, but this is still a WIP.
Might work on this later. Closing this for now so it doesn't clutter.