From: Francis Dupont Date: Tue, 21 Mar 2023 11:06:34 +0000 (+0100) Subject: [#2785] Almost done X-Git-Tag: Kea-2.3.6~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=39f01f50eb0e063b24c473e6807d405774c3958a;p=thirdparty%2Fkea.git [#2785] Almost done --- diff --git a/doc/examples/kea4/all-keys.json b/doc/examples/kea4/all-keys.json index 86f5038659..005438ecb0 100644 --- a/doc/examples/kea4/all-keys.json +++ b/doc/examples/kea4/all-keys.json @@ -118,6 +118,13 @@ // Parameters for triggering behaviors compatible with broken or // non-compliant clients, relays or other agents "compatibility": { + // Ignore DHCP Server Identifier option if set to true. + // Enabling this will cause Kea to accept any query even + // if the address in the option belongs to another server + // instead of dropping it. This config option defaults to + // false, as enabling it breaks RFC compliance. + "ignore-dhcp-server-identifier": false, + // Ignore Relay Agent Information Link Selection suboption if set // to true. Enabling this will cause Kea use normal subnet // selection logic instead of attempting to use the subnet diff --git a/doc/sphinx/arm/dhcp4-srv.rst b/doc/sphinx/arm/dhcp4-srv.rst index 8e8777d308..7e4184a655 100644 --- a/doc/sphinx/arm/dhcp4-srv.rst +++ b/doc/sphinx/arm/dhcp4-srv.rst @@ -1521,8 +1521,8 @@ Parameter Request List option (or its equivalent for vendor options): In the example above, the ``domain-name-servers`` option respects the global -``always-send`` flag and is always added to responses, but for subnet -``192.0.3.0/24``, the value is taken from the subnet-level option data +``always-send`` flag and is always added to responses, but for subnet +``192.0.3.0/24``, the value is taken from the subnet-level option data specification. At the opposite of ``always-send`` if the ``never-send`` flag is set to @@ -7638,6 +7638,24 @@ or in terms of the log message above, the tuple length ``y`` becomes ``x``. } } +Ignore DHCP Server Identifier +----------------------------- + +With ``"ignore-dhcp-server-identifier": true``, the server does not check the +address in the DHCP Server Identifier option i.e. whether a query is sent +to this server or another one (and in the second case dropping the query). + +.. code-block:: json + + { + "Dhcp4": { + "compatibility": { + "ignore-dhcp-server-identifier": true + } + } + } + + Ignore RAI Link Selection ------------------------- diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc index 8431c2750d..8a63102ff9 100644 --- a/src/bin/dhcp4/dhcp4_srv.cc +++ b/src/bin/dhcp4/dhcp4_srv.cc @@ -4036,6 +4036,12 @@ Dhcpv4Srv::acceptServerId(const Pkt4Ptr& query) const { } } + // Skip address check if configured to ignore the server id. + SrvConfigPtr cfg = CfgMgr::instance().getCurrentCfg(); + if (cfg->getIgnoreServerIdentifier()) { + return (true); + } + // This function iterates over all interfaces on which the // server is listening to find the one which has a socket bound // to the address carried in the server identifier option. @@ -4067,8 +4073,6 @@ Dhcpv4Srv::acceptServerId(const Pkt4Ptr& query) const { /// know the reservations for the client communicating with the server. /// We may revise some of these choices in the future. - SrvConfigPtr cfg = CfgMgr::instance().getCurrentCfg(); - // Check if there is at least one subnet configured with this server // identifier. ConstCfgSubnets4Ptr cfg_subnets = cfg->getCfgSubnets4(); diff --git a/src/bin/dhcp4/json_config_parser.cc b/src/bin/dhcp4/json_config_parser.cc index fd0378ced0..09466e89b3 100644 --- a/src/bin/dhcp4/json_config_parser.cc +++ b/src/bin/dhcp4/json_config_parser.cc @@ -584,6 +584,9 @@ processDhcp4Config(isc::data::ConstElementPtr config_set) { if (kv.first == "lenient-option-parsing") { CfgMgr::instance().getStagingCfg()->setLenientOptionParsing( kv.second->boolValue()); + } else if (kv.first == "ignore-dhcp-server-identifier") { + CfgMgr::instance().getStagingCfg()->setIgnoreServerIdentifier( + kv.second->boolValue()); } else if (kv.first == "ignore-rai-link-selection") { CfgMgr::instance().getStagingCfg()->setIgnoreRAILinkSelection( kv.second->boolValue()); diff --git a/src/bin/dhcp4/tests/config_parser_unittest.cc b/src/bin/dhcp4/tests/config_parser_unittest.cc index 4077ce15db..271185129a 100644 --- a/src/bin/dhcp4/tests/config_parser_unittest.cc +++ b/src/bin/dhcp4/tests/config_parser_unittest.cc @@ -1701,6 +1701,7 @@ TEST_F(Dhcp4ParserTest, compatibility) { "\"renew-timer\": 1000, " "\"compatibility\": { " " \"lenient-option-parsing\": true," + " \"ignore-dhcp-server-identifier\": true," " \"ignore-rai-link-selection\": true," " \"exclude-first-last-24\": true" "}," @@ -1715,6 +1716,7 @@ TEST_F(Dhcp4ParserTest, compatibility) { // Check defaults: they should be false. EXPECT_FALSE(CfgMgr::instance().getStagingCfg()->getLenientOptionParsing()); + EXPECT_FALSE(CfgMgr::instance().getStagingCfg()->getIgnoreServerIdentifier()); EXPECT_FALSE(CfgMgr::instance().getStagingCfg()->getIgnoreRAILinkSelection()); EXPECT_FALSE(CfgMgr::instance().getStagingCfg()->getExcludeFirstLast24()); @@ -1724,6 +1726,7 @@ TEST_F(Dhcp4ParserTest, compatibility) { checkResult(status, 0); EXPECT_TRUE(CfgMgr::instance().getStagingCfg()->getLenientOptionParsing()); + EXPECT_TRUE(CfgMgr::instance().getStagingCfg()->getIgnoreServerIdentifier()); EXPECT_TRUE(CfgMgr::instance().getStagingCfg()->getIgnoreRAILinkSelection()); EXPECT_TRUE(CfgMgr::instance().getStagingCfg()->getExcludeFirstLast24()); } diff --git a/src/bin/dhcp4/tests/get_config_unittest.cc b/src/bin/dhcp4/tests/get_config_unittest.cc index be9b62dc69..782b64c318 100644 --- a/src/bin/dhcp4/tests/get_config_unittest.cc +++ b/src/bin/dhcp4/tests/get_config_unittest.cc @@ -351,6 +351,7 @@ const char* EXTRACTED_CONFIGS[] = { "{\n" " \"compatibility\": {\n" " \"exclude-first-last-24\": true,\n" +" \"ignore-dhcp-server-identifier\": true,\n" " \"ignore-rai-link-selection\": true,\n" " \"lenient-option-parsing\": true\n" " },\n" @@ -3772,6 +3773,7 @@ const char* UNPARSED_CONFIGS[] = { " \"calculate-tee-times\": false,\n" " \"compatibility\": {\n" " \"exclude-first-last-24\": true,\n" +" \"ignore-dhcp-server-identifier\": true,\n" " \"ignore-rai-link-selection\": true,\n" " \"lenient-option-parsing\": true\n" " },\n" diff --git a/src/lib/dhcpsrv/srv_config.cc b/src/lib/dhcpsrv/srv_config.cc index 6d1df21612..b44d410baf 100644 --- a/src/lib/dhcpsrv/srv_config.cc +++ b/src/lib/dhcpsrv/srv_config.cc @@ -47,8 +47,9 @@ SrvConfig::SrvConfig() decline_timer_(0), echo_v4_client_id_(true), dhcp4o6_port_(0), d2_client_config_(new D2ClientConfig()), configured_globals_(new CfgGlobals()), cfg_consist_(new CfgConsistency()), - lenient_option_parsing_(false), ignore_rai_link_selection_(false), - exclude_first_last_24_(false), reservations_lookup_first_(false) { + lenient_option_parsing_(false), ignore_dhcp_server_identifier_(false), + ignore_rai_link_selection_(false), exclude_first_last_24_(false), + reservations_lookup_first_(false) { } SrvConfig::SrvConfig(const uint32_t sequence) @@ -66,8 +67,9 @@ SrvConfig::SrvConfig(const uint32_t sequence) decline_timer_(0), echo_v4_client_id_(true), dhcp4o6_port_(0), d2_client_config_(new D2ClientConfig()), configured_globals_(new CfgGlobals()), cfg_consist_(new CfgConsistency()), - lenient_option_parsing_(false), ignore_rai_link_selection_(false), - exclude_first_last_24_(false), reservations_lookup_first_(false) { + lenient_option_parsing_(false), ignore_dhcp_server_identifier_(false), + ignore_rai_link_selection_(false), exclude_first_last_24_(false), + reservations_lookup_first_(false) { } std::string @@ -637,6 +639,9 @@ SrvConfig::toElement() const { if (getLenientOptionParsing()) { compatibility->set("lenient-option-parsing", Element::create(true)); } + if (getIgnoreServerIdentifier()) { + compatibility->set("ignore-dhcp-server-identifier", Element::create(true)); + } if (getIgnoreRAILinkSelection()) { compatibility->set("ignore-rai-link-selection", Element::create(true)); } diff --git a/src/lib/dhcpsrv/srv_config.h b/src/lib/dhcpsrv/srv_config.h index ab5e8da0b2..4790341735 100644 --- a/src/lib/dhcpsrv/srv_config.h +++ b/src/lib/dhcpsrv/srv_config.h @@ -991,6 +991,21 @@ public: return lenient_option_parsing_; } + /// @brief Set ignore DHCP Server Identifier compatibility flag. + /// + /// @param value the boolean value to be set when configuring DHCP + /// Server Identifier usage preferences. + void setIgnoreServerIdentifier(bool const value) { + ignore_dhcp_server_identifier_ = value; + } + + /// @brief Get ignore DHCP Server Identifier compatibility flag. + /// + /// @return the configured value for DHCP Server Identifier usage preferences. + bool getIgnoreServerIdentifier() const { + return (ignore_dhcp_server_identifier_); + } + /// @brief Set ignore RAI Link Selection compatibility flag. /// /// @param value the boolean value to be set when configuring RAI Link @@ -1187,6 +1202,8 @@ private: //@{ /// @brief Indicates whether lenient option parsing is enabled bool lenient_option_parsing_; + /// @brief Indicates whether DHCP server identifier option will be ignored + bool ignore_dhcp_server_identifier_; /// @brief Indicates whether RAI link-selection suboptions will be ignored bool ignore_rai_link_selection_; /// @brief Indicates whether exclude .0 .255 from subnets bigger than /24. diff --git a/src/lib/dhcpsrv/tests/srv_config_unittest.cc b/src/lib/dhcpsrv/tests/srv_config_unittest.cc index 3935cdc8dc..67150a578c 100644 --- a/src/lib/dhcpsrv/tests/srv_config_unittest.cc +++ b/src/lib/dhcpsrv/tests/srv_config_unittest.cc @@ -315,28 +315,34 @@ TEST_F(SrvConfigTest, compatibility) { // Check that defaults are false. EXPECT_FALSE(conf.getLenientOptionParsing()); + EXPECT_FALSE(conf.getIgnoreServerIdentifier()); EXPECT_FALSE(conf.getIgnoreRAILinkSelection()); EXPECT_FALSE(conf.getExcludeFirstLast24()); // Check that they can be modified to true. conf.setLenientOptionParsing(true); + conf.setIgnoreServerIdentifier(true); conf.setIgnoreRAILinkSelection(true); conf.setExcludeFirstLast24(true); EXPECT_TRUE(conf.getLenientOptionParsing()); + EXPECT_TRUE(conf.getIgnoreServerIdentifier()); EXPECT_TRUE(conf.getIgnoreRAILinkSelection()); EXPECT_TRUE(conf.getExcludeFirstLast24()); // Check that default values can be restored. conf.setLenientOptionParsing(false); + conf.setIgnoreServerIdentifier(false); conf.setIgnoreRAILinkSelection(false); conf.setExcludeFirstLast24(false); EXPECT_FALSE(conf.getLenientOptionParsing()); + EXPECT_FALSE(conf.getIgnoreServerIdentifier()); EXPECT_FALSE(conf.getIgnoreRAILinkSelection()); EXPECT_FALSE(conf.getExcludeFirstLast24()); // Check the other constructor has the same default. SrvConfig conf1(1); EXPECT_FALSE(conf1.getLenientOptionParsing()); + EXPECT_FALSE(conf.getIgnoreServerIdentifier()); EXPECT_FALSE(conf1.getIgnoreRAILinkSelection()); EXPECT_FALSE(conf1.getExcludeFirstLast24()); }