|
@@ -53,17 +53,16 @@ TEST_F(Dhcpv6SrvTest, Hooks) {
|
|
|
NakedDhcpv6Srv srv(0);
|
|
|
|
|
|
// check if appropriate hooks are registered
|
|
|
- int hook_index_buffer6_receive = -1;
|
|
|
- int hook_index_buffer6_send = -1;
|
|
|
- int hook_index_lease6_renew = -1;
|
|
|
- int hook_index_lease6_release = -1;
|
|
|
- int hook_index_lease6_rebind = -1;
|
|
|
- int hook_index_lease6_decline = -1;
|
|
|
- int hook_index_pkt6_received = -1;
|
|
|
- int hook_index_select_subnet = -1;
|
|
|
- int hook_index_pkt6_send = -1;
|
|
|
- int hook_index_host6_identifier= -1;
|
|
|
-
|
|
|
+ int hook_index_buffer6_receive = -1;
|
|
|
+ int hook_index_buffer6_send = -1;
|
|
|
+ int hook_index_lease6_renew = -1;
|
|
|
+ int hook_index_lease6_release = -1;
|
|
|
+ int hook_index_lease6_rebind = -1;
|
|
|
+ int hook_index_lease6_decline = -1;
|
|
|
+ int hook_index_pkt6_received = -1;
|
|
|
+ int hook_index_select_subnet = -1;
|
|
|
+ int hook_index_pkt6_send = -1;
|
|
|
+ int hook_index_host6_identifier = -1;
|
|
|
|
|
|
// check if appropriate indexes are set
|
|
|
EXPECT_NO_THROW(hook_index_buffer6_receive = ServerHooks::getServerHooks()
|
|
@@ -666,19 +665,46 @@ public:
|
|
|
handle.getArgument("id_type", type);
|
|
|
|
|
|
// Make sure id_value parameter is passed.
|
|
|
- std::vector<uint8_t> id;
|
|
|
- handle.getArgument("id_value", id);
|
|
|
+ std::vector<uint8_t> id_test;
|
|
|
+ handle.getArgument("id_value", id_test);
|
|
|
|
|
|
- id.resize(3);
|
|
|
- id[0] = 0x66; // f
|
|
|
- id[1] = 0x6f; // o
|
|
|
- id[2] = 0x6f; // o
|
|
|
+ // Ok, now set the identifier.
|
|
|
+ std::vector<uint8_t> id = { 0x66, 0x6f, 0x6f }; // foo
|
|
|
handle.setArgument("id_value", id);
|
|
|
handle.setArgument("id_type", Host::IDENT_FLEX);
|
|
|
|
|
|
return (0);
|
|
|
}
|
|
|
|
|
|
+ /// @brief Test host4_identifier callout by setting identifier to hwaddr
|
|
|
+ ///
|
|
|
+ /// This callout always returns fixed HWADDR: 00:01:02:03:04:05
|
|
|
+ ///
|
|
|
+ /// @param callout_handle handle passed by the hooks framework
|
|
|
+ /// @return always 0
|
|
|
+ static int
|
|
|
+ host6_identifier_hwaddr_callout(CalloutHandle& handle) {
|
|
|
+ callback_name_ = string("host6_identifier");
|
|
|
+
|
|
|
+ // Make sure the query6 parameter is passed.
|
|
|
+ handle.getArgument("query6", callback_qry_pkt6_);
|
|
|
+
|
|
|
+ // Make sure id_type parameter is passed.
|
|
|
+ Host::IdentifierType type = Host::IDENT_FLEX;
|
|
|
+ handle.getArgument("id_type", type);
|
|
|
+
|
|
|
+ // Make sure id_value parameter is passed.
|
|
|
+ std::vector<uint8_t> id_test;
|
|
|
+ handle.getArgument("id_value", id_test);
|
|
|
+
|
|
|
+ // Ok, now set the identifier to 00:01:02:03:04:05
|
|
|
+ std::vector<uint8_t> id = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 };
|
|
|
+ handle.setArgument("id_value", id);
|
|
|
+ handle.setArgument("id_type", Host::IDENT_HWADDR);
|
|
|
+
|
|
|
+ return (0);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/// Resets buffers used to store data received by callouts
|
|
|
void resetCalloutBuffers() {
|
|
@@ -2264,7 +2290,6 @@ TEST_F(HooksDhcpv6SrvTest, lease6DeclineDrop) {
|
|
|
EXPECT_EQ(Lease::STATE_DEFAULT, from_mgr->state_);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
// Checks if callout installed on host6_identifier can generate an
|
|
|
// identifier and whether that identifier is actually used.
|
|
|
TEST_F(HooksDhcpv6SrvTest, host6Identifier) {
|
|
@@ -2338,6 +2363,79 @@ TEST_F(HooksDhcpv6SrvTest, host6Identifier) {
|
|
|
ASSERT_EQ("2001:db8::f00", addr_opt->getAddress().toText());
|
|
|
}
|
|
|
|
|
|
+// Checks if callout installed on host6_identifier can generate an identifier
|
|
|
+// other type. This particular callout always returns hwaddr.
|
|
|
+TEST_F(HooksDhcpv6SrvTest, host6Identifier_hwaddr) {
|
|
|
+
|
|
|
+ // Configure 2 subnets, both directly reachable over local interface
|
|
|
+ // (let's not complicate the matter with relays)
|
|
|
+ string config = "{ \"interfaces-config\": {\n"
|
|
|
+ " \"interfaces\": [ \"*\" ]\n"
|
|
|
+ "},\n"
|
|
|
+ "\"preferred-lifetime\": 3000,\n"
|
|
|
+ "\"rebind-timer\": 2000,\n"
|
|
|
+ "\"renew-timer\": 1000,\n"
|
|
|
+ "\"host-reservation-identifiers\": [ \"flex-id\" ],\n"
|
|
|
+ "\"subnet6\": [ {\n"
|
|
|
+ " \"pools\": [ { \"pool\": \"2001:db8::/64\" } ],\n"
|
|
|
+ " \"subnet\": \"2001:db8::/48\", \n"
|
|
|
+ " \"interface\": \"" + valid_iface_ + "\",\n"
|
|
|
+ " \"reservations\": [\n"
|
|
|
+ " {\n"
|
|
|
+ " \"hw-address\": \"00:01:02:03:04:05\",\n"
|
|
|
+ " \"ip-addresses\": [ \"2001:db8::f00\" ]\n"
|
|
|
+ " }\n"
|
|
|
+ " ]\n"
|
|
|
+ " } ]\n,"
|
|
|
+ "\"valid-lifetime\": 4000 }";
|
|
|
+
|
|
|
+ ConstElementPtr json;
|
|
|
+ EXPECT_NO_THROW(json = parseDHCP6(config));
|
|
|
+ ConstElementPtr status;
|
|
|
+
|
|
|
+ // Configure the server and make sure the config is accepted
|
|
|
+ EXPECT_NO_THROW(status = configureDhcp6Server(*srv_, json));
|
|
|
+ ASSERT_TRUE(status);
|
|
|
+ comment_ = isc::config::parseAnswer(rcode_, status);
|
|
|
+ ASSERT_EQ(0, rcode_);
|
|
|
+
|
|
|
+ CfgMgr::instance().commit();
|
|
|
+
|
|
|
+ // Install host6_identifier_foo_callout
|
|
|
+ EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
|
|
|
+ "host6_identifier", host6_identifier_hwaddr_callout));
|
|
|
+
|
|
|
+ // Prepare solicit packet. Server should select first subnet for it
|
|
|
+ Pkt6Ptr sol = Pkt6Ptr(new Pkt6(DHCPV6_SOLICIT, 1234));
|
|
|
+ sol->setRemoteAddr(IOAddress("fe80::abcd"));
|
|
|
+ sol->setIface(valid_iface_);
|
|
|
+ sol->addOption(generateIA(D6O_IA_NA, 234, 1500, 3000));
|
|
|
+ OptionPtr clientid = generateClientId();
|
|
|
+ sol->addOption(clientid);
|
|
|
+
|
|
|
+ // Pass it to the server and get an advertise
|
|
|
+ Pkt6Ptr adv = srv_->processSolicit(sol);
|
|
|
+
|
|
|
+ // Check if we get response at all
|
|
|
+ ASSERT_TRUE(adv);
|
|
|
+
|
|
|
+ // Check that the callback called is indeed the one we installed
|
|
|
+ EXPECT_EQ("host6_identifier", callback_name_);
|
|
|
+
|
|
|
+ // Check that pkt6 argument passing was successful and returned proper value
|
|
|
+ EXPECT_TRUE(callback_qry_pkt6_.get() == sol.get());
|
|
|
+
|
|
|
+ // Now check if we got the reserved address
|
|
|
+ OptionPtr tmp = adv->getOption(D6O_IA_NA);
|
|
|
+ ASSERT_TRUE(tmp);
|
|
|
+
|
|
|
+ // Check that IA_NA was returned and that there's an address included
|
|
|
+ boost::shared_ptr<Option6IAAddr> addr_opt = checkIA_NA(adv, 234, 1000, 2000);
|
|
|
+
|
|
|
+ ASSERT_TRUE(addr_opt);
|
|
|
+ ASSERT_EQ("2001:db8::f00", addr_opt->getAddress().toText());
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
// Verifies that libraries are unloaded by server destruction
|
|
|
// The callout libraries write their library index number to a marker
|