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