Commit a0a0a916 authored by Francis Dupont's avatar Francis Dupont
Browse files

[#553] Checkpoint: convert to use interface indexes

parent 7e5746e6
......@@ -1601,8 +1601,7 @@ Dhcpv4Srv::appendServerID(Dhcpv4Exchange& ex) {
Pkt4Ptr query = ex.getQuery();
if (local_addr.isV4Bcast() || query->isDhcp4o6()) {
SocketInfo sock_info = IfaceMgr::instance().getSocket(*query);
local_addr = sock_info.addr_;
local_addr = IfaceMgr::instance().getSocket(query).addr_;
}
OptionPtr opt_srvid(new Option4AddrLst(DHO_DHCP_SERVER_IDENTIFIER,
......@@ -2697,8 +2696,7 @@ Dhcpv4Srv::adjustIfaceData(Dhcpv4Exchange& ex) {
// use this address as a source address for the response.
// Do the same for DHCPv4-over-DHCPv6 exchanges.
if (local_addr.isV4Bcast() || query->isDhcp4o6()) {
SocketInfo sock_info = IfaceMgr::instance().getSocket(*query);
local_addr = sock_info.addr_;
local_addr = IfaceMgr::instance().getSocket(query).addr_;
}
// We assume that there is an appropriate socket bound to this address
......
// 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();
......
// 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_;
......
......@@ -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
......
// 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));
......
......@@ -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"));