25 AuthKey::AuthKey(
const std::vector<uint8_t>& key) {
29 AuthKey::AuthKey(
const std::string& key) {
34 authKey_ = AuthKey::getRandomKeyString();
38 AuthKey::getRandomKeyString() {
43 AuthKey::toText()
const {
44 if (authKey_.empty()) {
51 AuthKey::setAuthKey(
const std::vector<uint8_t>& key) {
59 AuthKey::setAuthKey(
const std::string& key) {
65 std::vector<uint8_t> bin;
68 }
catch (
const std::exception& ex) {
75 return (authKey_ == other.authKey_);
80 return (authKey_ != other.authKey_);
83 IPv6Resrv::IPv6Resrv(
const Type& type,
85 const uint8_t prefix_len)
88 set(type, prefix, prefix_len);
93 const uint8_t prefix_len) {
96 <<
"' for new IPv6 reservation");
98 }
else if (prefix_len > 128) {
100 << static_cast<int>(prefix_len)
101 <<
"' for new IPv6 reservation");
103 }
else if ((type ==
TYPE_NA) && (prefix_len != 128)) {
105 << static_cast<int>(prefix_len)
106 <<
"' for reserved IPv6 address, expected 128");
111 prefix_len_ = prefix_len;
116 std::ostringstream s;
120 s <<
"/" <<
static_cast<int>(prefix_len_);
127 return (type_ == other.type_ &&
128 prefix_ == other.prefix_ &&
129 prefix_len_ == other.prefix_len_);
134 return (!
operator==(other));
137 Host::Host(
const uint8_t* identifier,
const size_t identifier_len,
141 const std::string& hostname,
142 const std::string& dhcp4_client_classes,
143 const std::string& dhcp6_client_classes,
145 const std::string& server_host_name,
146 const std::string& boot_file_name,
149 : identifier_type_(identifier_type),
150 identifier_value_(), ipv4_subnet_id_(ipv4_subnet_id),
151 ipv6_subnet_id_(ipv6_subnet_id),
153 hostname_(hostname), dhcp4_client_classes_(dhcp4_client_classes),
154 dhcp6_client_classes_(dhcp6_client_classes),
156 server_host_name_(server_host_name), boot_file_name_(boot_file_name),
157 host_id_(0), cfg_option4_(new
CfgOption()),
158 cfg_option6_(new
CfgOption()), negative_(false),
175 Host::Host(
const std::string& identifier,
const std::string& identifier_name,
178 const std::string& hostname,
179 const std::string& dhcp4_client_classes,
180 const std::string& dhcp6_client_classes,
182 const std::string& server_host_name,
183 const std::string& boot_file_name,
185 : identifier_type_(IDENT_HWADDR),
186 identifier_value_(), ipv4_subnet_id_(ipv4_subnet_id),
187 ipv6_subnet_id_(ipv6_subnet_id),
189 hostname_(hostname), dhcp4_client_classes_(dhcp4_client_classes),
190 dhcp6_client_classes_(dhcp6_client_classes),
192 server_host_name_(server_host_name), boot_file_name_(boot_file_name),
193 host_id_(0), cfg_option4_(new
CfgOption()),
194 cfg_option6_(new
CfgOption()), negative_(false),
211 const std::vector<uint8_t>&
213 return (identifier_value_);
218 return (identifier_type_);
223 if (identifier_name ==
"hw-address") {
226 }
else if (identifier_name ==
"duid") {
229 }
else if (identifier_name ==
"circuit-id") {
232 }
else if (identifier_name ==
"client-id") {
234 }
else if (identifier_name ==
"flex-id") {
238 << identifier_name <<
"'");
258 identifier_value_.size()));
263 const size_t length) {
265 std::ostringstream s;
285 s <<
"(invalid-type)";
287 std::vector<uint8_t> vec(value, value + length);
296 return (
"hw-address");
302 return (
"circuit-id");
305 return (
"client-id");
313 return (
"(unknown)");
324 identifier_type_ = type;
325 identifier_value_.assign(identifier, identifier + len);
331 if (identifier.empty()) {
348 if (binary.empty()) {
352 identifier_value_.swap(binary);
358 << identifier <<
"'");
364 if (!address.
isV4()) {
369 << address <<
"' address");
371 ipv4_reservation_ = address;
384 " host reservation for " << reservation.
toText());
393 return (ipv6_reservations_.equal_range(type));
399 ipv6_reservations_.end()));
404 return (!ipv6_reservations_.empty());
410 if (std::distance(reservations.first, reservations.second) > 0) {
412 it != reservations.second; ++it) {
413 if (it->second == reservation) {
425 addClientClassInternal(dhcp4_client_classes_, class_name);
431 addClientClassInternal(dhcp6_client_classes_, class_name);
436 const std::string& class_name) {
438 if (!trimmed.empty()) {
445 if (!next_server.
isV4()) {
447 <<
"' is not a valid IPv4 address");
450 << next_server <<
"'");
453 next_server_ = next_server;
462 server_host_name_ = server_host_name;
471 boot_file_name_ = boot_file_name;
485 map->set(
"hw-address", Element::create(hwaddr->toText(
false)));
488 map->set(
"duid", Element::create(duid->toText()));
492 map->set(
"circuit-id", Element::create(circuit_id));
496 map->set(
"client-id", Element::create(client_id));
500 map->set(
"flex-id", Element::create(flex));
507 map->set(
"ip-address", Element::create(address.
toText()));
511 map->set(
"hostname", Element::create(hostname));
514 map->set(
"next-server", Element::create(next_server.
toText()));
517 map->set(
"server-hostname", Element::create(server_hostname));
520 map->set(
"boot-file-name", Element::create(boot_file_name));
525 cclass != cclasses.
cend(); ++cclass) {
526 classes->add(Element::create(*cclass));
528 map->set(
"client-classes", classes);
531 map->set(
"option-data", opts->toElement());
546 map->set(
"hw-address", Element::create(hwaddr->toText(
false)));
549 map->set(
"duid", Element::create(duid->toText()));
557 map->set(
"flex-id", Element::create(flex));
565 resv != na_resv.second; ++resv) {
566 resvs->add(Element::create(resv->second.toText()));
568 map->set(
"ip-addresses", resvs);
571 resvs = Element::createList();
573 resv != pd_resv.second; ++resv) {
574 resvs->add(Element::create(resv->second.toText()));
576 map->set(
"prefixes", resvs);
579 map->set(
"hostname", Element::create(hostname));
584 cclass != cclasses.
cend(); ++cclass) {
585 classes->add(Element::create(*cclass));
587 map->set(
"client-classes", classes);
591 map->set(
"option-data", opts->toElement());
602 std::ostringstream s;
608 if (ipv4_subnet_id_ != SUBNET_ID_UNUSED) {
609 s <<
" ipv4_subnet_id=" << ipv4_subnet_id_;
613 if (ipv6_subnet_id_ != SUBNET_ID_UNUSED) {
614 s <<
" ipv6_subnet_id=" << ipv6_subnet_id_;
618 s <<
" hostname=" << (hostname_.empty() ?
"(empty)" : hostname_);
621 s <<
" ipv4_reservation=" << (ipv4_reservation_.
isV4Zero() ?
"(no)" :
622 ipv4_reservation_.
toText());
625 s <<
" siaddr=" << (next_server_.
isV4Zero() ?
"(no)" :
629 s <<
" sname=" << (server_host_name_.empty() ?
"(empty)" : server_host_name_);
632 s <<
" file=" << (boot_file_name_.empty() ?
"(empty)" : boot_file_name_);
634 s <<
" key=" << (key_.
toText().empty() ?
"(empty)" : key_.
toText());
636 if (ipv6_reservations_.empty()) {
637 s <<
" ipv6_reservations=(none)";
642 resrv != ipv6_reservations_.end(); ++resrv) {
643 s <<
" ipv6_reservation"
644 << std::distance(ipv6_reservations_.begin(), resrv)
645 <<
"=" << resrv->second.toText();
651 cclass != dhcp4_client_classes_.
cend(); ++cclass) {
653 << std::distance(dhcp4_client_classes_.
cbegin(), cclass)
659 cclass != dhcp6_client_classes_.
cend(); ++cclass) {
661 << std::distance(dhcp6_client_classes_.
cbegin(), cclass)
667 s <<
" negative cached";
std::string getIdentifierAsText() const
Returns host identifier in a textual form.
static const size_t MAX_SNAME_LEN
length of the SNAME field in DHCPv4 message
std::string toText() const
Returns information about the reservation in the textual format.
bool isV4Bcast() const
Convenience function to check if it is an IPv4 broadcast address.
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.
std::string toText() const
Returns information about the host in the textual format.
const asiolink::IOAddress & getNextServer() const
Returns value of next server field (siaddr).
const ClientClasses & getClientClasses4() const
Returns classes which DHCPv4 client is associated with.
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
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
boost::shared_ptr< Element > ElementPtr
static std::string getIdentifierName(const IdentifierType &type)
Returns name of the identifier of a specified type.
IPv6 reservation for a host.
CfgOptionPtr getCfgOption6()
Returns pointer to the DHCPv6 option data configuration for this host.
void contextToElement(data::ElementPtr map) const
Merge unparse a user_context object.
void decodeFormattedHexString(const std::string &hex_string, std::vector< uint8_t > &binary)
Converts a formatted string of hexadecimal digits into a vector.
bool isV4() const
Convenience function to check for an IPv4 address.
Holds DUID (DHCPv6 Unique Identifier)
const std::string & getServerHostname() const
Returns value of server hostname (sname).
bool hasReservation(const IPv6Resrv &reservation) const
Checks if specified IPv6 reservation exists for the host.
bool operator!=(const IPv6Resrv &other) const
Inequality operator.
bool operator==(const Element &a, const Element &b)
#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...
const asiolink::IOAddress & getIPv4Reservation() const
Returns reserved IPv4 address.
std::pair< IPv6ResrvIterator, IPv6ResrvIterator > IPv6ResrvRange
std::list< ClientClass >::const_iterator const_iterator
Type of iterators.
Represents option data configuration for the DHCP server.
bool operator==(const IPv6Resrv &other) const
Equality operator.
const_iterator cend() const
Iterator to the past the end element.
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.
const std::string & getBootFileName() const
Returns value of boot file name (file).
void decodeHex(const string &input, vector< uint8_t > &result)
Decode a text encoded in the base16 ('hex') format into the original data.
const std::vector< uint8_t > & getIdentifier() const
Returns the identifier in a binary form.
static const IOAddress & IPV4_ZERO_ADDRESS()
Returns an address set to all zeros.
Flexible host identifier.
IdentifierType getIdentifierType() const
Returns the identifier type.
std::string toText() const
Return text format for keys.
void setServerHostname(const std::string &server_host_name)
Sets new value for server hostname (sname).
IPv6ResrvRange getIPv6Reservations() const
Returns all IPv6 reservations.
bool isV4Zero() const
Convenience function to check if it is an IPv4 zero address.
isc::data::ElementPtr toElement6() const
Unparses (converts to Element representation) IPv6 host.
Type
Type of the reservation.
IPv6ResrvCollection::const_iterator IPv6ResrvIterator
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
std::vector< uint8_t > quotedStringToBinary(const std::string "ed_string)
Converts a string in quotes into vector.
const std::string & getHostname() const
Returns reserved hostname.
Defines the logger used by the top-level component of kea-dhcp-ddns.
void set(const Type &type, const asiolink::IOAddress &prefix, const uint8_t prefix_len)
Sets a new prefix and prefix length.
string encodeHex(const vector< uint8_t > &binary)
Encode binary data in the base16 ('hex') format.
HWAddrPtr getHWAddress() const
Returns hardware address for which the reservations are made.
void addReservation(const IPv6Resrv &reservation)
Adds new IPv6 reservation.
A wrapper interface for the ASIO library.
const ClientClasses & getClientClasses6() const
Returns classes which DHCPv6 client is associated with.
Type getType() const
Returns reservation type.
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.
std::string toText() const
Convert the address to a string.
void setBootFileName(const std::string &boot_file_name)
Sets new value for boot file name (file).
Hardware type that represents information from DHCPv4 packet.
bool isV6() const
Convenience function to check for an IPv6 address.
string trim(const string &instring)
Trim Leading and Trailing Spaces.
bool hasIPv6Reservation() const
Checks if there is at least one IPv6 reservation for this host.
void setIPv4Reservation(const asiolink::IOAddress &address)
Sets new IPv4 reservation.
bool isV6Multicast() const
checks whether and address is IPv6 and is multicast
void removeIPv4Reservation()
Removes the IPv4 reservation.
void insert(const ClientClass &class_name)
Insert an element.
IdentifierType
Type of the host identifier.
std::string ClientClass
Defines a single class name.
std::pair< IPv6Resrv::Type, IPv6Resrv > IPv6ResrvTuple
The IOAddress class represents an IP addresses (version agnostic)
const uint8_t AUTH_KEY_LEN
Maximum length of authentication keys - 128 bits.
std::vector< uint8_t > random(size_t len)
Generate random value.
const_iterator cbegin() const
Iterator to the first element.
isc::data::ElementPtr toElement4() const
Unparses (converts to Element representation) IPv4 host.
void setNextServer(const asiolink::IOAddress &next_server)
Sets new value for next server field (siaddr).
Container for storing client class names.
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)
DuidPtr getDuid() const
Returns DUID for which the reservations are made.