Tomato 1.28
[tomato.git] / release / src / router / zebra / ospf6d / ospf6_area.c
blob7a9e7b51a5c583c218b7724a4a15d36a5a539f12
1 /*
2 * OSPF6 Area Data Structure
3 * Copyright (C) 1999 Yasuhiro Ohara
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
10 * later version.
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
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #include "ospf6d.h"
25 static void
26 ospf6_area_foreach_interface (struct ospf6_area *o6a, void *arg, int val,
27 void (*func) (void *, int, void *))
29 listnode node;
30 struct ospf6_interface *o6i;
32 for (node = listhead (o6a->if_list); node; nextnode (node))
34 o6i = (struct ospf6_interface *) getdata (node);
35 (*func) (arg, val, o6i);
39 static void
40 ospf6_area_foreach_neighbor (struct ospf6_area *o6a, void *arg, int val,
41 void (*func) (void *, int, void *))
43 listnode node;
44 struct ospf6_interface *o6i;
46 for (node = listhead (o6a->if_list); node; nextnode (node))
48 o6i = (struct ospf6_interface *) getdata (node);
49 (*o6i->foreach_nei) (o6i, arg, val, func);
53 static int
54 ospf6_area_maxage_remover (struct thread *t)
56 int count;
57 struct ospf6_area *o6a = (struct ospf6_area *) THREAD_ARG (t);
59 o6a->maxage_remover = (struct thread *) NULL;
61 count = 0;
62 o6a->foreach_nei (o6a, &count, NBS_EXCHANGE, ospf6_count_state);
63 o6a->foreach_nei (o6a, &count, NBS_LOADING, ospf6_count_state);
64 if (count != 0)
65 return 0;
67 ospf6_lsdb_remove_maxage (o6a->lsdb);
68 return 0;
71 void
72 ospf6_area_schedule_maxage_remover (void *arg, int val, void *obj)
74 struct ospf6_area *o6a = (struct ospf6_area *) obj;
76 if (o6a->maxage_remover != NULL)
77 return;
79 o6a->maxage_remover =
80 thread_add_event (master, ospf6_area_maxage_remover, o6a, 0);
83 int
84 ospf6_area_is_stub (struct ospf6_area *o6a)
86 if (OSPF6_OPT_ISSET (o6a->options, OSPF6_OPT_E))
87 return 0;
88 return 1;
91 int
92 ospf6_area_is_transit (struct ospf6_area *o6a)
94 return 0;
97 /* Make new area structure */
98 struct ospf6_area *
99 ospf6_area_create (u_int32_t area_id)
101 struct ospf6_area *o6a;
103 /* allocate memory */
104 o6a = (struct ospf6_area *) XMALLOC (MTYPE_OSPF6_AREA,
105 sizeof (struct ospf6_area));
106 if (!o6a)
108 char str[16];
109 inet_ntop (AF_INET, &area_id, str, sizeof (str));
110 zlog_err ("can't allocate memory for Area %s", str);
111 return NULL;
114 /* initialize */
115 memset (o6a, 0, sizeof (struct ospf6_area));
116 inet_ntop (AF_INET, &area_id, o6a->str, sizeof (o6a->str));
117 o6a->area_id = area_id;
118 o6a->if_list = list_new ();
120 #if 0
121 o6a->lsdb = list_new ();
122 #endif
123 o6a->lsdb = ospf6_lsdb_create ();
125 o6a->spf_tree = ospf6_spftree_create ();
126 o6a->table_topology = route_table_init ();
128 /* xxx, set options */
129 OSPF6_OPT_SET (o6a->options, OSPF6_OPT_V6);
130 OSPF6_OPT_SET (o6a->options, OSPF6_OPT_E);
131 OSPF6_OPT_SET (o6a->options, OSPF6_OPT_R);
133 o6a->foreach_if = ospf6_area_foreach_interface;
134 o6a->foreach_nei = ospf6_area_foreach_neighbor;
136 return o6a;
139 void
140 ospf6_area_delete (struct ospf6_area *o6a)
142 listnode n;
143 struct ospf6_interface *o6i;
145 /* ospf6 interface list */
146 for (n = listhead (o6a->if_list); n; nextnode (n))
148 o6i = (struct ospf6_interface *) getdata (n);
149 /* ospf6_interface_delete (o6i); */
151 list_delete (o6a->if_list);
153 /* terminate LSDB */
154 ospf6_lsdb_remove_all (o6a->lsdb);
156 /* spf tree terminate */
157 /* xxx */
159 /* threads */
160 if (o6a->spf_calc)
161 thread_cancel (o6a->spf_calc);
162 o6a->spf_calc = (struct thread *) NULL;
163 if (o6a->route_calc)
164 thread_cancel (o6a->route_calc);
165 o6a->route_calc = (struct thread *) NULL;
167 /* new */
168 ospf6_spftree_delete (o6a->spf_tree);
169 ospf6_route_delete_all (o6a->table_topology);
170 route_table_finish (o6a->table_topology);
172 /* free area */
173 XFREE (MTYPE_OSPF6_AREA, o6a);
176 struct ospf6_area *
177 ospf6_area_lookup (u_int32_t area_id, struct ospf6 *o6)
179 struct ospf6_area *o6a;
180 listnode n;
182 for (n = listhead (o6->area_list); n; nextnode (n))
184 o6a = (struct ospf6_area *) getdata (n);
185 if (o6a->area_id == area_id)
186 return o6a;
189 return (struct ospf6_area *) NULL;
192 void
193 ospf6_area_show (struct vty *vty, struct ospf6_area *o6a)
195 listnode i;
196 struct ospf6_interface *o6i;
198 vty_out (vty, " Area %s%s", o6a->str, VTY_NEWLINE);
199 vty_out (vty, " Number of Area scoped LSAs is %u%s",
200 o6a->lsdb->count, VTY_NEWLINE);
202 ospf6_spf_statistics_show (vty, o6a->spf_tree);
204 vty_out (vty, " Interface attached to this area:");
205 for (i = listhead (o6a->if_list); i; nextnode (i))
207 o6i = (struct ospf6_interface *) getdata (i);
208 vty_out (vty, " %s", o6i->interface->name);
210 vty_out (vty, "%s", VTY_NEWLINE);
212 for (i = listhead (o6a->if_list); i; nextnode (i))
214 o6i = (struct ospf6_interface *) getdata (i);
215 if (listcount (o6i->neighbor_list) != 0)
216 ospf6_interface_statistics_show (vty, o6i);
220 void
221 ospf6_area_statistics_show (struct vty *vty, struct ospf6_area *o6a)
223 #if 0
224 listnode node;
225 struct ospf6_interface *o6i;
227 vty_out (vty, " Statistics of Area %s%s", o6a->str, VTY_NEWLINE);
228 #endif