]> git.proxmox.com Git - mirror_frr.git/blob - ospf6d/ospf6_top.c
16fb012ea95d9b07394eae61c9450eb973ae2d2e
[mirror_frr.git] / ospf6d / ospf6_top.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 "vty.h"
27 #include "linklist.h"
28 #include "prefix.h"
29 #include "table.h"
30 #include "thread.h"
31 #include "command.h"
32
33 #include "ospf6_proto.h"
34 #include "ospf6_message.h"
35 #include "ospf6_lsa.h"
36 #include "ospf6_lsdb.h"
37 #include "ospf6_route.h"
38 #include "ospf6_zebra.h"
39
40 #include "ospf6_top.h"
41 #include "ospf6_area.h"
42 #include "ospf6_interface.h"
43 #include "ospf6_neighbor.h"
44
45 #include "ospf6_flood.h"
46 #include "ospf6_asbr.h"
47 #include "ospf6_abr.h"
48 #include "ospf6_intra.h"
49 #include "ospf6_spf.h"
50 #include "ospf6d.h"
51
52 /* global ospf6d variable */
53 struct ospf6 *ospf6;
54
55 static void ospf6_disable (struct ospf6 *o);
56
57 static void
58 ospf6_top_lsdb_hook_add (struct ospf6_lsa *lsa)
59 {
60 switch (ntohs (lsa->header->type))
61 {
62 case OSPF6_LSTYPE_AS_EXTERNAL:
63 ospf6_asbr_lsa_add (lsa);
64 break;
65
66 default:
67 break;
68 }
69 }
70
71 static void
72 ospf6_top_lsdb_hook_remove (struct ospf6_lsa *lsa)
73 {
74 switch (ntohs (lsa->header->type))
75 {
76 case OSPF6_LSTYPE_AS_EXTERNAL:
77 ospf6_asbr_lsa_remove (lsa);
78 break;
79
80 default:
81 break;
82 }
83 }
84
85 static void
86 ospf6_top_route_hook_add (struct ospf6_route *route)
87 {
88 ospf6_abr_originate_summary (route);
89 ospf6_zebra_route_update_add (route);
90 }
91
92 static void
93 ospf6_top_route_hook_remove (struct ospf6_route *route)
94 {
95 route->flag |= OSPF6_ROUTE_REMOVE;
96 ospf6_abr_originate_summary (route);
97 ospf6_zebra_route_update_remove (route);
98 }
99
100 static void
101 ospf6_top_brouter_hook_add (struct ospf6_route *route)
102 {
103 ospf6_abr_examin_brouter (ADV_ROUTER_IN_PREFIX (&route->prefix));
104 ospf6_asbr_lsentry_add (route);
105 ospf6_abr_originate_summary (route);
106 }
107
108 static void
109 ospf6_top_brouter_hook_remove (struct ospf6_route *route)
110 {
111 route->flag |= OSPF6_ROUTE_REMOVE;
112 ospf6_abr_examin_brouter (ADV_ROUTER_IN_PREFIX (&route->prefix));
113 ospf6_asbr_lsentry_remove (route);
114 ospf6_abr_originate_summary (route);
115 }
116
117 static struct ospf6 *
118 ospf6_create (void)
119 {
120 struct ospf6 *o;
121
122 o = XCALLOC (MTYPE_OSPF6_TOP, sizeof (struct ospf6));
123
124 /* initialize */
125 quagga_gettime (QUAGGA_CLK_MONOTONIC, &o->starttime);
126 o->area_list = list_new ();
127 o->area_list->cmp = ospf6_area_cmp;
128 o->lsdb = ospf6_lsdb_create (o);
129 o->lsdb_self = ospf6_lsdb_create (o);
130 o->lsdb->hook_add = ospf6_top_lsdb_hook_add;
131 o->lsdb->hook_remove = ospf6_top_lsdb_hook_remove;
132
133 o->spf_delay = OSPF_SPF_DELAY_DEFAULT;
134 o->spf_holdtime = OSPF_SPF_HOLDTIME_DEFAULT;
135 o->spf_max_holdtime = OSPF_SPF_MAX_HOLDTIME_DEFAULT;
136 o->spf_hold_multiplier = 1;
137
138 /* LSA timers value init */
139 o->lsa_minarrival = OSPF_MIN_LS_ARRIVAL;
140
141 o->route_table = OSPF6_ROUTE_TABLE_CREATE (GLOBAL, ROUTES);
142 o->route_table->scope = o;
143 o->route_table->hook_add = ospf6_top_route_hook_add;
144 o->route_table->hook_remove = ospf6_top_route_hook_remove;
145
146 o->brouter_table = OSPF6_ROUTE_TABLE_CREATE (GLOBAL, BORDER_ROUTERS);
147 o->brouter_table->scope = o;
148 o->brouter_table->hook_add = ospf6_top_brouter_hook_add;
149 o->brouter_table->hook_remove = ospf6_top_brouter_hook_remove;
150
151 o->external_table = OSPF6_ROUTE_TABLE_CREATE (GLOBAL, EXTERNAL_ROUTES);
152 o->external_table->scope = o;
153
154 o->external_id_table = route_table_init ();
155
156 o->ref_bandwidth = OSPF6_REFERENCE_BANDWIDTH;
157
158 o->distance_table = route_table_init ();
159
160 /* Enable "log-adjacency-changes" */
161 SET_FLAG(o->config_flags, OSPF6_LOG_ADJACENCY_CHANGES);
162
163 return o;
164 }
165
166 void
167 ospf6_delete (struct ospf6 *o)
168 {
169 struct listnode *node, *nnode;
170 struct ospf6_area *oa;
171
172 ospf6_disable (ospf6);
173
174 for (ALL_LIST_ELEMENTS (o->area_list, node, nnode, oa))
175 ospf6_area_delete (oa);
176
177
178 list_delete (o->area_list);
179
180 ospf6_lsdb_delete (o->lsdb);
181 ospf6_lsdb_delete (o->lsdb_self);
182
183 ospf6_route_table_delete (o->route_table);
184 ospf6_route_table_delete (o->brouter_table);
185
186 ospf6_route_table_delete (o->external_table);
187 route_table_finish (o->external_id_table);
188
189 ospf6_distance_reset (o);
190 route_table_finish (o->distance_table);
191
192 XFREE (MTYPE_OSPF6_TOP, o);
193 }
194
195 static void
196 ospf6_disable (struct ospf6 *o)
197 {
198 struct listnode *node, *nnode;
199 struct ospf6_area *oa;
200
201 if (! CHECK_FLAG (o->flag, OSPF6_DISABLED))
202 {
203 SET_FLAG (o->flag, OSPF6_DISABLED);
204
205 for (ALL_LIST_ELEMENTS (o->area_list, node, nnode, oa))
206 ospf6_area_disable (oa);
207
208 /* XXX: This also changes persistent settings */
209 ospf6_asbr_redistribute_reset();
210
211 ospf6_lsdb_remove_all (o->lsdb);
212 ospf6_route_remove_all (o->route_table);
213 ospf6_route_remove_all (o->brouter_table);
214
215 THREAD_OFF(o->maxage_remover);
216 THREAD_OFF(o->t_spf_calc);
217 THREAD_OFF(o->t_ase_calc);
218 }
219 }
220
221 static int
222 ospf6_maxage_remover (struct thread *thread)
223 {
224 struct ospf6 *o = (struct ospf6 *) THREAD_ARG (thread);
225 struct ospf6_area *oa;
226 struct ospf6_interface *oi;
227 struct ospf6_neighbor *on;
228 struct listnode *i, *j, *k;
229 int reschedule = 0;
230
231 o->maxage_remover = (struct thread *) NULL;
232
233 for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa))
234 {
235 for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi))
236 {
237 for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, k, on))
238 {
239 if (on->state != OSPF6_NEIGHBOR_EXCHANGE &&
240 on->state != OSPF6_NEIGHBOR_LOADING)
241 continue;
242
243 ospf6_maxage_remove (o);
244 return 0;
245 }
246 }
247 }
248
249 for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa))
250 {
251 for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi))
252 {
253 if (ospf6_lsdb_maxage_remover (oi->lsdb))
254 {
255 reschedule = 1;
256 }
257 }
258
259 if (ospf6_lsdb_maxage_remover (oa->lsdb))
260 {
261 reschedule = 1;
262 }
263 }
264
265 if (ospf6_lsdb_maxage_remover (o->lsdb))
266 {
267 reschedule = 1;
268 }
269
270 if (reschedule)
271 {
272 ospf6_maxage_remove (o);
273 }
274
275 return 0;
276 }
277
278 void
279 ospf6_maxage_remove (struct ospf6 *o)
280 {
281 if (o && ! o->maxage_remover)
282 o->maxage_remover = thread_add_timer (master, ospf6_maxage_remover, o,
283 OSPF_LSA_MAXAGE_REMOVE_DELAY_DEFAULT);
284 }
285
286 /* start ospf6 */
287 DEFUN (router_ospf6,
288 router_ospf6_cmd,
289 "router ospf6",
290 ROUTER_STR
291 OSPF6_STR)
292 {
293 if (ospf6 == NULL)
294 ospf6 = ospf6_create ();
295
296 /* set current ospf point. */
297 vty->node = OSPF6_NODE;
298 vty->index = ospf6;
299
300 return CMD_SUCCESS;
301 }
302
303 /* stop ospf6 */
304 DEFUN (no_router_ospf6,
305 no_router_ospf6_cmd,
306 "no router ospf6",
307 NO_STR
308 ROUTER_STR
309 OSPF6_STR)
310 {
311 /* return to config node . */
312 vty->node = CONFIG_NODE;
313 vty->index = NULL;
314
315 return CMD_SUCCESS;
316 }
317
318 /* change Router_ID commands. */
319 DEFUN (ospf6_router_id,
320 ospf6_router_id_cmd,
321 "router-id A.B.C.D",
322 "Configure OSPF Router-ID\n"
323 V4NOTATION_STR)
324 {
325 int idx_ipv4 = 1;
326 int ret;
327 u_int32_t router_id;
328 struct ospf6 *o;
329
330 o = (struct ospf6 *) vty->index;
331
332 ret = inet_pton (AF_INET, argv[idx_ipv4]->arg, &router_id);
333 if (ret == 0)
334 {
335 vty_out (vty, "malformed OSPF Router-ID: %s%s", argv[idx_ipv4]->arg, VNL);
336 return CMD_SUCCESS;
337 }
338
339 o->router_id_static = router_id;
340 if (o->router_id == 0)
341 o->router_id = router_id;
342
343 return CMD_SUCCESS;
344 }
345
346 DEFUN (ospf6_log_adjacency_changes,
347 ospf6_log_adjacency_changes_cmd,
348 "log-adjacency-changes",
349 "Log changes in adjacency state\n")
350 {
351 struct ospf6 *ospf6 = vty->index;
352
353 SET_FLAG(ospf6->config_flags, OSPF6_LOG_ADJACENCY_CHANGES);
354 UNSET_FLAG(ospf6->config_flags, OSPF6_LOG_ADJACENCY_DETAIL);
355 return CMD_SUCCESS;
356 }
357
358 DEFUN (ospf6_log_adjacency_changes_detail,
359 ospf6_log_adjacency_changes_detail_cmd,
360 "log-adjacency-changes detail",
361 "Log changes in adjacency state\n"
362 "Log all state changes\n")
363 {
364 struct ospf6 *ospf6 = vty->index;
365
366 SET_FLAG(ospf6->config_flags, OSPF6_LOG_ADJACENCY_CHANGES);
367 SET_FLAG(ospf6->config_flags, OSPF6_LOG_ADJACENCY_DETAIL);
368 return CMD_SUCCESS;
369 }
370
371 DEFUN (no_ospf6_log_adjacency_changes,
372 no_ospf6_log_adjacency_changes_cmd,
373 "no log-adjacency-changes",
374 NO_STR
375 "Log changes in adjacency state\n")
376 {
377 struct ospf6 *ospf6 = vty->index;
378
379 UNSET_FLAG(ospf6->config_flags, OSPF6_LOG_ADJACENCY_DETAIL);
380 UNSET_FLAG(ospf6->config_flags, OSPF6_LOG_ADJACENCY_CHANGES);
381 return CMD_SUCCESS;
382 }
383
384 DEFUN (no_ospf6_log_adjacency_changes_detail,
385 no_ospf6_log_adjacency_changes_detail_cmd,
386 "no log-adjacency-changes detail",
387 NO_STR
388 "Log changes in adjacency state\n"
389 "Log all state changes\n")
390 {
391 struct ospf6 *ospf6 = vty->index;
392
393 UNSET_FLAG(ospf6->config_flags, OSPF6_LOG_ADJACENCY_DETAIL);
394 UNSET_FLAG(ospf6->config_flags, OSPF6_LOG_ADJACENCY_CHANGES);
395 return CMD_SUCCESS;
396 }
397
398 DEFUN (ospf6_timers_lsa,
399 ospf6_timers_lsa_cmd,
400 "timers lsa min-arrival (0-600000)",
401 "Adjust routing timers\n"
402 "OSPF6 LSA timers\n"
403 "Minimum delay in receiving new version of a LSA\n"
404 "Delay in milliseconds\n")
405 {
406 int idx_number = 3;
407 unsigned int minarrival;
408 struct ospf6 *ospf = vty->index;
409
410 if (!ospf)
411 return CMD_SUCCESS;
412
413 VTY_GET_INTEGER ("LSA min-arrival", minarrival, argv[idx_number]->arg);
414 ospf->lsa_minarrival = minarrival;
415
416 return CMD_SUCCESS;
417 }
418
419 DEFUN (no_ospf6_timers_lsa,
420 no_ospf6_timers_lsa_cmd,
421 "no timers lsa min-arrival [(0-600000)]",
422 NO_STR
423 "Adjust routing timers\n"
424 "OSPF6 LSA timers\n"
425 "Minimum delay in receiving new version of a LSA\n"
426 "Delay in milliseconds\n")
427 {
428 int idx_number = 4;
429 unsigned int minarrival;
430 struct ospf6 *ospf = vty->index;
431
432 if (!ospf)
433 return CMD_SUCCESS;
434
435 if (argc == 5)
436 {
437 VTY_GET_INTEGER ("LSA min-arrival", minarrival, argv[idx_number]->arg);
438
439 if (ospf->lsa_minarrival != minarrival ||
440 minarrival == OSPF_MIN_LS_ARRIVAL)
441 return CMD_SUCCESS;
442 }
443
444 ospf->lsa_minarrival = OSPF_MIN_LS_ARRIVAL;
445
446 return CMD_SUCCESS;
447 }
448
449
450 DEFUN (ospf6_distance,
451 ospf6_distance_cmd,
452 "distance (1-255)",
453 "Administrative distance\n"
454 "OSPF6 Administrative distance\n")
455 {
456 struct ospf6 *o = vty->index;
457
458 o->distance_all = atoi (argv[1]->arg);
459
460 return CMD_SUCCESS;
461 }
462
463 DEFUN (no_ospf6_distance,
464 no_ospf6_distance_cmd,
465 "no distance (1-255)",
466 NO_STR
467 "Administrative distance\n"
468 "OSPF6 Administrative distance\n")
469 {
470 struct ospf6 *o = vty->index;
471
472 o->distance_all = 0;
473
474 return CMD_SUCCESS;
475 }
476
477 DEFUN (ospf6_distance_ospf6,
478 ospf6_distance_ospf6_cmd,
479 "distance ospf6 <intra-area (1-255)|inter-area (1-255)|external (1-255)> <intra-area (1-255)|inter-area (1-255)|external (1-255)> <intra-area (1-255)|inter-area (1-255)|external (1-255)>",
480 "Administrative distance\n"
481 "OSPF6 distance\n"
482 "Intra-area routes\n"
483 "Distance for intra-area routes\n"
484 "Inter-area routes\n"
485 "Distance for inter-area routes\n"
486 "External routes\n"
487 "Distance for external routes\n"
488 "Intra-area routes\n"
489 "Distance for intra-area routes\n"
490 "Inter-area routes\n"
491 "Distance for inter-area routes\n"
492 "External routes\n"
493 "Distance for external routes\n"
494 "Intra-area routes\n"
495 "Distance for intra-area routes\n"
496 "Inter-area routes\n"
497 "Distance for inter-area routes\n"
498 "External routes\n"
499 "Distance for external routes\n")
500 {
501 struct ospf6 *o = vty->index;
502
503 char *intra, *inter, *external;
504 intra = inter = external = NULL;
505
506 int idx = 0;
507 if (argv_find (argv, argc, "intra-area", &idx))
508 intra = argv[++idx]->arg;
509 if (argv_find (argv, argc, "intra-area", &idx))
510 {
511 vty_out (vty, "%% Cannot specify intra-area distance twice%s", VTY_NEWLINE);
512 return CMD_WARNING;
513 }
514
515 idx = 0;
516 if (argv_find (argv, argc, "inter-area", &idx))
517 inter = argv[++idx]->arg;
518 if (argv_find (argv, argc, "inter-area", &idx))
519 {
520 vty_out (vty, "%% Cannot specify inter-area distance twice%s", VTY_NEWLINE);
521 return CMD_WARNING;
522 }
523
524 idx = 0;
525 if (argv_find (argv, argc, "external", &idx))
526 external = argv[++idx]->arg;
527 if (argv_find (argv, argc, "external", &idx))
528 {
529 vty_out (vty, "%% Cannot specify external distance twice%s", VTY_NEWLINE);
530 return CMD_WARNING;
531 }
532
533
534 if (intra)
535 o->distance_intra = atoi (intra);
536
537 if (inter)
538 o->distance_inter = atoi (inter);
539
540 if (external)
541 o->distance_external = atoi (external);
542
543 return CMD_SUCCESS;
544 }
545
546 DEFUN (no_ospf6_distance_ospf6,
547 no_ospf6_distance_ospf6_cmd,
548 "no distance ospf6 [<intra-area (1-255)|inter-area (1-255)|external (1-255)> <intra-area (1-255)|inter-area (1-255)|external (1-255)> <intra-area (1-255)|inter-area (1-255)|external (1-255)>]",
549 NO_STR
550 "Administrative distance\n"
551 "OSPF6 distance\n"
552 "Intra-area routes\n"
553 "Distance for intra-area routes\n"
554 "Inter-area routes\n"
555 "Distance for inter-area routes\n"
556 "External routes\n"
557 "Distance for external routes\n"
558 "Intra-area routes\n"
559 "Distance for intra-area routes\n"
560 "Inter-area routes\n"
561 "Distance for inter-area routes\n"
562 "External routes\n"
563 "Distance for external routes\n"
564 "Intra-area routes\n"
565 "Distance for intra-area routes\n"
566 "Inter-area routes\n"
567 "Distance for inter-area routes\n"
568 "External routes\n"
569 "Distance for external routes\n")
570 {
571 struct ospf6 *o = vty->index;
572
573 char *intra, *inter, *external;
574 intra = inter = external = NULL;
575
576 if (argc == 3)
577 {
578 /* If no arguments are given, clear all distance information */
579 o->distance_intra = 0;
580 o->distance_inter = 0;
581 o->distance_external = 0;
582 return CMD_SUCCESS;
583 }
584
585 int idx = 0;
586 if (argv_find (argv, argc, "intra-area", &idx))
587 intra = argv[++idx]->arg;
588 if (argv_find (argv, argc, "intra-area", &idx))
589 {
590 vty_out (vty, "%% Cannot specify intra-area distance twice%s", VTY_NEWLINE);
591 return CMD_WARNING;
592 }
593
594 idx = 0;
595 if (argv_find (argv, argc, "inter-area", &idx))
596 inter = argv[++idx]->arg;
597 if (argv_find (argv, argc, "inter-area", &idx))
598 {
599 vty_out (vty, "%% Cannot specify inter-area distance twice%s", VTY_NEWLINE);
600 return CMD_WARNING;
601 }
602
603 idx = 0;
604 if (argv_find (argv, argc, "external", &idx))
605 external = argv[++idx]->arg;
606 if (argv_find (argv, argc, "external", &idx))
607 {
608 vty_out (vty, "%% Cannot specify external distance twice%s", VTY_NEWLINE);
609 return CMD_WARNING;
610 }
611 if (argc < 3) /* should not happen */
612 return CMD_WARNING;
613
614 if (intra)
615 o->distance_intra = 0;
616
617 if (inter)
618 o->distance_inter = 0;
619
620 if (external)
621 o->distance_external = 0;
622
623 return CMD_SUCCESS;
624 }
625
626 #if 0
627 DEFUN (ospf6_distance_source,
628 ospf6_distance_source_cmd,
629 "distance (1-255) X:X::X:X/M [WORD]",
630 "Administrative distance\n"
631 "Distance value\n"
632 "IP source prefix\n"
633 "Access list name\n")
634 {
635 struct ospf6 *o = vty->index;
636 char *alname = (argc == 4) ? argv[3]->arg : NULL;
637 ospf6_distance_set (vty, o, argv[1]->arg, argv[2]->arg, alname);
638
639 return CMD_SUCCESS;
640 }
641
642 DEFUN (no_ospf6_distance_source,
643 no_ospf6_distance_source_cmd,
644 "no distance (1-255) X:X::X:X/M [WORD]",
645 NO_STR
646 "Administrative distance\n"
647 "Distance value\n"
648 "IP source prefix\n"
649 "Access list name\n")
650 {
651 struct ospf6 *o = vty->index;
652 char *alname = (argc == 5) ? argv[4]->arg : NULL;
653 ospf6_distance_unset (vty, o, argv[2]->arg, argv[3]->arg, alname);
654
655 return CMD_SUCCESS;
656 }
657 #endif
658
659 DEFUN (ospf6_interface_area,
660 ospf6_interface_area_cmd,
661 "interface IFNAME area A.B.C.D",
662 "Enable routing on an IPv6 interface\n"
663 IFNAME_STR
664 "Specify the OSPF6 area ID\n"
665 "OSPF6 area ID in IPv4 address notation\n"
666 )
667 {
668 int idx_ifname = 1;
669 int idx_ipv4 = 3;
670 struct ospf6 *o;
671 struct ospf6_area *oa;
672 struct ospf6_interface *oi;
673 struct interface *ifp;
674 u_int32_t area_id;
675
676 o = (struct ospf6 *) vty->index;
677
678 /* find/create ospf6 interface */
679 ifp = if_get_by_name (argv[idx_ifname]->arg);
680 oi = (struct ospf6_interface *) ifp->info;
681 if (oi == NULL)
682 oi = ospf6_interface_create (ifp);
683 if (oi->area)
684 {
685 vty_out (vty, "%s already attached to Area %s%s",
686 oi->interface->name, oi->area->name, VNL);
687 return CMD_SUCCESS;
688 }
689
690 /* parse Area-ID */
691 if (inet_pton (AF_INET, argv[idx_ipv4]->arg, &area_id) != 1)
692 {
693 vty_out (vty, "Invalid Area-ID: %s%s", argv[idx_ipv4]->arg, VNL);
694 return CMD_SUCCESS;
695 }
696
697 /* find/create ospf6 area */
698 oa = ospf6_area_lookup (area_id, o);
699 if (oa == NULL)
700 oa = ospf6_area_create (area_id, o);
701
702 /* attach interface to area */
703 listnode_add (oa->if_list, oi); /* sort ?? */
704 oi->area = oa;
705
706 SET_FLAG (oa->flag, OSPF6_AREA_ENABLE);
707
708 /* ospf6 process is currently disabled, not much more to do */
709 if (CHECK_FLAG (o->flag, OSPF6_DISABLED))
710 return CMD_SUCCESS;
711
712 /* start up */
713 ospf6_interface_enable (oi);
714
715 /* If the router is ABR, originate summary routes */
716 if (ospf6_is_router_abr (o))
717 ospf6_abr_enable_area (oa);
718
719 return CMD_SUCCESS;
720 }
721
722 DEFUN (no_ospf6_interface_area,
723 no_ospf6_interface_area_cmd,
724 "no interface IFNAME area A.B.C.D",
725 NO_STR
726 "Disable routing on an IPv6 interface\n"
727 IFNAME_STR
728 "Specify the OSPF6 area ID\n"
729 "OSPF6 area ID in IPv4 address notation\n"
730 )
731 {
732 int idx_ifname = 2;
733 int idx_ipv4 = 4;
734 struct ospf6_interface *oi;
735 struct ospf6_area *oa;
736 struct interface *ifp;
737 u_int32_t area_id;
738
739 ifp = if_lookup_by_name (argv[idx_ifname]->arg);
740 if (ifp == NULL)
741 {
742 vty_out (vty, "No such interface %s%s", argv[idx_ifname]->arg, VNL);
743 return CMD_SUCCESS;
744 }
745
746 oi = (struct ospf6_interface *) ifp->info;
747 if (oi == NULL)
748 {
749 vty_out (vty, "Interface %s not enabled%s", ifp->name, VNL);
750 return CMD_SUCCESS;
751 }
752
753 /* parse Area-ID */
754 if (inet_pton (AF_INET, argv[idx_ipv4]->arg, &area_id) != 1)
755 {
756 vty_out (vty, "Invalid Area-ID: %s%s", argv[idx_ipv4]->arg, VNL);
757 return CMD_SUCCESS;
758 }
759
760 /* Verify Area */
761 if (oi->area == NULL)
762 {
763 vty_out (vty, "No such Area-ID: %s%s", argv[idx_ipv4]->arg, VNL);
764 return CMD_SUCCESS;
765 }
766
767 if (oi->area->area_id != area_id)
768 {
769 vty_out (vty, "Wrong Area-ID: %s is attached to area %s%s",
770 oi->interface->name, oi->area->name, VNL);
771 return CMD_SUCCESS;
772 }
773
774 thread_execute (master, interface_down, oi, 0);
775
776 oa = oi->area;
777 listnode_delete (oi->area->if_list, oi);
778 oi->area = (struct ospf6_area *) NULL;
779
780 /* Withdraw inter-area routes from this area, if necessary */
781 if (oa->if_list->count == 0)
782 {
783 UNSET_FLAG (oa->flag, OSPF6_AREA_ENABLE);
784 ospf6_abr_disable_area (oa);
785 }
786
787 return CMD_SUCCESS;
788 }
789
790 DEFUN (ospf6_stub_router_admin,
791 ospf6_stub_router_admin_cmd,
792 "stub-router administrative",
793 "Make router a stub router\n"
794 "Advertise inability to be a transit router\n"
795 "Administratively applied, for an indefinite period\n")
796 {
797 struct listnode *node;
798 struct ospf6_area *oa;
799
800 if (!CHECK_FLAG (ospf6->flag, OSPF6_STUB_ROUTER))
801 {
802 for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, node, oa))
803 {
804 OSPF6_OPT_CLEAR (oa->options, OSPF6_OPT_V6);
805 OSPF6_OPT_CLEAR (oa->options, OSPF6_OPT_R);
806 OSPF6_ROUTER_LSA_SCHEDULE (oa);
807 }
808 SET_FLAG (ospf6->flag, OSPF6_STUB_ROUTER);
809 }
810
811 return CMD_SUCCESS;
812 }
813
814 DEFUN (no_ospf6_stub_router_admin,
815 no_ospf6_stub_router_admin_cmd,
816 "no stub-router administrative",
817 NO_STR
818 "Make router a stub router\n"
819 "Advertise ability to be a transit router\n"
820 "Administratively applied, for an indefinite period\n")
821 {
822 struct listnode *node;
823 struct ospf6_area *oa;
824
825 if (CHECK_FLAG (ospf6->flag, OSPF6_STUB_ROUTER))
826 {
827 for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, node, oa))
828 {
829 OSPF6_OPT_SET (oa->options, OSPF6_OPT_V6);
830 OSPF6_OPT_SET (oa->options, OSPF6_OPT_R);
831 OSPF6_ROUTER_LSA_SCHEDULE (oa);
832 }
833 UNSET_FLAG (ospf6->flag, OSPF6_STUB_ROUTER);
834 }
835
836 return CMD_SUCCESS;
837 }
838
839 #if 0
840 DEFUN (ospf6_stub_router_startup,
841 ospf6_stub_router_startup_cmd,
842 "stub-router on-startup (5-86400)",
843 "Make router a stub router\n"
844 "Advertise inability to be a transit router\n"
845 "Automatically advertise as stub-router on startup of OSPF6\n"
846 "Time (seconds) to advertise self as stub-router\n")
847 {
848 return CMD_SUCCESS;
849 }
850
851 DEFUN (no_ospf6_stub_router_startup,
852 no_ospf6_stub_router_startup_cmd,
853 "no stub-router on-startup",
854 NO_STR
855 "Make router a stub router\n"
856 "Advertise inability to be a transit router\n"
857 "Automatically advertise as stub-router on startup of OSPF6\n"
858 "Time (seconds) to advertise self as stub-router\n")
859 {
860 return CMD_SUCCESS;
861 }
862
863 DEFUN (ospf6_stub_router_shutdown,
864 ospf6_stub_router_shutdown_cmd,
865 "stub-router on-shutdown (5-86400)",
866 "Make router a stub router\n"
867 "Advertise inability to be a transit router\n"
868 "Automatically advertise as stub-router before shutdown\n"
869 "Time (seconds) to advertise self as stub-router\n")
870 {
871 return CMD_SUCCESS;
872 }
873
874 DEFUN (no_ospf6_stub_router_shutdown,
875 no_ospf6_stub_router_shutdown_cmd,
876 "no stub-router on-shutdown",
877 NO_STR
878 "Make router a stub router\n"
879 "Advertise inability to be a transit router\n"
880 "Automatically advertise as stub-router before shutdown\n"
881 "Time (seconds) to advertise self as stub-router\n")
882 {
883 return CMD_SUCCESS;
884 }
885 #endif
886
887 static void
888 ospf6_show (struct vty *vty, struct ospf6 *o)
889 {
890 struct listnode *n;
891 struct ospf6_area *oa;
892 char router_id[16], duration[32];
893 struct timeval now, running, result;
894 char buf[32], rbuf[32];
895
896 /* process id, router id */
897 inet_ntop (AF_INET, &o->router_id, router_id, sizeof (router_id));
898 vty_out (vty, " OSPFv3 Routing Process (0) with Router-ID %s%s",
899 router_id, VNL);
900
901 /* running time */
902 quagga_gettime (QUAGGA_CLK_MONOTONIC, &now);
903 timersub (&now, &o->starttime, &running);
904 timerstring (&running, duration, sizeof (duration));
905 vty_out (vty, " Running %s%s", duration, VNL);
906
907 /* Redistribute configuration */
908 /* XXX */
909
910 vty_out (vty, " LSA minimum arrival %d msecs%s", o->lsa_minarrival,
911 VTY_NEWLINE);
912
913 /* Show SPF parameters */
914 vty_out(vty, " Initial SPF scheduling delay %d millisec(s)%s"
915 " Minimum hold time between consecutive SPFs %d millsecond(s)%s"
916 " Maximum hold time between consecutive SPFs %d millsecond(s)%s"
917 " Hold time multiplier is currently %d%s",
918 o->spf_delay, VNL,
919 o->spf_holdtime, VNL,
920 o->spf_max_holdtime, VNL,
921 o->spf_hold_multiplier, VNL);
922
923 vty_out(vty, " SPF algorithm ");
924 if (o->ts_spf.tv_sec || o->ts_spf.tv_usec)
925 {
926 timersub(&now, &o->ts_spf, &result);
927 timerstring(&result, buf, sizeof(buf));
928 ospf6_spf_reason_string(o->last_spf_reason, rbuf, sizeof(rbuf));
929 vty_out(vty, "last executed %s ago, reason %s%s", buf, rbuf, VNL);
930 vty_out (vty, " Last SPF duration %lld sec %lld usec%s",
931 (long long)o->ts_spf_duration.tv_sec,
932 (long long)o->ts_spf_duration.tv_usec, VNL);
933 }
934 else
935 vty_out(vty, "has not been run$%s", VNL);
936 threadtimer_string(now, o->t_spf_calc, buf, sizeof(buf));
937 vty_out (vty, " SPF timer %s%s%s",
938 (o->t_spf_calc ? "due in " : "is "), buf, VNL);
939
940 if (CHECK_FLAG (o->flag, OSPF6_STUB_ROUTER))
941 vty_out (vty, " Router Is Stub Router%s", VNL);
942
943 /* LSAs */
944 vty_out (vty, " Number of AS scoped LSAs is %u%s",
945 o->lsdb->count, VNL);
946
947 /* Areas */
948 vty_out (vty, " Number of areas in this router is %u%s",
949 listcount (o->area_list), VNL);
950
951 if (CHECK_FLAG(o->config_flags, OSPF6_LOG_ADJACENCY_CHANGES))
952 {
953 if (CHECK_FLAG(o->config_flags, OSPF6_LOG_ADJACENCY_DETAIL))
954 vty_out(vty, " All adjacency changes are logged%s",VTY_NEWLINE);
955 else
956 vty_out(vty, " Adjacency changes are logged%s",VTY_NEWLINE);
957 }
958
959 vty_out (vty, "%s",VTY_NEWLINE);
960
961 for (ALL_LIST_ELEMENTS_RO (o->area_list, n, oa))
962 ospf6_area_show (vty, oa);
963 }
964
965 /* show top level structures */
966 DEFUN (show_ipv6_ospf6,
967 show_ipv6_ospf6_cmd,
968 "show ipv6 ospf6",
969 SHOW_STR
970 IP6_STR
971 OSPF6_STR)
972 {
973 OSPF6_CMD_CHECK_RUNNING ();
974
975 ospf6_show (vty, ospf6);
976 return CMD_SUCCESS;
977 }
978
979 DEFUN (show_ipv6_ospf6_route,
980 show_ipv6_ospf6_route_cmd,
981 "show ipv6 ospf6 route [<intra-area|inter-area|external-1|external-2|X:X::X:X|X:X::X:X/M|detail|summary>]",
982 SHOW_STR
983 IP6_STR
984 OSPF6_STR
985 ROUTE_STR
986 "Display Intra-Area routes\n"
987 "Display Inter-Area routes\n"
988 "Display Type-1 External routes\n"
989 "Display Type-2 External routes\n"
990 "Specify IPv6 address\n"
991 "Specify IPv6 prefix\n"
992 "Detailed information\n"
993 "Summary of route table\n")
994 {
995 OSPF6_CMD_CHECK_RUNNING ();
996
997 ospf6_route_table_show (vty, 4, argc, argv, ospf6->route_table);
998 return CMD_SUCCESS;
999 }
1000
1001 DEFUN (show_ipv6_ospf6_route_match,
1002 show_ipv6_ospf6_route_match_cmd,
1003 "show ipv6 ospf6 route X:X::X:X/M <match|longer>",
1004 SHOW_STR
1005 IP6_STR
1006 OSPF6_STR
1007 ROUTE_STR
1008 "Specify IPv6 prefix\n"
1009 "Display routes which match the specified route\n"
1010 "Display routes longer than the specified route\n")
1011 {
1012 OSPF6_CMD_CHECK_RUNNING ();
1013
1014 ospf6_route_table_show (vty, 4, argc, argv, ospf6->route_table);
1015 return CMD_SUCCESS;
1016 }
1017
1018 DEFUN (show_ipv6_ospf6_route_match_detail,
1019 show_ipv6_ospf6_route_match_detail_cmd,
1020 "show ipv6 ospf6 route X:X::X:X/M match detail",
1021 SHOW_STR
1022 IP6_STR
1023 OSPF6_STR
1024 ROUTE_STR
1025 "Specify IPv6 prefix\n"
1026 "Display routes which match the specified route\n"
1027 "Detailed information\n"
1028 )
1029 {
1030 OSPF6_CMD_CHECK_RUNNING ();
1031
1032 ospf6_route_table_show (vty, 4, argc, argv, ospf6->route_table);
1033 return CMD_SUCCESS;
1034 }
1035
1036
1037
1038 DEFUN (show_ipv6_ospf6_route_type_detail,
1039 show_ipv6_ospf6_route_type_detail_cmd,
1040 "show ipv6 ospf6 route <intra-area|inter-area|external-1|external-2> detail",
1041 SHOW_STR
1042 IP6_STR
1043 OSPF6_STR
1044 ROUTE_STR
1045 "Display Intra-Area routes\n"
1046 "Display Inter-Area routes\n"
1047 "Display Type-1 External routes\n"
1048 "Display Type-2 External routes\n"
1049 "Detailed information\n"
1050 )
1051 {
1052 OSPF6_CMD_CHECK_RUNNING ();
1053
1054 ospf6_route_table_show (vty, 4, argc, argv, ospf6->route_table);
1055 return CMD_SUCCESS;
1056 }
1057
1058 static void
1059 ospf6_stub_router_config_write (struct vty *vty)
1060 {
1061 if (CHECK_FLAG (ospf6->flag, OSPF6_STUB_ROUTER))
1062 {
1063 vty_out (vty, " stub-router administrative%s", VNL);
1064 }
1065 return;
1066 }
1067
1068 static int
1069 ospf6_distance_config_write (struct vty *vty)
1070 {
1071 struct route_node *rn;
1072 struct ospf6_distance *odistance;
1073
1074 if (ospf6->distance_all)
1075 vty_out (vty, " distance %u%s", ospf6->distance_all, VTY_NEWLINE);
1076
1077 if (ospf6->distance_intra
1078 || ospf6->distance_inter
1079 || ospf6->distance_external)
1080 {
1081 vty_out (vty, " distance ospf6");
1082
1083 if (ospf6->distance_intra)
1084 vty_out (vty, " intra-area %u", ospf6->distance_intra);
1085 if (ospf6->distance_inter)
1086 vty_out (vty, " inter-area %u", ospf6->distance_inter);
1087 if (ospf6->distance_external)
1088 vty_out (vty, " external %u", ospf6->distance_external);
1089
1090 vty_out (vty, "%s", VTY_NEWLINE);
1091 }
1092
1093 for (rn = route_top (ospf6->distance_table); rn; rn = route_next (rn))
1094 if ((odistance = rn->info) != NULL)
1095 {
1096 char buf[PREFIX_STRLEN];
1097
1098 vty_out (vty, " distance %u %s %s%s", odistance->distance,
1099 prefix2str (&rn->p, buf, sizeof (buf)),
1100 odistance->access_list ? odistance->access_list : "",
1101 VTY_NEWLINE);
1102 }
1103 return 0;
1104 }
1105
1106 /* OSPF configuration write function. */
1107 static int
1108 config_write_ospf6 (struct vty *vty)
1109 {
1110 char router_id[16];
1111 struct listnode *j, *k;
1112 struct ospf6_area *oa;
1113 struct ospf6_interface *oi;
1114
1115 /* OSPFv3 configuration. */
1116 if (ospf6 == NULL)
1117 return CMD_SUCCESS;
1118
1119 inet_ntop (AF_INET, &ospf6->router_id_static, router_id, sizeof (router_id));
1120 vty_out (vty, "router ospf6%s", VNL);
1121 if (ospf6->router_id_static != 0)
1122 vty_out (vty, " router-id %s%s", router_id, VNL);
1123
1124 /* log-adjacency-changes flag print. */
1125 if (CHECK_FLAG(ospf6->config_flags, OSPF6_LOG_ADJACENCY_CHANGES))
1126 {
1127 if (CHECK_FLAG(ospf6->config_flags, OSPF6_LOG_ADJACENCY_DETAIL))
1128 vty_out(vty, " log-adjacency-changes detail%s", VTY_NEWLINE);
1129 }
1130 else
1131 {
1132 vty_out(vty, " no log-adjacency-changes%s", VTY_NEWLINE);
1133 }
1134
1135 if (ospf6->ref_bandwidth != OSPF6_REFERENCE_BANDWIDTH)
1136 vty_out (vty, " auto-cost reference-bandwidth %d%s", ospf6->ref_bandwidth,
1137 VNL);
1138
1139 /* LSA timers print. */
1140 if (ospf6->lsa_minarrival != OSPF_MIN_LS_ARRIVAL)
1141 vty_out (vty, " timers lsa min-arrival %d%s", ospf6->lsa_minarrival,
1142 VTY_NEWLINE);
1143
1144 ospf6_stub_router_config_write (vty);
1145 ospf6_redistribute_config_write (vty);
1146 ospf6_area_config_write (vty);
1147 ospf6_spf_config_write (vty);
1148 ospf6_distance_config_write (vty);
1149
1150 for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, j, oa))
1151 {
1152 for (ALL_LIST_ELEMENTS_RO (oa->if_list, k, oi))
1153 vty_out (vty, " interface %s area %s%s",
1154 oi->interface->name, oa->name, VNL);
1155 }
1156 vty_out (vty, "!%s", VNL);
1157 return 0;
1158 }
1159
1160 /* OSPF6 node structure. */
1161 static struct cmd_node ospf6_node =
1162 {
1163 OSPF6_NODE,
1164 "%s(config-ospf6)# ",
1165 1 /* VTYSH */
1166 };
1167
1168 /* Install ospf related commands. */
1169 void
1170 ospf6_top_init (void)
1171 {
1172 /* Install ospf6 top node. */
1173 install_node (&ospf6_node, config_write_ospf6);
1174
1175 install_element (VIEW_NODE, &show_ipv6_ospf6_cmd);
1176 install_element (CONFIG_NODE, &router_ospf6_cmd);
1177 install_element (CONFIG_NODE, &no_router_ospf6_cmd);
1178
1179 install_element (VIEW_NODE, &show_ipv6_ospf6_route_cmd);
1180 install_element (VIEW_NODE, &show_ipv6_ospf6_route_match_cmd);
1181 install_element (VIEW_NODE, &show_ipv6_ospf6_route_match_detail_cmd);
1182 install_element (VIEW_NODE, &show_ipv6_ospf6_route_type_detail_cmd);
1183
1184 install_default (OSPF6_NODE);
1185 install_element (OSPF6_NODE, &ospf6_router_id_cmd);
1186 install_element (OSPF6_NODE, &ospf6_log_adjacency_changes_cmd);
1187 install_element (OSPF6_NODE, &ospf6_log_adjacency_changes_detail_cmd);
1188 install_element (OSPF6_NODE, &no_ospf6_log_adjacency_changes_cmd);
1189 install_element (OSPF6_NODE, &no_ospf6_log_adjacency_changes_detail_cmd);
1190
1191 /* LSA timers commands */
1192 install_element (OSPF6_NODE, &ospf6_timers_lsa_cmd);
1193 install_element (OSPF6_NODE, &no_ospf6_timers_lsa_cmd);
1194
1195 install_element (OSPF6_NODE, &ospf6_interface_area_cmd);
1196 install_element (OSPF6_NODE, &no_ospf6_interface_area_cmd);
1197 install_element (OSPF6_NODE, &ospf6_stub_router_admin_cmd);
1198 install_element (OSPF6_NODE, &no_ospf6_stub_router_admin_cmd);
1199 /* For a later time */
1200 #if 0
1201 install_element (OSPF6_NODE, &ospf6_stub_router_startup_cmd);
1202 install_element (OSPF6_NODE, &no_ospf6_stub_router_startup_cmd);
1203 install_element (OSPF6_NODE, &ospf6_stub_router_shutdown_cmd);
1204 install_element (OSPF6_NODE, &no_ospf6_stub_router_shutdown_cmd);
1205 #endif
1206
1207 install_element (OSPF6_NODE, &ospf6_distance_cmd);
1208 install_element (OSPF6_NODE, &no_ospf6_distance_cmd);
1209 install_element (OSPF6_NODE, &ospf6_distance_ospf6_cmd);
1210 install_element (OSPF6_NODE, &no_ospf6_distance_ospf6_cmd);
1211 #if 0
1212 install_element (OSPF6_NODE, &ospf6_distance_source_cmd);
1213 install_element (OSPF6_NODE, &no_ospf6_distance_source_cmd);
1214 #endif
1215 }