]> git.proxmox.com Git - mirror_frr.git/commitdiff
ripngd: retrofit the 'passive-interface' command to the new northbound model
authorRenato Westphal <renato@opensourcerouting.org>
Thu, 29 Nov 2018 04:41:57 +0000 (02:41 -0200)
committerRenato Westphal <renato@opensourcerouting.org>
Mon, 3 Dec 2018 15:47:58 +0000 (13:47 -0200)
Trivial conversion.

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.c
ripngd/ripngd.h

index 1eb31a0ce6847cc9a7203abecc193c6f40ec52f4..7d90867f1175f67f379de2326d16b6ff2f5687b8 100644 (file)
@@ -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);
 }
index d65241436ff444dc2a4b2d00afe425ab5b55fdc4..eef3cc248234907dd542d7c7eceac629ca814647 100644 (file)
@@ -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_ */
index 14ca3a5907afd156990c1d141cb85bb0c8e7457a..25d3b2e16d2f3de23eedf01942be57496394cbb0 100644 (file)
@@ -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);
index 614259a7b416e0a8099a0e48778a18ef6a9013d5..0b2948b5d693ef6e217831ff68dc31d08b9f6abe 100644 (file)
@@ -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",
index f6aa49f6634a8c06fd54b5c835ef56b5c577e58f..19be43703f6594fcd103328b06df7409e15e9b90 100644 (file)
@@ -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,
index fd2ae4ad32d74de870f91646d5f23adb63304951..78215d0eddbb1f9beb77cd2eb185a39ee63f8c46 100644 (file)
@@ -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 *);