Commit 011f0be3 authored by Francis Dupont's avatar Francis Dupont

[850-unable-to-set-not-present-interface-for-a-subnet-via-remote] not present interface: first pass

parent 37d5c94d
......@@ -556,12 +556,15 @@ Pools4ListParser::parse(PoolStoragePtr pools, ConstElementPtr pools_list) {
SubnetConfigParser::SubnetConfigParser(uint16_t family)
: pools_(new PoolStorage()),
address_family_(family),
options_(new CfgOption()) {
options_(new CfgOption()),
check_iface_(true) {
relay_info_.reset(new isc::dhcp::Network::RelayInfo());
}
SubnetPtr
SubnetConfigParser::parse(ConstElementPtr subnet) {
SubnetConfigParser::parse(ConstElementPtr subnet, bool check_iface) {
check_iface_ = check_iface;
ConstElementPtr options_params = subnet->get("option-data");
if (options_params) {
......@@ -682,7 +685,7 @@ Subnet4ConfigParser::Subnet4ConfigParser()
}
Subnet4Ptr
Subnet4ConfigParser::parse(ConstElementPtr subnet) {
Subnet4ConfigParser::parse(ConstElementPtr subnet, bool check_iface) {
// Check parameters.
checkKeywords(SimpleParser4::SUBNET4_PARAMETERS, subnet);
......@@ -693,7 +696,7 @@ Subnet4ConfigParser::parse(ConstElementPtr subnet) {
parser.parse(pools_, pools);
}
SubnetPtr generic = SubnetConfigParser::parse(subnet);
SubnetPtr generic = SubnetConfigParser::parse(subnet, check_iface);
if (!generic) {
// Sanity check: not supposed to fail.
......@@ -831,7 +834,7 @@ Subnet4ConfigParser::initSubnet(data::ConstElementPtr params,
if (params->contains("interface")) {
std::string iface = getString(params, "interface");
if (!iface.empty()) {
if (!IfaceMgr::instance().getIface(iface)) {
if (check_iface_ && !IfaceMgr::instance().getIface(iface)) {
ConstElementPtr error = params->get("interface");
isc_throw(DhcpConfigError, "Specified network interface name " << iface
<< " for subnet " << subnet4->toText()
......@@ -933,12 +936,14 @@ Subnet4ConfigParser::initSubnet(data::ConstElementPtr params,
//**************************** Subnets4ListConfigParser **********************
size_t
Subnets4ListConfigParser::parse(SrvConfigPtr cfg, ConstElementPtr subnets_list) {
Subnets4ListConfigParser::parse(SrvConfigPtr cfg,
ConstElementPtr subnets_list,
bool check_iface) {
size_t cnt = 0;
BOOST_FOREACH(ConstElementPtr subnet_json, subnets_list->listValue()) {
Subnet4ConfigParser parser;
Subnet4Ptr subnet = parser.parse(subnet_json);
Subnet4Ptr subnet = parser.parse(subnet_json, check_iface);
if (subnet) {
// Adding a subnet to the Configuration Manager may fail if the
......@@ -958,12 +963,13 @@ Subnets4ListConfigParser::parse(SrvConfigPtr cfg, ConstElementPtr subnets_list)
size_t
Subnets4ListConfigParser::parse(Subnet4Collection& subnets,
data::ConstElementPtr subnets_list) {
data::ConstElementPtr subnets_list,
bool check_iface) {
size_t cnt = 0;
BOOST_FOREACH(ConstElementPtr subnet_json, subnets_list->listValue()) {
Subnet4ConfigParser parser;
Subnet4Ptr subnet = parser.parse(subnet_json);
Subnet4Ptr subnet = parser.parse(subnet_json, check_iface);
if (subnet) {
try {
auto ret = subnets.push_back(subnet);
......@@ -1117,7 +1123,7 @@ Subnet6ConfigParser::Subnet6ConfigParser()
}
Subnet6Ptr
Subnet6ConfigParser::parse(ConstElementPtr subnet) {
Subnet6ConfigParser::parse(ConstElementPtr subnet, bool check_iface) {
// Check parameters.
checkKeywords(SimpleParser6::SUBNET6_PARAMETERS, subnet);
......@@ -1133,7 +1139,7 @@ Subnet6ConfigParser::parse(ConstElementPtr subnet) {
parser.parse(pools_, pd_pools);
}
SubnetPtr generic = SubnetConfigParser::parse(subnet);
SubnetPtr generic = SubnetConfigParser::parse(subnet, check_iface);
if (!generic) {
// Sanity check: not supposed to fail.
......@@ -1269,7 +1275,7 @@ Subnet6ConfigParser::initSubnet(data::ConstElementPtr params,
// Get interface name. If it is defined, then the subnet is available
// directly over specified network interface.
if (!iface.unspecified() && !iface.empty()) {
if (!IfaceMgr::instance().getIface(iface)) {
if (check_iface_ && !IfaceMgr::instance().getIface(iface)) {
ConstElementPtr error = params->get("interface");
isc_throw(DhcpConfigError, "Specified network interface name " << iface
<< " for subnet " << subnet6->toText()
......@@ -1325,12 +1331,14 @@ Subnet6ConfigParser::initSubnet(data::ConstElementPtr params,
//**************************** Subnet6ListConfigParser ********************
size_t
Subnets6ListConfigParser::parse(SrvConfigPtr cfg, ConstElementPtr subnets_list) {
Subnets6ListConfigParser::parse(SrvConfigPtr cfg,
ConstElementPtr subnets_list,
bool check_iface) {
size_t cnt = 0;
BOOST_FOREACH(ConstElementPtr subnet_json, subnets_list->listValue()) {
Subnet6ConfigParser parser;
Subnet6Ptr subnet = parser.parse(subnet_json);
Subnet6Ptr subnet = parser.parse(subnet_json, check_iface);
// Adding a subnet to the Configuration Manager may fail if the
// subnet id is invalid (duplicate). Thus, we catch exceptions
......@@ -1348,12 +1356,13 @@ Subnets6ListConfigParser::parse(SrvConfigPtr cfg, ConstElementPtr subnets_list)
size_t
Subnets6ListConfigParser::parse(Subnet6Collection& subnets,
ConstElementPtr subnets_list) {
ConstElementPtr subnets_list,
bool check_iface) {
size_t cnt = 0;
BOOST_FOREACH(ConstElementPtr subnet_json, subnets_list->listValue()) {
Subnet6ConfigParser parser;
Subnet6Ptr subnet = parser.parse(subnet_json);
Subnet6Ptr subnet = parser.parse(subnet_json, check_iface);
if (subnet) {
try {
auto ret = subnets.push_back(subnet);
......
......@@ -486,10 +486,13 @@ protected:
/// Subnet6ConfigParser) classes.
///
/// @param subnet pointer to the content of subnet definition
/// @param check_iface Check if the specified interface exists in
/// the system.
/// @return a pointer to newly created subnet
///
/// @throw isc::DhcpConfigError if subnet configuration parsing failed.
SubnetPtr parse(isc::data::ConstElementPtr subnet);
SubnetPtr parse(isc::data::ConstElementPtr subnet,
bool check_iface = true);
/// @brief Instantiates the subnet based on a given IP prefix and prefix
/// length.
......@@ -525,6 +528,9 @@ protected:
/// Pointer to the options configuration.
CfgOptionPtr options_;
/// Check if the specified interface exists in the system.
bool check_iface_;
};
/// @anchor Subnet4ConfigParser
......@@ -544,8 +550,10 @@ public:
/// Configuration Manager.
///
/// @param subnet A new subnet being configured.
/// @param check_iface Check if the specified interface exists in
/// the system.
/// @return a pointer to created Subnet4 object
Subnet4Ptr parse(data::ConstElementPtr subnet);
Subnet4Ptr parse(data::ConstElementPtr subnet, bool check_iface = true);
protected:
......@@ -575,16 +583,22 @@ public:
///
/// @param cfg Pointer to server configuration.
/// @param subnets_list pointer to a list of IPv4 subnets
/// @param check_iface Check if the specified interface exists in
/// the system.
/// @return number of subnets created
size_t parse(SrvConfigPtr cfg, data::ConstElementPtr subnets_list);
size_t parse(SrvConfigPtr cfg, data::ConstElementPtr subnets_list,
bool check_iface = true);
/// @brief Parses contents of the subnet4 list.
///
/// @param [out] subnets Container where parsed subnets will be stored.
/// @param subnets_list pointer to a list of IPv4 subnets
/// @param check_iface Check if the specified interface exists in
/// the system.
/// @return Number of subnets created.
size_t parse(Subnet4Collection& subnets,
data::ConstElementPtr subnets_list);
data::ConstElementPtr subnets_list,
bool check_iface = true);
};
/// @brief Parser for IPv6 pool definitions.
......@@ -727,8 +741,10 @@ public:
/// Configuration Manager.
///
/// @param subnet A new subnet being configured.
/// @param check_iface Check if the specified interface exists in
/// the system.
/// @return a pointer to created Subnet6 object
Subnet6Ptr parse(data::ConstElementPtr subnet);
Subnet6Ptr parse(data::ConstElementPtr subnet, bool check_iface = true);
protected:
/// @brief Issues a DHCP6 server specific warning regarding duplicate subnet
......@@ -768,16 +784,22 @@ public:
///
/// @param cfg configuration (parsed subnets will be stored here)
/// @param subnets_list pointer to a list of IPv6 subnets
/// @param check_iface Check if the specified interface exists in
/// the system.
/// @throw DhcpConfigError if CfgMgr rejects the subnet (e.g. subnet-id is a duplicate)
size_t parse(SrvConfigPtr cfg, data::ConstElementPtr subnets_list);
size_t parse(SrvConfigPtr cfg, data::ConstElementPtr subnets_list,
bool check_iface = true);
/// @brief Parses contents of the subnet6 list.
///
/// @param [out] subnets Container where parsed subnets will be stored.
/// @param subnets_list pointer to a list of IPv6 subnets
/// @param check_iface Check if the specified interface exists in
/// the system.
/// @return Number of subnets created.
size_t parse(Subnet6Collection& subnets,
data::ConstElementPtr subnets_list);
data::ConstElementPtr subnets_list,
bool check_iface = true);
};
......
......@@ -27,7 +27,8 @@ namespace isc {
namespace dhcp {
SharedNetwork4Ptr
SharedNetwork4Parser::parse(const data::ConstElementPtr& shared_network_data) {
SharedNetwork4Parser::parse(const data::ConstElementPtr& shared_network_data,
bool check_iface) {
SharedNetwork4Ptr shared_network;
try {
......@@ -46,6 +47,7 @@ SharedNetwork4Parser::parse(const data::ConstElementPtr& shared_network_data) {
// interface is an optional parameter
if (shared_network_data->contains("interface")) {
// check_iface applies only on subnets?
shared_network->setIface(getString(shared_network_data, "interface"));
}
......@@ -63,7 +65,7 @@ SharedNetwork4Parser::parse(const data::ConstElementPtr& shared_network_data) {
// Create parser instance of subnet4.
Subnets4ListConfigParser parser;
Subnet4Collection subnets;
parser.parse(subnets, json);
parser.parse(subnets, json, check_iface);
// Add all returned subnets into shared network.
for (auto subnet = subnets.cbegin(); subnet != subnets.cend();
......@@ -195,7 +197,8 @@ SharedNetwork4Parser::parse(const data::ConstElementPtr& shared_network_data) {
}
SharedNetwork6Ptr
SharedNetwork6Parser::parse(const data::ConstElementPtr& shared_network_data) {
SharedNetwork6Parser::parse(const data::ConstElementPtr& shared_network_data,
bool check_iface) {
SharedNetwork6Ptr shared_network;
std::string name;
try {
......@@ -250,6 +253,7 @@ SharedNetwork6Parser::parse(const data::ConstElementPtr& shared_network_data) {
// Get interface name. If it is defined, then the subnet is available
// directly over specified network interface.
// check_iface applies only on subnets?
if (!iface.unspecified() && !iface.empty()) {
shared_network->setIface(iface);
}
......@@ -304,7 +308,7 @@ SharedNetwork6Parser::parse(const data::ConstElementPtr& shared_network_data) {
// Create parser instance of subnet6.
Subnets6ListConfigParser parser;
Subnet6Collection subnets;
parser.parse(subnets, json);
parser.parse(subnets, json, check_iface);
// Add all returned subnets into shared network.
for (auto subnet = subnets.cbegin(); subnet != subnets.cend();
......
......@@ -25,11 +25,14 @@ public:
///
/// @param shared_network_data Data element holding shared network
/// configuration to be parsed.
/// @param check_iface Check if the specified interface exists in
/// the system.
///
/// @return Pointer to an object representing shared network.
/// @throw DhcpConfigError when shared network configuration is invalid.
SharedNetwork4Ptr
parse(const data::ConstElementPtr& shared_network_data);
parse(const data::ConstElementPtr& shared_network_data,
bool check_iface = true);
};
/// @brief Implements parser for IPv6 shared networks.
......@@ -39,11 +42,14 @@ public:
///
/// @param shared_network_data Data element holding shared network
/// configuration to be parsed.
/// @param check_iface Check if the specified interface exists in
/// the system.
///
/// @return Pointer to an object representing shared network.
/// @throw DhcpConfigError when shared network configuration is invalid.
SharedNetwork6Ptr
parse(const data::ConstElementPtr& shared_network_data);
parse(const data::ConstElementPtr& shared_network_data,
bool check_iface = true);
};
} // enf of namespace isc::dhcp
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment