Skip to content

Commit 523796c

Browse files
committed
[#3802] Updated and fixed tests
1 parent ac52823 commit 523796c

File tree

4 files changed

+75
-12
lines changed

4 files changed

+75
-12
lines changed

src/bin/dhcp6/dhcp6_srv.cc

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4530,13 +4530,6 @@ Dhcpv6Srv::processAddrRegInform(AllocEngine::ClientContext6& ctx) {
45304530
isc_throw(Unexpected, "can't convert the IAADDR option");
45314531
}
45324532

4533-
// Set per-IA context values.
4534-
// Note the address is considered as not-temporary address.
4535-
4536-
ctx.createIAContext();
4537-
ctx.currentIA().type_ = Lease::TYPE_NA;
4538-
ctx.currentIA().iaid_ = no_iaid;
4539-
45404533
// Client and IADDR addresses must match.
45414534
if (addr != iaaddr->getAddress()) {
45424535
isc_throw(RFCViolation, "Address mismatch: client at " << addr
@@ -4587,6 +4580,15 @@ Dhcpv6Srv::processAddrRegInform(AllocEngine::ClientContext6& ctx) {
45874580
addr_reg_inf->getTransid()));
45884581
addr_reg_rep->addOption(iaaddr);
45894582

4583+
// Set per-IA context values for DDNS.
4584+
// Note the address is considered as not-temporary address.
4585+
ctx.createIAContext();
4586+
ctx.currentIA().type_ = Lease::TYPE_NA;
4587+
ctx.currentIA().iaid_ = no_iaid;
4588+
Option6IAPtr ia(new Option6IA(D6O_IA_NA, no_iaid));
4589+
ia->addOption(iaaddr);
4590+
ctx.currentIA().ia_rsp_ = ia;
4591+
45904592
// Process FQDN.
45914593
processClientFqdn(addr_reg_inf, addr_reg_rep, ctx);
45924594

src/bin/dhcp6/tests/addr_reg_unittest.cc

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <config.h>
88
#include <asiolink/io_address.h>
99
#include <cc/data.h>
10+
#include <dhcp/option_int.h>
1011
#include <dhcp/option6_addrlst.h>
1112
#include <dhcp/testutils/iface_mgr_test_config.h>
1213
#include <dhcp6/json_config_parser.h>
@@ -370,7 +371,7 @@ TEST_F(AddrRegTest, noSubnet) {
370371
}
371372

372373
// Test that an IA_NA option is fordidden.
373-
TEST_F(AddrRegTest, iA_NA) {
374+
TEST_F(AddrRegTest, unexpectedIA_NA) {
374375
IfaceMgrTestConfig test_config(true);
375376

376377
ASSERT_NO_THROW(configure(config_));
@@ -403,7 +404,7 @@ TEST_F(AddrRegTest, iA_NA) {
403404
}
404405

405406
// Test that an IA_TA option is fordidden.
406-
TEST_F(AddrRegTest, iA_TA) {
407+
TEST_F(AddrRegTest, unexpectedIA_TA) {
407408
IfaceMgrTestConfig test_config(true);
408409

409410
ASSERT_NO_THROW(configure(config_));
@@ -414,7 +415,7 @@ TEST_F(AddrRegTest, iA_TA) {
414415
addr_reg_inf->setIndex(ETH0_INDEX);
415416
OptionPtr clientid = generateClientId();
416417
addr_reg_inf->addOption(clientid);
417-
Option6IAPtr ia(new Option6IA(D6O_IA_TA, 234));
418+
OptionPtr ia(new OptionInt<uint32_t>(Option::V6, D6O_IA_TA, 234));
418419
addr_reg_inf->addOption(ia);
419420

420421
// Pass it to the server.
@@ -437,7 +438,7 @@ TEST_F(AddrRegTest, iA_TA) {
437438
}
438439

439440
// Test that an IA_PD option is fordidden.
440-
TEST_F(AddrRegTest, iA_PD) {
441+
TEST_F(AddrRegTest, unexpectedIA_PD) {
441442
IfaceMgrTestConfig test_config(true);
442443

443444
ASSERT_NO_THROW(configure(config_));
@@ -497,7 +498,7 @@ TEST_F(AddrRegTest, noIAADDR) {
497498

498499
string expected = "DHCP6_ADDR_REG_INFORM_FAIL ";
499500
expected += "error on ADDR-REG-INFORM from client fe80::abcd: ";
500-
expected += "Exactly 1 IAADDRE option expected, but 0 received";
501+
expected += "Exactly 1 IAADDR option expected, but 0 received";
501502
EXPECT_EQ(1, countFile(expected));
502503
}
503504

@@ -535,6 +536,44 @@ TEST_F(AddrRegTest, twoIAADDR) {
535536
EXPECT_EQ(1, countFile(expected));
536537
}
537538

539+
// Test that a well formed IAADDR option is required.
540+
TEST_F(AddrRegTest, badIAADDR) {
541+
IfaceMgrTestConfig test_config(true);
542+
543+
ASSERT_NO_THROW(configure(config_));
544+
545+
Pkt6Ptr addr_reg_inf = Pkt6Ptr(new Pkt6(DHCPV6_ADDR_REG_INFORM, 1234));
546+
addr_reg_inf->setRemoteAddr(IOAddress("fe80::abcd"));
547+
addr_reg_inf->setIface("eth0");
548+
addr_reg_inf->setIndex(ETH0_INDEX);
549+
OptionPtr clientid = generateClientId();
550+
addr_reg_inf->addOption(clientid);
551+
OptionCustomPtr iaddr(new OptionCustom(LibDHCP::D6O_IAADDR_DEF(),
552+
Option::V6));
553+
iaddr->writeAddress(IOAddress("2001:db8:1::1"), 0);
554+
iaddr->writeInteger<uint32_t>(3000, 1);
555+
iaddr->writeInteger<uint32_t>(4000, 2);
556+
addr_reg_inf->addOption(iaddr);
557+
558+
// Pass it to the server.
559+
AllocEngine::ClientContext6 ctx;
560+
bool drop = !srv_->earlyGHRLookup(addr_reg_inf, ctx);
561+
ASSERT_FALSE(drop);
562+
ctx.subnet_ = srv_->selectSubnet(addr_reg_inf, drop);
563+
ASSERT_FALSE(drop);
564+
srv_->initContext(ctx, drop);
565+
ASSERT_FALSE(drop);
566+
ASSERT_TRUE(ctx.subnet_);
567+
568+
// Two IAADDR options: no response.
569+
EXPECT_FALSE(srv_->processAddrRegInform(ctx));
570+
571+
string expected = "DHCP6_ADDR_REG_INFORM_FAIL ";
572+
expected += "error on ADDR-REG-INFORM from client fe80::abcd: ";
573+
expected += "can't convert the IAADDR option";
574+
EXPECT_EQ(1, countFile(expected));
575+
}
576+
538577
// Test that addresses must match.
539578
TEST_F(AddrRegTest, noAddrMatch) {
540579
IfaceMgrTestConfig test_config(true);

src/lib/dhcp/libdhcp++.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,7 @@ LibDHCP::initOptionDefs() {
13361336
static_cast<void>(LibDHCP::D6O_NTP_SERVER_DEF());
13371337
static_cast<void>(LibDHCP::D6O_BOOTFILE_URL_DEF());
13381338
static_cast<void>(LibDHCP::D6O_RSOO_DEF());
1339+
static_cast<void>(LibDHCP::D6O_IAADDR_DEF());
13391340

13401341
return (true);
13411342
}
@@ -1663,3 +1664,21 @@ LibDHCP::D6O_RSOO_DEF() {
16631664
}
16641665
return (*def);
16651666
}
1667+
1668+
const OptionDefinition&
1669+
LibDHCP::D6O_IAADDR_DEF() {
1670+
static OptionDefinitionPtr def =
1671+
LibDHCP::getOptionDef(DHCP6_OPTION_SPACE, D6O_IAADDR);
1672+
static bool check_once(true);
1673+
if (check_once) {
1674+
isc_throw_assert(def);
1675+
isc_throw_assert(def->getName() == "iaaddr");
1676+
isc_throw_assert(def->getCode() == D6O_IAADDR);
1677+
isc_throw_assert(def->getType() == OPT_RECORD_TYPE);
1678+
isc_throw_assert(!def->getArrayType());
1679+
isc_throw_assert(def->getEncapsulatedSpace().empty());
1680+
isc_throw_assert(def->getOptionSpaceName() == DHCP6_OPTION_SPACE);
1681+
check_once = false;
1682+
}
1683+
return (*def);
1684+
}

src/lib/dhcp/libdhcp++.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,9 @@ class LibDHCP {
464464
/// @brief Get definition of D6O_RSOO option.
465465
static const OptionDefinition& D6O_RSOO_DEF();
466466

467+
/// @brief Get definition of D6O_IAADDR option.
468+
static const OptionDefinition& D6O_IAADDR_DEF();
469+
467470
private:
468471

469472
/// Initialize DHCP option definitions.

0 commit comments

Comments
 (0)