12#include <boost/pointer_cast.hpp>
13#include <boost/lexical_cast.hpp>
33 mutable_cfg = boost::const_pointer_cast<Element>(
config);
38 if (!mutable_cfg || (mutable_cfg->getType() !=
Element::map)) {
45 int64_t maximum =
getInteger(mutable_cfg,
"maximum");
51 <<
"(" << maximum <<
" > " <<
MAXIMUM <<
")");
53 hcref.
setMaximum(
static_cast<size_t>(maximum));
56 }
catch (
const exception& ex) {
66 string identifier_name;
69 auto& map = entry->mapValue();
70 for (
auto const& element : map) {
71 if ((element.first ==
"hw-address") ||
72 (element.first ==
"duid") ||
73 (element.first ==
"circuit-id") ||
74 (element.first ==
"client-id") ||
75 (element.first ==
"flex-id")) {
76 if (!identifier_name.empty()) {
78 <<
"' and '" << identifier_name
79 <<
"' are mutually exclusive");
81 identifier = element.second->stringValue();
82 identifier_name = element.first;
86 if (element.first ==
"hostname") {
87 hostname = element.second->stringValue();
91 if (element.first ==
"user-context") {
92 user_context = element.second;
98 if (identifier_name.empty()) {
104 host.reset(
new Host(identifier, identifier_name,
110 host->setContext(user_context);
114 for (
auto const& element : map) {
115 if ((element.first ==
"hw-address") ||
116 (element.first ==
"duid") ||
117 (element.first ==
"circuit-id") ||
118 (element.first ==
"client-id") ||
119 (element.first ==
"flex-id") ||
120 (element.first ==
"hostname") ||
121 (element.first ==
"user-context")) {
125 if (element.first ==
"subnet-id4") {
126 host->setIPv4SubnetID(element.second->intValue());
130 if (element.first ==
"subnet-id6") {
131 host->setIPv6SubnetID(element.second->intValue());
135 if (element.first ==
"option-data4") {
138 parser.
parse(cfg_option, element.second);
142 if (element.first ==
"option-data6") {
145 parser.
parse(cfg_option, element.second);
149 if (element.first ==
"ip-address") {
150 host->setIPv4Reservation(
IOAddress(element.second->stringValue()));
154 if (element.first ==
"next-server") {
155 host->setNextServer(
IOAddress(element.second->stringValue()));
159 if (element.first ==
"server-hostname") {
160 host->setServerHostname(element.second->stringValue());
164 if (element.first ==
"boot-file-name") {
165 host->setBootFileName(element.second->stringValue());
169 if (element.first ==
"client-classes4") {
170 auto const& classes = element.second->listValue();
171 for (
auto const& cclass : classes) {
172 host->addClientClass4(cclass->stringValue());
177 if (element.first ==
"client-classes6") {
178 auto const& classes = element.second->listValue();
179 for (
auto const& cclass : classes) {
180 host->addClientClass6(cclass->stringValue());
185 if (element.first ==
"ip-addresses") {
186 auto const& addresses = element.second->listValue();
187 for (
auto const& addr : addresses) {
188 string address = addr->stringValue();
196 if (element.first ==
"prefixes") {
197 auto& prefixes = element.second->listValue();
198 for (
auto const& pref : prefixes) {
199 string prefix = pref->stringValue();
201 size_t pos = prefix.find(
'/');
202 if (pos == string::npos) {
204 }
else if (pos > prefix.length() - 1) {
208 string preflen = prefix.substr(pos + 1);
209 len = boost::lexical_cast<unsigned>(preflen);
210 }
catch (
const boost::bad_lexical_cast&) {
222 if (element.first ==
"host-id") {
223 int64_t hid = element.second->intValue();
224 host->setHostId(
static_cast<uint64_t
>(hid));
228 if (element.first ==
"negative") {
229 host->setNegative(element.second->boolValue());
239 }
catch (
const exception& ex) {
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
An exception that is thrown if an error occurs while configuring any server.
IOAddress(const std::string &address_str)
Constructor from string.
static int64_t getInteger(isc::data::ConstElementPtr scope, const std::string &name)
Returns an integer parameter from a scope.
static size_t setDefaults(isc::data::ElementPtr scope, const SimpleDefaults &default_values)
Sets the default values.
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.
IPv6Resrv(const Type &type, const asiolink::IOAddress &prefix, const uint8_t prefix_len=128)
Constructor.
Parser for option data values within a subnet.
void parse(const CfgOptionPtr &cfg, isc::data::ConstElementPtr option_data_list, bool encapsulate=true)
Parses a list of options, instantiates them and stores in cfg.
static const int64_t MAXIMUM
Absolute maximum number of elements.
static const data::SimpleDefaults HOST_CACHE_DEFAULTS
Defaults for Host Cache configuration.
void parse(HostCache &hcref, const data::ConstElementPtr &config)
Parses Host Cache configuration.
dhcp::HostPtr parse(const data::ConstElementPtr &entry)
Parses Host Cache entry.
Host Cache implementation.
virtual void setMaximum(size_t maximum)
Set maximum number of cached hosts (0 means unbound).
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< const Element > ConstElementPtr
std::vector< SimpleDefault > SimpleDefaults
This specifies all default values in a given scope (e.g. a subnet).
boost::shared_ptr< Element > ElementPtr
boost::shared_ptr< CfgOption > CfgOptionPtr
Non-const pointer.
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Defines the logger used by the top-level component of kea-lfc.