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