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