From: Marcin Siodelski Date: Tue, 15 Jul 2014 12:15:26 +0000 (+0200) Subject: [3390] Append basic options that we always want be returned. X-Git-Tag: trac3482_base~79^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d777fbc73dc2b52585ddb6e97707e1c90d0a51b5;p=thirdparty%2Fkea.git [3390] Append basic options that we always want be returned. --- diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc index b23130b362..9c337afe39 100644 --- a/src/bin/dhcp4/dhcp4_srv.cc +++ b/src/bin/dhcp4/dhcp4_srv.cc @@ -1422,6 +1422,7 @@ Dhcpv4Srv::processInform(Pkt4Ptr& inform) { copyDefaultFields(inform, ack); appendRequestedOptions(inform, ack); appendRequestedVendorOptions(inform, ack); + appendBasicOptions(inform, ack); adjustIfaceData(inform, ack); // There are cases for the DHCPINFORM that the server receives it via diff --git a/src/bin/dhcp4/tests/dhcp4_client.cc b/src/bin/dhcp4/tests/dhcp4_client.cc index dd9c3b8bf6..42900ba172 100644 --- a/src/bin/dhcp4/tests/dhcp4_client.cc +++ b/src/bin/dhcp4/tests/dhcp4_client.cc @@ -25,7 +25,8 @@ namespace dhcp { namespace test { Dhcp4Client::Configuration::Configuration() - : routers_(), dns_servers_(), serverid_("0.0.0.0") { + : routers_(), dns_servers_(), log_servers_(), quotes_servers_(), + serverid_("0.0.0.0") { reset(); } @@ -33,6 +34,8 @@ void Dhcp4Client::Configuration::reset() { routers_.clear(); dns_servers_.clear(); + log_servers_.clear(); + quotes_servers_.clear(); serverid_ = asiolink::IOAddress("0.0.0.0"); } @@ -69,25 +72,38 @@ Dhcp4Client::applyConfiguration() { config_.reset(); + // Routers Option4AddrLstPtr opt_routers = boost::dynamic_pointer_cast< Option4AddrLst>(resp->getOption(DHO_ROUTERS)); if (opt_routers) { config_.routers_ = opt_routers->getAddresses(); } - + // DNS Servers Option4AddrLstPtr opt_dns_servers = boost::dynamic_pointer_cast< Option4AddrLst>(resp->getOption(DHO_DOMAIN_NAME_SERVERS)); if (opt_dns_servers) { config_.dns_servers_ = opt_dns_servers->getAddresses(); } - + // Log Servers + Option4AddrLstPtr opt_log_servers = boost::dynamic_pointer_cast< + Option4AddrLst>(resp->getOption(DHO_LOG_SERVERS)); + if (opt_log_servers) { + config_.log_servers_ = opt_routers->getAddresses(); + } + // Quotes Servers + Option4AddrLstPtr opt_quotes_servers = boost::dynamic_pointer_cast< + Option4AddrLst>(resp->getOption(DHO_COOKIE_SERVERS)); + if (opt_quotes_servers) { + config_.quotes_servers_ = opt_dns_servers->getAddresses(); + } + // Server Identifier OptionCustomPtr opt_serverid = boost::dynamic_pointer_cast< OptionCustom>(resp->getOption(DHO_DHCP_SERVER_IDENTIFIER)); if (opt_serverid) { config_.serverid_ = opt_serverid->readAddress(); } - /// @todo Other possible configuration. + /// @todo Other possible configuration, e.g. lease. } void diff --git a/src/bin/dhcp4/tests/dhcp4_client.h b/src/bin/dhcp4/tests/dhcp4_client.h index f1eefe7c47..f6865d2830 100644 --- a/src/bin/dhcp4/tests/dhcp4_client.h +++ b/src/bin/dhcp4/tests/dhcp4_client.h @@ -59,6 +59,8 @@ public: struct Configuration { Option4AddrLst::AddressContainer routers_; Option4AddrLst::AddressContainer dns_servers_; + Option4AddrLst::AddressContainer log_servers_; + Option4AddrLst::AddressContainer quotes_servers_; Lease4 lease_; asiolink::IOAddress serverid_; @@ -200,6 +202,17 @@ public: private: /// @brief Stores configuration received from the server. + /// + /// This methods stores the configuration obtained from the DHCP server + /// in the @c Configuration structure. This configuration includes: + /// - obtained lease + /// - server id of the server that provided the configuration + /// - lease + /// - selected options (used by unit tests): + /// - DNS Servers + /// - Routers + /// - Log Servers + /// - Quotes Servers void applyConfiguration(); /// @brief Creates client's side DHCP message. diff --git a/src/bin/dhcp4/tests/inform_unittest.cc b/src/bin/dhcp4/tests/inform_unittest.cc index 52450d6916..494ea77420 100644 --- a/src/bin/dhcp4/tests/inform_unittest.cc +++ b/src/bin/dhcp4/tests/inform_unittest.cc @@ -36,12 +36,16 @@ namespace { /// - 1 pool: 10.0.0.10-10.0.0.100 /// - Router option present: 10.0.0.200 and 10.0.0.201 /// - Domain Name Server option present: 10.0.0.202, 10.0.0.203. +/// - Log Servers option present: 192.0.2.200 and 192.0.2.201 +/// - Quotes Servers option present: 192.0.2.202, 192.0.2.203. /// /// - Configuration 1: /// - Use for testing relayed messages /// - 1 subnet: 192.0.2.0/24 /// - Router option present: 192.0.2.200 and 192.0.2.201 /// - Domain Name Server option present: 192.0.2.202, 192.0.2.203. +/// - Log Servers option present: 192.0.2.200 and 192.0.2.201 +/// - Quotes Servers option present: 192.0.2.202, 192.0.2.203. const char* INFORM_CONFIGS[] = { // Configuration 0 "{ \"interfaces\": [ \"all\" ]," @@ -62,7 +66,20 @@ const char* INFORM_CONFIGS[] = { " \"data\": \"10.0.0.202,10.0.0.203\"," " \"csv-format\": true," " \"space\": \"dhcp4\"" - + " }," + " {" + " \"name\": \"log-servers\"," + " \"code\": 7," + " \"data\": \"10.0.0.200,10.0.0.201\"," + " \"csv-format\": true," + " \"space\": \"dhcp4\"" + " }," + " {" + " \"name\": \"cookie-servers\"," + " \"code\": 8," + " \"data\": \"10.0.0.202,10.0.0.203\"," + " \"csv-format\": true," + " \"space\": \"dhcp4\"" " } ]" " } ]" "}", @@ -85,7 +102,20 @@ const char* INFORM_CONFIGS[] = { " \"data\": \"192.0.2.202,192.0.2.203\"," " \"csv-format\": true," " \"space\": \"dhcp4\"" - + " }," + " {" + " \"name\": \"log-servers\"," + " \"code\": 7," + " \"data\": \"10.0.0.200,10.0.0.201\"," + " \"csv-format\": true," + " \"space\": \"dhcp4\"" + " }," + " {" + " \"name\": \"cookie-servers\"," + " \"code\": 8," + " \"data\": \"10.0.0.202,10.0.0.203\"," + " \"csv-format\": true," + " \"space\": \"dhcp4\"" " } ]" " } ]" "}" @@ -116,7 +146,7 @@ TEST_F(InformTest, directClientBroadcast) { // Configure DHCP server. configure(INFORM_CONFIGS[0], *client.getServer()); // Request some configuration when DHCPINFORM is sent. - client.requestOptions(DHO_DOMAIN_NAME_SERVERS, DHO_ROUTERS); + client.requestOptions(DHO_LOG_SERVERS, DHO_COOKIE_SERVERS); // Preconfigure the client with the IP address. client.createLease(IOAddress("10.0.0.56"), 600); // Send DHCPINFORM message to the server. @@ -141,13 +171,21 @@ TEST_F(InformTest, directClientBroadcast) { ASSERT_EQ(2, client.config_.dns_servers_.size()); EXPECT_EQ("10.0.0.202", client.config_.dns_servers_[0].toText()); EXPECT_EQ("10.0.0.203", client.config_.dns_servers_[1].toText()); + // Make sure that the Log Servers option has been received. + ASSERT_EQ(2, client.config_.quotes_servers_.size()); + EXPECT_EQ("10.0.0.200", client.config_.routers_[0].toText()); + EXPECT_EQ("10.0.0.201", client.config_.routers_[1].toText()); + // Make sure that the Quotes Servers option has been received. + ASSERT_EQ(2, client.config_.log_servers_.size()); + EXPECT_EQ("10.0.0.202", client.config_.dns_servers_[0].toText()); + EXPECT_EQ("10.0.0.203", client.config_.dns_servers_[1].toText()); // Check that we can send another DHCPINFORM message using // different ciaddr and we will get the configuration. client.createLease(IOAddress("10.0.0.12"), 600); - // This time do not request DNS Servers option and it should not + // This time do not request Quotes Servers option and it should not // be returned. - client.requestOptions(DHO_ROUTERS); + client.requestOptions(DHO_LOG_SERVERS); // Send DHCPINFORM. ASSERT_NO_THROW(client.doInform()); ASSERT_TRUE(client.getContext().response_); @@ -165,7 +203,11 @@ TEST_F(InformTest, directClientBroadcast) { EXPECT_EQ("10.0.0.200", client.config_.routers_[0].toText()); EXPECT_EQ("10.0.0.201", client.config_.routers_[1].toText()); // Make sure that the DNS Servers option has been received. - ASSERT_TRUE(client.config_.dns_servers_.empty()); + ASSERT_EQ(2, client.config_.dns_servers_.size()); + EXPECT_EQ("10.0.0.202", client.config_.dns_servers_[0].toText()); + EXPECT_EQ("10.0.0.203", client.config_.dns_servers_[1].toText()); + // Make sure that the Quotes Servers option hasn't been received. + ASSERT_TRUE(client.config_.quotes_servers_.empty()); } // This test checks that the server drops DHCPINFORM message when the @@ -175,7 +217,7 @@ TEST_F(InformTest, directClientBroadcastNoAddress) { // Configure DHCP server. configure(INFORM_CONFIGS[0], *client.getServer()); // Request some configuration when DHCPINFORM is sent. - client.requestOptions(DHO_DOMAIN_NAME_SERVERS, DHO_ROUTERS); + client.requestOptions(DHO_LOG_SERVERS, DHO_COOKIE_SERVERS); // Send DHCPINFORM message to the server. ASSERT_NO_THROW(client.doInform()); // Make sure that the server dropped the message. @@ -189,8 +231,6 @@ TEST_F(InformTest, directClientUnicast) { Dhcp4Client client; // Configure DHCP server. configure(INFORM_CONFIGS[0], *client.getServer()); - // Request some configuration when DHCPINFORM is sent. - client.requestOptions(DHO_DOMAIN_NAME_SERVERS, DHO_ROUTERS); // Preconfigure the client with the IP address. client.createLease(IOAddress("10.0.0.56"), 600); // Set remote address to unicast. @@ -225,8 +265,6 @@ TEST_F(InformTest, directClientNoCiaddr) { Dhcp4Client client; // Configure DHCP server. configure(INFORM_CONFIGS[0], *client.getServer()); - // Request some configuration when DHCPINFORM is sent. - client.requestOptions(DHO_DOMAIN_NAME_SERVERS, DHO_ROUTERS); // Preconfigure the client with the IP address. client.createLease(IOAddress("10.0.0.56"), 600); // Send DHCPINFORM message (with ciaddr not set) to the server. @@ -261,7 +299,7 @@ TEST_F(InformTest, relayedClient) { // Message is relayed. client.useRelay(); // Request some configuration when DHCPINFORM is sent. - client.requestOptions(DHO_DOMAIN_NAME_SERVERS, DHO_ROUTERS); + client.requestOptions(DHO_LOG_SERVERS, DHO_COOKIE_SERVERS); // Preconfigure the client with the IP address. client.createLease(IOAddress("192.0.2.56"), 600); // Send DHCPINFORM message to the server. @@ -285,6 +323,14 @@ TEST_F(InformTest, relayedClient) { ASSERT_EQ(2, client.config_.dns_servers_.size()); EXPECT_EQ("192.0.2.202", client.config_.dns_servers_[0].toText()); EXPECT_EQ("192.0.2.203", client.config_.dns_servers_[1].toText()); + // Make sure that the Log Servers option has been received. + ASSERT_EQ(2, client.config_.quotes_servers_.size()); + EXPECT_EQ("192.0.2.200", client.config_.routers_[0].toText()); + EXPECT_EQ("192.0.2.201", client.config_.routers_[1].toText()); + // Make sure that the Quotes Servers option has been received. + ASSERT_EQ(2, client.config_.log_servers_.size()); + EXPECT_EQ("192.0.2.202", client.config_.dns_servers_[0].toText()); + EXPECT_EQ("192.0.2.203", client.config_.dns_servers_[1].toText()); } // This test checks that the server can respond to the DHCPINFORM message @@ -295,8 +341,6 @@ TEST_F(InformTest, relayedClientNoCiaddr) { configure(INFORM_CONFIGS[1], *client.getServer()); // Message is relayed. client.useRelay(); - // Request some configuration when DHCPINFORM is sent. - client.requestOptions(DHO_DOMAIN_NAME_SERVERS, DHO_ROUTERS); // Send DHCPINFORM message to the server. ASSERT_NO_THROW(client.doInform()); // Make sure that the server responded.