]>
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
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
31 #include "ripngd/ripngd.h"
32 #include "ripngd/ripng_route.h"
34 static struct ripng_aggregate
*ripng_aggregate_new(void)
36 struct ripng_aggregate
*new;
38 new = XCALLOC(MTYPE_RIPNG_AGGREGATE
, sizeof(struct ripng_aggregate
));
42 void ripng_aggregate_free(struct ripng_aggregate
*aggregate
)
44 XFREE(MTYPE_RIPNG_AGGREGATE
, aggregate
);
47 /* Aggregate count increment check. */
48 void ripng_aggregate_increment(struct route_node
*child
,
49 struct ripng_info
*rinfo
)
51 struct route_node
*np
;
52 struct ripng_aggregate
*aggregate
;
54 for (np
= child
; np
; np
= np
->parent
)
55 if ((aggregate
= np
->aggregate
) != NULL
) {
61 /* Aggregate count decrement check. */
62 void ripng_aggregate_decrement(struct route_node
*child
,
63 struct ripng_info
*rinfo
)
65 struct route_node
*np
;
66 struct ripng_aggregate
*aggregate
;
68 for (np
= child
; np
; np
= np
->parent
)
69 if ((aggregate
= np
->aggregate
) != NULL
) {
75 /* Aggregate count decrement check for a list. */
76 void ripng_aggregate_decrement_list(struct route_node
*child
, struct list
*list
)
78 struct route_node
*np
;
79 struct ripng_aggregate
*aggregate
;
80 struct ripng_info
*rinfo
= NULL
;
81 struct listnode
*node
= NULL
;
83 for (np
= child
; np
; np
= np
->parent
)
84 if ((aggregate
= np
->aggregate
) != NULL
)
85 aggregate
->count
-= listcount(list
);
87 for (ALL_LIST_ELEMENTS_RO(list
, node
, rinfo
))
91 /* RIPng routes treatment. */
92 int ripng_aggregate_add(struct prefix
*p
)
94 struct route_node
*top
;
95 struct route_node
*rp
;
96 struct ripng_info
*rinfo
;
97 struct ripng_aggregate
*aggregate
;
98 struct ripng_aggregate
*sub
;
99 struct list
*list
= NULL
;
100 struct listnode
*node
= NULL
;
102 /* Get top node for aggregation. */
103 top
= route_node_get(ripng
->table
, p
);
105 /* Allocate new aggregate. */
106 aggregate
= ripng_aggregate_new();
107 aggregate
->metric
= 1;
109 top
->aggregate
= aggregate
;
111 /* Suppress routes match to the aggregate. */
112 for (rp
= route_lock_node(top
); rp
; rp
= route_next_until(rp
, top
)) {
113 /* Suppress normal route. */
114 if ((list
= rp
->info
) != NULL
)
115 for (ALL_LIST_ELEMENTS_RO(list
, node
, rinfo
)) {
119 /* Suppress aggregate route. This may not need. */
120 if (rp
!= top
&& (sub
= rp
->aggregate
) != NULL
) {
129 /* Delete RIPng static route. */
130 int ripng_aggregate_delete(struct prefix
*p
)
132 struct route_node
*top
;
133 struct route_node
*rp
;
134 struct ripng_info
*rinfo
;
135 struct ripng_aggregate
*aggregate
;
136 struct ripng_aggregate
*sub
;
137 struct list
*list
= NULL
;
138 struct listnode
*node
= NULL
;
140 /* Get top node for aggregation. */
141 top
= route_node_get(ripng
->table
, p
);
143 /* Allocate new aggregate. */
144 aggregate
= top
->aggregate
;
146 /* Suppress routes match to the aggregate. */
147 for (rp
= route_lock_node(top
); rp
; rp
= route_next_until(rp
, top
)) {
148 /* Suppress normal route. */
149 if ((list
= rp
->info
) != NULL
)
150 for (ALL_LIST_ELEMENTS_RO(list
, node
, rinfo
)) {
155 if (rp
!= top
&& (sub
= rp
->aggregate
) != NULL
) {
161 top
->aggregate
= NULL
;
162 ripng_aggregate_free(aggregate
);
164 route_unlock_node(top
);
165 route_unlock_node(top
);