Kea 2.7.5
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
126 ManagedScopedOptionsCopyContainer m_scoped_options;
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.
135 LibDHCP::splitOptions4(options_, m_scoped_options.scoped_options_);
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 // Kea supports multiple vendor options so it needs to split received and
226 // fused options in multiple OptionVendor instances.
228
229 // No need to call check() here. There are thorough tests for this
230 // later (see Dhcp4Srv::accept()). We want to drop the packet later,
231 // so we'll be able to log more detailed drop reason.
232}
233
234uint8_t Pkt4::getType() const {
236 if (!generic) {
237 return (DHCP_NOTYPE);
238 }
239
240 // Check if Message Type is specified as OptionInt<uint8_t>
241 boost::shared_ptr<OptionInt<uint8_t> > type_opt =
242 boost::dynamic_pointer_cast<OptionInt<uint8_t> >(generic);
243 if (type_opt) {
244 return (type_opt->getValue());
245 }
246
247 // Try to use it as generic option
248 return (generic->getUint8());
249}
250
251void Pkt4::setType(uint8_t dhcp_type) {
253 if (opt) {
254
255 // There is message type option already, update it. It seems that
256 // we do have two types of objects representing message-type option.
257 // It would be more preferable to use only one type, but there's no
258 // easy way to enforce it.
259 //
260 // One is an instance of the Option class. It stores type in
261 // Option::data_, so Option::setUint8() and Option::getUint8() can be
262 // used. The other one is an instance of OptionInt<uint8_t> and
263 // it stores message type as integer, hence
264 // OptionInt<uint8_t>::getValue() and OptionInt<uint8_t>::setValue()
265 // should be used.
266 boost::shared_ptr<OptionInt<uint8_t> > type_opt =
267 boost::dynamic_pointer_cast<OptionInt<uint8_t> >(opt);
268 if (type_opt) {
269 type_opt->setValue(dhcp_type);
270 } else {
271 opt->setUint8(dhcp_type);
272 }
273 } else {
274 // There is no message type option yet, add it
275 opt.reset(new OptionInt<uint8_t>(Option::V4, DHO_DHCP_MESSAGE_TYPE,
276 dhcp_type));
277 addOption(opt);
278 }
279}
280
281const char*
282Pkt4::getName(const uint8_t type) {
283 static const char* DHCPDISCOVER_NAME = "DHCPDISCOVER";
284 static const char* DHCPOFFER_NAME = "DHCPOFFER";
285 static const char* DHCPREQUEST_NAME = "DHCPREQUEST";
286 static const char* DHCPDECLINE_NAME = "DHCPDECLINE";
287 static const char* DHCPACK_NAME = "DHCPACK";
288 static const char* DHCPNAK_NAME = "DHCPNAK";
289 static const char* DHCPRELEASE_NAME = "DHCPRELEASE";
290 static const char* DHCPINFORM_NAME = "DHCPINFORM";
291 static const char* DHCPLEASEQUERY_NAME = "DHCPLEASEQUERY";
292 static const char* DHCPLEASEUNASSIGNED_NAME = "DHCPLEASEUNASSIGNED";
293 static const char* DHCPLEASEUNKNOWN_NAME = "DHCPLEASEUNKNOWN";
294 static const char* DHCPLEASEACTIVE_NAME = "DHCPLEASEACTIVE";
295 static const char* DHCPBULKLEASEQUERY_NAME = "DHCPBULKLEASEQUERY";
296 static const char* DHCPLEASEQUERYDONE_NAME = "DHCPLEASEQUERYDONE";
297 static const char* DHCPLEASEQUERYSTATUS_NAME = "DHCPLEASEQUERYSTATUS";
298 static const char* DHCPTLS_NAME = "DHCPTLS";
299 static const char* UNKNOWN_NAME = "UNKNOWN";
300
301 switch (type) {
302 case DHCPDISCOVER:
303 return (DHCPDISCOVER_NAME);
304
305 case DHCPOFFER:
306 return (DHCPOFFER_NAME);
307
308 case DHCPREQUEST:
309 return (DHCPREQUEST_NAME);
310
311 case DHCPDECLINE:
312 return (DHCPDECLINE_NAME);
313
314 case DHCPACK:
315 return (DHCPACK_NAME);
316
317 case DHCPNAK:
318 return (DHCPNAK_NAME);
319
320 case DHCPRELEASE:
321 return (DHCPRELEASE_NAME);
322
323 case DHCPINFORM:
324 return (DHCPINFORM_NAME);
325
326 case DHCPLEASEQUERY:
327 return (DHCPLEASEQUERY_NAME);
328
330 return (DHCPLEASEUNASSIGNED_NAME);
331
332 case DHCPLEASEUNKNOWN:
333 return (DHCPLEASEUNKNOWN_NAME);
334
335 case DHCPLEASEACTIVE:
336 return (DHCPLEASEACTIVE_NAME);
337
339 return (DHCPBULKLEASEQUERY_NAME);
340
342 return (DHCPLEASEQUERYDONE_NAME);
343
345 return (DHCPLEASEQUERYSTATUS_NAME);
346
347 case DHCPTLS:
348 return (DHCPTLS_NAME);
349
350 default:
351 ;
352 }
353 return (UNKNOWN_NAME);
354}
355
356const char*
358 // getType() is now exception safe. Even if there's no option 53 (message
359 // type), it now returns 0 rather than throw. getName() is able to handle
360 // 0 and unknown message types.
361 return (Pkt4::getName(getType()));
362}
363
364std::string
366
369 std::string suffix;
370 ClientIdPtr client_id;
371 OptionPtr client_opt = getNonCopiedOption(DHO_DHCP_CLIENT_IDENTIFIER);
372 if (client_opt) {
373 try {
374 client_id = ClientIdPtr(new ClientId(client_opt->getData()));
375 } catch (...) {
376 // ClientId may throw if the client-id is too short.
377 suffix = " (malformed client-id)";
378 }
379 }
380
381 std::ostringstream label;
382 try {
383 label << makeLabel(hwaddr_, client_id, transid_);
384 } catch (...) {
385 // This should not happen with the current code, but we may add extra
386 // sanity checks in the future that would possibly throw if
387 // the hwaddr length is 0.
388 label << " (malformed hw address)";
389 }
390
391 label << suffix;
392
393 return (label.str());
394}
395
396std::string
397Pkt4::makeLabel(const HWAddrPtr& hwaddr, const ClientIdPtr& client_id,
398 const uint32_t transid) {
399 // Create label with HW address and client identifier.
400 stringstream label;
401 label << makeLabel(hwaddr, client_id);
402
403 // Append transaction id.
404 label << ", tid=0x" << hex << transid << dec;
405
406 return (label.str());
407}
408
409std::string
410Pkt4::makeLabel(const HWAddrPtr& hwaddr, const ClientIdPtr& client_id) {
411 stringstream label;
412 label << "[" << (hwaddr ? hwaddr->toText() : "no hwaddr info")
413 << "], cid=[" << (client_id ? client_id->toText() : "no info")
414 << "]";
415
416 return (label.str());
417}
418
419std::string
421 stringstream tmp;
422
423 // First print the basics
424 tmp << "local_address=" << local_addr_ << ":" << local_port_
425 << ", remote_address=" << remote_addr_ << ":" << remote_port_ << "," << endl;
426
427 tmp << "msg_type=";
428
429 // Try to obtain message type.
430 uint8_t msg_type = getType();
431 if (msg_type != DHCP_NOTYPE) {
432 tmp << getName(msg_type) << " (" << static_cast<int>(msg_type) << ")";
433 } else {
434 // Message Type option is missing.
435 tmp << "(missing)";
436 }
437
438 tmp << ", trans_id=0x" << hex << transid_ << dec;
439
440 if (!options_.empty()) {
441 tmp << "," << endl << "options:";
442 for (auto const& opt : options_) {
443 try {
444 tmp << endl << opt.second->toText(2);
445 } catch (...) {
446 tmp << "(unknown)" << endl;
447 }
448 }
449
450 } else {
451 tmp << "," << endl << "message contains no options";
452 }
453
454 return (tmp.str());
455}
456
457void
458Pkt4::setHWAddr(uint8_t htype, uint8_t hlen,
459 const std::vector<uint8_t>& mac_addr) {
460 setHWAddrMember(htype, hlen, mac_addr, hwaddr_);
461}
462
463void
465 if (!addr) {
466 isc_throw(BadValue, "Setting DHCPv4 chaddr field to NULL"
467 << " is forbidden");
468 }
469 hwaddr_ = addr;
470}
471
472void
473Pkt4::setHWAddrMember(const uint8_t htype, const uint8_t hlen,
474 const std::vector<uint8_t>& mac_addr,
475 HWAddrPtr& hw_addr) {
478 if (hlen > MAX_CHADDR_LEN) {
479 isc_throw(OutOfRange, "Hardware address (len=" << static_cast<uint32_t>(hlen)
480 << ") too long. Max " << MAX_CHADDR_LEN << " supported.");
481
482 } else if (mac_addr.empty() && (hlen > 0) ) {
483 isc_throw(OutOfRange, "Invalid HW Address specified");
484 }
485
489 hw_addr.reset(new HWAddr(mac_addr, htype));
490}
491
492void
493Pkt4::setLocalHWAddr(const uint8_t htype, const uint8_t hlen,
494 const std::vector<uint8_t>& mac_addr) {
495 setHWAddrMember(htype, hlen, mac_addr, local_hwaddr_);
496}
497
498void
500 if (!addr) {
501 isc_throw(BadValue, "Setting local HW address to NULL is"
502 << " forbidden.");
503 }
504 local_hwaddr_ = addr;
505}
506
507void
508Pkt4::setSname(const uint8_t* sname, size_t snameLen /*= MAX_SNAME_LEN*/) {
509 if (snameLen > MAX_SNAME_LEN) {
510 isc_throw(OutOfRange, "sname field (len=" << snameLen
511 << ") too long, Max " << MAX_SNAME_LEN << " supported.");
512
513 } else if (sname == NULL) {
514 isc_throw(InvalidParameter, "Invalid sname specified");
515 }
516
517 std::copy(sname, (sname + snameLen), sname_);
518 if (snameLen < MAX_SNAME_LEN) {
519 std::fill((sname_ + snameLen), (sname_ + MAX_SNAME_LEN), 0);
520 }
521
522 // No need to store snameLen as any empty space is filled with 0s
523}
524
525void
526Pkt4::setFile(const uint8_t* file, size_t fileLen /*= MAX_FILE_LEN*/) {
527 if (fileLen > MAX_FILE_LEN) {
528 isc_throw(OutOfRange, "file field (len=" << fileLen
529 << ") too long, Max " << MAX_FILE_LEN << " supported.");
530
531 } else if (file == NULL) {
532 isc_throw(InvalidParameter, "Invalid file name specified");
533 }
534
535 std::copy(file, (file + fileLen), file_);
536 if (fileLen < MAX_FILE_LEN) {
537 std::fill((file_ + fileLen), (file_ + MAX_FILE_LEN), 0);
538 }
539
540 // No need to store fileLen as any empty space is filled with 0s
541}
542
543uint8_t
544// cppcheck-suppress unusedFunction
545Pkt4::DHCPTypeToBootpType(uint8_t dhcpType) {
546 switch (dhcpType) {
547 case DHCPDISCOVER:
548 case DHCPREQUEST:
549 case DHCPDECLINE:
550 case DHCPRELEASE:
551 case DHCPINFORM:
552 case DHCPLEASEQUERY:
554 return (BOOTREQUEST);
555
556 case DHCPACK:
557 case DHCPNAK:
558 case DHCPOFFER:
560 case DHCPLEASEUNKNOWN:
561 case DHCPLEASEACTIVE:
563 return (BOOTREPLY);
564
565 default:
566 isc_throw(OutOfRange, "Invalid message type: "
567 << static_cast<int>(dhcpType) );
568 }
569}
570
571uint8_t
573 if (!hwaddr_) {
574 return (HTYPE_UNDEFINED);
575 }
576 return (hwaddr_->htype_);
577}
578
579uint8_t
581 if (!hwaddr_) {
582 return (0);
583 }
584 uint8_t len = hwaddr_->hwaddr_.size();
585 return (len <= MAX_CHADDR_LEN ? len : MAX_CHADDR_LEN);
586}
587
588void
590 // Check for uniqueness (DHCPv4 options must be unique)
591 if (getNonCopiedOption(opt->getType())) {
592 isc_throw(BadValue, "Option " << opt->getType()
593 << " already present in this message.");
594 }
595
596 Pkt::addOption(opt);
597}
598
599bool
601 return (!giaddr_.isV4Zero() && !giaddr_.isV4Bcast());
602}
603
604std::string
606 std::ostringstream label;
607 label << "hwaddr=";
608 hwaddr_ ? label << hwaddr_->toText(false) : label << "(undefined)";
609 return (label.str());
610}
611
612} // end of namespace isc::dhcp
613} // 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:471
static void extendVendorOptions4(isc::dhcp::OptionCollection &options)
Extend vendor options from fused options in multiple OptionVendor or OptionVendorClass options and ad...
Definition libdhcp++.cc:817
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).
virtual void addOption(const OptionPtr &opt)
Add an option.
Definition pkt4.cc:589
std::string toText() const
Returns text representation of the packet.
Definition pkt4.cc:420
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:357
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:493
std::string getHWAddrLabel() const
Returns text representation of the hardware address.
Definition pkt4.cc:605
uint8_t DHCPTypeToBootpType(uint8_t dhcpType)
converts DHCP message type to BOOTP op type
Definition pkt4.cc:545
std::string getLabel() const
Returns text representation of the primary packet identifiers.
Definition pkt4.cc:365
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:508
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:580
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:600
void setFile(const uint8_t *file, size_t file_len)
Sets file field.
Definition pkt4.cc:526
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:397
uint8_t getType() const
Returns DHCP message type (e.g.
Definition pkt4.cc:234
void setType(uint8_t type)
Sets DHCP message type (e.g.
Definition pkt4.cc:251
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:458
uint8_t getHtype() const
Returns htype field.
Definition pkt4.cc:572
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:946
uint16_t local_port_
local TDP or UDP port
Definition pkt.h:949
uint32_t transid_
Transaction-id (32 bits for v4, 24 bits for v6)
Definition pkt.h:924
isc::asiolink::IOAddress local_addr_
Local IP (v4 or v6) address.
Definition pkt.h:940
OptionBuffer data_
Unparsed data (in received packets).
Definition pkt.h:414
uint16_t remote_port_
remote TCP or UDP port
Definition pkt.h:952
isc::dhcp::OptionCollection options_
Collection of options present in this message.
Definition pkt.h:812
isc::util::OutputBuffer buffer_out_
Output buffer (used during message transmission)
Definition pkt.h:962
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
The InputBuffer class is a buffer abstraction for manipulating read-only data.
Definition buffer.h:81
void writeUint8(uint8_t data)
Write an unsigned 8-bit integer into the buffer.
Definition buffer.h:473
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:466
#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.
Definition libdhcp++.h:26
@ DHO_DHCP_MESSAGE_TYPE
Definition dhcp4.h:122
@ DHO_END
Definition dhcp4.h:229
@ 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:251
@ DHCPTLS
Definition dhcp4.h:252
@ DHCPREQUEST
Definition dhcp4.h:237
@ DHCPLEASEQUERYDONE
Definition dhcp4.h:249
@ DHCPLEASEUNKNOWN
Definition dhcp4.h:246
@ DHCPOFFER
Definition dhcp4.h:236
@ DHCPLEASEACTIVE
Definition dhcp4.h:247
@ DHCPLEASEQUERY
Definition dhcp4.h:244
@ DHCPDECLINE
Definition dhcp4.h:238
@ DHCPNAK
Definition dhcp4.h:240
@ DHCPRELEASE
Definition dhcp4.h:241
@ DHCPLEASEUNASSIGNED
Definition dhcp4.h:245
@ DHCPDISCOVER
Definition dhcp4.h:235
@ DHCPBULKLEASEQUERY
Definition dhcp4.h:248
@ DHCP_NOTYPE
Message Type option missing.
Definition dhcp4.h:234
@ DHCPINFORM
Definition dhcp4.h:242
@ DHCPACK
Definition dhcp4.h:239
@ 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