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