Kea  2.3.4-git
isc::dhcp::HWAddr Struct Reference

Hardware type that represents information from DHCPv4 packet. More...

#include <hwaddr.h>

Public Member Functions

 HWAddr ()
 default constructor More...
 
 HWAddr (const uint8_t *hwaddr, size_t len, uint16_t htype)
 constructor, based on C-style pointer and length More...
 
 HWAddr (const std::vector< uint8_t > &hwaddr, uint16_t htype)
 constructor, based on C++ vector<uint8_t> More...
 
bool operator!= (const HWAddr &other) const
 Compares two hardware addresses for inequality. More...
 
bool operator== (const HWAddr &other) const
 Compares two hardware addresses for equality. More...
 
std::string toText (bool include_htype=true) const
 Returns textual representation of a hardware address (e.g. More...
 

Static Public Member Functions

static HWAddr fromText (const std::string &text, const uint16_t htype=HTYPE_ETHER)
 Creates instance of the hardware address from textual format. More...
 

Public Attributes

uint16_t htype_
 Hardware type. More...
 
std::vector< uint8_t > hwaddr_
 
uint32_t source_
 Hardware address source. More...
 

Static Public Attributes

static const size_t ETHERNET_HWADDR_LEN = 6
 Size of an ethernet hardware address. More...
 
static const uint32_t HWADDR_SOURCE_ANY = 0xffffffff
 Not really a type, only used in getMAC() calls. More...
 
static const uint32_t HWADDR_SOURCE_CLIENT_ADDR_RELAY_OPTION = 0x00000008
 Get it from RFC6939 option. More...
 
static const uint32_t HWADDR_SOURCE_DOCSIS_CMTS = 0x00000040
 A CMTS (acting as DHCP relay agent) that supports DOCSIS standard can insert DOCSIS options that contain client's MAC address. More...
 
static const uint32_t HWADDR_SOURCE_DOCSIS_MODEM = 0x00000080
 A cable modem (acting as DHCP client) that supports DOCSIS standard can insert DOCSIS options that contain client's MAC address. More...
 
static const uint32_t HWADDR_SOURCE_DUID = 0x00000002
 Extracted from DUID-LL or DUID-LLT (not 100% reliable as the client can send fake DUID). More...
 
static const uint32_t HWADDR_SOURCE_IPV6_LINK_LOCAL = 0x00000004
 Extracted from IPv6 link-local address. More...
 
static const uint32_t HWADDR_SOURCE_RAW = 0x00000001
 Obtained first hand from raw socket (100% reliable). More...
 
static const uint32_t HWADDR_SOURCE_REMOTE_ID = 0x00000010
 A relay can insert remote-id. More...
 
static const uint32_t HWADDR_SOURCE_SUBSCRIBER_ID = 0x00000020
 A relay can insert a subscriber-id option. More...
 
static const uint32_t HWADDR_SOURCE_UNKNOWN = 0x00000000
 Used when actual origin is not known, e.g. More...
 
static const size_t MAX_HWADDR_LEN = 20
 Maximum size of a hardware address. More...
 

Detailed Description

Hardware type that represents information from DHCPv4 packet.

Definition at line 20 of file hwaddr.h.

Constructor & Destructor Documentation

◆ HWAddr() [1/3]

isc::dhcp::HWAddr::HWAddr ( )

default constructor

Definition at line 32 of file hwaddr.cc.

Referenced by fromText().

◆ HWAddr() [2/3]

isc::dhcp::HWAddr::HWAddr ( const uint8_t *  hwaddr,
size_t  len,
uint16_t  htype 
)

constructor, based on C-style pointer and length

Parameters
hwaddrpointer to hardware address
lenlength of the address pointed by hwaddr
htypehardware type

Definition at line 36 of file hwaddr.cc.

References isc_throw, and MAX_HWADDR_LEN.

◆ HWAddr() [3/3]

isc::dhcp::HWAddr::HWAddr ( const std::vector< uint8_t > &  hwaddr,
uint16_t  htype 
)

constructor, based on C++ vector<uint8_t>

Parameters
hwaddrconst reference to hardware address
htypehardware type

Definition at line 43 of file hwaddr.cc.

References isc_throw, and MAX_HWADDR_LEN.

Member Function Documentation

◆ fromText()

HWAddr isc::dhcp::HWAddr::fromText ( const std::string &  text,
const uint16_t  htype = HTYPE_ETHER 
)
static

Creates instance of the hardware address from textual format.

This function parses HW address specified as text and creates the corresponding HWAddr instance. The hexadecimal digits representing individual bytes of the hardware address should be separated with colons. Typically, two digits per byte are used. However, this function allows for 1 digit per HW address byte. In this case, the digit is prepended with '0' during conversion to binary value.

This function can be used to perform a reverse operation to the HWAddr::toText(false).

The instance created by this function sets HTYPE_ETHER as a hardware type.

Parameters
textHW address in the textual format.
htypeHardware type.
Returns
Instance of the HW address created from text.

Definition at line 70 of file hwaddr.cc.

References isc::util::str::decodeColonSeparatedHexString(), and HWAddr().

Referenced by isc::dhcp::Lease::fromElementCommon(), isc::lease_cmds::LeaseCmdsImpl::getParameters(), isc::lease_cmds::LeaseCmdsImpl::leaseGetByHwAddressHandler(), isc::dhcp::CSVLeaseFile6::next(), and isc::dhcp::CSVLeaseFile4::next().

+ Here is the call graph for this function:

◆ operator!=()

bool isc::dhcp::HWAddr::operator!= ( const HWAddr other) const

Compares two hardware addresses for inequality.

Definition at line 81 of file hwaddr.cc.

◆ operator==()

bool isc::dhcp::HWAddr::operator== ( const HWAddr other) const

Compares two hardware addresses for equality.

Definition at line 76 of file hwaddr.cc.

References htype_, and hwaddr_.

◆ toText()

std::string isc::dhcp::HWAddr::toText ( bool  include_htype = true) const

Returns textual representation of a hardware address (e.g.

00:01:02:03:04:05)

Parameters
include_htypeBoolean value which controls whether the hardware type is included in the returned string (true), or not (false).
Returns
Hardware address in the textual format.

Definition at line 51 of file hwaddr.cc.

References htype_, and hwaddr_.

Referenced by isc::dhcp::Memfile_LeaseMgr::getLease4(), isc::dhcp::PgSqlLeaseMgr::getLease4(), and isc::dhcp::MySqlLeaseMgr::getLease4().

Member Data Documentation

◆ ETHERNET_HWADDR_LEN

const size_t isc::dhcp::HWAddr::ETHERNET_HWADDR_LEN = 6
static

Size of an ethernet hardware address.

Definition at line 24 of file hwaddr.h.

◆ htype_

uint16_t isc::dhcp::HWAddr::htype_

Hardware type.

Note
It used to be uint8_t as used in DHCPv4. However, since we're expanding MAC addresses support to DHCPv6 that uses hw_type as 16 bits, we need to be able to store that wider format.

Definition at line 105 of file hwaddr.h.

Referenced by operator==(), and toText().

◆ hwaddr_

◆ MAX_HWADDR_LEN

const size_t isc::dhcp::HWAddr::MAX_HWADDR_LEN = 20
static

Maximum size of a hardware address.

Definition at line 27 of file hwaddr.h.

Referenced by isc::dhcp::Host::getIdentifierMaxLength(), isc::dhcp::Pkt6::getMACFromRemoteIdRelayOption(), and HWAddr().

◆ source_

uint32_t isc::dhcp::HWAddr::source_

Hardware address source.

This variable specifies how the hardware address was obtained.

Todo:
This is a stub implementation. Proper implementation will move constants from Pkt::HWADDR_SOURCE_* here. Currently always initialized to zero.

Definition at line 113 of file hwaddr.h.

Referenced by isc::dhcp::CSVLeaseFile6::next().


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