Kea 2.5.9
host.h
Go to the documentation of this file.
1// Copyright (C) 2014-2023 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
417 static size_t getIdentifierMaxLength(const IdentifierType& type);
418
429 void setIdentifier(const uint8_t* identifier, const size_t len,
430 const IdentifierType& type);
431
442 void setIdentifier(const std::string& identifier, const std::string& name);
443
448 HWAddrPtr getHWAddress() const;
449
454 DuidPtr getDuid() const;
455
460 const std::vector<uint8_t>& getIdentifier() const;
461
465
470 static IdentifierType getIdentifierType(const std::string& identifier_name);
471
475 std::string getIdentifierAsText() const;
476
478 static std::string getIdentifierName(const IdentifierType& type);
479
486 static std::string getIdentifierAsText(const IdentifierType& type,
487 const uint8_t* value,
488 const size_t length);
489
493 void setIPv4SubnetID(const SubnetID ipv4_subnet_id) {
494 ipv4_subnet_id_ = ipv4_subnet_id;
495 }
496
500 void setIPv6SubnetID(const SubnetID ipv6_subnet_id) {
501 ipv6_subnet_id_ = ipv6_subnet_id;
502 }
503
506 return (ipv4_subnet_id_);
507 }
508
511 return (ipv6_subnet_id_);
512 }
513
522 void setIPv4Reservation(const asiolink::IOAddress& address);
523
528
533 return (ipv4_reservation_);
534 }
535
539 void addReservation(const IPv6Resrv& reservation);
540
548
554
558 bool hasIPv6Reservation() const;
559
566 bool hasReservation(const IPv6Resrv& reservation) const;
567
571 void setHostname(const std::string& hostname) {
572 hostname_ = hostname;
573 }
574
576 const std::string& getHostname() const {
577 return (hostname_);
578 }
579
581 std::string getLowerHostname() const {
582 return (boost::algorithm::to_lower_copy(hostname_));
583 }
584
588 void addClientClass4(const std::string& class_name);
589
592 return (dhcp4_client_classes_);
593 }
594
598 void addClientClass6(const std::string& class_name);
599
602 return (dhcp6_client_classes_);
603 }
604
611 void setNextServer(const asiolink::IOAddress& next_server);
612
615 return (next_server_);
616 }
617
623 void setServerHostname(const std::string& server_host_name);
624
626 const std::string& getServerHostname() const {
627 return (server_host_name_);
628 }
629
635 void setBootFileName(const std::string& boot_file_name);
636
638 const std::string& getBootFileName() const {
639 return (boot_file_name_);
640 }
641
648 return (cfg_option4_);
649 }
650
654 return (cfg_option4_);
655 }
656
663 return (cfg_option6_);
664 }
665
669 return (cfg_option6_);
670 }
671
676 void encapsulateOptions() const;
677
679 std::string toText() const;
680
683 void setHostId(HostID id) {
684 host_id_ = id;
685 }
686
690 return (host_id_);
691 }
692
698 void setNegative(bool negative) {
699 negative_ = negative;
700 }
701
704 bool getNegative() const {
705 return (negative_);
706 }
707
712
717
721 void setKey(const AuthKey& key) {
722 key_ = key;
723 }
724
728 AuthKey getKey() const {
729 return(key_);
730 }
731
732protected:
733
739 void setIdentifierType(const IdentifierType& type);
740
741private:
742
753 void addClientClassInternal(ClientClasses& classes,
754 const std::string& class_name);
755
757 IdentifierType identifier_type_;
759 std::vector<uint8_t> identifier_value_;
761 SubnetID ipv4_subnet_id_;
763 SubnetID ipv6_subnet_id_;
765 asiolink::IOAddress ipv4_reservation_;
767 IPv6ResrvCollection ipv6_reservations_;
769 std::string hostname_;
771 ClientClasses dhcp4_client_classes_;
773 ClientClasses dhcp6_client_classes_;
775 asiolink::IOAddress next_server_;
777 std::string server_host_name_;
779 std::string boot_file_name_;
780
783 uint64_t host_id_;
784
786 CfgOptionPtr cfg_option4_;
788 CfgOptionPtr cfg_option6_;
789
795 bool negative_;
796
803 AuthKey key_;
804};
805
807typedef boost::shared_ptr<Host> HostPtr;
808
810typedef boost::shared_ptr<const Host> ConstHostPtr;
811
813typedef std::vector<ConstHostPtr> ConstHostCollection;
814
816typedef std::vector<HostPtr> HostCollection;
817
818}
819}
820
821#endif // HOST_H
Defines elements for storing the names of client classes.
Authentication keys.
Definition: host.h:75
AuthKey()
Constructor.
Definition: host.cc:36
bool operator!=(const AuthKey &other) const
Inequality operator.
Definition: host.cc:82
static std::vector< uint8_t > getRandomKeyString()
Random string is generated by default will be used for the keys to be used for signing Reconfigure Me...
Definition: host.cc:41
std::string toText() const
Return text format for keys.
Definition: host.cc:46
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:54
bool operator==(const AuthKey &other) const
Equality operator.
Definition: host.cc:77
Container for storing client class names.
Definition: classify.h:108
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:464
void setServerHostname(const std::string &server_host_name)
Sets new value for server hostname (sname).
Definition: host.cc:497
static size_t getIdentifierMaxLength(const IdentifierType &type)
Get maximum identifier length.
Definition: host.cc:215
void setHostId(HostID id)
Sets Host ID (primary key in MySQL and PostgreSQL backends)
Definition: host.h:683
void encapsulateOptions() const
Encapsulates host-specific options with their suboptions.
Definition: host.cc:637
const ClientClasses & getClientClasses6() const
Returns classes which DHCPv6 client is associated with.
Definition: host.h:601
CfgOptionPtr getCfgOption4()
Returns pointer to the DHCPv4 option data configuration for this host.
Definition: host.h:647
void setNegative(bool negative)
Sets the negative cached flag.
Definition: host.h:698
std::string toText() const
Returns information about the host in the textual format.
Definition: host.cc:647
void addClientClass6(const std::string &class_name)
Adds new client class for DHCPv6.
Definition: host.cc:470
SubnetID getIPv4SubnetID() const
Returns subnet identifier for IPv4 reservation.
Definition: host.h:505
IdentifierType
Type of the host identifier.
Definition: host.h:307
@ IDENT_HWADDR
Definition: host.h:308
@ IDENT_FLEX
Flexible host identifier.
Definition: host.h:312
@ IDENT_CLIENT_ID
Definition: host.h:311
@ IDENT_CIRCUIT_ID
Definition: host.h:310
IdentifierType getIdentifierType() const
Returns the identifier type.
Definition: host.cc:236
std::string getLowerHostname() const
Returns reserved hostname in lower case.
Definition: host.h:581
void setIdentifier(const uint8_t *identifier, const size_t len, const IdentifierType &type)
Replaces currently used identifier with a new identifier.
Definition: host.cc:337
SubnetID getIPv6SubnetID() const
Returns subnet identifier for IPv6 reservations.
Definition: host.h:510
void setHostname(const std::string &hostname)
Sets new hostname.
Definition: host.h:571
const asiolink::IOAddress & getIPv4Reservation() const
Returns reserved IPv4 address.
Definition: host.h:532
static const IdentifierType LAST_IDENTIFIER_TYPE
Constant pointing to the last identifier of the IdentifierType enumeration.
Definition: host.h:317
void setIdentifierType(const IdentifierType &type)
Set the identifier type.
Definition: host.cc:399
const std::string & getHostname() const
Returns reserved hostname.
Definition: host.h:576
IPv6ResrvRange getIPv6Reservations() const
Returns all IPv6 reservations.
Definition: host.cc:438
const std::string & getBootFileName() const
Returns value of boot file name (file).
Definition: host.h:638
bool hasIPv6Reservation() const
Checks if there is at least one IPv6 reservation for this host.
Definition: host.cc:444
const std::vector< uint8_t > & getIdentifier() const
Returns the identifier in a binary form.
Definition: host.cc:231
isc::data::ElementPtr toElement6() const
Unparses (converts to Element representation) IPv6 host.
Definition: host.cc:576
ConstCfgOptionPtr getCfgOption4() const
Returns const pointer to the DHCPv4 option data configuration for this host.
Definition: host.h:653
void addReservation(const IPv6Resrv &reservation)
Adds new IPv6 reservation.
Definition: host.cc:421
const ClientClasses & getClientClasses4() const
Returns classes which DHCPv4 client is associated with.
Definition: host.h:591
static std::string getIdentifierName(const IdentifierType &type)
Returns name of the identifier of a specified type.
Definition: host.cc:312
const std::string & getServerHostname() const
Returns value of server hostname (sname).
Definition: host.h:626
void setBootFileName(const std::string &boot_file_name)
Sets new value for boot file name (file).
Definition: host.cc:506
void setNextServer(const asiolink::IOAddress &next_server)
Sets new value for next server field (siaddr).
Definition: host.cc:484
CfgOptionPtr getCfgOption6()
Returns pointer to the DHCPv6 option data configuration for this host.
Definition: host.h:662
bool hasReservation(const IPv6Resrv &reservation) const
Checks if specified IPv6 reservation exists for the host.
Definition: host.cc:449
const asiolink::IOAddress & getNextServer() const
Returns value of next server field (siaddr).
Definition: host.h:614
ConstCfgOptionPtr getCfgOption6() const
Returns const pointer to the DHCPv6 option data configuration for this host.
Definition: host.h:668
std::string getIdentifierAsText() const
Returns host identifier in a textual form.
Definition: host.cc:275
AuthKey getKey() const
Returns the key.
Definition: host.h:728
isc::data::ElementPtr toElement4() const
Unparses (converts to Element representation) IPv4 host.
Definition: host.cc:515
DuidPtr getDuid() const
Returns DUID for which the reservations are made.
Definition: host.cc:268
void setIPv4SubnetID(const SubnetID ipv4_subnet_id)
Sets new IPv4 subnet identifier.
Definition: host.h:493
void removeIPv4Reservation()
Removes the IPv4 reservation.
Definition: host.cc:416
void setIPv6SubnetID(const SubnetID ipv6_subnet_id)
Sets new IPv6 subnet identifier.
Definition: host.h:500
HWAddrPtr getHWAddress() const
Returns hardware address for which the reservations are made.
Definition: host.cc:262
void setKey(const AuthKey &key)
sets key.
Definition: host.h:721
HostID getHostId() const
Returns Host ID (primary key in MySQL and PostgreSQL backends)
Definition: host.h:689
bool getNegative() const
Return the negative cache flag value.
Definition: host.h:704
void setIPv4Reservation(const asiolink::IOAddress &address)
Sets new IPv4 reservation.
Definition: host.cc:404
IPv6 reservation for a host.
Definition: host.h:161
void set(const Type &type, const asiolink::IOAddress &prefix, const uint8_t prefix_len)
Sets a new prefix and prefix length.
Definition: host.cc:95
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:118
bool operator==(const IPv6Resrv &other) const
Equality operator.
Definition: host.cc:129
bool operator!=(const IPv6Resrv &other) const
Inequality operator.
Definition: host.cc:136
boost::shared_ptr< Element > ElementPtr
Definition: data.h:28
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:803
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
Definition: host.h:807
std::vector< ConstHostPtr > ConstHostCollection
Collection of the const Host objects.
Definition: host.h:813
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:36
std::pair< IPv6ResrvIterator, IPv6ResrvIterator > IPv6ResrvRange
Definition: host.h:243
std::vector< HostPtr > HostCollection
Collection of the Host objects.
Definition: host.h:816
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:25
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:810
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:806
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