From c5b2b5f65cd76c76f9d1ed1a219b33469f1e8524 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Fri, 4 Jan 2019 19:08:10 -0200 Subject: [PATCH] ripngd: add vrf input parameter to the "clear-ripng-route" RPC Description of the new parameter (adapted from the ietf-rip module): "VRF name identifying a specific RIPng instance. This leaf is optional for the rpc. If it is specified, the rpc will clear all routes in the specified RIPng instance; if it is not specified, the rpc will clear all routes in all RIPng instances."; Signed-off-by: Renato Westphal --- ripngd/ripng_cli.c | 18 ++++++++++++++--- ripngd/ripng_northbound.c | 42 ++++++++++++++++++++++++++++++--------- yang/frr-ripngd.yang | 13 ++++++++++++ 3 files changed, 61 insertions(+), 12 deletions(-) diff --git a/ripngd/ripng_cli.c b/ripngd/ripng_cli.c index c89832d51d..804fa8dea6 100644 --- a/ripngd/ripng_cli.c +++ b/ripngd/ripng_cli.c @@ -478,12 +478,24 @@ void cli_show_ipv6_ripng_split_horizon(struct vty *vty, struct lyd_node *dnode, */ DEFPY (clear_ipv6_rip, clear_ipv6_rip_cmd, - "clear ipv6 ripng", + "clear ipv6 ripng [vrf WORD]", CLEAR_STR IPV6_STR - "Clear IPv6 RIP database\n") + "Clear IPv6 RIP database\n" + VRF_CMD_HELP_STR) { - return nb_cli_rpc("/frr-ripngd:clear-ripng-route", NULL, NULL); + struct list *input; + + input = list_new(); + if (vrf) { + struct yang_data *yang_vrf; + + yang_vrf = yang_data_new( + "/frr-ripngd:clear-ripng-route/input/vrf", vrf); + listnode_add(input, yang_vrf); + } + + return nb_cli_rpc("/frr-ripngd:clear-ripng-route", input, NULL); } void ripng_cli_init(void) diff --git a/ripngd/ripng_northbound.c b/ripngd/ripng_northbound.c index 3a1d528375..4b15a3aef7 100644 --- a/ripngd/ripng_northbound.c +++ b/ripngd/ripng_northbound.c @@ -32,6 +32,7 @@ #include "libfrr.h" #include "ripngd/ripngd.h" +#include "ripngd/ripng_debug.h" #include "ripngd/ripng_route.h" #include "ripngd/ripng_cli.h" @@ -894,21 +895,20 @@ ripngd_instance_state_routes_route_metric_get_elem(const char *xpath, /* * XPath: /frr-ripngd:clear-ripng-route */ -static int clear_ripng_route_rpc(const char *xpath, const struct list *input, - struct list *output) +static void clear_ripng_route(struct ripng *ripng) { - struct ripng *ripng; struct agg_node *rp; - struct ripng_info *rinfo; - struct list *list; - struct listnode *listnode; - ripng = ripng_lookup_by_vrf_id(VRF_DEFAULT); - if (!ripng) - return NB_OK; + if (IS_RIPNG_DEBUG_EVENT) + zlog_debug("Clearing all RIPng routes (VRF %s)", + ripng->vrf_name); /* Clear received RIPng routes */ for (rp = agg_route_top(ripng->table); rp; rp = agg_route_next(rp)) { + struct list *list; + struct listnode *listnode; + struct ripng_info *rinfo; + list = rp->info; if (list == NULL) continue; @@ -935,6 +935,30 @@ static int clear_ripng_route_rpc(const char *xpath, const struct list *input, agg_unlock_node(rp); } } +} + +static int clear_ripng_route_rpc(const char *xpath, const struct list *input, + struct list *output) +{ + struct ripng *ripng; + struct yang_data *yang_vrf; + + yang_vrf = yang_data_list_find(input, "%s/%s", xpath, "input/vrf"); + if (yang_vrf) { + ripng = ripng_lookup_by_vrf_name(yang_vrf->value); + if (ripng) + clear_ripng_route(ripng); + } else { + struct vrf *vrf; + + RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { + ripng = vrf->info; + if (!ripng) + continue; + + clear_ripng_route(ripng); + } + } return NB_OK; } diff --git a/yang/frr-ripngd.yang b/yang/frr-ripngd.yang index 6f7773f8ba..b341b438a4 100644 --- a/yang/frr-ripngd.yang +++ b/yang/frr-ripngd.yang @@ -322,5 +322,18 @@ module frr-ripngd { description "Clears RIPng routes from the IPv6 routing table and routes redistributed into the RIPng protocol."; + + input { + leaf vrf { + type string; + description + "VRF name identifying a specific RIPng instance. + This leaf is optional for the rpc. + If it is specified, the rpc will clear all routes in the + specified RIPng instance; + if it is not specified, the rpc will clear all routes in + all RIPng instances."; + } + } } } -- 2.39.5