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