2 * RIPng routes function.
3 * Copyright (C) 1998 Kunihiro Ishiguro
5 * This file is part of GNU Zebra.
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
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.
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
31 #include "ripngd/ripngd.h"
32 #include "ripngd/ripng_route.h"
34 static struct ripng_aggregate *
35 ripng_aggregate_new ()
37 struct ripng_aggregate *new;
39 new = XCALLOC (MTYPE_RIPNG_AGGREGATE, sizeof (struct ripng_aggregate));
44 ripng_aggregate_free (struct ripng_aggregate *aggregate)
46 XFREE (MTYPE_RIPNG_AGGREGATE, aggregate);
49 /* Aggregate count increment check. */
51 ripng_aggregate_increment (struct route_node *child, struct ripng_info *rinfo)
53 struct route_node *np;
54 struct ripng_aggregate *aggregate;
56 for (np = child; np; np = np->parent)
57 if ((aggregate = np->aggregate) != NULL)
64 /* Aggregate count decrement check. */
66 ripng_aggregate_decrement (struct route_node *child, struct ripng_info *rinfo)
68 struct route_node *np;
69 struct ripng_aggregate *aggregate;
71 for (np = child; np; np = np->parent)
72 if ((aggregate = np->aggregate) != NULL)
79 /* Aggregate count decrement check for a list. */
81 ripng_aggregate_decrement_list (struct route_node *child, struct list *list)
83 struct route_node *np;
84 struct ripng_aggregate *aggregate;
85 struct ripng_info *rinfo = NULL;
86 struct listnode *node = NULL;
88 for (np = child; np; np = np->parent)
89 if ((aggregate = np->aggregate) != NULL)
90 aggregate->count -= listcount (list);
92 for (ALL_LIST_ELEMENTS_RO (list, node, rinfo))
96 /* RIPng routes treatment. */
98 ripng_aggregate_add (struct prefix *p)
100 struct route_node *top;
101 struct route_node *rp;
102 struct ripng_info *rinfo;
103 struct ripng_aggregate *aggregate;
104 struct ripng_aggregate *sub;
105 struct list *list = NULL;
106 struct listnode *node = NULL;
108 /* Get top node for aggregation. */
109 top = route_node_get (ripng->table, p);
111 /* Allocate new aggregate. */
112 aggregate = ripng_aggregate_new ();
113 aggregate->metric = 1;
115 top->aggregate = aggregate;
117 /* Suppress routes match to the aggregate. */
118 for (rp = route_lock_node (top); rp; rp = route_next_until (rp, top))
120 /* Suppress normal route. */
121 if ((list = rp->info) != NULL)
122 for (ALL_LIST_ELEMENTS_RO (list, node, rinfo))
127 /* Suppress aggregate route. This may not need. */
128 if (rp != top && (sub = rp->aggregate) != NULL)
138 /* Delete RIPng static route. */
140 ripng_aggregate_delete (struct prefix *p)
142 struct route_node *top;
143 struct route_node *rp;
144 struct ripng_info *rinfo;
145 struct ripng_aggregate *aggregate;
146 struct ripng_aggregate *sub;
147 struct list *list = NULL;
148 struct listnode *node = NULL;
150 /* Get top node for aggregation. */
151 top = route_node_get (ripng->table, p);
153 /* Allocate new aggregate. */
154 aggregate = top->aggregate;
156 /* Suppress routes match to the aggregate. */
157 for (rp = route_lock_node (top); rp; rp = route_next_until (rp, top))
159 /* Suppress normal route. */
160 if ((list = rp->info) != NULL)
161 for (ALL_LIST_ELEMENTS_RO (list, node, rinfo))
167 if (rp != top && (sub = rp->aggregate) != NULL)
174 top->aggregate = NULL;
175 ripng_aggregate_free (aggregate);
177 route_unlock_node (top);
178 route_unlock_node (top);