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