PcapPlusPlus  Next
pcpp::GeneveLayer Class Reference

#include <GeneveLayer.h>

Inheritance diagram for pcpp::GeneveLayer:
pcpp::Layer pcpp::IDataContainer

Classes

struct  SerializedFields
 

Public Member Functions

 GeneveLayer (uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
 
 GeneveLayer (uint32_t vni=0, uint16_t protocolType=0x6558, bool oamFlag=false)
 
uint32_t getVNI () const
 
void setVNI (uint32_t vni)
 
uint16_t getProtocolType () const
 
void setProtocolType (uint16_t protocolType)
 
bool getOamFlag () const
 
void setOamFlag (bool value)
 
bool getCriticalFlag () const
 
size_t getOptionsLength () const
 
size_t getOptionCount () const
 
GeneveOption getFirstOption () const
 
GeneveOption getNextOption (const GeneveOption &option) const
 
GeneveOption getOption (uint16_t optionClass, uint8_t optionType) const
 
bool addOption (uint16_t optionClass, uint8_t optionType, const uint8_t *optionData, size_t optionDataLen, bool critical=false)
 
bool removeOption (uint16_t optionClass, uint8_t optionType)
 
bool removeAllOptions ()
 
void parseNextLayer () override
 
size_t getHeaderLen () const override
 
void computeCalculateFields () override
 Update the Protocol Type and Critical flag from the following layer and options.
 
std::string toString () const override
 
OsiModelLayer getOsiModelLayer () const override
 
- Public Member Functions inherited from pcpp::Layer
 ~Layer () override
 
Layer * getNextLayer () const
 
Layer * getPrevLayer () const
 
ProtocolType getProtocol () const
 
bool isMemberOfProtocolFamily (ProtocolTypeFamily protocolTypeFamily) const
 
uint8_t * getData () const
 
size_t getDataLen () const
 
uint8_t * getLayerPayload () const
 
size_t getLayerPayloadSize () const
 
bool isAllocatedToPacket () const
 
void copyData (uint8_t *toArr) const
 Copy the raw data of this layer to another array. More...
 
size_t copyData (uint8_t *dest, size_t destSize) const
 Copy the raw data of this layer to another array, with a specified maximum size. More...
 
void serialize (ISerializer &serializer) const
 
uint8_t * getDataPtr (size_t offset=0) const override
 

Static Public Member Functions

static bool isDataValid (const uint8_t *data, size_t dataLen)
 
static bool isGenevePort (uint16_t port)
 

Static Public Attributes

static constexpr uint16_t DefaultPort = 6081
 The IANA-assigned UDP destination port for GENEVE.
 

Protected Member Functions

void serializeLayer (ObjectScope &serializer) const override
 
- Protected Member Functions inherited from pcpp::Layer
Packet * getAttachedPacket ()
 Get a pointer to the Packet this layer is attached to (if any). More...
 
Packet const * getAttachedPacket () const
 Get a pointer to the Packet this layer is attached to (if any). More...
 
void allocData (size_t dataLen, bool zeroInit=true)
 Requests the layer to allocate a new data buffer of the specified length. More...
 
template<typename T , typename... Args>
Layer * constructNextLayer (uint8_t *data, size_t dataLen, Args &&... extraArgs)
 Construct the next layer in the protocol stack. No validation is performed on the data. More...
 
template<typename T , typename... Args>
Layer * constructNextLayer (uint8_t *data, size_t dataLen, Packet *packet, Args &&... extraArgs)
 
template<typename TFactory , typename... Args>
Layer * constructNextLayerFromFactory (TFactory factoryFn, uint8_t *data, size_t dataLen, Args &&... extraArgs)
 Construct the next layer in the protocol stack using a factory functor. More...
 
template<typename TFactory , typename... Args>
Layer * constructNextLayerFromFactory (TFactory factoryFn, uint8_t *data, size_t dataLen, Packet *packet, Args &&... extraArgs)
 Construct the next layer in the protocol stack using a factory functor. More...
 
template<typename T , typename... Args>
Layer * tryConstructNextLayer (uint8_t *data, size_t dataLen, Args &&... extraArgs)
 
template<typename T , typename... Args>
Layer * tryConstructNextLayer (uint8_t *data, size_t dataLen, Packet *packet, Args &&... extraArgs)
 
template<typename T , typename TFallback , typename... Args>
Layer * tryConstructNextLayerWithFallback (uint8_t *data, size_t dataLen, Args &&... extraArgs)
 Try to construct the next layer in the protocol stack with a fallback option. More...
 
template<typename T , typename TFallback , typename... Args>
Layer * tryConstructNextLayerWithFallback (uint8_t *data, size_t dataLen, Packet *packet, Args &&... extraArgs)
 
template<typename TFallback , typename TFactory , typename... Args>
Layer * tryConstructNextLayerFromFactoryWithFallback (TFactory factoryFn, uint8_t *data, size_t dataLen, Args &&... extraArgs)
 Try to construct the next layer in the protocol stack using a factory functor with a fallback option. More...
 
template<typename TFallback , typename TFactory , typename... Args>
Layer * tryConstructNextLayerFromFactoryWithFallback (TFactory factoryFn, uint8_t *data, size_t dataLen, Packet *packet, Args &&... extraArgs)
 Try to construct the next layer in the protocol stack using a factory functor with a fallback option. More...
 

Additional Inherited Members

- Static Protected Member Functions inherited from pcpp::Layer
template<typename T >
static bool canReinterpretAs (const uint8_t *data, size_t dataLen)
 Check if the data is large enough to reinterpret as a type. More...
 

Detailed Description

Represents a GENEVE (Generic Network Virtualization Encapsulation) protocol layer. Layer methods assume that the fixed header and its declared options area are complete. Data passed to the raw-data constructor must first pass isDataValid(); crafted layers establish this layout internally. Callers modifying raw layer data must preserve this layout. Individual options may still be malformed and are checked during traversal.

Constructor & Destructor Documentation

◆ GeneveLayer() [1/2]

pcpp::GeneveLayer::GeneveLayer ( uint8_t *  data,
size_t  dataLen,
Layer *  prevLayer,
Packet *  packet 
)
inline

Construct a layer from existing packet data

Parameters
[in]dataA pointer to the raw data
[in]dataLenSize of the data in bytes
[in]prevLayerA pointer to the previous layer
[in]packetA pointer to the Packet instance where the layer is stored
Note
This constructor does not validate the input. The caller must ensure isDataValid(data, dataLen) returns true before calling it.

◆ GeneveLayer() [2/2]

pcpp::GeneveLayer::GeneveLayer ( uint32_t  vni = 0,
uint16_t  protocolType = 0x6558,
bool  oamFlag = false 
)
explicit

Construct a new GENEVE layer

Parameters
[in]vniThe 24-bit virtual network identifier
[in]protocolTypeEtherType of the encapsulated protocol. Defaults to Transparent Ethernet Bridging
[in]oamFlagSet the operations, administration, and maintenance flag

Member Function Documentation

◆ addOption()

bool pcpp::GeneveLayer::addOption ( uint16_t  optionClass,
uint8_t  optionType,
const uint8_t *  optionData,
size_t  optionDataLen,
bool  critical = false 
)

Add an option after all existing options. Option data is padded with zeroes to a 4-byte boundary.

Parameters
[in]optionClassOption namespace assigned by IANA
[in]optionTypeThe 7-bit option type
[in]optionDataA read-only buffer containing option data
[in]optionDataLenOption data length in bytes. The maximum supported length is 124 bytes
[in]criticalSet the option critical bit
Returns
True if the option was added successfully

◆ getCriticalFlag()

bool pcpp::GeneveLayer::getCriticalFlag ( ) const
Returns
True if the GENEVE critical options flag is set

◆ getFirstOption()

GeneveOption pcpp::GeneveLayer::getFirstOption ( ) const
Returns
The first option, or a null option if no complete option is available

◆ getHeaderLen()

size_t pcpp::GeneveLayer::getHeaderLen ( ) const
overridevirtual
Returns
The fixed header plus the declared options length

Implements pcpp::Layer.

◆ getNextOption()

GeneveOption pcpp::GeneveLayer::getNextOption ( const GeneveOption &  option) const

Get the option following a previous option.

Parameters
[in]optionAn option previously returned by this layer
Returns
The next option, or a null option if the input is null, malformed, doesn't belong to this layer, is the last option, or the next option is malformed

◆ getOamFlag()

bool pcpp::GeneveLayer::getOamFlag ( ) const
Returns
True if the GENEVE OAM flag is set

◆ getOption()

GeneveOption pcpp::GeneveLayer::getOption ( uint16_t  optionClass,
uint8_t  optionType 
) const

Find the first option with the given class and type.

Parameters
[in]optionClassOption namespace assigned by IANA
[in]optionTypeThe 7-bit option type
Returns
The matching option, or a null option if it is not present or traversal reaches malformed data

◆ getOptionCount()

size_t pcpp::GeneveLayer::getOptionCount ( ) const
Returns
Number of options that can be traversed safely before malformed data, in this layer

◆ getOptionsLength()

size_t pcpp::GeneveLayer::getOptionsLength ( ) const
Returns
Total options length in bytes declared by the fixed header

◆ getOsiModelLayer()

OsiModelLayer pcpp::GeneveLayer::getOsiModelLayer ( ) const
inlineoverridevirtual
Returns
The OSI Model layer this protocol belongs to

Implements pcpp::Layer.

◆ getProtocolType()

uint16_t pcpp::GeneveLayer::getProtocolType ( ) const
Returns
Encapsulated protocol EtherType in host byte order

◆ getVNI()

uint32_t pcpp::GeneveLayer::getVNI ( ) const
Returns
The VNI in host byte order

◆ isDataValid()

static bool pcpp::GeneveLayer::isDataValid ( const uint8_t *  data,
size_t  dataLen 
)
static

Validate the fixed GENEVE header and its declared options area.

Parameters
[in]dataThe beginning of the GENEVE header
[in]dataLenAvailable bytes
Returns
True if the fixed header is supported and the declared options area fits in dataLen
Note
This is a fast-path check and does not parse individual options. Option accessors take into account that the data might be malformed and return a null option when an option cannot be read safely.

◆ isGenevePort()

static bool pcpp::GeneveLayer::isGenevePort ( uint16_t  port)
inlinestatic

Check whether a UDP port is the standard GENEVE destination port

Parameters
[in]portUDP port in host byte order
Returns
True for port 6081

◆ parseNextLayer()

void pcpp::GeneveLayer::parseNextLayer ( )
overridevirtual

Parse the encapsulated protocol according to the Protocol Type field. Supported next layers are IPv4, ARP, IPv6, VLAN/QinQ, MPLS, Ethernet and EthernetDot3; unsupported or malformed payloads are represented as a generic PayloadLayer.

Implements pcpp::Layer.

◆ removeAllOptions()

bool pcpp::GeneveLayer::removeAllOptions ( )

Remove all options

Returns
True if all options were removed

◆ removeOption()

bool pcpp::GeneveLayer::removeOption ( uint16_t  optionClass,
uint8_t  optionType 
)

Remove the first option matching a class and type

Parameters
[in]optionClassOption class in host byte order
[in]optionTypeThe 7-bit option type
Returns
True if an option was found and removed

◆ serializeLayer()

void pcpp::GeneveLayer::serializeLayer ( ObjectScope &  serializer) const
overrideprotectedvirtual

Serializes the layer's data into a provided serializer object. This is used for generating serialized representations (like JSON) of the packet layers. This method should be overridden by derived layers to provide specific serialization logic.

Parameters
[in]serializerThe object scope serializer to which the layer details should be written.

Reimplemented from pcpp::Layer.

◆ setOamFlag()

void pcpp::GeneveLayer::setOamFlag ( bool  value)

Set the GENEVE OAM flag

Parameters
[in]valueWhether to set the OAM flag

◆ setProtocolType()

void pcpp::GeneveLayer::setProtocolType ( uint16_t  protocolType)

Set the encapsulated protocol EtherType

Parameters
[in]protocolTypeEtherType in host byte order

◆ setVNI()

void pcpp::GeneveLayer::setVNI ( uint32_t  vni)

Set the VNI. Only the least significant 24 bits are used

Parameters
[in]vniThe VNI to set

◆ toString()

std::string pcpp::GeneveLayer::toString ( ) const
overridevirtual
Returns
A string representation of the layer most important data (should look like the layer description in Wireshark)

Implements pcpp::Layer.