Kea: isc::dhcp::Pkt6 Class Reference

| Kea 3.0.0

isc::dhcp::Pkt6 Class Reference

Represents a DHCPv6 packet. More...

`#include <pkt6.h>`

Inheritance diagram for isc::dhcp::Pkt6:
[legend]

## Classes
struct | RelayInfo
| structure that describes a single relay information More...

## Public Types
enum | DHCPv6Proto { UDP = 0 , TCP = 1 }
| DHCPv6 transport protocol. More...
enum | RelaySearchOrder { RELAY_SEARCH_FROM_CLIENT = 1 , RELAY_SEARCH_FROM_SERVER = 2 , RELAY_GET_FIRST = 3 , RELAY_GET_LAST = 4 }
| defines relay search pattern More...

## Public Member Functions
| Pkt6 (const uint8_t *buf, uint32_t len, DHCPv6Proto proto=UDP)
| Constructor, used in message transmission.
| Pkt6 (uint8_t msg_type, uint32_t transid, DHCPv6Proto proto=UDP)
| Constructor, used in replying to a message.
void | addRelayInfo (const RelayInfo &relay)
| add information about one traversed relay
void | copyRelayInfo (const Pkt6Ptr &question)
| copies relay information from client's packet to server's response
OptionCollection | getAllRelayOptions (const uint16_t option_code, const RelaySearchOrder &order)
| Return first instances of a specified option.
OptionPtr | getAnyRelayOption (const uint16_t option_code, const RelaySearchOrder &order)
| Return first instance of a specified option.
DuidPtr | getClientId () const
| Retrieves the DUID from the Client Identifier option.
virtual std::string | getLabel () const
| Returns text representation of the primary packet identifiers.
const char * | getName () const
| Returns name of the DHCPv6 message.
DHCPv6Proto | getProto ()
| Returns protocol of this packet (UDP or TCP).
const isc::asiolink::IOAddress & | getRelay6LinkAddress (uint8_t relay_level) const
| return the link address field from a relay option
const isc::asiolink::IOAddress & | getRelay6PeerAddress (uint8_t relay_level) const
| return the peer address field from a relay option
OptionPtr | getRelayOption (uint16_t option_code, uint8_t nesting_level)
| Returns option inserted by relay.
OptionCollection | getRelayOptions (uint16_t option_code, uint8_t nesting_level)
| Returns options inserted by relay.
virtual uint8_t | getType () const
| Returns message type (e.g.
virtual size_t | len ()
| Returns length of the packet.
virtual void | pack ()
| Prepares on-wire format.
void | setProto (DHCPv6Proto proto=UDP)
| Sets protocol of this packet.
virtual void | setType (uint8_t type)
| Sets message type (e.g.
virtual std::string | toText () const
| Returns text representation of the packet.
virtual void | unpack ()
| Dispatch method that handles binary packet parsing.
Public Member Functions inherited from isc::dhcp::Pkt
virtual | ~Pkt ()
| Virtual destructor.
void | addAdditionalClass (const isc::dhcp::ClientClass &client_class)
| Adds a specified class to the packet's additional class list.
void | addClass (const isc::dhcp::ClientClass &client_class)
| Adds a specified class to the packet.
virtual void | addOption (const OptionPtr &opt)
| Adds an option to this packet.
void | addPktEvent (const std::string &label, const boost::posix_time::ptime &timestamp=PktEvent::now())
| Adds an event to the end of the event stack.
void | addPktEvent (const std::string &label, const struct timeval &timestamp)
| Adds an event to the end of the event stack with the timestamp specified as a struct timeval.
void | addSubClass (const isc::dhcp::ClientClass &class_def, const isc::dhcp::ClientClass &subclass)
| Adds a specified subclass to the packet.
void | clearPktEvents ()
| Discards contents of the packet event stack.
OptionCollection | cloneOptions ()
| Clones all options so that they can be safely modified.
bool | delOption (uint16_t type)
| Attempts to delete first suboption of requested type.
std::string | dumpPktEvents (bool verbose=false) const
| Creates a dump of the stack contents to a string for logging.
const ClientClasses & | getAdditionalClasses () const
| Returns the additional class list.
isc::util::OutputBuffer & | getBuffer ()
| Returns reference to output buffer.
const ClientClasses & | getClasses () const
| Returns the class set.
std::string | getIface () const
| Returns interface name.
int | getIndex () const
| Returns interface index.
const isc::asiolink::IOAddress & | getLocalAddr () const
| Returns local IP address.
uint16_t | getLocalPort () const
| Returns local UDP (and soon TCP) port.
HWAddrPtr | getMAC (uint32_t hw_addr_src)
| Returns MAC address.
OptionPtr | getOption (const uint16_t type)
| Returns the first option of specified type.
isc::dhcp::OptionCollection | getOptions (const uint16_t type)
| Returns all instances of specified type.
const std::list< PktEvent > & | getPktEvents ()
| Fetches the current event stack contents.
boost::posix_time::ptime | getPktEventTime (const std::string &label) const
| Fetches the timestamp for a given event in the stack.
const isc::asiolink::IOAddress & | getRemoteAddr () const
| Returns remote IP address.
HWAddrPtr | getRemoteHWAddr () const
| Returns the remote HW address obtained from raw sockets.
uint16_t | getRemotePort () const
| Returns remote port.
const SubClassRelationContainer & | getSubClassesRelations () const
| Returns the class set including template classes associated with subclasses.
const boost::posix_time::ptime & | getTimestamp () const
| Returns packet timestamp.
uint32_t | getTransid () const
| Returns value of transaction-id field.
bool | inClass (const isc::dhcp::ClientClass &client_class)
| Checks whether a client belongs to a given class.
bool | indexSet () const
| Checks if interface index has been set.
bool | isCopyRetrievedOptions () const
| Returns whether the copying of retrieved options is enabled.
void | repack ()
| Copies content of input buffer to output buffer.
void | resetIndex ()
| Resets interface index to negative value.
virtual void | setCopyRetrievedOptions (const bool copy)
| Controls whether the option retrieved by the Pkt::getOption should be copied before being returned.
void | setIface (const std::string &iface)
| Sets interface name.
void | setIndex (const unsigned int ifindex)
| Sets interface index.
void | setLocalAddr (const isc::asiolink::IOAddress &local)
| Sets local IP address.
void | setLocalPort (uint16_t local)
| Sets local UDP (and soon TCP) port.
void | setPktEvent (const std::string &label, const boost::posix_time::ptime &timestamp=PktEvent::now())
| Updates (or adds) an event in the event stack.
void | setRemoteAddr (const isc::asiolink::IOAddress &remote)
| Sets remote IP address.
void | setRemoteHWAddr (const HWAddrPtr &hw_addr)
| Sets remote hardware address.
void | setRemoteHWAddr (const uint8_t htype, const uint8_t hlen, const std::vector< uint8_t > &hw_addr)
| Sets remote hardware address.
void | setRemotePort (uint16_t remote)
| Sets remote UDP (and soon TCP) port.
void | setTimestamp (boost::posix_time::ptime &timestamp)
| Set socket receive timestamp.
void | setTransid (uint32_t transid)
| Sets transaction-id value.
void | updateTimestamp ()
| Update packet timestamp.
Public Member Functions inherited from isc::hooks::CalloutHandleAssociate
| CalloutHandleAssociate ()
| Constructor.
CalloutHandlePtr | getCalloutHandle ()
| Returns callout handle.
void | resetCalloutHandle ()
| Reset callout handle.

## Static Public Member Functions
static const char * | getName (const uint8_t type)
| Returns name of the DHCPv6 message for a given type number.
static std::string | makeLabel (const DuidPtr duid, const HWAddrPtr &hwaddr)
| Returns text representation of the given packet identifiers.
static std::string | makeLabel (const DuidPtr duid, const uint32_t transid, const HWAddrPtr &hwaddr)
| Returns text representation of the given packet identifiers.

## Public Attributes
std::vector< RelayInfo > | relay_info_
| Relay information.
Public Attributes inherited from isc::dhcp::Pkt
ClientClasses | additional_classes_
| Classes to be evaluated during additional class evaluation.
ClientClasses | classes_
| Classes this packet belongs to.
OptionBuffer | data_
| Unparsed data (in received packets).
isc::dhcp::OptionCollection | options_
| Collection of options present in this message.
SubClassRelationContainer | subclasses_
| SubClasses this packet belongs to.

## Static Public Attributes
static const size_t | DHCPV6_PKT_HDR_LEN = 4
| specifies non-relayed DHCPv6 packet header length (over UDP)
static const size_t | DHCPV6_RELAY_HDR_LEN = 34
| specifies relay DHCPv6 packet header length (over UDP)

## Protected Member Functions
uint16_t | calculateRelaySizes ()
| Calculates overhead for all relays defined for this message.
uint16_t | directLen () const
| Calculates size of the message as if it was not relayed at all.
virtual HWAddrPtr | getMACFromDocsisCMTS ()
| Attempts to extract MAC/Hardware address from DOCSIS options.
virtual HWAddrPtr | getMACFromDocsisModem ()
| Attempts to extract MAC/Hardware address from DOCSIS options inserted by the modem itself.
virtual HWAddrPtr | getMACFromDUID ()
| Extract MAC/Hardware address from client-id.
virtual HWAddrPtr | getMACFromIPv6RelayOpt ()
| Extract MAC/Hardware address from client link-layer address.
virtual HWAddrPtr | getMACFromRemoteIdRelayOption ()
| Attempts to obtain MAC address from remote-id relay option.
virtual HWAddrPtr | getMACFromSrcLinkLocalAddr ()
| Attempts to generate MAC/Hardware address from IPv6 link-local address.
OptionCollection | getNonCopiedAllRelayOptions (const uint16_t option_code, const RelaySearchOrder &order) const
| Returns pointers to instances of specified option.
OptionPtr | getNonCopiedAnyRelayOption (const uint16_t option_code, const RelaySearchOrder &order) const
| Returns pointer to an instance of specified option.
OptionPtr | getNonCopiedRelayOption (const uint16_t opt_type, const uint8_t relay_level) const
| Returns pointer to an option inserted by relay agent.
OptionCollection | getNonCopiedRelayOptions (const uint16_t opt_type, const uint8_t relay_level) const
| Returns all option instances inserted by relay agent.
uint16_t | getRelayOverhead (const RelayInfo &relay) const
| Calculates overhead introduced in specified relay.
void | packTCP ()
| Builds on wire packet for TCP transmission.
void | packUDP ()
| Builds on wire packet for UDP transmission.
void | unpackMsg (OptionBuffer::const_iterator begin, OptionBuffer::const_iterator end)
| Unpacks direct (non-relayed) message.
void | unpackRelayMsg ()
| Unpacks relayed message (RELAY-FORW or RELAY-REPL).
void | unpackTCP ()
| Parses on-wire form of TCP DHCPv6 packet.
void | unpackUDP ()
| Parses on-wire form of UDP DHCPv6 packet.
Protected Member Functions inherited from isc::dhcp::Pkt
| Pkt (const uint8_t *buf, uint32_t len, const isc::asiolink::IOAddress &local_addr, const isc::asiolink::IOAddress &remote_addr, uint16_t local_port, uint16_t remote_port)
| Constructor.
| 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.
HWAddrPtr | getMACFromIPv6 (const isc::asiolink::IOAddress &addr)
| Attempts to convert IPv6 address into MAC.
OptionPtr | getNonCopiedOption (const uint16_t type) const
| Returns the first option of specified type without copying.
OptionCollection | getNonCopiedOptions (const uint16_t opt_type) const
| Returns all option instances of specified type without copying.

## Protected Attributes
uint8_t | msg_type_
| DHCPv6 message type.
DHCPv6Proto | proto_
| UDP (usually) or TCP (bulk leasequery or failover)
Protected Attributes inherited from isc::dhcp::Pkt
isc::util::OutputBuffer | buffer_out_
| Output buffer (used during message transmission)
bool | copy_retrieved_options_
| Indicates if a copy of the retrieved option should be returned when Pkt::getOption is called.
std::string | iface_
| Name of the network interface the packet was received/to be sent over.
unsigned int | ifindex_
| Interface index.
isc::asiolink::IOAddress | local_addr_
| Local IP (v4 or v6) address.
uint16_t | local_port_
| local TDP or UDP port
isc::asiolink::IOAddress | remote_addr_
| Remote IP address.
HWAddrPtr | remote_hwaddr_
uint16_t | remote_port_
| remote TCP or UDP port
boost::posix_time::ptime | timestamp_
| packet timestamp
uint32_t | transid_
| Transaction-id (32 bits for v4, 24 bits for v6)
Protected Attributes inherited from isc::hooks::CalloutHandleAssociate
CalloutHandlePtr | callout_handle_
| Callout handle stored.

## Detailed Description

Represents a DHCPv6 packet.

This class represents a single DHCPv6 packet. It handles both incoming and transmitted packets, parsing incoming options, options handling (add, get, remove), on-wire assembly, sanity checks and other operations. This specific class has several DHCPv6-specific methods, but it uses a lot of common operations from its base `Pkt` class that is shared with Pkt4.

This class also handles relayed packets. For example, a RELAY-FORW message with a SOLICIT inside will be represented as SOLICIT and the RELAY-FORW layers will be stored in relay_info_ vector.

Definition at line 44 of file pkt6.h.

## Member Enumeration Documentation

## ◆ DHCPv6Proto

enum isc::dhcp::Pkt6::DHCPv6Proto

DHCPv6 transport protocol.

Enumerator
UDP |
TCP |

Definition at line 53 of file pkt6.h.

## ◆ RelaySearchOrder

enum isc::dhcp::Pkt6::RelaySearchOrder

defines relay search pattern

Defines order in which options are searched in a message that passed through multiple relays. RELAY_SEACH_FROM_CLIENT will start search from the relay that was the closest to the client (i.e. innermost in the encapsulated message, which also means this was the first relay that forwarded packet received by the server and this will be the last relay that will handle the response that server sent towards the client.). RELAY_SEARCH_FROM_SERVER is the opposite. This will be the relay closest to the server (i.e. outermost in the encapsulated message, which also means it was the last relay that relayed the received message and will be the first one to process server's response). RELAY_GET_FIRST will try to get option from the first relay only (closest to the client), RELAY_GET_LAST will try to get option form the last relay (closest to the server).

Enumerator
RELAY_SEARCH_FROM_CLIENT |
RELAY_SEARCH_FROM_SERVER |
RELAY_GET_FIRST |
RELAY_GET_LAST |

Definition at line 74 of file pkt6.h.

## Constructor & Destructor Documentation

## ◆ Pkt6() [1/2]

isc::dhcp::Pkt6::Pkt6 | ( | uint8_t | msg_type,
|  | uint32_t | transid,
|  | DHCPv6Proto | proto = UDP )

Constructor, used in replying to a message.

Parameters

  msg_type | type of message (SOLICIT=1, ADVERTISE=2, ...)
  transid | transaction-id
  proto | protocol (TCP or UDP)

Definition at line 58 of file pkt6.cc.

References isc::dhcp::Pkt::Pkt(), DEFAULT_ADDRESS6, msg_type_, and proto_.

Referenced by isc::perfdhcp::PerfPkt6::PerfPkt6().

Here is the call graph for this function:

## ◆ Pkt6() [2/2]

isc::dhcp::Pkt6::Pkt6 | ( | const uint8_t * | buf,
|  | uint32_t | len,
|  | DHCPv6Proto | proto = UDP )

Constructor, used in message transmission.

Creates new message. Transaction-id will randomized.

Parameters

  buf | pointer to a buffer of received packet content
  len | size of buffer of received packet content
  proto | protocol (usually UDP, but TCP will be supported eventually)

Definition at line 53 of file pkt6.cc.

References isc::dhcp::Pkt::Pkt(), DEFAULT_ADDRESS6, msg_type_, and proto_.

Here is the call graph for this function:

## Member Function Documentation

## ◆ addRelayInfo()

void isc::dhcp::Pkt6::addRelayInfo | ( | const RelayInfo & | relay | ) |

add information about one traversed relay

This adds information about one traversed relay, i.e. one relay-forw or relay-repl level of encapsulation.

Parameters

  relay | structure with necessary relay information

Todo
  : Implement type checks here (e.g. we could receive relay-forw in relay-repl)

Definition at line 625 of file pkt6.cc.

References HOP_COUNT_LIMIT, isc_throw, and relay_info_.

Referenced by unpackRelayMsg().

## ◆ calculateRelaySizes()

uint16_t isc::dhcp::Pkt6::calculateRelaySizes | ( |  | ) |
| protected

Calculates overhead for all relays defined for this message.

Returns
  number of bytes needed to store all relay information

Definition at line 354 of file pkt6.cc.

References directLen(), getRelayOverhead(), len(), and relay_info_.

Referenced by len(), and packUDP().

Here is the call graph for this function:

## ◆ copyRelayInfo()

void isc::dhcp::Pkt6::copyRelayInfo | ( | const Pkt6Ptr & | question | ) |

copies relay information from client's packet to server's response

This information is not simply copied over. Some parameter are removed, msg_type_is updated (RELAY-FORW => RELAY-REPL), etc.

Parameters

  question | client's packet

Todo
  : Implement support for ERO (Echo Request Option, RFC4994)

Definition at line 882 of file pkt6.cc.

References D6O_INTERFACE_ID, D6O_RELAY_SOURCE_PORT, DHCPV6_RELAY_REPL, isc::db::info, and relay_info_.

## ◆ directLen()

uint16_t isc::dhcp::Pkt6::directLen | ( |  | ) | const
| protected

Calculates size of the message as if it was not relayed at all.

This is equal to len() if the message was not relayed.

Returns
  number of bytes required to store the message

Definition at line 366 of file pkt6.cc.

References DHCPV6_PKT_HDR_LEN, and isc::dhcp::Pkt::options_.

Referenced by calculateRelaySizes(), and len().

## ◆ getAllRelayOptions()

OptionCollection isc::dhcp::Pkt6::getAllRelayOptions | ( | const uint16_t | option_code,
|  | const RelaySearchOrder & | order )

Return first instances of a specified option.

When a client's packet traverses multiple relays, each passing relay may insert extra options. This method allows the specific instances of a given option to be obtained in the specified order (e.g. first closest to the client, first closest to the server, etc.) See RelaySearchOrder for a detailed description.

Parameters

  option_code | searched option
  order | option search order (see RelaySearchOrder)

Returns
  Collection of options found.

Definition at line 201 of file pkt6.cc.

References isc::dhcp::Pkt::copy_retrieved_options_, and relay_info_.

Referenced by getMACFromDocsisCMTS().

## ◆ getAnyRelayOption()

OptionPtr isc::dhcp::Pkt6::getAnyRelayOption | ( | const uint16_t | option_code,
|  | const RelaySearchOrder & | order )

Return first instance of a specified option.

When a client's packet traverses multiple relays, each passing relay may insert extra options. This method allows the specific instance of a given option to be obtained (e.g. closest to the client, closest to the server, etc.) See RelaySearchOrder for a detailed description.

Parameters

  option_code | searched option
  order | option search order (see RelaySearchOrder)

Returns
  option pointer (or null if no option matches specified criteria)

Definition at line 138 of file pkt6.cc.

References getRelayOption(), and relay_info_.

Referenced by getMACFromIPv6RelayOpt(), and getMACFromRemoteIdRelayOption().

Here is the call graph for this function:

## ◆ getClientId()

DuidPtr isc::dhcp::Pkt6::getClientId | ( |  | ) | const

Retrieves the DUID from the Client Identifier option.

This method is exception safe.

Returns
  Pointer to the DUID or NULL if the option doesn't exist.

Definition at line 767 of file pkt6.cc.

References D6O_CLIENTID, and isc::dhcp::Pkt::getNonCopiedOption().

Referenced by getLabel().

Here is the call graph for this function:

## ◆ getLabel()

std::string isc::dhcp::Pkt6::getLabel | ( |  | ) | const
| virtual

Returns text representation of the primary packet identifiers.

This method is intended to be used to provide a consistent way to identify packets within log statements. It is an instance-level wrapper around static makeLabel(). See this method for string content.

Note
  Currently this method doesn't include the HW address in the returned text.

Returns
  string with text representation

Todo
  Do not print HW address as it is unclear how it should be retrieved if there is no access to user configuration which specifies the order of various techniques to be used to retrieve it.

Reimplemented from isc::dhcp::Pkt.

Definition at line 720 of file pkt6.cc.

References getClientId(), isc::dhcp::Pkt::getTransid(), and makeLabel().

Referenced by isc::radius::RadiusAccess::buildAuth(), and isc::radius::RadiusAccess::getIdentifier().

Here is the call graph for this function:

## ◆ getMACFromDocsisCMTS()

HWAddrPtr isc::dhcp::Pkt6::getMACFromDocsisCMTS | ( |  | ) |
| protectedvirtual

Attempts to extract MAC/Hardware address from DOCSIS options.

The DHCPv6 mechanism extracts that information from DOCSIS option (vendor-specific info, vendor-id=4491, suboption 1026). Note that in a DOCSIS capable network, the MAC address information is provided several times. The first is specified by the modem itself. The second is added by the CMTS, which acts as a relay agent. This method attempts to extract the latter. See getMACFromDocsisModem for a similar method that extracts from the modem (client) options.

Returns
  hardware address (if DOCSIS suboption 1026 is present)

Implements isc::dhcp::Pkt.

Definition at line 983 of file pkt6.cc.

References D6O_VENDOR_OPTS, DOCSIS3_V6_CMTS_CM_MAC, getAllRelayOptions(), isc::dhcp::HTYPE_DOCSIS, isc::dhcp::HWAddr::HWADDR_SOURCE_DOCSIS_CMTS, relay_info_, RELAY_SEARCH_FROM_CLIENT, and VENDOR_ID_CABLE_LABS.

Here is the call graph for this function:

## ◆ getMACFromDocsisModem()

HWAddrPtr isc::dhcp::Pkt6::getMACFromDocsisModem | ( |  | ) |
| protectedvirtual

Attempts to extract MAC/Hardware address from DOCSIS options inserted by the modem itself.

The mechanism extracts that information from DOCSIS option (vendor-specific info, vendor-id=4491, suboption 36). Note that in a DOCSIS capable network, the MAC address information is provided several times. The first is specified by the modem itself. The second is added by the CMTS, which acts as a relay agent. This method attempts to extract the former. See getMACFromDocsisCMTS for a similar method that extracts from the CMTS (relay) options.

Returns
  hardware address (if DOCSIS suboption 36 is present)

Implements isc::dhcp::Pkt.

Definition at line 955 of file pkt6.cc.

References D6O_VENDOR_OPTS, DOCSIS3_V6_DEVICE_ID, isc::dhcp::Pkt::getNonCopiedOptions(), isc::dhcp::HTYPE_DOCSIS, isc::dhcp::HWAddr::HWADDR_SOURCE_DOCSIS_MODEM, and VENDOR_ID_CABLE_LABS.

Here is the call graph for this function:

## ◆ getMACFromDUID()

HWAddrPtr isc::dhcp::Pkt6::getMACFromDUID | ( |  | ) |
| protectedvirtual

Extract MAC/Hardware address from client-id.

This method attempts to extract MAC/Hardware address from DUID sent as client-id. This method may fail, as only DUID-LLT and DUID-LL are based on link-layer addresses. Client may use other valid DUID types and this method will fail.

Returns
  Hardware address (or NULL)

Implements isc::dhcp::Pkt.

Definition at line 641 of file pkt6.cc.

References D6O_CLIENTID, isc::dhcp::DUID::DUID_LL, isc::dhcp::DUID::DUID_LLT, isc::dhcp::Pkt::getNonCopiedOption(), isc::dhcp::HWAddr::HWADDR_SOURCE_DUID, and isc::util::readUint16().

Here is the call graph for this function:

## ◆ getMACFromIPv6RelayOpt()

HWAddrPtr isc::dhcp::Pkt6::getMACFromIPv6RelayOpt | ( |  | ) |
| protectedvirtual

Extract MAC/Hardware address from client link-layer address.

This method extracts the client's hardware address from the

Returns
  Hardware address (or NULL)

Implements isc::dhcp::Pkt.

Definition at line 927 of file pkt6.cc.

References D6O_CLIENT_LINKLAYER_ADDR, getAnyRelayOption(), isc::dhcp::HWAddr::HWADDR_SOURCE_CLIENT_ADDR_RELAY_OPTION, RELAY_GET_FIRST, and relay_info_.

Here is the call graph for this function:

## ◆ getMACFromRemoteIdRelayOption()

HWAddrPtr isc::dhcp::Pkt6::getMACFromRemoteIdRelayOption | ( |  | ) |
| protectedvirtual

Attempts to obtain MAC address from remote-id relay option.

This method is called from getMAC(HWADDR_SOURCE_REMOTE_ID) and should not be called directly. It will attempt to extract MAC address information from remote-id option inserted by a relay agent closest to the client. If this method fails, it will return NULL.

Returns
  hardware address (or NULL)

Implements isc::dhcp::Pkt.

Definition at line 1017 of file pkt6.cc.

References D6O_REMOTE_ID, getAnyRelayOption(), isc::dhcp::IfaceMgr::getIface(), isc::dhcp::HWAddr::HWADDR_SOURCE_REMOTE_ID, isc::dhcp::Pkt::iface_, isc::dhcp::IfaceMgr::instance(), len(), isc::dhcp::HWAddr::MAX_HWADDR_LEN, RELAY_GET_FIRST, and relay_info_.

Here is the call graph for this function:

## ◆ getMACFromSrcLinkLocalAddr()

HWAddrPtr isc::dhcp::Pkt6::getMACFromSrcLinkLocalAddr | ( |  | ) |
| protectedvirtual

Attempts to generate MAC/Hardware address from IPv6 link-local address.

This method uses source IPv6 address for direct messages and the peeraddr or the first relay that saw that packet. It may fail if the address is not link-local or does not use EUI-64 identifier.

Returns
  Hardware address (or NULL)

Implements isc::dhcp::Pkt.

Definition at line 916 of file pkt6.cc.

References isc::dhcp::Pkt::getMACFromIPv6(), relay_info_, and isc::dhcp::Pkt::remote_addr_.

Here is the call graph for this function:

## ◆ getName() [1/2]

const char * isc::dhcp::Pkt6::getName | ( |  | ) | const
| virtual

Returns name of the DHCPv6 message.

This method requires an object. There is also a static version, which requires one parameter (type).

Returns
  Pointer to "const" string containing the message name. If the message type is unknown the "UNKNOWN" is returned. The caller must not release the returned pointer.

Implements isc::dhcp::Pkt.

Definition at line 878 of file pkt6.cc.

References getName(), and getType().

Referenced by getName(), isc::dhcp::Pkt6::RelayInfo::toText(), and toText().

Here is the call graph for this function:

## ◆ getName() [2/2]

const char * isc::dhcp::Pkt6::getName | ( | const uint8_t | type | ) |
| static

Returns name of the DHCPv6 message for a given type number.

As the operation of the method does not depend on any server state, it is declared static. There is also non-static getName() method that works on Pkt6 objects.

Parameters

  type | DHCPv6 message type which name should be returned.

Returns
  Pointer to "const" string containing the message name. If the message type is unknown the "UNKNOWN" is returned. The caller must not release the returned pointer.

Definition at line 784 of file pkt6.cc.

References DHCPV6_ADDR_REG_INFORM, DHCPV6_ADDR_REG_REPLY, DHCPV6_ADVERTISE, DHCPV6_CONFIRM, DHCPV6_DECLINE, DHCPV6_DHCPV4_QUERY, DHCPV6_DHCPV4_RESPONSE, DHCPV6_INFORMATION_REQUEST, DHCPV6_LEASEQUERY, DHCPV6_LEASEQUERY_DATA, DHCPV6_LEASEQUERY_DONE, DHCPV6_LEASEQUERY_REPLY, DHCPV6_REBIND, DHCPV6_RECONFIGURE, DHCPV6_RELAY_FORW, DHCPV6_RELAY_REPL, DHCPV6_RELEASE, DHCPV6_RENEW, DHCPV6_REPLY, DHCPV6_REQUEST, DHCPV6_SOLICIT, and isc::dhcp::RELEASE.

Referenced by isc::perfmon::DurationKey::getMessageTypeLabel(), isc::perfmon::DurationKeyParser::toElement(), and isc::perfmon::DurationKey::validateMessagePair().

## ◆ getNonCopiedAllRelayOptions()

OptionCollection isc::dhcp::Pkt6::getNonCopiedAllRelayOptions | ( | const uint16_t | option_code,
|  | const RelaySearchOrder & | order ) const
| protected

Returns pointers to instances of specified option.

This is a variant of getAllRelayOptions but it never copies an option returned. This method should be only used by the Pkt6 class and derived classes. Any external callers should use getAnyRelayOption which copies the option before returning it when the Pkt::copy_retrieved_options_ flag is set to true.

Parameters

  option_code | Searched option.
  order | Option search order (see RelaySearchOrder).

Returns
  Collection of options found.

Definition at line 171 of file pkt6.cc.

References relay_info_.

## ◆ getNonCopiedAnyRelayOption()

OptionPtr isc::dhcp::Pkt6::getNonCopiedAnyRelayOption | ( | const uint16_t | option_code,
|  | const RelaySearchOrder & | order ) const
| protected

Returns pointer to an instance of specified option.

This is a variant of getAnyRelayOption but it never copies an option returned. This method should be only used by the Pkt6 class and derived classes. Any external callers should use getAnyRelayOption which copies the option before returning it when the Pkt::copy_retrieved_options_ flag is set to true.

Parameters

  option_code | Searched option.
  order | Option search order (see RelaySearchOrder).

Returns
  Option pointer or null, if no option matches specified criteria.

Definition at line 106 of file pkt6.cc.

References getNonCopiedRelayOption(), and relay_info_.

Here is the call graph for this function:

## ◆ getNonCopiedRelayOption()

OptionPtr isc::dhcp::Pkt6::getNonCopiedRelayOption | ( | const uint16_t | opt_type,
|  | const uint8_t | relay_level ) const
| protected

Returns pointer to an option inserted by relay agent.

This is a variant of the Pkt6::getRelayOption function which never copies an option returned. This method should be only used by the Pkt6 class and derived classes. Any external callers should use getRelayOption which copies the option before returning it when the Pkt::copy_retrieved_options_ flag is set to true.

Parameters

  opt_type | Code of the requested option.
  relay_level | Nesting level as described for Pkt6::getRelayOption.

Returns
  Pointer to the option or null if such option doesn't exist.

Definition at line 241 of file pkt6.cc.

References isc_throw, isc::dhcp::Pkt::options_, and relay_info_.

Referenced by getNonCopiedAnyRelayOption().

## ◆ getNonCopiedRelayOptions()

OptionCollection isc::dhcp::Pkt6::getNonCopiedRelayOptions | ( | const uint16_t | opt_type,
|  | const uint8_t | relay_level ) const
| protected

Returns all option instances inserted by relay agent.

This is a variant of the Pkt6::getRelayOptions function which never copies an option returned. This method should be only used by the Pkt6 class and derived classes. Any external callers should use getRelayOption which copies the option before returning it when the Pkt::copy_retrieved_options_ flag is set to true.

Parameters

  opt_type | Code of the requested option.
  relay_level | Nesting level as described for Pkt6::getRelayOption.

Returns
  Collection of options found.

Definition at line 280 of file pkt6.cc.

References isc_throw, and relay_info_.

## ◆ getProto()

DHCPv6Proto isc::dhcp::Pkt6::getProto | ( |  | ) |
| inline

Returns protocol of this packet (UDP or TCP).

Returns
  protocol type

Definition at line 149 of file pkt6.h.

References proto_.

## ◆ getRelay6LinkAddress()

const isc::asiolink::IOAddress & isc::dhcp::Pkt6::getRelay6LinkAddress | ( | uint8_t | relay_level | ) | const

return the link address field from a relay option

As with `Pkt6::getRelayOption` this returns information from the specified relay scope. The relay_level specifies which relay scope is to be used. 0 is the outermost encapsulation (relay closest to the server). pkt->relay_info_.size() -1 is the innermost encapsulation (relay closest to the client).

Exceptions

  isc::OutOfRange | if relay level has an invalid value.

Parameters

  relay_level | see description above

Returns
  pointer to the link address field

Definition at line 324 of file pkt6.cc.

References isc_throw, and relay_info_.

Referenced by isc::dhcp::TokenRelay6Field::evaluate().

## ◆ getRelay6PeerAddress()

const isc::asiolink::IOAddress & isc::dhcp::Pkt6::getRelay6PeerAddress | ( | uint8_t | relay_level | ) | const

return the peer address field from a relay option

As with `Pkt6::getRelayOption` this returns information from the specified relay scope. The relay_level specifies which relay scope is to be used. 0 is the outermost encapsulation (relay closest to the server). pkt->relay_info_.size() -1 is the innermost encapsulation (relay closest to the client).

Exceptions

  isc::OutOfRange | if relay level has an invalid value.

Parameters

  relay_level | see description above

Returns
  pointer to the peer address field

Definition at line 334 of file pkt6.cc.

References isc_throw, and relay_info_.

Referenced by isc::dhcp::TokenRelay6Field::evaluate().

## ◆ getRelayOption()

OptionPtr isc::dhcp::Pkt6::getRelayOption | ( | uint16_t | option_code,
|  | uint8_t | nesting_level )

Returns option inserted by relay.

Returns an option from specified relay scope (inserted by a given relay if this is received packet or to be decapsulated by a given relay if this is a transmitted packet). nesting_level specifies which relay scope is to be used. 0 is the outermost encapsulation (relay closest to the server). pkt->relay_info_.size() - 1 is the innermost encapsulation (relay closest to the client).

Exceptions

  isc::OutOfRange | if nesting level has invalid value.

Parameters

  option_code | code of the requested option
  nesting_level | see description above

Returns
  pointer to the option (or null if there is no such option)

Definition at line 259 of file pkt6.cc.

References isc::dhcp::Pkt::copy_retrieved_options_, isc_throw, isc::dhcp::Pkt::options_, and relay_info_.

Referenced by getAnyRelayOption(), and isc::dhcp::TokenRelay6Option::getOption().

## ◆ getRelayOptions()

OptionCollection isc::dhcp::Pkt6::getRelayOptions | ( | uint16_t | option_code,
|  | uint8_t | nesting_level )

Returns options inserted by relay.

Returns options from specified relay scope (inserted by a given relay if this is received packet or to be decapsulated by a given relay if this is a transmitted packet). nesting_level specifies which relay scope is to be used. 0 is the outermost encapsulation (relay closest to the server). pkt->relay_info_.size() - 1 is the innermost encapsulation (relay closest to the client).

Exceptions

  isc::OutOfRange | if nesting level has invalid value.

Parameters

  option_code | code of the requested option
  nesting_level | see description above

Returns
  Collection of options found.

Definition at line 296 of file pkt6.cc.

References isc::dhcp::Pkt::copy_retrieved_options_, isc_throw, and relay_info_.

## ◆ getRelayOverhead()

uint16_t isc::dhcp::Pkt6::getRelayOverhead | ( | const RelayInfo & | relay | ) | const
| protected

Calculates overhead introduced in specified relay.

It is used when calculating message size and packing message

Parameters

  relay | RelayInfo structure that holds information about relay

Returns
  number of bytes needed to store relay information

Definition at line 343 of file pkt6.cc.

References DHCPV6_RELAY_HDR_LEN, len(), isc::dhcp::Option::OPTION6_HDR_LEN, and isc::dhcp::Pkt6::RelayInfo::options_.

Referenced by calculateRelaySizes(), and len().

Here is the call graph for this function:

## ◆ getType()

virtual uint8_t isc::dhcp::Pkt6::getType | ( |  | ) | const
| inlinevirtual

Returns message type (e.g.

1 = SOLICIT).

Returns
  message type

Implements isc::dhcp::Pkt.

Definition at line 220 of file pkt6.h.

References msg_type_.

Referenced by isc::dhcp::TokenPkt6::evaluate(), and getName().

## ◆ len()

size_t isc::dhcp::Pkt6::len | ( |  | ) |
| virtual

Returns length of the packet.

This function returns size required to hold this packet. It includes DHCPv6 header and all options stored in options_ field.

Note: It does not return proper length of incoming packets before they are unpacked.

Returns
  number of bytes required to assemble this packet

Implements isc::dhcp::Pkt.

Definition at line 63 of file pkt6.cc.

References calculateRelaySizes(), directLen(), getRelayOverhead(), and relay_info_.

Referenced by isc::perfdhcp::PerfPkt6::PerfPkt6(), calculateRelaySizes(), getMACFromRemoteIdRelayOption(), and getRelayOverhead().

Here is the call graph for this function:

## ◆ makeLabel() [1/2]

std::string isc::dhcp::Pkt6::makeLabel | ( | const DuidPtr | duid,
|  | const HWAddrPtr & | hwaddr )
| static

Returns text representation of the given packet identifiers.

This variant of the method does not include transaction id.

Parameters

  duid | Pointer to the client identifier or NULL.
  hwaddr | Hardware address to include in the string or NULL.

Returns
  String with text representation of the packet identifiers.

Definition at line 706 of file pkt6.cc.

## ◆ makeLabel() [2/2]

std::string isc::dhcp::Pkt6::makeLabel | ( | const DuidPtr | duid,
|  | const uint32_t | transid,
|  | const HWAddrPtr & | hwaddr )
| static

Returns text representation of the given packet identifiers.

Note
  The parameters are ordered from the one that should be available almost at all times, to the one that is optional. This allows for providing default values for the parameters that may not be available in some places in the code where `Pkt6::makeLabel` is called.

Parameters

  duid | Pointer to the client identifier or NULL.
  transid | Numeric transaction id to include in the string.
  hwaddr | Hardware address to include in the string or NULL.

Returns
  String with text representation of the packet identifiers.

Definition at line 693 of file pkt6.cc.

References makeLabel().

Referenced by getLabel(), makeLabel(), and isc::dhcp::queueNCR().

Here is the call graph for this function:

## ◆ pack()

void isc::dhcp::Pkt6::pack | ( |  | ) |
| virtual

Prepares on-wire format.

Prepares on-wire format of message and all its options. Options must be stored in options_ field. Output buffer will be stored in data_. Length will be set in data_len_. The output buffer is cleared before new data is written to it.

Exceptions

  BadValue | if packet protocol is invalid, InvalidOperation if packing fails, or NotImplemented if protocol is TCP (IPv6 over TCP is not yet supported).

Implements isc::dhcp::Pkt.

Definition at line 377 of file pkt6.cc.

References isc_throw, packTCP(), packUDP(), proto_, TCP, and UDP.

Referenced by packUDP().

Here is the call graph for this function:

## ◆ packTCP()

void isc::dhcp::Pkt6::packTCP | ( |  | ) |
| protected

Builds on wire packet for TCP transmission.

Todo
  This function is not implemented yet.

Exceptions

  NotImplemented,IPv6 | over TCP is not yet supported.

TODO Implement this function.

Definition at line 453 of file pkt6.cc.

References isc_throw.

Referenced by pack().

## ◆ packUDP()

void isc::dhcp::Pkt6::packUDP | ( |  | ) |
| protected

Builds on wire packet for UDP transmission.

Exceptions

  InvalidOperation | if packing fails

Definition at line 391 of file pkt6.cc.

References isc::dhcp::Pkt::buffer_out_, calculateRelaySizes(), D6O_RELAY_MSG, isc_throw, msg_type_, isc::dhcp::Pkt::options_, pack(), isc::dhcp::LibDHCP::packOptions6(), relay_info_, isc::dhcp::Pkt::transid_, and isc::Exception::what().

Referenced by pack().

Here is the call graph for this function:

## ◆ setProto()

void isc::dhcp::Pkt6::setProto | ( | DHCPv6Proto | proto = UDP | ) |
| inline

Sets protocol of this packet.

Parameters

  proto | protocol (UDP or TCP)

Definition at line 156 of file pkt6.h.

References proto_, and UDP.

## ◆ setType()

virtual void isc::dhcp::Pkt6::setType | ( | uint8_t | type | ) |
| inlinevirtual

Sets message type (e.g.

1 = SOLICIT).

Parameters

  type | message type to be set

Implements isc::dhcp::Pkt.

Definition at line 225 of file pkt6.h.

References msg_type_.

## ◆ toText()

std::string isc::dhcp::Pkt6::toText | ( |  | ) | const
| virtual

Returns text representation of the packet.

This function is useful mainly for debugging.

Returns
  string with text representation

Implements isc::dhcp::Pkt.

Definition at line 728 of file pkt6.cc.

References getName(), isc::dhcp::Pkt::local_addr_, isc::dhcp::Pkt::local_port_, msg_type_, isc::dhcp::Pkt::options_, relay_info_, isc::dhcp::Pkt::remote_addr_, isc::dhcp::Pkt::remote_port_, and isc::dhcp::Pkt::transid_.

Here is the call graph for this function:

## ◆ unpack()

void isc::dhcp::Pkt6::unpack | ( |  | ) |
| virtual

Dispatch method that handles binary packet parsing.

This method calls appropriate dispatch function (unpackUDP or unpackTCP).

Exceptions

  tbd |

Implements isc::dhcp::Pkt.

Definition at line 460 of file pkt6.cc.

References isc_throw, proto_, TCP, UDP, unpackTCP(), and unpackUDP().

Here is the call graph for this function:

## ◆ unpackMsg()

void isc::dhcp::Pkt6::unpackMsg | ( | OptionBuffer::const_iterator | begin,
|  | OptionBuffer::const_iterator | end )
| protected

Unpacks direct (non-relayed) message.

This method unpacks specified buffer range as a direct (e.g. solicit or request) message. This method is called from unpackUDP() when received message is detected to be direct.

Parameters

  begin | start of the buffer
  end | end of the buffer

Exceptions

  tbd |

Definition at line 504 of file pkt6.cc.

References isc::dhcp::Pkt::data_, DHCP6_OPTION_SPACE, isc_throw, msg_type_, isc::dhcp::Pkt::options_, isc::dhcp::Pkt::transid_, and isc::dhcp::LibDHCP::unpackOptions6().

Referenced by unpackRelayMsg(), and unpackUDP().

Here is the call graph for this function:

## ◆ unpackRelayMsg()

void isc::dhcp::Pkt6::unpackRelayMsg | ( |  | ) |
| protected

Unpacks relayed message (RELAY-FORW or RELAY-REPL).

This method is called from unpackUDP() when received message is detected to be relay-message. It goes iteratively over all relays (if there are multiple encapsulation levels).

Exceptions

  tbd |

Todo
  : check that each option appears at most once

Todo
  : implement ERO (Echo Request Option, RFC 4994) here

Todo
  : log here that there are additional unparsed bytes

Definition at line 548 of file pkt6.cc.

References addRelayInfo(), isc::dhcp::Pkt::data_, DHCP6_OPTION_SPACE, DHCPV6_RELAY_FORW, DHCPV6_RELAY_HDR_LEN, DHCPV6_RELAY_REPL, isc::asiolink::IOAddress::fromBytes(), isc::dhcp::Pkt6::RelayInfo::hop_count_, isc_throw, isc::dhcp::Pkt6::RelayInfo::linkaddr_, isc::dhcp::Pkt6::RelayInfo::msg_type_, isc::dhcp::Pkt6::RelayInfo::options_, isc::dhcp::Pkt6::RelayInfo::peeraddr_, unpackMsg(), and isc::dhcp::LibDHCP::unpackOptions6().

Referenced by unpackUDP().

Here is the call graph for this function:

## ◆ unpackTCP()

void isc::dhcp::Pkt6::unpackTCP | ( |  | ) |
| protected

Parses on-wire form of TCP DHCPv6 packet.

Parses received packet, stored in on-wire format in data_. data_len_ must be set to indicate data length. Will create a collection of option objects that will be stored in options_ container.

Todo
  This function is not implemented yet.

Exceptions

  tbd |

Definition at line 635 of file pkt6.cc.

References isc_throw.

Referenced by unpack().

## ◆ unpackUDP()

void isc::dhcp::Pkt6::unpackUDP | ( |  | ) |
| protected

Parses on-wire form of UDP DHCPv6 packet.

Parses received packet, stored in on-wire format in data_. data_len_ must be set to indicate data length. Will create a collection of option objects that will be stored in options_ container.

Exceptions

  tbd |

Definition at line 472 of file pkt6.cc.

References isc::dhcp::Pkt::data_, DHCPV6_ADDR_REG_INFORM, DHCPV6_ADDR_REG_REPLY, DHCPV6_ADVERTISE, DHCPV6_CONFIRM, DHCPV6_DECLINE, DHCPV6_DHCPV4_QUERY, DHCPV6_DHCPV4_RESPONSE, DHCPV6_INFORMATION_REQUEST, DHCPV6_REBIND, DHCPV6_RECONFIGURE, DHCPV6_RELAY_FORW, DHCPV6_RELAY_REPL, DHCPV6_RENEW, DHCPV6_REPLY, DHCPV6_REQUEST, DHCPV6_SOLICIT, isc_throw, msg_type_, unpackMsg(), and unpackRelayMsg().

Referenced by unpack().

Here is the call graph for this function:

## Member Data Documentation

## ◆ DHCPV6_PKT_HDR_LEN

const size_t isc::dhcp::Pkt6::DHCPV6_PKT_HDR_LEN = 4
| static

specifies non-relayed DHCPv6 packet header length (over UDP)

Definition at line 47 of file pkt6.h.

Referenced by directLen().

## ◆ DHCPV6_RELAY_HDR_LEN

const size_t isc::dhcp::Pkt6::DHCPV6_RELAY_HDR_LEN = 34
| static

specifies relay DHCPv6 packet header length (over UDP)

Definition at line 50 of file pkt6.h.

Referenced by getRelayOverhead(), isc::lease_query::LeaseQueryImpl6::getRelayOverhead(), isc::lease_query::LeaseQueryImpl6::makeRelayOption(), and unpackRelayMsg().

## ◆ msg_type_

uint8_t isc::dhcp::Pkt6::msg_type_
| protected

DHCPv6 message type.

Definition at line 620 of file pkt6.h.

Referenced by Pkt6(), Pkt6(), getType(), packUDP(), setType(), toText(), unpackMsg(), and unpackUDP().

## ◆ proto_

DHCPv6Proto isc::dhcp::Pkt6::proto_
| protected

UDP (usually) or TCP (bulk leasequery or failover)

Definition at line 617 of file pkt6.h.

Referenced by Pkt6(), Pkt6(), getProto(), pack(), setProto(), and unpack().

## ◆ relay_info_

std::vector<RelayInfo> isc::dhcp::Pkt6::relay_info_

Relay information.

This is a public field. Otherwise we hit one of the two problems: we return reference to an internal field (and that reference could be potentially used past Pkt6 object lifetime causing badness) or we return a copy (which is inefficient and also causes any updates to be impossible). Therefore public field is considered the best (or least bad) solution.

This vector is arranged in the order packet is encapsulated, i.e. relay[0] was the outermost encapsulation (relay closest to the server), relay[last] was the innermost encapsulation (relay closest to the client).

Definition at line 473 of file pkt6.h.

Referenced by addRelayInfo(), calculateRelaySizes(), copyRelayInfo(), isc::dhcp::TokenRelay6Field::evaluate(), getAllRelayOptions(), getAnyRelayOption(), getMACFromDocsisCMTS(), getMACFromIPv6RelayOpt(), getMACFromRemoteIdRelayOption(), getMACFromSrcLinkLocalAddr(), getNonCopiedAllRelayOptions(), getNonCopiedAnyRelayOption(), getNonCopiedRelayOption(), getNonCopiedRelayOptions(), isc::dhcp::TokenRelay6Option::getOption(), getRelay6LinkAddress(), getRelay6PeerAddress(), getRelayOption(), getRelayOptions(), len(), packUDP(), and toText().

The documentation for this class was generated from the following files:

- pkt6.h
- pkt6.cc