Skip to content

Commit

Permalink
zebra: convert to mgmtd
Browse files Browse the repository at this point in the history
Signed-off-by: Igor Ryzhov <[email protected]>
  • Loading branch information
idryzhov committed Jan 27, 2024
1 parent 9353ffb commit 3c3f791
Show file tree
Hide file tree
Showing 28 changed files with 3,010 additions and 3,285 deletions.
8 changes: 8 additions & 0 deletions lib/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ struct cmd_node {
#define DEFPY_YANG(funcname, cmdname, cmdstr, helpstr) \
DEFPY_ATTR(funcname, cmdname, cmdstr, helpstr, CMD_ATTR_YANG)

#define DEFPY_YANG_HIDDEN(funcname, cmdname, cmdstr, helpstr) \
DEFPY_ATTR(funcname, cmdname, cmdstr, helpstr, \
CMD_ATTR_YANG | CMD_ATTR_HIDDEN)

#define DEFPY_YANG_NOSH(funcname, cmdname, cmdstr, helpstr) \
DEFPY_ATTR(funcname, cmdname, cmdstr, helpstr, \
CMD_ATTR_YANG | CMD_ATTR_NOSH)
Expand All @@ -315,6 +319,10 @@ struct cmd_node {
#define DEFUN_NOSH(funcname, cmdname, cmdstr, helpstr) \
DEFUN_ATTR(funcname, cmdname, cmdstr, helpstr, CMD_ATTR_NOSH)

#define DEFUN_YANG_HIDDEN(funcname, cmdname, cmdstr, helpstr) \
DEFUN_ATTR(funcname, cmdname, cmdstr, helpstr, \
CMD_ATTR_YANG | CMD_ATTR_HIDDEN)

#define DEFUN_YANG_NOSH(funcname, cmdname, cmdstr, helpstr) \
DEFUN_ATTR(funcname, cmdname, cmdstr, helpstr, \
CMD_ATTR_YANG | CMD_ATTR_NOSH)
Expand Down
1 change: 1 addition & 0 deletions lib/defun_lex.l
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ SPECIAL [(),]
"DEFPY_ATTR" value = strdup(yytext); return DEFUNNY;
"DEFPY_HIDDEN" value = strdup(yytext); return DEFUNNY;
"DEFPY_YANG" value = strdup(yytext); return DEFUNNY;
"DEFPY_YANG_HIDDEN" value = strdup(yytext); return DEFUNNY;
"DEFPY_YANG_NOSH" value = strdup(yytext); return DEFUNNY;
"ALIAS" value = strdup(yytext); return DEFUNNY;
"ALIAS_HIDDEN" value = strdup(yytext); return DEFUNNY;
Expand Down
14 changes: 1 addition & 13 deletions lib/vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ bool vty_log_commands;
static bool vty_log_commands_perm;

char const *const mgmt_daemons[] = {
"zebra",
#ifdef HAVE_RIPD
"ripd",
#endif
Expand Down Expand Up @@ -2262,19 +2263,6 @@ bool mgmt_vty_read_configs(void)

snprintf(path, sizeof(path), "%s/mgmtd.conf", frr_sysconfdir);
confp = vty_open_config(path, config_default);
if (!confp) {
char *orig;

snprintf(path, sizeof(path), "%s/zebra.conf", frr_sysconfdir);
orig = XSTRDUP(MTYPE_TMP, host_config_get());

zlog_info("mgmtd: trying backup config file: %s", path);
confp = vty_open_config(path, config_default);

host_config_set(path);
XFREE(MTYPE_TMP, orig);
}

if (confp) {
zlog_info("mgmtd: reading config file: %s", path);

Expand Down
24 changes: 17 additions & 7 deletions mgmtd/mgmt_be_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ struct mgmt_be_xpath_map {
* above map as well.
*/

static const char *const zebra_config_xpaths[] = {
"/frr-affinity-map:lib",
"/frr-filter:lib",
"/frr-route-map:lib",
"/frr-interface:lib",
"/frr-vrf:lib",
NULL,
};

static const char *const zebra_oper_xpaths[] = {
"/frr-interface:lib/interface",
"/frr-vrf:lib/vrf/frr-zebra:zebra",
"/frr-zebra:zebra",
NULL,
};

#if HAVE_RIPD
static const char *const ripd_config_xpaths[] = {
"/frr-filter:lib",
Expand Down Expand Up @@ -105,6 +121,7 @@ static const char *const staticd_config_xpaths[] = {
#endif

static const char *const *be_client_config_xpaths[MGMTD_BE_CLIENT_ID_MAX] = {
[MGMTD_BE_CLIENT_ID_ZEBRA] = zebra_config_xpaths,
#ifdef HAVE_RIPD
[MGMTD_BE_CLIENT_ID_RIPD] = ripd_config_xpaths,
#endif
Expand All @@ -116,13 +133,6 @@ static const char *const *be_client_config_xpaths[MGMTD_BE_CLIENT_ID_MAX] = {
#endif
};

static const char *const zebra_oper_xpaths[] = {
"/frr-interface:lib/interface",
"/frr-vrf:lib/vrf/frr-zebra:zebra",
"/frr-zebra:zebra",
NULL,
};

static const char *const *be_client_oper_xpaths[MGMTD_BE_CLIENT_ID_MAX] = {
#ifdef HAVE_RIPD
[MGMTD_BE_CLIENT_ID_RIPD] = ripd_oper_xpaths,
Expand Down
24 changes: 2 additions & 22 deletions mgmtd/mgmt_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "ripngd/ripng_nb.h"
#include "routing_nb.h"
#include "affinitymap.h"
#include "zebra/zebra_cli.h"

/* mgmt options, we use GNU getopt library. */
static const struct option longopts[] = {
Expand Down Expand Up @@ -143,32 +144,11 @@ static struct frr_signal_t mgmt_signals[] = {
extern const struct frr_yang_module_info frr_staticd_cli_info;
#endif

#if HAVE_BFDD == 0 || defined(HAVE_RTADV)
const char *zebra_features[] = {
#if HAVE_BFDD == 0
"ptm-bfd",
#endif
#if defined(HAVE_RTADV)
"ipv6-router-advertisements",
#endif
NULL
};
#endif

/*
* These are stub info structs that are used to load the modules used by backend
* clients into mgmtd. The modules are used by libyang in order to support
* parsing binary data returns from the backend.
*/
const struct frr_yang_module_info zebra_info = {
.name = "frr-zebra",
#if HAVE_BFDD == 0 || defined(HAVE_RTADV)
.features = zebra_features,
#endif
.ignore_cfg_cbs = true,
.nodes = { { .xpath = NULL } },
};

const struct frr_yang_module_info zebra_route_map_info = {
.name = "frr-zebra-route-map",
.ignore_cfg_cbs = true,
Expand All @@ -191,7 +171,7 @@ static const struct frr_yang_module_info *const mgmt_yang_modules[] = {
* YANG module info used by backend clients get added here.
*/

&zebra_info,
&frr_zebra_cli_info,
&zebra_route_map_info,

#ifdef HAVE_RIPD
Expand Down
2 changes: 2 additions & 0 deletions mgmtd/mgmt_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "ripd/rip_nb.h"
#include "ripngd/ripng_nb.h"
#include "staticd/static_vty.h"
#include "zebra/zebra_cli.h"

extern struct frr_daemon_info *mgmt_daemon_info;

Expand Down Expand Up @@ -579,6 +580,7 @@ void mgmt_vty_init(void)
* backend components that are moved to new MGMTD infra
* here one by one.
*/
zebra_cli_init();
#if HAVE_RIPD
rip_cli_init();
#endif
Expand Down
3 changes: 3 additions & 0 deletions mgmtd/subdir.am
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ clippy_scan += \

lib_LTLIBRARIES += mgmtd/libmgmt_be_nb.la
mgmtd_libmgmt_be_nb_la_SOURCES = \
zebra/zebra_cli.c \
# end
nodist_mgmtd_libmgmt_be_nb_la_SOURCES = \
lib/affinitymap_cli.c \
Expand Down Expand Up @@ -44,6 +45,7 @@ noinst_HEADERS += \
mgmtd/mgmt_history.h \
mgmtd/mgmt_memory.h \
mgmtd/mgmt_txn.h \
zebra/zebra_cli.h \
# end

sbin_PROGRAMS += mgmtd/mgmtd
Expand All @@ -52,6 +54,7 @@ mgmtd_mgmtd_SOURCES = \
mgmtd/mgmt_main.c \
# end
nodist_mgmtd_mgmtd_SOURCES = \
yang/frr-zebra.yang.c \
# nothing
mgmtd_mgmtd_CFLAGS = $(AM_CFLAGS) -I ./
mgmtd_mgmtd_LDADD = mgmtd/libmgmtd.a lib/libfrr.la $(LIBCAP) $(LIBM) $(LIBYANG_LIBS) $(UST_LIBS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
"interface": [
{
"name": "r1-eth0",
"description": "r1-eth0-desc"
"description": "r1-eth0-desc",
"frr-zebra:zebra": {
"ipv4-addrs": [
{
"ip": "1.1.1.1",
"prefix-length": 24
}
]
}
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
"phy-address": "rubout"
},
"frr-zebra:zebra": {
"ipv4-addrs": [
{
"ip": "1.1.1.1",
"prefix-length": 24
}
],
"state": {
"up-count": 0,
"down-count": 0
Expand Down
12 changes: 6 additions & 6 deletions vtysh/vtysh.c
Original file line number Diff line number Diff line change
Expand Up @@ -3007,38 +3007,38 @@ DEFUN (vtysh_show_work_queues_daemon,
return show_one_daemon(vty, argv, argc - 1, argv[argc - 1]->text);
}

DEFUNSH(VTYSH_ZEBRA, vtysh_link_params, vtysh_link_params_cmd, "link-params",
DEFUNSH(VTYSH_MGMTD, vtysh_link_params, vtysh_link_params_cmd, "link-params",
LINK_PARAMS_STR)
{
vty->node = LINK_PARAMS_NODE;
return CMD_SUCCESS;
}

DEFUNSH_HIDDEN(VTYSH_ZEBRA, no_link_params_enable, no_link_params_enable_cmd,
"no enable", NO_STR "Disable link parameters on this interface\n")
DEFUNSH_HIDDEN(VTYSH_MGMTD, no_link_params_enable, no_link_params_enable_cmd,
"no enable", NO_STR "Disable link parameters on this interface\n")
{
if (vty->node == LINK_PARAMS_NODE)
vty->node = INTERFACE_NODE;
return CMD_SUCCESS;
}

DEFUNSH(VTYSH_ZEBRA, exit_link_params, exit_link_params_cmd, "exit-link-params",
DEFUNSH(VTYSH_MGMTD, exit_link_params, exit_link_params_cmd, "exit-link-params",
"Exit from Link Params configuration node\n")
{
if (vty->node == LINK_PARAMS_NODE)
vty->node = INTERFACE_NODE;
return CMD_SUCCESS;
}

DEFUNSH(VTYSH_ZEBRA, vtysh_exit_link_params, vtysh_exit_link_params_cmd, "exit",
DEFUNSH(VTYSH_MGMTD, vtysh_exit_link_params, vtysh_exit_link_params_cmd, "exit",
"Exit current mode and down to previous mode\n")
{
if (vty->node == LINK_PARAMS_NODE)
vty->node = INTERFACE_NODE;
return CMD_SUCCESS;
}

DEFUNSH(VTYSH_ZEBRA, vtysh_quit_link_params, vtysh_quit_link_params_cmd, "quit",
DEFUNSH(VTYSH_MGMTD, vtysh_quit_link_params, vtysh_quit_link_params_cmd, "quit",
"Exit current mode and down to previous mode\n")
{
return vtysh_exit_link_params(self, vty, argc, argv);
Expand Down
8 changes: 4 additions & 4 deletions vtysh/vtysh.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,23 @@ extern struct event_loop *master;
VTYSH_BFDD | VTYSH_BABELD | VTYSH_BGPD | VTYSH_EIGRPD | VTYSH_ISISD | \
VTYSH_FABRICD | VTYSH_LDPD | VTYSH_NHRPD | VTYSH_OSPF6D | \
VTYSH_OSPFD | VTYSH_PBRD | VTYSH_PIMD | VTYSH_PIM6D | \
VTYSH_VRRPD | VTYSH_ZEBRA | VTYSH_MGMTD
VTYSH_VRRPD | VTYSH_MGMTD
#define VTYSH_ACL_SHOW \
VTYSH_BFDD | VTYSH_BABELD | VTYSH_BGPD | VTYSH_EIGRPD | VTYSH_ISISD | \
VTYSH_FABRICD | VTYSH_LDPD | VTYSH_NHRPD | VTYSH_OSPF6D | \
VTYSH_OSPFD | VTYSH_PBRD | VTYSH_PIMD | VTYSH_PIM6D | \
VTYSH_RIPD | VTYSH_RIPNGD | VTYSH_VRRPD | VTYSH_ZEBRA

#define VTYSH_AFFMAP VTYSH_ZEBRA | VTYSH_ISISD | VTYSH_MGMTD
#define VTYSH_AFFMAP VTYSH_ISISD | VTYSH_MGMTD
#define VTYSH_RMAP_CONFIG \
VTYSH_ZEBRA | VTYSH_OSPFD | VTYSH_OSPF6D | VTYSH_BGPD | VTYSH_ISISD | \
VTYSH_OSPFD | VTYSH_OSPF6D | VTYSH_BGPD | VTYSH_ISISD | \
VTYSH_PIMD | VTYSH_EIGRPD | VTYSH_FABRICD | VTYSH_MGMTD
#define VTYSH_RMAP_SHOW \
VTYSH_ZEBRA | VTYSH_RIPD | VTYSH_RIPNGD | VTYSH_OSPFD | VTYSH_OSPF6D | \
VTYSH_BGPD | VTYSH_ISISD | VTYSH_PIMD | VTYSH_EIGRPD | \
VTYSH_FABRICD
#define VTYSH_INTERFACE_SUBSET \
VTYSH_ZEBRA | VTYSH_OSPFD | VTYSH_OSPF6D | \
VTYSH_OSPFD | VTYSH_OSPF6D | \
VTYSH_ISISD | VTYSH_PIMD | VTYSH_PIM6D | VTYSH_NHRPD | \
VTYSH_EIGRPD | VTYSH_BABELD | VTYSH_PBRD | VTYSH_FABRICD | \
VTYSH_VRRPD | VTYSH_MGMTD
Expand Down
Loading

0 comments on commit 3c3f791

Please sign in to comment.