From 77cadfb3eeee5b667c155a26bab329130f6d380e Mon Sep 17 00:00:00 2001 From: Christian Hopps Date: Tue, 3 Oct 2023 17:53:11 -0400 Subject: [PATCH] zebra: add zebra to mgmtd oper-state Signed-off-by: Christian Hopps --- lib/mgmt_be_client.c | 1 + lib/mgmt_be_client.h | 1 + mgmtd/mgmt_be_adapter.c | 11 ++++++++++- mgmtd/mgmt_main.c | 2 ++ zebra/debug.c | 4 ++++ zebra/main.c | 7 +++++++ zebra/zebra_nb_state.c | 4 ++++ 7 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/mgmt_be_client.c b/lib/mgmt_be_client.c index 2bf2abbfa5f8..4f1facf550d8 100644 --- a/lib/mgmt_be_client.c +++ b/lib/mgmt_be_client.c @@ -122,6 +122,7 @@ struct mgmt_be_client { struct debug mgmt_dbg_be_client = {0, "Management backend client operations"}; const char *mgmt_be_client_names[MGMTD_BE_CLIENT_ID_MAX + 1] = { + [MGMTD_BE_CLIENT_ID_ZEBRA] = "zebra", #ifdef HAVE_STATICD [MGMTD_BE_CLIENT_ID_STATICD] = "staticd", #endif diff --git a/lib/mgmt_be_client.h b/lib/mgmt_be_client.h index c692b9c963f1..11a437aa895a 100644 --- a/lib/mgmt_be_client.h +++ b/lib/mgmt_be_client.h @@ -30,6 +30,7 @@ enum mgmt_be_client_id { #ifdef HAVE_STATICD MGMTD_BE_CLIENT_ID_STATICD, #endif + MGMTD_BE_CLIENT_ID_ZEBRA, MGMTD_BE_CLIENT_ID_MAX }; diff --git a/mgmtd/mgmt_be_adapter.c b/mgmtd/mgmt_be_adapter.c index e0b757c5a08f..a61fcabb7ac9 100644 --- a/mgmtd/mgmt_be_adapter.c +++ b/mgmtd/mgmt_be_adapter.c @@ -57,7 +57,16 @@ static const char *const *be_client_xpaths[] = { #endif }; -static const char **be_client_oper_xpaths[] = {}; +static const char *const zebra_oper_xpaths[] = { + "/frr-interface:lib/frr-interface:interface/frr-zebra:zebra/*", + "/frr-vrf:lib/vrf/frr-zebra:zebra/*", + "/frr-zebra:zebra/*", + NULL, +}; + +static const char *const *be_client_oper_xpaths[] = { + [MGMTD_BE_CLIENT_ID_ZEBRA] = zebra_oper_xpaths, +}; /* * We would like to have a better ADT than one with O(n) comparisons diff --git a/mgmtd/mgmt_main.c b/mgmtd/mgmt_main.c index 39362fa74a83..84977bd11d3d 100644 --- a/mgmtd/mgmt_main.c +++ b/mgmtd/mgmt_main.c @@ -203,6 +203,8 @@ static const struct frr_yang_module_info *const mgmt_yang_modules[] = { * NOTE: Always set .ignore_cbs true for to avoid validating * backend northbound callbacks during loading. */ + &(struct frr_yang_module_info){.name = "frr-zebra", + .ignore_cbs = true}, #ifdef HAVE_STATICD &(struct frr_yang_module_info){.name = "frr-staticd", .ignore_cbs = true}, diff --git a/zebra/debug.c b/zebra/debug.c index 68bedaf0578a..cf1701be1938 100644 --- a/zebra/debug.c +++ b/zebra/debug.c @@ -7,6 +7,7 @@ #include #include "command.h" #include "debug.h" +#include "mgmt_be_client.h" #include "zebra/debug_clippy.c" @@ -846,4 +847,7 @@ void zebra_debug_init(void) install_element(CONFIG_NODE, &no_debug_zebra_pbr_cmd); install_element(CONFIG_NODE, &debug_zebra_mlag_cmd); install_element(CONFIG_NODE, &debug_zebra_evpn_mh_cmd); + + /* Init mgmtd backend client debug commands. */ + mgmt_be_client_lib_vty_init(); } diff --git a/zebra/main.c b/zebra/main.c index 1e833ce7f182..f019fd42e88d 100644 --- a/zebra/main.c +++ b/zebra/main.c @@ -21,6 +21,7 @@ #include "affinitymap.h" #include "routemap.h" #include "routing_nb.h" +#include "mgmt_be_client.h" #include "zebra/zebra_router.h" #include "zebra/zebra_errors.h" @@ -54,6 +55,8 @@ pid_t pid; /* Pacify zclient.o in libfrr, which expects this variable. */ struct event_loop *master; +struct mgmt_be_client *mgmt_be_client; + /* Route retain mode flag. */ int retain_mode = 0; @@ -140,6 +143,8 @@ static void sigint(void) zlog_notice("Terminating on signal"); + mgmt_be_client_destroy(mgmt_be_client); + atomic_store_explicit(&zrouter.in_shutdown, true, memory_order_relaxed); @@ -418,6 +423,8 @@ int main(int argc, char **argv) zebra_ns_init(); router_id_cmd_init(); zebra_vty_init(); + mgmt_be_client = mgmt_be_client_create("zebra", NULL, 0, + zrouter.master); access_list_init(); prefix_list_init(); rtadv_cmd_init(); diff --git a/zebra/zebra_nb_state.c b/zebra/zebra_nb_state.c index ba537475cbcc..4fa6587b0a93 100644 --- a/zebra/zebra_nb_state.c +++ b/zebra/zebra_nb_state.c @@ -156,6 +156,8 @@ const void *lib_vrf_zebra_ribs_rib_get_next(struct nb_cb_get_next_args *args) safi_t safi; zvrf = zebra_vrf_lookup_by_id(vrf->vrf_id); + if (!zvrf) + return NULL; if (args->list_entry == NULL) { afi = AFI_IP; @@ -198,6 +200,8 @@ lib_vrf_zebra_ribs_rib_lookup_entry(struct nb_cb_lookup_entry_args *args) uint32_t table_id = 0; zvrf = zebra_vrf_lookup_by_id(vrf->vrf_id); + if (!zvrf) + return NULL; yang_afi_safi_identity2value(args->keys->key[0], &afi, &safi); table_id = yang_str2uint32(args->keys->key[1]);