]> git.proxmox.com Git - mirror_frr.git/blob - ripngd/ripng_route.c
Merge remote-tracking branch 'origin/master' into babel
[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 "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 *
34 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
43 ripng_aggregate_free (struct ripng_aggregate *aggregate)
44 {
45 XFREE (MTYPE_RIPNG_AGGREGATE, aggregate);
46 }
47
48 /* Aggregate count increment check. */
49 void
50 ripng_aggregate_increment (struct route_node *child, struct ripng_info *rinfo)
51 {
52 struct route_node *np;
53 struct ripng_aggregate *aggregate;
54
55 for (np = child; np; np = np->parent)
56 if ((aggregate = np->aggregate) != NULL)
57 {
58 aggregate->count++;
59 rinfo->suppress++;
60 }
61 }
62
63 /* Aggregate count decrement check. */
64 void
65 ripng_aggregate_decrement (struct route_node *child, struct ripng_info *rinfo)
66 {
67 struct route_node *np;
68 struct ripng_aggregate *aggregate;
69
70 for (np = child; np; np = np->parent)
71 if ((aggregate = np->aggregate) != NULL)
72 {
73 aggregate->count--;
74 rinfo->suppress--;
75 }
76 }
77
78 /* Aggregate count decrement check for a list. */
79 void
80 ripng_aggregate_decrement_list (struct route_node *child, struct list *list)
81 {
82 struct route_node *np;
83 struct ripng_aggregate *aggregate;
84 struct ripng_info *rinfo = NULL;
85 struct listnode *node = NULL;
86
87 for (np = child; np; np = np->parent)
88 if ((aggregate = np->aggregate) != NULL)
89 aggregate->count -= listcount (list);
90
91 for (ALL_LIST_ELEMENTS_RO (list, node, rinfo))
92 rinfo->suppress--;
93 }
94
95 /* RIPng routes treatment. */
96 int
97 ripng_aggregate_add (struct prefix *p)
98 {
99 struct route_node *top;
100 struct route_node *rp;
101 struct ripng_info *rinfo;
102 struct ripng_aggregate *aggregate;
103 struct ripng_aggregate *sub;
104 struct list *list = NULL;
105 struct listnode *node = NULL;
106
107 /* Get top node for aggregation. */
108 top = route_node_get (ripng->table, p);
109
110 /* Allocate new aggregate. */
111 aggregate = ripng_aggregate_new ();
112 aggregate->metric = 1;
113
114 top->aggregate = aggregate;
115
116 /* Suppress routes match to the aggregate. */
117 for (rp = route_lock_node (top); rp; rp = route_next_until (rp, top))
118 {
119 /* Suppress normal route. */
120 if ((list = rp->info) != NULL)
121 for (ALL_LIST_ELEMENTS_RO (list, node, rinfo))
122 {
123 aggregate->count++;
124 rinfo->suppress++;
125 }
126 /* Suppress aggregate route. This may not need. */
127 if (rp != top && (sub = rp->aggregate) != NULL)
128 {
129 aggregate->count++;
130 sub->suppress++;
131 }
132 }
133
134 return 0;
135 }
136
137 /* Delete RIPng static route. */
138 int
139 ripng_aggregate_delete (struct prefix *p)
140 {
141 struct route_node *top;
142 struct route_node *rp;
143 struct ripng_info *rinfo;
144 struct ripng_aggregate *aggregate;
145 struct ripng_aggregate *sub;
146 struct list *list = NULL;
147 struct listnode *node = NULL;
148
149 /* Get top node for aggregation. */
150 top = route_node_get (ripng->table, p);
151
152 /* Allocate new aggregate. */
153 aggregate = top->aggregate;
154
155 /* Suppress routes match to the aggregate. */
156 for (rp = route_lock_node (top); rp; rp = route_next_until (rp, top))
157 {
158 /* Suppress normal route. */
159 if ((list = rp->info) != NULL)
160 for (ALL_LIST_ELEMENTS_RO (list, node, rinfo))
161 {
162 aggregate->count--;
163 rinfo->suppress--;
164 }
165
166 if (rp != top && (sub = rp->aggregate) != NULL)
167 {
168 aggregate->count--;
169 sub->suppress--;
170 }
171 }
172
173 top->aggregate = NULL;
174 ripng_aggregate_free (aggregate);
175
176 route_unlock_node (top);
177 route_unlock_node (top);
178
179 return 0;
180 }