PcapPlusPlus  Next
GreLayer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Layer.h"
4 
6 
11 namespace pcpp
12 {
13 
18 #pragma pack(push, 1)
20  {
21 #if (BYTE_ORDER == LITTLE_ENDIAN)
23  uint8_t recursionControl : 3,
29  keyBit : 1,
34 #else
36  uint8_t checksumBit : 1,
38  routingBit : 1,
40  keyBit : 1,
42  sequenceNumBit : 1,
46  recursionControl : 3;
47 #endif
48 #if (BYTE_ORDER == LITTLE_ENDIAN)
50  uint8_t version : 3,
52  flags : 4,
55 #else
57  uint8_t ackSequenceNumBit : 1,
59  flags : 4,
61  version : 3;
62 #endif
63 
65  uint16_t protocol;
66  };
67 #pragma pack(pop)
68 
73 #pragma pack(push, 1)
75  {
77  uint16_t payloadLength;
79  uint16_t callID;
80  };
81 #pragma pack(pop)
82 
87 #pragma pack(push, 1)
89  {
91  uint8_t address;
93  uint8_t control;
95  uint16_t protocol;
96  };
97 #pragma pack(pop)
98 
104  class GreLayer : public Layer
105  {
106  public:
107  ~GreLayer() override = default;
108 
116  static ProtocolType getGREVersion(uint8_t* greData, size_t greDataLen);
117 
124  bool getSequenceNumber(uint32_t& seqNumber) const;
125 
133  bool setSequenceNumber(uint32_t seqNumber);
134 
141 
142  // implement abstract methods
143 
149  void parseNextLayer() override;
150 
154  size_t getHeaderLen() const override;
155 
157  {
158  return OsiModelNetworkLayer;
159  }
160 
161  protected:
162  GreLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet, ProtocolType protocol)
163  : Layer(data, dataLen, prevLayer, packet, protocol)
164  {}
165 
166  GreLayer()
167  {}
168 
169  enum GreField
170  {
171  GreChecksumOrRouting = 0,
172  GreKey = 1,
173  GreSeq = 2,
174  GreAck = 3
175  };
176 
177  uint8_t* getFieldValue(GreField field, bool returnOffsetEvenIfFieldMissing) const;
178 
179  void computeCalculateFieldsInner();
180  };
181 
188  class GREv0Layer : public GreLayer
189  {
190  public:
197  GREv0Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
198  : GreLayer(data, dataLen, prevLayer, packet, GREv0)
199  {}
200 
205 
206  ~GREv0Layer() override = default;
207 
218  {
219  return reinterpret_cast<gre_basic_header*>(m_Data);
220  }
221 
228  bool getChecksum(uint16_t& checksum);
229 
240  bool setChecksum(uint16_t checksum);
241 
250 
258  bool getOffset(uint16_t& offset) const;
259 
266  bool getKey(uint32_t& key) const;
267 
275  bool setKey(uint32_t key);
276 
282  bool unsetKey();
283 
290  static inline bool isDataValid(const uint8_t* data, size_t dataLen)
291  {
292  return data && dataLen >= sizeof(gre_basic_header);
293  }
294 
295  // implement abstract methods
296 
302  void computeCalculateFields() override;
303 
304  std::string toString() const override;
305  };
306 
311  class GREv1Layer : public GreLayer
312  {
313  public:
320  GREv1Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
321  : GreLayer(data, dataLen, prevLayer, packet, GREv1)
322  {}
323 
328  explicit GREv1Layer(uint16_t callID);
329 
330  ~GREv1Layer() override = default;
331 
343  {
344  return reinterpret_cast<gre1_header*>(m_Data);
345  }
346 
353  bool getAcknowledgmentNum(uint32_t& ackNum) const;
354 
362  bool setAcknowledgmentNum(uint32_t ackNum);
363 
370 
377  static inline bool isDataValid(const uint8_t* data, size_t dataLen)
378  {
379  return data && dataLen >= sizeof(gre1_header);
380  }
381 
382  // implement abstract methods
383 
389  void computeCalculateFields() override;
390 
391  std::string toString() const override;
392  };
393 
399  class PPP_PPTPLayer : public Layer
400  {
401  public:
409  PPP_PPTPLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
410  : Layer(data, dataLen, prevLayer, packet, PPP_PPTP)
411  {}
412 
418  PPP_PPTPLayer(uint8_t address, uint8_t control);
419 
420  ~PPP_PPTPLayer() override = default;
421 
428  {
429  return reinterpret_cast<ppp_pptp_header*>(m_Data);
430  }
431 
432  // implement abstract methods
433 
437  void parseNextLayer() override;
438 
442  size_t getHeaderLen() const override
443  {
444  return sizeof(ppp_pptp_header);
445  }
446 
451  void computeCalculateFields() override;
452 
453  std::string toString() const override
454  {
455  return "PPP for PPTP Layer";
456  }
457 
459  {
460  return OsiModelSesionLayer;
461  }
462  };
463 
464 } // namespace pcpp
Definition: GreLayer.h:189
std::string toString() const override
bool getChecksum(uint16_t &checksum)
bool setKey(uint32_t key)
gre_basic_header * getGreHeader() const
Definition: GreLayer.h:217
GREv0Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: GreLayer.h:197
bool getKey(uint32_t &key) const
bool getOffset(uint16_t &offset) const
void computeCalculateFields() override
static bool isDataValid(const uint8_t *data, size_t dataLen)
Definition: GreLayer.h:290
bool setChecksum(uint16_t checksum)
Definition: GreLayer.h:312
bool setAcknowledgmentNum(uint32_t ackNum)
static bool isDataValid(const uint8_t *data, size_t dataLen)
Definition: GreLayer.h:377
bool getAcknowledgmentNum(uint32_t &ackNum) const
GREv1Layer(uint16_t callID)
void computeCalculateFields() override
bool unsetAcknowledgmentNum()
std::string toString() const override
gre1_header * getGreHeader() const
Definition: GreLayer.h:342
GREv1Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: GreLayer.h:320
Definition: GreLayer.h:105
bool unsetSequenceNumber()
bool getSequenceNumber(uint32_t &seqNumber) const
void parseNextLayer() override
OsiModelLayer getOsiModelLayer() const override
Definition: GreLayer.h:156
bool setSequenceNumber(uint32_t seqNumber)
static ProtocolType getGREVersion(uint8_t *greData, size_t greDataLen)
size_t getHeaderLen() const override
Definition: Layer.h:69
Definition: GreLayer.h:400
size_t getHeaderLen() const override
Definition: GreLayer.h:442
void computeCalculateFields() override
PPP_PPTPLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: GreLayer.h:409
ppp_pptp_header * getPPP_PPTPHeader() const
Definition: GreLayer.h:427
OsiModelLayer getOsiModelLayer() const override
Definition: GreLayer.h:458
std::string toString() const override
Definition: GreLayer.h:453
PPP_PPTPLayer(uint8_t address, uint8_t control)
void parseNextLayer() override
Definition: Packet.h:27
The main namespace for the PcapPlusPlus lib.
uint8_t ProtocolType
Definition: ProtocolType.h:17
const ProtocolType GREv0
Definition: ProtocolType.h:118
const ProtocolType PPP_PPTP
Definition: ProtocolType.h:133
const ProtocolType GREv1
Definition: ProtocolType.h:123
OsiModelLayer
Definition: ProtocolType.h:364
@ OsiModelSesionLayer
Definition: ProtocolType.h:374
@ OsiModelNetworkLayer
Definition: ProtocolType.h:370
Definition: GreLayer.h:75
uint16_t payloadLength
Definition: GreLayer.h:77
uint16_t callID
Definition: GreLayer.h:79
Definition: GreLayer.h:20
uint8_t recursionControl
Definition: GreLayer.h:23
uint8_t sequenceNumBit
Definition: GreLayer.h:27
uint8_t strictSourceRouteBit
Definition: GreLayer.h:25
uint8_t routingBit
Definition: GreLayer.h:31
uint8_t ackSequenceNumBit
Definition: GreLayer.h:54
uint8_t keyBit
Definition: GreLayer.h:29
uint8_t flags
Definition: GreLayer.h:52
uint16_t protocol
Definition: GreLayer.h:65
uint8_t checksumBit
Definition: GreLayer.h:33
uint8_t version
Definition: GreLayer.h:50
Definition: GreLayer.h:89
uint16_t protocol
Definition: GreLayer.h:95
uint8_t address
Definition: GreLayer.h:91
uint8_t control
Definition: GreLayer.h:93