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