From e91c44cfdb498dfcc5aa462b8acf605ce600830e Mon Sep 17 00:00:00 2001 From: Dan Theisen Date: Wed, 21 Sep 2022 03:34:04 -0700 Subject: [PATCH] [#2543] Add RAI Link Selection preferences --- doc/examples/kea4/all-keys-netconf.json | 6 +++++- doc/examples/kea4/all-keys.json | 6 +++++- doc/sphinx/grammar/grammar-dhcp4-parser.rst | 4 +++- src/bin/dhcp4/dhcp4_parser.yy | 7 +++++++ src/bin/dhcp4/json_config_parser.cc | 4 ++++ src/lib/dhcpsrv/cfg_subnets4.cc | 22 +++++++++++++-------- src/lib/dhcpsrv/srv_config.cc | 6 ++++-- src/lib/dhcpsrv/srv_config.h | 16 +++++++++++++++ 8 files changed, 58 insertions(+), 13 deletions(-) diff --git a/doc/examples/kea4/all-keys-netconf.json b/doc/examples/kea4/all-keys-netconf.json index baa1594c22..64241eaa96 100644 --- a/doc/examples/kea4/all-keys-netconf.json +++ b/doc/examples/kea4/all-keys-netconf.json @@ -105,7 +105,11 @@ "compatibility": { // Parse options more leniently where fields can be deduced // deterministically even if against RFC or common practice. - "lenient-option-parsing": true + "lenient-option-parsing": true, + // Ignore Relay Agent Information Link Selection suboption if set + // to true. This will use normal subnet selection logic instead of + // attempting to use the subnet specified by the suboption. + "ignore-rai-link-selection": false }, // Command control socket configuration parameters for Kea DHCPv4 server. diff --git a/doc/examples/kea4/all-keys.json b/doc/examples/kea4/all-keys.json index 3b3b722b4e..225afcf06e 100644 --- a/doc/examples/kea4/all-keys.json +++ b/doc/examples/kea4/all-keys.json @@ -105,7 +105,11 @@ "compatibility": { // Parse options more leniently where fields can be deduced // deterministically even if against RFC or common practice. - "lenient-option-parsing": true + "lenient-option-parsing": true, + // Ignore Relay Agent Information Link Selection suboption if set + // to true. This will use normal subnet selection logic instead of + // attempting to use the subnet specified by the suboption. + "ignore-rai-link-selection": false }, // Command control socket configuration parameters for Kea DHCPv4 server. diff --git a/doc/sphinx/grammar/grammar-dhcp4-parser.rst b/doc/sphinx/grammar/grammar-dhcp4-parser.rst index 94e9891e6e..3bf1984212 100644 --- a/doc/sphinx/grammar/grammar-dhcp4-parser.rst +++ b/doc/sphinx/grammar/grammar-dhcp4-parser.rst @@ -990,8 +990,10 @@ This grammar is generated from ``dhcp4_parser.yy``. See :ref:`dhcp4` for more de | compatibility_params "," compatibility_param | compatibility_params "," - compatibility_param ::= lenient_option_parsing + compatibility_param ::= lenient_option_parsing | ignore-rai-link-selection | | unknown_map_entry lenient_option_parsing ::= "lenient-option-parsing" ":" BOOLEAN + ignore-rai-link-selection ::= "ignore-rai-link-selection" ":" BOOLEAN + diff --git a/src/bin/dhcp4/dhcp4_parser.yy b/src/bin/dhcp4/dhcp4_parser.yy index 6e5f5519d6..c411443cf0 100644 --- a/src/bin/dhcp4/dhcp4_parser.yy +++ b/src/bin/dhcp4/dhcp4_parser.yy @@ -2847,6 +2847,7 @@ compatibility_params: compatibility_param ; compatibility_param: lenient_option_parsing + | ignore-rai-link-selection | unknown_map_entry ; @@ -2856,6 +2857,12 @@ lenient_option_parsing: LENIENT_OPTION_PARSING COLON BOOLEAN { ctx.stack_.back()->set("lenient-option-parsing", b); }; +ignore-rai-link-selection: IGNORE_RAI_LINK_SEL COLON BOOLEAN { + ctx.unique("ignore-rai-link-selection", ctx.loc2pos(@1)); + ElementPtr b(new BoolElement($3, ctx.loc2pos(@3))); + ctx.stack_.back()->set("lenient-option-parsing", b); +} + %% void diff --git a/src/bin/dhcp4/json_config_parser.cc b/src/bin/dhcp4/json_config_parser.cc index 4816fccc4a..21ed702136 100644 --- a/src/bin/dhcp4/json_config_parser.cc +++ b/src/bin/dhcp4/json_config_parser.cc @@ -598,6 +598,10 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set, CfgMgr::instance().getStagingCfg()->setLenientOptionParsing( kv.second->boolValue()); } + if (kv.first == "ignore-rai-link-selection") { + CfgMgr::instance().getStagingCfg()->setIgnoreRAILinkSelection( + kv.second->boolValue()); + } } } diff --git a/src/lib/dhcpsrv/cfg_subnets4.cc b/src/lib/dhcpsrv/cfg_subnets4.cc index 2f160b655d..782986aee6 100644 --- a/src/lib/dhcpsrv/cfg_subnets4.cc +++ b/src/lib/dhcpsrv/cfg_subnets4.cc @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -224,14 +225,19 @@ CfgSubnets4::initSelector(const Pkt4Ptr& query) { OptionCustomPtr rai_custom = boost::dynamic_pointer_cast(rai); if (rai_custom) { - OptionPtr link_select = - rai_custom->getOption(RAI_OPTION_LINK_SELECTION); - if (link_select) { - OptionBuffer link_select_buf = link_select->getData(); - if (link_select_buf.size() == sizeof(uint32_t)) { - selector.option_select_ = - IOAddress::fromBytes(AF_INET, &link_select_buf[0]); - return (selector); + // If Relay Agent Information Link Selection is ignored in the configuration, skip + // returning the related subnet selector here, and move on to normal subnet selection. + bool ignore_link_sel = CfgMgr::instance().getCurrentCfg()->getIgnoreRAILinkSelection(); + if (!ignore_link_sel) { + OptionPtr link_select = + rai_custom->getOption(RAI_OPTION_LINK_SELECTION); + if (link_select) { + OptionBuffer link_select_buf = link_select->getData(); + if (link_select_buf.size() == sizeof(uint32_t)) { + selector.option_select_ = + IOAddress::fromBytes(AF_INET, &link_select_buf[0]); + return (selector); + } } } } diff --git a/src/lib/dhcpsrv/srv_config.cc b/src/lib/dhcpsrv/srv_config.cc index 44b4be5672..50e4e7891a 100644 --- a/src/lib/dhcpsrv/srv_config.cc +++ b/src/lib/dhcpsrv/srv_config.cc @@ -47,7 +47,8 @@ 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), reservations_lookup_first_(false) { + lenient_option_parsing_(false), ignore_rai_link_selection_(false), + reservations_lookup_first_(false) { } SrvConfig::SrvConfig(const uint32_t sequence) @@ -65,7 +66,8 @@ 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), reservations_lookup_first_(false) { + lenient_option_parsing_(false), ignore_rai_link_selection_(false), + reservations_lookup_first_(false) { } std::string diff --git a/src/lib/dhcpsrv/srv_config.h b/src/lib/dhcpsrv/srv_config.h index 7ad9a1b45d..e0b323f8ec 100644 --- a/src/lib/dhcpsrv/srv_config.h +++ b/src/lib/dhcpsrv/srv_config.h @@ -984,6 +984,21 @@ public: return lenient_option_parsing_; } + /// @brief Set ignore RAI Link Selection compatibility flag. + /// + /// @param value the boolean value to be set when configuring RAI Link + /// Selection usage preferences + void setIgnoreRAILinkSelection(bool const value) { + ignore_rai_link_selection_ = value; + } + + /// @brief Get ignore RAI Link Selection compatibility flag. + /// + /// @return the configured value for RAI Link Selection usage preferences + bool getIgnoreRAILinkSelection() const { + return ignore_rai_link_selection_; + } + /// @brief Convenience method to propagate configuration parameters through /// inversion of control. /// @@ -1148,6 +1163,7 @@ private: /// @brief Compatibility flags /// @{ bool lenient_option_parsing_; + bool ignore_rai_link_selection_; /// @} /// @brief Flag which indicates if the server should do host reservations