PcapPlusPlus  23.09
NflogLayer.h
Go to the documentation of this file.
1 #ifndef PACKETPP_NFLOG_LAYER
2 #define PACKETPP_NFLOG_LAYER
3 
4 #include "Layer.h"
5 #include "TLVData.h"
6 #include "GeneralUtils.h"
7 
9 
14 namespace pcpp
15 {
20 #pragma pack(push, 1)
21  struct nflog_header
22  {
24  uint8_t addressFamily;
26  uint8_t version;
28  uint16_t resourceId;
29  };
30 #pragma pack(pop)
31 
36  enum class NflogTlvType
37  {
39  NFULA_PACKET_HDR = 1,
41  NFULA_MARK = 2,
43  NFULA_TIMESTAMP = 3,
53  NFULA_HWADDR = 8,
55  NFULA_PAYLOAD = 9,
57  NFULA_PREFIX = 10,
59  NFULA_UID = 11,
61  NFULA_SEQ = 12,
63  NFULA_SEQ_GLOBAL = 13,
65  NFULA_GID = 14,
67  NFULA_HWTYPE = 15,
69  NFULA_HWHEADER = 16,
71  NFULA_HWLEN = 17,
72  };
73 
79  class NflogTlv
80  {
81  private:
82  struct NflogTLVRawData
83  {
85  uint16_t recordLen;
87  uint16_t recordType;
89  uint8_t recordValue[];
90  };
91  NflogTLVRawData* m_Data;
92  public:
97  explicit NflogTlv(uint8_t* recordRawData)
98  {
99  assign(recordRawData);
100  }
101 
105  size_t getTotalSize() const
106  {
107  // as in https://github.com/the-tcpdump-group/libpcap/blob/766b607d60d8038087b49fc4cf433dac3dcdb49c/pcap-util.c#L371-L374
108  return align<4>(m_Data->recordLen);
109  }
110 
115  void assign(uint8_t* recordRawData)
116  {
117  m_Data = (NflogTLVRawData*)recordRawData;
118  }
119 
123  bool isNull() const
124  {
125  return (m_Data == nullptr);
126  }
127 
131  uint16_t getType() const { return m_Data->recordType; }
132 
136  uint8_t* getRecordBasePtr() const { return (uint8_t*)m_Data; }
137 
141  uint8_t* getValue() const { return m_Data->recordValue; }
142  };
143 
148  class NflogLayer : public Layer
149  {
150  public:
157  NflogLayer(uint8_t* data, size_t dataLen, Packet* packet) : Layer(data, dataLen, NULL, packet) { m_Protocol = NFLOG; }
158 
159  ~NflogLayer() {}
160 
165  nflog_header* getNflogHeader() const { return (nflog_header*)m_Data; }
166 
171  uint8_t getFamily();
172 
178  uint8_t getVersion();
179 
184  uint16_t getResourceId();
185 
191  NflogTlv getTlvByType(NflogTlvType type) const;
192 
193  // implement abstract methods
194 
199  void parseNextLayer();
200 
204  size_t getHeaderLen() const;
205 
210 
211  std::string toString() const;
212 
214 
221  static bool isDataValid(const uint8_t* data, size_t dataLen);
222 
223  private:
224  uint8_t* getTlvsBasePtr() const { return m_Data + sizeof(nflog_header); }
225 
226  TLVRecordReader<NflogTlv> m_TlvReader;
227  };
228 
229 } // namespace pcpp
230 
231 #endif /* PACKETPP_NFLOG_LAYER */
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:333
const ProtocolType NFLOG
Definition: ProtocolType.h:298
Definition: ProtocolType.h:338
size_t getTotalSize() const
Definition: NflogLayer.h:105
Definition: Layer.h:70
Definition: Packet.h:26
uint8_t addressFamily
Definition: NflogLayer.h:24
bool isNull() const
Definition: NflogLayer.h:123
Definition: TLVData.h:217
void computeCalculateFields()
Definition: NflogLayer.h:209
NflogLayer(uint8_t *data, size_t dataLen, Packet *packet)
Definition: NflogLayer.h:157
uint8_t * getValue() const
Definition: NflogLayer.h:141
Definition: NflogLayer.h:148
uint16_t resourceId
Definition: NflogLayer.h:28
nflog_header * getNflogHeader() const
Definition: NflogLayer.h:165
uint8_t * getRecordBasePtr() const
Definition: NflogLayer.h:136
uint16_t getType() const
Definition: NflogLayer.h:131
uint8_t version
Definition: NflogLayer.h:26
void assign(uint8_t *recordRawData)
Definition: NflogLayer.h:115
Definition: NflogLayer.h:79
NflogTlv(uint8_t *recordRawData)
Definition: NflogLayer.h:97
OsiModelLayer getOsiModelLayer() const
Definition: NflogLayer.h:213
NflogTlvType
Definition: NflogLayer.h:36
Definition: NflogLayer.h:21