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 "agg_table.h"
30 : #include "northbound.h"
31 : #include "libfrr.h"
32 :
33 : #include "ripngd/ripngd.h"
34 : #include "ripngd/ripng_nb.h"
35 : #include "ripngd/ripng_debug.h"
36 : #include "ripngd/ripng_route.h"
37 :
38 : /*
39 : * XPath: /frr-ripngd:clear-ripng-route
40 : */
41 0 : static void clear_ripng_route(struct ripng *ripng)
42 : {
43 0 : struct agg_node *rp;
44 :
45 0 : if (IS_RIPNG_DEBUG_EVENT)
46 0 : zlog_debug("Clearing all RIPng routes (VRF %s)",
47 : ripng->vrf_name);
48 :
49 : /* Clear received RIPng routes */
50 0 : for (rp = agg_route_top(ripng->table); rp; rp = agg_route_next(rp)) {
51 0 : struct list *list;
52 0 : struct listnode *listnode;
53 0 : struct ripng_info *rinfo;
54 :
55 0 : list = rp->info;
56 0 : if (list == NULL)
57 0 : continue;
58 :
59 0 : for (ALL_LIST_ELEMENTS_RO(list, listnode, rinfo)) {
60 0 : if (!ripng_route_rte(rinfo))
61 0 : continue;
62 :
63 0 : if (CHECK_FLAG(rinfo->flags, RIPNG_RTF_FIB))
64 0 : ripng_zebra_ipv6_delete(ripng, rp);
65 : break;
66 : }
67 :
68 0 : if (rinfo) {
69 0 : THREAD_OFF(rinfo->t_timeout);
70 0 : THREAD_OFF(rinfo->t_garbage_collect);
71 0 : listnode_delete(list, rinfo);
72 0 : ripng_info_free(rinfo);
73 : }
74 :
75 0 : if (list_isempty(list)) {
76 0 : list_delete(&list);
77 0 : rp->info = NULL;
78 0 : agg_unlock_node(rp);
79 : }
80 : }
81 0 : }
82 :
83 0 : int clear_ripng_route_rpc(struct nb_cb_rpc_args *args)
84 : {
85 0 : struct ripng *ripng;
86 0 : struct yang_data *yang_vrf;
87 :
88 0 : yang_vrf = yang_data_list_find(args->input, "%s/%s", args->xpath,
89 : "input/vrf");
90 0 : if (yang_vrf) {
91 0 : ripng = ripng_lookup_by_vrf_name(yang_vrf->value);
92 0 : if (ripng)
93 0 : clear_ripng_route(ripng);
94 : } else {
95 0 : struct vrf *vrf;
96 :
97 0 : RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
98 0 : ripng = vrf->info;
99 0 : if (!ripng)
100 0 : continue;
101 :
102 0 : clear_ripng_route(ripng);
103 : }
104 : }
105 :
106 0 : return NB_OK;
107 : }
|