Kea  1.9.9-git
pkt4.cc
Go to the documentation of this file.
1 // Copyright (C) 2011-2020 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #include <config.h>
8 #include <asiolink/io_address.h>
9 #include <dhcp/dhcp4.h>
10 #include <dhcp/libdhcp++.h>
11 #include <dhcp/option_int.h>
12 #include <dhcp/pkt4.h>
13 #include <exceptions/exceptions.h>
14 
15 #include <algorithm>
16 #include <iostream>
17 #include <sstream>
18 
19 using namespace std;
20 using namespace isc::dhcp;
21 using namespace isc::asiolink;
22 
23 namespace {
24 
26 const IOAddress DEFAULT_ADDRESS("0.0.0.0");
27 }
28 
29 namespace isc {
30 namespace dhcp {
31 
32 Pkt4::Pkt4(uint8_t msg_type, uint32_t transid)
33  :Pkt(transid, DEFAULT_ADDRESS, DEFAULT_ADDRESS, DHCP4_SERVER_PORT,
34  DHCP4_CLIENT_PORT),
35  op_(DHCPTypeToBootpType(msg_type)),
36  hwaddr_(new HWAddr()),
37  hops_(0),
38  secs_(0),
39  flags_(0),
40  ciaddr_(DEFAULT_ADDRESS),
41  yiaddr_(DEFAULT_ADDRESS),
42  siaddr_(DEFAULT_ADDRESS),
43  giaddr_(DEFAULT_ADDRESS)
44 {
45  memset(sname_, 0, MAX_SNAME_LEN);
46  memset(file_, 0, MAX_FILE_LEN);
47 
48  setType(msg_type);
49 }
50 
51 Pkt4::Pkt4(const uint8_t* data, size_t len)
52  :Pkt(data, len, DEFAULT_ADDRESS, DEFAULT_ADDRESS, DHCP4_SERVER_PORT,
53  DHCP4_CLIENT_PORT),
54  op_(BOOTREQUEST),
55  hwaddr_(new HWAddr()),
56  hops_(0),
57  secs_(0),
58  flags_(0),
59  ciaddr_(DEFAULT_ADDRESS),
60  yiaddr_(DEFAULT_ADDRESS),
61  siaddr_(DEFAULT_ADDRESS),
62  giaddr_(DEFAULT_ADDRESS)
63 {
64 
65  if (len < DHCPV4_PKT_HDR_LEN) {
66  isc_throw(OutOfRange, "Truncated DHCPv4 packet (len=" << len
67  << ") received, at least " << DHCPV4_PKT_HDR_LEN
68  << " is expected.");
69  }
70  memset(sname_, 0, MAX_SNAME_LEN);
71  memset(file_, 0, MAX_FILE_LEN);
72 }
73 
74 size_t
76  size_t length = DHCPV4_PKT_HDR_LEN; // DHCPv4 header
77 
78  // ... and sum of lengths of all options
79  for (OptionCollection::const_iterator it = options_.begin();
80  it != options_.end();
81  ++it) {
82  length += (*it).second->len();
83  }
84 
85  return (length);
86 }
87 
88 void
90  if (!hwaddr_) {
91  isc_throw(InvalidOperation, "Can't build Pkt4 packet. HWAddr not set.");
92  }
93 
94  // Clear the output buffer to make sure that consecutive calls to pack()
95  // will not result in concatenation of multiple packet copies.
97 
98  try {
99  size_t hw_len = hwaddr_->hwaddr_.size();
100 
102  buffer_out_.writeUint8(hwaddr_->htype_);
104  hw_len : MAX_CHADDR_LEN);
113 
114 
115  if ((hw_len > 0) && (hw_len <= MAX_CHADDR_LEN)) {
116  // write up to 16 bytes of the hardware address (CHADDR field is 16
117  // bytes long in DHCPv4 message).
118  buffer_out_.writeData(&hwaddr_->hwaddr_[0],
119  (hw_len < MAX_CHADDR_LEN ?
120  hw_len : MAX_CHADDR_LEN) );
121  hw_len = MAX_CHADDR_LEN - hw_len;
122  } else {
123  hw_len = MAX_CHADDR_LEN;
124  }
125 
126  // write (len) bytes of padding
127  if (hw_len > 0) {
128  vector<uint8_t> zeros(hw_len, 0);
129  buffer_out_.writeData(&zeros[0], hw_len);
130  }
131 
134 
135  // write DHCP magic cookie
136  buffer_out_.writeUint32(DHCP_OPTIONS_COOKIE);
137 
138  // Call packOptions4() with parameter,"top", true. This invokes
139  // logic to emit the message type option first.
141 
142  // add END option that indicates end of options
143  // (End option is very simple, just a 255 octet)
145  } catch(const Exception& e) {
146  // An exception is thrown and message will be written to Logger
148  }
149 }
150 
151 void
153 
154  // input buffer (used during message reception)
155  isc::util::InputBuffer buffer_in(&data_[0], data_.size());
156 
157  if (buffer_in.getLength() < DHCPV4_PKT_HDR_LEN) {
158  isc_throw(OutOfRange, "Received truncated DHCPv4 packet (len="
159  << buffer_in.getLength() << " received, at least "
160  << DHCPV4_PKT_HDR_LEN << "is expected");
161  }
162 
163  op_ = buffer_in.readUint8();
164  uint8_t htype = buffer_in.readUint8();
165  uint8_t hlen = buffer_in.readUint8();
166  hops_ = buffer_in.readUint8();
167  transid_ = buffer_in.readUint32();
168  secs_ = buffer_in.readUint16();
169  flags_ = buffer_in.readUint16();
170  ciaddr_ = IOAddress(buffer_in.readUint32());
171  yiaddr_ = IOAddress(buffer_in.readUint32());
172  siaddr_ = IOAddress(buffer_in.readUint32());
173  giaddr_ = IOAddress(buffer_in.readUint32());
174 
175  vector<uint8_t> hw_addr(MAX_CHADDR_LEN, 0);
176  buffer_in.readVector(hw_addr, MAX_CHADDR_LEN);
177  buffer_in.readData(sname_, MAX_SNAME_LEN);
178  buffer_in.readData(file_, MAX_FILE_LEN);
179 
180  hw_addr.resize(hlen);
181 
182  hwaddr_ = HWAddrPtr(new HWAddr(hw_addr, htype));
183 
184  if (buffer_in.getLength() == buffer_in.getPosition()) {
185  // this is *NOT* DHCP packet. It does not have any DHCPv4 options. In
186  // particular, it does not have magic cookie, a 4 byte sequence that
187  // differentiates between DHCP and RFC 951 BOOTP packets.
188  isc_throw(InvalidOperation, "Received BOOTP packet without vendor information extensions.");
189  }
190 
191  if (buffer_in.getLength() - buffer_in.getPosition() < 4) {
192  // there is not enough data to hold magic DHCP cookie
193  isc_throw(Unexpected, "Truncated or no DHCP packet.");
194  }
195 
196  uint32_t magic = buffer_in.readUint32();
197  if (magic != DHCP_OPTIONS_COOKIE) {
198  isc_throw(Unexpected, "Invalid or missing DHCP magic cookie");
199  }
200 
201  size_t opts_len = buffer_in.getLength() - buffer_in.getPosition();
202  vector<uint8_t> opts_buffer;
203 
204  // Use readVector because a function which parses option requires
205  // a vector as an input.
206  buffer_in.readVector(opts_buffer, opts_len);
207 
208  size_t offset = LibDHCP::unpackOptions4(opts_buffer, DHCP4_OPTION_SPACE, options_, deferred_options_, false);
209 
210  // If offset is not equal to the size and there is no DHO_END,
211  // then something is wrong here. We either parsed past input
212  // buffer (bug in our code) or we haven't parsed everything
213  // (received trailing garbage or truncated option).
214  //
215  // Invoking Jon Postel's law here: be conservative in what you send, and be
216  // liberal in what you accept. There's no easy way to log something from
217  // libdhcp++ library, so we just choose to be silent about remaining
218  // bytes. We also need to quell compiler warning about unused offset
219  // variable.
220  //
221  // if ((offset != size) && (opts_buffer[offset] != DHO_END)) {
222  // isc_throw(BadValue, "Received DHCPv6 buffer of size " << size
223  // << ", were able to parse " << offset << " bytes.");
224  // }
225  (void)offset;
226 
227  // No need to call check() here. There are thorough tests for this
228  // later (see Dhcp4Srv::accept()). We want to drop the packet later,
229  // so we'll be able to log more detailed drop reason.
230 }
231 
232 uint8_t Pkt4::getType() const {
234  if (!generic) {
235  return (DHCP_NOTYPE);
236  }
237 
238  // Check if Message Type is specified as OptionInt<uint8_t>
239  boost::shared_ptr<OptionInt<uint8_t> > type_opt =
240  boost::dynamic_pointer_cast<OptionInt<uint8_t> >(generic);
241  if (type_opt) {
242  return (type_opt->getValue());
243  }
244 
245  // Try to use it as generic option
246  return (generic->getUint8());
247 }
248 
249 void Pkt4::setType(uint8_t dhcp_type) {
251  if (opt) {
252 
253  // There is message type option already, update it. It seems that
254  // we do have two types of objects representing message-type option.
255  // It would be more preferable to use only one type, but there's no
256  // easy way to enforce it.
257  //
258  // One is an instance of the Option class. It stores type in
259  // Option::data_, so Option::setUint8() and Option::getUint8() can be
260  // used. The other one is an instance of OptionInt<uint8_t> and
261  // it stores message type as integer, hence
262  // OptionInt<uint8_t>::getValue() and OptionInt<uint8_t>::setValue()
263  // should be used.
264  boost::shared_ptr<OptionInt<uint8_t> > type_opt =
265  boost::dynamic_pointer_cast<OptionInt<uint8_t> >(opt);
266  if (type_opt) {
267  type_opt->setValue(dhcp_type);
268  } else {
269  opt->setUint8(dhcp_type);
270  }
271  } else {
272  // There is no message type option yet, add it
274  dhcp_type));
275  addOption(opt);
276  }
277 }
278 
279 const char*
280 Pkt4::getName(const uint8_t type) {
281  static const char* DHCPDISCOVER_NAME = "DHCPDISCOVER";
282  static const char* DHCPOFFER_NAME = "DHCPOFFER";
283  static const char* DHCPREQUEST_NAME = "DHCPREQUEST";
284  static const char* DHCPDECLINE_NAME = "DHCPDECLINE";
285  static const char* DHCPACK_NAME = "DHCPACK";
286  static const char* DHCPNAK_NAME = "DHCPNAK";
287  static const char* DHCPRELEASE_NAME = "DHCPRELEASE";
288  static const char* DHCPINFORM_NAME = "DHCPINFORM";
289  static const char* DHCPLEASEQUERY_NAME = "DHCPLEASEQUERY";
290  static const char* DHCPLEASEUNASSIGNED_NAME = "DHCPLEASEUNASSIGNED";
291  static const char* DHCPLEASEUNKNOWN_NAME = "DHCPLEASEUNKNOWN";
292  static const char* DHCPLEASEACTIVE_NAME = "DHCPLEASEACTIVE";
293  static const char* DHCPBULKLEASEQUERY_NAME = "DHCPBULKLEASEQUERY";
294  static const char* DHCPLEASEQUERYDONE_NAME = "DHCPLEASEQUERYDONE";
295  static const char* DHCPLEASEQUERYSTATUS_NAME = "DHCPLEASEQUERYSTATUS";
296  static const char* DHCPTLS_NAME = "DHCPTLS";
297  static const char* UNKNOWN_NAME = "UNKNOWN";
298 
299  switch (type) {
300  case DHCPDISCOVER:
301  return (DHCPDISCOVER_NAME);
302 
303  case DHCPOFFER:
304  return (DHCPOFFER_NAME);
305 
306  case DHCPREQUEST:
307  return (DHCPREQUEST_NAME);
308 
309  case DHCPDECLINE:
310  return (DHCPDECLINE_NAME);
311 
312  case DHCPACK:
313  return (DHCPACK_NAME);
314 
315  case DHCPNAK:
316  return (DHCPNAK_NAME);
317 
318  case DHCPRELEASE:
319  return (DHCPRELEASE_NAME);
320 
321  case DHCPINFORM:
322  return (DHCPINFORM_NAME);
323 
324  case DHCPLEASEQUERY:
325  return (DHCPLEASEQUERY_NAME);
326 
327  case DHCPLEASEUNASSIGNED:
328  return (DHCPLEASEUNASSIGNED_NAME);
329 
330  case DHCPLEASEUNKNOWN:
331  return (DHCPLEASEUNKNOWN_NAME);
332 
333  case DHCPLEASEACTIVE:
334  return (DHCPLEASEACTIVE_NAME);
335 
336  case DHCPBULKLEASEQUERY:
337  return (DHCPBULKLEASEQUERY_NAME);
338 
339  case DHCPLEASEQUERYDONE:
340  return (DHCPLEASEQUERYDONE_NAME);
341 
343  return (DHCPLEASEQUERYSTATUS_NAME);
344 
345  case DHCPTLS:
346  return (DHCPTLS_NAME);
347 
348  default:
349  ;
350  }
351  return (UNKNOWN_NAME);
352 }
353 
354 const char*
355 Pkt4::getName() const {
356  // getType() is now exception safe. Even if there's no option 53 (message
357  // type), it now returns 0 rather than throw. getName() is able to handle
358  // 0 and unknown message types.
359  return (Pkt4::getName(getType()));
360 }
361 
362 std::string
363 Pkt4::getLabel() const {
364 
367  std::string suffix;
368  ClientIdPtr client_id;
370  if (client_opt) {
371  try {
372  client_id = ClientIdPtr(new ClientId(client_opt->getData()));
373  } catch (...) {
374  // ClientId may throw if the client-id is too short.
375  suffix = " (malformed client-id)";
376  }
377  }
378 
379  std::ostringstream label;
380  try {
381  label << makeLabel(hwaddr_, client_id, transid_);
382  } catch (...) {
383  // This should not happen with the current code, but we may add extra
384  // sanity checks in the future that would possibly throw if
385  // the hwaddr length is 0.
386  label << " (malformed hw address)";
387  }
388 
389  label << suffix;
390  return (label.str());
391 }
392 
393 std::string
394 Pkt4::makeLabel(const HWAddrPtr& hwaddr, const ClientIdPtr& client_id,
395  const uint32_t transid) {
396  // Create label with HW address and client identifier.
397  stringstream label;
398  label << makeLabel(hwaddr, client_id);
399 
400  // Append transaction id.
401  label << ", tid=0x" << hex << transid << dec;
402 
403  return label.str();
404 }
405 
406 std::string
407 Pkt4::makeLabel(const HWAddrPtr& hwaddr, const ClientIdPtr& client_id) {
408  stringstream label;
409  label << "[" << (hwaddr ? hwaddr->toText() : "no hwaddr info")
410  << "], cid=[" << (client_id ? client_id->toText() : "no info")
411  << "]";
412 
413  return label.str();
414 }
415 
416 std::string
417 Pkt4::toText() const {
418  stringstream output;
419  output << "local_address=" << local_addr_ << ":" << local_port_
420  << ", remote_address=" << remote_addr_
421  << ":" << remote_port_ << ", msg_type=";
422 
423  // Try to obtain message type.
424  uint8_t msg_type = getType();
425  if (msg_type != DHCP_NOTYPE) {
426  output << getName(msg_type) << " (" << static_cast<int>(msg_type) << ")";
427  } else {
428  // Message Type option is missing.
429  output << "(missing)";
430  }
431 
432  output << ", transid=0x" << hex << transid_ << dec;
433 
434  if (!options_.empty()) {
435  output << "," << std::endl << "options:";
436  for (isc::dhcp::OptionCollection::const_iterator opt = options_.begin();
437  opt != options_.end(); ++opt) {
438  try {
439  output << std::endl << opt->second->toText(2);
440  } catch (...) {
441  output << "(unknown)" << std::endl;
442  }
443  }
444 
445  } else {
446  output << ", message contains no options";
447  }
448 
449  return (output.str());
450 }
451 
452 void
453 Pkt4::setHWAddr(uint8_t htype, uint8_t hlen,
454  const std::vector<uint8_t>& mac_addr) {
455  setHWAddrMember(htype, hlen, mac_addr, hwaddr_);
456 }
457 
458 void
460  if (!addr) {
461  isc_throw(BadValue, "Setting DHCPv4 chaddr field to NULL"
462  << " is forbidden");
463  }
464  hwaddr_ = addr;
465 }
466 
467 void
468 Pkt4::setHWAddrMember(const uint8_t htype, const uint8_t hlen,
469  const std::vector<uint8_t>& mac_addr,
470  HWAddrPtr& hw_addr) {
473  if (hlen > MAX_CHADDR_LEN) {
474  isc_throw(OutOfRange, "Hardware address (len=" << hlen
475  << " too long. Max " << MAX_CHADDR_LEN << " supported.");
476 
477  } else if (mac_addr.empty() && (hlen > 0) ) {
478  isc_throw(OutOfRange, "Invalid HW Address specified");
479  }
480 
484  hw_addr.reset(new HWAddr(mac_addr, htype));
485 }
486 
487 void
488 Pkt4::setLocalHWAddr(const uint8_t htype, const uint8_t hlen,
489  const std::vector<uint8_t>& mac_addr) {
490  setHWAddrMember(htype, hlen, mac_addr, local_hwaddr_);
491 }
492 
493 void
495  if (!addr) {
496  isc_throw(BadValue, "Setting local HW address to NULL is"
497  << " forbidden.");
498  }
499  local_hwaddr_ = addr;
500 }
501 
502 void
503 Pkt4::setSname(const uint8_t* sname, size_t snameLen /*= MAX_SNAME_LEN*/) {
504  if (snameLen > MAX_SNAME_LEN) {
505  isc_throw(OutOfRange, "sname field (len=" << snameLen
506  << ") too long, Max " << MAX_SNAME_LEN << " supported.");
507 
508  } else if (sname == NULL) {
509  isc_throw(InvalidParameter, "Invalid sname specified");
510  }
511 
512  std::copy(sname, (sname + snameLen), sname_);
513  if (snameLen < MAX_SNAME_LEN) {
514  std::fill((sname_ + snameLen), (sname_ + MAX_SNAME_LEN), 0);
515  }
516 
517  // No need to store snameLen as any empty space is filled with 0s
518 }
519 
520 void
521 Pkt4::setFile(const uint8_t* file, size_t fileLen /*= MAX_FILE_LEN*/) {
522  if (fileLen > MAX_FILE_LEN) {
523  isc_throw(OutOfRange, "file field (len=" << fileLen
524  << ") too long, Max " << MAX_FILE_LEN << " supported.");
525 
526  } else if (file == NULL) {
527  isc_throw(InvalidParameter, "Invalid file name specified");
528  }
529 
530  std::copy(file, (file + fileLen), file_);
531  if (fileLen < MAX_FILE_LEN) {
532  std::fill((file_ + fileLen), (file_ + MAX_FILE_LEN), 0);
533  }
534 
535  // No need to store fileLen as any empty space is filled with 0s
536 }
537 
538 uint8_t
539 // cppcheck-suppress unusedFunction
540 Pkt4::DHCPTypeToBootpType(uint8_t dhcpType) {
541  switch (dhcpType) {
542  case DHCPDISCOVER:
543  case DHCPREQUEST:
544  case DHCPDECLINE:
545  case DHCPRELEASE:
546  case DHCPINFORM:
547  case DHCPLEASEQUERY:
548  case DHCPBULKLEASEQUERY:
549  return (BOOTREQUEST);
550 
551  case DHCPACK:
552  case DHCPNAK:
553  case DHCPOFFER:
554  case DHCPLEASEUNASSIGNED:
555  case DHCPLEASEUNKNOWN:
556  case DHCPLEASEACTIVE:
557  case DHCPLEASEQUERYDONE:
558  return (BOOTREPLY);
559 
560  default:
561  isc_throw(OutOfRange, "Invalid message type: "
562  << static_cast<int>(dhcpType) );
563  }
564 }
565 
566 uint8_t
567 Pkt4::getHtype() const {
568  if (!hwaddr_) {
569  return (HTYPE_UNDEFINED);
570  }
571  return (hwaddr_->htype_);
572 }
573 
574 uint8_t
575 Pkt4::getHlen() const {
576  if (!hwaddr_) {
577  return (0);
578  }
579  uint8_t len = hwaddr_->hwaddr_.size();
580  return (len <= MAX_CHADDR_LEN ? len : MAX_CHADDR_LEN);
581 }
582 
583 void
585  // Check for uniqueness (DHCPv4 options must be unique)
586  if (getNonCopiedOption(opt->getType())) {
587  isc_throw(BadValue, "Option " << opt->getType()
588  << " already present in this message.");
589  }
590 
591  Pkt::addOption(opt);
592 }
593 
594 bool
596  return (!giaddr_.isV4Zero() && !giaddr_.isV4Bcast());
597 }
598 
599 } // end of namespace isc::dhcp
600 
601 } // end of namespace isc
static const size_t MAX_SNAME_LEN
length of the SNAME field in DHCPv4 message
Definition: pkt4.h:44
Pkt4(uint8_t msg_type, uint32_t transid)
Constructor, used in replying to a message.
Definition: pkt4.cc:32
uint8_t hops_
Number of relay agents traversed.
Definition: pkt4.h:514
isc::asiolink::IOAddress local_addr_
Local IP (v4 or v6) address.
Definition: pkt.h:742
void setValue(T value)
Set option value.
Definition: option_int.h:185
uint8_t sname_[MAX_SNAME_LEN]
sname field (64 bytes)
Definition: pkt4.h:535
uint16_t flags_
flags
Definition: pkt4.h:520
OptionBuffer data_
Unparsed data (in received packets).
Definition: pkt.h:312
static std::string makeLabel(const HWAddrPtr &hwaddr, const ClientIdPtr &client_id, const uint32_t transid)
Returns text representation of the given packet identifiers.
Definition: pkt4.cc:394
uint8_t getHlen() const
Returns hlen field.
Definition: pkt4.cc:575
Message Type option missing.
Definition: dhcp4.h:229
uint8_t DHCPTypeToBootpType(uint8_t dhcpType)
converts DHCP message type to BOOTP op type
Definition: pkt4.cc:540
isc::asiolink::IOAddress giaddr_
giaddr field (32 bits): Gateway IP address
Definition: pkt4.h:532
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.
Definition: hwaddr.h:154
static const size_t MAX_CHADDR_LEN
length of the CHADDR field in DHCPv4 message
Definition: pkt4.h:41
uint32_t transid_
Transaction-id (32 bits for v4, 24 bits for v6)
Definition: pkt.h:726
static const size_t MAX_FILE_LEN
length of the FILE field in DHCPv4 message
Definition: pkt4.h:47
static const size_t DHCPV4_PKT_HDR_LEN
specifies DHCPv4 packet header length (fixed part)
Definition: pkt4.h:50
virtual void unpack()
Parses on-wire form of DHCPv4 packet.
Definition: pkt4.cc:152
Base class for classes representing DHCP messages.
Definition: pkt.h:90
boost::shared_ptr< Option > OptionPtr
Definition: option.h:36
STL namespace.
virtual void addOption(const OptionPtr &opt)
Adds an option to this packet.
Definition: pkt.cc:56
std::string getLabel() const
Returns text representation of the primary packet identifiers.
Definition: pkt4.cc:363
Forward declaration to OptionInt.
OptionPtr getNonCopiedOption(const uint16_t type) const
Returns the first option of specified type without copying.
Definition: pkt.cc:61
bool isRelayed() const
Checks if a DHCPv4 message has been relayed.
Definition: pkt4.cc:595
isc::asiolink::IOAddress siaddr_
siaddr field (32 bits): next server IP address in boot process(e.g.TFTP)
Definition: pkt4.h:529
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)
Definition: pkt4.h:511
not specified or undefined
Definition: dhcp4.h:55
static void packOptions4(isc::util::OutputBuffer &buf, const isc::dhcp::OptionCollection &options, bool top=false)
Stores DHCPv4 options in a buffer.
Definition: libdhcp++.cc:814
void writeData(const void *data, size_t len)
Copy an arbitrary length of data into the buffer.
Definition: buffer.h:550
#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
Definition: pkt4.h:505
ElementPtr copy(ConstElementPtr from, int level)
Copy the data up to a nesting level.
Definition: data.cc:1097
uint8_t getType() const
Returns DHCP message type (e.g.
Definition: pkt4.cc:232
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.
Definition: pkt4.cc:503
void clear()
Clear buffer content.
Definition: buffer.h:451
isc::asiolink::IOAddress ciaddr_
ciaddr field (32 bits): Client's IP address
Definition: pkt4.h:523
boost::shared_ptr< ClientId > ClientIdPtr
Shared pointer to a Client ID.
Definition: duid.h:103
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
void writeUint32(uint32_t data)
Write an unsigned 32-bit integer in host byte order into the buffer in network byte order...
Definition: buffer.h:520
uint16_t remote_port_
remote TCP or UDP port
Definition: pkt.h:754
std::list< uint16_t > deferred_options_
Definition: pkt4.h:496
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-dhcp-ddns.
const char * getName() const
Returns name of the DHCP message.
Definition: pkt4.cc:355
uint16_t local_port_
local TDP or UDP port
Definition: pkt.h:751
void setHWAddr(uint8_t htype, uint8_t hlen, const std::vector< uint8_t > &mac_addr)
Sets hardware address.
Definition: pkt4.cc:453
void setType(uint8_t type)
Sets DHCP message type (e.g.
Definition: pkt4.cc:249
isc::asiolink::IOAddress remote_addr_
Remote IP address.
Definition: pkt.h:748
Holds Client identifier or client IPv4 address.
Definition: duid.h:111
void writeUint8(uint8_t data)
Write an unsigned 8-bit integer into the buffer.
Definition: buffer.h:466
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.
Definition: hwaddr.h:20
void writeUint16(uint16_t data)
Write an unsigned 16-bit integer in host byte order into the buffer in network byte order...
Definition: buffer.h:490
The InputBuffer class is a buffer abstraction for manipulating read-only data.
Definition: buffer.h:81
uint8_t file_[MAX_FILE_LEN]
file field (128 bytes)
Definition: pkt4.h:538
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
uint8_t getHtype() const
Returns htype field.
Definition: pkt4.cc:567
virtual void addOption(const OptionPtr &opt)
Add an option.
Definition: pkt4.cc:584
isc::util::OutputBuffer buffer_out_
Output buffer (used during message transmission)
Definition: pkt.h:764
void setFile(const uint8_t *file, size_t file_len)
Sets file field.
Definition: pkt4.cc:521
uint16_t secs_
elapsed (number of seconds since beginning of transmission)
Definition: pkt4.h:517
virtual void pack()
Prepares on-wire format of DHCPv4 packet.
Definition: pkt4.cc:89
HWAddrPtr local_hwaddr_
local HW address (dst if receiving packet, src if sending packet)
Definition: pkt4.h:493
isc::dhcp::OptionCollection options_
Collection of options present in this message.
Definition: pkt.h:614
void setLocalHWAddr(const uint8_t htype, const uint8_t hlen, const std::vector< uint8_t > &mac_addr)
Sets local HW address.
Definition: pkt4.cc:488
size_t len()
Returns the size of the required buffer to build the packet.
Definition: pkt4.cc:75
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.
Definition: libdhcp++.cc:459
std::string toText() const
Returns text representation of the packet.
Definition: pkt4.cc:417
isc::asiolink::IOAddress yiaddr_
yiaddr field (32 bits): Client's IP address ("your"), set by server
Definition: pkt4.h:526