]>
git.proxmox.com Git - mirror_frr.git/blob - ripngd/ripng_route.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * RIPng routes function.
4 * Copyright (C) 1998 Kunihiro Ishiguro
10 #include "agg_table.h"
15 #include "ripngd/ripngd.h"
16 #include "ripngd/ripng_route.h"
18 DEFINE_MTYPE_STATIC(RIPNGD
, RIPNG_AGGREGATE
, "RIPng aggregate");
20 static struct ripng_aggregate
*ripng_aggregate_new(void)
22 struct ripng_aggregate
*new;
24 new = XCALLOC(MTYPE_RIPNG_AGGREGATE
, sizeof(struct ripng_aggregate
));
28 void ripng_aggregate_free(struct ripng_aggregate
*aggregate
)
30 XFREE(MTYPE_RIPNG_AGGREGATE
, aggregate
);
33 /* Aggregate count increment check. */
34 void ripng_aggregate_increment(struct agg_node
*child
, struct ripng_info
*rinfo
)
37 struct ripng_aggregate
*aggregate
;
39 for (np
= child
; np
; np
= agg_node_parent(np
))
40 if ((aggregate
= np
->aggregate
) != NULL
) {
46 /* Aggregate count decrement check. */
47 void ripng_aggregate_decrement(struct agg_node
*child
, struct ripng_info
*rinfo
)
50 struct ripng_aggregate
*aggregate
;
52 for (np
= child
; np
; np
= agg_node_parent(np
))
53 if ((aggregate
= np
->aggregate
) != NULL
) {
59 /* Aggregate count decrement check for a list. */
60 void ripng_aggregate_decrement_list(struct agg_node
*child
, struct list
*list
)
63 struct ripng_aggregate
*aggregate
;
64 struct ripng_info
*rinfo
= NULL
;
65 struct listnode
*node
= NULL
;
67 for (np
= child
; np
; np
= agg_node_parent(np
))
68 if ((aggregate
= np
->aggregate
) != NULL
)
69 aggregate
->count
-= listcount(list
);
71 for (ALL_LIST_ELEMENTS_RO(list
, node
, rinfo
))
75 /* RIPng routes treatment. */
76 int ripng_aggregate_add(struct ripng
*ripng
, struct prefix
*p
)
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
;
86 /* Get top node for aggregation. */
87 top
= agg_node_get(ripng
->table
, p
);
89 /* Allocate new aggregate. */
90 aggregate
= ripng_aggregate_new();
91 aggregate
->metric
= 1;
93 top
->aggregate
= aggregate
;
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
)) {
103 /* Suppress aggregate route. This may not need. */
104 if (rp
!= top
&& (sub
= rp
->aggregate
) != NULL
) {
113 /* Delete RIPng static route. */
114 int ripng_aggregate_delete(struct ripng
*ripng
, struct prefix
*p
)
116 struct agg_node
*top
;
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
;
124 /* Get top node for aggregation. */
125 top
= agg_node_get(ripng
->table
, p
);
127 /* Allocate new aggregate. */
128 aggregate
= top
->aggregate
;
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
)) {
139 if (rp
!= top
&& (sub
= rp
->aggregate
) != NULL
) {
145 top
->aggregate
= NULL
;
146 ripng_aggregate_free(aggregate
);
148 agg_unlock_node(top
);
149 agg_unlock_node(top
);