]> git.proxmox.com Git - mirror_frr.git/blob - ripngd/ripng_route.c
Merge pull request #13649 from donaldsharp/unlock_the_node_or_else
[mirror_frr.git] / ripngd / ripng_route.c
1 /*
2 * RIPng routes function.
3 * Copyright (C) 1998 Kunihiro Ishiguro
4 *
5 * This file is part of GNU Zebra.
6 *
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
10 * later version.
11 *
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include <zebra.h>
23
24 #include "prefix.h"
25 #include "agg_table.h"
26 #include "memory.h"
27 #include "if.h"
28 #include "vty.h"
29
30 #include "ripngd/ripngd.h"
31 #include "ripngd/ripng_route.h"
32
33 static struct ripng_aggregate *ripng_aggregate_new(void)
34 {
35 struct ripng_aggregate *new;
36
37 new = XCALLOC(MTYPE_RIPNG_AGGREGATE, sizeof(struct ripng_aggregate));
38 return new;
39 }
40
41 void ripng_aggregate_free(struct ripng_aggregate *aggregate)
42 {
43 XFREE(MTYPE_RIPNG_AGGREGATE, aggregate);
44 }
45
46 /* Aggregate count increment check. */
47 void ripng_aggregate_increment(struct agg_node *child, struct ripng_info *rinfo)
48 {
49 struct agg_node *np;
50 struct ripng_aggregate *aggregate;
51
52 for (np = child; np; np = agg_node_parent(np))
53 if ((aggregate = np->aggregate) != NULL) {
54 aggregate->count++;
55 rinfo->suppress++;
56 }
57 }
58
59 /* Aggregate count decrement check. */
60 void ripng_aggregate_decrement(struct agg_node *child, struct ripng_info *rinfo)
61 {
62 struct agg_node *np;
63 struct ripng_aggregate *aggregate;
64
65 for (np = child; np; np = agg_node_parent(np))
66 if ((aggregate = np->aggregate) != NULL) {
67 aggregate->count--;
68 rinfo->suppress--;
69 }
70 }
71
72 /* Aggregate count decrement check for a list. */
73 void ripng_aggregate_decrement_list(struct agg_node *child, struct list *list)
74 {
75 struct agg_node *np;
76 struct ripng_aggregate *aggregate;
77 struct ripng_info *rinfo = NULL;
78 struct listnode *node = NULL;
79
80 for (np = child; np; np = agg_node_parent(np))
81 if ((aggregate = np->aggregate) != NULL)
82 aggregate->count -= listcount(list);
83
84 for (ALL_LIST_ELEMENTS_RO(list, node, rinfo))
85 rinfo->suppress--;
86 }
87
88 /* RIPng routes treatment. */
89 int ripng_aggregate_add(struct prefix *p)
90 {
91 struct agg_node *top;
92 struct agg_node *rp;
93 struct ripng_info *rinfo;
94 struct ripng_aggregate *aggregate;
95 struct ripng_aggregate *sub;
96 struct list *list = NULL;
97 struct listnode *node = NULL;
98
99 /* Get top node for aggregation. */
100 top = agg_node_get(ripng->table, p);
101
102 /* Allocate new aggregate. */
103 aggregate = ripng_aggregate_new();
104 aggregate->metric = 1;
105
106 top->aggregate = aggregate;
107
108 /* Suppress routes match to the aggregate. */
109 for (rp = agg_lock_node(top); rp; rp = agg_route_next_until(rp, top)) {
110 /* Suppress normal route. */
111 if ((list = rp->info) != NULL)
112 for (ALL_LIST_ELEMENTS_RO(list, node, rinfo)) {
113 aggregate->count++;
114 rinfo->suppress++;
115 }
116 /* Suppress aggregate route. This may not need. */
117 if (rp != top && (sub = rp->aggregate) != NULL) {
118 aggregate->count++;
119 sub->suppress++;
120 }
121 }
122
123 return 0;
124 }
125
126 /* Delete RIPng static route. */
127 int ripng_aggregate_delete(struct prefix *p)
128 {
129 struct agg_node *top;
130 struct agg_node *rp;
131 struct ripng_info *rinfo;
132 struct ripng_aggregate *aggregate;
133 struct ripng_aggregate *sub;
134 struct list *list = NULL;
135 struct listnode *node = NULL;
136
137 /* Get top node for aggregation. */
138 top = agg_node_get(ripng->table, p);
139
140 /* Allocate new aggregate. */
141 aggregate = top->aggregate;
142
143 /* Suppress routes match to the aggregate. */
144 for (rp = agg_lock_node(top); rp; rp = agg_route_next_until(rp, top)) {
145 /* Suppress normal route. */
146 if ((list = rp->info) != NULL)
147 for (ALL_LIST_ELEMENTS_RO(list, node, rinfo)) {
148 aggregate->count--;
149 rinfo->suppress--;
150 }
151
152 if (rp != top && (sub = rp->aggregate) != NULL) {
153 aggregate->count--;
154 sub->suppress--;
155 }
156 }
157
158 top->aggregate = NULL;
159 ripng_aggregate_free(aggregate);
160
161 agg_unlock_node(top);
162 agg_unlock_node(top);
163
164 return 0;
165 }