Kea 2.5.9
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
37 authKey_ = AuthKey::getRandomKeyString();
38}
39
40std::vector<uint8_t>
43}
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 // Validate and set the actual values.
91 set(type, prefix, prefix_len);
92}
93
94void
95IPv6Resrv::set(const Type& type, const asiolink::IOAddress& prefix,
96 const uint8_t prefix_len) {
97 if (!prefix.isV6() || prefix.isV6Multicast()) {
98 isc_throw(isc::BadValue, "invalid prefix '" << prefix
99 << "' for new IPv6 reservation");
100
101 } else if (prefix_len > 128) {
102 isc_throw(isc::BadValue, "invalid prefix length '"
103 << static_cast<int>(prefix_len)
104 << "' for new IPv6 reservation");
105
106 } else if ((type == TYPE_NA) && (prefix_len != 128)) {
107 isc_throw(isc::BadValue, "invalid prefix length '"
108 << static_cast<int>(prefix_len)
109 << "' for reserved IPv6 address, expected 128");
110 }
111
112 type_ = type;
113 prefix_ = prefix;
114 prefix_len_ = prefix_len;
115}
116
117std::string
119 std::ostringstream s;
120 s << prefix_;
121 // For PD, append prefix length.
122 if (getType() == TYPE_PD) {
123 s << "/" << static_cast<int>(prefix_len_);
124 }
125 return (s.str());
126}
127
128bool
129IPv6Resrv::operator==(const IPv6Resrv& other) const {
130 return (type_ == other.type_ &&
131 prefix_ == other.prefix_ &&
132 prefix_len_ == other.prefix_len_);
133}
134
135bool
136IPv6Resrv::operator!=(const IPv6Resrv& other) const {
137 return (!operator==(other));
138}
139
140Host::Host(const uint8_t* identifier, const size_t identifier_len,
141 const IdentifierType& identifier_type,
142 const SubnetID ipv4_subnet_id, const SubnetID ipv6_subnet_id,
143 const asiolink::IOAddress& ipv4_reservation,
144 const std::string& hostname,
145 const std::string& dhcp4_client_classes,
146 const std::string& dhcp6_client_classes,
147 const asiolink::IOAddress& next_server,
148 const std::string& server_host_name,
149 const std::string& boot_file_name,
150 const AuthKey& auth_key)
151
152 : identifier_type_(identifier_type),
153 identifier_value_(), ipv4_subnet_id_(ipv4_subnet_id),
154 ipv6_subnet_id_(ipv6_subnet_id),
155 ipv4_reservation_(asiolink::IOAddress::IPV4_ZERO_ADDRESS()),
156 hostname_(hostname), dhcp4_client_classes_(dhcp4_client_classes),
157 dhcp6_client_classes_(dhcp6_client_classes),
158 next_server_(asiolink::IOAddress::IPV4_ZERO_ADDRESS()),
159 server_host_name_(server_host_name), boot_file_name_(boot_file_name),
160 host_id_(0), cfg_option4_(new CfgOption()),
161 cfg_option6_(new CfgOption()), negative_(false),
162 key_(auth_key) {
163
164 // Initialize host identifier.
165 setIdentifier(identifier, identifier_len, identifier_type);
166
167 if (!ipv4_reservation.isV4Zero()) {
168 // Validate and set IPv4 address reservation.
169 setIPv4Reservation(ipv4_reservation);
170 }
171
172 if (!next_server.isV4Zero()) {
173 // Validate and set next server address.
174 setNextServer(next_server);
175 }
176}
177
178Host::Host(const std::string& identifier, const std::string& identifier_name,
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 : identifier_type_(IDENT_HWADDR),
189 identifier_value_(), ipv4_subnet_id_(ipv4_subnet_id),
190 ipv6_subnet_id_(ipv6_subnet_id),
191 ipv4_reservation_(asiolink::IOAddress::IPV4_ZERO_ADDRESS()),
192 hostname_(hostname), dhcp4_client_classes_(dhcp4_client_classes),
193 dhcp6_client_classes_(dhcp6_client_classes),
194 next_server_(asiolink::IOAddress::IPV4_ZERO_ADDRESS()),
195 server_host_name_(server_host_name), boot_file_name_(boot_file_name),
196 host_id_(0), cfg_option4_(new CfgOption()),
197 cfg_option6_(new CfgOption()), negative_(false),
198 key_(auth_key) {
199
200 // Initialize host identifier.
201 setIdentifier(identifier, identifier_name);
202
203 if (!ipv4_reservation.isV4Zero()) {
204 // Validate and set IPv4 address reservation.
205 setIPv4Reservation(ipv4_reservation);
206 }
207
208 if (!next_server.isV4Zero()) {
209 // Validate and set next server address.
210 setNextServer(next_server);
211 }
212}
213
214size_t
216 switch (type) {
217 case IDENT_HWADDR:
218 return (HWAddr::MAX_HWADDR_LEN);
219 case IDENT_DUID:
220 return (DUID::MAX_DUID_LEN);
221 case IDENT_CLIENT_ID:
223 default:
224 // In fact it is backend dependent but for compatibility we take
225 // the lowest value.
226 return (128);
227 }
228}
229
230const std::vector<uint8_t>&
232 return (identifier_value_);
233}
234
237 return (identifier_type_);
238}
239
241Host::getIdentifierType(const std::string& identifier_name) {
242 if (identifier_name == "hw-address") {
243 return (IDENT_HWADDR);
244
245 } else if (identifier_name == "duid") {
246 return (IDENT_DUID);
247
248 } else if (identifier_name == "circuit-id") {
249 return (IDENT_CIRCUIT_ID);
250
251 } else if (identifier_name == "client-id") {
252 return (IDENT_CLIENT_ID);
253 } else if (identifier_name == "flex-id") {
254 return (IDENT_FLEX);
255 } else {
256 isc_throw(isc::BadValue, "invalid client identifier type '"
257 << identifier_name << "'");
258 }
259}
260
263 return ((identifier_type_ == IDENT_HWADDR) ?
264 HWAddrPtr(new HWAddr(identifier_value_, HTYPE_ETHER)) : HWAddrPtr());
265}
266
269 return ((identifier_type_ == IDENT_DUID) ?
270 DuidPtr(new DUID(identifier_value_)) : DuidPtr());
271}
272
273
274std::string
276 return (getIdentifierAsText(identifier_type_, &identifier_value_[0],
277 identifier_value_.size()));
278}
279
280std::string
281Host::getIdentifierAsText(const IdentifierType& type, const uint8_t* value,
282 const size_t length) {
283 // Convert identifier into <type>=<value> form.
284 std::ostringstream s;
285 switch (type) {
286 case IDENT_HWADDR:
287 s << "hwaddr";
288 break;
289 case IDENT_DUID:
290 s << "duid";
291 break;
292 case IDENT_CIRCUIT_ID:
293 s << "circuit-id";
294 break;
295 case IDENT_CLIENT_ID:
296 s << "client-id";
297 break;
298 case IDENT_FLEX:
299 s << "flex-id";
300 break;
301 default:
302 // This should never happen actually, unless we add new identifier
303 // and forget to add a case for it above.
304 s << "(invalid-type)";
305 }
306 std::vector<uint8_t> vec(value, value + length);
307 s << "=" << (length > 0 ? util::encode::encodeHex(vec) : "(null)");
308 return (s.str());
309}
310
311std::string
313 switch (type) {
315 return ("hw-address");
316
317 case Host::IDENT_DUID:
318 return ("duid");
319
321 return ("circuit-id");
322
324 return ("client-id");
325
326 case Host::IDENT_FLEX:
327 return ("flex-id");
328
329 default:
330 ;
331 }
332 return ("(unknown)");
333}
334
335
336void
337Host::setIdentifier(const uint8_t* identifier, const size_t len,
338 const IdentifierType& type) {
339 if (len < 1) {
340 isc_throw(BadValue, "invalid client identifier length 0");
341 } else if (len > getIdentifierMaxLength(type)) {
342 isc_throw(BadValue, "too long client identifier type "
343 << getIdentifierName(type)
344 << " length " << len);
345 }
346
347 identifier_type_ = type;
348 identifier_value_.assign(identifier, identifier + len);
349}
350
351void
352Host::setIdentifier(const std::string& identifier, const std::string& name) {
353 // Empty identifier is not allowed.
354 if (identifier.empty()) {
355 isc_throw(isc::BadValue, "empty host identifier used");
356 }
357
358 // Set identifier type.
359 identifier_type_ = getIdentifierType(name);
360
361 // Identifier value can either be specified as string of hexadecimal
362 // digits or a string in quotes. The latter is copied to a vector excluding
363 // quote characters.
364
365 // Try to convert the values in quotes into a vector of ASCII codes.
366 // If the identifier lacks opening and closing quote, this will return
367 // an empty value, in which case we'll try to decode it as a string of
368 // hexadecimal digits.
369 bool too_long = false;
370 try {
371 std::vector<uint8_t> binary = util::str::quotedStringToBinary(identifier);
372 if (binary.empty()) {
373 util::str::decodeFormattedHexString(identifier, binary);
374 }
375
376 size_t len = binary.size();
377 if (len > getIdentifierMaxLength(identifier_type_)) {
378 // Message does not matter as it will be replaced below...
379 too_long = true;
380 isc_throw(BadValue, "too long client identifier type " << name
381 << " length " << len);
382 }
383
384 // Successfully decoded the identifier, so let's use it.
385 identifier_value_.swap(binary);
386
387 } catch (...) {
388 // The string doesn't match any known pattern, so we have to
389 // report an error at this point.
390 if (too_long) {
391 throw;
392 }
393 isc_throw(isc::BadValue, "invalid host identifier value '"
394 << identifier << "'");
395 }
396}
397
398void
400 identifier_type_ = type;
401}
402
403void
405 if (!address.isV4()) {
406 isc_throw(isc::BadValue, "address '" << address << "' is not a valid"
407 " IPv4 address");
408 } else if (address.isV4Zero() || address.isV4Bcast()) {
409 isc_throw(isc::BadValue, "must not make reservation for the '"
410 << address << "' address");
411 }
412 ipv4_reservation_ = address;
413}
414
415void
417 ipv4_reservation_ = asiolink::IOAddress::IPV4_ZERO_ADDRESS();
418}
419
420void
421Host::addReservation(const IPv6Resrv& reservation) {
422 // Check if it is not duplicating existing reservation.
423 if (hasReservation(reservation)) {
424 isc_throw(isc::InvalidOperation, "failed on attempt to add a duplicated"
425 " host reservation for " << reservation.toText());
426 }
427 // Add it.
428 ipv6_reservations_.insert(IPv6ResrvTuple(reservation.getType(),
429 reservation));
430}
431
434 return (ipv6_reservations_.equal_range(type));
435}
436
439 return (IPv6ResrvRange(ipv6_reservations_.begin(),
440 ipv6_reservations_.end()));
441}
442
443bool
445 return (!ipv6_reservations_.empty());
446}
447
448bool
449Host::hasReservation(const IPv6Resrv& reservation) const {
450 IPv6ResrvRange reservations = getIPv6Reservations(reservation.getType());
451 if (std::distance(reservations.first, reservations.second) > 0) {
452 BOOST_FOREACH(auto const& it, reservations) {
453 if (it.second == reservation) {
454 return (true);
455 }
456 }
457 }
458
459 // No matching reservations found.
460 return (false);
461}
462
463void
464Host::addClientClass4(const std::string& class_name) {
465 addClientClassInternal(dhcp4_client_classes_, class_name);
466}
467
468
469void
470Host::addClientClass6(const std::string& class_name) {
471 addClientClassInternal(dhcp6_client_classes_, class_name);
472}
473
474void
475Host::addClientClassInternal(ClientClasses& classes,
476 const std::string& class_name) {
477 std::string trimmed = util::str::trim(class_name);
478 if (!trimmed.empty()) {
479 classes.insert(ClientClass(trimmed));
480 }
481}
482
483void
485 if (!next_server.isV4()) {
486 isc_throw(isc::BadValue, "next server address '" << next_server
487 << "' is not a valid IPv4 address");
488 } else if (next_server.isV4Bcast()) {
489 isc_throw(isc::BadValue, "invalid next server address '"
490 << next_server << "'");
491 }
492
493 next_server_ = next_server;
494}
495
496void
497Host::setServerHostname(const std::string& server_host_name) {
498 if (server_host_name.size() > Pkt4::MAX_SNAME_LEN - 1) {
499 isc_throw(isc::BadValue, "server hostname length must not exceed "
500 << (Pkt4::MAX_SNAME_LEN - 1));
501 }
502 server_host_name_ = server_host_name;
503}
504
505void
506Host::setBootFileName(const std::string& boot_file_name) {
507 if (boot_file_name.size() > Pkt4::MAX_FILE_LEN - 1) {
508 isc_throw(isc::BadValue, "boot file length must not exceed "
509 << (Pkt4::MAX_FILE_LEN - 1));
510 }
511 boot_file_name_ = boot_file_name;
512}
513
516
517 // Prepare the map
519 // Set the user context
520 contextToElement(map);
521 // Set the identifier
523 if (id_type == Host::IDENT_HWADDR) {
524 HWAddrPtr hwaddr = getHWAddress();
525 map->set("hw-address", Element::create(hwaddr->toText(false)));
526 } else if (id_type == Host::IDENT_DUID) {
527 DuidPtr duid = getDuid();
528 map->set("duid", Element::create(duid->toText()));
529 } else if (id_type == Host::IDENT_CIRCUIT_ID) {
530 const std::vector<uint8_t>& bin = getIdentifier();
531 std::string circuit_id = util::encode::encodeHex(bin);
532 map->set("circuit-id", Element::create(circuit_id));
533 } else if (id_type == Host::IDENT_CLIENT_ID) {
534 const std::vector<uint8_t>& bin = getIdentifier();
535 std::string client_id = util::encode::encodeHex(bin);
536 map->set("client-id", Element::create(client_id));
537 } else if (id_type == Host::IDENT_FLEX) {
538 const std::vector<uint8_t>& bin = getIdentifier();
539 std::string flex = util::encode::encodeHex(bin);
540 map->set("flex-id", Element::create(flex));
541 } else {
542 isc_throw(ToElementError, "invalid identifier type: " << id_type);
543 }
544 // Set the reservation (if not 0.0.0.0 which may not be re-read)
545 const IOAddress& address = getIPv4Reservation();
546 if (!address.isV4Zero()) {
547 map->set("ip-address", Element::create(address.toText()));
548 }
549 // Set the hostname
550 const std::string& hostname = getHostname();
551 map->set("hostname", Element::create(hostname));
552 // Set next-server
553 const IOAddress& next_server = getNextServer();
554 map->set("next-server", Element::create(next_server.toText()));
555 // Set server-hostname
556 const std::string& server_hostname = getServerHostname();
557 map->set("server-hostname", Element::create(server_hostname));
558 // Set boot-file-name
559 const std::string& boot_file_name = getBootFileName();
560 map->set("boot-file-name", Element::create(boot_file_name));
561 // Set client-classes
562 const ClientClasses& cclasses = getClientClasses4();
564 for (auto const& cclass : cclasses) {
565 classes->add(Element::create(cclass));
566 }
567 map->set("client-classes", classes);
568 // Set option-data
570 map->set("option-data", opts->toElement());
571
572 return (map);
573}
574
577 // Prepare the map
579 // Set the user context
580 contextToElement(map);
581 // Set the identifier
583 if (id_type == Host::IDENT_HWADDR) {
584 HWAddrPtr hwaddr = getHWAddress();
585 map->set("hw-address", Element::create(hwaddr->toText(false)));
586 } else if (id_type == Host::IDENT_DUID) {
587 DuidPtr duid = getDuid();
588 map->set("duid", Element::create(duid->toText()));
589 } else if (id_type == Host::IDENT_CIRCUIT_ID) {
590 isc_throw(ToElementError, "unexpected circuit-id DUID type");
591 } else if (id_type == Host::IDENT_CLIENT_ID) {
592 isc_throw(ToElementError, "unexpected client-id DUID type");
593 } else if (id_type == Host::IDENT_FLEX) {
594 const std::vector<uint8_t>& bin = getIdentifier();
595 std::string flex = util::encode::encodeHex(bin);
596 map->set("flex-id", Element::create(flex));
597 } else {
598 isc_throw(ToElementError, "invalid DUID type: " << id_type);
599 }
600 // Set reservations (ip-addresses)
603 BOOST_FOREACH(auto const& resv, na_resv) {
604 resvs->add(Element::create(resv.second.toText()));
605 }
606 map->set("ip-addresses", resvs);
607 // Set reservations (prefixes)
609 resvs = Element::createList();
610 BOOST_FOREACH(auto const& resv, pd_resv) {
611 resvs->add(Element::create(resv.second.toText()));
612 }
613 map->set("prefixes", resvs);
614 // Set the hostname
615 const std::string& hostname = getHostname();
616 map->set("hostname", Element::create(hostname));
617 // Set client-classes
618 const ClientClasses& cclasses = getClientClasses6();
620 for (auto const& cclass : cclasses) {
621 classes->add(Element::create(cclass));
622 }
623 map->set("client-classes", classes);
624
625 // Set option-data
627 map->set("option-data", opts->toElement());
628
629 // Set auth key
630 //@todo: uncomment once storing in configuration file is enabled
631 //map->set("auth-key", Element::create(getKey().toText()));
632
633 return (map);
634}
635
636void
638 if (!cfg_option4_->isEncapsulated()) {
639 cfg_option4_->encapsulate();
640 }
641 if (!cfg_option6_->isEncapsulated()) {
642 cfg_option6_->encapsulate();
643 }
644}
645
646std::string
648 std::ostringstream s;
649
650 // Add HW address or DUID.
651 s << getIdentifierAsText();
652
653 // Add IPv4 subnet id if exists.
654 if (ipv4_subnet_id_ != SUBNET_ID_UNUSED) {
655 s << " ipv4_subnet_id=" << ipv4_subnet_id_;
656 }
657
658 // Add IPv6 subnet id if exists.
659 if (ipv6_subnet_id_ != SUBNET_ID_UNUSED) {
660 s << " ipv6_subnet_id=" << ipv6_subnet_id_;
661 }
662
663 // Add hostname.
664 s << " hostname=" << (hostname_.empty() ? "(empty)" : hostname_);
665
666 // Add IPv4 reservation.
667 s << " ipv4_reservation=" << (ipv4_reservation_.isV4Zero() ? "(no)" :
668 ipv4_reservation_.toText());
669
670 // Add next server.
671 s << " siaddr=" << (next_server_.isV4Zero() ? "(no)" :
672 next_server_.toText());
673
674 // Add server host name.
675 s << " sname=" << (server_host_name_.empty() ? "(empty)" : server_host_name_);
676
677 // Add boot file name.
678 s << " file=" << (boot_file_name_.empty() ? "(empty)" : boot_file_name_);
679
680 s << " key=" << (key_.toText().empty() ? "(empty)" : key_.toText());
681
682 size_t count = 0;
683
684 if (ipv6_reservations_.empty()) {
685 s << " ipv6_reservations=(none)";
686
687 } else {
688 // Add all IPv6 reservations.
689 count = 0;
690 for (auto const& resrv : ipv6_reservations_) {
691 s << " ipv6_reservation"
692 << count++
693 << "=" << resrv.second.toText();
694 }
695 }
696
697 // Add DHCPv4 client classes.
698 count = 0;
699 for (auto const& cclass : dhcp4_client_classes_) {
700 s << " dhcp4_class"
701 << count++
702 << "=" << cclass;
703 }
704
705 // Add DHCPv6 client classes.
706 count = 0;
707 for (auto const& cclass : dhcp6_client_classes_) {
708 s << " dhcp6_class"
709 << count++
710 << "=" << cclass;
711 }
712
713 // Add negative cached.
714 if (negative_) {
715 s << " negative cached";
716 }
717
718 return (s.str());
719}
720
721} // end of namespace isc::dhcp
722} // 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:75
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
void insert(const ClientClass &class_name)
Insert an element.
Definition: classify.h:128
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:464
void setServerHostname(const std::string &server_host_name)
Sets new value for server hostname (sname).
Definition: host.cc:497
static size_t getIdentifierMaxLength(const IdentifierType &type)
Get maximum identifier length.
Definition: host.cc:215
void encapsulateOptions() const
Encapsulates host-specific options with their suboptions.
Definition: host.cc:637
const ClientClasses & getClientClasses6() const
Returns classes which DHCPv6 client is associated with.
Definition: host.h:601
CfgOptionPtr getCfgOption4()
Returns pointer to the DHCPv4 option data configuration for this host.
Definition: host.h:647
std::string toText() const
Returns information about the host in the textual format.
Definition: host.cc:647
void addClientClass6(const std::string &class_name)
Adds new client class for DHCPv6.
Definition: host.cc:470
IdentifierType
Type of the host identifier.
Definition: host.h:307
@ IDENT_HWADDR
Definition: host.h:308
@ IDENT_FLEX
Flexible host identifier.
Definition: host.h:312
@ IDENT_CLIENT_ID
Definition: host.h:311
@ IDENT_CIRCUIT_ID
Definition: host.h:310
IdentifierType getIdentifierType() const
Returns the identifier type.
Definition: host.cc:236
void setIdentifier(const uint8_t *identifier, const size_t len, const IdentifierType &type)
Replaces currently used identifier with a new identifier.
Definition: host.cc:337
const asiolink::IOAddress & getIPv4Reservation() const
Returns reserved IPv4 address.
Definition: host.h:532
void setIdentifierType(const IdentifierType &type)
Set the identifier type.
Definition: host.cc:399
const std::string & getHostname() const
Returns reserved hostname.
Definition: host.h:576
IPv6ResrvRange getIPv6Reservations() const
Returns all IPv6 reservations.
Definition: host.cc:438
const std::string & getBootFileName() const
Returns value of boot file name (file).
Definition: host.h:638
bool hasIPv6Reservation() const
Checks if there is at least one IPv6 reservation for this host.
Definition: host.cc:444
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:140
const std::vector< uint8_t > & getIdentifier() const
Returns the identifier in a binary form.
Definition: host.cc:231
isc::data::ElementPtr toElement6() const
Unparses (converts to Element representation) IPv6 host.
Definition: host.cc:576
void addReservation(const IPv6Resrv &reservation)
Adds new IPv6 reservation.
Definition: host.cc:421
const ClientClasses & getClientClasses4() const
Returns classes which DHCPv4 client is associated with.
Definition: host.h:591
static std::string getIdentifierName(const IdentifierType &type)
Returns name of the identifier of a specified type.
Definition: host.cc:312
const std::string & getServerHostname() const
Returns value of server hostname (sname).
Definition: host.h:626
void setBootFileName(const std::string &boot_file_name)
Sets new value for boot file name (file).
Definition: host.cc:506
void setNextServer(const asiolink::IOAddress &next_server)
Sets new value for next server field (siaddr).
Definition: host.cc:484
CfgOptionPtr getCfgOption6()
Returns pointer to the DHCPv6 option data configuration for this host.
Definition: host.h:662
bool hasReservation(const IPv6Resrv &reservation) const
Checks if specified IPv6 reservation exists for the host.
Definition: host.cc:449
const asiolink::IOAddress & getNextServer() const
Returns value of next server field (siaddr).
Definition: host.h:614
std::string getIdentifierAsText() const
Returns host identifier in a textual form.
Definition: host.cc:275
isc::data::ElementPtr toElement4() const
Unparses (converts to Element representation) IPv4 host.
Definition: host.cc:515
DuidPtr getDuid() const
Returns DUID for which the reservations are made.
Definition: host.cc:268
void removeIPv4Reservation()
Removes the IPv4 reservation.
Definition: host.cc:416
HWAddrPtr getHWAddress() const
Returns hardware address for which the reservations are made.
Definition: host.cc:262
void setIPv4Reservation(const asiolink::IOAddress &address)
Sets new IPv4 reservation.
Definition: host.cc:404
IPv6 reservation for a host.
Definition: host.h:161
void set(const Type &type, const asiolink::IOAddress &prefix, const uint8_t prefix_len)
Sets a new prefix and prefix length.
Definition: host.cc:95
Type getType() const
Returns reservation type.
Definition: host.h:204
Type
Type of the reservation.
Definition: host.h:167
std::string toText() const
Returns information about the reservation in the textual format.
Definition: host.cc:118
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:129
bool operator!=(const IPv6Resrv &other) const
Inequality operator.
Definition: host.cc:136
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:243
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:63
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Definition: subnet_id.h:25
std::pair< IPv6Resrv::Type, IPv6Resrv > IPv6ResrvTuple
Definition: host.h:242
@ 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.
Definition: user_context.cc:15
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