]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[575-cb-cmds-unknown-fields-in-arguments-should-raise-an-error] Added keyword checks...
authorFrancis Dupont <fdupont@isc.org>
Sun, 9 Jun 2019 15:17:14 +0000 (17:17 +0200)
committerFrancis Dupont <fdupont@isc.org>
Sun, 7 Jul 2019 09:07:09 +0000 (11:07 +0200)
src/lib/dhcpsrv/parsers/dhcp_parsers.cc
src/lib/dhcpsrv/parsers/dhcp_parsers.h
src/lib/dhcpsrv/parsers/option_data_parser.cc
src/lib/dhcpsrv/parsers/option_data_parser.h
src/lib/dhcpsrv/parsers/shared_network_parser.cc
src/lib/dhcpsrv/parsers/shared_network_parser.h
src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc
src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc
src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc
src/lib/dhcpsrv/tests/shared_network_parser_unittest.cc

index 1a4b24a36d64872b87c43daa4729770b22c4829b..3d022f774cca0ab6aa64f26a0b17b59a0a7a2f9b 100644 (file)
@@ -112,6 +112,19 @@ OptionDataParser::findOptionDefinition(const std::string& option_space,
 
 // ******************************** OptionDefParser ****************************
 
+const SimpleKeywords
+OptionDefParser::OPTION_DEF_PARAMETERS = {
+    { "name",         Element::string },
+    { "code",         Element::integer },
+    { "type",         Element::string },
+    { "record-types", Element::string },
+    { "space",        Element::string },
+    { "encapsulate",  Element::string },
+    { "array",        Element::boolean, },
+    { "user-context", Element::map },
+    { "comment",      Element::string }
+};
+
 OptionDefParser::OptionDefParser(const uint16_t address_family)
     : address_family_(address_family) {
 }
@@ -119,6 +132,9 @@ OptionDefParser::OptionDefParser(const uint16_t address_family)
 std::pair<isc::dhcp::OptionDefinitionPtr, std::string>
 OptionDefParser::parse(ConstElementPtr option_def) {
 
+    // Check parameters.
+    checkKeywords(OPTION_DEF_PARAMETERS, option_def);
+
     // Get mandatory parameters.
     std::string name = getString(option_def, "name");
     int64_t code64 = getInteger(option_def, "code");
@@ -364,11 +380,23 @@ RelayInfoParser::addAddress(const std::string& name,
 
 //****************************** PoolParser ********************************
 
+const SimpleKeywords
+PoolParser::POOL_PARAMETERS = {
+    { "pool",                   Element::string },
+    { "option-data",            Element::list },
+    { "client-class",           Element::string },
+    { "require-client-classes", Element::list },
+    { "user-context",           Element::map },
+    { "comment",                Element::string }
+};
+
 void
 PoolParser::parse(PoolStoragePtr pools,
                   ConstElementPtr pool_structure,
                   const uint16_t address_family) {
 
+    checkKeywords(POOL_PARAMETERS, pool_structure);
+
     ConstElementPtr text_pool = pool_structure->get("pool");
 
     if (!text_pool) {
@@ -661,12 +689,45 @@ SubnetConfigParser::createSubnet(ConstElementPtr params) {
 
 //****************************** Subnet4ConfigParser *************************
 
+const SimpleKeywords
+Subnet4ConfigParser::SUBNET4_PARAMETERS = {
+    { "valid-lifetime",         Element::integer },
+    { "renew-timer",            Element::integer },
+    { "rebind-timer",           Element::integer },
+    { "option-data",            Element::list },
+    { "pools",                  Element::list },
+    { "subnet",                 Element::string },
+    { "interface",              Element::string },
+    { "id",                     Element::integer },
+    { "client-class",           Element::string },
+    { "require-client-classes", Element::list },
+    { "reservations",           Element::list },
+    { "reservation-mode",       Element::string },
+    { "relay",                  Element::map },
+    { "match-client-id",        Element::boolean },
+    { "authoritative",          Element::boolean },
+    { "next-server",            Element::string },
+    { "server-hostname",        Element::string },
+    { "boot-file-name",         Element::string },
+    { "4o6-interface",          Element::string },
+    { "4o6-interface-id",       Element::string },
+    { "4o6-subnet",             Element::string },
+    { "user-context",           Element::map },
+    { "comment",                Element::string },
+    { "calculate-tee-times",    Element::boolean },
+    { "t1-percent",             Element::real },
+    { "t2-percent",             Element::real }
+};
+
 Subnet4ConfigParser::Subnet4ConfigParser()
     :SubnetConfigParser(AF_INET) {
 }
 
 Subnet4Ptr
 Subnet4ConfigParser::parse(ConstElementPtr subnet) {
+    // Check parameters.
+    checkKeywords(SUBNET4_PARAMETERS, subnet);
+
     /// Parse Pools first.
     ConstElementPtr pools = subnet->get("pools");
     if (pools) {
@@ -989,11 +1050,27 @@ Pools6ListParser::parse(PoolStoragePtr pools, ConstElementPtr pools_list) {
 
 //**************************** PdPoolParser ******************************
 
+const SimpleKeywords
+PdPoolParser::PD_POOL_PARAMETERS = {
+    { "prefix",                 Element::string },
+    { "prefix-len",             Element::integer },
+    { "delegated-len",          Element::integer },
+    { "option-data",            Element::list },
+    { "client-class",           Element::string },
+    { "require-client-classes", Element::list },
+    { "excluded-prefix",        Element::string },
+    { "excluded-prefix-len",    Element::integer },
+    { "user-context",           Element::map },
+    { "comment",                Element::string }
+};
+
 PdPoolParser::PdPoolParser() : options_(new CfgOption()) {
 }
 
 void
 PdPoolParser::parse(PoolStoragePtr pools, ConstElementPtr pd_pool_) {
+    checkKeywords(PD_POOL_PARAMETERS, pd_pool_);
+
     std::string addr_str = getString(pd_pool_, "prefix");
 
     uint8_t prefix_len = getUint8(pd_pool_, "prefix-len");
@@ -1088,12 +1165,41 @@ PdPoolsListParser::parse(PoolStoragePtr pools, ConstElementPtr pd_pool_list) {
 
 //**************************** Subnet6ConfigParser ***********************
 
+const SimpleKeywords
+Subnet6ConfigParser::SUBNET6_PARAMETERS = {
+    { "preferred-lifetime",     Element::integer },
+    { "valid-lifetime",         Element::integer },
+    { "renew-timer",            Element::integer },
+    { "rebind-timer",           Element::integer },
+    { "option-data",            Element::list },
+    { "pools",                  Element::list },
+    { "pd-pools",               Element::list },
+    { "subnet",                 Element::string },
+    { "interface",              Element::string },
+    { "interface-id",           Element::string },
+    { "id",                     Element::integer },
+    { "rapid-commit",           Element::boolean },
+    { "client-class",           Element::string },
+    { "require-client-classes", Element::list },
+    { "reservations",           Element::list },
+    { "reservation-mode",       Element::string },
+    { "relay",                  Element::map },
+    { "user-context",           Element::map },
+    { "comment",                Element::string },
+    { "calculate-tee-times",    Element::boolean },
+    { "t1-percent",             Element::real },
+    { "t2-percent",             Element::real }
+};
+
 Subnet6ConfigParser::Subnet6ConfigParser()
     : SubnetConfigParser(AF_INET6) {
 }
 
 Subnet6Ptr
 Subnet6ConfigParser::parse(ConstElementPtr subnet) {
+    // Check parameters.
+    checkKeywords(SUBNET6_PARAMETERS, subnet);
+
     /// Parse all pools first.
     ConstElementPtr pools = subnet->get("pools");
     if (pools) {
index 8333c4b74962c0e1a80c567c54d9bd748148d438..6d274749dcda390cec1742e3bfe162b7bd185527 100644 (file)
@@ -242,6 +242,13 @@ public:
     OptionDefinitionTuple
     parse(isc::data::ConstElementPtr option_def);
 
+    /// @brief This table defines all option definition parameters.
+    ///
+    /// Boolean, integer, real and string types are for scalar parameters,
+    /// list and map types for entries.
+    /// Order follows option_def_param rules in bison grammar.
+    static const isc::data::SimpleKeywords OPTION_DEF_PARAMETERS;
+
 private:
     /// @brief Address family: @c AF_INET or @c AF_INET6.
     uint16_t address_family_;
@@ -309,6 +316,13 @@ public:
                        isc::data::ConstElementPtr pool_structure,
                        const uint16_t address_family);
 
+    /// @brief This table defines all pool parameters.
+    ///
+    /// Boolean, integer, real and string types are for scalar parameters,
+    /// list and map types for entries.
+    /// Order follows pool_param rules in bison grammar.
+    static const isc::data::SimpleKeywords POOL_PARAMETERS;
+
 protected:
     /// @brief Creates a Pool object given a IPv4 prefix and the prefix length.
     ///
@@ -547,6 +561,13 @@ public:
     /// @return a pointer to created Subnet4 object
     Subnet4Ptr parse(data::ConstElementPtr subnet);
 
+    /// @brief This table defines all subnet parameters for DHCPv4.
+    ///
+    /// Boolean, integer, real and string types are for scalar parameters,
+    /// list and map types for entries.
+    /// Order follows subnet4_param rule in bison grammar.
+    static const isc::data::SimpleKeywords SUBNET4_PARAMETERS;
+
 protected:
 
     /// @brief Instantiates the IPv4 Subnet based on a given IPv4 address
@@ -669,6 +690,13 @@ public:
     /// @throw DhcpConfigError if configuration parsing fails.
     void parse(PoolStoragePtr pools, data::ConstElementPtr pd_pool_);
 
+    /// @brief This table defines all prefix delegation pool parameters.
+    ///
+    /// Boolean, integer, real and string types are for scalar parameters,
+    /// list and map types for entries.
+    /// Order follows pd_pool_param rules in bison grammar.
+    static const isc::data::SimpleKeywords PD_POOL_PARAMETERS;
+
 private:
 
     /// Pointer to the created pool object.
@@ -730,6 +758,13 @@ public:
     /// @return a pointer to created Subnet6 object
     Subnet6Ptr parse(data::ConstElementPtr subnet);
 
+    /// @brief This table defines all subnet parameters for DHCPv6.
+    ///
+    /// Boolean, integer, real and string types are for scalar parameters,
+    /// list and map types for entries.
+    /// Order follows subnet6_param rule in bison grammar.
+    static const isc::data::SimpleKeywords SUBNET6_PARAMETERS;
+
 protected:
     /// @brief Issues a DHCP6 server specific warning regarding duplicate subnet
     /// options.
index 93d01dce1bce0ee1cef8ccb2c974631070213e07..6a55fdc8fcc8a0cf7f7cfaa76b21707b629150b4 100644 (file)
@@ -27,6 +27,18 @@ namespace dhcp {
 
 // **************************** OptionDataParser *************************
 
+const SimpleKeywords
+OptionDataParser::OPTION_PARAMETERS = {
+    { "name",         Element::string },
+    { "data",         Element::string },
+    { "code",         Element::integer },
+    { "space",        Element::string },
+    { "csv-format",   Element::boolean },
+    { "always-send",  Element::boolean },
+    { "user-context", Element::map },
+    { "comment",      Element::string }
+};
+
 OptionDataParser::OptionDataParser(const uint16_t address_family,
                                    CfgOptionDefPtr cfg_option_def)
     : address_family_(address_family), cfg_option_def_(cfg_option_def) {
@@ -35,6 +47,9 @@ OptionDataParser::OptionDataParser(const uint16_t address_family,
 std::pair<OptionDescriptor, std::string>
 OptionDataParser::parse(isc::data::ConstElementPtr single_option) {
 
+    // Check parameters.
+    checkKeywords(OPTION_PARAMETERS, single_option);
+
     // Try to create the option instance.
     std::pair<OptionDescriptor, std::string> opt = createOption(single_option);
 
index 7c6e53da4cba0598a32802e21bb5977ef975ed9a..1c4bee2d378522c7d4791e7c934a801295d1fb7c 100644 (file)
@@ -64,6 +64,14 @@ public:
     ///         space
     std::pair<OptionDescriptor, std::string>
     parse(isc::data::ConstElementPtr single_option);
+
+    /// @brief This table defines all option parameters.
+    ///
+    /// Boolean, integer, real and string types are for scalar parameters,
+    /// list and map types for entries.
+    /// Order follows option_param rules in bison grammar.
+    static const isc::data::SimpleKeywords OPTION_PARAMETERS;
+
 private:
 
     /// @brief Finds an option definition within an option space
index 93fea77dbc2a53df8de46232543c287140bd2b0c..312c9d4bb544c0b96653cb28ad9a795ba9f91e64 100644 (file)
@@ -24,11 +24,39 @@ using namespace isc::util;
 namespace isc {
 namespace dhcp {
 
+const SimpleKeywords
+SharedNetwork4Parser::SHARED_NETWORK4_PARAMETERS = {
+    { "name",                   Element::string },
+    { "subnet4",                Element::list },
+    { "interface",              Element::string },
+    { "renew-timer",            Element::integer },
+    { "rebind-timer",           Element::integer },
+    { "option-data",            Element::list },
+    { "match-client-id",        Element::boolean },
+    { "authoritative",          Element::boolean },
+    { "next-server",            Element::string },
+    { "server-hostname",        Element::string },
+    { "boot-file-name",         Element::string },
+    { "relay",                  Element::map },
+    { "reservation-mode",       Element::string },
+    { "client-class",           Element::string },
+    { "require-client-classes", Element::list },
+    { "valid-lifetime",         Element::integer },
+    { "user-context",           Element::map },
+    { "comment",                Element::string },
+    { "calculate-tee-times",    Element::boolean },
+    { "t1-percent",             Element::real },
+    { "t2-percent",             Element::real }
+};
+
 SharedNetwork4Ptr
 SharedNetwork4Parser::parse(const data::ConstElementPtr& shared_network_data) {
     SharedNetwork4Ptr shared_network;
     try {
 
+        // Check parameters.
+        checkKeywords(SHARED_NETWORK4_PARAMETERS, shared_network_data);
+
         // Make sure that the network name has been specified. The name is required
         // to create a SharedNetwork4 object.
         std::string name = getString(shared_network_data, "name");
@@ -186,11 +214,37 @@ SharedNetwork4Parser::parse(const data::ConstElementPtr& shared_network_data) {
     return (shared_network);
 }
 
+const SimpleKeywords
+SharedNetwork6Parser::SHARED_NETWORK6_PARAMETERS = {
+    { "name",                   Element::string },
+    { "subnet6",                Element::list },
+    { "interface",              Element::string },
+    { "interface-id",           Element::string },
+    { "renew-timer",            Element::integer },
+    { "rebind-timer",           Element::integer },
+    { "option-data",            Element::list },
+    { "relay",                  Element::map },
+    { "reservation-mode",       Element::string },
+    { "client-class",           Element::string },
+    { "require-client-classes", Element::list },
+    { "preferred-lifetime",     Element::integer },
+    { "rapid-commit",           Element::boolean },
+    { "valid-lifetime",         Element::integer },
+    { "user-context",           Element::map },
+    { "comment",                Element::string },
+    { "calculate-tee-times",    Element::boolean },
+    { "t1-percent",             Element::real },
+    { "t2-percent",             Element::real }
+};
+
 SharedNetwork6Ptr
 SharedNetwork6Parser::parse(const data::ConstElementPtr& shared_network_data) {
     SharedNetwork6Ptr shared_network;
     std::string name;
     try {
+        // Check parameters.
+        checkKeywords(SHARED_NETWORK6_PARAMETERS, shared_network_data);
+
         // Make sure that the network name has been specified. The name is required
         // to create a SharedNetwork6 object.
         std::string name = getString(shared_network_data, "name");
index d88e1b2d4df94db5e2ef99e632cf92b8ccd6ba54..3e6a16e55ac6e339492604cce5330d80baf66e1c 100644 (file)
@@ -21,6 +21,13 @@ namespace dhcp {
 class SharedNetwork4Parser : public BaseNetworkParser {
 public:
 
+    /// @brief This table defines all shared network parameters for DHCPv4.
+    ///
+    /// Boolean, integer, real and string types are for scalar parameters,
+    /// list and map types for entries.
+    /// Order follows shared_network_param rule in bison grammar.
+    static const isc::data::SimpleKeywords SHARED_NETWORK4_PARAMETERS;
+
     /// @brief Parses shared configuration information for IPv4 shared network.
     ///
     /// @param shared_network_data Data element holding shared network
@@ -36,6 +43,13 @@ public:
 class SharedNetwork6Parser : public BaseNetworkParser {
 public:
 
+    /// @brief This table defines all shared network parameters for DHCPv6.
+    ///
+    /// Boolean, integer, real and string types are for scalar parameters,
+    /// list and map types for entries.
+    /// Order follows shared_network_param rule in bison grammar.
+    static const isc::data::SimpleKeywords SHARED_NETWORK6_PARAMETERS;
+
     /// @brief Parses shared configuration information for IPv6 shared network.
     ///
     /// @param shared_network_data Data element holding shared network
index 624c30d577f04e41875829069b555e2be39d33f9..f651b4daea9f9fc1d873db75b0a5d511b9f3d0aa 100644 (file)
@@ -1255,9 +1255,7 @@ TEST(CfgSubnets4Test, teeTimePercentValidation) {
         "            \"reservation-mode\": \"all\", \n"
         "            \"4o6-interface\": \"\", \n"
         "            \"4o6-interface-id\": \"\", \n"
-        "            \"4o6-subnet\": \"\", \n"
-        "            \"dhcp4o6-port\": 0, \n"
-        "            \"decline-probation-period\": 86400 \n"
+        "            \"4o6-subnet\": \"\" \n"
         "        }";
 
 
index d442e06872e777fa06899cef0fe0c53525cb9de9..9d4b981de3bcba7f98832808409d23f66d34161b 100644 (file)
@@ -1047,12 +1047,7 @@ TEST(CfgSubnets6Test, teeTimePercentValidation) {
         "            \"valid-lifetime\": 300, \n"
         "            \"client-class\": \"\", \n"
         "            \"require-client-classes\": [] \n,"
-        "            \"reservation-mode\": \"all\", \n"
-        "            \"4o6-interface\": \"\", \n"
-        "            \"4o6-interface-id\": \"\", \n"
-        "            \"4o6-subnet\": \"\", \n"
-        "            \"dhcp4o6-port\": 0, \n"
-        "            \"decline-probation-period\": 86400 \n"
+        "            \"reservation-mode\": \"all\" \n"
         "        }";
 
 
index 231af76def821fcb5b149780c31f2280272b4c55..85f3d7436b3715a1d134280c0662fb5b28666ee2 100644 (file)
@@ -1701,7 +1701,7 @@ TEST_F(ParseConfigTest, hexOptionData) {
             "{ \n"
             "  \"option-data\": [ { \n"
             "    \"name\": \"domain-name-servers\", \n"
-            "    \"code \": 6, \n"
+            "    \"code\": 6, \n"
             "    \"space\": \"dhcp4\", \n"
             "    \"csv-format\": false, \n"
             "    \"data\": \"" << hex_str << "\" \n"
index 82744d88fcabb10f7ee53ef8f755a852742107b5..9fdbdf61f54e5d3892d1baba82f25b5acf9b70b8 100644 (file)
@@ -162,8 +162,6 @@ public:
                 "            \"4o6-interface\": \"\","
                 "            \"4o6-interface-id\": \"\","
                 "            \"4o6-subnet\": \"\","
-                "            \"dhcp4o6-port\": 0,"
-                "            \"decline-probation-period\": 86400,"
                 "            \"reservation-mode\": \"all\","
                 "            \"calculate-tee-times\": true,"
                 "            \"t1-percent\": .45,"
@@ -187,8 +185,6 @@ public:
                 "            \"4o6-interface\": \"\","
                 "            \"4o6-interface-id\": \"\","
                 "            \"4o6-subnet\": \"\","
-                "            \"dhcp4o6-port\": 0,"
-                "            \"decline-probation-period\": 86400,"
                 "            \"reservation-mode\": \"all\","
                 "            \"calculate-tee-times\": false,"
                 "            \"t1-percent\": .40,"
@@ -472,8 +468,6 @@ public:
                 "            \"client-class\": \"\","
                 "            \"require-client-classes\": []\n,"
                 "            \"reservation-mode\": \"all\","
-                "            \"decline-probation-period\": 86400,"
-                "            \"dhcp4o6-port\": 0,"
                 "            \"rapid-commit\": false"
                 "        },"
                 "        {"
@@ -488,8 +482,6 @@ public:
                 "            \"client-class\": \"\","
                 "            \"require-client-classes\": []\n,"
                 "            \"reservation-mode\": \"all\","
-                "            \"decline-probation-period\": 86400,"
-                "            \"dhcp4o6-port\": 0,"
                 "            \"rapid-commit\": false"
                 "        }"
                 "    ]"