]> git.proxmox.com Git - mirror_frr.git/blob - ospfd/ospf_vty.c
ospfd: OSPF P2MP Delayed Reflooding configuration
[mirror_frr.git] / ospfd / ospf_vty.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* OSPF VTY interface.
3 * Copyright (C) 2005 6WIND <alain.ritoux@6wind.com>
4 * Copyright (C) 2000 Toshiaki Takada
5 */
6
7 #include <zebra.h>
8 #include <string.h>
9
10 #include "printfrr.h"
11 #include "monotime.h"
12 #include "memory.h"
13 #include "frrevent.h"
14 #include "prefix.h"
15 #include "table.h"
16 #include "vty.h"
17 #include "command.h"
18 #include "plist.h"
19 #include "log.h"
20 #include "zclient.h"
21 #include <lib/json.h>
22 #include "defaults.h"
23 #include "lib/printfrr.h"
24
25 #include "ospfd/ospfd.h"
26 #include "ospfd/ospf_asbr.h"
27 #include "ospfd/ospf_lsa.h"
28 #include "ospfd/ospf_lsdb.h"
29 #include "ospfd/ospf_ism.h"
30 #include "ospfd/ospf_interface.h"
31 #include "ospfd/ospf_nsm.h"
32 #include "ospfd/ospf_neighbor.h"
33 #include "ospfd/ospf_flood.h"
34 #include "ospfd/ospf_abr.h"
35 #include "ospfd/ospf_spf.h"
36 #include "ospfd/ospf_route.h"
37 #include "ospfd/ospf_zebra.h"
38 #include "ospfd/ospf_vty.h"
39 #include "ospfd/ospf_dump.h"
40 #include "ospfd/ospf_bfd.h"
41 #include "ospfd/ospf_ldp_sync.h"
42 #include "ospfd/ospf_network.h"
43
44 FRR_CFG_DEFAULT_BOOL(OSPF_LOG_ADJACENCY_CHANGES,
45 { .val_bool = true, .match_profile = "datacenter", },
46 { .val_bool = false },
47 );
48
49 static const char *const ospf_network_type_str[] = {
50 "Null", "POINTOPOINT", "BROADCAST", "NBMA", "POINTOMULTIPOINT",
51 "VIRTUALLINK", "LOOPBACK"};
52
53 /* Utility functions. */
54 int str2area_id(const char *str, struct in_addr *area_id, int *area_id_fmt)
55 {
56 char *ep;
57
58 area_id->s_addr = htonl(strtoul(str, &ep, 10));
59 if (*ep && !inet_aton(str, area_id))
60 return -1;
61
62 *area_id_fmt =
63 *ep ? OSPF_AREA_ID_FMT_DOTTEDQUAD : OSPF_AREA_ID_FMT_DECIMAL;
64
65 return 0;
66 }
67
68 static void area_id2str(char *buf, int length, struct in_addr *area_id,
69 int area_id_fmt)
70 {
71 if (area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD)
72 inet_ntop(AF_INET, area_id, buf, length);
73 else
74 snprintf(buf, length, "%lu",
75 (unsigned long)ntohl(area_id->s_addr));
76 }
77
78 static int str2metric(const char *str, int *metric)
79 {
80 /* Sanity check. */
81 if (str == NULL)
82 return 0;
83
84 *metric = strtol(str, NULL, 10);
85 if (*metric < 0 || *metric > 16777214) {
86 /* vty_out (vty, "OSPF metric value is invalid\n"); */
87 return 0;
88 }
89
90 return 1;
91 }
92
93 static int str2metric_type(const char *str, int *metric_type)
94 {
95 /* Sanity check. */
96 if (str == NULL)
97 return 0;
98
99 if (strncmp(str, "1", 1) == 0)
100 *metric_type = EXTERNAL_METRIC_TYPE_1;
101 else if (strncmp(str, "2", 1) == 0)
102 *metric_type = EXTERNAL_METRIC_TYPE_2;
103 else
104 return 0;
105
106 return 1;
107 }
108
109 int ospf_oi_count(struct interface *ifp)
110 {
111 struct route_node *rn;
112 int i = 0;
113
114 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn))
115 if (rn->info)
116 i++;
117
118 return i;
119 }
120
121 #define OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf) \
122 if (argv_find(argv, argc, "vrf", &idx_vrf)) { \
123 vrf_name = argv[idx_vrf + 1]->arg; \
124 all_vrf = strmatch(vrf_name, "all"); \
125 }
126
127 static int ospf_router_cmd_parse(struct vty *vty, struct cmd_token *argv[],
128 const int argc, unsigned short *instance,
129 const char **vrf_name)
130 {
131 int idx_vrf = 0, idx_inst = 0;
132
133 *instance = 0;
134 if (argv_find(argv, argc, "(1-65535)", &idx_inst)) {
135 if (ospf_instance == 0) {
136 vty_out(vty,
137 "%% OSPF is not running in instance mode\n");
138 return CMD_WARNING_CONFIG_FAILED;
139 }
140
141 *instance = strtoul(argv[idx_inst]->arg, NULL, 10);
142 }
143
144 *vrf_name = VRF_DEFAULT_NAME;
145 if (argv_find(argv, argc, "vrf", &idx_vrf)) {
146 if (ospf_instance != 0) {
147 vty_out(vty,
148 "%% VRF is not supported in instance mode\n");
149 return CMD_WARNING_CONFIG_FAILED;
150 }
151
152 *vrf_name = argv[idx_vrf + 1]->arg;
153 }
154
155 return CMD_SUCCESS;
156 }
157
158 static void ospf_show_vrf_name(struct ospf *ospf, struct vty *vty,
159 json_object *json, uint8_t use_vrf)
160 {
161 if (use_vrf) {
162 if (json) {
163 json_object_string_add(json, "vrfName",
164 ospf_get_name(ospf));
165 json_object_int_add(json, "vrfId", ospf->vrf_id);
166 } else
167 vty_out(vty, "VRF Name: %s\n", ospf_get_name(ospf));
168 }
169 }
170
171 #include "ospfd/ospf_vty_clippy.c"
172
173 DEFUN_NOSH (router_ospf,
174 router_ospf_cmd,
175 "router ospf [{(1-65535)|vrf NAME}]",
176 "Enable a routing process\n"
177 "Start OSPF configuration\n"
178 "Instance ID\n"
179 VRF_CMD_HELP_STR)
180 {
181 unsigned short instance;
182 const char *vrf_name;
183 bool created = false;
184 struct ospf *ospf;
185 int ret;
186
187 ret = ospf_router_cmd_parse(vty, argv, argc, &instance, &vrf_name);
188 if (ret != CMD_SUCCESS)
189 return ret;
190
191 if (instance != ospf_instance) {
192 VTY_PUSH_CONTEXT_NULL(OSPF_NODE);
193 return CMD_NOT_MY_INSTANCE;
194 }
195
196 ospf = ospf_get(instance, vrf_name, &created);
197
198 if (created)
199 if (DFLT_OSPF_LOG_ADJACENCY_CHANGES)
200 SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES);
201
202 if (IS_DEBUG_OSPF_EVENT)
203 zlog_debug(
204 "Config command 'router ospf %d' received, vrf %s id %u oi_running %u",
205 ospf->instance, ospf_get_name(ospf), ospf->vrf_id,
206 ospf->oi_running);
207
208 VTY_PUSH_CONTEXT(OSPF_NODE, ospf);
209
210 return ret;
211 }
212
213 DEFUN (no_router_ospf,
214 no_router_ospf_cmd,
215 "no router ospf [{(1-65535)|vrf NAME}]",
216 NO_STR
217 "Enable a routing process\n"
218 "Start OSPF configuration\n"
219 "Instance ID\n"
220 VRF_CMD_HELP_STR)
221 {
222 unsigned short instance;
223 const char *vrf_name;
224 struct ospf *ospf;
225 int ret;
226
227 ret = ospf_router_cmd_parse(vty, argv, argc, &instance, &vrf_name);
228 if (ret != CMD_SUCCESS)
229 return ret;
230
231 if (instance != ospf_instance)
232 return CMD_NOT_MY_INSTANCE;
233
234 ospf = ospf_lookup(instance, vrf_name);
235 if (ospf) {
236 if (ospf->gr_info.restart_support)
237 ospf_gr_nvm_delete(ospf);
238
239 ospf_finish(ospf);
240 } else
241 ret = CMD_WARNING_CONFIG_FAILED;
242
243 return ret;
244 }
245
246
247 DEFPY (ospf_router_id,
248 ospf_router_id_cmd,
249 "ospf router-id A.B.C.D",
250 "OSPF specific commands\n"
251 "router-id for the OSPF process\n"
252 "OSPF router-id in IP address format\n")
253 {
254 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
255
256 struct listnode *node;
257 struct ospf_area *area;
258
259 ospf->router_id_static = router_id;
260
261 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area))
262 if (area->full_nbrs) {
263 vty_out(vty,
264 "For this router-id change to take effect, use \"clear ip ospf process\" command\n");
265 return CMD_SUCCESS;
266 }
267
268 ospf_router_id_update(ospf);
269
270 return CMD_SUCCESS;
271 }
272
273 DEFUN_HIDDEN (ospf_router_id_old,
274 ospf_router_id_old_cmd,
275 "router-id A.B.C.D",
276 "router-id for the OSPF process\n"
277 "OSPF router-id in IP address format\n")
278 {
279 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
280 int idx_ipv4 = 1;
281 struct listnode *node;
282 struct ospf_area *area;
283 struct in_addr router_id;
284 int ret;
285
286 ret = inet_aton(argv[idx_ipv4]->arg, &router_id);
287 if (!ret) {
288 vty_out(vty, "Please specify Router ID by A.B.C.D\n");
289 return CMD_WARNING_CONFIG_FAILED;
290 }
291
292 ospf->router_id_static = router_id;
293
294 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area))
295 if (area->full_nbrs) {
296 vty_out(vty,
297 "For this router-id change to take effect, use \"clear ip ospf process\" command\n");
298 return CMD_SUCCESS;
299 }
300
301 ospf_router_id_update(ospf);
302
303 return CMD_SUCCESS;
304 }
305
306 DEFPY (no_ospf_router_id,
307 no_ospf_router_id_cmd,
308 "no ospf router-id [A.B.C.D]",
309 NO_STR
310 "OSPF specific commands\n"
311 "router-id for the OSPF process\n"
312 "OSPF router-id in IP address format\n")
313 {
314 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
315 struct listnode *node;
316 struct ospf_area *area;
317
318 if (router_id_str) {
319 if (!IPV4_ADDR_SAME(&ospf->router_id_static, &router_id)) {
320 vty_out(vty, "%% OSPF router-id doesn't match\n");
321 return CMD_WARNING_CONFIG_FAILED;
322 }
323 }
324
325 ospf->router_id_static.s_addr = 0;
326
327 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area))
328 if (area->full_nbrs) {
329 vty_out(vty,
330 "For this router-id change to take effect, use \"clear ip ospf process\" command\n");
331 return CMD_SUCCESS;
332 }
333
334 ospf_router_id_update(ospf);
335
336 return CMD_SUCCESS;
337 }
338
339
340 static void ospf_passive_interface_default_update(struct ospf *ospf,
341 uint8_t newval)
342 {
343 struct listnode *ln;
344 struct ospf_interface *oi;
345
346 ospf->passive_interface_default = newval;
347
348 /* update multicast memberships */
349 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, ln, oi))
350 ospf_if_set_multicast(oi);
351 }
352
353 static void ospf_passive_interface_update(struct interface *ifp,
354 struct ospf_if_params *params,
355 struct in_addr addr, uint8_t newval)
356 {
357 struct route_node *rn;
358
359 if (OSPF_IF_PARAM_CONFIGURED(params, passive_interface)) {
360 if (params->passive_interface == newval)
361 return;
362
363 params->passive_interface = newval;
364 UNSET_IF_PARAM(params, passive_interface);
365 if (params != IF_DEF_PARAMS(ifp)) {
366 ospf_free_if_params(ifp, addr);
367 ospf_if_update_params(ifp, addr);
368 }
369 } else {
370 params->passive_interface = newval;
371 SET_IF_PARAM(params, passive_interface);
372 }
373
374 /*
375 * XXX We should call ospf_if_set_multicast on exactly those
376 * interfaces for which the passive property changed. It is too much
377 * work to determine this set, so we do this for every interface.
378 * This is safe and reasonable because ospf_if_set_multicast uses a
379 * record of joined groups to avoid systems calls if the desired
380 * memberships match the current memership.
381 */
382
383 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
384 struct ospf_interface *oi = rn->info;
385
386 if (oi)
387 ospf_if_set_multicast(oi);
388 }
389
390 /*
391 * XXX It is not clear what state transitions the interface needs to
392 * undergo when going from active to passive and vice versa. Fixing
393 * this will require precise identification of interfaces having such a
394 * transition.
395 */
396 }
397
398 DEFUN (ospf_passive_interface_default,
399 ospf_passive_interface_default_cmd,
400 "passive-interface default",
401 "Suppress routing updates on an interface\n"
402 "Suppress routing updates on interfaces by default\n")
403 {
404 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
405
406 ospf_passive_interface_default_update(ospf, OSPF_IF_PASSIVE);
407
408 return CMD_SUCCESS;
409 }
410
411 DEFUN_HIDDEN (ospf_passive_interface_addr,
412 ospf_passive_interface_addr_cmd,
413 "passive-interface IFNAME [A.B.C.D]",
414 "Suppress routing updates on an interface\n"
415 "Interface's name\n"
416 "IPv4 address\n")
417 {
418 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
419 int idx_ipv4 = 2;
420 struct interface *ifp = NULL;
421 struct in_addr addr = {.s_addr = INADDR_ANY};
422 struct ospf_if_params *params;
423 int ret;
424
425 vty_out(vty,
426 "This command is deprecated, because it is not VRF-aware.\n");
427 vty_out(vty,
428 "Please, use \"ip ospf passive\" on an interface instead.\n");
429
430 if (ospf->vrf_id != VRF_UNKNOWN)
431 ifp = if_get_by_name(argv[1]->arg, ospf->vrf_id, ospf->name);
432
433 if (ifp == NULL) {
434 vty_out(vty, "interface %s not found.\n", (char *)argv[1]->arg);
435 return CMD_WARNING_CONFIG_FAILED;
436 }
437
438 if (argc == 3) {
439 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
440 if (!ret) {
441 vty_out(vty,
442 "Please specify interface address by A.B.C.D\n");
443 return CMD_WARNING_CONFIG_FAILED;
444 }
445
446 params = ospf_get_if_params(ifp, addr);
447 ospf_if_update_params(ifp, addr);
448 } else {
449 params = IF_DEF_PARAMS(ifp);
450 }
451
452 ospf_passive_interface_update(ifp, params, addr, OSPF_IF_PASSIVE);
453
454 return CMD_SUCCESS;
455 }
456
457 DEFUN (no_ospf_passive_interface_default,
458 no_ospf_passive_interface_default_cmd,
459 "no passive-interface default",
460 NO_STR
461 "Allow routing updates on an interface\n"
462 "Allow routing updates on interfaces by default\n")
463 {
464 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
465
466 ospf_passive_interface_default_update(ospf, OSPF_IF_ACTIVE);
467
468 return CMD_SUCCESS;
469 }
470
471 DEFUN_HIDDEN (no_ospf_passive_interface,
472 no_ospf_passive_interface_addr_cmd,
473 "no passive-interface IFNAME [A.B.C.D]",
474 NO_STR
475 "Allow routing updates on an interface\n"
476 "Interface's name\n"
477 "IPv4 address\n")
478 {
479 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
480 int idx_ipv4 = 3;
481 struct interface *ifp = NULL;
482 struct in_addr addr = {.s_addr = INADDR_ANY};
483 struct ospf_if_params *params;
484 int ret;
485
486 vty_out(vty,
487 "This command is deprecated, because it is not VRF-aware.\n");
488 vty_out(vty,
489 "Please, use \"no ip ospf passive\" on an interface instead.\n");
490
491 if (ospf->vrf_id != VRF_UNKNOWN)
492 ifp = if_get_by_name(argv[2]->arg, ospf->vrf_id, ospf->name);
493
494 if (ifp == NULL) {
495 vty_out(vty, "interface %s not found.\n", (char *)argv[2]->arg);
496 return CMD_WARNING_CONFIG_FAILED;
497 }
498
499 if (argc == 4) {
500 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
501 if (!ret) {
502 vty_out(vty,
503 "Please specify interface address by A.B.C.D\n");
504 return CMD_WARNING_CONFIG_FAILED;
505 }
506 params = ospf_lookup_if_params(ifp, addr);
507 if (params == NULL)
508 return CMD_SUCCESS;
509 } else {
510 params = IF_DEF_PARAMS(ifp);
511 }
512
513 ospf_passive_interface_update(ifp, params, addr, OSPF_IF_ACTIVE);
514
515 return CMD_SUCCESS;
516 }
517
518
519 DEFUN (ospf_network_area,
520 ospf_network_area_cmd,
521 "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
522 "Enable routing on an IP network\n"
523 "OSPF network prefix\n"
524 "Set the OSPF area ID\n"
525 "OSPF area ID in IP address format\n"
526 "OSPF area ID as a decimal value\n")
527 {
528 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
529 int idx_ipv4_prefixlen = 1;
530 int idx_ipv4_number = 3;
531 struct prefix_ipv4 p;
532 struct in_addr area_id;
533 int ret, format;
534 uint32_t count;
535
536 if (ospf->instance) {
537 vty_out(vty,
538 "The network command is not supported in multi-instance ospf\n");
539 return CMD_WARNING_CONFIG_FAILED;
540 }
541
542 count = ospf_count_area_params(ospf);
543 if (count > 0) {
544 vty_out(vty,
545 "Please remove all ip ospf area x.x.x.x commands first.\n");
546 if (IS_DEBUG_OSPF_EVENT)
547 zlog_debug(
548 "%s ospf vrf %s num of %u ip ospf area x config",
549 __func__, ospf_get_name(ospf), count);
550 return CMD_WARNING_CONFIG_FAILED;
551 }
552
553 /* Get network prefix and Area ID. */
554 str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
555 VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
556
557 ret = ospf_network_set(ospf, &p, area_id, format);
558 if (ret == 0) {
559 vty_out(vty, "There is already same network statement.\n");
560 return CMD_WARNING_CONFIG_FAILED;
561 }
562
563 return CMD_SUCCESS;
564 }
565
566 DEFUN (no_ospf_network_area,
567 no_ospf_network_area_cmd,
568 "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
569 NO_STR
570 "Enable routing on an IP network\n"
571 "OSPF network prefix\n"
572 "Set the OSPF area ID\n"
573 "OSPF area ID in IP address format\n"
574 "OSPF area ID as a decimal value\n")
575 {
576 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
577 int idx_ipv4_prefixlen = 2;
578 int idx_ipv4_number = 4;
579 struct prefix_ipv4 p;
580 struct in_addr area_id;
581 int ret, format;
582
583 if (ospf->instance) {
584 vty_out(vty,
585 "The network command is not supported in multi-instance ospf\n");
586 return CMD_WARNING_CONFIG_FAILED;
587 }
588
589 /* Get network prefix and Area ID. */
590 str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
591 VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
592
593 ret = ospf_network_unset(ospf, &p, area_id);
594 if (ret == 0) {
595 vty_out(vty,
596 "Can't find specified network area configuration.\n");
597 return CMD_WARNING_CONFIG_FAILED;
598 }
599
600 return CMD_SUCCESS;
601 }
602
603 DEFUN (ospf_area_range,
604 ospf_area_range_cmd,
605 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]",
606 "OSPF area parameters\n"
607 "OSPF area ID in IP address format\n"
608 "OSPF area ID as a decimal value\n"
609 "Summarize routes matching address/mask (border routers only)\n"
610 "Area range prefix\n"
611 "Advertise this range (default)\n"
612 "User specified metric for this range\n"
613 "Advertised metric for this range\n")
614 {
615 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
616 struct ospf_area *area;
617 int idx_ipv4_number = 1;
618 int idx_ipv4_prefixlen = 3;
619 int idx_cost = 6;
620 struct prefix_ipv4 p;
621 struct in_addr area_id;
622 int format;
623 uint32_t cost;
624
625 VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
626 str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
627
628 area = ospf_area_get(ospf, area_id);
629 ospf_area_display_format_set(ospf, area, format);
630
631 ospf_area_range_set(ospf, area, area->ranges, &p,
632 OSPF_AREA_RANGE_ADVERTISE, false);
633 if (argc > 5) {
634 cost = strtoul(argv[idx_cost]->arg, NULL, 10);
635 ospf_area_range_cost_set(ospf, area, area->ranges, &p, cost);
636 }
637
638 return CMD_SUCCESS;
639 }
640
641 DEFUN (ospf_area_range_cost,
642 ospf_area_range_cost_cmd,
643 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M {cost (0-16777215)|substitute A.B.C.D/M}",
644 "OSPF area parameters\n"
645 "OSPF area ID in IP address format\n"
646 "OSPF area ID as a decimal value\n"
647 "Summarize routes matching address/mask (border routers only)\n"
648 "Area range prefix\n"
649 "User specified metric for this range\n"
650 "Advertised metric for this range\n"
651 "Announce area range as another prefix\n"
652 "Network prefix to be announced instead of range\n")
653 {
654 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
655 struct ospf_area *area;
656 int idx_ipv4_number = 1;
657 int idx_ipv4_prefixlen = 3;
658 int idx = 4;
659 struct prefix_ipv4 p, s;
660 struct in_addr area_id;
661 int format;
662 uint32_t cost;
663
664 VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
665 str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
666
667 area = ospf_area_get(ospf, area_id);
668 ospf_area_display_format_set(ospf, area, format);
669
670 ospf_area_range_set(ospf, area, area->ranges, &p,
671 OSPF_AREA_RANGE_ADVERTISE, false);
672 if (argv_find(argv, argc, "cost", &idx)) {
673 cost = strtoul(argv[idx + 1]->arg, NULL, 10);
674 ospf_area_range_cost_set(ospf, area, area->ranges, &p, cost);
675 }
676
677 idx = 4;
678 if (argv_find(argv, argc, "substitute", &idx)) {
679 str2prefix_ipv4(argv[idx + 1]->arg, &s);
680 ospf_area_range_substitute_set(ospf, area, &p, &s);
681 }
682
683 return CMD_SUCCESS;
684 }
685
686 DEFUN (ospf_area_range_not_advertise,
687 ospf_area_range_not_advertise_cmd,
688 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise",
689 "OSPF area parameters\n"
690 "OSPF area ID in IP address format\n"
691 "OSPF area ID as a decimal value\n"
692 "Summarize routes matching address/mask (border routers only)\n"
693 "Area range prefix\n"
694 "DoNotAdvertise this range\n")
695 {
696 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
697 struct ospf_area *area;
698 int idx_ipv4_number = 1;
699 int idx_ipv4_prefixlen = 3;
700 struct prefix_ipv4 p;
701 struct in_addr area_id;
702 int format;
703
704 VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
705 str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
706
707 area = ospf_area_get(ospf, area_id);
708 ospf_area_display_format_set(ospf, area, format);
709
710 ospf_area_range_set(ospf, area, area->ranges, &p, 0, false);
711 ospf_area_range_substitute_unset(ospf, area, &p);
712
713 return CMD_SUCCESS;
714 }
715
716 DEFUN (no_ospf_area_range,
717 no_ospf_area_range_cmd,
718 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]",
719 NO_STR
720 "OSPF area parameters\n"
721 "OSPF area ID in IP address format\n"
722 "OSPF area ID as a decimal value\n"
723 "Summarize routes matching address/mask (border routers only)\n"
724 "Area range prefix\n"
725 "User specified metric for this range\n"
726 "Advertised metric for this range\n"
727 "Advertise this range (default)\n"
728 "User specified metric for this range\n"
729 "Advertised metric for this range\n"
730 "DoNotAdvertise this range\n")
731 {
732 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
733 struct ospf_area *area;
734 int idx_ipv4_number = 2;
735 int idx_ipv4_prefixlen = 4;
736 struct prefix_ipv4 p;
737 struct in_addr area_id;
738 int format;
739
740 VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
741 str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
742
743 area = ospf_area_get(ospf, area_id);
744 ospf_area_display_format_set(ospf, area, format);
745
746 ospf_area_range_unset(ospf, area, area->ranges, &p);
747
748 return CMD_SUCCESS;
749 }
750
751 DEFUN (no_ospf_area_range_substitute,
752 no_ospf_area_range_substitute_cmd,
753 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
754 NO_STR
755 "OSPF area parameters\n"
756 "OSPF area ID in IP address format\n"
757 "OSPF area ID as a decimal value\n"
758 "Summarize routes matching address/mask (border routers only)\n"
759 "Area range prefix\n"
760 "Announce area range as another prefix\n"
761 "Network prefix to be announced instead of range\n")
762 {
763 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
764 struct ospf_area *area;
765 int idx_ipv4_number = 2;
766 int idx_ipv4_prefixlen = 4;
767 int idx_ipv4_prefixlen_2 = 6;
768 struct prefix_ipv4 p, s;
769 struct in_addr area_id;
770 int format;
771
772 VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
773 str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
774 str2prefix_ipv4(argv[idx_ipv4_prefixlen_2]->arg, &s);
775
776 area = ospf_area_get(ospf, area_id);
777 ospf_area_display_format_set(ospf, area, format);
778
779 ospf_area_range_substitute_unset(ospf, area, &p);
780
781 return CMD_SUCCESS;
782 }
783
784
785 /* Command Handler Logic in VLink stuff is delicate!!
786
787 ALTER AT YOUR OWN RISK!!!!
788
789 Various dummy values are used to represent 'NoChange' state for
790 VLink configuration NOT being changed by a VLink command, and
791 special syntax is used within the command strings so that the
792 typed in command verbs can be seen in the configuration command
793 bacckend handler. This is to drastically reduce the verbeage
794 required to coe up with a reasonably compatible Cisco VLink command
795
796 - Matthew Grant <grantma@anathoth.gen.nz>
797 Wed, 21 Feb 2001 15:13:52 +1300
798 */
799
800 /* Configuration data for virtual links
801 */
802 struct ospf_vl_config_data {
803 struct vty *vty; /* vty stuff */
804 struct in_addr area_id; /* area ID from command line */
805 int area_id_fmt; /* command line area ID format */
806 struct in_addr vl_peer; /* command line vl_peer */
807 int auth_type; /* Authehntication type, if given */
808 char *auth_key; /* simple password if present */
809 int crypto_key_id; /* Cryptographic key ID */
810 char *md5_key; /* MD5 authentication key */
811 int hello_interval; /* Obvious what these are... */
812 int retransmit_interval;
813 int transmit_delay;
814 int dead_interval;
815 };
816
817 static void ospf_vl_config_data_init(struct ospf_vl_config_data *vl_config,
818 struct vty *vty)
819 {
820 memset(vl_config, 0, sizeof(struct ospf_vl_config_data));
821 vl_config->auth_type = OSPF_AUTH_CMD_NOTSEEN;
822 vl_config->vty = vty;
823 }
824
825 static struct ospf_vl_data *
826 ospf_find_vl_data(struct ospf *ospf, struct ospf_vl_config_data *vl_config)
827 {
828 struct ospf_area *area;
829 struct ospf_vl_data *vl_data;
830 struct vty *vty;
831 struct in_addr area_id;
832
833 vty = vl_config->vty;
834 area_id = vl_config->area_id;
835
836 if (area_id.s_addr == OSPF_AREA_BACKBONE) {
837 vty_out(vty,
838 "Configuring VLs over the backbone is not allowed\n");
839 return NULL;
840 }
841 area = ospf_area_get(ospf, area_id);
842 ospf_area_display_format_set(ospf, area, vl_config->area_id_fmt);
843
844 if (area->external_routing != OSPF_AREA_DEFAULT) {
845 if (vl_config->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD)
846 vty_out(vty, "Area %pI4 is %s\n", &area_id,
847 area->external_routing == OSPF_AREA_NSSA
848 ? "nssa"
849 : "stub");
850 else
851 vty_out(vty, "Area %ld is %s\n",
852 (unsigned long)ntohl(area_id.s_addr),
853 area->external_routing == OSPF_AREA_NSSA
854 ? "nssa"
855 : "stub");
856 return NULL;
857 }
858
859 if ((vl_data = ospf_vl_lookup(ospf, area, vl_config->vl_peer))
860 == NULL) {
861 vl_data = ospf_vl_data_new(area, vl_config->vl_peer);
862 if (vl_data->vl_oi == NULL) {
863 vl_data->vl_oi = ospf_vl_new(ospf, vl_data);
864 ospf_vl_add(ospf, vl_data);
865 ospf_spf_calculate_schedule(ospf,
866 SPF_FLAG_CONFIG_CHANGE);
867 }
868 }
869 return vl_data;
870 }
871
872
873 static int ospf_vl_set_security(struct ospf_vl_data *vl_data,
874 struct ospf_vl_config_data *vl_config)
875 {
876 struct crypt_key *ck;
877 struct vty *vty;
878 struct interface *ifp = vl_data->vl_oi->ifp;
879
880 vty = vl_config->vty;
881
882 if (vl_config->auth_type != OSPF_AUTH_CMD_NOTSEEN) {
883 SET_IF_PARAM(IF_DEF_PARAMS(ifp), auth_type);
884 IF_DEF_PARAMS(ifp)->auth_type = vl_config->auth_type;
885 }
886
887 if (vl_config->auth_key) {
888 memset(IF_DEF_PARAMS(ifp)->auth_simple, 0,
889 OSPF_AUTH_SIMPLE_SIZE + 1);
890 strlcpy((char *)IF_DEF_PARAMS(ifp)->auth_simple,
891 vl_config->auth_key,
892 sizeof(IF_DEF_PARAMS(ifp)->auth_simple));
893 } else if (vl_config->md5_key) {
894 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt,
895 vl_config->crypto_key_id)
896 != NULL) {
897 vty_out(vty, "OSPF: Key %d already exists\n",
898 vl_config->crypto_key_id);
899 return CMD_WARNING;
900 }
901 ck = ospf_crypt_key_new();
902 ck->key_id = vl_config->crypto_key_id;
903 memset(ck->auth_key, 0, OSPF_AUTH_MD5_SIZE + 1);
904 strlcpy((char *)ck->auth_key, vl_config->md5_key,
905 sizeof(ck->auth_key));
906
907 ospf_crypt_key_add(IF_DEF_PARAMS(ifp)->auth_crypt, ck);
908 } else if (vl_config->crypto_key_id != 0) {
909 /* Delete a key */
910
911 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt,
912 vl_config->crypto_key_id)
913 == NULL) {
914 vty_out(vty, "OSPF: Key %d does not exist\n",
915 vl_config->crypto_key_id);
916 return CMD_WARNING_CONFIG_FAILED;
917 }
918
919 ospf_crypt_key_delete(IF_DEF_PARAMS(ifp)->auth_crypt,
920 vl_config->crypto_key_id);
921 }
922
923 return CMD_SUCCESS;
924 }
925
926 static int ospf_vl_set_timers(struct ospf_vl_data *vl_data,
927 struct ospf_vl_config_data *vl_config)
928 {
929 struct interface *ifp = vl_data->vl_oi->ifp;
930 /* Virtual Link data initialised to defaults, so only set
931 if a value given */
932 if (vl_config->hello_interval) {
933 SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_hello);
934 IF_DEF_PARAMS(ifp)->v_hello = vl_config->hello_interval;
935 }
936
937 if (vl_config->dead_interval) {
938 SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_wait);
939 IF_DEF_PARAMS(ifp)->v_wait = vl_config->dead_interval;
940 }
941
942 if (vl_config->retransmit_interval) {
943 SET_IF_PARAM(IF_DEF_PARAMS(ifp), retransmit_interval);
944 IF_DEF_PARAMS(ifp)->retransmit_interval =
945 vl_config->retransmit_interval;
946 }
947
948 if (vl_config->transmit_delay) {
949 SET_IF_PARAM(IF_DEF_PARAMS(ifp), transmit_delay);
950 IF_DEF_PARAMS(ifp)->transmit_delay = vl_config->transmit_delay;
951 }
952
953 return CMD_SUCCESS;
954 }
955
956
957 /* The business end of all of the above */
958 static int ospf_vl_set(struct ospf *ospf, struct ospf_vl_config_data *vl_config)
959 {
960 struct ospf_vl_data *vl_data;
961 int ret;
962
963 vl_data = ospf_find_vl_data(ospf, vl_config);
964 if (!vl_data)
965 return CMD_WARNING_CONFIG_FAILED;
966
967 /* Process this one first as it can have a fatal result, which can
968 only logically occur if the virtual link exists already
969 Thus a command error does not result in a change to the
970 running configuration such as unexpectedly altered timer
971 values etc.*/
972 ret = ospf_vl_set_security(vl_data, vl_config);
973 if (ret != CMD_SUCCESS)
974 return ret;
975
976 /* Set any time based parameters, these area already range checked */
977
978 ret = ospf_vl_set_timers(vl_data, vl_config);
979 if (ret != CMD_SUCCESS)
980 return ret;
981
982 return CMD_SUCCESS;
983 }
984
985 /* This stuff exists to make specifying all the alias commands A LOT simpler
986 */
987 #define VLINK_HELPSTR_IPADDR \
988 "OSPF area parameters\n" \
989 "OSPF area ID in IP address format\n" \
990 "OSPF area ID as a decimal value\n" \
991 "Configure a virtual link\n" \
992 "Router ID of the remote ABR\n"
993
994 #define VLINK_HELPSTR_AUTHTYPE_SIMPLE \
995 "Enable authentication on this virtual link\n" \
996 "dummy string \n"
997
998 #define VLINK_HELPSTR_AUTHTYPE_ALL \
999 VLINK_HELPSTR_AUTHTYPE_SIMPLE \
1000 "Use null authentication\n" \
1001 "Use message-digest authentication\n"
1002
1003 #define VLINK_HELPSTR_TIME_PARAM \
1004 "Time between HELLO packets\n" \
1005 "Seconds\n" \
1006 "Time between retransmitting lost link state advertisements\n" \
1007 "Seconds\n" \
1008 "Link state transmit delay\n" \
1009 "Seconds\n" \
1010 "Interval time after which a neighbor is declared down\n" \
1011 "Seconds\n"
1012
1013 #define VLINK_HELPSTR_AUTH_SIMPLE \
1014 "Authentication password (key)\n" \
1015 "The OSPF password (key)\n"
1016
1017 #define VLINK_HELPSTR_AUTH_MD5 \
1018 "Message digest authentication password (key)\n" \
1019 "Key ID\n" \
1020 "Use MD5 algorithm\n" \
1021 "The OSPF password (key)\n"
1022
1023 DEFUN (ospf_area_vlink,
1024 ospf_area_vlink_cmd,
1025 "area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D [authentication [<message-digest|null>]] [<message-digest-key (1-255) md5 KEY|authentication-key AUTH_KEY>]",
1026 VLINK_HELPSTR_IPADDR
1027 "Enable authentication on this virtual link\n"
1028 "Use message-digest authentication\n"
1029 "Use null authentication\n"
1030 VLINK_HELPSTR_AUTH_MD5
1031 VLINK_HELPSTR_AUTH_SIMPLE)
1032 {
1033 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1034 int idx_ipv4_number = 1;
1035 int idx_ipv4 = 3;
1036 struct ospf_vl_config_data vl_config;
1037 char auth_key[OSPF_AUTH_SIMPLE_SIZE + 1];
1038 char md5_key[OSPF_AUTH_MD5_SIZE + 1];
1039 int ret;
1040 int idx = 0;
1041
1042 ospf_vl_config_data_init(&vl_config, vty);
1043
1044 /* Read off first 2 parameters and check them */
1045 ret = str2area_id(argv[idx_ipv4_number]->arg, &vl_config.area_id,
1046 &vl_config.area_id_fmt);
1047 if (ret < 0) {
1048 vty_out(vty, "OSPF area ID is invalid\n");
1049 return CMD_WARNING_CONFIG_FAILED;
1050 }
1051
1052 ret = inet_aton(argv[idx_ipv4]->arg, &vl_config.vl_peer);
1053 if (!ret) {
1054 vty_out(vty, "Please specify valid Router ID as a.b.c.d\n");
1055 return CMD_WARNING_CONFIG_FAILED;
1056 }
1057
1058 if (argc <= 4) {
1059 /* Thats all folks! - BUGS B. strikes again!!!*/
1060
1061 return ospf_vl_set(ospf, &vl_config);
1062 }
1063
1064 if (argv_find(argv, argc, "authentication", &idx)) {
1065 /* authentication - this option can only occur
1066 at start of command line */
1067 vl_config.auth_type = OSPF_AUTH_SIMPLE;
1068 }
1069
1070 if (argv_find(argv, argc, "message-digest", &idx)) {
1071 /* authentication message-digest */
1072 vl_config.auth_type = OSPF_AUTH_CRYPTOGRAPHIC;
1073 } else if (argv_find(argv, argc, "null", &idx)) {
1074 /* "authentication null" */
1075 vl_config.auth_type = OSPF_AUTH_NULL;
1076 }
1077
1078 if (argv_find(argv, argc, "message-digest-key", &idx)) {
1079 vl_config.md5_key = NULL;
1080 vl_config.crypto_key_id = strtol(argv[idx + 1]->arg, NULL, 10);
1081 if (vl_config.crypto_key_id < 0)
1082 return CMD_WARNING_CONFIG_FAILED;
1083
1084 strlcpy(md5_key, argv[idx + 3]->arg, sizeof(md5_key));
1085 vl_config.md5_key = md5_key;
1086 }
1087
1088 if (argv_find(argv, argc, "authentication-key", &idx)) {
1089 strlcpy(auth_key, argv[idx + 1]->arg, sizeof(auth_key));
1090 vl_config.auth_key = auth_key;
1091 }
1092
1093 /* Action configuration */
1094
1095 return ospf_vl_set(ospf, &vl_config);
1096 }
1097
1098 DEFUN (no_ospf_area_vlink,
1099 no_ospf_area_vlink_cmd,
1100 "no area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D [authentication [<message-digest|null>]] [<message-digest-key (1-255) md5 KEY|authentication-key AUTH_KEY>]",
1101 NO_STR
1102 VLINK_HELPSTR_IPADDR
1103 "Enable authentication on this virtual link\n"
1104 "Use message-digest authentication\n"
1105 "Use null authentication\n"
1106 VLINK_HELPSTR_AUTH_MD5
1107 VLINK_HELPSTR_AUTH_SIMPLE)
1108 {
1109 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1110 int idx_ipv4_number = 2;
1111 int idx_ipv4 = 4;
1112 struct ospf_area *area;
1113 struct ospf_vl_config_data vl_config;
1114 struct ospf_vl_data *vl_data = NULL;
1115 char auth_key[OSPF_AUTH_SIMPLE_SIZE + 1];
1116 int idx = 0;
1117 int ret, format;
1118
1119 ospf_vl_config_data_init(&vl_config, vty);
1120
1121 ret = str2area_id(argv[idx_ipv4_number]->arg, &vl_config.area_id,
1122 &format);
1123 if (ret < 0) {
1124 vty_out(vty, "OSPF area ID is invalid\n");
1125 return CMD_WARNING_CONFIG_FAILED;
1126 }
1127
1128 area = ospf_area_lookup_by_area_id(ospf, vl_config.area_id);
1129 if (!area) {
1130 vty_out(vty, "Area does not exist\n");
1131 return CMD_WARNING_CONFIG_FAILED;
1132 }
1133
1134 ret = inet_aton(argv[idx_ipv4]->arg, &vl_config.vl_peer);
1135 if (!ret) {
1136 vty_out(vty, "Please specify valid Router ID as a.b.c.d\n");
1137 return CMD_WARNING_CONFIG_FAILED;
1138 }
1139
1140 vl_data = ospf_vl_lookup(ospf, area, vl_config.vl_peer);
1141 if (!vl_data) {
1142 vty_out(vty, "Virtual link does not exist\n");
1143 return CMD_WARNING_CONFIG_FAILED;
1144 }
1145
1146 if (argc <= 5) {
1147 /* Basic VLink no command */
1148 /* Thats all folks! - BUGS B. strikes again!!!*/
1149 ospf_vl_delete(ospf, vl_data);
1150 ospf_area_check_free(ospf, vl_config.area_id);
1151 return CMD_SUCCESS;
1152 }
1153
1154 /* If we are down here, we are reseting parameters */
1155 /* Deal with other parameters */
1156
1157 if (argv_find(argv, argc, "authentication", &idx)) {
1158 /* authentication - this option can only occur
1159 at start of command line */
1160 vl_config.auth_type = OSPF_AUTH_NOTSET;
1161 }
1162
1163 if (argv_find(argv, argc, "message-digest-key", &idx)) {
1164 vl_config.md5_key = NULL;
1165 vl_config.crypto_key_id = strtol(argv[idx + 1]->arg, NULL, 10);
1166 if (vl_config.crypto_key_id < 0)
1167 return CMD_WARNING_CONFIG_FAILED;
1168 }
1169
1170 if (argv_find(argv, argc, "authentication-key", &idx)) {
1171 /* Reset authentication-key to 0 */
1172 memset(auth_key, 0, OSPF_AUTH_SIMPLE_SIZE + 1);
1173 vl_config.auth_key = auth_key;
1174 }
1175
1176 /* Action configuration */
1177
1178 return ospf_vl_set(ospf, &vl_config);
1179 }
1180
1181 DEFUN (ospf_area_vlink_intervals,
1182 ospf_area_vlink_intervals_cmd,
1183 "area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D {hello-interval (1-65535)|retransmit-interval (1-65535)|transmit-delay (1-65535)|dead-interval (1-65535)}",
1184 VLINK_HELPSTR_IPADDR
1185 VLINK_HELPSTR_TIME_PARAM)
1186 {
1187 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1188 struct ospf_vl_config_data vl_config;
1189 int ret = 0;
1190
1191 ospf_vl_config_data_init(&vl_config, vty);
1192
1193 char *area_id = argv[1]->arg;
1194 char *router_id = argv[3]->arg;
1195
1196 ret = str2area_id(area_id, &vl_config.area_id, &vl_config.area_id_fmt);
1197 if (ret < 0) {
1198 vty_out(vty, "OSPF area ID is invalid\n");
1199 return CMD_WARNING_CONFIG_FAILED;
1200 }
1201
1202 ret = inet_aton(router_id, &vl_config.vl_peer);
1203 if (!ret) {
1204 vty_out(vty, "Please specify valid Router ID as a.b.c.d\n");
1205 return CMD_WARNING_CONFIG_FAILED;
1206 }
1207
1208 for (int idx = 4; idx < argc; idx++) {
1209 if (strmatch(argv[idx]->text, "hello-interval"))
1210 vl_config.hello_interval =
1211 strtol(argv[++idx]->arg, NULL, 10);
1212 else if (strmatch(argv[idx]->text, "retransmit-interval"))
1213 vl_config.retransmit_interval =
1214 strtol(argv[++idx]->arg, NULL, 10);
1215 else if (strmatch(argv[idx]->text, "transmit-delay"))
1216 vl_config.transmit_delay =
1217 strtol(argv[++idx]->arg, NULL, 10);
1218 else if (strmatch(argv[idx]->text, "dead-interval"))
1219 vl_config.dead_interval =
1220 strtol(argv[++idx]->arg, NULL, 10);
1221 }
1222
1223 /* Action configuration */
1224 return ospf_vl_set(ospf, &vl_config);
1225 }
1226
1227 DEFUN (no_ospf_area_vlink_intervals,
1228 no_ospf_area_vlink_intervals_cmd,
1229 "no area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D {hello-interval (1-65535)|retransmit-interval (1-65535)|transmit-delay (1-65535)|dead-interval (1-65535)}",
1230 NO_STR
1231 VLINK_HELPSTR_IPADDR
1232 VLINK_HELPSTR_TIME_PARAM)
1233 {
1234 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1235 struct ospf_vl_config_data vl_config;
1236 int ret = 0;
1237
1238 ospf_vl_config_data_init(&vl_config, vty);
1239
1240 char *area_id = argv[2]->arg;
1241 char *router_id = argv[4]->arg;
1242
1243 ret = str2area_id(area_id, &vl_config.area_id, &vl_config.area_id_fmt);
1244 if (ret < 0) {
1245 vty_out(vty, "OSPF area ID is invalid\n");
1246 return CMD_WARNING_CONFIG_FAILED;
1247 }
1248
1249 ret = inet_aton(router_id, &vl_config.vl_peer);
1250 if (!ret) {
1251 vty_out(vty, "Please specify valid Router ID as a.b.c.d\n");
1252 return CMD_WARNING_CONFIG_FAILED;
1253 }
1254
1255 for (int idx = 5; idx < argc; idx++) {
1256 if (strmatch(argv[idx]->text, "hello-interval"))
1257 vl_config.hello_interval = OSPF_HELLO_INTERVAL_DEFAULT;
1258 else if (strmatch(argv[idx]->text, "retransmit-interval"))
1259 vl_config.retransmit_interval =
1260 OSPF_RETRANSMIT_INTERVAL_DEFAULT;
1261 else if (strmatch(argv[idx]->text, "transmit-delay"))
1262 vl_config.transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT;
1263 else if (strmatch(argv[idx]->text, "dead-interval"))
1264 vl_config.dead_interval =
1265 OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
1266 }
1267
1268 /* Action configuration */
1269 return ospf_vl_set(ospf, &vl_config);
1270 }
1271
1272 DEFUN (ospf_area_shortcut,
1273 ospf_area_shortcut_cmd,
1274 "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>",
1275 "OSPF area parameters\n"
1276 "OSPF area ID in IP address format\n"
1277 "OSPF area ID as a decimal value\n"
1278 "Configure the area's shortcutting mode\n"
1279 "Set default shortcutting behavior\n"
1280 "Enable shortcutting through the area\n"
1281 "Disable shortcutting through the area\n")
1282 {
1283 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1284 int idx_ipv4_number = 1;
1285 int idx_enable_disable = 3;
1286 struct ospf_area *area;
1287 struct in_addr area_id;
1288 int mode;
1289 int format;
1290
1291 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id, format,
1292 argv[idx_ipv4_number]->arg);
1293
1294 area = ospf_area_get(ospf, area_id);
1295 ospf_area_display_format_set(ospf, area, format);
1296
1297 if (strncmp(argv[idx_enable_disable]->arg, "de", 2) == 0)
1298 mode = OSPF_SHORTCUT_DEFAULT;
1299 else if (strncmp(argv[idx_enable_disable]->arg, "di", 2) == 0)
1300 mode = OSPF_SHORTCUT_DISABLE;
1301 else if (strncmp(argv[idx_enable_disable]->arg, "e", 1) == 0)
1302 mode = OSPF_SHORTCUT_ENABLE;
1303 else
1304 return CMD_WARNING_CONFIG_FAILED;
1305
1306 ospf_area_shortcut_set(ospf, area, mode);
1307
1308 if (ospf->abr_type != OSPF_ABR_SHORTCUT)
1309 vty_out(vty,
1310 "Shortcut area setting will take effect only when the router is configured as Shortcut ABR\n");
1311
1312 return CMD_SUCCESS;
1313 }
1314
1315 DEFUN (no_ospf_area_shortcut,
1316 no_ospf_area_shortcut_cmd,
1317 "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>",
1318 NO_STR
1319 "OSPF area parameters\n"
1320 "OSPF area ID in IP address format\n"
1321 "OSPF area ID as a decimal value\n"
1322 "Deconfigure the area's shortcutting mode\n"
1323 "Deconfigure enabled shortcutting through the area\n"
1324 "Deconfigure disabled shortcutting through the area\n")
1325 {
1326 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1327 int idx_ipv4_number = 2;
1328 struct ospf_area *area;
1329 struct in_addr area_id;
1330 int format;
1331
1332 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id, format,
1333 argv[idx_ipv4_number]->arg);
1334
1335 area = ospf_area_lookup_by_area_id(ospf, area_id);
1336 if (!area)
1337 return CMD_SUCCESS;
1338
1339 ospf_area_shortcut_unset(ospf, area);
1340
1341 return CMD_SUCCESS;
1342 }
1343
1344
1345 DEFUN (ospf_area_stub,
1346 ospf_area_stub_cmd,
1347 "area <A.B.C.D|(0-4294967295)> stub",
1348 "OSPF area parameters\n"
1349 "OSPF area ID in IP address format\n"
1350 "OSPF area ID as a decimal value\n"
1351 "Configure OSPF area as stub\n")
1352 {
1353 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1354 int idx_ipv4_number = 1;
1355 struct in_addr area_id;
1356 int ret, format;
1357
1358 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format,
1359 argv[idx_ipv4_number]->arg);
1360
1361 ret = ospf_area_stub_set(ospf, area_id);
1362 ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
1363 format);
1364 if (ret == 0) {
1365 vty_out(vty,
1366 "First deconfigure all virtual link through this area\n");
1367 return CMD_WARNING_CONFIG_FAILED;
1368 }
1369
1370 /* Flush the external LSAs from the specified area */
1371 ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_EXTERNAL_LSA);
1372 ospf_area_no_summary_unset(ospf, area_id);
1373
1374 return CMD_SUCCESS;
1375 }
1376
1377 DEFUN (ospf_area_stub_no_summary,
1378 ospf_area_stub_no_summary_cmd,
1379 "area <A.B.C.D|(0-4294967295)> stub no-summary",
1380 "OSPF stub parameters\n"
1381 "OSPF area ID in IP address format\n"
1382 "OSPF area ID as a decimal value\n"
1383 "Configure OSPF area as stub\n"
1384 "Do not inject inter-area routes into stub\n")
1385 {
1386 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1387 int idx_ipv4_number = 1;
1388 struct in_addr area_id;
1389 int ret, format;
1390
1391 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format,
1392 argv[idx_ipv4_number]->arg);
1393
1394 ret = ospf_area_stub_set(ospf, area_id);
1395 ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
1396 format);
1397 if (ret == 0) {
1398 vty_out(vty,
1399 "%% Area cannot be stub as it contains a virtual link\n");
1400 return CMD_WARNING_CONFIG_FAILED;
1401 }
1402
1403 ospf_area_no_summary_set(ospf, area_id);
1404
1405 return CMD_SUCCESS;
1406 }
1407
1408 DEFUN (no_ospf_area_stub,
1409 no_ospf_area_stub_cmd,
1410 "no area <A.B.C.D|(0-4294967295)> stub",
1411 NO_STR
1412 "OSPF area parameters\n"
1413 "OSPF area ID in IP address format\n"
1414 "OSPF area ID as a decimal value\n"
1415 "Configure OSPF area as stub\n")
1416 {
1417 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1418 int idx_ipv4_number = 2;
1419 struct in_addr area_id;
1420 int format;
1421
1422 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format,
1423 argv[idx_ipv4_number]->arg);
1424
1425 ospf_area_stub_unset(ospf, area_id);
1426 ospf_area_no_summary_unset(ospf, area_id);
1427
1428 return CMD_SUCCESS;
1429 }
1430
1431 DEFUN (no_ospf_area_stub_no_summary,
1432 no_ospf_area_stub_no_summary_cmd,
1433 "no area <A.B.C.D|(0-4294967295)> stub no-summary",
1434 NO_STR
1435 "OSPF area parameters\n"
1436 "OSPF area ID in IP address format\n"
1437 "OSPF area ID as a decimal value\n"
1438 "Configure OSPF area as stub\n"
1439 "Do not inject inter-area routes into area\n")
1440 {
1441 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1442 int idx_ipv4_number = 2;
1443 struct in_addr area_id;
1444 int format;
1445
1446 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format,
1447 argv[idx_ipv4_number]->arg);
1448 ospf_area_no_summary_unset(ospf, area_id);
1449
1450 return CMD_SUCCESS;
1451 }
1452
1453 DEFPY (ospf_area_nssa,
1454 ospf_area_nssa_cmd,
1455 "area <A.B.C.D|(0-4294967295)>$area_str nssa\
1456 [{\
1457 <translate-candidate|translate-never|translate-always>$translator_role\
1458 |default-information-originate$dflt_originate [{metric (0-16777214)$mval|metric-type (1-2)$mtype}]\
1459 |no-summary$no_summary\
1460 |suppress-fa$suppress_fa\
1461 }]",
1462 "OSPF area parameters\n"
1463 "OSPF area ID in IP address format\n"
1464 "OSPF area ID as a decimal value\n"
1465 "Configure OSPF area as nssa\n"
1466 "Configure NSSA-ABR for translate election (default)\n"
1467 "Configure NSSA-ABR to never translate\n"
1468 "Configure NSSA-ABR to always translate\n"
1469 "Originate Type 7 default into NSSA area\n"
1470 "OSPF default metric\n"
1471 "OSPF metric\n"
1472 "OSPF metric type for default routes\n"
1473 "Set OSPF External Type 1/2 metrics\n"
1474 "Do not inject inter-area routes into nssa\n"
1475 "Suppress forwarding address\n")
1476 {
1477 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1478 struct in_addr area_id;
1479 int ret, format;
1480
1481 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, area_str);
1482
1483 ret = ospf_area_nssa_set(ospf, area_id);
1484 ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
1485 format);
1486 if (ret == 0) {
1487 vty_out(vty,
1488 "%% Area cannot be nssa as it contains a virtual link\n");
1489 return CMD_WARNING_CONFIG_FAILED;
1490 }
1491
1492 if (translator_role) {
1493 if (strncmp(translator_role, "translate-c", 11) == 0)
1494 ospf_area_nssa_translator_role_set(
1495 ospf, area_id, OSPF_NSSA_ROLE_CANDIDATE);
1496 else if (strncmp(translator_role, "translate-n", 11) == 0)
1497 ospf_area_nssa_translator_role_set(
1498 ospf, area_id, OSPF_NSSA_ROLE_NEVER);
1499 else if (strncmp(translator_role, "translate-a", 11) == 0)
1500 ospf_area_nssa_translator_role_set(
1501 ospf, area_id, OSPF_NSSA_ROLE_ALWAYS);
1502 } else {
1503 ospf_area_nssa_translator_role_set(ospf, area_id,
1504 OSPF_NSSA_ROLE_CANDIDATE);
1505 }
1506
1507 if (dflt_originate) {
1508 int metric_type = DEFAULT_METRIC_TYPE;
1509
1510 if (mval_str == NULL)
1511 mval = -1;
1512 if (mtype_str)
1513 (void)str2metric_type(mtype_str, &metric_type);
1514 ospf_area_nssa_default_originate_set(ospf, area_id, mval,
1515 metric_type);
1516 } else
1517 ospf_area_nssa_default_originate_unset(ospf, area_id);
1518
1519 if (no_summary)
1520 ospf_area_nssa_no_summary_set(ospf, area_id);
1521 else
1522 ospf_area_no_summary_unset(ospf, area_id);
1523
1524 if (suppress_fa)
1525 ospf_area_nssa_suppress_fa_set(ospf, area_id);
1526 else
1527 ospf_area_nssa_suppress_fa_unset(ospf, area_id);
1528
1529 /* Flush the external LSA for the specified area */
1530 ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_EXTERNAL_LSA);
1531 ospf_schedule_abr_task(ospf);
1532 ospf_schedule_asbr_nssa_redist_update(ospf);
1533
1534 return CMD_SUCCESS;
1535 }
1536
1537 DEFPY (no_ospf_area_nssa,
1538 no_ospf_area_nssa_cmd,
1539 "no area <A.B.C.D|(0-4294967295)>$area_str nssa\
1540 [{\
1541 <translate-candidate|translate-never|translate-always>\
1542 |default-information-originate [{metric (0-16777214)|metric-type (1-2)}]\
1543 |no-summary\
1544 |suppress-fa\
1545 }]",
1546 NO_STR
1547 "OSPF area parameters\n"
1548 "OSPF area ID in IP address format\n"
1549 "OSPF area ID as a decimal value\n"
1550 "Configure OSPF area as nssa\n"
1551 "Configure NSSA-ABR for translate election (default)\n"
1552 "Configure NSSA-ABR to never translate\n"
1553 "Configure NSSA-ABR to always translate\n"
1554 "Originate Type 7 default into NSSA area\n"
1555 "OSPF default metric\n"
1556 "OSPF metric\n"
1557 "OSPF metric type for default routes\n"
1558 "Set OSPF External Type 1/2 metrics\n"
1559 "Do not inject inter-area routes into nssa\n"
1560 "Suppress forwarding address\n")
1561 {
1562 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1563 struct in_addr area_id;
1564 int format;
1565
1566 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, area_str);
1567
1568 /* Flush the NSSA LSA for the specified area */
1569 ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_NSSA_LSA);
1570 ospf_area_no_summary_unset(ospf, area_id);
1571 ospf_area_nssa_default_originate_unset(ospf, area_id);
1572 ospf_area_nssa_suppress_fa_unset(ospf, area_id);
1573 ospf_area_nssa_unset(ospf, area_id);
1574
1575 ospf_schedule_abr_task(ospf);
1576
1577 return CMD_SUCCESS;
1578 }
1579
1580 DEFPY (ospf_area_nssa_range,
1581 ospf_area_nssa_range_cmd,
1582 "area <A.B.C.D|(0-4294967295)>$area_str nssa range A.B.C.D/M$prefix [<not-advertise$not_adv|cost (0-16777215)$cost>]",
1583 "OSPF area parameters\n"
1584 "OSPF area ID in IP address format\n"
1585 "OSPF area ID as a decimal value\n"
1586 "Configure OSPF area as nssa\n"
1587 "Configured address range\n"
1588 "Specify IPv4 prefix\n"
1589 "Do not advertise\n"
1590 "User specified metric for this range\n"
1591 "Advertised metric for this range\n")
1592 {
1593 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1594 struct ospf_area *area;
1595 struct in_addr area_id;
1596 int format;
1597 int advertise = 0;
1598
1599 VTY_GET_OSPF_AREA_ID(area_id, format, area_str);
1600 area = ospf_area_get(ospf, area_id);
1601 ospf_area_display_format_set(ospf, area, format);
1602
1603 if (area->external_routing != OSPF_AREA_NSSA) {
1604 vty_out(vty, "%% First configure %s as an NSSA area\n",
1605 area_str);
1606 return CMD_WARNING;
1607 }
1608
1609 if (!not_adv)
1610 advertise = OSPF_AREA_RANGE_ADVERTISE;
1611
1612 ospf_area_range_set(ospf, area, area->nssa_ranges,
1613 (struct prefix_ipv4 *)prefix, advertise, true);
1614 if (cost_str)
1615 ospf_area_range_cost_set(ospf, area, area->nssa_ranges,
1616 (struct prefix_ipv4 *)prefix, cost);
1617
1618 return CMD_SUCCESS;
1619 }
1620
1621 DEFPY (no_ospf_area_nssa_range,
1622 no_ospf_area_nssa_range_cmd,
1623 "no area <A.B.C.D|(0-4294967295)>$area_str nssa range A.B.C.D/M$prefix [<not-advertise|cost (0-16777215)>]",
1624 NO_STR
1625 "OSPF area parameters\n"
1626 "OSPF area ID in IP address format\n"
1627 "OSPF area ID as a decimal value\n"
1628 "Configure OSPF area as nssa\n"
1629 "Configured address range\n"
1630 "Specify IPv4 prefix\n"
1631 "Do not advertise\n"
1632 "User specified metric for this range\n"
1633 "Advertised metric for this range\n")
1634 {
1635 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1636 struct ospf_area *area;
1637 struct in_addr area_id;
1638 int format;
1639
1640 VTY_GET_OSPF_AREA_ID(area_id, format, area_str);
1641 area = ospf_area_get(ospf, area_id);
1642 ospf_area_display_format_set(ospf, area, format);
1643
1644 if (area->external_routing != OSPF_AREA_NSSA) {
1645 vty_out(vty, "%% First configure %s as an NSSA area\n",
1646 area_str);
1647 return CMD_WARNING;
1648 }
1649
1650 ospf_area_range_unset(ospf, area, area->nssa_ranges,
1651 (struct prefix_ipv4 *)prefix);
1652
1653 return CMD_SUCCESS;
1654 }
1655
1656 DEFUN (ospf_area_default_cost,
1657 ospf_area_default_cost_cmd,
1658 "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1659 "OSPF area parameters\n"
1660 "OSPF area ID in IP address format\n"
1661 "OSPF area ID as a decimal value\n"
1662 "Set the summary-default cost of a NSSA or stub area\n"
1663 "Stub's advertised default summary cost\n")
1664 {
1665 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1666 int idx_ipv4_number = 1;
1667 int idx_number = 3;
1668 struct ospf_area *area;
1669 struct in_addr area_id;
1670 uint32_t cost;
1671 int format;
1672 struct prefix_ipv4 p;
1673
1674 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id, format,
1675 argv[idx_ipv4_number]->arg);
1676 cost = strtoul(argv[idx_number]->arg, NULL, 10);
1677
1678 area = ospf_area_get(ospf, area_id);
1679 ospf_area_display_format_set(ospf, area, format);
1680
1681 if (area->external_routing == OSPF_AREA_DEFAULT) {
1682 vty_out(vty, "The area is neither stub, nor NSSA\n");
1683 return CMD_WARNING_CONFIG_FAILED;
1684 }
1685
1686 area->default_cost = cost;
1687
1688 p.family = AF_INET;
1689 p.prefix.s_addr = OSPF_DEFAULT_DESTINATION;
1690 p.prefixlen = 0;
1691 if (IS_DEBUG_OSPF_EVENT)
1692 zlog_debug(
1693 "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4",
1694 &area->area_id);
1695 ospf_abr_announce_network_to_area(&p, area->default_cost, area);
1696
1697 return CMD_SUCCESS;
1698 }
1699
1700 DEFUN (no_ospf_area_default_cost,
1701 no_ospf_area_default_cost_cmd,
1702 "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1703 NO_STR
1704 "OSPF area parameters\n"
1705 "OSPF area ID in IP address format\n"
1706 "OSPF area ID as a decimal value\n"
1707 "Set the summary-default cost of a NSSA or stub area\n"
1708 "Stub's advertised default summary cost\n")
1709 {
1710 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1711 int idx_ipv4_number = 2;
1712 struct ospf_area *area;
1713 struct in_addr area_id;
1714 int format;
1715 struct prefix_ipv4 p;
1716
1717 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id, format,
1718 argv[idx_ipv4_number]->arg);
1719
1720 area = ospf_area_lookup_by_area_id(ospf, area_id);
1721 if (area == NULL)
1722 return CMD_SUCCESS;
1723
1724 if (area->external_routing == OSPF_AREA_DEFAULT) {
1725 vty_out(vty, "The area is neither stub, nor NSSA\n");
1726 return CMD_WARNING_CONFIG_FAILED;
1727 }
1728
1729 area->default_cost = 1;
1730
1731 p.family = AF_INET;
1732 p.prefix.s_addr = OSPF_DEFAULT_DESTINATION;
1733 p.prefixlen = 0;
1734 if (IS_DEBUG_OSPF_EVENT)
1735 zlog_debug(
1736 "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4",
1737 &area->area_id);
1738 ospf_abr_announce_network_to_area(&p, area->default_cost, area);
1739
1740
1741 ospf_area_check_free(ospf, area_id);
1742
1743 return CMD_SUCCESS;
1744 }
1745
1746 DEFUN (ospf_area_export_list,
1747 ospf_area_export_list_cmd,
1748 "area <A.B.C.D|(0-4294967295)> export-list ACCESSLIST4_NAME",
1749 "OSPF area parameters\n"
1750 "OSPF area ID in IP address format\n"
1751 "OSPF area ID as a decimal value\n"
1752 "Set the filter for networks announced to other areas\n"
1753 "Name of the access-list\n")
1754 {
1755 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1756 int idx_ipv4_number = 1;
1757 struct ospf_area *area;
1758 struct in_addr area_id;
1759 int format;
1760
1761 VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
1762
1763 area = ospf_area_get(ospf, area_id);
1764 ospf_area_display_format_set(ospf, area, format);
1765 ospf_area_export_list_set(ospf, area, argv[3]->arg);
1766
1767 return CMD_SUCCESS;
1768 }
1769
1770 DEFUN (no_ospf_area_export_list,
1771 no_ospf_area_export_list_cmd,
1772 "no area <A.B.C.D|(0-4294967295)> export-list ACCESSLIST4_NAME",
1773 NO_STR
1774 "OSPF area parameters\n"
1775 "OSPF area ID in IP address format\n"
1776 "OSPF area ID as a decimal value\n"
1777 "Unset the filter for networks announced to other areas\n"
1778 "Name of the access-list\n")
1779 {
1780 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1781 int idx_ipv4_number = 2;
1782 struct ospf_area *area;
1783 struct in_addr area_id;
1784 int format;
1785
1786 VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
1787
1788 area = ospf_area_lookup_by_area_id(ospf, area_id);
1789 if (area == NULL)
1790 return CMD_SUCCESS;
1791
1792 ospf_area_export_list_unset(ospf, area);
1793
1794 return CMD_SUCCESS;
1795 }
1796
1797
1798 DEFUN (ospf_area_import_list,
1799 ospf_area_import_list_cmd,
1800 "area <A.B.C.D|(0-4294967295)> import-list ACCESSLIST4_NAME",
1801 "OSPF area parameters\n"
1802 "OSPF area ID in IP address format\n"
1803 "OSPF area ID as a decimal value\n"
1804 "Set the filter for networks from other areas announced to the specified one\n"
1805 "Name of the access-list\n")
1806 {
1807 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1808 int idx_ipv4_number = 1;
1809 struct ospf_area *area;
1810 struct in_addr area_id;
1811 int format;
1812
1813 VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
1814
1815 area = ospf_area_get(ospf, area_id);
1816 ospf_area_display_format_set(ospf, area, format);
1817 ospf_area_import_list_set(ospf, area, argv[3]->arg);
1818
1819 return CMD_SUCCESS;
1820 }
1821
1822 DEFUN (no_ospf_area_import_list,
1823 no_ospf_area_import_list_cmd,
1824 "no area <A.B.C.D|(0-4294967295)> import-list ACCESSLIST4_NAME",
1825 NO_STR
1826 "OSPF area parameters\n"
1827 "OSPF area ID in IP address format\n"
1828 "OSPF area ID as a decimal value\n"
1829 "Unset the filter for networks announced to other areas\n"
1830 "Name of the access-list\n")
1831 {
1832 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1833 int idx_ipv4_number = 2;
1834 struct ospf_area *area;
1835 struct in_addr area_id;
1836 int format;
1837
1838 VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
1839
1840 area = ospf_area_lookup_by_area_id(ospf, area_id);
1841 if (area == NULL)
1842 return CMD_SUCCESS;
1843
1844 ospf_area_import_list_unset(ospf, area);
1845
1846 return CMD_SUCCESS;
1847 }
1848
1849 DEFUN (ospf_area_filter_list,
1850 ospf_area_filter_list_cmd,
1851 "area <A.B.C.D|(0-4294967295)> filter-list prefix PREFIXLIST_NAME <in|out>",
1852 "OSPF area parameters\n"
1853 "OSPF area ID in IP address format\n"
1854 "OSPF area ID as a decimal value\n"
1855 "Filter networks between OSPF areas\n"
1856 "Filter prefixes between OSPF areas\n"
1857 "Name of an IP prefix-list\n"
1858 "Filter networks sent to this area\n"
1859 "Filter networks sent from this area\n")
1860 {
1861 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1862 int idx_ipv4_number = 1;
1863 int idx_word = 4;
1864 int idx_in_out = 5;
1865 struct ospf_area *area;
1866 struct in_addr area_id;
1867 struct prefix_list *plist;
1868 int format;
1869
1870 VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
1871
1872 area = ospf_area_get(ospf, area_id);
1873 ospf_area_display_format_set(ospf, area, format);
1874 plist = prefix_list_lookup(AFI_IP, argv[idx_word]->arg);
1875 if (strncmp(argv[idx_in_out]->arg, "in", 2) == 0) {
1876 PREFIX_LIST_IN(area) = plist;
1877 if (PREFIX_NAME_IN(area))
1878 free(PREFIX_NAME_IN(area));
1879
1880 PREFIX_NAME_IN(area) = strdup(argv[idx_word]->arg);
1881 ospf_schedule_abr_task(ospf);
1882 } else {
1883 PREFIX_LIST_OUT(area) = plist;
1884 if (PREFIX_NAME_OUT(area))
1885 free(PREFIX_NAME_OUT(area));
1886
1887 PREFIX_NAME_OUT(area) = strdup(argv[idx_word]->arg);
1888 ospf_schedule_abr_task(ospf);
1889 }
1890
1891 return CMD_SUCCESS;
1892 }
1893
1894 DEFUN (no_ospf_area_filter_list,
1895 no_ospf_area_filter_list_cmd,
1896 "no area <A.B.C.D|(0-4294967295)> filter-list prefix PREFIXLIST_NAME <in|out>",
1897 NO_STR
1898 "OSPF area parameters\n"
1899 "OSPF area ID in IP address format\n"
1900 "OSPF area ID as a decimal value\n"
1901 "Filter networks between OSPF areas\n"
1902 "Filter prefixes between OSPF areas\n"
1903 "Name of an IP prefix-list\n"
1904 "Filter networks sent to this area\n"
1905 "Filter networks sent from this area\n")
1906 {
1907 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1908 int idx_ipv4_number = 2;
1909 int idx_word = 5;
1910 int idx_in_out = 6;
1911 struct ospf_area *area;
1912 struct in_addr area_id;
1913 int format;
1914
1915 VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
1916
1917 if ((area = ospf_area_lookup_by_area_id(ospf, area_id)) == NULL)
1918 return CMD_SUCCESS;
1919
1920 if (strncmp(argv[idx_in_out]->arg, "in", 2) == 0) {
1921 if (PREFIX_NAME_IN(area))
1922 if (strcmp(PREFIX_NAME_IN(area), argv[idx_word]->arg)
1923 != 0)
1924 return CMD_SUCCESS;
1925
1926 PREFIX_LIST_IN(area) = NULL;
1927 if (PREFIX_NAME_IN(area))
1928 free(PREFIX_NAME_IN(area));
1929
1930 PREFIX_NAME_IN(area) = NULL;
1931
1932 ospf_schedule_abr_task(ospf);
1933 } else {
1934 if (PREFIX_NAME_OUT(area))
1935 if (strcmp(PREFIX_NAME_OUT(area), argv[idx_word]->arg)
1936 != 0)
1937 return CMD_SUCCESS;
1938
1939 PREFIX_LIST_OUT(area) = NULL;
1940 if (PREFIX_NAME_OUT(area))
1941 free(PREFIX_NAME_OUT(area));
1942
1943 PREFIX_NAME_OUT(area) = NULL;
1944
1945 ospf_schedule_abr_task(ospf);
1946 }
1947
1948 return CMD_SUCCESS;
1949 }
1950
1951
1952 DEFUN (ospf_area_authentication_message_digest,
1953 ospf_area_authentication_message_digest_cmd,
1954 "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest",
1955 NO_STR
1956 "OSPF area parameters\n"
1957 "OSPF area ID in IP address format\n"
1958 "OSPF area ID as a decimal value\n"
1959 "Enable authentication\n"
1960 "Use message-digest authentication\n")
1961 {
1962 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1963 int idx = 0;
1964 struct ospf_area *area;
1965 struct in_addr area_id;
1966 int format;
1967
1968 argv_find(argv, argc, "area", &idx);
1969 VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx + 1]->arg);
1970
1971 area = ospf_area_get(ospf, area_id);
1972 ospf_area_display_format_set(ospf, area, format);
1973 area->auth_type = strmatch(argv[0]->text, "no")
1974 ? OSPF_AUTH_NULL
1975 : OSPF_AUTH_CRYPTOGRAPHIC;
1976
1977 return CMD_SUCCESS;
1978 }
1979
1980 DEFUN (ospf_area_authentication,
1981 ospf_area_authentication_cmd,
1982 "area <A.B.C.D|(0-4294967295)> authentication",
1983 "OSPF area parameters\n"
1984 "OSPF area ID in IP address format\n"
1985 "OSPF area ID as a decimal value\n"
1986 "Enable authentication\n")
1987 {
1988 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1989 int idx_ipv4_number = 1;
1990 struct ospf_area *area;
1991 struct in_addr area_id;
1992 int format;
1993
1994 VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
1995
1996 area = ospf_area_get(ospf, area_id);
1997 ospf_area_display_format_set(ospf, area, format);
1998 area->auth_type = OSPF_AUTH_SIMPLE;
1999
2000 return CMD_SUCCESS;
2001 }
2002
2003 DEFUN (no_ospf_area_authentication,
2004 no_ospf_area_authentication_cmd,
2005 "no area <A.B.C.D|(0-4294967295)> authentication",
2006 NO_STR
2007 "OSPF area parameters\n"
2008 "OSPF area ID in IP address format\n"
2009 "OSPF area ID as a decimal value\n"
2010 "Enable authentication\n")
2011 {
2012 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2013 int idx_ipv4_number = 2;
2014 struct ospf_area *area;
2015 struct in_addr area_id;
2016 int format;
2017
2018 VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
2019
2020 area = ospf_area_lookup_by_area_id(ospf, area_id);
2021 if (area == NULL)
2022 return CMD_SUCCESS;
2023
2024 area->auth_type = OSPF_AUTH_NULL;
2025
2026 ospf_area_check_free(ospf, area_id);
2027
2028 return CMD_SUCCESS;
2029 }
2030
2031
2032 DEFUN (ospf_abr_type,
2033 ospf_abr_type_cmd,
2034 "ospf abr-type <cisco|ibm|shortcut|standard>",
2035 "OSPF specific commands\n"
2036 "Set OSPF ABR type\n"
2037 "Alternative ABR, cisco implementation\n"
2038 "Alternative ABR, IBM implementation\n"
2039 "Shortcut ABR\n"
2040 "Standard behavior (RFC2328)\n")
2041 {
2042 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2043 int idx_vendor = 2;
2044 uint8_t abr_type = OSPF_ABR_UNKNOWN;
2045
2046 if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0)
2047 abr_type = OSPF_ABR_CISCO;
2048 else if (strncmp(argv[idx_vendor]->arg, "i", 1) == 0)
2049 abr_type = OSPF_ABR_IBM;
2050 else if (strncmp(argv[idx_vendor]->arg, "sh", 2) == 0)
2051 abr_type = OSPF_ABR_SHORTCUT;
2052 else if (strncmp(argv[idx_vendor]->arg, "st", 2) == 0)
2053 abr_type = OSPF_ABR_STAND;
2054 else
2055 return CMD_WARNING_CONFIG_FAILED;
2056
2057 /* If ABR type value is changed, schedule ABR task. */
2058 if (ospf->abr_type != abr_type) {
2059 ospf->abr_type = abr_type;
2060 ospf_schedule_abr_task(ospf);
2061 }
2062
2063 return CMD_SUCCESS;
2064 }
2065
2066 DEFUN (no_ospf_abr_type,
2067 no_ospf_abr_type_cmd,
2068 "no ospf abr-type <cisco|ibm|shortcut|standard>",
2069 NO_STR
2070 "OSPF specific commands\n"
2071 "Set OSPF ABR type\n"
2072 "Alternative ABR, cisco implementation\n"
2073 "Alternative ABR, IBM implementation\n"
2074 "Shortcut ABR\n"
2075 "Standard ABR\n")
2076 {
2077 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2078 int idx_vendor = 3;
2079 uint8_t abr_type = OSPF_ABR_UNKNOWN;
2080
2081 if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0)
2082 abr_type = OSPF_ABR_CISCO;
2083 else if (strncmp(argv[idx_vendor]->arg, "i", 1) == 0)
2084 abr_type = OSPF_ABR_IBM;
2085 else if (strncmp(argv[idx_vendor]->arg, "sh", 2) == 0)
2086 abr_type = OSPF_ABR_SHORTCUT;
2087 else if (strncmp(argv[idx_vendor]->arg, "st", 2) == 0)
2088 abr_type = OSPF_ABR_STAND;
2089 else
2090 return CMD_WARNING_CONFIG_FAILED;
2091
2092 /* If ABR type value is changed, schedule ABR task. */
2093 if (ospf->abr_type == abr_type) {
2094 ospf->abr_type = OSPF_ABR_DEFAULT;
2095 ospf_schedule_abr_task(ospf);
2096 }
2097
2098 return CMD_SUCCESS;
2099 }
2100
2101 DEFUN (ospf_log_adjacency_changes,
2102 ospf_log_adjacency_changes_cmd,
2103 "log-adjacency-changes",
2104 "Log changes in adjacency state\n")
2105 {
2106 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2107
2108 SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES);
2109 UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL);
2110 return CMD_SUCCESS;
2111 }
2112
2113 DEFUN (ospf_log_adjacency_changes_detail,
2114 ospf_log_adjacency_changes_detail_cmd,
2115 "log-adjacency-changes detail",
2116 "Log changes in adjacency state\n"
2117 "Log all state changes\n")
2118 {
2119 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2120
2121 SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES);
2122 SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL);
2123 return CMD_SUCCESS;
2124 }
2125
2126 DEFUN (no_ospf_log_adjacency_changes,
2127 no_ospf_log_adjacency_changes_cmd,
2128 "no log-adjacency-changes",
2129 NO_STR
2130 "Log changes in adjacency state\n")
2131 {
2132 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2133
2134 UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL);
2135 UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES);
2136 return CMD_SUCCESS;
2137 }
2138
2139 DEFUN (no_ospf_log_adjacency_changes_detail,
2140 no_ospf_log_adjacency_changes_detail_cmd,
2141 "no log-adjacency-changes detail",
2142 NO_STR
2143 "Log changes in adjacency state\n"
2144 "Log all state changes\n")
2145 {
2146 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2147
2148 UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL);
2149 return CMD_SUCCESS;
2150 }
2151
2152 DEFUN (ospf_compatible_rfc1583,
2153 ospf_compatible_rfc1583_cmd,
2154 "compatible rfc1583",
2155 "OSPF compatibility list\n"
2156 "compatible with RFC 1583\n")
2157 {
2158 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2159
2160 if (!CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) {
2161 SET_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE);
2162 ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE);
2163 }
2164 return CMD_SUCCESS;
2165 }
2166
2167 DEFUN (no_ospf_compatible_rfc1583,
2168 no_ospf_compatible_rfc1583_cmd,
2169 "no compatible rfc1583",
2170 NO_STR
2171 "OSPF compatibility list\n"
2172 "compatible with RFC 1583\n")
2173 {
2174 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2175
2176 if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) {
2177 UNSET_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE);
2178 ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE);
2179 }
2180 return CMD_SUCCESS;
2181 }
2182
2183 ALIAS(ospf_compatible_rfc1583, ospf_rfc1583_flag_cmd,
2184 "ospf rfc1583compatibility",
2185 "OSPF specific commands\n"
2186 "Enable the RFC1583Compatibility flag\n")
2187
2188 ALIAS(no_ospf_compatible_rfc1583, no_ospf_rfc1583_flag_cmd,
2189 "no ospf rfc1583compatibility", NO_STR
2190 "OSPF specific commands\n"
2191 "Disable the RFC1583Compatibility flag\n")
2192
2193 static void ospf_table_reinstall_routes(struct ospf *ospf,
2194 struct route_table *rt)
2195 {
2196 struct route_node *rn;
2197
2198 if (!rt)
2199 return;
2200
2201 for (rn = route_top(rt); rn; rn = route_next(rn)) {
2202 struct ospf_route *or;
2203
2204 or = rn->info;
2205 if (!or)
2206 continue;
2207
2208 if (or->type == OSPF_DESTINATION_NETWORK)
2209 ospf_zebra_add(ospf, (struct prefix_ipv4 *)&rn->p, or);
2210 else if (or->type == OSPF_DESTINATION_DISCARD)
2211 ospf_zebra_add_discard(ospf,
2212 (struct prefix_ipv4 *)&rn->p);
2213 }
2214 }
2215
2216 static void ospf_reinstall_routes(struct ospf *ospf)
2217 {
2218 ospf_table_reinstall_routes(ospf, ospf->new_table);
2219 ospf_table_reinstall_routes(ospf, ospf->new_external_route);
2220 }
2221
2222 DEFPY (ospf_send_extra_data,
2223 ospf_send_extra_data_cmd,
2224 "[no] ospf send-extra-data zebra",
2225 NO_STR
2226 OSPF_STR
2227 "Extra data to Zebra for display/use\n"
2228 "To zebra\n")
2229 {
2230 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2231
2232 if (no && CHECK_FLAG(ospf->config, OSPF_SEND_EXTRA_DATA_TO_ZEBRA)) {
2233 UNSET_FLAG(ospf->config, OSPF_SEND_EXTRA_DATA_TO_ZEBRA);
2234 ospf_reinstall_routes(ospf);
2235 } else if (!CHECK_FLAG(ospf->config, OSPF_SEND_EXTRA_DATA_TO_ZEBRA)) {
2236 SET_FLAG(ospf->config, OSPF_SEND_EXTRA_DATA_TO_ZEBRA);
2237 ospf_reinstall_routes(ospf);
2238 }
2239
2240 return CMD_SUCCESS;
2241 }
2242
2243 static int ospf_timers_spf_set(struct vty *vty, unsigned int delay,
2244 unsigned int hold, unsigned int max)
2245 {
2246 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2247
2248 ospf->spf_delay = delay;
2249 ospf->spf_holdtime = hold;
2250 ospf->spf_max_holdtime = max;
2251
2252 return CMD_SUCCESS;
2253 }
2254
2255 DEFUN (ospf_timers_min_ls_interval,
2256 ospf_timers_min_ls_interval_cmd,
2257 "timers throttle lsa all (0-5000)",
2258 "Adjust routing timers\n"
2259 "Throttling adaptive timer\n"
2260 "LSA delay between transmissions\n"
2261 "All LSA types\n"
2262 "Delay (msec) between sending LSAs\n")
2263 {
2264 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2265 int idx_number = 4;
2266 unsigned int interval;
2267
2268 if (argc < 5) {
2269 vty_out(vty, "Insufficient arguments\n");
2270 return CMD_WARNING_CONFIG_FAILED;
2271 }
2272
2273 interval = strtoul(argv[idx_number]->arg, NULL, 10);
2274
2275 ospf->min_ls_interval = interval;
2276
2277 return CMD_SUCCESS;
2278 }
2279
2280 DEFUN (no_ospf_timers_min_ls_interval,
2281 no_ospf_timers_min_ls_interval_cmd,
2282 "no timers throttle lsa all [(0-5000)]",
2283 NO_STR
2284 "Adjust routing timers\n"
2285 "Throttling adaptive timer\n"
2286 "LSA delay between transmissions\n"
2287 "All LSA types\n"
2288 "Delay (msec) between sending LSAs\n")
2289 {
2290 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2291 ospf->min_ls_interval = OSPF_MIN_LS_INTERVAL;
2292
2293 return CMD_SUCCESS;
2294 }
2295
2296 DEFUN (ospf_timers_throttle_spf,
2297 ospf_timers_throttle_spf_cmd,
2298 "timers throttle spf (0-600000) (0-600000) (0-600000)",
2299 "Adjust routing timers\n"
2300 "Throttling adaptive timer\n"
2301 "OSPF SPF timers\n"
2302 "Delay (msec) from first change received till SPF calculation\n"
2303 "Initial hold time (msec) between consecutive SPF calculations\n"
2304 "Maximum hold time (msec)\n")
2305 {
2306 int idx_number = 3;
2307 int idx_number_2 = 4;
2308 int idx_number_3 = 5;
2309 unsigned int delay, hold, max;
2310
2311 if (argc < 6) {
2312 vty_out(vty, "Insufficient arguments\n");
2313 return CMD_WARNING_CONFIG_FAILED;
2314 }
2315
2316 delay = strtoul(argv[idx_number]->arg, NULL, 10);
2317 hold = strtoul(argv[idx_number_2]->arg, NULL, 10);
2318 max = strtoul(argv[idx_number_3]->arg, NULL, 10);
2319
2320 return ospf_timers_spf_set(vty, delay, hold, max);
2321 }
2322
2323 DEFUN (no_ospf_timers_throttle_spf,
2324 no_ospf_timers_throttle_spf_cmd,
2325 "no timers throttle spf [(0-600000)(0-600000)(0-600000)]",
2326 NO_STR
2327 "Adjust routing timers\n"
2328 "Throttling adaptive timer\n"
2329 "OSPF SPF timers\n"
2330 "Delay (msec) from first change received till SPF calculation\n"
2331 "Initial hold time (msec) between consecutive SPF calculations\n"
2332 "Maximum hold time (msec)\n")
2333 {
2334 return ospf_timers_spf_set(vty, OSPF_SPF_DELAY_DEFAULT,
2335 OSPF_SPF_HOLDTIME_DEFAULT,
2336 OSPF_SPF_MAX_HOLDTIME_DEFAULT);
2337 }
2338
2339
2340 DEFUN (ospf_timers_lsa_min_arrival,
2341 ospf_timers_lsa_min_arrival_cmd,
2342 "timers lsa min-arrival (0-600000)",
2343 "Adjust routing timers\n"
2344 "OSPF LSA timers\n"
2345 "Minimum delay in receiving new version of a LSA\n"
2346 "Delay in milliseconds\n")
2347 {
2348 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2349 ospf->min_ls_arrival = strtoul(argv[argc - 1]->arg, NULL, 10);
2350 return CMD_SUCCESS;
2351 }
2352
2353 DEFUN (no_ospf_timers_lsa_min_arrival,
2354 no_ospf_timers_lsa_min_arrival_cmd,
2355 "no timers lsa min-arrival [(0-600000)]",
2356 NO_STR
2357 "Adjust routing timers\n"
2358 "OSPF LSA timers\n"
2359 "Minimum delay in receiving new version of a LSA\n"
2360 "Delay in milliseconds\n")
2361 {
2362 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2363 unsigned int minarrival;
2364
2365 if (argc > 4) {
2366 minarrival = strtoul(argv[argc - 1]->arg, NULL, 10);
2367
2368 if (ospf->min_ls_arrival != minarrival
2369 || minarrival == OSPF_MIN_LS_ARRIVAL)
2370 return CMD_SUCCESS;
2371 }
2372
2373 ospf->min_ls_arrival = OSPF_MIN_LS_ARRIVAL;
2374
2375 return CMD_SUCCESS;
2376 }
2377
2378 DEFUN (ospf_neighbor,
2379 ospf_neighbor_cmd,
2380 "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]",
2381 NEIGHBOR_STR
2382 "Neighbor IP address\n"
2383 "Neighbor Priority\n"
2384 "Priority\n"
2385 "Dead Neighbor Polling interval\n"
2386 "Seconds\n")
2387 {
2388 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2389 int idx_ipv4 = 1;
2390 int idx_pri = 3;
2391 int idx_poll = 5;
2392 struct in_addr nbr_addr;
2393 unsigned int priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT;
2394 unsigned int interval = OSPF_POLL_INTERVAL_DEFAULT;
2395
2396 if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) {
2397 vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n");
2398 return CMD_WARNING_CONFIG_FAILED;
2399 }
2400
2401 if (argc > 2)
2402 priority = strtoul(argv[idx_pri]->arg, NULL, 10);
2403
2404 if (argc > 4)
2405 interval = strtoul(argv[idx_poll]->arg, NULL, 10);
2406
2407 ospf_nbr_nbma_set(ospf, nbr_addr);
2408
2409 if (argc > 2)
2410 ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority);
2411
2412 if (argc > 4)
2413 ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval);
2414
2415 return CMD_SUCCESS;
2416 }
2417
2418 DEFUN (ospf_neighbor_poll_interval,
2419 ospf_neighbor_poll_interval_cmd,
2420 "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2421 NEIGHBOR_STR
2422 "Neighbor IP address\n"
2423 "Dead Neighbor Polling interval\n"
2424 "Seconds\n"
2425 "OSPF priority of non-broadcast neighbor\n"
2426 "Priority\n")
2427 {
2428 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2429 int idx_ipv4 = 1;
2430 int idx_poll = 3;
2431 int idx_pri = 5;
2432 struct in_addr nbr_addr;
2433 unsigned int priority;
2434 unsigned int interval;
2435
2436 if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) {
2437 vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n");
2438 return CMD_WARNING_CONFIG_FAILED;
2439 }
2440
2441 interval = strtoul(argv[idx_poll]->arg, NULL, 10);
2442
2443 priority = argc > 4 ? strtoul(argv[idx_pri]->arg, NULL, 10)
2444 : OSPF_NEIGHBOR_PRIORITY_DEFAULT;
2445
2446 ospf_nbr_nbma_set(ospf, nbr_addr);
2447 ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval);
2448
2449 if (argc > 4)
2450 ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority);
2451
2452 return CMD_SUCCESS;
2453 }
2454
2455 DEFUN (no_ospf_neighbor,
2456 no_ospf_neighbor_cmd,
2457 "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]",
2458 NO_STR
2459 NEIGHBOR_STR
2460 "Neighbor IP address\n"
2461 "Neighbor Priority\n"
2462 "Priority\n"
2463 "Dead Neighbor Polling interval\n"
2464 "Seconds\n")
2465 {
2466 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2467 int idx_ipv4 = 2;
2468 struct in_addr nbr_addr;
2469
2470 if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) {
2471 vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n");
2472 return CMD_WARNING_CONFIG_FAILED;
2473 }
2474
2475 (void)ospf_nbr_nbma_unset(ospf, nbr_addr);
2476
2477 return CMD_SUCCESS;
2478 }
2479
2480 DEFUN (no_ospf_neighbor_poll,
2481 no_ospf_neighbor_poll_cmd,
2482 "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2483 NO_STR
2484 NEIGHBOR_STR
2485 "Neighbor IP address\n"
2486 "Dead Neighbor Polling interval\n"
2487 "Seconds\n"
2488 "Neighbor Priority\n"
2489 "Priority\n")
2490 {
2491 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2492 int idx_ipv4 = 2;
2493 struct in_addr nbr_addr;
2494
2495 if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) {
2496 vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n");
2497 return CMD_WARNING_CONFIG_FAILED;
2498 }
2499
2500 (void)ospf_nbr_nbma_unset(ospf, nbr_addr);
2501
2502 return CMD_SUCCESS;
2503 }
2504
2505 DEFUN (ospf_refresh_timer,
2506 ospf_refresh_timer_cmd,
2507 "refresh timer (10-1800)",
2508 "Adjust refresh parameters\n"
2509 "Set refresh timer\n"
2510 "Timer value in seconds\n")
2511 {
2512 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2513 int idx_number = 2;
2514 unsigned int interval;
2515
2516 interval = strtoul(argv[idx_number]->arg, NULL, 10);
2517 interval = (interval / OSPF_LSA_REFRESHER_GRANULARITY)
2518 * OSPF_LSA_REFRESHER_GRANULARITY;
2519
2520 ospf_timers_refresh_set(ospf, interval);
2521
2522 return CMD_SUCCESS;
2523 }
2524
2525 DEFUN (no_ospf_refresh_timer,
2526 no_ospf_refresh_timer_val_cmd,
2527 "no refresh timer [(10-1800)]",
2528 NO_STR
2529 "Adjust refresh parameters\n"
2530 "Unset refresh timer\n"
2531 "Timer value in seconds\n")
2532 {
2533 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2534 int idx_number = 3;
2535 unsigned int interval;
2536
2537 if (argc == 1) {
2538 interval = strtoul(argv[idx_number]->arg, NULL, 10);
2539
2540 if (ospf->lsa_refresh_interval != interval
2541 || interval == OSPF_LSA_REFRESH_INTERVAL_DEFAULT)
2542 return CMD_SUCCESS;
2543 }
2544
2545 ospf_timers_refresh_unset(ospf);
2546
2547 return CMD_SUCCESS;
2548 }
2549
2550
2551 DEFUN (ospf_auto_cost_reference_bandwidth,
2552 ospf_auto_cost_reference_bandwidth_cmd,
2553 "auto-cost reference-bandwidth (1-4294967)",
2554 "Calculate OSPF interface cost according to bandwidth\n"
2555 "Use reference bandwidth method to assign OSPF cost\n"
2556 "The reference bandwidth in terms of Mbits per second\n")
2557 {
2558 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2559 struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id);
2560 int idx_number = 2;
2561 uint32_t refbw;
2562 struct interface *ifp;
2563
2564 refbw = strtol(argv[idx_number]->arg, NULL, 10);
2565 if (refbw < 1 || refbw > 4294967) {
2566 vty_out(vty, "reference-bandwidth value is invalid\n");
2567 return CMD_WARNING_CONFIG_FAILED;
2568 }
2569
2570 /* If reference bandwidth is changed. */
2571 if ((refbw) == ospf->ref_bandwidth)
2572 return CMD_SUCCESS;
2573
2574 ospf->ref_bandwidth = refbw;
2575 FOR_ALL_INTERFACES (vrf, ifp)
2576 ospf_if_recalculate_output_cost(ifp);
2577
2578 return CMD_SUCCESS;
2579 }
2580
2581 DEFUN (no_ospf_auto_cost_reference_bandwidth,
2582 no_ospf_auto_cost_reference_bandwidth_cmd,
2583 "no auto-cost reference-bandwidth [(1-4294967)]",
2584 NO_STR
2585 "Calculate OSPF interface cost according to bandwidth\n"
2586 "Use reference bandwidth method to assign OSPF cost\n"
2587 "The reference bandwidth in terms of Mbits per second\n")
2588 {
2589 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2590 struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id);
2591 struct interface *ifp;
2592
2593 if (ospf->ref_bandwidth == OSPF_DEFAULT_REF_BANDWIDTH)
2594 return CMD_SUCCESS;
2595
2596 ospf->ref_bandwidth = OSPF_DEFAULT_REF_BANDWIDTH;
2597 vty_out(vty, "%% OSPF: Reference bandwidth is changed.\n");
2598 vty_out(vty,
2599 " Please ensure reference bandwidth is consistent across all routers\n");
2600
2601 FOR_ALL_INTERFACES (vrf, ifp)
2602 ospf_if_recalculate_output_cost(ifp);
2603
2604 return CMD_SUCCESS;
2605 }
2606
2607 DEFUN (ospf_write_multiplier,
2608 ospf_write_multiplier_cmd,
2609 "ospf write-multiplier (1-100)",
2610 "OSPF specific commands\n"
2611 "Write multiplier\n"
2612 "Maximum number of interface serviced per write\n")
2613 {
2614 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2615 int idx_number;
2616 uint32_t write_oi_count;
2617
2618 if (argc == 3)
2619 idx_number = 2;
2620 else
2621 idx_number = 1;
2622
2623 write_oi_count = strtol(argv[idx_number]->arg, NULL, 10);
2624 if (write_oi_count < 1 || write_oi_count > 100) {
2625 vty_out(vty, "write-multiplier value is invalid\n");
2626 return CMD_WARNING_CONFIG_FAILED;
2627 }
2628
2629 ospf->write_oi_count = write_oi_count;
2630 return CMD_SUCCESS;
2631 }
2632
2633 ALIAS(ospf_write_multiplier, write_multiplier_cmd, "write-multiplier (1-100)",
2634 "Write multiplier\n"
2635 "Maximum number of interface serviced per write\n")
2636
2637 DEFUN (no_ospf_write_multiplier,
2638 no_ospf_write_multiplier_cmd,
2639 "no ospf write-multiplier (1-100)",
2640 NO_STR
2641 "OSPF specific commands\n"
2642 "Write multiplier\n"
2643 "Maximum number of interface serviced per write\n")
2644 {
2645 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2646
2647 ospf->write_oi_count = OSPF_WRITE_INTERFACE_COUNT_DEFAULT;
2648 return CMD_SUCCESS;
2649 }
2650
2651 ALIAS(no_ospf_write_multiplier, no_write_multiplier_cmd,
2652 "no write-multiplier (1-100)", NO_STR
2653 "Write multiplier\n"
2654 "Maximum number of interface serviced per write\n")
2655
2656 DEFUN(ospf_ti_lfa, ospf_ti_lfa_cmd, "fast-reroute ti-lfa [node-protection]",
2657 "Fast Reroute for MPLS and IP resilience\n"
2658 "Topology Independent LFA (Loop-Free Alternate)\n"
2659 "TI-LFA node protection (default is link protection)\n")
2660 {
2661 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2662
2663 ospf->ti_lfa_enabled = true;
2664
2665 if (argc == 3)
2666 ospf->ti_lfa_protection_type = OSPF_TI_LFA_NODE_PROTECTION;
2667 else
2668 ospf->ti_lfa_protection_type = OSPF_TI_LFA_LINK_PROTECTION;
2669
2670 ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE);
2671
2672 return CMD_SUCCESS;
2673 }
2674
2675 DEFUN(no_ospf_ti_lfa, no_ospf_ti_lfa_cmd,
2676 "no fast-reroute ti-lfa [node-protection]",
2677 NO_STR
2678 "Fast Reroute for MPLS and IP resilience\n"
2679 "Topology Independent LFA (Loop-Free Alternate)\n"
2680 "TI-LFA node protection (default is link protection)\n")
2681 {
2682 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2683
2684 ospf->ti_lfa_enabled = false;
2685
2686 ospf->ti_lfa_protection_type = OSPF_TI_LFA_UNDEFINED_PROTECTION;
2687
2688 ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE);
2689
2690 return CMD_SUCCESS;
2691 }
2692
2693 static void ospf_maxpath_set(struct vty *vty, struct ospf *ospf, uint16_t paths)
2694 {
2695 if (ospf->max_multipath == paths)
2696 return;
2697
2698 ospf->max_multipath = paths;
2699
2700 /* Send deletion notification to zebra to delete all
2701 * ospf specific routes and reinitiat SPF to reflect
2702 * the new max multipath.
2703 */
2704 ospf_restart_spf(ospf);
2705 }
2706
2707 /* Ospf Maximum multiple paths config support */
2708 DEFUN (ospf_max_multipath,
2709 ospf_max_multipath_cmd,
2710 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2711 "Max no of multiple paths for ECMP support\n"
2712 "Number of paths\n")
2713 {
2714 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2715 int idx_number = 1;
2716 uint16_t maxpaths;
2717
2718 maxpaths = strtol(argv[idx_number]->arg, NULL, 10);
2719
2720 ospf_maxpath_set(vty, ospf, maxpaths);
2721 return CMD_SUCCESS;
2722 }
2723
2724 DEFUN (no_ospf_max_multipath,
2725 no_ospf_max_multipath_cmd,
2726 "no maximum-paths",
2727 NO_STR
2728 "Max no of multiple paths for ECMP support\n")
2729 {
2730 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2731 uint16_t maxpaths = MULTIPATH_NUM;
2732
2733 ospf_maxpath_set(vty, ospf, maxpaths);
2734 return CMD_SUCCESS;
2735 }
2736
2737 static const char *const ospf_abr_type_descr_str[] = {
2738 "Unknown", "Standard (RFC2328)", "Alternative IBM",
2739 "Alternative Cisco", "Alternative Shortcut"
2740 };
2741
2742 static const char *const ospf_shortcut_mode_descr_str[] = {
2743 "Default", "Enabled", "Disabled"
2744 };
2745
2746 static void show_ip_ospf_area(struct vty *vty, struct ospf_area *area,
2747 json_object *json_areas, bool use_json)
2748 {
2749 json_object *json_area = NULL;
2750 char buf[PREFIX_STRLEN];
2751
2752 if (use_json)
2753 json_area = json_object_new_object();
2754
2755 /* Show Area ID. */
2756 if (!use_json)
2757 vty_out(vty, " Area ID: %pI4", &area->area_id);
2758
2759 /* Show Area type/mode. */
2760 if (OSPF_IS_AREA_BACKBONE(area)) {
2761 if (use_json)
2762 json_object_boolean_true_add(json_area, "backbone");
2763 else
2764 vty_out(vty, " (Backbone)\n");
2765 } else {
2766 if (use_json) {
2767 if (area->external_routing == OSPF_AREA_STUB) {
2768 if (area->no_summary)
2769 json_object_boolean_true_add(
2770 json_area, "stubNoSummary");
2771 if (area->shortcut_configured)
2772 json_object_boolean_true_add(
2773 json_area, "stubShortcut");
2774 } else if (area->external_routing == OSPF_AREA_NSSA) {
2775 if (area->no_summary)
2776 json_object_boolean_true_add(
2777 json_area, "nssaNoSummary");
2778 if (area->shortcut_configured)
2779 json_object_boolean_true_add(
2780 json_area, "nssaShortcut");
2781 }
2782
2783 json_object_string_add(
2784 json_area, "shortcuttingMode",
2785 ospf_shortcut_mode_descr_str
2786 [area->shortcut_configured]);
2787 if (area->shortcut_capability)
2788 json_object_boolean_true_add(json_area,
2789 "sBitConcensus");
2790 } else {
2791 if (area->external_routing == OSPF_AREA_STUB)
2792 vty_out(vty, " (Stub%s%s)",
2793 area->no_summary ? ", no summary" : "",
2794 area->shortcut_configured ? "; " : "");
2795 else if (area->external_routing == OSPF_AREA_NSSA)
2796 vty_out(vty, " (NSSA%s%s)",
2797 area->no_summary ? ", no summary" : "",
2798 area->shortcut_configured ? "; " : "");
2799
2800 vty_out(vty, "\n");
2801 vty_out(vty, " Shortcutting mode: %s",
2802 ospf_shortcut_mode_descr_str
2803 [area->shortcut_configured]);
2804 vty_out(vty, ", S-bit consensus: %s\n",
2805 area->shortcut_capability ? "ok" : "no");
2806 }
2807 }
2808
2809 /* Show number of interfaces */
2810 if (use_json) {
2811 json_object_int_add(json_area, "areaIfTotalCounter",
2812 listcount(area->oiflist));
2813 json_object_int_add(json_area, "areaIfActiveCounter",
2814 area->act_ints);
2815 } else
2816 vty_out(vty,
2817 " Number of interfaces in this area: Total: %d, Active: %d\n",
2818 listcount(area->oiflist), area->act_ints);
2819
2820 if (area->external_routing == OSPF_AREA_NSSA) {
2821 if (use_json) {
2822 json_object_boolean_true_add(json_area, "nssa");
2823 if (!IS_OSPF_ABR(area->ospf))
2824 json_object_boolean_false_add(json_area, "abr");
2825 else if (area->NSSATranslatorState) {
2826 json_object_boolean_true_add(json_area, "abr");
2827 if (area->NSSATranslatorRole
2828 == OSPF_NSSA_ROLE_CANDIDATE)
2829 json_object_boolean_true_add(
2830 json_area,
2831 "nssaTranslatorElected");
2832 else if (area->NSSATranslatorRole
2833 == OSPF_NSSA_ROLE_ALWAYS)
2834 json_object_boolean_true_add(
2835 json_area,
2836 "nssaTranslatorAlways");
2837 else
2838 json_object_boolean_true_add(
2839 json_area,
2840 "nssaTranslatorNever");
2841 } else {
2842 json_object_boolean_true_add(json_area, "abr");
2843 if (area->NSSATranslatorRole
2844 == OSPF_NSSA_ROLE_CANDIDATE)
2845 json_object_boolean_false_add(
2846 json_area,
2847 "nssaTranslatorElected");
2848 else
2849 json_object_boolean_true_add(
2850 json_area,
2851 "nssaTranslatorNever");
2852 }
2853 } else {
2854 vty_out(vty,
2855 " It is an NSSA configuration.\n Elected NSSA/ABR performs type-7/type-5 LSA translation.\n");
2856 if (!IS_OSPF_ABR(area->ospf))
2857 vty_out(vty,
2858 " It is not ABR, therefore not Translator.\n");
2859 else if (area->NSSATranslatorState) {
2860 vty_out(vty, " We are an ABR and ");
2861 if (area->NSSATranslatorRole
2862 == OSPF_NSSA_ROLE_CANDIDATE)
2863 vty_out(vty,
2864 "the NSSA Elected Translator.\n");
2865 else if (area->NSSATranslatorRole
2866 == OSPF_NSSA_ROLE_ALWAYS)
2867 vty_out(vty,
2868 "always an NSSA Translator.\n");
2869 else
2870 vty_out(vty,
2871 "never an NSSA Translator.\n");
2872 } else {
2873 vty_out(vty, " We are an ABR, but ");
2874 if (area->NSSATranslatorRole
2875 == OSPF_NSSA_ROLE_CANDIDATE)
2876 vty_out(vty,
2877 "not the NSSA Elected Translator.\n");
2878 else
2879 vty_out(vty,
2880 "never an NSSA Translator.\n");
2881 }
2882 }
2883 }
2884
2885 /* Stub-router state for this area */
2886 if (CHECK_FLAG(area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED)) {
2887 char timebuf[OSPF_TIME_DUMP_SIZE];
2888
2889 if (use_json) {
2890 json_object_boolean_true_add(
2891 json_area, "originStubMaxDistRouterLsa");
2892 if (CHECK_FLAG(area->stub_router_state,
2893 OSPF_AREA_ADMIN_STUB_ROUTED))
2894 json_object_boolean_true_add(
2895 json_area, "indefiniteActiveAdmin");
2896 if (area->t_stub_router) {
2897 long time_store;
2898 time_store =
2899 monotime_until(
2900 &area->t_stub_router->u.sands,
2901 NULL)
2902 / 1000LL;
2903 json_object_int_add(
2904 json_area,
2905 "activeStartupRemainderMsecs",
2906 time_store);
2907 }
2908 } else {
2909 vty_out(vty,
2910 " Originating stub / maximum-distance Router-LSA\n");
2911 if (CHECK_FLAG(area->stub_router_state,
2912 OSPF_AREA_ADMIN_STUB_ROUTED))
2913 vty_out(vty,
2914 " Administratively activated (indefinitely)\n");
2915 if (area->t_stub_router)
2916 vty_out(vty,
2917 " Active from startup, %s remaining\n",
2918 ospf_timer_dump(area->t_stub_router,
2919 timebuf,
2920 sizeof(timebuf)));
2921 }
2922 }
2923
2924 if (use_json) {
2925 /* Show number of fully adjacent neighbors. */
2926 json_object_int_add(json_area, "nbrFullAdjacentCounter",
2927 area->full_nbrs);
2928
2929 /* Show authentication type. */
2930 if (area->auth_type == OSPF_AUTH_NULL)
2931 json_object_string_add(json_area, "authentication",
2932 "authenticationNone");
2933 else if (area->auth_type == OSPF_AUTH_SIMPLE)
2934 json_object_string_add(json_area, "authentication",
2935 "authenticationSimplePassword");
2936 else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC)
2937 json_object_string_add(json_area, "authentication",
2938 "authenticationMessageDigest");
2939
2940 if (!OSPF_IS_AREA_BACKBONE(area))
2941 json_object_int_add(json_area,
2942 "virtualAdjacenciesPassingCounter",
2943 area->full_vls);
2944
2945 /* Show SPF calculation times. */
2946 json_object_int_add(json_area, "spfExecutedCounter",
2947 area->spf_calculation);
2948 json_object_int_add(json_area, "lsaNumber", area->lsdb->total);
2949 json_object_int_add(
2950 json_area, "lsaRouterNumber",
2951 ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA));
2952 json_object_int_add(
2953 json_area, "lsaRouterChecksum",
2954 ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA));
2955 json_object_int_add(
2956 json_area, "lsaNetworkNumber",
2957 ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA));
2958 json_object_int_add(
2959 json_area, "lsaNetworkChecksum",
2960 ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA));
2961 json_object_int_add(
2962 json_area, "lsaSummaryNumber",
2963 ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA));
2964 json_object_int_add(
2965 json_area, "lsaSummaryChecksum",
2966 ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA));
2967 json_object_int_add(
2968 json_area, "lsaAsbrNumber",
2969 ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA));
2970 json_object_int_add(
2971 json_area, "lsaAsbrChecksum",
2972 ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA));
2973 json_object_int_add(
2974 json_area, "lsaNssaNumber",
2975 ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA));
2976 json_object_int_add(
2977 json_area, "lsaNssaChecksum",
2978 ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA));
2979 } else {
2980 /* Show number of fully adjacent neighbors. */
2981 vty_out(vty,
2982 " Number of fully adjacent neighbors in this area: %d\n",
2983 area->full_nbrs);
2984
2985 /* Show authentication type. */
2986 vty_out(vty, " Area has ");
2987 if (area->auth_type == OSPF_AUTH_NULL)
2988 vty_out(vty, "no authentication\n");
2989 else if (area->auth_type == OSPF_AUTH_SIMPLE)
2990 vty_out(vty, "simple password authentication\n");
2991 else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC)
2992 vty_out(vty, "message digest authentication\n");
2993
2994 if (!OSPF_IS_AREA_BACKBONE(area))
2995 vty_out(vty,
2996 " Number of full virtual adjacencies going through this area: %d\n",
2997 area->full_vls);
2998
2999 /* Show SPF calculation times. */
3000 vty_out(vty, " SPF algorithm executed %d times\n",
3001 area->spf_calculation);
3002
3003 /* Show number of LSA. */
3004 vty_out(vty, " Number of LSA %ld\n", area->lsdb->total);
3005 vty_out(vty,
3006 " Number of router LSA %ld. Checksum Sum 0x%08x\n",
3007 ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA),
3008 ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA));
3009 vty_out(vty,
3010 " Number of network LSA %ld. Checksum Sum 0x%08x\n",
3011 ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA),
3012 ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA));
3013 vty_out(vty,
3014 " Number of summary LSA %ld. Checksum Sum 0x%08x\n",
3015 ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA),
3016 ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA));
3017 vty_out(vty,
3018 " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n",
3019 ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA),
3020 ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA));
3021 vty_out(vty, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n",
3022 ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA),
3023 ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA));
3024 }
3025
3026 if (use_json) {
3027 json_object_int_add(
3028 json_area, "lsaOpaqueLinkNumber",
3029 ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA));
3030 json_object_int_add(
3031 json_area, "lsaOpaqueLinkChecksum",
3032 ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA));
3033 json_object_int_add(
3034 json_area, "lsaOpaqueAreaNumber",
3035 ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA));
3036 json_object_int_add(
3037 json_area, "lsaOpaqueAreaChecksum",
3038 ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA));
3039 } else {
3040 vty_out(vty,
3041 " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n",
3042 ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA),
3043 ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA));
3044 vty_out(vty,
3045 " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n",
3046 ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA),
3047 ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA));
3048 }
3049
3050 if (area->fr_info.configured) {
3051 if (use_json)
3052 json_object_string_add(json_area, "areaFloodReduction",
3053 "configured");
3054 else
3055 vty_out(vty, " Flood Reduction is configured.\n");
3056 }
3057
3058 if (area->fr_info.enabled) {
3059 if (use_json) {
3060 json_object_boolean_true_add(
3061 json_area, "areaFloodReductionEnabled");
3062 if (area->fr_info.router_lsas_recv_dc_bit)
3063 json_object_boolean_true_add(
3064 json_area, "lsasRecvDCbitSet");
3065 if (area->fr_info.area_ind_lsa_recvd)
3066 json_object_string_add(json_area,
3067 "areaIndicationLsaRecv",
3068 "received");
3069 if (area->fr_info.indication_lsa_self)
3070 json_object_string_addf(
3071 json_area, "areaIndicationLsa", "%pI4",
3072 &area->fr_info.indication_lsa_self->data
3073 ->id);
3074 } else {
3075 vty_out(vty, " Flood Reduction is enabled.\n");
3076 vty_out(vty, " No of LSAs rcv'd with DC bit set %d\n",
3077 area->fr_info.router_lsas_recv_dc_bit);
3078 if (area->fr_info.area_ind_lsa_recvd)
3079 vty_out(vty, " Ind LSA by other abr.\n");
3080 if (area->fr_info.indication_lsa_self)
3081 vty_out(vty, " Ind LSA generated %pI4\n",
3082 &area->fr_info.indication_lsa_self->data
3083 ->id);
3084 }
3085 }
3086
3087 if (use_json)
3088 json_object_object_add(json_areas,
3089 inet_ntop(AF_INET, &area->area_id,
3090 buf, sizeof(buf)),
3091 json_area);
3092 else
3093 vty_out(vty, "\n");
3094 }
3095
3096 static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf,
3097 json_object *json, uint8_t use_vrf)
3098 {
3099 struct listnode *node, *nnode;
3100 struct ospf_area *area;
3101 struct timeval result;
3102 char timebuf[OSPF_TIME_DUMP_SIZE];
3103 json_object *json_vrf = NULL;
3104 json_object *json_areas = NULL;
3105
3106 if (json) {
3107 if (use_vrf)
3108 json_vrf = json_object_new_object();
3109 else
3110 json_vrf = json;
3111 json_areas = json_object_new_object();
3112 }
3113
3114 if (ospf->instance) {
3115 if (json) {
3116 json_object_int_add(json, "ospfInstance",
3117 ospf->instance);
3118 } else {
3119 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
3120 }
3121 }
3122
3123 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
3124
3125 /* Show Router ID. */
3126 if (json) {
3127 json_object_string_addf(json_vrf, "routerId", "%pI4",
3128 &ospf->router_id);
3129 } else {
3130 vty_out(vty, " OSPF Routing Process, Router ID: %pI4\n",
3131 &ospf->router_id);
3132 }
3133
3134 /* Graceful shutdown */
3135 if (ospf->t_deferred_shutdown) {
3136 if (json) {
3137 long time_store;
3138 time_store =
3139 monotime_until(
3140 &ospf->t_deferred_shutdown->u.sands,
3141 NULL)
3142 / 1000LL;
3143 json_object_int_add(json_vrf, "deferredShutdownMsecs",
3144 time_store);
3145 } else {
3146 vty_out(vty,
3147 " Deferred shutdown in progress, %s remaining\n",
3148 ospf_timer_dump(ospf->t_deferred_shutdown,
3149 timebuf, sizeof(timebuf)));
3150 }
3151 }
3152
3153 /* Show capability. */
3154 if (json) {
3155 json_object_boolean_true_add(json_vrf, "tosRoutesOnly");
3156 json_object_boolean_true_add(json_vrf, "rfc2328Conform");
3157 if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) {
3158 json_object_boolean_true_add(json_vrf,
3159 "rfc1583Compatibility");
3160 }
3161 } else {
3162 vty_out(vty, " Supports only single TOS (TOS0) routes\n");
3163 vty_out(vty, " This implementation conforms to RFC2328\n");
3164 vty_out(vty, " RFC1583Compatibility flag is %s\n",
3165 CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)
3166 ? "enabled"
3167 : "disabled");
3168 }
3169
3170 if (json) {
3171 if (CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE)) {
3172 json_object_boolean_true_add(json_vrf, "opaqueCapable");
3173 }
3174 } else {
3175 vty_out(vty, " OpaqueCapability flag is %s\n",
3176 CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE)
3177 ? "enabled"
3178 : "disabled");
3179 }
3180
3181 /* Show stub-router configuration */
3182 if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED
3183 || ospf->stub_router_shutdown_time
3184 != OSPF_STUB_ROUTER_UNCONFIGURED) {
3185 if (json) {
3186 json_object_boolean_true_add(json_vrf,
3187 "stubAdvertisement");
3188 if (ospf->stub_router_startup_time
3189 != OSPF_STUB_ROUTER_UNCONFIGURED)
3190 json_object_int_add(
3191 json_vrf, "postStartEnabledSecs",
3192 ospf->stub_router_startup_time);
3193 if (ospf->stub_router_shutdown_time
3194 != OSPF_STUB_ROUTER_UNCONFIGURED)
3195 json_object_int_add(
3196 json_vrf, "preShutdownEnabledSecs",
3197 ospf->stub_router_shutdown_time);
3198 } else {
3199 vty_out(vty,
3200 " Stub router advertisement is configured\n");
3201 if (ospf->stub_router_startup_time
3202 != OSPF_STUB_ROUTER_UNCONFIGURED)
3203 vty_out(vty,
3204 " Enabled for %us after start-up\n",
3205 ospf->stub_router_startup_time);
3206 if (ospf->stub_router_shutdown_time
3207 != OSPF_STUB_ROUTER_UNCONFIGURED)
3208 vty_out(vty,
3209 " Enabled for %us prior to full shutdown\n",
3210 ospf->stub_router_shutdown_time);
3211 }
3212 }
3213
3214 /* Show SPF timers. */
3215 if (json) {
3216 json_object_int_add(json_vrf, "spfScheduleDelayMsecs",
3217 ospf->spf_delay);
3218 json_object_int_add(json_vrf, "holdtimeMinMsecs",
3219 ospf->spf_holdtime);
3220 json_object_int_add(json_vrf, "holdtimeMaxMsecs",
3221 ospf->spf_max_holdtime);
3222 json_object_int_add(json_vrf, "holdtimeMultplier",
3223 ospf->spf_hold_multiplier);
3224 } else {
3225 vty_out(vty,
3226 " Initial SPF scheduling delay %d millisec(s)\n"
3227 " Minimum hold time between consecutive SPFs %d millisec(s)\n"
3228 " Maximum hold time between consecutive SPFs %d millisec(s)\n"
3229 " Hold time multiplier is currently %d\n",
3230 ospf->spf_delay, ospf->spf_holdtime,
3231 ospf->spf_max_holdtime, ospf->spf_hold_multiplier);
3232 }
3233
3234 if (json) {
3235 if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) {
3236 long time_store = 0;
3237
3238 time_store =
3239 monotime_since(&ospf->ts_spf, NULL) / 1000LL;
3240 json_object_int_add(json_vrf, "spfLastExecutedMsecs",
3241 time_store);
3242
3243 time_store = (1000 * ospf->ts_spf_duration.tv_sec)
3244 + (ospf->ts_spf_duration.tv_usec / 1000);
3245 json_object_int_add(json_vrf, "spfLastDurationMsecs",
3246 time_store);
3247 } else
3248 json_object_boolean_true_add(json_vrf, "spfHasNotRun");
3249 } else {
3250 vty_out(vty, " SPF algorithm ");
3251 if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) {
3252 monotime_since(&ospf->ts_spf, &result);
3253 vty_out(vty, "last executed %s ago\n",
3254 ospf_timeval_dump(&result, timebuf,
3255 sizeof(timebuf)));
3256 vty_out(vty, " Last SPF duration %s\n",
3257 ospf_timeval_dump(&ospf->ts_spf_duration,
3258 timebuf, sizeof(timebuf)));
3259 } else
3260 vty_out(vty, "has not been run\n");
3261 }
3262
3263 if (json) {
3264 if (ospf->t_spf_calc) {
3265 long time_store;
3266 time_store =
3267 monotime_until(&ospf->t_spf_calc->u.sands, NULL)
3268 / 1000LL;
3269 json_object_int_add(json_vrf, "spfTimerDueInMsecs",
3270 time_store);
3271 }
3272
3273 json_object_int_add(json_vrf, "lsaMinIntervalMsecs",
3274 ospf->min_ls_interval);
3275 json_object_int_add(json_vrf, "lsaMinArrivalMsecs",
3276 ospf->min_ls_arrival);
3277 /* Show write multiplier values */
3278 json_object_int_add(json_vrf, "writeMultiplier",
3279 ospf->write_oi_count);
3280 /* Show refresh parameters. */
3281 json_object_int_add(json_vrf, "refreshTimerMsecs",
3282 ospf->lsa_refresh_interval * 1000);
3283
3284 /* show max multipath */
3285 json_object_int_add(json_vrf, "maximumPaths",
3286 ospf->max_multipath);
3287
3288 /* show administrative distance */
3289 json_object_int_add(json_vrf, "preference",
3290 ospf->distance_all
3291 ? ospf->distance_all
3292 : ZEBRA_OSPF_DISTANCE_DEFAULT);
3293 } else {
3294 vty_out(vty, " SPF timer %s%s\n",
3295 (ospf->t_spf_calc ? "due in " : "is "),
3296 ospf_timer_dump(ospf->t_spf_calc, timebuf,
3297 sizeof(timebuf)));
3298
3299 vty_out(vty, " LSA minimum interval %d msecs\n",
3300 ospf->min_ls_interval);
3301 vty_out(vty, " LSA minimum arrival %d msecs\n",
3302 ospf->min_ls_arrival);
3303
3304 /* Show write multiplier values */
3305 vty_out(vty, " Write Multiplier set to %d \n",
3306 ospf->write_oi_count);
3307
3308 /* Show refresh parameters. */
3309 vty_out(vty, " Refresh timer %d secs\n",
3310 ospf->lsa_refresh_interval);
3311
3312 /* show max multipath */
3313 vty_out(vty, " Maximum multiple paths(ECMP) supported %d\n",
3314 ospf->max_multipath);
3315
3316 /* show administrative distance */
3317 vty_out(vty, " Administrative distance %u\n",
3318 ospf->distance_all ? ospf->distance_all
3319 : ZEBRA_OSPF_DISTANCE_DEFAULT);
3320 }
3321
3322 if (ospf->fr_configured) {
3323 if (json)
3324 json_object_string_add(json_vrf, "floodReduction",
3325 "configured");
3326 else
3327 vty_out(vty, " Flood Reduction is configured.\n");
3328 }
3329
3330 /* Show ABR/ASBR flags. */
3331 if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ABR)) {
3332 if (json)
3333 json_object_string_add(
3334 json_vrf, "abrType",
3335 ospf_abr_type_descr_str[ospf->abr_type]);
3336 else
3337 vty_out(vty,
3338 " This router is an ABR, ABR type is: %s\n",
3339 ospf_abr_type_descr_str[ospf->abr_type]);
3340 }
3341 if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ASBR)) {
3342 if (json)
3343 json_object_string_add(
3344 json_vrf, "asbrRouter",
3345 "injectingExternalRoutingInformation");
3346 else
3347 vty_out(vty,
3348 " This router is an ASBR (injecting external routing information)\n");
3349 }
3350
3351 /* Show Number of AS-external-LSAs. */
3352 if (json) {
3353 json_object_int_add(
3354 json_vrf, "lsaExternalCounter",
3355 ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA));
3356 json_object_int_add(
3357 json_vrf, "lsaExternalChecksum",
3358 ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA));
3359 } else {
3360 vty_out(vty,
3361 " Number of external LSA %ld. Checksum Sum 0x%08x\n",
3362 ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA),
3363 ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA));
3364 }
3365
3366 if (json) {
3367 json_object_int_add(
3368 json_vrf, "lsaAsopaqueCounter",
3369 ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA));
3370 json_object_int_add(
3371 json_vrf, "lsaAsOpaqueChecksum",
3372 ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA));
3373 } else {
3374 vty_out(vty,
3375 " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n",
3376 ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA),
3377 ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA));
3378 }
3379
3380 /* Show number of areas attached. */
3381 if (json)
3382 json_object_int_add(json_vrf, "attachedAreaCounter",
3383 listcount(ospf->areas));
3384 else
3385 vty_out(vty, " Number of areas attached to this router: %d\n",
3386 listcount(ospf->areas));
3387
3388 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) {
3389 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) {
3390 if (json)
3391 json_object_boolean_true_add(
3392 json_vrf, "adjacencyChangesLoggedAll");
3393 else
3394 vty_out(vty,
3395 " All adjacency changes are logged\n");
3396 } else {
3397 if (json)
3398 json_object_boolean_true_add(
3399 json_vrf, "adjacencyChangesLogged");
3400 else
3401 vty_out(vty, " Adjacency changes are logged\n");
3402 }
3403 }
3404
3405 /* show LDP-Sync status */
3406 ospf_ldp_sync_show_info(vty, ospf, json_vrf, json ? 1 : 0);
3407
3408 /* Socket buffer sizes */
3409 if (json) {
3410 if (ospf->recv_sock_bufsize != OSPF_DEFAULT_SOCK_BUFSIZE)
3411 json_object_int_add(json_vrf, "recvSockBufsize",
3412 ospf->recv_sock_bufsize);
3413 if (ospf->send_sock_bufsize != OSPF_DEFAULT_SOCK_BUFSIZE)
3414 json_object_int_add(json_vrf, "sendSockBufsize",
3415 ospf->send_sock_bufsize);
3416 } else {
3417 if (ospf->recv_sock_bufsize != OSPF_DEFAULT_SOCK_BUFSIZE)
3418 vty_out(vty, " Receive socket bufsize: %u\n",
3419 ospf->recv_sock_bufsize);
3420 if (ospf->send_sock_bufsize != OSPF_DEFAULT_SOCK_BUFSIZE)
3421 vty_out(vty, " Send socket bufsize: %u\n",
3422 ospf->send_sock_bufsize);
3423 }
3424
3425 /* Show each area status. */
3426 for (ALL_LIST_ELEMENTS(ospf->areas, node, nnode, area))
3427 show_ip_ospf_area(vty, area, json_areas, json ? 1 : 0);
3428
3429 if (json) {
3430 if (use_vrf) {
3431 json_object_object_add(json_vrf, "areas", json_areas);
3432 json_object_object_add(json, ospf_get_name(ospf),
3433 json_vrf);
3434 } else {
3435 json_object_object_add(json, "areas", json_areas);
3436 }
3437 } else
3438 vty_out(vty, "\n");
3439
3440 return CMD_SUCCESS;
3441 }
3442
3443 DEFUN (show_ip_ospf,
3444 show_ip_ospf_cmd,
3445 "show ip ospf [vrf <NAME|all>] [json]",
3446 SHOW_STR
3447 IP_STR
3448 "OSPF information\n"
3449 VRF_CMD_HELP_STR
3450 "All VRFs\n"
3451 JSON_STR)
3452 {
3453 struct ospf *ospf;
3454 bool uj = use_json(argc, argv);
3455 struct listnode *node = NULL;
3456 char *vrf_name = NULL;
3457 bool all_vrf = false;
3458 int ret = CMD_SUCCESS;
3459 int inst = 0;
3460 int idx_vrf = 0;
3461 json_object *json = NULL;
3462 uint8_t use_vrf = 0;
3463
3464 if (listcount(om->ospf) == 0)
3465 return CMD_SUCCESS;
3466
3467 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
3468
3469 if (uj)
3470 json = json_object_new_object();
3471
3472 /* vrf input is provided could be all or specific vrf*/
3473 if (vrf_name) {
3474 bool ospf_output = false;
3475
3476 use_vrf = 1;
3477
3478 if (all_vrf) {
3479 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
3480 if (!ospf->oi_running)
3481 continue;
3482 ospf_output = true;
3483 ret = show_ip_ospf_common(vty, ospf, json,
3484 use_vrf);
3485 }
3486 if (uj)
3487 vty_json(vty, json);
3488 else if (!ospf_output)
3489 vty_out(vty, "%% OSPF is not enabled\n");
3490 return ret;
3491 }
3492 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
3493 if ((ospf == NULL) || !ospf->oi_running) {
3494 if (uj)
3495 vty_json(vty, json);
3496 else
3497 vty_out(vty,
3498 "%% OSPF is not enabled in vrf %s\n",
3499 vrf_name);
3500
3501 return CMD_SUCCESS;
3502 }
3503 } else {
3504 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
3505 /* Display default ospf (instance 0) info */
3506 if (ospf == NULL || !ospf->oi_running) {
3507 if (uj)
3508 vty_json(vty, json);
3509 else
3510 vty_out(vty,
3511 "%% OSPF is not enabled in vrf default\n");
3512
3513 return CMD_SUCCESS;
3514 }
3515 }
3516
3517 if (ospf) {
3518 show_ip_ospf_common(vty, ospf, json, use_vrf);
3519 if (uj)
3520 vty_out(vty, "%s\n",
3521 json_object_to_json_string_ext(
3522 json, JSON_C_TO_STRING_PRETTY));
3523 }
3524
3525 if (uj)
3526 json_object_free(json);
3527
3528 return ret;
3529 }
3530
3531 DEFUN (show_ip_ospf_instance,
3532 show_ip_ospf_instance_cmd,
3533 "show ip ospf (1-65535) [json]",
3534 SHOW_STR
3535 IP_STR
3536 "OSPF information\n"
3537 "Instance ID\n"
3538 JSON_STR)
3539 {
3540 int idx_number = 3;
3541 struct ospf *ospf;
3542 unsigned short instance = 0;
3543 bool uj = use_json(argc, argv);
3544 int ret = CMD_SUCCESS;
3545 json_object *json = NULL;
3546
3547 instance = strtoul(argv[idx_number]->arg, NULL, 10);
3548 if (instance != ospf_instance)
3549 return CMD_NOT_MY_INSTANCE;
3550
3551 ospf = ospf_lookup_instance(instance);
3552 if (!ospf || !ospf->oi_running)
3553 return CMD_SUCCESS;
3554
3555 if (uj)
3556 json = json_object_new_object();
3557
3558 ret = show_ip_ospf_common(vty, ospf, json, 0);
3559
3560 if (uj)
3561 vty_json(vty, json);
3562
3563 return ret;
3564 }
3565
3566 static void ospf_interface_auth_show(struct vty *vty, struct ospf_interface *oi,
3567 json_object *json, bool use_json)
3568 {
3569 int auth_type;
3570
3571 auth_type = OSPF_IF_PARAM(oi, auth_type);
3572
3573 switch (auth_type) {
3574 case OSPF_AUTH_NULL:
3575 if (use_json)
3576 json_object_string_add(json, "authentication",
3577 "authenticationNone");
3578 else
3579 vty_out(vty, " Authentication NULL is enabled\n");
3580 break;
3581 case OSPF_AUTH_SIMPLE: {
3582 if (use_json)
3583 json_object_string_add(json, "authentication",
3584 "authenticationSimplePassword");
3585 else
3586 vty_out(vty,
3587 " Simple password authentication enabled\n");
3588 break;
3589 }
3590 case OSPF_AUTH_CRYPTOGRAPHIC: {
3591 struct crypt_key *ckey;
3592
3593 if (list_isempty(OSPF_IF_PARAM(oi, auth_crypt)))
3594 return;
3595
3596 ckey = listgetdata(listtail(OSPF_IF_PARAM(oi, auth_crypt)));
3597 if (ckey) {
3598 if (use_json) {
3599 json_object_string_add(json, "authentication",
3600 "authenticationMessageDigest");
3601 } else {
3602 vty_out(vty,
3603 " Cryptographic authentication enabled\n");
3604 vty_out(vty, " Algorithm:MD5\n");
3605 }
3606 }
3607 break;
3608 }
3609 default:
3610 break;
3611 }
3612 }
3613
3614 static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf,
3615 struct interface *ifp,
3616 json_object *json_interface_sub,
3617 bool use_json)
3618 {
3619 int is_up;
3620 struct ospf_neighbor *nbr;
3621 struct route_node *rn;
3622 uint32_t bandwidth = ifp->bandwidth ? ifp->bandwidth : ifp->speed;
3623 struct ospf_if_params *params;
3624
3625 /* Is interface up? */
3626 if (use_json) {
3627 is_up = if_is_operative(ifp);
3628 if (is_up)
3629 json_object_boolean_true_add(json_interface_sub,
3630 "ifUp");
3631 else
3632 json_object_boolean_false_add(json_interface_sub,
3633 "ifDown");
3634
3635 json_object_int_add(json_interface_sub, "ifIndex",
3636 ifp->ifindex);
3637 json_object_int_add(json_interface_sub, "mtuBytes", ifp->mtu);
3638 json_object_int_add(json_interface_sub, "bandwidthMbit",
3639 bandwidth);
3640 json_object_string_add(json_interface_sub, "ifFlags",
3641 if_flag_dump(ifp->flags));
3642 } else {
3643 vty_out(vty, "%s is %s\n", ifp->name,
3644 ((is_up = if_is_operative(ifp)) ? "up" : "down"));
3645 vty_out(vty, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n",
3646 ifp->ifindex, ifp->mtu, bandwidth,
3647 if_flag_dump(ifp->flags));
3648 }
3649
3650 /* Is interface OSPF enabled? */
3651 if (use_json) {
3652 if (ospf_oi_count(ifp) == 0) {
3653 json_object_boolean_false_add(json_interface_sub,
3654 "ospfEnabled");
3655 return;
3656 } else if (!is_up) {
3657 json_object_boolean_false_add(json_interface_sub,
3658 "ospfRunning");
3659 return;
3660 } else
3661 json_object_boolean_true_add(json_interface_sub,
3662 "ospfEnabled");
3663 } else {
3664 if (ospf_oi_count(ifp) == 0) {
3665 vty_out(vty, " OSPF not enabled on this interface\n");
3666 return;
3667 } else if (!is_up) {
3668 vty_out(vty,
3669 " OSPF is enabled, but not running on this interface\n");
3670 return;
3671 }
3672 }
3673
3674 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
3675 struct ospf_interface *oi = rn->info;
3676
3677 if (oi == NULL)
3678 continue;
3679
3680 if (CHECK_FLAG(oi->connected->flags, ZEBRA_IFA_UNNUMBERED)) {
3681 if (use_json)
3682 json_object_boolean_true_add(json_interface_sub,
3683 "ifUnnumbered");
3684 else
3685 vty_out(vty, " This interface is UNNUMBERED,");
3686 } else {
3687 struct in_addr dest;
3688 const char *dstr;
3689
3690 /* Show OSPF interface information. */
3691 if (use_json) {
3692 json_object_string_addf(
3693 json_interface_sub, "ipAddress", "%pI4",
3694 &oi->address->u.prefix4);
3695 json_object_int_add(json_interface_sub,
3696 "ipAddressPrefixlen",
3697 oi->address->prefixlen);
3698 } else
3699 vty_out(vty, " Internet Address %pFX,",
3700 oi->address);
3701
3702 /* For Vlinks, showing the peer address is
3703 * probably more informative than the local
3704 * interface that is being used */
3705 if (oi->type == OSPF_IFTYPE_VIRTUALLINK) {
3706 dstr = "Peer";
3707 dest = oi->vl_data->peer_addr;
3708 } else if (CONNECTED_PEER(oi->connected)
3709 && oi->connected->destination) {
3710 dstr = "Peer";
3711 dest = oi->connected->destination->u.prefix4;
3712 } else {
3713 dstr = "Broadcast";
3714 dest.s_addr = ipv4_broadcast_addr(
3715 oi->connected->address->u.prefix4.s_addr,
3716 oi->connected->address->prefixlen);
3717 }
3718
3719 if (use_json) {
3720 json_object_string_add(
3721 json_interface_sub,
3722 "ospfIfType", dstr);
3723 if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
3724 json_object_string_addf(
3725 json_interface_sub, "vlinkPeer",
3726 "%pI4", &dest);
3727 else
3728 json_object_string_addf(
3729 json_interface_sub,
3730 "localIfUsed", "%pI4", &dest);
3731 } else
3732 vty_out(vty, " %s %pI4,", dstr,
3733 &dest);
3734 }
3735 if (use_json) {
3736 json_object_string_add(json_interface_sub, "area",
3737 ospf_area_desc_string(oi->area));
3738 if (OSPF_IF_PARAM(oi, mtu_ignore))
3739 json_object_boolean_true_add(
3740 json_interface_sub,
3741 "mtuMismatchDetect");
3742 json_object_string_addf(json_interface_sub, "routerId",
3743 "%pI4", &ospf->router_id);
3744 json_object_string_add(json_interface_sub,
3745 "networkType",
3746 ospf_network_type_str[oi->type]);
3747 json_object_int_add(json_interface_sub, "cost",
3748 oi->output_cost);
3749 json_object_int_add(
3750 json_interface_sub, "transmitDelaySecs",
3751 OSPF_IF_PARAM(oi, transmit_delay));
3752 json_object_string_add(json_interface_sub, "state",
3753 lookup_msg(ospf_ism_state_msg,
3754 oi->state, NULL));
3755 json_object_int_add(json_interface_sub, "priority",
3756 PRIORITY(oi));
3757 } else {
3758 vty_out(vty, " Area %s\n",
3759 ospf_area_desc_string(oi->area));
3760
3761 vty_out(vty, " MTU mismatch detection: %s\n",
3762 OSPF_IF_PARAM(oi, mtu_ignore) ? "disabled"
3763 : "enabled");
3764
3765 vty_out(vty,
3766 " Router ID %pI4, Network Type %s, Cost: %d\n",
3767 &ospf->router_id,
3768 ospf_network_type_str[oi->type],
3769 oi->output_cost);
3770
3771 vty_out(vty,
3772 " Transmit Delay is %d sec, State %s, Priority %d\n",
3773 OSPF_IF_PARAM(oi, transmit_delay),
3774 lookup_msg(ospf_ism_state_msg, oi->state, NULL),
3775 PRIORITY(oi));
3776 }
3777
3778 /* Show DR information. */
3779 if (DR(oi).s_addr == INADDR_ANY) {
3780 if (!use_json)
3781 vty_out(vty,
3782 " No backup designated router on this network\n");
3783 } else {
3784 nbr = ospf_nbr_lookup_by_addr(oi->nbrs, &DR(oi));
3785 if (nbr) {
3786 if (use_json) {
3787 json_object_string_addf(
3788 json_interface_sub, "drId",
3789 "%pI4", &nbr->router_id);
3790 json_object_string_addf(
3791 json_interface_sub, "drAddress",
3792 "%pI4",
3793 &nbr->address.u.prefix4);
3794 } else {
3795 vty_out(vty,
3796 " Designated Router (ID) %pI4",
3797 &nbr->router_id);
3798 vty_out(vty,
3799 " Interface Address %pFX\n",
3800 &nbr->address);
3801 }
3802 }
3803 nbr = NULL;
3804
3805 nbr = ospf_nbr_lookup_by_addr(oi->nbrs, &BDR(oi));
3806 if (nbr == NULL) {
3807 if (!use_json)
3808 vty_out(vty,
3809 " No backup designated router on this network\n");
3810 } else {
3811 if (use_json) {
3812 json_object_string_addf(
3813 json_interface_sub, "bdrId",
3814 "%pI4", &nbr->router_id);
3815 json_object_string_addf(
3816 json_interface_sub,
3817 "bdrAddress", "%pI4",
3818 &nbr->address.u.prefix4);
3819 } else {
3820 vty_out(vty,
3821 " Backup Designated Router (ID) %pI4,",
3822 &nbr->router_id);
3823 vty_out(vty, " Interface Address %pI4\n",
3824 &nbr->address.u.prefix4);
3825 }
3826 }
3827 }
3828
3829 /* Next network-LSA sequence number we'll use, if we're elected
3830 * DR */
3831 if (oi->params
3832 && ntohl(oi->params->network_lsa_seqnum)
3833 != OSPF_INITIAL_SEQUENCE_NUMBER) {
3834 if (use_json)
3835 json_object_int_add(
3836 json_interface_sub,
3837 "networkLsaSequence",
3838 ntohl(oi->params->network_lsa_seqnum));
3839 else
3840 vty_out(vty,
3841 " Saved Network-LSA sequence number 0x%x\n",
3842 ntohl(oi->params->network_lsa_seqnum));
3843 }
3844
3845 if (use_json) {
3846 if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)
3847 || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) {
3848 if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS))
3849 json_object_boolean_true_add(
3850 json_interface_sub,
3851 "mcastMemberOspfAllRouters");
3852 if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS))
3853 json_object_boolean_true_add(
3854 json_interface_sub,
3855 "mcastMemberOspfDesignatedRouters");
3856 }
3857 } else {
3858 vty_out(vty, " Multicast group memberships:");
3859 if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)
3860 || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) {
3861 if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS))
3862 vty_out(vty, " OSPFAllRouters");
3863 if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS))
3864 vty_out(vty, " OSPFDesignatedRouters");
3865 } else
3866 vty_out(vty, " <None>");
3867 vty_out(vty, "\n");
3868 }
3869
3870 if (use_json) {
3871 if (OSPF_IF_PARAM(oi, fast_hello) == 0)
3872 json_object_int_add(
3873 json_interface_sub, "timerMsecs",
3874 OSPF_IF_PARAM(oi, v_hello) * 1000);
3875 else
3876 json_object_int_add(
3877 json_interface_sub, "timerMsecs",
3878 1000 / OSPF_IF_PARAM(oi, fast_hello));
3879 json_object_int_add(json_interface_sub,
3880 "timerDeadSecs",
3881 OSPF_IF_PARAM(oi, v_wait));
3882 json_object_int_add(json_interface_sub,
3883 "timerWaitSecs",
3884 OSPF_IF_PARAM(oi, v_wait));
3885 json_object_int_add(
3886 json_interface_sub, "timerRetransmitSecs",
3887 OSPF_IF_PARAM(oi, retransmit_interval));
3888 } else {
3889 vty_out(vty, " Timer intervals configured,");
3890 vty_out(vty, " Hello ");
3891 if (OSPF_IF_PARAM(oi, fast_hello) == 0)
3892 vty_out(vty, "%ds,",
3893 OSPF_IF_PARAM(oi, v_hello));
3894 else
3895 vty_out(vty, "%dms,",
3896 1000 / OSPF_IF_PARAM(oi, fast_hello));
3897 vty_out(vty, " Dead %ds, Wait %ds, Retransmit %d\n",
3898 OSPF_IF_PARAM(oi, v_wait),
3899 OSPF_IF_PARAM(oi, v_wait),
3900 OSPF_IF_PARAM(oi, retransmit_interval));
3901 }
3902
3903 if (OSPF_IF_PASSIVE_STATUS(oi) == OSPF_IF_ACTIVE) {
3904 char timebuf[OSPF_TIME_DUMP_SIZE];
3905 if (use_json) {
3906 long time_store = 0;
3907 if (oi->t_hello)
3908 time_store =
3909 monotime_until(
3910 &oi->t_hello->u.sands,
3911 NULL)
3912 / 1000LL;
3913 json_object_int_add(json_interface_sub,
3914 "timerHelloInMsecs",
3915 time_store);
3916 } else
3917 vty_out(vty, " Hello due in %s\n",
3918 ospf_timer_dump(oi->t_hello, timebuf,
3919 sizeof(timebuf)));
3920 } else /* passive-interface is set */
3921 {
3922 if (use_json)
3923 json_object_boolean_true_add(
3924 json_interface_sub,
3925 "timerPassiveIface");
3926 else
3927 vty_out(vty,
3928 " No Hellos (Passive interface)\n");
3929 }
3930
3931 if (use_json) {
3932 json_object_int_add(json_interface_sub, "nbrCount",
3933 ospf_nbr_count(oi, 0));
3934 json_object_int_add(json_interface_sub,
3935 "nbrAdjacentCount",
3936 ospf_nbr_count(oi, NSM_Full));
3937 } else
3938 vty_out(vty,
3939 " Neighbor Count is %d, Adjacent neighbor count is %d\n",
3940 ospf_nbr_count(oi, 0),
3941 ospf_nbr_count(oi, NSM_Full));
3942
3943
3944 params = IF_DEF_PARAMS(ifp);
3945 if (params &&
3946 OSPF_IF_PARAM_CONFIGURED(params, v_gr_hello_delay)) {
3947 if (use_json) {
3948 json_object_int_add(json_interface_sub,
3949 "grHelloDelaySecs",
3950 params->v_gr_hello_delay);
3951 } else
3952 vty_out(vty,
3953 " Graceful Restart hello delay: %us\n",
3954 params->v_gr_hello_delay);
3955 }
3956
3957 ospf_interface_bfd_show(vty, ifp, json_interface_sub);
3958
3959 /* OSPF Authentication information */
3960 ospf_interface_auth_show(vty, oi, json_interface_sub, use_json);
3961 if (oi->type == OSPF_IFTYPE_POINTOMULTIPOINT) {
3962 if (use_json)
3963 json_object_boolean_add(json_interface_sub,
3964 "p2mpDelayReflood",
3965 oi->p2mp_delay_reflood);
3966 else
3967 vty_out(vty,
3968 " %sDelay reflooding LSAs received on P2MP interface\n",
3969 oi->p2mp_delay_reflood ? "" : "Don't ");
3970 }
3971 }
3972 }
3973
3974 static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf,
3975 char *intf_name, uint8_t use_vrf,
3976 json_object *json, bool use_json)
3977 {
3978 struct interface *ifp;
3979 struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id);
3980 json_object *json_vrf = NULL;
3981 json_object *json_interface_sub = NULL, *json_interface = NULL;
3982
3983 if (use_json) {
3984 if (use_vrf)
3985 json_vrf = json_object_new_object();
3986 else
3987 json_vrf = json;
3988 json_interface = json_object_new_object();
3989 }
3990
3991 if (ospf->instance) {
3992 if (use_json)
3993 json_object_int_add(json, "ospfInstance",
3994 ospf->instance);
3995 else
3996 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
3997 }
3998
3999 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
4000
4001 if (intf_name == NULL) {
4002 /* Show All Interfaces.*/
4003 FOR_ALL_INTERFACES (vrf, ifp) {
4004 if (ospf_oi_count(ifp)) {
4005 if (use_json) {
4006 json_interface_sub =
4007 json_object_new_object();
4008 }
4009 show_ip_ospf_interface_sub(vty, ospf, ifp,
4010 json_interface_sub,
4011 use_json);
4012
4013 if (use_json) {
4014 json_object_object_add(
4015 json_interface, ifp->name,
4016 json_interface_sub);
4017 }
4018 }
4019 }
4020 if (use_json)
4021 json_object_object_add(json_vrf, "interfaces",
4022 json_interface);
4023 } else {
4024 /* Interface name is specified. */
4025 ifp = if_lookup_by_name(intf_name, ospf->vrf_id);
4026 if (ifp == NULL) {
4027 if (use_json) {
4028 json_object_boolean_true_add(json_vrf,
4029 "noSuchIface");
4030 json_object_free(json_interface);
4031 } else
4032 vty_out(vty, "No such interface name\n");
4033 } else {
4034 if (use_json)
4035 json_interface_sub = json_object_new_object();
4036
4037 show_ip_ospf_interface_sub(
4038 vty, ospf, ifp, json_interface_sub, use_json);
4039
4040 if (use_json) {
4041 json_object_object_add(json_interface,
4042 ifp->name,
4043 json_interface_sub);
4044 json_object_object_add(json_vrf, "interfaces",
4045 json_interface);
4046 }
4047 }
4048 }
4049
4050 if (use_json) {
4051 if (use_vrf) {
4052 json_object_object_add(json, ospf_get_name(ospf),
4053 json_vrf);
4054 }
4055 } else
4056 vty_out(vty, "\n");
4057
4058 return CMD_SUCCESS;
4059 }
4060
4061 static void show_ip_ospf_interface_traffic_sub(struct vty *vty,
4062 struct ospf_interface *oi,
4063 json_object *json_interface_sub,
4064 bool use_json)
4065 {
4066 if (use_json) {
4067 json_object_int_add(json_interface_sub, "ifIndex",
4068 oi->ifp->ifindex);
4069 json_object_int_add(json_interface_sub, "helloIn",
4070 oi->hello_in);
4071 json_object_int_add(json_interface_sub, "helloOut",
4072 oi->hello_out);
4073 json_object_int_add(json_interface_sub, "dbDescIn",
4074 oi->db_desc_in);
4075 json_object_int_add(json_interface_sub, "dbDescOut",
4076 oi->db_desc_out);
4077 json_object_int_add(json_interface_sub, "lsReqIn",
4078 oi->ls_req_in);
4079 json_object_int_add(json_interface_sub, "lsReqOut",
4080 oi->ls_req_out);
4081 json_object_int_add(json_interface_sub, "lsUpdIn",
4082 oi->ls_upd_in);
4083 json_object_int_add(json_interface_sub, "lsUpdOut",
4084 oi->ls_upd_out);
4085 json_object_int_add(json_interface_sub, "lsAckIn",
4086 oi->ls_ack_in);
4087 json_object_int_add(json_interface_sub, "lsAckOut",
4088 oi->ls_ack_out);
4089 json_object_int_add(json_interface_sub, "packetsQueued",
4090 listcount(oi->obuf));
4091 } else {
4092 vty_out(vty,
4093 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u %12lu\n",
4094 oi->ifp->name, oi->hello_in, oi->hello_out,
4095 oi->db_desc_in, oi->db_desc_out, oi->ls_req_in,
4096 oi->ls_req_out, oi->ls_upd_in, oi->ls_upd_out,
4097 oi->ls_ack_in, oi->ls_ack_out, listcount(oi->obuf));
4098 }
4099 }
4100
4101 /* OSPFv2 Packet Counters */
4102 static int show_ip_ospf_interface_traffic_common(
4103 struct vty *vty, struct ospf *ospf, char *intf_name, json_object *json,
4104 int display_once, uint8_t use_vrf, bool use_json)
4105 {
4106 struct vrf *vrf = NULL;
4107 struct interface *ifp = NULL;
4108 json_object *json_vrf = NULL;
4109 json_object *json_interface_sub = NULL;
4110
4111 if (!use_json && !display_once) {
4112 vty_out(vty, "\n");
4113 vty_out(vty, "%-12s%-17s%-17s%-17s%-17s%-17s%-17s\n",
4114 "Interface", " HELLO", " DB-Desc", " LS-Req",
4115 " LS-Update", " LS-Ack", " Packets");
4116 vty_out(vty, "%-10s%-18s%-18s%-17s%-17s%-17s%-17s\n", "",
4117 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
4118 " Rx/Tx", " Queued");
4119 vty_out(vty,
4120 "-------------------------------------------------------------------------------------------------------------\n");
4121 } else if (use_json) {
4122 if (use_vrf)
4123 json_vrf = json_object_new_object();
4124 else
4125 json_vrf = json;
4126 }
4127
4128 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
4129
4130 if (intf_name == NULL) {
4131 vrf = vrf_lookup_by_id(ospf->vrf_id);
4132 FOR_ALL_INTERFACES (vrf, ifp) {
4133 struct route_node *rn;
4134 struct ospf_interface *oi;
4135
4136 if (ospf_oi_count(ifp) == 0)
4137 continue;
4138
4139 for (rn = route_top(IF_OIFS(ifp)); rn;
4140 rn = route_next(rn)) {
4141 oi = rn->info;
4142
4143 if (oi == NULL)
4144 continue;
4145
4146 if (use_json) {
4147 json_interface_sub =
4148 json_object_new_object();
4149 }
4150
4151 show_ip_ospf_interface_traffic_sub(
4152 vty, oi, json_interface_sub, use_json);
4153 if (use_json) {
4154 json_object_object_add(
4155 json_vrf, ifp->name,
4156 json_interface_sub);
4157 }
4158 }
4159 }
4160 } else {
4161 /* Interface name is specified. */
4162 ifp = if_lookup_by_name(intf_name, ospf->vrf_id);
4163 if (ifp != NULL) {
4164 struct route_node *rn;
4165 struct ospf_interface *oi;
4166
4167 if (ospf_oi_count(ifp) == 0) {
4168 vty_out(vty,
4169 " OSPF not enabled on this interface %s\n",
4170 ifp->name);
4171 return CMD_SUCCESS;
4172 }
4173
4174 for (rn = route_top(IF_OIFS(ifp)); rn;
4175 rn = route_next(rn)) {
4176 oi = rn->info;
4177
4178 if (use_json) {
4179 json_interface_sub =
4180 json_object_new_object();
4181 }
4182
4183 show_ip_ospf_interface_traffic_sub(
4184 vty, oi, json_interface_sub, use_json);
4185 if (use_json) {
4186 json_object_object_add(
4187 json_vrf, ifp->name,
4188 json_interface_sub);
4189 }
4190 }
4191 }
4192 }
4193
4194 if (use_json) {
4195 if (use_vrf)
4196 json_object_object_add(json, ospf_get_name(ospf),
4197 json_vrf);
4198 } else
4199 vty_out(vty, "\n");
4200
4201 return CMD_SUCCESS;
4202 }
4203
4204 DEFUN (show_ip_ospf_interface,
4205 show_ip_ospf_interface_cmd,
4206 "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]",
4207 SHOW_STR
4208 IP_STR
4209 "OSPF information\n"
4210 VRF_CMD_HELP_STR
4211 "All VRFs\n"
4212 "Interface information\n"
4213 "Interface name\n"
4214 JSON_STR)
4215 {
4216 struct ospf *ospf;
4217 bool uj = use_json(argc, argv);
4218 struct listnode *node = NULL;
4219 char *vrf_name = NULL, *intf_name = NULL;
4220 bool all_vrf = false;
4221 int ret = CMD_SUCCESS;
4222 int inst = 0;
4223 int idx_vrf = 0, idx_intf = 0;
4224 uint8_t use_vrf = 0;
4225 json_object *json = NULL;
4226
4227 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
4228
4229 if (argv_find(argv, argc, "INTERFACE", &idx_intf))
4230 intf_name = argv[idx_intf]->arg;
4231
4232 if (uj)
4233 json = json_object_new_object();
4234
4235 /* vrf input is provided could be all or specific vrf*/
4236 if (vrf_name) {
4237 use_vrf = 1;
4238 if (all_vrf) {
4239 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
4240 if (!ospf->oi_running)
4241 continue;
4242 ret = show_ip_ospf_interface_common(
4243 vty, ospf, intf_name, use_vrf, json,
4244 uj);
4245 }
4246
4247 if (uj)
4248 vty_json(vty, json);
4249 else if (!ospf)
4250 vty_out(vty, "%% OSPF is not enabled\n");
4251
4252 return ret;
4253 }
4254 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
4255 if (ospf == NULL || !ospf->oi_running) {
4256 if (uj)
4257 vty_json(vty, json);
4258 else
4259 vty_out(vty,
4260 "%% OSPF is not enabled in vrf %s\n",
4261 vrf_name);
4262
4263 return CMD_SUCCESS;
4264 }
4265 ret = show_ip_ospf_interface_common(vty, ospf, intf_name,
4266 use_vrf, json, uj);
4267
4268 } else {
4269 /* Display default ospf (instance 0) info */
4270 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
4271 if (ospf == NULL || !ospf->oi_running) {
4272 if (uj)
4273 vty_json(vty, json);
4274 else
4275 vty_out(vty,
4276 "%% OSPF is not enabled in vrf default\n");
4277
4278 return CMD_SUCCESS;
4279 }
4280 ret = show_ip_ospf_interface_common(vty, ospf, intf_name,
4281 use_vrf, json, uj);
4282 }
4283
4284 if (uj)
4285 vty_json(vty, json);
4286
4287 return ret;
4288 }
4289
4290 DEFUN (show_ip_ospf_instance_interface,
4291 show_ip_ospf_instance_interface_cmd,
4292 "show ip ospf (1-65535) interface [INTERFACE] [json]",
4293 SHOW_STR
4294 IP_STR
4295 "OSPF information\n"
4296 "Instance ID\n"
4297 "Interface information\n"
4298 "Interface name\n"
4299 JSON_STR)
4300 {
4301 int idx_number = 3;
4302 int idx_intf = 0;
4303 struct ospf *ospf;
4304 unsigned short instance = 0;
4305 bool uj = use_json(argc, argv);
4306 char *intf_name = NULL;
4307 int ret = CMD_SUCCESS;
4308 json_object *json = NULL;
4309
4310 instance = strtoul(argv[idx_number]->arg, NULL, 10);
4311 if (instance != ospf_instance)
4312 return CMD_NOT_MY_INSTANCE;
4313
4314 ospf = ospf_lookup_instance(instance);
4315 if (!ospf || !ospf->oi_running)
4316 return CMD_SUCCESS;
4317
4318 if (uj)
4319 json = json_object_new_object();
4320
4321 if (argv_find(argv, argc, "INTERFACE", &idx_intf))
4322 intf_name = argv[idx_intf]->arg;
4323
4324 ret = show_ip_ospf_interface_common(vty, ospf, intf_name, 0, json, uj);
4325
4326 if (uj)
4327 vty_json(vty, json);
4328
4329 return ret;
4330 }
4331
4332 DEFUN (show_ip_ospf_interface_traffic,
4333 show_ip_ospf_interface_traffic_cmd,
4334 "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]",
4335 SHOW_STR
4336 IP_STR
4337 "OSPF information\n"
4338 VRF_CMD_HELP_STR
4339 "All VRFs\n"
4340 "Interface information\n"
4341 "Protocol Packet counters\n"
4342 "Interface name\n"
4343 JSON_STR)
4344 {
4345 struct ospf *ospf = NULL;
4346 struct listnode *node = NULL;
4347 char *vrf_name = NULL, *intf_name = NULL;
4348 bool all_vrf = false;
4349 int inst = 0;
4350 int idx_vrf = 0, idx_intf = 0;
4351 bool uj = use_json(argc, argv);
4352 json_object *json = NULL;
4353 int ret = CMD_SUCCESS;
4354 int display_once = 0;
4355 uint8_t use_vrf = 0;
4356
4357 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
4358
4359 if (argv_find(argv, argc, "INTERFACE", &idx_intf))
4360 intf_name = argv[idx_intf]->arg;
4361
4362 if (uj)
4363 json = json_object_new_object();
4364
4365 if (vrf_name) {
4366 use_vrf = 1;
4367 if (all_vrf) {
4368 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
4369 if (!ospf->oi_running)
4370 continue;
4371
4372 ret = show_ip_ospf_interface_traffic_common(
4373 vty, ospf, intf_name, json,
4374 display_once, use_vrf, uj);
4375 display_once = 1;
4376 }
4377
4378 if (uj)
4379 vty_json(vty, json);
4380
4381 return ret;
4382 }
4383 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
4384 if (ospf == NULL || !ospf->oi_running) {
4385 if (uj)
4386 json_object_free(json);
4387 return CMD_SUCCESS;
4388 }
4389
4390 ret = show_ip_ospf_interface_traffic_common(
4391 vty, ospf, intf_name, json, display_once, use_vrf, uj);
4392 } else {
4393 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
4394 if (ospf == NULL || !ospf->oi_running) {
4395 if (uj)
4396 json_object_free(json);
4397 return CMD_SUCCESS;
4398 }
4399
4400 ret = show_ip_ospf_interface_traffic_common(
4401 vty, ospf, intf_name, json, display_once, use_vrf, uj);
4402 }
4403
4404 if (uj)
4405 vty_json(vty, json);
4406
4407 return ret;
4408 }
4409
4410
4411 static void show_ip_ospf_neighbour_header(struct vty *vty)
4412 {
4413 vty_out(vty, "\n%-15s %-3s %-15s %-15s %-9s %-15s %-32s %5s %5s %5s\n",
4414 "Neighbor ID", "Pri", "State", "Up Time", "Dead Time",
4415 "Address", "Interface", "RXmtL", "RqstL", "DBsmL");
4416 }
4417
4418 static void show_ip_ospf_neighbour_brief(struct vty *vty,
4419 struct ospf_neighbor *nbr,
4420 struct ospf_neighbor *prev_nbr,
4421 json_object *json, bool use_json)
4422 {
4423 char msgbuf[16];
4424 char timebuf[OSPF_TIME_DUMP_SIZE];
4425 json_object *json_neighbor = NULL, *json_neigh_array = NULL;
4426 struct timeval res = {.tv_sec = 0, .tv_usec = 0};
4427 long time_val = 0;
4428 char uptime[OSPF_TIME_DUMP_SIZE];
4429
4430 if (nbr->ts_last_progress.tv_sec || nbr->ts_last_progress.tv_usec)
4431 time_val =
4432 monotime_since(&nbr->ts_last_progress, &res) / 1000LL;
4433
4434 if (use_json) {
4435 char neigh_str[INET_ADDRSTRLEN];
4436
4437 if (prev_nbr && !IPV4_ADDR_SAME(&prev_nbr->src, &nbr->src)) {
4438 /* Start new neigh list */
4439 json_neigh_array = NULL;
4440 }
4441
4442 if (nbr->state == NSM_Attempt &&
4443 nbr->router_id.s_addr == INADDR_ANY)
4444 strlcpy(neigh_str, "neighbor", sizeof(neigh_str));
4445 else
4446 inet_ntop(AF_INET, &nbr->router_id, neigh_str,
4447 sizeof(neigh_str));
4448
4449 json_object_object_get_ex(json, neigh_str, &json_neigh_array);
4450
4451 if (!json_neigh_array) {
4452 json_neigh_array = json_object_new_array();
4453 json_object_object_add(json, neigh_str,
4454 json_neigh_array);
4455 }
4456
4457 json_neighbor = json_object_new_object();
4458
4459 ospf_nbr_ism_state_message(nbr, msgbuf, sizeof(msgbuf));
4460 json_object_string_add(json_neighbor, "nbrState", msgbuf);
4461
4462 json_object_int_add(json_neighbor, "nbrPriority",
4463 nbr->priority);
4464
4465 json_object_string_add(
4466 json_neighbor, "converged",
4467 lookup_msg(ospf_nsm_state_msg, nbr->state, NULL));
4468 json_object_string_add(json_neighbor, "role",
4469 lookup_msg(ospf_ism_state_msg,
4470 ospf_nbr_ism_state(nbr),
4471 NULL));
4472 if (nbr->t_inactivity) {
4473 long time_store;
4474
4475 time_store = monotime_until(&nbr->t_inactivity->u.sands,
4476 NULL) /
4477 1000LL;
4478 json_object_int_add(json_neighbor, "upTimeInMsec",
4479 time_val);
4480 json_object_int_add(json_neighbor,
4481 "routerDeadIntervalTimerDueMsec",
4482 time_store);
4483 json_object_string_add(
4484 json_neighbor, "upTime",
4485 ospf_timeval_dump(&res, uptime,
4486 sizeof(uptime)));
4487 json_object_string_add(
4488 json_neighbor, "deadTime",
4489 ospf_timer_dump(nbr->t_inactivity, timebuf,
4490 sizeof(timebuf)));
4491 } else {
4492 json_object_string_add(json_neighbor, "deadTimeMsecs",
4493 "inactive");
4494 json_object_string_add(json_neighbor,
4495 "routerDeadIntervalTimerDueMsec",
4496 "inactive");
4497 }
4498 json_object_string_addf(json_neighbor, "ifaceAddress", "%pI4",
4499 &nbr->src);
4500 json_object_string_add(json_neighbor, "ifaceName",
4501 IF_NAME(nbr->oi));
4502 json_object_int_add(json_neighbor,
4503 "linkStateRetransmissionListCounter",
4504 ospf_ls_retransmit_count(nbr));
4505 json_object_int_add(json_neighbor,
4506 "linkStateRequestListCounter",
4507 ospf_ls_request_count(nbr));
4508 json_object_int_add(json_neighbor, "databaseSummaryListCounter",
4509 ospf_db_summary_count(nbr));
4510
4511 json_object_array_add(json_neigh_array, json_neighbor);
4512 } else {
4513 ospf_nbr_ism_state_message(nbr, msgbuf, sizeof(msgbuf));
4514
4515 if (nbr->state == NSM_Attempt &&
4516 nbr->router_id.s_addr == INADDR_ANY)
4517 vty_out(vty, "%-15s %3d %-15s ", "-", nbr->priority,
4518 msgbuf);
4519 else
4520 vty_out(vty, "%-15pI4 %3d %-15s ", &nbr->router_id,
4521 nbr->priority, msgbuf);
4522
4523 vty_out(vty, "%-15s ",
4524 ospf_timeval_dump(&res, uptime, sizeof(uptime)));
4525
4526 vty_out(vty, "%9s ",
4527 ospf_timer_dump(nbr->t_inactivity, timebuf,
4528 sizeof(timebuf)));
4529 vty_out(vty, "%-15pI4 ", &nbr->src);
4530 vty_out(vty, "%-32s %5ld %5ld %5d\n", IF_NAME(nbr->oi),
4531 ospf_ls_retransmit_count(nbr),
4532 ospf_ls_request_count(nbr), ospf_db_summary_count(nbr));
4533 }
4534 }
4535
4536 static void show_ip_ospf_neighbor_sub(struct vty *vty,
4537 struct ospf_interface *oi,
4538 json_object *json, bool use_json)
4539 {
4540 struct route_node *rn;
4541 struct ospf_neighbor *nbr, *prev_nbr = NULL;
4542
4543 for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
4544 nbr = rn->info;
4545
4546 if (!nbr)
4547 continue;
4548
4549 /* Do not show myself. */
4550 if (nbr == oi->nbr_self)
4551 continue;
4552 /* Down state is not shown. */
4553 if (nbr->state == NSM_Down)
4554 continue;
4555
4556 prev_nbr = nbr;
4557
4558 show_ip_ospf_neighbour_brief(vty, nbr, prev_nbr, json,
4559 use_json);
4560 }
4561 }
4562
4563 static int show_ip_ospf_neighbor_common(struct vty *vty, struct ospf *ospf,
4564 json_object *json, bool use_json,
4565 uint8_t use_vrf)
4566 {
4567 struct ospf_interface *oi;
4568 struct listnode *node;
4569 json_object *json_vrf = NULL;
4570 json_object *json_nbr_sub = NULL;
4571
4572 if (use_json) {
4573 if (use_vrf)
4574 json_vrf = json_object_new_object();
4575 else
4576 json_vrf = json;
4577 json_nbr_sub = json_object_new_object();
4578 }
4579
4580 if (ospf->instance) {
4581 if (use_json)
4582 json_object_int_add(json, "ospfInstance",
4583 ospf->instance);
4584 else
4585 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
4586 }
4587
4588 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
4589 if (!use_json)
4590 show_ip_ospf_neighbour_header(vty);
4591
4592 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
4593 if (ospf_interface_neighbor_count(oi) == 0)
4594 continue;
4595 show_ip_ospf_neighbor_sub(vty, oi, json_nbr_sub, use_json);
4596 }
4597
4598 if (use_json) {
4599 json_object_object_add(json_vrf, "neighbors", json_nbr_sub);
4600 if (use_vrf)
4601 json_object_object_add(json, ospf_get_name(ospf),
4602 json_vrf);
4603 } else
4604 vty_out(vty, "\n");
4605
4606 return CMD_SUCCESS;
4607 }
4608
4609 DEFUN (show_ip_ospf_neighbor,
4610 show_ip_ospf_neighbor_cmd,
4611 "show ip ospf [vrf <NAME|all>] neighbor [json]",
4612 SHOW_STR
4613 IP_STR
4614 "OSPF information\n"
4615 VRF_CMD_HELP_STR
4616 "All VRFs\n"
4617 "Neighbor list\n"
4618 JSON_STR)
4619 {
4620 struct ospf *ospf;
4621 bool uj = use_json(argc, argv);
4622 struct listnode *node = NULL;
4623 char *vrf_name = NULL;
4624 bool all_vrf = false;
4625 int ret = CMD_SUCCESS;
4626 int inst = 0;
4627 int idx_vrf = 0;
4628 uint8_t use_vrf = 0;
4629 json_object *json = NULL;
4630
4631 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
4632
4633 if (uj)
4634 json = json_object_new_object();
4635
4636 /* vrf input is provided could be all or specific vrf*/
4637 if (vrf_name) {
4638 use_vrf = 1;
4639 if (all_vrf) {
4640 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
4641 if (!ospf->oi_running)
4642 continue;
4643 ret = show_ip_ospf_neighbor_common(
4644 vty, ospf, json, uj, use_vrf);
4645 }
4646
4647 if (uj)
4648 vty_json(vty, json);
4649 else if (!ospf)
4650 vty_out(vty, "OSPF is not enabled\n");
4651
4652 return ret;
4653 }
4654
4655 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
4656 if (ospf == NULL || !ospf->oi_running) {
4657 if (uj)
4658 vty_json(vty, json);
4659 else
4660 vty_out(vty,
4661 "%% OSPF is not enabled in vrf %s\n",
4662 vrf_name);
4663
4664 return CMD_SUCCESS;
4665 }
4666 } else {
4667 /* Display default ospf (instance 0) info */
4668 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
4669 if (ospf == NULL || !ospf->oi_running) {
4670 if (uj)
4671 vty_json(vty, json);
4672 else
4673 vty_out(vty,
4674 "%% OSPF is not enabled in vrf default\n");
4675
4676 return CMD_SUCCESS;
4677 }
4678 }
4679
4680 if (ospf) {
4681 ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj,
4682 use_vrf);
4683
4684 if (uj) {
4685 vty_out(vty, "%s\n",
4686 json_object_to_json_string_ext(
4687 json, JSON_C_TO_STRING_PRETTY));
4688 }
4689 }
4690
4691 if (uj)
4692 json_object_free(json);
4693
4694 return ret;
4695 }
4696
4697
4698 DEFUN (show_ip_ospf_instance_neighbor,
4699 show_ip_ospf_instance_neighbor_cmd,
4700 "show ip ospf (1-65535) neighbor [json]",
4701 SHOW_STR
4702 IP_STR
4703 "OSPF information\n"
4704 "Instance ID\n"
4705 "Neighbor list\n"
4706 JSON_STR)
4707 {
4708 int idx_number = 3;
4709 struct ospf *ospf;
4710 unsigned short instance = 0;
4711 bool uj = use_json(argc, argv);
4712 json_object *json = NULL;
4713 int ret = CMD_SUCCESS;
4714
4715 instance = strtoul(argv[idx_number]->arg, NULL, 10);
4716 if (instance != ospf_instance)
4717 return CMD_NOT_MY_INSTANCE;
4718
4719 ospf = ospf_lookup_instance(instance);
4720 if (!ospf || !ospf->oi_running)
4721 return CMD_SUCCESS;
4722
4723 if (uj)
4724 json = json_object_new_object();
4725
4726 ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj, 0);
4727
4728 if (uj)
4729 vty_json(vty, json);
4730
4731 return ret;
4732 }
4733
4734 static int show_ip_ospf_neighbor_all_common(struct vty *vty, struct ospf *ospf,
4735 json_object *json, bool use_json,
4736 uint8_t use_vrf)
4737 {
4738 struct listnode *node;
4739 struct ospf_interface *oi;
4740 char buf[PREFIX_STRLEN];
4741 json_object *json_vrf = NULL;
4742 json_object *json_neighbor_sub = NULL;
4743
4744 if (use_json) {
4745 if (use_vrf)
4746 json_vrf = json_object_new_object();
4747 else
4748 json_vrf = json;
4749 }
4750
4751 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
4752 if (!use_json)
4753 show_ip_ospf_neighbour_header(vty);
4754
4755 if (ospf->instance) {
4756 if (use_json)
4757 json_object_int_add(json_vrf, "ospfInstance",
4758 ospf->instance);
4759 else
4760 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
4761 }
4762
4763 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
4764 struct listnode *nbr_node;
4765 struct ospf_nbr_nbma *nbr_nbma;
4766
4767 show_ip_ospf_neighbor_sub(vty, oi, json_vrf, use_json);
4768
4769 /* print Down neighbor status */
4770 for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nbr_node, nbr_nbma)) {
4771 if (nbr_nbma->nbr == NULL
4772 || nbr_nbma->nbr->state == NSM_Down) {
4773 if (use_json) {
4774 json_neighbor_sub =
4775 json_object_new_object();
4776 json_object_int_add(json_neighbor_sub,
4777 "nbrNbmaPriority",
4778 nbr_nbma->priority);
4779 json_object_boolean_true_add(
4780 json_neighbor_sub,
4781 "nbrNbmaDown");
4782 json_object_string_add(
4783 json_neighbor_sub,
4784 "nbrNbmaIfaceName",
4785 IF_NAME(oi));
4786 json_object_int_add(
4787 json_neighbor_sub,
4788 "nbrNbmaRetransmitCounter", 0);
4789 json_object_int_add(
4790 json_neighbor_sub,
4791 "nbrNbmaRequestCounter", 0);
4792 json_object_int_add(
4793 json_neighbor_sub,
4794 "nbrNbmaDbSummaryCounter", 0);
4795 json_object_object_add(
4796 json_vrf,
4797 inet_ntop(AF_INET,
4798 &nbr_nbma->addr, buf,
4799 sizeof(buf)),
4800 json_neighbor_sub);
4801 } else {
4802 vty_out(vty, "%-15s %3d %-15s %9s ",
4803 "-", nbr_nbma->priority, "Down",
4804 "-");
4805 vty_out(vty,
4806 "%-32pI4 %-20s %5d %5d %5d\n",
4807 &nbr_nbma->addr,
4808 IF_NAME(oi), 0, 0, 0);
4809 }
4810 }
4811 }
4812 }
4813
4814 if (use_json) {
4815 if (use_vrf)
4816 json_object_object_add(json, ospf_get_name(ospf),
4817 json_vrf);
4818 } else
4819 vty_out(vty, "\n");
4820
4821 return CMD_SUCCESS;
4822 }
4823
4824 DEFUN (show_ip_ospf_neighbor_all,
4825 show_ip_ospf_neighbor_all_cmd,
4826 "show ip ospf [vrf <NAME|all>] neighbor all [json]",
4827 SHOW_STR
4828 IP_STR
4829 "OSPF information\n"
4830 VRF_CMD_HELP_STR
4831 "All VRFs\n"
4832 "Neighbor list\n"
4833 "include down status neighbor\n"
4834 JSON_STR)
4835 {
4836 struct ospf *ospf;
4837 bool uj = use_json(argc, argv);
4838 struct listnode *node = NULL;
4839 char *vrf_name = NULL;
4840 bool all_vrf = false;
4841 int ret = CMD_SUCCESS;
4842 int inst = 0;
4843 int idx_vrf = 0;
4844 uint8_t use_vrf = 0;
4845 json_object *json = NULL;
4846
4847 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
4848
4849 if (uj)
4850 json = json_object_new_object();
4851
4852 /* vrf input is provided could be all or specific vrf*/
4853 if (vrf_name) {
4854 use_vrf = 1;
4855 if (all_vrf) {
4856 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
4857 if (!ospf->oi_running)
4858 continue;
4859 ret = show_ip_ospf_neighbor_all_common(
4860 vty, ospf, json, uj, use_vrf);
4861 }
4862
4863 if (uj)
4864 vty_json(vty, json);
4865
4866 return ret;
4867 }
4868
4869 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
4870 if (ospf == NULL || !ospf->oi_running) {
4871 if (uj)
4872 json_object_free(json);
4873 return CMD_SUCCESS;
4874 }
4875 } else {
4876 /* Display default ospf (instance 0) info */
4877 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
4878 if (ospf == NULL || !ospf->oi_running) {
4879 if (uj)
4880 json_object_free(json);
4881 return CMD_SUCCESS;
4882 }
4883 }
4884
4885 if (ospf) {
4886 ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj,
4887 use_vrf);
4888 if (uj) {
4889 vty_out(vty, "%s\n",
4890 json_object_to_json_string_ext(
4891 json, JSON_C_TO_STRING_PRETTY));
4892 }
4893 }
4894
4895 if (uj)
4896 json_object_free(json);
4897
4898 return ret;
4899 }
4900
4901 DEFUN (show_ip_ospf_instance_neighbor_all,
4902 show_ip_ospf_instance_neighbor_all_cmd,
4903 "show ip ospf (1-65535) neighbor all [json]",
4904 SHOW_STR
4905 IP_STR
4906 "OSPF information\n"
4907 "Instance ID\n"
4908 "Neighbor list\n"
4909 "include down status neighbor\n"
4910 JSON_STR)
4911 {
4912 int idx_number = 3;
4913 struct ospf *ospf;
4914 unsigned short instance = 0;
4915 bool uj = use_json(argc, argv);
4916 json_object *json = NULL;
4917 int ret = CMD_SUCCESS;
4918
4919 instance = strtoul(argv[idx_number]->arg, NULL, 10);
4920 if (instance != ospf_instance)
4921 return CMD_NOT_MY_INSTANCE;
4922
4923 ospf = ospf_lookup_instance(instance);
4924 if (!ospf || !ospf->oi_running)
4925 return CMD_SUCCESS;
4926 if (uj)
4927 json = json_object_new_object();
4928
4929 ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj, 0);
4930
4931 if (uj)
4932 vty_json(vty, json);
4933
4934 return ret;
4935 }
4936
4937 static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf,
4938 const char *ifname, bool use_json,
4939 uint8_t use_vrf)
4940 {
4941 struct interface *ifp;
4942 struct route_node *rn;
4943 json_object *json = NULL;
4944
4945 if (use_json)
4946 json = json_object_new_object();
4947
4948 if (ospf->instance) {
4949 if (use_json)
4950 json_object_int_add(json, "ospfInstance",
4951 ospf->instance);
4952 else
4953 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
4954 }
4955
4956 ospf_show_vrf_name(ospf, vty, json, use_vrf);
4957
4958 ifp = if_lookup_by_name(ifname, ospf->vrf_id);
4959 if (!ifp) {
4960 if (use_json)
4961 json_object_boolean_true_add(json, "noSuchIface");
4962 else
4963 vty_out(vty, "No such interface.\n");
4964 return CMD_WARNING;
4965 }
4966
4967 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
4968 struct ospf_interface *oi = rn->info;
4969
4970 if (oi == NULL)
4971 continue;
4972
4973 show_ip_ospf_neighbor_sub(vty, oi, json, use_json);
4974 }
4975
4976 if (use_json)
4977 vty_json(vty, json);
4978 else
4979 vty_out(vty, "\n");
4980
4981 return CMD_SUCCESS;
4982 }
4983
4984 DEFPY(show_ip_ospf_instance_neighbor_int,
4985 show_ip_ospf_instance_neighbor_int_cmd,
4986 "show ip ospf (1-65535)$instance neighbor IFNAME$ifname [json$json]",
4987 SHOW_STR
4988 IP_STR
4989 "OSPF information\n"
4990 "Instance ID\n"
4991 "Neighbor list\n"
4992 "Interface name\n"
4993 JSON_STR)
4994 {
4995 struct ospf *ospf;
4996
4997 if (!json)
4998 show_ip_ospf_neighbour_header(vty);
4999
5000 if (instance != ospf_instance)
5001 return CMD_NOT_MY_INSTANCE;
5002
5003 ospf = ospf_lookup_instance(instance);
5004 if (!ospf || !ospf->oi_running)
5005 return CMD_SUCCESS;
5006
5007 if (!json)
5008 show_ip_ospf_neighbour_header(vty);
5009
5010 return show_ip_ospf_neighbor_int_common(vty, ospf, ifname, !!json, 0);
5011 }
5012
5013 static void show_ip_ospf_nbr_nbma_detail_sub(struct vty *vty,
5014 struct ospf_interface *oi,
5015 struct ospf_nbr_nbma *nbr_nbma,
5016 bool use_json, json_object *json)
5017 {
5018 char timebuf[OSPF_TIME_DUMP_SIZE];
5019 json_object *json_sub = NULL;
5020
5021 if (use_json)
5022 json_sub = json_object_new_object();
5023 else /* Show neighbor ID. */
5024 vty_out(vty, " Neighbor %s,", "-");
5025
5026 /* Show interface address. */
5027 if (use_json)
5028 json_object_string_addf(json_sub, "ifaceAddress", "%pI4",
5029 &nbr_nbma->addr);
5030 else
5031 vty_out(vty, " interface address %pI4\n",
5032 &nbr_nbma->addr);
5033
5034 /* Show Area ID. */
5035 if (use_json) {
5036 json_object_string_add(json_sub, "areaId",
5037 ospf_area_desc_string(oi->area));
5038 json_object_string_add(json_sub, "iface", IF_NAME(oi));
5039 } else
5040 vty_out(vty, " In the area %s via interface %s\n",
5041 ospf_area_desc_string(oi->area), IF_NAME(oi));
5042
5043 /* Show neighbor priority and state. */
5044 if (use_json) {
5045 json_object_int_add(json_sub, "nbrPriority",
5046 nbr_nbma->priority);
5047 json_object_string_add(json_sub, "nbrState", "down");
5048 } else
5049 vty_out(vty, " Neighbor priority is %d, State is %s,",
5050 nbr_nbma->priority, "Down");
5051
5052 /* Show state changes. */
5053 if (use_json)
5054 json_object_int_add(json_sub, "stateChangeCounter",
5055 nbr_nbma->state_change);
5056 else
5057 vty_out(vty, " %d state changes\n", nbr_nbma->state_change);
5058
5059 /* Show PollInterval */
5060 if (use_json)
5061 json_object_int_add(json_sub, "pollInterval", nbr_nbma->v_poll);
5062 else
5063 vty_out(vty, " Poll interval %d\n", nbr_nbma->v_poll);
5064
5065 /* Show poll-interval timer. */
5066 if (nbr_nbma->t_poll) {
5067 if (use_json) {
5068 long time_store;
5069 time_store = monotime_until(&nbr_nbma->t_poll->u.sands,
5070 NULL) / 1000LL;
5071 json_object_int_add(json_sub,
5072 "pollIntervalTimerDueMsec",
5073 time_store);
5074 } else
5075 vty_out(vty, " Poll timer due in %s\n",
5076 ospf_timer_dump(nbr_nbma->t_poll, timebuf,
5077 sizeof(timebuf)));
5078 }
5079
5080 /* Show poll-interval timer thread. */
5081 if (use_json) {
5082 if (nbr_nbma->t_poll != NULL)
5083 json_object_string_add(json_sub,
5084 "pollIntervalTimerThread", "on");
5085 } else
5086 vty_out(vty, " Thread Poll Timer %s\n",
5087 nbr_nbma->t_poll != NULL ? "on" : "off");
5088
5089 if (use_json)
5090 json_object_object_add(json, "noNbrId", json_sub);
5091 }
5092
5093 static void show_ip_ospf_neighbor_detail_sub(struct vty *vty,
5094 struct ospf_interface *oi,
5095 struct ospf_neighbor *nbr,
5096 struct ospf_neighbor *prev_nbr,
5097 json_object *json, bool use_json)
5098 {
5099 char timebuf[OSPF_TIME_DUMP_SIZE];
5100 json_object *json_neigh = NULL, *json_neigh_array = NULL;
5101 char neigh_str[INET_ADDRSTRLEN] = {0};
5102 char neigh_state[16] = {0};
5103 struct ospf_neighbor *nbr_dr, *nbr_bdr;
5104
5105 if (use_json) {
5106 if (prev_nbr &&
5107 !IPV4_ADDR_SAME(&prev_nbr->src, &nbr->src)) {
5108 json_neigh_array = NULL;
5109 }
5110
5111 if (nbr->state == NSM_Attempt
5112 && nbr->router_id.s_addr == INADDR_ANY)
5113 strlcpy(neigh_str, "noNbrId", sizeof(neigh_str));
5114 else
5115 inet_ntop(AF_INET, &nbr->router_id,
5116 neigh_str, sizeof(neigh_str));
5117
5118 json_object_object_get_ex(json, neigh_str, &json_neigh_array);
5119
5120 if (!json_neigh_array) {
5121 json_neigh_array = json_object_new_array();
5122 json_object_object_add(json, neigh_str,
5123 json_neigh_array);
5124 }
5125
5126 json_neigh = json_object_new_object();
5127
5128 } else {
5129 /* Show neighbor ID. */
5130 if (nbr->state == NSM_Attempt
5131 && nbr->router_id.s_addr == INADDR_ANY)
5132 vty_out(vty, " Neighbor %s,", "-");
5133 else
5134 vty_out(vty, " Neighbor %pI4,",
5135 &nbr->router_id);
5136 }
5137
5138 /* Show interface address. */
5139 if (use_json)
5140 json_object_string_addf(json_neigh, "ifaceAddress", "%pI4",
5141 &nbr->address.u.prefix4);
5142 else
5143 vty_out(vty, " interface address %pI4\n",
5144 &nbr->address.u.prefix4);
5145
5146 /* Show Area ID. */
5147 if (use_json) {
5148 json_object_string_add(json_neigh, "areaId",
5149 ospf_area_desc_string(oi->area));
5150 json_object_string_add(json_neigh, "ifaceName", oi->ifp->name);
5151 if (oi->address)
5152 json_object_string_addf(json_neigh, "localIfaceAddress",
5153 "%pI4",
5154 &oi->address->u.prefix4);
5155 } else {
5156 vty_out(vty, " In the area %s via interface %s",
5157 ospf_area_desc_string(oi->area), oi->ifp->name);
5158 if (oi->address)
5159 vty_out(vty, " local interface IP %pI4\n",
5160 &oi->address->u.prefix4);
5161 else
5162 vty_out(vty, "\n");
5163 }
5164
5165 /* Show neighbor priority and state. */
5166 ospf_nbr_ism_state_message(nbr, neigh_state, sizeof(neigh_state));
5167 if (use_json) {
5168 json_object_int_add(json_neigh, "nbrPriority", nbr->priority);
5169 json_object_string_add(json_neigh, "nbrState", neigh_state);
5170 json_object_string_add(json_neigh, "role",
5171 lookup_msg(ospf_ism_state_msg,
5172 ospf_nbr_ism_state(nbr),
5173 NULL));
5174 } else {
5175 vty_out(vty,
5176 " Neighbor priority is %d, State is %s, Role is %s,",
5177 nbr->priority, neigh_state,
5178 lookup_msg(ospf_ism_state_msg, ospf_nbr_ism_state(nbr),
5179 NULL));
5180 }
5181 /* Show state changes. */
5182 if (use_json)
5183 json_object_int_add(json_neigh, "stateChangeCounter",
5184 nbr->state_change);
5185 else
5186 vty_out(vty, " %d state changes\n", nbr->state_change);
5187
5188 if (nbr->ts_last_progress.tv_sec || nbr->ts_last_progress.tv_usec) {
5189 struct timeval res;
5190 long time_store;
5191
5192 time_store =
5193 monotime_since(&nbr->ts_last_progress, &res) / 1000LL;
5194 if (use_json) {
5195 json_object_int_add(json_neigh, "lastPrgrsvChangeMsec",
5196 time_store);
5197 } else {
5198 vty_out(vty,
5199 " Most recent state change statistics:\n");
5200 vty_out(vty, " Progressive change %s ago\n",
5201 ospf_timeval_dump(&res, timebuf,
5202 sizeof(timebuf)));
5203 }
5204 }
5205
5206 if (nbr->ts_last_regress.tv_sec || nbr->ts_last_regress.tv_usec) {
5207 struct timeval res;
5208 long time_store;
5209
5210 time_store =
5211 monotime_since(&nbr->ts_last_regress, &res) / 1000LL;
5212 if (use_json) {
5213 json_object_int_add(json_neigh,
5214 "lastRegressiveChangeMsec",
5215 time_store);
5216 if (nbr->last_regress_str)
5217 json_object_string_add(
5218 json_neigh,
5219 "lastRegressiveChangeReason",
5220 nbr->last_regress_str);
5221 } else {
5222 vty_out(vty,
5223 " Regressive change %s ago, due to %s\n",
5224 ospf_timeval_dump(&res, timebuf,
5225 sizeof(timebuf)),
5226 (nbr->last_regress_str ? nbr->last_regress_str
5227 : "??"));
5228 }
5229 }
5230
5231 /* Show Designated Router ID. */
5232 if (DR(oi).s_addr == INADDR_ANY) {
5233 if (!use_json)
5234 vty_out(vty,
5235 " No designated router on this network\n");
5236 } else {
5237 nbr_dr = ospf_nbr_lookup_by_addr(oi->nbrs, &DR(oi));
5238 if (nbr_dr) {
5239 if (use_json)
5240 json_object_string_addf(
5241 json_neigh, "routerDesignatedId",
5242 "%pI4", &nbr_dr->router_id);
5243 else
5244 vty_out(vty, " DR is %pI4,",
5245 &nbr_dr->router_id);
5246 }
5247 }
5248
5249 /* Show Backup Designated Router ID. */
5250 nbr_bdr = ospf_nbr_lookup_by_addr(oi->nbrs, &BDR(oi));
5251 if (nbr_bdr == NULL) {
5252 if (!use_json)
5253 vty_out(vty,
5254 " No backup designated router on this network\n");
5255 } else {
5256 if (use_json)
5257 json_object_string_addf(json_neigh,
5258 "routerDesignatedBackupId",
5259 "%pI4", &nbr_bdr->router_id);
5260 else
5261 vty_out(vty, " BDR is %pI4\n", &nbr_bdr->router_id);
5262 }
5263
5264 /* Show options. */
5265 if (use_json) {
5266 json_object_int_add(json_neigh, "optionsCounter", nbr->options);
5267 json_object_string_add(json_neigh, "optionsList",
5268 ospf_options_dump(nbr->options));
5269 } else
5270 vty_out(vty, " Options %d %s\n", nbr->options,
5271 ospf_options_dump(nbr->options));
5272
5273 /* Show Router Dead interval timer. */
5274 if (use_json) {
5275 if (nbr->t_inactivity) {
5276 long time_store;
5277 time_store = monotime_until(&nbr->t_inactivity->u.sands,
5278 NULL)
5279 / 1000LL;
5280 json_object_int_add(json_neigh,
5281 "routerDeadIntervalTimerDueMsec",
5282 time_store);
5283 } else
5284 json_object_int_add(
5285 json_neigh,
5286 "routerDeadIntervalTimerDueMsec", -1);
5287 } else
5288 vty_out(vty, " Dead timer due in %s\n",
5289 ospf_timer_dump(nbr->t_inactivity, timebuf,
5290 sizeof(timebuf)));
5291
5292 /* Show Database Summary list. */
5293 if (use_json)
5294 json_object_int_add(json_neigh, "databaseSummaryListCounter",
5295 ospf_db_summary_count(nbr));
5296 else
5297 vty_out(vty, " Database Summary List %d\n",
5298 ospf_db_summary_count(nbr));
5299
5300 /* Show Link State Request list. */
5301 if (use_json)
5302 json_object_int_add(json_neigh, "linkStateRequestListCounter",
5303 ospf_ls_request_count(nbr));
5304 else
5305 vty_out(vty, " Link State Request List %ld\n",
5306 ospf_ls_request_count(nbr));
5307
5308 /* Show Link State Retransmission list. */
5309 if (use_json)
5310 json_object_int_add(json_neigh,
5311 "linkStateRetransmissionListCounter",
5312 ospf_ls_retransmit_count(nbr));
5313 else
5314 vty_out(vty, " Link State Retransmission List %ld\n",
5315 ospf_ls_retransmit_count(nbr));
5316
5317 /* Show inactivity timer thread. */
5318 if (use_json) {
5319 if (nbr->t_inactivity != NULL)
5320 json_object_string_add(json_neigh,
5321 "threadInactivityTimer", "on");
5322 } else
5323 vty_out(vty, " Thread Inactivity Timer %s\n",
5324 nbr->t_inactivity != NULL ? "on" : "off");
5325
5326 /* Show Database Description retransmission thread. */
5327 if (use_json) {
5328 if (nbr->t_db_desc != NULL)
5329 json_object_string_add(
5330 json_neigh,
5331 "threadDatabaseDescriptionRetransmission",
5332 "on");
5333 } else
5334 vty_out(vty,
5335 " Thread Database Description Retransmision %s\n",
5336 nbr->t_db_desc != NULL ? "on" : "off");
5337
5338 /* Show Link State Request Retransmission thread. */
5339 if (use_json) {
5340 if (nbr->t_ls_req != NULL)
5341 json_object_string_add(
5342 json_neigh,
5343 "threadLinkStateRequestRetransmission", "on");
5344 } else
5345 vty_out(vty,
5346 " Thread Link State Request Retransmission %s\n",
5347 nbr->t_ls_req != NULL ? "on" : "off");
5348
5349 /* Show Link State Update Retransmission thread. */
5350 if (use_json) {
5351 if (nbr->t_ls_upd != NULL)
5352 json_object_string_add(
5353 json_neigh,
5354 "threadLinkStateUpdateRetransmission",
5355 "on");
5356 } else
5357 vty_out(vty,
5358 " Thread Link State Update Retransmission %s\n\n",
5359 nbr->t_ls_upd != NULL ? "on" : "off");
5360
5361 if (!use_json) {
5362 vty_out(vty, " Graceful restart Helper info:\n");
5363
5364 if (OSPF_GR_IS_ACTIVE_HELPER(nbr)) {
5365 vty_out(vty,
5366 " Graceful Restart HELPER Status : Inprogress.\n");
5367
5368 vty_out(vty,
5369 " Graceful Restart grace period time: %d (seconds).\n",
5370 nbr->gr_helper_info.recvd_grace_period);
5371 vty_out(vty, " Graceful Restart reason: %s.\n",
5372 ospf_restart_reason2str(
5373 nbr->gr_helper_info.gr_restart_reason));
5374 } else {
5375 vty_out(vty,
5376 " Graceful Restart HELPER Status : None\n");
5377 }
5378
5379 if (nbr->gr_helper_info.rejected_reason
5380 != OSPF_HELPER_REJECTED_NONE)
5381 vty_out(vty, " Helper rejected reason: %s.\n",
5382 ospf_rejected_reason2str(
5383 nbr->gr_helper_info.rejected_reason));
5384
5385 if (nbr->gr_helper_info.helper_exit_reason
5386 != OSPF_GR_HELPER_EXIT_NONE)
5387 vty_out(vty, " Last helper exit reason: %s.\n\n",
5388 ospf_exit_reason2str(
5389 nbr->gr_helper_info.helper_exit_reason));
5390 else
5391 vty_out(vty, "\n");
5392 } else {
5393 json_object_string_add(json_neigh, "grHelperStatus",
5394 OSPF_GR_IS_ACTIVE_HELPER(nbr) ?
5395 "Inprogress"
5396 : "None");
5397 if (OSPF_GR_IS_ACTIVE_HELPER(nbr)) {
5398 json_object_int_add(
5399 json_neigh, "graceInterval",
5400 nbr->gr_helper_info.recvd_grace_period);
5401 json_object_string_add(
5402 json_neigh, "grRestartReason",
5403 ospf_restart_reason2str(
5404 nbr->gr_helper_info.gr_restart_reason));
5405 }
5406
5407 if (nbr->gr_helper_info.rejected_reason
5408 != OSPF_HELPER_REJECTED_NONE)
5409 json_object_string_add(
5410 json_neigh, "helperRejectReason",
5411 ospf_rejected_reason2str(
5412 nbr->gr_helper_info.rejected_reason));
5413
5414 if (nbr->gr_helper_info.helper_exit_reason
5415 != OSPF_GR_HELPER_EXIT_NONE)
5416 json_object_string_add(
5417 json_neigh, "helperExitReason",
5418 ospf_exit_reason2str(
5419 nbr->gr_helper_info
5420 .helper_exit_reason));
5421 }
5422
5423 bfd_sess_show(vty, json_neigh, nbr->bfd_session);
5424
5425 if (use_json)
5426 json_object_array_add(json_neigh_array, json_neigh);
5427
5428 }
5429
5430 static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf,
5431 struct in_addr *router_id,
5432 bool use_json, uint8_t use_vrf,
5433 bool is_detail,
5434 json_object *json_vrf)
5435 {
5436 struct listnode *node;
5437 struct ospf_neighbor *nbr;
5438 struct ospf_interface *oi;
5439 json_object *json = NULL;
5440
5441 if (use_json)
5442 json = json_object_new_object();
5443
5444 if (ospf->instance) {
5445 if (use_json)
5446 json_object_int_add(json, "ospfInstance",
5447 ospf->instance);
5448 else
5449 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
5450 }
5451
5452 ospf_show_vrf_name(ospf, vty, json, use_vrf);
5453
5454 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
5455 nbr = ospf_nbr_lookup_by_routerid(oi->nbrs, router_id);
5456
5457 if (!nbr)
5458 continue;
5459
5460 if (is_detail)
5461 show_ip_ospf_neighbor_detail_sub(vty, oi, nbr, NULL,
5462 json, use_json);
5463 else
5464 show_ip_ospf_neighbour_brief(vty, nbr, NULL, json,
5465 use_json);
5466 }
5467
5468 if (json_vrf && use_json) {
5469 json_object_object_add(
5470 json_vrf,
5471 (ospf->vrf_id == VRF_DEFAULT) ? "default" : ospf->name,
5472 json);
5473 return CMD_SUCCESS;
5474 }
5475
5476 if (use_json)
5477 vty_json(vty, json);
5478 else
5479 vty_out(vty, "\n");
5480
5481 return CMD_SUCCESS;
5482 }
5483
5484 DEFPY(show_ip_ospf_neighbor_id,
5485 show_ip_ospf_neighbor_id_cmd,
5486 "show ip ospf [vrf NAME$vrf_name] neighbor A.B.C.D$router_id [detail$detail] [json$json]",
5487 SHOW_STR
5488 IP_STR
5489 "OSPF information\n"
5490 VRF_CMD_HELP_STR
5491 "Neighbor list\n"
5492 "Neighbor ID\n"
5493 "Detailed output\n"
5494 JSON_STR)
5495 {
5496 struct ospf *ospf;
5497 struct listnode *node;
5498 int ret = CMD_SUCCESS;
5499 int inst = 0;
5500
5501 if (vrf_name && !strmatch(vrf_name, "all")) {
5502 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
5503 if (ospf == NULL || !ospf->oi_running) {
5504 if (!json)
5505 vty_out(vty,
5506 "%% OSPF is not enabled in vrf %s\n",
5507 vrf_name);
5508 else
5509 vty_json_empty(vty);
5510 return CMD_SUCCESS;
5511 }
5512 ret = show_ip_ospf_neighbor_id_common(
5513 vty, ospf, &router_id, !!json, 0, !!detail, NULL);
5514 } else {
5515 json_object *json_vrf = NULL;
5516
5517 if (json)
5518 json_vrf = json_object_new_object();
5519 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
5520 if (!ospf->oi_running)
5521 continue;
5522 ret = show_ip_ospf_neighbor_id_common(
5523 vty, ospf, &router_id, !!json, 0, !!detail,
5524 json_vrf);
5525 }
5526 if (json)
5527 vty_json(vty, json_vrf);
5528 }
5529
5530 return ret;
5531 }
5532
5533 DEFPY(show_ip_ospf_instance_neighbor_id, show_ip_ospf_instance_neighbor_id_cmd,
5534 "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [detail$detail] [json$json]",
5535 SHOW_STR IP_STR
5536 "OSPF information\n"
5537 "Instance ID\n"
5538 "Neighbor list\n"
5539 "Neighbor ID\n"
5540 "Detailed output\n" JSON_STR)
5541 {
5542 struct ospf *ospf;
5543
5544 if (instance != ospf_instance)
5545 return CMD_NOT_MY_INSTANCE;
5546
5547 ospf = ospf_lookup_instance(instance);
5548 if (!ospf || !ospf->oi_running)
5549 return CMD_SUCCESS;
5550
5551 return show_ip_ospf_neighbor_id_common(vty, ospf, &router_id, !!json, 0,
5552 !!detail, NULL);
5553 }
5554
5555 static int show_ip_ospf_neighbor_detail_common(struct vty *vty,
5556 struct ospf *ospf,
5557 json_object *json, bool use_json,
5558 uint8_t use_vrf)
5559 {
5560 struct ospf_interface *oi;
5561 struct listnode *node;
5562 json_object *json_vrf = NULL;
5563 json_object *json_nbr_sub = NULL;
5564
5565 if (use_json) {
5566 if (use_vrf)
5567 json_vrf = json_object_new_object();
5568 else
5569 json_vrf = json;
5570
5571 json_nbr_sub = json_object_new_object();
5572 }
5573
5574 if (ospf->instance) {
5575 if (use_json)
5576 json_object_int_add(json, "ospfInstance",
5577 ospf->instance);
5578 else
5579 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
5580 }
5581
5582 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
5583
5584 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
5585 struct route_node *rn;
5586 struct ospf_neighbor *nbr, *prev_nbr = NULL;
5587
5588 for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
5589 nbr = rn->info;
5590
5591 if (!nbr)
5592 continue;
5593
5594 if (nbr != oi->nbr_self) {
5595 if (nbr->state != NSM_Down) {
5596 show_ip_ospf_neighbor_detail_sub(
5597 vty, oi, nbr, prev_nbr,
5598 json_nbr_sub, use_json);
5599 }
5600 }
5601 prev_nbr = nbr;
5602 }
5603 }
5604
5605 if (use_json) {
5606 json_object_object_add(json_vrf, "neighbors",
5607 json_nbr_sub);
5608 if (use_vrf)
5609 json_object_object_add(json, ospf_get_name(ospf),
5610 json_vrf);
5611 } else
5612 vty_out(vty, "\n");
5613
5614 return CMD_SUCCESS;
5615 }
5616
5617 DEFPY(show_ip_ospf_neighbor_detail,
5618 show_ip_ospf_neighbor_detail_cmd,
5619 "show ip ospf [vrf <NAME|all>$vrf_name] neighbor detail [json$json]",
5620 SHOW_STR
5621 IP_STR
5622 "OSPF information\n"
5623 VRF_CMD_HELP_STR
5624 "All VRFs\n"
5625 "Neighbor list\n"
5626 "detail of all neighbors\n"
5627 JSON_STR)
5628 {
5629 struct ospf *ospf;
5630 struct listnode *node = NULL;
5631 int ret = CMD_SUCCESS;
5632 int inst = 0;
5633 uint8_t use_vrf = 0;
5634 json_object *json_vrf = NULL;
5635
5636 if (json)
5637 json_vrf = json_object_new_object();
5638
5639 /* vrf input is provided could be all or specific vrf*/
5640 if (vrf_name) {
5641 use_vrf = 1;
5642 if (strmatch(vrf_name, "all")) {
5643 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
5644 if (!ospf->oi_running)
5645 continue;
5646 ret = show_ip_ospf_neighbor_detail_common(
5647 vty, ospf, json_vrf, !!json, use_vrf);
5648 }
5649 if (json)
5650 vty_json(vty, json_vrf);
5651
5652 return ret;
5653 }
5654 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
5655 if (ospf == NULL || !ospf->oi_running) {
5656 if (json)
5657 vty_json(vty, json_vrf);
5658 else
5659 vty_out(vty,
5660 "%% OSPF is not enabled in vrf %s\n",
5661 vrf_name);
5662 return CMD_SUCCESS;
5663 }
5664 } else {
5665 /* Display default ospf (instance 0) info */
5666 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
5667 if (ospf == NULL || !ospf->oi_running) {
5668 if (json)
5669 vty_json(vty, json_vrf);
5670 else
5671 vty_out(vty, "%% OSPF is not enabled\n");
5672 return CMD_SUCCESS;
5673 }
5674 }
5675
5676 if (ospf)
5677 ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json_vrf,
5678 !!json, use_vrf);
5679
5680 if (json)
5681 vty_json(vty, json_vrf);
5682
5683 return ret;
5684 }
5685
5686 DEFUN (show_ip_ospf_instance_neighbor_detail,
5687 show_ip_ospf_instance_neighbor_detail_cmd,
5688 "show ip ospf (1-65535) neighbor detail [json]",
5689 SHOW_STR
5690 IP_STR
5691 "OSPF information\n"
5692 "Instance ID\n"
5693 "Neighbor list\n"
5694 "detail of all neighbors\n"
5695 JSON_STR)
5696 {
5697 int idx_number = 3;
5698 struct ospf *ospf;
5699 unsigned short instance = 0;
5700 bool uj = use_json(argc, argv);
5701 json_object *json = NULL;
5702 int ret = CMD_SUCCESS;
5703
5704 instance = strtoul(argv[idx_number]->arg, NULL, 10);
5705 if (instance != ospf_instance)
5706 return CMD_NOT_MY_INSTANCE;
5707
5708 ospf = ospf_lookup_instance(instance);
5709 if (!ospf || !ospf->oi_running)
5710 return CMD_SUCCESS;
5711
5712 if (uj)
5713 json = json_object_new_object();
5714
5715 ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj, 0);
5716
5717 if (uj)
5718 vty_json(vty, json);
5719
5720 return ret;
5721 }
5722
5723 static int show_ip_ospf_neighbor_detail_all_common(struct vty *vty,
5724 struct ospf *ospf,
5725 json_object *json,
5726 bool use_json,
5727 uint8_t use_vrf)
5728 {
5729 struct listnode *node;
5730 struct ospf_interface *oi;
5731 json_object *json_vrf = NULL;
5732
5733 if (use_json) {
5734 if (use_vrf)
5735 json_vrf = json_object_new_object();
5736 else
5737 json_vrf = json;
5738 }
5739
5740 if (ospf->instance) {
5741 if (use_json)
5742 json_object_int_add(json, "ospfInstance",
5743 ospf->instance);
5744 else
5745 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
5746 }
5747
5748 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
5749
5750 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
5751 struct route_node *rn;
5752 struct ospf_neighbor *nbr, *prev_nbr = NULL;
5753 struct ospf_nbr_nbma *nbr_nbma;
5754
5755 for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
5756 nbr = rn->info;
5757
5758 if (!nbr)
5759 continue;
5760
5761 if (nbr != oi->nbr_self)
5762 if (nbr->state != NSM_Down)
5763 show_ip_ospf_neighbor_detail_sub(
5764 vty, oi, rn->info, prev_nbr,
5765 json_vrf, use_json);
5766 prev_nbr = nbr;
5767 }
5768
5769 if (oi->type != OSPF_IFTYPE_NBMA)
5770 continue;
5771
5772 struct listnode *nd;
5773
5774 for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nd, nbr_nbma)) {
5775 if (nbr_nbma->nbr == NULL ||
5776 nbr_nbma->nbr->state == NSM_Down)
5777 show_ip_ospf_nbr_nbma_detail_sub(
5778 vty, oi, nbr_nbma, use_json, json_vrf);
5779 }
5780 }
5781
5782 if (use_json) {
5783 if (use_vrf)
5784 json_object_object_add(json, ospf_get_name(ospf),
5785 json_vrf);
5786 } else {
5787 vty_out(vty, "\n");
5788 }
5789
5790 return CMD_SUCCESS;
5791 }
5792
5793 DEFUN (show_ip_ospf_neighbor_detail_all,
5794 show_ip_ospf_neighbor_detail_all_cmd,
5795 "show ip ospf [vrf <NAME|all>] neighbor detail all [json]",
5796 SHOW_STR
5797 IP_STR
5798 "OSPF information\n"
5799 VRF_CMD_HELP_STR
5800 "All VRFs\n"
5801 "Neighbor list\n"
5802 "detail of all neighbors\n"
5803 "include down status neighbor\n"
5804 JSON_STR)
5805 {
5806 struct ospf *ospf;
5807 bool uj = use_json(argc, argv);
5808 struct listnode *node = NULL;
5809 char *vrf_name = NULL;
5810 bool all_vrf = false;
5811 int ret = CMD_SUCCESS;
5812 int inst = 0;
5813 int idx_vrf = 0;
5814 uint8_t use_vrf = 0;
5815 json_object *json = NULL;
5816
5817 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
5818
5819 if (uj)
5820 json = json_object_new_object();
5821
5822 /* vrf input is provided could be all or specific vrf*/
5823 if (vrf_name) {
5824 use_vrf = 1;
5825 if (all_vrf) {
5826 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
5827 if (!ospf->oi_running)
5828 continue;
5829 ret = show_ip_ospf_neighbor_detail_all_common(
5830 vty, ospf, json, uj, use_vrf);
5831 }
5832
5833 if (uj)
5834 vty_json(vty, json);
5835
5836 return ret;
5837 }
5838 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
5839 if (ospf == NULL || !ospf->oi_running) {
5840 if (uj)
5841 json_object_free(json);
5842 return CMD_SUCCESS;
5843 }
5844 } else {
5845 /* Display default ospf (instance 0) info */
5846 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
5847 if (ospf == NULL || !ospf->oi_running) {
5848 if (uj)
5849 json_object_free(json);
5850 return CMD_SUCCESS;
5851 }
5852 }
5853
5854 if (ospf) {
5855 ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json,
5856 uj, use_vrf);
5857 if (uj) {
5858 vty_out(vty, "%s\n",
5859 json_object_to_json_string_ext(
5860 json, JSON_C_TO_STRING_PRETTY));
5861 }
5862 }
5863
5864 if (uj)
5865 json_object_free(json);
5866
5867 return ret;
5868 }
5869
5870 DEFUN (show_ip_ospf_instance_neighbor_detail_all,
5871 show_ip_ospf_instance_neighbor_detail_all_cmd,
5872 "show ip ospf (1-65535) neighbor detail all [json]",
5873 SHOW_STR
5874 IP_STR
5875 "OSPF information\n"
5876 "Instance ID\n"
5877 "Neighbor list\n"
5878 "detail of all neighbors\n"
5879 "include down status neighbor\n"
5880 JSON_STR)
5881 {
5882 int idx_number = 3;
5883 struct ospf *ospf;
5884 unsigned short instance = 0;
5885 bool uj = use_json(argc, argv);
5886 json_object *json = NULL;
5887 int ret = CMD_SUCCESS;
5888
5889 instance = strtoul(argv[idx_number]->arg, NULL, 10);
5890 if (instance != ospf_instance)
5891 return CMD_NOT_MY_INSTANCE;
5892
5893 ospf = ospf_lookup_instance(instance);
5894 if (!ospf || !ospf->oi_running)
5895 return CMD_SUCCESS;
5896
5897 if (uj)
5898 json = json_object_new_object();
5899
5900 ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json, uj, 0);
5901
5902 if (uj)
5903 vty_json(vty, json);
5904
5905 return ret;
5906 }
5907
5908 static int show_ip_ospf_neighbor_int_detail_common(struct vty *vty,
5909 struct ospf *ospf,
5910 const char *ifname,
5911 bool use_json,
5912 json_object *json_vrf)
5913 {
5914 struct ospf_interface *oi;
5915 struct interface *ifp;
5916 struct route_node *rn, *nrn;
5917 struct ospf_neighbor *nbr;
5918 json_object *json = NULL;
5919
5920 if (use_json) {
5921 json = json_object_new_object();
5922 if (json_vrf)
5923 json_object_object_add(json_vrf,
5924 (ospf->vrf_id == VRF_DEFAULT)
5925 ? "default"
5926 : ospf->name,
5927 json);
5928 }
5929
5930 if (ospf->instance) {
5931 if (use_json)
5932 json_object_int_add(json, "ospfInstance",
5933 ospf->instance);
5934 else
5935 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
5936 }
5937
5938 ifp = if_lookup_by_name(ifname, ospf->vrf_id);
5939 if (!ifp) {
5940 if (!use_json) {
5941 vty_out(vty, "No such interface.\n");
5942 } else {
5943 if (!json_vrf)
5944 vty_json(vty, json);
5945 }
5946 return CMD_WARNING;
5947 }
5948
5949 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
5950 oi = rn->info;
5951
5952 if (!oi)
5953 continue;
5954
5955 for (nrn = route_top(oi->nbrs); nrn; nrn = route_next(nrn)) {
5956 nbr = nrn->info;
5957
5958 if (!nbr)
5959 continue;
5960
5961 if (nbr == oi->nbr_self)
5962 continue;
5963
5964 if (nbr->state == NSM_Down)
5965 continue;
5966
5967 show_ip_ospf_neighbor_detail_sub(vty, oi, nbr, NULL,
5968 json, use_json);
5969 }
5970 }
5971
5972 if (use_json) {
5973 if (!json_vrf)
5974 vty_json(vty, json);
5975 } else {
5976 vty_out(vty, "\n");
5977 }
5978
5979 return CMD_SUCCESS;
5980 }
5981
5982 DEFPY(show_ip_ospf_neighbor_int,
5983 show_ip_ospf_neighbor_int_cmd,
5984 "show ip ospf [vrf NAME$vrf_name] neighbor IFNAME$ifname [json$json]",
5985 SHOW_STR
5986 IP_STR
5987 "OSPF information\n"
5988 VRF_CMD_HELP_STR
5989 "Neighbor list\n"
5990 "Interface name\n"
5991 JSON_STR)
5992 {
5993 struct ospf *ospf;
5994 int ret = CMD_SUCCESS;
5995 struct interface *ifp = NULL;
5996 vrf_id_t vrf_id = VRF_DEFAULT;
5997 struct vrf *vrf = NULL;
5998
5999 if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME))
6000 vrf_name = NULL;
6001 if (vrf_name) {
6002 vrf = vrf_lookup_by_name(vrf_name);
6003 if (vrf)
6004 vrf_id = vrf->vrf_id;
6005 }
6006 ospf = ospf_lookup_by_vrf_id(vrf_id);
6007
6008 if (!ospf || !ospf->oi_running) {
6009 if (json)
6010 vty_json_empty(vty);
6011 return ret;
6012 }
6013
6014 if (!json)
6015 show_ip_ospf_neighbour_header(vty);
6016
6017 ifp = if_lookup_by_name(ifname, vrf_id);
6018 if (!ifp) {
6019 if (json)
6020 vty_json_empty(vty);
6021 else
6022 vty_out(vty, "No such interface.\n");
6023 return ret;
6024 }
6025
6026 ret = show_ip_ospf_neighbor_int_common(vty, ospf, ifname, !!json, 0);
6027 return ret;
6028 }
6029
6030 DEFPY(show_ip_ospf_neighbor_int_detail,
6031 show_ip_ospf_neighbor_int_detail_cmd,
6032 "show ip ospf [vrf NAME$vrf_name] neighbor IFNAME$ifname detail [json$json]",
6033 SHOW_STR
6034 IP_STR
6035 "OSPF information\n"
6036 VRF_CMD_HELP_STR
6037 "Neighbor list\n"
6038 "Interface name\n"
6039 "detail of all neighbors\n"
6040 JSON_STR)
6041 {
6042 struct ospf *ospf;
6043 struct listnode *node = NULL;
6044 int ret = CMD_SUCCESS;
6045 bool ospf_output = false;
6046
6047 if (vrf_name && !strmatch(vrf_name, "all")) {
6048 int inst = 0;
6049
6050 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
6051 if (ospf == NULL || !ospf->oi_running) {
6052 if (!json)
6053 vty_out(vty,
6054 "%% OSPF is not enabled in vrf %s\n",
6055 vrf_name);
6056 else
6057 vty_json_empty(vty);
6058 return CMD_SUCCESS;
6059 }
6060 return show_ip_ospf_neighbor_int_detail_common(
6061 vty, ospf, ifname, !!json, NULL);
6062 }
6063
6064 json_object *json_vrf = NULL;
6065
6066 if (json)
6067 json_vrf = json_object_new_object();
6068
6069 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
6070 if (!ospf->oi_running)
6071 continue;
6072 ospf_output = true;
6073 ret = show_ip_ospf_neighbor_int_detail_common(vty, ospf, ifname,
6074 !!json, json_vrf);
6075 }
6076
6077 if (json) {
6078 vty_json(vty, json_vrf);
6079 return ret;
6080 }
6081
6082 if (!ospf_output)
6083 vty_out(vty, "%% OSPF instance not found\n");
6084
6085 return ret;
6086 }
6087
6088 DEFPY(show_ip_ospf_instance_neighbor_int_detail,
6089 show_ip_ospf_instance_neighbor_int_detail_cmd,
6090 "show ip ospf (1-65535)$instance neighbor IFNAME$ifname detail [json$json]",
6091 SHOW_STR
6092 IP_STR
6093 "OSPF information\n"
6094 "Instance ID\n"
6095 "Neighbor list\n"
6096 "Interface name\n"
6097 "detail of all neighbors\n"
6098 JSON_STR)
6099 {
6100 struct ospf *ospf;
6101
6102 if (instance != ospf_instance)
6103 return CMD_NOT_MY_INSTANCE;
6104
6105 ospf = ospf_lookup_instance(instance);
6106 if (!ospf || !ospf->oi_running)
6107 return CMD_SUCCESS;
6108
6109 return show_ip_ospf_neighbor_int_detail_common(vty, ospf, ifname,
6110 !!json, NULL);
6111 }
6112
6113 /* Show functions */
6114 static int show_lsa_summary(struct vty *vty, struct ospf_lsa *lsa, int self,
6115 json_object *json_lsa)
6116 {
6117 struct router_lsa *rl;
6118 struct summary_lsa *sl;
6119 struct as_external_lsa *asel;
6120 struct prefix_ipv4 p;
6121
6122 if (lsa == NULL)
6123 return 0;
6124
6125 /* If self option is set, check LSA self flag. */
6126 if (self == 0 || IS_LSA_SELF(lsa)) {
6127
6128 if (!json_lsa) {
6129 /* LSA common part show. */
6130 vty_out(vty, "%-15pI4", &lsa->data->id);
6131 vty_out(vty, "%-15pI4 %4d 0x%08lx 0x%04x",
6132 &lsa->data->adv_router, LS_AGE(lsa),
6133 (unsigned long)ntohl(lsa->data->ls_seqnum),
6134 ntohs(lsa->data->checksum));
6135 } else {
6136 char seqnum[10];
6137 char checksum[10];
6138
6139 snprintf(seqnum, sizeof(seqnum), "%x",
6140 ntohl(lsa->data->ls_seqnum));
6141 snprintf(checksum, sizeof(checksum), "%x",
6142 ntohs(lsa->data->checksum));
6143 json_object_string_addf(json_lsa, "lsId", "%pI4",
6144 &lsa->data->id);
6145 json_object_string_addf(json_lsa, "advertisedRouter",
6146 "%pI4", &lsa->data->adv_router);
6147 json_object_int_add(json_lsa, "lsaAge", LS_AGE(lsa));
6148 json_object_string_add(json_lsa, "sequenceNumber",
6149 seqnum);
6150 json_object_string_add(json_lsa, "checksum", checksum);
6151 }
6152
6153 /* LSA specific part show. */
6154 switch (lsa->data->type) {
6155 case OSPF_ROUTER_LSA:
6156 rl = (struct router_lsa *)lsa->data;
6157
6158 if (!json_lsa)
6159 vty_out(vty, " %-d", ntohs(rl->links));
6160 else
6161 json_object_int_add(json_lsa,
6162 "numOfRouterLinks",
6163 ntohs(rl->links));
6164 break;
6165 case OSPF_SUMMARY_LSA:
6166 sl = (struct summary_lsa *)lsa->data;
6167
6168 p.family = AF_INET;
6169 p.prefix = sl->header.id;
6170 p.prefixlen = ip_masklen(sl->mask);
6171 apply_mask_ipv4(&p);
6172
6173 if (!json_lsa)
6174 vty_out(vty, " %pFX", &p);
6175 else {
6176 json_object_string_addf(
6177 json_lsa, "summaryAddress", "%pFX", &p);
6178 }
6179 break;
6180 case OSPF_AS_EXTERNAL_LSA:
6181 case OSPF_AS_NSSA_LSA:
6182 asel = (struct as_external_lsa *)lsa->data;
6183
6184 p.family = AF_INET;
6185 p.prefix = asel->header.id;
6186 p.prefixlen = ip_masklen(asel->mask);
6187 apply_mask_ipv4(&p);
6188
6189 if (!json_lsa)
6190 vty_out(vty, " %s %pFX [0x%lx]",
6191 IS_EXTERNAL_METRIC(asel->e[0].tos)
6192 ? "E2"
6193 : "E1",
6194 &p,
6195 (unsigned long)ntohl(
6196 asel->e[0].route_tag));
6197 else {
6198 json_object_string_add(
6199 json_lsa, "metricType",
6200 IS_EXTERNAL_METRIC(asel->e[0].tos)
6201 ? "E2"
6202 : "E1");
6203 json_object_string_addf(json_lsa, "route",
6204 "%pFX", &p);
6205 json_object_int_add(
6206 json_lsa, "tag",
6207 (unsigned long)ntohl(
6208 asel->e[0].route_tag));
6209 }
6210 break;
6211 case OSPF_NETWORK_LSA:
6212 case OSPF_ASBR_SUMMARY_LSA:
6213 case OSPF_OPAQUE_LINK_LSA:
6214 case OSPF_OPAQUE_AREA_LSA:
6215 case OSPF_OPAQUE_AS_LSA:
6216 default:
6217 break;
6218 }
6219
6220 if (!json_lsa)
6221 vty_out(vty, "\n");
6222 }
6223
6224 return 1;
6225 }
6226
6227 static const char *const show_database_desc[] = {
6228 "unknown",
6229 "Router Link States",
6230 "Net Link States",
6231 "Summary Link States",
6232 "ASBR-Summary Link States",
6233 "AS External Link States",
6234 "Group Membership LSA",
6235 "NSSA-external Link States",
6236 "Type-8 LSA",
6237 "Link-Local Opaque-LSA",
6238 "Area-Local Opaque-LSA",
6239 "AS-external Opaque-LSA",
6240 };
6241
6242 static const char * const show_database_desc_json[] = {
6243 "unknown",
6244 "routerLinkStates",
6245 "networkLinkStates",
6246 "summaryLinkStates",
6247 "asbrSummaryLinkStates",
6248 "asExternalLinkStates",
6249 "groupMembershipLsa",
6250 "nssaExternalLinkStates",
6251 "type8Lsa",
6252 "linkLocalOpaqueLsa",
6253 "areaLocalOpaqueLsa",
6254 "asExternalOpaqueLsa",
6255 };
6256
6257 static const char *const show_database_desc_count_json[] = {
6258 "unknownCount",
6259 "routerLinkStatesCount",
6260 "networkLinkStatesCount",
6261 "summaryLinkStatesCount",
6262 "asbrSummaryLinkStatesCount",
6263 "asExternalLinkStatesCount",
6264 "groupMembershipLsaCount",
6265 "nssaExternalLinkStatesCount",
6266 "type8LsaCount",
6267 "linkLocalOpaqueLsaCount",
6268 "areaLocalOpaqueLsaCount",
6269 "asExternalOpaqueLsaCount",
6270 };
6271
6272 static const char *const show_database_header[] = {
6273 "",
6274 "Link ID ADV Router Age Seq# CkSum Link count",
6275 "Link ID ADV Router Age Seq# CkSum",
6276 "Link ID ADV Router Age Seq# CkSum Route",
6277 "Link ID ADV Router Age Seq# CkSum",
6278 "Link ID ADV Router Age Seq# CkSum Route",
6279 " --- header for Group Member ----",
6280 "Link ID ADV Router Age Seq# CkSum Route",
6281 " --- type-8 ---",
6282 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6283 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6284 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6285 };
6286
6287 static void show_ip_ospf_database_header(struct vty *vty, struct ospf_lsa *lsa,
6288 json_object *json)
6289 {
6290 struct router_lsa *rlsa = (struct router_lsa *)lsa->data;
6291
6292 if (!json) {
6293 if (IS_LSA_SELF(lsa))
6294 vty_out(vty, " LS age: %d%s\n", LS_AGE(lsa),
6295 CHECK_FLAG(lsa->data->ls_age, DO_NOT_AGE)
6296 ? "(S-DNA)"
6297 : "");
6298 else
6299 vty_out(vty, " LS age: %d%s\n", LS_AGE(lsa),
6300 CHECK_FLAG(lsa->data->ls_age, DO_NOT_AGE)
6301 ? "(DNA)"
6302 : "");
6303 vty_out(vty, " Options: 0x%-2x : %s\n", lsa->data->options,
6304 ospf_options_dump(lsa->data->options));
6305 vty_out(vty, " LS Flags: 0x%-2x %s\n", lsa->flags,
6306 ((lsa->flags & OSPF_LSA_LOCAL_XLT)
6307 ? "(Translated from Type-7)"
6308 : ""));
6309
6310 if (lsa->data->type == OSPF_ROUTER_LSA) {
6311 vty_out(vty, " Flags: 0x%x", rlsa->flags);
6312
6313 if (rlsa->flags)
6314 vty_out(vty, " :%s%s%s%s",
6315 IS_ROUTER_LSA_BORDER(rlsa) ? " ABR"
6316 : "",
6317 IS_ROUTER_LSA_EXTERNAL(rlsa) ? " ASBR"
6318 : "",
6319 IS_ROUTER_LSA_VIRTUAL(rlsa)
6320 ? " VL-endpoint"
6321 : "",
6322 IS_ROUTER_LSA_SHORTCUT(rlsa)
6323 ? " Shortcut"
6324 : "");
6325
6326 vty_out(vty, "\n");
6327 }
6328 vty_out(vty, " LS Type: %s\n",
6329 lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL));
6330 vty_out(vty, " Link State ID: %pI4 %s\n",
6331 &lsa->data->id,
6332 lookup_msg(ospf_link_state_id_type_msg, lsa->data->type,
6333 NULL));
6334 vty_out(vty, " Advertising Router: %pI4\n",
6335 &lsa->data->adv_router);
6336 vty_out(vty, " LS Seq Number: %08lx\n",
6337 (unsigned long)ntohl(lsa->data->ls_seqnum));
6338 vty_out(vty, " Checksum: 0x%04x\n",
6339 ntohs(lsa->data->checksum));
6340 vty_out(vty, " Length: %d\n\n", ntohs(lsa->data->length));
6341 } else {
6342 char seqnum[10];
6343 char checksum[10];
6344
6345 snprintf(seqnum, 10, "%x", ntohl(lsa->data->ls_seqnum));
6346 snprintf(checksum, 10, "%x", ntohs(lsa->data->checksum));
6347
6348 json_object_int_add(json, "lsaAge", LS_AGE(lsa));
6349 json_object_string_add(json, "options",
6350 ospf_options_dump(lsa->data->options));
6351 json_object_int_add(json, "lsaFlags", lsa->flags);
6352
6353 if (lsa->flags & OSPF_LSA_LOCAL_XLT)
6354 json_object_boolean_true_add(json,
6355 "translatedFromType7");
6356
6357 if (lsa->data->type == OSPF_ROUTER_LSA) {
6358 json_object_int_add(json, "flags", rlsa->flags);
6359
6360 if (rlsa->flags) {
6361 if (IS_ROUTER_LSA_BORDER(rlsa))
6362 json_object_boolean_true_add(json,
6363 "abr");
6364 if (IS_ROUTER_LSA_EXTERNAL(rlsa))
6365 json_object_boolean_true_add(json,
6366 "asbr");
6367 if (IS_ROUTER_LSA_VIRTUAL(rlsa))
6368 json_object_boolean_true_add(
6369 json, "vlEndpoint");
6370 if (IS_ROUTER_LSA_SHORTCUT(rlsa))
6371 json_object_boolean_true_add(
6372 json, "shortcut");
6373 }
6374 }
6375
6376 json_object_string_add(
6377 json, "lsaType",
6378 lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL));
6379 json_object_string_addf(json, "linkStateId", "%pI4",
6380 &lsa->data->id);
6381 json_object_string_addf(json, "advertisingRouter", "%pI4",
6382 &lsa->data->adv_router);
6383 json_object_string_add(json, "lsaSeqNumber", seqnum);
6384 json_object_string_add(json, "checksum", checksum);
6385 json_object_int_add(json, "length", ntohs(lsa->data->length));
6386 }
6387 }
6388
6389 static const char *const link_type_desc[] = {
6390 "(null)",
6391 "another Router (point-to-point)",
6392 "a Transit Network",
6393 "Stub Network",
6394 "a Virtual Link",
6395 };
6396
6397 static const char *const link_id_desc[] = {
6398 "(null)", "Neighboring Router ID", "Designated Router address",
6399 "Net", "Neighboring Router ID",
6400 };
6401
6402 static const char *const link_data_desc[] = {
6403 "(null)", "Router Interface address", "Router Interface address",
6404 "Network Mask", "Router Interface address",
6405 };
6406
6407 static const char *const link_id_desc_json[] = {
6408 "null", "neighborRouterId", "designatedRouterAddress",
6409 "networkAddress", "neighborRouterId",
6410 };
6411
6412 static const char *const link_data_desc_json[] = {
6413 "null", "routerInterfaceAddress", "routerInterfaceAddress",
6414 "networkMask", "routerInterfaceAddress",
6415 };
6416
6417 /* Show router-LSA each Link information. */
6418 static void show_ip_ospf_database_router_links(struct vty *vty,
6419 struct router_lsa *rl,
6420 json_object *json)
6421 {
6422 int len, type;
6423 unsigned short i;
6424 json_object *json_links = NULL;
6425 json_object *json_link = NULL;
6426 int metric = 0;
6427 char buf[PREFIX_STRLEN];
6428
6429 if (json)
6430 json_links = json_object_new_object();
6431
6432 len = ntohs(rl->header.length) - 4;
6433 for (i = 0; i < ntohs(rl->links) && len > 0; len -= 12, i++) {
6434 type = rl->link[i].type;
6435
6436 if (json) {
6437 char link[16];
6438
6439 snprintf(link, sizeof(link), "link%u", i);
6440 json_link = json_object_new_object();
6441 json_object_string_add(json_link, "linkType",
6442 link_type_desc[type]);
6443 json_object_string_add(json_link,
6444 link_id_desc_json[type],
6445 inet_ntop(AF_INET,
6446 &rl->link[i].link_id,
6447 buf, sizeof(buf)));
6448 json_object_string_add(
6449 json_link, link_data_desc_json[type],
6450 inet_ntop(AF_INET, &rl->link[i].link_data,
6451 buf, sizeof(buf)));
6452 json_object_int_add(json_link, "numOfTosMetrics",
6453 metric);
6454 json_object_int_add(json_link, "tos0Metric",
6455 ntohs(rl->link[i].metric));
6456 json_object_object_add(json_links, link, json_link);
6457 } else {
6458 vty_out(vty, " Link connected to: %s\n",
6459 link_type_desc[type]);
6460 vty_out(vty, " (Link ID) %s: %pI4\n",
6461 link_id_desc[type],
6462 &rl->link[i].link_id);
6463 vty_out(vty, " (Link Data) %s: %pI4\n",
6464 link_data_desc[type],
6465 &rl->link[i].link_data);
6466 vty_out(vty, " Number of TOS metrics: 0\n");
6467 vty_out(vty, " TOS 0 Metric: %d\n",
6468 ntohs(rl->link[i].metric));
6469 vty_out(vty, "\n");
6470 }
6471 }
6472 if (json)
6473 json_object_object_add(json, "routerLinks", json_links);
6474 }
6475
6476 /* Show router-LSA detail information. */
6477 static int show_router_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
6478 json_object *json)
6479 {
6480 if (lsa != NULL) {
6481 struct router_lsa *rl = (struct router_lsa *)lsa->data;
6482
6483 show_ip_ospf_database_header(vty, lsa, json);
6484
6485 if (!json)
6486 vty_out(vty, " Number of Links: %d\n\n",
6487 ntohs(rl->links));
6488 else
6489 json_object_int_add(json, "numOfLinks",
6490 ntohs(rl->links));
6491
6492 show_ip_ospf_database_router_links(vty, rl, json);
6493
6494 if (!json)
6495 vty_out(vty, "\n");
6496 }
6497
6498 return 0;
6499 }
6500
6501 /* Show network-LSA detail information. */
6502 static int show_network_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
6503 json_object *json)
6504 {
6505 int length, i;
6506 char buf[PREFIX_STRLEN];
6507 json_object *json_attached_rt = NULL;
6508 json_object *json_router = NULL;
6509
6510 if (json)
6511 json_attached_rt = json_object_new_object();
6512
6513 if (lsa != NULL) {
6514 struct network_lsa *nl = (struct network_lsa *)lsa->data;
6515 struct in_addr *addr;
6516
6517 show_ip_ospf_database_header(vty, lsa, json);
6518
6519 if (!json)
6520 vty_out(vty, " Network Mask: /%d\n",
6521 ip_masklen(nl->mask));
6522 else
6523 json_object_int_add(json, "networkMask",
6524 ip_masklen(nl->mask));
6525
6526 length = lsa->size - OSPF_LSA_HEADER_SIZE - 4;
6527 addr = &nl->routers[0];
6528 for (i = 0; length > 0 && addr;
6529 length -= 4, addr = &nl->routers[++i])
6530 if (!json) {
6531 vty_out(vty, " Attached Router: %pI4\n",
6532 addr);
6533 vty_out(vty, "\n");
6534 } else {
6535 json_router = json_object_new_object();
6536 json_object_string_add(
6537 json_router, "attachedRouterId",
6538 inet_ntop(AF_INET, addr, buf,
6539 sizeof(buf)));
6540 json_object_object_add(json_attached_rt,
6541 inet_ntop(AF_INET, addr,
6542 buf,
6543 sizeof(buf)),
6544 json_router);
6545 }
6546 }
6547
6548 if (json)
6549 json_object_object_add(json, "attchedRouters",
6550 json_attached_rt);
6551
6552 return 0;
6553 }
6554
6555 /* Show summary-LSA detail information. */
6556 static int show_summary_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
6557 json_object *json)
6558 {
6559 if (lsa != NULL) {
6560 struct summary_lsa *sl = (struct summary_lsa *)lsa->data;
6561
6562 show_ip_ospf_database_header(vty, lsa, json);
6563
6564 if (!json) {
6565 vty_out(vty, " Network Mask: /%d\n",
6566 ip_masklen(sl->mask));
6567 vty_out(vty, " TOS: 0 Metric: %d\n",
6568 GET_METRIC(sl->metric));
6569 vty_out(vty, "\n");
6570 } else {
6571 json_object_int_add(json, "networkMask",
6572 ip_masklen(sl->mask));
6573 json_object_int_add(json, "tos0Metric",
6574 GET_METRIC(sl->metric));
6575 }
6576 }
6577
6578 return 0;
6579 }
6580
6581 /* Show summary-ASBR-LSA detail information. */
6582 static int show_summary_asbr_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
6583 json_object *json)
6584 {
6585 if (lsa != NULL) {
6586 struct summary_lsa *sl = (struct summary_lsa *)lsa->data;
6587
6588 show_ip_ospf_database_header(vty, lsa, json);
6589
6590 if (!json) {
6591 vty_out(vty, " Network Mask: /%d\n",
6592 ip_masklen(sl->mask));
6593 vty_out(vty, " TOS: 0 Metric: %d\n",
6594 GET_METRIC(sl->metric));
6595 vty_out(vty, "\n");
6596 } else {
6597 json_object_int_add(json, "networkMask",
6598 ip_masklen(sl->mask));
6599 json_object_int_add(json, "tos0Metric",
6600 GET_METRIC(sl->metric));
6601 }
6602 }
6603
6604 return 0;
6605 }
6606
6607 /* Show AS-external-LSA detail information. */
6608 static int show_as_external_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
6609 json_object *json)
6610 {
6611 int tos = 0;
6612
6613 if (lsa != NULL) {
6614 struct as_external_lsa *al =
6615 (struct as_external_lsa *)lsa->data;
6616
6617 show_ip_ospf_database_header(vty, lsa, json);
6618
6619 if (!json) {
6620 vty_out(vty, " Network Mask: /%d\n",
6621 ip_masklen(al->mask));
6622 vty_out(vty, " Metric Type: %s\n",
6623 IS_EXTERNAL_METRIC(al->e[0].tos)
6624 ? "2 (Larger than any link state path)"
6625 : "1");
6626 vty_out(vty, " TOS: 0\n");
6627 vty_out(vty, " Metric: %d\n",
6628 GET_METRIC(al->e[0].metric));
6629 vty_out(vty, " Forward Address: %pI4\n",
6630 &al->e[0].fwd_addr);
6631 vty_out(vty,
6632 " External Route Tag: %" ROUTE_TAG_PRI "\n\n",
6633 (route_tag_t)ntohl(al->e[0].route_tag));
6634 } else {
6635 json_object_int_add(json, "networkMask",
6636 ip_masklen(al->mask));
6637 json_object_string_add(
6638 json, "metricType",
6639 IS_EXTERNAL_METRIC(al->e[0].tos)
6640 ? "E2 (Larger than any link state path)"
6641 : "E1");
6642 json_object_int_add(json, "tos", tos);
6643 json_object_int_add(json, "metric",
6644 GET_METRIC(al->e[0].metric));
6645 json_object_string_addf(json, "forwardAddress", "%pI4",
6646 &(al->e[0].fwd_addr));
6647 json_object_int_add(
6648 json, "externalRouteTag",
6649 (route_tag_t)ntohl(al->e[0].route_tag));
6650 }
6651 }
6652
6653 return 0;
6654 }
6655
6656 /* Show AS-NSSA-LSA detail information. */
6657 static int show_as_nssa_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
6658 json_object *json)
6659 {
6660 int tos = 0;
6661
6662 if (lsa != NULL) {
6663 struct as_external_lsa *al =
6664 (struct as_external_lsa *)lsa->data;
6665
6666 show_ip_ospf_database_header(vty, lsa, json);
6667
6668 if (!json) {
6669 vty_out(vty, " Network Mask: /%d\n",
6670 ip_masklen(al->mask));
6671 vty_out(vty, " Metric Type: %s\n",
6672 IS_EXTERNAL_METRIC(al->e[0].tos)
6673 ? "2 (Larger than any link state path)"
6674 : "1");
6675 vty_out(vty, " TOS: 0\n");
6676 vty_out(vty, " Metric: %d\n",
6677 GET_METRIC(al->e[0].metric));
6678 vty_out(vty, " NSSA: Forward Address: %pI4\n",
6679 &al->e[0].fwd_addr);
6680 vty_out(vty,
6681 " External Route Tag: %" ROUTE_TAG_PRI
6682 "\n\n",
6683 (route_tag_t)ntohl(al->e[0].route_tag));
6684 } else {
6685 json_object_int_add(json, "networkMask",
6686 ip_masklen(al->mask));
6687 json_object_string_add(
6688 json, "metricType",
6689 IS_EXTERNAL_METRIC(al->e[0].tos)
6690 ? "E2 (Larger than any link state path)"
6691 : "E1");
6692 json_object_int_add(json, "tos", tos);
6693 json_object_int_add(json, "metric",
6694 GET_METRIC(al->e[0].metric));
6695 json_object_string_addf(json, "nssaForwardAddress",
6696 "%pI4", &al->e[0].fwd_addr);
6697 json_object_int_add(
6698 json, "externalRouteTag",
6699 (route_tag_t)ntohl(al->e[0].route_tag));
6700 }
6701 }
6702
6703 return 0;
6704 }
6705
6706 static int show_func_dummy(struct vty *vty, struct ospf_lsa *lsa,
6707 json_object *json)
6708 {
6709 return 0;
6710 }
6711
6712 static int show_opaque_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
6713 json_object *json)
6714 {
6715 if (lsa != NULL) {
6716 show_ip_ospf_database_header(vty, lsa, json);
6717 show_opaque_info_detail(vty, lsa, json);
6718 if (!json)
6719 vty_out(vty, "\n");
6720 }
6721 return 0;
6722 }
6723
6724 int (*show_function[])(struct vty *, struct ospf_lsa *, json_object *) = {
6725 NULL,
6726 show_router_lsa_detail,
6727 show_network_lsa_detail,
6728 show_summary_lsa_detail,
6729 show_summary_asbr_lsa_detail,
6730 show_as_external_lsa_detail,
6731 show_func_dummy,
6732 show_as_nssa_lsa_detail, /* almost same as external */
6733 NULL, /* type-8 */
6734 show_opaque_lsa_detail,
6735 show_opaque_lsa_detail,
6736 show_opaque_lsa_detail,
6737 };
6738
6739 static void show_lsa_prefix_set(struct vty *vty, struct prefix_ls *lp,
6740 struct in_addr *id, struct in_addr *adv_router)
6741 {
6742 memset(lp, 0, sizeof(struct prefix_ls));
6743 lp->family = AF_UNSPEC;
6744 if (id == NULL)
6745 lp->prefixlen = 0;
6746 else if (adv_router == NULL) {
6747 lp->prefixlen = IPV4_MAX_BITLEN;
6748 lp->id = *id;
6749 } else {
6750 lp->prefixlen = 64;
6751 lp->id = *id;
6752 lp->adv_router = *adv_router;
6753 }
6754 }
6755
6756 static void show_lsa_detail_proc(struct vty *vty, struct route_table *rt,
6757 struct in_addr *id, struct in_addr *adv_router,
6758 json_object *json)
6759 {
6760 struct prefix_ls lp;
6761 struct route_node *rn, *start;
6762 struct ospf_lsa *lsa;
6763 json_object *json_lsa = NULL;
6764
6765 show_lsa_prefix_set(vty, &lp, id, adv_router);
6766 start = route_node_get(rt, (struct prefix *)&lp);
6767 if (start) {
6768 route_lock_node(start);
6769 for (rn = start; rn; rn = route_next_until(rn, start))
6770 if ((lsa = rn->info)) {
6771 if (show_function[lsa->data->type] != NULL) {
6772 if (json) {
6773 json_lsa =
6774 json_object_new_object();
6775 json_object_array_add(json,
6776 json_lsa);
6777 }
6778
6779 show_function[lsa->data->type](
6780 vty, lsa, json_lsa);
6781 }
6782 }
6783 route_unlock_node(start);
6784 }
6785 }
6786
6787 /* Show detail LSA information
6788 -- if id is NULL then show all LSAs. */
6789 static void show_lsa_detail(struct vty *vty, struct ospf *ospf, int type,
6790 struct in_addr *id, struct in_addr *adv_router,
6791 json_object *json)
6792 {
6793 struct listnode *node;
6794 struct ospf_area *area;
6795 char buf[PREFIX_STRLEN];
6796 json_object *json_lsa_type = NULL;
6797 json_object *json_areas = NULL;
6798 json_object *json_lsa_array = NULL;
6799
6800 switch (type) {
6801 case OSPF_AS_EXTERNAL_LSA:
6802 case OSPF_OPAQUE_AS_LSA:
6803 if (!json)
6804 vty_out(vty, " %s \n\n",
6805 show_database_desc[type]);
6806 else
6807 json_lsa_array = json_object_new_array();
6808
6809 show_lsa_detail_proc(vty, AS_LSDB(ospf, type), id, adv_router,
6810 json_lsa_array);
6811 if (json)
6812 json_object_object_add(json,
6813 show_database_desc_json[type],
6814 json_lsa_array);
6815
6816 break;
6817 default:
6818 if (json)
6819 json_areas = json_object_new_object();
6820
6821 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
6822 if (!json) {
6823 vty_out(vty,
6824 "\n %s (Area %s)\n\n",
6825 show_database_desc[type],
6826 ospf_area_desc_string(area));
6827 } else {
6828 json_lsa_array = json_object_new_array();
6829 json_object_object_add(json_areas,
6830 inet_ntop(AF_INET,
6831 &area->area_id,
6832 buf,
6833 sizeof(buf)),
6834 json_lsa_array);
6835 }
6836
6837 show_lsa_detail_proc(vty, AREA_LSDB(area, type), id,
6838 adv_router, json_lsa_array);
6839 }
6840
6841 if (json) {
6842 json_lsa_type = json_object_new_object();
6843 json_object_object_add(json_lsa_type, "areas",
6844 json_areas);
6845 json_object_object_add(json,
6846 show_database_desc_json[type],
6847 json_lsa_type);
6848 }
6849 break;
6850 }
6851 }
6852
6853 static void show_lsa_detail_adv_router_proc(struct vty *vty,
6854 struct route_table *rt,
6855 struct in_addr *adv_router,
6856 json_object *json)
6857 {
6858 struct route_node *rn;
6859 struct ospf_lsa *lsa;
6860 json_object *json_lsa = NULL;
6861
6862 for (rn = route_top(rt); rn; rn = route_next(rn))
6863 if ((lsa = rn->info)) {
6864 if (IPV4_ADDR_SAME(adv_router,
6865 &lsa->data->adv_router)) {
6866 if (CHECK_FLAG(lsa->flags, OSPF_LSA_LOCAL_XLT))
6867 continue;
6868 if (json) {
6869 json_lsa = json_object_new_object();
6870 json_object_array_add(json, json_lsa);
6871 }
6872
6873 if (show_function[lsa->data->type] != NULL)
6874 show_function[lsa->data->type](
6875 vty, lsa, json_lsa);
6876 }
6877 }
6878 }
6879
6880 /* Show detail LSA information. */
6881 static void show_lsa_detail_adv_router(struct vty *vty, struct ospf *ospf,
6882 int type, struct in_addr *adv_router,
6883 json_object *json)
6884 {
6885 struct listnode *node;
6886 struct ospf_area *area;
6887 char buf[PREFIX_STRLEN];
6888 json_object *json_lsa_type = NULL;
6889 json_object *json_areas = NULL;
6890 json_object *json_lsa_array = NULL;
6891
6892 if (json)
6893 json_lsa_type = json_object_new_object();
6894
6895 switch (type) {
6896 case OSPF_AS_EXTERNAL_LSA:
6897 case OSPF_OPAQUE_AS_LSA:
6898 if (!json)
6899 vty_out(vty, " %s \n\n",
6900 show_database_desc[type]);
6901 else
6902 json_lsa_array = json_object_new_array();
6903
6904 show_lsa_detail_adv_router_proc(vty, AS_LSDB(ospf, type),
6905 adv_router, json_lsa_array);
6906 if (json)
6907 json_object_object_add(json,
6908 show_database_desc_json[type],
6909 json_lsa_array);
6910 break;
6911 default:
6912 if (json)
6913 json_areas = json_object_new_object();
6914
6915 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
6916 if (!json) {
6917 vty_out(vty,
6918 "\n %s (Area %s)\n\n",
6919 show_database_desc[type],
6920 ospf_area_desc_string(area));
6921 } else {
6922 json_lsa_array = json_object_new_array();
6923 json_object_object_add(
6924 json_areas,
6925 inet_ntop(AF_INET, &area->area_id, buf,
6926 sizeof(buf)),
6927 json_lsa_array);
6928 }
6929
6930 show_lsa_detail_adv_router_proc(
6931 vty, AREA_LSDB(area, type), adv_router,
6932 json_lsa_array);
6933 }
6934
6935 if (json) {
6936 json_object_object_add(json_lsa_type, "areas",
6937 json_areas);
6938 json_object_object_add(json,
6939 show_database_desc_json[type],
6940 json_lsa_type);
6941 }
6942 break;
6943 }
6944 }
6945
6946 void show_ip_ospf_database_summary(struct vty *vty, struct ospf *ospf, int self,
6947 json_object *json)
6948 {
6949 struct ospf_lsa *lsa;
6950 struct route_node *rn;
6951 struct ospf_area *area;
6952 struct listnode *node;
6953 char buf[PREFIX_STRLEN];
6954 json_object *json_areas = NULL;
6955 json_object *json_area = NULL;
6956 json_object *json_lsa = NULL;
6957 int type;
6958 json_object *json_lsa_array = NULL;
6959 uint32_t count;
6960
6961 if (json)
6962 json_areas = json_object_new_object();
6963
6964 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
6965 if (json)
6966 json_area = json_object_new_object();
6967
6968 for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) {
6969 count = 0;
6970 switch (type) {
6971 case OSPF_AS_EXTERNAL_LSA:
6972 case OSPF_OPAQUE_AS_LSA:
6973 continue;
6974 default:
6975 break;
6976 }
6977 if (ospf_lsdb_count_self(area->lsdb, type) > 0
6978 || (!self
6979 && ospf_lsdb_count(area->lsdb, type) > 0)) {
6980
6981 if (!json) {
6982 vty_out(vty,
6983 " %s (Area %s)\n\n",
6984 show_database_desc[type],
6985 ospf_area_desc_string(area));
6986 vty_out(vty, "%s\n",
6987 show_database_header[type]);
6988 } else {
6989 json_lsa_array =
6990 json_object_new_array();
6991 json_object_object_add(
6992 json_area,
6993 show_database_desc_json[type],
6994 json_lsa_array);
6995 }
6996
6997 LSDB_LOOP (AREA_LSDB(area, type), rn, lsa) {
6998 if (json) {
6999 json_lsa =
7000 json_object_new_object();
7001 json_object_array_add(
7002 json_lsa_array,
7003 json_lsa);
7004 }
7005
7006 count += show_lsa_summary(
7007 vty, lsa, self, json_lsa);
7008 }
7009
7010 if (!json)
7011 vty_out(vty, "\n");
7012 else
7013 json_object_int_add(
7014 json_area,
7015
7016 show_database_desc_count_json
7017 [type],
7018 count);
7019 }
7020 }
7021 if (json)
7022 json_object_object_add(json_areas,
7023 inet_ntop(AF_INET,
7024 &area->area_id,
7025 buf, sizeof(buf)),
7026 json_area);
7027 }
7028
7029 if (json)
7030 json_object_object_add(json, "areas", json_areas);
7031
7032 for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) {
7033 count = 0;
7034 switch (type) {
7035 case OSPF_AS_EXTERNAL_LSA:
7036 case OSPF_OPAQUE_AS_LSA:
7037 break;
7038 default:
7039 continue;
7040 }
7041 if (ospf_lsdb_count_self(ospf->lsdb, type)
7042 || (!self && ospf_lsdb_count(ospf->lsdb, type))) {
7043 if (!json) {
7044 vty_out(vty, " %s\n\n",
7045 show_database_desc[type]);
7046 vty_out(vty, "%s\n",
7047 show_database_header[type]);
7048 } else {
7049 json_lsa_array = json_object_new_array();
7050 json_object_object_add(
7051 json, show_database_desc_json[type],
7052 json_lsa_array);
7053 }
7054
7055 LSDB_LOOP (AS_LSDB(ospf, type), rn, lsa) {
7056 if (json) {
7057 json_lsa = json_object_new_object();
7058 json_object_array_add(json_lsa_array,
7059 json_lsa);
7060 }
7061
7062 count += show_lsa_summary(vty, lsa, self,
7063 json_lsa);
7064 }
7065
7066 if (!json)
7067 vty_out(vty, "\n");
7068 else
7069 json_object_int_add(
7070 json,
7071 show_database_desc_count_json[type],
7072 count);
7073 }
7074 }
7075
7076 if (!json)
7077 vty_out(vty, "\n");
7078 }
7079
7080 static void show_ip_ospf_database_maxage(struct vty *vty, struct ospf *ospf,
7081 json_object *json)
7082 {
7083 struct route_node *rn;
7084 char buf[PREFIX_STRLEN];
7085 json_object *json_maxage = NULL;
7086
7087 if (!json)
7088 vty_out(vty, "\n MaxAge Link States:\n\n");
7089 else
7090 json_maxage = json_object_new_object();
7091
7092 for (rn = route_top(ospf->maxage_lsa); rn; rn = route_next(rn)) {
7093 struct ospf_lsa *lsa;
7094 json_object *json_lsa = NULL;
7095
7096 if ((lsa = rn->info) != NULL) {
7097 if (!json) {
7098 vty_out(vty, "Link type: %d\n",
7099 lsa->data->type);
7100 vty_out(vty, "Link State ID: %pI4\n",
7101 &lsa->data->id);
7102 vty_out(vty, "Advertising Router: %pI4\n",
7103 &lsa->data->adv_router);
7104 vty_out(vty, "LSA lock count: %d\n", lsa->lock);
7105 vty_out(vty, "\n");
7106 } else {
7107 json_lsa = json_object_new_object();
7108 json_object_int_add(json_lsa, "linkType",
7109 lsa->data->type);
7110 json_object_string_addf(json_lsa, "linkStateId",
7111 "%pI4", &lsa->data->id);
7112 json_object_string_addf(
7113 json_lsa, "advertisingRouter", "%pI4",
7114 &lsa->data->adv_router);
7115 json_object_int_add(json_lsa, "lsaLockCount",
7116 lsa->lock);
7117 json_object_object_add(
7118 json_maxage,
7119 inet_ntop(AF_INET,
7120 &lsa->data->id,
7121 buf, sizeof(buf)),
7122 json_lsa);
7123 }
7124 }
7125 }
7126 if (json)
7127 json_object_object_add(json, "maxAgeLinkStates", json_maxage);
7128 }
7129
7130 #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
7131 #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
7132
7133 #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
7134 #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
7135 #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
7136 #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
7137
7138 #define OSPF_LSA_TYPES_DESC \
7139 "ASBR summary link states\n" \
7140 "External link states\n" \
7141 "Network link states\n" \
7142 "Router link states\n" \
7143 "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \
7144 OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
7145 OSPF_LSA_TYPE_OPAQUE_AS_DESC
7146
7147 static int
7148 show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf, bool maxage,
7149 bool self, bool detail, const char *type_name,
7150 struct in_addr *lsid, struct in_addr *adv_router,
7151 bool use_vrf, json_object *json, bool uj)
7152 {
7153 int type;
7154 json_object *json_vrf = NULL;
7155
7156 if (uj) {
7157 if (use_vrf)
7158 json_vrf = json_object_new_object();
7159 else
7160 json_vrf = json;
7161 }
7162
7163 if (ospf->instance) {
7164 if (uj)
7165 json_object_int_add(json_vrf, "ospfInstance",
7166 ospf->instance);
7167 else
7168 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
7169 }
7170
7171 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
7172
7173 /* Show Router ID. */
7174 if (uj) {
7175 json_object_string_addf(json_vrf, "routerId", "%pI4",
7176 &ospf->router_id);
7177 } else {
7178 vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n",
7179 &ospf->router_id);
7180 }
7181
7182 /* Show MaxAge LSAs */
7183 if (maxage) {
7184 show_ip_ospf_database_maxage(vty, ospf, json_vrf);
7185 if (json) {
7186 if (use_vrf) {
7187 if (ospf->vrf_id == VRF_DEFAULT)
7188 json_object_object_add(json, "default",
7189 json_vrf);
7190 else
7191 json_object_object_add(json, ospf->name,
7192 json_vrf);
7193 }
7194 }
7195 return CMD_SUCCESS;
7196 }
7197
7198 /* Show all LSAs. */
7199 if (!type_name) {
7200 if (detail) {
7201 for (int i = OSPF_ROUTER_LSA; i <= OSPF_OPAQUE_AS_LSA;
7202 i++) {
7203 switch (i) {
7204 case OSPF_GROUP_MEMBER_LSA:
7205 case OSPF_EXTERNAL_ATTRIBUTES_LSA:
7206 /* ignore deprecated LSA types */
7207 continue;
7208 default:
7209 break;
7210 }
7211
7212 if (adv_router && !lsid)
7213 show_lsa_detail_adv_router(vty, ospf, i,
7214 adv_router,
7215 json_vrf);
7216 else
7217 show_lsa_detail(vty, ospf, i, lsid,
7218 adv_router, json_vrf);
7219 }
7220 } else
7221 show_ip_ospf_database_summary(vty, ospf, self,
7222 json_vrf);
7223
7224 if (json) {
7225 if (use_vrf) {
7226 if (ospf->vrf_id == VRF_DEFAULT)
7227 json_object_object_add(json, "default",
7228 json_vrf);
7229 else
7230 json_object_object_add(json, ospf->name,
7231 json_vrf);
7232 }
7233 }
7234 return CMD_SUCCESS;
7235 }
7236
7237 /* Set database type to show. */
7238 if (strncmp(type_name, "r", 1) == 0)
7239 type = OSPF_ROUTER_LSA;
7240 else if (strncmp(type_name, "ne", 2) == 0)
7241 type = OSPF_NETWORK_LSA;
7242 else if (strncmp(type_name, "ns", 2) == 0)
7243 type = OSPF_AS_NSSA_LSA;
7244 else if (strncmp(type_name, "su", 2) == 0)
7245 type = OSPF_SUMMARY_LSA;
7246 else if (strncmp(type_name, "a", 1) == 0)
7247 type = OSPF_ASBR_SUMMARY_LSA;
7248 else if (strncmp(type_name, "e", 1) == 0)
7249 type = OSPF_AS_EXTERNAL_LSA;
7250 else if (strncmp(type_name, "opaque-l", 8) == 0)
7251 type = OSPF_OPAQUE_LINK_LSA;
7252 else if (strncmp(type_name, "opaque-ar", 9) == 0)
7253 type = OSPF_OPAQUE_AREA_LSA;
7254 else if (strncmp(type_name, "opaque-as", 9) == 0)
7255 type = OSPF_OPAQUE_AS_LSA;
7256 else {
7257 if (uj) {
7258 if (use_vrf)
7259 json_object_free(json_vrf);
7260 }
7261 return CMD_WARNING;
7262 }
7263
7264 if (adv_router && !lsid)
7265 show_lsa_detail_adv_router(vty, ospf, type, adv_router,
7266 json_vrf);
7267 else
7268 show_lsa_detail(vty, ospf, type, lsid, adv_router, json_vrf);
7269
7270 if (json) {
7271 if (use_vrf) {
7272 if (ospf->vrf_id == VRF_DEFAULT)
7273 json_object_object_add(json, "default",
7274 json_vrf);
7275 else
7276 json_object_object_add(json, ospf->name,
7277 json_vrf);
7278 }
7279 }
7280
7281 return CMD_SUCCESS;
7282 }
7283
7284 DEFPY (show_ip_ospf_database,
7285 show_ip_ospf_database_cmd,
7286 "show ip ospf [(1-65535)$instance_id] [vrf <NAME|all>$vrf_name] database\
7287 [<\
7288 max-age$maxage\
7289 |self-originate$selforig\
7290 |<\
7291 detail$detail\
7292 |<asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as>$type_name\
7293 >\
7294 [{\
7295 A.B.C.D$lsid\
7296 |<adv-router A.B.C.D$adv_router|self-originate$adv_router_self>\
7297 }]\
7298 >]\
7299 [json]",
7300 SHOW_STR
7301 IP_STR
7302 "OSPF information\n"
7303 "Instance ID\n"
7304 VRF_CMD_HELP_STR
7305 "All VRFs\n"
7306 "Database summary\n"
7307 "LSAs in MaxAge list\n"
7308 "Self-originated link states\n"
7309 "Show detailed information\n"
7310 OSPF_LSA_TYPES_DESC
7311 "Link State ID (as an IP address)\n"
7312 "Advertising Router link states\n"
7313 "Advertising Router (as an IP address)\n"
7314 "Self-originated link states\n"
7315 JSON_STR)
7316 {
7317 struct ospf *ospf;
7318 int ret = CMD_SUCCESS;
7319 bool use_vrf = !!vrf_name;
7320 bool uj = use_json(argc, argv);
7321 struct in_addr *lsid_p = NULL;
7322 struct in_addr *adv_router_p = NULL;
7323 json_object *json = NULL;
7324
7325 if (uj)
7326 json = json_object_new_object();
7327 if (lsid_str)
7328 lsid_p = &lsid;
7329 if (adv_router_str)
7330 adv_router_p = &adv_router;
7331
7332 if (vrf_name && strmatch(vrf_name, "all")) {
7333 struct listnode *node;
7334 bool ospf_output = false;
7335
7336 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
7337 if (!ospf->oi_running)
7338 continue;
7339 if (ospf->instance != instance_id)
7340 continue;
7341
7342 if (adv_router_self)
7343 adv_router_p = &ospf->router_id;
7344
7345 ospf_output = true;
7346 ret = show_ip_ospf_database_common(
7347 vty, ospf, !!maxage, !!selforig, !!detail,
7348 type_name, lsid_p, adv_router_p, use_vrf, json,
7349 uj);
7350 }
7351
7352 if (!ospf_output && !uj)
7353 vty_out(vty, "%% OSPF is not enabled\n");
7354 } else {
7355 if (!vrf_name)
7356 vrf_name = VRF_DEFAULT_NAME;
7357 ospf = ospf_lookup_by_inst_name(instance_id, vrf_name);
7358 if (ospf == NULL || !ospf->oi_running) {
7359 if (uj)
7360 vty_json(vty, json);
7361 else
7362 vty_out(vty, "%% OSPF instance not found\n");
7363 return CMD_SUCCESS;
7364 }
7365 if (adv_router_self)
7366 adv_router_p = &ospf->router_id;
7367
7368 ret = (show_ip_ospf_database_common(
7369 vty, ospf, !!maxage, !!selforig, !!detail, type_name,
7370 lsid_p, adv_router_p, use_vrf, json, uj));
7371 }
7372
7373 if (uj)
7374 vty_json(vty, json);
7375
7376 return ret;
7377 }
7378
7379 DEFUN (ip_ospf_authentication_args,
7380 ip_ospf_authentication_args_addr_cmd,
7381 "ip ospf authentication <null|message-digest> [A.B.C.D]",
7382 "IP Information\n"
7383 "OSPF interface commands\n"
7384 "Enable authentication on this interface\n"
7385 "Use null authentication\n"
7386 "Use message-digest authentication\n"
7387 "Address of interface\n")
7388 {
7389 VTY_DECLVAR_CONTEXT(interface, ifp);
7390 int idx_encryption = 3;
7391 int idx_ipv4 = 4;
7392 struct in_addr addr;
7393 int ret;
7394 struct ospf_if_params *params;
7395
7396 params = IF_DEF_PARAMS(ifp);
7397
7398 if (argc == 5) {
7399 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7400 if (!ret) {
7401 vty_out(vty,
7402 "Please specify interface address by A.B.C.D\n");
7403 return CMD_WARNING_CONFIG_FAILED;
7404 }
7405
7406 params = ospf_get_if_params(ifp, addr);
7407 ospf_if_update_params(ifp, addr);
7408 }
7409
7410 /* Handle null authentication */
7411 if (argv[idx_encryption]->arg[0] == 'n') {
7412 SET_IF_PARAM(params, auth_type);
7413 params->auth_type = OSPF_AUTH_NULL;
7414 return CMD_SUCCESS;
7415 }
7416
7417 /* Handle message-digest authentication */
7418 if (argv[idx_encryption]->arg[0] == 'm') {
7419 SET_IF_PARAM(params, auth_type);
7420 params->auth_type = OSPF_AUTH_CRYPTOGRAPHIC;
7421 return CMD_SUCCESS;
7422 }
7423
7424 vty_out(vty, "You shouldn't get here!\n");
7425 return CMD_WARNING_CONFIG_FAILED;
7426 }
7427
7428 DEFUN (ip_ospf_authentication,
7429 ip_ospf_authentication_addr_cmd,
7430 "ip ospf authentication [A.B.C.D]",
7431 "IP Information\n"
7432 "OSPF interface commands\n"
7433 "Enable authentication on this interface\n"
7434 "Address of interface\n")
7435 {
7436 VTY_DECLVAR_CONTEXT(interface, ifp);
7437 int idx_ipv4 = 3;
7438 struct in_addr addr;
7439 int ret;
7440 struct ospf_if_params *params;
7441
7442 params = IF_DEF_PARAMS(ifp);
7443
7444 if (argc == 4) {
7445 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7446 if (!ret) {
7447 vty_out(vty,
7448 "Please specify interface address by A.B.C.D\n");
7449 return CMD_WARNING_CONFIG_FAILED;
7450 }
7451
7452 params = ospf_get_if_params(ifp, addr);
7453 ospf_if_update_params(ifp, addr);
7454 }
7455
7456 SET_IF_PARAM(params, auth_type);
7457 params->auth_type = OSPF_AUTH_SIMPLE;
7458
7459 return CMD_SUCCESS;
7460 }
7461
7462 DEFUN (no_ip_ospf_authentication_args,
7463 no_ip_ospf_authentication_args_addr_cmd,
7464 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
7465 NO_STR
7466 "IP Information\n"
7467 "OSPF interface commands\n"
7468 "Enable authentication on this interface\n"
7469 "Use null authentication\n"
7470 "Use message-digest authentication\n"
7471 "Address of interface\n")
7472 {
7473 VTY_DECLVAR_CONTEXT(interface, ifp);
7474 int idx_encryption = 4;
7475 int idx_ipv4 = 5;
7476 struct in_addr addr;
7477 int ret;
7478 struct ospf_if_params *params;
7479 struct route_node *rn;
7480 int auth_type;
7481
7482 params = IF_DEF_PARAMS(ifp);
7483
7484 if (argc == 6) {
7485 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7486 if (!ret) {
7487 vty_out(vty,
7488 "Please specify interface address by A.B.C.D\n");
7489 return CMD_WARNING_CONFIG_FAILED;
7490 }
7491
7492 params = ospf_lookup_if_params(ifp, addr);
7493 if (params == NULL) {
7494 vty_out(vty, "Ip Address specified is unknown\n");
7495 return CMD_WARNING_CONFIG_FAILED;
7496 }
7497 params->auth_type = OSPF_AUTH_NOTSET;
7498 UNSET_IF_PARAM(params, auth_type);
7499 if (params != IF_DEF_PARAMS(ifp)) {
7500 ospf_free_if_params(ifp, addr);
7501 ospf_if_update_params(ifp, addr);
7502 }
7503 } else {
7504 if (argv[idx_encryption]->arg[0] == 'n') {
7505 auth_type = OSPF_AUTH_NULL;
7506 } else if (argv[idx_encryption]->arg[0] == 'm') {
7507 auth_type = OSPF_AUTH_CRYPTOGRAPHIC;
7508 } else {
7509 vty_out(vty, "Unexpected input encountered\n");
7510 return CMD_WARNING_CONFIG_FAILED;
7511 }
7512 /*
7513 * Here we have a case where the user has entered
7514 * 'no ip ospf authentication (null | message_digest )'
7515 * we need to find if we have any ip addresses underneath it
7516 * that
7517 * correspond to the associated type.
7518 */
7519 if (params->auth_type == auth_type) {
7520 params->auth_type = OSPF_AUTH_NOTSET;
7521 UNSET_IF_PARAM(params, auth_type);
7522 }
7523
7524 for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn;
7525 rn = route_next(rn)) {
7526 if ((params = rn->info)) {
7527 if (params->auth_type == auth_type) {
7528 params->auth_type = OSPF_AUTH_NOTSET;
7529 UNSET_IF_PARAM(params, auth_type);
7530 if (params != IF_DEF_PARAMS(ifp)) {
7531 ospf_free_if_params(
7532 ifp, rn->p.u.prefix4);
7533 ospf_if_update_params(
7534 ifp, rn->p.u.prefix4);
7535 }
7536 }
7537 }
7538 }
7539 }
7540
7541 return CMD_SUCCESS;
7542 }
7543
7544 DEFUN (no_ip_ospf_authentication,
7545 no_ip_ospf_authentication_addr_cmd,
7546 "no ip ospf authentication [A.B.C.D]",
7547 NO_STR
7548 "IP Information\n"
7549 "OSPF interface commands\n"
7550 "Enable authentication on this interface\n"
7551 "Address of interface\n")
7552 {
7553 VTY_DECLVAR_CONTEXT(interface, ifp);
7554 int idx_ipv4 = 4;
7555 struct in_addr addr;
7556 int ret;
7557 struct ospf_if_params *params;
7558 struct route_node *rn;
7559
7560 params = IF_DEF_PARAMS(ifp);
7561
7562 if (argc == 5) {
7563 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7564 if (!ret) {
7565 vty_out(vty,
7566 "Please specify interface address by A.B.C.D\n");
7567 return CMD_WARNING_CONFIG_FAILED;
7568 }
7569
7570 params = ospf_lookup_if_params(ifp, addr);
7571 if (params == NULL) {
7572 vty_out(vty, "Ip Address specified is unknown\n");
7573 return CMD_WARNING_CONFIG_FAILED;
7574 }
7575
7576 params->auth_type = OSPF_AUTH_NOTSET;
7577 UNSET_IF_PARAM(params, auth_type);
7578 if (params != IF_DEF_PARAMS(ifp)) {
7579 ospf_free_if_params(ifp, addr);
7580 ospf_if_update_params(ifp, addr);
7581 }
7582 } else {
7583 /*
7584 * When a user enters 'no ip ospf authentication'
7585 * We should remove all authentication types from
7586 * the interface.
7587 */
7588 if ((params->auth_type == OSPF_AUTH_NULL)
7589 || (params->auth_type == OSPF_AUTH_CRYPTOGRAPHIC)
7590 || (params->auth_type == OSPF_AUTH_SIMPLE)) {
7591 params->auth_type = OSPF_AUTH_NOTSET;
7592 UNSET_IF_PARAM(params, auth_type);
7593 }
7594
7595 for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn;
7596 rn = route_next(rn)) {
7597 if ((params = rn->info)) {
7598
7599 if ((params->auth_type == OSPF_AUTH_NULL)
7600 || (params->auth_type
7601 == OSPF_AUTH_CRYPTOGRAPHIC)
7602 || (params->auth_type
7603 == OSPF_AUTH_SIMPLE)) {
7604 params->auth_type = OSPF_AUTH_NOTSET;
7605 UNSET_IF_PARAM(params, auth_type);
7606 if (params != IF_DEF_PARAMS(ifp)) {
7607 ospf_free_if_params(
7608 ifp, rn->p.u.prefix4);
7609 ospf_if_update_params(
7610 ifp, rn->p.u.prefix4);
7611 }
7612 }
7613 }
7614 }
7615 }
7616
7617 return CMD_SUCCESS;
7618 }
7619
7620
7621 DEFUN (ip_ospf_authentication_key,
7622 ip_ospf_authentication_key_addr_cmd,
7623 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
7624 "IP Information\n"
7625 "OSPF interface commands\n"
7626 "Authentication password (key)\n"
7627 "The OSPF password (key)\n"
7628 "Address of interface\n")
7629 {
7630 VTY_DECLVAR_CONTEXT(interface, ifp);
7631 int idx = 0;
7632 struct in_addr addr;
7633 struct ospf_if_params *params;
7634
7635 params = IF_DEF_PARAMS(ifp);
7636
7637 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7638 if (!inet_aton(argv[idx]->arg, &addr)) {
7639 vty_out(vty,
7640 "Please specify interface address by A.B.C.D\n");
7641 return CMD_WARNING_CONFIG_FAILED;
7642 }
7643
7644 params = ospf_get_if_params(ifp, addr);
7645 ospf_if_update_params(ifp, addr);
7646 }
7647
7648 strlcpy((char *)params->auth_simple, argv[3]->arg,
7649 sizeof(params->auth_simple));
7650 SET_IF_PARAM(params, auth_simple);
7651
7652 return CMD_SUCCESS;
7653 }
7654
7655 DEFUN_HIDDEN (ospf_authentication_key,
7656 ospf_authentication_key_cmd,
7657 "ospf authentication-key AUTH_KEY [A.B.C.D]",
7658 "OSPF interface commands\n"
7659 VLINK_HELPSTR_AUTH_SIMPLE
7660 "Address of interface\n")
7661 {
7662 return ip_ospf_authentication_key(self, vty, argc, argv);
7663 }
7664
7665 DEFUN (no_ip_ospf_authentication_key,
7666 no_ip_ospf_authentication_key_authkey_addr_cmd,
7667 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7668 NO_STR
7669 "IP Information\n"
7670 "OSPF interface commands\n"
7671 VLINK_HELPSTR_AUTH_SIMPLE
7672 "Address of interface\n")
7673 {
7674 VTY_DECLVAR_CONTEXT(interface, ifp);
7675 int idx = 0;
7676 struct in_addr addr;
7677 struct ospf_if_params *params;
7678 params = IF_DEF_PARAMS(ifp);
7679
7680 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7681 if (!inet_aton(argv[idx]->arg, &addr)) {
7682 vty_out(vty,
7683 "Please specify interface address by A.B.C.D\n");
7684 return CMD_WARNING_CONFIG_FAILED;
7685 }
7686
7687 params = ospf_lookup_if_params(ifp, addr);
7688 if (params == NULL)
7689 return CMD_SUCCESS;
7690 }
7691
7692 memset(params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE);
7693 UNSET_IF_PARAM(params, auth_simple);
7694
7695 if (params != IF_DEF_PARAMS(ifp)) {
7696 ospf_free_if_params(ifp, addr);
7697 ospf_if_update_params(ifp, addr);
7698 }
7699
7700 return CMD_SUCCESS;
7701 }
7702
7703 DEFUN_HIDDEN (no_ospf_authentication_key,
7704 no_ospf_authentication_key_authkey_addr_cmd,
7705 "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7706 NO_STR
7707 "OSPF interface commands\n"
7708 VLINK_HELPSTR_AUTH_SIMPLE
7709 "Address of interface\n")
7710 {
7711 return no_ip_ospf_authentication_key(self, vty, argc, argv);
7712 }
7713
7714 DEFUN (ip_ospf_message_digest_key,
7715 ip_ospf_message_digest_key_cmd,
7716 "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7717 "IP Information\n"
7718 "OSPF interface commands\n"
7719 "Message digest authentication password (key)\n"
7720 "Key ID\n"
7721 "Use MD5 algorithm\n"
7722 "The OSPF password (key)\n"
7723 "Address of interface\n")
7724 {
7725 VTY_DECLVAR_CONTEXT(interface, ifp);
7726 struct crypt_key *ck;
7727 uint8_t key_id;
7728 struct in_addr addr;
7729 struct ospf_if_params *params;
7730
7731 params = IF_DEF_PARAMS(ifp);
7732 int idx = 0;
7733
7734 argv_find(argv, argc, "(1-255)", &idx);
7735 char *keyid = argv[idx]->arg;
7736 argv_find(argv, argc, "KEY", &idx);
7737 char *cryptkey = argv[idx]->arg;
7738
7739 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7740 if (!inet_aton(argv[idx]->arg, &addr)) {
7741 vty_out(vty,
7742 "Please specify interface address by A.B.C.D\n");
7743 return CMD_WARNING_CONFIG_FAILED;
7744 }
7745
7746 params = ospf_get_if_params(ifp, addr);
7747 ospf_if_update_params(ifp, addr);
7748 }
7749
7750 key_id = strtol(keyid, NULL, 10);
7751
7752 /* Remove existing key, if any */
7753 ospf_crypt_key_delete(params->auth_crypt, key_id);
7754
7755 ck = ospf_crypt_key_new();
7756 ck->key_id = (uint8_t)key_id;
7757 strlcpy((char *)ck->auth_key, cryptkey, sizeof(ck->auth_key));
7758
7759 ospf_crypt_key_add(params->auth_crypt, ck);
7760 SET_IF_PARAM(params, auth_crypt);
7761
7762 return CMD_SUCCESS;
7763 }
7764
7765 DEFUN_HIDDEN (ospf_message_digest_key,
7766 ospf_message_digest_key_cmd,
7767 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7768 "OSPF interface commands\n"
7769 "Message digest authentication password (key)\n"
7770 "Key ID\n"
7771 "Use MD5 algorithm\n"
7772 "The OSPF password (key)\n"
7773 "Address of interface\n")
7774 {
7775 return ip_ospf_message_digest_key(self, vty, argc, argv);
7776 }
7777
7778 DEFUN (no_ip_ospf_message_digest_key,
7779 no_ip_ospf_message_digest_key_cmd,
7780 "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7781 NO_STR
7782 "IP Information\n"
7783 "OSPF interface commands\n"
7784 "Message digest authentication password (key)\n"
7785 "Key ID\n"
7786 "Use MD5 algorithm\n"
7787 "The OSPF password (key)\n"
7788 "Address of interface\n")
7789 {
7790 VTY_DECLVAR_CONTEXT(interface, ifp);
7791 int idx = 0;
7792 struct crypt_key *ck;
7793 int key_id;
7794 struct in_addr addr;
7795 struct ospf_if_params *params;
7796 params = IF_DEF_PARAMS(ifp);
7797
7798 argv_find(argv, argc, "(1-255)", &idx);
7799 char *keyid = argv[idx]->arg;
7800
7801 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7802 if (!inet_aton(argv[idx]->arg, &addr)) {
7803 vty_out(vty,
7804 "Please specify interface address by A.B.C.D\n");
7805 return CMD_WARNING_CONFIG_FAILED;
7806 }
7807
7808 params = ospf_lookup_if_params(ifp, addr);
7809 if (params == NULL)
7810 return CMD_SUCCESS;
7811 }
7812
7813 key_id = strtol(keyid, NULL, 10);
7814 ck = ospf_crypt_key_lookup(params->auth_crypt, key_id);
7815 if (ck == NULL) {
7816 vty_out(vty, "OSPF: Key %d does not exist\n", key_id);
7817 return CMD_WARNING_CONFIG_FAILED;
7818 }
7819
7820 ospf_crypt_key_delete(params->auth_crypt, key_id);
7821
7822 if (params != IF_DEF_PARAMS(ifp)) {
7823 ospf_free_if_params(ifp, addr);
7824 ospf_if_update_params(ifp, addr);
7825 }
7826
7827 return CMD_SUCCESS;
7828 }
7829
7830 DEFUN_HIDDEN (no_ospf_message_digest_key,
7831 no_ospf_message_digest_key_cmd,
7832 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7833 NO_STR
7834 "OSPF interface commands\n"
7835 "Message digest authentication password (key)\n"
7836 "Key ID\n"
7837 "Use MD5 algorithm\n"
7838 "The OSPF password (key)\n"
7839 "Address of interface\n")
7840 {
7841 return no_ip_ospf_message_digest_key(self, vty, argc, argv);
7842 }
7843
7844 DEFUN (ip_ospf_cost,
7845 ip_ospf_cost_cmd,
7846 "ip ospf cost (1-65535) [A.B.C.D]",
7847 "IP Information\n"
7848 "OSPF interface commands\n"
7849 "Interface cost\n"
7850 "Cost\n"
7851 "Address of interface\n")
7852 {
7853 VTY_DECLVAR_CONTEXT(interface, ifp);
7854 int idx = 0;
7855 uint32_t cost = OSPF_OUTPUT_COST_DEFAULT;
7856 struct in_addr addr;
7857 struct ospf_if_params *params;
7858 params = IF_DEF_PARAMS(ifp);
7859
7860 // get arguments
7861 char *coststr = NULL, *ifaddr = NULL;
7862
7863 argv_find(argv, argc, "(1-65535)", &idx);
7864 coststr = argv[idx]->arg;
7865 cost = strtol(coststr, NULL, 10);
7866
7867 ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
7868 if (ifaddr) {
7869 if (!inet_aton(ifaddr, &addr)) {
7870 vty_out(vty,
7871 "Please specify interface address by A.B.C.D\n");
7872 return CMD_WARNING_CONFIG_FAILED;
7873 }
7874
7875 params = ospf_get_if_params(ifp, addr);
7876 ospf_if_update_params(ifp, addr);
7877 }
7878
7879 SET_IF_PARAM(params, output_cost_cmd);
7880 params->output_cost_cmd = cost;
7881
7882 ospf_if_recalculate_output_cost(ifp);
7883
7884 return CMD_SUCCESS;
7885 }
7886
7887 DEFUN_HIDDEN (ospf_cost,
7888 ospf_cost_cmd,
7889 "ospf cost (1-65535) [A.B.C.D]",
7890 "OSPF interface commands\n"
7891 "Interface cost\n"
7892 "Cost\n"
7893 "Address of interface\n")
7894 {
7895 return ip_ospf_cost(self, vty, argc, argv);
7896 }
7897
7898 DEFUN (no_ip_ospf_cost,
7899 no_ip_ospf_cost_cmd,
7900 "no ip ospf cost [(1-65535)] [A.B.C.D]",
7901 NO_STR
7902 "IP Information\n"
7903 "OSPF interface commands\n"
7904 "Interface cost\n"
7905 "Cost\n"
7906 "Address of interface\n")
7907 {
7908 VTY_DECLVAR_CONTEXT(interface, ifp);
7909 int idx = 0;
7910 struct in_addr addr;
7911 struct ospf_if_params *params;
7912
7913 params = IF_DEF_PARAMS(ifp);
7914
7915 // get arguments
7916 char *ifaddr = NULL;
7917 ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
7918
7919 /* According to the semantics we are mimicking "no ip ospf cost N" is
7920 * always treated as "no ip ospf cost" regardless of the actual value
7921 * of N already configured for the interface. Thus ignore cost. */
7922
7923 if (ifaddr) {
7924 if (!inet_aton(ifaddr, &addr)) {
7925 vty_out(vty,
7926 "Please specify interface address by A.B.C.D\n");
7927 return CMD_WARNING_CONFIG_FAILED;
7928 }
7929
7930 params = ospf_lookup_if_params(ifp, addr);
7931 if (params == NULL)
7932 return CMD_SUCCESS;
7933 }
7934
7935 UNSET_IF_PARAM(params, output_cost_cmd);
7936
7937 if (params != IF_DEF_PARAMS(ifp)) {
7938 ospf_free_if_params(ifp, addr);
7939 ospf_if_update_params(ifp, addr);
7940 }
7941
7942 ospf_if_recalculate_output_cost(ifp);
7943
7944 return CMD_SUCCESS;
7945 }
7946
7947 DEFUN_HIDDEN (no_ospf_cost,
7948 no_ospf_cost_cmd,
7949 "no ospf cost [(1-65535)] [A.B.C.D]",
7950 NO_STR
7951 "OSPF interface commands\n"
7952 "Interface cost\n"
7953 "Cost\n"
7954 "Address of interface\n")
7955 {
7956 return no_ip_ospf_cost(self, vty, argc, argv);
7957 }
7958
7959 static void ospf_nbr_timer_update(struct ospf_interface *oi)
7960 {
7961 struct route_node *rn;
7962 struct ospf_neighbor *nbr;
7963
7964 for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
7965 nbr = rn->info;
7966
7967 if (!nbr)
7968 continue;
7969
7970 nbr->v_inactivity = OSPF_IF_PARAM(oi, v_wait);
7971 nbr->v_db_desc = OSPF_IF_PARAM(oi, retransmit_interval);
7972 nbr->v_ls_req = OSPF_IF_PARAM(oi, retransmit_interval);
7973 nbr->v_ls_upd = OSPF_IF_PARAM(oi, retransmit_interval);
7974 }
7975 }
7976
7977 static int ospf_vty_dead_interval_set(struct vty *vty, const char *interval_str,
7978 const char *nbr_str,
7979 const char *fast_hello_str)
7980 {
7981 VTY_DECLVAR_CONTEXT(interface, ifp);
7982 uint32_t seconds;
7983 uint8_t hellomult;
7984 struct in_addr addr;
7985 int ret;
7986 struct ospf_if_params *params;
7987 struct ospf_interface *oi;
7988 struct route_node *rn;
7989
7990 params = IF_DEF_PARAMS(ifp);
7991
7992 if (nbr_str) {
7993 ret = inet_aton(nbr_str, &addr);
7994 if (!ret) {
7995 vty_out(vty,
7996 "Please specify interface address by A.B.C.D\n");
7997 return CMD_WARNING_CONFIG_FAILED;
7998 }
7999
8000 params = ospf_get_if_params(ifp, addr);
8001 ospf_if_update_params(ifp, addr);
8002 }
8003
8004 if (interval_str) {
8005 seconds = strtoul(interval_str, NULL, 10);
8006
8007 /* reset fast_hello too, just to be sure */
8008 UNSET_IF_PARAM(params, fast_hello);
8009 params->fast_hello = OSPF_FAST_HELLO_DEFAULT;
8010 } else if (fast_hello_str) {
8011 hellomult = strtoul(fast_hello_str, NULL, 10);
8012 /* 1s dead-interval with sub-second hellos desired */
8013 seconds = OSPF_ROUTER_DEAD_INTERVAL_MINIMAL;
8014 SET_IF_PARAM(params, fast_hello);
8015 params->fast_hello = hellomult;
8016 } else {
8017 vty_out(vty,
8018 "Please specify dead-interval or hello-multiplier\n");
8019 return CMD_WARNING_CONFIG_FAILED;
8020 }
8021
8022 SET_IF_PARAM(params, v_wait);
8023 params->v_wait = seconds;
8024 params->is_v_wait_set = true;
8025
8026 /* Update timer values in neighbor structure. */
8027 if (nbr_str) {
8028 struct ospf *ospf = NULL;
8029
8030 ospf = ifp->vrf->info;
8031 if (ospf) {
8032 oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr);
8033 if (oi)
8034 ospf_nbr_timer_update(oi);
8035 }
8036 } else {
8037 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn))
8038 if ((oi = rn->info))
8039 ospf_nbr_timer_update(oi);
8040 }
8041
8042 return CMD_SUCCESS;
8043 }
8044
8045 DEFUN (ip_ospf_dead_interval,
8046 ip_ospf_dead_interval_cmd,
8047 "ip ospf dead-interval (1-65535) [A.B.C.D]",
8048 "IP Information\n"
8049 "OSPF interface commands\n"
8050 "Interval time after which a neighbor is declared down\n"
8051 "Seconds\n"
8052 "Address of interface\n")
8053 {
8054 int idx = 0;
8055 char *interval = argv_find(argv, argc, "(1-65535)", &idx)
8056 ? argv[idx]->arg
8057 : NULL;
8058 char *ifaddr =
8059 argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
8060 return ospf_vty_dead_interval_set(vty, interval, ifaddr, NULL);
8061 }
8062
8063
8064 DEFUN_HIDDEN (ospf_dead_interval,
8065 ospf_dead_interval_cmd,
8066 "ospf dead-interval (1-65535) [A.B.C.D]",
8067 "OSPF interface commands\n"
8068 "Interval time after which a neighbor is declared down\n"
8069 "Seconds\n"
8070 "Address of interface\n")
8071 {
8072 return ip_ospf_dead_interval(self, vty, argc, argv);
8073 }
8074
8075 DEFUN (ip_ospf_dead_interval_minimal,
8076 ip_ospf_dead_interval_minimal_addr_cmd,
8077 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
8078 "IP Information\n"
8079 "OSPF interface commands\n"
8080 "Interval time after which a neighbor is declared down\n"
8081 "Minimal 1s dead-interval with fast sub-second hellos\n"
8082 "Hello multiplier factor\n"
8083 "Number of Hellos to send each second\n"
8084 "Address of interface\n")
8085 {
8086 int idx_number = 5;
8087 int idx_ipv4 = 6;
8088 if (argc == 7)
8089 return ospf_vty_dead_interval_set(
8090 vty, NULL, argv[idx_ipv4]->arg, argv[idx_number]->arg);
8091 else
8092 return ospf_vty_dead_interval_set(vty, NULL, NULL,
8093 argv[idx_number]->arg);
8094 }
8095
8096 DEFUN (no_ip_ospf_dead_interval,
8097 no_ip_ospf_dead_interval_cmd,
8098 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8099 NO_STR
8100 "IP Information\n"
8101 "OSPF interface commands\n"
8102 "Interval time after which a neighbor is declared down\n"
8103 "Seconds\n"
8104 "Minimal 1s dead-interval with fast sub-second hellos\n"
8105 "Hello multiplier factor\n"
8106 "Number of Hellos to send each second\n"
8107 "Address of interface\n")
8108 {
8109 VTY_DECLVAR_CONTEXT(interface, ifp);
8110 int idx_ipv4 = argc - 1;
8111 struct in_addr addr = {.s_addr = 0L};
8112 int ret;
8113 struct ospf_if_params *params;
8114 struct ospf_interface *oi;
8115 struct route_node *rn;
8116
8117 params = IF_DEF_PARAMS(ifp);
8118
8119 if (argv[idx_ipv4]->type == IPV4_TKN) {
8120 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
8121 if (!ret) {
8122 vty_out(vty,
8123 "Please specify interface address by A.B.C.D\n");
8124 return CMD_WARNING_CONFIG_FAILED;
8125 }
8126
8127 params = ospf_lookup_if_params(ifp, addr);
8128 if (params == NULL)
8129 return CMD_SUCCESS;
8130 }
8131
8132 UNSET_IF_PARAM(params, v_wait);
8133 params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
8134 params->is_v_wait_set = false;
8135
8136 UNSET_IF_PARAM(params, fast_hello);
8137 params->fast_hello = OSPF_FAST_HELLO_DEFAULT;
8138
8139 if (params != IF_DEF_PARAMS(ifp)) {
8140 ospf_free_if_params(ifp, addr);
8141 ospf_if_update_params(ifp, addr);
8142 }
8143
8144 /* Update timer values in neighbor structure. */
8145 if (argc == 1) {
8146 struct ospf *ospf = NULL;
8147
8148 ospf = ifp->vrf->info;
8149 if (ospf) {
8150 oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr);
8151 if (oi)
8152 ospf_nbr_timer_update(oi);
8153 }
8154 } else {
8155 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn))
8156 if ((oi = rn->info))
8157 ospf_nbr_timer_update(oi);
8158 }
8159
8160 return CMD_SUCCESS;
8161 }
8162
8163 DEFUN_HIDDEN (no_ospf_dead_interval,
8164 no_ospf_dead_interval_cmd,
8165 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8166 NO_STR
8167 "OSPF interface commands\n"
8168 "Interval time after which a neighbor is declared down\n"
8169 "Seconds\n"
8170 "Minimal 1s dead-interval with fast sub-second hellos\n"
8171 "Hello multiplier factor\n"
8172 "Number of Hellos to send each second\n"
8173 "Address of interface\n")
8174 {
8175 return no_ip_ospf_dead_interval(self, vty, argc, argv);
8176 }
8177
8178 DEFUN (ip_ospf_hello_interval,
8179 ip_ospf_hello_interval_cmd,
8180 "ip ospf hello-interval (1-65535) [A.B.C.D]",
8181 "IP Information\n"
8182 "OSPF interface commands\n"
8183 "Time between HELLO packets\n"
8184 "Seconds\n"
8185 "Address of interface\n")
8186 {
8187 VTY_DECLVAR_CONTEXT(interface, ifp);
8188 int idx = 0;
8189 struct in_addr addr = {.s_addr = 0L};
8190 struct ospf_if_params *params;
8191 params = IF_DEF_PARAMS(ifp);
8192 uint32_t seconds = 0;
8193 bool is_addr = false;
8194 uint32_t old_interval = 0;
8195
8196 argv_find(argv, argc, "(1-65535)", &idx);
8197 seconds = strtol(argv[idx]->arg, NULL, 10);
8198
8199 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8200 if (!inet_aton(argv[idx]->arg, &addr)) {
8201 vty_out(vty,
8202 "Please specify interface address by A.B.C.D\n");
8203 return CMD_WARNING_CONFIG_FAILED;
8204 }
8205
8206 params = ospf_get_if_params(ifp, addr);
8207 ospf_if_update_params(ifp, addr);
8208 is_addr = true;
8209 }
8210
8211 old_interval = params->v_hello;
8212
8213 /* Return, if same interval is configured. */
8214 if (old_interval == seconds)
8215 return CMD_SUCCESS;
8216
8217 SET_IF_PARAM(params, v_hello);
8218 params->v_hello = seconds;
8219
8220 if (!params->is_v_wait_set) {
8221 SET_IF_PARAM(params, v_wait);
8222 /* As per RFC 4062
8223 * The router dead interval should
8224 * be some multiple of the HelloInterval (perhaps 4 times the
8225 * hello interval) and must be the same for all routers
8226 * attached to a common network.
8227 */
8228 params->v_wait = 4 * seconds;
8229 }
8230
8231 ospf_reset_hello_timer(ifp, addr, is_addr);
8232
8233 return CMD_SUCCESS;
8234 }
8235
8236 DEFUN_HIDDEN (ospf_hello_interval,
8237 ospf_hello_interval_cmd,
8238 "ospf hello-interval (1-65535) [A.B.C.D]",
8239 "OSPF interface commands\n"
8240 "Time between HELLO packets\n"
8241 "Seconds\n"
8242 "Address of interface\n")
8243 {
8244 return ip_ospf_hello_interval(self, vty, argc, argv);
8245 }
8246
8247 DEFUN (no_ip_ospf_hello_interval,
8248 no_ip_ospf_hello_interval_cmd,
8249 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
8250 NO_STR
8251 "IP Information\n"
8252 "OSPF interface commands\n"
8253 "Time between HELLO packets\n" // ignored
8254 "Seconds\n"
8255 "Address of interface\n")
8256 {
8257 VTY_DECLVAR_CONTEXT(interface, ifp);
8258 int idx = 0;
8259 struct in_addr addr = {.s_addr = 0L};
8260 struct ospf_if_params *params;
8261 struct route_node *rn;
8262
8263 params = IF_DEF_PARAMS(ifp);
8264
8265 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8266 if (!inet_aton(argv[idx]->arg, &addr)) {
8267 vty_out(vty,
8268 "Please specify interface address by A.B.C.D\n");
8269 return CMD_WARNING_CONFIG_FAILED;
8270 }
8271
8272 params = ospf_lookup_if_params(ifp, addr);
8273 if (params == NULL)
8274 return CMD_SUCCESS;
8275 }
8276
8277 UNSET_IF_PARAM(params, v_hello);
8278 params->v_hello = OSPF_HELLO_INTERVAL_DEFAULT;
8279
8280 if (!params->is_v_wait_set) {
8281 UNSET_IF_PARAM(params, v_wait);
8282 params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
8283 }
8284
8285 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8286 struct ospf_interface *oi = rn->info;
8287
8288 if (!oi)
8289 continue;
8290
8291 oi->type = IF_DEF_PARAMS(ifp)->type;
8292 oi->ptp_dmvpn = IF_DEF_PARAMS(ifp)->ptp_dmvpn;
8293
8294 if (oi->state > ISM_Down) {
8295 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown);
8296 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp);
8297 }
8298 }
8299
8300 if (params != IF_DEF_PARAMS(ifp)) {
8301 ospf_free_if_params(ifp, addr);
8302 ospf_if_update_params(ifp, addr);
8303 }
8304
8305 return CMD_SUCCESS;
8306 }
8307
8308 DEFUN_HIDDEN (no_ospf_hello_interval,
8309 no_ospf_hello_interval_cmd,
8310 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
8311 NO_STR
8312 "OSPF interface commands\n"
8313 "Time between HELLO packets\n" // ignored
8314 "Seconds\n"
8315 "Address of interface\n")
8316 {
8317 return no_ip_ospf_hello_interval(self, vty, argc, argv);
8318 }
8319
8320 DEFUN(ip_ospf_network, ip_ospf_network_cmd,
8321 "ip ospf network <broadcast|"
8322 "non-broadcast|"
8323 "point-to-multipoint [delay-reflood]|"
8324 "point-to-point [dmvpn]>",
8325 "IP Information\n"
8326 "OSPF interface commands\n"
8327 "Network type\n"
8328 "Specify OSPF broadcast multi-access network\n"
8329 "Specify OSPF NBMA network\n"
8330 "Specify OSPF point-to-multipoint network\n"
8331 "Specify OSPF delayed reflooding of LSAs received on P2MP interface\n"
8332 "Specify OSPF point-to-point network\n"
8333 "Specify OSPF point-to-point DMVPN network\n")
8334 {
8335 VTY_DECLVAR_CONTEXT(interface, ifp);
8336 int idx = 0;
8337 int old_type = IF_DEF_PARAMS(ifp)->type;
8338 uint8_t old_ptp_dmvpn = IF_DEF_PARAMS(ifp)->ptp_dmvpn;
8339 uint8_t old_p2mp_delay_reflood = IF_DEF_PARAMS(ifp)->p2mp_delay_reflood;
8340 struct route_node *rn;
8341
8342 if (old_type == OSPF_IFTYPE_LOOPBACK) {
8343 vty_out(vty,
8344 "This is a loopback interface. Can't set network type.\n");
8345 return CMD_WARNING_CONFIG_FAILED;
8346 }
8347
8348 IF_DEF_PARAMS(ifp)->ptp_dmvpn = 0;
8349 IF_DEF_PARAMS(ifp)->p2mp_delay_reflood =
8350 OSPF_P2MP_DELAY_REFLOOD_DEFAULT;
8351
8352 if (argv_find(argv, argc, "broadcast", &idx))
8353 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_BROADCAST;
8354 else if (argv_find(argv, argc, "non-broadcast", &idx))
8355 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_NBMA;
8356 else if (argv_find(argv, argc, "point-to-multipoint", &idx)) {
8357 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOMULTIPOINT;
8358 if (argv_find(argv, argc, "delay-reflood", &idx))
8359 IF_DEF_PARAMS(ifp)->p2mp_delay_reflood = true;
8360 } else if (argv_find(argv, argc, "point-to-point", &idx)) {
8361 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOPOINT;
8362 if (argv_find(argv, argc, "dmvpn", &idx))
8363 IF_DEF_PARAMS(ifp)->ptp_dmvpn = 1;
8364 }
8365
8366 if (IF_DEF_PARAMS(ifp)->type == old_type &&
8367 IF_DEF_PARAMS(ifp)->ptp_dmvpn == old_ptp_dmvpn &&
8368 IF_DEF_PARAMS(ifp)->p2mp_delay_reflood == old_p2mp_delay_reflood)
8369 return CMD_SUCCESS;
8370
8371 SET_IF_PARAM(IF_DEF_PARAMS(ifp), type);
8372
8373 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8374 struct ospf_interface *oi = rn->info;
8375
8376 if (!oi)
8377 continue;
8378
8379 oi->type = IF_DEF_PARAMS(ifp)->type;
8380 oi->ptp_dmvpn = IF_DEF_PARAMS(ifp)->ptp_dmvpn;
8381 oi->p2mp_delay_reflood = IF_DEF_PARAMS(ifp)->p2mp_delay_reflood;
8382
8383 /*
8384 * The OSPF interface only needs to be flapped if the network
8385 * type or DMVPN parameter changes.
8386 */
8387 if (IF_DEF_PARAMS(ifp)->type != old_type ||
8388 IF_DEF_PARAMS(ifp)->ptp_dmvpn != old_ptp_dmvpn) {
8389 if (oi->state > ISM_Down) {
8390 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown);
8391 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp);
8392 }
8393 }
8394 }
8395
8396 return CMD_SUCCESS;
8397 }
8398
8399 DEFUN_HIDDEN (ospf_network,
8400 ospf_network_cmd,
8401 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
8402 "OSPF interface commands\n"
8403 "Network type\n"
8404 "Specify OSPF broadcast multi-access network\n"
8405 "Specify OSPF NBMA network\n"
8406 "Specify OSPF point-to-multipoint network\n"
8407 "Specify OSPF point-to-point network\n")
8408 {
8409 return ip_ospf_network(self, vty, argc, argv);
8410 }
8411
8412 DEFUN (no_ip_ospf_network,
8413 no_ip_ospf_network_cmd,
8414 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8415 NO_STR
8416 "IP Information\n"
8417 "OSPF interface commands\n"
8418 "Network type\n"
8419 "Specify OSPF broadcast multi-access network\n"
8420 "Specify OSPF NBMA network\n"
8421 "Specify OSPF point-to-multipoint network\n"
8422 "Specify OSPF point-to-point network\n")
8423 {
8424 VTY_DECLVAR_CONTEXT(interface, ifp);
8425 int old_type = IF_DEF_PARAMS(ifp)->type;
8426 struct route_node *rn;
8427
8428 IF_DEF_PARAMS(ifp)->type = ospf_default_iftype(ifp);
8429 IF_DEF_PARAMS(ifp)->ptp_dmvpn = 0;
8430 IF_DEF_PARAMS(ifp)->p2mp_delay_reflood =
8431 OSPF_P2MP_DELAY_REFLOOD_DEFAULT;
8432
8433 if (IF_DEF_PARAMS(ifp)->type == old_type)
8434 return CMD_SUCCESS;
8435
8436 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8437 struct ospf_interface *oi = rn->info;
8438
8439 if (!oi)
8440 continue;
8441
8442 oi->type = IF_DEF_PARAMS(ifp)->type;
8443 oi->ptp_dmvpn = IF_DEF_PARAMS(ifp)->ptp_dmvpn;
8444 oi->p2mp_delay_reflood = IF_DEF_PARAMS(ifp)->p2mp_delay_reflood;
8445
8446 if (oi->state > ISM_Down) {
8447 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown);
8448 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp);
8449 }
8450 }
8451
8452 return CMD_SUCCESS;
8453 }
8454
8455 DEFUN_HIDDEN (no_ospf_network,
8456 no_ospf_network_cmd,
8457 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8458 NO_STR
8459 "OSPF interface commands\n"
8460 "Network type\n"
8461 "Specify OSPF broadcast multi-access network\n"
8462 "Specify OSPF NBMA network\n"
8463 "Specify OSPF point-to-multipoint network\n"
8464 "Specify OSPF point-to-point network\n")
8465 {
8466 return no_ip_ospf_network(self, vty, argc, argv);
8467 }
8468
8469 DEFUN (ip_ospf_priority,
8470 ip_ospf_priority_cmd,
8471 "ip ospf priority (0-255) [A.B.C.D]",
8472 "IP Information\n"
8473 "OSPF interface commands\n"
8474 "Router priority\n"
8475 "Priority\n"
8476 "Address of interface\n")
8477 {
8478 VTY_DECLVAR_CONTEXT(interface, ifp);
8479 int idx = 0;
8480 long priority;
8481 struct route_node *rn;
8482 struct in_addr addr;
8483 struct ospf_if_params *params;
8484 params = IF_DEF_PARAMS(ifp);
8485
8486 argv_find(argv, argc, "(0-255)", &idx);
8487 priority = strtol(argv[idx]->arg, NULL, 10);
8488
8489 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8490 if (!inet_aton(argv[idx]->arg, &addr)) {
8491 vty_out(vty,
8492 "Please specify interface address by A.B.C.D\n");
8493 return CMD_WARNING_CONFIG_FAILED;
8494 }
8495
8496 params = ospf_get_if_params(ifp, addr);
8497 ospf_if_update_params(ifp, addr);
8498 }
8499
8500 SET_IF_PARAM(params, priority);
8501 params->priority = priority;
8502
8503 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8504 struct ospf_interface *oi = rn->info;
8505
8506 if (!oi)
8507 continue;
8508
8509 if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) {
8510 PRIORITY(oi) = OSPF_IF_PARAM(oi, priority);
8511 OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange);
8512 }
8513 }
8514
8515 return CMD_SUCCESS;
8516 }
8517
8518 DEFUN_HIDDEN (ospf_priority,
8519 ospf_priority_cmd,
8520 "ospf priority (0-255) [A.B.C.D]",
8521 "OSPF interface commands\n"
8522 "Router priority\n"
8523 "Priority\n"
8524 "Address of interface\n")
8525 {
8526 return ip_ospf_priority(self, vty, argc, argv);
8527 }
8528
8529 DEFUN (no_ip_ospf_priority,
8530 no_ip_ospf_priority_cmd,
8531 "no ip ospf priority [(0-255) [A.B.C.D]]",
8532 NO_STR
8533 "IP Information\n"
8534 "OSPF interface commands\n"
8535 "Router priority\n" // ignored
8536 "Priority\n"
8537 "Address of interface\n")
8538 {
8539 VTY_DECLVAR_CONTEXT(interface, ifp);
8540 int idx = 0;
8541 struct route_node *rn;
8542 struct in_addr addr;
8543 struct ospf_if_params *params;
8544
8545 params = IF_DEF_PARAMS(ifp);
8546
8547 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8548 if (!inet_aton(argv[idx]->arg, &addr)) {
8549 vty_out(vty,
8550 "Please specify interface address by A.B.C.D\n");
8551 return CMD_WARNING_CONFIG_FAILED;
8552 }
8553
8554 params = ospf_lookup_if_params(ifp, addr);
8555 if (params == NULL)
8556 return CMD_SUCCESS;
8557 }
8558
8559 UNSET_IF_PARAM(params, priority);
8560 params->priority = OSPF_ROUTER_PRIORITY_DEFAULT;
8561
8562 if (params != IF_DEF_PARAMS(ifp)) {
8563 ospf_free_if_params(ifp, addr);
8564 ospf_if_update_params(ifp, addr);
8565 }
8566
8567 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8568 struct ospf_interface *oi = rn->info;
8569
8570 if (!oi)
8571 continue;
8572
8573 if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) {
8574 PRIORITY(oi) = OSPF_IF_PARAM(oi, priority);
8575 OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange);
8576 }
8577 }
8578
8579 return CMD_SUCCESS;
8580 }
8581
8582 DEFUN_HIDDEN (no_ospf_priority,
8583 no_ospf_priority_cmd,
8584 "no ospf priority [(0-255) [A.B.C.D]]",
8585 NO_STR
8586 "OSPF interface commands\n"
8587 "Router priority\n"
8588 "Priority\n"
8589 "Address of interface\n")
8590 {
8591 return no_ip_ospf_priority(self, vty, argc, argv);
8592 }
8593
8594 DEFUN (ip_ospf_retransmit_interval,
8595 ip_ospf_retransmit_interval_addr_cmd,
8596 "ip ospf retransmit-interval (1-65535) [A.B.C.D]",
8597 "IP Information\n"
8598 "OSPF interface commands\n"
8599 "Time between retransmitting lost link state advertisements\n"
8600 "Seconds\n"
8601 "Address of interface\n")
8602 {
8603 VTY_DECLVAR_CONTEXT(interface, ifp);
8604 int idx = 0;
8605 uint32_t seconds;
8606 struct in_addr addr;
8607 struct ospf_if_params *params;
8608 params = IF_DEF_PARAMS(ifp);
8609
8610 argv_find(argv, argc, "(1-65535)", &idx);
8611 seconds = strtol(argv[idx]->arg, NULL, 10);
8612
8613 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8614 if (!inet_aton(argv[idx]->arg, &addr)) {
8615 vty_out(vty,
8616 "Please specify interface address by A.B.C.D\n");
8617 return CMD_WARNING_CONFIG_FAILED;
8618 }
8619
8620 params = ospf_get_if_params(ifp, addr);
8621 ospf_if_update_params(ifp, addr);
8622 }
8623
8624 SET_IF_PARAM(params, retransmit_interval);
8625 params->retransmit_interval = seconds;
8626
8627 return CMD_SUCCESS;
8628 }
8629
8630 DEFUN_HIDDEN (ospf_retransmit_interval,
8631 ospf_retransmit_interval_cmd,
8632 "ospf retransmit-interval (1-65535) [A.B.C.D]",
8633 "OSPF interface commands\n"
8634 "Time between retransmitting lost link state advertisements\n"
8635 "Seconds\n"
8636 "Address of interface\n")
8637 {
8638 return ip_ospf_retransmit_interval(self, vty, argc, argv);
8639 }
8640
8641 DEFUN (no_ip_ospf_retransmit_interval,
8642 no_ip_ospf_retransmit_interval_addr_cmd,
8643 "no ip ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8644 NO_STR
8645 "IP Information\n"
8646 "OSPF interface commands\n"
8647 "Time between retransmitting lost link state advertisements\n"
8648 "Seconds\n"
8649 "Address of interface\n")
8650 {
8651 VTY_DECLVAR_CONTEXT(interface, ifp);
8652 int idx = 0;
8653 struct in_addr addr;
8654 struct ospf_if_params *params;
8655
8656 params = IF_DEF_PARAMS(ifp);
8657
8658 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8659 if (!inet_aton(argv[idx]->arg, &addr)) {
8660 vty_out(vty,
8661 "Please specify interface address by A.B.C.D\n");
8662 return CMD_WARNING_CONFIG_FAILED;
8663 }
8664
8665 params = ospf_lookup_if_params(ifp, addr);
8666 if (params == NULL)
8667 return CMD_SUCCESS;
8668 }
8669
8670 UNSET_IF_PARAM(params, retransmit_interval);
8671 params->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT;
8672
8673 if (params != IF_DEF_PARAMS(ifp)) {
8674 ospf_free_if_params(ifp, addr);
8675 ospf_if_update_params(ifp, addr);
8676 }
8677
8678 return CMD_SUCCESS;
8679 }
8680
8681 DEFUN_HIDDEN (no_ospf_retransmit_interval,
8682 no_ospf_retransmit_interval_cmd,
8683 "no ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8684 NO_STR
8685 "OSPF interface commands\n"
8686 "Time between retransmitting lost link state advertisements\n"
8687 "Seconds\n"
8688 "Address of interface\n")
8689 {
8690 return no_ip_ospf_retransmit_interval(self, vty, argc, argv);
8691 }
8692
8693 DEFPY (ip_ospf_gr_hdelay,
8694 ip_ospf_gr_hdelay_cmd,
8695 "ip ospf graceful-restart hello-delay (1-1800)",
8696 IP_STR
8697 "OSPF interface commands\n"
8698 "Graceful Restart parameters\n"
8699 "Delay the sending of the first hello packets.\n"
8700 "Delay in seconds\n")
8701 {
8702 VTY_DECLVAR_CONTEXT(interface, ifp);
8703 struct ospf_if_params *params;
8704
8705 params = IF_DEF_PARAMS(ifp);
8706
8707 /* Note: new or updated value won't affect ongoing graceful restart. */
8708 SET_IF_PARAM(params, v_gr_hello_delay);
8709 params->v_gr_hello_delay = hello_delay;
8710
8711 return CMD_SUCCESS;
8712 }
8713
8714 DEFPY (no_ip_ospf_gr_hdelay,
8715 no_ip_ospf_gr_hdelay_cmd,
8716 "no ip ospf graceful-restart hello-delay [(1-1800)]",
8717 NO_STR
8718 IP_STR
8719 "OSPF interface commands\n"
8720 "Graceful Restart parameters\n"
8721 "Delay the sending of the first hello packets.\n"
8722 "Delay in seconds\n")
8723 {
8724 VTY_DECLVAR_CONTEXT(interface, ifp);
8725 struct ospf_if_params *params;
8726 struct route_node *rn;
8727
8728 params = IF_DEF_PARAMS(ifp);
8729 UNSET_IF_PARAM(params, v_gr_hello_delay);
8730 params->v_gr_hello_delay = OSPF_HELLO_DELAY_DEFAULT;
8731
8732 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8733 struct ospf_interface *oi;
8734
8735 oi = rn->info;
8736 if (!oi)
8737 continue;
8738
8739 oi->gr.hello_delay.elapsed_seconds = 0;
8740 EVENT_OFF(oi->gr.hello_delay.t_grace_send);
8741 }
8742
8743 return CMD_SUCCESS;
8744 }
8745
8746 DEFUN (ip_ospf_transmit_delay,
8747 ip_ospf_transmit_delay_addr_cmd,
8748 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
8749 "IP Information\n"
8750 "OSPF interface commands\n"
8751 "Link state transmit delay\n"
8752 "Seconds\n"
8753 "Address of interface\n")
8754 {
8755 VTY_DECLVAR_CONTEXT(interface, ifp);
8756 int idx = 0;
8757 uint32_t seconds;
8758 struct in_addr addr;
8759 struct ospf_if_params *params;
8760
8761 params = IF_DEF_PARAMS(ifp);
8762 argv_find(argv, argc, "(1-65535)", &idx);
8763 seconds = strtol(argv[idx]->arg, NULL, 10);
8764
8765 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8766 if (!inet_aton(argv[idx]->arg, &addr)) {
8767 vty_out(vty,
8768 "Please specify interface address by A.B.C.D\n");
8769 return CMD_WARNING_CONFIG_FAILED;
8770 }
8771
8772 params = ospf_get_if_params(ifp, addr);
8773 ospf_if_update_params(ifp, addr);
8774 }
8775
8776 SET_IF_PARAM(params, transmit_delay);
8777 params->transmit_delay = seconds;
8778
8779 return CMD_SUCCESS;
8780 }
8781
8782 DEFUN_HIDDEN (ospf_transmit_delay,
8783 ospf_transmit_delay_cmd,
8784 "ospf transmit-delay (1-65535) [A.B.C.D]",
8785 "OSPF interface commands\n"
8786 "Link state transmit delay\n"
8787 "Seconds\n"
8788 "Address of interface\n")
8789 {
8790 return ip_ospf_transmit_delay(self, vty, argc, argv);
8791 }
8792
8793 DEFUN (no_ip_ospf_transmit_delay,
8794 no_ip_ospf_transmit_delay_addr_cmd,
8795 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
8796 NO_STR
8797 "IP Information\n"
8798 "OSPF interface commands\n"
8799 "Link state transmit delay\n"
8800 "Seconds\n"
8801 "Address of interface\n")
8802 {
8803 VTY_DECLVAR_CONTEXT(interface, ifp);
8804 int idx = 0;
8805 struct in_addr addr;
8806 struct ospf_if_params *params;
8807
8808 params = IF_DEF_PARAMS(ifp);
8809
8810 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8811 if (!inet_aton(argv[idx]->arg, &addr)) {
8812 vty_out(vty,
8813 "Please specify interface address by A.B.C.D\n");
8814 return CMD_WARNING_CONFIG_FAILED;
8815 }
8816
8817 params = ospf_lookup_if_params(ifp, addr);
8818 if (params == NULL)
8819 return CMD_SUCCESS;
8820 }
8821
8822 UNSET_IF_PARAM(params, transmit_delay);
8823 params->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT;
8824
8825 if (params != IF_DEF_PARAMS(ifp)) {
8826 ospf_free_if_params(ifp, addr);
8827 ospf_if_update_params(ifp, addr);
8828 }
8829
8830 return CMD_SUCCESS;
8831 }
8832
8833
8834 DEFUN_HIDDEN (no_ospf_transmit_delay,
8835 no_ospf_transmit_delay_cmd,
8836 "no ospf transmit-delay [(1-65535) [A.B.C.D]]",
8837 NO_STR
8838 "OSPF interface commands\n"
8839 "Link state transmit delay\n"
8840 "Seconds\n"
8841 "Address of interface\n")
8842 {
8843 return no_ip_ospf_transmit_delay(self, vty, argc, argv);
8844 }
8845
8846 DEFUN (ip_ospf_area,
8847 ip_ospf_area_cmd,
8848 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]",
8849 "IP Information\n"
8850 "OSPF interface commands\n"
8851 "Instance ID\n"
8852 "Enable OSPF on this interface\n"
8853 "OSPF area ID in IP address format\n"
8854 "OSPF area ID as a decimal value\n"
8855 "Address of interface\n")
8856 {
8857 VTY_DECLVAR_CONTEXT(interface, ifp);
8858 int idx = 0;
8859 int format, ret;
8860 struct in_addr area_id;
8861 struct in_addr addr;
8862 struct ospf_if_params *params = NULL;
8863 struct route_node *rn;
8864 struct ospf *ospf = NULL;
8865 unsigned short instance = 0;
8866 char *areaid;
8867 uint32_t count = 0;
8868
8869 if (argv_find(argv, argc, "(1-65535)", &idx))
8870 instance = strtol(argv[idx]->arg, NULL, 10);
8871
8872 argv_find(argv, argc, "area", &idx);
8873 areaid = argv[idx + 1]->arg;
8874
8875 if (!instance)
8876 ospf = ifp->vrf->info;
8877 else
8878 ospf = ospf_lookup_instance(instance);
8879
8880 if (instance && instance != ospf_instance) {
8881 /*
8882 * At this point we know we have received
8883 * an instance and there is no ospf instance
8884 * associated with it. This means we are
8885 * in a situation where we have an
8886 * ospf command that is setup for a different
8887 * process(instance). We need to safely
8888 * remove the command from ourselves and
8889 * allow the other instance(process) handle
8890 * the configuration command.
8891 */
8892 count = 0;
8893
8894 params = IF_DEF_PARAMS(ifp);
8895 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
8896 UNSET_IF_PARAM(params, if_area);
8897 count++;
8898 }
8899
8900 for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; rn = route_next(rn))
8901 if ((params = rn->info) && OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
8902 UNSET_IF_PARAM(params, if_area);
8903 count++;
8904 }
8905
8906 if (count > 0) {
8907 ospf = ifp->vrf->info;
8908 if (ospf)
8909 ospf_interface_area_unset(ospf, ifp);
8910 }
8911
8912 return CMD_NOT_MY_INSTANCE;
8913 }
8914
8915 ret = str2area_id(areaid, &area_id, &format);
8916 if (ret < 0) {
8917 vty_out(vty, "Please specify area by A.B.C.D|<0-4294967295>\n");
8918 return CMD_WARNING_CONFIG_FAILED;
8919 }
8920 if (memcmp(ifp->name, "VLINK", 5) == 0) {
8921 vty_out(vty, "Cannot enable OSPF on a virtual link.\n");
8922 return CMD_WARNING_CONFIG_FAILED;
8923 }
8924
8925 if (ospf) {
8926 for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) {
8927 if (rn->info != NULL) {
8928 vty_out(vty,
8929 "Please remove all network commands first.\n");
8930 return CMD_WARNING_CONFIG_FAILED;
8931 }
8932 }
8933 }
8934
8935 params = IF_DEF_PARAMS(ifp);
8936 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)
8937 && !IPV4_ADDR_SAME(&params->if_area, &area_id)) {
8938 vty_out(vty,
8939 "Must remove previous area config before changing ospf area \n");
8940 return CMD_WARNING_CONFIG_FAILED;
8941 }
8942
8943 // Check if we have an address arg and proccess it
8944 if (argc == idx + 3) {
8945 if (!inet_aton(argv[idx + 2]->arg, &addr)) {
8946 vty_out(vty,
8947 "Please specify Intf Address by A.B.C.D\n");
8948 return CMD_WARNING_CONFIG_FAILED;
8949 }
8950 // update/create address-level params
8951 params = ospf_get_if_params((ifp), (addr));
8952 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
8953 if (!IPV4_ADDR_SAME(&params->if_area, &area_id)) {
8954 vty_out(vty,
8955 "Must remove previous area/address config before changing ospf area\n");
8956 return CMD_WARNING_CONFIG_FAILED;
8957 } else
8958 return CMD_SUCCESS;
8959 }
8960 ospf_if_update_params((ifp), (addr));
8961 }
8962
8963 /* enable ospf on this interface with area_id */
8964 if (params) {
8965 SET_IF_PARAM(params, if_area);
8966 params->if_area = area_id;
8967 params->if_area_id_fmt = format;
8968 }
8969
8970 if (ospf)
8971 ospf_interface_area_set(ospf, ifp);
8972
8973 return CMD_SUCCESS;
8974 }
8975
8976 DEFUN (no_ip_ospf_area,
8977 no_ip_ospf_area_cmd,
8978 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]",
8979 NO_STR
8980 "IP Information\n"
8981 "OSPF interface commands\n"
8982 "Instance ID\n"
8983 "Disable OSPF on this interface\n"
8984 "OSPF area ID in IP address format\n"
8985 "OSPF area ID as a decimal value\n"
8986 "Address of interface\n")
8987 {
8988 VTY_DECLVAR_CONTEXT(interface, ifp);
8989 int idx = 0;
8990 struct ospf *ospf;
8991 struct ospf_if_params *params;
8992 unsigned short instance = 0;
8993 struct in_addr addr;
8994 struct in_addr area_id;
8995
8996 if (argv_find(argv, argc, "(1-65535)", &idx))
8997 instance = strtol(argv[idx]->arg, NULL, 10);
8998
8999 if (!instance)
9000 ospf = ifp->vrf->info;
9001 else
9002 ospf = ospf_lookup_instance(instance);
9003
9004 if (instance && instance != ospf_instance)
9005 return CMD_NOT_MY_INSTANCE;
9006
9007 argv_find(argv, argc, "area", &idx);
9008
9009 // Check if we have an address arg and proccess it
9010 if (argc == idx + 3) {
9011 if (!inet_aton(argv[idx + 2]->arg, &addr)) {
9012 vty_out(vty,
9013 "Please specify Intf Address by A.B.C.D\n");
9014 return CMD_WARNING_CONFIG_FAILED;
9015 }
9016 params = ospf_lookup_if_params(ifp, addr);
9017 if ((params) == NULL)
9018 return CMD_SUCCESS;
9019 } else
9020 params = IF_DEF_PARAMS(ifp);
9021
9022 area_id = params->if_area;
9023 if (!OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
9024 vty_out(vty,
9025 "Can't find specified interface area configuration.\n");
9026 return CMD_WARNING_CONFIG_FAILED;
9027 }
9028
9029 UNSET_IF_PARAM(params, if_area);
9030 if (params != IF_DEF_PARAMS((ifp))) {
9031 ospf_free_if_params((ifp), (addr));
9032 ospf_if_update_params((ifp), (addr));
9033 }
9034
9035 if (ospf) {
9036 ospf_interface_area_unset(ospf, ifp);
9037 ospf_area_check_free(ospf, area_id);
9038 }
9039
9040 return CMD_SUCCESS;
9041 }
9042
9043 DEFUN (ip_ospf_passive,
9044 ip_ospf_passive_cmd,
9045 "ip ospf passive [A.B.C.D]",
9046 "IP Information\n"
9047 "OSPF interface commands\n"
9048 "Suppress routing updates on an interface\n"
9049 "Address of interface\n")
9050 {
9051 VTY_DECLVAR_CONTEXT(interface, ifp);
9052 int idx_ipv4 = 3;
9053 struct in_addr addr = {.s_addr = INADDR_ANY};
9054 struct ospf_if_params *params;
9055 int ret;
9056
9057 if (argc == 4) {
9058 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
9059 if (!ret) {
9060 vty_out(vty,
9061 "Please specify interface address by A.B.C.D\n");
9062 return CMD_WARNING_CONFIG_FAILED;
9063 }
9064 params = ospf_get_if_params(ifp, addr);
9065 ospf_if_update_params(ifp, addr);
9066 } else {
9067 params = IF_DEF_PARAMS(ifp);
9068 }
9069
9070 ospf_passive_interface_update(ifp, params, addr, OSPF_IF_PASSIVE);
9071
9072 return CMD_SUCCESS;
9073 }
9074
9075 DEFUN (no_ip_ospf_passive,
9076 no_ip_ospf_passive_cmd,
9077 "no ip ospf passive [A.B.C.D]",
9078 NO_STR
9079 "IP Information\n"
9080 "OSPF interface commands\n"
9081 "Enable routing updates on an interface\n"
9082 "Address of interface\n")
9083 {
9084 VTY_DECLVAR_CONTEXT(interface, ifp);
9085 int idx_ipv4 = 4;
9086 struct in_addr addr = {.s_addr = INADDR_ANY};
9087 struct ospf_if_params *params;
9088 int ret;
9089
9090 if (argc == 5) {
9091 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
9092 if (!ret) {
9093 vty_out(vty,
9094 "Please specify interface address by A.B.C.D\n");
9095 return CMD_WARNING_CONFIG_FAILED;
9096 }
9097 params = ospf_lookup_if_params(ifp, addr);
9098 if (params == NULL)
9099 return CMD_SUCCESS;
9100 } else {
9101 params = IF_DEF_PARAMS(ifp);
9102 }
9103
9104 ospf_passive_interface_update(ifp, params, addr, OSPF_IF_ACTIVE);
9105
9106 return CMD_SUCCESS;
9107 }
9108
9109 DEFUN (ospf_redistribute_source,
9110 ospf_redistribute_source_cmd,
9111 "redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9112 REDIST_STR
9113 FRR_REDIST_HELP_STR_OSPFD
9114 "Metric for redistributed routes\n"
9115 "OSPF default metric\n"
9116 "OSPF exterior metric type for redistributed routes\n"
9117 "Set OSPF External Type 1/2 metrics\n"
9118 "Route map reference\n"
9119 "Pointer to route-map entries\n")
9120 {
9121 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9122 int idx_protocol = 1;
9123 int source;
9124 int type = -1;
9125 int metric = -1;
9126 struct ospf_redist *red;
9127 int idx = 0;
9128 bool update = false;
9129
9130 /* Get distribute source. */
9131 source = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
9132 if (source < 0)
9133 return CMD_WARNING_CONFIG_FAILED;
9134
9135 /* Get metric value. */
9136 if (argv_find(argv, argc, "(0-16777214)", &idx)) {
9137 if (!str2metric(argv[idx]->arg, &metric))
9138 return CMD_WARNING_CONFIG_FAILED;
9139 }
9140 idx = 1;
9141 /* Get metric type. */
9142 if (argv_find(argv, argc, "(1-2)", &idx)) {
9143 if (!str2metric_type(argv[idx]->arg, &type))
9144 return CMD_WARNING_CONFIG_FAILED;
9145 }
9146 idx = 1;
9147
9148 red = ospf_redist_lookup(ospf, source, 0);
9149 if (!red)
9150 red = ospf_redist_add(ospf, source, 0);
9151 else
9152 update = true;
9153
9154 /* Get route-map */
9155 if (argv_find(argv, argc, "route-map", &idx)) {
9156 ospf_routemap_set(red, argv[idx + 1]->arg);
9157 } else
9158 ospf_routemap_unset(red);
9159
9160 if (update)
9161 return ospf_redistribute_update(ospf, red, source, 0, type,
9162 metric);
9163 else
9164 return ospf_redistribute_set(ospf, red, source, 0, type,
9165 metric);
9166 }
9167
9168 DEFUN (no_ospf_redistribute_source,
9169 no_ospf_redistribute_source_cmd,
9170 "no redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9171 NO_STR
9172 REDIST_STR
9173 FRR_REDIST_HELP_STR_OSPFD
9174 "Metric for redistributed routes\n"
9175 "OSPF default metric\n"
9176 "OSPF exterior metric type for redistributed routes\n"
9177 "Set OSPF External Type 1/2 metrics\n"
9178 "Route map reference\n"
9179 "Pointer to route-map entries\n")
9180 {
9181 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9182 int idx_protocol = 2;
9183 int source;
9184 struct ospf_redist *red;
9185
9186 source = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
9187 if (source < 0)
9188 return CMD_WARNING_CONFIG_FAILED;
9189
9190 red = ospf_redist_lookup(ospf, source, 0);
9191 if (!red)
9192 return CMD_SUCCESS;
9193
9194 ospf_routemap_unset(red);
9195 ospf_redist_del(ospf, source, 0);
9196
9197 return ospf_redistribute_unset(ospf, source, 0);
9198 }
9199
9200 DEFUN (ospf_redistribute_instance_source,
9201 ospf_redistribute_instance_source_cmd,
9202 "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9203 REDIST_STR
9204 "Open Shortest Path First\n"
9205 "Non-main Kernel Routing Table\n"
9206 "Instance ID/Table ID\n"
9207 "Metric for redistributed routes\n"
9208 "OSPF default metric\n"
9209 "OSPF exterior metric type for redistributed routes\n"
9210 "Set OSPF External Type 1/2 metrics\n"
9211 "Route map reference\n"
9212 "Pointer to route-map entries\n")
9213 {
9214 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9215 int idx_ospf_table = 1;
9216 int idx_number = 2;
9217 int idx = 3;
9218 int source;
9219 int type = -1;
9220 int metric = -1;
9221 unsigned short instance;
9222 struct ospf_redist *red;
9223 bool update = false;
9224
9225 source = proto_redistnum(AFI_IP, argv[idx_ospf_table]->text);
9226
9227 if (source < 0) {
9228 vty_out(vty, "Unknown instance redistribution\n");
9229 return CMD_WARNING_CONFIG_FAILED;
9230 }
9231
9232 instance = strtoul(argv[idx_number]->arg, NULL, 10);
9233
9234 if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) {
9235 vty_out(vty,
9236 "Instance redistribution in non-instanced OSPF not allowed\n");
9237 return CMD_WARNING_CONFIG_FAILED;
9238 }
9239
9240 if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) {
9241 vty_out(vty, "Same instance OSPF redistribution not allowed\n");
9242 return CMD_WARNING_CONFIG_FAILED;
9243 }
9244
9245 /* Get metric value. */
9246 if (argv_find(argv, argc, "metric", &idx))
9247 if (!str2metric(argv[idx + 1]->arg, &metric))
9248 return CMD_WARNING_CONFIG_FAILED;
9249
9250 idx = 3;
9251 /* Get metric type. */
9252 if (argv_find(argv, argc, "metric-type", &idx))
9253 if (!str2metric_type(argv[idx + 1]->arg, &type))
9254 return CMD_WARNING_CONFIG_FAILED;
9255
9256 red = ospf_redist_lookup(ospf, source, instance);
9257 if (!red)
9258 red = ospf_redist_add(ospf, source, instance);
9259 else
9260 update = true;
9261
9262 idx = 3;
9263 if (argv_find(argv, argc, "route-map", &idx))
9264 ospf_routemap_set(red, argv[idx + 1]->arg);
9265 else
9266 ospf_routemap_unset(red);
9267
9268 if (update)
9269 return ospf_redistribute_update(ospf, red, source, instance,
9270 type, metric);
9271 else
9272 return ospf_redistribute_set(ospf, red, source, instance, type,
9273 metric);
9274 }
9275
9276 DEFUN (no_ospf_redistribute_instance_source,
9277 no_ospf_redistribute_instance_source_cmd,
9278 "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9279 NO_STR
9280 REDIST_STR
9281 "Open Shortest Path First\n"
9282 "Non-main Kernel Routing Table\n"
9283 "Instance ID/Table Id\n"
9284 "Metric for redistributed routes\n"
9285 "OSPF default metric\n"
9286 "OSPF exterior metric type for redistributed routes\n"
9287 "Set OSPF External Type 1/2 metrics\n"
9288 "Route map reference\n"
9289 "Pointer to route-map entries\n")
9290 {
9291 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9292 int idx_ospf_table = 2;
9293 int idx_number = 3;
9294 unsigned int instance;
9295 struct ospf_redist *red;
9296 int source;
9297
9298 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
9299 source = ZEBRA_ROUTE_OSPF;
9300 else
9301 source = ZEBRA_ROUTE_TABLE;
9302
9303 instance = strtoul(argv[idx_number]->arg, NULL, 10);
9304
9305 if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) {
9306 vty_out(vty,
9307 "Instance redistribution in non-instanced OSPF not allowed\n");
9308 return CMD_WARNING_CONFIG_FAILED;
9309 }
9310
9311 if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) {
9312 vty_out(vty, "Same instance OSPF redistribution not allowed\n");
9313 return CMD_WARNING_CONFIG_FAILED;
9314 }
9315
9316 red = ospf_redist_lookup(ospf, source, instance);
9317 if (!red)
9318 return CMD_SUCCESS;
9319
9320 ospf_routemap_unset(red);
9321 ospf_redist_del(ospf, source, instance);
9322
9323 return ospf_redistribute_unset(ospf, source, instance);
9324 }
9325
9326 DEFUN (ospf_distribute_list_out,
9327 ospf_distribute_list_out_cmd,
9328 "distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD,
9329 "Filter networks in routing updates\n"
9330 "Access-list name\n"
9331 OUT_STR
9332 FRR_REDIST_HELP_STR_OSPFD)
9333 {
9334 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9335 int idx_word = 1;
9336 int source;
9337
9338 char *proto = argv[argc - 1]->text;
9339
9340 /* Get distribute source. */
9341 source = proto_redistnum(AFI_IP, proto);
9342 if (source < 0)
9343 return CMD_WARNING_CONFIG_FAILED;
9344
9345 return ospf_distribute_list_out_set(ospf, source, argv[idx_word]->arg);
9346 }
9347
9348 DEFUN (no_ospf_distribute_list_out,
9349 no_ospf_distribute_list_out_cmd,
9350 "no distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD,
9351 NO_STR
9352 "Filter networks in routing updates\n"
9353 "Access-list name\n"
9354 OUT_STR
9355 FRR_REDIST_HELP_STR_OSPFD)
9356 {
9357 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9358 int idx_word = 2;
9359 int source;
9360
9361 char *proto = argv[argc - 1]->text;
9362 source = proto_redistnum(AFI_IP, proto);
9363 if (source < 0)
9364 return CMD_WARNING_CONFIG_FAILED;
9365
9366 return ospf_distribute_list_out_unset(ospf, source,
9367 argv[idx_word]->arg);
9368 }
9369
9370 /* Default information originate. */
9371 DEFUN (ospf_default_information_originate,
9372 ospf_default_information_originate_cmd,
9373 "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9374 "Control distribution of default information\n"
9375 "Distribute a default route\n"
9376 "Always advertise default route\n"
9377 "OSPF default metric\n"
9378 "OSPF metric\n"
9379 "OSPF metric type for default routes\n"
9380 "Set OSPF External Type 1/2 metrics\n"
9381 "Route map reference\n"
9382 "Pointer to route-map entries\n")
9383 {
9384 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9385 int default_originate = DEFAULT_ORIGINATE_ZEBRA;
9386 int type = -1;
9387 int metric = -1;
9388 struct ospf_redist *red;
9389 int idx = 0;
9390 int cur_originate = ospf->default_originate;
9391 bool sameRtmap = false;
9392 char *rtmap = NULL;
9393
9394 red = ospf_redist_add(ospf, DEFAULT_ROUTE, 0);
9395
9396 /* Check whether "always" was specified */
9397 if (argv_find(argv, argc, "always", &idx))
9398 default_originate = DEFAULT_ORIGINATE_ALWAYS;
9399 idx = 1;
9400 /* Get metric value */
9401 if (argv_find(argv, argc, "(0-16777214)", &idx)) {
9402 if (!str2metric(argv[idx]->arg, &metric))
9403 return CMD_WARNING_CONFIG_FAILED;
9404 }
9405 idx = 1;
9406 /* Get metric type. */
9407 if (argv_find(argv, argc, "(1-2)", &idx)) {
9408 if (!str2metric_type(argv[idx]->arg, &type))
9409 return CMD_WARNING_CONFIG_FAILED;
9410 }
9411 idx = 1;
9412 /* Get route-map */
9413 if (argv_find(argv, argc, "route-map", &idx))
9414 rtmap = argv[idx + 1]->arg;
9415
9416 /* To check if user is providing same route map */
9417 if ((!rtmap && !ROUTEMAP_NAME(red)) ||
9418 (rtmap && ROUTEMAP_NAME(red) &&
9419 (strcmp(rtmap, ROUTEMAP_NAME(red)) == 0)))
9420 sameRtmap = true;
9421
9422 /* Don't allow if the same lsa is already originated. */
9423 if ((sameRtmap)
9424 && (red->dmetric.type == type)
9425 && (red->dmetric.value == metric)
9426 && (cur_originate == default_originate))
9427 return CMD_SUCCESS;
9428
9429 /* Updating Metric details */
9430 red->dmetric.type = type;
9431 red->dmetric.value = metric;
9432
9433 /* updating route map details */
9434 if (rtmap)
9435 ospf_routemap_set(red, rtmap);
9436 else
9437 ospf_routemap_unset(red);
9438
9439 return ospf_redistribute_default_set(ospf, default_originate, type,
9440 metric);
9441 }
9442
9443 DEFUN (no_ospf_default_information_originate,
9444 no_ospf_default_information_originate_cmd,
9445 "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9446 NO_STR
9447 "Control distribution of default information\n"
9448 "Distribute a default route\n"
9449 "Always advertise default route\n"
9450 "OSPF default metric\n"
9451 "OSPF metric\n"
9452 "OSPF metric type for default routes\n"
9453 "Set OSPF External Type 1/2 metrics\n"
9454 "Route map reference\n"
9455 "Pointer to route-map entries\n")
9456 {
9457 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9458 struct ospf_redist *red;
9459
9460 red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0);
9461 if (!red)
9462 return CMD_SUCCESS;
9463
9464 ospf_routemap_unset(red);
9465 ospf_redist_del(ospf, DEFAULT_ROUTE, 0);
9466
9467 return ospf_redistribute_default_set(ospf, DEFAULT_ORIGINATE_NONE,
9468 0, 0);
9469 }
9470
9471 DEFUN (ospf_default_metric,
9472 ospf_default_metric_cmd,
9473 "default-metric (0-16777214)",
9474 "Set metric of redistributed routes\n"
9475 "Default metric\n")
9476 {
9477 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9478 int idx_number = 1;
9479 int metric = -1;
9480
9481 if (!str2metric(argv[idx_number]->arg, &metric))
9482 return CMD_WARNING_CONFIG_FAILED;
9483
9484 ospf->default_metric = metric;
9485
9486 return CMD_SUCCESS;
9487 }
9488
9489 DEFUN (no_ospf_default_metric,
9490 no_ospf_default_metric_cmd,
9491 "no default-metric [(0-16777214)]",
9492 NO_STR
9493 "Set metric of redistributed routes\n"
9494 "Default metric\n")
9495 {
9496 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9497
9498 ospf->default_metric = -1;
9499
9500 return CMD_SUCCESS;
9501 }
9502
9503
9504 DEFUN (ospf_distance,
9505 ospf_distance_cmd,
9506 "distance (1-255)",
9507 "Administrative distance\n"
9508 "OSPF Administrative distance\n")
9509 {
9510 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9511 int idx_number = 1;
9512 uint8_t distance;
9513
9514 distance = atoi(argv[idx_number]->arg);
9515 if (ospf->distance_all != distance) {
9516 ospf->distance_all = distance;
9517 ospf_restart_spf(ospf);
9518 }
9519
9520 return CMD_SUCCESS;
9521 }
9522
9523 DEFUN (no_ospf_distance,
9524 no_ospf_distance_cmd,
9525 "no distance (1-255)",
9526 NO_STR
9527 "Administrative distance\n"
9528 "OSPF Administrative distance\n")
9529 {
9530 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9531
9532 if (ospf->distance_all) {
9533 ospf->distance_all = 0;
9534 ospf_restart_spf(ospf);
9535 }
9536
9537 return CMD_SUCCESS;
9538 }
9539
9540 DEFUN (no_ospf_distance_ospf,
9541 no_ospf_distance_ospf_cmd,
9542 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
9543 NO_STR
9544 "Administrative distance\n"
9545 "OSPF administrative distance\n"
9546 "Intra-area routes\n"
9547 "Distance for intra-area routes\n"
9548 "Inter-area routes\n"
9549 "Distance for inter-area routes\n"
9550 "External routes\n"
9551 "Distance for external routes\n")
9552 {
9553 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9554 int idx = 0;
9555
9556 if (argv_find(argv, argc, "intra-area", &idx) || argc == 3)
9557 idx = ospf->distance_intra = 0;
9558 if (argv_find(argv, argc, "inter-area", &idx) || argc == 3)
9559 idx = ospf->distance_inter = 0;
9560 if (argv_find(argv, argc, "external", &idx) || argc == 3)
9561 ospf->distance_external = 0;
9562
9563 return CMD_SUCCESS;
9564 }
9565
9566 DEFUN (ospf_distance_ospf,
9567 ospf_distance_ospf_cmd,
9568 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
9569 "Administrative distance\n"
9570 "OSPF administrative distance\n"
9571 "Intra-area routes\n"
9572 "Distance for intra-area routes\n"
9573 "Inter-area routes\n"
9574 "Distance for inter-area routes\n"
9575 "External routes\n"
9576 "Distance for external routes\n")
9577 {
9578 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9579 int idx = 0;
9580
9581 ospf->distance_intra = 0;
9582 ospf->distance_inter = 0;
9583 ospf->distance_external = 0;
9584
9585 if (argv_find(argv, argc, "intra-area", &idx))
9586 ospf->distance_intra = atoi(argv[idx + 1]->arg);
9587 idx = 0;
9588 if (argv_find(argv, argc, "inter-area", &idx))
9589 ospf->distance_inter = atoi(argv[idx + 1]->arg);
9590 idx = 0;
9591 if (argv_find(argv, argc, "external", &idx))
9592 ospf->distance_external = atoi(argv[idx + 1]->arg);
9593
9594 return CMD_SUCCESS;
9595 }
9596
9597 DEFUN (ip_ospf_mtu_ignore,
9598 ip_ospf_mtu_ignore_addr_cmd,
9599 "ip ospf mtu-ignore [A.B.C.D]",
9600 "IP Information\n"
9601 "OSPF interface commands\n"
9602 "Disable MTU mismatch detection on this interface\n"
9603 "Address of interface\n")
9604 {
9605 VTY_DECLVAR_CONTEXT(interface, ifp);
9606 int idx_ipv4 = 3;
9607 struct in_addr addr;
9608 int ret;
9609
9610 struct ospf_if_params *params;
9611 params = IF_DEF_PARAMS(ifp);
9612
9613 if (argc == 4) {
9614 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
9615 if (!ret) {
9616 vty_out(vty,
9617 "Please specify interface address by A.B.C.D\n");
9618 return CMD_WARNING_CONFIG_FAILED;
9619 }
9620 params = ospf_get_if_params(ifp, addr);
9621 ospf_if_update_params(ifp, addr);
9622 }
9623 params->mtu_ignore = 1;
9624 if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT)
9625 SET_IF_PARAM(params, mtu_ignore);
9626 else {
9627 UNSET_IF_PARAM(params, mtu_ignore);
9628 if (params != IF_DEF_PARAMS(ifp)) {
9629 ospf_free_if_params(ifp, addr);
9630 ospf_if_update_params(ifp, addr);
9631 }
9632 }
9633 return CMD_SUCCESS;
9634 }
9635
9636 DEFUN (no_ip_ospf_mtu_ignore,
9637 no_ip_ospf_mtu_ignore_addr_cmd,
9638 "no ip ospf mtu-ignore [A.B.C.D]",
9639 NO_STR
9640 "IP Information\n"
9641 "OSPF interface commands\n"
9642 "Disable MTU mismatch detection on this interface\n"
9643 "Address of interface\n")
9644 {
9645 VTY_DECLVAR_CONTEXT(interface, ifp);
9646 int idx_ipv4 = 4;
9647 struct in_addr addr;
9648 int ret;
9649
9650 struct ospf_if_params *params;
9651 params = IF_DEF_PARAMS(ifp);
9652
9653 if (argc == 5) {
9654 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
9655 if (!ret) {
9656 vty_out(vty,
9657 "Please specify interface address by A.B.C.D\n");
9658 return CMD_WARNING_CONFIG_FAILED;
9659 }
9660 params = ospf_get_if_params(ifp, addr);
9661 ospf_if_update_params(ifp, addr);
9662 }
9663 params->mtu_ignore = 0;
9664 if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT)
9665 SET_IF_PARAM(params, mtu_ignore);
9666 else {
9667 UNSET_IF_PARAM(params, mtu_ignore);
9668 if (params != IF_DEF_PARAMS(ifp)) {
9669 ospf_free_if_params(ifp, addr);
9670 ospf_if_update_params(ifp, addr);
9671 }
9672 }
9673 return CMD_SUCCESS;
9674 }
9675
9676
9677 DEFUN (ospf_max_metric_router_lsa_admin,
9678 ospf_max_metric_router_lsa_admin_cmd,
9679 "max-metric router-lsa administrative",
9680 "OSPF maximum / infinite-distance metric\n"
9681 "Advertise own Router-LSA with infinite distance (stub router)\n"
9682 "Administratively applied, for an indefinite period\n")
9683 {
9684 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9685 struct listnode *ln;
9686 struct ospf_area *area;
9687
9688 for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
9689 SET_FLAG(area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED);
9690
9691 if (!CHECK_FLAG(area->stub_router_state,
9692 OSPF_AREA_IS_STUB_ROUTED))
9693 ospf_router_lsa_update_area(area);
9694 }
9695
9696 /* Allows for areas configured later to get the property */
9697 ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_SET;
9698
9699 return CMD_SUCCESS;
9700 }
9701
9702 DEFUN (no_ospf_max_metric_router_lsa_admin,
9703 no_ospf_max_metric_router_lsa_admin_cmd,
9704 "no max-metric router-lsa administrative",
9705 NO_STR
9706 "OSPF maximum / infinite-distance metric\n"
9707 "Advertise own Router-LSA with infinite distance (stub router)\n"
9708 "Administratively applied, for an indefinite period\n")
9709 {
9710 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9711 struct listnode *ln;
9712 struct ospf_area *area;
9713
9714 for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
9715 UNSET_FLAG(area->stub_router_state,
9716 OSPF_AREA_ADMIN_STUB_ROUTED);
9717
9718 /* Don't trample on the start-up stub timer */
9719 if (CHECK_FLAG(area->stub_router_state,
9720 OSPF_AREA_IS_STUB_ROUTED)
9721 && !area->t_stub_router) {
9722 UNSET_FLAG(area->stub_router_state,
9723 OSPF_AREA_IS_STUB_ROUTED);
9724 ospf_router_lsa_update_area(area);
9725 }
9726 }
9727 ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET;
9728 return CMD_SUCCESS;
9729 }
9730
9731 DEFUN (ospf_max_metric_router_lsa_startup,
9732 ospf_max_metric_router_lsa_startup_cmd,
9733 "max-metric router-lsa on-startup (5-86400)",
9734 "OSPF maximum / infinite-distance metric\n"
9735 "Advertise own Router-LSA with infinite distance (stub router)\n"
9736 "Automatically advertise stub Router-LSA on startup of OSPF\n"
9737 "Time (seconds) to advertise self as stub-router\n")
9738 {
9739 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9740 int idx_number = 3;
9741 unsigned int seconds;
9742
9743 if (argc < 4) {
9744 vty_out(vty, "%% Must supply stub-router period\n");
9745 return CMD_WARNING_CONFIG_FAILED;
9746 }
9747
9748 seconds = strtoul(argv[idx_number]->arg, NULL, 10);
9749
9750 ospf->stub_router_startup_time = seconds;
9751
9752 return CMD_SUCCESS;
9753 }
9754
9755 DEFUN (no_ospf_max_metric_router_lsa_startup,
9756 no_ospf_max_metric_router_lsa_startup_cmd,
9757 "no max-metric router-lsa on-startup [(5-86400)]",
9758 NO_STR
9759 "OSPF maximum / infinite-distance metric\n"
9760 "Advertise own Router-LSA with infinite distance (stub router)\n"
9761 "Automatically advertise stub Router-LSA on startup of OSPF\n"
9762 "Time (seconds) to advertise self as stub-router\n")
9763 {
9764 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9765 struct listnode *ln;
9766 struct ospf_area *area;
9767
9768 ospf->stub_router_startup_time = OSPF_STUB_ROUTER_UNCONFIGURED;
9769
9770 for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
9771 SET_FLAG(area->stub_router_state,
9772 OSPF_AREA_WAS_START_STUB_ROUTED);
9773 EVENT_OFF(area->t_stub_router);
9774
9775 /* Don't trample on admin stub routed */
9776 if (!CHECK_FLAG(area->stub_router_state,
9777 OSPF_AREA_ADMIN_STUB_ROUTED)) {
9778 UNSET_FLAG(area->stub_router_state,
9779 OSPF_AREA_IS_STUB_ROUTED);
9780 ospf_router_lsa_update_area(area);
9781 }
9782 }
9783 return CMD_SUCCESS;
9784 }
9785
9786
9787 DEFUN (ospf_max_metric_router_lsa_shutdown,
9788 ospf_max_metric_router_lsa_shutdown_cmd,
9789 "max-metric router-lsa on-shutdown (5-100)",
9790 "OSPF maximum / infinite-distance metric\n"
9791 "Advertise own Router-LSA with infinite distance (stub router)\n"
9792 "Advertise stub-router prior to full shutdown of OSPF\n"
9793 "Time (seconds) to wait till full shutdown\n")
9794 {
9795 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9796 int idx_number = 3;
9797 unsigned int seconds;
9798
9799 if (argc < 4) {
9800 vty_out(vty, "%% Must supply stub-router shutdown period\n");
9801 return CMD_WARNING_CONFIG_FAILED;
9802 }
9803
9804 seconds = strtoul(argv[idx_number]->arg, NULL, 10);
9805
9806 ospf->stub_router_shutdown_time = seconds;
9807
9808 return CMD_SUCCESS;
9809 }
9810
9811 DEFUN (no_ospf_max_metric_router_lsa_shutdown,
9812 no_ospf_max_metric_router_lsa_shutdown_cmd,
9813 "no max-metric router-lsa on-shutdown [(5-100)]",
9814 NO_STR
9815 "OSPF maximum / infinite-distance metric\n"
9816 "Advertise own Router-LSA with infinite distance (stub router)\n"
9817 "Advertise stub-router prior to full shutdown of OSPF\n"
9818 "Time (seconds) to wait till full shutdown\n")
9819 {
9820 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9821
9822 ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED;
9823
9824 return CMD_SUCCESS;
9825 }
9826
9827 DEFUN (ospf_proactive_arp,
9828 ospf_proactive_arp_cmd,
9829 "proactive-arp",
9830 "Allow sending ARP requests proactively\n")
9831 {
9832 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9833
9834 ospf->proactive_arp = true;
9835
9836 return CMD_SUCCESS;
9837 }
9838
9839 DEFUN (no_ospf_proactive_arp,
9840 no_ospf_proactive_arp_cmd,
9841 "no proactive-arp",
9842 NO_STR
9843 "Disallow sending ARP requests proactively\n")
9844 {
9845 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9846
9847 ospf->proactive_arp = false;
9848
9849 return CMD_SUCCESS;
9850 }
9851
9852 /* Graceful Restart HELPER Commands */
9853 DEFPY(ospf_gr_helper_enable, ospf_gr_helper_enable_cmd,
9854 "graceful-restart helper enable [A.B.C.D$address]",
9855 "OSPF Graceful Restart\n"
9856 "OSPF GR Helper\n"
9857 "Enable Helper support\n"
9858 "Advertising Router-ID\n")
9859 {
9860 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9861
9862 if (address_str) {
9863 ospf_gr_helper_support_set_per_routerid(ospf, &address,
9864 OSPF_GR_TRUE);
9865 return CMD_SUCCESS;
9866 }
9867
9868 ospf_gr_helper_support_set(ospf, OSPF_GR_TRUE);
9869
9870 return CMD_SUCCESS;
9871 }
9872
9873 DEFPY(no_ospf_gr_helper_enable,
9874 no_ospf_gr_helper_enable_cmd,
9875 "no graceful-restart helper enable [A.B.C.D$address]",
9876 NO_STR
9877 "OSPF Graceful Restart\n"
9878 "OSPF GR Helper\n"
9879 "Enable Helper support\n"
9880 "Advertising Router-ID\n")
9881 {
9882 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9883
9884 if (address_str) {
9885 ospf_gr_helper_support_set_per_routerid(ospf, &address,
9886 OSPF_GR_FALSE);
9887 return CMD_SUCCESS;
9888 }
9889
9890 ospf_gr_helper_support_set(ospf, OSPF_GR_FALSE);
9891 return CMD_SUCCESS;
9892 }
9893
9894 DEFPY(ospf_gr_helper_enable_lsacheck,
9895 ospf_gr_helper_enable_lsacheck_cmd,
9896 "graceful-restart helper strict-lsa-checking",
9897 "OSPF Graceful Restart\n"
9898 "OSPF GR Helper\n"
9899 "Enable strict LSA check\n")
9900 {
9901 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9902
9903 ospf_gr_helper_lsa_check_set(ospf, OSPF_GR_TRUE);
9904 return CMD_SUCCESS;
9905 }
9906
9907 DEFPY(no_ospf_gr_helper_enable_lsacheck,
9908 no_ospf_gr_helper_enable_lsacheck_cmd,
9909 "no graceful-restart helper strict-lsa-checking",
9910 NO_STR
9911 "OSPF Graceful Restart\n"
9912 "OSPF GR Helper\n"
9913 "Disable strict LSA check\n")
9914 {
9915 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9916
9917 ospf_gr_helper_lsa_check_set(ospf, OSPF_GR_FALSE);
9918 return CMD_SUCCESS;
9919 }
9920
9921 DEFPY(ospf_gr_helper_supported_grace_time,
9922 ospf_gr_helper_supported_grace_time_cmd,
9923 "graceful-restart helper supported-grace-time (10-1800)$interval",
9924 "OSPF Graceful Restart\n"
9925 "OSPF GR Helper\n"
9926 "Supported grace timer\n"
9927 "Grace interval(in seconds)\n")
9928 {
9929 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9930
9931 ospf_gr_helper_supported_gracetime_set(ospf, interval);
9932 return CMD_SUCCESS;
9933 }
9934
9935 DEFPY(no_ospf_gr_helper_supported_grace_time,
9936 no_ospf_gr_helper_supported_grace_time_cmd,
9937 "no graceful-restart helper supported-grace-time (10-1800)$interval",
9938 NO_STR
9939 "OSPF Graceful Restart\n"
9940 "OSPF GR Helper\n"
9941 "Supported grace timer\n"
9942 "Grace interval(in seconds)\n")
9943 {
9944 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9945
9946 ospf_gr_helper_supported_gracetime_set(ospf, OSPF_MAX_GRACE_INTERVAL);
9947 return CMD_SUCCESS;
9948 }
9949
9950 DEFPY(ospf_gr_helper_planned_only,
9951 ospf_gr_helper_planned_only_cmd,
9952 "graceful-restart helper planned-only",
9953 "OSPF Graceful Restart\n"
9954 "OSPF GR Helper\n"
9955 "Supported only planned restart\n")
9956 {
9957 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9958
9959 ospf_gr_helper_set_supported_planned_only_restart(ospf, OSPF_GR_TRUE);
9960
9961 return CMD_SUCCESS;
9962 }
9963
9964 /* External Route Aggregation */
9965 DEFUN (ospf_external_route_aggregation,
9966 ospf_external_route_aggregation_cmd,
9967 "summary-address A.B.C.D/M [tag (1-4294967295)]",
9968 "External summary address\n"
9969 "Summary address prefix\n"
9970 "Router tag \n"
9971 "Router tag value\n")
9972 {
9973 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9974 struct prefix_ipv4 p;
9975 int idx = 1;
9976 route_tag_t tag = 0;
9977 int ret = OSPF_SUCCESS;
9978
9979 str2prefix_ipv4(argv[idx]->arg, &p);
9980
9981 if (is_default_prefix4(&p)) {
9982 vty_out(vty,
9983 "Default address shouldn't be configured as summary address.\n");
9984 return CMD_SUCCESS;
9985 }
9986
9987 /* Apply mask for given prefix. */
9988 apply_mask(&p);
9989
9990 if (!is_valid_summary_addr(&p)) {
9991 vty_out(vty, "Not a valid summary address.\n");
9992 return CMD_WARNING_CONFIG_FAILED;
9993 }
9994
9995 if (argc > 2)
9996 tag = strtoul(argv[idx + 2]->arg, NULL, 10);
9997
9998 ret = ospf_asbr_external_aggregator_set(ospf, &p, tag);
9999 if (ret == OSPF_INVALID)
10000 vty_out(vty, "Invalid configuration!!\n");
10001
10002 return CMD_SUCCESS;
10003 }
10004
10005 DEFUN (no_ospf_external_route_aggregation,
10006 no_ospf_external_route_aggregation_cmd,
10007 "no summary-address A.B.C.D/M [tag (1-4294967295)]",
10008 NO_STR
10009 "External summary address\n"
10010 "Summary address prefix\n"
10011 "Router tag\n"
10012 "Router tag value\n")
10013 {
10014 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10015 struct prefix_ipv4 p;
10016 int idx = 2;
10017 route_tag_t tag = 0;
10018 int ret = OSPF_SUCCESS;
10019
10020 str2prefix_ipv4(argv[idx]->arg, &p);
10021
10022 if (is_default_prefix4(&p)) {
10023 vty_out(vty,
10024 "Default address shouldn't be configured as summary address.\n");
10025 return CMD_SUCCESS;
10026 }
10027
10028 /* Apply mask for given prefix. */
10029 apply_mask(&p);
10030
10031 if (!is_valid_summary_addr(&p)) {
10032 vty_out(vty, "Not a valid summary address.\n");
10033 return CMD_WARNING_CONFIG_FAILED;
10034 }
10035
10036 if (argc > 3)
10037 tag = strtoul(argv[idx + 2]->arg, NULL, 10);
10038
10039 ret = ospf_asbr_external_aggregator_unset(ospf, &p, tag);
10040 if (ret == OSPF_INVALID)
10041 vty_out(vty, "Invalid configuration!!\n");
10042
10043 return CMD_SUCCESS;
10044 }
10045
10046 DEFPY(no_ospf_gr_helper_planned_only,
10047 no_ospf_gr_helper_planned_only_cmd,
10048 "no graceful-restart helper planned-only",
10049 NO_STR
10050 "OSPF Graceful Restart\n"
10051 "OSPF GR Helper\n"
10052 "Supported only for planned restart\n")
10053 {
10054 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10055
10056 ospf_gr_helper_set_supported_planned_only_restart(ospf, OSPF_GR_FALSE);
10057
10058 return CMD_SUCCESS;
10059 }
10060
10061 static int ospf_print_vty_helper_dis_rtr_walkcb(struct hash_bucket *bucket,
10062 void *arg)
10063 {
10064 struct advRtr *rtr = bucket->data;
10065 struct vty *vty = (struct vty *)arg;
10066 static unsigned int count;
10067
10068 vty_out(vty, "%-6pI4,", &rtr->advRtrAddr);
10069 count++;
10070
10071 if (count % 5 == 0)
10072 vty_out(vty, "\n");
10073
10074 return HASHWALK_CONTINUE;
10075 }
10076
10077 static int ospf_print_json_helper_enabled_rtr_walkcb(struct hash_bucket *bucket,
10078 void *arg)
10079 {
10080 struct advRtr *rtr = bucket->data;
10081 struct json_object *json_rid_array = arg;
10082 struct json_object *json_rid;
10083
10084 json_rid = json_object_new_object();
10085
10086 json_object_string_addf(json_rid, "routerId", "%pI4", &rtr->advRtrAddr);
10087 json_object_array_add(json_rid_array, json_rid);
10088
10089 return HASHWALK_CONTINUE;
10090 }
10091
10092 static int ospf_show_gr_helper_details(struct vty *vty, struct ospf *ospf,
10093 uint8_t use_vrf, json_object *json,
10094 bool uj, bool detail)
10095 {
10096 struct listnode *node;
10097 struct ospf_interface *oi;
10098 char buf[PREFIX_STRLEN];
10099 json_object *json_vrf = NULL;
10100
10101 if (uj) {
10102 if (use_vrf)
10103 json_vrf = json_object_new_object();
10104 else
10105 json_vrf = json;
10106 }
10107
10108 if (ospf->instance) {
10109 if (uj)
10110 json_object_int_add(json, "ospfInstance",
10111 ospf->instance);
10112 else
10113 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
10114 }
10115
10116 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
10117
10118 if (uj) {
10119 if (use_vrf)
10120 json_object_object_add(json, ospf_get_name(ospf),
10121 json_vrf);
10122 } else
10123 vty_out(vty, "\n");
10124
10125 /* Show Router ID. */
10126 if (uj) {
10127 json_object_string_add(json_vrf, "routerId",
10128 inet_ntop(AF_INET, &ospf->router_id,
10129 buf, sizeof(buf)));
10130 } else {
10131 vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n",
10132 &ospf->router_id);
10133 }
10134
10135 if (!uj) {
10136
10137 if (ospf->is_helper_supported)
10138 vty_out(vty,
10139 " Graceful restart helper support enabled.\n");
10140 else
10141 vty_out(vty,
10142 " Graceful restart helper support disabled.\n");
10143
10144 if (ospf->strict_lsa_check)
10145 vty_out(vty, " Strict LSA check is enabled.\n");
10146 else
10147 vty_out(vty, " Strict LSA check is disabled.\n");
10148
10149 if (ospf->only_planned_restart)
10150 vty_out(vty,
10151 " Helper supported for planned restarts only.\n");
10152 else
10153 vty_out(vty,
10154 " Helper supported for Planned and Unplanned Restarts.\n");
10155
10156 vty_out(vty,
10157 " Supported Graceful restart interval: %d(in seconds).\n",
10158 ospf->supported_grace_time);
10159
10160 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf)) {
10161 vty_out(vty, " Enable Router list:\n");
10162 vty_out(vty, " ");
10163 hash_walk(ospf->enable_rtr_list,
10164 ospf_print_vty_helper_dis_rtr_walkcb, vty);
10165 vty_out(vty, "\n\n");
10166 }
10167
10168 if (ospf->last_exit_reason != OSPF_GR_HELPER_EXIT_NONE) {
10169 vty_out(vty, " Last Helper exit Reason :%s\n",
10170 ospf_exit_reason2str(ospf->last_exit_reason));
10171 }
10172
10173 if (ospf->active_restarter_cnt)
10174 vty_out(vty,
10175 " Number of Active neighbours in graceful restart: %d\n",
10176 ospf->active_restarter_cnt);
10177 else
10178 vty_out(vty, "\n");
10179
10180 } else {
10181 json_object_string_add(
10182 json_vrf, "helperSupport",
10183 (ospf->is_helper_supported) ? "Enabled" : "Disabled");
10184 json_object_string_add(json_vrf, "strictLsaCheck",
10185 (ospf->strict_lsa_check) ? "Enabled"
10186 : "Disabled");
10187 #if CONFDATE > 20240401
10188 CPP_NOTICE("Remove deprecated json key: restartSupoort")
10189 #endif
10190 json_object_string_add(
10191 json_vrf, "restartSupoort",
10192 (ospf->only_planned_restart)
10193 ? "Planned Restart only"
10194 : "Planned and Unplanned Restarts");
10195
10196 json_object_string_add(
10197 json_vrf, "restartSupport",
10198 (ospf->only_planned_restart)
10199 ? "Planned Restart only"
10200 : "Planned and Unplanned Restarts");
10201
10202 json_object_int_add(json_vrf, "supportedGracePeriod",
10203 ospf->supported_grace_time);
10204
10205 if (ospf->last_exit_reason != OSPF_GR_HELPER_EXIT_NONE)
10206 json_object_string_add(
10207 json_vrf, "lastExitReason",
10208 ospf_exit_reason2str(ospf->last_exit_reason));
10209
10210 if (ospf->active_restarter_cnt)
10211 json_object_int_add(json_vrf, "activeRestarterCnt",
10212 ospf->active_restarter_cnt);
10213
10214 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf)) {
10215 struct json_object *json_rid_array =
10216 json_object_new_array();
10217
10218 json_object_object_add(json_vrf, "enabledRouterIds",
10219 json_rid_array);
10220
10221 hash_walk(ospf->enable_rtr_list,
10222 ospf_print_json_helper_enabled_rtr_walkcb,
10223 json_rid_array);
10224 }
10225 }
10226
10227
10228 if (detail) {
10229 int cnt = 1;
10230 json_object *json_neighbors = NULL;
10231
10232 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
10233 struct route_node *rn;
10234 struct ospf_neighbor *nbr;
10235 json_object *json_neigh;
10236
10237 if (ospf_interface_neighbor_count(oi) == 0)
10238 continue;
10239
10240 if (uj) {
10241 json_object_object_get_ex(json_vrf, "neighbors",
10242 &json_neighbors);
10243 if (!json_neighbors) {
10244 json_neighbors =
10245 json_object_new_object();
10246 json_object_object_add(json_vrf,
10247 "neighbors",
10248 json_neighbors);
10249 }
10250 }
10251
10252 for (rn = route_top(oi->nbrs); rn;
10253 rn = route_next(rn)) {
10254
10255 if (!rn->info)
10256 continue;
10257
10258 nbr = rn->info;
10259
10260 if (!OSPF_GR_IS_ACTIVE_HELPER(nbr))
10261 continue;
10262
10263 if (!uj) {
10264 vty_out(vty, " Neighbour %d :\n", cnt);
10265 vty_out(vty, " Address : %pI4\n",
10266 &nbr->address.u.prefix4);
10267 vty_out(vty, " Routerid : %pI4\n",
10268 &nbr->router_id);
10269 vty_out(vty,
10270 " Received Grace period : %d(in seconds).\n",
10271 nbr->gr_helper_info
10272 .recvd_grace_period);
10273 vty_out(vty,
10274 " Actual Grace period : %d(in seconds)\n",
10275 nbr->gr_helper_info
10276 .actual_grace_period);
10277 vty_out(vty,
10278 " Remaining GraceTime:%ld(in seconds).\n",
10279 event_timer_remain_second(
10280 nbr->gr_helper_info
10281 .t_grace_timer));
10282 vty_out(vty,
10283 " Graceful Restart reason: %s.\n\n",
10284 ospf_restart_reason2str(
10285 nbr->gr_helper_info
10286 .gr_restart_reason));
10287 cnt++;
10288 } else {
10289 json_neigh = json_object_new_object();
10290 json_object_string_add(
10291 json_neigh, "srcAddr",
10292 inet_ntop(AF_INET, &nbr->src,
10293 buf, sizeof(buf)));
10294
10295 json_object_string_add(
10296 json_neigh, "routerid",
10297 inet_ntop(AF_INET,
10298 &nbr->router_id,
10299 buf, sizeof(buf)));
10300 json_object_int_add(
10301 json_neigh,
10302 "recvdGraceInterval",
10303 nbr->gr_helper_info
10304 .recvd_grace_period);
10305 json_object_int_add(
10306 json_neigh,
10307 "actualGraceInterval",
10308 nbr->gr_helper_info
10309 .actual_grace_period);
10310 json_object_int_add(
10311 json_neigh, "remainGracetime",
10312 event_timer_remain_second(
10313 nbr->gr_helper_info
10314 .t_grace_timer));
10315 json_object_string_add(
10316 json_neigh, "restartReason",
10317 ospf_restart_reason2str(
10318 nbr->gr_helper_info
10319 .gr_restart_reason));
10320 json_object_object_add(
10321 json_neighbors,
10322 inet_ntop(AF_INET, &nbr->src,
10323 buf, sizeof(buf)),
10324 json_neigh);
10325 }
10326 }
10327 }
10328 }
10329 return CMD_SUCCESS;
10330 }
10331
10332 DEFUN (ospf_external_route_aggregation_no_adrvertise,
10333 ospf_external_route_aggregation_no_adrvertise_cmd,
10334 "summary-address A.B.C.D/M no-advertise",
10335 "External summary address\n"
10336 "Summary address prefix\n"
10337 "Don't advertise summary route \n")
10338 {
10339 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10340 struct prefix_ipv4 p;
10341 int idx = 1;
10342 int ret = OSPF_SUCCESS;
10343
10344 str2prefix_ipv4(argv[idx]->arg, &p);
10345
10346 if (is_default_prefix4(&p)) {
10347 vty_out(vty,
10348 "Default address shouldn't be configured as summary address.\n");
10349 return CMD_SUCCESS;
10350 }
10351
10352 /* Apply mask for given prefix. */
10353 apply_mask(&p);
10354
10355 if (!is_valid_summary_addr(&p)) {
10356 vty_out(vty, "Not a valid summary address.\n");
10357 return CMD_WARNING_CONFIG_FAILED;
10358 }
10359
10360 ret = ospf_asbr_external_rt_no_advertise(ospf, &p);
10361 if (ret == OSPF_INVALID)
10362 vty_out(vty, "Invalid configuration!!\n");
10363
10364 return CMD_SUCCESS;
10365 }
10366
10367 DEFUN (no_ospf_external_route_aggregation_no_adrvertise,
10368 no_ospf_external_route_aggregation_no_adrvertise_cmd,
10369 "no summary-address A.B.C.D/M no-advertise",
10370 NO_STR
10371 "External summary address\n"
10372 "Summary address prefix\n"
10373 "Advertise summary route to the AS \n")
10374 {
10375 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10376 struct prefix_ipv4 p;
10377 int idx = 2;
10378 int ret = OSPF_SUCCESS;
10379
10380 str2prefix_ipv4(argv[idx]->arg, &p);
10381
10382 if (is_default_prefix4(&p)) {
10383 vty_out(vty,
10384 "Default address shouldn't be configured as summary address.\n");
10385 return CMD_SUCCESS;
10386 }
10387
10388 /* Apply mask for given prefix. */
10389 apply_mask(&p);
10390
10391 if (!is_valid_summary_addr(&p)) {
10392 vty_out(vty, "Not a valid summary address.\n");
10393 return CMD_WARNING_CONFIG_FAILED;
10394 }
10395
10396 ret = ospf_asbr_external_rt_advertise(ospf, &p);
10397 if (ret == OSPF_INVALID)
10398 vty_out(vty, "Invalid configuration!!\n");
10399
10400 return CMD_SUCCESS;
10401 }
10402
10403 DEFUN (ospf_route_aggregation_timer,
10404 ospf_route_aggregation_timer_cmd,
10405 "aggregation timer (5-1800)",
10406 "External route aggregation\n"
10407 "Delay timer (in seconds)\n"
10408 "Timer interval(in seconds)\n")
10409 {
10410 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10411 uint16_t interval = 0;
10412
10413 interval = strtoul(argv[2]->arg, NULL, 10);
10414
10415 ospf_external_aggregator_timer_set(ospf, interval);
10416
10417 return CMD_SUCCESS;
10418 }
10419
10420 DEFPY (show_ip_ospf_gr_helper,
10421 show_ip_ospf_gr_helper_cmd,
10422 "show ip ospf [vrf <NAME|all>] graceful-restart helper [detail] [json]",
10423 SHOW_STR
10424 IP_STR
10425 "OSPF information\n"
10426 VRF_CMD_HELP_STR
10427 "All VRFs\n"
10428 "OSPF Graceful Restart\n"
10429 "Helper details in the router\n"
10430 "Detailed information\n"
10431 JSON_STR)
10432 {
10433 char *vrf_name = NULL;
10434 bool all_vrf = false;
10435 int ret = CMD_SUCCESS;
10436 int idx_vrf = 0;
10437 int idx = 0;
10438 uint8_t use_vrf = 0;
10439 bool uj = use_json(argc, argv);
10440 struct ospf *ospf = NULL;
10441 json_object *json = NULL;
10442 struct listnode *node = NULL;
10443 int inst = 0;
10444 bool detail = false;
10445
10446 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
10447
10448 if (argv_find(argv, argc, "detail", &idx))
10449 detail = true;
10450
10451 if (uj)
10452 json = json_object_new_object();
10453
10454 /* vrf input is provided */
10455 if (vrf_name) {
10456 use_vrf = 1;
10457
10458 if (all_vrf) {
10459 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
10460 if (!ospf->oi_running)
10461 continue;
10462
10463 ret = ospf_show_gr_helper_details(
10464 vty, ospf, use_vrf, json, uj, detail);
10465 }
10466
10467 if (uj)
10468 vty_json(vty, json);
10469
10470 return ret;
10471 }
10472
10473 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
10474
10475 if (ospf == NULL || !ospf->oi_running) {
10476
10477 if (uj)
10478 vty_json(vty, json);
10479 else
10480 vty_out(vty,
10481 "%% OSPF is not enabled in vrf %s\n",
10482 vrf_name);
10483
10484 return CMD_SUCCESS;
10485 }
10486
10487 } else {
10488 /* Default Vrf */
10489 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
10490
10491 if (ospf == NULL || !ospf->oi_running) {
10492
10493 if (uj)
10494 vty_json(vty, json);
10495 else
10496 vty_out(vty,
10497 "%% OSPF is not enabled in vrf default\n");
10498
10499 return CMD_SUCCESS;
10500 }
10501
10502 ospf_show_gr_helper_details(vty, ospf, use_vrf, json, uj,
10503 detail);
10504 }
10505
10506 if (uj)
10507 vty_json(vty, json);
10508
10509 return CMD_SUCCESS;
10510 }
10511 /* Graceful Restart HELPER commands end */
10512 DEFUN (no_ospf_route_aggregation_timer,
10513 no_ospf_route_aggregation_timer_cmd,
10514 "no aggregation timer",
10515 NO_STR
10516 "External route aggregation\n"
10517 "Delay timer\n")
10518 {
10519 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10520
10521 ospf_external_aggregator_timer_set(ospf, OSPF_EXTL_AGGR_DEFAULT_DELAY);
10522
10523 return CMD_SUCCESS;
10524 }
10525
10526 /* External Route Aggregation End */
10527
10528 static void config_write_stub_router(struct vty *vty, struct ospf *ospf)
10529 {
10530 if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED)
10531 vty_out(vty, " max-metric router-lsa on-startup %u\n",
10532 ospf->stub_router_startup_time);
10533 if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED)
10534 vty_out(vty, " max-metric router-lsa on-shutdown %u\n",
10535 ospf->stub_router_shutdown_time);
10536 if (ospf->stub_router_admin_set == OSPF_STUB_ROUTER_ADMINISTRATIVE_SET)
10537 vty_out(vty, " max-metric router-lsa administrative\n");
10538
10539 return;
10540 }
10541
10542 static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf,
10543 struct route_table *rt,
10544 json_object *json)
10545 {
10546 struct route_node *rn;
10547 struct ospf_route * or ;
10548 struct listnode *pnode, *pnnode;
10549 struct ospf_path *path;
10550 json_object *json_route = NULL, *json_nexthop_array = NULL,
10551 *json_nexthop = NULL;
10552
10553 if (!json)
10554 vty_out(vty,
10555 "============ OSPF network routing table ============\n");
10556
10557 for (rn = route_top(rt); rn; rn = route_next(rn)) {
10558 char buf1[PREFIX2STR_BUFFER];
10559
10560 if ((or = rn->info) == NULL)
10561 continue;
10562
10563 prefix2str(&rn->p, buf1, sizeof(buf1));
10564
10565 if (json) {
10566 json_route = json_object_new_object();
10567 json_object_object_add(json, buf1, json_route);
10568 }
10569
10570 switch (or->path_type) {
10571 case OSPF_PATH_INTER_AREA:
10572 if (or->type == OSPF_DESTINATION_NETWORK) {
10573 if (json) {
10574 json_object_string_add(json_route,
10575 "routeType",
10576 "N IA");
10577 json_object_int_add(json_route, "cost",
10578 or->cost);
10579 json_object_string_addf(
10580 json_route, "area", "%pI4",
10581 &or->u.std.area_id);
10582 } else {
10583 vty_out(vty,
10584 "N IA %-18s [%d] area: %pI4\n",
10585 buf1, or->cost,
10586 &or->u.std.area_id);
10587 }
10588 } else if (or->type == OSPF_DESTINATION_DISCARD) {
10589 if (json) {
10590 json_object_string_add(json_route,
10591 "routeType",
10592 "D IA");
10593 } else {
10594 vty_out(vty,
10595 "D IA %-18s Discard entry\n",
10596 buf1);
10597 }
10598 }
10599 break;
10600 case OSPF_PATH_INTRA_AREA:
10601 if (json) {
10602 json_object_string_add(json_route, "routeType",
10603 "N");
10604 json_object_int_add(json_route, "cost",
10605 or->cost);
10606 json_object_string_addf(json_route, "area",
10607 "%pI4",
10608 &or->u.std.area_id);
10609 } else {
10610 vty_out(vty, "N %-18s [%d] area: %pI4\n",
10611 buf1, or->cost,
10612 &or->u.std.area_id);
10613 }
10614 break;
10615 default:
10616 break;
10617 }
10618
10619 if (or->type == OSPF_DESTINATION_NETWORK) {
10620 if (json) {
10621 json_nexthop_array = json_object_new_array();
10622 json_object_object_add(json_route, "nexthops",
10623 json_nexthop_array);
10624 }
10625
10626 for (ALL_LIST_ELEMENTS(or->paths, pnode, pnnode,
10627 path)) {
10628 if (json) {
10629 json_nexthop = json_object_new_object();
10630 json_object_array_add(
10631 json_nexthop_array,
10632 json_nexthop);
10633 }
10634 if (if_lookup_by_index(path->ifindex,
10635 ospf->vrf_id)) {
10636
10637 if (path->nexthop.s_addr
10638 == INADDR_ANY) {
10639 if (json) {
10640 json_object_string_add(
10641 json_nexthop,
10642 "ip", " ");
10643 json_object_string_add(
10644 json_nexthop,
10645 "directlyAttachedTo",
10646 ifindex2ifname(
10647 path->ifindex,
10648 ospf->vrf_id));
10649 } else {
10650 vty_out(vty,
10651 "%24s directly attached to %s\n",
10652 "",
10653 ifindex2ifname(
10654 path->ifindex,
10655 ospf->vrf_id));
10656 }
10657 } else {
10658 if (json) {
10659 json_object_string_addf(
10660 json_nexthop,
10661 "ip", "%pI4",
10662 &path->nexthop);
10663 json_object_string_add(
10664 json_nexthop,
10665 "via",
10666 ifindex2ifname(
10667 path->ifindex,
10668 ospf->vrf_id));
10669 } else {
10670 vty_out(vty,
10671 "%24s via %pI4, %s\n",
10672 "",
10673 &path->nexthop,
10674 ifindex2ifname(
10675 path->ifindex,
10676 ospf->vrf_id));
10677 }
10678 }
10679 }
10680 }
10681 }
10682 }
10683 if (!json)
10684 vty_out(vty, "\n");
10685 }
10686
10687 static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf,
10688 struct route_table *rtrs,
10689 json_object *json)
10690 {
10691 struct route_node *rn;
10692 struct ospf_route * or ;
10693 struct listnode *pnode;
10694 struct listnode *node;
10695 struct ospf_path *path;
10696 char buf[PREFIX_STRLEN];
10697 json_object *json_route = NULL, *json_nexthop_array = NULL,
10698 *json_nexthop = NULL;
10699
10700 if (!json)
10701 vty_out(vty, "============ OSPF %s table =============\n",
10702 ospf->all_rtrs == rtrs ? "reachable routers"
10703 : "router routing");
10704
10705 for (rn = route_top(rtrs); rn; rn = route_next(rn)) {
10706 if (rn->info == NULL)
10707 continue;
10708 int flag = 0;
10709
10710 if (json) {
10711 json_route = json_object_new_object();
10712 json_object_object_add(
10713 json, inet_ntop(AF_INET, &rn->p.u.prefix4,
10714 buf, sizeof(buf)),
10715 json_route);
10716 json_object_string_add(json_route, "routeType", "R ");
10717 } else {
10718 vty_out(vty, "R %-15pI4 ",
10719 &rn->p.u.prefix4);
10720 }
10721
10722 for (ALL_LIST_ELEMENTS_RO((struct list *)rn->info, node, or)) {
10723 if (flag++) {
10724 if (!json)
10725 vty_out(vty, "%24s", "");
10726 }
10727
10728 /* Show path. */
10729 if (json) {
10730 json_object_int_add(json_route, "cost",
10731 or->cost);
10732 json_object_string_addf(json_route, "area",
10733 "%pI4",
10734 &or->u.std.area_id);
10735 if (or->path_type == OSPF_PATH_INTER_AREA) {
10736 json_object_boolean_true_add(json_route,
10737 "IA");
10738 json_object_boolean_true_add(json_route,
10739 "ia");
10740 }
10741 if (or->u.std.flags & ROUTER_LSA_BORDER)
10742 json_object_string_add(json_route,
10743 "routerType",
10744 "abr");
10745 else if (or->u.std.flags & ROUTER_LSA_EXTERNAL)
10746 json_object_string_add(json_route,
10747 "routerType",
10748 "asbr");
10749 } else {
10750 vty_out(vty, "%s [%d] area: %pI4",
10751 (or->path_type == OSPF_PATH_INTER_AREA
10752 ? "IA"
10753 : " "),
10754 or->cost, &or->u.std.area_id);
10755 /* Show flags. */
10756 vty_out(vty, "%s%s\n",
10757 (or->u.std.flags & ROUTER_LSA_BORDER
10758 ? ", ABR"
10759 : ""),
10760 (or->u.std.flags & ROUTER_LSA_EXTERNAL
10761 ? ", ASBR"
10762 : ""));
10763 }
10764
10765 if (json) {
10766 json_nexthop_array = json_object_new_array();
10767 json_object_object_add(json_route, "nexthops",
10768 json_nexthop_array);
10769 }
10770
10771 for (ALL_LIST_ELEMENTS_RO(or->paths, pnode, path)) {
10772 if (json) {
10773 json_nexthop = json_object_new_object();
10774 json_object_array_add(
10775 json_nexthop_array,
10776 json_nexthop);
10777 }
10778 if (if_lookup_by_index(path->ifindex,
10779 ospf->vrf_id)) {
10780 if (path->nexthop.s_addr
10781 == INADDR_ANY) {
10782 if (json) {
10783 json_object_string_add(
10784 json_nexthop,
10785 "ip", " ");
10786 json_object_string_add(
10787 json_nexthop,
10788 "directlyAttachedTo",
10789 ifindex2ifname(
10790 path->ifindex,
10791 ospf->vrf_id));
10792 } else {
10793 vty_out(vty,
10794 "%24s directly attached to %s\n",
10795 "",
10796 ifindex2ifname(
10797 path->ifindex,
10798 ospf->vrf_id));
10799 }
10800 } else {
10801 if (json) {
10802 json_object_string_addf(
10803 json_nexthop,
10804 "ip", "%pI4",
10805 &path->nexthop);
10806 json_object_string_add(
10807 json_nexthop,
10808 "via",
10809 ifindex2ifname(
10810 path->ifindex,
10811 ospf->vrf_id));
10812 } else {
10813 vty_out(vty,
10814 "%24s via %pI4, %s\n",
10815 "",
10816 &path->nexthop,
10817 ifindex2ifname(
10818 path->ifindex,
10819 ospf->vrf_id));
10820 }
10821 }
10822 }
10823 }
10824 }
10825 }
10826 if (!json)
10827 vty_out(vty, "\n");
10828 }
10829
10830 static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf,
10831 struct route_table *rt,
10832 json_object *json)
10833 {
10834 struct route_node *rn;
10835 struct ospf_route *er;
10836 struct listnode *pnode, *pnnode;
10837 struct ospf_path *path;
10838 json_object *json_route = NULL, *json_nexthop_array = NULL,
10839 *json_nexthop = NULL;
10840
10841 if (!json)
10842 vty_out(vty,
10843 "============ OSPF external routing table ===========\n");
10844
10845 for (rn = route_top(rt); rn; rn = route_next(rn)) {
10846 if ((er = rn->info) == NULL)
10847 continue;
10848
10849 char buf1[19];
10850
10851 snprintfrr(buf1, sizeof(buf1), "%pFX", &rn->p);
10852 if (json) {
10853 json_route = json_object_new_object();
10854 json_object_object_add(json, buf1, json_route);
10855 }
10856
10857 switch (er->path_type) {
10858 case OSPF_PATH_TYPE1_EXTERNAL:
10859 if (json) {
10860 json_object_string_add(json_route, "routeType",
10861 "N E1");
10862 json_object_int_add(json_route, "cost",
10863 er->cost);
10864 json_object_int_add(json_route, "tag",
10865 er->u.ext.tag);
10866 } else {
10867 vty_out(vty,
10868 "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI
10869 "\n",
10870 buf1, er->cost, er->u.ext.tag);
10871 }
10872 break;
10873 case OSPF_PATH_TYPE2_EXTERNAL:
10874 if (json) {
10875 json_object_string_add(json_route, "routeType",
10876 "N E2");
10877 json_object_int_add(json_route, "cost",
10878 er->cost);
10879 json_object_int_add(json_route, "type2cost",
10880 er->u.ext.type2_cost);
10881 json_object_int_add(json_route, "tag",
10882 er->u.ext.tag);
10883 } else {
10884 vty_out(vty,
10885 "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI
10886 "\n",
10887 buf1, er->cost, er->u.ext.type2_cost,
10888 er->u.ext.tag);
10889 }
10890 break;
10891 }
10892
10893 if (json) {
10894 json_nexthop_array = json_object_new_array();
10895 json_object_object_add(json_route, "nexthops",
10896 json_nexthop_array);
10897 }
10898
10899 for (ALL_LIST_ELEMENTS(er->paths, pnode, pnnode, path)) {
10900 if (json) {
10901 json_nexthop = json_object_new_object();
10902 json_object_array_add(json_nexthop_array,
10903 json_nexthop);
10904 }
10905
10906 if (if_lookup_by_index(path->ifindex, ospf->vrf_id)) {
10907 if (path->nexthop.s_addr == INADDR_ANY) {
10908 if (json) {
10909 json_object_string_add(
10910 json_nexthop, "ip",
10911 " ");
10912 json_object_string_add(
10913 json_nexthop,
10914 "directlyAttachedTo",
10915 ifindex2ifname(
10916 path->ifindex,
10917 ospf->vrf_id));
10918 } else {
10919 vty_out(vty,
10920 "%24s directly attached to %s\n",
10921 "",
10922 ifindex2ifname(
10923 path->ifindex,
10924 ospf->vrf_id));
10925 }
10926 } else {
10927 if (json) {
10928 json_object_string_addf(
10929 json_nexthop, "ip",
10930 "%pI4", &path->nexthop);
10931 json_object_string_add(
10932 json_nexthop, "via",
10933 ifindex2ifname(
10934 path->ifindex,
10935 ospf->vrf_id));
10936 } else {
10937 vty_out(vty,
10938 "%24s via %pI4, %s\n",
10939 "",
10940 &path->nexthop,
10941 ifindex2ifname(
10942 path->ifindex,
10943 ospf->vrf_id));
10944 }
10945 }
10946 }
10947 }
10948 }
10949 if (!json)
10950 vty_out(vty, "\n");
10951 }
10952
10953 static int show_ip_ospf_reachable_routers_common(struct vty *vty,
10954 struct ospf *ospf,
10955 uint8_t use_vrf)
10956 {
10957 if (ospf->instance)
10958 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
10959
10960 ospf_show_vrf_name(ospf, vty, NULL, use_vrf);
10961
10962 if (ospf->all_rtrs == NULL) {
10963 vty_out(vty, "No OSPF reachable router information exist\n");
10964 return CMD_SUCCESS;
10965 }
10966
10967 /* Show Router routes. */
10968 show_ip_ospf_route_router(vty, ospf, ospf->all_rtrs, NULL);
10969
10970 vty_out(vty, "\n");
10971
10972 return CMD_SUCCESS;
10973 }
10974
10975 DEFUN (show_ip_ospf_reachable_routers,
10976 show_ip_ospf_reachable_routers_cmd,
10977 "show ip ospf [vrf <NAME|all>] reachable-routers",
10978 SHOW_STR
10979 IP_STR
10980 "OSPF information\n"
10981 VRF_CMD_HELP_STR
10982 "All VRFs\n"
10983 "Show all the reachable OSPF routers\n")
10984 {
10985 struct ospf *ospf = NULL;
10986 struct listnode *node = NULL;
10987 char *vrf_name = NULL;
10988 bool all_vrf = false;
10989 int ret = CMD_SUCCESS;
10990 int inst = 0;
10991 int idx_vrf = 0;
10992 uint8_t use_vrf = 0;
10993
10994 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
10995
10996 if (vrf_name) {
10997 bool ospf_output = false;
10998
10999 use_vrf = 1;
11000
11001 if (all_vrf) {
11002 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11003 if (!ospf->oi_running)
11004 continue;
11005
11006 ospf_output = true;
11007 ret = show_ip_ospf_reachable_routers_common(
11008 vty, ospf, use_vrf);
11009 }
11010
11011 if (!ospf_output)
11012 vty_out(vty, "%% OSPF instance not found\n");
11013 } else {
11014 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
11015 if (ospf == NULL || !ospf->oi_running) {
11016 vty_out(vty, "%% OSPF instance not found\n");
11017 return CMD_SUCCESS;
11018 }
11019
11020 ret = show_ip_ospf_reachable_routers_common(vty, ospf,
11021 use_vrf);
11022 }
11023 } else {
11024 /* Display default ospf (instance 0) info */
11025 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
11026 if (ospf == NULL || !ospf->oi_running) {
11027 vty_out(vty, "%% OSPF instance not found\n");
11028 return CMD_SUCCESS;
11029 }
11030
11031 ret = show_ip_ospf_reachable_routers_common(vty, ospf, use_vrf);
11032 }
11033
11034 return ret;
11035 }
11036
11037 DEFUN (show_ip_ospf_instance_reachable_routers,
11038 show_ip_ospf_instance_reachable_routers_cmd,
11039 "show ip ospf (1-65535) reachable-routers",
11040 SHOW_STR
11041 IP_STR
11042 "OSPF information\n"
11043 "Instance ID\n"
11044 "Show all the reachable OSPF routers\n")
11045 {
11046 int idx_number = 3;
11047 struct ospf *ospf;
11048 unsigned short instance = 0;
11049
11050 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11051 if (instance != ospf_instance)
11052 return CMD_NOT_MY_INSTANCE;
11053
11054 ospf = ospf_lookup_instance(instance);
11055 if (!ospf || !ospf->oi_running)
11056 return CMD_SUCCESS;
11057
11058 return show_ip_ospf_reachable_routers_common(vty, ospf, 0);
11059 }
11060
11061 static int show_ip_ospf_border_routers_common(struct vty *vty,
11062 struct ospf *ospf,
11063 uint8_t use_vrf,
11064 json_object *json)
11065 {
11066 json_object *json_vrf = NULL;
11067 json_object *json_router = NULL;
11068
11069 if (json) {
11070 if (use_vrf)
11071 json_vrf = json_object_new_object();
11072 else
11073 json_vrf = json;
11074 json_router = json_object_new_object();
11075 }
11076
11077 if (ospf->instance) {
11078 if (!json)
11079 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
11080 else
11081 json_object_int_add(json_vrf, "ospfInstance",
11082 ospf->instance);
11083 }
11084
11085 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
11086
11087 if (ospf->new_table == NULL) {
11088 if (!json)
11089 vty_out(vty, "No OSPF routing information exist\n");
11090 else {
11091 json_object_free(json_router);
11092 if (use_vrf)
11093 json_object_free(json_vrf);
11094 }
11095 return CMD_SUCCESS;
11096 }
11097
11098 /* Show Network routes.
11099 show_ip_ospf_route_network (vty, ospf->new_table); */
11100
11101 /* Show Router routes. */
11102 show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, json_router);
11103
11104 if (json) {
11105 json_object_object_add(json_vrf, "routers", json_router);
11106 if (use_vrf) {
11107 if (ospf->vrf_id == VRF_DEFAULT)
11108 json_object_object_add(json, "default",
11109 json_vrf);
11110 else
11111 json_object_object_add(json, ospf->name,
11112 json_vrf);
11113 }
11114 } else {
11115 vty_out(vty, "\n");
11116 }
11117
11118 return CMD_SUCCESS;
11119 }
11120
11121 DEFPY (show_ip_ospf_border_routers,
11122 show_ip_ospf_border_routers_cmd,
11123 "show ip ospf [vrf <NAME|all>] border-routers [json]",
11124 SHOW_STR
11125 IP_STR
11126 "OSPF information\n"
11127 VRF_CMD_HELP_STR
11128 "All VRFs\n"
11129 "Show all the ABR's and ASBR's\n"
11130 JSON_STR)
11131 {
11132 struct ospf *ospf = NULL;
11133 struct listnode *node = NULL;
11134 char *vrf_name = NULL;
11135 bool all_vrf = false;
11136 int ret = CMD_SUCCESS;
11137 int inst = 0;
11138 int idx_vrf = 0;
11139 uint8_t use_vrf = 0;
11140 bool uj = use_json(argc, argv);
11141 json_object *json = NULL;
11142
11143 if (uj)
11144 json = json_object_new_object();
11145
11146 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
11147
11148 if (vrf_name) {
11149 bool ospf_output = false;
11150
11151 use_vrf = 1;
11152
11153 if (all_vrf) {
11154 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11155 if (!ospf->oi_running)
11156 continue;
11157
11158 ospf_output = true;
11159 ret = show_ip_ospf_border_routers_common(
11160 vty, ospf, use_vrf, json);
11161 }
11162
11163 if (uj)
11164 vty_json(vty, json);
11165 else if (!ospf_output)
11166 vty_out(vty, "%% OSPF is not enabled\n");
11167
11168 return ret;
11169 } else {
11170 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
11171 if (ospf == NULL || !ospf->oi_running) {
11172 if (uj)
11173 vty_json(vty, json);
11174 else
11175 vty_out(vty,
11176 "%% OSPF is not enabled in vrf %s\n",
11177 vrf_name);
11178
11179 return CMD_SUCCESS;
11180 }
11181 }
11182 } else {
11183 /* Display default ospf (instance 0) info */
11184 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
11185 if (ospf == NULL || !ospf->oi_running) {
11186 if (uj)
11187 vty_json(vty, json);
11188 else
11189 vty_out(vty,
11190 "%% OSPF is not enabled in vrf default\n");
11191
11192 return CMD_SUCCESS;
11193 }
11194 }
11195
11196 if (ospf) {
11197 ret = show_ip_ospf_border_routers_common(vty, ospf, use_vrf,
11198 json);
11199 if (uj)
11200 vty_json(vty, json);
11201 }
11202
11203 return ret;
11204 }
11205
11206 DEFUN (show_ip_ospf_instance_border_routers,
11207 show_ip_ospf_instance_border_routers_cmd,
11208 "show ip ospf (1-65535) border-routers",
11209 SHOW_STR
11210 IP_STR
11211 "OSPF information\n"
11212 "Instance ID\n"
11213 "Show all the ABR's and ASBR's\n")
11214 {
11215 int idx_number = 3;
11216 struct ospf *ospf;
11217 unsigned short instance = 0;
11218
11219 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11220 if (instance != ospf_instance)
11221 return CMD_NOT_MY_INSTANCE;
11222
11223 ospf = ospf_lookup_instance(instance);
11224 if (!ospf || !ospf->oi_running)
11225 return CMD_SUCCESS;
11226
11227 return show_ip_ospf_border_routers_common(vty, ospf, 0, NULL);
11228 }
11229
11230 static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf,
11231 json_object *json, uint8_t use_vrf)
11232 {
11233 json_object *json_vrf = NULL;
11234
11235 if (ospf->instance)
11236 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
11237
11238
11239 if (json) {
11240 if (use_vrf)
11241 json_vrf = json_object_new_object();
11242 else
11243 json_vrf = json;
11244 }
11245
11246 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
11247
11248 if (ospf->new_table == NULL) {
11249 if (json) {
11250 if (use_vrf)
11251 json_object_free(json_vrf);
11252 } else {
11253 vty_out(vty, "No OSPF routing information exist\n");
11254 }
11255 return CMD_SUCCESS;
11256 }
11257
11258 /* Show Network routes. */
11259 show_ip_ospf_route_network(vty, ospf, ospf->new_table, json_vrf);
11260
11261 /* Show Router routes. */
11262 show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, json_vrf);
11263
11264 /* Show Router routes. */
11265 if (ospf->all_rtrs)
11266 show_ip_ospf_route_router(vty, ospf, ospf->all_rtrs, json_vrf);
11267
11268 /* Show AS External routes. */
11269 show_ip_ospf_route_external(vty, ospf, ospf->old_external_route,
11270 json_vrf);
11271
11272 if (json) {
11273 if (use_vrf) {
11274 // json_object_object_add(json_vrf, "areas",
11275 // json_areas);
11276 json_object_object_add(json, ospf_get_name(ospf),
11277 json_vrf);
11278 }
11279 } else {
11280 vty_out(vty, "\n");
11281 }
11282
11283 return CMD_SUCCESS;
11284 }
11285
11286 DEFUN (show_ip_ospf_route,
11287 show_ip_ospf_route_cmd,
11288 "show ip ospf [vrf <NAME|all>] route [json]",
11289 SHOW_STR
11290 IP_STR
11291 "OSPF information\n"
11292 VRF_CMD_HELP_STR
11293 "All VRFs\n"
11294 "OSPF routing table\n"
11295 JSON_STR)
11296 {
11297 struct ospf *ospf = NULL;
11298 struct listnode *node = NULL;
11299 char *vrf_name = NULL;
11300 bool all_vrf = false;
11301 int ret = CMD_SUCCESS;
11302 int inst = 0;
11303 int idx_vrf = 0;
11304 uint8_t use_vrf = 0;
11305 bool uj = use_json(argc, argv);
11306 json_object *json = NULL;
11307
11308 if (uj)
11309 json = json_object_new_object();
11310
11311 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
11312
11313 /* vrf input is provided could be all or specific vrf*/
11314 if (vrf_name) {
11315 bool ospf_output = false;
11316
11317 use_vrf = 1;
11318
11319 if (all_vrf) {
11320 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11321 if (!ospf->oi_running)
11322 continue;
11323 ospf_output = true;
11324 ret = show_ip_ospf_route_common(vty, ospf, json,
11325 use_vrf);
11326 }
11327
11328 if (uj) {
11329 /* Keep Non-pretty format */
11330 vty_json(vty, json);
11331 } else if (!ospf_output)
11332 vty_out(vty, "%% OSPF is not enabled\n");
11333
11334 return ret;
11335 }
11336 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
11337 if (ospf == NULL || !ospf->oi_running) {
11338 if (uj)
11339 vty_json(vty, json);
11340 else
11341 vty_out(vty,
11342 "%% OSPF is not enabled in vrf %s\n",
11343 vrf_name);
11344
11345 return CMD_SUCCESS;
11346 }
11347 } else {
11348 /* Display default ospf (instance 0) info */
11349 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
11350 if (ospf == NULL || !ospf->oi_running) {
11351 if (uj)
11352 vty_json(vty, json);
11353 else
11354 vty_out(vty,
11355 "%% OSPF is not enabled in vrf default\n");
11356
11357 return CMD_SUCCESS;
11358 }
11359 }
11360
11361 if (ospf) {
11362 ret = show_ip_ospf_route_common(vty, ospf, json, use_vrf);
11363 /* Keep Non-pretty format */
11364 if (uj)
11365 vty_out(vty, "%s\n",
11366 json_object_to_json_string_ext(
11367 json, JSON_C_TO_STRING_NOSLASHESCAPE));
11368 }
11369
11370 if (uj)
11371 json_object_free(json);
11372
11373 return ret;
11374 }
11375
11376 DEFUN (show_ip_ospf_instance_route,
11377 show_ip_ospf_instance_route_cmd,
11378 "show ip ospf (1-65535) route",
11379 SHOW_STR
11380 IP_STR
11381 "OSPF information\n"
11382 "Instance ID\n"
11383 "OSPF routing table\n")
11384 {
11385 int idx_number = 3;
11386 struct ospf *ospf;
11387 unsigned short instance = 0;
11388
11389 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11390 if (instance != ospf_instance)
11391 return CMD_NOT_MY_INSTANCE;
11392
11393 ospf = ospf_lookup_instance(instance);
11394 if (!ospf || !ospf->oi_running)
11395 return CMD_SUCCESS;
11396
11397 return show_ip_ospf_route_common(vty, ospf, NULL, 0);
11398 }
11399
11400
11401 DEFUN (show_ip_ospf_vrfs,
11402 show_ip_ospf_vrfs_cmd,
11403 "show ip ospf vrfs [json]",
11404 SHOW_STR
11405 IP_STR
11406 "OSPF information\n"
11407 "Show OSPF VRFs \n"
11408 JSON_STR)
11409 {
11410 bool uj = use_json(argc, argv);
11411 json_object *json = NULL;
11412 json_object *json_vrfs = NULL;
11413 struct ospf *ospf = NULL;
11414 struct listnode *node = NULL;
11415 int count = 0;
11416 static const char header[] = "Name Id RouterId ";
11417
11418 if (uj) {
11419 json = json_object_new_object();
11420 json_vrfs = json_object_new_object();
11421 }
11422
11423 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11424 json_object *json_vrf = NULL;
11425 const char *name = NULL;
11426 int64_t vrf_id_ui = 0;
11427
11428 count++;
11429
11430 if (!uj && count == 1)
11431 vty_out(vty, "%s\n", header);
11432 if (uj)
11433 json_vrf = json_object_new_object();
11434
11435 name = ospf_get_name(ospf);
11436
11437 vrf_id_ui = (ospf->vrf_id == VRF_UNKNOWN)
11438 ? -1
11439 : (int64_t)ospf->vrf_id;
11440
11441 if (uj) {
11442 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
11443 json_object_string_addf(json_vrf, "routerId", "%pI4",
11444 &ospf->router_id);
11445
11446 json_object_object_add(json_vrfs, name, json_vrf);
11447
11448 } else {
11449 vty_out(vty, "%-25s %-5d %-16pI4 \n", name,
11450 ospf->vrf_id, &ospf->router_id);
11451 }
11452 }
11453
11454 if (uj) {
11455 json_object_object_add(json, "vrfs", json_vrfs);
11456 json_object_int_add(json, "totalVrfs", count);
11457
11458 vty_json(vty, json);
11459 } else {
11460 if (count)
11461 vty_out(vty, "\nTotal number of OSPF VRFs: %d\n",
11462 count);
11463 }
11464
11465 return CMD_SUCCESS;
11466 }
11467 DEFPY (clear_ip_ospf_neighbor,
11468 clear_ip_ospf_neighbor_cmd,
11469 "clear ip ospf [(1-65535)]$instance neighbor [A.B.C.D$nbr_id]",
11470 CLEAR_STR
11471 IP_STR
11472 "OSPF information\n"
11473 "Instance ID\n"
11474 "Reset OSPF Neighbor\n"
11475 "Neighbor ID\n")
11476 {
11477 struct listnode *node;
11478 struct ospf *ospf = NULL;
11479
11480 /* If user does not specify the arguments,
11481 * instance = 0 and nbr_id = 0.0.0.0
11482 */
11483 if (instance != 0) {
11484 /* This means clear only the particular ospf process */
11485 if (instance != ospf_instance)
11486 return CMD_NOT_MY_INSTANCE;
11487 }
11488
11489 /* Clear all the ospf processes */
11490 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11491 if (!ospf->oi_running)
11492 continue;
11493
11494 if (nbr_id_str && IPV4_ADDR_SAME(&ospf->router_id, &nbr_id)) {
11495 vty_out(vty, "Self router-id is not allowed.\r\n ");
11496 return CMD_SUCCESS;
11497 }
11498
11499 ospf_neighbor_reset(ospf, nbr_id, nbr_id_str);
11500 }
11501
11502 return CMD_SUCCESS;
11503 }
11504
11505 DEFPY (clear_ip_ospf_process,
11506 clear_ip_ospf_process_cmd,
11507 "clear ip ospf [(1-65535)]$instance process",
11508 CLEAR_STR
11509 IP_STR
11510 "OSPF information\n"
11511 "Instance ID\n"
11512 "Reset OSPF Process\n")
11513 {
11514 struct listnode *node;
11515 struct ospf *ospf = NULL;
11516
11517 /* Check if instance is not passed as an argument */
11518 if (instance != 0) {
11519 /* This means clear only the particular ospf process */
11520 if (instance != ospf_instance)
11521 return CMD_NOT_MY_INSTANCE;
11522 }
11523
11524 /* Clear all the ospf processes */
11525 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11526 if (!ospf->oi_running)
11527 continue;
11528
11529 ospf_process_reset(ospf);
11530 }
11531
11532 return CMD_SUCCESS;
11533 }
11534
11535 static const char *const ospf_abr_type_str[] = {
11536 "unknown", "standard", "ibm", "cisco", "shortcut"
11537 };
11538
11539 static const char *const ospf_shortcut_mode_str[] = {
11540 "default", "enable", "disable"
11541 };
11542 static int ospf_vty_external_rt_walkcb(struct hash_bucket *bucket,
11543 void *arg)
11544 {
11545 struct external_info *ei = bucket->data;
11546 struct vty *vty = (struct vty *)arg;
11547 static unsigned int count;
11548
11549 vty_out(vty, "%-4pI4/%d, ", &ei->p.prefix, ei->p.prefixlen);
11550 count++;
11551
11552 if (count % 5 == 0)
11553 vty_out(vty, "\n");
11554
11555 if (OSPF_EXTERNAL_RT_COUNT(ei->aggr_route) == count)
11556 count = 0;
11557
11558 return HASHWALK_CONTINUE;
11559 }
11560
11561 static int ospf_json_external_rt_walkcb(struct hash_bucket *bucket,
11562 void *arg)
11563 {
11564 struct external_info *ei = bucket->data;
11565 struct json_object *json = (struct json_object *)arg;
11566 char buf[PREFIX2STR_BUFFER];
11567 char exnalbuf[20];
11568 static unsigned int count;
11569
11570 prefix2str(&ei->p, buf, sizeof(buf));
11571
11572 snprintf(exnalbuf, 20, "Exnl Addr-%d", count);
11573
11574 json_object_string_add(json, exnalbuf, buf);
11575
11576 count++;
11577
11578 if (OSPF_EXTERNAL_RT_COUNT(ei->aggr_route) == count)
11579 count = 0;
11580
11581 return HASHWALK_CONTINUE;
11582 }
11583
11584 static int ospf_show_summary_address(struct vty *vty, struct ospf *ospf,
11585 uint8_t use_vrf, json_object *json,
11586 bool uj, bool detail)
11587 {
11588 struct route_node *rn;
11589 json_object *json_vrf = NULL;
11590 int mtype = 0;
11591 int mval = 0;
11592 static char header[] =
11593 "Summary-address Metric-type Metric Tag External_Rt_count\n";
11594
11595 mtype = metric_type(ospf, 0, ospf->instance);
11596 mval = metric_value(ospf, 0, ospf->instance);
11597
11598 if (!uj)
11599 vty_out(vty, "%s\n", header);
11600
11601 if (uj) {
11602 if (use_vrf)
11603 json_vrf = json_object_new_object();
11604 else
11605 json_vrf = json;
11606 }
11607
11608 if (ospf->instance) {
11609 if (uj)
11610 json_object_int_add(json, "ospfInstance",
11611 ospf->instance);
11612 else
11613 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
11614 }
11615
11616 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
11617
11618 if (!uj) {
11619 vty_out(vty, "aggregation delay interval :%u(in seconds)\n\n",
11620 ospf->aggr_delay_interval);
11621 } else {
11622 json_object_int_add(json_vrf, "aggregationDelayInterval",
11623 ospf->aggr_delay_interval);
11624 }
11625
11626 for (rn = route_top(ospf->rt_aggr_tbl); rn; rn = route_next(rn))
11627 if (rn->info) {
11628 struct ospf_external_aggr_rt *aggr = rn->info;
11629 json_object *json_aggr = NULL;
11630 char buf[PREFIX2STR_BUFFER];
11631
11632 prefix2str(&aggr->p, buf, sizeof(buf));
11633
11634 if (uj) {
11635
11636 json_aggr = json_object_new_object();
11637
11638 json_object_object_add(json_vrf, buf,
11639 json_aggr);
11640 json_object_string_add(json_aggr,
11641 "summaryAddress", buf);
11642 json_object_string_add(
11643 json_aggr, "metricType",
11644 (mtype == EXTERNAL_METRIC_TYPE_1)
11645 ? "E1"
11646 : "E2");
11647
11648 json_object_int_add(json_aggr, "metric", mval);
11649 json_object_int_add(json_aggr, "tag",
11650 aggr->tag);
11651 json_object_int_add(
11652 json_aggr, "externalRouteCount",
11653 OSPF_EXTERNAL_RT_COUNT(aggr));
11654
11655 if (OSPF_EXTERNAL_RT_COUNT(aggr) && detail) {
11656 hash_walk(
11657 aggr->match_extnl_hash,
11658 ospf_json_external_rt_walkcb,
11659 json_aggr);
11660 }
11661
11662 } else {
11663 vty_out(vty, "%-20s", buf);
11664
11665 (mtype == EXTERNAL_METRIC_TYPE_1)
11666 ? vty_out(vty, "%-16s", "E1")
11667 : vty_out(vty, "%-16s", "E2");
11668 vty_out(vty, "%-11d", mval);
11669
11670 vty_out(vty, "%-12u", aggr->tag);
11671
11672 vty_out(vty, "%-5ld\n",
11673 OSPF_EXTERNAL_RT_COUNT(aggr));
11674
11675 if (OSPF_EXTERNAL_RT_COUNT(aggr) && detail) {
11676 vty_out(vty,
11677 "Matched External routes:\n");
11678 hash_walk(
11679 aggr->match_extnl_hash,
11680 ospf_vty_external_rt_walkcb,
11681 vty);
11682 vty_out(vty, "\n");
11683 }
11684
11685 vty_out(vty, "\n");
11686 }
11687 }
11688
11689 if (uj) {
11690 if (use_vrf)
11691 json_object_object_add(json, ospf_get_name(ospf),
11692 json_vrf);
11693 } else
11694 vty_out(vty, "\n");
11695
11696 return CMD_SUCCESS;
11697 }
11698
11699 DEFUN (show_ip_ospf_external_aggregator,
11700 show_ip_ospf_external_aggregator_cmd,
11701 "show ip ospf [vrf <NAME|all>] summary-address [detail] [json]",
11702 SHOW_STR IP_STR
11703 "OSPF information\n"
11704 VRF_CMD_HELP_STR
11705 "All VRFs\n"
11706 "Show external summary addresses\n"
11707 "Detailed information\n"
11708 JSON_STR)
11709 {
11710 char *vrf_name = NULL;
11711 bool all_vrf = false;
11712 int ret = CMD_SUCCESS;
11713 int idx_vrf = 0;
11714 int idx = 0;
11715 uint8_t use_vrf = 0;
11716 bool uj = use_json(argc, argv);
11717 struct ospf *ospf = NULL;
11718 json_object *json = NULL;
11719 struct listnode *node = NULL;
11720 int inst = 0;
11721 bool detail = false;
11722
11723 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
11724
11725 if (argv_find(argv, argc, "detail", &idx))
11726 detail = true;
11727
11728 if (uj)
11729 json = json_object_new_object();
11730
11731 /* vrf input is provided */
11732 if (vrf_name) {
11733 use_vrf = 1;
11734 if (all_vrf) {
11735 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11736 if (!ospf->oi_running)
11737 continue;
11738 ret = ospf_show_summary_address(
11739 vty, ospf, use_vrf, json, uj, detail);
11740 }
11741
11742 if (uj)
11743 vty_json(vty, json);
11744
11745 return ret;
11746 }
11747
11748 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
11749
11750 if (ospf == NULL || !ospf->oi_running) {
11751 if (uj)
11752 vty_json(vty, json);
11753 else
11754 vty_out(vty,
11755 "%% OSPF is not enabled in vrf %s\n",
11756 vrf_name);
11757
11758 return CMD_SUCCESS;
11759 }
11760 ospf_show_summary_address(vty, ospf, use_vrf, json, uj, detail);
11761
11762 } else {
11763 /* Default Vrf */
11764 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
11765 if (ospf == NULL || !ospf->oi_running) {
11766 if (uj)
11767 vty_json(vty, json);
11768 else
11769 vty_out(vty,
11770 "%% OSPF is not enabled in vrf default\n");
11771
11772 return CMD_SUCCESS;
11773 }
11774
11775 ospf_show_summary_address(vty, ospf, use_vrf, json, uj, detail);
11776 }
11777
11778 if (uj)
11779 vty_json(vty, json);
11780 return CMD_SUCCESS;
11781 }
11782
11783 static const char *const ospf_int_type_str[] = {
11784 "unknown", /* should never be used. */
11785 "point-to-point",
11786 "broadcast",
11787 "non-broadcast",
11788 "point-to-multipoint",
11789 "virtual-link", /* should never be used. */
11790 "loopback"
11791 };
11792
11793 static const char *interface_config_auth_str(struct ospf_if_params *params)
11794 {
11795 if (!OSPF_IF_PARAM_CONFIGURED(params, auth_type)
11796 || params->auth_type == OSPF_AUTH_NOTSET)
11797 return NULL;
11798
11799 /* Translation tables are not that much help
11800 * here due to syntax
11801 * of the simple option */
11802 switch (params->auth_type) {
11803
11804 case OSPF_AUTH_NULL:
11805 return " null";
11806
11807 case OSPF_AUTH_SIMPLE:
11808 return "";
11809
11810 case OSPF_AUTH_CRYPTOGRAPHIC:
11811 return " message-digest";
11812 }
11813
11814 return "";
11815 }
11816
11817 static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
11818 {
11819 struct listnode *node;
11820 struct interface *ifp;
11821 struct crypt_key *ck;
11822 struct route_node *rn = NULL;
11823 struct ospf_if_params *params;
11824 const char *auth_str;
11825 int write = 0;
11826
11827 FOR_ALL_INTERFACES (vrf, ifp) {
11828
11829 if (memcmp(ifp->name, "VLINK", 5) == 0)
11830 continue;
11831
11832 if_vty_config_start(vty, ifp);
11833
11834 if (ifp->desc)
11835 vty_out(vty, " description %s\n", ifp->desc);
11836
11837 write++;
11838
11839 params = IF_DEF_PARAMS(ifp);
11840
11841 do {
11842 /* Interface Network print. */
11843 if (OSPF_IF_PARAM_CONFIGURED(params, type)
11844 && params->type != OSPF_IFTYPE_LOOPBACK) {
11845 if (params->type != ospf_default_iftype(ifp)) {
11846 vty_out(vty, " ip ospf network %s",
11847 ospf_int_type_str
11848 [params->type]);
11849 if (params->type
11850 == OSPF_IFTYPE_POINTOPOINT
11851 && params->ptp_dmvpn)
11852 vty_out(vty, " dmvpn");
11853 if (params->type ==
11854 OSPF_IFTYPE_POINTOMULTIPOINT &&
11855 params->p2mp_delay_reflood)
11856 vty_out(vty, " delay-reflood");
11857 if (params != IF_DEF_PARAMS(ifp) && rn)
11858 vty_out(vty, " %pI4",
11859 &rn->p.u.prefix4);
11860 vty_out(vty, "\n");
11861 }
11862 }
11863
11864 /* OSPF interface authentication print */
11865 auth_str = interface_config_auth_str(params);
11866 if (auth_str) {
11867 vty_out(vty, " ip ospf authentication%s",
11868 auth_str);
11869 if (params != IF_DEF_PARAMS(ifp) && rn)
11870 vty_out(vty, " %pI4",
11871 &rn->p.u.prefix4);
11872 vty_out(vty, "\n");
11873 }
11874
11875 /* Simple Authentication Password print. */
11876 if (OSPF_IF_PARAM_CONFIGURED(params, auth_simple)
11877 && params->auth_simple[0] != '\0') {
11878 vty_out(vty, " ip ospf authentication-key %s",
11879 params->auth_simple);
11880 if (params != IF_DEF_PARAMS(ifp) && rn)
11881 vty_out(vty, " %pI4",
11882 &rn->p.u.prefix4);
11883 vty_out(vty, "\n");
11884 }
11885
11886 /* Cryptographic Authentication Key print. */
11887 if (params && params->auth_crypt) {
11888 for (ALL_LIST_ELEMENTS_RO(params->auth_crypt,
11889 node, ck)) {
11890 vty_out(vty,
11891 " ip ospf message-digest-key %d md5 %s",
11892 ck->key_id, ck->auth_key);
11893 if (params != IF_DEF_PARAMS(ifp) && rn)
11894 vty_out(vty, " %pI4",
11895 &rn->p.u.prefix4);
11896 vty_out(vty, "\n");
11897 }
11898 }
11899
11900 /* Interface Output Cost print. */
11901 if (OSPF_IF_PARAM_CONFIGURED(params, output_cost_cmd)) {
11902 vty_out(vty, " ip ospf cost %u",
11903 params->output_cost_cmd);
11904 if (params != IF_DEF_PARAMS(ifp) && rn)
11905 vty_out(vty, " %pI4",
11906 &rn->p.u.prefix4);
11907 vty_out(vty, "\n");
11908 }
11909
11910 /* Hello Interval print. */
11911 if (OSPF_IF_PARAM_CONFIGURED(params, v_hello)
11912 && params->v_hello != OSPF_HELLO_INTERVAL_DEFAULT) {
11913 vty_out(vty, " ip ospf hello-interval %u",
11914 params->v_hello);
11915 if (params != IF_DEF_PARAMS(ifp) && rn)
11916 vty_out(vty, " %pI4",
11917 &rn->p.u.prefix4);
11918 vty_out(vty, "\n");
11919 }
11920
11921
11922 /* Router Dead Interval print. */
11923 if (OSPF_IF_PARAM_CONFIGURED(params, v_wait)
11924 && params->is_v_wait_set) {
11925 vty_out(vty, " ip ospf dead-interval ");
11926
11927 /* fast hello ? */
11928 if (OSPF_IF_PARAM_CONFIGURED(params,
11929 fast_hello))
11930 vty_out(vty,
11931 "minimal hello-multiplier %d",
11932 params->fast_hello);
11933 else
11934 vty_out(vty, "%u", params->v_wait);
11935
11936 if (params != IF_DEF_PARAMS(ifp) && rn)
11937 vty_out(vty, " %pI4",
11938 &rn->p.u.prefix4);
11939 vty_out(vty, "\n");
11940 }
11941
11942 /* Hello Graceful-Restart Delay print. */
11943 if (OSPF_IF_PARAM_CONFIGURED(params,
11944 v_gr_hello_delay) &&
11945 params->v_gr_hello_delay !=
11946 OSPF_HELLO_DELAY_DEFAULT)
11947 vty_out(vty,
11948 " ip ospf graceful-restart hello-delay %u\n",
11949 params->v_gr_hello_delay);
11950
11951 /* Router Priority print. */
11952 if (OSPF_IF_PARAM_CONFIGURED(params, priority)
11953 && params->priority
11954 != OSPF_ROUTER_PRIORITY_DEFAULT) {
11955 vty_out(vty, " ip ospf priority %u",
11956 params->priority);
11957 if (params != IF_DEF_PARAMS(ifp) && rn)
11958 vty_out(vty, " %pI4",
11959 &rn->p.u.prefix4);
11960 vty_out(vty, "\n");
11961 }
11962
11963 /* Retransmit Interval print. */
11964 if (OSPF_IF_PARAM_CONFIGURED(params,
11965 retransmit_interval)
11966 && params->retransmit_interval
11967 != OSPF_RETRANSMIT_INTERVAL_DEFAULT) {
11968 vty_out(vty, " ip ospf retransmit-interval %u",
11969 params->retransmit_interval);
11970 if (params != IF_DEF_PARAMS(ifp) && rn)
11971 vty_out(vty, " %pI4",
11972 &rn->p.u.prefix4);
11973 vty_out(vty, "\n");
11974 }
11975
11976 /* Transmit Delay print. */
11977 if (OSPF_IF_PARAM_CONFIGURED(params, transmit_delay)
11978 && params->transmit_delay
11979 != OSPF_TRANSMIT_DELAY_DEFAULT) {
11980 vty_out(vty, " ip ospf transmit-delay %u",
11981 params->transmit_delay);
11982 if (params != IF_DEF_PARAMS(ifp) && rn)
11983 vty_out(vty, " %pI4",
11984 &rn->p.u.prefix4);
11985 vty_out(vty, "\n");
11986 }
11987
11988 /* Area print. */
11989 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
11990 if (ospf_instance)
11991 vty_out(vty, " ip ospf %d",
11992 ospf_instance);
11993 else
11994 vty_out(vty, " ip ospf");
11995
11996 char buf[INET_ADDRSTRLEN];
11997
11998 area_id2str(buf, sizeof(buf), &params->if_area,
11999 params->if_area_id_fmt);
12000 vty_out(vty, " area %s", buf);
12001 if (params != IF_DEF_PARAMS(ifp) && rn)
12002 vty_out(vty, " %pI4",
12003 &rn->p.u.prefix4);
12004 vty_out(vty, "\n");
12005 }
12006
12007 /* bfd print. */
12008 if (params && params->bfd_config)
12009 ospf_bfd_write_config(vty, params);
12010
12011 /* MTU ignore print. */
12012 if (OSPF_IF_PARAM_CONFIGURED(params, mtu_ignore)
12013 && params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) {
12014 if (params->mtu_ignore == 0)
12015 vty_out(vty, " no ip ospf mtu-ignore");
12016 else
12017 vty_out(vty, " ip ospf mtu-ignore");
12018 if (params != IF_DEF_PARAMS(ifp) && rn)
12019 vty_out(vty, " %pI4",
12020 &rn->p.u.prefix4);
12021 vty_out(vty, "\n");
12022 }
12023
12024 if (OSPF_IF_PARAM_CONFIGURED(params,
12025 passive_interface)) {
12026 vty_out(vty, " %sip ospf passive",
12027 params->passive_interface
12028 == OSPF_IF_ACTIVE
12029 ? "no "
12030 : "");
12031 if (params != IF_DEF_PARAMS(ifp) && rn)
12032 vty_out(vty, " %pI4", &rn->p.u.prefix4);
12033 vty_out(vty, "\n");
12034 }
12035
12036 /* LDP-Sync print */
12037 if (params && params->ldp_sync_info)
12038 ospf_ldp_sync_if_write_config(vty, params);
12039
12040 while (1) {
12041 if (rn == NULL)
12042 rn = route_top(IF_OIFS_PARAMS(ifp));
12043 else
12044 rn = route_next(rn);
12045
12046 if (rn == NULL)
12047 break;
12048 params = rn->info;
12049 if (params != NULL)
12050 break;
12051 }
12052 } while (rn);
12053
12054 ospf_opaque_config_write_if(vty, ifp);
12055
12056 if_vty_config_end(vty);
12057 }
12058
12059 return write;
12060 }
12061
12062 /* Configuration write function for ospfd. */
12063 static int config_write_interface(struct vty *vty)
12064 {
12065 int write = 0;
12066 struct vrf *vrf = NULL;
12067
12068 /* Display all VRF aware OSPF interface configuration */
12069 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
12070 write += config_write_interface_one(vty, vrf);
12071 }
12072
12073 return write;
12074 }
12075
12076 static int config_write_network_area(struct vty *vty, struct ospf *ospf)
12077 {
12078 struct route_node *rn;
12079 char buf[INET_ADDRSTRLEN];
12080
12081 /* `network area' print. */
12082 for (rn = route_top(ospf->networks); rn; rn = route_next(rn))
12083 if (rn->info) {
12084 struct ospf_network *n = rn->info;
12085
12086 /* Create Area ID string by specified Area ID format. */
12087 if (n->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD)
12088 inet_ntop(AF_INET, &n->area_id, buf,
12089 sizeof(buf));
12090 else
12091 snprintf(buf, sizeof(buf), "%lu",
12092 (unsigned long int)ntohl(
12093 n->area_id.s_addr));
12094
12095 /* Network print. */
12096 vty_out(vty, " network %pFX area %s\n", &rn->p, buf);
12097 }
12098
12099 return 0;
12100 }
12101
12102 static int config_write_ospf_area(struct vty *vty, struct ospf *ospf)
12103 {
12104 struct listnode *node;
12105 struct ospf_area *area;
12106 char buf[INET_ADDRSTRLEN];
12107
12108 /* Area configuration print. */
12109 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
12110 struct route_node *rn1;
12111
12112 area_id2str(buf, sizeof(buf), &area->area_id,
12113 area->area_id_fmt);
12114
12115 if (area->auth_type != OSPF_AUTH_NULL) {
12116 if (area->auth_type == OSPF_AUTH_SIMPLE)
12117 vty_out(vty, " area %s authentication\n", buf);
12118 else
12119 vty_out(vty,
12120 " area %s authentication message-digest\n",
12121 buf);
12122 }
12123
12124 if (area->shortcut_configured != OSPF_SHORTCUT_DEFAULT)
12125 vty_out(vty, " area %s shortcut %s\n", buf,
12126 ospf_shortcut_mode_str
12127 [area->shortcut_configured]);
12128
12129 if ((area->external_routing == OSPF_AREA_STUB)
12130 || (area->external_routing == OSPF_AREA_NSSA)) {
12131 if (area->external_routing == OSPF_AREA_STUB) {
12132 vty_out(vty, " area %s stub", buf);
12133 if (area->no_summary)
12134 vty_out(vty, " no-summary\n");
12135 vty_out(vty, "\n");
12136 } else if (area->external_routing == OSPF_AREA_NSSA) {
12137 vty_out(vty, " area %s nssa", buf);
12138
12139 switch (area->NSSATranslatorRole) {
12140 case OSPF_NSSA_ROLE_NEVER:
12141 vty_out(vty, " translate-never");
12142 break;
12143 case OSPF_NSSA_ROLE_ALWAYS:
12144 vty_out(vty, " translate-always");
12145 break;
12146 case OSPF_NSSA_ROLE_CANDIDATE:
12147 break;
12148 }
12149
12150 if (area->nssa_default_originate.enabled) {
12151 vty_out(vty,
12152 " default-information-originate");
12153 if (area->nssa_default_originate
12154 .metric_value != -1)
12155 vty_out(vty, " metric %d",
12156 area->nssa_default_originate
12157 .metric_value);
12158 if (area->nssa_default_originate
12159 .metric_type !=
12160 DEFAULT_METRIC_TYPE)
12161 vty_out(vty, " metric-type 1");
12162 }
12163
12164 if (area->no_summary)
12165 vty_out(vty, " no-summary");
12166 if (area->suppress_fa)
12167 vty_out(vty, " suppress-fa");
12168 vty_out(vty, "\n");
12169
12170 for (rn1 = route_top(area->nssa_ranges); rn1;
12171 rn1 = route_next(rn1)) {
12172 struct ospf_area_range *range;
12173
12174 range = rn1->info;
12175 if (!range)
12176 continue;
12177
12178 vty_out(vty, " area %s nssa range %pFX",
12179 buf, &rn1->p);
12180
12181 if (range->cost_config !=
12182 OSPF_AREA_RANGE_COST_UNSPEC)
12183 vty_out(vty, " cost %u",
12184 range->cost_config);
12185
12186 if (!CHECK_FLAG(
12187 range->flags,
12188 OSPF_AREA_RANGE_ADVERTISE))
12189 vty_out(vty, " not-advertise");
12190
12191 vty_out(vty, "\n");
12192 }
12193 }
12194
12195 if (area->default_cost != 1)
12196 vty_out(vty, " area %s default-cost %d\n", buf,
12197 area->default_cost);
12198 }
12199
12200 for (rn1 = route_top(area->ranges); rn1; rn1 = route_next(rn1))
12201 if (rn1->info) {
12202 struct ospf_area_range *range = rn1->info;
12203
12204 vty_out(vty, " area %s range %pFX", buf,
12205 &rn1->p);
12206
12207 if (range->cost_config
12208 != OSPF_AREA_RANGE_COST_UNSPEC)
12209 vty_out(vty, " cost %d",
12210 range->cost_config);
12211
12212 if (!CHECK_FLAG(range->flags,
12213 OSPF_AREA_RANGE_ADVERTISE))
12214 vty_out(vty, " not-advertise");
12215
12216 if (CHECK_FLAG(range->flags,
12217 OSPF_AREA_RANGE_SUBSTITUTE))
12218 vty_out(vty, " substitute %pI4/%d",
12219 &range->subst_addr,
12220 range->subst_masklen);
12221
12222 vty_out(vty, "\n");
12223 }
12224
12225 if (EXPORT_NAME(area))
12226 vty_out(vty, " area %s export-list %s\n", buf,
12227 EXPORT_NAME(area));
12228
12229 if (IMPORT_NAME(area))
12230 vty_out(vty, " area %s import-list %s\n", buf,
12231 IMPORT_NAME(area));
12232
12233 if (PREFIX_NAME_IN(area))
12234 vty_out(vty, " area %s filter-list prefix %s in\n", buf,
12235 PREFIX_NAME_IN(area));
12236
12237 if (PREFIX_NAME_OUT(area))
12238 vty_out(vty, " area %s filter-list prefix %s out\n",
12239 buf, PREFIX_NAME_OUT(area));
12240
12241 if (area->fr_info.configured)
12242 vty_out(vty, " area %s flood-reduction\n", buf);
12243 }
12244
12245 return 0;
12246 }
12247
12248 static int config_write_ospf_nbr_nbma(struct vty *vty, struct ospf *ospf)
12249 {
12250 struct ospf_nbr_nbma *nbr_nbma;
12251 struct route_node *rn;
12252
12253 /* Static Neighbor configuration print. */
12254 for (rn = route_top(ospf->nbr_nbma); rn; rn = route_next(rn))
12255 if ((nbr_nbma = rn->info)) {
12256 vty_out(vty, " neighbor %pI4", &nbr_nbma->addr);
12257
12258 if (nbr_nbma->priority
12259 != OSPF_NEIGHBOR_PRIORITY_DEFAULT)
12260 vty_out(vty, " priority %d",
12261 nbr_nbma->priority);
12262
12263 if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT)
12264 vty_out(vty, " poll-interval %d",
12265 nbr_nbma->v_poll);
12266
12267 vty_out(vty, "\n");
12268 }
12269
12270 return 0;
12271 }
12272
12273 static int config_write_virtual_link(struct vty *vty, struct ospf *ospf)
12274 {
12275 struct listnode *node;
12276 struct ospf_vl_data *vl_data;
12277 const char *auth_str;
12278 char buf[INET_ADDRSTRLEN];
12279
12280 /* Virtual-Link print */
12281 for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl_data)) {
12282 struct listnode *n2;
12283 struct crypt_key *ck;
12284 struct ospf_interface *oi;
12285
12286 if (vl_data != NULL) {
12287 area_id2str(buf, sizeof(buf), &vl_data->vl_area_id,
12288 vl_data->vl_area_id_fmt);
12289 oi = vl_data->vl_oi;
12290
12291 /* timers */
12292 if (OSPF_IF_PARAM(oi, v_hello)
12293 != OSPF_HELLO_INTERVAL_DEFAULT
12294 || OSPF_IF_PARAM(oi, v_wait)
12295 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
12296 || OSPF_IF_PARAM(oi, retransmit_interval)
12297 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
12298 || OSPF_IF_PARAM(oi, transmit_delay)
12299 != OSPF_TRANSMIT_DELAY_DEFAULT)
12300 vty_out(vty,
12301 " area %s virtual-link %pI4 hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n",
12302 buf, &vl_data->vl_peer,
12303 OSPF_IF_PARAM(oi, v_hello),
12304 OSPF_IF_PARAM(oi, retransmit_interval),
12305 OSPF_IF_PARAM(oi, transmit_delay),
12306 OSPF_IF_PARAM(oi, v_wait));
12307 else
12308 vty_out(vty, " area %s virtual-link %pI4\n", buf,
12309 &vl_data->vl_peer);
12310 /* Auth type */
12311 auth_str = interface_config_auth_str(
12312 IF_DEF_PARAMS(oi->ifp));
12313 if (auth_str)
12314 vty_out(vty,
12315 " area %s virtual-link %pI4 authentication%s\n",
12316 buf, &vl_data->vl_peer, auth_str);
12317 /* Auth key */
12318 if (IF_DEF_PARAMS(vl_data->vl_oi->ifp)->auth_simple[0]
12319 != '\0')
12320 vty_out(vty,
12321 " area %s virtual-link %pI4 authentication-key %s\n",
12322 buf, &vl_data->vl_peer,
12323 IF_DEF_PARAMS(vl_data->vl_oi->ifp)
12324 ->auth_simple);
12325 /* md5 keys */
12326 for (ALL_LIST_ELEMENTS_RO(
12327 IF_DEF_PARAMS(vl_data->vl_oi->ifp)
12328 ->auth_crypt,
12329 n2, ck))
12330 vty_out(vty,
12331 " area %s virtual-link %pI4 message-digest-key %d md5 %s\n",
12332 buf, &vl_data->vl_peer,
12333 ck->key_id, ck->auth_key);
12334 }
12335 }
12336
12337 return 0;
12338 }
12339
12340
12341 static int config_write_ospf_redistribute(struct vty *vty, struct ospf *ospf)
12342 {
12343 int type;
12344
12345 /* redistribute print. */
12346 for (type = 0; type < ZEBRA_ROUTE_MAX; type++) {
12347 struct list *red_list;
12348 struct listnode *node;
12349 struct ospf_redist *red;
12350
12351 red_list = ospf->redist[type];
12352 if (!red_list)
12353 continue;
12354
12355 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12356 vty_out(vty, " redistribute %s",
12357 zebra_route_string(type));
12358 if (red->instance)
12359 vty_out(vty, " %d", red->instance);
12360
12361 if (red->dmetric.value >= 0)
12362 vty_out(vty, " metric %d", red->dmetric.value);
12363
12364 if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1)
12365 vty_out(vty, " metric-type 1");
12366
12367 if (ROUTEMAP_NAME(red))
12368 vty_out(vty, " route-map %s",
12369 ROUTEMAP_NAME(red));
12370
12371 vty_out(vty, "\n");
12372 }
12373 }
12374
12375 return 0;
12376 }
12377
12378 static int ospf_cfg_write_helper_dis_rtr_walkcb(struct hash_bucket *bucket,
12379 void *arg)
12380 {
12381 struct advRtr *rtr = bucket->data;
12382 struct vty *vty = (struct vty *)arg;
12383
12384 vty_out(vty, " graceful-restart helper enable %pI4\n",
12385 &rtr->advRtrAddr);
12386 return HASHWALK_CONTINUE;
12387 }
12388
12389 static void config_write_ospf_gr(struct vty *vty, struct ospf *ospf)
12390 {
12391 if (!ospf->gr_info.restart_support)
12392 return;
12393
12394 if (ospf->gr_info.grace_period == OSPF_DFLT_GRACE_INTERVAL)
12395 vty_out(vty, " graceful-restart\n");
12396 else
12397 vty_out(vty, " graceful-restart grace-period %u\n",
12398 ospf->gr_info.grace_period);
12399 }
12400
12401 static int config_write_ospf_gr_helper(struct vty *vty, struct ospf *ospf)
12402 {
12403 if (ospf->is_helper_supported)
12404 vty_out(vty, " graceful-restart helper enable\n");
12405
12406 if (!ospf->strict_lsa_check)
12407 vty_out(vty,
12408 " no graceful-restart helper strict-lsa-checking\n");
12409
12410 if (ospf->only_planned_restart)
12411 vty_out(vty, " graceful-restart helper planned-only\n");
12412
12413 if (ospf->supported_grace_time != OSPF_MAX_GRACE_INTERVAL)
12414 vty_out(vty,
12415 " graceful-restart helper supported-grace-time %d\n",
12416 ospf->supported_grace_time);
12417
12418 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf)) {
12419 hash_walk(ospf->enable_rtr_list,
12420 ospf_cfg_write_helper_dis_rtr_walkcb, vty);
12421 }
12422 return 0;
12423 }
12424
12425 static int config_write_ospf_external_aggregator(struct vty *vty,
12426 struct ospf *ospf)
12427 {
12428 struct route_node *rn;
12429
12430 if (ospf->aggr_delay_interval != OSPF_EXTL_AGGR_DEFAULT_DELAY)
12431 vty_out(vty, " aggregation timer %u\n",
12432 ospf->aggr_delay_interval);
12433
12434 /* print 'summary-address A.B.C.D/M' */
12435 for (rn = route_top(ospf->rt_aggr_tbl); rn; rn = route_next(rn))
12436 if (rn->info) {
12437 struct ospf_external_aggr_rt *aggr = rn->info;
12438
12439 vty_out(vty, " summary-address %pI4/%d",
12440 &aggr->p.prefix, aggr->p.prefixlen);
12441 if (aggr->tag)
12442 vty_out(vty, " tag %u", aggr->tag);
12443
12444 if (CHECK_FLAG(aggr->flags,
12445 OSPF_EXTERNAL_AGGRT_NO_ADVERTISE))
12446 vty_out(vty, " no-advertise");
12447
12448 vty_out(vty, "\n");
12449 }
12450
12451 return 0;
12452 }
12453
12454 static int config_write_ospf_default_metric(struct vty *vty, struct ospf *ospf)
12455 {
12456 if (ospf->default_metric != -1)
12457 vty_out(vty, " default-metric %d\n", ospf->default_metric);
12458 return 0;
12459 }
12460
12461 static int config_write_ospf_distribute(struct vty *vty, struct ospf *ospf)
12462 {
12463 int type;
12464 struct ospf_redist *red;
12465
12466 if (ospf) {
12467 /* distribute-list print. */
12468 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
12469 if (DISTRIBUTE_NAME(ospf, type))
12470 vty_out(vty, " distribute-list %s out %s\n",
12471 DISTRIBUTE_NAME(ospf, type),
12472 zebra_route_string(type));
12473
12474 /* default-information print. */
12475 if (ospf->default_originate != DEFAULT_ORIGINATE_NONE) {
12476 vty_out(vty, " default-information originate");
12477 if (ospf->default_originate == DEFAULT_ORIGINATE_ALWAYS)
12478 vty_out(vty, " always");
12479
12480 red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0);
12481 if (red) {
12482 if (red->dmetric.value >= 0)
12483 vty_out(vty, " metric %d",
12484 red->dmetric.value);
12485
12486 if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1)
12487 vty_out(vty, " metric-type 1");
12488
12489 if (ROUTEMAP_NAME(red))
12490 vty_out(vty, " route-map %s",
12491 ROUTEMAP_NAME(red));
12492 }
12493
12494 vty_out(vty, "\n");
12495 }
12496 }
12497
12498 return 0;
12499 }
12500
12501 static int config_write_ospf_distance(struct vty *vty, struct ospf *ospf)
12502 {
12503 struct route_node *rn;
12504 struct ospf_distance *odistance;
12505
12506 if (ospf->distance_all)
12507 vty_out(vty, " distance %d\n", ospf->distance_all);
12508
12509 if (ospf->distance_intra || ospf->distance_inter
12510 || ospf->distance_external) {
12511 vty_out(vty, " distance ospf");
12512
12513 if (ospf->distance_intra)
12514 vty_out(vty, " intra-area %d", ospf->distance_intra);
12515 if (ospf->distance_inter)
12516 vty_out(vty, " inter-area %d", ospf->distance_inter);
12517 if (ospf->distance_external)
12518 vty_out(vty, " external %d", ospf->distance_external);
12519
12520 vty_out(vty, "\n");
12521 }
12522
12523 for (rn = route_top(ospf->distance_table); rn; rn = route_next(rn))
12524 if ((odistance = rn->info) != NULL) {
12525 vty_out(vty, " distance %d %pFX %s\n",
12526 odistance->distance, &rn->p,
12527 odistance->access_list ? odistance->access_list
12528 : "");
12529 }
12530 return 0;
12531 }
12532
12533 static int ospf_config_write_one(struct vty *vty, struct ospf *ospf)
12534 {
12535 int write = 0;
12536
12537 /* `router ospf' print. */
12538 if (ospf->instance && strcmp(ospf->name, VRF_DEFAULT_NAME)) {
12539 vty_out(vty, "router ospf %d vrf %s\n", ospf->instance,
12540 ospf->name);
12541 } else if (ospf->instance) {
12542 vty_out(vty, "router ospf %d\n", ospf->instance);
12543 } else if (strcmp(ospf->name, VRF_DEFAULT_NAME)) {
12544 vty_out(vty, "router ospf vrf %s\n", ospf->name);
12545 } else
12546 vty_out(vty, "router ospf\n");
12547
12548 if (!ospf->networks) {
12549 write++;
12550 return write;
12551 }
12552
12553 /* Router ID print. */
12554 if (ospf->router_id_static.s_addr != INADDR_ANY)
12555 vty_out(vty, " ospf router-id %pI4\n",
12556 &ospf->router_id_static);
12557
12558 /* zebra opaque attributes configuration. */
12559 if (CHECK_FLAG(ospf->config, OSPF_SEND_EXTRA_DATA_TO_ZEBRA))
12560 vty_out(vty, " ospf send-extra-data zebra\n");
12561
12562 /* ABR type print. */
12563 if (ospf->abr_type != OSPF_ABR_DEFAULT)
12564 vty_out(vty, " ospf abr-type %s\n",
12565 ospf_abr_type_str[ospf->abr_type]);
12566
12567 /* log-adjacency-changes flag print. */
12568 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) {
12569 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL))
12570 vty_out(vty, " log-adjacency-changes detail\n");
12571 else if (!SAVE_OSPF_LOG_ADJACENCY_CHANGES)
12572 vty_out(vty, " log-adjacency-changes\n");
12573 } else if (SAVE_OSPF_LOG_ADJACENCY_CHANGES) {
12574 vty_out(vty, " no log-adjacency-changes\n");
12575 }
12576
12577 /* RFC1583 compatibility flag print -- Compatible with CISCO
12578 * 12.1. */
12579 if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE))
12580 vty_out(vty, " compatible rfc1583\n");
12581
12582 /* auto-cost reference-bandwidth configuration. */
12583 if (ospf->ref_bandwidth != OSPF_DEFAULT_REF_BANDWIDTH) {
12584 vty_out(vty,
12585 "! Important: ensure reference bandwidth is consistent across all routers\n");
12586 vty_out(vty, " auto-cost reference-bandwidth %d\n",
12587 ospf->ref_bandwidth);
12588 }
12589
12590 /* SPF timers print. */
12591 if (ospf->spf_delay != OSPF_SPF_DELAY_DEFAULT
12592 || ospf->spf_holdtime != OSPF_SPF_HOLDTIME_DEFAULT
12593 || ospf->spf_max_holdtime != OSPF_SPF_MAX_HOLDTIME_DEFAULT)
12594 vty_out(vty, " timers throttle spf %d %d %d\n", ospf->spf_delay,
12595 ospf->spf_holdtime, ospf->spf_max_holdtime);
12596
12597 /* LSA timers print. */
12598 if (ospf->min_ls_interval != OSPF_MIN_LS_INTERVAL)
12599 vty_out(vty, " timers throttle lsa all %d\n",
12600 ospf->min_ls_interval);
12601 if (ospf->min_ls_arrival != OSPF_MIN_LS_ARRIVAL)
12602 vty_out(vty, " timers lsa min-arrival %d\n",
12603 ospf->min_ls_arrival);
12604
12605 /* Write multiplier print. */
12606 if (ospf->write_oi_count != OSPF_WRITE_INTERFACE_COUNT_DEFAULT)
12607 vty_out(vty, " ospf write-multiplier %d\n",
12608 ospf->write_oi_count);
12609
12610 if (ospf->max_multipath != MULTIPATH_NUM)
12611 vty_out(vty, " maximum-paths %d\n", ospf->max_multipath);
12612
12613 /* Max-metric router-lsa print */
12614 config_write_stub_router(vty, ospf);
12615
12616 /* SPF refresh parameters print. */
12617 if (ospf->lsa_refresh_interval != OSPF_LSA_REFRESH_INTERVAL_DEFAULT)
12618 vty_out(vty, " refresh timer %d\n", ospf->lsa_refresh_interval);
12619
12620 if (ospf->fr_configured)
12621 vty_out(vty, " flood-reduction\n");
12622
12623 if (!ospf->intf_socket_enabled)
12624 vty_out(vty, " no socket-per-interface\n");
12625
12626 /* Redistribute information print. */
12627 config_write_ospf_redistribute(vty, ospf);
12628
12629 /* Graceful Restart print */
12630 config_write_ospf_gr(vty, ospf);
12631 config_write_ospf_gr_helper(vty, ospf);
12632
12633 /* Print external route aggregation. */
12634 config_write_ospf_external_aggregator(vty, ospf);
12635
12636 /* passive-interface print. */
12637 if (ospf->passive_interface_default == OSPF_IF_PASSIVE)
12638 vty_out(vty, " passive-interface default\n");
12639
12640 /* proactive-arp print. */
12641 if (ospf->proactive_arp != OSPF_PROACTIVE_ARP_DEFAULT) {
12642 if (ospf->proactive_arp)
12643 vty_out(vty, " proactive-arp\n");
12644 else
12645 vty_out(vty, " no proactive-arp\n");
12646 }
12647
12648 /* TI-LFA print. */
12649 if (ospf->ti_lfa_enabled) {
12650 if (ospf->ti_lfa_protection_type == OSPF_TI_LFA_NODE_PROTECTION)
12651 vty_out(vty, " fast-reroute ti-lfa node-protection\n");
12652 else
12653 vty_out(vty, " fast-reroute ti-lfa\n");
12654 }
12655
12656 /* Network area print. */
12657 config_write_network_area(vty, ospf);
12658
12659 /* Area config print. */
12660 config_write_ospf_area(vty, ospf);
12661
12662 /* static neighbor print. */
12663 config_write_ospf_nbr_nbma(vty, ospf);
12664
12665 /* Virtual-Link print. */
12666 config_write_virtual_link(vty, ospf);
12667
12668 /* Default metric configuration. */
12669 config_write_ospf_default_metric(vty, ospf);
12670
12671 /* Distribute-list and default-information print. */
12672 config_write_ospf_distribute(vty, ospf);
12673
12674 /* Distance configuration. */
12675 config_write_ospf_distance(vty, ospf);
12676
12677 ospf_opaque_config_write_router(vty, ospf);
12678
12679 /* LDP-Sync print */
12680 ospf_ldp_sync_write_config(vty, ospf);
12681
12682 /* Socket buffer sizes */
12683 if (ospf->recv_sock_bufsize != OSPF_DEFAULT_SOCK_BUFSIZE) {
12684 if (ospf->send_sock_bufsize == ospf->recv_sock_bufsize)
12685 vty_out(vty, " socket buffer all %u\n",
12686 ospf->recv_sock_bufsize);
12687 else
12688 vty_out(vty, " socket buffer recv %u\n",
12689 ospf->recv_sock_bufsize);
12690 }
12691
12692 if (ospf->send_sock_bufsize != OSPF_DEFAULT_SOCK_BUFSIZE &&
12693 ospf->send_sock_bufsize != ospf->recv_sock_bufsize)
12694 vty_out(vty, " socket buffer send %u\n",
12695 ospf->send_sock_bufsize);
12696
12697
12698 vty_out(vty, "exit\n");
12699
12700 write++;
12701 return write;
12702 }
12703
12704 /* OSPF configuration write function. */
12705 static int ospf_config_write(struct vty *vty)
12706 {
12707 struct ospf *ospf;
12708 struct listnode *ospf_node = NULL;
12709 int write = 0;
12710
12711 if (listcount(om->ospf) == 0)
12712 return write;
12713
12714 for (ALL_LIST_ELEMENTS_RO(om->ospf, ospf_node, ospf)) {
12715 /* VRF Default check if it is running.
12716 * Upon daemon start, there could be default instance
12717 * in absence of 'router ospf'/oi_running is disabled. */
12718 if (ospf->vrf_id == VRF_DEFAULT && ospf->oi_running)
12719 write += ospf_config_write_one(vty, ospf);
12720 /* For Non-Default VRF simply display the configuration,
12721 * even if it is not oi_running. */
12722 else if (ospf->vrf_id != VRF_DEFAULT)
12723 write += ospf_config_write_one(vty, ospf);
12724 }
12725 return write;
12726 }
12727
12728 void ospf_vty_show_init(void)
12729 {
12730 /* "show ip ospf" commands. */
12731 install_element(VIEW_NODE, &show_ip_ospf_cmd);
12732
12733 install_element(VIEW_NODE, &show_ip_ospf_instance_cmd);
12734
12735 /* "show ip ospf database" commands. */
12736 install_element(VIEW_NODE, &show_ip_ospf_database_cmd);
12737
12738 /* "show ip ospf interface" commands. */
12739 install_element(VIEW_NODE, &show_ip_ospf_interface_cmd);
12740
12741 install_element(VIEW_NODE, &show_ip_ospf_instance_interface_cmd);
12742 /* "show ip ospf interface traffic */
12743 install_element(VIEW_NODE, &show_ip_ospf_interface_traffic_cmd);
12744
12745 /* "show ip ospf neighbor" commands. */
12746 install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_detail_cmd);
12747 install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_cmd);
12748 install_element(VIEW_NODE, &show_ip_ospf_neighbor_id_cmd);
12749 install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_all_cmd);
12750 install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_cmd);
12751 install_element(VIEW_NODE, &show_ip_ospf_neighbor_cmd);
12752 install_element(VIEW_NODE, &show_ip_ospf_neighbor_all_cmd);
12753
12754 install_element(VIEW_NODE,
12755 &show_ip_ospf_instance_neighbor_int_detail_cmd);
12756 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_int_cmd);
12757 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_id_cmd);
12758 install_element(VIEW_NODE,
12759 &show_ip_ospf_instance_neighbor_detail_all_cmd);
12760 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_detail_cmd);
12761 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_cmd);
12762 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_all_cmd);
12763
12764 /* "show ip ospf route" commands. */
12765 install_element(VIEW_NODE, &show_ip_ospf_route_cmd);
12766 install_element(VIEW_NODE, &show_ip_ospf_border_routers_cmd);
12767 install_element(VIEW_NODE, &show_ip_ospf_reachable_routers_cmd);
12768
12769 install_element(VIEW_NODE, &show_ip_ospf_instance_route_cmd);
12770 install_element(VIEW_NODE, &show_ip_ospf_instance_border_routers_cmd);
12771 install_element(VIEW_NODE,
12772 &show_ip_ospf_instance_reachable_routers_cmd);
12773
12774 /* "show ip ospf vrfs" commands. */
12775 install_element(VIEW_NODE, &show_ip_ospf_vrfs_cmd);
12776
12777 /* "show ip ospf gr-helper details" command */
12778 install_element(VIEW_NODE, &show_ip_ospf_gr_helper_cmd);
12779
12780 /* "show ip ospf summary-address" command */
12781 install_element(VIEW_NODE, &show_ip_ospf_external_aggregator_cmd);
12782 }
12783
12784 /* Initialization of OSPF interface. */
12785 static void ospf_vty_if_init(void)
12786 {
12787 /* Install interface node. */
12788 if_cmd_init(config_write_interface);
12789
12790 /* "ip ospf authentication" commands. */
12791 install_element(INTERFACE_NODE, &ip_ospf_authentication_args_addr_cmd);
12792 install_element(INTERFACE_NODE, &ip_ospf_authentication_addr_cmd);
12793 install_element(INTERFACE_NODE,
12794 &no_ip_ospf_authentication_args_addr_cmd);
12795 install_element(INTERFACE_NODE, &no_ip_ospf_authentication_addr_cmd);
12796 install_element(INTERFACE_NODE, &ip_ospf_authentication_key_addr_cmd);
12797 install_element(INTERFACE_NODE,
12798 &no_ip_ospf_authentication_key_authkey_addr_cmd);
12799 install_element(INTERFACE_NODE,
12800 &no_ospf_authentication_key_authkey_addr_cmd);
12801
12802 /* "ip ospf message-digest-key" commands. */
12803 install_element(INTERFACE_NODE, &ip_ospf_message_digest_key_cmd);
12804 install_element(INTERFACE_NODE, &no_ip_ospf_message_digest_key_cmd);
12805
12806 /* "ip ospf cost" commands. */
12807 install_element(INTERFACE_NODE, &ip_ospf_cost_cmd);
12808 install_element(INTERFACE_NODE, &no_ip_ospf_cost_cmd);
12809
12810 /* "ip ospf mtu-ignore" commands. */
12811 install_element(INTERFACE_NODE, &ip_ospf_mtu_ignore_addr_cmd);
12812 install_element(INTERFACE_NODE, &no_ip_ospf_mtu_ignore_addr_cmd);
12813
12814 /* "ip ospf dead-interval" commands. */
12815 install_element(INTERFACE_NODE, &ip_ospf_dead_interval_cmd);
12816 install_element(INTERFACE_NODE,
12817 &ip_ospf_dead_interval_minimal_addr_cmd);
12818 install_element(INTERFACE_NODE, &no_ip_ospf_dead_interval_cmd);
12819
12820 /* "ip ospf hello-interval" commands. */
12821 install_element(INTERFACE_NODE, &ip_ospf_hello_interval_cmd);
12822 install_element(INTERFACE_NODE, &no_ip_ospf_hello_interval_cmd);
12823
12824 /* "ip ospf network" commands. */
12825 install_element(INTERFACE_NODE, &ip_ospf_network_cmd);
12826 install_element(INTERFACE_NODE, &no_ip_ospf_network_cmd);
12827
12828 /* "ip ospf priority" commands. */
12829 install_element(INTERFACE_NODE, &ip_ospf_priority_cmd);
12830 install_element(INTERFACE_NODE, &no_ip_ospf_priority_cmd);
12831
12832 /* "ip ospf retransmit-interval" commands. */
12833 install_element(INTERFACE_NODE, &ip_ospf_retransmit_interval_addr_cmd);
12834 install_element(INTERFACE_NODE,
12835 &no_ip_ospf_retransmit_interval_addr_cmd);
12836
12837 /* "ip ospf transmit-delay" commands. */
12838 install_element(INTERFACE_NODE, &ip_ospf_transmit_delay_addr_cmd);
12839 install_element(INTERFACE_NODE, &no_ip_ospf_transmit_delay_addr_cmd);
12840
12841 /* "ip ospf area" commands. */
12842 install_element(INTERFACE_NODE, &ip_ospf_area_cmd);
12843 install_element(INTERFACE_NODE, &no_ip_ospf_area_cmd);
12844
12845 /* "ip ospf passive" commands. */
12846 install_element(INTERFACE_NODE, &ip_ospf_passive_cmd);
12847 install_element(INTERFACE_NODE, &no_ip_ospf_passive_cmd);
12848
12849 /* These commands are compatibitliy for previous version. */
12850 install_element(INTERFACE_NODE, &ospf_authentication_key_cmd);
12851 install_element(INTERFACE_NODE, &ospf_message_digest_key_cmd);
12852 install_element(INTERFACE_NODE, &no_ospf_message_digest_key_cmd);
12853 install_element(INTERFACE_NODE, &ospf_dead_interval_cmd);
12854 install_element(INTERFACE_NODE, &no_ospf_dead_interval_cmd);
12855 install_element(INTERFACE_NODE, &ospf_hello_interval_cmd);
12856 install_element(INTERFACE_NODE, &no_ospf_hello_interval_cmd);
12857 install_element(INTERFACE_NODE, &ospf_cost_cmd);
12858 install_element(INTERFACE_NODE, &no_ospf_cost_cmd);
12859 install_element(INTERFACE_NODE, &ospf_network_cmd);
12860 install_element(INTERFACE_NODE, &no_ospf_network_cmd);
12861 install_element(INTERFACE_NODE, &ospf_priority_cmd);
12862 install_element(INTERFACE_NODE, &no_ospf_priority_cmd);
12863 install_element(INTERFACE_NODE, &ospf_retransmit_interval_cmd);
12864 install_element(INTERFACE_NODE, &no_ospf_retransmit_interval_cmd);
12865 install_element(INTERFACE_NODE, &ospf_transmit_delay_cmd);
12866 install_element(INTERFACE_NODE, &no_ospf_transmit_delay_cmd);
12867 }
12868
12869 static void ospf_vty_zebra_init(void)
12870 {
12871 install_element(OSPF_NODE, &ospf_redistribute_source_cmd);
12872 install_element(OSPF_NODE, &no_ospf_redistribute_source_cmd);
12873 install_element(OSPF_NODE, &ospf_redistribute_instance_source_cmd);
12874 install_element(OSPF_NODE, &no_ospf_redistribute_instance_source_cmd);
12875
12876 install_element(OSPF_NODE, &ospf_distribute_list_out_cmd);
12877 install_element(OSPF_NODE, &no_ospf_distribute_list_out_cmd);
12878
12879 install_element(OSPF_NODE, &ospf_default_information_originate_cmd);
12880 install_element(OSPF_NODE, &no_ospf_default_information_originate_cmd);
12881
12882 install_element(OSPF_NODE, &ospf_default_metric_cmd);
12883 install_element(OSPF_NODE, &no_ospf_default_metric_cmd);
12884
12885 install_element(OSPF_NODE, &ospf_distance_cmd);
12886 install_element(OSPF_NODE, &no_ospf_distance_cmd);
12887 install_element(OSPF_NODE, &no_ospf_distance_ospf_cmd);
12888 install_element(OSPF_NODE, &ospf_distance_ospf_cmd);
12889
12890 /*Ospf garcefull restart helper configurations */
12891 install_element(OSPF_NODE, &ospf_gr_helper_enable_cmd);
12892 install_element(OSPF_NODE, &no_ospf_gr_helper_enable_cmd);
12893 install_element(OSPF_NODE, &ospf_gr_helper_enable_lsacheck_cmd);
12894 install_element(OSPF_NODE, &no_ospf_gr_helper_enable_lsacheck_cmd);
12895 install_element(OSPF_NODE, &ospf_gr_helper_supported_grace_time_cmd);
12896 install_element(OSPF_NODE, &no_ospf_gr_helper_supported_grace_time_cmd);
12897 install_element(OSPF_NODE, &ospf_gr_helper_planned_only_cmd);
12898 install_element(OSPF_NODE, &no_ospf_gr_helper_planned_only_cmd);
12899
12900 /* External LSA summarisation config commands.*/
12901 install_element(OSPF_NODE, &ospf_external_route_aggregation_cmd);
12902 install_element(OSPF_NODE, &no_ospf_external_route_aggregation_cmd);
12903 install_element(OSPF_NODE,
12904 &ospf_external_route_aggregation_no_adrvertise_cmd);
12905 install_element(OSPF_NODE,
12906 &no_ospf_external_route_aggregation_no_adrvertise_cmd);
12907 install_element(OSPF_NODE, &ospf_route_aggregation_timer_cmd);
12908 install_element(OSPF_NODE, &no_ospf_route_aggregation_timer_cmd);
12909 }
12910
12911 static int ospf_config_write(struct vty *vty);
12912 static struct cmd_node ospf_node = {
12913 .name = "ospf",
12914 .node = OSPF_NODE,
12915 .parent_node = CONFIG_NODE,
12916 .prompt = "%s(config-router)# ",
12917 .config_write = ospf_config_write,
12918 };
12919
12920 static void ospf_interface_clear(struct interface *ifp)
12921 {
12922 if (!if_is_operative(ifp))
12923 return;
12924
12925 if (IS_DEBUG_OSPF(ism, ISM_EVENTS))
12926 zlog_debug("ISM[%s]: clear by reset", ifp->name);
12927
12928 ospf_if_reset(ifp);
12929 }
12930
12931 DEFUN (clear_ip_ospf_interface,
12932 clear_ip_ospf_interface_cmd,
12933 "clear ip ospf [vrf NAME] interface [IFNAME]",
12934 CLEAR_STR
12935 IP_STR
12936 "OSPF information\n"
12937 VRF_CMD_HELP_STR
12938 "Interface information\n"
12939 "Interface name\n")
12940 {
12941 int idx_ifname = 0;
12942 int idx_vrf = 0;
12943 struct interface *ifp;
12944 struct listnode *node;
12945 struct ospf *ospf = NULL;
12946 char *vrf_name = NULL;
12947 vrf_id_t vrf_id = VRF_DEFAULT;
12948 struct vrf *vrf = NULL;
12949
12950 if (argv_find(argv, argc, "vrf", &idx_vrf))
12951 vrf_name = argv[idx_vrf + 1]->arg;
12952 if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME))
12953 vrf_name = NULL;
12954 if (vrf_name) {
12955 vrf = vrf_lookup_by_name(vrf_name);
12956 if (vrf)
12957 vrf_id = vrf->vrf_id;
12958 }
12959 if (!argv_find(argv, argc, "IFNAME", &idx_ifname)) {
12960 /* Clear all the ospfv2 interfaces. */
12961 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
12962 if (vrf_id != ospf->vrf_id)
12963 continue;
12964 if (!vrf)
12965 vrf = vrf_lookup_by_id(ospf->vrf_id);
12966 FOR_ALL_INTERFACES (vrf, ifp)
12967 ospf_interface_clear(ifp);
12968 }
12969 } else {
12970 /* Interface name is specified. */
12971 ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id);
12972 if (ifp == NULL)
12973 vty_out(vty, "No such interface name\n");
12974 else
12975 ospf_interface_clear(ifp);
12976 }
12977
12978 return CMD_SUCCESS;
12979 }
12980
12981 DEFPY_HIDDEN(ospf_lsa_refresh_timer, ospf_lsa_refresh_timer_cmd,
12982 "[no$no] ospf lsa-refresh [(120-1800)]$value",
12983 NO_STR OSPF_STR
12984 "OSPF lsa refresh timer\n"
12985 "timer value in seconds\n")
12986 {
12987 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf)
12988
12989 if (no)
12990 ospf->lsa_refresh_timer = OSPF_LS_REFRESH_TIME;
12991 else
12992 ospf->lsa_refresh_timer = value;
12993
12994 return CMD_SUCCESS;
12995 }
12996
12997 DEFPY_HIDDEN(ospf_maxage_delay_timer, ospf_maxage_delay_timer_cmd,
12998 "[no$no] ospf maxage-delay [(0-60)]$value",
12999 NO_STR OSPF_STR
13000 "OSPF lsa maxage delay timer\n"
13001 "timer value in seconds\n")
13002 {
13003 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf)
13004
13005 if (no)
13006 ospf->maxage_delay = OSPF_LSA_MAXAGE_REMOVE_DELAY_DEFAULT;
13007 else
13008 ospf->maxage_delay = value;
13009
13010 EVENT_OFF(ospf->t_maxage);
13011 OSPF_TIMER_ON(ospf->t_maxage, ospf_maxage_lsa_remover,
13012 ospf->maxage_delay);
13013
13014 return CMD_SUCCESS;
13015 }
13016
13017 /*
13018 * ------------------------------------------------------------------------*
13019 * Following is (vty) configuration functions for flood-reduction handling.
13020 * ------------------------------------------------------------------------
13021 */
13022
13023 DEFPY(flood_reduction, flood_reduction_cmd, "flood-reduction",
13024 "flood reduction feature\n")
13025 {
13026 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf)
13027 struct ospf_area *area;
13028 struct listnode *node;
13029
13030 /* Turn on the Flood Reduction feature for the router. */
13031 if (!ospf->fr_configured) {
13032 ospf->fr_configured = true;
13033 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT,
13034 "Flood Reduction: OFF -> ON");
13035 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
13036 if (area) {
13037 ospf_area_update_fr_state(area);
13038 ospf_refresh_area_self_lsas(area);
13039 }
13040 }
13041 }
13042
13043 return CMD_SUCCESS;
13044 }
13045
13046 DEFPY(flood_reduction_area, flood_reduction_area_cmd,
13047 "area <A.B.C.D|(0-4294967295)> flood-reduction",
13048 "OSPF area parameters\n"
13049 "OSPF area ID in IP address format\n"
13050 "OSPF area ID as a decimal value\n"
13051 "Enable flood reduction for area\n")
13052 {
13053 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf)
13054 struct ospf_area *oa;
13055 int idx = 1;
13056 int format;
13057 int ret;
13058 const char *areaid;
13059 struct in_addr area_id;
13060
13061 areaid = argv[idx]->arg;
13062
13063 ret = str2area_id(areaid, &area_id, &format);
13064 if (ret < 0) {
13065 vty_out(vty, "Please specify area by A.B.C.D|<0-4294967295>\n");
13066 return CMD_WARNING_CONFIG_FAILED;
13067 }
13068
13069 oa = ospf_area_lookup_by_area_id(ospf, area_id);
13070 if (!oa) {
13071 vty_out(vty, "OSPF area ID not present\n");
13072 return CMD_WARNING_CONFIG_FAILED;
13073 }
13074
13075 /* Turn on the Flood Reduction feature for the area. */
13076 if (!oa->fr_info.configured) {
13077 oa->fr_info.configured = true;
13078 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT,
13079 "Flood Reduction area %pI4 : OFF -> ON",
13080 &oa->area_id);
13081 ospf_area_update_fr_state(oa);
13082 ospf_refresh_area_self_lsas(oa);
13083 }
13084
13085 return CMD_SUCCESS;
13086 }
13087
13088 DEFPY(no_flood_reduction, no_flood_reduction_cmd, "no flood-reduction",
13089 NO_STR "flood reduction feature\n")
13090 {
13091 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf)
13092 struct listnode *node;
13093 struct ospf_area *area;
13094
13095 /* Turn off the Flood Reduction feature for the router. */
13096 if (ospf->fr_configured) {
13097 ospf->fr_configured = false;
13098 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT,
13099 "Flood Reduction: ON -> OFF");
13100 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
13101 if (area) {
13102 ospf_area_update_fr_state(area);
13103 ospf_refresh_area_self_lsas(area);
13104 }
13105 }
13106 }
13107
13108 return CMD_SUCCESS;
13109 }
13110
13111 DEFPY(no_flood_reduction_area, no_flood_reduction_area_cmd,
13112 "no area <A.B.C.D|(0-4294967295)> flood-reduction",
13113 NO_STR
13114 "OSPF area parameters\n"
13115 "OSPF area ID in IP address format\n"
13116 "OSPF area ID as a decimal value\n"
13117 "Disable flood reduction for area\n")
13118 {
13119 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf)
13120 struct ospf_area *oa;
13121 int idx = 2;
13122 int format;
13123 int ret;
13124 const char *areaid;
13125 struct in_addr area_id;
13126
13127 areaid = argv[idx]->arg;
13128
13129 ret = str2area_id(areaid, &area_id, &format);
13130 if (ret < 0) {
13131 vty_out(vty, "Please specify area by A.B.C.D|<0-4294967295>\n");
13132 return CMD_WARNING_CONFIG_FAILED;
13133 }
13134
13135 oa = ospf_area_lookup_by_area_id(ospf, area_id);
13136 if (!oa) {
13137 vty_out(vty, "OSPF area ID not present\n");
13138 return CMD_WARNING_CONFIG_FAILED;
13139 }
13140
13141 /* Turn off the Flood Reduction feature for the area. */
13142 if (oa->fr_info.configured) {
13143 oa->fr_info.configured = false;
13144 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT,
13145 "Flood Reduction area %pI4 : ON -> OFF",
13146 &oa->area_id);
13147 ospf_area_update_fr_state(oa);
13148 ospf_refresh_area_self_lsas(oa);
13149 }
13150
13151 return CMD_SUCCESS;
13152 }
13153
13154 DEFPY(ospf_socket_bufsizes,
13155 ospf_socket_bufsizes_cmd,
13156 "[no] socket buffer <send$send_val | recv$recv_val | all$all_val> \
13157 ![(1-4000000000)$bufsize]",
13158 NO_STR
13159 "Socket parameters\n"
13160 "Buffer size configuration\n"
13161 "Send buffer size\n"
13162 "Receive buffer size\n"
13163 "Both send and receive buffer sizes\n"
13164 "Buffer size, in bytes\n")
13165 {
13166 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
13167 uint32_t recvsz, sendsz;
13168
13169 if (no)
13170 bufsize = OSPF_DEFAULT_SOCK_BUFSIZE;
13171
13172 if (all_val) {
13173 recvsz = bufsize;
13174 sendsz = bufsize;
13175 } else if (send_val) {
13176 sendsz = bufsize;
13177 recvsz = ospf->recv_sock_bufsize;
13178 } else if (recv_val) {
13179 recvsz = bufsize;
13180 sendsz = ospf->send_sock_bufsize;
13181 } else
13182 return CMD_SUCCESS;
13183
13184 /* React to a change by modifying existing sockets */
13185 ospf_update_bufsize(ospf, recvsz, sendsz);
13186
13187 return CMD_SUCCESS;
13188 }
13189
13190 DEFPY (per_intf_socket,
13191 per_intf_socket_cmd,
13192 "[no] socket-per-interface",
13193 NO_STR
13194 "Use write socket per interface\n")
13195 {
13196 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
13197 struct listnode *node;
13198 struct ospf_interface *oi;
13199
13200 if (no) {
13201 if (ospf->intf_socket_enabled) {
13202 ospf->intf_socket_enabled = false;
13203
13204 /* Iterate and close any sockets */
13205 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi))
13206 ospf_ifp_sock_close(oi->ifp);
13207 }
13208 } else if (!ospf->intf_socket_enabled) {
13209 ospf->intf_socket_enabled = true;
13210
13211 /* Iterate and open sockets */
13212 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi))
13213 ospf_ifp_sock_init(oi->ifp);
13214 }
13215
13216 return CMD_SUCCESS;
13217 }
13218
13219 void ospf_vty_clear_init(void)
13220 {
13221 install_element(ENABLE_NODE, &clear_ip_ospf_interface_cmd);
13222 install_element(ENABLE_NODE, &clear_ip_ospf_process_cmd);
13223 install_element(ENABLE_NODE, &clear_ip_ospf_neighbor_cmd);
13224 }
13225
13226
13227 /* Install OSPF related vty commands. */
13228 void ospf_vty_init(void)
13229 {
13230 /* Install ospf top node. */
13231 install_node(&ospf_node);
13232
13233 /* "router ospf" commands. */
13234 install_element(CONFIG_NODE, &router_ospf_cmd);
13235 install_element(CONFIG_NODE, &no_router_ospf_cmd);
13236
13237
13238 install_default(OSPF_NODE);
13239
13240 /* "ospf router-id" commands. */
13241 install_element(OSPF_NODE, &ospf_router_id_cmd);
13242 install_element(OSPF_NODE, &ospf_router_id_old_cmd);
13243 install_element(OSPF_NODE, &no_ospf_router_id_cmd);
13244
13245 /* "passive-interface" commands. */
13246 install_element(OSPF_NODE, &ospf_passive_interface_default_cmd);
13247 install_element(OSPF_NODE, &ospf_passive_interface_addr_cmd);
13248 install_element(OSPF_NODE, &no_ospf_passive_interface_default_cmd);
13249 install_element(OSPF_NODE, &no_ospf_passive_interface_addr_cmd);
13250
13251 /* "ospf abr-type" commands. */
13252 install_element(OSPF_NODE, &ospf_abr_type_cmd);
13253 install_element(OSPF_NODE, &no_ospf_abr_type_cmd);
13254
13255 /* "ospf log-adjacency-changes" commands. */
13256 install_element(OSPF_NODE, &ospf_log_adjacency_changes_cmd);
13257 install_element(OSPF_NODE, &ospf_log_adjacency_changes_detail_cmd);
13258 install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_cmd);
13259 install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_detail_cmd);
13260
13261 /* "ospf rfc1583-compatible" commands. */
13262 install_element(OSPF_NODE, &ospf_compatible_rfc1583_cmd);
13263 install_element(OSPF_NODE, &no_ospf_compatible_rfc1583_cmd);
13264 install_element(OSPF_NODE, &ospf_rfc1583_flag_cmd);
13265 install_element(OSPF_NODE, &no_ospf_rfc1583_flag_cmd);
13266
13267 /* "ospf send-extra-data zebra" commands. */
13268 install_element(OSPF_NODE, &ospf_send_extra_data_cmd);
13269
13270 /* "network area" commands. */
13271 install_element(OSPF_NODE, &ospf_network_area_cmd);
13272 install_element(OSPF_NODE, &no_ospf_network_area_cmd);
13273
13274 /* "area authentication" commands. */
13275 install_element(OSPF_NODE,
13276 &ospf_area_authentication_message_digest_cmd);
13277 install_element(OSPF_NODE, &ospf_area_authentication_cmd);
13278 install_element(OSPF_NODE, &no_ospf_area_authentication_cmd);
13279
13280 /* "area range" commands. */
13281 install_element(OSPF_NODE, &ospf_area_range_cmd);
13282 install_element(OSPF_NODE, &ospf_area_range_cost_cmd);
13283 install_element(OSPF_NODE, &ospf_area_range_not_advertise_cmd);
13284 install_element(OSPF_NODE, &no_ospf_area_range_cmd);
13285 install_element(OSPF_NODE, &no_ospf_area_range_substitute_cmd);
13286
13287 /* "area virtual-link" commands. */
13288 install_element(OSPF_NODE, &ospf_area_vlink_cmd);
13289 install_element(OSPF_NODE, &ospf_area_vlink_intervals_cmd);
13290 install_element(OSPF_NODE, &no_ospf_area_vlink_cmd);
13291 install_element(OSPF_NODE, &no_ospf_area_vlink_intervals_cmd);
13292
13293
13294 /* "area stub" commands. */
13295 install_element(OSPF_NODE, &ospf_area_stub_no_summary_cmd);
13296 install_element(OSPF_NODE, &ospf_area_stub_cmd);
13297 install_element(OSPF_NODE, &no_ospf_area_stub_no_summary_cmd);
13298 install_element(OSPF_NODE, &no_ospf_area_stub_cmd);
13299
13300 /* "area nssa" commands. */
13301 install_element(OSPF_NODE, &ospf_area_nssa_cmd);
13302 install_element(OSPF_NODE, &no_ospf_area_nssa_cmd);
13303 install_element(OSPF_NODE, &ospf_area_nssa_range_cmd);
13304 install_element(OSPF_NODE, &no_ospf_area_nssa_range_cmd);
13305
13306 install_element(OSPF_NODE, &ospf_area_default_cost_cmd);
13307 install_element(OSPF_NODE, &no_ospf_area_default_cost_cmd);
13308
13309 install_element(OSPF_NODE, &ospf_area_shortcut_cmd);
13310 install_element(OSPF_NODE, &no_ospf_area_shortcut_cmd);
13311
13312 install_element(OSPF_NODE, &ospf_area_export_list_cmd);
13313 install_element(OSPF_NODE, &no_ospf_area_export_list_cmd);
13314
13315 install_element(OSPF_NODE, &ospf_area_filter_list_cmd);
13316 install_element(OSPF_NODE, &no_ospf_area_filter_list_cmd);
13317
13318 install_element(OSPF_NODE, &ospf_area_import_list_cmd);
13319 install_element(OSPF_NODE, &no_ospf_area_import_list_cmd);
13320
13321 /* SPF timer commands */
13322 install_element(OSPF_NODE, &ospf_timers_throttle_spf_cmd);
13323 install_element(OSPF_NODE, &no_ospf_timers_throttle_spf_cmd);
13324
13325 /* LSA timers commands */
13326 install_element(OSPF_NODE, &ospf_timers_min_ls_interval_cmd);
13327 install_element(OSPF_NODE, &no_ospf_timers_min_ls_interval_cmd);
13328 install_element(OSPF_NODE, &ospf_timers_lsa_min_arrival_cmd);
13329 install_element(OSPF_NODE, &no_ospf_timers_lsa_min_arrival_cmd);
13330
13331 /* refresh timer commands */
13332 install_element(OSPF_NODE, &ospf_refresh_timer_cmd);
13333 install_element(OSPF_NODE, &no_ospf_refresh_timer_val_cmd);
13334
13335 /* max-metric commands */
13336 install_element(OSPF_NODE, &ospf_max_metric_router_lsa_admin_cmd);
13337 install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_admin_cmd);
13338 install_element(OSPF_NODE, &ospf_max_metric_router_lsa_startup_cmd);
13339 install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_startup_cmd);
13340 install_element(OSPF_NODE, &ospf_max_metric_router_lsa_shutdown_cmd);
13341 install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_shutdown_cmd);
13342
13343 /* reference bandwidth commands */
13344 install_element(OSPF_NODE, &ospf_auto_cost_reference_bandwidth_cmd);
13345 install_element(OSPF_NODE, &no_ospf_auto_cost_reference_bandwidth_cmd);
13346
13347 /* "neighbor" commands. */
13348 install_element(OSPF_NODE, &ospf_neighbor_cmd);
13349 install_element(OSPF_NODE, &ospf_neighbor_poll_interval_cmd);
13350 install_element(OSPF_NODE, &no_ospf_neighbor_cmd);
13351 install_element(OSPF_NODE, &no_ospf_neighbor_poll_cmd);
13352
13353 /* write multiplier commands */
13354 install_element(OSPF_NODE, &ospf_write_multiplier_cmd);
13355 install_element(OSPF_NODE, &write_multiplier_cmd);
13356 install_element(OSPF_NODE, &no_ospf_write_multiplier_cmd);
13357 install_element(OSPF_NODE, &no_write_multiplier_cmd);
13358
13359 /* "proactive-arp" commands. */
13360 install_element(OSPF_NODE, &ospf_proactive_arp_cmd);
13361 install_element(OSPF_NODE, &no_ospf_proactive_arp_cmd);
13362
13363 /* TI-LFA commands */
13364 install_element(OSPF_NODE, &ospf_ti_lfa_cmd);
13365 install_element(OSPF_NODE, &no_ospf_ti_lfa_cmd);
13366
13367 /* Max path configurations */
13368 install_element(OSPF_NODE, &ospf_max_multipath_cmd);
13369 install_element(OSPF_NODE, &no_ospf_max_multipath_cmd);
13370
13371 vrf_cmd_init(NULL);
13372
13373 install_element(OSPF_NODE, &ospf_lsa_refresh_timer_cmd);
13374 install_element(OSPF_NODE, &ospf_maxage_delay_timer_cmd);
13375
13376 /* Flood Reduction commands */
13377 install_element(OSPF_NODE, &flood_reduction_cmd);
13378 install_element(OSPF_NODE, &no_flood_reduction_cmd);
13379 install_element(OSPF_NODE, &flood_reduction_area_cmd);
13380 install_element(OSPF_NODE, &no_flood_reduction_area_cmd);
13381
13382 install_element(OSPF_NODE, &ospf_socket_bufsizes_cmd);
13383 install_element(OSPF_NODE, &per_intf_socket_cmd);
13384
13385 /* Init interface related vty commands. */
13386 ospf_vty_if_init();
13387
13388 /* Init zebra related vty commands. */
13389 ospf_vty_zebra_init();
13390 }