[administrivia] Ignore rebase files and .msg
[jleu-quagga.git] / ripngd / ripng_route.c
blob9c3c4f990826101f3dae9a559f797af41f6b5b27
1 /*
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
10 * later version.
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
20 * 02111-1307, USA.
23 #include <zebra.h>
25 #include "prefix.h"
26 #include "table.h"
27 #include "memory.h"
28 #include "if.h"
29 #include "vty.h"
31 #include "ripngd/ripngd.h"
32 #include "ripngd/ripng_route.h"
34 struct ripng_aggregate *
35 ripng_aggregate_new ()
37 struct ripng_aggregate *new;
39 new = XCALLOC (MTYPE_RIPNG_AGGREGATE, sizeof (struct ripng_aggregate));
40 return new;
43 void
44 ripng_aggregate_free (struct ripng_aggregate *aggregate)
46 XFREE (MTYPE_RIPNG_AGGREGATE, aggregate);
49 /* Aggregate count increment check. */
50 void
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)
59 aggregate->count++;
60 rinfo->suppress++;
64 /* Aggregate count decrement check. */
65 void
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)
74 aggregate->count--;
75 rinfo->suppress--;
79 /* RIPng routes treatment. */
80 int
81 ripng_aggregate_add (struct prefix *p)
83 struct route_node *top;
84 struct route_node *rp;
85 struct ripng_info *rinfo;
86 struct ripng_aggregate *aggregate;
87 struct ripng_aggregate *sub;
89 /* Get top node for aggregation. */
90 top = route_node_get (ripng->table, p);
92 /* Allocate new aggregate. */
93 aggregate = ripng_aggregate_new ();
94 aggregate->metric = 1;
96 top->aggregate = aggregate;
98 /* Suppress routes match to the aggregate. */
99 for (rp = route_lock_node (top); rp; rp = route_next_until (rp, top))
101 /* Suppress normal route. */
102 if ((rinfo = rp->info) != NULL)
104 aggregate->count++;
105 rinfo->suppress++;
107 /* Suppress aggregate route. This may not need. */
108 if (rp != top && (sub = rp->aggregate) != NULL)
110 aggregate->count++;
111 sub->suppress++;
115 return 0;
118 /* Delete RIPng static route. */
120 ripng_aggregate_delete (struct prefix *p)
122 struct route_node *top;
123 struct route_node *rp;
124 struct ripng_info *rinfo;
125 struct ripng_aggregate *aggregate;
126 struct ripng_aggregate *sub;
128 /* Get top node for aggregation. */
129 top = route_node_get (ripng->table, p);
131 /* Allocate new aggregate. */
132 aggregate = top->aggregate;
134 /* Suppress routes match to the aggregate. */
135 for (rp = route_lock_node (top); rp; rp = route_next_until (rp, top))
137 /* Suppress normal route. */
138 if ((rinfo = rp->info) != NULL)
140 aggregate->count--;
141 rinfo->suppress--;
144 if (rp != top && (sub = rp->aggregate) != NULL)
146 aggregate->count--;
147 sub->suppress--;
151 top->aggregate = NULL;
152 ripng_aggregate_free (aggregate);
154 route_unlock_node (top);
155 route_unlock_node (top);
157 return 0;