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