PcapPlusPlus  21.11
IPSecLayer.h
Go to the documentation of this file.
1 #ifndef PACKETPP_IPSEC_LAYER
2 #define PACKETPP_IPSEC_LAYER
3 
5 
6 #include "Layer.h"
7 
12 namespace pcpp
13 {
18 #pragma pack(push, 1)
20  {
22  uint8_t nextHeader;
24  uint8_t payloadLen;
26  uint16_t reserved;
28  uint32_t spi;
30  uint32_t sequenceNumber;
31  };
32 #pragma pack(pop)
33 
38 #pragma pack(push, 1)
39  struct ipsec_esp
40  {
42  uint32_t spi;
44  uint32_t sequenceNumber;
45  };
46 #pragma pack(pop)
47 
53  {
54  public:
61  AuthenticationHeaderLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : Layer(data, dataLen, prevLayer, packet) { m_Protocol = AuthenticationHeader; }
62 
68 
72  uint32_t getSPI() const;
73 
77  uint32_t getSequenceNumber() const;
78 
82  size_t getICVLength() const;
83 
87  uint8_t* getICVBytes() const;
88 
92  std::string getICVHexStream() const;
93 
100  static inline bool isDataValid(const uint8_t* data, size_t dataLen);
101 
102  // implement abstract methods
103 
107  size_t getHeaderLen() const { return 4*(getAHHeader()->payloadLen + 2); }
108 
112  void parseNextLayer();
113 
118 
119  std::string toString() const;
120 
122 
123  private:
124  // this layer supports parsing only
126  };
127 
128 
129 
134  class ESPLayer : public Layer
135  {
136  public:
143  ESPLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : Layer(data, dataLen, prevLayer, packet) { m_Protocol = ESP; }
144 
145  ipsec_esp* getESPHeader() const { return (ipsec_esp*)m_Data; }
146 
150  uint32_t getSPI() const;
151 
155  uint32_t getSequenceNumber() const;
156 
163  static inline bool isDataValid(const uint8_t* data, size_t dataLen);
164 
165  // implement abstract methods
166 
170  size_t getHeaderLen() const { return sizeof(ipsec_esp); }
171 
175  void parseNextLayer();
176 
181 
182  std::string toString() const;
183 
185 
186  private:
187  // this layer supports parsing only
188  ESPLayer() {}
189  };
190 
191 
192  // implementation of inline methods
193 
194  bool AuthenticationHeaderLayer::isDataValid(const uint8_t* data, size_t dataLen)
195  {
196  if (dataLen < sizeof(ipsec_authentication_header))
197  return false;
198 
199  size_t payloadLen = 4 * (data[1] + 2);
200  if (payloadLen < sizeof(ipsec_authentication_header) || payloadLen > dataLen)
201  return false;
202 
203  return true;
204  }
205 
206  bool ESPLayer::isDataValid(const uint8_t* data, size_t dataLen)
207  {
208  return dataLen >= sizeof(ipsec_esp);
209  }
210 }
211 
212 #endif // PACKETPP_IPSEC_LAYER
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:258
uint8_t nextHeader
Definition: IPSecLayer.h:22
ESPLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: IPSecLayer.h:143
void computeCalculateFields()
Definition: IPSecLayer.h:180
static bool isDataValid(const uint8_t *data, size_t dataLen)
Definition: IPSecLayer.h:206
Definition: Layer.h:70
Definition: Packet.h:26
Definition: IPSecLayer.h:52
Definition: ProtocolType.h:265
Definition: IPSecLayer.h:39
uint32_t spi
Definition: IPSecLayer.h:28
uint32_t sequenceNumber
Definition: IPSecLayer.h:44
uint32_t spi
Definition: IPSecLayer.h:42
AuthenticationHeaderLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: IPSecLayer.h:61
Definition: IPSecLayer.h:134
Definition: ProtocolType.h:267
static bool isDataValid(const uint8_t *data, size_t dataLen)
Definition: IPSecLayer.h:194
uint16_t reserved
Definition: IPSecLayer.h:26
void computeCalculateFields()
Definition: IPSecLayer.h:117
size_t getHeaderLen() const
Definition: IPSecLayer.h:107
size_t getHeaderLen() const
Definition: IPSecLayer.h:170
uint8_t payloadLen
Definition: IPSecLayer.h:24
Definition: IPSecLayer.h:19
OsiModelLayer getOsiModelLayer() const
Definition: IPSecLayer.h:121
const ProtocolType ESP
Definition: ProtocolType.h:243
ipsec_authentication_header * getAHHeader() const
Definition: IPSecLayer.h:67
uint32_t sequenceNumber
Definition: IPSecLayer.h:30
const ProtocolType AuthenticationHeader
Definition: ProtocolType.h:238
OsiModelLayer getOsiModelLayer() const
Definition: IPSecLayer.h:184