]>
git.proxmox.com Git - mirror_frr.git/blob - ripngd/ripng_route.c
2 * RIPng routes function.
3 * Copyright (C) 1998 Kunihiro Ishiguro
5 * This file is part of GNU Zebra.
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
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.
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
25 #include "agg_table.h"
30 #include "ripngd/ripngd.h"
31 #include "ripngd/ripng_route.h"
33 static struct ripng_aggregate
*ripng_aggregate_new(void)
35 struct ripng_aggregate
*new;
37 new = XCALLOC(MTYPE_RIPNG_AGGREGATE
, sizeof(struct ripng_aggregate
));
41 void ripng_aggregate_free(struct ripng_aggregate
*aggregate
)
43 XFREE(MTYPE_RIPNG_AGGREGATE
, aggregate
);
46 /* Aggregate count increment check. */
47 void ripng_aggregate_increment(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. */
60 void ripng_aggregate_decrement(struct agg_node
*child
, struct ripng_info
*rinfo
)
63 struct ripng_aggregate
*aggregate
;
65 for (np
= child
; np
; np
= agg_node_parent(np
))
66 if ((aggregate
= np
->aggregate
) != NULL
) {
72 /* Aggregate count decrement check for a list. */
73 void ripng_aggregate_decrement_list(struct agg_node
*child
, struct list
*list
)
76 struct ripng_aggregate
*aggregate
;
77 struct ripng_info
*rinfo
= NULL
;
78 struct listnode
*node
= NULL
;
80 for (np
= child
; np
; np
= agg_node_parent(np
))
81 if ((aggregate
= np
->aggregate
) != NULL
)
82 aggregate
->count
-= listcount(list
);
84 for (ALL_LIST_ELEMENTS_RO(list
, node
, rinfo
))
88 /* RIPng routes treatment. */
89 int ripng_aggregate_add(struct ripng
*ripng
, struct prefix
*p
)
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
;
99 /* Get top node for aggregation. */
100 top
= agg_node_get(ripng
->table
, p
);
102 /* Allocate new aggregate. */
103 aggregate
= ripng_aggregate_new();
104 aggregate
->metric
= 1;
106 top
->aggregate
= aggregate
;
108 /* Suppress routes match to the aggregate. */
109 for (rp
= agg_lock_node(top
); rp
; rp
= agg_route_next_until(rp
, top
)) {
110 /* Suppress normal route. */
111 if ((list
= rp
->info
) != NULL
)
112 for (ALL_LIST_ELEMENTS_RO(list
, node
, rinfo
)) {
116 /* Suppress aggregate route. This may not need. */
117 if (rp
!= top
&& (sub
= rp
->aggregate
) != NULL
) {
126 /* Delete RIPng static route. */
127 int ripng_aggregate_delete(struct ripng
*ripng
, struct prefix
*p
)
129 struct agg_node
*top
;
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
;
137 /* Get top node for aggregation. */
138 top
= agg_node_get(ripng
->table
, p
);
140 /* Allocate new aggregate. */
141 aggregate
= top
->aggregate
;
143 /* Suppress routes match to the aggregate. */
144 for (rp
= agg_lock_node(top
); rp
; rp
= agg_route_next_until(rp
, top
)) {
145 /* Suppress normal route. */
146 if ((list
= rp
->info
) != NULL
)
147 for (ALL_LIST_ELEMENTS_RO(list
, node
, rinfo
)) {
152 if (rp
!= top
&& (sub
= rp
->aggregate
) != NULL
) {
158 top
->aggregate
= NULL
;
159 ripng_aggregate_free(aggregate
);
161 agg_unlock_node(top
);
162 agg_unlock_node(top
);