From 22e8c7ae642026865234741b9a9bb50df79378bf Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Thu, 29 Nov 2018 02:41:57 -0200 Subject: [PATCH] ripngd: retrofit the 'passive-interface' command to the new northbound model Trivial conversion. Signed-off-by: Renato Westphal --- ripngd/ripng_cli.c | 24 ++++++++++++++++++ ripngd/ripng_cli.h | 3 +++ ripngd/ripng_interface.c | 51 +++++++-------------------------------- ripngd/ripng_northbound.c | 21 +++++++++++++--- ripngd/ripngd.c | 2 +- ripngd/ripngd.h | 4 ++- 6 files changed, 57 insertions(+), 48 deletions(-) diff --git a/ripngd/ripng_cli.c b/ripngd/ripng_cli.c index 1eb31a0ce6..7d90867f11 100644 --- a/ripngd/ripng_cli.c +++ b/ripngd/ripng_cli.c @@ -246,6 +246,29 @@ void cli_show_ripng_offset_list(struct vty *vty, struct lyd_node *dnode, vty_out(vty, "\n"); } +/* + * XPath: /frr-ripngd:ripngd/instance/passive-interface + */ +DEFPY (ripng_passive_interface, + ripng_passive_interface_cmd, + "[no] passive-interface IFNAME", + NO_STR + "Suppress routing updates on an interface\n" + "Interface name\n") +{ + nb_cli_enqueue_change(vty, "./passive-interface", + no ? NB_OP_DELETE : NB_OP_CREATE, ifname); + + return nb_cli_apply_changes(vty, NULL); +} + +void cli_show_ripng_passive_interface(struct vty *vty, struct lyd_node *dnode, + bool show_defaults) +{ + vty_out(vty, " passive-interface %s\n", + yang_dnode_get_string(dnode, NULL)); +} + void ripng_cli_init(void) { install_element(CONFIG_NODE, &router_ripng_cmd); @@ -258,4 +281,5 @@ void ripng_cli_init(void) install_element(RIPNG_NODE, &ripng_network_prefix_cmd); install_element(RIPNG_NODE, &ripng_network_if_cmd); install_element(RIPNG_NODE, &ripng_offset_list_cmd); + install_element(RIPNG_NODE, &ripng_passive_interface_cmd); } diff --git a/ripngd/ripng_cli.h b/ripngd/ripng_cli.h index d65241436f..eef3cc2482 100644 --- a/ripngd/ripng_cli.h +++ b/ripngd/ripng_cli.h @@ -39,5 +39,8 @@ extern void cli_show_ripng_network_interface(struct vty *vty, bool show_defaults); extern void cli_show_ripng_offset_list(struct vty *vty, struct lyd_node *dnode, bool show_defaults); +extern void cli_show_ripng_passive_interface(struct vty *vty, + struct lyd_node *dnode, + bool show_defaults); #endif /* _FRR_RIPNG_CLI_H_ */ diff --git a/ripngd/ripng_interface.c b/ripngd/ripng_interface.c index 14ca3a5907..25d3b2e16d 100644 --- a/ripngd/ripng_interface.c +++ b/ripngd/ripng_interface.c @@ -831,26 +831,26 @@ static void ripng_passive_interface_apply_all(void) } /* Passive interface. */ -static int ripng_passive_interface_set(struct vty *vty, const char *ifname) +int ripng_passive_interface_set(const char *ifname) { if (ripng_passive_interface_lookup(ifname) >= 0) - return CMD_WARNING_CONFIG_FAILED; + return NB_ERR_INCONSISTENCY; vector_set(Vripng_passive_interface, strdup(ifname)); ripng_passive_interface_apply_all(); - return CMD_SUCCESS; + return NB_OK; } -static int ripng_passive_interface_unset(struct vty *vty, const char *ifname) +int ripng_passive_interface_unset(const char *ifname) { int i; char *str; i = ripng_passive_interface_lookup(ifname); if (i < 0) - return CMD_WARNING_CONFIG_FAILED; + return NB_ERR_INCONSISTENCY; str = vector_slot(Vripng_passive_interface, i); free(str); @@ -858,7 +858,7 @@ static int ripng_passive_interface_unset(struct vty *vty, const char *ifname) ripng_passive_interface_apply_all(); - return CMD_SUCCESS; + return NB_OK; } /* Free all configured RIP passive-interface settings. */ @@ -876,7 +876,7 @@ void ripng_passive_interface_clean(void) } /* Write RIPng enable network and interface to the vty. */ -int ripng_network_write(struct vty *vty, int config_mode) +int ripng_network_write(struct vty *vty) { unsigned int i; const char *ifname; @@ -888,8 +888,7 @@ int ripng_network_write(struct vty *vty, int config_mode) node = agg_route_next(node)) if (node->info) { struct prefix *p = &node->p; - vty_out(vty, "%s%s/%d\n", - config_mode ? " network " : " ", + vty_out(vty, " %s/%d\n", inet_ntop(p->family, &p->u.prefix, buf, BUFSIZ), p->prefixlen); } @@ -897,15 +896,7 @@ int ripng_network_write(struct vty *vty, int config_mode) /* Write enable interface. */ for (i = 0; i < vector_active(ripng_enable_if); i++) if ((ifname = vector_slot(ripng_enable_if, i)) != NULL) - vty_out(vty, "%s%s\n", - config_mode ? " network " : " ", ifname); - - /* Write passive interface. */ - if (config_mode) - for (i = 0; i < vector_active(Vripng_passive_interface); i++) - if ((ifname = vector_slot(Vripng_passive_interface, i)) - != NULL) - vty_out(vty, " passive-interface %s\n", ifname); + vty_out(vty, " %s\n", ifname); return 0; } @@ -961,27 +952,6 @@ DEFUN (no_ipv6_ripng_split_horizon, return CMD_SUCCESS; } -DEFUN (ripng_passive_interface, - ripng_passive_interface_cmd, - "passive-interface IFNAME", - "Suppress routing updates on an interface\n" - "Interface name\n") -{ - int idx_ifname = 1; - return ripng_passive_interface_set(vty, argv[idx_ifname]->arg); -} - -DEFUN (no_ripng_passive_interface, - no_ripng_passive_interface_cmd, - "no passive-interface IFNAME", - NO_STR - "Suppress routing updates on an interface\n" - "Interface name\n") -{ - int idx_ifname = 2; - return ripng_passive_interface_unset(vty, argv[idx_ifname]->arg); -} - static struct ripng_interface *ri_new(void) { struct ripng_interface *ri; @@ -1082,9 +1052,6 @@ void ripng_if_init() install_node(&interface_node, interface_config_write); if_cmd_init(); - install_element(RIPNG_NODE, &ripng_passive_interface_cmd); - install_element(RIPNG_NODE, &no_ripng_passive_interface_cmd); - install_element(INTERFACE_NODE, &ipv6_ripng_split_horizon_cmd); install_element(INTERFACE_NODE, &ipv6_ripng_split_horizon_poisoned_reverse_cmd); diff --git a/ripngd/ripng_northbound.c b/ripngd/ripng_northbound.c index 614259a7b4..0b2948b5d6 100644 --- a/ripngd/ripng_northbound.c +++ b/ripngd/ripng_northbound.c @@ -297,16 +297,28 @@ ripngd_instance_passive_interface_create(enum nb_event event, const struct lyd_node *dnode, union nb_resource *resource) { - /* TODO: implement me. */ - return NB_OK; + const char *ifname; + + if (event != NB_EV_APPLY) + return NB_OK; + + ifname = yang_dnode_get_string(dnode, NULL); + + return ripng_passive_interface_set(ifname); } static int ripngd_instance_passive_interface_delete(enum nb_event event, const struct lyd_node *dnode) { - /* TODO: implement me. */ - return NB_OK; + const char *ifname; + + if (event != NB_EV_APPLY) + return NB_OK; + + ifname = yang_dnode_get_string(dnode, NULL); + + return ripng_passive_interface_unset(ifname); } /* @@ -658,6 +670,7 @@ const struct frr_yang_module_info frr_ripngd_info = { .xpath = "/frr-ripngd:ripngd/instance/passive-interface", .cbs.create = ripngd_instance_passive_interface_create, .cbs.delete = ripngd_instance_passive_interface_delete, + .cbs.cli_show = cli_show_ripng_passive_interface, }, { .xpath = "/frr-ripngd:ripngd/instance/redistribute", diff --git a/ripngd/ripngd.c b/ripngd/ripngd.c index f6aa49f663..19be43703f 100644 --- a/ripngd/ripngd.c +++ b/ripngd/ripngd.c @@ -2103,7 +2103,7 @@ DEFUN (show_ipv6_ripng_status, } vty_out(vty, " Routing for Networks:\n"); - ripng_network_write(vty, 0); + ripng_network_write(vty); vty_out(vty, " Routing Information Sources:\n"); vty_out(vty, diff --git a/ripngd/ripngd.h b/ripngd/ripngd.h index fd2ae4ad32..78215d0edd 100644 --- a/ripngd/ripngd.h +++ b/ripngd/ripngd.h @@ -355,6 +355,8 @@ extern int ripng_enable_network_add(struct prefix *p); extern int ripng_enable_network_delete(struct prefix *p); extern int ripng_enable_if_add(const char *ifname); extern int ripng_enable_if_delete(const char *ifname); +extern int ripng_passive_interface_set(const char *ifname); +extern int ripng_passive_interface_unset(const char *ifname); extern void ripng_passive_interface_clean(void); extern void ripng_if_init(void); extern void ripng_route_map_init(void); @@ -429,7 +431,7 @@ extern int ripng_interface_address_delete(int command, struct zclient *, extern int ripng_create(int socket); extern int ripng_make_socket(void); -extern int ripng_network_write(struct vty *, int); +extern int ripng_network_write(struct vty *); extern struct ripng_info *ripng_ecmp_add(struct ripng_info *); extern struct ripng_info *ripng_ecmp_replace(struct ripng_info *); -- 2.39.5