From c9af62e314893d8d3bdb7b3fcd91249e8e401064 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Wed, 15 Jun 2022 19:54:29 -0400 Subject: [PATCH] zebra: Add a configurable knob `zebra nexthop-group keep (1-3600)` Allow end operator to set how long a nexthop-group is kept around in the system after it is no-longer being used. Signed-off-by: Donald Sharp --- doc/user/zebra.rst | 6 ++++++ zebra/zebra_nhg.c | 4 ++-- zebra/zebra_router.c | 2 ++ zebra/zebra_router.h | 3 +++ zebra/zebra_vty.c | 21 +++++++++++++++++++++ 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/doc/user/zebra.rst b/doc/user/zebra.rst index 29f305520a..eca67c0609 100644 --- a/doc/user/zebra.rst +++ b/doc/user/zebra.rst @@ -273,6 +273,12 @@ Nexthop tracking doesn't resolve nexthops via the default route by default. Allowing this might be useful when e.g. you want to allow BGP to peer across the default route. +.. clicmd:: zebra nexthop-group keep (1-3600) + + Set the time that zebra will keep a created and installed nexthop group + before removing it from the system if the nexthop group is no longer + being used. The default time is 180 seconds. + .. clicmd:: ip nht resolve-via-default Allow IPv4 nexthop tracking to resolve via the default route. This parameter diff --git a/zebra/zebra_nhg.c b/zebra/zebra_nhg.c index 542972d175..f025507f7d 100644 --- a/zebra/zebra_nhg.c +++ b/zebra/zebra_nhg.c @@ -1649,8 +1649,8 @@ void zebra_nhg_decrement_ref(struct nhg_hash_entry *nhe) !CHECK_FLAG(nhe->flags, NEXTHOP_GROUP_KEEP_AROUND)) { nhe->refcnt = 1; SET_FLAG(nhe->flags, NEXTHOP_GROUP_KEEP_AROUND); - thread_add_timer(zrouter.master, zebra_nhg_timer, nhe, 180, - &nhe->timer); + thread_add_timer(zrouter.master, zebra_nhg_timer, nhe, + zrouter.nhg_keep, &nhe->timer); } if (!zebra_nhg_depends_is_empty(nhe)) diff --git a/zebra/zebra_router.c b/zebra/zebra_router.c index 6b4a7543cd..92d519bad1 100644 --- a/zebra/zebra_router.c +++ b/zebra/zebra_router.c @@ -278,6 +278,8 @@ void zebra_router_init(bool asic_offload, bool notify_on_ack) zrouter.packets_to_process = ZEBRA_ZAPI_PACKETS_TO_PROCESS; + zrouter.nhg_keep = ZEBRA_DEFAULT_NHG_KEEP_TIMER; + zebra_vxlan_init(); zebra_mlag_init(); diff --git a/zebra/zebra_router.h b/zebra/zebra_router.h index 7aca91959c..c96c8e5f46 100644 --- a/zebra/zebra_router.h +++ b/zebra/zebra_router.h @@ -219,6 +219,9 @@ struct zebra_router { bool notify_on_ack; bool supports_nhgs; + +#define ZEBRA_DEFAULT_NHG_KEEP_TIMER 180 + uint32_t nhg_keep; }; #define GRACEFUL_RESTART_TIME 60 diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 88752edb9f..9149da8b0d 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -3850,11 +3850,31 @@ DEFUN (no_ip_zebra_import_table, return (zebra_import_table(AFI_IP, VRF_DEFAULT, table_id, 0, NULL, 0)); } +DEFPY (zebra_nexthop_group_keep, + zebra_nexthop_group_keep_cmd, + "[no] zebra nexthop-group keep (1-3600)", + NO_STR + ZEBRA_STR + "Nexthop-Group\n" + "How long to keep\n" + "Time in seconds from 1-3600\n") +{ + if (no) + zrouter.nhg_keep = ZEBRA_DEFAULT_NHG_KEEP_TIMER; + else + zrouter.nhg_keep = keep; + + return CMD_SUCCESS; +} + static int config_write_protocol(struct vty *vty) { if (allow_delete) vty_out(vty, "allow-external-route-update\n"); + if (zrouter.nhg_keep != ZEBRA_DEFAULT_NHG_KEEP_TIMER) + vty_out(vty, "zebra nexthop-group keep %u\n", zrouter.nhg_keep); + if (zrouter.ribq->spec.hold != ZEBRA_RIB_PROCESS_HOLD_TIME) vty_out(vty, "zebra work-queue %u\n", zrouter.ribq->spec.hold); @@ -4433,6 +4453,7 @@ void zebra_vty_init(void) install_element(CONFIG_NODE, &ip_multicast_mode_cmd); install_element(CONFIG_NODE, &no_ip_multicast_mode_cmd); + install_element(CONFIG_NODE, &zebra_nexthop_group_keep_cmd); install_element(CONFIG_NODE, &ip_zebra_import_table_distance_cmd); install_element(CONFIG_NODE, &no_ip_zebra_import_table_cmd); install_element(CONFIG_NODE, &zebra_workqueue_timer_cmd); -- 2.39.5