]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#487,!242] Set defaults for 4o6 config in subnet.
authorMarcin Siodelski <marcin@isc.org>
Wed, 27 Feb 2019 07:06:21 +0000 (08:06 +0100)
committerMarcin Siodelski <marcin@isc.org>
Thu, 28 Feb 2019 13:38:18 +0000 (08:38 -0500)
src/bin/dhcp4/tests/config_parser_unittest.cc
src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc
src/lib/dhcpsrv/cfg_4o6.cc
src/lib/dhcpsrv/cfg_4o6.h
src/lib/dhcpsrv/tests/subnet_unittest.cc

index 3de157ee315ff94f80926d42e7fabe13092cb81b..f77955c1dab3d7e6b9e87dab2517d4d25c9bd97a 100644 (file)
@@ -5221,8 +5221,8 @@ TEST_F(Dhcp4ParserTest, 4o6subnet) {
 
     Cfg4o6& dhcp4o6 = subnet->get4o6();
     EXPECT_TRUE(dhcp4o6.enabled());
-    EXPECT_EQ(IOAddress("2001:db8::123"), dhcp4o6.getSubnet4o6().first);
-    EXPECT_EQ(45, dhcp4o6.getSubnet4o6().second);
+    EXPECT_EQ(IOAddress("2001:db8::123"), dhcp4o6.getSubnet4o6().get().first);
+    EXPECT_EQ(45, dhcp4o6.getSubnet4o6().get().second);
 }
 
 // Checks if the DHCPv4 is able to parse the configuration with 4o6 subnet
@@ -5318,7 +5318,7 @@ TEST_F(Dhcp4ParserTest, 4o6iface) {
 
     Cfg4o6& dhcp4o6 = subnet->get4o6();
     EXPECT_TRUE(dhcp4o6.enabled());
-    EXPECT_EQ("ethX", dhcp4o6.getIface4o6());
+    EXPECT_EQ("ethX", dhcp4o6.getIface4o6().get());
 }
 
 // Checks if the DHCPv4 is able to parse the configuration with both 4o6 network
@@ -5356,9 +5356,9 @@ TEST_F(Dhcp4ParserTest, 4o6subnetIface) {
     // ... and that subnet has 4o6 network interface specified.
     Cfg4o6& dhcp4o6 = subnet->get4o6();
     EXPECT_TRUE(dhcp4o6.enabled());
-    EXPECT_EQ(IOAddress("2001:db8::543"), dhcp4o6.getSubnet4o6().first);
-    EXPECT_EQ(21, dhcp4o6.getSubnet4o6().second);
-    EXPECT_EQ("ethX", dhcp4o6.getIface4o6());
+    EXPECT_EQ(IOAddress("2001:db8::543"), dhcp4o6.getSubnet4o6().get().first);
+    EXPECT_EQ(21, dhcp4o6.getSubnet4o6().get().second);
+    EXPECT_EQ("ethX", dhcp4o6.getIface4o6().get());
 }
 
 // Checks if the DHCPv4 is able to parse the configuration with 4o6 network
index 5eaffb98f38152faedb9e131aca654ad795e9877..0332a9ba7d4a1015b23c6f6d87e7e18cf7a9bf09 100644 (file)
@@ -676,11 +676,11 @@ public:
 
         // Convert DHCPv4o6 subnet to text.
         std::string dhcp4o6_subnet;
-        if (!subnet->get4o6().getSubnet4o6().first.isV6Zero() ||
-            (subnet->get4o6().getSubnet4o6().second != 128u)) {
+        if (!subnet->get4o6().getSubnet4o6().get().first.isV6Zero() ||
+            (subnet->get4o6().getSubnet4o6().get().second != 128u)) {
             std::ostringstream s;
-            s << subnet->get4o6().getSubnet4o6().first << "/"
-              << static_cast<int>(subnet->get4o6().getSubnet4o6().second);
+            s << subnet->get4o6().getSubnet4o6().get().first << "/"
+              << static_cast<int>(subnet->get4o6().getSubnet4o6().get().second);
             dhcp4o6_subnet = s.str();
         }
 
index d55b441aa6ae8f9b478f97d2450615dc8aa6d26b..c37d7734790674d5f6d1a2d9f2d281b421d8b40f 100644 (file)
@@ -24,10 +24,10 @@ Cfg4o6::toElement() const {
     // Set 4o6-interface
     result->set("4o6-interface", Element::create(iface4o6_));
     // Set 4o6-subnet
-    if (!subnet4o6_.first.isV6Zero() || (subnet4o6_.second != 128u)) {
+    if (!subnet4o6_.get().first.isV6Zero() || (subnet4o6_.get().second != 128u)) {
         std::ostringstream oss;
-        oss << subnet4o6_.first << "/"
-            << static_cast<unsigned>(subnet4o6_.second);
+        oss << subnet4o6_.get().first << "/"
+            << static_cast<unsigned>(subnet4o6_.get().second);
         result->set("4o6-subnet", Element::create(oss.str()));
     } else {
         result->set("4o6-subnet", Element::create(std::string()));
index e231e775e6dc0220b738888a977073ed6d063518..22d7664a70f109e904c149c02e8fec5980c3001d 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2015-2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2015-2019 Internet Systems Consortium, Inc. ("ISC")
 //
 // 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
@@ -9,6 +9,7 @@
 
 #include <asiolink/io_address.h>
 #include <cc/cfg_to_element.h>
+#include <util/optional.h>
 #include <string>
 
 namespace isc {
@@ -24,7 +25,7 @@ struct Cfg4o6 : public isc::data::CfgToElement {
     ///
     /// Initializes fields to their default value.
     Cfg4o6()
-    :enabled_(false), subnet4o6_(std::make_pair(asiolink::IOAddress("::"), 128u)) {
+    :enabled_(false), subnet4o6_(std::make_pair(asiolink::IOAddress("::"), 128u), true) {
     }
 
     /// @brief Returns whether the DHCP4o6 is enabled or not.
@@ -41,7 +42,7 @@ struct Cfg4o6 : public isc::data::CfgToElement {
 
     /// @brief Returns the DHCP4o6 interface.
     /// @return value of the 4o6-interface parameter.
-    std::string getIface4o6() const {
+    util::Optional<std::string> getIface4o6() const {
         return (iface4o6_);
     }
 
@@ -54,7 +55,7 @@ struct Cfg4o6 : public isc::data::CfgToElement {
 
     /// @brief Returns prefix/len for the IPv6 subnet.
     /// @return prefix/length pair
-    std::pair<asiolink::IOAddress, uint8_t> getSubnet4o6() const {
+    util::Optional<std::pair<asiolink::IOAddress, uint8_t> > getSubnet4o6() const {
         return (subnet4o6_);
     }
 
@@ -90,10 +91,10 @@ private:
     bool enabled_;
 
     /// Specifies the network interface used as v4 subnet selector.
-    std::string iface4o6_;
+    util::Optional<std::string> iface4o6_;
 
     /// Specifies the IPv6 subnet used for v4 subnet selection.
-    std::pair<asiolink::IOAddress, uint8_t> subnet4o6_;
+    util::Optional<std::pair<asiolink::IOAddress, uint8_t> > subnet4o6_;
 
     /// Specifies the v6 interface-id used for v4 subnet selection.
     OptionPtr interface_id_;
index 6937d21446d0320190b8b43d2132170398fdbfd7..a957f3b077e3c843e07f6dbe4018152f6c346dc1 100644 (file)
@@ -92,6 +92,15 @@ TEST(Subnet4Test, defaults) {
 
     EXPECT_TRUE(subnet.getFilename().unspecified());
     EXPECT_TRUE(subnet.getFilename().empty());
+
+    EXPECT_FALSE(subnet.get4o6().enabled());
+
+    EXPECT_TRUE(subnet.get4o6().getIface4o6().unspecified());
+    EXPECT_TRUE(subnet.get4o6().getIface4o6().empty());
+
+    EXPECT_TRUE(subnet.get4o6().getSubnet4o6().unspecified());
+    EXPECT_TRUE(subnet.get4o6().getSubnet4o6().get().first.isV6Zero());
+    EXPECT_EQ(128, subnet.get4o6().getSubnet4o6().get().second);
 }
 
 // Checks that the subnet id can be either autogenerated or set to an