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