]> git.proxmox.com Git - mirror_frr.git/blame - ripngd/ripng_route.c
Merge pull request #4773 from thozza/31-prefix-bcast-addr
[mirror_frr.git] / ripngd / ripng_route.c
CommitLineData
718e3744 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 *
896014f4
DL
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
718e3744 20 */
21
22#include <zebra.h>
23
24#include "prefix.h"
fe08ba7e 25#include "agg_table.h"
718e3744 26#include "memory.h"
27#include "if.h"
a94434b6 28#include "vty.h"
718e3744 29
30#include "ripngd/ripngd.h"
31#include "ripngd/ripng_route.h"
32
b3a7e30d
DL
33DEFINE_MTYPE_STATIC(RIPNGD, RIPNG_AGGREGATE, "RIPng aggregate")
34
d62a17ae 35static struct ripng_aggregate *ripng_aggregate_new(void)
718e3744 36{
d62a17ae 37 struct ripng_aggregate *new;
718e3744 38
d62a17ae 39 new = XCALLOC(MTYPE_RIPNG_AGGREGATE, sizeof(struct ripng_aggregate));
40 return new;
718e3744 41}
42
d62a17ae 43void ripng_aggregate_free(struct ripng_aggregate *aggregate)
718e3744 44{
d62a17ae 45 XFREE(MTYPE_RIPNG_AGGREGATE, aggregate);
718e3744 46}
47
48/* Aggregate count increment check. */
fe08ba7e 49void ripng_aggregate_increment(struct agg_node *child, struct ripng_info *rinfo)
718e3744 50{
fe08ba7e 51 struct agg_node *np;
d62a17ae 52 struct ripng_aggregate *aggregate;
53
fe08ba7e 54 for (np = child; np; np = agg_node_parent(np))
d62a17ae 55 if ((aggregate = np->aggregate) != NULL) {
56 aggregate->count++;
57 rinfo->suppress++;
58 }
718e3744 59}
60
61/* Aggregate count decrement check. */
fe08ba7e 62void ripng_aggregate_decrement(struct agg_node *child, struct ripng_info *rinfo)
718e3744 63{
fe08ba7e 64 struct agg_node *np;
d62a17ae 65 struct ripng_aggregate *aggregate;
66
fe08ba7e 67 for (np = child; np; np = agg_node_parent(np))
d62a17ae 68 if ((aggregate = np->aggregate) != NULL) {
69 aggregate->count--;
70 rinfo->suppress--;
71 }
718e3744 72}
73
c880b636 74/* Aggregate count decrement check for a list. */
fe08ba7e 75void ripng_aggregate_decrement_list(struct agg_node *child, struct list *list)
c880b636 76{
fe08ba7e 77 struct agg_node *np;
d62a17ae 78 struct ripng_aggregate *aggregate;
79 struct ripng_info *rinfo = NULL;
80 struct listnode *node = NULL;
c880b636 81
fe08ba7e 82 for (np = child; np; np = agg_node_parent(np))
d62a17ae 83 if ((aggregate = np->aggregate) != NULL)
84 aggregate->count -= listcount(list);
c880b636 85
d62a17ae 86 for (ALL_LIST_ELEMENTS_RO(list, node, rinfo))
87 rinfo->suppress--;
c880b636
FL
88}
89
718e3744 90/* RIPng routes treatment. */
5c84b9a5 91int ripng_aggregate_add(struct ripng *ripng, struct prefix *p)
718e3744 92{
fe08ba7e
DS
93 struct agg_node *top;
94 struct agg_node *rp;
d62a17ae 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. */
fe08ba7e 102 top = agg_node_get(ripng->table, p);
d62a17ae 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. */
fe08ba7e 111 for (rp = agg_lock_node(top); rp; rp = agg_route_next_until(rp, top)) {
d62a17ae 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 }
718e3744 123 }
718e3744 124
d62a17ae 125 return 0;
718e3744 126}
127
128/* Delete RIPng static route. */
5c84b9a5 129int ripng_aggregate_delete(struct ripng *ripng, struct prefix *p)
718e3744 130{
fe08ba7e
DS
131 struct agg_node *top;
132 struct agg_node *rp;
d62a17ae 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. */
fe08ba7e 140 top = agg_node_get(ripng->table, p);
d62a17ae 141
142 /* Allocate new aggregate. */
143 aggregate = top->aggregate;
144
145 /* Suppress routes match to the aggregate. */
fe08ba7e 146 for (rp = agg_lock_node(top); rp; rp = agg_route_next_until(rp, top)) {
d62a17ae 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 }
718e3744 158 }
718e3744 159
d62a17ae 160 top->aggregate = NULL;
161 ripng_aggregate_free(aggregate);
718e3744 162
fe08ba7e
DS
163 agg_unlock_node(top);
164 agg_unlock_node(top);
718e3744 165
d62a17ae 166 return 0;
718e3744 167}