]> git.proxmox.com Git - mirror_frr.git/blob - ospfd/ospf_vty.c
lib: Remove tests for ipv[4|6]_prefix_table
[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 struct route_node *rn;
6804 struct ospf_lsa *lsa;
6805 json_object *json_lsa = NULL;
6806
6807 for (rn = route_top(rt); rn; rn = route_next(rn))
6808 if ((lsa = rn->info)) {
6809 if (IPV4_ADDR_SAME(adv_router,
6810 &lsa->data->adv_router)) {
6811 if (CHECK_FLAG(lsa->flags, OSPF_LSA_LOCAL_XLT))
6812 continue;
6813 if (json) {
6814 json_lsa = json_object_new_object();
6815 json_object_array_add(json, json_lsa);
6816 }
6817
6818 if (show_function[lsa->data->type] != NULL)
6819 show_function[lsa->data->type](
6820 vty, lsa, json_lsa);
6821 }
6822 }
6823 }
6824
6825 /* Show detail LSA information. */
6826 static void show_lsa_detail_adv_router(struct vty *vty, struct ospf *ospf,
6827 int type, struct in_addr *adv_router,
6828 json_object *json)
6829 {
6830 struct listnode *node;
6831 struct ospf_area *area;
6832 char buf[PREFIX_STRLEN];
6833 json_object *json_lsa_type = NULL;
6834 json_object *json_areas = NULL;
6835 json_object *json_lsa_array = NULL;
6836
6837 if (json)
6838 json_lsa_type = json_object_new_object();
6839
6840 switch (type) {
6841 case OSPF_AS_EXTERNAL_LSA:
6842 case OSPF_OPAQUE_AS_LSA:
6843 if (!json)
6844 vty_out(vty, " %s \n\n",
6845 show_database_desc[type]);
6846 else
6847 json_lsa_array = json_object_new_array();
6848
6849 show_lsa_detail_adv_router_proc(vty, AS_LSDB(ospf, type),
6850 adv_router, json_lsa_array);
6851 if (json)
6852 json_object_object_add(json,
6853 show_database_desc_json[type],
6854 json_lsa_array);
6855 break;
6856 default:
6857 if (json)
6858 json_areas = json_object_new_object();
6859
6860 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
6861 if (!json) {
6862 vty_out(vty,
6863 "\n %s (Area %s)\n\n",
6864 show_database_desc[type],
6865 ospf_area_desc_string(area));
6866 } else {
6867 json_lsa_array = json_object_new_array();
6868 json_object_object_add(
6869 json_areas,
6870 inet_ntop(AF_INET, &area->area_id, buf,
6871 sizeof(buf)),
6872 json_lsa_array);
6873 }
6874
6875 show_lsa_detail_adv_router_proc(
6876 vty, AREA_LSDB(area, type), adv_router,
6877 json_lsa_array);
6878 }
6879
6880 if (json) {
6881 json_object_object_add(json_lsa_type, "areas",
6882 json_areas);
6883 json_object_object_add(json,
6884 show_database_desc_json[type],
6885 json_lsa_type);
6886 }
6887 break;
6888 }
6889 }
6890
6891 void show_ip_ospf_database_summary(struct vty *vty, struct ospf *ospf, int self,
6892 json_object *json)
6893 {
6894 struct ospf_lsa *lsa;
6895 struct route_node *rn;
6896 struct ospf_area *area;
6897 struct listnode *node;
6898 char buf[PREFIX_STRLEN];
6899 json_object *json_areas = NULL;
6900 json_object *json_area = NULL;
6901 json_object *json_lsa = NULL;
6902 int type;
6903 json_object *json_lsa_array = NULL;
6904 uint32_t count;
6905
6906 if (json)
6907 json_areas = json_object_new_object();
6908
6909 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
6910 if (json)
6911 json_area = json_object_new_object();
6912
6913 for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) {
6914 count = 0;
6915 switch (type) {
6916 case OSPF_AS_EXTERNAL_LSA:
6917 case OSPF_OPAQUE_AS_LSA:
6918 continue;
6919 default:
6920 break;
6921 }
6922 if (ospf_lsdb_count_self(area->lsdb, type) > 0
6923 || (!self
6924 && ospf_lsdb_count(area->lsdb, type) > 0)) {
6925
6926 if (!json) {
6927 vty_out(vty,
6928 " %s (Area %s)\n\n",
6929 show_database_desc[type],
6930 ospf_area_desc_string(area));
6931 vty_out(vty, "%s\n",
6932 show_database_header[type]);
6933 } else {
6934 json_lsa_array =
6935 json_object_new_array();
6936 json_object_object_add(
6937 json_area,
6938 show_database_desc_json[type],
6939 json_lsa_array);
6940 }
6941
6942 LSDB_LOOP (AREA_LSDB(area, type), rn, lsa) {
6943 if (json) {
6944 json_lsa =
6945 json_object_new_object();
6946 json_object_array_add(
6947 json_lsa_array,
6948 json_lsa);
6949 }
6950
6951 count += show_lsa_summary(
6952 vty, lsa, self, json_lsa);
6953 }
6954
6955 if (!json)
6956 vty_out(vty, "\n");
6957 else
6958 json_object_int_add(
6959 json_area,
6960
6961 show_database_desc_count_json
6962 [type],
6963 count);
6964 }
6965 }
6966 if (json)
6967 json_object_object_add(json_areas,
6968 inet_ntop(AF_INET,
6969 &area->area_id,
6970 buf, sizeof(buf)),
6971 json_area);
6972 }
6973
6974 if (json)
6975 json_object_object_add(json, "areas", json_areas);
6976
6977 for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) {
6978 count = 0;
6979 switch (type) {
6980 case OSPF_AS_EXTERNAL_LSA:
6981 case OSPF_OPAQUE_AS_LSA:
6982 break;
6983 default:
6984 continue;
6985 }
6986 if (ospf_lsdb_count_self(ospf->lsdb, type)
6987 || (!self && ospf_lsdb_count(ospf->lsdb, type))) {
6988 if (!json) {
6989 vty_out(vty, " %s\n\n",
6990 show_database_desc[type]);
6991 vty_out(vty, "%s\n",
6992 show_database_header[type]);
6993 } else {
6994 json_lsa_array = json_object_new_array();
6995 json_object_object_add(
6996 json, show_database_desc_json[type],
6997 json_lsa_array);
6998 }
6999
7000 LSDB_LOOP (AS_LSDB(ospf, type), rn, lsa) {
7001 if (json) {
7002 json_lsa = json_object_new_object();
7003 json_object_array_add(json_lsa_array,
7004 json_lsa);
7005 }
7006
7007 count += show_lsa_summary(vty, lsa, self,
7008 json_lsa);
7009 }
7010
7011 if (!json)
7012 vty_out(vty, "\n");
7013 else
7014 json_object_int_add(
7015 json,
7016 show_database_desc_count_json[type],
7017 count);
7018 }
7019 }
7020
7021 if (!json)
7022 vty_out(vty, "\n");
7023 }
7024
7025 static void show_ip_ospf_database_maxage(struct vty *vty, struct ospf *ospf,
7026 json_object *json)
7027 {
7028 struct route_node *rn;
7029 char buf[PREFIX_STRLEN];
7030 json_object *json_maxage = NULL;
7031
7032 if (!json)
7033 vty_out(vty, "\n MaxAge Link States:\n\n");
7034 else
7035 json_maxage = json_object_new_object();
7036
7037 for (rn = route_top(ospf->maxage_lsa); rn; rn = route_next(rn)) {
7038 struct ospf_lsa *lsa;
7039 json_object *json_lsa = NULL;
7040
7041 if ((lsa = rn->info) != NULL) {
7042 if (!json) {
7043 vty_out(vty, "Link type: %d\n",
7044 lsa->data->type);
7045 vty_out(vty, "Link State ID: %pI4\n",
7046 &lsa->data->id);
7047 vty_out(vty, "Advertising Router: %pI4\n",
7048 &lsa->data->adv_router);
7049 vty_out(vty, "LSA lock count: %d\n", lsa->lock);
7050 vty_out(vty, "\n");
7051 } else {
7052 json_lsa = json_object_new_object();
7053 json_object_int_add(json_lsa, "linkType",
7054 lsa->data->type);
7055 json_object_string_addf(json_lsa, "linkStateId",
7056 "%pI4", &lsa->data->id);
7057 json_object_string_addf(
7058 json_lsa, "advertisingRouter", "%pI4",
7059 &lsa->data->adv_router);
7060 json_object_int_add(json_lsa, "lsaLockCount",
7061 lsa->lock);
7062 json_object_object_add(
7063 json_maxage,
7064 inet_ntop(AF_INET,
7065 &lsa->data->id,
7066 buf, sizeof(buf)),
7067 json_lsa);
7068 }
7069 }
7070 }
7071 if (json)
7072 json_object_object_add(json, "maxAgeLinkStates", json_maxage);
7073 }
7074
7075 #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
7076 #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
7077
7078 #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
7079 #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
7080 #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
7081 #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
7082
7083 #define OSPF_LSA_TYPES_DESC \
7084 "ASBR summary link states\n" \
7085 "External link states\n" \
7086 "Network link states\n" \
7087 "Router link states\n" \
7088 "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \
7089 OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
7090 OSPF_LSA_TYPE_OPAQUE_AS_DESC
7091
7092 static int
7093 show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf, bool maxage,
7094 bool self, bool detail, const char *type_name,
7095 struct in_addr *lsid, struct in_addr *adv_router,
7096 bool use_vrf, json_object *json, bool uj)
7097 {
7098 int type;
7099 json_object *json_vrf = NULL;
7100
7101 if (uj) {
7102 if (use_vrf)
7103 json_vrf = json_object_new_object();
7104 else
7105 json_vrf = json;
7106 }
7107
7108 if (ospf->instance) {
7109 if (uj)
7110 json_object_int_add(json_vrf, "ospfInstance",
7111 ospf->instance);
7112 else
7113 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
7114 }
7115
7116 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
7117
7118 /* Show Router ID. */
7119 if (uj) {
7120 json_object_string_addf(json_vrf, "routerId", "%pI4",
7121 &ospf->router_id);
7122 } else {
7123 vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n",
7124 &ospf->router_id);
7125 }
7126
7127 /* Show MaxAge LSAs */
7128 if (maxage) {
7129 show_ip_ospf_database_maxage(vty, ospf, json_vrf);
7130 if (json) {
7131 if (use_vrf) {
7132 if (ospf->vrf_id == VRF_DEFAULT)
7133 json_object_object_add(json, "default",
7134 json_vrf);
7135 else
7136 json_object_object_add(json, ospf->name,
7137 json_vrf);
7138 }
7139 }
7140 return CMD_SUCCESS;
7141 }
7142
7143 /* Show all LSAs. */
7144 if (!type_name) {
7145 if (detail) {
7146 for (int i = OSPF_ROUTER_LSA; i <= OSPF_OPAQUE_AS_LSA;
7147 i++) {
7148 switch (i) {
7149 case OSPF_GROUP_MEMBER_LSA:
7150 case OSPF_EXTERNAL_ATTRIBUTES_LSA:
7151 /* ignore deprecated LSA types */
7152 continue;
7153 default:
7154 break;
7155 }
7156
7157 if (adv_router && !lsid)
7158 show_lsa_detail_adv_router(vty, ospf, i,
7159 adv_router,
7160 json_vrf);
7161 else
7162 show_lsa_detail(vty, ospf, i, lsid,
7163 adv_router, json_vrf);
7164 }
7165 } else
7166 show_ip_ospf_database_summary(vty, ospf, self,
7167 json_vrf);
7168
7169 if (json) {
7170 if (use_vrf) {
7171 if (ospf->vrf_id == VRF_DEFAULT)
7172 json_object_object_add(json, "default",
7173 json_vrf);
7174 else
7175 json_object_object_add(json, ospf->name,
7176 json_vrf);
7177 }
7178 }
7179 return CMD_SUCCESS;
7180 }
7181
7182 /* Set database type to show. */
7183 if (strncmp(type_name, "r", 1) == 0)
7184 type = OSPF_ROUTER_LSA;
7185 else if (strncmp(type_name, "ne", 2) == 0)
7186 type = OSPF_NETWORK_LSA;
7187 else if (strncmp(type_name, "ns", 2) == 0)
7188 type = OSPF_AS_NSSA_LSA;
7189 else if (strncmp(type_name, "su", 2) == 0)
7190 type = OSPF_SUMMARY_LSA;
7191 else if (strncmp(type_name, "a", 1) == 0)
7192 type = OSPF_ASBR_SUMMARY_LSA;
7193 else if (strncmp(type_name, "e", 1) == 0)
7194 type = OSPF_AS_EXTERNAL_LSA;
7195 else if (strncmp(type_name, "opaque-l", 8) == 0)
7196 type = OSPF_OPAQUE_LINK_LSA;
7197 else if (strncmp(type_name, "opaque-ar", 9) == 0)
7198 type = OSPF_OPAQUE_AREA_LSA;
7199 else if (strncmp(type_name, "opaque-as", 9) == 0)
7200 type = OSPF_OPAQUE_AS_LSA;
7201 else {
7202 if (uj) {
7203 if (use_vrf)
7204 json_object_free(json_vrf);
7205 }
7206 return CMD_WARNING;
7207 }
7208
7209 if (adv_router && !lsid)
7210 show_lsa_detail_adv_router(vty, ospf, type, adv_router,
7211 json_vrf);
7212 else
7213 show_lsa_detail(vty, ospf, type, lsid, adv_router, json_vrf);
7214
7215 if (json) {
7216 if (use_vrf) {
7217 if (ospf->vrf_id == VRF_DEFAULT)
7218 json_object_object_add(json, "default",
7219 json_vrf);
7220 else
7221 json_object_object_add(json, ospf->name,
7222 json_vrf);
7223 }
7224 }
7225
7226 return CMD_SUCCESS;
7227 }
7228
7229 DEFPY (show_ip_ospf_database,
7230 show_ip_ospf_database_cmd,
7231 "show ip ospf [(1-65535)$instance_id] [vrf <NAME|all>$vrf_name] database\
7232 [<\
7233 max-age$maxage\
7234 |self-originate$selforig\
7235 |<\
7236 detail$detail\
7237 |<asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as>$type_name\
7238 >\
7239 [{\
7240 A.B.C.D$lsid\
7241 |<adv-router A.B.C.D$adv_router|self-originate$adv_router_self>\
7242 }]\
7243 >]\
7244 [json]",
7245 SHOW_STR
7246 IP_STR
7247 "OSPF information\n"
7248 "Instance ID\n"
7249 VRF_CMD_HELP_STR
7250 "All VRFs\n"
7251 "Database summary\n"
7252 "LSAs in MaxAge list\n"
7253 "Self-originated link states\n"
7254 "Show detailed information\n"
7255 OSPF_LSA_TYPES_DESC
7256 "Link State ID (as an IP address)\n"
7257 "Advertising Router link states\n"
7258 "Advertising Router (as an IP address)\n"
7259 "Self-originated link states\n"
7260 JSON_STR)
7261 {
7262 struct ospf *ospf;
7263 int ret = CMD_SUCCESS;
7264 bool use_vrf = !!vrf_name;
7265 bool uj = use_json(argc, argv);
7266 struct in_addr *lsid_p = NULL;
7267 struct in_addr *adv_router_p = NULL;
7268 json_object *json = NULL;
7269
7270 if (uj)
7271 json = json_object_new_object();
7272 if (lsid_str)
7273 lsid_p = &lsid;
7274 if (adv_router_str)
7275 adv_router_p = &adv_router;
7276
7277 if (vrf_name && strmatch(vrf_name, "all")) {
7278 struct listnode *node;
7279 bool ospf_output = false;
7280
7281 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
7282 if (!ospf->oi_running)
7283 continue;
7284 if (ospf->instance != instance_id)
7285 continue;
7286
7287 if (adv_router_self)
7288 adv_router_p = &ospf->router_id;
7289
7290 ospf_output = true;
7291 ret = show_ip_ospf_database_common(
7292 vty, ospf, !!maxage, !!selforig, !!detail,
7293 type_name, lsid_p, adv_router_p, use_vrf, json,
7294 uj);
7295 }
7296
7297 if (!ospf_output && !uj)
7298 vty_out(vty, "%% OSPF is not enabled\n");
7299 } else {
7300 if (!vrf_name)
7301 vrf_name = VRF_DEFAULT_NAME;
7302 ospf = ospf_lookup_by_inst_name(instance_id, vrf_name);
7303 if (ospf == NULL || !ospf->oi_running) {
7304 if (uj)
7305 vty_json(vty, json);
7306 else
7307 vty_out(vty, "%% OSPF instance not found\n");
7308 return CMD_SUCCESS;
7309 }
7310 if (adv_router_self)
7311 adv_router_p = &ospf->router_id;
7312
7313 ret = (show_ip_ospf_database_common(
7314 vty, ospf, !!maxage, !!selforig, !!detail, type_name,
7315 lsid_p, adv_router_p, use_vrf, json, uj));
7316 }
7317
7318 if (uj)
7319 vty_json(vty, json);
7320
7321 return ret;
7322 }
7323
7324 DEFUN (ip_ospf_authentication_args,
7325 ip_ospf_authentication_args_addr_cmd,
7326 "ip ospf authentication <null|message-digest> [A.B.C.D]",
7327 "IP Information\n"
7328 "OSPF interface commands\n"
7329 "Enable authentication on this interface\n"
7330 "Use null authentication\n"
7331 "Use message-digest authentication\n"
7332 "Address of interface\n")
7333 {
7334 VTY_DECLVAR_CONTEXT(interface, ifp);
7335 int idx_encryption = 3;
7336 int idx_ipv4 = 4;
7337 struct in_addr addr;
7338 int ret;
7339 struct ospf_if_params *params;
7340
7341 params = IF_DEF_PARAMS(ifp);
7342
7343 if (argc == 5) {
7344 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7345 if (!ret) {
7346 vty_out(vty,
7347 "Please specify interface address by A.B.C.D\n");
7348 return CMD_WARNING_CONFIG_FAILED;
7349 }
7350
7351 params = ospf_get_if_params(ifp, addr);
7352 ospf_if_update_params(ifp, addr);
7353 }
7354
7355 /* Handle null authentication */
7356 if (argv[idx_encryption]->arg[0] == 'n') {
7357 SET_IF_PARAM(params, auth_type);
7358 params->auth_type = OSPF_AUTH_NULL;
7359 return CMD_SUCCESS;
7360 }
7361
7362 /* Handle message-digest authentication */
7363 if (argv[idx_encryption]->arg[0] == 'm') {
7364 SET_IF_PARAM(params, auth_type);
7365 params->auth_type = OSPF_AUTH_CRYPTOGRAPHIC;
7366 return CMD_SUCCESS;
7367 }
7368
7369 vty_out(vty, "You shouldn't get here!\n");
7370 return CMD_WARNING_CONFIG_FAILED;
7371 }
7372
7373 DEFUN (ip_ospf_authentication,
7374 ip_ospf_authentication_addr_cmd,
7375 "ip ospf authentication [A.B.C.D]",
7376 "IP Information\n"
7377 "OSPF interface commands\n"
7378 "Enable authentication on this interface\n"
7379 "Address of interface\n")
7380 {
7381 VTY_DECLVAR_CONTEXT(interface, ifp);
7382 int idx_ipv4 = 3;
7383 struct in_addr addr;
7384 int ret;
7385 struct ospf_if_params *params;
7386
7387 params = IF_DEF_PARAMS(ifp);
7388
7389 if (argc == 4) {
7390 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7391 if (!ret) {
7392 vty_out(vty,
7393 "Please specify interface address by A.B.C.D\n");
7394 return CMD_WARNING_CONFIG_FAILED;
7395 }
7396
7397 params = ospf_get_if_params(ifp, addr);
7398 ospf_if_update_params(ifp, addr);
7399 }
7400
7401 SET_IF_PARAM(params, auth_type);
7402 params->auth_type = OSPF_AUTH_SIMPLE;
7403
7404 return CMD_SUCCESS;
7405 }
7406
7407 DEFUN (no_ip_ospf_authentication_args,
7408 no_ip_ospf_authentication_args_addr_cmd,
7409 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
7410 NO_STR
7411 "IP Information\n"
7412 "OSPF interface commands\n"
7413 "Enable authentication on this interface\n"
7414 "Use null authentication\n"
7415 "Use message-digest authentication\n"
7416 "Address of interface\n")
7417 {
7418 VTY_DECLVAR_CONTEXT(interface, ifp);
7419 int idx_encryption = 4;
7420 int idx_ipv4 = 5;
7421 struct in_addr addr;
7422 int ret;
7423 struct ospf_if_params *params;
7424 struct route_node *rn;
7425 int auth_type;
7426
7427 params = IF_DEF_PARAMS(ifp);
7428
7429 if (argc == 6) {
7430 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7431 if (!ret) {
7432 vty_out(vty,
7433 "Please specify interface address by A.B.C.D\n");
7434 return CMD_WARNING_CONFIG_FAILED;
7435 }
7436
7437 params = ospf_lookup_if_params(ifp, addr);
7438 if (params == NULL) {
7439 vty_out(vty, "Ip Address specified is unknown\n");
7440 return CMD_WARNING_CONFIG_FAILED;
7441 }
7442 params->auth_type = OSPF_AUTH_NOTSET;
7443 UNSET_IF_PARAM(params, auth_type);
7444 if (params != IF_DEF_PARAMS(ifp)) {
7445 ospf_free_if_params(ifp, addr);
7446 ospf_if_update_params(ifp, addr);
7447 }
7448 } else {
7449 if (argv[idx_encryption]->arg[0] == 'n') {
7450 auth_type = OSPF_AUTH_NULL;
7451 } else if (argv[idx_encryption]->arg[0] == 'm') {
7452 auth_type = OSPF_AUTH_CRYPTOGRAPHIC;
7453 } else {
7454 vty_out(vty, "Unexpected input encountered\n");
7455 return CMD_WARNING_CONFIG_FAILED;
7456 }
7457 /*
7458 * Here we have a case where the user has entered
7459 * 'no ip ospf authentication (null | message_digest )'
7460 * we need to find if we have any ip addresses underneath it
7461 * that
7462 * correspond to the associated type.
7463 */
7464 if (params->auth_type == auth_type) {
7465 params->auth_type = OSPF_AUTH_NOTSET;
7466 UNSET_IF_PARAM(params, auth_type);
7467 }
7468
7469 for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn;
7470 rn = route_next(rn)) {
7471 if ((params = rn->info)) {
7472 if (params->auth_type == auth_type) {
7473 params->auth_type = OSPF_AUTH_NOTSET;
7474 UNSET_IF_PARAM(params, auth_type);
7475 if (params != IF_DEF_PARAMS(ifp)) {
7476 ospf_free_if_params(
7477 ifp, rn->p.u.prefix4);
7478 ospf_if_update_params(
7479 ifp, rn->p.u.prefix4);
7480 }
7481 }
7482 }
7483 }
7484 }
7485
7486 return CMD_SUCCESS;
7487 }
7488
7489 DEFUN (no_ip_ospf_authentication,
7490 no_ip_ospf_authentication_addr_cmd,
7491 "no ip ospf authentication [A.B.C.D]",
7492 NO_STR
7493 "IP Information\n"
7494 "OSPF interface commands\n"
7495 "Enable authentication on this interface\n"
7496 "Address of interface\n")
7497 {
7498 VTY_DECLVAR_CONTEXT(interface, ifp);
7499 int idx_ipv4 = 4;
7500 struct in_addr addr;
7501 int ret;
7502 struct ospf_if_params *params;
7503 struct route_node *rn;
7504
7505 params = IF_DEF_PARAMS(ifp);
7506
7507 if (argc == 5) {
7508 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7509 if (!ret) {
7510 vty_out(vty,
7511 "Please specify interface address by A.B.C.D\n");
7512 return CMD_WARNING_CONFIG_FAILED;
7513 }
7514
7515 params = ospf_lookup_if_params(ifp, addr);
7516 if (params == NULL) {
7517 vty_out(vty, "Ip Address specified is unknown\n");
7518 return CMD_WARNING_CONFIG_FAILED;
7519 }
7520
7521 params->auth_type = OSPF_AUTH_NOTSET;
7522 UNSET_IF_PARAM(params, auth_type);
7523 if (params != IF_DEF_PARAMS(ifp)) {
7524 ospf_free_if_params(ifp, addr);
7525 ospf_if_update_params(ifp, addr);
7526 }
7527 } else {
7528 /*
7529 * When a user enters 'no ip ospf authentication'
7530 * We should remove all authentication types from
7531 * the interface.
7532 */
7533 if ((params->auth_type == OSPF_AUTH_NULL)
7534 || (params->auth_type == OSPF_AUTH_CRYPTOGRAPHIC)
7535 || (params->auth_type == OSPF_AUTH_SIMPLE)) {
7536 params->auth_type = OSPF_AUTH_NOTSET;
7537 UNSET_IF_PARAM(params, auth_type);
7538 }
7539
7540 for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn;
7541 rn = route_next(rn)) {
7542 if ((params = rn->info)) {
7543
7544 if ((params->auth_type == OSPF_AUTH_NULL)
7545 || (params->auth_type
7546 == OSPF_AUTH_CRYPTOGRAPHIC)
7547 || (params->auth_type
7548 == OSPF_AUTH_SIMPLE)) {
7549 params->auth_type = OSPF_AUTH_NOTSET;
7550 UNSET_IF_PARAM(params, auth_type);
7551 if (params != IF_DEF_PARAMS(ifp)) {
7552 ospf_free_if_params(
7553 ifp, rn->p.u.prefix4);
7554 ospf_if_update_params(
7555 ifp, rn->p.u.prefix4);
7556 }
7557 }
7558 }
7559 }
7560 }
7561
7562 return CMD_SUCCESS;
7563 }
7564
7565
7566 DEFUN (ip_ospf_authentication_key,
7567 ip_ospf_authentication_key_addr_cmd,
7568 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
7569 "IP Information\n"
7570 "OSPF interface commands\n"
7571 "Authentication password (key)\n"
7572 "The OSPF password (key)\n"
7573 "Address of interface\n")
7574 {
7575 VTY_DECLVAR_CONTEXT(interface, ifp);
7576 int idx = 0;
7577 struct in_addr addr;
7578 struct ospf_if_params *params;
7579
7580 params = IF_DEF_PARAMS(ifp);
7581
7582 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7583 if (!inet_aton(argv[idx]->arg, &addr)) {
7584 vty_out(vty,
7585 "Please specify interface address by A.B.C.D\n");
7586 return CMD_WARNING_CONFIG_FAILED;
7587 }
7588
7589 params = ospf_get_if_params(ifp, addr);
7590 ospf_if_update_params(ifp, addr);
7591 }
7592
7593 strlcpy((char *)params->auth_simple, argv[3]->arg,
7594 sizeof(params->auth_simple));
7595 SET_IF_PARAM(params, auth_simple);
7596
7597 return CMD_SUCCESS;
7598 }
7599
7600 DEFUN_HIDDEN (ospf_authentication_key,
7601 ospf_authentication_key_cmd,
7602 "ospf authentication-key AUTH_KEY [A.B.C.D]",
7603 "OSPF interface commands\n"
7604 VLINK_HELPSTR_AUTH_SIMPLE
7605 "Address of interface\n")
7606 {
7607 return ip_ospf_authentication_key(self, vty, argc, argv);
7608 }
7609
7610 DEFUN (no_ip_ospf_authentication_key,
7611 no_ip_ospf_authentication_key_authkey_addr_cmd,
7612 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7613 NO_STR
7614 "IP Information\n"
7615 "OSPF interface commands\n"
7616 VLINK_HELPSTR_AUTH_SIMPLE
7617 "Address of interface\n")
7618 {
7619 VTY_DECLVAR_CONTEXT(interface, ifp);
7620 int idx = 0;
7621 struct in_addr addr;
7622 struct ospf_if_params *params;
7623 params = IF_DEF_PARAMS(ifp);
7624
7625 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7626 if (!inet_aton(argv[idx]->arg, &addr)) {
7627 vty_out(vty,
7628 "Please specify interface address by A.B.C.D\n");
7629 return CMD_WARNING_CONFIG_FAILED;
7630 }
7631
7632 params = ospf_lookup_if_params(ifp, addr);
7633 if (params == NULL)
7634 return CMD_SUCCESS;
7635 }
7636
7637 memset(params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE);
7638 UNSET_IF_PARAM(params, auth_simple);
7639
7640 if (params != IF_DEF_PARAMS(ifp)) {
7641 ospf_free_if_params(ifp, addr);
7642 ospf_if_update_params(ifp, addr);
7643 }
7644
7645 return CMD_SUCCESS;
7646 }
7647
7648 DEFUN_HIDDEN (no_ospf_authentication_key,
7649 no_ospf_authentication_key_authkey_addr_cmd,
7650 "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7651 NO_STR
7652 "OSPF interface commands\n"
7653 VLINK_HELPSTR_AUTH_SIMPLE
7654 "Address of interface\n")
7655 {
7656 return no_ip_ospf_authentication_key(self, vty, argc, argv);
7657 }
7658
7659 DEFUN (ip_ospf_message_digest_key,
7660 ip_ospf_message_digest_key_cmd,
7661 "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7662 "IP Information\n"
7663 "OSPF interface commands\n"
7664 "Message digest authentication password (key)\n"
7665 "Key ID\n"
7666 "Use MD5 algorithm\n"
7667 "The OSPF password (key)\n"
7668 "Address of interface\n")
7669 {
7670 VTY_DECLVAR_CONTEXT(interface, ifp);
7671 struct crypt_key *ck;
7672 uint8_t key_id;
7673 struct in_addr addr;
7674 struct ospf_if_params *params;
7675
7676 params = IF_DEF_PARAMS(ifp);
7677 int idx = 0;
7678
7679 argv_find(argv, argc, "(1-255)", &idx);
7680 char *keyid = argv[idx]->arg;
7681 argv_find(argv, argc, "KEY", &idx);
7682 char *cryptkey = argv[idx]->arg;
7683
7684 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7685 if (!inet_aton(argv[idx]->arg, &addr)) {
7686 vty_out(vty,
7687 "Please specify interface address by A.B.C.D\n");
7688 return CMD_WARNING_CONFIG_FAILED;
7689 }
7690
7691 params = ospf_get_if_params(ifp, addr);
7692 ospf_if_update_params(ifp, addr);
7693 }
7694
7695 key_id = strtol(keyid, NULL, 10);
7696
7697 /* Remove existing key, if any */
7698 ospf_crypt_key_delete(params->auth_crypt, key_id);
7699
7700 ck = ospf_crypt_key_new();
7701 ck->key_id = (uint8_t)key_id;
7702 strlcpy((char *)ck->auth_key, cryptkey, sizeof(ck->auth_key));
7703
7704 ospf_crypt_key_add(params->auth_crypt, ck);
7705 SET_IF_PARAM(params, auth_crypt);
7706
7707 return CMD_SUCCESS;
7708 }
7709
7710 DEFUN_HIDDEN (ospf_message_digest_key,
7711 ospf_message_digest_key_cmd,
7712 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7713 "OSPF interface commands\n"
7714 "Message digest authentication password (key)\n"
7715 "Key ID\n"
7716 "Use MD5 algorithm\n"
7717 "The OSPF password (key)\n"
7718 "Address of interface\n")
7719 {
7720 return ip_ospf_message_digest_key(self, vty, argc, argv);
7721 }
7722
7723 DEFUN (no_ip_ospf_message_digest_key,
7724 no_ip_ospf_message_digest_key_cmd,
7725 "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7726 NO_STR
7727 "IP Information\n"
7728 "OSPF interface commands\n"
7729 "Message digest authentication password (key)\n"
7730 "Key ID\n"
7731 "Use MD5 algorithm\n"
7732 "The OSPF password (key)\n"
7733 "Address of interface\n")
7734 {
7735 VTY_DECLVAR_CONTEXT(interface, ifp);
7736 int idx = 0;
7737 struct crypt_key *ck;
7738 int key_id;
7739 struct in_addr addr;
7740 struct ospf_if_params *params;
7741 params = IF_DEF_PARAMS(ifp);
7742
7743 argv_find(argv, argc, "(1-255)", &idx);
7744 char *keyid = argv[idx]->arg;
7745
7746 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7747 if (!inet_aton(argv[idx]->arg, &addr)) {
7748 vty_out(vty,
7749 "Please specify interface address by A.B.C.D\n");
7750 return CMD_WARNING_CONFIG_FAILED;
7751 }
7752
7753 params = ospf_lookup_if_params(ifp, addr);
7754 if (params == NULL)
7755 return CMD_SUCCESS;
7756 }
7757
7758 key_id = strtol(keyid, NULL, 10);
7759 ck = ospf_crypt_key_lookup(params->auth_crypt, key_id);
7760 if (ck == NULL) {
7761 vty_out(vty, "OSPF: Key %d does not exist\n", key_id);
7762 return CMD_WARNING_CONFIG_FAILED;
7763 }
7764
7765 ospf_crypt_key_delete(params->auth_crypt, key_id);
7766
7767 if (params != IF_DEF_PARAMS(ifp)) {
7768 ospf_free_if_params(ifp, addr);
7769 ospf_if_update_params(ifp, addr);
7770 }
7771
7772 return CMD_SUCCESS;
7773 }
7774
7775 DEFUN_HIDDEN (no_ospf_message_digest_key,
7776 no_ospf_message_digest_key_cmd,
7777 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7778 NO_STR
7779 "OSPF interface commands\n"
7780 "Message digest authentication password (key)\n"
7781 "Key ID\n"
7782 "Use MD5 algorithm\n"
7783 "The OSPF password (key)\n"
7784 "Address of interface\n")
7785 {
7786 return no_ip_ospf_message_digest_key(self, vty, argc, argv);
7787 }
7788
7789 DEFUN (ip_ospf_cost,
7790 ip_ospf_cost_cmd,
7791 "ip ospf cost (1-65535) [A.B.C.D]",
7792 "IP Information\n"
7793 "OSPF interface commands\n"
7794 "Interface cost\n"
7795 "Cost\n"
7796 "Address of interface\n")
7797 {
7798 VTY_DECLVAR_CONTEXT(interface, ifp);
7799 int idx = 0;
7800 uint32_t cost = OSPF_OUTPUT_COST_DEFAULT;
7801 struct in_addr addr;
7802 struct ospf_if_params *params;
7803 params = IF_DEF_PARAMS(ifp);
7804
7805 // get arguments
7806 char *coststr = NULL, *ifaddr = NULL;
7807
7808 argv_find(argv, argc, "(1-65535)", &idx);
7809 coststr = argv[idx]->arg;
7810 cost = strtol(coststr, NULL, 10);
7811
7812 ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
7813 if (ifaddr) {
7814 if (!inet_aton(ifaddr, &addr)) {
7815 vty_out(vty,
7816 "Please specify interface address by A.B.C.D\n");
7817 return CMD_WARNING_CONFIG_FAILED;
7818 }
7819
7820 params = ospf_get_if_params(ifp, addr);
7821 ospf_if_update_params(ifp, addr);
7822 }
7823
7824 SET_IF_PARAM(params, output_cost_cmd);
7825 params->output_cost_cmd = cost;
7826
7827 ospf_if_recalculate_output_cost(ifp);
7828
7829 return CMD_SUCCESS;
7830 }
7831
7832 DEFUN_HIDDEN (ospf_cost,
7833 ospf_cost_cmd,
7834 "ospf cost (1-65535) [A.B.C.D]",
7835 "OSPF interface commands\n"
7836 "Interface cost\n"
7837 "Cost\n"
7838 "Address of interface\n")
7839 {
7840 return ip_ospf_cost(self, vty, argc, argv);
7841 }
7842
7843 DEFUN (no_ip_ospf_cost,
7844 no_ip_ospf_cost_cmd,
7845 "no ip ospf cost [(1-65535)] [A.B.C.D]",
7846 NO_STR
7847 "IP Information\n"
7848 "OSPF interface commands\n"
7849 "Interface cost\n"
7850 "Cost\n"
7851 "Address of interface\n")
7852 {
7853 VTY_DECLVAR_CONTEXT(interface, ifp);
7854 int idx = 0;
7855 struct in_addr addr;
7856 struct ospf_if_params *params;
7857
7858 params = IF_DEF_PARAMS(ifp);
7859
7860 // get arguments
7861 char *ifaddr = NULL;
7862 ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
7863
7864 /* According to the semantics we are mimicking "no ip ospf cost N" is
7865 * always treated as "no ip ospf cost" regardless of the actual value
7866 * of N already configured for the interface. Thus ignore cost. */
7867
7868 if (ifaddr) {
7869 if (!inet_aton(ifaddr, &addr)) {
7870 vty_out(vty,
7871 "Please specify interface address by A.B.C.D\n");
7872 return CMD_WARNING_CONFIG_FAILED;
7873 }
7874
7875 params = ospf_lookup_if_params(ifp, addr);
7876 if (params == NULL)
7877 return CMD_SUCCESS;
7878 }
7879
7880 UNSET_IF_PARAM(params, output_cost_cmd);
7881
7882 if (params != IF_DEF_PARAMS(ifp)) {
7883 ospf_free_if_params(ifp, addr);
7884 ospf_if_update_params(ifp, addr);
7885 }
7886
7887 ospf_if_recalculate_output_cost(ifp);
7888
7889 return CMD_SUCCESS;
7890 }
7891
7892 DEFUN_HIDDEN (no_ospf_cost,
7893 no_ospf_cost_cmd,
7894 "no ospf cost [(1-65535)] [A.B.C.D]",
7895 NO_STR
7896 "OSPF interface commands\n"
7897 "Interface cost\n"
7898 "Cost\n"
7899 "Address of interface\n")
7900 {
7901 return no_ip_ospf_cost(self, vty, argc, argv);
7902 }
7903
7904 static void ospf_nbr_timer_update(struct ospf_interface *oi)
7905 {
7906 struct route_node *rn;
7907 struct ospf_neighbor *nbr;
7908
7909 for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
7910 nbr = rn->info;
7911
7912 if (!nbr)
7913 continue;
7914
7915 nbr->v_inactivity = OSPF_IF_PARAM(oi, v_wait);
7916 nbr->v_db_desc = OSPF_IF_PARAM(oi, retransmit_interval);
7917 nbr->v_ls_req = OSPF_IF_PARAM(oi, retransmit_interval);
7918 nbr->v_ls_upd = OSPF_IF_PARAM(oi, retransmit_interval);
7919 }
7920 }
7921
7922 static int ospf_vty_dead_interval_set(struct vty *vty, const char *interval_str,
7923 const char *nbr_str,
7924 const char *fast_hello_str)
7925 {
7926 VTY_DECLVAR_CONTEXT(interface, ifp);
7927 uint32_t seconds;
7928 uint8_t hellomult;
7929 struct in_addr addr;
7930 int ret;
7931 struct ospf_if_params *params;
7932 struct ospf_interface *oi;
7933 struct route_node *rn;
7934
7935 params = IF_DEF_PARAMS(ifp);
7936
7937 if (nbr_str) {
7938 ret = inet_aton(nbr_str, &addr);
7939 if (!ret) {
7940 vty_out(vty,
7941 "Please specify interface address by A.B.C.D\n");
7942 return CMD_WARNING_CONFIG_FAILED;
7943 }
7944
7945 params = ospf_get_if_params(ifp, addr);
7946 ospf_if_update_params(ifp, addr);
7947 }
7948
7949 if (interval_str) {
7950 seconds = strtoul(interval_str, NULL, 10);
7951
7952 /* reset fast_hello too, just to be sure */
7953 UNSET_IF_PARAM(params, fast_hello);
7954 params->fast_hello = OSPF_FAST_HELLO_DEFAULT;
7955 } else if (fast_hello_str) {
7956 hellomult = strtoul(fast_hello_str, NULL, 10);
7957 /* 1s dead-interval with sub-second hellos desired */
7958 seconds = OSPF_ROUTER_DEAD_INTERVAL_MINIMAL;
7959 SET_IF_PARAM(params, fast_hello);
7960 params->fast_hello = hellomult;
7961 } else {
7962 vty_out(vty,
7963 "Please specify dead-interval or hello-multiplier\n");
7964 return CMD_WARNING_CONFIG_FAILED;
7965 }
7966
7967 SET_IF_PARAM(params, v_wait);
7968 params->v_wait = seconds;
7969 params->is_v_wait_set = true;
7970
7971 /* Update timer values in neighbor structure. */
7972 if (nbr_str) {
7973 struct ospf *ospf = NULL;
7974
7975 ospf = ifp->vrf->info;
7976 if (ospf) {
7977 oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr);
7978 if (oi)
7979 ospf_nbr_timer_update(oi);
7980 }
7981 } else {
7982 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn))
7983 if ((oi = rn->info))
7984 ospf_nbr_timer_update(oi);
7985 }
7986
7987 return CMD_SUCCESS;
7988 }
7989
7990 DEFUN (ip_ospf_dead_interval,
7991 ip_ospf_dead_interval_cmd,
7992 "ip ospf dead-interval (1-65535) [A.B.C.D]",
7993 "IP Information\n"
7994 "OSPF interface commands\n"
7995 "Interval time after which a neighbor is declared down\n"
7996 "Seconds\n"
7997 "Address of interface\n")
7998 {
7999 int idx = 0;
8000 char *interval = argv_find(argv, argc, "(1-65535)", &idx)
8001 ? argv[idx]->arg
8002 : NULL;
8003 char *ifaddr =
8004 argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
8005 return ospf_vty_dead_interval_set(vty, interval, ifaddr, NULL);
8006 }
8007
8008
8009 DEFUN_HIDDEN (ospf_dead_interval,
8010 ospf_dead_interval_cmd,
8011 "ospf dead-interval (1-65535) [A.B.C.D]",
8012 "OSPF interface commands\n"
8013 "Interval time after which a neighbor is declared down\n"
8014 "Seconds\n"
8015 "Address of interface\n")
8016 {
8017 return ip_ospf_dead_interval(self, vty, argc, argv);
8018 }
8019
8020 DEFUN (ip_ospf_dead_interval_minimal,
8021 ip_ospf_dead_interval_minimal_addr_cmd,
8022 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
8023 "IP Information\n"
8024 "OSPF interface commands\n"
8025 "Interval time after which a neighbor is declared down\n"
8026 "Minimal 1s dead-interval with fast sub-second hellos\n"
8027 "Hello multiplier factor\n"
8028 "Number of Hellos to send each second\n"
8029 "Address of interface\n")
8030 {
8031 int idx_number = 5;
8032 int idx_ipv4 = 6;
8033 if (argc == 7)
8034 return ospf_vty_dead_interval_set(
8035 vty, NULL, argv[idx_ipv4]->arg, argv[idx_number]->arg);
8036 else
8037 return ospf_vty_dead_interval_set(vty, NULL, NULL,
8038 argv[idx_number]->arg);
8039 }
8040
8041 DEFUN (no_ip_ospf_dead_interval,
8042 no_ip_ospf_dead_interval_cmd,
8043 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8044 NO_STR
8045 "IP Information\n"
8046 "OSPF interface commands\n"
8047 "Interval time after which a neighbor is declared down\n"
8048 "Seconds\n"
8049 "Minimal 1s dead-interval with fast sub-second hellos\n"
8050 "Hello multiplier factor\n"
8051 "Number of Hellos to send each second\n"
8052 "Address of interface\n")
8053 {
8054 VTY_DECLVAR_CONTEXT(interface, ifp);
8055 int idx_ipv4 = argc - 1;
8056 struct in_addr addr = {.s_addr = 0L};
8057 int ret;
8058 struct ospf_if_params *params;
8059 struct ospf_interface *oi;
8060 struct route_node *rn;
8061
8062 params = IF_DEF_PARAMS(ifp);
8063
8064 if (argv[idx_ipv4]->type == IPV4_TKN) {
8065 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
8066 if (!ret) {
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_lookup_if_params(ifp, addr);
8073 if (params == NULL)
8074 return CMD_SUCCESS;
8075 }
8076
8077 UNSET_IF_PARAM(params, v_wait);
8078 params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
8079 params->is_v_wait_set = false;
8080
8081 UNSET_IF_PARAM(params, fast_hello);
8082 params->fast_hello = OSPF_FAST_HELLO_DEFAULT;
8083
8084 if (params != IF_DEF_PARAMS(ifp)) {
8085 ospf_free_if_params(ifp, addr);
8086 ospf_if_update_params(ifp, addr);
8087 }
8088
8089 /* Update timer values in neighbor structure. */
8090 if (argc == 1) {
8091 struct ospf *ospf = NULL;
8092
8093 ospf = ifp->vrf->info;
8094 if (ospf) {
8095 oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr);
8096 if (oi)
8097 ospf_nbr_timer_update(oi);
8098 }
8099 } else {
8100 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn))
8101 if ((oi = rn->info))
8102 ospf_nbr_timer_update(oi);
8103 }
8104
8105 return CMD_SUCCESS;
8106 }
8107
8108 DEFUN_HIDDEN (no_ospf_dead_interval,
8109 no_ospf_dead_interval_cmd,
8110 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8111 NO_STR
8112 "OSPF interface commands\n"
8113 "Interval time after which a neighbor is declared down\n"
8114 "Seconds\n"
8115 "Minimal 1s dead-interval with fast sub-second hellos\n"
8116 "Hello multiplier factor\n"
8117 "Number of Hellos to send each second\n"
8118 "Address of interface\n")
8119 {
8120 return no_ip_ospf_dead_interval(self, vty, argc, argv);
8121 }
8122
8123 DEFUN (ip_ospf_hello_interval,
8124 ip_ospf_hello_interval_cmd,
8125 "ip ospf hello-interval (1-65535) [A.B.C.D]",
8126 "IP Information\n"
8127 "OSPF interface commands\n"
8128 "Time between HELLO packets\n"
8129 "Seconds\n"
8130 "Address of interface\n")
8131 {
8132 VTY_DECLVAR_CONTEXT(interface, ifp);
8133 int idx = 0;
8134 struct in_addr addr = {.s_addr = 0L};
8135 struct ospf_if_params *params;
8136 params = IF_DEF_PARAMS(ifp);
8137 uint32_t seconds = 0;
8138 bool is_addr = false;
8139 uint32_t old_interval = 0;
8140
8141 argv_find(argv, argc, "(1-65535)", &idx);
8142 seconds = strtol(argv[idx]->arg, NULL, 10);
8143
8144 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8145 if (!inet_aton(argv[idx]->arg, &addr)) {
8146 vty_out(vty,
8147 "Please specify interface address by A.B.C.D\n");
8148 return CMD_WARNING_CONFIG_FAILED;
8149 }
8150
8151 params = ospf_get_if_params(ifp, addr);
8152 ospf_if_update_params(ifp, addr);
8153 is_addr = true;
8154 }
8155
8156 old_interval = params->v_hello;
8157
8158 /* Return, if same interval is configured. */
8159 if (old_interval == seconds)
8160 return CMD_SUCCESS;
8161
8162 SET_IF_PARAM(params, v_hello);
8163 params->v_hello = seconds;
8164
8165 if (!params->is_v_wait_set) {
8166 SET_IF_PARAM(params, v_wait);
8167 /* As per RFC 4062
8168 * The router dead interval should
8169 * be some multiple of the HelloInterval (perhaps 4 times the
8170 * hello interval) and must be the same for all routers
8171 * attached to a common network.
8172 */
8173 params->v_wait = 4 * seconds;
8174 }
8175
8176 ospf_reset_hello_timer(ifp, addr, is_addr);
8177
8178 return CMD_SUCCESS;
8179 }
8180
8181 DEFUN_HIDDEN (ospf_hello_interval,
8182 ospf_hello_interval_cmd,
8183 "ospf hello-interval (1-65535) [A.B.C.D]",
8184 "OSPF interface commands\n"
8185 "Time between HELLO packets\n"
8186 "Seconds\n"
8187 "Address of interface\n")
8188 {
8189 return ip_ospf_hello_interval(self, vty, argc, argv);
8190 }
8191
8192 DEFUN (no_ip_ospf_hello_interval,
8193 no_ip_ospf_hello_interval_cmd,
8194 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
8195 NO_STR
8196 "IP Information\n"
8197 "OSPF interface commands\n"
8198 "Time between HELLO packets\n" // ignored
8199 "Seconds\n"
8200 "Address of interface\n")
8201 {
8202 VTY_DECLVAR_CONTEXT(interface, ifp);
8203 int idx = 0;
8204 struct in_addr addr = {.s_addr = 0L};
8205 struct ospf_if_params *params;
8206 struct route_node *rn;
8207
8208 params = IF_DEF_PARAMS(ifp);
8209
8210 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8211 if (!inet_aton(argv[idx]->arg, &addr)) {
8212 vty_out(vty,
8213 "Please specify interface address by A.B.C.D\n");
8214 return CMD_WARNING_CONFIG_FAILED;
8215 }
8216
8217 params = ospf_lookup_if_params(ifp, addr);
8218 if (params == NULL)
8219 return CMD_SUCCESS;
8220 }
8221
8222 UNSET_IF_PARAM(params, v_hello);
8223 params->v_hello = OSPF_HELLO_INTERVAL_DEFAULT;
8224
8225 if (!params->is_v_wait_set) {
8226 UNSET_IF_PARAM(params, v_wait);
8227 params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
8228 }
8229
8230 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8231 struct ospf_interface *oi = rn->info;
8232
8233 if (!oi)
8234 continue;
8235
8236 oi->type = IF_DEF_PARAMS(ifp)->type;
8237 oi->ptp_dmvpn = IF_DEF_PARAMS(ifp)->ptp_dmvpn;
8238
8239 if (oi->state > ISM_Down) {
8240 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown);
8241 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp);
8242 }
8243 }
8244
8245 if (params != IF_DEF_PARAMS(ifp)) {
8246 ospf_free_if_params(ifp, addr);
8247 ospf_if_update_params(ifp, addr);
8248 }
8249
8250 return CMD_SUCCESS;
8251 }
8252
8253 DEFUN_HIDDEN (no_ospf_hello_interval,
8254 no_ospf_hello_interval_cmd,
8255 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
8256 NO_STR
8257 "OSPF interface commands\n"
8258 "Time between HELLO packets\n" // ignored
8259 "Seconds\n"
8260 "Address of interface\n")
8261 {
8262 return no_ip_ospf_hello_interval(self, vty, argc, argv);
8263 }
8264
8265 DEFUN(ip_ospf_network, ip_ospf_network_cmd,
8266 "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point [dmvpn]>",
8267 "IP Information\n"
8268 "OSPF interface commands\n"
8269 "Network type\n"
8270 "Specify OSPF broadcast multi-access network\n"
8271 "Specify OSPF NBMA network\n"
8272 "Specify OSPF point-to-multipoint network\n"
8273 "Specify OSPF point-to-point network\n"
8274 "Specify OSPF point-to-point DMVPN network\n")
8275 {
8276 VTY_DECLVAR_CONTEXT(interface, ifp);
8277 int idx = 0;
8278 int old_type = IF_DEF_PARAMS(ifp)->type;
8279 uint8_t old_ptp_dmvpn = IF_DEF_PARAMS(ifp)->ptp_dmvpn;
8280 struct route_node *rn;
8281
8282 if (old_type == OSPF_IFTYPE_LOOPBACK) {
8283 vty_out(vty,
8284 "This is a loopback interface. Can't set network type.\n");
8285 return CMD_WARNING_CONFIG_FAILED;
8286 }
8287
8288 IF_DEF_PARAMS(ifp)->ptp_dmvpn = 0;
8289
8290 if (argv_find(argv, argc, "broadcast", &idx))
8291 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_BROADCAST;
8292 else if (argv_find(argv, argc, "non-broadcast", &idx))
8293 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_NBMA;
8294 else if (argv_find(argv, argc, "point-to-multipoint", &idx))
8295 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOMULTIPOINT;
8296 else if (argv_find(argv, argc, "point-to-point", &idx)) {
8297 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOPOINT;
8298 if (argv_find(argv, argc, "dmvpn", &idx))
8299 IF_DEF_PARAMS(ifp)->ptp_dmvpn = 1;
8300 }
8301
8302 if (IF_DEF_PARAMS(ifp)->type == old_type
8303 && IF_DEF_PARAMS(ifp)->ptp_dmvpn == old_ptp_dmvpn)
8304 return CMD_SUCCESS;
8305
8306 SET_IF_PARAM(IF_DEF_PARAMS(ifp), type);
8307
8308 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8309 struct ospf_interface *oi = rn->info;
8310
8311 if (!oi)
8312 continue;
8313
8314 oi->type = IF_DEF_PARAMS(ifp)->type;
8315
8316 if (oi->state > ISM_Down) {
8317 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown);
8318 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp);
8319 }
8320 }
8321
8322 return CMD_SUCCESS;
8323 }
8324
8325 DEFUN_HIDDEN (ospf_network,
8326 ospf_network_cmd,
8327 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
8328 "OSPF interface commands\n"
8329 "Network type\n"
8330 "Specify OSPF broadcast multi-access network\n"
8331 "Specify OSPF NBMA network\n"
8332 "Specify OSPF point-to-multipoint network\n"
8333 "Specify OSPF point-to-point network\n")
8334 {
8335 return ip_ospf_network(self, vty, argc, argv);
8336 }
8337
8338 DEFUN (no_ip_ospf_network,
8339 no_ip_ospf_network_cmd,
8340 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8341 NO_STR
8342 "IP Information\n"
8343 "OSPF interface commands\n"
8344 "Network type\n"
8345 "Specify OSPF broadcast multi-access network\n"
8346 "Specify OSPF NBMA network\n"
8347 "Specify OSPF point-to-multipoint network\n"
8348 "Specify OSPF point-to-point network\n")
8349 {
8350 VTY_DECLVAR_CONTEXT(interface, ifp);
8351 int old_type = IF_DEF_PARAMS(ifp)->type;
8352 struct route_node *rn;
8353
8354 IF_DEF_PARAMS(ifp)->type = ospf_default_iftype(ifp);
8355 IF_DEF_PARAMS(ifp)->ptp_dmvpn = 0;
8356
8357 if (IF_DEF_PARAMS(ifp)->type == old_type)
8358 return CMD_SUCCESS;
8359
8360 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8361 struct ospf_interface *oi = rn->info;
8362
8363 if (!oi)
8364 continue;
8365
8366 oi->type = IF_DEF_PARAMS(ifp)->type;
8367
8368 if (oi->state > ISM_Down) {
8369 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown);
8370 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp);
8371 }
8372 }
8373
8374 return CMD_SUCCESS;
8375 }
8376
8377 DEFUN_HIDDEN (no_ospf_network,
8378 no_ospf_network_cmd,
8379 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8380 NO_STR
8381 "OSPF interface commands\n"
8382 "Network type\n"
8383 "Specify OSPF broadcast multi-access network\n"
8384 "Specify OSPF NBMA network\n"
8385 "Specify OSPF point-to-multipoint network\n"
8386 "Specify OSPF point-to-point network\n")
8387 {
8388 return no_ip_ospf_network(self, vty, argc, argv);
8389 }
8390
8391 DEFUN (ip_ospf_priority,
8392 ip_ospf_priority_cmd,
8393 "ip ospf priority (0-255) [A.B.C.D]",
8394 "IP Information\n"
8395 "OSPF interface commands\n"
8396 "Router priority\n"
8397 "Priority\n"
8398 "Address of interface\n")
8399 {
8400 VTY_DECLVAR_CONTEXT(interface, ifp);
8401 int idx = 0;
8402 long priority;
8403 struct route_node *rn;
8404 struct in_addr addr;
8405 struct ospf_if_params *params;
8406 params = IF_DEF_PARAMS(ifp);
8407
8408 argv_find(argv, argc, "(0-255)", &idx);
8409 priority = strtol(argv[idx]->arg, NULL, 10);
8410
8411 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8412 if (!inet_aton(argv[idx]->arg, &addr)) {
8413 vty_out(vty,
8414 "Please specify interface address by A.B.C.D\n");
8415 return CMD_WARNING_CONFIG_FAILED;
8416 }
8417
8418 params = ospf_get_if_params(ifp, addr);
8419 ospf_if_update_params(ifp, addr);
8420 }
8421
8422 SET_IF_PARAM(params, priority);
8423 params->priority = priority;
8424
8425 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8426 struct ospf_interface *oi = rn->info;
8427
8428 if (!oi)
8429 continue;
8430
8431 if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) {
8432 PRIORITY(oi) = OSPF_IF_PARAM(oi, priority);
8433 OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange);
8434 }
8435 }
8436
8437 return CMD_SUCCESS;
8438 }
8439
8440 DEFUN_HIDDEN (ospf_priority,
8441 ospf_priority_cmd,
8442 "ospf priority (0-255) [A.B.C.D]",
8443 "OSPF interface commands\n"
8444 "Router priority\n"
8445 "Priority\n"
8446 "Address of interface\n")
8447 {
8448 return ip_ospf_priority(self, vty, argc, argv);
8449 }
8450
8451 DEFUN (no_ip_ospf_priority,
8452 no_ip_ospf_priority_cmd,
8453 "no ip ospf priority [(0-255) [A.B.C.D]]",
8454 NO_STR
8455 "IP Information\n"
8456 "OSPF interface commands\n"
8457 "Router priority\n" // ignored
8458 "Priority\n"
8459 "Address of interface\n")
8460 {
8461 VTY_DECLVAR_CONTEXT(interface, ifp);
8462 int idx = 0;
8463 struct route_node *rn;
8464 struct in_addr addr;
8465 struct ospf_if_params *params;
8466
8467 params = IF_DEF_PARAMS(ifp);
8468
8469 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8470 if (!inet_aton(argv[idx]->arg, &addr)) {
8471 vty_out(vty,
8472 "Please specify interface address by A.B.C.D\n");
8473 return CMD_WARNING_CONFIG_FAILED;
8474 }
8475
8476 params = ospf_lookup_if_params(ifp, addr);
8477 if (params == NULL)
8478 return CMD_SUCCESS;
8479 }
8480
8481 UNSET_IF_PARAM(params, priority);
8482 params->priority = OSPF_ROUTER_PRIORITY_DEFAULT;
8483
8484 if (params != IF_DEF_PARAMS(ifp)) {
8485 ospf_free_if_params(ifp, addr);
8486 ospf_if_update_params(ifp, addr);
8487 }
8488
8489 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8490 struct ospf_interface *oi = rn->info;
8491
8492 if (!oi)
8493 continue;
8494
8495 if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) {
8496 PRIORITY(oi) = OSPF_IF_PARAM(oi, priority);
8497 OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange);
8498 }
8499 }
8500
8501 return CMD_SUCCESS;
8502 }
8503
8504 DEFUN_HIDDEN (no_ospf_priority,
8505 no_ospf_priority_cmd,
8506 "no ospf priority [(0-255) [A.B.C.D]]",
8507 NO_STR
8508 "OSPF interface commands\n"
8509 "Router priority\n"
8510 "Priority\n"
8511 "Address of interface\n")
8512 {
8513 return no_ip_ospf_priority(self, vty, argc, argv);
8514 }
8515
8516 DEFUN (ip_ospf_retransmit_interval,
8517 ip_ospf_retransmit_interval_addr_cmd,
8518 "ip ospf retransmit-interval (1-65535) [A.B.C.D]",
8519 "IP Information\n"
8520 "OSPF interface commands\n"
8521 "Time between retransmitting lost link state advertisements\n"
8522 "Seconds\n"
8523 "Address of interface\n")
8524 {
8525 VTY_DECLVAR_CONTEXT(interface, ifp);
8526 int idx = 0;
8527 uint32_t seconds;
8528 struct in_addr addr;
8529 struct ospf_if_params *params;
8530 params = IF_DEF_PARAMS(ifp);
8531
8532 argv_find(argv, argc, "(1-65535)", &idx);
8533 seconds = strtol(argv[idx]->arg, NULL, 10);
8534
8535 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8536 if (!inet_aton(argv[idx]->arg, &addr)) {
8537 vty_out(vty,
8538 "Please specify interface address by A.B.C.D\n");
8539 return CMD_WARNING_CONFIG_FAILED;
8540 }
8541
8542 params = ospf_get_if_params(ifp, addr);
8543 ospf_if_update_params(ifp, addr);
8544 }
8545
8546 SET_IF_PARAM(params, retransmit_interval);
8547 params->retransmit_interval = seconds;
8548
8549 return CMD_SUCCESS;
8550 }
8551
8552 DEFUN_HIDDEN (ospf_retransmit_interval,
8553 ospf_retransmit_interval_cmd,
8554 "ospf retransmit-interval (1-65535) [A.B.C.D]",
8555 "OSPF interface commands\n"
8556 "Time between retransmitting lost link state advertisements\n"
8557 "Seconds\n"
8558 "Address of interface\n")
8559 {
8560 return ip_ospf_retransmit_interval(self, vty, argc, argv);
8561 }
8562
8563 DEFUN (no_ip_ospf_retransmit_interval,
8564 no_ip_ospf_retransmit_interval_addr_cmd,
8565 "no ip ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8566 NO_STR
8567 "IP Information\n"
8568 "OSPF interface commands\n"
8569 "Time between retransmitting lost link state advertisements\n"
8570 "Seconds\n"
8571 "Address of interface\n")
8572 {
8573 VTY_DECLVAR_CONTEXT(interface, ifp);
8574 int idx = 0;
8575 struct in_addr addr;
8576 struct ospf_if_params *params;
8577
8578 params = IF_DEF_PARAMS(ifp);
8579
8580 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8581 if (!inet_aton(argv[idx]->arg, &addr)) {
8582 vty_out(vty,
8583 "Please specify interface address by A.B.C.D\n");
8584 return CMD_WARNING_CONFIG_FAILED;
8585 }
8586
8587 params = ospf_lookup_if_params(ifp, addr);
8588 if (params == NULL)
8589 return CMD_SUCCESS;
8590 }
8591
8592 UNSET_IF_PARAM(params, retransmit_interval);
8593 params->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT;
8594
8595 if (params != IF_DEF_PARAMS(ifp)) {
8596 ospf_free_if_params(ifp, addr);
8597 ospf_if_update_params(ifp, addr);
8598 }
8599
8600 return CMD_SUCCESS;
8601 }
8602
8603 DEFUN_HIDDEN (no_ospf_retransmit_interval,
8604 no_ospf_retransmit_interval_cmd,
8605 "no ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8606 NO_STR
8607 "OSPF interface commands\n"
8608 "Time between retransmitting lost link state advertisements\n"
8609 "Seconds\n"
8610 "Address of interface\n")
8611 {
8612 return no_ip_ospf_retransmit_interval(self, vty, argc, argv);
8613 }
8614
8615 DEFUN (ip_ospf_transmit_delay,
8616 ip_ospf_transmit_delay_addr_cmd,
8617 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
8618 "IP Information\n"
8619 "OSPF interface commands\n"
8620 "Link state transmit delay\n"
8621 "Seconds\n"
8622 "Address of interface\n")
8623 {
8624 VTY_DECLVAR_CONTEXT(interface, ifp);
8625 int idx = 0;
8626 uint32_t seconds;
8627 struct in_addr addr;
8628 struct ospf_if_params *params;
8629
8630 params = IF_DEF_PARAMS(ifp);
8631 argv_find(argv, argc, "(1-65535)", &idx);
8632 seconds = strtol(argv[idx]->arg, NULL, 10);
8633
8634 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8635 if (!inet_aton(argv[idx]->arg, &addr)) {
8636 vty_out(vty,
8637 "Please specify interface address by A.B.C.D\n");
8638 return CMD_WARNING_CONFIG_FAILED;
8639 }
8640
8641 params = ospf_get_if_params(ifp, addr);
8642 ospf_if_update_params(ifp, addr);
8643 }
8644
8645 SET_IF_PARAM(params, transmit_delay);
8646 params->transmit_delay = seconds;
8647
8648 return CMD_SUCCESS;
8649 }
8650
8651 DEFUN_HIDDEN (ospf_transmit_delay,
8652 ospf_transmit_delay_cmd,
8653 "ospf transmit-delay (1-65535) [A.B.C.D]",
8654 "OSPF interface commands\n"
8655 "Link state transmit delay\n"
8656 "Seconds\n"
8657 "Address of interface\n")
8658 {
8659 return ip_ospf_transmit_delay(self, vty, argc, argv);
8660 }
8661
8662 DEFUN (no_ip_ospf_transmit_delay,
8663 no_ip_ospf_transmit_delay_addr_cmd,
8664 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
8665 NO_STR
8666 "IP Information\n"
8667 "OSPF interface commands\n"
8668 "Link state transmit delay\n"
8669 "Seconds\n"
8670 "Address of interface\n")
8671 {
8672 VTY_DECLVAR_CONTEXT(interface, ifp);
8673 int idx = 0;
8674 struct in_addr addr;
8675 struct ospf_if_params *params;
8676
8677 params = IF_DEF_PARAMS(ifp);
8678
8679 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8680 if (!inet_aton(argv[idx]->arg, &addr)) {
8681 vty_out(vty,
8682 "Please specify interface address by A.B.C.D\n");
8683 return CMD_WARNING_CONFIG_FAILED;
8684 }
8685
8686 params = ospf_lookup_if_params(ifp, addr);
8687 if (params == NULL)
8688 return CMD_SUCCESS;
8689 }
8690
8691 UNSET_IF_PARAM(params, transmit_delay);
8692 params->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT;
8693
8694 if (params != IF_DEF_PARAMS(ifp)) {
8695 ospf_free_if_params(ifp, addr);
8696 ospf_if_update_params(ifp, addr);
8697 }
8698
8699 return CMD_SUCCESS;
8700 }
8701
8702
8703 DEFUN_HIDDEN (no_ospf_transmit_delay,
8704 no_ospf_transmit_delay_cmd,
8705 "no ospf transmit-delay [(1-65535) [A.B.C.D]]",
8706 NO_STR
8707 "OSPF interface commands\n"
8708 "Link state transmit delay\n"
8709 "Seconds\n"
8710 "Address of interface\n")
8711 {
8712 return no_ip_ospf_transmit_delay(self, vty, argc, argv);
8713 }
8714
8715 DEFUN (ip_ospf_area,
8716 ip_ospf_area_cmd,
8717 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]",
8718 "IP Information\n"
8719 "OSPF interface commands\n"
8720 "Instance ID\n"
8721 "Enable OSPF on this interface\n"
8722 "OSPF area ID in IP address format\n"
8723 "OSPF area ID as a decimal value\n"
8724 "Address of interface\n")
8725 {
8726 VTY_DECLVAR_CONTEXT(interface, ifp);
8727 int idx = 0;
8728 int format, ret;
8729 struct in_addr area_id;
8730 struct in_addr addr;
8731 struct ospf_if_params *params = NULL;
8732 struct route_node *rn;
8733 struct ospf *ospf = NULL;
8734 unsigned short instance = 0;
8735 char *areaid;
8736 uint32_t count = 0;
8737
8738 if (argv_find(argv, argc, "(1-65535)", &idx))
8739 instance = strtol(argv[idx]->arg, NULL, 10);
8740
8741 argv_find(argv, argc, "area", &idx);
8742 areaid = argv[idx + 1]->arg;
8743
8744 if (!instance)
8745 ospf = ifp->vrf->info;
8746 else
8747 ospf = ospf_lookup_instance(instance);
8748
8749 if (instance && instance != ospf_instance) {
8750 /*
8751 * At this point we know we have received
8752 * an instance and there is no ospf instance
8753 * associated with it. This means we are
8754 * in a situation where we have an
8755 * ospf command that is setup for a different
8756 * process(instance). We need to safely
8757 * remove the command from ourselves and
8758 * allow the other instance(process) handle
8759 * the configuration command.
8760 */
8761 count = 0;
8762
8763 params = IF_DEF_PARAMS(ifp);
8764 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
8765 UNSET_IF_PARAM(params, if_area);
8766 count++;
8767 }
8768
8769 for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; rn = route_next(rn))
8770 if ((params = rn->info) && OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
8771 UNSET_IF_PARAM(params, if_area);
8772 count++;
8773 }
8774
8775 if (count > 0) {
8776 ospf = ifp->vrf->info;
8777 if (ospf)
8778 ospf_interface_area_unset(ospf, ifp);
8779 }
8780
8781 return CMD_NOT_MY_INSTANCE;
8782 }
8783
8784 ret = str2area_id(areaid, &area_id, &format);
8785 if (ret < 0) {
8786 vty_out(vty, "Please specify area by A.B.C.D|<0-4294967295>\n");
8787 return CMD_WARNING_CONFIG_FAILED;
8788 }
8789 if (memcmp(ifp->name, "VLINK", 5) == 0) {
8790 vty_out(vty, "Cannot enable OSPF on a virtual link.\n");
8791 return CMD_WARNING_CONFIG_FAILED;
8792 }
8793
8794 if (ospf) {
8795 for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) {
8796 if (rn->info != NULL) {
8797 vty_out(vty,
8798 "Please remove all network commands first.\n");
8799 return CMD_WARNING_CONFIG_FAILED;
8800 }
8801 }
8802 }
8803
8804 params = IF_DEF_PARAMS(ifp);
8805 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)
8806 && !IPV4_ADDR_SAME(&params->if_area, &area_id)) {
8807 vty_out(vty,
8808 "Must remove previous area config before changing ospf area \n");
8809 return CMD_WARNING_CONFIG_FAILED;
8810 }
8811
8812 // Check if we have an address arg and proccess it
8813 if (argc == idx + 3) {
8814 if (!inet_aton(argv[idx + 2]->arg, &addr)) {
8815 vty_out(vty,
8816 "Please specify Intf Address by A.B.C.D\n");
8817 return CMD_WARNING_CONFIG_FAILED;
8818 }
8819 // update/create address-level params
8820 params = ospf_get_if_params((ifp), (addr));
8821 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
8822 if (!IPV4_ADDR_SAME(&params->if_area, &area_id)) {
8823 vty_out(vty,
8824 "Must remove previous area/address config before changing ospf area\n");
8825 return CMD_WARNING_CONFIG_FAILED;
8826 } else
8827 return CMD_SUCCESS;
8828 }
8829 ospf_if_update_params((ifp), (addr));
8830 }
8831
8832 /* enable ospf on this interface with area_id */
8833 if (params) {
8834 SET_IF_PARAM(params, if_area);
8835 params->if_area = area_id;
8836 params->if_area_id_fmt = format;
8837 }
8838
8839 if (ospf)
8840 ospf_interface_area_set(ospf, ifp);
8841
8842 return CMD_SUCCESS;
8843 }
8844
8845 DEFUN (no_ip_ospf_area,
8846 no_ip_ospf_area_cmd,
8847 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]",
8848 NO_STR
8849 "IP Information\n"
8850 "OSPF interface commands\n"
8851 "Instance ID\n"
8852 "Disable OSPF on this interface\n"
8853 "OSPF area ID in IP address format\n"
8854 "OSPF area ID as a decimal value\n"
8855 "Address of interface\n")
8856 {
8857 VTY_DECLVAR_CONTEXT(interface, ifp);
8858 int idx = 0;
8859 struct ospf *ospf;
8860 struct ospf_if_params *params;
8861 unsigned short instance = 0;
8862 struct in_addr addr;
8863 struct in_addr area_id;
8864
8865 if (argv_find(argv, argc, "(1-65535)", &idx))
8866 instance = strtol(argv[idx]->arg, NULL, 10);
8867
8868 if (!instance)
8869 ospf = ifp->vrf->info;
8870 else
8871 ospf = ospf_lookup_instance(instance);
8872
8873 if (instance && instance != ospf_instance)
8874 return CMD_NOT_MY_INSTANCE;
8875
8876 argv_find(argv, argc, "area", &idx);
8877
8878 // Check if we have an address arg and proccess it
8879 if (argc == idx + 3) {
8880 if (!inet_aton(argv[idx + 2]->arg, &addr)) {
8881 vty_out(vty,
8882 "Please specify Intf Address by A.B.C.D\n");
8883 return CMD_WARNING_CONFIG_FAILED;
8884 }
8885 params = ospf_lookup_if_params(ifp, addr);
8886 if ((params) == NULL)
8887 return CMD_SUCCESS;
8888 } else
8889 params = IF_DEF_PARAMS(ifp);
8890
8891 area_id = params->if_area;
8892 if (!OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
8893 vty_out(vty,
8894 "Can't find specified interface area configuration.\n");
8895 return CMD_WARNING_CONFIG_FAILED;
8896 }
8897
8898 UNSET_IF_PARAM(params, if_area);
8899 if (params != IF_DEF_PARAMS((ifp))) {
8900 ospf_free_if_params((ifp), (addr));
8901 ospf_if_update_params((ifp), (addr));
8902 }
8903
8904 if (ospf) {
8905 ospf_interface_area_unset(ospf, ifp);
8906 ospf_area_check_free(ospf, area_id);
8907 }
8908
8909 return CMD_SUCCESS;
8910 }
8911
8912 DEFUN (ip_ospf_passive,
8913 ip_ospf_passive_cmd,
8914 "ip ospf passive [A.B.C.D]",
8915 "IP Information\n"
8916 "OSPF interface commands\n"
8917 "Suppress routing updates on an interface\n"
8918 "Address of interface\n")
8919 {
8920 VTY_DECLVAR_CONTEXT(interface, ifp);
8921 int idx_ipv4 = 3;
8922 struct in_addr addr = {.s_addr = INADDR_ANY};
8923 struct ospf_if_params *params;
8924 int ret;
8925
8926 if (argc == 4) {
8927 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
8928 if (!ret) {
8929 vty_out(vty,
8930 "Please specify interface address by A.B.C.D\n");
8931 return CMD_WARNING_CONFIG_FAILED;
8932 }
8933 params = ospf_get_if_params(ifp, addr);
8934 ospf_if_update_params(ifp, addr);
8935 } else {
8936 params = IF_DEF_PARAMS(ifp);
8937 }
8938
8939 ospf_passive_interface_update(ifp, params, addr, OSPF_IF_PASSIVE);
8940
8941 return CMD_SUCCESS;
8942 }
8943
8944 DEFUN (no_ip_ospf_passive,
8945 no_ip_ospf_passive_cmd,
8946 "no ip ospf passive [A.B.C.D]",
8947 NO_STR
8948 "IP Information\n"
8949 "OSPF interface commands\n"
8950 "Enable routing updates on an interface\n"
8951 "Address of interface\n")
8952 {
8953 VTY_DECLVAR_CONTEXT(interface, ifp);
8954 int idx_ipv4 = 4;
8955 struct in_addr addr = {.s_addr = INADDR_ANY};
8956 struct ospf_if_params *params;
8957 int ret;
8958
8959 if (argc == 5) {
8960 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
8961 if (!ret) {
8962 vty_out(vty,
8963 "Please specify interface address by A.B.C.D\n");
8964 return CMD_WARNING_CONFIG_FAILED;
8965 }
8966 params = ospf_lookup_if_params(ifp, addr);
8967 if (params == NULL)
8968 return CMD_SUCCESS;
8969 } else {
8970 params = IF_DEF_PARAMS(ifp);
8971 }
8972
8973 ospf_passive_interface_update(ifp, params, addr, OSPF_IF_ACTIVE);
8974
8975 return CMD_SUCCESS;
8976 }
8977
8978 DEFUN (ospf_redistribute_source,
8979 ospf_redistribute_source_cmd,
8980 "redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
8981 REDIST_STR
8982 FRR_REDIST_HELP_STR_OSPFD
8983 "Metric for redistributed routes\n"
8984 "OSPF default metric\n"
8985 "OSPF exterior metric type for redistributed routes\n"
8986 "Set OSPF External Type 1/2 metrics\n"
8987 "Route map reference\n"
8988 "Pointer to route-map entries\n")
8989 {
8990 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
8991 int idx_protocol = 1;
8992 int source;
8993 int type = -1;
8994 int metric = -1;
8995 struct ospf_redist *red;
8996 int idx = 0;
8997 bool update = false;
8998
8999 /* Get distribute source. */
9000 source = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
9001 if (source < 0)
9002 return CMD_WARNING_CONFIG_FAILED;
9003
9004 /* Get metric value. */
9005 if (argv_find(argv, argc, "(0-16777214)", &idx)) {
9006 if (!str2metric(argv[idx]->arg, &metric))
9007 return CMD_WARNING_CONFIG_FAILED;
9008 }
9009 idx = 1;
9010 /* Get metric type. */
9011 if (argv_find(argv, argc, "(1-2)", &idx)) {
9012 if (!str2metric_type(argv[idx]->arg, &type))
9013 return CMD_WARNING_CONFIG_FAILED;
9014 }
9015 idx = 1;
9016
9017 red = ospf_redist_lookup(ospf, source, 0);
9018 if (!red)
9019 red = ospf_redist_add(ospf, source, 0);
9020 else
9021 update = true;
9022
9023 /* Get route-map */
9024 if (argv_find(argv, argc, "route-map", &idx)) {
9025 ospf_routemap_set(red, argv[idx + 1]->arg);
9026 } else
9027 ospf_routemap_unset(red);
9028
9029 if (update)
9030 return ospf_redistribute_update(ospf, red, source, 0, type,
9031 metric);
9032 else
9033 return ospf_redistribute_set(ospf, red, source, 0, type,
9034 metric);
9035 }
9036
9037 DEFUN (no_ospf_redistribute_source,
9038 no_ospf_redistribute_source_cmd,
9039 "no redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9040 NO_STR
9041 REDIST_STR
9042 FRR_REDIST_HELP_STR_OSPFD
9043 "Metric for redistributed routes\n"
9044 "OSPF default metric\n"
9045 "OSPF exterior metric type for redistributed routes\n"
9046 "Set OSPF External Type 1/2 metrics\n"
9047 "Route map reference\n"
9048 "Pointer to route-map entries\n")
9049 {
9050 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9051 int idx_protocol = 2;
9052 int source;
9053 struct ospf_redist *red;
9054
9055 source = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
9056 if (source < 0)
9057 return CMD_WARNING_CONFIG_FAILED;
9058
9059 red = ospf_redist_lookup(ospf, source, 0);
9060 if (!red)
9061 return CMD_SUCCESS;
9062
9063 ospf_routemap_unset(red);
9064 ospf_redist_del(ospf, source, 0);
9065
9066 return ospf_redistribute_unset(ospf, source, 0);
9067 }
9068
9069 DEFUN (ospf_redistribute_instance_source,
9070 ospf_redistribute_instance_source_cmd,
9071 "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9072 REDIST_STR
9073 "Open Shortest Path First\n"
9074 "Non-main Kernel Routing Table\n"
9075 "Instance ID/Table ID\n"
9076 "Metric for redistributed routes\n"
9077 "OSPF default metric\n"
9078 "OSPF exterior metric type for redistributed routes\n"
9079 "Set OSPF External Type 1/2 metrics\n"
9080 "Route map reference\n"
9081 "Pointer to route-map entries\n")
9082 {
9083 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9084 int idx_ospf_table = 1;
9085 int idx_number = 2;
9086 int idx = 3;
9087 int source;
9088 int type = -1;
9089 int metric = -1;
9090 unsigned short instance;
9091 struct ospf_redist *red;
9092 bool update = false;
9093
9094 source = proto_redistnum(AFI_IP, argv[idx_ospf_table]->text);
9095
9096 if (source < 0) {
9097 vty_out(vty, "Unknown instance redistribution\n");
9098 return CMD_WARNING_CONFIG_FAILED;
9099 }
9100
9101 instance = strtoul(argv[idx_number]->arg, NULL, 10);
9102
9103 if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) {
9104 vty_out(vty,
9105 "Instance redistribution in non-instanced OSPF not allowed\n");
9106 return CMD_WARNING_CONFIG_FAILED;
9107 }
9108
9109 if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) {
9110 vty_out(vty, "Same instance OSPF redistribution not allowed\n");
9111 return CMD_WARNING_CONFIG_FAILED;
9112 }
9113
9114 /* Get metric value. */
9115 if (argv_find(argv, argc, "metric", &idx))
9116 if (!str2metric(argv[idx + 1]->arg, &metric))
9117 return CMD_WARNING_CONFIG_FAILED;
9118
9119 idx = 3;
9120 /* Get metric type. */
9121 if (argv_find(argv, argc, "metric-type", &idx))
9122 if (!str2metric_type(argv[idx + 1]->arg, &type))
9123 return CMD_WARNING_CONFIG_FAILED;
9124
9125 red = ospf_redist_lookup(ospf, source, instance);
9126 if (!red)
9127 red = ospf_redist_add(ospf, source, instance);
9128 else
9129 update = true;
9130
9131 idx = 3;
9132 if (argv_find(argv, argc, "route-map", &idx))
9133 ospf_routemap_set(red, argv[idx + 1]->arg);
9134 else
9135 ospf_routemap_unset(red);
9136
9137 if (update)
9138 return ospf_redistribute_update(ospf, red, source, instance,
9139 type, metric);
9140 else
9141 return ospf_redistribute_set(ospf, red, source, instance, type,
9142 metric);
9143 }
9144
9145 DEFUN (no_ospf_redistribute_instance_source,
9146 no_ospf_redistribute_instance_source_cmd,
9147 "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9148 NO_STR
9149 REDIST_STR
9150 "Open Shortest Path First\n"
9151 "Non-main Kernel Routing Table\n"
9152 "Instance ID/Table Id\n"
9153 "Metric for redistributed routes\n"
9154 "OSPF default metric\n"
9155 "OSPF exterior metric type for redistributed routes\n"
9156 "Set OSPF External Type 1/2 metrics\n"
9157 "Route map reference\n"
9158 "Pointer to route-map entries\n")
9159 {
9160 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9161 int idx_ospf_table = 2;
9162 int idx_number = 3;
9163 unsigned int instance;
9164 struct ospf_redist *red;
9165 int source;
9166
9167 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
9168 source = ZEBRA_ROUTE_OSPF;
9169 else
9170 source = ZEBRA_ROUTE_TABLE;
9171
9172 instance = strtoul(argv[idx_number]->arg, NULL, 10);
9173
9174 if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) {
9175 vty_out(vty,
9176 "Instance redistribution in non-instanced OSPF not allowed\n");
9177 return CMD_WARNING_CONFIG_FAILED;
9178 }
9179
9180 if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) {
9181 vty_out(vty, "Same instance OSPF redistribution not allowed\n");
9182 return CMD_WARNING_CONFIG_FAILED;
9183 }
9184
9185 red = ospf_redist_lookup(ospf, source, instance);
9186 if (!red)
9187 return CMD_SUCCESS;
9188
9189 ospf_routemap_unset(red);
9190 ospf_redist_del(ospf, source, instance);
9191
9192 return ospf_redistribute_unset(ospf, source, instance);
9193 }
9194
9195 DEFUN (ospf_distribute_list_out,
9196 ospf_distribute_list_out_cmd,
9197 "distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD,
9198 "Filter networks in routing updates\n"
9199 "Access-list name\n"
9200 OUT_STR
9201 FRR_REDIST_HELP_STR_OSPFD)
9202 {
9203 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9204 int idx_word = 1;
9205 int source;
9206
9207 char *proto = argv[argc - 1]->text;
9208
9209 /* Get distribute source. */
9210 source = proto_redistnum(AFI_IP, proto);
9211 if (source < 0)
9212 return CMD_WARNING_CONFIG_FAILED;
9213
9214 return ospf_distribute_list_out_set(ospf, source, argv[idx_word]->arg);
9215 }
9216
9217 DEFUN (no_ospf_distribute_list_out,
9218 no_ospf_distribute_list_out_cmd,
9219 "no distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD,
9220 NO_STR
9221 "Filter networks in routing updates\n"
9222 "Access-list name\n"
9223 OUT_STR
9224 FRR_REDIST_HELP_STR_OSPFD)
9225 {
9226 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9227 int idx_word = 2;
9228 int source;
9229
9230 char *proto = argv[argc - 1]->text;
9231 source = proto_redistnum(AFI_IP, proto);
9232 if (source < 0)
9233 return CMD_WARNING_CONFIG_FAILED;
9234
9235 return ospf_distribute_list_out_unset(ospf, source,
9236 argv[idx_word]->arg);
9237 }
9238
9239 /* Default information originate. */
9240 DEFUN (ospf_default_information_originate,
9241 ospf_default_information_originate_cmd,
9242 "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9243 "Control distribution of default information\n"
9244 "Distribute a default route\n"
9245 "Always advertise default route\n"
9246 "OSPF default metric\n"
9247 "OSPF metric\n"
9248 "OSPF metric type for default routes\n"
9249 "Set OSPF External Type 1/2 metrics\n"
9250 "Route map reference\n"
9251 "Pointer to route-map entries\n")
9252 {
9253 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9254 int default_originate = DEFAULT_ORIGINATE_ZEBRA;
9255 int type = -1;
9256 int metric = -1;
9257 struct ospf_redist *red;
9258 int idx = 0;
9259 int cur_originate = ospf->default_originate;
9260 bool sameRtmap = false;
9261 char *rtmap = NULL;
9262
9263 red = ospf_redist_add(ospf, DEFAULT_ROUTE, 0);
9264
9265 /* Check whether "always" was specified */
9266 if (argv_find(argv, argc, "always", &idx))
9267 default_originate = DEFAULT_ORIGINATE_ALWAYS;
9268 idx = 1;
9269 /* Get metric value */
9270 if (argv_find(argv, argc, "(0-16777214)", &idx)) {
9271 if (!str2metric(argv[idx]->arg, &metric))
9272 return CMD_WARNING_CONFIG_FAILED;
9273 }
9274 idx = 1;
9275 /* Get metric type. */
9276 if (argv_find(argv, argc, "(1-2)", &idx)) {
9277 if (!str2metric_type(argv[idx]->arg, &type))
9278 return CMD_WARNING_CONFIG_FAILED;
9279 }
9280 idx = 1;
9281 /* Get route-map */
9282 if (argv_find(argv, argc, "route-map", &idx))
9283 rtmap = argv[idx + 1]->arg;
9284
9285 /* To check if user is providing same route map */
9286 if ((!rtmap && !ROUTEMAP_NAME(red)) ||
9287 (rtmap && ROUTEMAP_NAME(red) &&
9288 (strcmp(rtmap, ROUTEMAP_NAME(red)) == 0)))
9289 sameRtmap = true;
9290
9291 /* Don't allow if the same lsa is already originated. */
9292 if ((sameRtmap)
9293 && (red->dmetric.type == type)
9294 && (red->dmetric.value == metric)
9295 && (cur_originate == default_originate))
9296 return CMD_SUCCESS;
9297
9298 /* Updating Metric details */
9299 red->dmetric.type = type;
9300 red->dmetric.value = metric;
9301
9302 /* updating route map details */
9303 if (rtmap)
9304 ospf_routemap_set(red, rtmap);
9305 else
9306 ospf_routemap_unset(red);
9307
9308 return ospf_redistribute_default_set(ospf, default_originate, type,
9309 metric);
9310 }
9311
9312 DEFUN (no_ospf_default_information_originate,
9313 no_ospf_default_information_originate_cmd,
9314 "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9315 NO_STR
9316 "Control distribution of default information\n"
9317 "Distribute a default route\n"
9318 "Always advertise default route\n"
9319 "OSPF default metric\n"
9320 "OSPF metric\n"
9321 "OSPF metric type for default routes\n"
9322 "Set OSPF External Type 1/2 metrics\n"
9323 "Route map reference\n"
9324 "Pointer to route-map entries\n")
9325 {
9326 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9327 struct ospf_redist *red;
9328
9329 red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0);
9330 if (!red)
9331 return CMD_SUCCESS;
9332
9333 ospf_routemap_unset(red);
9334 ospf_redist_del(ospf, DEFAULT_ROUTE, 0);
9335
9336 return ospf_redistribute_default_set(ospf, DEFAULT_ORIGINATE_NONE,
9337 0, 0);
9338 }
9339
9340 DEFUN (ospf_default_metric,
9341 ospf_default_metric_cmd,
9342 "default-metric (0-16777214)",
9343 "Set metric of redistributed routes\n"
9344 "Default metric\n")
9345 {
9346 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9347 int idx_number = 1;
9348 int metric = -1;
9349
9350 if (!str2metric(argv[idx_number]->arg, &metric))
9351 return CMD_WARNING_CONFIG_FAILED;
9352
9353 ospf->default_metric = metric;
9354
9355 return CMD_SUCCESS;
9356 }
9357
9358 DEFUN (no_ospf_default_metric,
9359 no_ospf_default_metric_cmd,
9360 "no default-metric [(0-16777214)]",
9361 NO_STR
9362 "Set metric of redistributed routes\n"
9363 "Default metric\n")
9364 {
9365 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9366
9367 ospf->default_metric = -1;
9368
9369 return CMD_SUCCESS;
9370 }
9371
9372
9373 DEFUN (ospf_distance,
9374 ospf_distance_cmd,
9375 "distance (1-255)",
9376 "Administrative distance\n"
9377 "OSPF Administrative distance\n")
9378 {
9379 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9380 int idx_number = 1;
9381 uint8_t distance;
9382
9383 distance = atoi(argv[idx_number]->arg);
9384 if (ospf->distance_all != distance) {
9385 ospf->distance_all = distance;
9386 ospf_restart_spf(ospf);
9387 }
9388
9389 return CMD_SUCCESS;
9390 }
9391
9392 DEFUN (no_ospf_distance,
9393 no_ospf_distance_cmd,
9394 "no distance (1-255)",
9395 NO_STR
9396 "Administrative distance\n"
9397 "OSPF Administrative distance\n")
9398 {
9399 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9400
9401 if (ospf->distance_all) {
9402 ospf->distance_all = 0;
9403 ospf_restart_spf(ospf);
9404 }
9405
9406 return CMD_SUCCESS;
9407 }
9408
9409 DEFUN (no_ospf_distance_ospf,
9410 no_ospf_distance_ospf_cmd,
9411 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
9412 NO_STR
9413 "Administrative distance\n"
9414 "OSPF administrative distance\n"
9415 "Intra-area routes\n"
9416 "Distance for intra-area routes\n"
9417 "Inter-area routes\n"
9418 "Distance for inter-area routes\n"
9419 "External routes\n"
9420 "Distance for external routes\n")
9421 {
9422 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9423 int idx = 0;
9424
9425 if (argv_find(argv, argc, "intra-area", &idx) || argc == 3)
9426 idx = ospf->distance_intra = 0;
9427 if (argv_find(argv, argc, "inter-area", &idx) || argc == 3)
9428 idx = ospf->distance_inter = 0;
9429 if (argv_find(argv, argc, "external", &idx) || argc == 3)
9430 ospf->distance_external = 0;
9431
9432 return CMD_SUCCESS;
9433 }
9434
9435 DEFUN (ospf_distance_ospf,
9436 ospf_distance_ospf_cmd,
9437 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
9438 "Administrative distance\n"
9439 "OSPF administrative distance\n"
9440 "Intra-area routes\n"
9441 "Distance for intra-area routes\n"
9442 "Inter-area routes\n"
9443 "Distance for inter-area routes\n"
9444 "External routes\n"
9445 "Distance for external routes\n")
9446 {
9447 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9448 int idx = 0;
9449
9450 ospf->distance_intra = 0;
9451 ospf->distance_inter = 0;
9452 ospf->distance_external = 0;
9453
9454 if (argv_find(argv, argc, "intra-area", &idx))
9455 ospf->distance_intra = atoi(argv[idx + 1]->arg);
9456 idx = 0;
9457 if (argv_find(argv, argc, "inter-area", &idx))
9458 ospf->distance_inter = atoi(argv[idx + 1]->arg);
9459 idx = 0;
9460 if (argv_find(argv, argc, "external", &idx))
9461 ospf->distance_external = atoi(argv[idx + 1]->arg);
9462
9463 return CMD_SUCCESS;
9464 }
9465
9466 DEFUN (ip_ospf_mtu_ignore,
9467 ip_ospf_mtu_ignore_addr_cmd,
9468 "ip ospf mtu-ignore [A.B.C.D]",
9469 "IP Information\n"
9470 "OSPF interface commands\n"
9471 "Disable MTU mismatch detection on this interface\n"
9472 "Address of interface\n")
9473 {
9474 VTY_DECLVAR_CONTEXT(interface, ifp);
9475 int idx_ipv4 = 3;
9476 struct in_addr addr;
9477 int ret;
9478
9479 struct ospf_if_params *params;
9480 params = IF_DEF_PARAMS(ifp);
9481
9482 if (argc == 4) {
9483 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
9484 if (!ret) {
9485 vty_out(vty,
9486 "Please specify interface address by A.B.C.D\n");
9487 return CMD_WARNING_CONFIG_FAILED;
9488 }
9489 params = ospf_get_if_params(ifp, addr);
9490 ospf_if_update_params(ifp, addr);
9491 }
9492 params->mtu_ignore = 1;
9493 if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT)
9494 SET_IF_PARAM(params, mtu_ignore);
9495 else {
9496 UNSET_IF_PARAM(params, mtu_ignore);
9497 if (params != IF_DEF_PARAMS(ifp)) {
9498 ospf_free_if_params(ifp, addr);
9499 ospf_if_update_params(ifp, addr);
9500 }
9501 }
9502 return CMD_SUCCESS;
9503 }
9504
9505 DEFUN (no_ip_ospf_mtu_ignore,
9506 no_ip_ospf_mtu_ignore_addr_cmd,
9507 "no ip ospf mtu-ignore [A.B.C.D]",
9508 NO_STR
9509 "IP Information\n"
9510 "OSPF interface commands\n"
9511 "Disable MTU mismatch detection on this interface\n"
9512 "Address of interface\n")
9513 {
9514 VTY_DECLVAR_CONTEXT(interface, ifp);
9515 int idx_ipv4 = 4;
9516 struct in_addr addr;
9517 int ret;
9518
9519 struct ospf_if_params *params;
9520 params = IF_DEF_PARAMS(ifp);
9521
9522 if (argc == 5) {
9523 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
9524 if (!ret) {
9525 vty_out(vty,
9526 "Please specify interface address by A.B.C.D\n");
9527 return CMD_WARNING_CONFIG_FAILED;
9528 }
9529 params = ospf_get_if_params(ifp, addr);
9530 ospf_if_update_params(ifp, addr);
9531 }
9532 params->mtu_ignore = 0;
9533 if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT)
9534 SET_IF_PARAM(params, mtu_ignore);
9535 else {
9536 UNSET_IF_PARAM(params, mtu_ignore);
9537 if (params != IF_DEF_PARAMS(ifp)) {
9538 ospf_free_if_params(ifp, addr);
9539 ospf_if_update_params(ifp, addr);
9540 }
9541 }
9542 return CMD_SUCCESS;
9543 }
9544
9545
9546 DEFUN (ospf_max_metric_router_lsa_admin,
9547 ospf_max_metric_router_lsa_admin_cmd,
9548 "max-metric router-lsa administrative",
9549 "OSPF maximum / infinite-distance metric\n"
9550 "Advertise own Router-LSA with infinite distance (stub router)\n"
9551 "Administratively applied, for an indefinite period\n")
9552 {
9553 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9554 struct listnode *ln;
9555 struct ospf_area *area;
9556
9557 for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
9558 SET_FLAG(area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED);
9559
9560 if (!CHECK_FLAG(area->stub_router_state,
9561 OSPF_AREA_IS_STUB_ROUTED))
9562 ospf_router_lsa_update_area(area);
9563 }
9564
9565 /* Allows for areas configured later to get the property */
9566 ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_SET;
9567
9568 return CMD_SUCCESS;
9569 }
9570
9571 DEFUN (no_ospf_max_metric_router_lsa_admin,
9572 no_ospf_max_metric_router_lsa_admin_cmd,
9573 "no max-metric router-lsa administrative",
9574 NO_STR
9575 "OSPF maximum / infinite-distance metric\n"
9576 "Advertise own Router-LSA with infinite distance (stub router)\n"
9577 "Administratively applied, for an indefinite period\n")
9578 {
9579 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9580 struct listnode *ln;
9581 struct ospf_area *area;
9582
9583 for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
9584 UNSET_FLAG(area->stub_router_state,
9585 OSPF_AREA_ADMIN_STUB_ROUTED);
9586
9587 /* Don't trample on the start-up stub timer */
9588 if (CHECK_FLAG(area->stub_router_state,
9589 OSPF_AREA_IS_STUB_ROUTED)
9590 && !area->t_stub_router) {
9591 UNSET_FLAG(area->stub_router_state,
9592 OSPF_AREA_IS_STUB_ROUTED);
9593 ospf_router_lsa_update_area(area);
9594 }
9595 }
9596 ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET;
9597 return CMD_SUCCESS;
9598 }
9599
9600 DEFUN (ospf_max_metric_router_lsa_startup,
9601 ospf_max_metric_router_lsa_startup_cmd,
9602 "max-metric router-lsa on-startup (5-86400)",
9603 "OSPF maximum / infinite-distance metric\n"
9604 "Advertise own Router-LSA with infinite distance (stub router)\n"
9605 "Automatically advertise stub Router-LSA on startup of OSPF\n"
9606 "Time (seconds) to advertise self as stub-router\n")
9607 {
9608 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9609 int idx_number = 3;
9610 unsigned int seconds;
9611
9612 if (argc < 4) {
9613 vty_out(vty, "%% Must supply stub-router period\n");
9614 return CMD_WARNING_CONFIG_FAILED;
9615 }
9616
9617 seconds = strtoul(argv[idx_number]->arg, NULL, 10);
9618
9619 ospf->stub_router_startup_time = seconds;
9620
9621 return CMD_SUCCESS;
9622 }
9623
9624 DEFUN (no_ospf_max_metric_router_lsa_startup,
9625 no_ospf_max_metric_router_lsa_startup_cmd,
9626 "no max-metric router-lsa on-startup [(5-86400)]",
9627 NO_STR
9628 "OSPF maximum / infinite-distance metric\n"
9629 "Advertise own Router-LSA with infinite distance (stub router)\n"
9630 "Automatically advertise stub Router-LSA on startup of OSPF\n"
9631 "Time (seconds) to advertise self as stub-router\n")
9632 {
9633 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9634 struct listnode *ln;
9635 struct ospf_area *area;
9636
9637 ospf->stub_router_startup_time = OSPF_STUB_ROUTER_UNCONFIGURED;
9638
9639 for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
9640 SET_FLAG(area->stub_router_state,
9641 OSPF_AREA_WAS_START_STUB_ROUTED);
9642 THREAD_OFF(area->t_stub_router);
9643
9644 /* Don't trample on admin stub routed */
9645 if (!CHECK_FLAG(area->stub_router_state,
9646 OSPF_AREA_ADMIN_STUB_ROUTED)) {
9647 UNSET_FLAG(area->stub_router_state,
9648 OSPF_AREA_IS_STUB_ROUTED);
9649 ospf_router_lsa_update_area(area);
9650 }
9651 }
9652 return CMD_SUCCESS;
9653 }
9654
9655
9656 DEFUN (ospf_max_metric_router_lsa_shutdown,
9657 ospf_max_metric_router_lsa_shutdown_cmd,
9658 "max-metric router-lsa on-shutdown (5-100)",
9659 "OSPF maximum / infinite-distance metric\n"
9660 "Advertise own Router-LSA with infinite distance (stub router)\n"
9661 "Advertise stub-router prior to full shutdown of OSPF\n"
9662 "Time (seconds) to wait till full shutdown\n")
9663 {
9664 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9665 int idx_number = 3;
9666 unsigned int seconds;
9667
9668 if (argc < 4) {
9669 vty_out(vty, "%% Must supply stub-router shutdown period\n");
9670 return CMD_WARNING_CONFIG_FAILED;
9671 }
9672
9673 seconds = strtoul(argv[idx_number]->arg, NULL, 10);
9674
9675 ospf->stub_router_shutdown_time = seconds;
9676
9677 return CMD_SUCCESS;
9678 }
9679
9680 DEFUN (no_ospf_max_metric_router_lsa_shutdown,
9681 no_ospf_max_metric_router_lsa_shutdown_cmd,
9682 "no max-metric router-lsa on-shutdown [(5-100)]",
9683 NO_STR
9684 "OSPF maximum / infinite-distance metric\n"
9685 "Advertise own Router-LSA with infinite distance (stub router)\n"
9686 "Advertise stub-router prior to full shutdown of OSPF\n"
9687 "Time (seconds) to wait till full shutdown\n")
9688 {
9689 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9690
9691 ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED;
9692
9693 return CMD_SUCCESS;
9694 }
9695
9696 DEFUN (ospf_proactive_arp,
9697 ospf_proactive_arp_cmd,
9698 "proactive-arp",
9699 "Allow sending ARP requests proactively\n")
9700 {
9701 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9702
9703 ospf->proactive_arp = true;
9704
9705 return CMD_SUCCESS;
9706 }
9707
9708 DEFUN (no_ospf_proactive_arp,
9709 no_ospf_proactive_arp_cmd,
9710 "no proactive-arp",
9711 NO_STR
9712 "Disallow sending ARP requests proactively\n")
9713 {
9714 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9715
9716 ospf->proactive_arp = false;
9717
9718 return CMD_SUCCESS;
9719 }
9720
9721 /* Graceful Restart HELPER Commands */
9722 DEFPY(ospf_gr_helper_enable, ospf_gr_helper_enable_cmd,
9723 "graceful-restart helper enable [A.B.C.D$address]",
9724 "OSPF Graceful Restart\n"
9725 "OSPF GR Helper\n"
9726 "Enable Helper support\n"
9727 "Advertising Router-ID\n")
9728 {
9729 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9730
9731 if (address_str) {
9732 ospf_gr_helper_support_set_per_routerid(ospf, &address,
9733 OSPF_GR_TRUE);
9734 return CMD_SUCCESS;
9735 }
9736
9737 ospf_gr_helper_support_set(ospf, OSPF_GR_TRUE);
9738
9739 return CMD_SUCCESS;
9740 }
9741
9742 DEFPY(no_ospf_gr_helper_enable,
9743 no_ospf_gr_helper_enable_cmd,
9744 "no graceful-restart helper enable [A.B.C.D$address]",
9745 NO_STR
9746 "OSPF Graceful Restart\n"
9747 "OSPF GR Helper\n"
9748 "Enable Helper support\n"
9749 "Advertising Router-ID\n")
9750 {
9751 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9752
9753 if (address_str) {
9754 ospf_gr_helper_support_set_per_routerid(ospf, &address,
9755 OSPF_GR_FALSE);
9756 return CMD_SUCCESS;
9757 }
9758
9759 ospf_gr_helper_support_set(ospf, OSPF_GR_FALSE);
9760 return CMD_SUCCESS;
9761 }
9762
9763 DEFPY(ospf_gr_helper_enable_lsacheck,
9764 ospf_gr_helper_enable_lsacheck_cmd,
9765 "graceful-restart helper strict-lsa-checking",
9766 "OSPF Graceful Restart\n"
9767 "OSPF GR Helper\n"
9768 "Enable strict LSA check\n")
9769 {
9770 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9771
9772 ospf_gr_helper_lsa_check_set(ospf, OSPF_GR_TRUE);
9773 return CMD_SUCCESS;
9774 }
9775
9776 DEFPY(no_ospf_gr_helper_enable_lsacheck,
9777 no_ospf_gr_helper_enable_lsacheck_cmd,
9778 "no graceful-restart helper strict-lsa-checking",
9779 NO_STR
9780 "OSPF Graceful Restart\n"
9781 "OSPF GR Helper\n"
9782 "Disable strict LSA check\n")
9783 {
9784 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9785
9786 ospf_gr_helper_lsa_check_set(ospf, OSPF_GR_FALSE);
9787 return CMD_SUCCESS;
9788 }
9789
9790 DEFPY(ospf_gr_helper_supported_grace_time,
9791 ospf_gr_helper_supported_grace_time_cmd,
9792 "graceful-restart helper supported-grace-time (10-1800)$interval",
9793 "OSPF Graceful Restart\n"
9794 "OSPF GR Helper\n"
9795 "Supported grace timer\n"
9796 "Grace interval(in seconds)\n")
9797 {
9798 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9799
9800 ospf_gr_helper_supported_gracetime_set(ospf, interval);
9801 return CMD_SUCCESS;
9802 }
9803
9804 DEFPY(no_ospf_gr_helper_supported_grace_time,
9805 no_ospf_gr_helper_supported_grace_time_cmd,
9806 "no graceful-restart helper supported-grace-time (10-1800)$interval",
9807 NO_STR
9808 "OSPF Graceful Restart\n"
9809 "OSPF GR Helper\n"
9810 "Supported grace timer\n"
9811 "Grace interval(in seconds)\n")
9812 {
9813 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9814
9815 ospf_gr_helper_supported_gracetime_set(ospf, OSPF_MAX_GRACE_INTERVAL);
9816 return CMD_SUCCESS;
9817 }
9818
9819 DEFPY(ospf_gr_helper_planned_only,
9820 ospf_gr_helper_planned_only_cmd,
9821 "graceful-restart helper planned-only",
9822 "OSPF Graceful Restart\n"
9823 "OSPF GR Helper\n"
9824 "Supported only planned restart\n")
9825 {
9826 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9827
9828 ospf_gr_helper_set_supported_planned_only_restart(ospf, OSPF_GR_TRUE);
9829
9830 return CMD_SUCCESS;
9831 }
9832
9833 /* External Route Aggregation */
9834 DEFUN (ospf_external_route_aggregation,
9835 ospf_external_route_aggregation_cmd,
9836 "summary-address A.B.C.D/M [tag (1-4294967295)]",
9837 "External summary address\n"
9838 "Summary address prefix\n"
9839 "Router tag \n"
9840 "Router tag value\n")
9841 {
9842 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9843 struct prefix_ipv4 p;
9844 int idx = 1;
9845 route_tag_t tag = 0;
9846 int ret = OSPF_SUCCESS;
9847
9848 str2prefix_ipv4(argv[idx]->arg, &p);
9849
9850 if (is_default_prefix4(&p)) {
9851 vty_out(vty,
9852 "Default address shouldn't be configured as summary address.\n");
9853 return CMD_SUCCESS;
9854 }
9855
9856 /* Apply mask for given prefix. */
9857 apply_mask(&p);
9858
9859 if (!is_valid_summary_addr(&p)) {
9860 vty_out(vty, "Not a valid summary address.\n");
9861 return CMD_WARNING_CONFIG_FAILED;
9862 }
9863
9864 if (argc > 2)
9865 tag = strtoul(argv[idx + 2]->arg, NULL, 10);
9866
9867 ret = ospf_asbr_external_aggregator_set(ospf, &p, tag);
9868 if (ret == OSPF_INVALID)
9869 vty_out(vty, "Invalid configuration!!\n");
9870
9871 return CMD_SUCCESS;
9872 }
9873
9874 DEFUN (no_ospf_external_route_aggregation,
9875 no_ospf_external_route_aggregation_cmd,
9876 "no summary-address A.B.C.D/M [tag (1-4294967295)]",
9877 NO_STR
9878 "External summary address\n"
9879 "Summary address prefix\n"
9880 "Router tag\n"
9881 "Router tag value\n")
9882 {
9883 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9884 struct prefix_ipv4 p;
9885 int idx = 2;
9886 route_tag_t tag = 0;
9887 int ret = OSPF_SUCCESS;
9888
9889 str2prefix_ipv4(argv[idx]->arg, &p);
9890
9891 if (is_default_prefix4(&p)) {
9892 vty_out(vty,
9893 "Default address shouldn't be configured as summary address.\n");
9894 return CMD_SUCCESS;
9895 }
9896
9897 /* Apply mask for given prefix. */
9898 apply_mask(&p);
9899
9900 if (!is_valid_summary_addr(&p)) {
9901 vty_out(vty, "Not a valid summary address.\n");
9902 return CMD_WARNING_CONFIG_FAILED;
9903 }
9904
9905 if (argc > 3)
9906 tag = strtoul(argv[idx + 2]->arg, NULL, 10);
9907
9908 ret = ospf_asbr_external_aggregator_unset(ospf, &p, tag);
9909 if (ret == OSPF_INVALID)
9910 vty_out(vty, "Invalid configuration!!\n");
9911
9912 return CMD_SUCCESS;
9913 }
9914
9915 DEFPY(no_ospf_gr_helper_planned_only,
9916 no_ospf_gr_helper_planned_only_cmd,
9917 "no graceful-restart helper planned-only",
9918 NO_STR
9919 "OSPF Graceful Restart\n"
9920 "OSPF GR Helper\n"
9921 "Supported only for planned restart\n")
9922 {
9923 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9924
9925 ospf_gr_helper_set_supported_planned_only_restart(ospf, OSPF_GR_FALSE);
9926
9927 return CMD_SUCCESS;
9928 }
9929
9930 static int ospf_print_vty_helper_dis_rtr_walkcb(struct hash_bucket *bucket,
9931 void *arg)
9932 {
9933 struct advRtr *rtr = bucket->data;
9934 struct vty *vty = (struct vty *)arg;
9935 static unsigned int count;
9936
9937 vty_out(vty, "%-6pI4,", &rtr->advRtrAddr);
9938 count++;
9939
9940 if (count % 5 == 0)
9941 vty_out(vty, "\n");
9942
9943 return HASHWALK_CONTINUE;
9944 }
9945
9946 static int ospf_print_json_helper_enabled_rtr_walkcb(struct hash_bucket *bucket,
9947 void *arg)
9948 {
9949 struct advRtr *rtr = bucket->data;
9950 struct json_object *json_rid_array = arg;
9951 struct json_object *json_rid;
9952
9953 json_rid = json_object_new_object();
9954
9955 json_object_string_addf(json_rid, "routerId", "%pI4", &rtr->advRtrAddr);
9956 json_object_array_add(json_rid_array, json_rid);
9957
9958 return HASHWALK_CONTINUE;
9959 }
9960
9961 static int ospf_show_gr_helper_details(struct vty *vty, struct ospf *ospf,
9962 uint8_t use_vrf, json_object *json,
9963 bool uj, bool detail)
9964 {
9965 struct listnode *node;
9966 struct ospf_interface *oi;
9967 char buf[PREFIX_STRLEN];
9968 json_object *json_vrf = NULL;
9969
9970 if (uj) {
9971 if (use_vrf)
9972 json_vrf = json_object_new_object();
9973 else
9974 json_vrf = json;
9975 }
9976
9977 if (ospf->instance) {
9978 if (uj)
9979 json_object_int_add(json, "ospfInstance",
9980 ospf->instance);
9981 else
9982 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
9983 }
9984
9985 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
9986
9987 if (uj) {
9988 if (use_vrf)
9989 json_object_object_add(json, ospf_get_name(ospf),
9990 json_vrf);
9991 } else
9992 vty_out(vty, "\n");
9993
9994 /* Show Router ID. */
9995 if (uj) {
9996 json_object_string_add(json_vrf, "routerId",
9997 inet_ntop(AF_INET, &ospf->router_id,
9998 buf, sizeof(buf)));
9999 } else {
10000 vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n",
10001 &ospf->router_id);
10002 }
10003
10004 if (!uj) {
10005
10006 if (ospf->is_helper_supported)
10007 vty_out(vty,
10008 " Graceful restart helper support enabled.\n");
10009 else
10010 vty_out(vty,
10011 " Graceful restart helper support disabled.\n");
10012
10013 if (ospf->strict_lsa_check)
10014 vty_out(vty, " Strict LSA check is enabled.\n");
10015 else
10016 vty_out(vty, " Strict LSA check is disabled.\n");
10017
10018 if (ospf->only_planned_restart)
10019 vty_out(vty,
10020 " Helper supported for planned restarts only.\n");
10021 else
10022 vty_out(vty,
10023 " Helper supported for Planned and Unplanned Restarts.\n");
10024
10025 vty_out(vty,
10026 " Supported Graceful restart interval: %d(in seconds).\n",
10027 ospf->supported_grace_time);
10028
10029 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf)) {
10030 vty_out(vty, " Enable Router list:\n");
10031 vty_out(vty, " ");
10032 hash_walk(ospf->enable_rtr_list,
10033 ospf_print_vty_helper_dis_rtr_walkcb, vty);
10034 vty_out(vty, "\n\n");
10035 }
10036
10037 if (ospf->last_exit_reason != OSPF_GR_HELPER_EXIT_NONE) {
10038 vty_out(vty, " Last Helper exit Reason :%s\n",
10039 ospf_exit_reason2str(ospf->last_exit_reason));
10040 }
10041
10042 if (ospf->active_restarter_cnt)
10043 vty_out(vty,
10044 " Number of Active neighbours in graceful restart: %d\n",
10045 ospf->active_restarter_cnt);
10046 else
10047 vty_out(vty, "\n");
10048
10049 } else {
10050 json_object_string_add(
10051 json_vrf, "helperSupport",
10052 (ospf->is_helper_supported) ? "Enabled" : "Disabled");
10053 json_object_string_add(json_vrf, "strictLsaCheck",
10054 (ospf->strict_lsa_check) ? "Enabled"
10055 : "Disabled");
10056 json_object_string_add(
10057 json_vrf, "restartSupoort",
10058 (ospf->only_planned_restart)
10059 ? "Planned Restart only"
10060 : "Planned and Unplanned Restarts");
10061
10062 json_object_int_add(json_vrf, "supportedGracePeriod",
10063 ospf->supported_grace_time);
10064
10065 if (ospf->last_exit_reason != OSPF_GR_HELPER_EXIT_NONE)
10066 json_object_string_add(
10067 json_vrf, "lastExitReason",
10068 ospf_exit_reason2str(ospf->last_exit_reason));
10069
10070 if (ospf->active_restarter_cnt)
10071 json_object_int_add(json_vrf, "activeRestarterCnt",
10072 ospf->active_restarter_cnt);
10073
10074 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf)) {
10075 struct json_object *json_rid_array =
10076 json_object_new_array();
10077
10078 json_object_object_add(json_vrf, "enabledRouterIds",
10079 json_rid_array);
10080
10081 hash_walk(ospf->enable_rtr_list,
10082 ospf_print_json_helper_enabled_rtr_walkcb,
10083 json_rid_array);
10084 }
10085 }
10086
10087
10088 if (detail) {
10089 int cnt = 1;
10090 json_object *json_neighbors = NULL;
10091
10092 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
10093 struct route_node *rn;
10094 struct ospf_neighbor *nbr;
10095 json_object *json_neigh;
10096
10097 if (ospf_interface_neighbor_count(oi) == 0)
10098 continue;
10099
10100 if (uj) {
10101 json_object_object_get_ex(json_vrf, "neighbors",
10102 &json_neighbors);
10103 if (!json_neighbors) {
10104 json_neighbors =
10105 json_object_new_object();
10106 json_object_object_add(json_vrf,
10107 "neighbors",
10108 json_neighbors);
10109 }
10110 }
10111
10112 for (rn = route_top(oi->nbrs); rn;
10113 rn = route_next(rn)) {
10114
10115 if (!rn->info)
10116 continue;
10117
10118 nbr = rn->info;
10119
10120 if (!OSPF_GR_IS_ACTIVE_HELPER(nbr))
10121 continue;
10122
10123 if (!uj) {
10124 vty_out(vty, " Neighbour %d :\n", cnt);
10125 vty_out(vty, " Address : %pI4\n",
10126 &nbr->address.u.prefix4);
10127 vty_out(vty, " Routerid : %pI4\n",
10128 &nbr->router_id);
10129 vty_out(vty,
10130 " Received Grace period : %d(in seconds).\n",
10131 nbr->gr_helper_info
10132 .recvd_grace_period);
10133 vty_out(vty,
10134 " Actual Grace period : %d(in seconds)\n",
10135 nbr->gr_helper_info
10136 .actual_grace_period);
10137 vty_out(vty,
10138 " Remaining GraceTime:%ld(in seconds).\n",
10139 thread_timer_remain_second(
10140 nbr->gr_helper_info
10141 .t_grace_timer));
10142 vty_out(vty,
10143 " Graceful Restart reason: %s.\n\n",
10144 ospf_restart_reason2str(
10145 nbr->gr_helper_info
10146 .gr_restart_reason));
10147 cnt++;
10148 } else {
10149 json_neigh = json_object_new_object();
10150 json_object_string_add(
10151 json_neigh, "srcAddr",
10152 inet_ntop(AF_INET, &nbr->src,
10153 buf, sizeof(buf)));
10154
10155 json_object_string_add(
10156 json_neigh, "routerid",
10157 inet_ntop(AF_INET,
10158 &nbr->router_id,
10159 buf, sizeof(buf)));
10160 json_object_int_add(
10161 json_neigh,
10162 "recvdGraceInterval",
10163 nbr->gr_helper_info
10164 .recvd_grace_period);
10165 json_object_int_add(
10166 json_neigh,
10167 "actualGraceInterval",
10168 nbr->gr_helper_info
10169 .actual_grace_period);
10170 json_object_int_add(
10171 json_neigh, "remainGracetime",
10172 thread_timer_remain_second(
10173 nbr->gr_helper_info
10174 .t_grace_timer));
10175 json_object_string_add(
10176 json_neigh, "restartReason",
10177 ospf_restart_reason2str(
10178 nbr->gr_helper_info
10179 .gr_restart_reason));
10180 json_object_object_add(
10181 json_neighbors,
10182 inet_ntop(AF_INET, &nbr->src,
10183 buf, sizeof(buf)),
10184 json_neigh);
10185 }
10186 }
10187 }
10188 }
10189 return CMD_SUCCESS;
10190 }
10191
10192 DEFUN (ospf_external_route_aggregation_no_adrvertise,
10193 ospf_external_route_aggregation_no_adrvertise_cmd,
10194 "summary-address A.B.C.D/M no-advertise",
10195 "External summary address\n"
10196 "Summary address prefix\n"
10197 "Don't advertise summary route \n")
10198 {
10199 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10200 struct prefix_ipv4 p;
10201 int idx = 1;
10202 int ret = OSPF_SUCCESS;
10203
10204 str2prefix_ipv4(argv[idx]->arg, &p);
10205
10206 if (is_default_prefix4(&p)) {
10207 vty_out(vty,
10208 "Default address shouldn't be configured as summary address.\n");
10209 return CMD_SUCCESS;
10210 }
10211
10212 /* Apply mask for given prefix. */
10213 apply_mask(&p);
10214
10215 if (!is_valid_summary_addr(&p)) {
10216 vty_out(vty, "Not a valid summary address.\n");
10217 return CMD_WARNING_CONFIG_FAILED;
10218 }
10219
10220 ret = ospf_asbr_external_rt_no_advertise(ospf, &p);
10221 if (ret == OSPF_INVALID)
10222 vty_out(vty, "Invalid configuration!!\n");
10223
10224 return CMD_SUCCESS;
10225 }
10226
10227 DEFUN (no_ospf_external_route_aggregation_no_adrvertise,
10228 no_ospf_external_route_aggregation_no_adrvertise_cmd,
10229 "no summary-address A.B.C.D/M no-advertise",
10230 NO_STR
10231 "External summary address\n"
10232 "Summary address prefix\n"
10233 "Advertise summary route to the AS \n")
10234 {
10235 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10236 struct prefix_ipv4 p;
10237 int idx = 2;
10238 int ret = OSPF_SUCCESS;
10239
10240 str2prefix_ipv4(argv[idx]->arg, &p);
10241
10242 if (is_default_prefix4(&p)) {
10243 vty_out(vty,
10244 "Default address shouldn't be configured as summary address.\n");
10245 return CMD_SUCCESS;
10246 }
10247
10248 /* Apply mask for given prefix. */
10249 apply_mask(&p);
10250
10251 if (!is_valid_summary_addr(&p)) {
10252 vty_out(vty, "Not a valid summary address.\n");
10253 return CMD_WARNING_CONFIG_FAILED;
10254 }
10255
10256 ret = ospf_asbr_external_rt_advertise(ospf, &p);
10257 if (ret == OSPF_INVALID)
10258 vty_out(vty, "Invalid configuration!!\n");
10259
10260 return CMD_SUCCESS;
10261 }
10262
10263 DEFUN (ospf_route_aggregation_timer,
10264 ospf_route_aggregation_timer_cmd,
10265 "aggregation timer (5-1800)",
10266 "External route aggregation\n"
10267 "Delay timer (in seconds)\n"
10268 "Timer interval(in seconds)\n")
10269 {
10270 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10271 uint16_t interval = 0;
10272
10273 interval = strtoul(argv[2]->arg, NULL, 10);
10274
10275 ospf_external_aggregator_timer_set(ospf, interval);
10276
10277 return CMD_SUCCESS;
10278 }
10279
10280 DEFPY (show_ip_ospf_gr_helper,
10281 show_ip_ospf_gr_helper_cmd,
10282 "show ip ospf [vrf <NAME|all>] graceful-restart helper [detail] [json]",
10283 SHOW_STR
10284 IP_STR
10285 "OSPF information\n"
10286 VRF_CMD_HELP_STR
10287 "All VRFs\n"
10288 "OSPF Graceful Restart\n"
10289 "Helper details in the router\n"
10290 "Detailed information\n"
10291 JSON_STR)
10292 {
10293 char *vrf_name = NULL;
10294 bool all_vrf = false;
10295 int ret = CMD_SUCCESS;
10296 int idx_vrf = 0;
10297 int idx = 0;
10298 uint8_t use_vrf = 0;
10299 bool uj = use_json(argc, argv);
10300 struct ospf *ospf = NULL;
10301 json_object *json = NULL;
10302 struct listnode *node = NULL;
10303 int inst = 0;
10304 bool detail = false;
10305
10306 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
10307
10308 if (argv_find(argv, argc, "detail", &idx))
10309 detail = true;
10310
10311 if (uj)
10312 json = json_object_new_object();
10313
10314 /* vrf input is provided */
10315 if (vrf_name) {
10316 use_vrf = 1;
10317
10318 if (all_vrf) {
10319 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
10320 if (!ospf->oi_running)
10321 continue;
10322
10323 ret = ospf_show_gr_helper_details(
10324 vty, ospf, use_vrf, json, uj, detail);
10325 }
10326
10327 if (uj)
10328 vty_json(vty, json);
10329
10330 return ret;
10331 }
10332
10333 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
10334
10335 if (ospf == NULL || !ospf->oi_running) {
10336
10337 if (uj)
10338 vty_json(vty, json);
10339 else
10340 vty_out(vty,
10341 "%% OSPF is not enabled in vrf %s\n",
10342 vrf_name);
10343
10344 return CMD_SUCCESS;
10345 }
10346
10347 } else {
10348 /* Default Vrf */
10349 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
10350
10351 if (ospf == NULL || !ospf->oi_running) {
10352
10353 if (uj)
10354 vty_json(vty, json);
10355 else
10356 vty_out(vty,
10357 "%% OSPF is not enabled in vrf default\n");
10358
10359 return CMD_SUCCESS;
10360 }
10361
10362 ospf_show_gr_helper_details(vty, ospf, use_vrf, json, uj,
10363 detail);
10364 }
10365
10366 if (uj)
10367 vty_json(vty, json);
10368
10369 return CMD_SUCCESS;
10370 }
10371 /* Graceful Restart HELPER commands end */
10372 DEFUN (no_ospf_route_aggregation_timer,
10373 no_ospf_route_aggregation_timer_cmd,
10374 "no aggregation timer",
10375 NO_STR
10376 "External route aggregation\n"
10377 "Delay timer\n")
10378 {
10379 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10380
10381 ospf_external_aggregator_timer_set(ospf, OSPF_EXTL_AGGR_DEFAULT_DELAY);
10382
10383 return CMD_SUCCESS;
10384 }
10385
10386 /* External Route Aggregation End */
10387
10388 static void config_write_stub_router(struct vty *vty, struct ospf *ospf)
10389 {
10390 if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED)
10391 vty_out(vty, " max-metric router-lsa on-startup %u\n",
10392 ospf->stub_router_startup_time);
10393 if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED)
10394 vty_out(vty, " max-metric router-lsa on-shutdown %u\n",
10395 ospf->stub_router_shutdown_time);
10396 if (ospf->stub_router_admin_set == OSPF_STUB_ROUTER_ADMINISTRATIVE_SET)
10397 vty_out(vty, " max-metric router-lsa administrative\n");
10398
10399 return;
10400 }
10401
10402 static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf,
10403 struct route_table *rt,
10404 json_object *json)
10405 {
10406 struct route_node *rn;
10407 struct ospf_route * or ;
10408 struct listnode *pnode, *pnnode;
10409 struct ospf_path *path;
10410 json_object *json_route = NULL, *json_nexthop_array = NULL,
10411 *json_nexthop = NULL;
10412
10413 if (!json)
10414 vty_out(vty,
10415 "============ OSPF network routing table ============\n");
10416
10417 for (rn = route_top(rt); rn; rn = route_next(rn)) {
10418 char buf1[PREFIX2STR_BUFFER];
10419
10420 if ((or = rn->info) == NULL)
10421 continue;
10422
10423 prefix2str(&rn->p, buf1, sizeof(buf1));
10424
10425 if (json) {
10426 json_route = json_object_new_object();
10427 json_object_object_add(json, buf1, json_route);
10428 }
10429
10430 switch (or->path_type) {
10431 case OSPF_PATH_INTER_AREA:
10432 if (or->type == OSPF_DESTINATION_NETWORK) {
10433 if (json) {
10434 json_object_string_add(json_route,
10435 "routeType",
10436 "N IA");
10437 json_object_int_add(json_route, "cost",
10438 or->cost);
10439 json_object_string_addf(
10440 json_route, "area", "%pI4",
10441 &or->u.std.area_id);
10442 } else {
10443 vty_out(vty,
10444 "N IA %-18s [%d] area: %pI4\n",
10445 buf1, or->cost,
10446 &or->u.std.area_id);
10447 }
10448 } else if (or->type == OSPF_DESTINATION_DISCARD) {
10449 if (json) {
10450 json_object_string_add(json_route,
10451 "routeType",
10452 "D IA");
10453 } else {
10454 vty_out(vty,
10455 "D IA %-18s Discard entry\n",
10456 buf1);
10457 }
10458 }
10459 break;
10460 case OSPF_PATH_INTRA_AREA:
10461 if (json) {
10462 json_object_string_add(json_route, "routeType",
10463 "N");
10464 json_object_int_add(json_route, "cost",
10465 or->cost);
10466 json_object_string_addf(json_route, "area",
10467 "%pI4",
10468 &or->u.std.area_id);
10469 } else {
10470 vty_out(vty, "N %-18s [%d] area: %pI4\n",
10471 buf1, or->cost,
10472 &or->u.std.area_id);
10473 }
10474 break;
10475 default:
10476 break;
10477 }
10478
10479 if (or->type == OSPF_DESTINATION_NETWORK) {
10480 if (json) {
10481 json_nexthop_array = json_object_new_array();
10482 json_object_object_add(json_route, "nexthops",
10483 json_nexthop_array);
10484 }
10485
10486 for (ALL_LIST_ELEMENTS(or->paths, pnode, pnnode,
10487 path)) {
10488 if (json) {
10489 json_nexthop = json_object_new_object();
10490 json_object_array_add(
10491 json_nexthop_array,
10492 json_nexthop);
10493 }
10494 if (if_lookup_by_index(path->ifindex,
10495 ospf->vrf_id)) {
10496
10497 if (path->nexthop.s_addr
10498 == INADDR_ANY) {
10499 if (json) {
10500 json_object_string_add(
10501 json_nexthop,
10502 "ip", " ");
10503 json_object_string_add(
10504 json_nexthop,
10505 "directlyAttachedTo",
10506 ifindex2ifname(
10507 path->ifindex,
10508 ospf->vrf_id));
10509 } else {
10510 vty_out(vty,
10511 "%24s directly attached to %s\n",
10512 "",
10513 ifindex2ifname(
10514 path->ifindex,
10515 ospf->vrf_id));
10516 }
10517 } else {
10518 if (json) {
10519 json_object_string_addf(
10520 json_nexthop,
10521 "ip", "%pI4",
10522 &path->nexthop);
10523 json_object_string_add(
10524 json_nexthop,
10525 "via",
10526 ifindex2ifname(
10527 path->ifindex,
10528 ospf->vrf_id));
10529 } else {
10530 vty_out(vty,
10531 "%24s via %pI4, %s\n",
10532 "",
10533 &path->nexthop,
10534 ifindex2ifname(
10535 path->ifindex,
10536 ospf->vrf_id));
10537 }
10538 }
10539 }
10540 }
10541 }
10542 }
10543 if (!json)
10544 vty_out(vty, "\n");
10545 }
10546
10547 static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf,
10548 struct route_table *rtrs,
10549 json_object *json)
10550 {
10551 struct route_node *rn;
10552 struct ospf_route * or ;
10553 struct listnode *pnode;
10554 struct listnode *node;
10555 struct ospf_path *path;
10556 char buf[PREFIX_STRLEN];
10557 json_object *json_route = NULL, *json_nexthop_array = NULL,
10558 *json_nexthop = NULL;
10559
10560 if (!json)
10561 vty_out(vty, "============ OSPF %s table =============\n",
10562 ospf->all_rtrs == rtrs ? "reachable routers"
10563 : "router routing");
10564
10565 for (rn = route_top(rtrs); rn; rn = route_next(rn)) {
10566 if (rn->info == NULL)
10567 continue;
10568 int flag = 0;
10569
10570 if (json) {
10571 json_route = json_object_new_object();
10572 json_object_object_add(
10573 json, inet_ntop(AF_INET, &rn->p.u.prefix4,
10574 buf, sizeof(buf)),
10575 json_route);
10576 json_object_string_add(json_route, "routeType", "R ");
10577 } else {
10578 vty_out(vty, "R %-15pI4 ",
10579 &rn->p.u.prefix4);
10580 }
10581
10582 for (ALL_LIST_ELEMENTS_RO((struct list *)rn->info, node, or)) {
10583 if (flag++) {
10584 if (!json)
10585 vty_out(vty, "%24s", "");
10586 }
10587
10588 /* Show path. */
10589 if (json) {
10590 json_object_int_add(json_route, "cost",
10591 or->cost);
10592 json_object_string_addf(json_route, "area",
10593 "%pI4",
10594 &or->u.std.area_id);
10595 if (or->path_type == OSPF_PATH_INTER_AREA) {
10596 json_object_boolean_true_add(json_route,
10597 "IA");
10598 json_object_boolean_true_add(json_route,
10599 "ia");
10600 }
10601 if (or->u.std.flags & ROUTER_LSA_BORDER)
10602 json_object_string_add(json_route,
10603 "routerType",
10604 "abr");
10605 else if (or->u.std.flags & ROUTER_LSA_EXTERNAL)
10606 json_object_string_add(json_route,
10607 "routerType",
10608 "asbr");
10609 } else {
10610 vty_out(vty, "%s [%d] area: %pI4",
10611 (or->path_type == OSPF_PATH_INTER_AREA
10612 ? "IA"
10613 : " "),
10614 or->cost, &or->u.std.area_id);
10615 /* Show flags. */
10616 vty_out(vty, "%s%s\n",
10617 (or->u.std.flags & ROUTER_LSA_BORDER
10618 ? ", ABR"
10619 : ""),
10620 (or->u.std.flags & ROUTER_LSA_EXTERNAL
10621 ? ", ASBR"
10622 : ""));
10623 }
10624
10625 if (json) {
10626 json_nexthop_array = json_object_new_array();
10627 json_object_object_add(json_route, "nexthops",
10628 json_nexthop_array);
10629 }
10630
10631 for (ALL_LIST_ELEMENTS_RO(or->paths, pnode, path)) {
10632 if (json) {
10633 json_nexthop = json_object_new_object();
10634 json_object_array_add(
10635 json_nexthop_array,
10636 json_nexthop);
10637 }
10638 if (if_lookup_by_index(path->ifindex,
10639 ospf->vrf_id)) {
10640 if (path->nexthop.s_addr
10641 == INADDR_ANY) {
10642 if (json) {
10643 json_object_string_add(
10644 json_nexthop,
10645 "ip", " ");
10646 json_object_string_add(
10647 json_nexthop,
10648 "directlyAttachedTo",
10649 ifindex2ifname(
10650 path->ifindex,
10651 ospf->vrf_id));
10652 } else {
10653 vty_out(vty,
10654 "%24s directly attached to %s\n",
10655 "",
10656 ifindex2ifname(
10657 path->ifindex,
10658 ospf->vrf_id));
10659 }
10660 } else {
10661 if (json) {
10662 json_object_string_addf(
10663 json_nexthop,
10664 "ip", "%pI4",
10665 &path->nexthop);
10666 json_object_string_add(
10667 json_nexthop,
10668 "via",
10669 ifindex2ifname(
10670 path->ifindex,
10671 ospf->vrf_id));
10672 } else {
10673 vty_out(vty,
10674 "%24s via %pI4, %s\n",
10675 "",
10676 &path->nexthop,
10677 ifindex2ifname(
10678 path->ifindex,
10679 ospf->vrf_id));
10680 }
10681 }
10682 }
10683 }
10684 }
10685 }
10686 if (!json)
10687 vty_out(vty, "\n");
10688 }
10689
10690 static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf,
10691 struct route_table *rt,
10692 json_object *json)
10693 {
10694 struct route_node *rn;
10695 struct ospf_route *er;
10696 struct listnode *pnode, *pnnode;
10697 struct ospf_path *path;
10698 json_object *json_route = NULL, *json_nexthop_array = NULL,
10699 *json_nexthop = NULL;
10700
10701 if (!json)
10702 vty_out(vty,
10703 "============ OSPF external routing table ===========\n");
10704
10705 for (rn = route_top(rt); rn; rn = route_next(rn)) {
10706 if ((er = rn->info) == NULL)
10707 continue;
10708
10709 char buf1[19];
10710
10711 snprintfrr(buf1, sizeof(buf1), "%pFX", &rn->p);
10712 if (json) {
10713 json_route = json_object_new_object();
10714 json_object_object_add(json, buf1, json_route);
10715 }
10716
10717 switch (er->path_type) {
10718 case OSPF_PATH_TYPE1_EXTERNAL:
10719 if (json) {
10720 json_object_string_add(json_route, "routeType",
10721 "N E1");
10722 json_object_int_add(json_route, "cost",
10723 er->cost);
10724 json_object_int_add(json_route, "tag",
10725 er->u.ext.tag);
10726 } else {
10727 vty_out(vty,
10728 "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI
10729 "\n",
10730 buf1, er->cost, er->u.ext.tag);
10731 }
10732 break;
10733 case OSPF_PATH_TYPE2_EXTERNAL:
10734 if (json) {
10735 json_object_string_add(json_route, "routeType",
10736 "N E2");
10737 json_object_int_add(json_route, "cost",
10738 er->cost);
10739 json_object_int_add(json_route, "type2cost",
10740 er->u.ext.type2_cost);
10741 json_object_int_add(json_route, "tag",
10742 er->u.ext.tag);
10743 } else {
10744 vty_out(vty,
10745 "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI
10746 "\n",
10747 buf1, er->cost, er->u.ext.type2_cost,
10748 er->u.ext.tag);
10749 }
10750 break;
10751 }
10752
10753 if (json) {
10754 json_nexthop_array = json_object_new_array();
10755 json_object_object_add(json_route, "nexthops",
10756 json_nexthop_array);
10757 }
10758
10759 for (ALL_LIST_ELEMENTS(er->paths, pnode, pnnode, path)) {
10760 if (json) {
10761 json_nexthop = json_object_new_object();
10762 json_object_array_add(json_nexthop_array,
10763 json_nexthop);
10764 }
10765
10766 if (if_lookup_by_index(path->ifindex, ospf->vrf_id)) {
10767 if (path->nexthop.s_addr == INADDR_ANY) {
10768 if (json) {
10769 json_object_string_add(
10770 json_nexthop, "ip",
10771 " ");
10772 json_object_string_add(
10773 json_nexthop,
10774 "directlyAttachedTo",
10775 ifindex2ifname(
10776 path->ifindex,
10777 ospf->vrf_id));
10778 } else {
10779 vty_out(vty,
10780 "%24s directly attached to %s\n",
10781 "",
10782 ifindex2ifname(
10783 path->ifindex,
10784 ospf->vrf_id));
10785 }
10786 } else {
10787 if (json) {
10788 json_object_string_addf(
10789 json_nexthop, "ip",
10790 "%pI4", &path->nexthop);
10791 json_object_string_add(
10792 json_nexthop, "via",
10793 ifindex2ifname(
10794 path->ifindex,
10795 ospf->vrf_id));
10796 } else {
10797 vty_out(vty,
10798 "%24s via %pI4, %s\n",
10799 "",
10800 &path->nexthop,
10801 ifindex2ifname(
10802 path->ifindex,
10803 ospf->vrf_id));
10804 }
10805 }
10806 }
10807 }
10808 }
10809 if (!json)
10810 vty_out(vty, "\n");
10811 }
10812
10813 static int show_ip_ospf_reachable_routers_common(struct vty *vty,
10814 struct ospf *ospf,
10815 uint8_t use_vrf)
10816 {
10817 if (ospf->instance)
10818 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
10819
10820 ospf_show_vrf_name(ospf, vty, NULL, use_vrf);
10821
10822 if (ospf->all_rtrs == NULL) {
10823 vty_out(vty, "No OSPF reachable router information exist\n");
10824 return CMD_SUCCESS;
10825 }
10826
10827 /* Show Router routes. */
10828 show_ip_ospf_route_router(vty, ospf, ospf->all_rtrs, NULL);
10829
10830 vty_out(vty, "\n");
10831
10832 return CMD_SUCCESS;
10833 }
10834
10835 DEFUN (show_ip_ospf_reachable_routers,
10836 show_ip_ospf_reachable_routers_cmd,
10837 "show ip ospf [vrf <NAME|all>] reachable-routers",
10838 SHOW_STR
10839 IP_STR
10840 "OSPF information\n"
10841 VRF_CMD_HELP_STR
10842 "All VRFs\n"
10843 "Show all the reachable OSPF routers\n")
10844 {
10845 struct ospf *ospf = NULL;
10846 struct listnode *node = NULL;
10847 char *vrf_name = NULL;
10848 bool all_vrf = false;
10849 int ret = CMD_SUCCESS;
10850 int inst = 0;
10851 int idx_vrf = 0;
10852 uint8_t use_vrf = 0;
10853
10854 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
10855
10856 if (vrf_name) {
10857 bool ospf_output = false;
10858
10859 use_vrf = 1;
10860
10861 if (all_vrf) {
10862 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
10863 if (!ospf->oi_running)
10864 continue;
10865
10866 ospf_output = true;
10867 ret = show_ip_ospf_reachable_routers_common(
10868 vty, ospf, use_vrf);
10869 }
10870
10871 if (!ospf_output)
10872 vty_out(vty, "%% OSPF instance not found\n");
10873 } else {
10874 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
10875 if (ospf == NULL || !ospf->oi_running) {
10876 vty_out(vty, "%% OSPF instance not found\n");
10877 return CMD_SUCCESS;
10878 }
10879
10880 ret = show_ip_ospf_reachable_routers_common(vty, ospf,
10881 use_vrf);
10882 }
10883 } else {
10884 /* Display default ospf (instance 0) info */
10885 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
10886 if (ospf == NULL || !ospf->oi_running) {
10887 vty_out(vty, "%% OSPF instance not found\n");
10888 return CMD_SUCCESS;
10889 }
10890
10891 ret = show_ip_ospf_reachable_routers_common(vty, ospf, use_vrf);
10892 }
10893
10894 return ret;
10895 }
10896
10897 DEFUN (show_ip_ospf_instance_reachable_routers,
10898 show_ip_ospf_instance_reachable_routers_cmd,
10899 "show ip ospf (1-65535) reachable-routers",
10900 SHOW_STR
10901 IP_STR
10902 "OSPF information\n"
10903 "Instance ID\n"
10904 "Show all the reachable OSPF routers\n")
10905 {
10906 int idx_number = 3;
10907 struct ospf *ospf;
10908 unsigned short instance = 0;
10909
10910 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10911 if (instance != ospf_instance)
10912 return CMD_NOT_MY_INSTANCE;
10913
10914 ospf = ospf_lookup_instance(instance);
10915 if (!ospf || !ospf->oi_running)
10916 return CMD_SUCCESS;
10917
10918 return show_ip_ospf_reachable_routers_common(vty, ospf, 0);
10919 }
10920
10921 static int show_ip_ospf_border_routers_common(struct vty *vty,
10922 struct ospf *ospf,
10923 uint8_t use_vrf,
10924 json_object *json)
10925 {
10926 json_object *json_vrf = NULL;
10927 json_object *json_router = NULL;
10928
10929 if (json) {
10930 if (use_vrf)
10931 json_vrf = json_object_new_object();
10932 else
10933 json_vrf = json;
10934 json_router = json_object_new_object();
10935 }
10936
10937 if (ospf->instance) {
10938 if (!json)
10939 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
10940 else
10941 json_object_int_add(json_vrf, "ospfInstance",
10942 ospf->instance);
10943 }
10944
10945 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
10946
10947 if (ospf->new_table == NULL) {
10948 if (!json)
10949 vty_out(vty, "No OSPF routing information exist\n");
10950 else {
10951 json_object_free(json_router);
10952 if (use_vrf)
10953 json_object_free(json_vrf);
10954 }
10955 return CMD_SUCCESS;
10956 }
10957
10958 /* Show Network routes.
10959 show_ip_ospf_route_network (vty, ospf->new_table); */
10960
10961 /* Show Router routes. */
10962 show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, json_router);
10963
10964 if (json) {
10965 json_object_object_add(json_vrf, "routers", json_router);
10966 if (use_vrf) {
10967 if (ospf->vrf_id == VRF_DEFAULT)
10968 json_object_object_add(json, "default",
10969 json_vrf);
10970 else
10971 json_object_object_add(json, ospf->name,
10972 json_vrf);
10973 }
10974 } else {
10975 vty_out(vty, "\n");
10976 }
10977
10978 return CMD_SUCCESS;
10979 }
10980
10981 DEFPY (show_ip_ospf_border_routers,
10982 show_ip_ospf_border_routers_cmd,
10983 "show ip ospf [vrf <NAME|all>] border-routers [json]",
10984 SHOW_STR
10985 IP_STR
10986 "OSPF information\n"
10987 VRF_CMD_HELP_STR
10988 "All VRFs\n"
10989 "Show all the ABR's and ASBR's\n"
10990 JSON_STR)
10991 {
10992 struct ospf *ospf = NULL;
10993 struct listnode *node = NULL;
10994 char *vrf_name = NULL;
10995 bool all_vrf = false;
10996 int ret = CMD_SUCCESS;
10997 int inst = 0;
10998 int idx_vrf = 0;
10999 uint8_t use_vrf = 0;
11000 bool uj = use_json(argc, argv);
11001 json_object *json = NULL;
11002
11003 if (uj)
11004 json = json_object_new_object();
11005
11006 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
11007
11008 if (vrf_name) {
11009 bool ospf_output = false;
11010
11011 use_vrf = 1;
11012
11013 if (all_vrf) {
11014 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11015 if (!ospf->oi_running)
11016 continue;
11017
11018 ospf_output = true;
11019 ret = show_ip_ospf_border_routers_common(
11020 vty, ospf, use_vrf, json);
11021 }
11022
11023 if (uj)
11024 vty_json(vty, json);
11025 else if (!ospf_output)
11026 vty_out(vty, "%% OSPF is not enabled\n");
11027
11028 return ret;
11029 } else {
11030 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
11031 if (ospf == NULL || !ospf->oi_running) {
11032 if (uj)
11033 vty_json(vty, json);
11034 else
11035 vty_out(vty,
11036 "%% OSPF is not enabled in vrf %s\n",
11037 vrf_name);
11038
11039 return CMD_SUCCESS;
11040 }
11041 }
11042 } else {
11043 /* Display default ospf (instance 0) info */
11044 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
11045 if (ospf == NULL || !ospf->oi_running) {
11046 if (uj)
11047 vty_json(vty, json);
11048 else
11049 vty_out(vty,
11050 "%% OSPF is not enabled in vrf default\n");
11051
11052 return CMD_SUCCESS;
11053 }
11054 }
11055
11056 if (ospf) {
11057 ret = show_ip_ospf_border_routers_common(vty, ospf, use_vrf,
11058 json);
11059 if (uj)
11060 vty_json(vty, json);
11061 }
11062
11063 return ret;
11064 }
11065
11066 DEFUN (show_ip_ospf_instance_border_routers,
11067 show_ip_ospf_instance_border_routers_cmd,
11068 "show ip ospf (1-65535) border-routers",
11069 SHOW_STR
11070 IP_STR
11071 "OSPF information\n"
11072 "Instance ID\n"
11073 "Show all the ABR's and ASBR's\n")
11074 {
11075 int idx_number = 3;
11076 struct ospf *ospf;
11077 unsigned short instance = 0;
11078
11079 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11080 if (instance != ospf_instance)
11081 return CMD_NOT_MY_INSTANCE;
11082
11083 ospf = ospf_lookup_instance(instance);
11084 if (!ospf || !ospf->oi_running)
11085 return CMD_SUCCESS;
11086
11087 return show_ip_ospf_border_routers_common(vty, ospf, 0, NULL);
11088 }
11089
11090 static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf,
11091 json_object *json, uint8_t use_vrf)
11092 {
11093 json_object *json_vrf = NULL;
11094
11095 if (ospf->instance)
11096 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
11097
11098
11099 if (json) {
11100 if (use_vrf)
11101 json_vrf = json_object_new_object();
11102 else
11103 json_vrf = json;
11104 }
11105
11106 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
11107
11108 if (ospf->new_table == NULL) {
11109 if (json) {
11110 if (use_vrf)
11111 json_object_free(json_vrf);
11112 } else {
11113 vty_out(vty, "No OSPF routing information exist\n");
11114 }
11115 return CMD_SUCCESS;
11116 }
11117
11118 /* Show Network routes. */
11119 show_ip_ospf_route_network(vty, ospf, ospf->new_table, json_vrf);
11120
11121 /* Show Router routes. */
11122 show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, json_vrf);
11123
11124 /* Show Router routes. */
11125 if (ospf->all_rtrs)
11126 show_ip_ospf_route_router(vty, ospf, ospf->all_rtrs, json_vrf);
11127
11128 /* Show AS External routes. */
11129 show_ip_ospf_route_external(vty, ospf, ospf->old_external_route,
11130 json_vrf);
11131
11132 if (json) {
11133 if (use_vrf) {
11134 // json_object_object_add(json_vrf, "areas",
11135 // json_areas);
11136 json_object_object_add(json, ospf_get_name(ospf),
11137 json_vrf);
11138 }
11139 } else {
11140 vty_out(vty, "\n");
11141 }
11142
11143 return CMD_SUCCESS;
11144 }
11145
11146 DEFUN (show_ip_ospf_route,
11147 show_ip_ospf_route_cmd,
11148 "show ip ospf [vrf <NAME|all>] route [json]",
11149 SHOW_STR
11150 IP_STR
11151 "OSPF information\n"
11152 VRF_CMD_HELP_STR
11153 "All VRFs\n"
11154 "OSPF routing table\n"
11155 JSON_STR)
11156 {
11157 struct ospf *ospf = NULL;
11158 struct listnode *node = NULL;
11159 char *vrf_name = NULL;
11160 bool all_vrf = false;
11161 int ret = CMD_SUCCESS;
11162 int inst = 0;
11163 int idx_vrf = 0;
11164 uint8_t use_vrf = 0;
11165 bool uj = use_json(argc, argv);
11166 json_object *json = NULL;
11167
11168 if (uj)
11169 json = json_object_new_object();
11170
11171 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
11172
11173 /* vrf input is provided could be all or specific vrf*/
11174 if (vrf_name) {
11175 bool ospf_output = false;
11176
11177 use_vrf = 1;
11178
11179 if (all_vrf) {
11180 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11181 if (!ospf->oi_running)
11182 continue;
11183 ospf_output = true;
11184 ret = show_ip_ospf_route_common(vty, ospf, json,
11185 use_vrf);
11186 }
11187
11188 if (uj) {
11189 /* Keep Non-pretty format */
11190 vty_json(vty, json);
11191 } else if (!ospf_output)
11192 vty_out(vty, "%% OSPF is not enabled\n");
11193
11194 return ret;
11195 }
11196 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
11197 if (ospf == NULL || !ospf->oi_running) {
11198 if (uj)
11199 vty_json(vty, json);
11200 else
11201 vty_out(vty,
11202 "%% OSPF is not enabled in vrf %s\n",
11203 vrf_name);
11204
11205 return CMD_SUCCESS;
11206 }
11207 } else {
11208 /* Display default ospf (instance 0) info */
11209 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
11210 if (ospf == NULL || !ospf->oi_running) {
11211 if (uj)
11212 vty_json(vty, json);
11213 else
11214 vty_out(vty,
11215 "%% OSPF is not enabled in vrf default\n");
11216
11217 return CMD_SUCCESS;
11218 }
11219 }
11220
11221 if (ospf) {
11222 ret = show_ip_ospf_route_common(vty, ospf, json, use_vrf);
11223 /* Keep Non-pretty format */
11224 if (uj)
11225 vty_out(vty, "%s\n",
11226 json_object_to_json_string_ext(
11227 json, JSON_C_TO_STRING_NOSLASHESCAPE));
11228 }
11229
11230 if (uj)
11231 json_object_free(json);
11232
11233 return ret;
11234 }
11235
11236 DEFUN (show_ip_ospf_instance_route,
11237 show_ip_ospf_instance_route_cmd,
11238 "show ip ospf (1-65535) route",
11239 SHOW_STR
11240 IP_STR
11241 "OSPF information\n"
11242 "Instance ID\n"
11243 "OSPF routing table\n")
11244 {
11245 int idx_number = 3;
11246 struct ospf *ospf;
11247 unsigned short instance = 0;
11248
11249 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11250 if (instance != ospf_instance)
11251 return CMD_NOT_MY_INSTANCE;
11252
11253 ospf = ospf_lookup_instance(instance);
11254 if (!ospf || !ospf->oi_running)
11255 return CMD_SUCCESS;
11256
11257 return show_ip_ospf_route_common(vty, ospf, NULL, 0);
11258 }
11259
11260
11261 DEFUN (show_ip_ospf_vrfs,
11262 show_ip_ospf_vrfs_cmd,
11263 "show ip ospf vrfs [json]",
11264 SHOW_STR
11265 IP_STR
11266 "OSPF information\n"
11267 "Show OSPF VRFs \n"
11268 JSON_STR)
11269 {
11270 bool uj = use_json(argc, argv);
11271 json_object *json = NULL;
11272 json_object *json_vrfs = NULL;
11273 struct ospf *ospf = NULL;
11274 struct listnode *node = NULL;
11275 int count = 0;
11276 static const char header[] = "Name Id RouterId ";
11277
11278 if (uj) {
11279 json = json_object_new_object();
11280 json_vrfs = json_object_new_object();
11281 }
11282
11283 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11284 json_object *json_vrf = NULL;
11285 const char *name = NULL;
11286 int64_t vrf_id_ui = 0;
11287
11288 count++;
11289
11290 if (!uj && count == 1)
11291 vty_out(vty, "%s\n", header);
11292 if (uj)
11293 json_vrf = json_object_new_object();
11294
11295 name = ospf_get_name(ospf);
11296
11297 vrf_id_ui = (ospf->vrf_id == VRF_UNKNOWN)
11298 ? -1
11299 : (int64_t)ospf->vrf_id;
11300
11301 if (uj) {
11302 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
11303 json_object_string_addf(json_vrf, "routerId", "%pI4",
11304 &ospf->router_id);
11305
11306 json_object_object_add(json_vrfs, name, json_vrf);
11307
11308 } else {
11309 vty_out(vty, "%-25s %-5d %-16pI4 \n", name,
11310 ospf->vrf_id, &ospf->router_id);
11311 }
11312 }
11313
11314 if (uj) {
11315 json_object_object_add(json, "vrfs", json_vrfs);
11316 json_object_int_add(json, "totalVrfs", count);
11317
11318 vty_json(vty, json);
11319 } else {
11320 if (count)
11321 vty_out(vty, "\nTotal number of OSPF VRFs: %d\n",
11322 count);
11323 }
11324
11325 return CMD_SUCCESS;
11326 }
11327 DEFPY (clear_ip_ospf_neighbor,
11328 clear_ip_ospf_neighbor_cmd,
11329 "clear ip ospf [(1-65535)]$instance neighbor [A.B.C.D$nbr_id]",
11330 CLEAR_STR
11331 IP_STR
11332 "OSPF information\n"
11333 "Instance ID\n"
11334 "Reset OSPF Neighbor\n"
11335 "Neighbor ID\n")
11336 {
11337 struct listnode *node;
11338 struct ospf *ospf = NULL;
11339
11340 /* If user does not specify the arguments,
11341 * instance = 0 and nbr_id = 0.0.0.0
11342 */
11343 if (instance != 0) {
11344 /* This means clear only the particular ospf process */
11345 if (instance != ospf_instance)
11346 return CMD_NOT_MY_INSTANCE;
11347 }
11348
11349 /* Clear all the ospf processes */
11350 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11351 if (!ospf->oi_running)
11352 continue;
11353
11354 if (nbr_id_str && IPV4_ADDR_SAME(&ospf->router_id, &nbr_id)) {
11355 vty_out(vty, "Self router-id is not allowed.\r\n ");
11356 return CMD_SUCCESS;
11357 }
11358
11359 ospf_neighbor_reset(ospf, nbr_id, nbr_id_str);
11360 }
11361
11362 return CMD_SUCCESS;
11363 }
11364
11365 DEFPY (clear_ip_ospf_process,
11366 clear_ip_ospf_process_cmd,
11367 "clear ip ospf [(1-65535)]$instance process",
11368 CLEAR_STR
11369 IP_STR
11370 "OSPF information\n"
11371 "Instance ID\n"
11372 "Reset OSPF Process\n")
11373 {
11374 struct listnode *node;
11375 struct ospf *ospf = NULL;
11376
11377 /* Check if instance is not passed as an argument */
11378 if (instance != 0) {
11379 /* This means clear only the particular ospf process */
11380 if (instance != ospf_instance)
11381 return CMD_NOT_MY_INSTANCE;
11382 }
11383
11384 /* Clear all the ospf processes */
11385 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11386 if (!ospf->oi_running)
11387 continue;
11388
11389 ospf_process_reset(ospf);
11390 }
11391
11392 return CMD_SUCCESS;
11393 }
11394
11395 static const char *const ospf_abr_type_str[] = {
11396 "unknown", "standard", "ibm", "cisco", "shortcut"
11397 };
11398
11399 static const char *const ospf_shortcut_mode_str[] = {
11400 "default", "enable", "disable"
11401 };
11402 static int ospf_vty_external_rt_walkcb(struct hash_bucket *bucket,
11403 void *arg)
11404 {
11405 struct external_info *ei = bucket->data;
11406 struct vty *vty = (struct vty *)arg;
11407 static unsigned int count;
11408
11409 vty_out(vty, "%-4pI4/%d, ", &ei->p.prefix, ei->p.prefixlen);
11410 count++;
11411
11412 if (count % 5 == 0)
11413 vty_out(vty, "\n");
11414
11415 if (OSPF_EXTERNAL_RT_COUNT(ei->aggr_route) == count)
11416 count = 0;
11417
11418 return HASHWALK_CONTINUE;
11419 }
11420
11421 static int ospf_json_external_rt_walkcb(struct hash_bucket *bucket,
11422 void *arg)
11423 {
11424 struct external_info *ei = bucket->data;
11425 struct json_object *json = (struct json_object *)arg;
11426 char buf[PREFIX2STR_BUFFER];
11427 char exnalbuf[20];
11428 static unsigned int count;
11429
11430 prefix2str(&ei->p, buf, sizeof(buf));
11431
11432 snprintf(exnalbuf, 20, "Exnl Addr-%d", count);
11433
11434 json_object_string_add(json, exnalbuf, buf);
11435
11436 count++;
11437
11438 if (OSPF_EXTERNAL_RT_COUNT(ei->aggr_route) == count)
11439 count = 0;
11440
11441 return HASHWALK_CONTINUE;
11442 }
11443
11444 static int ospf_show_summary_address(struct vty *vty, struct ospf *ospf,
11445 uint8_t use_vrf, json_object *json,
11446 bool uj, bool detail)
11447 {
11448 struct route_node *rn;
11449 json_object *json_vrf = NULL;
11450 int mtype = 0;
11451 int mval = 0;
11452 static char header[] =
11453 "Summary-address Metric-type Metric Tag External_Rt_count\n";
11454
11455 mtype = metric_type(ospf, 0, ospf->instance);
11456 mval = metric_value(ospf, 0, ospf->instance);
11457
11458 if (!uj)
11459 vty_out(vty, "%s\n", header);
11460
11461 if (uj) {
11462 if (use_vrf)
11463 json_vrf = json_object_new_object();
11464 else
11465 json_vrf = json;
11466 }
11467
11468 if (ospf->instance) {
11469 if (uj)
11470 json_object_int_add(json, "ospfInstance",
11471 ospf->instance);
11472 else
11473 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
11474 }
11475
11476 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
11477
11478 if (!uj) {
11479 vty_out(vty, "aggregation delay interval :%u(in seconds)\n\n",
11480 ospf->aggr_delay_interval);
11481 } else {
11482 json_object_int_add(json_vrf, "aggregationDelayInterval",
11483 ospf->aggr_delay_interval);
11484 }
11485
11486 for (rn = route_top(ospf->rt_aggr_tbl); rn; rn = route_next(rn))
11487 if (rn->info) {
11488 struct ospf_external_aggr_rt *aggr = rn->info;
11489 json_object *json_aggr = NULL;
11490 char buf[PREFIX2STR_BUFFER];
11491
11492 prefix2str(&aggr->p, buf, sizeof(buf));
11493
11494 if (uj) {
11495
11496 json_aggr = json_object_new_object();
11497
11498 json_object_object_add(json_vrf, buf,
11499 json_aggr);
11500 json_object_string_add(json_aggr,
11501 "summaryAddress", buf);
11502 json_object_string_add(
11503 json_aggr, "metricType",
11504 (mtype == EXTERNAL_METRIC_TYPE_1)
11505 ? "E1"
11506 : "E2");
11507
11508 json_object_int_add(json_aggr, "metric", mval);
11509 json_object_int_add(json_aggr, "tag",
11510 aggr->tag);
11511 json_object_int_add(
11512 json_aggr, "externalRouteCount",
11513 OSPF_EXTERNAL_RT_COUNT(aggr));
11514
11515 if (OSPF_EXTERNAL_RT_COUNT(aggr) && detail) {
11516 hash_walk(
11517 aggr->match_extnl_hash,
11518 ospf_json_external_rt_walkcb,
11519 json_aggr);
11520 }
11521
11522 } else {
11523 vty_out(vty, "%-20s", buf);
11524
11525 (mtype == EXTERNAL_METRIC_TYPE_1)
11526 ? vty_out(vty, "%-16s", "E1")
11527 : vty_out(vty, "%-16s", "E2");
11528 vty_out(vty, "%-11d", mval);
11529
11530 vty_out(vty, "%-12u", aggr->tag);
11531
11532 vty_out(vty, "%-5ld\n",
11533 OSPF_EXTERNAL_RT_COUNT(aggr));
11534
11535 if (OSPF_EXTERNAL_RT_COUNT(aggr) && detail) {
11536 vty_out(vty,
11537 "Matched External routes:\n");
11538 hash_walk(
11539 aggr->match_extnl_hash,
11540 ospf_vty_external_rt_walkcb,
11541 vty);
11542 vty_out(vty, "\n");
11543 }
11544
11545 vty_out(vty, "\n");
11546 }
11547 }
11548
11549 if (uj) {
11550 if (use_vrf)
11551 json_object_object_add(json, ospf_get_name(ospf),
11552 json_vrf);
11553 } else
11554 vty_out(vty, "\n");
11555
11556 return CMD_SUCCESS;
11557 }
11558
11559 DEFUN (show_ip_ospf_external_aggregator,
11560 show_ip_ospf_external_aggregator_cmd,
11561 "show ip ospf [vrf <NAME|all>] summary-address [detail] [json]",
11562 SHOW_STR IP_STR
11563 "OSPF information\n"
11564 VRF_CMD_HELP_STR
11565 "All VRFs\n"
11566 "Show external summary addresses\n"
11567 "Detailed information\n"
11568 JSON_STR)
11569 {
11570 char *vrf_name = NULL;
11571 bool all_vrf = false;
11572 int ret = CMD_SUCCESS;
11573 int idx_vrf = 0;
11574 int idx = 0;
11575 uint8_t use_vrf = 0;
11576 bool uj = use_json(argc, argv);
11577 struct ospf *ospf = NULL;
11578 json_object *json = NULL;
11579 struct listnode *node = NULL;
11580 int inst = 0;
11581 bool detail = false;
11582
11583 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
11584
11585 if (argv_find(argv, argc, "detail", &idx))
11586 detail = true;
11587
11588 if (uj)
11589 json = json_object_new_object();
11590
11591 /* vrf input is provided */
11592 if (vrf_name) {
11593 use_vrf = 1;
11594 if (all_vrf) {
11595 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11596 if (!ospf->oi_running)
11597 continue;
11598 ret = ospf_show_summary_address(
11599 vty, ospf, use_vrf, json, uj, detail);
11600 }
11601
11602 if (uj)
11603 vty_json(vty, json);
11604
11605 return ret;
11606 }
11607
11608 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
11609
11610 if (ospf == NULL || !ospf->oi_running) {
11611 if (uj)
11612 vty_json(vty, json);
11613 else
11614 vty_out(vty,
11615 "%% OSPF is not enabled in vrf %s\n",
11616 vrf_name);
11617
11618 return CMD_SUCCESS;
11619 }
11620 ospf_show_summary_address(vty, ospf, use_vrf, json, uj, detail);
11621
11622 } else {
11623 /* Default Vrf */
11624 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
11625 if (ospf == NULL || !ospf->oi_running) {
11626 if (uj)
11627 vty_json(vty, json);
11628 else
11629 vty_out(vty,
11630 "%% OSPF is not enabled in vrf default\n");
11631
11632 return CMD_SUCCESS;
11633 }
11634
11635 ospf_show_summary_address(vty, ospf, use_vrf, json, uj, detail);
11636 }
11637
11638 if (uj)
11639 vty_json(vty, json);
11640 return CMD_SUCCESS;
11641 }
11642
11643 static const char *const ospf_int_type_str[] = {
11644 "unknown", /* should never be used. */
11645 "point-to-point",
11646 "broadcast",
11647 "non-broadcast",
11648 "point-to-multipoint",
11649 "virtual-link", /* should never be used. */
11650 "loopback"
11651 };
11652
11653 static const char *interface_config_auth_str(struct ospf_if_params *params)
11654 {
11655 if (!OSPF_IF_PARAM_CONFIGURED(params, auth_type)
11656 || params->auth_type == OSPF_AUTH_NOTSET)
11657 return NULL;
11658
11659 /* Translation tables are not that much help
11660 * here due to syntax
11661 * of the simple option */
11662 switch (params->auth_type) {
11663
11664 case OSPF_AUTH_NULL:
11665 return " null";
11666
11667 case OSPF_AUTH_SIMPLE:
11668 return "";
11669
11670 case OSPF_AUTH_CRYPTOGRAPHIC:
11671 return " message-digest";
11672 }
11673
11674 return "";
11675 }
11676
11677 static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
11678 {
11679 struct listnode *node;
11680 struct interface *ifp;
11681 struct crypt_key *ck;
11682 struct route_node *rn = NULL;
11683 struct ospf_if_params *params;
11684 const char *auth_str;
11685 int write = 0;
11686
11687 FOR_ALL_INTERFACES (vrf, ifp) {
11688
11689 if (memcmp(ifp->name, "VLINK", 5) == 0)
11690 continue;
11691
11692 if_vty_config_start(vty, ifp);
11693
11694 if (ifp->desc)
11695 vty_out(vty, " description %s\n", ifp->desc);
11696
11697 write++;
11698
11699 params = IF_DEF_PARAMS(ifp);
11700
11701 do {
11702 /* Interface Network print. */
11703 if (OSPF_IF_PARAM_CONFIGURED(params, type)
11704 && params->type != OSPF_IFTYPE_LOOPBACK) {
11705 if (params->type != ospf_default_iftype(ifp)) {
11706 vty_out(vty, " ip ospf network %s",
11707 ospf_int_type_str
11708 [params->type]);
11709 if (params->type
11710 == OSPF_IFTYPE_POINTOPOINT
11711 && params->ptp_dmvpn)
11712 vty_out(vty, " dmvpn");
11713 if (params != IF_DEF_PARAMS(ifp) && rn)
11714 vty_out(vty, " %pI4",
11715 &rn->p.u.prefix4);
11716 vty_out(vty, "\n");
11717 }
11718 }
11719
11720 /* OSPF interface authentication print */
11721 auth_str = interface_config_auth_str(params);
11722 if (auth_str) {
11723 vty_out(vty, " ip ospf authentication%s",
11724 auth_str);
11725 if (params != IF_DEF_PARAMS(ifp) && rn)
11726 vty_out(vty, " %pI4",
11727 &rn->p.u.prefix4);
11728 vty_out(vty, "\n");
11729 }
11730
11731 /* Simple Authentication Password print. */
11732 if (OSPF_IF_PARAM_CONFIGURED(params, auth_simple)
11733 && params->auth_simple[0] != '\0') {
11734 vty_out(vty, " ip ospf authentication-key %s",
11735 params->auth_simple);
11736 if (params != IF_DEF_PARAMS(ifp) && rn)
11737 vty_out(vty, " %pI4",
11738 &rn->p.u.prefix4);
11739 vty_out(vty, "\n");
11740 }
11741
11742 /* Cryptographic Authentication Key print. */
11743 if (params && params->auth_crypt) {
11744 for (ALL_LIST_ELEMENTS_RO(params->auth_crypt,
11745 node, ck)) {
11746 vty_out(vty,
11747 " ip ospf message-digest-key %d md5 %s",
11748 ck->key_id, ck->auth_key);
11749 if (params != IF_DEF_PARAMS(ifp) && rn)
11750 vty_out(vty, " %pI4",
11751 &rn->p.u.prefix4);
11752 vty_out(vty, "\n");
11753 }
11754 }
11755
11756 /* Interface Output Cost print. */
11757 if (OSPF_IF_PARAM_CONFIGURED(params, output_cost_cmd)) {
11758 vty_out(vty, " ip ospf cost %u",
11759 params->output_cost_cmd);
11760 if (params != IF_DEF_PARAMS(ifp) && rn)
11761 vty_out(vty, " %pI4",
11762 &rn->p.u.prefix4);
11763 vty_out(vty, "\n");
11764 }
11765
11766 /* Hello Interval print. */
11767 if (OSPF_IF_PARAM_CONFIGURED(params, v_hello)
11768 && params->v_hello != OSPF_HELLO_INTERVAL_DEFAULT) {
11769 vty_out(vty, " ip ospf hello-interval %u",
11770 params->v_hello);
11771 if (params != IF_DEF_PARAMS(ifp) && rn)
11772 vty_out(vty, " %pI4",
11773 &rn->p.u.prefix4);
11774 vty_out(vty, "\n");
11775 }
11776
11777
11778 /* Router Dead Interval print. */
11779 if (OSPF_IF_PARAM_CONFIGURED(params, v_wait)
11780 && params->is_v_wait_set) {
11781 vty_out(vty, " ip ospf dead-interval ");
11782
11783 /* fast hello ? */
11784 if (OSPF_IF_PARAM_CONFIGURED(params,
11785 fast_hello))
11786 vty_out(vty,
11787 "minimal hello-multiplier %d",
11788 params->fast_hello);
11789 else
11790 vty_out(vty, "%u", params->v_wait);
11791
11792 if (params != IF_DEF_PARAMS(ifp) && rn)
11793 vty_out(vty, " %pI4",
11794 &rn->p.u.prefix4);
11795 vty_out(vty, "\n");
11796 }
11797
11798 /* Router Priority print. */
11799 if (OSPF_IF_PARAM_CONFIGURED(params, priority)
11800 && params->priority
11801 != OSPF_ROUTER_PRIORITY_DEFAULT) {
11802 vty_out(vty, " ip ospf priority %u",
11803 params->priority);
11804 if (params != IF_DEF_PARAMS(ifp) && rn)
11805 vty_out(vty, " %pI4",
11806 &rn->p.u.prefix4);
11807 vty_out(vty, "\n");
11808 }
11809
11810 /* Retransmit Interval print. */
11811 if (OSPF_IF_PARAM_CONFIGURED(params,
11812 retransmit_interval)
11813 && params->retransmit_interval
11814 != OSPF_RETRANSMIT_INTERVAL_DEFAULT) {
11815 vty_out(vty, " ip ospf retransmit-interval %u",
11816 params->retransmit_interval);
11817 if (params != IF_DEF_PARAMS(ifp) && rn)
11818 vty_out(vty, " %pI4",
11819 &rn->p.u.prefix4);
11820 vty_out(vty, "\n");
11821 }
11822
11823 /* Transmit Delay print. */
11824 if (OSPF_IF_PARAM_CONFIGURED(params, transmit_delay)
11825 && params->transmit_delay
11826 != OSPF_TRANSMIT_DELAY_DEFAULT) {
11827 vty_out(vty, " ip ospf transmit-delay %u",
11828 params->transmit_delay);
11829 if (params != IF_DEF_PARAMS(ifp) && rn)
11830 vty_out(vty, " %pI4",
11831 &rn->p.u.prefix4);
11832 vty_out(vty, "\n");
11833 }
11834
11835 /* Area print. */
11836 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
11837 if (ospf_instance)
11838 vty_out(vty, " ip ospf %d",
11839 ospf_instance);
11840 else
11841 vty_out(vty, " ip ospf");
11842
11843 char buf[INET_ADDRSTRLEN];
11844
11845 area_id2str(buf, sizeof(buf), &params->if_area,
11846 params->if_area_id_fmt);
11847 vty_out(vty, " area %s", buf);
11848 if (params != IF_DEF_PARAMS(ifp) && rn)
11849 vty_out(vty, " %pI4",
11850 &rn->p.u.prefix4);
11851 vty_out(vty, "\n");
11852 }
11853
11854 /* bfd print. */
11855 if (params && params->bfd_config)
11856 ospf_bfd_write_config(vty, params);
11857
11858 /* MTU ignore print. */
11859 if (OSPF_IF_PARAM_CONFIGURED(params, mtu_ignore)
11860 && params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) {
11861 if (params->mtu_ignore == 0)
11862 vty_out(vty, " no ip ospf mtu-ignore");
11863 else
11864 vty_out(vty, " ip ospf mtu-ignore");
11865 if (params != IF_DEF_PARAMS(ifp) && rn)
11866 vty_out(vty, " %pI4",
11867 &rn->p.u.prefix4);
11868 vty_out(vty, "\n");
11869 }
11870
11871 if (OSPF_IF_PARAM_CONFIGURED(params,
11872 passive_interface)) {
11873 vty_out(vty, " %sip ospf passive",
11874 params->passive_interface
11875 == OSPF_IF_ACTIVE
11876 ? "no "
11877 : "");
11878 if (params != IF_DEF_PARAMS(ifp) && rn)
11879 vty_out(vty, " %pI4", &rn->p.u.prefix4);
11880 vty_out(vty, "\n");
11881 }
11882
11883 /* LDP-Sync print */
11884 if (params && params->ldp_sync_info)
11885 ospf_ldp_sync_if_write_config(vty, params);
11886
11887 while (1) {
11888 if (rn == NULL)
11889 rn = route_top(IF_OIFS_PARAMS(ifp));
11890 else
11891 rn = route_next(rn);
11892
11893 if (rn == NULL)
11894 break;
11895 params = rn->info;
11896 if (params != NULL)
11897 break;
11898 }
11899 } while (rn);
11900
11901 ospf_opaque_config_write_if(vty, ifp);
11902
11903 if_vty_config_end(vty);
11904 }
11905
11906 return write;
11907 }
11908
11909 /* Configuration write function for ospfd. */
11910 static int config_write_interface(struct vty *vty)
11911 {
11912 int write = 0;
11913 struct vrf *vrf = NULL;
11914
11915 /* Display all VRF aware OSPF interface configuration */
11916 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
11917 write += config_write_interface_one(vty, vrf);
11918 }
11919
11920 return write;
11921 }
11922
11923 static int config_write_network_area(struct vty *vty, struct ospf *ospf)
11924 {
11925 struct route_node *rn;
11926 char buf[INET_ADDRSTRLEN];
11927
11928 /* `network area' print. */
11929 for (rn = route_top(ospf->networks); rn; rn = route_next(rn))
11930 if (rn->info) {
11931 struct ospf_network *n = rn->info;
11932
11933 /* Create Area ID string by specified Area ID format. */
11934 if (n->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD)
11935 inet_ntop(AF_INET, &n->area_id, buf,
11936 sizeof(buf));
11937 else
11938 snprintf(buf, sizeof(buf), "%lu",
11939 (unsigned long int)ntohl(
11940 n->area_id.s_addr));
11941
11942 /* Network print. */
11943 vty_out(vty, " network %pFX area %s\n", &rn->p, buf);
11944 }
11945
11946 return 0;
11947 }
11948
11949 static int config_write_ospf_area(struct vty *vty, struct ospf *ospf)
11950 {
11951 struct listnode *node;
11952 struct ospf_area *area;
11953 char buf[INET_ADDRSTRLEN];
11954
11955 /* Area configuration print. */
11956 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
11957 struct route_node *rn1;
11958
11959 area_id2str(buf, sizeof(buf), &area->area_id,
11960 area->area_id_fmt);
11961
11962 if (area->auth_type != OSPF_AUTH_NULL) {
11963 if (area->auth_type == OSPF_AUTH_SIMPLE)
11964 vty_out(vty, " area %s authentication\n", buf);
11965 else
11966 vty_out(vty,
11967 " area %s authentication message-digest\n",
11968 buf);
11969 }
11970
11971 if (area->shortcut_configured != OSPF_SHORTCUT_DEFAULT)
11972 vty_out(vty, " area %s shortcut %s\n", buf,
11973 ospf_shortcut_mode_str
11974 [area->shortcut_configured]);
11975
11976 if ((area->external_routing == OSPF_AREA_STUB)
11977 || (area->external_routing == OSPF_AREA_NSSA)) {
11978 if (area->external_routing == OSPF_AREA_STUB) {
11979 vty_out(vty, " area %s stub", buf);
11980 if (area->no_summary)
11981 vty_out(vty, " no-summary\n");
11982 vty_out(vty, "\n");
11983 } else if (area->external_routing == OSPF_AREA_NSSA) {
11984 switch (area->NSSATranslatorRole) {
11985 case OSPF_NSSA_ROLE_NEVER:
11986 vty_out(vty,
11987 " area %s nssa translate-never\n",
11988 buf);
11989 break;
11990 case OSPF_NSSA_ROLE_ALWAYS:
11991 vty_out(vty,
11992 " area %s nssa translate-always\n",
11993 buf);
11994 break;
11995 case OSPF_NSSA_ROLE_CANDIDATE:
11996 vty_out(vty, " area %s nssa \n", buf);
11997 break;
11998 }
11999 if (area->no_summary)
12000 vty_out(vty,
12001 " area %s nssa no-summary\n",
12002 buf);
12003 if (area->suppress_fa)
12004 vty_out(vty,
12005 " area %s nssa suppress-fa\n",
12006 buf);
12007 }
12008
12009 if (area->default_cost != 1)
12010 vty_out(vty, " area %s default-cost %d\n", buf,
12011 area->default_cost);
12012 }
12013
12014 for (rn1 = route_top(area->ranges); rn1; rn1 = route_next(rn1))
12015 if (rn1->info) {
12016 struct ospf_area_range *range = rn1->info;
12017
12018 vty_out(vty, " area %s range %pFX", buf,
12019 &rn1->p);
12020
12021 if (range->cost_config
12022 != OSPF_AREA_RANGE_COST_UNSPEC)
12023 vty_out(vty, " cost %d",
12024 range->cost_config);
12025
12026 if (!CHECK_FLAG(range->flags,
12027 OSPF_AREA_RANGE_ADVERTISE))
12028 vty_out(vty, " not-advertise");
12029
12030 if (CHECK_FLAG(range->flags,
12031 OSPF_AREA_RANGE_SUBSTITUTE))
12032 vty_out(vty, " substitute %pI4/%d",
12033 &range->subst_addr,
12034 range->subst_masklen);
12035
12036 vty_out(vty, "\n");
12037 }
12038
12039 if (EXPORT_NAME(area))
12040 vty_out(vty, " area %s export-list %s\n", buf,
12041 EXPORT_NAME(area));
12042
12043 if (IMPORT_NAME(area))
12044 vty_out(vty, " area %s import-list %s\n", buf,
12045 IMPORT_NAME(area));
12046
12047 if (PREFIX_NAME_IN(area))
12048 vty_out(vty, " area %s filter-list prefix %s in\n", buf,
12049 PREFIX_NAME_IN(area));
12050
12051 if (PREFIX_NAME_OUT(area))
12052 vty_out(vty, " area %s filter-list prefix %s out\n",
12053 buf, PREFIX_NAME_OUT(area));
12054
12055 if (area->fr_info.configured)
12056 vty_out(vty, " area %s flood-reduction\n", buf);
12057 }
12058
12059 return 0;
12060 }
12061
12062 static int config_write_ospf_nbr_nbma(struct vty *vty, struct ospf *ospf)
12063 {
12064 struct ospf_nbr_nbma *nbr_nbma;
12065 struct route_node *rn;
12066
12067 /* Static Neighbor configuration print. */
12068 for (rn = route_top(ospf->nbr_nbma); rn; rn = route_next(rn))
12069 if ((nbr_nbma = rn->info)) {
12070 vty_out(vty, " neighbor %pI4", &nbr_nbma->addr);
12071
12072 if (nbr_nbma->priority
12073 != OSPF_NEIGHBOR_PRIORITY_DEFAULT)
12074 vty_out(vty, " priority %d",
12075 nbr_nbma->priority);
12076
12077 if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT)
12078 vty_out(vty, " poll-interval %d",
12079 nbr_nbma->v_poll);
12080
12081 vty_out(vty, "\n");
12082 }
12083
12084 return 0;
12085 }
12086
12087 static int config_write_virtual_link(struct vty *vty, struct ospf *ospf)
12088 {
12089 struct listnode *node;
12090 struct ospf_vl_data *vl_data;
12091 const char *auth_str;
12092 char buf[INET_ADDRSTRLEN];
12093
12094 /* Virtual-Link print */
12095 for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl_data)) {
12096 struct listnode *n2;
12097 struct crypt_key *ck;
12098 struct ospf_interface *oi;
12099
12100 if (vl_data != NULL) {
12101 area_id2str(buf, sizeof(buf), &vl_data->vl_area_id,
12102 vl_data->vl_area_id_fmt);
12103 oi = vl_data->vl_oi;
12104
12105 /* timers */
12106 if (OSPF_IF_PARAM(oi, v_hello)
12107 != OSPF_HELLO_INTERVAL_DEFAULT
12108 || OSPF_IF_PARAM(oi, v_wait)
12109 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
12110 || OSPF_IF_PARAM(oi, retransmit_interval)
12111 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
12112 || OSPF_IF_PARAM(oi, transmit_delay)
12113 != OSPF_TRANSMIT_DELAY_DEFAULT)
12114 vty_out(vty,
12115 " area %s virtual-link %pI4 hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n",
12116 buf, &vl_data->vl_peer,
12117 OSPF_IF_PARAM(oi, v_hello),
12118 OSPF_IF_PARAM(oi, retransmit_interval),
12119 OSPF_IF_PARAM(oi, transmit_delay),
12120 OSPF_IF_PARAM(oi, v_wait));
12121 else
12122 vty_out(vty, " area %s virtual-link %pI4\n", buf,
12123 &vl_data->vl_peer);
12124 /* Auth type */
12125 auth_str = interface_config_auth_str(
12126 IF_DEF_PARAMS(oi->ifp));
12127 if (auth_str)
12128 vty_out(vty,
12129 " area %s virtual-link %pI4 authentication%s\n",
12130 buf, &vl_data->vl_peer, auth_str);
12131 /* Auth key */
12132 if (IF_DEF_PARAMS(vl_data->vl_oi->ifp)->auth_simple[0]
12133 != '\0')
12134 vty_out(vty,
12135 " area %s virtual-link %pI4 authentication-key %s\n",
12136 buf, &vl_data->vl_peer,
12137 IF_DEF_PARAMS(vl_data->vl_oi->ifp)
12138 ->auth_simple);
12139 /* md5 keys */
12140 for (ALL_LIST_ELEMENTS_RO(
12141 IF_DEF_PARAMS(vl_data->vl_oi->ifp)
12142 ->auth_crypt,
12143 n2, ck))
12144 vty_out(vty,
12145 " area %s virtual-link %pI4 message-digest-key %d md5 %s\n",
12146 buf, &vl_data->vl_peer,
12147 ck->key_id, ck->auth_key);
12148 }
12149 }
12150
12151 return 0;
12152 }
12153
12154
12155 static int config_write_ospf_redistribute(struct vty *vty, struct ospf *ospf)
12156 {
12157 int type;
12158
12159 /* redistribute print. */
12160 for (type = 0; type < ZEBRA_ROUTE_MAX; type++) {
12161 struct list *red_list;
12162 struct listnode *node;
12163 struct ospf_redist *red;
12164
12165 red_list = ospf->redist[type];
12166 if (!red_list)
12167 continue;
12168
12169 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12170 vty_out(vty, " redistribute %s",
12171 zebra_route_string(type));
12172 if (red->instance)
12173 vty_out(vty, " %d", red->instance);
12174
12175 if (red->dmetric.value >= 0)
12176 vty_out(vty, " metric %d", red->dmetric.value);
12177
12178 if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1)
12179 vty_out(vty, " metric-type 1");
12180
12181 if (ROUTEMAP_NAME(red))
12182 vty_out(vty, " route-map %s",
12183 ROUTEMAP_NAME(red));
12184
12185 vty_out(vty, "\n");
12186 }
12187 }
12188
12189 return 0;
12190 }
12191
12192 static int ospf_cfg_write_helper_dis_rtr_walkcb(struct hash_bucket *bucket,
12193 void *arg)
12194 {
12195 struct advRtr *rtr = bucket->data;
12196 struct vty *vty = (struct vty *)arg;
12197
12198 vty_out(vty, " graceful-restart helper enable %pI4\n",
12199 &rtr->advRtrAddr);
12200 return HASHWALK_CONTINUE;
12201 }
12202
12203 static void config_write_ospf_gr(struct vty *vty, struct ospf *ospf)
12204 {
12205 if (!ospf->gr_info.restart_support)
12206 return;
12207
12208 if (ospf->gr_info.grace_period == OSPF_DFLT_GRACE_INTERVAL)
12209 vty_out(vty, " graceful-restart\n");
12210 else
12211 vty_out(vty, " graceful-restart grace-period %u\n",
12212 ospf->gr_info.grace_period);
12213 }
12214
12215 static int config_write_ospf_gr_helper(struct vty *vty, struct ospf *ospf)
12216 {
12217 if (ospf->is_helper_supported)
12218 vty_out(vty, " graceful-restart helper enable\n");
12219
12220 if (!ospf->strict_lsa_check)
12221 vty_out(vty,
12222 " no graceful-restart helper strict-lsa-checking\n");
12223
12224 if (ospf->only_planned_restart)
12225 vty_out(vty, " graceful-restart helper planned-only\n");
12226
12227 if (ospf->supported_grace_time != OSPF_MAX_GRACE_INTERVAL)
12228 vty_out(vty,
12229 " graceful-restart helper supported-grace-time %d\n",
12230 ospf->supported_grace_time);
12231
12232 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf)) {
12233 hash_walk(ospf->enable_rtr_list,
12234 ospf_cfg_write_helper_dis_rtr_walkcb, vty);
12235 }
12236 return 0;
12237 }
12238
12239 static int config_write_ospf_external_aggregator(struct vty *vty,
12240 struct ospf *ospf)
12241 {
12242 struct route_node *rn;
12243
12244 if (ospf->aggr_delay_interval != OSPF_EXTL_AGGR_DEFAULT_DELAY)
12245 vty_out(vty, " aggregation timer %u\n",
12246 ospf->aggr_delay_interval);
12247
12248 /* print 'summary-address A.B.C.D/M' */
12249 for (rn = route_top(ospf->rt_aggr_tbl); rn; rn = route_next(rn))
12250 if (rn->info) {
12251 struct ospf_external_aggr_rt *aggr = rn->info;
12252
12253 vty_out(vty, " summary-address %pI4/%d",
12254 &aggr->p.prefix, aggr->p.prefixlen);
12255 if (aggr->tag)
12256 vty_out(vty, " tag %u", aggr->tag);
12257
12258 if (CHECK_FLAG(aggr->flags,
12259 OSPF_EXTERNAL_AGGRT_NO_ADVERTISE))
12260 vty_out(vty, " no-advertise");
12261
12262 vty_out(vty, "\n");
12263 }
12264
12265 return 0;
12266 }
12267
12268 static int config_write_ospf_default_metric(struct vty *vty, struct ospf *ospf)
12269 {
12270 if (ospf->default_metric != -1)
12271 vty_out(vty, " default-metric %d\n", ospf->default_metric);
12272 return 0;
12273 }
12274
12275 static int config_write_ospf_distribute(struct vty *vty, struct ospf *ospf)
12276 {
12277 int type;
12278 struct ospf_redist *red;
12279
12280 if (ospf) {
12281 /* distribute-list print. */
12282 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
12283 if (DISTRIBUTE_NAME(ospf, type))
12284 vty_out(vty, " distribute-list %s out %s\n",
12285 DISTRIBUTE_NAME(ospf, type),
12286 zebra_route_string(type));
12287
12288 /* default-information print. */
12289 if (ospf->default_originate != DEFAULT_ORIGINATE_NONE) {
12290 vty_out(vty, " default-information originate");
12291 if (ospf->default_originate == DEFAULT_ORIGINATE_ALWAYS)
12292 vty_out(vty, " always");
12293
12294 red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0);
12295 if (red) {
12296 if (red->dmetric.value >= 0)
12297 vty_out(vty, " metric %d",
12298 red->dmetric.value);
12299
12300 if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1)
12301 vty_out(vty, " metric-type 1");
12302
12303 if (ROUTEMAP_NAME(red))
12304 vty_out(vty, " route-map %s",
12305 ROUTEMAP_NAME(red));
12306 }
12307
12308 vty_out(vty, "\n");
12309 }
12310 }
12311
12312 return 0;
12313 }
12314
12315 static int config_write_ospf_distance(struct vty *vty, struct ospf *ospf)
12316 {
12317 struct route_node *rn;
12318 struct ospf_distance *odistance;
12319
12320 if (ospf->distance_all)
12321 vty_out(vty, " distance %d\n", ospf->distance_all);
12322
12323 if (ospf->distance_intra || ospf->distance_inter
12324 || ospf->distance_external) {
12325 vty_out(vty, " distance ospf");
12326
12327 if (ospf->distance_intra)
12328 vty_out(vty, " intra-area %d", ospf->distance_intra);
12329 if (ospf->distance_inter)
12330 vty_out(vty, " inter-area %d", ospf->distance_inter);
12331 if (ospf->distance_external)
12332 vty_out(vty, " external %d", ospf->distance_external);
12333
12334 vty_out(vty, "\n");
12335 }
12336
12337 for (rn = route_top(ospf->distance_table); rn; rn = route_next(rn))
12338 if ((odistance = rn->info) != NULL) {
12339 vty_out(vty, " distance %d %pFX %s\n",
12340 odistance->distance, &rn->p,
12341 odistance->access_list ? odistance->access_list
12342 : "");
12343 }
12344 return 0;
12345 }
12346
12347 static int ospf_config_write_one(struct vty *vty, struct ospf *ospf)
12348 {
12349 int write = 0;
12350
12351 /* `router ospf' print. */
12352 if (ospf->instance && strcmp(ospf->name, VRF_DEFAULT_NAME)) {
12353 vty_out(vty, "router ospf %d vrf %s\n", ospf->instance,
12354 ospf->name);
12355 } else if (ospf->instance) {
12356 vty_out(vty, "router ospf %d\n", ospf->instance);
12357 } else if (strcmp(ospf->name, VRF_DEFAULT_NAME)) {
12358 vty_out(vty, "router ospf vrf %s\n", ospf->name);
12359 } else
12360 vty_out(vty, "router ospf\n");
12361
12362 if (!ospf->networks) {
12363 write++;
12364 return write;
12365 }
12366
12367 /* Router ID print. */
12368 if (ospf->router_id_static.s_addr != INADDR_ANY)
12369 vty_out(vty, " ospf router-id %pI4\n",
12370 &ospf->router_id_static);
12371
12372 /* zebra opaque attributes configuration. */
12373 if (CHECK_FLAG(ospf->config, OSPF_SEND_EXTRA_DATA_TO_ZEBRA))
12374 vty_out(vty, " ospf send-extra-data zebra\n");
12375
12376 /* ABR type print. */
12377 if (ospf->abr_type != OSPF_ABR_DEFAULT)
12378 vty_out(vty, " ospf abr-type %s\n",
12379 ospf_abr_type_str[ospf->abr_type]);
12380
12381 /* log-adjacency-changes flag print. */
12382 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) {
12383 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL))
12384 vty_out(vty, " log-adjacency-changes detail\n");
12385 else if (!SAVE_OSPF_LOG_ADJACENCY_CHANGES)
12386 vty_out(vty, " log-adjacency-changes\n");
12387 } else if (SAVE_OSPF_LOG_ADJACENCY_CHANGES) {
12388 vty_out(vty, " no log-adjacency-changes\n");
12389 }
12390
12391 /* RFC1583 compatibility flag print -- Compatible with CISCO
12392 * 12.1. */
12393 if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE))
12394 vty_out(vty, " compatible rfc1583\n");
12395
12396 /* auto-cost reference-bandwidth configuration. */
12397 if (ospf->ref_bandwidth != OSPF_DEFAULT_REF_BANDWIDTH) {
12398 vty_out(vty,
12399 "! Important: ensure reference bandwidth is consistent across all routers\n");
12400 vty_out(vty, " auto-cost reference-bandwidth %d\n",
12401 ospf->ref_bandwidth);
12402 }
12403
12404 /* SPF timers print. */
12405 if (ospf->spf_delay != OSPF_SPF_DELAY_DEFAULT
12406 || ospf->spf_holdtime != OSPF_SPF_HOLDTIME_DEFAULT
12407 || ospf->spf_max_holdtime != OSPF_SPF_MAX_HOLDTIME_DEFAULT)
12408 vty_out(vty, " timers throttle spf %d %d %d\n", ospf->spf_delay,
12409 ospf->spf_holdtime, ospf->spf_max_holdtime);
12410
12411 /* LSA timers print. */
12412 if (ospf->min_ls_interval != OSPF_MIN_LS_INTERVAL)
12413 vty_out(vty, " timers throttle lsa all %d\n",
12414 ospf->min_ls_interval);
12415 if (ospf->min_ls_arrival != OSPF_MIN_LS_ARRIVAL)
12416 vty_out(vty, " timers lsa min-arrival %d\n",
12417 ospf->min_ls_arrival);
12418
12419 /* Write multiplier print. */
12420 if (ospf->write_oi_count != OSPF_WRITE_INTERFACE_COUNT_DEFAULT)
12421 vty_out(vty, " ospf write-multiplier %d\n",
12422 ospf->write_oi_count);
12423
12424 if (ospf->max_multipath != MULTIPATH_NUM)
12425 vty_out(vty, " maximum-paths %d\n", ospf->max_multipath);
12426
12427 /* Max-metric router-lsa print */
12428 config_write_stub_router(vty, ospf);
12429
12430 /* SPF refresh parameters print. */
12431 if (ospf->lsa_refresh_interval != OSPF_LSA_REFRESH_INTERVAL_DEFAULT)
12432 vty_out(vty, " refresh timer %d\n", ospf->lsa_refresh_interval);
12433
12434 if (ospf->fr_configured)
12435 vty_out(vty, " flood-reduction\n");
12436
12437 /* Redistribute information print. */
12438 config_write_ospf_redistribute(vty, ospf);
12439
12440 /* Graceful Restart print */
12441 config_write_ospf_gr(vty, ospf);
12442 config_write_ospf_gr_helper(vty, ospf);
12443
12444 /* Print external route aggregation. */
12445 config_write_ospf_external_aggregator(vty, ospf);
12446
12447 /* passive-interface print. */
12448 if (ospf->passive_interface_default == OSPF_IF_PASSIVE)
12449 vty_out(vty, " passive-interface default\n");
12450
12451 /* proactive-arp print. */
12452 if (ospf->proactive_arp != OSPF_PROACTIVE_ARP_DEFAULT) {
12453 if (ospf->proactive_arp)
12454 vty_out(vty, " proactive-arp\n");
12455 else
12456 vty_out(vty, " no proactive-arp\n");
12457 }
12458
12459 /* TI-LFA print. */
12460 if (ospf->ti_lfa_enabled) {
12461 if (ospf->ti_lfa_protection_type == OSPF_TI_LFA_NODE_PROTECTION)
12462 vty_out(vty, " fast-reroute ti-lfa node-protection\n");
12463 else
12464 vty_out(vty, " fast-reroute ti-lfa\n");
12465 }
12466
12467 /* Network area print. */
12468 config_write_network_area(vty, ospf);
12469
12470 /* Area config print. */
12471 config_write_ospf_area(vty, ospf);
12472
12473 /* static neighbor print. */
12474 config_write_ospf_nbr_nbma(vty, ospf);
12475
12476 /* Virtual-Link print. */
12477 config_write_virtual_link(vty, ospf);
12478
12479 /* Default metric configuration. */
12480 config_write_ospf_default_metric(vty, ospf);
12481
12482 /* Distribute-list and default-information print. */
12483 config_write_ospf_distribute(vty, ospf);
12484
12485 /* Distance configuration. */
12486 config_write_ospf_distance(vty, ospf);
12487
12488 ospf_opaque_config_write_router(vty, ospf);
12489
12490 /* LDP-Sync print */
12491 ospf_ldp_sync_write_config(vty, ospf);
12492
12493 vty_out(vty, "exit\n");
12494
12495 write++;
12496 return write;
12497 }
12498
12499 /* OSPF configuration write function. */
12500 static int ospf_config_write(struct vty *vty)
12501 {
12502 struct ospf *ospf;
12503 struct listnode *ospf_node = NULL;
12504 int write = 0;
12505
12506 if (listcount(om->ospf) == 0)
12507 return write;
12508
12509 for (ALL_LIST_ELEMENTS_RO(om->ospf, ospf_node, ospf)) {
12510 /* VRF Default check if it is running.
12511 * Upon daemon start, there could be default instance
12512 * in absence of 'router ospf'/oi_running is disabled. */
12513 if (ospf->vrf_id == VRF_DEFAULT && ospf->oi_running)
12514 write += ospf_config_write_one(vty, ospf);
12515 /* For Non-Default VRF simply display the configuration,
12516 * even if it is not oi_running. */
12517 else if (ospf->vrf_id != VRF_DEFAULT)
12518 write += ospf_config_write_one(vty, ospf);
12519 }
12520 return write;
12521 }
12522
12523 void ospf_vty_show_init(void)
12524 {
12525 /* "show ip ospf" commands. */
12526 install_element(VIEW_NODE, &show_ip_ospf_cmd);
12527
12528 install_element(VIEW_NODE, &show_ip_ospf_instance_cmd);
12529
12530 /* "show ip ospf database" commands. */
12531 install_element(VIEW_NODE, &show_ip_ospf_database_cmd);
12532
12533 /* "show ip ospf interface" commands. */
12534 install_element(VIEW_NODE, &show_ip_ospf_interface_cmd);
12535
12536 install_element(VIEW_NODE, &show_ip_ospf_instance_interface_cmd);
12537 /* "show ip ospf interface traffic */
12538 install_element(VIEW_NODE, &show_ip_ospf_interface_traffic_cmd);
12539
12540 /* "show ip ospf neighbor" commands. */
12541 install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_detail_cmd);
12542 install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_cmd);
12543 install_element(VIEW_NODE, &show_ip_ospf_neighbor_id_cmd);
12544 install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_all_cmd);
12545 install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_cmd);
12546 install_element(VIEW_NODE, &show_ip_ospf_neighbor_cmd);
12547 install_element(VIEW_NODE, &show_ip_ospf_neighbor_all_cmd);
12548
12549 install_element(VIEW_NODE,
12550 &show_ip_ospf_instance_neighbor_int_detail_cmd);
12551 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_int_cmd);
12552 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_id_cmd);
12553 install_element(VIEW_NODE,
12554 &show_ip_ospf_instance_neighbor_detail_all_cmd);
12555 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_detail_cmd);
12556 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_cmd);
12557 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_all_cmd);
12558
12559 /* "show ip ospf route" commands. */
12560 install_element(VIEW_NODE, &show_ip_ospf_route_cmd);
12561 install_element(VIEW_NODE, &show_ip_ospf_border_routers_cmd);
12562 install_element(VIEW_NODE, &show_ip_ospf_reachable_routers_cmd);
12563
12564 install_element(VIEW_NODE, &show_ip_ospf_instance_route_cmd);
12565 install_element(VIEW_NODE, &show_ip_ospf_instance_border_routers_cmd);
12566 install_element(VIEW_NODE,
12567 &show_ip_ospf_instance_reachable_routers_cmd);
12568
12569 /* "show ip ospf vrfs" commands. */
12570 install_element(VIEW_NODE, &show_ip_ospf_vrfs_cmd);
12571
12572 /* "show ip ospf gr-helper details" command */
12573 install_element(VIEW_NODE, &show_ip_ospf_gr_helper_cmd);
12574
12575 /* "show ip ospf summary-address" command */
12576 install_element(VIEW_NODE, &show_ip_ospf_external_aggregator_cmd);
12577 }
12578
12579 /* Initialization of OSPF interface. */
12580 static void ospf_vty_if_init(void)
12581 {
12582 /* Install interface node. */
12583 if_cmd_init(config_write_interface);
12584
12585 /* "ip ospf authentication" commands. */
12586 install_element(INTERFACE_NODE, &ip_ospf_authentication_args_addr_cmd);
12587 install_element(INTERFACE_NODE, &ip_ospf_authentication_addr_cmd);
12588 install_element(INTERFACE_NODE,
12589 &no_ip_ospf_authentication_args_addr_cmd);
12590 install_element(INTERFACE_NODE, &no_ip_ospf_authentication_addr_cmd);
12591 install_element(INTERFACE_NODE, &ip_ospf_authentication_key_addr_cmd);
12592 install_element(INTERFACE_NODE,
12593 &no_ip_ospf_authentication_key_authkey_addr_cmd);
12594 install_element(INTERFACE_NODE,
12595 &no_ospf_authentication_key_authkey_addr_cmd);
12596
12597 /* "ip ospf message-digest-key" commands. */
12598 install_element(INTERFACE_NODE, &ip_ospf_message_digest_key_cmd);
12599 install_element(INTERFACE_NODE, &no_ip_ospf_message_digest_key_cmd);
12600
12601 /* "ip ospf cost" commands. */
12602 install_element(INTERFACE_NODE, &ip_ospf_cost_cmd);
12603 install_element(INTERFACE_NODE, &no_ip_ospf_cost_cmd);
12604
12605 /* "ip ospf mtu-ignore" commands. */
12606 install_element(INTERFACE_NODE, &ip_ospf_mtu_ignore_addr_cmd);
12607 install_element(INTERFACE_NODE, &no_ip_ospf_mtu_ignore_addr_cmd);
12608
12609 /* "ip ospf dead-interval" commands. */
12610 install_element(INTERFACE_NODE, &ip_ospf_dead_interval_cmd);
12611 install_element(INTERFACE_NODE,
12612 &ip_ospf_dead_interval_minimal_addr_cmd);
12613 install_element(INTERFACE_NODE, &no_ip_ospf_dead_interval_cmd);
12614
12615 /* "ip ospf hello-interval" commands. */
12616 install_element(INTERFACE_NODE, &ip_ospf_hello_interval_cmd);
12617 install_element(INTERFACE_NODE, &no_ip_ospf_hello_interval_cmd);
12618
12619 /* "ip ospf network" commands. */
12620 install_element(INTERFACE_NODE, &ip_ospf_network_cmd);
12621 install_element(INTERFACE_NODE, &no_ip_ospf_network_cmd);
12622
12623 /* "ip ospf priority" commands. */
12624 install_element(INTERFACE_NODE, &ip_ospf_priority_cmd);
12625 install_element(INTERFACE_NODE, &no_ip_ospf_priority_cmd);
12626
12627 /* "ip ospf retransmit-interval" commands. */
12628 install_element(INTERFACE_NODE, &ip_ospf_retransmit_interval_addr_cmd);
12629 install_element(INTERFACE_NODE,
12630 &no_ip_ospf_retransmit_interval_addr_cmd);
12631
12632 /* "ip ospf transmit-delay" commands. */
12633 install_element(INTERFACE_NODE, &ip_ospf_transmit_delay_addr_cmd);
12634 install_element(INTERFACE_NODE, &no_ip_ospf_transmit_delay_addr_cmd);
12635
12636 /* "ip ospf area" commands. */
12637 install_element(INTERFACE_NODE, &ip_ospf_area_cmd);
12638 install_element(INTERFACE_NODE, &no_ip_ospf_area_cmd);
12639
12640 /* "ip ospf passive" commands. */
12641 install_element(INTERFACE_NODE, &ip_ospf_passive_cmd);
12642 install_element(INTERFACE_NODE, &no_ip_ospf_passive_cmd);
12643
12644 /* These commands are compatibitliy for previous version. */
12645 install_element(INTERFACE_NODE, &ospf_authentication_key_cmd);
12646 install_element(INTERFACE_NODE, &ospf_message_digest_key_cmd);
12647 install_element(INTERFACE_NODE, &no_ospf_message_digest_key_cmd);
12648 install_element(INTERFACE_NODE, &ospf_dead_interval_cmd);
12649 install_element(INTERFACE_NODE, &no_ospf_dead_interval_cmd);
12650 install_element(INTERFACE_NODE, &ospf_hello_interval_cmd);
12651 install_element(INTERFACE_NODE, &no_ospf_hello_interval_cmd);
12652 install_element(INTERFACE_NODE, &ospf_cost_cmd);
12653 install_element(INTERFACE_NODE, &no_ospf_cost_cmd);
12654 install_element(INTERFACE_NODE, &ospf_network_cmd);
12655 install_element(INTERFACE_NODE, &no_ospf_network_cmd);
12656 install_element(INTERFACE_NODE, &ospf_priority_cmd);
12657 install_element(INTERFACE_NODE, &no_ospf_priority_cmd);
12658 install_element(INTERFACE_NODE, &ospf_retransmit_interval_cmd);
12659 install_element(INTERFACE_NODE, &no_ospf_retransmit_interval_cmd);
12660 install_element(INTERFACE_NODE, &ospf_transmit_delay_cmd);
12661 install_element(INTERFACE_NODE, &no_ospf_transmit_delay_cmd);
12662 }
12663
12664 static void ospf_vty_zebra_init(void)
12665 {
12666 install_element(OSPF_NODE, &ospf_redistribute_source_cmd);
12667 install_element(OSPF_NODE, &no_ospf_redistribute_source_cmd);
12668 install_element(OSPF_NODE, &ospf_redistribute_instance_source_cmd);
12669 install_element(OSPF_NODE, &no_ospf_redistribute_instance_source_cmd);
12670
12671 install_element(OSPF_NODE, &ospf_distribute_list_out_cmd);
12672 install_element(OSPF_NODE, &no_ospf_distribute_list_out_cmd);
12673
12674 install_element(OSPF_NODE, &ospf_default_information_originate_cmd);
12675 install_element(OSPF_NODE, &no_ospf_default_information_originate_cmd);
12676
12677 install_element(OSPF_NODE, &ospf_default_metric_cmd);
12678 install_element(OSPF_NODE, &no_ospf_default_metric_cmd);
12679
12680 install_element(OSPF_NODE, &ospf_distance_cmd);
12681 install_element(OSPF_NODE, &no_ospf_distance_cmd);
12682 install_element(OSPF_NODE, &no_ospf_distance_ospf_cmd);
12683 install_element(OSPF_NODE, &ospf_distance_ospf_cmd);
12684
12685 /*Ospf garcefull restart helper configurations */
12686 install_element(OSPF_NODE, &ospf_gr_helper_enable_cmd);
12687 install_element(OSPF_NODE, &no_ospf_gr_helper_enable_cmd);
12688 install_element(OSPF_NODE, &ospf_gr_helper_enable_lsacheck_cmd);
12689 install_element(OSPF_NODE, &no_ospf_gr_helper_enable_lsacheck_cmd);
12690 install_element(OSPF_NODE, &ospf_gr_helper_supported_grace_time_cmd);
12691 install_element(OSPF_NODE, &no_ospf_gr_helper_supported_grace_time_cmd);
12692 install_element(OSPF_NODE, &ospf_gr_helper_planned_only_cmd);
12693 install_element(OSPF_NODE, &no_ospf_gr_helper_planned_only_cmd);
12694
12695 /* External LSA summarisation config commands.*/
12696 install_element(OSPF_NODE, &ospf_external_route_aggregation_cmd);
12697 install_element(OSPF_NODE, &no_ospf_external_route_aggregation_cmd);
12698 install_element(OSPF_NODE,
12699 &ospf_external_route_aggregation_no_adrvertise_cmd);
12700 install_element(OSPF_NODE,
12701 &no_ospf_external_route_aggregation_no_adrvertise_cmd);
12702 install_element(OSPF_NODE, &ospf_route_aggregation_timer_cmd);
12703 install_element(OSPF_NODE, &no_ospf_route_aggregation_timer_cmd);
12704 }
12705
12706 static int ospf_config_write(struct vty *vty);
12707 static struct cmd_node ospf_node = {
12708 .name = "ospf",
12709 .node = OSPF_NODE,
12710 .parent_node = CONFIG_NODE,
12711 .prompt = "%s(config-router)# ",
12712 .config_write = ospf_config_write,
12713 };
12714
12715 static void ospf_interface_clear(struct interface *ifp)
12716 {
12717 if (!if_is_operative(ifp))
12718 return;
12719
12720 if (IS_DEBUG_OSPF(ism, ISM_EVENTS))
12721 zlog_debug("ISM[%s]: clear by reset", ifp->name);
12722
12723 ospf_if_reset(ifp);
12724 }
12725
12726 DEFUN (clear_ip_ospf_interface,
12727 clear_ip_ospf_interface_cmd,
12728 "clear ip ospf [vrf NAME] interface [IFNAME]",
12729 CLEAR_STR
12730 IP_STR
12731 "OSPF information\n"
12732 VRF_CMD_HELP_STR
12733 "Interface information\n"
12734 "Interface name\n")
12735 {
12736 int idx_ifname = 0;
12737 int idx_vrf = 0;
12738 struct interface *ifp;
12739 struct listnode *node;
12740 struct ospf *ospf = NULL;
12741 char *vrf_name = NULL;
12742 vrf_id_t vrf_id = VRF_DEFAULT;
12743 struct vrf *vrf = NULL;
12744
12745 if (argv_find(argv, argc, "vrf", &idx_vrf))
12746 vrf_name = argv[idx_vrf + 1]->arg;
12747 if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME))
12748 vrf_name = NULL;
12749 if (vrf_name) {
12750 vrf = vrf_lookup_by_name(vrf_name);
12751 if (vrf)
12752 vrf_id = vrf->vrf_id;
12753 }
12754 if (!argv_find(argv, argc, "IFNAME", &idx_ifname)) {
12755 /* Clear all the ospfv2 interfaces. */
12756 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
12757 if (vrf_id != ospf->vrf_id)
12758 continue;
12759 if (!vrf)
12760 vrf = vrf_lookup_by_id(ospf->vrf_id);
12761 FOR_ALL_INTERFACES (vrf, ifp)
12762 ospf_interface_clear(ifp);
12763 }
12764 } else {
12765 /* Interface name is specified. */
12766 ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id);
12767 if (ifp == NULL)
12768 vty_out(vty, "No such interface name\n");
12769 else
12770 ospf_interface_clear(ifp);
12771 }
12772
12773 return CMD_SUCCESS;
12774 }
12775
12776 DEFPY_HIDDEN(ospf_lsa_refresh_timer, ospf_lsa_refresh_timer_cmd,
12777 "[no$no] ospf lsa-refresh [(120-1800)]$value",
12778 NO_STR OSPF_STR
12779 "OSPF lsa refresh timer\n"
12780 "timer value in seconds\n")
12781 {
12782 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf)
12783
12784 if (no)
12785 ospf->lsa_refresh_timer = OSPF_LS_REFRESH_TIME;
12786 else
12787 ospf->lsa_refresh_timer = value;
12788
12789 return CMD_SUCCESS;
12790 }
12791
12792 DEFPY_HIDDEN(ospf_maxage_delay_timer, ospf_maxage_delay_timer_cmd,
12793 "[no$no] ospf maxage-delay [(0-60)]$value",
12794 NO_STR OSPF_STR
12795 "OSPF lsa maxage delay timer\n"
12796 "timer value in seconds\n")
12797 {
12798 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf)
12799
12800 if (no)
12801 ospf->maxage_delay = OSPF_LSA_MAXAGE_REMOVE_DELAY_DEFAULT;
12802 else
12803 ospf->maxage_delay = value;
12804
12805 THREAD_OFF(ospf->t_maxage);
12806 OSPF_TIMER_ON(ospf->t_maxage, ospf_maxage_lsa_remover,
12807 ospf->maxage_delay);
12808
12809 return CMD_SUCCESS;
12810 }
12811
12812 /*
12813 * ------------------------------------------------------------------------*
12814 * Following is (vty) configuration functions for flood-reduction handling.
12815 * ------------------------------------------------------------------------
12816 */
12817
12818 DEFPY(flood_reduction, flood_reduction_cmd, "flood-reduction",
12819 "flood reduction feature\n")
12820 {
12821 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf)
12822 struct ospf_area *area;
12823 struct listnode *node;
12824
12825 /* Turn on the Flood Reduction feature for the router. */
12826 if (!ospf->fr_configured) {
12827 ospf->fr_configured = true;
12828 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT,
12829 "Flood Reduction: OFF -> ON");
12830 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
12831 if (area) {
12832 ospf_area_update_fr_state(area);
12833 ospf_refresh_area_self_lsas(area);
12834 }
12835 }
12836 }
12837
12838 return CMD_SUCCESS;
12839 }
12840
12841 DEFPY(flood_reduction_area, flood_reduction_area_cmd,
12842 "area <A.B.C.D|(0-4294967295)> flood-reduction",
12843 "OSPF area parameters\n"
12844 "OSPF area ID in IP address format\n"
12845 "OSPF area ID as a decimal value\n"
12846 "Enable flood reduction for area\n")
12847 {
12848 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf)
12849 struct ospf_area *oa;
12850 int idx = 1;
12851 int format;
12852 int ret;
12853 const char *areaid;
12854 struct in_addr area_id;
12855
12856 areaid = argv[idx]->arg;
12857
12858 ret = str2area_id(areaid, &area_id, &format);
12859 if (ret < 0) {
12860 vty_out(vty, "Please specify area by A.B.C.D|<0-4294967295>\n");
12861 return CMD_WARNING_CONFIG_FAILED;
12862 }
12863
12864 oa = ospf_area_lookup_by_area_id(ospf, area_id);
12865 if (!oa) {
12866 vty_out(vty, "OSPF area ID not present\n");
12867 return CMD_WARNING_CONFIG_FAILED;
12868 }
12869
12870 /* Turn on the Flood Reduction feature for the area. */
12871 if (!oa->fr_info.configured) {
12872 oa->fr_info.configured = true;
12873 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT,
12874 "Flood Reduction area %pI4 : OFF -> ON",
12875 &oa->area_id);
12876 ospf_area_update_fr_state(oa);
12877 ospf_refresh_area_self_lsas(oa);
12878 }
12879
12880 return CMD_SUCCESS;
12881 }
12882
12883 DEFPY(no_flood_reduction, no_flood_reduction_cmd, "no flood-reduction",
12884 NO_STR "flood reduction feature\n")
12885 {
12886 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf)
12887 struct listnode *node;
12888 struct ospf_area *area;
12889
12890 /* Turn off the Flood Reduction feature for the router. */
12891 if (ospf->fr_configured) {
12892 ospf->fr_configured = false;
12893 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT,
12894 "Flood Reduction: ON -> OFF");
12895 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
12896 if (area) {
12897 ospf_area_update_fr_state(area);
12898 ospf_refresh_area_self_lsas(area);
12899 }
12900 }
12901 }
12902
12903 return CMD_SUCCESS;
12904 }
12905
12906 DEFPY(no_flood_reduction_area, no_flood_reduction_area_cmd,
12907 "no area <A.B.C.D|(0-4294967295)> flood-reduction",
12908 NO_STR
12909 "OSPF area parameters\n"
12910 "OSPF area ID in IP address format\n"
12911 "OSPF area ID as a decimal value\n"
12912 "Disable flood reduction for area\n")
12913 {
12914 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf)
12915 struct ospf_area *oa;
12916 int idx = 2;
12917 int format;
12918 int ret;
12919 const char *areaid;
12920 struct in_addr area_id;
12921
12922 areaid = argv[idx]->arg;
12923
12924 ret = str2area_id(areaid, &area_id, &format);
12925 if (ret < 0) {
12926 vty_out(vty, "Please specify area by A.B.C.D|<0-4294967295>\n");
12927 return CMD_WARNING_CONFIG_FAILED;
12928 }
12929
12930 oa = ospf_area_lookup_by_area_id(ospf, area_id);
12931 if (!oa) {
12932 vty_out(vty, "OSPF area ID not present\n");
12933 return CMD_WARNING_CONFIG_FAILED;
12934 }
12935
12936 /* Turn off the Flood Reduction feature for the area. */
12937 if (oa->fr_info.configured) {
12938 oa->fr_info.configured = false;
12939 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT,
12940 "Flood Reduction area %pI4 : ON -> OFF",
12941 &oa->area_id);
12942 ospf_area_update_fr_state(oa);
12943 ospf_refresh_area_self_lsas(oa);
12944 }
12945
12946 return CMD_SUCCESS;
12947 }
12948
12949 void ospf_vty_clear_init(void)
12950 {
12951 install_element(ENABLE_NODE, &clear_ip_ospf_interface_cmd);
12952 install_element(ENABLE_NODE, &clear_ip_ospf_process_cmd);
12953 install_element(ENABLE_NODE, &clear_ip_ospf_neighbor_cmd);
12954 }
12955
12956
12957 /* Install OSPF related vty commands. */
12958 void ospf_vty_init(void)
12959 {
12960 /* Install ospf top node. */
12961 install_node(&ospf_node);
12962
12963 /* "router ospf" commands. */
12964 install_element(CONFIG_NODE, &router_ospf_cmd);
12965 install_element(CONFIG_NODE, &no_router_ospf_cmd);
12966
12967
12968 install_default(OSPF_NODE);
12969
12970 /* "ospf router-id" commands. */
12971 install_element(OSPF_NODE, &ospf_router_id_cmd);
12972 install_element(OSPF_NODE, &ospf_router_id_old_cmd);
12973 install_element(OSPF_NODE, &no_ospf_router_id_cmd);
12974
12975 /* "passive-interface" commands. */
12976 install_element(OSPF_NODE, &ospf_passive_interface_default_cmd);
12977 install_element(OSPF_NODE, &ospf_passive_interface_addr_cmd);
12978 install_element(OSPF_NODE, &no_ospf_passive_interface_default_cmd);
12979 install_element(OSPF_NODE, &no_ospf_passive_interface_addr_cmd);
12980
12981 /* "ospf abr-type" commands. */
12982 install_element(OSPF_NODE, &ospf_abr_type_cmd);
12983 install_element(OSPF_NODE, &no_ospf_abr_type_cmd);
12984
12985 /* "ospf log-adjacency-changes" commands. */
12986 install_element(OSPF_NODE, &ospf_log_adjacency_changes_cmd);
12987 install_element(OSPF_NODE, &ospf_log_adjacency_changes_detail_cmd);
12988 install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_cmd);
12989 install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_detail_cmd);
12990
12991 /* "ospf rfc1583-compatible" commands. */
12992 install_element(OSPF_NODE, &ospf_compatible_rfc1583_cmd);
12993 install_element(OSPF_NODE, &no_ospf_compatible_rfc1583_cmd);
12994 install_element(OSPF_NODE, &ospf_rfc1583_flag_cmd);
12995 install_element(OSPF_NODE, &no_ospf_rfc1583_flag_cmd);
12996
12997 /* "ospf send-extra-data zebra" commands. */
12998 install_element(OSPF_NODE, &ospf_send_extra_data_cmd);
12999
13000 /* "network area" commands. */
13001 install_element(OSPF_NODE, &ospf_network_area_cmd);
13002 install_element(OSPF_NODE, &no_ospf_network_area_cmd);
13003
13004 /* "area authentication" commands. */
13005 install_element(OSPF_NODE,
13006 &ospf_area_authentication_message_digest_cmd);
13007 install_element(OSPF_NODE, &ospf_area_authentication_cmd);
13008 install_element(OSPF_NODE, &no_ospf_area_authentication_cmd);
13009
13010 /* "area range" commands. */
13011 install_element(OSPF_NODE, &ospf_area_range_cmd);
13012 install_element(OSPF_NODE, &ospf_area_range_cost_cmd);
13013 install_element(OSPF_NODE, &ospf_area_range_not_advertise_cmd);
13014 install_element(OSPF_NODE, &no_ospf_area_range_cmd);
13015 install_element(OSPF_NODE, &no_ospf_area_range_substitute_cmd);
13016
13017 /* "area virtual-link" commands. */
13018 install_element(OSPF_NODE, &ospf_area_vlink_cmd);
13019 install_element(OSPF_NODE, &ospf_area_vlink_intervals_cmd);
13020 install_element(OSPF_NODE, &no_ospf_area_vlink_cmd);
13021 install_element(OSPF_NODE, &no_ospf_area_vlink_intervals_cmd);
13022
13023
13024 /* "area stub" commands. */
13025 install_element(OSPF_NODE, &ospf_area_stub_no_summary_cmd);
13026 install_element(OSPF_NODE, &ospf_area_stub_cmd);
13027 install_element(OSPF_NODE, &no_ospf_area_stub_no_summary_cmd);
13028 install_element(OSPF_NODE, &no_ospf_area_stub_cmd);
13029
13030 /* "area nssa" commands. */
13031 install_element(OSPF_NODE, &ospf_area_nssa_cmd);
13032 install_element(OSPF_NODE, &ospf_area_nssa_translate_cmd);
13033 install_element(OSPF_NODE, &ospf_area_nssa_no_summary_cmd);
13034 install_element(OSPF_NODE, &no_ospf_area_nssa_no_summary_cmd);
13035 install_element(OSPF_NODE, &ospf_area_nssa_suppress_fa_cmd);
13036 install_element(OSPF_NODE, &no_ospf_area_nssa_suppress_fa_cmd);
13037 install_element(OSPF_NODE, &no_ospf_area_nssa_cmd);
13038
13039 install_element(OSPF_NODE, &ospf_area_default_cost_cmd);
13040 install_element(OSPF_NODE, &no_ospf_area_default_cost_cmd);
13041
13042 install_element(OSPF_NODE, &ospf_area_shortcut_cmd);
13043 install_element(OSPF_NODE, &no_ospf_area_shortcut_cmd);
13044
13045 install_element(OSPF_NODE, &ospf_area_export_list_cmd);
13046 install_element(OSPF_NODE, &no_ospf_area_export_list_cmd);
13047
13048 install_element(OSPF_NODE, &ospf_area_filter_list_cmd);
13049 install_element(OSPF_NODE, &no_ospf_area_filter_list_cmd);
13050
13051 install_element(OSPF_NODE, &ospf_area_import_list_cmd);
13052 install_element(OSPF_NODE, &no_ospf_area_import_list_cmd);
13053
13054 /* SPF timer commands */
13055 install_element(OSPF_NODE, &ospf_timers_throttle_spf_cmd);
13056 install_element(OSPF_NODE, &no_ospf_timers_throttle_spf_cmd);
13057
13058 /* LSA timers commands */
13059 install_element(OSPF_NODE, &ospf_timers_min_ls_interval_cmd);
13060 install_element(OSPF_NODE, &no_ospf_timers_min_ls_interval_cmd);
13061 install_element(OSPF_NODE, &ospf_timers_lsa_min_arrival_cmd);
13062 install_element(OSPF_NODE, &no_ospf_timers_lsa_min_arrival_cmd);
13063
13064 /* refresh timer commands */
13065 install_element(OSPF_NODE, &ospf_refresh_timer_cmd);
13066 install_element(OSPF_NODE, &no_ospf_refresh_timer_val_cmd);
13067
13068 /* max-metric commands */
13069 install_element(OSPF_NODE, &ospf_max_metric_router_lsa_admin_cmd);
13070 install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_admin_cmd);
13071 install_element(OSPF_NODE, &ospf_max_metric_router_lsa_startup_cmd);
13072 install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_startup_cmd);
13073 install_element(OSPF_NODE, &ospf_max_metric_router_lsa_shutdown_cmd);
13074 install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_shutdown_cmd);
13075
13076 /* reference bandwidth commands */
13077 install_element(OSPF_NODE, &ospf_auto_cost_reference_bandwidth_cmd);
13078 install_element(OSPF_NODE, &no_ospf_auto_cost_reference_bandwidth_cmd);
13079
13080 /* "neighbor" commands. */
13081 install_element(OSPF_NODE, &ospf_neighbor_cmd);
13082 install_element(OSPF_NODE, &ospf_neighbor_poll_interval_cmd);
13083 install_element(OSPF_NODE, &no_ospf_neighbor_cmd);
13084 install_element(OSPF_NODE, &no_ospf_neighbor_poll_cmd);
13085
13086 /* write multiplier commands */
13087 install_element(OSPF_NODE, &ospf_write_multiplier_cmd);
13088 install_element(OSPF_NODE, &write_multiplier_cmd);
13089 install_element(OSPF_NODE, &no_ospf_write_multiplier_cmd);
13090 install_element(OSPF_NODE, &no_write_multiplier_cmd);
13091
13092 /* "proactive-arp" commands. */
13093 install_element(OSPF_NODE, &ospf_proactive_arp_cmd);
13094 install_element(OSPF_NODE, &no_ospf_proactive_arp_cmd);
13095
13096 /* TI-LFA commands */
13097 install_element(OSPF_NODE, &ospf_ti_lfa_cmd);
13098 install_element(OSPF_NODE, &no_ospf_ti_lfa_cmd);
13099
13100 /* Max path configurations */
13101 install_element(OSPF_NODE, &ospf_max_multipath_cmd);
13102 install_element(OSPF_NODE, &no_ospf_max_multipath_cmd);
13103
13104 vrf_cmd_init(NULL);
13105
13106 install_element(OSPF_NODE, &ospf_lsa_refresh_timer_cmd);
13107 install_element(OSPF_NODE, &ospf_maxage_delay_timer_cmd);
13108
13109 /* Flood Reduction commands */
13110 install_element(OSPF_NODE, &flood_reduction_cmd);
13111 install_element(OSPF_NODE, &no_flood_reduction_cmd);
13112 install_element(OSPF_NODE, &flood_reduction_area_cmd);
13113 install_element(OSPF_NODE, &no_flood_reduction_area_cmd);
13114
13115 /* Init interface related vty commands. */
13116 ospf_vty_if_init();
13117
13118 /* Init zebra related vty commands. */
13119 ospf_vty_zebra_init();
13120 }