18 #include <boost/make_shared.hpp> 19 #include <boost/pointer_cast.hpp> 29 SharedNetwork4Parser::SharedNetwork4Parser(
bool check_iface)
30 : check_iface_(check_iface) {
44 std::string name =
getString(shared_network_data,
"name");
49 mutable_params = boost::const_pointer_cast<
Element>(shared_network_data);
57 if (shared_network_data->contains(
"interface")) {
58 std::string iface =
getString(shared_network_data,
"interface");
62 shared_network_data->get(
"interface");
64 "Specified network interface name " << iface
65 <<
" for shared network " << name
66 <<
" is not present in the system (" 67 << error->getPosition() <<
")");
69 shared_network->setIface(iface);
73 if (shared_network_data->contains(
"option-data")) {
74 auto json = shared_network_data->get(
"option-data");
76 CfgOptionPtr cfg_option = shared_network->getCfgOption();
78 parser->parse(cfg_option, json);
81 if (shared_network_data->contains(
"subnet4")) {
82 auto json = shared_network_data->get(
"subnet4");
87 parser->parse(subnets, json);
90 for (
auto subnet = subnets.cbegin(); subnet != subnets.cend();
92 shared_network->add(*subnet);
96 if (shared_network_data->contains(
"match-client-id")) {
97 shared_network->setMatchClientId(
getBoolean(shared_network_data,
101 if (shared_network_data->contains(
"authoritative")) {
102 shared_network->setAuthoritative(
getBoolean(shared_network_data,
107 if (shared_network_data->contains(
"next-server")) {
108 std::string next_server;
110 next_server =
getString(shared_network_data,
"next-server");
111 if (!next_server.empty()) {
112 shared_network->setSiaddr(
IOAddress(next_server));
118 pos = next->getPosition().str();
120 pos = shared_network_data->getPosition().str();
123 << next_server <<
"(" << pos <<
")");
128 if (shared_network_data->contains(
"server-hostname")) {
129 std::string sname =
getString(shared_network_data,
"server-hostname");
130 if (!sname.empty()) {
135 << sname.length() <<
" (" 136 << error->getPosition() <<
")");
138 shared_network->setSname(sname);
143 if (shared_network_data->contains(
"boot-file-name")) {
144 std::string filename =
getString(shared_network_data,
"boot-file-name");
145 if (!filename.empty()) {
150 << filename.length() <<
" (" 151 << error->getPosition() <<
")");
153 shared_network->setFilename(filename);
157 if (shared_network_data->contains(
"client-class")) {
158 std::string client_class =
getString(shared_network_data,
"client-class");
159 if (!client_class.empty()) {
160 shared_network->allowClientClass(client_class);
164 ConstElementPtr user_context = shared_network_data->get(
"user-context");
166 shared_network->setContext(user_context);
169 if (shared_network_data->contains(
"require-client-classes")) {
170 const std::vector<data::ElementPtr>& class_list =
171 shared_network_data->get(
"require-client-classes")->listValue();
172 for (
auto cclass = class_list.cbegin();
173 cclass != class_list.cend(); ++cclass) {
174 if (((*cclass)->getType() != Element::string) ||
175 (*cclass)->stringValue().empty()) {
177 << (*cclass)->getPosition() <<
")");
179 shared_network->requireClientClass((*cclass)->stringValue());
183 if (shared_network_data->contains(
"relay")) {
184 auto relay_parms = shared_network_data->get(
"relay");
188 parser.
parse(relay_info, relay_parms);
189 shared_network->setRelayInfo(*relay_info);
203 }
catch (
const std::exception& ex) {
205 << shared_network_data->getPosition() <<
")");
215 return (shared_network);
218 boost::shared_ptr<OptionDataListParser>
220 auto parser = boost::make_shared<OptionDataListParser>(AF_INET);
224 boost::shared_ptr<Subnets4ListConfigParser>
226 auto parser = boost::make_shared<Subnets4ListConfigParser>(
check_iface_);
241 shared_network_data);
245 std::string name =
getString(shared_network_data,
"name");
250 mutable_params = boost::const_pointer_cast<
Element>(shared_network_data);
259 "preferred-lifetime"));
264 if (shared_network_data->contains(
"interface-id")) {
265 ifaceid =
getString(shared_network_data,
"interface-id");
270 if (shared_network_data->contains(
"interface")) {
271 iface =
getString(shared_network_data,
"interface");
280 "parser error: interface (defined for locally reachable " 281 "subnets) and interface-id (defined for subnets reachable" 282 " via relays) cannot be defined at the same time for " 283 "shared network " << name <<
"(" 284 << shared_network_data->getPosition() <<
")");
289 std::string ifaceid_value = ifaceid.
get();
290 OptionBuffer tmp(ifaceid_value.begin(), ifaceid_value.end());
292 shared_network->setInterfaceId(opt);
301 "Specified network interface name " << iface
302 <<
" for shared network " << name
303 <<
" is not present in the system (" 304 << error->getPosition() <<
")");
306 shared_network->setIface(iface);
309 if (shared_network_data->contains(
"rapid-commit")) {
310 shared_network->setRapidCommit(
getBoolean(shared_network_data,
314 if (shared_network_data->contains(
"option-data")) {
315 auto json = shared_network_data->get(
"option-data");
317 CfgOptionPtr cfg_option = shared_network->getCfgOption();
319 parser->parse(cfg_option, json);
322 if (shared_network_data->contains(
"client-class")) {
323 std::string client_class =
getString(shared_network_data,
"client-class");
324 if (!client_class.empty()) {
325 shared_network->allowClientClass(client_class);
329 ConstElementPtr user_context = shared_network_data->get(
"user-context");
331 shared_network->setContext(user_context);
334 if (shared_network_data->contains(
"require-client-classes")) {
335 const std::vector<data::ElementPtr>& class_list =
336 shared_network_data->get(
"require-client-classes")->listValue();
337 for (
auto cclass = class_list.cbegin();
338 cclass != class_list.cend(); ++cclass) {
339 if (((*cclass)->getType() != Element::string) ||
340 (*cclass)->stringValue().empty()) {
342 << (*cclass)->getPosition() <<
")");
344 shared_network->requireClientClass((*cclass)->stringValue());
348 if (shared_network_data->contains(
"subnet6")) {
349 auto json = shared_network_data->get(
"subnet6");
354 parser->parse(subnets, json);
357 for (
auto subnet = subnets.cbegin(); subnet != subnets.cend();
359 shared_network->add(*subnet);
363 if (shared_network_data->contains(
"relay")) {
364 auto relay_parms = shared_network_data->get(
"relay");
368 parser.
parse(relay_info, relay_parms);
369 shared_network->setRelayInfo(*relay_info);
380 }
catch (
const std::exception& ex) {
382 << shared_network_data->getPosition() <<
")");
392 return (shared_network);
395 boost::shared_ptr<OptionDataListParser>
397 auto parser = boost::make_shared<OptionDataListParser>(AF_INET6);
401 boost::shared_ptr<Subnets6ListConfigParser>
403 auto parser = boost::make_shared<Subnets6ListConfigParser>(
check_iface_);
void parseDdnsParams(const data::ConstElementPtr &network_data, NetworkPtr &network)
Parses parameters pertaining to DDNS behavior.
static const size_t MAX_SNAME_LEN
length of the SNAME field in DHCPv4 message
IfacePtr getIface(int ifindex)
Returns interface specified interface index.
static bool getBoolean(isc::data::ConstElementPtr scope, const std::string &name)
Returns a boolean parameter from a scope.
void unspecified(bool unspecified)
Modifies the flag that indicates whether the value is specified or unspecified.
boost::shared_ptr< CfgOption > CfgOptionPtr
Non-const pointer.
bool check_iface_
Check if the specified interface exists in the system.
boost::shared_ptr< Network > NetworkPtr
Pointer to the Network object.
static const isc::data::SimpleKeywords SHARED_NETWORK6_PARAMETERS
This table defines all shared network parameters for DHCPv6.
boost::shared_ptr< Network::RelayInfo > RelayInfoPtr
Pointer to the RelayInfo structure.
void parseCommon(const data::ConstElementPtr &network_data, NetworkPtr &network)
Parses common parameters.
static const size_t MAX_FILE_LEN
length of the FILE field in DHCPv4 message
static CfgMgr & instance()
returns a single instance of Configuration Manager
static const isc::data::SimpleKeywords SHARED_NETWORK4_PARAMETERS
This table defines all shared network parameters for DHCPv4.
boost::shared_ptr< Option > OptionPtr
virtual boost::shared_ptr< OptionDataListParser > createOptionDataListParser() const
Returns an instance of the OptionDataListParser to be used in parsing the option-data structure...
boost::shared_ptr< const CfgGlobals > ConstCfgGlobalsPtr
Const shared pointer to a CfgGlobals instance.
T get() const
Retrieves the encapsulated value.
void parseCacheParams(const data::ConstElementPtr &network_data, NetworkPtr &network)
Parses parameters related to lease cache settings.
boost::shared_ptr< Element > ElementPtr
bool check_iface_
Check if the specified interface exists in the system.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
Shared network holding IPv4 subnets.
Holds optional information about relay.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
SharedNetwork6Ptr parse(const data::ConstElementPtr &shared_network_data)
Parses shared configuration information for IPv6 shared network.
boost::multi_index_container< Subnet4Ptr, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetSubnetIdIndexTag >, boost::multi_index::const_mem_fun< Subnet, SubnetID, &Subnet::getID > >, boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetPrefixIndexTag >, boost::multi_index::const_mem_fun< Subnet, std::string, &Subnet::toText > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetServerIdIndexTag >, boost::multi_index::const_mem_fun< Network4, asiolink::IOAddress, &Network4::getServerId > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetModificationTimeIndexTag >, boost::multi_index::const_mem_fun< data::BaseStampedElement, boost::posix_time::ptime, &data::BaseStampedElement::getModificationTime > > >> Subnet4Collection
A collection of Subnet4 objects.
parser for additional relay information
To be removed. Please use ConfigError instead.
void parseTeePercents(const data::ConstElementPtr &network_data, NetworkPtr &network)
Parses parameters related to "percent" timers settings.
Common interface representing a network to which the DHCP clients are connected.
static void moveReservationMode(isc::data::ElementPtr config)
Moves deprecated reservation-mode parameter to new reservations flags.
boost::shared_ptr< const Element > ConstElementPtr
static std::string getString(isc::data::ConstElementPtr scope, const std::string &name)
Returns a string parameter from a scope.
boost::shared_ptr< SharedNetwork6 > SharedNetwork6Ptr
Pointer to SharedNetwork6 object.
virtual boost::shared_ptr< Subnets4ListConfigParser > createSubnetsListParser() const
Returns an instance of the Subnets4ListConfigParser to be used for parsing the subnets within the sha...
boost::shared_ptr< SharedNetwork4 > SharedNetwork4Ptr
Pointer to SharedNetwork4 object.
boost::multi_index_container< Subnet6Ptr, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetSubnetIdIndexTag >, boost::multi_index::const_mem_fun< Subnet, SubnetID, &Subnet::getID > >, boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetPrefixIndexTag >, boost::multi_index::const_mem_fun< Subnet, std::string, &Subnet::toText > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetModificationTimeIndexTag >, boost::multi_index::const_mem_fun< data::BaseStampedElement, boost::posix_time::ptime, &data::BaseStampedElement::getModificationTime > > >> Subnet6Collection
A collection of Subnet6 objects.
virtual boost::shared_ptr< OptionDataListParser > createOptionDataListParser() const
Returns an instance of the OptionDataListParser to be used in parsing the option-data structure...
Defines the logger used by the top-level component of kea-lfc.
SharedNetwork6Parser(bool check_iface=true)
Constructor.
void parse(const isc::dhcp::Network::RelayInfoPtr &relay_info, isc::data::ConstElementPtr relay_elem)
parses the actual relay parameters
static IfaceMgr & instance()
IfaceMgr is a singleton class.
static void checkKeywords(const SimpleKeywords &keywords, isc::data::ConstElementPtr scope)
Checks acceptable keywords with their expected type.
The Element class represents a piece of data, used by the command channel and configuration parts...
Shared network holding IPv6 subnets.
const isc::util::Triplet< uint32_t > parseIntTriplet(const data::ConstElementPtr &scope, const std::string &name)
Parses an integer triplet.
virtual boost::shared_ptr< Subnets6ListConfigParser > createSubnetsListParser() const
Returns an instance of the Subnets6ListConfigParser to be used for parsing the subnets within the sha...
The IOAddress class represents an IP addresses (version agnostic)
bool empty() const
Checks if the encapsulated value is empty.
SharedNetwork4Ptr parse(const data::ConstElementPtr &shared_network_data)
Parses shared configuration information for IPv4 shared network.