]> git.proxmox.com Git - mirror_frr.git/blob - ripngd/ripng_route.c
release: FRR 3.0-rc2
[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
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 * 02111-1307, USA.
21 */
22
23 #include <zebra.h>
24
25 #include "prefix.h"
26 #include "table.h"
27 #include "memory.h"
28 #include "if.h"
29 #include "vty.h"
30
31 #include "ripngd/ripngd.h"
32 #include "ripngd/ripng_route.h"
33
34 static struct ripng_aggregate *ripng_aggregate_new(void)
35 {
36 struct ripng_aggregate *new;
37
38 new = XCALLOC(MTYPE_RIPNG_AGGREGATE, sizeof(struct ripng_aggregate));
39 return new;
40 }
41
42 void ripng_aggregate_free(struct ripng_aggregate *aggregate)
43 {
44 XFREE(MTYPE_RIPNG_AGGREGATE, aggregate);
45 }
46
47 /* Aggregate count increment check. */
48 void ripng_aggregate_increment(struct route_node *child,
49 struct ripng_info *rinfo)
50 {
51 struct route_node *np;
52 struct ripng_aggregate *aggregate;
53
54 for (np = child; np; np = np->parent)
55 if ((aggregate = np->aggregate) != NULL) {
56 aggregate->count++;
57 rinfo->suppress++;
58 }
59 }
60
61 /* Aggregate count decrement check. */
62 void ripng_aggregate_decrement(struct route_node *child,
63 struct ripng_info *rinfo)
64 {
65 struct route_node *np;
66 struct ripng_aggregate *aggregate;
67
68 for (np = child; np; np = np->parent)
69 if ((aggregate = np->aggregate) != NULL) {
70 aggregate->count--;
71 rinfo->suppress--;
72 }
73 }
74
75 /* Aggregate count decrement check for a list. */
76 void ripng_aggregate_decrement_list(struct route_node *child, struct list *list)
77 {
78 struct route_node *np;
79 struct ripng_aggregate *aggregate;
80 struct ripng_info *rinfo = NULL;
81 struct listnode *node = NULL;
82
83 for (np = child; np; np = np->parent)
84 if ((aggregate = np->aggregate) != NULL)
85 aggregate->count -= listcount(list);
86
87 for (ALL_LIST_ELEMENTS_RO(list, node, rinfo))
88 rinfo->suppress--;
89 }
90
91 /* RIPng routes treatment. */
92 int ripng_aggregate_add(struct prefix *p)
93 {
94 struct route_node *top;
95 struct route_node *rp;
96 struct ripng_info *rinfo;
97 struct ripng_aggregate *aggregate;
98 struct ripng_aggregate *sub;
99 struct list *list = NULL;
100 struct listnode *node = NULL;
101
102 /* Get top node for aggregation. */
103 top = route_node_get(ripng->table, p);
104
105 /* Allocate new aggregate. */
106 aggregate = ripng_aggregate_new();
107 aggregate->metric = 1;
108
109 top->aggregate = aggregate;
110
111 /* Suppress routes match to the aggregate. */
112 for (rp = route_lock_node(top); rp; rp = route_next_until(rp, top)) {
113 /* Suppress normal route. */
114 if ((list = rp->info) != NULL)
115 for (ALL_LIST_ELEMENTS_RO(list, node, rinfo)) {
116 aggregate->count++;
117 rinfo->suppress++;
118 }
119 /* Suppress aggregate route. This may not need. */
120 if (rp != top && (sub = rp->aggregate) != NULL) {
121 aggregate->count++;
122 sub->suppress++;
123 }
124 }
125
126 return 0;
127 }
128
129 /* Delete RIPng static route. */
130 int ripng_aggregate_delete(struct prefix *p)
131 {
132 struct route_node *top;
133 struct route_node *rp;
134 struct ripng_info *rinfo;
135 struct ripng_aggregate *aggregate;
136 struct ripng_aggregate *sub;
137 struct list *list = NULL;
138 struct listnode *node = NULL;
139
140 /* Get top node for aggregation. */
141 top = route_node_get(ripng->table, p);
142
143 /* Allocate new aggregate. */
144 aggregate = top->aggregate;
145
146 /* Suppress routes match to the aggregate. */
147 for (rp = route_lock_node(top); rp; rp = route_next_until(rp, top)) {
148 /* Suppress normal route. */
149 if ((list = rp->info) != NULL)
150 for (ALL_LIST_ELEMENTS_RO(list, node, rinfo)) {
151 aggregate->count--;
152 rinfo->suppress--;
153 }
154
155 if (rp != top && (sub = rp->aggregate) != NULL) {
156 aggregate->count--;
157 sub->suppress--;
158 }
159 }
160
161 top->aggregate = NULL;
162 ripng_aggregate_free(aggregate);
163
164 route_unlock_node(top);
165 route_unlock_node(top);
166
167 return 0;
168 }