]> git.puffer.fish Git - matthieu/frr.git/commitdiff
ripd: add vrf input parameter to the "clear-rip-route" RPC
authorRenato Westphal <renato@opensourcerouting.org>
Fri, 4 Jan 2019 21:08:10 +0000 (19:08 -0200)
committerRenato Westphal <renato@opensourcerouting.org>
Fri, 18 Jan 2019 18:15:41 +0000 (16:15 -0200)
Description of the new parameter (adapted from the ietf-rip module):

  "VRF name identifying a specific RIP instance.
   This leaf is optional for the rpc.
   If it is specified, the rpc will clear all routes in the
   specified RIP instance;
   if it is not specified, the rpc will clear all routes in
   all RIP instances.";

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

index be24d04ff37eb4563803cb695fb7f62aed95fb19..6e5c01b6db36e94e28ff229f682aa4a24072123d 100644 (file)
@@ -983,12 +983,24 @@ void cli_show_ip_rip_authentication_key_chain(struct vty *vty,
  */
 DEFPY (clear_ip_rip,
        clear_ip_rip_cmd,
-       "clear ip rip",
+       "clear ip rip [vrf WORD]",
        CLEAR_STR
        IP_STR
-       "Clear IP RIP database\n")
+       "Clear IP RIP database\n"
+       VRF_CMD_HELP_STR)
 {
-       return nb_cli_rpc("/frr-ripd:clear-rip-route", NULL, NULL);
+       struct list *input;
+
+       input = list_new();
+       if (vrf) {
+               struct yang_data *yang_vrf;
+
+               yang_vrf = yang_data_new("/frr-ripd:clear-rip-route/input/vrf",
+                                        vrf);
+               listnode_add(input, yang_vrf);
+       }
+
+       return nb_cli_rpc("/frr-ripd:clear-rip-route", input, NULL);
 }
 
 void rip_cli_init(void)
index 1bdb2341e4229a95981c604b30bc4957f7e1874e..d2360c470ce4fbf3351e26a00ead9af9f6ba428f 100644 (file)
@@ -31,6 +31,7 @@
 #include "libfrr.h"
 
 #include "ripd/ripd.h"
+#include "ripd/rip_debug.h"
 #include "ripd/rip_cli.h"
 
 /*
@@ -1351,21 +1352,19 @@ ripd_instance_state_routes_route_metric_get_elem(const char *xpath,
 /*
  * XPath: /frr-ripd:clear-rip-route
  */
-static int clear_rip_route_rpc(const char *xpath, const struct list *input,
-                              struct list *output)
+static void clear_rip_route(struct rip *rip)
 {
-       struct rip *rip;
        struct route_node *rp;
-       struct rip_info *rinfo;
-       struct list *list;
-       struct listnode *listnode;
 
-       rip = rip_lookup_by_vrf_id(VRF_DEFAULT);
-       if (!rip)
-               return NB_OK;
+       if (IS_RIP_DEBUG_EVENT)
+               zlog_debug("Clearing all RIP routes (VRF %s)", rip->vrf_name);
 
        /* Clear received RIP routes */
        for (rp = route_top(rip->table); rp; rp = route_next(rp)) {
+               struct list *list;
+               struct listnode *listnode;
+               struct rip_info *rinfo;
+
                list = rp->info;
                if (!list)
                        continue;
@@ -1392,6 +1391,30 @@ static int clear_rip_route_rpc(const char *xpath, const struct list *input,
                        route_unlock_node(rp);
                }
        }
+}
+
+static int clear_rip_route_rpc(const char *xpath, const struct list *input,
+                              struct list *output)
+{
+       struct rip *rip;
+       struct yang_data *yang_vrf;
+
+       yang_vrf = yang_data_list_find(input, "%s/%s", xpath, "input/vrf");
+       if (yang_vrf) {
+               rip = rip_lookup_by_vrf_name(yang_vrf->value);
+               if (rip)
+                       clear_rip_route(rip);
+       } else {
+               struct vrf *vrf;
+
+               RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
+                       rip = vrf->info;
+                       if (!rip)
+                               continue;
+
+                       clear_rip_route(rip);
+               }
+       }
 
        return NB_OK;
 }
index e9f2fe0e997851f1899f2599a7e21ba53e3d18bf..07690793f0343c22d20bba79777f47fc8aeba332 100644 (file)
@@ -552,6 +552,19 @@ module frr-ripd {
     description
       "Clears RIP routes from the IP routing table and routes
        redistributed into the RIP protocol.";
+
+    input {
+      leaf vrf {
+        type string;
+        description
+          "VRF name identifying a specific RIP instance.
+           This leaf is optional for the rpc.
+           If it is specified, the rpc will clear all routes in the
+           specified RIP instance;
+           if it is not specified, the rpc will clear all routes in
+           all RIP instances.";
+      }
+    }
   }
 
   /*