Skip to content
Draft
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
7175409
Added initial framework for Parser configuration.
Dimi1010 May 21, 2025
a37a63f
Added nullptr guard and a helper method fetching required rules.
Dimi1010 May 21, 2025
319ca9c
Renamed methods to tryGetPortRule and getPortRule.
Dimi1010 May 21, 2025
a54c67d
Merge remote-tracking branch 'upstream/dev' into feature/parser-config
Dimi1010 Jul 17, 2025
3c26962
Rework the port mapper.
Dimi1010 Jul 17, 2025
938c74e
Moved some functions to cpp file.
Dimi1010 Jul 17, 2025
bc94131
Merge remote-tracking branch 'upstream/dev' into feature/parser-config
Dimi1010 Jul 17, 2025
94084f8
Fixed parser memory leak false positive.
Dimi1010 Jul 17, 2025
c7b79bf
Moved default factories to cpp file.
Dimi1010 Jul 17, 2025
7252620
Convert HTTP implementation to use PortMapper.
Dimi1010 Jul 17, 2025
9652a06
Lint
Dimi1010 Jul 17, 2025
1682e4b
Added helper method to reset the default config/
Dimi1010 Jul 17, 2025
89ca885
Added explicit cast to uint32_t in hash function.
Dimi1010 Jul 17, 2025
216accc
Added documentation.
Dimi1010 Jul 17, 2025
deb3e2e
Added method returning a match matrix instead of a single port.
Dimi1010 Jul 18, 2025
855e7df
Added port mappings from TCP Layer.
Dimi1010 Jul 18, 2025
e5b9f9c
Fixed SIP mappings.
Dimi1010 Jul 18, 2025
78071f3
Fixed recursion error.
Dimi1010 Jul 18, 2025
ea10b97
Lint
Dimi1010 Jul 18, 2025
a6ba392
Fixed warn / update execution order.
Dimi1010 Jul 18, 2025
e3c1876
Add port mappings from UDP Layer.
Dimi1010 Jul 18, 2025
8f4f3b5
Lint
Dimi1010 Jul 18, 2025
f5ff15b
Added member methods to PortPair to create a new pair from only one s…
Dimi1010 Jul 18, 2025
5d2df59
Extended the mapping to work with protocol families.
Dimi1010 Jul 20, 2025
5a60efa
Updated port mapping for GTPv2 to GTP
Dimi1010 Jul 20, 2025
e77dc46
Added utility function for quering port pair matrix.
Dimi1010 Jul 20, 2025
90bb410
Added todo.
Dimi1010 Jul 20, 2025
18f02a2
Merged SIP port rules to SIP family.
Dimi1010 Jul 20, 2025
08f67cd
Updated UDPLayer to utilize the dynamic protocol mapper.
Dimi1010 Jul 20, 2025
d6cdddd
Fixed SomeIP test
Dimi1010 Jul 20, 2025
d134241
Lint
Dimi1010 Jul 20, 2025
a890e74
Merge remote-tracking branch 'upstream/dev' into feature/parser-config
Dimi1010 Jul 20, 2025
800789f
Fix docs.
Dimi1010 Jul 20, 2025
a23b41b
Fix explicit ctor.
Dimi1010 Jul 20, 2025
6fe00cd
Docs fix.
Dimi1010 Jul 20, 2025
25bc58a
Changed getProtocolByPortPair to only check exact matches.
Dimi1010 Jul 20, 2025
27e7942
todo change
Dimi1010 Jul 20, 2025
21c3b95
Merge remote-tracking branch 'upstream/dev' into feature/parser-config
Dimi1010 Jul 22, 2025
ef5ca85
Fixed leftover parameter.
Dimi1010 Jul 22, 2025
067364d
Expanded PortPair to allow port 0 as a valid port.
Dimi1010 Jul 22, 2025
0dc3573
Merge remote-tracking branch 'upstream/dev' into feature/parser-config
Dimi1010 Jul 24, 2025
a89eadb
Fixed PortPair equalify operator.
Dimi1010 Jul 24, 2025
bd3ca9a
Added inequality operator.
Dimi1010 Jul 24, 2025
1dd6bbe
Enabled WakeOnLan port 0 mapping.
Dimi1010 Jul 24, 2025
6da2493
Changed comparePort to static helper.
Dimi1010 Jul 24, 2025
04a6a94
Merge remote-tracking branch 'upstream/dev' into feature/parser-config
Dimi1010 Jul 26, 2025
4be73ef
Fixed withAnySrc and withAnyDst not respecting port set flags.
Dimi1010 Jul 26, 2025
96297b5
Added constructor that takes anyport + anyport.
Dimi1010 Jul 26, 2025
63ab500
Merge branch 'dev' into feature/parser-config
Dimi1010 Aug 10, 2025
d828452
Fix parseNextLayer params in DoIP layer.
Dimi1010 Aug 10, 2025
c0b6ebd
Added DoIP mappings to default mapper.
Dimi1010 Aug 10, 2025
be81263
Added dedicated benchmark target.
Dimi1010 Aug 10, 2025
ff12269
Disabled mix of hash function.
Dimi1010 Aug 10, 2025
f8a3834
Added second port pair to benchmark.
Dimi1010 Aug 10, 2025
61fd2f8
Merge branch 'dev' into feature/parser-config
Dimi1010 Aug 14, 2025
da22e56
Renamed to getMatchMatrix.
Dimi1010 Aug 14, 2025
6d73cca
Removed portmapper namespace.
Dimi1010 Aug 14, 2025
280f6b4
Fixed mappings to FTPControl and FTPData.
Dimi1010 Aug 14, 2025
299db80
Merge branch 'dev' into feature/parser-config
Dimi1010 Sep 27, 2025
15ed36f
Converted `parseNextLayer` to static dispatch. Added protected `doPar…
Dimi1010 Sep 27, 2025
2a5fe39
Lint.
Dimi1010 Sep 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Packet++/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ add_library(
src/Packet.cpp
src/PacketTrailerLayer.cpp
src/PacketUtils.cpp
src/ParserConfig.cpp
src/PayloadLayer.cpp
src/PPPoELayer.cpp
src/RadiusLayer.cpp
Expand Down Expand Up @@ -111,6 +112,7 @@ set(
header/Packet.h
header/PacketTrailerLayer.h
header/PacketUtils.h
header/ParserConfig.h
header/PayloadLayer.h
header/PPPoELayer.h
header/ProtocolType.h
Expand Down
2 changes: 1 addition & 1 deletion Packet++/header/ArpLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ namespace pcpp
// implement abstract methods

/// Does nothing for this layer (ArpLayer is always last)
void parseNextLayer() override
void parseNextLayer(ParserConfiguration const& config) override
{}

/// @return The size of @ref arphdr
Expand Down
2 changes: 1 addition & 1 deletion Packet++/header/BgpLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ namespace pcpp

/// Multiple BGP messages can reside in a single packet, and the only layer that can come after a BGP message
/// is another BGP message. This method checks for remaining data and parses it as another BGP layer
void parseNextLayer() override;
void parseNextLayer(ParserConfiguration const& config) override;

std::string toString() const override;

Expand Down
2 changes: 1 addition & 1 deletion Packet++/header/CiscoHdlcLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ namespace pcpp
void computeCalculateFields() override;

/// Parses the next layer. Currently, supports IPv4 and IPv6
void parseNextLayer() override;
void parseNextLayer(ParserConfiguration const& config) override;

std::string toString() const override;

Expand Down
2 changes: 1 addition & 1 deletion Packet++/header/CotpLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace pcpp
{}

/// Currently parses the rest of the packet as a S7COMM or generic payload (PayloadLayer)
void parseNextLayer() override;
void parseNextLayer(ParserConfiguration const& config) override;

/// A static method that takes a byte array and detects whether it is a COTP
/// @param[in] data A byte array
Expand Down
2 changes: 1 addition & 1 deletion Packet++/header/DhcpLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ namespace pcpp
// implement abstract methods

/// Does nothing for this layer (DhcpLayer is always last)
void parseNextLayer() override
void parseNextLayer(ParserConfiguration const& config) override
{}

/// @return The size of @ref dhcp_header + size of options
Expand Down
2 changes: 1 addition & 1 deletion Packet++/header/DhcpV6Layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ namespace pcpp
// implement abstract methods

/// Does nothing for this layer (DhcpV6Layer is always last)
void parseNextLayer() override
void parseNextLayer(ParserConfiguration const& config) override
{}

/// @return The size of @ref dhcpv6_header + size of options
Expand Down
2 changes: 1 addition & 1 deletion Packet++/header/DnsLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ namespace pcpp
// implement abstract methods

/// Does nothing for this layer (DnsLayer is always last)
void parseNextLayer() override
void parseNextLayer(ParserConfiguration const& config) override
{}

/// @return The size of the DNS data in the packet including he DNS header and size of all queries, answers,
Expand Down
2 changes: 1 addition & 1 deletion Packet++/header/EthDot3Layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ namespace pcpp
// implement abstract methods

/// Parses next layer
void parseNextLayer() override;
void parseNextLayer(ParserConfiguration const& config) override;

/// @return Size of ether_dot3_header
size_t getHeaderLen() const override
Expand Down
2 changes: 1 addition & 1 deletion Packet++/header/EthLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ namespace pcpp

/// Currently identifies the following next layers: IPv4Layer, IPv6Layer, ArpLayer, VlanLayer,
/// PPPoESessionLayer, PPPoEDiscoveryLayer, MplsLayer. Otherwise sets PayloadLayer
void parseNextLayer() override;
void parseNextLayer(ParserConfiguration const& config) override;

/// @return Size of ether_header
size_t getHeaderLen() const override
Expand Down
2 changes: 1 addition & 1 deletion Packet++/header/FtpLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace pcpp
// overridden methods

/// FTP is the always last so does nothing for this layer
void parseNextLayer() override
void parseNextLayer(ParserConfiguration const& config) override
{}

/// @return Get the size of the layer
Expand Down
4 changes: 2 additions & 2 deletions Packet++/header/GreLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ namespace pcpp
/// Currently identifies the following next layers:
/// IPv4Layer, IPv6Layer, VlanLayer, MplsLayer, PPP_PPTPLayer, EthLayer, EthDot3Layer
/// Otherwise sets PayloadLayer
void parseNextLayer() override;
void parseNextLayer(ParserConfiguration const& config) override;

/// @return Size of GRE header (may change if optional fields are added or removed)
size_t getHeaderLen() const override;
Expand Down Expand Up @@ -368,7 +368,7 @@ namespace pcpp
// implement abstract methods

/// Currently identifies the following next layers: IPv4Layer, IPv6Layer. Otherwise sets PayloadLayer
void parseNextLayer() override;
void parseNextLayer(ParserConfiguration const& config) override;

/// @return The size of @ref ppp_pptp_header
size_t getHeaderLen() const override
Expand Down
4 changes: 2 additions & 2 deletions Packet++/header/GtpLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ namespace pcpp
// implement abstract methods

/// Identifies the following next layers for GTP-U packets: IPv4Layer, IPv6Layer. Otherwise sets PayloadLayer
void parseNextLayer() override;
void parseNextLayer(ParserConfiguration const& config) override;

/// @return The size of the GTP header. For GTP-C packets the size is determined by the value of
/// gtpv1_header#messageLength and for GTP-U the size only includes the GTP header itself (meaning
Expand Down Expand Up @@ -1099,7 +1099,7 @@ namespace pcpp
// implement abstract methods

/// Identifies if the next layer is GTPv2 piggyback. Otherwise sets PayloadLayer
void parseNextLayer() override;
void parseNextLayer(ParserConfiguration const& config) override;

/// @return The size of the GTPv2 header including its Information Elements (IE)
size_t getHeaderLen() const override;
Expand Down
4 changes: 2 additions & 2 deletions Packet++/header/IPSecLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ namespace pcpp

/// Currently identifies the following next layers: UdpLayer, TcpLayer, IPv4Layer, IPv6Layer and ESPLayer.
/// Otherwise sets PayloadLayer
void parseNextLayer() override;
void parseNextLayer(ParserConfiguration const& config) override;

/// Does nothing for this layer
void computeCalculateFields() override
Expand Down Expand Up @@ -152,7 +152,7 @@ namespace pcpp
}

/// The payload of an ESP layer is encrypted, hence the next layer is always a generic payload (PayloadLayer)
void parseNextLayer() override;
void parseNextLayer(ParserConfiguration const& config) override;

/// Does nothing for this layer
void computeCalculateFields() override
Expand Down
2 changes: 1 addition & 1 deletion Packet++/header/IPv4Layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ namespace pcpp
/// - ESPLayer (IPSec)
///
/// Otherwise sets PayloadLayer
void parseNextLayer() override;
void parseNextLayer(ParserConfiguration const& config) override;

/// @return Size of IPv4 header (including IPv4 options if exist)
size_t getHeaderLen() const override
Expand Down
2 changes: 1 addition & 1 deletion Packet++/header/IPv6Layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ namespace pcpp
/// - ESPLayer (IPSec)
///
/// Otherwise sets PayloadLayer
void parseNextLayer() override;
void parseNextLayer(ParserConfiguration const& config) override;

/// @return Size of @ref ip6_hdr
size_t getHeaderLen() const override
Expand Down
2 changes: 1 addition & 1 deletion Packet++/header/IcmpLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ namespace pcpp
/// ICMP messages of types: ICMP_DEST_UNREACHABLE, ICMP_SOURCE_QUENCH, ICMP_TIME_EXCEEDED, ICMP_REDIRECT,
/// ICMP_PARAM_PROBLEM have data that contains IPv4 header and some L4 header (TCP/UDP/ICMP). This method parses
/// these headers as separate layers on top of the ICMP layer
void parseNextLayer() override;
void parseNextLayer(ParserConfiguration const& config) override;

/// @return The ICMP header length. This length varies according to the ICMP message type. This length doesn't
/// include IPv4 and L4 headers in case ICMP message type are: ICMP_DEST_UNREACHABLE, ICMP_SOURCE_QUENCH,
Expand Down
2 changes: 1 addition & 1 deletion Packet++/header/IcmpV6Layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ namespace pcpp
uint16_t getChecksum() const;

/// Does nothing for this layer. ICMPv6 is the last layer.
void parseNextLayer() override
void parseNextLayer(ParserConfiguration const& config) override
{}

/// @return The size of the ICMPv6 message
Expand Down
2 changes: 1 addition & 1 deletion Packet++/header/IgmpLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ namespace pcpp
// implement abstract methods

/// Does nothing for this layer (IGMP layer is always last)
void parseNextLayer() override
void parseNextLayer(ParserConfiguration const& config) override
{}

/// @return Size of IGMP header = 8B
Expand Down
2 changes: 1 addition & 1 deletion Packet++/header/LLCLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace pcpp
// overridden methods

/// Parses the next layer. Currently only STP supported as next layer
void parseNextLayer() override;
void parseNextLayer(ParserConfiguration const& config) override;

/// Does nothing for this layer
void computeCalculateFields() override
Expand Down
8 changes: 7 additions & 1 deletion Packet++/header/Layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <stdint.h>
#include <stdio.h>
#include "ProtocolType.h"
#include "ParserConfig.h"
#include <string>
#include <stdexcept>
#include <utility>
Expand Down Expand Up @@ -142,7 +143,12 @@ namespace pcpp
// abstract methods

/// Each layer is responsible for parsing the next layer
virtual void parseNextLayer() = 0;
void parseNextLayer()
{
parseNextLayer(ParserConfiguration::getDefault());
}

virtual void parseNextLayer(ParserConfiguration const& config) = 0;

/// @return The header length in bytes
virtual size_t getHeaderLen() const = 0;
Expand Down
2 changes: 1 addition & 1 deletion Packet++/header/LdapLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ namespace pcpp
// implement abstract methods

/// Tries to identify more LDAP messages in this packet if exist
void parseNextLayer() override;
void parseNextLayer(ParserConfiguration const& config) override;

/// @return The size of the LDAP message
size_t getHeaderLen() const override
Expand Down
2 changes: 1 addition & 1 deletion Packet++/header/MplsLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ namespace pcpp
// implement abstract methods

/// Currently identifies the following next layers: IPv4Layer, IPv6Layer, MplsLayer. Otherwise sets PayloadLayer
void parseNextLayer() override;
void parseNextLayer(ParserConfiguration const& config) override;

/// @return Size of MPLS header (4 bytes)
size_t getHeaderLen() const override
Expand Down
2 changes: 1 addition & 1 deletion Packet++/header/NflogLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ namespace pcpp

/// Currently identifies the following next layers: IPv4Layer, IPv6Layer using address family
/// Otherwise sets PayloadLayer
void parseNextLayer() override;
void parseNextLayer(ParserConfiguration const& config) override;

/// @return Size of nflog_header
size_t getHeaderLen() const override;
Expand Down
2 changes: 1 addition & 1 deletion Packet++/header/NtpLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ namespace pcpp
// overridden methods

/// Parses the next layer. NTP is the always last so does nothing for this layer
void parseNextLayer() override
void parseNextLayer(ParserConfiguration const& config) override
{}

/// @return Get the size of the layer (Including the extension and authentication fields if exists)
Expand Down
2 changes: 1 addition & 1 deletion Packet++/header/NullLoopbackLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace pcpp
/// - for ::PCPP_BSD_AF_INET6_BSD, ::PCPP_BSD_AF_INET6_FREEBSD, ::PCPP_BSD_AF_INET6_DARWIN the next layer is
/// IPv6Layer
/// - for other values the next layer in PayloadLayer (unknown protocol)
void parseNextLayer() override;
void parseNextLayer(ParserConfiguration const& config) override;

/// @return Size of Null/Loopback header = 4B
size_t getHeaderLen() const override
Expand Down
4 changes: 2 additions & 2 deletions Packet++/header/PPPoELayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ namespace pcpp
// abstract methods implementation

/// Currently identifies the following next layers: IPv4Layer, IPv6Layer. Otherwise sets PayloadLayer
void parseNextLayer() override;
void parseNextLayer(ParserConfiguration const& config) override;

/// @return Size of @ref pppoe_header
size_t getHeaderLen() const override
Expand Down Expand Up @@ -350,7 +350,7 @@ namespace pcpp
// abstract methods implementation

/// Does nothing for this layer (PPPoE discovery is always the last layer)
void parseNextLayer() override
void parseNextLayer(ParserConfiguration const& config) override
{}

/// @return The header length which is size of strcut pppoe_header plus the total size of tags
Expand Down
2 changes: 1 addition & 1 deletion Packet++/header/PacketTrailerLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace pcpp
// implement abstract methods

/// Does nothing for this layer (PacketTrailerLayer is always last)
void parseNextLayer() override
void parseNextLayer(ParserConfiguration const& config) override
{}

/// @return trailer data length in bytes
Expand Down
Loading
Loading