]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[564-customer-request-relax-constraints-on-allowable-option-types-to-permit-option...
authorFrancis Dupont <fdupont@isc.org>
Wed, 10 Apr 2019 22:38:55 +0000 (00:38 +0200)
committerFrancis Dupont <fdupont@isc.org>
Thu, 18 Apr 2019 14:48:12 +0000 (16:48 +0200)
src/bin/dhcp4/tests/config_parser_unittest.cc
src/bin/dhcp6/tests/config_parser_unittest.cc
src/lib/dhcpsrv/parsers/dhcp_parsers.cc
src/lib/dhcpsrv/parsers/option_data_parser.cc

index 7c035595bb468ef476cf1075e4bb9236c5d755c8..d492e43fb061d411dd8f02b820d37d92d6ba6b7b 100644 (file)
@@ -3351,7 +3351,7 @@ TEST_F(Dhcp4ParserTest, optionCodeNonUint8) {
 }
 
 // Verify that zero option code is rejected in the configuration.
-TEST_F(Dhcp4ParserTest, DISABLED_optionCodeZero) {
+TEST_F(Dhcp4ParserTest, optionCodeZero) {
     // Option code 0 is reserved and should not be accepted
     // by configuration parser.
     testInvalidOptionParam("0", "code");
index 5458e4f41b0ca5c75ab00516fe24c727e1334141..64e1c95f268f7ae1dfb76682c275a21ba369f148 100644 (file)
@@ -3555,7 +3555,7 @@ TEST_F(Dhcp6ParserTest, optionCodeHighNonUint16) {
 }
 
 // Verify that zero option code is rejected in the configuration.
-TEST_F(Dhcp6ParserTest, DISABLED_optionCodeZero) {
+TEST_F(Dhcp6ParserTest, optionCodeZero) {
     // Option code 0 is reserved and should not be accepted
     // by configuration parser.
     testInvalidOptionParam("0", "code");
index d1c061d962d4eb9084ccf391e6de9ff89a0cbfb1..79af4c879b200aca22b0b689ec6a55d941d31215 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <config.h>
 #include <dhcp/iface_mgr.h>
+#include <dhcp/dhcp4.h>
 #include <dhcp/libdhcp++.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/cfg_option.h>
@@ -157,6 +158,29 @@ OptionDefParser::parse(ConstElementPtr option_def) {
                   << getPosition("space", option_def) << ")");
     }
 
+    // Protect against definition of options 0 (PAD) or 255 (END)
+    // in (and only in) the dhcp4 space.
+    if (space == DHCP4_OPTION_SPACE) {
+        if (code == DHO_PAD) {
+            isc_throw(DhcpConfigError, "invalid option code '0': "
+                      << "reserved for PAD ("
+                      << getPosition("code", option_def) << ")");
+        } else if (code == DHO_END) {
+            isc_throw(DhcpConfigError, "invalid option code '255': "
+                      << "reserved for END ("
+                      << getPosition("code", option_def) << ")");
+        }
+    }
+
+    // For dhcp6 space the value 0 is reserved.
+    if (space == DHCP6_OPTION_SPACE) {
+        if (code == 0) {
+            isc_throw(DhcpConfigError, "invalid option code '0': "
+                      << "reserved value ("
+                      << getPosition("code", option_def) << ")");
+        }
+    }
+
     // Create option definition.
     OptionDefinitionPtr def;
     // We need to check if user has set encapsulated option space
index 523ff3560dfab83cfb6d21475ba1970de9b297a8..93d01dce1bce0ee1cef8ccb2c974631070213e07 100644 (file)
@@ -7,6 +7,7 @@
 #include <config.h>
 
 #include <exceptions/exceptions.h>
+#include <dhcp/dhcp4.h>
 #include <dhcp/libdhcp++.h>
 #include <dhcp/option_definition.h>
 #include <dhcp/option_space.h>
@@ -302,7 +303,6 @@ OptionDataParser::createOption(ConstElementPtr option_data) {
         }
     }
 
-    OptionPtr option;
     OptionDescriptor desc(false);
 
     if (!def) {
@@ -350,6 +350,29 @@ OptionDataParser::createOption(ConstElementPtr option_data) {
         }
     }
 
+    // Check PAD and END in (and only in) dhcp4 space.
+    if (space_param == DHCP4_OPTION_SPACE) {
+        if (desc.option_->getType() == DHO_PAD) {
+            isc_throw(DhcpConfigError, "invalid option code '0': "
+                      << "reserved for PAD ("
+                      << option_data->getPosition() << ")");
+        } else if (desc.option_->getType() == DHO_END) {
+            isc_throw(DhcpConfigError, "invalid option code '255': "
+                      << "reserved for END ("
+                      << option_data->getPosition() << ")");
+        }
+    }
+
+    // For dhcp6 space the value 0 is reserved.
+    if (space_param == DHCP6_OPTION_SPACE) {
+        if (desc.option_->getType() == 0) {
+            isc_throw(DhcpConfigError, "invalid option code '0': "
+                      << "reserved value ("
+                      << option_data->getPosition() << ")");
+        }
+    }
+
+
     // Add user context
     if (user_context) {
         desc.setContext(user_context);