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