From: Renato Westphal Date: Thu, 29 Nov 2018 13:44:55 +0000 (-0200) Subject: ripngd: retrofit the 'split-horizon' command to the new northbound model X-Git-Tag: frr-7.1-dev~95^2~7 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=d406db4c87e9347df9e3b105b634159243374d58;p=matthieu%2Ffrr.git ripngd: retrofit the 'split-horizon' command to the new northbound model Signed-off-by: Renato Westphal --- diff --git a/ripngd/ripng_cli.c b/ripngd/ripng_cli.c index 2d5c985045..431c1ee324 100644 --- a/ripngd/ripng_cli.c +++ b/ripngd/ripng_cli.c @@ -406,6 +406,51 @@ void cli_show_ripng_timers(struct vty *vty, struct lyd_node *dnode, yang_dnode_get_string(dnode, "./flush-interval")); } +/* + * XPath: /frr-interface:lib/interface/frr-ripngd:ripng/split-horizon + */ +DEFPY (ipv6_ripng_split_horizon, + ipv6_ripng_split_horizon_cmd, + "[no] ipv6 ripng split-horizon [poisoned-reverse$poisoned_reverse]", + NO_STR + IPV6_STR + "Routing Information Protocol\n" + "Perform split horizon\n" + "With poisoned-reverse\n") +{ + const char *value; + + if (no) + value = "disabled"; + else if (poisoned_reverse) + value = "poison-reverse"; + else + value = "simple"; + + nb_cli_enqueue_change(vty, "./split-horizon", NB_OP_MODIFY, value); + + return nb_cli_apply_changes(vty, "./frr-ripngd:ripng"); +} + +void cli_show_ipv6_ripng_split_horizon(struct vty *vty, struct lyd_node *dnode, + bool show_defaults) +{ + int value; + + value = yang_dnode_get_enum(dnode, NULL); + switch (value) { + case RIPNG_NO_SPLIT_HORIZON: + vty_out(vty, " no ipv6 ripng split-horizon\n"); + break; + case RIPNG_SPLIT_HORIZON: + vty_out(vty, " ipv6 ripng split-horizon\n"); + break; + case RIPNG_SPLIT_HORIZON_POISONED_REVERSE: + vty_out(vty, " ipv6 ripng split-horizon poisoned-reverse\n"); + break; + } +} + void ripng_cli_init(void) { install_element(CONFIG_NODE, &router_ripng_cmd); @@ -424,4 +469,6 @@ void ripng_cli_init(void) install_element(RIPNG_NODE, &ripng_aggregate_address_cmd); install_element(RIPNG_NODE, &ripng_timers_cmd); install_element(RIPNG_NODE, &no_ripng_timers_cmd); + + install_element(INTERFACE_NODE, &ipv6_ripng_split_horizon_cmd); } diff --git a/ripngd/ripng_cli.h b/ripngd/ripng_cli.h index 99a67667e7..d95747e0f8 100644 --- a/ripngd/ripng_cli.h +++ b/ripngd/ripng_cli.h @@ -51,5 +51,8 @@ extern void cli_show_ripng_aggregate_address(struct vty *vty, bool show_defaults); extern void cli_show_ripng_timers(struct vty *vty, struct lyd_node *dnode, bool show_defaults); +extern void cli_show_ipv6_ripng_split_horizon(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 25d3b2e16d..d349b3e094 100644 --- a/ripngd/ripng_interface.c +++ b/ripngd/ripng_interface.c @@ -36,6 +36,7 @@ #include "privs.h" #include "vrf.h" #include "lib_errors.h" +#include "northbound_cli.h" #include "ripngd/ripngd.h" #include "ripngd/ripng_debug.h" @@ -336,8 +337,8 @@ void ripng_interface_reset(void) ri->enable_interface = 0; ri->running = 0; - ri->split_horizon = RIPNG_NO_SPLIT_HORIZON; - ri->split_horizon_default = RIPNG_NO_SPLIT_HORIZON; + ri->split_horizon = + yang_get_default_enum("%s/split-horizon", RIPNG_IFACE); ri->list[RIPNG_FILTER_IN] = NULL; ri->list[RIPNG_FILTER_OUT] = NULL; @@ -901,57 +902,6 @@ int ripng_network_write(struct vty *vty) return 0; } -DEFUN (ipv6_ripng_split_horizon, - ipv6_ripng_split_horizon_cmd, - "ipv6 ripng split-horizon", - IPV6_STR - "Routing Information Protocol\n" - "Perform split horizon\n") -{ - VTY_DECLVAR_CONTEXT(interface, ifp); - struct ripng_interface *ri; - - ri = ifp->info; - - ri->split_horizon = RIPNG_SPLIT_HORIZON; - return CMD_SUCCESS; -} - -DEFUN (ipv6_ripng_split_horizon_poisoned_reverse, - ipv6_ripng_split_horizon_poisoned_reverse_cmd, - "ipv6 ripng split-horizon poisoned-reverse", - IPV6_STR - "Routing Information Protocol\n" - "Perform split horizon\n" - "With poisoned-reverse\n") -{ - VTY_DECLVAR_CONTEXT(interface, ifp); - struct ripng_interface *ri; - - ri = ifp->info; - - ri->split_horizon = RIPNG_SPLIT_HORIZON_POISONED_REVERSE; - return CMD_SUCCESS; -} - -DEFUN (no_ipv6_ripng_split_horizon, - no_ipv6_ripng_split_horizon_cmd, - "no ipv6 ripng split-horizon [poisoned-reverse]", - NO_STR - IPV6_STR - "Routing Information Protocol\n" - "Perform split horizon\n" - "With poisoned-reverse\n") -{ - VTY_DECLVAR_CONTEXT(interface, ifp); - struct ripng_interface *ri; - - ri = ifp->info; - - ri->split_horizon = RIPNG_NO_SPLIT_HORIZON; - return CMD_SUCCESS; -} - static struct ripng_interface *ri_new(void) { struct ripng_interface *ri; @@ -961,8 +911,8 @@ static struct ripng_interface *ri_new(void) Relay or SMDS is enabled, the default value for split-horizon is off. But currently Zebra does detect Frame Relay or SMDS interface. So all interface is set to split horizon. */ - ri->split_horizon_default = RIPNG_SPLIT_HORIZON; - ri->split_horizon = ri->split_horizon_default; + ri->split_horizon = + yang_get_default_enum("%s/split-horizon", RIPNG_IFACE); return ri; } @@ -986,44 +936,22 @@ static int interface_config_write(struct vty *vty) { struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; - struct ripng_interface *ri; int write = 0; FOR_ALL_INTERFACES (vrf, ifp) { - ri = ifp->info; + struct lyd_node *dnode; - /* Do not display the interface if there is no - * configuration about it. - **/ - if ((!ifp->desc) - && (ri->split_horizon == ri->split_horizon_default)) + dnode = yang_dnode_get( + running_config->dnode, + "/frr-interface:lib/interface[name='%s'][vrf='%s']", + ifp->name, vrf->name); + if (dnode == NULL) continue; - vty_frame(vty, "interface %s\n", ifp->name); - if (ifp->desc) - vty_out(vty, " description %s\n", ifp->desc); - - /* Split horizon. */ - if (ri->split_horizon != ri->split_horizon_default) { - switch (ri->split_horizon) { - case RIPNG_SPLIT_HORIZON: - vty_out(vty, " ipv6 ripng split-horizon\n"); - break; - case RIPNG_SPLIT_HORIZON_POISONED_REVERSE: - vty_out(vty, - " ipv6 ripng split-horizon poisoned-reverse\n"); - break; - case RIPNG_NO_SPLIT_HORIZON: - default: - vty_out(vty, " no ipv6 ripng split-horizon\n"); - break; - } - } - - vty_endframe(vty, "!\n"); - - write++; + write = 1; + nb_cli_show_dnode_cmds(vty, dnode, false); } + return write; } @@ -1051,9 +979,4 @@ void ripng_if_init() /* Install interface node. */ install_node(&interface_node, interface_config_write); if_cmd_init(); - - install_element(INTERFACE_NODE, &ipv6_ripng_split_horizon_cmd); - install_element(INTERFACE_NODE, - &ipv6_ripng_split_horizon_poisoned_reverse_cmd); - install_element(INTERFACE_NODE, &no_ipv6_ripng_split_horizon_cmd); } diff --git a/ripngd/ripng_northbound.c b/ripngd/ripng_northbound.c index 4d1a945b6a..040bbf5d70 100644 --- a/ripngd/ripng_northbound.c +++ b/ripngd/ripng_northbound.c @@ -729,7 +729,16 @@ lib_interface_ripng_split_horizon_modify(enum nb_event event, const struct lyd_node *dnode, union nb_resource *resource) { - /* TODO: implement me. */ + struct interface *ifp; + struct ripng_interface *ri; + + if (event != NB_EV_APPLY) + return NB_OK; + + ifp = yang_dnode_get_entry(dnode, true); + ri = ifp->info; + ri->split_horizon = yang_dnode_get_enum(dnode, NULL); + return NB_OK; } @@ -887,6 +896,7 @@ const struct frr_yang_module_info frr_ripngd_info = { { .xpath = "/frr-interface:lib/interface/frr-ripngd:ripng/split-horizon", .cbs.modify = lib_interface_ripng_split_horizon_modify, + .cbs.cli_show = cli_show_ipv6_ripng_split_horizon, }, { .xpath = NULL, diff --git a/ripngd/ripngd.h b/ripngd/ripngd.h index a7453d1a1a..3df79541aa 100644 --- a/ripngd/ripngd.h +++ b/ripngd/ripngd.h @@ -236,7 +236,6 @@ struct ripng_interface { /* Split horizon flag. */ split_horizon_policy_t split_horizon; - split_horizon_policy_t split_horizon_default; /* For filter type slot. */ #define RIPNG_FILTER_IN 0