From 1e42a07ce99cf703e248f6b6a56825cb445efebf Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Thu, 29 Nov 2018 00:57:39 -0200 Subject: [PATCH] ripngd: retrofit the 'allow-ecmp' command to the new northbound model Trivial conversion. The ripng->ecmp variable was converted to a boolean to match the way it's defined in the YANG module. Signed-off-by: Renato Westphal --- ripngd/ripng_cli.c | 26 +++++++++++++++++++++++++ ripngd/ripng_cli.h | 2 ++ ripngd/ripng_northbound.c | 9 ++++++++- ripngd/ripngd.c | 41 +-------------------------------------- ripngd/ripngd.h | 3 ++- 5 files changed, 39 insertions(+), 42 deletions(-) diff --git a/ripngd/ripng_cli.c b/ripngd/ripng_cli.c index 7bdc742207..8944198c2f 100644 --- a/ripngd/ripng_cli.c +++ b/ripngd/ripng_cli.c @@ -75,8 +75,34 @@ void cli_show_router_ripng(struct vty *vty, struct lyd_node *dnode, vty_out(vty, "router ripng\n"); } +/* + * XPath: /frr-ripngd:ripngd/instance/allow-ecmp + */ +DEFPY (ripng_allow_ecmp, + ripng_allow_ecmp_cmd, + "[no] allow-ecmp", + NO_STR + "Allow Equal Cost MultiPath\n") +{ + nb_cli_enqueue_change(vty, "./allow-ecmp", NB_OP_MODIFY, + no ? "false" : "true"); + + return nb_cli_apply_changes(vty, NULL); +} + +void cli_show_ripng_allow_ecmp(struct vty *vty, struct lyd_node *dnode, + bool show_defaults) +{ + if (!yang_dnode_get_bool(dnode, NULL)) + vty_out(vty, " no"); + + vty_out(vty, " allow-ecmp\n"); +} + void ripng_cli_init(void) { install_element(CONFIG_NODE, &router_ripng_cmd); install_element(CONFIG_NODE, &no_router_ripng_cmd); + + install_element(RIPNG_NODE, &ripng_allow_ecmp_cmd); } diff --git a/ripngd/ripng_cli.h b/ripngd/ripng_cli.h index f0ef046f6a..e90fb8aaec 100644 --- a/ripngd/ripng_cli.h +++ b/ripngd/ripng_cli.h @@ -23,5 +23,7 @@ extern void cli_show_router_ripng(struct vty *vty, struct lyd_node *dnode, bool show_defaults); +extern void cli_show_ripng_allow_ecmp(struct vty *vty, struct lyd_node *dnode, + bool show_defaults); #endif /* _FRR_RIPNG_CLI_H_ */ diff --git a/ripngd/ripng_northbound.c b/ripngd/ripng_northbound.c index 219d8d1db7..f067d048e4 100644 --- a/ripngd/ripng_northbound.c +++ b/ripngd/ripng_northbound.c @@ -82,7 +82,13 @@ static int ripngd_instance_allow_ecmp_modify(enum nb_event event, const struct lyd_node *dnode, union nb_resource *resource) { - /* TODO: implement me. */ + if (event != NB_EV_APPLY) + return NB_OK; + + ripng->ecmp = yang_dnode_get_bool(dnode, NULL); + if (!ripng->ecmp) + ripng_ecmp_disable(); + return NB_OK; } @@ -513,6 +519,7 @@ const struct frr_yang_module_info frr_ripngd_info = { { .xpath = "/frr-ripngd:ripngd/instance/allow-ecmp", .cbs.modify = ripngd_instance_allow_ecmp_modify, + .cbs.cli_show = cli_show_ripng_allow_ecmp, }, { .xpath = "/frr-ripngd:ripngd/instance/default-information-originate", diff --git a/ripngd/ripngd.c b/ripngd/ripngd.c index 634596719c..0d5ec507bf 100644 --- a/ripngd/ripngd.c +++ b/ripngd/ripngd.c @@ -2540,7 +2540,7 @@ DEFUN (no_ripng_default_information_originate, } /* Update ECMP routes to zebra when ECMP is disabled. */ -static void ripng_ecmp_disable(void) +void ripng_ecmp_disable(void) { struct agg_node *rp; struct ripng_info *rinfo, *tmp_rinfo; @@ -2577,38 +2577,6 @@ static void ripng_ecmp_disable(void) } } -DEFUN (ripng_allow_ecmp, - ripng_allow_ecmp_cmd, - "allow-ecmp", - "Allow Equal Cost MultiPath\n") -{ - if (ripng->ecmp) { - vty_out(vty, "ECMP is already enabled.\n"); - return CMD_WARNING; - } - - ripng->ecmp = 1; - zlog_info("ECMP is enabled."); - return CMD_SUCCESS; -} - -DEFUN (no_ripng_allow_ecmp, - no_ripng_allow_ecmp_cmd, - "no allow-ecmp", - NO_STR - "Allow Equal Cost MultiPath\n") -{ - if (!ripng->ecmp) { - vty_out(vty, "ECMP is already disabled.\n"); - return CMD_WARNING; - } - - ripng->ecmp = 0; - zlog_info("ECMP is disabled."); - ripng_ecmp_disable(); - return CMD_SUCCESS; -} - /* RIPng configuration write function. */ static int ripng_config_write(struct vty *vty) { @@ -2644,10 +2612,6 @@ static int ripng_config_write(struct vty *vty) inet6_ntoa(rp->p.u.prefix6), rp->p.prefixlen); - /* ECMP configuration. */ - if (ripng->ecmp) - vty_out(vty, " allow-ecmp\n"); - /* RIPng static routes. */ for (rp = agg_route_top(ripng->route); rp; rp = agg_route_next(rp)) @@ -2983,9 +2947,6 @@ void ripng_init() install_element(RIPNG_NODE, &no_ripng_default_information_originate_cmd); - install_element(RIPNG_NODE, &ripng_allow_ecmp_cmd); - install_element(RIPNG_NODE, &no_ripng_allow_ecmp_cmd); - ripng_if_init(); ripng_debug_init(); diff --git a/ripngd/ripngd.h b/ripngd/ripngd.h index de3b2e1947..9b5f89076b 100644 --- a/ripngd/ripngd.h +++ b/ripngd/ripngd.h @@ -134,7 +134,7 @@ struct ripng { struct thread *t_triggered_interval; /* RIPng ECMP flag */ - unsigned int ecmp; + bool ecmp; /* For redistribute route map. */ struct { @@ -378,6 +378,7 @@ extern void ripng_redistribute_delete(int, int, struct prefix_ipv6 *, ifindex_t); extern void ripng_redistribute_withdraw(int type); +extern void ripng_ecmp_disable(void); extern void ripng_distribute_update_interface(struct interface *); extern void ripng_if_rmap_update_interface(struct interface *); -- 2.39.5