Line data Source code
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 0 : static void clear_rip_route(struct rip *rip)
41 : {
42 0 : struct route_node *rp;
43 :
44 0 : if (IS_RIP_DEBUG_EVENT)
45 0 : zlog_debug("Clearing all RIP routes (VRF %s)", rip->vrf_name);
46 :
47 : /* Clear received RIP routes */
48 0 : for (rp = route_top(rip->table); rp; rp = route_next(rp)) {
49 0 : struct list *list;
50 0 : struct listnode *listnode;
51 0 : struct rip_info *rinfo;
52 :
53 0 : list = rp->info;
54 0 : if (!list)
55 0 : continue;
56 :
57 0 : for (ALL_LIST_ELEMENTS_RO(list, listnode, rinfo)) {
58 0 : if (!rip_route_rte(rinfo))
59 0 : continue;
60 :
61 0 : if (CHECK_FLAG(rinfo->flags, RIP_RTF_FIB))
62 0 : rip_zebra_ipv4_delete(rip, rp);
63 : break;
64 : }
65 :
66 0 : if (rinfo) {
67 0 : THREAD_OFF(rinfo->t_timeout);
68 0 : THREAD_OFF(rinfo->t_garbage_collect);
69 0 : listnode_delete(list, rinfo);
70 0 : rip_info_free(rinfo);
71 : }
72 :
73 0 : if (list_isempty(list)) {
74 0 : list_delete(&list);
75 0 : rp->info = NULL;
76 0 : route_unlock_node(rp);
77 : }
78 : }
79 0 : }
80 :
81 0 : int clear_rip_route_rpc(struct nb_cb_rpc_args *args)
82 : {
83 0 : struct rip *rip;
84 0 : struct yang_data *yang_vrf;
85 :
86 0 : yang_vrf = yang_data_list_find(args->input, "%s/%s", args->xpath,
87 : "input/vrf");
88 0 : if (yang_vrf) {
89 0 : rip = rip_lookup_by_vrf_name(yang_vrf->value);
90 0 : if (rip)
91 0 : clear_rip_route(rip);
92 : } else {
93 0 : struct vrf *vrf;
94 :
95 0 : RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
96 0 : rip = vrf->info;
97 0 : if (!rip)
98 0 : continue;
99 :
100 0 : clear_rip_route(rip);
101 : }
102 : }
103 :
104 0 : return NB_OK;
105 : }
|