PcapPlusPlus  21.05+
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  IPv6Option(uint8_t* optionRawData) : TLVRecord(optionRawData) { }
209 
214 
215  // implement abstract methods
216 
217  size_t getTotalSize() const
218  {
219  if (m_Data->recordType == Pad0OptionType)
220  return sizeof(uint8_t);
221 
222  return (size_t)(m_Data->recordLen + sizeof(uint16_t));
223  }
224 
225  size_t getDataSize() const
226  {
227  if (m_Data->recordType == Pad0OptionType)
228  return (size_t)0;
229 
230  return (size_t)m_Data->recordLen;
231  }
232  };
233 
234 
241  {
242  public:
243 
251  IPv6TLVOptionBuilder(uint8_t optType, const uint8_t* optValue, uint8_t optValueLen) :
252  TLVRecordBuilder(optType, optValue, optValueLen) { }
253 
260  IPv6TLVOptionBuilder(uint8_t optType, uint8_t optValue) :
261  TLVRecordBuilder(optType, optValue) { }
262 
269  IPv6TLVOptionBuilder(uint8_t optType, uint16_t optValue) :
270  TLVRecordBuilder(optType, optValue) { }
271 
277  TLVRecordBuilder(other) {}
278 
284  {
285  TLVRecordBuilder::operator=(other);
286  return *this;
287  }
288 
293  IPv6Option build() const;
294  };
295 
302  IPv6Option getOption(uint8_t optionType) const;
303 
307  IPv6Option getFirstOption() const;
308 
318  IPv6Option getNextOption(IPv6Option& option) const;
319 
323  size_t getOptionCount() const;
324 
325  protected:
326 
328  IPv6TLVOptionHeader(const std::vector<IPv6TLVOptionBuilder>& options);
329 
330  IPv6TLVOptionHeader(IDataContainer* dataContainer, size_t offset);
331 
332  private:
333 
334  TLVRecordReader<IPv6Option> m_OptionReader;
335  };
336 
337 
338 
344  {
345  friend class IPv6Layer;
346 
347  public:
348 
355  IPv6HopByHopHeader(const std::vector<IPv6TLVOptionBuilder>& options) : IPv6TLVOptionHeader(options) { m_ExtType = IPv6HopByHop; }
356 
357  private:
358 
359  IPv6HopByHopHeader(IDataContainer* dataContainer, size_t offset) : IPv6TLVOptionHeader(dataContainer, offset) { m_ExtType = IPv6HopByHop; }
360  };
361 
362 
363 
369  {
370  friend class IPv6Layer;
371 
372  public:
373 
380  IPv6DestinationHeader(const std::vector<IPv6TLVOptionBuilder>& options) : IPv6TLVOptionHeader(options) { m_ExtType = IPv6Destination; }
381 
382  private:
383 
384  IPv6DestinationHeader(IDataContainer* dataContainer, size_t offset) : IPv6TLVOptionHeader(dataContainer, offset) { m_ExtType = IPv6Destination; }
385  };
386 
387 
388 
394  {
395  friend class IPv6Layer;
396 
397  public:
398 
404  {
406  uint8_t nextHeader;
408  uint8_t headerLen;
410  uint8_t routingType;
412  uint8_t segmentsLeft;
413  };
414 
424  IPv6RoutingHeader(uint8_t routingType, uint8_t segmentsLeft, const uint8_t* additionalRoutingData, size_t additionalRoutingDataLen);
425 
431  ipv6_routing_header* getRoutingHeader() const { return (ipv6_routing_header*)getDataPtr(); }
432 
437  uint8_t* getRoutingAdditionalData() const;
438 
442  size_t getRoutingAdditionalDataLength() const;
443 
453  IPv6Address getRoutingAdditionalDataAsIPv6Address(size_t offset = 0) const;
454 
455  private:
456 
457  IPv6RoutingHeader(IDataContainer* dataContainer, size_t offset) : IPv6Extension(dataContainer, offset) { m_ExtType = IPv6Routing; }
458 
459  };
460 
461 
467  {
468  friend class IPv6Layer;
469 
470  public:
471 
477  {
479  uint8_t nextHeader;
482  uint8_t headerLen;
484  uint16_t reserved;
488  uint32_t sequenceNumber;
489  };
490 
500  IPv6AuthenticationHeader(uint32_t securityParametersIndex, uint32_t sequenceNumber, const uint8_t* integrityCheckValue, size_t integrityCheckValueLen);
501 
508 
513  uint8_t* getIntegrityCheckValue() const;
514 
518  size_t getIntegrityCheckValueLength() const;
519 
520  // overridden methods
521 
527  size_t getExtensionLen() const { return 4 * (getBaseHeader()->headerLen+2); }
528 
529  private:
530 
531  IPv6AuthenticationHeader(IDataContainer* dataContainer, size_t offset) : IPv6Extension(dataContainer, offset) { m_ExtType = IPv6AuthenticationHdr; }
532  };
533 
534 }
535 
536 #endif // PACKETPP_IPV6_EXTENSION
The main namespace for the PcapPlusPlus lib.
uint8_t headerLen
Definition: IPv6Extensions.h:482
Definition: IPv6Extensions.h:121
Definition: IPv6Extensions.h:197
IPv6ExtensionType
Definition: IPv6Extensions.h:32
uint32_t sequenceNumber
Definition: IPv6Extensions.h:488
Definition: IPv6Extensions.h:23
size_t getDataSize() const
Definition: IPv6Extensions.h:225
size_t getExtensionLen() const
Definition: IPv6Extensions.h:527
Definition: TLVData.h:363
Definition: IPv6Extensions.h:343
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:251
Definition: IPv6Extensions.h:45
ipv6_routing_header * getRoutingHeader() const
Definition: IPv6Extensions.h:431
ipv6_frag_header * getFragHeader() const
Definition: IPv6Extensions.h:148
Definition: IPv6Extensions.h:393
uint16_t reserved
Definition: IPv6Extensions.h:484
uint16_t fragOffsetAndFlags
Definition: IPv6Extensions.h:129
Definition: IPv6Extensions.h:403
IPv6TLVOptionBuilder(uint8_t optType, uint8_t optValue)
Definition: IPv6Extensions.h:260
Definition: IPv6Extensions.h:37
size_t getTotalSize() const
Definition: IPv6Extensions.h:217
IPv6TLVOptionBuilder & operator=(const IPv6TLVOptionBuilder &other)
Definition: IPv6Extensions.h:283
Definition: TLVData.h:207
Definition: IPv6Extensions.h:368
Definition: IPv6Layer.h:67
Definition: IPv6Extensions.h:35
Definition: IPv6Extensions.h:111
Definition: IPv6Extensions.h:185
IPv6TLVOptionBuilder(uint8_t optType, uint16_t optValue)
Definition: IPv6Extensions.h:269
uint8_t headerLen
Definition: IPv6Extensions.h:408
virtual ~IPv6Extension()
uint32_t id
Definition: IPv6Extensions.h:131
IPv6HopByHopHeader(const std::vector< IPv6TLVOptionBuilder > &options)
Definition: IPv6Extensions.h:355
Definition: IPv6Extensions.h:39
uint8_t headerLen
Definition: IPv6Extensions.h:126
Definition: IpAddress.h:167
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:479
IPv6DestinationHeader(const std::vector< IPv6TLVOptionBuilder > &options)
Definition: IPv6Extensions.h:380
uint8_t nextHeader
Definition: IPv6Extensions.h:406
IPv6TLVOptionBuilder(const IPv6TLVOptionBuilder &other)
Definition: IPv6Extensions.h:276
IPv6Option(uint8_t *optionRawData)
Definition: IPv6Extensions.h:208
Definition: Layer.h:23
Definition: IPv6Extensions.h:41
Definition: IPv6Extensions.h:240
uint32_t securityParametersIndex
Definition: IPv6Extensions.h:486
Definition: IPv6Extensions.h:466
ipv6_authentication_header * getAuthHeader() const
Definition: IPv6Extensions.h:507
Definition: IPv6Extensions.h:43
uint8_t routingType
Definition: IPv6Extensions.h:410
uint8_t segmentsLeft
Definition: IPv6Extensions.h:412