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