Kea 1.5.0
host.h
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#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 <list>
20#include <map>
21#include <string>
22#include <utility>
23
24namespace isc {
25namespace dhcp {
26
28typedef uint64_t HostID;
29
34class AuthKey {
35public:
37 const static uint8_t KEY_LEN = 16;
38
44 AuthKey(const std::string key);
45
50 AuthKey();
51
52 // @brief get random string
58 static std::string getRandomKeyString();
59
63 // If the size is greater than 16 bytes, we resize to 16 Bytes
66 void setAuthKey(const std::string& key);
67
71 std::string getAuthKey() {
72 return authKey_;
73 }
74
79 std::string ToText() const;
80
86 bool operator==(const AuthKey& other) const;
87
92 bool operator!=(const AuthKey& other) const;
93
94private:
95 std::string authKey_;
96};
97
107public:
108
112 enum Type {
114 TYPE_PD
115 };
116
130 IPv6Resrv(const Type& type,
131 const asiolink::IOAddress& prefix,
132 const uint8_t prefix_len = 128);
133
136 return (prefix_);
137 }
138
140 uint8_t getPrefixLen() const {
141 return (prefix_len_);
142 }
143
149 Type getType() const {
150 return (type_);
151 }
152
161 void set(const Type& type, const asiolink::IOAddress& prefix,
162 const uint8_t prefix_len);
163
165 std::string toText() const;
166
170 bool operator==(const IPv6Resrv& other) const;
171
175 bool operator!=(const IPv6Resrv& other) const;
176
177private:
178
179 Type type_;
180 asiolink::IOAddress prefix_;
181 uint8_t prefix_len_;
182};
183
185typedef std::multimap<IPv6Resrv::Type, IPv6Resrv> IPv6ResrvCollection;
186typedef IPv6ResrvCollection::const_iterator IPv6ResrvIterator;
187typedef std::pair<IPv6Resrv::Type, IPv6Resrv> IPv6ResrvTuple;
188typedef std::pair<IPv6ResrvIterator, IPv6ResrvIterator> IPv6ResrvRange;
189
242class Host : public data::UserContext {
243public:
244
258 };
259
263
294 Host(const uint8_t* identifier, const size_t identifier_len,
295 const IdentifierType& identifier_type,
296 const SubnetID ipv4_subnet_id, const SubnetID ipv6_subnet_id,
297 const asiolink::IOAddress& ipv4_reservation,
298 const std::string& hostname = "",
299 const std::string& dhcp4_client_classes = "",
300 const std::string& dhcp6_client_classes = "",
302 const std::string& server_host_name = "",
303 const std::string& boot_file_name = "",
304 const AuthKey& auth_key = AuthKey(""));
305
346 Host(const std::string& identifier, const std::string& identifier_name,
347 const SubnetID ipv4_subnet_id, const SubnetID ipv6_subnet_id,
348 const asiolink::IOAddress& ipv4_reservation,
349 const std::string& hostname = "",
350 const std::string& dhcp4_client_classes = "",
351 const std::string& dhcp6_client_classes = "",
353 const std::string& server_host_name = "",
354 const std::string& boot_file_name = "",
355 const AuthKey& auth_key = AuthKey(""));
356
367 void setIdentifier(const uint8_t* identifier, const size_t len,
368 const IdentifierType& type);
369
380 void setIdentifier(const std::string& identifier, const std::string& name);
381
386 HWAddrPtr getHWAddress() const;
387
392 DuidPtr getDuid() const;
393
398 const std::vector<uint8_t>& getIdentifier() const;
399
403
408 static IdentifierType getIdentifierType(const std::string& identifier_name);
409
413 std::string getIdentifierAsText() const;
414
416 static std::string getIdentifierName(const IdentifierType& type);
417
424 static std::string getIdentifierAsText(const IdentifierType& type,
425 const uint8_t* value,
426 const size_t length);
427
431 void setIPv4SubnetID(const SubnetID ipv4_subnet_id) {
432 ipv4_subnet_id_ = ipv4_subnet_id;
433 }
434
438 void setIPv6SubnetID(const SubnetID ipv6_subnet_id) {
439 ipv6_subnet_id_ = ipv6_subnet_id;
440 }
441
444 return (ipv4_subnet_id_);
445 }
446
449 return (ipv6_subnet_id_);
450 }
451
460 void setIPv4Reservation(const asiolink::IOAddress& address);
461
466
471 return (ipv4_reservation_);
472 }
473
477 void addReservation(const IPv6Resrv& reservation);
478
486
492
496 bool hasIPv6Reservation() const;
497
504 bool hasReservation(const IPv6Resrv& reservation) const;
505
509 void setHostname(const std::string& hostname) {
510 hostname_ = hostname;
511 }
512
514 const std::string& getHostname() const {
515 return (hostname_);
516 }
517
521 void addClientClass4(const std::string& class_name);
522
525 return (dhcp4_client_classes_);
526 }
527
531 void addClientClass6(const std::string& class_name);
532
535 return (dhcp6_client_classes_);
536 }
537
544 void setNextServer(const asiolink::IOAddress& next_server);
545
548 return (next_server_);
549 }
550
556 void setServerHostname(const std::string& server_host_name);
557
559 const std::string& getServerHostname() const {
560 return (server_host_name_);
561 }
562
568 void setBootFileName(const std::string& boot_file_name);
569
571 const std::string& getBootFileName() const {
572 return (boot_file_name_);
573 }
574
581 return (cfg_option4_);
582 }
583
587 return (cfg_option4_);
588 }
589
596 return (cfg_option6_);
597 }
598
602 return (cfg_option6_);
603 }
604
606 std::string toText() const;
607
610 void setHostId(HostID id) {
611 host_id_ = id;
612 }
613
617 return (host_id_);
618 }
619
625 void setNegative(bool negative) {
626 negative_ = negative;
627 }
628
631 bool getNegative() const {
632 return (negative_);
633 }
634
639
644
648 void setKey(const AuthKey& key) {
649 key_ = key;
650 }
651
655 AuthKey getKey() const {
656 return(key_);
657 }
658
659private:
660
671 void addClientClassInternal(ClientClasses& classes,
672 const std::string& class_name);
673
675 IdentifierType identifier_type_;
677 std::vector<uint8_t> identifier_value_;
679 SubnetID ipv4_subnet_id_;
681 SubnetID ipv6_subnet_id_;
683 asiolink::IOAddress ipv4_reservation_;
685 IPv6ResrvCollection ipv6_reservations_;
687 std::string hostname_;
689 ClientClasses dhcp4_client_classes_;
691 ClientClasses dhcp6_client_classes_;
693 asiolink::IOAddress next_server_;
695 std::string server_host_name_;
697 std::string boot_file_name_;
698
701 uint64_t host_id_;
702
704 CfgOptionPtr cfg_option4_;
706 CfgOptionPtr cfg_option6_;
707
713 bool negative_;
714
721 AuthKey key_;
722};
723
725typedef boost::shared_ptr<Host> HostPtr;
726
728typedef boost::shared_ptr<const Host> ConstHostPtr;
729
731typedef std::vector<ConstHostPtr> ConstHostCollection;
732
734typedef std::vector<HostPtr> HostCollection;
735
736}
737}
738
739#endif // HOST_H
Defines elements for storing the names of client classes.
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 getAuthKey()
return auth key
Definition: host.h:71
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
Container for storing client class names.
Definition: classify.h:43
Represents a device with IPv4 and/or IPv6 reservations.
Definition: host.h:242
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
void setHostId(HostID id)
Sets Host ID (primary key in MySQL, PostgreSQL and Cassandra backends)
Definition: host.h:610
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
void setNegative(bool negative)
Sets the negative cached flag.
Definition: host.h:625
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
SubnetID getIPv4SubnetID() const
Returns subnet identifier for IPv4 reservation.
Definition: host.h:443
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
SubnetID getIPv6SubnetID() const
Returns subnet identifier for IPv6 reservations.
Definition: host.h:448
void setHostname(const std::string &hostname)
Sets new hostname.
Definition: host.h:509
const asiolink::IOAddress & getIPv4Reservation() const
Returns reserved IPv4 address.
Definition: host.h:470
static const IdentifierType LAST_IDENTIFIER_TYPE
Constant pointing to the last identifier of the IdentifierType enumeration.
Definition: host.h:262
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
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
ConstCfgOptionPtr getCfgOption4() const
Returns const pointer to the DHCPv4 option data configuration for this host.
Definition: host.h:586
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
ConstCfgOptionPtr getCfgOption6() const
Returns const pointer to the DHCPv6 option data configuration for this host.
Definition: host.h:601
std::string getIdentifierAsText() const
Returns host identifier in a textual form.
Definition: host.cc:239
AuthKey getKey() const
Returns the key.
Definition: host.h:655
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 setIPv4SubnetID(const SubnetID ipv4_subnet_id)
Sets new IPv4 subnet identifier.
Definition: host.h:431
void removeIPv4Reservation()
Removes the IPv4 reservation.
Definition: host.cc:358
void setIPv6SubnetID(const SubnetID ipv6_subnet_id)
Sets new IPv6 subnet identifier.
Definition: host.h:438
HWAddrPtr getHWAddress() const
Returns hardware address for which the reservations are made.
Definition: host.cc:226
void setKey(const AuthKey &key)
sets key.
Definition: host.h:648
HostID getHostId() const
Returns Host ID (primary key in MySQL, PostgreSQL and Cassandra backends)
Definition: host.h:616
bool getNegative() const
Return the negative cache flag value.
Definition: host.h:631
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
const asiolink::IOAddress & getPrefix() const
Returns prefix for the reservation.
Definition: host.h:135
Type getType() const
Returns reservation type.
Definition: host.h:149
Type
Type of the reservation.
Definition: host.h:112
uint8_t getPrefixLen() const
Returns prefix length.
Definition: host.h:140
std::string toText() const
Returns information about the reservation in the textual format.
Definition: host.cc:98
bool operator==(const IPv6Resrv &other) const
Equality operator.
Definition: host.cc:109
bool operator!=(const IPv6Resrv &other) const
Inequality operator.
Definition: host.cc:116
boost::shared_ptr< Element > ElementPtr
Definition: data.h:22
IPv6ResrvCollection::const_iterator IPv6ResrvIterator
Definition: host.h:186
boost::shared_ptr< CfgOption > CfgOptionPtr
Non-const pointer.
Definition: cfg_option.h:497
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
Definition: host.h:725
std::vector< ConstHostPtr > ConstHostCollection
Collection of the const Host objects.
Definition: host.h:731
boost::shared_ptr< DUID > DuidPtr
Definition: duid.h:21
std::pair< IPv6ResrvIterator, IPv6ResrvIterator > IPv6ResrvRange
Definition: host.h:188
std::vector< HostPtr > HostCollection
Collection of the Host objects.
Definition: host.h:734
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
Definition: hwaddr.h:154
std::multimap< IPv6Resrv::Type, IPv6Resrv > IPv6ResrvCollection
Collection of IPv6 reservations for the host.
Definition: host.h:185
uint32_t SubnetID
Unique identifier for a subnet (both v4 and v6)
Definition: lease.h:24
uint64_t HostID
HostID (used only when storing in MySQL, PostgreSQL or Cassandra)
Definition: host.h:28
boost::shared_ptr< const Host > ConstHostPtr
Const pointer to the Host object.
Definition: host.h:728
std::pair< IPv6Resrv::Type, IPv6Resrv > IPv6ResrvTuple
Definition: host.h:187
boost::shared_ptr< const CfgOption > ConstCfgOptionPtr
Const pointer.
Definition: cfg_option.h:500
Defines the logger used by the top-level component of kea-dhcp-ddns.
Base class for user context.
Definition: user_context.h:22