PcapPlusPlus  Next
MBufRawPacket.h
1 #pragma once
2 
3 // GCOVR_EXCL_START
4 
5 #include <time.h>
6 #include "Packet.h"
7 #include "PointerVector.h"
8 
9 struct rte_mbuf;
10 struct rte_mempool;
11 
14 namespace pcpp
15 {
16 
17  class DpdkDevice;
18 #ifdef USE_DPDK_KNI
19  class KniDevice;
20 #endif
21 
22 #define MBUFRAWPACKET_OBJECT_TYPE 1
23 
46  class MBufRawPacket : public RawPacket
47  {
48  friend class DpdkDevice;
49 #ifdef USE_DPDK_KNI
50  friend class KniDevice;
51 #endif
52 
53  protected:
54  struct rte_mbuf* m_MBuf;
55  struct rte_mempool* m_Mempool;
56  uint16_t m_MbufDataSize;
57  bool m_FreeMbuf;
58 
59  void setMBuf(struct rte_mbuf* mBuf, timespec timestamp);
60  bool init(struct rte_mempool* mempool);
61  bool initFromRawPacket(const RawPacket* rawPacket, struct rte_mempool* mempool);
62 
63  public:
68  MBufRawPacket() : RawPacket(), m_MBuf(nullptr), m_Mempool(nullptr), m_MbufDataSize(0), m_FreeMbuf(true)
69  {
70  m_OwnsRawData = false;
71  }
72 
75  virtual ~MBufRawPacket();
76 
82 
90  bool init(DpdkDevice* device);
91 
92 #ifdef USE_DPDK_KNI
100  bool init(KniDevice* device);
101 #endif
102 
112  bool initFromRawPacket(const RawPacket* rawPacket, DpdkDevice* device);
113 
114 #ifdef USE_DPDK_KNI
124  bool initFromRawPacket(const RawPacket* rawPacket, KniDevice* device);
125 #endif
126 
128  inline rte_mbuf* getMBuf()
129  {
130  return m_MBuf;
131  }
132 
133  // overridden methods
134 
139  PCPP_DEPRECATED("Deprecated due to unclear semantics.")
140  inline uint8_t getObjectType() const override
141  {
142  return MBUFRAWPACKET_OBJECT_TYPE;
143  }
144 
150 
154  MBufRawPacket* clone() const override;
155 
157  void clear() override;
158 
164  void appendData(const uint8_t* dataToAppend, size_t dataToAppendLen) override;
165 
173  void insertData(int atIndex, const uint8_t* dataToInsert, size_t dataToInsertLen) override;
174 
182  bool removeData(int atIndex, size_t numOfBytesToRemove) override;
183 
189  bool reallocateData(size_t newBufferLength) override;
190 
194  inline void setFreeMbuf(bool val = true)
195  {
196  m_FreeMbuf = val;
197  }
198 
199  protected:
201  {
202  return internal::RawPacketImplType::DpdkMBuf;
203  }
204 
222  bool doSetRawData(const uint8_t* pRawData, int rawDataLen, bool takeOwnership, timespec timestamp,
223  LinkLayerType layerType, int frameLength) override;
224  };
225 
229 
230 } // namespace pcpp
231 
232 // GCOVR_EXCL_STOP
RawPacketImplType
Type of RawPacket implementation.
Definition: RawPacket.h:267
Definition: DpdkDevice.h:168
Definition: KniDevice.h:116
Definition: MBufRawPacket.h:47
bool doSetRawData(const uint8_t *pRawData, int rawDataLen, bool takeOwnership, timespec timestamp, LinkLayerType layerType, int frameLength) override
bool initFromRawPacket(const RawPacket *rawPacket, DpdkDevice *device)
Initialize an instance of this class and copies the content of a RawPacket object....
MBufRawPacket(const MBufRawPacket &other)
internal::RawPacketImplType getImplType() const override
Get the type of RawPacket implementation.
Definition: MBufRawPacket.h:200
rte_mbuf * getMBuf()
Definition: MBufRawPacket.h:128
bool removeData(int atIndex, size_t numOfBytesToRemove) override
bool reallocateData(size_t newBufferLength) override
virtual ~MBufRawPacket()
void setFreeMbuf(bool val=true)
Definition: MBufRawPacket.h:194
MBufRawPacket * clone() const override
Clone this MBufRawPacket object. See copy constructor for details. The caller is responsible for the ...
uint8_t getObjectType() const override
Definition: MBufRawPacket.h:140
void appendData(const uint8_t *dataToAppend, size_t dataToAppendLen) override
bool init(DpdkDevice *device)
Initialize an instance of this class from DpdkDevice. Initialization includes allocating an mbuf from...
MBufRawPacket()
Definition: MBufRawPacket.h:68
MBufRawPacket & operator=(const MBufRawPacket &other)
void insertData(int atIndex, const uint8_t *dataToInsert, size_t dataToInsertLen) override
void clear() override
Clears the object and frees the mbuf.
Definition: PointerVector.h:50
Definition: RawPacket.h:290
The main namespace for the PcapPlusPlus lib.
Definition: AssertionUtils.h:19
LinkLayerType
An enum describing all known link layer type. Taken from: http://www.tcpdump.org/linktypes....
Definition: RawPacket.h:22