blob: d73d996b144e883a48ee664ecb36bdd96dac2019 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/*
hasso508e53e2004-05-18 18:57:06 +00002 * Copyright (C) 2003 Yasuhiro Ohara
paul718e3742002-12-13 20:15:29 +00003 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 */
21
hasso508e53e2004-05-18 18:57:06 +000022#include <zebra.h>
23
24#include "log.h"
25#include "memory.h"
26#include "linklist.h"
27#include "thread.h"
28#include "vty.h"
29#include "command.h"
30#include "if.h"
31#include "prefix.h"
32#include "table.h"
hasso34956b32005-06-24 08:44:02 +000033#include "plist.h"
34#include "filter.h"
hasso508e53e2004-05-18 18:57:06 +000035
hasso508e53e2004-05-18 18:57:06 +000036#include "ospf6_proto.h"
37#include "ospf6_lsa.h"
38#include "ospf6_lsdb.h"
39#include "ospf6_route.h"
40#include "ospf6_spf.h"
41#include "ospf6_top.h"
42#include "ospf6_area.h"
43#include "ospf6_interface.h"
44#include "ospf6_intra.h"
hasso049207c2004-08-04 20:02:13 +000045#include "ospf6_abr.h"
46#include "ospf6d.h"
paul718e3742002-12-13 20:15:29 +000047
hasso508e53e2004-05-18 18:57:06 +000048int
49ospf6_area_cmp (void *va, void *vb)
paul718e3742002-12-13 20:15:29 +000050{
hasso508e53e2004-05-18 18:57:06 +000051 struct ospf6_area *oa = (struct ospf6_area *) va;
52 struct ospf6_area *ob = (struct ospf6_area *) vb;
hasso6452df02004-08-15 05:52:07 +000053 return (ntohl (oa->area_id) < ntohl (ob->area_id) ? -1 : 1);
paul718e3742002-12-13 20:15:29 +000054}
55
hasso508e53e2004-05-18 18:57:06 +000056/* schedule routing table recalculation */
Paul Jakma6ac29a52008-08-15 13:45:30 +010057static void
hasso508e53e2004-05-18 18:57:06 +000058ospf6_area_lsdb_hook_add (struct ospf6_lsa *lsa)
paul718e3742002-12-13 20:15:29 +000059{
hasso508e53e2004-05-18 18:57:06 +000060 switch (ntohs (lsa->header->type))
paul718e3742002-12-13 20:15:29 +000061 {
hasso508e53e2004-05-18 18:57:06 +000062 case OSPF6_LSTYPE_ROUTER:
63 case OSPF6_LSTYPE_NETWORK:
hasso1e058382004-09-01 21:36:14 +000064 if (IS_OSPF6_DEBUG_EXAMIN_TYPE (lsa->header->type))
65 {
hassoc6487d62004-12-24 06:00:11 +000066 zlog_debug ("Examin %s", lsa->name);
67 zlog_debug ("Schedule SPF Calculation for %s",
68 OSPF6_AREA (lsa->lsdb->data)->name);
hasso1e058382004-09-01 21:36:14 +000069 }
hasso6452df02004-08-15 05:52:07 +000070 ospf6_spf_schedule (OSPF6_AREA (lsa->lsdb->data));
hasso508e53e2004-05-18 18:57:06 +000071 break;
paul718e3742002-12-13 20:15:29 +000072
hasso508e53e2004-05-18 18:57:06 +000073 case OSPF6_LSTYPE_INTRA_PREFIX:
74 ospf6_intra_prefix_lsa_add (lsa);
75 break;
76
77 case OSPF6_LSTYPE_INTER_PREFIX:
78 case OSPF6_LSTYPE_INTER_ROUTER:
hassoccb59b12004-08-25 09:10:37 +000079 ospf6_abr_examin_summary (lsa, (struct ospf6_area *) lsa->lsdb->data);
hasso508e53e2004-05-18 18:57:06 +000080 break;
81
82 default:
hasso508e53e2004-05-18 18:57:06 +000083 break;
84 }
paul718e3742002-12-13 20:15:29 +000085}
86
Paul Jakma6ac29a52008-08-15 13:45:30 +010087static void
hasso508e53e2004-05-18 18:57:06 +000088ospf6_area_lsdb_hook_remove (struct ospf6_lsa *lsa)
paul718e3742002-12-13 20:15:29 +000089{
hasso508e53e2004-05-18 18:57:06 +000090 switch (ntohs (lsa->header->type))
paul718e3742002-12-13 20:15:29 +000091 {
hasso508e53e2004-05-18 18:57:06 +000092 case OSPF6_LSTYPE_ROUTER:
93 case OSPF6_LSTYPE_NETWORK:
hasso1e058382004-09-01 21:36:14 +000094 if (IS_OSPF6_DEBUG_EXAMIN_TYPE (lsa->header->type))
95 {
hassoc6487d62004-12-24 06:00:11 +000096 zlog_debug ("LSA disappearing: %s", lsa->name);
97 zlog_debug ("Schedule SPF Calculation for %s",
hasso1e058382004-09-01 21:36:14 +000098 OSPF6_AREA (lsa->lsdb->data)->name);
99 }
hasso6452df02004-08-15 05:52:07 +0000100 ospf6_spf_schedule (OSPF6_AREA (lsa->lsdb->data));
hasso508e53e2004-05-18 18:57:06 +0000101 break;
paul718e3742002-12-13 20:15:29 +0000102
hasso508e53e2004-05-18 18:57:06 +0000103 case OSPF6_LSTYPE_INTRA_PREFIX:
104 ospf6_intra_prefix_lsa_remove (lsa);
105 break;
106
107 case OSPF6_LSTYPE_INTER_PREFIX:
108 case OSPF6_LSTYPE_INTER_ROUTER:
hassoccb59b12004-08-25 09:10:37 +0000109 ospf6_abr_examin_summary (lsa, (struct ospf6_area *) lsa->lsdb->data);
hasso508e53e2004-05-18 18:57:06 +0000110 break;
111
112 default:
hasso508e53e2004-05-18 18:57:06 +0000113 break;
114 }
115}
116
Paul Jakma6ac29a52008-08-15 13:45:30 +0100117static void
hasso508e53e2004-05-18 18:57:06 +0000118ospf6_area_route_hook_add (struct ospf6_route *route)
119{
120 struct ospf6_route *copy = ospf6_route_copy (route);
121 ospf6_route_add (copy, ospf6->route_table);
122}
123
Paul Jakma6ac29a52008-08-15 13:45:30 +0100124static void
hasso508e53e2004-05-18 18:57:06 +0000125ospf6_area_route_hook_remove (struct ospf6_route *route)
126{
127 struct ospf6_route *copy;
128
129 copy = ospf6_route_lookup_identical (route, ospf6->route_table);
130 if (copy)
131 ospf6_route_remove (copy, ospf6->route_table);
paul718e3742002-12-13 20:15:29 +0000132}
133
134/* Make new area structure */
135struct ospf6_area *
hasso508e53e2004-05-18 18:57:06 +0000136ospf6_area_create (u_int32_t area_id, struct ospf6 *o)
paul718e3742002-12-13 20:15:29 +0000137{
hasso508e53e2004-05-18 18:57:06 +0000138 struct ospf6_area *oa;
hasso049207c2004-08-04 20:02:13 +0000139 struct ospf6_route *route;
paul718e3742002-12-13 20:15:29 +0000140
hasso508e53e2004-05-18 18:57:06 +0000141 oa = XCALLOC (MTYPE_OSPF6_AREA, sizeof (struct ospf6_area));
paul718e3742002-12-13 20:15:29 +0000142
hasso508e53e2004-05-18 18:57:06 +0000143 inet_ntop (AF_INET, &area_id, oa->name, sizeof (oa->name));
144 oa->area_id = area_id;
145 oa->if_list = list_new ();
paul718e3742002-12-13 20:15:29 +0000146
hasso6452df02004-08-15 05:52:07 +0000147 oa->lsdb = ospf6_lsdb_create (oa);
hasso508e53e2004-05-18 18:57:06 +0000148 oa->lsdb->hook_add = ospf6_area_lsdb_hook_add;
149 oa->lsdb->hook_remove = ospf6_area_lsdb_hook_remove;
hasso6452df02004-08-15 05:52:07 +0000150 oa->lsdb_self = ospf6_lsdb_create (oa);
paul718e3742002-12-13 20:15:29 +0000151
Paul Jakmacf1ce252006-05-15 10:46:07 +0000152 oa->spf_table = OSPF6_ROUTE_TABLE_CREATE (AREA, SPF_RESULTS);
153 oa->spf_table->scope = oa;
154 oa->route_table = OSPF6_ROUTE_TABLE_CREATE (AREA, ROUTES);
155 oa->route_table->scope = oa;
hasso508e53e2004-05-18 18:57:06 +0000156 oa->route_table->hook_add = ospf6_area_route_hook_add;
157 oa->route_table->hook_remove = ospf6_area_route_hook_remove;
paul718e3742002-12-13 20:15:29 +0000158
Paul Jakmacf1ce252006-05-15 10:46:07 +0000159 oa->range_table = OSPF6_ROUTE_TABLE_CREATE (AREA, PREFIX_RANGES);
160 oa->range_table->scope = oa;
161 oa->summary_prefix = OSPF6_ROUTE_TABLE_CREATE (AREA, SUMMARY_PREFIXES);
162 oa->summary_prefix->scope = oa;
163 oa->summary_router = OSPF6_ROUTE_TABLE_CREATE (AREA, SUMMARY_ROUTERS);
164 oa->summary_router->scope = oa;
hasso6452df02004-08-15 05:52:07 +0000165
hasso508e53e2004-05-18 18:57:06 +0000166 /* set default options */
167 OSPF6_OPT_SET (oa->options, OSPF6_OPT_V6);
168 OSPF6_OPT_SET (oa->options, OSPF6_OPT_E);
169 OSPF6_OPT_SET (oa->options, OSPF6_OPT_R);
paul718e3742002-12-13 20:15:29 +0000170
hasso508e53e2004-05-18 18:57:06 +0000171 oa->ospf6 = o;
172 listnode_add_sort (o->area_list, oa);
paul718e3742002-12-13 20:15:29 +0000173
hasso049207c2004-08-04 20:02:13 +0000174 /* import athoer area's routes as inter-area routes */
175 for (route = ospf6_route_head (o->route_table); route;
176 route = ospf6_route_next (route))
hasso6452df02004-08-15 05:52:07 +0000177 ospf6_abr_originate_summary_to_area (route, oa);
hasso049207c2004-08-04 20:02:13 +0000178
hasso508e53e2004-05-18 18:57:06 +0000179 return oa;
paul718e3742002-12-13 20:15:29 +0000180}
181
182void
hasso508e53e2004-05-18 18:57:06 +0000183ospf6_area_delete (struct ospf6_area *oa)
paul718e3742002-12-13 20:15:29 +0000184{
paul1eb8ef22005-04-07 07:30:20 +0000185 struct listnode *n, *nnode;
hasso508e53e2004-05-18 18:57:06 +0000186 struct ospf6_interface *oi;
paul718e3742002-12-13 20:15:29 +0000187
hasso6452df02004-08-15 05:52:07 +0000188 ospf6_route_table_delete (oa->range_table);
189 ospf6_route_table_delete (oa->summary_prefix);
190 ospf6_route_table_delete (oa->summary_router);
hasso049207c2004-08-04 20:02:13 +0000191
paul718e3742002-12-13 20:15:29 +0000192 /* ospf6 interface list */
paul1eb8ef22005-04-07 07:30:20 +0000193 for (ALL_LIST_ELEMENTS (oa->if_list, n, nnode, oi))
paul718e3742002-12-13 20:15:29 +0000194 {
hasso508e53e2004-05-18 18:57:06 +0000195 ospf6_interface_delete (oi);
paul718e3742002-12-13 20:15:29 +0000196 }
hasso508e53e2004-05-18 18:57:06 +0000197 list_delete (oa->if_list);
paul718e3742002-12-13 20:15:29 +0000198
hasso508e53e2004-05-18 18:57:06 +0000199 ospf6_lsdb_delete (oa->lsdb);
hasso6452df02004-08-15 05:52:07 +0000200 ospf6_lsdb_delete (oa->lsdb_self);
201
hasso508e53e2004-05-18 18:57:06 +0000202 ospf6_route_table_delete (oa->spf_table);
203 ospf6_route_table_delete (oa->route_table);
paul718e3742002-12-13 20:15:29 +0000204
hasso508e53e2004-05-18 18:57:06 +0000205 THREAD_OFF (oa->thread_spf_calculation);
206 THREAD_OFF (oa->thread_route_calculation);
paul718e3742002-12-13 20:15:29 +0000207
hasso508e53e2004-05-18 18:57:06 +0000208 listnode_delete (oa->ospf6->area_list, oa);
209 oa->ospf6 = NULL;
paul718e3742002-12-13 20:15:29 +0000210
211 /* free area */
hasso508e53e2004-05-18 18:57:06 +0000212 XFREE (MTYPE_OSPF6_AREA, oa);
paul718e3742002-12-13 20:15:29 +0000213}
214
215struct ospf6_area *
hasso508e53e2004-05-18 18:57:06 +0000216ospf6_area_lookup (u_int32_t area_id, struct ospf6 *ospf6)
paul718e3742002-12-13 20:15:29 +0000217{
hasso508e53e2004-05-18 18:57:06 +0000218 struct ospf6_area *oa;
hasso52dc7ee2004-09-23 19:18:23 +0000219 struct listnode *n;
paul718e3742002-12-13 20:15:29 +0000220
paul1eb8ef22005-04-07 07:30:20 +0000221 for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, n, oa))
222 if (oa->area_id == area_id)
223 return oa;
paul718e3742002-12-13 20:15:29 +0000224
225 return (struct ospf6_area *) NULL;
226}
227
Paul Jakma6ac29a52008-08-15 13:45:30 +0100228static struct ospf6_area *
hasso6452df02004-08-15 05:52:07 +0000229ospf6_area_get (u_int32_t area_id, struct ospf6 *o)
230{
231 struct ospf6_area *oa;
232 oa = ospf6_area_lookup (area_id, o);
233 if (oa == NULL)
234 oa = ospf6_area_create (area_id, o);
235 return oa;
236}
237
paul718e3742002-12-13 20:15:29 +0000238void
hasso508e53e2004-05-18 18:57:06 +0000239ospf6_area_enable (struct ospf6_area *oa)
paul718e3742002-12-13 20:15:29 +0000240{
paul1eb8ef22005-04-07 07:30:20 +0000241 struct listnode *node, *nnode;
hasso508e53e2004-05-18 18:57:06 +0000242 struct ospf6_interface *oi;
paul718e3742002-12-13 20:15:29 +0000243
hasso6452df02004-08-15 05:52:07 +0000244 SET_FLAG (oa->flag, OSPF6_AREA_ENABLE);
paul718e3742002-12-13 20:15:29 +0000245
paul1eb8ef22005-04-07 07:30:20 +0000246 for (ALL_LIST_ELEMENTS (oa->if_list, node, nnode, oi))
247 ospf6_interface_enable (oi);
paul718e3742002-12-13 20:15:29 +0000248}
249
250void
hasso508e53e2004-05-18 18:57:06 +0000251ospf6_area_disable (struct ospf6_area *oa)
paul718e3742002-12-13 20:15:29 +0000252{
paul1eb8ef22005-04-07 07:30:20 +0000253 struct listnode *node, *nnode;
hasso508e53e2004-05-18 18:57:06 +0000254 struct ospf6_interface *oi;
paul718e3742002-12-13 20:15:29 +0000255
hasso6452df02004-08-15 05:52:07 +0000256 UNSET_FLAG (oa->flag, OSPF6_AREA_ENABLE);
hasso508e53e2004-05-18 18:57:06 +0000257
paul1eb8ef22005-04-07 07:30:20 +0000258 for (ALL_LIST_ELEMENTS (oa->if_list, node, nnode, oi))
259 ospf6_interface_disable (oi);
paul718e3742002-12-13 20:15:29 +0000260}
261
hasso508e53e2004-05-18 18:57:06 +0000262
263void
264ospf6_area_show (struct vty *vty, struct ospf6_area *oa)
265{
hasso52dc7ee2004-09-23 19:18:23 +0000266 struct listnode *i;
hasso508e53e2004-05-18 18:57:06 +0000267 struct ospf6_interface *oi;
268
hasso049207c2004-08-04 20:02:13 +0000269 vty_out (vty, " Area %s%s", oa->name, VNL);
hasso508e53e2004-05-18 18:57:06 +0000270 vty_out (vty, " Number of Area scoped LSAs is %u%s",
hasso049207c2004-08-04 20:02:13 +0000271 oa->lsdb->count, VNL);
hasso508e53e2004-05-18 18:57:06 +0000272
273 vty_out (vty, " Interface attached to this area:");
paul1eb8ef22005-04-07 07:30:20 +0000274 for (ALL_LIST_ELEMENTS_RO (oa->if_list, i, oi))
275 vty_out (vty, " %s", oi->interface->name);
276
hasso049207c2004-08-04 20:02:13 +0000277 vty_out (vty, "%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000278}
279
280
hasso049207c2004-08-04 20:02:13 +0000281#define OSPF6_CMD_AREA_LOOKUP(str, oa) \
282{ \
283 u_int32_t area_id = 0; \
284 if (inet_pton (AF_INET, str, &area_id) != 1) \
285 { \
286 vty_out (vty, "Malformed Area-ID: %s%s", str, VNL); \
287 return CMD_SUCCESS; \
288 } \
289 oa = ospf6_area_lookup (area_id, ospf6); \
290 if (oa == NULL) \
291 { \
292 vty_out (vty, "No such Area: %s%s", str, VNL); \
293 return CMD_SUCCESS; \
294 } \
hasso508e53e2004-05-18 18:57:06 +0000295}
296
hasso6452df02004-08-15 05:52:07 +0000297#define OSPF6_CMD_AREA_GET(str, oa) \
298{ \
299 u_int32_t area_id = 0; \
300 if (inet_pton (AF_INET, str, &area_id) != 1) \
301 { \
302 vty_out (vty, "Malformed Area-ID: %s%s", str, VNL); \
303 return CMD_SUCCESS; \
304 } \
305 oa = ospf6_area_get (area_id, ospf6); \
306}
307
308DEFUN (area_range,
309 area_range_cmd,
310 "area A.B.C.D range X:X::X:X/M",
311 "OSPF area parameters\n"
312 OSPF6_AREA_ID_STR
313 "Configured address range\n"
314 "Specify IPv6 prefix\n"
315 )
316{
317 int ret;
318 struct ospf6_area *oa;
319 struct prefix prefix;
320 struct ospf6_route *range;
321
322 OSPF6_CMD_AREA_GET (argv[0], oa);
323 argc--;
324 argv++;
325
326 ret = str2prefix (argv[0], &prefix);
327 if (ret != 1 || prefix.family != AF_INET6)
328 {
329 vty_out (vty, "Malformed argument: %s%s", argv[0], VNL);
330 return CMD_SUCCESS;
331 }
332 argc--;
333 argv++;
334
335 range = ospf6_route_lookup (&prefix, oa->range_table);
336 if (range == NULL)
337 {
338 range = ospf6_route_create ();
339 range->type = OSPF6_DEST_TYPE_RANGE;
340 range->prefix = prefix;
341 }
342
343 if (argc)
344 {
345 if (! strcmp (argv[0], "not-advertise"))
346 SET_FLAG (range->flag, OSPF6_ROUTE_DO_NOT_ADVERTISE);
347 else if (! strcmp (argv[0], "advertise"))
348 UNSET_FLAG (range->flag, OSPF6_ROUTE_DO_NOT_ADVERTISE);
349 }
350
Jon86f9e5a2009-02-11 17:22:03 -0800351 if (range->rnode)
352 {
353 vty_out (vty, "Range already defined: %s%s", argv[-1], VNL);
354 return CMD_WARNING;
355 }
356
hasso6452df02004-08-15 05:52:07 +0000357 ospf6_route_add (range, oa->range_table);
358 return CMD_SUCCESS;
359}
360
361ALIAS (area_range,
362 area_range_advertise_cmd,
363 "area A.B.C.D range X:X::X:X/M (advertise|not-advertise)",
364 "OSPF area parameters\n"
365 OSPF6_AREA_ID_STR
366 "Configured address range\n"
367 "Specify IPv6 prefix\n"
Paul Jakma6ac29a52008-08-15 13:45:30 +0100368 )
hasso6452df02004-08-15 05:52:07 +0000369
370DEFUN (no_area_range,
371 no_area_range_cmd,
372 "no area A.B.C.D range X:X::X:X/M",
373 "OSPF area parameters\n"
374 OSPF6_AREA_ID_STR
375 "Configured address range\n"
376 "Specify IPv6 prefix\n"
377 )
378{
379 int ret;
380 struct ospf6_area *oa;
381 struct prefix prefix;
382 struct ospf6_route *range;
383
384 OSPF6_CMD_AREA_GET (argv[0], oa);
385 argc--;
386 argv++;
387
388 ret = str2prefix (argv[0], &prefix);
389 if (ret != 1 || prefix.family != AF_INET6)
390 {
391 vty_out (vty, "Malformed argument: %s%s", argv[0], VNL);
392 return CMD_SUCCESS;
393 }
394
395 range = ospf6_route_lookup (&prefix, oa->range_table);
396 if (range == NULL)
397 {
398 vty_out (vty, "Range %s does not exists.%s", argv[0], VNL);
399 return CMD_SUCCESS;
400 }
401
402 ospf6_route_remove (range, oa->range_table);
403 return CMD_SUCCESS;
404}
405
406void
407ospf6_area_config_write (struct vty *vty)
408{
hasso52dc7ee2004-09-23 19:18:23 +0000409 struct listnode *node;
hasso6452df02004-08-15 05:52:07 +0000410 struct ospf6_area *oa;
411 struct ospf6_route *range;
412 char buf[128];
413
paul1eb8ef22005-04-07 07:30:20 +0000414 for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, node, oa))
hasso6452df02004-08-15 05:52:07 +0000415 {
hasso6452df02004-08-15 05:52:07 +0000416 for (range = ospf6_route_head (oa->range_table); range;
417 range = ospf6_route_next (range))
418 {
419 prefix2str (&range->prefix, buf, sizeof (buf));
420 vty_out (vty, " area %s range %s%s", oa->name, buf, VNL);
421 }
422 }
423}
424
hasso34956b32005-06-24 08:44:02 +0000425DEFUN (area_filter_list,
426 area_filter_list_cmd,
427 "area A.B.C.D filter-list prefix WORD (in|out)",
428 "OSPFv6 area parameters\n"
429 "OSPFv6 area ID in IP address format\n"
430 "Filter networks between OSPFv6 areas\n"
431 "Filter prefixes between OSPFv6 areas\n"
432 "Name of an IPv6 prefix-list\n"
433 "Filter networks sent to this area\n"
434 "Filter networks sent from this area\n")
435{
436 struct ospf6_area *area;
437 struct prefix_list *plist;
438
439 OSPF6_CMD_AREA_GET (argv[0], area);
440 argc--;
441 argv++;
442
Christian Hammersc8049c12011-09-12 14:23:05 +0400443 plist = prefix_list_lookup (AFI_IP6, argv[0]);
444 if (strncmp (argv[1], "in", 2) == 0)
hasso34956b32005-06-24 08:44:02 +0000445 {
446 PREFIX_LIST_IN (area) = plist;
447 if (PREFIX_NAME_IN (area))
448 free (PREFIX_NAME_IN (area));
449
Christian Hammersc8049c12011-09-12 14:23:05 +0400450 PREFIX_NAME_IN (area) = strdup (argv[0]);
hasso34956b32005-06-24 08:44:02 +0000451 ospf6_abr_reimport (area);
452 }
453 else
454 {
455 PREFIX_LIST_OUT (area) = plist;
456 if (PREFIX_NAME_OUT (area))
457 free (PREFIX_NAME_OUT (area));
458
Christian Hammersc8049c12011-09-12 14:23:05 +0400459 PREFIX_NAME_OUT (area) = strdup (argv[0]);
hasso34956b32005-06-24 08:44:02 +0000460 ospf6_abr_enable_area (area);
461 }
462
463 return CMD_SUCCESS;
464}
465
466DEFUN (no_area_filter_list,
467 no_area_filter_list_cmd,
468 "no area A.B.C.D filter-list prefix WORD (in|out)",
469 NO_STR
470 "OSPFv6 area parameters\n"
471 "OSPFv6 area ID in IP address format\n"
472 "Filter networks between OSPFv6 areas\n"
473 "Filter prefixes between OSPFv6 areas\n"
474 "Name of an IPv6 prefix-list\n"
475 "Filter networks sent to this area\n"
476 "Filter networks sent from this area\n")
477{
478 struct ospf6_area *area;
479 struct prefix_list *plist;
480
481 OSPF6_CMD_AREA_GET (argv[0], area);
482 argc--;
483 argv++;
484
Christian Hammersc8049c12011-09-12 14:23:05 +0400485 plist = prefix_list_lookup (AFI_IP6, argv[0]);
486 if (strncmp (argv[1], "in", 2) == 0)
hasso34956b32005-06-24 08:44:02 +0000487 {
488 if (PREFIX_NAME_IN (area))
Christian Hammersc8049c12011-09-12 14:23:05 +0400489 if (strcmp (PREFIX_NAME_IN (area), argv[0]) != 0)
hasso34956b32005-06-24 08:44:02 +0000490 return CMD_SUCCESS;
491
492 PREFIX_LIST_IN (area) = NULL;
493 if (PREFIX_NAME_IN (area))
494 free (PREFIX_NAME_IN (area));
495
496 PREFIX_NAME_IN (area) = NULL;
497 ospf6_abr_reimport (area);
498 }
499 else
500 {
501 if (PREFIX_NAME_OUT (area))
Christian Hammersc8049c12011-09-12 14:23:05 +0400502 if (strcmp (PREFIX_NAME_OUT (area), argv[0]) != 0)
hasso34956b32005-06-24 08:44:02 +0000503 return CMD_SUCCESS;
504
505 PREFIX_LIST_OUT (area) = NULL;
506 if (PREFIX_NAME_OUT (area))
507 free (PREFIX_NAME_OUT (area));
508
509 PREFIX_NAME_OUT (area) = NULL;
510 ospf6_abr_enable_area (area);
511 }
512
513 return CMD_SUCCESS;
514}
515
516DEFUN (area_import_list,
517 area_import_list_cmd,
518 "area A.B.C.D import-list NAME",
519 "OSPFv6 area parameters\n"
520 "OSPFv6 area ID in IP address format\n"
521 "Set the filter for networks from other areas announced to the specified one\n"
522 "Name of the acess-list\n")
523{
524 struct ospf6_area *area;
525 struct access_list *list;
526
527 OSPF6_CMD_AREA_GET(argv[0], area);
528
529 list = access_list_lookup (AFI_IP6, argv[1]);
530
531 IMPORT_LIST (area) = list;
532
533 if (IMPORT_NAME (area))
534 free (IMPORT_NAME (area));
535
536 IMPORT_NAME (area) = strdup (argv[1]);
537 ospf6_abr_reimport (area);
538
539 return CMD_SUCCESS;
540}
541
542DEFUN (no_area_import_list,
543 no_area_import_list_cmd,
544 "no area A.B.C.D import-list NAME",
545 "OSPFv6 area parameters\n"
546 "OSPFv6 area ID in IP address format\n"
547 "Unset the filter for networks announced to other areas\n"
548 "NAme of the access-list\n")
549{
550 struct ospf6_area *area;
551
552 OSPF6_CMD_AREA_GET(argv[0], area);
553
554 IMPORT_LIST (area) = 0;
555
556 if (IMPORT_NAME (area))
557 free (IMPORT_NAME (area));
558
559 IMPORT_NAME (area) = NULL;
560 ospf6_abr_reimport (area);
561
562 return CMD_SUCCESS;
563}
564
565DEFUN (area_export_list,
566 area_export_list_cmd,
567 "area A.B.C.D export-list NAME",
568 "OSPFv6 area parameters\n"
569 "OSPFv6 area ID in IP address format\n"
570 "Set the filter for networks announced to other areas\n"
571 "Name of the acess-list\n")
572{
573 struct ospf6_area *area;
574 struct access_list *list;
575
576 OSPF6_CMD_AREA_GET(argv[0], area);
577
578 list = access_list_lookup (AFI_IP6, argv[1]);
579
580 EXPORT_LIST (area) = list;
581
582 if (EXPORT_NAME (area))
583 free (EXPORT_NAME (area));
584
585 EXPORT_NAME (area) = strdup (argv[1]);
586 ospf6_abr_enable_area (area);
587
588 return CMD_SUCCESS;
589}
590
591DEFUN (no_area_export_list,
592 no_area_export_list_cmd,
593 "no area A.B.C.D export-list NAME",
594 "OSPFv6 area parameters\n"
595 "OSPFv6 area ID in IP address format\n"
596 "Unset the filter for networks announced to other areas\n"
597 "Name of the access-list\n")
598{
599 struct ospf6_area *area;
600
601 OSPF6_CMD_AREA_GET(argv[0], area);
602
603 EXPORT_LIST (area) = 0;
604
605 if (EXPORT_NAME (area))
606 free (EXPORT_NAME (area));
607
608 EXPORT_NAME (area) = NULL;
609 ospf6_abr_enable_area (area);
610
611 return CMD_SUCCESS;
612}
613
hasso508e53e2004-05-18 18:57:06 +0000614DEFUN (show_ipv6_ospf6_spf_tree,
615 show_ipv6_ospf6_spf_tree_cmd,
616 "show ipv6 ospf6 spf tree",
617 SHOW_STR
618 IP6_STR
619 OSPF6_STR
620 "Shortest Path First caculation\n"
621 "Show SPF tree\n")
622{
hasso52dc7ee2004-09-23 19:18:23 +0000623 struct listnode *node;
hasso508e53e2004-05-18 18:57:06 +0000624 struct ospf6_area *oa;
625 struct ospf6_vertex *root;
626 struct ospf6_route *route;
627 struct prefix prefix;
628
629 ospf6_linkstate_prefix (ospf6->router_id, htonl (0), &prefix);
paul1eb8ef22005-04-07 07:30:20 +0000630
631 for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, node, oa))
hasso508e53e2004-05-18 18:57:06 +0000632 {
hasso508e53e2004-05-18 18:57:06 +0000633 route = ospf6_route_lookup (&prefix, oa->spf_table);
634 if (route == NULL)
635 {
636 vty_out (vty, "LS entry for root not found in area %s%s",
hasso049207c2004-08-04 20:02:13 +0000637 oa->name, VNL);
hasso508e53e2004-05-18 18:57:06 +0000638 continue;
639 }
640 root = (struct ospf6_vertex *) route->route_option;
641 ospf6_spf_display_subtree (vty, "", 0, root);
642 }
643
644 return CMD_SUCCESS;
645}
646
647DEFUN (show_ipv6_ospf6_area_spf_tree,
648 show_ipv6_ospf6_area_spf_tree_cmd,
649 "show ipv6 ospf6 area A.B.C.D spf tree",
650 SHOW_STR
651 IP6_STR
652 OSPF6_STR
653 OSPF6_AREA_STR
654 OSPF6_AREA_ID_STR
655 "Shortest Path First caculation\n"
656 "Show SPF tree\n")
657{
658 u_int32_t area_id;
659 struct ospf6_area *oa;
660 struct ospf6_vertex *root;
661 struct ospf6_route *route;
662 struct prefix prefix;
663
664 ospf6_linkstate_prefix (ospf6->router_id, htonl (0), &prefix);
665
666 if (inet_pton (AF_INET, argv[0], &area_id) != 1)
667 {
hasso049207c2004-08-04 20:02:13 +0000668 vty_out (vty, "Malformed Area-ID: %s%s", argv[0], VNL);
hasso508e53e2004-05-18 18:57:06 +0000669 return CMD_SUCCESS;
670 }
671 oa = ospf6_area_lookup (area_id, ospf6);
672 if (oa == NULL)
673 {
hasso049207c2004-08-04 20:02:13 +0000674 vty_out (vty, "No such Area: %s%s", argv[0], VNL);
hasso508e53e2004-05-18 18:57:06 +0000675 return CMD_SUCCESS;
676 }
677
678 route = ospf6_route_lookup (&prefix, oa->spf_table);
679 if (route == NULL)
680 {
681 vty_out (vty, "LS entry for root not found in area %s%s",
hasso049207c2004-08-04 20:02:13 +0000682 oa->name, VNL);
hasso508e53e2004-05-18 18:57:06 +0000683 return CMD_SUCCESS;
684 }
685 root = (struct ospf6_vertex *) route->route_option;
686 ospf6_spf_display_subtree (vty, "", 0, root);
687
688 return CMD_SUCCESS;
689}
690
hasso508e53e2004-05-18 18:57:06 +0000691DEFUN (show_ipv6_ospf6_simulate_spf_tree_root,
692 show_ipv6_ospf6_simulate_spf_tree_root_cmd,
693 "show ipv6 ospf6 simulate spf-tree A.B.C.D area A.B.C.D",
694 SHOW_STR
695 IP6_STR
696 OSPF6_STR
697 "Shortest Path First caculation\n"
698 "Show SPF tree\n"
699 "Specify root's router-id to calculate another router's SPF tree\n")
700{
701 u_int32_t area_id;
702 struct ospf6_area *oa;
703 struct ospf6_vertex *root;
704 struct ospf6_route *route;
705 struct prefix prefix;
706 u_int32_t router_id;
707 struct ospf6_route_table *spf_table;
708 unsigned char tmp_debug_ospf6_spf = 0;
709
710 inet_pton (AF_INET, argv[0], &router_id);
711 ospf6_linkstate_prefix (router_id, htonl (0), &prefix);
712
713 if (inet_pton (AF_INET, argv[1], &area_id) != 1)
714 {
hasso049207c2004-08-04 20:02:13 +0000715 vty_out (vty, "Malformed Area-ID: %s%s", argv[1], VNL);
hasso508e53e2004-05-18 18:57:06 +0000716 return CMD_SUCCESS;
717 }
718 oa = ospf6_area_lookup (area_id, ospf6);
719 if (oa == NULL)
720 {
hasso049207c2004-08-04 20:02:13 +0000721 vty_out (vty, "No such Area: %s%s", argv[1], VNL);
hasso508e53e2004-05-18 18:57:06 +0000722 return CMD_SUCCESS;
723 }
724
725 tmp_debug_ospf6_spf = conf_debug_ospf6_spf;
726 conf_debug_ospf6_spf = 0;
727
Paul Jakmacf1ce252006-05-15 10:46:07 +0000728 spf_table = OSPF6_ROUTE_TABLE_CREATE (NONE, SPF_RESULTS);
hasso508e53e2004-05-18 18:57:06 +0000729 ospf6_spf_calculation (router_id, spf_table, oa);
730
731 conf_debug_ospf6_spf = tmp_debug_ospf6_spf;
732
733 route = ospf6_route_lookup (&prefix, spf_table);
734 if (route == NULL)
735 {
736 ospf6_spf_table_finish (spf_table);
737 ospf6_route_table_delete (spf_table);
738 return CMD_SUCCESS;
739 }
740 root = (struct ospf6_vertex *) route->route_option;
741 ospf6_spf_display_subtree (vty, "", 0, root);
742
743 ospf6_spf_table_finish (spf_table);
744 ospf6_route_table_delete (spf_table);
745
746 return CMD_SUCCESS;
747}
paul718e3742002-12-13 20:15:29 +0000748
749void
Paul Jakma6ac29a52008-08-15 13:45:30 +0100750ospf6_area_init (void)
paul718e3742002-12-13 20:15:29 +0000751{
hasso508e53e2004-05-18 18:57:06 +0000752 install_element (VIEW_NODE, &show_ipv6_ospf6_spf_tree_cmd);
hasso508e53e2004-05-18 18:57:06 +0000753 install_element (VIEW_NODE, &show_ipv6_ospf6_area_spf_tree_cmd);
hasso508e53e2004-05-18 18:57:06 +0000754 install_element (VIEW_NODE, &show_ipv6_ospf6_simulate_spf_tree_root_cmd);
755
756 install_element (ENABLE_NODE, &show_ipv6_ospf6_spf_tree_cmd);
hasso508e53e2004-05-18 18:57:06 +0000757 install_element (ENABLE_NODE, &show_ipv6_ospf6_area_spf_tree_cmd);
hasso508e53e2004-05-18 18:57:06 +0000758 install_element (ENABLE_NODE, &show_ipv6_ospf6_simulate_spf_tree_root_cmd);
hasso6452df02004-08-15 05:52:07 +0000759
760 install_element (OSPF6_NODE, &area_range_cmd);
761 install_element (OSPF6_NODE, &area_range_advertise_cmd);
762 install_element (OSPF6_NODE, &no_area_range_cmd);
hasso34956b32005-06-24 08:44:02 +0000763
764 install_element (OSPF6_NODE, &area_import_list_cmd);
765 install_element (OSPF6_NODE, &no_area_import_list_cmd);
766 install_element (OSPF6_NODE, &area_export_list_cmd);
767 install_element (OSPF6_NODE, &no_area_export_list_cmd);
768
769 install_element (OSPF6_NODE, &area_filter_list_cmd);
770 install_element (OSPF6_NODE, &no_area_filter_list_cmd);
771
paul718e3742002-12-13 20:15:29 +0000772}
hasso049207c2004-08-04 20:02:13 +0000773
hasso6452df02004-08-15 05:52:07 +0000774