]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5351] Last fix lost reservations: better fix now
authorFrancis Dupont <fdupont@isc.org>
Wed, 29 Nov 2017 03:20:38 +0000 (04:20 +0100)
committerFrancis Dupont <fdupont@isc.org>
Wed, 29 Nov 2017 03:20:38 +0000 (04:20 +0100)
src/bin/dhcp4/tests/get_config_unittest.cc
src/bin/dhcp4/tests/get_config_unittest.cc.skel
src/bin/dhcp6/tests/config_parser_unittest.cc
src/bin/dhcp6/tests/get_config_unittest.cc
src/bin/dhcp6/tests/get_config_unittest.cc.skel
src/lib/dhcpsrv/srv_config.cc

index 5ee6aca3588c08861237d6a9f5ec6dfee4554262..222edb15bfd4d419b99497fc50dc7cdf3fd7fd4c 100644 (file)
@@ -1584,6 +1584,27 @@ const char* EXTRACTED_CONFIGS[] = {
 "            }\n"
 "        ],\n"
 "        \"valid-lifetime\": 4000\n"
+"    }\n",
+    // CONFIGURATION 58
+"{\n"
+"        \"shared-networks\": [\n"
+"            {\n"
+"                \"comment\": \"A shared-network\",\n"
+"                \"name\": \"foo\",\n"
+"                \"subnet4\": [\n"
+"                    {\n"
+"                        \"comment\": \"A subnet\",\n"
+"                        \"pools\": [\n"
+"                            {\n"
+"                                \"comment\": \"A pool\",\n"
+"                                \"pool\": \"192.0.1.1-192.0.1.10\"\n"
+"                            }\n"
+"                        ],\n"
+"                        \"subnet\": \"192.0.1.0/24\"\n"
+"                    }\n"
+"                ]\n"
+"            }\n"
+"        ]\n"
 "    }\n"
 };
 
@@ -6227,6 +6248,92 @@ const char* UNPARSED_CONFIGS[] = {
 "                \"valid-lifetime\": 4000\n"
 "            }\n"
 "        ]\n"
+"    }\n",
+    // CONFIGURATION 58
+"{\n"
+"        \"decline-probation-period\": 86400,\n"
+"        \"dhcp-ddns\": {\n"
+"            \"always-include-fqdn\": false,\n"
+"            \"enable-updates\": false,\n"
+"            \"generated-prefix\": \"myhost\",\n"
+"            \"max-queue-size\": 1024,\n"
+"            \"ncr-format\": \"JSON\",\n"
+"            \"ncr-protocol\": \"UDP\",\n"
+"            \"override-client-update\": false,\n"
+"            \"override-no-update\": false,\n"
+"            \"qualifying-suffix\": \"\",\n"
+"            \"replace-client-name\": \"never\",\n"
+"            \"sender-ip\": \"0.0.0.0\",\n"
+"            \"sender-port\": 0,\n"
+"            \"server-ip\": \"127.0.0.1\",\n"
+"            \"server-port\": 53001\n"
+"        },\n"
+"        \"dhcp4o6-port\": 0,\n"
+"        \"echo-client-id\": true,\n"
+"        \"expired-leases-processing\": {\n"
+"            \"flush-reclaimed-timer-wait-time\": 25,\n"
+"            \"hold-reclaimed-time\": 3600,\n"
+"            \"max-reclaim-leases\": 100,\n"
+"            \"max-reclaim-time\": 250,\n"
+"            \"reclaim-timer-wait-time\": 10,\n"
+"            \"unwarned-reclaim-cycles\": 5\n"
+"        },\n"
+"        \"hooks-libraries\": [ ],\n"
+"        \"host-reservation-identifiers\": [ \"hw-address\", \"duid\", \"circuit-id\", \"client-id\" ],\n"
+"        \"interfaces-config\": {\n"
+"            \"interfaces\": [ ],\n"
+"            \"re-detect\": false\n"
+"        },\n"
+"        \"lease-database\": {\n"
+"            \"type\": \"memfile\"\n"
+"        },\n"
+"        \"option-data\": [ ],\n"
+"        \"option-def\": [ ],\n"
+"        \"shared-networks\": [\n"
+"            {\n"
+"                \"comment\": \"A shared-network\",\n"
+"                \"match-client-id\": true,\n"
+"                \"name\": \"foo\",\n"
+"                \"option-data\": [ ],\n"
+"                \"rebind-timer\": 0,\n"
+"                \"relay\": {\n"
+"                    \"ip-address\": \"0.0.0.0\"\n"
+"                },\n"
+"                \"renew-timer\": 0,\n"
+"                \"reservation-mode\": \"all\",\n"
+"                \"subnet4\": [\n"
+"                    {\n"
+"                        \"comment\": \"A subnet\",\n"
+"                        \"4o6-interface\": \"\",\n"
+"                        \"4o6-interface-id\": \"\",\n"
+"                        \"4o6-subnet\": \"\",\n"
+"                        \"boot-file-name\": \"\",\n"
+"                        \"id\": 1,\n"
+"                        \"match-client-id\": true,\n"
+"                        \"next-server\": \"0.0.0.0\",\n"
+"                        \"option-data\": [ ],\n"
+"                        \"pools\": [\n"
+"                            {\n"
+"                                \"comment\": \"A pool\",\n"
+"                                \"option-data\": [ ],\n"
+"                                \"pool\": \"192.0.1.1-192.0.1.10\"\n"
+"                            }\n"
+"                        ],\n"
+"                        \"rebind-timer\": 1800,\n"
+"                        \"relay\": {\n"
+"                            \"ip-address\": \"0.0.0.0\"\n"
+"                        },\n"
+"                        \"renew-timer\": 900,\n"
+"                        \"reservation-mode\": \"all\",\n"
+"                        \"server-hostname\": \"\",\n"
+"                        \"subnet\": \"192.0.1.0/24\",\n"
+"                        \"valid-lifetime\": 7200\n"
+"                    }\n"
+"                ],\n"
+"                \"valid-lifetime\": 0\n"
+"            }\n"
+"        ],\n"
+"        \"subnet4\": [ ]\n"
 "    }\n"
 };
 
@@ -6474,6 +6581,7 @@ TEST_P(Dhcp4GetConfigTest, run) {
         expected = UNPARSED_CONFIGS[config_counter];
         ConstElementPtr json;
         ASSERT_NO_THROW(json = parseDHCP4(expected, true));
+        ASSERT_NO_THROW(json = parseJSON(expected));
         EXPECT_TRUE(isEquivalent(dhcp, json));
         std::string current = prettyPrint(dhcp, 4, 4) + "\n";
         EXPECT_EQ(expected, current);
index 19a8ddc2a0e8e9bc5014a301b73ea019c6270b52..68d8f165d70c2e1912a058a5e5dd680dad4b0955 100644 (file)
@@ -317,6 +317,7 @@ TEST_P(Dhcp4GetConfigTest, run) {
         expected = UNPARSED_CONFIGS[config_counter];
         ConstElementPtr json;
         ASSERT_NO_THROW(json = parseDHCP4(expected, true));
+        ASSERT_NO_THROW(json = parseJSON(expected));
         EXPECT_TRUE(isEquivalent(dhcp, json));
         std::string current = prettyPrint(dhcp, 4, 4) + "\n";
         EXPECT_EQ(expected, current);
index 946ba5cb9cd8a9576b68a84542e6d9af81d8bed4..d6f9073d06d62279b439998bef89b0550b5c5f0e 100644 (file)
@@ -6049,5 +6049,95 @@ TEST_F(Dhcp6ParserTest, sharedNetworksRapidCommitMix) {
               "shared-network or the shared-network itself used rapid-commit true");
 }
 
+// This test checks comments. Please keep it last.
+TEST_F(Dhcp6ParserTest, comments) {
+
+    string config = "{\n"
+        "\"shared-networks\": [ {\n"
+        "    \"name\": \"foo\"\n,"
+        "    \"comment\": \"A shared-network\"\n,"
+        "    \"subnet6\": [\n"
+        "    { \n"
+        "        \"subnet\": \"2001:db1::/48\",\n"
+        "        \"comment\": \"A subnet\"\n,"
+        "        \"pools\": [\n"
+        "        {\n"
+        "             \"pool\": \"2001:db1::/64\",\n"
+        "             \"comment\": \"A pool\"\n"
+        "        }\n"
+        "        ],\n"
+        "        \"pd-pools\": [\n"
+        "        {\n"
+        "             \"prefix\": \"2001:db2::\",\n"
+        "             \"prefix-len\": 48,\n"
+        "             \"delegated-len\": 64,\n"
+        "             \"comment\": \"A prefix pool\"\n"
+        "        }\n"
+        "        ]\n"
+        "    }\n"
+        "    ]\n"
+        " } ]\n"
+        "} \n";
+
+    extractConfig(config);
+    configure(config, CONTROL_RESULT_SUCCESS, "");
+
+    // Now verify that the shared network was indeed configured.
+    CfgSharedNetworks6Ptr cfg_net = CfgMgr::instance().getStagingCfg()
+        ->getCfgSharedNetworks6();
+    ASSERT_TRUE(cfg_net);
+    const SharedNetwork6Collection* nets = cfg_net->getAll();
+    ASSERT_TRUE(nets);
+    ASSERT_EQ(1, nets->size());
+    SharedNetwork6Ptr net = nets->at(0);
+    ASSERT_TRUE(net);
+
+    // Check shared network user context
+    ConstElementPtr ctx_net = net->getContext();
+    ASSERT_TRUE(ctx_net);
+    ASSERT_EQ(1, ctx_net->size());
+    ASSERT_TRUE(ctx_net->get("comment"));
+    EXPECT_EQ("\"A shared-network\"", ctx_net->get("comment")->str());
+
+    // The shared network has a subnet.
+    const Subnet6Collection * subs = net->getAllSubnets();
+    ASSERT_TRUE(subs);
+    ASSERT_EQ(1, subs->size());
+    Subnet6Ptr sub = subs->at(0);
+    ASSERT_TRUE(sub);
+
+    // Check subnet user context
+    ConstElementPtr ctx_sub = sub->getContext();
+    ASSERT_TRUE(ctx_sub);
+    ASSERT_EQ(1, ctx_sub->size());
+    ASSERT_TRUE(ctx_sub->get("comment"));
+    EXPECT_EQ("\"A subnet\"", ctx_sub->get("comment")->str());
+
+    // The subnet has a pool
+    const PoolCollection& pools = sub->getPools(Lease::TYPE_NA);
+    ASSERT_EQ(1, pools.size());
+    PoolPtr pool = pools.at(0);
+    ASSERT_TRUE(pool);
+
+    // Check pool user context                                               
+    ConstElementPtr ctx_pool = pool->getContext();
+    ASSERT_TRUE(ctx_pool);
+    ASSERT_EQ(1, ctx_pool->size());
+    ASSERT_TRUE(ctx_pool->get("comment"));
+    EXPECT_EQ("\"A pool\"", ctx_pool->get("comment")->str());
+
+    // The subnet has a prefix pool
+    const PoolCollection& pdpools = sub->getPools(Lease::TYPE_PD);
+    ASSERT_EQ(1, pdpools.size());
+    PoolPtr pdpool = pdpools.at(0);
+    ASSERT_TRUE(pdpool);
+
+    // Check prefix pool user context                                               
+    ConstElementPtr ctx_pdpool = pdpool->getContext();
+    ASSERT_TRUE(ctx_pdpool);
+    ASSERT_EQ(1, ctx_pdpool->size());
+    ASSERT_TRUE(ctx_pdpool->get("comment"));
+    EXPECT_EQ("\"A prefix pool\"", ctx_pdpool->get("comment")->str());
+}
 
 };
index dae152ebc22b58c609606dac1a490b084f1b2205..22a3a81edea56c9e9be682c4ae42c136d5d05dcd 100644 (file)
@@ -1459,6 +1459,35 @@ const char* EXTRACTED_CONFIGS[] = {
 "            }\n"
 "        ],\n"
 "        \"valid-lifetime\": 4000\n"
+"    }\n",
+    // CONFIGURATION 51
+"{\n"
+"        \"shared-networks\": [\n"
+"            {\n"
+"                \"comment\": \"A shared-network\",\n"
+"                \"name\": \"foo\",\n"
+"                \"subnet6\": [\n"
+"                    {\n"
+"                        \"comment\": \"A subnet\",\n"
+"                        \"pd-pools\": [\n"
+"                            {\n"
+"                                \"comment\": \"A prefix pool\",\n"
+"                                \"delegated-len\": 64,\n"
+"                                \"prefix\": \"2001:db2::\",\n"
+"                                \"prefix-len\": 48\n"
+"                            }\n"
+"                        ],\n"
+"                        \"pools\": [\n"
+"                            {\n"
+"                                \"comment\": \"A pool\",\n"
+"                                \"pool\": \"2001:db1::/64\"\n"
+"                            }\n"
+"                        ],\n"
+"                        \"subnet\": \"2001:db1::/48\"\n"
+"                    }\n"
+"                ]\n"
+"            }\n"
+"        ]\n"
 "    }\n"
 };
 
@@ -5830,6 +5859,106 @@ const char* UNPARSED_CONFIGS[] = {
 "                \"valid-lifetime\": 4000\n"
 "            }\n"
 "        ]\n"
+"    }\n",
+    // CONFIGURATION 51
+"{\n"
+"        \"decline-probation-period\": 86400,\n"
+"        \"dhcp-ddns\": {\n"
+"            \"always-include-fqdn\": false,\n"
+"            \"enable-updates\": false,\n"
+"            \"generated-prefix\": \"myhost\",\n"
+"            \"max-queue-size\": 1024,\n"
+"            \"ncr-format\": \"JSON\",\n"
+"            \"ncr-protocol\": \"UDP\",\n"
+"            \"override-client-update\": false,\n"
+"            \"override-no-update\": false,\n"
+"            \"qualifying-suffix\": \"\",\n"
+"            \"replace-client-name\": \"never\",\n"
+"            \"sender-ip\": \"0.0.0.0\",\n"
+"            \"sender-port\": 0,\n"
+"            \"server-ip\": \"127.0.0.1\",\n"
+"            \"server-port\": 53001\n"
+"        },\n"
+"        \"dhcp4o6-port\": 0,\n"
+"        \"expired-leases-processing\": {\n"
+"            \"flush-reclaimed-timer-wait-time\": 25,\n"
+"            \"hold-reclaimed-time\": 3600,\n"
+"            \"max-reclaim-leases\": 100,\n"
+"            \"max-reclaim-time\": 250,\n"
+"            \"reclaim-timer-wait-time\": 10,\n"
+"            \"unwarned-reclaim-cycles\": 5\n"
+"        },\n"
+"        \"hooks-libraries\": [ ],\n"
+"        \"host-reservation-identifiers\": [ \"hw-address\", \"duid\" ],\n"
+"        \"interfaces-config\": {\n"
+"            \"interfaces\": [ ],\n"
+"            \"re-detect\": false\n"
+"        },\n"
+"        \"lease-database\": {\n"
+"            \"type\": \"memfile\"\n"
+"        },\n"
+"        \"mac-sources\": [ \"any\" ],\n"
+"        \"option-data\": [ ],\n"
+"        \"option-def\": [ ],\n"
+"        \"relay-supplied-options\": [ \"65\" ],\n"
+"        \"server-id\": {\n"
+"            \"enterprise-id\": 0,\n"
+"            \"htype\": 0,\n"
+"            \"identifier\": \"\",\n"
+"            \"persist\": true,\n"
+"            \"time\": 0,\n"
+"            \"type\": \"LLT\"\n"
+"        },\n"
+"        \"shared-networks\": [\n"
+"            {\n"
+"                \"comment\": \"A shared-network\",\n"
+"                \"name\": \"foo\",\n"
+"                \"option-data\": [ ],\n"
+"                \"preferred-lifetime\": 0,\n"
+"                \"rapid-commit\": false,\n"
+"                \"rebind-timer\": 0,\n"
+"                \"relay\": {\n"
+"                    \"ip-address\": \"::\"\n"
+"                },\n"
+"                \"renew-timer\": 0,\n"
+"                \"reservation-mode\": \"all\",\n"
+"                \"subnet6\": [\n"
+"                    {\n"
+"                        \"comment\": \"A subnet\",\n"
+"                        \"id\": 1,\n"
+"                        \"option-data\": [ ],\n"
+"                        \"pd-pools\": [\n"
+"                            {\n"
+"                                \"comment\": \"A prefix pool\",\n"
+"                                \"delegated-len\": 64,\n"
+"                                \"option-data\": [ ],\n"
+"                                \"prefix\": \"2001:db2::\",\n"
+"                                \"prefix-len\": 48\n"
+"                            }\n"
+"                        ],\n"
+"                        \"pools\": [\n"
+"                            {\n"
+"                                \"comment\": \"A pool\",\n"
+"                                \"option-data\": [ ],\n"
+"                                \"pool\": \"2001:db1::/64\"\n"
+"                            }\n"
+"                        ],\n"
+"                        \"preferred-lifetime\": 3600,\n"
+"                        \"rapid-commit\": false,\n"
+"                        \"rebind-timer\": 1800,\n"
+"                        \"relay\": {\n"
+"                            \"ip-address\": \"::\"\n"
+"                        },\n"
+"                        \"renew-timer\": 900,\n"
+"                        \"reservation-mode\": \"all\",\n"
+"                        \"subnet\": \"2001:db1::/48\",\n"
+"                        \"valid-lifetime\": 7200\n"
+"                    }\n"
+"                ],\n"
+"                \"valid-lifetime\": 0\n"
+"            }\n"
+"        ],\n"
+"        \"subnet6\": [ ]\n"
 "    }\n"
 };
 
@@ -6080,6 +6209,7 @@ TEST_P(Dhcp6GetConfigTest, run) {
         expected = UNPARSED_CONFIGS[config_counter];
         ConstElementPtr json;
         ASSERT_NO_THROW(json = parseDHCP6(expected, true));
+        ASSERT_NO_THROW(json = parseJSON(expected));
         EXPECT_TRUE(isEquivalent(dhcp, json));
         std::string current = prettyPrint(dhcp, 4, 4) + "\n";
         EXPECT_EQ(expected, current);
index 182b069bcd312f28ae7a54e9fa3206bb8893c91e..9a5566e4d9a0b68a5d4d9031102899dc43840e83 100644 (file)
@@ -320,6 +320,7 @@ TEST_P(Dhcp6GetConfigTest, run) {
         expected = UNPARSED_CONFIGS[config_counter];
         ConstElementPtr json;
         ASSERT_NO_THROW(json = parseDHCP6(expected, true));
+        ASSERT_NO_THROW(json = parseJSON(expected));
         EXPECT_TRUE(isEquivalent(dhcp, json));
         std::string current = prettyPrint(dhcp, 4, 4) + "\n";
         EXPECT_EQ(expected, current);
index 1b1226c3ac7ca0204ff38e72c4eb1455ffee101b..f155c9c5d4642e65297ff438c4e2ab49f66ac1c2 100644 (file)
@@ -234,21 +234,22 @@ SrvConfig::toElement() const {
     dhcp->set("option-data", cfg_option_->toElement());
 
     // Set subnets and shared networks.
-    ConstElementPtr subnets;
+    std::vector<ElementPtr> sn_list;
     if (family == AF_INET) {
-        subnets = cfg_subnets4_->toElement();
-
         ElementPtr plain_subnets = Element::createList();
-        const Subnet4Collection* subs = cfg_subnets4_->getAll();
-        for (Subnet4Collection::const_iterator subnet = subs->cbegin();
-             subnet != subs->cend(); ++subnet) {
+        const Subnet4Collection* subnets = cfg_subnets4_->getAll();
+        for (Subnet4Collection::const_iterator subnet = subnets->cbegin();
+             subnet != subnets->cend(); ++subnet) {
+            ElementPtr subnet_cfg = (*subnet)->toElement();
+            sn_list.push_back(subnet_cfg);
+
             // Skip subnets which are in a shared-network
             SharedNetwork4Ptr network;
             (*subnet)->getSharedNetwork(network);
             if (network) {
                 continue;
             }
-            plain_subnets->add((*subnet)->toElement());
+            plain_subnets->add(subnet_cfg);
         }
         dhcp->set("subnet4", plain_subnets);
 
@@ -256,19 +257,20 @@ SrvConfig::toElement() const {
         dhcp->set("shared-networks", shared_networks);
 
     } else {
-        subnets = cfg_subnets6_->toElement();
-
         ElementPtr plain_subnets = Element::createList();
-        const Subnet6Collection* subs = cfg_subnets6_->getAll();
-        for (Subnet6Collection::const_iterator subnet = subs->cbegin();
-             subnet != subs->cend(); ++subnet) {
+        const Subnet6Collection* subnets = cfg_subnets6_->getAll();
+        for (Subnet6Collection::const_iterator subnet = subnets->cbegin();
+             subnet != subnets->cend(); ++subnet) {
+            ElementPtr subnet_cfg = (*subnet)->toElement();
+            sn_list.push_back(subnet_cfg);
+
             // Skip subnets which are in a shared-network
             SharedNetwork6Ptr network;
             (*subnet)->getSharedNetwork(network);
             if (network) {
                 continue;
             }
-            plain_subnets->add((*subnet)->toElement());
+            plain_subnets->add(subnet_cfg);
         }
         dhcp->set("subnet6", plain_subnets);
 
@@ -278,9 +280,8 @@ SrvConfig::toElement() const {
     // Insert reservations
     CfgHostsList resv_list;
     resv_list.internalize(cfg_hosts_->toElement());
-    const std::vector<ElementPtr>& sn_list = subnets->listValue();
-    for (std::vector<ElementPtr>::const_iterator subnet = sn_list.begin();
-         subnet != sn_list.end(); ++subnet) {
+    for (std::vector<ElementPtr>::const_iterator subnet = sn_list.cbegin();
+         subnet != sn_list.cend(); ++subnet) {
         ConstElementPtr id = (*subnet)->get("id");
         if (isNull(id)) {
             isc_throw(ToElementError, "subnet has no id");