]> git.proxmox.com Git - mirror_frr.git/blame - ripngd/ripng_route.c
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / ripngd / ripng_route.c
CommitLineData
acddc0ed 1// SPDX-License-Identifier: GPL-2.0-or-later
718e3744 2/*
3 * RIPng routes function.
4 * Copyright (C) 1998 Kunihiro Ishiguro
718e3744 5 */
6
7#include <zebra.h>
8
9#include "prefix.h"
fe08ba7e 10#include "agg_table.h"
718e3744 11#include "memory.h"
12#include "if.h"
a94434b6 13#include "vty.h"
718e3744 14
15#include "ripngd/ripngd.h"
16#include "ripngd/ripng_route.h"
17
bf8d3d6a 18DEFINE_MTYPE_STATIC(RIPNGD, RIPNG_AGGREGATE, "RIPng aggregate");
b3a7e30d 19
d62a17ae 20static struct ripng_aggregate *ripng_aggregate_new(void)
718e3744 21{
d62a17ae 22 struct ripng_aggregate *new;
718e3744 23
d62a17ae 24 new = XCALLOC(MTYPE_RIPNG_AGGREGATE, sizeof(struct ripng_aggregate));
25 return new;
718e3744 26}
27
d62a17ae 28void ripng_aggregate_free(struct ripng_aggregate *aggregate)
718e3744 29{
d62a17ae 30 XFREE(MTYPE_RIPNG_AGGREGATE, aggregate);
718e3744 31}
32
33/* Aggregate count increment check. */
fe08ba7e 34void ripng_aggregate_increment(struct agg_node *child, struct ripng_info *rinfo)
718e3744 35{
fe08ba7e 36 struct agg_node *np;
d62a17ae 37 struct ripng_aggregate *aggregate;
38
fe08ba7e 39 for (np = child; np; np = agg_node_parent(np))
d62a17ae 40 if ((aggregate = np->aggregate) != NULL) {
41 aggregate->count++;
42 rinfo->suppress++;
43 }
718e3744 44}
45
46/* Aggregate count decrement check. */
fe08ba7e 47void ripng_aggregate_decrement(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
c880b636 59/* Aggregate count decrement check for a list. */
fe08ba7e 60void ripng_aggregate_decrement_list(struct agg_node *child, struct list *list)
c880b636 61{
fe08ba7e 62 struct agg_node *np;
d62a17ae 63 struct ripng_aggregate *aggregate;
64 struct ripng_info *rinfo = NULL;
65 struct listnode *node = NULL;
c880b636 66
fe08ba7e 67 for (np = child; np; np = agg_node_parent(np))
d62a17ae 68 if ((aggregate = np->aggregate) != NULL)
69 aggregate->count -= listcount(list);
c880b636 70
d62a17ae 71 for (ALL_LIST_ELEMENTS_RO(list, node, rinfo))
72 rinfo->suppress--;
c880b636
FL
73}
74
718e3744 75/* RIPng routes treatment. */
5c84b9a5 76int ripng_aggregate_add(struct ripng *ripng, struct prefix *p)
718e3744 77{
fe08ba7e
DS
78 struct agg_node *top;
79 struct agg_node *rp;
d62a17ae 80 struct ripng_info *rinfo;
81 struct ripng_aggregate *aggregate;
82 struct ripng_aggregate *sub;
83 struct list *list = NULL;
84 struct listnode *node = NULL;
85
86 /* Get top node for aggregation. */
fe08ba7e 87 top = agg_node_get(ripng->table, p);
d62a17ae 88
89 /* Allocate new aggregate. */
90 aggregate = ripng_aggregate_new();
91 aggregate->metric = 1;
92
93 top->aggregate = aggregate;
94
95 /* Suppress routes match to the aggregate. */
fe08ba7e 96 for (rp = agg_lock_node(top); rp; rp = agg_route_next_until(rp, top)) {
d62a17ae 97 /* Suppress normal route. */
98 if ((list = rp->info) != NULL)
99 for (ALL_LIST_ELEMENTS_RO(list, node, rinfo)) {
100 aggregate->count++;
101 rinfo->suppress++;
102 }
103 /* Suppress aggregate route. This may not need. */
104 if (rp != top && (sub = rp->aggregate) != NULL) {
105 aggregate->count++;
106 sub->suppress++;
107 }
718e3744 108 }
718e3744 109
d62a17ae 110 return 0;
718e3744 111}
112
113/* Delete RIPng static route. */
5c84b9a5 114int ripng_aggregate_delete(struct ripng *ripng, struct prefix *p)
718e3744 115{
fe08ba7e
DS
116 struct agg_node *top;
117 struct agg_node *rp;
d62a17ae 118 struct ripng_info *rinfo;
119 struct ripng_aggregate *aggregate;
120 struct ripng_aggregate *sub;
121 struct list *list = NULL;
122 struct listnode *node = NULL;
123
124 /* Get top node for aggregation. */
fe08ba7e 125 top = agg_node_get(ripng->table, p);
d62a17ae 126
127 /* Allocate new aggregate. */
128 aggregate = top->aggregate;
129
130 /* Suppress routes match to the aggregate. */
fe08ba7e 131 for (rp = agg_lock_node(top); rp; rp = agg_route_next_until(rp, top)) {
d62a17ae 132 /* Suppress normal route. */
133 if ((list = rp->info) != NULL)
134 for (ALL_LIST_ELEMENTS_RO(list, node, rinfo)) {
135 aggregate->count--;
136 rinfo->suppress--;
137 }
138
139 if (rp != top && (sub = rp->aggregate) != NULL) {
140 aggregate->count--;
141 sub->suppress--;
142 }
718e3744 143 }
718e3744 144
d62a17ae 145 top->aggregate = NULL;
146 ripng_aggregate_free(aggregate);
718e3744 147
fe08ba7e
DS
148 agg_unlock_node(top);
149 agg_unlock_node(top);
718e3744 150
d62a17ae 151 return 0;
718e3744 152}