From 14f17e6362fdc36428883c8557df6c681c9bceb4 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Fri, 4 Jan 2019 19:08:10 -0200 Subject: [PATCH] ripd: add vrf input parameter to the "clear-rip-route" RPC 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 --- ripd/rip_cli.c | 18 +++++++++++++++--- ripd/rip_northbound.c | 41 ++++++++++++++++++++++++++++++++--------- yang/frr-ripd.yang | 13 +++++++++++++ 3 files changed, 60 insertions(+), 12 deletions(-) diff --git a/ripd/rip_cli.c b/ripd/rip_cli.c index be24d04ff3..6e5c01b6db 100644 --- a/ripd/rip_cli.c +++ b/ripd/rip_cli.c @@ -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) diff --git a/ripd/rip_northbound.c b/ripd/rip_northbound.c index 1bdb2341e4..d2360c470c 100644 --- a/ripd/rip_northbound.c +++ b/ripd/rip_northbound.c @@ -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; } diff --git a/yang/frr-ripd.yang b/yang/frr-ripd.yang index e9f2fe0e99..07690793f0 100644 --- a/yang/frr-ripd.yang +++ b/yang/frr-ripd.yang @@ -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."; + } + } } /* -- 2.39.5