]> git.puffer.fish Git - matthieu/frr.git/commitdiff
ripd: retrofit the 'route' command to the new northbound model
authorRenato Westphal <renato@opensourcerouting.org>
Wed, 9 May 2018 04:35:01 +0000 (01:35 -0300)
committerRenato Westphal <renato@opensourcerouting.org>
Sat, 27 Oct 2018 18:16:12 +0000 (16:16 -0200)
Trivial conversion. Remove the rip->route routing table and associated
code because this variable was used only to show the running
configuration.

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

index 4bbec64f174b049b00418b1441a2d295b8128461..00608b0266cf128ae40b85393561c41fefd3c818 100644 (file)
@@ -612,6 +612,33 @@ void cli_show_rip_redistribute(struct vty *vty, struct lyd_node *dnode,
        vty_out(vty, "\n");
 }
 
+/*
+ * XPath: /frr-ripd:ripd/instance/static-route
+ */
+DEFPY (rip_route,
+       rip_route_cmd,
+       "[no] route A.B.C.D/M",
+       NO_STR
+       "RIP static route configuration\n"
+       "IP prefix <network>/<length>\n")
+{
+       struct cli_config_change changes[] = {
+               {
+                       .xpath = "./static-route",
+                       .operation = no ? NB_OP_DELETE : NB_OP_CREATE,
+                       .value = route_str,
+               },
+       };
+
+       return nb_cli_cfg_change(vty, NULL, changes, array_size(changes));
+}
+
+void cli_show_rip_route(struct vty *vty, struct lyd_node *dnode,
+                       bool show_defaults)
+{
+       vty_out(vty, " route %s\n", yang_dnode_get_string(dnode, NULL));
+}
+
 void rip_cli_init(void)
 {
        install_element(CONFIG_NODE, &router_rip_cmd);
@@ -634,4 +661,5 @@ void rip_cli_init(void)
        install_element(RIP_NODE, &rip_passive_interface_cmd);
        install_element(RIP_NODE, &rip_redistribute_cmd);
        install_element(RIP_NODE, &no_rip_redistribute_cmd);
+       install_element(RIP_NODE, &rip_route_cmd);
 }
index 6625a301e1ae71715dab677fbcea8a17cc58863a..3d06cc7a432ca429a751eb22d7aac9b7c86e0adc 100644 (file)
@@ -55,5 +55,7 @@ extern void cli_show_rip_non_passive_interface(struct vty *vty,
                                               bool show_defaults);
 extern void cli_show_rip_redistribute(struct vty *vty, struct lyd_node *dnode,
                                      bool show_defaults);
+extern void cli_show_rip_route(struct vty *vty, struct lyd_node *dnode,
+                              bool show_defaults);
 
 #endif /* _FRR_RIP_CLI_H_ */
index a57e29437349efd291b6222436623b7488e7cc82..ffb4a10c9e6287cf4d3fa2db09a6890f0c0a52c8 100644 (file)
@@ -660,14 +660,34 @@ static int ripd_instance_static_route_create(enum nb_event event,
                                             const struct lyd_node *dnode,
                                             union nb_resource *resource)
 {
-       /* TODO: implement me. */
+       struct nexthop nh;
+       struct prefix_ipv4 p;
+
+       if (event != NB_EV_APPLY)
+               return NB_OK;
+
+       yang_dnode_get_ipv4p(&p, dnode, NULL);
+
+       memset(&nh, 0, sizeof(nh));
+       nh.type = NEXTHOP_TYPE_IPV4;
+       rip_redistribute_add(ZEBRA_ROUTE_RIP, RIP_ROUTE_STATIC, &p, &nh, 0, 0,
+                            0);
+
        return NB_OK;
 }
 
 static int ripd_instance_static_route_delete(enum nb_event event,
                                             const struct lyd_node *dnode)
 {
-       /* TODO: implement me. */
+       struct prefix_ipv4 p;
+
+       if (event != NB_EV_APPLY)
+               return NB_OK;
+
+       yang_dnode_get_ipv4p(&p, dnode, NULL);
+
+       rip_redistribute_delete(ZEBRA_ROUTE_RIP, RIP_ROUTE_STATIC, &p, 0);
+
        return NB_OK;
 }
 
@@ -1106,6 +1126,7 @@ const struct frr_yang_module_info frr_ripd_info = {
                        .xpath = "/frr-ripd:ripd/instance/static-route",
                        .cbs.create = ripd_instance_static_route_create,
                        .cbs.delete = ripd_instance_static_route_delete,
+                       .cbs.cli_show = cli_show_rip_route,
                },
                {
                        .xpath = "/frr-ripd:ripd/instance/timers/flush-interval",
index 26b79e873ce1ac06ac1359d8a396ef38d171a3f2..806d55eb3c2f0ff32879abc217dfa878ed6bd236 100644 (file)
@@ -2689,7 +2689,6 @@ int rip_create(int socket)
 
        /* Initialize RIP routig table. */
        rip->table = route_table_init();
-       rip->route = route_table_init();
        rip->neighbor = route_table_init();
 
        /* Make output stream. */
@@ -2835,82 +2834,6 @@ DEFUN (no_rip_version,
        return CMD_SUCCESS;
 }
 
-
-DEFUN (rip_route,
-       rip_route_cmd,
-       "route A.B.C.D/M",
-       "RIP static route configuration\n"
-       "IP prefix <network>/<length>\n")
-{
-       int idx_ipv4_prefixlen = 1;
-       int ret;
-       struct nexthop nh;
-       struct prefix_ipv4 p;
-       struct route_node *node;
-
-       memset(&nh, 0, sizeof(nh));
-       nh.type = NEXTHOP_TYPE_IPV4;
-
-       ret = str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
-       if (ret < 0) {
-               vty_out(vty, "Malformed address\n");
-               return CMD_WARNING_CONFIG_FAILED;
-       }
-       apply_mask_ipv4(&p);
-
-       /* For router rip configuration. */
-       node = route_node_get(rip->route, (struct prefix *)&p);
-
-       if (node->info) {
-               vty_out(vty, "There is already same static route.\n");
-               route_unlock_node(node);
-               return CMD_WARNING;
-       }
-
-       node->info = (void *)1;
-
-       rip_redistribute_add(ZEBRA_ROUTE_RIP, RIP_ROUTE_STATIC, &p, &nh, 0, 0,
-                            0);
-
-       return CMD_SUCCESS;
-}
-
-DEFUN (no_rip_route,
-       no_rip_route_cmd,
-       "no route A.B.C.D/M",
-       NO_STR
-       "RIP static route configuration\n"
-       "IP prefix <network>/<length>\n")
-{
-       int idx_ipv4_prefixlen = 2;
-       int ret;
-       struct prefix_ipv4 p;
-       struct route_node *node;
-
-       ret = str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
-       if (ret < 0) {
-               vty_out(vty, "Malformed address\n");
-               return CMD_WARNING_CONFIG_FAILED;
-       }
-       apply_mask_ipv4(&p);
-
-       /* For router rip configuration. */
-       node = route_node_lookup(rip->route, (struct prefix *)&p);
-       if (!node) {
-               vty_out(vty, "Can't find route %s.\n",
-                       argv[idx_ipv4_prefixlen]->arg);
-               return CMD_WARNING_CONFIG_FAILED;
-       }
-
-       rip_redistribute_delete(ZEBRA_ROUTE_RIP, RIP_ROUTE_STATIC, &p, 0);
-       route_unlock_node(node);
-
-       node->info = NULL;
-       route_unlock_node(node);
-
-       return CMD_SUCCESS;
-}
-
 #if 0
 static void
 rip_update_default_metric (void)
@@ -3388,7 +3311,6 @@ DEFUN (show_ip_rip_status,
 static int config_write_rip(struct vty *vty)
 {
        int write = 0;
-       struct route_node *rn;
        struct lyd_node *dnode;
 
        dnode = yang_dnode_get(running_config->dnode,
@@ -3416,13 +3338,6 @@ static int config_write_rip(struct vty *vty)
 
                /* Interface routemap configuration */
                write += config_write_if_rmap(vty);
-
-               /* RIP static route configuration. */
-               for (rn = route_top(rip->route); rn; rn = route_next(rn))
-                       if (rn->info)
-                               vty_out(vty, " route %s/%d\n",
-                                       inet_ntoa(rn->p.u.prefix4),
-                                       rn->p.prefixlen);
        }
        return write;
 }
@@ -3558,12 +3473,6 @@ void rip_clean(void)
                }
 
                stream_free(rip->obuf);
-               /* Static RIP route configuration. */
-               for (rp = route_top(rip->route); rp; rp = route_next(rp))
-                       if (rp->info) {
-                               rp->info = NULL;
-                               route_unlock_node(rp);
-                       }
 
                /* RIP neighbor configuration. */
                for (rp = route_top(rip->neighbor); rp; rp = route_next(rp))
@@ -3577,7 +3486,6 @@ void rip_clean(void)
                                free(rip->route_map[i].name);
 
                XFREE(MTYPE_ROUTE_TABLE, rip->table);
-               XFREE(MTYPE_ROUTE_TABLE, rip->route);
                XFREE(MTYPE_ROUTE_TABLE, rip->neighbor);
 
                XFREE(MTYPE_RIP, rip);
@@ -3697,8 +3605,6 @@ void rip_init(void)
        install_element(RIP_NODE, &no_rip_version_cmd);
        install_element(RIP_NODE, &rip_timers_cmd);
        install_element(RIP_NODE, &no_rip_timers_cmd);
-       install_element(RIP_NODE, &rip_route_cmd);
-       install_element(RIP_NODE, &no_rip_route_cmd);
 
        /* Debug related init. */
        rip_debug_init();
index 7a1e3837bd2b08cdc76616c04b6679eb71ff7b6c..5ac2be9abb84a39f0c6670b4792fffb90f719997 100644 (file)
@@ -117,9 +117,6 @@ struct rip {
        /* RIP routing information base. */
        struct route_table *table;
 
-       /* RIP only static routing information. */
-       struct route_table *route;
-
        /* RIP neighbor. */
        struct route_table *neighbor;