]> git.proxmox.com Git - mirror_frr.git/blob - ospf6d/ospf6d.c
ospf6d: kill ospf6_memory.h, use MTYPE_STATIC
[mirror_frr.git] / ospf6d / ospf6d.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 "thread.h"
24 #include "linklist.h"
25 #include "vty.h"
26 #include "command.h"
27 #include "plist.h"
28
29 #include "ospf6_proto.h"
30 #include "ospf6_top.h"
31 #include "ospf6_network.h"
32 #include "ospf6_lsa.h"
33 #include "ospf6_lsdb.h"
34 #include "ospf6_message.h"
35 #include "ospf6_route.h"
36 #include "ospf6_zebra.h"
37 #include "ospf6_spf.h"
38 #include "ospf6_area.h"
39 #include "ospf6_interface.h"
40 #include "ospf6_neighbor.h"
41 #include "ospf6_intra.h"
42 #include "ospf6_asbr.h"
43 #include "ospf6_abr.h"
44 #include "ospf6_flood.h"
45 #include "ospf6d.h"
46 #include "ospf6_bfd.h"
47 #include "lib/json.h"
48
49 DEFINE_MGROUP(OSPF6D, "ospf6d");
50
51 struct route_node *route_prev(struct route_node *node)
52 {
53 struct route_node *end;
54 struct route_node *prev = NULL;
55
56 end = node;
57 node = node->parent;
58 if (node)
59 route_lock_node(node);
60 while (node) {
61 prev = node;
62 node = route_next(node);
63 if (node == end) {
64 route_unlock_node(node);
65 node = NULL;
66 }
67 }
68 route_unlock_node(end);
69 if (prev)
70 route_lock_node(prev);
71
72 return prev;
73 }
74
75 static int config_write_ospf6_debug(struct vty *vty);
76 static struct cmd_node debug_node = {
77 .name = "debug",
78 .node = DEBUG_NODE,
79 .prompt = "",
80 .config_write = config_write_ospf6_debug,
81 };
82
83 static int config_write_ospf6_debug(struct vty *vty)
84 {
85 config_write_ospf6_debug_message(vty);
86 config_write_ospf6_debug_lsa(vty);
87 config_write_ospf6_debug_zebra(vty);
88 config_write_ospf6_debug_interface(vty);
89 config_write_ospf6_debug_neighbor(vty);
90 config_write_ospf6_debug_spf(vty);
91 config_write_ospf6_debug_route(vty);
92 config_write_ospf6_debug_brouter(vty);
93 config_write_ospf6_debug_asbr(vty);
94 config_write_ospf6_debug_abr(vty);
95 config_write_ospf6_debug_flood(vty);
96
97 return 0;
98 }
99
100 DEFUN_NOSH (show_debugging_ospf6,
101 show_debugging_ospf6_cmd,
102 "show debugging [ospf6]",
103 SHOW_STR
104 DEBUG_STR
105 OSPF6_STR)
106 {
107 vty_out(vty, "OSPF6 debugging status:\n");
108
109 config_write_ospf6_debug(vty);
110
111 return CMD_SUCCESS;
112 }
113
114 #define AREA_LSDB_TITLE_FORMAT \
115 "\n Area Scoped Link State Database (Area %s)\n\n"
116 #define IF_LSDB_TITLE_FORMAT \
117 "\n I/F Scoped Link State Database (I/F %s in Area %s)\n\n"
118 #define AS_LSDB_TITLE_FORMAT "\n AS Scoped Link State Database\n\n"
119
120 static int parse_show_level(int idx_level, int argc, struct cmd_token **argv)
121 {
122 int level = OSPF6_LSDB_SHOW_LEVEL_NORMAL;
123
124 if (argc > idx_level) {
125 if (strmatch(argv[idx_level]->text, "detail"))
126 level = OSPF6_LSDB_SHOW_LEVEL_DETAIL;
127 else if (strmatch(argv[idx_level]->text, "dump"))
128 level = OSPF6_LSDB_SHOW_LEVEL_DUMP;
129 else if (strmatch(argv[idx_level]->text, "internal"))
130 level = OSPF6_LSDB_SHOW_LEVEL_INTERNAL;
131 }
132
133 return level;
134 }
135
136 static uint16_t parse_type_spec(int idx_lsa, int argc, struct cmd_token **argv)
137 {
138 uint16_t type = 0;
139
140 if (argc > idx_lsa) {
141 if (strmatch(argv[idx_lsa]->text, "router"))
142 type = htons(OSPF6_LSTYPE_ROUTER);
143 else if (strmatch(argv[idx_lsa]->text, "network"))
144 type = htons(OSPF6_LSTYPE_NETWORK);
145 else if (strmatch(argv[idx_lsa]->text, "as-external"))
146 type = htons(OSPF6_LSTYPE_AS_EXTERNAL);
147 else if (strmatch(argv[idx_lsa]->text, "intra-prefix"))
148 type = htons(OSPF6_LSTYPE_INTRA_PREFIX);
149 else if (strmatch(argv[idx_lsa]->text, "inter-router"))
150 type = htons(OSPF6_LSTYPE_INTER_ROUTER);
151 else if (strmatch(argv[idx_lsa]->text, "inter-prefix"))
152 type = htons(OSPF6_LSTYPE_INTER_PREFIX);
153 else if (strmatch(argv[idx_lsa]->text, "link"))
154 type = htons(OSPF6_LSTYPE_LINK);
155 }
156
157 return type;
158 }
159
160 void ospf6_lsdb_show(struct vty *vty, enum ospf_lsdb_show_level level,
161 uint16_t *type, uint32_t *id, uint32_t *adv_router,
162 struct ospf6_lsdb *lsdb, json_object *json_obj,
163 bool use_json)
164 {
165 struct ospf6_lsa *lsa;
166 const struct route_node *end = NULL;
167 void (*showfunc)(struct vty *, struct ospf6_lsa *, json_object *,
168 bool) = NULL;
169 json_object *json_array = NULL;
170
171 switch (level) {
172 case OSPF6_LSDB_SHOW_LEVEL_DETAIL:
173 showfunc = ospf6_lsa_show;
174 break;
175 case OSPF6_LSDB_SHOW_LEVEL_INTERNAL:
176 showfunc = ospf6_lsa_show_internal;
177 break;
178 case OSPF6_LSDB_SHOW_LEVEL_DUMP:
179 showfunc = ospf6_lsa_show_dump;
180 break;
181 case OSPF6_LSDB_SHOW_LEVEL_NORMAL:
182 default:
183 showfunc = ospf6_lsa_show_summary;
184 }
185
186 if (use_json)
187 json_array = json_object_new_array();
188
189 if (type && id && adv_router) {
190 lsa = ospf6_lsdb_lookup(*type, *id, *adv_router, lsdb);
191 if (lsa) {
192 if (level == OSPF6_LSDB_SHOW_LEVEL_NORMAL)
193 ospf6_lsa_show(vty, lsa, json_array, use_json);
194 else
195 (*showfunc)(vty, lsa, json_array, use_json);
196 }
197
198 if (use_json)
199 json_object_object_add(json_obj, "lsa", json_array);
200 return;
201 }
202
203 if ((level == OSPF6_LSDB_SHOW_LEVEL_NORMAL) && !use_json)
204 ospf6_lsa_show_summary_header(vty);
205
206 end = ospf6_lsdb_head(lsdb, !!type + !!(type && adv_router),
207 type ? *type : 0, adv_router ? *adv_router : 0,
208 &lsa);
209 while (lsa) {
210 if ((!adv_router || lsa->header->adv_router == *adv_router)
211 && (!id || lsa->header->id == *id))
212 (*showfunc)(vty, lsa, json_array, use_json);
213 lsa = ospf6_lsdb_next(end, lsa);
214 }
215
216 if (use_json)
217 json_object_object_add(json_obj, "lsa", json_array);
218 }
219
220 static void ospf6_lsdb_show_wrapper(struct vty *vty,
221 enum ospf_lsdb_show_level level,
222 uint16_t *type, uint32_t *id,
223 uint32_t *adv_router, bool uj,
224 struct ospf6 *ospf6)
225 {
226 struct listnode *i, *j;
227 struct ospf6 *o = ospf6;
228 struct ospf6_area *oa;
229 struct ospf6_interface *oi;
230 json_object *json = NULL;
231 json_object *json_array = NULL;
232 json_object *json_obj = NULL;
233
234 if (uj) {
235 json = json_object_new_object();
236 json_array = json_object_new_array();
237 }
238 for (ALL_LIST_ELEMENTS_RO(o->area_list, i, oa)) {
239 if (uj) {
240 json_obj = json_object_new_object();
241 json_object_string_add(json_obj, "areaId", oa->name);
242 } else
243 vty_out(vty, AREA_LSDB_TITLE_FORMAT, oa->name);
244 ospf6_lsdb_show(vty, level, type, id, adv_router, oa->lsdb,
245 json_obj, uj);
246 if (uj)
247 json_object_array_add(json_array, json_obj);
248 }
249 if (uj)
250 json_object_object_add(json, "areaScopedLinkStateDb",
251 json_array);
252
253 if (uj)
254 json_array = json_object_new_array();
255 for (ALL_LIST_ELEMENTS_RO(o->area_list, i, oa)) {
256 for (ALL_LIST_ELEMENTS_RO(oa->if_list, j, oi)) {
257 if (uj) {
258 json_obj = json_object_new_object();
259 json_object_string_add(json_obj, "areaId",
260 oa->name);
261 json_object_string_add(json_obj, "interface",
262 oi->interface->name);
263 } else
264 vty_out(vty, IF_LSDB_TITLE_FORMAT,
265 oi->interface->name, oa->name);
266 ospf6_lsdb_show(vty, level, type, id, adv_router,
267 oi->lsdb, json_obj, uj);
268 if (uj)
269 json_object_array_add(json_array, json_obj);
270 }
271 }
272 if (uj)
273 json_object_object_add(json, "interfaceScopedLinkStateDb",
274 json_array);
275 if (uj) {
276 json_array = json_object_new_array();
277 json_obj = json_object_new_object();
278 } else
279 vty_out(vty, AS_LSDB_TITLE_FORMAT);
280
281 ospf6_lsdb_show(vty, level, type, id, adv_router, o->lsdb, json_obj,
282 uj);
283
284 if (uj) {
285 json_object_array_add(json_array, json_obj);
286 json_object_object_add(json, "asScopedLinkStateDb", json_array);
287
288 vty_out(vty, "%s\n",
289 json_object_to_json_string_ext(
290 json, JSON_C_TO_STRING_PRETTY));
291 json_object_free(json);
292 } else
293 vty_out(vty, "\n");
294 }
295
296 static void ospf6_lsdb_type_show_wrapper(struct vty *vty,
297 enum ospf_lsdb_show_level level,
298 uint16_t *type, uint32_t *id,
299 uint32_t *adv_router, bool uj,
300 struct ospf6 *ospf6)
301 {
302 struct listnode *i, *j;
303 struct ospf6 *o = ospf6;
304 struct ospf6_area *oa;
305 struct ospf6_interface *oi;
306 json_object *json = NULL;
307 json_object *json_array = NULL;
308 json_object *json_obj = NULL;
309
310 if (uj) {
311 json = json_object_new_object();
312 json_array = json_object_new_array();
313 }
314
315 switch (OSPF6_LSA_SCOPE(*type)) {
316 case OSPF6_SCOPE_AREA:
317 for (ALL_LIST_ELEMENTS_RO(o->area_list, i, oa)) {
318 if (uj) {
319 json_obj = json_object_new_object();
320 json_object_string_add(json_obj, "areaId",
321 oa->name);
322 } else
323 vty_out(vty, AREA_LSDB_TITLE_FORMAT, oa->name);
324
325 ospf6_lsdb_show(vty, level, type, id, adv_router,
326 oa->lsdb, json_obj, uj);
327 if (uj)
328 json_object_array_add(json_array, json_obj);
329 }
330 if (uj)
331 json_object_object_add(json, "areaScopedLinkStateDb",
332 json_array);
333 break;
334
335 case OSPF6_SCOPE_LINKLOCAL:
336 for (ALL_LIST_ELEMENTS_RO(o->area_list, i, oa)) {
337 for (ALL_LIST_ELEMENTS_RO(oa->if_list, j, oi)) {
338 if (uj) {
339 json_obj = json_object_new_object();
340 json_object_string_add(
341 json_obj, "areaId", oa->name);
342 json_object_string_add(
343 json_obj, "interface",
344 oi->interface->name);
345 } else
346 vty_out(vty, IF_LSDB_TITLE_FORMAT,
347 oi->interface->name, oa->name);
348
349 ospf6_lsdb_show(vty, level, type, id,
350 adv_router, oi->lsdb, json_obj,
351 uj);
352
353 if (uj)
354 json_object_array_add(json_array,
355 json_obj);
356 }
357 }
358 if (uj)
359 json_object_object_add(
360 json, "interfaceScopedLinkStateDb", json_array);
361 break;
362
363 case OSPF6_SCOPE_AS:
364 if (uj)
365 json_obj = json_object_new_object();
366 else
367 vty_out(vty, AS_LSDB_TITLE_FORMAT);
368
369 ospf6_lsdb_show(vty, level, type, id, adv_router, o->lsdb,
370 json_obj, uj);
371 if (uj) {
372 json_object_array_add(json_array, json_obj);
373 json_object_object_add(json, "asScopedLinkStateDb",
374 json_array);
375 }
376 break;
377
378 default:
379 assert(0);
380 break;
381 }
382 if (uj) {
383 vty_out(vty, "%s\n",
384 json_object_to_json_string_ext(
385 json, JSON_C_TO_STRING_PRETTY));
386 json_object_free(json);
387 } else
388 vty_out(vty, "\n");
389 }
390
391 DEFUN (show_ipv6_ospf6_database,
392 show_ipv6_ospf6_database_cmd,
393 "show ipv6 ospf6 database [<detail|dump|internal>] [json]",
394 SHOW_STR
395 IPV6_STR
396 OSPF6_STR
397 "Display Link state database\n"
398 "Display details of LSAs\n"
399 "Dump LSAs\n"
400 "Display LSA's internal information\n"
401 JSON_STR)
402 {
403 int idx_level = 4;
404 int level;
405 bool uj = use_json(argc, argv);
406 struct ospf6 *ospf6;
407
408 ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME);
409 OSPF6_CMD_CHECK_RUNNING(ospf6);
410
411 level = parse_show_level(idx_level, argc, argv);
412 ospf6_lsdb_show_wrapper(vty, level, NULL, NULL, NULL, uj, ospf6);
413 return CMD_SUCCESS;
414 }
415
416 DEFUN (show_ipv6_ospf6_database_type, show_ipv6_ospf6_database_type_cmd,
417 "show ipv6 ospf6 database <router|network|inter-prefix|inter-router|as-external|group-membership|type-7|link|intra-prefix> [<detail|dump|internal>] [json]",
418 SHOW_STR
419 IPV6_STR
420 OSPF6_STR
421 "Display Link state database\n"
422 "Display Router LSAs\n"
423 "Display Network LSAs\n"
424 "Display Inter-Area-Prefix LSAs\n"
425 "Display Inter-Area-Router LSAs\n"
426 "Display As-External LSAs\n"
427 "Display Group-Membership LSAs\n"
428 "Display Type-7 LSAs\n"
429 "Display Link LSAs\n"
430 "Display Intra-Area-Prefix LSAs\n"
431 "Display details of LSAs\n"
432 "Dump LSAs\n"
433 "Display LSA's internal information\n"
434 JSON_STR)
435 {
436 int idx_lsa = 4;
437 int idx_level = 5;
438 int level;
439 uint16_t type = 0;
440 bool uj = use_json(argc, argv);
441 struct ospf6 *ospf6;
442
443
444 ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME);
445 OSPF6_CMD_CHECK_RUNNING(ospf6);
446
447 type = parse_type_spec(idx_lsa, argc, argv);
448 level = parse_show_level(idx_level, argc, argv);
449
450 ospf6_lsdb_type_show_wrapper(vty, level, &type, NULL, NULL, uj, ospf6);
451 return CMD_SUCCESS;
452 }
453
454 DEFUN (show_ipv6_ospf6_database_id,
455 show_ipv6_ospf6_database_id_cmd,
456 "show ipv6 ospf6 database <*|linkstate-id> A.B.C.D [<detail|dump|internal>] [json]",
457 SHOW_STR
458 IPV6_STR
459 OSPF6_STR
460 "Display Link state database\n"
461 "Any Link state Type\n"
462 "Search by Link state ID\n"
463 "Specify Link state ID as IPv4 address notation\n"
464 "Display details of LSAs\n"
465 "Dump LSAs\n"
466 "Display LSA's internal information\n"
467 JSON_STR)
468 {
469 int idx_ipv4 = 5;
470 int idx_level = 6;
471 int level;
472 uint32_t id = 0;
473 bool uj = use_json(argc, argv);
474 struct ospf6 *ospf6;
475
476
477 ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME);
478 OSPF6_CMD_CHECK_RUNNING(ospf6);
479
480 if (argv[idx_ipv4]->type == IPV4_TKN)
481 inet_pton(AF_INET, argv[idx_ipv4]->arg, &id);
482
483 level = parse_show_level(idx_level, argc, argv);
484 ospf6_lsdb_show_wrapper(vty, level, NULL, &id, NULL, uj, ospf6);
485
486 return CMD_SUCCESS;
487 }
488
489 DEFUN (show_ipv6_ospf6_database_router,
490 show_ipv6_ospf6_database_router_cmd,
491 "show ipv6 ospf6 database <*|adv-router> * A.B.C.D <detail|dump|internal> [json]",
492 SHOW_STR
493 IPV6_STR
494 OSPF6_STR
495 "Display Link state database\n"
496 "Any Link state Type\n"
497 "Search by Advertising Router\n"
498 "Any Link state ID\n"
499 "Specify Advertising Router as IPv4 address notation\n"
500 "Display details of LSAs\n"
501 "Dump LSAs\n"
502 "Display LSA's internal information\n"
503 JSON_STR)
504 {
505 int idx_ipv4 = 6;
506 int idx_level = 7;
507 int level;
508 uint32_t adv_router = 0;
509 bool uj = use_json(argc, argv);
510 struct ospf6 *ospf6;
511
512
513 ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME);
514 OSPF6_CMD_CHECK_RUNNING(ospf6);
515 inet_pton(AF_INET, argv[idx_ipv4]->arg, &adv_router);
516 level = parse_show_level(idx_level, argc, argv);
517
518 ospf6_lsdb_show_wrapper(vty, level, NULL, NULL, &adv_router, uj, ospf6);
519 return CMD_SUCCESS;
520 }
521
522 DEFUN_HIDDEN (show_ipv6_ospf6_database_aggr_router,
523 show_ipv6_ospf6_database_aggr_router_cmd,
524 "show ipv6 ospf6 database aggr adv-router A.B.C.D",
525 SHOW_STR
526 IPV6_STR
527 OSPF6_STR
528 "Display Link state database\n"
529 "Aggregated Router LSA\n"
530 "Search by Advertising Router\n"
531 "Specify Advertising Router as IPv4 address notation\n")
532 {
533 int level = OSPF6_LSDB_SHOW_LEVEL_DETAIL;
534 uint16_t type = htons(OSPF6_LSTYPE_ROUTER);
535 int idx_ipv4 = 6;
536 struct listnode *i;
537 struct ospf6 *ospf6;
538 struct ospf6_area *oa;
539 struct ospf6_lsdb *lsdb;
540 uint32_t adv_router = 0;
541
542 ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME);
543 OSPF6_CMD_CHECK_RUNNING(ospf6);
544
545 inet_pton(AF_INET, argv[idx_ipv4]->arg, &adv_router);
546
547 for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa)) {
548 if (adv_router == ospf6->router_id)
549 lsdb = oa->lsdb_self;
550 else
551 lsdb = oa->lsdb;
552 if (ospf6_create_single_router_lsa(oa, lsdb, adv_router)
553 == NULL) {
554 vty_out(vty, "Adv router is not found in LSDB.");
555 return CMD_SUCCESS;
556 }
557 ospf6_lsdb_show(vty, level, &type, NULL, NULL,
558 oa->temp_router_lsa_lsdb, NULL, false);
559 /* Remove the temp cache */
560 ospf6_remove_temp_router_lsa(oa);
561 }
562
563 vty_out(vty, "\n");
564
565 return CMD_SUCCESS;
566 }
567
568 DEFUN (show_ipv6_ospf6_database_type_id,
569 show_ipv6_ospf6_database_type_id_cmd,
570 "show ipv6 ospf6 database <router|network|inter-prefix|inter-router|as-external|group-membership|type-7|link|intra-prefix> linkstate-id A.B.C.D [<detail|dump|internal>] [json]",
571 SHOW_STR
572 IPV6_STR
573 OSPF6_STR
574 "Display Link state database\n"
575 "Display Router LSAs\n"
576 "Display Network LSAs\n"
577 "Display Inter-Area-Prefix LSAs\n"
578 "Display Inter-Area-Router LSAs\n"
579 "Display As-External LSAs\n"
580 "Display Group-Membership LSAs\n"
581 "Display Type-7 LSAs\n"
582 "Display Link LSAs\n"
583 "Display Intra-Area-Prefix LSAs\n"
584 "Search by Link state ID\n"
585 "Specify Link state ID as IPv4 address notation\n"
586 "Display details of LSAs\n"
587 "Dump LSAs\n"
588 "Display LSA's internal information\n"
589 JSON_STR)
590 {
591 int idx_lsa = 4;
592 int idx_ipv4 = 6;
593 int idx_level = 7;
594 int level;
595 uint16_t type = 0;
596 uint32_t id = 0;
597 bool uj = use_json(argc, argv);
598 struct ospf6 *ospf6;
599
600
601 ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME);
602 OSPF6_CMD_CHECK_RUNNING(ospf6);
603
604 type = parse_type_spec(idx_lsa, argc, argv);
605 inet_pton(AF_INET, argv[idx_ipv4]->arg, &id);
606 level = parse_show_level(idx_level, argc, argv);
607
608 ospf6_lsdb_type_show_wrapper(vty, level, &type, &id, NULL, uj, ospf6);
609 return CMD_SUCCESS;
610 }
611
612 DEFUN (show_ipv6_ospf6_database_type_router,
613 show_ipv6_ospf6_database_type_router_cmd,
614 "show ipv6 ospf6 database <router|network|inter-prefix|inter-router|as-external|group-membership|type-7|link|intra-prefix> <*|adv-router> A.B.C.D [<detail|dump|internal>] [json]",
615 SHOW_STR
616 IPV6_STR
617 OSPF6_STR
618 "Display Link state database\n"
619 "Display Router LSAs\n"
620 "Display Network LSAs\n"
621 "Display Inter-Area-Prefix LSAs\n"
622 "Display Inter-Area-Router LSAs\n"
623 "Display As-External LSAs\n"
624 "Display Group-Membership LSAs\n"
625 "Display Type-7 LSAs\n"
626 "Display Link LSAs\n"
627 "Display Intra-Area-Prefix LSAs\n"
628 "Any Link state ID\n"
629 "Search by Advertising Router\n"
630 "Specify Advertising Router as IPv4 address notation\n"
631 "Display details of LSAs\n"
632 "Dump LSAs\n"
633 "Display LSA's internal information\n"
634 JSON_STR)
635 {
636 int idx_lsa = 4;
637 int idx_ipv4 = 6;
638 int idx_level = 7;
639 int level;
640 uint16_t type = 0;
641 uint32_t adv_router = 0;
642 bool uj = use_json(argc, argv);
643 struct ospf6 *ospf6;
644
645
646 ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME);
647 OSPF6_CMD_CHECK_RUNNING(ospf6);
648 type = parse_type_spec(idx_lsa, argc, argv);
649 inet_pton(AF_INET, argv[idx_ipv4]->arg, &adv_router);
650 level = parse_show_level(idx_level, argc, argv);
651
652 ospf6_lsdb_type_show_wrapper(vty, level, &type, NULL, &adv_router, uj,
653 ospf6);
654 return CMD_SUCCESS;
655 }
656
657
658 DEFUN (show_ipv6_ospf6_database_id_router,
659 show_ipv6_ospf6_database_id_router_cmd,
660 "show ipv6 ospf6 database * A.B.C.D A.B.C.D [<detail|dump|internal>] [json]",
661 SHOW_STR
662 IPV6_STR
663 OSPF6_STR
664 "Display Link state database\n"
665 "Any Link state Type\n"
666 "Specify Link state ID as IPv4 address notation\n"
667 "Specify Advertising Router as IPv4 address notation\n"
668 "Display details of LSAs\n"
669 "Dump LSAs\n"
670 "Display LSA's internal information\n"
671 JSON_STR)
672 {
673 int idx_ls_id = 5;
674 int idx_adv_rtr = 6;
675 int idx_level = 7;
676 int level;
677 uint32_t id = 0;
678 uint32_t adv_router = 0;
679 bool uj = use_json(argc, argv);
680 struct ospf6 *ospf6;
681
682 ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME);
683 OSPF6_CMD_CHECK_RUNNING(ospf6);
684 inet_pton(AF_INET, argv[idx_ls_id]->arg, &id);
685 inet_pton(AF_INET, argv[idx_adv_rtr]->arg, &adv_router);
686 level = parse_show_level(idx_level, argc, argv);
687
688 ospf6_lsdb_show_wrapper(vty, level, NULL, &id, &adv_router, uj, ospf6);
689 return CMD_SUCCESS;
690 }
691
692
693 DEFUN (show_ipv6_ospf6_database_adv_router_linkstate_id,
694 show_ipv6_ospf6_database_adv_router_linkstate_id_cmd,
695 "show ipv6 ospf6 database adv-router A.B.C.D linkstate-id A.B.C.D [<detail|dump|internal>] [json]",
696 SHOW_STR
697 IPV6_STR
698 OSPF6_STR
699 "Display Link state database\n"
700 "Search by Advertising Router\n"
701 "Specify Advertising Router as IPv4 address notation\n"
702 "Search by Link state ID\n"
703 "Specify Link state ID as IPv4 address notation\n"
704 "Display details of LSAs\n"
705 "Dump LSAs\n"
706 "Display LSA's internal information\n"
707 JSON_STR)
708 {
709 int idx_adv_rtr = 5;
710 int idx_ls_id = 7;
711 int idx_level = 8;
712 int level;
713 uint32_t id = 0;
714 uint32_t adv_router = 0;
715 bool uj = use_json(argc, argv);
716 struct ospf6 *ospf6;
717
718
719 ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME);
720 OSPF6_CMD_CHECK_RUNNING(ospf6);
721 inet_pton(AF_INET, argv[idx_adv_rtr]->arg, &adv_router);
722 inet_pton(AF_INET, argv[idx_ls_id]->arg, &id);
723 level = parse_show_level(idx_level, argc, argv);
724
725 ospf6_lsdb_show_wrapper(vty, level, NULL, &id, &adv_router, uj, ospf6);
726 return CMD_SUCCESS;
727 }
728
729 DEFUN (show_ipv6_ospf6_database_type_id_router,
730 show_ipv6_ospf6_database_type_id_router_cmd,
731 "show ipv6 ospf6 database <router|network|inter-prefix|inter-router|as-external|group-membership|type-7|link|intra-prefix> A.B.C.D A.B.C.D [<dump|internal>] [json]",
732 SHOW_STR
733 IPV6_STR
734 OSPF6_STR
735 "Display Link state database\n"
736 "Display Router LSAs\n"
737 "Display Network LSAs\n"
738 "Display Inter-Area-Prefix LSAs\n"
739 "Display Inter-Area-Router LSAs\n"
740 "Display As-External LSAs\n"
741 "Display Group-Membership LSAs\n"
742 "Display Type-7 LSAs\n"
743 "Display Link LSAs\n"
744 "Display Intra-Area-Prefix LSAs\n"
745 "Specify Link state ID as IPv4 address notation\n"
746 "Specify Advertising Router as IPv4 address notation\n"
747 "Dump LSAs\n"
748 "Display LSA's internal information\n"
749 JSON_STR)
750 {
751 int idx_lsa = 4;
752 int idx_ls_id = 5;
753 int idx_adv_rtr = 6;
754 int idx_level = 7;
755 int level;
756 uint16_t type = 0;
757 uint32_t id = 0;
758 uint32_t adv_router = 0;
759 bool uj = use_json(argc, argv);
760 struct ospf6 *ospf6;
761
762
763 ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME);
764 OSPF6_CMD_CHECK_RUNNING(ospf6);
765
766 type = parse_type_spec(idx_lsa, argc, argv);
767 inet_pton(AF_INET, argv[idx_ls_id]->arg, &id);
768 inet_pton(AF_INET, argv[idx_adv_rtr]->arg, &adv_router);
769 level = parse_show_level(idx_level, argc, argv);
770
771 ospf6_lsdb_type_show_wrapper(vty, level, &type, &id, &adv_router, uj,
772 ospf6);
773 return CMD_SUCCESS;
774 }
775
776
777 DEFUN (show_ipv6_ospf6_database_type_adv_router_linkstate_id,
778 show_ipv6_ospf6_database_type_adv_router_linkstate_id_cmd,
779 "show ipv6 ospf6 database <router|network|inter-prefix|inter-router|as-external|group-membership|type-7|link|intra-prefix> adv-router A.B.C.D linkstate-id A.B.C.D [<dump|internal>] [json]",
780 SHOW_STR
781 IPV6_STR
782 OSPF6_STR
783 "Display Link state database\n"
784 "Display Router LSAs\n"
785 "Display Network LSAs\n"
786 "Display Inter-Area-Prefix LSAs\n"
787 "Display Inter-Area-Router LSAs\n"
788 "Display As-External LSAs\n"
789 "Display Group-Membership LSAs\n"
790 "Display Type-7 LSAs\n"
791 "Display Link LSAs\n"
792 "Display Intra-Area-Prefix LSAs\n"
793 "Search by Advertising Router\n"
794 "Specify Advertising Router as IPv4 address notation\n"
795 "Search by Link state ID\n"
796 "Specify Link state ID as IPv4 address notation\n"
797 "Dump LSAs\n"
798 "Display LSA's internal information\n"
799 JSON_STR)
800 {
801 int idx_lsa = 4;
802 int idx_adv_rtr = 6;
803 int idx_ls_id = 8;
804 int idx_level = 9;
805 int level;
806 uint16_t type = 0;
807 uint32_t id = 0;
808 uint32_t adv_router = 0;
809 bool uj = use_json(argc, argv);
810 struct ospf6 *ospf6;
811
812
813 ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME);
814 OSPF6_CMD_CHECK_RUNNING(ospf6);
815
816 type = parse_type_spec(idx_lsa, argc, argv);
817 inet_pton(AF_INET, argv[idx_adv_rtr]->arg, &adv_router);
818 inet_pton(AF_INET, argv[idx_ls_id]->arg, &id);
819 level = parse_show_level(idx_level, argc, argv);
820
821 ospf6_lsdb_type_show_wrapper(vty, level, &type, &id, &adv_router, uj,
822 ospf6);
823 return CMD_SUCCESS;
824 }
825
826 DEFUN (show_ipv6_ospf6_database_self_originated,
827 show_ipv6_ospf6_database_self_originated_cmd,
828 "show ipv6 ospf6 database self-originated [<detail|dump|internal>] [json]",
829 SHOW_STR
830 IPV6_STR
831 OSPF6_STR
832 "Display Link state database\n"
833 "Display Self-originated LSAs\n"
834 "Display details of LSAs\n"
835 "Dump LSAs\n"
836 "Display LSA's internal information\n"
837 JSON_STR)
838 {
839 int idx_level = 5;
840 int level;
841 uint32_t adv_router = 0;
842 bool uj = use_json(argc, argv);
843 struct ospf6 *ospf6;
844
845 ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME);
846 OSPF6_CMD_CHECK_RUNNING(ospf6);
847 level = parse_show_level(idx_level, argc, argv);
848 adv_router = ospf6->router_id;
849
850 ospf6_lsdb_show_wrapper(vty, level, NULL, NULL, &adv_router, uj, ospf6);
851 return CMD_SUCCESS;
852 }
853
854
855 DEFUN (show_ipv6_ospf6_database_type_self_originated,
856 show_ipv6_ospf6_database_type_self_originated_cmd,
857 "show ipv6 ospf6 database <router|network|inter-prefix|inter-router|as-external|group-membership|type-7|link|intra-prefix> self-originated [<detail|dump|internal>] [json]",
858 SHOW_STR
859 IPV6_STR
860 OSPF6_STR
861 "Display Link state database\n"
862 "Display Router LSAs\n"
863 "Display Network LSAs\n"
864 "Display Inter-Area-Prefix LSAs\n"
865 "Display Inter-Area-Router LSAs\n"
866 "Display As-External LSAs\n"
867 "Display Group-Membership LSAs\n"
868 "Display Type-7 LSAs\n"
869 "Display Link LSAs\n"
870 "Display Intra-Area-Prefix LSAs\n"
871 "Display Self-originated LSAs\n"
872 "Display details of LSAs\n"
873 "Dump LSAs\n"
874 "Display LSA's internal information\n"
875 JSON_STR)
876 {
877 int idx_lsa = 4;
878 int idx_level = 6;
879 int level;
880 uint16_t type = 0;
881 uint32_t adv_router = 0;
882 bool uj = use_json(argc, argv);
883 struct ospf6 *ospf6;
884
885 ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME);
886 OSPF6_CMD_CHECK_RUNNING(ospf6);
887 type = parse_type_spec(idx_lsa, argc, argv);
888 level = parse_show_level(idx_level, argc, argv);
889
890 adv_router = ospf6->router_id;
891
892 ospf6_lsdb_type_show_wrapper(vty, level, &type, NULL, &adv_router, uj,
893 ospf6);
894 return CMD_SUCCESS;
895 }
896
897 DEFUN (show_ipv6_ospf6_database_type_self_originated_linkstate_id,
898 show_ipv6_ospf6_database_type_self_originated_linkstate_id_cmd,
899 "show ipv6 ospf6 database <router|network|inter-prefix|inter-router|as-external|group-membership|type-7|link|intra-prefix> self-originated linkstate-id A.B.C.D [<detail|dump|internal>] [json]",
900 SHOW_STR
901 IPV6_STR
902 OSPF6_STR
903 "Display Link state database\n"
904 "Display Router LSAs\n"
905 "Display Network LSAs\n"
906 "Display Inter-Area-Prefix LSAs\n"
907 "Display Inter-Area-Router LSAs\n"
908 "Display As-External LSAs\n"
909 "Display Group-Membership LSAs\n"
910 "Display Type-7 LSAs\n"
911 "Display Link LSAs\n"
912 "Display Intra-Area-Prefix LSAs\n"
913 "Display Self-originated LSAs\n"
914 "Search by Link state ID\n"
915 "Specify Link state ID as IPv4 address notation\n"
916 "Display details of LSAs\n"
917 "Dump LSAs\n"
918 "Display LSA's internal information\n"
919 JSON_STR)
920 {
921 int idx_lsa = 4;
922 int idx_ls_id = 7;
923 int idx_level = 8;
924 int level;
925 uint16_t type = 0;
926 uint32_t adv_router = 0;
927 uint32_t id = 0;
928 bool uj = use_json(argc, argv);
929 struct ospf6 *ospf6;
930
931 ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME);
932 OSPF6_CMD_CHECK_RUNNING(ospf6);
933 type = parse_type_spec(idx_lsa, argc, argv);
934 inet_pton(AF_INET, argv[idx_ls_id]->arg, &id);
935 level = parse_show_level(idx_level, argc, argv);
936 adv_router = ospf6->router_id;
937
938 ospf6_lsdb_type_show_wrapper(vty, level, &type, &id, &adv_router, uj,
939 ospf6);
940 return CMD_SUCCESS;
941 }
942
943 DEFUN (show_ipv6_ospf6_database_type_id_self_originated,
944 show_ipv6_ospf6_database_type_id_self_originated_cmd,
945 "show ipv6 ospf6 database <router|network|inter-prefix|inter-router|as-external|group-membership|type-7|link|intra-prefix> A.B.C.D self-originated [<detail|dump|internal>] [json]",
946 SHOW_STR
947 IPV6_STR
948 OSPF6_STR
949 "Display Link state database\n"
950 "Display Router LSAs\n"
951 "Display Network LSAs\n"
952 "Display Inter-Area-Prefix LSAs\n"
953 "Display Inter-Area-Router LSAs\n"
954 "Display As-External LSAs\n"
955 "Display Group-Membership LSAs\n"
956 "Display Type-7 LSAs\n"
957 "Display Link LSAs\n"
958 "Display Intra-Area-Prefix LSAs\n"
959 "Specify Link state ID as IPv4 address notation\n"
960 "Display Self-originated LSAs\n"
961 "Display details of LSAs\n"
962 "Dump LSAs\n"
963 "Display LSA's internal information\n"
964 JSON_STR)
965 {
966 int idx_lsa = 4;
967 int idx_ls_id = 5;
968 int idx_level = 7;
969 int level;
970 uint16_t type = 0;
971 uint32_t adv_router = 0;
972 uint32_t id = 0;
973 bool uj = use_json(argc, argv);
974 struct ospf6 *ospf6;
975
976 ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME);
977 OSPF6_CMD_CHECK_RUNNING(ospf6);
978 type = parse_type_spec(idx_lsa, argc, argv);
979 inet_pton(AF_INET, argv[idx_ls_id]->arg, &id);
980 level = parse_show_level(idx_level, argc, argv);
981 adv_router = ospf6->router_id;
982
983 ospf6_lsdb_type_show_wrapper(vty, level, &type, &id, &adv_router, uj,
984 ospf6);
985 return CMD_SUCCESS;
986 }
987
988 DEFUN (show_ipv6_ospf6_border_routers,
989 show_ipv6_ospf6_border_routers_cmd,
990 "show ipv6 ospf6 border-routers [<A.B.C.D|detail>]",
991 SHOW_STR
992 IP6_STR
993 OSPF6_STR
994 "Display routing table for ABR and ASBR\n"
995 "Router ID\n"
996 "Show detailed output\n")
997 {
998 int idx_ipv4 = 4;
999 uint32_t adv_router;
1000 struct ospf6_route *ro;
1001 struct prefix prefix;
1002 struct ospf6 *ospf6 = NULL;
1003
1004
1005 ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME);
1006 OSPF6_CMD_CHECK_RUNNING(ospf6);
1007 if (argc == 5) {
1008 if (strmatch(argv[idx_ipv4]->text, "detail")) {
1009 for (ro = ospf6_route_head(ospf6->brouter_table); ro;
1010 ro = ospf6_route_next(ro))
1011 ospf6_route_show_detail(vty, ro, NULL, false);
1012 } else {
1013 inet_pton(AF_INET, argv[idx_ipv4]->arg, &adv_router);
1014
1015 ospf6_linkstate_prefix(adv_router, 0, &prefix);
1016 ro = ospf6_route_lookup(&prefix, ospf6->brouter_table);
1017 if (!ro) {
1018 vty_out(vty,
1019 "No Route found for Router ID: %s\n",
1020 argv[4]->arg);
1021 return CMD_SUCCESS;
1022 }
1023
1024 ospf6_route_show_detail(vty, ro, NULL, false);
1025 return CMD_SUCCESS;
1026 }
1027 } else {
1028 ospf6_brouter_show_header(vty);
1029
1030 for (ro = ospf6_route_head(ospf6->brouter_table); ro;
1031 ro = ospf6_route_next(ro))
1032 ospf6_brouter_show(vty, ro);
1033 }
1034
1035 return CMD_SUCCESS;
1036 }
1037
1038
1039 DEFUN (show_ipv6_ospf6_linkstate,
1040 show_ipv6_ospf6_linkstate_cmd,
1041 "show ipv6 ospf6 linkstate <router A.B.C.D|network A.B.C.D A.B.C.D>",
1042 SHOW_STR
1043 IP6_STR
1044 OSPF6_STR
1045 "Display linkstate routing table\n"
1046 "Display Router Entry\n"
1047 "Specify Router ID as IPv4 address notation\n"
1048 "Display Network Entry\n"
1049 "Specify Router ID as IPv4 address notation\n"
1050 "Specify Link state ID as IPv4 address notation\n")
1051 {
1052 int idx_ipv4 = 5;
1053 struct listnode *node;
1054 struct ospf6_area *oa;
1055 struct ospf6 *ospf6 = NULL;
1056
1057 ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME);
1058 OSPF6_CMD_CHECK_RUNNING(ospf6);
1059 for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, node, oa)) {
1060 vty_out(vty, "\n SPF Result in Area %s\n\n", oa->name);
1061 ospf6_linkstate_table_show(vty, idx_ipv4, argc, argv,
1062 oa->spf_table);
1063 }
1064
1065 vty_out(vty, "\n");
1066 return CMD_SUCCESS;
1067 }
1068
1069
1070 DEFUN (show_ipv6_ospf6_linkstate_detail,
1071 show_ipv6_ospf6_linkstate_detail_cmd,
1072 "show ipv6 ospf6 linkstate detail",
1073 SHOW_STR
1074 IP6_STR
1075 OSPF6_STR
1076 "Display linkstate routing table\n"
1077 "Display detailed information\n")
1078 {
1079 int idx_detail = 4;
1080 struct listnode *node;
1081 struct ospf6_area *oa;
1082 struct ospf6 *ospf6 = NULL;
1083
1084 ospf6 = ospf6_lookup_by_vrf_name(VRF_DEFAULT_NAME);
1085 OSPF6_CMD_CHECK_RUNNING(ospf6);
1086
1087 for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, node, oa)) {
1088 vty_out(vty, "\n SPF Result in Area %s\n\n", oa->name);
1089 ospf6_linkstate_table_show(vty, idx_detail, argc, argv,
1090 oa->spf_table);
1091 }
1092
1093 vty_out(vty, "\n");
1094 return CMD_SUCCESS;
1095 }
1096
1097 static void ospf6_plist_add(struct prefix_list *plist)
1098 {
1099 if (prefix_list_afi(plist) != AFI_IP6)
1100 return;
1101 ospf6_area_plist_update(plist, 1);
1102 }
1103
1104 static void ospf6_plist_del(struct prefix_list *plist)
1105 {
1106 if (prefix_list_afi(plist) != AFI_IP6)
1107 return;
1108 ospf6_area_plist_update(plist, 0);
1109 }
1110
1111 /* Install ospf related commands. */
1112 void ospf6_init(struct thread_master *master)
1113 {
1114 ospf6_top_init();
1115 ospf6_area_init();
1116 ospf6_interface_init();
1117 ospf6_neighbor_init();
1118 ospf6_zebra_init(master);
1119
1120 ospf6_lsa_init();
1121 ospf6_spf_init();
1122 ospf6_intra_init();
1123 ospf6_asbr_init();
1124 ospf6_abr_init();
1125
1126 prefix_list_add_hook(ospf6_plist_add);
1127 prefix_list_delete_hook(ospf6_plist_del);
1128
1129 ospf6_bfd_init();
1130 install_node(&debug_node);
1131
1132 install_element_ospf6_debug_message();
1133 install_element_ospf6_debug_lsa();
1134 install_element_ospf6_debug_interface();
1135 install_element_ospf6_debug_neighbor();
1136 install_element_ospf6_debug_zebra();
1137 install_element_ospf6_debug_spf();
1138 install_element_ospf6_debug_route();
1139 install_element_ospf6_debug_brouter();
1140 install_element_ospf6_debug_asbr();
1141 install_element_ospf6_debug_abr();
1142 install_element_ospf6_debug_flood();
1143
1144 install_element_ospf6_clear_interface();
1145
1146 install_element(ENABLE_NODE, &show_debugging_ospf6_cmd);
1147
1148 install_element(VIEW_NODE, &show_ipv6_ospf6_border_routers_cmd);
1149
1150 install_element(VIEW_NODE, &show_ipv6_ospf6_linkstate_cmd);
1151 install_element(VIEW_NODE, &show_ipv6_ospf6_linkstate_detail_cmd);
1152
1153 install_element(VIEW_NODE, &show_ipv6_ospf6_database_cmd);
1154 install_element(VIEW_NODE, &show_ipv6_ospf6_database_type_cmd);
1155 install_element(VIEW_NODE, &show_ipv6_ospf6_database_id_cmd);
1156 install_element(VIEW_NODE, &show_ipv6_ospf6_database_router_cmd);
1157 install_element(VIEW_NODE, &show_ipv6_ospf6_database_type_id_cmd);
1158 install_element(VIEW_NODE, &show_ipv6_ospf6_database_type_router_cmd);
1159 install_element(VIEW_NODE,
1160 &show_ipv6_ospf6_database_adv_router_linkstate_id_cmd);
1161 install_element(VIEW_NODE, &show_ipv6_ospf6_database_id_router_cmd);
1162 install_element(VIEW_NODE,
1163 &show_ipv6_ospf6_database_type_id_router_cmd);
1164 install_element(
1165 VIEW_NODE,
1166 &show_ipv6_ospf6_database_type_adv_router_linkstate_id_cmd);
1167 install_element(VIEW_NODE,
1168 &show_ipv6_ospf6_database_self_originated_cmd);
1169 install_element(VIEW_NODE,
1170 &show_ipv6_ospf6_database_type_self_originated_cmd);
1171 install_element(VIEW_NODE,
1172 &show_ipv6_ospf6_database_type_id_self_originated_cmd);
1173 install_element(
1174 VIEW_NODE,
1175 &show_ipv6_ospf6_database_type_self_originated_linkstate_id_cmd);
1176 install_element(VIEW_NODE, &show_ipv6_ospf6_database_aggr_router_cmd);
1177 }