Kea 2.7.6
|
Base class for classes representing DHCP messages. More...
#include <pkt.h>
Public Member Functions | |
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 ×tamp=PktEvent::now()) |
Adds an event to the end of the event stack. | |
void | addPktEvent (const std::string &label, const struct timeval ×tamp) |
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. | |
virtual std::string | getLabel () const |
Returns text representation primary packet identifiers. | |
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. | |
virtual const char * | getName () const =0 |
Returns name of the DHCP message. | |
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. | |
virtual uint8_t | getType () const =0 |
Returns message type (e.g. | |
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. | |
virtual size_t | len ()=0 |
Returns packet size in binary format. | |
virtual void | pack ()=0 |
Prepares on-wire format of DHCP (either v4 or v6) packet. | |
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 ×tamp=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 ×tamp) |
Set socket receive timestamp. | |
void | setTransid (uint32_t transid) |
Sets transaction-id value. | |
virtual void | setType (uint8_t type)=0 |
Sets message type (e.g. | |
virtual std::string | toText () const =0 |
Returns text representation of the packet. | |
virtual void | unpack ()=0 |
Parses on-wire form of DHCP (either v4 or v6) packet. | |
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. | |
Public Attributes | |
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. | |
Protected Member Functions | |
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. | |
virtual HWAddrPtr | getMACFromDocsisCMTS ()=0 |
Attempts to extract MAC/Hardware address from DOCSIS options inserted by the CMTS (the relay agent) | |
virtual HWAddrPtr | getMACFromDocsisModem ()=0 |
Attempts to extract MAC/Hardware address from DOCSIS options inserted by the modem itself. | |
virtual HWAddrPtr | getMACFromDUID ()=0 |
Attempts to obtain MAC address from DUID-LL or DUID-LLT. | |
HWAddrPtr | getMACFromIPv6 (const isc::asiolink::IOAddress &addr) |
Attempts to convert IPv6 address into MAC. | |
virtual HWAddrPtr | getMACFromIPv6RelayOpt ()=0 |
Attempts to obtain MAC address from relay option client-linklayer-addr. | |
virtual HWAddrPtr | getMACFromRemoteIdRelayOption ()=0 |
Attempts to obtain MAC address from remote-id relay option. | |
virtual HWAddrPtr | getMACFromSrcLinkLocalAddr ()=0 |
Attempts to obtain MAC address from source link-local IPv6 address. | |
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::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. | |
Base class for classes representing DHCP messages.
This is a base class that holds common information (e.g. source and destination ports) and operations (e.g. add, get, delete options) for derived classes representing both DHCPv4 and DHCPv6 messages. The Pkt4
and Pkt6
classes derive from it.
|
protected |
Constructor.
This constructor is typically used for transmitted messages as it creates an empty (no options) packet. The constructor is protected, so only derived classes can call it. Pkt class cannot be instantiated anyway, because it is an abstract class.
transid | transaction-id |
local_addr | local IPv4 or IPv6 address |
remote_addr | remote IPv4 or IPv6 address |
local_port | local UDP (one day also TCP) port |
remote_port | remote UDP (one day also TCP) port |
|
protected |
Constructor.
This constructor is typically used for received messages as it takes a buffer that's going to be parsed as one of arguments. The constructor is protected, so only derived classes can call it. Pkt class cannot be instantiated anyway, because it is an abstract class.
buf | pointer to a buffer that contains on-wire data |
len | length of the pointer specified in buf |
local_addr | local IPv4 or IPv6 address |
remote_addr | remote IPv4 or IPv6 address |
local_port | local UDP (one day also TCP) port |
remote_port | remote UDP (one day also TCP) port |
Definition at line 32 of file pkt.cc.
References data_, isc_throw, and len().
|
inlinevirtual |
void isc::dhcp::Pkt::addAdditionalClass | ( | const isc::dhcp::ClientClass & | client_class | ) |
Adds a specified class to the packet's additional class list.
A class can be added to the same packet repeatedly. Any additional attempts to add to a packet the class already added, will be ignored silently.
client_class | name of the class to be added |
Definition at line 134 of file pkt.cc.
References additional_classes_, isc::dhcp::ClientClasses::contains(), and isc::dhcp::ClientClasses::insert().
void isc::dhcp::Pkt::addClass | ( | const isc::dhcp::ClientClass & | client_class | ) |
Adds a specified class to the packet.
A class can be added to the same packet repeatedly. Any additional attempts to add to a packet the class already added, will be ignored silently.
client_class | name of the class to be added |
Definition at line 126 of file pkt.cc.
References classes_, isc::dhcp::ClientClasses::contains(), isc::dhcp::ClientClasses::insert(), and subclasses_.
|
virtual |
Adds an option to this packet.
Derived classes may provide more specialized implementations. In particular Pkt4
provides one that checks if option is unique.
opt | option to be added. |
Reimplemented in isc::dhcp::Pkt4.
Definition at line 57 of file pkt.cc.
References options_.
Referenced by isc::dhcp::Pkt4::addOption().
void isc::dhcp::Pkt::addPktEvent | ( | const std::string & | label, |
const boost::posix_time::ptime & | timestamp = PktEvent::now() ) |
Adds an event to the end of the event stack.
label | string identifying the event |
timestamp | time at which the event occurred. It is expected to be in UTC/microseconds. Defaults to the current time. |
Definition at line 328 of file pkt.cc.
Referenced by addPktEvent().
void isc::dhcp::Pkt::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.
label | string identifying the event |
timestamp | time at which the event occurred. It is expected to be in UTC/microseconds. |
Definition at line 345 of file pkt.cc.
References addPktEvent().
void isc::dhcp::Pkt::addSubClass | ( | const isc::dhcp::ClientClass & | class_def, |
const isc::dhcp::ClientClass & | subclass ) |
Adds a specified subclass to the packet.
A subclass can be added to the same packet repeatedly. Any additional attempts to add to a packet the subclass already added, will be ignored silently.
class_def | name of the class definition to be added |
subclass | name of the subclass to be added |
Definition at line 142 of file pkt.cc.
References classes_, isc::dhcp::ClientClasses::contains(), isc::dhcp::ClientClasses::insert(), and subclasses_.
void isc::dhcp::Pkt::clearPktEvents | ( | ) |
OptionCollection isc::dhcp::Pkt::cloneOptions | ( | ) |
bool isc::dhcp::Pkt::delOption | ( | uint16_t | type | ) |
Attempts to delete first suboption of requested type.
If there are several options of the same type present, only the first option will be deleted.
type | Type of option to be deleted. |
Definition at line 110 of file pkt.cc.
References options_.
std::string isc::dhcp::Pkt::dumpPktEvents | ( | bool | verbose = false | ) | const |
|
inline |
Returns the additional class list.
Definition at line 392 of file pkt.h.
References additional_classes_.
|
inline |
Returns reference to output buffer.
Returned buffer will contain reasonable data only for output (TX) packet and after pack() was called.
RX packet or TX packet before pack() will return buffer with zero length. This buffer is returned as non-const, so hooks framework (and user's callouts) can modify them if needed
Definition at line 245 of file pkt.h.
References buffer_out_.
Referenced by isc::dhcp::Pkt4o6::pack().
|
inline |
|
inline |
Returns interface name.
Returns interface name over which packet was received or is going to be transmitted.
Definition at line 692 of file pkt.h.
References iface_.
Referenced by isc::dhcp::TokenPkt::evaluate().
|
inline |
|
inlinevirtual |
Returns text representation primary packet identifiers.
This method is intended to be used to provide as a consistent way to identify packets within log statements. Derivations should supply there own implementation.
Reimplemented in isc::dhcp::Pkt4, and isc::dhcp::Pkt6.
Definition at line 275 of file pkt.h.
References isc_throw.
Referenced by isc::dhcp::TokenAnd::evaluate(), isc::dhcp::TokenConcat::evaluate(), isc::dhcp::TokenEqual::evaluate(), isc::dhcp::TokenHexString::evaluate(), isc::dhcp::TokenIfElse::evaluate(), isc::dhcp::TokenInt16ToText::evaluate(), isc::dhcp::TokenInt32ToText::evaluate(), isc::dhcp::TokenInt8ToText::evaluate(), isc::dhcp::TokenIpAddress::evaluate(), isc::dhcp::TokenIpAddressToText::evaluate(), isc::dhcp::TokenLowerCase::evaluate(), isc::dhcp::TokenMember::evaluate(), isc::dhcp::TokenNot::evaluate(), isc::dhcp::TokenOption::evaluate(), isc::dhcp::TokenOr::evaluate(), isc::dhcp::TokenPkt4::evaluate(), isc::dhcp::TokenPkt6::evaluate(), isc::dhcp::TokenPkt::evaluate(), isc::dhcp::TokenRelay6Field::evaluate(), isc::dhcp::TokenSplit::evaluate(), isc::dhcp::TokenString::evaluate(), isc::dhcp::TokenSubOption::evaluate(), isc::dhcp::TokenSubstring::evaluate(), isc::dhcp::TokenToHexString::evaluate(), isc::dhcp::TokenUInt16ToText::evaluate(), isc::dhcp::TokenUInt32ToText::evaluate(), isc::dhcp::TokenUInt8ToText::evaluate(), isc::dhcp::TokenUpperCase::evaluate(), isc::dhcp::TokenVendor::evaluate(), and isc::dhcp::TokenVendorClass::evaluate().
|
inline |
Returns local IP address.
Definition at line 619 of file pkt.h.
References local_addr_.
Referenced by isc::dhcp::TokenPkt::evaluate().
|
inline |
Returns local UDP (and soon TCP) port.
This sets a local port, i.e. destination port for recently received packet or a source port for to be transmitted packet.
Definition at line 639 of file pkt.h.
References local_port_.
HWAddrPtr isc::dhcp::Pkt::getMAC | ( | uint32_t | hw_addr_src | ) |
Returns MAC address.
The difference between this method and getRemoteHWAddr() is that getRemoteHWAddr() returns only what was obtained from raw sockets. This method is more generic and can attempt to obtain MAC from varied sources: raw sockets, client-id, link-local IPv6 address, and various relay options.
hw_addr_src takes a combination of bit values specified in HWADDR_SOURCE_* constants.
hw_addr_src | a bitmask that specifies hardware address source |
Definition at line 187 of file pkt.cc.
References getMACFromDocsisCMTS(), getMACFromDocsisModem(), getMACFromDUID(), getMACFromIPv6RelayOpt(), getMACFromRemoteIdRelayOption(), getMACFromSrcLinkLocalAddr(), getRemoteHWAddr(), isc::dhcp::HWAddr::HWADDR_SOURCE_CLIENT_ADDR_RELAY_OPTION, isc::dhcp::HWAddr::HWADDR_SOURCE_DOCSIS_CMTS, isc::dhcp::HWAddr::HWADDR_SOURCE_DOCSIS_MODEM, isc::dhcp::HWAddr::HWADDR_SOURCE_DUID, isc::dhcp::HWAddr::HWADDR_SOURCE_IPV6_LINK_LOCAL, isc::dhcp::HWAddr::HWADDR_SOURCE_RAW, and isc::dhcp::HWAddr::HWADDR_SOURCE_REMOTE_ID.
|
protectedpure virtual |
Attempts to extract MAC/Hardware address from DOCSIS options inserted by the CMTS (the relay agent)
This is a generic mechanism for extracting hardware address from the DOCSIS options.
Pkt6
class have respective implementation. This method is currently not implemented in DHCPv4.Implemented in isc::dhcp::Pkt4, and isc::dhcp::Pkt6.
Referenced by getMAC().
|
protectedpure virtual |
Attempts to extract MAC/Hardware address from DOCSIS options inserted by the modem itself.
This is a generic mechanism for extracting hardware address from the DOCSIS options.
Pkt6
class have respective implementation. This method is currently not implemented in DHCPv4.Implemented in isc::dhcp::Pkt4, and isc::dhcp::Pkt6.
Referenced by getMAC().
|
protectedpure virtual |
Attempts to obtain MAC address from DUID-LL or DUID-LLT.
This method is called from getMAC(HWADDR_SOURCE_DUID) and should not be called directly. It will attempt to extract MAC address information from DUID if its type is LLT or LL. If this method fails, it will return NULL.
Pkt6
class have respective implementation. This method is not applicable to DHCPv4.Implemented in isc::dhcp::Pkt4, and isc::dhcp::Pkt6.
Referenced by getMAC().
|
protected |
Attempts to convert IPv6 address into MAC.
Utility method that attempts to convert link-local IPv6 address to the MAC address. That works only for link-local IPv6 addresses that are based on EUI-64.
addr | IPv6 address to be converted |
Definition at line 284 of file pkt.cc.
References isc::dhcp::IfaceMgr::getIface(), isc::dhcp::HWAddr::HWADDR_SOURCE_IPV6_LINK_LOCAL, iface_, isc::dhcp::IfaceMgr::instance(), isc::asiolink::IOAddress::isV6LinkLocal(), and isc::asiolink::IOAddress::toBytes().
Referenced by isc::dhcp::Pkt6::getMACFromSrcLinkLocalAddr().
|
protectedpure virtual |
Attempts to obtain MAC address from relay option client-linklayer-addr.
This method is called from getMAC(HWADDR_SOURCE_CLIENT_ADDR_RELAY_OPTION) and should not be called directly. It will extract the client's MAC/Hardware address from option client_linklayer_addr (RFC6939) inserted by the relay agent closest to the client. If this method fails, it will return NULL.
Pkt6
class have respective implementation. This method is not applicable to DHCPv4.Implemented in isc::dhcp::Pkt4, and isc::dhcp::Pkt6.
Referenced by getMAC().
|
protectedpure virtual |
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.
Pkt6
class have respective implementation. This method is not applicable to DHCPv4.Implemented in isc::dhcp::Pkt4, and isc::dhcp::Pkt6.
Referenced by getMAC().
|
protectedpure virtual |
Attempts to obtain MAC address from source link-local IPv6 address.
This method is called from getMAC(HWADDR_SOURCE_IPV6_LINK_LOCAL) and should not be called directly. It is not 100% reliable. The source IPv6 address does not necessarily have to be link-local (may be global or ULA) and even if it's link-local, it doesn't necessarily be based on EUI-64. For example, Windows supports RFC4941, which randomized IID part of the link-local address. If this method fails, it will return NULL.
For direct message, it attempts to use remote_addr_ field. For relayed message, it uses peer-addr of the first relay.
Pkt6
class have respective implementation. This method is not applicable to DHCPv4.Implemented in isc::dhcp::Pkt4, and isc::dhcp::Pkt6.
Referenced by getMAC().
|
pure virtual |
Returns name of the DHCP message.
For all unsupported messages the derived classes must return "UNKNOWN".
Implemented in isc::dhcp::Pkt4, and isc::dhcp::Pkt6.
|
protected |
Returns the first option of specified type without copying.
This method is internally used by the Pkt class and derived classes to retrieve a pointer to the specified option. This method doesn't copy the option before returning it to the caller.
type | Option type. |
Definition at line 62 of file pkt.cc.
References options_.
Referenced by isc::dhcp::Pkt4::addOption(), isc::dhcp::Pkt6::getClientId(), isc::dhcp::Pkt4::getLabel(), isc::dhcp::Pkt6::getMACFromDUID(), isc::dhcp::Pkt4::getType(), and isc::dhcp::Pkt4::setType().
|
protected |
Returns all option instances of specified type without copying.
This is a variant of getOptions method, which returns a collection of options without copying them. This method should be only used by the Pkt6 class and derived classes. Any external callers should use getOptions which copies option instances before returning them when the Pkt::copy_retrieved_options_ flag is set to true.
opt_type | Option code. |
Definition at line 84 of file pkt.cc.
References options_.
Referenced by isc::dhcp::Pkt6::getMACFromDocsisModem().
OptionPtr isc::dhcp::Pkt::getOption | ( | const uint16_t | type | ) |
Returns the first option of specified type.
Returns the first option of specified type. Note that in DHCPv6 several instances of the same option are allowed (and frequently used).
The options will be only returned after unpack() is called.
type | option type we are looking for |
Definition at line 71 of file pkt.cc.
References copy_retrieved_options_, and options_.
Referenced by isc::dhcp::TokenVendor::evaluate(), isc::dhcp::TokenVendorClass::evaluate(), isc::dhcp::TokenOption::getOption(), isc::dhcp::TokenRelay4Option::getOption(), and isc::dhcp::TokenVendor::getOption().
OptionCollection isc::dhcp::Pkt::getOptions | ( | const uint16_t | type | ) |
Returns all instances of specified type.
Returns all instances of options of the specified type. DHCPv6 protocol allows (and uses frequently) multiple instances.
type | option type we are looking for |
Definition at line 91 of file pkt.cc.
References copy_retrieved_options_, and options_.
|
inline |
ptime isc::dhcp::Pkt::getPktEventTime | ( | const std::string & | label | ) | const |
Fetches the timestamp for a given event in the stack.
label | string identifying the event |
Definition at line 354 of file pkt.cc.
References isc::dhcp::PktEvent::EMPTY_TIME().
|
inline |
Returns remote IP address.
Definition at line 605 of file pkt.h.
References remote_addr_.
Referenced by isc::dhcp::TokenPkt::evaluate().
|
inline |
Returns the remote HW address obtained from raw sockets.
Definition at line 743 of file pkt.h.
References remote_hwaddr_.
Referenced by getMAC().
|
inline |
Returns remote port.
Definition at line 656 of file pkt.h.
References remote_port_.
|
inline |
Returns the class set including template classes associated with subclasses.
Definition at line 402 of file pkt.h.
References subclasses_.
|
inline |
Returns packet timestamp.
Returns packet timestamp value updated when packet is received or send.
Definition at line 524 of file pkt.h.
References timestamp_.
|
inline |
Returns value of transaction-id field.
Definition at line 341 of file pkt.h.
References transid_.
Referenced by isc::dhcp::TokenPkt4::evaluate(), isc::dhcp::TokenPkt6::evaluate(), isc::dhcp::Pkt6::getLabel(), isc::perfdhcp::PerfPkt4::rawPack(), isc::perfdhcp::PerfPkt6::rawPack(), isc::perfdhcp::PerfPkt4::rawUnpack(), and isc::perfdhcp::PerfPkt6::rawUnpack().
|
pure virtual |
Returns message type (e.g.
1 = SOLICIT).
Pkt4
and Pkt6
class have respective implementations of this method.Implemented in isc::dhcp::Pkt4, and isc::dhcp::Pkt6.
bool isc::dhcp::Pkt::inClass | ( | const isc::dhcp::ClientClass & | client_class | ) |
Checks whether a client belongs to a given class.
client_class | name of the class |
Definition at line 121 of file pkt.cc.
References classes_, and isc::dhcp::ClientClasses::contains().
Referenced by isc::dhcp::TokenMember::evaluate().
|
inline |
Checks if interface index has been set.
Definition at line 682 of file pkt.h.
References ifindex_, and isc::dhcp::UNSET_IFINDEX.
|
inline |
Returns whether the copying of retrieved options is enabled.
Also see setCopyRetrievedOptions.
Definition at line 506 of file pkt.h.
References copy_retrieved_options_.
|
pure virtual |
Returns packet size in binary format.
Returns size of the packet in on-wire format or size needed to store it in on-wire format.
Pkt4
and Pkt6
class have respective implementations of this method.Implemented in isc::dhcp::Pkt4, and isc::dhcp::Pkt6.
Referenced by Pkt().
|
pure virtual |
Prepares on-wire format of DHCP (either v4 or v6) packet.
Prepares on-wire format of message and all its options. A caller must ensure that options are stored in options_ field prior to calling this method.
Output buffer will be stored in buffer_out_. The buffer_out_ should be cleared before writing to the buffer in the derived classes.
Pkt4
and Pkt6
class have respective implementations of this method.InvalidOperation | if packing fails |
Implemented in isc::dhcp::Pkt4, isc::dhcp::Pkt4o6, and isc::dhcp::Pkt6.
void isc::dhcp::Pkt::repack | ( | ) |
Copies content of input buffer to output buffer.
This is mostly a diagnostic function. It is being used for sending received packet. Received packet is stored in data_, but transmitted data is stored in buffer_out_. If we want to send packet that we just received, a copy between those two buffers is necessary.
Definition at line 158 of file pkt.cc.
References buffer_out_, data_, and isc::util::OutputBuffer::writeData().
|
inline |
Resets interface index to negative value.
Definition at line 668 of file pkt.h.
References ifindex_, and isc::dhcp::UNSET_IFINDEX.
|
inlinevirtual |
Controls whether the option retrieved by the Pkt::getOption should be copied before being returned.
Setting this value to true enables the mechanism of copying options retrieved from the packet to prevent accidental modifications of options that shouldn't be modified. The typical use case for this mechanism is to prevent hook library from modifying instance of an option within the packet that would also affect the value for this option within the Kea configuration structures.
Kea doesn't copy option instances which it stores in the packet. It merely copy pointers into the packets. Thus, any modification to an option would change the value of this option in the Kea configuration. To prevent this, option copying should be enabled prior to passing the pointer to a packet to a hook library.
Not only does this method cause the server to copy an option, but the copied option also replaces the original option within the packet. The option can be then freely modified and the modifications will only affect the instance of this option within the packet but not within the server configuration.
copy | Indicates if the options should be copied when retrieved (if true), or not copied (if false). |
Reimplemented in isc::dhcp::Pkt4o6.
Definition at line 497 of file pkt.h.
References isc::data::copy(), and copy_retrieved_options_.
Referenced by isc::dhcp::Pkt4o6::setCopyRetrievedOptions().
|
inline |
Sets interface name.
Sets interface name over which packet was received or is going to be transmitted.
iface | The interface name |
Definition at line 702 of file pkt.h.
References iface_.
Referenced by isc::dhcp::Pkt4o6::Pkt4o6().
|
inline |
Sets interface index.
ifindex | specifies interface index. |
Definition at line 663 of file pkt.h.
References ifindex_.
Referenced by isc::dhcp::Pkt4o6::Pkt4o6().
|
inline |
Sets local IP address.
local | specifies local address |
Definition at line 612 of file pkt.h.
References local_addr_.
|
inline |
Sets local UDP (and soon TCP) port.
This sets a local port, i.e. destination port for recently received packet or a source port for to be transmitted packet.
local | specifies local port |
Definition at line 629 of file pkt.h.
References local_port_.
void isc::dhcp::Pkt::setPktEvent | ( | const std::string & | label, |
const boost::posix_time::ptime & | timestamp = PktEvent::now() ) |
Updates (or adds) an event in the event stack.
Updates the timestamp of the event described by label if it exists in the stack, otherwise it adds the event to the end of the stack. This is intended to be used for testing.
label | string identifying the event |
timestamp | time at which the event occurred. It is expected to be in UTC/microseconds. |
|
inline |
Sets remote IP address.
remote | specifies remote address |
Definition at line 598 of file pkt.h.
References remote_addr_.
Referenced by isc::dhcp::Pkt4o6::Pkt4o6().
void isc::dhcp::Pkt::setRemoteHWAddr | ( | const HWAddrPtr & | hw_addr | ) |
Sets remote hardware address.
Sets hardware address (MAC) from an existing HWAddr structure. The remote address is a destination address for outgoing packet and source address for incoming packet. When this is an outgoing packet, this address will be used to construct the link layer header.
hw_addr | structure representing HW address. |
BadValue | if addr is null |
Definition at line 171 of file pkt.cc.
References isc_throw, and remote_hwaddr_.
void isc::dhcp::Pkt::setRemoteHWAddr | ( | const uint8_t | htype, |
const uint8_t | hlen, | ||
const std::vector< uint8_t > & | hw_addr ) |
Sets remote hardware address.
Sets the destination hardware (MAC) address for the outgoing packet or source HW address for the incoming packet. When this is an outgoing packet this address will be used to construct the link layer header.
In a typical case, hlen field would be redundant, as it could be extracted from mac_addr.size(). However, the difference is when running on exotic hardware, like Infiniband, that had MAC addresses 20 bytes long. In that case, hlen is set to zero in DHCPv4.
htype | hardware type (will be sent in htype field) |
hlen | hardware length (will be sent in hlen field) |
hw_addr | pointer to hardware address |
Definition at line 165 of file pkt.cc.
References remote_hwaddr_.
|
inline |
Sets remote UDP (and soon TCP) port.
This sets a remote port, i.e. source port for recently received packet or a destination port for to be transmitted packet.
remote | specifies remote port |
Definition at line 649 of file pkt.h.
References remote_port_.
|
inline |
Set socket receive timestamp.
Sets the socket receive timestamp to an arbitrary value.
Definition at line 531 of file pkt.h.
References timestamp_.
|
inline |
Sets transaction-id value.
transid | transaction-id to be set. |
Definition at line 334 of file pkt.h.
References transid_.
Referenced by isc::perfdhcp::PerfPkt4::PerfPkt4(), isc::perfdhcp::PerfPkt6::PerfPkt6(), isc::perfdhcp::PerfPkt4::rawUnpack(), and isc::perfdhcp::PerfPkt6::rawUnpack().
|
pure virtual |
Sets message type (e.g.
1 = SOLICIT).
Pkt4
and Pkt6
class have respective implementations of this method.type | message type to be set |
Implemented in isc::dhcp::Pkt4, and isc::dhcp::Pkt6.
|
pure virtual |
Returns text representation of the packet.
This function is useful mainly for debugging.
Pkt4
and Pkt6
class have respective implementations of this method.Implemented in isc::dhcp::Pkt4, and isc::dhcp::Pkt6.
|
pure virtual |
Parses on-wire form of DHCP (either v4 or v6) packet.
Parses received packet, stored in on-wire format in data_.
Will create a collection of option objects that will be stored in options_ container.
Pkt4
and Pkt6
class have respective implementations of this method.Method will throw exception if packet parsing fails.
tbd |
Implemented in isc::dhcp::Pkt4, and isc::dhcp::Pkt6.
void isc::dhcp::Pkt::updateTimestamp | ( | ) |
Update packet timestamp.
Updates packet timestamp. This method is invoked by interface manager just before sending or just after receiving it.
isc::Unexpected | if timestamp update failed |
Definition at line 154 of file pkt.cc.
References timestamp_.
ClientClasses isc::dhcp::Pkt::additional_classes_ |
Classes to be evaluated during additional class evaluation.
This list allows hook libraries a way to add classes to the list of classes which will be evaluated during evaluate-additional-classes evaluation.
This field is public, so the code outside of Pkt4 or Pkt6 class can iterate over additional classes. Having it public also solves the problem of returned reference lifetime. It is preferred to use addAdditionalClass operate on this field.
Before output option processing these classes will be evaluated and if evaluation status is true added to the classes_ collection.
Definition at line 794 of file pkt.h.
Referenced by addAdditionalClass(), and getAdditionalClasses().
|
protected |
Output buffer (used during message transmission)
Definition at line 962 of file pkt.h.
Referenced by getBuffer(), isc::dhcp::Pkt4::pack(), isc::dhcp::Pkt6::packUDP(), isc::perfdhcp::PerfPkt4::rawPack(), isc::perfdhcp::PerfPkt6::rawPack(), and repack().
ClientClasses isc::dhcp::Pkt::classes_ |
Classes this packet belongs to.
This field is public, so the code outside of Pkt4 or Pkt6 class can iterate over existing classes. Having it public also solves the problem of returned reference lifetime. It is preferred to use inClass and addClass to operate on this field.
Definition at line 780 of file pkt.h.
Referenced by addClass(), addSubClass(), getClasses(), and inClass().
|
protected |
Indicates if a copy of the retrieved option should be returned when Pkt::getOption is called.
Definition at line 968 of file pkt.h.
Referenced by isc::dhcp::Pkt6::getAllRelayOptions(), getOption(), getOptions(), isc::dhcp::Pkt6::getRelayOption(), isc::dhcp::Pkt6::getRelayOptions(), isCopyRetrievedOptions(), and setCopyRetrievedOptions().
OptionBuffer isc::dhcp::Pkt::data_ |
Unparsed data (in received packets).
Definition at line 414 of file pkt.h.
Referenced by Pkt(), isc::perfdhcp::PerfPkt4::rawPack(), isc::perfdhcp::PerfPkt6::rawPack(), isc::perfdhcp::PerfPkt4::rawUnpack(), isc::perfdhcp::PerfPkt6::rawUnpack(), repack(), isc::dhcp::Pkt4::unpack(), isc::dhcp::Pkt6::unpackMsg(), isc::dhcp::Pkt6::unpackRelayMsg(), isc::dhcp::Pkt6::unpackUDP(), isc::perfdhcp::PerfPkt4::writeAt(), isc::perfdhcp::PerfPkt6::writeAt(), isc::perfdhcp::PerfPkt4::writeValueAt(), and isc::perfdhcp::PerfPkt6::writeValueAt().
|
protected |
Name of the network interface the packet was received/to be sent over.
Definition at line 927 of file pkt.h.
Referenced by getIface(), getMACFromIPv6(), isc::dhcp::Pkt6::getMACFromRemoteIdRelayOption(), and setIface().
|
protected |
Interface index.
Each network interface has assigned an unique ifindex. It is a functional equivalent of a name, but sometimes more useful, e.g. when using odd systems that allow spaces in interface names.
Definition at line 934 of file pkt.h.
Referenced by getIndex(), indexSet(), resetIndex(), and setIndex().
|
protected |
Local IP (v4 or v6) address.
Specifies local IPv4 or IPv6 address. It is a destination address for received packet, and a source address if it packet is being transmitted.
Definition at line 940 of file pkt.h.
Referenced by getLocalAddr(), setLocalAddr(), isc::dhcp::Pkt4::toText(), and isc::dhcp::Pkt6::toText().
|
protected |
local TDP or UDP port
Definition at line 949 of file pkt.h.
Referenced by getLocalPort(), setLocalPort(), isc::dhcp::Pkt4::toText(), and isc::dhcp::Pkt6::toText().
isc::dhcp::OptionCollection isc::dhcp::Pkt::options_ |
Collection of options present in this message.
Definition at line 812 of file pkt.h.
Referenced by addOption(), cloneOptions(), delOption(), isc::dhcp::Pkt6::directLen(), getNonCopiedOption(), getNonCopiedOptions(), isc::dhcp::Pkt6::getNonCopiedRelayOption(), getOption(), getOptions(), isc::dhcp::Pkt6::getRelayOption(), isc::dhcp::Pkt4::len(), isc::dhcp::Pkt4::pack(), isc::dhcp::Pkt6::packUDP(), isc::perfdhcp::PerfPkt4::rawPack(), isc::perfdhcp::PerfPkt6::rawPack(), isc::perfdhcp::PerfPkt4::rawUnpack(), isc::perfdhcp::PerfPkt6::rawUnpack(), isc::dhcp::Pkt4::toText(), isc::dhcp::Pkt6::RelayInfo::toText(), isc::dhcp::Pkt6::toText(), isc::dhcp::Pkt4::unpack(), and isc::dhcp::Pkt6::unpackMsg().
|
protected |
Remote IP address.
Specifies local IPv4 or IPv6 address. It is source address for received packet and a destination address for packet being transmitted.
Definition at line 946 of file pkt.h.
Referenced by isc::dhcp::Pkt6::getMACFromSrcLinkLocalAddr(), getRemoteAddr(), setRemoteAddr(), isc::dhcp::Pkt4::toText(), and isc::dhcp::Pkt6::toText().
|
protected |
Definition at line 974 of file pkt.h.
Referenced by getRemoteHWAddr(), setRemoteHWAddr(), and setRemoteHWAddr().
|
protected |
remote TCP or UDP port
Definition at line 952 of file pkt.h.
Referenced by getRemotePort(), setRemotePort(), isc::dhcp::Pkt4::toText(), and isc::dhcp::Pkt6::toText().
SubClassRelationContainer isc::dhcp::Pkt::subclasses_ |
SubClasses this packet belongs to.
This field is public, so the code outside of Pkt4 or Pkt6 class can iterate over existing classes. Having it public also solves the problem of returned reference lifetime. It is preferred to use inClass and addSubClass to operate on this field.
Definition at line 802 of file pkt.h.
Referenced by addClass(), addSubClass(), and getSubClassesRelations().
|
protected |
packet timestamp
Definition at line 971 of file pkt.h.
Referenced by getTimestamp(), setTimestamp(), and updateTimestamp().
|
protected |
Transaction-id (32 bits for v4, 24 bits for v6)
Definition at line 924 of file pkt.h.
Referenced by isc::dhcp::Pkt4::getLabel(), getTransid(), isc::dhcp::Pkt4::pack(), isc::dhcp::Pkt6::packUDP(), setTransid(), isc::dhcp::Pkt4::toText(), isc::dhcp::Pkt6::toText(), isc::dhcp::Pkt4::unpack(), and isc::dhcp::Pkt6::unpackMsg().