PcapPlusPlus  23.09
IPv6Extensions.h
Go to the documentation of this file.
1 #ifndef PACKETPP_IPV6_EXTENSION
2 #define PACKETPP_IPV6_EXTENSION
3 
4 #include <vector>
5 #include "IpAddress.h"
6 #include "Layer.h"
7 #include "TLVData.h"
8 
10 
15 namespace pcpp
16 {
17 
24  {
25  friend class IPv6Layer;
26 
27  public:
28 
33  {
46  };
47 
51  virtual size_t getExtensionLen() const { return 8 * (getBaseHeader()->headerLen+1); }
52 
56  IPv6ExtensionType getExtensionType() const { return m_ExtType; }
57 
61  virtual ~IPv6Extension();
62 
66  IPv6Extension* getNextHeader() const { return m_NextHeader; }
67 
68  protected:
69 
70  struct ipv6_ext_base_header
71  {
72  uint8_t nextHeader;
73  uint8_t headerLen;
74  };
75 
76  // protected c'tor
77  IPv6Extension(IDataContainer* dataContainer, size_t offset) :
78  m_NextHeader(NULL), m_ExtType(IPv6ExtensionUnknown), m_DataContainer(dataContainer), m_Offset(offset), m_ShadowData(NULL) {}
79 
80  // protected empty c'tor
81  IPv6Extension() :
82  m_NextHeader(NULL), m_ExtType(IPv6ExtensionUnknown), m_DataContainer(NULL), m_Offset(0), m_ShadowData(NULL) {}
83 
84  // protected assignment operator
85  IPv6Extension& operator=(const IPv6Extension& other);
86 
87  uint8_t* getDataPtr() const;
88 
89  void initShadowPtr(size_t size);
90 
91  ipv6_ext_base_header* getBaseHeader() const { return (ipv6_ext_base_header*)getDataPtr(); }
92 
93  void setNextHeader(IPv6Extension* nextHeader) { m_NextHeader = nextHeader; }
94 
95  IPv6Extension* m_NextHeader;
96  IPv6ExtensionType m_ExtType;
97 
98  private:
99  IDataContainer* m_DataContainer;
100  size_t m_Offset;
101  uint8_t* m_ShadowData;
102 
103  };
104 
105 
106 
112  {
113  friend class IPv6Layer;
114 
115  public:
116 
122  {
124  uint8_t nextHeader;
126  uint8_t headerLen;
131  uint32_t id;
132  };
133 
141  IPv6FragmentationHeader(uint32_t fragId, uint16_t fragOffset, bool lastFragment);
142 
148  ipv6_frag_header* getFragHeader() const { return (ipv6_frag_header*)getDataPtr(); }
149 
153  bool isFirstFragment() const;
154 
158  bool isLastFragment() const;
159 
163  bool isMoreFragments() const;
164 
168  uint16_t getFragmentOffset() const;
169 
170  private:
171 
172  IPv6FragmentationHeader(IDataContainer* dataContainer, size_t offset) : IPv6Extension(dataContainer, offset)
173  {
174  m_ExtType = IPv6Fragmentation;
175  }
176 
177  };
178 
179 
186  {
187  friend class IPv6Layer;
188 
189  public:
190 
197  class IPv6Option : public TLVRecord<uint8_t, uint8_t>
198  {
199  public:
200 
201  static const uint8_t Pad0OptionType = 0;
202  static const uint8_t PadNOptionType = 1;
203 
208  explicit IPv6Option(uint8_t* optionRawData) : TLVRecord(optionRawData) { }
209 
214 
215  // implement abstract methods
216 
217  size_t getTotalSize() const
218  {
219  if (m_Data == nullptr)
220  return 0;
221 
222  if (m_Data->recordType == Pad0OptionType)
223  return sizeof(uint8_t);
224 
225  return (size_t)(m_Data->recordLen + sizeof(uint16_t));
226  }
227 
228  size_t getDataSize() const
229  {
230  if (m_Data == nullptr || m_Data->recordType == Pad0OptionType)
231  return 0;
232 
233  return (size_t)m_Data->recordLen;
234  }
235  };
236 
237 
244  {
245  public:
246 
254  IPv6TLVOptionBuilder(uint8_t optType, const uint8_t* optValue, uint8_t optValueLen) :
255  TLVRecordBuilder(optType, optValue, optValueLen) { }
256 
263  IPv6TLVOptionBuilder(uint8_t optType, uint8_t optValue) :
264  TLVRecordBuilder(optType, optValue) { }
265 
272  IPv6TLVOptionBuilder(uint8_t optType, uint16_t optValue) :
273  TLVRecordBuilder(optType, optValue) { }
274 
280  TLVRecordBuilder(other) {}
281 
287  {
288  TLVRecordBuilder::operator=(other);
289  return *this;
290  }
291 
296  IPv6Option build() const;
297  };
298 
305  IPv6Option getOption(uint8_t optionType) const;
306 
310  IPv6Option getFirstOption() const;
311 
321  IPv6Option getNextOption(IPv6Option& option) const;
322 
326  size_t getOptionCount() const;
327 
328  protected:
329 
331  explicit IPv6TLVOptionHeader(const std::vector<IPv6TLVOptionBuilder>& options);
332 
333  IPv6TLVOptionHeader(IDataContainer* dataContainer, size_t offset);
334 
335  private:
336 
337  TLVRecordReader<IPv6Option> m_OptionReader;
338  };
339 
340 
341 
347  {
348  friend class IPv6Layer;
349 
350  public:
351 
358  explicit IPv6HopByHopHeader(const std::vector<IPv6TLVOptionBuilder>& options) : IPv6TLVOptionHeader(options) { m_ExtType = IPv6HopByHop; }
359 
360  private:
361 
362  IPv6HopByHopHeader(IDataContainer* dataContainer, size_t offset) : IPv6TLVOptionHeader(dataContainer, offset) { m_ExtType = IPv6HopByHop; }
363  };
364 
365 
366 
372  {
373  friend class IPv6Layer;
374 
375  public:
376 
383  explicit IPv6DestinationHeader(const std::vector<IPv6TLVOptionBuilder>& options) : IPv6TLVOptionHeader(options) { m_ExtType = IPv6Destination; }
384 
385  private:
386 
387  IPv6DestinationHeader(IDataContainer* dataContainer, size_t offset) : IPv6TLVOptionHeader(dataContainer, offset) { m_ExtType = IPv6Destination; }
388  };
389 
390 
391 
397  {
398  friend class IPv6Layer;
399 
400  public:
401 
407  {
409  uint8_t nextHeader;
411  uint8_t headerLen;
413  uint8_t routingType;
415  uint8_t segmentsLeft;
416  };
417 
427  IPv6RoutingHeader(uint8_t routingType, uint8_t segmentsLeft, const uint8_t* additionalRoutingData, size_t additionalRoutingDataLen);
428 
434  ipv6_routing_header* getRoutingHeader() const { return (ipv6_routing_header*)getDataPtr(); }
435 
440  uint8_t* getRoutingAdditionalData() const;
441 
445  size_t getRoutingAdditionalDataLength() const;
446 
456  IPv6Address getRoutingAdditionalDataAsIPv6Address(size_t offset = 0) const;
457 
458  private:
459 
460  IPv6RoutingHeader(IDataContainer* dataContainer, size_t offset) : IPv6Extension(dataContainer, offset) { m_ExtType = IPv6Routing; }
461 
462  };
463 
464 
470  {
471  friend class IPv6Layer;
472 
473  public:
474 
480  {
482  uint8_t nextHeader;
485  uint8_t headerLen;
487  uint16_t reserved;
491  uint32_t sequenceNumber;
492  };
493 
503  IPv6AuthenticationHeader(uint32_t securityParametersIndex, uint32_t sequenceNumber, const uint8_t* integrityCheckValue, size_t integrityCheckValueLen);
504 
511 
516  uint8_t* getIntegrityCheckValue() const;
517 
521  size_t getIntegrityCheckValueLength() const;
522 
523  // overridden methods
524 
530  size_t getExtensionLen() const { return 4 * (getBaseHeader()->headerLen+2); }
531 
532  private:
533 
534  IPv6AuthenticationHeader(IDataContainer* dataContainer, size_t offset) : IPv6Extension(dataContainer, offset) { m_ExtType = IPv6AuthenticationHdr; }
535  };
536 
537 }
538 
539 #endif // PACKETPP_IPV6_EXTENSION
The main namespace for the PcapPlusPlus lib.
uint8_t headerLen
Definition: IPv6Extensions.h:485
Definition: IPv6Extensions.h:121
Definition: IPv6Extensions.h:197
IPv6ExtensionType
Definition: IPv6Extensions.h:32
uint32_t sequenceNumber
Definition: IPv6Extensions.h:491
Definition: IPv6Extensions.h:23
size_t getDataSize() const
Definition: IPv6Extensions.h:228
size_t getExtensionLen() const
Definition: IPv6Extensions.h:530
Definition: TLVData.h:376
Definition: IPv6Extensions.h:346
virtual size_t getExtensionLen() const
Definition: IPv6Extensions.h:51
Definition: TLVData.h:24
IPv6TLVOptionBuilder(uint8_t optType, const uint8_t *optValue, uint8_t optValueLen)
Definition: IPv6Extensions.h:254
Definition: IPv6Extensions.h:45
ipv6_routing_header * getRoutingHeader() const
Definition: IPv6Extensions.h:434
ipv6_frag_header * getFragHeader() const
Definition: IPv6Extensions.h:148
Definition: IPv6Extensions.h:396
uint16_t reserved
Definition: IPv6Extensions.h:487
uint16_t fragOffsetAndFlags
Definition: IPv6Extensions.h:129
Definition: IPv6Extensions.h:406
IPv6TLVOptionBuilder(uint8_t optType, uint8_t optValue)
Definition: IPv6Extensions.h:263
Definition: IPv6Extensions.h:37
size_t getTotalSize() const
Definition: IPv6Extensions.h:217
IPv6TLVOptionBuilder & operator=(const IPv6TLVOptionBuilder &other)
Definition: IPv6Extensions.h:286
Definition: TLVData.h:217
Definition: IPv6Extensions.h:371
Definition: IPv6Layer.h:56
Definition: IPv6Extensions.h:35
Definition: IPv6Extensions.h:111
Definition: IPv6Extensions.h:185
IPv6TLVOptionBuilder(uint8_t optType, uint16_t optValue)
Definition: IPv6Extensions.h:272
uint8_t headerLen
Definition: IPv6Extensions.h:411
virtual ~IPv6Extension()
uint32_t id
Definition: IPv6Extensions.h:131
IPv6HopByHopHeader(const std::vector< IPv6TLVOptionBuilder > &options)
Definition: IPv6Extensions.h:358
Definition: IPv6Extensions.h:39
uint8_t headerLen
Definition: IPv6Extensions.h:126
Definition: IpAddress.h:192
IPv6ExtensionType getExtensionType() const
Definition: IPv6Extensions.h:56
~IPv6Option()
Definition: IPv6Extensions.h:213
uint8_t nextHeader
Definition: IPv6Extensions.h:124
IPv6Extension * getNextHeader() const
Definition: IPv6Extensions.h:66
uint8_t nextHeader
Definition: IPv6Extensions.h:482
IPv6DestinationHeader(const std::vector< IPv6TLVOptionBuilder > &options)
Definition: IPv6Extensions.h:383
uint8_t nextHeader
Definition: IPv6Extensions.h:409
IPv6TLVOptionBuilder(const IPv6TLVOptionBuilder &other)
Definition: IPv6Extensions.h:279
IPv6Option(uint8_t *optionRawData)
Definition: IPv6Extensions.h:208
Definition: Layer.h:23
Definition: IPv6Extensions.h:41
Definition: IPv6Extensions.h:243
uint32_t securityParametersIndex
Definition: IPv6Extensions.h:489
Definition: IPv6Extensions.h:469
ipv6_authentication_header * getAuthHeader() const
Definition: IPv6Extensions.h:510
Definition: IPv6Extensions.h:43
uint8_t routingType
Definition: IPv6Extensions.h:413
uint8_t segmentsLeft
Definition: IPv6Extensions.h:415