Skip to content

Commit 69f6467

Browse files
committed
[#1387] Addressed comments
1 parent a12167b commit 69f6467

File tree

6 files changed

+85
-37
lines changed

6 files changed

+85
-37
lines changed

doc/sphinx/arm/dhcp6-srv.rst

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4273,17 +4273,16 @@ another.
42734273

42744274
.. note::
42754275

4276-
Since Kea 2.7.1, a reserved (so delegated) prefix can be associated
4277-
with a single prefix to exclude as for prefix delegation pools
4278-
:ref:`pd-exclude-option`. The host reservation syntax is extended
4279-
by a new entry ``excluded-prefixes`` which when is present must have
4280-
the same size as the ``prefixes`` entry: both contains strings
4281-
representing IPv6 prefixes (e.g. ``2001:db8::/48``). Each element of
4282-
the ``excluded-prefixes`` must be either the empty string or match
4283-
the prefix at the same position in the ``prefixes`` list, e.g.
4284-
``2001:db8:0:1::/64`` matches / can be associated with ``2001:db8::/48``.
4285-
An empty ``excluded-prefixes`` list or a list with only empty strings
4286-
can be omitted (and will be omitted when produced by Kea).
4276+
Beginning with Kea 2.7.3, the host reservation syntax supports
4277+
a new entry, ``excluded-prefixes``. It can be used to specify
4278+
prefixes the client should exclude from delegated prefixes.
4279+
When present it must have the same number of elements as the
4280+
``prefixes`` entry. Both entries contain strings representing IPv6
4281+
prefixes. Each element of the ``excluded-prefixes`` must be either
4282+
an empty string or match the prefix at the same position in
4283+
``prefixes``. An empty ``excluded-prefixes`` list or a list with
4284+
only empty strings can be omitted. An example which excludes
4285+
``2001:db8:0:1::/64`` from ``2001:db8::/48`` is shown below:
42874286

42884287
::
42894288

@@ -4303,10 +4302,11 @@ another.
43034302

43044303
.. note::
43054304

4306-
Host reservations have precedence over prefix pools so when a reserved
4307-
prefix without an excluded prefix is assigned no pd-exclude option
4308-
is added to the prefix option even the prefix is in a configured
4309-
prefix pool with an excluded prefix (different from previous behavior).
4305+
Since host reservations have precedence over prefix pools, a reserved
4306+
prefix without an excluded prefix will not add a pd-exclude option
4307+
to the prefix option even if the delegated prefix is in a configured
4308+
prefix pool that does specify an excluded prefix (different from
4309+
previous behavior).
43104310

43114311
.. _reservation6-conflict:
43124312

src/bin/dhcp6/dhcp6_srv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,7 @@ class Dhcpv6Srv : public process::Daemon {
10641064
///
10651065
/// @param ctx client context (contains subnet and hosts).
10661066
/// @param lease lease (contains address/prefix and prefix length).
1067+
/// @param the prefix exclude option or null.
10671068
OptionPtr getPDExclude(const AllocEngine::ClientContext6& ctx,
10681069
const Lease6Ptr& lease);
10691070

src/bin/dhcp6/tests/sarr_unittest.cc

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -419,12 +419,16 @@ class SARRTest : public Dhcpv6SrvTest {
419419
/// @brief This test verifies that it is possible to specify an excluded
420420
/// prefix (RFC 6603) and send it back to the client requesting prefix
421421
/// delegation using a pool.
422-
void directClientExcludedPrefixPool();
422+
///
423+
/// @param request_pdx request pd exclude option.
424+
void directClientExcludedPrefixPool(bool request_pdx);
423425

424426
/// @brief This test verifies that it is possible to specify an excluded
425427
/// prefix (RFC 6603) and send it back to the client requesting prefix
426428
/// delegation using a reservation.
427-
void directClientExcludedPrefixHost();
429+
///
430+
/// @param request_pdx request pd exclude option.
431+
void directClientExcludedPrefixHost(bool request_pdx);
428432

429433
/// @brief Check that when the client includes the Rapid Commit option in
430434
/// its Solicit, the server responds with Reply and commits the lease.
@@ -682,11 +686,14 @@ TEST_F(SARRTest, optionsInheritanceMultiThreading) {
682686
}
683687

684688
void
685-
SARRTest::directClientExcludedPrefixPool() {
689+
SARRTest::directClientExcludedPrefixPool(bool request_pdx) {
686690
Dhcp6Client client;
687691
// Configure client to request IA_PD.
688692
client.requestPrefix();
689-
client.requestOption(D6O_PD_EXCLUDE);
693+
// Request pd exclude option when wanted.
694+
if (request_pdx) {
695+
client.requestOption(D6O_PD_EXCLUDE);
696+
}
690697
configure(CONFIGS[3], *client.getServer());
691698
// Make sure we ended-up having expected number of subnets configured.
692699
const Subnet6Collection* subnets = CfgMgr::instance().getCurrentCfg()->
@@ -713,6 +720,10 @@ SARRTest::directClientExcludedPrefixPool() {
713720
Option6IAPrefixPtr pd_option = boost::dynamic_pointer_cast<Option6IAPrefix>(option);
714721
ASSERT_TRUE(pd_option);
715722
option = pd_option->getOption(D6O_PD_EXCLUDE);
723+
if (!request_pdx) {
724+
EXPECT_FALSE(option);
725+
return;
726+
}
716727
ASSERT_TRUE(option);
717728
Option6PDExcludePtr pd_exclude = boost::dynamic_pointer_cast<Option6PDExclude>(option);
718729
ASSERT_TRUE(pd_exclude);
@@ -723,22 +734,35 @@ SARRTest::directClientExcludedPrefixPool() {
723734

724735
TEST_F(SARRTest, directClientExcludedPrefixPool) {
725736
Dhcpv6SrvMTTestGuard guard(*this, false);
726-
directClientExcludedPrefixPool();
737+
directClientExcludedPrefixPool(true);
727738
}
728739

729740
TEST_F(SARRTest, directClientExcludedPrefixPoolMultiThreading) {
730741
Dhcpv6SrvMTTestGuard guard(*this, true);
731-
directClientExcludedPrefixPool();
742+
directClientExcludedPrefixPool(true);
743+
}
744+
745+
TEST_F(SARRTest, directClientExcludedPrefixPoolNoOro) {
746+
Dhcpv6SrvMTTestGuard guard(*this, false);
747+
directClientExcludedPrefixPool(false);
748+
}
749+
750+
TEST_F(SARRTest, directClientExcludedPrefixPoolNoOroMultiThreading) {
751+
Dhcpv6SrvMTTestGuard guard(*this, true);
752+
directClientExcludedPrefixPool(false);
732753
}
733754

734755
void
735-
SARRTest::directClientExcludedPrefixHost() {
756+
SARRTest::directClientExcludedPrefixHost(bool request_pdx) {
736757
Dhcp6Client client;
737758
// Set DUID matching the one used to create host reservations.
738759
client.setDUID("01:02:03:05");
739760
// Configure client to request IA_PD.
740761
client.requestPrefix();
741-
client.requestOption(D6O_PD_EXCLUDE);
762+
// Request pd exclude option when wanted.
763+
if (request_pdx) {
764+
client.requestOption(D6O_PD_EXCLUDE);
765+
}
742766
configure(CONFIGS[8], *client.getServer());
743767
// Make sure we ended-up having expected number of subnets configured.
744768
const Subnet6Collection* subnets = CfgMgr::instance().getCurrentCfg()->
@@ -765,6 +789,10 @@ SARRTest::directClientExcludedPrefixHost() {
765789
Option6IAPrefixPtr pd_option = boost::dynamic_pointer_cast<Option6IAPrefix>(option);
766790
ASSERT_TRUE(pd_option);
767791
option = pd_option->getOption(D6O_PD_EXCLUDE);
792+
if (!request_pdx) {
793+
EXPECT_FALSE(option);
794+
return;
795+
}
768796
ASSERT_TRUE(option);
769797
Option6PDExcludePtr pd_exclude = boost::dynamic_pointer_cast<Option6PDExclude>(option);
770798
ASSERT_TRUE(pd_exclude);
@@ -775,12 +803,22 @@ SARRTest::directClientExcludedPrefixHost() {
775803

776804
TEST_F(SARRTest, directClientExcludedPrefixHost) {
777805
Dhcpv6SrvMTTestGuard guard(*this, false);
778-
directClientExcludedPrefixHost();
806+
directClientExcludedPrefixHost(true);
779807
}
780808

781809
TEST_F(SARRTest, directClientExcludedPrefixHostMultiThreading) {
782810
Dhcpv6SrvMTTestGuard guard(*this, true);
783-
directClientExcludedPrefixHost();
811+
directClientExcludedPrefixHost(true);
812+
}
813+
814+
TEST_F(SARRTest, directClientExcludedPrefixHostNoOro) {
815+
Dhcpv6SrvMTTestGuard guard(*this, false);
816+
directClientExcludedPrefixHost(false);
817+
}
818+
819+
TEST_F(SARRTest, directClientExcludedPrefixHostNoOroMultiThreading) {
820+
Dhcpv6SrvMTTestGuard guard(*this, true);
821+
directClientExcludedPrefixHost(false);
784822
}
785823

786824
void

src/lib/dhcpsrv/parsers/host_reservation_parser.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,8 @@ HostReservationParser6::parseInternal(const SubnetID& subnet_id,
381381
uint8_t excluded_prefix_len(0);
382382
parsePrefix(exclude, excluded_prefix, excluded_prefix_len,
383383
"exclude prefix");
384+
// setPDExclude calls the Option6PDExclude constructor
385+
// which throws on invalid prefix.
384386
res.setPDExclude(excluded_prefix, excluded_prefix_len);
385387
}
386388
host->addReservation(res);

src/lib/dhcpsrv/tests/host_reservation_parser_unittest.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,24 @@ TEST_F(HostReservationParserTest, dhcp6ExcludedTooLong) {
968968
testInvalidConfig<HostReservationParser6>(config);
969969
}
970970

971+
// This test verifies that the configuration parser throws an exception
972+
// when the excluded prefix is invalid (prefixes do not match).
973+
TEST_F(HostReservationParserTest, dhcp6ExcludedPrefixNotMatch) {
974+
std::string config = "{ \"duid\": \"01:02:03:04:05:06:07:08:09:0A\","
975+
"\"prefixes\": [ \"2001:db8::/48\" ],"
976+
"\"excluded-prefixes\": [ \"2001:db9:0:1::/64\" ] }";
977+
testInvalidConfig<HostReservationParser6>(config);
978+
}
979+
980+
// This test verifies that the configuration parser throws an exception
981+
// when the excluded prefix is invalid (bad length).
982+
TEST_F(HostReservationParserTest, dhcp6ExcludedPrefixBadLength) {
983+
std::string config = "{ \"duid\": \"01:02:03:04:05:06:07:08:09:0A\","
984+
"\"prefixes\": [ \"2001:db8::/48\" ],"
985+
"\"excluded-prefixes\": [ \"2001:db8::/48\" ] }";
986+
testInvalidConfig<HostReservationParser6>(config);
987+
}
988+
971989
// This test verifies that the configuration parser throws an exception
972990
// when invalid prefix length type is specified.
973991
TEST_F(HostReservationParserTest, dhcp6InvalidPrefixLengthType) {

src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,19 +1531,8 @@ GenericHostDataSourceTest::testPrefixExclude(std::string prefix,
15311531
ASSERT_TRUE(from_hds);
15321532

15331533
HostDataSourceUtils::compareHosts(host, from_hds);
1534-
1535-
#if 0
1536-
// Verify the test is meaningful.
1537-
HostPtr host2 = HostDataSourceUtils::initializeHost6(prefix,
1538-
"2001:db8:0:2::",
1539-
Host::IDENT_DUID,
1540-
false);
1541-
host2->setIPv4SubnetID(host->getIPv4SubnetID());
1542-
host2->setIPv6SubnetID(host->getIPv6SubnetID());
1543-
ASSERT_TRUE(host2);
1544-
HostDataSourceUtils::compareHosts(host, host2);
1545-
#endif
15461534
}
1535+
15471536
void
15481537
GenericHostDataSourceTest::testMultipleSubnets(int subnets,
15491538
const Host::IdentifierType& id) {

0 commit comments

Comments
 (0)