Browse Source

[master] Merged trac4291 (empty option vs csv-format)

Francis Dupont 9 years ago
parent
commit
19742f217e

+ 6 - 3
src/lib/dhcp/option_definition.cc

@@ -1,4 +1,4 @@
-// Copyright (C) 2012-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2016 Internet Systems Consortium, Inc. ("ISC")
 //
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -228,9 +228,12 @@ OptionDefinition::optionFactory(Option::Universe u, uint16_t type,
     OptionBuffer buf;
     OptionBuffer buf;
     if (!array_type_ && type_ != OPT_RECORD_TYPE) {
     if (!array_type_ && type_ != OPT_RECORD_TYPE) {
         if (values.empty()) {
         if (values.empty()) {
-            isc_throw(InvalidOptionValue, "no option value specified");
+            if (type_ != OPT_EMPTY_TYPE) {
+                isc_throw(InvalidOptionValue, "no option value specified");
+            }
+        } else {
+            writeToBuffer(util::str::trim(values[0]), type_, buf);
         }
         }
-        writeToBuffer(util::str::trim(values[0]), type_, buf);
     } else if (array_type_ && type_ != OPT_RECORD_TYPE) {
     } else if (array_type_ && type_ != OPT_RECORD_TYPE) {
         for (size_t i = 0; i < values.size(); ++i) {
         for (size_t i = 0; i < values.size(); ++i) {
             writeToBuffer(util::str::trim(values[i]), type_, buf);
             writeToBuffer(util::str::trim(values[i]), type_, buf);

+ 21 - 1
src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc

@@ -1,4 +1,4 @@
-// Copyright (C) 2012-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2016 Internet Systems Consortium, Inc. ("ISC")
 //
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -932,6 +932,26 @@ TEST_F(ParseConfigTest, emptyOptionData) {
     ASSERT_EQ(0, opt->getAddresses().size());
     ASSERT_EQ(0, opt->getAddresses().size());
 }
 }
 
 
+// This test verifies an option data without suboptions is supported
+TEST_F(ParseConfigTest, optionDataNoSubOpion) {
+    // Configuration string.
+    const std::string config =
+        "{ \"option-data\": [ {"
+        "    \"name\": \"vendor-encapsulated-options\""
+        " } ]"
+        "}";
+
+    // The default universe is V6. We need to change it to use dhcp4 option
+    // space.
+    parser_context_->universe_ = Option::V4;
+    int rcode = 0;
+    ASSERT_NO_THROW(rcode = parseConfiguration(config));
+    EXPECT_EQ(0, rcode);
+    const OptionPtr opt = getOptionPtr("dhcp4", DHO_VENDOR_ENCAPSULATED_OPTIONS);
+    ASSERT_TRUE(opt);
+    ASSERT_EQ(0, opt->getOptions().size());
+}
+
 /// The next set of tests check basic operation of the HooksLibrariesParser.
 /// The next set of tests check basic operation of the HooksLibrariesParser.
 //
 //
 // Convenience function to set a configuration of zero or more hooks
 // Convenience function to set a configuration of zero or more hooks