Kea  2.1.7-git
isc::dhcp::Pkt4 Class Reference

Represents DHCPv4 packet. More...

#include <pkt4.h>

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

Public Member Functions

 Pkt4 (uint8_t msg_type, uint32_t transid)
 Constructor, used in replying to a message. More...
 
 Pkt4 (const uint8_t *data, size_t len)
 Constructor, used in message reception. More...
 
virtual void addOption (const OptionPtr &opt)
 Add an option. More...
 
const isc::asiolink::IOAddressgetCiaddr () const
 Returns ciaddr field. More...
 
std::list< uint16_t > & getDeferredOptions ()
 Returns a reference to option codes which unpacking will be deferred. More...
 
const OptionBuffer getFile () const
 Returns file field. More...
 
uint16_t getFlags () const
 Returns flags field. More...
 
const isc::asiolink::IOAddressgetGiaddr () const
 Returns giaddr field. More...
 
uint8_t getHlen () const
 Returns hlen field. More...
 
uint8_t getHops () const
 Returns hops field. More...
 
uint8_t getHtype () const
 Returns htype field. More...
 
HWAddrPtr getHWAddr () const
 returns hardware address information More...
 
std::string getLabel () const
 Returns text representation of the primary packet identifiers. More...
 
HWAddrPtr getLocalHWAddr () const
 Returns local HW address. More...
 
const char * getName () const
 Returns name of the DHCP message. More...
 
uint8_t getOp () const
 Returns op field. More...
 
uint16_t getSecs () const
 Returns secs field. More...
 
const isc::asiolink::IOAddressgetSiaddr () const
 Returns siaddr field. More...
 
const OptionBuffer getSname () const
 Returns sname field. More...
 
uint8_t getType () const
 Returns DHCP message type (e.g. More...
 
const isc::asiolink::IOAddressgetYiaddr () const
 Returns yiaddr field. More...
 
virtual bool isDhcp4o6 () const
 Checks if a DHCPv4 message has been transported over DHCPv6. More...
 
bool isRelayed () const
 Checks if a DHCPv4 message has been relayed. More...
 
size_t len ()
 Returns the size of the required buffer to build the packet. More...
 
virtual void pack ()
 Prepares on-wire format of DHCPv4 packet. More...
 
void setCiaddr (const isc::asiolink::IOAddress &ciaddr)
 Sets ciaddr field. More...
 
void setFile (const uint8_t *file, size_t file_len)
 Sets file field. More...
 
void setFlags (uint16_t flags)
 Sets flags field. More...
 
void setGiaddr (const isc::asiolink::IOAddress &giaddr)
 Sets giaddr field. More...
 
void setHops (uint8_t hops)
 Sets hops field. More...
 
void setHWAddr (uint8_t htype, uint8_t hlen, const std::vector< uint8_t > &mac_addr)
 Sets hardware address. More...
 
void setHWAddr (const HWAddrPtr &addr)
 Sets hardware address. More...
 
void setLocalHWAddr (const uint8_t htype, const uint8_t hlen, const std::vector< uint8_t > &mac_addr)
 Sets local HW address. More...
 
void setLocalHWAddr (const HWAddrPtr &addr)
 Sets local HW address. More...
 
void setSecs (uint16_t secs)
 Sets secs field. More...
 
void setSiaddr (const isc::asiolink::IOAddress &siaddr)
 Sets siaddr field. More...
 
void setSname (const uint8_t *sname, size_t sname_len)
 Sets sname field. More...
 
void setType (uint8_t type)
 Sets DHCP message type (e.g. More...
 
void setYiaddr (const isc::asiolink::IOAddress &yiaddr)
 Sets yiaddr field. More...
 
std::string toText () const
 Returns text representation of the packet. More...
 
virtual void unpack ()
 Parses on-wire form of DHCPv4 packet. More...
 
- Public Member Functions inherited from isc::dhcp::Pkt
virtual ~Pkt ()
 Virtual destructor. More...
 
void addClass (const isc::dhcp::ClientClass &client_class, bool required=false)
 Adds packet to a specified class. More...
 
bool delOption (uint16_t type)
 Attempts to delete first suboption of requested type. More...
 
isc::util::OutputBuffergetBuffer ()
 Returns reference to output buffer. More...
 
const ClientClassesgetClasses (bool required=false) const
 Returns the class set. More...
 
std::string getIface () const
 Returns interface name. More...
 
int getIndex () const
 Returns interface index. More...
 
const isc::asiolink::IOAddressgetLocalAddr () const
 Returns local IP address. More...
 
uint16_t getLocalPort () const
 Returns local UDP (and soon TCP) port. More...
 
HWAddrPtr getMAC (uint32_t hw_addr_src)
 Returns MAC address. More...
 
OptionPtr getOption (const uint16_t type)
 Returns the first option of specified type. More...
 
const isc::asiolink::IOAddressgetRemoteAddr () const
 Returns remote IP address. More...
 
HWAddrPtr getRemoteHWAddr () const
 Returns the remote HW address obtained from raw sockets. More...
 
uint16_t getRemotePort () const
 Returns remote port. More...
 
const boost::posix_time::ptime & getTimestamp () const
 Returns packet timestamp. More...
 
uint32_t getTransid () const
 Returns value of transaction-id field. More...
 
bool inClass (const isc::dhcp::ClientClass &client_class)
 Checks whether a client belongs to a given class. More...
 
bool indexSet () const
 Checks if interface index has been set. More...
 
bool isCopyRetrievedOptions () const
 Returns whether the copying of retrieved options is enabled. More...
 
void repack ()
 Copies content of input buffer to output buffer. More...
 
void resetIndex ()
 Resets interface index to negative value. More...
 
virtual void setCopyRetrievedOptions (const bool copy)
 Controls whether the option retrieved by the Pkt::getOption should be copied before being returned. More...
 
void setIface (const std::string &iface)
 Sets interface name. More...
 
void setIndex (int ifindex)
 Sets interface index. More...
 
void setLocalAddr (const isc::asiolink::IOAddress &local)
 Sets local IP address. More...
 
void setLocalPort (uint16_t local)
 Sets local UDP (and soon TCP) port. More...
 
void setRemoteAddr (const isc::asiolink::IOAddress &remote)
 Sets remote IP address. More...
 
void setRemoteHWAddr (const HWAddrPtr &hw_addr)
 Sets remote hardware address. More...
 
void setRemoteHWAddr (const uint8_t htype, const uint8_t hlen, const std::vector< uint8_t > &hw_addr)
 Sets remote hardware address. More...
 
void setRemotePort (uint16_t remote)
 Sets remote UDP (and soon TCP) port. More...
 
void setTimestamp (boost::posix_time::ptime &timestamp)
 Set packet timestamp. More...
 
void setTransid (uint32_t transid)
 Sets transaction-id value. More...
 
void updateTimestamp ()
 Update packet timestamp. More...
 
- Public Member Functions inherited from isc::hooks::CalloutHandleAssociate
 CalloutHandleAssociate ()
 Constructor. More...
 
CalloutHandlePtr getCalloutHandle ()
 Returns callout handle. More...
 

Static Public Member Functions

static const char * getName (const uint8_t type)
 Returns name of the DHCP message for a given type number. More...
 
static std::string makeLabel (const HWAddrPtr &hwaddr, const ClientIdPtr &client_id, const uint32_t transid)
 Returns text representation of the given packet identifiers. More...
 
static std::string makeLabel (const HWAddrPtr &hwaddr, const ClientIdPtr &client_id)
 Returns text representation of the given packet identifiers. More...
 

Static Public Attributes

static const size_t DHCPV4_PKT_HDR_LEN = 236
 specifies DHCPv4 packet header length (fixed part) More...
 
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. More...
 
static const size_t MAX_CHADDR_LEN = 16
 length of the CHADDR field in DHCPv4 message More...
 
static const size_t MAX_FILE_LEN = 128
 length of the FILE field in DHCPv4 message More...
 
static const size_t MAX_SNAME_LEN = 64
 length of the SNAME field in DHCPv4 message More...
 

Protected Member Functions

uint8_t DHCPTypeToBootpType (uint8_t dhcpType)
 converts DHCP message type to BOOTP op type More...
 
virtual HWAddrPtr getMACFromDocsisCMTS ()
 No-op. More...
 
virtual HWAddrPtr getMACFromDocsisModem ()
 No-op. More...
 
virtual HWAddrPtr getMACFromDUID ()
 No-op. More...
 
virtual HWAddrPtr getMACFromIPv6RelayOpt ()
 No-op. More...
 
virtual HWAddrPtr getMACFromRemoteIdRelayOption ()
 No-op. More...
 
virtual HWAddrPtr getMACFromSrcLinkLocalAddr ()
 No-op. More...
 
- Protected Member Functions inherited from isc::dhcp::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. More...
 
 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. More...
 
HWAddrPtr getMACFromIPv6 (const isc::asiolink::IOAddress &addr)
 Attempts to convert IPv6 address into MAC. More...
 
OptionPtr getNonCopiedOption (const uint16_t type) const
 Returns the first option of specified type without copying. More...
 

Protected Attributes

isc::asiolink::IOAddress ciaddr_
 ciaddr field (32 bits): Client's IP address More...
 
std::list< uint16_t > deferred_options_
 
uint8_t file_ [MAX_FILE_LEN]
 file field (128 bytes) More...
 
uint16_t flags_
 flags More...
 
isc::asiolink::IOAddress giaddr_
 giaddr field (32 bits): Gateway IP address More...
 
uint8_t hops_
 Number of relay agents traversed. More...
 
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) More...
 
HWAddrPtr local_hwaddr_
 local HW address (dst if receiving packet, src if sending packet) More...
 
uint8_t op_
 message operation code More...
 
uint16_t secs_
 elapsed (number of seconds since beginning of transmission) More...
 
isc::asiolink::IOAddress siaddr_
 siaddr field (32 bits): next server IP address in boot process(e.g.TFTP) More...
 
uint8_t sname_ [MAX_SNAME_LEN]
 sname field (64 bytes) More...
 
isc::asiolink::IOAddress yiaddr_
 yiaddr field (32 bits): Client's IP address ("your"), set by server More...
 
- Protected Attributes inherited from isc::dhcp::Pkt
isc::util::OutputBuffer buffer_out_
 Output buffer (used during message transmission) More...
 
bool copy_retrieved_options_
 Indicates if a copy of the retrieved option should be returned when Pkt::getOption is called. More...
 
std::string iface_
 Name of the network interface the packet was received/to be sent over. More...
 
int64_t ifindex_
 Interface index. More...
 
isc::asiolink::IOAddress local_addr_
 Local IP (v4 or v6) address. More...
 
uint16_t local_port_
 local TDP or UDP port More...
 
isc::asiolink::IOAddress remote_addr_
 Remote IP address. More...
 
HWAddrPtr remote_hwaddr_
 
uint16_t remote_port_
 remote TCP or UDP port More...
 
boost::posix_time::ptime timestamp_
 packet timestamp More...
 
uint32_t transid_
 Transaction-id (32 bits for v4, 24 bits for v6) More...
 
- Protected Attributes inherited from isc::hooks::CalloutHandleAssociate
CalloutHandlePtr callout_handle_
 Callout handle stored. More...
 

Additional Inherited Members

- Public Attributes inherited from isc::dhcp::Pkt
ClientClasses classes_
 Classes this packet belongs to. More...
 
OptionBuffer data_
 Unparsed data (in received packets). More...
 
isc::dhcp::OptionCollection options_
 Collection of options present in this message. More...
 
ClientClasses required_classes_
 Classes which are required to be evaluated. More...
 

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.

◆ 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, MAX_FILE_LEN, MAX_SNAME_LEN, and sname_.

Member Function Documentation

◆ addOption()

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

Add an option.

Exceptions
BadValueif option with that type is already present.
Parameters
optoption to be added

Reimplemented from isc::dhcp::Pkt.

Definition at line 586 of file pkt4.cc.

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

Referenced by getHWAddr(), and 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 374 of file pkt4.h.

References deferred_options_, and isRelayed().

+ Here is the call graph for this function:

◆ 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_, getHlen(), getHtype(), setFile(), and setHWAddr().

+ Here is the call graph for this function:

◆ 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 577 of file pkt4.cc.

References hwaddr_, len(), and MAX_CHADDR_LEN.

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

+ 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 569 of file pkt4.cc.

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

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

◆ 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 addOption(), hwaddr_, and setLocalHWAddr().

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

+ Here is the call graph for this function:

◆ 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 366 of file pkt4.cc.

References isc::dhcp::DHO_DHCP_CLIENT_IDENTIFIER, 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 361 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 478 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 456 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 467 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 445 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 488 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 433 of file pkt4.h.

◆ getName() [1/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 283 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.

◆ getName() [2/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 358 of file pkt4.cc.

References getType().

Referenced by setGiaddr(), and toText().

+ Here is the call graph for this function:

◆ 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 setSname(), and sname_.

+ Here is the call graph for this function:

◆ 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 235 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(), setGiaddr(), 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 394 of file pkt4.h.

References DHCPTypeToBootpType().

+ Here is the call graph for this function:

◆ 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 597 of file pkt4.cc.

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

Referenced by getDeferredOptions().

+ 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 getHlen().

◆ makeLabel() [1/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.

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

◆ makeLabel() [2/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.

◆ 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 523 of file pkt4.cc.

References isc::data::copy(), file_, isc_throw, and MAX_FILE_LEN.

Referenced by getFile().

+ Here is the call graph for this function:

◆ 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 getName(), getType(), giaddr_, and setType().

+ Here is the call graph for this function:

◆ 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 ( 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 455 of file pkt4.cc.

References hwaddr_.

Referenced by getFile().

◆ setHWAddr() [2/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 461 of file pkt4.cc.

References hwaddr_, isc_throw, and MAX_CHADDR_LEN.

◆ setLocalHWAddr() [1/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 490 of file pkt4.cc.

References local_hwaddr_.

Referenced by getHWAddr().

◆ setLocalHWAddr() [2/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 496 of file pkt4.cc.

References isc_throw, and 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 505 of file pkt4.cc.

References isc::data::copy(), isc_throw, MAX_SNAME_LEN, and sname_.

Referenced by getSname().

+ Here is the call graph for this function:

◆ 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 252 of file pkt4.cc.

References addOption(), isc::dhcp::DHO_DHCP_MESSAGE_TYPE, isc::dhcp::Pkt::getNonCopiedOption(), isc::dhcp::OptionInt< T >::setValue(), and isc::dhcp::Option::V4.

Referenced by setGiaddr().

+ 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 148 of file pkt4.cc.

References ciaddr_, isc::dhcp::Pkt::data_, deferred_options_, DHCP4_OPTION_SPACE, DHCPV4_PKT_HDR_LEN, file_, flags_, isc::dhcp::LibDHCP::fuseOptions4(), giaddr_, hops_, hwaddr_, isc_throw, MAX_CHADDR_LEN, MAX_FILE_LEN, MAX_SNAME_LEN, op_, isc::dhcp::Pkt::options_, 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 523 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 496 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 len(), Pkt4(), and unpack().

◆ file_

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

file field (128 bytes)

Definition at line 538 of file pkt4.h.

Referenced by getFile(), pack(), Pkt4(), 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().

◆ flags_

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

flags

Definition at line 520 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 532 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 514 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 511 of file pkt4.h.

Referenced by getHlen(), getHtype(), getHWAddr(), getLabel(), pack(), 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 493 of file pkt4.h.

Referenced by getLocalHWAddr(), 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(), setHWAddr(), and unpack().

◆ MAX_FILE_LEN

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

length of the FILE field in DHCPv4 message

Definition at line 47 of file pkt4.h.

Referenced by isc::dhcp::Subnet4ConfigParser::initSubnet(), pack(), isc::dhcp::SharedNetwork4Parser::parse(), Pkt4(), isc::dhcp::Host::setBootFileName(), setFile(), and unpack().

◆ MAX_SNAME_LEN

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

length of the SNAME field in DHCPv4 message

Definition at line 44 of file pkt4.h.

Referenced by isc::dhcp::Subnet4ConfigParser::initSubnet(), pack(), isc::dhcp::SharedNetwork4Parser::parse(), Pkt4(), isc::dhcp::Host::setServerHostname(), setSname(), and unpack().

◆ 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 505 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 517 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 529 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 535 of file pkt4.h.

Referenced by getSname(), pack(), Pkt4(), 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 526 of file pkt4.h.

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


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