]>
Commit | Line | Data |
---|---|---|
acddc0ed | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
f80ec39e RW |
2 | /* |
3 | * Copyright (C) 2018 NetDEF, Inc. | |
4 | * Renato Westphal | |
f80ec39e RW |
5 | */ |
6 | ||
7 | #include <zebra.h> | |
8 | ||
9 | #include "if.h" | |
10 | #include "vrf.h" | |
11 | #include "log.h" | |
12 | #include "prefix.h" | |
13 | #include "table.h" | |
14 | #include "command.h" | |
15 | #include "routemap.h" | |
16 | #include "northbound.h" | |
17 | #include "libfrr.h" | |
18 | ||
19 | #include "ripd/ripd.h" | |
20 | #include "ripd/rip_nb.h" | |
21 | #include "ripd/rip_debug.h" | |
22 | #include "ripd/rip_interface.h" | |
23 | ||
24 | /* | |
25 | * XPath: /frr-ripd:clear-rip-route | |
26 | */ | |
27 | static void clear_rip_route(struct rip *rip) | |
28 | { | |
29 | struct route_node *rp; | |
30 | ||
31 | if (IS_RIP_DEBUG_EVENT) | |
32 | zlog_debug("Clearing all RIP routes (VRF %s)", rip->vrf_name); | |
33 | ||
34 | /* Clear received RIP routes */ | |
35 | for (rp = route_top(rip->table); rp; rp = route_next(rp)) { | |
36 | struct list *list; | |
37 | struct listnode *listnode; | |
38 | struct rip_info *rinfo; | |
39 | ||
40 | list = rp->info; | |
41 | if (!list) | |
42 | continue; | |
43 | ||
44 | for (ALL_LIST_ELEMENTS_RO(list, listnode, rinfo)) { | |
45 | if (!rip_route_rte(rinfo)) | |
46 | continue; | |
47 | ||
48 | if (CHECK_FLAG(rinfo->flags, RIP_RTF_FIB)) | |
49 | rip_zebra_ipv4_delete(rip, rp); | |
50 | break; | |
51 | } | |
52 | ||
53 | if (rinfo) { | |
e16d030c DS |
54 | EVENT_OFF(rinfo->t_timeout); |
55 | EVENT_OFF(rinfo->t_garbage_collect); | |
f80ec39e RW |
56 | listnode_delete(list, rinfo); |
57 | rip_info_free(rinfo); | |
58 | } | |
59 | ||
60 | if (list_isempty(list)) { | |
61 | list_delete(&list); | |
62 | rp->info = NULL; | |
63 | route_unlock_node(rp); | |
64 | } | |
65 | } | |
66 | } | |
67 | ||
60ee8be1 | 68 | int clear_rip_route_rpc(struct nb_cb_rpc_args *args) |
f80ec39e RW |
69 | { |
70 | struct rip *rip; | |
71 | struct yang_data *yang_vrf; | |
72 | ||
60ee8be1 RW |
73 | yang_vrf = yang_data_list_find(args->input, "%s/%s", args->xpath, |
74 | "input/vrf"); | |
f80ec39e RW |
75 | if (yang_vrf) { |
76 | rip = rip_lookup_by_vrf_name(yang_vrf->value); | |
77 | if (rip) | |
78 | clear_rip_route(rip); | |
79 | } else { | |
80 | struct vrf *vrf; | |
81 | ||
82 | RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { | |
83 | rip = vrf->info; | |
84 | if (!rip) | |
85 | continue; | |
86 | ||
87 | clear_rip_route(rip); | |
88 | } | |
89 | } | |
90 | ||
91 | return NB_OK; | |
92 | } |