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
The main namespace for the PcapPlusPlus lib.
uint8_t headerLen
Definition: IPv6Extensions.h:483
Definition: IPv6Extensions.h:121
Definition: IPv6Extensions.h:197
IPv6ExtensionType
Definition: IPv6Extensions.h:32
uint32_t sequenceNumber
Definition: IPv6Extensions.h:489
Definition: IPv6Extensions.h:23
size_t getDataSize() const
Definition: IPv6Extensions.h:225
size_t getExtensionLen() const
Definition: IPv6Extensions.h:528
Definition: TLVData.h:351
Definition: IPv6Extensions.h:344
virtual size_t getExtensionLen() const
Definition: IPv6Extensions.h:51
Definition: TLVData.h:23
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:432
ipv6_frag_header * getFragHeader() const
Definition: IPv6Extensions.h:148
Definition: IPv6Extensions.h:394
uint16_t reserved
Definition: IPv6Extensions.h:485
uint16_t fragOffsetAndFlags
Definition: IPv6Extensions.h:129
Definition: IPv6Extensions.h:404
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:284
Definition: TLVData.h:197
Definition: IPv6Extensions.h:369
Definition: IPv6Layer.h:54
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:409
virtual ~IPv6Extension()
uint32_t id
Definition: IPv6Extensions.h:131
IPv6HopByHopHeader(const std::vector< IPv6TLVOptionBuilder > &options)
Definition: IPv6Extensions.h:356
Definition: IPv6Extensions.h:39
uint8_t headerLen
Definition: IPv6Extensions.h:126
Definition: IpAddress.h:140
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:480
IPv6DestinationHeader(const std::vector< IPv6TLVOptionBuilder > &options)
Definition: IPv6Extensions.h:381
uint8_t nextHeader
Definition: IPv6Extensions.h:407
IPv6TLVOptionBuilder(const IPv6TLVOptionBuilder &other)
Definition: IPv6Extensions.h:277
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:487
Definition: IPv6Extensions.h:467
ipv6_authentication_header * getAuthHeader() const
Definition: IPv6Extensions.h:508
Definition: IPv6Extensions.h:43
uint8_t routingType
Definition: IPv6Extensions.h:411
uint8_t segmentsLeft
Definition: IPv6Extensions.h:413