Skip to content

Commit

Permalink
Merge pull request #6135 from opensourcerouting/cli-node-cleanup
Browse files Browse the repository at this point in the history
*: clean up the mess that is CLI command nodes
  • Loading branch information
donaldsharp authored Apr 16, 2020
2 parents edf7eff + d1b221f commit 2ff9950
Show file tree
Hide file tree
Showing 59 changed files with 1,184 additions and 745 deletions.
14 changes: 8 additions & 6 deletions babeld/babel_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,13 @@ static void babel_interface_free (babel_interface_nfo *bi);


static vector babel_enable_if; /* enable interfaces (by cmd). */
static struct cmd_node babel_interface_node = /* babeld's interface node. */
{
INTERFACE_NODE,
"%s(config-if)# ",
1 /* VTYSH */
static int interface_config_write(struct vty *vty);
static struct cmd_node babel_interface_node = {
.name = "interface",
.node = INTERFACE_NODE,
.parent_node = CONFIG_NODE,
.prompt = "%s(config-if)# ",
.config_write = interface_config_write,
};


Expand Down Expand Up @@ -1247,7 +1249,7 @@ babel_if_init(void)
babel_enable_if = vector_init (1);

/* install interface node and commands */
install_node (&babel_interface_node, interface_config_write);
install_node(&babel_interface_node);
if_cmd_init();

install_element(BABEL_NODE, &babel_network_cmd);
Expand Down
7 changes: 5 additions & 2 deletions babeld/babeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,14 @@ static time_t expiry_time;
static time_t source_expiry_time;

/* Babel node structure. */
static int babel_config_write (struct vty *vty);
static struct cmd_node cmd_babel_node =
{
.name = "babel",
.node = BABEL_NODE,
.parent_node = CONFIG_NODE,
.prompt = "%s(config-router)# ",
.vtysh = 1,
.config_write = babel_config_write,
};

/* print current babel configuration on vty */
Expand Down Expand Up @@ -719,7 +722,7 @@ void
babeld_quagga_init(void)
{

install_node(&cmd_babel_node, &babel_config_write);
install_node(&cmd_babel_node);

install_element(CONFIG_NODE, &router_babel_cmd);
install_element(CONFIG_NODE, &no_router_babel_cmd);
Expand Down
20 changes: 12 additions & 8 deletions bfdd/bfdd_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -885,16 +885,20 @@ DEFUN_NOSH(show_debugging_bfd,
return CMD_SUCCESS;
}

static int bfdd_write_config(struct vty *vty);
struct cmd_node bfd_node = {
BFD_NODE,
"%s(config-bfd)# ",
1,
.name = "bfd",
.node = BFD_NODE,
.parent_node = CONFIG_NODE,
.prompt = "%s(config-bfd)# ",
.config_write = bfdd_write_config,
};

struct cmd_node bfd_peer_node = {
BFD_PEER_NODE,
"%s(config-bfd-peer)# ",
1,
.name = "bfd peer",
.node = BFD_PEER_NODE,
.parent_node = BFD_NODE,
.prompt = "%s(config-bfd-peer)# ",
};

static int bfdd_write_config(struct vty *vty)
Expand Down Expand Up @@ -945,11 +949,11 @@ void bfdd_vty_init(void)
install_element(CONFIG_NODE, &bfd_debug_network_cmd);

/* Install BFD node and commands. */
install_node(&bfd_node, bfdd_write_config);
install_node(&bfd_node);
install_default(BFD_NODE);

/* Install BFD peer node. */
install_node(&bfd_peer_node, NULL);
install_node(&bfd_peer_node);
install_default(BFD_PEER_NODE);

bfdd_cli_init();
Expand Down
9 changes: 7 additions & 2 deletions bgpd/bgp_bmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1772,7 +1772,12 @@ static void bmp_active_setup(struct bmp_active *ba)
}
}

static struct cmd_node bmp_node = {BMP_NODE, "%s(config-bgp-bmp)# "};
static struct cmd_node bmp_node = {
.name = "bmp",
.node = BMP_NODE,
.parent_node = BGP_NODE,
.prompt = "%s(config-bgp-bmp)# "
};

#define BMP_STR "BGP Monitoring Protocol\n"

Expand Down Expand Up @@ -2266,7 +2271,7 @@ static int bmp_config_write(struct bgp *bgp, struct vty *vty)

static int bgp_bmp_init(struct thread_master *tm)
{
install_node(&bmp_node, NULL);
install_node(&bmp_node);
install_default(BMP_NODE);
install_element(BGP_NODE, &bmp_targets_cmd);
install_element(BGP_NODE, &no_bmp_targets_cmd);
Expand Down
10 changes: 8 additions & 2 deletions bgpd/bgp_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -2282,11 +2282,17 @@ static int bgp_config_write_debug(struct vty *vty)
return write;
}

static struct cmd_node debug_node = {DEBUG_NODE, "", 1};
static int bgp_config_write_debug(struct vty *vty);
static struct cmd_node debug_node = {
.name = "debug",
.node = DEBUG_NODE,
.prompt = "",
.config_write = bgp_config_write_debug,
};

void bgp_debug_init(void)
{
install_node(&debug_node, bgp_config_write_debug);
install_node(&debug_node);

install_element(ENABLE_NODE, &show_debugging_bgp_cmd);

Expand Down
10 changes: 8 additions & 2 deletions bgpd/bgp_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -777,8 +777,14 @@ DEFUN (no_dump_bgp_all,
return bgp_dump_unset(bgp_dump_struct);
}

static int config_write_bgp_dump(struct vty *vty);
/* BGP node structure. */
static struct cmd_node bgp_dump_node = {DUMP_NODE, "", 1};
static struct cmd_node bgp_dump_node = {
.name = "dump",
.node = DUMP_NODE,
.prompt = "",
.config_write = config_write_bgp_dump,
};

#if 0
char *
Expand Down Expand Up @@ -857,7 +863,7 @@ void bgp_dump_init(void)
stream_new((BGP_MAX_PACKET_SIZE << 1) + BGP_DUMP_MSG_HEADER
+ BGP_DUMP_HEADER_SIZE);

install_node(&bgp_dump_node, config_write_bgp_dump);
install_node(&bgp_dump_node);

install_element(CONFIG_NODE, &dump_bgp_all_cmd);
install_element(CONFIG_NODE, &no_dump_bgp_all_cmd);
Expand Down
10 changes: 8 additions & 2 deletions bgpd/bgp_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -667,12 +667,18 @@ static int config_write_as_list(struct vty *vty)
return write;
}

static struct cmd_node as_list_node = {AS_LIST_NODE, "", 1};
static int config_write_as_list(struct vty *vty);
static struct cmd_node as_list_node = {
.name = "as list",
.node = AS_LIST_NODE,
.prompt = "",
.config_write = config_write_as_list,
};

/* Register functions. */
void bgp_filter_init(void)
{
install_node(&as_list_node, config_write_as_list);
install_node(&as_list_node);

install_element(CONFIG_NODE, &bgp_as_path_cmd);
install_element(CONFIG_NODE, &no_bgp_as_path_cmd);
Expand Down
63 changes: 12 additions & 51 deletions bgpd/bgp_rpki.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ static struct rtr_mgr_group *get_connected_group(void);
static void print_prefix_table(struct vty *vty);
static void install_cli_commands(void);
static int config_write(struct vty *vty);
static void overwrite_exit_commands(void);
static int config_on_exit(struct vty *vty);
static void free_cache(struct cache *cache);
static struct rtr_mgr_group *get_groups(void);
#if defined(FOUND_SSH)
Expand Down Expand Up @@ -143,7 +143,14 @@ static unsigned int retry_interval;
static int rpki_sync_socket_rtr;
static int rpki_sync_socket_bgpd;

static struct cmd_node rpki_node = {RPKI_NODE, "%s(config-rpki)# ", 1};
static struct cmd_node rpki_node = {
.name = "rpki",
.node = RPKI_NODE,
.parent_node = CONFIG_NODE,
.prompt = "%s(config-rpki)# ",
.config_write = config_write,
.node_exit = config_on_exit,
};
static const struct route_map_rule_cmd route_match_rpki_cmd = {
"rpki", route_match, route_match_compile, route_match_free};

Expand Down Expand Up @@ -1394,35 +1401,10 @@ DEFUN (show_rpki_cache_connection,
return CMD_SUCCESS;
}

DEFUN_NOSH (rpki_exit,
rpki_exit_cmd,
"exit",
"Exit rpki configuration and restart rpki session\n")
static int config_on_exit(struct vty *vty)
{
reset(false);

vty->node = CONFIG_NODE;
return CMD_SUCCESS;
}

DEFUN_NOSH (rpki_quit,
rpki_quit_cmd,
"quit",
"Exit rpki configuration mode\n")
{
return rpki_exit(self, vty, argc, argv);
}

DEFUN_NOSH (rpki_end,
rpki_end_cmd,
"end",
"End rpki configuration, restart rpki session and change to enable mode.\n")
{
int ret = reset(false);

vty_config_exit(vty);
vty->node = ENABLE_NODE;
return ret == SUCCESS ? CMD_SUCCESS : CMD_WARNING;
return 1;
}

DEFUN (rpki_reset,
Expand Down Expand Up @@ -1516,32 +1498,11 @@ DEFUN (no_match_rpki,
return CMD_SUCCESS;
}

static void overwrite_exit_commands(void)
{
unsigned int i;
vector cmd_vector = rpki_node.cmd_vector;

for (i = 0; i < cmd_vector->active; ++i) {
struct cmd_element *cmd = vector_lookup(cmd_vector, i);

if (strcmp(cmd->string, "exit") == 0
|| strcmp(cmd->string, "quit") == 0
|| strcmp(cmd->string, "end") == 0) {
uninstall_element(RPKI_NODE, cmd);
}
}

install_element(RPKI_NODE, &rpki_exit_cmd);
install_element(RPKI_NODE, &rpki_quit_cmd);
install_element(RPKI_NODE, &rpki_end_cmd);
}

static void install_cli_commands(void)
{
// TODO: make config write work
install_node(&rpki_node, &config_write);
install_node(&rpki_node);
install_default(RPKI_NODE);
overwrite_exit_commands();
install_element(CONFIG_NODE, &rpki_cmd);
install_element(ENABLE_NODE, &rpki_cmd);

Expand Down
Loading

0 comments on commit 2ff9950

Please sign in to comment.