25 AuthKey::AuthKey(
const std::string key) {
29 AuthKey::AuthKey(
void) {
30 authKey_ = AuthKey::getRandomKeyString();
34 AuthKey::getRandomKeyString() {
37 result.resize(rs.size());
38 memmove(&result[0], &rs[0], result.size());
43 AuthKey::ToText()
const {
49 AuthKey::setAuthKey(
const std::string& key) {
51 if (authKey_.size() > AuthKey::KEY_LEN) {
52 authKey_.resize(AuthKey::KEY_LEN);
58 return (authKey_ == other.authKey_);
63 return (authKey_ != other.authKey_);
66 IPv6Resrv::IPv6Resrv(
const Type& type,
68 const uint8_t prefix_len)
71 set(type, prefix, prefix_len);
76 const uint8_t prefix_len) {
79 <<
"' for new IPv6 reservation");
81 }
else if (prefix_len > 128) {
83 << static_cast<int>(prefix_len)
84 <<
"' for new IPv6 reservation");
86 }
else if ((type ==
TYPE_NA) && (prefix_len != 128)) {
88 << static_cast<int>(prefix_len)
89 <<
"' for reserved IPv6 address, expected 128");
94 prefix_len_ = prefix_len;
103 s <<
"/" << static_cast<int>(prefix_len_);
110 return (type_ == other.type_ &&
111 prefix_ == other.prefix_ &&
112 prefix_len_ == other.prefix_len_);
117 return (!
operator==(other));
120 Host::Host(
const uint8_t* identifier,
const size_t identifier_len,
124 const std::string& hostname,
125 const std::string& dhcp4_client_classes,
126 const std::string& dhcp6_client_classes,
128 const std::string& server_host_name,
129 const std::string& boot_file_name,
132 : identifier_type_(identifier_type),
133 identifier_value_(), ipv4_subnet_id_(ipv4_subnet_id),
134 ipv6_subnet_id_(ipv6_subnet_id),
136 hostname_(hostname), dhcp4_client_classes_(dhcp4_client_classes),
137 dhcp6_client_classes_(dhcp6_client_classes),
139 server_host_name_(server_host_name), boot_file_name_(boot_file_name),
140 host_id_(0), cfg_option4_(new
CfgOption()),
141 cfg_option6_(new
CfgOption()), negative_(false),
158 Host::Host(
const std::string& identifier,
const std::string& identifier_name,
161 const std::string& hostname,
162 const std::string& dhcp4_client_classes,
163 const std::string& dhcp6_client_classes,
165 const std::string& server_host_name,
166 const std::string& boot_file_name,
168 : identifier_type_(IDENT_HWADDR),
169 identifier_value_(), ipv4_subnet_id_(ipv4_subnet_id),
170 ipv6_subnet_id_(ipv6_subnet_id),
172 hostname_(hostname), dhcp4_client_classes_(dhcp4_client_classes),
173 dhcp6_client_classes_(dhcp6_client_classes),
175 server_host_name_(server_host_name), boot_file_name_(boot_file_name),
176 host_id_(0), cfg_option4_(new
CfgOption()),
177 cfg_option6_(new
CfgOption()), negative_(false),
194 const std::vector<uint8_t>&
196 return (identifier_value_);
201 return (identifier_type_);
206 if (identifier_name ==
"hw-address") {
209 }
else if (identifier_name ==
"duid") {
212 }
else if (identifier_name ==
"circuit-id") {
215 }
else if (identifier_name ==
"client-id") {
217 }
else if (identifier_name ==
"flex-id") {
221 << identifier_name <<
"'");
241 identifier_value_.size()));
246 const size_t length) {
248 std::ostringstream s;
268 s <<
"(invalid-type)";
270 std::vector<uint8_t> vec(value, value + length);
279 return (
"hw-address");
285 return (
"circuit-id");
288 return (
"client-id");
296 return (
"(unknown)");
307 identifier_type_ = type;
308 identifier_value_.assign(identifier, identifier + len);
314 if (identifier.empty()) {
331 if (binary.empty()) {
335 identifier_value_.swap(binary);
341 << identifier <<
"'");
347 if (!address.
isV4()) {
352 << address <<
"' address");
354 ipv4_reservation_ = address;
367 " host reservation for " << reservation.
toText());
376 return (ipv6_reservations_.equal_range(type));
382 ipv6_reservations_.end()));
387 return (!ipv6_reservations_.empty());
393 if (std::distance(reservations.first, reservations.second) > 0) {
395 it != reservations.second; ++it) {
396 if (it->second == reservation) {
408 addClientClassInternal(dhcp4_client_classes_, class_name);
414 addClientClassInternal(dhcp6_client_classes_, class_name);
419 const std::string& class_name) {
421 if (!trimmed.empty()) {
428 if (!next_server.
isV4()) {
430 <<
"' is not a valid IPv4 address");
433 << next_server <<
"'");
436 next_server_ = next_server;
445 server_host_name_ = server_host_name;
454 boot_file_name_ = boot_file_name;
468 map->set(
"hw-address", Element::create(hwaddr->toText(
false)));
471 map->set(
"duid", Element::create(duid->toText()));
475 map->set(
"circuit-id", Element::create(circuit_id));
479 map->set(
"client-id", Element::create(client_id));
483 map->set(
"flex-id", Element::create(flex));
490 map->set(
"ip-address", Element::create(address.
toText()));
494 map->set(
"hostname", Element::create(hostname));
497 map->set(
"next-server", Element::create(next_server.
toText()));
500 map->set(
"server-hostname", Element::create(server_hostname));
503 map->set(
"boot-file-name", Element::create(boot_file_name));
508 cclass != cclasses.
cend(); ++cclass) {
509 classes->add(Element::create(*cclass));
511 map->set(
"client-classes", classes);
514 map->set(
"option-data", opts->toElement());
529 map->set(
"hw-address", Element::create(hwaddr->toText(
false)));
532 map->set(
"duid", Element::create(duid->toText()));
540 map->set(
"flex-id", Element::create(flex));
548 resv != na_resv.second; ++resv) {
549 resvs->add(Element::create(resv->second.toText()));
551 map->set(
"ip-addresses", resvs);
554 resvs = Element::createList();
556 resv != pd_resv.second; ++resv) {
557 resvs->add(Element::create(resv->second.toText()));
559 map->set(
"prefixes", resvs);
562 map->set(
"hostname", Element::create(hostname));
567 cclass != cclasses.
cend(); ++cclass) {
568 classes->add(Element::create(*cclass));
570 map->set(
"client-classes", classes);
574 map->set(
"option-data", opts->toElement());
585 std::ostringstream s;
591 if (ipv4_subnet_id_ != SUBNET_ID_UNUSED) {
592 s <<
" ipv4_subnet_id=" << ipv4_subnet_id_;
596 if (ipv6_subnet_id_ != SUBNET_ID_UNUSED) {
597 s <<
" ipv6_subnet_id=" << ipv6_subnet_id_;
601 s <<
" hostname=" << (hostname_.empty() ?
"(empty)" : hostname_);
604 s <<
" ipv4_reservation=" << (ipv4_reservation_.
isV4Zero() ?
"(no)" :
605 ipv4_reservation_.
toText());
608 s <<
" siaddr=" << (next_server_.
isV4Zero() ?
"(no)" :
612 s <<
" sname=" << (server_host_name_.empty() ?
"(empty)" : server_host_name_);
615 s <<
" file=" << (boot_file_name_.empty() ?
"(empty)" : boot_file_name_);
617 s <<
" key=" << (key_.
ToText().empty() ?
"(empty)" : key_.
ToText());
619 if (ipv6_reservations_.empty()) {
620 s <<
" ipv6_reservations=(none)";
625 resrv != ipv6_reservations_.end(); ++resrv) {
626 s <<
" ipv6_reservation" 627 << std::distance(ipv6_reservations_.begin(), resrv)
628 <<
"=" << resrv->second.toText();
634 cclass != dhcp4_client_classes_.
cend(); ++cclass) {
636 << std::distance(dhcp4_client_classes_.
cbegin(), cclass)
642 cclass != dhcp6_client_classes_.
cend(); ++cclass) {
644 << std::distance(dhcp6_client_classes_.
cbegin(), cclass)
650 s <<
" negative cached";
static const size_t MAX_SNAME_LEN
length of the SNAME field in DHCPv4 message
boost::shared_ptr< DUID > DuidPtr
void setIdentifier(const uint8_t *identifier, const size_t len, const IdentifierType &type)
Replaces currently used identifier with a new identifier.
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
std::string toText() const
Returns information about the reservation in the textual format.
const std::string & getHostname() const
Returns reserved hostname.
boost::shared_ptr< const CfgOption > ConstCfgOptionPtr
Const pointer.
bool operator!=(const Element &a, const Element &b)
static const size_t MAX_FILE_LEN
length of the FILE field in DHCPv4 message
const std::string & getBootFileName() const
Returns value of boot file name (file).
boost::shared_ptr< Element > ElementPtr
IPv6ResrvRange getIPv6Reservations() const
Returns all IPv6 reservations.
static std::string getIdentifierName(const IdentifierType &type)
Returns name of the identifier of a specified type.
isc::data::ElementPtr toElement6() const
Unparses (converts to Element representation) IPv6 host.
IPv6 reservation for a host.
const_iterator cbegin() const
Iterator to the first element.
CfgOptionPtr getCfgOption6()
Returns pointer to the DHCPv6 option data configuration for this host.
void decodeFormattedHexString(const std::string &hex_string, std::vector< uint8_t > &binary)
Converts a formatted string of hexadecimal digits into a vector.
Holds DUID (DHCPv6 Unique Identifier)
const ClientClasses & getClientClasses6() const
Returns classes which DHCPv6 client is associated with.
bool operator==(const Element &a, const Element &b)
const asiolink::IOAddress & getNextServer() const
Returns value of next server field (siaddr).
#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...
std::pair< IPv6ResrvIterator, IPv6ResrvIterator > IPv6ResrvRange
std::list< ClientClass >::const_iterator const_iterator
Type of iterators.
Represents option data configuration for the DHCP server.
std::string getIdentifierAsText() const
Returns host identifier in a textual form.
void addClientClass4(const std::string &class_name)
Adds new client class for DHCPv4.
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.
bool isV4Bcast() const
Convenience function to check if it is an IPv4 broadcast address.
const std::string & getServerHostname() const
Returns value of server hostname (sname).
bool isV4Zero() const
Convenience function to check if it is an IPv4 zero address.
static const IOAddress & IPV4_ZERO_ADDRESS()
Returns an address set to all zeros.
Flexible host identifier.
DuidPtr getDuid() const
Returns DUID for which the reservations are made.
void setServerHostname(const std::string &server_host_name)
Sets new value for server hostname (sname).
void contextToElement(data::ElementPtr map) const
Merge unparse a user_context object.
bool isV6Multicast() const
checks whether and address is IPv6 and is multicast
Type
Type of the reservation.
bool isV6() const
Convenience function to check for an IPv6 address.
bool isV4() const
Convenience function to check for an IPv4 address.
IPv6ResrvCollection::const_iterator IPv6ResrvIterator
std::vector< uint8_t > quotedStringToBinary(const std::string "ed_string)
Converts a string in quotes into vector.
const asiolink::IOAddress & getIPv4Reservation() const
Returns reserved IPv4 address.
Defines the logger used by the top-level component of kea-dhcp-ddns.
Type getType() const
Returns reservation type.
bool operator!=(const IPv6Resrv &other) const
Inequality operator.
HWAddrPtr getHWAddress() const
Returns hardware address for which the reservations are made.
string encodeHex(const vector< uint8_t > &binary)
Encode binary data in the base16 ('hex') format.
void set(const Type &type, const asiolink::IOAddress &prefix, const uint8_t prefix_len)
Sets a new prefix and prefix length.
isc::data::ElementPtr toElement4() const
Unparses (converts to Element representation) IPv4 host.
std::string toText() const
Convert the address to a string.
void addReservation(const IPv6Resrv &reservation)
Adds new IPv6 reservation.
A wrapper interface for the ASIO library.
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.
IdentifierType getIdentifierType() const
Returns the identifier type.
bool operator==(const IPv6Resrv &other) const
Equality operator.
const ClientClasses & getClientClasses4() const
Returns classes which DHCPv4 client is associated with.
const_iterator cend() const
Iterator to the past the end element.
void setBootFileName(const std::string &boot_file_name)
Sets new value for boot file name (file).
Hardware type that represents information from DHCPv4 packet.
std::string toText() const
Returns information about the host in the textual format.
string trim(const string &instring)
Trim Leading and Trailing Spaces.
std::string ToText() const
return text format for keys
void setIPv4Reservation(const asiolink::IOAddress &address)
Sets new IPv4 reservation.
void removeIPv4Reservation()
Removes the IPv4 reservation.
void insert(const ClientClass &class_name)
Insert an element.
bool hasReservation(const IPv6Resrv &reservation) const
Checks if specified IPv6 reservation exists for the host.
IdentifierType
Type of the host identifier.
const std::vector< uint8_t > & getIdentifier() const
Returns the identifier in a binary form.
std::string ClientClass
Defines a single class name.
std::pair< IPv6Resrv::Type, IPv6Resrv > IPv6ResrvTuple
The IOAddress class represents an IP addresses (version agnostic)
std::vector< uint8_t > random(size_t len)
Generate random value.
void setNextServer(const asiolink::IOAddress &next_server)
Sets new value for next server field (siaddr).
Container for storing client class names.
bool hasIPv6Reservation() const
Checks if there is at least one IPv6 reservation for this host.
CfgOptionPtr getCfgOption4()
Returns pointer to the DHCPv4 option data configuration for this host.
uint32_t SubnetID
Unique identifier for a subnet (both v4 and v6)