Kea: pkt6.h Source File

| Kea 3.2.0-git

pkt6.h
Go to the documentation of this file.
1// Copyright (C) 2011-2025 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
31 typedef boost::shared_ptr<Pkt6> Pkt6Ptr;
32
44 class 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
53 enum DHCPv6Proto {
54 UDP = 0, // most packets are UDP
55 TCP = 1 // there are TCP DHCPv6 packets (bulk leasequery, failover)
56 };
57
74 enum RelaySearchOrder {
75 RELAY_SEARCH_FROM_CLIENT = 1,
76 RELAY_SEARCH_FROM_SERVER = 2,
77 RELAY_GET_FIRST = 3,
78 RELAY_GET_LAST = 4
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_;
96 isc::asiolink::IOAddress linkaddr_;
97 isc::asiolink::IOAddress peeraddr_;
98
101 uint16_t relay_msg_len_;
102
104 isc::dhcp::OptionCollection options_;
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
149 DHCPv6Proto getProto() {
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
206 virtual std::string toText(bool verbose = false) const;
207
218 virtual size_t len();
219
223 virtual uint8_t getType() const { return (msg_type_); }
224
228 virtual void setType(uint8_t type) { msg_type_=type; }
229
235 DuidPtr getClientId() const;
236
237
238protected:
239
253 OptionPtr getNonCopiedRelayOption(const uint16_t opt_type,
254 const uint8_t relay_level) const;
255
269 OptionCollection getNonCopiedRelayOptions(const uint16_t opt_type,
270 const uint8_t relay_level) const;
271
272public:
273
289 OptionPtr getRelayOption(uint16_t option_code, uint8_t nesting_level);
290
306 OptionCollection getRelayOptions(uint16_t option_code,
307 uint8_t nesting_level);
308
309private:
310
327 void prepareGetAnyRelayOption(const RelaySearchOrder& order,
328 int& start, int& end, int& direction) const;
329
330protected:
331
344 OptionPtr getNonCopiedAnyRelayOption(const uint16_t option_code,
345 const RelaySearchOrder& order) const;
346
359 OptionCollection getNonCopiedAllRelayOptions(const uint16_t option_code,
360 const RelaySearchOrder& order) const;
361
362public:
363
374 OptionPtr getAnyRelayOption(const uint16_t option_code,
375 const RelaySearchOrder& order);
376
389 OptionCollection getAllRelayOptions(const uint16_t option_code,
390 const RelaySearchOrder& order);
391
405 const isc::asiolink::IOAddress&
406 getRelay6LinkAddress(uint8_t relay_level) const;
407
421 const isc::asiolink::IOAddress&
422 getRelay6PeerAddress(uint8_t relay_level) const;
423
430 void addRelayInfo(const RelayInfo& relay);
431
443 static const char* getName(const uint8_t type);
444
453 const char* getName() const;
454
461 void copyRelayInfo(const Pkt6Ptr& question);
462
476 std::vector<RelayInfo> relay_info_;
477
478protected:
479
488 virtual HWAddrPtr getMACFromSrcLinkLocalAddr();
489
491 // option inserted by a relay agent (RFC6939).
494 // client-linklayer-addr option inserted by the relay agent closest to
495 // the client.
498 virtual HWAddrPtr getMACFromIPv6RelayOpt();
499
508 virtual HWAddrPtr getMACFromDUID();
509
522 virtual HWAddrPtr getMACFromDocsisModem();
523
535 virtual HWAddrPtr getMACFromDocsisCMTS();
536
545 virtual HWAddrPtr getMACFromRemoteIdRelayOption();
546
552 void packTCP();
553
557 void packUDP();
558
569 void unpackTCP();
570
579 void unpackUDP();
580
590 void unpackMsg(OptionBuffer::const_iterator begin,
591 OptionBuffer::const_iterator end);
592
600 void unpackRelayMsg();
601
607 uint16_t getRelayOverhead(const RelayInfo& relay) const;
608
611 uint16_t calculateRelaySizes();
612
617 uint16_t directLen() const;
618
620 DHCPv6Proto proto_;
621
623 uint8_t msg_type_;
624
625}; // Pkt6 class
626
627} // isc::dhcp namespace
628} // isc namespace
629
630#endif
isc::asiolink::IOAddress
The IOAddress class represents an IP addresses (version agnostic).
Definition io_address.h:53
isc::dhcp::Pkt6
Represents a DHCPv6 packet.
Definition pkt6.h:44
isc::dhcp::Pkt6::calculateRelaySizes
uint16_t calculateRelaySizes()
Calculates overhead for all relays defined for this message.
Definition pkt6.cc:354
isc::dhcp::Pkt6::getMACFromIPv6RelayOpt
virtual HWAddrPtr getMACFromIPv6RelayOpt()
Extract MAC/Hardware address from client link-layer address.
Definition pkt6.cc:927
isc::dhcp::Pkt6::DHCPv6Proto
DHCPv6Proto
DHCPv6 transport protocol.
Definition pkt6.h:53
isc::dhcp::Pkt6::UDP
@ UDP
Definition pkt6.h:54
isc::dhcp::Pkt6::TCP
@ TCP
Definition pkt6.h:55
isc::dhcp::Pkt6::getLabel
virtual std::string getLabel() const
Returns text representation of the primary packet identifiers.
Definition pkt6.cc:720
isc::dhcp::Pkt6::setType
virtual void setType(uint8_t type)
Sets message type (e.g.
Definition pkt6.h:228
isc::dhcp::Pkt6::getRelayOptions
OptionCollection getRelayOptions(uint16_t option_code, uint8_t nesting_level)
Returns options inserted by relay.
Definition pkt6.cc:296
isc::dhcp::Pkt6::DHCPV6_PKT_HDR_LEN
static const size_t DHCPV6_PKT_HDR_LEN
specifies non-relayed DHCPv6 packet header length (over UDP)
Definition pkt6.h:47
isc::dhcp::Pkt6::len
virtual size_t len()
Returns length of the packet.
Definition pkt6.cc:63
isc::dhcp::Pkt6::pack
virtual void pack()
Prepares on-wire format.
Definition pkt6.cc:377
isc::dhcp::Pkt6::getRelayOption
OptionPtr getRelayOption(uint16_t option_code, uint8_t nesting_level)
Returns option inserted by relay.
Definition pkt6.cc:259
isc::dhcp::Pkt6::getMACFromRemoteIdRelayOption
virtual HWAddrPtr getMACFromRemoteIdRelayOption()
Attempts to obtain MAC address from remote-id relay option.
Definition pkt6.cc:1017
isc::dhcp::Pkt6::unpackTCP
void unpackTCP()
Parses on-wire form of TCP DHCPv6 packet.
Definition pkt6.cc:635
isc::dhcp::Pkt6::getName
const char * getName() const
Returns name of the DHCPv6 message.
Definition pkt6.cc:878
isc::dhcp::Pkt6::getProto
DHCPv6Proto getProto()
Returns protocol of this packet (UDP or TCP).
Definition pkt6.h:149
isc::dhcp::Pkt6::getMACFromSrcLinkLocalAddr
virtual HWAddrPtr getMACFromSrcLinkLocalAddr()
Attempts to generate MAC/Hardware address from IPv6 link-local address.
Definition pkt6.cc:916
isc::dhcp::Pkt6::getNonCopiedRelayOption
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:241
isc::dhcp::Pkt6::unpackRelayMsg
void unpackRelayMsg()
Unpacks relayed message (RELAY-FORW or RELAY-REPL).
Definition pkt6.cc:548
isc::dhcp::Pkt6::RelaySearchOrder
RelaySearchOrder
defines relay search pattern
Definition pkt6.h:74
isc::dhcp::Pkt6::RELAY_GET_LAST
@ RELAY_GET_LAST
Definition pkt6.h:78
isc::dhcp::Pkt6::RELAY_SEARCH_FROM_CLIENT
@ RELAY_SEARCH_FROM_CLIENT
Definition pkt6.h:75
isc::dhcp::Pkt6::RELAY_GET_FIRST
@ RELAY_GET_FIRST
Definition pkt6.h:77
isc::dhcp::Pkt6::RELAY_SEARCH_FROM_SERVER
@ RELAY_SEARCH_FROM_SERVER
Definition pkt6.h:76
isc::dhcp::Pkt6::makeLabel
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:693
isc::dhcp::Pkt6::getAnyRelayOption
OptionPtr getAnyRelayOption(const uint16_t option_code, const RelaySearchOrder &order)
Return first instance of a specified option.
Definition pkt6.cc:138
isc::dhcp::Pkt6::getClientId
DuidPtr getClientId() const
Retrieves the DUID from the Client Identifier option.
Definition pkt6.cc:767
isc::dhcp::Pkt6::packTCP
void packTCP()
Builds on wire packet for TCP transmission.
Definition pkt6.cc:453
isc::dhcp::Pkt6::getNonCopiedAnyRelayOption
OptionPtr getNonCopiedAnyRelayOption(const uint16_t option_code, const RelaySearchOrder &order) const
Returns pointer to an instance of specified option.
Definition pkt6.cc:106
isc::dhcp::Pkt6::copyRelayInfo
void copyRelayInfo(const Pkt6Ptr &question)
copies relay information from client's packet to server's response
Definition pkt6.cc:882
isc::dhcp::Pkt6::toText
virtual std::string toText(bool verbose=false) const
Returns text representation of the packet.
Definition pkt6.cc:728
isc::dhcp::Pkt6::proto_
DHCPv6Proto proto_
UDP (usually) or TCP (bulk leasequery or failover).
Definition pkt6.h:620
isc::dhcp::Pkt6::getRelay6PeerAddress
const isc::asiolink::IOAddress & getRelay6PeerAddress(uint8_t relay_level) const
return the peer address field from a relay option
Definition pkt6.cc:334
isc::dhcp::Pkt6::unpack
virtual void unpack()
Dispatch method that handles binary packet parsing.
Definition pkt6.cc:460
isc::dhcp::Pkt6::getAllRelayOptions
OptionCollection getAllRelayOptions(const uint16_t option_code, const RelaySearchOrder &order)
Return first instances of a specified option.
Definition pkt6.cc:201
isc::dhcp::Pkt6::getMACFromDUID
virtual HWAddrPtr getMACFromDUID()
Extract MAC/Hardware address from client-id.
Definition pkt6.cc:641
isc::dhcp::Pkt6::getMACFromDocsisCMTS
virtual HWAddrPtr getMACFromDocsisCMTS()
Attempts to extract MAC/Hardware address from DOCSIS options.
Definition pkt6.cc:983
isc::dhcp::Pkt6::getRelay6LinkAddress
const isc::asiolink::IOAddress & getRelay6LinkAddress(uint8_t relay_level) const
return the link address field from a relay option
Definition pkt6.cc:324
isc::dhcp::Pkt6::getNonCopiedAllRelayOptions
OptionCollection getNonCopiedAllRelayOptions(const uint16_t option_code, const RelaySearchOrder &order) const
Returns pointers to instances of specified option.
Definition pkt6.cc:171
isc::dhcp::Pkt6::relay_info_
std::vector< RelayInfo > relay_info_
Relay information.
Definition pkt6.h:476
isc::dhcp::Pkt6::setProto
void setProto(DHCPv6Proto proto=UDP)
Sets protocol of this packet.
Definition pkt6.h:156
isc::dhcp::Pkt6::msg_type_
uint8_t msg_type_
DHCPv6 message type.
Definition pkt6.h:623
isc::dhcp::Pkt6::Pkt6
Pkt6(uint8_t msg_type, uint32_t transid, DHCPv6Proto proto=UDP)
Constructor, used in replying to a message.
Definition pkt6.cc:58
isc::dhcp::Pkt6::addRelayInfo
void addRelayInfo(const RelayInfo &relay)
add information about one traversed relay
Definition pkt6.cc:625
isc::dhcp::Pkt6::getMACFromDocsisModem
virtual HWAddrPtr getMACFromDocsisModem()
Attempts to extract MAC/Hardware address from DOCSIS options inserted by the modem itself.
Definition pkt6.cc:955
isc::dhcp::Pkt6::getNonCopiedRelayOptions
OptionCollection getNonCopiedRelayOptions(const uint16_t opt_type, const uint8_t relay_level) const
Returns all option instances inserted by relay agent.
Definition pkt6.cc:280
isc::dhcp::Pkt6::packUDP
void packUDP()
Builds on wire packet for UDP transmission.
Definition pkt6.cc:391
isc::dhcp::Pkt6::unpackUDP
void unpackUDP()
Parses on-wire form of UDP DHCPv6 packet.
Definition pkt6.cc:472
isc::dhcp::Pkt6::unpackMsg
void unpackMsg(OptionBuffer::const_iterator begin, OptionBuffer::const_iterator end)
Unpacks direct (non-relayed) message.
Definition pkt6.cc:504
isc::dhcp::Pkt6::directLen
uint16_t directLen() const
Calculates size of the message as if it was not relayed at all.
Definition pkt6.cc:366
isc::dhcp::Pkt6::getRelayOverhead
uint16_t getRelayOverhead(const RelayInfo &relay) const
Calculates overhead introduced in specified relay.
Definition pkt6.cc:343
isc::dhcp::Pkt6::getType
virtual uint8_t getType() const
Returns message type (e.g.
Definition pkt6.h:223
isc::dhcp::Pkt6::DHCPV6_RELAY_HDR_LEN
static const size_t DHCPV6_RELAY_HDR_LEN
specifies relay DHCPv6 packet header length (over UDP)
Definition pkt6.h:50
isc::dhcp::Pkt::Pkt
Pkt(uint32_t transid, const isc::asiolink::IOAddress &local_addr, const isc::asiolink::IOAddress &remote_addr, uint16_t local_port, uint16_t remote_port)
Constructor.
Definition pkt.cc:24
duid.h
io_address.h
isc::dhcp
Definition dhcp4/client_handler.cc:20
isc::dhcp::DuidPtr
boost::shared_ptr< DUID > DuidPtr
Definition duid.h:136
isc::dhcp::OptionCollection
std::multimap< unsigned int, OptionPtr > OptionCollection
A collection of DHCP (v4 or v6) options.
Definition option.h:40
isc::dhcp::HWAddrPtr
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
Definition hwaddr.h:154
isc::dhcp::Pkt6Ptr
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
Definition pkt6.h:31
isc::dhcp::OptionPtr
boost::shared_ptr< Option > OptionPtr
Definition option.h:37
isc
Defines the logger used by the top-level component of kea-lfc.
Definition check_exists_add.cc:18
option.h
pkt.h
isc::dhcp::Pkt6::RelayInfo
structure that describes a single relay information
Definition pkt6.h:85
isc::dhcp::Pkt6::RelayInfo::RelayInfo
RelayInfo()
default constructor
Definition pkt6.cc:35
isc::dhcp::Pkt6::RelayInfo::relay_msg_len_
uint16_t relay_msg_len_
length of the relay_msg_len Used when calculating length during pack/unpack
Definition pkt6.h:101
isc::dhcp::Pkt6::RelayInfo::options_
isc::dhcp::OptionCollection options_
options received from a specified relay, except relay-msg option
Definition pkt6.h:104
isc::dhcp::Pkt6::RelayInfo::msg_type_
uint8_t msg_type_
message type (RELAY-FORW oro RELAY-REPL)
Definition pkt6.h:94
isc::dhcp::Pkt6::RelayInfo::toText
std::string toText() const
Returns printable representation of the relay information.
Definition pkt6.cc:40
isc::dhcp::Pkt6::RelayInfo::linkaddr_
isc::asiolink::IOAddress linkaddr_
fixed field in relay-forw/relay-reply
Definition pkt6.h:96
isc::dhcp::Pkt6::RelayInfo::hop_count_
uint8_t hop_count_
number of traversed relays (up to 32)
Definition pkt6.h:95
isc::dhcp::Pkt6::RelayInfo::peeraddr_
isc::asiolink::IOAddress peeraddr_
fixed field in relay-forw/relay-reply
Definition pkt6.h:97