]> git.proxmox.com Git - mirror_frr.git/blob - ospfd/ospf_vty.c
Merge pull request #11824 from sigeryang/master
[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 json_object_int_add(json_interface_sub, "packetsQueued",
4012 listcount(oi->obuf));
4013 } else {
4014 vty_out(vty,
4015 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u %12lu\n",
4016 oi->ifp->name, oi->hello_in, oi->hello_out,
4017 oi->db_desc_in, oi->db_desc_out, oi->ls_req_in,
4018 oi->ls_req_out, oi->ls_upd_in, oi->ls_upd_out,
4019 oi->ls_ack_in, oi->ls_ack_out, listcount(oi->obuf));
4020 }
4021 }
4022
4023 /* OSPFv2 Packet Counters */
4024 static int show_ip_ospf_interface_traffic_common(
4025 struct vty *vty, struct ospf *ospf, char *intf_name, json_object *json,
4026 int display_once, uint8_t use_vrf, bool use_json)
4027 {
4028 struct vrf *vrf = NULL;
4029 struct interface *ifp = NULL;
4030 json_object *json_vrf = NULL;
4031 json_object *json_interface_sub = NULL;
4032
4033 if (!use_json && !display_once) {
4034 vty_out(vty, "\n");
4035 vty_out(vty, "%-12s%-17s%-17s%-17s%-17s%-17s%-17s\n",
4036 "Interface", " HELLO", " DB-Desc", " LS-Req",
4037 " LS-Update", " LS-Ack", " Packets");
4038 vty_out(vty, "%-10s%-18s%-18s%-17s%-17s%-17s%-17s\n", "",
4039 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
4040 " Rx/Tx", " Queued");
4041 vty_out(vty,
4042 "-------------------------------------------------------------------------------------------------------------\n");
4043 } else if (use_json) {
4044 if (use_vrf)
4045 json_vrf = json_object_new_object();
4046 else
4047 json_vrf = json;
4048 }
4049
4050 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
4051
4052 if (intf_name == NULL) {
4053 vrf = vrf_lookup_by_id(ospf->vrf_id);
4054 FOR_ALL_INTERFACES (vrf, ifp) {
4055 struct route_node *rn;
4056 struct ospf_interface *oi;
4057
4058 if (ospf_oi_count(ifp) == 0)
4059 continue;
4060
4061 for (rn = route_top(IF_OIFS(ifp)); rn;
4062 rn = route_next(rn)) {
4063 oi = rn->info;
4064
4065 if (oi == NULL)
4066 continue;
4067
4068 if (use_json) {
4069 json_interface_sub =
4070 json_object_new_object();
4071 }
4072
4073 show_ip_ospf_interface_traffic_sub(
4074 vty, oi, json_interface_sub, use_json);
4075 if (use_json) {
4076 json_object_object_add(
4077 json_vrf, ifp->name,
4078 json_interface_sub);
4079 }
4080 }
4081 }
4082 } else {
4083 /* Interface name is specified. */
4084 ifp = if_lookup_by_name(intf_name, ospf->vrf_id);
4085 if (ifp != NULL) {
4086 struct route_node *rn;
4087 struct ospf_interface *oi;
4088
4089 if (ospf_oi_count(ifp) == 0) {
4090 vty_out(vty,
4091 " OSPF not enabled on this interface %s\n",
4092 ifp->name);
4093 return CMD_SUCCESS;
4094 }
4095
4096 for (rn = route_top(IF_OIFS(ifp)); rn;
4097 rn = route_next(rn)) {
4098 oi = rn->info;
4099
4100 if (use_json) {
4101 json_interface_sub =
4102 json_object_new_object();
4103 }
4104
4105 show_ip_ospf_interface_traffic_sub(
4106 vty, oi, json_interface_sub, use_json);
4107 if (use_json) {
4108 json_object_object_add(
4109 json_vrf, ifp->name,
4110 json_interface_sub);
4111 }
4112 }
4113 }
4114 }
4115
4116 if (use_json) {
4117 if (use_vrf)
4118 json_object_object_add(json, ospf_get_name(ospf),
4119 json_vrf);
4120 } else
4121 vty_out(vty, "\n");
4122
4123 return CMD_SUCCESS;
4124 }
4125
4126 DEFUN (show_ip_ospf_interface,
4127 show_ip_ospf_interface_cmd,
4128 "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]",
4129 SHOW_STR
4130 IP_STR
4131 "OSPF information\n"
4132 VRF_CMD_HELP_STR
4133 "All VRFs\n"
4134 "Interface information\n"
4135 "Interface name\n"
4136 JSON_STR)
4137 {
4138 struct ospf *ospf;
4139 bool uj = use_json(argc, argv);
4140 struct listnode *node = NULL;
4141 char *vrf_name = NULL, *intf_name = NULL;
4142 bool all_vrf = false;
4143 int ret = CMD_SUCCESS;
4144 int inst = 0;
4145 int idx_vrf = 0, idx_intf = 0;
4146 uint8_t use_vrf = 0;
4147 json_object *json = NULL;
4148
4149 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
4150
4151 if (argv_find(argv, argc, "INTERFACE", &idx_intf))
4152 intf_name = argv[idx_intf]->arg;
4153
4154 if (uj)
4155 json = json_object_new_object();
4156
4157 /* vrf input is provided could be all or specific vrf*/
4158 if (vrf_name) {
4159 use_vrf = 1;
4160 if (all_vrf) {
4161 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
4162 if (!ospf->oi_running)
4163 continue;
4164 ret = show_ip_ospf_interface_common(
4165 vty, ospf, intf_name, use_vrf, json,
4166 uj);
4167 }
4168
4169 if (uj)
4170 vty_json(vty, json);
4171 else if (!ospf)
4172 vty_out(vty, "%% OSPF is not enabled\n");
4173
4174 return ret;
4175 }
4176 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
4177 if (ospf == NULL || !ospf->oi_running) {
4178 if (uj)
4179 vty_json(vty, json);
4180 else
4181 vty_out(vty,
4182 "%% OSPF is not enabled in vrf %s\n",
4183 vrf_name);
4184
4185 return CMD_SUCCESS;
4186 }
4187 ret = show_ip_ospf_interface_common(vty, ospf, intf_name,
4188 use_vrf, json, uj);
4189
4190 } else {
4191 /* Display default ospf (instance 0) info */
4192 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
4193 if (ospf == NULL || !ospf->oi_running) {
4194 if (uj)
4195 vty_json(vty, json);
4196 else
4197 vty_out(vty,
4198 "%% OSPF is not enabled in vrf default\n");
4199
4200 return CMD_SUCCESS;
4201 }
4202 ret = show_ip_ospf_interface_common(vty, ospf, intf_name,
4203 use_vrf, json, uj);
4204 }
4205
4206 if (uj)
4207 vty_json(vty, json);
4208
4209 return ret;
4210 }
4211
4212 DEFUN (show_ip_ospf_instance_interface,
4213 show_ip_ospf_instance_interface_cmd,
4214 "show ip ospf (1-65535) interface [INTERFACE] [json]",
4215 SHOW_STR
4216 IP_STR
4217 "OSPF information\n"
4218 "Instance ID\n"
4219 "Interface information\n"
4220 "Interface name\n"
4221 JSON_STR)
4222 {
4223 int idx_number = 3;
4224 int idx_intf = 0;
4225 struct ospf *ospf;
4226 unsigned short instance = 0;
4227 bool uj = use_json(argc, argv);
4228 char *intf_name = NULL;
4229 int ret = CMD_SUCCESS;
4230 json_object *json = NULL;
4231
4232 instance = strtoul(argv[idx_number]->arg, NULL, 10);
4233 if (instance != ospf_instance)
4234 return CMD_NOT_MY_INSTANCE;
4235
4236 ospf = ospf_lookup_instance(instance);
4237 if (!ospf || !ospf->oi_running)
4238 return CMD_SUCCESS;
4239
4240 if (uj)
4241 json = json_object_new_object();
4242
4243 if (argv_find(argv, argc, "INTERFACE", &idx_intf))
4244 intf_name = argv[idx_intf]->arg;
4245
4246 ret = show_ip_ospf_interface_common(vty, ospf, intf_name, 0, json, uj);
4247
4248 if (uj)
4249 vty_json(vty, json);
4250
4251 return ret;
4252 }
4253
4254 DEFUN (show_ip_ospf_interface_traffic,
4255 show_ip_ospf_interface_traffic_cmd,
4256 "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]",
4257 SHOW_STR
4258 IP_STR
4259 "OSPF information\n"
4260 VRF_CMD_HELP_STR
4261 "All VRFs\n"
4262 "Interface information\n"
4263 "Protocol Packet counters\n"
4264 "Interface name\n"
4265 JSON_STR)
4266 {
4267 struct ospf *ospf = NULL;
4268 struct listnode *node = NULL;
4269 char *vrf_name = NULL, *intf_name = NULL;
4270 bool all_vrf = false;
4271 int inst = 0;
4272 int idx_vrf = 0, idx_intf = 0;
4273 bool uj = use_json(argc, argv);
4274 json_object *json = NULL;
4275 int ret = CMD_SUCCESS;
4276 int display_once = 0;
4277 uint8_t use_vrf = 0;
4278
4279 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
4280
4281 if (argv_find(argv, argc, "INTERFACE", &idx_intf))
4282 intf_name = argv[idx_intf]->arg;
4283
4284 if (uj)
4285 json = json_object_new_object();
4286
4287 if (vrf_name) {
4288 use_vrf = 1;
4289 if (all_vrf) {
4290 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
4291 if (!ospf->oi_running)
4292 continue;
4293
4294 ret = show_ip_ospf_interface_traffic_common(
4295 vty, ospf, intf_name, json,
4296 display_once, use_vrf, uj);
4297 display_once = 1;
4298 }
4299
4300 if (uj)
4301 vty_json(vty, json);
4302
4303 return ret;
4304 }
4305 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
4306 if (ospf == NULL || !ospf->oi_running) {
4307 if (uj)
4308 json_object_free(json);
4309 return CMD_SUCCESS;
4310 }
4311
4312 ret = show_ip_ospf_interface_traffic_common(
4313 vty, ospf, intf_name, json, display_once, use_vrf, uj);
4314 } else {
4315 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
4316 if (ospf == NULL || !ospf->oi_running) {
4317 if (uj)
4318 json_object_free(json);
4319 return CMD_SUCCESS;
4320 }
4321
4322 ret = show_ip_ospf_interface_traffic_common(
4323 vty, ospf, intf_name, json, display_once, use_vrf, uj);
4324 }
4325
4326 if (uj)
4327 vty_json(vty, json);
4328
4329 return ret;
4330 }
4331
4332
4333 static void show_ip_ospf_neighbour_header(struct vty *vty)
4334 {
4335 vty_out(vty, "\n%-15s %-3s %-15s %-15s %-9s %-15s %-32s %5s %5s %5s\n",
4336 "Neighbor ID", "Pri", "State", "Up Time", "Dead Time",
4337 "Address", "Interface", "RXmtL", "RqstL", "DBsmL");
4338 }
4339
4340 static void show_ip_ospf_neighbour_brief(struct vty *vty,
4341 struct ospf_neighbor *nbr,
4342 struct ospf_neighbor *prev_nbr,
4343 json_object *json, bool use_json)
4344 {
4345 char msgbuf[16];
4346 char timebuf[OSPF_TIME_DUMP_SIZE];
4347 json_object *json_neighbor = NULL, *json_neigh_array = NULL;
4348 struct timeval res = {.tv_sec = 0, .tv_usec = 0};
4349 long time_val = 0;
4350 char uptime[OSPF_TIME_DUMP_SIZE];
4351
4352 if (nbr->ts_last_progress.tv_sec || nbr->ts_last_progress.tv_usec)
4353 time_val =
4354 monotime_since(&nbr->ts_last_progress, &res) / 1000LL;
4355
4356 if (use_json) {
4357 char neigh_str[INET_ADDRSTRLEN];
4358
4359 if (prev_nbr && !IPV4_ADDR_SAME(&prev_nbr->src, &nbr->src)) {
4360 /* Start new neigh list */
4361 json_neigh_array = NULL;
4362 }
4363
4364 if (nbr->state == NSM_Attempt &&
4365 nbr->router_id.s_addr == INADDR_ANY)
4366 strlcpy(neigh_str, "neighbor", sizeof(neigh_str));
4367 else
4368 inet_ntop(AF_INET, &nbr->router_id, neigh_str,
4369 sizeof(neigh_str));
4370
4371 json_object_object_get_ex(json, neigh_str, &json_neigh_array);
4372
4373 if (!json_neigh_array) {
4374 json_neigh_array = json_object_new_array();
4375 json_object_object_add(json, neigh_str,
4376 json_neigh_array);
4377 }
4378
4379 json_neighbor = json_object_new_object();
4380
4381 ospf_nbr_ism_state_message(nbr, msgbuf, sizeof(msgbuf));
4382 #if CONFDATE > 20230321
4383 CPP_NOTICE(
4384 "Remove show_ip_ospf_neighbor_sub() JSON keys: priority, state, deadTimeMsecs, address, retransmitCounter, requestCounter, dbSummaryCounter")
4385 #endif
4386 json_object_int_add(json_neighbor, "priority", nbr->priority);
4387 json_object_string_add(json_neighbor, "state", msgbuf);
4388 json_object_int_add(json_neighbor, "nbrPriority",
4389 nbr->priority);
4390 json_object_string_add(json_neighbor, "nbrState", msgbuf);
4391
4392 json_object_string_add(
4393 json_neighbor, "converged",
4394 lookup_msg(ospf_nsm_state_msg, nbr->state, NULL));
4395 json_object_string_add(json_neighbor, "role",
4396 lookup_msg(ospf_ism_state_msg,
4397 ospf_nbr_ism_state(nbr),
4398 NULL));
4399 if (nbr->t_inactivity) {
4400 long time_store;
4401
4402 time_store = monotime_until(&nbr->t_inactivity->u.sands,
4403 NULL) /
4404 1000LL;
4405 json_object_int_add(json_neighbor, "upTimeInMsec",
4406 time_val);
4407 json_object_int_add(json_neighbor, "deadTimeMsecs",
4408 time_store);
4409 json_object_int_add(json_neighbor,
4410 "routerDeadIntervalTimerDueMsec",
4411 time_store);
4412 json_object_string_add(
4413 json_neighbor, "upTime",
4414 ospf_timeval_dump(&res, uptime,
4415 sizeof(uptime)));
4416 json_object_string_add(
4417 json_neighbor, "deadTime",
4418 ospf_timer_dump(nbr->t_inactivity, timebuf,
4419 sizeof(timebuf)));
4420 } else {
4421 json_object_string_add(json_neighbor, "deadTimeMsecs",
4422 "inactive");
4423 json_object_string_add(json_neighbor,
4424 "routerDeadIntervalTimerDueMsec",
4425 "inactive");
4426 }
4427 json_object_string_addf(json_neighbor, "address", "%pI4",
4428 &nbr->src);
4429 json_object_string_addf(json_neighbor, "ifaceAddress", "%pI4",
4430 &nbr->src);
4431 json_object_string_add(json_neighbor, "ifaceName",
4432 IF_NAME(nbr->oi));
4433 json_object_int_add(json_neighbor, "retransmitCounter",
4434 ospf_ls_retransmit_count(nbr));
4435 json_object_int_add(json_neighbor,
4436 "linkStateRetransmissionListCounter",
4437 ospf_ls_retransmit_count(nbr));
4438 json_object_int_add(json_neighbor, "requestCounter",
4439 ospf_ls_request_count(nbr));
4440 json_object_int_add(json_neighbor,
4441 "linkStateRequestListCounter",
4442 ospf_ls_request_count(nbr));
4443 json_object_int_add(json_neighbor, "dbSummaryCounter",
4444 ospf_db_summary_count(nbr));
4445 json_object_int_add(json_neighbor, "databaseSummaryListCounter",
4446 ospf_db_summary_count(nbr));
4447
4448 json_object_array_add(json_neigh_array, json_neighbor);
4449 } else {
4450 ospf_nbr_ism_state_message(nbr, msgbuf, sizeof(msgbuf));
4451
4452 if (nbr->state == NSM_Attempt &&
4453 nbr->router_id.s_addr == INADDR_ANY)
4454 vty_out(vty, "%-15s %3d %-15s ", "-", nbr->priority,
4455 msgbuf);
4456 else
4457 vty_out(vty, "%-15pI4 %3d %-15s ", &nbr->router_id,
4458 nbr->priority, msgbuf);
4459
4460 vty_out(vty, "%-15s ",
4461 ospf_timeval_dump(&res, uptime, sizeof(uptime)));
4462
4463 vty_out(vty, "%9s ",
4464 ospf_timer_dump(nbr->t_inactivity, timebuf,
4465 sizeof(timebuf)));
4466 vty_out(vty, "%-15pI4 ", &nbr->src);
4467 vty_out(vty, "%-32s %5ld %5ld %5d\n", IF_NAME(nbr->oi),
4468 ospf_ls_retransmit_count(nbr),
4469 ospf_ls_request_count(nbr), ospf_db_summary_count(nbr));
4470 }
4471 }
4472
4473 static void show_ip_ospf_neighbor_sub(struct vty *vty,
4474 struct ospf_interface *oi,
4475 json_object *json, bool use_json)
4476 {
4477 struct route_node *rn;
4478 struct ospf_neighbor *nbr, *prev_nbr = NULL;
4479
4480 for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
4481 nbr = rn->info;
4482
4483 if (!nbr)
4484 continue;
4485
4486 /* Do not show myself. */
4487 if (nbr == oi->nbr_self)
4488 continue;
4489 /* Down state is not shown. */
4490 if (nbr->state == NSM_Down)
4491 continue;
4492
4493 prev_nbr = nbr;
4494
4495 show_ip_ospf_neighbour_brief(vty, nbr, prev_nbr, json,
4496 use_json);
4497 }
4498 }
4499
4500 static int show_ip_ospf_neighbor_common(struct vty *vty, struct ospf *ospf,
4501 json_object *json, bool use_json,
4502 uint8_t use_vrf)
4503 {
4504 struct ospf_interface *oi;
4505 struct listnode *node;
4506 json_object *json_vrf = NULL;
4507 json_object *json_nbr_sub = NULL;
4508
4509 if (use_json) {
4510 if (use_vrf)
4511 json_vrf = json_object_new_object();
4512 else
4513 json_vrf = json;
4514 json_nbr_sub = json_object_new_object();
4515 }
4516
4517 if (ospf->instance) {
4518 if (use_json)
4519 json_object_int_add(json, "ospfInstance",
4520 ospf->instance);
4521 else
4522 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
4523 }
4524
4525 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
4526 if (!use_json)
4527 show_ip_ospf_neighbour_header(vty);
4528
4529 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
4530 if (ospf_interface_neighbor_count(oi) == 0)
4531 continue;
4532 show_ip_ospf_neighbor_sub(vty, oi, json_nbr_sub, use_json);
4533 }
4534
4535 if (use_json) {
4536 json_object_object_add(json_vrf, "neighbors", json_nbr_sub);
4537 if (use_vrf)
4538 json_object_object_add(json, ospf_get_name(ospf),
4539 json_vrf);
4540 } else
4541 vty_out(vty, "\n");
4542
4543 return CMD_SUCCESS;
4544 }
4545
4546 DEFUN (show_ip_ospf_neighbor,
4547 show_ip_ospf_neighbor_cmd,
4548 "show ip ospf [vrf <NAME|all>] neighbor [json]",
4549 SHOW_STR
4550 IP_STR
4551 "OSPF information\n"
4552 VRF_CMD_HELP_STR
4553 "All VRFs\n"
4554 "Neighbor list\n"
4555 JSON_STR)
4556 {
4557 struct ospf *ospf;
4558 bool uj = use_json(argc, argv);
4559 struct listnode *node = NULL;
4560 char *vrf_name = NULL;
4561 bool all_vrf = false;
4562 int ret = CMD_SUCCESS;
4563 int inst = 0;
4564 int idx_vrf = 0;
4565 uint8_t use_vrf = 0;
4566 json_object *json = NULL;
4567
4568 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
4569
4570 if (uj)
4571 json = json_object_new_object();
4572
4573 /* vrf input is provided could be all or specific vrf*/
4574 if (vrf_name) {
4575 use_vrf = 1;
4576 if (all_vrf) {
4577 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
4578 if (!ospf->oi_running)
4579 continue;
4580 ret = show_ip_ospf_neighbor_common(
4581 vty, ospf, json, uj, use_vrf);
4582 }
4583
4584 if (uj)
4585 vty_json(vty, json);
4586 else if (!ospf)
4587 vty_out(vty, "OSPF is not enabled\n");
4588
4589 return ret;
4590 }
4591
4592 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
4593 if (ospf == NULL || !ospf->oi_running) {
4594 if (uj)
4595 vty_json(vty, json);
4596 else
4597 vty_out(vty,
4598 "%% OSPF is not enabled in vrf %s\n",
4599 vrf_name);
4600
4601 return CMD_SUCCESS;
4602 }
4603 } else {
4604 /* Display default ospf (instance 0) info */
4605 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
4606 if (ospf == NULL || !ospf->oi_running) {
4607 if (uj)
4608 vty_json(vty, json);
4609 else
4610 vty_out(vty,
4611 "%% OSPF is not enabled in vrf default\n");
4612
4613 return CMD_SUCCESS;
4614 }
4615 }
4616
4617 if (ospf) {
4618 ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj,
4619 use_vrf);
4620
4621 if (uj) {
4622 vty_out(vty, "%s\n",
4623 json_object_to_json_string_ext(
4624 json, JSON_C_TO_STRING_PRETTY));
4625 }
4626 }
4627
4628 if (uj)
4629 json_object_free(json);
4630
4631 return ret;
4632 }
4633
4634
4635 DEFUN (show_ip_ospf_instance_neighbor,
4636 show_ip_ospf_instance_neighbor_cmd,
4637 "show ip ospf (1-65535) neighbor [json]",
4638 SHOW_STR
4639 IP_STR
4640 "OSPF information\n"
4641 "Instance ID\n"
4642 "Neighbor list\n"
4643 JSON_STR)
4644 {
4645 int idx_number = 3;
4646 struct ospf *ospf;
4647 unsigned short instance = 0;
4648 bool uj = use_json(argc, argv);
4649 json_object *json = NULL;
4650 int ret = CMD_SUCCESS;
4651
4652 instance = strtoul(argv[idx_number]->arg, NULL, 10);
4653 if (instance != ospf_instance)
4654 return CMD_NOT_MY_INSTANCE;
4655
4656 ospf = ospf_lookup_instance(instance);
4657 if (!ospf || !ospf->oi_running)
4658 return CMD_SUCCESS;
4659
4660 if (uj)
4661 json = json_object_new_object();
4662
4663 ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj, 0);
4664
4665 if (uj)
4666 vty_json(vty, json);
4667
4668 return ret;
4669 }
4670
4671 static int show_ip_ospf_neighbor_all_common(struct vty *vty, struct ospf *ospf,
4672 json_object *json, bool use_json,
4673 uint8_t use_vrf)
4674 {
4675 struct listnode *node;
4676 struct ospf_interface *oi;
4677 char buf[PREFIX_STRLEN];
4678 json_object *json_vrf = NULL;
4679 json_object *json_neighbor_sub = NULL;
4680
4681 if (use_json) {
4682 if (use_vrf)
4683 json_vrf = json_object_new_object();
4684 else
4685 json_vrf = json;
4686 }
4687
4688 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
4689 if (!use_json)
4690 show_ip_ospf_neighbour_header(vty);
4691
4692 if (ospf->instance) {
4693 if (use_json)
4694 json_object_int_add(json_vrf, "ospfInstance",
4695 ospf->instance);
4696 else
4697 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
4698 }
4699
4700 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
4701 struct listnode *nbr_node;
4702 struct ospf_nbr_nbma *nbr_nbma;
4703
4704 show_ip_ospf_neighbor_sub(vty, oi, json_vrf, use_json);
4705
4706 /* print Down neighbor status */
4707 for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nbr_node, nbr_nbma)) {
4708 if (nbr_nbma->nbr == NULL
4709 || nbr_nbma->nbr->state == NSM_Down) {
4710 if (use_json) {
4711 json_neighbor_sub =
4712 json_object_new_object();
4713 json_object_int_add(json_neighbor_sub,
4714 "nbrNbmaPriority",
4715 nbr_nbma->priority);
4716 json_object_boolean_true_add(
4717 json_neighbor_sub,
4718 "nbrNbmaDown");
4719 json_object_string_add(
4720 json_neighbor_sub,
4721 "nbrNbmaIfaceName",
4722 IF_NAME(oi));
4723 json_object_int_add(
4724 json_neighbor_sub,
4725 "nbrNbmaRetransmitCounter", 0);
4726 json_object_int_add(
4727 json_neighbor_sub,
4728 "nbrNbmaRequestCounter", 0);
4729 json_object_int_add(
4730 json_neighbor_sub,
4731 "nbrNbmaDbSummaryCounter", 0);
4732 json_object_object_add(
4733 json_vrf,
4734 inet_ntop(AF_INET,
4735 &nbr_nbma->addr, buf,
4736 sizeof(buf)),
4737 json_neighbor_sub);
4738 } else {
4739 vty_out(vty, "%-15s %3d %-15s %9s ",
4740 "-", nbr_nbma->priority, "Down",
4741 "-");
4742 vty_out(vty,
4743 "%-32pI4 %-20s %5d %5d %5d\n",
4744 &nbr_nbma->addr,
4745 IF_NAME(oi), 0, 0, 0);
4746 }
4747 }
4748 }
4749 }
4750
4751 if (use_json) {
4752 if (use_vrf)
4753 json_object_object_add(json, ospf_get_name(ospf),
4754 json_vrf);
4755 } else
4756 vty_out(vty, "\n");
4757
4758 return CMD_SUCCESS;
4759 }
4760
4761 DEFUN (show_ip_ospf_neighbor_all,
4762 show_ip_ospf_neighbor_all_cmd,
4763 "show ip ospf [vrf <NAME|all>] neighbor all [json]",
4764 SHOW_STR
4765 IP_STR
4766 "OSPF information\n"
4767 VRF_CMD_HELP_STR
4768 "All VRFs\n"
4769 "Neighbor list\n"
4770 "include down status neighbor\n"
4771 JSON_STR)
4772 {
4773 struct ospf *ospf;
4774 bool uj = use_json(argc, argv);
4775 struct listnode *node = NULL;
4776 char *vrf_name = NULL;
4777 bool all_vrf = false;
4778 int ret = CMD_SUCCESS;
4779 int inst = 0;
4780 int idx_vrf = 0;
4781 uint8_t use_vrf = 0;
4782 json_object *json = NULL;
4783
4784 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
4785
4786 if (uj)
4787 json = json_object_new_object();
4788
4789 /* vrf input is provided could be all or specific vrf*/
4790 if (vrf_name) {
4791 use_vrf = 1;
4792 if (all_vrf) {
4793 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
4794 if (!ospf->oi_running)
4795 continue;
4796 ret = show_ip_ospf_neighbor_all_common(
4797 vty, ospf, json, uj, use_vrf);
4798 }
4799
4800 if (uj)
4801 vty_json(vty, json);
4802
4803 return ret;
4804 }
4805
4806 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
4807 if (ospf == NULL || !ospf->oi_running) {
4808 if (uj)
4809 json_object_free(json);
4810 return CMD_SUCCESS;
4811 }
4812 } else {
4813 /* Display default ospf (instance 0) info */
4814 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
4815 if (ospf == NULL || !ospf->oi_running) {
4816 if (uj)
4817 json_object_free(json);
4818 return CMD_SUCCESS;
4819 }
4820 }
4821
4822 if (ospf) {
4823 ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj,
4824 use_vrf);
4825 if (uj) {
4826 vty_out(vty, "%s\n",
4827 json_object_to_json_string_ext(
4828 json, JSON_C_TO_STRING_PRETTY));
4829 }
4830 }
4831
4832 if (uj)
4833 json_object_free(json);
4834
4835 return ret;
4836 }
4837
4838 DEFUN (show_ip_ospf_instance_neighbor_all,
4839 show_ip_ospf_instance_neighbor_all_cmd,
4840 "show ip ospf (1-65535) neighbor all [json]",
4841 SHOW_STR
4842 IP_STR
4843 "OSPF information\n"
4844 "Instance ID\n"
4845 "Neighbor list\n"
4846 "include down status neighbor\n"
4847 JSON_STR)
4848 {
4849 int idx_number = 3;
4850 struct ospf *ospf;
4851 unsigned short instance = 0;
4852 bool uj = use_json(argc, argv);
4853 json_object *json = NULL;
4854 int ret = CMD_SUCCESS;
4855
4856 instance = strtoul(argv[idx_number]->arg, NULL, 10);
4857 if (instance != ospf_instance)
4858 return CMD_NOT_MY_INSTANCE;
4859
4860 ospf = ospf_lookup_instance(instance);
4861 if (!ospf || !ospf->oi_running)
4862 return CMD_SUCCESS;
4863 if (uj)
4864 json = json_object_new_object();
4865
4866 ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj, 0);
4867
4868 if (uj)
4869 vty_json(vty, json);
4870
4871 return ret;
4872 }
4873
4874 static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf,
4875 int arg_base,
4876 struct cmd_token **argv,
4877 bool use_json, uint8_t use_vrf)
4878 {
4879 struct interface *ifp;
4880 struct route_node *rn;
4881 json_object *json = NULL;
4882
4883 if (use_json)
4884 json = json_object_new_object();
4885
4886 if (ospf->instance) {
4887 if (use_json)
4888 json_object_int_add(json, "ospfInstance",
4889 ospf->instance);
4890 else
4891 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
4892 }
4893
4894 ospf_show_vrf_name(ospf, vty, json, use_vrf);
4895
4896 ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id);
4897 if (!ifp) {
4898 if (use_json)
4899 json_object_boolean_true_add(json, "noSuchIface");
4900 else
4901 vty_out(vty, "No such interface.\n");
4902 return CMD_WARNING;
4903 }
4904
4905 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
4906 struct ospf_interface *oi = rn->info;
4907
4908 if (oi == NULL)
4909 continue;
4910
4911 show_ip_ospf_neighbor_sub(vty, oi, json, use_json);
4912 }
4913
4914 if (use_json)
4915 vty_json(vty, json);
4916 else
4917 vty_out(vty, "\n");
4918
4919 return CMD_SUCCESS;
4920 }
4921
4922 DEFUN (show_ip_ospf_neighbor_int,
4923 show_ip_ospf_neighbor_int_cmd,
4924 "show ip ospf [vrf <NAME>] neighbor IFNAME [json]",
4925 SHOW_STR
4926 IP_STR
4927 "OSPF information\n"
4928 VRF_CMD_HELP_STR
4929 "Neighbor list\n"
4930 "Interface name\n"
4931 JSON_STR)
4932 {
4933 struct ospf *ospf;
4934 int idx_ifname = 0;
4935 int idx_vrf = 0;
4936 bool uj = use_json(argc, argv);
4937 int ret = CMD_SUCCESS;
4938 struct interface *ifp = NULL;
4939 char *vrf_name = NULL;
4940 vrf_id_t vrf_id = VRF_DEFAULT;
4941 struct vrf *vrf = NULL;
4942
4943 if (argv_find(argv, argc, "vrf", &idx_vrf))
4944 vrf_name = argv[idx_vrf + 1]->arg;
4945 if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME))
4946 vrf_name = NULL;
4947 if (vrf_name) {
4948 vrf = vrf_lookup_by_name(vrf_name);
4949 if (vrf)
4950 vrf_id = vrf->vrf_id;
4951 }
4952 ospf = ospf_lookup_by_vrf_id(vrf_id);
4953
4954 if (!ospf || !ospf->oi_running)
4955 return ret;
4956
4957 if (!uj)
4958 show_ip_ospf_neighbour_header(vty);
4959
4960 argv_find(argv, argc, "IFNAME", &idx_ifname);
4961
4962 ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id);
4963 if (!ifp)
4964 return ret;
4965
4966 ret = show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname,
4967 argv, uj, 0);
4968 return ret;
4969 }
4970
4971 DEFUN (show_ip_ospf_instance_neighbor_int,
4972 show_ip_ospf_instance_neighbor_int_cmd,
4973 "show ip ospf (1-65535) neighbor IFNAME [json]",
4974 SHOW_STR
4975 IP_STR
4976 "OSPF information\n"
4977 "Instance ID\n"
4978 "Neighbor list\n"
4979 "Interface name\n"
4980 JSON_STR)
4981 {
4982 int idx_number = 3;
4983 int idx_ifname = 5;
4984 struct ospf *ospf;
4985 unsigned short instance = 0;
4986 bool uj = use_json(argc, argv);
4987
4988 if (!uj)
4989 show_ip_ospf_neighbour_header(vty);
4990
4991 instance = strtoul(argv[idx_number]->arg, NULL, 10);
4992 if (instance != ospf_instance)
4993 return CMD_NOT_MY_INSTANCE;
4994
4995 ospf = ospf_lookup_instance(instance);
4996 if (!ospf || !ospf->oi_running)
4997 return CMD_SUCCESS;
4998
4999 if (!uj)
5000 show_ip_ospf_neighbour_header(vty);
5001
5002 return show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname, argv, uj,
5003 0);
5004 }
5005
5006 static void show_ip_ospf_nbr_nbma_detail_sub(struct vty *vty,
5007 struct ospf_interface *oi,
5008 struct ospf_nbr_nbma *nbr_nbma,
5009 bool use_json, json_object *json)
5010 {
5011 char timebuf[OSPF_TIME_DUMP_SIZE];
5012 json_object *json_sub = NULL;
5013
5014 if (use_json)
5015 json_sub = json_object_new_object();
5016 else /* Show neighbor ID. */
5017 vty_out(vty, " Neighbor %s,", "-");
5018
5019 /* Show interface address. */
5020 if (use_json)
5021 json_object_string_addf(json_sub, "ifaceAddress", "%pI4",
5022 &nbr_nbma->addr);
5023 else
5024 vty_out(vty, " interface address %pI4\n",
5025 &nbr_nbma->addr);
5026
5027 /* Show Area ID. */
5028 if (use_json) {
5029 json_object_string_add(json_sub, "areaId",
5030 ospf_area_desc_string(oi->area));
5031 json_object_string_add(json_sub, "iface", IF_NAME(oi));
5032 } else
5033 vty_out(vty, " In the area %s via interface %s\n",
5034 ospf_area_desc_string(oi->area), IF_NAME(oi));
5035
5036 /* Show neighbor priority and state. */
5037 if (use_json) {
5038 json_object_int_add(json_sub, "nbrPriority",
5039 nbr_nbma->priority);
5040 json_object_string_add(json_sub, "nbrState", "down");
5041 } else
5042 vty_out(vty, " Neighbor priority is %d, State is %s,",
5043 nbr_nbma->priority, "Down");
5044
5045 /* Show state changes. */
5046 if (use_json)
5047 json_object_int_add(json_sub, "stateChangeCounter",
5048 nbr_nbma->state_change);
5049 else
5050 vty_out(vty, " %d state changes\n", nbr_nbma->state_change);
5051
5052 /* Show PollInterval */
5053 if (use_json)
5054 json_object_int_add(json_sub, "pollInterval", nbr_nbma->v_poll);
5055 else
5056 vty_out(vty, " Poll interval %d\n", nbr_nbma->v_poll);
5057
5058 /* Show poll-interval timer. */
5059 if (nbr_nbma->t_poll) {
5060 if (use_json) {
5061 long time_store;
5062 time_store = monotime_until(&nbr_nbma->t_poll->u.sands,
5063 NULL) / 1000LL;
5064 json_object_int_add(json_sub,
5065 "pollIntervalTimerDueMsec",
5066 time_store);
5067 } else
5068 vty_out(vty, " Poll timer due in %s\n",
5069 ospf_timer_dump(nbr_nbma->t_poll, timebuf,
5070 sizeof(timebuf)));
5071 }
5072
5073 /* Show poll-interval timer thread. */
5074 if (use_json) {
5075 if (nbr_nbma->t_poll != NULL)
5076 json_object_string_add(json_sub,
5077 "pollIntervalTimerThread", "on");
5078 } else
5079 vty_out(vty, " Thread Poll Timer %s\n",
5080 nbr_nbma->t_poll != NULL ? "on" : "off");
5081
5082 if (use_json)
5083 json_object_object_add(json, "noNbrId", json_sub);
5084 }
5085
5086 static void show_ip_ospf_neighbor_detail_sub(struct vty *vty,
5087 struct ospf_interface *oi,
5088 struct ospf_neighbor *nbr,
5089 struct ospf_neighbor *prev_nbr,
5090 json_object *json, bool use_json)
5091 {
5092 char timebuf[OSPF_TIME_DUMP_SIZE];
5093 json_object *json_neigh = NULL, *json_neigh_array = NULL;
5094 char neigh_str[INET_ADDRSTRLEN] = {0};
5095 char neigh_state[16] = {0};
5096
5097 if (use_json) {
5098 if (prev_nbr &&
5099 !IPV4_ADDR_SAME(&prev_nbr->src, &nbr->src)) {
5100 json_neigh_array = NULL;
5101 }
5102
5103 if (nbr->state == NSM_Attempt
5104 && nbr->router_id.s_addr == INADDR_ANY)
5105 strlcpy(neigh_str, "noNbrId", sizeof(neigh_str));
5106 else
5107 inet_ntop(AF_INET, &nbr->router_id,
5108 neigh_str, sizeof(neigh_str));
5109
5110 json_object_object_get_ex(json, neigh_str, &json_neigh_array);
5111
5112 if (!json_neigh_array) {
5113 json_neigh_array = json_object_new_array();
5114 json_object_object_add(json, neigh_str,
5115 json_neigh_array);
5116 }
5117
5118 json_neigh = json_object_new_object();
5119
5120 } else {
5121 /* Show neighbor ID. */
5122 if (nbr->state == NSM_Attempt
5123 && nbr->router_id.s_addr == INADDR_ANY)
5124 vty_out(vty, " Neighbor %s,", "-");
5125 else
5126 vty_out(vty, " Neighbor %pI4,",
5127 &nbr->router_id);
5128 }
5129
5130 /* Show interface address. */
5131 if (use_json)
5132 json_object_string_addf(json_neigh, "ifaceAddress", "%pI4",
5133 &nbr->address.u.prefix4);
5134 else
5135 vty_out(vty, " interface address %pI4\n",
5136 &nbr->address.u.prefix4);
5137
5138 /* Show Area ID. */
5139 if (use_json) {
5140 json_object_string_add(json_neigh, "areaId",
5141 ospf_area_desc_string(oi->area));
5142 json_object_string_add(json_neigh, "ifaceName", oi->ifp->name);
5143 } else
5144 vty_out(vty, " In the area %s via interface %s\n",
5145 ospf_area_desc_string(oi->area), oi->ifp->name);
5146
5147 /* Show neighbor priority and state. */
5148 ospf_nbr_ism_state_message(nbr, neigh_state, sizeof(neigh_state));
5149 if (use_json) {
5150 json_object_int_add(json_neigh, "nbrPriority", nbr->priority);
5151 json_object_string_add(json_neigh, "nbrState", neigh_state);
5152 } else
5153 vty_out(vty, " Neighbor priority is %d, State is %s,",
5154 nbr->priority, neigh_state);
5155
5156 /* Show state changes. */
5157 if (use_json)
5158 json_object_int_add(json_neigh, "stateChangeCounter",
5159 nbr->state_change);
5160 else
5161 vty_out(vty, " %d state changes\n", nbr->state_change);
5162
5163 if (nbr->ts_last_progress.tv_sec || nbr->ts_last_progress.tv_usec) {
5164 struct timeval res;
5165 long time_store;
5166
5167 time_store =
5168 monotime_since(&nbr->ts_last_progress, &res) / 1000LL;
5169 if (use_json) {
5170 json_object_int_add(json_neigh, "lastPrgrsvChangeMsec",
5171 time_store);
5172 } else {
5173 vty_out(vty,
5174 " Most recent state change statistics:\n");
5175 vty_out(vty, " Progressive change %s ago\n",
5176 ospf_timeval_dump(&res, timebuf,
5177 sizeof(timebuf)));
5178 }
5179 }
5180
5181 if (nbr->ts_last_regress.tv_sec || nbr->ts_last_regress.tv_usec) {
5182 struct timeval res;
5183 long time_store;
5184
5185 time_store =
5186 monotime_since(&nbr->ts_last_regress, &res) / 1000LL;
5187 if (use_json) {
5188 json_object_int_add(json_neigh,
5189 "lastRegressiveChangeMsec",
5190 time_store);
5191 if (nbr->last_regress_str)
5192 json_object_string_add(
5193 json_neigh,
5194 "lastRegressiveChangeReason",
5195 nbr->last_regress_str);
5196 } else {
5197 vty_out(vty,
5198 " Regressive change %s ago, due to %s\n",
5199 ospf_timeval_dump(&res, timebuf,
5200 sizeof(timebuf)),
5201 (nbr->last_regress_str ? nbr->last_regress_str
5202 : "??"));
5203 }
5204 }
5205
5206 /* Show Designated Rotuer ID. */
5207 if (use_json)
5208 json_object_string_addf(json_neigh, "routerDesignatedId",
5209 "%pI4", &nbr->d_router);
5210 else
5211 vty_out(vty, " DR is %pI4,", &nbr->d_router);
5212
5213 /* Show Backup Designated Rotuer ID. */
5214 if (use_json)
5215 json_object_string_addf(json_neigh, "routerDesignatedBackupId",
5216 "%pI4", &nbr->bd_router);
5217 else
5218 vty_out(vty, " BDR is %pI4\n", &nbr->bd_router);
5219
5220 /* Show options. */
5221 if (use_json) {
5222 json_object_int_add(json_neigh, "optionsCounter", nbr->options);
5223 json_object_string_add(json_neigh, "optionsList",
5224 ospf_options_dump(nbr->options));
5225 } else
5226 vty_out(vty, " Options %d %s\n", nbr->options,
5227 ospf_options_dump(nbr->options));
5228
5229 /* Show Router Dead interval timer. */
5230 if (use_json) {
5231 if (nbr->t_inactivity) {
5232 long time_store;
5233 time_store = monotime_until(&nbr->t_inactivity->u.sands,
5234 NULL)
5235 / 1000LL;
5236 json_object_int_add(json_neigh,
5237 "routerDeadIntervalTimerDueMsec",
5238 time_store);
5239 } else
5240 json_object_int_add(
5241 json_neigh,
5242 "routerDeadIntervalTimerDueMsec", -1);
5243 } else
5244 vty_out(vty, " Dead timer due in %s\n",
5245 ospf_timer_dump(nbr->t_inactivity, timebuf,
5246 sizeof(timebuf)));
5247
5248 /* Show Database Summary list. */
5249 if (use_json)
5250 json_object_int_add(json_neigh, "databaseSummaryListCounter",
5251 ospf_db_summary_count(nbr));
5252 else
5253 vty_out(vty, " Database Summary List %d\n",
5254 ospf_db_summary_count(nbr));
5255
5256 /* Show Link State Request list. */
5257 if (use_json)
5258 json_object_int_add(json_neigh, "linkStateRequestListCounter",
5259 ospf_ls_request_count(nbr));
5260 else
5261 vty_out(vty, " Link State Request List %ld\n",
5262 ospf_ls_request_count(nbr));
5263
5264 /* Show Link State Retransmission list. */
5265 if (use_json)
5266 json_object_int_add(json_neigh,
5267 "linkStateRetransmissionListCounter",
5268 ospf_ls_retransmit_count(nbr));
5269 else
5270 vty_out(vty, " Link State Retransmission List %ld\n",
5271 ospf_ls_retransmit_count(nbr));
5272
5273 /* Show inactivity timer thread. */
5274 if (use_json) {
5275 if (nbr->t_inactivity != NULL)
5276 json_object_string_add(json_neigh,
5277 "threadInactivityTimer", "on");
5278 } else
5279 vty_out(vty, " Thread Inactivity Timer %s\n",
5280 nbr->t_inactivity != NULL ? "on" : "off");
5281
5282 /* Show Database Description retransmission thread. */
5283 if (use_json) {
5284 if (nbr->t_db_desc != NULL)
5285 json_object_string_add(
5286 json_neigh,
5287 "threadDatabaseDescriptionRetransmission",
5288 "on");
5289 } else
5290 vty_out(vty,
5291 " Thread Database Description Retransmision %s\n",
5292 nbr->t_db_desc != NULL ? "on" : "off");
5293
5294 /* Show Link State Request Retransmission thread. */
5295 if (use_json) {
5296 if (nbr->t_ls_req != NULL)
5297 json_object_string_add(
5298 json_neigh,
5299 "threadLinkStateRequestRetransmission", "on");
5300 } else
5301 vty_out(vty,
5302 " Thread Link State Request Retransmission %s\n",
5303 nbr->t_ls_req != NULL ? "on" : "off");
5304
5305 /* Show Link State Update Retransmission thread. */
5306 if (use_json) {
5307 if (nbr->t_ls_upd != NULL)
5308 json_object_string_add(
5309 json_neigh,
5310 "threadLinkStateUpdateRetransmission",
5311 "on");
5312 } else
5313 vty_out(vty,
5314 " Thread Link State Update Retransmission %s\n\n",
5315 nbr->t_ls_upd != NULL ? "on" : "off");
5316
5317 if (!use_json) {
5318 vty_out(vty, " Graceful restart Helper info:\n");
5319
5320 if (OSPF_GR_IS_ACTIVE_HELPER(nbr)) {
5321 vty_out(vty,
5322 " Graceful Restart HELPER Status : Inprogress.\n");
5323
5324 vty_out(vty,
5325 " Graceful Restart grace period time: %d (seconds).\n",
5326 nbr->gr_helper_info.recvd_grace_period);
5327 vty_out(vty, " Graceful Restart reason: %s.\n",
5328 ospf_restart_reason2str(
5329 nbr->gr_helper_info.gr_restart_reason));
5330 } else {
5331 vty_out(vty,
5332 " Graceful Restart HELPER Status : None\n");
5333 }
5334
5335 if (nbr->gr_helper_info.rejected_reason
5336 != OSPF_HELPER_REJECTED_NONE)
5337 vty_out(vty, " Helper rejected reason: %s.\n",
5338 ospf_rejected_reason2str(
5339 nbr->gr_helper_info.rejected_reason));
5340
5341 if (nbr->gr_helper_info.helper_exit_reason
5342 != OSPF_GR_HELPER_EXIT_NONE)
5343 vty_out(vty, " Last helper exit reason: %s.\n\n",
5344 ospf_exit_reason2str(
5345 nbr->gr_helper_info.helper_exit_reason));
5346 else
5347 vty_out(vty, "\n");
5348 } else {
5349 json_object_string_add(json_neigh, "grHelperStatus",
5350 OSPF_GR_IS_ACTIVE_HELPER(nbr) ?
5351 "Inprogress"
5352 : "None");
5353 if (OSPF_GR_IS_ACTIVE_HELPER(nbr)) {
5354 json_object_int_add(
5355 json_neigh, "graceInterval",
5356 nbr->gr_helper_info.recvd_grace_period);
5357 json_object_string_add(
5358 json_neigh, "grRestartReason",
5359 ospf_restart_reason2str(
5360 nbr->gr_helper_info.gr_restart_reason));
5361 }
5362
5363 if (nbr->gr_helper_info.rejected_reason
5364 != OSPF_HELPER_REJECTED_NONE)
5365 json_object_string_add(
5366 json_neigh, "helperRejectReason",
5367 ospf_rejected_reason2str(
5368 nbr->gr_helper_info.rejected_reason));
5369
5370 if (nbr->gr_helper_info.helper_exit_reason
5371 != OSPF_GR_HELPER_EXIT_NONE)
5372 json_object_string_add(
5373 json_neigh, "helperExitReason",
5374 ospf_exit_reason2str(
5375 nbr->gr_helper_info
5376 .helper_exit_reason));
5377 }
5378
5379 bfd_sess_show(vty, json_neigh, nbr->bfd_session);
5380
5381 if (use_json)
5382 json_object_array_add(json_neigh_array, json_neigh);
5383
5384 }
5385
5386 static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf,
5387 struct in_addr *router_id,
5388 bool use_json, uint8_t use_vrf,
5389 bool is_detail)
5390 {
5391 struct listnode *node;
5392 struct ospf_neighbor *nbr;
5393 struct ospf_interface *oi;
5394 json_object *json = NULL;
5395
5396 if (use_json)
5397 json = json_object_new_object();
5398
5399 if (ospf->instance) {
5400 if (use_json)
5401 json_object_int_add(json, "ospfInstance",
5402 ospf->instance);
5403 else
5404 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
5405 }
5406
5407 ospf_show_vrf_name(ospf, vty, json, use_vrf);
5408
5409 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
5410 nbr = ospf_nbr_lookup_by_routerid(oi->nbrs, router_id);
5411
5412 if (!nbr)
5413 continue;
5414
5415 if (is_detail)
5416 show_ip_ospf_neighbor_detail_sub(vty, oi, nbr, NULL,
5417 json, use_json);
5418 else
5419 show_ip_ospf_neighbour_brief(vty, nbr, NULL, json,
5420 use_json);
5421 }
5422
5423 if (use_json)
5424 vty_json(vty, json);
5425 else
5426 vty_out(vty, "\n");
5427
5428 return CMD_SUCCESS;
5429 }
5430
5431 DEFPY(show_ip_ospf_neighbor_id, show_ip_ospf_neighbor_id_cmd,
5432 "show ip ospf neighbor A.B.C.D$router_id [detail$detail] [json$json]",
5433 SHOW_STR IP_STR
5434 "OSPF information\n"
5435 "Neighbor list\n"
5436 "Neighbor ID\n"
5437 "Detailed output\n" JSON_STR)
5438 {
5439 struct ospf *ospf;
5440 struct listnode *node;
5441 int ret = CMD_SUCCESS;
5442
5443 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
5444 if (!ospf->oi_running)
5445 continue;
5446 ret = show_ip_ospf_neighbor_id_common(vty, ospf, &router_id,
5447 !!json, 0, !!detail);
5448 }
5449
5450 return ret;
5451 }
5452
5453 DEFPY(show_ip_ospf_instance_neighbor_id, show_ip_ospf_instance_neighbor_id_cmd,
5454 "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [detail$detail] [json$json]",
5455 SHOW_STR IP_STR
5456 "OSPF information\n"
5457 "Instance ID\n"
5458 "Neighbor list\n"
5459 "Neighbor ID\n"
5460 "Detailed output\n" JSON_STR)
5461 {
5462 struct ospf *ospf;
5463
5464 if (instance != ospf_instance)
5465 return CMD_NOT_MY_INSTANCE;
5466
5467 ospf = ospf_lookup_instance(instance);
5468 if (!ospf || !ospf->oi_running)
5469 return CMD_SUCCESS;
5470
5471 return show_ip_ospf_neighbor_id_common(vty, ospf, &router_id, !!json, 0,
5472 !!detail);
5473 }
5474
5475 static int show_ip_ospf_neighbor_detail_common(struct vty *vty,
5476 struct ospf *ospf,
5477 json_object *json, bool use_json,
5478 uint8_t use_vrf)
5479 {
5480 struct ospf_interface *oi;
5481 struct listnode *node;
5482 json_object *json_vrf = NULL;
5483 json_object *json_nbr_sub = NULL;
5484
5485 if (use_json) {
5486 if (use_vrf)
5487 json_vrf = json_object_new_object();
5488 else
5489 json_vrf = json;
5490
5491 json_nbr_sub = json_object_new_object();
5492 }
5493
5494 if (ospf->instance) {
5495 if (use_json)
5496 json_object_int_add(json, "ospfInstance",
5497 ospf->instance);
5498 else
5499 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
5500 }
5501
5502 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
5503
5504 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
5505 struct route_node *rn;
5506 struct ospf_neighbor *nbr, *prev_nbr = NULL;
5507
5508 for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
5509 nbr = rn->info;
5510
5511 if (!nbr)
5512 continue;
5513
5514 if (nbr != oi->nbr_self) {
5515 if (nbr->state != NSM_Down) {
5516 show_ip_ospf_neighbor_detail_sub(
5517 vty, oi, nbr, prev_nbr,
5518 json_nbr_sub, use_json);
5519 }
5520 }
5521 prev_nbr = nbr;
5522 }
5523 }
5524
5525 if (use_json) {
5526 json_object_object_add(json_vrf, "neighbors",
5527 json_nbr_sub);
5528 if (use_vrf)
5529 json_object_object_add(json, ospf_get_name(ospf),
5530 json_vrf);
5531 } else
5532 vty_out(vty, "\n");
5533
5534 return CMD_SUCCESS;
5535 }
5536
5537 DEFUN (show_ip_ospf_neighbor_detail,
5538 show_ip_ospf_neighbor_detail_cmd,
5539 "show ip ospf [vrf <NAME|all>] neighbor detail [json]",
5540 SHOW_STR
5541 IP_STR
5542 "OSPF information\n"
5543 VRF_CMD_HELP_STR
5544 "All VRFs\n"
5545 "Neighbor list\n"
5546 "detail of all neighbors\n"
5547 JSON_STR)
5548 {
5549 struct ospf *ospf;
5550 bool uj = use_json(argc, argv);
5551 struct listnode *node = NULL;
5552 char *vrf_name = NULL;
5553 bool all_vrf = false;
5554 int ret = CMD_SUCCESS;
5555 int inst = 0;
5556 int idx_vrf = 0;
5557 uint8_t use_vrf = 0;
5558 json_object *json = NULL;
5559
5560 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
5561
5562 if (uj)
5563 json = json_object_new_object();
5564
5565 /* vrf input is provided could be all or specific vrf*/
5566 if (vrf_name) {
5567 use_vrf = 1;
5568 if (all_vrf) {
5569 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
5570 if (!ospf->oi_running)
5571 continue;
5572 ret = show_ip_ospf_neighbor_detail_common(
5573 vty, ospf, json, uj, use_vrf);
5574 }
5575 if (uj)
5576 vty_json(vty, json);
5577
5578 return ret;
5579 }
5580 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
5581 if (ospf == NULL || !ospf->oi_running) {
5582 if (uj)
5583 json_object_free(json);
5584 return CMD_SUCCESS;
5585 }
5586 } else {
5587 /* Display default ospf (instance 0) info */
5588 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
5589 if (ospf == NULL || !ospf->oi_running) {
5590 if (uj)
5591 json_object_free(json);
5592 return CMD_SUCCESS;
5593 }
5594 }
5595
5596 if (ospf) {
5597 ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj,
5598 use_vrf);
5599 if (uj) {
5600 vty_out(vty, "%s\n",
5601 json_object_to_json_string_ext(
5602 json, JSON_C_TO_STRING_PRETTY));
5603 }
5604 }
5605
5606 if (uj)
5607 json_object_free(json);
5608
5609 return ret;
5610 }
5611
5612 DEFUN (show_ip_ospf_instance_neighbor_detail,
5613 show_ip_ospf_instance_neighbor_detail_cmd,
5614 "show ip ospf (1-65535) neighbor detail [json]",
5615 SHOW_STR
5616 IP_STR
5617 "OSPF information\n"
5618 "Instance ID\n"
5619 "Neighbor list\n"
5620 "detail of all neighbors\n"
5621 JSON_STR)
5622 {
5623 int idx_number = 3;
5624 struct ospf *ospf;
5625 unsigned short instance = 0;
5626 bool uj = use_json(argc, argv);
5627 json_object *json = NULL;
5628 int ret = CMD_SUCCESS;
5629
5630 instance = strtoul(argv[idx_number]->arg, NULL, 10);
5631 if (instance != ospf_instance)
5632 return CMD_NOT_MY_INSTANCE;
5633
5634 ospf = ospf_lookup_instance(instance);
5635 if (!ospf || !ospf->oi_running)
5636 return CMD_SUCCESS;
5637
5638 if (uj)
5639 json = json_object_new_object();
5640
5641 ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj, 0);
5642
5643 if (uj)
5644 vty_json(vty, json);
5645
5646 return ret;
5647 }
5648
5649 static int show_ip_ospf_neighbor_detail_all_common(struct vty *vty,
5650 struct ospf *ospf,
5651 json_object *json,
5652 bool use_json,
5653 uint8_t use_vrf)
5654 {
5655 struct listnode *node;
5656 struct ospf_interface *oi;
5657 json_object *json_vrf = NULL;
5658
5659 if (use_json) {
5660 if (use_vrf)
5661 json_vrf = json_object_new_object();
5662 else
5663 json_vrf = json;
5664 }
5665
5666 if (ospf->instance) {
5667 if (use_json)
5668 json_object_int_add(json, "ospfInstance",
5669 ospf->instance);
5670 else
5671 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
5672 }
5673
5674 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
5675
5676 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
5677 struct route_node *rn;
5678 struct ospf_neighbor *nbr, *prev_nbr = NULL;
5679 struct ospf_nbr_nbma *nbr_nbma;
5680
5681 for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
5682 nbr = rn->info;
5683
5684 if (!nbr)
5685 continue;
5686
5687 if (nbr != oi->nbr_self)
5688 if (nbr->state != NSM_Down)
5689 show_ip_ospf_neighbor_detail_sub(
5690 vty, oi, rn->info, prev_nbr,
5691 json_vrf, use_json);
5692 prev_nbr = nbr;
5693 }
5694
5695 if (oi->type != OSPF_IFTYPE_NBMA)
5696 continue;
5697
5698 struct listnode *nd;
5699
5700 for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nd, nbr_nbma)) {
5701 if (nbr_nbma->nbr == NULL ||
5702 nbr_nbma->nbr->state == NSM_Down)
5703 show_ip_ospf_nbr_nbma_detail_sub(
5704 vty, oi, nbr_nbma, use_json, json_vrf);
5705 }
5706 }
5707
5708 if (use_json) {
5709 if (use_vrf)
5710 json_object_object_add(json, ospf_get_name(ospf),
5711 json_vrf);
5712 } else {
5713 vty_out(vty, "\n");
5714 }
5715
5716 return CMD_SUCCESS;
5717 }
5718
5719 DEFUN (show_ip_ospf_neighbor_detail_all,
5720 show_ip_ospf_neighbor_detail_all_cmd,
5721 "show ip ospf [vrf <NAME|all>] neighbor detail all [json]",
5722 SHOW_STR
5723 IP_STR
5724 "OSPF information\n"
5725 VRF_CMD_HELP_STR
5726 "All VRFs\n"
5727 "Neighbor list\n"
5728 "detail of all neighbors\n"
5729 "include down status neighbor\n"
5730 JSON_STR)
5731 {
5732 struct ospf *ospf;
5733 bool uj = use_json(argc, argv);
5734 struct listnode *node = NULL;
5735 char *vrf_name = NULL;
5736 bool all_vrf = false;
5737 int ret = CMD_SUCCESS;
5738 int inst = 0;
5739 int idx_vrf = 0;
5740 uint8_t use_vrf = 0;
5741 json_object *json = NULL;
5742
5743 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
5744
5745 if (uj)
5746 json = json_object_new_object();
5747
5748 /* vrf input is provided could be all or specific vrf*/
5749 if (vrf_name) {
5750 use_vrf = 1;
5751 if (all_vrf) {
5752 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
5753 if (!ospf->oi_running)
5754 continue;
5755 ret = show_ip_ospf_neighbor_detail_all_common(
5756 vty, ospf, json, uj, use_vrf);
5757 }
5758
5759 if (uj)
5760 vty_json(vty, json);
5761
5762 return ret;
5763 }
5764 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
5765 if (ospf == NULL || !ospf->oi_running) {
5766 if (uj)
5767 json_object_free(json);
5768 return CMD_SUCCESS;
5769 }
5770 } else {
5771 /* Display default ospf (instance 0) info */
5772 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
5773 if (ospf == NULL || !ospf->oi_running) {
5774 if (uj)
5775 json_object_free(json);
5776 return CMD_SUCCESS;
5777 }
5778 }
5779
5780 if (ospf) {
5781 ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json,
5782 uj, use_vrf);
5783 if (uj) {
5784 vty_out(vty, "%s\n",
5785 json_object_to_json_string_ext(
5786 json, JSON_C_TO_STRING_PRETTY));
5787 }
5788 }
5789
5790 if (uj)
5791 json_object_free(json);
5792
5793 return ret;
5794 }
5795
5796 DEFUN (show_ip_ospf_instance_neighbor_detail_all,
5797 show_ip_ospf_instance_neighbor_detail_all_cmd,
5798 "show ip ospf (1-65535) neighbor detail all [json]",
5799 SHOW_STR
5800 IP_STR
5801 "OSPF information\n"
5802 "Instance ID\n"
5803 "Neighbor list\n"
5804 "detail of all neighbors\n"
5805 "include down status neighbor\n"
5806 JSON_STR)
5807 {
5808 int idx_number = 3;
5809 struct ospf *ospf;
5810 unsigned short instance = 0;
5811 bool uj = use_json(argc, argv);
5812 json_object *json = NULL;
5813 int ret = CMD_SUCCESS;
5814
5815 instance = strtoul(argv[idx_number]->arg, NULL, 10);
5816 if (instance != ospf_instance)
5817 return CMD_NOT_MY_INSTANCE;
5818
5819 ospf = ospf_lookup_instance(instance);
5820 if (!ospf || !ospf->oi_running)
5821 return CMD_SUCCESS;
5822
5823 if (uj)
5824 json = json_object_new_object();
5825
5826 ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json, uj, 0);
5827
5828 if (uj)
5829 vty_json(vty, json);
5830
5831 return ret;
5832 }
5833
5834 static int show_ip_ospf_neighbor_int_detail_common(struct vty *vty,
5835 struct ospf *ospf,
5836 int arg_base,
5837 struct cmd_token **argv,
5838 bool use_json)
5839 {
5840 struct ospf_interface *oi;
5841 struct interface *ifp;
5842 struct route_node *rn, *nrn;
5843 struct ospf_neighbor *nbr;
5844 json_object *json = NULL;
5845
5846 if (use_json)
5847 json = json_object_new_object();
5848
5849 if (ospf->instance) {
5850 if (use_json)
5851 json_object_int_add(json, "ospfInstance",
5852 ospf->instance);
5853 else
5854 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
5855 }
5856
5857 ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id);
5858 if (!ifp) {
5859 if (!use_json)
5860 vty_out(vty, "No such interface.\n");
5861 else {
5862 vty_out(vty, "{}\n");
5863 json_object_free(json);
5864 }
5865 return CMD_WARNING;
5866 }
5867
5868 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
5869 oi = rn->info;
5870
5871 if (!oi)
5872 continue;
5873
5874 for (nrn = route_top(oi->nbrs); nrn; nrn = route_next(nrn)) {
5875 nbr = nrn->info;
5876
5877 if (!nbr)
5878 continue;
5879
5880 if (nbr == oi->nbr_self)
5881 continue;
5882
5883 if (nbr->state == NSM_Down)
5884 continue;
5885
5886 show_ip_ospf_neighbor_detail_sub(vty, oi, nbr, NULL,
5887 json, use_json);
5888 }
5889 }
5890
5891 if (use_json)
5892 vty_json(vty, json);
5893 else
5894 vty_out(vty, "\n");
5895
5896 return CMD_SUCCESS;
5897 }
5898
5899 DEFUN (show_ip_ospf_neighbor_int_detail,
5900 show_ip_ospf_neighbor_int_detail_cmd,
5901 "show ip ospf neighbor IFNAME detail [json]",
5902 SHOW_STR
5903 IP_STR
5904 "OSPF information\n"
5905 "Neighbor list\n"
5906 "Interface name\n"
5907 "detail of all neighbors\n"
5908 JSON_STR)
5909 {
5910 struct ospf *ospf;
5911 bool uj = use_json(argc, argv);
5912 struct listnode *node = NULL;
5913 int ret = CMD_SUCCESS;
5914 bool ospf_output = false;
5915
5916 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
5917 if (!ospf->oi_running)
5918 continue;
5919 ospf_output = true;
5920 ret = show_ip_ospf_neighbor_int_detail_common(vty, ospf, 4,
5921 argv, uj);
5922 }
5923
5924 if (!ospf_output)
5925 vty_out(vty, "%% OSPF instance not found\n");
5926
5927 return ret;
5928 }
5929
5930 DEFUN (show_ip_ospf_instance_neighbor_int_detail,
5931 show_ip_ospf_instance_neighbor_int_detail_cmd,
5932 "show ip ospf (1-65535) neighbor IFNAME detail [json]",
5933 SHOW_STR
5934 IP_STR
5935 "OSPF information\n"
5936 "Instance ID\n"
5937 "Neighbor list\n"
5938 "Interface name\n"
5939 "detail of all neighbors\n"
5940 JSON_STR)
5941 {
5942 int idx_number = 3;
5943 int idx_ifname = 5;
5944 struct ospf *ospf;
5945 unsigned short instance = 0;
5946 bool uj = use_json(argc, argv);
5947
5948 instance = strtoul(argv[idx_number]->arg, NULL, 10);
5949 if (instance != ospf_instance)
5950 return CMD_NOT_MY_INSTANCE;
5951
5952 ospf = ospf_lookup_instance(instance);
5953 if (!ospf || !ospf->oi_running)
5954 return CMD_SUCCESS;
5955
5956 return show_ip_ospf_neighbor_int_detail_common(vty, ospf, idx_ifname,
5957 argv, uj);
5958 }
5959
5960 /* Show functions */
5961 static int show_lsa_summary(struct vty *vty, struct ospf_lsa *lsa, int self,
5962 json_object *json_lsa)
5963 {
5964 struct router_lsa *rl;
5965 struct summary_lsa *sl;
5966 struct as_external_lsa *asel;
5967 struct prefix_ipv4 p;
5968
5969 if (lsa != NULL) {
5970 /* If self option is set, check LSA self flag. */
5971 if (self == 0 || IS_LSA_SELF(lsa)) {
5972
5973 if (!json_lsa) {
5974 /* LSA common part show. */
5975 vty_out(vty, "%-15pI4",
5976 &lsa->data->id);
5977 vty_out(vty, "%-15pI4 %4d 0x%08lx 0x%04x",
5978 &lsa->data->adv_router, LS_AGE(lsa),
5979 (unsigned long)ntohl(
5980 lsa->data->ls_seqnum),
5981 ntohs(lsa->data->checksum));
5982 } else {
5983 char seqnum[10];
5984 char checksum[10];
5985
5986 snprintf(seqnum, sizeof(seqnum), "%x",
5987 ntohl(lsa->data->ls_seqnum));
5988 snprintf(checksum, sizeof(checksum), "%x",
5989 ntohs(lsa->data->checksum));
5990 json_object_string_addf(json_lsa, "lsId",
5991 "%pI4", &lsa->data->id);
5992 json_object_string_addf(
5993 json_lsa, "advertisedRouter", "%pI4",
5994 &lsa->data->adv_router);
5995 json_object_int_add(json_lsa, "lsaAge",
5996 LS_AGE(lsa));
5997 json_object_string_add(
5998 json_lsa, "sequenceNumber", seqnum);
5999 json_object_string_add(json_lsa, "checksum",
6000 checksum);
6001 }
6002
6003 /* LSA specific part show. */
6004 switch (lsa->data->type) {
6005 case OSPF_ROUTER_LSA:
6006 rl = (struct router_lsa *)lsa->data;
6007
6008 if (!json_lsa)
6009 vty_out(vty, " %-d", ntohs(rl->links));
6010 else
6011 json_object_int_add(json_lsa,
6012 "numOfRouterLinks",
6013 ntohs(rl->links));
6014 break;
6015 case OSPF_SUMMARY_LSA:
6016 sl = (struct summary_lsa *)lsa->data;
6017
6018 p.family = AF_INET;
6019 p.prefix = sl->header.id;
6020 p.prefixlen = ip_masklen(sl->mask);
6021 apply_mask_ipv4(&p);
6022
6023 if (!json_lsa)
6024 vty_out(vty, " %pFX", &p);
6025 else {
6026 json_object_string_addf(
6027 json_lsa, "summaryAddress",
6028 "%pFX", &p);
6029 }
6030 break;
6031 case OSPF_AS_EXTERNAL_LSA:
6032 case OSPF_AS_NSSA_LSA:
6033 asel = (struct as_external_lsa *)lsa->data;
6034
6035 p.family = AF_INET;
6036 p.prefix = asel->header.id;
6037 p.prefixlen = ip_masklen(asel->mask);
6038 apply_mask_ipv4(&p);
6039
6040 if (!json_lsa)
6041 vty_out(vty, " %s %pFX [0x%lx]",
6042 IS_EXTERNAL_METRIC(
6043 asel->e[0].tos)
6044 ? "E2"
6045 : "E1",
6046 &p,
6047 (unsigned long)ntohl(
6048 asel->e[0].route_tag));
6049 else {
6050 json_object_string_add(
6051 json_lsa, "metricType",
6052 IS_EXTERNAL_METRIC(
6053 asel->e[0].tos)
6054 ? "E2"
6055 : "E1");
6056 json_object_string_addf(
6057 json_lsa, "route", "%pFX", &p);
6058 json_object_int_add(
6059 json_lsa, "tag",
6060 (unsigned long)ntohl(
6061 asel->e[0].route_tag));
6062 }
6063 break;
6064 case OSPF_NETWORK_LSA:
6065 case OSPF_ASBR_SUMMARY_LSA:
6066 case OSPF_OPAQUE_LINK_LSA:
6067 case OSPF_OPAQUE_AREA_LSA:
6068 case OSPF_OPAQUE_AS_LSA:
6069 default:
6070 break;
6071 }
6072
6073 if (!json_lsa)
6074 vty_out(vty, "\n");
6075 }
6076
6077 return 1;
6078 }
6079
6080 return 0;
6081 }
6082
6083 static const char *const show_database_desc[] = {
6084 "unknown",
6085 "Router Link States",
6086 "Net Link States",
6087 "Summary Link States",
6088 "ASBR-Summary Link States",
6089 "AS External Link States",
6090 "Group Membership LSA",
6091 "NSSA-external Link States",
6092 "Type-8 LSA",
6093 "Link-Local Opaque-LSA",
6094 "Area-Local Opaque-LSA",
6095 "AS-external Opaque-LSA",
6096 };
6097
6098 static const char * const show_database_desc_json[] = {
6099 "unknown",
6100 "routerLinkStates",
6101 "networkLinkStates",
6102 "summaryLinkStates",
6103 "asbrSummaryLinkStates",
6104 "asExternalLinkStates",
6105 "groupMembershipLsa",
6106 "nssaExternalLinkStates",
6107 "type8Lsa",
6108 "linkLocalOpaqueLsa",
6109 "areaLocalOpaqueLsa",
6110 "asExternalOpaqueLsa",
6111 };
6112
6113 static const char *const show_database_desc_count_json[] = {
6114 "unknownCount",
6115 "routerLinkStatesCount",
6116 "networkLinkStatesCount",
6117 "summaryLinkStatesCount",
6118 "asbrSummaryLinkStatesCount",
6119 "asExternalLinkStatesCount",
6120 "groupMembershipLsaCount",
6121 "nssaExternalLinkStatesCount",
6122 "type8LsaCount",
6123 "linkLocalOpaqueLsaCount",
6124 "areaLocalOpaqueLsaCount",
6125 "asExternalOpaqueLsaCount",
6126 };
6127
6128 static const char *const show_database_header[] = {
6129 "",
6130 "Link ID ADV Router Age Seq# CkSum Link count",
6131 "Link ID ADV Router Age Seq# CkSum",
6132 "Link ID ADV Router Age Seq# CkSum Route",
6133 "Link ID ADV Router Age Seq# CkSum",
6134 "Link ID ADV Router Age Seq# CkSum Route",
6135 " --- header for Group Member ----",
6136 "Link ID ADV Router Age Seq# CkSum Route",
6137 " --- type-8 ---",
6138 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6139 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6140 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6141 };
6142
6143 static void show_ip_ospf_database_header(struct vty *vty, struct ospf_lsa *lsa,
6144 json_object *json)
6145 {
6146 struct router_lsa *rlsa = (struct router_lsa *)lsa->data;
6147
6148 if (!json) {
6149 vty_out(vty, " LS age: %d\n", LS_AGE(lsa));
6150 vty_out(vty, " Options: 0x%-2x : %s\n", lsa->data->options,
6151 ospf_options_dump(lsa->data->options));
6152 vty_out(vty, " LS Flags: 0x%-2x %s\n", lsa->flags,
6153 ((lsa->flags & OSPF_LSA_LOCAL_XLT)
6154 ? "(Translated from Type-7)"
6155 : ""));
6156
6157 if (lsa->data->type == OSPF_ROUTER_LSA) {
6158 vty_out(vty, " Flags: 0x%x", rlsa->flags);
6159
6160 if (rlsa->flags)
6161 vty_out(vty, " :%s%s%s%s",
6162 IS_ROUTER_LSA_BORDER(rlsa) ? " ABR"
6163 : "",
6164 IS_ROUTER_LSA_EXTERNAL(rlsa) ? " ASBR"
6165 : "",
6166 IS_ROUTER_LSA_VIRTUAL(rlsa)
6167 ? " VL-endpoint"
6168 : "",
6169 IS_ROUTER_LSA_SHORTCUT(rlsa)
6170 ? " Shortcut"
6171 : "");
6172
6173 vty_out(vty, "\n");
6174 }
6175 vty_out(vty, " LS Type: %s\n",
6176 lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL));
6177 vty_out(vty, " Link State ID: %pI4 %s\n",
6178 &lsa->data->id,
6179 lookup_msg(ospf_link_state_id_type_msg, lsa->data->type,
6180 NULL));
6181 vty_out(vty, " Advertising Router: %pI4\n",
6182 &lsa->data->adv_router);
6183 vty_out(vty, " LS Seq Number: %08lx\n",
6184 (unsigned long)ntohl(lsa->data->ls_seqnum));
6185 vty_out(vty, " Checksum: 0x%04x\n",
6186 ntohs(lsa->data->checksum));
6187 vty_out(vty, " Length: %d\n\n", ntohs(lsa->data->length));
6188 } else {
6189 char seqnum[10];
6190 char checksum[10];
6191
6192 snprintf(seqnum, 10, "%x", ntohl(lsa->data->ls_seqnum));
6193 snprintf(checksum, 10, "%x", ntohs(lsa->data->checksum));
6194
6195 json_object_int_add(json, "lsaAge", LS_AGE(lsa));
6196 json_object_string_add(json, "options",
6197 ospf_options_dump(lsa->data->options));
6198 json_object_int_add(json, "lsaFlags", lsa->flags);
6199
6200 if (lsa->flags & OSPF_LSA_LOCAL_XLT)
6201 json_object_boolean_true_add(json,
6202 "translatedFromType7");
6203
6204 if (lsa->data->type == OSPF_ROUTER_LSA) {
6205 json_object_int_add(json, "flags", rlsa->flags);
6206
6207 if (rlsa->flags) {
6208 if (IS_ROUTER_LSA_BORDER(rlsa))
6209 json_object_boolean_true_add(json,
6210 "abr");
6211 if (IS_ROUTER_LSA_EXTERNAL(rlsa))
6212 json_object_boolean_true_add(json,
6213 "asbr");
6214 if (IS_ROUTER_LSA_VIRTUAL(rlsa))
6215 json_object_boolean_true_add(
6216 json, "vlEndpoint");
6217 if (IS_ROUTER_LSA_SHORTCUT(rlsa))
6218 json_object_boolean_true_add(
6219 json, "shortcut");
6220 }
6221 }
6222
6223 json_object_string_add(
6224 json, "lsaType",
6225 lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL));
6226 json_object_string_addf(json, "linkStateId", "%pI4",
6227 &lsa->data->id);
6228 json_object_string_addf(json, "advertisingRouter", "%pI4",
6229 &lsa->data->adv_router);
6230 json_object_string_add(json, "lsaSeqNumber", seqnum);
6231 json_object_string_add(json, "checksum", checksum);
6232 json_object_int_add(json, "length", ntohs(lsa->data->length));
6233 }
6234 }
6235
6236 static const char *const link_type_desc[] = {
6237 "(null)",
6238 "another Router (point-to-point)",
6239 "a Transit Network",
6240 "Stub Network",
6241 "a Virtual Link",
6242 };
6243
6244 static const char *const link_id_desc[] = {
6245 "(null)", "Neighboring Router ID", "Designated Router address",
6246 "Net", "Neighboring Router ID",
6247 };
6248
6249 static const char *const link_data_desc[] = {
6250 "(null)", "Router Interface address", "Router Interface address",
6251 "Network Mask", "Router Interface address",
6252 };
6253
6254 static const char *const link_id_desc_json[] = {
6255 "null", "neighborRouterId", "designatedRouterAddress",
6256 "networkAddress", "neighborRouterId",
6257 };
6258
6259 static const char *const link_data_desc_json[] = {
6260 "null", "routerInterfaceAddress", "routerInterfaceAddress",
6261 "networkMask", "routerInterfaceAddress",
6262 };
6263
6264 /* Show router-LSA each Link information. */
6265 static void show_ip_ospf_database_router_links(struct vty *vty,
6266 struct router_lsa *rl,
6267 json_object *json)
6268 {
6269 int len, type;
6270 unsigned short i;
6271 json_object *json_links = NULL;
6272 json_object *json_link = NULL;
6273 int metric = 0;
6274 char buf[PREFIX_STRLEN];
6275
6276 if (json)
6277 json_links = json_object_new_object();
6278
6279 len = ntohs(rl->header.length) - 4;
6280 for (i = 0; i < ntohs(rl->links) && len > 0; len -= 12, i++) {
6281 type = rl->link[i].type;
6282
6283 if (json) {
6284 char link[16];
6285
6286 snprintf(link, sizeof(link), "link%u", i);
6287 json_link = json_object_new_object();
6288 json_object_string_add(json_link, "linkType",
6289 link_type_desc[type]);
6290 json_object_string_add(json_link,
6291 link_id_desc_json[type],
6292 inet_ntop(AF_INET,
6293 &rl->link[i].link_id,
6294 buf, sizeof(buf)));
6295 json_object_string_add(
6296 json_link, link_data_desc_json[type],
6297 inet_ntop(AF_INET, &rl->link[i].link_data,
6298 buf, sizeof(buf)));
6299 json_object_int_add(json_link, "numOfTosMetrics",
6300 metric);
6301 json_object_int_add(json_link, "tos0Metric",
6302 ntohs(rl->link[i].metric));
6303 json_object_object_add(json_links, link, json_link);
6304 } else {
6305 vty_out(vty, " Link connected to: %s\n",
6306 link_type_desc[type]);
6307 vty_out(vty, " (Link ID) %s: %pI4\n",
6308 link_id_desc[type],
6309 &rl->link[i].link_id);
6310 vty_out(vty, " (Link Data) %s: %pI4\n",
6311 link_data_desc[type],
6312 &rl->link[i].link_data);
6313 vty_out(vty, " Number of TOS metrics: 0\n");
6314 vty_out(vty, " TOS 0 Metric: %d\n",
6315 ntohs(rl->link[i].metric));
6316 vty_out(vty, "\n");
6317 }
6318 }
6319 if (json)
6320 json_object_object_add(json, "routerLinks", json_links);
6321 }
6322
6323 /* Show router-LSA detail information. */
6324 static int show_router_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
6325 json_object *json)
6326 {
6327 if (lsa != NULL) {
6328 struct router_lsa *rl = (struct router_lsa *)lsa->data;
6329
6330 show_ip_ospf_database_header(vty, lsa, json);
6331
6332 if (!json)
6333 vty_out(vty, " Number of Links: %d\n\n",
6334 ntohs(rl->links));
6335 else
6336 json_object_int_add(json, "numOfLinks",
6337 ntohs(rl->links));
6338
6339 show_ip_ospf_database_router_links(vty, rl, json);
6340
6341 if (!json)
6342 vty_out(vty, "\n");
6343 }
6344
6345 return 0;
6346 }
6347
6348 /* Show network-LSA detail information. */
6349 static int show_network_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
6350 json_object *json)
6351 {
6352 int length, i;
6353 char buf[PREFIX_STRLEN];
6354 json_object *json_attached_rt = NULL;
6355 json_object *json_router = NULL;
6356
6357 if (json)
6358 json_attached_rt = json_object_new_object();
6359
6360 if (lsa != NULL) {
6361 struct network_lsa *nl = (struct network_lsa *)lsa->data;
6362 struct in_addr *addr;
6363
6364 show_ip_ospf_database_header(vty, lsa, json);
6365
6366 if (!json)
6367 vty_out(vty, " Network Mask: /%d\n",
6368 ip_masklen(nl->mask));
6369 else
6370 json_object_int_add(json, "networkMask",
6371 ip_masklen(nl->mask));
6372
6373 length = lsa->size - OSPF_LSA_HEADER_SIZE - 4;
6374 addr = &nl->routers[0];
6375 for (i = 0; length > 0 && addr;
6376 length -= 4, addr = &nl->routers[++i])
6377 if (!json) {
6378 vty_out(vty, " Attached Router: %pI4\n",
6379 addr);
6380 vty_out(vty, "\n");
6381 } else {
6382 json_router = json_object_new_object();
6383 json_object_string_add(
6384 json_router, "attachedRouterId",
6385 inet_ntop(AF_INET, addr, buf,
6386 sizeof(buf)));
6387 json_object_object_add(json_attached_rt,
6388 inet_ntop(AF_INET, addr,
6389 buf,
6390 sizeof(buf)),
6391 json_router);
6392 }
6393 }
6394
6395 if (json)
6396 json_object_object_add(json, "attchedRouters",
6397 json_attached_rt);
6398
6399 return 0;
6400 }
6401
6402 /* Show summary-LSA detail information. */
6403 static int show_summary_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
6404 json_object *json)
6405 {
6406 if (lsa != NULL) {
6407 struct summary_lsa *sl = (struct summary_lsa *)lsa->data;
6408
6409 show_ip_ospf_database_header(vty, lsa, json);
6410
6411 if (!json) {
6412 vty_out(vty, " Network Mask: /%d\n",
6413 ip_masklen(sl->mask));
6414 vty_out(vty, " TOS: 0 Metric: %d\n",
6415 GET_METRIC(sl->metric));
6416 vty_out(vty, "\n");
6417 } else {
6418 json_object_int_add(json, "networkMask",
6419 ip_masklen(sl->mask));
6420 json_object_int_add(json, "tos0Metric",
6421 GET_METRIC(sl->metric));
6422 }
6423 }
6424
6425 return 0;
6426 }
6427
6428 /* Show summary-ASBR-LSA detail information. */
6429 static int show_summary_asbr_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
6430 json_object *json)
6431 {
6432 if (lsa != NULL) {
6433 struct summary_lsa *sl = (struct summary_lsa *)lsa->data;
6434
6435 show_ip_ospf_database_header(vty, lsa, json);
6436
6437 if (!json) {
6438 vty_out(vty, " Network Mask: /%d\n",
6439 ip_masklen(sl->mask));
6440 vty_out(vty, " TOS: 0 Metric: %d\n",
6441 GET_METRIC(sl->metric));
6442 vty_out(vty, "\n");
6443 } else {
6444 json_object_int_add(json, "networkMask",
6445 ip_masklen(sl->mask));
6446 json_object_int_add(json, "tos0Metric",
6447 GET_METRIC(sl->metric));
6448 }
6449 }
6450
6451 return 0;
6452 }
6453
6454 /* Show AS-external-LSA detail information. */
6455 static int show_as_external_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
6456 json_object *json)
6457 {
6458 int tos = 0;
6459
6460 if (lsa != NULL) {
6461 struct as_external_lsa *al =
6462 (struct as_external_lsa *)lsa->data;
6463
6464 show_ip_ospf_database_header(vty, lsa, json);
6465
6466 if (!json) {
6467 vty_out(vty, " Network Mask: /%d\n",
6468 ip_masklen(al->mask));
6469 vty_out(vty, " Metric Type: %s\n",
6470 IS_EXTERNAL_METRIC(al->e[0].tos)
6471 ? "2 (Larger than any link state path)"
6472 : "1");
6473 vty_out(vty, " TOS: 0\n");
6474 vty_out(vty, " Metric: %d\n",
6475 GET_METRIC(al->e[0].metric));
6476 vty_out(vty, " Forward Address: %pI4\n",
6477 &al->e[0].fwd_addr);
6478 vty_out(vty,
6479 " External Route Tag: %" ROUTE_TAG_PRI "\n\n",
6480 (route_tag_t)ntohl(al->e[0].route_tag));
6481 } else {
6482 json_object_int_add(json, "networkMask",
6483 ip_masklen(al->mask));
6484 json_object_string_add(
6485 json, "metricType",
6486 IS_EXTERNAL_METRIC(al->e[0].tos)
6487 ? "E2 (Larger than any link state path)"
6488 : "E1");
6489 json_object_int_add(json, "tos", tos);
6490 json_object_int_add(json, "metric",
6491 GET_METRIC(al->e[0].metric));
6492 json_object_string_addf(json, "forwardAddress", "%pI4",
6493 &(al->e[0].fwd_addr));
6494 json_object_int_add(
6495 json, "externalRouteTag",
6496 (route_tag_t)ntohl(al->e[0].route_tag));
6497 }
6498 }
6499
6500 return 0;
6501 }
6502
6503 /* Show AS-NSSA-LSA detail information. */
6504 static int show_as_nssa_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
6505 json_object *json)
6506 {
6507 int tos = 0;
6508
6509 if (lsa != NULL) {
6510 struct as_external_lsa *al =
6511 (struct as_external_lsa *)lsa->data;
6512
6513 show_ip_ospf_database_header(vty, lsa, json);
6514
6515 if (!json) {
6516 vty_out(vty, " Network Mask: /%d\n",
6517 ip_masklen(al->mask));
6518 vty_out(vty, " Metric Type: %s\n",
6519 IS_EXTERNAL_METRIC(al->e[0].tos)
6520 ? "2 (Larger than any link state path)"
6521 : "1");
6522 vty_out(vty, " TOS: 0\n");
6523 vty_out(vty, " Metric: %d\n",
6524 GET_METRIC(al->e[0].metric));
6525 vty_out(vty, " NSSA: Forward Address: %pI4\n",
6526 &al->e[0].fwd_addr);
6527 vty_out(vty,
6528 " External Route Tag: %" ROUTE_TAG_PRI
6529 "\n\n",
6530 (route_tag_t)ntohl(al->e[0].route_tag));
6531 } else {
6532 json_object_int_add(json, "networkMask",
6533 ip_masklen(al->mask));
6534 json_object_string_add(
6535 json, "metricType",
6536 IS_EXTERNAL_METRIC(al->e[0].tos)
6537 ? "E2 (Larger than any link state path)"
6538 : "E1");
6539 json_object_int_add(json, "tos", tos);
6540 json_object_int_add(json, "metric",
6541 GET_METRIC(al->e[0].metric));
6542 json_object_string_addf(json, "nssaForwardAddress",
6543 "%pI4", &al->e[0].fwd_addr);
6544 json_object_int_add(
6545 json, "externalRouteTag",
6546 (route_tag_t)ntohl(al->e[0].route_tag));
6547 }
6548 }
6549
6550 return 0;
6551 }
6552
6553 static int show_func_dummy(struct vty *vty, struct ospf_lsa *lsa,
6554 json_object *json)
6555 {
6556 return 0;
6557 }
6558
6559 static int show_opaque_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
6560 json_object *json)
6561 {
6562 if (lsa != NULL) {
6563 show_ip_ospf_database_header(vty, lsa, json);
6564 show_opaque_info_detail(vty, lsa, json);
6565 if (!json)
6566 vty_out(vty, "\n");
6567 }
6568 return 0;
6569 }
6570
6571 int (*show_function[])(struct vty *, struct ospf_lsa *, json_object *) = {
6572 NULL,
6573 show_router_lsa_detail,
6574 show_network_lsa_detail,
6575 show_summary_lsa_detail,
6576 show_summary_asbr_lsa_detail,
6577 show_as_external_lsa_detail,
6578 show_func_dummy,
6579 show_as_nssa_lsa_detail, /* almost same as external */
6580 NULL, /* type-8 */
6581 show_opaque_lsa_detail,
6582 show_opaque_lsa_detail,
6583 show_opaque_lsa_detail,
6584 };
6585
6586 static void show_lsa_prefix_set(struct vty *vty, struct prefix_ls *lp,
6587 struct in_addr *id, struct in_addr *adv_router)
6588 {
6589 memset(lp, 0, sizeof(struct prefix_ls));
6590 lp->family = AF_UNSPEC;
6591 if (id == NULL)
6592 lp->prefixlen = 0;
6593 else if (adv_router == NULL) {
6594 lp->prefixlen = IPV4_MAX_BITLEN;
6595 lp->id = *id;
6596 } else {
6597 lp->prefixlen = 64;
6598 lp->id = *id;
6599 lp->adv_router = *adv_router;
6600 }
6601 }
6602
6603 static void show_lsa_detail_proc(struct vty *vty, struct route_table *rt,
6604 struct in_addr *id, struct in_addr *adv_router,
6605 json_object *json)
6606 {
6607 struct prefix_ls lp;
6608 struct route_node *rn, *start;
6609 struct ospf_lsa *lsa;
6610 json_object *json_lsa = NULL;
6611
6612 show_lsa_prefix_set(vty, &lp, id, adv_router);
6613 start = route_node_get(rt, (struct prefix *)&lp);
6614 if (start) {
6615 route_lock_node(start);
6616 for (rn = start; rn; rn = route_next_until(rn, start))
6617 if ((lsa = rn->info)) {
6618 if (json) {
6619 json_lsa = json_object_new_object();
6620 json_object_array_add(json, json_lsa);
6621 }
6622
6623 if (show_function[lsa->data->type] != NULL)
6624 show_function[lsa->data->type](
6625 vty, lsa, json_lsa);
6626 }
6627 route_unlock_node(start);
6628 }
6629 }
6630
6631 /* Show detail LSA information
6632 -- if id is NULL then show all LSAs. */
6633 static void show_lsa_detail(struct vty *vty, struct ospf *ospf, int type,
6634 struct in_addr *id, struct in_addr *adv_router,
6635 json_object *json)
6636 {
6637 struct listnode *node;
6638 struct ospf_area *area;
6639 char buf[PREFIX_STRLEN];
6640 json_object *json_lsa_type = NULL;
6641 json_object *json_areas = NULL;
6642 json_object *json_lsa_array = NULL;
6643
6644 if (json)
6645 json_lsa_type = json_object_new_object();
6646
6647 switch (type) {
6648 case OSPF_AS_EXTERNAL_LSA:
6649 case OSPF_OPAQUE_AS_LSA:
6650 if (!json)
6651 vty_out(vty, " %s \n\n",
6652 show_database_desc[type]);
6653 else
6654 json_lsa_array = json_object_new_array();
6655
6656 show_lsa_detail_proc(vty, AS_LSDB(ospf, type), id, adv_router,
6657 json_lsa_array);
6658 if (json)
6659 json_object_object_add(json,
6660 show_database_desc_json[type],
6661 json_lsa_array);
6662
6663 break;
6664 default:
6665 if (json)
6666 json_areas = json_object_new_object();
6667
6668 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
6669 if (!json) {
6670 vty_out(vty,
6671 "\n %s (Area %s)\n\n",
6672 show_database_desc[type],
6673 ospf_area_desc_string(area));
6674 } else {
6675 json_lsa_array = json_object_new_array();
6676 json_object_object_add(json_areas,
6677 inet_ntop(AF_INET,
6678 &area->area_id,
6679 buf,
6680 sizeof(buf)),
6681 json_lsa_array);
6682 }
6683
6684 show_lsa_detail_proc(vty, AREA_LSDB(area, type), id,
6685 adv_router, json_lsa_array);
6686 }
6687
6688 if (json) {
6689 json_object_object_add(json_lsa_type, "areas",
6690 json_areas);
6691 json_object_object_add(json,
6692 show_database_desc_json[type],
6693 json_lsa_type);
6694 }
6695 break;
6696 }
6697 }
6698
6699 static void show_lsa_detail_adv_router_proc(struct vty *vty,
6700 struct route_table *rt,
6701 struct in_addr *adv_router,
6702 json_object *json)
6703 {
6704 char buf[PREFIX_STRLEN];
6705 struct route_node *rn;
6706 struct ospf_lsa *lsa;
6707
6708 for (rn = route_top(rt); rn; rn = route_next(rn))
6709 if ((lsa = rn->info)) {
6710 json_object *json_lsa = NULL;
6711
6712 if (IPV4_ADDR_SAME(adv_router,
6713 &lsa->data->adv_router)) {
6714 if (CHECK_FLAG(lsa->flags, OSPF_LSA_LOCAL_XLT))
6715 continue;
6716 if (json)
6717 json_lsa = json_object_new_object();
6718
6719 if (show_function[lsa->data->type] != NULL)
6720 show_function[lsa->data->type](
6721 vty, lsa, json_lsa);
6722 if (json)
6723 json_object_object_add(
6724 json,
6725 inet_ntop(AF_INET,
6726 &lsa->data->id,
6727 buf, sizeof(buf)),
6728 json_lsa);
6729 }
6730 }
6731 }
6732
6733 /* Show detail LSA information. */
6734 static void show_lsa_detail_adv_router(struct vty *vty, struct ospf *ospf,
6735 int type, struct in_addr *adv_router,
6736 json_object *json)
6737 {
6738 struct listnode *node;
6739 struct ospf_area *area;
6740 char buf[PREFIX_STRLEN];
6741 json_object *json_lstype = NULL;
6742 json_object *json_area = NULL;
6743
6744 if (json)
6745 json_lstype = json_object_new_object();
6746
6747 switch (type) {
6748 case OSPF_AS_EXTERNAL_LSA:
6749 case OSPF_OPAQUE_AS_LSA:
6750 if (!json)
6751 vty_out(vty, " %s \n\n",
6752 show_database_desc[type]);
6753
6754 show_lsa_detail_adv_router_proc(vty, AS_LSDB(ospf, type),
6755 adv_router, json_lstype);
6756 break;
6757 default:
6758
6759 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
6760 if (json)
6761 json_area = json_object_new_object();
6762 else
6763 vty_out(vty,
6764 "\n %s (Area %s)\n\n",
6765 show_database_desc[type],
6766 ospf_area_desc_string(area));
6767 show_lsa_detail_adv_router_proc(vty,
6768 AREA_LSDB(area, type),
6769 adv_router, json_area);
6770
6771 if (json)
6772 json_object_object_add(json_lstype,
6773 inet_ntop(AF_INET,
6774 &area->area_id,
6775 buf,
6776 sizeof(buf)),
6777 json_area);
6778 }
6779 break;
6780 }
6781
6782 if (json)
6783 json_object_object_add(json, show_database_desc[type],
6784 json_lstype);
6785 }
6786
6787 void show_ip_ospf_database_summary(struct vty *vty, struct ospf *ospf, int self,
6788 json_object *json)
6789 {
6790 struct ospf_lsa *lsa;
6791 struct route_node *rn;
6792 struct ospf_area *area;
6793 struct listnode *node;
6794 char buf[PREFIX_STRLEN];
6795 json_object *json_areas = NULL;
6796 json_object *json_area = NULL;
6797 json_object *json_lsa = NULL;
6798 int type;
6799 json_object *json_lsa_array = NULL;
6800 uint32_t count;
6801
6802 if (json)
6803 json_areas = json_object_new_object();
6804
6805 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
6806 if (json)
6807 json_area = json_object_new_object();
6808
6809 for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) {
6810 count = 0;
6811 switch (type) {
6812 case OSPF_AS_EXTERNAL_LSA:
6813 case OSPF_OPAQUE_AS_LSA:
6814 continue;
6815 default:
6816 break;
6817 }
6818 if (ospf_lsdb_count_self(area->lsdb, type) > 0
6819 || (!self
6820 && ospf_lsdb_count(area->lsdb, type) > 0)) {
6821
6822 if (!json) {
6823 vty_out(vty,
6824 " %s (Area %s)\n\n",
6825 show_database_desc[type],
6826 ospf_area_desc_string(area));
6827 vty_out(vty, "%s\n",
6828 show_database_header[type]);
6829 } else {
6830 json_lsa_array =
6831 json_object_new_array();
6832 json_object_object_add(
6833 json_area,
6834 show_database_desc_json[type],
6835 json_lsa_array);
6836 }
6837
6838 LSDB_LOOP (AREA_LSDB(area, type), rn, lsa) {
6839 if (json) {
6840 json_lsa =
6841 json_object_new_object();
6842 json_object_array_add(
6843 json_lsa_array,
6844 json_lsa);
6845 }
6846
6847 count += show_lsa_summary(
6848 vty, lsa, self, json_lsa);
6849 }
6850
6851 if (!json)
6852 vty_out(vty, "\n");
6853 else
6854 json_object_int_add(
6855 json_area,
6856
6857 show_database_desc_count_json
6858 [type],
6859 count);
6860 }
6861 }
6862 if (json)
6863 json_object_object_add(json_areas,
6864 inet_ntop(AF_INET,
6865 &area->area_id,
6866 buf, sizeof(buf)),
6867 json_area);
6868 }
6869
6870 if (json)
6871 json_object_object_add(json, "areas", json_areas);
6872
6873 for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) {
6874 count = 0;
6875 switch (type) {
6876 case OSPF_AS_EXTERNAL_LSA:
6877 case OSPF_OPAQUE_AS_LSA:
6878 break;
6879 default:
6880 continue;
6881 }
6882 if (ospf_lsdb_count_self(ospf->lsdb, type)
6883 || (!self && ospf_lsdb_count(ospf->lsdb, type))) {
6884 if (!json) {
6885 vty_out(vty, " %s\n\n",
6886 show_database_desc[type]);
6887 vty_out(vty, "%s\n",
6888 show_database_header[type]);
6889 } else {
6890 json_lsa_array = json_object_new_array();
6891 json_object_object_add(
6892 json, show_database_desc_json[type],
6893 json_lsa_array);
6894 }
6895
6896 LSDB_LOOP (AS_LSDB(ospf, type), rn, lsa) {
6897 if (json) {
6898 json_lsa = json_object_new_object();
6899 json_object_array_add(json_lsa_array,
6900 json_lsa);
6901 }
6902
6903 count += show_lsa_summary(vty, lsa, self,
6904 json_lsa);
6905 }
6906
6907 if (!json)
6908 vty_out(vty, "\n");
6909 else
6910 json_object_int_add(
6911 json,
6912 show_database_desc_count_json[type],
6913 count);
6914 }
6915 }
6916
6917 if (!json)
6918 vty_out(vty, "\n");
6919 }
6920
6921 static void show_ip_ospf_database_maxage(struct vty *vty, struct ospf *ospf,
6922 json_object *json)
6923 {
6924 struct route_node *rn;
6925 char buf[PREFIX_STRLEN];
6926 json_object *json_maxage = NULL;
6927
6928 if (!json)
6929 vty_out(vty, "\n MaxAge Link States:\n\n");
6930 else
6931 json_maxage = json_object_new_object();
6932
6933 for (rn = route_top(ospf->maxage_lsa); rn; rn = route_next(rn)) {
6934 struct ospf_lsa *lsa;
6935 json_object *json_lsa = NULL;
6936
6937 if ((lsa = rn->info) != NULL) {
6938 if (!json) {
6939 vty_out(vty, "Link type: %d\n",
6940 lsa->data->type);
6941 vty_out(vty, "Link State ID: %pI4\n",
6942 &lsa->data->id);
6943 vty_out(vty, "Advertising Router: %pI4\n",
6944 &lsa->data->adv_router);
6945 vty_out(vty, "LSA lock count: %d\n", lsa->lock);
6946 vty_out(vty, "\n");
6947 } else {
6948 json_lsa = json_object_new_object();
6949 json_object_int_add(json_lsa, "linkType",
6950 lsa->data->type);
6951 json_object_string_addf(json_lsa, "linkStateId",
6952 "%pI4", &lsa->data->id);
6953 json_object_string_addf(
6954 json_lsa, "advertisingRouter", "%pI4",
6955 &lsa->data->adv_router);
6956 json_object_int_add(json_lsa, "lsaLockCount",
6957 lsa->lock);
6958 json_object_object_add(
6959 json_maxage,
6960 inet_ntop(AF_INET,
6961 &lsa->data->id,
6962 buf, sizeof(buf)),
6963 json_lsa);
6964 }
6965 }
6966 }
6967 if (json)
6968 json_object_object_add(json, "maxAgeLinkStates", json_maxage);
6969 }
6970
6971 #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
6972 #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
6973
6974 #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
6975 #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
6976 #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
6977 #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
6978
6979 #define OSPF_LSA_TYPES_DESC \
6980 "ASBR summary link states\n" \
6981 "External link states\n" \
6982 "Network link states\n" \
6983 "Router link states\n" \
6984 "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \
6985 OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
6986 OSPF_LSA_TYPE_OPAQUE_AS_DESC
6987
6988 static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf,
6989 int arg_base, int argc,
6990 struct cmd_token **argv,
6991 uint8_t use_vrf, json_object *json,
6992 bool uj)
6993 {
6994 int idx_type = 4;
6995 int type, ret;
6996 struct in_addr id, adv_router;
6997 json_object *json_vrf = NULL;
6998
6999 if (uj) {
7000 if (use_vrf)
7001 json_vrf = json_object_new_object();
7002 else
7003 json_vrf = json;
7004 }
7005
7006 if (ospf->instance) {
7007 if (uj)
7008 json_object_int_add(json_vrf, "ospfInstance",
7009 ospf->instance);
7010 else
7011 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
7012 }
7013
7014 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
7015
7016 /* Show Router ID. */
7017 if (uj) {
7018 json_object_string_addf(json_vrf, "routerId", "%pI4",
7019 &ospf->router_id);
7020 } else {
7021 vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n",
7022 &ospf->router_id);
7023 }
7024
7025 /* Show all LSA. */
7026 if ((argc == arg_base + 4) || (uj && (argc == arg_base + 5))) {
7027 show_ip_ospf_database_summary(vty, ospf, 0, json_vrf);
7028 if (json) {
7029 if (use_vrf)
7030 json_object_object_add(
7031 json, ospf_get_name(ospf), json_vrf);
7032 }
7033 return CMD_SUCCESS;
7034 }
7035
7036 /* Set database type to show. */
7037 if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0)
7038 type = OSPF_ROUTER_LSA;
7039 else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0)
7040 type = OSPF_NETWORK_LSA;
7041 else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0)
7042 type = OSPF_AS_NSSA_LSA;
7043 else if (strncmp(argv[arg_base + idx_type]->text, "su", 2) == 0)
7044 type = OSPF_SUMMARY_LSA;
7045 else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0)
7046 type = OSPF_ASBR_SUMMARY_LSA;
7047 else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0)
7048 type = OSPF_AS_EXTERNAL_LSA;
7049 else if (strncmp(argv[arg_base + idx_type]->text, "se", 2) == 0) {
7050 show_ip_ospf_database_summary(vty, ospf, 1, json_vrf);
7051 if (json) {
7052 if (use_vrf)
7053 json_object_object_add(
7054 json, ospf_get_name(ospf), json_vrf);
7055 }
7056 return CMD_SUCCESS;
7057 } else if (strncmp(argv[arg_base + idx_type]->text, "m", 1) == 0) {
7058 show_ip_ospf_database_maxage(vty, ospf, json_vrf);
7059 if (json) {
7060 if (use_vrf)
7061 json_object_object_add(
7062 json, ospf_get_name(ospf), json_vrf);
7063 }
7064 return CMD_SUCCESS;
7065 } else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0)
7066 type = OSPF_OPAQUE_LINK_LSA;
7067 else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0)
7068 type = OSPF_OPAQUE_AREA_LSA;
7069 else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0)
7070 type = OSPF_OPAQUE_AS_LSA;
7071 else
7072 return CMD_WARNING;
7073
7074 /* `show ip ospf database LSA'. */
7075 if ((argc == arg_base + 5) || (uj && (argc == arg_base + 6)))
7076 show_lsa_detail(vty, ospf, type, NULL, NULL, json_vrf);
7077 else if (argc >= arg_base + 6) {
7078 ret = inet_aton(argv[arg_base + 5]->arg, &id);
7079 if (!ret)
7080 return CMD_WARNING;
7081
7082 /* `show ip ospf database LSA ID'. */
7083 if ((argc == arg_base + 6) || (uj && (argc == arg_base + 7)))
7084 show_lsa_detail(vty, ospf, type, &id, NULL, json_vrf);
7085 /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */
7086 else if ((argc == arg_base + 7)
7087 || (uj && (argc == arg_base + 8))) {
7088 if (strncmp(argv[arg_base + 6]->text, "s", 1) == 0)
7089 adv_router = ospf->router_id;
7090 else {
7091 ret = inet_aton(argv[arg_base + 7]->arg,
7092 &adv_router);
7093 if (!ret)
7094 return CMD_WARNING;
7095 }
7096 show_lsa_detail(vty, ospf, type, &id, &adv_router,
7097 json_vrf);
7098 }
7099 }
7100
7101 if (json) {
7102 if (use_vrf)
7103 json_object_object_add(json, ospf_get_name(ospf),
7104 json_vrf);
7105 }
7106
7107 return CMD_SUCCESS;
7108 }
7109
7110 DEFUN (show_ip_ospf_database_max,
7111 show_ip_ospf_database_max_cmd,
7112 "show ip ospf [vrf <NAME|all>] database <max-age|self-originate> [json]",
7113 SHOW_STR
7114 IP_STR
7115 "OSPF information\n"
7116 VRF_CMD_HELP_STR
7117 "All VRFs\n"
7118 "Database summary\n"
7119 "LSAs in MaxAge list\n"
7120 "Self-originated link states\n"
7121 JSON_STR)
7122 {
7123 struct ospf *ospf = NULL;
7124 struct listnode *node = NULL;
7125 char *vrf_name = NULL;
7126 bool all_vrf = false;
7127 int ret = CMD_SUCCESS;
7128 int inst = 0;
7129 int idx_vrf = 0;
7130 uint8_t use_vrf = 0;
7131 bool uj = use_json(argc, argv);
7132 json_object *json = NULL;
7133
7134 if (uj)
7135 json = json_object_new_object();
7136
7137 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
7138
7139 if (vrf_name) {
7140 bool ospf_output = false;
7141
7142 use_vrf = 1;
7143
7144 if (all_vrf) {
7145 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
7146 if (!ospf->oi_running)
7147 continue;
7148 ospf_output = true;
7149 ret = show_ip_ospf_database_common(
7150 vty, ospf, idx_vrf ? 2 : 0, argc, argv,
7151 use_vrf, json, uj);
7152 }
7153
7154 if (!ospf_output)
7155 vty_out(vty, "%% OSPF is not enabled\n");
7156 } else {
7157 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
7158 if (ospf == NULL || !ospf->oi_running) {
7159 vty_out(vty,
7160 "%% OSPF is not enabled in vrf %s\n",
7161 vrf_name);
7162 return CMD_SUCCESS;
7163 }
7164 ret = (show_ip_ospf_database_common(
7165 vty, ospf, idx_vrf ? 2 : 0, argc, argv, use_vrf,
7166 json, uj));
7167 }
7168 } else {
7169 /* Display default ospf (instance 0) info */
7170 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
7171 if (ospf == NULL || !ospf->oi_running) {
7172 vty_out(vty, "%% OSPF is not enabled in vrf default\n");
7173 return CMD_SUCCESS;
7174 }
7175
7176 ret = show_ip_ospf_database_common(vty, ospf, 0, argc, argv,
7177 use_vrf, json, uj);
7178 }
7179
7180 if (uj) {
7181 vty_out(vty, "%s\n", json_object_to_json_string(json));
7182 json_object_free(json);
7183 }
7184
7185 return ret;
7186 }
7187
7188 ALIAS (show_ip_ospf_database_max,
7189 show_ip_ospf_database_cmd,
7190 "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]",
7191 SHOW_STR
7192 IP_STR
7193 "OSPF information\n"
7194 VRF_CMD_HELP_STR
7195 "All VRFs\n"
7196 "Database summary\n"
7197 OSPF_LSA_TYPES_DESC
7198 "Link State ID (as an IP address)\n"
7199 "Self-originated link states\n"
7200 "Advertising Router link states\n"
7201 "Advertising Router (as an IP address)\n"
7202 JSON_STR)
7203
7204 DEFUN (show_ip_ospf_instance_database_max,
7205 show_ip_ospf_instance_database_max_cmd,
7206 "show ip ospf (1-65535) database <max-age|self-originate> [json]",
7207 SHOW_STR
7208 IP_STR
7209 "OSPF information\n"
7210 "Instance ID\n"
7211 "Database summary\n"
7212 "LSAs in MaxAge list\n"
7213 "Self-originated link states\n"
7214 JSON_STR)
7215 {
7216 int idx_number = 3;
7217 struct ospf *ospf;
7218 unsigned short instance = 0;
7219 bool uj = use_json(argc, argv);
7220 json_object *json = NULL;
7221
7222 if (uj)
7223 json = json_object_new_object();
7224
7225 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7226 if (instance != ospf_instance)
7227 return CMD_NOT_MY_INSTANCE;
7228
7229 ospf = ospf_lookup_instance(instance);
7230 if (!ospf || !ospf->oi_running)
7231 return CMD_SUCCESS;
7232
7233 show_ip_ospf_database_common(vty, ospf, 1, argc, argv, 0, json, uj);
7234
7235 if (uj)
7236 vty_json(vty, json);
7237
7238 return CMD_SUCCESS;
7239 }
7240
7241 ALIAS (show_ip_ospf_instance_database_max,
7242 show_ip_ospf_instance_database_cmd,
7243 "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]",
7244 SHOW_STR
7245 IP_STR
7246 "OSPF information\n"
7247 "Instance ID\n"
7248 "Database summary\n"
7249 OSPF_LSA_TYPES_DESC
7250 "Link State ID (as an IP address)\n"
7251 "Self-originated link states\n"
7252 "Advertising Router link states\n"
7253 "Advertising Router (as an IP address)\n"
7254 JSON_STR)
7255
7256 static int show_ip_ospf_database_type_adv_router_common(struct vty *vty,
7257 struct ospf *ospf,
7258 int arg_base, int argc,
7259 struct cmd_token **argv,
7260 uint8_t use_vrf,
7261 json_object *json,
7262 bool uj)
7263 {
7264 int idx_type = 4;
7265 int type, ret;
7266 struct in_addr adv_router;
7267 json_object *json_vrf = NULL;
7268
7269 if (uj) {
7270 if (use_vrf)
7271 json_vrf = json_object_new_object();
7272 else
7273 json_vrf = json;
7274 }
7275
7276 if (ospf->instance) {
7277 if (uj)
7278 json_object_int_add(json, "ospfInstance",
7279 ospf->instance);
7280 else
7281 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
7282 }
7283
7284 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
7285
7286 /* Show Router ID. */
7287 if (uj) {
7288 json_object_string_addf(json_vrf, "routerId", "%pI4",
7289 &ospf->router_id);
7290 } else {
7291 vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n",
7292 &ospf->router_id);
7293 }
7294
7295 /* Set database type to show. */
7296 if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0)
7297 type = OSPF_ROUTER_LSA;
7298 else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0)
7299 type = OSPF_NETWORK_LSA;
7300 else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0)
7301 type = OSPF_AS_NSSA_LSA;
7302 else if (strncmp(argv[arg_base + idx_type]->text, "s", 1) == 0)
7303 type = OSPF_SUMMARY_LSA;
7304 else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0)
7305 type = OSPF_ASBR_SUMMARY_LSA;
7306 else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0)
7307 type = OSPF_AS_EXTERNAL_LSA;
7308 else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0)
7309 type = OSPF_OPAQUE_LINK_LSA;
7310 else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0)
7311 type = OSPF_OPAQUE_AREA_LSA;
7312 else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0)
7313 type = OSPF_OPAQUE_AS_LSA;
7314 else
7315 return CMD_WARNING;
7316
7317 /* `show ip ospf database LSA adv-router ADV_ROUTER'. */
7318 if (strncmp(argv[arg_base + 5]->text, "s", 1) == 0)
7319 adv_router = ospf->router_id;
7320 else {
7321 ret = inet_aton(argv[arg_base + 6]->arg, &adv_router);
7322 if (!ret)
7323 return CMD_WARNING;
7324 }
7325
7326 show_lsa_detail_adv_router(vty, ospf, type, &adv_router, json_vrf);
7327
7328 if (json) {
7329 if (use_vrf)
7330 json_object_object_add(json, ospf_get_name(ospf),
7331 json_vrf);
7332 }
7333
7334 return CMD_SUCCESS;
7335 }
7336
7337 DEFUN (show_ip_ospf_database_type_adv_router,
7338 show_ip_ospf_database_type_adv_router_cmd,
7339 "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]",
7340 SHOW_STR
7341 IP_STR
7342 "OSPF information\n"
7343 VRF_CMD_HELP_STR
7344 "All VRFs\n"
7345 "Database summary\n"
7346 OSPF_LSA_TYPES_DESC
7347 "Advertising Router link states\n"
7348 "Advertising Router (as an IP address)\n"
7349 "Self-originated link states\n"
7350 JSON_STR)
7351 {
7352 struct ospf *ospf = NULL;
7353 struct listnode *node = NULL;
7354 char *vrf_name = NULL;
7355 bool all_vrf = false;
7356 int ret = CMD_SUCCESS;
7357 int inst = 0;
7358 int idx_vrf = 0;
7359 uint8_t use_vrf = 0;
7360 bool uj = use_json(argc, argv);
7361 json_object *json = NULL;
7362
7363 if (uj)
7364 json = json_object_new_object();
7365
7366 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
7367
7368 if (vrf_name) {
7369 bool ospf_output = false;
7370
7371 use_vrf = 1;
7372
7373 if (all_vrf) {
7374 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
7375 if (!ospf->oi_running)
7376 continue;
7377 ospf_output = true;
7378 ret = show_ip_ospf_database_type_adv_router_common(
7379 vty, ospf, 2, argc, argv, use_vrf, json,
7380 uj);
7381 }
7382 if (!ospf_output)
7383 vty_out(vty, "%% OSPF is not enabled\n");
7384 } else {
7385 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
7386 if ((ospf == NULL) || !ospf->oi_running) {
7387 vty_out(vty,
7388 "%% OSPF is not enabled in vrf %s\n",
7389 vrf_name);
7390 return CMD_SUCCESS;
7391 }
7392
7393 ret = show_ip_ospf_database_type_adv_router_common(
7394 vty, ospf, 2, argc, argv, use_vrf, json, uj);
7395 }
7396 } else {
7397 /* Display default ospf (instance 0) info */
7398 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
7399 if (ospf == NULL || !ospf->oi_running) {
7400 vty_out(vty, "%% OSPF is not enabled on vrf default\n");
7401 return CMD_SUCCESS;
7402 }
7403
7404 ret = show_ip_ospf_database_type_adv_router_common(
7405 vty, ospf, 0, argc, argv, use_vrf, json, uj);
7406 }
7407
7408 if (uj) {
7409 vty_out(vty, "%s\n", json_object_to_json_string(json));
7410 json_object_free(json);
7411 }
7412
7413 return ret;
7414 }
7415
7416 DEFUN (show_ip_ospf_instance_database_type_adv_router,
7417 show_ip_ospf_instance_database_type_adv_router_cmd,
7418 "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]",
7419 SHOW_STR
7420 IP_STR
7421 "OSPF information\n"
7422 "Instance ID\n"
7423 "Database summary\n"
7424 OSPF_LSA_TYPES_DESC
7425 "Advertising Router link states\n"
7426 "Advertising Router (as an IP address)\n"
7427 "Self-originated link states\n"
7428 JSON_STR)
7429 {
7430 int idx_number = 3;
7431 struct ospf *ospf;
7432 unsigned short instance = 0;
7433 bool uj = use_json(argc, argv);
7434 json_object *json = NULL;
7435
7436 if (uj)
7437 json = json_object_new_object();
7438
7439 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7440 if (instance != ospf_instance)
7441 return CMD_NOT_MY_INSTANCE;
7442
7443 ospf = ospf_lookup_instance(instance);
7444 if (!ospf || !ospf->oi_running)
7445 return CMD_SUCCESS;
7446
7447 show_ip_ospf_database_type_adv_router_common(vty, ospf, 1, argc, argv,
7448 0, json, uj);
7449
7450 if (uj)
7451 vty_json(vty, json);
7452
7453 return CMD_SUCCESS;
7454 }
7455
7456 DEFUN (ip_ospf_authentication_args,
7457 ip_ospf_authentication_args_addr_cmd,
7458 "ip ospf authentication <null|message-digest> [A.B.C.D]",
7459 "IP Information\n"
7460 "OSPF interface commands\n"
7461 "Enable authentication on this interface\n"
7462 "Use null authentication\n"
7463 "Use message-digest authentication\n"
7464 "Address of interface\n")
7465 {
7466 VTY_DECLVAR_CONTEXT(interface, ifp);
7467 int idx_encryption = 3;
7468 int idx_ipv4 = 4;
7469 struct in_addr addr;
7470 int ret;
7471 struct ospf_if_params *params;
7472
7473 params = IF_DEF_PARAMS(ifp);
7474
7475 if (argc == 5) {
7476 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7477 if (!ret) {
7478 vty_out(vty,
7479 "Please specify interface address by A.B.C.D\n");
7480 return CMD_WARNING_CONFIG_FAILED;
7481 }
7482
7483 params = ospf_get_if_params(ifp, addr);
7484 ospf_if_update_params(ifp, addr);
7485 }
7486
7487 /* Handle null authentication */
7488 if (argv[idx_encryption]->arg[0] == 'n') {
7489 SET_IF_PARAM(params, auth_type);
7490 params->auth_type = OSPF_AUTH_NULL;
7491 return CMD_SUCCESS;
7492 }
7493
7494 /* Handle message-digest authentication */
7495 if (argv[idx_encryption]->arg[0] == 'm') {
7496 SET_IF_PARAM(params, auth_type);
7497 params->auth_type = OSPF_AUTH_CRYPTOGRAPHIC;
7498 return CMD_SUCCESS;
7499 }
7500
7501 vty_out(vty, "You shouldn't get here!\n");
7502 return CMD_WARNING_CONFIG_FAILED;
7503 }
7504
7505 DEFUN (ip_ospf_authentication,
7506 ip_ospf_authentication_addr_cmd,
7507 "ip ospf authentication [A.B.C.D]",
7508 "IP Information\n"
7509 "OSPF interface commands\n"
7510 "Enable authentication on this interface\n"
7511 "Address of interface\n")
7512 {
7513 VTY_DECLVAR_CONTEXT(interface, ifp);
7514 int idx_ipv4 = 3;
7515 struct in_addr addr;
7516 int ret;
7517 struct ospf_if_params *params;
7518
7519 params = IF_DEF_PARAMS(ifp);
7520
7521 if (argc == 4) {
7522 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7523 if (!ret) {
7524 vty_out(vty,
7525 "Please specify interface address by A.B.C.D\n");
7526 return CMD_WARNING_CONFIG_FAILED;
7527 }
7528
7529 params = ospf_get_if_params(ifp, addr);
7530 ospf_if_update_params(ifp, addr);
7531 }
7532
7533 SET_IF_PARAM(params, auth_type);
7534 params->auth_type = OSPF_AUTH_SIMPLE;
7535
7536 return CMD_SUCCESS;
7537 }
7538
7539 DEFUN (no_ip_ospf_authentication_args,
7540 no_ip_ospf_authentication_args_addr_cmd,
7541 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
7542 NO_STR
7543 "IP Information\n"
7544 "OSPF interface commands\n"
7545 "Enable authentication on this interface\n"
7546 "Use null authentication\n"
7547 "Use message-digest authentication\n"
7548 "Address of interface\n")
7549 {
7550 VTY_DECLVAR_CONTEXT(interface, ifp);
7551 int idx_encryption = 4;
7552 int idx_ipv4 = 5;
7553 struct in_addr addr;
7554 int ret;
7555 struct ospf_if_params *params;
7556 struct route_node *rn;
7557 int auth_type;
7558
7559 params = IF_DEF_PARAMS(ifp);
7560
7561 if (argc == 6) {
7562 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7563 if (!ret) {
7564 vty_out(vty,
7565 "Please specify interface address by A.B.C.D\n");
7566 return CMD_WARNING_CONFIG_FAILED;
7567 }
7568
7569 params = ospf_lookup_if_params(ifp, addr);
7570 if (params == NULL) {
7571 vty_out(vty, "Ip Address specified is unknown\n");
7572 return CMD_WARNING_CONFIG_FAILED;
7573 }
7574 params->auth_type = OSPF_AUTH_NOTSET;
7575 UNSET_IF_PARAM(params, auth_type);
7576 if (params != IF_DEF_PARAMS(ifp)) {
7577 ospf_free_if_params(ifp, addr);
7578 ospf_if_update_params(ifp, addr);
7579 }
7580 } else {
7581 if (argv[idx_encryption]->arg[0] == 'n') {
7582 auth_type = OSPF_AUTH_NULL;
7583 } else if (argv[idx_encryption]->arg[0] == 'm') {
7584 auth_type = OSPF_AUTH_CRYPTOGRAPHIC;
7585 } else {
7586 vty_out(vty, "Unexpected input encountered\n");
7587 return CMD_WARNING_CONFIG_FAILED;
7588 }
7589 /*
7590 * Here we have a case where the user has entered
7591 * 'no ip ospf authentication (null | message_digest )'
7592 * we need to find if we have any ip addresses underneath it
7593 * that
7594 * correspond to the associated type.
7595 */
7596 if (params->auth_type == auth_type) {
7597 params->auth_type = OSPF_AUTH_NOTSET;
7598 UNSET_IF_PARAM(params, auth_type);
7599 }
7600
7601 for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn;
7602 rn = route_next(rn)) {
7603 if ((params = rn->info)) {
7604 if (params->auth_type == auth_type) {
7605 params->auth_type = OSPF_AUTH_NOTSET;
7606 UNSET_IF_PARAM(params, auth_type);
7607 if (params != IF_DEF_PARAMS(ifp)) {
7608 ospf_free_if_params(
7609 ifp, rn->p.u.prefix4);
7610 ospf_if_update_params(
7611 ifp, rn->p.u.prefix4);
7612 }
7613 }
7614 }
7615 }
7616 }
7617
7618 return CMD_SUCCESS;
7619 }
7620
7621 DEFUN (no_ip_ospf_authentication,
7622 no_ip_ospf_authentication_addr_cmd,
7623 "no ip ospf authentication [A.B.C.D]",
7624 NO_STR
7625 "IP Information\n"
7626 "OSPF interface commands\n"
7627 "Enable authentication on this interface\n"
7628 "Address of interface\n")
7629 {
7630 VTY_DECLVAR_CONTEXT(interface, ifp);
7631 int idx_ipv4 = 4;
7632 struct in_addr addr;
7633 int ret;
7634 struct ospf_if_params *params;
7635 struct route_node *rn;
7636
7637 params = IF_DEF_PARAMS(ifp);
7638
7639 if (argc == 5) {
7640 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7641 if (!ret) {
7642 vty_out(vty,
7643 "Please specify interface address by A.B.C.D\n");
7644 return CMD_WARNING_CONFIG_FAILED;
7645 }
7646
7647 params = ospf_lookup_if_params(ifp, addr);
7648 if (params == NULL) {
7649 vty_out(vty, "Ip Address specified is unknown\n");
7650 return CMD_WARNING_CONFIG_FAILED;
7651 }
7652
7653 params->auth_type = OSPF_AUTH_NOTSET;
7654 UNSET_IF_PARAM(params, auth_type);
7655 if (params != IF_DEF_PARAMS(ifp)) {
7656 ospf_free_if_params(ifp, addr);
7657 ospf_if_update_params(ifp, addr);
7658 }
7659 } else {
7660 /*
7661 * When a user enters 'no ip ospf authentication'
7662 * We should remove all authentication types from
7663 * the interface.
7664 */
7665 if ((params->auth_type == OSPF_AUTH_NULL)
7666 || (params->auth_type == OSPF_AUTH_CRYPTOGRAPHIC)
7667 || (params->auth_type == OSPF_AUTH_SIMPLE)) {
7668 params->auth_type = OSPF_AUTH_NOTSET;
7669 UNSET_IF_PARAM(params, auth_type);
7670 }
7671
7672 for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn;
7673 rn = route_next(rn)) {
7674 if ((params = rn->info)) {
7675
7676 if ((params->auth_type == OSPF_AUTH_NULL)
7677 || (params->auth_type
7678 == OSPF_AUTH_CRYPTOGRAPHIC)
7679 || (params->auth_type
7680 == OSPF_AUTH_SIMPLE)) {
7681 params->auth_type = OSPF_AUTH_NOTSET;
7682 UNSET_IF_PARAM(params, auth_type);
7683 if (params != IF_DEF_PARAMS(ifp)) {
7684 ospf_free_if_params(
7685 ifp, rn->p.u.prefix4);
7686 ospf_if_update_params(
7687 ifp, rn->p.u.prefix4);
7688 }
7689 }
7690 }
7691 }
7692 }
7693
7694 return CMD_SUCCESS;
7695 }
7696
7697
7698 DEFUN (ip_ospf_authentication_key,
7699 ip_ospf_authentication_key_addr_cmd,
7700 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
7701 "IP Information\n"
7702 "OSPF interface commands\n"
7703 "Authentication password (key)\n"
7704 "The OSPF password (key)\n"
7705 "Address of interface\n")
7706 {
7707 VTY_DECLVAR_CONTEXT(interface, ifp);
7708 int idx = 0;
7709 struct in_addr addr;
7710 struct ospf_if_params *params;
7711
7712 params = IF_DEF_PARAMS(ifp);
7713
7714 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7715 if (!inet_aton(argv[idx]->arg, &addr)) {
7716 vty_out(vty,
7717 "Please specify interface address by A.B.C.D\n");
7718 return CMD_WARNING_CONFIG_FAILED;
7719 }
7720
7721 params = ospf_get_if_params(ifp, addr);
7722 ospf_if_update_params(ifp, addr);
7723 }
7724
7725 strlcpy((char *)params->auth_simple, argv[3]->arg,
7726 sizeof(params->auth_simple));
7727 SET_IF_PARAM(params, auth_simple);
7728
7729 return CMD_SUCCESS;
7730 }
7731
7732 DEFUN_HIDDEN (ospf_authentication_key,
7733 ospf_authentication_key_cmd,
7734 "ospf authentication-key AUTH_KEY [A.B.C.D]",
7735 "OSPF interface commands\n"
7736 VLINK_HELPSTR_AUTH_SIMPLE
7737 "Address of interface\n")
7738 {
7739 return ip_ospf_authentication_key(self, vty, argc, argv);
7740 }
7741
7742 DEFUN (no_ip_ospf_authentication_key,
7743 no_ip_ospf_authentication_key_authkey_addr_cmd,
7744 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7745 NO_STR
7746 "IP Information\n"
7747 "OSPF interface commands\n"
7748 VLINK_HELPSTR_AUTH_SIMPLE
7749 "Address of interface\n")
7750 {
7751 VTY_DECLVAR_CONTEXT(interface, ifp);
7752 int idx = 0;
7753 struct in_addr addr;
7754 struct ospf_if_params *params;
7755 params = IF_DEF_PARAMS(ifp);
7756
7757 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7758 if (!inet_aton(argv[idx]->arg, &addr)) {
7759 vty_out(vty,
7760 "Please specify interface address by A.B.C.D\n");
7761 return CMD_WARNING_CONFIG_FAILED;
7762 }
7763
7764 params = ospf_lookup_if_params(ifp, addr);
7765 if (params == NULL)
7766 return CMD_SUCCESS;
7767 }
7768
7769 memset(params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE);
7770 UNSET_IF_PARAM(params, auth_simple);
7771
7772 if (params != IF_DEF_PARAMS(ifp)) {
7773 ospf_free_if_params(ifp, addr);
7774 ospf_if_update_params(ifp, addr);
7775 }
7776
7777 return CMD_SUCCESS;
7778 }
7779
7780 DEFUN_HIDDEN (no_ospf_authentication_key,
7781 no_ospf_authentication_key_authkey_addr_cmd,
7782 "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7783 NO_STR
7784 "OSPF interface commands\n"
7785 VLINK_HELPSTR_AUTH_SIMPLE
7786 "Address of interface\n")
7787 {
7788 return no_ip_ospf_authentication_key(self, vty, argc, argv);
7789 }
7790
7791 DEFUN (ip_ospf_message_digest_key,
7792 ip_ospf_message_digest_key_cmd,
7793 "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7794 "IP Information\n"
7795 "OSPF interface commands\n"
7796 "Message digest authentication password (key)\n"
7797 "Key ID\n"
7798 "Use MD5 algorithm\n"
7799 "The OSPF password (key)\n"
7800 "Address of interface\n")
7801 {
7802 VTY_DECLVAR_CONTEXT(interface, ifp);
7803 struct crypt_key *ck;
7804 uint8_t key_id;
7805 struct in_addr addr;
7806 struct ospf_if_params *params;
7807
7808 params = IF_DEF_PARAMS(ifp);
7809 int idx = 0;
7810
7811 argv_find(argv, argc, "(1-255)", &idx);
7812 char *keyid = argv[idx]->arg;
7813 argv_find(argv, argc, "KEY", &idx);
7814 char *cryptkey = argv[idx]->arg;
7815
7816 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7817 if (!inet_aton(argv[idx]->arg, &addr)) {
7818 vty_out(vty,
7819 "Please specify interface address by A.B.C.D\n");
7820 return CMD_WARNING_CONFIG_FAILED;
7821 }
7822
7823 params = ospf_get_if_params(ifp, addr);
7824 ospf_if_update_params(ifp, addr);
7825 }
7826
7827 key_id = strtol(keyid, NULL, 10);
7828
7829 /* Remove existing key, if any */
7830 ospf_crypt_key_delete(params->auth_crypt, key_id);
7831
7832 ck = ospf_crypt_key_new();
7833 ck->key_id = (uint8_t)key_id;
7834 strlcpy((char *)ck->auth_key, cryptkey, sizeof(ck->auth_key));
7835
7836 ospf_crypt_key_add(params->auth_crypt, ck);
7837 SET_IF_PARAM(params, auth_crypt);
7838
7839 return CMD_SUCCESS;
7840 }
7841
7842 DEFUN_HIDDEN (ospf_message_digest_key,
7843 ospf_message_digest_key_cmd,
7844 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7845 "OSPF interface commands\n"
7846 "Message digest authentication password (key)\n"
7847 "Key ID\n"
7848 "Use MD5 algorithm\n"
7849 "The OSPF password (key)\n"
7850 "Address of interface\n")
7851 {
7852 return ip_ospf_message_digest_key(self, vty, argc, argv);
7853 }
7854
7855 DEFUN (no_ip_ospf_message_digest_key,
7856 no_ip_ospf_message_digest_key_cmd,
7857 "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7858 NO_STR
7859 "IP Information\n"
7860 "OSPF interface commands\n"
7861 "Message digest authentication password (key)\n"
7862 "Key ID\n"
7863 "Use MD5 algorithm\n"
7864 "The OSPF password (key)\n"
7865 "Address of interface\n")
7866 {
7867 VTY_DECLVAR_CONTEXT(interface, ifp);
7868 int idx = 0;
7869 struct crypt_key *ck;
7870 int key_id;
7871 struct in_addr addr;
7872 struct ospf_if_params *params;
7873 params = IF_DEF_PARAMS(ifp);
7874
7875 argv_find(argv, argc, "(1-255)", &idx);
7876 char *keyid = argv[idx]->arg;
7877
7878 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7879 if (!inet_aton(argv[idx]->arg, &addr)) {
7880 vty_out(vty,
7881 "Please specify interface address by A.B.C.D\n");
7882 return CMD_WARNING_CONFIG_FAILED;
7883 }
7884
7885 params = ospf_lookup_if_params(ifp, addr);
7886 if (params == NULL)
7887 return CMD_SUCCESS;
7888 }
7889
7890 key_id = strtol(keyid, NULL, 10);
7891 ck = ospf_crypt_key_lookup(params->auth_crypt, key_id);
7892 if (ck == NULL) {
7893 vty_out(vty, "OSPF: Key %d does not exist\n", key_id);
7894 return CMD_WARNING_CONFIG_FAILED;
7895 }
7896
7897 ospf_crypt_key_delete(params->auth_crypt, key_id);
7898
7899 if (params != IF_DEF_PARAMS(ifp)) {
7900 ospf_free_if_params(ifp, addr);
7901 ospf_if_update_params(ifp, addr);
7902 }
7903
7904 return CMD_SUCCESS;
7905 }
7906
7907 DEFUN_HIDDEN (no_ospf_message_digest_key,
7908 no_ospf_message_digest_key_cmd,
7909 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7910 NO_STR
7911 "OSPF interface commands\n"
7912 "Message digest authentication password (key)\n"
7913 "Key ID\n"
7914 "Use MD5 algorithm\n"
7915 "The OSPF password (key)\n"
7916 "Address of interface\n")
7917 {
7918 return no_ip_ospf_message_digest_key(self, vty, argc, argv);
7919 }
7920
7921 DEFUN (ip_ospf_cost,
7922 ip_ospf_cost_cmd,
7923 "ip ospf cost (1-65535) [A.B.C.D]",
7924 "IP Information\n"
7925 "OSPF interface commands\n"
7926 "Interface cost\n"
7927 "Cost\n"
7928 "Address of interface\n")
7929 {
7930 VTY_DECLVAR_CONTEXT(interface, ifp);
7931 int idx = 0;
7932 uint32_t cost = OSPF_OUTPUT_COST_DEFAULT;
7933 struct in_addr addr;
7934 struct ospf_if_params *params;
7935 params = IF_DEF_PARAMS(ifp);
7936
7937 // get arguments
7938 char *coststr = NULL, *ifaddr = NULL;
7939
7940 argv_find(argv, argc, "(1-65535)", &idx);
7941 coststr = argv[idx]->arg;
7942 cost = strtol(coststr, NULL, 10);
7943
7944 ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
7945 if (ifaddr) {
7946 if (!inet_aton(ifaddr, &addr)) {
7947 vty_out(vty,
7948 "Please specify interface address by A.B.C.D\n");
7949 return CMD_WARNING_CONFIG_FAILED;
7950 }
7951
7952 params = ospf_get_if_params(ifp, addr);
7953 ospf_if_update_params(ifp, addr);
7954 }
7955
7956 SET_IF_PARAM(params, output_cost_cmd);
7957 params->output_cost_cmd = cost;
7958
7959 ospf_if_recalculate_output_cost(ifp);
7960
7961 return CMD_SUCCESS;
7962 }
7963
7964 DEFUN_HIDDEN (ospf_cost,
7965 ospf_cost_cmd,
7966 "ospf cost (1-65535) [A.B.C.D]",
7967 "OSPF interface commands\n"
7968 "Interface cost\n"
7969 "Cost\n"
7970 "Address of interface\n")
7971 {
7972 return ip_ospf_cost(self, vty, argc, argv);
7973 }
7974
7975 DEFUN (no_ip_ospf_cost,
7976 no_ip_ospf_cost_cmd,
7977 "no ip ospf cost [(1-65535)] [A.B.C.D]",
7978 NO_STR
7979 "IP Information\n"
7980 "OSPF interface commands\n"
7981 "Interface cost\n"
7982 "Cost\n"
7983 "Address of interface\n")
7984 {
7985 VTY_DECLVAR_CONTEXT(interface, ifp);
7986 int idx = 0;
7987 struct in_addr addr;
7988 struct ospf_if_params *params;
7989
7990 params = IF_DEF_PARAMS(ifp);
7991
7992 // get arguments
7993 char *ifaddr = NULL;
7994 ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
7995
7996 /* According to the semantics we are mimicking "no ip ospf cost N" is
7997 * always treated as "no ip ospf cost" regardless of the actual value
7998 * of N already configured for the interface. Thus ignore cost. */
7999
8000 if (ifaddr) {
8001 if (!inet_aton(ifaddr, &addr)) {
8002 vty_out(vty,
8003 "Please specify interface address by A.B.C.D\n");
8004 return CMD_WARNING_CONFIG_FAILED;
8005 }
8006
8007 params = ospf_lookup_if_params(ifp, addr);
8008 if (params == NULL)
8009 return CMD_SUCCESS;
8010 }
8011
8012 UNSET_IF_PARAM(params, output_cost_cmd);
8013
8014 if (params != IF_DEF_PARAMS(ifp)) {
8015 ospf_free_if_params(ifp, addr);
8016 ospf_if_update_params(ifp, addr);
8017 }
8018
8019 ospf_if_recalculate_output_cost(ifp);
8020
8021 return CMD_SUCCESS;
8022 }
8023
8024 DEFUN_HIDDEN (no_ospf_cost,
8025 no_ospf_cost_cmd,
8026 "no ospf cost [(1-65535)] [A.B.C.D]",
8027 NO_STR
8028 "OSPF interface commands\n"
8029 "Interface cost\n"
8030 "Cost\n"
8031 "Address of interface\n")
8032 {
8033 return no_ip_ospf_cost(self, vty, argc, argv);
8034 }
8035
8036 static void ospf_nbr_timer_update(struct ospf_interface *oi)
8037 {
8038 struct route_node *rn;
8039 struct ospf_neighbor *nbr;
8040
8041 for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
8042 nbr = rn->info;
8043
8044 if (!nbr)
8045 continue;
8046
8047 nbr->v_inactivity = OSPF_IF_PARAM(oi, v_wait);
8048 nbr->v_db_desc = OSPF_IF_PARAM(oi, retransmit_interval);
8049 nbr->v_ls_req = OSPF_IF_PARAM(oi, retransmit_interval);
8050 nbr->v_ls_upd = OSPF_IF_PARAM(oi, retransmit_interval);
8051 }
8052 }
8053
8054 static int ospf_vty_dead_interval_set(struct vty *vty, const char *interval_str,
8055 const char *nbr_str,
8056 const char *fast_hello_str)
8057 {
8058 VTY_DECLVAR_CONTEXT(interface, ifp);
8059 uint32_t seconds;
8060 uint8_t hellomult;
8061 struct in_addr addr;
8062 int ret;
8063 struct ospf_if_params *params;
8064 struct ospf_interface *oi;
8065 struct route_node *rn;
8066
8067 params = IF_DEF_PARAMS(ifp);
8068
8069 if (nbr_str) {
8070 ret = inet_aton(nbr_str, &addr);
8071 if (!ret) {
8072 vty_out(vty,
8073 "Please specify interface address by A.B.C.D\n");
8074 return CMD_WARNING_CONFIG_FAILED;
8075 }
8076
8077 params = ospf_get_if_params(ifp, addr);
8078 ospf_if_update_params(ifp, addr);
8079 }
8080
8081 if (interval_str) {
8082 seconds = strtoul(interval_str, NULL, 10);
8083
8084 /* reset fast_hello too, just to be sure */
8085 UNSET_IF_PARAM(params, fast_hello);
8086 params->fast_hello = OSPF_FAST_HELLO_DEFAULT;
8087 } else if (fast_hello_str) {
8088 hellomult = strtoul(fast_hello_str, NULL, 10);
8089 /* 1s dead-interval with sub-second hellos desired */
8090 seconds = OSPF_ROUTER_DEAD_INTERVAL_MINIMAL;
8091 SET_IF_PARAM(params, fast_hello);
8092 params->fast_hello = hellomult;
8093 } else {
8094 vty_out(vty,
8095 "Please specify dead-interval or hello-multiplier\n");
8096 return CMD_WARNING_CONFIG_FAILED;
8097 }
8098
8099 SET_IF_PARAM(params, v_wait);
8100 params->v_wait = seconds;
8101 params->is_v_wait_set = true;
8102
8103 /* Update timer values in neighbor structure. */
8104 if (nbr_str) {
8105 struct ospf *ospf = NULL;
8106
8107 ospf = ifp->vrf->info;
8108 if (ospf) {
8109 oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr);
8110 if (oi)
8111 ospf_nbr_timer_update(oi);
8112 }
8113 } else {
8114 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn))
8115 if ((oi = rn->info))
8116 ospf_nbr_timer_update(oi);
8117 }
8118
8119 return CMD_SUCCESS;
8120 }
8121
8122 DEFUN (ip_ospf_dead_interval,
8123 ip_ospf_dead_interval_cmd,
8124 "ip ospf dead-interval (1-65535) [A.B.C.D]",
8125 "IP Information\n"
8126 "OSPF interface commands\n"
8127 "Interval time after which a neighbor is declared down\n"
8128 "Seconds\n"
8129 "Address of interface\n")
8130 {
8131 int idx = 0;
8132 char *interval = argv_find(argv, argc, "(1-65535)", &idx)
8133 ? argv[idx]->arg
8134 : NULL;
8135 char *ifaddr =
8136 argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
8137 return ospf_vty_dead_interval_set(vty, interval, ifaddr, NULL);
8138 }
8139
8140
8141 DEFUN_HIDDEN (ospf_dead_interval,
8142 ospf_dead_interval_cmd,
8143 "ospf dead-interval (1-65535) [A.B.C.D]",
8144 "OSPF interface commands\n"
8145 "Interval time after which a neighbor is declared down\n"
8146 "Seconds\n"
8147 "Address of interface\n")
8148 {
8149 return ip_ospf_dead_interval(self, vty, argc, argv);
8150 }
8151
8152 DEFUN (ip_ospf_dead_interval_minimal,
8153 ip_ospf_dead_interval_minimal_addr_cmd,
8154 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
8155 "IP Information\n"
8156 "OSPF interface commands\n"
8157 "Interval time after which a neighbor is declared down\n"
8158 "Minimal 1s dead-interval with fast sub-second hellos\n"
8159 "Hello multiplier factor\n"
8160 "Number of Hellos to send each second\n"
8161 "Address of interface\n")
8162 {
8163 int idx_number = 5;
8164 int idx_ipv4 = 6;
8165 if (argc == 7)
8166 return ospf_vty_dead_interval_set(
8167 vty, NULL, argv[idx_ipv4]->arg, argv[idx_number]->arg);
8168 else
8169 return ospf_vty_dead_interval_set(vty, NULL, NULL,
8170 argv[idx_number]->arg);
8171 }
8172
8173 DEFUN (no_ip_ospf_dead_interval,
8174 no_ip_ospf_dead_interval_cmd,
8175 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8176 NO_STR
8177 "IP Information\n"
8178 "OSPF interface commands\n"
8179 "Interval time after which a neighbor is declared down\n"
8180 "Seconds\n"
8181 "Minimal 1s dead-interval with fast sub-second hellos\n"
8182 "Hello multiplier factor\n"
8183 "Number of Hellos to send each second\n"
8184 "Address of interface\n")
8185 {
8186 VTY_DECLVAR_CONTEXT(interface, ifp);
8187 int idx_ipv4 = argc - 1;
8188 struct in_addr addr = {.s_addr = 0L};
8189 int ret;
8190 struct ospf_if_params *params;
8191 struct ospf_interface *oi;
8192 struct route_node *rn;
8193
8194 params = IF_DEF_PARAMS(ifp);
8195
8196 if (argv[idx_ipv4]->type == IPV4_TKN) {
8197 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
8198 if (!ret) {
8199 vty_out(vty,
8200 "Please specify interface address by A.B.C.D\n");
8201 return CMD_WARNING_CONFIG_FAILED;
8202 }
8203
8204 params = ospf_lookup_if_params(ifp, addr);
8205 if (params == NULL)
8206 return CMD_SUCCESS;
8207 }
8208
8209 UNSET_IF_PARAM(params, v_wait);
8210 params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
8211 params->is_v_wait_set = false;
8212
8213 UNSET_IF_PARAM(params, fast_hello);
8214 params->fast_hello = OSPF_FAST_HELLO_DEFAULT;
8215
8216 if (params != IF_DEF_PARAMS(ifp)) {
8217 ospf_free_if_params(ifp, addr);
8218 ospf_if_update_params(ifp, addr);
8219 }
8220
8221 /* Update timer values in neighbor structure. */
8222 if (argc == 1) {
8223 struct ospf *ospf = NULL;
8224
8225 ospf = ifp->vrf->info;
8226 if (ospf) {
8227 oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr);
8228 if (oi)
8229 ospf_nbr_timer_update(oi);
8230 }
8231 } else {
8232 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn))
8233 if ((oi = rn->info))
8234 ospf_nbr_timer_update(oi);
8235 }
8236
8237 return CMD_SUCCESS;
8238 }
8239
8240 DEFUN_HIDDEN (no_ospf_dead_interval,
8241 no_ospf_dead_interval_cmd,
8242 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8243 NO_STR
8244 "OSPF interface commands\n"
8245 "Interval time after which a neighbor is declared down\n"
8246 "Seconds\n"
8247 "Minimal 1s dead-interval with fast sub-second hellos\n"
8248 "Hello multiplier factor\n"
8249 "Number of Hellos to send each second\n"
8250 "Address of interface\n")
8251 {
8252 return no_ip_ospf_dead_interval(self, vty, argc, argv);
8253 }
8254
8255 DEFUN (ip_ospf_hello_interval,
8256 ip_ospf_hello_interval_cmd,
8257 "ip ospf hello-interval (1-65535) [A.B.C.D]",
8258 "IP Information\n"
8259 "OSPF interface commands\n"
8260 "Time between HELLO packets\n"
8261 "Seconds\n"
8262 "Address of interface\n")
8263 {
8264 VTY_DECLVAR_CONTEXT(interface, ifp);
8265 int idx = 0;
8266 struct in_addr addr = {.s_addr = 0L};
8267 struct ospf_if_params *params;
8268 params = IF_DEF_PARAMS(ifp);
8269 uint32_t seconds = 0;
8270 bool is_addr = false;
8271 uint32_t old_interval = 0;
8272
8273 argv_find(argv, argc, "(1-65535)", &idx);
8274 seconds = strtol(argv[idx]->arg, NULL, 10);
8275
8276 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8277 if (!inet_aton(argv[idx]->arg, &addr)) {
8278 vty_out(vty,
8279 "Please specify interface address by A.B.C.D\n");
8280 return CMD_WARNING_CONFIG_FAILED;
8281 }
8282
8283 params = ospf_get_if_params(ifp, addr);
8284 ospf_if_update_params(ifp, addr);
8285 is_addr = true;
8286 }
8287
8288 old_interval = params->v_hello;
8289
8290 /* Return, if same interval is configured. */
8291 if (old_interval == seconds)
8292 return CMD_SUCCESS;
8293
8294 SET_IF_PARAM(params, v_hello);
8295 params->v_hello = seconds;
8296
8297 if (!params->is_v_wait_set) {
8298 SET_IF_PARAM(params, v_wait);
8299 /* As per RFC 4062
8300 * The router dead interval should
8301 * be some multiple of the HelloInterval (perhaps 4 times the
8302 * hello interval) and must be the same for all routers
8303 * attached to a common network.
8304 */
8305 params->v_wait = 4 * seconds;
8306 }
8307
8308 ospf_reset_hello_timer(ifp, addr, is_addr);
8309
8310 return CMD_SUCCESS;
8311 }
8312
8313 DEFUN_HIDDEN (ospf_hello_interval,
8314 ospf_hello_interval_cmd,
8315 "ospf hello-interval (1-65535) [A.B.C.D]",
8316 "OSPF interface commands\n"
8317 "Time between HELLO packets\n"
8318 "Seconds\n"
8319 "Address of interface\n")
8320 {
8321 return ip_ospf_hello_interval(self, vty, argc, argv);
8322 }
8323
8324 DEFUN (no_ip_ospf_hello_interval,
8325 no_ip_ospf_hello_interval_cmd,
8326 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
8327 NO_STR
8328 "IP Information\n"
8329 "OSPF interface commands\n"
8330 "Time between HELLO packets\n" // ignored
8331 "Seconds\n"
8332 "Address of interface\n")
8333 {
8334 VTY_DECLVAR_CONTEXT(interface, ifp);
8335 int idx = 0;
8336 struct in_addr addr = {.s_addr = 0L};
8337 struct ospf_if_params *params;
8338 struct route_node *rn;
8339
8340 params = IF_DEF_PARAMS(ifp);
8341
8342 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8343 if (!inet_aton(argv[idx]->arg, &addr)) {
8344 vty_out(vty,
8345 "Please specify interface address by A.B.C.D\n");
8346 return CMD_WARNING_CONFIG_FAILED;
8347 }
8348
8349 params = ospf_lookup_if_params(ifp, addr);
8350 if (params == NULL)
8351 return CMD_SUCCESS;
8352 }
8353
8354 UNSET_IF_PARAM(params, v_hello);
8355 params->v_hello = OSPF_HELLO_INTERVAL_DEFAULT;
8356
8357 if (!params->is_v_wait_set) {
8358 UNSET_IF_PARAM(params, v_wait);
8359 params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
8360 }
8361
8362 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8363 struct ospf_interface *oi = rn->info;
8364
8365 if (!oi)
8366 continue;
8367
8368 oi->type = IF_DEF_PARAMS(ifp)->type;
8369 oi->ptp_dmvpn = IF_DEF_PARAMS(ifp)->ptp_dmvpn;
8370
8371 if (oi->state > ISM_Down) {
8372 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown);
8373 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp);
8374 }
8375 }
8376
8377 if (params != IF_DEF_PARAMS(ifp)) {
8378 ospf_free_if_params(ifp, addr);
8379 ospf_if_update_params(ifp, addr);
8380 }
8381
8382 return CMD_SUCCESS;
8383 }
8384
8385 DEFUN_HIDDEN (no_ospf_hello_interval,
8386 no_ospf_hello_interval_cmd,
8387 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
8388 NO_STR
8389 "OSPF interface commands\n"
8390 "Time between HELLO packets\n" // ignored
8391 "Seconds\n"
8392 "Address of interface\n")
8393 {
8394 return no_ip_ospf_hello_interval(self, vty, argc, argv);
8395 }
8396
8397 DEFUN(ip_ospf_network, ip_ospf_network_cmd,
8398 "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point [dmvpn]>",
8399 "IP Information\n"
8400 "OSPF interface commands\n"
8401 "Network type\n"
8402 "Specify OSPF broadcast multi-access network\n"
8403 "Specify OSPF NBMA network\n"
8404 "Specify OSPF point-to-multipoint network\n"
8405 "Specify OSPF point-to-point network\n"
8406 "Specify OSPF point-to-point DMVPN network\n")
8407 {
8408 VTY_DECLVAR_CONTEXT(interface, ifp);
8409 int idx = 0;
8410 int old_type = IF_DEF_PARAMS(ifp)->type;
8411 uint8_t old_ptp_dmvpn = IF_DEF_PARAMS(ifp)->ptp_dmvpn;
8412 struct route_node *rn;
8413
8414 if (old_type == OSPF_IFTYPE_LOOPBACK) {
8415 vty_out(vty,
8416 "This is a loopback interface. Can't set network type.\n");
8417 return CMD_WARNING_CONFIG_FAILED;
8418 }
8419
8420 IF_DEF_PARAMS(ifp)->ptp_dmvpn = 0;
8421
8422 if (argv_find(argv, argc, "broadcast", &idx))
8423 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_BROADCAST;
8424 else if (argv_find(argv, argc, "non-broadcast", &idx))
8425 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_NBMA;
8426 else if (argv_find(argv, argc, "point-to-multipoint", &idx))
8427 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOMULTIPOINT;
8428 else if (argv_find(argv, argc, "point-to-point", &idx)) {
8429 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOPOINT;
8430 if (argv_find(argv, argc, "dmvpn", &idx))
8431 IF_DEF_PARAMS(ifp)->ptp_dmvpn = 1;
8432 }
8433
8434 if (IF_DEF_PARAMS(ifp)->type == old_type
8435 && IF_DEF_PARAMS(ifp)->ptp_dmvpn == old_ptp_dmvpn)
8436 return CMD_SUCCESS;
8437
8438 SET_IF_PARAM(IF_DEF_PARAMS(ifp), type);
8439
8440 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8441 struct ospf_interface *oi = rn->info;
8442
8443 if (!oi)
8444 continue;
8445
8446 oi->type = IF_DEF_PARAMS(ifp)->type;
8447
8448 if (oi->state > ISM_Down) {
8449 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown);
8450 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp);
8451 }
8452 }
8453
8454 return CMD_SUCCESS;
8455 }
8456
8457 DEFUN_HIDDEN (ospf_network,
8458 ospf_network_cmd,
8459 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
8460 "OSPF interface commands\n"
8461 "Network type\n"
8462 "Specify OSPF broadcast multi-access network\n"
8463 "Specify OSPF NBMA network\n"
8464 "Specify OSPF point-to-multipoint network\n"
8465 "Specify OSPF point-to-point network\n")
8466 {
8467 return ip_ospf_network(self, vty, argc, argv);
8468 }
8469
8470 DEFUN (no_ip_ospf_network,
8471 no_ip_ospf_network_cmd,
8472 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8473 NO_STR
8474 "IP Information\n"
8475 "OSPF interface commands\n"
8476 "Network type\n"
8477 "Specify OSPF broadcast multi-access network\n"
8478 "Specify OSPF NBMA network\n"
8479 "Specify OSPF point-to-multipoint network\n"
8480 "Specify OSPF point-to-point network\n")
8481 {
8482 VTY_DECLVAR_CONTEXT(interface, ifp);
8483 int old_type = IF_DEF_PARAMS(ifp)->type;
8484 struct route_node *rn;
8485
8486 IF_DEF_PARAMS(ifp)->type = ospf_default_iftype(ifp);
8487 IF_DEF_PARAMS(ifp)->ptp_dmvpn = 0;
8488
8489 if (IF_DEF_PARAMS(ifp)->type == old_type)
8490 return CMD_SUCCESS;
8491
8492 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8493 struct ospf_interface *oi = rn->info;
8494
8495 if (!oi)
8496 continue;
8497
8498 oi->type = IF_DEF_PARAMS(ifp)->type;
8499
8500 if (oi->state > ISM_Down) {
8501 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown);
8502 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp);
8503 }
8504 }
8505
8506 return CMD_SUCCESS;
8507 }
8508
8509 DEFUN_HIDDEN (no_ospf_network,
8510 no_ospf_network_cmd,
8511 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8512 NO_STR
8513 "OSPF interface commands\n"
8514 "Network type\n"
8515 "Specify OSPF broadcast multi-access network\n"
8516 "Specify OSPF NBMA network\n"
8517 "Specify OSPF point-to-multipoint network\n"
8518 "Specify OSPF point-to-point network\n")
8519 {
8520 return no_ip_ospf_network(self, vty, argc, argv);
8521 }
8522
8523 DEFUN (ip_ospf_priority,
8524 ip_ospf_priority_cmd,
8525 "ip ospf priority (0-255) [A.B.C.D]",
8526 "IP Information\n"
8527 "OSPF interface commands\n"
8528 "Router priority\n"
8529 "Priority\n"
8530 "Address of interface\n")
8531 {
8532 VTY_DECLVAR_CONTEXT(interface, ifp);
8533 int idx = 0;
8534 long priority;
8535 struct route_node *rn;
8536 struct in_addr addr;
8537 struct ospf_if_params *params;
8538 params = IF_DEF_PARAMS(ifp);
8539
8540 argv_find(argv, argc, "(0-255)", &idx);
8541 priority = strtol(argv[idx]->arg, NULL, 10);
8542
8543 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8544 if (!inet_aton(argv[idx]->arg, &addr)) {
8545 vty_out(vty,
8546 "Please specify interface address by A.B.C.D\n");
8547 return CMD_WARNING_CONFIG_FAILED;
8548 }
8549
8550 params = ospf_get_if_params(ifp, addr);
8551 ospf_if_update_params(ifp, addr);
8552 }
8553
8554 SET_IF_PARAM(params, priority);
8555 params->priority = priority;
8556
8557 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8558 struct ospf_interface *oi = rn->info;
8559
8560 if (!oi)
8561 continue;
8562
8563 if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) {
8564 PRIORITY(oi) = OSPF_IF_PARAM(oi, priority);
8565 OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange);
8566 }
8567 }
8568
8569 return CMD_SUCCESS;
8570 }
8571
8572 DEFUN_HIDDEN (ospf_priority,
8573 ospf_priority_cmd,
8574 "ospf priority (0-255) [A.B.C.D]",
8575 "OSPF interface commands\n"
8576 "Router priority\n"
8577 "Priority\n"
8578 "Address of interface\n")
8579 {
8580 return ip_ospf_priority(self, vty, argc, argv);
8581 }
8582
8583 DEFUN (no_ip_ospf_priority,
8584 no_ip_ospf_priority_cmd,
8585 "no ip ospf priority [(0-255) [A.B.C.D]]",
8586 NO_STR
8587 "IP Information\n"
8588 "OSPF interface commands\n"
8589 "Router priority\n" // ignored
8590 "Priority\n"
8591 "Address of interface\n")
8592 {
8593 VTY_DECLVAR_CONTEXT(interface, ifp);
8594 int idx = 0;
8595 struct route_node *rn;
8596 struct in_addr addr;
8597 struct ospf_if_params *params;
8598
8599 params = IF_DEF_PARAMS(ifp);
8600
8601 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8602 if (!inet_aton(argv[idx]->arg, &addr)) {
8603 vty_out(vty,
8604 "Please specify interface address by A.B.C.D\n");
8605 return CMD_WARNING_CONFIG_FAILED;
8606 }
8607
8608 params = ospf_lookup_if_params(ifp, addr);
8609 if (params == NULL)
8610 return CMD_SUCCESS;
8611 }
8612
8613 UNSET_IF_PARAM(params, priority);
8614 params->priority = OSPF_ROUTER_PRIORITY_DEFAULT;
8615
8616 if (params != IF_DEF_PARAMS(ifp)) {
8617 ospf_free_if_params(ifp, addr);
8618 ospf_if_update_params(ifp, addr);
8619 }
8620
8621 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8622 struct ospf_interface *oi = rn->info;
8623
8624 if (!oi)
8625 continue;
8626
8627 if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) {
8628 PRIORITY(oi) = OSPF_IF_PARAM(oi, priority);
8629 OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange);
8630 }
8631 }
8632
8633 return CMD_SUCCESS;
8634 }
8635
8636 DEFUN_HIDDEN (no_ospf_priority,
8637 no_ospf_priority_cmd,
8638 "no ospf priority [(0-255) [A.B.C.D]]",
8639 NO_STR
8640 "OSPF interface commands\n"
8641 "Router priority\n"
8642 "Priority\n"
8643 "Address of interface\n")
8644 {
8645 return no_ip_ospf_priority(self, vty, argc, argv);
8646 }
8647
8648 DEFUN (ip_ospf_retransmit_interval,
8649 ip_ospf_retransmit_interval_addr_cmd,
8650 "ip ospf retransmit-interval (1-65535) [A.B.C.D]",
8651 "IP Information\n"
8652 "OSPF interface commands\n"
8653 "Time between retransmitting lost link state advertisements\n"
8654 "Seconds\n"
8655 "Address of interface\n")
8656 {
8657 VTY_DECLVAR_CONTEXT(interface, ifp);
8658 int idx = 0;
8659 uint32_t seconds;
8660 struct in_addr addr;
8661 struct ospf_if_params *params;
8662 params = IF_DEF_PARAMS(ifp);
8663
8664 argv_find(argv, argc, "(1-65535)", &idx);
8665 seconds = strtol(argv[idx]->arg, NULL, 10);
8666
8667 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8668 if (!inet_aton(argv[idx]->arg, &addr)) {
8669 vty_out(vty,
8670 "Please specify interface address by A.B.C.D\n");
8671 return CMD_WARNING_CONFIG_FAILED;
8672 }
8673
8674 params = ospf_get_if_params(ifp, addr);
8675 ospf_if_update_params(ifp, addr);
8676 }
8677
8678 SET_IF_PARAM(params, retransmit_interval);
8679 params->retransmit_interval = seconds;
8680
8681 return CMD_SUCCESS;
8682 }
8683
8684 DEFUN_HIDDEN (ospf_retransmit_interval,
8685 ospf_retransmit_interval_cmd,
8686 "ospf retransmit-interval (1-65535) [A.B.C.D]",
8687 "OSPF interface commands\n"
8688 "Time between retransmitting lost link state advertisements\n"
8689 "Seconds\n"
8690 "Address of interface\n")
8691 {
8692 return ip_ospf_retransmit_interval(self, vty, argc, argv);
8693 }
8694
8695 DEFUN (no_ip_ospf_retransmit_interval,
8696 no_ip_ospf_retransmit_interval_addr_cmd,
8697 "no ip ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8698 NO_STR
8699 "IP Information\n"
8700 "OSPF interface commands\n"
8701 "Time between retransmitting lost link state advertisements\n"
8702 "Seconds\n"
8703 "Address of interface\n")
8704 {
8705 VTY_DECLVAR_CONTEXT(interface, ifp);
8706 int idx = 0;
8707 struct in_addr addr;
8708 struct ospf_if_params *params;
8709
8710 params = IF_DEF_PARAMS(ifp);
8711
8712 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8713 if (!inet_aton(argv[idx]->arg, &addr)) {
8714 vty_out(vty,
8715 "Please specify interface address by A.B.C.D\n");
8716 return CMD_WARNING_CONFIG_FAILED;
8717 }
8718
8719 params = ospf_lookup_if_params(ifp, addr);
8720 if (params == NULL)
8721 return CMD_SUCCESS;
8722 }
8723
8724 UNSET_IF_PARAM(params, retransmit_interval);
8725 params->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT;
8726
8727 if (params != IF_DEF_PARAMS(ifp)) {
8728 ospf_free_if_params(ifp, addr);
8729 ospf_if_update_params(ifp, addr);
8730 }
8731
8732 return CMD_SUCCESS;
8733 }
8734
8735 DEFUN_HIDDEN (no_ospf_retransmit_interval,
8736 no_ospf_retransmit_interval_cmd,
8737 "no ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8738 NO_STR
8739 "OSPF interface commands\n"
8740 "Time between retransmitting lost link state advertisements\n"
8741 "Seconds\n"
8742 "Address of interface\n")
8743 {
8744 return no_ip_ospf_retransmit_interval(self, vty, argc, argv);
8745 }
8746
8747 DEFUN (ip_ospf_transmit_delay,
8748 ip_ospf_transmit_delay_addr_cmd,
8749 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
8750 "IP Information\n"
8751 "OSPF interface commands\n"
8752 "Link state transmit delay\n"
8753 "Seconds\n"
8754 "Address of interface\n")
8755 {
8756 VTY_DECLVAR_CONTEXT(interface, ifp);
8757 int idx = 0;
8758 uint32_t seconds;
8759 struct in_addr addr;
8760 struct ospf_if_params *params;
8761
8762 params = IF_DEF_PARAMS(ifp);
8763 argv_find(argv, argc, "(1-65535)", &idx);
8764 seconds = strtol(argv[idx]->arg, NULL, 10);
8765
8766 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8767 if (!inet_aton(argv[idx]->arg, &addr)) {
8768 vty_out(vty,
8769 "Please specify interface address by A.B.C.D\n");
8770 return CMD_WARNING_CONFIG_FAILED;
8771 }
8772
8773 params = ospf_get_if_params(ifp, addr);
8774 ospf_if_update_params(ifp, addr);
8775 }
8776
8777 SET_IF_PARAM(params, transmit_delay);
8778 params->transmit_delay = seconds;
8779
8780 return CMD_SUCCESS;
8781 }
8782
8783 DEFUN_HIDDEN (ospf_transmit_delay,
8784 ospf_transmit_delay_cmd,
8785 "ospf transmit-delay (1-65535) [A.B.C.D]",
8786 "OSPF interface commands\n"
8787 "Link state transmit delay\n"
8788 "Seconds\n"
8789 "Address of interface\n")
8790 {
8791 return ip_ospf_transmit_delay(self, vty, argc, argv);
8792 }
8793
8794 DEFUN (no_ip_ospf_transmit_delay,
8795 no_ip_ospf_transmit_delay_addr_cmd,
8796 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
8797 NO_STR
8798 "IP Information\n"
8799 "OSPF interface commands\n"
8800 "Link state transmit delay\n"
8801 "Seconds\n"
8802 "Address of interface\n")
8803 {
8804 VTY_DECLVAR_CONTEXT(interface, ifp);
8805 int idx = 0;
8806 struct in_addr addr;
8807 struct ospf_if_params *params;
8808
8809 params = IF_DEF_PARAMS(ifp);
8810
8811 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8812 if (!inet_aton(argv[idx]->arg, &addr)) {
8813 vty_out(vty,
8814 "Please specify interface address by A.B.C.D\n");
8815 return CMD_WARNING_CONFIG_FAILED;
8816 }
8817
8818 params = ospf_lookup_if_params(ifp, addr);
8819 if (params == NULL)
8820 return CMD_SUCCESS;
8821 }
8822
8823 UNSET_IF_PARAM(params, transmit_delay);
8824 params->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT;
8825
8826 if (params != IF_DEF_PARAMS(ifp)) {
8827 ospf_free_if_params(ifp, addr);
8828 ospf_if_update_params(ifp, addr);
8829 }
8830
8831 return CMD_SUCCESS;
8832 }
8833
8834
8835 DEFUN_HIDDEN (no_ospf_transmit_delay,
8836 no_ospf_transmit_delay_cmd,
8837 "no ospf transmit-delay [(1-65535) [A.B.C.D]]",
8838 NO_STR
8839 "OSPF interface commands\n"
8840 "Link state transmit delay\n"
8841 "Seconds\n"
8842 "Address of interface\n")
8843 {
8844 return no_ip_ospf_transmit_delay(self, vty, argc, argv);
8845 }
8846
8847 DEFUN (ip_ospf_area,
8848 ip_ospf_area_cmd,
8849 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]",
8850 "IP Information\n"
8851 "OSPF interface commands\n"
8852 "Instance ID\n"
8853 "Enable OSPF on this interface\n"
8854 "OSPF area ID in IP address format\n"
8855 "OSPF area ID as a decimal value\n"
8856 "Address of interface\n")
8857 {
8858 VTY_DECLVAR_CONTEXT(interface, ifp);
8859 int idx = 0;
8860 int format, ret;
8861 struct in_addr area_id;
8862 struct in_addr addr;
8863 struct ospf_if_params *params = NULL;
8864 struct route_node *rn;
8865 struct ospf *ospf = NULL;
8866 unsigned short instance = 0;
8867 char *areaid;
8868 uint32_t count = 0;
8869
8870 if (argv_find(argv, argc, "(1-65535)", &idx))
8871 instance = strtol(argv[idx]->arg, NULL, 10);
8872
8873 argv_find(argv, argc, "area", &idx);
8874 areaid = argv[idx + 1]->arg;
8875
8876 if (!instance)
8877 ospf = ifp->vrf->info;
8878 else
8879 ospf = ospf_lookup_instance(instance);
8880
8881 if (instance && instance != ospf_instance) {
8882 /*
8883 * At this point we know we have received
8884 * an instance and there is no ospf instance
8885 * associated with it. This means we are
8886 * in a situation where we have an
8887 * ospf command that is setup for a different
8888 * process(instance). We need to safely
8889 * remove the command from ourselves and
8890 * allow the other instance(process) handle
8891 * the configuration command.
8892 */
8893 count = 0;
8894
8895 params = IF_DEF_PARAMS(ifp);
8896 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
8897 UNSET_IF_PARAM(params, if_area);
8898 count++;
8899 }
8900
8901 for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; rn = route_next(rn))
8902 if ((params = rn->info) && OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
8903 UNSET_IF_PARAM(params, if_area);
8904 count++;
8905 }
8906
8907 if (count > 0) {
8908 ospf = ifp->vrf->info;
8909 if (ospf)
8910 ospf_interface_area_unset(ospf, ifp);
8911 }
8912
8913 return CMD_NOT_MY_INSTANCE;
8914 }
8915
8916 ret = str2area_id(areaid, &area_id, &format);
8917 if (ret < 0) {
8918 vty_out(vty, "Please specify area by A.B.C.D|<0-4294967295>\n");
8919 return CMD_WARNING_CONFIG_FAILED;
8920 }
8921 if (memcmp(ifp->name, "VLINK", 5) == 0) {
8922 vty_out(vty, "Cannot enable OSPF on a virtual link.\n");
8923 return CMD_WARNING_CONFIG_FAILED;
8924 }
8925
8926 if (ospf) {
8927 for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) {
8928 if (rn->info != NULL) {
8929 vty_out(vty,
8930 "Please remove all network commands first.\n");
8931 return CMD_WARNING_CONFIG_FAILED;
8932 }
8933 }
8934 }
8935
8936 params = IF_DEF_PARAMS(ifp);
8937 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)
8938 && !IPV4_ADDR_SAME(&params->if_area, &area_id)) {
8939 vty_out(vty,
8940 "Must remove previous area config before changing ospf area \n");
8941 return CMD_WARNING_CONFIG_FAILED;
8942 }
8943
8944 // Check if we have an address arg and proccess it
8945 if (argc == idx + 3) {
8946 if (!inet_aton(argv[idx + 2]->arg, &addr)) {
8947 vty_out(vty,
8948 "Please specify Intf Address by A.B.C.D\n");
8949 return CMD_WARNING_CONFIG_FAILED;
8950 }
8951 // update/create address-level params
8952 params = ospf_get_if_params((ifp), (addr));
8953 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
8954 if (!IPV4_ADDR_SAME(&params->if_area, &area_id)) {
8955 vty_out(vty,
8956 "Must remove previous area/address config before changing ospf area\n");
8957 return CMD_WARNING_CONFIG_FAILED;
8958 } else
8959 return CMD_SUCCESS;
8960 }
8961 ospf_if_update_params((ifp), (addr));
8962 }
8963
8964 /* enable ospf on this interface with area_id */
8965 if (params) {
8966 SET_IF_PARAM(params, if_area);
8967 params->if_area = area_id;
8968 params->if_area_id_fmt = format;
8969 }
8970
8971 if (ospf)
8972 ospf_interface_area_set(ospf, ifp);
8973
8974 return CMD_SUCCESS;
8975 }
8976
8977 DEFUN (no_ip_ospf_area,
8978 no_ip_ospf_area_cmd,
8979 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]",
8980 NO_STR
8981 "IP Information\n"
8982 "OSPF interface commands\n"
8983 "Instance ID\n"
8984 "Disable OSPF on this interface\n"
8985 "OSPF area ID in IP address format\n"
8986 "OSPF area ID as a decimal value\n"
8987 "Address of interface\n")
8988 {
8989 VTY_DECLVAR_CONTEXT(interface, ifp);
8990 int idx = 0;
8991 struct ospf *ospf;
8992 struct ospf_if_params *params;
8993 unsigned short instance = 0;
8994 struct in_addr addr;
8995 struct in_addr area_id;
8996
8997 if (argv_find(argv, argc, "(1-65535)", &idx))
8998 instance = strtol(argv[idx]->arg, NULL, 10);
8999
9000 if (!instance)
9001 ospf = ifp->vrf->info;
9002 else
9003 ospf = ospf_lookup_instance(instance);
9004
9005 if (instance && instance != ospf_instance)
9006 return CMD_NOT_MY_INSTANCE;
9007
9008 argv_find(argv, argc, "area", &idx);
9009
9010 // Check if we have an address arg and proccess it
9011 if (argc == idx + 3) {
9012 if (!inet_aton(argv[idx + 2]->arg, &addr)) {
9013 vty_out(vty,
9014 "Please specify Intf Address by A.B.C.D\n");
9015 return CMD_WARNING_CONFIG_FAILED;
9016 }
9017 params = ospf_lookup_if_params(ifp, addr);
9018 if ((params) == NULL)
9019 return CMD_SUCCESS;
9020 } else
9021 params = IF_DEF_PARAMS(ifp);
9022
9023 area_id = params->if_area;
9024 if (!OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
9025 vty_out(vty,
9026 "Can't find specified interface area configuration.\n");
9027 return CMD_WARNING_CONFIG_FAILED;
9028 }
9029
9030 UNSET_IF_PARAM(params, if_area);
9031 if (params != IF_DEF_PARAMS((ifp))) {
9032 ospf_free_if_params((ifp), (addr));
9033 ospf_if_update_params((ifp), (addr));
9034 }
9035
9036 if (ospf) {
9037 ospf_interface_area_unset(ospf, ifp);
9038 ospf_area_check_free(ospf, area_id);
9039 }
9040
9041 return CMD_SUCCESS;
9042 }
9043
9044 DEFUN (ip_ospf_passive,
9045 ip_ospf_passive_cmd,
9046 "ip ospf passive [A.B.C.D]",
9047 "IP Information\n"
9048 "OSPF interface commands\n"
9049 "Suppress routing updates on an interface\n"
9050 "Address of interface\n")
9051 {
9052 VTY_DECLVAR_CONTEXT(interface, ifp);
9053 int idx_ipv4 = 3;
9054 struct in_addr addr = {.s_addr = INADDR_ANY};
9055 struct ospf_if_params *params;
9056 int ret;
9057
9058 if (argc == 4) {
9059 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
9060 if (!ret) {
9061 vty_out(vty,
9062 "Please specify interface address by A.B.C.D\n");
9063 return CMD_WARNING_CONFIG_FAILED;
9064 }
9065 params = ospf_get_if_params(ifp, addr);
9066 ospf_if_update_params(ifp, addr);
9067 } else {
9068 params = IF_DEF_PARAMS(ifp);
9069 }
9070
9071 ospf_passive_interface_update(ifp, params, addr, OSPF_IF_PASSIVE);
9072
9073 return CMD_SUCCESS;
9074 }
9075
9076 DEFUN (no_ip_ospf_passive,
9077 no_ip_ospf_passive_cmd,
9078 "no ip ospf passive [A.B.C.D]",
9079 NO_STR
9080 "IP Information\n"
9081 "OSPF interface commands\n"
9082 "Enable routing updates on an interface\n"
9083 "Address of interface\n")
9084 {
9085 VTY_DECLVAR_CONTEXT(interface, ifp);
9086 int idx_ipv4 = 4;
9087 struct in_addr addr = {.s_addr = INADDR_ANY};
9088 struct ospf_if_params *params;
9089 int ret;
9090
9091 if (argc == 5) {
9092 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
9093 if (!ret) {
9094 vty_out(vty,
9095 "Please specify interface address by A.B.C.D\n");
9096 return CMD_WARNING_CONFIG_FAILED;
9097 }
9098 params = ospf_lookup_if_params(ifp, addr);
9099 if (params == NULL)
9100 return CMD_SUCCESS;
9101 } else {
9102 params = IF_DEF_PARAMS(ifp);
9103 }
9104
9105 ospf_passive_interface_update(ifp, params, addr, OSPF_IF_ACTIVE);
9106
9107 return CMD_SUCCESS;
9108 }
9109
9110 DEFUN (ospf_redistribute_source,
9111 ospf_redistribute_source_cmd,
9112 "redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9113 REDIST_STR
9114 FRR_REDIST_HELP_STR_OSPFD
9115 "Metric for redistributed routes\n"
9116 "OSPF default metric\n"
9117 "OSPF exterior metric type for redistributed routes\n"
9118 "Set OSPF External Type 1/2 metrics\n"
9119 "Route map reference\n"
9120 "Pointer to route-map entries\n")
9121 {
9122 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9123 int idx_protocol = 1;
9124 int source;
9125 int type = -1;
9126 int metric = -1;
9127 struct ospf_redist *red;
9128 int idx = 0;
9129 bool update = false;
9130
9131 /* Get distribute source. */
9132 source = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
9133 if (source < 0)
9134 return CMD_WARNING_CONFIG_FAILED;
9135
9136 /* Get metric value. */
9137 if (argv_find(argv, argc, "(0-16777214)", &idx)) {
9138 if (!str2metric(argv[idx]->arg, &metric))
9139 return CMD_WARNING_CONFIG_FAILED;
9140 }
9141 idx = 1;
9142 /* Get metric type. */
9143 if (argv_find(argv, argc, "(1-2)", &idx)) {
9144 if (!str2metric_type(argv[idx]->arg, &type))
9145 return CMD_WARNING_CONFIG_FAILED;
9146 }
9147 idx = 1;
9148
9149 red = ospf_redist_lookup(ospf, source, 0);
9150 if (!red)
9151 red = ospf_redist_add(ospf, source, 0);
9152 else
9153 update = true;
9154
9155 /* Get route-map */
9156 if (argv_find(argv, argc, "route-map", &idx)) {
9157 ospf_routemap_set(red, argv[idx + 1]->arg);
9158 } else
9159 ospf_routemap_unset(red);
9160
9161 if (update)
9162 return ospf_redistribute_update(ospf, red, source, 0, type,
9163 metric);
9164 else
9165 return ospf_redistribute_set(ospf, red, source, 0, type,
9166 metric);
9167 }
9168
9169 DEFUN (no_ospf_redistribute_source,
9170 no_ospf_redistribute_source_cmd,
9171 "no redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9172 NO_STR
9173 REDIST_STR
9174 FRR_REDIST_HELP_STR_OSPFD
9175 "Metric for redistributed routes\n"
9176 "OSPF default metric\n"
9177 "OSPF exterior metric type for redistributed routes\n"
9178 "Set OSPF External Type 1/2 metrics\n"
9179 "Route map reference\n"
9180 "Pointer to route-map entries\n")
9181 {
9182 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9183 int idx_protocol = 2;
9184 int source;
9185 struct ospf_redist *red;
9186
9187 source = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
9188 if (source < 0)
9189 return CMD_WARNING_CONFIG_FAILED;
9190
9191 red = ospf_redist_lookup(ospf, source, 0);
9192 if (!red)
9193 return CMD_SUCCESS;
9194
9195 ospf_routemap_unset(red);
9196 ospf_redist_del(ospf, source, 0);
9197
9198 return ospf_redistribute_unset(ospf, source, 0);
9199 }
9200
9201 DEFUN (ospf_redistribute_instance_source,
9202 ospf_redistribute_instance_source_cmd,
9203 "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9204 REDIST_STR
9205 "Open Shortest Path First\n"
9206 "Non-main Kernel Routing Table\n"
9207 "Instance ID/Table ID\n"
9208 "Metric for redistributed routes\n"
9209 "OSPF default metric\n"
9210 "OSPF exterior metric type for redistributed routes\n"
9211 "Set OSPF External Type 1/2 metrics\n"
9212 "Route map reference\n"
9213 "Pointer to route-map entries\n")
9214 {
9215 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9216 int idx_ospf_table = 1;
9217 int idx_number = 2;
9218 int idx = 3;
9219 int source;
9220 int type = -1;
9221 int metric = -1;
9222 unsigned short instance;
9223 struct ospf_redist *red;
9224 bool update = false;
9225
9226 source = proto_redistnum(AFI_IP, argv[idx_ospf_table]->text);
9227
9228 if (source < 0) {
9229 vty_out(vty, "Unknown instance redistribution\n");
9230 return CMD_WARNING_CONFIG_FAILED;
9231 }
9232
9233 instance = strtoul(argv[idx_number]->arg, NULL, 10);
9234
9235 if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) {
9236 vty_out(vty,
9237 "Instance redistribution in non-instanced OSPF not allowed\n");
9238 return CMD_WARNING_CONFIG_FAILED;
9239 }
9240
9241 if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) {
9242 vty_out(vty, "Same instance OSPF redistribution not allowed\n");
9243 return CMD_WARNING_CONFIG_FAILED;
9244 }
9245
9246 /* Get metric value. */
9247 if (argv_find(argv, argc, "metric", &idx))
9248 if (!str2metric(argv[idx + 1]->arg, &metric))
9249 return CMD_WARNING_CONFIG_FAILED;
9250
9251 idx = 3;
9252 /* Get metric type. */
9253 if (argv_find(argv, argc, "metric-type", &idx))
9254 if (!str2metric_type(argv[idx + 1]->arg, &type))
9255 return CMD_WARNING_CONFIG_FAILED;
9256
9257 red = ospf_redist_lookup(ospf, source, instance);
9258 if (!red)
9259 red = ospf_redist_add(ospf, source, instance);
9260 else
9261 update = true;
9262
9263 idx = 3;
9264 if (argv_find(argv, argc, "route-map", &idx))
9265 ospf_routemap_set(red, argv[idx + 1]->arg);
9266 else
9267 ospf_routemap_unset(red);
9268
9269 if (update)
9270 return ospf_redistribute_update(ospf, red, source, instance,
9271 type, metric);
9272 else
9273 return ospf_redistribute_set(ospf, red, source, instance, type,
9274 metric);
9275 }
9276
9277 DEFUN (no_ospf_redistribute_instance_source,
9278 no_ospf_redistribute_instance_source_cmd,
9279 "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9280 NO_STR
9281 REDIST_STR
9282 "Open Shortest Path First\n"
9283 "Non-main Kernel Routing Table\n"
9284 "Instance ID/Table Id\n"
9285 "Metric for redistributed routes\n"
9286 "OSPF default metric\n"
9287 "OSPF exterior metric type for redistributed routes\n"
9288 "Set OSPF External Type 1/2 metrics\n"
9289 "Route map reference\n"
9290 "Pointer to route-map entries\n")
9291 {
9292 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9293 int idx_ospf_table = 2;
9294 int idx_number = 3;
9295 unsigned int instance;
9296 struct ospf_redist *red;
9297 int source;
9298
9299 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
9300 source = ZEBRA_ROUTE_OSPF;
9301 else
9302 source = ZEBRA_ROUTE_TABLE;
9303
9304 instance = strtoul(argv[idx_number]->arg, NULL, 10);
9305
9306 if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) {
9307 vty_out(vty,
9308 "Instance redistribution in non-instanced OSPF not allowed\n");
9309 return CMD_WARNING_CONFIG_FAILED;
9310 }
9311
9312 if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) {
9313 vty_out(vty, "Same instance OSPF redistribution not allowed\n");
9314 return CMD_WARNING_CONFIG_FAILED;
9315 }
9316
9317 red = ospf_redist_lookup(ospf, source, instance);
9318 if (!red)
9319 return CMD_SUCCESS;
9320
9321 ospf_routemap_unset(red);
9322 ospf_redist_del(ospf, source, instance);
9323
9324 return ospf_redistribute_unset(ospf, source, instance);
9325 }
9326
9327 DEFUN (ospf_distribute_list_out,
9328 ospf_distribute_list_out_cmd,
9329 "distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD,
9330 "Filter networks in routing updates\n"
9331 "Access-list name\n"
9332 OUT_STR
9333 FRR_REDIST_HELP_STR_OSPFD)
9334 {
9335 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9336 int idx_word = 1;
9337 int source;
9338
9339 char *proto = argv[argc - 1]->text;
9340
9341 /* Get distribute source. */
9342 source = proto_redistnum(AFI_IP, proto);
9343 if (source < 0)
9344 return CMD_WARNING_CONFIG_FAILED;
9345
9346 return ospf_distribute_list_out_set(ospf, source, argv[idx_word]->arg);
9347 }
9348
9349 DEFUN (no_ospf_distribute_list_out,
9350 no_ospf_distribute_list_out_cmd,
9351 "no distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD,
9352 NO_STR
9353 "Filter networks in routing updates\n"
9354 "Access-list name\n"
9355 OUT_STR
9356 FRR_REDIST_HELP_STR_OSPFD)
9357 {
9358 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9359 int idx_word = 2;
9360 int source;
9361
9362 char *proto = argv[argc - 1]->text;
9363 source = proto_redistnum(AFI_IP, proto);
9364 if (source < 0)
9365 return CMD_WARNING_CONFIG_FAILED;
9366
9367 return ospf_distribute_list_out_unset(ospf, source,
9368 argv[idx_word]->arg);
9369 }
9370
9371 /* Default information originate. */
9372 DEFUN (ospf_default_information_originate,
9373 ospf_default_information_originate_cmd,
9374 "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9375 "Control distribution of default information\n"
9376 "Distribute a default route\n"
9377 "Always advertise default route\n"
9378 "OSPF default metric\n"
9379 "OSPF metric\n"
9380 "OSPF metric type for default routes\n"
9381 "Set OSPF External Type 1/2 metrics\n"
9382 "Route map reference\n"
9383 "Pointer to route-map entries\n")
9384 {
9385 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9386 int default_originate = DEFAULT_ORIGINATE_ZEBRA;
9387 int type = -1;
9388 int metric = -1;
9389 struct ospf_redist *red;
9390 int idx = 0;
9391 int cur_originate = ospf->default_originate;
9392 bool sameRtmap = false;
9393 char *rtmap = NULL;
9394
9395 red = ospf_redist_add(ospf, DEFAULT_ROUTE, 0);
9396
9397 /* Check whether "always" was specified */
9398 if (argv_find(argv, argc, "always", &idx))
9399 default_originate = DEFAULT_ORIGINATE_ALWAYS;
9400 idx = 1;
9401 /* Get metric value */
9402 if (argv_find(argv, argc, "(0-16777214)", &idx)) {
9403 if (!str2metric(argv[idx]->arg, &metric))
9404 return CMD_WARNING_CONFIG_FAILED;
9405 }
9406 idx = 1;
9407 /* Get metric type. */
9408 if (argv_find(argv, argc, "(1-2)", &idx)) {
9409 if (!str2metric_type(argv[idx]->arg, &type))
9410 return CMD_WARNING_CONFIG_FAILED;
9411 }
9412 idx = 1;
9413 /* Get route-map */
9414 if (argv_find(argv, argc, "route-map", &idx))
9415 rtmap = argv[idx]->arg + 1;
9416
9417 /* To check if user is providing same route map */
9418 if ((!rtmap && !ROUTEMAP_NAME(red)) ||
9419 (rtmap && ROUTEMAP_NAME(red) &&
9420 (strcmp(rtmap, ROUTEMAP_NAME(red)) == 0)))
9421 sameRtmap = true;
9422
9423 /* Don't allow if the same lsa is already originated. */
9424 if ((sameRtmap)
9425 && (red->dmetric.type == type)
9426 && (red->dmetric.value == metric)
9427 && (cur_originate == default_originate))
9428 return CMD_SUCCESS;
9429
9430 /* Updating Metric details */
9431 red->dmetric.type = type;
9432 red->dmetric.value = metric;
9433
9434 /* updating route map details */
9435 if (rtmap)
9436 ospf_routemap_set(red, rtmap);
9437 else
9438 ospf_routemap_unset(red);
9439
9440 return ospf_redistribute_default_set(ospf, default_originate, type,
9441 metric);
9442 }
9443
9444 DEFUN (no_ospf_default_information_originate,
9445 no_ospf_default_information_originate_cmd,
9446 "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9447 NO_STR
9448 "Control distribution of default information\n"
9449 "Distribute a default route\n"
9450 "Always advertise default route\n"
9451 "OSPF default metric\n"
9452 "OSPF metric\n"
9453 "OSPF metric type for default routes\n"
9454 "Set OSPF External Type 1/2 metrics\n"
9455 "Route map reference\n"
9456 "Pointer to route-map entries\n")
9457 {
9458 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9459 struct ospf_redist *red;
9460
9461 red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0);
9462 if (!red)
9463 return CMD_SUCCESS;
9464
9465 ospf_routemap_unset(red);
9466 ospf_redist_del(ospf, DEFAULT_ROUTE, 0);
9467
9468 return ospf_redistribute_default_set(ospf, DEFAULT_ORIGINATE_NONE,
9469 0, 0);
9470 }
9471
9472 DEFUN (ospf_default_metric,
9473 ospf_default_metric_cmd,
9474 "default-metric (0-16777214)",
9475 "Set metric of redistributed routes\n"
9476 "Default metric\n")
9477 {
9478 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9479 int idx_number = 1;
9480 int metric = -1;
9481
9482 if (!str2metric(argv[idx_number]->arg, &metric))
9483 return CMD_WARNING_CONFIG_FAILED;
9484
9485 ospf->default_metric = metric;
9486
9487 return CMD_SUCCESS;
9488 }
9489
9490 DEFUN (no_ospf_default_metric,
9491 no_ospf_default_metric_cmd,
9492 "no default-metric [(0-16777214)]",
9493 NO_STR
9494 "Set metric of redistributed routes\n"
9495 "Default metric\n")
9496 {
9497 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9498
9499 ospf->default_metric = -1;
9500
9501 return CMD_SUCCESS;
9502 }
9503
9504
9505 DEFUN (ospf_distance,
9506 ospf_distance_cmd,
9507 "distance (1-255)",
9508 "Administrative distance\n"
9509 "OSPF Administrative distance\n")
9510 {
9511 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9512 int idx_number = 1;
9513 uint8_t distance;
9514
9515 distance = atoi(argv[idx_number]->arg);
9516 if (ospf->distance_all != distance) {
9517 ospf->distance_all = distance;
9518 ospf_restart_spf(ospf);
9519 }
9520
9521 return CMD_SUCCESS;
9522 }
9523
9524 DEFUN (no_ospf_distance,
9525 no_ospf_distance_cmd,
9526 "no distance (1-255)",
9527 NO_STR
9528 "Administrative distance\n"
9529 "OSPF Administrative distance\n")
9530 {
9531 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9532
9533 if (ospf->distance_all) {
9534 ospf->distance_all = 0;
9535 ospf_restart_spf(ospf);
9536 }
9537
9538 return CMD_SUCCESS;
9539 }
9540
9541 DEFUN (no_ospf_distance_ospf,
9542 no_ospf_distance_ospf_cmd,
9543 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
9544 NO_STR
9545 "Administrative distance\n"
9546 "OSPF administrative distance\n"
9547 "Intra-area routes\n"
9548 "Distance for intra-area routes\n"
9549 "Inter-area routes\n"
9550 "Distance for inter-area routes\n"
9551 "External routes\n"
9552 "Distance for external routes\n")
9553 {
9554 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9555 int idx = 0;
9556
9557 if (argv_find(argv, argc, "intra-area", &idx) || argc == 3)
9558 idx = ospf->distance_intra = 0;
9559 if (argv_find(argv, argc, "inter-area", &idx) || argc == 3)
9560 idx = ospf->distance_inter = 0;
9561 if (argv_find(argv, argc, "external", &idx) || argc == 3)
9562 ospf->distance_external = 0;
9563
9564 return CMD_SUCCESS;
9565 }
9566
9567 DEFUN (ospf_distance_ospf,
9568 ospf_distance_ospf_cmd,
9569 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
9570 "Administrative distance\n"
9571 "OSPF administrative distance\n"
9572 "Intra-area routes\n"
9573 "Distance for intra-area routes\n"
9574 "Inter-area routes\n"
9575 "Distance for inter-area routes\n"
9576 "External routes\n"
9577 "Distance for external routes\n")
9578 {
9579 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9580 int idx = 0;
9581
9582 ospf->distance_intra = 0;
9583 ospf->distance_inter = 0;
9584 ospf->distance_external = 0;
9585
9586 if (argv_find(argv, argc, "intra-area", &idx))
9587 ospf->distance_intra = atoi(argv[idx + 1]->arg);
9588 idx = 0;
9589 if (argv_find(argv, argc, "inter-area", &idx))
9590 ospf->distance_inter = atoi(argv[idx + 1]->arg);
9591 idx = 0;
9592 if (argv_find(argv, argc, "external", &idx))
9593 ospf->distance_external = atoi(argv[idx + 1]->arg);
9594
9595 return CMD_SUCCESS;
9596 }
9597
9598 DEFUN (ip_ospf_mtu_ignore,
9599 ip_ospf_mtu_ignore_addr_cmd,
9600 "ip ospf mtu-ignore [A.B.C.D]",
9601 "IP Information\n"
9602 "OSPF interface commands\n"
9603 "Disable MTU mismatch detection on this interface\n"
9604 "Address of interface\n")
9605 {
9606 VTY_DECLVAR_CONTEXT(interface, ifp);
9607 int idx_ipv4 = 3;
9608 struct in_addr addr;
9609 int ret;
9610
9611 struct ospf_if_params *params;
9612 params = IF_DEF_PARAMS(ifp);
9613
9614 if (argc == 4) {
9615 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
9616 if (!ret) {
9617 vty_out(vty,
9618 "Please specify interface address by A.B.C.D\n");
9619 return CMD_WARNING_CONFIG_FAILED;
9620 }
9621 params = ospf_get_if_params(ifp, addr);
9622 ospf_if_update_params(ifp, addr);
9623 }
9624 params->mtu_ignore = 1;
9625 if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT)
9626 SET_IF_PARAM(params, mtu_ignore);
9627 else {
9628 UNSET_IF_PARAM(params, mtu_ignore);
9629 if (params != IF_DEF_PARAMS(ifp)) {
9630 ospf_free_if_params(ifp, addr);
9631 ospf_if_update_params(ifp, addr);
9632 }
9633 }
9634 return CMD_SUCCESS;
9635 }
9636
9637 DEFUN (no_ip_ospf_mtu_ignore,
9638 no_ip_ospf_mtu_ignore_addr_cmd,
9639 "no ip ospf mtu-ignore [A.B.C.D]",
9640 NO_STR
9641 "IP Information\n"
9642 "OSPF interface commands\n"
9643 "Disable MTU mismatch detection on this interface\n"
9644 "Address of interface\n")
9645 {
9646 VTY_DECLVAR_CONTEXT(interface, ifp);
9647 int idx_ipv4 = 4;
9648 struct in_addr addr;
9649 int ret;
9650
9651 struct ospf_if_params *params;
9652 params = IF_DEF_PARAMS(ifp);
9653
9654 if (argc == 5) {
9655 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
9656 if (!ret) {
9657 vty_out(vty,
9658 "Please specify interface address by A.B.C.D\n");
9659 return CMD_WARNING_CONFIG_FAILED;
9660 }
9661 params = ospf_get_if_params(ifp, addr);
9662 ospf_if_update_params(ifp, addr);
9663 }
9664 params->mtu_ignore = 0;
9665 if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT)
9666 SET_IF_PARAM(params, mtu_ignore);
9667 else {
9668 UNSET_IF_PARAM(params, mtu_ignore);
9669 if (params != IF_DEF_PARAMS(ifp)) {
9670 ospf_free_if_params(ifp, addr);
9671 ospf_if_update_params(ifp, addr);
9672 }
9673 }
9674 return CMD_SUCCESS;
9675 }
9676
9677
9678 DEFUN (ospf_max_metric_router_lsa_admin,
9679 ospf_max_metric_router_lsa_admin_cmd,
9680 "max-metric router-lsa administrative",
9681 "OSPF maximum / infinite-distance metric\n"
9682 "Advertise own Router-LSA with infinite distance (stub router)\n"
9683 "Administratively applied, for an indefinite period\n")
9684 {
9685 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9686 struct listnode *ln;
9687 struct ospf_area *area;
9688
9689 for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
9690 SET_FLAG(area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED);
9691
9692 if (!CHECK_FLAG(area->stub_router_state,
9693 OSPF_AREA_IS_STUB_ROUTED))
9694 ospf_router_lsa_update_area(area);
9695 }
9696
9697 /* Allows for areas configured later to get the property */
9698 ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_SET;
9699
9700 return CMD_SUCCESS;
9701 }
9702
9703 DEFUN (no_ospf_max_metric_router_lsa_admin,
9704 no_ospf_max_metric_router_lsa_admin_cmd,
9705 "no max-metric router-lsa administrative",
9706 NO_STR
9707 "OSPF maximum / infinite-distance metric\n"
9708 "Advertise own Router-LSA with infinite distance (stub router)\n"
9709 "Administratively applied, for an indefinite period\n")
9710 {
9711 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9712 struct listnode *ln;
9713 struct ospf_area *area;
9714
9715 for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
9716 UNSET_FLAG(area->stub_router_state,
9717 OSPF_AREA_ADMIN_STUB_ROUTED);
9718
9719 /* Don't trample on the start-up stub timer */
9720 if (CHECK_FLAG(area->stub_router_state,
9721 OSPF_AREA_IS_STUB_ROUTED)
9722 && !area->t_stub_router) {
9723 UNSET_FLAG(area->stub_router_state,
9724 OSPF_AREA_IS_STUB_ROUTED);
9725 ospf_router_lsa_update_area(area);
9726 }
9727 }
9728 ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET;
9729 return CMD_SUCCESS;
9730 }
9731
9732 DEFUN (ospf_max_metric_router_lsa_startup,
9733 ospf_max_metric_router_lsa_startup_cmd,
9734 "max-metric router-lsa on-startup (5-86400)",
9735 "OSPF maximum / infinite-distance metric\n"
9736 "Advertise own Router-LSA with infinite distance (stub router)\n"
9737 "Automatically advertise stub Router-LSA on startup of OSPF\n"
9738 "Time (seconds) to advertise self as stub-router\n")
9739 {
9740 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9741 int idx_number = 3;
9742 unsigned int seconds;
9743
9744 if (argc < 4) {
9745 vty_out(vty, "%% Must supply stub-router period\n");
9746 return CMD_WARNING_CONFIG_FAILED;
9747 }
9748
9749 seconds = strtoul(argv[idx_number]->arg, NULL, 10);
9750
9751 ospf->stub_router_startup_time = seconds;
9752
9753 return CMD_SUCCESS;
9754 }
9755
9756 DEFUN (no_ospf_max_metric_router_lsa_startup,
9757 no_ospf_max_metric_router_lsa_startup_cmd,
9758 "no max-metric router-lsa on-startup [(5-86400)]",
9759 NO_STR
9760 "OSPF maximum / infinite-distance metric\n"
9761 "Advertise own Router-LSA with infinite distance (stub router)\n"
9762 "Automatically advertise stub Router-LSA on startup of OSPF\n"
9763 "Time (seconds) to advertise self as stub-router\n")
9764 {
9765 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9766 struct listnode *ln;
9767 struct ospf_area *area;
9768
9769 ospf->stub_router_startup_time = OSPF_STUB_ROUTER_UNCONFIGURED;
9770
9771 for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
9772 SET_FLAG(area->stub_router_state,
9773 OSPF_AREA_WAS_START_STUB_ROUTED);
9774 THREAD_OFF(area->t_stub_router);
9775
9776 /* Don't trample on admin stub routed */
9777 if (!CHECK_FLAG(area->stub_router_state,
9778 OSPF_AREA_ADMIN_STUB_ROUTED)) {
9779 UNSET_FLAG(area->stub_router_state,
9780 OSPF_AREA_IS_STUB_ROUTED);
9781 ospf_router_lsa_update_area(area);
9782 }
9783 }
9784 return CMD_SUCCESS;
9785 }
9786
9787
9788 DEFUN (ospf_max_metric_router_lsa_shutdown,
9789 ospf_max_metric_router_lsa_shutdown_cmd,
9790 "max-metric router-lsa on-shutdown (5-100)",
9791 "OSPF maximum / infinite-distance metric\n"
9792 "Advertise own Router-LSA with infinite distance (stub router)\n"
9793 "Advertise stub-router prior to full shutdown of OSPF\n"
9794 "Time (seconds) to wait till full shutdown\n")
9795 {
9796 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9797 int idx_number = 3;
9798 unsigned int seconds;
9799
9800 if (argc < 4) {
9801 vty_out(vty, "%% Must supply stub-router shutdown period\n");
9802 return CMD_WARNING_CONFIG_FAILED;
9803 }
9804
9805 seconds = strtoul(argv[idx_number]->arg, NULL, 10);
9806
9807 ospf->stub_router_shutdown_time = seconds;
9808
9809 return CMD_SUCCESS;
9810 }
9811
9812 DEFUN (no_ospf_max_metric_router_lsa_shutdown,
9813 no_ospf_max_metric_router_lsa_shutdown_cmd,
9814 "no max-metric router-lsa on-shutdown [(5-100)]",
9815 NO_STR
9816 "OSPF maximum / infinite-distance metric\n"
9817 "Advertise own Router-LSA with infinite distance (stub router)\n"
9818 "Advertise stub-router prior to full shutdown of OSPF\n"
9819 "Time (seconds) to wait till full shutdown\n")
9820 {
9821 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9822
9823 ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED;
9824
9825 return CMD_SUCCESS;
9826 }
9827
9828 DEFUN (ospf_proactive_arp,
9829 ospf_proactive_arp_cmd,
9830 "proactive-arp",
9831 "Allow sending ARP requests proactively\n")
9832 {
9833 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9834
9835 ospf->proactive_arp = true;
9836
9837 return CMD_SUCCESS;
9838 }
9839
9840 DEFUN (no_ospf_proactive_arp,
9841 no_ospf_proactive_arp_cmd,
9842 "no proactive-arp",
9843 NO_STR
9844 "Disallow sending ARP requests proactively\n")
9845 {
9846 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9847
9848 ospf->proactive_arp = false;
9849
9850 return CMD_SUCCESS;
9851 }
9852
9853 /* Graceful Restart HELPER Commands */
9854 DEFPY(ospf_gr_helper_enable, ospf_gr_helper_enable_cmd,
9855 "graceful-restart helper enable [A.B.C.D$address]",
9856 "OSPF Graceful Restart\n"
9857 "OSPF GR Helper\n"
9858 "Enable Helper support\n"
9859 "Advertising Router-ID\n")
9860 {
9861 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9862
9863 if (address_str) {
9864 ospf_gr_helper_support_set_per_routerid(ospf, &address,
9865 OSPF_GR_TRUE);
9866 return CMD_SUCCESS;
9867 }
9868
9869 ospf_gr_helper_support_set(ospf, OSPF_GR_TRUE);
9870
9871 return CMD_SUCCESS;
9872 }
9873
9874 DEFPY(no_ospf_gr_helper_enable,
9875 no_ospf_gr_helper_enable_cmd,
9876 "no graceful-restart helper enable [A.B.C.D$address]",
9877 NO_STR
9878 "OSPF Graceful Restart\n"
9879 "OSPF GR Helper\n"
9880 "Enable Helper support\n"
9881 "Advertising Router-ID\n")
9882 {
9883 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9884
9885 if (address_str) {
9886 ospf_gr_helper_support_set_per_routerid(ospf, &address,
9887 OSPF_GR_FALSE);
9888 return CMD_SUCCESS;
9889 }
9890
9891 ospf_gr_helper_support_set(ospf, OSPF_GR_FALSE);
9892 return CMD_SUCCESS;
9893 }
9894
9895 #if CONFDATE > 20220921
9896 CPP_NOTICE(
9897 "Time to remove the deprecated \"[no] graceful-restart helper-only\" commands")
9898 #endif
9899
9900 DEFPY_HIDDEN(ospf_gr_helper_only, ospf_gr_helper_only_cmd,
9901 "graceful-restart helper-only [A.B.C.D]",
9902 "OSPF Graceful Restart\n"
9903 "Enable Helper support\n"
9904 "Advertising router id\n")
9905 {
9906 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9907 struct in_addr addr;
9908 int ret;
9909
9910 vty_out(vty,
9911 "%% This command is deprecated. Please, use `graceful-restart helper enable` instead.\n");
9912
9913 if (argc == 3) {
9914 ret = inet_aton(argv[2]->arg, &addr);
9915 if (!ret) {
9916 vty_out(vty,
9917 "Please specify the valid routerid address.\n");
9918 return CMD_WARNING_CONFIG_FAILED;
9919 }
9920
9921 ospf_gr_helper_support_set_per_routerid(ospf, &addr, OSPF_GR_TRUE);
9922 return CMD_SUCCESS;
9923 }
9924
9925 ospf_gr_helper_support_set(ospf, OSPF_GR_TRUE);
9926
9927 return CMD_SUCCESS;
9928 }
9929
9930 ALIAS_HIDDEN(no_ospf_gr_helper_enable,
9931 no_ospf_gr_helper_only_cmd,
9932 "no graceful-restart helper-only [A.B.C.D]",
9933 NO_STR
9934 "OSPF Graceful Restart\n"
9935 "Disable Helper support\n"
9936 "Advertising router id\n")
9937
9938 DEFPY(ospf_gr_helper_enable_lsacheck,
9939 ospf_gr_helper_enable_lsacheck_cmd,
9940 "graceful-restart helper strict-lsa-checking",
9941 "OSPF Graceful Restart\n"
9942 "OSPF GR Helper\n"
9943 "Enable strict LSA check\n")
9944 {
9945 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9946
9947 ospf_gr_helper_lsa_check_set(ospf, OSPF_GR_TRUE);
9948 return CMD_SUCCESS;
9949 }
9950
9951 DEFPY(no_ospf_gr_helper_enable_lsacheck,
9952 no_ospf_gr_helper_enable_lsacheck_cmd,
9953 "no graceful-restart helper strict-lsa-checking",
9954 NO_STR
9955 "OSPF Graceful Restart\n"
9956 "OSPF GR Helper\n"
9957 "Disable strict LSA check\n")
9958 {
9959 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9960
9961 ospf_gr_helper_lsa_check_set(ospf, OSPF_GR_FALSE);
9962 return CMD_SUCCESS;
9963 }
9964
9965 DEFPY(ospf_gr_helper_supported_grace_time,
9966 ospf_gr_helper_supported_grace_time_cmd,
9967 "graceful-restart helper supported-grace-time (10-1800)$interval",
9968 "OSPF Graceful Restart\n"
9969 "OSPF GR Helper\n"
9970 "Supported grace timer\n"
9971 "Grace interval(in seconds)\n")
9972 {
9973 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9974
9975 ospf_gr_helper_supported_gracetime_set(ospf, interval);
9976 return CMD_SUCCESS;
9977 }
9978
9979 DEFPY(no_ospf_gr_helper_supported_grace_time,
9980 no_ospf_gr_helper_supported_grace_time_cmd,
9981 "no graceful-restart helper supported-grace-time (10-1800)$interval",
9982 NO_STR
9983 "OSPF Graceful Restart\n"
9984 "OSPF GR Helper\n"
9985 "Supported grace timer\n"
9986 "Grace interval(in seconds)\n")
9987 {
9988 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9989
9990 ospf_gr_helper_supported_gracetime_set(ospf, OSPF_MAX_GRACE_INTERVAL);
9991 return CMD_SUCCESS;
9992 }
9993
9994 DEFPY(ospf_gr_helper_planned_only,
9995 ospf_gr_helper_planned_only_cmd,
9996 "graceful-restart helper planned-only",
9997 "OSPF Graceful Restart\n"
9998 "OSPF GR Helper\n"
9999 "Supported only planned restart\n")
10000 {
10001 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10002
10003 ospf_gr_helper_set_supported_planned_only_restart(ospf, OSPF_GR_TRUE);
10004
10005 return CMD_SUCCESS;
10006 }
10007
10008 /* External Route Aggregation */
10009 DEFUN (ospf_external_route_aggregation,
10010 ospf_external_route_aggregation_cmd,
10011 "summary-address A.B.C.D/M [tag (1-4294967295)]",
10012 "External summary address\n"
10013 "Summary address prefix\n"
10014 "Router tag \n"
10015 "Router tag value\n")
10016 {
10017 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10018 struct prefix_ipv4 p;
10019 int idx = 1;
10020 route_tag_t tag = 0;
10021 int ret = OSPF_SUCCESS;
10022
10023 str2prefix_ipv4(argv[idx]->arg, &p);
10024
10025 if (is_default_prefix4(&p)) {
10026 vty_out(vty,
10027 "Default address shouldn't be configured as summary address.\n");
10028 return CMD_SUCCESS;
10029 }
10030
10031 /* Apply mask for given prefix. */
10032 apply_mask(&p);
10033
10034 if (!is_valid_summary_addr(&p)) {
10035 vty_out(vty, "Not a valid summary address.\n");
10036 return CMD_WARNING_CONFIG_FAILED;
10037 }
10038
10039 if (argc > 2)
10040 tag = strtoul(argv[idx + 2]->arg, NULL, 10);
10041
10042 ret = ospf_asbr_external_aggregator_set(ospf, &p, tag);
10043 if (ret == OSPF_INVALID)
10044 vty_out(vty, "Invalid configuration!!\n");
10045
10046 return CMD_SUCCESS;
10047 }
10048
10049 DEFUN (no_ospf_external_route_aggregation,
10050 no_ospf_external_route_aggregation_cmd,
10051 "no summary-address A.B.C.D/M [tag (1-4294967295)]",
10052 NO_STR
10053 "External summary address\n"
10054 "Summary address prefix\n"
10055 "Router tag\n"
10056 "Router tag value\n")
10057 {
10058 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10059 struct prefix_ipv4 p;
10060 int idx = 2;
10061 route_tag_t tag = 0;
10062 int ret = OSPF_SUCCESS;
10063
10064 str2prefix_ipv4(argv[idx]->arg, &p);
10065
10066 if (is_default_prefix4(&p)) {
10067 vty_out(vty,
10068 "Default address shouldn't be configured as summary address.\n");
10069 return CMD_SUCCESS;
10070 }
10071
10072 /* Apply mask for given prefix. */
10073 apply_mask(&p);
10074
10075 if (!is_valid_summary_addr(&p)) {
10076 vty_out(vty, "Not a valid summary address.\n");
10077 return CMD_WARNING_CONFIG_FAILED;
10078 }
10079
10080 if (argc > 3)
10081 tag = strtoul(argv[idx + 2]->arg, NULL, 10);
10082
10083 ret = ospf_asbr_external_aggregator_unset(ospf, &p, tag);
10084 if (ret == OSPF_INVALID)
10085 vty_out(vty, "Invalid configuration!!\n");
10086
10087 return CMD_SUCCESS;
10088 }
10089
10090 DEFPY(no_ospf_gr_helper_planned_only,
10091 no_ospf_gr_helper_planned_only_cmd,
10092 "no graceful-restart helper planned-only",
10093 NO_STR
10094 "OSPF Graceful Restart\n"
10095 "OSPF GR Helper\n"
10096 "Supported only for planned restart\n")
10097 {
10098 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10099
10100 ospf_gr_helper_set_supported_planned_only_restart(ospf, OSPF_GR_FALSE);
10101
10102 return CMD_SUCCESS;
10103 }
10104
10105 static int ospf_print_vty_helper_dis_rtr_walkcb(struct hash_bucket *bucket,
10106 void *arg)
10107 {
10108 struct advRtr *rtr = bucket->data;
10109 struct vty *vty = (struct vty *)arg;
10110 static unsigned int count;
10111
10112 vty_out(vty, "%-6pI4,", &rtr->advRtrAddr);
10113 count++;
10114
10115 if (count % 5 == 0)
10116 vty_out(vty, "\n");
10117
10118 return HASHWALK_CONTINUE;
10119 }
10120
10121 static int ospf_show_gr_helper_details(struct vty *vty, struct ospf *ospf,
10122 uint8_t use_vrf, json_object *json,
10123 bool uj, bool detail)
10124 {
10125 struct listnode *node;
10126 struct ospf_interface *oi;
10127 char buf[PREFIX_STRLEN];
10128 json_object *json_vrf = NULL;
10129
10130 if (uj) {
10131 if (use_vrf)
10132 json_vrf = json_object_new_object();
10133 else
10134 json_vrf = json;
10135 }
10136
10137 if (ospf->instance) {
10138 if (uj)
10139 json_object_int_add(json, "ospfInstance",
10140 ospf->instance);
10141 else
10142 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
10143 }
10144
10145 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
10146
10147 if (uj) {
10148 if (use_vrf)
10149 json_object_object_add(json, ospf_get_name(ospf),
10150 json_vrf);
10151 } else
10152 vty_out(vty, "\n");
10153
10154 /* Show Router ID. */
10155 if (uj) {
10156 json_object_string_add(json_vrf, "routerId",
10157 inet_ntop(AF_INET, &ospf->router_id,
10158 buf, sizeof(buf)));
10159 } else {
10160 vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n",
10161 &ospf->router_id);
10162 }
10163
10164 if (!uj) {
10165
10166 if (ospf->is_helper_supported)
10167 vty_out(vty,
10168 " Graceful restart helper support enabled.\n");
10169 else
10170 vty_out(vty,
10171 " Graceful restart helper support disabled.\n");
10172
10173 if (ospf->strict_lsa_check)
10174 vty_out(vty, " Strict LSA check is enabled.\n");
10175 else
10176 vty_out(vty, " Strict LSA check is disabled.\n");
10177
10178 if (ospf->only_planned_restart)
10179 vty_out(vty,
10180 " Helper supported for planned restarts only.\n");
10181 else
10182 vty_out(vty,
10183 " Helper supported for Planned and Unplanned Restarts.\n");
10184
10185 vty_out(vty,
10186 " Supported Graceful restart interval: %d(in seconds).\n",
10187 ospf->supported_grace_time);
10188
10189 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf)) {
10190 vty_out(vty, " Enable Router list:\n");
10191 vty_out(vty, " ");
10192 hash_walk(ospf->enable_rtr_list,
10193 ospf_print_vty_helper_dis_rtr_walkcb, vty);
10194 vty_out(vty, "\n\n");
10195 }
10196
10197 if (ospf->last_exit_reason != OSPF_GR_HELPER_EXIT_NONE) {
10198 vty_out(vty, " Last Helper exit Reason :%s\n",
10199 ospf_exit_reason2str(ospf->last_exit_reason));
10200 }
10201
10202 if (ospf->active_restarter_cnt)
10203 vty_out(vty,
10204 " Number of Active neighbours in graceful restart: %d\n",
10205 ospf->active_restarter_cnt);
10206 else
10207 vty_out(vty, "\n");
10208
10209 } else {
10210 json_object_string_add(
10211 json_vrf, "helperSupport",
10212 (ospf->is_helper_supported) ? "Enabled" : "Disabled");
10213 json_object_string_add(json_vrf, "strictLsaCheck",
10214 (ospf->strict_lsa_check) ? "Enabled"
10215 : "Disabled");
10216 json_object_string_add(
10217 json_vrf, "restartSupoort",
10218 (ospf->only_planned_restart)
10219 ? "Planned Restart only"
10220 : "Planned and Unplanned Restarts");
10221
10222 json_object_int_add(json_vrf, "supportedGracePeriod",
10223 ospf->supported_grace_time);
10224
10225 #if CONFDATE > 20230131
10226 CPP_NOTICE("Remove JSON object commands with keys starting with capital")
10227 #endif
10228 if (ospf->last_exit_reason != OSPF_GR_HELPER_EXIT_NONE) {
10229 json_object_string_add(
10230 json_vrf, "LastExitReason",
10231 ospf_exit_reason2str(ospf->last_exit_reason));
10232 json_object_string_add(
10233 json_vrf, "lastExitReason",
10234 ospf_exit_reason2str(ospf->last_exit_reason));
10235 }
10236
10237 if (ospf->active_restarter_cnt)
10238 json_object_int_add(json_vrf, "activeRestarterCnt",
10239 ospf->active_restarter_cnt);
10240 }
10241
10242
10243 if (detail) {
10244 int cnt = 1;
10245 json_object *json_neighbors = NULL;
10246
10247 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
10248 struct route_node *rn;
10249 struct ospf_neighbor *nbr;
10250 json_object *json_neigh;
10251
10252 if (ospf_interface_neighbor_count(oi) == 0)
10253 continue;
10254
10255 if (uj) {
10256 json_object_object_get_ex(json_vrf, "Neighbors",
10257 &json_neighbors);
10258 json_object_object_get_ex(json_vrf, "neighbors",
10259 &json_neighbors);
10260 if (!json_neighbors) {
10261 json_neighbors =
10262 json_object_new_object();
10263 json_object_object_add(json_vrf,
10264 "Neighbors",
10265 json_neighbors);
10266 json_object_object_add(json_vrf,
10267 "neighbors",
10268 json_neighbors);
10269 }
10270 }
10271
10272 for (rn = route_top(oi->nbrs); rn;
10273 rn = route_next(rn)) {
10274
10275 if (!rn->info)
10276 continue;
10277
10278 nbr = rn->info;
10279
10280 if (!OSPF_GR_IS_ACTIVE_HELPER(nbr))
10281 continue;
10282
10283 if (!uj) {
10284 vty_out(vty, " Neighbour %d :\n", cnt);
10285 vty_out(vty, " Address : %pI4\n",
10286 &nbr->address.u.prefix4);
10287 vty_out(vty, " Routerid : %pI4\n",
10288 &nbr->router_id);
10289 vty_out(vty,
10290 " Received Grace period : %d(in seconds).\n",
10291 nbr->gr_helper_info
10292 .recvd_grace_period);
10293 vty_out(vty,
10294 " Actual Grace period : %d(in seconds)\n",
10295 nbr->gr_helper_info
10296 .actual_grace_period);
10297 vty_out(vty,
10298 " Remaining GraceTime:%ld(in seconds).\n",
10299 thread_timer_remain_second(
10300 nbr->gr_helper_info
10301 .t_grace_timer));
10302 vty_out(vty,
10303 " Graceful Restart reason: %s.\n\n",
10304 ospf_restart_reason2str(
10305 nbr->gr_helper_info
10306 .gr_restart_reason));
10307 cnt++;
10308 } else {
10309 json_neigh = json_object_new_object();
10310 json_object_string_add(
10311 json_neigh, "srcAddr",
10312 inet_ntop(AF_INET, &nbr->src,
10313 buf, sizeof(buf)));
10314
10315 json_object_string_add(
10316 json_neigh, "routerid",
10317 inet_ntop(AF_INET,
10318 &nbr->router_id,
10319 buf, sizeof(buf)));
10320 json_object_int_add(
10321 json_neigh,
10322 "recvdGraceInterval",
10323 nbr->gr_helper_info
10324 .recvd_grace_period);
10325 json_object_int_add(
10326 json_neigh,
10327 "actualGraceInterval",
10328 nbr->gr_helper_info
10329 .actual_grace_period);
10330 json_object_int_add(
10331 json_neigh, "remainGracetime",
10332 thread_timer_remain_second(
10333 nbr->gr_helper_info
10334 .t_grace_timer));
10335 json_object_string_add(
10336 json_neigh, "restartReason",
10337 ospf_restart_reason2str(
10338 nbr->gr_helper_info
10339 .gr_restart_reason));
10340 json_object_object_add(
10341 json_neighbors,
10342 inet_ntop(AF_INET, &nbr->src,
10343 buf, sizeof(buf)),
10344 json_neigh);
10345 }
10346 }
10347 }
10348 }
10349 return CMD_SUCCESS;
10350 }
10351
10352 DEFUN (ospf_external_route_aggregation_no_adrvertise,
10353 ospf_external_route_aggregation_no_adrvertise_cmd,
10354 "summary-address A.B.C.D/M no-advertise",
10355 "External summary address\n"
10356 "Summary address prefix\n"
10357 "Don't advertise summary route \n")
10358 {
10359 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10360 struct prefix_ipv4 p;
10361 int idx = 1;
10362 int ret = OSPF_SUCCESS;
10363
10364 str2prefix_ipv4(argv[idx]->arg, &p);
10365
10366 if (is_default_prefix4(&p)) {
10367 vty_out(vty,
10368 "Default address shouldn't be configured as summary address.\n");
10369 return CMD_SUCCESS;
10370 }
10371
10372 /* Apply mask for given prefix. */
10373 apply_mask(&p);
10374
10375 if (!is_valid_summary_addr(&p)) {
10376 vty_out(vty, "Not a valid summary address.\n");
10377 return CMD_WARNING_CONFIG_FAILED;
10378 }
10379
10380 ret = ospf_asbr_external_rt_no_advertise(ospf, &p);
10381 if (ret == OSPF_INVALID)
10382 vty_out(vty, "Invalid configuration!!\n");
10383
10384 return CMD_SUCCESS;
10385 }
10386
10387 DEFUN (no_ospf_external_route_aggregation_no_adrvertise,
10388 no_ospf_external_route_aggregation_no_adrvertise_cmd,
10389 "no summary-address A.B.C.D/M no-advertise",
10390 NO_STR
10391 "External summary address\n"
10392 "Summary address prefix\n"
10393 "Advertise summary route to the AS \n")
10394 {
10395 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10396 struct prefix_ipv4 p;
10397 int idx = 2;
10398 int ret = OSPF_SUCCESS;
10399
10400 str2prefix_ipv4(argv[idx]->arg, &p);
10401
10402 if (is_default_prefix4(&p)) {
10403 vty_out(vty,
10404 "Default address shouldn't be configured as summary address.\n");
10405 return CMD_SUCCESS;
10406 }
10407
10408 /* Apply mask for given prefix. */
10409 apply_mask(&p);
10410
10411 if (!is_valid_summary_addr(&p)) {
10412 vty_out(vty, "Not a valid summary address.\n");
10413 return CMD_WARNING_CONFIG_FAILED;
10414 }
10415
10416 ret = ospf_asbr_external_rt_advertise(ospf, &p);
10417 if (ret == OSPF_INVALID)
10418 vty_out(vty, "Invalid configuration!!\n");
10419
10420 return CMD_SUCCESS;
10421 }
10422
10423 DEFUN (ospf_route_aggregation_timer,
10424 ospf_route_aggregation_timer_cmd,
10425 "aggregation timer (5-1800)",
10426 "External route aggregation\n"
10427 "Delay timer (in seconds)\n"
10428 "Timer interval(in seconds)\n")
10429 {
10430 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10431 uint16_t interval = 0;
10432
10433 interval = strtoul(argv[2]->arg, NULL, 10);
10434
10435 ospf_external_aggregator_timer_set(ospf, interval);
10436
10437 return CMD_SUCCESS;
10438 }
10439
10440 DEFPY (show_ip_ospf_gr_helper,
10441 show_ip_ospf_gr_helper_cmd,
10442 "show ip ospf [vrf <NAME|all>] graceful-restart helper [detail] [json]",
10443 SHOW_STR
10444 IP_STR
10445 "OSPF information\n"
10446 VRF_CMD_HELP_STR
10447 "All VRFs\n"
10448 "OSPF Graceful Restart\n"
10449 "Helper details in the router\n"
10450 "Detailed information\n"
10451 JSON_STR)
10452 {
10453 char *vrf_name = NULL;
10454 bool all_vrf = false;
10455 int ret = CMD_SUCCESS;
10456 int idx_vrf = 0;
10457 int idx = 0;
10458 uint8_t use_vrf = 0;
10459 bool uj = use_json(argc, argv);
10460 struct ospf *ospf = NULL;
10461 json_object *json = NULL;
10462 struct listnode *node = NULL;
10463 int inst = 0;
10464 bool detail = false;
10465
10466 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
10467
10468 if (argv_find(argv, argc, "detail", &idx))
10469 detail = true;
10470
10471 if (uj)
10472 json = json_object_new_object();
10473
10474 /* vrf input is provided */
10475 if (vrf_name) {
10476 use_vrf = 1;
10477
10478 if (all_vrf) {
10479 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
10480 if (!ospf->oi_running)
10481 continue;
10482
10483 ret = ospf_show_gr_helper_details(
10484 vty, ospf, use_vrf, json, uj, detail);
10485 }
10486
10487 if (uj)
10488 vty_json(vty, json);
10489
10490 return ret;
10491 }
10492
10493 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
10494
10495 if (ospf == NULL || !ospf->oi_running) {
10496
10497 if (uj)
10498 vty_json(vty, json);
10499 else
10500 vty_out(vty,
10501 "%% OSPF is not enabled in vrf %s\n",
10502 vrf_name);
10503
10504 return CMD_SUCCESS;
10505 }
10506
10507 } else {
10508 /* Default Vrf */
10509 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
10510
10511 if (ospf == NULL || !ospf->oi_running) {
10512
10513 if (uj)
10514 vty_json(vty, json);
10515 else
10516 vty_out(vty,
10517 "%% OSPF is not enabled in vrf default\n");
10518
10519 return CMD_SUCCESS;
10520 }
10521
10522 ospf_show_gr_helper_details(vty, ospf, use_vrf, json, uj,
10523 detail);
10524 }
10525
10526 if (uj)
10527 vty_json(vty, json);
10528
10529 return CMD_SUCCESS;
10530 }
10531 /* Graceful Restart HELPER commands end */
10532 DEFUN (no_ospf_route_aggregation_timer,
10533 no_ospf_route_aggregation_timer_cmd,
10534 "no aggregation timer",
10535 NO_STR
10536 "External route aggregation\n"
10537 "Delay timer\n")
10538 {
10539 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10540
10541 ospf_external_aggregator_timer_set(ospf, OSPF_EXTL_AGGR_DEFAULT_DELAY);
10542
10543 return CMD_SUCCESS;
10544 }
10545
10546 /* External Route Aggregation End */
10547
10548 static void config_write_stub_router(struct vty *vty, struct ospf *ospf)
10549 {
10550 struct listnode *ln;
10551 struct ospf_area *area;
10552
10553 if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED)
10554 vty_out(vty, " max-metric router-lsa on-startup %u\n",
10555 ospf->stub_router_startup_time);
10556 if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED)
10557 vty_out(vty, " max-metric router-lsa on-shutdown %u\n",
10558 ospf->stub_router_shutdown_time);
10559 for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
10560 if (CHECK_FLAG(area->stub_router_state,
10561 OSPF_AREA_ADMIN_STUB_ROUTED)) {
10562 vty_out(vty, " max-metric router-lsa administrative\n");
10563 break;
10564 }
10565 }
10566 return;
10567 }
10568
10569 #if CONFDATE > 20230131
10570 CPP_NOTICE("Remove JSON object commands with keys containing whitespaces")
10571 #endif
10572 static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf,
10573 struct route_table *rt,
10574 json_object *json)
10575 {
10576 struct route_node *rn;
10577 struct ospf_route * or ;
10578 struct listnode *pnode, *pnnode;
10579 struct ospf_path *path;
10580 json_object *json_route = NULL, *json_nexthop_array = NULL,
10581 *json_nexthop = NULL;
10582
10583 if (!json)
10584 vty_out(vty,
10585 "============ OSPF network routing table ============\n");
10586
10587 for (rn = route_top(rt); rn; rn = route_next(rn)) {
10588 char buf1[PREFIX2STR_BUFFER];
10589
10590 if ((or = rn->info) == NULL)
10591 continue;
10592
10593 prefix2str(&rn->p, buf1, sizeof(buf1));
10594
10595 if (json) {
10596 json_route = json_object_new_object();
10597 json_object_object_add(json, buf1, json_route);
10598 }
10599
10600 switch (or->path_type) {
10601 case OSPF_PATH_INTER_AREA:
10602 if (or->type == OSPF_DESTINATION_NETWORK) {
10603 if (json) {
10604 json_object_string_add(json_route,
10605 "routeType",
10606 "N IA");
10607 json_object_int_add(json_route, "cost",
10608 or->cost);
10609 json_object_string_addf(
10610 json_route, "area", "%pI4",
10611 &or->u.std.area_id);
10612 } else {
10613 vty_out(vty,
10614 "N IA %-18s [%d] area: %pI4\n",
10615 buf1, or->cost,
10616 &or->u.std.area_id);
10617 }
10618 } else if (or->type == OSPF_DESTINATION_DISCARD) {
10619 if (json) {
10620 json_object_string_add(json_route,
10621 "routeType",
10622 "D IA");
10623 } else {
10624 vty_out(vty,
10625 "D IA %-18s Discard entry\n",
10626 buf1);
10627 }
10628 }
10629 break;
10630 case OSPF_PATH_INTRA_AREA:
10631 if (json) {
10632 json_object_string_add(json_route, "routeType",
10633 "N");
10634 json_object_int_add(json_route, "cost",
10635 or->cost);
10636 json_object_string_addf(json_route, "area",
10637 "%pI4",
10638 &or->u.std.area_id);
10639 } else {
10640 vty_out(vty, "N %-18s [%d] area: %pI4\n",
10641 buf1, or->cost,
10642 &or->u.std.area_id);
10643 }
10644 break;
10645 default:
10646 break;
10647 }
10648
10649 if (or->type == OSPF_DESTINATION_NETWORK) {
10650 if (json) {
10651 json_nexthop_array = json_object_new_array();
10652 json_object_object_add(json_route, "nexthops",
10653 json_nexthop_array);
10654 }
10655
10656 for (ALL_LIST_ELEMENTS(or->paths, pnode, pnnode,
10657 path)) {
10658 if (json) {
10659 json_nexthop = json_object_new_object();
10660 json_object_array_add(
10661 json_nexthop_array,
10662 json_nexthop);
10663 }
10664 if (if_lookup_by_index(path->ifindex,
10665 ospf->vrf_id)) {
10666
10667 if (path->nexthop.s_addr
10668 == INADDR_ANY) {
10669 if (json) {
10670 json_object_string_add(
10671 json_nexthop,
10672 "ip", " ");
10673 json_object_string_add(
10674 json_nexthop,
10675 "directly attached to",
10676 ifindex2ifname(
10677 path->ifindex,
10678 ospf->vrf_id));
10679 json_object_string_add(
10680 json_nexthop,
10681 "directlyAttachedTo",
10682 ifindex2ifname(
10683 path->ifindex,
10684 ospf->vrf_id));
10685 } else {
10686 vty_out(vty,
10687 "%24s directly attached to %s\n",
10688 "",
10689 ifindex2ifname(
10690 path->ifindex,
10691 ospf->vrf_id));
10692 }
10693 } else {
10694 if (json) {
10695 json_object_string_addf(
10696 json_nexthop,
10697 "ip", "%pI4",
10698 &path->nexthop);
10699 json_object_string_add(
10700 json_nexthop,
10701 "via",
10702 ifindex2ifname(
10703 path->ifindex,
10704 ospf->vrf_id));
10705 } else {
10706 vty_out(vty,
10707 "%24s via %pI4, %s\n",
10708 "",
10709 &path->nexthop,
10710 ifindex2ifname(
10711 path->ifindex,
10712 ospf->vrf_id));
10713 }
10714 }
10715 }
10716 }
10717 }
10718 }
10719 if (!json)
10720 vty_out(vty, "\n");
10721 }
10722
10723 static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf,
10724 struct route_table *rtrs,
10725 json_object *json)
10726 {
10727 struct route_node *rn;
10728 struct ospf_route * or ;
10729 struct listnode *pnode;
10730 struct listnode *node;
10731 struct ospf_path *path;
10732 char buf[PREFIX_STRLEN];
10733 json_object *json_route = NULL, *json_nexthop_array = NULL,
10734 *json_nexthop = NULL;
10735
10736 if (!json)
10737 vty_out(vty, "============ OSPF %s table =============\n",
10738 ospf->all_rtrs == rtrs ? "reachable routers"
10739 : "router routing");
10740
10741 for (rn = route_top(rtrs); rn; rn = route_next(rn)) {
10742 if (rn->info == NULL)
10743 continue;
10744 int flag = 0;
10745
10746 if (json) {
10747 json_route = json_object_new_object();
10748 json_object_object_add(
10749 json, inet_ntop(AF_INET, &rn->p.u.prefix4,
10750 buf, sizeof(buf)),
10751 json_route);
10752 json_object_string_add(json_route, "routeType", "R ");
10753 } else {
10754 vty_out(vty, "R %-15pI4 ",
10755 &rn->p.u.prefix4);
10756 }
10757
10758 for (ALL_LIST_ELEMENTS_RO((struct list *)rn->info, node, or)) {
10759 if (flag++) {
10760 if (!json)
10761 vty_out(vty, "%24s", "");
10762 }
10763
10764 /* Show path. */
10765 if (json) {
10766 json_object_int_add(json_route, "cost",
10767 or->cost);
10768 json_object_string_addf(json_route, "area",
10769 "%pI4",
10770 &or->u.std.area_id);
10771 if (or->path_type == OSPF_PATH_INTER_AREA) {
10772 json_object_boolean_true_add(json_route,
10773 "IA");
10774 json_object_boolean_true_add(json_route,
10775 "ia");
10776 }
10777 if (or->u.std.flags & ROUTER_LSA_BORDER)
10778 json_object_string_add(json_route,
10779 "routerType",
10780 "abr");
10781 else if (or->u.std.flags & ROUTER_LSA_EXTERNAL)
10782 json_object_string_add(json_route,
10783 "routerType",
10784 "asbr");
10785 } else {
10786 vty_out(vty, "%s [%d] area: %pI4",
10787 (or->path_type == OSPF_PATH_INTER_AREA
10788 ? "IA"
10789 : " "),
10790 or->cost, &or->u.std.area_id);
10791 /* Show flags. */
10792 vty_out(vty, "%s%s\n",
10793 (or->u.std.flags & ROUTER_LSA_BORDER
10794 ? ", ABR"
10795 : ""),
10796 (or->u.std.flags & ROUTER_LSA_EXTERNAL
10797 ? ", ASBR"
10798 : ""));
10799 }
10800
10801 if (json) {
10802 json_nexthop_array = json_object_new_array();
10803 json_object_object_add(json_route, "nexthops",
10804 json_nexthop_array);
10805 }
10806
10807 for (ALL_LIST_ELEMENTS_RO(or->paths, pnode, path)) {
10808 if (json) {
10809 json_nexthop = json_object_new_object();
10810 json_object_array_add(
10811 json_nexthop_array,
10812 json_nexthop);
10813 }
10814 if (if_lookup_by_index(path->ifindex,
10815 ospf->vrf_id)) {
10816 if (path->nexthop.s_addr
10817 == INADDR_ANY) {
10818 if (json) {
10819 json_object_string_add(
10820 json_nexthop,
10821 "ip", " ");
10822 json_object_string_add(
10823 json_nexthop,
10824 "directly attached to",
10825 ifindex2ifname(
10826 path->ifindex,
10827 ospf->vrf_id));
10828 json_object_string_add(
10829 json_nexthop,
10830 "directlyAttachedTo",
10831 ifindex2ifname(
10832 path->ifindex,
10833 ospf->vrf_id));
10834 } else {
10835 vty_out(vty,
10836 "%24s directly attached to %s\n",
10837 "",
10838 ifindex2ifname(
10839 path->ifindex,
10840 ospf->vrf_id));
10841 }
10842 } else {
10843 if (json) {
10844 json_object_string_addf(
10845 json_nexthop,
10846 "ip", "%pI4",
10847 &path->nexthop);
10848 json_object_string_add(
10849 json_nexthop,
10850 "via",
10851 ifindex2ifname(
10852 path->ifindex,
10853 ospf->vrf_id));
10854 } else {
10855 vty_out(vty,
10856 "%24s via %pI4, %s\n",
10857 "",
10858 &path->nexthop,
10859 ifindex2ifname(
10860 path->ifindex,
10861 ospf->vrf_id));
10862 }
10863 }
10864 }
10865 }
10866 }
10867 }
10868 if (!json)
10869 vty_out(vty, "\n");
10870 }
10871
10872 static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf,
10873 struct route_table *rt,
10874 json_object *json)
10875 {
10876 struct route_node *rn;
10877 struct ospf_route *er;
10878 struct listnode *pnode, *pnnode;
10879 struct ospf_path *path;
10880 json_object *json_route = NULL, *json_nexthop_array = NULL,
10881 *json_nexthop = NULL;
10882
10883 if (!json)
10884 vty_out(vty,
10885 "============ OSPF external routing table ===========\n");
10886
10887 for (rn = route_top(rt); rn; rn = route_next(rn)) {
10888 if ((er = rn->info) == NULL)
10889 continue;
10890
10891 char buf1[19];
10892
10893 snprintfrr(buf1, sizeof(buf1), "%pFX", &rn->p);
10894 if (json) {
10895 json_route = json_object_new_object();
10896 json_object_object_add(json, buf1, json_route);
10897 }
10898
10899 switch (er->path_type) {
10900 case OSPF_PATH_TYPE1_EXTERNAL:
10901 if (json) {
10902 json_object_string_add(json_route, "routeType",
10903 "N E1");
10904 json_object_int_add(json_route, "cost",
10905 er->cost);
10906 json_object_int_add(json_route, "tag",
10907 er->u.ext.tag);
10908 } else {
10909 vty_out(vty,
10910 "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI
10911 "\n",
10912 buf1, er->cost, er->u.ext.tag);
10913 }
10914 break;
10915 case OSPF_PATH_TYPE2_EXTERNAL:
10916 if (json) {
10917 json_object_string_add(json_route, "routeType",
10918 "N E2");
10919 json_object_int_add(json_route, "cost",
10920 er->cost);
10921 json_object_int_add(json_route, "type2cost",
10922 er->u.ext.type2_cost);
10923 json_object_int_add(json_route, "tag",
10924 er->u.ext.tag);
10925 } else {
10926 vty_out(vty,
10927 "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI
10928 "\n",
10929 buf1, er->cost, er->u.ext.type2_cost,
10930 er->u.ext.tag);
10931 }
10932 break;
10933 }
10934
10935 if (json) {
10936 json_nexthop_array = json_object_new_array();
10937 json_object_object_add(json_route, "nexthops",
10938 json_nexthop_array);
10939 }
10940
10941 for (ALL_LIST_ELEMENTS(er->paths, pnode, pnnode, path)) {
10942 if (json) {
10943 json_nexthop = json_object_new_object();
10944 json_object_array_add(json_nexthop_array,
10945 json_nexthop);
10946 }
10947
10948 if (if_lookup_by_index(path->ifindex, ospf->vrf_id)) {
10949 if (path->nexthop.s_addr == INADDR_ANY) {
10950 if (json) {
10951 json_object_string_add(
10952 json_nexthop, "ip",
10953 " ");
10954 json_object_string_add(
10955 json_nexthop,
10956 "directly attached to",
10957 ifindex2ifname(
10958 path->ifindex,
10959 ospf->vrf_id));
10960 json_object_string_add(
10961 json_nexthop,
10962 "directlyAttachedTo",
10963 ifindex2ifname(
10964 path->ifindex,
10965 ospf->vrf_id));
10966 } else {
10967 vty_out(vty,
10968 "%24s directly attached to %s\n",
10969 "",
10970 ifindex2ifname(
10971 path->ifindex,
10972 ospf->vrf_id));
10973 }
10974 } else {
10975 if (json) {
10976 json_object_string_addf(
10977 json_nexthop, "ip",
10978 "%pI4", &path->nexthop);
10979 json_object_string_add(
10980 json_nexthop, "via",
10981 ifindex2ifname(
10982 path->ifindex,
10983 ospf->vrf_id));
10984 } else {
10985 vty_out(vty,
10986 "%24s via %pI4, %s\n",
10987 "",
10988 &path->nexthop,
10989 ifindex2ifname(
10990 path->ifindex,
10991 ospf->vrf_id));
10992 }
10993 }
10994 }
10995 }
10996 }
10997 if (!json)
10998 vty_out(vty, "\n");
10999 }
11000
11001 static int show_ip_ospf_reachable_routers_common(struct vty *vty,
11002 struct ospf *ospf,
11003 uint8_t use_vrf)
11004 {
11005 if (ospf->instance)
11006 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
11007
11008 ospf_show_vrf_name(ospf, vty, NULL, use_vrf);
11009
11010 if (ospf->all_rtrs == NULL) {
11011 vty_out(vty, "No OSPF reachable router information exist\n");
11012 return CMD_SUCCESS;
11013 }
11014
11015 /* Show Router routes. */
11016 show_ip_ospf_route_router(vty, ospf, ospf->all_rtrs, NULL);
11017
11018 vty_out(vty, "\n");
11019
11020 return CMD_SUCCESS;
11021 }
11022
11023 DEFUN (show_ip_ospf_reachable_routers,
11024 show_ip_ospf_reachable_routers_cmd,
11025 "show ip ospf [vrf <NAME|all>] reachable-routers",
11026 SHOW_STR
11027 IP_STR
11028 "OSPF information\n"
11029 VRF_CMD_HELP_STR
11030 "All VRFs\n"
11031 "Show all the reachable OSPF routers\n")
11032 {
11033 struct ospf *ospf = NULL;
11034 struct listnode *node = NULL;
11035 char *vrf_name = NULL;
11036 bool all_vrf = false;
11037 int ret = CMD_SUCCESS;
11038 int inst = 0;
11039 int idx_vrf = 0;
11040 uint8_t use_vrf = 0;
11041
11042 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
11043
11044 if (vrf_name) {
11045 bool ospf_output = false;
11046
11047 use_vrf = 1;
11048
11049 if (all_vrf) {
11050 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11051 if (!ospf->oi_running)
11052 continue;
11053
11054 ospf_output = true;
11055 ret = show_ip_ospf_reachable_routers_common(
11056 vty, ospf, use_vrf);
11057 }
11058
11059 if (!ospf_output)
11060 vty_out(vty, "%% OSPF instance not found\n");
11061 } else {
11062 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
11063 if (ospf == NULL || !ospf->oi_running) {
11064 vty_out(vty, "%% OSPF instance not found\n");
11065 return CMD_SUCCESS;
11066 }
11067
11068 ret = show_ip_ospf_reachable_routers_common(vty, ospf,
11069 use_vrf);
11070 }
11071 } else {
11072 /* Display default ospf (instance 0) info */
11073 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
11074 if (ospf == NULL || !ospf->oi_running) {
11075 vty_out(vty, "%% OSPF instance not found\n");
11076 return CMD_SUCCESS;
11077 }
11078
11079 ret = show_ip_ospf_reachable_routers_common(vty, ospf, use_vrf);
11080 }
11081
11082 return ret;
11083 }
11084
11085 DEFUN (show_ip_ospf_instance_reachable_routers,
11086 show_ip_ospf_instance_reachable_routers_cmd,
11087 "show ip ospf (1-65535) reachable-routers",
11088 SHOW_STR
11089 IP_STR
11090 "OSPF information\n"
11091 "Instance ID\n"
11092 "Show all the reachable OSPF routers\n")
11093 {
11094 int idx_number = 3;
11095 struct ospf *ospf;
11096 unsigned short instance = 0;
11097
11098 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11099 if (instance != ospf_instance)
11100 return CMD_NOT_MY_INSTANCE;
11101
11102 ospf = ospf_lookup_instance(instance);
11103 if (!ospf || !ospf->oi_running)
11104 return CMD_SUCCESS;
11105
11106 return show_ip_ospf_reachable_routers_common(vty, ospf, 0);
11107 }
11108
11109 static int show_ip_ospf_border_routers_common(struct vty *vty,
11110 struct ospf *ospf,
11111 uint8_t use_vrf)
11112 {
11113 if (ospf->instance)
11114 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
11115
11116 ospf_show_vrf_name(ospf, vty, NULL, use_vrf);
11117
11118 if (ospf->new_table == NULL) {
11119 vty_out(vty, "No OSPF routing information exist\n");
11120 return CMD_SUCCESS;
11121 }
11122
11123 /* Show Network routes.
11124 show_ip_ospf_route_network (vty, ospf->new_table); */
11125
11126 /* Show Router routes. */
11127 show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, NULL);
11128
11129 vty_out(vty, "\n");
11130
11131 return CMD_SUCCESS;
11132 }
11133
11134 DEFUN (show_ip_ospf_border_routers,
11135 show_ip_ospf_border_routers_cmd,
11136 "show ip ospf [vrf <NAME|all>] border-routers",
11137 SHOW_STR
11138 IP_STR
11139 "OSPF information\n"
11140 VRF_CMD_HELP_STR
11141 "All VRFs\n"
11142 "Show all the ABR's and ASBR's\n")
11143 {
11144 struct ospf *ospf = NULL;
11145 struct listnode *node = NULL;
11146 char *vrf_name = NULL;
11147 bool all_vrf = false;
11148 int ret = CMD_SUCCESS;
11149 int inst = 0;
11150 int idx_vrf = 0;
11151 uint8_t use_vrf = 0;
11152
11153 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
11154
11155 if (vrf_name) {
11156 bool ospf_output = false;
11157
11158 use_vrf = 1;
11159
11160 if (all_vrf) {
11161 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11162 if (!ospf->oi_running)
11163 continue;
11164
11165 ospf_output = true;
11166 ret = show_ip_ospf_border_routers_common(
11167 vty, ospf, use_vrf);
11168 }
11169
11170 if (!ospf_output)
11171 vty_out(vty, "%% OSPF is not enabled\n");
11172 } else {
11173 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
11174 if (ospf == NULL || !ospf->oi_running) {
11175 vty_out(vty,
11176 "%% OSPF is not enabled in vrf %s\n",
11177 vrf_name);
11178 return CMD_SUCCESS;
11179 }
11180
11181 ret = show_ip_ospf_border_routers_common(vty, ospf,
11182 use_vrf);
11183 }
11184 } else {
11185 /* Display default ospf (instance 0) info */
11186 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
11187 if (ospf == NULL || !ospf->oi_running) {
11188 vty_out(vty, "%% OSPF is not enabled in vrf default\n");
11189 return CMD_SUCCESS;
11190 }
11191
11192 ret = show_ip_ospf_border_routers_common(vty, ospf, use_vrf);
11193 }
11194
11195 return ret;
11196 }
11197
11198 DEFUN (show_ip_ospf_instance_border_routers,
11199 show_ip_ospf_instance_border_routers_cmd,
11200 "show ip ospf (1-65535) border-routers",
11201 SHOW_STR
11202 IP_STR
11203 "OSPF information\n"
11204 "Instance ID\n"
11205 "Show all the ABR's and ASBR's\n")
11206 {
11207 int idx_number = 3;
11208 struct ospf *ospf;
11209 unsigned short instance = 0;
11210
11211 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11212 if (instance != ospf_instance)
11213 return CMD_NOT_MY_INSTANCE;
11214
11215 ospf = ospf_lookup_instance(instance);
11216 if (!ospf || !ospf->oi_running)
11217 return CMD_SUCCESS;
11218
11219 return show_ip_ospf_border_routers_common(vty, ospf, 0);
11220 }
11221
11222 static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf,
11223 json_object *json, uint8_t use_vrf)
11224 {
11225 json_object *json_vrf = NULL;
11226
11227 if (ospf->instance)
11228 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
11229
11230
11231 if (json) {
11232 if (use_vrf)
11233 json_vrf = json_object_new_object();
11234 else
11235 json_vrf = json;
11236 }
11237
11238 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
11239
11240 if (ospf->new_table == NULL) {
11241 vty_out(vty, "No OSPF routing information exist\n");
11242 return CMD_SUCCESS;
11243 }
11244
11245 /* Show Network routes. */
11246 show_ip_ospf_route_network(vty, ospf, ospf->new_table, json_vrf);
11247
11248 /* Show Router routes. */
11249 show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, json_vrf);
11250
11251 /* Show Router routes. */
11252 if (ospf->all_rtrs)
11253 show_ip_ospf_route_router(vty, ospf, ospf->all_rtrs, json_vrf);
11254
11255 /* Show AS External routes. */
11256 show_ip_ospf_route_external(vty, ospf, ospf->old_external_route,
11257 json_vrf);
11258
11259 if (json) {
11260 if (use_vrf) {
11261 // json_object_object_add(json_vrf, "areas",
11262 // json_areas);
11263 json_object_object_add(json, ospf_get_name(ospf),
11264 json_vrf);
11265 }
11266 } else {
11267 vty_out(vty, "\n");
11268 }
11269
11270 return CMD_SUCCESS;
11271 }
11272
11273 DEFUN (show_ip_ospf_route,
11274 show_ip_ospf_route_cmd,
11275 "show ip ospf [vrf <NAME|all>] route [json]",
11276 SHOW_STR
11277 IP_STR
11278 "OSPF information\n"
11279 VRF_CMD_HELP_STR
11280 "All VRFs\n"
11281 "OSPF routing table\n"
11282 JSON_STR)
11283 {
11284 struct ospf *ospf = NULL;
11285 struct listnode *node = NULL;
11286 char *vrf_name = NULL;
11287 bool all_vrf = false;
11288 int ret = CMD_SUCCESS;
11289 int inst = 0;
11290 int idx_vrf = 0;
11291 uint8_t use_vrf = 0;
11292 bool uj = use_json(argc, argv);
11293 json_object *json = NULL;
11294
11295 if (uj)
11296 json = json_object_new_object();
11297
11298 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
11299
11300 /* vrf input is provided could be all or specific vrf*/
11301 if (vrf_name) {
11302 bool ospf_output = false;
11303
11304 use_vrf = 1;
11305
11306 if (all_vrf) {
11307 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11308 if (!ospf->oi_running)
11309 continue;
11310 ospf_output = true;
11311 ret = show_ip_ospf_route_common(vty, ospf, json,
11312 use_vrf);
11313 }
11314
11315 if (uj) {
11316 /* Keep Non-pretty format */
11317 vty_json(vty, json);
11318 } else if (!ospf_output)
11319 vty_out(vty, "%% OSPF is not enabled\n");
11320
11321 return ret;
11322 }
11323 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
11324 if (ospf == NULL || !ospf->oi_running) {
11325 if (uj)
11326 vty_json(vty, json);
11327 else
11328 vty_out(vty,
11329 "%% OSPF is not enabled in vrf %s\n",
11330 vrf_name);
11331
11332 return CMD_SUCCESS;
11333 }
11334 } else {
11335 /* Display default ospf (instance 0) info */
11336 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
11337 if (ospf == NULL || !ospf->oi_running) {
11338 if (uj)
11339 vty_json(vty, json);
11340 else
11341 vty_out(vty,
11342 "%% OSPF is not enabled in vrf default\n");
11343
11344 return CMD_SUCCESS;
11345 }
11346 }
11347
11348 if (ospf) {
11349 ret = show_ip_ospf_route_common(vty, ospf, json, use_vrf);
11350 /* Keep Non-pretty format */
11351 if (uj)
11352 vty_out(vty, "%s\n",
11353 json_object_to_json_string_ext(
11354 json, JSON_C_TO_STRING_NOSLASHESCAPE));
11355 }
11356
11357 if (uj)
11358 json_object_free(json);
11359
11360 return ret;
11361 }
11362
11363 DEFUN (show_ip_ospf_instance_route,
11364 show_ip_ospf_instance_route_cmd,
11365 "show ip ospf (1-65535) route",
11366 SHOW_STR
11367 IP_STR
11368 "OSPF information\n"
11369 "Instance ID\n"
11370 "OSPF routing table\n")
11371 {
11372 int idx_number = 3;
11373 struct ospf *ospf;
11374 unsigned short instance = 0;
11375
11376 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11377 if (instance != ospf_instance)
11378 return CMD_NOT_MY_INSTANCE;
11379
11380 ospf = ospf_lookup_instance(instance);
11381 if (!ospf || !ospf->oi_running)
11382 return CMD_SUCCESS;
11383
11384 return show_ip_ospf_route_common(vty, ospf, NULL, 0);
11385 }
11386
11387
11388 DEFUN (show_ip_ospf_vrfs,
11389 show_ip_ospf_vrfs_cmd,
11390 "show ip ospf vrfs [json]",
11391 SHOW_STR
11392 IP_STR
11393 "OSPF information\n"
11394 "Show OSPF VRFs \n"
11395 JSON_STR)
11396 {
11397 bool uj = use_json(argc, argv);
11398 json_object *json = NULL;
11399 json_object *json_vrfs = NULL;
11400 struct ospf *ospf = NULL;
11401 struct listnode *node = NULL;
11402 int count = 0;
11403 static const char header[] = "Name Id RouterId ";
11404
11405 if (uj) {
11406 json = json_object_new_object();
11407 json_vrfs = json_object_new_object();
11408 }
11409
11410 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11411 json_object *json_vrf = NULL;
11412 const char *name = NULL;
11413 int64_t vrf_id_ui = 0;
11414
11415 count++;
11416
11417 if (!uj && count == 1)
11418 vty_out(vty, "%s\n", header);
11419 if (uj)
11420 json_vrf = json_object_new_object();
11421
11422 name = ospf_get_name(ospf);
11423
11424 vrf_id_ui = (ospf->vrf_id == VRF_UNKNOWN)
11425 ? -1
11426 : (int64_t)ospf->vrf_id;
11427
11428 if (uj) {
11429 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
11430 json_object_string_addf(json_vrf, "routerId", "%pI4",
11431 &ospf->router_id);
11432
11433 json_object_object_add(json_vrfs, name, json_vrf);
11434
11435 } else {
11436 vty_out(vty, "%-25s %-5d %-16pI4 \n", name,
11437 ospf->vrf_id, &ospf->router_id);
11438 }
11439 }
11440
11441 if (uj) {
11442 json_object_object_add(json, "vrfs", json_vrfs);
11443 json_object_int_add(json, "totalVrfs", count);
11444
11445 vty_json(vty, json);
11446 } else {
11447 if (count)
11448 vty_out(vty, "\nTotal number of OSPF VRFs: %d\n",
11449 count);
11450 }
11451
11452 return CMD_SUCCESS;
11453 }
11454 DEFPY (clear_ip_ospf_neighbor,
11455 clear_ip_ospf_neighbor_cmd,
11456 "clear ip ospf [(1-65535)]$instance neighbor [A.B.C.D$nbr_id]",
11457 CLEAR_STR
11458 IP_STR
11459 "OSPF information\n"
11460 "Instance ID\n"
11461 "Reset OSPF Neighbor\n"
11462 "Neighbor ID\n")
11463 {
11464 struct listnode *node;
11465 struct ospf *ospf = NULL;
11466
11467 /* If user does not specify the arguments,
11468 * instance = 0 and nbr_id = 0.0.0.0
11469 */
11470 if (instance != 0) {
11471 /* This means clear only the particular ospf process */
11472 if (instance != ospf_instance)
11473 return CMD_NOT_MY_INSTANCE;
11474 }
11475
11476 /* Clear all the ospf processes */
11477 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11478 if (!ospf->oi_running)
11479 continue;
11480
11481 if (nbr_id_str && IPV4_ADDR_SAME(&ospf->router_id, &nbr_id)) {
11482 vty_out(vty, "Self router-id is not allowed.\r\n ");
11483 return CMD_SUCCESS;
11484 }
11485
11486 ospf_neighbor_reset(ospf, nbr_id, nbr_id_str);
11487 }
11488
11489 return CMD_SUCCESS;
11490 }
11491
11492 DEFPY (clear_ip_ospf_process,
11493 clear_ip_ospf_process_cmd,
11494 "clear ip ospf [(1-65535)]$instance process",
11495 CLEAR_STR
11496 IP_STR
11497 "OSPF information\n"
11498 "Instance ID\n"
11499 "Reset OSPF Process\n")
11500 {
11501 struct listnode *node;
11502 struct ospf *ospf = NULL;
11503
11504 /* Check if instance is not passed as an argument */
11505 if (instance != 0) {
11506 /* This means clear only the particular ospf process */
11507 if (instance != ospf_instance)
11508 return CMD_NOT_MY_INSTANCE;
11509 }
11510
11511 /* Clear all the ospf processes */
11512 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11513 if (!ospf->oi_running)
11514 continue;
11515
11516 ospf_process_reset(ospf);
11517 }
11518
11519 return CMD_SUCCESS;
11520 }
11521
11522 static const char *const ospf_abr_type_str[] = {
11523 "unknown", "standard", "ibm", "cisco", "shortcut"
11524 };
11525
11526 static const char *const ospf_shortcut_mode_str[] = {
11527 "default", "enable", "disable"
11528 };
11529 static int ospf_vty_external_rt_walkcb(struct hash_bucket *bucket,
11530 void *arg)
11531 {
11532 struct external_info *ei = bucket->data;
11533 struct vty *vty = (struct vty *)arg;
11534 static unsigned int count;
11535
11536 vty_out(vty, "%-4pI4/%d, ", &ei->p.prefix, ei->p.prefixlen);
11537 count++;
11538
11539 if (count % 5 == 0)
11540 vty_out(vty, "\n");
11541
11542 if (OSPF_EXTERNAL_RT_COUNT(ei->aggr_route) == count)
11543 count = 0;
11544
11545 return HASHWALK_CONTINUE;
11546 }
11547
11548 static int ospf_json_external_rt_walkcb(struct hash_bucket *bucket,
11549 void *arg)
11550 {
11551 struct external_info *ei = bucket->data;
11552 struct json_object *json = (struct json_object *)arg;
11553 char buf[PREFIX2STR_BUFFER];
11554 char exnalbuf[20];
11555 static unsigned int count;
11556
11557 prefix2str(&ei->p, buf, sizeof(buf));
11558
11559 snprintf(exnalbuf, 20, "Exnl Addr-%d", count);
11560
11561 json_object_string_add(json, exnalbuf, buf);
11562
11563 count++;
11564
11565 if (OSPF_EXTERNAL_RT_COUNT(ei->aggr_route) == count)
11566 count = 0;
11567
11568 return HASHWALK_CONTINUE;
11569 }
11570
11571 static int ospf_show_summary_address(struct vty *vty, struct ospf *ospf,
11572 uint8_t use_vrf, json_object *json,
11573 bool uj, bool detail)
11574 {
11575 struct route_node *rn;
11576 json_object *json_vrf = NULL;
11577 int mtype = 0;
11578 int mval = 0;
11579 static char header[] =
11580 "Summary-address Metric-type Metric Tag External_Rt_count\n";
11581
11582 mtype = metric_type(ospf, 0, ospf->instance);
11583 mval = metric_value(ospf, 0, ospf->instance);
11584
11585 if (!uj)
11586 vty_out(vty, "%s\n", header);
11587
11588 if (uj) {
11589 if (use_vrf)
11590 json_vrf = json_object_new_object();
11591 else
11592 json_vrf = json;
11593 }
11594
11595 if (ospf->instance) {
11596 if (uj)
11597 json_object_int_add(json, "ospfInstance",
11598 ospf->instance);
11599 else
11600 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
11601 }
11602
11603 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
11604
11605 if (!uj) {
11606 vty_out(vty, "aggregation delay interval :%u(in seconds)\n\n",
11607 ospf->aggr_delay_interval);
11608 } else {
11609 json_object_int_add(json_vrf, "aggregation delay interval",
11610 ospf->aggr_delay_interval);
11611 json_object_int_add(json_vrf, "aggregationDelayInterval",
11612 ospf->aggr_delay_interval);
11613 }
11614
11615 for (rn = route_top(ospf->rt_aggr_tbl); rn; rn = route_next(rn))
11616 if (rn->info) {
11617 struct ospf_external_aggr_rt *aggr = rn->info;
11618 json_object *json_aggr = NULL;
11619 char buf[PREFIX2STR_BUFFER];
11620
11621 prefix2str(&aggr->p, buf, sizeof(buf));
11622
11623 if (uj) {
11624
11625 json_aggr = json_object_new_object();
11626
11627 json_object_object_add(json_vrf, buf,
11628 json_aggr);
11629
11630 json_object_string_add(json_aggr,
11631 "Summary address", buf);
11632 json_object_string_add(json_aggr,
11633 "summaryAddress", buf);
11634
11635 json_object_string_add(
11636 json_aggr, "Metric-type",
11637 (mtype == EXTERNAL_METRIC_TYPE_1)
11638 ? "E1"
11639 : "E2");
11640 json_object_string_add(
11641 json_aggr, "metricType",
11642 (mtype == EXTERNAL_METRIC_TYPE_1)
11643 ? "E1"
11644 : "E2");
11645
11646 #if CONFDATE > 20230131
11647 CPP_NOTICE("Remove JSON object commands with keys starting with capital")
11648 #endif
11649 json_object_int_add(json_aggr, "Metric", mval);
11650 json_object_int_add(json_aggr, "metric", mval);
11651
11652 json_object_int_add(json_aggr, "Tag",
11653 aggr->tag);
11654 json_object_int_add(json_aggr, "tag",
11655 aggr->tag);
11656
11657 json_object_int_add(
11658 json_aggr, "External route count",
11659 OSPF_EXTERNAL_RT_COUNT(aggr));
11660 json_object_int_add(
11661 json_aggr, "externalRouteCount",
11662 OSPF_EXTERNAL_RT_COUNT(aggr));
11663
11664 if (OSPF_EXTERNAL_RT_COUNT(aggr) && detail) {
11665 hash_walk(
11666 aggr->match_extnl_hash,
11667 ospf_json_external_rt_walkcb,
11668 json_aggr);
11669 }
11670
11671 } else {
11672 vty_out(vty, "%-20s", buf);
11673
11674 (mtype == EXTERNAL_METRIC_TYPE_1)
11675 ? vty_out(vty, "%-16s", "E1")
11676 : vty_out(vty, "%-16s", "E2");
11677 vty_out(vty, "%-11d", mval);
11678
11679 vty_out(vty, "%-12u", aggr->tag);
11680
11681 vty_out(vty, "%-5ld\n",
11682 OSPF_EXTERNAL_RT_COUNT(aggr));
11683
11684 if (OSPF_EXTERNAL_RT_COUNT(aggr) && detail) {
11685 vty_out(vty,
11686 "Matched External routes:\n");
11687 hash_walk(
11688 aggr->match_extnl_hash,
11689 ospf_vty_external_rt_walkcb,
11690 vty);
11691 vty_out(vty, "\n");
11692 }
11693
11694 vty_out(vty, "\n");
11695 }
11696 }
11697
11698 if (uj) {
11699 if (use_vrf)
11700 json_object_object_add(json, ospf_get_name(ospf),
11701 json_vrf);
11702 } else
11703 vty_out(vty, "\n");
11704
11705 return CMD_SUCCESS;
11706 }
11707
11708 DEFUN (show_ip_ospf_external_aggregator,
11709 show_ip_ospf_external_aggregator_cmd,
11710 "show ip ospf [vrf <NAME|all>] summary-address [detail] [json]",
11711 SHOW_STR IP_STR
11712 "OSPF information\n"
11713 VRF_CMD_HELP_STR
11714 "All VRFs\n"
11715 "Show external summary addresses\n"
11716 "Detailed information\n"
11717 JSON_STR)
11718 {
11719 char *vrf_name = NULL;
11720 bool all_vrf = false;
11721 int ret = CMD_SUCCESS;
11722 int idx_vrf = 0;
11723 int idx = 0;
11724 uint8_t use_vrf = 0;
11725 bool uj = use_json(argc, argv);
11726 struct ospf *ospf = NULL;
11727 json_object *json = NULL;
11728 struct listnode *node = NULL;
11729 int inst = 0;
11730 bool detail = false;
11731
11732 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
11733
11734 if (argv_find(argv, argc, "detail", &idx))
11735 detail = true;
11736
11737 if (uj)
11738 json = json_object_new_object();
11739
11740 /* vrf input is provided */
11741 if (vrf_name) {
11742 use_vrf = 1;
11743 if (all_vrf) {
11744 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11745 if (!ospf->oi_running)
11746 continue;
11747 ret = ospf_show_summary_address(
11748 vty, ospf, use_vrf, json, uj, detail);
11749 }
11750
11751 if (uj)
11752 vty_json(vty, json);
11753
11754 return ret;
11755 }
11756
11757 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
11758
11759 if (ospf == NULL || !ospf->oi_running) {
11760 if (uj)
11761 vty_json(vty, json);
11762 else
11763 vty_out(vty,
11764 "%% OSPF is not enabled in vrf %s\n",
11765 vrf_name);
11766
11767 return CMD_SUCCESS;
11768 }
11769 ospf_show_summary_address(vty, ospf, use_vrf, json, uj, detail);
11770
11771 } else {
11772 /* Default Vrf */
11773 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
11774 if (ospf == NULL || !ospf->oi_running) {
11775 if (uj)
11776 vty_json(vty, json);
11777 else
11778 vty_out(vty,
11779 "%% OSPF is not enabled in vrf default\n");
11780
11781 return CMD_SUCCESS;
11782 }
11783
11784 ospf_show_summary_address(vty, ospf, use_vrf, json, uj, detail);
11785 }
11786
11787 if (uj)
11788 vty_json(vty, json);
11789 return CMD_SUCCESS;
11790 }
11791
11792 static const char *const ospf_int_type_str[] = {
11793 "unknown", /* should never be used. */
11794 "point-to-point",
11795 "broadcast",
11796 "non-broadcast",
11797 "point-to-multipoint",
11798 "virtual-link", /* should never be used. */
11799 "loopback"
11800 };
11801
11802 static const char *interface_config_auth_str(struct ospf_if_params *params)
11803 {
11804 if (!OSPF_IF_PARAM_CONFIGURED(params, auth_type)
11805 || params->auth_type == OSPF_AUTH_NOTSET)
11806 return NULL;
11807
11808 /* Translation tables are not that much help
11809 * here due to syntax
11810 * of the simple option */
11811 switch (params->auth_type) {
11812
11813 case OSPF_AUTH_NULL:
11814 return " null";
11815
11816 case OSPF_AUTH_SIMPLE:
11817 return "";
11818
11819 case OSPF_AUTH_CRYPTOGRAPHIC:
11820 return " message-digest";
11821 }
11822
11823 return "";
11824 }
11825
11826 static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
11827 {
11828 struct listnode *node;
11829 struct interface *ifp;
11830 struct crypt_key *ck;
11831 struct route_node *rn = NULL;
11832 struct ospf_if_params *params;
11833 const char *auth_str;
11834 int write = 0;
11835
11836 FOR_ALL_INTERFACES (vrf, ifp) {
11837
11838 if (memcmp(ifp->name, "VLINK", 5) == 0)
11839 continue;
11840
11841 if_vty_config_start(vty, ifp);
11842
11843 if (ifp->desc)
11844 vty_out(vty, " description %s\n", ifp->desc);
11845
11846 write++;
11847
11848 params = IF_DEF_PARAMS(ifp);
11849
11850 do {
11851 /* Interface Network print. */
11852 if (OSPF_IF_PARAM_CONFIGURED(params, type)
11853 && params->type != OSPF_IFTYPE_LOOPBACK) {
11854 if (params->type != ospf_default_iftype(ifp)) {
11855 vty_out(vty, " ip ospf network %s",
11856 ospf_int_type_str
11857 [params->type]);
11858 if (params->type
11859 == OSPF_IFTYPE_POINTOPOINT
11860 && params->ptp_dmvpn)
11861 vty_out(vty, " dmvpn");
11862 if (params != IF_DEF_PARAMS(ifp) && rn)
11863 vty_out(vty, " %pI4",
11864 &rn->p.u.prefix4);
11865 vty_out(vty, "\n");
11866 }
11867 }
11868
11869 /* OSPF interface authentication print */
11870 auth_str = interface_config_auth_str(params);
11871 if (auth_str) {
11872 vty_out(vty, " ip ospf authentication%s",
11873 auth_str);
11874 if (params != IF_DEF_PARAMS(ifp) && rn)
11875 vty_out(vty, " %pI4",
11876 &rn->p.u.prefix4);
11877 vty_out(vty, "\n");
11878 }
11879
11880 /* Simple Authentication Password print. */
11881 if (OSPF_IF_PARAM_CONFIGURED(params, auth_simple)
11882 && params->auth_simple[0] != '\0') {
11883 vty_out(vty, " ip ospf authentication-key %s",
11884 params->auth_simple);
11885 if (params != IF_DEF_PARAMS(ifp) && rn)
11886 vty_out(vty, " %pI4",
11887 &rn->p.u.prefix4);
11888 vty_out(vty, "\n");
11889 }
11890
11891 /* Cryptographic Authentication Key print. */
11892 if (params && params->auth_crypt) {
11893 for (ALL_LIST_ELEMENTS_RO(params->auth_crypt,
11894 node, ck)) {
11895 vty_out(vty,
11896 " ip ospf message-digest-key %d md5 %s",
11897 ck->key_id, ck->auth_key);
11898 if (params != IF_DEF_PARAMS(ifp) && rn)
11899 vty_out(vty, " %pI4",
11900 &rn->p.u.prefix4);
11901 vty_out(vty, "\n");
11902 }
11903 }
11904
11905 /* Interface Output Cost print. */
11906 if (OSPF_IF_PARAM_CONFIGURED(params, output_cost_cmd)) {
11907 vty_out(vty, " ip ospf cost %u",
11908 params->output_cost_cmd);
11909 if (params != IF_DEF_PARAMS(ifp) && rn)
11910 vty_out(vty, " %pI4",
11911 &rn->p.u.prefix4);
11912 vty_out(vty, "\n");
11913 }
11914
11915 /* Hello Interval print. */
11916 if (OSPF_IF_PARAM_CONFIGURED(params, v_hello)
11917 && params->v_hello != OSPF_HELLO_INTERVAL_DEFAULT) {
11918 vty_out(vty, " ip ospf hello-interval %u",
11919 params->v_hello);
11920 if (params != IF_DEF_PARAMS(ifp) && rn)
11921 vty_out(vty, " %pI4",
11922 &rn->p.u.prefix4);
11923 vty_out(vty, "\n");
11924 }
11925
11926
11927 /* Router Dead Interval print. */
11928 if (OSPF_IF_PARAM_CONFIGURED(params, v_wait)
11929 && params->is_v_wait_set) {
11930 vty_out(vty, " ip ospf dead-interval ");
11931
11932 /* fast hello ? */
11933 if (OSPF_IF_PARAM_CONFIGURED(params,
11934 fast_hello))
11935 vty_out(vty,
11936 "minimal hello-multiplier %d",
11937 params->fast_hello);
11938 else
11939 vty_out(vty, "%u", params->v_wait);
11940
11941 if (params != IF_DEF_PARAMS(ifp) && rn)
11942 vty_out(vty, " %pI4",
11943 &rn->p.u.prefix4);
11944 vty_out(vty, "\n");
11945 }
11946
11947 /* Router Priority print. */
11948 if (OSPF_IF_PARAM_CONFIGURED(params, priority)
11949 && params->priority
11950 != OSPF_ROUTER_PRIORITY_DEFAULT) {
11951 vty_out(vty, " ip ospf priority %u",
11952 params->priority);
11953 if (params != IF_DEF_PARAMS(ifp) && rn)
11954 vty_out(vty, " %pI4",
11955 &rn->p.u.prefix4);
11956 vty_out(vty, "\n");
11957 }
11958
11959 /* Retransmit Interval print. */
11960 if (OSPF_IF_PARAM_CONFIGURED(params,
11961 retransmit_interval)
11962 && params->retransmit_interval
11963 != OSPF_RETRANSMIT_INTERVAL_DEFAULT) {
11964 vty_out(vty, " ip ospf retransmit-interval %u",
11965 params->retransmit_interval);
11966 if (params != IF_DEF_PARAMS(ifp) && rn)
11967 vty_out(vty, " %pI4",
11968 &rn->p.u.prefix4);
11969 vty_out(vty, "\n");
11970 }
11971
11972 /* Transmit Delay print. */
11973 if (OSPF_IF_PARAM_CONFIGURED(params, transmit_delay)
11974 && params->transmit_delay
11975 != OSPF_TRANSMIT_DELAY_DEFAULT) {
11976 vty_out(vty, " ip ospf transmit-delay %u",
11977 params->transmit_delay);
11978 if (params != IF_DEF_PARAMS(ifp) && rn)
11979 vty_out(vty, " %pI4",
11980 &rn->p.u.prefix4);
11981 vty_out(vty, "\n");
11982 }
11983
11984 /* Area print. */
11985 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
11986 if (ospf_instance)
11987 vty_out(vty, " ip ospf %d",
11988 ospf_instance);
11989 else
11990 vty_out(vty, " ip ospf");
11991
11992 char buf[INET_ADDRSTRLEN];
11993
11994 area_id2str(buf, sizeof(buf), &params->if_area,
11995 params->if_area_id_fmt);
11996 vty_out(vty, " area %s", buf);
11997 if (params != IF_DEF_PARAMS(ifp) && rn)
11998 vty_out(vty, " %pI4",
11999 &rn->p.u.prefix4);
12000 vty_out(vty, "\n");
12001 }
12002
12003 /* bfd print. */
12004 if (params && params->bfd_config)
12005 ospf_bfd_write_config(vty, params);
12006
12007 /* MTU ignore print. */
12008 if (OSPF_IF_PARAM_CONFIGURED(params, mtu_ignore)
12009 && params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) {
12010 if (params->mtu_ignore == 0)
12011 vty_out(vty, " no ip ospf mtu-ignore");
12012 else
12013 vty_out(vty, " ip ospf mtu-ignore");
12014 if (params != IF_DEF_PARAMS(ifp) && rn)
12015 vty_out(vty, " %pI4",
12016 &rn->p.u.prefix4);
12017 vty_out(vty, "\n");
12018 }
12019
12020 if (OSPF_IF_PARAM_CONFIGURED(params,
12021 passive_interface)) {
12022 vty_out(vty, " %sip ospf passive",
12023 params->passive_interface
12024 == OSPF_IF_ACTIVE
12025 ? "no "
12026 : "");
12027 if (params != IF_DEF_PARAMS(ifp) && rn)
12028 vty_out(vty, " %pI4", &rn->p.u.prefix4);
12029 vty_out(vty, "\n");
12030 }
12031
12032 /* LDP-Sync print */
12033 if (params && params->ldp_sync_info)
12034 ospf_ldp_sync_if_write_config(vty, params);
12035
12036 while (1) {
12037 if (rn == NULL)
12038 rn = route_top(IF_OIFS_PARAMS(ifp));
12039 else
12040 rn = route_next(rn);
12041
12042 if (rn == NULL)
12043 break;
12044 params = rn->info;
12045 if (params != NULL)
12046 break;
12047 }
12048 } while (rn);
12049
12050 ospf_opaque_config_write_if(vty, ifp);
12051
12052 if_vty_config_end(vty);
12053 }
12054
12055 return write;
12056 }
12057
12058 /* Configuration write function for ospfd. */
12059 static int config_write_interface(struct vty *vty)
12060 {
12061 int write = 0;
12062 struct vrf *vrf = NULL;
12063
12064 /* Display all VRF aware OSPF interface configuration */
12065 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
12066 write += config_write_interface_one(vty, vrf);
12067 }
12068
12069 return write;
12070 }
12071
12072 static int config_write_network_area(struct vty *vty, struct ospf *ospf)
12073 {
12074 struct route_node *rn;
12075 char buf[INET_ADDRSTRLEN];
12076
12077 /* `network area' print. */
12078 for (rn = route_top(ospf->networks); rn; rn = route_next(rn))
12079 if (rn->info) {
12080 struct ospf_network *n = rn->info;
12081
12082 /* Create Area ID string by specified Area ID format. */
12083 if (n->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD)
12084 inet_ntop(AF_INET, &n->area_id, buf,
12085 sizeof(buf));
12086 else
12087 snprintf(buf, sizeof(buf), "%lu",
12088 (unsigned long int)ntohl(
12089 n->area_id.s_addr));
12090
12091 /* Network print. */
12092 vty_out(vty, " network %pFX area %s\n", &rn->p, buf);
12093 }
12094
12095 return 0;
12096 }
12097
12098 static int config_write_ospf_area(struct vty *vty, struct ospf *ospf)
12099 {
12100 struct listnode *node;
12101 struct ospf_area *area;
12102 char buf[INET_ADDRSTRLEN];
12103
12104 /* Area configuration print. */
12105 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
12106 struct route_node *rn1;
12107
12108 area_id2str(buf, sizeof(buf), &area->area_id,
12109 area->area_id_fmt);
12110
12111 if (area->auth_type != OSPF_AUTH_NULL) {
12112 if (area->auth_type == OSPF_AUTH_SIMPLE)
12113 vty_out(vty, " area %s authentication\n", buf);
12114 else
12115 vty_out(vty,
12116 " area %s authentication message-digest\n",
12117 buf);
12118 }
12119
12120 if (area->shortcut_configured != OSPF_SHORTCUT_DEFAULT)
12121 vty_out(vty, " area %s shortcut %s\n", buf,
12122 ospf_shortcut_mode_str
12123 [area->shortcut_configured]);
12124
12125 if ((area->external_routing == OSPF_AREA_STUB)
12126 || (area->external_routing == OSPF_AREA_NSSA)) {
12127 if (area->external_routing == OSPF_AREA_STUB) {
12128 vty_out(vty, " area %s stub", buf);
12129 if (area->no_summary)
12130 vty_out(vty, " no-summary\n");
12131 vty_out(vty, "\n");
12132 } else if (area->external_routing == OSPF_AREA_NSSA) {
12133 switch (area->NSSATranslatorRole) {
12134 case OSPF_NSSA_ROLE_NEVER:
12135 vty_out(vty,
12136 " area %s nssa translate-never\n",
12137 buf);
12138 break;
12139 case OSPF_NSSA_ROLE_ALWAYS:
12140 vty_out(vty,
12141 " area %s nssa translate-always\n",
12142 buf);
12143 break;
12144 case OSPF_NSSA_ROLE_CANDIDATE:
12145 vty_out(vty, " area %s nssa \n", buf);
12146 break;
12147 }
12148 if (area->no_summary)
12149 vty_out(vty,
12150 " area %s nssa no-summary\n",
12151 buf);
12152 if (area->suppress_fa)
12153 vty_out(vty,
12154 " area %s nssa suppress-fa\n",
12155 buf);
12156 }
12157
12158 if (area->default_cost != 1)
12159 vty_out(vty, " area %s default-cost %d\n", buf,
12160 area->default_cost);
12161 }
12162
12163 for (rn1 = route_top(area->ranges); rn1; rn1 = route_next(rn1))
12164 if (rn1->info) {
12165 struct ospf_area_range *range = rn1->info;
12166
12167 vty_out(vty, " area %s range %pFX", buf,
12168 &rn1->p);
12169
12170 if (range->cost_config
12171 != OSPF_AREA_RANGE_COST_UNSPEC)
12172 vty_out(vty, " cost %d",
12173 range->cost_config);
12174
12175 if (!CHECK_FLAG(range->flags,
12176 OSPF_AREA_RANGE_ADVERTISE))
12177 vty_out(vty, " not-advertise");
12178
12179 if (CHECK_FLAG(range->flags,
12180 OSPF_AREA_RANGE_SUBSTITUTE))
12181 vty_out(vty, " substitute %pI4/%d",
12182 &range->subst_addr,
12183 range->subst_masklen);
12184
12185 vty_out(vty, "\n");
12186 }
12187
12188 if (EXPORT_NAME(area))
12189 vty_out(vty, " area %s export-list %s\n", buf,
12190 EXPORT_NAME(area));
12191
12192 if (IMPORT_NAME(area))
12193 vty_out(vty, " area %s import-list %s\n", buf,
12194 IMPORT_NAME(area));
12195
12196 if (PREFIX_NAME_IN(area))
12197 vty_out(vty, " area %s filter-list prefix %s in\n", buf,
12198 PREFIX_NAME_IN(area));
12199
12200 if (PREFIX_NAME_OUT(area))
12201 vty_out(vty, " area %s filter-list prefix %s out\n",
12202 buf, PREFIX_NAME_OUT(area));
12203 }
12204
12205 return 0;
12206 }
12207
12208 static int config_write_ospf_nbr_nbma(struct vty *vty, struct ospf *ospf)
12209 {
12210 struct ospf_nbr_nbma *nbr_nbma;
12211 struct route_node *rn;
12212
12213 /* Static Neighbor configuration print. */
12214 for (rn = route_top(ospf->nbr_nbma); rn; rn = route_next(rn))
12215 if ((nbr_nbma = rn->info)) {
12216 vty_out(vty, " neighbor %pI4", &nbr_nbma->addr);
12217
12218 if (nbr_nbma->priority
12219 != OSPF_NEIGHBOR_PRIORITY_DEFAULT)
12220 vty_out(vty, " priority %d",
12221 nbr_nbma->priority);
12222
12223 if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT)
12224 vty_out(vty, " poll-interval %d",
12225 nbr_nbma->v_poll);
12226
12227 vty_out(vty, "\n");
12228 }
12229
12230 return 0;
12231 }
12232
12233 static int config_write_virtual_link(struct vty *vty, struct ospf *ospf)
12234 {
12235 struct listnode *node;
12236 struct ospf_vl_data *vl_data;
12237 const char *auth_str;
12238 char buf[INET_ADDRSTRLEN];
12239
12240 /* Virtual-Link print */
12241 for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl_data)) {
12242 struct listnode *n2;
12243 struct crypt_key *ck;
12244 struct ospf_interface *oi;
12245
12246 if (vl_data != NULL) {
12247 area_id2str(buf, sizeof(buf), &vl_data->vl_area_id,
12248 vl_data->vl_area_id_fmt);
12249 oi = vl_data->vl_oi;
12250
12251 /* timers */
12252 if (OSPF_IF_PARAM(oi, v_hello)
12253 != OSPF_HELLO_INTERVAL_DEFAULT
12254 || OSPF_IF_PARAM(oi, v_wait)
12255 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
12256 || OSPF_IF_PARAM(oi, retransmit_interval)
12257 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
12258 || OSPF_IF_PARAM(oi, transmit_delay)
12259 != OSPF_TRANSMIT_DELAY_DEFAULT)
12260 vty_out(vty,
12261 " area %s virtual-link %pI4 hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n",
12262 buf, &vl_data->vl_peer,
12263 OSPF_IF_PARAM(oi, v_hello),
12264 OSPF_IF_PARAM(oi, retransmit_interval),
12265 OSPF_IF_PARAM(oi, transmit_delay),
12266 OSPF_IF_PARAM(oi, v_wait));
12267 else
12268 vty_out(vty, " area %s virtual-link %pI4\n", buf,
12269 &vl_data->vl_peer);
12270 /* Auth type */
12271 auth_str = interface_config_auth_str(
12272 IF_DEF_PARAMS(oi->ifp));
12273 if (auth_str)
12274 vty_out(vty,
12275 " area %s virtual-link %pI4 authentication%s\n",
12276 buf, &vl_data->vl_peer, auth_str);
12277 /* Auth key */
12278 if (IF_DEF_PARAMS(vl_data->vl_oi->ifp)->auth_simple[0]
12279 != '\0')
12280 vty_out(vty,
12281 " area %s virtual-link %pI4 authentication-key %s\n",
12282 buf, &vl_data->vl_peer,
12283 IF_DEF_PARAMS(vl_data->vl_oi->ifp)
12284 ->auth_simple);
12285 /* md5 keys */
12286 for (ALL_LIST_ELEMENTS_RO(
12287 IF_DEF_PARAMS(vl_data->vl_oi->ifp)
12288 ->auth_crypt,
12289 n2, ck))
12290 vty_out(vty,
12291 " area %s virtual-link %pI4 message-digest-key %d md5 %s\n",
12292 buf, &vl_data->vl_peer,
12293 ck->key_id, ck->auth_key);
12294 }
12295 }
12296
12297 return 0;
12298 }
12299
12300
12301 static int config_write_ospf_redistribute(struct vty *vty, struct ospf *ospf)
12302 {
12303 int type;
12304
12305 /* redistribute print. */
12306 for (type = 0; type < ZEBRA_ROUTE_MAX; type++) {
12307 struct list *red_list;
12308 struct listnode *node;
12309 struct ospf_redist *red;
12310
12311 red_list = ospf->redist[type];
12312 if (!red_list)
12313 continue;
12314
12315 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12316 vty_out(vty, " redistribute %s",
12317 zebra_route_string(type));
12318 if (red->instance)
12319 vty_out(vty, " %d", red->instance);
12320
12321 if (red->dmetric.value >= 0)
12322 vty_out(vty, " metric %d", red->dmetric.value);
12323
12324 if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1)
12325 vty_out(vty, " metric-type 1");
12326
12327 if (ROUTEMAP_NAME(red))
12328 vty_out(vty, " route-map %s",
12329 ROUTEMAP_NAME(red));
12330
12331 vty_out(vty, "\n");
12332 }
12333 }
12334
12335 return 0;
12336 }
12337
12338 static int ospf_cfg_write_helper_dis_rtr_walkcb(struct hash_bucket *bucket,
12339 void *arg)
12340 {
12341 struct advRtr *rtr = bucket->data;
12342 struct vty *vty = (struct vty *)arg;
12343
12344 vty_out(vty, " graceful-restart helper enable %pI4\n",
12345 &rtr->advRtrAddr);
12346 return HASHWALK_CONTINUE;
12347 }
12348
12349 static void config_write_ospf_gr(struct vty *vty, struct ospf *ospf)
12350 {
12351 if (!ospf->gr_info.restart_support)
12352 return;
12353
12354 if (ospf->gr_info.grace_period == OSPF_DFLT_GRACE_INTERVAL)
12355 vty_out(vty, " graceful-restart\n");
12356 else
12357 vty_out(vty, " graceful-restart grace-period %u\n",
12358 ospf->gr_info.grace_period);
12359 }
12360
12361 static int config_write_ospf_gr_helper(struct vty *vty, struct ospf *ospf)
12362 {
12363 if (ospf->is_helper_supported)
12364 vty_out(vty, " graceful-restart helper enable\n");
12365
12366 if (!ospf->strict_lsa_check)
12367 vty_out(vty,
12368 " no graceful-restart helper strict-lsa-checking\n");
12369
12370 if (ospf->only_planned_restart)
12371 vty_out(vty, " graceful-restart helper planned-only\n");
12372
12373 if (ospf->supported_grace_time != OSPF_MAX_GRACE_INTERVAL)
12374 vty_out(vty,
12375 " graceful-restart helper supported-grace-time %d\n",
12376 ospf->supported_grace_time);
12377
12378 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf)) {
12379 hash_walk(ospf->enable_rtr_list,
12380 ospf_cfg_write_helper_dis_rtr_walkcb, vty);
12381 }
12382 return 0;
12383 }
12384
12385 static int config_write_ospf_external_aggregator(struct vty *vty,
12386 struct ospf *ospf)
12387 {
12388 struct route_node *rn;
12389
12390 if (ospf->aggr_delay_interval != OSPF_EXTL_AGGR_DEFAULT_DELAY)
12391 vty_out(vty, " aggregation timer %u\n",
12392 ospf->aggr_delay_interval);
12393
12394 /* print 'summary-address A.B.C.D/M' */
12395 for (rn = route_top(ospf->rt_aggr_tbl); rn; rn = route_next(rn))
12396 if (rn->info) {
12397 struct ospf_external_aggr_rt *aggr = rn->info;
12398
12399 vty_out(vty, " summary-address %pI4/%d",
12400 &aggr->p.prefix, aggr->p.prefixlen);
12401 if (aggr->tag)
12402 vty_out(vty, " tag %u", aggr->tag);
12403
12404 if (CHECK_FLAG(aggr->flags,
12405 OSPF_EXTERNAL_AGGRT_NO_ADVERTISE))
12406 vty_out(vty, " no-advertise");
12407
12408 vty_out(vty, "\n");
12409 }
12410
12411 return 0;
12412 }
12413
12414 static int config_write_ospf_default_metric(struct vty *vty, struct ospf *ospf)
12415 {
12416 if (ospf->default_metric != -1)
12417 vty_out(vty, " default-metric %d\n", ospf->default_metric);
12418 return 0;
12419 }
12420
12421 static int config_write_ospf_distribute(struct vty *vty, struct ospf *ospf)
12422 {
12423 int type;
12424 struct ospf_redist *red;
12425
12426 if (ospf) {
12427 /* distribute-list print. */
12428 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
12429 if (DISTRIBUTE_NAME(ospf, type))
12430 vty_out(vty, " distribute-list %s out %s\n",
12431 DISTRIBUTE_NAME(ospf, type),
12432 zebra_route_string(type));
12433
12434 /* default-information print. */
12435 if (ospf->default_originate != DEFAULT_ORIGINATE_NONE) {
12436 vty_out(vty, " default-information originate");
12437 if (ospf->default_originate == DEFAULT_ORIGINATE_ALWAYS)
12438 vty_out(vty, " always");
12439
12440 red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0);
12441 if (red) {
12442 if (red->dmetric.value >= 0)
12443 vty_out(vty, " metric %d",
12444 red->dmetric.value);
12445
12446 if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1)
12447 vty_out(vty, " metric-type 1");
12448
12449 if (ROUTEMAP_NAME(red))
12450 vty_out(vty, " route-map %s",
12451 ROUTEMAP_NAME(red));
12452 }
12453
12454 vty_out(vty, "\n");
12455 }
12456 }
12457
12458 return 0;
12459 }
12460
12461 static int config_write_ospf_distance(struct vty *vty, struct ospf *ospf)
12462 {
12463 struct route_node *rn;
12464 struct ospf_distance *odistance;
12465
12466 if (ospf->distance_all)
12467 vty_out(vty, " distance %d\n", ospf->distance_all);
12468
12469 if (ospf->distance_intra || ospf->distance_inter
12470 || ospf->distance_external) {
12471 vty_out(vty, " distance ospf");
12472
12473 if (ospf->distance_intra)
12474 vty_out(vty, " intra-area %d", ospf->distance_intra);
12475 if (ospf->distance_inter)
12476 vty_out(vty, " inter-area %d", ospf->distance_inter);
12477 if (ospf->distance_external)
12478 vty_out(vty, " external %d", ospf->distance_external);
12479
12480 vty_out(vty, "\n");
12481 }
12482
12483 for (rn = route_top(ospf->distance_table); rn; rn = route_next(rn))
12484 if ((odistance = rn->info) != NULL) {
12485 vty_out(vty, " distance %d %pFX %s\n",
12486 odistance->distance, &rn->p,
12487 odistance->access_list ? odistance->access_list
12488 : "");
12489 }
12490 return 0;
12491 }
12492
12493 static int ospf_config_write_one(struct vty *vty, struct ospf *ospf)
12494 {
12495 int write = 0;
12496
12497 /* `router ospf' print. */
12498 if (ospf->instance && strcmp(ospf->name, VRF_DEFAULT_NAME)) {
12499 vty_out(vty, "router ospf %d vrf %s\n", ospf->instance,
12500 ospf->name);
12501 } else if (ospf->instance) {
12502 vty_out(vty, "router ospf %d\n", ospf->instance);
12503 } else if (strcmp(ospf->name, VRF_DEFAULT_NAME)) {
12504 vty_out(vty, "router ospf vrf %s\n", ospf->name);
12505 } else
12506 vty_out(vty, "router ospf\n");
12507
12508 if (!ospf->networks) {
12509 write++;
12510 return write;
12511 }
12512
12513 /* Router ID print. */
12514 if (ospf->router_id_static.s_addr != INADDR_ANY)
12515 vty_out(vty, " ospf router-id %pI4\n",
12516 &ospf->router_id_static);
12517
12518 /* zebra opaque attributes configuration. */
12519 if (CHECK_FLAG(ospf->config, OSPF_SEND_EXTRA_DATA_TO_ZEBRA))
12520 vty_out(vty, " ospf send-extra-data zebra\n");
12521
12522 /* ABR type print. */
12523 if (ospf->abr_type != OSPF_ABR_DEFAULT)
12524 vty_out(vty, " ospf abr-type %s\n",
12525 ospf_abr_type_str[ospf->abr_type]);
12526
12527 /* log-adjacency-changes flag print. */
12528 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) {
12529 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL))
12530 vty_out(vty, " log-adjacency-changes detail\n");
12531 else if (!SAVE_OSPF_LOG_ADJACENCY_CHANGES)
12532 vty_out(vty, " log-adjacency-changes\n");
12533 } else if (SAVE_OSPF_LOG_ADJACENCY_CHANGES) {
12534 vty_out(vty, " no log-adjacency-changes\n");
12535 }
12536
12537 /* RFC1583 compatibility flag print -- Compatible with CISCO
12538 * 12.1. */
12539 if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE))
12540 vty_out(vty, " compatible rfc1583\n");
12541
12542 /* auto-cost reference-bandwidth configuration. */
12543 if (ospf->ref_bandwidth != OSPF_DEFAULT_REF_BANDWIDTH) {
12544 vty_out(vty,
12545 "! Important: ensure reference bandwidth is consistent across all routers\n");
12546 vty_out(vty, " auto-cost reference-bandwidth %d\n",
12547 ospf->ref_bandwidth);
12548 }
12549
12550 /* SPF timers print. */
12551 if (ospf->spf_delay != OSPF_SPF_DELAY_DEFAULT
12552 || ospf->spf_holdtime != OSPF_SPF_HOLDTIME_DEFAULT
12553 || ospf->spf_max_holdtime != OSPF_SPF_MAX_HOLDTIME_DEFAULT)
12554 vty_out(vty, " timers throttle spf %d %d %d\n", ospf->spf_delay,
12555 ospf->spf_holdtime, ospf->spf_max_holdtime);
12556
12557 /* LSA timers print. */
12558 if (ospf->min_ls_interval != OSPF_MIN_LS_INTERVAL)
12559 vty_out(vty, " timers throttle lsa all %d\n",
12560 ospf->min_ls_interval);
12561 if (ospf->min_ls_arrival != OSPF_MIN_LS_ARRIVAL)
12562 vty_out(vty, " timers lsa min-arrival %d\n",
12563 ospf->min_ls_arrival);
12564
12565 /* Write multiplier print. */
12566 if (ospf->write_oi_count != OSPF_WRITE_INTERFACE_COUNT_DEFAULT)
12567 vty_out(vty, " ospf write-multiplier %d\n",
12568 ospf->write_oi_count);
12569
12570 if (ospf->max_multipath != MULTIPATH_NUM)
12571 vty_out(vty, " maximum-paths %d\n", ospf->max_multipath);
12572
12573 /* Max-metric router-lsa print */
12574 config_write_stub_router(vty, ospf);
12575
12576 /* SPF refresh parameters print. */
12577 if (ospf->lsa_refresh_interval != OSPF_LSA_REFRESH_INTERVAL_DEFAULT)
12578 vty_out(vty, " refresh timer %d\n", ospf->lsa_refresh_interval);
12579
12580 /* Redistribute information print. */
12581 config_write_ospf_redistribute(vty, ospf);
12582
12583 /* Graceful Restart print */
12584 config_write_ospf_gr(vty, ospf);
12585 config_write_ospf_gr_helper(vty, ospf);
12586
12587 /* Print external route aggregation. */
12588 config_write_ospf_external_aggregator(vty, ospf);
12589
12590 /* passive-interface print. */
12591 if (ospf->passive_interface_default == OSPF_IF_PASSIVE)
12592 vty_out(vty, " passive-interface default\n");
12593
12594 /* proactive-arp print. */
12595 if (ospf->proactive_arp != OSPF_PROACTIVE_ARP_DEFAULT) {
12596 if (ospf->proactive_arp)
12597 vty_out(vty, " proactive-arp\n");
12598 else
12599 vty_out(vty, " no proactive-arp\n");
12600 }
12601
12602 /* TI-LFA print. */
12603 if (ospf->ti_lfa_enabled) {
12604 if (ospf->ti_lfa_protection_type == OSPF_TI_LFA_NODE_PROTECTION)
12605 vty_out(vty, " fast-reroute ti-lfa node-protection\n");
12606 else
12607 vty_out(vty, " fast-reroute ti-lfa\n");
12608 }
12609
12610 /* Network area print. */
12611 config_write_network_area(vty, ospf);
12612
12613 /* Area config print. */
12614 config_write_ospf_area(vty, ospf);
12615
12616 /* static neighbor print. */
12617 config_write_ospf_nbr_nbma(vty, ospf);
12618
12619 /* Virtual-Link print. */
12620 config_write_virtual_link(vty, ospf);
12621
12622 /* Default metric configuration. */
12623 config_write_ospf_default_metric(vty, ospf);
12624
12625 /* Distribute-list and default-information print. */
12626 config_write_ospf_distribute(vty, ospf);
12627
12628 /* Distance configuration. */
12629 config_write_ospf_distance(vty, ospf);
12630
12631 ospf_opaque_config_write_router(vty, ospf);
12632
12633 /* LDP-Sync print */
12634 ospf_ldp_sync_write_config(vty, ospf);
12635
12636 vty_out(vty, "exit\n");
12637
12638 write++;
12639 return write;
12640 }
12641
12642 /* OSPF configuration write function. */
12643 static int ospf_config_write(struct vty *vty)
12644 {
12645 struct ospf *ospf;
12646 struct listnode *ospf_node = NULL;
12647 int write = 0;
12648
12649 if (listcount(om->ospf) == 0)
12650 return write;
12651
12652 for (ALL_LIST_ELEMENTS_RO(om->ospf, ospf_node, ospf)) {
12653 /* VRF Default check if it is running.
12654 * Upon daemon start, there could be default instance
12655 * in absence of 'router ospf'/oi_running is disabled. */
12656 if (ospf->vrf_id == VRF_DEFAULT && ospf->oi_running)
12657 write += ospf_config_write_one(vty, ospf);
12658 /* For Non-Default VRF simply display the configuration,
12659 * even if it is not oi_running. */
12660 else if (ospf->vrf_id != VRF_DEFAULT)
12661 write += ospf_config_write_one(vty, ospf);
12662 }
12663 return write;
12664 }
12665
12666 void ospf_vty_show_init(void)
12667 {
12668 /* "show ip ospf" commands. */
12669 install_element(VIEW_NODE, &show_ip_ospf_cmd);
12670
12671 install_element(VIEW_NODE, &show_ip_ospf_instance_cmd);
12672
12673 /* "show ip ospf database" commands. */
12674 install_element(VIEW_NODE, &show_ip_ospf_database_cmd);
12675 install_element(VIEW_NODE, &show_ip_ospf_database_max_cmd);
12676 install_element(VIEW_NODE,
12677 &show_ip_ospf_database_type_adv_router_cmd);
12678 install_element(VIEW_NODE,
12679 &show_ip_ospf_instance_database_type_adv_router_cmd);
12680 install_element(VIEW_NODE, &show_ip_ospf_instance_database_cmd);
12681 install_element(VIEW_NODE, &show_ip_ospf_instance_database_max_cmd);
12682
12683 /* "show ip ospf interface" commands. */
12684 install_element(VIEW_NODE, &show_ip_ospf_interface_cmd);
12685
12686 install_element(VIEW_NODE, &show_ip_ospf_instance_interface_cmd);
12687 /* "show ip ospf interface traffic */
12688 install_element(VIEW_NODE, &show_ip_ospf_interface_traffic_cmd);
12689
12690 /* "show ip ospf neighbor" commands. */
12691 install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_detail_cmd);
12692 install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_cmd);
12693 install_element(VIEW_NODE, &show_ip_ospf_neighbor_id_cmd);
12694 install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_all_cmd);
12695 install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_cmd);
12696 install_element(VIEW_NODE, &show_ip_ospf_neighbor_cmd);
12697 install_element(VIEW_NODE, &show_ip_ospf_neighbor_all_cmd);
12698
12699 install_element(VIEW_NODE,
12700 &show_ip_ospf_instance_neighbor_int_detail_cmd);
12701 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_int_cmd);
12702 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_id_cmd);
12703 install_element(VIEW_NODE,
12704 &show_ip_ospf_instance_neighbor_detail_all_cmd);
12705 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_detail_cmd);
12706 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_cmd);
12707 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_all_cmd);
12708
12709 /* "show ip ospf route" commands. */
12710 install_element(VIEW_NODE, &show_ip_ospf_route_cmd);
12711 install_element(VIEW_NODE, &show_ip_ospf_border_routers_cmd);
12712 install_element(VIEW_NODE, &show_ip_ospf_reachable_routers_cmd);
12713
12714 install_element(VIEW_NODE, &show_ip_ospf_instance_route_cmd);
12715 install_element(VIEW_NODE, &show_ip_ospf_instance_border_routers_cmd);
12716 install_element(VIEW_NODE,
12717 &show_ip_ospf_instance_reachable_routers_cmd);
12718
12719 /* "show ip ospf vrfs" commands. */
12720 install_element(VIEW_NODE, &show_ip_ospf_vrfs_cmd);
12721
12722 /* "show ip ospf gr-helper details" command */
12723 install_element(VIEW_NODE, &show_ip_ospf_gr_helper_cmd);
12724
12725 /* "show ip ospf summary-address" command */
12726 install_element(VIEW_NODE, &show_ip_ospf_external_aggregator_cmd);
12727 }
12728
12729 /* Initialization of OSPF interface. */
12730 static void ospf_vty_if_init(void)
12731 {
12732 /* Install interface node. */
12733 if_cmd_init(config_write_interface);
12734
12735 /* "ip ospf authentication" commands. */
12736 install_element(INTERFACE_NODE, &ip_ospf_authentication_args_addr_cmd);
12737 install_element(INTERFACE_NODE, &ip_ospf_authentication_addr_cmd);
12738 install_element(INTERFACE_NODE,
12739 &no_ip_ospf_authentication_args_addr_cmd);
12740 install_element(INTERFACE_NODE, &no_ip_ospf_authentication_addr_cmd);
12741 install_element(INTERFACE_NODE, &ip_ospf_authentication_key_addr_cmd);
12742 install_element(INTERFACE_NODE,
12743 &no_ip_ospf_authentication_key_authkey_addr_cmd);
12744 install_element(INTERFACE_NODE,
12745 &no_ospf_authentication_key_authkey_addr_cmd);
12746
12747 /* "ip ospf message-digest-key" commands. */
12748 install_element(INTERFACE_NODE, &ip_ospf_message_digest_key_cmd);
12749 install_element(INTERFACE_NODE, &no_ip_ospf_message_digest_key_cmd);
12750
12751 /* "ip ospf cost" commands. */
12752 install_element(INTERFACE_NODE, &ip_ospf_cost_cmd);
12753 install_element(INTERFACE_NODE, &no_ip_ospf_cost_cmd);
12754
12755 /* "ip ospf mtu-ignore" commands. */
12756 install_element(INTERFACE_NODE, &ip_ospf_mtu_ignore_addr_cmd);
12757 install_element(INTERFACE_NODE, &no_ip_ospf_mtu_ignore_addr_cmd);
12758
12759 /* "ip ospf dead-interval" commands. */
12760 install_element(INTERFACE_NODE, &ip_ospf_dead_interval_cmd);
12761 install_element(INTERFACE_NODE,
12762 &ip_ospf_dead_interval_minimal_addr_cmd);
12763 install_element(INTERFACE_NODE, &no_ip_ospf_dead_interval_cmd);
12764
12765 /* "ip ospf hello-interval" commands. */
12766 install_element(INTERFACE_NODE, &ip_ospf_hello_interval_cmd);
12767 install_element(INTERFACE_NODE, &no_ip_ospf_hello_interval_cmd);
12768
12769 /* "ip ospf network" commands. */
12770 install_element(INTERFACE_NODE, &ip_ospf_network_cmd);
12771 install_element(INTERFACE_NODE, &no_ip_ospf_network_cmd);
12772
12773 /* "ip ospf priority" commands. */
12774 install_element(INTERFACE_NODE, &ip_ospf_priority_cmd);
12775 install_element(INTERFACE_NODE, &no_ip_ospf_priority_cmd);
12776
12777 /* "ip ospf retransmit-interval" commands. */
12778 install_element(INTERFACE_NODE, &ip_ospf_retransmit_interval_addr_cmd);
12779 install_element(INTERFACE_NODE,
12780 &no_ip_ospf_retransmit_interval_addr_cmd);
12781
12782 /* "ip ospf transmit-delay" commands. */
12783 install_element(INTERFACE_NODE, &ip_ospf_transmit_delay_addr_cmd);
12784 install_element(INTERFACE_NODE, &no_ip_ospf_transmit_delay_addr_cmd);
12785
12786 /* "ip ospf area" commands. */
12787 install_element(INTERFACE_NODE, &ip_ospf_area_cmd);
12788 install_element(INTERFACE_NODE, &no_ip_ospf_area_cmd);
12789
12790 /* "ip ospf passive" commands. */
12791 install_element(INTERFACE_NODE, &ip_ospf_passive_cmd);
12792 install_element(INTERFACE_NODE, &no_ip_ospf_passive_cmd);
12793
12794 /* These commands are compatibitliy for previous version. */
12795 install_element(INTERFACE_NODE, &ospf_authentication_key_cmd);
12796 install_element(INTERFACE_NODE, &ospf_message_digest_key_cmd);
12797 install_element(INTERFACE_NODE, &no_ospf_message_digest_key_cmd);
12798 install_element(INTERFACE_NODE, &ospf_dead_interval_cmd);
12799 install_element(INTERFACE_NODE, &no_ospf_dead_interval_cmd);
12800 install_element(INTERFACE_NODE, &ospf_hello_interval_cmd);
12801 install_element(INTERFACE_NODE, &no_ospf_hello_interval_cmd);
12802 install_element(INTERFACE_NODE, &ospf_cost_cmd);
12803 install_element(INTERFACE_NODE, &no_ospf_cost_cmd);
12804 install_element(INTERFACE_NODE, &ospf_network_cmd);
12805 install_element(INTERFACE_NODE, &no_ospf_network_cmd);
12806 install_element(INTERFACE_NODE, &ospf_priority_cmd);
12807 install_element(INTERFACE_NODE, &no_ospf_priority_cmd);
12808 install_element(INTERFACE_NODE, &ospf_retransmit_interval_cmd);
12809 install_element(INTERFACE_NODE, &no_ospf_retransmit_interval_cmd);
12810 install_element(INTERFACE_NODE, &ospf_transmit_delay_cmd);
12811 install_element(INTERFACE_NODE, &no_ospf_transmit_delay_cmd);
12812 }
12813
12814 static void ospf_vty_zebra_init(void)
12815 {
12816 install_element(OSPF_NODE, &ospf_redistribute_source_cmd);
12817 install_element(OSPF_NODE, &no_ospf_redistribute_source_cmd);
12818 install_element(OSPF_NODE, &ospf_redistribute_instance_source_cmd);
12819 install_element(OSPF_NODE, &no_ospf_redistribute_instance_source_cmd);
12820
12821 install_element(OSPF_NODE, &ospf_distribute_list_out_cmd);
12822 install_element(OSPF_NODE, &no_ospf_distribute_list_out_cmd);
12823
12824 install_element(OSPF_NODE, &ospf_default_information_originate_cmd);
12825 install_element(OSPF_NODE, &no_ospf_default_information_originate_cmd);
12826
12827 install_element(OSPF_NODE, &ospf_default_metric_cmd);
12828 install_element(OSPF_NODE, &no_ospf_default_metric_cmd);
12829
12830 install_element(OSPF_NODE, &ospf_distance_cmd);
12831 install_element(OSPF_NODE, &no_ospf_distance_cmd);
12832 install_element(OSPF_NODE, &no_ospf_distance_ospf_cmd);
12833 install_element(OSPF_NODE, &ospf_distance_ospf_cmd);
12834
12835 /*Ospf garcefull restart helper configurations */
12836 install_element(OSPF_NODE, &ospf_gr_helper_enable_cmd);
12837 install_element(OSPF_NODE, &no_ospf_gr_helper_enable_cmd);
12838 install_element(OSPF_NODE, &ospf_gr_helper_only_cmd);
12839 install_element(OSPF_NODE, &no_ospf_gr_helper_only_cmd);
12840 install_element(OSPF_NODE, &ospf_gr_helper_enable_lsacheck_cmd);
12841 install_element(OSPF_NODE, &no_ospf_gr_helper_enable_lsacheck_cmd);
12842 install_element(OSPF_NODE, &ospf_gr_helper_supported_grace_time_cmd);
12843 install_element(OSPF_NODE, &no_ospf_gr_helper_supported_grace_time_cmd);
12844 install_element(OSPF_NODE, &ospf_gr_helper_planned_only_cmd);
12845 install_element(OSPF_NODE, &no_ospf_gr_helper_planned_only_cmd);
12846
12847 /* External LSA summarisation config commands.*/
12848 install_element(OSPF_NODE, &ospf_external_route_aggregation_cmd);
12849 install_element(OSPF_NODE, &no_ospf_external_route_aggregation_cmd);
12850 install_element(OSPF_NODE,
12851 &ospf_external_route_aggregation_no_adrvertise_cmd);
12852 install_element(OSPF_NODE,
12853 &no_ospf_external_route_aggregation_no_adrvertise_cmd);
12854 install_element(OSPF_NODE, &ospf_route_aggregation_timer_cmd);
12855 install_element(OSPF_NODE, &no_ospf_route_aggregation_timer_cmd);
12856 }
12857
12858 static int ospf_config_write(struct vty *vty);
12859 static struct cmd_node ospf_node = {
12860 .name = "ospf",
12861 .node = OSPF_NODE,
12862 .parent_node = CONFIG_NODE,
12863 .prompt = "%s(config-router)# ",
12864 .config_write = ospf_config_write,
12865 };
12866
12867 static void ospf_interface_clear(struct interface *ifp)
12868 {
12869 if (!if_is_operative(ifp))
12870 return;
12871
12872 if (IS_DEBUG_OSPF(ism, ISM_EVENTS))
12873 zlog_debug("ISM[%s]: clear by reset", ifp->name);
12874
12875 ospf_if_reset(ifp);
12876 }
12877
12878 DEFUN (clear_ip_ospf_interface,
12879 clear_ip_ospf_interface_cmd,
12880 "clear ip ospf [vrf NAME] interface [IFNAME]",
12881 CLEAR_STR
12882 IP_STR
12883 "OSPF information\n"
12884 VRF_CMD_HELP_STR
12885 "Interface information\n"
12886 "Interface name\n")
12887 {
12888 int idx_ifname = 0;
12889 int idx_vrf = 0;
12890 struct interface *ifp;
12891 struct listnode *node;
12892 struct ospf *ospf = NULL;
12893 char *vrf_name = NULL;
12894 vrf_id_t vrf_id = VRF_DEFAULT;
12895 struct vrf *vrf = NULL;
12896
12897 if (argv_find(argv, argc, "vrf", &idx_vrf))
12898 vrf_name = argv[idx_vrf + 1]->arg;
12899 if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME))
12900 vrf_name = NULL;
12901 if (vrf_name) {
12902 vrf = vrf_lookup_by_name(vrf_name);
12903 if (vrf)
12904 vrf_id = vrf->vrf_id;
12905 }
12906 if (!argv_find(argv, argc, "IFNAME", &idx_ifname)) {
12907 /* Clear all the ospfv2 interfaces. */
12908 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
12909 if (vrf_id != ospf->vrf_id)
12910 continue;
12911 if (!vrf)
12912 vrf = vrf_lookup_by_id(ospf->vrf_id);
12913 FOR_ALL_INTERFACES (vrf, ifp)
12914 ospf_interface_clear(ifp);
12915 }
12916 } else {
12917 /* Interface name is specified. */
12918 ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id);
12919 if (ifp == NULL)
12920 vty_out(vty, "No such interface name\n");
12921 else
12922 ospf_interface_clear(ifp);
12923 }
12924
12925 return CMD_SUCCESS;
12926 }
12927
12928 void ospf_vty_clear_init(void)
12929 {
12930 install_element(ENABLE_NODE, &clear_ip_ospf_interface_cmd);
12931 install_element(ENABLE_NODE, &clear_ip_ospf_process_cmd);
12932 install_element(ENABLE_NODE, &clear_ip_ospf_neighbor_cmd);
12933 }
12934
12935
12936 /* Install OSPF related vty commands. */
12937 void ospf_vty_init(void)
12938 {
12939 /* Install ospf top node. */
12940 install_node(&ospf_node);
12941
12942 /* "router ospf" commands. */
12943 install_element(CONFIG_NODE, &router_ospf_cmd);
12944 install_element(CONFIG_NODE, &no_router_ospf_cmd);
12945
12946
12947 install_default(OSPF_NODE);
12948
12949 /* "ospf router-id" commands. */
12950 install_element(OSPF_NODE, &ospf_router_id_cmd);
12951 install_element(OSPF_NODE, &ospf_router_id_old_cmd);
12952 install_element(OSPF_NODE, &no_ospf_router_id_cmd);
12953
12954 /* "passive-interface" commands. */
12955 install_element(OSPF_NODE, &ospf_passive_interface_default_cmd);
12956 install_element(OSPF_NODE, &ospf_passive_interface_addr_cmd);
12957 install_element(OSPF_NODE, &no_ospf_passive_interface_default_cmd);
12958 install_element(OSPF_NODE, &no_ospf_passive_interface_addr_cmd);
12959
12960 /* "ospf abr-type" commands. */
12961 install_element(OSPF_NODE, &ospf_abr_type_cmd);
12962 install_element(OSPF_NODE, &no_ospf_abr_type_cmd);
12963
12964 /* "ospf log-adjacency-changes" commands. */
12965 install_element(OSPF_NODE, &ospf_log_adjacency_changes_cmd);
12966 install_element(OSPF_NODE, &ospf_log_adjacency_changes_detail_cmd);
12967 install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_cmd);
12968 install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_detail_cmd);
12969
12970 /* "ospf rfc1583-compatible" commands. */
12971 install_element(OSPF_NODE, &ospf_compatible_rfc1583_cmd);
12972 install_element(OSPF_NODE, &no_ospf_compatible_rfc1583_cmd);
12973 install_element(OSPF_NODE, &ospf_rfc1583_flag_cmd);
12974 install_element(OSPF_NODE, &no_ospf_rfc1583_flag_cmd);
12975
12976 /* "ospf send-extra-data zebra" commands. */
12977 install_element(OSPF_NODE, &ospf_send_extra_data_cmd);
12978
12979 /* "network area" commands. */
12980 install_element(OSPF_NODE, &ospf_network_area_cmd);
12981 install_element(OSPF_NODE, &no_ospf_network_area_cmd);
12982
12983 /* "area authentication" commands. */
12984 install_element(OSPF_NODE,
12985 &ospf_area_authentication_message_digest_cmd);
12986 install_element(OSPF_NODE, &ospf_area_authentication_cmd);
12987 install_element(OSPF_NODE, &no_ospf_area_authentication_cmd);
12988
12989 /* "area range" commands. */
12990 install_element(OSPF_NODE, &ospf_area_range_cmd);
12991 install_element(OSPF_NODE, &ospf_area_range_cost_cmd);
12992 install_element(OSPF_NODE, &ospf_area_range_not_advertise_cmd);
12993 install_element(OSPF_NODE, &no_ospf_area_range_cmd);
12994 install_element(OSPF_NODE, &no_ospf_area_range_substitute_cmd);
12995
12996 /* "area virtual-link" commands. */
12997 install_element(OSPF_NODE, &ospf_area_vlink_cmd);
12998 install_element(OSPF_NODE, &ospf_area_vlink_intervals_cmd);
12999 install_element(OSPF_NODE, &no_ospf_area_vlink_cmd);
13000 install_element(OSPF_NODE, &no_ospf_area_vlink_intervals_cmd);
13001
13002
13003 /* "area stub" commands. */
13004 install_element(OSPF_NODE, &ospf_area_stub_no_summary_cmd);
13005 install_element(OSPF_NODE, &ospf_area_stub_cmd);
13006 install_element(OSPF_NODE, &no_ospf_area_stub_no_summary_cmd);
13007 install_element(OSPF_NODE, &no_ospf_area_stub_cmd);
13008
13009 /* "area nssa" commands. */
13010 install_element(OSPF_NODE, &ospf_area_nssa_cmd);
13011 install_element(OSPF_NODE, &ospf_area_nssa_translate_cmd);
13012 install_element(OSPF_NODE, &ospf_area_nssa_no_summary_cmd);
13013 install_element(OSPF_NODE, &no_ospf_area_nssa_no_summary_cmd);
13014 install_element(OSPF_NODE, &ospf_area_nssa_suppress_fa_cmd);
13015 install_element(OSPF_NODE, &no_ospf_area_nssa_suppress_fa_cmd);
13016 install_element(OSPF_NODE, &no_ospf_area_nssa_cmd);
13017
13018 install_element(OSPF_NODE, &ospf_area_default_cost_cmd);
13019 install_element(OSPF_NODE, &no_ospf_area_default_cost_cmd);
13020
13021 install_element(OSPF_NODE, &ospf_area_shortcut_cmd);
13022 install_element(OSPF_NODE, &no_ospf_area_shortcut_cmd);
13023
13024 install_element(OSPF_NODE, &ospf_area_export_list_cmd);
13025 install_element(OSPF_NODE, &no_ospf_area_export_list_cmd);
13026
13027 install_element(OSPF_NODE, &ospf_area_filter_list_cmd);
13028 install_element(OSPF_NODE, &no_ospf_area_filter_list_cmd);
13029
13030 install_element(OSPF_NODE, &ospf_area_import_list_cmd);
13031 install_element(OSPF_NODE, &no_ospf_area_import_list_cmd);
13032
13033 /* SPF timer commands */
13034 install_element(OSPF_NODE, &ospf_timers_throttle_spf_cmd);
13035 install_element(OSPF_NODE, &no_ospf_timers_throttle_spf_cmd);
13036
13037 /* LSA timers commands */
13038 install_element(OSPF_NODE, &ospf_timers_min_ls_interval_cmd);
13039 install_element(OSPF_NODE, &no_ospf_timers_min_ls_interval_cmd);
13040 install_element(OSPF_NODE, &ospf_timers_lsa_min_arrival_cmd);
13041 install_element(OSPF_NODE, &no_ospf_timers_lsa_min_arrival_cmd);
13042
13043 /* refresh timer commands */
13044 install_element(OSPF_NODE, &ospf_refresh_timer_cmd);
13045 install_element(OSPF_NODE, &no_ospf_refresh_timer_val_cmd);
13046
13047 /* max-metric commands */
13048 install_element(OSPF_NODE, &ospf_max_metric_router_lsa_admin_cmd);
13049 install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_admin_cmd);
13050 install_element(OSPF_NODE, &ospf_max_metric_router_lsa_startup_cmd);
13051 install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_startup_cmd);
13052 install_element(OSPF_NODE, &ospf_max_metric_router_lsa_shutdown_cmd);
13053 install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_shutdown_cmd);
13054
13055 /* reference bandwidth commands */
13056 install_element(OSPF_NODE, &ospf_auto_cost_reference_bandwidth_cmd);
13057 install_element(OSPF_NODE, &no_ospf_auto_cost_reference_bandwidth_cmd);
13058
13059 /* "neighbor" commands. */
13060 install_element(OSPF_NODE, &ospf_neighbor_cmd);
13061 install_element(OSPF_NODE, &ospf_neighbor_poll_interval_cmd);
13062 install_element(OSPF_NODE, &no_ospf_neighbor_cmd);
13063 install_element(OSPF_NODE, &no_ospf_neighbor_poll_cmd);
13064
13065 /* write multiplier commands */
13066 install_element(OSPF_NODE, &ospf_write_multiplier_cmd);
13067 install_element(OSPF_NODE, &write_multiplier_cmd);
13068 install_element(OSPF_NODE, &no_ospf_write_multiplier_cmd);
13069 install_element(OSPF_NODE, &no_write_multiplier_cmd);
13070
13071 /* "proactive-arp" commands. */
13072 install_element(OSPF_NODE, &ospf_proactive_arp_cmd);
13073 install_element(OSPF_NODE, &no_ospf_proactive_arp_cmd);
13074
13075 /* TI-LFA commands */
13076 install_element(OSPF_NODE, &ospf_ti_lfa_cmd);
13077 install_element(OSPF_NODE, &no_ospf_ti_lfa_cmd);
13078
13079 /* Max path configurations */
13080 install_element(OSPF_NODE, &ospf_max_multipath_cmd);
13081 install_element(OSPF_NODE, &no_ospf_max_multipath_cmd);
13082
13083 vrf_cmd_init(NULL);
13084
13085 /* Init interface related vty commands. */
13086 ospf_vty_if_init();
13087
13088 /* Init zebra related vty commands. */
13089 ospf_vty_zebra_init();
13090 }