summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrancis Dupont <fdupont@isc.org>2023-12-14 15:44:04 +0100
committerFrancis Dupont <fdupont@isc.org>2024-01-17 11:06:16 +0100
commit7c84c8e88018f67cf8db6534b4948c9a719c4c3b (patch)
tree574af169155d4a8677ce5ecf02adb4155ffa60c2
parent[#3149] Rewrote getLeases6ByLink (diff)
downloadkea-7c84c8e88018f67cf8db6534b4948c9a719c4c3b.tar.xz
kea-7c84c8e88018f67cf8db6534b4948c9a719c4c3b.zip
[#3149] Simplified getLinks
-rw-r--r--src/lib/dhcpsrv/cfg_subnets4.cc8
-rw-r--r--src/lib/dhcpsrv/cfg_subnets4.h9
-rw-r--r--src/lib/dhcpsrv/cfg_subnets6.cc8
-rw-r--r--src/lib/dhcpsrv/cfg_subnets6.h9
-rw-r--r--src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc34
-rw-r--r--src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc35
6 files changed, 28 insertions, 75 deletions
diff --git a/src/lib/dhcpsrv/cfg_subnets4.cc b/src/lib/dhcpsrv/cfg_subnets4.cc
index fe4967a024..5241269cfa 100644
--- a/src/lib/dhcpsrv/cfg_subnets4.cc
+++ b/src/lib/dhcpsrv/cfg_subnets4.cc
@@ -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);
diff --git a/src/lib/dhcpsrv/cfg_subnets4.h b/src/lib/dhcpsrv/cfg_subnets4.h
index 84367bb273..11021929e5 100644
--- a/src/lib/dhcpsrv/cfg_subnets4.h
+++ b/src/lib/dhcpsrv/cfg_subnets4.h
@@ -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.
///
diff --git a/src/lib/dhcpsrv/cfg_subnets6.cc b/src/lib/dhcpsrv/cfg_subnets6.cc
index 93565ace89..f1725ae16c 100644
--- a/src/lib/dhcpsrv/cfg_subnets6.cc
+++ b/src/lib/dhcpsrv/cfg_subnets6.cc
@@ -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);
diff --git a/src/lib/dhcpsrv/cfg_subnets6.h b/src/lib/dhcpsrv/cfg_subnets6.h
index b21c808193..e8fc3a472b 100644
--- a/src/lib/dhcpsrv/cfg_subnets6.h
+++ b/src/lib/dhcpsrv/cfg_subnets6.h
@@ -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.
///
diff --git a/src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc b/src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc
index f1472e645c..d10fd8ee5e 100644
--- a/src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc
+++ b/src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc
@@ -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
diff --git a/src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc b/src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc
index 83fad92123..20707fed8e 100644
--- a/src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc
+++ b/src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc
@@ -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