PcapPlusPlus  20.08
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
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 
278  TLVRecordBuilder(other) {}
279 
285  {
286  TLVRecordBuilder::operator=(other);
287  return *this;
288  }
289 
294  IPv6Option build() const;
295  };
296 
303  IPv6Option getOption(uint8_t optionType) const;
304 
308  IPv6Option getFirstOption() const;
309 
319  IPv6Option getNextOption(IPv6Option& option) const;
320 
324  size_t getOptionCount() const;
325 
326  protected:
327 
329  IPv6TLVOptionHeader(const std::vector<IPv6TLVOptionBuilder>& options);
330 
331  IPv6TLVOptionHeader(IDataContainer* dataContainer, size_t offset);
332 
333  private:
334 
335  TLVRecordReader<IPv6Option> m_OptionReader;
336  };
337 
338 
339 
345  {
346  friend class IPv6Layer;
347 
348  public:
349 
356  IPv6HopByHopHeader(const std::vector<IPv6TLVOptionBuilder>& options) : IPv6TLVOptionHeader(options) { m_ExtType = IPv6HopByHop; }
357 
358  private:
359 
360  IPv6HopByHopHeader(IDataContainer* dataContainer, size_t offset) : IPv6TLVOptionHeader(dataContainer, offset) { m_ExtType = IPv6HopByHop; }
361  };
362 
363 
364 
370  {
371  friend class IPv6Layer;
372 
373  public:
374 
381  IPv6DestinationHeader(const std::vector<IPv6TLVOptionBuilder>& options) : IPv6TLVOptionHeader(options) { m_ExtType = IPv6Destination; }
382 
383  private:
384 
385  IPv6DestinationHeader(IDataContainer* dataContainer, size_t offset) : IPv6TLVOptionHeader(dataContainer, offset) { m_ExtType = IPv6Destination; }
386  };
387 
388 
389 
395  {
396  friend class IPv6Layer;
397 
398  public:
399 
405  {
407  uint8_t nextHeader;
409  uint8_t headerLen;
411  uint8_t routingType;
413  uint8_t segmentsLeft;
414  };
415 
425  IPv6RoutingHeader(uint8_t routingType, uint8_t segmentsLeft, const uint8_t* additionalRoutingData, size_t additionalRoutingDataLen);
426 
432  ipv6_routing_header* getRoutingHeader() const { return (ipv6_routing_header*)getDataPtr(); }
433 
438  uint8_t* getRoutingAdditionalData() const;
439 
443  size_t getRoutingAdditionalDataLength() const;
444 
454  IPv6Address getRoutingAdditionalDataAsIPv6Address(size_t offset = 0) const;
455 
456  private:
457 
458  IPv6RoutingHeader(IDataContainer* dataContainer, size_t offset) : IPv6Extension(dataContainer, offset) { m_ExtType = IPv6Routing; }
459 
460  };
461 
462 
468  {
469  friend class IPv6Layer;
470 
471  public:
472 
478  {
480  uint8_t nextHeader;
483  uint8_t headerLen;
485  uint16_t reserved;
489  uint32_t sequenceNumber;
490  };
491 
501  IPv6AuthenticationHeader(uint32_t securityParametersIndex, uint32_t sequenceNumber, const uint8_t* integrityCheckValue, size_t integrityCheckValueLen);
502 
509 
514  uint8_t* getIntegrityCheckValue() const;
515 
519  size_t getIntegrityCheckValueLength() const;
520 
521  // overridden methods
522 
528  size_t getExtensionLen() const { return 4 * (getBaseHeader()->headerLen+2); }
529 
530  private:
531 
532  IPv6AuthenticationHeader(IDataContainer* dataContainer, size_t offset) : IPv6Extension(dataContainer, offset) { m_ExtType = IPv6AuthenticationHdr; }
533  };
534 
535 }
536 
537 #endif // PACKETPP_IPV6_EXTENSION
pcpp::IPv6AuthenticationHeader::ipv6_authentication_header
Definition: IPv6Extensions.h:477
pcpp::IPv6TLVOptionHeader::getOptionCount
size_t getOptionCount() const
pcpp::IPv6AuthenticationHeader::IPv6AuthenticationHeader
IPv6AuthenticationHeader(uint32_t securityParametersIndex, uint32_t sequenceNumber, const uint8_t *integrityCheckValue, size_t integrityCheckValueLen)
pcpp::TLVRecord
Definition: TLVData.h:23
pcpp::IPv6AuthenticationHeader::ipv6_authentication_header::securityParametersIndex
uint32_t securityParametersIndex
Definition: IPv6Extensions.h:487
pcpp::IPv6Address
Definition: IpAddress.h:140
pcpp::IPv6RoutingHeader::getRoutingHeader
ipv6_routing_header * getRoutingHeader() const
Definition: IPv6Extensions.h:432
pcpp::IPv6AuthenticationHeader::getAuthHeader
ipv6_authentication_header * getAuthHeader() const
Definition: IPv6Extensions.h:508
pcpp::IPv6FragmentationHeader::isFirstFragment
bool isFirstFragment() const
pcpp::IPv6RoutingHeader::getRoutingAdditionalDataLength
size_t getRoutingAdditionalDataLength() const
pcpp::IPv6DestinationHeader::IPv6DestinationHeader
IPv6DestinationHeader(const std::vector< IPv6TLVOptionBuilder > &options)
Definition: IPv6Extensions.h:381
pcpp::IPv6TLVOptionHeader::IPv6Option
Definition: IPv6Extensions.h:197
pcpp::IPv6HopByHopHeader
Definition: IPv6Extensions.h:344
Layer.h
pcpp::TLVRecord::TLVRawData::recordType
uint8_t recordType
Definition: TLVData.h:31
pcpp::IPv6FragmentationHeader::isMoreFragments
bool isMoreFragments() const
pcpp::IPv6TLVOptionHeader::IPv6TLVOptionBuilder::IPv6TLVOptionBuilder
IPv6TLVOptionBuilder(uint8_t optType, uint8_t optValue)
Definition: IPv6Extensions.h:260
pcpp::IPv6FragmentationHeader::ipv6_frag_header::nextHeader
uint8_t nextHeader
Definition: IPv6Extensions.h:124
pcpp::IDataContainer
Definition: Layer.h:23
pcpp::IPv6Extension::IPv6Fragmentation
@ IPv6Fragmentation
Definition: IPv6Extensions.h:39
pcpp::IPv6Extension::IPv6Destination
@ IPv6Destination
Definition: IPv6Extensions.h:43
pcpp::IPv6FragmentationHeader::getFragHeader
ipv6_frag_header * getFragHeader() const
Definition: IPv6Extensions.h:148
pcpp::IPv6AuthenticationHeader::ipv6_authentication_header::headerLen
uint8_t headerLen
Definition: IPv6Extensions.h:483
pcpp::IPv6TLVOptionHeader::IPv6TLVOptionHeader
IPv6TLVOptionHeader(const std::vector< IPv6TLVOptionBuilder > &options)
pcpp::IPv6TLVOptionHeader::IPv6TLVOptionBuilder::IPv6TLVOptionBuilder
IPv6TLVOptionBuilder(uint8_t optType, uint16_t optValue)
Definition: IPv6Extensions.h:269
pcpp::IPv6AuthenticationHeader::getIntegrityCheckValueLength
size_t getIntegrityCheckValueLength() const
pcpp::IPv6Extension::IPv6ExtensionType
IPv6ExtensionType
Definition: IPv6Extensions.h:32
pcpp::IPv6FragmentationHeader::IPv6FragmentationHeader
IPv6FragmentationHeader(uint32_t fragId, uint16_t fragOffset, bool lastFragment)
pcpp::IPv6AuthenticationHeader::getExtensionLen
size_t getExtensionLen() const
Definition: IPv6Extensions.h:528
pcpp::IPv6TLVOptionHeader::getNextOption
IPv6Option getNextOption(IPv6Option &option) const
pcpp::IPv6RoutingHeader::getRoutingAdditionalDataAsIPv6Address
IPv6Address getRoutingAdditionalDataAsIPv6Address(size_t offset=0) const
pcpp::IPv6Extension
Definition: IPv6Extensions.h:23
pcpp::IPv6TLVOptionHeader::IPv6TLVOptionBuilder::IPv6TLVOptionBuilder
IPv6TLVOptionBuilder(uint8_t optType, const uint8_t *optValue, uint8_t optValueLen)
Definition: IPv6Extensions.h:251
pcpp::IPv6RoutingHeader::ipv6_routing_header::segmentsLeft
uint8_t segmentsLeft
Definition: IPv6Extensions.h:413
TLVData.h
pcpp::IPv6Extension::getExtensionType
IPv6ExtensionType getExtensionType() const
Definition: IPv6Extensions.h:56
pcpp::IPv6TLVOptionHeader::IPv6Option::IPv6Option
IPv6Option(uint8_t *optionRawData)
Definition: IPv6Extensions.h:208
pcpp::IPv6RoutingHeader::ipv6_routing_header::nextHeader
uint8_t nextHeader
Definition: IPv6Extensions.h:407
pcpp::IPv6Extension::IPv6AuthenticationHdr
@ IPv6AuthenticationHdr
Definition: IPv6Extensions.h:41
pcpp::IPv6TLVOptionHeader::IPv6TLVOptionBuilder
Definition: IPv6Extensions.h:240
pcpp::IPv6Extension::getExtensionLen
virtual size_t getExtensionLen() const
Definition: IPv6Extensions.h:51
pcpp::IPv6TLVOptionHeader
Definition: IPv6Extensions.h:185
pcpp::IPv6RoutingHeader::ipv6_routing_header
Definition: IPv6Extensions.h:404
pcpp::IPv6AuthenticationHeader::ipv6_authentication_header::sequenceNumber
uint32_t sequenceNumber
Definition: IPv6Extensions.h:489
pcpp::IPv6TLVOptionHeader::IPv6TLVOptionBuilder::operator=
IPv6TLVOptionBuilder & operator=(const IPv6TLVOptionBuilder &other)
Definition: IPv6Extensions.h:284
pcpp::IPv6AuthenticationHeader::getIntegrityCheckValue
uint8_t * getIntegrityCheckValue() const
pcpp::IPv6RoutingHeader::IPv6RoutingHeader
IPv6RoutingHeader(uint8_t routingType, uint8_t segmentsLeft, const uint8_t *additionalRoutingData, size_t additionalRoutingDataLen)
pcpp::IPv6TLVOptionHeader::IPv6Option::getDataSize
size_t getDataSize() const
Definition: IPv6Extensions.h:225
pcpp::IPv6Extension::IPv6Routing
@ IPv6Routing
Definition: IPv6Extensions.h:37
pcpp::IPv6RoutingHeader::ipv6_routing_header::routingType
uint8_t routingType
Definition: IPv6Extensions.h:411
pcpp::IPv6RoutingHeader::getRoutingAdditionalData
uint8_t * getRoutingAdditionalData() const
pcpp::IPv6TLVOptionHeader::IPv6Option::getTotalSize
size_t getTotalSize() const
Definition: IPv6Extensions.h:217
pcpp::IPv6Extension::~IPv6Extension
virtual ~IPv6Extension()
IpAddress.h
pcpp::IPv6TLVOptionHeader::IPv6TLVOptionBuilder::IPv6TLVOptionBuilder
IPv6TLVOptionBuilder(const IPv6TLVOptionBuilder &other)
Definition: IPv6Extensions.h:277
pcpp
The main namespace for the PcapPlusPlus lib.
pcpp::TLVRecordBuilder
Definition: TLVData.h:351
pcpp::IPv6AuthenticationHeader::ipv6_authentication_header::nextHeader
uint8_t nextHeader
Definition: IPv6Extensions.h:480
pcpp::IPv6FragmentationHeader::ipv6_frag_header::headerLen
uint8_t headerLen
Definition: IPv6Extensions.h:126
pcpp::IPv6RoutingHeader::ipv6_routing_header::headerLen
uint8_t headerLen
Definition: IPv6Extensions.h:409
pcpp::IPv6RoutingHeader
Definition: IPv6Extensions.h:394
pcpp::IPv6FragmentationHeader::ipv6_frag_header::fragOffsetAndFlags
uint16_t fragOffsetAndFlags
Definition: IPv6Extensions.h:129
pcpp::IPv6TLVOptionHeader::IPv6Option::~IPv6Option
~IPv6Option()
Definition: IPv6Extensions.h:213
pcpp::IPv6TLVOptionHeader::getOption
IPv6Option getOption(uint8_t optionType) const
pcpp::TLVRecordReader
Definition: TLVData.h:197
pcpp::IPv6DestinationHeader
Definition: IPv6Extensions.h:369
pcpp::IPv6Extension::getNextHeader
IPv6Extension * getNextHeader() const
Definition: IPv6Extensions.h:66
pcpp::IPv6Layer
Definition: IPv6Layer.h:54
pcpp::IPv6TLVOptionHeader::IPv6TLVOptionBuilder::build
IPv6Option build() const
pcpp::IPv6FragmentationHeader::getFragmentOffset
uint16_t getFragmentOffset() const
pcpp::IPv6FragmentationHeader
Definition: IPv6Extensions.h:111
pcpp::IPv6AuthenticationHeader::ipv6_authentication_header::reserved
uint16_t reserved
Definition: IPv6Extensions.h:485
pcpp::IPv6Extension::IPv6ExtensionUnknown
@ IPv6ExtensionUnknown
Definition: IPv6Extensions.h:45
pcpp::IPv6FragmentationHeader::isLastFragment
bool isLastFragment() const
pcpp::IPv6TLVOptionHeader::getFirstOption
IPv6Option getFirstOption() const
pcpp::TLVRecord::TLVRawData::recordLen
uint8_t recordLen
Definition: TLVData.h:33
pcpp::IPv6Extension::IPv6HopByHop
@ IPv6HopByHop
Definition: IPv6Extensions.h:35
pcpp::IPv6FragmentationHeader::ipv6_frag_header::id
uint32_t id
Definition: IPv6Extensions.h:131
pcpp::IPv6AuthenticationHeader
Definition: IPv6Extensions.h:467
pcpp::IPv6FragmentationHeader::ipv6_frag_header
Definition: IPv6Extensions.h:121
pcpp::IPv6HopByHopHeader::IPv6HopByHopHeader
IPv6HopByHopHeader(const std::vector< IPv6TLVOptionBuilder > &options)
Definition: IPv6Extensions.h:356