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 <renato@opensourcerouting.org>
This commit is contained in:
Renato Westphal 2019-01-04 19:08:10 -02:00
parent 80cf4e451d
commit c5b2b5f65c
3 changed files with 61 additions and 12 deletions

View File

@ -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)

View File

@ -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;
}

View File

@ -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.";
}
}
}
}