diff options
author | Francis Dupont <fdupont@isc.org> | 2020-05-24 20:49:39 +0200 |
---|---|---|
committer | Francis Dupont <fdupont@isc.org> | 2020-07-07 12:47:26 +0200 |
commit | a0a0a9160a94d0e782f3ad97d838532a28a8d195 (patch) | |
tree | bb6e8904a95ca1015f8811e37a474bd64bd50f38 /src/bin/dhcp4/tests | |
parent | [#1247] Improved revision id comments (diff) | |
download | kea-a0a0a9160a94d0e782f3ad97d838532a28a8d195.tar.xz kea-a0a0a9160a94d0e782f3ad97d838532a28a8d195.zip |
[#553] Checkpoint: convert to use interface indexes
Diffstat (limited to 'src/bin/dhcp4/tests')
-rw-r--r-- | src/bin/dhcp4/tests/dhcp4_client.cc | 17 | ||||
-rw-r--r-- | src/bin/dhcp4/tests/dhcp4_client.h | 15 | ||||
-rw-r--r-- | src/bin/dhcp4/tests/dhcp4_srv_unittest.cc | 73 | ||||
-rw-r--r-- | src/bin/dhcp4/tests/dhcp4_test_utils.cc | 10 | ||||
-rw-r--r-- | src/bin/dhcp4/tests/dhcp4to6_ipc_unittest.cc | 7 | ||||
-rw-r--r-- | src/bin/dhcp4/tests/direct_client_unittest.cc | 35 | ||||
-rw-r--r-- | src/bin/dhcp4/tests/dora_unittest.cc | 1 | ||||
-rw-r--r-- | src/bin/dhcp4/tests/fqdn_unittest.cc | 9 | ||||
-rw-r--r-- | src/bin/dhcp4/tests/hooks_unittest.cc | 10 | ||||
-rw-r--r-- | src/bin/dhcp4/tests/host_unittest.cc | 5 | ||||
-rw-r--r-- | src/bin/dhcp4/tests/shared_network_unittest.cc | 25 | ||||
-rw-r--r-- | src/bin/dhcp4/tests/vendor_opts_unittest.cc | 11 |
12 files changed, 172 insertions, 46 deletions
diff --git a/src/bin/dhcp4/tests/dhcp4_client.cc b/src/bin/dhcp4/tests/dhcp4_client.cc index b7e861d99e..38290bda92 100644 --- a/src/bin/dhcp4/tests/dhcp4_client.cc +++ b/src/bin/dhcp4/tests/dhcp4_client.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2019 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2014-2020 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -9,6 +9,7 @@ #include <dhcp/option.h> #include <dhcp/option_int_array.h> #include <dhcp/option_vendor.h> +#include <dhcp/tests/iface_mgr_test_config.h> #include <dhcpsrv/lease.h> #include <dhcp4/tests/dhcp4_client.h> #include <util/range_utilities.h> @@ -23,7 +24,7 @@ namespace test { Dhcp4Client::Configuration::Configuration() : routers_(), dns_servers_(), log_servers_(), quotes_servers_(), - serverid_("0.0.0.0"), siaddr_(asiolink::IOAddress::IPV4_ZERO_ADDRESS()) { + serverid_("0.0.0.0"), siaddr_(IOAddress::IPV4_ZERO_ADDRESS()) { reset(); } @@ -33,8 +34,8 @@ Dhcp4Client::Configuration::reset() { dns_servers_.clear(); log_servers_.clear(); quotes_servers_.clear(); - serverid_ = asiolink::IOAddress("0.0.0.0"); - siaddr_ = asiolink::IOAddress::IPV4_ZERO_ADDRESS(); + serverid_ = IOAddress("0.0.0.0"); + siaddr_ = IOAddress::IPV4_ZERO_ADDRESS(); sname_.clear(); boot_file_name_.clear(); lease_ = Lease4(); @@ -48,6 +49,7 @@ Dhcp4Client::Dhcp4Client(const Dhcp4Client::State& state) : hwaddr_(generateHWAddr()), clientid_(), iface_name_("eth0"), + iface_index_(ETH0_INDEX), relay_addr_("192.0.2.2"), requested_options_(), server_facing_relay_addr_("10.0.0.2"), @@ -67,6 +69,7 @@ Dhcp4Client::Dhcp4Client(boost::shared_ptr<NakedDhcpv4Srv> srv, hwaddr_(generateHWAddr()), clientid_(), iface_name_("eth0"), + iface_index_(ETH0_INDEX), relay_addr_("192.0.2.2"), requested_options_(), server_facing_relay_addr_("10.0.0.2"), @@ -77,7 +80,7 @@ Dhcp4Client::Dhcp4Client(boost::shared_ptr<NakedDhcpv4Srv> srv, } void -Dhcp4Client::addRequestedAddress(const asiolink::IOAddress& addr) { +Dhcp4Client::addRequestedAddress(const IOAddress& addr) { if (context_.query_) { Option4AddrLstPtr opt(new Option4AddrLst(DHO_DHCP_REQUESTED_ADDRESS, addr)); @@ -213,8 +216,7 @@ Dhcp4Client::applyConfiguration() { } void -Dhcp4Client::createLease(const asiolink::IOAddress& addr, - const uint32_t valid_lft) { +Dhcp4Client::createLease(const IOAddress& addr, const uint32_t valid_lft) { Lease4 lease(addr, hwaddr_, 0, 0, valid_lft, time(NULL), 0, false, false, ""); config_.lease_ = lease; @@ -540,6 +542,7 @@ Dhcp4Client::sendMsg(const Pkt4Ptr& msg) { msg_copy->setRemoteAddr(msg->getLocalAddr()); msg_copy->setLocalAddr(dest_addr_); msg_copy->setIface(iface_name_); + msg_copy->setIndex(iface_index_); // Copy classes const ClientClasses& classes = msg->getClasses(); for (ClientClasses::const_iterator cclass = classes.cbegin(); diff --git a/src/bin/dhcp4/tests/dhcp4_client.h b/src/bin/dhcp4/tests/dhcp4_client.h index e4e939cbbb..a7265a43ad 100644 --- a/src/bin/dhcp4/tests/dhcp4_client.h +++ b/src/bin/dhcp4/tests/dhcp4_client.h @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2019 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2014-2020 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -337,6 +337,14 @@ public: iface_name_ = iface_name; } + /// @brief Sets the interface over which the messages should be sent. + /// + /// @param iface_index Index of the interface over which the + /// messages should be sent. + void setIfaceIndex(uint32_t iface_index) { + iface_index_ = iface_index; + } + /// @brief Sets client state. /// /// Depending on the current state the client's behavior is different @@ -483,9 +491,12 @@ private: /// @brief Current client identifier. ClientIdPtr clientid_; - /// @brief Interface to be used to send the messages. + /// @brief Interface to be used to send the messages (name). std::string iface_name_; + /// @brief Interface to be used to send the messages (index). + uint32_t iface_index_; + /// @brief Relay address to use. asiolink::IOAddress relay_addr_; diff --git a/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc b/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc index 1e4b9d6d4c..9df9fef14f 100644 --- a/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc +++ b/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc @@ -159,7 +159,7 @@ TEST_F(Dhcpv4SrvTest, adjustIfaceDataRelay) { req->setLocalAddr(IOAddress("192.0.2.5")); req->setLocalPort(1001); req->setIface("eth1"); - req->setIndex(1); + req->setIndex(ETH1_INDEX); // Set remote port (it will be used in the next test). req->setRemotePort(1234); @@ -188,7 +188,7 @@ TEST_F(Dhcpv4SrvTest, adjustIfaceDataRelay) { // We will send response over the same interface which was used to receive // query. EXPECT_EQ("eth1", resp->getIface()); - EXPECT_EQ(1, resp->getIndex()); + EXPECT_EQ(ETH1_INDEX, resp->getIndex()); // Let's do another test and set other fields: ciaddr and // flags. By doing it, we want to make sure that the relay @@ -239,7 +239,7 @@ TEST_F(Dhcpv4SrvTest, adjustIfaceDataRelayPort) { req->setLocalAddr(IOAddress("192.0.2.5")); req->setLocalPort(1001); req->setIface("eth1"); - req->setIndex(1); + req->setIndex(ETH1_INDEX); // Set remote port. req->setRemotePort(1234); @@ -283,7 +283,7 @@ TEST_F(Dhcpv4SrvTest, adjustIfaceDataRelayPort) { // We will send response over the same interface which was used to receive // query. EXPECT_EQ("eth1", resp->getIface()); - EXPECT_EQ(1, resp->getIndex()); + EXPECT_EQ(ETH1_INDEX, resp->getIndex()); } // This test verifies that it is possible to configure the server to use @@ -321,7 +321,7 @@ TEST_F(Dhcpv4SrvTest, adjustIfaceDataUseRouting) { req->setLocalAddr(IOAddress("192.0.2.5")); req->setLocalPort(1001); req->setIface("eth1"); - req->setIndex(1); + req->setIndex(ETH1_INDEX); // Create the exchange using the req. Dhcpv4Exchange ex = createExchange(req); @@ -367,7 +367,7 @@ TEST_F(Dhcpv4SrvTest, adjustIfaceDataUseRouting) { EXPECT_EQ("192.0.2.5", resp->getLocalAddr().toText()); EXPECT_EQ("eth1", resp->getIface()); - EXPECT_EQ(1, resp->getIndex()); + EXPECT_EQ(ETH1_INDEX, resp->getIndex()); } // This test verifies that the destination address of the response @@ -393,7 +393,7 @@ TEST_F(Dhcpv4SrvTest, adjustRemoteAddressRelaySendToSourceTestingModeEnabled) { req->setLocalAddr(IOAddress("192.0.2.5")); req->setLocalPort(1001); req->setIface("eth1"); - req->setIndex(1); + req->setIndex(ETH1_INDEX); // Set remote address and port. req->setRemoteAddr(IOAddress("192.0.2.1")); @@ -451,7 +451,7 @@ TEST_F(Dhcpv4SrvTest, adjustIfaceDataRenew) { req->setLocalPort(DHCP4_SERVER_PORT); // Set the interface. The response should be sent over the same interface. req->setIface("eth1"); - req->setIndex(1); + req->setIndex(ETH1_INDEX); // Create the exchange using the req. Dhcpv4Exchange ex = createExchange(req); @@ -481,8 +481,7 @@ TEST_F(Dhcpv4SrvTest, adjustIfaceDataRenew) { EXPECT_EQ(DHCP4_SERVER_PORT, resp->getLocalPort()); // The interface data should match the data in the query. EXPECT_EQ("eth1", resp->getIface()); - EXPECT_EQ(1, resp->getIndex()); - + EXPECT_EQ(ETH1_INDEX, resp->getIndex()); } // This test verifies that the destination address of the response message @@ -516,7 +515,7 @@ TEST_F(Dhcpv4SrvTest, adjustRemoteAddressRenewSendToSourceTestingModeEnabled) { req->setLocalPort(DHCP4_SERVER_PORT); // Set the interface. The response should be sent over the same interface. req->setIface("eth1"); - req->setIndex(1); + req->setIndex(ETH1_INDEX); // Set remote address. req->setRemoteAddr(IOAddress("192.0.2.1")); @@ -573,7 +572,7 @@ TEST_F(Dhcpv4SrvTest, adjustIfaceDataSelect) { req->setLocalPort(DHCP4_SERVER_PORT); // Set the interface. The response should be sent via the same interface. req->setIface("eth1"); - req->setIndex(1); + req->setIndex(ETH1_INDEX); // Create the exchange using the req. Dhcpv4Exchange ex = createExchange(req); @@ -586,7 +585,7 @@ TEST_F(Dhcpv4SrvTest, adjustIfaceDataSelect) { resp->setHops(req->getHops()); // We want to test the case, when the server (packet filter) doesn't support - // ddirect responses to the client which doesn't have an address yet. In + // direct responses to the client which doesn't have an address yet. In // case, the server should send its response to the broadcast address. // We can control whether the current packet filter returns that its support // direct responses or not. @@ -615,7 +614,7 @@ TEST_F(Dhcpv4SrvTest, adjustIfaceDataSelect) { // The response should be sent via the same interface through which // query has been received. EXPECT_EQ("eth1", resp->getIface()); - EXPECT_EQ(1, resp->getIndex()); + EXPECT_EQ(ETH1_INDEX, resp->getIndex()); // We also want to test the case when the server has capability to // respond directly to the client which is not configured. Server @@ -658,7 +657,7 @@ TEST_F(Dhcpv4SrvTest, adjustRemoteAddressSelectSendToSourceTestingModeEnabled) { req->setLocalPort(DHCP4_SERVER_PORT); // Set the interface. The response should be sent via the same interface. req->setIface("eth1"); - req->setIndex(1); + req->setIndex(ETH1_INDEX); // Set remote address. req->setRemoteAddr(IOAddress("192.0.2.1")); @@ -717,7 +716,7 @@ TEST_F(Dhcpv4SrvTest, adjustIfaceDataBroadcast) { req->setLocalPort(DHCP4_SERVER_PORT); // Set the interface. The response should be sent via the same interface. req->setIface("eth1"); - req->setIndex(1); + req->setIndex(ETH1_INDEX); // Let's set the broadcast flag. req->setFlags(Pkt4::FLAG_BROADCAST_MASK); @@ -749,7 +748,7 @@ TEST_F(Dhcpv4SrvTest, adjustIfaceDataBroadcast) { // The response should be sent via the same interface through which // query has been received. EXPECT_EQ("eth1", resp->getIface()); - EXPECT_EQ(1, resp->getIndex()); + EXPECT_EQ(ETH1_INDEX, resp->getIndex()); } @@ -773,7 +772,7 @@ TEST_F(Dhcpv4SrvTest, adjustRemoteAddressBroadcastSendToSourceTestingModeEnabled req->setLocalPort(DHCP4_SERVER_PORT); // Set the interface. The response should be sent via the same interface. req->setIface("eth1"); - req->setIndex(1); + req->setIndex(ETH1_INDEX); // Set remote address. req->setRemoteAddr(IOAddress("192.0.2.1")); @@ -1186,6 +1185,7 @@ TEST_F(Dhcpv4SrvTest, DiscoverBasic) { OptionPtr clientid = generateClientId(); dis->addOption(clientid); dis->setIface("eth1"); + dis->setIndex(ETH1_INDEX); // Pass it to the server and get an offer Pkt4Ptr offer = srv->processDiscover(dis); @@ -1253,6 +1253,7 @@ TEST_F(Dhcpv4SrvTest, DiscoverValidLifetime) { OptionPtr clientid = generateClientId(); dis->addOption(clientid); dis->setIface("eth1"); + dis->setIndex(ETH1_INDEX); // Add dhcp-lease-time option. if (test.hint) { @@ -1405,6 +1406,7 @@ TEST_F(Dhcpv4SrvTest, DiscoverTimers) { OptionPtr clientid = generateClientId(); dis->addOption(clientid); dis->setIface("eth1"); + dis->setIndex(ETH1_INDEX); // Iterate over the test scenarios. for (auto test = tests.begin(); test != tests.end(); ++test) { @@ -1521,6 +1523,7 @@ TEST_F(Dhcpv4SrvTest, calculateTeeTimers) { OptionPtr clientid = generateClientId(); dis->addOption(clientid); dis->setIface("eth1"); + dis->setIndex(ETH1_INDEX); // Iterate over the test scenarios. for (auto test = tests.begin(); test != tests.end(); ++test) { @@ -1593,6 +1596,7 @@ TEST_F(Dhcpv4SrvTest, DiscoverInvalidHint) { dis->addOption(clientid); dis->setYiaddr(hint); dis->setIface("eth1"); + dis->setIndex(ETH1_INDEX); // Pass it to the server and get an offer Pkt4Ptr offer = srv->processDiscover(dis); @@ -1638,8 +1642,11 @@ TEST_F(Dhcpv4SrvTest, ManyDiscovers) { // Assign interfaces dis1->setIface("eth1"); + dis1->setIndex(ETH1_INDEX); dis2->setIface("eth1"); + dis2->setIndex(ETH1_INDEX); dis3->setIface("eth1"); + dis3->setIndex(ETH1_INDEX); // Different client-id sizes OptionPtr clientid1 = generateClientId(4); // length 4 @@ -1700,6 +1707,7 @@ TEST_F(Dhcpv4SrvTest, discoverEchoClientId) { OptionPtr clientid = generateClientId(); dis->addOption(clientid); dis->setIface("eth1"); + dis->setIndex(ETH1_INDEX); // Pass it to the server and get an offer Pkt4Ptr offer = srv.processDiscover(dis); @@ -1736,6 +1744,7 @@ TEST_F(Dhcpv4SrvTest, RequestNoTimers) { OptionPtr clientid = generateClientId(); req->addOption(clientid); req->setIface("eth1"); + req->setIndex(ETH1_INDEX); // Recreate a subnet but set T1 and T2 to "unspecified". subnet_.reset(new Subnet4(IOAddress("192.0.2.0"), 24, @@ -1775,6 +1784,7 @@ TEST_F(Dhcpv4SrvTest, requestEchoClientId) { OptionPtr clientid = generateClientId(); dis->addOption(clientid); dis->setIface("eth1"); + dis->setIndex(ETH1_INDEX); // Pass it to the server and get ACK Pkt4Ptr ack = srv.processRequest(dis); @@ -1848,6 +1858,7 @@ TEST_F(Dhcpv4SrvTest, RenewBasic) { req->setYiaddr(addr); req->setCiaddr(addr); // client's address req->setIface("eth0"); + req->setIndex(ETH0_INDEX); req->setHWAddr(hwaddr2); req->addOption(clientid); @@ -1940,6 +1951,7 @@ void prepare(struct ctx& c) { c.req->setYiaddr(c.addr); c.req->setCiaddr(c.addr); // client's address c.req->setIface("eth0"); + c.req->setIndex(ETH0_INDEX); c.req->setHWAddr(c.hwaddr); c.req->addOption(c.clientid); @@ -2438,6 +2450,7 @@ TEST_F(Dhcpv4SrvTest, siaddrDefault) { dis->addOption(clientid); dis->setYiaddr(hint); dis->setIface("eth1"); + dis->setIndex(ETH1_INDEX); // Pass it to the server and get an offer Pkt4Ptr offer = srv->processDiscover(dis); @@ -2462,6 +2475,7 @@ TEST_F(Dhcpv4SrvTest, siaddr) { Pkt4Ptr dis = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 1234)); dis->setRemoteAddr(IOAddress("192.0.2.1")); dis->setIface("eth1"); + dis->setIndex(ETH1_INDEX); OptionPtr clientid = generateClientId(); dis->addOption(clientid); @@ -2519,6 +2533,7 @@ TEST_F(Dhcpv4SrvTest, nextServerOverride) { Pkt4Ptr dis = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 1234)); dis->setRemoteAddr(IOAddress("192.0.2.1")); dis->setIface("eth1"); + dis->setIndex(ETH1_INDEX); OptionPtr clientid = generateClientId(); dis->addOption(clientid); @@ -2580,6 +2595,7 @@ TEST_F(Dhcpv4SrvTest, nextServerGlobal) { Pkt4Ptr dis = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 1234)); dis->setRemoteAddr(IOAddress("192.0.2.1")); dis->setIface("eth1"); + dis->setIndex(ETH1_INDEX); OptionPtr clientid = generateClientId(); dis->addOption(clientid); @@ -2601,8 +2617,6 @@ TEST_F(Dhcpv4SrvTest, nextServerGlobal) { EXPECT_EQ(0, std::memcmp(filename_buf, &offer->getFile()[0], Pkt4::MAX_FILE_LEN)); } - - // Checks if client packets are classified properly using match expressions. TEST_F(Dhcpv4SrvTest, matchClassification) { IfaceMgrTestConfig test_config(true); @@ -2645,14 +2659,17 @@ TEST_F(Dhcpv4SrvTest, matchClassification) { query1->setRemoteAddr(IOAddress("192.0.2.1")); query1->addOption(clientid); query1->setIface("eth1"); + query1->setIndex(ETH1_INDEX); Pkt4Ptr query2(new Pkt4(DHCPDISCOVER, 1234)); query2->setRemoteAddr(IOAddress("192.0.2.1")); query2->addOption(clientid); query2->setIface("eth1"); + query2->setIndex(ETH1_INDEX); Pkt4Ptr query3(new Pkt4(DHCPDISCOVER, 1234)); query3->setRemoteAddr(IOAddress("192.0.2.1")); query3->addOption(clientid); query3->setIface("eth1"); + query3->setIndex(ETH1_INDEX); // Create and add a PRL option to the first 2 queries OptionUint8ArrayPtr prl(new OptionUint8Array(Option::V4, @@ -2840,6 +2857,7 @@ TEST_F(Dhcpv4SrvTest, subnetClassPriority) { OptionPtr clientid = generateClientId(); query->addOption(clientid); query->setIface("eth1"); + query->setIndex(ETH1_INDEX); // Create and add a PRL option to the query OptionUint8ArrayPtr prl(new OptionUint8Array(Option::V4, @@ -2913,6 +2931,7 @@ TEST_F(Dhcpv4SrvTest, subnetGlobalPriority) { OptionPtr clientid = generateClientId(); query->addOption(clientid); query->setIface("eth1"); + query->setIndex(ETH1_INDEX); // Create and add a PRL option to the query OptionUint8ArrayPtr prl(new OptionUint8Array(Option::V4, @@ -2985,6 +3004,7 @@ TEST_F(Dhcpv4SrvTest, classGlobalPriority) { OptionPtr clientid = generateClientId(); query->addOption(clientid); query->setIface("eth1"); + query->setIndex(ETH1_INDEX); // Create and add a PRL option to the query OptionUint8ArrayPtr prl(new OptionUint8Array(Option::V4, @@ -3067,6 +3087,7 @@ TEST_F(Dhcpv4SrvTest, classGlobalPersistency) { OptionPtr clientid = generateClientId(); query->addOption(clientid); query->setIface("eth1"); + query->setIndex(ETH1_INDEX); // Do not add a PRL OptionPtr prl = query->getOption(DHO_DHCP_PARAMETER_REQUEST_LIST); @@ -3131,6 +3152,7 @@ TEST_F(Dhcpv4SrvTest, clientClassify) { dis->setRemoteAddr(IOAddress("192.0.2.1")); dis->setCiaddr(IOAddress("192.0.2.1")); dis->setIface("eth0"); + dis->setIndex(ETH0_INDEX); OptionPtr clientid = generateClientId(); dis->addOption(clientid); @@ -3199,6 +3221,7 @@ TEST_F(Dhcpv4SrvTest, clientPoolClassify) { dis->setRemoteAddr(IOAddress("192.0.2.1")); dis->setCiaddr(IOAddress("192.0.2.1")); dis->setIface("eth0"); + dis->setIndex(ETH0_INDEX); OptionPtr clientid = generateClientId(); dis->addOption(clientid); @@ -3266,6 +3289,7 @@ TEST_F(Dhcpv4SrvTest, clientPoolClassifyKnown) { dis->setRemoteAddr(IOAddress("192.0.2.1")); dis->setCiaddr(IOAddress("192.0.2.1")); dis->setIface("eth0"); + dis->setIndex(ETH0_INDEX); OptionPtr clientid = generateClientId(); dis->addOption(clientid); @@ -3321,6 +3345,7 @@ TEST_F(Dhcpv4SrvTest, clientPoolClassifyUnknown) { dis->setRemoteAddr(IOAddress("192.0.2.1")); dis->setCiaddr(IOAddress("192.0.2.1")); dis->setIface("eth0"); + dis->setIndex(ETH0_INDEX); OptionPtr clientid = generateClientId(); dis->addOption(clientid); @@ -3384,6 +3409,7 @@ TEST_F(Dhcpv4SrvTest, privateOption) { OptionPtr clientid = generateClientId(); query->addOption(clientid); query->setIface("eth1"); + query->setIndex(ETH1_INDEX); // Create and add a private option with code 234 OptionBuffer buf; @@ -3453,6 +3479,7 @@ TEST_F(Dhcpv4SrvTest, prlPersistency) { OptionPtr clientid = generateClientId(); query->addOption(clientid); query->setIface("eth1"); + query->setIndex(ETH1_INDEX); // Create and add a PRL option for another option OptionUint8ArrayPtr prl(new OptionUint8Array(Option::V4, @@ -3537,6 +3564,7 @@ TEST_F(Dhcpv4SrvTest, relayOverride) { Pkt4Ptr dis = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 1234)); dis->setRemoteAddr(IOAddress("192.0.2.1")); dis->setIface("eth0"); + dis->setIndex(ETH0_INDEX); dis->setHops(1); OptionPtr clientid = generateClientId(); dis->addOption(clientid); @@ -3622,6 +3650,7 @@ TEST_F(Dhcpv4SrvTest, relayOverrideAndClientClass) { Pkt4Ptr dis = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 1234)); dis->setRemoteAddr(IOAddress("192.0.2.1")); dis->setIface("eth0"); + dis->setIndex(ETH0_INDEX); dis->setHops(1); dis->setGiaddr(IOAddress("192.0.5.1")); OptionPtr clientid = generateClientId(); @@ -3685,6 +3714,7 @@ TEST_F(Dhcpv4SrvTest, relayLinkSelect) { Pkt4Ptr dis = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 1234)); dis->setRemoteAddr(IOAddress("192.0.2.1")); dis->setIface("eth0"); + dis->setIndex(ETH0_INDEX); dis->setHops(1); OptionPtr clientid = generateClientId(); dis->addOption(clientid); @@ -3803,6 +3833,7 @@ TEST_F(Dhcpv4SrvTest, subnetSelect) { Pkt4Ptr dis = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 1234)); dis->setRemoteAddr(IOAddress("192.0.2.1")); dis->setIface("eth0"); + dis->setIndex(ETH0_INDEX); dis->setHops(1); OptionPtr clientid = generateClientId(); dis->addOption(clientid); @@ -3867,6 +3898,7 @@ TEST_F(Dhcpv4SrvTest, acceptDirectRequest) { pkt->setRemoteAddr(IOAddress("0.0.0.0")); pkt->setLocalAddr(IOAddress("192.0.2.3")); pkt->setIface("eth1"); + pkt->setIndex(ETH1_INDEX); EXPECT_TRUE(srv.accept(pkt)); // Let's set hops and check that the message is still accepted as @@ -3892,6 +3924,7 @@ TEST_F(Dhcpv4SrvTest, acceptDirectRequest) { // For eth0, there is no subnet configured. Such message is expected // to be silently dropped. pkt->setIface("eth0"); + pkt->setIndex(ETH0_INDEX); EXPECT_FALSE(srv.accept(pkt)); // But, if the message is unicast it should be accepted, even though diff --git a/src/bin/dhcp4/tests/dhcp4_test_utils.cc b/src/bin/dhcp4/tests/dhcp4_test_utils.cc index 74476abf53..717fba0523 100644 --- a/src/bin/dhcp4/tests/dhcp4_test_utils.cc +++ b/src/bin/dhcp4/tests/dhcp4_test_utils.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2019 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2013-2020 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -483,9 +483,8 @@ Dhcpv4SrvTest::testDiscoverRequest(const uint8_t msg_type) { boost::shared_ptr<Pkt4> rsp; // Set the name of the interface on which packet is received. req->setIface("eth0"); - // Set the interface index. It is just a dummy value and will - // not be interpreted. - req->setIndex(17); + // Set the interface index. + req->setIndex(ETH0_INDEX); // Set the target HW address. This value is normally used to // construct the data link layer header. req->setRemoteHWAddr(1, 6, dst_mac); @@ -513,6 +512,7 @@ Dhcpv4SrvTest::testDiscoverRequest(const uint8_t msg_type) { ASSERT_TRUE(createPacketFromBuffer(req, received)); // Set interface. It is required for the server to generate server id. received->setIface("eth0"); + received->setIndex(ETH0_INDEX); if (msg_type == DHCPDISCOVER) { ASSERT_NO_THROW( rsp = srv->processDiscover(received); @@ -548,6 +548,7 @@ Dhcpv4SrvTest::testDiscoverRequest(const uint8_t msg_type) { // Set interface. It is required for the server to generate server id. received->setIface("eth0"); + received->setIndex(ETH0_INDEX); if (msg_type == DHCPDISCOVER) { ASSERT_NO_THROW(rsp = srv->processDiscover(received)); @@ -584,6 +585,7 @@ Dhcpv4SrvTest::testDiscoverRequest(const uint8_t msg_type) { // Set interface. It is required for the server to generate server id. received->setIface("eth0"); + received->setIndex(ETH0_INDEX); if (msg_type == DHCPDISCOVER) { ASSERT_NO_THROW(rsp = srv->processDiscover(received)); diff --git a/src/bin/dhcp4/tests/dhcp4to6_ipc_unittest.cc b/src/bin/dhcp4/tests/dhcp4to6_ipc_unittest.cc index 13101d61f2..2a47d71821 100644 --- a/src/bin/dhcp4/tests/dhcp4to6_ipc_unittest.cc +++ b/src/bin/dhcp4/tests/dhcp4to6_ipc_unittest.cc @@ -214,6 +214,7 @@ TEST_F(Dhcp4to6IpcTest, receive) { Pkt6Ptr pkt(new Pkt6(DHCPV6_DHCPV4_QUERY, 1234)); pkt->addOption(createDHCPv4MsgOption()); pkt->setIface("eth0"); + pkt->setIndex(ETH0_INDEX); pkt->setRemoteAddr(IOAddress("2001:db8:1::123")); ASSERT_NO_THROW(pkt->pack()); @@ -235,6 +236,7 @@ TEST_F(Dhcp4to6IpcTest, receive) { Pkt6Ptr pkt6_received = pkt_received->getPkt6(); ASSERT_TRUE(pkt6_received); EXPECT_EQ("eth0", pkt6_received->getIface()); + EXPECT_EQ(ETH0_INDEX, pkt6_received->getIndex()); EXPECT_EQ("2001:db8:1::123", pkt6_received->getRemoteAddr().toText()); // Both DHCP4o6 and encapsulated DHCPv6 packet should have the @@ -261,6 +263,7 @@ TEST_F(Dhcp4to6IpcTest, receiveMultipleQueries) { pkt->addOption(createDHCPv4MsgOption()); pkt->addOption(createDHCPv4MsgOption()); pkt->setIface("eth0"); + pkt->setIndex(ETH0_INDEX); pkt->setRemoteAddr(IOAddress("2001:db8:1::123")); ASSERT_NO_THROW(pkt->pack()); @@ -290,6 +293,7 @@ TEST_F(Dhcp4to6IpcTest, receiveNoQueries) { // Create message to be sent over IPC without DHCPv4 query option. Pkt6Ptr pkt(new Pkt6(DHCPV6_DHCPV4_QUERY, 1234)); pkt->setIface("eth0"); + pkt->setIndex(ETH0_INDEX); pkt->setRemoteAddr(IOAddress("2001:db8:1::123")); ASSERT_NO_THROW(pkt->pack()); @@ -341,6 +345,7 @@ TEST_F(Dhcp4to6IpcTest, process) { Pkt6Ptr pkt(new Pkt6(DHCPV6_DHCPV4_QUERY, 1234)); pkt->addOption(opt_msg); pkt->setIface("eth0"); + pkt->setIndex(ETH0_INDEX); pkt->setRemoteAddr(IOAddress("2001:db8:1::123")); ASSERT_NO_THROW(pkt->pack()); @@ -360,6 +365,7 @@ TEST_F(Dhcp4to6IpcTest, process) { Pkt6Ptr pkt6_received = pkt_received->getPkt6(); ASSERT_TRUE(pkt6_received); EXPECT_EQ("eth0", pkt6_received->getIface()); + EXPECT_EQ(ETH0_INDEX, pkt6_received->getIndex()); EXPECT_EQ("2001:db8:1::123", pkt6_received->getRemoteAddr().toText()); // Make sure that the message has been processed. @@ -373,6 +379,7 @@ TEST_F(Dhcp4to6IpcTest, process) { ASSERT_TRUE(pkt6_sent); EXPECT_EQ(DHCPV6_DHCPV4_RESPONSE, pkt6_sent->getType()); EXPECT_EQ("eth0", pkt6_sent->getIface()); + EXPECT_EQ(ETH0_INDEX, pkt6_sent->getIndex()); EXPECT_EQ("2001:db8:1::123", pkt6_sent->getRemoteAddr().toText()); // Both DHCP4o6 and encapsulated DHCPv6 packet should have the diff --git a/src/bin/dhcp4/tests/direct_client_unittest.cc b/src/bin/dhcp4/tests/direct_client_unittest.cc index 5c1c756873..dedb3b9386 100644 --- a/src/bin/dhcp4/tests/direct_client_unittest.cc +++ b/src/bin/dhcp4/tests/direct_client_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2014-2020 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -77,10 +77,13 @@ public: /// @param msg_type Type of the message to be created. /// @param iface Name of the interface on which the message has been /// "received" by the server. + /// @param ifindex Index of the interface on which the message has been + /// "received" by the server. /// /// @return Generated message. Pkt4Ptr createClientMessage(const uint16_t msg_type, - const std::string& iface); + const std::string& iface, + const uint32_t ifindex); /// @brief Creates simple message from a client. /// @@ -93,9 +96,13 @@ public: /// not be NULL. /// @param iface Name of the interface on which the message has been /// "received" by the server. + /// @param ifindex Index of the interface on which the message has been + /// "received" by the server. /// /// @return Configured and parsed message. - Pkt4Ptr createClientMessage(const Pkt4Ptr &msg, const std::string& iface); + Pkt4Ptr createClientMessage(const Pkt4Ptr &msg, + const std::string& iface, + const uint32_t ifindex); /// @brief classes the client belongs to /// @@ -159,20 +166,23 @@ DirectClientTest::configureTwoSubnets(const std::string& prefix1, } Pkt4Ptr -DirectClientTest:: createClientMessage(const uint16_t msg_type, - const std::string& iface) { +DirectClientTest::createClientMessage(const uint16_t msg_type, + const std::string& iface, + const uint32_t ifindex) { // Create a source packet. Pkt4Ptr msg = Pkt4Ptr(new Pkt4(msg_type, 1234)); - return (createClientMessage(msg, iface)); + return (createClientMessage(msg, iface, ifindex)); } Pkt4Ptr DirectClientTest::createClientMessage(const Pkt4Ptr& msg, - const std::string& iface) { + const std::string& iface, + const uint32_t ifindex) { msg->setRemoteAddr(IOAddress("255.255.255.255")); msg->addOption(generateClientId()); msg->setIface(iface); + msg->setIndex(ifindex); // Create copy of this packet by parsing its wire data. Make sure that the // local and remote address are set like it was a message sent from the @@ -180,6 +190,7 @@ DirectClientTest::createClientMessage(const Pkt4Ptr& msg, Pkt4Ptr received; createPacketFromBuffer(msg, received); received->setIface(iface); + received->setIndex(ifindex); received->setLocalAddr(IOAddress("255.255.255.255")); received->setRemoteAddr(IOAddress("0.0.0.0")); @@ -204,10 +215,10 @@ TEST_F(DirectClientTest, twoSubnets) { // address on eth1 belongs to the first subnet. ASSERT_NO_FATAL_FAILURE(configureTwoSubnets("192.0.2.0", "10.0.0.0")); // Create Discover and simulate reception of this message through eth0. - Pkt4Ptr dis = createClientMessage(DHCPDISCOVER, "eth0"); + Pkt4Ptr dis = createClientMessage(DHCPDISCOVER, "eth0", ETH0_INDEX); srv_.fakeReceive(dis); // Create Request and simulate reception of this message through eth1. - Pkt4Ptr req = createClientMessage(DHCPREQUEST, "eth1"); + Pkt4Ptr req = createClientMessage(DHCPREQUEST, "eth1", ETH1_INDEX); srv_.fakeReceive(req); // Process clients' messages. @@ -259,10 +270,10 @@ TEST_F(DirectClientTest, oneSubnet) { // connected client is received through interface eth0. ASSERT_NO_FATAL_FAILURE(configureSubnet("10.0.0.0")); // Create Discover and simulate reception of this message through eth0. - Pkt4Ptr dis = createClientMessage(DHCPDISCOVER, "eth0"); + Pkt4Ptr dis = createClientMessage(DHCPDISCOVER, "eth0", ETH0_INDEX); srv_.fakeReceive(dis); // Create Request and simulate reception of this message through eth1. - Pkt4Ptr req = createClientMessage(DHCPDISCOVER, "eth1"); + Pkt4Ptr req = createClientMessage(DHCPDISCOVER, "eth1", ETH1_INDEX); srv_.fakeReceive(req); // Process clients' messages. @@ -347,12 +358,14 @@ TEST_F(DirectClientTest, rebind) { // Broadcast Request through an interface for which there is no subnet // configured. This message should be discarded by the server. client.setIfaceName("eth1"); + client.setIfaceIndex(ETH1_INDEX); ASSERT_NO_THROW(client.doRequest()); EXPECT_FALSE(client.getContext().response_); // Send Rebind over the correct interface, and make sure we have obtained // the same address. client.setIfaceName("eth0"); + client.setIfaceIndex(ETH0_INDEX); ASSERT_NO_THROW(client.doRequest()); ASSERT_TRUE(client.getContext().response_); EXPECT_EQ(DHCPACK, static_cast<int>(client.getContext().response_->getType())); diff --git a/src/bin/dhcp4/tests/dora_unittest.cc b/src/bin/dhcp4/tests/dora_unittest.cc index e97995abf6..3a18f62f5d 100644 --- a/src/bin/dhcp4/tests/dora_unittest.cc +++ b/src/bin/dhcp4/tests/dora_unittest.cc @@ -2131,6 +2131,7 @@ TEST_F(DORATest, customServerIdentifier) { // Repeat the test for different subnet. Dhcp4Client client2(client1.getServer(), Dhcp4Client::SELECTING); client2.setIfaceName("eth1"); + client2.setIfaceIndex(ETH1_INDEX); ASSERT_NO_THROW(client2.doDORA()); ASSERT_TRUE(client2.getContext().response_); diff --git a/src/bin/dhcp4/tests/fqdn_unittest.cc b/src/bin/dhcp4/tests/fqdn_unittest.cc index 73b4064e57..2853ec213c 100644 --- a/src/bin/dhcp4/tests/fqdn_unittest.cc +++ b/src/bin/dhcp4/tests/fqdn_unittest.cc @@ -434,6 +434,7 @@ public: Pkt4Ptr pkt = Pkt4Ptr(new Pkt4(msg_type, 1234)); pkt->setRemoteAddr(IOAddress("192.0.2.3")); pkt->setIface("eth1"); + pkt->setIndex(ETH1_INDEX); // For DISCOVER we don't include server id, because client broadcasts // the message to all servers. if (msg_type != DHCPDISCOVER) { @@ -1133,6 +1134,7 @@ TEST_F(NameDhcpv4SrvTest, processRequestTopLevelHostname) { // Set interface for the incoming packet. The server requires it to // generate client id. req->setIface("eth1"); + req->setIndex(ETH1_INDEX); Pkt4Ptr reply; ASSERT_NO_THROW(reply = srv_->processRequest(req)); @@ -1220,7 +1222,7 @@ TEST_F(NameDhcpv4SrvTest, processTwoRequestsHostname) { // Set interface for the incoming packet. The server requires it to // generate client id. req1->setIface("eth1"); - + req1->setIndex(ETH1_INDEX); Pkt4Ptr reply; ASSERT_NO_THROW(reply = srv_->processRequest(req1)); @@ -1243,6 +1245,7 @@ TEST_F(NameDhcpv4SrvTest, processTwoRequestsHostname) { // Set interface for the incoming packet. The server requires it to // generate client id. req2->setIface("eth1"); + req2->setIndex(ETH1_INDEX); ASSERT_NO_THROW(reply = srv_->processRequest(req2)); @@ -1317,6 +1320,7 @@ TEST_F(NameDhcpv4SrvTest, processRequestRenewHostname) { // Set interface for the incoming packet. The server requires it to // generate client id. req1->setIface("eth1"); + req1->setIndex(ETH1_INDEX); Pkt4Ptr reply; ASSERT_NO_THROW(reply = srv_->processRequest(req1)); @@ -1338,6 +1342,7 @@ TEST_F(NameDhcpv4SrvTest, processRequestRenewHostname) { // Set interface for the incoming packet. The server requires it to // generate client id. req2->setIface("eth1"); + req2->setIndex(ETH1_INDEX); ASSERT_NO_THROW(reply = srv_->processRequest(req2)); @@ -2192,6 +2197,7 @@ TEST_F(NameDhcpv4SrvTest, sanitizeFqdnGlobal) { TEST_F(NameDhcpv4SrvTest, ddnsScopeTest) { Dhcp4Client client1(Dhcp4Client::SELECTING); client1.setIfaceName("eth0"); + client1.setIfaceIndex(ETH0_INDEX); // Load a configuration with D2 enabled ASSERT_NO_FATAL_FAILURE(configure(CONFIGS[8], *client1.getServer())); @@ -2221,6 +2227,7 @@ TEST_F(NameDhcpv4SrvTest, ddnsScopeTest) { // Now let's try with a client on subnet 2. Dhcp4Client client2(Dhcp4Client::SELECTING); client2.setIfaceName("eth1"); + client2.setIfaceIndex(ETH1_INDEX); // Include the Client FQDN option. ASSERT_NO_THROW(client2.includeFQDN((Option4ClientFqdn::FLAG_S diff --git a/src/bin/dhcp4/tests/hooks_unittest.cc b/src/bin/dhcp4/tests/hooks_unittest.cc index a343973fe2..06cc6d333d 100644 --- a/src/bin/dhcp4/tests/hooks_unittest.cc +++ b/src/bin/dhcp4/tests/hooks_unittest.cc @@ -217,6 +217,7 @@ public: // and the fake eth0 interface has IPv4 address matching the subnet // currently configured for this test. dis->setIface("eth1"); + dis->setIndex(ETH1_INDEX); return (dis); } @@ -1594,6 +1595,7 @@ TEST_F(HooksDhcpv4SrvTest, subnet4SelectSimple) { Pkt4Ptr sol = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 1234)); sol->setRemoteAddr(IOAddress("192.0.2.1")); sol->setIface("eth1"); + sol->setIndex(ETH1_INDEX); OptionPtr clientid = generateClientId(); sol->addOption(clientid); @@ -1675,6 +1677,7 @@ TEST_F(HooksDhcpv4SrvTest, subnet4SelectChange) { Pkt4Ptr sol = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 1234)); sol->setRemoteAddr(IOAddress("192.0.2.1")); sol->setIface("eth0"); + sol->setIndex(ETH0_INDEX); OptionPtr clientid = generateClientId(); sol->addOption(clientid); @@ -1714,6 +1717,7 @@ TEST_F(HooksDhcpv4SrvTest, leases4CommittedDiscover) { Dhcp4Client client(Dhcp4Client::SELECTING); client.setIfaceName("eth1"); + client.setIfaceIndex(ETH1_INDEX); ASSERT_NO_THROW(client.doDiscover()); // Make sure that we received a response @@ -1789,6 +1793,7 @@ TEST_F(HooksDhcpv4SrvTest, lease4RenewSimple) { req->setYiaddr(addr); req->setCiaddr(addr); // client's address req->setIface("eth0"); + req->setIndex(ETH0_INDEX); req->setHWAddr(hwaddr2); req->addOption(clientid); @@ -1891,6 +1896,7 @@ TEST_F(HooksDhcpv4SrvTest, lease4RenewSkip) { req->setYiaddr(addr); req->setCiaddr(addr); // client's address req->setIface("eth0"); + req->setIndex(ETH0_INDEX); req->setHWAddr(hwaddr2); req->addOption(clientid); @@ -1929,6 +1935,7 @@ TEST_F(HooksDhcpv4SrvTest, leases4CommittedRequest) { Dhcp4Client client(Dhcp4Client::SELECTING); client.setIfaceName("eth1"); + client.setIfaceIndex(ETH1_INDEX); ASSERT_NO_THROW(client.doDORA(boost::shared_ptr<IOAddress>(new IOAddress("192.0.2.100")))); // Make sure that we received a response @@ -2048,6 +2055,7 @@ TEST_F(HooksDhcpv4SrvTest, leases4CommittedParkRequests) { // Create first client and perform DORA. Dhcp4Client client1(Dhcp4Client::SELECTING); client1.setIfaceName("eth1"); + client1.setIfaceIndex(ETH1_INDEX); ASSERT_NO_THROW(client1.doDORA(boost::shared_ptr<IOAddress>(new IOAddress("192.0.2.100")))); // We should be offered an address but the DHCPACK should not arrive @@ -2086,6 +2094,7 @@ TEST_F(HooksDhcpv4SrvTest, leases4CommittedParkRequests) { // server while the previous packet is parked. Dhcp4Client client2(client1.getServer(), Dhcp4Client::SELECTING); client2.setIfaceName("eth1"); + client2.setIfaceIndex(ETH1_INDEX); ASSERT_NO_THROW(client2.doDORA(boost::shared_ptr<IOAddress>(new IOAddress("192.0.2.101")))); // The DHCPOFFER should have been returned but not DHCPACK, as this @@ -2283,6 +2292,7 @@ TEST_F(HooksDhcpv4SrvTest, leases4CommittedRelease) { Dhcp4Client client(Dhcp4Client::SELECTING); client.setIfaceName("eth1"); + client.setIfaceIndex(ETH1_INDEX); ASSERT_NO_THROW(client.doDORA(boost::shared_ptr<IOAddress>(new IOAddress("192.0.2.100")))); // Make sure that we received a response diff --git a/src/bin/dhcp4/tests/host_unittest.cc b/src/bin/dhcp4/tests/host_unittest.cc index 65cee16bfe..85958b5de9 100644 --- a/src/bin/dhcp4/tests/host_unittest.cc +++ b/src/bin/dhcp4/tests/host_unittest.cc @@ -355,7 +355,7 @@ public: // Perform 4-way exchange with the server but to not request any // specific address in the DHCPDISCOVER message. - boost::shared_ptr<IOAddress> hint; + boost::shared_ptr<IOAddress> hint; if (!requested_addr.empty()) { hint = boost::make_shared<IOAddress>(requested_addr); } @@ -402,6 +402,7 @@ public: // client class. client_resrv.setHWAddress("aa:bb:cc:dd:ee:fe"); client_resrv.setIfaceName("eth0"); + client_resrv.setIfaceIndex(ETH0_INDEX); ASSERT_NO_FATAL_FAILURE(configure(CONFIGS[config_idx], *client_resrv.getServer())); @@ -421,6 +422,7 @@ public: Dhcp4Client client_no_resrv(client_resrv.getServer(), Dhcp4Client::SELECTING); client_no_resrv.setHWAddress("aa:bb:cc:dd:ee:ff"); client_no_resrv.setIfaceName("eth0"); + client_no_resrv.setIfaceIndex(ETH0_INDEX); // Let's use the address of 10.0.0.10 as a hint to make sure that the // server refuses it in favor of the 192.0.3.10. @@ -533,6 +535,7 @@ TEST_F(HostTest, globalOverSubnet) { // Change to subnet 20 client.setIfaceName("eth1"); + client.setIfaceIndex(ETH1_INDEX); // Subnet 20 usses global HR mode, so the global // reservation should be used, rather than the subnet one. diff --git a/src/bin/dhcp4/tests/shared_network_unittest.cc b/src/bin/dhcp4/tests/shared_network_unittest.cc index 5cf868c8fb..970f9a772d 100644 --- a/src/bin/dhcp4/tests/shared_network_unittest.cc +++ b/src/bin/dhcp4/tests/shared_network_unittest.cc @@ -1223,6 +1223,7 @@ public: // Create client and set MAC address to the one that has a reservation. Dhcp4Client client(Dhcp4Client::SELECTING); client.setIfaceName("eth1"); + client.setIfaceIndex(ETH1_INDEX); client.setHWAddress("aa:bb:cc:dd:ee:ff"); // Request domain-name-servers. client.requestOptions(DHO_DOMAIN_NAME_SERVERS); @@ -1366,6 +1367,7 @@ TEST_F(Dhcpv4SharedNetworkTest, poolInSharedNetworkShortage) { // Create client #1 Dhcp4Client client1(Dhcp4Client::SELECTING); client1.setIfaceName("eth1"); + client1.setIfaceIndex(ETH1_INDEX); // Configure the server with one shared network including two subnets and // one subnet outside of the shared network. @@ -1381,6 +1383,7 @@ TEST_F(Dhcpv4SharedNetworkTest, poolInSharedNetworkShortage) { // an address from the second subnet. Dhcp4Client client2(client1.getServer(), Dhcp4Client::SELECTING); client2.setIfaceName("eth1"); + client2.setIfaceIndex(ETH1_INDEX); testAssigned([this, &client2]() { doDORA(client2, "10.0.0.16"); }); @@ -1389,6 +1392,7 @@ TEST_F(Dhcpv4SharedNetworkTest, poolInSharedNetworkShortage) { // the server has no more addresses to assign. Dhcp4Client client3(client1.getServer(), Dhcp4Client::SELECTING); client3.setIfaceName("eth1"); + client3.setIfaceIndex(ETH1_INDEX); testAssigned([&client3]() { ASSERT_NO_THROW(client3.doDiscover()); Pkt4Ptr resp3 = client3.getContext().response_; @@ -1397,6 +1401,7 @@ TEST_F(Dhcpv4SharedNetworkTest, poolInSharedNetworkShortage) { // Client #3 should be assigned an address if subnet 3 is selected for this client. client3.setIfaceName("eth0"); + client3.setIfaceIndex(ETH0_INDEX); testAssigned([this, &client3]() { doDORA(client3, "192.0.2.65"); }); @@ -1419,6 +1424,7 @@ TEST_F(Dhcpv4SharedNetworkTest, returningClientStartsOver) { // Create client. Dhcp4Client client(Dhcp4Client::SELECTING); client.setIfaceName("eth1"); + client.setIfaceIndex(ETH1_INDEX); client.includeClientId("01:02:03:04"); // Configure the server with one shared network including two subnets and @@ -1506,6 +1512,7 @@ TEST_F(Dhcpv4SharedNetworkTest, hintWithinSharedNetwork) { // Create client. Dhcp4Client client(Dhcp4Client::SELECTING); client.setIfaceName("eth1"); + client.setIfaceIndex(ETH1_INDEX); // Configure the server with one shared network including two subnets and // one subnet outside of the shared network. @@ -1576,6 +1583,7 @@ TEST_F(Dhcpv4SharedNetworkTest, subnetInSharedNetworkSelectedByClass) { Dhcp4Client client2(client1.getServer(), Dhcp4Client::SELECTING); client2.useRelay(true, IOAddress("192.3.5.6")); client2.setIfaceName("eth1"); + client2.setIfaceIndex(ETH1_INDEX); testAssigned([this, &client2] { doDORA(client2, "10.0.0.16"); }); @@ -1717,6 +1725,7 @@ TEST_F(Dhcpv4SharedNetworkTest, optionsDerivation) { // Client #1. Dhcp4Client client1(Dhcp4Client::SELECTING); client1.setIfaceName("eth1"); + client1.setIfaceIndex(ETH1_INDEX); client1.requestOptions(DHO_LOG_SERVERS, DHO_COOKIE_SERVERS, DHO_DOMAIN_NAME_SERVERS); configure(NETWORKS_CONFIG[7], *client1.getServer()); @@ -1746,6 +1755,7 @@ TEST_F(Dhcpv4SharedNetworkTest, optionsDerivation) { // Client #2. Dhcp4Client client2(Dhcp4Client::SELECTING); client2.setIfaceName("eth1"); + client2.setIfaceIndex(ETH1_INDEX); client2.requestOptions(DHO_LOG_SERVERS, DHO_COOKIE_SERVERS, DHO_DOMAIN_NAME_SERVERS); // Request an address from the second subnet within the shared network. @@ -1768,6 +1778,7 @@ TEST_F(Dhcpv4SharedNetworkTest, optionsDerivation) { // Client #3. Dhcp4Client client3(Dhcp4Client::SELECTING); client3.setIfaceName("eth0"); + client3.setIfaceIndex(ETH0_INDEX); client3.requestOptions(DHO_LOG_SERVERS, DHO_COOKIE_SERVERS, DHO_DOMAIN_NAME_SERVERS); // Client 3 should get an address from the subnet defined outside of the shared network. @@ -1792,6 +1803,7 @@ TEST_F(Dhcpv4SharedNetworkTest, initReboot) { // Create client #1. Dhcp4Client client1(Dhcp4Client::SELECTING); client1.setIfaceName("eth1"); + client1.setIfaceIndex(ETH1_INDEX); configure(NETWORKS_CONFIG[0], *client1.getServer()); @@ -1814,6 +1826,7 @@ TEST_F(Dhcpv4SharedNetworkTest, initReboot) { // Create client #2. Dhcp4Client client2(client1.getServer(), Dhcp4Client::SELECTING); client2.setIfaceName("eth1"); + client2.setIfaceIndex(ETH1_INDEX); // Let's make sure that the behavior is the same for the other subnet within the // same shared network. @@ -1837,6 +1850,7 @@ TEST_F(Dhcpv4SharedNetworkTest, variousFieldsInReservation) { // Create client. Dhcp4Client client(Dhcp4Client::SELECTING); client.setIfaceName("eth1"); + client.setIfaceIndex(ETH1_INDEX); client.setHWAddress("11:22:33:44:55:66"); // Include hostname to force the server to return hostname to @@ -1888,6 +1902,7 @@ TEST_F(Dhcpv4SharedNetworkTest, sharedNetworkSelectionByInterface) { // this client. Dhcp4Client client1(Dhcp4Client::SELECTING); client1.setIfaceName("eth1"); + client1.setIfaceIndex(ETH1_INDEX); // Create server configuration with two shared networks selected // by the local interface: eth1 and eth0. @@ -1907,6 +1922,7 @@ TEST_F(Dhcpv4SharedNetworkTest, sharedNetworkSelectionByInterface) { // Create client #2 which requests are received on eth0. Dhcp4Client client2(client1.getServer(), Dhcp4Client::SELECTING); client2.setIfaceName("eth0"); + client2.setIfaceIndex(ETH0_INDEX); // Perform 4-way exchange. testAssigned([&client2] { @@ -1963,6 +1979,7 @@ TEST_F(Dhcpv4SharedNetworkTest, matchClientId) { Dhcp4Client client(Dhcp4Client::SELECTING); client.includeClientId("01:02:03:04"); client.setIfaceName("eth1"); + client.setIfaceIndex(ETH1_INDEX); // Create server configuration with match-client-id value initially // set to true. The client should be allocated a lease and the @@ -2003,6 +2020,7 @@ TEST_F(Dhcpv4SharedNetworkTest, sharedNetworkSelectedByClass) { // Create client #1. Dhcp4Client client1(Dhcp4Client::SELECTING); client1.setIfaceName("eth1"); + client1.setIfaceIndex(ETH1_INDEX); // Add option93 which would cause the client1 to be classified as "b-devices". OptionPtr option93(new OptionUint16(Option::V4, 93, 0x0002)); @@ -2026,6 +2044,7 @@ TEST_F(Dhcpv4SharedNetworkTest, sharedNetworkSelectedByClass) { // Create another client which will belong to a different class. Dhcp4Client client2(client1.getServer(), Dhcp4Client::SELECTING); client2.setIfaceName("eth1"); + client2.setIfaceIndex(ETH1_INDEX); // Add option93 which would cause the client1 to be classified as "a-devices". option93.reset(new OptionUint16(Option::V4, 93, 0x0001)); @@ -2043,6 +2062,7 @@ TEST_F(Dhcpv4SharedNetworkTest, sharedNetworkSelectedByClass) { TEST_F(Dhcpv4SharedNetworkTest, customServerIdentifier) { Dhcp4Client client1(Dhcp4Client::SELECTING); client1.setIfaceName("eth1"); + client1.setIfaceIndex(ETH1_INDEX); // Configure DHCP server. ASSERT_NO_THROW(configure(NETWORKS_CONFIG[15], *client1.getServer())); @@ -2063,6 +2083,7 @@ TEST_F(Dhcpv4SharedNetworkTest, customServerIdentifier) { // Create another client using different interface. Dhcp4Client client2(client1.getServer(), Dhcp4Client::SELECTING); client2.setIfaceName("eth0"); + client2.setIfaceIndex(ETH0_INDEX); testAssigned([&client2] { ASSERT_NO_THROW(client2.doDORA()); @@ -2084,6 +2105,7 @@ TEST_F(Dhcpv4SharedNetworkTest, poolInSharedNetworkSelectedByClass) { // Create client #1 Dhcp4Client client1(Dhcp4Client::SELECTING); client1.setIfaceName("eth1"); + client1.setIfaceIndex(ETH1_INDEX); // Configure the server with one shared network including one subnet and // in 2 pools in it. The access to one of the pools is restricted @@ -2114,6 +2136,7 @@ TEST_F(Dhcpv4SharedNetworkTest, poolInSharedNetworkSelectedByClass) { // Client 2 should be assigned an address from the unrestricted pool. Dhcp4Client client2(client1.getServer(), Dhcp4Client::SELECTING); client2.setIfaceName("eth1"); + client2.setIfaceIndex(ETH1_INDEX); testAssigned([this, &client2] { doDORA(client2, "192.0.2.100"); }); @@ -2144,6 +2167,7 @@ TEST_F(Dhcpv4SharedNetworkTest, poolInSubnetSelectedByClass) { // Create client #1 Dhcp4Client client1(Dhcp4Client::SELECTING); client1.setIfaceName("eth1"); + client1.setIfaceIndex(ETH1_INDEX); // Configure the server with one plain subnet including two pools. // The access to one of the pools is restricted by client classification. @@ -2173,6 +2197,7 @@ TEST_F(Dhcpv4SharedNetworkTest, poolInSubnetSelectedByClass) { // Client 2 should be assigned an address from the unrestricted pool. Dhcp4Client client2(client1.getServer(), Dhcp4Client::SELECTING); client2.setIfaceName("eth1"); + client2.setIfaceIndex(ETH1_INDEX); testAssigned([this, &client2] { doDORA(client2, "192.0.2.100"); }); diff --git a/src/bin/dhcp4/tests/vendor_opts_unittest.cc b/src/bin/dhcp4/tests/vendor_opts_unittest.cc index f80cf08b67..10c09e8882 100644 --- a/src/bin/dhcp4/tests/vendor_opts_unittest.cc +++ b/src/bin/dhcp4/tests/vendor_opts_unittest.cc @@ -226,6 +226,7 @@ TEST_F(VendorOptsTest, vendorOptionsORO) { dis->addOption(clientid); // Set interface. It is required by the server to generate server id. dis->setIface("eth0"); + dis->setIndex(ETH0_INDEX); // Pass it to the server and get an advertise Pkt4Ptr offer = srv.processDiscover(dis); @@ -317,6 +318,7 @@ TEST_F(VendorOptsTest, vendorPersistentOptions) { dis->addOption(clientid); // Set interface. It is required by the server to generate server id. dis->setIface("eth0"); + dis->setIndex(ETH0_INDEX); // Let's add a vendor-option (vendor-id=4491). OptionPtr vendor(new OptionVendor(Option::V4, 4491)); @@ -557,6 +559,7 @@ TEST_F(VendorOptsTest, option43LastResort) { OptionPtr clientid = generateClientId(); query->addOption(clientid); query->setIface("eth1"); + query->setIndex(ETH1_INDEX); // Create and add a PRL option to the query OptionUint8ArrayPtr prl(new OptionUint8Array(Option::V4, @@ -631,6 +634,7 @@ TEST_F(VendorOptsTest, option43BadRaw) { OptionPtr clientid = generateClientId(); query->addOption(clientid); query->setIface("eth1"); + query->setIndex(ETH1_INDEX); // Create and add a vendor-encapsulated-options (code 43) // with not compatible (not parsable as suboptions) content @@ -721,6 +725,7 @@ TEST_F(VendorOptsTest, option43FailRaw) { OptionPtr clientid = generateClientId(); query->addOption(clientid); query->setIface("eth1"); + query->setIndex(ETH1_INDEX); // Create and add a vendor-encapsulated-options (code 43) // with not compatible (not parsable as suboptions) content @@ -791,6 +796,7 @@ TEST_F(VendorOptsTest, option43RawGlobal) { OptionPtr clientid = generateClientId(); query->addOption(clientid); query->setIface("eth1"); + query->setIndex(ETH1_INDEX); // Create and add a vendor-encapsulated-options (code 43) // with not compatible (not parsable as suboptions) content @@ -883,6 +889,7 @@ TEST_F(VendorOptsTest, option43RawClass) { OptionPtr clientid = generateClientId(); query->addOption(clientid); query->setIface("eth1"); + query->setIndex(ETH1_INDEX); // Create and add a vendor-encapsulated-options (code 43) // with not compatible (not parsable as suboptions) content @@ -982,6 +989,7 @@ TEST_F(VendorOptsTest, option43Class) { OptionPtr clientid = generateClientId(); query->addOption(clientid); query->setIface("eth1"); + query->setIndex(ETH1_INDEX); // Create and add a vendor-encapsulated-options (code 43) OptionBuffer buf; @@ -1113,6 +1121,7 @@ TEST_F(VendorOptsTest, option43ClassPriority) { OptionPtr clientid = generateClientId(); query->addOption(clientid); query->setIface("eth1"); + query->setIndex(ETH1_INDEX); // Create and add a vendor-encapsulated-options (code 43) OptionBuffer buf; @@ -1250,6 +1259,7 @@ TEST_F(VendorOptsTest, option43Classes) { OptionPtr clientid = generateClientId(); query->addOption(clientid); query->setIface("eth1"); + query->setIndex(ETH1_INDEX); // Create and add a vendor-encapsulated-options (code 43) OptionBuffer buf; @@ -1594,6 +1604,7 @@ TEST_F(VendorOptsTest, vendorOpsSubOption0) { OptionPtr clientid = generateClientId(); query->addOption(clientid); query->setIface("eth1"); + query->setIndex(ETH1_INDEX); // Create and add a PRL option to the query OptionUint8ArrayPtr prl(new OptionUint8Array(Option::V4, |