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