]>
Commit | Line | Data |
---|---|---|
f80ec39e RW |
1 | /* |
2 | * Copyright (C) 2018 NetDEF, Inc. | |
3 | * Renato Westphal | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU General Public License as published by the Free | |
7 | * Software Foundation; either version 2 of the License, or (at your option) | |
8 | * any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
13 | * more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License along | |
16 | * with this program; see the file COPYING; if not, write to the Free Software | |
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
18 | */ | |
19 | ||
20 | #include <zebra.h> | |
21 | ||
22 | #include "if.h" | |
23 | #include "vrf.h" | |
24 | #include "log.h" | |
25 | #include "prefix.h" | |
26 | #include "table.h" | |
27 | #include "command.h" | |
28 | #include "routemap.h" | |
29 | #include "northbound.h" | |
30 | #include "libfrr.h" | |
31 | ||
32 | #include "ripd/ripd.h" | |
33 | #include "ripd/rip_nb.h" | |
34 | #include "ripd/rip_debug.h" | |
35 | #include "ripd/rip_interface.h" | |
36 | ||
37 | /* | |
38 | * XPath: /frr-ripd:clear-rip-route | |
39 | */ | |
40 | static void clear_rip_route(struct rip *rip) | |
41 | { | |
42 | struct route_node *rp; | |
43 | ||
44 | if (IS_RIP_DEBUG_EVENT) | |
45 | zlog_debug("Clearing all RIP routes (VRF %s)", rip->vrf_name); | |
46 | ||
47 | /* Clear received RIP routes */ | |
48 | for (rp = route_top(rip->table); rp; rp = route_next(rp)) { | |
49 | struct list *list; | |
50 | struct listnode *listnode; | |
51 | struct rip_info *rinfo; | |
52 | ||
53 | list = rp->info; | |
54 | if (!list) | |
55 | continue; | |
56 | ||
57 | for (ALL_LIST_ELEMENTS_RO(list, listnode, rinfo)) { | |
58 | if (!rip_route_rte(rinfo)) | |
59 | continue; | |
60 | ||
61 | if (CHECK_FLAG(rinfo->flags, RIP_RTF_FIB)) | |
62 | rip_zebra_ipv4_delete(rip, rp); | |
63 | break; | |
64 | } | |
65 | ||
66 | if (rinfo) { | |
67 | RIP_TIMER_OFF(rinfo->t_timeout); | |
68 | RIP_TIMER_OFF(rinfo->t_garbage_collect); | |
69 | listnode_delete(list, rinfo); | |
70 | rip_info_free(rinfo); | |
71 | } | |
72 | ||
73 | if (list_isempty(list)) { | |
74 | list_delete(&list); | |
75 | rp->info = NULL; | |
76 | route_unlock_node(rp); | |
77 | } | |
78 | } | |
79 | } | |
80 | ||
81 | int clear_rip_route_rpc(const char *xpath, const struct list *input, | |
82 | struct list *output) | |
83 | { | |
84 | struct rip *rip; | |
85 | struct yang_data *yang_vrf; | |
86 | ||
87 | yang_vrf = yang_data_list_find(input, "%s/%s", xpath, "input/vrf"); | |
88 | if (yang_vrf) { | |
89 | rip = rip_lookup_by_vrf_name(yang_vrf->value); | |
90 | if (rip) | |
91 | clear_rip_route(rip); | |
92 | } else { | |
93 | struct vrf *vrf; | |
94 | ||
95 | RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { | |
96 | rip = vrf->info; | |
97 | if (!rip) | |
98 | continue; | |
99 | ||
100 | clear_rip_route(rip); | |
101 | } | |
102 | } | |
103 | ||
104 | return NB_OK; | |
105 | } |