]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3149] Simplified getLinks
authorFrancis Dupont <fdupont@isc.org>
Thu, 14 Dec 2023 14:44:04 +0000 (15:44 +0100)
committerFrancis Dupont <fdupont@isc.org>
Wed, 17 Jan 2024 10:06:16 +0000 (11:06 +0100)
src/lib/dhcpsrv/cfg_subnets4.cc
src/lib/dhcpsrv/cfg_subnets4.h
src/lib/dhcpsrv/cfg_subnets6.cc
src/lib/dhcpsrv/cfg_subnets6.h
src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc
src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc

index fe4967a024e8d10b257c5de4af3674d88d624bd3..5241269cfabc127910a5725b4d9c9f90528e7326 100644 (file)
@@ -498,18 +498,12 @@ CfgSubnets4::selectSubnet(const IOAddress& address,
 }
 
 SubnetIDSet
-CfgSubnets4::getLinks(const IOAddress& link_addr, uint8_t& link_len) const {
+CfgSubnets4::getLinks(const IOAddress& link_addr) const {
     SubnetIDSet links;
-    bool link_len_set = false;
     for (auto const& subnet : subnets_) {
         if (!subnet->inRange(link_addr)) {
             continue;
         }
-        uint8_t plen = subnet->get().second;
-        if (!link_len_set || (plen < link_len)) {
-            link_len_set = true;
-            link_len = plen;
-        }
         links.insert(subnet->getID());
     }
     return (links);
index 84367bb273ecc2908371f1f6ab5a019d864a92f6..11021929e53815b35b1ccb2e1d061b6b9714dc11 100644 (file)
@@ -301,14 +301,13 @@ public:
     /// @brief Convert a link address into a link set.
     ///
     /// Given a link address this returns the ordered list aka set of id
-    /// of subnets the address belongs to. It also sets the minimum link
-    /// length when there is at least one subnet.
+    /// of subnets the address belongs to.
+    ///
+    /// @todo: extend to consider whether a shared network is a link.
     ///
     /// @param link_addr The link address.
-    /// @param[out] link_len The minimum link length.
     /// @return The set of subnet ids the link address belongs to.
-    SubnetIDSet getLinks(const asiolink::IOAddress& link_addr,
-                         uint8_t& link_len) const;
+    SubnetIDSet getLinks(const asiolink::IOAddress& link_addr) const;
 
     /// @brief Updates statistics.
     ///
index 93565ace8937aae397fcc2deaefe812119617f93..f1725ae16c30f2722c62c578757151488916863d 100644 (file)
@@ -387,18 +387,12 @@ CfgSubnets6::getSubnet(const SubnetID id) const {
 }
 
 SubnetIDSet
-CfgSubnets6::getLinks(const IOAddress& link_addr, uint8_t& link_len) const {
+CfgSubnets6::getLinks(const IOAddress& link_addr) const {
     SubnetIDSet links;
-    bool link_len_set = false;
     for (auto const& subnet : subnets_) {
         if (!subnet->inRange(link_addr)) {
             continue;
         }
-        uint8_t plen = subnet->get().second;
-        if (!link_len_set || (plen < link_len)) {
-            link_len_set = true;
-            link_len = plen;
-        }
         links.insert(subnet->getID());
     }
     return (links);
index b21c808193c38ce5c153a1151326e9622153b748..e8fc3a472b1d1cee523914d0d4680eb293773205 100644 (file)
@@ -251,14 +251,13 @@ public:
     /// @brief Convert a link address into a link set.
     ///
     /// Given a link address this returns the ordered list aka set of id
-    /// of subnets the address belongs to. It also sets the minimum link
-    /// length when there is at least one subnet.
+    /// of subnets the address belongs to.
+    ///
+    /// @todo: extend to consider whether a shared network is a link.
     ///
     /// @param link_addr The link address.
-    /// @param[out] link_len The minimum link length.
     /// @return The set of subnet ids the link address belongs to.
-    SubnetIDSet getLinks(const asiolink::IOAddress& link_addr,
-                         uint8_t& link_len) const;
+    SubnetIDSet getLinks(const asiolink::IOAddress& link_addr) const;
 
     /// @brief Updates statistics.
     ///
index f1472e645cc8216289e347ff878c0e4a8c1f5428..d10fd8ee5e555623020f803aabdab3a8a0ad8f6a 100644 (file)
@@ -2334,32 +2334,24 @@ TEST(CfgSubnets4Test, getLinks) {
 
     // No 192.0.4.0 subnet.
     SubnetIDSet links;
-    uint8_t link_len = 111;
-    EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("192.0.4.0"), link_len));
+    EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("192.0.4.0")));
     EXPECT_TRUE(links.empty());
-    EXPECT_EQ(111, link_len);
 
     // A 192.0.2.0/26 subnet.
     links.clear();
-    link_len = 111;
-    EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("192.0.2.0"), link_len));
+    EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("192.0.2.0")));
     SubnetIDSet expected = { 2 };
     EXPECT_EQ(expected, links);
-    EXPECT_EQ(26, link_len);
 
     // Check that any address in the subnet works.
     links.clear();
-    link_len = 111;
-    EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("192.0.2.23"), link_len));
+    EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("192.0.2.23")));
     EXPECT_EQ(expected, links);
-    EXPECT_EQ(26, link_len);
 
     // Check that an address outside the subnet does not work.
     links.clear();
-    link_len = 111;
-    EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("192.0.2.123"), link_len));
+    EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("192.0.2.123")));
     EXPECT_TRUE(links.empty());
-    EXPECT_EQ(111, link_len);
 
     // Add a second 192.0.2.0/26 subnet.
     Subnet4Ptr subnet10(new Subnet4(IOAddress("192.0.2.10"),
@@ -2368,40 +2360,32 @@ TEST(CfgSubnets4Test, getLinks) {
 
     // Now we should get 2 subnets.
     links.clear();
-    link_len = 111;
-    EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("192.0.2.0"), link_len));
+    EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("192.0.2.0")));
     expected = { 2, 10 };
     EXPECT_EQ(expected, links);
-    EXPECT_EQ(26, link_len);
 
     // Add a larger subnet.
     Subnet4Ptr subnet20(new Subnet4(IOAddress("192.0.2.20"),
                                     24, 1, 2, 3, SubnetID(20)));
     ASSERT_NO_THROW(cfg.add(subnet20));
 
-    // Now we should get 3 subnets and a smaller prefix length.
+    // Now we should get 3 subnets.
     links.clear();
-    link_len = 111;
-    EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("192.0.2.0"), link_len));
+    EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("192.0.2.0")));
     expected = { 2, 10, 20 };
     EXPECT_EQ(expected, links);
-    EXPECT_EQ(24, link_len);
 
     // But only the larger subnet if the address is only in it.
     links.clear();
-    link_len = 111;
-    EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("192.0.2.123"), link_len));
+    EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("192.0.2.123")));
     expected = { 20 };
     EXPECT_EQ(expected, links);
-    EXPECT_EQ(24, link_len);
 
     // Even it is not used for Bulk Leasequery, it works for 0.0.0.0 too.
     links.clear();
-    link_len = 111;
-    EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("0.0.0.0"), link_len));
+    EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("0.0.0.0")));
     expected = { 111 };
     EXPECT_EQ(expected, links);
-    EXPECT_EQ(24, link_len);
 }
 
 // This test verifies that for each subnet in the configuration it calls
index 83fad92123eba396112e911610eccc20c2257d36..20707fed8eaf1f8acbc2f2fe4330de1c676c0322 100644 (file)
@@ -2361,33 +2361,24 @@ TEST(CfgSubnets6Test, getLinks) {
 
     // No 2001:db8:4:: subnet.
     SubnetIDSet links;
-    uint8_t link_len = 111;
-    EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("2001:db8:4::"), link_len));
+    EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("2001:db8:4::")));
     EXPECT_TRUE(links.empty());
-    EXPECT_EQ(111, link_len);
 
     // A 2001:db8:2::/64 subnet.
     links.clear();
-    link_len = 111;
-    EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("2001:db8:2::"), link_len));
+    EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("2001:db8:2::")));
     SubnetIDSet expected = { 2 };
     EXPECT_EQ(expected, links);
-    EXPECT_EQ(64, link_len);
 
     // Check that any address in the subnet works.
     links.clear();
-    link_len = 111;
-    EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("2001:db8:2::1234:5678:9abc:def0"),
-                                         link_len));
+    EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("2001:db8:2::1234:5678:9abc:def0")));
     EXPECT_EQ(expected, links);
-    EXPECT_EQ(64, link_len);
 
     // Check that an address outside the subnet does not work.
     links.clear();
-    link_len = 111;
-    EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("2001:db8:2:1::"), link_len));
+    EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("2001:db8:2:1::")));
     EXPECT_TRUE(links.empty());
-    EXPECT_EQ(111, link_len);
 
     // Add a second 2001:db8:2::/64 subnet.
     Subnet6Ptr subnet10(new Subnet6(IOAddress("2001:db8:2::10"), 64, 1, 2, 3,
@@ -2396,40 +2387,32 @@ TEST(CfgSubnets6Test, getLinks) {
 
     // Now we should get 2 subnets.
     links.clear();
-    link_len = 111;
-    EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("2001:db8:2::"), link_len));
+    EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("2001:db8:2::")));
     expected = { 2, 10 };
     EXPECT_EQ(expected, links);
-    EXPECT_EQ(64, link_len);
 
     // Add a larger subnet.
     Subnet6Ptr subnet20(new Subnet6(IOAddress("2001:db8:2::20"), 56, 1, 2, 3,
                                     4, SubnetID(20)));
     ASSERT_NO_THROW(cfg.add(subnet20));
 
-    // Now we should get 3 subnets and a smaller prefix length.
+    // Now we should get 3 subnets.
     links.clear();
-    link_len = 111;
-    EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("2001:db8:2::"), link_len));
+    EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("2001:db8:2::")));
     expected = { 2, 10, 20 };
     EXPECT_EQ(expected, links);
-    EXPECT_EQ(56, link_len);
 
     // But only the larger subnet if the address is only in it.
     links.clear();
-    link_len = 111;
-    EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("2001:db8:2:1::"), link_len));
+    EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("2001:db8:2:1::")));
     expected = { 20 };
     EXPECT_EQ(expected, links);
-    EXPECT_EQ(56, link_len);
 
     // Even it is not used for Bulk Leasequery, it works for :: too.
     links.clear();
-    link_len = 111;
-    EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("::"), link_len));
+    EXPECT_NO_THROW(links = cfg.getLinks(IOAddress("::")));
     expected = { 111 };
     EXPECT_EQ(expected, links);
-    EXPECT_EQ(48, link_len);
 }
 
 // This test verifies that for each subnet in the configuration it calls