]> git.proxmox.com Git - mirror_frr.git/blob - ospfd/ospf_vty.c
Merge pull request #12681 from pguibert6WIND/vpnv6_encode_plus
[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 if (uj) {
7319 if (use_vrf)
7320 json_object_free(json_vrf);
7321 }
7322 return CMD_WARNING;
7323 }
7324
7325 /* `show ip ospf database LSA adv-router ADV_ROUTER'. */
7326 if (strncmp(argv[arg_base + 5]->text, "s", 1) == 0)
7327 adv_router = ospf->router_id;
7328 else {
7329 ret = inet_aton(argv[arg_base + 6]->arg, &adv_router);
7330 if (!ret) {
7331 if (uj) {
7332 if (use_vrf)
7333 json_object_free(json_vrf);
7334 }
7335 return CMD_WARNING;
7336 }
7337 }
7338
7339 show_lsa_detail_adv_router(vty, ospf, type, &adv_router, json_vrf);
7340
7341 if (json) {
7342 if (use_vrf)
7343 json_object_object_add(json, ospf_get_name(ospf),
7344 json_vrf);
7345 }
7346
7347 return CMD_SUCCESS;
7348 }
7349
7350 DEFUN (show_ip_ospf_database_type_adv_router,
7351 show_ip_ospf_database_type_adv_router_cmd,
7352 "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]",
7353 SHOW_STR
7354 IP_STR
7355 "OSPF information\n"
7356 VRF_CMD_HELP_STR
7357 "All VRFs\n"
7358 "Database summary\n"
7359 OSPF_LSA_TYPES_DESC
7360 "Advertising Router link states\n"
7361 "Advertising Router (as an IP address)\n"
7362 "Self-originated link states\n"
7363 JSON_STR)
7364 {
7365 struct ospf *ospf = NULL;
7366 struct listnode *node = NULL;
7367 char *vrf_name = NULL;
7368 bool all_vrf = false;
7369 int ret = CMD_SUCCESS;
7370 int inst = 0;
7371 int idx_vrf = 0;
7372 uint8_t use_vrf = 0;
7373 bool uj = use_json(argc, argv);
7374 json_object *json = NULL;
7375
7376 if (uj)
7377 json = json_object_new_object();
7378
7379 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
7380
7381 if (vrf_name) {
7382 bool ospf_output = false;
7383
7384 use_vrf = 1;
7385
7386 if (all_vrf) {
7387 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
7388 if (!ospf->oi_running)
7389 continue;
7390 ospf_output = true;
7391 ret = show_ip_ospf_database_type_adv_router_common(
7392 vty, ospf, 2, argc, argv, use_vrf, json,
7393 uj);
7394 }
7395 if (!ospf_output)
7396 vty_out(vty, "%% OSPF is not enabled\n");
7397 } else {
7398 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
7399 if ((ospf == NULL) || !ospf->oi_running) {
7400 if (uj)
7401 vty_json(vty, json);
7402 else
7403 vty_out(vty,
7404 "%% OSPF is not enabled in vrf %s\n",
7405 vrf_name);
7406 return CMD_SUCCESS;
7407 }
7408
7409 ret = show_ip_ospf_database_type_adv_router_common(
7410 vty, ospf, 2, argc, argv, use_vrf, json, uj);
7411 }
7412 } else {
7413 /* Display default ospf (instance 0) info */
7414 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
7415 if (ospf == NULL || !ospf->oi_running) {
7416 if (uj)
7417 vty_json(vty, json);
7418 else
7419 vty_out(vty,
7420 "%% OSPF is not enabled on vrf default\n");
7421 return CMD_SUCCESS;
7422 }
7423
7424 ret = show_ip_ospf_database_type_adv_router_common(
7425 vty, ospf, 0, argc, argv, use_vrf, json, uj);
7426 }
7427
7428 if (uj) {
7429 vty_out(vty, "%s\n", json_object_to_json_string(json));
7430 json_object_free(json);
7431 }
7432
7433 return ret;
7434 }
7435
7436 DEFUN (show_ip_ospf_instance_database_type_adv_router,
7437 show_ip_ospf_instance_database_type_adv_router_cmd,
7438 "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]",
7439 SHOW_STR
7440 IP_STR
7441 "OSPF information\n"
7442 "Instance ID\n"
7443 "Database summary\n"
7444 OSPF_LSA_TYPES_DESC
7445 "Advertising Router link states\n"
7446 "Advertising Router (as an IP address)\n"
7447 "Self-originated link states\n"
7448 JSON_STR)
7449 {
7450 int idx_number = 3;
7451 struct ospf *ospf;
7452 unsigned short instance = 0;
7453 bool uj = use_json(argc, argv);
7454 json_object *json = NULL;
7455
7456 if (uj)
7457 json = json_object_new_object();
7458
7459 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7460 if (instance != ospf_instance)
7461 return CMD_NOT_MY_INSTANCE;
7462
7463 ospf = ospf_lookup_instance(instance);
7464 if (!ospf || !ospf->oi_running)
7465 return CMD_SUCCESS;
7466
7467 show_ip_ospf_database_type_adv_router_common(vty, ospf, 1, argc, argv,
7468 0, json, uj);
7469
7470 if (uj)
7471 vty_json(vty, json);
7472
7473 return CMD_SUCCESS;
7474 }
7475
7476 DEFUN (ip_ospf_authentication_args,
7477 ip_ospf_authentication_args_addr_cmd,
7478 "ip ospf authentication <null|message-digest> [A.B.C.D]",
7479 "IP Information\n"
7480 "OSPF interface commands\n"
7481 "Enable authentication on this interface\n"
7482 "Use null authentication\n"
7483 "Use message-digest authentication\n"
7484 "Address of interface\n")
7485 {
7486 VTY_DECLVAR_CONTEXT(interface, ifp);
7487 int idx_encryption = 3;
7488 int idx_ipv4 = 4;
7489 struct in_addr addr;
7490 int ret;
7491 struct ospf_if_params *params;
7492
7493 params = IF_DEF_PARAMS(ifp);
7494
7495 if (argc == 5) {
7496 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7497 if (!ret) {
7498 vty_out(vty,
7499 "Please specify interface address by A.B.C.D\n");
7500 return CMD_WARNING_CONFIG_FAILED;
7501 }
7502
7503 params = ospf_get_if_params(ifp, addr);
7504 ospf_if_update_params(ifp, addr);
7505 }
7506
7507 /* Handle null authentication */
7508 if (argv[idx_encryption]->arg[0] == 'n') {
7509 SET_IF_PARAM(params, auth_type);
7510 params->auth_type = OSPF_AUTH_NULL;
7511 return CMD_SUCCESS;
7512 }
7513
7514 /* Handle message-digest authentication */
7515 if (argv[idx_encryption]->arg[0] == 'm') {
7516 SET_IF_PARAM(params, auth_type);
7517 params->auth_type = OSPF_AUTH_CRYPTOGRAPHIC;
7518 return CMD_SUCCESS;
7519 }
7520
7521 vty_out(vty, "You shouldn't get here!\n");
7522 return CMD_WARNING_CONFIG_FAILED;
7523 }
7524
7525 DEFUN (ip_ospf_authentication,
7526 ip_ospf_authentication_addr_cmd,
7527 "ip ospf authentication [A.B.C.D]",
7528 "IP Information\n"
7529 "OSPF interface commands\n"
7530 "Enable authentication on this interface\n"
7531 "Address of interface\n")
7532 {
7533 VTY_DECLVAR_CONTEXT(interface, ifp);
7534 int idx_ipv4 = 3;
7535 struct in_addr addr;
7536 int ret;
7537 struct ospf_if_params *params;
7538
7539 params = IF_DEF_PARAMS(ifp);
7540
7541 if (argc == 4) {
7542 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7543 if (!ret) {
7544 vty_out(vty,
7545 "Please specify interface address by A.B.C.D\n");
7546 return CMD_WARNING_CONFIG_FAILED;
7547 }
7548
7549 params = ospf_get_if_params(ifp, addr);
7550 ospf_if_update_params(ifp, addr);
7551 }
7552
7553 SET_IF_PARAM(params, auth_type);
7554 params->auth_type = OSPF_AUTH_SIMPLE;
7555
7556 return CMD_SUCCESS;
7557 }
7558
7559 DEFUN (no_ip_ospf_authentication_args,
7560 no_ip_ospf_authentication_args_addr_cmd,
7561 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
7562 NO_STR
7563 "IP Information\n"
7564 "OSPF interface commands\n"
7565 "Enable authentication on this interface\n"
7566 "Use null authentication\n"
7567 "Use message-digest authentication\n"
7568 "Address of interface\n")
7569 {
7570 VTY_DECLVAR_CONTEXT(interface, ifp);
7571 int idx_encryption = 4;
7572 int idx_ipv4 = 5;
7573 struct in_addr addr;
7574 int ret;
7575 struct ospf_if_params *params;
7576 struct route_node *rn;
7577 int auth_type;
7578
7579 params = IF_DEF_PARAMS(ifp);
7580
7581 if (argc == 6) {
7582 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7583 if (!ret) {
7584 vty_out(vty,
7585 "Please specify interface address by A.B.C.D\n");
7586 return CMD_WARNING_CONFIG_FAILED;
7587 }
7588
7589 params = ospf_lookup_if_params(ifp, addr);
7590 if (params == NULL) {
7591 vty_out(vty, "Ip Address specified is unknown\n");
7592 return CMD_WARNING_CONFIG_FAILED;
7593 }
7594 params->auth_type = OSPF_AUTH_NOTSET;
7595 UNSET_IF_PARAM(params, auth_type);
7596 if (params != IF_DEF_PARAMS(ifp)) {
7597 ospf_free_if_params(ifp, addr);
7598 ospf_if_update_params(ifp, addr);
7599 }
7600 } else {
7601 if (argv[idx_encryption]->arg[0] == 'n') {
7602 auth_type = OSPF_AUTH_NULL;
7603 } else if (argv[idx_encryption]->arg[0] == 'm') {
7604 auth_type = OSPF_AUTH_CRYPTOGRAPHIC;
7605 } else {
7606 vty_out(vty, "Unexpected input encountered\n");
7607 return CMD_WARNING_CONFIG_FAILED;
7608 }
7609 /*
7610 * Here we have a case where the user has entered
7611 * 'no ip ospf authentication (null | message_digest )'
7612 * we need to find if we have any ip addresses underneath it
7613 * that
7614 * correspond to the associated type.
7615 */
7616 if (params->auth_type == auth_type) {
7617 params->auth_type = OSPF_AUTH_NOTSET;
7618 UNSET_IF_PARAM(params, auth_type);
7619 }
7620
7621 for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn;
7622 rn = route_next(rn)) {
7623 if ((params = rn->info)) {
7624 if (params->auth_type == auth_type) {
7625 params->auth_type = OSPF_AUTH_NOTSET;
7626 UNSET_IF_PARAM(params, auth_type);
7627 if (params != IF_DEF_PARAMS(ifp)) {
7628 ospf_free_if_params(
7629 ifp, rn->p.u.prefix4);
7630 ospf_if_update_params(
7631 ifp, rn->p.u.prefix4);
7632 }
7633 }
7634 }
7635 }
7636 }
7637
7638 return CMD_SUCCESS;
7639 }
7640
7641 DEFUN (no_ip_ospf_authentication,
7642 no_ip_ospf_authentication_addr_cmd,
7643 "no ip ospf authentication [A.B.C.D]",
7644 NO_STR
7645 "IP Information\n"
7646 "OSPF interface commands\n"
7647 "Enable authentication on this interface\n"
7648 "Address of interface\n")
7649 {
7650 VTY_DECLVAR_CONTEXT(interface, ifp);
7651 int idx_ipv4 = 4;
7652 struct in_addr addr;
7653 int ret;
7654 struct ospf_if_params *params;
7655 struct route_node *rn;
7656
7657 params = IF_DEF_PARAMS(ifp);
7658
7659 if (argc == 5) {
7660 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7661 if (!ret) {
7662 vty_out(vty,
7663 "Please specify interface address by A.B.C.D\n");
7664 return CMD_WARNING_CONFIG_FAILED;
7665 }
7666
7667 params = ospf_lookup_if_params(ifp, addr);
7668 if (params == NULL) {
7669 vty_out(vty, "Ip Address specified is unknown\n");
7670 return CMD_WARNING_CONFIG_FAILED;
7671 }
7672
7673 params->auth_type = OSPF_AUTH_NOTSET;
7674 UNSET_IF_PARAM(params, auth_type);
7675 if (params != IF_DEF_PARAMS(ifp)) {
7676 ospf_free_if_params(ifp, addr);
7677 ospf_if_update_params(ifp, addr);
7678 }
7679 } else {
7680 /*
7681 * When a user enters 'no ip ospf authentication'
7682 * We should remove all authentication types from
7683 * the interface.
7684 */
7685 if ((params->auth_type == OSPF_AUTH_NULL)
7686 || (params->auth_type == OSPF_AUTH_CRYPTOGRAPHIC)
7687 || (params->auth_type == OSPF_AUTH_SIMPLE)) {
7688 params->auth_type = OSPF_AUTH_NOTSET;
7689 UNSET_IF_PARAM(params, auth_type);
7690 }
7691
7692 for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn;
7693 rn = route_next(rn)) {
7694 if ((params = rn->info)) {
7695
7696 if ((params->auth_type == OSPF_AUTH_NULL)
7697 || (params->auth_type
7698 == OSPF_AUTH_CRYPTOGRAPHIC)
7699 || (params->auth_type
7700 == OSPF_AUTH_SIMPLE)) {
7701 params->auth_type = OSPF_AUTH_NOTSET;
7702 UNSET_IF_PARAM(params, auth_type);
7703 if (params != IF_DEF_PARAMS(ifp)) {
7704 ospf_free_if_params(
7705 ifp, rn->p.u.prefix4);
7706 ospf_if_update_params(
7707 ifp, rn->p.u.prefix4);
7708 }
7709 }
7710 }
7711 }
7712 }
7713
7714 return CMD_SUCCESS;
7715 }
7716
7717
7718 DEFUN (ip_ospf_authentication_key,
7719 ip_ospf_authentication_key_addr_cmd,
7720 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
7721 "IP Information\n"
7722 "OSPF interface commands\n"
7723 "Authentication password (key)\n"
7724 "The OSPF password (key)\n"
7725 "Address of interface\n")
7726 {
7727 VTY_DECLVAR_CONTEXT(interface, ifp);
7728 int idx = 0;
7729 struct in_addr addr;
7730 struct ospf_if_params *params;
7731
7732 params = IF_DEF_PARAMS(ifp);
7733
7734 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7735 if (!inet_aton(argv[idx]->arg, &addr)) {
7736 vty_out(vty,
7737 "Please specify interface address by A.B.C.D\n");
7738 return CMD_WARNING_CONFIG_FAILED;
7739 }
7740
7741 params = ospf_get_if_params(ifp, addr);
7742 ospf_if_update_params(ifp, addr);
7743 }
7744
7745 strlcpy((char *)params->auth_simple, argv[3]->arg,
7746 sizeof(params->auth_simple));
7747 SET_IF_PARAM(params, auth_simple);
7748
7749 return CMD_SUCCESS;
7750 }
7751
7752 DEFUN_HIDDEN (ospf_authentication_key,
7753 ospf_authentication_key_cmd,
7754 "ospf authentication-key AUTH_KEY [A.B.C.D]",
7755 "OSPF interface commands\n"
7756 VLINK_HELPSTR_AUTH_SIMPLE
7757 "Address of interface\n")
7758 {
7759 return ip_ospf_authentication_key(self, vty, argc, argv);
7760 }
7761
7762 DEFUN (no_ip_ospf_authentication_key,
7763 no_ip_ospf_authentication_key_authkey_addr_cmd,
7764 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7765 NO_STR
7766 "IP Information\n"
7767 "OSPF interface commands\n"
7768 VLINK_HELPSTR_AUTH_SIMPLE
7769 "Address of interface\n")
7770 {
7771 VTY_DECLVAR_CONTEXT(interface, ifp);
7772 int idx = 0;
7773 struct in_addr addr;
7774 struct ospf_if_params *params;
7775 params = IF_DEF_PARAMS(ifp);
7776
7777 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7778 if (!inet_aton(argv[idx]->arg, &addr)) {
7779 vty_out(vty,
7780 "Please specify interface address by A.B.C.D\n");
7781 return CMD_WARNING_CONFIG_FAILED;
7782 }
7783
7784 params = ospf_lookup_if_params(ifp, addr);
7785 if (params == NULL)
7786 return CMD_SUCCESS;
7787 }
7788
7789 memset(params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE);
7790 UNSET_IF_PARAM(params, auth_simple);
7791
7792 if (params != IF_DEF_PARAMS(ifp)) {
7793 ospf_free_if_params(ifp, addr);
7794 ospf_if_update_params(ifp, addr);
7795 }
7796
7797 return CMD_SUCCESS;
7798 }
7799
7800 DEFUN_HIDDEN (no_ospf_authentication_key,
7801 no_ospf_authentication_key_authkey_addr_cmd,
7802 "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7803 NO_STR
7804 "OSPF interface commands\n"
7805 VLINK_HELPSTR_AUTH_SIMPLE
7806 "Address of interface\n")
7807 {
7808 return no_ip_ospf_authentication_key(self, vty, argc, argv);
7809 }
7810
7811 DEFUN (ip_ospf_message_digest_key,
7812 ip_ospf_message_digest_key_cmd,
7813 "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7814 "IP Information\n"
7815 "OSPF interface commands\n"
7816 "Message digest authentication password (key)\n"
7817 "Key ID\n"
7818 "Use MD5 algorithm\n"
7819 "The OSPF password (key)\n"
7820 "Address of interface\n")
7821 {
7822 VTY_DECLVAR_CONTEXT(interface, ifp);
7823 struct crypt_key *ck;
7824 uint8_t key_id;
7825 struct in_addr addr;
7826 struct ospf_if_params *params;
7827
7828 params = IF_DEF_PARAMS(ifp);
7829 int idx = 0;
7830
7831 argv_find(argv, argc, "(1-255)", &idx);
7832 char *keyid = argv[idx]->arg;
7833 argv_find(argv, argc, "KEY", &idx);
7834 char *cryptkey = argv[idx]->arg;
7835
7836 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7837 if (!inet_aton(argv[idx]->arg, &addr)) {
7838 vty_out(vty,
7839 "Please specify interface address by A.B.C.D\n");
7840 return CMD_WARNING_CONFIG_FAILED;
7841 }
7842
7843 params = ospf_get_if_params(ifp, addr);
7844 ospf_if_update_params(ifp, addr);
7845 }
7846
7847 key_id = strtol(keyid, NULL, 10);
7848
7849 /* Remove existing key, if any */
7850 ospf_crypt_key_delete(params->auth_crypt, key_id);
7851
7852 ck = ospf_crypt_key_new();
7853 ck->key_id = (uint8_t)key_id;
7854 strlcpy((char *)ck->auth_key, cryptkey, sizeof(ck->auth_key));
7855
7856 ospf_crypt_key_add(params->auth_crypt, ck);
7857 SET_IF_PARAM(params, auth_crypt);
7858
7859 return CMD_SUCCESS;
7860 }
7861
7862 DEFUN_HIDDEN (ospf_message_digest_key,
7863 ospf_message_digest_key_cmd,
7864 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7865 "OSPF interface commands\n"
7866 "Message digest authentication password (key)\n"
7867 "Key ID\n"
7868 "Use MD5 algorithm\n"
7869 "The OSPF password (key)\n"
7870 "Address of interface\n")
7871 {
7872 return ip_ospf_message_digest_key(self, vty, argc, argv);
7873 }
7874
7875 DEFUN (no_ip_ospf_message_digest_key,
7876 no_ip_ospf_message_digest_key_cmd,
7877 "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7878 NO_STR
7879 "IP Information\n"
7880 "OSPF interface commands\n"
7881 "Message digest authentication password (key)\n"
7882 "Key ID\n"
7883 "Use MD5 algorithm\n"
7884 "The OSPF password (key)\n"
7885 "Address of interface\n")
7886 {
7887 VTY_DECLVAR_CONTEXT(interface, ifp);
7888 int idx = 0;
7889 struct crypt_key *ck;
7890 int key_id;
7891 struct in_addr addr;
7892 struct ospf_if_params *params;
7893 params = IF_DEF_PARAMS(ifp);
7894
7895 argv_find(argv, argc, "(1-255)", &idx);
7896 char *keyid = argv[idx]->arg;
7897
7898 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7899 if (!inet_aton(argv[idx]->arg, &addr)) {
7900 vty_out(vty,
7901 "Please specify interface address by A.B.C.D\n");
7902 return CMD_WARNING_CONFIG_FAILED;
7903 }
7904
7905 params = ospf_lookup_if_params(ifp, addr);
7906 if (params == NULL)
7907 return CMD_SUCCESS;
7908 }
7909
7910 key_id = strtol(keyid, NULL, 10);
7911 ck = ospf_crypt_key_lookup(params->auth_crypt, key_id);
7912 if (ck == NULL) {
7913 vty_out(vty, "OSPF: Key %d does not exist\n", key_id);
7914 return CMD_WARNING_CONFIG_FAILED;
7915 }
7916
7917 ospf_crypt_key_delete(params->auth_crypt, key_id);
7918
7919 if (params != IF_DEF_PARAMS(ifp)) {
7920 ospf_free_if_params(ifp, addr);
7921 ospf_if_update_params(ifp, addr);
7922 }
7923
7924 return CMD_SUCCESS;
7925 }
7926
7927 DEFUN_HIDDEN (no_ospf_message_digest_key,
7928 no_ospf_message_digest_key_cmd,
7929 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7930 NO_STR
7931 "OSPF interface commands\n"
7932 "Message digest authentication password (key)\n"
7933 "Key ID\n"
7934 "Use MD5 algorithm\n"
7935 "The OSPF password (key)\n"
7936 "Address of interface\n")
7937 {
7938 return no_ip_ospf_message_digest_key(self, vty, argc, argv);
7939 }
7940
7941 DEFUN (ip_ospf_cost,
7942 ip_ospf_cost_cmd,
7943 "ip ospf cost (1-65535) [A.B.C.D]",
7944 "IP Information\n"
7945 "OSPF interface commands\n"
7946 "Interface cost\n"
7947 "Cost\n"
7948 "Address of interface\n")
7949 {
7950 VTY_DECLVAR_CONTEXT(interface, ifp);
7951 int idx = 0;
7952 uint32_t cost = OSPF_OUTPUT_COST_DEFAULT;
7953 struct in_addr addr;
7954 struct ospf_if_params *params;
7955 params = IF_DEF_PARAMS(ifp);
7956
7957 // get arguments
7958 char *coststr = NULL, *ifaddr = NULL;
7959
7960 argv_find(argv, argc, "(1-65535)", &idx);
7961 coststr = argv[idx]->arg;
7962 cost = strtol(coststr, NULL, 10);
7963
7964 ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
7965 if (ifaddr) {
7966 if (!inet_aton(ifaddr, &addr)) {
7967 vty_out(vty,
7968 "Please specify interface address by A.B.C.D\n");
7969 return CMD_WARNING_CONFIG_FAILED;
7970 }
7971
7972 params = ospf_get_if_params(ifp, addr);
7973 ospf_if_update_params(ifp, addr);
7974 }
7975
7976 SET_IF_PARAM(params, output_cost_cmd);
7977 params->output_cost_cmd = cost;
7978
7979 ospf_if_recalculate_output_cost(ifp);
7980
7981 return CMD_SUCCESS;
7982 }
7983
7984 DEFUN_HIDDEN (ospf_cost,
7985 ospf_cost_cmd,
7986 "ospf cost (1-65535) [A.B.C.D]",
7987 "OSPF interface commands\n"
7988 "Interface cost\n"
7989 "Cost\n"
7990 "Address of interface\n")
7991 {
7992 return ip_ospf_cost(self, vty, argc, argv);
7993 }
7994
7995 DEFUN (no_ip_ospf_cost,
7996 no_ip_ospf_cost_cmd,
7997 "no ip ospf cost [(1-65535)] [A.B.C.D]",
7998 NO_STR
7999 "IP Information\n"
8000 "OSPF interface commands\n"
8001 "Interface cost\n"
8002 "Cost\n"
8003 "Address of interface\n")
8004 {
8005 VTY_DECLVAR_CONTEXT(interface, ifp);
8006 int idx = 0;
8007 struct in_addr addr;
8008 struct ospf_if_params *params;
8009
8010 params = IF_DEF_PARAMS(ifp);
8011
8012 // get arguments
8013 char *ifaddr = NULL;
8014 ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
8015
8016 /* According to the semantics we are mimicking "no ip ospf cost N" is
8017 * always treated as "no ip ospf cost" regardless of the actual value
8018 * of N already configured for the interface. Thus ignore cost. */
8019
8020 if (ifaddr) {
8021 if (!inet_aton(ifaddr, &addr)) {
8022 vty_out(vty,
8023 "Please specify interface address by A.B.C.D\n");
8024 return CMD_WARNING_CONFIG_FAILED;
8025 }
8026
8027 params = ospf_lookup_if_params(ifp, addr);
8028 if (params == NULL)
8029 return CMD_SUCCESS;
8030 }
8031
8032 UNSET_IF_PARAM(params, output_cost_cmd);
8033
8034 if (params != IF_DEF_PARAMS(ifp)) {
8035 ospf_free_if_params(ifp, addr);
8036 ospf_if_update_params(ifp, addr);
8037 }
8038
8039 ospf_if_recalculate_output_cost(ifp);
8040
8041 return CMD_SUCCESS;
8042 }
8043
8044 DEFUN_HIDDEN (no_ospf_cost,
8045 no_ospf_cost_cmd,
8046 "no ospf cost [(1-65535)] [A.B.C.D]",
8047 NO_STR
8048 "OSPF interface commands\n"
8049 "Interface cost\n"
8050 "Cost\n"
8051 "Address of interface\n")
8052 {
8053 return no_ip_ospf_cost(self, vty, argc, argv);
8054 }
8055
8056 static void ospf_nbr_timer_update(struct ospf_interface *oi)
8057 {
8058 struct route_node *rn;
8059 struct ospf_neighbor *nbr;
8060
8061 for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
8062 nbr = rn->info;
8063
8064 if (!nbr)
8065 continue;
8066
8067 nbr->v_inactivity = OSPF_IF_PARAM(oi, v_wait);
8068 nbr->v_db_desc = OSPF_IF_PARAM(oi, retransmit_interval);
8069 nbr->v_ls_req = OSPF_IF_PARAM(oi, retransmit_interval);
8070 nbr->v_ls_upd = OSPF_IF_PARAM(oi, retransmit_interval);
8071 }
8072 }
8073
8074 static int ospf_vty_dead_interval_set(struct vty *vty, const char *interval_str,
8075 const char *nbr_str,
8076 const char *fast_hello_str)
8077 {
8078 VTY_DECLVAR_CONTEXT(interface, ifp);
8079 uint32_t seconds;
8080 uint8_t hellomult;
8081 struct in_addr addr;
8082 int ret;
8083 struct ospf_if_params *params;
8084 struct ospf_interface *oi;
8085 struct route_node *rn;
8086
8087 params = IF_DEF_PARAMS(ifp);
8088
8089 if (nbr_str) {
8090 ret = inet_aton(nbr_str, &addr);
8091 if (!ret) {
8092 vty_out(vty,
8093 "Please specify interface address by A.B.C.D\n");
8094 return CMD_WARNING_CONFIG_FAILED;
8095 }
8096
8097 params = ospf_get_if_params(ifp, addr);
8098 ospf_if_update_params(ifp, addr);
8099 }
8100
8101 if (interval_str) {
8102 seconds = strtoul(interval_str, NULL, 10);
8103
8104 /* reset fast_hello too, just to be sure */
8105 UNSET_IF_PARAM(params, fast_hello);
8106 params->fast_hello = OSPF_FAST_HELLO_DEFAULT;
8107 } else if (fast_hello_str) {
8108 hellomult = strtoul(fast_hello_str, NULL, 10);
8109 /* 1s dead-interval with sub-second hellos desired */
8110 seconds = OSPF_ROUTER_DEAD_INTERVAL_MINIMAL;
8111 SET_IF_PARAM(params, fast_hello);
8112 params->fast_hello = hellomult;
8113 } else {
8114 vty_out(vty,
8115 "Please specify dead-interval or hello-multiplier\n");
8116 return CMD_WARNING_CONFIG_FAILED;
8117 }
8118
8119 SET_IF_PARAM(params, v_wait);
8120 params->v_wait = seconds;
8121 params->is_v_wait_set = true;
8122
8123 /* Update timer values in neighbor structure. */
8124 if (nbr_str) {
8125 struct ospf *ospf = NULL;
8126
8127 ospf = ifp->vrf->info;
8128 if (ospf) {
8129 oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr);
8130 if (oi)
8131 ospf_nbr_timer_update(oi);
8132 }
8133 } else {
8134 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn))
8135 if ((oi = rn->info))
8136 ospf_nbr_timer_update(oi);
8137 }
8138
8139 return CMD_SUCCESS;
8140 }
8141
8142 DEFUN (ip_ospf_dead_interval,
8143 ip_ospf_dead_interval_cmd,
8144 "ip ospf dead-interval (1-65535) [A.B.C.D]",
8145 "IP Information\n"
8146 "OSPF interface commands\n"
8147 "Interval time after which a neighbor is declared down\n"
8148 "Seconds\n"
8149 "Address of interface\n")
8150 {
8151 int idx = 0;
8152 char *interval = argv_find(argv, argc, "(1-65535)", &idx)
8153 ? argv[idx]->arg
8154 : NULL;
8155 char *ifaddr =
8156 argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
8157 return ospf_vty_dead_interval_set(vty, interval, ifaddr, NULL);
8158 }
8159
8160
8161 DEFUN_HIDDEN (ospf_dead_interval,
8162 ospf_dead_interval_cmd,
8163 "ospf dead-interval (1-65535) [A.B.C.D]",
8164 "OSPF interface commands\n"
8165 "Interval time after which a neighbor is declared down\n"
8166 "Seconds\n"
8167 "Address of interface\n")
8168 {
8169 return ip_ospf_dead_interval(self, vty, argc, argv);
8170 }
8171
8172 DEFUN (ip_ospf_dead_interval_minimal,
8173 ip_ospf_dead_interval_minimal_addr_cmd,
8174 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
8175 "IP Information\n"
8176 "OSPF interface commands\n"
8177 "Interval time after which a neighbor is declared down\n"
8178 "Minimal 1s dead-interval with fast sub-second hellos\n"
8179 "Hello multiplier factor\n"
8180 "Number of Hellos to send each second\n"
8181 "Address of interface\n")
8182 {
8183 int idx_number = 5;
8184 int idx_ipv4 = 6;
8185 if (argc == 7)
8186 return ospf_vty_dead_interval_set(
8187 vty, NULL, argv[idx_ipv4]->arg, argv[idx_number]->arg);
8188 else
8189 return ospf_vty_dead_interval_set(vty, NULL, NULL,
8190 argv[idx_number]->arg);
8191 }
8192
8193 DEFUN (no_ip_ospf_dead_interval,
8194 no_ip_ospf_dead_interval_cmd,
8195 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8196 NO_STR
8197 "IP Information\n"
8198 "OSPF interface commands\n"
8199 "Interval time after which a neighbor is declared down\n"
8200 "Seconds\n"
8201 "Minimal 1s dead-interval with fast sub-second hellos\n"
8202 "Hello multiplier factor\n"
8203 "Number of Hellos to send each second\n"
8204 "Address of interface\n")
8205 {
8206 VTY_DECLVAR_CONTEXT(interface, ifp);
8207 int idx_ipv4 = argc - 1;
8208 struct in_addr addr = {.s_addr = 0L};
8209 int ret;
8210 struct ospf_if_params *params;
8211 struct ospf_interface *oi;
8212 struct route_node *rn;
8213
8214 params = IF_DEF_PARAMS(ifp);
8215
8216 if (argv[idx_ipv4]->type == IPV4_TKN) {
8217 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
8218 if (!ret) {
8219 vty_out(vty,
8220 "Please specify interface address by A.B.C.D\n");
8221 return CMD_WARNING_CONFIG_FAILED;
8222 }
8223
8224 params = ospf_lookup_if_params(ifp, addr);
8225 if (params == NULL)
8226 return CMD_SUCCESS;
8227 }
8228
8229 UNSET_IF_PARAM(params, v_wait);
8230 params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
8231 params->is_v_wait_set = false;
8232
8233 UNSET_IF_PARAM(params, fast_hello);
8234 params->fast_hello = OSPF_FAST_HELLO_DEFAULT;
8235
8236 if (params != IF_DEF_PARAMS(ifp)) {
8237 ospf_free_if_params(ifp, addr);
8238 ospf_if_update_params(ifp, addr);
8239 }
8240
8241 /* Update timer values in neighbor structure. */
8242 if (argc == 1) {
8243 struct ospf *ospf = NULL;
8244
8245 ospf = ifp->vrf->info;
8246 if (ospf) {
8247 oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr);
8248 if (oi)
8249 ospf_nbr_timer_update(oi);
8250 }
8251 } else {
8252 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn))
8253 if ((oi = rn->info))
8254 ospf_nbr_timer_update(oi);
8255 }
8256
8257 return CMD_SUCCESS;
8258 }
8259
8260 DEFUN_HIDDEN (no_ospf_dead_interval,
8261 no_ospf_dead_interval_cmd,
8262 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8263 NO_STR
8264 "OSPF interface commands\n"
8265 "Interval time after which a neighbor is declared down\n"
8266 "Seconds\n"
8267 "Minimal 1s dead-interval with fast sub-second hellos\n"
8268 "Hello multiplier factor\n"
8269 "Number of Hellos to send each second\n"
8270 "Address of interface\n")
8271 {
8272 return no_ip_ospf_dead_interval(self, vty, argc, argv);
8273 }
8274
8275 DEFUN (ip_ospf_hello_interval,
8276 ip_ospf_hello_interval_cmd,
8277 "ip ospf hello-interval (1-65535) [A.B.C.D]",
8278 "IP Information\n"
8279 "OSPF interface commands\n"
8280 "Time between HELLO packets\n"
8281 "Seconds\n"
8282 "Address of interface\n")
8283 {
8284 VTY_DECLVAR_CONTEXT(interface, ifp);
8285 int idx = 0;
8286 struct in_addr addr = {.s_addr = 0L};
8287 struct ospf_if_params *params;
8288 params = IF_DEF_PARAMS(ifp);
8289 uint32_t seconds = 0;
8290 bool is_addr = false;
8291 uint32_t old_interval = 0;
8292
8293 argv_find(argv, argc, "(1-65535)", &idx);
8294 seconds = strtol(argv[idx]->arg, NULL, 10);
8295
8296 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8297 if (!inet_aton(argv[idx]->arg, &addr)) {
8298 vty_out(vty,
8299 "Please specify interface address by A.B.C.D\n");
8300 return CMD_WARNING_CONFIG_FAILED;
8301 }
8302
8303 params = ospf_get_if_params(ifp, addr);
8304 ospf_if_update_params(ifp, addr);
8305 is_addr = true;
8306 }
8307
8308 old_interval = params->v_hello;
8309
8310 /* Return, if same interval is configured. */
8311 if (old_interval == seconds)
8312 return CMD_SUCCESS;
8313
8314 SET_IF_PARAM(params, v_hello);
8315 params->v_hello = seconds;
8316
8317 if (!params->is_v_wait_set) {
8318 SET_IF_PARAM(params, v_wait);
8319 /* As per RFC 4062
8320 * The router dead interval should
8321 * be some multiple of the HelloInterval (perhaps 4 times the
8322 * hello interval) and must be the same for all routers
8323 * attached to a common network.
8324 */
8325 params->v_wait = 4 * seconds;
8326 }
8327
8328 ospf_reset_hello_timer(ifp, addr, is_addr);
8329
8330 return CMD_SUCCESS;
8331 }
8332
8333 DEFUN_HIDDEN (ospf_hello_interval,
8334 ospf_hello_interval_cmd,
8335 "ospf hello-interval (1-65535) [A.B.C.D]",
8336 "OSPF interface commands\n"
8337 "Time between HELLO packets\n"
8338 "Seconds\n"
8339 "Address of interface\n")
8340 {
8341 return ip_ospf_hello_interval(self, vty, argc, argv);
8342 }
8343
8344 DEFUN (no_ip_ospf_hello_interval,
8345 no_ip_ospf_hello_interval_cmd,
8346 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
8347 NO_STR
8348 "IP Information\n"
8349 "OSPF interface commands\n"
8350 "Time between HELLO packets\n" // ignored
8351 "Seconds\n"
8352 "Address of interface\n")
8353 {
8354 VTY_DECLVAR_CONTEXT(interface, ifp);
8355 int idx = 0;
8356 struct in_addr addr = {.s_addr = 0L};
8357 struct ospf_if_params *params;
8358 struct route_node *rn;
8359
8360 params = IF_DEF_PARAMS(ifp);
8361
8362 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8363 if (!inet_aton(argv[idx]->arg, &addr)) {
8364 vty_out(vty,
8365 "Please specify interface address by A.B.C.D\n");
8366 return CMD_WARNING_CONFIG_FAILED;
8367 }
8368
8369 params = ospf_lookup_if_params(ifp, addr);
8370 if (params == NULL)
8371 return CMD_SUCCESS;
8372 }
8373
8374 UNSET_IF_PARAM(params, v_hello);
8375 params->v_hello = OSPF_HELLO_INTERVAL_DEFAULT;
8376
8377 if (!params->is_v_wait_set) {
8378 UNSET_IF_PARAM(params, v_wait);
8379 params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
8380 }
8381
8382 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8383 struct ospf_interface *oi = rn->info;
8384
8385 if (!oi)
8386 continue;
8387
8388 oi->type = IF_DEF_PARAMS(ifp)->type;
8389 oi->ptp_dmvpn = IF_DEF_PARAMS(ifp)->ptp_dmvpn;
8390
8391 if (oi->state > ISM_Down) {
8392 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown);
8393 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp);
8394 }
8395 }
8396
8397 if (params != IF_DEF_PARAMS(ifp)) {
8398 ospf_free_if_params(ifp, addr);
8399 ospf_if_update_params(ifp, addr);
8400 }
8401
8402 return CMD_SUCCESS;
8403 }
8404
8405 DEFUN_HIDDEN (no_ospf_hello_interval,
8406 no_ospf_hello_interval_cmd,
8407 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
8408 NO_STR
8409 "OSPF interface commands\n"
8410 "Time between HELLO packets\n" // ignored
8411 "Seconds\n"
8412 "Address of interface\n")
8413 {
8414 return no_ip_ospf_hello_interval(self, vty, argc, argv);
8415 }
8416
8417 DEFUN(ip_ospf_network, ip_ospf_network_cmd,
8418 "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point [dmvpn]>",
8419 "IP Information\n"
8420 "OSPF interface commands\n"
8421 "Network type\n"
8422 "Specify OSPF broadcast multi-access network\n"
8423 "Specify OSPF NBMA network\n"
8424 "Specify OSPF point-to-multipoint network\n"
8425 "Specify OSPF point-to-point network\n"
8426 "Specify OSPF point-to-point DMVPN network\n")
8427 {
8428 VTY_DECLVAR_CONTEXT(interface, ifp);
8429 int idx = 0;
8430 int old_type = IF_DEF_PARAMS(ifp)->type;
8431 uint8_t old_ptp_dmvpn = IF_DEF_PARAMS(ifp)->ptp_dmvpn;
8432 struct route_node *rn;
8433
8434 if (old_type == OSPF_IFTYPE_LOOPBACK) {
8435 vty_out(vty,
8436 "This is a loopback interface. Can't set network type.\n");
8437 return CMD_WARNING_CONFIG_FAILED;
8438 }
8439
8440 IF_DEF_PARAMS(ifp)->ptp_dmvpn = 0;
8441
8442 if (argv_find(argv, argc, "broadcast", &idx))
8443 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_BROADCAST;
8444 else if (argv_find(argv, argc, "non-broadcast", &idx))
8445 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_NBMA;
8446 else if (argv_find(argv, argc, "point-to-multipoint", &idx))
8447 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOMULTIPOINT;
8448 else if (argv_find(argv, argc, "point-to-point", &idx)) {
8449 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOPOINT;
8450 if (argv_find(argv, argc, "dmvpn", &idx))
8451 IF_DEF_PARAMS(ifp)->ptp_dmvpn = 1;
8452 }
8453
8454 if (IF_DEF_PARAMS(ifp)->type == old_type
8455 && IF_DEF_PARAMS(ifp)->ptp_dmvpn == old_ptp_dmvpn)
8456 return CMD_SUCCESS;
8457
8458 SET_IF_PARAM(IF_DEF_PARAMS(ifp), type);
8459
8460 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8461 struct ospf_interface *oi = rn->info;
8462
8463 if (!oi)
8464 continue;
8465
8466 oi->type = IF_DEF_PARAMS(ifp)->type;
8467
8468 if (oi->state > ISM_Down) {
8469 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown);
8470 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp);
8471 }
8472 }
8473
8474 return CMD_SUCCESS;
8475 }
8476
8477 DEFUN_HIDDEN (ospf_network,
8478 ospf_network_cmd,
8479 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
8480 "OSPF interface commands\n"
8481 "Network type\n"
8482 "Specify OSPF broadcast multi-access network\n"
8483 "Specify OSPF NBMA network\n"
8484 "Specify OSPF point-to-multipoint network\n"
8485 "Specify OSPF point-to-point network\n")
8486 {
8487 return ip_ospf_network(self, vty, argc, argv);
8488 }
8489
8490 DEFUN (no_ip_ospf_network,
8491 no_ip_ospf_network_cmd,
8492 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8493 NO_STR
8494 "IP Information\n"
8495 "OSPF interface commands\n"
8496 "Network type\n"
8497 "Specify OSPF broadcast multi-access network\n"
8498 "Specify OSPF NBMA network\n"
8499 "Specify OSPF point-to-multipoint network\n"
8500 "Specify OSPF point-to-point network\n")
8501 {
8502 VTY_DECLVAR_CONTEXT(interface, ifp);
8503 int old_type = IF_DEF_PARAMS(ifp)->type;
8504 struct route_node *rn;
8505
8506 IF_DEF_PARAMS(ifp)->type = ospf_default_iftype(ifp);
8507 IF_DEF_PARAMS(ifp)->ptp_dmvpn = 0;
8508
8509 if (IF_DEF_PARAMS(ifp)->type == old_type)
8510 return CMD_SUCCESS;
8511
8512 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8513 struct ospf_interface *oi = rn->info;
8514
8515 if (!oi)
8516 continue;
8517
8518 oi->type = IF_DEF_PARAMS(ifp)->type;
8519
8520 if (oi->state > ISM_Down) {
8521 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown);
8522 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp);
8523 }
8524 }
8525
8526 return CMD_SUCCESS;
8527 }
8528
8529 DEFUN_HIDDEN (no_ospf_network,
8530 no_ospf_network_cmd,
8531 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8532 NO_STR
8533 "OSPF interface commands\n"
8534 "Network type\n"
8535 "Specify OSPF broadcast multi-access network\n"
8536 "Specify OSPF NBMA network\n"
8537 "Specify OSPF point-to-multipoint network\n"
8538 "Specify OSPF point-to-point network\n")
8539 {
8540 return no_ip_ospf_network(self, vty, argc, argv);
8541 }
8542
8543 DEFUN (ip_ospf_priority,
8544 ip_ospf_priority_cmd,
8545 "ip ospf priority (0-255) [A.B.C.D]",
8546 "IP Information\n"
8547 "OSPF interface commands\n"
8548 "Router priority\n"
8549 "Priority\n"
8550 "Address of interface\n")
8551 {
8552 VTY_DECLVAR_CONTEXT(interface, ifp);
8553 int idx = 0;
8554 long priority;
8555 struct route_node *rn;
8556 struct in_addr addr;
8557 struct ospf_if_params *params;
8558 params = IF_DEF_PARAMS(ifp);
8559
8560 argv_find(argv, argc, "(0-255)", &idx);
8561 priority = strtol(argv[idx]->arg, NULL, 10);
8562
8563 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8564 if (!inet_aton(argv[idx]->arg, &addr)) {
8565 vty_out(vty,
8566 "Please specify interface address by A.B.C.D\n");
8567 return CMD_WARNING_CONFIG_FAILED;
8568 }
8569
8570 params = ospf_get_if_params(ifp, addr);
8571 ospf_if_update_params(ifp, addr);
8572 }
8573
8574 SET_IF_PARAM(params, priority);
8575 params->priority = priority;
8576
8577 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8578 struct ospf_interface *oi = rn->info;
8579
8580 if (!oi)
8581 continue;
8582
8583 if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) {
8584 PRIORITY(oi) = OSPF_IF_PARAM(oi, priority);
8585 OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange);
8586 }
8587 }
8588
8589 return CMD_SUCCESS;
8590 }
8591
8592 DEFUN_HIDDEN (ospf_priority,
8593 ospf_priority_cmd,
8594 "ospf priority (0-255) [A.B.C.D]",
8595 "OSPF interface commands\n"
8596 "Router priority\n"
8597 "Priority\n"
8598 "Address of interface\n")
8599 {
8600 return ip_ospf_priority(self, vty, argc, argv);
8601 }
8602
8603 DEFUN (no_ip_ospf_priority,
8604 no_ip_ospf_priority_cmd,
8605 "no ip ospf priority [(0-255) [A.B.C.D]]",
8606 NO_STR
8607 "IP Information\n"
8608 "OSPF interface commands\n"
8609 "Router priority\n" // ignored
8610 "Priority\n"
8611 "Address of interface\n")
8612 {
8613 VTY_DECLVAR_CONTEXT(interface, ifp);
8614 int idx = 0;
8615 struct route_node *rn;
8616 struct in_addr addr;
8617 struct ospf_if_params *params;
8618
8619 params = IF_DEF_PARAMS(ifp);
8620
8621 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8622 if (!inet_aton(argv[idx]->arg, &addr)) {
8623 vty_out(vty,
8624 "Please specify interface address by A.B.C.D\n");
8625 return CMD_WARNING_CONFIG_FAILED;
8626 }
8627
8628 params = ospf_lookup_if_params(ifp, addr);
8629 if (params == NULL)
8630 return CMD_SUCCESS;
8631 }
8632
8633 UNSET_IF_PARAM(params, priority);
8634 params->priority = OSPF_ROUTER_PRIORITY_DEFAULT;
8635
8636 if (params != IF_DEF_PARAMS(ifp)) {
8637 ospf_free_if_params(ifp, addr);
8638 ospf_if_update_params(ifp, addr);
8639 }
8640
8641 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8642 struct ospf_interface *oi = rn->info;
8643
8644 if (!oi)
8645 continue;
8646
8647 if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) {
8648 PRIORITY(oi) = OSPF_IF_PARAM(oi, priority);
8649 OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange);
8650 }
8651 }
8652
8653 return CMD_SUCCESS;
8654 }
8655
8656 DEFUN_HIDDEN (no_ospf_priority,
8657 no_ospf_priority_cmd,
8658 "no ospf priority [(0-255) [A.B.C.D]]",
8659 NO_STR
8660 "OSPF interface commands\n"
8661 "Router priority\n"
8662 "Priority\n"
8663 "Address of interface\n")
8664 {
8665 return no_ip_ospf_priority(self, vty, argc, argv);
8666 }
8667
8668 DEFUN (ip_ospf_retransmit_interval,
8669 ip_ospf_retransmit_interval_addr_cmd,
8670 "ip ospf retransmit-interval (1-65535) [A.B.C.D]",
8671 "IP Information\n"
8672 "OSPF interface commands\n"
8673 "Time between retransmitting lost link state advertisements\n"
8674 "Seconds\n"
8675 "Address of interface\n")
8676 {
8677 VTY_DECLVAR_CONTEXT(interface, ifp);
8678 int idx = 0;
8679 uint32_t seconds;
8680 struct in_addr addr;
8681 struct ospf_if_params *params;
8682 params = IF_DEF_PARAMS(ifp);
8683
8684 argv_find(argv, argc, "(1-65535)", &idx);
8685 seconds = strtol(argv[idx]->arg, NULL, 10);
8686
8687 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8688 if (!inet_aton(argv[idx]->arg, &addr)) {
8689 vty_out(vty,
8690 "Please specify interface address by A.B.C.D\n");
8691 return CMD_WARNING_CONFIG_FAILED;
8692 }
8693
8694 params = ospf_get_if_params(ifp, addr);
8695 ospf_if_update_params(ifp, addr);
8696 }
8697
8698 SET_IF_PARAM(params, retransmit_interval);
8699 params->retransmit_interval = seconds;
8700
8701 return CMD_SUCCESS;
8702 }
8703
8704 DEFUN_HIDDEN (ospf_retransmit_interval,
8705 ospf_retransmit_interval_cmd,
8706 "ospf retransmit-interval (1-65535) [A.B.C.D]",
8707 "OSPF interface commands\n"
8708 "Time between retransmitting lost link state advertisements\n"
8709 "Seconds\n"
8710 "Address of interface\n")
8711 {
8712 return ip_ospf_retransmit_interval(self, vty, argc, argv);
8713 }
8714
8715 DEFUN (no_ip_ospf_retransmit_interval,
8716 no_ip_ospf_retransmit_interval_addr_cmd,
8717 "no ip ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8718 NO_STR
8719 "IP Information\n"
8720 "OSPF interface commands\n"
8721 "Time between retransmitting lost link state advertisements\n"
8722 "Seconds\n"
8723 "Address of interface\n")
8724 {
8725 VTY_DECLVAR_CONTEXT(interface, ifp);
8726 int idx = 0;
8727 struct in_addr addr;
8728 struct ospf_if_params *params;
8729
8730 params = IF_DEF_PARAMS(ifp);
8731
8732 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8733 if (!inet_aton(argv[idx]->arg, &addr)) {
8734 vty_out(vty,
8735 "Please specify interface address by A.B.C.D\n");
8736 return CMD_WARNING_CONFIG_FAILED;
8737 }
8738
8739 params = ospf_lookup_if_params(ifp, addr);
8740 if (params == NULL)
8741 return CMD_SUCCESS;
8742 }
8743
8744 UNSET_IF_PARAM(params, retransmit_interval);
8745 params->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT;
8746
8747 if (params != IF_DEF_PARAMS(ifp)) {
8748 ospf_free_if_params(ifp, addr);
8749 ospf_if_update_params(ifp, addr);
8750 }
8751
8752 return CMD_SUCCESS;
8753 }
8754
8755 DEFUN_HIDDEN (no_ospf_retransmit_interval,
8756 no_ospf_retransmit_interval_cmd,
8757 "no ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8758 NO_STR
8759 "OSPF interface commands\n"
8760 "Time between retransmitting lost link state advertisements\n"
8761 "Seconds\n"
8762 "Address of interface\n")
8763 {
8764 return no_ip_ospf_retransmit_interval(self, vty, argc, argv);
8765 }
8766
8767 DEFUN (ip_ospf_transmit_delay,
8768 ip_ospf_transmit_delay_addr_cmd,
8769 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
8770 "IP Information\n"
8771 "OSPF interface commands\n"
8772 "Link state transmit delay\n"
8773 "Seconds\n"
8774 "Address of interface\n")
8775 {
8776 VTY_DECLVAR_CONTEXT(interface, ifp);
8777 int idx = 0;
8778 uint32_t seconds;
8779 struct in_addr addr;
8780 struct ospf_if_params *params;
8781
8782 params = IF_DEF_PARAMS(ifp);
8783 argv_find(argv, argc, "(1-65535)", &idx);
8784 seconds = strtol(argv[idx]->arg, NULL, 10);
8785
8786 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8787 if (!inet_aton(argv[idx]->arg, &addr)) {
8788 vty_out(vty,
8789 "Please specify interface address by A.B.C.D\n");
8790 return CMD_WARNING_CONFIG_FAILED;
8791 }
8792
8793 params = ospf_get_if_params(ifp, addr);
8794 ospf_if_update_params(ifp, addr);
8795 }
8796
8797 SET_IF_PARAM(params, transmit_delay);
8798 params->transmit_delay = seconds;
8799
8800 return CMD_SUCCESS;
8801 }
8802
8803 DEFUN_HIDDEN (ospf_transmit_delay,
8804 ospf_transmit_delay_cmd,
8805 "ospf transmit-delay (1-65535) [A.B.C.D]",
8806 "OSPF interface commands\n"
8807 "Link state transmit delay\n"
8808 "Seconds\n"
8809 "Address of interface\n")
8810 {
8811 return ip_ospf_transmit_delay(self, vty, argc, argv);
8812 }
8813
8814 DEFUN (no_ip_ospf_transmit_delay,
8815 no_ip_ospf_transmit_delay_addr_cmd,
8816 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
8817 NO_STR
8818 "IP Information\n"
8819 "OSPF interface commands\n"
8820 "Link state transmit delay\n"
8821 "Seconds\n"
8822 "Address of interface\n")
8823 {
8824 VTY_DECLVAR_CONTEXT(interface, ifp);
8825 int idx = 0;
8826 struct in_addr addr;
8827 struct ospf_if_params *params;
8828
8829 params = IF_DEF_PARAMS(ifp);
8830
8831 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8832 if (!inet_aton(argv[idx]->arg, &addr)) {
8833 vty_out(vty,
8834 "Please specify interface address by A.B.C.D\n");
8835 return CMD_WARNING_CONFIG_FAILED;
8836 }
8837
8838 params = ospf_lookup_if_params(ifp, addr);
8839 if (params == NULL)
8840 return CMD_SUCCESS;
8841 }
8842
8843 UNSET_IF_PARAM(params, transmit_delay);
8844 params->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT;
8845
8846 if (params != IF_DEF_PARAMS(ifp)) {
8847 ospf_free_if_params(ifp, addr);
8848 ospf_if_update_params(ifp, addr);
8849 }
8850
8851 return CMD_SUCCESS;
8852 }
8853
8854
8855 DEFUN_HIDDEN (no_ospf_transmit_delay,
8856 no_ospf_transmit_delay_cmd,
8857 "no ospf transmit-delay [(1-65535) [A.B.C.D]]",
8858 NO_STR
8859 "OSPF interface commands\n"
8860 "Link state transmit delay\n"
8861 "Seconds\n"
8862 "Address of interface\n")
8863 {
8864 return no_ip_ospf_transmit_delay(self, vty, argc, argv);
8865 }
8866
8867 DEFUN (ip_ospf_area,
8868 ip_ospf_area_cmd,
8869 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]",
8870 "IP Information\n"
8871 "OSPF interface commands\n"
8872 "Instance ID\n"
8873 "Enable OSPF on this interface\n"
8874 "OSPF area ID in IP address format\n"
8875 "OSPF area ID as a decimal value\n"
8876 "Address of interface\n")
8877 {
8878 VTY_DECLVAR_CONTEXT(interface, ifp);
8879 int idx = 0;
8880 int format, ret;
8881 struct in_addr area_id;
8882 struct in_addr addr;
8883 struct ospf_if_params *params = NULL;
8884 struct route_node *rn;
8885 struct ospf *ospf = NULL;
8886 unsigned short instance = 0;
8887 char *areaid;
8888 uint32_t count = 0;
8889
8890 if (argv_find(argv, argc, "(1-65535)", &idx))
8891 instance = strtol(argv[idx]->arg, NULL, 10);
8892
8893 argv_find(argv, argc, "area", &idx);
8894 areaid = argv[idx + 1]->arg;
8895
8896 if (!instance)
8897 ospf = ifp->vrf->info;
8898 else
8899 ospf = ospf_lookup_instance(instance);
8900
8901 if (instance && instance != ospf_instance) {
8902 /*
8903 * At this point we know we have received
8904 * an instance and there is no ospf instance
8905 * associated with it. This means we are
8906 * in a situation where we have an
8907 * ospf command that is setup for a different
8908 * process(instance). We need to safely
8909 * remove the command from ourselves and
8910 * allow the other instance(process) handle
8911 * the configuration command.
8912 */
8913 count = 0;
8914
8915 params = IF_DEF_PARAMS(ifp);
8916 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
8917 UNSET_IF_PARAM(params, if_area);
8918 count++;
8919 }
8920
8921 for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; rn = route_next(rn))
8922 if ((params = rn->info) && OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
8923 UNSET_IF_PARAM(params, if_area);
8924 count++;
8925 }
8926
8927 if (count > 0) {
8928 ospf = ifp->vrf->info;
8929 if (ospf)
8930 ospf_interface_area_unset(ospf, ifp);
8931 }
8932
8933 return CMD_NOT_MY_INSTANCE;
8934 }
8935
8936 ret = str2area_id(areaid, &area_id, &format);
8937 if (ret < 0) {
8938 vty_out(vty, "Please specify area by A.B.C.D|<0-4294967295>\n");
8939 return CMD_WARNING_CONFIG_FAILED;
8940 }
8941 if (memcmp(ifp->name, "VLINK", 5) == 0) {
8942 vty_out(vty, "Cannot enable OSPF on a virtual link.\n");
8943 return CMD_WARNING_CONFIG_FAILED;
8944 }
8945
8946 if (ospf) {
8947 for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) {
8948 if (rn->info != NULL) {
8949 vty_out(vty,
8950 "Please remove all network commands first.\n");
8951 return CMD_WARNING_CONFIG_FAILED;
8952 }
8953 }
8954 }
8955
8956 params = IF_DEF_PARAMS(ifp);
8957 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)
8958 && !IPV4_ADDR_SAME(&params->if_area, &area_id)) {
8959 vty_out(vty,
8960 "Must remove previous area config before changing ospf area \n");
8961 return CMD_WARNING_CONFIG_FAILED;
8962 }
8963
8964 // Check if we have an address arg and proccess it
8965 if (argc == idx + 3) {
8966 if (!inet_aton(argv[idx + 2]->arg, &addr)) {
8967 vty_out(vty,
8968 "Please specify Intf Address by A.B.C.D\n");
8969 return CMD_WARNING_CONFIG_FAILED;
8970 }
8971 // update/create address-level params
8972 params = ospf_get_if_params((ifp), (addr));
8973 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
8974 if (!IPV4_ADDR_SAME(&params->if_area, &area_id)) {
8975 vty_out(vty,
8976 "Must remove previous area/address config before changing ospf area\n");
8977 return CMD_WARNING_CONFIG_FAILED;
8978 } else
8979 return CMD_SUCCESS;
8980 }
8981 ospf_if_update_params((ifp), (addr));
8982 }
8983
8984 /* enable ospf on this interface with area_id */
8985 if (params) {
8986 SET_IF_PARAM(params, if_area);
8987 params->if_area = area_id;
8988 params->if_area_id_fmt = format;
8989 }
8990
8991 if (ospf)
8992 ospf_interface_area_set(ospf, ifp);
8993
8994 return CMD_SUCCESS;
8995 }
8996
8997 DEFUN (no_ip_ospf_area,
8998 no_ip_ospf_area_cmd,
8999 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]",
9000 NO_STR
9001 "IP Information\n"
9002 "OSPF interface commands\n"
9003 "Instance ID\n"
9004 "Disable OSPF on this interface\n"
9005 "OSPF area ID in IP address format\n"
9006 "OSPF area ID as a decimal value\n"
9007 "Address of interface\n")
9008 {
9009 VTY_DECLVAR_CONTEXT(interface, ifp);
9010 int idx = 0;
9011 struct ospf *ospf;
9012 struct ospf_if_params *params;
9013 unsigned short instance = 0;
9014 struct in_addr addr;
9015 struct in_addr area_id;
9016
9017 if (argv_find(argv, argc, "(1-65535)", &idx))
9018 instance = strtol(argv[idx]->arg, NULL, 10);
9019
9020 if (!instance)
9021 ospf = ifp->vrf->info;
9022 else
9023 ospf = ospf_lookup_instance(instance);
9024
9025 if (instance && instance != ospf_instance)
9026 return CMD_NOT_MY_INSTANCE;
9027
9028 argv_find(argv, argc, "area", &idx);
9029
9030 // Check if we have an address arg and proccess it
9031 if (argc == idx + 3) {
9032 if (!inet_aton(argv[idx + 2]->arg, &addr)) {
9033 vty_out(vty,
9034 "Please specify Intf Address by A.B.C.D\n");
9035 return CMD_WARNING_CONFIG_FAILED;
9036 }
9037 params = ospf_lookup_if_params(ifp, addr);
9038 if ((params) == NULL)
9039 return CMD_SUCCESS;
9040 } else
9041 params = IF_DEF_PARAMS(ifp);
9042
9043 area_id = params->if_area;
9044 if (!OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
9045 vty_out(vty,
9046 "Can't find specified interface area configuration.\n");
9047 return CMD_WARNING_CONFIG_FAILED;
9048 }
9049
9050 UNSET_IF_PARAM(params, if_area);
9051 if (params != IF_DEF_PARAMS((ifp))) {
9052 ospf_free_if_params((ifp), (addr));
9053 ospf_if_update_params((ifp), (addr));
9054 }
9055
9056 if (ospf) {
9057 ospf_interface_area_unset(ospf, ifp);
9058 ospf_area_check_free(ospf, area_id);
9059 }
9060
9061 return CMD_SUCCESS;
9062 }
9063
9064 DEFUN (ip_ospf_passive,
9065 ip_ospf_passive_cmd,
9066 "ip ospf passive [A.B.C.D]",
9067 "IP Information\n"
9068 "OSPF interface commands\n"
9069 "Suppress routing updates on an interface\n"
9070 "Address of interface\n")
9071 {
9072 VTY_DECLVAR_CONTEXT(interface, ifp);
9073 int idx_ipv4 = 3;
9074 struct in_addr addr = {.s_addr = INADDR_ANY};
9075 struct ospf_if_params *params;
9076 int ret;
9077
9078 if (argc == 4) {
9079 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
9080 if (!ret) {
9081 vty_out(vty,
9082 "Please specify interface address by A.B.C.D\n");
9083 return CMD_WARNING_CONFIG_FAILED;
9084 }
9085 params = ospf_get_if_params(ifp, addr);
9086 ospf_if_update_params(ifp, addr);
9087 } else {
9088 params = IF_DEF_PARAMS(ifp);
9089 }
9090
9091 ospf_passive_interface_update(ifp, params, addr, OSPF_IF_PASSIVE);
9092
9093 return CMD_SUCCESS;
9094 }
9095
9096 DEFUN (no_ip_ospf_passive,
9097 no_ip_ospf_passive_cmd,
9098 "no ip ospf passive [A.B.C.D]",
9099 NO_STR
9100 "IP Information\n"
9101 "OSPF interface commands\n"
9102 "Enable routing updates on an interface\n"
9103 "Address of interface\n")
9104 {
9105 VTY_DECLVAR_CONTEXT(interface, ifp);
9106 int idx_ipv4 = 4;
9107 struct in_addr addr = {.s_addr = INADDR_ANY};
9108 struct ospf_if_params *params;
9109 int ret;
9110
9111 if (argc == 5) {
9112 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
9113 if (!ret) {
9114 vty_out(vty,
9115 "Please specify interface address by A.B.C.D\n");
9116 return CMD_WARNING_CONFIG_FAILED;
9117 }
9118 params = ospf_lookup_if_params(ifp, addr);
9119 if (params == NULL)
9120 return CMD_SUCCESS;
9121 } else {
9122 params = IF_DEF_PARAMS(ifp);
9123 }
9124
9125 ospf_passive_interface_update(ifp, params, addr, OSPF_IF_ACTIVE);
9126
9127 return CMD_SUCCESS;
9128 }
9129
9130 DEFUN (ospf_redistribute_source,
9131 ospf_redistribute_source_cmd,
9132 "redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9133 REDIST_STR
9134 FRR_REDIST_HELP_STR_OSPFD
9135 "Metric for redistributed routes\n"
9136 "OSPF default metric\n"
9137 "OSPF exterior metric type for redistributed routes\n"
9138 "Set OSPF External Type 1/2 metrics\n"
9139 "Route map reference\n"
9140 "Pointer to route-map entries\n")
9141 {
9142 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9143 int idx_protocol = 1;
9144 int source;
9145 int type = -1;
9146 int metric = -1;
9147 struct ospf_redist *red;
9148 int idx = 0;
9149 bool update = false;
9150
9151 /* Get distribute source. */
9152 source = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
9153 if (source < 0)
9154 return CMD_WARNING_CONFIG_FAILED;
9155
9156 /* Get metric value. */
9157 if (argv_find(argv, argc, "(0-16777214)", &idx)) {
9158 if (!str2metric(argv[idx]->arg, &metric))
9159 return CMD_WARNING_CONFIG_FAILED;
9160 }
9161 idx = 1;
9162 /* Get metric type. */
9163 if (argv_find(argv, argc, "(1-2)", &idx)) {
9164 if (!str2metric_type(argv[idx]->arg, &type))
9165 return CMD_WARNING_CONFIG_FAILED;
9166 }
9167 idx = 1;
9168
9169 red = ospf_redist_lookup(ospf, source, 0);
9170 if (!red)
9171 red = ospf_redist_add(ospf, source, 0);
9172 else
9173 update = true;
9174
9175 /* Get route-map */
9176 if (argv_find(argv, argc, "route-map", &idx)) {
9177 ospf_routemap_set(red, argv[idx + 1]->arg);
9178 } else
9179 ospf_routemap_unset(red);
9180
9181 if (update)
9182 return ospf_redistribute_update(ospf, red, source, 0, type,
9183 metric);
9184 else
9185 return ospf_redistribute_set(ospf, red, source, 0, type,
9186 metric);
9187 }
9188
9189 DEFUN (no_ospf_redistribute_source,
9190 no_ospf_redistribute_source_cmd,
9191 "no redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9192 NO_STR
9193 REDIST_STR
9194 FRR_REDIST_HELP_STR_OSPFD
9195 "Metric for redistributed routes\n"
9196 "OSPF default metric\n"
9197 "OSPF exterior metric type for redistributed routes\n"
9198 "Set OSPF External Type 1/2 metrics\n"
9199 "Route map reference\n"
9200 "Pointer to route-map entries\n")
9201 {
9202 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9203 int idx_protocol = 2;
9204 int source;
9205 struct ospf_redist *red;
9206
9207 source = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
9208 if (source < 0)
9209 return CMD_WARNING_CONFIG_FAILED;
9210
9211 red = ospf_redist_lookup(ospf, source, 0);
9212 if (!red)
9213 return CMD_SUCCESS;
9214
9215 ospf_routemap_unset(red);
9216 ospf_redist_del(ospf, source, 0);
9217
9218 return ospf_redistribute_unset(ospf, source, 0);
9219 }
9220
9221 DEFUN (ospf_redistribute_instance_source,
9222 ospf_redistribute_instance_source_cmd,
9223 "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9224 REDIST_STR
9225 "Open Shortest Path First\n"
9226 "Non-main Kernel Routing Table\n"
9227 "Instance ID/Table ID\n"
9228 "Metric for redistributed routes\n"
9229 "OSPF default metric\n"
9230 "OSPF exterior metric type for redistributed routes\n"
9231 "Set OSPF External Type 1/2 metrics\n"
9232 "Route map reference\n"
9233 "Pointer to route-map entries\n")
9234 {
9235 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9236 int idx_ospf_table = 1;
9237 int idx_number = 2;
9238 int idx = 3;
9239 int source;
9240 int type = -1;
9241 int metric = -1;
9242 unsigned short instance;
9243 struct ospf_redist *red;
9244 bool update = false;
9245
9246 source = proto_redistnum(AFI_IP, argv[idx_ospf_table]->text);
9247
9248 if (source < 0) {
9249 vty_out(vty, "Unknown instance redistribution\n");
9250 return CMD_WARNING_CONFIG_FAILED;
9251 }
9252
9253 instance = strtoul(argv[idx_number]->arg, NULL, 10);
9254
9255 if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) {
9256 vty_out(vty,
9257 "Instance redistribution in non-instanced OSPF not allowed\n");
9258 return CMD_WARNING_CONFIG_FAILED;
9259 }
9260
9261 if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) {
9262 vty_out(vty, "Same instance OSPF redistribution not allowed\n");
9263 return CMD_WARNING_CONFIG_FAILED;
9264 }
9265
9266 /* Get metric value. */
9267 if (argv_find(argv, argc, "metric", &idx))
9268 if (!str2metric(argv[idx + 1]->arg, &metric))
9269 return CMD_WARNING_CONFIG_FAILED;
9270
9271 idx = 3;
9272 /* Get metric type. */
9273 if (argv_find(argv, argc, "metric-type", &idx))
9274 if (!str2metric_type(argv[idx + 1]->arg, &type))
9275 return CMD_WARNING_CONFIG_FAILED;
9276
9277 red = ospf_redist_lookup(ospf, source, instance);
9278 if (!red)
9279 red = ospf_redist_add(ospf, source, instance);
9280 else
9281 update = true;
9282
9283 idx = 3;
9284 if (argv_find(argv, argc, "route-map", &idx))
9285 ospf_routemap_set(red, argv[idx + 1]->arg);
9286 else
9287 ospf_routemap_unset(red);
9288
9289 if (update)
9290 return ospf_redistribute_update(ospf, red, source, instance,
9291 type, metric);
9292 else
9293 return ospf_redistribute_set(ospf, red, source, instance, type,
9294 metric);
9295 }
9296
9297 DEFUN (no_ospf_redistribute_instance_source,
9298 no_ospf_redistribute_instance_source_cmd,
9299 "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9300 NO_STR
9301 REDIST_STR
9302 "Open Shortest Path First\n"
9303 "Non-main Kernel Routing Table\n"
9304 "Instance ID/Table Id\n"
9305 "Metric for redistributed routes\n"
9306 "OSPF default metric\n"
9307 "OSPF exterior metric type for redistributed routes\n"
9308 "Set OSPF External Type 1/2 metrics\n"
9309 "Route map reference\n"
9310 "Pointer to route-map entries\n")
9311 {
9312 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9313 int idx_ospf_table = 2;
9314 int idx_number = 3;
9315 unsigned int instance;
9316 struct ospf_redist *red;
9317 int source;
9318
9319 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
9320 source = ZEBRA_ROUTE_OSPF;
9321 else
9322 source = ZEBRA_ROUTE_TABLE;
9323
9324 instance = strtoul(argv[idx_number]->arg, NULL, 10);
9325
9326 if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) {
9327 vty_out(vty,
9328 "Instance redistribution in non-instanced OSPF not allowed\n");
9329 return CMD_WARNING_CONFIG_FAILED;
9330 }
9331
9332 if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) {
9333 vty_out(vty, "Same instance OSPF redistribution not allowed\n");
9334 return CMD_WARNING_CONFIG_FAILED;
9335 }
9336
9337 red = ospf_redist_lookup(ospf, source, instance);
9338 if (!red)
9339 return CMD_SUCCESS;
9340
9341 ospf_routemap_unset(red);
9342 ospf_redist_del(ospf, source, instance);
9343
9344 return ospf_redistribute_unset(ospf, source, instance);
9345 }
9346
9347 DEFUN (ospf_distribute_list_out,
9348 ospf_distribute_list_out_cmd,
9349 "distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD,
9350 "Filter networks in routing updates\n"
9351 "Access-list name\n"
9352 OUT_STR
9353 FRR_REDIST_HELP_STR_OSPFD)
9354 {
9355 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9356 int idx_word = 1;
9357 int source;
9358
9359 char *proto = argv[argc - 1]->text;
9360
9361 /* Get distribute source. */
9362 source = proto_redistnum(AFI_IP, proto);
9363 if (source < 0)
9364 return CMD_WARNING_CONFIG_FAILED;
9365
9366 return ospf_distribute_list_out_set(ospf, source, argv[idx_word]->arg);
9367 }
9368
9369 DEFUN (no_ospf_distribute_list_out,
9370 no_ospf_distribute_list_out_cmd,
9371 "no distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD,
9372 NO_STR
9373 "Filter networks in routing updates\n"
9374 "Access-list name\n"
9375 OUT_STR
9376 FRR_REDIST_HELP_STR_OSPFD)
9377 {
9378 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9379 int idx_word = 2;
9380 int source;
9381
9382 char *proto = argv[argc - 1]->text;
9383 source = proto_redistnum(AFI_IP, proto);
9384 if (source < 0)
9385 return CMD_WARNING_CONFIG_FAILED;
9386
9387 return ospf_distribute_list_out_unset(ospf, source,
9388 argv[idx_word]->arg);
9389 }
9390
9391 /* Default information originate. */
9392 DEFUN (ospf_default_information_originate,
9393 ospf_default_information_originate_cmd,
9394 "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9395 "Control distribution of default information\n"
9396 "Distribute a default route\n"
9397 "Always advertise default route\n"
9398 "OSPF default metric\n"
9399 "OSPF metric\n"
9400 "OSPF metric type for default routes\n"
9401 "Set OSPF External Type 1/2 metrics\n"
9402 "Route map reference\n"
9403 "Pointer to route-map entries\n")
9404 {
9405 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9406 int default_originate = DEFAULT_ORIGINATE_ZEBRA;
9407 int type = -1;
9408 int metric = -1;
9409 struct ospf_redist *red;
9410 int idx = 0;
9411 int cur_originate = ospf->default_originate;
9412 bool sameRtmap = false;
9413 char *rtmap = NULL;
9414
9415 red = ospf_redist_add(ospf, DEFAULT_ROUTE, 0);
9416
9417 /* Check whether "always" was specified */
9418 if (argv_find(argv, argc, "always", &idx))
9419 default_originate = DEFAULT_ORIGINATE_ALWAYS;
9420 idx = 1;
9421 /* Get metric value */
9422 if (argv_find(argv, argc, "(0-16777214)", &idx)) {
9423 if (!str2metric(argv[idx]->arg, &metric))
9424 return CMD_WARNING_CONFIG_FAILED;
9425 }
9426 idx = 1;
9427 /* Get metric type. */
9428 if (argv_find(argv, argc, "(1-2)", &idx)) {
9429 if (!str2metric_type(argv[idx]->arg, &type))
9430 return CMD_WARNING_CONFIG_FAILED;
9431 }
9432 idx = 1;
9433 /* Get route-map */
9434 if (argv_find(argv, argc, "route-map", &idx))
9435 rtmap = argv[idx + 1]->arg;
9436
9437 /* To check if user is providing same route map */
9438 if ((!rtmap && !ROUTEMAP_NAME(red)) ||
9439 (rtmap && ROUTEMAP_NAME(red) &&
9440 (strcmp(rtmap, ROUTEMAP_NAME(red)) == 0)))
9441 sameRtmap = true;
9442
9443 /* Don't allow if the same lsa is already originated. */
9444 if ((sameRtmap)
9445 && (red->dmetric.type == type)
9446 && (red->dmetric.value == metric)
9447 && (cur_originate == default_originate))
9448 return CMD_SUCCESS;
9449
9450 /* Updating Metric details */
9451 red->dmetric.type = type;
9452 red->dmetric.value = metric;
9453
9454 /* updating route map details */
9455 if (rtmap)
9456 ospf_routemap_set(red, rtmap);
9457 else
9458 ospf_routemap_unset(red);
9459
9460 return ospf_redistribute_default_set(ospf, default_originate, type,
9461 metric);
9462 }
9463
9464 DEFUN (no_ospf_default_information_originate,
9465 no_ospf_default_information_originate_cmd,
9466 "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9467 NO_STR
9468 "Control distribution of default information\n"
9469 "Distribute a default route\n"
9470 "Always advertise default route\n"
9471 "OSPF default metric\n"
9472 "OSPF metric\n"
9473 "OSPF metric type for default routes\n"
9474 "Set OSPF External Type 1/2 metrics\n"
9475 "Route map reference\n"
9476 "Pointer to route-map entries\n")
9477 {
9478 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9479 struct ospf_redist *red;
9480
9481 red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0);
9482 if (!red)
9483 return CMD_SUCCESS;
9484
9485 ospf_routemap_unset(red);
9486 ospf_redist_del(ospf, DEFAULT_ROUTE, 0);
9487
9488 return ospf_redistribute_default_set(ospf, DEFAULT_ORIGINATE_NONE,
9489 0, 0);
9490 }
9491
9492 DEFUN (ospf_default_metric,
9493 ospf_default_metric_cmd,
9494 "default-metric (0-16777214)",
9495 "Set metric of redistributed routes\n"
9496 "Default metric\n")
9497 {
9498 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9499 int idx_number = 1;
9500 int metric = -1;
9501
9502 if (!str2metric(argv[idx_number]->arg, &metric))
9503 return CMD_WARNING_CONFIG_FAILED;
9504
9505 ospf->default_metric = metric;
9506
9507 return CMD_SUCCESS;
9508 }
9509
9510 DEFUN (no_ospf_default_metric,
9511 no_ospf_default_metric_cmd,
9512 "no default-metric [(0-16777214)]",
9513 NO_STR
9514 "Set metric of redistributed routes\n"
9515 "Default metric\n")
9516 {
9517 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9518
9519 ospf->default_metric = -1;
9520
9521 return CMD_SUCCESS;
9522 }
9523
9524
9525 DEFUN (ospf_distance,
9526 ospf_distance_cmd,
9527 "distance (1-255)",
9528 "Administrative distance\n"
9529 "OSPF Administrative distance\n")
9530 {
9531 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9532 int idx_number = 1;
9533 uint8_t distance;
9534
9535 distance = atoi(argv[idx_number]->arg);
9536 if (ospf->distance_all != distance) {
9537 ospf->distance_all = distance;
9538 ospf_restart_spf(ospf);
9539 }
9540
9541 return CMD_SUCCESS;
9542 }
9543
9544 DEFUN (no_ospf_distance,
9545 no_ospf_distance_cmd,
9546 "no distance (1-255)",
9547 NO_STR
9548 "Administrative distance\n"
9549 "OSPF Administrative distance\n")
9550 {
9551 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9552
9553 if (ospf->distance_all) {
9554 ospf->distance_all = 0;
9555 ospf_restart_spf(ospf);
9556 }
9557
9558 return CMD_SUCCESS;
9559 }
9560
9561 DEFUN (no_ospf_distance_ospf,
9562 no_ospf_distance_ospf_cmd,
9563 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
9564 NO_STR
9565 "Administrative distance\n"
9566 "OSPF administrative distance\n"
9567 "Intra-area routes\n"
9568 "Distance for intra-area routes\n"
9569 "Inter-area routes\n"
9570 "Distance for inter-area routes\n"
9571 "External routes\n"
9572 "Distance for external routes\n")
9573 {
9574 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9575 int idx = 0;
9576
9577 if (argv_find(argv, argc, "intra-area", &idx) || argc == 3)
9578 idx = ospf->distance_intra = 0;
9579 if (argv_find(argv, argc, "inter-area", &idx) || argc == 3)
9580 idx = ospf->distance_inter = 0;
9581 if (argv_find(argv, argc, "external", &idx) || argc == 3)
9582 ospf->distance_external = 0;
9583
9584 return CMD_SUCCESS;
9585 }
9586
9587 DEFUN (ospf_distance_ospf,
9588 ospf_distance_ospf_cmd,
9589 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
9590 "Administrative distance\n"
9591 "OSPF administrative distance\n"
9592 "Intra-area routes\n"
9593 "Distance for intra-area routes\n"
9594 "Inter-area routes\n"
9595 "Distance for inter-area routes\n"
9596 "External routes\n"
9597 "Distance for external routes\n")
9598 {
9599 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9600 int idx = 0;
9601
9602 ospf->distance_intra = 0;
9603 ospf->distance_inter = 0;
9604 ospf->distance_external = 0;
9605
9606 if (argv_find(argv, argc, "intra-area", &idx))
9607 ospf->distance_intra = atoi(argv[idx + 1]->arg);
9608 idx = 0;
9609 if (argv_find(argv, argc, "inter-area", &idx))
9610 ospf->distance_inter = atoi(argv[idx + 1]->arg);
9611 idx = 0;
9612 if (argv_find(argv, argc, "external", &idx))
9613 ospf->distance_external = atoi(argv[idx + 1]->arg);
9614
9615 return CMD_SUCCESS;
9616 }
9617
9618 DEFUN (ip_ospf_mtu_ignore,
9619 ip_ospf_mtu_ignore_addr_cmd,
9620 "ip ospf mtu-ignore [A.B.C.D]",
9621 "IP Information\n"
9622 "OSPF interface commands\n"
9623 "Disable MTU mismatch detection on this interface\n"
9624 "Address of interface\n")
9625 {
9626 VTY_DECLVAR_CONTEXT(interface, ifp);
9627 int idx_ipv4 = 3;
9628 struct in_addr addr;
9629 int ret;
9630
9631 struct ospf_if_params *params;
9632 params = IF_DEF_PARAMS(ifp);
9633
9634 if (argc == 4) {
9635 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
9636 if (!ret) {
9637 vty_out(vty,
9638 "Please specify interface address by A.B.C.D\n");
9639 return CMD_WARNING_CONFIG_FAILED;
9640 }
9641 params = ospf_get_if_params(ifp, addr);
9642 ospf_if_update_params(ifp, addr);
9643 }
9644 params->mtu_ignore = 1;
9645 if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT)
9646 SET_IF_PARAM(params, mtu_ignore);
9647 else {
9648 UNSET_IF_PARAM(params, mtu_ignore);
9649 if (params != IF_DEF_PARAMS(ifp)) {
9650 ospf_free_if_params(ifp, addr);
9651 ospf_if_update_params(ifp, addr);
9652 }
9653 }
9654 return CMD_SUCCESS;
9655 }
9656
9657 DEFUN (no_ip_ospf_mtu_ignore,
9658 no_ip_ospf_mtu_ignore_addr_cmd,
9659 "no ip ospf mtu-ignore [A.B.C.D]",
9660 NO_STR
9661 "IP Information\n"
9662 "OSPF interface commands\n"
9663 "Disable MTU mismatch detection on this interface\n"
9664 "Address of interface\n")
9665 {
9666 VTY_DECLVAR_CONTEXT(interface, ifp);
9667 int idx_ipv4 = 4;
9668 struct in_addr addr;
9669 int ret;
9670
9671 struct ospf_if_params *params;
9672 params = IF_DEF_PARAMS(ifp);
9673
9674 if (argc == 5) {
9675 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
9676 if (!ret) {
9677 vty_out(vty,
9678 "Please specify interface address by A.B.C.D\n");
9679 return CMD_WARNING_CONFIG_FAILED;
9680 }
9681 params = ospf_get_if_params(ifp, addr);
9682 ospf_if_update_params(ifp, addr);
9683 }
9684 params->mtu_ignore = 0;
9685 if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT)
9686 SET_IF_PARAM(params, mtu_ignore);
9687 else {
9688 UNSET_IF_PARAM(params, mtu_ignore);
9689 if (params != IF_DEF_PARAMS(ifp)) {
9690 ospf_free_if_params(ifp, addr);
9691 ospf_if_update_params(ifp, addr);
9692 }
9693 }
9694 return CMD_SUCCESS;
9695 }
9696
9697
9698 DEFUN (ospf_max_metric_router_lsa_admin,
9699 ospf_max_metric_router_lsa_admin_cmd,
9700 "max-metric router-lsa administrative",
9701 "OSPF maximum / infinite-distance metric\n"
9702 "Advertise own Router-LSA with infinite distance (stub router)\n"
9703 "Administratively applied, for an indefinite period\n")
9704 {
9705 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9706 struct listnode *ln;
9707 struct ospf_area *area;
9708
9709 for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
9710 SET_FLAG(area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED);
9711
9712 if (!CHECK_FLAG(area->stub_router_state,
9713 OSPF_AREA_IS_STUB_ROUTED))
9714 ospf_router_lsa_update_area(area);
9715 }
9716
9717 /* Allows for areas configured later to get the property */
9718 ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_SET;
9719
9720 return CMD_SUCCESS;
9721 }
9722
9723 DEFUN (no_ospf_max_metric_router_lsa_admin,
9724 no_ospf_max_metric_router_lsa_admin_cmd,
9725 "no max-metric router-lsa administrative",
9726 NO_STR
9727 "OSPF maximum / infinite-distance metric\n"
9728 "Advertise own Router-LSA with infinite distance (stub router)\n"
9729 "Administratively applied, for an indefinite period\n")
9730 {
9731 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9732 struct listnode *ln;
9733 struct ospf_area *area;
9734
9735 for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
9736 UNSET_FLAG(area->stub_router_state,
9737 OSPF_AREA_ADMIN_STUB_ROUTED);
9738
9739 /* Don't trample on the start-up stub timer */
9740 if (CHECK_FLAG(area->stub_router_state,
9741 OSPF_AREA_IS_STUB_ROUTED)
9742 && !area->t_stub_router) {
9743 UNSET_FLAG(area->stub_router_state,
9744 OSPF_AREA_IS_STUB_ROUTED);
9745 ospf_router_lsa_update_area(area);
9746 }
9747 }
9748 ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET;
9749 return CMD_SUCCESS;
9750 }
9751
9752 DEFUN (ospf_max_metric_router_lsa_startup,
9753 ospf_max_metric_router_lsa_startup_cmd,
9754 "max-metric router-lsa on-startup (5-86400)",
9755 "OSPF maximum / infinite-distance metric\n"
9756 "Advertise own Router-LSA with infinite distance (stub router)\n"
9757 "Automatically advertise stub Router-LSA on startup of OSPF\n"
9758 "Time (seconds) to advertise self as stub-router\n")
9759 {
9760 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9761 int idx_number = 3;
9762 unsigned int seconds;
9763
9764 if (argc < 4) {
9765 vty_out(vty, "%% Must supply stub-router period\n");
9766 return CMD_WARNING_CONFIG_FAILED;
9767 }
9768
9769 seconds = strtoul(argv[idx_number]->arg, NULL, 10);
9770
9771 ospf->stub_router_startup_time = seconds;
9772
9773 return CMD_SUCCESS;
9774 }
9775
9776 DEFUN (no_ospf_max_metric_router_lsa_startup,
9777 no_ospf_max_metric_router_lsa_startup_cmd,
9778 "no max-metric router-lsa on-startup [(5-86400)]",
9779 NO_STR
9780 "OSPF maximum / infinite-distance metric\n"
9781 "Advertise own Router-LSA with infinite distance (stub router)\n"
9782 "Automatically advertise stub Router-LSA on startup of OSPF\n"
9783 "Time (seconds) to advertise self as stub-router\n")
9784 {
9785 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9786 struct listnode *ln;
9787 struct ospf_area *area;
9788
9789 ospf->stub_router_startup_time = OSPF_STUB_ROUTER_UNCONFIGURED;
9790
9791 for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
9792 SET_FLAG(area->stub_router_state,
9793 OSPF_AREA_WAS_START_STUB_ROUTED);
9794 THREAD_OFF(area->t_stub_router);
9795
9796 /* Don't trample on admin stub routed */
9797 if (!CHECK_FLAG(area->stub_router_state,
9798 OSPF_AREA_ADMIN_STUB_ROUTED)) {
9799 UNSET_FLAG(area->stub_router_state,
9800 OSPF_AREA_IS_STUB_ROUTED);
9801 ospf_router_lsa_update_area(area);
9802 }
9803 }
9804 return CMD_SUCCESS;
9805 }
9806
9807
9808 DEFUN (ospf_max_metric_router_lsa_shutdown,
9809 ospf_max_metric_router_lsa_shutdown_cmd,
9810 "max-metric router-lsa on-shutdown (5-100)",
9811 "OSPF maximum / infinite-distance metric\n"
9812 "Advertise own Router-LSA with infinite distance (stub router)\n"
9813 "Advertise stub-router prior to full shutdown of OSPF\n"
9814 "Time (seconds) to wait till full shutdown\n")
9815 {
9816 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9817 int idx_number = 3;
9818 unsigned int seconds;
9819
9820 if (argc < 4) {
9821 vty_out(vty, "%% Must supply stub-router shutdown period\n");
9822 return CMD_WARNING_CONFIG_FAILED;
9823 }
9824
9825 seconds = strtoul(argv[idx_number]->arg, NULL, 10);
9826
9827 ospf->stub_router_shutdown_time = seconds;
9828
9829 return CMD_SUCCESS;
9830 }
9831
9832 DEFUN (no_ospf_max_metric_router_lsa_shutdown,
9833 no_ospf_max_metric_router_lsa_shutdown_cmd,
9834 "no max-metric router-lsa on-shutdown [(5-100)]",
9835 NO_STR
9836 "OSPF maximum / infinite-distance metric\n"
9837 "Advertise own Router-LSA with infinite distance (stub router)\n"
9838 "Advertise stub-router prior to full shutdown of OSPF\n"
9839 "Time (seconds) to wait till full shutdown\n")
9840 {
9841 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9842
9843 ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED;
9844
9845 return CMD_SUCCESS;
9846 }
9847
9848 DEFUN (ospf_proactive_arp,
9849 ospf_proactive_arp_cmd,
9850 "proactive-arp",
9851 "Allow sending ARP requests proactively\n")
9852 {
9853 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9854
9855 ospf->proactive_arp = true;
9856
9857 return CMD_SUCCESS;
9858 }
9859
9860 DEFUN (no_ospf_proactive_arp,
9861 no_ospf_proactive_arp_cmd,
9862 "no proactive-arp",
9863 NO_STR
9864 "Disallow sending ARP requests proactively\n")
9865 {
9866 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9867
9868 ospf->proactive_arp = false;
9869
9870 return CMD_SUCCESS;
9871 }
9872
9873 /* Graceful Restart HELPER Commands */
9874 DEFPY(ospf_gr_helper_enable, ospf_gr_helper_enable_cmd,
9875 "graceful-restart helper enable [A.B.C.D$address]",
9876 "OSPF Graceful Restart\n"
9877 "OSPF GR Helper\n"
9878 "Enable Helper support\n"
9879 "Advertising Router-ID\n")
9880 {
9881 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9882
9883 if (address_str) {
9884 ospf_gr_helper_support_set_per_routerid(ospf, &address,
9885 OSPF_GR_TRUE);
9886 return CMD_SUCCESS;
9887 }
9888
9889 ospf_gr_helper_support_set(ospf, OSPF_GR_TRUE);
9890
9891 return CMD_SUCCESS;
9892 }
9893
9894 DEFPY(no_ospf_gr_helper_enable,
9895 no_ospf_gr_helper_enable_cmd,
9896 "no graceful-restart helper enable [A.B.C.D$address]",
9897 NO_STR
9898 "OSPF Graceful Restart\n"
9899 "OSPF GR Helper\n"
9900 "Enable Helper support\n"
9901 "Advertising Router-ID\n")
9902 {
9903 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9904
9905 if (address_str) {
9906 ospf_gr_helper_support_set_per_routerid(ospf, &address,
9907 OSPF_GR_FALSE);
9908 return CMD_SUCCESS;
9909 }
9910
9911 ospf_gr_helper_support_set(ospf, OSPF_GR_FALSE);
9912 return CMD_SUCCESS;
9913 }
9914
9915 DEFPY(ospf_gr_helper_enable_lsacheck,
9916 ospf_gr_helper_enable_lsacheck_cmd,
9917 "graceful-restart helper strict-lsa-checking",
9918 "OSPF Graceful Restart\n"
9919 "OSPF GR Helper\n"
9920 "Enable strict LSA check\n")
9921 {
9922 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9923
9924 ospf_gr_helper_lsa_check_set(ospf, OSPF_GR_TRUE);
9925 return CMD_SUCCESS;
9926 }
9927
9928 DEFPY(no_ospf_gr_helper_enable_lsacheck,
9929 no_ospf_gr_helper_enable_lsacheck_cmd,
9930 "no graceful-restart helper strict-lsa-checking",
9931 NO_STR
9932 "OSPF Graceful Restart\n"
9933 "OSPF GR Helper\n"
9934 "Disable strict LSA check\n")
9935 {
9936 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9937
9938 ospf_gr_helper_lsa_check_set(ospf, OSPF_GR_FALSE);
9939 return CMD_SUCCESS;
9940 }
9941
9942 DEFPY(ospf_gr_helper_supported_grace_time,
9943 ospf_gr_helper_supported_grace_time_cmd,
9944 "graceful-restart helper supported-grace-time (10-1800)$interval",
9945 "OSPF Graceful Restart\n"
9946 "OSPF GR Helper\n"
9947 "Supported grace timer\n"
9948 "Grace interval(in seconds)\n")
9949 {
9950 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9951
9952 ospf_gr_helper_supported_gracetime_set(ospf, interval);
9953 return CMD_SUCCESS;
9954 }
9955
9956 DEFPY(no_ospf_gr_helper_supported_grace_time,
9957 no_ospf_gr_helper_supported_grace_time_cmd,
9958 "no graceful-restart helper supported-grace-time (10-1800)$interval",
9959 NO_STR
9960 "OSPF Graceful Restart\n"
9961 "OSPF GR Helper\n"
9962 "Supported grace timer\n"
9963 "Grace interval(in seconds)\n")
9964 {
9965 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9966
9967 ospf_gr_helper_supported_gracetime_set(ospf, OSPF_MAX_GRACE_INTERVAL);
9968 return CMD_SUCCESS;
9969 }
9970
9971 DEFPY(ospf_gr_helper_planned_only,
9972 ospf_gr_helper_planned_only_cmd,
9973 "graceful-restart helper planned-only",
9974 "OSPF Graceful Restart\n"
9975 "OSPF GR Helper\n"
9976 "Supported only planned restart\n")
9977 {
9978 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9979
9980 ospf_gr_helper_set_supported_planned_only_restart(ospf, OSPF_GR_TRUE);
9981
9982 return CMD_SUCCESS;
9983 }
9984
9985 /* External Route Aggregation */
9986 DEFUN (ospf_external_route_aggregation,
9987 ospf_external_route_aggregation_cmd,
9988 "summary-address A.B.C.D/M [tag (1-4294967295)]",
9989 "External summary address\n"
9990 "Summary address prefix\n"
9991 "Router tag \n"
9992 "Router tag value\n")
9993 {
9994 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9995 struct prefix_ipv4 p;
9996 int idx = 1;
9997 route_tag_t tag = 0;
9998 int ret = OSPF_SUCCESS;
9999
10000 str2prefix_ipv4(argv[idx]->arg, &p);
10001
10002 if (is_default_prefix4(&p)) {
10003 vty_out(vty,
10004 "Default address shouldn't be configured as summary address.\n");
10005 return CMD_SUCCESS;
10006 }
10007
10008 /* Apply mask for given prefix. */
10009 apply_mask(&p);
10010
10011 if (!is_valid_summary_addr(&p)) {
10012 vty_out(vty, "Not a valid summary address.\n");
10013 return CMD_WARNING_CONFIG_FAILED;
10014 }
10015
10016 if (argc > 2)
10017 tag = strtoul(argv[idx + 2]->arg, NULL, 10);
10018
10019 ret = ospf_asbr_external_aggregator_set(ospf, &p, tag);
10020 if (ret == OSPF_INVALID)
10021 vty_out(vty, "Invalid configuration!!\n");
10022
10023 return CMD_SUCCESS;
10024 }
10025
10026 DEFUN (no_ospf_external_route_aggregation,
10027 no_ospf_external_route_aggregation_cmd,
10028 "no summary-address A.B.C.D/M [tag (1-4294967295)]",
10029 NO_STR
10030 "External summary address\n"
10031 "Summary address prefix\n"
10032 "Router tag\n"
10033 "Router tag value\n")
10034 {
10035 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10036 struct prefix_ipv4 p;
10037 int idx = 2;
10038 route_tag_t tag = 0;
10039 int ret = OSPF_SUCCESS;
10040
10041 str2prefix_ipv4(argv[idx]->arg, &p);
10042
10043 if (is_default_prefix4(&p)) {
10044 vty_out(vty,
10045 "Default address shouldn't be configured as summary address.\n");
10046 return CMD_SUCCESS;
10047 }
10048
10049 /* Apply mask for given prefix. */
10050 apply_mask(&p);
10051
10052 if (!is_valid_summary_addr(&p)) {
10053 vty_out(vty, "Not a valid summary address.\n");
10054 return CMD_WARNING_CONFIG_FAILED;
10055 }
10056
10057 if (argc > 3)
10058 tag = strtoul(argv[idx + 2]->arg, NULL, 10);
10059
10060 ret = ospf_asbr_external_aggregator_unset(ospf, &p, tag);
10061 if (ret == OSPF_INVALID)
10062 vty_out(vty, "Invalid configuration!!\n");
10063
10064 return CMD_SUCCESS;
10065 }
10066
10067 DEFPY(no_ospf_gr_helper_planned_only,
10068 no_ospf_gr_helper_planned_only_cmd,
10069 "no graceful-restart helper planned-only",
10070 NO_STR
10071 "OSPF Graceful Restart\n"
10072 "OSPF GR Helper\n"
10073 "Supported only for planned restart\n")
10074 {
10075 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10076
10077 ospf_gr_helper_set_supported_planned_only_restart(ospf, OSPF_GR_FALSE);
10078
10079 return CMD_SUCCESS;
10080 }
10081
10082 static int ospf_print_vty_helper_dis_rtr_walkcb(struct hash_bucket *bucket,
10083 void *arg)
10084 {
10085 struct advRtr *rtr = bucket->data;
10086 struct vty *vty = (struct vty *)arg;
10087 static unsigned int count;
10088
10089 vty_out(vty, "%-6pI4,", &rtr->advRtrAddr);
10090 count++;
10091
10092 if (count % 5 == 0)
10093 vty_out(vty, "\n");
10094
10095 return HASHWALK_CONTINUE;
10096 }
10097
10098 static int ospf_print_json_helper_enabled_rtr_walkcb(struct hash_bucket *bucket,
10099 void *arg)
10100 {
10101 struct advRtr *rtr = bucket->data;
10102 struct json_object *json_rid_array = arg;
10103 struct json_object *json_rid;
10104
10105 json_rid = json_object_new_object();
10106
10107 json_object_string_addf(json_rid, "routerId", "%pI4", &rtr->advRtrAddr);
10108 json_object_array_add(json_rid_array, json_rid);
10109
10110 return HASHWALK_CONTINUE;
10111 }
10112
10113 static int ospf_show_gr_helper_details(struct vty *vty, struct ospf *ospf,
10114 uint8_t use_vrf, json_object *json,
10115 bool uj, bool detail)
10116 {
10117 struct listnode *node;
10118 struct ospf_interface *oi;
10119 char buf[PREFIX_STRLEN];
10120 json_object *json_vrf = NULL;
10121
10122 if (uj) {
10123 if (use_vrf)
10124 json_vrf = json_object_new_object();
10125 else
10126 json_vrf = json;
10127 }
10128
10129 if (ospf->instance) {
10130 if (uj)
10131 json_object_int_add(json, "ospfInstance",
10132 ospf->instance);
10133 else
10134 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
10135 }
10136
10137 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
10138
10139 if (uj) {
10140 if (use_vrf)
10141 json_object_object_add(json, ospf_get_name(ospf),
10142 json_vrf);
10143 } else
10144 vty_out(vty, "\n");
10145
10146 /* Show Router ID. */
10147 if (uj) {
10148 json_object_string_add(json_vrf, "routerId",
10149 inet_ntop(AF_INET, &ospf->router_id,
10150 buf, sizeof(buf)));
10151 } else {
10152 vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n",
10153 &ospf->router_id);
10154 }
10155
10156 if (!uj) {
10157
10158 if (ospf->is_helper_supported)
10159 vty_out(vty,
10160 " Graceful restart helper support enabled.\n");
10161 else
10162 vty_out(vty,
10163 " Graceful restart helper support disabled.\n");
10164
10165 if (ospf->strict_lsa_check)
10166 vty_out(vty, " Strict LSA check is enabled.\n");
10167 else
10168 vty_out(vty, " Strict LSA check is disabled.\n");
10169
10170 if (ospf->only_planned_restart)
10171 vty_out(vty,
10172 " Helper supported for planned restarts only.\n");
10173 else
10174 vty_out(vty,
10175 " Helper supported for Planned and Unplanned Restarts.\n");
10176
10177 vty_out(vty,
10178 " Supported Graceful restart interval: %d(in seconds).\n",
10179 ospf->supported_grace_time);
10180
10181 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf)) {
10182 vty_out(vty, " Enable Router list:\n");
10183 vty_out(vty, " ");
10184 hash_walk(ospf->enable_rtr_list,
10185 ospf_print_vty_helper_dis_rtr_walkcb, vty);
10186 vty_out(vty, "\n\n");
10187 }
10188
10189 if (ospf->last_exit_reason != OSPF_GR_HELPER_EXIT_NONE) {
10190 vty_out(vty, " Last Helper exit Reason :%s\n",
10191 ospf_exit_reason2str(ospf->last_exit_reason));
10192 }
10193
10194 if (ospf->active_restarter_cnt)
10195 vty_out(vty,
10196 " Number of Active neighbours in graceful restart: %d\n",
10197 ospf->active_restarter_cnt);
10198 else
10199 vty_out(vty, "\n");
10200
10201 } else {
10202 json_object_string_add(
10203 json_vrf, "helperSupport",
10204 (ospf->is_helper_supported) ? "Enabled" : "Disabled");
10205 json_object_string_add(json_vrf, "strictLsaCheck",
10206 (ospf->strict_lsa_check) ? "Enabled"
10207 : "Disabled");
10208 json_object_string_add(
10209 json_vrf, "restartSupoort",
10210 (ospf->only_planned_restart)
10211 ? "Planned Restart only"
10212 : "Planned and Unplanned Restarts");
10213
10214 json_object_int_add(json_vrf, "supportedGracePeriod",
10215 ospf->supported_grace_time);
10216
10217 #if CONFDATE > 20230131
10218 CPP_NOTICE("Remove JSON object commands with keys starting with capital")
10219 #endif
10220 if (ospf->last_exit_reason != OSPF_GR_HELPER_EXIT_NONE) {
10221 json_object_string_add(
10222 json_vrf, "LastExitReason",
10223 ospf_exit_reason2str(ospf->last_exit_reason));
10224 json_object_string_add(
10225 json_vrf, "lastExitReason",
10226 ospf_exit_reason2str(ospf->last_exit_reason));
10227 }
10228
10229 if (ospf->active_restarter_cnt)
10230 json_object_int_add(json_vrf, "activeRestarterCnt",
10231 ospf->active_restarter_cnt);
10232
10233 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf)) {
10234 struct json_object *json_rid_array =
10235 json_object_new_array();
10236
10237 json_object_object_add(json_vrf, "enabledRouterIds",
10238 json_rid_array);
10239
10240 hash_walk(ospf->enable_rtr_list,
10241 ospf_print_json_helper_enabled_rtr_walkcb,
10242 json_rid_array);
10243 }
10244 }
10245
10246
10247 if (detail) {
10248 int cnt = 1;
10249 json_object *json_neighbors = NULL;
10250
10251 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
10252 struct route_node *rn;
10253 struct ospf_neighbor *nbr;
10254 json_object *json_neigh;
10255
10256 if (ospf_interface_neighbor_count(oi) == 0)
10257 continue;
10258
10259 if (uj) {
10260 json_object_object_get_ex(json_vrf, "Neighbors",
10261 &json_neighbors);
10262 json_object_object_get_ex(json_vrf, "neighbors",
10263 &json_neighbors);
10264 if (!json_neighbors) {
10265 json_neighbors =
10266 json_object_new_object();
10267 json_object_object_add(json_vrf,
10268 "Neighbors",
10269 json_neighbors);
10270 json_object_object_add(json_vrf,
10271 "neighbors",
10272 json_neighbors);
10273 }
10274 }
10275
10276 for (rn = route_top(oi->nbrs); rn;
10277 rn = route_next(rn)) {
10278
10279 if (!rn->info)
10280 continue;
10281
10282 nbr = rn->info;
10283
10284 if (!OSPF_GR_IS_ACTIVE_HELPER(nbr))
10285 continue;
10286
10287 if (!uj) {
10288 vty_out(vty, " Neighbour %d :\n", cnt);
10289 vty_out(vty, " Address : %pI4\n",
10290 &nbr->address.u.prefix4);
10291 vty_out(vty, " Routerid : %pI4\n",
10292 &nbr->router_id);
10293 vty_out(vty,
10294 " Received Grace period : %d(in seconds).\n",
10295 nbr->gr_helper_info
10296 .recvd_grace_period);
10297 vty_out(vty,
10298 " Actual Grace period : %d(in seconds)\n",
10299 nbr->gr_helper_info
10300 .actual_grace_period);
10301 vty_out(vty,
10302 " Remaining GraceTime:%ld(in seconds).\n",
10303 thread_timer_remain_second(
10304 nbr->gr_helper_info
10305 .t_grace_timer));
10306 vty_out(vty,
10307 " Graceful Restart reason: %s.\n\n",
10308 ospf_restart_reason2str(
10309 nbr->gr_helper_info
10310 .gr_restart_reason));
10311 cnt++;
10312 } else {
10313 json_neigh = json_object_new_object();
10314 json_object_string_add(
10315 json_neigh, "srcAddr",
10316 inet_ntop(AF_INET, &nbr->src,
10317 buf, sizeof(buf)));
10318
10319 json_object_string_add(
10320 json_neigh, "routerid",
10321 inet_ntop(AF_INET,
10322 &nbr->router_id,
10323 buf, sizeof(buf)));
10324 json_object_int_add(
10325 json_neigh,
10326 "recvdGraceInterval",
10327 nbr->gr_helper_info
10328 .recvd_grace_period);
10329 json_object_int_add(
10330 json_neigh,
10331 "actualGraceInterval",
10332 nbr->gr_helper_info
10333 .actual_grace_period);
10334 json_object_int_add(
10335 json_neigh, "remainGracetime",
10336 thread_timer_remain_second(
10337 nbr->gr_helper_info
10338 .t_grace_timer));
10339 json_object_string_add(
10340 json_neigh, "restartReason",
10341 ospf_restart_reason2str(
10342 nbr->gr_helper_info
10343 .gr_restart_reason));
10344 json_object_object_add(
10345 json_neighbors,
10346 inet_ntop(AF_INET, &nbr->src,
10347 buf, sizeof(buf)),
10348 json_neigh);
10349 }
10350 }
10351 }
10352 }
10353 return CMD_SUCCESS;
10354 }
10355
10356 DEFUN (ospf_external_route_aggregation_no_adrvertise,
10357 ospf_external_route_aggregation_no_adrvertise_cmd,
10358 "summary-address A.B.C.D/M no-advertise",
10359 "External summary address\n"
10360 "Summary address prefix\n"
10361 "Don't advertise summary route \n")
10362 {
10363 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10364 struct prefix_ipv4 p;
10365 int idx = 1;
10366 int ret = OSPF_SUCCESS;
10367
10368 str2prefix_ipv4(argv[idx]->arg, &p);
10369
10370 if (is_default_prefix4(&p)) {
10371 vty_out(vty,
10372 "Default address shouldn't be configured as summary address.\n");
10373 return CMD_SUCCESS;
10374 }
10375
10376 /* Apply mask for given prefix. */
10377 apply_mask(&p);
10378
10379 if (!is_valid_summary_addr(&p)) {
10380 vty_out(vty, "Not a valid summary address.\n");
10381 return CMD_WARNING_CONFIG_FAILED;
10382 }
10383
10384 ret = ospf_asbr_external_rt_no_advertise(ospf, &p);
10385 if (ret == OSPF_INVALID)
10386 vty_out(vty, "Invalid configuration!!\n");
10387
10388 return CMD_SUCCESS;
10389 }
10390
10391 DEFUN (no_ospf_external_route_aggregation_no_adrvertise,
10392 no_ospf_external_route_aggregation_no_adrvertise_cmd,
10393 "no summary-address A.B.C.D/M no-advertise",
10394 NO_STR
10395 "External summary address\n"
10396 "Summary address prefix\n"
10397 "Advertise summary route to the AS \n")
10398 {
10399 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10400 struct prefix_ipv4 p;
10401 int idx = 2;
10402 int ret = OSPF_SUCCESS;
10403
10404 str2prefix_ipv4(argv[idx]->arg, &p);
10405
10406 if (is_default_prefix4(&p)) {
10407 vty_out(vty,
10408 "Default address shouldn't be configured as summary address.\n");
10409 return CMD_SUCCESS;
10410 }
10411
10412 /* Apply mask for given prefix. */
10413 apply_mask(&p);
10414
10415 if (!is_valid_summary_addr(&p)) {
10416 vty_out(vty, "Not a valid summary address.\n");
10417 return CMD_WARNING_CONFIG_FAILED;
10418 }
10419
10420 ret = ospf_asbr_external_rt_advertise(ospf, &p);
10421 if (ret == OSPF_INVALID)
10422 vty_out(vty, "Invalid configuration!!\n");
10423
10424 return CMD_SUCCESS;
10425 }
10426
10427 DEFUN (ospf_route_aggregation_timer,
10428 ospf_route_aggregation_timer_cmd,
10429 "aggregation timer (5-1800)",
10430 "External route aggregation\n"
10431 "Delay timer (in seconds)\n"
10432 "Timer interval(in seconds)\n")
10433 {
10434 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10435 uint16_t interval = 0;
10436
10437 interval = strtoul(argv[2]->arg, NULL, 10);
10438
10439 ospf_external_aggregator_timer_set(ospf, interval);
10440
10441 return CMD_SUCCESS;
10442 }
10443
10444 DEFPY (show_ip_ospf_gr_helper,
10445 show_ip_ospf_gr_helper_cmd,
10446 "show ip ospf [vrf <NAME|all>] graceful-restart helper [detail] [json]",
10447 SHOW_STR
10448 IP_STR
10449 "OSPF information\n"
10450 VRF_CMD_HELP_STR
10451 "All VRFs\n"
10452 "OSPF Graceful Restart\n"
10453 "Helper details in the router\n"
10454 "Detailed information\n"
10455 JSON_STR)
10456 {
10457 char *vrf_name = NULL;
10458 bool all_vrf = false;
10459 int ret = CMD_SUCCESS;
10460 int idx_vrf = 0;
10461 int idx = 0;
10462 uint8_t use_vrf = 0;
10463 bool uj = use_json(argc, argv);
10464 struct ospf *ospf = NULL;
10465 json_object *json = NULL;
10466 struct listnode *node = NULL;
10467 int inst = 0;
10468 bool detail = false;
10469
10470 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
10471
10472 if (argv_find(argv, argc, "detail", &idx))
10473 detail = true;
10474
10475 if (uj)
10476 json = json_object_new_object();
10477
10478 /* vrf input is provided */
10479 if (vrf_name) {
10480 use_vrf = 1;
10481
10482 if (all_vrf) {
10483 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
10484 if (!ospf->oi_running)
10485 continue;
10486
10487 ret = ospf_show_gr_helper_details(
10488 vty, ospf, use_vrf, json, uj, detail);
10489 }
10490
10491 if (uj)
10492 vty_json(vty, json);
10493
10494 return ret;
10495 }
10496
10497 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
10498
10499 if (ospf == NULL || !ospf->oi_running) {
10500
10501 if (uj)
10502 vty_json(vty, json);
10503 else
10504 vty_out(vty,
10505 "%% OSPF is not enabled in vrf %s\n",
10506 vrf_name);
10507
10508 return CMD_SUCCESS;
10509 }
10510
10511 } else {
10512 /* Default Vrf */
10513 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
10514
10515 if (ospf == NULL || !ospf->oi_running) {
10516
10517 if (uj)
10518 vty_json(vty, json);
10519 else
10520 vty_out(vty,
10521 "%% OSPF is not enabled in vrf default\n");
10522
10523 return CMD_SUCCESS;
10524 }
10525
10526 ospf_show_gr_helper_details(vty, ospf, use_vrf, json, uj,
10527 detail);
10528 }
10529
10530 if (uj)
10531 vty_json(vty, json);
10532
10533 return CMD_SUCCESS;
10534 }
10535 /* Graceful Restart HELPER commands end */
10536 DEFUN (no_ospf_route_aggregation_timer,
10537 no_ospf_route_aggregation_timer_cmd,
10538 "no aggregation timer",
10539 NO_STR
10540 "External route aggregation\n"
10541 "Delay timer\n")
10542 {
10543 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10544
10545 ospf_external_aggregator_timer_set(ospf, OSPF_EXTL_AGGR_DEFAULT_DELAY);
10546
10547 return CMD_SUCCESS;
10548 }
10549
10550 /* External Route Aggregation End */
10551
10552 static void config_write_stub_router(struct vty *vty, struct ospf *ospf)
10553 {
10554 if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED)
10555 vty_out(vty, " max-metric router-lsa on-startup %u\n",
10556 ospf->stub_router_startup_time);
10557 if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED)
10558 vty_out(vty, " max-metric router-lsa on-shutdown %u\n",
10559 ospf->stub_router_shutdown_time);
10560 if (ospf->stub_router_admin_set == OSPF_STUB_ROUTER_ADMINISTRATIVE_SET)
10561 vty_out(vty, " max-metric router-lsa administrative\n");
10562
10563 return;
10564 }
10565
10566 #if CONFDATE > 20230131
10567 CPP_NOTICE("Remove JSON object commands with keys containing whitespaces")
10568 #endif
10569 static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf,
10570 struct route_table *rt,
10571 json_object *json)
10572 {
10573 struct route_node *rn;
10574 struct ospf_route * or ;
10575 struct listnode *pnode, *pnnode;
10576 struct ospf_path *path;
10577 json_object *json_route = NULL, *json_nexthop_array = NULL,
10578 *json_nexthop = NULL;
10579
10580 if (!json)
10581 vty_out(vty,
10582 "============ OSPF network routing table ============\n");
10583
10584 for (rn = route_top(rt); rn; rn = route_next(rn)) {
10585 char buf1[PREFIX2STR_BUFFER];
10586
10587 if ((or = rn->info) == NULL)
10588 continue;
10589
10590 prefix2str(&rn->p, buf1, sizeof(buf1));
10591
10592 if (json) {
10593 json_route = json_object_new_object();
10594 json_object_object_add(json, buf1, json_route);
10595 }
10596
10597 switch (or->path_type) {
10598 case OSPF_PATH_INTER_AREA:
10599 if (or->type == OSPF_DESTINATION_NETWORK) {
10600 if (json) {
10601 json_object_string_add(json_route,
10602 "routeType",
10603 "N IA");
10604 json_object_int_add(json_route, "cost",
10605 or->cost);
10606 json_object_string_addf(
10607 json_route, "area", "%pI4",
10608 &or->u.std.area_id);
10609 } else {
10610 vty_out(vty,
10611 "N IA %-18s [%d] area: %pI4\n",
10612 buf1, or->cost,
10613 &or->u.std.area_id);
10614 }
10615 } else if (or->type == OSPF_DESTINATION_DISCARD) {
10616 if (json) {
10617 json_object_string_add(json_route,
10618 "routeType",
10619 "D IA");
10620 } else {
10621 vty_out(vty,
10622 "D IA %-18s Discard entry\n",
10623 buf1);
10624 }
10625 }
10626 break;
10627 case OSPF_PATH_INTRA_AREA:
10628 if (json) {
10629 json_object_string_add(json_route, "routeType",
10630 "N");
10631 json_object_int_add(json_route, "cost",
10632 or->cost);
10633 json_object_string_addf(json_route, "area",
10634 "%pI4",
10635 &or->u.std.area_id);
10636 } else {
10637 vty_out(vty, "N %-18s [%d] area: %pI4\n",
10638 buf1, or->cost,
10639 &or->u.std.area_id);
10640 }
10641 break;
10642 default:
10643 break;
10644 }
10645
10646 if (or->type == OSPF_DESTINATION_NETWORK) {
10647 if (json) {
10648 json_nexthop_array = json_object_new_array();
10649 json_object_object_add(json_route, "nexthops",
10650 json_nexthop_array);
10651 }
10652
10653 for (ALL_LIST_ELEMENTS(or->paths, pnode, pnnode,
10654 path)) {
10655 if (json) {
10656 json_nexthop = json_object_new_object();
10657 json_object_array_add(
10658 json_nexthop_array,
10659 json_nexthop);
10660 }
10661 if (if_lookup_by_index(path->ifindex,
10662 ospf->vrf_id)) {
10663
10664 if (path->nexthop.s_addr
10665 == INADDR_ANY) {
10666 if (json) {
10667 json_object_string_add(
10668 json_nexthop,
10669 "ip", " ");
10670 json_object_string_add(
10671 json_nexthop,
10672 "directly attached to",
10673 ifindex2ifname(
10674 path->ifindex,
10675 ospf->vrf_id));
10676 json_object_string_add(
10677 json_nexthop,
10678 "directlyAttachedTo",
10679 ifindex2ifname(
10680 path->ifindex,
10681 ospf->vrf_id));
10682 } else {
10683 vty_out(vty,
10684 "%24s directly attached to %s\n",
10685 "",
10686 ifindex2ifname(
10687 path->ifindex,
10688 ospf->vrf_id));
10689 }
10690 } else {
10691 if (json) {
10692 json_object_string_addf(
10693 json_nexthop,
10694 "ip", "%pI4",
10695 &path->nexthop);
10696 json_object_string_add(
10697 json_nexthop,
10698 "via",
10699 ifindex2ifname(
10700 path->ifindex,
10701 ospf->vrf_id));
10702 } else {
10703 vty_out(vty,
10704 "%24s via %pI4, %s\n",
10705 "",
10706 &path->nexthop,
10707 ifindex2ifname(
10708 path->ifindex,
10709 ospf->vrf_id));
10710 }
10711 }
10712 }
10713 }
10714 }
10715 }
10716 if (!json)
10717 vty_out(vty, "\n");
10718 }
10719
10720 static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf,
10721 struct route_table *rtrs,
10722 json_object *json)
10723 {
10724 struct route_node *rn;
10725 struct ospf_route * or ;
10726 struct listnode *pnode;
10727 struct listnode *node;
10728 struct ospf_path *path;
10729 char buf[PREFIX_STRLEN];
10730 json_object *json_route = NULL, *json_nexthop_array = NULL,
10731 *json_nexthop = NULL;
10732
10733 if (!json)
10734 vty_out(vty, "============ OSPF %s table =============\n",
10735 ospf->all_rtrs == rtrs ? "reachable routers"
10736 : "router routing");
10737
10738 for (rn = route_top(rtrs); rn; rn = route_next(rn)) {
10739 if (rn->info == NULL)
10740 continue;
10741 int flag = 0;
10742
10743 if (json) {
10744 json_route = json_object_new_object();
10745 json_object_object_add(
10746 json, inet_ntop(AF_INET, &rn->p.u.prefix4,
10747 buf, sizeof(buf)),
10748 json_route);
10749 json_object_string_add(json_route, "routeType", "R ");
10750 } else {
10751 vty_out(vty, "R %-15pI4 ",
10752 &rn->p.u.prefix4);
10753 }
10754
10755 for (ALL_LIST_ELEMENTS_RO((struct list *)rn->info, node, or)) {
10756 if (flag++) {
10757 if (!json)
10758 vty_out(vty, "%24s", "");
10759 }
10760
10761 /* Show path. */
10762 if (json) {
10763 json_object_int_add(json_route, "cost",
10764 or->cost);
10765 json_object_string_addf(json_route, "area",
10766 "%pI4",
10767 &or->u.std.area_id);
10768 if (or->path_type == OSPF_PATH_INTER_AREA) {
10769 json_object_boolean_true_add(json_route,
10770 "IA");
10771 json_object_boolean_true_add(json_route,
10772 "ia");
10773 }
10774 if (or->u.std.flags & ROUTER_LSA_BORDER)
10775 json_object_string_add(json_route,
10776 "routerType",
10777 "abr");
10778 else if (or->u.std.flags & ROUTER_LSA_EXTERNAL)
10779 json_object_string_add(json_route,
10780 "routerType",
10781 "asbr");
10782 } else {
10783 vty_out(vty, "%s [%d] area: %pI4",
10784 (or->path_type == OSPF_PATH_INTER_AREA
10785 ? "IA"
10786 : " "),
10787 or->cost, &or->u.std.area_id);
10788 /* Show flags. */
10789 vty_out(vty, "%s%s\n",
10790 (or->u.std.flags & ROUTER_LSA_BORDER
10791 ? ", ABR"
10792 : ""),
10793 (or->u.std.flags & ROUTER_LSA_EXTERNAL
10794 ? ", ASBR"
10795 : ""));
10796 }
10797
10798 if (json) {
10799 json_nexthop_array = json_object_new_array();
10800 json_object_object_add(json_route, "nexthops",
10801 json_nexthop_array);
10802 }
10803
10804 for (ALL_LIST_ELEMENTS_RO(or->paths, pnode, path)) {
10805 if (json) {
10806 json_nexthop = json_object_new_object();
10807 json_object_array_add(
10808 json_nexthop_array,
10809 json_nexthop);
10810 }
10811 if (if_lookup_by_index(path->ifindex,
10812 ospf->vrf_id)) {
10813 if (path->nexthop.s_addr
10814 == INADDR_ANY) {
10815 if (json) {
10816 json_object_string_add(
10817 json_nexthop,
10818 "ip", " ");
10819 json_object_string_add(
10820 json_nexthop,
10821 "directly attached to",
10822 ifindex2ifname(
10823 path->ifindex,
10824 ospf->vrf_id));
10825 json_object_string_add(
10826 json_nexthop,
10827 "directlyAttachedTo",
10828 ifindex2ifname(
10829 path->ifindex,
10830 ospf->vrf_id));
10831 } else {
10832 vty_out(vty,
10833 "%24s directly attached to %s\n",
10834 "",
10835 ifindex2ifname(
10836 path->ifindex,
10837 ospf->vrf_id));
10838 }
10839 } else {
10840 if (json) {
10841 json_object_string_addf(
10842 json_nexthop,
10843 "ip", "%pI4",
10844 &path->nexthop);
10845 json_object_string_add(
10846 json_nexthop,
10847 "via",
10848 ifindex2ifname(
10849 path->ifindex,
10850 ospf->vrf_id));
10851 } else {
10852 vty_out(vty,
10853 "%24s via %pI4, %s\n",
10854 "",
10855 &path->nexthop,
10856 ifindex2ifname(
10857 path->ifindex,
10858 ospf->vrf_id));
10859 }
10860 }
10861 }
10862 }
10863 }
10864 }
10865 if (!json)
10866 vty_out(vty, "\n");
10867 }
10868
10869 static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf,
10870 struct route_table *rt,
10871 json_object *json)
10872 {
10873 struct route_node *rn;
10874 struct ospf_route *er;
10875 struct listnode *pnode, *pnnode;
10876 struct ospf_path *path;
10877 json_object *json_route = NULL, *json_nexthop_array = NULL,
10878 *json_nexthop = NULL;
10879
10880 if (!json)
10881 vty_out(vty,
10882 "============ OSPF external routing table ===========\n");
10883
10884 for (rn = route_top(rt); rn; rn = route_next(rn)) {
10885 if ((er = rn->info) == NULL)
10886 continue;
10887
10888 char buf1[19];
10889
10890 snprintfrr(buf1, sizeof(buf1), "%pFX", &rn->p);
10891 if (json) {
10892 json_route = json_object_new_object();
10893 json_object_object_add(json, buf1, json_route);
10894 }
10895
10896 switch (er->path_type) {
10897 case OSPF_PATH_TYPE1_EXTERNAL:
10898 if (json) {
10899 json_object_string_add(json_route, "routeType",
10900 "N E1");
10901 json_object_int_add(json_route, "cost",
10902 er->cost);
10903 json_object_int_add(json_route, "tag",
10904 er->u.ext.tag);
10905 } else {
10906 vty_out(vty,
10907 "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI
10908 "\n",
10909 buf1, er->cost, er->u.ext.tag);
10910 }
10911 break;
10912 case OSPF_PATH_TYPE2_EXTERNAL:
10913 if (json) {
10914 json_object_string_add(json_route, "routeType",
10915 "N E2");
10916 json_object_int_add(json_route, "cost",
10917 er->cost);
10918 json_object_int_add(json_route, "type2cost",
10919 er->u.ext.type2_cost);
10920 json_object_int_add(json_route, "tag",
10921 er->u.ext.tag);
10922 } else {
10923 vty_out(vty,
10924 "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI
10925 "\n",
10926 buf1, er->cost, er->u.ext.type2_cost,
10927 er->u.ext.tag);
10928 }
10929 break;
10930 }
10931
10932 if (json) {
10933 json_nexthop_array = json_object_new_array();
10934 json_object_object_add(json_route, "nexthops",
10935 json_nexthop_array);
10936 }
10937
10938 for (ALL_LIST_ELEMENTS(er->paths, pnode, pnnode, path)) {
10939 if (json) {
10940 json_nexthop = json_object_new_object();
10941 json_object_array_add(json_nexthop_array,
10942 json_nexthop);
10943 }
10944
10945 if (if_lookup_by_index(path->ifindex, ospf->vrf_id)) {
10946 if (path->nexthop.s_addr == INADDR_ANY) {
10947 if (json) {
10948 json_object_string_add(
10949 json_nexthop, "ip",
10950 " ");
10951 json_object_string_add(
10952 json_nexthop,
10953 "directly attached to",
10954 ifindex2ifname(
10955 path->ifindex,
10956 ospf->vrf_id));
10957 json_object_string_add(
10958 json_nexthop,
10959 "directlyAttachedTo",
10960 ifindex2ifname(
10961 path->ifindex,
10962 ospf->vrf_id));
10963 } else {
10964 vty_out(vty,
10965 "%24s directly attached to %s\n",
10966 "",
10967 ifindex2ifname(
10968 path->ifindex,
10969 ospf->vrf_id));
10970 }
10971 } else {
10972 if (json) {
10973 json_object_string_addf(
10974 json_nexthop, "ip",
10975 "%pI4", &path->nexthop);
10976 json_object_string_add(
10977 json_nexthop, "via",
10978 ifindex2ifname(
10979 path->ifindex,
10980 ospf->vrf_id));
10981 } else {
10982 vty_out(vty,
10983 "%24s via %pI4, %s\n",
10984 "",
10985 &path->nexthop,
10986 ifindex2ifname(
10987 path->ifindex,
10988 ospf->vrf_id));
10989 }
10990 }
10991 }
10992 }
10993 }
10994 if (!json)
10995 vty_out(vty, "\n");
10996 }
10997
10998 static int show_ip_ospf_reachable_routers_common(struct vty *vty,
10999 struct ospf *ospf,
11000 uint8_t use_vrf)
11001 {
11002 if (ospf->instance)
11003 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
11004
11005 ospf_show_vrf_name(ospf, vty, NULL, use_vrf);
11006
11007 if (ospf->all_rtrs == NULL) {
11008 vty_out(vty, "No OSPF reachable router information exist\n");
11009 return CMD_SUCCESS;
11010 }
11011
11012 /* Show Router routes. */
11013 show_ip_ospf_route_router(vty, ospf, ospf->all_rtrs, NULL);
11014
11015 vty_out(vty, "\n");
11016
11017 return CMD_SUCCESS;
11018 }
11019
11020 DEFUN (show_ip_ospf_reachable_routers,
11021 show_ip_ospf_reachable_routers_cmd,
11022 "show ip ospf [vrf <NAME|all>] reachable-routers",
11023 SHOW_STR
11024 IP_STR
11025 "OSPF information\n"
11026 VRF_CMD_HELP_STR
11027 "All VRFs\n"
11028 "Show all the reachable OSPF routers\n")
11029 {
11030 struct ospf *ospf = NULL;
11031 struct listnode *node = NULL;
11032 char *vrf_name = NULL;
11033 bool all_vrf = false;
11034 int ret = CMD_SUCCESS;
11035 int inst = 0;
11036 int idx_vrf = 0;
11037 uint8_t use_vrf = 0;
11038
11039 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
11040
11041 if (vrf_name) {
11042 bool ospf_output = false;
11043
11044 use_vrf = 1;
11045
11046 if (all_vrf) {
11047 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11048 if (!ospf->oi_running)
11049 continue;
11050
11051 ospf_output = true;
11052 ret = show_ip_ospf_reachable_routers_common(
11053 vty, ospf, use_vrf);
11054 }
11055
11056 if (!ospf_output)
11057 vty_out(vty, "%% OSPF instance not found\n");
11058 } else {
11059 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
11060 if (ospf == NULL || !ospf->oi_running) {
11061 vty_out(vty, "%% OSPF instance not found\n");
11062 return CMD_SUCCESS;
11063 }
11064
11065 ret = show_ip_ospf_reachable_routers_common(vty, ospf,
11066 use_vrf);
11067 }
11068 } else {
11069 /* Display default ospf (instance 0) info */
11070 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
11071 if (ospf == NULL || !ospf->oi_running) {
11072 vty_out(vty, "%% OSPF instance not found\n");
11073 return CMD_SUCCESS;
11074 }
11075
11076 ret = show_ip_ospf_reachable_routers_common(vty, ospf, use_vrf);
11077 }
11078
11079 return ret;
11080 }
11081
11082 DEFUN (show_ip_ospf_instance_reachable_routers,
11083 show_ip_ospf_instance_reachable_routers_cmd,
11084 "show ip ospf (1-65535) reachable-routers",
11085 SHOW_STR
11086 IP_STR
11087 "OSPF information\n"
11088 "Instance ID\n"
11089 "Show all the reachable OSPF routers\n")
11090 {
11091 int idx_number = 3;
11092 struct ospf *ospf;
11093 unsigned short instance = 0;
11094
11095 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11096 if (instance != ospf_instance)
11097 return CMD_NOT_MY_INSTANCE;
11098
11099 ospf = ospf_lookup_instance(instance);
11100 if (!ospf || !ospf->oi_running)
11101 return CMD_SUCCESS;
11102
11103 return show_ip_ospf_reachable_routers_common(vty, ospf, 0);
11104 }
11105
11106 static int show_ip_ospf_border_routers_common(struct vty *vty,
11107 struct ospf *ospf,
11108 uint8_t use_vrf,
11109 json_object *json)
11110 {
11111 json_object *json_vrf = NULL;
11112 json_object *json_router = NULL;
11113
11114 if (json) {
11115 if (use_vrf)
11116 json_vrf = json_object_new_object();
11117 else
11118 json_vrf = json;
11119 json_router = json_object_new_object();
11120 }
11121
11122 if (ospf->instance) {
11123 if (!json)
11124 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
11125 else
11126 json_object_int_add(json_vrf, "ospfInstance",
11127 ospf->instance);
11128 }
11129
11130 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
11131
11132 if (ospf->new_table == NULL) {
11133 if (!json)
11134 vty_out(vty, "No OSPF routing information exist\n");
11135 else {
11136 json_object_free(json_router);
11137 if (use_vrf)
11138 json_object_free(json_vrf);
11139 }
11140 return CMD_SUCCESS;
11141 }
11142
11143 /* Show Network routes.
11144 show_ip_ospf_route_network (vty, ospf->new_table); */
11145
11146 /* Show Router routes. */
11147 show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, json_router);
11148
11149 if (json) {
11150 json_object_object_add(json_vrf, "routers", json_router);
11151 if (use_vrf) {
11152 if (ospf->vrf_id == VRF_DEFAULT)
11153 json_object_object_add(json, "default",
11154 json_vrf);
11155 else
11156 json_object_object_add(json, ospf->name,
11157 json_vrf);
11158 }
11159 } else {
11160 vty_out(vty, "\n");
11161 }
11162
11163 return CMD_SUCCESS;
11164 }
11165
11166 DEFPY (show_ip_ospf_border_routers,
11167 show_ip_ospf_border_routers_cmd,
11168 "show ip ospf [vrf <NAME|all>] border-routers [json]",
11169 SHOW_STR
11170 IP_STR
11171 "OSPF information\n"
11172 VRF_CMD_HELP_STR
11173 "All VRFs\n"
11174 "Show all the ABR's and ASBR's\n"
11175 JSON_STR)
11176 {
11177 struct ospf *ospf = NULL;
11178 struct listnode *node = NULL;
11179 char *vrf_name = NULL;
11180 bool all_vrf = false;
11181 int ret = CMD_SUCCESS;
11182 int inst = 0;
11183 int idx_vrf = 0;
11184 uint8_t use_vrf = 0;
11185 bool uj = use_json(argc, argv);
11186 json_object *json = NULL;
11187
11188 if (uj)
11189 json = json_object_new_object();
11190
11191 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
11192
11193 if (vrf_name) {
11194 bool ospf_output = false;
11195
11196 use_vrf = 1;
11197
11198 if (all_vrf) {
11199 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11200 if (!ospf->oi_running)
11201 continue;
11202
11203 ospf_output = true;
11204 ret = show_ip_ospf_border_routers_common(
11205 vty, ospf, use_vrf, json);
11206 }
11207
11208 if (uj)
11209 vty_json(vty, json);
11210 else if (!ospf_output)
11211 vty_out(vty, "%% OSPF is not enabled\n");
11212
11213 return ret;
11214 } else {
11215 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
11216 if (ospf == NULL || !ospf->oi_running) {
11217 if (uj)
11218 vty_json(vty, json);
11219 else
11220 vty_out(vty,
11221 "%% OSPF is not enabled in vrf %s\n",
11222 vrf_name);
11223
11224 return CMD_SUCCESS;
11225 }
11226 }
11227 } else {
11228 /* Display default ospf (instance 0) info */
11229 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
11230 if (ospf == NULL || !ospf->oi_running) {
11231 if (uj)
11232 vty_json(vty, json);
11233 else
11234 vty_out(vty,
11235 "%% OSPF is not enabled in vrf default\n");
11236
11237 return CMD_SUCCESS;
11238 }
11239 }
11240
11241 if (ospf) {
11242 ret = show_ip_ospf_border_routers_common(vty, ospf, use_vrf,
11243 json);
11244 if (uj)
11245 vty_json(vty, json);
11246 }
11247
11248 return ret;
11249 }
11250
11251 DEFUN (show_ip_ospf_instance_border_routers,
11252 show_ip_ospf_instance_border_routers_cmd,
11253 "show ip ospf (1-65535) border-routers",
11254 SHOW_STR
11255 IP_STR
11256 "OSPF information\n"
11257 "Instance ID\n"
11258 "Show all the ABR's and ASBR's\n")
11259 {
11260 int idx_number = 3;
11261 struct ospf *ospf;
11262 unsigned short instance = 0;
11263
11264 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11265 if (instance != ospf_instance)
11266 return CMD_NOT_MY_INSTANCE;
11267
11268 ospf = ospf_lookup_instance(instance);
11269 if (!ospf || !ospf->oi_running)
11270 return CMD_SUCCESS;
11271
11272 return show_ip_ospf_border_routers_common(vty, ospf, 0, NULL);
11273 }
11274
11275 static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf,
11276 json_object *json, uint8_t use_vrf)
11277 {
11278 json_object *json_vrf = NULL;
11279
11280 if (ospf->instance)
11281 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
11282
11283
11284 if (json) {
11285 if (use_vrf)
11286 json_vrf = json_object_new_object();
11287 else
11288 json_vrf = json;
11289 }
11290
11291 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
11292
11293 if (ospf->new_table == NULL) {
11294 if (json) {
11295 if (use_vrf)
11296 json_object_free(json_vrf);
11297 } else {
11298 vty_out(vty, "No OSPF routing information exist\n");
11299 }
11300 return CMD_SUCCESS;
11301 }
11302
11303 /* Show Network routes. */
11304 show_ip_ospf_route_network(vty, ospf, ospf->new_table, json_vrf);
11305
11306 /* Show Router routes. */
11307 show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, json_vrf);
11308
11309 /* Show Router routes. */
11310 if (ospf->all_rtrs)
11311 show_ip_ospf_route_router(vty, ospf, ospf->all_rtrs, json_vrf);
11312
11313 /* Show AS External routes. */
11314 show_ip_ospf_route_external(vty, ospf, ospf->old_external_route,
11315 json_vrf);
11316
11317 if (json) {
11318 if (use_vrf) {
11319 // json_object_object_add(json_vrf, "areas",
11320 // json_areas);
11321 json_object_object_add(json, ospf_get_name(ospf),
11322 json_vrf);
11323 }
11324 } else {
11325 vty_out(vty, "\n");
11326 }
11327
11328 return CMD_SUCCESS;
11329 }
11330
11331 DEFUN (show_ip_ospf_route,
11332 show_ip_ospf_route_cmd,
11333 "show ip ospf [vrf <NAME|all>] route [json]",
11334 SHOW_STR
11335 IP_STR
11336 "OSPF information\n"
11337 VRF_CMD_HELP_STR
11338 "All VRFs\n"
11339 "OSPF routing table\n"
11340 JSON_STR)
11341 {
11342 struct ospf *ospf = NULL;
11343 struct listnode *node = NULL;
11344 char *vrf_name = NULL;
11345 bool all_vrf = false;
11346 int ret = CMD_SUCCESS;
11347 int inst = 0;
11348 int idx_vrf = 0;
11349 uint8_t use_vrf = 0;
11350 bool uj = use_json(argc, argv);
11351 json_object *json = NULL;
11352
11353 if (uj)
11354 json = json_object_new_object();
11355
11356 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
11357
11358 /* vrf input is provided could be all or specific vrf*/
11359 if (vrf_name) {
11360 bool ospf_output = false;
11361
11362 use_vrf = 1;
11363
11364 if (all_vrf) {
11365 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11366 if (!ospf->oi_running)
11367 continue;
11368 ospf_output = true;
11369 ret = show_ip_ospf_route_common(vty, ospf, json,
11370 use_vrf);
11371 }
11372
11373 if (uj) {
11374 /* Keep Non-pretty format */
11375 vty_json(vty, json);
11376 } else if (!ospf_output)
11377 vty_out(vty, "%% OSPF is not enabled\n");
11378
11379 return ret;
11380 }
11381 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
11382 if (ospf == NULL || !ospf->oi_running) {
11383 if (uj)
11384 vty_json(vty, json);
11385 else
11386 vty_out(vty,
11387 "%% OSPF is not enabled in vrf %s\n",
11388 vrf_name);
11389
11390 return CMD_SUCCESS;
11391 }
11392 } else {
11393 /* Display default ospf (instance 0) info */
11394 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
11395 if (ospf == NULL || !ospf->oi_running) {
11396 if (uj)
11397 vty_json(vty, json);
11398 else
11399 vty_out(vty,
11400 "%% OSPF is not enabled in vrf default\n");
11401
11402 return CMD_SUCCESS;
11403 }
11404 }
11405
11406 if (ospf) {
11407 ret = show_ip_ospf_route_common(vty, ospf, json, use_vrf);
11408 /* Keep Non-pretty format */
11409 if (uj)
11410 vty_out(vty, "%s\n",
11411 json_object_to_json_string_ext(
11412 json, JSON_C_TO_STRING_NOSLASHESCAPE));
11413 }
11414
11415 if (uj)
11416 json_object_free(json);
11417
11418 return ret;
11419 }
11420
11421 DEFUN (show_ip_ospf_instance_route,
11422 show_ip_ospf_instance_route_cmd,
11423 "show ip ospf (1-65535) route",
11424 SHOW_STR
11425 IP_STR
11426 "OSPF information\n"
11427 "Instance ID\n"
11428 "OSPF routing table\n")
11429 {
11430 int idx_number = 3;
11431 struct ospf *ospf;
11432 unsigned short instance = 0;
11433
11434 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11435 if (instance != ospf_instance)
11436 return CMD_NOT_MY_INSTANCE;
11437
11438 ospf = ospf_lookup_instance(instance);
11439 if (!ospf || !ospf->oi_running)
11440 return CMD_SUCCESS;
11441
11442 return show_ip_ospf_route_common(vty, ospf, NULL, 0);
11443 }
11444
11445
11446 DEFUN (show_ip_ospf_vrfs,
11447 show_ip_ospf_vrfs_cmd,
11448 "show ip ospf vrfs [json]",
11449 SHOW_STR
11450 IP_STR
11451 "OSPF information\n"
11452 "Show OSPF VRFs \n"
11453 JSON_STR)
11454 {
11455 bool uj = use_json(argc, argv);
11456 json_object *json = NULL;
11457 json_object *json_vrfs = NULL;
11458 struct ospf *ospf = NULL;
11459 struct listnode *node = NULL;
11460 int count = 0;
11461 static const char header[] = "Name Id RouterId ";
11462
11463 if (uj) {
11464 json = json_object_new_object();
11465 json_vrfs = json_object_new_object();
11466 }
11467
11468 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11469 json_object *json_vrf = NULL;
11470 const char *name = NULL;
11471 int64_t vrf_id_ui = 0;
11472
11473 count++;
11474
11475 if (!uj && count == 1)
11476 vty_out(vty, "%s\n", header);
11477 if (uj)
11478 json_vrf = json_object_new_object();
11479
11480 name = ospf_get_name(ospf);
11481
11482 vrf_id_ui = (ospf->vrf_id == VRF_UNKNOWN)
11483 ? -1
11484 : (int64_t)ospf->vrf_id;
11485
11486 if (uj) {
11487 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
11488 json_object_string_addf(json_vrf, "routerId", "%pI4",
11489 &ospf->router_id);
11490
11491 json_object_object_add(json_vrfs, name, json_vrf);
11492
11493 } else {
11494 vty_out(vty, "%-25s %-5d %-16pI4 \n", name,
11495 ospf->vrf_id, &ospf->router_id);
11496 }
11497 }
11498
11499 if (uj) {
11500 json_object_object_add(json, "vrfs", json_vrfs);
11501 json_object_int_add(json, "totalVrfs", count);
11502
11503 vty_json(vty, json);
11504 } else {
11505 if (count)
11506 vty_out(vty, "\nTotal number of OSPF VRFs: %d\n",
11507 count);
11508 }
11509
11510 return CMD_SUCCESS;
11511 }
11512 DEFPY (clear_ip_ospf_neighbor,
11513 clear_ip_ospf_neighbor_cmd,
11514 "clear ip ospf [(1-65535)]$instance neighbor [A.B.C.D$nbr_id]",
11515 CLEAR_STR
11516 IP_STR
11517 "OSPF information\n"
11518 "Instance ID\n"
11519 "Reset OSPF Neighbor\n"
11520 "Neighbor ID\n")
11521 {
11522 struct listnode *node;
11523 struct ospf *ospf = NULL;
11524
11525 /* If user does not specify the arguments,
11526 * instance = 0 and nbr_id = 0.0.0.0
11527 */
11528 if (instance != 0) {
11529 /* This means clear only the particular ospf process */
11530 if (instance != ospf_instance)
11531 return CMD_NOT_MY_INSTANCE;
11532 }
11533
11534 /* Clear all the ospf processes */
11535 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11536 if (!ospf->oi_running)
11537 continue;
11538
11539 if (nbr_id_str && IPV4_ADDR_SAME(&ospf->router_id, &nbr_id)) {
11540 vty_out(vty, "Self router-id is not allowed.\r\n ");
11541 return CMD_SUCCESS;
11542 }
11543
11544 ospf_neighbor_reset(ospf, nbr_id, nbr_id_str);
11545 }
11546
11547 return CMD_SUCCESS;
11548 }
11549
11550 DEFPY (clear_ip_ospf_process,
11551 clear_ip_ospf_process_cmd,
11552 "clear ip ospf [(1-65535)]$instance process",
11553 CLEAR_STR
11554 IP_STR
11555 "OSPF information\n"
11556 "Instance ID\n"
11557 "Reset OSPF Process\n")
11558 {
11559 struct listnode *node;
11560 struct ospf *ospf = NULL;
11561
11562 /* Check if instance is not passed as an argument */
11563 if (instance != 0) {
11564 /* This means clear only the particular ospf process */
11565 if (instance != ospf_instance)
11566 return CMD_NOT_MY_INSTANCE;
11567 }
11568
11569 /* Clear all the ospf processes */
11570 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11571 if (!ospf->oi_running)
11572 continue;
11573
11574 ospf_process_reset(ospf);
11575 }
11576
11577 return CMD_SUCCESS;
11578 }
11579
11580 static const char *const ospf_abr_type_str[] = {
11581 "unknown", "standard", "ibm", "cisco", "shortcut"
11582 };
11583
11584 static const char *const ospf_shortcut_mode_str[] = {
11585 "default", "enable", "disable"
11586 };
11587 static int ospf_vty_external_rt_walkcb(struct hash_bucket *bucket,
11588 void *arg)
11589 {
11590 struct external_info *ei = bucket->data;
11591 struct vty *vty = (struct vty *)arg;
11592 static unsigned int count;
11593
11594 vty_out(vty, "%-4pI4/%d, ", &ei->p.prefix, ei->p.prefixlen);
11595 count++;
11596
11597 if (count % 5 == 0)
11598 vty_out(vty, "\n");
11599
11600 if (OSPF_EXTERNAL_RT_COUNT(ei->aggr_route) == count)
11601 count = 0;
11602
11603 return HASHWALK_CONTINUE;
11604 }
11605
11606 static int ospf_json_external_rt_walkcb(struct hash_bucket *bucket,
11607 void *arg)
11608 {
11609 struct external_info *ei = bucket->data;
11610 struct json_object *json = (struct json_object *)arg;
11611 char buf[PREFIX2STR_BUFFER];
11612 char exnalbuf[20];
11613 static unsigned int count;
11614
11615 prefix2str(&ei->p, buf, sizeof(buf));
11616
11617 snprintf(exnalbuf, 20, "Exnl Addr-%d", count);
11618
11619 json_object_string_add(json, exnalbuf, buf);
11620
11621 count++;
11622
11623 if (OSPF_EXTERNAL_RT_COUNT(ei->aggr_route) == count)
11624 count = 0;
11625
11626 return HASHWALK_CONTINUE;
11627 }
11628
11629 static int ospf_show_summary_address(struct vty *vty, struct ospf *ospf,
11630 uint8_t use_vrf, json_object *json,
11631 bool uj, bool detail)
11632 {
11633 struct route_node *rn;
11634 json_object *json_vrf = NULL;
11635 int mtype = 0;
11636 int mval = 0;
11637 static char header[] =
11638 "Summary-address Metric-type Metric Tag External_Rt_count\n";
11639
11640 mtype = metric_type(ospf, 0, ospf->instance);
11641 mval = metric_value(ospf, 0, ospf->instance);
11642
11643 if (!uj)
11644 vty_out(vty, "%s\n", header);
11645
11646 if (uj) {
11647 if (use_vrf)
11648 json_vrf = json_object_new_object();
11649 else
11650 json_vrf = json;
11651 }
11652
11653 if (ospf->instance) {
11654 if (uj)
11655 json_object_int_add(json, "ospfInstance",
11656 ospf->instance);
11657 else
11658 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
11659 }
11660
11661 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
11662
11663 if (!uj) {
11664 vty_out(vty, "aggregation delay interval :%u(in seconds)\n\n",
11665 ospf->aggr_delay_interval);
11666 } else {
11667 json_object_int_add(json_vrf, "aggregation delay interval",
11668 ospf->aggr_delay_interval);
11669 json_object_int_add(json_vrf, "aggregationDelayInterval",
11670 ospf->aggr_delay_interval);
11671 }
11672
11673 for (rn = route_top(ospf->rt_aggr_tbl); rn; rn = route_next(rn))
11674 if (rn->info) {
11675 struct ospf_external_aggr_rt *aggr = rn->info;
11676 json_object *json_aggr = NULL;
11677 char buf[PREFIX2STR_BUFFER];
11678
11679 prefix2str(&aggr->p, buf, sizeof(buf));
11680
11681 if (uj) {
11682
11683 json_aggr = json_object_new_object();
11684
11685 json_object_object_add(json_vrf, buf,
11686 json_aggr);
11687
11688 json_object_string_add(json_aggr,
11689 "Summary address", buf);
11690 json_object_string_add(json_aggr,
11691 "summaryAddress", buf);
11692
11693 json_object_string_add(
11694 json_aggr, "Metric-type",
11695 (mtype == EXTERNAL_METRIC_TYPE_1)
11696 ? "E1"
11697 : "E2");
11698 json_object_string_add(
11699 json_aggr, "metricType",
11700 (mtype == EXTERNAL_METRIC_TYPE_1)
11701 ? "E1"
11702 : "E2");
11703
11704 #if CONFDATE > 20230131
11705 CPP_NOTICE("Remove JSON object commands with keys starting with capital")
11706 #endif
11707 json_object_int_add(json_aggr, "Metric", mval);
11708 json_object_int_add(json_aggr, "metric", mval);
11709
11710 json_object_int_add(json_aggr, "Tag",
11711 aggr->tag);
11712 json_object_int_add(json_aggr, "tag",
11713 aggr->tag);
11714
11715 json_object_int_add(
11716 json_aggr, "External route count",
11717 OSPF_EXTERNAL_RT_COUNT(aggr));
11718 json_object_int_add(
11719 json_aggr, "externalRouteCount",
11720 OSPF_EXTERNAL_RT_COUNT(aggr));
11721
11722 if (OSPF_EXTERNAL_RT_COUNT(aggr) && detail) {
11723 hash_walk(
11724 aggr->match_extnl_hash,
11725 ospf_json_external_rt_walkcb,
11726 json_aggr);
11727 }
11728
11729 } else {
11730 vty_out(vty, "%-20s", buf);
11731
11732 (mtype == EXTERNAL_METRIC_TYPE_1)
11733 ? vty_out(vty, "%-16s", "E1")
11734 : vty_out(vty, "%-16s", "E2");
11735 vty_out(vty, "%-11d", mval);
11736
11737 vty_out(vty, "%-12u", aggr->tag);
11738
11739 vty_out(vty, "%-5ld\n",
11740 OSPF_EXTERNAL_RT_COUNT(aggr));
11741
11742 if (OSPF_EXTERNAL_RT_COUNT(aggr) && detail) {
11743 vty_out(vty,
11744 "Matched External routes:\n");
11745 hash_walk(
11746 aggr->match_extnl_hash,
11747 ospf_vty_external_rt_walkcb,
11748 vty);
11749 vty_out(vty, "\n");
11750 }
11751
11752 vty_out(vty, "\n");
11753 }
11754 }
11755
11756 if (uj) {
11757 if (use_vrf)
11758 json_object_object_add(json, ospf_get_name(ospf),
11759 json_vrf);
11760 } else
11761 vty_out(vty, "\n");
11762
11763 return CMD_SUCCESS;
11764 }
11765
11766 DEFUN (show_ip_ospf_external_aggregator,
11767 show_ip_ospf_external_aggregator_cmd,
11768 "show ip ospf [vrf <NAME|all>] summary-address [detail] [json]",
11769 SHOW_STR IP_STR
11770 "OSPF information\n"
11771 VRF_CMD_HELP_STR
11772 "All VRFs\n"
11773 "Show external summary addresses\n"
11774 "Detailed information\n"
11775 JSON_STR)
11776 {
11777 char *vrf_name = NULL;
11778 bool all_vrf = false;
11779 int ret = CMD_SUCCESS;
11780 int idx_vrf = 0;
11781 int idx = 0;
11782 uint8_t use_vrf = 0;
11783 bool uj = use_json(argc, argv);
11784 struct ospf *ospf = NULL;
11785 json_object *json = NULL;
11786 struct listnode *node = NULL;
11787 int inst = 0;
11788 bool detail = false;
11789
11790 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
11791
11792 if (argv_find(argv, argc, "detail", &idx))
11793 detail = true;
11794
11795 if (uj)
11796 json = json_object_new_object();
11797
11798 /* vrf input is provided */
11799 if (vrf_name) {
11800 use_vrf = 1;
11801 if (all_vrf) {
11802 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11803 if (!ospf->oi_running)
11804 continue;
11805 ret = ospf_show_summary_address(
11806 vty, ospf, use_vrf, json, uj, detail);
11807 }
11808
11809 if (uj)
11810 vty_json(vty, json);
11811
11812 return ret;
11813 }
11814
11815 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
11816
11817 if (ospf == NULL || !ospf->oi_running) {
11818 if (uj)
11819 vty_json(vty, json);
11820 else
11821 vty_out(vty,
11822 "%% OSPF is not enabled in vrf %s\n",
11823 vrf_name);
11824
11825 return CMD_SUCCESS;
11826 }
11827 ospf_show_summary_address(vty, ospf, use_vrf, json, uj, detail);
11828
11829 } else {
11830 /* Default Vrf */
11831 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
11832 if (ospf == NULL || !ospf->oi_running) {
11833 if (uj)
11834 vty_json(vty, json);
11835 else
11836 vty_out(vty,
11837 "%% OSPF is not enabled in vrf default\n");
11838
11839 return CMD_SUCCESS;
11840 }
11841
11842 ospf_show_summary_address(vty, ospf, use_vrf, json, uj, detail);
11843 }
11844
11845 if (uj)
11846 vty_json(vty, json);
11847 return CMD_SUCCESS;
11848 }
11849
11850 static const char *const ospf_int_type_str[] = {
11851 "unknown", /* should never be used. */
11852 "point-to-point",
11853 "broadcast",
11854 "non-broadcast",
11855 "point-to-multipoint",
11856 "virtual-link", /* should never be used. */
11857 "loopback"
11858 };
11859
11860 static const char *interface_config_auth_str(struct ospf_if_params *params)
11861 {
11862 if (!OSPF_IF_PARAM_CONFIGURED(params, auth_type)
11863 || params->auth_type == OSPF_AUTH_NOTSET)
11864 return NULL;
11865
11866 /* Translation tables are not that much help
11867 * here due to syntax
11868 * of the simple option */
11869 switch (params->auth_type) {
11870
11871 case OSPF_AUTH_NULL:
11872 return " null";
11873
11874 case OSPF_AUTH_SIMPLE:
11875 return "";
11876
11877 case OSPF_AUTH_CRYPTOGRAPHIC:
11878 return " message-digest";
11879 }
11880
11881 return "";
11882 }
11883
11884 static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
11885 {
11886 struct listnode *node;
11887 struct interface *ifp;
11888 struct crypt_key *ck;
11889 struct route_node *rn = NULL;
11890 struct ospf_if_params *params;
11891 const char *auth_str;
11892 int write = 0;
11893
11894 FOR_ALL_INTERFACES (vrf, ifp) {
11895
11896 if (memcmp(ifp->name, "VLINK", 5) == 0)
11897 continue;
11898
11899 if_vty_config_start(vty, ifp);
11900
11901 if (ifp->desc)
11902 vty_out(vty, " description %s\n", ifp->desc);
11903
11904 write++;
11905
11906 params = IF_DEF_PARAMS(ifp);
11907
11908 do {
11909 /* Interface Network print. */
11910 if (OSPF_IF_PARAM_CONFIGURED(params, type)
11911 && params->type != OSPF_IFTYPE_LOOPBACK) {
11912 if (params->type != ospf_default_iftype(ifp)) {
11913 vty_out(vty, " ip ospf network %s",
11914 ospf_int_type_str
11915 [params->type]);
11916 if (params->type
11917 == OSPF_IFTYPE_POINTOPOINT
11918 && params->ptp_dmvpn)
11919 vty_out(vty, " dmvpn");
11920 if (params != IF_DEF_PARAMS(ifp) && rn)
11921 vty_out(vty, " %pI4",
11922 &rn->p.u.prefix4);
11923 vty_out(vty, "\n");
11924 }
11925 }
11926
11927 /* OSPF interface authentication print */
11928 auth_str = interface_config_auth_str(params);
11929 if (auth_str) {
11930 vty_out(vty, " ip ospf authentication%s",
11931 auth_str);
11932 if (params != IF_DEF_PARAMS(ifp) && rn)
11933 vty_out(vty, " %pI4",
11934 &rn->p.u.prefix4);
11935 vty_out(vty, "\n");
11936 }
11937
11938 /* Simple Authentication Password print. */
11939 if (OSPF_IF_PARAM_CONFIGURED(params, auth_simple)
11940 && params->auth_simple[0] != '\0') {
11941 vty_out(vty, " ip ospf authentication-key %s",
11942 params->auth_simple);
11943 if (params != IF_DEF_PARAMS(ifp) && rn)
11944 vty_out(vty, " %pI4",
11945 &rn->p.u.prefix4);
11946 vty_out(vty, "\n");
11947 }
11948
11949 /* Cryptographic Authentication Key print. */
11950 if (params && params->auth_crypt) {
11951 for (ALL_LIST_ELEMENTS_RO(params->auth_crypt,
11952 node, ck)) {
11953 vty_out(vty,
11954 " ip ospf message-digest-key %d md5 %s",
11955 ck->key_id, ck->auth_key);
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 /* Interface Output Cost print. */
11964 if (OSPF_IF_PARAM_CONFIGURED(params, output_cost_cmd)) {
11965 vty_out(vty, " ip ospf cost %u",
11966 params->output_cost_cmd);
11967 if (params != IF_DEF_PARAMS(ifp) && rn)
11968 vty_out(vty, " %pI4",
11969 &rn->p.u.prefix4);
11970 vty_out(vty, "\n");
11971 }
11972
11973 /* Hello Interval print. */
11974 if (OSPF_IF_PARAM_CONFIGURED(params, v_hello)
11975 && params->v_hello != OSPF_HELLO_INTERVAL_DEFAULT) {
11976 vty_out(vty, " ip ospf hello-interval %u",
11977 params->v_hello);
11978 if (params != IF_DEF_PARAMS(ifp) && rn)
11979 vty_out(vty, " %pI4",
11980 &rn->p.u.prefix4);
11981 vty_out(vty, "\n");
11982 }
11983
11984
11985 /* Router Dead Interval print. */
11986 if (OSPF_IF_PARAM_CONFIGURED(params, v_wait)
11987 && params->is_v_wait_set) {
11988 vty_out(vty, " ip ospf dead-interval ");
11989
11990 /* fast hello ? */
11991 if (OSPF_IF_PARAM_CONFIGURED(params,
11992 fast_hello))
11993 vty_out(vty,
11994 "minimal hello-multiplier %d",
11995 params->fast_hello);
11996 else
11997 vty_out(vty, "%u", params->v_wait);
11998
11999 if (params != IF_DEF_PARAMS(ifp) && rn)
12000 vty_out(vty, " %pI4",
12001 &rn->p.u.prefix4);
12002 vty_out(vty, "\n");
12003 }
12004
12005 /* Router Priority print. */
12006 if (OSPF_IF_PARAM_CONFIGURED(params, priority)
12007 && params->priority
12008 != OSPF_ROUTER_PRIORITY_DEFAULT) {
12009 vty_out(vty, " ip ospf priority %u",
12010 params->priority);
12011 if (params != IF_DEF_PARAMS(ifp) && rn)
12012 vty_out(vty, " %pI4",
12013 &rn->p.u.prefix4);
12014 vty_out(vty, "\n");
12015 }
12016
12017 /* Retransmit Interval print. */
12018 if (OSPF_IF_PARAM_CONFIGURED(params,
12019 retransmit_interval)
12020 && params->retransmit_interval
12021 != OSPF_RETRANSMIT_INTERVAL_DEFAULT) {
12022 vty_out(vty, " ip ospf retransmit-interval %u",
12023 params->retransmit_interval);
12024 if (params != IF_DEF_PARAMS(ifp) && rn)
12025 vty_out(vty, " %pI4",
12026 &rn->p.u.prefix4);
12027 vty_out(vty, "\n");
12028 }
12029
12030 /* Transmit Delay print. */
12031 if (OSPF_IF_PARAM_CONFIGURED(params, transmit_delay)
12032 && params->transmit_delay
12033 != OSPF_TRANSMIT_DELAY_DEFAULT) {
12034 vty_out(vty, " ip ospf transmit-delay %u",
12035 params->transmit_delay);
12036 if (params != IF_DEF_PARAMS(ifp) && rn)
12037 vty_out(vty, " %pI4",
12038 &rn->p.u.prefix4);
12039 vty_out(vty, "\n");
12040 }
12041
12042 /* Area print. */
12043 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
12044 if (ospf_instance)
12045 vty_out(vty, " ip ospf %d",
12046 ospf_instance);
12047 else
12048 vty_out(vty, " ip ospf");
12049
12050 char buf[INET_ADDRSTRLEN];
12051
12052 area_id2str(buf, sizeof(buf), &params->if_area,
12053 params->if_area_id_fmt);
12054 vty_out(vty, " area %s", buf);
12055 if (params != IF_DEF_PARAMS(ifp) && rn)
12056 vty_out(vty, " %pI4",
12057 &rn->p.u.prefix4);
12058 vty_out(vty, "\n");
12059 }
12060
12061 /* bfd print. */
12062 if (params && params->bfd_config)
12063 ospf_bfd_write_config(vty, params);
12064
12065 /* MTU ignore print. */
12066 if (OSPF_IF_PARAM_CONFIGURED(params, mtu_ignore)
12067 && params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) {
12068 if (params->mtu_ignore == 0)
12069 vty_out(vty, " no ip ospf mtu-ignore");
12070 else
12071 vty_out(vty, " ip ospf mtu-ignore");
12072 if (params != IF_DEF_PARAMS(ifp) && rn)
12073 vty_out(vty, " %pI4",
12074 &rn->p.u.prefix4);
12075 vty_out(vty, "\n");
12076 }
12077
12078 if (OSPF_IF_PARAM_CONFIGURED(params,
12079 passive_interface)) {
12080 vty_out(vty, " %sip ospf passive",
12081 params->passive_interface
12082 == OSPF_IF_ACTIVE
12083 ? "no "
12084 : "");
12085 if (params != IF_DEF_PARAMS(ifp) && rn)
12086 vty_out(vty, " %pI4", &rn->p.u.prefix4);
12087 vty_out(vty, "\n");
12088 }
12089
12090 /* LDP-Sync print */
12091 if (params && params->ldp_sync_info)
12092 ospf_ldp_sync_if_write_config(vty, params);
12093
12094 while (1) {
12095 if (rn == NULL)
12096 rn = route_top(IF_OIFS_PARAMS(ifp));
12097 else
12098 rn = route_next(rn);
12099
12100 if (rn == NULL)
12101 break;
12102 params = rn->info;
12103 if (params != NULL)
12104 break;
12105 }
12106 } while (rn);
12107
12108 ospf_opaque_config_write_if(vty, ifp);
12109
12110 if_vty_config_end(vty);
12111 }
12112
12113 return write;
12114 }
12115
12116 /* Configuration write function for ospfd. */
12117 static int config_write_interface(struct vty *vty)
12118 {
12119 int write = 0;
12120 struct vrf *vrf = NULL;
12121
12122 /* Display all VRF aware OSPF interface configuration */
12123 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
12124 write += config_write_interface_one(vty, vrf);
12125 }
12126
12127 return write;
12128 }
12129
12130 static int config_write_network_area(struct vty *vty, struct ospf *ospf)
12131 {
12132 struct route_node *rn;
12133 char buf[INET_ADDRSTRLEN];
12134
12135 /* `network area' print. */
12136 for (rn = route_top(ospf->networks); rn; rn = route_next(rn))
12137 if (rn->info) {
12138 struct ospf_network *n = rn->info;
12139
12140 /* Create Area ID string by specified Area ID format. */
12141 if (n->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD)
12142 inet_ntop(AF_INET, &n->area_id, buf,
12143 sizeof(buf));
12144 else
12145 snprintf(buf, sizeof(buf), "%lu",
12146 (unsigned long int)ntohl(
12147 n->area_id.s_addr));
12148
12149 /* Network print. */
12150 vty_out(vty, " network %pFX area %s\n", &rn->p, buf);
12151 }
12152
12153 return 0;
12154 }
12155
12156 static int config_write_ospf_area(struct vty *vty, struct ospf *ospf)
12157 {
12158 struct listnode *node;
12159 struct ospf_area *area;
12160 char buf[INET_ADDRSTRLEN];
12161
12162 /* Area configuration print. */
12163 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
12164 struct route_node *rn1;
12165
12166 area_id2str(buf, sizeof(buf), &area->area_id,
12167 area->area_id_fmt);
12168
12169 if (area->auth_type != OSPF_AUTH_NULL) {
12170 if (area->auth_type == OSPF_AUTH_SIMPLE)
12171 vty_out(vty, " area %s authentication\n", buf);
12172 else
12173 vty_out(vty,
12174 " area %s authentication message-digest\n",
12175 buf);
12176 }
12177
12178 if (area->shortcut_configured != OSPF_SHORTCUT_DEFAULT)
12179 vty_out(vty, " area %s shortcut %s\n", buf,
12180 ospf_shortcut_mode_str
12181 [area->shortcut_configured]);
12182
12183 if ((area->external_routing == OSPF_AREA_STUB)
12184 || (area->external_routing == OSPF_AREA_NSSA)) {
12185 if (area->external_routing == OSPF_AREA_STUB) {
12186 vty_out(vty, " area %s stub", buf);
12187 if (area->no_summary)
12188 vty_out(vty, " no-summary\n");
12189 vty_out(vty, "\n");
12190 } else if (area->external_routing == OSPF_AREA_NSSA) {
12191 switch (area->NSSATranslatorRole) {
12192 case OSPF_NSSA_ROLE_NEVER:
12193 vty_out(vty,
12194 " area %s nssa translate-never\n",
12195 buf);
12196 break;
12197 case OSPF_NSSA_ROLE_ALWAYS:
12198 vty_out(vty,
12199 " area %s nssa translate-always\n",
12200 buf);
12201 break;
12202 case OSPF_NSSA_ROLE_CANDIDATE:
12203 vty_out(vty, " area %s nssa \n", buf);
12204 break;
12205 }
12206 if (area->no_summary)
12207 vty_out(vty,
12208 " area %s nssa no-summary\n",
12209 buf);
12210 if (area->suppress_fa)
12211 vty_out(vty,
12212 " area %s nssa suppress-fa\n",
12213 buf);
12214 }
12215
12216 if (area->default_cost != 1)
12217 vty_out(vty, " area %s default-cost %d\n", buf,
12218 area->default_cost);
12219 }
12220
12221 for (rn1 = route_top(area->ranges); rn1; rn1 = route_next(rn1))
12222 if (rn1->info) {
12223 struct ospf_area_range *range = rn1->info;
12224
12225 vty_out(vty, " area %s range %pFX", buf,
12226 &rn1->p);
12227
12228 if (range->cost_config
12229 != OSPF_AREA_RANGE_COST_UNSPEC)
12230 vty_out(vty, " cost %d",
12231 range->cost_config);
12232
12233 if (!CHECK_FLAG(range->flags,
12234 OSPF_AREA_RANGE_ADVERTISE))
12235 vty_out(vty, " not-advertise");
12236
12237 if (CHECK_FLAG(range->flags,
12238 OSPF_AREA_RANGE_SUBSTITUTE))
12239 vty_out(vty, " substitute %pI4/%d",
12240 &range->subst_addr,
12241 range->subst_masklen);
12242
12243 vty_out(vty, "\n");
12244 }
12245
12246 if (EXPORT_NAME(area))
12247 vty_out(vty, " area %s export-list %s\n", buf,
12248 EXPORT_NAME(area));
12249
12250 if (IMPORT_NAME(area))
12251 vty_out(vty, " area %s import-list %s\n", buf,
12252 IMPORT_NAME(area));
12253
12254 if (PREFIX_NAME_IN(area))
12255 vty_out(vty, " area %s filter-list prefix %s in\n", buf,
12256 PREFIX_NAME_IN(area));
12257
12258 if (PREFIX_NAME_OUT(area))
12259 vty_out(vty, " area %s filter-list prefix %s out\n",
12260 buf, PREFIX_NAME_OUT(area));
12261 }
12262
12263 return 0;
12264 }
12265
12266 static int config_write_ospf_nbr_nbma(struct vty *vty, struct ospf *ospf)
12267 {
12268 struct ospf_nbr_nbma *nbr_nbma;
12269 struct route_node *rn;
12270
12271 /* Static Neighbor configuration print. */
12272 for (rn = route_top(ospf->nbr_nbma); rn; rn = route_next(rn))
12273 if ((nbr_nbma = rn->info)) {
12274 vty_out(vty, " neighbor %pI4", &nbr_nbma->addr);
12275
12276 if (nbr_nbma->priority
12277 != OSPF_NEIGHBOR_PRIORITY_DEFAULT)
12278 vty_out(vty, " priority %d",
12279 nbr_nbma->priority);
12280
12281 if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT)
12282 vty_out(vty, " poll-interval %d",
12283 nbr_nbma->v_poll);
12284
12285 vty_out(vty, "\n");
12286 }
12287
12288 return 0;
12289 }
12290
12291 static int config_write_virtual_link(struct vty *vty, struct ospf *ospf)
12292 {
12293 struct listnode *node;
12294 struct ospf_vl_data *vl_data;
12295 const char *auth_str;
12296 char buf[INET_ADDRSTRLEN];
12297
12298 /* Virtual-Link print */
12299 for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl_data)) {
12300 struct listnode *n2;
12301 struct crypt_key *ck;
12302 struct ospf_interface *oi;
12303
12304 if (vl_data != NULL) {
12305 area_id2str(buf, sizeof(buf), &vl_data->vl_area_id,
12306 vl_data->vl_area_id_fmt);
12307 oi = vl_data->vl_oi;
12308
12309 /* timers */
12310 if (OSPF_IF_PARAM(oi, v_hello)
12311 != OSPF_HELLO_INTERVAL_DEFAULT
12312 || OSPF_IF_PARAM(oi, v_wait)
12313 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
12314 || OSPF_IF_PARAM(oi, retransmit_interval)
12315 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
12316 || OSPF_IF_PARAM(oi, transmit_delay)
12317 != OSPF_TRANSMIT_DELAY_DEFAULT)
12318 vty_out(vty,
12319 " area %s virtual-link %pI4 hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n",
12320 buf, &vl_data->vl_peer,
12321 OSPF_IF_PARAM(oi, v_hello),
12322 OSPF_IF_PARAM(oi, retransmit_interval),
12323 OSPF_IF_PARAM(oi, transmit_delay),
12324 OSPF_IF_PARAM(oi, v_wait));
12325 else
12326 vty_out(vty, " area %s virtual-link %pI4\n", buf,
12327 &vl_data->vl_peer);
12328 /* Auth type */
12329 auth_str = interface_config_auth_str(
12330 IF_DEF_PARAMS(oi->ifp));
12331 if (auth_str)
12332 vty_out(vty,
12333 " area %s virtual-link %pI4 authentication%s\n",
12334 buf, &vl_data->vl_peer, auth_str);
12335 /* Auth key */
12336 if (IF_DEF_PARAMS(vl_data->vl_oi->ifp)->auth_simple[0]
12337 != '\0')
12338 vty_out(vty,
12339 " area %s virtual-link %pI4 authentication-key %s\n",
12340 buf, &vl_data->vl_peer,
12341 IF_DEF_PARAMS(vl_data->vl_oi->ifp)
12342 ->auth_simple);
12343 /* md5 keys */
12344 for (ALL_LIST_ELEMENTS_RO(
12345 IF_DEF_PARAMS(vl_data->vl_oi->ifp)
12346 ->auth_crypt,
12347 n2, ck))
12348 vty_out(vty,
12349 " area %s virtual-link %pI4 message-digest-key %d md5 %s\n",
12350 buf, &vl_data->vl_peer,
12351 ck->key_id, ck->auth_key);
12352 }
12353 }
12354
12355 return 0;
12356 }
12357
12358
12359 static int config_write_ospf_redistribute(struct vty *vty, struct ospf *ospf)
12360 {
12361 int type;
12362
12363 /* redistribute print. */
12364 for (type = 0; type < ZEBRA_ROUTE_MAX; type++) {
12365 struct list *red_list;
12366 struct listnode *node;
12367 struct ospf_redist *red;
12368
12369 red_list = ospf->redist[type];
12370 if (!red_list)
12371 continue;
12372
12373 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12374 vty_out(vty, " redistribute %s",
12375 zebra_route_string(type));
12376 if (red->instance)
12377 vty_out(vty, " %d", red->instance);
12378
12379 if (red->dmetric.value >= 0)
12380 vty_out(vty, " metric %d", red->dmetric.value);
12381
12382 if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1)
12383 vty_out(vty, " metric-type 1");
12384
12385 if (ROUTEMAP_NAME(red))
12386 vty_out(vty, " route-map %s",
12387 ROUTEMAP_NAME(red));
12388
12389 vty_out(vty, "\n");
12390 }
12391 }
12392
12393 return 0;
12394 }
12395
12396 static int ospf_cfg_write_helper_dis_rtr_walkcb(struct hash_bucket *bucket,
12397 void *arg)
12398 {
12399 struct advRtr *rtr = bucket->data;
12400 struct vty *vty = (struct vty *)arg;
12401
12402 vty_out(vty, " graceful-restart helper enable %pI4\n",
12403 &rtr->advRtrAddr);
12404 return HASHWALK_CONTINUE;
12405 }
12406
12407 static void config_write_ospf_gr(struct vty *vty, struct ospf *ospf)
12408 {
12409 if (!ospf->gr_info.restart_support)
12410 return;
12411
12412 if (ospf->gr_info.grace_period == OSPF_DFLT_GRACE_INTERVAL)
12413 vty_out(vty, " graceful-restart\n");
12414 else
12415 vty_out(vty, " graceful-restart grace-period %u\n",
12416 ospf->gr_info.grace_period);
12417 }
12418
12419 static int config_write_ospf_gr_helper(struct vty *vty, struct ospf *ospf)
12420 {
12421 if (ospf->is_helper_supported)
12422 vty_out(vty, " graceful-restart helper enable\n");
12423
12424 if (!ospf->strict_lsa_check)
12425 vty_out(vty,
12426 " no graceful-restart helper strict-lsa-checking\n");
12427
12428 if (ospf->only_planned_restart)
12429 vty_out(vty, " graceful-restart helper planned-only\n");
12430
12431 if (ospf->supported_grace_time != OSPF_MAX_GRACE_INTERVAL)
12432 vty_out(vty,
12433 " graceful-restart helper supported-grace-time %d\n",
12434 ospf->supported_grace_time);
12435
12436 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf)) {
12437 hash_walk(ospf->enable_rtr_list,
12438 ospf_cfg_write_helper_dis_rtr_walkcb, vty);
12439 }
12440 return 0;
12441 }
12442
12443 static int config_write_ospf_external_aggregator(struct vty *vty,
12444 struct ospf *ospf)
12445 {
12446 struct route_node *rn;
12447
12448 if (ospf->aggr_delay_interval != OSPF_EXTL_AGGR_DEFAULT_DELAY)
12449 vty_out(vty, " aggregation timer %u\n",
12450 ospf->aggr_delay_interval);
12451
12452 /* print 'summary-address A.B.C.D/M' */
12453 for (rn = route_top(ospf->rt_aggr_tbl); rn; rn = route_next(rn))
12454 if (rn->info) {
12455 struct ospf_external_aggr_rt *aggr = rn->info;
12456
12457 vty_out(vty, " summary-address %pI4/%d",
12458 &aggr->p.prefix, aggr->p.prefixlen);
12459 if (aggr->tag)
12460 vty_out(vty, " tag %u", aggr->tag);
12461
12462 if (CHECK_FLAG(aggr->flags,
12463 OSPF_EXTERNAL_AGGRT_NO_ADVERTISE))
12464 vty_out(vty, " no-advertise");
12465
12466 vty_out(vty, "\n");
12467 }
12468
12469 return 0;
12470 }
12471
12472 static int config_write_ospf_default_metric(struct vty *vty, struct ospf *ospf)
12473 {
12474 if (ospf->default_metric != -1)
12475 vty_out(vty, " default-metric %d\n", ospf->default_metric);
12476 return 0;
12477 }
12478
12479 static int config_write_ospf_distribute(struct vty *vty, struct ospf *ospf)
12480 {
12481 int type;
12482 struct ospf_redist *red;
12483
12484 if (ospf) {
12485 /* distribute-list print. */
12486 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
12487 if (DISTRIBUTE_NAME(ospf, type))
12488 vty_out(vty, " distribute-list %s out %s\n",
12489 DISTRIBUTE_NAME(ospf, type),
12490 zebra_route_string(type));
12491
12492 /* default-information print. */
12493 if (ospf->default_originate != DEFAULT_ORIGINATE_NONE) {
12494 vty_out(vty, " default-information originate");
12495 if (ospf->default_originate == DEFAULT_ORIGINATE_ALWAYS)
12496 vty_out(vty, " always");
12497
12498 red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0);
12499 if (red) {
12500 if (red->dmetric.value >= 0)
12501 vty_out(vty, " metric %d",
12502 red->dmetric.value);
12503
12504 if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1)
12505 vty_out(vty, " metric-type 1");
12506
12507 if (ROUTEMAP_NAME(red))
12508 vty_out(vty, " route-map %s",
12509 ROUTEMAP_NAME(red));
12510 }
12511
12512 vty_out(vty, "\n");
12513 }
12514 }
12515
12516 return 0;
12517 }
12518
12519 static int config_write_ospf_distance(struct vty *vty, struct ospf *ospf)
12520 {
12521 struct route_node *rn;
12522 struct ospf_distance *odistance;
12523
12524 if (ospf->distance_all)
12525 vty_out(vty, " distance %d\n", ospf->distance_all);
12526
12527 if (ospf->distance_intra || ospf->distance_inter
12528 || ospf->distance_external) {
12529 vty_out(vty, " distance ospf");
12530
12531 if (ospf->distance_intra)
12532 vty_out(vty, " intra-area %d", ospf->distance_intra);
12533 if (ospf->distance_inter)
12534 vty_out(vty, " inter-area %d", ospf->distance_inter);
12535 if (ospf->distance_external)
12536 vty_out(vty, " external %d", ospf->distance_external);
12537
12538 vty_out(vty, "\n");
12539 }
12540
12541 for (rn = route_top(ospf->distance_table); rn; rn = route_next(rn))
12542 if ((odistance = rn->info) != NULL) {
12543 vty_out(vty, " distance %d %pFX %s\n",
12544 odistance->distance, &rn->p,
12545 odistance->access_list ? odistance->access_list
12546 : "");
12547 }
12548 return 0;
12549 }
12550
12551 static int ospf_config_write_one(struct vty *vty, struct ospf *ospf)
12552 {
12553 int write = 0;
12554
12555 /* `router ospf' print. */
12556 if (ospf->instance && strcmp(ospf->name, VRF_DEFAULT_NAME)) {
12557 vty_out(vty, "router ospf %d vrf %s\n", ospf->instance,
12558 ospf->name);
12559 } else if (ospf->instance) {
12560 vty_out(vty, "router ospf %d\n", ospf->instance);
12561 } else if (strcmp(ospf->name, VRF_DEFAULT_NAME)) {
12562 vty_out(vty, "router ospf vrf %s\n", ospf->name);
12563 } else
12564 vty_out(vty, "router ospf\n");
12565
12566 if (!ospf->networks) {
12567 write++;
12568 return write;
12569 }
12570
12571 /* Router ID print. */
12572 if (ospf->router_id_static.s_addr != INADDR_ANY)
12573 vty_out(vty, " ospf router-id %pI4\n",
12574 &ospf->router_id_static);
12575
12576 /* zebra opaque attributes configuration. */
12577 if (CHECK_FLAG(ospf->config, OSPF_SEND_EXTRA_DATA_TO_ZEBRA))
12578 vty_out(vty, " ospf send-extra-data zebra\n");
12579
12580 /* ABR type print. */
12581 if (ospf->abr_type != OSPF_ABR_DEFAULT)
12582 vty_out(vty, " ospf abr-type %s\n",
12583 ospf_abr_type_str[ospf->abr_type]);
12584
12585 /* log-adjacency-changes flag print. */
12586 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) {
12587 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL))
12588 vty_out(vty, " log-adjacency-changes detail\n");
12589 else if (!SAVE_OSPF_LOG_ADJACENCY_CHANGES)
12590 vty_out(vty, " log-adjacency-changes\n");
12591 } else if (SAVE_OSPF_LOG_ADJACENCY_CHANGES) {
12592 vty_out(vty, " no log-adjacency-changes\n");
12593 }
12594
12595 /* RFC1583 compatibility flag print -- Compatible with CISCO
12596 * 12.1. */
12597 if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE))
12598 vty_out(vty, " compatible rfc1583\n");
12599
12600 /* auto-cost reference-bandwidth configuration. */
12601 if (ospf->ref_bandwidth != OSPF_DEFAULT_REF_BANDWIDTH) {
12602 vty_out(vty,
12603 "! Important: ensure reference bandwidth is consistent across all routers\n");
12604 vty_out(vty, " auto-cost reference-bandwidth %d\n",
12605 ospf->ref_bandwidth);
12606 }
12607
12608 /* SPF timers print. */
12609 if (ospf->spf_delay != OSPF_SPF_DELAY_DEFAULT
12610 || ospf->spf_holdtime != OSPF_SPF_HOLDTIME_DEFAULT
12611 || ospf->spf_max_holdtime != OSPF_SPF_MAX_HOLDTIME_DEFAULT)
12612 vty_out(vty, " timers throttle spf %d %d %d\n", ospf->spf_delay,
12613 ospf->spf_holdtime, ospf->spf_max_holdtime);
12614
12615 /* LSA timers print. */
12616 if (ospf->min_ls_interval != OSPF_MIN_LS_INTERVAL)
12617 vty_out(vty, " timers throttle lsa all %d\n",
12618 ospf->min_ls_interval);
12619 if (ospf->min_ls_arrival != OSPF_MIN_LS_ARRIVAL)
12620 vty_out(vty, " timers lsa min-arrival %d\n",
12621 ospf->min_ls_arrival);
12622
12623 /* Write multiplier print. */
12624 if (ospf->write_oi_count != OSPF_WRITE_INTERFACE_COUNT_DEFAULT)
12625 vty_out(vty, " ospf write-multiplier %d\n",
12626 ospf->write_oi_count);
12627
12628 if (ospf->max_multipath != MULTIPATH_NUM)
12629 vty_out(vty, " maximum-paths %d\n", ospf->max_multipath);
12630
12631 /* Max-metric router-lsa print */
12632 config_write_stub_router(vty, ospf);
12633
12634 /* SPF refresh parameters print. */
12635 if (ospf->lsa_refresh_interval != OSPF_LSA_REFRESH_INTERVAL_DEFAULT)
12636 vty_out(vty, " refresh timer %d\n", ospf->lsa_refresh_interval);
12637
12638 /* Redistribute information print. */
12639 config_write_ospf_redistribute(vty, ospf);
12640
12641 /* Graceful Restart print */
12642 config_write_ospf_gr(vty, ospf);
12643 config_write_ospf_gr_helper(vty, ospf);
12644
12645 /* Print external route aggregation. */
12646 config_write_ospf_external_aggregator(vty, ospf);
12647
12648 /* passive-interface print. */
12649 if (ospf->passive_interface_default == OSPF_IF_PASSIVE)
12650 vty_out(vty, " passive-interface default\n");
12651
12652 /* proactive-arp print. */
12653 if (ospf->proactive_arp != OSPF_PROACTIVE_ARP_DEFAULT) {
12654 if (ospf->proactive_arp)
12655 vty_out(vty, " proactive-arp\n");
12656 else
12657 vty_out(vty, " no proactive-arp\n");
12658 }
12659
12660 /* TI-LFA print. */
12661 if (ospf->ti_lfa_enabled) {
12662 if (ospf->ti_lfa_protection_type == OSPF_TI_LFA_NODE_PROTECTION)
12663 vty_out(vty, " fast-reroute ti-lfa node-protection\n");
12664 else
12665 vty_out(vty, " fast-reroute ti-lfa\n");
12666 }
12667
12668 /* Network area print. */
12669 config_write_network_area(vty, ospf);
12670
12671 /* Area config print. */
12672 config_write_ospf_area(vty, ospf);
12673
12674 /* static neighbor print. */
12675 config_write_ospf_nbr_nbma(vty, ospf);
12676
12677 /* Virtual-Link print. */
12678 config_write_virtual_link(vty, ospf);
12679
12680 /* Default metric configuration. */
12681 config_write_ospf_default_metric(vty, ospf);
12682
12683 /* Distribute-list and default-information print. */
12684 config_write_ospf_distribute(vty, ospf);
12685
12686 /* Distance configuration. */
12687 config_write_ospf_distance(vty, ospf);
12688
12689 ospf_opaque_config_write_router(vty, ospf);
12690
12691 /* LDP-Sync print */
12692 ospf_ldp_sync_write_config(vty, ospf);
12693
12694 vty_out(vty, "exit\n");
12695
12696 write++;
12697 return write;
12698 }
12699
12700 /* OSPF configuration write function. */
12701 static int ospf_config_write(struct vty *vty)
12702 {
12703 struct ospf *ospf;
12704 struct listnode *ospf_node = NULL;
12705 int write = 0;
12706
12707 if (listcount(om->ospf) == 0)
12708 return write;
12709
12710 for (ALL_LIST_ELEMENTS_RO(om->ospf, ospf_node, ospf)) {
12711 /* VRF Default check if it is running.
12712 * Upon daemon start, there could be default instance
12713 * in absence of 'router ospf'/oi_running is disabled. */
12714 if (ospf->vrf_id == VRF_DEFAULT && ospf->oi_running)
12715 write += ospf_config_write_one(vty, ospf);
12716 /* For Non-Default VRF simply display the configuration,
12717 * even if it is not oi_running. */
12718 else if (ospf->vrf_id != VRF_DEFAULT)
12719 write += ospf_config_write_one(vty, ospf);
12720 }
12721 return write;
12722 }
12723
12724 void ospf_vty_show_init(void)
12725 {
12726 /* "show ip ospf" commands. */
12727 install_element(VIEW_NODE, &show_ip_ospf_cmd);
12728
12729 install_element(VIEW_NODE, &show_ip_ospf_instance_cmd);
12730
12731 /* "show ip ospf database" commands. */
12732 install_element(VIEW_NODE, &show_ip_ospf_database_cmd);
12733 install_element(VIEW_NODE, &show_ip_ospf_database_max_cmd);
12734 install_element(VIEW_NODE,
12735 &show_ip_ospf_database_type_adv_router_cmd);
12736 install_element(VIEW_NODE,
12737 &show_ip_ospf_instance_database_type_adv_router_cmd);
12738 install_element(VIEW_NODE, &show_ip_ospf_instance_database_cmd);
12739 install_element(VIEW_NODE, &show_ip_ospf_instance_database_max_cmd);
12740
12741 /* "show ip ospf interface" commands. */
12742 install_element(VIEW_NODE, &show_ip_ospf_interface_cmd);
12743
12744 install_element(VIEW_NODE, &show_ip_ospf_instance_interface_cmd);
12745 /* "show ip ospf interface traffic */
12746 install_element(VIEW_NODE, &show_ip_ospf_interface_traffic_cmd);
12747
12748 /* "show ip ospf neighbor" commands. */
12749 install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_detail_cmd);
12750 install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_cmd);
12751 install_element(VIEW_NODE, &show_ip_ospf_neighbor_id_cmd);
12752 install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_all_cmd);
12753 install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_cmd);
12754 install_element(VIEW_NODE, &show_ip_ospf_neighbor_cmd);
12755 install_element(VIEW_NODE, &show_ip_ospf_neighbor_all_cmd);
12756
12757 install_element(VIEW_NODE,
12758 &show_ip_ospf_instance_neighbor_int_detail_cmd);
12759 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_int_cmd);
12760 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_id_cmd);
12761 install_element(VIEW_NODE,
12762 &show_ip_ospf_instance_neighbor_detail_all_cmd);
12763 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_detail_cmd);
12764 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_cmd);
12765 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_all_cmd);
12766
12767 /* "show ip ospf route" commands. */
12768 install_element(VIEW_NODE, &show_ip_ospf_route_cmd);
12769 install_element(VIEW_NODE, &show_ip_ospf_border_routers_cmd);
12770 install_element(VIEW_NODE, &show_ip_ospf_reachable_routers_cmd);
12771
12772 install_element(VIEW_NODE, &show_ip_ospf_instance_route_cmd);
12773 install_element(VIEW_NODE, &show_ip_ospf_instance_border_routers_cmd);
12774 install_element(VIEW_NODE,
12775 &show_ip_ospf_instance_reachable_routers_cmd);
12776
12777 /* "show ip ospf vrfs" commands. */
12778 install_element(VIEW_NODE, &show_ip_ospf_vrfs_cmd);
12779
12780 /* "show ip ospf gr-helper details" command */
12781 install_element(VIEW_NODE, &show_ip_ospf_gr_helper_cmd);
12782
12783 /* "show ip ospf summary-address" command */
12784 install_element(VIEW_NODE, &show_ip_ospf_external_aggregator_cmd);
12785 }
12786
12787 /* Initialization of OSPF interface. */
12788 static void ospf_vty_if_init(void)
12789 {
12790 /* Install interface node. */
12791 if_cmd_init(config_write_interface);
12792
12793 /* "ip ospf authentication" commands. */
12794 install_element(INTERFACE_NODE, &ip_ospf_authentication_args_addr_cmd);
12795 install_element(INTERFACE_NODE, &ip_ospf_authentication_addr_cmd);
12796 install_element(INTERFACE_NODE,
12797 &no_ip_ospf_authentication_args_addr_cmd);
12798 install_element(INTERFACE_NODE, &no_ip_ospf_authentication_addr_cmd);
12799 install_element(INTERFACE_NODE, &ip_ospf_authentication_key_addr_cmd);
12800 install_element(INTERFACE_NODE,
12801 &no_ip_ospf_authentication_key_authkey_addr_cmd);
12802 install_element(INTERFACE_NODE,
12803 &no_ospf_authentication_key_authkey_addr_cmd);
12804
12805 /* "ip ospf message-digest-key" commands. */
12806 install_element(INTERFACE_NODE, &ip_ospf_message_digest_key_cmd);
12807 install_element(INTERFACE_NODE, &no_ip_ospf_message_digest_key_cmd);
12808
12809 /* "ip ospf cost" commands. */
12810 install_element(INTERFACE_NODE, &ip_ospf_cost_cmd);
12811 install_element(INTERFACE_NODE, &no_ip_ospf_cost_cmd);
12812
12813 /* "ip ospf mtu-ignore" commands. */
12814 install_element(INTERFACE_NODE, &ip_ospf_mtu_ignore_addr_cmd);
12815 install_element(INTERFACE_NODE, &no_ip_ospf_mtu_ignore_addr_cmd);
12816
12817 /* "ip ospf dead-interval" commands. */
12818 install_element(INTERFACE_NODE, &ip_ospf_dead_interval_cmd);
12819 install_element(INTERFACE_NODE,
12820 &ip_ospf_dead_interval_minimal_addr_cmd);
12821 install_element(INTERFACE_NODE, &no_ip_ospf_dead_interval_cmd);
12822
12823 /* "ip ospf hello-interval" commands. */
12824 install_element(INTERFACE_NODE, &ip_ospf_hello_interval_cmd);
12825 install_element(INTERFACE_NODE, &no_ip_ospf_hello_interval_cmd);
12826
12827 /* "ip ospf network" commands. */
12828 install_element(INTERFACE_NODE, &ip_ospf_network_cmd);
12829 install_element(INTERFACE_NODE, &no_ip_ospf_network_cmd);
12830
12831 /* "ip ospf priority" commands. */
12832 install_element(INTERFACE_NODE, &ip_ospf_priority_cmd);
12833 install_element(INTERFACE_NODE, &no_ip_ospf_priority_cmd);
12834
12835 /* "ip ospf retransmit-interval" commands. */
12836 install_element(INTERFACE_NODE, &ip_ospf_retransmit_interval_addr_cmd);
12837 install_element(INTERFACE_NODE,
12838 &no_ip_ospf_retransmit_interval_addr_cmd);
12839
12840 /* "ip ospf transmit-delay" commands. */
12841 install_element(INTERFACE_NODE, &ip_ospf_transmit_delay_addr_cmd);
12842 install_element(INTERFACE_NODE, &no_ip_ospf_transmit_delay_addr_cmd);
12843
12844 /* "ip ospf area" commands. */
12845 install_element(INTERFACE_NODE, &ip_ospf_area_cmd);
12846 install_element(INTERFACE_NODE, &no_ip_ospf_area_cmd);
12847
12848 /* "ip ospf passive" commands. */
12849 install_element(INTERFACE_NODE, &ip_ospf_passive_cmd);
12850 install_element(INTERFACE_NODE, &no_ip_ospf_passive_cmd);
12851
12852 /* These commands are compatibitliy for previous version. */
12853 install_element(INTERFACE_NODE, &ospf_authentication_key_cmd);
12854 install_element(INTERFACE_NODE, &ospf_message_digest_key_cmd);
12855 install_element(INTERFACE_NODE, &no_ospf_message_digest_key_cmd);
12856 install_element(INTERFACE_NODE, &ospf_dead_interval_cmd);
12857 install_element(INTERFACE_NODE, &no_ospf_dead_interval_cmd);
12858 install_element(INTERFACE_NODE, &ospf_hello_interval_cmd);
12859 install_element(INTERFACE_NODE, &no_ospf_hello_interval_cmd);
12860 install_element(INTERFACE_NODE, &ospf_cost_cmd);
12861 install_element(INTERFACE_NODE, &no_ospf_cost_cmd);
12862 install_element(INTERFACE_NODE, &ospf_network_cmd);
12863 install_element(INTERFACE_NODE, &no_ospf_network_cmd);
12864 install_element(INTERFACE_NODE, &ospf_priority_cmd);
12865 install_element(INTERFACE_NODE, &no_ospf_priority_cmd);
12866 install_element(INTERFACE_NODE, &ospf_retransmit_interval_cmd);
12867 install_element(INTERFACE_NODE, &no_ospf_retransmit_interval_cmd);
12868 install_element(INTERFACE_NODE, &ospf_transmit_delay_cmd);
12869 install_element(INTERFACE_NODE, &no_ospf_transmit_delay_cmd);
12870 }
12871
12872 static void ospf_vty_zebra_init(void)
12873 {
12874 install_element(OSPF_NODE, &ospf_redistribute_source_cmd);
12875 install_element(OSPF_NODE, &no_ospf_redistribute_source_cmd);
12876 install_element(OSPF_NODE, &ospf_redistribute_instance_source_cmd);
12877 install_element(OSPF_NODE, &no_ospf_redistribute_instance_source_cmd);
12878
12879 install_element(OSPF_NODE, &ospf_distribute_list_out_cmd);
12880 install_element(OSPF_NODE, &no_ospf_distribute_list_out_cmd);
12881
12882 install_element(OSPF_NODE, &ospf_default_information_originate_cmd);
12883 install_element(OSPF_NODE, &no_ospf_default_information_originate_cmd);
12884
12885 install_element(OSPF_NODE, &ospf_default_metric_cmd);
12886 install_element(OSPF_NODE, &no_ospf_default_metric_cmd);
12887
12888 install_element(OSPF_NODE, &ospf_distance_cmd);
12889 install_element(OSPF_NODE, &no_ospf_distance_cmd);
12890 install_element(OSPF_NODE, &no_ospf_distance_ospf_cmd);
12891 install_element(OSPF_NODE, &ospf_distance_ospf_cmd);
12892
12893 /*Ospf garcefull restart helper configurations */
12894 install_element(OSPF_NODE, &ospf_gr_helper_enable_cmd);
12895 install_element(OSPF_NODE, &no_ospf_gr_helper_enable_cmd);
12896 install_element(OSPF_NODE, &ospf_gr_helper_enable_lsacheck_cmd);
12897 install_element(OSPF_NODE, &no_ospf_gr_helper_enable_lsacheck_cmd);
12898 install_element(OSPF_NODE, &ospf_gr_helper_supported_grace_time_cmd);
12899 install_element(OSPF_NODE, &no_ospf_gr_helper_supported_grace_time_cmd);
12900 install_element(OSPF_NODE, &ospf_gr_helper_planned_only_cmd);
12901 install_element(OSPF_NODE, &no_ospf_gr_helper_planned_only_cmd);
12902
12903 /* External LSA summarisation config commands.*/
12904 install_element(OSPF_NODE, &ospf_external_route_aggregation_cmd);
12905 install_element(OSPF_NODE, &no_ospf_external_route_aggregation_cmd);
12906 install_element(OSPF_NODE,
12907 &ospf_external_route_aggregation_no_adrvertise_cmd);
12908 install_element(OSPF_NODE,
12909 &no_ospf_external_route_aggregation_no_adrvertise_cmd);
12910 install_element(OSPF_NODE, &ospf_route_aggregation_timer_cmd);
12911 install_element(OSPF_NODE, &no_ospf_route_aggregation_timer_cmd);
12912 }
12913
12914 static int ospf_config_write(struct vty *vty);
12915 static struct cmd_node ospf_node = {
12916 .name = "ospf",
12917 .node = OSPF_NODE,
12918 .parent_node = CONFIG_NODE,
12919 .prompt = "%s(config-router)# ",
12920 .config_write = ospf_config_write,
12921 };
12922
12923 static void ospf_interface_clear(struct interface *ifp)
12924 {
12925 if (!if_is_operative(ifp))
12926 return;
12927
12928 if (IS_DEBUG_OSPF(ism, ISM_EVENTS))
12929 zlog_debug("ISM[%s]: clear by reset", ifp->name);
12930
12931 ospf_if_reset(ifp);
12932 }
12933
12934 DEFUN (clear_ip_ospf_interface,
12935 clear_ip_ospf_interface_cmd,
12936 "clear ip ospf [vrf NAME] interface [IFNAME]",
12937 CLEAR_STR
12938 IP_STR
12939 "OSPF information\n"
12940 VRF_CMD_HELP_STR
12941 "Interface information\n"
12942 "Interface name\n")
12943 {
12944 int idx_ifname = 0;
12945 int idx_vrf = 0;
12946 struct interface *ifp;
12947 struct listnode *node;
12948 struct ospf *ospf = NULL;
12949 char *vrf_name = NULL;
12950 vrf_id_t vrf_id = VRF_DEFAULT;
12951 struct vrf *vrf = NULL;
12952
12953 if (argv_find(argv, argc, "vrf", &idx_vrf))
12954 vrf_name = argv[idx_vrf + 1]->arg;
12955 if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME))
12956 vrf_name = NULL;
12957 if (vrf_name) {
12958 vrf = vrf_lookup_by_name(vrf_name);
12959 if (vrf)
12960 vrf_id = vrf->vrf_id;
12961 }
12962 if (!argv_find(argv, argc, "IFNAME", &idx_ifname)) {
12963 /* Clear all the ospfv2 interfaces. */
12964 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
12965 if (vrf_id != ospf->vrf_id)
12966 continue;
12967 if (!vrf)
12968 vrf = vrf_lookup_by_id(ospf->vrf_id);
12969 FOR_ALL_INTERFACES (vrf, ifp)
12970 ospf_interface_clear(ifp);
12971 }
12972 } else {
12973 /* Interface name is specified. */
12974 ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id);
12975 if (ifp == NULL)
12976 vty_out(vty, "No such interface name\n");
12977 else
12978 ospf_interface_clear(ifp);
12979 }
12980
12981 return CMD_SUCCESS;
12982 }
12983
12984 DEFPY_HIDDEN(ospf_lsa_refresh_timer, ospf_lsa_refresh_timer_cmd,
12985 "[no$no] ospf lsa-refresh [(120-1800)]$value",
12986 NO_STR OSPF_STR
12987 "OSPF lsa refresh timer\n"
12988 "timer value in seconds\n")
12989 {
12990 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf)
12991
12992 if (no)
12993 ospf->lsa_refresh_timer = OSPF_LS_REFRESH_TIME;
12994 else
12995 ospf->lsa_refresh_timer = value;
12996
12997 return CMD_SUCCESS;
12998 }
12999
13000 DEFPY_HIDDEN(ospf_maxage_delay_timer, ospf_maxage_delay_timer_cmd,
13001 "[no$no] ospf maxage-delay [(0-60)]$value",
13002 NO_STR OSPF_STR
13003 "OSPF lsa maxage delay timer\n"
13004 "timer value in seconds\n")
13005 {
13006 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf)
13007
13008 if (no)
13009 ospf->maxage_delay = OSPF_LSA_MAXAGE_REMOVE_DELAY_DEFAULT;
13010 else
13011 ospf->maxage_delay = value;
13012
13013 THREAD_OFF(ospf->t_maxage);
13014 OSPF_TIMER_ON(ospf->t_maxage, ospf_maxage_lsa_remover,
13015 ospf->maxage_delay);
13016
13017 return CMD_SUCCESS;
13018 }
13019
13020 void ospf_vty_clear_init(void)
13021 {
13022 install_element(ENABLE_NODE, &clear_ip_ospf_interface_cmd);
13023 install_element(ENABLE_NODE, &clear_ip_ospf_process_cmd);
13024 install_element(ENABLE_NODE, &clear_ip_ospf_neighbor_cmd);
13025 }
13026
13027
13028 /* Install OSPF related vty commands. */
13029 void ospf_vty_init(void)
13030 {
13031 /* Install ospf top node. */
13032 install_node(&ospf_node);
13033
13034 /* "router ospf" commands. */
13035 install_element(CONFIG_NODE, &router_ospf_cmd);
13036 install_element(CONFIG_NODE, &no_router_ospf_cmd);
13037
13038
13039 install_default(OSPF_NODE);
13040
13041 /* "ospf router-id" commands. */
13042 install_element(OSPF_NODE, &ospf_router_id_cmd);
13043 install_element(OSPF_NODE, &ospf_router_id_old_cmd);
13044 install_element(OSPF_NODE, &no_ospf_router_id_cmd);
13045
13046 /* "passive-interface" commands. */
13047 install_element(OSPF_NODE, &ospf_passive_interface_default_cmd);
13048 install_element(OSPF_NODE, &ospf_passive_interface_addr_cmd);
13049 install_element(OSPF_NODE, &no_ospf_passive_interface_default_cmd);
13050 install_element(OSPF_NODE, &no_ospf_passive_interface_addr_cmd);
13051
13052 /* "ospf abr-type" commands. */
13053 install_element(OSPF_NODE, &ospf_abr_type_cmd);
13054 install_element(OSPF_NODE, &no_ospf_abr_type_cmd);
13055
13056 /* "ospf log-adjacency-changes" commands. */
13057 install_element(OSPF_NODE, &ospf_log_adjacency_changes_cmd);
13058 install_element(OSPF_NODE, &ospf_log_adjacency_changes_detail_cmd);
13059 install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_cmd);
13060 install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_detail_cmd);
13061
13062 /* "ospf rfc1583-compatible" commands. */
13063 install_element(OSPF_NODE, &ospf_compatible_rfc1583_cmd);
13064 install_element(OSPF_NODE, &no_ospf_compatible_rfc1583_cmd);
13065 install_element(OSPF_NODE, &ospf_rfc1583_flag_cmd);
13066 install_element(OSPF_NODE, &no_ospf_rfc1583_flag_cmd);
13067
13068 /* "ospf send-extra-data zebra" commands. */
13069 install_element(OSPF_NODE, &ospf_send_extra_data_cmd);
13070
13071 /* "network area" commands. */
13072 install_element(OSPF_NODE, &ospf_network_area_cmd);
13073 install_element(OSPF_NODE, &no_ospf_network_area_cmd);
13074
13075 /* "area authentication" commands. */
13076 install_element(OSPF_NODE,
13077 &ospf_area_authentication_message_digest_cmd);
13078 install_element(OSPF_NODE, &ospf_area_authentication_cmd);
13079 install_element(OSPF_NODE, &no_ospf_area_authentication_cmd);
13080
13081 /* "area range" commands. */
13082 install_element(OSPF_NODE, &ospf_area_range_cmd);
13083 install_element(OSPF_NODE, &ospf_area_range_cost_cmd);
13084 install_element(OSPF_NODE, &ospf_area_range_not_advertise_cmd);
13085 install_element(OSPF_NODE, &no_ospf_area_range_cmd);
13086 install_element(OSPF_NODE, &no_ospf_area_range_substitute_cmd);
13087
13088 /* "area virtual-link" commands. */
13089 install_element(OSPF_NODE, &ospf_area_vlink_cmd);
13090 install_element(OSPF_NODE, &ospf_area_vlink_intervals_cmd);
13091 install_element(OSPF_NODE, &no_ospf_area_vlink_cmd);
13092 install_element(OSPF_NODE, &no_ospf_area_vlink_intervals_cmd);
13093
13094
13095 /* "area stub" commands. */
13096 install_element(OSPF_NODE, &ospf_area_stub_no_summary_cmd);
13097 install_element(OSPF_NODE, &ospf_area_stub_cmd);
13098 install_element(OSPF_NODE, &no_ospf_area_stub_no_summary_cmd);
13099 install_element(OSPF_NODE, &no_ospf_area_stub_cmd);
13100
13101 /* "area nssa" commands. */
13102 install_element(OSPF_NODE, &ospf_area_nssa_cmd);
13103 install_element(OSPF_NODE, &ospf_area_nssa_translate_cmd);
13104 install_element(OSPF_NODE, &ospf_area_nssa_no_summary_cmd);
13105 install_element(OSPF_NODE, &no_ospf_area_nssa_no_summary_cmd);
13106 install_element(OSPF_NODE, &ospf_area_nssa_suppress_fa_cmd);
13107 install_element(OSPF_NODE, &no_ospf_area_nssa_suppress_fa_cmd);
13108 install_element(OSPF_NODE, &no_ospf_area_nssa_cmd);
13109
13110 install_element(OSPF_NODE, &ospf_area_default_cost_cmd);
13111 install_element(OSPF_NODE, &no_ospf_area_default_cost_cmd);
13112
13113 install_element(OSPF_NODE, &ospf_area_shortcut_cmd);
13114 install_element(OSPF_NODE, &no_ospf_area_shortcut_cmd);
13115
13116 install_element(OSPF_NODE, &ospf_area_export_list_cmd);
13117 install_element(OSPF_NODE, &no_ospf_area_export_list_cmd);
13118
13119 install_element(OSPF_NODE, &ospf_area_filter_list_cmd);
13120 install_element(OSPF_NODE, &no_ospf_area_filter_list_cmd);
13121
13122 install_element(OSPF_NODE, &ospf_area_import_list_cmd);
13123 install_element(OSPF_NODE, &no_ospf_area_import_list_cmd);
13124
13125 /* SPF timer commands */
13126 install_element(OSPF_NODE, &ospf_timers_throttle_spf_cmd);
13127 install_element(OSPF_NODE, &no_ospf_timers_throttle_spf_cmd);
13128
13129 /* LSA timers commands */
13130 install_element(OSPF_NODE, &ospf_timers_min_ls_interval_cmd);
13131 install_element(OSPF_NODE, &no_ospf_timers_min_ls_interval_cmd);
13132 install_element(OSPF_NODE, &ospf_timers_lsa_min_arrival_cmd);
13133 install_element(OSPF_NODE, &no_ospf_timers_lsa_min_arrival_cmd);
13134
13135 /* refresh timer commands */
13136 install_element(OSPF_NODE, &ospf_refresh_timer_cmd);
13137 install_element(OSPF_NODE, &no_ospf_refresh_timer_val_cmd);
13138
13139 /* max-metric commands */
13140 install_element(OSPF_NODE, &ospf_max_metric_router_lsa_admin_cmd);
13141 install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_admin_cmd);
13142 install_element(OSPF_NODE, &ospf_max_metric_router_lsa_startup_cmd);
13143 install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_startup_cmd);
13144 install_element(OSPF_NODE, &ospf_max_metric_router_lsa_shutdown_cmd);
13145 install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_shutdown_cmd);
13146
13147 /* reference bandwidth commands */
13148 install_element(OSPF_NODE, &ospf_auto_cost_reference_bandwidth_cmd);
13149 install_element(OSPF_NODE, &no_ospf_auto_cost_reference_bandwidth_cmd);
13150
13151 /* "neighbor" commands. */
13152 install_element(OSPF_NODE, &ospf_neighbor_cmd);
13153 install_element(OSPF_NODE, &ospf_neighbor_poll_interval_cmd);
13154 install_element(OSPF_NODE, &no_ospf_neighbor_cmd);
13155 install_element(OSPF_NODE, &no_ospf_neighbor_poll_cmd);
13156
13157 /* write multiplier commands */
13158 install_element(OSPF_NODE, &ospf_write_multiplier_cmd);
13159 install_element(OSPF_NODE, &write_multiplier_cmd);
13160 install_element(OSPF_NODE, &no_ospf_write_multiplier_cmd);
13161 install_element(OSPF_NODE, &no_write_multiplier_cmd);
13162
13163 /* "proactive-arp" commands. */
13164 install_element(OSPF_NODE, &ospf_proactive_arp_cmd);
13165 install_element(OSPF_NODE, &no_ospf_proactive_arp_cmd);
13166
13167 /* TI-LFA commands */
13168 install_element(OSPF_NODE, &ospf_ti_lfa_cmd);
13169 install_element(OSPF_NODE, &no_ospf_ti_lfa_cmd);
13170
13171 /* Max path configurations */
13172 install_element(OSPF_NODE, &ospf_max_multipath_cmd);
13173 install_element(OSPF_NODE, &no_ospf_max_multipath_cmd);
13174
13175 vrf_cmd_init(NULL);
13176
13177 install_element(OSPF_NODE, &ospf_lsa_refresh_timer_cmd);
13178 install_element(OSPF_NODE, &ospf_maxage_delay_timer_cmd);
13179
13180 /* Init interface related vty commands. */
13181 ospf_vty_if_init();
13182
13183 /* Init zebra related vty commands. */
13184 ospf_vty_zebra_init();
13185 }