Kea 2.7.6
isc::dhcp::Pkt4 Class Reference

Represents DHCPv4 packet. More...

#include <pkt4.h>

+ Inheritance diagram for isc::dhcp::Pkt4:

Public Member Functions

 Pkt4 (const uint8_t *data, size_t len)
 Constructor, used in message reception.
 
 Pkt4 (uint8_t msg_type, uint32_t transid)
 Constructor, used in replying to a message.
 
virtual void addOption (const OptionPtr &opt)
 Add an option.
 
const isc::asiolink::IOAddressgetCiaddr () const
 Returns ciaddr field.
 
std::list< uint16_t > & getDeferredOptions ()
 Returns a reference to option codes which unpacking will be deferred.
 
const OptionBuffer getFile () const
 Returns file field.
 
uint16_t getFlags () const
 Returns flags field.
 
const isc::asiolink::IOAddressgetGiaddr () const
 Returns giaddr field.
 
uint8_t getHlen () const
 Returns hlen field.
 
uint8_t getHops () const
 Returns hops field.
 
uint8_t getHtype () const
 Returns htype field.
 
HWAddrPtr getHWAddr () const
 returns hardware address information
 
std::string getHWAddrLabel () const
 Returns text representation of the hardware address.
 
std::string getLabel () const
 Returns text representation of the primary packet identifiers.
 
HWAddrPtr getLocalHWAddr () const
 Returns local HW address.
 
const char * getName () const
 Returns name of the DHCP message.
 
uint8_t getOp () const
 Returns op field.
 
uint16_t getSecs () const
 Returns secs field.
 
const isc::asiolink::IOAddressgetSiaddr () const
 Returns siaddr field.
 
const OptionBuffer getSname () const
 Returns sname field.
 
uint8_t getType () const
 Returns DHCP message type (e.g.
 
const isc::asiolink::IOAddressgetYiaddr () const
 Returns yiaddr field.
 
virtual bool isDhcp4o6 () const
 Checks if a DHCPv4 message has been transported over DHCPv6.
 
bool isRelayed () const
 Checks if a DHCPv4 message has been relayed.
 
size_t len ()
 Returns the size of the required buffer to build the packet.
 
virtual void pack ()
 Prepares on-wire format of DHCPv4 packet.
 
void setCiaddr (const isc::asiolink::IOAddress &ciaddr)
 Sets ciaddr field.
 
void setFile (const uint8_t *file, size_t file_len)
 Sets file field.
 
void setFlags (uint16_t flags)
 Sets flags field.
 
void setGiaddr (const isc::asiolink::IOAddress &giaddr)
 Sets giaddr field.
 
void setHops (uint8_t hops)
 Sets hops field.
 
void setHWAddr (const HWAddrPtr &addr)
 Sets hardware address.
 
void setHWAddr (uint8_t htype, uint8_t hlen, const std::vector< uint8_t > &mac_addr)
 Sets hardware address.
 
void setLocalHWAddr (const HWAddrPtr &addr)
 Sets local HW address.
 
void setLocalHWAddr (const uint8_t htype, const uint8_t hlen, const std::vector< uint8_t > &mac_addr)
 Sets local HW address.
 
void setSecs (uint16_t secs)
 Sets secs field.
 
void setSiaddr (const isc::asiolink::IOAddress &siaddr)
 Sets siaddr field.
 
void setSname (const uint8_t *sname, size_t sname_len)
 Sets sname field.
 
void setType (uint8_t type)
 Sets DHCP message type (e.g.
 
void setYiaddr (const isc::asiolink::IOAddress &yiaddr)
 Sets yiaddr field.
 
std::string toText () const
 Returns text representation of the packet.
 
virtual void unpack ()
 Parses on-wire form of DHCPv4 packet.
 
- 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.
 
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 ClientClassesgetAdditionalClasses () const
 Returns the additional class list.
 
isc::util::OutputBuffergetBuffer ()
 Returns reference to output buffer.
 
const ClientClassesgetClasses () const
 Returns the class set.
 
std::string getIface () const
 Returns interface name.
 
int getIndex () const
 Returns interface index.
 
const isc::asiolink::IOAddressgetLocalAddr () 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::IOAddressgetRemoteAddr () 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 SubClassRelationContainergetSubClassesRelations () 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 DHCP message for a given type number.
 
static std::string makeLabel (const HWAddrPtr &hwaddr, const ClientIdPtr &client_id)
 Returns text representation of the given packet identifiers.
 
static std::string makeLabel (const HWAddrPtr &hwaddr, const ClientIdPtr &client_id, const uint32_t transid)
 Returns text representation of the given packet identifiers.
 

Static Public Attributes

static const size_t DHCPV4_PKT_HDR_LEN = 236
 specifies DHCPv4 packet header length (fixed part)
 
static const uint16_t FLAG_BROADCAST_MASK = 0x8000
 Mask for the value of flags field in the DHCPv4 message to check whether client requested broadcast response.
 
static const size_t MAX_CHADDR_LEN = 16
 length of the CHADDR field in DHCPv4 message
 
static const size_t MAX_FILE_LEN = 128
 length of the FILE field in DHCPv4 message
 
static const size_t MAX_SNAME_LEN = 64
 length of the SNAME field in DHCPv4 message
 

Protected Member Functions

uint8_t DHCPTypeToBootpType (uint8_t dhcpType)
 converts DHCP message type to BOOTP op type
 
virtual HWAddrPtr getMACFromDocsisCMTS ()
 No-op.
 
virtual HWAddrPtr getMACFromDocsisModem ()
 No-op.
 
virtual HWAddrPtr getMACFromDUID ()
 No-op.
 
virtual HWAddrPtr getMACFromIPv6RelayOpt ()
 No-op.
 
virtual HWAddrPtr getMACFromRemoteIdRelayOption ()
 No-op.
 
virtual HWAddrPtr getMACFromSrcLinkLocalAddr ()
 No-op.
 
- 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

isc::asiolink::IOAddress ciaddr_
 ciaddr field (32 bits): Client's IP address
 
std::list< uint16_t > deferred_options_
 
uint8_t file_ [MAX_FILE_LEN]
 file field (128 bytes)
 
uint16_t flags_
 flags
 
isc::asiolink::IOAddress giaddr_
 giaddr field (32 bits): Gateway IP address
 
uint8_t hops_
 Number of relay agents traversed.
 
HWAddrPtr hwaddr_
 link-layer address and hardware information represents 3 fields: htype (hardware type, 1 byte), hlen (length of the hardware address, up to 16) and chaddr (hardware address field, 16 bytes)
 
HWAddrPtr local_hwaddr_
 local HW address (dst if receiving packet, src if sending packet)
 
uint8_t op_
 message operation code
 
uint16_t secs_
 elapsed (number of seconds since beginning of transmission)
 
isc::asiolink::IOAddress siaddr_
 siaddr field (32 bits): next server IP address in boot process(e.g.TFTP)
 
uint8_t sname_ [MAX_SNAME_LEN]
 sname field (64 bytes)
 
isc::asiolink::IOAddress yiaddr_
 yiaddr field (32 bits): Client's IP address ("your"), set by server
 
- 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.
 

Additional Inherited Members

- 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.
 

Detailed Description

Represents DHCPv4 packet.

This class represents a single DHCPv4 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 DHCPv4-specific methods, but it uses a lot of common operations from its base Pkt class that is shared with Pkt6.

Definition at line 37 of file pkt4.h.

Constructor & Destructor Documentation

◆ Pkt4() [1/2]

isc::dhcp::Pkt4::Pkt4 ( uint8_t msg_type,
uint32_t transid )

Constructor, used in replying to a message.

Parameters
msg_typetype of message (e.g. DHCPDISCOVER=1)
transidtransaction-id

Definition at line 32 of file pkt4.cc.

References file_, MAX_FILE_LEN, MAX_SNAME_LEN, setType(), and sname_.

+ Here is the call graph for this function:

◆ Pkt4() [2/2]

isc::dhcp::Pkt4::Pkt4 ( const uint8_t * data,
size_t len )

Constructor, used in message reception.

Creates new message. Pkt4 will copy data to bufferIn_ buffer on creation.

Parameters
datapointer to received data
lensize of buffer to be allocated for this packet.

Definition at line 43 of file pkt4.cc.

References DHCPV4_PKT_HDR_LEN, file_, isc_throw, len(), MAX_FILE_LEN, MAX_SNAME_LEN, and sname_.

+ Here is the call graph for this function:

Member Function Documentation

◆ addOption()

void isc::dhcp::Pkt4::addOption ( const OptionPtr & opt)
virtual

Add an option.

Note
: to avoid throwing when adding multiple options with the same type use Pkt::addOption.
Exceptions
BadValueif option with that type is already present.
Parameters
optoption to be added

Reimplemented from isc::dhcp::Pkt.

Definition at line 589 of file pkt4.cc.

References isc::dhcp::Pkt::addOption(), isc::dhcp::Pkt::getNonCopiedOption(), and isc_throw.

Referenced by setType().

+ Here is the call graph for this function:

◆ DHCPTypeToBootpType()

uint8_t isc::dhcp::Pkt4::DHCPTypeToBootpType ( uint8_t dhcpType)
protected

◆ getCiaddr()

const isc::asiolink::IOAddress & isc::dhcp::Pkt4::getCiaddr ( ) const
inline

Returns ciaddr field.

Returns
ciaddr field

Definition at line 182 of file pkt4.h.

References ciaddr_.

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

◆ getDeferredOptions()

std::list< uint16_t > & isc::dhcp::Pkt4::getDeferredOptions ( )
inline

Returns a reference to option codes which unpacking will be deferred.

Only options 43 and 224-254 are subject of deferred unpacking: when the packet unpacking is performed, each time such an option is found, it is unpacked as an unknown option and the code added in this list.

Returns
List of codes of options which unpacking is deferred.

Definition at line 385 of file pkt4.h.

References deferred_options_.

◆ getFile()

const OptionBuffer isc::dhcp::Pkt4::getFile ( ) const
inline

Returns file field.

Note: This is 128 bytes long field. It doesn't have to be null-terminated. Do not use strlen() or similar on it.

Returns
pointer to file field

Definition at line 280 of file pkt4.h.

References file_, and MAX_FILE_LEN.

◆ getFlags()

uint16_t isc::dhcp::Pkt4::getFlags ( ) const
inline

Returns flags field.

Returns
flags field

Definition at line 176 of file pkt4.h.

References flags_.

◆ getGiaddr()

const isc::asiolink::IOAddress & isc::dhcp::Pkt4::getGiaddr ( ) const
inline

Returns giaddr field.

Returns
giaddr field

Definition at line 218 of file pkt4.h.

References giaddr_.

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

◆ getHlen()

uint8_t isc::dhcp::Pkt4::getHlen ( ) const

Returns hlen field.

Returns
hardware address length

Definition at line 580 of file pkt4.cc.

References hwaddr_, len(), and MAX_CHADDR_LEN.

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

+ Here is the call graph for this function:

◆ getHops()

uint8_t isc::dhcp::Pkt4::getHops ( ) const
inline

Returns hops field.

Returns
hops field

Definition at line 148 of file pkt4.h.

References hops_.

◆ getHtype()

uint8_t isc::dhcp::Pkt4::getHtype ( ) const

Returns htype field.

Returns
hardware type

Definition at line 572 of file pkt4.cc.

References isc::dhcp::HTYPE_UNDEFINED, and hwaddr_.

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

◆ getHWAddr()

HWAddrPtr isc::dhcp::Pkt4::getHWAddr ( ) const
inline

returns hardware address information

Returns
hardware address structure

Definition at line 324 of file pkt4.h.

References hwaddr_.

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

◆ getHWAddrLabel()

std::string isc::dhcp::Pkt4::getHWAddrLabel ( ) const

Returns text representation of the hardware address.

Returns text representation of the hardware address (e.g. hwaddr=00:01:02:03:04:05). If there is no defined hardware address, it returns hwaddr=(undefined).

Returns
string with text representation

Definition at line 605 of file pkt4.cc.

References hwaddr_.

◆ getLabel()

std::string isc::dhcp::Pkt4::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.

This method is exception safe.

Returns
string with text representation
Todo
If and when client id is extracted into Pkt4, this method should use the instance member rather than fetch it every time.

Reimplemented from isc::dhcp::Pkt.

Definition at line 365 of file pkt4.cc.

References isc::dhcp::Pkt::getNonCopiedOption(), hwaddr_, makeLabel(), and isc::dhcp::Pkt::transid_.

+ Here is the call graph for this function:

◆ getLocalHWAddr()

HWAddrPtr isc::dhcp::Pkt4::getLocalHWAddr ( ) const
inline

Returns local HW address.

Returns
local HW addr.

Definition at line 372 of file pkt4.h.

References local_hwaddr_.

◆ getMACFromDocsisCMTS()

virtual HWAddrPtr isc::dhcp::Pkt4::getMACFromDocsisCMTS ( )
inlineprotectedvirtual

No-op.

This is a DHCPv4 version of the function that attempts to extract MAC address from the options inserted by a CMTS. It is currently not implemented for v4.

Returns
always NULL

Implements isc::dhcp::Pkt.

Definition at line 489 of file pkt4.h.

◆ getMACFromDocsisModem()

virtual HWAddrPtr isc::dhcp::Pkt4::getMACFromDocsisModem ( )
inlineprotectedvirtual

No-op.

This is a DHCPv4 version of the function that attempts to extract MAC address from the options inserted by a cable modem. It is currently not implemented for v4.

Returns
always NULL

Implements isc::dhcp::Pkt.

Definition at line 467 of file pkt4.h.

◆ getMACFromDUID()

virtual HWAddrPtr isc::dhcp::Pkt4::getMACFromDUID ( )
inlineprotectedvirtual

No-op.

This method returns hardware address extracted from DUID. Currently it is a no-op, even though there's RFC that defines how to use DUID in DHCPv4 (see RFC4361). We may implement it one day.

Returns
always NULL

Implements isc::dhcp::Pkt.

Definition at line 478 of file pkt4.h.

◆ getMACFromIPv6RelayOpt()

virtual HWAddrPtr isc::dhcp::Pkt4::getMACFromIPv6RelayOpt ( )
inlineprotectedvirtual

No-op.

This method returns hardware address extracted from an IPv6 relay agent. option. As there is no IPv4-equivalent, it always returns NULL. We need this stub implementation here, to keep all the get hardware address logic in the base class.

Returns
always NULL

Implements isc::dhcp::Pkt.

Definition at line 456 of file pkt4.h.

◆ getMACFromRemoteIdRelayOption()

virtual HWAddrPtr isc::dhcp::Pkt4::getMACFromRemoteIdRelayOption ( )
inlineprotectedvirtual

No-op.

This method returns hardware address extracted from remote-id relay option. Currently it is a no-op, it always returns NULL.

Returns
always NULL

Implements isc::dhcp::Pkt.

Definition at line 499 of file pkt4.h.

◆ getMACFromSrcLinkLocalAddr()

virtual HWAddrPtr isc::dhcp::Pkt4::getMACFromSrcLinkLocalAddr ( )
inlineprotectedvirtual

No-op.

This method returns hardware address generated from the IPv6 link-local address. As there is no IPv4-equivalent, it always returns NULL. We need this stub implementation here, to keep all the get hardware address logic in the base class.

Returns
always NULL

Implements isc::dhcp::Pkt.

Definition at line 444 of file pkt4.h.

◆ getName() [1/2]

const char * isc::dhcp::Pkt4::getName ( ) const
virtual

Returns name of the DHCP message.

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

Implements isc::dhcp::Pkt.

Definition at line 357 of file pkt4.cc.

References getName(), and getType().

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

+ Here is the call graph for this function:

◆ getName() [2/2]

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

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

This method is exception safe. For messages without DHCP Message Type options, it returns UNKNOWN.

Parameters
typeDHCPv4 message type which name should be returned.
Returns
Pointer to the "const" string containing DHCP message name. If the message type is unsupported the "UNKNOWN" is returned. The caller must not release the returned pointer.

Definition at line 282 of file pkt4.cc.

References isc::dhcp::DHCPACK, isc::dhcp::DHCPBULKLEASEQUERY, isc::dhcp::DHCPDECLINE, isc::dhcp::DHCPDISCOVER, isc::dhcp::DHCPINFORM, isc::dhcp::DHCPLEASEACTIVE, isc::dhcp::DHCPLEASEQUERY, isc::dhcp::DHCPLEASEQUERYDONE, isc::dhcp::DHCPLEASEQUERYSTATUS, isc::dhcp::DHCPLEASEUNASSIGNED, isc::dhcp::DHCPLEASEUNKNOWN, isc::dhcp::DHCPNAK, isc::dhcp::DHCPOFFER, isc::dhcp::DHCPRELEASE, isc::dhcp::DHCPREQUEST, and isc::dhcp::DHCPTLS.

◆ getOp()

uint8_t isc::dhcp::Pkt4::getOp ( ) const
inline

Returns op field.

Returns
op field

Definition at line 156 of file pkt4.h.

References op_.

◆ getSecs()

uint16_t isc::dhcp::Pkt4::getSecs ( ) const
inline

Returns secs field.

Returns
secs field

Definition at line 166 of file pkt4.h.

References secs_.

◆ getSiaddr()

const isc::asiolink::IOAddress & isc::dhcp::Pkt4::getSiaddr ( ) const
inline

Returns siaddr field.

Returns
siaddr field

Definition at line 194 of file pkt4.h.

References siaddr_.

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

◆ getSname()

const OptionBuffer isc::dhcp::Pkt4::getSname ( ) const
inline

Returns sname field.

Note: This is 64 bytes long field. It doesn't have to be null-terminated. Do not use strlen() or similar on it.

Returns
sname field

Definition at line 265 of file pkt4.h.

References MAX_SNAME_LEN, and sname_.

◆ getType()

uint8_t isc::dhcp::Pkt4::getType ( ) const
virtual

Returns DHCP message type (e.g.

1 = DHCPDISCOVER).

This method is exception safe. For packets without DHCP Message Type option, it returns DHCP_NOTYPE (0).

Returns
message type

Implements isc::dhcp::Pkt.

Definition at line 234 of file pkt4.cc.

References isc::dhcp::DHCP_NOTYPE, isc::dhcp::DHO_DHCP_MESSAGE_TYPE, and isc::dhcp::Pkt::getNonCopiedOption().

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

+ Here is the call graph for this function:

◆ getYiaddr()

const isc::asiolink::IOAddress & isc::dhcp::Pkt4::getYiaddr ( ) const
inline

Returns yiaddr field.

Returns
yiaddr field

Definition at line 206 of file pkt4.h.

References yiaddr_.

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

◆ isDhcp4o6()

virtual bool isc::dhcp::Pkt4::isDhcp4o6 ( ) const
inlinevirtual

Checks if a DHCPv4 message has been transported over DHCPv6.

Returns
Boolean value which indicates whether the message is transported over DHCPv6 (true) or native DHCPv4 (false)

Reimplemented in isc::dhcp::Pkt4o6.

Definition at line 405 of file pkt4.h.

◆ isRelayed()

bool isc::dhcp::Pkt4::isRelayed ( ) const

Checks if a DHCPv4 message has been relayed.

This function returns a boolean value which indicates whether a DHCPv4 message has been relayed (if true is returned) or not (if false).

The message is considered relayed if the giaddr field is non-zero and non-broadcast.

Returns
Boolean value which indicates whether the message is relayed (true) or non-relayed (false).

Definition at line 600 of file pkt4.cc.

References giaddr_, isc::asiolink::IOAddress::isV4Bcast(), and isc::asiolink::IOAddress::isV4Zero().

+ Here is the call graph for this function:

◆ len()

size_t isc::dhcp::Pkt4::len ( )
virtual

Returns the size of the required buffer to build the packet.

Returns the size of the required buffer to build the packet with the current set of packet options.

Returns
number of bytes required to build this packet

Implements isc::dhcp::Pkt.

Definition at line 59 of file pkt4.cc.

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

Referenced by Pkt4(), and getHlen().

◆ makeLabel() [1/2]

std::string isc::dhcp::Pkt4::makeLabel ( const HWAddrPtr & hwaddr,
const ClientIdPtr & client_id )
static

Returns text representation of the given packet identifiers.

This variant of the method does not include transaction id.

Parameters
hwaddrhardware address to include in the string, it may be NULL.
client_idclient id to include in the string, it may be NULL.

Definition at line 410 of file pkt4.cc.

◆ makeLabel() [2/2]

std::string isc::dhcp::Pkt4::makeLabel ( const HWAddrPtr & hwaddr,
const ClientIdPtr & client_id,
const uint32_t transid )
static

Returns text representation of the given packet identifiers.

Parameters
hwaddr- hardware address to include in the string, it may be NULL.
client_id- client id to include in the string, it may be NULL. to include in the string
transid- numeric transaction id to include in the string
Returns
string with text representation

Definition at line 397 of file pkt4.cc.

References makeLabel().

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

+ Here is the call graph for this function:

◆ pack()

void isc::dhcp::Pkt4::pack ( )
virtual

Prepares on-wire format of DHCPv4 packet.

Prepares on-wire format of message and all its options. Options must be stored in options_ field. Output buffer will be stored in buffer_out_. The buffer_out_ is cleared before writing to the buffer.

Exceptions
InvalidOperationif packing fails

Create a ManagedScopedOptionsCopyContainer to handle storing and restoration of copied options.

Implements isc::dhcp::Pkt.

Reimplemented in isc::dhcp::Pkt4o6.

Definition at line 71 of file pkt4.cc.

References isc::dhcp::Pkt::buffer_out_, ciaddr_, isc::util::OutputBuffer::clear(), isc::dhcp::DHO_END, file_, flags_, giaddr_, hops_, hwaddr_, isc_throw, MAX_CHADDR_LEN, MAX_FILE_LEN, MAX_SNAME_LEN, op_, isc::dhcp::Pkt::options_, isc::dhcp::LibDHCP::packOptions4(), isc::dhcp::ManagedScopedOptionsCopyContainer::scoped_options_, secs_, siaddr_, sname_, isc::dhcp::LibDHCP::splitOptions4(), isc::asiolink::IOAddress::toUint32(), isc::dhcp::Pkt::transid_, isc::Exception::what(), isc::util::OutputBuffer::writeData(), isc::util::OutputBuffer::writeUint16(), isc::util::OutputBuffer::writeUint32(), isc::util::OutputBuffer::writeUint8(), and yiaddr_.

Referenced by isc::dhcp::Pkt4o6::pack().

+ Here is the call graph for this function:

◆ setCiaddr()

void isc::dhcp::Pkt4::setCiaddr ( const isc::asiolink::IOAddress & ciaddr)
inline

Sets ciaddr field.

Parameters
ciaddrvalue to be set

Definition at line 188 of file pkt4.h.

References ciaddr_.

◆ setFile()

void isc::dhcp::Pkt4::setFile ( const uint8_t * file,
size_t file_len )

Sets file field.

Parameters
filevalue to be set
file_lenlength of the file buffer (up to MAX_FILE_LEN)

Definition at line 526 of file pkt4.cc.

References file_, isc_throw, and MAX_FILE_LEN.

◆ setFlags()

void isc::dhcp::Pkt4::setFlags ( uint16_t flags)
inline

Sets flags field.

Parameters
flagsvalue to be set

Definition at line 171 of file pkt4.h.

References flags_.

◆ setGiaddr()

void isc::dhcp::Pkt4::setGiaddr ( const isc::asiolink::IOAddress & giaddr)
inline

Sets giaddr field.

Parameters
giaddrvalue to be set

Definition at line 224 of file pkt4.h.

References giaddr_.

◆ setHops()

void isc::dhcp::Pkt4::setHops ( uint8_t hops)
inline

Sets hops field.

Parameters
hopsvalue to be set

Definition at line 143 of file pkt4.h.

References hops_.

◆ setHWAddr() [1/2]

void isc::dhcp::Pkt4::setHWAddr ( const HWAddrPtr & addr)

Sets hardware address.

Sets hardware address, based on existing HWAddr structure

Parameters
addralready filled in HWAddr structure
Exceptions
BadValueif addr is null

Definition at line 464 of file pkt4.cc.

References hwaddr_, and isc_throw.

◆ setHWAddr() [2/2]

void isc::dhcp::Pkt4::setHWAddr ( uint8_t htype,
uint8_t hlen,
const std::vector< uint8_t > & mac_addr )

Sets hardware address.

Sets parameters of hardware address. hlen specifies length of mac_addr buffer. Content of mac_addr buffer will be copied to appropriate field.

Note: mac_addr must be a buffer of at least hlen bytes.

Parameters
htypehardware type (will be sent in htype field)
hlenhardware length (will be sent in hlen field)
mac_addrpointer to hardware address

Definition at line 458 of file pkt4.cc.

References hwaddr_.

◆ setLocalHWAddr() [1/2]

void isc::dhcp::Pkt4::setLocalHWAddr ( const HWAddrPtr & addr)

Sets local HW address.

Sets hardware address from an existing HWAddr structure. The local address is a source address for outgoing packet and destination address for incoming packet.

Parameters
addrstructure representing HW address.
Exceptions
BadValueif addr is null

Definition at line 499 of file pkt4.cc.

References isc_throw, and local_hwaddr_.

◆ setLocalHWAddr() [2/2]

void isc::dhcp::Pkt4::setLocalHWAddr ( const uint8_t htype,
const uint8_t hlen,
const std::vector< uint8_t > & mac_addr )

Sets local HW address.

Sets the source HW address for the outgoing packet or destination HW address for the incoming packet.

Note
mac_addr must be a buffer of at least hlen bytes.
Parameters
htypehardware type (will be sent in htype field)
hlenhardware length (will be sent in hlen field)
mac_addrpointer to hardware address

Definition at line 493 of file pkt4.cc.

References local_hwaddr_.

◆ setSecs()

void isc::dhcp::Pkt4::setSecs ( uint16_t secs)
inline

Sets secs field.

Parameters
secsvalue to be set

Definition at line 161 of file pkt4.h.

References secs_.

◆ setSiaddr()

void isc::dhcp::Pkt4::setSiaddr ( const isc::asiolink::IOAddress & siaddr)
inline

Sets siaddr field.

Parameters
siaddrvalue to be set

Definition at line 200 of file pkt4.h.

References siaddr_.

◆ setSname()

void isc::dhcp::Pkt4::setSname ( const uint8_t * sname,
size_t sname_len )

Sets sname field.

Parameters
snamevalue to be set
sname_lenlength of the sname buffer (up to MAX_SNAME_LEN)

Definition at line 508 of file pkt4.cc.

References isc_throw, MAX_SNAME_LEN, and sname_.

◆ setType()

void isc::dhcp::Pkt4::setType ( uint8_t type)
virtual

Sets DHCP message type (e.g.

1 = DHCPDISCOVER).

Parameters
typemessage type to be set

Implements isc::dhcp::Pkt.

Definition at line 251 of file pkt4.cc.

References addOption(), isc::dhcp::DHO_DHCP_MESSAGE_TYPE, isc::dhcp::Pkt::getNonCopiedOption(), and isc::dhcp::Option::V4.

Referenced by Pkt4().

+ Here is the call graph for this function:

◆ setYiaddr()

void isc::dhcp::Pkt4::setYiaddr ( const isc::asiolink::IOAddress & yiaddr)
inline

Sets yiaddr field.

Parameters
yiaddrvalue to be set

Definition at line 212 of file pkt4.h.

References yiaddr_.

◆ toText()

std::string isc::dhcp::Pkt4::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 420 of file pkt4.cc.

References isc::dhcp::DHCP_NOTYPE, getName(), getType(), isc::dhcp::Pkt::local_addr_, isc::dhcp::Pkt::local_port_, isc::dhcp::Pkt::options_, 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::Pkt4::unpack ( )
virtual

Parses on-wire form of DHCPv4 packet.

Parses received packet, stored in on-wire format in bufferIn_.

Will create a collection of option objects that will be stored in options_ container.

Method with throw exception if packet parsing fails.

Implements isc::dhcp::Pkt.

Definition at line 151 of file pkt4.cc.

References ciaddr_, isc::dhcp::Pkt::data_, deferred_options_, DHCP4_OPTION_SPACE, DHCPV4_PKT_HDR_LEN, isc::dhcp::LibDHCP::extendVendorOptions4(), file_, flags_, isc::util::InputBuffer::getLength(), isc::util::InputBuffer::getPosition(), giaddr_, hops_, hwaddr_, isc_throw, MAX_CHADDR_LEN, MAX_FILE_LEN, MAX_SNAME_LEN, op_, isc::dhcp::Pkt::options_, isc::util::InputBuffer::readData(), isc::util::InputBuffer::readUint16(), isc::util::InputBuffer::readUint32(), isc::util::InputBuffer::readUint8(), isc::util::InputBuffer::readVector(), secs_, siaddr_, sname_, isc::dhcp::Pkt::transid_, isc::dhcp::LibDHCP::unpackOptions4(), and yiaddr_.

+ Here is the call graph for this function:

Member Data Documentation

◆ ciaddr_

isc::asiolink::IOAddress isc::dhcp::Pkt4::ciaddr_
protected

ciaddr field (32 bits): Client's IP address

Definition at line 534 of file pkt4.h.

Referenced by getCiaddr(), pack(), setCiaddr(), and unpack().

◆ deferred_options_

std::list<uint16_t> isc::dhcp::Pkt4::deferred_options_
protected

Definition at line 507 of file pkt4.h.

Referenced by getDeferredOptions(), and unpack().

◆ DHCPV4_PKT_HDR_LEN

const size_t isc::dhcp::Pkt4::DHCPV4_PKT_HDR_LEN = 236
static

specifies DHCPv4 packet header length (fixed part)

Definition at line 50 of file pkt4.h.

Referenced by Pkt4(), len(), and unpack().

◆ file_

uint8_t isc::dhcp::Pkt4::file_[MAX_FILE_LEN]
protected

file field (128 bytes)

Definition at line 549 of file pkt4.h.

Referenced by Pkt4(), Pkt4(), getFile(), pack(), setFile(), and unpack().

◆ FLAG_BROADCAST_MASK

const uint16_t isc::dhcp::Pkt4::FLAG_BROADCAST_MASK = 0x8000
static

Mask for the value of flags field in the DHCPv4 message to check whether client requested broadcast response.

Definition at line 54 of file pkt4.h.

Referenced by isc::dhcp::Dhcpv4Srv::adjustRemoteAddr(), and isc::dhcp::writeEthernetHeader().

◆ flags_

uint16_t isc::dhcp::Pkt4::flags_
protected

flags

Definition at line 531 of file pkt4.h.

Referenced by getFlags(), pack(), setFlags(), and unpack().

◆ giaddr_

isc::asiolink::IOAddress isc::dhcp::Pkt4::giaddr_
protected

giaddr field (32 bits): Gateway IP address

Definition at line 543 of file pkt4.h.

Referenced by getGiaddr(), isRelayed(), pack(), setGiaddr(), and unpack().

◆ hops_

uint8_t isc::dhcp::Pkt4::hops_
protected

Number of relay agents traversed.

Definition at line 525 of file pkt4.h.

Referenced by getHops(), pack(), setHops(), and unpack().

◆ hwaddr_

HWAddrPtr isc::dhcp::Pkt4::hwaddr_
protected

link-layer address and hardware information represents 3 fields: htype (hardware type, 1 byte), hlen (length of the hardware address, up to 16) and chaddr (hardware address field, 16 bytes)

Definition at line 522 of file pkt4.h.

Referenced by getHlen(), getHtype(), getHWAddr(), getHWAddrLabel(), getLabel(), pack(), setHWAddr(), setHWAddr(), and unpack().

◆ local_hwaddr_

HWAddrPtr isc::dhcp::Pkt4::local_hwaddr_
protected

local HW address (dst if receiving packet, src if sending packet)

Definition at line 504 of file pkt4.h.

Referenced by getLocalHWAddr(), setLocalHWAddr(), and setLocalHWAddr().

◆ MAX_CHADDR_LEN

const size_t isc::dhcp::Pkt4::MAX_CHADDR_LEN = 16
static

length of the CHADDR field in DHCPv4 message

Definition at line 41 of file pkt4.h.

Referenced by getHlen(), pack(), and unpack().

◆ MAX_FILE_LEN

const size_t isc::dhcp::Pkt4::MAX_FILE_LEN = 128
static

◆ MAX_SNAME_LEN

const size_t isc::dhcp::Pkt4::MAX_SNAME_LEN = 64
static

◆ op_

uint8_t isc::dhcp::Pkt4::op_
protected

message operation code

Note: This is legacy BOOTP field. There's no need to manipulate it directly. Its value is set based on DHCP message type. Note that DHCPv4 protocol reuses BOOTP message format, so this field is kept due to BOOTP format. This is NOT DHCPv4 type (DHCPv4 message type is kept in message type option).

Definition at line 516 of file pkt4.h.

Referenced by getOp(), pack(), and unpack().

◆ secs_

uint16_t isc::dhcp::Pkt4::secs_
protected

elapsed (number of seconds since beginning of transmission)

Definition at line 528 of file pkt4.h.

Referenced by getSecs(), pack(), setSecs(), and unpack().

◆ siaddr_

isc::asiolink::IOAddress isc::dhcp::Pkt4::siaddr_
protected

siaddr field (32 bits): next server IP address in boot process(e.g.TFTP)

Definition at line 540 of file pkt4.h.

Referenced by getSiaddr(), pack(), setSiaddr(), and unpack().

◆ sname_

uint8_t isc::dhcp::Pkt4::sname_[MAX_SNAME_LEN]
protected

sname field (64 bytes)

Definition at line 546 of file pkt4.h.

Referenced by Pkt4(), Pkt4(), getSname(), pack(), setSname(), and unpack().

◆ yiaddr_

isc::asiolink::IOAddress isc::dhcp::Pkt4::yiaddr_
protected

yiaddr field (32 bits): Client's IP address ("your"), set by server

Definition at line 537 of file pkt4.h.

Referenced by getYiaddr(), pack(), setYiaddr(), and unpack().


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