From: Francis Dupont Date: Mon, 17 Mar 2025 22:14:21 +0000 (+0100) Subject: [#3802] Updated and fixed tests X-Git-Tag: Kea-2.7.7~14 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=523796c815d5b418d4f089e56fae2fb03956585b;p=thirdparty%2Fkea.git [#3802] Updated and fixed tests --- diff --git a/src/bin/dhcp6/dhcp6_srv.cc b/src/bin/dhcp6/dhcp6_srv.cc index 8f3fb77cd3..417960b126 100644 --- a/src/bin/dhcp6/dhcp6_srv.cc +++ b/src/bin/dhcp6/dhcp6_srv.cc @@ -4530,13 +4530,6 @@ Dhcpv6Srv::processAddrRegInform(AllocEngine::ClientContext6& ctx) { isc_throw(Unexpected, "can't convert the IAADDR option"); } - // Set per-IA context values. - // Note the address is considered as not-temporary address. - - ctx.createIAContext(); - ctx.currentIA().type_ = Lease::TYPE_NA; - ctx.currentIA().iaid_ = no_iaid; - // Client and IADDR addresses must match. if (addr != iaaddr->getAddress()) { isc_throw(RFCViolation, "Address mismatch: client at " << addr @@ -4587,6 +4580,15 @@ Dhcpv6Srv::processAddrRegInform(AllocEngine::ClientContext6& ctx) { addr_reg_inf->getTransid())); addr_reg_rep->addOption(iaaddr); + // Set per-IA context values for DDNS. + // Note the address is considered as not-temporary address. + ctx.createIAContext(); + ctx.currentIA().type_ = Lease::TYPE_NA; + ctx.currentIA().iaid_ = no_iaid; + Option6IAPtr ia(new Option6IA(D6O_IA_NA, no_iaid)); + ia->addOption(iaaddr); + ctx.currentIA().ia_rsp_ = ia; + // Process FQDN. processClientFqdn(addr_reg_inf, addr_reg_rep, ctx); diff --git a/src/bin/dhcp6/tests/addr_reg_unittest.cc b/src/bin/dhcp6/tests/addr_reg_unittest.cc index 08aa73fbbe..5fab4d918a 100644 --- a/src/bin/dhcp6/tests/addr_reg_unittest.cc +++ b/src/bin/dhcp6/tests/addr_reg_unittest.cc @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -370,7 +371,7 @@ TEST_F(AddrRegTest, noSubnet) { } // Test that an IA_NA option is fordidden. -TEST_F(AddrRegTest, iA_NA) { +TEST_F(AddrRegTest, unexpectedIA_NA) { IfaceMgrTestConfig test_config(true); ASSERT_NO_THROW(configure(config_)); @@ -403,7 +404,7 @@ TEST_F(AddrRegTest, iA_NA) { } // Test that an IA_TA option is fordidden. -TEST_F(AddrRegTest, iA_TA) { +TEST_F(AddrRegTest, unexpectedIA_TA) { IfaceMgrTestConfig test_config(true); ASSERT_NO_THROW(configure(config_)); @@ -414,7 +415,7 @@ TEST_F(AddrRegTest, iA_TA) { addr_reg_inf->setIndex(ETH0_INDEX); OptionPtr clientid = generateClientId(); addr_reg_inf->addOption(clientid); - Option6IAPtr ia(new Option6IA(D6O_IA_TA, 234)); + OptionPtr ia(new OptionInt(Option::V6, D6O_IA_TA, 234)); addr_reg_inf->addOption(ia); // Pass it to the server. @@ -437,7 +438,7 @@ TEST_F(AddrRegTest, iA_TA) { } // Test that an IA_PD option is fordidden. -TEST_F(AddrRegTest, iA_PD) { +TEST_F(AddrRegTest, unexpectedIA_PD) { IfaceMgrTestConfig test_config(true); ASSERT_NO_THROW(configure(config_)); @@ -497,7 +498,7 @@ TEST_F(AddrRegTest, noIAADDR) { string expected = "DHCP6_ADDR_REG_INFORM_FAIL "; expected += "error on ADDR-REG-INFORM from client fe80::abcd: "; - expected += "Exactly 1 IAADDRE option expected, but 0 received"; + expected += "Exactly 1 IAADDR option expected, but 0 received"; EXPECT_EQ(1, countFile(expected)); } @@ -535,6 +536,44 @@ TEST_F(AddrRegTest, twoIAADDR) { EXPECT_EQ(1, countFile(expected)); } +// Test that a well formed IAADDR option is required. +TEST_F(AddrRegTest, badIAADDR) { + IfaceMgrTestConfig test_config(true); + + ASSERT_NO_THROW(configure(config_)); + + Pkt6Ptr addr_reg_inf = Pkt6Ptr(new Pkt6(DHCPV6_ADDR_REG_INFORM, 1234)); + addr_reg_inf->setRemoteAddr(IOAddress("fe80::abcd")); + addr_reg_inf->setIface("eth0"); + addr_reg_inf->setIndex(ETH0_INDEX); + OptionPtr clientid = generateClientId(); + addr_reg_inf->addOption(clientid); + OptionCustomPtr iaddr(new OptionCustom(LibDHCP::D6O_IAADDR_DEF(), + Option::V6)); + iaddr->writeAddress(IOAddress("2001:db8:1::1"), 0); + iaddr->writeInteger(3000, 1); + iaddr->writeInteger(4000, 2); + addr_reg_inf->addOption(iaddr); + + // Pass it to the server. + AllocEngine::ClientContext6 ctx; + bool drop = !srv_->earlyGHRLookup(addr_reg_inf, ctx); + ASSERT_FALSE(drop); + ctx.subnet_ = srv_->selectSubnet(addr_reg_inf, drop); + ASSERT_FALSE(drop); + srv_->initContext(ctx, drop); + ASSERT_FALSE(drop); + ASSERT_TRUE(ctx.subnet_); + + // Two IAADDR options: no response. + EXPECT_FALSE(srv_->processAddrRegInform(ctx)); + + string expected = "DHCP6_ADDR_REG_INFORM_FAIL "; + expected += "error on ADDR-REG-INFORM from client fe80::abcd: "; + expected += "can't convert the IAADDR option"; + EXPECT_EQ(1, countFile(expected)); +} + // Test that addresses must match. TEST_F(AddrRegTest, noAddrMatch) { IfaceMgrTestConfig test_config(true); diff --git a/src/lib/dhcp/libdhcp++.cc b/src/lib/dhcp/libdhcp++.cc index db64d3653b..1ee7e95c6f 100644 --- a/src/lib/dhcp/libdhcp++.cc +++ b/src/lib/dhcp/libdhcp++.cc @@ -1336,6 +1336,7 @@ LibDHCP::initOptionDefs() { static_cast(LibDHCP::D6O_NTP_SERVER_DEF()); static_cast(LibDHCP::D6O_BOOTFILE_URL_DEF()); static_cast(LibDHCP::D6O_RSOO_DEF()); + static_cast(LibDHCP::D6O_IAADDR_DEF()); return (true); } @@ -1663,3 +1664,21 @@ LibDHCP::D6O_RSOO_DEF() { } return (*def); } + +const OptionDefinition& +LibDHCP::D6O_IAADDR_DEF() { + static OptionDefinitionPtr def = + LibDHCP::getOptionDef(DHCP6_OPTION_SPACE, D6O_IAADDR); + static bool check_once(true); + if (check_once) { + isc_throw_assert(def); + isc_throw_assert(def->getName() == "iaaddr"); + isc_throw_assert(def->getCode() == D6O_IAADDR); + isc_throw_assert(def->getType() == OPT_RECORD_TYPE); + isc_throw_assert(!def->getArrayType()); + isc_throw_assert(def->getEncapsulatedSpace().empty()); + isc_throw_assert(def->getOptionSpaceName() == DHCP6_OPTION_SPACE); + check_once = false; + } + return (*def); +} diff --git a/src/lib/dhcp/libdhcp++.h b/src/lib/dhcp/libdhcp++.h index a2a0578699..ffa72722f4 100644 --- a/src/lib/dhcp/libdhcp++.h +++ b/src/lib/dhcp/libdhcp++.h @@ -464,6 +464,9 @@ public: /// @brief Get definition of D6O_RSOO option. static const OptionDefinition& D6O_RSOO_DEF(); + /// @brief Get definition of D6O_IAADDR option. + static const OptionDefinition& D6O_IAADDR_DEF(); + private: /// Initialize DHCP option definitions.