PcapPlusPlus
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 inline size_t getExtensionLen() const { return 8 * (getBaseHeader()->headerLen+1); }
52 
56  inline IPv6ExtensionType getExtensionType() { return m_ExtType; }
57 
61  virtual ~IPv6Extension();
62 
66  inline IPv6Extension* getNextHeader() { 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  inline 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() { return (ipv6_frag_header*)getDataPtr(); }
149 
153  bool isFirstFragment();
154 
158  bool isLastFragment();
159 
163  bool isMoreFragments();
164 
168  uint16_t getFragmentOffset();
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()
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 
284  IPv6Option build() const;
285  };
286 
293  IPv6Option getOption(uint8_t optionType);
294 
298  IPv6Option getFirstOption();
299 
309  IPv6Option getNextOption(IPv6Option& option);
310 
314  size_t getOptionCount();
315 
316  protected:
317 
319  IPv6TLVOptionHeader(const std::vector<IPv6TLVOptionBuilder>& options);
320 
321  IPv6TLVOptionHeader(IDataContainer* dataContainer, size_t offset);
322 
323  private:
324 
325  TLVRecordReader<IPv6Option> m_OptionReader;
326  };
327 
328 
329 
335  {
336  friend class IPv6Layer;
337 
338  public:
339 
346  IPv6HopByHopHeader(const std::vector<IPv6TLVOptionBuilder>& options) : IPv6TLVOptionHeader(options) { m_ExtType = IPv6HopByHop; }
347 
348  private:
349 
350  IPv6HopByHopHeader(IDataContainer* dataContainer, size_t offset) : IPv6TLVOptionHeader(dataContainer, offset) { m_ExtType = IPv6HopByHop; }
351  };
352 
353 
354 
360  {
361  friend class IPv6Layer;
362 
363  public:
364 
371  IPv6DestinationHeader(const std::vector<IPv6TLVOptionBuilder>& options) : IPv6TLVOptionHeader(options) { m_ExtType = IPv6Destination; }
372 
373  private:
374 
375  IPv6DestinationHeader(IDataContainer* dataContainer, size_t offset) : IPv6TLVOptionHeader(dataContainer, offset) { m_ExtType = IPv6Destination; }
376  };
377 
378 
379 
385  {
386  friend class IPv6Layer;
387 
388  public:
389 
395  {
397  uint8_t nextHeader;
399  uint8_t headerLen;
401  uint8_t routingType;
403  uint8_t segmentsLeft;
404  };
405 
415  IPv6RoutingHeader(uint8_t routingType, uint8_t segmentsLeft, const uint8_t* additionalRoutingData, size_t additionalRoutingDataLen);
416 
423 
428  uint8_t* getRoutingAdditionalData();
429 
434 
445 
446  private:
447 
448  IPv6RoutingHeader(IDataContainer* dataContainer, size_t offset) : IPv6Extension(dataContainer, offset) { m_ExtType = IPv6Routing; }
449 
450  };
451 
452 
458  {
459  friend class IPv6Layer;
460 
461  public:
462 
468  {
470  uint8_t nextHeader;
473  uint8_t headerLen;
475  uint16_t reserved;
479  uint32_t sequenceNumber;
480  };
481 
491  IPv6AuthenticationHeader(uint32_t securityParametersIndex, uint32_t sequenceNumber, const uint8_t* integrityCheckValue, size_t integrityCheckValueLen);
492 
499 
504  uint8_t* getIntegrityCheckValue();
505 
510 
511  // overridden methods
512 
518  size_t getExtensionLen() const { return 4 * (getBaseHeader()->headerLen+2); }
519 
520  private:
521 
522  IPv6AuthenticationHeader(IDataContainer* dataContainer, size_t offset) : IPv6Extension(dataContainer, offset) { m_ExtType = IPv6AuthenticationHdr; }
523  };
524 
525 }
526 
527 #endif // PACKETPP_IPV6_EXTENSION
uint8_t recordLen
Definition: TLVData.h:33
uint8_t routingType
Definition: IPv6Extensions.h:401
Definition: IPv6Extensions.h:185
uint8_t recordType
Definition: TLVData.h:31
IPv6DestinationHeader(const std::vector< IPv6TLVOptionBuilder > &options)
Definition: IPv6Extensions.h:371
size_t getRoutingAdditionalDataLength()
uint8_t nextHeader
Definition: IPv6Extensions.h:124
size_t getDataSize()
Definition: IPv6Extensions.h:225
Definition: IPv6Extensions.h:384
IPv6Address getRoutingAdditionalDataAsIPv6Address(size_t offset=0)
uint16_t fragOffsetAndFlags
Definition: IPv6Extensions.h:129
Definition: TLVData.h:333
IPv6Option getNextOption(IPv6Option &option)
Definition: IPv6Extensions.h:240
Definition: TLVData.h:23
uint8_t * getRoutingAdditionalData()
IPv6HopByHopHeader(const std::vector< IPv6TLVOptionBuilder > &options)
Definition: IPv6Extensions.h:346
Definition: IPv6Layer.h:54
Definition: IPv6Extensions.h:457
uint8_t segmentsLeft
Definition: IPv6Extensions.h:403
uint8_t headerLen
Definition: IPv6Extensions.h:126
virtual ~IPv6Extension()
IPv6Option(uint8_t *optionRawData)
Definition: IPv6Extensions.h:208
IPv6AuthenticationHeader(uint32_t securityParametersIndex, uint32_t sequenceNumber, const uint8_t *integrityCheckValue, size_t integrityCheckValueLen)
ipv6_authentication_header * getAuthHeader()
Definition: IPv6Extensions.h:498
IPv6FragmentationHeader(uint32_t fragId, uint16_t fragOffset, bool lastFragment)
IPv6ExtensionType getExtensionType()
Definition: IPv6Extensions.h:56
~IPv6Option()
Definition: IPv6Extensions.h:213
virtual size_t getExtensionLen() const
Definition: IPv6Extensions.h:51
Definition: IPv6Extensions.h:359
Definition: TLVData.h:189
uint8_t nextHeader
Definition: IPv6Extensions.h:397
Definition: IPv6Extensions.h:197
uint8_t headerLen
Definition: IPv6Extensions.h:473
Definition: IPv6Extensions.h:45
Definition: IPv6Extensions.h:394
uint16_t reserved
Definition: IPv6Extensions.h:475
uint32_t sequenceNumber
Definition: IPv6Extensions.h:479
IPv6TLVOptionBuilder(uint8_t optType, uint8_t optValue)
Definition: IPv6Extensions.h:260
size_t getTotalSize() const
Definition: IPv6Extensions.h:217
ipv6_routing_header * getRoutingHeader()
Definition: IPv6Extensions.h:422
Definition: IPv6Extensions.h:334
IPv6RoutingHeader(uint8_t routingType, uint8_t segmentsLeft, const uint8_t *additionalRoutingData, size_t additionalRoutingDataLen)
uint8_t nextHeader
Definition: IPv6Extensions.h:470
IPv6TLVOptionBuilder(uint8_t optType, uint16_t optValue)
Definition: IPv6Extensions.h:269
ipv6_frag_header * getFragHeader()
Definition: IPv6Extensions.h:148
Definition: Layer.h:23
Definition: IPv6Extensions.h:43
Definition: IpAddress.h:212
uint32_t securityParametersIndex
Definition: IPv6Extensions.h:477
IPv6TLVOptionBuilder(uint8_t optType, const uint8_t *optValue, uint8_t optValueLen)
Definition: IPv6Extensions.h:251
IPv6TLVOptionHeader(const std::vector< IPv6TLVOptionBuilder > &options)
uint32_t id
Definition: IPv6Extensions.h:131
IPv6Option getOption(uint8_t optionType)
size_t getExtensionLen() const
Definition: IPv6Extensions.h:518
Definition: IPv6Extensions.h:41
Definition: IPv6Extensions.h:37
uint8_t headerLen
Definition: IPv6Extensions.h:399
Definition: IPv6Extensions.h:35
IPv6TLVOptionBuilder(const IPv6TLVOptionBuilder &other)
Definition: IPv6Extensions.h:277
Definition: IPv6Extensions.h:121
IPv6Extension * getNextHeader()
Definition: IPv6Extensions.h:66
Definition: IPv6Extensions.h:23
Definition: IPv6Extensions.h:39
The main namespace for the PcapPlusPlus lib.
IPv6ExtensionType
Definition: IPv6Extensions.h:32
Definition: IPv6Extensions.h:111