]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2543] Add RAI Link Selection preferences
authorDan Theisen <djt@isc.org>
Wed, 21 Sep 2022 10:34:04 +0000 (03:34 -0700)
committerDan Theisen <djt@isc.org>
Tue, 11 Oct 2022 08:03:46 +0000 (01:03 -0700)
doc/examples/kea4/all-keys-netconf.json
doc/examples/kea4/all-keys.json
doc/sphinx/grammar/grammar-dhcp4-parser.rst
src/bin/dhcp4/dhcp4_parser.yy
src/bin/dhcp4/json_config_parser.cc
src/lib/dhcpsrv/cfg_subnets4.cc
src/lib/dhcpsrv/srv_config.cc
src/lib/dhcpsrv/srv_config.h

index baa1594c22d4ff7663ff7b799c65a9a4ecdf9679..64241eaa96f1abcfd98ba62f9edb8af60affab84 100644 (file)
         "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.
index 3b3b722b4ea089ad7892ae2d16506d06b0f089fa..225afcf06e8f286fe2db2e2ed1d6897bb862dec0 100644 (file)
         "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.
index 94e9891e6e4048437fde70a043f78f51be5a61f4..3bf1984212b49a4fac2739f7a44f889cb81337cf 100644 (file)
@@ -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
+
index 6e5f5519d69f4cc74d3e774e910c3920b15b7cc1..c411443cf0572d0fcf321f7c816961a70f1610fb 100644 (file)
@@ -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
index 4816fccc4ada74656c4bc54b0018354ab325f461..21ed702136bf6a653c47160a742f938f8d8bb143 100644 (file)
@@ -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());
+                }
             }
         }
 
index 2f160b655d5692490e65e8b27aa923c21f6a5074..782986aee6732a37fecfd245c7ff17321e4963d9 100644 (file)
@@ -7,6 +7,7 @@
 #include <config.h>
 #include <dhcp/iface_mgr.h>
 #include <dhcp/option_custom.h>
+#include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/cfg_subnets4.h>
 #include <dhcpsrv/dhcpsrv_log.h>
 #include <dhcpsrv/lease_mgr_factory.h>
@@ -224,14 +225,19 @@ CfgSubnets4::initSelector(const Pkt4Ptr& query) {
         OptionCustomPtr rai_custom =
             boost::dynamic_pointer_cast<OptionCustom>(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);
+                    }
                 }
             }
         }
index 44b4be5672fb66267ba7f54277f537915e6dbc6d..50e4e7891a7c4aa8095b4ec6149f769938f244f4 100644 (file)
@@ -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
index 7ad9a1b45deaef13f6fc88e50cd126add1fa5c4b..e0b323f8ec6700025e8f668ab39bd42772db1b15 100644 (file)
@@ -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