Skip to content

Commit

Permalink
lib,mgmtd,zebra: Add Zebra as a MGMT Bckend client
Browse files Browse the repository at this point in the history
Add Zebra as a MGMT Backend client. This commit does not divert show
commands to MGMTd yet.

Co-authored-by: Yash Ranjan <[email protected]>
Signed-off-by: Pushpasis Sarkar <[email protected]>
  • Loading branch information
pushpasis and YashRanjanVMWare committed Sep 26, 2023
1 parent e262650 commit 73f511b
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/mgmt_be_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ const char *mgmt_be_client_names[MGMTD_BE_CLIENT_ID_MAX + 1] = {
#ifdef HAVE_STATICD
[MGMTD_BE_CLIENT_ID_STATICD] = "staticd",
#endif
[MGMTD_BE_CLIENT_ID_ZEBRA] = "zebra",
[MGMTD_BE_CLIENT_ID_MAX] = "Unknown/Invalid",
};

Expand Down
1 change: 1 addition & 0 deletions lib/mgmt_be_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down
14 changes: 14 additions & 0 deletions mgmtd/mgmt_be_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,27 @@ static struct mgmt_be_client_xpath staticd_xpaths[] = {
},
};
#endif
static struct mgmt_be_client_xpath zebra_xpaths[] = {
{
.xpath = "/frr-zebra:zebra/*",
.subscribed = MGMT_SUBSCR_VALIDATE_CFG | MGMT_SUBSCR_NOTIFY_CFG
| MGMT_SUBSCR_OPER_OWN,
},
{
.xpath = "/frr-vrf:lib/vrf[name='*']/frr-zebra:zebra/*",
.subscribed = MGMT_SUBSCR_VALIDATE_CFG | MGMT_SUBSCR_NOTIFY_CFG
| MGMT_SUBSCR_OPER_OWN,
},
};

static struct mgmt_be_client_xpath_map
mgmt_client_xpaths[MGMTD_BE_CLIENT_ID_MAX] = {
#ifdef HAVE_STATICD
[MGMTD_BE_CLIENT_ID_STATICD] = {staticd_xpaths,
array_size(staticd_xpaths)},
#endif
[MGMTD_BE_CLIENT_ID_ZEBRA] = {zebra_xpaths,
array_size(zebra_xpaths)},
};

/*
Expand Down
2 changes: 2 additions & 0 deletions mgmtd/mgmt_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ static const struct frr_yang_module_info *const mgmt_yang_modules[] = {
&(struct frr_yang_module_info){.name = "frr-staticd",
.ignore_cbs = true},
#endif
&(struct frr_yang_module_info){.name = "frr-zebra",
.ignore_cbs = true},
};

FRR_DAEMON_INFO(mgmtd, MGMTD, .vty_port = MGMTD_VTY_PORT,
Expand Down
10 changes: 10 additions & 0 deletions zebra/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -115,6 +116,8 @@ struct zebra_privs_t zserv_privs = {
.cap_num_p = array_size(_caps_p),
.cap_num_i = 0};

struct mgmt_be_client *mgmt_be_client;

/* SIGHUP handler. */
static void sighup(void)
{
Expand All @@ -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);

Expand Down Expand Up @@ -418,6 +423,11 @@ int main(int argc, char **argv)
zebra_ns_init();
router_id_cmd_init();
zebra_vty_init();

/* Initialize MGMT backend functionalities */
mgmt_be_client = mgmt_be_client_create("zebra", NULL, 0,
zrouter.master);

access_list_init();
prefix_list_init();
rtadv_cmd_init();
Expand Down
4 changes: 4 additions & 0 deletions zebra/zebra_nb_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]);
Expand Down
3 changes: 3 additions & 0 deletions zebra/zebra_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "vxlan.h"
#include "termtable.h"
#include "affinitymap.h"
#include "mgmt_be_client.h"

#include "zebra/zebra_router.h"
#include "zebra/zserv.h"
Expand Down Expand Up @@ -4702,4 +4703,6 @@ void zebra_vty_init(void)
#endif /* HAVE_SCRIPTING */

install_element(VIEW_NODE, &zebra_show_routing_tables_summary_cmd);

mgmt_be_client_lib_vty_init();
}

0 comments on commit 73f511b

Please sign in to comment.