 |
Kea
1.5.0
|
Go to the documentation of this file.
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,
35 op_(DHCPTypeToBootpType(msg_type)),
40 ciaddr_(DEFAULT_ADDRESS),
41 yiaddr_(DEFAULT_ADDRESS),
42 siaddr_(DEFAULT_ADDRESS),
43 giaddr_(DEFAULT_ADDRESS)
52 :
Pkt(data, len, DEFAULT_ADDRESS, DEFAULT_ADDRESS, DHCP4_SERVER_PORT,
59 ciaddr_(DEFAULT_ADDRESS),
60 yiaddr_(DEFAULT_ADDRESS),
61 siaddr_(DEFAULT_ADDRESS),
62 giaddr_(DEFAULT_ADDRESS)
79 for (OptionCollection::const_iterator it =
options_.begin();
82 length += (*it).second->len();
99 size_t hw_len =
hwaddr_->hwaddr_.size();
128 vector<uint8_t> zeros(hw_len, 0);
157 << buffer_in.
getLength() <<
" received, at least "
178 hw_addr.resize(hlen);
195 if (magic != DHCP_OPTIONS_COOKIE) {
200 vector<uint8_t> opts_buffer;
237 boost::shared_ptr<OptionInt<uint8_t> > type_opt =
238 boost::dynamic_pointer_cast<OptionInt<uint8_t> >(
generic);
240 return (type_opt->getValue());
244 return (generic->getUint8());
262 boost::shared_ptr<OptionInt<uint8_t> > type_opt =
263 boost::dynamic_pointer_cast<OptionInt<uint8_t> >(opt);
265 type_opt->setValue(dhcp_type);
267 opt->setUint8(dhcp_type);
279 static const char* DHCPDISCOVER_NAME =
"DHCPDISCOVER";
280 static const char* DHCPOFFER_NAME =
"DHCPOFFER";
281 static const char* DHCPREQUEST_NAME =
"DHCPREQUEST";
282 static const char* DHCPDECLINE_NAME =
"DHCPDECLINE";
283 static const char* DHCPACK_NAME =
"DHCPACK";
284 static const char* DHCPNAK_NAME =
"DHCPNAK";
285 static const char* DHCPRELEASE_NAME =
"DHCPRELEASE";
286 static const char* DHCPINFORM_NAME =
"DHCPINFORM";
287 static const char* UNKNOWN_NAME =
"UNKNOWN";
291 return (DHCPDISCOVER_NAME);
294 return (DHCPOFFER_NAME);
297 return (DHCPREQUEST_NAME);
300 return (DHCPDECLINE_NAME);
303 return (DHCPACK_NAME);
306 return (DHCPNAK_NAME);
309 return (DHCPRELEASE_NAME);
312 return (DHCPINFORM_NAME);
317 return (UNKNOWN_NAME);
341 suffix =
" (malformed client-id)";
345 std::ostringstream label;
352 label <<
" (malformed hw address)";
356 return (label.str());
361 const uint32_t transid) {
367 label <<
", tid=0x" << hex << transid << dec;
375 label <<
"[" << (hwaddr ? hwaddr->toText() :
"no hwaddr info")
376 <<
"], cid=[" << (client_id ? client_id->toText() :
"no info")
392 output <<
getName(msg_type) <<
" (" <<
static_cast<int>(msg_type) <<
")";
395 output <<
"(missing)";
398 output <<
", transid=0x" << hex <<
transid_ << dec;
401 output <<
"," << std::endl <<
"options:";
402 for (isc::dhcp::OptionCollection::const_iterator opt =
options_.begin();
405 output << std::endl << opt->second->toText(2);
407 output <<
"(unknown)" << std::endl;
412 output <<
", message contains no options";
415 return (output.str());
420 const std::vector<uint8_t>& mac_addr) {
421 setHWAddrMember(htype, hlen, mac_addr,
hwaddr_);
434 Pkt4::setHWAddrMember(
const uint8_t htype,
const uint8_t hlen,
435 const std::vector<uint8_t>& mac_addr,
443 }
else if (mac_addr.empty() && (hlen > 0) ) {
450 hw_addr.reset(
new HWAddr(mac_addr, htype));
455 const std::vector<uint8_t>& mac_addr) {
474 }
else if (sname == NULL) {
490 <<
") too long, Max " <<
MAX_FILE_LEN <<
" supported.");
492 }
else if (file == NULL) {
528 <<
static_cast<int>(dhcpType) );
554 <<
" already present in this message.");
isc::asiolink::IOAddress local_addr_
Local IP (v4 or v6) address.
std::string getLabel() const
Returns text representation of the primary packet identifiers.
void setFile(const uint8_t *file, size_t file_len)
Sets file field.
ElementPtr copy(ConstElementPtr from, int level)
Copy the data up to a nesting level.
A generic exception that is thrown when an unexpected error condition occurs.
virtual void addOption(const OptionPtr &opt)
Adds an option to this packet.
HWAddrPtr local_hwaddr_
local HW address (dst if receiving packet, src if sending packet)
virtual void unpack()
Parses on-wire form of DHCPv4 packet.
The IOAddress class represents an IP addresses (version agnostic)
void setType(uint8_t type)
Sets DHCP message type (e.g.
static std::string makeLabel(const HWAddrPtr &hwaddr, const ClientIdPtr &client_id, const uint32_t transid)
Returns text representation of the given packet identifiers.
isc::dhcp::OptionCollection options_
Collection of options present in this message.
void writeUint16(uint16_t data)
Write an unsigned 16-bit integer in host byte order into the buffer in network byte order.
Hardware type that represents information from DHCPv4 packet.
@ HTYPE_UNDEFINED
not specified or undefined
bool isRelayed() const
Checks if a DHCPv4 message has been relayed.
bool isV4Zero() const
Convenience function to check if it is an IPv4 zero address.
isc::asiolink::IOAddress siaddr_
siaddr field (32 bits): next server IP address in boot process(e.g.TFTP)
uint8_t file_[MAX_FILE_LEN]
file field (128 bytes)
uint8_t hops_
Number of relay agents traversed.
virtual void addOption(const OptionPtr &opt)
Add an option.
OptionPtr getNonCopiedOption(const uint16_t type) const
Returns the first option of specified type without copying.
std::string toText() const
Returns text representation of the packet.
virtual void pack()
Prepares on-wire format of DHCPv4 packet.
This is a base class for exceptions thrown from the DNS library module.
bool isV4Bcast() const
Convenience function to check if it is an IPv4 broadcast address.
uint8_t getHtype() const
Returns htype field.
Defines the logger used by the top-level component of kea-dhcp-ddns.
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
isc::asiolink::IOAddress giaddr_
giaddr field (32 bits): Gateway IP address
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 is considered invalid in that con...
void writeUint8(uint8_t data)
Write an unsigned 8-bit integer into the buffer.
Holds Client identifier or client IPv4 address.
void clear()
Clear buffer content.
isc::asiolink::IOAddress ciaddr_
ciaddr field (32 bits): Client's IP address
static const size_t MAX_SNAME_LEN
length of the SNAME field in DHCPv4 message
Base class for classes representing DHCP messages.
#define DHCP4_OPTION_SPACE
OptionBuffer data_
Unparsed data (in received packets).
isc::util::OutputBuffer buffer_out_
Output buffer (used during message transmission)
uint8_t getType() const
Returns DHCP message type (e.g.
isc::asiolink::IOAddress remote_addr_
Remote IP address.
static const size_t MAX_CHADDR_LEN
length of the CHADDR field in DHCPv4 message
const char * getName() const
Returns name of the DHCP message.
void setSname(const uint8_t *sname, size_t sname_len)
Sets sname field.
isc::asiolink::IOAddress yiaddr_
yiaddr field (32 bits): Client's IP address ("your"), set by server
Forward declaration to OptionInt.
static const size_t MAX_FILE_LEN
length of the FILE field in DHCPv4 message
uint32_t toUint32() const
Converts IPv4 address to uint32_t.
boost::shared_ptr< ClientId > ClientIdPtr
Shared pointer to a Client ID.
std::list< uint16_t > deferred_options_
uint8_t getHlen() const
Returns hlen field.
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
size_t len()
Returns the size of the required buffer to build the packet.
uint16_t local_port_
local TDP or UDP port
boost::shared_ptr< Option > OptionPtr
Pkt4(uint8_t msg_type, uint32_t transid)
Constructor, used in replying to a message.
void setLocalHWAddr(const uint8_t htype, const uint8_t hlen, const std::vector< uint8_t > &mac_addr)
Sets local HW address.
void writeUint32(uint32_t data)
Write an unsigned 32-bit integer in host byte order into the buffer in network byte order.
HWAddrPtr hwaddr_
link-layer address and hardware information represents 3 fields: htype (hardware type,...
static size_t unpackOptions4(const OptionBuffer &buf, const std::string &option_space, isc::dhcp::OptionCollection &options, std::list< uint16_t > &deferred)
Parses provided buffer as DHCPv4 options and creates Option objects.
void writeData(const void *data, size_t len)
Copy an arbitrary length of data into the buffer.
@ DHO_DHCP_CLIENT_IDENTIFIER
uint32_t transid_
Transaction-id (32 bits for v4, 24 bits for v6)
uint8_t op_
message operation code
void setHWAddr(uint8_t htype, uint8_t hlen, const std::vector< uint8_t > &mac_addr)
Sets hardware address.
@ DHCP_NOTYPE
Message Type option missing.
uint8_t DHCPTypeToBootpType(uint8_t dhcpType)
converts DHCP message type to BOOTP op type
uint16_t remote_port_
remote TCP or UDP port
static const size_t DHCPV4_PKT_HDR_LEN
specifies DHCPv4 packet header length (fixed part)
uint8_t sname_[MAX_SNAME_LEN]
sname field (64 bytes)
static void packOptions4(isc::util::OutputBuffer &buf, const isc::dhcp::OptionCollection &options)
Stores DHCPv4 options in a buffer.
uint16_t secs_
elapsed (number of seconds since beginning of transmission)