]> git.proxmox.com Git - mirror_frr.git/blob - ospfd/ospf_vty.c
Merge pull request #13141 from mjstapp/fix_ospf_json_keys
[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 else
4003 vty_out(vty, "No such interface name\n");
4004 } else {
4005 if (use_json) {
4006 json_interface_sub = json_object_new_object();
4007 json_interface = json_object_new_object();
4008 }
4009
4010 show_ip_ospf_interface_sub(
4011 vty, ospf, ifp, json_interface_sub, use_json);
4012
4013 if (use_json) {
4014 json_object_object_add(json_interface,
4015 ifp->name,
4016 json_interface_sub);
4017 json_object_object_add(json_vrf, "interfaces",
4018 json_interface);
4019 }
4020 }
4021 }
4022
4023 if (use_json) {
4024 if (use_vrf) {
4025 json_object_object_add(json, ospf_get_name(ospf),
4026 json_vrf);
4027 }
4028 } else
4029 vty_out(vty, "\n");
4030
4031 return CMD_SUCCESS;
4032 }
4033
4034 static void show_ip_ospf_interface_traffic_sub(struct vty *vty,
4035 struct ospf_interface *oi,
4036 json_object *json_interface_sub,
4037 bool use_json)
4038 {
4039 if (use_json) {
4040 json_object_int_add(json_interface_sub, "ifIndex",
4041 oi->ifp->ifindex);
4042 json_object_int_add(json_interface_sub, "helloIn",
4043 oi->hello_in);
4044 json_object_int_add(json_interface_sub, "helloOut",
4045 oi->hello_out);
4046 json_object_int_add(json_interface_sub, "dbDescIn",
4047 oi->db_desc_in);
4048 json_object_int_add(json_interface_sub, "dbDescOut",
4049 oi->db_desc_out);
4050 json_object_int_add(json_interface_sub, "lsReqIn",
4051 oi->ls_req_in);
4052 json_object_int_add(json_interface_sub, "lsReqOut",
4053 oi->ls_req_out);
4054 json_object_int_add(json_interface_sub, "lsUpdIn",
4055 oi->ls_upd_in);
4056 json_object_int_add(json_interface_sub, "lsUpdOut",
4057 oi->ls_upd_out);
4058 json_object_int_add(json_interface_sub, "lsAckIn",
4059 oi->ls_ack_in);
4060 json_object_int_add(json_interface_sub, "lsAckOut",
4061 oi->ls_ack_out);
4062 json_object_int_add(json_interface_sub, "packetsQueued",
4063 listcount(oi->obuf));
4064 } else {
4065 vty_out(vty,
4066 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u %12lu\n",
4067 oi->ifp->name, oi->hello_in, oi->hello_out,
4068 oi->db_desc_in, oi->db_desc_out, oi->ls_req_in,
4069 oi->ls_req_out, oi->ls_upd_in, oi->ls_upd_out,
4070 oi->ls_ack_in, oi->ls_ack_out, listcount(oi->obuf));
4071 }
4072 }
4073
4074 /* OSPFv2 Packet Counters */
4075 static int show_ip_ospf_interface_traffic_common(
4076 struct vty *vty, struct ospf *ospf, char *intf_name, json_object *json,
4077 int display_once, uint8_t use_vrf, bool use_json)
4078 {
4079 struct vrf *vrf = NULL;
4080 struct interface *ifp = NULL;
4081 json_object *json_vrf = NULL;
4082 json_object *json_interface_sub = NULL;
4083
4084 if (!use_json && !display_once) {
4085 vty_out(vty, "\n");
4086 vty_out(vty, "%-12s%-17s%-17s%-17s%-17s%-17s%-17s\n",
4087 "Interface", " HELLO", " DB-Desc", " LS-Req",
4088 " LS-Update", " LS-Ack", " Packets");
4089 vty_out(vty, "%-10s%-18s%-18s%-17s%-17s%-17s%-17s\n", "",
4090 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
4091 " Rx/Tx", " Queued");
4092 vty_out(vty,
4093 "-------------------------------------------------------------------------------------------------------------\n");
4094 } else if (use_json) {
4095 if (use_vrf)
4096 json_vrf = json_object_new_object();
4097 else
4098 json_vrf = json;
4099 }
4100
4101 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
4102
4103 if (intf_name == NULL) {
4104 vrf = vrf_lookup_by_id(ospf->vrf_id);
4105 FOR_ALL_INTERFACES (vrf, ifp) {
4106 struct route_node *rn;
4107 struct ospf_interface *oi;
4108
4109 if (ospf_oi_count(ifp) == 0)
4110 continue;
4111
4112 for (rn = route_top(IF_OIFS(ifp)); rn;
4113 rn = route_next(rn)) {
4114 oi = rn->info;
4115
4116 if (oi == NULL)
4117 continue;
4118
4119 if (use_json) {
4120 json_interface_sub =
4121 json_object_new_object();
4122 }
4123
4124 show_ip_ospf_interface_traffic_sub(
4125 vty, oi, json_interface_sub, use_json);
4126 if (use_json) {
4127 json_object_object_add(
4128 json_vrf, ifp->name,
4129 json_interface_sub);
4130 }
4131 }
4132 }
4133 } else {
4134 /* Interface name is specified. */
4135 ifp = if_lookup_by_name(intf_name, ospf->vrf_id);
4136 if (ifp != NULL) {
4137 struct route_node *rn;
4138 struct ospf_interface *oi;
4139
4140 if (ospf_oi_count(ifp) == 0) {
4141 vty_out(vty,
4142 " OSPF not enabled on this interface %s\n",
4143 ifp->name);
4144 return CMD_SUCCESS;
4145 }
4146
4147 for (rn = route_top(IF_OIFS(ifp)); rn;
4148 rn = route_next(rn)) {
4149 oi = rn->info;
4150
4151 if (use_json) {
4152 json_interface_sub =
4153 json_object_new_object();
4154 }
4155
4156 show_ip_ospf_interface_traffic_sub(
4157 vty, oi, json_interface_sub, use_json);
4158 if (use_json) {
4159 json_object_object_add(
4160 json_vrf, ifp->name,
4161 json_interface_sub);
4162 }
4163 }
4164 }
4165 }
4166
4167 if (use_json) {
4168 if (use_vrf)
4169 json_object_object_add(json, ospf_get_name(ospf),
4170 json_vrf);
4171 } else
4172 vty_out(vty, "\n");
4173
4174 return CMD_SUCCESS;
4175 }
4176
4177 DEFUN (show_ip_ospf_interface,
4178 show_ip_ospf_interface_cmd,
4179 "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]",
4180 SHOW_STR
4181 IP_STR
4182 "OSPF information\n"
4183 VRF_CMD_HELP_STR
4184 "All VRFs\n"
4185 "Interface information\n"
4186 "Interface name\n"
4187 JSON_STR)
4188 {
4189 struct ospf *ospf;
4190 bool uj = use_json(argc, argv);
4191 struct listnode *node = NULL;
4192 char *vrf_name = NULL, *intf_name = NULL;
4193 bool all_vrf = false;
4194 int ret = CMD_SUCCESS;
4195 int inst = 0;
4196 int idx_vrf = 0, idx_intf = 0;
4197 uint8_t use_vrf = 0;
4198 json_object *json = NULL;
4199
4200 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
4201
4202 if (argv_find(argv, argc, "INTERFACE", &idx_intf))
4203 intf_name = argv[idx_intf]->arg;
4204
4205 if (uj)
4206 json = json_object_new_object();
4207
4208 /* vrf input is provided could be all or specific vrf*/
4209 if (vrf_name) {
4210 use_vrf = 1;
4211 if (all_vrf) {
4212 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
4213 if (!ospf->oi_running)
4214 continue;
4215 ret = show_ip_ospf_interface_common(
4216 vty, ospf, intf_name, use_vrf, json,
4217 uj);
4218 }
4219
4220 if (uj)
4221 vty_json(vty, json);
4222 else if (!ospf)
4223 vty_out(vty, "%% OSPF is not enabled\n");
4224
4225 return ret;
4226 }
4227 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
4228 if (ospf == NULL || !ospf->oi_running) {
4229 if (uj)
4230 vty_json(vty, json);
4231 else
4232 vty_out(vty,
4233 "%% OSPF is not enabled in vrf %s\n",
4234 vrf_name);
4235
4236 return CMD_SUCCESS;
4237 }
4238 ret = show_ip_ospf_interface_common(vty, ospf, intf_name,
4239 use_vrf, json, uj);
4240
4241 } else {
4242 /* Display default ospf (instance 0) info */
4243 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
4244 if (ospf == NULL || !ospf->oi_running) {
4245 if (uj)
4246 vty_json(vty, json);
4247 else
4248 vty_out(vty,
4249 "%% OSPF is not enabled in vrf default\n");
4250
4251 return CMD_SUCCESS;
4252 }
4253 ret = show_ip_ospf_interface_common(vty, ospf, intf_name,
4254 use_vrf, json, uj);
4255 }
4256
4257 if (uj)
4258 vty_json(vty, json);
4259
4260 return ret;
4261 }
4262
4263 DEFUN (show_ip_ospf_instance_interface,
4264 show_ip_ospf_instance_interface_cmd,
4265 "show ip ospf (1-65535) interface [INTERFACE] [json]",
4266 SHOW_STR
4267 IP_STR
4268 "OSPF information\n"
4269 "Instance ID\n"
4270 "Interface information\n"
4271 "Interface name\n"
4272 JSON_STR)
4273 {
4274 int idx_number = 3;
4275 int idx_intf = 0;
4276 struct ospf *ospf;
4277 unsigned short instance = 0;
4278 bool uj = use_json(argc, argv);
4279 char *intf_name = NULL;
4280 int ret = CMD_SUCCESS;
4281 json_object *json = NULL;
4282
4283 instance = strtoul(argv[idx_number]->arg, NULL, 10);
4284 if (instance != ospf_instance)
4285 return CMD_NOT_MY_INSTANCE;
4286
4287 ospf = ospf_lookup_instance(instance);
4288 if (!ospf || !ospf->oi_running)
4289 return CMD_SUCCESS;
4290
4291 if (uj)
4292 json = json_object_new_object();
4293
4294 if (argv_find(argv, argc, "INTERFACE", &idx_intf))
4295 intf_name = argv[idx_intf]->arg;
4296
4297 ret = show_ip_ospf_interface_common(vty, ospf, intf_name, 0, json, uj);
4298
4299 if (uj)
4300 vty_json(vty, json);
4301
4302 return ret;
4303 }
4304
4305 DEFUN (show_ip_ospf_interface_traffic,
4306 show_ip_ospf_interface_traffic_cmd,
4307 "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]",
4308 SHOW_STR
4309 IP_STR
4310 "OSPF information\n"
4311 VRF_CMD_HELP_STR
4312 "All VRFs\n"
4313 "Interface information\n"
4314 "Protocol Packet counters\n"
4315 "Interface name\n"
4316 JSON_STR)
4317 {
4318 struct ospf *ospf = NULL;
4319 struct listnode *node = NULL;
4320 char *vrf_name = NULL, *intf_name = NULL;
4321 bool all_vrf = false;
4322 int inst = 0;
4323 int idx_vrf = 0, idx_intf = 0;
4324 bool uj = use_json(argc, argv);
4325 json_object *json = NULL;
4326 int ret = CMD_SUCCESS;
4327 int display_once = 0;
4328 uint8_t use_vrf = 0;
4329
4330 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
4331
4332 if (argv_find(argv, argc, "INTERFACE", &idx_intf))
4333 intf_name = argv[idx_intf]->arg;
4334
4335 if (uj)
4336 json = json_object_new_object();
4337
4338 if (vrf_name) {
4339 use_vrf = 1;
4340 if (all_vrf) {
4341 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
4342 if (!ospf->oi_running)
4343 continue;
4344
4345 ret = show_ip_ospf_interface_traffic_common(
4346 vty, ospf, intf_name, json,
4347 display_once, use_vrf, uj);
4348 display_once = 1;
4349 }
4350
4351 if (uj)
4352 vty_json(vty, json);
4353
4354 return ret;
4355 }
4356 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
4357 if (ospf == NULL || !ospf->oi_running) {
4358 if (uj)
4359 json_object_free(json);
4360 return CMD_SUCCESS;
4361 }
4362
4363 ret = show_ip_ospf_interface_traffic_common(
4364 vty, ospf, intf_name, json, display_once, use_vrf, uj);
4365 } else {
4366 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
4367 if (ospf == NULL || !ospf->oi_running) {
4368 if (uj)
4369 json_object_free(json);
4370 return CMD_SUCCESS;
4371 }
4372
4373 ret = show_ip_ospf_interface_traffic_common(
4374 vty, ospf, intf_name, json, display_once, use_vrf, uj);
4375 }
4376
4377 if (uj)
4378 vty_json(vty, json);
4379
4380 return ret;
4381 }
4382
4383
4384 static void show_ip_ospf_neighbour_header(struct vty *vty)
4385 {
4386 vty_out(vty, "\n%-15s %-3s %-15s %-15s %-9s %-15s %-32s %5s %5s %5s\n",
4387 "Neighbor ID", "Pri", "State", "Up Time", "Dead Time",
4388 "Address", "Interface", "RXmtL", "RqstL", "DBsmL");
4389 }
4390
4391 static void show_ip_ospf_neighbour_brief(struct vty *vty,
4392 struct ospf_neighbor *nbr,
4393 struct ospf_neighbor *prev_nbr,
4394 json_object *json, bool use_json)
4395 {
4396 char msgbuf[16];
4397 char timebuf[OSPF_TIME_DUMP_SIZE];
4398 json_object *json_neighbor = NULL, *json_neigh_array = NULL;
4399 struct timeval res = {.tv_sec = 0, .tv_usec = 0};
4400 long time_val = 0;
4401 char uptime[OSPF_TIME_DUMP_SIZE];
4402
4403 if (nbr->ts_last_progress.tv_sec || nbr->ts_last_progress.tv_usec)
4404 time_val =
4405 monotime_since(&nbr->ts_last_progress, &res) / 1000LL;
4406
4407 if (use_json) {
4408 char neigh_str[INET_ADDRSTRLEN];
4409
4410 if (prev_nbr && !IPV4_ADDR_SAME(&prev_nbr->src, &nbr->src)) {
4411 /* Start new neigh list */
4412 json_neigh_array = NULL;
4413 }
4414
4415 if (nbr->state == NSM_Attempt &&
4416 nbr->router_id.s_addr == INADDR_ANY)
4417 strlcpy(neigh_str, "neighbor", sizeof(neigh_str));
4418 else
4419 inet_ntop(AF_INET, &nbr->router_id, neigh_str,
4420 sizeof(neigh_str));
4421
4422 json_object_object_get_ex(json, neigh_str, &json_neigh_array);
4423
4424 if (!json_neigh_array) {
4425 json_neigh_array = json_object_new_array();
4426 json_object_object_add(json, neigh_str,
4427 json_neigh_array);
4428 }
4429
4430 json_neighbor = json_object_new_object();
4431
4432 ospf_nbr_ism_state_message(nbr, msgbuf, sizeof(msgbuf));
4433 json_object_string_add(json_neighbor, "nbrState", msgbuf);
4434
4435 json_object_int_add(json_neighbor, "nbrPriority",
4436 nbr->priority);
4437
4438 json_object_string_add(
4439 json_neighbor, "converged",
4440 lookup_msg(ospf_nsm_state_msg, nbr->state, NULL));
4441 json_object_string_add(json_neighbor, "role",
4442 lookup_msg(ospf_ism_state_msg,
4443 ospf_nbr_ism_state(nbr),
4444 NULL));
4445 if (nbr->t_inactivity) {
4446 long time_store;
4447
4448 time_store = monotime_until(&nbr->t_inactivity->u.sands,
4449 NULL) /
4450 1000LL;
4451 json_object_int_add(json_neighbor, "upTimeInMsec",
4452 time_val);
4453 json_object_int_add(json_neighbor,
4454 "routerDeadIntervalTimerDueMsec",
4455 time_store);
4456 json_object_string_add(
4457 json_neighbor, "upTime",
4458 ospf_timeval_dump(&res, uptime,
4459 sizeof(uptime)));
4460 json_object_string_add(
4461 json_neighbor, "deadTime",
4462 ospf_timer_dump(nbr->t_inactivity, timebuf,
4463 sizeof(timebuf)));
4464 } else {
4465 json_object_string_add(json_neighbor, "deadTimeMsecs",
4466 "inactive");
4467 json_object_string_add(json_neighbor,
4468 "routerDeadIntervalTimerDueMsec",
4469 "inactive");
4470 }
4471 json_object_string_addf(json_neighbor, "ifaceAddress", "%pI4",
4472 &nbr->src);
4473 json_object_string_add(json_neighbor, "ifaceName",
4474 IF_NAME(nbr->oi));
4475 json_object_int_add(json_neighbor,
4476 "linkStateRetransmissionListCounter",
4477 ospf_ls_retransmit_count(nbr));
4478 json_object_int_add(json_neighbor,
4479 "linkStateRequestListCounter",
4480 ospf_ls_request_count(nbr));
4481 json_object_int_add(json_neighbor, "databaseSummaryListCounter",
4482 ospf_db_summary_count(nbr));
4483
4484 json_object_array_add(json_neigh_array, json_neighbor);
4485 } else {
4486 ospf_nbr_ism_state_message(nbr, msgbuf, sizeof(msgbuf));
4487
4488 if (nbr->state == NSM_Attempt &&
4489 nbr->router_id.s_addr == INADDR_ANY)
4490 vty_out(vty, "%-15s %3d %-15s ", "-", nbr->priority,
4491 msgbuf);
4492 else
4493 vty_out(vty, "%-15pI4 %3d %-15s ", &nbr->router_id,
4494 nbr->priority, msgbuf);
4495
4496 vty_out(vty, "%-15s ",
4497 ospf_timeval_dump(&res, uptime, sizeof(uptime)));
4498
4499 vty_out(vty, "%9s ",
4500 ospf_timer_dump(nbr->t_inactivity, timebuf,
4501 sizeof(timebuf)));
4502 vty_out(vty, "%-15pI4 ", &nbr->src);
4503 vty_out(vty, "%-32s %5ld %5ld %5d\n", IF_NAME(nbr->oi),
4504 ospf_ls_retransmit_count(nbr),
4505 ospf_ls_request_count(nbr), ospf_db_summary_count(nbr));
4506 }
4507 }
4508
4509 static void show_ip_ospf_neighbor_sub(struct vty *vty,
4510 struct ospf_interface *oi,
4511 json_object *json, bool use_json)
4512 {
4513 struct route_node *rn;
4514 struct ospf_neighbor *nbr, *prev_nbr = NULL;
4515
4516 for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
4517 nbr = rn->info;
4518
4519 if (!nbr)
4520 continue;
4521
4522 /* Do not show myself. */
4523 if (nbr == oi->nbr_self)
4524 continue;
4525 /* Down state is not shown. */
4526 if (nbr->state == NSM_Down)
4527 continue;
4528
4529 prev_nbr = nbr;
4530
4531 show_ip_ospf_neighbour_brief(vty, nbr, prev_nbr, json,
4532 use_json);
4533 }
4534 }
4535
4536 static int show_ip_ospf_neighbor_common(struct vty *vty, struct ospf *ospf,
4537 json_object *json, bool use_json,
4538 uint8_t use_vrf)
4539 {
4540 struct ospf_interface *oi;
4541 struct listnode *node;
4542 json_object *json_vrf = NULL;
4543 json_object *json_nbr_sub = NULL;
4544
4545 if (use_json) {
4546 if (use_vrf)
4547 json_vrf = json_object_new_object();
4548 else
4549 json_vrf = json;
4550 json_nbr_sub = json_object_new_object();
4551 }
4552
4553 if (ospf->instance) {
4554 if (use_json)
4555 json_object_int_add(json, "ospfInstance",
4556 ospf->instance);
4557 else
4558 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
4559 }
4560
4561 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
4562 if (!use_json)
4563 show_ip_ospf_neighbour_header(vty);
4564
4565 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
4566 if (ospf_interface_neighbor_count(oi) == 0)
4567 continue;
4568 show_ip_ospf_neighbor_sub(vty, oi, json_nbr_sub, use_json);
4569 }
4570
4571 if (use_json) {
4572 json_object_object_add(json_vrf, "neighbors", json_nbr_sub);
4573 if (use_vrf)
4574 json_object_object_add(json, ospf_get_name(ospf),
4575 json_vrf);
4576 } else
4577 vty_out(vty, "\n");
4578
4579 return CMD_SUCCESS;
4580 }
4581
4582 DEFUN (show_ip_ospf_neighbor,
4583 show_ip_ospf_neighbor_cmd,
4584 "show ip ospf [vrf <NAME|all>] neighbor [json]",
4585 SHOW_STR
4586 IP_STR
4587 "OSPF information\n"
4588 VRF_CMD_HELP_STR
4589 "All VRFs\n"
4590 "Neighbor list\n"
4591 JSON_STR)
4592 {
4593 struct ospf *ospf;
4594 bool uj = use_json(argc, argv);
4595 struct listnode *node = NULL;
4596 char *vrf_name = NULL;
4597 bool all_vrf = false;
4598 int ret = CMD_SUCCESS;
4599 int inst = 0;
4600 int idx_vrf = 0;
4601 uint8_t use_vrf = 0;
4602 json_object *json = NULL;
4603
4604 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
4605
4606 if (uj)
4607 json = json_object_new_object();
4608
4609 /* vrf input is provided could be all or specific vrf*/
4610 if (vrf_name) {
4611 use_vrf = 1;
4612 if (all_vrf) {
4613 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
4614 if (!ospf->oi_running)
4615 continue;
4616 ret = show_ip_ospf_neighbor_common(
4617 vty, ospf, json, uj, use_vrf);
4618 }
4619
4620 if (uj)
4621 vty_json(vty, json);
4622 else if (!ospf)
4623 vty_out(vty, "OSPF is not enabled\n");
4624
4625 return ret;
4626 }
4627
4628 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
4629 if (ospf == NULL || !ospf->oi_running) {
4630 if (uj)
4631 vty_json(vty, json);
4632 else
4633 vty_out(vty,
4634 "%% OSPF is not enabled in vrf %s\n",
4635 vrf_name);
4636
4637 return CMD_SUCCESS;
4638 }
4639 } else {
4640 /* Display default ospf (instance 0) info */
4641 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
4642 if (ospf == NULL || !ospf->oi_running) {
4643 if (uj)
4644 vty_json(vty, json);
4645 else
4646 vty_out(vty,
4647 "%% OSPF is not enabled in vrf default\n");
4648
4649 return CMD_SUCCESS;
4650 }
4651 }
4652
4653 if (ospf) {
4654 ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj,
4655 use_vrf);
4656
4657 if (uj) {
4658 vty_out(vty, "%s\n",
4659 json_object_to_json_string_ext(
4660 json, JSON_C_TO_STRING_PRETTY));
4661 }
4662 }
4663
4664 if (uj)
4665 json_object_free(json);
4666
4667 return ret;
4668 }
4669
4670
4671 DEFUN (show_ip_ospf_instance_neighbor,
4672 show_ip_ospf_instance_neighbor_cmd,
4673 "show ip ospf (1-65535) neighbor [json]",
4674 SHOW_STR
4675 IP_STR
4676 "OSPF information\n"
4677 "Instance ID\n"
4678 "Neighbor list\n"
4679 JSON_STR)
4680 {
4681 int idx_number = 3;
4682 struct ospf *ospf;
4683 unsigned short instance = 0;
4684 bool uj = use_json(argc, argv);
4685 json_object *json = NULL;
4686 int ret = CMD_SUCCESS;
4687
4688 instance = strtoul(argv[idx_number]->arg, NULL, 10);
4689 if (instance != ospf_instance)
4690 return CMD_NOT_MY_INSTANCE;
4691
4692 ospf = ospf_lookup_instance(instance);
4693 if (!ospf || !ospf->oi_running)
4694 return CMD_SUCCESS;
4695
4696 if (uj)
4697 json = json_object_new_object();
4698
4699 ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj, 0);
4700
4701 if (uj)
4702 vty_json(vty, json);
4703
4704 return ret;
4705 }
4706
4707 static int show_ip_ospf_neighbor_all_common(struct vty *vty, struct ospf *ospf,
4708 json_object *json, bool use_json,
4709 uint8_t use_vrf)
4710 {
4711 struct listnode *node;
4712 struct ospf_interface *oi;
4713 char buf[PREFIX_STRLEN];
4714 json_object *json_vrf = NULL;
4715 json_object *json_neighbor_sub = NULL;
4716
4717 if (use_json) {
4718 if (use_vrf)
4719 json_vrf = json_object_new_object();
4720 else
4721 json_vrf = json;
4722 }
4723
4724 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
4725 if (!use_json)
4726 show_ip_ospf_neighbour_header(vty);
4727
4728 if (ospf->instance) {
4729 if (use_json)
4730 json_object_int_add(json_vrf, "ospfInstance",
4731 ospf->instance);
4732 else
4733 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
4734 }
4735
4736 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
4737 struct listnode *nbr_node;
4738 struct ospf_nbr_nbma *nbr_nbma;
4739
4740 show_ip_ospf_neighbor_sub(vty, oi, json_vrf, use_json);
4741
4742 /* print Down neighbor status */
4743 for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nbr_node, nbr_nbma)) {
4744 if (nbr_nbma->nbr == NULL
4745 || nbr_nbma->nbr->state == NSM_Down) {
4746 if (use_json) {
4747 json_neighbor_sub =
4748 json_object_new_object();
4749 json_object_int_add(json_neighbor_sub,
4750 "nbrNbmaPriority",
4751 nbr_nbma->priority);
4752 json_object_boolean_true_add(
4753 json_neighbor_sub,
4754 "nbrNbmaDown");
4755 json_object_string_add(
4756 json_neighbor_sub,
4757 "nbrNbmaIfaceName",
4758 IF_NAME(oi));
4759 json_object_int_add(
4760 json_neighbor_sub,
4761 "nbrNbmaRetransmitCounter", 0);
4762 json_object_int_add(
4763 json_neighbor_sub,
4764 "nbrNbmaRequestCounter", 0);
4765 json_object_int_add(
4766 json_neighbor_sub,
4767 "nbrNbmaDbSummaryCounter", 0);
4768 json_object_object_add(
4769 json_vrf,
4770 inet_ntop(AF_INET,
4771 &nbr_nbma->addr, buf,
4772 sizeof(buf)),
4773 json_neighbor_sub);
4774 } else {
4775 vty_out(vty, "%-15s %3d %-15s %9s ",
4776 "-", nbr_nbma->priority, "Down",
4777 "-");
4778 vty_out(vty,
4779 "%-32pI4 %-20s %5d %5d %5d\n",
4780 &nbr_nbma->addr,
4781 IF_NAME(oi), 0, 0, 0);
4782 }
4783 }
4784 }
4785 }
4786
4787 if (use_json) {
4788 if (use_vrf)
4789 json_object_object_add(json, ospf_get_name(ospf),
4790 json_vrf);
4791 } else
4792 vty_out(vty, "\n");
4793
4794 return CMD_SUCCESS;
4795 }
4796
4797 DEFUN (show_ip_ospf_neighbor_all,
4798 show_ip_ospf_neighbor_all_cmd,
4799 "show ip ospf [vrf <NAME|all>] neighbor all [json]",
4800 SHOW_STR
4801 IP_STR
4802 "OSPF information\n"
4803 VRF_CMD_HELP_STR
4804 "All VRFs\n"
4805 "Neighbor list\n"
4806 "include down status neighbor\n"
4807 JSON_STR)
4808 {
4809 struct ospf *ospf;
4810 bool uj = use_json(argc, argv);
4811 struct listnode *node = NULL;
4812 char *vrf_name = NULL;
4813 bool all_vrf = false;
4814 int ret = CMD_SUCCESS;
4815 int inst = 0;
4816 int idx_vrf = 0;
4817 uint8_t use_vrf = 0;
4818 json_object *json = NULL;
4819
4820 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
4821
4822 if (uj)
4823 json = json_object_new_object();
4824
4825 /* vrf input is provided could be all or specific vrf*/
4826 if (vrf_name) {
4827 use_vrf = 1;
4828 if (all_vrf) {
4829 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
4830 if (!ospf->oi_running)
4831 continue;
4832 ret = show_ip_ospf_neighbor_all_common(
4833 vty, ospf, json, uj, use_vrf);
4834 }
4835
4836 if (uj)
4837 vty_json(vty, json);
4838
4839 return ret;
4840 }
4841
4842 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
4843 if (ospf == NULL || !ospf->oi_running) {
4844 if (uj)
4845 json_object_free(json);
4846 return CMD_SUCCESS;
4847 }
4848 } else {
4849 /* Display default ospf (instance 0) info */
4850 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
4851 if (ospf == NULL || !ospf->oi_running) {
4852 if (uj)
4853 json_object_free(json);
4854 return CMD_SUCCESS;
4855 }
4856 }
4857
4858 if (ospf) {
4859 ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj,
4860 use_vrf);
4861 if (uj) {
4862 vty_out(vty, "%s\n",
4863 json_object_to_json_string_ext(
4864 json, JSON_C_TO_STRING_PRETTY));
4865 }
4866 }
4867
4868 if (uj)
4869 json_object_free(json);
4870
4871 return ret;
4872 }
4873
4874 DEFUN (show_ip_ospf_instance_neighbor_all,
4875 show_ip_ospf_instance_neighbor_all_cmd,
4876 "show ip ospf (1-65535) neighbor all [json]",
4877 SHOW_STR
4878 IP_STR
4879 "OSPF information\n"
4880 "Instance ID\n"
4881 "Neighbor list\n"
4882 "include down status neighbor\n"
4883 JSON_STR)
4884 {
4885 int idx_number = 3;
4886 struct ospf *ospf;
4887 unsigned short instance = 0;
4888 bool uj = use_json(argc, argv);
4889 json_object *json = NULL;
4890 int ret = CMD_SUCCESS;
4891
4892 instance = strtoul(argv[idx_number]->arg, NULL, 10);
4893 if (instance != ospf_instance)
4894 return CMD_NOT_MY_INSTANCE;
4895
4896 ospf = ospf_lookup_instance(instance);
4897 if (!ospf || !ospf->oi_running)
4898 return CMD_SUCCESS;
4899 if (uj)
4900 json = json_object_new_object();
4901
4902 ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj, 0);
4903
4904 if (uj)
4905 vty_json(vty, json);
4906
4907 return ret;
4908 }
4909
4910 static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf,
4911 const char *ifname, bool use_json,
4912 uint8_t use_vrf)
4913 {
4914 struct interface *ifp;
4915 struct route_node *rn;
4916 json_object *json = NULL;
4917
4918 if (use_json)
4919 json = json_object_new_object();
4920
4921 if (ospf->instance) {
4922 if (use_json)
4923 json_object_int_add(json, "ospfInstance",
4924 ospf->instance);
4925 else
4926 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
4927 }
4928
4929 ospf_show_vrf_name(ospf, vty, json, use_vrf);
4930
4931 ifp = if_lookup_by_name(ifname, ospf->vrf_id);
4932 if (!ifp) {
4933 if (use_json)
4934 json_object_boolean_true_add(json, "noSuchIface");
4935 else
4936 vty_out(vty, "No such interface.\n");
4937 return CMD_WARNING;
4938 }
4939
4940 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
4941 struct ospf_interface *oi = rn->info;
4942
4943 if (oi == NULL)
4944 continue;
4945
4946 show_ip_ospf_neighbor_sub(vty, oi, json, use_json);
4947 }
4948
4949 if (use_json)
4950 vty_json(vty, json);
4951 else
4952 vty_out(vty, "\n");
4953
4954 return CMD_SUCCESS;
4955 }
4956
4957 DEFPY(show_ip_ospf_instance_neighbor_int,
4958 show_ip_ospf_instance_neighbor_int_cmd,
4959 "show ip ospf (1-65535)$instance neighbor IFNAME$ifname [json$json]",
4960 SHOW_STR
4961 IP_STR
4962 "OSPF information\n"
4963 "Instance ID\n"
4964 "Neighbor list\n"
4965 "Interface name\n"
4966 JSON_STR)
4967 {
4968 struct ospf *ospf;
4969
4970 if (!json)
4971 show_ip_ospf_neighbour_header(vty);
4972
4973 if (instance != ospf_instance)
4974 return CMD_NOT_MY_INSTANCE;
4975
4976 ospf = ospf_lookup_instance(instance);
4977 if (!ospf || !ospf->oi_running)
4978 return CMD_SUCCESS;
4979
4980 if (!json)
4981 show_ip_ospf_neighbour_header(vty);
4982
4983 return show_ip_ospf_neighbor_int_common(vty, ospf, ifname, !!json, 0);
4984 }
4985
4986 static void show_ip_ospf_nbr_nbma_detail_sub(struct vty *vty,
4987 struct ospf_interface *oi,
4988 struct ospf_nbr_nbma *nbr_nbma,
4989 bool use_json, json_object *json)
4990 {
4991 char timebuf[OSPF_TIME_DUMP_SIZE];
4992 json_object *json_sub = NULL;
4993
4994 if (use_json)
4995 json_sub = json_object_new_object();
4996 else /* Show neighbor ID. */
4997 vty_out(vty, " Neighbor %s,", "-");
4998
4999 /* Show interface address. */
5000 if (use_json)
5001 json_object_string_addf(json_sub, "ifaceAddress", "%pI4",
5002 &nbr_nbma->addr);
5003 else
5004 vty_out(vty, " interface address %pI4\n",
5005 &nbr_nbma->addr);
5006
5007 /* Show Area ID. */
5008 if (use_json) {
5009 json_object_string_add(json_sub, "areaId",
5010 ospf_area_desc_string(oi->area));
5011 json_object_string_add(json_sub, "iface", IF_NAME(oi));
5012 } else
5013 vty_out(vty, " In the area %s via interface %s\n",
5014 ospf_area_desc_string(oi->area), IF_NAME(oi));
5015
5016 /* Show neighbor priority and state. */
5017 if (use_json) {
5018 json_object_int_add(json_sub, "nbrPriority",
5019 nbr_nbma->priority);
5020 json_object_string_add(json_sub, "nbrState", "down");
5021 } else
5022 vty_out(vty, " Neighbor priority is %d, State is %s,",
5023 nbr_nbma->priority, "Down");
5024
5025 /* Show state changes. */
5026 if (use_json)
5027 json_object_int_add(json_sub, "stateChangeCounter",
5028 nbr_nbma->state_change);
5029 else
5030 vty_out(vty, " %d state changes\n", nbr_nbma->state_change);
5031
5032 /* Show PollInterval */
5033 if (use_json)
5034 json_object_int_add(json_sub, "pollInterval", nbr_nbma->v_poll);
5035 else
5036 vty_out(vty, " Poll interval %d\n", nbr_nbma->v_poll);
5037
5038 /* Show poll-interval timer. */
5039 if (nbr_nbma->t_poll) {
5040 if (use_json) {
5041 long time_store;
5042 time_store = monotime_until(&nbr_nbma->t_poll->u.sands,
5043 NULL) / 1000LL;
5044 json_object_int_add(json_sub,
5045 "pollIntervalTimerDueMsec",
5046 time_store);
5047 } else
5048 vty_out(vty, " Poll timer due in %s\n",
5049 ospf_timer_dump(nbr_nbma->t_poll, timebuf,
5050 sizeof(timebuf)));
5051 }
5052
5053 /* Show poll-interval timer thread. */
5054 if (use_json) {
5055 if (nbr_nbma->t_poll != NULL)
5056 json_object_string_add(json_sub,
5057 "pollIntervalTimerThread", "on");
5058 } else
5059 vty_out(vty, " Thread Poll Timer %s\n",
5060 nbr_nbma->t_poll != NULL ? "on" : "off");
5061
5062 if (use_json)
5063 json_object_object_add(json, "noNbrId", json_sub);
5064 }
5065
5066 static void show_ip_ospf_neighbor_detail_sub(struct vty *vty,
5067 struct ospf_interface *oi,
5068 struct ospf_neighbor *nbr,
5069 struct ospf_neighbor *prev_nbr,
5070 json_object *json, bool use_json)
5071 {
5072 char timebuf[OSPF_TIME_DUMP_SIZE];
5073 json_object *json_neigh = NULL, *json_neigh_array = NULL;
5074 char neigh_str[INET_ADDRSTRLEN] = {0};
5075 char neigh_state[16] = {0};
5076 struct ospf_neighbor *nbr_dr, *nbr_bdr;
5077
5078 if (use_json) {
5079 if (prev_nbr &&
5080 !IPV4_ADDR_SAME(&prev_nbr->src, &nbr->src)) {
5081 json_neigh_array = NULL;
5082 }
5083
5084 if (nbr->state == NSM_Attempt
5085 && nbr->router_id.s_addr == INADDR_ANY)
5086 strlcpy(neigh_str, "noNbrId", sizeof(neigh_str));
5087 else
5088 inet_ntop(AF_INET, &nbr->router_id,
5089 neigh_str, sizeof(neigh_str));
5090
5091 json_object_object_get_ex(json, neigh_str, &json_neigh_array);
5092
5093 if (!json_neigh_array) {
5094 json_neigh_array = json_object_new_array();
5095 json_object_object_add(json, neigh_str,
5096 json_neigh_array);
5097 }
5098
5099 json_neigh = json_object_new_object();
5100
5101 } else {
5102 /* Show neighbor ID. */
5103 if (nbr->state == NSM_Attempt
5104 && nbr->router_id.s_addr == INADDR_ANY)
5105 vty_out(vty, " Neighbor %s,", "-");
5106 else
5107 vty_out(vty, " Neighbor %pI4,",
5108 &nbr->router_id);
5109 }
5110
5111 /* Show interface address. */
5112 if (use_json)
5113 json_object_string_addf(json_neigh, "ifaceAddress", "%pI4",
5114 &nbr->address.u.prefix4);
5115 else
5116 vty_out(vty, " interface address %pI4\n",
5117 &nbr->address.u.prefix4);
5118
5119 /* Show Area ID. */
5120 if (use_json) {
5121 json_object_string_add(json_neigh, "areaId",
5122 ospf_area_desc_string(oi->area));
5123 json_object_string_add(json_neigh, "ifaceName", oi->ifp->name);
5124 if (oi->address)
5125 json_object_string_addf(json_neigh, "localIfaceAddress",
5126 "%pI4",
5127 &oi->address->u.prefix4);
5128 } else {
5129 vty_out(vty, " In the area %s via interface %s",
5130 ospf_area_desc_string(oi->area), oi->ifp->name);
5131 if (oi->address)
5132 vty_out(vty, " local interface IP %pI4\n",
5133 &oi->address->u.prefix4);
5134 else
5135 vty_out(vty, "\n");
5136 }
5137
5138 /* Show neighbor priority and state. */
5139 ospf_nbr_ism_state_message(nbr, neigh_state, sizeof(neigh_state));
5140 if (use_json) {
5141 json_object_int_add(json_neigh, "nbrPriority", nbr->priority);
5142 json_object_string_add(json_neigh, "nbrState", neigh_state);
5143 json_object_string_add(json_neigh, "role",
5144 lookup_msg(ospf_ism_state_msg,
5145 ospf_nbr_ism_state(nbr),
5146 NULL));
5147 } else {
5148 vty_out(vty,
5149 " Neighbor priority is %d, State is %s, Role is %s,",
5150 nbr->priority, neigh_state,
5151 lookup_msg(ospf_ism_state_msg, ospf_nbr_ism_state(nbr),
5152 NULL));
5153 }
5154 /* Show state changes. */
5155 if (use_json)
5156 json_object_int_add(json_neigh, "stateChangeCounter",
5157 nbr->state_change);
5158 else
5159 vty_out(vty, " %d state changes\n", nbr->state_change);
5160
5161 if (nbr->ts_last_progress.tv_sec || nbr->ts_last_progress.tv_usec) {
5162 struct timeval res;
5163 long time_store;
5164
5165 time_store =
5166 monotime_since(&nbr->ts_last_progress, &res) / 1000LL;
5167 if (use_json) {
5168 json_object_int_add(json_neigh, "lastPrgrsvChangeMsec",
5169 time_store);
5170 } else {
5171 vty_out(vty,
5172 " Most recent state change statistics:\n");
5173 vty_out(vty, " Progressive change %s ago\n",
5174 ospf_timeval_dump(&res, timebuf,
5175 sizeof(timebuf)));
5176 }
5177 }
5178
5179 if (nbr->ts_last_regress.tv_sec || nbr->ts_last_regress.tv_usec) {
5180 struct timeval res;
5181 long time_store;
5182
5183 time_store =
5184 monotime_since(&nbr->ts_last_regress, &res) / 1000LL;
5185 if (use_json) {
5186 json_object_int_add(json_neigh,
5187 "lastRegressiveChangeMsec",
5188 time_store);
5189 if (nbr->last_regress_str)
5190 json_object_string_add(
5191 json_neigh,
5192 "lastRegressiveChangeReason",
5193 nbr->last_regress_str);
5194 } else {
5195 vty_out(vty,
5196 " Regressive change %s ago, due to %s\n",
5197 ospf_timeval_dump(&res, timebuf,
5198 sizeof(timebuf)),
5199 (nbr->last_regress_str ? nbr->last_regress_str
5200 : "??"));
5201 }
5202 }
5203
5204 /* Show Designated Router ID. */
5205 if (DR(oi).s_addr == INADDR_ANY) {
5206 if (!use_json)
5207 vty_out(vty,
5208 " No designated router on this network\n");
5209 } else {
5210 nbr_dr = ospf_nbr_lookup_by_addr(oi->nbrs, &DR(oi));
5211 if (nbr_dr) {
5212 if (use_json)
5213 json_object_string_addf(
5214 json_neigh, "routerDesignatedId",
5215 "%pI4", &nbr_dr->router_id);
5216 else
5217 vty_out(vty, " DR is %pI4,",
5218 &nbr_dr->router_id);
5219 }
5220 }
5221
5222 /* Show Backup Designated Router ID. */
5223 nbr_bdr = ospf_nbr_lookup_by_addr(oi->nbrs, &BDR(oi));
5224 if (nbr_bdr == NULL) {
5225 if (!use_json)
5226 vty_out(vty,
5227 " No backup designated router on this network\n");
5228 } else {
5229 if (use_json)
5230 json_object_string_addf(json_neigh,
5231 "routerDesignatedBackupId",
5232 "%pI4", &nbr_bdr->router_id);
5233 else
5234 vty_out(vty, " BDR is %pI4\n", &nbr_bdr->router_id);
5235 }
5236
5237 /* Show options. */
5238 if (use_json) {
5239 json_object_int_add(json_neigh, "optionsCounter", nbr->options);
5240 json_object_string_add(json_neigh, "optionsList",
5241 ospf_options_dump(nbr->options));
5242 } else
5243 vty_out(vty, " Options %d %s\n", nbr->options,
5244 ospf_options_dump(nbr->options));
5245
5246 /* Show Router Dead interval timer. */
5247 if (use_json) {
5248 if (nbr->t_inactivity) {
5249 long time_store;
5250 time_store = monotime_until(&nbr->t_inactivity->u.sands,
5251 NULL)
5252 / 1000LL;
5253 json_object_int_add(json_neigh,
5254 "routerDeadIntervalTimerDueMsec",
5255 time_store);
5256 } else
5257 json_object_int_add(
5258 json_neigh,
5259 "routerDeadIntervalTimerDueMsec", -1);
5260 } else
5261 vty_out(vty, " Dead timer due in %s\n",
5262 ospf_timer_dump(nbr->t_inactivity, timebuf,
5263 sizeof(timebuf)));
5264
5265 /* Show Database Summary list. */
5266 if (use_json)
5267 json_object_int_add(json_neigh, "databaseSummaryListCounter",
5268 ospf_db_summary_count(nbr));
5269 else
5270 vty_out(vty, " Database Summary List %d\n",
5271 ospf_db_summary_count(nbr));
5272
5273 /* Show Link State Request list. */
5274 if (use_json)
5275 json_object_int_add(json_neigh, "linkStateRequestListCounter",
5276 ospf_ls_request_count(nbr));
5277 else
5278 vty_out(vty, " Link State Request List %ld\n",
5279 ospf_ls_request_count(nbr));
5280
5281 /* Show Link State Retransmission list. */
5282 if (use_json)
5283 json_object_int_add(json_neigh,
5284 "linkStateRetransmissionListCounter",
5285 ospf_ls_retransmit_count(nbr));
5286 else
5287 vty_out(vty, " Link State Retransmission List %ld\n",
5288 ospf_ls_retransmit_count(nbr));
5289
5290 /* Show inactivity timer thread. */
5291 if (use_json) {
5292 if (nbr->t_inactivity != NULL)
5293 json_object_string_add(json_neigh,
5294 "threadInactivityTimer", "on");
5295 } else
5296 vty_out(vty, " Thread Inactivity Timer %s\n",
5297 nbr->t_inactivity != NULL ? "on" : "off");
5298
5299 /* Show Database Description retransmission thread. */
5300 if (use_json) {
5301 if (nbr->t_db_desc != NULL)
5302 json_object_string_add(
5303 json_neigh,
5304 "threadDatabaseDescriptionRetransmission",
5305 "on");
5306 } else
5307 vty_out(vty,
5308 " Thread Database Description Retransmision %s\n",
5309 nbr->t_db_desc != NULL ? "on" : "off");
5310
5311 /* Show Link State Request Retransmission thread. */
5312 if (use_json) {
5313 if (nbr->t_ls_req != NULL)
5314 json_object_string_add(
5315 json_neigh,
5316 "threadLinkStateRequestRetransmission", "on");
5317 } else
5318 vty_out(vty,
5319 " Thread Link State Request Retransmission %s\n",
5320 nbr->t_ls_req != NULL ? "on" : "off");
5321
5322 /* Show Link State Update Retransmission thread. */
5323 if (use_json) {
5324 if (nbr->t_ls_upd != NULL)
5325 json_object_string_add(
5326 json_neigh,
5327 "threadLinkStateUpdateRetransmission",
5328 "on");
5329 } else
5330 vty_out(vty,
5331 " Thread Link State Update Retransmission %s\n\n",
5332 nbr->t_ls_upd != NULL ? "on" : "off");
5333
5334 if (!use_json) {
5335 vty_out(vty, " Graceful restart Helper info:\n");
5336
5337 if (OSPF_GR_IS_ACTIVE_HELPER(nbr)) {
5338 vty_out(vty,
5339 " Graceful Restart HELPER Status : Inprogress.\n");
5340
5341 vty_out(vty,
5342 " Graceful Restart grace period time: %d (seconds).\n",
5343 nbr->gr_helper_info.recvd_grace_period);
5344 vty_out(vty, " Graceful Restart reason: %s.\n",
5345 ospf_restart_reason2str(
5346 nbr->gr_helper_info.gr_restart_reason));
5347 } else {
5348 vty_out(vty,
5349 " Graceful Restart HELPER Status : None\n");
5350 }
5351
5352 if (nbr->gr_helper_info.rejected_reason
5353 != OSPF_HELPER_REJECTED_NONE)
5354 vty_out(vty, " Helper rejected reason: %s.\n",
5355 ospf_rejected_reason2str(
5356 nbr->gr_helper_info.rejected_reason));
5357
5358 if (nbr->gr_helper_info.helper_exit_reason
5359 != OSPF_GR_HELPER_EXIT_NONE)
5360 vty_out(vty, " Last helper exit reason: %s.\n\n",
5361 ospf_exit_reason2str(
5362 nbr->gr_helper_info.helper_exit_reason));
5363 else
5364 vty_out(vty, "\n");
5365 } else {
5366 json_object_string_add(json_neigh, "grHelperStatus",
5367 OSPF_GR_IS_ACTIVE_HELPER(nbr) ?
5368 "Inprogress"
5369 : "None");
5370 if (OSPF_GR_IS_ACTIVE_HELPER(nbr)) {
5371 json_object_int_add(
5372 json_neigh, "graceInterval",
5373 nbr->gr_helper_info.recvd_grace_period);
5374 json_object_string_add(
5375 json_neigh, "grRestartReason",
5376 ospf_restart_reason2str(
5377 nbr->gr_helper_info.gr_restart_reason));
5378 }
5379
5380 if (nbr->gr_helper_info.rejected_reason
5381 != OSPF_HELPER_REJECTED_NONE)
5382 json_object_string_add(
5383 json_neigh, "helperRejectReason",
5384 ospf_rejected_reason2str(
5385 nbr->gr_helper_info.rejected_reason));
5386
5387 if (nbr->gr_helper_info.helper_exit_reason
5388 != OSPF_GR_HELPER_EXIT_NONE)
5389 json_object_string_add(
5390 json_neigh, "helperExitReason",
5391 ospf_exit_reason2str(
5392 nbr->gr_helper_info
5393 .helper_exit_reason));
5394 }
5395
5396 bfd_sess_show(vty, json_neigh, nbr->bfd_session);
5397
5398 if (use_json)
5399 json_object_array_add(json_neigh_array, json_neigh);
5400
5401 }
5402
5403 static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf,
5404 struct in_addr *router_id,
5405 bool use_json, uint8_t use_vrf,
5406 bool is_detail,
5407 json_object *json_vrf)
5408 {
5409 struct listnode *node;
5410 struct ospf_neighbor *nbr;
5411 struct ospf_interface *oi;
5412 json_object *json = NULL;
5413
5414 if (use_json)
5415 json = json_object_new_object();
5416
5417 if (ospf->instance) {
5418 if (use_json)
5419 json_object_int_add(json, "ospfInstance",
5420 ospf->instance);
5421 else
5422 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
5423 }
5424
5425 ospf_show_vrf_name(ospf, vty, json, use_vrf);
5426
5427 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
5428 nbr = ospf_nbr_lookup_by_routerid(oi->nbrs, router_id);
5429
5430 if (!nbr)
5431 continue;
5432
5433 if (is_detail)
5434 show_ip_ospf_neighbor_detail_sub(vty, oi, nbr, NULL,
5435 json, use_json);
5436 else
5437 show_ip_ospf_neighbour_brief(vty, nbr, NULL, json,
5438 use_json);
5439 }
5440
5441 if (json_vrf && use_json) {
5442 json_object_object_add(
5443 json_vrf,
5444 (ospf->vrf_id == VRF_DEFAULT) ? "default" : ospf->name,
5445 json);
5446 return CMD_SUCCESS;
5447 }
5448
5449 if (use_json)
5450 vty_json(vty, json);
5451 else
5452 vty_out(vty, "\n");
5453
5454 return CMD_SUCCESS;
5455 }
5456
5457 DEFPY(show_ip_ospf_neighbor_id,
5458 show_ip_ospf_neighbor_id_cmd,
5459 "show ip ospf [vrf NAME$vrf_name] neighbor A.B.C.D$router_id [detail$detail] [json$json]",
5460 SHOW_STR
5461 IP_STR
5462 "OSPF information\n"
5463 VRF_CMD_HELP_STR
5464 "Neighbor list\n"
5465 "Neighbor ID\n"
5466 "Detailed output\n"
5467 JSON_STR)
5468 {
5469 struct ospf *ospf;
5470 struct listnode *node;
5471 int ret = CMD_SUCCESS;
5472 int inst = 0;
5473
5474 if (vrf_name && !strmatch(vrf_name, "all")) {
5475 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
5476 if (ospf == NULL || !ospf->oi_running) {
5477 if (!json)
5478 vty_out(vty,
5479 "%% OSPF is not enabled in vrf %s\n",
5480 vrf_name);
5481 else
5482 vty_json_empty(vty);
5483 return CMD_SUCCESS;
5484 }
5485 ret = show_ip_ospf_neighbor_id_common(
5486 vty, ospf, &router_id, !!json, 0, !!detail, NULL);
5487 } else {
5488 json_object *json_vrf = NULL;
5489
5490 if (json)
5491 json_vrf = json_object_new_object();
5492 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
5493 if (!ospf->oi_running)
5494 continue;
5495 ret = show_ip_ospf_neighbor_id_common(
5496 vty, ospf, &router_id, !!json, 0, !!detail,
5497 json_vrf);
5498 }
5499 if (json)
5500 vty_json(vty, json_vrf);
5501 }
5502
5503 return ret;
5504 }
5505
5506 DEFPY(show_ip_ospf_instance_neighbor_id, show_ip_ospf_instance_neighbor_id_cmd,
5507 "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [detail$detail] [json$json]",
5508 SHOW_STR IP_STR
5509 "OSPF information\n"
5510 "Instance ID\n"
5511 "Neighbor list\n"
5512 "Neighbor ID\n"
5513 "Detailed output\n" JSON_STR)
5514 {
5515 struct ospf *ospf;
5516
5517 if (instance != ospf_instance)
5518 return CMD_NOT_MY_INSTANCE;
5519
5520 ospf = ospf_lookup_instance(instance);
5521 if (!ospf || !ospf->oi_running)
5522 return CMD_SUCCESS;
5523
5524 return show_ip_ospf_neighbor_id_common(vty, ospf, &router_id, !!json, 0,
5525 !!detail, NULL);
5526 }
5527
5528 static int show_ip_ospf_neighbor_detail_common(struct vty *vty,
5529 struct ospf *ospf,
5530 json_object *json, bool use_json,
5531 uint8_t use_vrf)
5532 {
5533 struct ospf_interface *oi;
5534 struct listnode *node;
5535 json_object *json_vrf = NULL;
5536 json_object *json_nbr_sub = NULL;
5537
5538 if (use_json) {
5539 if (use_vrf)
5540 json_vrf = json_object_new_object();
5541 else
5542 json_vrf = json;
5543
5544 json_nbr_sub = json_object_new_object();
5545 }
5546
5547 if (ospf->instance) {
5548 if (use_json)
5549 json_object_int_add(json, "ospfInstance",
5550 ospf->instance);
5551 else
5552 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
5553 }
5554
5555 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
5556
5557 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
5558 struct route_node *rn;
5559 struct ospf_neighbor *nbr, *prev_nbr = NULL;
5560
5561 for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
5562 nbr = rn->info;
5563
5564 if (!nbr)
5565 continue;
5566
5567 if (nbr != oi->nbr_self) {
5568 if (nbr->state != NSM_Down) {
5569 show_ip_ospf_neighbor_detail_sub(
5570 vty, oi, nbr, prev_nbr,
5571 json_nbr_sub, use_json);
5572 }
5573 }
5574 prev_nbr = nbr;
5575 }
5576 }
5577
5578 if (use_json) {
5579 json_object_object_add(json_vrf, "neighbors",
5580 json_nbr_sub);
5581 if (use_vrf)
5582 json_object_object_add(json, ospf_get_name(ospf),
5583 json_vrf);
5584 } else
5585 vty_out(vty, "\n");
5586
5587 return CMD_SUCCESS;
5588 }
5589
5590 DEFPY(show_ip_ospf_neighbor_detail,
5591 show_ip_ospf_neighbor_detail_cmd,
5592 "show ip ospf [vrf <NAME|all>$vrf_name] neighbor detail [json$json]",
5593 SHOW_STR
5594 IP_STR
5595 "OSPF information\n"
5596 VRF_CMD_HELP_STR
5597 "All VRFs\n"
5598 "Neighbor list\n"
5599 "detail of all neighbors\n"
5600 JSON_STR)
5601 {
5602 struct ospf *ospf;
5603 struct listnode *node = NULL;
5604 int ret = CMD_SUCCESS;
5605 int inst = 0;
5606 uint8_t use_vrf = 0;
5607 json_object *json_vrf = NULL;
5608
5609 if (json)
5610 json_vrf = json_object_new_object();
5611
5612 /* vrf input is provided could be all or specific vrf*/
5613 if (vrf_name) {
5614 use_vrf = 1;
5615 if (strmatch(vrf_name, "all")) {
5616 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
5617 if (!ospf->oi_running)
5618 continue;
5619 ret = show_ip_ospf_neighbor_detail_common(
5620 vty, ospf, json_vrf, !!json, use_vrf);
5621 }
5622 if (json)
5623 vty_json(vty, json_vrf);
5624
5625 return ret;
5626 }
5627 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
5628 if (ospf == NULL || !ospf->oi_running) {
5629 if (json)
5630 vty_json(vty, json_vrf);
5631 else
5632 vty_out(vty,
5633 "%% OSPF is not enabled in vrf %s\n",
5634 vrf_name);
5635 return CMD_SUCCESS;
5636 }
5637 } else {
5638 /* Display default ospf (instance 0) info */
5639 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
5640 if (ospf == NULL || !ospf->oi_running) {
5641 if (json)
5642 vty_json(vty, json_vrf);
5643 else
5644 vty_out(vty, "%% OSPF is not enabled\n");
5645 return CMD_SUCCESS;
5646 }
5647 }
5648
5649 if (ospf)
5650 ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json_vrf,
5651 !!json, use_vrf);
5652
5653 if (json)
5654 vty_json(vty, json_vrf);
5655
5656 return ret;
5657 }
5658
5659 DEFUN (show_ip_ospf_instance_neighbor_detail,
5660 show_ip_ospf_instance_neighbor_detail_cmd,
5661 "show ip ospf (1-65535) neighbor detail [json]",
5662 SHOW_STR
5663 IP_STR
5664 "OSPF information\n"
5665 "Instance ID\n"
5666 "Neighbor list\n"
5667 "detail of all neighbors\n"
5668 JSON_STR)
5669 {
5670 int idx_number = 3;
5671 struct ospf *ospf;
5672 unsigned short instance = 0;
5673 bool uj = use_json(argc, argv);
5674 json_object *json = NULL;
5675 int ret = CMD_SUCCESS;
5676
5677 instance = strtoul(argv[idx_number]->arg, NULL, 10);
5678 if (instance != ospf_instance)
5679 return CMD_NOT_MY_INSTANCE;
5680
5681 ospf = ospf_lookup_instance(instance);
5682 if (!ospf || !ospf->oi_running)
5683 return CMD_SUCCESS;
5684
5685 if (uj)
5686 json = json_object_new_object();
5687
5688 ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj, 0);
5689
5690 if (uj)
5691 vty_json(vty, json);
5692
5693 return ret;
5694 }
5695
5696 static int show_ip_ospf_neighbor_detail_all_common(struct vty *vty,
5697 struct ospf *ospf,
5698 json_object *json,
5699 bool use_json,
5700 uint8_t use_vrf)
5701 {
5702 struct listnode *node;
5703 struct ospf_interface *oi;
5704 json_object *json_vrf = NULL;
5705
5706 if (use_json) {
5707 if (use_vrf)
5708 json_vrf = json_object_new_object();
5709 else
5710 json_vrf = json;
5711 }
5712
5713 if (ospf->instance) {
5714 if (use_json)
5715 json_object_int_add(json, "ospfInstance",
5716 ospf->instance);
5717 else
5718 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
5719 }
5720
5721 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
5722
5723 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
5724 struct route_node *rn;
5725 struct ospf_neighbor *nbr, *prev_nbr = NULL;
5726 struct ospf_nbr_nbma *nbr_nbma;
5727
5728 for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
5729 nbr = rn->info;
5730
5731 if (!nbr)
5732 continue;
5733
5734 if (nbr != oi->nbr_self)
5735 if (nbr->state != NSM_Down)
5736 show_ip_ospf_neighbor_detail_sub(
5737 vty, oi, rn->info, prev_nbr,
5738 json_vrf, use_json);
5739 prev_nbr = nbr;
5740 }
5741
5742 if (oi->type != OSPF_IFTYPE_NBMA)
5743 continue;
5744
5745 struct listnode *nd;
5746
5747 for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nd, nbr_nbma)) {
5748 if (nbr_nbma->nbr == NULL ||
5749 nbr_nbma->nbr->state == NSM_Down)
5750 show_ip_ospf_nbr_nbma_detail_sub(
5751 vty, oi, nbr_nbma, use_json, json_vrf);
5752 }
5753 }
5754
5755 if (use_json) {
5756 if (use_vrf)
5757 json_object_object_add(json, ospf_get_name(ospf),
5758 json_vrf);
5759 } else {
5760 vty_out(vty, "\n");
5761 }
5762
5763 return CMD_SUCCESS;
5764 }
5765
5766 DEFUN (show_ip_ospf_neighbor_detail_all,
5767 show_ip_ospf_neighbor_detail_all_cmd,
5768 "show ip ospf [vrf <NAME|all>] neighbor detail all [json]",
5769 SHOW_STR
5770 IP_STR
5771 "OSPF information\n"
5772 VRF_CMD_HELP_STR
5773 "All VRFs\n"
5774 "Neighbor list\n"
5775 "detail of all neighbors\n"
5776 "include down status neighbor\n"
5777 JSON_STR)
5778 {
5779 struct ospf *ospf;
5780 bool uj = use_json(argc, argv);
5781 struct listnode *node = NULL;
5782 char *vrf_name = NULL;
5783 bool all_vrf = false;
5784 int ret = CMD_SUCCESS;
5785 int inst = 0;
5786 int idx_vrf = 0;
5787 uint8_t use_vrf = 0;
5788 json_object *json = NULL;
5789
5790 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
5791
5792 if (uj)
5793 json = json_object_new_object();
5794
5795 /* vrf input is provided could be all or specific vrf*/
5796 if (vrf_name) {
5797 use_vrf = 1;
5798 if (all_vrf) {
5799 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
5800 if (!ospf->oi_running)
5801 continue;
5802 ret = show_ip_ospf_neighbor_detail_all_common(
5803 vty, ospf, json, uj, use_vrf);
5804 }
5805
5806 if (uj)
5807 vty_json(vty, json);
5808
5809 return ret;
5810 }
5811 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
5812 if (ospf == NULL || !ospf->oi_running) {
5813 if (uj)
5814 json_object_free(json);
5815 return CMD_SUCCESS;
5816 }
5817 } else {
5818 /* Display default ospf (instance 0) info */
5819 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
5820 if (ospf == NULL || !ospf->oi_running) {
5821 if (uj)
5822 json_object_free(json);
5823 return CMD_SUCCESS;
5824 }
5825 }
5826
5827 if (ospf) {
5828 ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json,
5829 uj, use_vrf);
5830 if (uj) {
5831 vty_out(vty, "%s\n",
5832 json_object_to_json_string_ext(
5833 json, JSON_C_TO_STRING_PRETTY));
5834 }
5835 }
5836
5837 if (uj)
5838 json_object_free(json);
5839
5840 return ret;
5841 }
5842
5843 DEFUN (show_ip_ospf_instance_neighbor_detail_all,
5844 show_ip_ospf_instance_neighbor_detail_all_cmd,
5845 "show ip ospf (1-65535) neighbor detail all [json]",
5846 SHOW_STR
5847 IP_STR
5848 "OSPF information\n"
5849 "Instance ID\n"
5850 "Neighbor list\n"
5851 "detail of all neighbors\n"
5852 "include down status neighbor\n"
5853 JSON_STR)
5854 {
5855 int idx_number = 3;
5856 struct ospf *ospf;
5857 unsigned short instance = 0;
5858 bool uj = use_json(argc, argv);
5859 json_object *json = NULL;
5860 int ret = CMD_SUCCESS;
5861
5862 instance = strtoul(argv[idx_number]->arg, NULL, 10);
5863 if (instance != ospf_instance)
5864 return CMD_NOT_MY_INSTANCE;
5865
5866 ospf = ospf_lookup_instance(instance);
5867 if (!ospf || !ospf->oi_running)
5868 return CMD_SUCCESS;
5869
5870 if (uj)
5871 json = json_object_new_object();
5872
5873 ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json, uj, 0);
5874
5875 if (uj)
5876 vty_json(vty, json);
5877
5878 return ret;
5879 }
5880
5881 static int show_ip_ospf_neighbor_int_detail_common(struct vty *vty,
5882 struct ospf *ospf,
5883 const char *ifname,
5884 bool use_json,
5885 json_object *json_vrf)
5886 {
5887 struct ospf_interface *oi;
5888 struct interface *ifp;
5889 struct route_node *rn, *nrn;
5890 struct ospf_neighbor *nbr;
5891 json_object *json = NULL;
5892
5893 if (use_json) {
5894 json = json_object_new_object();
5895 if (json_vrf)
5896 json_object_object_add(json_vrf,
5897 (ospf->vrf_id == VRF_DEFAULT)
5898 ? "default"
5899 : ospf->name,
5900 json);
5901 }
5902
5903 if (ospf->instance) {
5904 if (use_json)
5905 json_object_int_add(json, "ospfInstance",
5906 ospf->instance);
5907 else
5908 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
5909 }
5910
5911 ifp = if_lookup_by_name(ifname, ospf->vrf_id);
5912 if (!ifp) {
5913 if (!use_json) {
5914 vty_out(vty, "No such interface.\n");
5915 } else {
5916 if (!json_vrf)
5917 vty_json(vty, json);
5918 }
5919 return CMD_WARNING;
5920 }
5921
5922 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
5923 oi = rn->info;
5924
5925 if (!oi)
5926 continue;
5927
5928 for (nrn = route_top(oi->nbrs); nrn; nrn = route_next(nrn)) {
5929 nbr = nrn->info;
5930
5931 if (!nbr)
5932 continue;
5933
5934 if (nbr == oi->nbr_self)
5935 continue;
5936
5937 if (nbr->state == NSM_Down)
5938 continue;
5939
5940 show_ip_ospf_neighbor_detail_sub(vty, oi, nbr, NULL,
5941 json, use_json);
5942 }
5943 }
5944
5945 if (use_json) {
5946 if (!json_vrf)
5947 vty_json(vty, json);
5948 } else {
5949 vty_out(vty, "\n");
5950 }
5951
5952 return CMD_SUCCESS;
5953 }
5954
5955 DEFPY(show_ip_ospf_neighbor_int,
5956 show_ip_ospf_neighbor_int_cmd,
5957 "show ip ospf [vrf NAME$vrf_name] neighbor IFNAME$ifname [json$json]",
5958 SHOW_STR
5959 IP_STR
5960 "OSPF information\n"
5961 VRF_CMD_HELP_STR
5962 "Neighbor list\n"
5963 "Interface name\n"
5964 JSON_STR)
5965 {
5966 struct ospf *ospf;
5967 int ret = CMD_SUCCESS;
5968 struct interface *ifp = NULL;
5969 vrf_id_t vrf_id = VRF_DEFAULT;
5970 struct vrf *vrf = NULL;
5971
5972 if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME))
5973 vrf_name = NULL;
5974 if (vrf_name) {
5975 vrf = vrf_lookup_by_name(vrf_name);
5976 if (vrf)
5977 vrf_id = vrf->vrf_id;
5978 }
5979 ospf = ospf_lookup_by_vrf_id(vrf_id);
5980
5981 if (!ospf || !ospf->oi_running) {
5982 if (json)
5983 vty_json_empty(vty);
5984 return ret;
5985 }
5986
5987 if (!json)
5988 show_ip_ospf_neighbour_header(vty);
5989
5990 ifp = if_lookup_by_name(ifname, vrf_id);
5991 if (!ifp) {
5992 if (json)
5993 vty_json_empty(vty);
5994 else
5995 vty_out(vty, "No such interface.\n");
5996 return ret;
5997 }
5998
5999 ret = show_ip_ospf_neighbor_int_common(vty, ospf, ifname, !!json, 0);
6000 return ret;
6001 }
6002
6003 DEFPY(show_ip_ospf_neighbor_int_detail,
6004 show_ip_ospf_neighbor_int_detail_cmd,
6005 "show ip ospf [vrf NAME$vrf_name] neighbor IFNAME$ifname detail [json$json]",
6006 SHOW_STR
6007 IP_STR
6008 "OSPF information\n"
6009 VRF_CMD_HELP_STR
6010 "Neighbor list\n"
6011 "Interface name\n"
6012 "detail of all neighbors\n"
6013 JSON_STR)
6014 {
6015 struct ospf *ospf;
6016 struct listnode *node = NULL;
6017 int ret = CMD_SUCCESS;
6018 bool ospf_output = false;
6019
6020 if (vrf_name && !strmatch(vrf_name, "all")) {
6021 int inst = 0;
6022
6023 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
6024 if (ospf == NULL || !ospf->oi_running) {
6025 if (!json)
6026 vty_out(vty,
6027 "%% OSPF is not enabled in vrf %s\n",
6028 vrf_name);
6029 else
6030 vty_json_empty(vty);
6031 return CMD_SUCCESS;
6032 }
6033 return show_ip_ospf_neighbor_int_detail_common(
6034 vty, ospf, ifname, !!json, NULL);
6035 }
6036
6037 json_object *json_vrf = NULL;
6038
6039 if (json)
6040 json_vrf = json_object_new_object();
6041
6042 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
6043 if (!ospf->oi_running)
6044 continue;
6045 ospf_output = true;
6046 ret = show_ip_ospf_neighbor_int_detail_common(vty, ospf, ifname,
6047 !!json, json_vrf);
6048 }
6049
6050 if (json) {
6051 vty_json(vty, json_vrf);
6052 return ret;
6053 }
6054
6055 if (!ospf_output)
6056 vty_out(vty, "%% OSPF instance not found\n");
6057
6058 return ret;
6059 }
6060
6061 DEFPY(show_ip_ospf_instance_neighbor_int_detail,
6062 show_ip_ospf_instance_neighbor_int_detail_cmd,
6063 "show ip ospf (1-65535)$instance neighbor IFNAME$ifname detail [json$json]",
6064 SHOW_STR
6065 IP_STR
6066 "OSPF information\n"
6067 "Instance ID\n"
6068 "Neighbor list\n"
6069 "Interface name\n"
6070 "detail of all neighbors\n"
6071 JSON_STR)
6072 {
6073 struct ospf *ospf;
6074
6075 if (instance != ospf_instance)
6076 return CMD_NOT_MY_INSTANCE;
6077
6078 ospf = ospf_lookup_instance(instance);
6079 if (!ospf || !ospf->oi_running)
6080 return CMD_SUCCESS;
6081
6082 return show_ip_ospf_neighbor_int_detail_common(vty, ospf, ifname,
6083 !!json, NULL);
6084 }
6085
6086 /* Show functions */
6087 static int show_lsa_summary(struct vty *vty, struct ospf_lsa *lsa, int self,
6088 json_object *json_lsa)
6089 {
6090 struct router_lsa *rl;
6091 struct summary_lsa *sl;
6092 struct as_external_lsa *asel;
6093 struct prefix_ipv4 p;
6094
6095 if (lsa == NULL)
6096 return 0;
6097
6098 /* If self option is set, check LSA self flag. */
6099 if (self == 0 || IS_LSA_SELF(lsa)) {
6100
6101 if (!json_lsa) {
6102 /* LSA common part show. */
6103 vty_out(vty, "%-15pI4", &lsa->data->id);
6104 vty_out(vty, "%-15pI4 %4d 0x%08lx 0x%04x",
6105 &lsa->data->adv_router, LS_AGE(lsa),
6106 (unsigned long)ntohl(lsa->data->ls_seqnum),
6107 ntohs(lsa->data->checksum));
6108 } else {
6109 char seqnum[10];
6110 char checksum[10];
6111
6112 snprintf(seqnum, sizeof(seqnum), "%x",
6113 ntohl(lsa->data->ls_seqnum));
6114 snprintf(checksum, sizeof(checksum), "%x",
6115 ntohs(lsa->data->checksum));
6116 json_object_string_addf(json_lsa, "lsId", "%pI4",
6117 &lsa->data->id);
6118 json_object_string_addf(json_lsa, "advertisedRouter",
6119 "%pI4", &lsa->data->adv_router);
6120 json_object_int_add(json_lsa, "lsaAge", LS_AGE(lsa));
6121 json_object_string_add(json_lsa, "sequenceNumber",
6122 seqnum);
6123 json_object_string_add(json_lsa, "checksum", checksum);
6124 }
6125
6126 /* LSA specific part show. */
6127 switch (lsa->data->type) {
6128 case OSPF_ROUTER_LSA:
6129 rl = (struct router_lsa *)lsa->data;
6130
6131 if (!json_lsa)
6132 vty_out(vty, " %-d", ntohs(rl->links));
6133 else
6134 json_object_int_add(json_lsa,
6135 "numOfRouterLinks",
6136 ntohs(rl->links));
6137 break;
6138 case OSPF_SUMMARY_LSA:
6139 sl = (struct summary_lsa *)lsa->data;
6140
6141 p.family = AF_INET;
6142 p.prefix = sl->header.id;
6143 p.prefixlen = ip_masklen(sl->mask);
6144 apply_mask_ipv4(&p);
6145
6146 if (!json_lsa)
6147 vty_out(vty, " %pFX", &p);
6148 else {
6149 json_object_string_addf(
6150 json_lsa, "summaryAddress", "%pFX", &p);
6151 }
6152 break;
6153 case OSPF_AS_EXTERNAL_LSA:
6154 case OSPF_AS_NSSA_LSA:
6155 asel = (struct as_external_lsa *)lsa->data;
6156
6157 p.family = AF_INET;
6158 p.prefix = asel->header.id;
6159 p.prefixlen = ip_masklen(asel->mask);
6160 apply_mask_ipv4(&p);
6161
6162 if (!json_lsa)
6163 vty_out(vty, " %s %pFX [0x%lx]",
6164 IS_EXTERNAL_METRIC(asel->e[0].tos)
6165 ? "E2"
6166 : "E1",
6167 &p,
6168 (unsigned long)ntohl(
6169 asel->e[0].route_tag));
6170 else {
6171 json_object_string_add(
6172 json_lsa, "metricType",
6173 IS_EXTERNAL_METRIC(asel->e[0].tos)
6174 ? "E2"
6175 : "E1");
6176 json_object_string_addf(json_lsa, "route",
6177 "%pFX", &p);
6178 json_object_int_add(
6179 json_lsa, "tag",
6180 (unsigned long)ntohl(
6181 asel->e[0].route_tag));
6182 }
6183 break;
6184 case OSPF_NETWORK_LSA:
6185 case OSPF_ASBR_SUMMARY_LSA:
6186 case OSPF_OPAQUE_LINK_LSA:
6187 case OSPF_OPAQUE_AREA_LSA:
6188 case OSPF_OPAQUE_AS_LSA:
6189 default:
6190 break;
6191 }
6192
6193 if (!json_lsa)
6194 vty_out(vty, "\n");
6195 }
6196
6197 return 1;
6198 }
6199
6200 static const char *const show_database_desc[] = {
6201 "unknown",
6202 "Router Link States",
6203 "Net Link States",
6204 "Summary Link States",
6205 "ASBR-Summary Link States",
6206 "AS External Link States",
6207 "Group Membership LSA",
6208 "NSSA-external Link States",
6209 "Type-8 LSA",
6210 "Link-Local Opaque-LSA",
6211 "Area-Local Opaque-LSA",
6212 "AS-external Opaque-LSA",
6213 };
6214
6215 static const char * const show_database_desc_json[] = {
6216 "unknown",
6217 "routerLinkStates",
6218 "networkLinkStates",
6219 "summaryLinkStates",
6220 "asbrSummaryLinkStates",
6221 "asExternalLinkStates",
6222 "groupMembershipLsa",
6223 "nssaExternalLinkStates",
6224 "type8Lsa",
6225 "linkLocalOpaqueLsa",
6226 "areaLocalOpaqueLsa",
6227 "asExternalOpaqueLsa",
6228 };
6229
6230 static const char *const show_database_desc_count_json[] = {
6231 "unknownCount",
6232 "routerLinkStatesCount",
6233 "networkLinkStatesCount",
6234 "summaryLinkStatesCount",
6235 "asbrSummaryLinkStatesCount",
6236 "asExternalLinkStatesCount",
6237 "groupMembershipLsaCount",
6238 "nssaExternalLinkStatesCount",
6239 "type8LsaCount",
6240 "linkLocalOpaqueLsaCount",
6241 "areaLocalOpaqueLsaCount",
6242 "asExternalOpaqueLsaCount",
6243 };
6244
6245 static const char *const show_database_header[] = {
6246 "",
6247 "Link ID ADV Router Age Seq# CkSum Link count",
6248 "Link ID ADV Router Age Seq# CkSum",
6249 "Link ID ADV Router Age Seq# CkSum Route",
6250 "Link ID ADV Router Age Seq# CkSum",
6251 "Link ID ADV Router Age Seq# CkSum Route",
6252 " --- header for Group Member ----",
6253 "Link ID ADV Router Age Seq# CkSum Route",
6254 " --- type-8 ---",
6255 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6256 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6257 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6258 };
6259
6260 static void show_ip_ospf_database_header(struct vty *vty, struct ospf_lsa *lsa,
6261 json_object *json)
6262 {
6263 struct router_lsa *rlsa = (struct router_lsa *)lsa->data;
6264
6265 if (!json) {
6266 if (IS_LSA_SELF(lsa))
6267 vty_out(vty, " LS age: %d%s\n", LS_AGE(lsa),
6268 CHECK_FLAG(lsa->data->ls_age, DO_NOT_AGE)
6269 ? "(S-DNA)"
6270 : "");
6271 else
6272 vty_out(vty, " LS age: %d%s\n", LS_AGE(lsa),
6273 CHECK_FLAG(lsa->data->ls_age, DO_NOT_AGE)
6274 ? "(DNA)"
6275 : "");
6276 vty_out(vty, " Options: 0x%-2x : %s\n", lsa->data->options,
6277 ospf_options_dump(lsa->data->options));
6278 vty_out(vty, " LS Flags: 0x%-2x %s\n", lsa->flags,
6279 ((lsa->flags & OSPF_LSA_LOCAL_XLT)
6280 ? "(Translated from Type-7)"
6281 : ""));
6282
6283 if (lsa->data->type == OSPF_ROUTER_LSA) {
6284 vty_out(vty, " Flags: 0x%x", rlsa->flags);
6285
6286 if (rlsa->flags)
6287 vty_out(vty, " :%s%s%s%s",
6288 IS_ROUTER_LSA_BORDER(rlsa) ? " ABR"
6289 : "",
6290 IS_ROUTER_LSA_EXTERNAL(rlsa) ? " ASBR"
6291 : "",
6292 IS_ROUTER_LSA_VIRTUAL(rlsa)
6293 ? " VL-endpoint"
6294 : "",
6295 IS_ROUTER_LSA_SHORTCUT(rlsa)
6296 ? " Shortcut"
6297 : "");
6298
6299 vty_out(vty, "\n");
6300 }
6301 vty_out(vty, " LS Type: %s\n",
6302 lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL));
6303 vty_out(vty, " Link State ID: %pI4 %s\n",
6304 &lsa->data->id,
6305 lookup_msg(ospf_link_state_id_type_msg, lsa->data->type,
6306 NULL));
6307 vty_out(vty, " Advertising Router: %pI4\n",
6308 &lsa->data->adv_router);
6309 vty_out(vty, " LS Seq Number: %08lx\n",
6310 (unsigned long)ntohl(lsa->data->ls_seqnum));
6311 vty_out(vty, " Checksum: 0x%04x\n",
6312 ntohs(lsa->data->checksum));
6313 vty_out(vty, " Length: %d\n\n", ntohs(lsa->data->length));
6314 } else {
6315 char seqnum[10];
6316 char checksum[10];
6317
6318 snprintf(seqnum, 10, "%x", ntohl(lsa->data->ls_seqnum));
6319 snprintf(checksum, 10, "%x", ntohs(lsa->data->checksum));
6320
6321 json_object_int_add(json, "lsaAge", LS_AGE(lsa));
6322 json_object_string_add(json, "options",
6323 ospf_options_dump(lsa->data->options));
6324 json_object_int_add(json, "lsaFlags", lsa->flags);
6325
6326 if (lsa->flags & OSPF_LSA_LOCAL_XLT)
6327 json_object_boolean_true_add(json,
6328 "translatedFromType7");
6329
6330 if (lsa->data->type == OSPF_ROUTER_LSA) {
6331 json_object_int_add(json, "flags", rlsa->flags);
6332
6333 if (rlsa->flags) {
6334 if (IS_ROUTER_LSA_BORDER(rlsa))
6335 json_object_boolean_true_add(json,
6336 "abr");
6337 if (IS_ROUTER_LSA_EXTERNAL(rlsa))
6338 json_object_boolean_true_add(json,
6339 "asbr");
6340 if (IS_ROUTER_LSA_VIRTUAL(rlsa))
6341 json_object_boolean_true_add(
6342 json, "vlEndpoint");
6343 if (IS_ROUTER_LSA_SHORTCUT(rlsa))
6344 json_object_boolean_true_add(
6345 json, "shortcut");
6346 }
6347 }
6348
6349 json_object_string_add(
6350 json, "lsaType",
6351 lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL));
6352 json_object_string_addf(json, "linkStateId", "%pI4",
6353 &lsa->data->id);
6354 json_object_string_addf(json, "advertisingRouter", "%pI4",
6355 &lsa->data->adv_router);
6356 json_object_string_add(json, "lsaSeqNumber", seqnum);
6357 json_object_string_add(json, "checksum", checksum);
6358 json_object_int_add(json, "length", ntohs(lsa->data->length));
6359 }
6360 }
6361
6362 static const char *const link_type_desc[] = {
6363 "(null)",
6364 "another Router (point-to-point)",
6365 "a Transit Network",
6366 "Stub Network",
6367 "a Virtual Link",
6368 };
6369
6370 static const char *const link_id_desc[] = {
6371 "(null)", "Neighboring Router ID", "Designated Router address",
6372 "Net", "Neighboring Router ID",
6373 };
6374
6375 static const char *const link_data_desc[] = {
6376 "(null)", "Router Interface address", "Router Interface address",
6377 "Network Mask", "Router Interface address",
6378 };
6379
6380 static const char *const link_id_desc_json[] = {
6381 "null", "neighborRouterId", "designatedRouterAddress",
6382 "networkAddress", "neighborRouterId",
6383 };
6384
6385 static const char *const link_data_desc_json[] = {
6386 "null", "routerInterfaceAddress", "routerInterfaceAddress",
6387 "networkMask", "routerInterfaceAddress",
6388 };
6389
6390 /* Show router-LSA each Link information. */
6391 static void show_ip_ospf_database_router_links(struct vty *vty,
6392 struct router_lsa *rl,
6393 json_object *json)
6394 {
6395 int len, type;
6396 unsigned short i;
6397 json_object *json_links = NULL;
6398 json_object *json_link = NULL;
6399 int metric = 0;
6400 char buf[PREFIX_STRLEN];
6401
6402 if (json)
6403 json_links = json_object_new_object();
6404
6405 len = ntohs(rl->header.length) - 4;
6406 for (i = 0; i < ntohs(rl->links) && len > 0; len -= 12, i++) {
6407 type = rl->link[i].type;
6408
6409 if (json) {
6410 char link[16];
6411
6412 snprintf(link, sizeof(link), "link%u", i);
6413 json_link = json_object_new_object();
6414 json_object_string_add(json_link, "linkType",
6415 link_type_desc[type]);
6416 json_object_string_add(json_link,
6417 link_id_desc_json[type],
6418 inet_ntop(AF_INET,
6419 &rl->link[i].link_id,
6420 buf, sizeof(buf)));
6421 json_object_string_add(
6422 json_link, link_data_desc_json[type],
6423 inet_ntop(AF_INET, &rl->link[i].link_data,
6424 buf, sizeof(buf)));
6425 json_object_int_add(json_link, "numOfTosMetrics",
6426 metric);
6427 json_object_int_add(json_link, "tos0Metric",
6428 ntohs(rl->link[i].metric));
6429 json_object_object_add(json_links, link, json_link);
6430 } else {
6431 vty_out(vty, " Link connected to: %s\n",
6432 link_type_desc[type]);
6433 vty_out(vty, " (Link ID) %s: %pI4\n",
6434 link_id_desc[type],
6435 &rl->link[i].link_id);
6436 vty_out(vty, " (Link Data) %s: %pI4\n",
6437 link_data_desc[type],
6438 &rl->link[i].link_data);
6439 vty_out(vty, " Number of TOS metrics: 0\n");
6440 vty_out(vty, " TOS 0 Metric: %d\n",
6441 ntohs(rl->link[i].metric));
6442 vty_out(vty, "\n");
6443 }
6444 }
6445 if (json)
6446 json_object_object_add(json, "routerLinks", json_links);
6447 }
6448
6449 /* Show router-LSA detail information. */
6450 static int show_router_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
6451 json_object *json)
6452 {
6453 if (lsa != NULL) {
6454 struct router_lsa *rl = (struct router_lsa *)lsa->data;
6455
6456 show_ip_ospf_database_header(vty, lsa, json);
6457
6458 if (!json)
6459 vty_out(vty, " Number of Links: %d\n\n",
6460 ntohs(rl->links));
6461 else
6462 json_object_int_add(json, "numOfLinks",
6463 ntohs(rl->links));
6464
6465 show_ip_ospf_database_router_links(vty, rl, json);
6466
6467 if (!json)
6468 vty_out(vty, "\n");
6469 }
6470
6471 return 0;
6472 }
6473
6474 /* Show network-LSA detail information. */
6475 static int show_network_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
6476 json_object *json)
6477 {
6478 int length, i;
6479 char buf[PREFIX_STRLEN];
6480 json_object *json_attached_rt = NULL;
6481 json_object *json_router = NULL;
6482
6483 if (json)
6484 json_attached_rt = json_object_new_object();
6485
6486 if (lsa != NULL) {
6487 struct network_lsa *nl = (struct network_lsa *)lsa->data;
6488 struct in_addr *addr;
6489
6490 show_ip_ospf_database_header(vty, lsa, json);
6491
6492 if (!json)
6493 vty_out(vty, " Network Mask: /%d\n",
6494 ip_masklen(nl->mask));
6495 else
6496 json_object_int_add(json, "networkMask",
6497 ip_masklen(nl->mask));
6498
6499 length = lsa->size - OSPF_LSA_HEADER_SIZE - 4;
6500 addr = &nl->routers[0];
6501 for (i = 0; length > 0 && addr;
6502 length -= 4, addr = &nl->routers[++i])
6503 if (!json) {
6504 vty_out(vty, " Attached Router: %pI4\n",
6505 addr);
6506 vty_out(vty, "\n");
6507 } else {
6508 json_router = json_object_new_object();
6509 json_object_string_add(
6510 json_router, "attachedRouterId",
6511 inet_ntop(AF_INET, addr, buf,
6512 sizeof(buf)));
6513 json_object_object_add(json_attached_rt,
6514 inet_ntop(AF_INET, addr,
6515 buf,
6516 sizeof(buf)),
6517 json_router);
6518 }
6519 }
6520
6521 if (json)
6522 json_object_object_add(json, "attchedRouters",
6523 json_attached_rt);
6524
6525 return 0;
6526 }
6527
6528 /* Show summary-LSA detail information. */
6529 static int show_summary_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
6530 json_object *json)
6531 {
6532 if (lsa != NULL) {
6533 struct summary_lsa *sl = (struct summary_lsa *)lsa->data;
6534
6535 show_ip_ospf_database_header(vty, lsa, json);
6536
6537 if (!json) {
6538 vty_out(vty, " Network Mask: /%d\n",
6539 ip_masklen(sl->mask));
6540 vty_out(vty, " TOS: 0 Metric: %d\n",
6541 GET_METRIC(sl->metric));
6542 vty_out(vty, "\n");
6543 } else {
6544 json_object_int_add(json, "networkMask",
6545 ip_masklen(sl->mask));
6546 json_object_int_add(json, "tos0Metric",
6547 GET_METRIC(sl->metric));
6548 }
6549 }
6550
6551 return 0;
6552 }
6553
6554 /* Show summary-ASBR-LSA detail information. */
6555 static int show_summary_asbr_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
6556 json_object *json)
6557 {
6558 if (lsa != NULL) {
6559 struct summary_lsa *sl = (struct summary_lsa *)lsa->data;
6560
6561 show_ip_ospf_database_header(vty, lsa, json);
6562
6563 if (!json) {
6564 vty_out(vty, " Network Mask: /%d\n",
6565 ip_masklen(sl->mask));
6566 vty_out(vty, " TOS: 0 Metric: %d\n",
6567 GET_METRIC(sl->metric));
6568 vty_out(vty, "\n");
6569 } else {
6570 json_object_int_add(json, "networkMask",
6571 ip_masklen(sl->mask));
6572 json_object_int_add(json, "tos0Metric",
6573 GET_METRIC(sl->metric));
6574 }
6575 }
6576
6577 return 0;
6578 }
6579
6580 /* Show AS-external-LSA detail information. */
6581 static int show_as_external_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
6582 json_object *json)
6583 {
6584 int tos = 0;
6585
6586 if (lsa != NULL) {
6587 struct as_external_lsa *al =
6588 (struct as_external_lsa *)lsa->data;
6589
6590 show_ip_ospf_database_header(vty, lsa, json);
6591
6592 if (!json) {
6593 vty_out(vty, " Network Mask: /%d\n",
6594 ip_masklen(al->mask));
6595 vty_out(vty, " Metric Type: %s\n",
6596 IS_EXTERNAL_METRIC(al->e[0].tos)
6597 ? "2 (Larger than any link state path)"
6598 : "1");
6599 vty_out(vty, " TOS: 0\n");
6600 vty_out(vty, " Metric: %d\n",
6601 GET_METRIC(al->e[0].metric));
6602 vty_out(vty, " Forward Address: %pI4\n",
6603 &al->e[0].fwd_addr);
6604 vty_out(vty,
6605 " External Route Tag: %" ROUTE_TAG_PRI "\n\n",
6606 (route_tag_t)ntohl(al->e[0].route_tag));
6607 } else {
6608 json_object_int_add(json, "networkMask",
6609 ip_masklen(al->mask));
6610 json_object_string_add(
6611 json, "metricType",
6612 IS_EXTERNAL_METRIC(al->e[0].tos)
6613 ? "E2 (Larger than any link state path)"
6614 : "E1");
6615 json_object_int_add(json, "tos", tos);
6616 json_object_int_add(json, "metric",
6617 GET_METRIC(al->e[0].metric));
6618 json_object_string_addf(json, "forwardAddress", "%pI4",
6619 &(al->e[0].fwd_addr));
6620 json_object_int_add(
6621 json, "externalRouteTag",
6622 (route_tag_t)ntohl(al->e[0].route_tag));
6623 }
6624 }
6625
6626 return 0;
6627 }
6628
6629 /* Show AS-NSSA-LSA detail information. */
6630 static int show_as_nssa_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
6631 json_object *json)
6632 {
6633 int tos = 0;
6634
6635 if (lsa != NULL) {
6636 struct as_external_lsa *al =
6637 (struct as_external_lsa *)lsa->data;
6638
6639 show_ip_ospf_database_header(vty, lsa, json);
6640
6641 if (!json) {
6642 vty_out(vty, " Network Mask: /%d\n",
6643 ip_masklen(al->mask));
6644 vty_out(vty, " Metric Type: %s\n",
6645 IS_EXTERNAL_METRIC(al->e[0].tos)
6646 ? "2 (Larger than any link state path)"
6647 : "1");
6648 vty_out(vty, " TOS: 0\n");
6649 vty_out(vty, " Metric: %d\n",
6650 GET_METRIC(al->e[0].metric));
6651 vty_out(vty, " NSSA: Forward Address: %pI4\n",
6652 &al->e[0].fwd_addr);
6653 vty_out(vty,
6654 " External Route Tag: %" ROUTE_TAG_PRI
6655 "\n\n",
6656 (route_tag_t)ntohl(al->e[0].route_tag));
6657 } else {
6658 json_object_int_add(json, "networkMask",
6659 ip_masklen(al->mask));
6660 json_object_string_add(
6661 json, "metricType",
6662 IS_EXTERNAL_METRIC(al->e[0].tos)
6663 ? "E2 (Larger than any link state path)"
6664 : "E1");
6665 json_object_int_add(json, "tos", tos);
6666 json_object_int_add(json, "metric",
6667 GET_METRIC(al->e[0].metric));
6668 json_object_string_addf(json, "nssaForwardAddress",
6669 "%pI4", &al->e[0].fwd_addr);
6670 json_object_int_add(
6671 json, "externalRouteTag",
6672 (route_tag_t)ntohl(al->e[0].route_tag));
6673 }
6674 }
6675
6676 return 0;
6677 }
6678
6679 static int show_func_dummy(struct vty *vty, struct ospf_lsa *lsa,
6680 json_object *json)
6681 {
6682 return 0;
6683 }
6684
6685 static int show_opaque_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
6686 json_object *json)
6687 {
6688 if (lsa != NULL) {
6689 show_ip_ospf_database_header(vty, lsa, json);
6690 show_opaque_info_detail(vty, lsa, json);
6691 if (!json)
6692 vty_out(vty, "\n");
6693 }
6694 return 0;
6695 }
6696
6697 int (*show_function[])(struct vty *, struct ospf_lsa *, json_object *) = {
6698 NULL,
6699 show_router_lsa_detail,
6700 show_network_lsa_detail,
6701 show_summary_lsa_detail,
6702 show_summary_asbr_lsa_detail,
6703 show_as_external_lsa_detail,
6704 show_func_dummy,
6705 show_as_nssa_lsa_detail, /* almost same as external */
6706 NULL, /* type-8 */
6707 show_opaque_lsa_detail,
6708 show_opaque_lsa_detail,
6709 show_opaque_lsa_detail,
6710 };
6711
6712 static void show_lsa_prefix_set(struct vty *vty, struct prefix_ls *lp,
6713 struct in_addr *id, struct in_addr *adv_router)
6714 {
6715 memset(lp, 0, sizeof(struct prefix_ls));
6716 lp->family = AF_UNSPEC;
6717 if (id == NULL)
6718 lp->prefixlen = 0;
6719 else if (adv_router == NULL) {
6720 lp->prefixlen = IPV4_MAX_BITLEN;
6721 lp->id = *id;
6722 } else {
6723 lp->prefixlen = 64;
6724 lp->id = *id;
6725 lp->adv_router = *adv_router;
6726 }
6727 }
6728
6729 static void show_lsa_detail_proc(struct vty *vty, struct route_table *rt,
6730 struct in_addr *id, struct in_addr *adv_router,
6731 json_object *json)
6732 {
6733 struct prefix_ls lp;
6734 struct route_node *rn, *start;
6735 struct ospf_lsa *lsa;
6736 json_object *json_lsa = NULL;
6737
6738 show_lsa_prefix_set(vty, &lp, id, adv_router);
6739 start = route_node_get(rt, (struct prefix *)&lp);
6740 if (start) {
6741 route_lock_node(start);
6742 for (rn = start; rn; rn = route_next_until(rn, start))
6743 if ((lsa = rn->info)) {
6744 if (show_function[lsa->data->type] != NULL) {
6745 if (json) {
6746 json_lsa =
6747 json_object_new_object();
6748 json_object_array_add(json,
6749 json_lsa);
6750 }
6751
6752 show_function[lsa->data->type](
6753 vty, lsa, json_lsa);
6754 }
6755 }
6756 route_unlock_node(start);
6757 }
6758 }
6759
6760 /* Show detail LSA information
6761 -- if id is NULL then show all LSAs. */
6762 static void show_lsa_detail(struct vty *vty, struct ospf *ospf, int type,
6763 struct in_addr *id, struct in_addr *adv_router,
6764 json_object *json)
6765 {
6766 struct listnode *node;
6767 struct ospf_area *area;
6768 char buf[PREFIX_STRLEN];
6769 json_object *json_lsa_type = NULL;
6770 json_object *json_areas = NULL;
6771 json_object *json_lsa_array = NULL;
6772
6773 switch (type) {
6774 case OSPF_AS_EXTERNAL_LSA:
6775 case OSPF_OPAQUE_AS_LSA:
6776 if (!json)
6777 vty_out(vty, " %s \n\n",
6778 show_database_desc[type]);
6779 else
6780 json_lsa_array = json_object_new_array();
6781
6782 show_lsa_detail_proc(vty, AS_LSDB(ospf, type), id, adv_router,
6783 json_lsa_array);
6784 if (json)
6785 json_object_object_add(json,
6786 show_database_desc_json[type],
6787 json_lsa_array);
6788
6789 break;
6790 default:
6791 if (json)
6792 json_areas = json_object_new_object();
6793
6794 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
6795 if (!json) {
6796 vty_out(vty,
6797 "\n %s (Area %s)\n\n",
6798 show_database_desc[type],
6799 ospf_area_desc_string(area));
6800 } else {
6801 json_lsa_array = json_object_new_array();
6802 json_object_object_add(json_areas,
6803 inet_ntop(AF_INET,
6804 &area->area_id,
6805 buf,
6806 sizeof(buf)),
6807 json_lsa_array);
6808 }
6809
6810 show_lsa_detail_proc(vty, AREA_LSDB(area, type), id,
6811 adv_router, json_lsa_array);
6812 }
6813
6814 if (json) {
6815 json_lsa_type = json_object_new_object();
6816 json_object_object_add(json_lsa_type, "areas",
6817 json_areas);
6818 json_object_object_add(json,
6819 show_database_desc_json[type],
6820 json_lsa_type);
6821 }
6822 break;
6823 }
6824 }
6825
6826 static void show_lsa_detail_adv_router_proc(struct vty *vty,
6827 struct route_table *rt,
6828 struct in_addr *adv_router,
6829 json_object *json)
6830 {
6831 struct route_node *rn;
6832 struct ospf_lsa *lsa;
6833 json_object *json_lsa = NULL;
6834
6835 for (rn = route_top(rt); rn; rn = route_next(rn))
6836 if ((lsa = rn->info)) {
6837 if (IPV4_ADDR_SAME(adv_router,
6838 &lsa->data->adv_router)) {
6839 if (CHECK_FLAG(lsa->flags, OSPF_LSA_LOCAL_XLT))
6840 continue;
6841 if (json) {
6842 json_lsa = json_object_new_object();
6843 json_object_array_add(json, json_lsa);
6844 }
6845
6846 if (show_function[lsa->data->type] != NULL)
6847 show_function[lsa->data->type](
6848 vty, lsa, json_lsa);
6849 }
6850 }
6851 }
6852
6853 /* Show detail LSA information. */
6854 static void show_lsa_detail_adv_router(struct vty *vty, struct ospf *ospf,
6855 int type, struct in_addr *adv_router,
6856 json_object *json)
6857 {
6858 struct listnode *node;
6859 struct ospf_area *area;
6860 char buf[PREFIX_STRLEN];
6861 json_object *json_lsa_type = NULL;
6862 json_object *json_areas = NULL;
6863 json_object *json_lsa_array = NULL;
6864
6865 if (json)
6866 json_lsa_type = json_object_new_object();
6867
6868 switch (type) {
6869 case OSPF_AS_EXTERNAL_LSA:
6870 case OSPF_OPAQUE_AS_LSA:
6871 if (!json)
6872 vty_out(vty, " %s \n\n",
6873 show_database_desc[type]);
6874 else
6875 json_lsa_array = json_object_new_array();
6876
6877 show_lsa_detail_adv_router_proc(vty, AS_LSDB(ospf, type),
6878 adv_router, json_lsa_array);
6879 if (json)
6880 json_object_object_add(json,
6881 show_database_desc_json[type],
6882 json_lsa_array);
6883 break;
6884 default:
6885 if (json)
6886 json_areas = json_object_new_object();
6887
6888 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
6889 if (!json) {
6890 vty_out(vty,
6891 "\n %s (Area %s)\n\n",
6892 show_database_desc[type],
6893 ospf_area_desc_string(area));
6894 } else {
6895 json_lsa_array = json_object_new_array();
6896 json_object_object_add(
6897 json_areas,
6898 inet_ntop(AF_INET, &area->area_id, buf,
6899 sizeof(buf)),
6900 json_lsa_array);
6901 }
6902
6903 show_lsa_detail_adv_router_proc(
6904 vty, AREA_LSDB(area, type), adv_router,
6905 json_lsa_array);
6906 }
6907
6908 if (json) {
6909 json_object_object_add(json_lsa_type, "areas",
6910 json_areas);
6911 json_object_object_add(json,
6912 show_database_desc_json[type],
6913 json_lsa_type);
6914 }
6915 break;
6916 }
6917 }
6918
6919 void show_ip_ospf_database_summary(struct vty *vty, struct ospf *ospf, int self,
6920 json_object *json)
6921 {
6922 struct ospf_lsa *lsa;
6923 struct route_node *rn;
6924 struct ospf_area *area;
6925 struct listnode *node;
6926 char buf[PREFIX_STRLEN];
6927 json_object *json_areas = NULL;
6928 json_object *json_area = NULL;
6929 json_object *json_lsa = NULL;
6930 int type;
6931 json_object *json_lsa_array = NULL;
6932 uint32_t count;
6933
6934 if (json)
6935 json_areas = json_object_new_object();
6936
6937 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
6938 if (json)
6939 json_area = json_object_new_object();
6940
6941 for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) {
6942 count = 0;
6943 switch (type) {
6944 case OSPF_AS_EXTERNAL_LSA:
6945 case OSPF_OPAQUE_AS_LSA:
6946 continue;
6947 default:
6948 break;
6949 }
6950 if (ospf_lsdb_count_self(area->lsdb, type) > 0
6951 || (!self
6952 && ospf_lsdb_count(area->lsdb, type) > 0)) {
6953
6954 if (!json) {
6955 vty_out(vty,
6956 " %s (Area %s)\n\n",
6957 show_database_desc[type],
6958 ospf_area_desc_string(area));
6959 vty_out(vty, "%s\n",
6960 show_database_header[type]);
6961 } else {
6962 json_lsa_array =
6963 json_object_new_array();
6964 json_object_object_add(
6965 json_area,
6966 show_database_desc_json[type],
6967 json_lsa_array);
6968 }
6969
6970 LSDB_LOOP (AREA_LSDB(area, type), rn, lsa) {
6971 if (json) {
6972 json_lsa =
6973 json_object_new_object();
6974 json_object_array_add(
6975 json_lsa_array,
6976 json_lsa);
6977 }
6978
6979 count += show_lsa_summary(
6980 vty, lsa, self, json_lsa);
6981 }
6982
6983 if (!json)
6984 vty_out(vty, "\n");
6985 else
6986 json_object_int_add(
6987 json_area,
6988
6989 show_database_desc_count_json
6990 [type],
6991 count);
6992 }
6993 }
6994 if (json)
6995 json_object_object_add(json_areas,
6996 inet_ntop(AF_INET,
6997 &area->area_id,
6998 buf, sizeof(buf)),
6999 json_area);
7000 }
7001
7002 if (json)
7003 json_object_object_add(json, "areas", json_areas);
7004
7005 for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) {
7006 count = 0;
7007 switch (type) {
7008 case OSPF_AS_EXTERNAL_LSA:
7009 case OSPF_OPAQUE_AS_LSA:
7010 break;
7011 default:
7012 continue;
7013 }
7014 if (ospf_lsdb_count_self(ospf->lsdb, type)
7015 || (!self && ospf_lsdb_count(ospf->lsdb, type))) {
7016 if (!json) {
7017 vty_out(vty, " %s\n\n",
7018 show_database_desc[type]);
7019 vty_out(vty, "%s\n",
7020 show_database_header[type]);
7021 } else {
7022 json_lsa_array = json_object_new_array();
7023 json_object_object_add(
7024 json, show_database_desc_json[type],
7025 json_lsa_array);
7026 }
7027
7028 LSDB_LOOP (AS_LSDB(ospf, type), rn, lsa) {
7029 if (json) {
7030 json_lsa = json_object_new_object();
7031 json_object_array_add(json_lsa_array,
7032 json_lsa);
7033 }
7034
7035 count += show_lsa_summary(vty, lsa, self,
7036 json_lsa);
7037 }
7038
7039 if (!json)
7040 vty_out(vty, "\n");
7041 else
7042 json_object_int_add(
7043 json,
7044 show_database_desc_count_json[type],
7045 count);
7046 }
7047 }
7048
7049 if (!json)
7050 vty_out(vty, "\n");
7051 }
7052
7053 static void show_ip_ospf_database_maxage(struct vty *vty, struct ospf *ospf,
7054 json_object *json)
7055 {
7056 struct route_node *rn;
7057 char buf[PREFIX_STRLEN];
7058 json_object *json_maxage = NULL;
7059
7060 if (!json)
7061 vty_out(vty, "\n MaxAge Link States:\n\n");
7062 else
7063 json_maxage = json_object_new_object();
7064
7065 for (rn = route_top(ospf->maxage_lsa); rn; rn = route_next(rn)) {
7066 struct ospf_lsa *lsa;
7067 json_object *json_lsa = NULL;
7068
7069 if ((lsa = rn->info) != NULL) {
7070 if (!json) {
7071 vty_out(vty, "Link type: %d\n",
7072 lsa->data->type);
7073 vty_out(vty, "Link State ID: %pI4\n",
7074 &lsa->data->id);
7075 vty_out(vty, "Advertising Router: %pI4\n",
7076 &lsa->data->adv_router);
7077 vty_out(vty, "LSA lock count: %d\n", lsa->lock);
7078 vty_out(vty, "\n");
7079 } else {
7080 json_lsa = json_object_new_object();
7081 json_object_int_add(json_lsa, "linkType",
7082 lsa->data->type);
7083 json_object_string_addf(json_lsa, "linkStateId",
7084 "%pI4", &lsa->data->id);
7085 json_object_string_addf(
7086 json_lsa, "advertisingRouter", "%pI4",
7087 &lsa->data->adv_router);
7088 json_object_int_add(json_lsa, "lsaLockCount",
7089 lsa->lock);
7090 json_object_object_add(
7091 json_maxage,
7092 inet_ntop(AF_INET,
7093 &lsa->data->id,
7094 buf, sizeof(buf)),
7095 json_lsa);
7096 }
7097 }
7098 }
7099 if (json)
7100 json_object_object_add(json, "maxAgeLinkStates", json_maxage);
7101 }
7102
7103 #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
7104 #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
7105
7106 #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
7107 #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
7108 #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
7109 #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
7110
7111 #define OSPF_LSA_TYPES_DESC \
7112 "ASBR summary link states\n" \
7113 "External link states\n" \
7114 "Network link states\n" \
7115 "Router link states\n" \
7116 "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \
7117 OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
7118 OSPF_LSA_TYPE_OPAQUE_AS_DESC
7119
7120 static int
7121 show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf, bool maxage,
7122 bool self, bool detail, const char *type_name,
7123 struct in_addr *lsid, struct in_addr *adv_router,
7124 bool use_vrf, json_object *json, bool uj)
7125 {
7126 int type;
7127 json_object *json_vrf = NULL;
7128
7129 if (uj) {
7130 if (use_vrf)
7131 json_vrf = json_object_new_object();
7132 else
7133 json_vrf = json;
7134 }
7135
7136 if (ospf->instance) {
7137 if (uj)
7138 json_object_int_add(json_vrf, "ospfInstance",
7139 ospf->instance);
7140 else
7141 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
7142 }
7143
7144 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
7145
7146 /* Show Router ID. */
7147 if (uj) {
7148 json_object_string_addf(json_vrf, "routerId", "%pI4",
7149 &ospf->router_id);
7150 } else {
7151 vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n",
7152 &ospf->router_id);
7153 }
7154
7155 /* Show MaxAge LSAs */
7156 if (maxage) {
7157 show_ip_ospf_database_maxage(vty, ospf, json_vrf);
7158 if (json) {
7159 if (use_vrf) {
7160 if (ospf->vrf_id == VRF_DEFAULT)
7161 json_object_object_add(json, "default",
7162 json_vrf);
7163 else
7164 json_object_object_add(json, ospf->name,
7165 json_vrf);
7166 }
7167 }
7168 return CMD_SUCCESS;
7169 }
7170
7171 /* Show all LSAs. */
7172 if (!type_name) {
7173 if (detail) {
7174 for (int i = OSPF_ROUTER_LSA; i <= OSPF_OPAQUE_AS_LSA;
7175 i++) {
7176 switch (i) {
7177 case OSPF_GROUP_MEMBER_LSA:
7178 case OSPF_EXTERNAL_ATTRIBUTES_LSA:
7179 /* ignore deprecated LSA types */
7180 continue;
7181 default:
7182 break;
7183 }
7184
7185 if (adv_router && !lsid)
7186 show_lsa_detail_adv_router(vty, ospf, i,
7187 adv_router,
7188 json_vrf);
7189 else
7190 show_lsa_detail(vty, ospf, i, lsid,
7191 adv_router, json_vrf);
7192 }
7193 } else
7194 show_ip_ospf_database_summary(vty, ospf, self,
7195 json_vrf);
7196
7197 if (json) {
7198 if (use_vrf) {
7199 if (ospf->vrf_id == VRF_DEFAULT)
7200 json_object_object_add(json, "default",
7201 json_vrf);
7202 else
7203 json_object_object_add(json, ospf->name,
7204 json_vrf);
7205 }
7206 }
7207 return CMD_SUCCESS;
7208 }
7209
7210 /* Set database type to show. */
7211 if (strncmp(type_name, "r", 1) == 0)
7212 type = OSPF_ROUTER_LSA;
7213 else if (strncmp(type_name, "ne", 2) == 0)
7214 type = OSPF_NETWORK_LSA;
7215 else if (strncmp(type_name, "ns", 2) == 0)
7216 type = OSPF_AS_NSSA_LSA;
7217 else if (strncmp(type_name, "su", 2) == 0)
7218 type = OSPF_SUMMARY_LSA;
7219 else if (strncmp(type_name, "a", 1) == 0)
7220 type = OSPF_ASBR_SUMMARY_LSA;
7221 else if (strncmp(type_name, "e", 1) == 0)
7222 type = OSPF_AS_EXTERNAL_LSA;
7223 else if (strncmp(type_name, "opaque-l", 8) == 0)
7224 type = OSPF_OPAQUE_LINK_LSA;
7225 else if (strncmp(type_name, "opaque-ar", 9) == 0)
7226 type = OSPF_OPAQUE_AREA_LSA;
7227 else if (strncmp(type_name, "opaque-as", 9) == 0)
7228 type = OSPF_OPAQUE_AS_LSA;
7229 else {
7230 if (uj) {
7231 if (use_vrf)
7232 json_object_free(json_vrf);
7233 }
7234 return CMD_WARNING;
7235 }
7236
7237 if (adv_router && !lsid)
7238 show_lsa_detail_adv_router(vty, ospf, type, adv_router,
7239 json_vrf);
7240 else
7241 show_lsa_detail(vty, ospf, type, lsid, adv_router, json_vrf);
7242
7243 if (json) {
7244 if (use_vrf) {
7245 if (ospf->vrf_id == VRF_DEFAULT)
7246 json_object_object_add(json, "default",
7247 json_vrf);
7248 else
7249 json_object_object_add(json, ospf->name,
7250 json_vrf);
7251 }
7252 }
7253
7254 return CMD_SUCCESS;
7255 }
7256
7257 DEFPY (show_ip_ospf_database,
7258 show_ip_ospf_database_cmd,
7259 "show ip ospf [(1-65535)$instance_id] [vrf <NAME|all>$vrf_name] database\
7260 [<\
7261 max-age$maxage\
7262 |self-originate$selforig\
7263 |<\
7264 detail$detail\
7265 |<asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as>$type_name\
7266 >\
7267 [{\
7268 A.B.C.D$lsid\
7269 |<adv-router A.B.C.D$adv_router|self-originate$adv_router_self>\
7270 }]\
7271 >]\
7272 [json]",
7273 SHOW_STR
7274 IP_STR
7275 "OSPF information\n"
7276 "Instance ID\n"
7277 VRF_CMD_HELP_STR
7278 "All VRFs\n"
7279 "Database summary\n"
7280 "LSAs in MaxAge list\n"
7281 "Self-originated link states\n"
7282 "Show detailed information\n"
7283 OSPF_LSA_TYPES_DESC
7284 "Link State ID (as an IP address)\n"
7285 "Advertising Router link states\n"
7286 "Advertising Router (as an IP address)\n"
7287 "Self-originated link states\n"
7288 JSON_STR)
7289 {
7290 struct ospf *ospf;
7291 int ret = CMD_SUCCESS;
7292 bool use_vrf = !!vrf_name;
7293 bool uj = use_json(argc, argv);
7294 struct in_addr *lsid_p = NULL;
7295 struct in_addr *adv_router_p = NULL;
7296 json_object *json = NULL;
7297
7298 if (uj)
7299 json = json_object_new_object();
7300 if (lsid_str)
7301 lsid_p = &lsid;
7302 if (adv_router_str)
7303 adv_router_p = &adv_router;
7304
7305 if (vrf_name && strmatch(vrf_name, "all")) {
7306 struct listnode *node;
7307 bool ospf_output = false;
7308
7309 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
7310 if (!ospf->oi_running)
7311 continue;
7312 if (ospf->instance != instance_id)
7313 continue;
7314
7315 if (adv_router_self)
7316 adv_router_p = &ospf->router_id;
7317
7318 ospf_output = true;
7319 ret = show_ip_ospf_database_common(
7320 vty, ospf, !!maxage, !!selforig, !!detail,
7321 type_name, lsid_p, adv_router_p, use_vrf, json,
7322 uj);
7323 }
7324
7325 if (!ospf_output && !uj)
7326 vty_out(vty, "%% OSPF is not enabled\n");
7327 } else {
7328 if (!vrf_name)
7329 vrf_name = VRF_DEFAULT_NAME;
7330 ospf = ospf_lookup_by_inst_name(instance_id, vrf_name);
7331 if (ospf == NULL || !ospf->oi_running) {
7332 if (uj)
7333 vty_json(vty, json);
7334 else
7335 vty_out(vty, "%% OSPF instance not found\n");
7336 return CMD_SUCCESS;
7337 }
7338 if (adv_router_self)
7339 adv_router_p = &ospf->router_id;
7340
7341 ret = (show_ip_ospf_database_common(
7342 vty, ospf, !!maxage, !!selforig, !!detail, type_name,
7343 lsid_p, adv_router_p, use_vrf, json, uj));
7344 }
7345
7346 if (uj)
7347 vty_json(vty, json);
7348
7349 return ret;
7350 }
7351
7352 DEFUN (ip_ospf_authentication_args,
7353 ip_ospf_authentication_args_addr_cmd,
7354 "ip ospf authentication <null|message-digest> [A.B.C.D]",
7355 "IP Information\n"
7356 "OSPF interface commands\n"
7357 "Enable authentication on this interface\n"
7358 "Use null authentication\n"
7359 "Use message-digest authentication\n"
7360 "Address of interface\n")
7361 {
7362 VTY_DECLVAR_CONTEXT(interface, ifp);
7363 int idx_encryption = 3;
7364 int idx_ipv4 = 4;
7365 struct in_addr addr;
7366 int ret;
7367 struct ospf_if_params *params;
7368
7369 params = IF_DEF_PARAMS(ifp);
7370
7371 if (argc == 5) {
7372 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7373 if (!ret) {
7374 vty_out(vty,
7375 "Please specify interface address by A.B.C.D\n");
7376 return CMD_WARNING_CONFIG_FAILED;
7377 }
7378
7379 params = ospf_get_if_params(ifp, addr);
7380 ospf_if_update_params(ifp, addr);
7381 }
7382
7383 /* Handle null authentication */
7384 if (argv[idx_encryption]->arg[0] == 'n') {
7385 SET_IF_PARAM(params, auth_type);
7386 params->auth_type = OSPF_AUTH_NULL;
7387 return CMD_SUCCESS;
7388 }
7389
7390 /* Handle message-digest authentication */
7391 if (argv[idx_encryption]->arg[0] == 'm') {
7392 SET_IF_PARAM(params, auth_type);
7393 params->auth_type = OSPF_AUTH_CRYPTOGRAPHIC;
7394 return CMD_SUCCESS;
7395 }
7396
7397 vty_out(vty, "You shouldn't get here!\n");
7398 return CMD_WARNING_CONFIG_FAILED;
7399 }
7400
7401 DEFUN (ip_ospf_authentication,
7402 ip_ospf_authentication_addr_cmd,
7403 "ip ospf authentication [A.B.C.D]",
7404 "IP Information\n"
7405 "OSPF interface commands\n"
7406 "Enable authentication on this interface\n"
7407 "Address of interface\n")
7408 {
7409 VTY_DECLVAR_CONTEXT(interface, ifp);
7410 int idx_ipv4 = 3;
7411 struct in_addr addr;
7412 int ret;
7413 struct ospf_if_params *params;
7414
7415 params = IF_DEF_PARAMS(ifp);
7416
7417 if (argc == 4) {
7418 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7419 if (!ret) {
7420 vty_out(vty,
7421 "Please specify interface address by A.B.C.D\n");
7422 return CMD_WARNING_CONFIG_FAILED;
7423 }
7424
7425 params = ospf_get_if_params(ifp, addr);
7426 ospf_if_update_params(ifp, addr);
7427 }
7428
7429 SET_IF_PARAM(params, auth_type);
7430 params->auth_type = OSPF_AUTH_SIMPLE;
7431
7432 return CMD_SUCCESS;
7433 }
7434
7435 DEFUN (no_ip_ospf_authentication_args,
7436 no_ip_ospf_authentication_args_addr_cmd,
7437 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
7438 NO_STR
7439 "IP Information\n"
7440 "OSPF interface commands\n"
7441 "Enable authentication on this interface\n"
7442 "Use null authentication\n"
7443 "Use message-digest authentication\n"
7444 "Address of interface\n")
7445 {
7446 VTY_DECLVAR_CONTEXT(interface, ifp);
7447 int idx_encryption = 4;
7448 int idx_ipv4 = 5;
7449 struct in_addr addr;
7450 int ret;
7451 struct ospf_if_params *params;
7452 struct route_node *rn;
7453 int auth_type;
7454
7455 params = IF_DEF_PARAMS(ifp);
7456
7457 if (argc == 6) {
7458 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7459 if (!ret) {
7460 vty_out(vty,
7461 "Please specify interface address by A.B.C.D\n");
7462 return CMD_WARNING_CONFIG_FAILED;
7463 }
7464
7465 params = ospf_lookup_if_params(ifp, addr);
7466 if (params == NULL) {
7467 vty_out(vty, "Ip Address specified is unknown\n");
7468 return CMD_WARNING_CONFIG_FAILED;
7469 }
7470 params->auth_type = OSPF_AUTH_NOTSET;
7471 UNSET_IF_PARAM(params, auth_type);
7472 if (params != IF_DEF_PARAMS(ifp)) {
7473 ospf_free_if_params(ifp, addr);
7474 ospf_if_update_params(ifp, addr);
7475 }
7476 } else {
7477 if (argv[idx_encryption]->arg[0] == 'n') {
7478 auth_type = OSPF_AUTH_NULL;
7479 } else if (argv[idx_encryption]->arg[0] == 'm') {
7480 auth_type = OSPF_AUTH_CRYPTOGRAPHIC;
7481 } else {
7482 vty_out(vty, "Unexpected input encountered\n");
7483 return CMD_WARNING_CONFIG_FAILED;
7484 }
7485 /*
7486 * Here we have a case where the user has entered
7487 * 'no ip ospf authentication (null | message_digest )'
7488 * we need to find if we have any ip addresses underneath it
7489 * that
7490 * correspond to the associated type.
7491 */
7492 if (params->auth_type == auth_type) {
7493 params->auth_type = OSPF_AUTH_NOTSET;
7494 UNSET_IF_PARAM(params, auth_type);
7495 }
7496
7497 for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn;
7498 rn = route_next(rn)) {
7499 if ((params = rn->info)) {
7500 if (params->auth_type == auth_type) {
7501 params->auth_type = OSPF_AUTH_NOTSET;
7502 UNSET_IF_PARAM(params, auth_type);
7503 if (params != IF_DEF_PARAMS(ifp)) {
7504 ospf_free_if_params(
7505 ifp, rn->p.u.prefix4);
7506 ospf_if_update_params(
7507 ifp, rn->p.u.prefix4);
7508 }
7509 }
7510 }
7511 }
7512 }
7513
7514 return CMD_SUCCESS;
7515 }
7516
7517 DEFUN (no_ip_ospf_authentication,
7518 no_ip_ospf_authentication_addr_cmd,
7519 "no ip ospf authentication [A.B.C.D]",
7520 NO_STR
7521 "IP Information\n"
7522 "OSPF interface commands\n"
7523 "Enable authentication on this interface\n"
7524 "Address of interface\n")
7525 {
7526 VTY_DECLVAR_CONTEXT(interface, ifp);
7527 int idx_ipv4 = 4;
7528 struct in_addr addr;
7529 int ret;
7530 struct ospf_if_params *params;
7531 struct route_node *rn;
7532
7533 params = IF_DEF_PARAMS(ifp);
7534
7535 if (argc == 5) {
7536 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7537 if (!ret) {
7538 vty_out(vty,
7539 "Please specify interface address by A.B.C.D\n");
7540 return CMD_WARNING_CONFIG_FAILED;
7541 }
7542
7543 params = ospf_lookup_if_params(ifp, addr);
7544 if (params == NULL) {
7545 vty_out(vty, "Ip Address specified is unknown\n");
7546 return CMD_WARNING_CONFIG_FAILED;
7547 }
7548
7549 params->auth_type = OSPF_AUTH_NOTSET;
7550 UNSET_IF_PARAM(params, auth_type);
7551 if (params != IF_DEF_PARAMS(ifp)) {
7552 ospf_free_if_params(ifp, addr);
7553 ospf_if_update_params(ifp, addr);
7554 }
7555 } else {
7556 /*
7557 * When a user enters 'no ip ospf authentication'
7558 * We should remove all authentication types from
7559 * the interface.
7560 */
7561 if ((params->auth_type == OSPF_AUTH_NULL)
7562 || (params->auth_type == OSPF_AUTH_CRYPTOGRAPHIC)
7563 || (params->auth_type == OSPF_AUTH_SIMPLE)) {
7564 params->auth_type = OSPF_AUTH_NOTSET;
7565 UNSET_IF_PARAM(params, auth_type);
7566 }
7567
7568 for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn;
7569 rn = route_next(rn)) {
7570 if ((params = rn->info)) {
7571
7572 if ((params->auth_type == OSPF_AUTH_NULL)
7573 || (params->auth_type
7574 == OSPF_AUTH_CRYPTOGRAPHIC)
7575 || (params->auth_type
7576 == OSPF_AUTH_SIMPLE)) {
7577 params->auth_type = OSPF_AUTH_NOTSET;
7578 UNSET_IF_PARAM(params, auth_type);
7579 if (params != IF_DEF_PARAMS(ifp)) {
7580 ospf_free_if_params(
7581 ifp, rn->p.u.prefix4);
7582 ospf_if_update_params(
7583 ifp, rn->p.u.prefix4);
7584 }
7585 }
7586 }
7587 }
7588 }
7589
7590 return CMD_SUCCESS;
7591 }
7592
7593
7594 DEFUN (ip_ospf_authentication_key,
7595 ip_ospf_authentication_key_addr_cmd,
7596 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
7597 "IP Information\n"
7598 "OSPF interface commands\n"
7599 "Authentication password (key)\n"
7600 "The OSPF password (key)\n"
7601 "Address of interface\n")
7602 {
7603 VTY_DECLVAR_CONTEXT(interface, ifp);
7604 int idx = 0;
7605 struct in_addr addr;
7606 struct ospf_if_params *params;
7607
7608 params = IF_DEF_PARAMS(ifp);
7609
7610 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7611 if (!inet_aton(argv[idx]->arg, &addr)) {
7612 vty_out(vty,
7613 "Please specify interface address by A.B.C.D\n");
7614 return CMD_WARNING_CONFIG_FAILED;
7615 }
7616
7617 params = ospf_get_if_params(ifp, addr);
7618 ospf_if_update_params(ifp, addr);
7619 }
7620
7621 strlcpy((char *)params->auth_simple, argv[3]->arg,
7622 sizeof(params->auth_simple));
7623 SET_IF_PARAM(params, auth_simple);
7624
7625 return CMD_SUCCESS;
7626 }
7627
7628 DEFUN_HIDDEN (ospf_authentication_key,
7629 ospf_authentication_key_cmd,
7630 "ospf authentication-key AUTH_KEY [A.B.C.D]",
7631 "OSPF interface commands\n"
7632 VLINK_HELPSTR_AUTH_SIMPLE
7633 "Address of interface\n")
7634 {
7635 return ip_ospf_authentication_key(self, vty, argc, argv);
7636 }
7637
7638 DEFUN (no_ip_ospf_authentication_key,
7639 no_ip_ospf_authentication_key_authkey_addr_cmd,
7640 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7641 NO_STR
7642 "IP Information\n"
7643 "OSPF interface commands\n"
7644 VLINK_HELPSTR_AUTH_SIMPLE
7645 "Address of interface\n")
7646 {
7647 VTY_DECLVAR_CONTEXT(interface, ifp);
7648 int idx = 0;
7649 struct in_addr addr;
7650 struct ospf_if_params *params;
7651 params = IF_DEF_PARAMS(ifp);
7652
7653 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7654 if (!inet_aton(argv[idx]->arg, &addr)) {
7655 vty_out(vty,
7656 "Please specify interface address by A.B.C.D\n");
7657 return CMD_WARNING_CONFIG_FAILED;
7658 }
7659
7660 params = ospf_lookup_if_params(ifp, addr);
7661 if (params == NULL)
7662 return CMD_SUCCESS;
7663 }
7664
7665 memset(params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE);
7666 UNSET_IF_PARAM(params, auth_simple);
7667
7668 if (params != IF_DEF_PARAMS(ifp)) {
7669 ospf_free_if_params(ifp, addr);
7670 ospf_if_update_params(ifp, addr);
7671 }
7672
7673 return CMD_SUCCESS;
7674 }
7675
7676 DEFUN_HIDDEN (no_ospf_authentication_key,
7677 no_ospf_authentication_key_authkey_addr_cmd,
7678 "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7679 NO_STR
7680 "OSPF interface commands\n"
7681 VLINK_HELPSTR_AUTH_SIMPLE
7682 "Address of interface\n")
7683 {
7684 return no_ip_ospf_authentication_key(self, vty, argc, argv);
7685 }
7686
7687 DEFUN (ip_ospf_message_digest_key,
7688 ip_ospf_message_digest_key_cmd,
7689 "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7690 "IP Information\n"
7691 "OSPF interface commands\n"
7692 "Message digest authentication password (key)\n"
7693 "Key ID\n"
7694 "Use MD5 algorithm\n"
7695 "The OSPF password (key)\n"
7696 "Address of interface\n")
7697 {
7698 VTY_DECLVAR_CONTEXT(interface, ifp);
7699 struct crypt_key *ck;
7700 uint8_t key_id;
7701 struct in_addr addr;
7702 struct ospf_if_params *params;
7703
7704 params = IF_DEF_PARAMS(ifp);
7705 int idx = 0;
7706
7707 argv_find(argv, argc, "(1-255)", &idx);
7708 char *keyid = argv[idx]->arg;
7709 argv_find(argv, argc, "KEY", &idx);
7710 char *cryptkey = argv[idx]->arg;
7711
7712 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7713 if (!inet_aton(argv[idx]->arg, &addr)) {
7714 vty_out(vty,
7715 "Please specify interface address by A.B.C.D\n");
7716 return CMD_WARNING_CONFIG_FAILED;
7717 }
7718
7719 params = ospf_get_if_params(ifp, addr);
7720 ospf_if_update_params(ifp, addr);
7721 }
7722
7723 key_id = strtol(keyid, NULL, 10);
7724
7725 /* Remove existing key, if any */
7726 ospf_crypt_key_delete(params->auth_crypt, key_id);
7727
7728 ck = ospf_crypt_key_new();
7729 ck->key_id = (uint8_t)key_id;
7730 strlcpy((char *)ck->auth_key, cryptkey, sizeof(ck->auth_key));
7731
7732 ospf_crypt_key_add(params->auth_crypt, ck);
7733 SET_IF_PARAM(params, auth_crypt);
7734
7735 return CMD_SUCCESS;
7736 }
7737
7738 DEFUN_HIDDEN (ospf_message_digest_key,
7739 ospf_message_digest_key_cmd,
7740 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7741 "OSPF interface commands\n"
7742 "Message digest authentication password (key)\n"
7743 "Key ID\n"
7744 "Use MD5 algorithm\n"
7745 "The OSPF password (key)\n"
7746 "Address of interface\n")
7747 {
7748 return ip_ospf_message_digest_key(self, vty, argc, argv);
7749 }
7750
7751 DEFUN (no_ip_ospf_message_digest_key,
7752 no_ip_ospf_message_digest_key_cmd,
7753 "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7754 NO_STR
7755 "IP Information\n"
7756 "OSPF interface commands\n"
7757 "Message digest authentication password (key)\n"
7758 "Key ID\n"
7759 "Use MD5 algorithm\n"
7760 "The OSPF password (key)\n"
7761 "Address of interface\n")
7762 {
7763 VTY_DECLVAR_CONTEXT(interface, ifp);
7764 int idx = 0;
7765 struct crypt_key *ck;
7766 int key_id;
7767 struct in_addr addr;
7768 struct ospf_if_params *params;
7769 params = IF_DEF_PARAMS(ifp);
7770
7771 argv_find(argv, argc, "(1-255)", &idx);
7772 char *keyid = argv[idx]->arg;
7773
7774 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7775 if (!inet_aton(argv[idx]->arg, &addr)) {
7776 vty_out(vty,
7777 "Please specify interface address by A.B.C.D\n");
7778 return CMD_WARNING_CONFIG_FAILED;
7779 }
7780
7781 params = ospf_lookup_if_params(ifp, addr);
7782 if (params == NULL)
7783 return CMD_SUCCESS;
7784 }
7785
7786 key_id = strtol(keyid, NULL, 10);
7787 ck = ospf_crypt_key_lookup(params->auth_crypt, key_id);
7788 if (ck == NULL) {
7789 vty_out(vty, "OSPF: Key %d does not exist\n", key_id);
7790 return CMD_WARNING_CONFIG_FAILED;
7791 }
7792
7793 ospf_crypt_key_delete(params->auth_crypt, key_id);
7794
7795 if (params != IF_DEF_PARAMS(ifp)) {
7796 ospf_free_if_params(ifp, addr);
7797 ospf_if_update_params(ifp, addr);
7798 }
7799
7800 return CMD_SUCCESS;
7801 }
7802
7803 DEFUN_HIDDEN (no_ospf_message_digest_key,
7804 no_ospf_message_digest_key_cmd,
7805 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7806 NO_STR
7807 "OSPF interface commands\n"
7808 "Message digest authentication password (key)\n"
7809 "Key ID\n"
7810 "Use MD5 algorithm\n"
7811 "The OSPF password (key)\n"
7812 "Address of interface\n")
7813 {
7814 return no_ip_ospf_message_digest_key(self, vty, argc, argv);
7815 }
7816
7817 DEFUN (ip_ospf_cost,
7818 ip_ospf_cost_cmd,
7819 "ip ospf cost (1-65535) [A.B.C.D]",
7820 "IP Information\n"
7821 "OSPF interface commands\n"
7822 "Interface cost\n"
7823 "Cost\n"
7824 "Address of interface\n")
7825 {
7826 VTY_DECLVAR_CONTEXT(interface, ifp);
7827 int idx = 0;
7828 uint32_t cost = OSPF_OUTPUT_COST_DEFAULT;
7829 struct in_addr addr;
7830 struct ospf_if_params *params;
7831 params = IF_DEF_PARAMS(ifp);
7832
7833 // get arguments
7834 char *coststr = NULL, *ifaddr = NULL;
7835
7836 argv_find(argv, argc, "(1-65535)", &idx);
7837 coststr = argv[idx]->arg;
7838 cost = strtol(coststr, NULL, 10);
7839
7840 ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
7841 if (ifaddr) {
7842 if (!inet_aton(ifaddr, &addr)) {
7843 vty_out(vty,
7844 "Please specify interface address by A.B.C.D\n");
7845 return CMD_WARNING_CONFIG_FAILED;
7846 }
7847
7848 params = ospf_get_if_params(ifp, addr);
7849 ospf_if_update_params(ifp, addr);
7850 }
7851
7852 SET_IF_PARAM(params, output_cost_cmd);
7853 params->output_cost_cmd = cost;
7854
7855 ospf_if_recalculate_output_cost(ifp);
7856
7857 return CMD_SUCCESS;
7858 }
7859
7860 DEFUN_HIDDEN (ospf_cost,
7861 ospf_cost_cmd,
7862 "ospf cost (1-65535) [A.B.C.D]",
7863 "OSPF interface commands\n"
7864 "Interface cost\n"
7865 "Cost\n"
7866 "Address of interface\n")
7867 {
7868 return ip_ospf_cost(self, vty, argc, argv);
7869 }
7870
7871 DEFUN (no_ip_ospf_cost,
7872 no_ip_ospf_cost_cmd,
7873 "no ip ospf cost [(1-65535)] [A.B.C.D]",
7874 NO_STR
7875 "IP Information\n"
7876 "OSPF interface commands\n"
7877 "Interface cost\n"
7878 "Cost\n"
7879 "Address of interface\n")
7880 {
7881 VTY_DECLVAR_CONTEXT(interface, ifp);
7882 int idx = 0;
7883 struct in_addr addr;
7884 struct ospf_if_params *params;
7885
7886 params = IF_DEF_PARAMS(ifp);
7887
7888 // get arguments
7889 char *ifaddr = NULL;
7890 ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
7891
7892 /* According to the semantics we are mimicking "no ip ospf cost N" is
7893 * always treated as "no ip ospf cost" regardless of the actual value
7894 * of N already configured for the interface. Thus ignore cost. */
7895
7896 if (ifaddr) {
7897 if (!inet_aton(ifaddr, &addr)) {
7898 vty_out(vty,
7899 "Please specify interface address by A.B.C.D\n");
7900 return CMD_WARNING_CONFIG_FAILED;
7901 }
7902
7903 params = ospf_lookup_if_params(ifp, addr);
7904 if (params == NULL)
7905 return CMD_SUCCESS;
7906 }
7907
7908 UNSET_IF_PARAM(params, output_cost_cmd);
7909
7910 if (params != IF_DEF_PARAMS(ifp)) {
7911 ospf_free_if_params(ifp, addr);
7912 ospf_if_update_params(ifp, addr);
7913 }
7914
7915 ospf_if_recalculate_output_cost(ifp);
7916
7917 return CMD_SUCCESS;
7918 }
7919
7920 DEFUN_HIDDEN (no_ospf_cost,
7921 no_ospf_cost_cmd,
7922 "no ospf cost [(1-65535)] [A.B.C.D]",
7923 NO_STR
7924 "OSPF interface commands\n"
7925 "Interface cost\n"
7926 "Cost\n"
7927 "Address of interface\n")
7928 {
7929 return no_ip_ospf_cost(self, vty, argc, argv);
7930 }
7931
7932 static void ospf_nbr_timer_update(struct ospf_interface *oi)
7933 {
7934 struct route_node *rn;
7935 struct ospf_neighbor *nbr;
7936
7937 for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
7938 nbr = rn->info;
7939
7940 if (!nbr)
7941 continue;
7942
7943 nbr->v_inactivity = OSPF_IF_PARAM(oi, v_wait);
7944 nbr->v_db_desc = OSPF_IF_PARAM(oi, retransmit_interval);
7945 nbr->v_ls_req = OSPF_IF_PARAM(oi, retransmit_interval);
7946 nbr->v_ls_upd = OSPF_IF_PARAM(oi, retransmit_interval);
7947 }
7948 }
7949
7950 static int ospf_vty_dead_interval_set(struct vty *vty, const char *interval_str,
7951 const char *nbr_str,
7952 const char *fast_hello_str)
7953 {
7954 VTY_DECLVAR_CONTEXT(interface, ifp);
7955 uint32_t seconds;
7956 uint8_t hellomult;
7957 struct in_addr addr;
7958 int ret;
7959 struct ospf_if_params *params;
7960 struct ospf_interface *oi;
7961 struct route_node *rn;
7962
7963 params = IF_DEF_PARAMS(ifp);
7964
7965 if (nbr_str) {
7966 ret = inet_aton(nbr_str, &addr);
7967 if (!ret) {
7968 vty_out(vty,
7969 "Please specify interface address by A.B.C.D\n");
7970 return CMD_WARNING_CONFIG_FAILED;
7971 }
7972
7973 params = ospf_get_if_params(ifp, addr);
7974 ospf_if_update_params(ifp, addr);
7975 }
7976
7977 if (interval_str) {
7978 seconds = strtoul(interval_str, NULL, 10);
7979
7980 /* reset fast_hello too, just to be sure */
7981 UNSET_IF_PARAM(params, fast_hello);
7982 params->fast_hello = OSPF_FAST_HELLO_DEFAULT;
7983 } else if (fast_hello_str) {
7984 hellomult = strtoul(fast_hello_str, NULL, 10);
7985 /* 1s dead-interval with sub-second hellos desired */
7986 seconds = OSPF_ROUTER_DEAD_INTERVAL_MINIMAL;
7987 SET_IF_PARAM(params, fast_hello);
7988 params->fast_hello = hellomult;
7989 } else {
7990 vty_out(vty,
7991 "Please specify dead-interval or hello-multiplier\n");
7992 return CMD_WARNING_CONFIG_FAILED;
7993 }
7994
7995 SET_IF_PARAM(params, v_wait);
7996 params->v_wait = seconds;
7997 params->is_v_wait_set = true;
7998
7999 /* Update timer values in neighbor structure. */
8000 if (nbr_str) {
8001 struct ospf *ospf = NULL;
8002
8003 ospf = ifp->vrf->info;
8004 if (ospf) {
8005 oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr);
8006 if (oi)
8007 ospf_nbr_timer_update(oi);
8008 }
8009 } else {
8010 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn))
8011 if ((oi = rn->info))
8012 ospf_nbr_timer_update(oi);
8013 }
8014
8015 return CMD_SUCCESS;
8016 }
8017
8018 DEFUN (ip_ospf_dead_interval,
8019 ip_ospf_dead_interval_cmd,
8020 "ip ospf dead-interval (1-65535) [A.B.C.D]",
8021 "IP Information\n"
8022 "OSPF interface commands\n"
8023 "Interval time after which a neighbor is declared down\n"
8024 "Seconds\n"
8025 "Address of interface\n")
8026 {
8027 int idx = 0;
8028 char *interval = argv_find(argv, argc, "(1-65535)", &idx)
8029 ? argv[idx]->arg
8030 : NULL;
8031 char *ifaddr =
8032 argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
8033 return ospf_vty_dead_interval_set(vty, interval, ifaddr, NULL);
8034 }
8035
8036
8037 DEFUN_HIDDEN (ospf_dead_interval,
8038 ospf_dead_interval_cmd,
8039 "ospf dead-interval (1-65535) [A.B.C.D]",
8040 "OSPF interface commands\n"
8041 "Interval time after which a neighbor is declared down\n"
8042 "Seconds\n"
8043 "Address of interface\n")
8044 {
8045 return ip_ospf_dead_interval(self, vty, argc, argv);
8046 }
8047
8048 DEFUN (ip_ospf_dead_interval_minimal,
8049 ip_ospf_dead_interval_minimal_addr_cmd,
8050 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
8051 "IP Information\n"
8052 "OSPF interface commands\n"
8053 "Interval time after which a neighbor is declared down\n"
8054 "Minimal 1s dead-interval with fast sub-second hellos\n"
8055 "Hello multiplier factor\n"
8056 "Number of Hellos to send each second\n"
8057 "Address of interface\n")
8058 {
8059 int idx_number = 5;
8060 int idx_ipv4 = 6;
8061 if (argc == 7)
8062 return ospf_vty_dead_interval_set(
8063 vty, NULL, argv[idx_ipv4]->arg, argv[idx_number]->arg);
8064 else
8065 return ospf_vty_dead_interval_set(vty, NULL, NULL,
8066 argv[idx_number]->arg);
8067 }
8068
8069 DEFUN (no_ip_ospf_dead_interval,
8070 no_ip_ospf_dead_interval_cmd,
8071 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8072 NO_STR
8073 "IP Information\n"
8074 "OSPF interface commands\n"
8075 "Interval time after which a neighbor is declared down\n"
8076 "Seconds\n"
8077 "Minimal 1s dead-interval with fast sub-second hellos\n"
8078 "Hello multiplier factor\n"
8079 "Number of Hellos to send each second\n"
8080 "Address of interface\n")
8081 {
8082 VTY_DECLVAR_CONTEXT(interface, ifp);
8083 int idx_ipv4 = argc - 1;
8084 struct in_addr addr = {.s_addr = 0L};
8085 int ret;
8086 struct ospf_if_params *params;
8087 struct ospf_interface *oi;
8088 struct route_node *rn;
8089
8090 params = IF_DEF_PARAMS(ifp);
8091
8092 if (argv[idx_ipv4]->type == IPV4_TKN) {
8093 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
8094 if (!ret) {
8095 vty_out(vty,
8096 "Please specify interface address by A.B.C.D\n");
8097 return CMD_WARNING_CONFIG_FAILED;
8098 }
8099
8100 params = ospf_lookup_if_params(ifp, addr);
8101 if (params == NULL)
8102 return CMD_SUCCESS;
8103 }
8104
8105 UNSET_IF_PARAM(params, v_wait);
8106 params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
8107 params->is_v_wait_set = false;
8108
8109 UNSET_IF_PARAM(params, fast_hello);
8110 params->fast_hello = OSPF_FAST_HELLO_DEFAULT;
8111
8112 if (params != IF_DEF_PARAMS(ifp)) {
8113 ospf_free_if_params(ifp, addr);
8114 ospf_if_update_params(ifp, addr);
8115 }
8116
8117 /* Update timer values in neighbor structure. */
8118 if (argc == 1) {
8119 struct ospf *ospf = NULL;
8120
8121 ospf = ifp->vrf->info;
8122 if (ospf) {
8123 oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr);
8124 if (oi)
8125 ospf_nbr_timer_update(oi);
8126 }
8127 } else {
8128 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn))
8129 if ((oi = rn->info))
8130 ospf_nbr_timer_update(oi);
8131 }
8132
8133 return CMD_SUCCESS;
8134 }
8135
8136 DEFUN_HIDDEN (no_ospf_dead_interval,
8137 no_ospf_dead_interval_cmd,
8138 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8139 NO_STR
8140 "OSPF interface commands\n"
8141 "Interval time after which a neighbor is declared down\n"
8142 "Seconds\n"
8143 "Minimal 1s dead-interval with fast sub-second hellos\n"
8144 "Hello multiplier factor\n"
8145 "Number of Hellos to send each second\n"
8146 "Address of interface\n")
8147 {
8148 return no_ip_ospf_dead_interval(self, vty, argc, argv);
8149 }
8150
8151 DEFUN (ip_ospf_hello_interval,
8152 ip_ospf_hello_interval_cmd,
8153 "ip ospf hello-interval (1-65535) [A.B.C.D]",
8154 "IP Information\n"
8155 "OSPF interface commands\n"
8156 "Time between HELLO packets\n"
8157 "Seconds\n"
8158 "Address of interface\n")
8159 {
8160 VTY_DECLVAR_CONTEXT(interface, ifp);
8161 int idx = 0;
8162 struct in_addr addr = {.s_addr = 0L};
8163 struct ospf_if_params *params;
8164 params = IF_DEF_PARAMS(ifp);
8165 uint32_t seconds = 0;
8166 bool is_addr = false;
8167 uint32_t old_interval = 0;
8168
8169 argv_find(argv, argc, "(1-65535)", &idx);
8170 seconds = strtol(argv[idx]->arg, NULL, 10);
8171
8172 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8173 if (!inet_aton(argv[idx]->arg, &addr)) {
8174 vty_out(vty,
8175 "Please specify interface address by A.B.C.D\n");
8176 return CMD_WARNING_CONFIG_FAILED;
8177 }
8178
8179 params = ospf_get_if_params(ifp, addr);
8180 ospf_if_update_params(ifp, addr);
8181 is_addr = true;
8182 }
8183
8184 old_interval = params->v_hello;
8185
8186 /* Return, if same interval is configured. */
8187 if (old_interval == seconds)
8188 return CMD_SUCCESS;
8189
8190 SET_IF_PARAM(params, v_hello);
8191 params->v_hello = seconds;
8192
8193 if (!params->is_v_wait_set) {
8194 SET_IF_PARAM(params, v_wait);
8195 /* As per RFC 4062
8196 * The router dead interval should
8197 * be some multiple of the HelloInterval (perhaps 4 times the
8198 * hello interval) and must be the same for all routers
8199 * attached to a common network.
8200 */
8201 params->v_wait = 4 * seconds;
8202 }
8203
8204 ospf_reset_hello_timer(ifp, addr, is_addr);
8205
8206 return CMD_SUCCESS;
8207 }
8208
8209 DEFUN_HIDDEN (ospf_hello_interval,
8210 ospf_hello_interval_cmd,
8211 "ospf hello-interval (1-65535) [A.B.C.D]",
8212 "OSPF interface commands\n"
8213 "Time between HELLO packets\n"
8214 "Seconds\n"
8215 "Address of interface\n")
8216 {
8217 return ip_ospf_hello_interval(self, vty, argc, argv);
8218 }
8219
8220 DEFUN (no_ip_ospf_hello_interval,
8221 no_ip_ospf_hello_interval_cmd,
8222 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
8223 NO_STR
8224 "IP Information\n"
8225 "OSPF interface commands\n"
8226 "Time between HELLO packets\n" // ignored
8227 "Seconds\n"
8228 "Address of interface\n")
8229 {
8230 VTY_DECLVAR_CONTEXT(interface, ifp);
8231 int idx = 0;
8232 struct in_addr addr = {.s_addr = 0L};
8233 struct ospf_if_params *params;
8234 struct route_node *rn;
8235
8236 params = IF_DEF_PARAMS(ifp);
8237
8238 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8239 if (!inet_aton(argv[idx]->arg, &addr)) {
8240 vty_out(vty,
8241 "Please specify interface address by A.B.C.D\n");
8242 return CMD_WARNING_CONFIG_FAILED;
8243 }
8244
8245 params = ospf_lookup_if_params(ifp, addr);
8246 if (params == NULL)
8247 return CMD_SUCCESS;
8248 }
8249
8250 UNSET_IF_PARAM(params, v_hello);
8251 params->v_hello = OSPF_HELLO_INTERVAL_DEFAULT;
8252
8253 if (!params->is_v_wait_set) {
8254 UNSET_IF_PARAM(params, v_wait);
8255 params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
8256 }
8257
8258 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8259 struct ospf_interface *oi = rn->info;
8260
8261 if (!oi)
8262 continue;
8263
8264 oi->type = IF_DEF_PARAMS(ifp)->type;
8265 oi->ptp_dmvpn = IF_DEF_PARAMS(ifp)->ptp_dmvpn;
8266
8267 if (oi->state > ISM_Down) {
8268 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown);
8269 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp);
8270 }
8271 }
8272
8273 if (params != IF_DEF_PARAMS(ifp)) {
8274 ospf_free_if_params(ifp, addr);
8275 ospf_if_update_params(ifp, addr);
8276 }
8277
8278 return CMD_SUCCESS;
8279 }
8280
8281 DEFUN_HIDDEN (no_ospf_hello_interval,
8282 no_ospf_hello_interval_cmd,
8283 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
8284 NO_STR
8285 "OSPF interface commands\n"
8286 "Time between HELLO packets\n" // ignored
8287 "Seconds\n"
8288 "Address of interface\n")
8289 {
8290 return no_ip_ospf_hello_interval(self, vty, argc, argv);
8291 }
8292
8293 DEFUN(ip_ospf_network, ip_ospf_network_cmd,
8294 "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point [dmvpn]>",
8295 "IP Information\n"
8296 "OSPF interface commands\n"
8297 "Network type\n"
8298 "Specify OSPF broadcast multi-access network\n"
8299 "Specify OSPF NBMA network\n"
8300 "Specify OSPF point-to-multipoint network\n"
8301 "Specify OSPF point-to-point network\n"
8302 "Specify OSPF point-to-point DMVPN network\n")
8303 {
8304 VTY_DECLVAR_CONTEXT(interface, ifp);
8305 int idx = 0;
8306 int old_type = IF_DEF_PARAMS(ifp)->type;
8307 uint8_t old_ptp_dmvpn = IF_DEF_PARAMS(ifp)->ptp_dmvpn;
8308 struct route_node *rn;
8309
8310 if (old_type == OSPF_IFTYPE_LOOPBACK) {
8311 vty_out(vty,
8312 "This is a loopback interface. Can't set network type.\n");
8313 return CMD_WARNING_CONFIG_FAILED;
8314 }
8315
8316 IF_DEF_PARAMS(ifp)->ptp_dmvpn = 0;
8317
8318 if (argv_find(argv, argc, "broadcast", &idx))
8319 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_BROADCAST;
8320 else if (argv_find(argv, argc, "non-broadcast", &idx))
8321 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_NBMA;
8322 else if (argv_find(argv, argc, "point-to-multipoint", &idx))
8323 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOMULTIPOINT;
8324 else if (argv_find(argv, argc, "point-to-point", &idx)) {
8325 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOPOINT;
8326 if (argv_find(argv, argc, "dmvpn", &idx))
8327 IF_DEF_PARAMS(ifp)->ptp_dmvpn = 1;
8328 }
8329
8330 if (IF_DEF_PARAMS(ifp)->type == old_type
8331 && IF_DEF_PARAMS(ifp)->ptp_dmvpn == old_ptp_dmvpn)
8332 return CMD_SUCCESS;
8333
8334 SET_IF_PARAM(IF_DEF_PARAMS(ifp), type);
8335
8336 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8337 struct ospf_interface *oi = rn->info;
8338
8339 if (!oi)
8340 continue;
8341
8342 oi->type = IF_DEF_PARAMS(ifp)->type;
8343
8344 if (oi->state > ISM_Down) {
8345 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown);
8346 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp);
8347 }
8348 }
8349
8350 return CMD_SUCCESS;
8351 }
8352
8353 DEFUN_HIDDEN (ospf_network,
8354 ospf_network_cmd,
8355 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
8356 "OSPF interface commands\n"
8357 "Network type\n"
8358 "Specify OSPF broadcast multi-access network\n"
8359 "Specify OSPF NBMA network\n"
8360 "Specify OSPF point-to-multipoint network\n"
8361 "Specify OSPF point-to-point network\n")
8362 {
8363 return ip_ospf_network(self, vty, argc, argv);
8364 }
8365
8366 DEFUN (no_ip_ospf_network,
8367 no_ip_ospf_network_cmd,
8368 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8369 NO_STR
8370 "IP Information\n"
8371 "OSPF interface commands\n"
8372 "Network type\n"
8373 "Specify OSPF broadcast multi-access network\n"
8374 "Specify OSPF NBMA network\n"
8375 "Specify OSPF point-to-multipoint network\n"
8376 "Specify OSPF point-to-point network\n")
8377 {
8378 VTY_DECLVAR_CONTEXT(interface, ifp);
8379 int old_type = IF_DEF_PARAMS(ifp)->type;
8380 struct route_node *rn;
8381
8382 IF_DEF_PARAMS(ifp)->type = ospf_default_iftype(ifp);
8383 IF_DEF_PARAMS(ifp)->ptp_dmvpn = 0;
8384
8385 if (IF_DEF_PARAMS(ifp)->type == old_type)
8386 return CMD_SUCCESS;
8387
8388 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8389 struct ospf_interface *oi = rn->info;
8390
8391 if (!oi)
8392 continue;
8393
8394 oi->type = IF_DEF_PARAMS(ifp)->type;
8395
8396 if (oi->state > ISM_Down) {
8397 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown);
8398 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp);
8399 }
8400 }
8401
8402 return CMD_SUCCESS;
8403 }
8404
8405 DEFUN_HIDDEN (no_ospf_network,
8406 no_ospf_network_cmd,
8407 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8408 NO_STR
8409 "OSPF interface commands\n"
8410 "Network type\n"
8411 "Specify OSPF broadcast multi-access network\n"
8412 "Specify OSPF NBMA network\n"
8413 "Specify OSPF point-to-multipoint network\n"
8414 "Specify OSPF point-to-point network\n")
8415 {
8416 return no_ip_ospf_network(self, vty, argc, argv);
8417 }
8418
8419 DEFUN (ip_ospf_priority,
8420 ip_ospf_priority_cmd,
8421 "ip ospf priority (0-255) [A.B.C.D]",
8422 "IP Information\n"
8423 "OSPF interface commands\n"
8424 "Router priority\n"
8425 "Priority\n"
8426 "Address of interface\n")
8427 {
8428 VTY_DECLVAR_CONTEXT(interface, ifp);
8429 int idx = 0;
8430 long priority;
8431 struct route_node *rn;
8432 struct in_addr addr;
8433 struct ospf_if_params *params;
8434 params = IF_DEF_PARAMS(ifp);
8435
8436 argv_find(argv, argc, "(0-255)", &idx);
8437 priority = strtol(argv[idx]->arg, NULL, 10);
8438
8439 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8440 if (!inet_aton(argv[idx]->arg, &addr)) {
8441 vty_out(vty,
8442 "Please specify interface address by A.B.C.D\n");
8443 return CMD_WARNING_CONFIG_FAILED;
8444 }
8445
8446 params = ospf_get_if_params(ifp, addr);
8447 ospf_if_update_params(ifp, addr);
8448 }
8449
8450 SET_IF_PARAM(params, priority);
8451 params->priority = priority;
8452
8453 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8454 struct ospf_interface *oi = rn->info;
8455
8456 if (!oi)
8457 continue;
8458
8459 if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) {
8460 PRIORITY(oi) = OSPF_IF_PARAM(oi, priority);
8461 OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange);
8462 }
8463 }
8464
8465 return CMD_SUCCESS;
8466 }
8467
8468 DEFUN_HIDDEN (ospf_priority,
8469 ospf_priority_cmd,
8470 "ospf priority (0-255) [A.B.C.D]",
8471 "OSPF interface commands\n"
8472 "Router priority\n"
8473 "Priority\n"
8474 "Address of interface\n")
8475 {
8476 return ip_ospf_priority(self, vty, argc, argv);
8477 }
8478
8479 DEFUN (no_ip_ospf_priority,
8480 no_ip_ospf_priority_cmd,
8481 "no ip ospf priority [(0-255) [A.B.C.D]]",
8482 NO_STR
8483 "IP Information\n"
8484 "OSPF interface commands\n"
8485 "Router priority\n" // ignored
8486 "Priority\n"
8487 "Address of interface\n")
8488 {
8489 VTY_DECLVAR_CONTEXT(interface, ifp);
8490 int idx = 0;
8491 struct route_node *rn;
8492 struct in_addr addr;
8493 struct ospf_if_params *params;
8494
8495 params = IF_DEF_PARAMS(ifp);
8496
8497 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8498 if (!inet_aton(argv[idx]->arg, &addr)) {
8499 vty_out(vty,
8500 "Please specify interface address by A.B.C.D\n");
8501 return CMD_WARNING_CONFIG_FAILED;
8502 }
8503
8504 params = ospf_lookup_if_params(ifp, addr);
8505 if (params == NULL)
8506 return CMD_SUCCESS;
8507 }
8508
8509 UNSET_IF_PARAM(params, priority);
8510 params->priority = OSPF_ROUTER_PRIORITY_DEFAULT;
8511
8512 if (params != IF_DEF_PARAMS(ifp)) {
8513 ospf_free_if_params(ifp, addr);
8514 ospf_if_update_params(ifp, addr);
8515 }
8516
8517 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8518 struct ospf_interface *oi = rn->info;
8519
8520 if (!oi)
8521 continue;
8522
8523 if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) {
8524 PRIORITY(oi) = OSPF_IF_PARAM(oi, priority);
8525 OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange);
8526 }
8527 }
8528
8529 return CMD_SUCCESS;
8530 }
8531
8532 DEFUN_HIDDEN (no_ospf_priority,
8533 no_ospf_priority_cmd,
8534 "no ospf priority [(0-255) [A.B.C.D]]",
8535 NO_STR
8536 "OSPF interface commands\n"
8537 "Router priority\n"
8538 "Priority\n"
8539 "Address of interface\n")
8540 {
8541 return no_ip_ospf_priority(self, vty, argc, argv);
8542 }
8543
8544 DEFUN (ip_ospf_retransmit_interval,
8545 ip_ospf_retransmit_interval_addr_cmd,
8546 "ip ospf retransmit-interval (1-65535) [A.B.C.D]",
8547 "IP Information\n"
8548 "OSPF interface commands\n"
8549 "Time between retransmitting lost link state advertisements\n"
8550 "Seconds\n"
8551 "Address of interface\n")
8552 {
8553 VTY_DECLVAR_CONTEXT(interface, ifp);
8554 int idx = 0;
8555 uint32_t seconds;
8556 struct in_addr addr;
8557 struct ospf_if_params *params;
8558 params = IF_DEF_PARAMS(ifp);
8559
8560 argv_find(argv, argc, "(1-65535)", &idx);
8561 seconds = strtol(argv[idx]->arg, NULL, 10);
8562
8563 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8564 if (!inet_aton(argv[idx]->arg, &addr)) {
8565 vty_out(vty,
8566 "Please specify interface address by A.B.C.D\n");
8567 return CMD_WARNING_CONFIG_FAILED;
8568 }
8569
8570 params = ospf_get_if_params(ifp, addr);
8571 ospf_if_update_params(ifp, addr);
8572 }
8573
8574 SET_IF_PARAM(params, retransmit_interval);
8575 params->retransmit_interval = seconds;
8576
8577 return CMD_SUCCESS;
8578 }
8579
8580 DEFUN_HIDDEN (ospf_retransmit_interval,
8581 ospf_retransmit_interval_cmd,
8582 "ospf retransmit-interval (1-65535) [A.B.C.D]",
8583 "OSPF interface commands\n"
8584 "Time between retransmitting lost link state advertisements\n"
8585 "Seconds\n"
8586 "Address of interface\n")
8587 {
8588 return ip_ospf_retransmit_interval(self, vty, argc, argv);
8589 }
8590
8591 DEFUN (no_ip_ospf_retransmit_interval,
8592 no_ip_ospf_retransmit_interval_addr_cmd,
8593 "no ip ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8594 NO_STR
8595 "IP Information\n"
8596 "OSPF interface commands\n"
8597 "Time between retransmitting lost link state advertisements\n"
8598 "Seconds\n"
8599 "Address of interface\n")
8600 {
8601 VTY_DECLVAR_CONTEXT(interface, ifp);
8602 int idx = 0;
8603 struct in_addr addr;
8604 struct ospf_if_params *params;
8605
8606 params = IF_DEF_PARAMS(ifp);
8607
8608 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8609 if (!inet_aton(argv[idx]->arg, &addr)) {
8610 vty_out(vty,
8611 "Please specify interface address by A.B.C.D\n");
8612 return CMD_WARNING_CONFIG_FAILED;
8613 }
8614
8615 params = ospf_lookup_if_params(ifp, addr);
8616 if (params == NULL)
8617 return CMD_SUCCESS;
8618 }
8619
8620 UNSET_IF_PARAM(params, retransmit_interval);
8621 params->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT;
8622
8623 if (params != IF_DEF_PARAMS(ifp)) {
8624 ospf_free_if_params(ifp, addr);
8625 ospf_if_update_params(ifp, addr);
8626 }
8627
8628 return CMD_SUCCESS;
8629 }
8630
8631 DEFUN_HIDDEN (no_ospf_retransmit_interval,
8632 no_ospf_retransmit_interval_cmd,
8633 "no ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8634 NO_STR
8635 "OSPF interface commands\n"
8636 "Time between retransmitting lost link state advertisements\n"
8637 "Seconds\n"
8638 "Address of interface\n")
8639 {
8640 return no_ip_ospf_retransmit_interval(self, vty, argc, argv);
8641 }
8642
8643 DEFUN (ip_ospf_transmit_delay,
8644 ip_ospf_transmit_delay_addr_cmd,
8645 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
8646 "IP Information\n"
8647 "OSPF interface commands\n"
8648 "Link state transmit delay\n"
8649 "Seconds\n"
8650 "Address of interface\n")
8651 {
8652 VTY_DECLVAR_CONTEXT(interface, ifp);
8653 int idx = 0;
8654 uint32_t seconds;
8655 struct in_addr addr;
8656 struct ospf_if_params *params;
8657
8658 params = IF_DEF_PARAMS(ifp);
8659 argv_find(argv, argc, "(1-65535)", &idx);
8660 seconds = strtol(argv[idx]->arg, NULL, 10);
8661
8662 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8663 if (!inet_aton(argv[idx]->arg, &addr)) {
8664 vty_out(vty,
8665 "Please specify interface address by A.B.C.D\n");
8666 return CMD_WARNING_CONFIG_FAILED;
8667 }
8668
8669 params = ospf_get_if_params(ifp, addr);
8670 ospf_if_update_params(ifp, addr);
8671 }
8672
8673 SET_IF_PARAM(params, transmit_delay);
8674 params->transmit_delay = seconds;
8675
8676 return CMD_SUCCESS;
8677 }
8678
8679 DEFUN_HIDDEN (ospf_transmit_delay,
8680 ospf_transmit_delay_cmd,
8681 "ospf transmit-delay (1-65535) [A.B.C.D]",
8682 "OSPF interface commands\n"
8683 "Link state transmit delay\n"
8684 "Seconds\n"
8685 "Address of interface\n")
8686 {
8687 return ip_ospf_transmit_delay(self, vty, argc, argv);
8688 }
8689
8690 DEFUN (no_ip_ospf_transmit_delay,
8691 no_ip_ospf_transmit_delay_addr_cmd,
8692 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
8693 NO_STR
8694 "IP Information\n"
8695 "OSPF interface commands\n"
8696 "Link state transmit delay\n"
8697 "Seconds\n"
8698 "Address of interface\n")
8699 {
8700 VTY_DECLVAR_CONTEXT(interface, ifp);
8701 int idx = 0;
8702 struct in_addr addr;
8703 struct ospf_if_params *params;
8704
8705 params = IF_DEF_PARAMS(ifp);
8706
8707 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8708 if (!inet_aton(argv[idx]->arg, &addr)) {
8709 vty_out(vty,
8710 "Please specify interface address by A.B.C.D\n");
8711 return CMD_WARNING_CONFIG_FAILED;
8712 }
8713
8714 params = ospf_lookup_if_params(ifp, addr);
8715 if (params == NULL)
8716 return CMD_SUCCESS;
8717 }
8718
8719 UNSET_IF_PARAM(params, transmit_delay);
8720 params->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT;
8721
8722 if (params != IF_DEF_PARAMS(ifp)) {
8723 ospf_free_if_params(ifp, addr);
8724 ospf_if_update_params(ifp, addr);
8725 }
8726
8727 return CMD_SUCCESS;
8728 }
8729
8730
8731 DEFUN_HIDDEN (no_ospf_transmit_delay,
8732 no_ospf_transmit_delay_cmd,
8733 "no ospf transmit-delay [(1-65535) [A.B.C.D]]",
8734 NO_STR
8735 "OSPF interface commands\n"
8736 "Link state transmit delay\n"
8737 "Seconds\n"
8738 "Address of interface\n")
8739 {
8740 return no_ip_ospf_transmit_delay(self, vty, argc, argv);
8741 }
8742
8743 DEFUN (ip_ospf_area,
8744 ip_ospf_area_cmd,
8745 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]",
8746 "IP Information\n"
8747 "OSPF interface commands\n"
8748 "Instance ID\n"
8749 "Enable OSPF on this interface\n"
8750 "OSPF area ID in IP address format\n"
8751 "OSPF area ID as a decimal value\n"
8752 "Address of interface\n")
8753 {
8754 VTY_DECLVAR_CONTEXT(interface, ifp);
8755 int idx = 0;
8756 int format, ret;
8757 struct in_addr area_id;
8758 struct in_addr addr;
8759 struct ospf_if_params *params = NULL;
8760 struct route_node *rn;
8761 struct ospf *ospf = NULL;
8762 unsigned short instance = 0;
8763 char *areaid;
8764 uint32_t count = 0;
8765
8766 if (argv_find(argv, argc, "(1-65535)", &idx))
8767 instance = strtol(argv[idx]->arg, NULL, 10);
8768
8769 argv_find(argv, argc, "area", &idx);
8770 areaid = argv[idx + 1]->arg;
8771
8772 if (!instance)
8773 ospf = ifp->vrf->info;
8774 else
8775 ospf = ospf_lookup_instance(instance);
8776
8777 if (instance && instance != ospf_instance) {
8778 /*
8779 * At this point we know we have received
8780 * an instance and there is no ospf instance
8781 * associated with it. This means we are
8782 * in a situation where we have an
8783 * ospf command that is setup for a different
8784 * process(instance). We need to safely
8785 * remove the command from ourselves and
8786 * allow the other instance(process) handle
8787 * the configuration command.
8788 */
8789 count = 0;
8790
8791 params = IF_DEF_PARAMS(ifp);
8792 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
8793 UNSET_IF_PARAM(params, if_area);
8794 count++;
8795 }
8796
8797 for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; rn = route_next(rn))
8798 if ((params = rn->info) && OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
8799 UNSET_IF_PARAM(params, if_area);
8800 count++;
8801 }
8802
8803 if (count > 0) {
8804 ospf = ifp->vrf->info;
8805 if (ospf)
8806 ospf_interface_area_unset(ospf, ifp);
8807 }
8808
8809 return CMD_NOT_MY_INSTANCE;
8810 }
8811
8812 ret = str2area_id(areaid, &area_id, &format);
8813 if (ret < 0) {
8814 vty_out(vty, "Please specify area by A.B.C.D|<0-4294967295>\n");
8815 return CMD_WARNING_CONFIG_FAILED;
8816 }
8817 if (memcmp(ifp->name, "VLINK", 5) == 0) {
8818 vty_out(vty, "Cannot enable OSPF on a virtual link.\n");
8819 return CMD_WARNING_CONFIG_FAILED;
8820 }
8821
8822 if (ospf) {
8823 for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) {
8824 if (rn->info != NULL) {
8825 vty_out(vty,
8826 "Please remove all network commands first.\n");
8827 return CMD_WARNING_CONFIG_FAILED;
8828 }
8829 }
8830 }
8831
8832 params = IF_DEF_PARAMS(ifp);
8833 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)
8834 && !IPV4_ADDR_SAME(&params->if_area, &area_id)) {
8835 vty_out(vty,
8836 "Must remove previous area config before changing ospf area \n");
8837 return CMD_WARNING_CONFIG_FAILED;
8838 }
8839
8840 // Check if we have an address arg and proccess it
8841 if (argc == idx + 3) {
8842 if (!inet_aton(argv[idx + 2]->arg, &addr)) {
8843 vty_out(vty,
8844 "Please specify Intf Address by A.B.C.D\n");
8845 return CMD_WARNING_CONFIG_FAILED;
8846 }
8847 // update/create address-level params
8848 params = ospf_get_if_params((ifp), (addr));
8849 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
8850 if (!IPV4_ADDR_SAME(&params->if_area, &area_id)) {
8851 vty_out(vty,
8852 "Must remove previous area/address config before changing ospf area\n");
8853 return CMD_WARNING_CONFIG_FAILED;
8854 } else
8855 return CMD_SUCCESS;
8856 }
8857 ospf_if_update_params((ifp), (addr));
8858 }
8859
8860 /* enable ospf on this interface with area_id */
8861 if (params) {
8862 SET_IF_PARAM(params, if_area);
8863 params->if_area = area_id;
8864 params->if_area_id_fmt = format;
8865 }
8866
8867 if (ospf)
8868 ospf_interface_area_set(ospf, ifp);
8869
8870 return CMD_SUCCESS;
8871 }
8872
8873 DEFUN (no_ip_ospf_area,
8874 no_ip_ospf_area_cmd,
8875 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]",
8876 NO_STR
8877 "IP Information\n"
8878 "OSPF interface commands\n"
8879 "Instance ID\n"
8880 "Disable OSPF on this interface\n"
8881 "OSPF area ID in IP address format\n"
8882 "OSPF area ID as a decimal value\n"
8883 "Address of interface\n")
8884 {
8885 VTY_DECLVAR_CONTEXT(interface, ifp);
8886 int idx = 0;
8887 struct ospf *ospf;
8888 struct ospf_if_params *params;
8889 unsigned short instance = 0;
8890 struct in_addr addr;
8891 struct in_addr area_id;
8892
8893 if (argv_find(argv, argc, "(1-65535)", &idx))
8894 instance = strtol(argv[idx]->arg, NULL, 10);
8895
8896 if (!instance)
8897 ospf = ifp->vrf->info;
8898 else
8899 ospf = ospf_lookup_instance(instance);
8900
8901 if (instance && instance != ospf_instance)
8902 return CMD_NOT_MY_INSTANCE;
8903
8904 argv_find(argv, argc, "area", &idx);
8905
8906 // Check if we have an address arg and proccess it
8907 if (argc == idx + 3) {
8908 if (!inet_aton(argv[idx + 2]->arg, &addr)) {
8909 vty_out(vty,
8910 "Please specify Intf Address by A.B.C.D\n");
8911 return CMD_WARNING_CONFIG_FAILED;
8912 }
8913 params = ospf_lookup_if_params(ifp, addr);
8914 if ((params) == NULL)
8915 return CMD_SUCCESS;
8916 } else
8917 params = IF_DEF_PARAMS(ifp);
8918
8919 area_id = params->if_area;
8920 if (!OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
8921 vty_out(vty,
8922 "Can't find specified interface area configuration.\n");
8923 return CMD_WARNING_CONFIG_FAILED;
8924 }
8925
8926 UNSET_IF_PARAM(params, if_area);
8927 if (params != IF_DEF_PARAMS((ifp))) {
8928 ospf_free_if_params((ifp), (addr));
8929 ospf_if_update_params((ifp), (addr));
8930 }
8931
8932 if (ospf) {
8933 ospf_interface_area_unset(ospf, ifp);
8934 ospf_area_check_free(ospf, area_id);
8935 }
8936
8937 return CMD_SUCCESS;
8938 }
8939
8940 DEFUN (ip_ospf_passive,
8941 ip_ospf_passive_cmd,
8942 "ip ospf passive [A.B.C.D]",
8943 "IP Information\n"
8944 "OSPF interface commands\n"
8945 "Suppress routing updates on an interface\n"
8946 "Address of interface\n")
8947 {
8948 VTY_DECLVAR_CONTEXT(interface, ifp);
8949 int idx_ipv4 = 3;
8950 struct in_addr addr = {.s_addr = INADDR_ANY};
8951 struct ospf_if_params *params;
8952 int ret;
8953
8954 if (argc == 4) {
8955 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
8956 if (!ret) {
8957 vty_out(vty,
8958 "Please specify interface address by A.B.C.D\n");
8959 return CMD_WARNING_CONFIG_FAILED;
8960 }
8961 params = ospf_get_if_params(ifp, addr);
8962 ospf_if_update_params(ifp, addr);
8963 } else {
8964 params = IF_DEF_PARAMS(ifp);
8965 }
8966
8967 ospf_passive_interface_update(ifp, params, addr, OSPF_IF_PASSIVE);
8968
8969 return CMD_SUCCESS;
8970 }
8971
8972 DEFUN (no_ip_ospf_passive,
8973 no_ip_ospf_passive_cmd,
8974 "no ip ospf passive [A.B.C.D]",
8975 NO_STR
8976 "IP Information\n"
8977 "OSPF interface commands\n"
8978 "Enable routing updates on an interface\n"
8979 "Address of interface\n")
8980 {
8981 VTY_DECLVAR_CONTEXT(interface, ifp);
8982 int idx_ipv4 = 4;
8983 struct in_addr addr = {.s_addr = INADDR_ANY};
8984 struct ospf_if_params *params;
8985 int ret;
8986
8987 if (argc == 5) {
8988 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
8989 if (!ret) {
8990 vty_out(vty,
8991 "Please specify interface address by A.B.C.D\n");
8992 return CMD_WARNING_CONFIG_FAILED;
8993 }
8994 params = ospf_lookup_if_params(ifp, addr);
8995 if (params == NULL)
8996 return CMD_SUCCESS;
8997 } else {
8998 params = IF_DEF_PARAMS(ifp);
8999 }
9000
9001 ospf_passive_interface_update(ifp, params, addr, OSPF_IF_ACTIVE);
9002
9003 return CMD_SUCCESS;
9004 }
9005
9006 DEFUN (ospf_redistribute_source,
9007 ospf_redistribute_source_cmd,
9008 "redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9009 REDIST_STR
9010 FRR_REDIST_HELP_STR_OSPFD
9011 "Metric for redistributed routes\n"
9012 "OSPF default metric\n"
9013 "OSPF exterior metric type for redistributed routes\n"
9014 "Set OSPF External Type 1/2 metrics\n"
9015 "Route map reference\n"
9016 "Pointer to route-map entries\n")
9017 {
9018 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9019 int idx_protocol = 1;
9020 int source;
9021 int type = -1;
9022 int metric = -1;
9023 struct ospf_redist *red;
9024 int idx = 0;
9025 bool update = false;
9026
9027 /* Get distribute source. */
9028 source = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
9029 if (source < 0)
9030 return CMD_WARNING_CONFIG_FAILED;
9031
9032 /* Get metric value. */
9033 if (argv_find(argv, argc, "(0-16777214)", &idx)) {
9034 if (!str2metric(argv[idx]->arg, &metric))
9035 return CMD_WARNING_CONFIG_FAILED;
9036 }
9037 idx = 1;
9038 /* Get metric type. */
9039 if (argv_find(argv, argc, "(1-2)", &idx)) {
9040 if (!str2metric_type(argv[idx]->arg, &type))
9041 return CMD_WARNING_CONFIG_FAILED;
9042 }
9043 idx = 1;
9044
9045 red = ospf_redist_lookup(ospf, source, 0);
9046 if (!red)
9047 red = ospf_redist_add(ospf, source, 0);
9048 else
9049 update = true;
9050
9051 /* Get route-map */
9052 if (argv_find(argv, argc, "route-map", &idx)) {
9053 ospf_routemap_set(red, argv[idx + 1]->arg);
9054 } else
9055 ospf_routemap_unset(red);
9056
9057 if (update)
9058 return ospf_redistribute_update(ospf, red, source, 0, type,
9059 metric);
9060 else
9061 return ospf_redistribute_set(ospf, red, source, 0, type,
9062 metric);
9063 }
9064
9065 DEFUN (no_ospf_redistribute_source,
9066 no_ospf_redistribute_source_cmd,
9067 "no redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9068 NO_STR
9069 REDIST_STR
9070 FRR_REDIST_HELP_STR_OSPFD
9071 "Metric for redistributed routes\n"
9072 "OSPF default metric\n"
9073 "OSPF exterior metric type for redistributed routes\n"
9074 "Set OSPF External Type 1/2 metrics\n"
9075 "Route map reference\n"
9076 "Pointer to route-map entries\n")
9077 {
9078 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9079 int idx_protocol = 2;
9080 int source;
9081 struct ospf_redist *red;
9082
9083 source = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
9084 if (source < 0)
9085 return CMD_WARNING_CONFIG_FAILED;
9086
9087 red = ospf_redist_lookup(ospf, source, 0);
9088 if (!red)
9089 return CMD_SUCCESS;
9090
9091 ospf_routemap_unset(red);
9092 ospf_redist_del(ospf, source, 0);
9093
9094 return ospf_redistribute_unset(ospf, source, 0);
9095 }
9096
9097 DEFUN (ospf_redistribute_instance_source,
9098 ospf_redistribute_instance_source_cmd,
9099 "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9100 REDIST_STR
9101 "Open Shortest Path First\n"
9102 "Non-main Kernel Routing Table\n"
9103 "Instance ID/Table ID\n"
9104 "Metric for redistributed routes\n"
9105 "OSPF default metric\n"
9106 "OSPF exterior metric type for redistributed routes\n"
9107 "Set OSPF External Type 1/2 metrics\n"
9108 "Route map reference\n"
9109 "Pointer to route-map entries\n")
9110 {
9111 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9112 int idx_ospf_table = 1;
9113 int idx_number = 2;
9114 int idx = 3;
9115 int source;
9116 int type = -1;
9117 int metric = -1;
9118 unsigned short instance;
9119 struct ospf_redist *red;
9120 bool update = false;
9121
9122 source = proto_redistnum(AFI_IP, argv[idx_ospf_table]->text);
9123
9124 if (source < 0) {
9125 vty_out(vty, "Unknown instance redistribution\n");
9126 return CMD_WARNING_CONFIG_FAILED;
9127 }
9128
9129 instance = strtoul(argv[idx_number]->arg, NULL, 10);
9130
9131 if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) {
9132 vty_out(vty,
9133 "Instance redistribution in non-instanced OSPF not allowed\n");
9134 return CMD_WARNING_CONFIG_FAILED;
9135 }
9136
9137 if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) {
9138 vty_out(vty, "Same instance OSPF redistribution not allowed\n");
9139 return CMD_WARNING_CONFIG_FAILED;
9140 }
9141
9142 /* Get metric value. */
9143 if (argv_find(argv, argc, "metric", &idx))
9144 if (!str2metric(argv[idx + 1]->arg, &metric))
9145 return CMD_WARNING_CONFIG_FAILED;
9146
9147 idx = 3;
9148 /* Get metric type. */
9149 if (argv_find(argv, argc, "metric-type", &idx))
9150 if (!str2metric_type(argv[idx + 1]->arg, &type))
9151 return CMD_WARNING_CONFIG_FAILED;
9152
9153 red = ospf_redist_lookup(ospf, source, instance);
9154 if (!red)
9155 red = ospf_redist_add(ospf, source, instance);
9156 else
9157 update = true;
9158
9159 idx = 3;
9160 if (argv_find(argv, argc, "route-map", &idx))
9161 ospf_routemap_set(red, argv[idx + 1]->arg);
9162 else
9163 ospf_routemap_unset(red);
9164
9165 if (update)
9166 return ospf_redistribute_update(ospf, red, source, instance,
9167 type, metric);
9168 else
9169 return ospf_redistribute_set(ospf, red, source, instance, type,
9170 metric);
9171 }
9172
9173 DEFUN (no_ospf_redistribute_instance_source,
9174 no_ospf_redistribute_instance_source_cmd,
9175 "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9176 NO_STR
9177 REDIST_STR
9178 "Open Shortest Path First\n"
9179 "Non-main Kernel Routing Table\n"
9180 "Instance ID/Table Id\n"
9181 "Metric for redistributed routes\n"
9182 "OSPF default metric\n"
9183 "OSPF exterior metric type for redistributed routes\n"
9184 "Set OSPF External Type 1/2 metrics\n"
9185 "Route map reference\n"
9186 "Pointer to route-map entries\n")
9187 {
9188 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9189 int idx_ospf_table = 2;
9190 int idx_number = 3;
9191 unsigned int instance;
9192 struct ospf_redist *red;
9193 int source;
9194
9195 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
9196 source = ZEBRA_ROUTE_OSPF;
9197 else
9198 source = ZEBRA_ROUTE_TABLE;
9199
9200 instance = strtoul(argv[idx_number]->arg, NULL, 10);
9201
9202 if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) {
9203 vty_out(vty,
9204 "Instance redistribution in non-instanced OSPF not allowed\n");
9205 return CMD_WARNING_CONFIG_FAILED;
9206 }
9207
9208 if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) {
9209 vty_out(vty, "Same instance OSPF redistribution not allowed\n");
9210 return CMD_WARNING_CONFIG_FAILED;
9211 }
9212
9213 red = ospf_redist_lookup(ospf, source, instance);
9214 if (!red)
9215 return CMD_SUCCESS;
9216
9217 ospf_routemap_unset(red);
9218 ospf_redist_del(ospf, source, instance);
9219
9220 return ospf_redistribute_unset(ospf, source, instance);
9221 }
9222
9223 DEFUN (ospf_distribute_list_out,
9224 ospf_distribute_list_out_cmd,
9225 "distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD,
9226 "Filter networks in routing updates\n"
9227 "Access-list name\n"
9228 OUT_STR
9229 FRR_REDIST_HELP_STR_OSPFD)
9230 {
9231 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9232 int idx_word = 1;
9233 int source;
9234
9235 char *proto = argv[argc - 1]->text;
9236
9237 /* Get distribute source. */
9238 source = proto_redistnum(AFI_IP, proto);
9239 if (source < 0)
9240 return CMD_WARNING_CONFIG_FAILED;
9241
9242 return ospf_distribute_list_out_set(ospf, source, argv[idx_word]->arg);
9243 }
9244
9245 DEFUN (no_ospf_distribute_list_out,
9246 no_ospf_distribute_list_out_cmd,
9247 "no distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD,
9248 NO_STR
9249 "Filter networks in routing updates\n"
9250 "Access-list name\n"
9251 OUT_STR
9252 FRR_REDIST_HELP_STR_OSPFD)
9253 {
9254 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9255 int idx_word = 2;
9256 int source;
9257
9258 char *proto = argv[argc - 1]->text;
9259 source = proto_redistnum(AFI_IP, proto);
9260 if (source < 0)
9261 return CMD_WARNING_CONFIG_FAILED;
9262
9263 return ospf_distribute_list_out_unset(ospf, source,
9264 argv[idx_word]->arg);
9265 }
9266
9267 /* Default information originate. */
9268 DEFUN (ospf_default_information_originate,
9269 ospf_default_information_originate_cmd,
9270 "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9271 "Control distribution of default information\n"
9272 "Distribute a default route\n"
9273 "Always advertise default route\n"
9274 "OSPF default metric\n"
9275 "OSPF metric\n"
9276 "OSPF metric type for default routes\n"
9277 "Set OSPF External Type 1/2 metrics\n"
9278 "Route map reference\n"
9279 "Pointer to route-map entries\n")
9280 {
9281 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9282 int default_originate = DEFAULT_ORIGINATE_ZEBRA;
9283 int type = -1;
9284 int metric = -1;
9285 struct ospf_redist *red;
9286 int idx = 0;
9287 int cur_originate = ospf->default_originate;
9288 bool sameRtmap = false;
9289 char *rtmap = NULL;
9290
9291 red = ospf_redist_add(ospf, DEFAULT_ROUTE, 0);
9292
9293 /* Check whether "always" was specified */
9294 if (argv_find(argv, argc, "always", &idx))
9295 default_originate = DEFAULT_ORIGINATE_ALWAYS;
9296 idx = 1;
9297 /* Get metric value */
9298 if (argv_find(argv, argc, "(0-16777214)", &idx)) {
9299 if (!str2metric(argv[idx]->arg, &metric))
9300 return CMD_WARNING_CONFIG_FAILED;
9301 }
9302 idx = 1;
9303 /* Get metric type. */
9304 if (argv_find(argv, argc, "(1-2)", &idx)) {
9305 if (!str2metric_type(argv[idx]->arg, &type))
9306 return CMD_WARNING_CONFIG_FAILED;
9307 }
9308 idx = 1;
9309 /* Get route-map */
9310 if (argv_find(argv, argc, "route-map", &idx))
9311 rtmap = argv[idx + 1]->arg;
9312
9313 /* To check if user is providing same route map */
9314 if ((!rtmap && !ROUTEMAP_NAME(red)) ||
9315 (rtmap && ROUTEMAP_NAME(red) &&
9316 (strcmp(rtmap, ROUTEMAP_NAME(red)) == 0)))
9317 sameRtmap = true;
9318
9319 /* Don't allow if the same lsa is already originated. */
9320 if ((sameRtmap)
9321 && (red->dmetric.type == type)
9322 && (red->dmetric.value == metric)
9323 && (cur_originate == default_originate))
9324 return CMD_SUCCESS;
9325
9326 /* Updating Metric details */
9327 red->dmetric.type = type;
9328 red->dmetric.value = metric;
9329
9330 /* updating route map details */
9331 if (rtmap)
9332 ospf_routemap_set(red, rtmap);
9333 else
9334 ospf_routemap_unset(red);
9335
9336 return ospf_redistribute_default_set(ospf, default_originate, type,
9337 metric);
9338 }
9339
9340 DEFUN (no_ospf_default_information_originate,
9341 no_ospf_default_information_originate_cmd,
9342 "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9343 NO_STR
9344 "Control distribution of default information\n"
9345 "Distribute a default route\n"
9346 "Always advertise default route\n"
9347 "OSPF default metric\n"
9348 "OSPF metric\n"
9349 "OSPF metric type for default routes\n"
9350 "Set OSPF External Type 1/2 metrics\n"
9351 "Route map reference\n"
9352 "Pointer to route-map entries\n")
9353 {
9354 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9355 struct ospf_redist *red;
9356
9357 red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0);
9358 if (!red)
9359 return CMD_SUCCESS;
9360
9361 ospf_routemap_unset(red);
9362 ospf_redist_del(ospf, DEFAULT_ROUTE, 0);
9363
9364 return ospf_redistribute_default_set(ospf, DEFAULT_ORIGINATE_NONE,
9365 0, 0);
9366 }
9367
9368 DEFUN (ospf_default_metric,
9369 ospf_default_metric_cmd,
9370 "default-metric (0-16777214)",
9371 "Set metric of redistributed routes\n"
9372 "Default metric\n")
9373 {
9374 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9375 int idx_number = 1;
9376 int metric = -1;
9377
9378 if (!str2metric(argv[idx_number]->arg, &metric))
9379 return CMD_WARNING_CONFIG_FAILED;
9380
9381 ospf->default_metric = metric;
9382
9383 return CMD_SUCCESS;
9384 }
9385
9386 DEFUN (no_ospf_default_metric,
9387 no_ospf_default_metric_cmd,
9388 "no default-metric [(0-16777214)]",
9389 NO_STR
9390 "Set metric of redistributed routes\n"
9391 "Default metric\n")
9392 {
9393 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9394
9395 ospf->default_metric = -1;
9396
9397 return CMD_SUCCESS;
9398 }
9399
9400
9401 DEFUN (ospf_distance,
9402 ospf_distance_cmd,
9403 "distance (1-255)",
9404 "Administrative distance\n"
9405 "OSPF Administrative distance\n")
9406 {
9407 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9408 int idx_number = 1;
9409 uint8_t distance;
9410
9411 distance = atoi(argv[idx_number]->arg);
9412 if (ospf->distance_all != distance) {
9413 ospf->distance_all = distance;
9414 ospf_restart_spf(ospf);
9415 }
9416
9417 return CMD_SUCCESS;
9418 }
9419
9420 DEFUN (no_ospf_distance,
9421 no_ospf_distance_cmd,
9422 "no distance (1-255)",
9423 NO_STR
9424 "Administrative distance\n"
9425 "OSPF Administrative distance\n")
9426 {
9427 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9428
9429 if (ospf->distance_all) {
9430 ospf->distance_all = 0;
9431 ospf_restart_spf(ospf);
9432 }
9433
9434 return CMD_SUCCESS;
9435 }
9436
9437 DEFUN (no_ospf_distance_ospf,
9438 no_ospf_distance_ospf_cmd,
9439 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
9440 NO_STR
9441 "Administrative distance\n"
9442 "OSPF administrative distance\n"
9443 "Intra-area routes\n"
9444 "Distance for intra-area routes\n"
9445 "Inter-area routes\n"
9446 "Distance for inter-area routes\n"
9447 "External routes\n"
9448 "Distance for external routes\n")
9449 {
9450 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9451 int idx = 0;
9452
9453 if (argv_find(argv, argc, "intra-area", &idx) || argc == 3)
9454 idx = ospf->distance_intra = 0;
9455 if (argv_find(argv, argc, "inter-area", &idx) || argc == 3)
9456 idx = ospf->distance_inter = 0;
9457 if (argv_find(argv, argc, "external", &idx) || argc == 3)
9458 ospf->distance_external = 0;
9459
9460 return CMD_SUCCESS;
9461 }
9462
9463 DEFUN (ospf_distance_ospf,
9464 ospf_distance_ospf_cmd,
9465 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
9466 "Administrative distance\n"
9467 "OSPF administrative distance\n"
9468 "Intra-area routes\n"
9469 "Distance for intra-area routes\n"
9470 "Inter-area routes\n"
9471 "Distance for inter-area routes\n"
9472 "External routes\n"
9473 "Distance for external routes\n")
9474 {
9475 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9476 int idx = 0;
9477
9478 ospf->distance_intra = 0;
9479 ospf->distance_inter = 0;
9480 ospf->distance_external = 0;
9481
9482 if (argv_find(argv, argc, "intra-area", &idx))
9483 ospf->distance_intra = atoi(argv[idx + 1]->arg);
9484 idx = 0;
9485 if (argv_find(argv, argc, "inter-area", &idx))
9486 ospf->distance_inter = atoi(argv[idx + 1]->arg);
9487 idx = 0;
9488 if (argv_find(argv, argc, "external", &idx))
9489 ospf->distance_external = atoi(argv[idx + 1]->arg);
9490
9491 return CMD_SUCCESS;
9492 }
9493
9494 DEFUN (ip_ospf_mtu_ignore,
9495 ip_ospf_mtu_ignore_addr_cmd,
9496 "ip ospf mtu-ignore [A.B.C.D]",
9497 "IP Information\n"
9498 "OSPF interface commands\n"
9499 "Disable MTU mismatch detection on this interface\n"
9500 "Address of interface\n")
9501 {
9502 VTY_DECLVAR_CONTEXT(interface, ifp);
9503 int idx_ipv4 = 3;
9504 struct in_addr addr;
9505 int ret;
9506
9507 struct ospf_if_params *params;
9508 params = IF_DEF_PARAMS(ifp);
9509
9510 if (argc == 4) {
9511 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
9512 if (!ret) {
9513 vty_out(vty,
9514 "Please specify interface address by A.B.C.D\n");
9515 return CMD_WARNING_CONFIG_FAILED;
9516 }
9517 params = ospf_get_if_params(ifp, addr);
9518 ospf_if_update_params(ifp, addr);
9519 }
9520 params->mtu_ignore = 1;
9521 if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT)
9522 SET_IF_PARAM(params, mtu_ignore);
9523 else {
9524 UNSET_IF_PARAM(params, mtu_ignore);
9525 if (params != IF_DEF_PARAMS(ifp)) {
9526 ospf_free_if_params(ifp, addr);
9527 ospf_if_update_params(ifp, addr);
9528 }
9529 }
9530 return CMD_SUCCESS;
9531 }
9532
9533 DEFUN (no_ip_ospf_mtu_ignore,
9534 no_ip_ospf_mtu_ignore_addr_cmd,
9535 "no ip ospf mtu-ignore [A.B.C.D]",
9536 NO_STR
9537 "IP Information\n"
9538 "OSPF interface commands\n"
9539 "Disable MTU mismatch detection on this interface\n"
9540 "Address of interface\n")
9541 {
9542 VTY_DECLVAR_CONTEXT(interface, ifp);
9543 int idx_ipv4 = 4;
9544 struct in_addr addr;
9545 int ret;
9546
9547 struct ospf_if_params *params;
9548 params = IF_DEF_PARAMS(ifp);
9549
9550 if (argc == 5) {
9551 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
9552 if (!ret) {
9553 vty_out(vty,
9554 "Please specify interface address by A.B.C.D\n");
9555 return CMD_WARNING_CONFIG_FAILED;
9556 }
9557 params = ospf_get_if_params(ifp, addr);
9558 ospf_if_update_params(ifp, addr);
9559 }
9560 params->mtu_ignore = 0;
9561 if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT)
9562 SET_IF_PARAM(params, mtu_ignore);
9563 else {
9564 UNSET_IF_PARAM(params, mtu_ignore);
9565 if (params != IF_DEF_PARAMS(ifp)) {
9566 ospf_free_if_params(ifp, addr);
9567 ospf_if_update_params(ifp, addr);
9568 }
9569 }
9570 return CMD_SUCCESS;
9571 }
9572
9573
9574 DEFUN (ospf_max_metric_router_lsa_admin,
9575 ospf_max_metric_router_lsa_admin_cmd,
9576 "max-metric router-lsa administrative",
9577 "OSPF maximum / infinite-distance metric\n"
9578 "Advertise own Router-LSA with infinite distance (stub router)\n"
9579 "Administratively applied, for an indefinite period\n")
9580 {
9581 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9582 struct listnode *ln;
9583 struct ospf_area *area;
9584
9585 for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
9586 SET_FLAG(area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED);
9587
9588 if (!CHECK_FLAG(area->stub_router_state,
9589 OSPF_AREA_IS_STUB_ROUTED))
9590 ospf_router_lsa_update_area(area);
9591 }
9592
9593 /* Allows for areas configured later to get the property */
9594 ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_SET;
9595
9596 return CMD_SUCCESS;
9597 }
9598
9599 DEFUN (no_ospf_max_metric_router_lsa_admin,
9600 no_ospf_max_metric_router_lsa_admin_cmd,
9601 "no max-metric router-lsa administrative",
9602 NO_STR
9603 "OSPF maximum / infinite-distance metric\n"
9604 "Advertise own Router-LSA with infinite distance (stub router)\n"
9605 "Administratively applied, for an indefinite period\n")
9606 {
9607 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9608 struct listnode *ln;
9609 struct ospf_area *area;
9610
9611 for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
9612 UNSET_FLAG(area->stub_router_state,
9613 OSPF_AREA_ADMIN_STUB_ROUTED);
9614
9615 /* Don't trample on the start-up stub timer */
9616 if (CHECK_FLAG(area->stub_router_state,
9617 OSPF_AREA_IS_STUB_ROUTED)
9618 && !area->t_stub_router) {
9619 UNSET_FLAG(area->stub_router_state,
9620 OSPF_AREA_IS_STUB_ROUTED);
9621 ospf_router_lsa_update_area(area);
9622 }
9623 }
9624 ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET;
9625 return CMD_SUCCESS;
9626 }
9627
9628 DEFUN (ospf_max_metric_router_lsa_startup,
9629 ospf_max_metric_router_lsa_startup_cmd,
9630 "max-metric router-lsa on-startup (5-86400)",
9631 "OSPF maximum / infinite-distance metric\n"
9632 "Advertise own Router-LSA with infinite distance (stub router)\n"
9633 "Automatically advertise stub Router-LSA on startup of OSPF\n"
9634 "Time (seconds) to advertise self as stub-router\n")
9635 {
9636 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9637 int idx_number = 3;
9638 unsigned int seconds;
9639
9640 if (argc < 4) {
9641 vty_out(vty, "%% Must supply stub-router period\n");
9642 return CMD_WARNING_CONFIG_FAILED;
9643 }
9644
9645 seconds = strtoul(argv[idx_number]->arg, NULL, 10);
9646
9647 ospf->stub_router_startup_time = seconds;
9648
9649 return CMD_SUCCESS;
9650 }
9651
9652 DEFUN (no_ospf_max_metric_router_lsa_startup,
9653 no_ospf_max_metric_router_lsa_startup_cmd,
9654 "no max-metric router-lsa on-startup [(5-86400)]",
9655 NO_STR
9656 "OSPF maximum / infinite-distance metric\n"
9657 "Advertise own Router-LSA with infinite distance (stub router)\n"
9658 "Automatically advertise stub Router-LSA on startup of OSPF\n"
9659 "Time (seconds) to advertise self as stub-router\n")
9660 {
9661 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9662 struct listnode *ln;
9663 struct ospf_area *area;
9664
9665 ospf->stub_router_startup_time = OSPF_STUB_ROUTER_UNCONFIGURED;
9666
9667 for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
9668 SET_FLAG(area->stub_router_state,
9669 OSPF_AREA_WAS_START_STUB_ROUTED);
9670 EVENT_OFF(area->t_stub_router);
9671
9672 /* Don't trample on admin stub routed */
9673 if (!CHECK_FLAG(area->stub_router_state,
9674 OSPF_AREA_ADMIN_STUB_ROUTED)) {
9675 UNSET_FLAG(area->stub_router_state,
9676 OSPF_AREA_IS_STUB_ROUTED);
9677 ospf_router_lsa_update_area(area);
9678 }
9679 }
9680 return CMD_SUCCESS;
9681 }
9682
9683
9684 DEFUN (ospf_max_metric_router_lsa_shutdown,
9685 ospf_max_metric_router_lsa_shutdown_cmd,
9686 "max-metric router-lsa on-shutdown (5-100)",
9687 "OSPF maximum / infinite-distance metric\n"
9688 "Advertise own Router-LSA with infinite distance (stub router)\n"
9689 "Advertise stub-router prior to full shutdown of OSPF\n"
9690 "Time (seconds) to wait till full shutdown\n")
9691 {
9692 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9693 int idx_number = 3;
9694 unsigned int seconds;
9695
9696 if (argc < 4) {
9697 vty_out(vty, "%% Must supply stub-router shutdown period\n");
9698 return CMD_WARNING_CONFIG_FAILED;
9699 }
9700
9701 seconds = strtoul(argv[idx_number]->arg, NULL, 10);
9702
9703 ospf->stub_router_shutdown_time = seconds;
9704
9705 return CMD_SUCCESS;
9706 }
9707
9708 DEFUN (no_ospf_max_metric_router_lsa_shutdown,
9709 no_ospf_max_metric_router_lsa_shutdown_cmd,
9710 "no max-metric router-lsa on-shutdown [(5-100)]",
9711 NO_STR
9712 "OSPF maximum / infinite-distance metric\n"
9713 "Advertise own Router-LSA with infinite distance (stub router)\n"
9714 "Advertise stub-router prior to full shutdown of OSPF\n"
9715 "Time (seconds) to wait till full shutdown\n")
9716 {
9717 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9718
9719 ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED;
9720
9721 return CMD_SUCCESS;
9722 }
9723
9724 DEFUN (ospf_proactive_arp,
9725 ospf_proactive_arp_cmd,
9726 "proactive-arp",
9727 "Allow sending ARP requests proactively\n")
9728 {
9729 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9730
9731 ospf->proactive_arp = true;
9732
9733 return CMD_SUCCESS;
9734 }
9735
9736 DEFUN (no_ospf_proactive_arp,
9737 no_ospf_proactive_arp_cmd,
9738 "no proactive-arp",
9739 NO_STR
9740 "Disallow sending ARP requests proactively\n")
9741 {
9742 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9743
9744 ospf->proactive_arp = false;
9745
9746 return CMD_SUCCESS;
9747 }
9748
9749 /* Graceful Restart HELPER Commands */
9750 DEFPY(ospf_gr_helper_enable, ospf_gr_helper_enable_cmd,
9751 "graceful-restart helper enable [A.B.C.D$address]",
9752 "OSPF Graceful Restart\n"
9753 "OSPF GR Helper\n"
9754 "Enable Helper support\n"
9755 "Advertising Router-ID\n")
9756 {
9757 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9758
9759 if (address_str) {
9760 ospf_gr_helper_support_set_per_routerid(ospf, &address,
9761 OSPF_GR_TRUE);
9762 return CMD_SUCCESS;
9763 }
9764
9765 ospf_gr_helper_support_set(ospf, OSPF_GR_TRUE);
9766
9767 return CMD_SUCCESS;
9768 }
9769
9770 DEFPY(no_ospf_gr_helper_enable,
9771 no_ospf_gr_helper_enable_cmd,
9772 "no graceful-restart helper enable [A.B.C.D$address]",
9773 NO_STR
9774 "OSPF Graceful Restart\n"
9775 "OSPF GR Helper\n"
9776 "Enable Helper support\n"
9777 "Advertising Router-ID\n")
9778 {
9779 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9780
9781 if (address_str) {
9782 ospf_gr_helper_support_set_per_routerid(ospf, &address,
9783 OSPF_GR_FALSE);
9784 return CMD_SUCCESS;
9785 }
9786
9787 ospf_gr_helper_support_set(ospf, OSPF_GR_FALSE);
9788 return CMD_SUCCESS;
9789 }
9790
9791 DEFPY(ospf_gr_helper_enable_lsacheck,
9792 ospf_gr_helper_enable_lsacheck_cmd,
9793 "graceful-restart helper strict-lsa-checking",
9794 "OSPF Graceful Restart\n"
9795 "OSPF GR Helper\n"
9796 "Enable strict LSA check\n")
9797 {
9798 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9799
9800 ospf_gr_helper_lsa_check_set(ospf, OSPF_GR_TRUE);
9801 return CMD_SUCCESS;
9802 }
9803
9804 DEFPY(no_ospf_gr_helper_enable_lsacheck,
9805 no_ospf_gr_helper_enable_lsacheck_cmd,
9806 "no graceful-restart helper strict-lsa-checking",
9807 NO_STR
9808 "OSPF Graceful Restart\n"
9809 "OSPF GR Helper\n"
9810 "Disable strict LSA check\n")
9811 {
9812 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9813
9814 ospf_gr_helper_lsa_check_set(ospf, OSPF_GR_FALSE);
9815 return CMD_SUCCESS;
9816 }
9817
9818 DEFPY(ospf_gr_helper_supported_grace_time,
9819 ospf_gr_helper_supported_grace_time_cmd,
9820 "graceful-restart helper supported-grace-time (10-1800)$interval",
9821 "OSPF Graceful Restart\n"
9822 "OSPF GR Helper\n"
9823 "Supported grace timer\n"
9824 "Grace interval(in seconds)\n")
9825 {
9826 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9827
9828 ospf_gr_helper_supported_gracetime_set(ospf, interval);
9829 return CMD_SUCCESS;
9830 }
9831
9832 DEFPY(no_ospf_gr_helper_supported_grace_time,
9833 no_ospf_gr_helper_supported_grace_time_cmd,
9834 "no graceful-restart helper supported-grace-time (10-1800)$interval",
9835 NO_STR
9836 "OSPF Graceful Restart\n"
9837 "OSPF GR Helper\n"
9838 "Supported grace timer\n"
9839 "Grace interval(in seconds)\n")
9840 {
9841 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9842
9843 ospf_gr_helper_supported_gracetime_set(ospf, OSPF_MAX_GRACE_INTERVAL);
9844 return CMD_SUCCESS;
9845 }
9846
9847 DEFPY(ospf_gr_helper_planned_only,
9848 ospf_gr_helper_planned_only_cmd,
9849 "graceful-restart helper planned-only",
9850 "OSPF Graceful Restart\n"
9851 "OSPF GR Helper\n"
9852 "Supported only planned restart\n")
9853 {
9854 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9855
9856 ospf_gr_helper_set_supported_planned_only_restart(ospf, OSPF_GR_TRUE);
9857
9858 return CMD_SUCCESS;
9859 }
9860
9861 /* External Route Aggregation */
9862 DEFUN (ospf_external_route_aggregation,
9863 ospf_external_route_aggregation_cmd,
9864 "summary-address A.B.C.D/M [tag (1-4294967295)]",
9865 "External summary address\n"
9866 "Summary address prefix\n"
9867 "Router tag \n"
9868 "Router tag value\n")
9869 {
9870 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9871 struct prefix_ipv4 p;
9872 int idx = 1;
9873 route_tag_t tag = 0;
9874 int ret = OSPF_SUCCESS;
9875
9876 str2prefix_ipv4(argv[idx]->arg, &p);
9877
9878 if (is_default_prefix4(&p)) {
9879 vty_out(vty,
9880 "Default address shouldn't be configured as summary address.\n");
9881 return CMD_SUCCESS;
9882 }
9883
9884 /* Apply mask for given prefix. */
9885 apply_mask(&p);
9886
9887 if (!is_valid_summary_addr(&p)) {
9888 vty_out(vty, "Not a valid summary address.\n");
9889 return CMD_WARNING_CONFIG_FAILED;
9890 }
9891
9892 if (argc > 2)
9893 tag = strtoul(argv[idx + 2]->arg, NULL, 10);
9894
9895 ret = ospf_asbr_external_aggregator_set(ospf, &p, tag);
9896 if (ret == OSPF_INVALID)
9897 vty_out(vty, "Invalid configuration!!\n");
9898
9899 return CMD_SUCCESS;
9900 }
9901
9902 DEFUN (no_ospf_external_route_aggregation,
9903 no_ospf_external_route_aggregation_cmd,
9904 "no summary-address A.B.C.D/M [tag (1-4294967295)]",
9905 NO_STR
9906 "External summary address\n"
9907 "Summary address prefix\n"
9908 "Router tag\n"
9909 "Router tag value\n")
9910 {
9911 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9912 struct prefix_ipv4 p;
9913 int idx = 2;
9914 route_tag_t tag = 0;
9915 int ret = OSPF_SUCCESS;
9916
9917 str2prefix_ipv4(argv[idx]->arg, &p);
9918
9919 if (is_default_prefix4(&p)) {
9920 vty_out(vty,
9921 "Default address shouldn't be configured as summary address.\n");
9922 return CMD_SUCCESS;
9923 }
9924
9925 /* Apply mask for given prefix. */
9926 apply_mask(&p);
9927
9928 if (!is_valid_summary_addr(&p)) {
9929 vty_out(vty, "Not a valid summary address.\n");
9930 return CMD_WARNING_CONFIG_FAILED;
9931 }
9932
9933 if (argc > 3)
9934 tag = strtoul(argv[idx + 2]->arg, NULL, 10);
9935
9936 ret = ospf_asbr_external_aggregator_unset(ospf, &p, tag);
9937 if (ret == OSPF_INVALID)
9938 vty_out(vty, "Invalid configuration!!\n");
9939
9940 return CMD_SUCCESS;
9941 }
9942
9943 DEFPY(no_ospf_gr_helper_planned_only,
9944 no_ospf_gr_helper_planned_only_cmd,
9945 "no graceful-restart helper planned-only",
9946 NO_STR
9947 "OSPF Graceful Restart\n"
9948 "OSPF GR Helper\n"
9949 "Supported only for planned restart\n")
9950 {
9951 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9952
9953 ospf_gr_helper_set_supported_planned_only_restart(ospf, OSPF_GR_FALSE);
9954
9955 return CMD_SUCCESS;
9956 }
9957
9958 static int ospf_print_vty_helper_dis_rtr_walkcb(struct hash_bucket *bucket,
9959 void *arg)
9960 {
9961 struct advRtr *rtr = bucket->data;
9962 struct vty *vty = (struct vty *)arg;
9963 static unsigned int count;
9964
9965 vty_out(vty, "%-6pI4,", &rtr->advRtrAddr);
9966 count++;
9967
9968 if (count % 5 == 0)
9969 vty_out(vty, "\n");
9970
9971 return HASHWALK_CONTINUE;
9972 }
9973
9974 static int ospf_print_json_helper_enabled_rtr_walkcb(struct hash_bucket *bucket,
9975 void *arg)
9976 {
9977 struct advRtr *rtr = bucket->data;
9978 struct json_object *json_rid_array = arg;
9979 struct json_object *json_rid;
9980
9981 json_rid = json_object_new_object();
9982
9983 json_object_string_addf(json_rid, "routerId", "%pI4", &rtr->advRtrAddr);
9984 json_object_array_add(json_rid_array, json_rid);
9985
9986 return HASHWALK_CONTINUE;
9987 }
9988
9989 static int ospf_show_gr_helper_details(struct vty *vty, struct ospf *ospf,
9990 uint8_t use_vrf, json_object *json,
9991 bool uj, bool detail)
9992 {
9993 struct listnode *node;
9994 struct ospf_interface *oi;
9995 char buf[PREFIX_STRLEN];
9996 json_object *json_vrf = NULL;
9997
9998 if (uj) {
9999 if (use_vrf)
10000 json_vrf = json_object_new_object();
10001 else
10002 json_vrf = json;
10003 }
10004
10005 if (ospf->instance) {
10006 if (uj)
10007 json_object_int_add(json, "ospfInstance",
10008 ospf->instance);
10009 else
10010 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
10011 }
10012
10013 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
10014
10015 if (uj) {
10016 if (use_vrf)
10017 json_object_object_add(json, ospf_get_name(ospf),
10018 json_vrf);
10019 } else
10020 vty_out(vty, "\n");
10021
10022 /* Show Router ID. */
10023 if (uj) {
10024 json_object_string_add(json_vrf, "routerId",
10025 inet_ntop(AF_INET, &ospf->router_id,
10026 buf, sizeof(buf)));
10027 } else {
10028 vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n",
10029 &ospf->router_id);
10030 }
10031
10032 if (!uj) {
10033
10034 if (ospf->is_helper_supported)
10035 vty_out(vty,
10036 " Graceful restart helper support enabled.\n");
10037 else
10038 vty_out(vty,
10039 " Graceful restart helper support disabled.\n");
10040
10041 if (ospf->strict_lsa_check)
10042 vty_out(vty, " Strict LSA check is enabled.\n");
10043 else
10044 vty_out(vty, " Strict LSA check is disabled.\n");
10045
10046 if (ospf->only_planned_restart)
10047 vty_out(vty,
10048 " Helper supported for planned restarts only.\n");
10049 else
10050 vty_out(vty,
10051 " Helper supported for Planned and Unplanned Restarts.\n");
10052
10053 vty_out(vty,
10054 " Supported Graceful restart interval: %d(in seconds).\n",
10055 ospf->supported_grace_time);
10056
10057 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf)) {
10058 vty_out(vty, " Enable Router list:\n");
10059 vty_out(vty, " ");
10060 hash_walk(ospf->enable_rtr_list,
10061 ospf_print_vty_helper_dis_rtr_walkcb, vty);
10062 vty_out(vty, "\n\n");
10063 }
10064
10065 if (ospf->last_exit_reason != OSPF_GR_HELPER_EXIT_NONE) {
10066 vty_out(vty, " Last Helper exit Reason :%s\n",
10067 ospf_exit_reason2str(ospf->last_exit_reason));
10068 }
10069
10070 if (ospf->active_restarter_cnt)
10071 vty_out(vty,
10072 " Number of Active neighbours in graceful restart: %d\n",
10073 ospf->active_restarter_cnt);
10074 else
10075 vty_out(vty, "\n");
10076
10077 } else {
10078 json_object_string_add(
10079 json_vrf, "helperSupport",
10080 (ospf->is_helper_supported) ? "Enabled" : "Disabled");
10081 json_object_string_add(json_vrf, "strictLsaCheck",
10082 (ospf->strict_lsa_check) ? "Enabled"
10083 : "Disabled");
10084 #if CONFDATE > 20240401
10085 CPP_NOTICE("Remove deprecated json key: restartSupoort")
10086 #endif
10087 json_object_string_add(
10088 json_vrf, "restartSupoort",
10089 (ospf->only_planned_restart)
10090 ? "Planned Restart only"
10091 : "Planned and Unplanned Restarts");
10092
10093 json_object_string_add(
10094 json_vrf, "restartSupport",
10095 (ospf->only_planned_restart)
10096 ? "Planned Restart only"
10097 : "Planned and Unplanned Restarts");
10098
10099 json_object_int_add(json_vrf, "supportedGracePeriod",
10100 ospf->supported_grace_time);
10101
10102 if (ospf->last_exit_reason != OSPF_GR_HELPER_EXIT_NONE)
10103 json_object_string_add(
10104 json_vrf, "lastExitReason",
10105 ospf_exit_reason2str(ospf->last_exit_reason));
10106
10107 if (ospf->active_restarter_cnt)
10108 json_object_int_add(json_vrf, "activeRestarterCnt",
10109 ospf->active_restarter_cnt);
10110
10111 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf)) {
10112 struct json_object *json_rid_array =
10113 json_object_new_array();
10114
10115 json_object_object_add(json_vrf, "enabledRouterIds",
10116 json_rid_array);
10117
10118 hash_walk(ospf->enable_rtr_list,
10119 ospf_print_json_helper_enabled_rtr_walkcb,
10120 json_rid_array);
10121 }
10122 }
10123
10124
10125 if (detail) {
10126 int cnt = 1;
10127 json_object *json_neighbors = NULL;
10128
10129 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
10130 struct route_node *rn;
10131 struct ospf_neighbor *nbr;
10132 json_object *json_neigh;
10133
10134 if (ospf_interface_neighbor_count(oi) == 0)
10135 continue;
10136
10137 if (uj) {
10138 json_object_object_get_ex(json_vrf, "neighbors",
10139 &json_neighbors);
10140 if (!json_neighbors) {
10141 json_neighbors =
10142 json_object_new_object();
10143 json_object_object_add(json_vrf,
10144 "neighbors",
10145 json_neighbors);
10146 }
10147 }
10148
10149 for (rn = route_top(oi->nbrs); rn;
10150 rn = route_next(rn)) {
10151
10152 if (!rn->info)
10153 continue;
10154
10155 nbr = rn->info;
10156
10157 if (!OSPF_GR_IS_ACTIVE_HELPER(nbr))
10158 continue;
10159
10160 if (!uj) {
10161 vty_out(vty, " Neighbour %d :\n", cnt);
10162 vty_out(vty, " Address : %pI4\n",
10163 &nbr->address.u.prefix4);
10164 vty_out(vty, " Routerid : %pI4\n",
10165 &nbr->router_id);
10166 vty_out(vty,
10167 " Received Grace period : %d(in seconds).\n",
10168 nbr->gr_helper_info
10169 .recvd_grace_period);
10170 vty_out(vty,
10171 " Actual Grace period : %d(in seconds)\n",
10172 nbr->gr_helper_info
10173 .actual_grace_period);
10174 vty_out(vty,
10175 " Remaining GraceTime:%ld(in seconds).\n",
10176 event_timer_remain_second(
10177 nbr->gr_helper_info
10178 .t_grace_timer));
10179 vty_out(vty,
10180 " Graceful Restart reason: %s.\n\n",
10181 ospf_restart_reason2str(
10182 nbr->gr_helper_info
10183 .gr_restart_reason));
10184 cnt++;
10185 } else {
10186 json_neigh = json_object_new_object();
10187 json_object_string_add(
10188 json_neigh, "srcAddr",
10189 inet_ntop(AF_INET, &nbr->src,
10190 buf, sizeof(buf)));
10191
10192 json_object_string_add(
10193 json_neigh, "routerid",
10194 inet_ntop(AF_INET,
10195 &nbr->router_id,
10196 buf, sizeof(buf)));
10197 json_object_int_add(
10198 json_neigh,
10199 "recvdGraceInterval",
10200 nbr->gr_helper_info
10201 .recvd_grace_period);
10202 json_object_int_add(
10203 json_neigh,
10204 "actualGraceInterval",
10205 nbr->gr_helper_info
10206 .actual_grace_period);
10207 json_object_int_add(
10208 json_neigh, "remainGracetime",
10209 event_timer_remain_second(
10210 nbr->gr_helper_info
10211 .t_grace_timer));
10212 json_object_string_add(
10213 json_neigh, "restartReason",
10214 ospf_restart_reason2str(
10215 nbr->gr_helper_info
10216 .gr_restart_reason));
10217 json_object_object_add(
10218 json_neighbors,
10219 inet_ntop(AF_INET, &nbr->src,
10220 buf, sizeof(buf)),
10221 json_neigh);
10222 }
10223 }
10224 }
10225 }
10226 return CMD_SUCCESS;
10227 }
10228
10229 DEFUN (ospf_external_route_aggregation_no_adrvertise,
10230 ospf_external_route_aggregation_no_adrvertise_cmd,
10231 "summary-address A.B.C.D/M no-advertise",
10232 "External summary address\n"
10233 "Summary address prefix\n"
10234 "Don't advertise summary route \n")
10235 {
10236 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10237 struct prefix_ipv4 p;
10238 int idx = 1;
10239 int ret = OSPF_SUCCESS;
10240
10241 str2prefix_ipv4(argv[idx]->arg, &p);
10242
10243 if (is_default_prefix4(&p)) {
10244 vty_out(vty,
10245 "Default address shouldn't be configured as summary address.\n");
10246 return CMD_SUCCESS;
10247 }
10248
10249 /* Apply mask for given prefix. */
10250 apply_mask(&p);
10251
10252 if (!is_valid_summary_addr(&p)) {
10253 vty_out(vty, "Not a valid summary address.\n");
10254 return CMD_WARNING_CONFIG_FAILED;
10255 }
10256
10257 ret = ospf_asbr_external_rt_no_advertise(ospf, &p);
10258 if (ret == OSPF_INVALID)
10259 vty_out(vty, "Invalid configuration!!\n");
10260
10261 return CMD_SUCCESS;
10262 }
10263
10264 DEFUN (no_ospf_external_route_aggregation_no_adrvertise,
10265 no_ospf_external_route_aggregation_no_adrvertise_cmd,
10266 "no summary-address A.B.C.D/M no-advertise",
10267 NO_STR
10268 "External summary address\n"
10269 "Summary address prefix\n"
10270 "Advertise summary route to the AS \n")
10271 {
10272 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10273 struct prefix_ipv4 p;
10274 int idx = 2;
10275 int ret = OSPF_SUCCESS;
10276
10277 str2prefix_ipv4(argv[idx]->arg, &p);
10278
10279 if (is_default_prefix4(&p)) {
10280 vty_out(vty,
10281 "Default address shouldn't be configured as summary address.\n");
10282 return CMD_SUCCESS;
10283 }
10284
10285 /* Apply mask for given prefix. */
10286 apply_mask(&p);
10287
10288 if (!is_valid_summary_addr(&p)) {
10289 vty_out(vty, "Not a valid summary address.\n");
10290 return CMD_WARNING_CONFIG_FAILED;
10291 }
10292
10293 ret = ospf_asbr_external_rt_advertise(ospf, &p);
10294 if (ret == OSPF_INVALID)
10295 vty_out(vty, "Invalid configuration!!\n");
10296
10297 return CMD_SUCCESS;
10298 }
10299
10300 DEFUN (ospf_route_aggregation_timer,
10301 ospf_route_aggregation_timer_cmd,
10302 "aggregation timer (5-1800)",
10303 "External route aggregation\n"
10304 "Delay timer (in seconds)\n"
10305 "Timer interval(in seconds)\n")
10306 {
10307 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10308 uint16_t interval = 0;
10309
10310 interval = strtoul(argv[2]->arg, NULL, 10);
10311
10312 ospf_external_aggregator_timer_set(ospf, interval);
10313
10314 return CMD_SUCCESS;
10315 }
10316
10317 DEFPY (show_ip_ospf_gr_helper,
10318 show_ip_ospf_gr_helper_cmd,
10319 "show ip ospf [vrf <NAME|all>] graceful-restart helper [detail] [json]",
10320 SHOW_STR
10321 IP_STR
10322 "OSPF information\n"
10323 VRF_CMD_HELP_STR
10324 "All VRFs\n"
10325 "OSPF Graceful Restart\n"
10326 "Helper details in the router\n"
10327 "Detailed information\n"
10328 JSON_STR)
10329 {
10330 char *vrf_name = NULL;
10331 bool all_vrf = false;
10332 int ret = CMD_SUCCESS;
10333 int idx_vrf = 0;
10334 int idx = 0;
10335 uint8_t use_vrf = 0;
10336 bool uj = use_json(argc, argv);
10337 struct ospf *ospf = NULL;
10338 json_object *json = NULL;
10339 struct listnode *node = NULL;
10340 int inst = 0;
10341 bool detail = false;
10342
10343 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
10344
10345 if (argv_find(argv, argc, "detail", &idx))
10346 detail = true;
10347
10348 if (uj)
10349 json = json_object_new_object();
10350
10351 /* vrf input is provided */
10352 if (vrf_name) {
10353 use_vrf = 1;
10354
10355 if (all_vrf) {
10356 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
10357 if (!ospf->oi_running)
10358 continue;
10359
10360 ret = ospf_show_gr_helper_details(
10361 vty, ospf, use_vrf, json, uj, detail);
10362 }
10363
10364 if (uj)
10365 vty_json(vty, json);
10366
10367 return ret;
10368 }
10369
10370 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
10371
10372 if (ospf == NULL || !ospf->oi_running) {
10373
10374 if (uj)
10375 vty_json(vty, json);
10376 else
10377 vty_out(vty,
10378 "%% OSPF is not enabled in vrf %s\n",
10379 vrf_name);
10380
10381 return CMD_SUCCESS;
10382 }
10383
10384 } else {
10385 /* Default Vrf */
10386 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
10387
10388 if (ospf == NULL || !ospf->oi_running) {
10389
10390 if (uj)
10391 vty_json(vty, json);
10392 else
10393 vty_out(vty,
10394 "%% OSPF is not enabled in vrf default\n");
10395
10396 return CMD_SUCCESS;
10397 }
10398
10399 ospf_show_gr_helper_details(vty, ospf, use_vrf, json, uj,
10400 detail);
10401 }
10402
10403 if (uj)
10404 vty_json(vty, json);
10405
10406 return CMD_SUCCESS;
10407 }
10408 /* Graceful Restart HELPER commands end */
10409 DEFUN (no_ospf_route_aggregation_timer,
10410 no_ospf_route_aggregation_timer_cmd,
10411 "no aggregation timer",
10412 NO_STR
10413 "External route aggregation\n"
10414 "Delay timer\n")
10415 {
10416 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10417
10418 ospf_external_aggregator_timer_set(ospf, OSPF_EXTL_AGGR_DEFAULT_DELAY);
10419
10420 return CMD_SUCCESS;
10421 }
10422
10423 /* External Route Aggregation End */
10424
10425 static void config_write_stub_router(struct vty *vty, struct ospf *ospf)
10426 {
10427 if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED)
10428 vty_out(vty, " max-metric router-lsa on-startup %u\n",
10429 ospf->stub_router_startup_time);
10430 if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED)
10431 vty_out(vty, " max-metric router-lsa on-shutdown %u\n",
10432 ospf->stub_router_shutdown_time);
10433 if (ospf->stub_router_admin_set == OSPF_STUB_ROUTER_ADMINISTRATIVE_SET)
10434 vty_out(vty, " max-metric router-lsa administrative\n");
10435
10436 return;
10437 }
10438
10439 static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf,
10440 struct route_table *rt,
10441 json_object *json)
10442 {
10443 struct route_node *rn;
10444 struct ospf_route * or ;
10445 struct listnode *pnode, *pnnode;
10446 struct ospf_path *path;
10447 json_object *json_route = NULL, *json_nexthop_array = NULL,
10448 *json_nexthop = NULL;
10449
10450 if (!json)
10451 vty_out(vty,
10452 "============ OSPF network routing table ============\n");
10453
10454 for (rn = route_top(rt); rn; rn = route_next(rn)) {
10455 char buf1[PREFIX2STR_BUFFER];
10456
10457 if ((or = rn->info) == NULL)
10458 continue;
10459
10460 prefix2str(&rn->p, buf1, sizeof(buf1));
10461
10462 if (json) {
10463 json_route = json_object_new_object();
10464 json_object_object_add(json, buf1, json_route);
10465 }
10466
10467 switch (or->path_type) {
10468 case OSPF_PATH_INTER_AREA:
10469 if (or->type == OSPF_DESTINATION_NETWORK) {
10470 if (json) {
10471 json_object_string_add(json_route,
10472 "routeType",
10473 "N IA");
10474 json_object_int_add(json_route, "cost",
10475 or->cost);
10476 json_object_string_addf(
10477 json_route, "area", "%pI4",
10478 &or->u.std.area_id);
10479 } else {
10480 vty_out(vty,
10481 "N IA %-18s [%d] area: %pI4\n",
10482 buf1, or->cost,
10483 &or->u.std.area_id);
10484 }
10485 } else if (or->type == OSPF_DESTINATION_DISCARD) {
10486 if (json) {
10487 json_object_string_add(json_route,
10488 "routeType",
10489 "D IA");
10490 } else {
10491 vty_out(vty,
10492 "D IA %-18s Discard entry\n",
10493 buf1);
10494 }
10495 }
10496 break;
10497 case OSPF_PATH_INTRA_AREA:
10498 if (json) {
10499 json_object_string_add(json_route, "routeType",
10500 "N");
10501 json_object_int_add(json_route, "cost",
10502 or->cost);
10503 json_object_string_addf(json_route, "area",
10504 "%pI4",
10505 &or->u.std.area_id);
10506 } else {
10507 vty_out(vty, "N %-18s [%d] area: %pI4\n",
10508 buf1, or->cost,
10509 &or->u.std.area_id);
10510 }
10511 break;
10512 default:
10513 break;
10514 }
10515
10516 if (or->type == OSPF_DESTINATION_NETWORK) {
10517 if (json) {
10518 json_nexthop_array = json_object_new_array();
10519 json_object_object_add(json_route, "nexthops",
10520 json_nexthop_array);
10521 }
10522
10523 for (ALL_LIST_ELEMENTS(or->paths, pnode, pnnode,
10524 path)) {
10525 if (json) {
10526 json_nexthop = json_object_new_object();
10527 json_object_array_add(
10528 json_nexthop_array,
10529 json_nexthop);
10530 }
10531 if (if_lookup_by_index(path->ifindex,
10532 ospf->vrf_id)) {
10533
10534 if (path->nexthop.s_addr
10535 == INADDR_ANY) {
10536 if (json) {
10537 json_object_string_add(
10538 json_nexthop,
10539 "ip", " ");
10540 json_object_string_add(
10541 json_nexthop,
10542 "directlyAttachedTo",
10543 ifindex2ifname(
10544 path->ifindex,
10545 ospf->vrf_id));
10546 } else {
10547 vty_out(vty,
10548 "%24s directly attached to %s\n",
10549 "",
10550 ifindex2ifname(
10551 path->ifindex,
10552 ospf->vrf_id));
10553 }
10554 } else {
10555 if (json) {
10556 json_object_string_addf(
10557 json_nexthop,
10558 "ip", "%pI4",
10559 &path->nexthop);
10560 json_object_string_add(
10561 json_nexthop,
10562 "via",
10563 ifindex2ifname(
10564 path->ifindex,
10565 ospf->vrf_id));
10566 } else {
10567 vty_out(vty,
10568 "%24s via %pI4, %s\n",
10569 "",
10570 &path->nexthop,
10571 ifindex2ifname(
10572 path->ifindex,
10573 ospf->vrf_id));
10574 }
10575 }
10576 }
10577 }
10578 }
10579 }
10580 if (!json)
10581 vty_out(vty, "\n");
10582 }
10583
10584 static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf,
10585 struct route_table *rtrs,
10586 json_object *json)
10587 {
10588 struct route_node *rn;
10589 struct ospf_route * or ;
10590 struct listnode *pnode;
10591 struct listnode *node;
10592 struct ospf_path *path;
10593 char buf[PREFIX_STRLEN];
10594 json_object *json_route = NULL, *json_nexthop_array = NULL,
10595 *json_nexthop = NULL;
10596
10597 if (!json)
10598 vty_out(vty, "============ OSPF %s table =============\n",
10599 ospf->all_rtrs == rtrs ? "reachable routers"
10600 : "router routing");
10601
10602 for (rn = route_top(rtrs); rn; rn = route_next(rn)) {
10603 if (rn->info == NULL)
10604 continue;
10605 int flag = 0;
10606
10607 if (json) {
10608 json_route = json_object_new_object();
10609 json_object_object_add(
10610 json, inet_ntop(AF_INET, &rn->p.u.prefix4,
10611 buf, sizeof(buf)),
10612 json_route);
10613 json_object_string_add(json_route, "routeType", "R ");
10614 } else {
10615 vty_out(vty, "R %-15pI4 ",
10616 &rn->p.u.prefix4);
10617 }
10618
10619 for (ALL_LIST_ELEMENTS_RO((struct list *)rn->info, node, or)) {
10620 if (flag++) {
10621 if (!json)
10622 vty_out(vty, "%24s", "");
10623 }
10624
10625 /* Show path. */
10626 if (json) {
10627 json_object_int_add(json_route, "cost",
10628 or->cost);
10629 json_object_string_addf(json_route, "area",
10630 "%pI4",
10631 &or->u.std.area_id);
10632 if (or->path_type == OSPF_PATH_INTER_AREA) {
10633 json_object_boolean_true_add(json_route,
10634 "IA");
10635 json_object_boolean_true_add(json_route,
10636 "ia");
10637 }
10638 if (or->u.std.flags & ROUTER_LSA_BORDER)
10639 json_object_string_add(json_route,
10640 "routerType",
10641 "abr");
10642 else if (or->u.std.flags & ROUTER_LSA_EXTERNAL)
10643 json_object_string_add(json_route,
10644 "routerType",
10645 "asbr");
10646 } else {
10647 vty_out(vty, "%s [%d] area: %pI4",
10648 (or->path_type == OSPF_PATH_INTER_AREA
10649 ? "IA"
10650 : " "),
10651 or->cost, &or->u.std.area_id);
10652 /* Show flags. */
10653 vty_out(vty, "%s%s\n",
10654 (or->u.std.flags & ROUTER_LSA_BORDER
10655 ? ", ABR"
10656 : ""),
10657 (or->u.std.flags & ROUTER_LSA_EXTERNAL
10658 ? ", ASBR"
10659 : ""));
10660 }
10661
10662 if (json) {
10663 json_nexthop_array = json_object_new_array();
10664 json_object_object_add(json_route, "nexthops",
10665 json_nexthop_array);
10666 }
10667
10668 for (ALL_LIST_ELEMENTS_RO(or->paths, pnode, path)) {
10669 if (json) {
10670 json_nexthop = json_object_new_object();
10671 json_object_array_add(
10672 json_nexthop_array,
10673 json_nexthop);
10674 }
10675 if (if_lookup_by_index(path->ifindex,
10676 ospf->vrf_id)) {
10677 if (path->nexthop.s_addr
10678 == INADDR_ANY) {
10679 if (json) {
10680 json_object_string_add(
10681 json_nexthop,
10682 "ip", " ");
10683 json_object_string_add(
10684 json_nexthop,
10685 "directlyAttachedTo",
10686 ifindex2ifname(
10687 path->ifindex,
10688 ospf->vrf_id));
10689 } else {
10690 vty_out(vty,
10691 "%24s directly attached to %s\n",
10692 "",
10693 ifindex2ifname(
10694 path->ifindex,
10695 ospf->vrf_id));
10696 }
10697 } else {
10698 if (json) {
10699 json_object_string_addf(
10700 json_nexthop,
10701 "ip", "%pI4",
10702 &path->nexthop);
10703 json_object_string_add(
10704 json_nexthop,
10705 "via",
10706 ifindex2ifname(
10707 path->ifindex,
10708 ospf->vrf_id));
10709 } else {
10710 vty_out(vty,
10711 "%24s via %pI4, %s\n",
10712 "",
10713 &path->nexthop,
10714 ifindex2ifname(
10715 path->ifindex,
10716 ospf->vrf_id));
10717 }
10718 }
10719 }
10720 }
10721 }
10722 }
10723 if (!json)
10724 vty_out(vty, "\n");
10725 }
10726
10727 static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf,
10728 struct route_table *rt,
10729 json_object *json)
10730 {
10731 struct route_node *rn;
10732 struct ospf_route *er;
10733 struct listnode *pnode, *pnnode;
10734 struct ospf_path *path;
10735 json_object *json_route = NULL, *json_nexthop_array = NULL,
10736 *json_nexthop = NULL;
10737
10738 if (!json)
10739 vty_out(vty,
10740 "============ OSPF external routing table ===========\n");
10741
10742 for (rn = route_top(rt); rn; rn = route_next(rn)) {
10743 if ((er = rn->info) == NULL)
10744 continue;
10745
10746 char buf1[19];
10747
10748 snprintfrr(buf1, sizeof(buf1), "%pFX", &rn->p);
10749 if (json) {
10750 json_route = json_object_new_object();
10751 json_object_object_add(json, buf1, json_route);
10752 }
10753
10754 switch (er->path_type) {
10755 case OSPF_PATH_TYPE1_EXTERNAL:
10756 if (json) {
10757 json_object_string_add(json_route, "routeType",
10758 "N E1");
10759 json_object_int_add(json_route, "cost",
10760 er->cost);
10761 json_object_int_add(json_route, "tag",
10762 er->u.ext.tag);
10763 } else {
10764 vty_out(vty,
10765 "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI
10766 "\n",
10767 buf1, er->cost, er->u.ext.tag);
10768 }
10769 break;
10770 case OSPF_PATH_TYPE2_EXTERNAL:
10771 if (json) {
10772 json_object_string_add(json_route, "routeType",
10773 "N E2");
10774 json_object_int_add(json_route, "cost",
10775 er->cost);
10776 json_object_int_add(json_route, "type2cost",
10777 er->u.ext.type2_cost);
10778 json_object_int_add(json_route, "tag",
10779 er->u.ext.tag);
10780 } else {
10781 vty_out(vty,
10782 "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI
10783 "\n",
10784 buf1, er->cost, er->u.ext.type2_cost,
10785 er->u.ext.tag);
10786 }
10787 break;
10788 }
10789
10790 if (json) {
10791 json_nexthop_array = json_object_new_array();
10792 json_object_object_add(json_route, "nexthops",
10793 json_nexthop_array);
10794 }
10795
10796 for (ALL_LIST_ELEMENTS(er->paths, pnode, pnnode, path)) {
10797 if (json) {
10798 json_nexthop = json_object_new_object();
10799 json_object_array_add(json_nexthop_array,
10800 json_nexthop);
10801 }
10802
10803 if (if_lookup_by_index(path->ifindex, ospf->vrf_id)) {
10804 if (path->nexthop.s_addr == INADDR_ANY) {
10805 if (json) {
10806 json_object_string_add(
10807 json_nexthop, "ip",
10808 " ");
10809 json_object_string_add(
10810 json_nexthop,
10811 "directlyAttachedTo",
10812 ifindex2ifname(
10813 path->ifindex,
10814 ospf->vrf_id));
10815 } else {
10816 vty_out(vty,
10817 "%24s directly attached to %s\n",
10818 "",
10819 ifindex2ifname(
10820 path->ifindex,
10821 ospf->vrf_id));
10822 }
10823 } else {
10824 if (json) {
10825 json_object_string_addf(
10826 json_nexthop, "ip",
10827 "%pI4", &path->nexthop);
10828 json_object_string_add(
10829 json_nexthop, "via",
10830 ifindex2ifname(
10831 path->ifindex,
10832 ospf->vrf_id));
10833 } else {
10834 vty_out(vty,
10835 "%24s via %pI4, %s\n",
10836 "",
10837 &path->nexthop,
10838 ifindex2ifname(
10839 path->ifindex,
10840 ospf->vrf_id));
10841 }
10842 }
10843 }
10844 }
10845 }
10846 if (!json)
10847 vty_out(vty, "\n");
10848 }
10849
10850 static int show_ip_ospf_reachable_routers_common(struct vty *vty,
10851 struct ospf *ospf,
10852 uint8_t use_vrf)
10853 {
10854 if (ospf->instance)
10855 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
10856
10857 ospf_show_vrf_name(ospf, vty, NULL, use_vrf);
10858
10859 if (ospf->all_rtrs == NULL) {
10860 vty_out(vty, "No OSPF reachable router information exist\n");
10861 return CMD_SUCCESS;
10862 }
10863
10864 /* Show Router routes. */
10865 show_ip_ospf_route_router(vty, ospf, ospf->all_rtrs, NULL);
10866
10867 vty_out(vty, "\n");
10868
10869 return CMD_SUCCESS;
10870 }
10871
10872 DEFUN (show_ip_ospf_reachable_routers,
10873 show_ip_ospf_reachable_routers_cmd,
10874 "show ip ospf [vrf <NAME|all>] reachable-routers",
10875 SHOW_STR
10876 IP_STR
10877 "OSPF information\n"
10878 VRF_CMD_HELP_STR
10879 "All VRFs\n"
10880 "Show all the reachable OSPF routers\n")
10881 {
10882 struct ospf *ospf = NULL;
10883 struct listnode *node = NULL;
10884 char *vrf_name = NULL;
10885 bool all_vrf = false;
10886 int ret = CMD_SUCCESS;
10887 int inst = 0;
10888 int idx_vrf = 0;
10889 uint8_t use_vrf = 0;
10890
10891 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
10892
10893 if (vrf_name) {
10894 bool ospf_output = false;
10895
10896 use_vrf = 1;
10897
10898 if (all_vrf) {
10899 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
10900 if (!ospf->oi_running)
10901 continue;
10902
10903 ospf_output = true;
10904 ret = show_ip_ospf_reachable_routers_common(
10905 vty, ospf, use_vrf);
10906 }
10907
10908 if (!ospf_output)
10909 vty_out(vty, "%% OSPF instance not found\n");
10910 } else {
10911 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
10912 if (ospf == NULL || !ospf->oi_running) {
10913 vty_out(vty, "%% OSPF instance not found\n");
10914 return CMD_SUCCESS;
10915 }
10916
10917 ret = show_ip_ospf_reachable_routers_common(vty, ospf,
10918 use_vrf);
10919 }
10920 } else {
10921 /* Display default ospf (instance 0) info */
10922 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
10923 if (ospf == NULL || !ospf->oi_running) {
10924 vty_out(vty, "%% OSPF instance not found\n");
10925 return CMD_SUCCESS;
10926 }
10927
10928 ret = show_ip_ospf_reachable_routers_common(vty, ospf, use_vrf);
10929 }
10930
10931 return ret;
10932 }
10933
10934 DEFUN (show_ip_ospf_instance_reachable_routers,
10935 show_ip_ospf_instance_reachable_routers_cmd,
10936 "show ip ospf (1-65535) reachable-routers",
10937 SHOW_STR
10938 IP_STR
10939 "OSPF information\n"
10940 "Instance ID\n"
10941 "Show all the reachable OSPF routers\n")
10942 {
10943 int idx_number = 3;
10944 struct ospf *ospf;
10945 unsigned short instance = 0;
10946
10947 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10948 if (instance != ospf_instance)
10949 return CMD_NOT_MY_INSTANCE;
10950
10951 ospf = ospf_lookup_instance(instance);
10952 if (!ospf || !ospf->oi_running)
10953 return CMD_SUCCESS;
10954
10955 return show_ip_ospf_reachable_routers_common(vty, ospf, 0);
10956 }
10957
10958 static int show_ip_ospf_border_routers_common(struct vty *vty,
10959 struct ospf *ospf,
10960 uint8_t use_vrf,
10961 json_object *json)
10962 {
10963 json_object *json_vrf = NULL;
10964 json_object *json_router = NULL;
10965
10966 if (json) {
10967 if (use_vrf)
10968 json_vrf = json_object_new_object();
10969 else
10970 json_vrf = json;
10971 json_router = json_object_new_object();
10972 }
10973
10974 if (ospf->instance) {
10975 if (!json)
10976 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
10977 else
10978 json_object_int_add(json_vrf, "ospfInstance",
10979 ospf->instance);
10980 }
10981
10982 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
10983
10984 if (ospf->new_table == NULL) {
10985 if (!json)
10986 vty_out(vty, "No OSPF routing information exist\n");
10987 else {
10988 json_object_free(json_router);
10989 if (use_vrf)
10990 json_object_free(json_vrf);
10991 }
10992 return CMD_SUCCESS;
10993 }
10994
10995 /* Show Network routes.
10996 show_ip_ospf_route_network (vty, ospf->new_table); */
10997
10998 /* Show Router routes. */
10999 show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, json_router);
11000
11001 if (json) {
11002 json_object_object_add(json_vrf, "routers", json_router);
11003 if (use_vrf) {
11004 if (ospf->vrf_id == VRF_DEFAULT)
11005 json_object_object_add(json, "default",
11006 json_vrf);
11007 else
11008 json_object_object_add(json, ospf->name,
11009 json_vrf);
11010 }
11011 } else {
11012 vty_out(vty, "\n");
11013 }
11014
11015 return CMD_SUCCESS;
11016 }
11017
11018 DEFPY (show_ip_ospf_border_routers,
11019 show_ip_ospf_border_routers_cmd,
11020 "show ip ospf [vrf <NAME|all>] border-routers [json]",
11021 SHOW_STR
11022 IP_STR
11023 "OSPF information\n"
11024 VRF_CMD_HELP_STR
11025 "All VRFs\n"
11026 "Show all the ABR's and ASBR's\n"
11027 JSON_STR)
11028 {
11029 struct ospf *ospf = NULL;
11030 struct listnode *node = NULL;
11031 char *vrf_name = NULL;
11032 bool all_vrf = false;
11033 int ret = CMD_SUCCESS;
11034 int inst = 0;
11035 int idx_vrf = 0;
11036 uint8_t use_vrf = 0;
11037 bool uj = use_json(argc, argv);
11038 json_object *json = NULL;
11039
11040 if (uj)
11041 json = json_object_new_object();
11042
11043 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
11044
11045 if (vrf_name) {
11046 bool ospf_output = false;
11047
11048 use_vrf = 1;
11049
11050 if (all_vrf) {
11051 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11052 if (!ospf->oi_running)
11053 continue;
11054
11055 ospf_output = true;
11056 ret = show_ip_ospf_border_routers_common(
11057 vty, ospf, use_vrf, json);
11058 }
11059
11060 if (uj)
11061 vty_json(vty, json);
11062 else if (!ospf_output)
11063 vty_out(vty, "%% OSPF is not enabled\n");
11064
11065 return ret;
11066 } else {
11067 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
11068 if (ospf == NULL || !ospf->oi_running) {
11069 if (uj)
11070 vty_json(vty, json);
11071 else
11072 vty_out(vty,
11073 "%% OSPF is not enabled in vrf %s\n",
11074 vrf_name);
11075
11076 return CMD_SUCCESS;
11077 }
11078 }
11079 } else {
11080 /* Display default ospf (instance 0) info */
11081 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
11082 if (ospf == NULL || !ospf->oi_running) {
11083 if (uj)
11084 vty_json(vty, json);
11085 else
11086 vty_out(vty,
11087 "%% OSPF is not enabled in vrf default\n");
11088
11089 return CMD_SUCCESS;
11090 }
11091 }
11092
11093 if (ospf) {
11094 ret = show_ip_ospf_border_routers_common(vty, ospf, use_vrf,
11095 json);
11096 if (uj)
11097 vty_json(vty, json);
11098 }
11099
11100 return ret;
11101 }
11102
11103 DEFUN (show_ip_ospf_instance_border_routers,
11104 show_ip_ospf_instance_border_routers_cmd,
11105 "show ip ospf (1-65535) border-routers",
11106 SHOW_STR
11107 IP_STR
11108 "OSPF information\n"
11109 "Instance ID\n"
11110 "Show all the ABR's and ASBR's\n")
11111 {
11112 int idx_number = 3;
11113 struct ospf *ospf;
11114 unsigned short instance = 0;
11115
11116 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11117 if (instance != ospf_instance)
11118 return CMD_NOT_MY_INSTANCE;
11119
11120 ospf = ospf_lookup_instance(instance);
11121 if (!ospf || !ospf->oi_running)
11122 return CMD_SUCCESS;
11123
11124 return show_ip_ospf_border_routers_common(vty, ospf, 0, NULL);
11125 }
11126
11127 static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf,
11128 json_object *json, uint8_t use_vrf)
11129 {
11130 json_object *json_vrf = NULL;
11131
11132 if (ospf->instance)
11133 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
11134
11135
11136 if (json) {
11137 if (use_vrf)
11138 json_vrf = json_object_new_object();
11139 else
11140 json_vrf = json;
11141 }
11142
11143 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
11144
11145 if (ospf->new_table == NULL) {
11146 if (json) {
11147 if (use_vrf)
11148 json_object_free(json_vrf);
11149 } else {
11150 vty_out(vty, "No OSPF routing information exist\n");
11151 }
11152 return CMD_SUCCESS;
11153 }
11154
11155 /* Show Network routes. */
11156 show_ip_ospf_route_network(vty, ospf, ospf->new_table, json_vrf);
11157
11158 /* Show Router routes. */
11159 show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, json_vrf);
11160
11161 /* Show Router routes. */
11162 if (ospf->all_rtrs)
11163 show_ip_ospf_route_router(vty, ospf, ospf->all_rtrs, json_vrf);
11164
11165 /* Show AS External routes. */
11166 show_ip_ospf_route_external(vty, ospf, ospf->old_external_route,
11167 json_vrf);
11168
11169 if (json) {
11170 if (use_vrf) {
11171 // json_object_object_add(json_vrf, "areas",
11172 // json_areas);
11173 json_object_object_add(json, ospf_get_name(ospf),
11174 json_vrf);
11175 }
11176 } else {
11177 vty_out(vty, "\n");
11178 }
11179
11180 return CMD_SUCCESS;
11181 }
11182
11183 DEFUN (show_ip_ospf_route,
11184 show_ip_ospf_route_cmd,
11185 "show ip ospf [vrf <NAME|all>] route [json]",
11186 SHOW_STR
11187 IP_STR
11188 "OSPF information\n"
11189 VRF_CMD_HELP_STR
11190 "All VRFs\n"
11191 "OSPF routing table\n"
11192 JSON_STR)
11193 {
11194 struct ospf *ospf = NULL;
11195 struct listnode *node = NULL;
11196 char *vrf_name = NULL;
11197 bool all_vrf = false;
11198 int ret = CMD_SUCCESS;
11199 int inst = 0;
11200 int idx_vrf = 0;
11201 uint8_t use_vrf = 0;
11202 bool uj = use_json(argc, argv);
11203 json_object *json = NULL;
11204
11205 if (uj)
11206 json = json_object_new_object();
11207
11208 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
11209
11210 /* vrf input is provided could be all or specific vrf*/
11211 if (vrf_name) {
11212 bool ospf_output = false;
11213
11214 use_vrf = 1;
11215
11216 if (all_vrf) {
11217 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11218 if (!ospf->oi_running)
11219 continue;
11220 ospf_output = true;
11221 ret = show_ip_ospf_route_common(vty, ospf, json,
11222 use_vrf);
11223 }
11224
11225 if (uj) {
11226 /* Keep Non-pretty format */
11227 vty_json(vty, json);
11228 } else if (!ospf_output)
11229 vty_out(vty, "%% OSPF is not enabled\n");
11230
11231 return ret;
11232 }
11233 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
11234 if (ospf == NULL || !ospf->oi_running) {
11235 if (uj)
11236 vty_json(vty, json);
11237 else
11238 vty_out(vty,
11239 "%% OSPF is not enabled in vrf %s\n",
11240 vrf_name);
11241
11242 return CMD_SUCCESS;
11243 }
11244 } else {
11245 /* Display default ospf (instance 0) info */
11246 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
11247 if (ospf == NULL || !ospf->oi_running) {
11248 if (uj)
11249 vty_json(vty, json);
11250 else
11251 vty_out(vty,
11252 "%% OSPF is not enabled in vrf default\n");
11253
11254 return CMD_SUCCESS;
11255 }
11256 }
11257
11258 if (ospf) {
11259 ret = show_ip_ospf_route_common(vty, ospf, json, use_vrf);
11260 /* Keep Non-pretty format */
11261 if (uj)
11262 vty_out(vty, "%s\n",
11263 json_object_to_json_string_ext(
11264 json, JSON_C_TO_STRING_NOSLASHESCAPE));
11265 }
11266
11267 if (uj)
11268 json_object_free(json);
11269
11270 return ret;
11271 }
11272
11273 DEFUN (show_ip_ospf_instance_route,
11274 show_ip_ospf_instance_route_cmd,
11275 "show ip ospf (1-65535) route",
11276 SHOW_STR
11277 IP_STR
11278 "OSPF information\n"
11279 "Instance ID\n"
11280 "OSPF routing table\n")
11281 {
11282 int idx_number = 3;
11283 struct ospf *ospf;
11284 unsigned short instance = 0;
11285
11286 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11287 if (instance != ospf_instance)
11288 return CMD_NOT_MY_INSTANCE;
11289
11290 ospf = ospf_lookup_instance(instance);
11291 if (!ospf || !ospf->oi_running)
11292 return CMD_SUCCESS;
11293
11294 return show_ip_ospf_route_common(vty, ospf, NULL, 0);
11295 }
11296
11297
11298 DEFUN (show_ip_ospf_vrfs,
11299 show_ip_ospf_vrfs_cmd,
11300 "show ip ospf vrfs [json]",
11301 SHOW_STR
11302 IP_STR
11303 "OSPF information\n"
11304 "Show OSPF VRFs \n"
11305 JSON_STR)
11306 {
11307 bool uj = use_json(argc, argv);
11308 json_object *json = NULL;
11309 json_object *json_vrfs = NULL;
11310 struct ospf *ospf = NULL;
11311 struct listnode *node = NULL;
11312 int count = 0;
11313 static const char header[] = "Name Id RouterId ";
11314
11315 if (uj) {
11316 json = json_object_new_object();
11317 json_vrfs = json_object_new_object();
11318 }
11319
11320 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11321 json_object *json_vrf = NULL;
11322 const char *name = NULL;
11323 int64_t vrf_id_ui = 0;
11324
11325 count++;
11326
11327 if (!uj && count == 1)
11328 vty_out(vty, "%s\n", header);
11329 if (uj)
11330 json_vrf = json_object_new_object();
11331
11332 name = ospf_get_name(ospf);
11333
11334 vrf_id_ui = (ospf->vrf_id == VRF_UNKNOWN)
11335 ? -1
11336 : (int64_t)ospf->vrf_id;
11337
11338 if (uj) {
11339 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
11340 json_object_string_addf(json_vrf, "routerId", "%pI4",
11341 &ospf->router_id);
11342
11343 json_object_object_add(json_vrfs, name, json_vrf);
11344
11345 } else {
11346 vty_out(vty, "%-25s %-5d %-16pI4 \n", name,
11347 ospf->vrf_id, &ospf->router_id);
11348 }
11349 }
11350
11351 if (uj) {
11352 json_object_object_add(json, "vrfs", json_vrfs);
11353 json_object_int_add(json, "totalVrfs", count);
11354
11355 vty_json(vty, json);
11356 } else {
11357 if (count)
11358 vty_out(vty, "\nTotal number of OSPF VRFs: %d\n",
11359 count);
11360 }
11361
11362 return CMD_SUCCESS;
11363 }
11364 DEFPY (clear_ip_ospf_neighbor,
11365 clear_ip_ospf_neighbor_cmd,
11366 "clear ip ospf [(1-65535)]$instance neighbor [A.B.C.D$nbr_id]",
11367 CLEAR_STR
11368 IP_STR
11369 "OSPF information\n"
11370 "Instance ID\n"
11371 "Reset OSPF Neighbor\n"
11372 "Neighbor ID\n")
11373 {
11374 struct listnode *node;
11375 struct ospf *ospf = NULL;
11376
11377 /* If user does not specify the arguments,
11378 * instance = 0 and nbr_id = 0.0.0.0
11379 */
11380 if (instance != 0) {
11381 /* This means clear only the particular ospf process */
11382 if (instance != ospf_instance)
11383 return CMD_NOT_MY_INSTANCE;
11384 }
11385
11386 /* Clear all the ospf processes */
11387 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11388 if (!ospf->oi_running)
11389 continue;
11390
11391 if (nbr_id_str && IPV4_ADDR_SAME(&ospf->router_id, &nbr_id)) {
11392 vty_out(vty, "Self router-id is not allowed.\r\n ");
11393 return CMD_SUCCESS;
11394 }
11395
11396 ospf_neighbor_reset(ospf, nbr_id, nbr_id_str);
11397 }
11398
11399 return CMD_SUCCESS;
11400 }
11401
11402 DEFPY (clear_ip_ospf_process,
11403 clear_ip_ospf_process_cmd,
11404 "clear ip ospf [(1-65535)]$instance process",
11405 CLEAR_STR
11406 IP_STR
11407 "OSPF information\n"
11408 "Instance ID\n"
11409 "Reset OSPF Process\n")
11410 {
11411 struct listnode *node;
11412 struct ospf *ospf = NULL;
11413
11414 /* Check if instance is not passed as an argument */
11415 if (instance != 0) {
11416 /* This means clear only the particular ospf process */
11417 if (instance != ospf_instance)
11418 return CMD_NOT_MY_INSTANCE;
11419 }
11420
11421 /* Clear all the ospf processes */
11422 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11423 if (!ospf->oi_running)
11424 continue;
11425
11426 ospf_process_reset(ospf);
11427 }
11428
11429 return CMD_SUCCESS;
11430 }
11431
11432 static const char *const ospf_abr_type_str[] = {
11433 "unknown", "standard", "ibm", "cisco", "shortcut"
11434 };
11435
11436 static const char *const ospf_shortcut_mode_str[] = {
11437 "default", "enable", "disable"
11438 };
11439 static int ospf_vty_external_rt_walkcb(struct hash_bucket *bucket,
11440 void *arg)
11441 {
11442 struct external_info *ei = bucket->data;
11443 struct vty *vty = (struct vty *)arg;
11444 static unsigned int count;
11445
11446 vty_out(vty, "%-4pI4/%d, ", &ei->p.prefix, ei->p.prefixlen);
11447 count++;
11448
11449 if (count % 5 == 0)
11450 vty_out(vty, "\n");
11451
11452 if (OSPF_EXTERNAL_RT_COUNT(ei->aggr_route) == count)
11453 count = 0;
11454
11455 return HASHWALK_CONTINUE;
11456 }
11457
11458 static int ospf_json_external_rt_walkcb(struct hash_bucket *bucket,
11459 void *arg)
11460 {
11461 struct external_info *ei = bucket->data;
11462 struct json_object *json = (struct json_object *)arg;
11463 char buf[PREFIX2STR_BUFFER];
11464 char exnalbuf[20];
11465 static unsigned int count;
11466
11467 prefix2str(&ei->p, buf, sizeof(buf));
11468
11469 snprintf(exnalbuf, 20, "Exnl Addr-%d", count);
11470
11471 json_object_string_add(json, exnalbuf, buf);
11472
11473 count++;
11474
11475 if (OSPF_EXTERNAL_RT_COUNT(ei->aggr_route) == count)
11476 count = 0;
11477
11478 return HASHWALK_CONTINUE;
11479 }
11480
11481 static int ospf_show_summary_address(struct vty *vty, struct ospf *ospf,
11482 uint8_t use_vrf, json_object *json,
11483 bool uj, bool detail)
11484 {
11485 struct route_node *rn;
11486 json_object *json_vrf = NULL;
11487 int mtype = 0;
11488 int mval = 0;
11489 static char header[] =
11490 "Summary-address Metric-type Metric Tag External_Rt_count\n";
11491
11492 mtype = metric_type(ospf, 0, ospf->instance);
11493 mval = metric_value(ospf, 0, ospf->instance);
11494
11495 if (!uj)
11496 vty_out(vty, "%s\n", header);
11497
11498 if (uj) {
11499 if (use_vrf)
11500 json_vrf = json_object_new_object();
11501 else
11502 json_vrf = json;
11503 }
11504
11505 if (ospf->instance) {
11506 if (uj)
11507 json_object_int_add(json, "ospfInstance",
11508 ospf->instance);
11509 else
11510 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
11511 }
11512
11513 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
11514
11515 if (!uj) {
11516 vty_out(vty, "aggregation delay interval :%u(in seconds)\n\n",
11517 ospf->aggr_delay_interval);
11518 } else {
11519 json_object_int_add(json_vrf, "aggregationDelayInterval",
11520 ospf->aggr_delay_interval);
11521 }
11522
11523 for (rn = route_top(ospf->rt_aggr_tbl); rn; rn = route_next(rn))
11524 if (rn->info) {
11525 struct ospf_external_aggr_rt *aggr = rn->info;
11526 json_object *json_aggr = NULL;
11527 char buf[PREFIX2STR_BUFFER];
11528
11529 prefix2str(&aggr->p, buf, sizeof(buf));
11530
11531 if (uj) {
11532
11533 json_aggr = json_object_new_object();
11534
11535 json_object_object_add(json_vrf, buf,
11536 json_aggr);
11537 json_object_string_add(json_aggr,
11538 "summaryAddress", buf);
11539 json_object_string_add(
11540 json_aggr, "metricType",
11541 (mtype == EXTERNAL_METRIC_TYPE_1)
11542 ? "E1"
11543 : "E2");
11544
11545 json_object_int_add(json_aggr, "metric", mval);
11546 json_object_int_add(json_aggr, "tag",
11547 aggr->tag);
11548 json_object_int_add(
11549 json_aggr, "externalRouteCount",
11550 OSPF_EXTERNAL_RT_COUNT(aggr));
11551
11552 if (OSPF_EXTERNAL_RT_COUNT(aggr) && detail) {
11553 hash_walk(
11554 aggr->match_extnl_hash,
11555 ospf_json_external_rt_walkcb,
11556 json_aggr);
11557 }
11558
11559 } else {
11560 vty_out(vty, "%-20s", buf);
11561
11562 (mtype == EXTERNAL_METRIC_TYPE_1)
11563 ? vty_out(vty, "%-16s", "E1")
11564 : vty_out(vty, "%-16s", "E2");
11565 vty_out(vty, "%-11d", mval);
11566
11567 vty_out(vty, "%-12u", aggr->tag);
11568
11569 vty_out(vty, "%-5ld\n",
11570 OSPF_EXTERNAL_RT_COUNT(aggr));
11571
11572 if (OSPF_EXTERNAL_RT_COUNT(aggr) && detail) {
11573 vty_out(vty,
11574 "Matched External routes:\n");
11575 hash_walk(
11576 aggr->match_extnl_hash,
11577 ospf_vty_external_rt_walkcb,
11578 vty);
11579 vty_out(vty, "\n");
11580 }
11581
11582 vty_out(vty, "\n");
11583 }
11584 }
11585
11586 if (uj) {
11587 if (use_vrf)
11588 json_object_object_add(json, ospf_get_name(ospf),
11589 json_vrf);
11590 } else
11591 vty_out(vty, "\n");
11592
11593 return CMD_SUCCESS;
11594 }
11595
11596 DEFUN (show_ip_ospf_external_aggregator,
11597 show_ip_ospf_external_aggregator_cmd,
11598 "show ip ospf [vrf <NAME|all>] summary-address [detail] [json]",
11599 SHOW_STR IP_STR
11600 "OSPF information\n"
11601 VRF_CMD_HELP_STR
11602 "All VRFs\n"
11603 "Show external summary addresses\n"
11604 "Detailed information\n"
11605 JSON_STR)
11606 {
11607 char *vrf_name = NULL;
11608 bool all_vrf = false;
11609 int ret = CMD_SUCCESS;
11610 int idx_vrf = 0;
11611 int idx = 0;
11612 uint8_t use_vrf = 0;
11613 bool uj = use_json(argc, argv);
11614 struct ospf *ospf = NULL;
11615 json_object *json = NULL;
11616 struct listnode *node = NULL;
11617 int inst = 0;
11618 bool detail = false;
11619
11620 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
11621
11622 if (argv_find(argv, argc, "detail", &idx))
11623 detail = true;
11624
11625 if (uj)
11626 json = json_object_new_object();
11627
11628 /* vrf input is provided */
11629 if (vrf_name) {
11630 use_vrf = 1;
11631 if (all_vrf) {
11632 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11633 if (!ospf->oi_running)
11634 continue;
11635 ret = ospf_show_summary_address(
11636 vty, ospf, use_vrf, json, uj, detail);
11637 }
11638
11639 if (uj)
11640 vty_json(vty, json);
11641
11642 return ret;
11643 }
11644
11645 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
11646
11647 if (ospf == NULL || !ospf->oi_running) {
11648 if (uj)
11649 vty_json(vty, json);
11650 else
11651 vty_out(vty,
11652 "%% OSPF is not enabled in vrf %s\n",
11653 vrf_name);
11654
11655 return CMD_SUCCESS;
11656 }
11657 ospf_show_summary_address(vty, ospf, use_vrf, json, uj, detail);
11658
11659 } else {
11660 /* Default Vrf */
11661 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
11662 if (ospf == NULL || !ospf->oi_running) {
11663 if (uj)
11664 vty_json(vty, json);
11665 else
11666 vty_out(vty,
11667 "%% OSPF is not enabled in vrf default\n");
11668
11669 return CMD_SUCCESS;
11670 }
11671
11672 ospf_show_summary_address(vty, ospf, use_vrf, json, uj, detail);
11673 }
11674
11675 if (uj)
11676 vty_json(vty, json);
11677 return CMD_SUCCESS;
11678 }
11679
11680 static const char *const ospf_int_type_str[] = {
11681 "unknown", /* should never be used. */
11682 "point-to-point",
11683 "broadcast",
11684 "non-broadcast",
11685 "point-to-multipoint",
11686 "virtual-link", /* should never be used. */
11687 "loopback"
11688 };
11689
11690 static const char *interface_config_auth_str(struct ospf_if_params *params)
11691 {
11692 if (!OSPF_IF_PARAM_CONFIGURED(params, auth_type)
11693 || params->auth_type == OSPF_AUTH_NOTSET)
11694 return NULL;
11695
11696 /* Translation tables are not that much help
11697 * here due to syntax
11698 * of the simple option */
11699 switch (params->auth_type) {
11700
11701 case OSPF_AUTH_NULL:
11702 return " null";
11703
11704 case OSPF_AUTH_SIMPLE:
11705 return "";
11706
11707 case OSPF_AUTH_CRYPTOGRAPHIC:
11708 return " message-digest";
11709 }
11710
11711 return "";
11712 }
11713
11714 static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
11715 {
11716 struct listnode *node;
11717 struct interface *ifp;
11718 struct crypt_key *ck;
11719 struct route_node *rn = NULL;
11720 struct ospf_if_params *params;
11721 const char *auth_str;
11722 int write = 0;
11723
11724 FOR_ALL_INTERFACES (vrf, ifp) {
11725
11726 if (memcmp(ifp->name, "VLINK", 5) == 0)
11727 continue;
11728
11729 if_vty_config_start(vty, ifp);
11730
11731 if (ifp->desc)
11732 vty_out(vty, " description %s\n", ifp->desc);
11733
11734 write++;
11735
11736 params = IF_DEF_PARAMS(ifp);
11737
11738 do {
11739 /* Interface Network print. */
11740 if (OSPF_IF_PARAM_CONFIGURED(params, type)
11741 && params->type != OSPF_IFTYPE_LOOPBACK) {
11742 if (params->type != ospf_default_iftype(ifp)) {
11743 vty_out(vty, " ip ospf network %s",
11744 ospf_int_type_str
11745 [params->type]);
11746 if (params->type
11747 == OSPF_IFTYPE_POINTOPOINT
11748 && params->ptp_dmvpn)
11749 vty_out(vty, " dmvpn");
11750 if (params != IF_DEF_PARAMS(ifp) && rn)
11751 vty_out(vty, " %pI4",
11752 &rn->p.u.prefix4);
11753 vty_out(vty, "\n");
11754 }
11755 }
11756
11757 /* OSPF interface authentication print */
11758 auth_str = interface_config_auth_str(params);
11759 if (auth_str) {
11760 vty_out(vty, " ip ospf authentication%s",
11761 auth_str);
11762 if (params != IF_DEF_PARAMS(ifp) && rn)
11763 vty_out(vty, " %pI4",
11764 &rn->p.u.prefix4);
11765 vty_out(vty, "\n");
11766 }
11767
11768 /* Simple Authentication Password print. */
11769 if (OSPF_IF_PARAM_CONFIGURED(params, auth_simple)
11770 && params->auth_simple[0] != '\0') {
11771 vty_out(vty, " ip ospf authentication-key %s",
11772 params->auth_simple);
11773 if (params != IF_DEF_PARAMS(ifp) && rn)
11774 vty_out(vty, " %pI4",
11775 &rn->p.u.prefix4);
11776 vty_out(vty, "\n");
11777 }
11778
11779 /* Cryptographic Authentication Key print. */
11780 if (params && params->auth_crypt) {
11781 for (ALL_LIST_ELEMENTS_RO(params->auth_crypt,
11782 node, ck)) {
11783 vty_out(vty,
11784 " ip ospf message-digest-key %d md5 %s",
11785 ck->key_id, ck->auth_key);
11786 if (params != IF_DEF_PARAMS(ifp) && rn)
11787 vty_out(vty, " %pI4",
11788 &rn->p.u.prefix4);
11789 vty_out(vty, "\n");
11790 }
11791 }
11792
11793 /* Interface Output Cost print. */
11794 if (OSPF_IF_PARAM_CONFIGURED(params, output_cost_cmd)) {
11795 vty_out(vty, " ip ospf cost %u",
11796 params->output_cost_cmd);
11797 if (params != IF_DEF_PARAMS(ifp) && rn)
11798 vty_out(vty, " %pI4",
11799 &rn->p.u.prefix4);
11800 vty_out(vty, "\n");
11801 }
11802
11803 /* Hello Interval print. */
11804 if (OSPF_IF_PARAM_CONFIGURED(params, v_hello)
11805 && params->v_hello != OSPF_HELLO_INTERVAL_DEFAULT) {
11806 vty_out(vty, " ip ospf hello-interval %u",
11807 params->v_hello);
11808 if (params != IF_DEF_PARAMS(ifp) && rn)
11809 vty_out(vty, " %pI4",
11810 &rn->p.u.prefix4);
11811 vty_out(vty, "\n");
11812 }
11813
11814
11815 /* Router Dead Interval print. */
11816 if (OSPF_IF_PARAM_CONFIGURED(params, v_wait)
11817 && params->is_v_wait_set) {
11818 vty_out(vty, " ip ospf dead-interval ");
11819
11820 /* fast hello ? */
11821 if (OSPF_IF_PARAM_CONFIGURED(params,
11822 fast_hello))
11823 vty_out(vty,
11824 "minimal hello-multiplier %d",
11825 params->fast_hello);
11826 else
11827 vty_out(vty, "%u", params->v_wait);
11828
11829 if (params != IF_DEF_PARAMS(ifp) && rn)
11830 vty_out(vty, " %pI4",
11831 &rn->p.u.prefix4);
11832 vty_out(vty, "\n");
11833 }
11834
11835 /* Router Priority print. */
11836 if (OSPF_IF_PARAM_CONFIGURED(params, priority)
11837 && params->priority
11838 != OSPF_ROUTER_PRIORITY_DEFAULT) {
11839 vty_out(vty, " ip ospf priority %u",
11840 params->priority);
11841 if (params != IF_DEF_PARAMS(ifp) && rn)
11842 vty_out(vty, " %pI4",
11843 &rn->p.u.prefix4);
11844 vty_out(vty, "\n");
11845 }
11846
11847 /* Retransmit Interval print. */
11848 if (OSPF_IF_PARAM_CONFIGURED(params,
11849 retransmit_interval)
11850 && params->retransmit_interval
11851 != OSPF_RETRANSMIT_INTERVAL_DEFAULT) {
11852 vty_out(vty, " ip ospf retransmit-interval %u",
11853 params->retransmit_interval);
11854 if (params != IF_DEF_PARAMS(ifp) && rn)
11855 vty_out(vty, " %pI4",
11856 &rn->p.u.prefix4);
11857 vty_out(vty, "\n");
11858 }
11859
11860 /* Transmit Delay print. */
11861 if (OSPF_IF_PARAM_CONFIGURED(params, transmit_delay)
11862 && params->transmit_delay
11863 != OSPF_TRANSMIT_DELAY_DEFAULT) {
11864 vty_out(vty, " ip ospf transmit-delay %u",
11865 params->transmit_delay);
11866 if (params != IF_DEF_PARAMS(ifp) && rn)
11867 vty_out(vty, " %pI4",
11868 &rn->p.u.prefix4);
11869 vty_out(vty, "\n");
11870 }
11871
11872 /* Area print. */
11873 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
11874 if (ospf_instance)
11875 vty_out(vty, " ip ospf %d",
11876 ospf_instance);
11877 else
11878 vty_out(vty, " ip ospf");
11879
11880 char buf[INET_ADDRSTRLEN];
11881
11882 area_id2str(buf, sizeof(buf), &params->if_area,
11883 params->if_area_id_fmt);
11884 vty_out(vty, " area %s", buf);
11885 if (params != IF_DEF_PARAMS(ifp) && rn)
11886 vty_out(vty, " %pI4",
11887 &rn->p.u.prefix4);
11888 vty_out(vty, "\n");
11889 }
11890
11891 /* bfd print. */
11892 if (params && params->bfd_config)
11893 ospf_bfd_write_config(vty, params);
11894
11895 /* MTU ignore print. */
11896 if (OSPF_IF_PARAM_CONFIGURED(params, mtu_ignore)
11897 && params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) {
11898 if (params->mtu_ignore == 0)
11899 vty_out(vty, " no ip ospf mtu-ignore");
11900 else
11901 vty_out(vty, " ip ospf mtu-ignore");
11902 if (params != IF_DEF_PARAMS(ifp) && rn)
11903 vty_out(vty, " %pI4",
11904 &rn->p.u.prefix4);
11905 vty_out(vty, "\n");
11906 }
11907
11908 if (OSPF_IF_PARAM_CONFIGURED(params,
11909 passive_interface)) {
11910 vty_out(vty, " %sip ospf passive",
11911 params->passive_interface
11912 == OSPF_IF_ACTIVE
11913 ? "no "
11914 : "");
11915 if (params != IF_DEF_PARAMS(ifp) && rn)
11916 vty_out(vty, " %pI4", &rn->p.u.prefix4);
11917 vty_out(vty, "\n");
11918 }
11919
11920 /* LDP-Sync print */
11921 if (params && params->ldp_sync_info)
11922 ospf_ldp_sync_if_write_config(vty, params);
11923
11924 while (1) {
11925 if (rn == NULL)
11926 rn = route_top(IF_OIFS_PARAMS(ifp));
11927 else
11928 rn = route_next(rn);
11929
11930 if (rn == NULL)
11931 break;
11932 params = rn->info;
11933 if (params != NULL)
11934 break;
11935 }
11936 } while (rn);
11937
11938 ospf_opaque_config_write_if(vty, ifp);
11939
11940 if_vty_config_end(vty);
11941 }
11942
11943 return write;
11944 }
11945
11946 /* Configuration write function for ospfd. */
11947 static int config_write_interface(struct vty *vty)
11948 {
11949 int write = 0;
11950 struct vrf *vrf = NULL;
11951
11952 /* Display all VRF aware OSPF interface configuration */
11953 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
11954 write += config_write_interface_one(vty, vrf);
11955 }
11956
11957 return write;
11958 }
11959
11960 static int config_write_network_area(struct vty *vty, struct ospf *ospf)
11961 {
11962 struct route_node *rn;
11963 char buf[INET_ADDRSTRLEN];
11964
11965 /* `network area' print. */
11966 for (rn = route_top(ospf->networks); rn; rn = route_next(rn))
11967 if (rn->info) {
11968 struct ospf_network *n = rn->info;
11969
11970 /* Create Area ID string by specified Area ID format. */
11971 if (n->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD)
11972 inet_ntop(AF_INET, &n->area_id, buf,
11973 sizeof(buf));
11974 else
11975 snprintf(buf, sizeof(buf), "%lu",
11976 (unsigned long int)ntohl(
11977 n->area_id.s_addr));
11978
11979 /* Network print. */
11980 vty_out(vty, " network %pFX area %s\n", &rn->p, buf);
11981 }
11982
11983 return 0;
11984 }
11985
11986 static int config_write_ospf_area(struct vty *vty, struct ospf *ospf)
11987 {
11988 struct listnode *node;
11989 struct ospf_area *area;
11990 char buf[INET_ADDRSTRLEN];
11991
11992 /* Area configuration print. */
11993 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
11994 struct route_node *rn1;
11995
11996 area_id2str(buf, sizeof(buf), &area->area_id,
11997 area->area_id_fmt);
11998
11999 if (area->auth_type != OSPF_AUTH_NULL) {
12000 if (area->auth_type == OSPF_AUTH_SIMPLE)
12001 vty_out(vty, " area %s authentication\n", buf);
12002 else
12003 vty_out(vty,
12004 " area %s authentication message-digest\n",
12005 buf);
12006 }
12007
12008 if (area->shortcut_configured != OSPF_SHORTCUT_DEFAULT)
12009 vty_out(vty, " area %s shortcut %s\n", buf,
12010 ospf_shortcut_mode_str
12011 [area->shortcut_configured]);
12012
12013 if ((area->external_routing == OSPF_AREA_STUB)
12014 || (area->external_routing == OSPF_AREA_NSSA)) {
12015 if (area->external_routing == OSPF_AREA_STUB) {
12016 vty_out(vty, " area %s stub", buf);
12017 if (area->no_summary)
12018 vty_out(vty, " no-summary\n");
12019 vty_out(vty, "\n");
12020 } else if (area->external_routing == OSPF_AREA_NSSA) {
12021 vty_out(vty, " area %s nssa", buf);
12022
12023 switch (area->NSSATranslatorRole) {
12024 case OSPF_NSSA_ROLE_NEVER:
12025 vty_out(vty, " translate-never");
12026 break;
12027 case OSPF_NSSA_ROLE_ALWAYS:
12028 vty_out(vty, " translate-always");
12029 break;
12030 case OSPF_NSSA_ROLE_CANDIDATE:
12031 break;
12032 }
12033
12034 if (area->nssa_default_originate.enabled) {
12035 vty_out(vty,
12036 " default-information-originate");
12037 if (area->nssa_default_originate
12038 .metric_value != -1)
12039 vty_out(vty, " metric %d",
12040 area->nssa_default_originate
12041 .metric_value);
12042 if (area->nssa_default_originate
12043 .metric_type !=
12044 DEFAULT_METRIC_TYPE)
12045 vty_out(vty, " metric-type 1");
12046 }
12047
12048 if (area->no_summary)
12049 vty_out(vty, " no-summary");
12050 if (area->suppress_fa)
12051 vty_out(vty, " suppress-fa");
12052 vty_out(vty, "\n");
12053
12054 for (rn1 = route_top(area->nssa_ranges); rn1;
12055 rn1 = route_next(rn1)) {
12056 struct ospf_area_range *range;
12057
12058 range = rn1->info;
12059 if (!range)
12060 continue;
12061
12062 vty_out(vty, " area %s nssa range %pFX",
12063 buf, &rn1->p);
12064
12065 if (range->cost_config !=
12066 OSPF_AREA_RANGE_COST_UNSPEC)
12067 vty_out(vty, " cost %u",
12068 range->cost_config);
12069
12070 if (!CHECK_FLAG(
12071 range->flags,
12072 OSPF_AREA_RANGE_ADVERTISE))
12073 vty_out(vty, " not-advertise");
12074
12075 vty_out(vty, "\n");
12076 }
12077 }
12078
12079 if (area->default_cost != 1)
12080 vty_out(vty, " area %s default-cost %d\n", buf,
12081 area->default_cost);
12082 }
12083
12084 for (rn1 = route_top(area->ranges); rn1; rn1 = route_next(rn1))
12085 if (rn1->info) {
12086 struct ospf_area_range *range = rn1->info;
12087
12088 vty_out(vty, " area %s range %pFX", buf,
12089 &rn1->p);
12090
12091 if (range->cost_config
12092 != OSPF_AREA_RANGE_COST_UNSPEC)
12093 vty_out(vty, " cost %d",
12094 range->cost_config);
12095
12096 if (!CHECK_FLAG(range->flags,
12097 OSPF_AREA_RANGE_ADVERTISE))
12098 vty_out(vty, " not-advertise");
12099
12100 if (CHECK_FLAG(range->flags,
12101 OSPF_AREA_RANGE_SUBSTITUTE))
12102 vty_out(vty, " substitute %pI4/%d",
12103 &range->subst_addr,
12104 range->subst_masklen);
12105
12106 vty_out(vty, "\n");
12107 }
12108
12109 if (EXPORT_NAME(area))
12110 vty_out(vty, " area %s export-list %s\n", buf,
12111 EXPORT_NAME(area));
12112
12113 if (IMPORT_NAME(area))
12114 vty_out(vty, " area %s import-list %s\n", buf,
12115 IMPORT_NAME(area));
12116
12117 if (PREFIX_NAME_IN(area))
12118 vty_out(vty, " area %s filter-list prefix %s in\n", buf,
12119 PREFIX_NAME_IN(area));
12120
12121 if (PREFIX_NAME_OUT(area))
12122 vty_out(vty, " area %s filter-list prefix %s out\n",
12123 buf, PREFIX_NAME_OUT(area));
12124
12125 if (area->fr_info.configured)
12126 vty_out(vty, " area %s flood-reduction\n", buf);
12127 }
12128
12129 return 0;
12130 }
12131
12132 static int config_write_ospf_nbr_nbma(struct vty *vty, struct ospf *ospf)
12133 {
12134 struct ospf_nbr_nbma *nbr_nbma;
12135 struct route_node *rn;
12136
12137 /* Static Neighbor configuration print. */
12138 for (rn = route_top(ospf->nbr_nbma); rn; rn = route_next(rn))
12139 if ((nbr_nbma = rn->info)) {
12140 vty_out(vty, " neighbor %pI4", &nbr_nbma->addr);
12141
12142 if (nbr_nbma->priority
12143 != OSPF_NEIGHBOR_PRIORITY_DEFAULT)
12144 vty_out(vty, " priority %d",
12145 nbr_nbma->priority);
12146
12147 if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT)
12148 vty_out(vty, " poll-interval %d",
12149 nbr_nbma->v_poll);
12150
12151 vty_out(vty, "\n");
12152 }
12153
12154 return 0;
12155 }
12156
12157 static int config_write_virtual_link(struct vty *vty, struct ospf *ospf)
12158 {
12159 struct listnode *node;
12160 struct ospf_vl_data *vl_data;
12161 const char *auth_str;
12162 char buf[INET_ADDRSTRLEN];
12163
12164 /* Virtual-Link print */
12165 for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl_data)) {
12166 struct listnode *n2;
12167 struct crypt_key *ck;
12168 struct ospf_interface *oi;
12169
12170 if (vl_data != NULL) {
12171 area_id2str(buf, sizeof(buf), &vl_data->vl_area_id,
12172 vl_data->vl_area_id_fmt);
12173 oi = vl_data->vl_oi;
12174
12175 /* timers */
12176 if (OSPF_IF_PARAM(oi, v_hello)
12177 != OSPF_HELLO_INTERVAL_DEFAULT
12178 || OSPF_IF_PARAM(oi, v_wait)
12179 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
12180 || OSPF_IF_PARAM(oi, retransmit_interval)
12181 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
12182 || OSPF_IF_PARAM(oi, transmit_delay)
12183 != OSPF_TRANSMIT_DELAY_DEFAULT)
12184 vty_out(vty,
12185 " area %s virtual-link %pI4 hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n",
12186 buf, &vl_data->vl_peer,
12187 OSPF_IF_PARAM(oi, v_hello),
12188 OSPF_IF_PARAM(oi, retransmit_interval),
12189 OSPF_IF_PARAM(oi, transmit_delay),
12190 OSPF_IF_PARAM(oi, v_wait));
12191 else
12192 vty_out(vty, " area %s virtual-link %pI4\n", buf,
12193 &vl_data->vl_peer);
12194 /* Auth type */
12195 auth_str = interface_config_auth_str(
12196 IF_DEF_PARAMS(oi->ifp));
12197 if (auth_str)
12198 vty_out(vty,
12199 " area %s virtual-link %pI4 authentication%s\n",
12200 buf, &vl_data->vl_peer, auth_str);
12201 /* Auth key */
12202 if (IF_DEF_PARAMS(vl_data->vl_oi->ifp)->auth_simple[0]
12203 != '\0')
12204 vty_out(vty,
12205 " area %s virtual-link %pI4 authentication-key %s\n",
12206 buf, &vl_data->vl_peer,
12207 IF_DEF_PARAMS(vl_data->vl_oi->ifp)
12208 ->auth_simple);
12209 /* md5 keys */
12210 for (ALL_LIST_ELEMENTS_RO(
12211 IF_DEF_PARAMS(vl_data->vl_oi->ifp)
12212 ->auth_crypt,
12213 n2, ck))
12214 vty_out(vty,
12215 " area %s virtual-link %pI4 message-digest-key %d md5 %s\n",
12216 buf, &vl_data->vl_peer,
12217 ck->key_id, ck->auth_key);
12218 }
12219 }
12220
12221 return 0;
12222 }
12223
12224
12225 static int config_write_ospf_redistribute(struct vty *vty, struct ospf *ospf)
12226 {
12227 int type;
12228
12229 /* redistribute print. */
12230 for (type = 0; type < ZEBRA_ROUTE_MAX; type++) {
12231 struct list *red_list;
12232 struct listnode *node;
12233 struct ospf_redist *red;
12234
12235 red_list = ospf->redist[type];
12236 if (!red_list)
12237 continue;
12238
12239 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12240 vty_out(vty, " redistribute %s",
12241 zebra_route_string(type));
12242 if (red->instance)
12243 vty_out(vty, " %d", red->instance);
12244
12245 if (red->dmetric.value >= 0)
12246 vty_out(vty, " metric %d", red->dmetric.value);
12247
12248 if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1)
12249 vty_out(vty, " metric-type 1");
12250
12251 if (ROUTEMAP_NAME(red))
12252 vty_out(vty, " route-map %s",
12253 ROUTEMAP_NAME(red));
12254
12255 vty_out(vty, "\n");
12256 }
12257 }
12258
12259 return 0;
12260 }
12261
12262 static int ospf_cfg_write_helper_dis_rtr_walkcb(struct hash_bucket *bucket,
12263 void *arg)
12264 {
12265 struct advRtr *rtr = bucket->data;
12266 struct vty *vty = (struct vty *)arg;
12267
12268 vty_out(vty, " graceful-restart helper enable %pI4\n",
12269 &rtr->advRtrAddr);
12270 return HASHWALK_CONTINUE;
12271 }
12272
12273 static void config_write_ospf_gr(struct vty *vty, struct ospf *ospf)
12274 {
12275 if (!ospf->gr_info.restart_support)
12276 return;
12277
12278 if (ospf->gr_info.grace_period == OSPF_DFLT_GRACE_INTERVAL)
12279 vty_out(vty, " graceful-restart\n");
12280 else
12281 vty_out(vty, " graceful-restart grace-period %u\n",
12282 ospf->gr_info.grace_period);
12283 }
12284
12285 static int config_write_ospf_gr_helper(struct vty *vty, struct ospf *ospf)
12286 {
12287 if (ospf->is_helper_supported)
12288 vty_out(vty, " graceful-restart helper enable\n");
12289
12290 if (!ospf->strict_lsa_check)
12291 vty_out(vty,
12292 " no graceful-restart helper strict-lsa-checking\n");
12293
12294 if (ospf->only_planned_restart)
12295 vty_out(vty, " graceful-restart helper planned-only\n");
12296
12297 if (ospf->supported_grace_time != OSPF_MAX_GRACE_INTERVAL)
12298 vty_out(vty,
12299 " graceful-restart helper supported-grace-time %d\n",
12300 ospf->supported_grace_time);
12301
12302 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf)) {
12303 hash_walk(ospf->enable_rtr_list,
12304 ospf_cfg_write_helper_dis_rtr_walkcb, vty);
12305 }
12306 return 0;
12307 }
12308
12309 static int config_write_ospf_external_aggregator(struct vty *vty,
12310 struct ospf *ospf)
12311 {
12312 struct route_node *rn;
12313
12314 if (ospf->aggr_delay_interval != OSPF_EXTL_AGGR_DEFAULT_DELAY)
12315 vty_out(vty, " aggregation timer %u\n",
12316 ospf->aggr_delay_interval);
12317
12318 /* print 'summary-address A.B.C.D/M' */
12319 for (rn = route_top(ospf->rt_aggr_tbl); rn; rn = route_next(rn))
12320 if (rn->info) {
12321 struct ospf_external_aggr_rt *aggr = rn->info;
12322
12323 vty_out(vty, " summary-address %pI4/%d",
12324 &aggr->p.prefix, aggr->p.prefixlen);
12325 if (aggr->tag)
12326 vty_out(vty, " tag %u", aggr->tag);
12327
12328 if (CHECK_FLAG(aggr->flags,
12329 OSPF_EXTERNAL_AGGRT_NO_ADVERTISE))
12330 vty_out(vty, " no-advertise");
12331
12332 vty_out(vty, "\n");
12333 }
12334
12335 return 0;
12336 }
12337
12338 static int config_write_ospf_default_metric(struct vty *vty, struct ospf *ospf)
12339 {
12340 if (ospf->default_metric != -1)
12341 vty_out(vty, " default-metric %d\n", ospf->default_metric);
12342 return 0;
12343 }
12344
12345 static int config_write_ospf_distribute(struct vty *vty, struct ospf *ospf)
12346 {
12347 int type;
12348 struct ospf_redist *red;
12349
12350 if (ospf) {
12351 /* distribute-list print. */
12352 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
12353 if (DISTRIBUTE_NAME(ospf, type))
12354 vty_out(vty, " distribute-list %s out %s\n",
12355 DISTRIBUTE_NAME(ospf, type),
12356 zebra_route_string(type));
12357
12358 /* default-information print. */
12359 if (ospf->default_originate != DEFAULT_ORIGINATE_NONE) {
12360 vty_out(vty, " default-information originate");
12361 if (ospf->default_originate == DEFAULT_ORIGINATE_ALWAYS)
12362 vty_out(vty, " always");
12363
12364 red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0);
12365 if (red) {
12366 if (red->dmetric.value >= 0)
12367 vty_out(vty, " metric %d",
12368 red->dmetric.value);
12369
12370 if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1)
12371 vty_out(vty, " metric-type 1");
12372
12373 if (ROUTEMAP_NAME(red))
12374 vty_out(vty, " route-map %s",
12375 ROUTEMAP_NAME(red));
12376 }
12377
12378 vty_out(vty, "\n");
12379 }
12380 }
12381
12382 return 0;
12383 }
12384
12385 static int config_write_ospf_distance(struct vty *vty, struct ospf *ospf)
12386 {
12387 struct route_node *rn;
12388 struct ospf_distance *odistance;
12389
12390 if (ospf->distance_all)
12391 vty_out(vty, " distance %d\n", ospf->distance_all);
12392
12393 if (ospf->distance_intra || ospf->distance_inter
12394 || ospf->distance_external) {
12395 vty_out(vty, " distance ospf");
12396
12397 if (ospf->distance_intra)
12398 vty_out(vty, " intra-area %d", ospf->distance_intra);
12399 if (ospf->distance_inter)
12400 vty_out(vty, " inter-area %d", ospf->distance_inter);
12401 if (ospf->distance_external)
12402 vty_out(vty, " external %d", ospf->distance_external);
12403
12404 vty_out(vty, "\n");
12405 }
12406
12407 for (rn = route_top(ospf->distance_table); rn; rn = route_next(rn))
12408 if ((odistance = rn->info) != NULL) {
12409 vty_out(vty, " distance %d %pFX %s\n",
12410 odistance->distance, &rn->p,
12411 odistance->access_list ? odistance->access_list
12412 : "");
12413 }
12414 return 0;
12415 }
12416
12417 static int ospf_config_write_one(struct vty *vty, struct ospf *ospf)
12418 {
12419 int write = 0;
12420
12421 /* `router ospf' print. */
12422 if (ospf->instance && strcmp(ospf->name, VRF_DEFAULT_NAME)) {
12423 vty_out(vty, "router ospf %d vrf %s\n", ospf->instance,
12424 ospf->name);
12425 } else if (ospf->instance) {
12426 vty_out(vty, "router ospf %d\n", ospf->instance);
12427 } else if (strcmp(ospf->name, VRF_DEFAULT_NAME)) {
12428 vty_out(vty, "router ospf vrf %s\n", ospf->name);
12429 } else
12430 vty_out(vty, "router ospf\n");
12431
12432 if (!ospf->networks) {
12433 write++;
12434 return write;
12435 }
12436
12437 /* Router ID print. */
12438 if (ospf->router_id_static.s_addr != INADDR_ANY)
12439 vty_out(vty, " ospf router-id %pI4\n",
12440 &ospf->router_id_static);
12441
12442 /* zebra opaque attributes configuration. */
12443 if (CHECK_FLAG(ospf->config, OSPF_SEND_EXTRA_DATA_TO_ZEBRA))
12444 vty_out(vty, " ospf send-extra-data zebra\n");
12445
12446 /* ABR type print. */
12447 if (ospf->abr_type != OSPF_ABR_DEFAULT)
12448 vty_out(vty, " ospf abr-type %s\n",
12449 ospf_abr_type_str[ospf->abr_type]);
12450
12451 /* log-adjacency-changes flag print. */
12452 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) {
12453 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL))
12454 vty_out(vty, " log-adjacency-changes detail\n");
12455 else if (!SAVE_OSPF_LOG_ADJACENCY_CHANGES)
12456 vty_out(vty, " log-adjacency-changes\n");
12457 } else if (SAVE_OSPF_LOG_ADJACENCY_CHANGES) {
12458 vty_out(vty, " no log-adjacency-changes\n");
12459 }
12460
12461 /* RFC1583 compatibility flag print -- Compatible with CISCO
12462 * 12.1. */
12463 if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE))
12464 vty_out(vty, " compatible rfc1583\n");
12465
12466 /* auto-cost reference-bandwidth configuration. */
12467 if (ospf->ref_bandwidth != OSPF_DEFAULT_REF_BANDWIDTH) {
12468 vty_out(vty,
12469 "! Important: ensure reference bandwidth is consistent across all routers\n");
12470 vty_out(vty, " auto-cost reference-bandwidth %d\n",
12471 ospf->ref_bandwidth);
12472 }
12473
12474 /* SPF timers print. */
12475 if (ospf->spf_delay != OSPF_SPF_DELAY_DEFAULT
12476 || ospf->spf_holdtime != OSPF_SPF_HOLDTIME_DEFAULT
12477 || ospf->spf_max_holdtime != OSPF_SPF_MAX_HOLDTIME_DEFAULT)
12478 vty_out(vty, " timers throttle spf %d %d %d\n", ospf->spf_delay,
12479 ospf->spf_holdtime, ospf->spf_max_holdtime);
12480
12481 /* LSA timers print. */
12482 if (ospf->min_ls_interval != OSPF_MIN_LS_INTERVAL)
12483 vty_out(vty, " timers throttle lsa all %d\n",
12484 ospf->min_ls_interval);
12485 if (ospf->min_ls_arrival != OSPF_MIN_LS_ARRIVAL)
12486 vty_out(vty, " timers lsa min-arrival %d\n",
12487 ospf->min_ls_arrival);
12488
12489 /* Write multiplier print. */
12490 if (ospf->write_oi_count != OSPF_WRITE_INTERFACE_COUNT_DEFAULT)
12491 vty_out(vty, " ospf write-multiplier %d\n",
12492 ospf->write_oi_count);
12493
12494 if (ospf->max_multipath != MULTIPATH_NUM)
12495 vty_out(vty, " maximum-paths %d\n", ospf->max_multipath);
12496
12497 /* Max-metric router-lsa print */
12498 config_write_stub_router(vty, ospf);
12499
12500 /* SPF refresh parameters print. */
12501 if (ospf->lsa_refresh_interval != OSPF_LSA_REFRESH_INTERVAL_DEFAULT)
12502 vty_out(vty, " refresh timer %d\n", ospf->lsa_refresh_interval);
12503
12504 if (ospf->fr_configured)
12505 vty_out(vty, " flood-reduction\n");
12506
12507 if (!ospf->intf_socket_enabled)
12508 vty_out(vty, " no socket-per-interface\n");
12509
12510 /* Redistribute information print. */
12511 config_write_ospf_redistribute(vty, ospf);
12512
12513 /* Graceful Restart print */
12514 config_write_ospf_gr(vty, ospf);
12515 config_write_ospf_gr_helper(vty, ospf);
12516
12517 /* Print external route aggregation. */
12518 config_write_ospf_external_aggregator(vty, ospf);
12519
12520 /* passive-interface print. */
12521 if (ospf->passive_interface_default == OSPF_IF_PASSIVE)
12522 vty_out(vty, " passive-interface default\n");
12523
12524 /* proactive-arp print. */
12525 if (ospf->proactive_arp != OSPF_PROACTIVE_ARP_DEFAULT) {
12526 if (ospf->proactive_arp)
12527 vty_out(vty, " proactive-arp\n");
12528 else
12529 vty_out(vty, " no proactive-arp\n");
12530 }
12531
12532 /* TI-LFA print. */
12533 if (ospf->ti_lfa_enabled) {
12534 if (ospf->ti_lfa_protection_type == OSPF_TI_LFA_NODE_PROTECTION)
12535 vty_out(vty, " fast-reroute ti-lfa node-protection\n");
12536 else
12537 vty_out(vty, " fast-reroute ti-lfa\n");
12538 }
12539
12540 /* Network area print. */
12541 config_write_network_area(vty, ospf);
12542
12543 /* Area config print. */
12544 config_write_ospf_area(vty, ospf);
12545
12546 /* static neighbor print. */
12547 config_write_ospf_nbr_nbma(vty, ospf);
12548
12549 /* Virtual-Link print. */
12550 config_write_virtual_link(vty, ospf);
12551
12552 /* Default metric configuration. */
12553 config_write_ospf_default_metric(vty, ospf);
12554
12555 /* Distribute-list and default-information print. */
12556 config_write_ospf_distribute(vty, ospf);
12557
12558 /* Distance configuration. */
12559 config_write_ospf_distance(vty, ospf);
12560
12561 ospf_opaque_config_write_router(vty, ospf);
12562
12563 /* LDP-Sync print */
12564 ospf_ldp_sync_write_config(vty, ospf);
12565
12566 /* Socket buffer sizes */
12567 if (ospf->recv_sock_bufsize != OSPF_DEFAULT_SOCK_BUFSIZE) {
12568 if (ospf->send_sock_bufsize == ospf->recv_sock_bufsize)
12569 vty_out(vty, " socket buffer all %u\n",
12570 ospf->recv_sock_bufsize);
12571 else
12572 vty_out(vty, " socket buffer recv %u\n",
12573 ospf->recv_sock_bufsize);
12574 }
12575
12576 if (ospf->send_sock_bufsize != OSPF_DEFAULT_SOCK_BUFSIZE &&
12577 ospf->send_sock_bufsize != ospf->recv_sock_bufsize)
12578 vty_out(vty, " socket buffer send %u\n",
12579 ospf->send_sock_bufsize);
12580
12581
12582 vty_out(vty, "exit\n");
12583
12584 write++;
12585 return write;
12586 }
12587
12588 /* OSPF configuration write function. */
12589 static int ospf_config_write(struct vty *vty)
12590 {
12591 struct ospf *ospf;
12592 struct listnode *ospf_node = NULL;
12593 int write = 0;
12594
12595 if (listcount(om->ospf) == 0)
12596 return write;
12597
12598 for (ALL_LIST_ELEMENTS_RO(om->ospf, ospf_node, ospf)) {
12599 /* VRF Default check if it is running.
12600 * Upon daemon start, there could be default instance
12601 * in absence of 'router ospf'/oi_running is disabled. */
12602 if (ospf->vrf_id == VRF_DEFAULT && ospf->oi_running)
12603 write += ospf_config_write_one(vty, ospf);
12604 /* For Non-Default VRF simply display the configuration,
12605 * even if it is not oi_running. */
12606 else if (ospf->vrf_id != VRF_DEFAULT)
12607 write += ospf_config_write_one(vty, ospf);
12608 }
12609 return write;
12610 }
12611
12612 void ospf_vty_show_init(void)
12613 {
12614 /* "show ip ospf" commands. */
12615 install_element(VIEW_NODE, &show_ip_ospf_cmd);
12616
12617 install_element(VIEW_NODE, &show_ip_ospf_instance_cmd);
12618
12619 /* "show ip ospf database" commands. */
12620 install_element(VIEW_NODE, &show_ip_ospf_database_cmd);
12621
12622 /* "show ip ospf interface" commands. */
12623 install_element(VIEW_NODE, &show_ip_ospf_interface_cmd);
12624
12625 install_element(VIEW_NODE, &show_ip_ospf_instance_interface_cmd);
12626 /* "show ip ospf interface traffic */
12627 install_element(VIEW_NODE, &show_ip_ospf_interface_traffic_cmd);
12628
12629 /* "show ip ospf neighbor" commands. */
12630 install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_detail_cmd);
12631 install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_cmd);
12632 install_element(VIEW_NODE, &show_ip_ospf_neighbor_id_cmd);
12633 install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_all_cmd);
12634 install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_cmd);
12635 install_element(VIEW_NODE, &show_ip_ospf_neighbor_cmd);
12636 install_element(VIEW_NODE, &show_ip_ospf_neighbor_all_cmd);
12637
12638 install_element(VIEW_NODE,
12639 &show_ip_ospf_instance_neighbor_int_detail_cmd);
12640 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_int_cmd);
12641 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_id_cmd);
12642 install_element(VIEW_NODE,
12643 &show_ip_ospf_instance_neighbor_detail_all_cmd);
12644 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_detail_cmd);
12645 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_cmd);
12646 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_all_cmd);
12647
12648 /* "show ip ospf route" commands. */
12649 install_element(VIEW_NODE, &show_ip_ospf_route_cmd);
12650 install_element(VIEW_NODE, &show_ip_ospf_border_routers_cmd);
12651 install_element(VIEW_NODE, &show_ip_ospf_reachable_routers_cmd);
12652
12653 install_element(VIEW_NODE, &show_ip_ospf_instance_route_cmd);
12654 install_element(VIEW_NODE, &show_ip_ospf_instance_border_routers_cmd);
12655 install_element(VIEW_NODE,
12656 &show_ip_ospf_instance_reachable_routers_cmd);
12657
12658 /* "show ip ospf vrfs" commands. */
12659 install_element(VIEW_NODE, &show_ip_ospf_vrfs_cmd);
12660
12661 /* "show ip ospf gr-helper details" command */
12662 install_element(VIEW_NODE, &show_ip_ospf_gr_helper_cmd);
12663
12664 /* "show ip ospf summary-address" command */
12665 install_element(VIEW_NODE, &show_ip_ospf_external_aggregator_cmd);
12666 }
12667
12668 /* Initialization of OSPF interface. */
12669 static void ospf_vty_if_init(void)
12670 {
12671 /* Install interface node. */
12672 if_cmd_init(config_write_interface);
12673
12674 /* "ip ospf authentication" commands. */
12675 install_element(INTERFACE_NODE, &ip_ospf_authentication_args_addr_cmd);
12676 install_element(INTERFACE_NODE, &ip_ospf_authentication_addr_cmd);
12677 install_element(INTERFACE_NODE,
12678 &no_ip_ospf_authentication_args_addr_cmd);
12679 install_element(INTERFACE_NODE, &no_ip_ospf_authentication_addr_cmd);
12680 install_element(INTERFACE_NODE, &ip_ospf_authentication_key_addr_cmd);
12681 install_element(INTERFACE_NODE,
12682 &no_ip_ospf_authentication_key_authkey_addr_cmd);
12683 install_element(INTERFACE_NODE,
12684 &no_ospf_authentication_key_authkey_addr_cmd);
12685
12686 /* "ip ospf message-digest-key" commands. */
12687 install_element(INTERFACE_NODE, &ip_ospf_message_digest_key_cmd);
12688 install_element(INTERFACE_NODE, &no_ip_ospf_message_digest_key_cmd);
12689
12690 /* "ip ospf cost" commands. */
12691 install_element(INTERFACE_NODE, &ip_ospf_cost_cmd);
12692 install_element(INTERFACE_NODE, &no_ip_ospf_cost_cmd);
12693
12694 /* "ip ospf mtu-ignore" commands. */
12695 install_element(INTERFACE_NODE, &ip_ospf_mtu_ignore_addr_cmd);
12696 install_element(INTERFACE_NODE, &no_ip_ospf_mtu_ignore_addr_cmd);
12697
12698 /* "ip ospf dead-interval" commands. */
12699 install_element(INTERFACE_NODE, &ip_ospf_dead_interval_cmd);
12700 install_element(INTERFACE_NODE,
12701 &ip_ospf_dead_interval_minimal_addr_cmd);
12702 install_element(INTERFACE_NODE, &no_ip_ospf_dead_interval_cmd);
12703
12704 /* "ip ospf hello-interval" commands. */
12705 install_element(INTERFACE_NODE, &ip_ospf_hello_interval_cmd);
12706 install_element(INTERFACE_NODE, &no_ip_ospf_hello_interval_cmd);
12707
12708 /* "ip ospf network" commands. */
12709 install_element(INTERFACE_NODE, &ip_ospf_network_cmd);
12710 install_element(INTERFACE_NODE, &no_ip_ospf_network_cmd);
12711
12712 /* "ip ospf priority" commands. */
12713 install_element(INTERFACE_NODE, &ip_ospf_priority_cmd);
12714 install_element(INTERFACE_NODE, &no_ip_ospf_priority_cmd);
12715
12716 /* "ip ospf retransmit-interval" commands. */
12717 install_element(INTERFACE_NODE, &ip_ospf_retransmit_interval_addr_cmd);
12718 install_element(INTERFACE_NODE,
12719 &no_ip_ospf_retransmit_interval_addr_cmd);
12720
12721 /* "ip ospf transmit-delay" commands. */
12722 install_element(INTERFACE_NODE, &ip_ospf_transmit_delay_addr_cmd);
12723 install_element(INTERFACE_NODE, &no_ip_ospf_transmit_delay_addr_cmd);
12724
12725 /* "ip ospf area" commands. */
12726 install_element(INTERFACE_NODE, &ip_ospf_area_cmd);
12727 install_element(INTERFACE_NODE, &no_ip_ospf_area_cmd);
12728
12729 /* "ip ospf passive" commands. */
12730 install_element(INTERFACE_NODE, &ip_ospf_passive_cmd);
12731 install_element(INTERFACE_NODE, &no_ip_ospf_passive_cmd);
12732
12733 /* These commands are compatibitliy for previous version. */
12734 install_element(INTERFACE_NODE, &ospf_authentication_key_cmd);
12735 install_element(INTERFACE_NODE, &ospf_message_digest_key_cmd);
12736 install_element(INTERFACE_NODE, &no_ospf_message_digest_key_cmd);
12737 install_element(INTERFACE_NODE, &ospf_dead_interval_cmd);
12738 install_element(INTERFACE_NODE, &no_ospf_dead_interval_cmd);
12739 install_element(INTERFACE_NODE, &ospf_hello_interval_cmd);
12740 install_element(INTERFACE_NODE, &no_ospf_hello_interval_cmd);
12741 install_element(INTERFACE_NODE, &ospf_cost_cmd);
12742 install_element(INTERFACE_NODE, &no_ospf_cost_cmd);
12743 install_element(INTERFACE_NODE, &ospf_network_cmd);
12744 install_element(INTERFACE_NODE, &no_ospf_network_cmd);
12745 install_element(INTERFACE_NODE, &ospf_priority_cmd);
12746 install_element(INTERFACE_NODE, &no_ospf_priority_cmd);
12747 install_element(INTERFACE_NODE, &ospf_retransmit_interval_cmd);
12748 install_element(INTERFACE_NODE, &no_ospf_retransmit_interval_cmd);
12749 install_element(INTERFACE_NODE, &ospf_transmit_delay_cmd);
12750 install_element(INTERFACE_NODE, &no_ospf_transmit_delay_cmd);
12751 }
12752
12753 static void ospf_vty_zebra_init(void)
12754 {
12755 install_element(OSPF_NODE, &ospf_redistribute_source_cmd);
12756 install_element(OSPF_NODE, &no_ospf_redistribute_source_cmd);
12757 install_element(OSPF_NODE, &ospf_redistribute_instance_source_cmd);
12758 install_element(OSPF_NODE, &no_ospf_redistribute_instance_source_cmd);
12759
12760 install_element(OSPF_NODE, &ospf_distribute_list_out_cmd);
12761 install_element(OSPF_NODE, &no_ospf_distribute_list_out_cmd);
12762
12763 install_element(OSPF_NODE, &ospf_default_information_originate_cmd);
12764 install_element(OSPF_NODE, &no_ospf_default_information_originate_cmd);
12765
12766 install_element(OSPF_NODE, &ospf_default_metric_cmd);
12767 install_element(OSPF_NODE, &no_ospf_default_metric_cmd);
12768
12769 install_element(OSPF_NODE, &ospf_distance_cmd);
12770 install_element(OSPF_NODE, &no_ospf_distance_cmd);
12771 install_element(OSPF_NODE, &no_ospf_distance_ospf_cmd);
12772 install_element(OSPF_NODE, &ospf_distance_ospf_cmd);
12773
12774 /*Ospf garcefull restart helper configurations */
12775 install_element(OSPF_NODE, &ospf_gr_helper_enable_cmd);
12776 install_element(OSPF_NODE, &no_ospf_gr_helper_enable_cmd);
12777 install_element(OSPF_NODE, &ospf_gr_helper_enable_lsacheck_cmd);
12778 install_element(OSPF_NODE, &no_ospf_gr_helper_enable_lsacheck_cmd);
12779 install_element(OSPF_NODE, &ospf_gr_helper_supported_grace_time_cmd);
12780 install_element(OSPF_NODE, &no_ospf_gr_helper_supported_grace_time_cmd);
12781 install_element(OSPF_NODE, &ospf_gr_helper_planned_only_cmd);
12782 install_element(OSPF_NODE, &no_ospf_gr_helper_planned_only_cmd);
12783
12784 /* External LSA summarisation config commands.*/
12785 install_element(OSPF_NODE, &ospf_external_route_aggregation_cmd);
12786 install_element(OSPF_NODE, &no_ospf_external_route_aggregation_cmd);
12787 install_element(OSPF_NODE,
12788 &ospf_external_route_aggregation_no_adrvertise_cmd);
12789 install_element(OSPF_NODE,
12790 &no_ospf_external_route_aggregation_no_adrvertise_cmd);
12791 install_element(OSPF_NODE, &ospf_route_aggregation_timer_cmd);
12792 install_element(OSPF_NODE, &no_ospf_route_aggregation_timer_cmd);
12793 }
12794
12795 static int ospf_config_write(struct vty *vty);
12796 static struct cmd_node ospf_node = {
12797 .name = "ospf",
12798 .node = OSPF_NODE,
12799 .parent_node = CONFIG_NODE,
12800 .prompt = "%s(config-router)# ",
12801 .config_write = ospf_config_write,
12802 };
12803
12804 static void ospf_interface_clear(struct interface *ifp)
12805 {
12806 if (!if_is_operative(ifp))
12807 return;
12808
12809 if (IS_DEBUG_OSPF(ism, ISM_EVENTS))
12810 zlog_debug("ISM[%s]: clear by reset", ifp->name);
12811
12812 ospf_if_reset(ifp);
12813 }
12814
12815 DEFUN (clear_ip_ospf_interface,
12816 clear_ip_ospf_interface_cmd,
12817 "clear ip ospf [vrf NAME] interface [IFNAME]",
12818 CLEAR_STR
12819 IP_STR
12820 "OSPF information\n"
12821 VRF_CMD_HELP_STR
12822 "Interface information\n"
12823 "Interface name\n")
12824 {
12825 int idx_ifname = 0;
12826 int idx_vrf = 0;
12827 struct interface *ifp;
12828 struct listnode *node;
12829 struct ospf *ospf = NULL;
12830 char *vrf_name = NULL;
12831 vrf_id_t vrf_id = VRF_DEFAULT;
12832 struct vrf *vrf = NULL;
12833
12834 if (argv_find(argv, argc, "vrf", &idx_vrf))
12835 vrf_name = argv[idx_vrf + 1]->arg;
12836 if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME))
12837 vrf_name = NULL;
12838 if (vrf_name) {
12839 vrf = vrf_lookup_by_name(vrf_name);
12840 if (vrf)
12841 vrf_id = vrf->vrf_id;
12842 }
12843 if (!argv_find(argv, argc, "IFNAME", &idx_ifname)) {
12844 /* Clear all the ospfv2 interfaces. */
12845 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
12846 if (vrf_id != ospf->vrf_id)
12847 continue;
12848 if (!vrf)
12849 vrf = vrf_lookup_by_id(ospf->vrf_id);
12850 FOR_ALL_INTERFACES (vrf, ifp)
12851 ospf_interface_clear(ifp);
12852 }
12853 } else {
12854 /* Interface name is specified. */
12855 ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id);
12856 if (ifp == NULL)
12857 vty_out(vty, "No such interface name\n");
12858 else
12859 ospf_interface_clear(ifp);
12860 }
12861
12862 return CMD_SUCCESS;
12863 }
12864
12865 DEFPY_HIDDEN(ospf_lsa_refresh_timer, ospf_lsa_refresh_timer_cmd,
12866 "[no$no] ospf lsa-refresh [(120-1800)]$value",
12867 NO_STR OSPF_STR
12868 "OSPF lsa refresh timer\n"
12869 "timer value in seconds\n")
12870 {
12871 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf)
12872
12873 if (no)
12874 ospf->lsa_refresh_timer = OSPF_LS_REFRESH_TIME;
12875 else
12876 ospf->lsa_refresh_timer = value;
12877
12878 return CMD_SUCCESS;
12879 }
12880
12881 DEFPY_HIDDEN(ospf_maxage_delay_timer, ospf_maxage_delay_timer_cmd,
12882 "[no$no] ospf maxage-delay [(0-60)]$value",
12883 NO_STR OSPF_STR
12884 "OSPF lsa maxage delay timer\n"
12885 "timer value in seconds\n")
12886 {
12887 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf)
12888
12889 if (no)
12890 ospf->maxage_delay = OSPF_LSA_MAXAGE_REMOVE_DELAY_DEFAULT;
12891 else
12892 ospf->maxage_delay = value;
12893
12894 EVENT_OFF(ospf->t_maxage);
12895 OSPF_TIMER_ON(ospf->t_maxage, ospf_maxage_lsa_remover,
12896 ospf->maxage_delay);
12897
12898 return CMD_SUCCESS;
12899 }
12900
12901 /*
12902 * ------------------------------------------------------------------------*
12903 * Following is (vty) configuration functions for flood-reduction handling.
12904 * ------------------------------------------------------------------------
12905 */
12906
12907 DEFPY(flood_reduction, flood_reduction_cmd, "flood-reduction",
12908 "flood reduction feature\n")
12909 {
12910 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf)
12911 struct ospf_area *area;
12912 struct listnode *node;
12913
12914 /* Turn on the Flood Reduction feature for the router. */
12915 if (!ospf->fr_configured) {
12916 ospf->fr_configured = true;
12917 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT,
12918 "Flood Reduction: OFF -> ON");
12919 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
12920 if (area) {
12921 ospf_area_update_fr_state(area);
12922 ospf_refresh_area_self_lsas(area);
12923 }
12924 }
12925 }
12926
12927 return CMD_SUCCESS;
12928 }
12929
12930 DEFPY(flood_reduction_area, flood_reduction_area_cmd,
12931 "area <A.B.C.D|(0-4294967295)> flood-reduction",
12932 "OSPF area parameters\n"
12933 "OSPF area ID in IP address format\n"
12934 "OSPF area ID as a decimal value\n"
12935 "Enable flood reduction for area\n")
12936 {
12937 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf)
12938 struct ospf_area *oa;
12939 int idx = 1;
12940 int format;
12941 int ret;
12942 const char *areaid;
12943 struct in_addr area_id;
12944
12945 areaid = argv[idx]->arg;
12946
12947 ret = str2area_id(areaid, &area_id, &format);
12948 if (ret < 0) {
12949 vty_out(vty, "Please specify area by A.B.C.D|<0-4294967295>\n");
12950 return CMD_WARNING_CONFIG_FAILED;
12951 }
12952
12953 oa = ospf_area_lookup_by_area_id(ospf, area_id);
12954 if (!oa) {
12955 vty_out(vty, "OSPF area ID not present\n");
12956 return CMD_WARNING_CONFIG_FAILED;
12957 }
12958
12959 /* Turn on the Flood Reduction feature for the area. */
12960 if (!oa->fr_info.configured) {
12961 oa->fr_info.configured = true;
12962 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT,
12963 "Flood Reduction area %pI4 : OFF -> ON",
12964 &oa->area_id);
12965 ospf_area_update_fr_state(oa);
12966 ospf_refresh_area_self_lsas(oa);
12967 }
12968
12969 return CMD_SUCCESS;
12970 }
12971
12972 DEFPY(no_flood_reduction, no_flood_reduction_cmd, "no flood-reduction",
12973 NO_STR "flood reduction feature\n")
12974 {
12975 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf)
12976 struct listnode *node;
12977 struct ospf_area *area;
12978
12979 /* Turn off the Flood Reduction feature for the router. */
12980 if (ospf->fr_configured) {
12981 ospf->fr_configured = false;
12982 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT,
12983 "Flood Reduction: ON -> OFF");
12984 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
12985 if (area) {
12986 ospf_area_update_fr_state(area);
12987 ospf_refresh_area_self_lsas(area);
12988 }
12989 }
12990 }
12991
12992 return CMD_SUCCESS;
12993 }
12994
12995 DEFPY(no_flood_reduction_area, no_flood_reduction_area_cmd,
12996 "no area <A.B.C.D|(0-4294967295)> flood-reduction",
12997 NO_STR
12998 "OSPF area parameters\n"
12999 "OSPF area ID in IP address format\n"
13000 "OSPF area ID as a decimal value\n"
13001 "Disable flood reduction for area\n")
13002 {
13003 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf)
13004 struct ospf_area *oa;
13005 int idx = 2;
13006 int format;
13007 int ret;
13008 const char *areaid;
13009 struct in_addr area_id;
13010
13011 areaid = argv[idx]->arg;
13012
13013 ret = str2area_id(areaid, &area_id, &format);
13014 if (ret < 0) {
13015 vty_out(vty, "Please specify area by A.B.C.D|<0-4294967295>\n");
13016 return CMD_WARNING_CONFIG_FAILED;
13017 }
13018
13019 oa = ospf_area_lookup_by_area_id(ospf, area_id);
13020 if (!oa) {
13021 vty_out(vty, "OSPF area ID not present\n");
13022 return CMD_WARNING_CONFIG_FAILED;
13023 }
13024
13025 /* Turn off the Flood Reduction feature for the area. */
13026 if (oa->fr_info.configured) {
13027 oa->fr_info.configured = false;
13028 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT,
13029 "Flood Reduction area %pI4 : ON -> OFF",
13030 &oa->area_id);
13031 ospf_area_update_fr_state(oa);
13032 ospf_refresh_area_self_lsas(oa);
13033 }
13034
13035 return CMD_SUCCESS;
13036 }
13037
13038 DEFPY(ospf_socket_bufsizes,
13039 ospf_socket_bufsizes_cmd,
13040 "[no] socket buffer <send$send_val | recv$recv_val | all$all_val> \
13041 ![(1-4000000000)$bufsize]",
13042 NO_STR
13043 "Socket parameters\n"
13044 "Buffer size configuration\n"
13045 "Send buffer size\n"
13046 "Receive buffer size\n"
13047 "Both send and receive buffer sizes\n"
13048 "Buffer size, in bytes\n")
13049 {
13050 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
13051 uint32_t recvsz, sendsz;
13052
13053 if (no)
13054 bufsize = OSPF_DEFAULT_SOCK_BUFSIZE;
13055
13056 if (all_val) {
13057 recvsz = bufsize;
13058 sendsz = bufsize;
13059 } else if (send_val) {
13060 sendsz = bufsize;
13061 recvsz = ospf->recv_sock_bufsize;
13062 } else if (recv_val) {
13063 recvsz = bufsize;
13064 sendsz = ospf->send_sock_bufsize;
13065 } else
13066 return CMD_SUCCESS;
13067
13068 /* React to a change by modifying existing sockets */
13069 ospf_update_bufsize(ospf, recvsz, sendsz);
13070
13071 return CMD_SUCCESS;
13072 }
13073
13074 DEFPY (per_intf_socket,
13075 per_intf_socket_cmd,
13076 "[no] socket-per-interface",
13077 NO_STR
13078 "Use write socket per interface\n")
13079 {
13080 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
13081 struct listnode *node;
13082 struct ospf_interface *oi;
13083
13084 if (no) {
13085 if (ospf->intf_socket_enabled) {
13086 ospf->intf_socket_enabled = false;
13087
13088 /* Iterate and close any sockets */
13089 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi))
13090 ospf_ifp_sock_close(oi->ifp);
13091 }
13092 } else if (!ospf->intf_socket_enabled) {
13093 ospf->intf_socket_enabled = true;
13094
13095 /* Iterate and open sockets */
13096 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi))
13097 ospf_ifp_sock_init(oi->ifp);
13098 }
13099
13100 return CMD_SUCCESS;
13101 }
13102
13103 void ospf_vty_clear_init(void)
13104 {
13105 install_element(ENABLE_NODE, &clear_ip_ospf_interface_cmd);
13106 install_element(ENABLE_NODE, &clear_ip_ospf_process_cmd);
13107 install_element(ENABLE_NODE, &clear_ip_ospf_neighbor_cmd);
13108 }
13109
13110
13111 /* Install OSPF related vty commands. */
13112 void ospf_vty_init(void)
13113 {
13114 /* Install ospf top node. */
13115 install_node(&ospf_node);
13116
13117 /* "router ospf" commands. */
13118 install_element(CONFIG_NODE, &router_ospf_cmd);
13119 install_element(CONFIG_NODE, &no_router_ospf_cmd);
13120
13121
13122 install_default(OSPF_NODE);
13123
13124 /* "ospf router-id" commands. */
13125 install_element(OSPF_NODE, &ospf_router_id_cmd);
13126 install_element(OSPF_NODE, &ospf_router_id_old_cmd);
13127 install_element(OSPF_NODE, &no_ospf_router_id_cmd);
13128
13129 /* "passive-interface" commands. */
13130 install_element(OSPF_NODE, &ospf_passive_interface_default_cmd);
13131 install_element(OSPF_NODE, &ospf_passive_interface_addr_cmd);
13132 install_element(OSPF_NODE, &no_ospf_passive_interface_default_cmd);
13133 install_element(OSPF_NODE, &no_ospf_passive_interface_addr_cmd);
13134
13135 /* "ospf abr-type" commands. */
13136 install_element(OSPF_NODE, &ospf_abr_type_cmd);
13137 install_element(OSPF_NODE, &no_ospf_abr_type_cmd);
13138
13139 /* "ospf log-adjacency-changes" commands. */
13140 install_element(OSPF_NODE, &ospf_log_adjacency_changes_cmd);
13141 install_element(OSPF_NODE, &ospf_log_adjacency_changes_detail_cmd);
13142 install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_cmd);
13143 install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_detail_cmd);
13144
13145 /* "ospf rfc1583-compatible" commands. */
13146 install_element(OSPF_NODE, &ospf_compatible_rfc1583_cmd);
13147 install_element(OSPF_NODE, &no_ospf_compatible_rfc1583_cmd);
13148 install_element(OSPF_NODE, &ospf_rfc1583_flag_cmd);
13149 install_element(OSPF_NODE, &no_ospf_rfc1583_flag_cmd);
13150
13151 /* "ospf send-extra-data zebra" commands. */
13152 install_element(OSPF_NODE, &ospf_send_extra_data_cmd);
13153
13154 /* "network area" commands. */
13155 install_element(OSPF_NODE, &ospf_network_area_cmd);
13156 install_element(OSPF_NODE, &no_ospf_network_area_cmd);
13157
13158 /* "area authentication" commands. */
13159 install_element(OSPF_NODE,
13160 &ospf_area_authentication_message_digest_cmd);
13161 install_element(OSPF_NODE, &ospf_area_authentication_cmd);
13162 install_element(OSPF_NODE, &no_ospf_area_authentication_cmd);
13163
13164 /* "area range" commands. */
13165 install_element(OSPF_NODE, &ospf_area_range_cmd);
13166 install_element(OSPF_NODE, &ospf_area_range_cost_cmd);
13167 install_element(OSPF_NODE, &ospf_area_range_not_advertise_cmd);
13168 install_element(OSPF_NODE, &no_ospf_area_range_cmd);
13169 install_element(OSPF_NODE, &no_ospf_area_range_substitute_cmd);
13170
13171 /* "area virtual-link" commands. */
13172 install_element(OSPF_NODE, &ospf_area_vlink_cmd);
13173 install_element(OSPF_NODE, &ospf_area_vlink_intervals_cmd);
13174 install_element(OSPF_NODE, &no_ospf_area_vlink_cmd);
13175 install_element(OSPF_NODE, &no_ospf_area_vlink_intervals_cmd);
13176
13177
13178 /* "area stub" commands. */
13179 install_element(OSPF_NODE, &ospf_area_stub_no_summary_cmd);
13180 install_element(OSPF_NODE, &ospf_area_stub_cmd);
13181 install_element(OSPF_NODE, &no_ospf_area_stub_no_summary_cmd);
13182 install_element(OSPF_NODE, &no_ospf_area_stub_cmd);
13183
13184 /* "area nssa" commands. */
13185 install_element(OSPF_NODE, &ospf_area_nssa_cmd);
13186 install_element(OSPF_NODE, &no_ospf_area_nssa_cmd);
13187 install_element(OSPF_NODE, &ospf_area_nssa_range_cmd);
13188 install_element(OSPF_NODE, &no_ospf_area_nssa_range_cmd);
13189
13190 install_element(OSPF_NODE, &ospf_area_default_cost_cmd);
13191 install_element(OSPF_NODE, &no_ospf_area_default_cost_cmd);
13192
13193 install_element(OSPF_NODE, &ospf_area_shortcut_cmd);
13194 install_element(OSPF_NODE, &no_ospf_area_shortcut_cmd);
13195
13196 install_element(OSPF_NODE, &ospf_area_export_list_cmd);
13197 install_element(OSPF_NODE, &no_ospf_area_export_list_cmd);
13198
13199 install_element(OSPF_NODE, &ospf_area_filter_list_cmd);
13200 install_element(OSPF_NODE, &no_ospf_area_filter_list_cmd);
13201
13202 install_element(OSPF_NODE, &ospf_area_import_list_cmd);
13203 install_element(OSPF_NODE, &no_ospf_area_import_list_cmd);
13204
13205 /* SPF timer commands */
13206 install_element(OSPF_NODE, &ospf_timers_throttle_spf_cmd);
13207 install_element(OSPF_NODE, &no_ospf_timers_throttle_spf_cmd);
13208
13209 /* LSA timers commands */
13210 install_element(OSPF_NODE, &ospf_timers_min_ls_interval_cmd);
13211 install_element(OSPF_NODE, &no_ospf_timers_min_ls_interval_cmd);
13212 install_element(OSPF_NODE, &ospf_timers_lsa_min_arrival_cmd);
13213 install_element(OSPF_NODE, &no_ospf_timers_lsa_min_arrival_cmd);
13214
13215 /* refresh timer commands */
13216 install_element(OSPF_NODE, &ospf_refresh_timer_cmd);
13217 install_element(OSPF_NODE, &no_ospf_refresh_timer_val_cmd);
13218
13219 /* max-metric commands */
13220 install_element(OSPF_NODE, &ospf_max_metric_router_lsa_admin_cmd);
13221 install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_admin_cmd);
13222 install_element(OSPF_NODE, &ospf_max_metric_router_lsa_startup_cmd);
13223 install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_startup_cmd);
13224 install_element(OSPF_NODE, &ospf_max_metric_router_lsa_shutdown_cmd);
13225 install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_shutdown_cmd);
13226
13227 /* reference bandwidth commands */
13228 install_element(OSPF_NODE, &ospf_auto_cost_reference_bandwidth_cmd);
13229 install_element(OSPF_NODE, &no_ospf_auto_cost_reference_bandwidth_cmd);
13230
13231 /* "neighbor" commands. */
13232 install_element(OSPF_NODE, &ospf_neighbor_cmd);
13233 install_element(OSPF_NODE, &ospf_neighbor_poll_interval_cmd);
13234 install_element(OSPF_NODE, &no_ospf_neighbor_cmd);
13235 install_element(OSPF_NODE, &no_ospf_neighbor_poll_cmd);
13236
13237 /* write multiplier commands */
13238 install_element(OSPF_NODE, &ospf_write_multiplier_cmd);
13239 install_element(OSPF_NODE, &write_multiplier_cmd);
13240 install_element(OSPF_NODE, &no_ospf_write_multiplier_cmd);
13241 install_element(OSPF_NODE, &no_write_multiplier_cmd);
13242
13243 /* "proactive-arp" commands. */
13244 install_element(OSPF_NODE, &ospf_proactive_arp_cmd);
13245 install_element(OSPF_NODE, &no_ospf_proactive_arp_cmd);
13246
13247 /* TI-LFA commands */
13248 install_element(OSPF_NODE, &ospf_ti_lfa_cmd);
13249 install_element(OSPF_NODE, &no_ospf_ti_lfa_cmd);
13250
13251 /* Max path configurations */
13252 install_element(OSPF_NODE, &ospf_max_multipath_cmd);
13253 install_element(OSPF_NODE, &no_ospf_max_multipath_cmd);
13254
13255 vrf_cmd_init(NULL);
13256
13257 install_element(OSPF_NODE, &ospf_lsa_refresh_timer_cmd);
13258 install_element(OSPF_NODE, &ospf_maxage_delay_timer_cmd);
13259
13260 /* Flood Reduction commands */
13261 install_element(OSPF_NODE, &flood_reduction_cmd);
13262 install_element(OSPF_NODE, &no_flood_reduction_cmd);
13263 install_element(OSPF_NODE, &flood_reduction_area_cmd);
13264 install_element(OSPF_NODE, &no_flood_reduction_area_cmd);
13265
13266 install_element(OSPF_NODE, &ospf_socket_bufsizes_cmd);
13267 install_element(OSPF_NODE, &per_intf_socket_cmd);
13268
13269 /* Init interface related vty commands. */
13270 ospf_vty_if_init();
13271
13272 /* Init zebra related vty commands. */
13273 ospf_vty_zebra_init();
13274 }