26 const IOAddress DEFAULT_ADDRESS(
"0.0.0.0");
32 Pkt4::Pkt4(uint8_t msg_type, uint32_t transid)
33 :
Pkt(transid, DEFAULT_ADDRESS, DEFAULT_ADDRESS, DHCP4_SERVER_PORT, DHCP4_CLIENT_PORT),
34 op_(DHCPTypeToBootpType(msg_type)), hwaddr_(new
HWAddr()), hops_(0), secs_(0), flags_(0),
35 ciaddr_(DEFAULT_ADDRESS), yiaddr_(DEFAULT_ADDRESS), siaddr_(DEFAULT_ADDRESS),
36 giaddr_(DEFAULT_ADDRESS) {
44 :
Pkt(data, len, DEFAULT_ADDRESS, DEFAULT_ADDRESS, DHCP4_SERVER_PORT, DHCP4_CLIENT_PORT),
64 length += it.second->len();
81 size_t hw_len =
hwaddr_->hwaddr_.size();
101 (hw_len < MAX_CHADDR_LEN ?
102 hw_len : MAX_CHADDR_LEN) );
103 hw_len = MAX_CHADDR_LEN - hw_len;
110 vector<uint8_t> zeros(hw_len, 0);
141 << buffer_in.getLength() <<
" received, at least " 145 op_ = buffer_in.readUint8();
146 uint8_t htype = buffer_in.readUint8();
147 uint8_t hlen = buffer_in.readUint8();
148 hops_ = buffer_in.readUint8();
150 secs_ = buffer_in.readUint16();
151 flags_ = buffer_in.readUint16();
162 hw_addr.resize(hlen);
166 if (buffer_in.getLength() == buffer_in.getPosition()) {
173 if (buffer_in.getLength() - buffer_in.getPosition() < 4) {
178 uint32_t magic = buffer_in.readUint32();
179 if (magic != DHCP_OPTIONS_COOKIE) {
183 size_t opts_len = buffer_in.getLength() - buffer_in.getPosition();
184 vector<uint8_t> opts_buffer;
188 buffer_in.readVector(opts_buffer, opts_len);
221 boost::shared_ptr<OptionInt<uint8_t> > type_opt =
224 return (type_opt->getValue());
228 return (generic->getUint8());
246 boost::shared_ptr<OptionInt<uint8_t> > type_opt =
251 opt->setUint8(dhcp_type);
263 static const char* DHCPDISCOVER_NAME =
"DHCPDISCOVER";
264 static const char* DHCPOFFER_NAME =
"DHCPOFFER";
265 static const char* DHCPREQUEST_NAME =
"DHCPREQUEST";
266 static const char* DHCPDECLINE_NAME =
"DHCPDECLINE";
267 static const char* DHCPACK_NAME =
"DHCPACK";
268 static const char* DHCPNAK_NAME =
"DHCPNAK";
269 static const char* DHCPRELEASE_NAME =
"DHCPRELEASE";
270 static const char* DHCPINFORM_NAME =
"DHCPINFORM";
271 static const char* DHCPLEASEQUERY_NAME =
"DHCPLEASEQUERY";
272 static const char* DHCPLEASEUNASSIGNED_NAME =
"DHCPLEASEUNASSIGNED";
273 static const char* DHCPLEASEUNKNOWN_NAME =
"DHCPLEASEUNKNOWN";
274 static const char* DHCPLEASEACTIVE_NAME =
"DHCPLEASEACTIVE";
275 static const char* DHCPBULKLEASEQUERY_NAME =
"DHCPBULKLEASEQUERY";
276 static const char* DHCPLEASEQUERYDONE_NAME =
"DHCPLEASEQUERYDONE";
277 static const char* DHCPLEASEQUERYSTATUS_NAME =
"DHCPLEASEQUERYSTATUS";
278 static const char* DHCPTLS_NAME =
"DHCPTLS";
279 static const char* UNKNOWN_NAME =
"UNKNOWN";
283 return (DHCPDISCOVER_NAME);
286 return (DHCPOFFER_NAME);
289 return (DHCPREQUEST_NAME);
292 return (DHCPDECLINE_NAME);
295 return (DHCPACK_NAME);
298 return (DHCPNAK_NAME);
301 return (DHCPRELEASE_NAME);
304 return (DHCPINFORM_NAME);
307 return (DHCPLEASEQUERY_NAME);
310 return (DHCPLEASEUNASSIGNED_NAME);
313 return (DHCPLEASEUNKNOWN_NAME);
316 return (DHCPLEASEACTIVE_NAME);
319 return (DHCPBULKLEASEQUERY_NAME);
322 return (DHCPLEASEQUERYDONE_NAME);
325 return (DHCPLEASEQUERYSTATUS_NAME);
328 return (DHCPTLS_NAME);
333 return (UNKNOWN_NAME);
357 suffix =
" (malformed client-id)";
361 std::ostringstream label;
368 label <<
" (malformed hw address)";
372 return (label.str());
377 const uint32_t transid) {
383 label <<
", tid=0x" << hex << transid << dec;
391 label <<
"[" << (hwaddr ? hwaddr->toText() :
"no hwaddr info")
392 <<
"], cid=[" << (client_id ? client_id->toText() :
"no info")
408 output <<
getName(msg_type) <<
" (" <<
static_cast<int>(msg_type) <<
")";
411 output <<
"(missing)";
414 output <<
", transid=0x" << hex <<
transid_ << dec;
417 output <<
"," << std::endl <<
"options:";
420 output << std::endl << opt.second->toText(2);
422 output <<
"(unknown)" << std::endl;
427 output <<
", message contains no options";
430 return (output.str());
435 const std::vector<uint8_t>& mac_addr) {
436 setHWAddrMember(htype, hlen, mac_addr,
hwaddr_);
449 Pkt4::setHWAddrMember(
const uint8_t htype,
const uint8_t hlen,
450 const std::vector<uint8_t>& mac_addr,
458 }
else if (mac_addr.empty() && (hlen > 0) ) {
465 hw_addr.reset(
new HWAddr(mac_addr, htype));
470 const std::vector<uint8_t>& mac_addr) {
489 }
else if (sname == NULL) {
505 <<
") too long, Max " <<
MAX_FILE_LEN <<
" supported.");
507 }
else if (file == NULL) {
543 << static_cast<int>(dhcpType) );
569 <<
" already present in this message.");
uint8_t getHlen() const
Returns hlen field.
static const size_t MAX_SNAME_LEN
length of the SNAME field in DHCPv4 message
Pkt4(uint8_t msg_type, uint32_t transid)
Constructor, used in replying to a message.
uint8_t hops_
Number of relay agents traversed.
isc::asiolink::IOAddress local_addr_
Local IP (v4 or v6) address.
void setValue(T value)
Set option value.
uint8_t sname_[MAX_SNAME_LEN]
sname field (64 bytes)
OptionBuffer data_
Unparsed data (in received packets).
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 getHtype() const
Returns htype field.
Message Type option missing.
uint8_t DHCPTypeToBootpType(uint8_t dhcpType)
converts DHCP message type to BOOTP op type
isc::asiolink::IOAddress giaddr_
giaddr field (32 bits): Gateway IP address
A generic exception that is thrown if a parameter given to a method or function is considered invalid...
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
static const size_t MAX_CHADDR_LEN
length of the CHADDR field in DHCPv4 message
uint32_t transid_
Transaction-id (32 bits for v4, 24 bits for v6)
static const size_t MAX_FILE_LEN
length of the FILE field in DHCPv4 message
static const size_t DHCPV4_PKT_HDR_LEN
specifies DHCPv4 packet header length (fixed part)
virtual void unpack()
Parses on-wire form of DHCPv4 packet.
Base class for classes representing DHCP messages.
boost::shared_ptr< Option > OptionPtr
virtual void addOption(const OptionPtr &opt)
Adds an option to this packet.
Forward declaration to OptionInt.
isc::asiolink::IOAddress siaddr_
siaddr field (32 bits): next server IP address in boot process(e.g.TFTP)
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
const char * getName() const
Returns name of the DHCP message.
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)
not specified or undefined
static void packOptions4(isc::util::OutputBuffer &buf, const isc::dhcp::OptionCollection &options, bool top=false)
Stores DHCPv4 options in a buffer.
void writeData(const void *data, size_t len)
Copy an arbitrary length of data into the buffer.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
uint8_t op_
message operation code
ElementPtr copy(ConstElementPtr from, int level)
Copy the data up to a nesting level.
uint32_t toUint32() const
Converts IPv4 address to uint32_t.
bool isV4Bcast() const
Convenience function to check if it is an IPv4 broadcast address.
uint8_t getType() const
Returns DHCP message type (e.g.
A generic exception that is thrown when an unexpected error condition occurs.
void setSname(const uint8_t *sname, size_t sname_len)
Sets sname field.
bool isV4Zero() const
Convenience function to check if it is an IPv4 zero address.
void clear()
Clear buffer content.
isc::asiolink::IOAddress ciaddr_
ciaddr field (32 bits): Client's IP address
boost::shared_ptr< ClientId > ClientIdPtr
Shared pointer to a Client ID.
void writeUint32(uint32_t data)
Write an unsigned 32-bit integer in host byte order into the buffer in network byte order...
uint16_t remote_port_
remote TCP or UDP port
std::list< uint16_t > deferred_options_
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-lfc.
uint16_t local_port_
local TDP or UDP port
void setHWAddr(uint8_t htype, uint8_t hlen, const std::vector< uint8_t > &mac_addr)
Sets hardware address.
bool isRelayed() const
Checks if a DHCPv4 message has been relayed.
void setType(uint8_t type)
Sets DHCP message type (e.g.
isc::asiolink::IOAddress remote_addr_
Remote IP address.
std::string getLabel() const
Returns text representation of the primary packet identifiers.
OptionPtr getNonCopiedOption(const uint16_t type) const
Returns the first option of specified type without copying.
Holds Client identifier or client IPv4 address.
void writeUint8(uint8_t data)
Write an unsigned 8-bit integer into the buffer.
A generic exception that is thrown if a function is called in a prohibited way.
#define DHCP4_OPTION_SPACE
global std option spaces
Hardware type that represents information from DHCPv4 packet.
void writeUint16(uint16_t data)
Write an unsigned 16-bit integer in host byte order into the buffer in network byte order...
std::string toText() const
Returns text representation of the packet.
uint8_t file_[MAX_FILE_LEN]
file field (128 bytes)
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
virtual void addOption(const OptionPtr &opt)
Add an option.
isc::util::OutputBuffer buffer_out_
Output buffer (used during message transmission)
void setFile(const uint8_t *file, size_t file_len)
Sets file field.
The IOAddress class represents an IP addresses (version agnostic)
uint16_t secs_
elapsed (number of seconds since beginning of transmission)
virtual void pack()
Prepares on-wire format of DHCPv4 packet.
HWAddrPtr local_hwaddr_
local HW address (dst if receiving packet, src if sending packet)
isc::dhcp::OptionCollection options_
Collection of options present in this message.
void setLocalHWAddr(const uint8_t htype, const uint8_t hlen, const std::vector< uint8_t > &mac_addr)
Sets local HW address.
size_t len()
Returns the size of the required buffer to build the packet.
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.
isc::asiolink::IOAddress yiaddr_
yiaddr field (32 bits): Client's IP address ("your"), set by server