]> git.proxmox.com Git - mirror_frr.git/commitdiff
ripd: retrofit the 'network' command to the new northbound model
authorRenato Westphal <renato@opensourcerouting.org>
Wed, 9 May 2018 04:35:00 +0000 (01:35 -0300)
committerRenato Westphal <renato@opensourcerouting.org>
Sat, 27 Oct 2018 18:16:12 +0000 (16:16 -0200)
The frr-ripd YANG module models the ripd "network" command using two
separate leaf-lists for simplicity: one leaf-list for interfaces and
another leaf-list for actual networks. In the 'cli_show' callbacks,
display the "network" command for entries of both leaf-lists.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
ripd/rip_cli.c
ripd/rip_cli.h
ripd/rip_interface.c
ripd/rip_northbound.c
ripd/ripd.c
ripd/ripd.h

index 1d94d02bd7b548bb22d8cae4646d80cc0b0f080e..a22f3054a621f613b07f3d2f8226749b3892233d 100644 (file)
@@ -331,6 +331,60 @@ void cli_show_rip_neighbor(struct vty *vty, struct lyd_node *dnode,
        vty_out(vty, " neighbor %s\n", yang_dnode_get_string(dnode, NULL));
 }
 
+/*
+ * XPath: /frr-ripd:ripd/instance/network
+ */
+DEFPY (rip_network_prefix,
+       rip_network_prefix_cmd,
+       "[no] network A.B.C.D/M",
+       NO_STR
+       "Enable routing on an IP network\n"
+       "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
+{
+       struct cli_config_change changes[] = {
+               {
+                       .xpath = "./network",
+                       .operation = no ? NB_OP_DELETE : NB_OP_CREATE,
+                       .value = network_str,
+               },
+       };
+
+       return nb_cli_cfg_change(vty, NULL, changes, array_size(changes));
+}
+
+void cli_show_rip_network_prefix(struct vty *vty, struct lyd_node *dnode,
+                                bool show_defaults)
+{
+       vty_out(vty, " network %s\n", yang_dnode_get_string(dnode, NULL));
+}
+
+/*
+ * XPath: /frr-ripd:ripd/instance/interface
+ */
+DEFPY (rip_network_if,
+       rip_network_if_cmd,
+       "[no] network WORD",
+       NO_STR
+       "Enable routing on an IP network\n"
+       "Interface name\n")
+{
+       struct cli_config_change changes[] = {
+               {
+                       .xpath = "./interface",
+                       .operation = no ? NB_OP_DELETE : NB_OP_CREATE,
+                       .value = network,
+               },
+       };
+
+       return nb_cli_cfg_change(vty, NULL, changes, array_size(changes));
+}
+
+void cli_show_rip_network_interface(struct vty *vty, struct lyd_node *dnode,
+                                   bool show_defaults)
+{
+       vty_out(vty, " network %s\n", yang_dnode_get_string(dnode, NULL));
+}
+
 void rip_cli_init(void)
 {
        install_element(CONFIG_NODE, &router_rip_cmd);
@@ -345,4 +399,6 @@ void rip_cli_init(void)
        install_element(RIP_NODE, &rip_distance_source_cmd);
        install_element(RIP_NODE, &no_rip_distance_source_cmd);
        install_element(RIP_NODE, &rip_neighbor_cmd);
+       install_element(RIP_NODE, &rip_network_prefix_cmd);
+       install_element(RIP_NODE, &rip_network_if_cmd);
 }
index 34cbd646fb9f6b9c24fc4ba3178fc806af456d14..2a054059240a58e8926ae4764cabaf541dd25dcc 100644 (file)
@@ -37,5 +37,10 @@ extern void cli_show_rip_distance_source(struct vty *vty,
                                         bool show_defaults);
 extern void cli_show_rip_neighbor(struct vty *vty, struct lyd_node *dnode,
                                  bool show_defaults);
+extern void cli_show_rip_network_prefix(struct vty *vty, struct lyd_node *dnode,
+                                       bool show_defaults);
+extern void cli_show_rip_network_interface(struct vty *vty,
+                                          struct lyd_node *dnode,
+                                          bool show_defaults);
 
 #endif /* _FRR_RIP_CLI_H_ */
index 4373484a293b22129018932b5549508ceb74343e..1e79e6d275ca4d3d64bb5320ab65fcad97a9e96c 100644 (file)
@@ -762,7 +762,7 @@ int rip_enable_network_lookup2(struct connected *connected)
        return -1;
 }
 /* Add RIP enable network. */
-static int rip_enable_network_add(struct prefix *p)
+int rip_enable_network_add(struct prefix *p)
 {
        struct route_node *node;
 
@@ -770,18 +770,18 @@ static int rip_enable_network_add(struct prefix *p)
 
        if (node->info) {
                route_unlock_node(node);
-               return -1;
+               return NB_ERR_INCONSISTENCY;
        } else
                node->info = (void *)1;
 
        /* XXX: One should find a better solution than a generic one */
        rip_enable_apply_all();
 
-       return 1;
+       return NB_OK;
 }
 
 /* Delete RIP enable network. */
-static int rip_enable_network_delete(struct prefix *p)
+int rip_enable_network_delete(struct prefix *p)
 {
        struct route_node *node;
 
@@ -798,9 +798,10 @@ static int rip_enable_network_delete(struct prefix *p)
                /* XXX: One should find a better solution than a generic one */
                rip_enable_apply_all();
 
-               return 1;
+               return NB_OK;
        }
-       return -1;
+
+       return NB_ERR_INCONSISTENCY;
 }
 
 /* Check interface is enabled by ifname statement. */
@@ -817,31 +818,31 @@ static int rip_enable_if_lookup(const char *ifname)
 }
 
 /* Add interface to rip_enable_if. */
-static int rip_enable_if_add(const char *ifname)
+int rip_enable_if_add(const char *ifname)
 {
        int ret;
 
        ret = rip_enable_if_lookup(ifname);
        if (ret >= 0)
-               return -1;
+               return NB_ERR_INCONSISTENCY;
 
        vector_set(rip_enable_interface,
                   XSTRDUP(MTYPE_RIP_INTERFACE_STRING, ifname));
 
        rip_enable_apply_all(); /* TODOVJ */
 
-       return 1;
+       return NB_OK;
 }
 
 /* Delete interface from rip_enable_if. */
-static int rip_enable_if_delete(const char *ifname)
+int rip_enable_if_delete(const char *ifname)
 {
        int index;
        char *str;
 
        index = rip_enable_if_lookup(ifname);
        if (index < 0)
-               return -1;
+               return NB_ERR_INCONSISTENCY;
 
        str = vector_slot(rip_enable_interface, index);
        XFREE(MTYPE_RIP_INTERFACE_STRING, str);
@@ -849,7 +850,7 @@ static int rip_enable_if_delete(const char *ifname)
 
        rip_enable_apply_all(); /* TODOVJ */
 
-       return 1;
+       return NB_OK;
 }
 
 /* Join to multicast group and send request to the interface. */
@@ -1152,63 +1153,6 @@ void rip_passive_nondefault_clean(void)
        rip_passive_interface_apply_all();
 }
 
-/* RIP enable network or interface configuration. */
-DEFUN (rip_network,
-       rip_network_cmd,
-       "network <A.B.C.D/M|WORD>",
-       "Enable routing on an IP network\n"
-       "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
-       "Interface name\n")
-{
-       int idx_ipv4_word = 1;
-       int ret;
-       struct prefix_ipv4 p;
-
-       ret = str2prefix_ipv4(argv[idx_ipv4_word]->arg, &p);
-
-       if (ret)
-               ret = rip_enable_network_add((struct prefix *)&p);
-       else
-               ret = rip_enable_if_add(argv[idx_ipv4_word]->arg);
-
-       if (ret < 0) {
-               vty_out(vty, "There is a same network configuration %s\n",
-                       argv[idx_ipv4_word]->arg);
-               return CMD_WARNING_CONFIG_FAILED;
-       }
-
-       return CMD_SUCCESS;
-}
-
-/* RIP enable network or interface configuration. */
-DEFUN (no_rip_network,
-       no_rip_network_cmd,
-       "no network <A.B.C.D/M|WORD>",
-       NO_STR
-       "Enable routing on an IP network\n"
-       "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
-       "Interface name\n")
-{
-       int idx_ipv4_word = 2;
-       int ret;
-       struct prefix_ipv4 p;
-
-       ret = str2prefix_ipv4(argv[idx_ipv4_word]->arg, &p);
-
-       if (ret)
-               ret = rip_enable_network_delete((struct prefix *)&p);
-       else
-               ret = rip_enable_if_delete(argv[idx_ipv4_word]->arg);
-
-       if (ret < 0) {
-               vty_out(vty, "Can't find network configuration %s\n",
-                       argv[idx_ipv4_word]->arg);
-               return CMD_WARNING_CONFIG_FAILED;
-       }
-
-       return CMD_SUCCESS;
-}
-
 DEFUN (ip_rip_receive_version,
        ip_rip_receive_version_cmd,
        "ip rip receive version <(1-2)|none>",
@@ -1848,9 +1792,6 @@ void rip_if_init(void)
        if_cmd_init();
 
        /* Install commands. */
-       install_element(RIP_NODE, &rip_network_cmd);
-       install_element(RIP_NODE, &no_rip_network_cmd);
-
        install_element(RIP_NODE, &rip_passive_interface_cmd);
        install_element(RIP_NODE, &no_rip_passive_interface_cmd);
 
index fdb19a3c14f552fa12728ad222931524a284b8de..498aa322cbc88a238bb34cd82e4f561b99c50757 100644 (file)
@@ -310,15 +310,27 @@ static int ripd_instance_network_create(enum nb_event event,
                                        const struct lyd_node *dnode,
                                        union nb_resource *resource)
 {
-       /* TODO: implement me. */
-       return NB_OK;
+       struct prefix p;
+
+       if (event != NB_EV_APPLY)
+               return NB_OK;
+
+       yang_dnode_get_ipv4p(&p, dnode, NULL);
+
+       return rip_enable_network_add(&p);
 }
 
 static int ripd_instance_network_delete(enum nb_event event,
                                        const struct lyd_node *dnode)
 {
-       /* TODO: implement me. */
-       return NB_OK;
+       struct prefix p;
+
+       if (event != NB_EV_APPLY)
+               return NB_OK;
+
+       yang_dnode_get_ipv4p(&p, dnode, NULL);
+
+       return rip_enable_network_delete(&p);
 }
 
 /*
@@ -328,15 +340,27 @@ static int ripd_instance_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 rip_enable_if_add(ifname);
 }
 
 static int ripd_instance_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 rip_enable_if_delete(ifname);
 }
 
 /*
@@ -880,11 +904,13 @@ const struct frr_yang_module_info frr_ripd_info = {
                        .xpath = "/frr-ripd:ripd/instance/network",
                        .cbs.create = ripd_instance_network_create,
                        .cbs.delete = ripd_instance_network_delete,
+                       .cbs.cli_show = cli_show_rip_network_prefix,
                },
                {
                        .xpath = "/frr-ripd:ripd/instance/interface",
                        .cbs.create = ripd_instance_interface_create,
                        .cbs.delete = ripd_instance_interface_delete,
+                       .cbs.cli_show = cli_show_rip_network_interface,
                },
                {
                        .xpath = "/frr-ripd:ripd/instance/offset-list",
index 4dbb47ebd235ac496ff65a4e92ecf4d65c5d1728..027ad878bb3afb6d66f8011bcf628bfd185c722f 100644 (file)
@@ -3415,9 +3415,6 @@ static int config_write_rip(struct vty *vty)
                /* RIP offset-list configuration. */
                config_write_rip_offset_list(vty);
 
-               /* RIP enabled network and interface configuration. */
-               config_write_rip_network(vty, 1);
-
                /* Distribute configuration. */
                write += config_write_distribute(vty);
 
index fd8762904f17d1c8b2d266b04debf30f84369928..9bd9f53f2263181a3b79a1f7d54dd1cd8f22e5c4 100644 (file)
@@ -392,6 +392,11 @@ extern int rip_neighbor_lookup(struct sockaddr_in *);
 extern int rip_neighbor_add(struct prefix_ipv4 *p);
 extern int rip_neighbor_delete(struct prefix_ipv4 *p);
 
+extern int rip_enable_network_add(struct prefix *p);
+extern int rip_enable_network_delete(struct prefix *p);
+extern int rip_enable_if_add(const char *ifname);
+extern int rip_enable_if_delete(const char *ifname);
+
 extern void rip_ecmp_disable(void);
 
 extern int rip_create_socket(void);