Kea 2.2.0
pkt6.h
Go to the documentation of this file.
1// Copyright (C) 2011-2022 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef PKT6_H
8#define PKT6_H
9
10#include <asiolink/io_address.h>
11#include <dhcp/duid.h>
12#include <dhcp/option.h>
13#include <dhcp/pkt.h>
14
15#include <boost/date_time/posix_time/posix_time.hpp>
16#include <boost/shared_array.hpp>
17#include <boost/shared_ptr.hpp>
18
19#include <iostream>
20#include <set>
21
22#include <time.h>
23
24namespace isc {
25
26namespace dhcp {
27
28class Pkt6;
29
31typedef boost::shared_ptr<Pkt6> Pkt6Ptr;
32
44class Pkt6 : public Pkt {
45public:
47 const static size_t DHCPV6_PKT_HDR_LEN = 4;
48
50 const static size_t DHCPV6_RELAY_HDR_LEN = 34;
51
54 UDP = 0, // most packets are UDP
55 TCP = 1 // there are TCP DHCPv6 packets (bulk leasequery, failover)
56 };
57
79 };
80
85 struct RelayInfo {
86
88 RelayInfo();
89
92 std::string toText() const;
93
94 uint8_t msg_type_;
95 uint8_t hop_count_;
98
102
105 };
106
112 Pkt6(uint8_t msg_type,
113 uint32_t transid,
114 DHCPv6Proto proto = UDP);
115
123 Pkt6(const uint8_t* buf, uint32_t len, DHCPv6Proto proto = UDP);
124
136 virtual void pack();
137
144 virtual void unpack();
145
150 return (proto_);
151 }
152
156 void setProto(DHCPv6Proto proto = UDP) {
157 proto_ = proto;
158 }
159
172 static std::string makeLabel(const DuidPtr duid, const uint32_t transid,
173 const HWAddrPtr& hwaddr);
174
183 static std::string makeLabel(const DuidPtr duid, const HWAddrPtr& hwaddr);
184
196 virtual std::string getLabel() const;
197
203 virtual std::string toText() const;
204
215 virtual size_t len();
216
220 virtual uint8_t getType() const { return (msg_type_); }
221
225 virtual void setType(uint8_t type) { msg_type_=type; };
226
232 DuidPtr getClientId() const;
233
234
235protected:
236
250 OptionPtr getNonCopiedRelayOption(const uint16_t opt_type,
251 const uint8_t relay_level) const;
252
253public:
254
270 OptionPtr getRelayOption(uint16_t option_code, uint8_t nesting_level);
271
272private:
273
290 void prepareGetAnyRelayOption(const RelaySearchOrder& order,
291 int& start, int& end, int& direction) const;
292
293protected:
294
307 OptionPtr getNonCopiedAnyRelayOption(const uint16_t option_code,
308 const RelaySearchOrder& order) const;
309
310public:
311
322 OptionPtr getAnyRelayOption(const uint16_t option_code,
323 const RelaySearchOrder& order);
324
339 getRelay6LinkAddress(uint8_t relay_level) const;
340
355 getRelay6PeerAddress(uint8_t relay_level) const;
356
357protected:
358
371 OptionCollection getNonCopiedOptions(const uint16_t opt_type) const;
372
373public:
374
382 isc::dhcp::OptionCollection getOptions(const uint16_t type);
383
390 void addRelayInfo(const RelayInfo& relay);
391
403 static const char* getName(const uint8_t type);
404
413 const char* getName() const;
414
421 void copyRelayInfo(const Pkt6Ptr& question);
422
436 std::vector<RelayInfo> relay_info_;
437
438protected:
439
449
451 // option inserted by a relay agent (RFC6939).
454 // client-linklayer-addr option inserted by the relay agent closest to
455 // the client.
459
468 virtual HWAddrPtr getMACFromDUID();
469
483
496
506
512 void packTCP();
513
517 void packUDP();
518
529 void unpackTCP();
530
539 void unpackUDP();
540
550 void unpackMsg(OptionBuffer::const_iterator begin,
551 OptionBuffer::const_iterator end);
552
560 void unpackRelayMsg();
561
567 uint16_t getRelayOverhead(const RelayInfo& relay) const;
568
571 uint16_t calculateRelaySizes();
572
577 uint16_t directLen() const;
578
581
583 uint8_t msg_type_;
584
585}; // Pkt6 class
586
587} // isc::dhcp namespace
588} // isc namespace
589
590#endif
Represents a DHCPv6 packet.
Definition: pkt6.h:44
virtual std::string toText() const
Returns text representation of the packet.
Definition: pkt6.cc:619
uint16_t calculateRelaySizes()
Calculates overhead for all relays defined for this message.
Definition: pkt6.cc:241
virtual HWAddrPtr getMACFromIPv6RelayOpt()
Extract MAC/Hardware address from client link-layer address.
Definition: pkt6.cc:819
OptionCollection getNonCopiedOptions(const uint16_t opt_type) const
Returns all option instances of specified type without copying.
Definition: pkt6.cc:665
DHCPv6Proto
DHCPv6 transport protocol.
Definition: pkt6.h:53
virtual std::string getLabel() const
Returns text representation of the primary packet identifiers.
Definition: pkt6.cc:611
virtual void setType(uint8_t type)
Sets message type (e.g.
Definition: pkt6.h:225
static const size_t DHCPV6_PKT_HDR_LEN
specifies non-relayed DHCPv6 packet header length (over UDP)
Definition: pkt6.h:47
virtual size_t len()
Returns length of the packet.
Definition: pkt6.cc:63
virtual void pack()
Prepares on-wire format.
Definition: pkt6.cc:265
OptionPtr getRelayOption(uint16_t option_code, uint8_t nesting_level)
Returns option inserted by relay.
Definition: pkt6.cc:190
virtual HWAddrPtr getMACFromRemoteIdRelayOption()
Attempts to obtain MAC address from remote-id relay option.
Definition: pkt6.cc:896
void unpackTCP()
Parses on-wire form of TCP DHCPv6 packet.
Definition: pkt6.cc:522
const char * getName() const
Returns name of the DHCPv6 message.
Definition: pkt6.cc:770
DHCPv6Proto getProto()
Returns protocol of this packet (UDP or TCP).
Definition: pkt6.h:149
virtual HWAddrPtr getMACFromSrcLinkLocalAddr()
Attempts to generate MAC/Hardware address from IPv6 link-local address.
Definition: pkt6.cc:808
OptionPtr getNonCopiedRelayOption(const uint16_t opt_type, const uint8_t relay_level) const
Returns pointer to an option inserted by relay agent.
Definition: pkt6.cc:172
void unpackRelayMsg()
Unpacks relayed message (RELAY-FORW or RELAY-REPL).
Definition: pkt6.cc:435
RelaySearchOrder
defines relay search pattern
Definition: pkt6.h:74
@ RELAY_GET_LAST
Definition: pkt6.h:78
@ RELAY_SEARCH_FROM_CLIENT
Definition: pkt6.h:75
@ RELAY_GET_FIRST
Definition: pkt6.h:77
@ RELAY_SEARCH_FROM_SERVER
Definition: pkt6.h:76
static std::string makeLabel(const DuidPtr duid, const uint32_t transid, const HWAddrPtr &hwaddr)
Returns text representation of the given packet identifiers.
Definition: pkt6.cc:580
OptionPtr getAnyRelayOption(const uint16_t option_code, const RelaySearchOrder &order)
Return first instance of a specified option.
Definition: pkt6.cc:139
DuidPtr getClientId() const
Retrieves the DUID from the Client Identifier option.
Definition: pkt6.cc:648
void packTCP()
Builds on wire packet for TCP transmission.
Definition: pkt6.cc:342
OptionPtr getNonCopiedAnyRelayOption(const uint16_t option_code, const RelaySearchOrder &order) const
Returns pointer to an instance of specified option.
Definition: pkt6.cc:107
isc::dhcp::OptionCollection getOptions(const uint16_t type)
Returns all instances of specified type.
Definition: pkt6.cc:672
void copyRelayInfo(const Pkt6Ptr &question)
copies relay information from client's packet to server's response
Definition: pkt6.cc:774
DHCPv6Proto proto_
UDP (usually) or TCP (bulk leasequery or failover)
Definition: pkt6.h:580
const isc::asiolink::IOAddress & getRelay6PeerAddress(uint8_t relay_level) const
return the peer address field from a relay option
Definition: pkt6.cc:221
virtual void unpack()
Dispatch method that handles binary packet parsing.
Definition: pkt6.cc:349
virtual HWAddrPtr getMACFromDUID()
Extract MAC/Hardware address from client-id.
Definition: pkt6.cc:528
virtual HWAddrPtr getMACFromDocsisCMTS()
Attempts to extract MAC/Hardware address from DOCSIS options.
Definition: pkt6.cc:869
const isc::asiolink::IOAddress & getRelay6LinkAddress(uint8_t relay_level) const
return the link address field from a relay option
Definition: pkt6.cc:211
std::vector< RelayInfo > relay_info_
Relay information.
Definition: pkt6.h:436
void setProto(DHCPv6Proto proto=UDP)
Sets protocol of this packet.
Definition: pkt6.h:156
uint8_t msg_type_
DHCPv6 message type.
Definition: pkt6.h:583
Pkt6(uint8_t msg_type, uint32_t transid, DHCPv6Proto proto=UDP)
Constructor, used in replying to a message.
Definition: pkt6.cc:58
void addRelayInfo(const RelayInfo &relay)
add information about one traversed relay
Definition: pkt6.cc:512
virtual HWAddrPtr getMACFromDocsisModem()
Attempts to extract MAC/Hardware address from DOCSIS options inserted by the modem itself.
Definition: pkt6.cc:847
void packUDP()
Builds on wire packet for UDP transmission.
Definition: pkt6.cc:279
void unpackUDP()
Parses on-wire form of UDP DHCPv6 packet.
Definition: pkt6.cc:361
void unpackMsg(OptionBuffer::const_iterator begin, OptionBuffer::const_iterator end)
Unpacks direct (non-relayed) message.
Definition: pkt6.cc:391
uint16_t directLen() const
Calculates size of the message as if it was not relayed at all.
Definition: pkt6.cc:253
uint16_t getRelayOverhead(const RelayInfo &relay) const
Calculates overhead introduced in specified relay.
Definition: pkt6.cc:230
virtual uint8_t getType() const
Returns message type (e.g.
Definition: pkt6.h:220
static const size_t DHCPV6_RELAY_HDR_LEN
specifies relay DHCPv6 packet header length (over UDP)
Definition: pkt6.h:50
Base class for classes representing DHCP messages.
Definition: pkt.h:90
boost::shared_ptr< DUID > DuidPtr
Definition: duid.h:20
std::multimap< unsigned int, OptionPtr > OptionCollection
A collection of DHCP (v4 or v6) options.
Definition: option.h:40
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
Definition: hwaddr.h:154
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
Definition: pkt6.h:28
boost::shared_ptr< Option > OptionPtr
Definition: option.h:36
Defines the logger used by the top-level component of kea-lfc.
structure that describes a single relay information
Definition: pkt6.h:85
RelayInfo()
default constructor
Definition: pkt6.cc:35
uint16_t relay_msg_len_
length of the relay_msg_len Used when calculating length during pack/unpack
Definition: pkt6.h:101
isc::dhcp::OptionCollection options_
options received from a specified relay, except relay-msg option
Definition: pkt6.h:104
uint8_t msg_type_
message type (RELAY-FORW oro RELAY-REPL)
Definition: pkt6.h:94
std::string toText() const
Returns printable representation of the relay information.
Definition: pkt6.cc:40
isc::asiolink::IOAddress linkaddr_
fixed field in relay-forw/relay-reply
Definition: pkt6.h:96
uint8_t hop_count_
number of traversed relays (up to 32)
Definition: pkt6.h:95
isc::asiolink::IOAddress peeraddr_
fixed field in relay-forw/relay-reply
Definition: pkt6.h:97