Kea 1.5.0
host.cc
Go to the documentation of this file.
1// Copyright (C) 2014-2018 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
9#include <dhcp/pkt4.h>
10#include <dhcpsrv/host.h>
11#include <util/encode/hex.h>
12#include <util/strutil.h>
13#include <asiolink/io_address.h>
16
17#include <sstream>
18
19using namespace isc::data;
20using namespace isc::asiolink;
21
22namespace isc {
23namespace dhcp {
24
25AuthKey::AuthKey(const std::string key) {
26 setAuthKey(key);
27}
28
30 authKey_ = AuthKey::getRandomKeyString();
31}
32
33std::string
35 std::vector<uint8_t> rs = isc::cryptolink::random(AuthKey::KEY_LEN);
36 std::string result;
37 result.resize(rs.size());
38 memmove(&result[0], &rs[0], result.size());
39 return (result);
40}
41
42std::string
44 // this will need enhancement if the stored container is not a string
45 return (authKey_);
46}
47
48void
49AuthKey::setAuthKey(const std::string& key) {
50 authKey_ = key;
51 if (authKey_.size() > AuthKey::KEY_LEN) {
52 authKey_.resize(AuthKey::KEY_LEN);
53 }
54}
55
56bool
57AuthKey::operator==(const AuthKey& other) const {
58 return (authKey_ == other.authKey_);
59}
60
61bool
62AuthKey::operator!=(const AuthKey& other) const {
63 return (authKey_ != other.authKey_);
64}
65
67 const asiolink::IOAddress& prefix,
68 const uint8_t prefix_len)
69 : type_(type), prefix_(asiolink::IOAddress("::")), prefix_len_(128) {
70 // Validate and set the actual values.
71 set(type, prefix, prefix_len);
72}
73
74void
75IPv6Resrv::set(const Type& type, const asiolink::IOAddress& prefix,
76 const uint8_t prefix_len) {
77 if (!prefix.isV6() || prefix.isV6Multicast()) {
78 isc_throw(isc::BadValue, "invalid prefix '" << prefix
79 << "' for new IPv6 reservation");
80
81 } else if (prefix_len > 128) {
82 isc_throw(isc::BadValue, "invalid prefix length '"
83 << static_cast<int>(prefix_len)
84 << "' for new IPv6 reservation");
85
86 } else if ((type == TYPE_NA) && (prefix_len != 128)) {
87 isc_throw(isc::BadValue, "invalid prefix length '"
88 << static_cast<int>(prefix_len)
89 << "' for reserved IPv6 address, expected 128");
90 }
91
92 type_ = type;
93 prefix_ = prefix;
94 prefix_len_ = prefix_len;
95}
96
97std::string
99 std::ostringstream s;
100 s << prefix_;
101 // For PD, append prefix length.
102 if (getType() == TYPE_PD) {
103 s << "/" << static_cast<int>(prefix_len_);
104 }
105 return (s.str());
106}
107
108bool
109IPv6Resrv::operator==(const IPv6Resrv& other) const {
110 return (type_ == other.type_ &&
111 prefix_ == other.prefix_ &&
112 prefix_len_ == other.prefix_len_);
113}
114
115bool
116IPv6Resrv::operator!=(const IPv6Resrv& other) const {
117 return (!operator==(other));
118}
119
120Host::Host(const uint8_t* identifier, const size_t identifier_len,
121 const IdentifierType& identifier_type,
122 const SubnetID ipv4_subnet_id, const SubnetID ipv6_subnet_id,
123 const asiolink::IOAddress& ipv4_reservation,
124 const std::string& hostname,
125 const std::string& dhcp4_client_classes,
126 const std::string& dhcp6_client_classes,
127 const asiolink::IOAddress& next_server,
128 const std::string& server_host_name,
129 const std::string& boot_file_name,
130 const AuthKey& auth_key)
131
132 : identifier_type_(identifier_type),
133 identifier_value_(), ipv4_subnet_id_(ipv4_subnet_id),
134 ipv6_subnet_id_(ipv6_subnet_id),
135 ipv4_reservation_(asiolink::IOAddress::IPV4_ZERO_ADDRESS()),
136 hostname_(hostname), dhcp4_client_classes_(dhcp4_client_classes),
137 dhcp6_client_classes_(dhcp6_client_classes),
138 next_server_(asiolink::IOAddress::IPV4_ZERO_ADDRESS()),
139 server_host_name_(server_host_name), boot_file_name_(boot_file_name),
140 host_id_(0), cfg_option4_(new CfgOption()),
141 cfg_option6_(new CfgOption()), negative_(false),
142 key_(auth_key) {
143
144 // Initialize host identifier.
145 setIdentifier(identifier, identifier_len, identifier_type);
146
147 if (!ipv4_reservation.isV4Zero()) {
148 // Validate and set IPv4 address reservation.
149 setIPv4Reservation(ipv4_reservation);
150 }
151
152 if (!next_server.isV4Zero()) {
153 // Validate and set next server address.
154 setNextServer(next_server);
155 }
156}
157
158Host::Host(const std::string& identifier, const std::string& identifier_name,
159 const SubnetID ipv4_subnet_id, const SubnetID ipv6_subnet_id,
160 const asiolink::IOAddress& ipv4_reservation,
161 const std::string& hostname,
162 const std::string& dhcp4_client_classes,
163 const std::string& dhcp6_client_classes,
164 const asiolink::IOAddress& next_server,
165 const std::string& server_host_name,
166 const std::string& boot_file_name,
167 const AuthKey& auth_key)
168 : identifier_type_(IDENT_HWADDR),
169 identifier_value_(), ipv4_subnet_id_(ipv4_subnet_id),
170 ipv6_subnet_id_(ipv6_subnet_id),
171 ipv4_reservation_(asiolink::IOAddress::IPV4_ZERO_ADDRESS()),
172 hostname_(hostname), dhcp4_client_classes_(dhcp4_client_classes),
173 dhcp6_client_classes_(dhcp6_client_classes),
174 next_server_(asiolink::IOAddress::IPV4_ZERO_ADDRESS()),
175 server_host_name_(server_host_name), boot_file_name_(boot_file_name),
176 host_id_(0), cfg_option4_(new CfgOption()),
177 cfg_option6_(new CfgOption()), negative_(false),
178 key_(auth_key) {
179
180 // Initialize host identifier.
181 setIdentifier(identifier, identifier_name);
182
183 if (!ipv4_reservation.isV4Zero()) {
184 // Validate and set IPv4 address reservation.
185 setIPv4Reservation(ipv4_reservation);
186 }
187
188 if (!next_server.isV4Zero()) {
189 // Validate and set next server address.
190 setNextServer(next_server);
191 }
192}
193
194const std::vector<uint8_t>&
196 return (identifier_value_);
197}
198
201 return (identifier_type_);
202}
203
205Host::getIdentifierType(const std::string& identifier_name) {
206 if (identifier_name == "hw-address") {
207 return (IDENT_HWADDR);
208
209 } else if (identifier_name == "duid") {
210 return (IDENT_DUID);
211
212 } else if (identifier_name == "circuit-id") {
213 return (IDENT_CIRCUIT_ID);
214
215 } else if (identifier_name == "client-id") {
216 return (IDENT_CLIENT_ID);
217 } else if (identifier_name == "flex-id") {
218 return (IDENT_FLEX);
219 } else {
220 isc_throw(isc::BadValue, "invalid client identifier type '"
221 << identifier_name << "'");
222 }
223}
224
227 return ((identifier_type_ == IDENT_HWADDR) ?
228 HWAddrPtr(new HWAddr(identifier_value_, HTYPE_ETHER)) : HWAddrPtr());
229}
230
233 return ((identifier_type_ == IDENT_DUID) ?
234 DuidPtr(new DUID(identifier_value_)) : DuidPtr());
235}
236
237
238std::string
240 return (getIdentifierAsText(identifier_type_, &identifier_value_[0],
241 identifier_value_.size()));
242}
243
244std::string
245Host::getIdentifierAsText(const IdentifierType& type, const uint8_t* value,
246 const size_t length) {
247 // Convert identifier into <type>=<value> form.
248 std::ostringstream s;
249 switch (type) {
250 case IDENT_HWADDR:
251 s << "hwaddr";
252 break;
253 case IDENT_DUID:
254 s << "duid";
255 break;
256 case IDENT_CIRCUIT_ID:
257 s << "circuit-id";
258 break;
259 case IDENT_CLIENT_ID:
260 s << "client-id";
261 break;
262 case IDENT_FLEX:
263 s << "flex-id";
264 break;
265 default:
266 // This should never happen actually, unless we add new identifier
267 // and forget to add a case for it above.
268 s << "(invalid-type)";
269 }
270 std::vector<uint8_t> vec(value, value + length);
271 s << "=" << (length > 0 ? util::encode::encodeHex(vec) : "(null)");
272 return (s.str());
273}
274
275std::string
277 switch (type) {
279 return ("hw-address");
280
281 case Host::IDENT_DUID:
282 return ("duid");
283
285 return ("circuit-id");
286
288 return ("client-id");
289
290 case Host::IDENT_FLEX:
291 return ("flex-id");
292
293 default:
294 ;
295 }
296 return ("(unknown)");
297}
298
299
300void
301Host::setIdentifier(const uint8_t* identifier, const size_t len,
302 const IdentifierType& type) {
303 if (len < 1) {
304 isc_throw(BadValue, "invalid client identifier length 0");
305 }
306
307 identifier_type_ = type;
308 identifier_value_.assign(identifier, identifier + len);
309}
310
311void
312Host::setIdentifier(const std::string& identifier, const std::string& name) {
313 // Empty identifier is not allowed.
314 if (identifier.empty()) {
315 isc_throw(isc::BadValue, "empty host identifier used");
316 }
317
318 // Set identifier type.
319 identifier_type_ = getIdentifierType(name);
320
321 // Identifier value can either be specified as string of hexadecimal
322 // digits or a string in quotes. The latter is copied to a vector excluding
323 // quote characters.
324
325 // Try to convert the values in quotes into a vector of ASCII codes.
326 // If the identifier lacks opening and closing quote, this will return
327 // an empty value, in which case we'll try to decode it as a string of
328 // hexadecimal digits.
329 try {
330 std::vector<uint8_t> binary = util::str::quotedStringToBinary(identifier);
331 if (binary.empty()) {
332 util::str::decodeFormattedHexString(identifier, binary);
333 }
334 // Successfully decoded the identifier, so let's use it.
335 identifier_value_.swap(binary);
336
337 } catch (...) {
338 // The string doesn't match any known pattern, so we have to
339 // report an error at this point.
340 isc_throw(isc::BadValue, "invalid host identifier value '"
341 << identifier << "'");
342 }
343}
344
345void
347 if (!address.isV4()) {
348 isc_throw(isc::BadValue, "address '" << address << "' is not a valid"
349 " IPv4 address");
350 } else if (address.isV4Zero() || address.isV4Bcast()) {
351 isc_throw(isc::BadValue, "must not make reservation for the '"
352 << address << "' address");
353 }
354 ipv4_reservation_ = address;
355}
356
357void
359 ipv4_reservation_ = asiolink::IOAddress::IPV4_ZERO_ADDRESS();
360}
361
362void
363Host::addReservation(const IPv6Resrv& reservation) {
364 // Check if it is not duplicating existing reservation.
365 if (hasReservation(reservation)) {
366 isc_throw(isc::InvalidOperation, "failed on attempt to add a duplicated"
367 " host reservation for " << reservation.toText());
368 }
369 // Add it.
370 ipv6_reservations_.insert(IPv6ResrvTuple(reservation.getType(),
371 reservation));
372}
373
376 return (ipv6_reservations_.equal_range(type));
377}
378
381 return (IPv6ResrvRange(ipv6_reservations_.begin(),
382 ipv6_reservations_.end()));
383}
384
385bool
387 return (!ipv6_reservations_.empty());
388}
389
390bool
391Host::hasReservation(const IPv6Resrv& reservation) const {
392 IPv6ResrvRange reservations = getIPv6Reservations(reservation.getType());
393 if (std::distance(reservations.first, reservations.second) > 0) {
394 for (IPv6ResrvIterator it = reservations.first;
395 it != reservations.second; ++it) {
396 if (it->second == reservation) {
397 return (true);
398 }
399 }
400 }
401
402 // No matching reservations found.
403 return (false);
404}
405
406void
407Host::addClientClass4(const std::string& class_name) {
408 addClientClassInternal(dhcp4_client_classes_, class_name);
409}
410
411
412void
413Host::addClientClass6(const std::string& class_name) {
414 addClientClassInternal(dhcp6_client_classes_, class_name);
415}
416
417void
418Host::addClientClassInternal(ClientClasses& classes,
419 const std::string& class_name) {
420 std::string trimmed = util::str::trim(class_name);
421 if (!trimmed.empty()) {
422 classes.insert(ClientClass(trimmed));
423 }
424}
425
426void
428 if (!next_server.isV4()) {
429 isc_throw(isc::BadValue, "next server address '" << next_server
430 << "' is not a valid IPv4 address");
431 } else if (next_server.isV4Bcast()) {
432 isc_throw(isc::BadValue, "invalid next server address '"
433 << next_server << "'");
434 }
435
436 next_server_ = next_server;
437}
438
439void
440Host::setServerHostname(const std::string& server_host_name) {
441 if (server_host_name.size() > Pkt4::MAX_SNAME_LEN - 1) {
442 isc_throw(isc::BadValue, "server hostname length must not exceed "
443 << (Pkt4::MAX_SNAME_LEN - 1));
444 }
445 server_host_name_ = server_host_name;
446}
447
448void
449Host::setBootFileName(const std::string& boot_file_name) {
450 if (boot_file_name.size() > Pkt4::MAX_FILE_LEN - 1) {
451 isc_throw(isc::BadValue, "boot file length must not exceed "
452 << (Pkt4::MAX_FILE_LEN - 1));
453 }
454 boot_file_name_ = boot_file_name;
455}
456
459
460 // Prepare the map
462 // Set the user context
463 contextToElement(map);
464 // Set the identifier
466 if (id_type == Host::IDENT_HWADDR) {
467 HWAddrPtr hwaddr = getHWAddress();
468 map->set("hw-address", Element::create(hwaddr->toText(false)));
469 } else if (id_type == Host::IDENT_DUID) {
470 DuidPtr duid = getDuid();
471 map->set("duid", Element::create(duid->toText()));
472 } else if (id_type == Host::IDENT_CIRCUIT_ID) {
473 const std::vector<uint8_t>& bin = getIdentifier();
474 std::string circuit_id = util::encode::encodeHex(bin);
475 map->set("circuit-id", Element::create(circuit_id));
476 } else if (id_type == Host::IDENT_CLIENT_ID) {
477 const std::vector<uint8_t>& bin = getIdentifier();
478 std::string client_id = util::encode::encodeHex(bin);
479 map->set("client-id", Element::create(client_id));
480 } else if (id_type == Host::IDENT_FLEX) {
481 const std::vector<uint8_t>& bin = getIdentifier();
482 std::string flex = util::encode::encodeHex(bin);
483 map->set("flex-id", Element::create(flex));
484 } else {
485 isc_throw(ToElementError, "invalid identifier type: " << id_type);
486 }
487 // Set the reservation (if not 0.0.0.0 which may not be re-read)
488 const IOAddress& address = getIPv4Reservation();
489 if (!address.isV4Zero()) {
490 map->set("ip-address", Element::create(address.toText()));
491 }
492 // Set the hostname
493 const std::string& hostname = getHostname();
494 map->set("hostname", Element::create(hostname));
495 // Set next-server
496 const IOAddress& next_server = getNextServer();
497 map->set("next-server", Element::create(next_server.toText()));
498 // Set server-hostname
499 const std::string& server_hostname = getServerHostname();
500 map->set("server-hostname", Element::create(server_hostname));
501 // Set boot-file-name
502 const std::string& boot_file_name = getBootFileName();
503 map->set("boot-file-name", Element::create(boot_file_name));
504 // Set client-classes
505 const ClientClasses& cclasses = getClientClasses4();
507 for (ClientClasses::const_iterator cclass = cclasses.cbegin();
508 cclass != cclasses.cend(); ++cclass) {
509 classes->add(Element::create(*cclass));
510 }
511 map->set("client-classes", classes);
512 // Set option-data
514 map->set("option-data", opts->toElement());
515
516 return (map);
517}
518
521 // Prepare the map
523 // Set the user context
524 contextToElement(map);
525 // Set the identifier
527 if (id_type == Host::IDENT_HWADDR) {
528 HWAddrPtr hwaddr = getHWAddress();
529 map->set("hw-address", Element::create(hwaddr->toText(false)));
530 } else if (id_type == Host::IDENT_DUID) {
531 DuidPtr duid = getDuid();
532 map->set("duid", Element::create(duid->toText()));
533 } else if (id_type == Host::IDENT_CIRCUIT_ID) {
534 isc_throw(ToElementError, "unexpected circuit-id DUID type");
535 } else if (id_type == Host::IDENT_CLIENT_ID) {
536 isc_throw(ToElementError, "unexpected client-id DUID type");
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 DUID type: " << id_type);
543 }
544 // Set reservations (ip-addresses)
547 for (IPv6ResrvIterator resv = na_resv.first;
548 resv != na_resv.second; ++resv) {
549 resvs->add(Element::create(resv->second.toText()));
550 }
551 map->set("ip-addresses", resvs);
552 // Set reservations (prefixes)
554 resvs = Element::createList();
555 for (IPv6ResrvIterator resv = pd_resv.first;
556 resv != pd_resv.second; ++resv) {
557 resvs->add(Element::create(resv->second.toText()));
558 }
559 map->set("prefixes", resvs);
560 // Set the hostname
561 const std::string& hostname = getHostname();
562 map->set("hostname", Element::create(hostname));
563 // Set client-classes
564 const ClientClasses& cclasses = getClientClasses6();
566 for (ClientClasses::const_iterator cclass = cclasses.cbegin();
567 cclass != cclasses.cend(); ++cclass) {
568 classes->add(Element::create(*cclass));
569 }
570 map->set("client-classes", classes);
571
572 // Set option-data
574 map->set("option-data", opts->toElement());
575
576 // Set auth key
577 //@todo: uncomment once storing in configuration file is enabled
578 //map->set("auth-key", Element::create(getKey().ToText()));
579
580 return (map);
581}
582
583std::string
585 std::ostringstream s;
586
587 // Add HW address or DUID.
588 s << getIdentifierAsText();
589
590 // Add IPv4 subnet id if exists.
591 if (ipv4_subnet_id_ != SUBNET_ID_UNUSED) {
592 s << " ipv4_subnet_id=" << ipv4_subnet_id_;
593 }
594
595 // Add IPv6 subnet id if exists.
596 if (ipv6_subnet_id_ != SUBNET_ID_UNUSED) {
597 s << " ipv6_subnet_id=" << ipv6_subnet_id_;
598 }
599
600 // Add hostname.
601 s << " hostname=" << (hostname_.empty() ? "(empty)" : hostname_);
602
603 // Add IPv4 reservation.
604 s << " ipv4_reservation=" << (ipv4_reservation_.isV4Zero() ? "(no)" :
605 ipv4_reservation_.toText());
606
607 // Add next server.
608 s << " siaddr=" << (next_server_.isV4Zero() ? "(no)" :
609 next_server_.toText());
610
611 // Add server host name.
612 s << " sname=" << (server_host_name_.empty() ? "(empty)" : server_host_name_);
613
614 // Add boot file name.
615 s << " file=" << (boot_file_name_.empty() ? "(empty)" : boot_file_name_);
616
617 s << " key=" << (key_.ToText().empty() ? "(empty)" : key_.ToText());
618
619 if (ipv6_reservations_.empty()) {
620 s << " ipv6_reservations=(none)";
621
622 } else {
623 // Add all IPv6 reservations.
624 for (IPv6ResrvIterator resrv = ipv6_reservations_.begin();
625 resrv != ipv6_reservations_.end(); ++resrv) {
626 s << " ipv6_reservation"
627 << std::distance(ipv6_reservations_.begin(), resrv)
628 << "=" << resrv->second.toText();
629 }
630 }
631
632 // Add DHCPv4 client classes.
633 for (ClientClasses::const_iterator cclass = dhcp4_client_classes_.cbegin();
634 cclass != dhcp4_client_classes_.cend(); ++cclass) {
635 s << " dhcp4_class"
636 << std::distance(dhcp4_client_classes_.cbegin(), cclass)
637 << "=" << *cclass;
638 }
639
640 // Add DHCPv6 client classes.
641 for (ClientClasses::const_iterator cclass = dhcp6_client_classes_.cbegin();
642 cclass != dhcp6_client_classes_.cend(); ++cclass) {
643 s << " dhcp6_class"
644 << std::distance(dhcp6_client_classes_.cbegin(), cclass)
645 << "=" << *cclass;
646 }
647
648 // Add negative cached.
649 if (negative_) {
650 s << " negative cached";
651 }
652
653 return (s.str());
654}
655
656} // end of namespace isc::dhcp
657} // end of namespace isc
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
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:223
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
Definition: data.cc:268
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
Definition: data.cc:263
Authentication keys.
Definition: host.h:34
AuthKey()
Constructor.
Definition: host.cc:29
bool operator!=(const AuthKey &other) const
inequality operator
Definition: host.cc:62
std::string ToText() const
return text format for keys
Definition: host.cc:43
static std::string getRandomKeyString()
Random string is generated by default will be used for the keys to be used for signing Reconfigure Me...
Definition: host.cc:34
void setAuthKey(const std::string &key)
set auth key value
Definition: host.cc:49
static const uint8_t KEY_LEN
Length of the key - 128 bits.
Definition: host.h:37
bool operator==(const AuthKey &other) const
equality operator
Definition: host.cc:57
Represents option data configuration for the DHCP server.
Definition: cfg_option.h:248
Container for storing client class names.
Definition: classify.h:43
void insert(const ClientClass &class_name)
Insert an element.
Definition: classify.h:62
std::list< ClientClass >::const_iterator const_iterator
Type of iterators.
Definition: classify.h:47
const_iterator cbegin() const
Iterator to the first element.
Definition: classify.h:81
const_iterator cend() const
Iterator to the past the end element.
Definition: classify.h:86
Holds DUID (DHCPv6 Unique Identifier)
Definition: duid.h:27
void addClientClass4(const std::string &class_name)
Adds new client class for DHCPv4.
Definition: host.cc:407
void setServerHostname(const std::string &server_host_name)
Sets new value for server hostname (sname).
Definition: host.cc:440
const ClientClasses & getClientClasses6() const
Returns classes which DHCPv6 client is associated with.
Definition: host.h:534
CfgOptionPtr getCfgOption4()
Returns pointer to the DHCPv4 option data configuration for this host.
Definition: host.h:580
std::string toText() const
Returns information about the host in the textual format.
Definition: host.cc:584
void addClientClass6(const std::string &class_name)
Adds new client class for DHCPv6.
Definition: host.cc:413
IdentifierType
Type of the host identifier.
Definition: host.h:252
@ IDENT_HWADDR
Definition: host.h:253
@ IDENT_FLEX
Flexible host identifier.
Definition: host.h:257
@ IDENT_CLIENT_ID
Definition: host.h:256
@ IDENT_CIRCUIT_ID
Definition: host.h:255
IdentifierType getIdentifierType() const
Returns the identifier type.
Definition: host.cc:200
void setIdentifier(const uint8_t *identifier, const size_t len, const IdentifierType &type)
Replaces currently used identifier with a new identifier.
Definition: host.cc:301
const asiolink::IOAddress & getIPv4Reservation() const
Returns reserved IPv4 address.
Definition: host.h:470
const std::string & getHostname() const
Returns reserved hostname.
Definition: host.h:514
IPv6ResrvRange getIPv6Reservations() const
Returns all IPv6 reservations.
Definition: host.cc:380
const std::string & getBootFileName() const
Returns value of boot file name (file).
Definition: host.h:571
bool hasIPv6Reservation() const
Checks if there is at least one IPv6 reservation for this host.
Definition: host.cc:386
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:120
const std::vector< uint8_t > & getIdentifier() const
Returns the identifier in a binary form.
Definition: host.cc:195
isc::data::ElementPtr toElement6() const
Unparses (converts to Element representation) IPv6 host.
Definition: host.cc:520
void addReservation(const IPv6Resrv &reservation)
Adds new IPv6 reservation.
Definition: host.cc:363
const ClientClasses & getClientClasses4() const
Returns classes which DHCPv4 client is associated with.
Definition: host.h:524
static std::string getIdentifierName(const IdentifierType &type)
Returns name of the identifier of a specified type.
Definition: host.cc:276
const std::string & getServerHostname() const
Returns value of server hostname (sname).
Definition: host.h:559
void setBootFileName(const std::string &boot_file_name)
Sets new value for boot file name (file).
Definition: host.cc:449
void setNextServer(const asiolink::IOAddress &next_server)
Sets new value for next server field (siaddr).
Definition: host.cc:427
CfgOptionPtr getCfgOption6()
Returns pointer to the DHCPv6 option data configuration for this host.
Definition: host.h:595
bool hasReservation(const IPv6Resrv &reservation) const
Checks if specified IPv6 reservation exists for the host.
Definition: host.cc:391
const asiolink::IOAddress & getNextServer() const
Returns value of next server field (siaddr).
Definition: host.h:547
std::string getIdentifierAsText() const
Returns host identifier in a textual form.
Definition: host.cc:239
isc::data::ElementPtr toElement4() const
Unparses (converts to Element representation) IPv4 host.
Definition: host.cc:458
DuidPtr getDuid() const
Returns DUID for which the reservations are made.
Definition: host.cc:232
void removeIPv4Reservation()
Removes the IPv4 reservation.
Definition: host.cc:358
HWAddrPtr getHWAddress() const
Returns hardware address for which the reservations are made.
Definition: host.cc:226
void setIPv4Reservation(const asiolink::IOAddress &address)
Sets new IPv4 reservation.
Definition: host.cc:346
IPv6 reservation for a host.
Definition: host.h:106
void set(const Type &type, const asiolink::IOAddress &prefix, const uint8_t prefix_len)
Sets a new prefix and prefix length.
Definition: host.cc:75
Type getType() const
Returns reservation type.
Definition: host.h:149
Type
Type of the reservation.
Definition: host.h:112
std::string toText() const
Returns information about the reservation in the textual format.
Definition: host.cc:98
IPv6Resrv(const Type &type, const asiolink::IOAddress &prefix, const uint8_t prefix_len=128)
Constructor.
Definition: host.cc:66
bool operator==(const IPv6Resrv &other) const
Equality operator.
Definition: host.cc:109
bool operator!=(const IPv6Resrv &other) const
Inequality operator.
Definition: host.cc:116
static const size_t MAX_SNAME_LEN
length of the SNAME field in DHCPv4 message
Definition: pkt4.h:45
static const size_t MAX_FILE_LEN
length of the FILE field in DHCPv4 message
Definition: pkt4.h:48
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< Element > ElementPtr
Definition: data.h:22
IPv6ResrvCollection::const_iterator IPv6ResrvIterator
Definition: host.h:186
std::string ClientClass
Defines a single class name.
Definition: classify.h:37
boost::shared_ptr< DUID > DuidPtr
Definition: duid.h:21
std::pair< IPv6ResrvIterator, IPv6ResrvIterator > IPv6ResrvRange
Definition: host.h:188
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
Definition: hwaddr.h:154
uint32_t SubnetID
Unique identifier for a subnet (both v4 and v6)
Definition: lease.h:24
std::pair< IPv6Resrv::Type, IPv6Resrv > IPv6ResrvTuple
Definition: host.h:187
@ HTYPE_ETHER
Ethernet 10Mbps.
Definition: dhcp4.h:56
boost::shared_ptr< const CfgOption > ConstCfgOptionPtr
Const pointer.
Definition: cfg_option.h:500
string encodeHex(const vector< uint8_t > &binary)
Encode binary data in the base16 ('hex') format.
Definition: base_n.cc:461
void decodeFormattedHexString(const std::string &hex_string, std::vector< uint8_t > &binary)
Converts a formatted string of hexadecimal digits into a vector.
Definition: strutil.cc:266
std::vector< uint8_t > quotedStringToBinary(const std::string &quoted_string)
Converts a string in quotes into vector.
Definition: strutil.cc:196
string trim(const string &instring)
Trim Leading and Trailing Spaces.
Definition: strutil.cc:53
Defines the logger used by the top-level component of kea-dhcp-ddns.
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