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