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