]> git.proxmox.com Git - mirror_frr.git/blame - ripngd/ripng_route.c
zebra: Allow ns delete to happen after under/over flow checks
[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
d62a17ae 33static struct ripng_aggregate *ripng_aggregate_new(void)
718e3744 34{
d62a17ae 35 struct ripng_aggregate *new;
718e3744 36
d62a17ae 37 new = XCALLOC(MTYPE_RIPNG_AGGREGATE, sizeof(struct ripng_aggregate));
38 return new;
718e3744 39}
40
d62a17ae 41void ripng_aggregate_free(struct ripng_aggregate *aggregate)
718e3744 42{
d62a17ae 43 XFREE(MTYPE_RIPNG_AGGREGATE, aggregate);
718e3744 44}
45
46/* Aggregate count increment check. */
fe08ba7e 47void ripng_aggregate_increment(struct agg_node *child, struct ripng_info *rinfo)
718e3744 48{
fe08ba7e 49 struct agg_node *np;
d62a17ae 50 struct ripng_aggregate *aggregate;
51
fe08ba7e 52 for (np = child; np; np = agg_node_parent(np))
d62a17ae 53 if ((aggregate = np->aggregate) != NULL) {
54 aggregate->count++;
55 rinfo->suppress++;
56 }
718e3744 57}
58
59/* Aggregate count decrement check. */
fe08ba7e 60void ripng_aggregate_decrement(struct agg_node *child, struct ripng_info *rinfo)
718e3744 61{
fe08ba7e 62 struct agg_node *np;
d62a17ae 63 struct ripng_aggregate *aggregate;
64
fe08ba7e 65 for (np = child; np; np = agg_node_parent(np))
d62a17ae 66 if ((aggregate = np->aggregate) != NULL) {
67 aggregate->count--;
68 rinfo->suppress--;
69 }
718e3744 70}
71
c880b636 72/* Aggregate count decrement check for a list. */
fe08ba7e 73void ripng_aggregate_decrement_list(struct agg_node *child, struct list *list)
c880b636 74{
fe08ba7e 75 struct agg_node *np;
d62a17ae 76 struct ripng_aggregate *aggregate;
77 struct ripng_info *rinfo = NULL;
78 struct listnode *node = NULL;
c880b636 79
fe08ba7e 80 for (np = child; np; np = agg_node_parent(np))
d62a17ae 81 if ((aggregate = np->aggregate) != NULL)
82 aggregate->count -= listcount(list);
c880b636 83
d62a17ae 84 for (ALL_LIST_ELEMENTS_RO(list, node, rinfo))
85 rinfo->suppress--;
c880b636
FL
86}
87
718e3744 88/* RIPng routes treatment. */
d62a17ae 89int ripng_aggregate_add(struct prefix *p)
718e3744 90{
fe08ba7e
DS
91 struct agg_node *top;
92 struct agg_node *rp;
d62a17ae 93 struct ripng_info *rinfo;
94 struct ripng_aggregate *aggregate;
95 struct ripng_aggregate *sub;
96 struct list *list = NULL;
97 struct listnode *node = NULL;
98
99 /* Get top node for aggregation. */
fe08ba7e 100 top = agg_node_get(ripng->table, p);
d62a17ae 101
102 /* Allocate new aggregate. */
103 aggregate = ripng_aggregate_new();
104 aggregate->metric = 1;
105
106 top->aggregate = aggregate;
107
108 /* Suppress routes match to the aggregate. */
fe08ba7e 109 for (rp = agg_lock_node(top); rp; rp = agg_route_next_until(rp, top)) {
d62a17ae 110 /* Suppress normal route. */
111 if ((list = rp->info) != NULL)
112 for (ALL_LIST_ELEMENTS_RO(list, node, rinfo)) {
113 aggregate->count++;
114 rinfo->suppress++;
115 }
116 /* Suppress aggregate route. This may not need. */
117 if (rp != top && (sub = rp->aggregate) != NULL) {
118 aggregate->count++;
119 sub->suppress++;
120 }
718e3744 121 }
718e3744 122
d62a17ae 123 return 0;
718e3744 124}
125
126/* Delete RIPng static route. */
d62a17ae 127int ripng_aggregate_delete(struct prefix *p)
718e3744 128{
fe08ba7e
DS
129 struct agg_node *top;
130 struct agg_node *rp;
d62a17ae 131 struct ripng_info *rinfo;
132 struct ripng_aggregate *aggregate;
133 struct ripng_aggregate *sub;
134 struct list *list = NULL;
135 struct listnode *node = NULL;
136
137 /* Get top node for aggregation. */
fe08ba7e 138 top = agg_node_get(ripng->table, p);
d62a17ae 139
140 /* Allocate new aggregate. */
141 aggregate = top->aggregate;
142
143 /* Suppress routes match to the aggregate. */
fe08ba7e 144 for (rp = agg_lock_node(top); rp; rp = agg_route_next_until(rp, top)) {
d62a17ae 145 /* Suppress normal route. */
146 if ((list = rp->info) != NULL)
147 for (ALL_LIST_ELEMENTS_RO(list, node, rinfo)) {
148 aggregate->count--;
149 rinfo->suppress--;
150 }
151
152 if (rp != top && (sub = rp->aggregate) != NULL) {
153 aggregate->count--;
154 sub->suppress--;
155 }
718e3744 156 }
718e3744 157
d62a17ae 158 top->aggregate = NULL;
159 ripng_aggregate_free(aggregate);
718e3744 160
fe08ba7e
DS
161 agg_unlock_node(top);
162 agg_unlock_node(top);
718e3744 163
d62a17ae 164 return 0;
718e3744 165}