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