Kea 2.7.4
host.cc
Go to the documentation of this file.
1// Copyright (C) 2014-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>
8
12#include <dhcp/pkt4.h>
13#include <dhcpsrv/host.h>
15
16#include <util/encode/encode.h>
17#include <util/str.h>
18
19#include <boost/foreach.hpp>
20#include <sstream>
21
22using namespace isc::data;
23using namespace isc::asiolink;
24
25namespace isc {
26namespace dhcp {
27
28AuthKey::AuthKey(const std::vector<uint8_t>& key) {
29 setAuthKey(key);
30}
31
32AuthKey::AuthKey(const std::string& key) {
33 setAuthKey(key);
34}
35
39
40std::vector<uint8_t>
44
45std::string
47 if (authKey_.empty()) {
48 return ("");
49 }
50 return (util::encode::encodeHex(authKey_));
51}
52
53void
54AuthKey::setAuthKey(const std::vector<uint8_t>& key) {
55 authKey_ = key;
56 if (authKey_.size() > AUTH_KEY_LEN) {
57 authKey_.resize(AUTH_KEY_LEN);
58 }
59}
60
61void
62AuthKey::setAuthKey(const std::string& key) {
63 if (key.empty()) {
64 authKey_.clear();
65 return;
66 }
67 try {
68 std::vector<uint8_t> bin;
70 setAuthKey(bin);
71 } catch (const std::exception& ex) {
72 isc_throw(BadValue, "bad auth key: " << ex.what());
73 }
74}
75
76bool
77AuthKey::operator==(const AuthKey& other) const {
78 return (authKey_ == other.authKey_);
79}
80
81bool
82AuthKey::operator!=(const AuthKey& other) const {
83 return (authKey_ != other.authKey_);
84}
85
87 const asiolink::IOAddress& prefix,
88 const uint8_t prefix_len)
89 : type_(type), prefix_(asiolink::IOAddress("::")), prefix_len_(128),
90 pd_exclude_option_() {
91 // Validate and set the actual values.
92 set(type, prefix, prefix_len);
93}
94
95void
96IPv6Resrv::set(const Type& type, const asiolink::IOAddress& prefix,
97 const uint8_t prefix_len) {
98 if (!prefix.isV6() || prefix.isV6Multicast()) {
99 isc_throw(isc::BadValue, "invalid prefix '" << prefix
100 << "' for new IPv6 reservation");
101
102 } else if (prefix_len > 128) {
103 isc_throw(isc::BadValue, "invalid prefix length '"
104 << static_cast<int>(prefix_len)
105 << "' for new IPv6 reservation");
106
107 } else if ((type == TYPE_NA) && (prefix_len != 128)) {
108 isc_throw(isc::BadValue, "invalid prefix length '"
109 << static_cast<int>(prefix_len)
110 << "' for reserved IPv6 address, expected 128");
111 }
112
113 type_ = type;
114 prefix_ = prefix;
115 prefix_len_ = prefix_len;
116 pd_exclude_option_.reset();
117}
118
119void
121 const uint8_t excluded_prefix_len) {
122 if (excluded_prefix_len == 0) {
123 pd_exclude_option_.reset();
124 } else {
125 pd_exclude_option_.reset(new Option6PDExclude(prefix_, prefix_len_,
126 excluded_prefix,
127 excluded_prefix_len));
128 }
129}
130
131std::string
132IPv6Resrv::toText(bool display_pd_exclude_option) const {
133 std::ostringstream s;
134 s << prefix_;
135 // For PD, append prefix length.
136 if (type_ == TYPE_PD) {
137 s << "/" << static_cast<int>(prefix_len_);
138 // If there is a Prefix Exclude option append it.
139 if (display_pd_exclude_option && pd_exclude_option_) {
140 s << " (excluded_prefix="
141 << pd_exclude_option_->getExcludedPrefix(prefix_,
142 prefix_len_).toText()
143 << "/"
144 << static_cast<int>(pd_exclude_option_->getExcludedPrefixLength())
145 << ")";
146 }
147 }
148 return (s.str());
149}
150
151std::string
153 if (pd_exclude_option_) {
154 std::ostringstream s;
155 s << pd_exclude_option_->getExcludedPrefix(prefix_,
156 prefix_len_).toText()
157 << "/"
158 << static_cast<int>(pd_exclude_option_->getExcludedPrefixLength());
159 return (s.str());
160 } else {
161 return ("");
162 }
163}
164
165bool
166IPv6Resrv::operator==(const IPv6Resrv& other) const {
167 return (type_ == other.type_ &&
168 prefix_ == other.prefix_ &&
169 prefix_len_ == other.prefix_len_);
170}
171
172bool
173IPv6Resrv::operator!=(const IPv6Resrv& other) const {
174 return (!operator==(other));
175}
176
177Host::Host(const uint8_t* identifier, const size_t identifier_len,
178 const IdentifierType& identifier_type,
179 const SubnetID ipv4_subnet_id, const SubnetID ipv6_subnet_id,
180 const asiolink::IOAddress& ipv4_reservation,
181 const std::string& hostname,
182 const std::string& dhcp4_client_classes,
183 const std::string& dhcp6_client_classes,
184 const asiolink::IOAddress& next_server,
185 const std::string& server_host_name,
186 const std::string& boot_file_name,
187 const AuthKey& auth_key)
188
189 : identifier_type_(identifier_type),
190 identifier_value_(), ipv4_subnet_id_(ipv4_subnet_id),
191 ipv6_subnet_id_(ipv6_subnet_id),
192 ipv4_reservation_(asiolink::IOAddress::IPV4_ZERO_ADDRESS()),
193 hostname_(hostname), dhcp4_client_classes_(dhcp4_client_classes),
194 dhcp6_client_classes_(dhcp6_client_classes),
195 next_server_(asiolink::IOAddress::IPV4_ZERO_ADDRESS()),
196 server_host_name_(server_host_name), boot_file_name_(boot_file_name),
197 host_id_(0), cfg_option4_(new CfgOption()),
198 cfg_option6_(new CfgOption()), negative_(false),
199 key_(auth_key) {
200
201 // Initialize host identifier.
202 setIdentifier(identifier, identifier_len, identifier_type);
203
204 if (!ipv4_reservation.isV4Zero()) {
205 // Validate and set IPv4 address reservation.
206 setIPv4Reservation(ipv4_reservation);
207 }
208
209 if (!next_server.isV4Zero()) {
210 // Validate and set next server address.
211 setNextServer(next_server);
212 }
213}
214
215Host::Host(const std::string& identifier, const std::string& identifier_name,
216 const SubnetID ipv4_subnet_id, const SubnetID ipv6_subnet_id,
217 const asiolink::IOAddress& ipv4_reservation,
218 const std::string& hostname,
219 const std::string& dhcp4_client_classes,
220 const std::string& dhcp6_client_classes,
221 const asiolink::IOAddress& next_server,
222 const std::string& server_host_name,
223 const std::string& boot_file_name,
224 const AuthKey& auth_key)
225 : identifier_type_(IDENT_HWADDR),
226 identifier_value_(), ipv4_subnet_id_(ipv4_subnet_id),
227 ipv6_subnet_id_(ipv6_subnet_id),
228 ipv4_reservation_(asiolink::IOAddress::IPV4_ZERO_ADDRESS()),
229 hostname_(hostname), dhcp4_client_classes_(dhcp4_client_classes),
230 dhcp6_client_classes_(dhcp6_client_classes),
231 next_server_(asiolink::IOAddress::IPV4_ZERO_ADDRESS()),
232 server_host_name_(server_host_name), boot_file_name_(boot_file_name),
233 host_id_(0), cfg_option4_(new CfgOption()),
234 cfg_option6_(new CfgOption()), negative_(false),
235 key_(auth_key) {
236
237 // Initialize host identifier.
238 setIdentifier(identifier, identifier_name);
239
240 if (!ipv4_reservation.isV4Zero()) {
241 // Validate and set IPv4 address reservation.
242 setIPv4Reservation(ipv4_reservation);
243 }
244
245 if (!next_server.isV4Zero()) {
246 // Validate and set next server address.
247 setNextServer(next_server);
248 }
249}
250
251size_t
253 switch (type) {
254 case IDENT_HWADDR:
255 return (HWAddr::MAX_HWADDR_LEN);
256 case IDENT_DUID:
257 return (DUID::MAX_DUID_LEN);
258 case IDENT_CLIENT_ID:
260 default:
261 // In fact it is backend dependent but for compatibility we take
262 // the lowest value.
263 return (128);
264 }
265}
266
267const std::vector<uint8_t>&
269 return (identifier_value_);
270}
271
274 return (identifier_type_);
275}
276
278Host::getIdentifierType(const std::string& identifier_name) {
279 if (identifier_name == "hw-address") {
280 return (IDENT_HWADDR);
281
282 } else if (identifier_name == "duid") {
283 return (IDENT_DUID);
284
285 } else if (identifier_name == "circuit-id") {
286 return (IDENT_CIRCUIT_ID);
287
288 } else if (identifier_name == "client-id") {
289 return (IDENT_CLIENT_ID);
290 } else if (identifier_name == "flex-id") {
291 return (IDENT_FLEX);
292 } else {
293 isc_throw(isc::BadValue, "invalid client identifier type '"
294 << identifier_name << "'");
295 }
296}
297
300 return ((identifier_type_ == IDENT_HWADDR) ?
301 HWAddrPtr(new HWAddr(identifier_value_, HTYPE_ETHER)) : HWAddrPtr());
302}
303
306 return ((identifier_type_ == IDENT_DUID) ?
307 DuidPtr(new DUID(identifier_value_)) : DuidPtr());
308}
309
310
311std::string
313 return (getIdentifierAsText(identifier_type_, &identifier_value_[0],
314 identifier_value_.size()));
315}
316
317std::string
318Host::getIdentifierAsText(const IdentifierType& type, const uint8_t* value,
319 const size_t length) {
320 // Convert identifier into <type>=<value> form.
321 std::ostringstream s;
322 switch (type) {
323 case IDENT_HWADDR:
324 s << "hwaddr";
325 break;
326 case IDENT_DUID:
327 s << "duid";
328 break;
329 case IDENT_CIRCUIT_ID:
330 s << "circuit-id";
331 break;
332 case IDENT_CLIENT_ID:
333 s << "client-id";
334 break;
335 case IDENT_FLEX:
336 s << "flex-id";
337 break;
338 default:
339 // This should never happen actually, unless we add new identifier
340 // and forget to add a case for it above.
341 s << "(invalid-type)";
342 }
343 std::vector<uint8_t> vec(value, value + length);
344 s << "=" << (length > 0 ? util::encode::encodeHex(vec) : "(null)");
345 return (s.str());
346}
347
348std::string
350 switch (type) {
352 return ("hw-address");
353
354 case Host::IDENT_DUID:
355 return ("duid");
356
358 return ("circuit-id");
359
361 return ("client-id");
362
363 case Host::IDENT_FLEX:
364 return ("flex-id");
365
366 default:
367 ;
368 }
369 return ("(unknown)");
370}
371
372
373void
374Host::setIdentifier(const uint8_t* identifier, const size_t len,
375 const IdentifierType& type) {
376 if (len < 1) {
377 isc_throw(BadValue, "invalid client identifier length 0");
378 } else if (len > getIdentifierMaxLength(type)) {
379 isc_throw(BadValue, "too long client identifier type "
380 << getIdentifierName(type)
381 << " length " << len);
382 }
383
384 identifier_type_ = type;
385 identifier_value_.assign(identifier, identifier + len);
386}
387
388void
389Host::setIdentifier(const std::string& identifier, const std::string& name) {
390 // Empty identifier is not allowed.
391 if (identifier.empty()) {
392 isc_throw(isc::BadValue, "empty host identifier used");
393 }
394
395 // Set identifier type.
396 identifier_type_ = getIdentifierType(name);
397
398 // Identifier value can either be specified as string of hexadecimal
399 // digits or a string in quotes. The latter is copied to a vector excluding
400 // quote characters.
401
402 // Try to convert the values in quotes into a vector of ASCII codes.
403 // If the identifier lacks opening and closing quote, this will return
404 // an empty value, in which case we'll try to decode it as a string of
405 // hexadecimal digits.
406 bool too_long = false;
407 try {
408 std::vector<uint8_t> binary = util::str::quotedStringToBinary(identifier);
409 if (binary.empty()) {
410 util::str::decodeFormattedHexString(identifier, binary);
411 }
412
413 size_t len = binary.size();
414 if (len > getIdentifierMaxLength(identifier_type_)) {
415 // Message does not matter as it will be replaced below...
416 too_long = true;
417 isc_throw(BadValue, "too long client identifier type " << name
418 << " length " << len);
419 }
420
421 // Successfully decoded the identifier, so let's use it.
422 identifier_value_.swap(binary);
423
424 } catch (...) {
425 // The string doesn't match any known pattern, so we have to
426 // report an error at this point.
427 if (too_long) {
428 throw;
429 }
430 isc_throw(isc::BadValue, "invalid host identifier value '"
431 << identifier << "'");
432 }
433}
434
435void
437 identifier_type_ = type;
438}
439
440void
442 if (!address.isV4()) {
443 isc_throw(isc::BadValue, "address '" << address << "' is not a valid"
444 " IPv4 address");
445 } else if (address.isV4Zero() || address.isV4Bcast()) {
446 isc_throw(isc::BadValue, "must not make reservation for the '"
447 << address << "' address");
448 }
449 ipv4_reservation_ = address;
450}
451
452void
456
457void
458Host::addReservation(const IPv6Resrv& reservation) {
459 // Check if it is not duplicating existing reservation.
460 if (hasReservation(reservation)) {
461 isc_throw(isc::InvalidOperation, "failed on attempt to add a duplicated"
462 " host reservation for " << reservation.toText());
463 }
464 // Add it.
465 ipv6_reservations_.insert(IPv6ResrvTuple(reservation.getType(),
466 reservation));
467}
468
471 return (ipv6_reservations_.equal_range(type));
472}
473
476 return (IPv6ResrvRange(ipv6_reservations_.begin(),
477 ipv6_reservations_.end()));
478}
479
480bool
482 return (!ipv6_reservations_.empty());
483}
484
485bool
486Host::hasReservation(const IPv6Resrv& reservation) const {
487 IPv6ResrvRange reservations = getIPv6Reservations(reservation.getType());
488 if (std::distance(reservations.first, reservations.second) > 0) {
489 BOOST_FOREACH(auto const& it, reservations) {
490 if (it.second == reservation) {
491 return (true);
492 }
493 }
494 }
495
496 // No matching reservations found.
497 return (false);
498}
499
500void
501Host::addClientClass4(const std::string& class_name) {
502 addClientClassInternal(dhcp4_client_classes_, class_name);
503}
504
505
506void
507Host::addClientClass6(const std::string& class_name) {
508 addClientClassInternal(dhcp6_client_classes_, class_name);
509}
510
511void
512Host::addClientClassInternal(ClientClasses& classes,
513 const std::string& class_name) {
514 std::string trimmed = util::str::trim(class_name);
515 if (!trimmed.empty()) {
516 classes.insert(ClientClass(trimmed));
517 }
518}
519
520void
522 if (!next_server.isV4()) {
523 isc_throw(isc::BadValue, "next server address '" << next_server
524 << "' is not a valid IPv4 address");
525 } else if (next_server.isV4Bcast()) {
526 isc_throw(isc::BadValue, "invalid next server address '"
527 << next_server << "'");
528 }
529
530 next_server_ = next_server;
531}
532
533void
534Host::setServerHostname(const std::string& server_host_name) {
535 if (server_host_name.size() > Pkt4::MAX_SNAME_LEN - 1) {
536 isc_throw(isc::BadValue, "server hostname length must not exceed "
537 << (Pkt4::MAX_SNAME_LEN - 1));
538 }
539 server_host_name_ = server_host_name;
540}
541
542void
543Host::setBootFileName(const std::string& boot_file_name) {
544 if (boot_file_name.size() > Pkt4::MAX_FILE_LEN - 1) {
545 isc_throw(isc::BadValue, "boot file length must not exceed "
546 << (Pkt4::MAX_FILE_LEN - 1));
547 }
548 boot_file_name_ = boot_file_name;
549}
550
553
554 // Prepare the map
556 // Set the user context
557 contextToElement(map);
558 // Set the identifier
560 if (id_type == Host::IDENT_HWADDR) {
561 HWAddrPtr hwaddr = getHWAddress();
562 map->set("hw-address", Element::create(hwaddr->toText(false)));
563 } else if (id_type == Host::IDENT_DUID) {
564 DuidPtr duid = getDuid();
565 map->set("duid", Element::create(duid->toText()));
566 } else if (id_type == Host::IDENT_CIRCUIT_ID) {
567 const std::vector<uint8_t>& bin = getIdentifier();
568 std::string circuit_id = util::encode::encodeHex(bin);
569 map->set("circuit-id", Element::create(circuit_id));
570 } else if (id_type == Host::IDENT_CLIENT_ID) {
571 const std::vector<uint8_t>& bin = getIdentifier();
572 std::string client_id = util::encode::encodeHex(bin);
573 map->set("client-id", Element::create(client_id));
574 } else if (id_type == Host::IDENT_FLEX) {
575 const std::vector<uint8_t>& bin = getIdentifier();
576 std::string flex = util::encode::encodeHex(bin);
577 map->set("flex-id", Element::create(flex));
578 } else {
579 isc_throw(ToElementError, "invalid identifier type: " << id_type);
580 }
581 // Set the reservation (if not 0.0.0.0 which may not be re-read)
582 const IOAddress& address = getIPv4Reservation();
583 if (!address.isV4Zero()) {
584 map->set("ip-address", Element::create(address.toText()));
585 }
586 // Set the hostname
587 const std::string& hostname = getHostname();
588 map->set("hostname", Element::create(hostname));
589 // Set next-server
590 const IOAddress& next_server = getNextServer();
591 map->set("next-server", Element::create(next_server.toText()));
592 // Set server-hostname
593 const std::string& server_hostname = getServerHostname();
594 map->set("server-hostname", Element::create(server_hostname));
595 // Set boot-file-name
596 const std::string& boot_file_name = getBootFileName();
597 map->set("boot-file-name", Element::create(boot_file_name));
598 // Set client-classes
599 const ClientClasses& cclasses = getClientClasses4();
601 for (auto const& cclass : cclasses) {
602 classes->add(Element::create(cclass));
603 }
604 map->set("client-classes", classes);
605 // Set option-data
607 map->set("option-data", opts->toElement());
608
609 return (map);
610}
611
614 // Prepare the map
616 // Set the user context
617 contextToElement(map);
618 // Set the identifier
620 if (id_type == Host::IDENT_HWADDR) {
621 HWAddrPtr hwaddr = getHWAddress();
622 map->set("hw-address", Element::create(hwaddr->toText(false)));
623 } else if (id_type == Host::IDENT_DUID) {
624 DuidPtr duid = getDuid();
625 map->set("duid", Element::create(duid->toText()));
626 } else if (id_type == Host::IDENT_CIRCUIT_ID) {
627 isc_throw(ToElementError, "unexpected circuit-id DUID type");
628 } else if (id_type == Host::IDENT_CLIENT_ID) {
629 isc_throw(ToElementError, "unexpected client-id DUID type");
630 } else if (id_type == Host::IDENT_FLEX) {
631 const std::vector<uint8_t>& bin = getIdentifier();
632 std::string flex = util::encode::encodeHex(bin);
633 map->set("flex-id", Element::create(flex));
634 } else {
635 isc_throw(ToElementError, "invalid DUID type: " << id_type);
636 }
637 // Set reservations (ip-addresses)
640 BOOST_FOREACH(auto const& resv, na_resv) {
641 resvs->add(Element::create(resv.second.toText()));
642 }
643 map->set("ip-addresses", resvs);
644 // Set reservations (prefixes)
646 resvs = Element::createList();
647 bool has_pd_exclude_option(false);
648 BOOST_FOREACH(auto const& resv, pd_resv) {
649 if (resv.second.getPDExclude()) {
650 has_pd_exclude_option = true;
651 }
652 resvs->add(Element::create(resv.second.toText(false)));
653 }
654 map->set("prefixes", resvs);
655 // Set Prefix Exclude options.
656 if (has_pd_exclude_option) {
658 BOOST_FOREACH(auto const& resv, pd_resv) {
659 options->add(Element::create(resv.second.PDExcludetoText()));
660 }
661 map->set("excluded-prefixes", options);
662 }
663 // Set the hostname
664 const std::string& hostname = getHostname();
665 map->set("hostname", Element::create(hostname));
666 // Set client-classes
667 const ClientClasses& cclasses = getClientClasses6();
669 for (auto const& cclass : cclasses) {
670 classes->add(Element::create(cclass));
671 }
672 map->set("client-classes", classes);
673
674 // Set option-data
676 map->set("option-data", opts->toElement());
677
678 // Set auth key
679 //@todo: uncomment once storing in configuration file is enabled
680 //map->set("auth-key", Element::create(getKey().toText()));
681
682 return (map);
683}
684
685void
687 if (!cfg_option4_->isEncapsulated()) {
688 cfg_option4_->encapsulate();
689 }
690 if (!cfg_option6_->isEncapsulated()) {
691 cfg_option6_->encapsulate();
692 }
693}
694
695std::string
697 std::ostringstream s;
698
699 // Add HW address or DUID.
700 s << getIdentifierAsText();
701
702 // Add IPv4 subnet id if exists.
703 if (ipv4_subnet_id_ != SUBNET_ID_UNUSED) {
704 s << " ipv4_subnet_id=" << ipv4_subnet_id_;
705 }
706
707 // Add IPv6 subnet id if exists.
708 if (ipv6_subnet_id_ != SUBNET_ID_UNUSED) {
709 s << " ipv6_subnet_id=" << ipv6_subnet_id_;
710 }
711
712 // Add hostname.
713 s << " hostname=" << (hostname_.empty() ? "(empty)" : hostname_);
714
715 // Add IPv4 reservation.
716 s << " ipv4_reservation=" << (ipv4_reservation_.isV4Zero() ? "(no)" :
717 ipv4_reservation_.toText());
718
719 // Add next server.
720 s << " siaddr=" << (next_server_.isV4Zero() ? "(no)" :
721 next_server_.toText());
722
723 // Add server host name.
724 s << " sname=" << (server_host_name_.empty() ? "(empty)" : server_host_name_);
725
726 // Add boot file name.
727 s << " file=" << (boot_file_name_.empty() ? "(empty)" : boot_file_name_);
728
729 s << " key=" << (key_.toText().empty() ? "(empty)" : key_.toText());
730
731 size_t count = 0;
732
733 if (ipv6_reservations_.empty()) {
734 s << " ipv6_reservations=(none)";
735
736 } else {
737 // Add all IPv6 reservations.
738 count = 0;
739 for (auto const& resrv : ipv6_reservations_) {
740 s << " ipv6_reservation"
741 << count++
742 << "=" << resrv.second.toText();
743 }
744 }
745
746 // Add DHCPv4 client classes.
747 count = 0;
748 for (auto const& cclass : dhcp4_client_classes_) {
749 s << " dhcp4_class"
750 << count++
751 << "=" << cclass;
752 }
753
754 // Add DHCPv6 client classes.
755 count = 0;
756 for (auto const& cclass : dhcp6_client_classes_) {
757 s << " dhcp6_class"
758 << count++
759 << "=" << cclass;
760 }
761
762 // Add negative cached.
763 if (negative_) {
764 s << " negative cached";
765 }
766
767 return (s.str());
768}
769
770} // end of namespace isc::dhcp
771} // end of namespace isc
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
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.
Cannot unparse error.
static ElementPtr create(const Position &pos=ZERO_POSITION())
Definition data.cc:249
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
Definition data.cc:304
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
Definition data.cc:299
Authentication keys.
Definition host.h:76
AuthKey()
Constructor.
Definition host.cc:36
bool operator!=(const AuthKey &other) const
Inequality operator.
Definition host.cc:82
static std::vector< uint8_t > getRandomKeyString()
Random string is generated by default will be used for the keys to be used for signing Reconfigure Me...
Definition host.cc:41
std::string toText() const
Return text format for keys.
Definition host.cc:46
void setAuthKey(const std::vector< uint8_t > &key)
Set auth key value from binary.
Definition host.cc:54
bool operator==(const AuthKey &other) const
Equality operator.
Definition host.cc:77
Represents option data configuration for the DHCP server.
Definition cfg_option.h:352
Container for storing client class names.
Definition classify.h:108
static constexpr size_t MAX_CLIENT_ID_LEN
Maximum size of a client ID.
Definition duid.h:235
Holds DUID (DHCPv6 Unique Identifier)
Definition duid.h:142
static constexpr size_t MAX_DUID_LEN
maximum duid size
Definition duid.h:155
void addClientClass4(const std::string &class_name)
Adds new client class for DHCPv4.
Definition host.cc:501
void setServerHostname(const std::string &server_host_name)
Sets new value for server hostname (sname).
Definition host.cc:534
static size_t getIdentifierMaxLength(const IdentifierType &type)
Get maximum identifier length.
Definition host.cc:252
void encapsulateOptions() const
Encapsulates host-specific options with their suboptions.
Definition host.cc:686
const ClientClasses & getClientClasses6() const
Returns classes which DHCPv6 client is associated with.
Definition host.h:631
CfgOptionPtr getCfgOption4()
Returns pointer to the DHCPv4 option data configuration for this host.
Definition host.h:677
std::string toText() const
Returns information about the host in the textual format.
Definition host.cc:696
void addClientClass6(const std::string &class_name)
Adds new client class for DHCPv6.
Definition host.cc:507
IdentifierType
Type of the host identifier.
Definition host.h:337
@ IDENT_FLEX
Flexible host identifier.
Definition host.h:342
@ IDENT_CLIENT_ID
Definition host.h:341
@ IDENT_CIRCUIT_ID
Definition host.h:340
IdentifierType getIdentifierType() const
Returns the identifier type.
Definition host.cc:273
void setIdentifier(const uint8_t *identifier, const size_t len, const IdentifierType &type)
Replaces currently used identifier with a new identifier.
Definition host.cc:374
const asiolink::IOAddress & getIPv4Reservation() const
Returns reserved IPv4 address.
Definition host.h:562
void setIdentifierType(const IdentifierType &type)
Set the identifier type.
Definition host.cc:436
const std::string & getHostname() const
Returns reserved hostname.
Definition host.h:606
IPv6ResrvRange getIPv6Reservations() const
Returns all IPv6 reservations.
Definition host.cc:475
const std::string & getBootFileName() const
Returns value of boot file name (file).
Definition host.h:668
bool hasIPv6Reservation() const
Checks if there is at least one IPv6 reservation for this host.
Definition host.cc:481
Host(const uint8_t *identifier, const size_t identifier_len, const IdentifierType &identifier_type, const SubnetID ipv4_subnet_id, const SubnetID ipv6_subnet_id, const asiolink::IOAddress &ipv4_reservation, const std::string &hostname="", const std::string &dhcp4_client_classes="", const std::string &dhcp6_client_classes="", const asiolink::IOAddress &next_server=asiolink::IOAddress::IPV4_ZERO_ADDRESS(), const std::string &server_host_name="", const std::string &boot_file_name="", const AuthKey &auth_key=AuthKey(""))
Constructor.
Definition host.cc:177
const std::vector< uint8_t > & getIdentifier() const
Returns the identifier in a binary form.
Definition host.cc:268
isc::data::ElementPtr toElement6() const
Unparses (converts to Element representation) IPv6 host.
Definition host.cc:613
void addReservation(const IPv6Resrv &reservation)
Adds new IPv6 reservation.
Definition host.cc:458
const ClientClasses & getClientClasses4() const
Returns classes which DHCPv4 client is associated with.
Definition host.h:621
static std::string getIdentifierName(const IdentifierType &type)
Returns name of the identifier of a specified type.
Definition host.cc:349
const std::string & getServerHostname() const
Returns value of server hostname (sname).
Definition host.h:656
void setBootFileName(const std::string &boot_file_name)
Sets new value for boot file name (file).
Definition host.cc:543
void setNextServer(const asiolink::IOAddress &next_server)
Sets new value for next server field (siaddr).
Definition host.cc:521
CfgOptionPtr getCfgOption6()
Returns pointer to the DHCPv6 option data configuration for this host.
Definition host.h:692
bool hasReservation(const IPv6Resrv &reservation) const
Checks if specified IPv6 reservation exists for the host.
Definition host.cc:486
const asiolink::IOAddress & getNextServer() const
Returns value of next server field (siaddr).
Definition host.h:644
std::string getIdentifierAsText() const
Returns host identifier in a textual form.
Definition host.cc:312
isc::data::ElementPtr toElement4() const
Unparses (converts to Element representation) IPv4 host.
Definition host.cc:552
DuidPtr getDuid() const
Returns DUID for which the reservations are made.
Definition host.cc:305
void removeIPv4Reservation()
Removes the IPv4 reservation.
Definition host.cc:453
HWAddrPtr getHWAddress() const
Returns hardware address for which the reservations are made.
Definition host.cc:299
void setIPv4Reservation(const asiolink::IOAddress &address)
Sets new IPv4 reservation.
Definition host.cc:441
IPv6 reservation for a host.
Definition host.h:163
void set(const Type &type, const asiolink::IOAddress &prefix, const uint8_t prefix_len)
Sets a new prefix and prefix length.
Definition host.cc:96
std::string PDExcludetoText() const
Returns information about the Prefix Exclude option of the reservation the textual format.
Definition host.cc:152
Type
Type of the reservation.
Definition host.h:169
void setPDExclude(const asiolink::IOAddress &excluded_prefix, const uint8_t excluded_prefix_len)
Sets the Prefix Exclude option.
Definition host.cc:120
IPv6Resrv(const Type &type, const asiolink::IOAddress &prefix, const uint8_t prefix_len=128)
Constructor.
Definition host.cc:86
bool operator==(const IPv6Resrv &other) const
Equality operator.
Definition host.cc:166
std::string toText(bool display_pd_exclude_option=true) const
Returns information about the reservation in the textual format.
Definition host.cc:132
bool operator!=(const IPv6Resrv &other) const
Inequality operator.
Definition host.cc:173
DHCPv6 option class representing Prefix Exclude Option (RFC 6603).
static const size_t MAX_SNAME_LEN
length of the SNAME field in DHCPv4 message
Definition pkt4.h:44
static const size_t MAX_FILE_LEN
length of the FILE field in DHCPv4 message
Definition pkt4.h:47
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
std::string ClientClass
Defines a single class name.
Definition classify.h:42
boost::shared_ptr< DUID > DuidPtr
Definition duid.h:136
std::pair< IPv6ResrvIterator, IPv6ResrvIterator > IPv6ResrvRange
Definition host.h:273
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
Definition hwaddr.h:154
const uint8_t AUTH_KEY_LEN
Maximum length of authentication keys - 128 bits.
Definition host.h:64
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Definition subnet_id.h:25
std::pair< IPv6Resrv::Type, IPv6Resrv > IPv6ResrvTuple
Definition host.h:272
@ HTYPE_ETHER
Ethernet 10Mbps.
Definition dhcp4.h:56
boost::shared_ptr< const CfgOption > ConstCfgOptionPtr
Const pointer.
Definition cfg_option.h:806
void decodeHex(const string &encoded_str, vector< uint8_t > &output)
Decode a base16 encoded string into binary data.
Definition encode.cc:367
string encodeHex(const vector< uint8_t > &binary)
Encode binary data in the base16 format.
Definition encode.cc:361
void decodeFormattedHexString(const string &hex_string, vector< uint8_t > &binary)
Converts a formatted string of hexadecimal digits into a vector.
Definition str.cc:212
vector< uint8_t > quotedStringToBinary(const string &quoted_string)
Converts a string in quotes into vector.
Definition str.cc:139
string trim(const string &input)
Trim leading and trailing spaces.
Definition str.cc:32
Defines the logger used by the top-level component of kea-lfc.
void contextToElement(data::ElementPtr map) const
Merge unparse a user_context object.
Hardware type that represents information from DHCPv4 packet.
Definition hwaddr.h:20
static const size_t MAX_HWADDR_LEN
Maximum size of a hardware address.
Definition hwaddr.h:27