28const IOAddress DEFAULT_ADDRESS(
"0.0.0.0");
35 :
Pkt(transid, DEFAULT_ADDRESS, DEFAULT_ADDRESS, DHCP4_SERVER_PORT, DHCP4_CLIENT_PORT),
46 :
Pkt(
data,
len, DEFAULT_ADDRESS, DEFAULT_ADDRESS, DHCP4_SERVER_PORT, DHCP4_CLIENT_PORT),
66 length += it.second->len();
88 size_t hw_len =
hwaddr_->hwaddr_.size();
116 vector<uint8_t> zeros(hw_len, 0);
156 <<
data_.size() <<
" received, at least "
180 hw_addr.resize(hlen);
197 if (magic != DHCP_OPTIONS_COOKIE) {
202 vector<uint8_t> opts_buffer;
243 boost::shared_ptr<OptionInt<uint8_t> > type_opt =
244 boost::dynamic_pointer_cast<OptionInt<uint8_t> >(
generic);
246 return (type_opt->getValue());
250 return (generic->getUint8());
268 boost::shared_ptr<OptionInt<uint8_t> > type_opt =
269 boost::dynamic_pointer_cast<OptionInt<uint8_t> >(opt);
271 type_opt->setValue(dhcp_type);
273 opt->setUint8(dhcp_type);
285 static const char* DHCPDISCOVER_NAME =
"DHCPDISCOVER";
286 static const char* DHCPOFFER_NAME =
"DHCPOFFER";
287 static const char* DHCPREQUEST_NAME =
"DHCPREQUEST";
288 static const char* DHCPDECLINE_NAME =
"DHCPDECLINE";
289 static const char* DHCPACK_NAME =
"DHCPACK";
290 static const char* DHCPNAK_NAME =
"DHCPNAK";
291 static const char* DHCPRELEASE_NAME =
"DHCPRELEASE";
292 static const char* DHCPINFORM_NAME =
"DHCPINFORM";
293 static const char* DHCPLEASEQUERY_NAME =
"DHCPLEASEQUERY";
294 static const char* DHCPLEASEUNASSIGNED_NAME =
"DHCPLEASEUNASSIGNED";
295 static const char* DHCPLEASEUNKNOWN_NAME =
"DHCPLEASEUNKNOWN";
296 static const char* DHCPLEASEACTIVE_NAME =
"DHCPLEASEACTIVE";
297 static const char* DHCPBULKLEASEQUERY_NAME =
"DHCPBULKLEASEQUERY";
298 static const char* DHCPLEASEQUERYDONE_NAME =
"DHCPLEASEQUERYDONE";
299 static const char* DHCPLEASEQUERYSTATUS_NAME =
"DHCPLEASEQUERYSTATUS";
300 static const char* DHCPTLS_NAME =
"DHCPTLS";
301 static const char* UNKNOWN_NAME =
"UNKNOWN";
305 return (DHCPDISCOVER_NAME);
308 return (DHCPOFFER_NAME);
311 return (DHCPREQUEST_NAME);
314 return (DHCPDECLINE_NAME);
317 return (DHCPACK_NAME);
320 return (DHCPNAK_NAME);
323 return (DHCPRELEASE_NAME);
326 return (DHCPINFORM_NAME);
329 return (DHCPLEASEQUERY_NAME);
332 return (DHCPLEASEUNASSIGNED_NAME);
335 return (DHCPLEASEUNKNOWN_NAME);
338 return (DHCPLEASEACTIVE_NAME);
341 return (DHCPBULKLEASEQUERY_NAME);
344 return (DHCPLEASEQUERYDONE_NAME);
347 return (DHCPLEASEQUERYSTATUS_NAME);
350 return (DHCPTLS_NAME);
355 return (UNKNOWN_NAME);
379 suffix =
" (malformed client-id)";
383 std::ostringstream label;
390 label <<
" (malformed hw address)";
395 return (label.str());
400 const uint32_t transid) {
406 label <<
", tid=0x" << hex << transid << dec;
408 return (label.str());
414 label <<
"[" << (hwaddr ? hwaddr->toText() :
"no hwaddr info")
415 <<
"], cid=[" << (client_id ? client_id->toText() :
"no info")
418 return (label.str());
434 tmp <<
getName(msg_type) <<
" (" <<
static_cast<int>(msg_type) <<
")";
440 tmp <<
", trans_id=0x" << hex <<
transid_ << dec;
443 tmp <<
", secs=" <<
secs_;
444 tmp <<
", flags=0x" << hex <<
flags_;
462 if (!sname_dump.empty()) {
463 tmp <<
", sname=[" << sname_dump <<
"]";
467 if (!file_dump.empty()) {
468 tmp <<
", file=[" << file_dump <<
"]";
473 tmp <<
"," << endl <<
"options:";
476 tmp << endl << opt.second->toText(2);
478 tmp <<
"(unknown)" << endl;
483 tmp <<
"," << endl <<
"message contains no options";
491 const std::vector<uint8_t>& mac_addr) {
492 setHWAddrMember(htype, hlen, mac_addr,
hwaddr_);
505Pkt4::setHWAddrMember(
const uint8_t htype,
const uint8_t hlen,
506 const std::vector<uint8_t>& mac_addr,
514 }
else if (mac_addr.empty() && (hlen > 0) ) {
521 hw_addr.reset(
new HWAddr(mac_addr, htype));
526 const std::vector<uint8_t>& mac_addr) {
545 }
else if (sname == NULL) {
549 std::copy(sname, (sname + snameLen),
sname_);
561 <<
") too long, Max " <<
MAX_FILE_LEN <<
" supported.");
563 }
else if (
file == NULL) {
599 <<
static_cast<int>(dhcpType) );
625 <<
" already present in this message.");
638 std::ostringstream label;
640 hwaddr_ ? label <<
hwaddr_->toText(
false) : label <<
"(undefined)";
641 return (label.str());
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown if a function is called in a prohibited way.
A generic exception that is thrown if a parameter given to a method or function is considered invalid...
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
A generic exception that is thrown when an unexpected error condition occurs.
The IOAddress class represents an IP addresses (version agnostic).
bool isV4Zero() const
Convenience function to check if it is an IPv4 zero address.
std::string toText() const
Convert the address to a string.
uint32_t toUint32() const
Converts IPv4 address to uint32_t.
IOAddress(const std::string &address_str)
Constructor from string.
bool isV4Bcast() const
Convenience function to check if it is an IPv4 broadcast address.
ClientId(const std::vector< uint8_t > &data)
Constructor based on vector<uint8_t>.
static size_t unpackOptions4(const OptionBuffer &buf, const std::string &option_space, isc::dhcp::OptionCollection &options, std::list< uint16_t > &deferred, bool flexible_pad_end=false)
Parses provided buffer as DHCPv4 options and creates Option objects.
static void extendVendorOptions4(isc::dhcp::OptionCollection &options)
Extend vendor options from fused options in multiple OptionVendor or OptionVendorClass options and ad...
static void packOptions4(isc::util::OutputBuffer &buf, const isc::dhcp::OptionCollection &options, bool top=false, bool check=true)
Stores DHCPv4 options in a buffer.
static bool splitOptions4(isc::dhcp::OptionCollection &options, ScopedOptionsCopyContainer &scopedOptions, uint32_t used=0)
Split long options in multiple options with the same option code (RFC3396).
Forward declaration to OptionInt.
virtual void addOption(const OptionPtr &opt)
Add an option.
virtual void unpack()
Parses on-wire form of DHCPv4 packet.
std::list< uint16_t > deferred_options_
List of deferred option codes.
HWAddrPtr hwaddr_
link-layer address and hardware information represents 3 fields: htype (hardware type,...
const char * getName() const
Returns name of the DHCP message.
HWAddrPtr local_hwaddr_
local HW address (dst if receiving packet, src if sending packet)
static const size_t MAX_CHADDR_LEN
length of the CHADDR field in DHCPv4 message
void setLocalHWAddr(const uint8_t htype, const uint8_t hlen, const std::vector< uint8_t > &mac_addr)
Sets local HW address.
std::string getHWAddrLabel() const
Returns text representation of the hardware address.
uint8_t DHCPTypeToBootpType(uint8_t dhcpType)
converts DHCP message type to BOOTP op type
std::string getLabel() const
Returns text representation of the primary packet identifiers.
virtual void pack()
Prepares on-wire format of DHCPv4 packet.
isc::asiolink::IOAddress giaddr_
giaddr field (32 bits): Gateway IP address
uint8_t file_[MAX_FILE_LEN]
file field (128 bytes)
uint8_t op_
message operation code
uint8_t hops_
Number of relay agents traversed.
const OptionBuffer getFile() const
Returns file field.
const OptionBuffer getSname() const
Returns sname field.
void setSname(const uint8_t *sname, size_t sname_len)
Sets sname field.
Pkt4(uint8_t msg_type, uint32_t transid)
Constructor, used in replying to a message.
uint8_t getHlen() const
Returns hlen field.
static const size_t DHCPV4_PKT_HDR_LEN
specifies DHCPv4 packet header length (fixed part)
bool isRelayed() const
Checks if a DHCPv4 message has been relayed.
void setFile(const uint8_t *file, size_t file_len)
Sets file field.
static const size_t MAX_SNAME_LEN
length of the SNAME field in DHCPv4 message
static std::string makeLabel(const HWAddrPtr &hwaddr, const ClientIdPtr &client_id, const uint32_t transid)
Returns text representation of the given packet identifiers.
uint8_t getType() const
Returns DHCP message type (e.g.
void setType(uint8_t type)
Sets DHCP message type (e.g.
isc::asiolink::IOAddress siaddr_
siaddr field (32 bits): next server IP address in boot process(e.g.TFTP)
size_t len()
Returns the size of the required buffer to build the packet.
uint16_t secs_
elapsed (number of seconds since beginning of transmission)
isc::asiolink::IOAddress ciaddr_
ciaddr field (32 bits): Client's IP address
std::string toText(bool verbose=false) const
Returns text representation of the packet.
isc::asiolink::IOAddress yiaddr_
yiaddr field (32 bits): Client's IP address ("your"), set by server
uint8_t sname_[MAX_SNAME_LEN]
sname field (64 bytes)
void setHWAddr(uint8_t htype, uint8_t hlen, const std::vector< uint8_t > &mac_addr)
Sets hardware address.
uint8_t getHtype() const
Returns htype field.
static const char * getName(const uint8_t type)
Returns name of the DHCP message for a given type number.
static const size_t MAX_FILE_LEN
length of the FILE field in DHCPv4 message
isc::asiolink::IOAddress remote_addr_
Remote IP address.
uint16_t local_port_
local TDP or UDP port
uint32_t transid_
Transaction-id (32 bits for v4, 24 bits for v6).
isc::asiolink::IOAddress local_addr_
Local IP (v4 or v6) address.
OptionBuffer data_
Unparsed data (in received packets).
uint16_t remote_port_
remote TCP or UDP port
isc::dhcp::OptionCollection options_
Collection of options present in this message.
isc::util::OutputBuffer buffer_out_
Output buffer (used during message transmission).
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.
OptionPtr getNonCopiedOption(const uint16_t type) const
Returns the first option of specified type without copying.
virtual void addOption(const OptionPtr &opt)
Adds an option to this packet.
void writeUint8(uint8_t data)
Write an unsigned 8-bit integer into the buffer.
void writeUint16(uint16_t data)
Write an unsigned 16-bit integer in host byte order into the buffer in network byte order.
void writeData(const void *data, size_t len)
Copy an arbitrary length of data into the buffer.
void writeUint32(uint32_t data)
Write an unsigned 32-bit integer in host byte order into the buffer in network byte order.
void clear()
Clear buffer content.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
ScopedPktOptionsCopy< Pkt4 > ScopedPkt4OptionsCopy
A pointer to a ScopedPktOptionsCopy object instantiated using Pkt4.
@ DHO_DHCP_CLIENT_IDENTIFIER
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
boost::shared_ptr< ClientId > ClientIdPtr
Shared pointer to a Client ID.
@ DHCP_NOTYPE
Message Type option missing.
@ HTYPE_UNDEFINED
not specified or undefined
boost::shared_ptr< Option > OptionPtr
std::string printOrDump(const std::vector< uint8_t > &data, size_t max_dump)
Outputs the contents of a vector as either a string printable characters or a hex dump.
Defines the logger used by the top-level component of kea-lfc.
#define DHCP4_OPTION_SPACE
global std option spaces
Hardware type that represents information from DHCPv4 packet.
HWAddr()
default constructor
ScopedOptionsCopyContainer scoped_options_
The container.