Skip to content

[WIP] General refactor of RawPacket to remove ambiguity in API and streamline logic. #1845

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 26 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0e8665a
Initial commit for general RawPacket refactor.
Dimi1010 Jun 5, 2025
c57fa31
Fixed casting to narrow int type from size_t for comparison.
Dimi1010 Jun 5, 2025
4938bed
Fixed shadowing of setPacketTimestamp overload.
Dimi1010 Jun 5, 2025
8c3ace4
Fixed setRawData not setting m_Reallocation allowed to true by default.
Dimi1010 Jun 5, 2025
f872862
Defaulted copy ctor and assignment for RawPacketBase as it conly cont…
Dimi1010 Jun 5, 2025
6c7071e
Updated usages of deprecated versions of setRawData.
Dimi1010 Jun 5, 2025
deb4bd2
Added BufferInfo struct to encapsulate a triplet of ptr, size and cap…
Dimi1010 Jun 5, 2025
cb0b318
Added deprecation warnings to old RawPacket constructors due to lack …
Dimi1010 Jun 5, 2025
9d8faea
Added specific method for taking read only rawData pointer from non-c…
Dimi1010 Jun 5, 2025
d190494
Fixed capacity being wrong on Copy policy.
Dimi1010 Jun 5, 2025
c8fa568
Cleaned up copy constructor and assignment to utilize existing methods.
Dimi1010 Jun 5, 2025
b81daa7
Swapped self check to guard clause.
Dimi1010 Jun 5, 2025
3ac560c
Removed copy of capacity as that is internal instance information spe…
Dimi1010 Jun 5, 2025
726b7fb
Fixed signed to unsigned conversion.
Dimi1010 Jun 5, 2025
1b11ae9
Updated raw packet constructor.
Dimi1010 Jun 5, 2025
1bf4bde
Simplified copy semantics.
Dimi1010 Jun 5, 2025
b3b4704
Add warning log level.
Dimi1010 Jun 7, 2025
aebc062
Added old behaviour of insertData with a warning message.
Dimi1010 Jun 7, 2025
2c2c555
Removed old copy method.
Dimi1010 Jun 7, 2025
fb8a3f3
Removed the need for separate RawPacketSet field.
Dimi1010 Jun 7, 2025
13c75c4
Removed unnessesary casts.
Dimi1010 Jun 7, 2025
7c1ca59
Changed Packet to utilize a pointer to IRawPacket.
Dimi1010 Jun 7, 2025
0981fd0
Added converting constructor from IRawPacket to RawPacket.
Dimi1010 Jun 10, 2025
2050777
Changed RawPacket pointers to IRawPacket pointers.
Dimi1010 Jun 10, 2025
8f6b99d
Wrapped raw new/delete to unique_ptr.
Dimi1010 Jun 10, 2025
9fd49f3
Fixed RawPacket copy ctor.
Dimi1010 Jun 10, 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
12 changes: 10 additions & 2 deletions Common++/header/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
// Allows for conditional removal of unwanted log calls at compile time.
#define PCPP_LOG_LEVEL_OFF 0
#define PCPP_LOG_LEVEL_ERROR 1
#define PCPP_LOG_LEVEL_INFO 2
#define PCPP_LOG_LEVEL_DEBUG 3
#define PCPP_LOG_LEVEL_WARN 2
#define PCPP_LOG_LEVEL_INFO 3
#define PCPP_LOG_LEVEL_DEBUG 4

// All log messages built via a PCPP_LOG_* macro below the PCPP_ACTIVE_LOG_LEVEL will be removed at compile time.
// Uses the PCPP_ACTIVE_LOG_LEVEL if it is defined, otherwise defaults to PCAP_LOG_LEVEL_DEBUG
Expand Down Expand Up @@ -146,6 +147,7 @@ namespace pcpp
{
Off = PCPP_LOG_LEVEL_OFF, ///< No log messages are emitted.
Error = PCPP_LOG_LEVEL_ERROR, ///< Error level logs are emitted.
Warn = PCPP_LOG_LEVEL_WARN, ///< Warning level logs and above are emitted.
Info = PCPP_LOG_LEVEL_INFO, ///< Info level logs and above are emitted.
Debug = PCPP_LOG_LEVEL_DEBUG ///< Debug level logs and above are emitted.
};
Expand Down Expand Up @@ -436,6 +438,12 @@ namespace pcpp
# define PCPP_LOG_INFO(message) (void)0
#endif

#if PCPP_ACTIVE_LOG_LEVEL >= PCPP_LOG_LEVEL_WARN
# define PCPP_LOG_WARN(message) PCPP_LOG(pcpp::LogLevel::Warn, message)
#else
# define PCPP_LOG_WARN(message) (void)0
#endif

#if PCPP_ACTIVE_LOG_LEVEL >= PCPP_LOG_LEVEL_ERROR
# define PCPP_LOG_ERROR(message) PCPP_LOG(pcpp::LogLevel::Error, message)
#else
Expand Down
2 changes: 1 addition & 1 deletion Packet++/header/IPReassembly.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ namespace pcpp
/// - If the input fragment is the last one and the reassembled packet is ready - a pointer to the reassembled
/// packet is returned. Notice it's the user's responsibility to free this pointer when done using it
/// - If the reassembled packet isn't ready then nullptr is returned
Packet* processPacket(RawPacket* fragment, ReassemblyStatus& status, ProtocolType parseUntil = UnknownProtocol,
Packet* processPacket(IRawPacket* fragment, ReassemblyStatus& status, ProtocolType parseUntil = UnknownProtocol,
OsiModelLayer parseUntilLayer = OsiModelLayerUnknown);

/// Get a partially reassembled packet. This method returns all the reassembled data that was gathered so far
Expand Down
16 changes: 8 additions & 8 deletions Packet++/header/Packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace pcpp
friend class Layer;

private:
RawPacket* m_RawPacket;
IRawPacket* m_RawPacket;
Layer* m_FirstLayer;
Layer* m_LastLayer;
size_t m_MaxPacketLen;
Expand Down Expand Up @@ -65,7 +65,7 @@ namespace pcpp
/// model (inclusive). Can be useful for cases when you need to parse only up to a certain OSI layer (for
/// example transport layer) and want to avoid the performance impact and memory consumption of parsing the
/// whole packet. Default value is ::OsiModelLayerUnknown which means don't take this parameter into account
explicit Packet(RawPacket* rawPacket, bool freeRawPacket = false, ProtocolType parseUntil = UnknownProtocol,
explicit Packet(IRawPacket* rawPacket, bool freeRawPacket = false, ProtocolType parseUntil = UnknownProtocol,
OsiModelLayer parseUntilLayer = OsiModelLayerUnknown);

/// A constructor for creating a packet out of already allocated RawPacket. Very useful when parsing packets
Expand All @@ -77,7 +77,7 @@ namespace pcpp
/// @param[in] parseUntil Parse the packet until you reach a certain protocol (inclusive). Can be useful for
/// cases when you need to parse only up to a certain layer and want to avoid the performance impact and memory
/// consumption of parsing the whole packet
explicit Packet(RawPacket* rawPacket, ProtocolType parseUntil);
explicit Packet(IRawPacket* rawPacket, ProtocolType parseUntil);

/// A constructor for creating a packet out of already allocated RawPacket. Very useful when parsing packets
/// that came from the network. When using this constructor a pointer to the RawPacket is saved (data isn't
Expand All @@ -88,7 +88,7 @@ namespace pcpp
/// @param[in] parseUntilFamily Parse the packet until you reach a certain protocol family (inclusive). Can be
/// useful for cases when you need to parse only up to a certain layer and want to avoid the performance impact
/// and memory consumption of parsing the whole packet
explicit Packet(RawPacket* rawPacket, ProtocolTypeFamily parseUntilFamily);
explicit Packet(IRawPacket* rawPacket, ProtocolTypeFamily parseUntilFamily);

/// A constructor for creating a packet out of already allocated RawPacket. Very useful when parsing packets
/// that came from the network. When using this constructor a pointer to the RawPacket is saved (data isn't
Expand All @@ -101,7 +101,7 @@ namespace pcpp
/// model (inclusive). Can be useful for cases when you need to parse only up to a certain OSI layer (for
/// example transport layer) and want to avoid the performance impact and memory consumption of parsing the
/// whole packet
explicit Packet(RawPacket* rawPacket, OsiModelLayer parseUntilLayer);
explicit Packet(IRawPacket* rawPacket, OsiModelLayer parseUntilLayer);

/// A destructor for this class. Frees all layers allocated by this instance (Notice: it doesn't free layers
/// that weren't allocated by this class, for example layers that were added by addLayer() or insertLayer() ).
Expand Down Expand Up @@ -130,7 +130,7 @@ namespace pcpp

/// Get a pointer to the Packet's RawPacket
/// @return A pointer to the Packet's RawPacket
RawPacket* getRawPacket() const
IRawPacket* getRawPacket() const
{
return m_RawPacket;
}
Expand All @@ -147,12 +147,12 @@ namespace pcpp
/// you need to parse only up to a certain layer and want to avoid the performance impact and memory consumption
/// of parsing the whole packet. Default value is ::OsiModelLayerUnknown which means don't take this parameter
/// into account
void setRawPacket(RawPacket* rawPacket, bool freeRawPacket, ProtocolTypeFamily parseUntil = UnknownProtocol,
void setRawPacket(IRawPacket* rawPacket, bool freeRawPacket, ProtocolTypeFamily parseUntil = UnknownProtocol,
OsiModelLayer parseUntilLayer = OsiModelLayerUnknown);

/// Get a pointer to the Packet's RawPacket in a read-only manner
/// @return A pointer to the Packet's RawPacket
const RawPacket* getRawPacketReadOnly() const
const IRawPacket* getRawPacketReadOnly() const
{
return m_RawPacket;
}
Expand Down
Loading
Loading