]> git.proxmox.com Git - mirror_frr.git/commitdiff
ripngd: retrofit the 'split-horizon' command to the new northbound model
authorRenato Westphal <renato@opensourcerouting.org>
Thu, 29 Nov 2018 13:44:55 +0000 (11:44 -0200)
committerRenato Westphal <renato@opensourcerouting.org>
Mon, 3 Dec 2018 15:47:58 +0000 (13:47 -0200)
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
ripngd/ripng_cli.c
ripngd/ripng_cli.h
ripngd/ripng_interface.c
ripngd/ripng_northbound.c
ripngd/ripngd.h

index 2d5c9850452d319df6b3943cd1f51cd0f724a5cc..431c1ee3248585d52c203140727417dcf3d2a50e 100644 (file)
@@ -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);
 }
index 99a67667e7fc1fdf83319f8861928b85b6f14888..d95747e0f8bfd87543bc688c8fc316a5839f9d45 100644 (file)
@@ -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_ */
index 25d3b2e16d2f3de23eedf01942be57496394cbb0..d349b3e094c5cde52e7db73c8d618d3192e61133 100644 (file)
@@ -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);
 }
index 4d1a945b6aa6b249376f9e0f86e372a99ed079a4..040bbf5d70daccf97ae0d2bc4e5cb2ee1fad61ab 100644 (file)
@@ -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,
index a7453d1a1adc2163d4e65000a62b5f33aa14fcdf..3df79541aa283acbe525c6871f0ff137f669bb26 100644 (file)
@@ -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