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