PcapPlusPlus  Next
DhcpV6Layer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Layer.h"
4 #include "TLVData.h"
5 
7 
10 namespace pcpp
11 {
14  {
43  };
44 
52  {
181  DHCPV6_OPT_MUD_URL = 112
182  };
183 
187  class DhcpV6Option : public TLVRecord<uint16_t, uint16_t>
188  {
189  public:
192  explicit DhcpV6Option(uint8_t* optionRawData) : TLVRecord(optionRawData)
193  {}
194 
196  ~DhcpV6Option() override = default;
197 
200 
202  std::string getValueAsHexString() const;
203 
204  // implement abstract methods
205 
206  size_t getTotalSize() const override;
207  size_t getDataSize() const override;
208  };
209 
214  {
215  public:
220  DhcpV6OptionBuilder(DhcpV6OptionType optionType, const std::string& optionValueAsHexStream)
221  : TLVRecordBuilder(static_cast<uint16_t>(optionType), optionValueAsHexStream, true)
222  {}
223 
230  DhcpV6OptionBuilder(DhcpV6OptionType optionType, const uint8_t* optionValue, uint8_t optionValueLen)
231  : TLVRecordBuilder(static_cast<uint16_t>(optionType), optionValue, optionValueLen)
232  {}
233 
237  };
238 
242  {
244  uint8_t messageType;
246  uint8_t transactionId1;
248  uint8_t transactionId2;
250  uint8_t transactionId3;
251  };
252  static_assert(sizeof(dhcpv6_header) == 4, "dhcpv6_header size is not 4 bytes");
253 
256  class DhcpV6Layer : public Layer
257  {
258  public:
264  DhcpV6Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet);
265 
270  DhcpV6Layer(DhcpV6MessageType messageType, uint32_t transactionId);
271 
274 
276  std::string getMessageTypeAsString() const;
277 
281 
283  uint32_t getTransactionID() const;
284 
287  void setTransactionID(uint32_t transactionId) const;
288 
292 
299 
305 
307  size_t getOptionCount() const;
308 
314 
321 
328 
332  bool removeOption(DhcpV6OptionType optionType);
333 
337 
341  static inline bool isDhcpV6Port(uint16_t port);
342 
347  static inline bool isDataValid(const uint8_t* data, size_t dataLen);
348 
349  // implement abstract methods
350 
352  void parseNextLayer() override
353  {}
354 
356  size_t getHeaderLen() const override
357  {
358  return m_DataLen;
359  }
360 
362  void computeCalculateFields() override
363  {}
364 
365  std::string toString() const override;
366 
368  {
370  }
371 
372  private:
373  uint8_t* getOptionsBasePtr() const
374  {
375  return m_Data + sizeof(dhcpv6_header);
376  }
377  dhcpv6_header* getDhcpHeader() const
378  {
379  return reinterpret_cast<dhcpv6_header*>(m_Data);
380  }
381  DhcpV6Option addOptionAt(const DhcpV6OptionBuilder& optionBuilder, int offset);
382 
383  TLVRecordReader<DhcpV6Option> m_OptionReader;
384  };
385 
386  // implementation of inline methods
387 
388  bool DhcpV6Layer::isDhcpV6Port(uint16_t port)
389  {
390  return (port == 546) || (port == 547);
391  }
392 
393  bool DhcpV6Layer::isDataValid(const uint8_t* data, size_t dataLen)
394  {
395  return data && dataLen >= sizeof(dhcpv6_header);
396  }
397 
398 } // namespace pcpp
Definition: DhcpV6Layer.h:257
std::string getMessageTypeAsString() const
DhcpV6Option getNextOptionData(DhcpV6Option dhcpv6Option) const
std::string toString() const override
DhcpV6Option addOptionAfter(const DhcpV6OptionBuilder &optionBuilder, DhcpV6OptionType optionType)
bool removeOption(DhcpV6OptionType optionType)
void setMessageType(DhcpV6MessageType messageType)
DhcpV6Option addOptionBefore(const DhcpV6OptionBuilder &optionBuilder, DhcpV6OptionType optionType)
size_t getHeaderLen() const override
Definition: DhcpV6Layer.h:356
DhcpV6Layer(DhcpV6MessageType messageType, uint32_t transactionId)
void setTransactionID(uint32_t transactionId) const
void parseNextLayer() override
Does nothing for this layer (DhcpV6Layer is always last)
Definition: DhcpV6Layer.h:352
DhcpV6Option getOptionData(DhcpV6OptionType option) const
uint32_t getTransactionID() const
size_t getOptionCount() const
static bool isDataValid(const uint8_t *data, size_t dataLen)
Definition: DhcpV6Layer.h:393
OsiModelLayer getOsiModelLayer() const override
Definition: DhcpV6Layer.h:367
DhcpV6Option getFirstOptionData() const
void computeCalculateFields() override
Does nothing for this layer.
Definition: DhcpV6Layer.h:362
DhcpV6Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
DhcpV6MessageType getMessageType() const
DhcpV6Option addOption(const DhcpV6OptionBuilder &optionBuilder)
static bool isDhcpV6Port(uint16_t port)
Definition: DhcpV6Layer.h:388
Definition: DhcpV6Layer.h:214
DhcpV6Option build() const
DhcpV6OptionBuilder(DhcpV6OptionType optionType, const std::string &optionValueAsHexStream)
Definition: DhcpV6Layer.h:220
DhcpV6OptionBuilder(DhcpV6OptionType optionType, const uint8_t *optionValue, uint8_t optionValueLen)
Definition: DhcpV6Layer.h:230
Definition: DhcpV6Layer.h:188
size_t getDataSize() const override
~DhcpV6Option() override=default
A d'tor for this class, currently does nothing.
size_t getTotalSize() const override
std::string getValueAsHexString() const
DhcpV6Option(uint8_t *optionRawData)
Definition: DhcpV6Layer.h:192
DhcpV6OptionType getType() const
Definition: Layer.h:60
Definition: Packet.h:22
Definition: TLVData.h:357
Definition: TLVData.h:19
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
An enum representing OSI model layers.
Definition: ProtocolType.h:225
@ OsiModelApplicationLayer
Application layer (layer 7)
Definition: ProtocolType.h:239
DhcpV6MessageType
DHCPv6 message types.
Definition: DhcpV6Layer.h:14
@ DHCPV6_REQUEST
Request message type (Client to Server)
Definition: DhcpV6Layer.h:22
@ DHCPV6_SOLICIT
Solicit message type (Client to Server)
Definition: DhcpV6Layer.h:18
@ DHCPV6_RELAY_REPLY
Relay-Reply message type (Server to Relay agent)
Definition: DhcpV6Layer.h:42
@ DHCPV6_INFORMATION_REQUEST
Information-Request message type (Client to Server)
Definition: DhcpV6Layer.h:38
@ DHCPV6_ADVERTISE
Advertise message type (Server to Client)
Definition: DhcpV6Layer.h:20
@ DHCPV6_REBIND
Rebind message type (Client to Server)
Definition: DhcpV6Layer.h:28
@ DHCPV6_UNKNOWN_MSG_TYPE
Unknown message type.
Definition: DhcpV6Layer.h:16
@ DHCPV6_CONFIRM
Confirm message type (Client to Server)
Definition: DhcpV6Layer.h:24
@ DHCPV6_RENEW
Renew message type (Client to Server)
Definition: DhcpV6Layer.h:26
@ DHCPV6_REPLY
Reply message type (Server to Client)
Definition: DhcpV6Layer.h:30
@ DHCPV6_RECONFIGURE
Reconfigure message type (Server to Client)
Definition: DhcpV6Layer.h:36
@ DHCPV6_DECLINE
Decline message type (Client to Server)
Definition: DhcpV6Layer.h:34
@ DHCPV6_RELEASE
Release message type (Client to Server)
Definition: DhcpV6Layer.h:32
@ DHCPV6_RELAY_FORWARD
Relay-Forward message type (Relay agent to Server)
Definition: DhcpV6Layer.h:40
DhcpV6OptionType
Definition: DhcpV6Layer.h:52
@ DHCPV6_OPT_ERP_LOCAL_DOMAIN_NAME
ERP Local Domain Name.
Definition: DhcpV6Layer.h:173
@ DHCPV6_OPT_NISP_DOMAIN_NAME
Network Information Service v2 (NIS+) domain name.
Definition: DhcpV6Layer.h:112
@ DHCPV6_OPT_CLT_TIME
Client Last Transaction Time.
Definition: DhcpV6Layer.h:143
@ DHCPV6_OPT_CLIENT_DATA
Client Data.
Definition: DhcpV6Layer.h:141
@ DHCPV6_OPT_MUD_URL
Manufacturer Usage Description.
Definition: DhcpV6Layer.h:181
@ DHCPV6_OPT_DOMAIN_LIST
Domain Search List.
Definition: DhcpV6Layer.h:100
@ DHCPV6_OPT_SIP_SERVERS_A
SIP Servers IPv6 Address List.
Definition: DhcpV6Layer.h:96
@ DHCPV6_OPT_PANA_AGENT
Definition: DhcpV6Layer.h:131
@ DHCPV6_OPT_MIP6_HNINF
Mobile IPv6 Home Network Information.
Definition: DhcpV6Layer.h:149
@ DHCPV6_OPT_MIP6_RELAY
Mobile IPv6 Relay Agent.
Definition: DhcpV6Layer.h:151
@ DHCPV6_OPT_IPV6_FQDN_MOS
List of FQDNs for servers providing particular types of IEEE 802.21 Mobility Service (MoS)
Definition: DhcpV6Layer.h:161
@ DHCPV6_OPT_IA_NA
Identity Association for Non-temporary addresses.
Definition: DhcpV6Layer.h:60
@ DHCPV6_OPT_USER_CLASS
User class.
Definition: DhcpV6Layer.h:82
@ DHCPV6_OPT_NIS_SERVERS
Network Information Service (NIS) Servers.
Definition: DhcpV6Layer.h:106
@ DHCPV6_OPT_LQ_QUERY
Query option.
Definition: DhcpV6Layer.h:139
@ DHCPV6_OPT_RELAY_MSG
The DHCP message being relayed by a relay agent.
Definition: DhcpV6Layer.h:72
@ DHCPV6_OPT_SUBSCRIBER_ID
Relay Agent Subscriber ID.
Definition: DhcpV6Layer.h:126
@ DHCPV6_OPT_IA_TA
Identity Association for Temporary addresses.
Definition: DhcpV6Layer.h:62
@ DHCPV6_OPT_LQ_RELAY_DATA
Relay data.
Definition: DhcpV6Layer.h:145
@ DHCPV6_OPT_NTP_SERVER
Network Time Protocol (NTP) or Simple NTP (SNTP) Server Location.
Definition: DhcpV6Layer.h:163
@ DHCPV6_OPT_NEW_POSIX_TIMEZONE
Time zone to be used by the client in IEEE 1003.1 format.
Definition: DhcpV6Layer.h:133
@ DHCPV6_OPT_IPH6_ADDRESS_MOS
List of IPv6 addresses for servers providing particular types of IEEE 802.21 Mobility Service (MoS)
Definition: DhcpV6Layer.h:159
@ DHCPV6_OPT_CLIENT_FQDN
FQDN.
Definition: DhcpV6Layer.h:128
@ DHCPV6_OPT_INTERFACE_ID
Interface ID.
Definition: DhcpV6Layer.h:88
@ DHCPV6_OPT_BOOTFILE_URL
Boot File Uniform Resource Locator (URL)
Definition: DhcpV6Layer.h:165
@ DHCPV6_OPT_NEW_TZDB_TIMEZONE
Time zone (TZ) database entry referred to by entry name.
Definition: DhcpV6Layer.h:135
@ DHCPV6_OPT_BOOTFILE_PARAM
Boot File Parameters.
Definition: DhcpV6Layer.h:167
@ DHCPV6_OPT_DNS_SERVERS
DNS Recursive Name Server.
Definition: DhcpV6Layer.h:98
@ DHCPV6_OPT_CLIENT_ARCH_TYPE
Client System Architecture Type.
Definition: DhcpV6Layer.h:169
@ DHCPV6_OPT_AUTH
Authentication information.
Definition: DhcpV6Layer.h:74
@ DHCPV6_OPT_STATUS_CODE
Status code.
Definition: DhcpV6Layer.h:78
@ DHCPV6_OPT_SIP_SERVERS_D
SIP Servers Domain Name.
Definition: DhcpV6Layer.h:94
@ DHCPV6_OPT_UNKNOWN
Unknown option type.
Definition: DhcpV6Layer.h:54
@ DHCPV6_OPT_IAADDR
IA Address option.
Definition: DhcpV6Layer.h:64
@ DHCPV6_OPT_NIS_DOMAIN_NAME
Network Information Service (NIS) domain name.
Definition: DhcpV6Layer.h:110
@ DHCPV6_OPT_REMOTE_ID
Relay Agent Remote ID.
Definition: DhcpV6Layer.h:124
@ DHCPV6_OPT_RECONF_ACCEPT
Reconfigure Accept.
Definition: DhcpV6Layer.h:92
@ DHCPV6_OPT_RAPID_COMMIT
Rapid commit.
Definition: DhcpV6Layer.h:80
@ DHCPV6_OPT_V6_LOST
Location to Service Translation (LoST) server domain name.
Definition: DhcpV6Layer.h:153
@ DHCPV6_OPT_CAPWAP_AC_V6
Access Points (CAPWAP) Access Controller IPv6 addresses.
Definition: DhcpV6Layer.h:155
@ DHCPV6_OPT_VENDOR_CLASS
Vendor class.
Definition: DhcpV6Layer.h:84
@ DHCPV6_OPT_LQ_CLIENT_LINK
Client link.
Definition: DhcpV6Layer.h:147
@ DHCPV6_OPT_BCMCS_SERVER_A
Broadcast and Multicast Service (BCMCS) IPv6 Address List.
Definition: DhcpV6Layer.h:120
@ DHCPV6_OPT_NII
Client Network Interface Identifier.
Definition: DhcpV6Layer.h:171
@ DHCPV6_OPT_INFORMATION_REFRESH_TIME
Information Refresh.
Definition: DhcpV6Layer.h:116
@ DHCPV6_OPT_IA_PD
Identity Association for Prefix Delegation.
Definition: DhcpV6Layer.h:102
@ DHCPV6_OPT_ELAPSED_TIME
The amount of time since the client began the current DHCP transaction.
Definition: DhcpV6Layer.h:70
@ DHCPV6_OPT_RECONF_MSG
Reconfigure Message.
Definition: DhcpV6Layer.h:90
@ DHCPV6_OPT_BCMCS_SERVER_D
Broadcast and Multicast Service (BCMCS) Domain Name List.
Definition: DhcpV6Layer.h:118
@ DHCPV6_OPT_UNICAST
Server unicast.
Definition: DhcpV6Layer.h:76
@ DHCPV6_OPT_ORO
Option Request Option.
Definition: DhcpV6Layer.h:66
@ DHCPV6_OPT_VENDOR_OPTS
Vendor specific information.
Definition: DhcpV6Layer.h:86
@ DHCPV6_OPT_VSS
Virtual Subnet Selection.
Definition: DhcpV6Layer.h:177
@ DHCPV6_OPT_RELAY_SUPPLIED_OPTIONS
Relay supplied options.
Definition: DhcpV6Layer.h:175
@ DHCPV6_OPT_IAPREFIX
IA_PD Prefix.
Definition: DhcpV6Layer.h:104
@ DHCPV6_OPT_SERVERID
Server Identifier (DUID of server)
Definition: DhcpV6Layer.h:58
@ DHCPV6_OPT_CLIENTID
Client Identifier (DUID of client)
Definition: DhcpV6Layer.h:56
@ DHCPV6_OPT_ERO
Relay Agent Echo Request.
Definition: DhcpV6Layer.h:137
@ DHCPV6_OPT_CLIENT_LINKLAYER_ADDR
Client link layer.
Definition: DhcpV6Layer.h:179
@ DHCPV6_OPT_GEOCONF_CIVIC
Geographical location in civic (e.g., postal) format.
Definition: DhcpV6Layer.h:122
@ DHCPV6_OPT_PREFERENCE
Preference setting.
Definition: DhcpV6Layer.h:68
@ DHCPV6_OPT_SNTP_SERVERS
Simple Network Time Protocol (SNTP) servers.
Definition: DhcpV6Layer.h:114
@ DHCPV6_OPT_RELAY_ID
DHCPv6 Bulk LeaseQuery.
Definition: DhcpV6Layer.h:157
@ DHCPV6_OPT_NISP_SERVERS
Network Information Service v2 (NIS+) Servers.
Definition: DhcpV6Layer.h:108
Definition: DhcpV6Layer.h:242
uint8_t messageType
DHCPv6 message type.
Definition: DhcpV6Layer.h:244
uint8_t transactionId3
DHCPv6 transaction ID (last byte)
Definition: DhcpV6Layer.h:250
uint8_t transactionId2
DHCPv6 transaction ID (second byte)
Definition: DhcpV6Layer.h:248
uint8_t transactionId1
DHCPv6 transaction ID (first byte)
Definition: DhcpV6Layer.h:246