Kea 2.2.0
host.h
Go to the documentation of this file.
1// Copyright (C) 2014-2022 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#ifndef HOST_H
8#define HOST_H
9
10#include <asiolink/io_address.h>
11#include <cc/data.h>
12#include <cc/user_context.h>
13#include <dhcp/classify.h>
14#include <dhcp/duid.h>
15#include <dhcp/hwaddr.h>
16#include <dhcpsrv/cfg_option.h>
17#include <dhcpsrv/subnet_id.h>
18#include <boost/shared_ptr.hpp>
19#include <boost/algorithm/string.hpp>
20#include <list>
21#include <map>
22#include <string>
23#include <utility>
24
25namespace isc {
26namespace dhcp {
27
32const size_t ADDRESS6_TEXT_MAX_LEN = 39;
33
36const size_t CLIENT_CLASSES_MAX_LEN = 255;
37
42const size_t HOSTNAME_MAX_LEN = 255;
43
45const size_t OPTION_VALUE_MAX_LEN = 4096;
46
49
51const size_t OPTION_SPACE_MAX_LEN = 128;
52
54const size_t USER_CONTEXT_MAX_LEN = 8192;
55
57const size_t SERVER_HOSTNAME_MAX_LEN = 64;
58
60const size_t BOOT_FILE_NAME_MAX_LEN = 128;
61
63const uint8_t AUTH_KEY_LEN = 16;
64
67
69typedef uint64_t HostID;
70
75class AuthKey {
76public:
82 AuthKey(const std::vector<uint8_t>& key);
83
92 AuthKey(const std::string& key);
93
98 AuthKey();
99
100 // @brief Get random string.
105 static std::vector<uint8_t> getRandomKeyString();
106
110 // If the size is greater than 16 bytes, we resize to 16 bytes.
113 void setAuthKey(const std::vector<uint8_t>& key);
114
122 void setAuthKey(const std::string& key);
123
127 const std::vector<uint8_t>& getAuthKey() const {
128 return authKey_;
129 }
130
134 std::string toText() const;
135
141 bool operator==(const AuthKey& other) const;
142
147 bool operator!=(const AuthKey& other) const;
148
149private:
150 std::vector<uint8_t> authKey_;
151};
152
162public:
163
167 enum Type {
169 TYPE_PD
170 };
171
185 IPv6Resrv(const Type& type,
186 const asiolink::IOAddress& prefix,
187 const uint8_t prefix_len = 128);
188
191 return (prefix_);
192 }
193
195 uint8_t getPrefixLen() const {
196 return (prefix_len_);
197 }
198
204 Type getType() const {
205 return (type_);
206 }
207
216 void set(const Type& type, const asiolink::IOAddress& prefix,
217 const uint8_t prefix_len);
218
220 std::string toText() const;
221
225 bool operator==(const IPv6Resrv& other) const;
226
230 bool operator!=(const IPv6Resrv& other) const;
231
232private:
233
234 Type type_;
235 asiolink::IOAddress prefix_;
236 uint8_t prefix_len_;
237};
238
240typedef std::multimap<IPv6Resrv::Type, IPv6Resrv> IPv6ResrvCollection;
241typedef IPv6ResrvCollection::const_iterator IPv6ResrvIterator;
242typedef std::pair<IPv6Resrv::Type, IPv6Resrv> IPv6ResrvTuple;
243typedef std::pair<IPv6ResrvIterator, IPv6ResrvIterator> IPv6ResrvRange;
244
297class Host : public data::UserContext {
298public:
299
313 };
314
318
349 Host(const uint8_t* identifier, const size_t identifier_len,
350 const IdentifierType& identifier_type,
351 const SubnetID ipv4_subnet_id, const SubnetID ipv6_subnet_id,
352 const asiolink::IOAddress& ipv4_reservation,
353 const std::string& hostname = "",
354 const std::string& dhcp4_client_classes = "",
355 const std::string& dhcp6_client_classes = "",
357 const std::string& server_host_name = "",
358 const std::string& boot_file_name = "",
359 const AuthKey& auth_key = AuthKey(""));
360
401 Host(const std::string& identifier, const std::string& identifier_name,
402 const SubnetID ipv4_subnet_id, const SubnetID ipv6_subnet_id,
403 const asiolink::IOAddress& ipv4_reservation,
404 const std::string& hostname = "",
405 const std::string& dhcp4_client_classes = "",
406 const std::string& dhcp6_client_classes = "",
408 const std::string& server_host_name = "",
409 const std::string& boot_file_name = "",
410 const AuthKey& auth_key = AuthKey(""));
411
422 void setIdentifier(const uint8_t* identifier, const size_t len,
423 const IdentifierType& type);
424
435 void setIdentifier(const std::string& identifier, const std::string& name);
436
441 HWAddrPtr getHWAddress() const;
442
447 DuidPtr getDuid() const;
448
453 const std::vector<uint8_t>& getIdentifier() const;
454
458
463 static IdentifierType getIdentifierType(const std::string& identifier_name);
464
468 std::string getIdentifierAsText() const;
469
471 static std::string getIdentifierName(const IdentifierType& type);
472
479 static std::string getIdentifierAsText(const IdentifierType& type,
480 const uint8_t* value,
481 const size_t length);
482
486 void setIPv4SubnetID(const SubnetID ipv4_subnet_id) {
487 ipv4_subnet_id_ = ipv4_subnet_id;
488 }
489
493 void setIPv6SubnetID(const SubnetID ipv6_subnet_id) {
494 ipv6_subnet_id_ = ipv6_subnet_id;
495 }
496
499 return (ipv4_subnet_id_);
500 }
501
504 return (ipv6_subnet_id_);
505 }
506
515 void setIPv4Reservation(const asiolink::IOAddress& address);
516
521
526 return (ipv4_reservation_);
527 }
528
532 void addReservation(const IPv6Resrv& reservation);
533
541
547
551 bool hasIPv6Reservation() const;
552
559 bool hasReservation(const IPv6Resrv& reservation) const;
560
564 void setHostname(const std::string& hostname) {
565 hostname_ = hostname;
566 }
567
569 const std::string& getHostname() const {
570 return (hostname_);
571 }
572
574 std::string getLowerHostname() const {
575 return (boost::algorithm::to_lower_copy(hostname_));
576 }
577
581 void addClientClass4(const std::string& class_name);
582
585 return (dhcp4_client_classes_);
586 }
587
591 void addClientClass6(const std::string& class_name);
592
595 return (dhcp6_client_classes_);
596 }
597
604 void setNextServer(const asiolink::IOAddress& next_server);
605
608 return (next_server_);
609 }
610
616 void setServerHostname(const std::string& server_host_name);
617
619 const std::string& getServerHostname() const {
620 return (server_host_name_);
621 }
622
628 void setBootFileName(const std::string& boot_file_name);
629
631 const std::string& getBootFileName() const {
632 return (boot_file_name_);
633 }
634
641 return (cfg_option4_);
642 }
643
647 return (cfg_option4_);
648 }
649
656 return (cfg_option6_);
657 }
658
662 return (cfg_option6_);
663 }
664
666 std::string toText() const;
667
670 void setHostId(HostID id) {
671 host_id_ = id;
672 }
673
677 return (host_id_);
678 }
679
685 void setNegative(bool negative) {
686 negative_ = negative;
687 }
688
691 bool getNegative() const {
692 return (negative_);
693 }
694
699
704
708 void setKey(const AuthKey& key) {
709 key_ = key;
710 }
711
715 AuthKey getKey() const {
716 return(key_);
717 }
718
719private:
720
731 void addClientClassInternal(ClientClasses& classes,
732 const std::string& class_name);
733
735 IdentifierType identifier_type_;
737 std::vector<uint8_t> identifier_value_;
739 SubnetID ipv4_subnet_id_;
741 SubnetID ipv6_subnet_id_;
743 asiolink::IOAddress ipv4_reservation_;
745 IPv6ResrvCollection ipv6_reservations_;
747 std::string hostname_;
749 ClientClasses dhcp4_client_classes_;
751 ClientClasses dhcp6_client_classes_;
753 asiolink::IOAddress next_server_;
755 std::string server_host_name_;
757 std::string boot_file_name_;
758
761 uint64_t host_id_;
762
764 CfgOptionPtr cfg_option4_;
766 CfgOptionPtr cfg_option6_;
767
773 bool negative_;
774
781 AuthKey key_;
782};
783
785typedef boost::shared_ptr<Host> HostPtr;
786
788typedef boost::shared_ptr<const Host> ConstHostPtr;
789
791typedef std::vector<ConstHostPtr> ConstHostCollection;
792
794typedef std::vector<HostPtr> HostCollection;
795
796}
797}
798
799#endif // HOST_H
Defines elements for storing the names of client classes.
Authentication keys.
Definition: host.h:75
AuthKey()
Constructor.
Definition: host.cc:33
bool operator!=(const AuthKey &other) const
Inequality operator.
Definition: host.cc:79
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:38
std::string toText() const
Return text format for keys.
Definition: host.cc:43
const std::vector< uint8_t > & getAuthKey() const
Return auth key.
Definition: host.h:127
void setAuthKey(const std::vector< uint8_t > &key)
Set auth key value from binary.
Definition: host.cc:51
bool operator==(const AuthKey &other) const
Equality operator.
Definition: host.cc:74
Container for storing client class names.
Definition: classify.h:70
Represents a device with IPv4 and/or IPv6 reservations.
Definition: host.h:297
void addClientClass4(const std::string &class_name)
Adds new client class for DHCPv4.
Definition: host.cc:424
void setServerHostname(const std::string &server_host_name)
Sets new value for server hostname (sname).
Definition: host.cc:457
void setHostId(HostID id)
Sets Host ID (primary key in MySQL and PostgreSQL backends)
Definition: host.h:670
const ClientClasses & getClientClasses6() const
Returns classes which DHCPv6 client is associated with.
Definition: host.h:594
CfgOptionPtr getCfgOption4()
Returns pointer to the DHCPv4 option data configuration for this host.
Definition: host.h:640
void setNegative(bool negative)
Sets the negative cached flag.
Definition: host.h:685
std::string toText() const
Returns information about the host in the textual format.
Definition: host.cc:601
void addClientClass6(const std::string &class_name)
Adds new client class for DHCPv6.
Definition: host.cc:430
SubnetID getIPv4SubnetID() const
Returns subnet identifier for IPv4 reservation.
Definition: host.h:498
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:217
std::string getLowerHostname() const
Returns reserved hostname in lower case.
Definition: host.h:574
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
SubnetID getIPv6SubnetID() const
Returns subnet identifier for IPv6 reservations.
Definition: host.h:503
void setHostname(const std::string &hostname)
Sets new hostname.
Definition: host.h:564
const asiolink::IOAddress & getIPv4Reservation() const
Returns reserved IPv4 address.
Definition: host.h:525
static const IdentifierType LAST_IDENTIFIER_TYPE
Constant pointing to the last identifier of the IdentifierType enumeration.
Definition: host.h:317
const std::string & getHostname() const
Returns reserved hostname.
Definition: host.h:569
IPv6ResrvRange getIPv6Reservations() const
Returns all IPv6 reservations.
Definition: host.cc:397
const std::string & getBootFileName() const
Returns value of boot file name (file).
Definition: host.h:631
bool hasIPv6Reservation() const
Checks if there is at least one IPv6 reservation for this host.
Definition: host.cc:403
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
const std::vector< uint8_t > & getIdentifier() const
Returns the identifier in a binary form.
Definition: host.cc:212
isc::data::ElementPtr toElement6() const
Unparses (converts to Element representation) IPv6 host.
Definition: host.cc:537
ConstCfgOptionPtr getCfgOption4() const
Returns const pointer to the DHCPv4 option data configuration for this host.
Definition: host.h:646
void addReservation(const IPv6Resrv &reservation)
Adds new IPv6 reservation.
Definition: host.cc:380
const ClientClasses & getClientClasses4() const
Returns classes which DHCPv4 client is associated with.
Definition: host.h:584
static std::string getIdentifierName(const IdentifierType &type)
Returns name of the identifier of a specified type.
Definition: host.cc:293
const std::string & getServerHostname() const
Returns value of server hostname (sname).
Definition: host.h:619
void setBootFileName(const std::string &boot_file_name)
Sets new value for boot file name (file).
Definition: host.cc:466
void setNextServer(const asiolink::IOAddress &next_server)
Sets new value for next server field (siaddr).
Definition: host.cc:444
CfgOptionPtr getCfgOption6()
Returns pointer to the DHCPv6 option data configuration for this host.
Definition: host.h:655
bool hasReservation(const IPv6Resrv &reservation) const
Checks if specified IPv6 reservation exists for the host.
Definition: host.cc:408
const asiolink::IOAddress & getNextServer() const
Returns value of next server field (siaddr).
Definition: host.h:607
ConstCfgOptionPtr getCfgOption6() const
Returns const pointer to the DHCPv6 option data configuration for this host.
Definition: host.h:661
std::string getIdentifierAsText() const
Returns host identifier in a textual form.
Definition: host.cc:256
AuthKey getKey() const
Returns the key.
Definition: host.h:715
isc::data::ElementPtr toElement4() const
Unparses (converts to Element representation) IPv4 host.
Definition: host.cc:475
DuidPtr getDuid() const
Returns DUID for which the reservations are made.
Definition: host.cc:249
void setIPv4SubnetID(const SubnetID ipv4_subnet_id)
Sets new IPv4 subnet identifier.
Definition: host.h:486
void removeIPv4Reservation()
Removes the IPv4 reservation.
Definition: host.cc:375
void setIPv6SubnetID(const SubnetID ipv6_subnet_id)
Sets new IPv6 subnet identifier.
Definition: host.h:493
HWAddrPtr getHWAddress() const
Returns hardware address for which the reservations are made.
Definition: host.cc:243
void setKey(const AuthKey &key)
sets key.
Definition: host.h:708
HostID getHostId() const
Returns Host ID (primary key in MySQL and PostgreSQL backends)
Definition: host.h:676
bool getNegative() const
Return the negative cache flag value.
Definition: host.h:691
void setIPv4Reservation(const asiolink::IOAddress &address)
Sets new IPv4 reservation.
Definition: host.cc:363
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:92
const asiolink::IOAddress & getPrefix() const
Returns prefix for the reservation.
Definition: host.h:190
Type getType() const
Returns reservation type.
Definition: host.h:204
Type
Type of the reservation.
Definition: host.h:167
uint8_t getPrefixLen() const
Returns prefix length.
Definition: host.h:195
std::string toText() const
Returns information about the reservation in the textual format.
Definition: host.cc:115
IPv6Resrv(const Type &type, const asiolink::IOAddress &prefix, const uint8_t prefix_len=128)
Constructor.
Definition: host.cc:83
bool operator==(const IPv6Resrv &other) const
Equality operator.
Definition: host.cc:126
bool operator!=(const IPv6Resrv &other) const
Inequality operator.
Definition: host.cc:133
boost::shared_ptr< Element > ElementPtr
Definition: data.h:24
IPv6ResrvCollection::const_iterator IPv6ResrvIterator
Definition: host.h:241
const size_t OPTION_FORMATTED_VALUE_MAX_LEN
Maximum length of option value specified in textual format.
Definition: host.h:48
boost::shared_ptr< CfgOption > CfgOptionPtr
Non-const pointer.
Definition: cfg_option.h:706
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
Definition: host.h:785
std::vector< ConstHostPtr > ConstHostCollection
Collection of the const Host objects.
Definition: host.h:791
boost::shared_ptr< DUID > DuidPtr
Definition: duid.h:20
const size_t CLIENT_CLASSES_MAX_LEN
Maximum length of classes stored in a dhcp4/6_client_classes columns.
Definition: host.h:36
std::pair< IPv6ResrvIterator, IPv6ResrvIterator > IPv6ResrvRange
Definition: host.h:243
std::vector< HostPtr > HostCollection
Collection of the Host objects.
Definition: host.h:794
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
Definition: hwaddr.h:154
const size_t TEXT_AUTH_KEY_LEN
Maximum length of authentication keys (coded in hexadecimal).
Definition: host.h:66
const uint8_t AUTH_KEY_LEN
Maximum length of authentication keys - 128 bits.
Definition: host.h:63
std::multimap< IPv6Resrv::Type, IPv6Resrv > IPv6ResrvCollection
Collection of IPv6 reservations for the host.
Definition: host.h:240
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Definition: subnet_id.h:24
uint64_t HostID
HostID (used only when storing in MySQL or PostgreSQL backends)
Definition: host.h:69
const size_t ADDRESS6_TEXT_MAX_LEN
Maximum size of an IPv6 address represented as a text string.
Definition: host.h:32
boost::shared_ptr< const Host > ConstHostPtr
Const pointer to the Host object.
Definition: host.h:788
const size_t HOSTNAME_MAX_LEN
Maximum length of the hostname stored in DNS.
Definition: host.h:42
const size_t USER_CONTEXT_MAX_LEN
Maximum length of user context.
Definition: host.h:54
std::pair< IPv6Resrv::Type, IPv6Resrv > IPv6ResrvTuple
Definition: host.h:242
const size_t OPTION_VALUE_MAX_LEN
Maximum length of option value.
Definition: host.h:45
const size_t SERVER_HOSTNAME_MAX_LEN
Maximum length of the server hostname.
Definition: host.h:57
const size_t BOOT_FILE_NAME_MAX_LEN
Maximum length of the boot file name.
Definition: host.h:60
boost::shared_ptr< const CfgOption > ConstCfgOptionPtr
Const pointer.
Definition: cfg_option.h:709
const size_t OPTION_SPACE_MAX_LEN
Maximum length of option space name.
Definition: host.h:51
Defines the logger used by the top-level component of kea-lfc.
Base class for user context.
Definition: user_context.h:22