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