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