]> git.proxmox.com Git - mirror_frr.git/blob - ospf6d/ospf6_area.c
ospf6d: Fix memory allocation issues in SPF
[mirror_frr.git] / ospf6d / ospf6_area.c
1 /*
2 * Copyright (C) 2003 Yasuhiro Ohara
3 *
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
22 #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"
33 #include "plist.h"
34 #include "filter.h"
35
36 #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"
45 #include "ospf6_abr.h"
46 #include "ospf6d.h"
47
48 int
49 ospf6_area_cmp (void *va, void *vb)
50 {
51 struct ospf6_area *oa = (struct ospf6_area *) va;
52 struct ospf6_area *ob = (struct ospf6_area *) vb;
53 return (ntohl (oa->area_id) < ntohl (ob->area_id) ? -1 : 1);
54 }
55
56 /* schedule routing table recalculation */
57 static void
58 ospf6_area_lsdb_hook_add (struct ospf6_lsa *lsa)
59 {
60 switch (ntohs (lsa->header->type))
61 {
62 case OSPF6_LSTYPE_ROUTER:
63 case OSPF6_LSTYPE_NETWORK:
64 if (IS_OSPF6_DEBUG_EXAMIN_TYPE (lsa->header->type))
65 {
66 zlog_debug ("Examin %s", lsa->name);
67 zlog_debug ("Schedule SPF Calculation for %s",
68 OSPF6_AREA (lsa->lsdb->data)->name);
69 }
70 ospf6_spf_schedule (OSPF6_AREA (lsa->lsdb->data));
71 break;
72
73 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:
79 ospf6_abr_examin_summary (lsa, (struct ospf6_area *) lsa->lsdb->data);
80 break;
81
82 default:
83 break;
84 }
85 }
86
87 static void
88 ospf6_area_lsdb_hook_remove (struct ospf6_lsa *lsa)
89 {
90 switch (ntohs (lsa->header->type))
91 {
92 case OSPF6_LSTYPE_ROUTER:
93 case OSPF6_LSTYPE_NETWORK:
94 if (IS_OSPF6_DEBUG_EXAMIN_TYPE (lsa->header->type))
95 {
96 zlog_debug ("LSA disappearing: %s", lsa->name);
97 zlog_debug ("Schedule SPF Calculation for %s",
98 OSPF6_AREA (lsa->lsdb->data)->name);
99 }
100 ospf6_spf_schedule (OSPF6_AREA (lsa->lsdb->data));
101 break;
102
103 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:
109 ospf6_abr_examin_summary (lsa, (struct ospf6_area *) lsa->lsdb->data);
110 break;
111
112 default:
113 break;
114 }
115 }
116
117 static void
118 ospf6_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
124 static void
125 ospf6_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);
132 }
133
134 /* Make new area structure */
135 struct ospf6_area *
136 ospf6_area_create (u_int32_t area_id, struct ospf6 *o)
137 {
138 struct ospf6_area *oa;
139 struct ospf6_route *route;
140
141 oa = XCALLOC (MTYPE_OSPF6_AREA, sizeof (struct ospf6_area));
142
143 inet_ntop (AF_INET, &area_id, oa->name, sizeof (oa->name));
144 oa->area_id = area_id;
145 oa->if_list = list_new ();
146
147 oa->lsdb = ospf6_lsdb_create (oa);
148 oa->lsdb->hook_add = ospf6_area_lsdb_hook_add;
149 oa->lsdb->hook_remove = ospf6_area_lsdb_hook_remove;
150 oa->lsdb_self = ospf6_lsdb_create (oa);
151
152 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;
156 oa->route_table->hook_add = ospf6_area_route_hook_add;
157 oa->route_table->hook_remove = ospf6_area_route_hook_remove;
158
159 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;
165
166 /* 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);
170
171 oa->ospf6 = o;
172 listnode_add_sort (o->area_list, oa);
173
174 /* 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))
177 ospf6_abr_originate_summary_to_area (route, oa);
178
179 return oa;
180 }
181
182 void
183 ospf6_area_delete (struct ospf6_area *oa)
184 {
185 struct listnode *n, *nnode;
186 struct ospf6_interface *oi;
187
188 ospf6_route_table_delete (oa->range_table);
189 ospf6_route_table_delete (oa->summary_prefix);
190 ospf6_route_table_delete (oa->summary_router);
191
192 /* ospf6 interface list */
193 for (ALL_LIST_ELEMENTS (oa->if_list, n, nnode, oi))
194 {
195 ospf6_interface_delete (oi);
196 }
197 list_delete (oa->if_list);
198
199 ospf6_lsdb_delete (oa->lsdb);
200 ospf6_lsdb_delete (oa->lsdb_self);
201
202 ospf6_spf_table_finish (oa->spf_table);
203 ospf6_route_table_delete (oa->spf_table);
204 ospf6_route_table_delete (oa->route_table);
205
206 #if 0
207 ospf6_spftree_delete (oa->spf_tree);
208 ospf6_route_table_delete (oa->topology_table);
209 #endif /*0*/
210
211 THREAD_OFF (oa->thread_spf_calculation);
212 THREAD_OFF (oa->thread_route_calculation);
213
214 listnode_delete (oa->ospf6->area_list, oa);
215 oa->ospf6 = NULL;
216
217 /* free area */
218 XFREE (MTYPE_OSPF6_AREA, oa);
219 }
220
221 struct ospf6_area *
222 ospf6_area_lookup (u_int32_t area_id, struct ospf6 *ospf6)
223 {
224 struct ospf6_area *oa;
225 struct listnode *n;
226
227 for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, n, oa))
228 if (oa->area_id == area_id)
229 return oa;
230
231 return (struct ospf6_area *) NULL;
232 }
233
234 static struct ospf6_area *
235 ospf6_area_get (u_int32_t area_id, struct ospf6 *o)
236 {
237 struct ospf6_area *oa;
238 oa = ospf6_area_lookup (area_id, o);
239 if (oa == NULL)
240 oa = ospf6_area_create (area_id, o);
241 return oa;
242 }
243
244 void
245 ospf6_area_enable (struct ospf6_area *oa)
246 {
247 struct listnode *node, *nnode;
248 struct ospf6_interface *oi;
249
250 SET_FLAG (oa->flag, OSPF6_AREA_ENABLE);
251
252 for (ALL_LIST_ELEMENTS (oa->if_list, node, nnode, oi))
253 ospf6_interface_enable (oi);
254 }
255
256 void
257 ospf6_area_disable (struct ospf6_area *oa)
258 {
259 struct listnode *node, *nnode;
260 struct ospf6_interface *oi;
261
262 UNSET_FLAG (oa->flag, OSPF6_AREA_ENABLE);
263
264 for (ALL_LIST_ELEMENTS (oa->if_list, node, nnode, oi))
265 ospf6_interface_disable (oi);
266 }
267
268 \f
269 void
270 ospf6_area_show (struct vty *vty, struct ospf6_area *oa)
271 {
272 struct listnode *i;
273 struct ospf6_interface *oi;
274
275 vty_out (vty, " Area %s%s", oa->name, VNL);
276 vty_out (vty, " Number of Area scoped LSAs is %u%s",
277 oa->lsdb->count, VNL);
278
279 vty_out (vty, " Interface attached to this area:");
280 for (ALL_LIST_ELEMENTS_RO (oa->if_list, i, oi))
281 vty_out (vty, " %s", oi->interface->name);
282
283 vty_out (vty, "%s", VNL);
284 }
285
286
287 #define OSPF6_CMD_AREA_LOOKUP(str, oa) \
288 { \
289 u_int32_t area_id = 0; \
290 if (inet_pton (AF_INET, str, &area_id) != 1) \
291 { \
292 vty_out (vty, "Malformed Area-ID: %s%s", str, VNL); \
293 return CMD_SUCCESS; \
294 } \
295 oa = ospf6_area_lookup (area_id, ospf6); \
296 if (oa == NULL) \
297 { \
298 vty_out (vty, "No such Area: %s%s", str, VNL); \
299 return CMD_SUCCESS; \
300 } \
301 }
302
303 #define OSPF6_CMD_AREA_GET(str, oa) \
304 { \
305 u_int32_t area_id = 0; \
306 if (inet_pton (AF_INET, str, &area_id) != 1) \
307 { \
308 vty_out (vty, "Malformed Area-ID: %s%s", str, VNL); \
309 return CMD_SUCCESS; \
310 } \
311 oa = ospf6_area_get (area_id, ospf6); \
312 }
313
314 DEFUN (area_range,
315 area_range_cmd,
316 "area A.B.C.D range X:X::X:X/M",
317 "OSPF area parameters\n"
318 OSPF6_AREA_ID_STR
319 "Configured address range\n"
320 "Specify IPv6 prefix\n"
321 )
322 {
323 int ret;
324 struct ospf6_area *oa;
325 struct prefix prefix;
326 struct ospf6_route *range;
327
328 OSPF6_CMD_AREA_GET (argv[0], oa);
329 argc--;
330 argv++;
331
332 ret = str2prefix (argv[0], &prefix);
333 if (ret != 1 || prefix.family != AF_INET6)
334 {
335 vty_out (vty, "Malformed argument: %s%s", argv[0], VNL);
336 return CMD_SUCCESS;
337 }
338 argc--;
339 argv++;
340
341 range = ospf6_route_lookup (&prefix, oa->range_table);
342 if (range == NULL)
343 {
344 range = ospf6_route_create ();
345 range->type = OSPF6_DEST_TYPE_RANGE;
346 range->prefix = prefix;
347 }
348
349 if (argc)
350 {
351 if (! strcmp (argv[0], "not-advertise"))
352 SET_FLAG (range->flag, OSPF6_ROUTE_DO_NOT_ADVERTISE);
353 else if (! strcmp (argv[0], "advertise"))
354 UNSET_FLAG (range->flag, OSPF6_ROUTE_DO_NOT_ADVERTISE);
355 }
356
357 if (range->rnode)
358 {
359 vty_out (vty, "Range already defined: %s%s", argv[-1], VNL);
360 return CMD_WARNING;
361 }
362
363 ospf6_route_add (range, oa->range_table);
364 return CMD_SUCCESS;
365 }
366
367 ALIAS (area_range,
368 area_range_advertise_cmd,
369 "area A.B.C.D range X:X::X:X/M (advertise|not-advertise)",
370 "OSPF area parameters\n"
371 OSPF6_AREA_ID_STR
372 "Configured address range\n"
373 "Specify IPv6 prefix\n"
374 )
375
376 DEFUN (no_area_range,
377 no_area_range_cmd,
378 "no area A.B.C.D range X:X::X:X/M",
379 "OSPF area parameters\n"
380 OSPF6_AREA_ID_STR
381 "Configured address range\n"
382 "Specify IPv6 prefix\n"
383 )
384 {
385 int ret;
386 struct ospf6_area *oa;
387 struct prefix prefix;
388 struct ospf6_route *range;
389
390 OSPF6_CMD_AREA_GET (argv[0], oa);
391 argc--;
392 argv++;
393
394 ret = str2prefix (argv[0], &prefix);
395 if (ret != 1 || prefix.family != AF_INET6)
396 {
397 vty_out (vty, "Malformed argument: %s%s", argv[0], VNL);
398 return CMD_SUCCESS;
399 }
400
401 range = ospf6_route_lookup (&prefix, oa->range_table);
402 if (range == NULL)
403 {
404 vty_out (vty, "Range %s does not exists.%s", argv[0], VNL);
405 return CMD_SUCCESS;
406 }
407
408 ospf6_route_remove (range, oa->range_table);
409 return CMD_SUCCESS;
410 }
411
412 void
413 ospf6_area_config_write (struct vty *vty)
414 {
415 struct listnode *node;
416 struct ospf6_area *oa;
417 struct ospf6_route *range;
418 char buf[128];
419
420 for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, node, oa))
421 {
422 for (range = ospf6_route_head (oa->range_table); range;
423 range = ospf6_route_next (range))
424 {
425 prefix2str (&range->prefix, buf, sizeof (buf));
426 vty_out (vty, " area %s range %s%s", oa->name, buf, VNL);
427 }
428 }
429 }
430
431 DEFUN (area_filter_list,
432 area_filter_list_cmd,
433 "area A.B.C.D filter-list prefix WORD (in|out)",
434 "OSPFv6 area parameters\n"
435 "OSPFv6 area ID in IP address format\n"
436 "Filter networks between OSPFv6 areas\n"
437 "Filter prefixes between OSPFv6 areas\n"
438 "Name of an IPv6 prefix-list\n"
439 "Filter networks sent to this area\n"
440 "Filter networks sent from this area\n")
441 {
442 struct ospf6_area *area;
443 struct prefix_list *plist;
444
445 OSPF6_CMD_AREA_GET (argv[0], area);
446 argc--;
447 argv++;
448
449 plist = prefix_list_lookup (AFI_IP6, argv[1]);
450 if (strncmp (argv[2], "in", 2) == 0)
451 {
452 PREFIX_LIST_IN (area) = plist;
453 if (PREFIX_NAME_IN (area))
454 free (PREFIX_NAME_IN (area));
455
456 PREFIX_NAME_IN (area) = strdup (argv[1]);
457 ospf6_abr_reimport (area);
458 }
459 else
460 {
461 PREFIX_LIST_OUT (area) = plist;
462 if (PREFIX_NAME_OUT (area))
463 free (PREFIX_NAME_OUT (area));
464
465 PREFIX_NAME_OUT (area) = strdup (argv[1]);
466 ospf6_abr_enable_area (area);
467 }
468
469 return CMD_SUCCESS;
470 }
471
472 DEFUN (no_area_filter_list,
473 no_area_filter_list_cmd,
474 "no area A.B.C.D filter-list prefix WORD (in|out)",
475 NO_STR
476 "OSPFv6 area parameters\n"
477 "OSPFv6 area ID in IP address format\n"
478 "Filter networks between OSPFv6 areas\n"
479 "Filter prefixes between OSPFv6 areas\n"
480 "Name of an IPv6 prefix-list\n"
481 "Filter networks sent to this area\n"
482 "Filter networks sent from this area\n")
483 {
484 struct ospf6_area *area;
485 struct prefix_list *plist;
486
487 OSPF6_CMD_AREA_GET (argv[0], area);
488 argc--;
489 argv++;
490
491 plist = prefix_list_lookup (AFI_IP6, argv[1]);
492 if (strncmp (argv[2], "in", 2) == 0)
493 {
494 if (PREFIX_NAME_IN (area))
495 if (strcmp (PREFIX_NAME_IN (area), argv[1]) != 0)
496 return CMD_SUCCESS;
497
498 PREFIX_LIST_IN (area) = NULL;
499 if (PREFIX_NAME_IN (area))
500 free (PREFIX_NAME_IN (area));
501
502 PREFIX_NAME_IN (area) = NULL;
503 ospf6_abr_reimport (area);
504 }
505 else
506 {
507 if (PREFIX_NAME_OUT (area))
508 if (strcmp (PREFIX_NAME_OUT (area), argv[1]) != 0)
509 return CMD_SUCCESS;
510
511 PREFIX_LIST_OUT (area) = NULL;
512 if (PREFIX_NAME_OUT (area))
513 free (PREFIX_NAME_OUT (area));
514
515 PREFIX_NAME_OUT (area) = NULL;
516 ospf6_abr_enable_area (area);
517 }
518
519 return CMD_SUCCESS;
520 }
521
522 DEFUN (area_import_list,
523 area_import_list_cmd,
524 "area A.B.C.D import-list NAME",
525 "OSPFv6 area parameters\n"
526 "OSPFv6 area ID in IP address format\n"
527 "Set the filter for networks from other areas announced to the specified one\n"
528 "Name of the acess-list\n")
529 {
530 struct ospf6_area *area;
531 struct access_list *list;
532
533 OSPF6_CMD_AREA_GET(argv[0], area);
534
535 list = access_list_lookup (AFI_IP6, argv[1]);
536
537 IMPORT_LIST (area) = list;
538
539 if (IMPORT_NAME (area))
540 free (IMPORT_NAME (area));
541
542 IMPORT_NAME (area) = strdup (argv[1]);
543 ospf6_abr_reimport (area);
544
545 return CMD_SUCCESS;
546 }
547
548 DEFUN (no_area_import_list,
549 no_area_import_list_cmd,
550 "no area A.B.C.D import-list NAME",
551 "OSPFv6 area parameters\n"
552 "OSPFv6 area ID in IP address format\n"
553 "Unset the filter for networks announced to other areas\n"
554 "NAme of the access-list\n")
555 {
556 struct ospf6_area *area;
557
558 OSPF6_CMD_AREA_GET(argv[0], area);
559
560 IMPORT_LIST (area) = 0;
561
562 if (IMPORT_NAME (area))
563 free (IMPORT_NAME (area));
564
565 IMPORT_NAME (area) = NULL;
566 ospf6_abr_reimport (area);
567
568 return CMD_SUCCESS;
569 }
570
571 DEFUN (area_export_list,
572 area_export_list_cmd,
573 "area A.B.C.D export-list NAME",
574 "OSPFv6 area parameters\n"
575 "OSPFv6 area ID in IP address format\n"
576 "Set the filter for networks announced to other areas\n"
577 "Name of the acess-list\n")
578 {
579 struct ospf6_area *area;
580 struct access_list *list;
581
582 OSPF6_CMD_AREA_GET(argv[0], area);
583
584 list = access_list_lookup (AFI_IP6, argv[1]);
585
586 EXPORT_LIST (area) = list;
587
588 if (EXPORT_NAME (area))
589 free (EXPORT_NAME (area));
590
591 EXPORT_NAME (area) = strdup (argv[1]);
592 ospf6_abr_enable_area (area);
593
594 return CMD_SUCCESS;
595 }
596
597 DEFUN (no_area_export_list,
598 no_area_export_list_cmd,
599 "no area A.B.C.D export-list NAME",
600 "OSPFv6 area parameters\n"
601 "OSPFv6 area ID in IP address format\n"
602 "Unset the filter for networks announced to other areas\n"
603 "Name of the access-list\n")
604 {
605 struct ospf6_area *area;
606
607 OSPF6_CMD_AREA_GET(argv[0], area);
608
609 EXPORT_LIST (area) = 0;
610
611 if (EXPORT_NAME (area))
612 free (EXPORT_NAME (area));
613
614 EXPORT_NAME (area) = NULL;
615 ospf6_abr_enable_area (area);
616
617 return CMD_SUCCESS;
618 }
619
620 DEFUN (show_ipv6_ospf6_spf_tree,
621 show_ipv6_ospf6_spf_tree_cmd,
622 "show ipv6 ospf6 spf tree",
623 SHOW_STR
624 IP6_STR
625 OSPF6_STR
626 "Shortest Path First caculation\n"
627 "Show SPF tree\n")
628 {
629 struct listnode *node;
630 struct ospf6_area *oa;
631 struct ospf6_vertex *root;
632 struct ospf6_route *route;
633 struct prefix prefix;
634
635 ospf6_linkstate_prefix (ospf6->router_id, htonl (0), &prefix);
636
637 for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, node, oa))
638 {
639 route = ospf6_route_lookup (&prefix, oa->spf_table);
640 if (route == NULL)
641 {
642 vty_out (vty, "LS entry for root not found in area %s%s",
643 oa->name, VNL);
644 continue;
645 }
646 root = (struct ospf6_vertex *) route->route_option;
647 ospf6_spf_display_subtree (vty, "", 0, root);
648 }
649
650 return CMD_SUCCESS;
651 }
652
653 DEFUN (show_ipv6_ospf6_area_spf_tree,
654 show_ipv6_ospf6_area_spf_tree_cmd,
655 "show ipv6 ospf6 area A.B.C.D spf tree",
656 SHOW_STR
657 IP6_STR
658 OSPF6_STR
659 OSPF6_AREA_STR
660 OSPF6_AREA_ID_STR
661 "Shortest Path First caculation\n"
662 "Show SPF tree\n")
663 {
664 u_int32_t area_id;
665 struct ospf6_area *oa;
666 struct ospf6_vertex *root;
667 struct ospf6_route *route;
668 struct prefix prefix;
669
670 ospf6_linkstate_prefix (ospf6->router_id, htonl (0), &prefix);
671
672 if (inet_pton (AF_INET, argv[0], &area_id) != 1)
673 {
674 vty_out (vty, "Malformed Area-ID: %s%s", argv[0], VNL);
675 return CMD_SUCCESS;
676 }
677 oa = ospf6_area_lookup (area_id, ospf6);
678 if (oa == NULL)
679 {
680 vty_out (vty, "No such Area: %s%s", argv[0], VNL);
681 return CMD_SUCCESS;
682 }
683
684 route = ospf6_route_lookup (&prefix, oa->spf_table);
685 if (route == NULL)
686 {
687 vty_out (vty, "LS entry for root not found in area %s%s",
688 oa->name, VNL);
689 return CMD_SUCCESS;
690 }
691 root = (struct ospf6_vertex *) route->route_option;
692 ospf6_spf_display_subtree (vty, "", 0, root);
693
694 return CMD_SUCCESS;
695 }
696
697 DEFUN (show_ipv6_ospf6_simulate_spf_tree_root,
698 show_ipv6_ospf6_simulate_spf_tree_root_cmd,
699 "show ipv6 ospf6 simulate spf-tree A.B.C.D area A.B.C.D",
700 SHOW_STR
701 IP6_STR
702 OSPF6_STR
703 "Shortest Path First caculation\n"
704 "Show SPF tree\n"
705 "Specify root's router-id to calculate another router's SPF tree\n")
706 {
707 u_int32_t area_id;
708 struct ospf6_area *oa;
709 struct ospf6_vertex *root;
710 struct ospf6_route *route;
711 struct prefix prefix;
712 u_int32_t router_id;
713 struct ospf6_route_table *spf_table;
714 unsigned char tmp_debug_ospf6_spf = 0;
715
716 inet_pton (AF_INET, argv[0], &router_id);
717 ospf6_linkstate_prefix (router_id, htonl (0), &prefix);
718
719 if (inet_pton (AF_INET, argv[1], &area_id) != 1)
720 {
721 vty_out (vty, "Malformed Area-ID: %s%s", argv[1], VNL);
722 return CMD_SUCCESS;
723 }
724 oa = ospf6_area_lookup (area_id, ospf6);
725 if (oa == NULL)
726 {
727 vty_out (vty, "No such Area: %s%s", argv[1], VNL);
728 return CMD_SUCCESS;
729 }
730
731 tmp_debug_ospf6_spf = conf_debug_ospf6_spf;
732 conf_debug_ospf6_spf = 0;
733
734 spf_table = OSPF6_ROUTE_TABLE_CREATE (NONE, SPF_RESULTS);
735 ospf6_spf_calculation (router_id, spf_table, oa);
736
737 conf_debug_ospf6_spf = tmp_debug_ospf6_spf;
738
739 route = ospf6_route_lookup (&prefix, spf_table);
740 if (route == NULL)
741 {
742 ospf6_spf_table_finish (spf_table);
743 ospf6_route_table_delete (spf_table);
744 return CMD_SUCCESS;
745 }
746 root = (struct ospf6_vertex *) route->route_option;
747 ospf6_spf_display_subtree (vty, "", 0, root);
748
749 ospf6_spf_table_finish (spf_table);
750 ospf6_route_table_delete (spf_table);
751
752 return CMD_SUCCESS;
753 }
754
755 void
756 ospf6_area_init (void)
757 {
758 install_element (VIEW_NODE, &show_ipv6_ospf6_spf_tree_cmd);
759 install_element (VIEW_NODE, &show_ipv6_ospf6_area_spf_tree_cmd);
760 install_element (VIEW_NODE, &show_ipv6_ospf6_simulate_spf_tree_root_cmd);
761
762 install_element (ENABLE_NODE, &show_ipv6_ospf6_spf_tree_cmd);
763 install_element (ENABLE_NODE, &show_ipv6_ospf6_area_spf_tree_cmd);
764 install_element (ENABLE_NODE, &show_ipv6_ospf6_simulate_spf_tree_root_cmd);
765
766 install_element (OSPF6_NODE, &area_range_cmd);
767 install_element (OSPF6_NODE, &area_range_advertise_cmd);
768 install_element (OSPF6_NODE, &no_area_range_cmd);
769
770 install_element (OSPF6_NODE, &area_import_list_cmd);
771 install_element (OSPF6_NODE, &no_area_import_list_cmd);
772 install_element (OSPF6_NODE, &area_export_list_cmd);
773 install_element (OSPF6_NODE, &no_area_export_list_cmd);
774
775 install_element (OSPF6_NODE, &area_filter_list_cmd);
776 install_element (OSPF6_NODE, &no_area_filter_list_cmd);
777
778 }
779
780