]> git.proxmox.com Git - mirror_frr.git/commitdiff
zebra: add config to disable use of kernel nexthops
authorMark Stapp <mjs@voltanet.io>
Tue, 28 Jan 2020 16:00:42 +0000 (11:00 -0500)
committerMark Stapp <mjs@voltanet.io>
Tue, 28 Jan 2020 16:00:42 +0000 (11:00 -0500)
Add a config that disables use of kernel-level nexthop ids.
Currently, zebra always uses nexthop ids if the kernel supports
them.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
zebra/rt_netlink.c
zebra/zebra_nhg.c
zebra/zebra_nhg.h
zebra/zebra_vty.c

index dd6e62ee6c8569a215a1f6904f84b42bd5d6baeb..32678ed664c92ed5811cdd1affc2674973ac570f 100644 (file)
 
 static vlanid_t filter_vlan = 0;
 
+/* We capture whether the current kernel supports nexthop ids; by
+ * default, we'll use them if possible. There's also a configuration
+ * available to _disable_ use of kernel nexthops.
+ */
 static bool supports_nh;
 
 struct gw_family_t {
@@ -86,6 +90,12 @@ struct gw_family_t {
 static const char ipv4_ll_buf[16] = "169.254.0.1";
 static struct in_addr ipv4_ll;
 
+/* Helper to control use of kernel-level nexthop ids */
+static bool kernel_nexthops_supported(void)
+{
+       return (supports_nh && zebra_nhg_kernel_nexthops_enabled());
+}
+
 /*
  * The ipv4_ll data structure is used for all 5549
  * additions to the kernel.  Let's figure out the
@@ -1628,7 +1638,7 @@ static int netlink_route_multipath(int cmd, struct zebra_dplane_ctx *ctx)
                          RTA_PAYLOAD(rta));
        }
 
-       if (supports_nh) {
+       if (kernel_nexthops_supported()) {
                /* Kernel supports nexthop objects */
                addattr32(&req.n, sizeof(req), RTA_NH_ID,
                          dplane_ctx_get_nhe_id(ctx));
@@ -1943,7 +1953,7 @@ static int netlink_nexthop(int cmd, struct zebra_dplane_ctx *ctx)
        size_t req_size = sizeof(req);
 
        /* Nothing to do if the kernel doesn't support nexthop objects */
-       if (!supports_nh)
+       if (!kernel_nexthops_supported())
                return 0;
 
        label_buf[0] = '\0';
@@ -2501,8 +2511,10 @@ int netlink_nexthop_read(struct zebra_ns *zns)
                 * this kernel must support them.
                 */
                supports_nh = true;
-       else if (IS_ZEBRA_DEBUG_KERNEL)
-               zlog_debug("Nexthop objects not supported on this kernel");
+
+       if (IS_ZEBRA_DEBUG_KERNEL || IS_ZEBRA_DEBUG_NHG)
+               zlog_debug("Nexthop objects %ssupported on this kernel",
+                          supports_nh ? "" : "not ");
 
        return ret;
 }
index 74303073206b6ac213ddd1dc60156b6bcf00cd75..ccc898836cc59a7cb238a345bd4c4827dc814572 100644 (file)
@@ -49,6 +49,9 @@ DEFINE_MTYPE_STATIC(ZEBRA, NHG_CTX, "Nexthop Group Context");
 /* id counter to keep in sync with kernel */
 uint32_t id_counter;
 
+/*  */
+static bool g_nexthops_enabled = true;
+
 static struct nhg_hash_entry *depends_find(const struct nexthop *nh,
                                           afi_t afi);
 static void depends_add(struct nhg_connected_tree_head *head,
@@ -1985,3 +1988,18 @@ void zebra_nhg_sweep_table(struct hash *hash)
 {
        hash_iterate(hash, zebra_nhg_sweep_entry, NULL);
 }
+
+/* Global control to disable use of kernel nexthops, if available. We can't
+ * force the kernel to support nexthop ids, of course, but we can disable
+ * zebra's use of them, for testing e.g. By default, if the kernel supports
+ * nexthop ids, zebra uses them.
+ */
+void zebra_nhg_enable_kernel_nexthops(bool set)
+{
+       g_nexthops_enabled = set;
+}
+
+bool zebra_nhg_kernel_nexthops_enabled(void)
+{
+       return g_nexthops_enabled;
+}
index 522ec1e9ddfb6615cc5b98431a2dfcf559fe3f09..f1d88092c6e2b95f5cadd2a86209e6a4111e39de 100644 (file)
@@ -153,6 +153,13 @@ struct nhg_ctx {
        enum nhg_ctx_status status;
 };
 
+/* Global control to disable use of kernel nexthops, if available. We can't
+ * force the kernel to support nexthop ids, of course, but we can disable
+ * zebra's use of them, for testing e.g. By default, if the kernel supports
+ * nexthop ids, zebra uses them.
+ */
+void zebra_nhg_enable_kernel_nexthops(bool set);
+bool zebra_nhg_kernel_nexthops_enabled(void);
 
 /**
  * NHE abstracted tree functions.
@@ -227,4 +234,5 @@ extern void zebra_nhg_sweep_table(struct hash *hash);
 /* Nexthop resolution processing */
 struct route_entry; /* Forward ref to avoid circular includes */
 extern int nexthop_active_update(struct route_node *rn, struct route_entry *re);
-#endif
+
+#endif /* __ZEBRA_NHG_H__ */
index c8b96011dc3b5ed85219b968ea3b9c98202f61b4..7b377a81c1e4f7b5ccd1ec06b111f315e62e13b3 100644 (file)
@@ -1404,6 +1404,19 @@ DEFPY (show_nexthop_group,
        return CMD_SUCCESS;
 }
 
+DEFPY_HIDDEN(nexthop_group_use_enable,
+            nexthop_group_use_enable_cmd,
+            "[no] zebra nexthop kernel enable",
+            NO_STR
+            ZEBRA_STR
+            "Nexthop configuration \n"
+            "Configure use of kernel nexthops\n"
+            "Enable kernel nexthops\n")
+{
+       zebra_nhg_enable_kernel_nexthops(!no);
+       return CMD_SUCCESS;
+}
+
 DEFUN (no_ip_nht_default_route,
        no_ip_nht_default_route_cmd,
        "no ip nht resolve-via-default",
@@ -3115,6 +3128,10 @@ static int config_write_protocol(struct vty *vty)
        /* Include dataplane info */
        dplane_config_write_helper(vty);
 
+       /* Include nexthop-group config */
+       if (!zebra_nhg_kernel_nexthops_enabled())
+               vty_out(vty, "no zebra nexthop kernel enable\n");
+
        return 1;
 }
 
@@ -3486,6 +3503,7 @@ void zebra_vty_init(void)
        install_element(CONFIG_NODE, &no_zebra_workqueue_timer_cmd);
        install_element(CONFIG_NODE, &zebra_packet_process_cmd);
        install_element(CONFIG_NODE, &no_zebra_packet_process_cmd);
+       install_element(CONFIG_NODE, &nexthop_group_use_enable_cmd);
 
        install_element(VIEW_NODE, &show_nexthop_group_cmd);
        install_element(VIEW_NODE, &show_interface_nexthop_group_cmd);