Kea 2.7.6
host.h
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#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>
17#include <dhcpsrv/cfg_option.h>
18#include <dhcpsrv/subnet_id.h>
19#include <boost/shared_ptr.hpp>
20#include <boost/algorithm/string.hpp>
21#include <list>
22#include <map>
23#include <string>
24#include <utility>
25
26namespace isc {
27namespace dhcp {
28
33const size_t ADDRESS6_TEXT_MAX_LEN = 39;
34
37const size_t CLIENT_CLASSES_MAX_LEN = 255;
38
43const size_t HOSTNAME_MAX_LEN = 255;
44
46const size_t OPTION_VALUE_MAX_LEN = 4096;
47
50
52const size_t OPTION_SPACE_MAX_LEN = 128;
53
55const size_t USER_CONTEXT_MAX_LEN = 8192;
56
58const size_t SERVER_HOSTNAME_MAX_LEN = 64;
59
61const size_t BOOT_FILE_NAME_MAX_LEN = 128;
62
64const uint8_t AUTH_KEY_LEN = 16;
65
68
70typedef uint64_t HostID;
71
76class AuthKey {
77public:
83 AuthKey(const std::vector<uint8_t>& key);
84
93 AuthKey(const std::string& key);
94
99 AuthKey();
100
101 // @brief Get random string.
106 static std::vector<uint8_t> getRandomKeyString();
107
111 // If the size is greater than 16 bytes, we resize to 16 bytes.
114 void setAuthKey(const std::vector<uint8_t>& key);
115
123 void setAuthKey(const std::string& key);
124
128 const std::vector<uint8_t>& getAuthKey() const {
129 return authKey_;
130 }
131
135 std::string toText() const;
136
142 bool operator==(const AuthKey& other) const;
143
148 bool operator!=(const AuthKey& other) const;
149
150private:
151 std::vector<uint8_t> authKey_;
152};
153
164public:
165
173
187 IPv6Resrv(const Type& type,
188 const asiolink::IOAddress& prefix,
189 const uint8_t prefix_len = 128);
190
193 return (prefix_);
194 }
195
197 uint8_t getPrefixLen() const {
198 return (prefix_len_);
199 }
200
206 Type getType() const {
207 return (type_);
208 }
209
214 return (pd_exclude_option_);
215 }
216
227 void set(const Type& type, const asiolink::IOAddress& prefix,
228 const uint8_t prefix_len);
229
236 void setPDExclude(const asiolink::IOAddress& excluded_prefix,
237 const uint8_t excluded_prefix_len);
238
243 std::string toText(bool display_pd_exclude_option = true) const;
244
247 std::string PDExcludetoText() const;
248
254 bool operator==(const IPv6Resrv& other) const;
255
259 bool operator!=(const IPv6Resrv& other) const;
260
261private:
262
263 Type type_;
264 asiolink::IOAddress prefix_;
265 uint8_t prefix_len_;
266 Option6PDExcludePtr pd_exclude_option_;
267};
268
270typedef std::multimap<IPv6Resrv::Type, IPv6Resrv> IPv6ResrvCollection;
271typedef IPv6ResrvCollection::const_iterator IPv6ResrvIterator;
272typedef std::pair<IPv6Resrv::Type, IPv6Resrv> IPv6ResrvTuple;
273typedef std::pair<IPv6ResrvIterator, IPv6ResrvIterator> IPv6ResrvRange;
274
327class Host : public data::UserContext {
328public:
329
344
348
379 Host(const uint8_t* identifier, const size_t identifier_len,
380 const IdentifierType& identifier_type,
381 const SubnetID ipv4_subnet_id, const SubnetID ipv6_subnet_id,
382 const asiolink::IOAddress& ipv4_reservation,
383 const std::string& hostname = "",
384 const std::string& dhcp4_client_classes = "",
385 const std::string& dhcp6_client_classes = "",
387 const std::string& server_host_name = "",
388 const std::string& boot_file_name = "",
389 const AuthKey& auth_key = AuthKey(""));
390
431 Host(const std::string& identifier, const std::string& identifier_name,
432 const SubnetID ipv4_subnet_id, const SubnetID ipv6_subnet_id,
433 const asiolink::IOAddress& ipv4_reservation,
434 const std::string& hostname = "",
435 const std::string& dhcp4_client_classes = "",
436 const std::string& dhcp6_client_classes = "",
438 const std::string& server_host_name = "",
439 const std::string& boot_file_name = "",
440 const AuthKey& auth_key = AuthKey(""));
441
447 static size_t getIdentifierMaxLength(const IdentifierType& type);
448
459 void setIdentifier(const uint8_t* identifier, const size_t len,
460 const IdentifierType& type);
461
472 void setIdentifier(const std::string& identifier, const std::string& name);
473
478 HWAddrPtr getHWAddress() const;
479
484 DuidPtr getDuid() const;
485
490 const std::vector<uint8_t>& getIdentifier() const;
491
495
500 static IdentifierType getIdentifierType(const std::string& identifier_name);
501
505 std::string getIdentifierAsText() const;
506
508 static std::string getIdentifierName(const IdentifierType& type);
509
516 static std::string getIdentifierAsText(const IdentifierType& type,
517 const uint8_t* value,
518 const size_t length);
519
523 void setIPv4SubnetID(const SubnetID ipv4_subnet_id) {
524 ipv4_subnet_id_ = ipv4_subnet_id;
525 }
526
530 void setIPv6SubnetID(const SubnetID ipv6_subnet_id) {
531 ipv6_subnet_id_ = ipv6_subnet_id;
532 }
533
536 return (ipv4_subnet_id_);
537 }
538
541 return (ipv6_subnet_id_);
542 }
543
552 void setIPv4Reservation(const asiolink::IOAddress& address);
553
558
563 return (ipv4_reservation_);
564 }
565
569 void addReservation(const IPv6Resrv& reservation);
570
578
584
588 bool hasIPv6Reservation() const;
589
596 bool hasReservation(const IPv6Resrv& reservation) const;
597
601 void setHostname(const std::string& hostname) {
602 hostname_ = hostname;
603 }
604
606 const std::string& getHostname() const {
607 return (hostname_);
608 }
609
611 std::string getLowerHostname() const {
612 return (boost::algorithm::to_lower_copy(hostname_));
613 }
614
618 void addClientClass4(const std::string& class_name);
619
622 return (dhcp4_client_classes_);
623 }
624
628 void addClientClass6(const std::string& class_name);
629
632 return (dhcp6_client_classes_);
633 }
634
641 void setNextServer(const asiolink::IOAddress& next_server);
642
645 return (next_server_);
646 }
647
653 void setServerHostname(const std::string& server_host_name);
654
656 const std::string& getServerHostname() const {
657 return (server_host_name_);
658 }
659
665 void setBootFileName(const std::string& boot_file_name);
666
668 const std::string& getBootFileName() const {
669 return (boot_file_name_);
670 }
671
678 return (cfg_option4_);
679 }
680
684 return (cfg_option4_);
685 }
686
693 return (cfg_option6_);
694 }
695
699 return (cfg_option6_);
700 }
701
706 void encapsulateOptions() const;
707
709 std::string toText() const;
710
713 void setHostId(HostID id) {
714 host_id_ = id;
715 }
716
720 return (host_id_);
721 }
722
728 void setNegative(bool negative) {
729 negative_ = negative;
730 }
731
734 bool getNegative() const {
735 return (negative_);
736 }
737
742
747
751 void setKey(const AuthKey& key) {
752 key_ = key;
753 }
754
758 AuthKey getKey() const {
759 return(key_);
760 }
761
762protected:
763
769 void setIdentifierType(const IdentifierType& type);
770
771private:
772
783 void addClientClassInternal(ClientClasses& classes,
784 const std::string& class_name);
785
787 IdentifierType identifier_type_;
789 std::vector<uint8_t> identifier_value_;
791 SubnetID ipv4_subnet_id_;
793 SubnetID ipv6_subnet_id_;
795 asiolink::IOAddress ipv4_reservation_;
797 IPv6ResrvCollection ipv6_reservations_;
799 std::string hostname_;
801 ClientClasses dhcp4_client_classes_;
803 ClientClasses dhcp6_client_classes_;
805 asiolink::IOAddress next_server_;
807 std::string server_host_name_;
809 std::string boot_file_name_;
810
813 uint64_t host_id_;
814
816 CfgOptionPtr cfg_option4_;
818 CfgOptionPtr cfg_option6_;
819
825 bool negative_;
826
833 AuthKey key_;
834};
835
837typedef boost::shared_ptr<Host> HostPtr;
838
840typedef boost::shared_ptr<const Host> ConstHostPtr;
841
843typedef std::vector<ConstHostPtr> ConstHostCollection;
844
846typedef std::vector<HostPtr> HostCollection;
847
848}
849}
850
851#endif // HOST_H
Defines elements for storing the names of client classes.
Authentication keys.
Definition host.h:76
AuthKey()
Constructor.
Definition host.cc:36
bool operator!=(const AuthKey &other) const
Inequality operator.
Definition host.cc:82
static std::vector< uint8_t > getRandomKeyString()
Random string is generated by default will be used for the keys to be used for signing Reconfigure Me...
Definition host.cc:41
std::string toText() const
Return text format for keys.
Definition host.cc:46
const std::vector< uint8_t > & getAuthKey() const
Return auth key.
Definition host.h:128
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
Container for storing client class names.
Definition classify.h:109
Represents a device with IPv4 and/or IPv6 reservations.
Definition host.h:327
void addClientClass4(const std::string &class_name)
Adds new client class for DHCPv4.
Definition host.cc:501
void setServerHostname(const std::string &server_host_name)
Sets new value for server hostname (sname).
Definition host.cc:534
static size_t getIdentifierMaxLength(const IdentifierType &type)
Get maximum identifier length.
Definition host.cc:252
void setHostId(HostID id)
Sets Host ID (primary key in MySQL and PostgreSQL backends)
Definition host.h:713
void encapsulateOptions() const
Encapsulates host-specific options with their suboptions.
Definition host.cc:686
const ClientClasses & getClientClasses6() const
Returns classes which DHCPv6 client is associated with.
Definition host.h:631
CfgOptionPtr getCfgOption4()
Returns pointer to the DHCPv4 option data configuration for this host.
Definition host.h:677
void setNegative(bool negative)
Sets the negative cached flag.
Definition host.h:728
std::string toText() const
Returns information about the host in the textual format.
Definition host.cc:696
void addClientClass6(const std::string &class_name)
Adds new client class for DHCPv6.
Definition host.cc:507
SubnetID getIPv4SubnetID() const
Returns subnet identifier for IPv4 reservation.
Definition host.h:535
IdentifierType
Type of the host identifier.
Definition host.h:337
@ IDENT_FLEX
Flexible host identifier.
Definition host.h:342
@ IDENT_CLIENT_ID
Definition host.h:341
@ IDENT_CIRCUIT_ID
Definition host.h:340
IdentifierType getIdentifierType() const
Returns the identifier type.
Definition host.cc:273
std::string getLowerHostname() const
Returns reserved hostname in lower case.
Definition host.h:611
void setIdentifier(const uint8_t *identifier, const size_t len, const IdentifierType &type)
Replaces currently used identifier with a new identifier.
Definition host.cc:374
SubnetID getIPv6SubnetID() const
Returns subnet identifier for IPv6 reservations.
Definition host.h:540
void setHostname(const std::string &hostname)
Sets new hostname.
Definition host.h:601
const asiolink::IOAddress & getIPv4Reservation() const
Returns reserved IPv4 address.
Definition host.h:562
static const IdentifierType LAST_IDENTIFIER_TYPE
Constant pointing to the last identifier of the IdentifierType enumeration.
Definition host.h:347
void setIdentifierType(const IdentifierType &type)
Set the identifier type.
Definition host.cc:436
const std::string & getHostname() const
Returns reserved hostname.
Definition host.h:606
IPv6ResrvRange getIPv6Reservations() const
Returns all IPv6 reservations.
Definition host.cc:475
const std::string & getBootFileName() const
Returns value of boot file name (file).
Definition host.h:668
bool hasIPv6Reservation() const
Checks if there is at least one IPv6 reservation for this host.
Definition host.cc:481
Host(const uint8_t *identifier, const size_t identifier_len, const IdentifierType &identifier_type, const SubnetID ipv4_subnet_id, const SubnetID ipv6_subnet_id, const asiolink::IOAddress &ipv4_reservation, const std::string &hostname="", const std::string &dhcp4_client_classes="", const std::string &dhcp6_client_classes="", const asiolink::IOAddress &next_server=asiolink::IOAddress::IPV4_ZERO_ADDRESS(), const std::string &server_host_name="", const std::string &boot_file_name="", const AuthKey &auth_key=AuthKey(""))
Constructor.
Definition host.cc:177
const std::vector< uint8_t > & getIdentifier() const
Returns the identifier in a binary form.
Definition host.cc:268
isc::data::ElementPtr toElement6() const
Unparses (converts to Element representation) IPv6 host.
Definition host.cc:613
ConstCfgOptionPtr getCfgOption4() const
Returns const pointer to the DHCPv4 option data configuration for this host.
Definition host.h:683
void addReservation(const IPv6Resrv &reservation)
Adds new IPv6 reservation.
Definition host.cc:458
const ClientClasses & getClientClasses4() const
Returns classes which DHCPv4 client is associated with.
Definition host.h:621
static std::string getIdentifierName(const IdentifierType &type)
Returns name of the identifier of a specified type.
Definition host.cc:349
const std::string & getServerHostname() const
Returns value of server hostname (sname).
Definition host.h:656
void setBootFileName(const std::string &boot_file_name)
Sets new value for boot file name (file).
Definition host.cc:543
void setNextServer(const asiolink::IOAddress &next_server)
Sets new value for next server field (siaddr).
Definition host.cc:521
CfgOptionPtr getCfgOption6()
Returns pointer to the DHCPv6 option data configuration for this host.
Definition host.h:692
bool hasReservation(const IPv6Resrv &reservation) const
Checks if specified IPv6 reservation exists for the host.
Definition host.cc:486
const asiolink::IOAddress & getNextServer() const
Returns value of next server field (siaddr).
Definition host.h:644
ConstCfgOptionPtr getCfgOption6() const
Returns const pointer to the DHCPv6 option data configuration for this host.
Definition host.h:698
std::string getIdentifierAsText() const
Returns host identifier in a textual form.
Definition host.cc:312
AuthKey getKey() const
Returns the key.
Definition host.h:758
isc::data::ElementPtr toElement4() const
Unparses (converts to Element representation) IPv4 host.
Definition host.cc:552
DuidPtr getDuid() const
Returns DUID for which the reservations are made.
Definition host.cc:305
void setIPv4SubnetID(const SubnetID ipv4_subnet_id)
Sets new IPv4 subnet identifier.
Definition host.h:523
void removeIPv4Reservation()
Removes the IPv4 reservation.
Definition host.cc:453
void setIPv6SubnetID(const SubnetID ipv6_subnet_id)
Sets new IPv6 subnet identifier.
Definition host.h:530
HWAddrPtr getHWAddress() const
Returns hardware address for which the reservations are made.
Definition host.cc:299
void setKey(const AuthKey &key)
sets key.
Definition host.h:751
HostID getHostId() const
Returns Host ID (primary key in MySQL and PostgreSQL backends)
Definition host.h:719
bool getNegative() const
Return the negative cache flag value.
Definition host.h:734
void setIPv4Reservation(const asiolink::IOAddress &address)
Sets new IPv4 reservation.
Definition host.cc:441
IPv6 reservation for a host.
Definition host.h:163
void set(const Type &type, const asiolink::IOAddress &prefix, const uint8_t prefix_len)
Sets a new prefix and prefix length.
Definition host.cc:96
const asiolink::IOAddress & getPrefix() const
Returns prefix for the reservation.
Definition host.h:192
std::string PDExcludetoText() const
Returns information about the Prefix Exclude option of the reservation the textual format.
Definition host.cc:152
Type getType() const
Returns reservation type.
Definition host.h:206
Type
Type of the reservation.
Definition host.h:169
void setPDExclude(const asiolink::IOAddress &excluded_prefix, const uint8_t excluded_prefix_len)
Sets the Prefix Exclude option.
Definition host.cc:120
uint8_t getPrefixLen() const
Returns prefix length.
Definition host.h:197
IPv6Resrv(const Type &type, const asiolink::IOAddress &prefix, const uint8_t prefix_len=128)
Constructor.
Definition host.cc:86
Option6PDExcludePtr getPDExclude() const
Returns the Prefix Exclude option.
Definition host.h:213
bool operator==(const IPv6Resrv &other) const
Equality operator.
Definition host.cc:166
std::string toText(bool display_pd_exclude_option=true) const
Returns information about the reservation in the textual format.
Definition host.cc:132
bool operator!=(const IPv6Resrv &other) const
Inequality operator.
Definition host.cc:173
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
IPv6ResrvCollection::const_iterator IPv6ResrvIterator
Definition host.h:271
const size_t OPTION_FORMATTED_VALUE_MAX_LEN
Maximum length of option value specified in textual format.
Definition host.h:49
boost::shared_ptr< CfgOption > CfgOptionPtr
Non-const pointer.
Definition cfg_option.h:832
boost::shared_ptr< Option6PDExclude > Option6PDExcludePtr
Pointer to the Option6PDExclude object.
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
Definition host.h:837
std::vector< ConstHostPtr > ConstHostCollection
Collection of the const Host objects.
Definition host.h:843
boost::shared_ptr< DUID > DuidPtr
Definition duid.h:136
const size_t CLIENT_CLASSES_MAX_LEN
Maximum length of classes stored in a dhcp4/6_client_classes columns.
Definition host.h:37
std::pair< IPv6ResrvIterator, IPv6ResrvIterator > IPv6ResrvRange
Definition host.h:273
std::vector< HostPtr > HostCollection
Collection of the Host objects.
Definition host.h:846
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:67
const uint8_t AUTH_KEY_LEN
Maximum length of authentication keys - 128 bits.
Definition host.h:64
std::multimap< IPv6Resrv::Type, IPv6Resrv > IPv6ResrvCollection
Collection of IPv6 reservations for the host.
Definition host.h:270
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Definition subnet_id.h:25
uint64_t HostID
HostID (used only when storing in MySQL or PostgreSQL backends)
Definition host.h:70
const size_t ADDRESS6_TEXT_MAX_LEN
Maximum size of an IPv6 address represented as a text string.
Definition host.h:33
boost::shared_ptr< const Host > ConstHostPtr
Const pointer to the Host object.
Definition host.h:840
const size_t HOSTNAME_MAX_LEN
Maximum length of the hostname stored in DNS.
Definition host.h:43
const size_t USER_CONTEXT_MAX_LEN
Maximum length of user context.
Definition host.h:55
std::pair< IPv6Resrv::Type, IPv6Resrv > IPv6ResrvTuple
Definition host.h:272
const size_t OPTION_VALUE_MAX_LEN
Maximum length of option value.
Definition host.h:46
const size_t SERVER_HOSTNAME_MAX_LEN
Maximum length of the server hostname.
Definition host.h:58
const size_t BOOT_FILE_NAME_MAX_LEN
Maximum length of the boot file name.
Definition host.h:61
boost::shared_ptr< const CfgOption > ConstCfgOptionPtr
Const pointer.
Definition cfg_option.h:835
const size_t OPTION_SPACE_MAX_LEN
Maximum length of option space name.
Definition host.h:52
Defines the logger used by the top-level component of kea-lfc.
Base class for user context.