]> git.proxmox.com Git - mirror_frr.git/blob - ripngd/ripng_route.c
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / ripngd / ripng_route.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * RIPng routes function.
4 * Copyright (C) 1998 Kunihiro Ishiguro
5 */
6
7 #include <zebra.h>
8
9 #include "prefix.h"
10 #include "agg_table.h"
11 #include "memory.h"
12 #include "if.h"
13 #include "vty.h"
14
15 #include "ripngd/ripngd.h"
16 #include "ripngd/ripng_route.h"
17
18 DEFINE_MTYPE_STATIC(RIPNGD, RIPNG_AGGREGATE, "RIPng aggregate");
19
20 static struct ripng_aggregate *ripng_aggregate_new(void)
21 {
22 struct ripng_aggregate *new;
23
24 new = XCALLOC(MTYPE_RIPNG_AGGREGATE, sizeof(struct ripng_aggregate));
25 return new;
26 }
27
28 void ripng_aggregate_free(struct ripng_aggregate *aggregate)
29 {
30 XFREE(MTYPE_RIPNG_AGGREGATE, aggregate);
31 }
32
33 /* Aggregate count increment check. */
34 void ripng_aggregate_increment(struct agg_node *child, struct ripng_info *rinfo)
35 {
36 struct agg_node *np;
37 struct ripng_aggregate *aggregate;
38
39 for (np = child; np; np = agg_node_parent(np))
40 if ((aggregate = np->aggregate) != NULL) {
41 aggregate->count++;
42 rinfo->suppress++;
43 }
44 }
45
46 /* Aggregate count decrement check. */
47 void ripng_aggregate_decrement(struct agg_node *child, struct ripng_info *rinfo)
48 {
49 struct agg_node *np;
50 struct ripng_aggregate *aggregate;
51
52 for (np = child; np; np = agg_node_parent(np))
53 if ((aggregate = np->aggregate) != NULL) {
54 aggregate->count--;
55 rinfo->suppress--;
56 }
57 }
58
59 /* Aggregate count decrement check for a list. */
60 void ripng_aggregate_decrement_list(struct agg_node *child, struct list *list)
61 {
62 struct agg_node *np;
63 struct ripng_aggregate *aggregate;
64 struct ripng_info *rinfo = NULL;
65 struct listnode *node = NULL;
66
67 for (np = child; np; np = agg_node_parent(np))
68 if ((aggregate = np->aggregate) != NULL)
69 aggregate->count -= listcount(list);
70
71 for (ALL_LIST_ELEMENTS_RO(list, node, rinfo))
72 rinfo->suppress--;
73 }
74
75 /* RIPng routes treatment. */
76 int ripng_aggregate_add(struct ripng *ripng, struct prefix *p)
77 {
78 struct agg_node *top;
79 struct agg_node *rp;
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. */
87 top = agg_node_get(ripng->table, p);
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. */
96 for (rp = agg_lock_node(top); rp; rp = agg_route_next_until(rp, top)) {
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 }
108 }
109
110 return 0;
111 }
112
113 /* Delete RIPng static route. */
114 int ripng_aggregate_delete(struct ripng *ripng, struct prefix *p)
115 {
116 struct agg_node *top;
117 struct agg_node *rp;
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. */
125 top = agg_node_get(ripng->table, p);
126
127 /* Allocate new aggregate. */
128 aggregate = top->aggregate;
129
130 /* Suppress routes match to the aggregate. */
131 for (rp = agg_lock_node(top); rp; rp = agg_route_next_until(rp, top)) {
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 }
143 }
144
145 top->aggregate = NULL;
146 ripng_aggregate_free(aggregate);
147
148 agg_unlock_node(top);
149 agg_unlock_node(top);
150
151 return 0;
152 }