]>
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
30 #include "ripngd/ripngd.h"
31 #include "ripngd/ripng_route.h"
33 static struct ripng_aggregate
*
34 ripng_aggregate_new (void)
36 struct ripng_aggregate
*new;
38 new = XCALLOC (MTYPE_RIPNG_AGGREGATE
, sizeof (struct ripng_aggregate
));
43 ripng_aggregate_free (struct ripng_aggregate
*aggregate
)
45 XFREE (MTYPE_RIPNG_AGGREGATE
, aggregate
);
48 /* Aggregate count increment check. */
50 ripng_aggregate_increment (struct route_node
*child
, struct ripng_info
*rinfo
)
52 struct route_node
*np
;
53 struct ripng_aggregate
*aggregate
;
55 for (np
= child
; np
; np
= np
->parent
)
56 if ((aggregate
= np
->aggregate
) != NULL
)
63 /* Aggregate count decrement check. */
65 ripng_aggregate_decrement (struct route_node
*child
, struct ripng_info
*rinfo
)
67 struct route_node
*np
;
68 struct ripng_aggregate
*aggregate
;
70 for (np
= child
; np
; np
= np
->parent
)
71 if ((aggregate
= np
->aggregate
) != NULL
)
78 /* Aggregate count decrement check for a list. */
80 ripng_aggregate_decrement_list (struct route_node
*child
, struct list
*list
)
82 struct route_node
*np
;
83 struct ripng_aggregate
*aggregate
;
84 struct ripng_info
*rinfo
= NULL
;
85 struct listnode
*node
= NULL
;
87 for (np
= child
; np
; np
= np
->parent
)
88 if ((aggregate
= np
->aggregate
) != NULL
)
89 aggregate
->count
-= listcount (list
);
91 for (ALL_LIST_ELEMENTS_RO (list
, node
, rinfo
))
95 /* RIPng routes treatment. */
97 ripng_aggregate_add (struct prefix
*p
)
99 struct route_node
*top
;
100 struct route_node
*rp
;
101 struct ripng_info
*rinfo
;
102 struct ripng_aggregate
*aggregate
;
103 struct ripng_aggregate
*sub
;
104 struct list
*list
= NULL
;
105 struct listnode
*node
= NULL
;
107 /* Get top node for aggregation. */
108 top
= route_node_get (ripng
->table
, p
);
110 /* Allocate new aggregate. */
111 aggregate
= ripng_aggregate_new ();
112 aggregate
->metric
= 1;
114 top
->aggregate
= aggregate
;
116 /* Suppress routes match to the aggregate. */
117 for (rp
= route_lock_node (top
); rp
; rp
= route_next_until (rp
, top
))
119 /* Suppress normal route. */
120 if ((list
= rp
->info
) != NULL
)
121 for (ALL_LIST_ELEMENTS_RO (list
, node
, rinfo
))
126 /* Suppress aggregate route. This may not need. */
127 if (rp
!= top
&& (sub
= rp
->aggregate
) != NULL
)
137 /* Delete RIPng static route. */
139 ripng_aggregate_delete (struct prefix
*p
)
141 struct route_node
*top
;
142 struct route_node
*rp
;
143 struct ripng_info
*rinfo
;
144 struct ripng_aggregate
*aggregate
;
145 struct ripng_aggregate
*sub
;
146 struct list
*list
= NULL
;
147 struct listnode
*node
= NULL
;
149 /* Get top node for aggregation. */
150 top
= route_node_get (ripng
->table
, p
);
152 /* Allocate new aggregate. */
153 aggregate
= top
->aggregate
;
155 /* Suppress routes match to the aggregate. */
156 for (rp
= route_lock_node (top
); rp
; rp
= route_next_until (rp
, top
))
158 /* Suppress normal route. */
159 if ((list
= rp
->info
) != NULL
)
160 for (ALL_LIST_ELEMENTS_RO (list
, node
, rinfo
))
166 if (rp
!= top
&& (sub
= rp
->aggregate
) != NULL
)
173 top
->aggregate
= NULL
;
174 ripng_aggregate_free (aggregate
);
176 route_unlock_node (top
);
177 route_unlock_node (top
);