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