1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2005 6WIND <alain.ritoux@6wind.com>
4 * Copyright (C) 2000 Toshiaki Takada
23 #include "lib/printfrr.h"
25 #include "ospfd/ospfd.h"
26 #include "ospfd/ospf_asbr.h"
27 #include "ospfd/ospf_lsa.h"
28 #include "ospfd/ospf_lsdb.h"
29 #include "ospfd/ospf_ism.h"
30 #include "ospfd/ospf_interface.h"
31 #include "ospfd/ospf_nsm.h"
32 #include "ospfd/ospf_neighbor.h"
33 #include "ospfd/ospf_flood.h"
34 #include "ospfd/ospf_abr.h"
35 #include "ospfd/ospf_spf.h"
36 #include "ospfd/ospf_route.h"
37 #include "ospfd/ospf_zebra.h"
38 /*#include "ospfd/ospf_routemap.h" */
39 #include "ospfd/ospf_vty.h"
40 #include "ospfd/ospf_dump.h"
41 #include "ospfd/ospf_bfd.h"
42 #include "ospfd/ospf_ldp_sync.h"
45 FRR_CFG_DEFAULT_BOOL(OSPF_LOG_ADJACENCY_CHANGES
,
46 { .val_bool
= true, .match_profile
= "datacenter", },
47 { .val_bool
= false },
50 static const char *const ospf_network_type_str
[] = {
51 "Null", "POINTOPOINT", "BROADCAST", "NBMA", "POINTOMULTIPOINT",
52 "VIRTUALLINK", "LOOPBACK"};
54 /* Utility functions. */
55 int str2area_id(const char *str
, struct in_addr
*area_id
, int *area_id_fmt
)
59 area_id
->s_addr
= htonl(strtoul(str
, &ep
, 10));
60 if (*ep
&& !inet_aton(str
, area_id
))
64 *ep
? OSPF_AREA_ID_FMT_DOTTEDQUAD
: OSPF_AREA_ID_FMT_DECIMAL
;
69 static void area_id2str(char *buf
, int length
, struct in_addr
*area_id
,
72 if (area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
73 inet_ntop(AF_INET
, area_id
, buf
, length
);
75 snprintf(buf
, length
, "%lu",
76 (unsigned long)ntohl(area_id
->s_addr
));
79 static int str2metric(const char *str
, int *metric
)
85 *metric
= strtol(str
, NULL
, 10);
86 if (*metric
< 0 || *metric
> 16777214) {
87 /* vty_out (vty, "OSPF metric value is invalid\n"); */
94 static int str2metric_type(const char *str
, int *metric_type
)
100 if (strncmp(str
, "1", 1) == 0)
101 *metric_type
= EXTERNAL_METRIC_TYPE_1
;
102 else if (strncmp(str
, "2", 1) == 0)
103 *metric_type
= EXTERNAL_METRIC_TYPE_2
;
110 int ospf_oi_count(struct interface
*ifp
)
112 struct route_node
*rn
;
115 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
122 #define OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf) \
123 if (argv_find(argv, argc, "vrf", &idx_vrf)) { \
124 vrf_name = argv[idx_vrf + 1]->arg; \
125 all_vrf = strmatch(vrf_name, "all"); \
128 static int ospf_router_cmd_parse(struct vty
*vty
, struct cmd_token
*argv
[],
129 const int argc
, unsigned short *instance
,
130 const char **vrf_name
)
132 int idx_vrf
= 0, idx_inst
= 0;
135 if (argv_find(argv
, argc
, "(1-65535)", &idx_inst
)) {
136 if (ospf_instance
== 0) {
138 "%% OSPF is not running in instance mode\n");
139 return CMD_WARNING_CONFIG_FAILED
;
142 *instance
= strtoul(argv
[idx_inst
]->arg
, NULL
, 10);
145 *vrf_name
= VRF_DEFAULT_NAME
;
146 if (argv_find(argv
, argc
, "vrf", &idx_vrf
)) {
147 if (ospf_instance
!= 0) {
149 "%% VRF is not supported in instance mode\n");
150 return CMD_WARNING_CONFIG_FAILED
;
153 *vrf_name
= argv
[idx_vrf
+ 1]->arg
;
159 static void ospf_show_vrf_name(struct ospf
*ospf
, struct vty
*vty
,
160 json_object
*json
, uint8_t use_vrf
)
164 json_object_string_add(json
, "vrfName",
165 ospf_get_name(ospf
));
166 json_object_int_add(json
, "vrfId", ospf
->vrf_id
);
168 vty_out(vty
, "VRF Name: %s\n", ospf_get_name(ospf
));
172 #include "ospfd/ospf_vty_clippy.c"
174 DEFUN_NOSH (router_ospf
,
176 "router ospf [{(1-65535)|vrf NAME}]",
177 "Enable a routing process\n"
178 "Start OSPF configuration\n"
182 unsigned short instance
;
183 const char *vrf_name
;
184 bool created
= false;
188 ret
= ospf_router_cmd_parse(vty
, argv
, argc
, &instance
, &vrf_name
);
189 if (ret
!= CMD_SUCCESS
)
192 if (instance
!= ospf_instance
) {
193 VTY_PUSH_CONTEXT_NULL(OSPF_NODE
);
194 return CMD_NOT_MY_INSTANCE
;
197 ospf
= ospf_get(instance
, vrf_name
, &created
);
200 if (DFLT_OSPF_LOG_ADJACENCY_CHANGES
)
201 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
203 if (IS_DEBUG_OSPF_EVENT
)
205 "Config command 'router ospf %d' received, vrf %s id %u oi_running %u",
206 ospf
->instance
, ospf_get_name(ospf
), ospf
->vrf_id
,
209 VTY_PUSH_CONTEXT(OSPF_NODE
, ospf
);
214 DEFUN (no_router_ospf
,
216 "no router ospf [{(1-65535)|vrf NAME}]",
218 "Enable a routing process\n"
219 "Start OSPF configuration\n"
223 unsigned short instance
;
224 const char *vrf_name
;
228 ret
= ospf_router_cmd_parse(vty
, argv
, argc
, &instance
, &vrf_name
);
229 if (ret
!= CMD_SUCCESS
)
232 if (instance
!= ospf_instance
)
233 return CMD_NOT_MY_INSTANCE
;
235 ospf
= ospf_lookup(instance
, vrf_name
);
239 ret
= CMD_WARNING_CONFIG_FAILED
;
245 DEFPY (ospf_router_id
,
247 "ospf router-id A.B.C.D",
248 "OSPF specific commands\n"
249 "router-id for the OSPF process\n"
250 "OSPF router-id in IP address format\n")
252 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
254 struct listnode
*node
;
255 struct ospf_area
*area
;
257 ospf
->router_id_static
= router_id
;
259 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
260 if (area
->full_nbrs
) {
262 "For this router-id change to take effect, use \"clear ip ospf process\" command\n");
266 ospf_router_id_update(ospf
);
271 DEFUN_HIDDEN (ospf_router_id_old
,
272 ospf_router_id_old_cmd
,
274 "router-id for the OSPF process\n"
275 "OSPF router-id in IP address format\n")
277 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
279 struct listnode
*node
;
280 struct ospf_area
*area
;
281 struct in_addr router_id
;
284 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &router_id
);
286 vty_out(vty
, "Please specify Router ID by A.B.C.D\n");
287 return CMD_WARNING_CONFIG_FAILED
;
290 ospf
->router_id_static
= router_id
;
292 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
293 if (area
->full_nbrs
) {
295 "For this router-id change to take effect, use \"clear ip ospf process\" command\n");
299 ospf_router_id_update(ospf
);
304 DEFPY (no_ospf_router_id
,
305 no_ospf_router_id_cmd
,
306 "no ospf router-id [A.B.C.D]",
308 "OSPF specific commands\n"
309 "router-id for the OSPF process\n"
310 "OSPF router-id in IP address format\n")
312 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
313 struct listnode
*node
;
314 struct ospf_area
*area
;
317 if (!IPV4_ADDR_SAME(&ospf
->router_id_static
, &router_id
)) {
318 vty_out(vty
, "%% OSPF router-id doesn't match\n");
319 return CMD_WARNING_CONFIG_FAILED
;
323 ospf
->router_id_static
.s_addr
= 0;
325 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
326 if (area
->full_nbrs
) {
328 "For this router-id change to take effect, use \"clear ip ospf process\" command\n");
332 ospf_router_id_update(ospf
);
338 static void ospf_passive_interface_default_update(struct ospf
*ospf
,
342 struct ospf_interface
*oi
;
344 ospf
->passive_interface_default
= newval
;
346 /* update multicast memberships */
347 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, ln
, oi
))
348 ospf_if_set_multicast(oi
);
351 static void ospf_passive_interface_update(struct interface
*ifp
,
352 struct ospf_if_params
*params
,
353 struct in_addr addr
, uint8_t newval
)
355 struct route_node
*rn
;
357 if (OSPF_IF_PARAM_CONFIGURED(params
, passive_interface
)) {
358 if (params
->passive_interface
== newval
)
361 params
->passive_interface
= newval
;
362 UNSET_IF_PARAM(params
, passive_interface
);
363 if (params
!= IF_DEF_PARAMS(ifp
)) {
364 ospf_free_if_params(ifp
, addr
);
365 ospf_if_update_params(ifp
, addr
);
368 params
->passive_interface
= newval
;
369 SET_IF_PARAM(params
, passive_interface
);
373 * XXX We should call ospf_if_set_multicast on exactly those
374 * interfaces for which the passive property changed. It is too much
375 * work to determine this set, so we do this for every interface.
376 * This is safe and reasonable because ospf_if_set_multicast uses a
377 * record of joined groups to avoid systems calls if the desired
378 * memberships match the current memership.
381 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
382 struct ospf_interface
*oi
= rn
->info
;
385 ospf_if_set_multicast(oi
);
389 * XXX It is not clear what state transitions the interface needs to
390 * undergo when going from active to passive and vice versa. Fixing
391 * this will require precise identification of interfaces having such a
396 DEFUN (ospf_passive_interface_default
,
397 ospf_passive_interface_default_cmd
,
398 "passive-interface default",
399 "Suppress routing updates on an interface\n"
400 "Suppress routing updates on interfaces by default\n")
402 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
404 ospf_passive_interface_default_update(ospf
, OSPF_IF_PASSIVE
);
409 DEFUN_HIDDEN (ospf_passive_interface_addr
,
410 ospf_passive_interface_addr_cmd
,
411 "passive-interface IFNAME [A.B.C.D]",
412 "Suppress routing updates on an interface\n"
416 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
418 struct interface
*ifp
= NULL
;
419 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
420 struct ospf_if_params
*params
;
424 "This command is deprecated, because it is not VRF-aware.\n");
426 "Please, use \"ip ospf passive\" on an interface instead.\n");
428 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
429 ifp
= if_get_by_name(argv
[1]->arg
, ospf
->vrf_id
, ospf
->name
);
432 vty_out(vty
, "interface %s not found.\n", (char *)argv
[1]->arg
);
433 return CMD_WARNING_CONFIG_FAILED
;
437 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
440 "Please specify interface address by A.B.C.D\n");
441 return CMD_WARNING_CONFIG_FAILED
;
444 params
= ospf_get_if_params(ifp
, addr
);
445 ospf_if_update_params(ifp
, addr
);
447 params
= IF_DEF_PARAMS(ifp
);
450 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_PASSIVE
);
455 DEFUN (no_ospf_passive_interface_default
,
456 no_ospf_passive_interface_default_cmd
,
457 "no passive-interface default",
459 "Allow routing updates on an interface\n"
460 "Allow routing updates on interfaces by default\n")
462 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
464 ospf_passive_interface_default_update(ospf
, OSPF_IF_ACTIVE
);
469 DEFUN_HIDDEN (no_ospf_passive_interface
,
470 no_ospf_passive_interface_addr_cmd
,
471 "no passive-interface IFNAME [A.B.C.D]",
473 "Allow routing updates on an interface\n"
477 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
479 struct interface
*ifp
= NULL
;
480 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
481 struct ospf_if_params
*params
;
485 "This command is deprecated, because it is not VRF-aware.\n");
487 "Please, use \"no ip ospf passive\" on an interface instead.\n");
489 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
490 ifp
= if_get_by_name(argv
[2]->arg
, ospf
->vrf_id
, ospf
->name
);
493 vty_out(vty
, "interface %s not found.\n", (char *)argv
[2]->arg
);
494 return CMD_WARNING_CONFIG_FAILED
;
498 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
501 "Please specify interface address by A.B.C.D\n");
502 return CMD_WARNING_CONFIG_FAILED
;
504 params
= ospf_lookup_if_params(ifp
, addr
);
508 params
= IF_DEF_PARAMS(ifp
);
511 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_ACTIVE
);
517 DEFUN (ospf_network_area
,
518 ospf_network_area_cmd
,
519 "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
520 "Enable routing on an IP network\n"
521 "OSPF network prefix\n"
522 "Set the OSPF area ID\n"
523 "OSPF area ID in IP address format\n"
524 "OSPF area ID as a decimal value\n")
526 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
527 int idx_ipv4_prefixlen
= 1;
528 int idx_ipv4_number
= 3;
529 struct prefix_ipv4 p
;
530 struct in_addr area_id
;
534 if (ospf
->instance
) {
536 "The network command is not supported in multi-instance ospf\n");
537 return CMD_WARNING_CONFIG_FAILED
;
540 count
= ospf_count_area_params(ospf
);
543 "Please remove all ip ospf area x.x.x.x commands first.\n");
544 if (IS_DEBUG_OSPF_EVENT
)
546 "%s ospf vrf %s num of %u ip ospf area x config",
547 __func__
, ospf_get_name(ospf
), count
);
548 return CMD_WARNING_CONFIG_FAILED
;
551 /* Get network prefix and Area ID. */
552 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
553 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
555 ret
= ospf_network_set(ospf
, &p
, area_id
, format
);
557 vty_out(vty
, "There is already same network statement.\n");
558 return CMD_WARNING_CONFIG_FAILED
;
564 DEFUN (no_ospf_network_area
,
565 no_ospf_network_area_cmd
,
566 "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
568 "Enable routing on an IP network\n"
569 "OSPF network prefix\n"
570 "Set the OSPF area ID\n"
571 "OSPF area ID in IP address format\n"
572 "OSPF area ID as a decimal value\n")
574 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
575 int idx_ipv4_prefixlen
= 2;
576 int idx_ipv4_number
= 4;
577 struct prefix_ipv4 p
;
578 struct in_addr area_id
;
581 if (ospf
->instance
) {
583 "The network command is not supported in multi-instance ospf\n");
584 return CMD_WARNING_CONFIG_FAILED
;
587 /* Get network prefix and Area ID. */
588 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
589 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
591 ret
= ospf_network_unset(ospf
, &p
, area_id
);
594 "Can't find specified network area configuration.\n");
595 return CMD_WARNING_CONFIG_FAILED
;
601 DEFUN (ospf_area_range
,
603 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]",
604 "OSPF area parameters\n"
605 "OSPF area ID in IP address format\n"
606 "OSPF area ID as a decimal value\n"
607 "Summarize routes matching address/mask (border routers only)\n"
608 "Area range prefix\n"
609 "Advertise this range (default)\n"
610 "User specified metric for this range\n"
611 "Advertised metric for this range\n")
613 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
614 int idx_ipv4_number
= 1;
615 int idx_ipv4_prefixlen
= 3;
617 struct prefix_ipv4 p
;
618 struct in_addr area_id
;
622 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
623 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
625 ospf_area_range_set(ospf
, area_id
, &p
, OSPF_AREA_RANGE_ADVERTISE
);
626 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
629 cost
= strtoul(argv
[idx_cost
]->arg
, NULL
, 10);
630 ospf_area_range_cost_set(ospf
, area_id
, &p
, cost
);
636 DEFUN (ospf_area_range_cost
,
637 ospf_area_range_cost_cmd
,
638 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M {cost (0-16777215)|substitute A.B.C.D/M}",
639 "OSPF area parameters\n"
640 "OSPF area ID in IP address format\n"
641 "OSPF area ID as a decimal value\n"
642 "Summarize routes matching address/mask (border routers only)\n"
643 "Area range prefix\n"
644 "User specified metric for this range\n"
645 "Advertised metric for this range\n"
646 "Announce area range as another prefix\n"
647 "Network prefix to be announced instead of range\n")
649 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
650 int idx_ipv4_number
= 1;
651 int idx_ipv4_prefixlen
= 3;
653 struct prefix_ipv4 p
, s
;
654 struct in_addr area_id
;
658 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
659 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
661 ospf_area_range_set(ospf
, area_id
, &p
, OSPF_AREA_RANGE_ADVERTISE
);
662 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
665 if (argv_find(argv
, argc
, "cost", &idx
)) {
666 cost
= strtoul(argv
[idx
+ 1]->arg
, NULL
, 10);
667 ospf_area_range_cost_set(ospf
, area_id
, &p
, cost
);
671 if (argv_find(argv
, argc
, "substitute", &idx
)) {
672 str2prefix_ipv4(argv
[idx
+ 1]->arg
, &s
);
673 ospf_area_range_substitute_set(ospf
, area_id
, &p
, &s
);
679 DEFUN (ospf_area_range_not_advertise
,
680 ospf_area_range_not_advertise_cmd
,
681 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise",
682 "OSPF area parameters\n"
683 "OSPF area ID in IP address format\n"
684 "OSPF area ID as a decimal value\n"
685 "Summarize routes matching address/mask (border routers only)\n"
686 "Area range prefix\n"
687 "DoNotAdvertise this range\n")
689 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
690 int idx_ipv4_number
= 1;
691 int idx_ipv4_prefixlen
= 3;
692 struct prefix_ipv4 p
;
693 struct in_addr area_id
;
696 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
697 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
699 ospf_area_range_set(ospf
, area_id
, &p
, 0);
700 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
702 ospf_area_range_substitute_unset(ospf
, area_id
, &p
);
707 DEFUN (no_ospf_area_range
,
708 no_ospf_area_range_cmd
,
709 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]",
711 "OSPF area parameters\n"
712 "OSPF area ID in IP address format\n"
713 "OSPF area ID as a decimal value\n"
714 "Summarize routes matching address/mask (border routers only)\n"
715 "Area range prefix\n"
716 "User specified metric for this range\n"
717 "Advertised metric for this range\n"
718 "Advertise this range (default)\n"
719 "User specified metric for this range\n"
720 "Advertised metric for this range\n"
721 "DoNotAdvertise this range\n")
723 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
724 int idx_ipv4_number
= 2;
725 int idx_ipv4_prefixlen
= 4;
726 struct prefix_ipv4 p
;
727 struct in_addr area_id
;
730 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
731 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
733 ospf_area_range_unset(ospf
, area_id
, &p
);
738 DEFUN (no_ospf_area_range_substitute
,
739 no_ospf_area_range_substitute_cmd
,
740 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
742 "OSPF area parameters\n"
743 "OSPF area ID in IP address format\n"
744 "OSPF area ID as a decimal value\n"
745 "Summarize routes matching address/mask (border routers only)\n"
746 "Area range prefix\n"
747 "Announce area range as another prefix\n"
748 "Network prefix to be announced instead of range\n")
750 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
751 int idx_ipv4_number
= 2;
752 int idx_ipv4_prefixlen
= 4;
753 int idx_ipv4_prefixlen_2
= 6;
754 struct prefix_ipv4 p
, s
;
755 struct in_addr area_id
;
758 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
759 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
760 str2prefix_ipv4(argv
[idx_ipv4_prefixlen_2
]->arg
, &s
);
762 ospf_area_range_substitute_unset(ospf
, area_id
, &p
);
768 /* Command Handler Logic in VLink stuff is delicate!!
770 ALTER AT YOUR OWN RISK!!!!
772 Various dummy values are used to represent 'NoChange' state for
773 VLink configuration NOT being changed by a VLink command, and
774 special syntax is used within the command strings so that the
775 typed in command verbs can be seen in the configuration command
776 bacckend handler. This is to drastically reduce the verbeage
777 required to coe up with a reasonably compatible Cisco VLink command
779 - Matthew Grant <grantma@anathoth.gen.nz>
780 Wed, 21 Feb 2001 15:13:52 +1300
783 /* Configuration data for virtual links
785 struct ospf_vl_config_data
{
786 struct vty
*vty
; /* vty stuff */
787 struct in_addr area_id
; /* area ID from command line */
788 int area_id_fmt
; /* command line area ID format */
789 struct in_addr vl_peer
; /* command line vl_peer */
790 int auth_type
; /* Authehntication type, if given */
791 char *auth_key
; /* simple password if present */
792 int crypto_key_id
; /* Cryptographic key ID */
793 char *md5_key
; /* MD5 authentication key */
794 int hello_interval
; /* Obvious what these are... */
795 int retransmit_interval
;
800 static void ospf_vl_config_data_init(struct ospf_vl_config_data
*vl_config
,
803 memset(vl_config
, 0, sizeof(struct ospf_vl_config_data
));
804 vl_config
->auth_type
= OSPF_AUTH_CMD_NOTSEEN
;
805 vl_config
->vty
= vty
;
808 static struct ospf_vl_data
*
809 ospf_find_vl_data(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
811 struct ospf_area
*area
;
812 struct ospf_vl_data
*vl_data
;
814 struct in_addr area_id
;
816 vty
= vl_config
->vty
;
817 area_id
= vl_config
->area_id
;
819 if (area_id
.s_addr
== OSPF_AREA_BACKBONE
) {
821 "Configuring VLs over the backbone is not allowed\n");
824 area
= ospf_area_get(ospf
, area_id
);
825 ospf_area_display_format_set(ospf
, area
, vl_config
->area_id_fmt
);
827 if (area
->external_routing
!= OSPF_AREA_DEFAULT
) {
828 if (vl_config
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
829 vty_out(vty
, "Area %pI4 is %s\n", &area_id
,
830 area
->external_routing
== OSPF_AREA_NSSA
834 vty_out(vty
, "Area %ld is %s\n",
835 (unsigned long)ntohl(area_id
.s_addr
),
836 area
->external_routing
== OSPF_AREA_NSSA
842 if ((vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
->vl_peer
))
844 vl_data
= ospf_vl_data_new(area
, vl_config
->vl_peer
);
845 if (vl_data
->vl_oi
== NULL
) {
846 vl_data
->vl_oi
= ospf_vl_new(ospf
, vl_data
);
847 ospf_vl_add(ospf
, vl_data
);
848 ospf_spf_calculate_schedule(ospf
,
849 SPF_FLAG_CONFIG_CHANGE
);
856 static int ospf_vl_set_security(struct ospf_vl_data
*vl_data
,
857 struct ospf_vl_config_data
*vl_config
)
859 struct crypt_key
*ck
;
861 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
863 vty
= vl_config
->vty
;
865 if (vl_config
->auth_type
!= OSPF_AUTH_CMD_NOTSEEN
) {
866 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), auth_type
);
867 IF_DEF_PARAMS(ifp
)->auth_type
= vl_config
->auth_type
;
870 if (vl_config
->auth_key
) {
871 memset(IF_DEF_PARAMS(ifp
)->auth_simple
, 0,
872 OSPF_AUTH_SIMPLE_SIZE
+ 1);
873 strlcpy((char *)IF_DEF_PARAMS(ifp
)->auth_simple
,
875 sizeof(IF_DEF_PARAMS(ifp
)->auth_simple
));
876 } else if (vl_config
->md5_key
) {
877 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
878 vl_config
->crypto_key_id
)
880 vty_out(vty
, "OSPF: Key %d already exists\n",
881 vl_config
->crypto_key_id
);
884 ck
= ospf_crypt_key_new();
885 ck
->key_id
= vl_config
->crypto_key_id
;
886 memset(ck
->auth_key
, 0, OSPF_AUTH_MD5_SIZE
+ 1);
887 strlcpy((char *)ck
->auth_key
, vl_config
->md5_key
,
888 sizeof(ck
->auth_key
));
890 ospf_crypt_key_add(IF_DEF_PARAMS(ifp
)->auth_crypt
, ck
);
891 } else if (vl_config
->crypto_key_id
!= 0) {
894 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
895 vl_config
->crypto_key_id
)
897 vty_out(vty
, "OSPF: Key %d does not exist\n",
898 vl_config
->crypto_key_id
);
899 return CMD_WARNING_CONFIG_FAILED
;
902 ospf_crypt_key_delete(IF_DEF_PARAMS(ifp
)->auth_crypt
,
903 vl_config
->crypto_key_id
);
909 static int ospf_vl_set_timers(struct ospf_vl_data
*vl_data
,
910 struct ospf_vl_config_data
*vl_config
)
912 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
913 /* Virtual Link data initialised to defaults, so only set
915 if (vl_config
->hello_interval
) {
916 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_hello
);
917 IF_DEF_PARAMS(ifp
)->v_hello
= vl_config
->hello_interval
;
920 if (vl_config
->dead_interval
) {
921 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_wait
);
922 IF_DEF_PARAMS(ifp
)->v_wait
= vl_config
->dead_interval
;
925 if (vl_config
->retransmit_interval
) {
926 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), retransmit_interval
);
927 IF_DEF_PARAMS(ifp
)->retransmit_interval
=
928 vl_config
->retransmit_interval
;
931 if (vl_config
->transmit_delay
) {
932 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), transmit_delay
);
933 IF_DEF_PARAMS(ifp
)->transmit_delay
= vl_config
->transmit_delay
;
940 /* The business end of all of the above */
941 static int ospf_vl_set(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
943 struct ospf_vl_data
*vl_data
;
946 vl_data
= ospf_find_vl_data(ospf
, vl_config
);
948 return CMD_WARNING_CONFIG_FAILED
;
950 /* Process this one first as it can have a fatal result, which can
951 only logically occur if the virtual link exists already
952 Thus a command error does not result in a change to the
953 running configuration such as unexpectedly altered timer
955 ret
= ospf_vl_set_security(vl_data
, vl_config
);
956 if (ret
!= CMD_SUCCESS
)
959 /* Set any time based parameters, these area already range checked */
961 ret
= ospf_vl_set_timers(vl_data
, vl_config
);
962 if (ret
!= CMD_SUCCESS
)
968 /* This stuff exists to make specifying all the alias commands A LOT simpler
970 #define VLINK_HELPSTR_IPADDR \
971 "OSPF area parameters\n" \
972 "OSPF area ID in IP address format\n" \
973 "OSPF area ID as a decimal value\n" \
974 "Configure a virtual link\n" \
975 "Router ID of the remote ABR\n"
977 #define VLINK_HELPSTR_AUTHTYPE_SIMPLE \
978 "Enable authentication on this virtual link\n" \
981 #define VLINK_HELPSTR_AUTHTYPE_ALL \
982 VLINK_HELPSTR_AUTHTYPE_SIMPLE \
983 "Use null authentication\n" \
984 "Use message-digest authentication\n"
986 #define VLINK_HELPSTR_TIME_PARAM \
987 "Time between HELLO packets\n" \
989 "Time between retransmitting lost link state advertisements\n" \
991 "Link state transmit delay\n" \
993 "Interval time after which a neighbor is declared down\n" \
996 #define VLINK_HELPSTR_AUTH_SIMPLE \
997 "Authentication password (key)\n" \
998 "The OSPF password (key)\n"
1000 #define VLINK_HELPSTR_AUTH_MD5 \
1001 "Message digest authentication password (key)\n" \
1003 "Use MD5 algorithm\n" \
1004 "The OSPF password (key)\n"
1006 DEFUN (ospf_area_vlink
,
1007 ospf_area_vlink_cmd
,
1008 "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>]",
1009 VLINK_HELPSTR_IPADDR
1010 "Enable authentication on this virtual link\n"
1011 "Use message-digest authentication\n"
1012 "Use null authentication\n"
1013 VLINK_HELPSTR_AUTH_MD5
1014 VLINK_HELPSTR_AUTH_SIMPLE
)
1016 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1017 int idx_ipv4_number
= 1;
1019 struct ospf_vl_config_data vl_config
;
1020 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1021 char md5_key
[OSPF_AUTH_MD5_SIZE
+ 1];
1025 ospf_vl_config_data_init(&vl_config
, vty
);
1027 /* Read off first 2 parameters and check them */
1028 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1029 &vl_config
.area_id_fmt
);
1031 vty_out(vty
, "OSPF area ID is invalid\n");
1032 return CMD_WARNING_CONFIG_FAILED
;
1035 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1037 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1038 return CMD_WARNING_CONFIG_FAILED
;
1042 /* Thats all folks! - BUGS B. strikes again!!!*/
1044 return ospf_vl_set(ospf
, &vl_config
);
1047 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1048 /* authentication - this option can only occur
1049 at start of command line */
1050 vl_config
.auth_type
= OSPF_AUTH_SIMPLE
;
1053 if (argv_find(argv
, argc
, "message-digest", &idx
)) {
1054 /* authentication message-digest */
1055 vl_config
.auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
1056 } else if (argv_find(argv
, argc
, "null", &idx
)) {
1057 /* "authentication null" */
1058 vl_config
.auth_type
= OSPF_AUTH_NULL
;
1061 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1062 vl_config
.md5_key
= NULL
;
1063 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1064 if (vl_config
.crypto_key_id
< 0)
1065 return CMD_WARNING_CONFIG_FAILED
;
1067 strlcpy(md5_key
, argv
[idx
+ 3]->arg
, sizeof(md5_key
));
1068 vl_config
.md5_key
= md5_key
;
1071 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1072 strlcpy(auth_key
, argv
[idx
+ 1]->arg
, sizeof(auth_key
));
1073 vl_config
.auth_key
= auth_key
;
1076 /* Action configuration */
1078 return ospf_vl_set(ospf
, &vl_config
);
1081 DEFUN (no_ospf_area_vlink
,
1082 no_ospf_area_vlink_cmd
,
1083 "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>]",
1085 VLINK_HELPSTR_IPADDR
1086 "Enable authentication on this virtual link\n"
1087 "Use message-digest authentication\n"
1088 "Use null authentication\n"
1089 VLINK_HELPSTR_AUTH_MD5
1090 VLINK_HELPSTR_AUTH_SIMPLE
)
1092 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1093 int idx_ipv4_number
= 2;
1095 struct ospf_area
*area
;
1096 struct ospf_vl_config_data vl_config
;
1097 struct ospf_vl_data
*vl_data
= NULL
;
1098 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1102 ospf_vl_config_data_init(&vl_config
, vty
);
1104 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1107 vty_out(vty
, "OSPF area ID is invalid\n");
1108 return CMD_WARNING_CONFIG_FAILED
;
1111 area
= ospf_area_lookup_by_area_id(ospf
, vl_config
.area_id
);
1113 vty_out(vty
, "Area does not exist\n");
1114 return CMD_WARNING_CONFIG_FAILED
;
1117 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1119 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1120 return CMD_WARNING_CONFIG_FAILED
;
1123 vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
.vl_peer
);
1125 vty_out(vty
, "Virtual link does not exist\n");
1126 return CMD_WARNING_CONFIG_FAILED
;
1130 /* Basic VLink no command */
1131 /* Thats all folks! - BUGS B. strikes again!!!*/
1132 ospf_vl_delete(ospf
, vl_data
);
1133 ospf_area_check_free(ospf
, vl_config
.area_id
);
1137 /* If we are down here, we are reseting parameters */
1138 /* Deal with other parameters */
1140 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1141 /* authentication - this option can only occur
1142 at start of command line */
1143 vl_config
.auth_type
= OSPF_AUTH_NOTSET
;
1146 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1147 vl_config
.md5_key
= NULL
;
1148 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1149 if (vl_config
.crypto_key_id
< 0)
1150 return CMD_WARNING_CONFIG_FAILED
;
1153 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1154 /* Reset authentication-key to 0 */
1155 memset(auth_key
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
1156 vl_config
.auth_key
= auth_key
;
1159 /* Action configuration */
1161 return ospf_vl_set(ospf
, &vl_config
);
1164 DEFUN (ospf_area_vlink_intervals
,
1165 ospf_area_vlink_intervals_cmd
,
1166 "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)}",
1167 VLINK_HELPSTR_IPADDR
1168 VLINK_HELPSTR_TIME_PARAM
)
1170 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1171 struct ospf_vl_config_data vl_config
;
1174 ospf_vl_config_data_init(&vl_config
, vty
);
1176 char *area_id
= argv
[1]->arg
;
1177 char *router_id
= argv
[3]->arg
;
1179 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1181 vty_out(vty
, "OSPF area ID is invalid\n");
1182 return CMD_WARNING_CONFIG_FAILED
;
1185 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1187 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1188 return CMD_WARNING_CONFIG_FAILED
;
1191 for (int idx
= 4; idx
< argc
; idx
++) {
1192 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1193 vl_config
.hello_interval
=
1194 strtol(argv
[++idx
]->arg
, NULL
, 10);
1195 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1196 vl_config
.retransmit_interval
=
1197 strtol(argv
[++idx
]->arg
, NULL
, 10);
1198 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1199 vl_config
.transmit_delay
=
1200 strtol(argv
[++idx
]->arg
, NULL
, 10);
1201 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1202 vl_config
.dead_interval
=
1203 strtol(argv
[++idx
]->arg
, NULL
, 10);
1206 /* Action configuration */
1207 return ospf_vl_set(ospf
, &vl_config
);
1210 DEFUN (no_ospf_area_vlink_intervals
,
1211 no_ospf_area_vlink_intervals_cmd
,
1212 "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)}",
1214 VLINK_HELPSTR_IPADDR
1215 VLINK_HELPSTR_TIME_PARAM
)
1217 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1218 struct ospf_vl_config_data vl_config
;
1221 ospf_vl_config_data_init(&vl_config
, vty
);
1223 char *area_id
= argv
[2]->arg
;
1224 char *router_id
= argv
[4]->arg
;
1226 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1228 vty_out(vty
, "OSPF area ID is invalid\n");
1229 return CMD_WARNING_CONFIG_FAILED
;
1232 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1234 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1235 return CMD_WARNING_CONFIG_FAILED
;
1238 for (int idx
= 5; idx
< argc
; idx
++) {
1239 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1240 vl_config
.hello_interval
= OSPF_HELLO_INTERVAL_DEFAULT
;
1241 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1242 vl_config
.retransmit_interval
=
1243 OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
1244 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1245 vl_config
.transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
1246 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1247 vl_config
.dead_interval
=
1248 OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
1251 /* Action configuration */
1252 return ospf_vl_set(ospf
, &vl_config
);
1255 DEFUN (ospf_area_shortcut
,
1256 ospf_area_shortcut_cmd
,
1257 "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>",
1258 "OSPF area parameters\n"
1259 "OSPF area ID in IP address format\n"
1260 "OSPF area ID as a decimal value\n"
1261 "Configure the area's shortcutting mode\n"
1262 "Set default shortcutting behavior\n"
1263 "Enable shortcutting through the area\n"
1264 "Disable shortcutting through the area\n")
1266 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1267 int idx_ipv4_number
= 1;
1268 int idx_enable_disable
= 3;
1269 struct ospf_area
*area
;
1270 struct in_addr area_id
;
1274 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1275 argv
[idx_ipv4_number
]->arg
);
1277 area
= ospf_area_get(ospf
, area_id
);
1278 ospf_area_display_format_set(ospf
, area
, format
);
1280 if (strncmp(argv
[idx_enable_disable
]->arg
, "de", 2) == 0)
1281 mode
= OSPF_SHORTCUT_DEFAULT
;
1282 else if (strncmp(argv
[idx_enable_disable
]->arg
, "di", 2) == 0)
1283 mode
= OSPF_SHORTCUT_DISABLE
;
1284 else if (strncmp(argv
[idx_enable_disable
]->arg
, "e", 1) == 0)
1285 mode
= OSPF_SHORTCUT_ENABLE
;
1287 return CMD_WARNING_CONFIG_FAILED
;
1289 ospf_area_shortcut_set(ospf
, area
, mode
);
1291 if (ospf
->abr_type
!= OSPF_ABR_SHORTCUT
)
1293 "Shortcut area setting will take effect only when the router is configured as Shortcut ABR\n");
1298 DEFUN (no_ospf_area_shortcut
,
1299 no_ospf_area_shortcut_cmd
,
1300 "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>",
1302 "OSPF area parameters\n"
1303 "OSPF area ID in IP address format\n"
1304 "OSPF area ID as a decimal value\n"
1305 "Deconfigure the area's shortcutting mode\n"
1306 "Deconfigure enabled shortcutting through the area\n"
1307 "Deconfigure disabled shortcutting through the area\n")
1309 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1310 int idx_ipv4_number
= 2;
1311 struct ospf_area
*area
;
1312 struct in_addr area_id
;
1315 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1316 argv
[idx_ipv4_number
]->arg
);
1318 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1322 ospf_area_shortcut_unset(ospf
, area
);
1328 DEFUN (ospf_area_stub
,
1330 "area <A.B.C.D|(0-4294967295)> stub",
1331 "OSPF area parameters\n"
1332 "OSPF area ID in IP address format\n"
1333 "OSPF area ID as a decimal value\n"
1334 "Configure OSPF area as stub\n")
1336 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1337 int idx_ipv4_number
= 1;
1338 struct in_addr area_id
;
1341 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1342 argv
[idx_ipv4_number
]->arg
);
1344 ret
= ospf_area_stub_set(ospf
, area_id
);
1345 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1349 "First deconfigure all virtual link through this area\n");
1350 return CMD_WARNING_CONFIG_FAILED
;
1353 /* Flush the external LSAs from the specified area */
1354 ospf_flush_lsa_from_area(ospf
, area_id
, OSPF_AS_EXTERNAL_LSA
);
1355 ospf_area_no_summary_unset(ospf
, area_id
);
1360 DEFUN (ospf_area_stub_no_summary
,
1361 ospf_area_stub_no_summary_cmd
,
1362 "area <A.B.C.D|(0-4294967295)> stub no-summary",
1363 "OSPF stub parameters\n"
1364 "OSPF area ID in IP address format\n"
1365 "OSPF area ID as a decimal value\n"
1366 "Configure OSPF area as stub\n"
1367 "Do not inject inter-area routes into stub\n")
1369 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1370 int idx_ipv4_number
= 1;
1371 struct in_addr area_id
;
1374 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1375 argv
[idx_ipv4_number
]->arg
);
1377 ret
= ospf_area_stub_set(ospf
, area_id
);
1378 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1382 "%% Area cannot be stub as it contains a virtual link\n");
1383 return CMD_WARNING_CONFIG_FAILED
;
1386 ospf_area_no_summary_set(ospf
, area_id
);
1391 DEFUN (no_ospf_area_stub
,
1392 no_ospf_area_stub_cmd
,
1393 "no area <A.B.C.D|(0-4294967295)> stub",
1395 "OSPF area parameters\n"
1396 "OSPF area ID in IP address format\n"
1397 "OSPF area ID as a decimal value\n"
1398 "Configure OSPF area as stub\n")
1400 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1401 int idx_ipv4_number
= 2;
1402 struct in_addr area_id
;
1405 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1406 argv
[idx_ipv4_number
]->arg
);
1408 ospf_area_stub_unset(ospf
, area_id
);
1409 ospf_area_no_summary_unset(ospf
, area_id
);
1414 DEFUN (no_ospf_area_stub_no_summary
,
1415 no_ospf_area_stub_no_summary_cmd
,
1416 "no area <A.B.C.D|(0-4294967295)> stub no-summary",
1418 "OSPF area parameters\n"
1419 "OSPF area ID in IP address format\n"
1420 "OSPF area ID as a decimal value\n"
1421 "Configure OSPF area as stub\n"
1422 "Do not inject inter-area routes into area\n")
1424 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1425 int idx_ipv4_number
= 2;
1426 struct in_addr area_id
;
1429 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1430 argv
[idx_ipv4_number
]->arg
);
1431 ospf_area_no_summary_unset(ospf
, area_id
);
1436 static int ospf_area_nssa_cmd_handler(struct vty
*vty
, int argc
,
1437 struct cmd_token
**argv
, int cfg_nosum
,
1440 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1441 struct in_addr area_id
;
1444 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
, argv
[1]->arg
);
1446 ret
= ospf_area_nssa_set(ospf
, area_id
);
1447 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1451 "%% Area cannot be nssa as it contains a virtual link\n");
1452 return CMD_WARNING_CONFIG_FAILED
;
1456 if (strncmp(argv
[3]->text
, "translate-c", 11) == 0)
1457 ospf_area_nssa_translator_role_set(
1458 ospf
, area_id
, OSPF_NSSA_ROLE_CANDIDATE
);
1459 else if (strncmp(argv
[3]->text
, "translate-n", 11) == 0)
1460 ospf_area_nssa_translator_role_set(
1461 ospf
, area_id
, OSPF_NSSA_ROLE_NEVER
);
1462 else if (strncmp(argv
[3]->text
, "translate-a", 11) == 0)
1463 ospf_area_nssa_translator_role_set(
1464 ospf
, area_id
, OSPF_NSSA_ROLE_ALWAYS
);
1466 ospf_area_nssa_translator_role_set(ospf
, area_id
,
1467 OSPF_NSSA_ROLE_CANDIDATE
);
1472 ospf_area_no_summary_set(ospf
, area_id
);
1474 ospf_area_no_summary_unset(ospf
, area_id
);
1477 /* Flush the external LSA for the specified area */
1478 ospf_flush_lsa_from_area(ospf
, area_id
, OSPF_AS_EXTERNAL_LSA
);
1479 ospf_schedule_abr_task(ospf
);
1480 ospf_schedule_asbr_nssa_redist_update(ospf
);
1486 DEFUN (ospf_area_nssa_translate
,
1487 ospf_area_nssa_translate_cmd
,
1488 "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always>",
1489 "OSPF area parameters\n"
1490 "OSPF area ID in IP address format\n"
1491 "OSPF area ID as a decimal value\n"
1492 "Configure OSPF area as nssa\n"
1493 "Configure NSSA-ABR for translate election (default)\n"
1494 "Configure NSSA-ABR to never translate\n"
1495 "Configure NSSA-ABR to always translate\n")
1497 return ospf_area_nssa_cmd_handler(vty
, argc
, argv
, 0, 0);
1500 DEFUN (ospf_area_nssa
,
1502 "area <A.B.C.D|(0-4294967295)> nssa",
1503 "OSPF area parameters\n"
1504 "OSPF area ID in IP address format\n"
1505 "OSPF area ID as a decimal value\n"
1506 "Configure OSPF area as nssa\n")
1508 return ospf_area_nssa_cmd_handler(vty
, argc
, argv
, 0, 0);
1511 DEFUN(ospf_area_nssa_suppress_fa
, ospf_area_nssa_suppress_fa_cmd
,
1512 "area <A.B.C.D|(0-4294967295)> nssa suppress-fa",
1513 "OSPF area parameters\n"
1514 "OSPF area ID in IP address format\n"
1515 "OSPF area ID as a decimal value\n"
1516 "Configure OSPF area as nssa\n"
1517 "Suppress forwarding address\n")
1519 int idx_ipv4_number
= 1;
1520 struct in_addr area_id
;
1523 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1524 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1525 argv
[idx_ipv4_number
]->arg
);
1527 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1529 ospf_area_nssa_suppress_fa_set(ospf
, area_id
);
1531 ospf_schedule_abr_task(ospf
);
1536 DEFUN(no_ospf_area_nssa_suppress_fa
, no_ospf_area_nssa_suppress_fa_cmd
,
1537 "no area <A.B.C.D|(0-4294967295)> nssa suppress-fa",
1539 "OSPF area parameters\n"
1540 "OSPF area ID in IP address format\n"
1541 "OSPF area ID as a decimal value\n"
1542 "Configure OSPF area as nssa\n"
1543 "Suppress forwarding address\n")
1545 int idx_ipv4_number
= 2;
1546 struct in_addr area_id
;
1549 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1551 VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id
, format
,
1552 argv
[idx_ipv4_number
]->arg
);
1554 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1556 ospf_area_nssa_suppress_fa_unset(ospf
, area_id
);
1558 ospf_schedule_abr_task(ospf
);
1563 DEFUN (ospf_area_nssa_no_summary
,
1564 ospf_area_nssa_no_summary_cmd
,
1565 "area <A.B.C.D|(0-4294967295)> nssa no-summary",
1566 "OSPF area parameters\n"
1567 "OSPF area ID in IP address format\n"
1568 "OSPF area ID as a decimal value\n"
1569 "Configure OSPF area as nssa\n"
1570 "Do not inject inter-area routes into nssa\n")
1572 int idx_ipv4_number
= 1;
1573 struct in_addr area_id
;
1576 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1577 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1578 argv
[idx_ipv4_number
]->arg
);
1580 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1582 ospf_area_nssa_no_summary_set(ospf
, area_id
);
1584 ospf_schedule_abr_task(ospf
);
1589 DEFUN (no_ospf_area_nssa_no_summary
,
1590 no_ospf_area_nssa_no_summary_cmd
,
1591 "no area <A.B.C.D|(0-4294967295)> nssa no-summary",
1593 "OSPF area parameters\n"
1594 "OSPF area ID in IP address format\n"
1595 "OSPF area ID as a decimal value\n"
1596 "Configure OSPF area as nssa\n"
1597 "Do not inject inter-area routes into nssa\n")
1599 int idx_ipv4_number
= 2;
1600 struct in_addr area_id
;
1603 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1605 VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id
, format
,
1606 argv
[idx_ipv4_number
]->arg
);
1608 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1610 ospf_area_no_summary_unset(ospf
, area_id
);
1612 ospf_schedule_abr_task(ospf
);
1617 DEFUN (no_ospf_area_nssa
,
1618 no_ospf_area_nssa_cmd
,
1619 "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always>]",
1621 "OSPF area parameters\n"
1622 "OSPF area ID in IP address format\n"
1623 "OSPF area ID as a decimal value\n"
1624 "Configure OSPF area as nssa\n"
1625 "Configure NSSA-ABR for translate election (default)\n"
1626 "Configure NSSA-ABR to never translate\n"
1627 "Configure NSSA-ABR to always translate\n")
1629 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1630 int idx_ipv4_number
= 2;
1631 struct in_addr area_id
;
1634 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1635 argv
[idx_ipv4_number
]->arg
);
1637 /* Flush the NSSA LSA for the specified area */
1638 ospf_flush_lsa_from_area(ospf
, area_id
, OSPF_AS_NSSA_LSA
);
1639 ospf_area_nssa_unset(ospf
, area_id
, argc
);
1641 ospf_schedule_abr_task(ospf
);
1647 DEFUN (ospf_area_default_cost
,
1648 ospf_area_default_cost_cmd
,
1649 "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1650 "OSPF area parameters\n"
1651 "OSPF area ID in IP address format\n"
1652 "OSPF area ID as a decimal value\n"
1653 "Set the summary-default cost of a NSSA or stub area\n"
1654 "Stub's advertised default summary cost\n")
1656 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1657 int idx_ipv4_number
= 1;
1659 struct ospf_area
*area
;
1660 struct in_addr area_id
;
1663 struct prefix_ipv4 p
;
1665 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1666 argv
[idx_ipv4_number
]->arg
);
1667 cost
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1669 area
= ospf_area_get(ospf
, area_id
);
1670 ospf_area_display_format_set(ospf
, area
, format
);
1672 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1673 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1674 return CMD_WARNING_CONFIG_FAILED
;
1677 area
->default_cost
= cost
;
1680 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1682 if (IS_DEBUG_OSPF_EVENT
)
1684 "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4",
1686 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1691 DEFUN (no_ospf_area_default_cost
,
1692 no_ospf_area_default_cost_cmd
,
1693 "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1695 "OSPF area parameters\n"
1696 "OSPF area ID in IP address format\n"
1697 "OSPF area ID as a decimal value\n"
1698 "Set the summary-default cost of a NSSA or stub area\n"
1699 "Stub's advertised default summary cost\n")
1701 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1702 int idx_ipv4_number
= 2;
1703 struct ospf_area
*area
;
1704 struct in_addr area_id
;
1706 struct prefix_ipv4 p
;
1708 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1709 argv
[idx_ipv4_number
]->arg
);
1711 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1715 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1716 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1717 return CMD_WARNING_CONFIG_FAILED
;
1720 area
->default_cost
= 1;
1723 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1725 if (IS_DEBUG_OSPF_EVENT
)
1727 "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4",
1729 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1732 ospf_area_check_free(ospf
, area_id
);
1737 DEFUN (ospf_area_export_list
,
1738 ospf_area_export_list_cmd
,
1739 "area <A.B.C.D|(0-4294967295)> export-list ACCESSLIST4_NAME",
1740 "OSPF area parameters\n"
1741 "OSPF area ID in IP address format\n"
1742 "OSPF area ID as a decimal value\n"
1743 "Set the filter for networks announced to other areas\n"
1744 "Name of the access-list\n")
1746 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1747 int idx_ipv4_number
= 1;
1748 struct ospf_area
*area
;
1749 struct in_addr area_id
;
1752 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1754 area
= ospf_area_get(ospf
, area_id
);
1755 ospf_area_display_format_set(ospf
, area
, format
);
1756 ospf_area_export_list_set(ospf
, area
, argv
[3]->arg
);
1761 DEFUN (no_ospf_area_export_list
,
1762 no_ospf_area_export_list_cmd
,
1763 "no area <A.B.C.D|(0-4294967295)> export-list ACCESSLIST4_NAME",
1765 "OSPF area parameters\n"
1766 "OSPF area ID in IP address format\n"
1767 "OSPF area ID as a decimal value\n"
1768 "Unset the filter for networks announced to other areas\n"
1769 "Name of the access-list\n")
1771 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1772 int idx_ipv4_number
= 2;
1773 struct ospf_area
*area
;
1774 struct in_addr area_id
;
1777 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1779 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1783 ospf_area_export_list_unset(ospf
, area
);
1789 DEFUN (ospf_area_import_list
,
1790 ospf_area_import_list_cmd
,
1791 "area <A.B.C.D|(0-4294967295)> import-list ACCESSLIST4_NAME",
1792 "OSPF area parameters\n"
1793 "OSPF area ID in IP address format\n"
1794 "OSPF area ID as a decimal value\n"
1795 "Set the filter for networks from other areas announced to the specified one\n"
1796 "Name of the access-list\n")
1798 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1799 int idx_ipv4_number
= 1;
1800 struct ospf_area
*area
;
1801 struct in_addr area_id
;
1804 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1806 area
= ospf_area_get(ospf
, area_id
);
1807 ospf_area_display_format_set(ospf
, area
, format
);
1808 ospf_area_import_list_set(ospf
, area
, argv
[3]->arg
);
1813 DEFUN (no_ospf_area_import_list
,
1814 no_ospf_area_import_list_cmd
,
1815 "no area <A.B.C.D|(0-4294967295)> import-list ACCESSLIST4_NAME",
1817 "OSPF area parameters\n"
1818 "OSPF area ID in IP address format\n"
1819 "OSPF area ID as a decimal value\n"
1820 "Unset the filter for networks announced to other areas\n"
1821 "Name of the access-list\n")
1823 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1824 int idx_ipv4_number
= 2;
1825 struct ospf_area
*area
;
1826 struct in_addr area_id
;
1829 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1831 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1835 ospf_area_import_list_unset(ospf
, area
);
1840 DEFUN (ospf_area_filter_list
,
1841 ospf_area_filter_list_cmd
,
1842 "area <A.B.C.D|(0-4294967295)> filter-list prefix PREFIXLIST_NAME <in|out>",
1843 "OSPF area parameters\n"
1844 "OSPF area ID in IP address format\n"
1845 "OSPF area ID as a decimal value\n"
1846 "Filter networks between OSPF areas\n"
1847 "Filter prefixes between OSPF areas\n"
1848 "Name of an IP prefix-list\n"
1849 "Filter networks sent to this area\n"
1850 "Filter networks sent from this area\n")
1852 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1853 int idx_ipv4_number
= 1;
1856 struct ospf_area
*area
;
1857 struct in_addr area_id
;
1858 struct prefix_list
*plist
;
1861 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1863 area
= ospf_area_get(ospf
, area_id
);
1864 ospf_area_display_format_set(ospf
, area
, format
);
1865 plist
= prefix_list_lookup(AFI_IP
, argv
[idx_word
]->arg
);
1866 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1867 PREFIX_LIST_IN(area
) = plist
;
1868 if (PREFIX_NAME_IN(area
))
1869 free(PREFIX_NAME_IN(area
));
1871 PREFIX_NAME_IN(area
) = strdup(argv
[idx_word
]->arg
);
1872 ospf_schedule_abr_task(ospf
);
1874 PREFIX_LIST_OUT(area
) = plist
;
1875 if (PREFIX_NAME_OUT(area
))
1876 free(PREFIX_NAME_OUT(area
));
1878 PREFIX_NAME_OUT(area
) = strdup(argv
[idx_word
]->arg
);
1879 ospf_schedule_abr_task(ospf
);
1885 DEFUN (no_ospf_area_filter_list
,
1886 no_ospf_area_filter_list_cmd
,
1887 "no area <A.B.C.D|(0-4294967295)> filter-list prefix PREFIXLIST_NAME <in|out>",
1889 "OSPF area parameters\n"
1890 "OSPF area ID in IP address format\n"
1891 "OSPF area ID as a decimal value\n"
1892 "Filter networks between OSPF areas\n"
1893 "Filter prefixes between OSPF areas\n"
1894 "Name of an IP prefix-list\n"
1895 "Filter networks sent to this area\n"
1896 "Filter networks sent from this area\n")
1898 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1899 int idx_ipv4_number
= 2;
1902 struct ospf_area
*area
;
1903 struct in_addr area_id
;
1906 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1908 if ((area
= ospf_area_lookup_by_area_id(ospf
, area_id
)) == NULL
)
1911 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1912 if (PREFIX_NAME_IN(area
))
1913 if (strcmp(PREFIX_NAME_IN(area
), argv
[idx_word
]->arg
)
1917 PREFIX_LIST_IN(area
) = NULL
;
1918 if (PREFIX_NAME_IN(area
))
1919 free(PREFIX_NAME_IN(area
));
1921 PREFIX_NAME_IN(area
) = NULL
;
1923 ospf_schedule_abr_task(ospf
);
1925 if (PREFIX_NAME_OUT(area
))
1926 if (strcmp(PREFIX_NAME_OUT(area
), argv
[idx_word
]->arg
)
1930 PREFIX_LIST_OUT(area
) = NULL
;
1931 if (PREFIX_NAME_OUT(area
))
1932 free(PREFIX_NAME_OUT(area
));
1934 PREFIX_NAME_OUT(area
) = NULL
;
1936 ospf_schedule_abr_task(ospf
);
1943 DEFUN (ospf_area_authentication_message_digest
,
1944 ospf_area_authentication_message_digest_cmd
,
1945 "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest",
1947 "OSPF area parameters\n"
1948 "OSPF area ID in IP address format\n"
1949 "OSPF area ID as a decimal value\n"
1950 "Enable authentication\n"
1951 "Use message-digest authentication\n")
1953 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1955 struct ospf_area
*area
;
1956 struct in_addr area_id
;
1959 argv_find(argv
, argc
, "area", &idx
);
1960 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx
+ 1]->arg
);
1962 area
= ospf_area_get(ospf
, area_id
);
1963 ospf_area_display_format_set(ospf
, area
, format
);
1964 area
->auth_type
= strmatch(argv
[0]->text
, "no")
1966 : OSPF_AUTH_CRYPTOGRAPHIC
;
1971 DEFUN (ospf_area_authentication
,
1972 ospf_area_authentication_cmd
,
1973 "area <A.B.C.D|(0-4294967295)> authentication",
1974 "OSPF area parameters\n"
1975 "OSPF area ID in IP address format\n"
1976 "OSPF area ID as a decimal value\n"
1977 "Enable authentication\n")
1979 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1980 int idx_ipv4_number
= 1;
1981 struct ospf_area
*area
;
1982 struct in_addr area_id
;
1985 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1987 area
= ospf_area_get(ospf
, area_id
);
1988 ospf_area_display_format_set(ospf
, area
, format
);
1989 area
->auth_type
= OSPF_AUTH_SIMPLE
;
1994 DEFUN (no_ospf_area_authentication
,
1995 no_ospf_area_authentication_cmd
,
1996 "no area <A.B.C.D|(0-4294967295)> authentication",
1998 "OSPF area parameters\n"
1999 "OSPF area ID in IP address format\n"
2000 "OSPF area ID as a decimal value\n"
2001 "Enable authentication\n")
2003 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2004 int idx_ipv4_number
= 2;
2005 struct ospf_area
*area
;
2006 struct in_addr area_id
;
2009 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
2011 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
2015 area
->auth_type
= OSPF_AUTH_NULL
;
2017 ospf_area_check_free(ospf
, area_id
);
2023 DEFUN (ospf_abr_type
,
2025 "ospf abr-type <cisco|ibm|shortcut|standard>",
2026 "OSPF specific commands\n"
2027 "Set OSPF ABR type\n"
2028 "Alternative ABR, cisco implementation\n"
2029 "Alternative ABR, IBM implementation\n"
2031 "Standard behavior (RFC2328)\n")
2033 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2035 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2037 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2038 abr_type
= OSPF_ABR_CISCO
;
2039 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2040 abr_type
= OSPF_ABR_IBM
;
2041 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2042 abr_type
= OSPF_ABR_SHORTCUT
;
2043 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2044 abr_type
= OSPF_ABR_STAND
;
2046 return CMD_WARNING_CONFIG_FAILED
;
2048 /* If ABR type value is changed, schedule ABR task. */
2049 if (ospf
->abr_type
!= abr_type
) {
2050 ospf
->abr_type
= abr_type
;
2051 ospf_schedule_abr_task(ospf
);
2057 DEFUN (no_ospf_abr_type
,
2058 no_ospf_abr_type_cmd
,
2059 "no ospf abr-type <cisco|ibm|shortcut|standard>",
2061 "OSPF specific commands\n"
2062 "Set OSPF ABR type\n"
2063 "Alternative ABR, cisco implementation\n"
2064 "Alternative ABR, IBM implementation\n"
2068 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2070 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2072 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2073 abr_type
= OSPF_ABR_CISCO
;
2074 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2075 abr_type
= OSPF_ABR_IBM
;
2076 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2077 abr_type
= OSPF_ABR_SHORTCUT
;
2078 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2079 abr_type
= OSPF_ABR_STAND
;
2081 return CMD_WARNING_CONFIG_FAILED
;
2083 /* If ABR type value is changed, schedule ABR task. */
2084 if (ospf
->abr_type
== abr_type
) {
2085 ospf
->abr_type
= OSPF_ABR_DEFAULT
;
2086 ospf_schedule_abr_task(ospf
);
2092 DEFUN (ospf_log_adjacency_changes
,
2093 ospf_log_adjacency_changes_cmd
,
2094 "log-adjacency-changes",
2095 "Log changes in adjacency state\n")
2097 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2099 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2100 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2104 DEFUN (ospf_log_adjacency_changes_detail
,
2105 ospf_log_adjacency_changes_detail_cmd
,
2106 "log-adjacency-changes detail",
2107 "Log changes in adjacency state\n"
2108 "Log all state changes\n")
2110 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2112 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2113 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2117 DEFUN (no_ospf_log_adjacency_changes
,
2118 no_ospf_log_adjacency_changes_cmd
,
2119 "no log-adjacency-changes",
2121 "Log changes in adjacency state\n")
2123 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2125 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2126 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2130 DEFUN (no_ospf_log_adjacency_changes_detail
,
2131 no_ospf_log_adjacency_changes_detail_cmd
,
2132 "no log-adjacency-changes detail",
2134 "Log changes in adjacency state\n"
2135 "Log all state changes\n")
2137 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2139 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2143 DEFUN (ospf_compatible_rfc1583
,
2144 ospf_compatible_rfc1583_cmd
,
2145 "compatible rfc1583",
2146 "OSPF compatibility list\n"
2147 "compatible with RFC 1583\n")
2149 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2151 if (!CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2152 SET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2153 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2158 DEFUN (no_ospf_compatible_rfc1583
,
2159 no_ospf_compatible_rfc1583_cmd
,
2160 "no compatible rfc1583",
2162 "OSPF compatibility list\n"
2163 "compatible with RFC 1583\n")
2165 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2167 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2168 UNSET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2169 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2174 ALIAS(ospf_compatible_rfc1583
, ospf_rfc1583_flag_cmd
,
2175 "ospf rfc1583compatibility",
2176 "OSPF specific commands\n"
2177 "Enable the RFC1583Compatibility flag\n")
2179 ALIAS(no_ospf_compatible_rfc1583
, no_ospf_rfc1583_flag_cmd
,
2180 "no ospf rfc1583compatibility", NO_STR
2181 "OSPF specific commands\n"
2182 "Disable the RFC1583Compatibility flag\n")
2184 static void ospf_table_reinstall_routes(struct ospf
*ospf
,
2185 struct route_table
*rt
)
2187 struct route_node
*rn
;
2192 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
2193 struct ospf_route
*or;
2199 if (or->type
== OSPF_DESTINATION_NETWORK
)
2200 ospf_zebra_add(ospf
, (struct prefix_ipv4
*)&rn
->p
, or);
2201 else if (or->type
== OSPF_DESTINATION_DISCARD
)
2202 ospf_zebra_add_discard(ospf
,
2203 (struct prefix_ipv4
*)&rn
->p
);
2207 static void ospf_reinstall_routes(struct ospf
*ospf
)
2209 ospf_table_reinstall_routes(ospf
, ospf
->new_table
);
2210 ospf_table_reinstall_routes(ospf
, ospf
->new_external_route
);
2213 DEFPY (ospf_send_extra_data
,
2214 ospf_send_extra_data_cmd
,
2215 "[no] ospf send-extra-data zebra",
2218 "Extra data to Zebra for display/use\n"
2221 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2223 if (no
&& CHECK_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
)) {
2224 UNSET_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
);
2225 ospf_reinstall_routes(ospf
);
2226 } else if (!CHECK_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
)) {
2227 SET_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
);
2228 ospf_reinstall_routes(ospf
);
2234 static int ospf_timers_spf_set(struct vty
*vty
, unsigned int delay
,
2235 unsigned int hold
, unsigned int max
)
2237 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2239 ospf
->spf_delay
= delay
;
2240 ospf
->spf_holdtime
= hold
;
2241 ospf
->spf_max_holdtime
= max
;
2246 DEFUN (ospf_timers_min_ls_interval
,
2247 ospf_timers_min_ls_interval_cmd
,
2248 "timers throttle lsa all (0-5000)",
2249 "Adjust routing timers\n"
2250 "Throttling adaptive timer\n"
2251 "LSA delay between transmissions\n"
2253 "Delay (msec) between sending LSAs\n")
2255 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2257 unsigned int interval
;
2260 vty_out(vty
, "Insufficient arguments\n");
2261 return CMD_WARNING_CONFIG_FAILED
;
2264 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2266 ospf
->min_ls_interval
= interval
;
2271 DEFUN (no_ospf_timers_min_ls_interval
,
2272 no_ospf_timers_min_ls_interval_cmd
,
2273 "no timers throttle lsa all [(0-5000)]",
2275 "Adjust routing timers\n"
2276 "Throttling adaptive timer\n"
2277 "LSA delay between transmissions\n"
2279 "Delay (msec) between sending LSAs\n")
2281 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2282 ospf
->min_ls_interval
= OSPF_MIN_LS_INTERVAL
;
2287 DEFUN (ospf_timers_throttle_spf
,
2288 ospf_timers_throttle_spf_cmd
,
2289 "timers throttle spf (0-600000) (0-600000) (0-600000)",
2290 "Adjust routing timers\n"
2291 "Throttling adaptive timer\n"
2293 "Delay (msec) from first change received till SPF calculation\n"
2294 "Initial hold time (msec) between consecutive SPF calculations\n"
2295 "Maximum hold time (msec)\n")
2298 int idx_number_2
= 4;
2299 int idx_number_3
= 5;
2300 unsigned int delay
, hold
, max
;
2303 vty_out(vty
, "Insufficient arguments\n");
2304 return CMD_WARNING_CONFIG_FAILED
;
2307 delay
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2308 hold
= strtoul(argv
[idx_number_2
]->arg
, NULL
, 10);
2309 max
= strtoul(argv
[idx_number_3
]->arg
, NULL
, 10);
2311 return ospf_timers_spf_set(vty
, delay
, hold
, max
);
2314 DEFUN (no_ospf_timers_throttle_spf
,
2315 no_ospf_timers_throttle_spf_cmd
,
2316 "no timers throttle spf [(0-600000)(0-600000)(0-600000)]",
2318 "Adjust routing timers\n"
2319 "Throttling adaptive timer\n"
2321 "Delay (msec) from first change received till SPF calculation\n"
2322 "Initial hold time (msec) between consecutive SPF calculations\n"
2323 "Maximum hold time (msec)\n")
2325 return ospf_timers_spf_set(vty
, OSPF_SPF_DELAY_DEFAULT
,
2326 OSPF_SPF_HOLDTIME_DEFAULT
,
2327 OSPF_SPF_MAX_HOLDTIME_DEFAULT
);
2331 DEFUN (ospf_timers_lsa_min_arrival
,
2332 ospf_timers_lsa_min_arrival_cmd
,
2333 "timers lsa min-arrival (0-600000)",
2334 "Adjust routing timers\n"
2336 "Minimum delay in receiving new version of a LSA\n"
2337 "Delay in milliseconds\n")
2339 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2340 ospf
->min_ls_arrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2344 DEFUN (no_ospf_timers_lsa_min_arrival
,
2345 no_ospf_timers_lsa_min_arrival_cmd
,
2346 "no timers lsa min-arrival [(0-600000)]",
2348 "Adjust routing timers\n"
2350 "Minimum delay in receiving new version of a LSA\n"
2351 "Delay in milliseconds\n")
2353 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2354 unsigned int minarrival
;
2357 minarrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2359 if (ospf
->min_ls_arrival
!= minarrival
2360 || minarrival
== OSPF_MIN_LS_ARRIVAL
)
2364 ospf
->min_ls_arrival
= OSPF_MIN_LS_ARRIVAL
;
2369 DEFUN (ospf_neighbor
,
2371 "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]",
2373 "Neighbor IP address\n"
2374 "Neighbor Priority\n"
2376 "Dead Neighbor Polling interval\n"
2379 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2383 struct in_addr nbr_addr
;
2384 unsigned int priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2385 unsigned int interval
= OSPF_POLL_INTERVAL_DEFAULT
;
2387 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2388 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2389 return CMD_WARNING_CONFIG_FAILED
;
2393 priority
= strtoul(argv
[idx_pri
]->arg
, NULL
, 10);
2396 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2398 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2401 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2404 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2409 DEFUN (ospf_neighbor_poll_interval
,
2410 ospf_neighbor_poll_interval_cmd
,
2411 "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2413 "Neighbor IP address\n"
2414 "Dead Neighbor Polling interval\n"
2416 "OSPF priority of non-broadcast neighbor\n"
2419 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2423 struct in_addr nbr_addr
;
2424 unsigned int priority
;
2425 unsigned int interval
;
2427 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2428 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2429 return CMD_WARNING_CONFIG_FAILED
;
2432 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2434 priority
= argc
> 4 ? strtoul(argv
[idx_pri
]->arg
, NULL
, 10)
2435 : OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2437 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2438 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2441 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2446 DEFUN (no_ospf_neighbor
,
2447 no_ospf_neighbor_cmd
,
2448 "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]",
2451 "Neighbor IP address\n"
2452 "Neighbor Priority\n"
2454 "Dead Neighbor Polling interval\n"
2457 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2459 struct in_addr nbr_addr
;
2461 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2462 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2463 return CMD_WARNING_CONFIG_FAILED
;
2466 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2471 DEFUN (no_ospf_neighbor_poll
,
2472 no_ospf_neighbor_poll_cmd
,
2473 "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2476 "Neighbor IP address\n"
2477 "Dead Neighbor Polling interval\n"
2479 "Neighbor Priority\n"
2482 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2484 struct in_addr nbr_addr
;
2486 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2487 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2488 return CMD_WARNING_CONFIG_FAILED
;
2491 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2496 DEFUN (ospf_refresh_timer
,
2497 ospf_refresh_timer_cmd
,
2498 "refresh timer (10-1800)",
2499 "Adjust refresh parameters\n"
2500 "Set refresh timer\n"
2501 "Timer value in seconds\n")
2503 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2505 unsigned int interval
;
2507 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2508 interval
= (interval
/ OSPF_LSA_REFRESHER_GRANULARITY
)
2509 * OSPF_LSA_REFRESHER_GRANULARITY
;
2511 ospf_timers_refresh_set(ospf
, interval
);
2516 DEFUN (no_ospf_refresh_timer
,
2517 no_ospf_refresh_timer_val_cmd
,
2518 "no refresh timer [(10-1800)]",
2520 "Adjust refresh parameters\n"
2521 "Unset refresh timer\n"
2522 "Timer value in seconds\n")
2524 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2526 unsigned int interval
;
2529 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2531 if (ospf
->lsa_refresh_interval
!= interval
2532 || interval
== OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
2536 ospf_timers_refresh_unset(ospf
);
2542 DEFUN (ospf_auto_cost_reference_bandwidth
,
2543 ospf_auto_cost_reference_bandwidth_cmd
,
2544 "auto-cost reference-bandwidth (1-4294967)",
2545 "Calculate OSPF interface cost according to bandwidth\n"
2546 "Use reference bandwidth method to assign OSPF cost\n"
2547 "The reference bandwidth in terms of Mbits per second\n")
2549 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2550 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2553 struct interface
*ifp
;
2555 refbw
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2556 if (refbw
< 1 || refbw
> 4294967) {
2557 vty_out(vty
, "reference-bandwidth value is invalid\n");
2558 return CMD_WARNING_CONFIG_FAILED
;
2561 /* If reference bandwidth is changed. */
2562 if ((refbw
) == ospf
->ref_bandwidth
)
2565 ospf
->ref_bandwidth
= refbw
;
2566 FOR_ALL_INTERFACES (vrf
, ifp
)
2567 ospf_if_recalculate_output_cost(ifp
);
2572 DEFUN (no_ospf_auto_cost_reference_bandwidth
,
2573 no_ospf_auto_cost_reference_bandwidth_cmd
,
2574 "no auto-cost reference-bandwidth [(1-4294967)]",
2576 "Calculate OSPF interface cost according to bandwidth\n"
2577 "Use reference bandwidth method to assign OSPF cost\n"
2578 "The reference bandwidth in terms of Mbits per second\n")
2580 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2581 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2582 struct interface
*ifp
;
2584 if (ospf
->ref_bandwidth
== OSPF_DEFAULT_REF_BANDWIDTH
)
2587 ospf
->ref_bandwidth
= OSPF_DEFAULT_REF_BANDWIDTH
;
2588 vty_out(vty
, "%% OSPF: Reference bandwidth is changed.\n");
2590 " Please ensure reference bandwidth is consistent across all routers\n");
2592 FOR_ALL_INTERFACES (vrf
, ifp
)
2593 ospf_if_recalculate_output_cost(ifp
);
2598 DEFUN (ospf_write_multiplier
,
2599 ospf_write_multiplier_cmd
,
2600 "ospf write-multiplier (1-100)",
2601 "OSPF specific commands\n"
2602 "Write multiplier\n"
2603 "Maximum number of interface serviced per write\n")
2605 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2607 uint32_t write_oi_count
;
2614 write_oi_count
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2615 if (write_oi_count
< 1 || write_oi_count
> 100) {
2616 vty_out(vty
, "write-multiplier value is invalid\n");
2617 return CMD_WARNING_CONFIG_FAILED
;
2620 ospf
->write_oi_count
= write_oi_count
;
2624 ALIAS(ospf_write_multiplier
, write_multiplier_cmd
, "write-multiplier (1-100)",
2625 "Write multiplier\n"
2626 "Maximum number of interface serviced per write\n")
2628 DEFUN (no_ospf_write_multiplier
,
2629 no_ospf_write_multiplier_cmd
,
2630 "no ospf write-multiplier (1-100)",
2632 "OSPF specific commands\n"
2633 "Write multiplier\n"
2634 "Maximum number of interface serviced per write\n")
2636 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2638 ospf
->write_oi_count
= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
;
2642 ALIAS(no_ospf_write_multiplier
, no_write_multiplier_cmd
,
2643 "no write-multiplier (1-100)", NO_STR
2644 "Write multiplier\n"
2645 "Maximum number of interface serviced per write\n")
2647 DEFUN(ospf_ti_lfa
, ospf_ti_lfa_cmd
, "fast-reroute ti-lfa [node-protection]",
2648 "Fast Reroute for MPLS and IP resilience\n"
2649 "Topology Independent LFA (Loop-Free Alternate)\n"
2650 "TI-LFA node protection (default is link protection)\n")
2652 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2654 ospf
->ti_lfa_enabled
= true;
2657 ospf
->ti_lfa_protection_type
= OSPF_TI_LFA_NODE_PROTECTION
;
2659 ospf
->ti_lfa_protection_type
= OSPF_TI_LFA_LINK_PROTECTION
;
2661 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2666 DEFUN(no_ospf_ti_lfa
, no_ospf_ti_lfa_cmd
,
2667 "no fast-reroute ti-lfa [node-protection]",
2669 "Fast Reroute for MPLS and IP resilience\n"
2670 "Topology Independent LFA (Loop-Free Alternate)\n"
2671 "TI-LFA node protection (default is link protection)\n")
2673 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2675 ospf
->ti_lfa_enabled
= false;
2677 ospf
->ti_lfa_protection_type
= OSPF_TI_LFA_UNDEFINED_PROTECTION
;
2679 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2684 static void ospf_maxpath_set(struct vty
*vty
, struct ospf
*ospf
, uint16_t paths
)
2686 if (ospf
->max_multipath
== paths
)
2689 ospf
->max_multipath
= paths
;
2691 /* Send deletion notification to zebra to delete all
2692 * ospf specific routes and reinitiat SPF to reflect
2693 * the new max multipath.
2695 ospf_restart_spf(ospf
);
2698 /* Ospf Maximum multiple paths config support */
2699 DEFUN (ospf_max_multipath
,
2700 ospf_max_multipath_cmd
,
2701 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM
),
2702 "Max no of multiple paths for ECMP support\n"
2703 "Number of paths\n")
2705 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2709 maxpaths
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2711 ospf_maxpath_set(vty
, ospf
, maxpaths
);
2715 DEFUN (no_ospf_max_multipath
,
2716 no_ospf_max_multipath_cmd
,
2719 "Max no of multiple paths for ECMP support\n")
2721 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2722 uint16_t maxpaths
= MULTIPATH_NUM
;
2724 ospf_maxpath_set(vty
, ospf
, maxpaths
);
2728 static const char *const ospf_abr_type_descr_str
[] = {
2729 "Unknown", "Standard (RFC2328)", "Alternative IBM",
2730 "Alternative Cisco", "Alternative Shortcut"
2733 static const char *const ospf_shortcut_mode_descr_str
[] = {
2734 "Default", "Enabled", "Disabled"
2737 static void show_ip_ospf_area(struct vty
*vty
, struct ospf_area
*area
,
2738 json_object
*json_areas
, bool use_json
)
2740 json_object
*json_area
= NULL
;
2741 char buf
[PREFIX_STRLEN
];
2744 json_area
= json_object_new_object();
2748 vty_out(vty
, " Area ID: %pI4", &area
->area_id
);
2750 /* Show Area type/mode. */
2751 if (OSPF_IS_AREA_BACKBONE(area
)) {
2753 json_object_boolean_true_add(json_area
, "backbone");
2755 vty_out(vty
, " (Backbone)\n");
2758 if (area
->external_routing
== OSPF_AREA_STUB
) {
2759 if (area
->no_summary
)
2760 json_object_boolean_true_add(
2761 json_area
, "stubNoSummary");
2762 if (area
->shortcut_configured
)
2763 json_object_boolean_true_add(
2764 json_area
, "stubShortcut");
2765 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
2766 if (area
->no_summary
)
2767 json_object_boolean_true_add(
2768 json_area
, "nssaNoSummary");
2769 if (area
->shortcut_configured
)
2770 json_object_boolean_true_add(
2771 json_area
, "nssaShortcut");
2774 json_object_string_add(
2775 json_area
, "shortcuttingMode",
2776 ospf_shortcut_mode_descr_str
2777 [area
->shortcut_configured
]);
2778 if (area
->shortcut_capability
)
2779 json_object_boolean_true_add(json_area
,
2782 if (area
->external_routing
== OSPF_AREA_STUB
)
2783 vty_out(vty
, " (Stub%s%s)",
2784 area
->no_summary
? ", no summary" : "",
2785 area
->shortcut_configured
? "; " : "");
2786 else if (area
->external_routing
== OSPF_AREA_NSSA
)
2787 vty_out(vty
, " (NSSA%s%s)",
2788 area
->no_summary
? ", no summary" : "",
2789 area
->shortcut_configured
? "; " : "");
2792 vty_out(vty
, " Shortcutting mode: %s",
2793 ospf_shortcut_mode_descr_str
2794 [area
->shortcut_configured
]);
2795 vty_out(vty
, ", S-bit consensus: %s\n",
2796 area
->shortcut_capability
? "ok" : "no");
2800 /* Show number of interfaces */
2802 json_object_int_add(json_area
, "areaIfTotalCounter",
2803 listcount(area
->oiflist
));
2804 json_object_int_add(json_area
, "areaIfActiveCounter",
2808 " Number of interfaces in this area: Total: %d, Active: %d\n",
2809 listcount(area
->oiflist
), area
->act_ints
);
2811 if (area
->external_routing
== OSPF_AREA_NSSA
) {
2813 json_object_boolean_true_add(json_area
, "nssa");
2814 if (!IS_OSPF_ABR(area
->ospf
))
2815 json_object_boolean_false_add(json_area
, "abr");
2816 else if (area
->NSSATranslatorState
) {
2817 json_object_boolean_true_add(json_area
, "abr");
2818 if (area
->NSSATranslatorRole
2819 == OSPF_NSSA_ROLE_CANDIDATE
)
2820 json_object_boolean_true_add(
2822 "nssaTranslatorElected");
2823 else if (area
->NSSATranslatorRole
2824 == OSPF_NSSA_ROLE_ALWAYS
)
2825 json_object_boolean_true_add(
2827 "nssaTranslatorAlways");
2829 json_object_boolean_true_add(
2831 "nssaTranslatorNever");
2833 json_object_boolean_true_add(json_area
, "abr");
2834 if (area
->NSSATranslatorRole
2835 == OSPF_NSSA_ROLE_CANDIDATE
)
2836 json_object_boolean_false_add(
2838 "nssaTranslatorElected");
2840 json_object_boolean_true_add(
2842 "nssaTranslatorNever");
2846 " It is an NSSA configuration.\n Elected NSSA/ABR performs type-7/type-5 LSA translation.\n");
2847 if (!IS_OSPF_ABR(area
->ospf
))
2849 " It is not ABR, therefore not Translator.\n");
2850 else if (area
->NSSATranslatorState
) {
2851 vty_out(vty
, " We are an ABR and ");
2852 if (area
->NSSATranslatorRole
2853 == OSPF_NSSA_ROLE_CANDIDATE
)
2855 "the NSSA Elected Translator.\n");
2856 else if (area
->NSSATranslatorRole
2857 == OSPF_NSSA_ROLE_ALWAYS
)
2859 "always an NSSA Translator.\n");
2862 "never an NSSA Translator.\n");
2864 vty_out(vty
, " We are an ABR, but ");
2865 if (area
->NSSATranslatorRole
2866 == OSPF_NSSA_ROLE_CANDIDATE
)
2868 "not the NSSA Elected Translator.\n");
2871 "never an NSSA Translator.\n");
2876 /* Stub-router state for this area */
2877 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
)) {
2878 char timebuf
[OSPF_TIME_DUMP_SIZE
];
2881 json_object_boolean_true_add(
2882 json_area
, "originStubMaxDistRouterLsa");
2883 if (CHECK_FLAG(area
->stub_router_state
,
2884 OSPF_AREA_ADMIN_STUB_ROUTED
))
2885 json_object_boolean_true_add(
2886 json_area
, "indefiniteActiveAdmin");
2887 if (area
->t_stub_router
) {
2891 &area
->t_stub_router
->u
.sands
,
2894 json_object_int_add(
2896 "activeStartupRemainderMsecs",
2901 " Originating stub / maximum-distance Router-LSA\n");
2902 if (CHECK_FLAG(area
->stub_router_state
,
2903 OSPF_AREA_ADMIN_STUB_ROUTED
))
2905 " Administratively activated (indefinitely)\n");
2906 if (area
->t_stub_router
)
2908 " Active from startup, %s remaining\n",
2909 ospf_timer_dump(area
->t_stub_router
,
2916 /* Show number of fully adjacent neighbors. */
2917 json_object_int_add(json_area
, "nbrFullAdjacentCounter",
2920 /* Show authentication type. */
2921 if (area
->auth_type
== OSPF_AUTH_NULL
)
2922 json_object_string_add(json_area
, "authentication",
2923 "authenticationNone");
2924 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2925 json_object_string_add(json_area
, "authentication",
2926 "authenticationSimplePassword");
2927 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2928 json_object_string_add(json_area
, "authentication",
2929 "authenticationMessageDigest");
2931 if (!OSPF_IS_AREA_BACKBONE(area
))
2932 json_object_int_add(json_area
,
2933 "virtualAdjacenciesPassingCounter",
2936 /* Show SPF calculation times. */
2937 json_object_int_add(json_area
, "spfExecutedCounter",
2938 area
->spf_calculation
);
2939 json_object_int_add(json_area
, "lsaNumber", area
->lsdb
->total
);
2940 json_object_int_add(
2941 json_area
, "lsaRouterNumber",
2942 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
));
2943 json_object_int_add(
2944 json_area
, "lsaRouterChecksum",
2945 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
2946 json_object_int_add(
2947 json_area
, "lsaNetworkNumber",
2948 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
));
2949 json_object_int_add(
2950 json_area
, "lsaNetworkChecksum",
2951 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
2952 json_object_int_add(
2953 json_area
, "lsaSummaryNumber",
2954 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
));
2955 json_object_int_add(
2956 json_area
, "lsaSummaryChecksum",
2957 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
2958 json_object_int_add(
2959 json_area
, "lsaAsbrNumber",
2960 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2961 json_object_int_add(
2962 json_area
, "lsaAsbrChecksum",
2963 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2964 json_object_int_add(
2965 json_area
, "lsaNssaNumber",
2966 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2967 json_object_int_add(
2968 json_area
, "lsaNssaChecksum",
2969 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2971 /* Show number of fully adjacent neighbors. */
2973 " Number of fully adjacent neighbors in this area: %d\n",
2976 /* Show authentication type. */
2977 vty_out(vty
, " Area has ");
2978 if (area
->auth_type
== OSPF_AUTH_NULL
)
2979 vty_out(vty
, "no authentication\n");
2980 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2981 vty_out(vty
, "simple password authentication\n");
2982 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2983 vty_out(vty
, "message digest authentication\n");
2985 if (!OSPF_IS_AREA_BACKBONE(area
))
2987 " Number of full virtual adjacencies going through this area: %d\n",
2990 /* Show SPF calculation times. */
2991 vty_out(vty
, " SPF algorithm executed %d times\n",
2992 area
->spf_calculation
);
2994 /* Show number of LSA. */
2995 vty_out(vty
, " Number of LSA %ld\n", area
->lsdb
->total
);
2997 " Number of router LSA %ld. Checksum Sum 0x%08x\n",
2998 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
),
2999 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
3001 " Number of network LSA %ld. Checksum Sum 0x%08x\n",
3002 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
),
3003 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
3005 " Number of summary LSA %ld. Checksum Sum 0x%08x\n",
3006 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
),
3007 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
3009 " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n",
3010 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
),
3011 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
3012 vty_out(vty
, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n",
3013 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
),
3014 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
3018 json_object_int_add(
3019 json_area
, "lsaOpaqueLinkNumber",
3020 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
3021 json_object_int_add(
3022 json_area
, "lsaOpaqueLinkChecksum",
3023 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
3024 json_object_int_add(
3025 json_area
, "lsaOpaqueAreaNumber",
3026 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
3027 json_object_int_add(
3028 json_area
, "lsaOpaqueAreaChecksum",
3029 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
3032 " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n",
3033 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
),
3034 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
3036 " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n",
3037 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
),
3038 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
3041 if (area
->fr_info
.configured
) {
3043 json_object_string_add(json_area
, "areaFloodReduction",
3046 vty_out(vty
, " Flood Reduction is configured.\n");
3049 if (area
->fr_info
.enabled
) {
3051 json_object_boolean_true_add(
3052 json_area
, "areaFloodReductionEnabled");
3053 if (area
->fr_info
.router_lsas_recv_dc_bit
)
3054 json_object_boolean_true_add(
3055 json_area
, "lsasRecvDCbitSet");
3056 if (area
->fr_info
.area_ind_lsa_recvd
)
3057 json_object_string_add(json_area
,
3058 "areaIndicationLsaRecv",
3060 if (area
->fr_info
.indication_lsa_self
)
3061 json_object_string_addf(
3062 json_area
, "areaIndicationLsa", "%pI4",
3063 &area
->fr_info
.indication_lsa_self
->data
3066 vty_out(vty
, " Flood Reduction is enabled.\n");
3067 vty_out(vty
, " No of LSAs rcv'd with DC bit set %d\n",
3068 area
->fr_info
.router_lsas_recv_dc_bit
);
3069 if (area
->fr_info
.area_ind_lsa_recvd
)
3070 vty_out(vty
, " Ind LSA by other abr.\n");
3071 if (area
->fr_info
.indication_lsa_self
)
3072 vty_out(vty
, " Ind LSA generated %pI4\n",
3073 &area
->fr_info
.indication_lsa_self
->data
3079 json_object_object_add(json_areas
,
3080 inet_ntop(AF_INET
, &area
->area_id
,
3087 static int show_ip_ospf_common(struct vty
*vty
, struct ospf
*ospf
,
3088 json_object
*json
, uint8_t use_vrf
)
3090 struct listnode
*node
, *nnode
;
3091 struct ospf_area
*area
;
3092 struct timeval result
;
3093 char timebuf
[OSPF_TIME_DUMP_SIZE
];
3094 json_object
*json_vrf
= NULL
;
3095 json_object
*json_areas
= NULL
;
3099 json_vrf
= json_object_new_object();
3102 json_areas
= json_object_new_object();
3105 if (ospf
->instance
) {
3107 json_object_int_add(json
, "ospfInstance",
3110 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
3114 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3116 /* Show Router ID. */
3118 json_object_string_addf(json_vrf
, "routerId", "%pI4",
3121 vty_out(vty
, " OSPF Routing Process, Router ID: %pI4\n",
3125 /* Graceful shutdown */
3126 if (ospf
->t_deferred_shutdown
) {
3131 &ospf
->t_deferred_shutdown
->u
.sands
,
3134 json_object_int_add(json_vrf
, "deferredShutdownMsecs",
3138 " Deferred shutdown in progress, %s remaining\n",
3139 ospf_timer_dump(ospf
->t_deferred_shutdown
,
3140 timebuf
, sizeof(timebuf
)));
3144 /* Show capability. */
3146 json_object_boolean_true_add(json_vrf
, "tosRoutesOnly");
3147 json_object_boolean_true_add(json_vrf
, "rfc2328Conform");
3148 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
3149 json_object_boolean_true_add(json_vrf
,
3150 "rfc1583Compatibility");
3153 vty_out(vty
, " Supports only single TOS (TOS0) routes\n");
3154 vty_out(vty
, " This implementation conforms to RFC2328\n");
3155 vty_out(vty
, " RFC1583Compatibility flag is %s\n",
3156 CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)
3162 if (CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)) {
3163 json_object_boolean_true_add(json_vrf
, "opaqueCapable");
3166 vty_out(vty
, " OpaqueCapability flag is %s\n",
3167 CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)
3172 /* Show stub-router configuration */
3173 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
3174 || ospf
->stub_router_shutdown_time
3175 != OSPF_STUB_ROUTER_UNCONFIGURED
) {
3177 json_object_boolean_true_add(json_vrf
,
3178 "stubAdvertisement");
3179 if (ospf
->stub_router_startup_time
3180 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3181 json_object_int_add(
3182 json_vrf
, "postStartEnabledSecs",
3183 ospf
->stub_router_startup_time
);
3184 if (ospf
->stub_router_shutdown_time
3185 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3186 json_object_int_add(
3187 json_vrf
, "preShutdownEnabledSecs",
3188 ospf
->stub_router_shutdown_time
);
3191 " Stub router advertisement is configured\n");
3192 if (ospf
->stub_router_startup_time
3193 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3195 " Enabled for %us after start-up\n",
3196 ospf
->stub_router_startup_time
);
3197 if (ospf
->stub_router_shutdown_time
3198 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3200 " Enabled for %us prior to full shutdown\n",
3201 ospf
->stub_router_shutdown_time
);
3205 /* Show SPF timers. */
3207 json_object_int_add(json_vrf
, "spfScheduleDelayMsecs",
3209 json_object_int_add(json_vrf
, "holdtimeMinMsecs",
3210 ospf
->spf_holdtime
);
3211 json_object_int_add(json_vrf
, "holdtimeMaxMsecs",
3212 ospf
->spf_max_holdtime
);
3213 json_object_int_add(json_vrf
, "holdtimeMultplier",
3214 ospf
->spf_hold_multiplier
);
3217 " Initial SPF scheduling delay %d millisec(s)\n"
3218 " Minimum hold time between consecutive SPFs %d millisec(s)\n"
3219 " Maximum hold time between consecutive SPFs %d millisec(s)\n"
3220 " Hold time multiplier is currently %d\n",
3221 ospf
->spf_delay
, ospf
->spf_holdtime
,
3222 ospf
->spf_max_holdtime
, ospf
->spf_hold_multiplier
);
3226 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3227 long time_store
= 0;
3230 monotime_since(&ospf
->ts_spf
, NULL
) / 1000LL;
3231 json_object_int_add(json_vrf
, "spfLastExecutedMsecs",
3234 time_store
= (1000 * ospf
->ts_spf_duration
.tv_sec
)
3235 + (ospf
->ts_spf_duration
.tv_usec
/ 1000);
3236 json_object_int_add(json_vrf
, "spfLastDurationMsecs",
3239 json_object_boolean_true_add(json_vrf
, "spfHasNotRun");
3241 vty_out(vty
, " SPF algorithm ");
3242 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3243 monotime_since(&ospf
->ts_spf
, &result
);
3244 vty_out(vty
, "last executed %s ago\n",
3245 ospf_timeval_dump(&result
, timebuf
,
3247 vty_out(vty
, " Last SPF duration %s\n",
3248 ospf_timeval_dump(&ospf
->ts_spf_duration
,
3249 timebuf
, sizeof(timebuf
)));
3251 vty_out(vty
, "has not been run\n");
3255 if (ospf
->t_spf_calc
) {
3258 monotime_until(&ospf
->t_spf_calc
->u
.sands
, NULL
)
3260 json_object_int_add(json_vrf
, "spfTimerDueInMsecs",
3264 json_object_int_add(json_vrf
, "lsaMinIntervalMsecs",
3265 ospf
->min_ls_interval
);
3266 json_object_int_add(json_vrf
, "lsaMinArrivalMsecs",
3267 ospf
->min_ls_arrival
);
3268 /* Show write multiplier values */
3269 json_object_int_add(json_vrf
, "writeMultiplier",
3270 ospf
->write_oi_count
);
3271 /* Show refresh parameters. */
3272 json_object_int_add(json_vrf
, "refreshTimerMsecs",
3273 ospf
->lsa_refresh_interval
* 1000);
3275 /* show max multipath */
3276 json_object_int_add(json_vrf
, "maximumPaths",
3277 ospf
->max_multipath
);
3279 /* show administrative distance */
3280 json_object_int_add(json_vrf
, "preference",
3282 ? ospf
->distance_all
3283 : ZEBRA_OSPF_DISTANCE_DEFAULT
);
3285 vty_out(vty
, " SPF timer %s%s\n",
3286 (ospf
->t_spf_calc
? "due in " : "is "),
3287 ospf_timer_dump(ospf
->t_spf_calc
, timebuf
,
3290 vty_out(vty
, " LSA minimum interval %d msecs\n",
3291 ospf
->min_ls_interval
);
3292 vty_out(vty
, " LSA minimum arrival %d msecs\n",
3293 ospf
->min_ls_arrival
);
3295 /* Show write multiplier values */
3296 vty_out(vty
, " Write Multiplier set to %d \n",
3297 ospf
->write_oi_count
);
3299 /* Show refresh parameters. */
3300 vty_out(vty
, " Refresh timer %d secs\n",
3301 ospf
->lsa_refresh_interval
);
3303 /* show max multipath */
3304 vty_out(vty
, " Maximum multiple paths(ECMP) supported %d\n",
3305 ospf
->max_multipath
);
3307 /* show administrative distance */
3308 vty_out(vty
, " Administrative distance %u\n",
3309 ospf
->distance_all
? ospf
->distance_all
3310 : ZEBRA_OSPF_DISTANCE_DEFAULT
);
3313 if (ospf
->fr_configured
) {
3315 json_object_string_add(json_vrf
, "floodReduction",
3318 vty_out(vty
, " Flood Reduction is configured.\n");
3321 /* Show ABR/ASBR flags. */
3322 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ABR
)) {
3324 json_object_string_add(
3325 json_vrf
, "abrType",
3326 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3329 " This router is an ABR, ABR type is: %s\n",
3330 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3332 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ASBR
)) {
3334 json_object_string_add(
3335 json_vrf
, "asbrRouter",
3336 "injectingExternalRoutingInformation");
3339 " This router is an ASBR (injecting external routing information)\n");
3342 /* Show Number of AS-external-LSAs. */
3344 json_object_int_add(
3345 json_vrf
, "lsaExternalCounter",
3346 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3347 json_object_int_add(
3348 json_vrf
, "lsaExternalChecksum",
3349 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3352 " Number of external LSA %ld. Checksum Sum 0x%08x\n",
3353 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
),
3354 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3358 json_object_int_add(
3359 json_vrf
, "lsaAsopaqueCounter",
3360 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3361 json_object_int_add(
3362 json_vrf
, "lsaAsOpaqueChecksum",
3363 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3366 " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n",
3367 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
),
3368 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3371 /* Show number of areas attached. */
3373 json_object_int_add(json_vrf
, "attachedAreaCounter",
3374 listcount(ospf
->areas
));
3376 vty_out(vty
, " Number of areas attached to this router: %d\n",
3377 listcount(ospf
->areas
));
3379 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
3380 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
)) {
3382 json_object_boolean_true_add(
3383 json_vrf
, "adjacencyChangesLoggedAll");
3386 " All adjacency changes are logged\n");
3389 json_object_boolean_true_add(
3390 json_vrf
, "adjacencyChangesLogged");
3392 vty_out(vty
, " Adjacency changes are logged\n");
3396 /* show LDP-Sync status */
3397 ospf_ldp_sync_show_info(vty
, ospf
, json_vrf
, json
? 1 : 0);
3399 /* Show each area status. */
3400 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
3401 show_ip_ospf_area(vty
, area
, json_areas
, json
? 1 : 0);
3405 json_object_object_add(json_vrf
, "areas", json_areas
);
3406 json_object_object_add(json
, ospf_get_name(ospf
),
3409 json_object_object_add(json
, "areas", json_areas
);
3417 DEFUN (show_ip_ospf
,
3419 "show ip ospf [vrf <NAME|all>] [json]",
3422 "OSPF information\n"
3428 bool uj
= use_json(argc
, argv
);
3429 struct listnode
*node
= NULL
;
3430 char *vrf_name
= NULL
;
3431 bool all_vrf
= false;
3432 int ret
= CMD_SUCCESS
;
3435 json_object
*json
= NULL
;
3436 uint8_t use_vrf
= 0;
3438 if (listcount(om
->ospf
) == 0)
3441 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
3444 json
= json_object_new_object();
3446 /* vrf input is provided could be all or specific vrf*/
3448 bool ospf_output
= false;
3453 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
3454 if (!ospf
->oi_running
)
3457 ret
= show_ip_ospf_common(vty
, ospf
, json
,
3461 vty_json(vty
, json
);
3462 else if (!ospf_output
)
3463 vty_out(vty
, "%% OSPF is not enabled\n");
3466 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
3467 if ((ospf
== NULL
) || !ospf
->oi_running
) {
3469 vty_json(vty
, json
);
3472 "%% OSPF is not enabled in vrf %s\n",
3478 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
3479 /* Display default ospf (instance 0) info */
3480 if (ospf
== NULL
|| !ospf
->oi_running
) {
3482 vty_json(vty
, json
);
3485 "%% OSPF is not enabled in vrf default\n");
3492 show_ip_ospf_common(vty
, ospf
, json
, use_vrf
);
3494 vty_out(vty
, "%s\n",
3495 json_object_to_json_string_ext(
3496 json
, JSON_C_TO_STRING_PRETTY
));
3500 json_object_free(json
);
3505 DEFUN (show_ip_ospf_instance
,
3506 show_ip_ospf_instance_cmd
,
3507 "show ip ospf (1-65535) [json]",
3510 "OSPF information\n"
3516 unsigned short instance
= 0;
3517 bool uj
= use_json(argc
, argv
);
3518 int ret
= CMD_SUCCESS
;
3519 json_object
*json
= NULL
;
3521 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
3522 if (instance
!= ospf_instance
)
3523 return CMD_NOT_MY_INSTANCE
;
3525 ospf
= ospf_lookup_instance(instance
);
3526 if (!ospf
|| !ospf
->oi_running
)
3530 json
= json_object_new_object();
3532 ret
= show_ip_ospf_common(vty
, ospf
, json
, 0);
3535 vty_json(vty
, json
);
3540 static void ospf_interface_auth_show(struct vty
*vty
, struct ospf_interface
*oi
,
3541 json_object
*json
, bool use_json
)
3545 auth_type
= OSPF_IF_PARAM(oi
, auth_type
);
3547 switch (auth_type
) {
3548 case OSPF_AUTH_NULL
:
3550 json_object_string_add(json
, "authentication",
3551 "authenticationNone");
3553 vty_out(vty
, " Authentication NULL is enabled\n");
3555 case OSPF_AUTH_SIMPLE
: {
3557 json_object_string_add(json
, "authentication",
3558 "authenticationSimplePassword");
3561 " Simple password authentication enabled\n");
3564 case OSPF_AUTH_CRYPTOGRAPHIC
: {
3565 struct crypt_key
*ckey
;
3567 if (list_isempty(OSPF_IF_PARAM(oi
, auth_crypt
)))
3570 ckey
= listgetdata(listtail(OSPF_IF_PARAM(oi
, auth_crypt
)));
3573 json_object_string_add(json
, "authentication",
3574 "authenticationMessageDigest");
3577 " Cryptographic authentication enabled\n");
3578 vty_out(vty
, " Algorithm:MD5\n");
3588 static void show_ip_ospf_interface_sub(struct vty
*vty
, struct ospf
*ospf
,
3589 struct interface
*ifp
,
3590 json_object
*json_interface_sub
,
3594 struct ospf_neighbor
*nbr
;
3595 struct route_node
*rn
;
3596 uint32_t bandwidth
= ifp
->bandwidth
? ifp
->bandwidth
: ifp
->speed
;
3598 /* Is interface up? */
3600 is_up
= if_is_operative(ifp
);
3602 json_object_boolean_true_add(json_interface_sub
,
3605 json_object_boolean_false_add(json_interface_sub
,
3608 json_object_int_add(json_interface_sub
, "ifIndex",
3610 json_object_int_add(json_interface_sub
, "mtuBytes", ifp
->mtu
);
3611 json_object_int_add(json_interface_sub
, "bandwidthMbit",
3613 json_object_string_add(json_interface_sub
, "ifFlags",
3614 if_flag_dump(ifp
->flags
));
3616 vty_out(vty
, "%s is %s\n", ifp
->name
,
3617 ((is_up
= if_is_operative(ifp
)) ? "up" : "down"));
3618 vty_out(vty
, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n",
3619 ifp
->ifindex
, ifp
->mtu
, bandwidth
,
3620 if_flag_dump(ifp
->flags
));
3623 /* Is interface OSPF enabled? */
3625 if (ospf_oi_count(ifp
) == 0) {
3626 json_object_boolean_false_add(json_interface_sub
,
3629 } else if (!is_up
) {
3630 json_object_boolean_false_add(json_interface_sub
,
3634 json_object_boolean_true_add(json_interface_sub
,
3637 if (ospf_oi_count(ifp
) == 0) {
3638 vty_out(vty
, " OSPF not enabled on this interface\n");
3640 } else if (!is_up
) {
3642 " OSPF is enabled, but not running on this interface\n");
3647 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
3648 struct ospf_interface
*oi
= rn
->info
;
3653 if (CHECK_FLAG(oi
->connected
->flags
, ZEBRA_IFA_UNNUMBERED
)) {
3655 json_object_boolean_true_add(json_interface_sub
,
3658 vty_out(vty
, " This interface is UNNUMBERED,");
3660 struct in_addr dest
;
3663 /* Show OSPF interface information. */
3665 json_object_string_addf(
3666 json_interface_sub
, "ipAddress", "%pI4",
3667 &oi
->address
->u
.prefix4
);
3668 json_object_int_add(json_interface_sub
,
3669 "ipAddressPrefixlen",
3670 oi
->address
->prefixlen
);
3672 vty_out(vty
, " Internet Address %pFX,",
3675 /* For Vlinks, showing the peer address is
3676 * probably more informative than the local
3677 * interface that is being used */
3678 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
) {
3680 dest
= oi
->vl_data
->peer_addr
;
3681 } else if (CONNECTED_PEER(oi
->connected
)
3682 && oi
->connected
->destination
) {
3684 dest
= oi
->connected
->destination
->u
.prefix4
;
3687 dest
.s_addr
= ipv4_broadcast_addr(
3688 oi
->connected
->address
->u
.prefix4
.s_addr
,
3689 oi
->connected
->address
->prefixlen
);
3693 json_object_string_add(
3695 "ospfIfType", dstr
);
3696 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3697 json_object_string_addf(
3698 json_interface_sub
, "vlinkPeer",
3701 json_object_string_addf(
3703 "localIfUsed", "%pI4", &dest
);
3705 vty_out(vty
, " %s %pI4,", dstr
,
3709 json_object_string_add(json_interface_sub
, "area",
3710 ospf_area_desc_string(oi
->area
));
3711 if (OSPF_IF_PARAM(oi
, mtu_ignore
))
3712 json_object_boolean_true_add(
3714 "mtuMismatchDetect");
3715 json_object_string_addf(json_interface_sub
, "routerId",
3716 "%pI4", &ospf
->router_id
);
3717 json_object_string_add(json_interface_sub
,
3719 ospf_network_type_str
[oi
->type
]);
3720 json_object_int_add(json_interface_sub
, "cost",
3722 json_object_int_add(
3723 json_interface_sub
, "transmitDelaySecs",
3724 OSPF_IF_PARAM(oi
, transmit_delay
));
3725 json_object_string_add(json_interface_sub
, "state",
3726 lookup_msg(ospf_ism_state_msg
,
3728 json_object_int_add(json_interface_sub
, "priority",
3731 vty_out(vty
, " Area %s\n",
3732 ospf_area_desc_string(oi
->area
));
3734 vty_out(vty
, " MTU mismatch detection: %s\n",
3735 OSPF_IF_PARAM(oi
, mtu_ignore
) ? "disabled"
3739 " Router ID %pI4, Network Type %s, Cost: %d\n",
3741 ospf_network_type_str
[oi
->type
],
3745 " Transmit Delay is %d sec, State %s, Priority %d\n",
3746 OSPF_IF_PARAM(oi
, transmit_delay
),
3747 lookup_msg(ospf_ism_state_msg
, oi
->state
, NULL
),
3751 /* Show DR information. */
3752 if (DR(oi
).s_addr
== INADDR_ANY
) {
3755 " No backup designated router on this network\n");
3757 nbr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &DR(oi
));
3760 json_object_string_addf(
3761 json_interface_sub
, "drId",
3762 "%pI4", &nbr
->router_id
);
3763 json_object_string_addf(
3764 json_interface_sub
, "drAddress",
3766 &nbr
->address
.u
.prefix4
);
3769 " Designated Router (ID) %pI4",
3772 " Interface Address %pFX\n",
3778 nbr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &BDR(oi
));
3782 " No backup designated router on this network\n");
3785 json_object_string_addf(
3786 json_interface_sub
, "bdrId",
3787 "%pI4", &nbr
->router_id
);
3788 json_object_string_addf(
3790 "bdrAddress", "%pI4",
3791 &nbr
->address
.u
.prefix4
);
3794 " Backup Designated Router (ID) %pI4,",
3796 vty_out(vty
, " Interface Address %pI4\n",
3797 &nbr
->address
.u
.prefix4
);
3802 /* Next network-LSA sequence number we'll use, if we're elected
3805 && ntohl(oi
->params
->network_lsa_seqnum
)
3806 != OSPF_INITIAL_SEQUENCE_NUMBER
) {
3808 json_object_int_add(
3810 "networkLsaSequence",
3811 ntohl(oi
->params
->network_lsa_seqnum
));
3814 " Saved Network-LSA sequence number 0x%x\n",
3815 ntohl(oi
->params
->network_lsa_seqnum
));
3819 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3820 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3821 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3822 json_object_boolean_true_add(
3824 "mcastMemberOspfAllRouters");
3825 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3826 json_object_boolean_true_add(
3828 "mcastMemberOspfDesignatedRouters");
3831 vty_out(vty
, " Multicast group memberships:");
3832 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3833 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3834 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3835 vty_out(vty
, " OSPFAllRouters");
3836 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3837 vty_out(vty
, " OSPFDesignatedRouters");
3839 vty_out(vty
, " <None>");
3844 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3845 json_object_int_add(
3846 json_interface_sub
, "timerMsecs",
3847 OSPF_IF_PARAM(oi
, v_hello
) * 1000);
3849 json_object_int_add(
3850 json_interface_sub
, "timerMsecs",
3851 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3852 json_object_int_add(json_interface_sub
,
3854 OSPF_IF_PARAM(oi
, v_wait
));
3855 json_object_int_add(json_interface_sub
,
3857 OSPF_IF_PARAM(oi
, v_wait
));
3858 json_object_int_add(
3859 json_interface_sub
, "timerRetransmitSecs",
3860 OSPF_IF_PARAM(oi
, retransmit_interval
));
3862 vty_out(vty
, " Timer intervals configured,");
3863 vty_out(vty
, " Hello ");
3864 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3865 vty_out(vty
, "%ds,",
3866 OSPF_IF_PARAM(oi
, v_hello
));
3868 vty_out(vty
, "%dms,",
3869 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3870 vty_out(vty
, " Dead %ds, Wait %ds, Retransmit %d\n",
3871 OSPF_IF_PARAM(oi
, v_wait
),
3872 OSPF_IF_PARAM(oi
, v_wait
),
3873 OSPF_IF_PARAM(oi
, retransmit_interval
));
3876 if (OSPF_IF_PASSIVE_STATUS(oi
) == OSPF_IF_ACTIVE
) {
3877 char timebuf
[OSPF_TIME_DUMP_SIZE
];
3879 long time_store
= 0;
3883 &oi
->t_hello
->u
.sands
,
3886 json_object_int_add(json_interface_sub
,
3887 "timerHelloInMsecs",
3890 vty_out(vty
, " Hello due in %s\n",
3891 ospf_timer_dump(oi
->t_hello
, timebuf
,
3893 } else /* passive-interface is set */
3896 json_object_boolean_true_add(
3898 "timerPassiveIface");
3901 " No Hellos (Passive interface)\n");
3905 json_object_int_add(json_interface_sub
, "nbrCount",
3906 ospf_nbr_count(oi
, 0));
3907 json_object_int_add(json_interface_sub
,
3909 ospf_nbr_count(oi
, NSM_Full
));
3912 " Neighbor Count is %d, Adjacent neighbor count is %d\n",
3913 ospf_nbr_count(oi
, 0),
3914 ospf_nbr_count(oi
, NSM_Full
));
3916 ospf_interface_bfd_show(vty
, ifp
, json_interface_sub
);
3918 /* OSPF Authentication information */
3919 ospf_interface_auth_show(vty
, oi
, json_interface_sub
, use_json
);
3923 static int show_ip_ospf_interface_common(struct vty
*vty
, struct ospf
*ospf
,
3924 char *intf_name
, uint8_t use_vrf
,
3925 json_object
*json
, bool use_json
)
3927 struct interface
*ifp
;
3928 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
3929 json_object
*json_vrf
= NULL
;
3930 json_object
*json_interface_sub
= NULL
, *json_interface
= NULL
;
3934 json_vrf
= json_object_new_object();
3937 json_interface
= json_object_new_object();
3940 if (ospf
->instance
) {
3942 json_object_int_add(json
, "ospfInstance",
3945 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
3948 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3950 if (intf_name
== NULL
) {
3951 /* Show All Interfaces.*/
3952 FOR_ALL_INTERFACES (vrf
, ifp
) {
3953 if (ospf_oi_count(ifp
)) {
3955 json_interface_sub
=
3956 json_object_new_object();
3958 show_ip_ospf_interface_sub(vty
, ospf
, ifp
,
3963 json_object_object_add(
3964 json_interface
, ifp
->name
,
3965 json_interface_sub
);
3970 json_object_object_add(json_vrf
, "interfaces",
3973 /* Interface name is specified. */
3974 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
3977 json_object_boolean_true_add(json_vrf
,
3980 vty_out(vty
, "No such interface name\n");
3983 json_interface_sub
= json_object_new_object();
3984 json_interface
= json_object_new_object();
3987 show_ip_ospf_interface_sub(
3988 vty
, ospf
, ifp
, json_interface_sub
, use_json
);
3991 json_object_object_add(json_interface
,
3993 json_interface_sub
);
3994 json_object_object_add(json_vrf
, "interfaces",
4002 json_object_object_add(json
, ospf_get_name(ospf
),
4011 static void show_ip_ospf_interface_traffic_sub(struct vty
*vty
,
4012 struct ospf_interface
*oi
,
4013 json_object
*json_interface_sub
,
4017 json_object_int_add(json_interface_sub
, "ifIndex",
4019 json_object_int_add(json_interface_sub
, "helloIn",
4021 json_object_int_add(json_interface_sub
, "helloOut",
4023 json_object_int_add(json_interface_sub
, "dbDescIn",
4025 json_object_int_add(json_interface_sub
, "dbDescOut",
4027 json_object_int_add(json_interface_sub
, "lsReqIn",
4029 json_object_int_add(json_interface_sub
, "lsReqOut",
4031 json_object_int_add(json_interface_sub
, "lsUpdIn",
4033 json_object_int_add(json_interface_sub
, "lsUpdOut",
4035 json_object_int_add(json_interface_sub
, "lsAckIn",
4037 json_object_int_add(json_interface_sub
, "lsAckOut",
4039 json_object_int_add(json_interface_sub
, "packetsQueued",
4040 listcount(oi
->obuf
));
4043 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u %12lu\n",
4044 oi
->ifp
->name
, oi
->hello_in
, oi
->hello_out
,
4045 oi
->db_desc_in
, oi
->db_desc_out
, oi
->ls_req_in
,
4046 oi
->ls_req_out
, oi
->ls_upd_in
, oi
->ls_upd_out
,
4047 oi
->ls_ack_in
, oi
->ls_ack_out
, listcount(oi
->obuf
));
4051 /* OSPFv2 Packet Counters */
4052 static int show_ip_ospf_interface_traffic_common(
4053 struct vty
*vty
, struct ospf
*ospf
, char *intf_name
, json_object
*json
,
4054 int display_once
, uint8_t use_vrf
, bool use_json
)
4056 struct vrf
*vrf
= NULL
;
4057 struct interface
*ifp
= NULL
;
4058 json_object
*json_vrf
= NULL
;
4059 json_object
*json_interface_sub
= NULL
;
4061 if (!use_json
&& !display_once
) {
4063 vty_out(vty
, "%-12s%-17s%-17s%-17s%-17s%-17s%-17s\n",
4064 "Interface", " HELLO", " DB-Desc", " LS-Req",
4065 " LS-Update", " LS-Ack", " Packets");
4066 vty_out(vty
, "%-10s%-18s%-18s%-17s%-17s%-17s%-17s\n", "",
4067 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
4068 " Rx/Tx", " Queued");
4070 "-------------------------------------------------------------------------------------------------------------\n");
4071 } else if (use_json
) {
4073 json_vrf
= json_object_new_object();
4078 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4080 if (intf_name
== NULL
) {
4081 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
4082 FOR_ALL_INTERFACES (vrf
, ifp
) {
4083 struct route_node
*rn
;
4084 struct ospf_interface
*oi
;
4086 if (ospf_oi_count(ifp
) == 0)
4089 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
4090 rn
= route_next(rn
)) {
4097 json_interface_sub
=
4098 json_object_new_object();
4101 show_ip_ospf_interface_traffic_sub(
4102 vty
, oi
, json_interface_sub
, use_json
);
4104 json_object_object_add(
4105 json_vrf
, ifp
->name
,
4106 json_interface_sub
);
4111 /* Interface name is specified. */
4112 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
4114 struct route_node
*rn
;
4115 struct ospf_interface
*oi
;
4117 if (ospf_oi_count(ifp
) == 0) {
4119 " OSPF not enabled on this interface %s\n",
4124 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
4125 rn
= route_next(rn
)) {
4129 json_interface_sub
=
4130 json_object_new_object();
4133 show_ip_ospf_interface_traffic_sub(
4134 vty
, oi
, json_interface_sub
, use_json
);
4136 json_object_object_add(
4137 json_vrf
, ifp
->name
,
4138 json_interface_sub
);
4146 json_object_object_add(json
, ospf_get_name(ospf
),
4154 DEFUN (show_ip_ospf_interface
,
4155 show_ip_ospf_interface_cmd
,
4156 "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]",
4159 "OSPF information\n"
4162 "Interface information\n"
4167 bool uj
= use_json(argc
, argv
);
4168 struct listnode
*node
= NULL
;
4169 char *vrf_name
= NULL
, *intf_name
= NULL
;
4170 bool all_vrf
= false;
4171 int ret
= CMD_SUCCESS
;
4173 int idx_vrf
= 0, idx_intf
= 0;
4174 uint8_t use_vrf
= 0;
4175 json_object
*json
= NULL
;
4177 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4179 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4180 intf_name
= argv
[idx_intf
]->arg
;
4183 json
= json_object_new_object();
4185 /* vrf input is provided could be all or specific vrf*/
4189 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4190 if (!ospf
->oi_running
)
4192 ret
= show_ip_ospf_interface_common(
4193 vty
, ospf
, intf_name
, use_vrf
, json
,
4198 vty_json(vty
, json
);
4200 vty_out(vty
, "%% OSPF is not enabled\n");
4204 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4205 if (ospf
== NULL
|| !ospf
->oi_running
) {
4207 vty_json(vty
, json
);
4210 "%% OSPF is not enabled in vrf %s\n",
4215 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
4219 /* Display default ospf (instance 0) info */
4220 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4221 if (ospf
== NULL
|| !ospf
->oi_running
) {
4223 vty_json(vty
, json
);
4226 "%% OSPF is not enabled in vrf default\n");
4230 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
4235 vty_json(vty
, json
);
4240 DEFUN (show_ip_ospf_instance_interface
,
4241 show_ip_ospf_instance_interface_cmd
,
4242 "show ip ospf (1-65535) interface [INTERFACE] [json]",
4245 "OSPF information\n"
4247 "Interface information\n"
4254 unsigned short instance
= 0;
4255 bool uj
= use_json(argc
, argv
);
4256 char *intf_name
= NULL
;
4257 int ret
= CMD_SUCCESS
;
4258 json_object
*json
= NULL
;
4260 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4261 if (instance
!= ospf_instance
)
4262 return CMD_NOT_MY_INSTANCE
;
4264 ospf
= ospf_lookup_instance(instance
);
4265 if (!ospf
|| !ospf
->oi_running
)
4269 json
= json_object_new_object();
4271 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4272 intf_name
= argv
[idx_intf
]->arg
;
4274 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
, 0, json
, uj
);
4277 vty_json(vty
, json
);
4282 DEFUN (show_ip_ospf_interface_traffic
,
4283 show_ip_ospf_interface_traffic_cmd
,
4284 "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]",
4287 "OSPF information\n"
4290 "Interface information\n"
4291 "Protocol Packet counters\n"
4295 struct ospf
*ospf
= NULL
;
4296 struct listnode
*node
= NULL
;
4297 char *vrf_name
= NULL
, *intf_name
= NULL
;
4298 bool all_vrf
= false;
4300 int idx_vrf
= 0, idx_intf
= 0;
4301 bool uj
= use_json(argc
, argv
);
4302 json_object
*json
= NULL
;
4303 int ret
= CMD_SUCCESS
;
4304 int display_once
= 0;
4305 uint8_t use_vrf
= 0;
4307 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4309 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4310 intf_name
= argv
[idx_intf
]->arg
;
4313 json
= json_object_new_object();
4318 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4319 if (!ospf
->oi_running
)
4322 ret
= show_ip_ospf_interface_traffic_common(
4323 vty
, ospf
, intf_name
, json
,
4324 display_once
, use_vrf
, uj
);
4329 vty_json(vty
, json
);
4333 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4334 if (ospf
== NULL
|| !ospf
->oi_running
) {
4336 json_object_free(json
);
4340 ret
= show_ip_ospf_interface_traffic_common(
4341 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4343 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4344 if (ospf
== NULL
|| !ospf
->oi_running
) {
4346 json_object_free(json
);
4350 ret
= show_ip_ospf_interface_traffic_common(
4351 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4355 vty_json(vty
, json
);
4361 static void show_ip_ospf_neighbour_header(struct vty
*vty
)
4363 vty_out(vty
, "\n%-15s %-3s %-15s %-15s %-9s %-15s %-32s %5s %5s %5s\n",
4364 "Neighbor ID", "Pri", "State", "Up Time", "Dead Time",
4365 "Address", "Interface", "RXmtL", "RqstL", "DBsmL");
4368 static void show_ip_ospf_neighbour_brief(struct vty
*vty
,
4369 struct ospf_neighbor
*nbr
,
4370 struct ospf_neighbor
*prev_nbr
,
4371 json_object
*json
, bool use_json
)
4374 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4375 json_object
*json_neighbor
= NULL
, *json_neigh_array
= NULL
;
4376 struct timeval res
= {.tv_sec
= 0, .tv_usec
= 0};
4378 char uptime
[OSPF_TIME_DUMP_SIZE
];
4380 if (nbr
->ts_last_progress
.tv_sec
|| nbr
->ts_last_progress
.tv_usec
)
4382 monotime_since(&nbr
->ts_last_progress
, &res
) / 1000LL;
4385 char neigh_str
[INET_ADDRSTRLEN
];
4387 if (prev_nbr
&& !IPV4_ADDR_SAME(&prev_nbr
->src
, &nbr
->src
)) {
4388 /* Start new neigh list */
4389 json_neigh_array
= NULL
;
4392 if (nbr
->state
== NSM_Attempt
&&
4393 nbr
->router_id
.s_addr
== INADDR_ANY
)
4394 strlcpy(neigh_str
, "neighbor", sizeof(neigh_str
));
4396 inet_ntop(AF_INET
, &nbr
->router_id
, neigh_str
,
4399 json_object_object_get_ex(json
, neigh_str
, &json_neigh_array
);
4401 if (!json_neigh_array
) {
4402 json_neigh_array
= json_object_new_array();
4403 json_object_object_add(json
, neigh_str
,
4407 json_neighbor
= json_object_new_object();
4409 ospf_nbr_ism_state_message(nbr
, msgbuf
, sizeof(msgbuf
));
4410 #if CONFDATE > 20230321
4412 "Remove show_ip_ospf_neighbor_sub() JSON keys: priority, state, deadTimeMsecs, address, retransmitCounter, requestCounter, dbSummaryCounter")
4414 json_object_int_add(json_neighbor
, "priority", nbr
->priority
);
4415 json_object_string_add(json_neighbor
, "state", msgbuf
);
4416 json_object_int_add(json_neighbor
, "nbrPriority",
4418 json_object_string_add(json_neighbor
, "nbrState", msgbuf
);
4420 json_object_string_add(
4421 json_neighbor
, "converged",
4422 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
4423 json_object_string_add(json_neighbor
, "role",
4424 lookup_msg(ospf_ism_state_msg
,
4425 ospf_nbr_ism_state(nbr
),
4427 if (nbr
->t_inactivity
) {
4430 time_store
= monotime_until(&nbr
->t_inactivity
->u
.sands
,
4433 json_object_int_add(json_neighbor
, "upTimeInMsec",
4435 json_object_int_add(json_neighbor
, "deadTimeMsecs",
4437 json_object_int_add(json_neighbor
,
4438 "routerDeadIntervalTimerDueMsec",
4440 json_object_string_add(
4441 json_neighbor
, "upTime",
4442 ospf_timeval_dump(&res
, uptime
,
4444 json_object_string_add(
4445 json_neighbor
, "deadTime",
4446 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
4449 json_object_string_add(json_neighbor
, "deadTimeMsecs",
4451 json_object_string_add(json_neighbor
,
4452 "routerDeadIntervalTimerDueMsec",
4455 json_object_string_addf(json_neighbor
, "address", "%pI4",
4457 json_object_string_addf(json_neighbor
, "ifaceAddress", "%pI4",
4459 json_object_string_add(json_neighbor
, "ifaceName",
4461 json_object_int_add(json_neighbor
, "retransmitCounter",
4462 ospf_ls_retransmit_count(nbr
));
4463 json_object_int_add(json_neighbor
,
4464 "linkStateRetransmissionListCounter",
4465 ospf_ls_retransmit_count(nbr
));
4466 json_object_int_add(json_neighbor
, "requestCounter",
4467 ospf_ls_request_count(nbr
));
4468 json_object_int_add(json_neighbor
,
4469 "linkStateRequestListCounter",
4470 ospf_ls_request_count(nbr
));
4471 json_object_int_add(json_neighbor
, "dbSummaryCounter",
4472 ospf_db_summary_count(nbr
));
4473 json_object_int_add(json_neighbor
, "databaseSummaryListCounter",
4474 ospf_db_summary_count(nbr
));
4476 json_object_array_add(json_neigh_array
, json_neighbor
);
4478 ospf_nbr_ism_state_message(nbr
, msgbuf
, sizeof(msgbuf
));
4480 if (nbr
->state
== NSM_Attempt
&&
4481 nbr
->router_id
.s_addr
== INADDR_ANY
)
4482 vty_out(vty
, "%-15s %3d %-15s ", "-", nbr
->priority
,
4485 vty_out(vty
, "%-15pI4 %3d %-15s ", &nbr
->router_id
,
4486 nbr
->priority
, msgbuf
);
4488 vty_out(vty
, "%-15s ",
4489 ospf_timeval_dump(&res
, uptime
, sizeof(uptime
)));
4491 vty_out(vty
, "%9s ",
4492 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
4494 vty_out(vty
, "%-15pI4 ", &nbr
->src
);
4495 vty_out(vty
, "%-32s %5ld %5ld %5d\n", IF_NAME(nbr
->oi
),
4496 ospf_ls_retransmit_count(nbr
),
4497 ospf_ls_request_count(nbr
), ospf_db_summary_count(nbr
));
4501 static void show_ip_ospf_neighbor_sub(struct vty
*vty
,
4502 struct ospf_interface
*oi
,
4503 json_object
*json
, bool use_json
)
4505 struct route_node
*rn
;
4506 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
4508 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
4514 /* Do not show myself. */
4515 if (nbr
== oi
->nbr_self
)
4517 /* Down state is not shown. */
4518 if (nbr
->state
== NSM_Down
)
4523 show_ip_ospf_neighbour_brief(vty
, nbr
, prev_nbr
, json
,
4528 static int show_ip_ospf_neighbor_common(struct vty
*vty
, struct ospf
*ospf
,
4529 json_object
*json
, bool use_json
,
4532 struct ospf_interface
*oi
;
4533 struct listnode
*node
;
4534 json_object
*json_vrf
= NULL
;
4535 json_object
*json_nbr_sub
= NULL
;
4539 json_vrf
= json_object_new_object();
4542 json_nbr_sub
= json_object_new_object();
4545 if (ospf
->instance
) {
4547 json_object_int_add(json
, "ospfInstance",
4550 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4553 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4555 show_ip_ospf_neighbour_header(vty
);
4557 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4558 if (ospf_interface_neighbor_count(oi
) == 0)
4560 show_ip_ospf_neighbor_sub(vty
, oi
, json_nbr_sub
, use_json
);
4564 json_object_object_add(json_vrf
, "neighbors", json_nbr_sub
);
4566 json_object_object_add(json
, ospf_get_name(ospf
),
4574 DEFUN (show_ip_ospf_neighbor
,
4575 show_ip_ospf_neighbor_cmd
,
4576 "show ip ospf [vrf <NAME|all>] neighbor [json]",
4579 "OSPF information\n"
4586 bool uj
= use_json(argc
, argv
);
4587 struct listnode
*node
= NULL
;
4588 char *vrf_name
= NULL
;
4589 bool all_vrf
= false;
4590 int ret
= CMD_SUCCESS
;
4593 uint8_t use_vrf
= 0;
4594 json_object
*json
= NULL
;
4596 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4599 json
= json_object_new_object();
4601 /* vrf input is provided could be all or specific vrf*/
4605 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4606 if (!ospf
->oi_running
)
4608 ret
= show_ip_ospf_neighbor_common(
4609 vty
, ospf
, json
, uj
, use_vrf
);
4613 vty_json(vty
, json
);
4615 vty_out(vty
, "OSPF is not enabled\n");
4620 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4621 if (ospf
== NULL
|| !ospf
->oi_running
) {
4623 vty_json(vty
, json
);
4626 "%% OSPF is not enabled in vrf %s\n",
4632 /* Display default ospf (instance 0) info */
4633 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4634 if (ospf
== NULL
|| !ospf
->oi_running
) {
4636 vty_json(vty
, json
);
4639 "%% OSPF is not enabled in vrf default\n");
4646 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
,
4650 vty_out(vty
, "%s\n",
4651 json_object_to_json_string_ext(
4652 json
, JSON_C_TO_STRING_PRETTY
));
4657 json_object_free(json
);
4663 DEFUN (show_ip_ospf_instance_neighbor
,
4664 show_ip_ospf_instance_neighbor_cmd
,
4665 "show ip ospf (1-65535) neighbor [json]",
4668 "OSPF information\n"
4675 unsigned short instance
= 0;
4676 bool uj
= use_json(argc
, argv
);
4677 json_object
*json
= NULL
;
4678 int ret
= CMD_SUCCESS
;
4680 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4681 if (instance
!= ospf_instance
)
4682 return CMD_NOT_MY_INSTANCE
;
4684 ospf
= ospf_lookup_instance(instance
);
4685 if (!ospf
|| !ospf
->oi_running
)
4689 json
= json_object_new_object();
4691 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
, 0);
4694 vty_json(vty
, json
);
4699 static int show_ip_ospf_neighbor_all_common(struct vty
*vty
, struct ospf
*ospf
,
4700 json_object
*json
, bool use_json
,
4703 struct listnode
*node
;
4704 struct ospf_interface
*oi
;
4705 char buf
[PREFIX_STRLEN
];
4706 json_object
*json_vrf
= NULL
;
4707 json_object
*json_neighbor_sub
= NULL
;
4711 json_vrf
= json_object_new_object();
4716 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4718 show_ip_ospf_neighbour_header(vty
);
4720 if (ospf
->instance
) {
4722 json_object_int_add(json_vrf
, "ospfInstance",
4725 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4728 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4729 struct listnode
*nbr_node
;
4730 struct ospf_nbr_nbma
*nbr_nbma
;
4732 show_ip_ospf_neighbor_sub(vty
, oi
, json_vrf
, use_json
);
4734 /* print Down neighbor status */
4735 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nbr_node
, nbr_nbma
)) {
4736 if (nbr_nbma
->nbr
== NULL
4737 || nbr_nbma
->nbr
->state
== NSM_Down
) {
4740 json_object_new_object();
4741 json_object_int_add(json_neighbor_sub
,
4743 nbr_nbma
->priority
);
4744 json_object_boolean_true_add(
4747 json_object_string_add(
4751 json_object_int_add(
4753 "nbrNbmaRetransmitCounter", 0);
4754 json_object_int_add(
4756 "nbrNbmaRequestCounter", 0);
4757 json_object_int_add(
4759 "nbrNbmaDbSummaryCounter", 0);
4760 json_object_object_add(
4763 &nbr_nbma
->addr
, buf
,
4767 vty_out(vty
, "%-15s %3d %-15s %9s ",
4768 "-", nbr_nbma
->priority
, "Down",
4771 "%-32pI4 %-20s %5d %5d %5d\n",
4773 IF_NAME(oi
), 0, 0, 0);
4781 json_object_object_add(json
, ospf_get_name(ospf
),
4789 DEFUN (show_ip_ospf_neighbor_all
,
4790 show_ip_ospf_neighbor_all_cmd
,
4791 "show ip ospf [vrf <NAME|all>] neighbor all [json]",
4794 "OSPF information\n"
4798 "include down status neighbor\n"
4802 bool uj
= use_json(argc
, argv
);
4803 struct listnode
*node
= NULL
;
4804 char *vrf_name
= NULL
;
4805 bool all_vrf
= false;
4806 int ret
= CMD_SUCCESS
;
4809 uint8_t use_vrf
= 0;
4810 json_object
*json
= NULL
;
4812 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4815 json
= json_object_new_object();
4817 /* vrf input is provided could be all or specific vrf*/
4821 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4822 if (!ospf
->oi_running
)
4824 ret
= show_ip_ospf_neighbor_all_common(
4825 vty
, ospf
, json
, uj
, use_vrf
);
4829 vty_json(vty
, json
);
4834 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4835 if (ospf
== NULL
|| !ospf
->oi_running
) {
4837 json_object_free(json
);
4841 /* Display default ospf (instance 0) info */
4842 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4843 if (ospf
== NULL
|| !ospf
->oi_running
) {
4845 json_object_free(json
);
4851 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
,
4854 vty_out(vty
, "%s\n",
4855 json_object_to_json_string_ext(
4856 json
, JSON_C_TO_STRING_PRETTY
));
4861 json_object_free(json
);
4866 DEFUN (show_ip_ospf_instance_neighbor_all
,
4867 show_ip_ospf_instance_neighbor_all_cmd
,
4868 "show ip ospf (1-65535) neighbor all [json]",
4871 "OSPF information\n"
4874 "include down status neighbor\n"
4879 unsigned short instance
= 0;
4880 bool uj
= use_json(argc
, argv
);
4881 json_object
*json
= NULL
;
4882 int ret
= CMD_SUCCESS
;
4884 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4885 if (instance
!= ospf_instance
)
4886 return CMD_NOT_MY_INSTANCE
;
4888 ospf
= ospf_lookup_instance(instance
);
4889 if (!ospf
|| !ospf
->oi_running
)
4892 json
= json_object_new_object();
4894 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
, 0);
4897 vty_json(vty
, json
);
4902 static int show_ip_ospf_neighbor_int_common(struct vty
*vty
, struct ospf
*ospf
,
4903 const char *ifname
, bool use_json
,
4906 struct interface
*ifp
;
4907 struct route_node
*rn
;
4908 json_object
*json
= NULL
;
4911 json
= json_object_new_object();
4913 if (ospf
->instance
) {
4915 json_object_int_add(json
, "ospfInstance",
4918 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4921 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
4923 ifp
= if_lookup_by_name(ifname
, ospf
->vrf_id
);
4926 json_object_boolean_true_add(json
, "noSuchIface");
4928 vty_out(vty
, "No such interface.\n");
4932 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
4933 struct ospf_interface
*oi
= rn
->info
;
4938 show_ip_ospf_neighbor_sub(vty
, oi
, json
, use_json
);
4942 vty_json(vty
, json
);
4949 DEFPY(show_ip_ospf_instance_neighbor_int
,
4950 show_ip_ospf_instance_neighbor_int_cmd
,
4951 "show ip ospf (1-65535)$instance neighbor IFNAME$ifname [json$json]",
4954 "OSPF information\n"
4963 show_ip_ospf_neighbour_header(vty
);
4965 if (instance
!= ospf_instance
)
4966 return CMD_NOT_MY_INSTANCE
;
4968 ospf
= ospf_lookup_instance(instance
);
4969 if (!ospf
|| !ospf
->oi_running
)
4973 show_ip_ospf_neighbour_header(vty
);
4975 return show_ip_ospf_neighbor_int_common(vty
, ospf
, ifname
, !!json
, 0);
4978 static void show_ip_ospf_nbr_nbma_detail_sub(struct vty
*vty
,
4979 struct ospf_interface
*oi
,
4980 struct ospf_nbr_nbma
*nbr_nbma
,
4981 bool use_json
, json_object
*json
)
4983 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4984 json_object
*json_sub
= NULL
;
4987 json_sub
= json_object_new_object();
4988 else /* Show neighbor ID. */
4989 vty_out(vty
, " Neighbor %s,", "-");
4991 /* Show interface address. */
4993 json_object_string_addf(json_sub
, "ifaceAddress", "%pI4",
4996 vty_out(vty
, " interface address %pI4\n",
5001 json_object_string_add(json_sub
, "areaId",
5002 ospf_area_desc_string(oi
->area
));
5003 json_object_string_add(json_sub
, "iface", IF_NAME(oi
));
5005 vty_out(vty
, " In the area %s via interface %s\n",
5006 ospf_area_desc_string(oi
->area
), IF_NAME(oi
));
5008 /* Show neighbor priority and state. */
5010 json_object_int_add(json_sub
, "nbrPriority",
5011 nbr_nbma
->priority
);
5012 json_object_string_add(json_sub
, "nbrState", "down");
5014 vty_out(vty
, " Neighbor priority is %d, State is %s,",
5015 nbr_nbma
->priority
, "Down");
5017 /* Show state changes. */
5019 json_object_int_add(json_sub
, "stateChangeCounter",
5020 nbr_nbma
->state_change
);
5022 vty_out(vty
, " %d state changes\n", nbr_nbma
->state_change
);
5024 /* Show PollInterval */
5026 json_object_int_add(json_sub
, "pollInterval", nbr_nbma
->v_poll
);
5028 vty_out(vty
, " Poll interval %d\n", nbr_nbma
->v_poll
);
5030 /* Show poll-interval timer. */
5031 if (nbr_nbma
->t_poll
) {
5034 time_store
= monotime_until(&nbr_nbma
->t_poll
->u
.sands
,
5036 json_object_int_add(json_sub
,
5037 "pollIntervalTimerDueMsec",
5040 vty_out(vty
, " Poll timer due in %s\n",
5041 ospf_timer_dump(nbr_nbma
->t_poll
, timebuf
,
5045 /* Show poll-interval timer thread. */
5047 if (nbr_nbma
->t_poll
!= NULL
)
5048 json_object_string_add(json_sub
,
5049 "pollIntervalTimerThread", "on");
5051 vty_out(vty
, " Thread Poll Timer %s\n",
5052 nbr_nbma
->t_poll
!= NULL
? "on" : "off");
5055 json_object_object_add(json
, "noNbrId", json_sub
);
5058 static void show_ip_ospf_neighbor_detail_sub(struct vty
*vty
,
5059 struct ospf_interface
*oi
,
5060 struct ospf_neighbor
*nbr
,
5061 struct ospf_neighbor
*prev_nbr
,
5062 json_object
*json
, bool use_json
)
5064 char timebuf
[OSPF_TIME_DUMP_SIZE
];
5065 json_object
*json_neigh
= NULL
, *json_neigh_array
= NULL
;
5066 char neigh_str
[INET_ADDRSTRLEN
] = {0};
5067 char neigh_state
[16] = {0};
5071 !IPV4_ADDR_SAME(&prev_nbr
->src
, &nbr
->src
)) {
5072 json_neigh_array
= NULL
;
5075 if (nbr
->state
== NSM_Attempt
5076 && nbr
->router_id
.s_addr
== INADDR_ANY
)
5077 strlcpy(neigh_str
, "noNbrId", sizeof(neigh_str
));
5079 inet_ntop(AF_INET
, &nbr
->router_id
,
5080 neigh_str
, sizeof(neigh_str
));
5082 json_object_object_get_ex(json
, neigh_str
, &json_neigh_array
);
5084 if (!json_neigh_array
) {
5085 json_neigh_array
= json_object_new_array();
5086 json_object_object_add(json
, neigh_str
,
5090 json_neigh
= json_object_new_object();
5093 /* Show neighbor ID. */
5094 if (nbr
->state
== NSM_Attempt
5095 && nbr
->router_id
.s_addr
== INADDR_ANY
)
5096 vty_out(vty
, " Neighbor %s,", "-");
5098 vty_out(vty
, " Neighbor %pI4,",
5102 /* Show interface address. */
5104 json_object_string_addf(json_neigh
, "ifaceAddress", "%pI4",
5105 &nbr
->address
.u
.prefix4
);
5107 vty_out(vty
, " interface address %pI4\n",
5108 &nbr
->address
.u
.prefix4
);
5112 json_object_string_add(json_neigh
, "areaId",
5113 ospf_area_desc_string(oi
->area
));
5114 json_object_string_add(json_neigh
, "ifaceName", oi
->ifp
->name
);
5116 json_object_string_addf(json_neigh
, "localIfaceAddress",
5118 &oi
->address
->u
.prefix4
);
5120 vty_out(vty
, " In the area %s via interface %s",
5121 ospf_area_desc_string(oi
->area
), oi
->ifp
->name
);
5123 vty_out(vty
, " local interface IP %pI4\n",
5124 &oi
->address
->u
.prefix4
);
5129 /* Show neighbor priority and state. */
5130 ospf_nbr_ism_state_message(nbr
, neigh_state
, sizeof(neigh_state
));
5132 json_object_int_add(json_neigh
, "nbrPriority", nbr
->priority
);
5133 json_object_string_add(json_neigh
, "nbrState", neigh_state
);
5134 json_object_string_add(json_neigh
, "role",
5135 lookup_msg(ospf_ism_state_msg
,
5136 ospf_nbr_ism_state(nbr
),
5140 " Neighbor priority is %d, State is %s, Role is %s,",
5141 nbr
->priority
, neigh_state
,
5142 lookup_msg(ospf_ism_state_msg
, ospf_nbr_ism_state(nbr
),
5145 /* Show state changes. */
5147 json_object_int_add(json_neigh
, "stateChangeCounter",
5150 vty_out(vty
, " %d state changes\n", nbr
->state_change
);
5152 if (nbr
->ts_last_progress
.tv_sec
|| nbr
->ts_last_progress
.tv_usec
) {
5157 monotime_since(&nbr
->ts_last_progress
, &res
) / 1000LL;
5159 json_object_int_add(json_neigh
, "lastPrgrsvChangeMsec",
5163 " Most recent state change statistics:\n");
5164 vty_out(vty
, " Progressive change %s ago\n",
5165 ospf_timeval_dump(&res
, timebuf
,
5170 if (nbr
->ts_last_regress
.tv_sec
|| nbr
->ts_last_regress
.tv_usec
) {
5175 monotime_since(&nbr
->ts_last_regress
, &res
) / 1000LL;
5177 json_object_int_add(json_neigh
,
5178 "lastRegressiveChangeMsec",
5180 if (nbr
->last_regress_str
)
5181 json_object_string_add(
5183 "lastRegressiveChangeReason",
5184 nbr
->last_regress_str
);
5187 " Regressive change %s ago, due to %s\n",
5188 ospf_timeval_dump(&res
, timebuf
,
5190 (nbr
->last_regress_str
? nbr
->last_regress_str
5195 /* Show Designated Rotuer ID. */
5197 json_object_string_addf(json_neigh
, "routerDesignatedId",
5198 "%pI4", &nbr
->d_router
);
5200 vty_out(vty
, " DR is %pI4,", &nbr
->d_router
);
5202 /* Show Backup Designated Rotuer ID. */
5204 json_object_string_addf(json_neigh
, "routerDesignatedBackupId",
5205 "%pI4", &nbr
->bd_router
);
5207 vty_out(vty
, " BDR is %pI4\n", &nbr
->bd_router
);
5211 json_object_int_add(json_neigh
, "optionsCounter", nbr
->options
);
5212 json_object_string_add(json_neigh
, "optionsList",
5213 ospf_options_dump(nbr
->options
));
5215 vty_out(vty
, " Options %d %s\n", nbr
->options
,
5216 ospf_options_dump(nbr
->options
));
5218 /* Show Router Dead interval timer. */
5220 if (nbr
->t_inactivity
) {
5222 time_store
= monotime_until(&nbr
->t_inactivity
->u
.sands
,
5225 json_object_int_add(json_neigh
,
5226 "routerDeadIntervalTimerDueMsec",
5229 json_object_int_add(
5231 "routerDeadIntervalTimerDueMsec", -1);
5233 vty_out(vty
, " Dead timer due in %s\n",
5234 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
5237 /* Show Database Summary list. */
5239 json_object_int_add(json_neigh
, "databaseSummaryListCounter",
5240 ospf_db_summary_count(nbr
));
5242 vty_out(vty
, " Database Summary List %d\n",
5243 ospf_db_summary_count(nbr
));
5245 /* Show Link State Request list. */
5247 json_object_int_add(json_neigh
, "linkStateRequestListCounter",
5248 ospf_ls_request_count(nbr
));
5250 vty_out(vty
, " Link State Request List %ld\n",
5251 ospf_ls_request_count(nbr
));
5253 /* Show Link State Retransmission list. */
5255 json_object_int_add(json_neigh
,
5256 "linkStateRetransmissionListCounter",
5257 ospf_ls_retransmit_count(nbr
));
5259 vty_out(vty
, " Link State Retransmission List %ld\n",
5260 ospf_ls_retransmit_count(nbr
));
5262 /* Show inactivity timer thread. */
5264 if (nbr
->t_inactivity
!= NULL
)
5265 json_object_string_add(json_neigh
,
5266 "threadInactivityTimer", "on");
5268 vty_out(vty
, " Thread Inactivity Timer %s\n",
5269 nbr
->t_inactivity
!= NULL
? "on" : "off");
5271 /* Show Database Description retransmission thread. */
5273 if (nbr
->t_db_desc
!= NULL
)
5274 json_object_string_add(
5276 "threadDatabaseDescriptionRetransmission",
5280 " Thread Database Description Retransmision %s\n",
5281 nbr
->t_db_desc
!= NULL
? "on" : "off");
5283 /* Show Link State Request Retransmission thread. */
5285 if (nbr
->t_ls_req
!= NULL
)
5286 json_object_string_add(
5288 "threadLinkStateRequestRetransmission", "on");
5291 " Thread Link State Request Retransmission %s\n",
5292 nbr
->t_ls_req
!= NULL
? "on" : "off");
5294 /* Show Link State Update Retransmission thread. */
5296 if (nbr
->t_ls_upd
!= NULL
)
5297 json_object_string_add(
5299 "threadLinkStateUpdateRetransmission",
5303 " Thread Link State Update Retransmission %s\n\n",
5304 nbr
->t_ls_upd
!= NULL
? "on" : "off");
5307 vty_out(vty
, " Graceful restart Helper info:\n");
5309 if (OSPF_GR_IS_ACTIVE_HELPER(nbr
)) {
5311 " Graceful Restart HELPER Status : Inprogress.\n");
5314 " Graceful Restart grace period time: %d (seconds).\n",
5315 nbr
->gr_helper_info
.recvd_grace_period
);
5316 vty_out(vty
, " Graceful Restart reason: %s.\n",
5317 ospf_restart_reason2str(
5318 nbr
->gr_helper_info
.gr_restart_reason
));
5321 " Graceful Restart HELPER Status : None\n");
5324 if (nbr
->gr_helper_info
.rejected_reason
5325 != OSPF_HELPER_REJECTED_NONE
)
5326 vty_out(vty
, " Helper rejected reason: %s.\n",
5327 ospf_rejected_reason2str(
5328 nbr
->gr_helper_info
.rejected_reason
));
5330 if (nbr
->gr_helper_info
.helper_exit_reason
5331 != OSPF_GR_HELPER_EXIT_NONE
)
5332 vty_out(vty
, " Last helper exit reason: %s.\n\n",
5333 ospf_exit_reason2str(
5334 nbr
->gr_helper_info
.helper_exit_reason
));
5338 json_object_string_add(json_neigh
, "grHelperStatus",
5339 OSPF_GR_IS_ACTIVE_HELPER(nbr
) ?
5342 if (OSPF_GR_IS_ACTIVE_HELPER(nbr
)) {
5343 json_object_int_add(
5344 json_neigh
, "graceInterval",
5345 nbr
->gr_helper_info
.recvd_grace_period
);
5346 json_object_string_add(
5347 json_neigh
, "grRestartReason",
5348 ospf_restart_reason2str(
5349 nbr
->gr_helper_info
.gr_restart_reason
));
5352 if (nbr
->gr_helper_info
.rejected_reason
5353 != OSPF_HELPER_REJECTED_NONE
)
5354 json_object_string_add(
5355 json_neigh
, "helperRejectReason",
5356 ospf_rejected_reason2str(
5357 nbr
->gr_helper_info
.rejected_reason
));
5359 if (nbr
->gr_helper_info
.helper_exit_reason
5360 != OSPF_GR_HELPER_EXIT_NONE
)
5361 json_object_string_add(
5362 json_neigh
, "helperExitReason",
5363 ospf_exit_reason2str(
5365 .helper_exit_reason
));
5368 bfd_sess_show(vty
, json_neigh
, nbr
->bfd_session
);
5371 json_object_array_add(json_neigh_array
, json_neigh
);
5375 static int show_ip_ospf_neighbor_id_common(struct vty
*vty
, struct ospf
*ospf
,
5376 struct in_addr
*router_id
,
5377 bool use_json
, uint8_t use_vrf
,
5379 json_object
*json_vrf
)
5381 struct listnode
*node
;
5382 struct ospf_neighbor
*nbr
;
5383 struct ospf_interface
*oi
;
5384 json_object
*json
= NULL
;
5387 json
= json_object_new_object();
5389 if (ospf
->instance
) {
5391 json_object_int_add(json
, "ospfInstance",
5394 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5397 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
5399 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5400 nbr
= ospf_nbr_lookup_by_routerid(oi
->nbrs
, router_id
);
5406 show_ip_ospf_neighbor_detail_sub(vty
, oi
, nbr
, NULL
,
5409 show_ip_ospf_neighbour_brief(vty
, nbr
, NULL
, json
,
5413 if (json_vrf
&& use_json
) {
5414 json_object_object_add(
5416 (ospf
->vrf_id
== VRF_DEFAULT
) ? "default" : ospf
->name
,
5422 vty_json(vty
, json
);
5429 DEFPY(show_ip_ospf_neighbor_id
,
5430 show_ip_ospf_neighbor_id_cmd
,
5431 "show ip ospf [vrf NAME$vrf_name] neighbor A.B.C.D$router_id [detail$detail] [json$json]",
5434 "OSPF information\n"
5442 struct listnode
*node
;
5443 int ret
= CMD_SUCCESS
;
5446 if (vrf_name
&& !strmatch(vrf_name
, "all")) {
5447 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5448 if (ospf
== NULL
|| !ospf
->oi_running
) {
5451 "%% OSPF is not enabled in vrf %s\n",
5454 vty_json_empty(vty
);
5457 ret
= show_ip_ospf_neighbor_id_common(
5458 vty
, ospf
, &router_id
, !!json
, 0, !!detail
, NULL
);
5460 json_object
*json_vrf
= NULL
;
5463 json_vrf
= json_object_new_object();
5464 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5465 if (!ospf
->oi_running
)
5467 ret
= show_ip_ospf_neighbor_id_common(
5468 vty
, ospf
, &router_id
, !!json
, 0, !!detail
,
5472 vty_json(vty
, json_vrf
);
5478 DEFPY(show_ip_ospf_instance_neighbor_id
, show_ip_ospf_instance_neighbor_id_cmd
,
5479 "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [detail$detail] [json$json]",
5481 "OSPF information\n"
5485 "Detailed output\n" JSON_STR
)
5489 if (instance
!= ospf_instance
)
5490 return CMD_NOT_MY_INSTANCE
;
5492 ospf
= ospf_lookup_instance(instance
);
5493 if (!ospf
|| !ospf
->oi_running
)
5496 return show_ip_ospf_neighbor_id_common(vty
, ospf
, &router_id
, !!json
, 0,
5500 static int show_ip_ospf_neighbor_detail_common(struct vty
*vty
,
5502 json_object
*json
, bool use_json
,
5505 struct ospf_interface
*oi
;
5506 struct listnode
*node
;
5507 json_object
*json_vrf
= NULL
;
5508 json_object
*json_nbr_sub
= NULL
;
5512 json_vrf
= json_object_new_object();
5516 json_nbr_sub
= json_object_new_object();
5519 if (ospf
->instance
) {
5521 json_object_int_add(json
, "ospfInstance",
5524 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5527 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5529 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5530 struct route_node
*rn
;
5531 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
5533 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5539 if (nbr
!= oi
->nbr_self
) {
5540 if (nbr
->state
!= NSM_Down
) {
5541 show_ip_ospf_neighbor_detail_sub(
5542 vty
, oi
, nbr
, prev_nbr
,
5543 json_nbr_sub
, use_json
);
5551 json_object_object_add(json_vrf
, "neighbors",
5554 json_object_object_add(json
, ospf_get_name(ospf
),
5562 DEFPY(show_ip_ospf_neighbor_detail
,
5563 show_ip_ospf_neighbor_detail_cmd
,
5564 "show ip ospf [vrf <NAME|all>$vrf_name] neighbor detail [json$json]",
5567 "OSPF information\n"
5571 "detail of all neighbors\n"
5575 struct listnode
*node
= NULL
;
5576 int ret
= CMD_SUCCESS
;
5578 uint8_t use_vrf
= 0;
5579 json_object
*json_vrf
= NULL
;
5582 json_vrf
= json_object_new_object();
5584 /* vrf input is provided could be all or specific vrf*/
5587 if (strmatch(vrf_name
, "all")) {
5588 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5589 if (!ospf
->oi_running
)
5591 ret
= show_ip_ospf_neighbor_detail_common(
5592 vty
, ospf
, json_vrf
, !!json
, use_vrf
);
5595 vty_json(vty
, json_vrf
);
5599 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5600 if (ospf
== NULL
|| !ospf
->oi_running
) {
5602 vty_json(vty
, json_vrf
);
5605 "%% OSPF is not enabled in vrf %s\n",
5610 /* Display default ospf (instance 0) info */
5611 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5612 if (ospf
== NULL
|| !ospf
->oi_running
) {
5614 vty_json(vty
, json_vrf
);
5616 vty_out(vty
, "%% OSPF is not enabled\n");
5622 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json_vrf
,
5626 vty_json(vty
, json_vrf
);
5631 DEFUN (show_ip_ospf_instance_neighbor_detail
,
5632 show_ip_ospf_instance_neighbor_detail_cmd
,
5633 "show ip ospf (1-65535) neighbor detail [json]",
5636 "OSPF information\n"
5639 "detail of all neighbors\n"
5644 unsigned short instance
= 0;
5645 bool uj
= use_json(argc
, argv
);
5646 json_object
*json
= NULL
;
5647 int ret
= CMD_SUCCESS
;
5649 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5650 if (instance
!= ospf_instance
)
5651 return CMD_NOT_MY_INSTANCE
;
5653 ospf
= ospf_lookup_instance(instance
);
5654 if (!ospf
|| !ospf
->oi_running
)
5658 json
= json_object_new_object();
5660 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
, 0);
5663 vty_json(vty
, json
);
5668 static int show_ip_ospf_neighbor_detail_all_common(struct vty
*vty
,
5674 struct listnode
*node
;
5675 struct ospf_interface
*oi
;
5676 json_object
*json_vrf
= NULL
;
5680 json_vrf
= json_object_new_object();
5685 if (ospf
->instance
) {
5687 json_object_int_add(json
, "ospfInstance",
5690 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5693 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5695 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5696 struct route_node
*rn
;
5697 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
5698 struct ospf_nbr_nbma
*nbr_nbma
;
5700 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5706 if (nbr
!= oi
->nbr_self
)
5707 if (nbr
->state
!= NSM_Down
)
5708 show_ip_ospf_neighbor_detail_sub(
5709 vty
, oi
, rn
->info
, prev_nbr
,
5710 json_vrf
, use_json
);
5714 if (oi
->type
!= OSPF_IFTYPE_NBMA
)
5717 struct listnode
*nd
;
5719 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nd
, nbr_nbma
)) {
5720 if (nbr_nbma
->nbr
== NULL
||
5721 nbr_nbma
->nbr
->state
== NSM_Down
)
5722 show_ip_ospf_nbr_nbma_detail_sub(
5723 vty
, oi
, nbr_nbma
, use_json
, json_vrf
);
5729 json_object_object_add(json
, ospf_get_name(ospf
),
5738 DEFUN (show_ip_ospf_neighbor_detail_all
,
5739 show_ip_ospf_neighbor_detail_all_cmd
,
5740 "show ip ospf [vrf <NAME|all>] neighbor detail all [json]",
5743 "OSPF information\n"
5747 "detail of all neighbors\n"
5748 "include down status neighbor\n"
5752 bool uj
= use_json(argc
, argv
);
5753 struct listnode
*node
= NULL
;
5754 char *vrf_name
= NULL
;
5755 bool all_vrf
= false;
5756 int ret
= CMD_SUCCESS
;
5759 uint8_t use_vrf
= 0;
5760 json_object
*json
= NULL
;
5762 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5765 json
= json_object_new_object();
5767 /* vrf input is provided could be all or specific vrf*/
5771 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5772 if (!ospf
->oi_running
)
5774 ret
= show_ip_ospf_neighbor_detail_all_common(
5775 vty
, ospf
, json
, uj
, use_vrf
);
5779 vty_json(vty
, json
);
5783 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5784 if (ospf
== NULL
|| !ospf
->oi_running
) {
5786 json_object_free(json
);
5790 /* Display default ospf (instance 0) info */
5791 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5792 if (ospf
== NULL
|| !ospf
->oi_running
) {
5794 json_object_free(json
);
5800 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
,
5803 vty_out(vty
, "%s\n",
5804 json_object_to_json_string_ext(
5805 json
, JSON_C_TO_STRING_PRETTY
));
5810 json_object_free(json
);
5815 DEFUN (show_ip_ospf_instance_neighbor_detail_all
,
5816 show_ip_ospf_instance_neighbor_detail_all_cmd
,
5817 "show ip ospf (1-65535) neighbor detail all [json]",
5820 "OSPF information\n"
5823 "detail of all neighbors\n"
5824 "include down status neighbor\n"
5829 unsigned short instance
= 0;
5830 bool uj
= use_json(argc
, argv
);
5831 json_object
*json
= NULL
;
5832 int ret
= CMD_SUCCESS
;
5834 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5835 if (instance
!= ospf_instance
)
5836 return CMD_NOT_MY_INSTANCE
;
5838 ospf
= ospf_lookup_instance(instance
);
5839 if (!ospf
|| !ospf
->oi_running
)
5843 json
= json_object_new_object();
5845 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
, uj
, 0);
5848 vty_json(vty
, json
);
5853 static int show_ip_ospf_neighbor_int_detail_common(struct vty
*vty
,
5857 json_object
*json_vrf
)
5859 struct ospf_interface
*oi
;
5860 struct interface
*ifp
;
5861 struct route_node
*rn
, *nrn
;
5862 struct ospf_neighbor
*nbr
;
5863 json_object
*json
= NULL
;
5866 json
= json_object_new_object();
5868 json_object_object_add(json_vrf
,
5869 (ospf
->vrf_id
== VRF_DEFAULT
)
5875 if (ospf
->instance
) {
5877 json_object_int_add(json
, "ospfInstance",
5880 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5883 ifp
= if_lookup_by_name(ifname
, ospf
->vrf_id
);
5886 vty_out(vty
, "No such interface.\n");
5889 vty_json(vty
, json
);
5894 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
5900 for (nrn
= route_top(oi
->nbrs
); nrn
; nrn
= route_next(nrn
)) {
5906 if (nbr
== oi
->nbr_self
)
5909 if (nbr
->state
== NSM_Down
)
5912 show_ip_ospf_neighbor_detail_sub(vty
, oi
, nbr
, NULL
,
5919 vty_json(vty
, json
);
5927 DEFPY(show_ip_ospf_neighbor_int
,
5928 show_ip_ospf_neighbor_int_cmd
,
5929 "show ip ospf [vrf NAME$vrf_name] neighbor IFNAME$ifname [json$json]",
5932 "OSPF information\n"
5939 int ret
= CMD_SUCCESS
;
5940 struct interface
*ifp
= NULL
;
5941 vrf_id_t vrf_id
= VRF_DEFAULT
;
5942 struct vrf
*vrf
= NULL
;
5944 if (vrf_name
&& strmatch(vrf_name
, VRF_DEFAULT_NAME
))
5947 vrf
= vrf_lookup_by_name(vrf_name
);
5949 vrf_id
= vrf
->vrf_id
;
5951 ospf
= ospf_lookup_by_vrf_id(vrf_id
);
5953 if (!ospf
|| !ospf
->oi_running
) {
5955 vty_json_empty(vty
);
5960 show_ip_ospf_neighbour_header(vty
);
5962 ifp
= if_lookup_by_name(ifname
, vrf_id
);
5965 vty_json_empty(vty
);
5967 vty_out(vty
, "No such interface.\n");
5971 ret
= show_ip_ospf_neighbor_int_common(vty
, ospf
, ifname
, !!json
, 0);
5975 DEFPY(show_ip_ospf_neighbor_int_detail
,
5976 show_ip_ospf_neighbor_int_detail_cmd
,
5977 "show ip ospf [vrf NAME$vrf_name] neighbor IFNAME$ifname detail [json$json]",
5980 "OSPF information\n"
5984 "detail of all neighbors\n"
5988 struct listnode
*node
= NULL
;
5989 int ret
= CMD_SUCCESS
;
5990 bool ospf_output
= false;
5992 if (vrf_name
&& !strmatch(vrf_name
, "all")) {
5995 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5996 if (ospf
== NULL
|| !ospf
->oi_running
) {
5999 "%% OSPF is not enabled in vrf %s\n",
6002 vty_json_empty(vty
);
6005 return show_ip_ospf_neighbor_int_detail_common(
6006 vty
, ospf
, ifname
, !!json
, NULL
);
6009 json_object
*json_vrf
= NULL
;
6012 json_vrf
= json_object_new_object();
6014 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6015 if (!ospf
->oi_running
)
6018 ret
= show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, ifname
,
6023 vty_json(vty
, json_vrf
);
6028 vty_out(vty
, "%% OSPF instance not found\n");
6033 DEFPY(show_ip_ospf_instance_neighbor_int_detail
,
6034 show_ip_ospf_instance_neighbor_int_detail_cmd
,
6035 "show ip ospf (1-65535)$instance neighbor IFNAME$ifname detail [json$json]",
6038 "OSPF information\n"
6042 "detail of all neighbors\n"
6047 if (instance
!= ospf_instance
)
6048 return CMD_NOT_MY_INSTANCE
;
6050 ospf
= ospf_lookup_instance(instance
);
6051 if (!ospf
|| !ospf
->oi_running
)
6054 return show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, ifname
,
6058 /* Show functions */
6059 static int show_lsa_summary(struct vty
*vty
, struct ospf_lsa
*lsa
, int self
,
6060 json_object
*json_lsa
)
6062 struct router_lsa
*rl
;
6063 struct summary_lsa
*sl
;
6064 struct as_external_lsa
*asel
;
6065 struct prefix_ipv4 p
;
6070 /* If self option is set, check LSA self flag. */
6071 if (self
== 0 || IS_LSA_SELF(lsa
)) {
6074 /* LSA common part show. */
6075 vty_out(vty
, "%-15pI4", &lsa
->data
->id
);
6076 vty_out(vty
, "%-15pI4 %4d 0x%08lx 0x%04x",
6077 &lsa
->data
->adv_router
, LS_AGE(lsa
),
6078 (unsigned long)ntohl(lsa
->data
->ls_seqnum
),
6079 ntohs(lsa
->data
->checksum
));
6084 snprintf(seqnum
, sizeof(seqnum
), "%x",
6085 ntohl(lsa
->data
->ls_seqnum
));
6086 snprintf(checksum
, sizeof(checksum
), "%x",
6087 ntohs(lsa
->data
->checksum
));
6088 json_object_string_addf(json_lsa
, "lsId", "%pI4",
6090 json_object_string_addf(json_lsa
, "advertisedRouter",
6091 "%pI4", &lsa
->data
->adv_router
);
6092 json_object_int_add(json_lsa
, "lsaAge", LS_AGE(lsa
));
6093 json_object_string_add(json_lsa
, "sequenceNumber",
6095 json_object_string_add(json_lsa
, "checksum", checksum
);
6098 /* LSA specific part show. */
6099 switch (lsa
->data
->type
) {
6100 case OSPF_ROUTER_LSA
:
6101 rl
= (struct router_lsa
*)lsa
->data
;
6104 vty_out(vty
, " %-d", ntohs(rl
->links
));
6106 json_object_int_add(json_lsa
,
6110 case OSPF_SUMMARY_LSA
:
6111 sl
= (struct summary_lsa
*)lsa
->data
;
6114 p
.prefix
= sl
->header
.id
;
6115 p
.prefixlen
= ip_masklen(sl
->mask
);
6116 apply_mask_ipv4(&p
);
6119 vty_out(vty
, " %pFX", &p
);
6121 json_object_string_addf(
6122 json_lsa
, "summaryAddress", "%pFX", &p
);
6125 case OSPF_AS_EXTERNAL_LSA
:
6126 case OSPF_AS_NSSA_LSA
:
6127 asel
= (struct as_external_lsa
*)lsa
->data
;
6130 p
.prefix
= asel
->header
.id
;
6131 p
.prefixlen
= ip_masklen(asel
->mask
);
6132 apply_mask_ipv4(&p
);
6135 vty_out(vty
, " %s %pFX [0x%lx]",
6136 IS_EXTERNAL_METRIC(asel
->e
[0].tos
)
6140 (unsigned long)ntohl(
6141 asel
->e
[0].route_tag
));
6143 json_object_string_add(
6144 json_lsa
, "metricType",
6145 IS_EXTERNAL_METRIC(asel
->e
[0].tos
)
6148 json_object_string_addf(json_lsa
, "route",
6150 json_object_int_add(
6152 (unsigned long)ntohl(
6153 asel
->e
[0].route_tag
));
6156 case OSPF_NETWORK_LSA
:
6157 case OSPF_ASBR_SUMMARY_LSA
:
6158 case OSPF_OPAQUE_LINK_LSA
:
6159 case OSPF_OPAQUE_AREA_LSA
:
6160 case OSPF_OPAQUE_AS_LSA
:
6172 static const char *const show_database_desc
[] = {
6174 "Router Link States",
6176 "Summary Link States",
6177 "ASBR-Summary Link States",
6178 "AS External Link States",
6179 "Group Membership LSA",
6180 "NSSA-external Link States",
6182 "Link-Local Opaque-LSA",
6183 "Area-Local Opaque-LSA",
6184 "AS-external Opaque-LSA",
6187 static const char * const show_database_desc_json
[] = {
6190 "networkLinkStates",
6191 "summaryLinkStates",
6192 "asbrSummaryLinkStates",
6193 "asExternalLinkStates",
6194 "groupMembershipLsa",
6195 "nssaExternalLinkStates",
6197 "linkLocalOpaqueLsa",
6198 "areaLocalOpaqueLsa",
6199 "asExternalOpaqueLsa",
6202 static const char *const show_database_desc_count_json
[] = {
6204 "routerLinkStatesCount",
6205 "networkLinkStatesCount",
6206 "summaryLinkStatesCount",
6207 "asbrSummaryLinkStatesCount",
6208 "asExternalLinkStatesCount",
6209 "groupMembershipLsaCount",
6210 "nssaExternalLinkStatesCount",
6212 "linkLocalOpaqueLsaCount",
6213 "areaLocalOpaqueLsaCount",
6214 "asExternalOpaqueLsaCount",
6217 static const char *const show_database_header
[] = {
6219 "Link ID ADV Router Age Seq# CkSum Link count",
6220 "Link ID ADV Router Age Seq# CkSum",
6221 "Link ID ADV Router Age Seq# CkSum Route",
6222 "Link ID ADV Router Age Seq# CkSum",
6223 "Link ID ADV Router Age Seq# CkSum Route",
6224 " --- header for Group Member ----",
6225 "Link ID ADV Router Age Seq# CkSum Route",
6227 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6228 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6229 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6232 static void show_ip_ospf_database_header(struct vty
*vty
, struct ospf_lsa
*lsa
,
6235 struct router_lsa
*rlsa
= (struct router_lsa
*)lsa
->data
;
6238 if (IS_LSA_SELF(lsa
))
6239 vty_out(vty
, " LS age: %d%s\n", LS_AGE(lsa
),
6240 CHECK_FLAG(lsa
->data
->ls_age
, DO_NOT_AGE
)
6244 vty_out(vty
, " LS age: %d%s\n", LS_AGE(lsa
),
6245 CHECK_FLAG(lsa
->data
->ls_age
, DO_NOT_AGE
)
6248 vty_out(vty
, " Options: 0x%-2x : %s\n", lsa
->data
->options
,
6249 ospf_options_dump(lsa
->data
->options
));
6250 vty_out(vty
, " LS Flags: 0x%-2x %s\n", lsa
->flags
,
6251 ((lsa
->flags
& OSPF_LSA_LOCAL_XLT
)
6252 ? "(Translated from Type-7)"
6255 if (lsa
->data
->type
== OSPF_ROUTER_LSA
) {
6256 vty_out(vty
, " Flags: 0x%x", rlsa
->flags
);
6259 vty_out(vty
, " :%s%s%s%s",
6260 IS_ROUTER_LSA_BORDER(rlsa
) ? " ABR"
6262 IS_ROUTER_LSA_EXTERNAL(rlsa
) ? " ASBR"
6264 IS_ROUTER_LSA_VIRTUAL(rlsa
)
6267 IS_ROUTER_LSA_SHORTCUT(rlsa
)
6273 vty_out(vty
, " LS Type: %s\n",
6274 lookup_msg(ospf_lsa_type_msg
, lsa
->data
->type
, NULL
));
6275 vty_out(vty
, " Link State ID: %pI4 %s\n",
6277 lookup_msg(ospf_link_state_id_type_msg
, lsa
->data
->type
,
6279 vty_out(vty
, " Advertising Router: %pI4\n",
6280 &lsa
->data
->adv_router
);
6281 vty_out(vty
, " LS Seq Number: %08lx\n",
6282 (unsigned long)ntohl(lsa
->data
->ls_seqnum
));
6283 vty_out(vty
, " Checksum: 0x%04x\n",
6284 ntohs(lsa
->data
->checksum
));
6285 vty_out(vty
, " Length: %d\n\n", ntohs(lsa
->data
->length
));
6290 snprintf(seqnum
, 10, "%x", ntohl(lsa
->data
->ls_seqnum
));
6291 snprintf(checksum
, 10, "%x", ntohs(lsa
->data
->checksum
));
6293 json_object_int_add(json
, "lsaAge", LS_AGE(lsa
));
6294 json_object_string_add(json
, "options",
6295 ospf_options_dump(lsa
->data
->options
));
6296 json_object_int_add(json
, "lsaFlags", lsa
->flags
);
6298 if (lsa
->flags
& OSPF_LSA_LOCAL_XLT
)
6299 json_object_boolean_true_add(json
,
6300 "translatedFromType7");
6302 if (lsa
->data
->type
== OSPF_ROUTER_LSA
) {
6303 json_object_int_add(json
, "flags", rlsa
->flags
);
6306 if (IS_ROUTER_LSA_BORDER(rlsa
))
6307 json_object_boolean_true_add(json
,
6309 if (IS_ROUTER_LSA_EXTERNAL(rlsa
))
6310 json_object_boolean_true_add(json
,
6312 if (IS_ROUTER_LSA_VIRTUAL(rlsa
))
6313 json_object_boolean_true_add(
6314 json
, "vlEndpoint");
6315 if (IS_ROUTER_LSA_SHORTCUT(rlsa
))
6316 json_object_boolean_true_add(
6321 json_object_string_add(
6323 lookup_msg(ospf_lsa_type_msg
, lsa
->data
->type
, NULL
));
6324 json_object_string_addf(json
, "linkStateId", "%pI4",
6326 json_object_string_addf(json
, "advertisingRouter", "%pI4",
6327 &lsa
->data
->adv_router
);
6328 json_object_string_add(json
, "lsaSeqNumber", seqnum
);
6329 json_object_string_add(json
, "checksum", checksum
);
6330 json_object_int_add(json
, "length", ntohs(lsa
->data
->length
));
6334 static const char *const link_type_desc
[] = {
6336 "another Router (point-to-point)",
6337 "a Transit Network",
6342 static const char *const link_id_desc
[] = {
6343 "(null)", "Neighboring Router ID", "Designated Router address",
6344 "Net", "Neighboring Router ID",
6347 static const char *const link_data_desc
[] = {
6348 "(null)", "Router Interface address", "Router Interface address",
6349 "Network Mask", "Router Interface address",
6352 static const char *const link_id_desc_json
[] = {
6353 "null", "neighborRouterId", "designatedRouterAddress",
6354 "networkAddress", "neighborRouterId",
6357 static const char *const link_data_desc_json
[] = {
6358 "null", "routerInterfaceAddress", "routerInterfaceAddress",
6359 "networkMask", "routerInterfaceAddress",
6362 /* Show router-LSA each Link information. */
6363 static void show_ip_ospf_database_router_links(struct vty
*vty
,
6364 struct router_lsa
*rl
,
6369 json_object
*json_links
= NULL
;
6370 json_object
*json_link
= NULL
;
6372 char buf
[PREFIX_STRLEN
];
6375 json_links
= json_object_new_object();
6377 len
= ntohs(rl
->header
.length
) - 4;
6378 for (i
= 0; i
< ntohs(rl
->links
) && len
> 0; len
-= 12, i
++) {
6379 type
= rl
->link
[i
].type
;
6384 snprintf(link
, sizeof(link
), "link%u", i
);
6385 json_link
= json_object_new_object();
6386 json_object_string_add(json_link
, "linkType",
6387 link_type_desc
[type
]);
6388 json_object_string_add(json_link
,
6389 link_id_desc_json
[type
],
6391 &rl
->link
[i
].link_id
,
6393 json_object_string_add(
6394 json_link
, link_data_desc_json
[type
],
6395 inet_ntop(AF_INET
, &rl
->link
[i
].link_data
,
6397 json_object_int_add(json_link
, "numOfTosMetrics",
6399 json_object_int_add(json_link
, "tos0Metric",
6400 ntohs(rl
->link
[i
].metric
));
6401 json_object_object_add(json_links
, link
, json_link
);
6403 vty_out(vty
, " Link connected to: %s\n",
6404 link_type_desc
[type
]);
6405 vty_out(vty
, " (Link ID) %s: %pI4\n",
6407 &rl
->link
[i
].link_id
);
6408 vty_out(vty
, " (Link Data) %s: %pI4\n",
6409 link_data_desc
[type
],
6410 &rl
->link
[i
].link_data
);
6411 vty_out(vty
, " Number of TOS metrics: 0\n");
6412 vty_out(vty
, " TOS 0 Metric: %d\n",
6413 ntohs(rl
->link
[i
].metric
));
6418 json_object_object_add(json
, "routerLinks", json_links
);
6421 /* Show router-LSA detail information. */
6422 static int show_router_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6426 struct router_lsa
*rl
= (struct router_lsa
*)lsa
->data
;
6428 show_ip_ospf_database_header(vty
, lsa
, json
);
6431 vty_out(vty
, " Number of Links: %d\n\n",
6434 json_object_int_add(json
, "numOfLinks",
6437 show_ip_ospf_database_router_links(vty
, rl
, json
);
6446 /* Show network-LSA detail information. */
6447 static int show_network_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6451 char buf
[PREFIX_STRLEN
];
6452 json_object
*json_attached_rt
= NULL
;
6453 json_object
*json_router
= NULL
;
6456 json_attached_rt
= json_object_new_object();
6459 struct network_lsa
*nl
= (struct network_lsa
*)lsa
->data
;
6460 struct in_addr
*addr
;
6462 show_ip_ospf_database_header(vty
, lsa
, json
);
6465 vty_out(vty
, " Network Mask: /%d\n",
6466 ip_masklen(nl
->mask
));
6468 json_object_int_add(json
, "networkMask",
6469 ip_masklen(nl
->mask
));
6471 length
= lsa
->size
- OSPF_LSA_HEADER_SIZE
- 4;
6472 addr
= &nl
->routers
[0];
6473 for (i
= 0; length
> 0 && addr
;
6474 length
-= 4, addr
= &nl
->routers
[++i
])
6476 vty_out(vty
, " Attached Router: %pI4\n",
6480 json_router
= json_object_new_object();
6481 json_object_string_add(
6482 json_router
, "attachedRouterId",
6483 inet_ntop(AF_INET
, addr
, buf
,
6485 json_object_object_add(json_attached_rt
,
6486 inet_ntop(AF_INET
, addr
,
6494 json_object_object_add(json
, "attchedRouters",
6500 /* Show summary-LSA detail information. */
6501 static int show_summary_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6505 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
6507 show_ip_ospf_database_header(vty
, lsa
, json
);
6510 vty_out(vty
, " Network Mask: /%d\n",
6511 ip_masklen(sl
->mask
));
6512 vty_out(vty
, " TOS: 0 Metric: %d\n",
6513 GET_METRIC(sl
->metric
));
6516 json_object_int_add(json
, "networkMask",
6517 ip_masklen(sl
->mask
));
6518 json_object_int_add(json
, "tos0Metric",
6519 GET_METRIC(sl
->metric
));
6526 /* Show summary-ASBR-LSA detail information. */
6527 static int show_summary_asbr_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6531 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
6533 show_ip_ospf_database_header(vty
, lsa
, json
);
6536 vty_out(vty
, " Network Mask: /%d\n",
6537 ip_masklen(sl
->mask
));
6538 vty_out(vty
, " TOS: 0 Metric: %d\n",
6539 GET_METRIC(sl
->metric
));
6542 json_object_int_add(json
, "networkMask",
6543 ip_masklen(sl
->mask
));
6544 json_object_int_add(json
, "tos0Metric",
6545 GET_METRIC(sl
->metric
));
6552 /* Show AS-external-LSA detail information. */
6553 static int show_as_external_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6559 struct as_external_lsa
*al
=
6560 (struct as_external_lsa
*)lsa
->data
;
6562 show_ip_ospf_database_header(vty
, lsa
, json
);
6565 vty_out(vty
, " Network Mask: /%d\n",
6566 ip_masklen(al
->mask
));
6567 vty_out(vty
, " Metric Type: %s\n",
6568 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6569 ? "2 (Larger than any link state path)"
6571 vty_out(vty
, " TOS: 0\n");
6572 vty_out(vty
, " Metric: %d\n",
6573 GET_METRIC(al
->e
[0].metric
));
6574 vty_out(vty
, " Forward Address: %pI4\n",
6575 &al
->e
[0].fwd_addr
);
6577 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
6578 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6580 json_object_int_add(json
, "networkMask",
6581 ip_masklen(al
->mask
));
6582 json_object_string_add(
6584 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6585 ? "E2 (Larger than any link state path)"
6587 json_object_int_add(json
, "tos", tos
);
6588 json_object_int_add(json
, "metric",
6589 GET_METRIC(al
->e
[0].metric
));
6590 json_object_string_addf(json
, "forwardAddress", "%pI4",
6591 &(al
->e
[0].fwd_addr
));
6592 json_object_int_add(
6593 json
, "externalRouteTag",
6594 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6601 /* Show AS-NSSA-LSA detail information. */
6602 static int show_as_nssa_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6608 struct as_external_lsa
*al
=
6609 (struct as_external_lsa
*)lsa
->data
;
6611 show_ip_ospf_database_header(vty
, lsa
, json
);
6614 vty_out(vty
, " Network Mask: /%d\n",
6615 ip_masklen(al
->mask
));
6616 vty_out(vty
, " Metric Type: %s\n",
6617 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6618 ? "2 (Larger than any link state path)"
6620 vty_out(vty
, " TOS: 0\n");
6621 vty_out(vty
, " Metric: %d\n",
6622 GET_METRIC(al
->e
[0].metric
));
6623 vty_out(vty
, " NSSA: Forward Address: %pI4\n",
6624 &al
->e
[0].fwd_addr
);
6626 " External Route Tag: %" ROUTE_TAG_PRI
6628 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6630 json_object_int_add(json
, "networkMask",
6631 ip_masklen(al
->mask
));
6632 json_object_string_add(
6634 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6635 ? "E2 (Larger than any link state path)"
6637 json_object_int_add(json
, "tos", tos
);
6638 json_object_int_add(json
, "metric",
6639 GET_METRIC(al
->e
[0].metric
));
6640 json_object_string_addf(json
, "nssaForwardAddress",
6641 "%pI4", &al
->e
[0].fwd_addr
);
6642 json_object_int_add(
6643 json
, "externalRouteTag",
6644 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6651 static int show_func_dummy(struct vty
*vty
, struct ospf_lsa
*lsa
,
6657 static int show_opaque_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6661 show_ip_ospf_database_header(vty
, lsa
, json
);
6662 show_opaque_info_detail(vty
, lsa
, json
);
6669 int (*show_function
[])(struct vty
*, struct ospf_lsa
*, json_object
*) = {
6671 show_router_lsa_detail
,
6672 show_network_lsa_detail
,
6673 show_summary_lsa_detail
,
6674 show_summary_asbr_lsa_detail
,
6675 show_as_external_lsa_detail
,
6677 show_as_nssa_lsa_detail
, /* almost same as external */
6679 show_opaque_lsa_detail
,
6680 show_opaque_lsa_detail
,
6681 show_opaque_lsa_detail
,
6684 static void show_lsa_prefix_set(struct vty
*vty
, struct prefix_ls
*lp
,
6685 struct in_addr
*id
, struct in_addr
*adv_router
)
6687 memset(lp
, 0, sizeof(struct prefix_ls
));
6688 lp
->family
= AF_UNSPEC
;
6691 else if (adv_router
== NULL
) {
6692 lp
->prefixlen
= IPV4_MAX_BITLEN
;
6697 lp
->adv_router
= *adv_router
;
6701 static void show_lsa_detail_proc(struct vty
*vty
, struct route_table
*rt
,
6702 struct in_addr
*id
, struct in_addr
*adv_router
,
6705 struct prefix_ls lp
;
6706 struct route_node
*rn
, *start
;
6707 struct ospf_lsa
*lsa
;
6708 json_object
*json_lsa
= NULL
;
6710 show_lsa_prefix_set(vty
, &lp
, id
, adv_router
);
6711 start
= route_node_get(rt
, (struct prefix
*)&lp
);
6713 route_lock_node(start
);
6714 for (rn
= start
; rn
; rn
= route_next_until(rn
, start
))
6715 if ((lsa
= rn
->info
)) {
6716 if (show_function
[lsa
->data
->type
] != NULL
) {
6719 json_object_new_object();
6720 json_object_array_add(json
,
6724 show_function
[lsa
->data
->type
](
6725 vty
, lsa
, json_lsa
);
6728 route_unlock_node(start
);
6732 /* Show detail LSA information
6733 -- if id is NULL then show all LSAs. */
6734 static void show_lsa_detail(struct vty
*vty
, struct ospf
*ospf
, int type
,
6735 struct in_addr
*id
, struct in_addr
*adv_router
,
6738 struct listnode
*node
;
6739 struct ospf_area
*area
;
6740 char buf
[PREFIX_STRLEN
];
6741 json_object
*json_lsa_type
= NULL
;
6742 json_object
*json_areas
= NULL
;
6743 json_object
*json_lsa_array
= NULL
;
6746 case OSPF_AS_EXTERNAL_LSA
:
6747 case OSPF_OPAQUE_AS_LSA
:
6749 vty_out(vty
, " %s \n\n",
6750 show_database_desc
[type
]);
6752 json_lsa_array
= json_object_new_array();
6754 show_lsa_detail_proc(vty
, AS_LSDB(ospf
, type
), id
, adv_router
,
6757 json_object_object_add(json
,
6758 show_database_desc_json
[type
],
6764 json_areas
= json_object_new_object();
6766 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6769 "\n %s (Area %s)\n\n",
6770 show_database_desc
[type
],
6771 ospf_area_desc_string(area
));
6773 json_lsa_array
= json_object_new_array();
6774 json_object_object_add(json_areas
,
6782 show_lsa_detail_proc(vty
, AREA_LSDB(area
, type
), id
,
6783 adv_router
, json_lsa_array
);
6787 json_lsa_type
= json_object_new_object();
6788 json_object_object_add(json_lsa_type
, "areas",
6790 json_object_object_add(json
,
6791 show_database_desc_json
[type
],
6798 static void show_lsa_detail_adv_router_proc(struct vty
*vty
,
6799 struct route_table
*rt
,
6800 struct in_addr
*adv_router
,
6803 struct route_node
*rn
;
6804 struct ospf_lsa
*lsa
;
6805 json_object
*json_lsa
= NULL
;
6807 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
))
6808 if ((lsa
= rn
->info
)) {
6809 if (IPV4_ADDR_SAME(adv_router
,
6810 &lsa
->data
->adv_router
)) {
6811 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
6814 json_lsa
= json_object_new_object();
6815 json_object_array_add(json
, json_lsa
);
6818 if (show_function
[lsa
->data
->type
] != NULL
)
6819 show_function
[lsa
->data
->type
](
6820 vty
, lsa
, json_lsa
);
6825 /* Show detail LSA information. */
6826 static void show_lsa_detail_adv_router(struct vty
*vty
, struct ospf
*ospf
,
6827 int type
, struct in_addr
*adv_router
,
6830 struct listnode
*node
;
6831 struct ospf_area
*area
;
6832 char buf
[PREFIX_STRLEN
];
6833 json_object
*json_lsa_type
= NULL
;
6834 json_object
*json_areas
= NULL
;
6835 json_object
*json_lsa_array
= NULL
;
6838 json_lsa_type
= json_object_new_object();
6841 case OSPF_AS_EXTERNAL_LSA
:
6842 case OSPF_OPAQUE_AS_LSA
:
6844 vty_out(vty
, " %s \n\n",
6845 show_database_desc
[type
]);
6847 json_lsa_array
= json_object_new_array();
6849 show_lsa_detail_adv_router_proc(vty
, AS_LSDB(ospf
, type
),
6850 adv_router
, json_lsa_array
);
6852 json_object_object_add(json
,
6853 show_database_desc_json
[type
],
6858 json_areas
= json_object_new_object();
6860 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6863 "\n %s (Area %s)\n\n",
6864 show_database_desc
[type
],
6865 ospf_area_desc_string(area
));
6867 json_lsa_array
= json_object_new_array();
6868 json_object_object_add(
6870 inet_ntop(AF_INET
, &area
->area_id
, buf
,
6875 show_lsa_detail_adv_router_proc(
6876 vty
, AREA_LSDB(area
, type
), adv_router
,
6881 json_object_object_add(json_lsa_type
, "areas",
6883 json_object_object_add(json
,
6884 show_database_desc_json
[type
],
6891 void show_ip_ospf_database_summary(struct vty
*vty
, struct ospf
*ospf
, int self
,
6894 struct ospf_lsa
*lsa
;
6895 struct route_node
*rn
;
6896 struct ospf_area
*area
;
6897 struct listnode
*node
;
6898 char buf
[PREFIX_STRLEN
];
6899 json_object
*json_areas
= NULL
;
6900 json_object
*json_area
= NULL
;
6901 json_object
*json_lsa
= NULL
;
6903 json_object
*json_lsa_array
= NULL
;
6907 json_areas
= json_object_new_object();
6909 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6911 json_area
= json_object_new_object();
6913 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6916 case OSPF_AS_EXTERNAL_LSA
:
6917 case OSPF_OPAQUE_AS_LSA
:
6922 if (ospf_lsdb_count_self(area
->lsdb
, type
) > 0
6924 && ospf_lsdb_count(area
->lsdb
, type
) > 0)) {
6928 " %s (Area %s)\n\n",
6929 show_database_desc
[type
],
6930 ospf_area_desc_string(area
));
6931 vty_out(vty
, "%s\n",
6932 show_database_header
[type
]);
6935 json_object_new_array();
6936 json_object_object_add(
6938 show_database_desc_json
[type
],
6942 LSDB_LOOP (AREA_LSDB(area
, type
), rn
, lsa
) {
6945 json_object_new_object();
6946 json_object_array_add(
6951 count
+= show_lsa_summary(
6952 vty
, lsa
, self
, json_lsa
);
6958 json_object_int_add(
6961 show_database_desc_count_json
6967 json_object_object_add(json_areas
,
6975 json_object_object_add(json
, "areas", json_areas
);
6977 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6980 case OSPF_AS_EXTERNAL_LSA
:
6981 case OSPF_OPAQUE_AS_LSA
:
6986 if (ospf_lsdb_count_self(ospf
->lsdb
, type
)
6987 || (!self
&& ospf_lsdb_count(ospf
->lsdb
, type
))) {
6989 vty_out(vty
, " %s\n\n",
6990 show_database_desc
[type
]);
6991 vty_out(vty
, "%s\n",
6992 show_database_header
[type
]);
6994 json_lsa_array
= json_object_new_array();
6995 json_object_object_add(
6996 json
, show_database_desc_json
[type
],
7000 LSDB_LOOP (AS_LSDB(ospf
, type
), rn
, lsa
) {
7002 json_lsa
= json_object_new_object();
7003 json_object_array_add(json_lsa_array
,
7007 count
+= show_lsa_summary(vty
, lsa
, self
,
7014 json_object_int_add(
7016 show_database_desc_count_json
[type
],
7025 static void show_ip_ospf_database_maxage(struct vty
*vty
, struct ospf
*ospf
,
7028 struct route_node
*rn
;
7029 char buf
[PREFIX_STRLEN
];
7030 json_object
*json_maxage
= NULL
;
7033 vty_out(vty
, "\n MaxAge Link States:\n\n");
7035 json_maxage
= json_object_new_object();
7037 for (rn
= route_top(ospf
->maxage_lsa
); rn
; rn
= route_next(rn
)) {
7038 struct ospf_lsa
*lsa
;
7039 json_object
*json_lsa
= NULL
;
7041 if ((lsa
= rn
->info
) != NULL
) {
7043 vty_out(vty
, "Link type: %d\n",
7045 vty_out(vty
, "Link State ID: %pI4\n",
7047 vty_out(vty
, "Advertising Router: %pI4\n",
7048 &lsa
->data
->adv_router
);
7049 vty_out(vty
, "LSA lock count: %d\n", lsa
->lock
);
7052 json_lsa
= json_object_new_object();
7053 json_object_int_add(json_lsa
, "linkType",
7055 json_object_string_addf(json_lsa
, "linkStateId",
7056 "%pI4", &lsa
->data
->id
);
7057 json_object_string_addf(
7058 json_lsa
, "advertisingRouter", "%pI4",
7059 &lsa
->data
->adv_router
);
7060 json_object_int_add(json_lsa
, "lsaLockCount",
7062 json_object_object_add(
7072 json_object_object_add(json
, "maxAgeLinkStates", json_maxage
);
7075 #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
7076 #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
7078 #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
7079 #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
7080 #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
7081 #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
7083 #define OSPF_LSA_TYPES_DESC \
7084 "ASBR summary link states\n" \
7085 "External link states\n" \
7086 "Network link states\n" \
7087 "Router link states\n" \
7088 "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \
7089 OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
7090 OSPF_LSA_TYPE_OPAQUE_AS_DESC
7093 show_ip_ospf_database_common(struct vty
*vty
, struct ospf
*ospf
, bool maxage
,
7094 bool self
, bool detail
, const char *type_name
,
7095 struct in_addr
*lsid
, struct in_addr
*adv_router
,
7096 bool use_vrf
, json_object
*json
, bool uj
)
7099 json_object
*json_vrf
= NULL
;
7103 json_vrf
= json_object_new_object();
7108 if (ospf
->instance
) {
7110 json_object_int_add(json_vrf
, "ospfInstance",
7113 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
7116 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
7118 /* Show Router ID. */
7120 json_object_string_addf(json_vrf
, "routerId", "%pI4",
7123 vty_out(vty
, "\n OSPF Router with ID (%pI4)\n\n",
7127 /* Show MaxAge LSAs */
7129 show_ip_ospf_database_maxage(vty
, ospf
, json_vrf
);
7132 if (ospf
->vrf_id
== VRF_DEFAULT
)
7133 json_object_object_add(json
, "default",
7136 json_object_object_add(json
, ospf
->name
,
7143 /* Show all LSAs. */
7146 for (int i
= OSPF_ROUTER_LSA
; i
<= OSPF_OPAQUE_AS_LSA
;
7149 case OSPF_GROUP_MEMBER_LSA
:
7150 case OSPF_EXTERNAL_ATTRIBUTES_LSA
:
7151 /* ignore deprecated LSA types */
7157 if (adv_router
&& !lsid
)
7158 show_lsa_detail_adv_router(vty
, ospf
, i
,
7162 show_lsa_detail(vty
, ospf
, i
, lsid
,
7163 adv_router
, json_vrf
);
7166 show_ip_ospf_database_summary(vty
, ospf
, self
,
7171 if (ospf
->vrf_id
== VRF_DEFAULT
)
7172 json_object_object_add(json
, "default",
7175 json_object_object_add(json
, ospf
->name
,
7182 /* Set database type to show. */
7183 if (strncmp(type_name
, "r", 1) == 0)
7184 type
= OSPF_ROUTER_LSA
;
7185 else if (strncmp(type_name
, "ne", 2) == 0)
7186 type
= OSPF_NETWORK_LSA
;
7187 else if (strncmp(type_name
, "ns", 2) == 0)
7188 type
= OSPF_AS_NSSA_LSA
;
7189 else if (strncmp(type_name
, "su", 2) == 0)
7190 type
= OSPF_SUMMARY_LSA
;
7191 else if (strncmp(type_name
, "a", 1) == 0)
7192 type
= OSPF_ASBR_SUMMARY_LSA
;
7193 else if (strncmp(type_name
, "e", 1) == 0)
7194 type
= OSPF_AS_EXTERNAL_LSA
;
7195 else if (strncmp(type_name
, "opaque-l", 8) == 0)
7196 type
= OSPF_OPAQUE_LINK_LSA
;
7197 else if (strncmp(type_name
, "opaque-ar", 9) == 0)
7198 type
= OSPF_OPAQUE_AREA_LSA
;
7199 else if (strncmp(type_name
, "opaque-as", 9) == 0)
7200 type
= OSPF_OPAQUE_AS_LSA
;
7204 json_object_free(json_vrf
);
7209 if (adv_router
&& !lsid
)
7210 show_lsa_detail_adv_router(vty
, ospf
, type
, adv_router
,
7213 show_lsa_detail(vty
, ospf
, type
, lsid
, adv_router
, json_vrf
);
7217 if (ospf
->vrf_id
== VRF_DEFAULT
)
7218 json_object_object_add(json
, "default",
7221 json_object_object_add(json
, ospf
->name
,
7229 DEFPY (show_ip_ospf_database
,
7230 show_ip_ospf_database_cmd
,
7231 "show ip ospf [(1-65535)$instance_id] [vrf <NAME|all>$vrf_name] database\
7234 |self-originate$selforig\
7237 |<asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as>$type_name\
7241 |<adv-router A.B.C.D$adv_router|self-originate$adv_router_self>\
7247 "OSPF information\n"
7251 "Database summary\n"
7252 "LSAs in MaxAge list\n"
7253 "Self-originated link states\n"
7254 "Show detailed information\n"
7256 "Link State ID (as an IP address)\n"
7257 "Advertising Router link states\n"
7258 "Advertising Router (as an IP address)\n"
7259 "Self-originated link states\n"
7263 int ret
= CMD_SUCCESS
;
7264 bool use_vrf
= !!vrf_name
;
7265 bool uj
= use_json(argc
, argv
);
7266 struct in_addr
*lsid_p
= NULL
;
7267 struct in_addr
*adv_router_p
= NULL
;
7268 json_object
*json
= NULL
;
7271 json
= json_object_new_object();
7275 adv_router_p
= &adv_router
;
7277 if (vrf_name
&& strmatch(vrf_name
, "all")) {
7278 struct listnode
*node
;
7279 bool ospf_output
= false;
7281 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
7282 if (!ospf
->oi_running
)
7284 if (ospf
->instance
!= instance_id
)
7287 if (adv_router_self
)
7288 adv_router_p
= &ospf
->router_id
;
7291 ret
= show_ip_ospf_database_common(
7292 vty
, ospf
, !!maxage
, !!selforig
, !!detail
,
7293 type_name
, lsid_p
, adv_router_p
, use_vrf
, json
,
7297 if (!ospf_output
&& !uj
)
7298 vty_out(vty
, "%% OSPF is not enabled\n");
7301 vrf_name
= VRF_DEFAULT_NAME
;
7302 ospf
= ospf_lookup_by_inst_name(instance_id
, vrf_name
);
7303 if (ospf
== NULL
|| !ospf
->oi_running
) {
7305 vty_json(vty
, json
);
7307 vty_out(vty
, "%% OSPF instance not found\n");
7310 if (adv_router_self
)
7311 adv_router_p
= &ospf
->router_id
;
7313 ret
= (show_ip_ospf_database_common(
7314 vty
, ospf
, !!maxage
, !!selforig
, !!detail
, type_name
,
7315 lsid_p
, adv_router_p
, use_vrf
, json
, uj
));
7319 vty_json(vty
, json
);
7324 DEFUN (ip_ospf_authentication_args
,
7325 ip_ospf_authentication_args_addr_cmd
,
7326 "ip ospf authentication <null|message-digest> [A.B.C.D]",
7328 "OSPF interface commands\n"
7329 "Enable authentication on this interface\n"
7330 "Use null authentication\n"
7331 "Use message-digest authentication\n"
7332 "Address of interface\n")
7334 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7335 int idx_encryption
= 3;
7337 struct in_addr addr
;
7339 struct ospf_if_params
*params
;
7341 params
= IF_DEF_PARAMS(ifp
);
7344 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7347 "Please specify interface address by A.B.C.D\n");
7348 return CMD_WARNING_CONFIG_FAILED
;
7351 params
= ospf_get_if_params(ifp
, addr
);
7352 ospf_if_update_params(ifp
, addr
);
7355 /* Handle null authentication */
7356 if (argv
[idx_encryption
]->arg
[0] == 'n') {
7357 SET_IF_PARAM(params
, auth_type
);
7358 params
->auth_type
= OSPF_AUTH_NULL
;
7362 /* Handle message-digest authentication */
7363 if (argv
[idx_encryption
]->arg
[0] == 'm') {
7364 SET_IF_PARAM(params
, auth_type
);
7365 params
->auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
7369 vty_out(vty
, "You shouldn't get here!\n");
7370 return CMD_WARNING_CONFIG_FAILED
;
7373 DEFUN (ip_ospf_authentication
,
7374 ip_ospf_authentication_addr_cmd
,
7375 "ip ospf authentication [A.B.C.D]",
7377 "OSPF interface commands\n"
7378 "Enable authentication on this interface\n"
7379 "Address of interface\n")
7381 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7383 struct in_addr addr
;
7385 struct ospf_if_params
*params
;
7387 params
= IF_DEF_PARAMS(ifp
);
7390 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7393 "Please specify interface address by A.B.C.D\n");
7394 return CMD_WARNING_CONFIG_FAILED
;
7397 params
= ospf_get_if_params(ifp
, addr
);
7398 ospf_if_update_params(ifp
, addr
);
7401 SET_IF_PARAM(params
, auth_type
);
7402 params
->auth_type
= OSPF_AUTH_SIMPLE
;
7407 DEFUN (no_ip_ospf_authentication_args
,
7408 no_ip_ospf_authentication_args_addr_cmd
,
7409 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
7412 "OSPF interface commands\n"
7413 "Enable authentication on this interface\n"
7414 "Use null authentication\n"
7415 "Use message-digest authentication\n"
7416 "Address of interface\n")
7418 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7419 int idx_encryption
= 4;
7421 struct in_addr addr
;
7423 struct ospf_if_params
*params
;
7424 struct route_node
*rn
;
7427 params
= IF_DEF_PARAMS(ifp
);
7430 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7433 "Please specify interface address by A.B.C.D\n");
7434 return CMD_WARNING_CONFIG_FAILED
;
7437 params
= ospf_lookup_if_params(ifp
, addr
);
7438 if (params
== NULL
) {
7439 vty_out(vty
, "Ip Address specified is unknown\n");
7440 return CMD_WARNING_CONFIG_FAILED
;
7442 params
->auth_type
= OSPF_AUTH_NOTSET
;
7443 UNSET_IF_PARAM(params
, auth_type
);
7444 if (params
!= IF_DEF_PARAMS(ifp
)) {
7445 ospf_free_if_params(ifp
, addr
);
7446 ospf_if_update_params(ifp
, addr
);
7449 if (argv
[idx_encryption
]->arg
[0] == 'n') {
7450 auth_type
= OSPF_AUTH_NULL
;
7451 } else if (argv
[idx_encryption
]->arg
[0] == 'm') {
7452 auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
7454 vty_out(vty
, "Unexpected input encountered\n");
7455 return CMD_WARNING_CONFIG_FAILED
;
7458 * Here we have a case where the user has entered
7459 * 'no ip ospf authentication (null | message_digest )'
7460 * we need to find if we have any ip addresses underneath it
7462 * correspond to the associated type.
7464 if (params
->auth_type
== auth_type
) {
7465 params
->auth_type
= OSPF_AUTH_NOTSET
;
7466 UNSET_IF_PARAM(params
, auth_type
);
7469 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
7470 rn
= route_next(rn
)) {
7471 if ((params
= rn
->info
)) {
7472 if (params
->auth_type
== auth_type
) {
7473 params
->auth_type
= OSPF_AUTH_NOTSET
;
7474 UNSET_IF_PARAM(params
, auth_type
);
7475 if (params
!= IF_DEF_PARAMS(ifp
)) {
7476 ospf_free_if_params(
7477 ifp
, rn
->p
.u
.prefix4
);
7478 ospf_if_update_params(
7479 ifp
, rn
->p
.u
.prefix4
);
7489 DEFUN (no_ip_ospf_authentication
,
7490 no_ip_ospf_authentication_addr_cmd
,
7491 "no ip ospf authentication [A.B.C.D]",
7494 "OSPF interface commands\n"
7495 "Enable authentication on this interface\n"
7496 "Address of interface\n")
7498 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7500 struct in_addr addr
;
7502 struct ospf_if_params
*params
;
7503 struct route_node
*rn
;
7505 params
= IF_DEF_PARAMS(ifp
);
7508 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7511 "Please specify interface address by A.B.C.D\n");
7512 return CMD_WARNING_CONFIG_FAILED
;
7515 params
= ospf_lookup_if_params(ifp
, addr
);
7516 if (params
== NULL
) {
7517 vty_out(vty
, "Ip Address specified is unknown\n");
7518 return CMD_WARNING_CONFIG_FAILED
;
7521 params
->auth_type
= OSPF_AUTH_NOTSET
;
7522 UNSET_IF_PARAM(params
, auth_type
);
7523 if (params
!= IF_DEF_PARAMS(ifp
)) {
7524 ospf_free_if_params(ifp
, addr
);
7525 ospf_if_update_params(ifp
, addr
);
7529 * When a user enters 'no ip ospf authentication'
7530 * We should remove all authentication types from
7533 if ((params
->auth_type
== OSPF_AUTH_NULL
)
7534 || (params
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
7535 || (params
->auth_type
== OSPF_AUTH_SIMPLE
)) {
7536 params
->auth_type
= OSPF_AUTH_NOTSET
;
7537 UNSET_IF_PARAM(params
, auth_type
);
7540 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
7541 rn
= route_next(rn
)) {
7542 if ((params
= rn
->info
)) {
7544 if ((params
->auth_type
== OSPF_AUTH_NULL
)
7545 || (params
->auth_type
7546 == OSPF_AUTH_CRYPTOGRAPHIC
)
7547 || (params
->auth_type
7548 == OSPF_AUTH_SIMPLE
)) {
7549 params
->auth_type
= OSPF_AUTH_NOTSET
;
7550 UNSET_IF_PARAM(params
, auth_type
);
7551 if (params
!= IF_DEF_PARAMS(ifp
)) {
7552 ospf_free_if_params(
7553 ifp
, rn
->p
.u
.prefix4
);
7554 ospf_if_update_params(
7555 ifp
, rn
->p
.u
.prefix4
);
7566 DEFUN (ip_ospf_authentication_key
,
7567 ip_ospf_authentication_key_addr_cmd
,
7568 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
7570 "OSPF interface commands\n"
7571 "Authentication password (key)\n"
7572 "The OSPF password (key)\n"
7573 "Address of interface\n")
7575 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7577 struct in_addr addr
;
7578 struct ospf_if_params
*params
;
7580 params
= IF_DEF_PARAMS(ifp
);
7582 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7583 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7585 "Please specify interface address by A.B.C.D\n");
7586 return CMD_WARNING_CONFIG_FAILED
;
7589 params
= ospf_get_if_params(ifp
, addr
);
7590 ospf_if_update_params(ifp
, addr
);
7593 strlcpy((char *)params
->auth_simple
, argv
[3]->arg
,
7594 sizeof(params
->auth_simple
));
7595 SET_IF_PARAM(params
, auth_simple
);
7600 DEFUN_HIDDEN (ospf_authentication_key
,
7601 ospf_authentication_key_cmd
,
7602 "ospf authentication-key AUTH_KEY [A.B.C.D]",
7603 "OSPF interface commands\n"
7604 VLINK_HELPSTR_AUTH_SIMPLE
7605 "Address of interface\n")
7607 return ip_ospf_authentication_key(self
, vty
, argc
, argv
);
7610 DEFUN (no_ip_ospf_authentication_key
,
7611 no_ip_ospf_authentication_key_authkey_addr_cmd
,
7612 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7615 "OSPF interface commands\n"
7616 VLINK_HELPSTR_AUTH_SIMPLE
7617 "Address of interface\n")
7619 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7621 struct in_addr addr
;
7622 struct ospf_if_params
*params
;
7623 params
= IF_DEF_PARAMS(ifp
);
7625 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7626 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7628 "Please specify interface address by A.B.C.D\n");
7629 return CMD_WARNING_CONFIG_FAILED
;
7632 params
= ospf_lookup_if_params(ifp
, addr
);
7637 memset(params
->auth_simple
, 0, OSPF_AUTH_SIMPLE_SIZE
);
7638 UNSET_IF_PARAM(params
, auth_simple
);
7640 if (params
!= IF_DEF_PARAMS(ifp
)) {
7641 ospf_free_if_params(ifp
, addr
);
7642 ospf_if_update_params(ifp
, addr
);
7648 DEFUN_HIDDEN (no_ospf_authentication_key
,
7649 no_ospf_authentication_key_authkey_addr_cmd
,
7650 "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7652 "OSPF interface commands\n"
7653 VLINK_HELPSTR_AUTH_SIMPLE
7654 "Address of interface\n")
7656 return no_ip_ospf_authentication_key(self
, vty
, argc
, argv
);
7659 DEFUN (ip_ospf_message_digest_key
,
7660 ip_ospf_message_digest_key_cmd
,
7661 "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7663 "OSPF interface commands\n"
7664 "Message digest authentication password (key)\n"
7666 "Use MD5 algorithm\n"
7667 "The OSPF password (key)\n"
7668 "Address of interface\n")
7670 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7671 struct crypt_key
*ck
;
7673 struct in_addr addr
;
7674 struct ospf_if_params
*params
;
7676 params
= IF_DEF_PARAMS(ifp
);
7679 argv_find(argv
, argc
, "(1-255)", &idx
);
7680 char *keyid
= argv
[idx
]->arg
;
7681 argv_find(argv
, argc
, "KEY", &idx
);
7682 char *cryptkey
= argv
[idx
]->arg
;
7684 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7685 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7687 "Please specify interface address by A.B.C.D\n");
7688 return CMD_WARNING_CONFIG_FAILED
;
7691 params
= ospf_get_if_params(ifp
, addr
);
7692 ospf_if_update_params(ifp
, addr
);
7695 key_id
= strtol(keyid
, NULL
, 10);
7697 /* Remove existing key, if any */
7698 ospf_crypt_key_delete(params
->auth_crypt
, key_id
);
7700 ck
= ospf_crypt_key_new();
7701 ck
->key_id
= (uint8_t)key_id
;
7702 strlcpy((char *)ck
->auth_key
, cryptkey
, sizeof(ck
->auth_key
));
7704 ospf_crypt_key_add(params
->auth_crypt
, ck
);
7705 SET_IF_PARAM(params
, auth_crypt
);
7710 DEFUN_HIDDEN (ospf_message_digest_key
,
7711 ospf_message_digest_key_cmd
,
7712 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7713 "OSPF interface commands\n"
7714 "Message digest authentication password (key)\n"
7716 "Use MD5 algorithm\n"
7717 "The OSPF password (key)\n"
7718 "Address of interface\n")
7720 return ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7723 DEFUN (no_ip_ospf_message_digest_key
,
7724 no_ip_ospf_message_digest_key_cmd
,
7725 "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7728 "OSPF interface commands\n"
7729 "Message digest authentication password (key)\n"
7731 "Use MD5 algorithm\n"
7732 "The OSPF password (key)\n"
7733 "Address of interface\n")
7735 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7737 struct crypt_key
*ck
;
7739 struct in_addr addr
;
7740 struct ospf_if_params
*params
;
7741 params
= IF_DEF_PARAMS(ifp
);
7743 argv_find(argv
, argc
, "(1-255)", &idx
);
7744 char *keyid
= argv
[idx
]->arg
;
7746 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7747 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7749 "Please specify interface address by A.B.C.D\n");
7750 return CMD_WARNING_CONFIG_FAILED
;
7753 params
= ospf_lookup_if_params(ifp
, addr
);
7758 key_id
= strtol(keyid
, NULL
, 10);
7759 ck
= ospf_crypt_key_lookup(params
->auth_crypt
, key_id
);
7761 vty_out(vty
, "OSPF: Key %d does not exist\n", key_id
);
7762 return CMD_WARNING_CONFIG_FAILED
;
7765 ospf_crypt_key_delete(params
->auth_crypt
, key_id
);
7767 if (params
!= IF_DEF_PARAMS(ifp
)) {
7768 ospf_free_if_params(ifp
, addr
);
7769 ospf_if_update_params(ifp
, addr
);
7775 DEFUN_HIDDEN (no_ospf_message_digest_key
,
7776 no_ospf_message_digest_key_cmd
,
7777 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7779 "OSPF interface commands\n"
7780 "Message digest authentication password (key)\n"
7782 "Use MD5 algorithm\n"
7783 "The OSPF password (key)\n"
7784 "Address of interface\n")
7786 return no_ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7789 DEFUN (ip_ospf_cost
,
7791 "ip ospf cost (1-65535) [A.B.C.D]",
7793 "OSPF interface commands\n"
7796 "Address of interface\n")
7798 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7800 uint32_t cost
= OSPF_OUTPUT_COST_DEFAULT
;
7801 struct in_addr addr
;
7802 struct ospf_if_params
*params
;
7803 params
= IF_DEF_PARAMS(ifp
);
7806 char *coststr
= NULL
, *ifaddr
= NULL
;
7808 argv_find(argv
, argc
, "(1-65535)", &idx
);
7809 coststr
= argv
[idx
]->arg
;
7810 cost
= strtol(coststr
, NULL
, 10);
7812 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7814 if (!inet_aton(ifaddr
, &addr
)) {
7816 "Please specify interface address by A.B.C.D\n");
7817 return CMD_WARNING_CONFIG_FAILED
;
7820 params
= ospf_get_if_params(ifp
, addr
);
7821 ospf_if_update_params(ifp
, addr
);
7824 SET_IF_PARAM(params
, output_cost_cmd
);
7825 params
->output_cost_cmd
= cost
;
7827 ospf_if_recalculate_output_cost(ifp
);
7832 DEFUN_HIDDEN (ospf_cost
,
7834 "ospf cost (1-65535) [A.B.C.D]",
7835 "OSPF interface commands\n"
7838 "Address of interface\n")
7840 return ip_ospf_cost(self
, vty
, argc
, argv
);
7843 DEFUN (no_ip_ospf_cost
,
7844 no_ip_ospf_cost_cmd
,
7845 "no ip ospf cost [(1-65535)] [A.B.C.D]",
7848 "OSPF interface commands\n"
7851 "Address of interface\n")
7853 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7855 struct in_addr addr
;
7856 struct ospf_if_params
*params
;
7858 params
= IF_DEF_PARAMS(ifp
);
7861 char *ifaddr
= NULL
;
7862 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7864 /* According to the semantics we are mimicking "no ip ospf cost N" is
7865 * always treated as "no ip ospf cost" regardless of the actual value
7866 * of N already configured for the interface. Thus ignore cost. */
7869 if (!inet_aton(ifaddr
, &addr
)) {
7871 "Please specify interface address by A.B.C.D\n");
7872 return CMD_WARNING_CONFIG_FAILED
;
7875 params
= ospf_lookup_if_params(ifp
, addr
);
7880 UNSET_IF_PARAM(params
, output_cost_cmd
);
7882 if (params
!= IF_DEF_PARAMS(ifp
)) {
7883 ospf_free_if_params(ifp
, addr
);
7884 ospf_if_update_params(ifp
, addr
);
7887 ospf_if_recalculate_output_cost(ifp
);
7892 DEFUN_HIDDEN (no_ospf_cost
,
7894 "no ospf cost [(1-65535)] [A.B.C.D]",
7896 "OSPF interface commands\n"
7899 "Address of interface\n")
7901 return no_ip_ospf_cost(self
, vty
, argc
, argv
);
7904 static void ospf_nbr_timer_update(struct ospf_interface
*oi
)
7906 struct route_node
*rn
;
7907 struct ospf_neighbor
*nbr
;
7909 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
7915 nbr
->v_inactivity
= OSPF_IF_PARAM(oi
, v_wait
);
7916 nbr
->v_db_desc
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7917 nbr
->v_ls_req
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7918 nbr
->v_ls_upd
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7922 static int ospf_vty_dead_interval_set(struct vty
*vty
, const char *interval_str
,
7923 const char *nbr_str
,
7924 const char *fast_hello_str
)
7926 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7929 struct in_addr addr
;
7931 struct ospf_if_params
*params
;
7932 struct ospf_interface
*oi
;
7933 struct route_node
*rn
;
7935 params
= IF_DEF_PARAMS(ifp
);
7938 ret
= inet_aton(nbr_str
, &addr
);
7941 "Please specify interface address by A.B.C.D\n");
7942 return CMD_WARNING_CONFIG_FAILED
;
7945 params
= ospf_get_if_params(ifp
, addr
);
7946 ospf_if_update_params(ifp
, addr
);
7950 seconds
= strtoul(interval_str
, NULL
, 10);
7952 /* reset fast_hello too, just to be sure */
7953 UNSET_IF_PARAM(params
, fast_hello
);
7954 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
7955 } else if (fast_hello_str
) {
7956 hellomult
= strtoul(fast_hello_str
, NULL
, 10);
7957 /* 1s dead-interval with sub-second hellos desired */
7958 seconds
= OSPF_ROUTER_DEAD_INTERVAL_MINIMAL
;
7959 SET_IF_PARAM(params
, fast_hello
);
7960 params
->fast_hello
= hellomult
;
7963 "Please specify dead-interval or hello-multiplier\n");
7964 return CMD_WARNING_CONFIG_FAILED
;
7967 SET_IF_PARAM(params
, v_wait
);
7968 params
->v_wait
= seconds
;
7969 params
->is_v_wait_set
= true;
7971 /* Update timer values in neighbor structure. */
7973 struct ospf
*ospf
= NULL
;
7975 ospf
= ifp
->vrf
->info
;
7977 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
7979 ospf_nbr_timer_update(oi
);
7982 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
7983 if ((oi
= rn
->info
))
7984 ospf_nbr_timer_update(oi
);
7990 DEFUN (ip_ospf_dead_interval
,
7991 ip_ospf_dead_interval_cmd
,
7992 "ip ospf dead-interval (1-65535) [A.B.C.D]",
7994 "OSPF interface commands\n"
7995 "Interval time after which a neighbor is declared down\n"
7997 "Address of interface\n")
8000 char *interval
= argv_find(argv
, argc
, "(1-65535)", &idx
)
8004 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
8005 return ospf_vty_dead_interval_set(vty
, interval
, ifaddr
, NULL
);
8009 DEFUN_HIDDEN (ospf_dead_interval
,
8010 ospf_dead_interval_cmd
,
8011 "ospf dead-interval (1-65535) [A.B.C.D]",
8012 "OSPF interface commands\n"
8013 "Interval time after which a neighbor is declared down\n"
8015 "Address of interface\n")
8017 return ip_ospf_dead_interval(self
, vty
, argc
, argv
);
8020 DEFUN (ip_ospf_dead_interval_minimal
,
8021 ip_ospf_dead_interval_minimal_addr_cmd
,
8022 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
8024 "OSPF interface commands\n"
8025 "Interval time after which a neighbor is declared down\n"
8026 "Minimal 1s dead-interval with fast sub-second hellos\n"
8027 "Hello multiplier factor\n"
8028 "Number of Hellos to send each second\n"
8029 "Address of interface\n")
8034 return ospf_vty_dead_interval_set(
8035 vty
, NULL
, argv
[idx_ipv4
]->arg
, argv
[idx_number
]->arg
);
8037 return ospf_vty_dead_interval_set(vty
, NULL
, NULL
,
8038 argv
[idx_number
]->arg
);
8041 DEFUN (no_ip_ospf_dead_interval
,
8042 no_ip_ospf_dead_interval_cmd
,
8043 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8046 "OSPF interface commands\n"
8047 "Interval time after which a neighbor is declared down\n"
8049 "Minimal 1s dead-interval with fast sub-second hellos\n"
8050 "Hello multiplier factor\n"
8051 "Number of Hellos to send each second\n"
8052 "Address of interface\n")
8054 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8055 int idx_ipv4
= argc
- 1;
8056 struct in_addr addr
= {.s_addr
= 0L};
8058 struct ospf_if_params
*params
;
8059 struct ospf_interface
*oi
;
8060 struct route_node
*rn
;
8062 params
= IF_DEF_PARAMS(ifp
);
8064 if (argv
[idx_ipv4
]->type
== IPV4_TKN
) {
8065 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8068 "Please specify interface address by A.B.C.D\n");
8069 return CMD_WARNING_CONFIG_FAILED
;
8072 params
= ospf_lookup_if_params(ifp
, addr
);
8077 UNSET_IF_PARAM(params
, v_wait
);
8078 params
->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
8079 params
->is_v_wait_set
= false;
8081 UNSET_IF_PARAM(params
, fast_hello
);
8082 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
8084 if (params
!= IF_DEF_PARAMS(ifp
)) {
8085 ospf_free_if_params(ifp
, addr
);
8086 ospf_if_update_params(ifp
, addr
);
8089 /* Update timer values in neighbor structure. */
8091 struct ospf
*ospf
= NULL
;
8093 ospf
= ifp
->vrf
->info
;
8095 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
8097 ospf_nbr_timer_update(oi
);
8100 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
8101 if ((oi
= rn
->info
))
8102 ospf_nbr_timer_update(oi
);
8108 DEFUN_HIDDEN (no_ospf_dead_interval
,
8109 no_ospf_dead_interval_cmd
,
8110 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8112 "OSPF interface commands\n"
8113 "Interval time after which a neighbor is declared down\n"
8115 "Minimal 1s dead-interval with fast sub-second hellos\n"
8116 "Hello multiplier factor\n"
8117 "Number of Hellos to send each second\n"
8118 "Address of interface\n")
8120 return no_ip_ospf_dead_interval(self
, vty
, argc
, argv
);
8123 DEFUN (ip_ospf_hello_interval
,
8124 ip_ospf_hello_interval_cmd
,
8125 "ip ospf hello-interval (1-65535) [A.B.C.D]",
8127 "OSPF interface commands\n"
8128 "Time between HELLO packets\n"
8130 "Address of interface\n")
8132 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8134 struct in_addr addr
= {.s_addr
= 0L};
8135 struct ospf_if_params
*params
;
8136 params
= IF_DEF_PARAMS(ifp
);
8137 uint32_t seconds
= 0;
8138 bool is_addr
= false;
8139 uint32_t old_interval
= 0;
8141 argv_find(argv
, argc
, "(1-65535)", &idx
);
8142 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
8144 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8145 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8147 "Please specify interface address by A.B.C.D\n");
8148 return CMD_WARNING_CONFIG_FAILED
;
8151 params
= ospf_get_if_params(ifp
, addr
);
8152 ospf_if_update_params(ifp
, addr
);
8156 old_interval
= params
->v_hello
;
8158 /* Return, if same interval is configured. */
8159 if (old_interval
== seconds
)
8162 SET_IF_PARAM(params
, v_hello
);
8163 params
->v_hello
= seconds
;
8165 if (!params
->is_v_wait_set
) {
8166 SET_IF_PARAM(params
, v_wait
);
8168 * The router dead interval should
8169 * be some multiple of the HelloInterval (perhaps 4 times the
8170 * hello interval) and must be the same for all routers
8171 * attached to a common network.
8173 params
->v_wait
= 4 * seconds
;
8176 ospf_reset_hello_timer(ifp
, addr
, is_addr
);
8181 DEFUN_HIDDEN (ospf_hello_interval
,
8182 ospf_hello_interval_cmd
,
8183 "ospf hello-interval (1-65535) [A.B.C.D]",
8184 "OSPF interface commands\n"
8185 "Time between HELLO packets\n"
8187 "Address of interface\n")
8189 return ip_ospf_hello_interval(self
, vty
, argc
, argv
);
8192 DEFUN (no_ip_ospf_hello_interval
,
8193 no_ip_ospf_hello_interval_cmd
,
8194 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
8197 "OSPF interface commands\n"
8198 "Time between HELLO packets\n" // ignored
8200 "Address of interface\n")
8202 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8204 struct in_addr addr
= {.s_addr
= 0L};
8205 struct ospf_if_params
*params
;
8206 struct route_node
*rn
;
8208 params
= IF_DEF_PARAMS(ifp
);
8210 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8211 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8213 "Please specify interface address by A.B.C.D\n");
8214 return CMD_WARNING_CONFIG_FAILED
;
8217 params
= ospf_lookup_if_params(ifp
, addr
);
8222 UNSET_IF_PARAM(params
, v_hello
);
8223 params
->v_hello
= OSPF_HELLO_INTERVAL_DEFAULT
;
8225 if (!params
->is_v_wait_set
) {
8226 UNSET_IF_PARAM(params
, v_wait
);
8227 params
->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
8230 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8231 struct ospf_interface
*oi
= rn
->info
;
8236 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
8237 oi
->ptp_dmvpn
= IF_DEF_PARAMS(ifp
)->ptp_dmvpn
;
8239 if (oi
->state
> ISM_Down
) {
8240 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
8241 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
8245 if (params
!= IF_DEF_PARAMS(ifp
)) {
8246 ospf_free_if_params(ifp
, addr
);
8247 ospf_if_update_params(ifp
, addr
);
8253 DEFUN_HIDDEN (no_ospf_hello_interval
,
8254 no_ospf_hello_interval_cmd
,
8255 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
8257 "OSPF interface commands\n"
8258 "Time between HELLO packets\n" // ignored
8260 "Address of interface\n")
8262 return no_ip_ospf_hello_interval(self
, vty
, argc
, argv
);
8265 DEFUN(ip_ospf_network
, ip_ospf_network_cmd
,
8266 "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point [dmvpn]>",
8268 "OSPF interface commands\n"
8270 "Specify OSPF broadcast multi-access network\n"
8271 "Specify OSPF NBMA network\n"
8272 "Specify OSPF point-to-multipoint network\n"
8273 "Specify OSPF point-to-point network\n"
8274 "Specify OSPF point-to-point DMVPN network\n")
8276 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8278 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
8279 uint8_t old_ptp_dmvpn
= IF_DEF_PARAMS(ifp
)->ptp_dmvpn
;
8280 struct route_node
*rn
;
8282 if (old_type
== OSPF_IFTYPE_LOOPBACK
) {
8284 "This is a loopback interface. Can't set network type.\n");
8285 return CMD_WARNING_CONFIG_FAILED
;
8288 IF_DEF_PARAMS(ifp
)->ptp_dmvpn
= 0;
8290 if (argv_find(argv
, argc
, "broadcast", &idx
))
8291 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_BROADCAST
;
8292 else if (argv_find(argv
, argc
, "non-broadcast", &idx
))
8293 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_NBMA
;
8294 else if (argv_find(argv
, argc
, "point-to-multipoint", &idx
))
8295 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOMULTIPOINT
;
8296 else if (argv_find(argv
, argc
, "point-to-point", &idx
)) {
8297 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOPOINT
;
8298 if (argv_find(argv
, argc
, "dmvpn", &idx
))
8299 IF_DEF_PARAMS(ifp
)->ptp_dmvpn
= 1;
8302 if (IF_DEF_PARAMS(ifp
)->type
== old_type
8303 && IF_DEF_PARAMS(ifp
)->ptp_dmvpn
== old_ptp_dmvpn
)
8306 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), type
);
8308 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8309 struct ospf_interface
*oi
= rn
->info
;
8314 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
8316 if (oi
->state
> ISM_Down
) {
8317 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
8318 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
8325 DEFUN_HIDDEN (ospf_network
,
8327 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
8328 "OSPF interface commands\n"
8330 "Specify OSPF broadcast multi-access network\n"
8331 "Specify OSPF NBMA network\n"
8332 "Specify OSPF point-to-multipoint network\n"
8333 "Specify OSPF point-to-point network\n")
8335 return ip_ospf_network(self
, vty
, argc
, argv
);
8338 DEFUN (no_ip_ospf_network
,
8339 no_ip_ospf_network_cmd
,
8340 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8343 "OSPF interface commands\n"
8345 "Specify OSPF broadcast multi-access network\n"
8346 "Specify OSPF NBMA network\n"
8347 "Specify OSPF point-to-multipoint network\n"
8348 "Specify OSPF point-to-point network\n")
8350 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8351 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
8352 struct route_node
*rn
;
8354 IF_DEF_PARAMS(ifp
)->type
= ospf_default_iftype(ifp
);
8355 IF_DEF_PARAMS(ifp
)->ptp_dmvpn
= 0;
8357 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
8360 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8361 struct ospf_interface
*oi
= rn
->info
;
8366 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
8368 if (oi
->state
> ISM_Down
) {
8369 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
8370 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
8377 DEFUN_HIDDEN (no_ospf_network
,
8378 no_ospf_network_cmd
,
8379 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8381 "OSPF interface commands\n"
8383 "Specify OSPF broadcast multi-access network\n"
8384 "Specify OSPF NBMA network\n"
8385 "Specify OSPF point-to-multipoint network\n"
8386 "Specify OSPF point-to-point network\n")
8388 return no_ip_ospf_network(self
, vty
, argc
, argv
);
8391 DEFUN (ip_ospf_priority
,
8392 ip_ospf_priority_cmd
,
8393 "ip ospf priority (0-255) [A.B.C.D]",
8395 "OSPF interface commands\n"
8398 "Address of interface\n")
8400 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8403 struct route_node
*rn
;
8404 struct in_addr addr
;
8405 struct ospf_if_params
*params
;
8406 params
= IF_DEF_PARAMS(ifp
);
8408 argv_find(argv
, argc
, "(0-255)", &idx
);
8409 priority
= strtol(argv
[idx
]->arg
, NULL
, 10);
8411 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8412 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8414 "Please specify interface address by A.B.C.D\n");
8415 return CMD_WARNING_CONFIG_FAILED
;
8418 params
= ospf_get_if_params(ifp
, addr
);
8419 ospf_if_update_params(ifp
, addr
);
8422 SET_IF_PARAM(params
, priority
);
8423 params
->priority
= priority
;
8425 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8426 struct ospf_interface
*oi
= rn
->info
;
8431 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
8432 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
8433 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
8440 DEFUN_HIDDEN (ospf_priority
,
8442 "ospf priority (0-255) [A.B.C.D]",
8443 "OSPF interface commands\n"
8446 "Address of interface\n")
8448 return ip_ospf_priority(self
, vty
, argc
, argv
);
8451 DEFUN (no_ip_ospf_priority
,
8452 no_ip_ospf_priority_cmd
,
8453 "no ip ospf priority [(0-255) [A.B.C.D]]",
8456 "OSPF interface commands\n"
8457 "Router priority\n" // ignored
8459 "Address of interface\n")
8461 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8463 struct route_node
*rn
;
8464 struct in_addr addr
;
8465 struct ospf_if_params
*params
;
8467 params
= IF_DEF_PARAMS(ifp
);
8469 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8470 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8472 "Please specify interface address by A.B.C.D\n");
8473 return CMD_WARNING_CONFIG_FAILED
;
8476 params
= ospf_lookup_if_params(ifp
, addr
);
8481 UNSET_IF_PARAM(params
, priority
);
8482 params
->priority
= OSPF_ROUTER_PRIORITY_DEFAULT
;
8484 if (params
!= IF_DEF_PARAMS(ifp
)) {
8485 ospf_free_if_params(ifp
, addr
);
8486 ospf_if_update_params(ifp
, addr
);
8489 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8490 struct ospf_interface
*oi
= rn
->info
;
8495 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
8496 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
8497 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
8504 DEFUN_HIDDEN (no_ospf_priority
,
8505 no_ospf_priority_cmd
,
8506 "no ospf priority [(0-255) [A.B.C.D]]",
8508 "OSPF interface commands\n"
8511 "Address of interface\n")
8513 return no_ip_ospf_priority(self
, vty
, argc
, argv
);
8516 DEFUN (ip_ospf_retransmit_interval
,
8517 ip_ospf_retransmit_interval_addr_cmd
,
8518 "ip ospf retransmit-interval (1-65535) [A.B.C.D]",
8520 "OSPF interface commands\n"
8521 "Time between retransmitting lost link state advertisements\n"
8523 "Address of interface\n")
8525 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8528 struct in_addr addr
;
8529 struct ospf_if_params
*params
;
8530 params
= IF_DEF_PARAMS(ifp
);
8532 argv_find(argv
, argc
, "(1-65535)", &idx
);
8533 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
8535 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8536 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8538 "Please specify interface address by A.B.C.D\n");
8539 return CMD_WARNING_CONFIG_FAILED
;
8542 params
= ospf_get_if_params(ifp
, addr
);
8543 ospf_if_update_params(ifp
, addr
);
8546 SET_IF_PARAM(params
, retransmit_interval
);
8547 params
->retransmit_interval
= seconds
;
8552 DEFUN_HIDDEN (ospf_retransmit_interval
,
8553 ospf_retransmit_interval_cmd
,
8554 "ospf retransmit-interval (1-65535) [A.B.C.D]",
8555 "OSPF interface commands\n"
8556 "Time between retransmitting lost link state advertisements\n"
8558 "Address of interface\n")
8560 return ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
8563 DEFUN (no_ip_ospf_retransmit_interval
,
8564 no_ip_ospf_retransmit_interval_addr_cmd
,
8565 "no ip ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8568 "OSPF interface commands\n"
8569 "Time between retransmitting lost link state advertisements\n"
8571 "Address of interface\n")
8573 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8575 struct in_addr addr
;
8576 struct ospf_if_params
*params
;
8578 params
= IF_DEF_PARAMS(ifp
);
8580 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8581 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8583 "Please specify interface address by A.B.C.D\n");
8584 return CMD_WARNING_CONFIG_FAILED
;
8587 params
= ospf_lookup_if_params(ifp
, addr
);
8592 UNSET_IF_PARAM(params
, retransmit_interval
);
8593 params
->retransmit_interval
= OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
8595 if (params
!= IF_DEF_PARAMS(ifp
)) {
8596 ospf_free_if_params(ifp
, addr
);
8597 ospf_if_update_params(ifp
, addr
);
8603 DEFUN_HIDDEN (no_ospf_retransmit_interval
,
8604 no_ospf_retransmit_interval_cmd
,
8605 "no ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8607 "OSPF interface commands\n"
8608 "Time between retransmitting lost link state advertisements\n"
8610 "Address of interface\n")
8612 return no_ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
8615 DEFUN (ip_ospf_transmit_delay
,
8616 ip_ospf_transmit_delay_addr_cmd
,
8617 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
8619 "OSPF interface commands\n"
8620 "Link state transmit delay\n"
8622 "Address of interface\n")
8624 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8627 struct in_addr addr
;
8628 struct ospf_if_params
*params
;
8630 params
= IF_DEF_PARAMS(ifp
);
8631 argv_find(argv
, argc
, "(1-65535)", &idx
);
8632 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
8634 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8635 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8637 "Please specify interface address by A.B.C.D\n");
8638 return CMD_WARNING_CONFIG_FAILED
;
8641 params
= ospf_get_if_params(ifp
, addr
);
8642 ospf_if_update_params(ifp
, addr
);
8645 SET_IF_PARAM(params
, transmit_delay
);
8646 params
->transmit_delay
= seconds
;
8651 DEFUN_HIDDEN (ospf_transmit_delay
,
8652 ospf_transmit_delay_cmd
,
8653 "ospf transmit-delay (1-65535) [A.B.C.D]",
8654 "OSPF interface commands\n"
8655 "Link state transmit delay\n"
8657 "Address of interface\n")
8659 return ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
8662 DEFUN (no_ip_ospf_transmit_delay
,
8663 no_ip_ospf_transmit_delay_addr_cmd
,
8664 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
8667 "OSPF interface commands\n"
8668 "Link state transmit delay\n"
8670 "Address of interface\n")
8672 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8674 struct in_addr addr
;
8675 struct ospf_if_params
*params
;
8677 params
= IF_DEF_PARAMS(ifp
);
8679 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8680 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8682 "Please specify interface address by A.B.C.D\n");
8683 return CMD_WARNING_CONFIG_FAILED
;
8686 params
= ospf_lookup_if_params(ifp
, addr
);
8691 UNSET_IF_PARAM(params
, transmit_delay
);
8692 params
->transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
8694 if (params
!= IF_DEF_PARAMS(ifp
)) {
8695 ospf_free_if_params(ifp
, addr
);
8696 ospf_if_update_params(ifp
, addr
);
8703 DEFUN_HIDDEN (no_ospf_transmit_delay
,
8704 no_ospf_transmit_delay_cmd
,
8705 "no ospf transmit-delay [(1-65535) [A.B.C.D]]",
8707 "OSPF interface commands\n"
8708 "Link state transmit delay\n"
8710 "Address of interface\n")
8712 return no_ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
8715 DEFUN (ip_ospf_area
,
8717 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]",
8719 "OSPF interface commands\n"
8721 "Enable OSPF on this interface\n"
8722 "OSPF area ID in IP address format\n"
8723 "OSPF area ID as a decimal value\n"
8724 "Address of interface\n")
8726 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8729 struct in_addr area_id
;
8730 struct in_addr addr
;
8731 struct ospf_if_params
*params
= NULL
;
8732 struct route_node
*rn
;
8733 struct ospf
*ospf
= NULL
;
8734 unsigned short instance
= 0;
8738 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
8739 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
8741 argv_find(argv
, argc
, "area", &idx
);
8742 areaid
= argv
[idx
+ 1]->arg
;
8745 ospf
= ifp
->vrf
->info
;
8747 ospf
= ospf_lookup_instance(instance
);
8749 if (instance
&& instance
!= ospf_instance
) {
8751 * At this point we know we have received
8752 * an instance and there is no ospf instance
8753 * associated with it. This means we are
8754 * in a situation where we have an
8755 * ospf command that is setup for a different
8756 * process(instance). We need to safely
8757 * remove the command from ourselves and
8758 * allow the other instance(process) handle
8759 * the configuration command.
8763 params
= IF_DEF_PARAMS(ifp
);
8764 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8765 UNSET_IF_PARAM(params
, if_area
);
8769 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
; rn
= route_next(rn
))
8770 if ((params
= rn
->info
) && OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8771 UNSET_IF_PARAM(params
, if_area
);
8776 ospf
= ifp
->vrf
->info
;
8778 ospf_interface_area_unset(ospf
, ifp
);
8781 return CMD_NOT_MY_INSTANCE
;
8784 ret
= str2area_id(areaid
, &area_id
, &format
);
8786 vty_out(vty
, "Please specify area by A.B.C.D|<0-4294967295>\n");
8787 return CMD_WARNING_CONFIG_FAILED
;
8789 if (memcmp(ifp
->name
, "VLINK", 5) == 0) {
8790 vty_out(vty
, "Cannot enable OSPF on a virtual link.\n");
8791 return CMD_WARNING_CONFIG_FAILED
;
8795 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
)) {
8796 if (rn
->info
!= NULL
) {
8798 "Please remove all network commands first.\n");
8799 return CMD_WARNING_CONFIG_FAILED
;
8804 params
= IF_DEF_PARAMS(ifp
);
8805 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)
8806 && !IPV4_ADDR_SAME(¶ms
->if_area
, &area_id
)) {
8808 "Must remove previous area config before changing ospf area \n");
8809 return CMD_WARNING_CONFIG_FAILED
;
8812 // Check if we have an address arg and proccess it
8813 if (argc
== idx
+ 3) {
8814 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
8816 "Please specify Intf Address by A.B.C.D\n");
8817 return CMD_WARNING_CONFIG_FAILED
;
8819 // update/create address-level params
8820 params
= ospf_get_if_params((ifp
), (addr
));
8821 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8822 if (!IPV4_ADDR_SAME(¶ms
->if_area
, &area_id
)) {
8824 "Must remove previous area/address config before changing ospf area\n");
8825 return CMD_WARNING_CONFIG_FAILED
;
8829 ospf_if_update_params((ifp
), (addr
));
8832 /* enable ospf on this interface with area_id */
8834 SET_IF_PARAM(params
, if_area
);
8835 params
->if_area
= area_id
;
8836 params
->if_area_id_fmt
= format
;
8840 ospf_interface_area_set(ospf
, ifp
);
8845 DEFUN (no_ip_ospf_area
,
8846 no_ip_ospf_area_cmd
,
8847 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]",
8850 "OSPF interface commands\n"
8852 "Disable OSPF on this interface\n"
8853 "OSPF area ID in IP address format\n"
8854 "OSPF area ID as a decimal value\n"
8855 "Address of interface\n")
8857 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8860 struct ospf_if_params
*params
;
8861 unsigned short instance
= 0;
8862 struct in_addr addr
;
8863 struct in_addr area_id
;
8865 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
8866 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
8869 ospf
= ifp
->vrf
->info
;
8871 ospf
= ospf_lookup_instance(instance
);
8873 if (instance
&& instance
!= ospf_instance
)
8874 return CMD_NOT_MY_INSTANCE
;
8876 argv_find(argv
, argc
, "area", &idx
);
8878 // Check if we have an address arg and proccess it
8879 if (argc
== idx
+ 3) {
8880 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
8882 "Please specify Intf Address by A.B.C.D\n");
8883 return CMD_WARNING_CONFIG_FAILED
;
8885 params
= ospf_lookup_if_params(ifp
, addr
);
8886 if ((params
) == NULL
)
8889 params
= IF_DEF_PARAMS(ifp
);
8891 area_id
= params
->if_area
;
8892 if (!OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8894 "Can't find specified interface area configuration.\n");
8895 return CMD_WARNING_CONFIG_FAILED
;
8898 UNSET_IF_PARAM(params
, if_area
);
8899 if (params
!= IF_DEF_PARAMS((ifp
))) {
8900 ospf_free_if_params((ifp
), (addr
));
8901 ospf_if_update_params((ifp
), (addr
));
8905 ospf_interface_area_unset(ospf
, ifp
);
8906 ospf_area_check_free(ospf
, area_id
);
8912 DEFUN (ip_ospf_passive
,
8913 ip_ospf_passive_cmd
,
8914 "ip ospf passive [A.B.C.D]",
8916 "OSPF interface commands\n"
8917 "Suppress routing updates on an interface\n"
8918 "Address of interface\n")
8920 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8922 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
8923 struct ospf_if_params
*params
;
8927 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8930 "Please specify interface address by A.B.C.D\n");
8931 return CMD_WARNING_CONFIG_FAILED
;
8933 params
= ospf_get_if_params(ifp
, addr
);
8934 ospf_if_update_params(ifp
, addr
);
8936 params
= IF_DEF_PARAMS(ifp
);
8939 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_PASSIVE
);
8944 DEFUN (no_ip_ospf_passive
,
8945 no_ip_ospf_passive_cmd
,
8946 "no ip ospf passive [A.B.C.D]",
8949 "OSPF interface commands\n"
8950 "Enable routing updates on an interface\n"
8951 "Address of interface\n")
8953 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8955 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
8956 struct ospf_if_params
*params
;
8960 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8963 "Please specify interface address by A.B.C.D\n");
8964 return CMD_WARNING_CONFIG_FAILED
;
8966 params
= ospf_lookup_if_params(ifp
, addr
);
8970 params
= IF_DEF_PARAMS(ifp
);
8973 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_ACTIVE
);
8978 DEFUN (ospf_redistribute_source
,
8979 ospf_redistribute_source_cmd
,
8980 "redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
8982 FRR_REDIST_HELP_STR_OSPFD
8983 "Metric for redistributed routes\n"
8984 "OSPF default metric\n"
8985 "OSPF exterior metric type for redistributed routes\n"
8986 "Set OSPF External Type 1/2 metrics\n"
8987 "Route map reference\n"
8988 "Pointer to route-map entries\n")
8990 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8991 int idx_protocol
= 1;
8995 struct ospf_redist
*red
;
8997 bool update
= false;
8999 /* Get distribute source. */
9000 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
9002 return CMD_WARNING_CONFIG_FAILED
;
9004 /* Get metric value. */
9005 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
9006 if (!str2metric(argv
[idx
]->arg
, &metric
))
9007 return CMD_WARNING_CONFIG_FAILED
;
9010 /* Get metric type. */
9011 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
9012 if (!str2metric_type(argv
[idx
]->arg
, &type
))
9013 return CMD_WARNING_CONFIG_FAILED
;
9017 red
= ospf_redist_lookup(ospf
, source
, 0);
9019 red
= ospf_redist_add(ospf
, source
, 0);
9024 if (argv_find(argv
, argc
, "route-map", &idx
)) {
9025 ospf_routemap_set(red
, argv
[idx
+ 1]->arg
);
9027 ospf_routemap_unset(red
);
9030 return ospf_redistribute_update(ospf
, red
, source
, 0, type
,
9033 return ospf_redistribute_set(ospf
, red
, source
, 0, type
,
9037 DEFUN (no_ospf_redistribute_source
,
9038 no_ospf_redistribute_source_cmd
,
9039 "no redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9042 FRR_REDIST_HELP_STR_OSPFD
9043 "Metric for redistributed routes\n"
9044 "OSPF default metric\n"
9045 "OSPF exterior metric type for redistributed routes\n"
9046 "Set OSPF External Type 1/2 metrics\n"
9047 "Route map reference\n"
9048 "Pointer to route-map entries\n")
9050 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9051 int idx_protocol
= 2;
9053 struct ospf_redist
*red
;
9055 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
9057 return CMD_WARNING_CONFIG_FAILED
;
9059 red
= ospf_redist_lookup(ospf
, source
, 0);
9063 ospf_routemap_unset(red
);
9064 ospf_redist_del(ospf
, source
, 0);
9066 return ospf_redistribute_unset(ospf
, source
, 0);
9069 DEFUN (ospf_redistribute_instance_source
,
9070 ospf_redistribute_instance_source_cmd
,
9071 "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9073 "Open Shortest Path First\n"
9074 "Non-main Kernel Routing Table\n"
9075 "Instance ID/Table ID\n"
9076 "Metric for redistributed routes\n"
9077 "OSPF default metric\n"
9078 "OSPF exterior metric type for redistributed routes\n"
9079 "Set OSPF External Type 1/2 metrics\n"
9080 "Route map reference\n"
9081 "Pointer to route-map entries\n")
9083 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9084 int idx_ospf_table
= 1;
9090 unsigned short instance
;
9091 struct ospf_redist
*red
;
9092 bool update
= false;
9094 source
= proto_redistnum(AFI_IP
, argv
[idx_ospf_table
]->text
);
9097 vty_out(vty
, "Unknown instance redistribution\n");
9098 return CMD_WARNING_CONFIG_FAILED
;
9101 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9103 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
9105 "Instance redistribution in non-instanced OSPF not allowed\n");
9106 return CMD_WARNING_CONFIG_FAILED
;
9109 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
9110 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
9111 return CMD_WARNING_CONFIG_FAILED
;
9114 /* Get metric value. */
9115 if (argv_find(argv
, argc
, "metric", &idx
))
9116 if (!str2metric(argv
[idx
+ 1]->arg
, &metric
))
9117 return CMD_WARNING_CONFIG_FAILED
;
9120 /* Get metric type. */
9121 if (argv_find(argv
, argc
, "metric-type", &idx
))
9122 if (!str2metric_type(argv
[idx
+ 1]->arg
, &type
))
9123 return CMD_WARNING_CONFIG_FAILED
;
9125 red
= ospf_redist_lookup(ospf
, source
, instance
);
9127 red
= ospf_redist_add(ospf
, source
, instance
);
9132 if (argv_find(argv
, argc
, "route-map", &idx
))
9133 ospf_routemap_set(red
, argv
[idx
+ 1]->arg
);
9135 ospf_routemap_unset(red
);
9138 return ospf_redistribute_update(ospf
, red
, source
, instance
,
9141 return ospf_redistribute_set(ospf
, red
, source
, instance
, type
,
9145 DEFUN (no_ospf_redistribute_instance_source
,
9146 no_ospf_redistribute_instance_source_cmd
,
9147 "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9150 "Open Shortest Path First\n"
9151 "Non-main Kernel Routing Table\n"
9152 "Instance ID/Table Id\n"
9153 "Metric for redistributed routes\n"
9154 "OSPF default metric\n"
9155 "OSPF exterior metric type for redistributed routes\n"
9156 "Set OSPF External Type 1/2 metrics\n"
9157 "Route map reference\n"
9158 "Pointer to route-map entries\n")
9160 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9161 int idx_ospf_table
= 2;
9163 unsigned int instance
;
9164 struct ospf_redist
*red
;
9167 if (strncmp(argv
[idx_ospf_table
]->arg
, "o", 1) == 0)
9168 source
= ZEBRA_ROUTE_OSPF
;
9170 source
= ZEBRA_ROUTE_TABLE
;
9172 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9174 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
9176 "Instance redistribution in non-instanced OSPF not allowed\n");
9177 return CMD_WARNING_CONFIG_FAILED
;
9180 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
9181 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
9182 return CMD_WARNING_CONFIG_FAILED
;
9185 red
= ospf_redist_lookup(ospf
, source
, instance
);
9189 ospf_routemap_unset(red
);
9190 ospf_redist_del(ospf
, source
, instance
);
9192 return ospf_redistribute_unset(ospf
, source
, instance
);
9195 DEFUN (ospf_distribute_list_out
,
9196 ospf_distribute_list_out_cmd
,
9197 "distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD
,
9198 "Filter networks in routing updates\n"
9199 "Access-list name\n"
9201 FRR_REDIST_HELP_STR_OSPFD
)
9203 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9207 char *proto
= argv
[argc
- 1]->text
;
9209 /* Get distribute source. */
9210 source
= proto_redistnum(AFI_IP
, proto
);
9212 return CMD_WARNING_CONFIG_FAILED
;
9214 return ospf_distribute_list_out_set(ospf
, source
, argv
[idx_word
]->arg
);
9217 DEFUN (no_ospf_distribute_list_out
,
9218 no_ospf_distribute_list_out_cmd
,
9219 "no distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD
,
9221 "Filter networks in routing updates\n"
9222 "Access-list name\n"
9224 FRR_REDIST_HELP_STR_OSPFD
)
9226 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9230 char *proto
= argv
[argc
- 1]->text
;
9231 source
= proto_redistnum(AFI_IP
, proto
);
9233 return CMD_WARNING_CONFIG_FAILED
;
9235 return ospf_distribute_list_out_unset(ospf
, source
,
9236 argv
[idx_word
]->arg
);
9239 /* Default information originate. */
9240 DEFUN (ospf_default_information_originate
,
9241 ospf_default_information_originate_cmd
,
9242 "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9243 "Control distribution of default information\n"
9244 "Distribute a default route\n"
9245 "Always advertise default route\n"
9246 "OSPF default metric\n"
9248 "OSPF metric type for default routes\n"
9249 "Set OSPF External Type 1/2 metrics\n"
9250 "Route map reference\n"
9251 "Pointer to route-map entries\n")
9253 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9254 int default_originate
= DEFAULT_ORIGINATE_ZEBRA
;
9257 struct ospf_redist
*red
;
9259 int cur_originate
= ospf
->default_originate
;
9260 bool sameRtmap
= false;
9263 red
= ospf_redist_add(ospf
, DEFAULT_ROUTE
, 0);
9265 /* Check whether "always" was specified */
9266 if (argv_find(argv
, argc
, "always", &idx
))
9267 default_originate
= DEFAULT_ORIGINATE_ALWAYS
;
9269 /* Get metric value */
9270 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
9271 if (!str2metric(argv
[idx
]->arg
, &metric
))
9272 return CMD_WARNING_CONFIG_FAILED
;
9275 /* Get metric type. */
9276 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
9277 if (!str2metric_type(argv
[idx
]->arg
, &type
))
9278 return CMD_WARNING_CONFIG_FAILED
;
9282 if (argv_find(argv
, argc
, "route-map", &idx
))
9283 rtmap
= argv
[idx
+ 1]->arg
;
9285 /* To check if user is providing same route map */
9286 if ((!rtmap
&& !ROUTEMAP_NAME(red
)) ||
9287 (rtmap
&& ROUTEMAP_NAME(red
) &&
9288 (strcmp(rtmap
, ROUTEMAP_NAME(red
)) == 0)))
9291 /* Don't allow if the same lsa is already originated. */
9293 && (red
->dmetric
.type
== type
)
9294 && (red
->dmetric
.value
== metric
)
9295 && (cur_originate
== default_originate
))
9298 /* Updating Metric details */
9299 red
->dmetric
.type
= type
;
9300 red
->dmetric
.value
= metric
;
9302 /* updating route map details */
9304 ospf_routemap_set(red
, rtmap
);
9306 ospf_routemap_unset(red
);
9308 return ospf_redistribute_default_set(ospf
, default_originate
, type
,
9312 DEFUN (no_ospf_default_information_originate
,
9313 no_ospf_default_information_originate_cmd
,
9314 "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9316 "Control distribution of default information\n"
9317 "Distribute a default route\n"
9318 "Always advertise default route\n"
9319 "OSPF default metric\n"
9321 "OSPF metric type for default routes\n"
9322 "Set OSPF External Type 1/2 metrics\n"
9323 "Route map reference\n"
9324 "Pointer to route-map entries\n")
9326 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9327 struct ospf_redist
*red
;
9329 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
9333 ospf_routemap_unset(red
);
9334 ospf_redist_del(ospf
, DEFAULT_ROUTE
, 0);
9336 return ospf_redistribute_default_set(ospf
, DEFAULT_ORIGINATE_NONE
,
9340 DEFUN (ospf_default_metric
,
9341 ospf_default_metric_cmd
,
9342 "default-metric (0-16777214)",
9343 "Set metric of redistributed routes\n"
9346 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9350 if (!str2metric(argv
[idx_number
]->arg
, &metric
))
9351 return CMD_WARNING_CONFIG_FAILED
;
9353 ospf
->default_metric
= metric
;
9358 DEFUN (no_ospf_default_metric
,
9359 no_ospf_default_metric_cmd
,
9360 "no default-metric [(0-16777214)]",
9362 "Set metric of redistributed routes\n"
9365 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9367 ospf
->default_metric
= -1;
9373 DEFUN (ospf_distance
,
9376 "Administrative distance\n"
9377 "OSPF Administrative distance\n")
9379 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9383 distance
= atoi(argv
[idx_number
]->arg
);
9384 if (ospf
->distance_all
!= distance
) {
9385 ospf
->distance_all
= distance
;
9386 ospf_restart_spf(ospf
);
9392 DEFUN (no_ospf_distance
,
9393 no_ospf_distance_cmd
,
9394 "no distance (1-255)",
9396 "Administrative distance\n"
9397 "OSPF Administrative distance\n")
9399 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9401 if (ospf
->distance_all
) {
9402 ospf
->distance_all
= 0;
9403 ospf_restart_spf(ospf
);
9409 DEFUN (no_ospf_distance_ospf
,
9410 no_ospf_distance_ospf_cmd
,
9411 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
9413 "Administrative distance\n"
9414 "OSPF administrative distance\n"
9415 "Intra-area routes\n"
9416 "Distance for intra-area routes\n"
9417 "Inter-area routes\n"
9418 "Distance for inter-area routes\n"
9420 "Distance for external routes\n")
9422 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9425 if (argv_find(argv
, argc
, "intra-area", &idx
) || argc
== 3)
9426 idx
= ospf
->distance_intra
= 0;
9427 if (argv_find(argv
, argc
, "inter-area", &idx
) || argc
== 3)
9428 idx
= ospf
->distance_inter
= 0;
9429 if (argv_find(argv
, argc
, "external", &idx
) || argc
== 3)
9430 ospf
->distance_external
= 0;
9435 DEFUN (ospf_distance_ospf
,
9436 ospf_distance_ospf_cmd
,
9437 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
9438 "Administrative distance\n"
9439 "OSPF administrative distance\n"
9440 "Intra-area routes\n"
9441 "Distance for intra-area routes\n"
9442 "Inter-area routes\n"
9443 "Distance for inter-area routes\n"
9445 "Distance for external routes\n")
9447 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9450 ospf
->distance_intra
= 0;
9451 ospf
->distance_inter
= 0;
9452 ospf
->distance_external
= 0;
9454 if (argv_find(argv
, argc
, "intra-area", &idx
))
9455 ospf
->distance_intra
= atoi(argv
[idx
+ 1]->arg
);
9457 if (argv_find(argv
, argc
, "inter-area", &idx
))
9458 ospf
->distance_inter
= atoi(argv
[idx
+ 1]->arg
);
9460 if (argv_find(argv
, argc
, "external", &idx
))
9461 ospf
->distance_external
= atoi(argv
[idx
+ 1]->arg
);
9466 DEFUN (ip_ospf_mtu_ignore
,
9467 ip_ospf_mtu_ignore_addr_cmd
,
9468 "ip ospf mtu-ignore [A.B.C.D]",
9470 "OSPF interface commands\n"
9471 "Disable MTU mismatch detection on this interface\n"
9472 "Address of interface\n")
9474 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9476 struct in_addr addr
;
9479 struct ospf_if_params
*params
;
9480 params
= IF_DEF_PARAMS(ifp
);
9483 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9486 "Please specify interface address by A.B.C.D\n");
9487 return CMD_WARNING_CONFIG_FAILED
;
9489 params
= ospf_get_if_params(ifp
, addr
);
9490 ospf_if_update_params(ifp
, addr
);
9492 params
->mtu_ignore
= 1;
9493 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
9494 SET_IF_PARAM(params
, mtu_ignore
);
9496 UNSET_IF_PARAM(params
, mtu_ignore
);
9497 if (params
!= IF_DEF_PARAMS(ifp
)) {
9498 ospf_free_if_params(ifp
, addr
);
9499 ospf_if_update_params(ifp
, addr
);
9505 DEFUN (no_ip_ospf_mtu_ignore
,
9506 no_ip_ospf_mtu_ignore_addr_cmd
,
9507 "no ip ospf mtu-ignore [A.B.C.D]",
9510 "OSPF interface commands\n"
9511 "Disable MTU mismatch detection on this interface\n"
9512 "Address of interface\n")
9514 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9516 struct in_addr addr
;
9519 struct ospf_if_params
*params
;
9520 params
= IF_DEF_PARAMS(ifp
);
9523 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9526 "Please specify interface address by A.B.C.D\n");
9527 return CMD_WARNING_CONFIG_FAILED
;
9529 params
= ospf_get_if_params(ifp
, addr
);
9530 ospf_if_update_params(ifp
, addr
);
9532 params
->mtu_ignore
= 0;
9533 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
9534 SET_IF_PARAM(params
, mtu_ignore
);
9536 UNSET_IF_PARAM(params
, mtu_ignore
);
9537 if (params
!= IF_DEF_PARAMS(ifp
)) {
9538 ospf_free_if_params(ifp
, addr
);
9539 ospf_if_update_params(ifp
, addr
);
9546 DEFUN (ospf_max_metric_router_lsa_admin
,
9547 ospf_max_metric_router_lsa_admin_cmd
,
9548 "max-metric router-lsa administrative",
9549 "OSPF maximum / infinite-distance metric\n"
9550 "Advertise own Router-LSA with infinite distance (stub router)\n"
9551 "Administratively applied, for an indefinite period\n")
9553 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9554 struct listnode
*ln
;
9555 struct ospf_area
*area
;
9557 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
9558 SET_FLAG(area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
);
9560 if (!CHECK_FLAG(area
->stub_router_state
,
9561 OSPF_AREA_IS_STUB_ROUTED
))
9562 ospf_router_lsa_update_area(area
);
9565 /* Allows for areas configured later to get the property */
9566 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
;
9571 DEFUN (no_ospf_max_metric_router_lsa_admin
,
9572 no_ospf_max_metric_router_lsa_admin_cmd
,
9573 "no max-metric router-lsa administrative",
9575 "OSPF maximum / infinite-distance metric\n"
9576 "Advertise own Router-LSA with infinite distance (stub router)\n"
9577 "Administratively applied, for an indefinite period\n")
9579 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9580 struct listnode
*ln
;
9581 struct ospf_area
*area
;
9583 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
9584 UNSET_FLAG(area
->stub_router_state
,
9585 OSPF_AREA_ADMIN_STUB_ROUTED
);
9587 /* Don't trample on the start-up stub timer */
9588 if (CHECK_FLAG(area
->stub_router_state
,
9589 OSPF_AREA_IS_STUB_ROUTED
)
9590 && !area
->t_stub_router
) {
9591 UNSET_FLAG(area
->stub_router_state
,
9592 OSPF_AREA_IS_STUB_ROUTED
);
9593 ospf_router_lsa_update_area(area
);
9596 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET
;
9600 DEFUN (ospf_max_metric_router_lsa_startup
,
9601 ospf_max_metric_router_lsa_startup_cmd
,
9602 "max-metric router-lsa on-startup (5-86400)",
9603 "OSPF maximum / infinite-distance metric\n"
9604 "Advertise own Router-LSA with infinite distance (stub router)\n"
9605 "Automatically advertise stub Router-LSA on startup of OSPF\n"
9606 "Time (seconds) to advertise self as stub-router\n")
9608 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9610 unsigned int seconds
;
9613 vty_out(vty
, "%% Must supply stub-router period\n");
9614 return CMD_WARNING_CONFIG_FAILED
;
9617 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9619 ospf
->stub_router_startup_time
= seconds
;
9624 DEFUN (no_ospf_max_metric_router_lsa_startup
,
9625 no_ospf_max_metric_router_lsa_startup_cmd
,
9626 "no max-metric router-lsa on-startup [(5-86400)]",
9628 "OSPF maximum / infinite-distance metric\n"
9629 "Advertise own Router-LSA with infinite distance (stub router)\n"
9630 "Automatically advertise stub Router-LSA on startup of OSPF\n"
9631 "Time (seconds) to advertise self as stub-router\n")
9633 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9634 struct listnode
*ln
;
9635 struct ospf_area
*area
;
9637 ospf
->stub_router_startup_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
9639 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
9640 SET_FLAG(area
->stub_router_state
,
9641 OSPF_AREA_WAS_START_STUB_ROUTED
);
9642 THREAD_OFF(area
->t_stub_router
);
9644 /* Don't trample on admin stub routed */
9645 if (!CHECK_FLAG(area
->stub_router_state
,
9646 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
9647 UNSET_FLAG(area
->stub_router_state
,
9648 OSPF_AREA_IS_STUB_ROUTED
);
9649 ospf_router_lsa_update_area(area
);
9656 DEFUN (ospf_max_metric_router_lsa_shutdown
,
9657 ospf_max_metric_router_lsa_shutdown_cmd
,
9658 "max-metric router-lsa on-shutdown (5-100)",
9659 "OSPF maximum / infinite-distance metric\n"
9660 "Advertise own Router-LSA with infinite distance (stub router)\n"
9661 "Advertise stub-router prior to full shutdown of OSPF\n"
9662 "Time (seconds) to wait till full shutdown\n")
9664 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9666 unsigned int seconds
;
9669 vty_out(vty
, "%% Must supply stub-router shutdown period\n");
9670 return CMD_WARNING_CONFIG_FAILED
;
9673 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9675 ospf
->stub_router_shutdown_time
= seconds
;
9680 DEFUN (no_ospf_max_metric_router_lsa_shutdown
,
9681 no_ospf_max_metric_router_lsa_shutdown_cmd
,
9682 "no max-metric router-lsa on-shutdown [(5-100)]",
9684 "OSPF maximum / infinite-distance metric\n"
9685 "Advertise own Router-LSA with infinite distance (stub router)\n"
9686 "Advertise stub-router prior to full shutdown of OSPF\n"
9687 "Time (seconds) to wait till full shutdown\n")
9689 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9691 ospf
->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
9696 DEFUN (ospf_proactive_arp
,
9697 ospf_proactive_arp_cmd
,
9699 "Allow sending ARP requests proactively\n")
9701 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9703 ospf
->proactive_arp
= true;
9708 DEFUN (no_ospf_proactive_arp
,
9709 no_ospf_proactive_arp_cmd
,
9712 "Disallow sending ARP requests proactively\n")
9714 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9716 ospf
->proactive_arp
= false;
9721 /* Graceful Restart HELPER Commands */
9722 DEFPY(ospf_gr_helper_enable
, ospf_gr_helper_enable_cmd
,
9723 "graceful-restart helper enable [A.B.C.D$address]",
9724 "OSPF Graceful Restart\n"
9726 "Enable Helper support\n"
9727 "Advertising Router-ID\n")
9729 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9732 ospf_gr_helper_support_set_per_routerid(ospf
, &address
,
9737 ospf_gr_helper_support_set(ospf
, OSPF_GR_TRUE
);
9742 DEFPY(no_ospf_gr_helper_enable
,
9743 no_ospf_gr_helper_enable_cmd
,
9744 "no graceful-restart helper enable [A.B.C.D$address]",
9746 "OSPF Graceful Restart\n"
9748 "Enable Helper support\n"
9749 "Advertising Router-ID\n")
9751 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9754 ospf_gr_helper_support_set_per_routerid(ospf
, &address
,
9759 ospf_gr_helper_support_set(ospf
, OSPF_GR_FALSE
);
9763 DEFPY(ospf_gr_helper_enable_lsacheck
,
9764 ospf_gr_helper_enable_lsacheck_cmd
,
9765 "graceful-restart helper strict-lsa-checking",
9766 "OSPF Graceful Restart\n"
9768 "Enable strict LSA check\n")
9770 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9772 ospf_gr_helper_lsa_check_set(ospf
, OSPF_GR_TRUE
);
9776 DEFPY(no_ospf_gr_helper_enable_lsacheck
,
9777 no_ospf_gr_helper_enable_lsacheck_cmd
,
9778 "no graceful-restart helper strict-lsa-checking",
9780 "OSPF Graceful Restart\n"
9782 "Disable strict LSA check\n")
9784 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9786 ospf_gr_helper_lsa_check_set(ospf
, OSPF_GR_FALSE
);
9790 DEFPY(ospf_gr_helper_supported_grace_time
,
9791 ospf_gr_helper_supported_grace_time_cmd
,
9792 "graceful-restart helper supported-grace-time (10-1800)$interval",
9793 "OSPF Graceful Restart\n"
9795 "Supported grace timer\n"
9796 "Grace interval(in seconds)\n")
9798 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9800 ospf_gr_helper_supported_gracetime_set(ospf
, interval
);
9804 DEFPY(no_ospf_gr_helper_supported_grace_time
,
9805 no_ospf_gr_helper_supported_grace_time_cmd
,
9806 "no graceful-restart helper supported-grace-time (10-1800)$interval",
9808 "OSPF Graceful Restart\n"
9810 "Supported grace timer\n"
9811 "Grace interval(in seconds)\n")
9813 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9815 ospf_gr_helper_supported_gracetime_set(ospf
, OSPF_MAX_GRACE_INTERVAL
);
9819 DEFPY(ospf_gr_helper_planned_only
,
9820 ospf_gr_helper_planned_only_cmd
,
9821 "graceful-restart helper planned-only",
9822 "OSPF Graceful Restart\n"
9824 "Supported only planned restart\n")
9826 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9828 ospf_gr_helper_set_supported_planned_only_restart(ospf
, OSPF_GR_TRUE
);
9833 /* External Route Aggregation */
9834 DEFUN (ospf_external_route_aggregation
,
9835 ospf_external_route_aggregation_cmd
,
9836 "summary-address A.B.C.D/M [tag (1-4294967295)]",
9837 "External summary address\n"
9838 "Summary address prefix\n"
9840 "Router tag value\n")
9842 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9843 struct prefix_ipv4 p
;
9845 route_tag_t tag
= 0;
9846 int ret
= OSPF_SUCCESS
;
9848 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
9850 if (is_default_prefix4(&p
)) {
9852 "Default address shouldn't be configured as summary address.\n");
9856 /* Apply mask for given prefix. */
9859 if (!is_valid_summary_addr(&p
)) {
9860 vty_out(vty
, "Not a valid summary address.\n");
9861 return CMD_WARNING_CONFIG_FAILED
;
9865 tag
= strtoul(argv
[idx
+ 2]->arg
, NULL
, 10);
9867 ret
= ospf_asbr_external_aggregator_set(ospf
, &p
, tag
);
9868 if (ret
== OSPF_INVALID
)
9869 vty_out(vty
, "Invalid configuration!!\n");
9874 DEFUN (no_ospf_external_route_aggregation
,
9875 no_ospf_external_route_aggregation_cmd
,
9876 "no summary-address A.B.C.D/M [tag (1-4294967295)]",
9878 "External summary address\n"
9879 "Summary address prefix\n"
9881 "Router tag value\n")
9883 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9884 struct prefix_ipv4 p
;
9886 route_tag_t tag
= 0;
9887 int ret
= OSPF_SUCCESS
;
9889 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
9891 if (is_default_prefix4(&p
)) {
9893 "Default address shouldn't be configured as summary address.\n");
9897 /* Apply mask for given prefix. */
9900 if (!is_valid_summary_addr(&p
)) {
9901 vty_out(vty
, "Not a valid summary address.\n");
9902 return CMD_WARNING_CONFIG_FAILED
;
9906 tag
= strtoul(argv
[idx
+ 2]->arg
, NULL
, 10);
9908 ret
= ospf_asbr_external_aggregator_unset(ospf
, &p
, tag
);
9909 if (ret
== OSPF_INVALID
)
9910 vty_out(vty
, "Invalid configuration!!\n");
9915 DEFPY(no_ospf_gr_helper_planned_only
,
9916 no_ospf_gr_helper_planned_only_cmd
,
9917 "no graceful-restart helper planned-only",
9919 "OSPF Graceful Restart\n"
9921 "Supported only for planned restart\n")
9923 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9925 ospf_gr_helper_set_supported_planned_only_restart(ospf
, OSPF_GR_FALSE
);
9930 static int ospf_print_vty_helper_dis_rtr_walkcb(struct hash_bucket
*bucket
,
9933 struct advRtr
*rtr
= bucket
->data
;
9934 struct vty
*vty
= (struct vty
*)arg
;
9935 static unsigned int count
;
9937 vty_out(vty
, "%-6pI4,", &rtr
->advRtrAddr
);
9943 return HASHWALK_CONTINUE
;
9946 static int ospf_print_json_helper_enabled_rtr_walkcb(struct hash_bucket
*bucket
,
9949 struct advRtr
*rtr
= bucket
->data
;
9950 struct json_object
*json_rid_array
= arg
;
9951 struct json_object
*json_rid
;
9953 json_rid
= json_object_new_object();
9955 json_object_string_addf(json_rid
, "routerId", "%pI4", &rtr
->advRtrAddr
);
9956 json_object_array_add(json_rid_array
, json_rid
);
9958 return HASHWALK_CONTINUE
;
9961 static int ospf_show_gr_helper_details(struct vty
*vty
, struct ospf
*ospf
,
9962 uint8_t use_vrf
, json_object
*json
,
9963 bool uj
, bool detail
)
9965 struct listnode
*node
;
9966 struct ospf_interface
*oi
;
9967 char buf
[PREFIX_STRLEN
];
9968 json_object
*json_vrf
= NULL
;
9972 json_vrf
= json_object_new_object();
9977 if (ospf
->instance
) {
9979 json_object_int_add(json
, "ospfInstance",
9982 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
9985 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
9989 json_object_object_add(json
, ospf_get_name(ospf
),
9994 /* Show Router ID. */
9996 json_object_string_add(json_vrf
, "routerId",
9997 inet_ntop(AF_INET
, &ospf
->router_id
,
10000 vty_out(vty
, "\n OSPF Router with ID (%pI4)\n\n",
10006 if (ospf
->is_helper_supported
)
10008 " Graceful restart helper support enabled.\n");
10011 " Graceful restart helper support disabled.\n");
10013 if (ospf
->strict_lsa_check
)
10014 vty_out(vty
, " Strict LSA check is enabled.\n");
10016 vty_out(vty
, " Strict LSA check is disabled.\n");
10018 if (ospf
->only_planned_restart
)
10020 " Helper supported for planned restarts only.\n");
10023 " Helper supported for Planned and Unplanned Restarts.\n");
10026 " Supported Graceful restart interval: %d(in seconds).\n",
10027 ospf
->supported_grace_time
);
10029 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf
)) {
10030 vty_out(vty
, " Enable Router list:\n");
10032 hash_walk(ospf
->enable_rtr_list
,
10033 ospf_print_vty_helper_dis_rtr_walkcb
, vty
);
10034 vty_out(vty
, "\n\n");
10037 if (ospf
->last_exit_reason
!= OSPF_GR_HELPER_EXIT_NONE
) {
10038 vty_out(vty
, " Last Helper exit Reason :%s\n",
10039 ospf_exit_reason2str(ospf
->last_exit_reason
));
10042 if (ospf
->active_restarter_cnt
)
10044 " Number of Active neighbours in graceful restart: %d\n",
10045 ospf
->active_restarter_cnt
);
10047 vty_out(vty
, "\n");
10050 json_object_string_add(
10051 json_vrf
, "helperSupport",
10052 (ospf
->is_helper_supported
) ? "Enabled" : "Disabled");
10053 json_object_string_add(json_vrf
, "strictLsaCheck",
10054 (ospf
->strict_lsa_check
) ? "Enabled"
10056 json_object_string_add(
10057 json_vrf
, "restartSupoort",
10058 (ospf
->only_planned_restart
)
10059 ? "Planned Restart only"
10060 : "Planned and Unplanned Restarts");
10062 json_object_int_add(json_vrf
, "supportedGracePeriod",
10063 ospf
->supported_grace_time
);
10065 if (ospf
->last_exit_reason
!= OSPF_GR_HELPER_EXIT_NONE
)
10066 json_object_string_add(
10067 json_vrf
, "lastExitReason",
10068 ospf_exit_reason2str(ospf
->last_exit_reason
));
10070 if (ospf
->active_restarter_cnt
)
10071 json_object_int_add(json_vrf
, "activeRestarterCnt",
10072 ospf
->active_restarter_cnt
);
10074 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf
)) {
10075 struct json_object
*json_rid_array
=
10076 json_object_new_array();
10078 json_object_object_add(json_vrf
, "enabledRouterIds",
10081 hash_walk(ospf
->enable_rtr_list
,
10082 ospf_print_json_helper_enabled_rtr_walkcb
,
10090 json_object
*json_neighbors
= NULL
;
10092 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
10093 struct route_node
*rn
;
10094 struct ospf_neighbor
*nbr
;
10095 json_object
*json_neigh
;
10097 if (ospf_interface_neighbor_count(oi
) == 0)
10101 json_object_object_get_ex(json_vrf
, "neighbors",
10103 if (!json_neighbors
) {
10105 json_object_new_object();
10106 json_object_object_add(json_vrf
,
10112 for (rn
= route_top(oi
->nbrs
); rn
;
10113 rn
= route_next(rn
)) {
10120 if (!OSPF_GR_IS_ACTIVE_HELPER(nbr
))
10124 vty_out(vty
, " Neighbour %d :\n", cnt
);
10125 vty_out(vty
, " Address : %pI4\n",
10126 &nbr
->address
.u
.prefix4
);
10127 vty_out(vty
, " Routerid : %pI4\n",
10130 " Received Grace period : %d(in seconds).\n",
10131 nbr
->gr_helper_info
10132 .recvd_grace_period
);
10134 " Actual Grace period : %d(in seconds)\n",
10135 nbr
->gr_helper_info
10136 .actual_grace_period
);
10138 " Remaining GraceTime:%ld(in seconds).\n",
10139 thread_timer_remain_second(
10140 nbr
->gr_helper_info
10143 " Graceful Restart reason: %s.\n\n",
10144 ospf_restart_reason2str(
10145 nbr
->gr_helper_info
10146 .gr_restart_reason
));
10149 json_neigh
= json_object_new_object();
10150 json_object_string_add(
10151 json_neigh
, "srcAddr",
10152 inet_ntop(AF_INET
, &nbr
->src
,
10153 buf
, sizeof(buf
)));
10155 json_object_string_add(
10156 json_neigh
, "routerid",
10159 buf
, sizeof(buf
)));
10160 json_object_int_add(
10162 "recvdGraceInterval",
10163 nbr
->gr_helper_info
10164 .recvd_grace_period
);
10165 json_object_int_add(
10167 "actualGraceInterval",
10168 nbr
->gr_helper_info
10169 .actual_grace_period
);
10170 json_object_int_add(
10171 json_neigh
, "remainGracetime",
10172 thread_timer_remain_second(
10173 nbr
->gr_helper_info
10175 json_object_string_add(
10176 json_neigh
, "restartReason",
10177 ospf_restart_reason2str(
10178 nbr
->gr_helper_info
10179 .gr_restart_reason
));
10180 json_object_object_add(
10182 inet_ntop(AF_INET
, &nbr
->src
,
10189 return CMD_SUCCESS
;
10192 DEFUN (ospf_external_route_aggregation_no_adrvertise
,
10193 ospf_external_route_aggregation_no_adrvertise_cmd
,
10194 "summary-address A.B.C.D/M no-advertise",
10195 "External summary address\n"
10196 "Summary address prefix\n"
10197 "Don't advertise summary route \n")
10199 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10200 struct prefix_ipv4 p
;
10202 int ret
= OSPF_SUCCESS
;
10204 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
10206 if (is_default_prefix4(&p
)) {
10208 "Default address shouldn't be configured as summary address.\n");
10209 return CMD_SUCCESS
;
10212 /* Apply mask for given prefix. */
10215 if (!is_valid_summary_addr(&p
)) {
10216 vty_out(vty
, "Not a valid summary address.\n");
10217 return CMD_WARNING_CONFIG_FAILED
;
10220 ret
= ospf_asbr_external_rt_no_advertise(ospf
, &p
);
10221 if (ret
== OSPF_INVALID
)
10222 vty_out(vty
, "Invalid configuration!!\n");
10224 return CMD_SUCCESS
;
10227 DEFUN (no_ospf_external_route_aggregation_no_adrvertise
,
10228 no_ospf_external_route_aggregation_no_adrvertise_cmd
,
10229 "no summary-address A.B.C.D/M no-advertise",
10231 "External summary address\n"
10232 "Summary address prefix\n"
10233 "Advertise summary route to the AS \n")
10235 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10236 struct prefix_ipv4 p
;
10238 int ret
= OSPF_SUCCESS
;
10240 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
10242 if (is_default_prefix4(&p
)) {
10244 "Default address shouldn't be configured as summary address.\n");
10245 return CMD_SUCCESS
;
10248 /* Apply mask for given prefix. */
10251 if (!is_valid_summary_addr(&p
)) {
10252 vty_out(vty
, "Not a valid summary address.\n");
10253 return CMD_WARNING_CONFIG_FAILED
;
10256 ret
= ospf_asbr_external_rt_advertise(ospf
, &p
);
10257 if (ret
== OSPF_INVALID
)
10258 vty_out(vty
, "Invalid configuration!!\n");
10260 return CMD_SUCCESS
;
10263 DEFUN (ospf_route_aggregation_timer
,
10264 ospf_route_aggregation_timer_cmd
,
10265 "aggregation timer (5-1800)",
10266 "External route aggregation\n"
10267 "Delay timer (in seconds)\n"
10268 "Timer interval(in seconds)\n")
10270 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10271 uint16_t interval
= 0;
10273 interval
= strtoul(argv
[2]->arg
, NULL
, 10);
10275 ospf_external_aggregator_timer_set(ospf
, interval
);
10277 return CMD_SUCCESS
;
10280 DEFPY (show_ip_ospf_gr_helper
,
10281 show_ip_ospf_gr_helper_cmd
,
10282 "show ip ospf [vrf <NAME|all>] graceful-restart helper [detail] [json]",
10285 "OSPF information\n"
10288 "OSPF Graceful Restart\n"
10289 "Helper details in the router\n"
10290 "Detailed information\n"
10293 char *vrf_name
= NULL
;
10294 bool all_vrf
= false;
10295 int ret
= CMD_SUCCESS
;
10298 uint8_t use_vrf
= 0;
10299 bool uj
= use_json(argc
, argv
);
10300 struct ospf
*ospf
= NULL
;
10301 json_object
*json
= NULL
;
10302 struct listnode
*node
= NULL
;
10304 bool detail
= false;
10306 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
10308 if (argv_find(argv
, argc
, "detail", &idx
))
10312 json
= json_object_new_object();
10314 /* vrf input is provided */
10319 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
10320 if (!ospf
->oi_running
)
10323 ret
= ospf_show_gr_helper_details(
10324 vty
, ospf
, use_vrf
, json
, uj
, detail
);
10328 vty_json(vty
, json
);
10333 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
10335 if (ospf
== NULL
|| !ospf
->oi_running
) {
10338 vty_json(vty
, json
);
10341 "%% OSPF is not enabled in vrf %s\n",
10344 return CMD_SUCCESS
;
10349 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
10351 if (ospf
== NULL
|| !ospf
->oi_running
) {
10354 vty_json(vty
, json
);
10357 "%% OSPF is not enabled in vrf default\n");
10359 return CMD_SUCCESS
;
10362 ospf_show_gr_helper_details(vty
, ospf
, use_vrf
, json
, uj
,
10367 vty_json(vty
, json
);
10369 return CMD_SUCCESS
;
10371 /* Graceful Restart HELPER commands end */
10372 DEFUN (no_ospf_route_aggregation_timer
,
10373 no_ospf_route_aggregation_timer_cmd
,
10374 "no aggregation timer",
10376 "External route aggregation\n"
10379 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10381 ospf_external_aggregator_timer_set(ospf
, OSPF_EXTL_AGGR_DEFAULT_DELAY
);
10383 return CMD_SUCCESS
;
10386 /* External Route Aggregation End */
10388 static void config_write_stub_router(struct vty
*vty
, struct ospf
*ospf
)
10390 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
10391 vty_out(vty
, " max-metric router-lsa on-startup %u\n",
10392 ospf
->stub_router_startup_time
);
10393 if (ospf
->stub_router_shutdown_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
10394 vty_out(vty
, " max-metric router-lsa on-shutdown %u\n",
10395 ospf
->stub_router_shutdown_time
);
10396 if (ospf
->stub_router_admin_set
== OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
)
10397 vty_out(vty
, " max-metric router-lsa administrative\n");
10402 static void show_ip_ospf_route_network(struct vty
*vty
, struct ospf
*ospf
,
10403 struct route_table
*rt
,
10406 struct route_node
*rn
;
10407 struct ospf_route
* or ;
10408 struct listnode
*pnode
, *pnnode
;
10409 struct ospf_path
*path
;
10410 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
10411 *json_nexthop
= NULL
;
10415 "============ OSPF network routing table ============\n");
10417 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
10418 char buf1
[PREFIX2STR_BUFFER
];
10420 if ((or = rn
->info
) == NULL
)
10423 prefix2str(&rn
->p
, buf1
, sizeof(buf1
));
10426 json_route
= json_object_new_object();
10427 json_object_object_add(json
, buf1
, json_route
);
10430 switch (or->path_type
) {
10431 case OSPF_PATH_INTER_AREA
:
10432 if (or->type
== OSPF_DESTINATION_NETWORK
) {
10434 json_object_string_add(json_route
,
10437 json_object_int_add(json_route
, "cost",
10439 json_object_string_addf(
10440 json_route
, "area", "%pI4",
10441 &or->u
.std
.area_id
);
10444 "N IA %-18s [%d] area: %pI4\n",
10446 &or->u
.std
.area_id
);
10448 } else if (or->type
== OSPF_DESTINATION_DISCARD
) {
10450 json_object_string_add(json_route
,
10455 "D IA %-18s Discard entry\n",
10460 case OSPF_PATH_INTRA_AREA
:
10462 json_object_string_add(json_route
, "routeType",
10464 json_object_int_add(json_route
, "cost",
10466 json_object_string_addf(json_route
, "area",
10468 &or->u
.std
.area_id
);
10470 vty_out(vty
, "N %-18s [%d] area: %pI4\n",
10472 &or->u
.std
.area_id
);
10479 if (or->type
== OSPF_DESTINATION_NETWORK
) {
10481 json_nexthop_array
= json_object_new_array();
10482 json_object_object_add(json_route
, "nexthops",
10483 json_nexthop_array
);
10486 for (ALL_LIST_ELEMENTS(or->paths
, pnode
, pnnode
,
10489 json_nexthop
= json_object_new_object();
10490 json_object_array_add(
10491 json_nexthop_array
,
10494 if (if_lookup_by_index(path
->ifindex
,
10497 if (path
->nexthop
.s_addr
10500 json_object_string_add(
10503 json_object_string_add(
10505 "directlyAttachedTo",
10511 "%24s directly attached to %s\n",
10519 json_object_string_addf(
10523 json_object_string_add(
10531 "%24s via %pI4, %s\n",
10544 vty_out(vty
, "\n");
10547 static void show_ip_ospf_route_router(struct vty
*vty
, struct ospf
*ospf
,
10548 struct route_table
*rtrs
,
10551 struct route_node
*rn
;
10552 struct ospf_route
* or ;
10553 struct listnode
*pnode
;
10554 struct listnode
*node
;
10555 struct ospf_path
*path
;
10556 char buf
[PREFIX_STRLEN
];
10557 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
10558 *json_nexthop
= NULL
;
10561 vty_out(vty
, "============ OSPF %s table =============\n",
10562 ospf
->all_rtrs
== rtrs
? "reachable routers"
10563 : "router routing");
10565 for (rn
= route_top(rtrs
); rn
; rn
= route_next(rn
)) {
10566 if (rn
->info
== NULL
)
10571 json_route
= json_object_new_object();
10572 json_object_object_add(
10573 json
, inet_ntop(AF_INET
, &rn
->p
.u
.prefix4
,
10576 json_object_string_add(json_route
, "routeType", "R ");
10578 vty_out(vty
, "R %-15pI4 ",
10582 for (ALL_LIST_ELEMENTS_RO((struct list
*)rn
->info
, node
, or)) {
10585 vty_out(vty
, "%24s", "");
10590 json_object_int_add(json_route
, "cost",
10592 json_object_string_addf(json_route
, "area",
10594 &or->u
.std
.area_id
);
10595 if (or->path_type
== OSPF_PATH_INTER_AREA
) {
10596 json_object_boolean_true_add(json_route
,
10598 json_object_boolean_true_add(json_route
,
10601 if (or->u
.std
.flags
& ROUTER_LSA_BORDER
)
10602 json_object_string_add(json_route
,
10605 else if (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
)
10606 json_object_string_add(json_route
,
10610 vty_out(vty
, "%s [%d] area: %pI4",
10611 (or->path_type
== OSPF_PATH_INTER_AREA
10614 or->cost
, &or->u
.std
.area_id
);
10616 vty_out(vty
, "%s%s\n",
10617 (or->u
.std
.flags
& ROUTER_LSA_BORDER
10620 (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
10626 json_nexthop_array
= json_object_new_array();
10627 json_object_object_add(json_route
, "nexthops",
10628 json_nexthop_array
);
10631 for (ALL_LIST_ELEMENTS_RO(or->paths
, pnode
, path
)) {
10633 json_nexthop
= json_object_new_object();
10634 json_object_array_add(
10635 json_nexthop_array
,
10638 if (if_lookup_by_index(path
->ifindex
,
10640 if (path
->nexthop
.s_addr
10643 json_object_string_add(
10646 json_object_string_add(
10648 "directlyAttachedTo",
10654 "%24s directly attached to %s\n",
10662 json_object_string_addf(
10666 json_object_string_add(
10674 "%24s via %pI4, %s\n",
10687 vty_out(vty
, "\n");
10690 static void show_ip_ospf_route_external(struct vty
*vty
, struct ospf
*ospf
,
10691 struct route_table
*rt
,
10694 struct route_node
*rn
;
10695 struct ospf_route
*er
;
10696 struct listnode
*pnode
, *pnnode
;
10697 struct ospf_path
*path
;
10698 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
10699 *json_nexthop
= NULL
;
10703 "============ OSPF external routing table ===========\n");
10705 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
10706 if ((er
= rn
->info
) == NULL
)
10711 snprintfrr(buf1
, sizeof(buf1
), "%pFX", &rn
->p
);
10713 json_route
= json_object_new_object();
10714 json_object_object_add(json
, buf1
, json_route
);
10717 switch (er
->path_type
) {
10718 case OSPF_PATH_TYPE1_EXTERNAL
:
10720 json_object_string_add(json_route
, "routeType",
10722 json_object_int_add(json_route
, "cost",
10724 json_object_int_add(json_route
, "tag",
10728 "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI
10730 buf1
, er
->cost
, er
->u
.ext
.tag
);
10733 case OSPF_PATH_TYPE2_EXTERNAL
:
10735 json_object_string_add(json_route
, "routeType",
10737 json_object_int_add(json_route
, "cost",
10739 json_object_int_add(json_route
, "type2cost",
10740 er
->u
.ext
.type2_cost
);
10741 json_object_int_add(json_route
, "tag",
10745 "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI
10747 buf1
, er
->cost
, er
->u
.ext
.type2_cost
,
10754 json_nexthop_array
= json_object_new_array();
10755 json_object_object_add(json_route
, "nexthops",
10756 json_nexthop_array
);
10759 for (ALL_LIST_ELEMENTS(er
->paths
, pnode
, pnnode
, path
)) {
10761 json_nexthop
= json_object_new_object();
10762 json_object_array_add(json_nexthop_array
,
10766 if (if_lookup_by_index(path
->ifindex
, ospf
->vrf_id
)) {
10767 if (path
->nexthop
.s_addr
== INADDR_ANY
) {
10769 json_object_string_add(
10770 json_nexthop
, "ip",
10772 json_object_string_add(
10774 "directlyAttachedTo",
10780 "%24s directly attached to %s\n",
10788 json_object_string_addf(
10789 json_nexthop
, "ip",
10790 "%pI4", &path
->nexthop
);
10791 json_object_string_add(
10792 json_nexthop
, "via",
10798 "%24s via %pI4, %s\n",
10810 vty_out(vty
, "\n");
10813 static int show_ip_ospf_reachable_routers_common(struct vty
*vty
,
10817 if (ospf
->instance
)
10818 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
10820 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
10822 if (ospf
->all_rtrs
== NULL
) {
10823 vty_out(vty
, "No OSPF reachable router information exist\n");
10824 return CMD_SUCCESS
;
10827 /* Show Router routes. */
10828 show_ip_ospf_route_router(vty
, ospf
, ospf
->all_rtrs
, NULL
);
10830 vty_out(vty
, "\n");
10832 return CMD_SUCCESS
;
10835 DEFUN (show_ip_ospf_reachable_routers
,
10836 show_ip_ospf_reachable_routers_cmd
,
10837 "show ip ospf [vrf <NAME|all>] reachable-routers",
10840 "OSPF information\n"
10843 "Show all the reachable OSPF routers\n")
10845 struct ospf
*ospf
= NULL
;
10846 struct listnode
*node
= NULL
;
10847 char *vrf_name
= NULL
;
10848 bool all_vrf
= false;
10849 int ret
= CMD_SUCCESS
;
10852 uint8_t use_vrf
= 0;
10854 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
10857 bool ospf_output
= false;
10862 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
10863 if (!ospf
->oi_running
)
10866 ospf_output
= true;
10867 ret
= show_ip_ospf_reachable_routers_common(
10868 vty
, ospf
, use_vrf
);
10872 vty_out(vty
, "%% OSPF instance not found\n");
10874 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
10875 if (ospf
== NULL
|| !ospf
->oi_running
) {
10876 vty_out(vty
, "%% OSPF instance not found\n");
10877 return CMD_SUCCESS
;
10880 ret
= show_ip_ospf_reachable_routers_common(vty
, ospf
,
10884 /* Display default ospf (instance 0) info */
10885 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
10886 if (ospf
== NULL
|| !ospf
->oi_running
) {
10887 vty_out(vty
, "%% OSPF instance not found\n");
10888 return CMD_SUCCESS
;
10891 ret
= show_ip_ospf_reachable_routers_common(vty
, ospf
, use_vrf
);
10897 DEFUN (show_ip_ospf_instance_reachable_routers
,
10898 show_ip_ospf_instance_reachable_routers_cmd
,
10899 "show ip ospf (1-65535) reachable-routers",
10902 "OSPF information\n"
10904 "Show all the reachable OSPF routers\n")
10906 int idx_number
= 3;
10908 unsigned short instance
= 0;
10910 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
10911 if (instance
!= ospf_instance
)
10912 return CMD_NOT_MY_INSTANCE
;
10914 ospf
= ospf_lookup_instance(instance
);
10915 if (!ospf
|| !ospf
->oi_running
)
10916 return CMD_SUCCESS
;
10918 return show_ip_ospf_reachable_routers_common(vty
, ospf
, 0);
10921 static int show_ip_ospf_border_routers_common(struct vty
*vty
,
10926 json_object
*json_vrf
= NULL
;
10927 json_object
*json_router
= NULL
;
10931 json_vrf
= json_object_new_object();
10934 json_router
= json_object_new_object();
10937 if (ospf
->instance
) {
10939 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
10941 json_object_int_add(json_vrf
, "ospfInstance",
10945 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
10947 if (ospf
->new_table
== NULL
) {
10949 vty_out(vty
, "No OSPF routing information exist\n");
10951 json_object_free(json_router
);
10953 json_object_free(json_vrf
);
10955 return CMD_SUCCESS
;
10958 /* Show Network routes.
10959 show_ip_ospf_route_network (vty, ospf->new_table); */
10961 /* Show Router routes. */
10962 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, json_router
);
10965 json_object_object_add(json_vrf
, "routers", json_router
);
10967 if (ospf
->vrf_id
== VRF_DEFAULT
)
10968 json_object_object_add(json
, "default",
10971 json_object_object_add(json
, ospf
->name
,
10975 vty_out(vty
, "\n");
10978 return CMD_SUCCESS
;
10981 DEFPY (show_ip_ospf_border_routers
,
10982 show_ip_ospf_border_routers_cmd
,
10983 "show ip ospf [vrf <NAME|all>] border-routers [json]",
10986 "OSPF information\n"
10989 "Show all the ABR's and ASBR's\n"
10992 struct ospf
*ospf
= NULL
;
10993 struct listnode
*node
= NULL
;
10994 char *vrf_name
= NULL
;
10995 bool all_vrf
= false;
10996 int ret
= CMD_SUCCESS
;
10999 uint8_t use_vrf
= 0;
11000 bool uj
= use_json(argc
, argv
);
11001 json_object
*json
= NULL
;
11004 json
= json_object_new_object();
11006 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11009 bool ospf_output
= false;
11014 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11015 if (!ospf
->oi_running
)
11018 ospf_output
= true;
11019 ret
= show_ip_ospf_border_routers_common(
11020 vty
, ospf
, use_vrf
, json
);
11024 vty_json(vty
, json
);
11025 else if (!ospf_output
)
11026 vty_out(vty
, "%% OSPF is not enabled\n");
11030 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11031 if (ospf
== NULL
|| !ospf
->oi_running
) {
11033 vty_json(vty
, json
);
11036 "%% OSPF is not enabled in vrf %s\n",
11039 return CMD_SUCCESS
;
11043 /* Display default ospf (instance 0) info */
11044 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11045 if (ospf
== NULL
|| !ospf
->oi_running
) {
11047 vty_json(vty
, json
);
11050 "%% OSPF is not enabled in vrf default\n");
11052 return CMD_SUCCESS
;
11057 ret
= show_ip_ospf_border_routers_common(vty
, ospf
, use_vrf
,
11060 vty_json(vty
, json
);
11066 DEFUN (show_ip_ospf_instance_border_routers
,
11067 show_ip_ospf_instance_border_routers_cmd
,
11068 "show ip ospf (1-65535) border-routers",
11071 "OSPF information\n"
11073 "Show all the ABR's and ASBR's\n")
11075 int idx_number
= 3;
11077 unsigned short instance
= 0;
11079 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
11080 if (instance
!= ospf_instance
)
11081 return CMD_NOT_MY_INSTANCE
;
11083 ospf
= ospf_lookup_instance(instance
);
11084 if (!ospf
|| !ospf
->oi_running
)
11085 return CMD_SUCCESS
;
11087 return show_ip_ospf_border_routers_common(vty
, ospf
, 0, NULL
);
11090 static int show_ip_ospf_route_common(struct vty
*vty
, struct ospf
*ospf
,
11091 json_object
*json
, uint8_t use_vrf
)
11093 json_object
*json_vrf
= NULL
;
11095 if (ospf
->instance
)
11096 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
11101 json_vrf
= json_object_new_object();
11106 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
11108 if (ospf
->new_table
== NULL
) {
11111 json_object_free(json_vrf
);
11113 vty_out(vty
, "No OSPF routing information exist\n");
11115 return CMD_SUCCESS
;
11118 /* Show Network routes. */
11119 show_ip_ospf_route_network(vty
, ospf
, ospf
->new_table
, json_vrf
);
11121 /* Show Router routes. */
11122 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, json_vrf
);
11124 /* Show Router routes. */
11125 if (ospf
->all_rtrs
)
11126 show_ip_ospf_route_router(vty
, ospf
, ospf
->all_rtrs
, json_vrf
);
11128 /* Show AS External routes. */
11129 show_ip_ospf_route_external(vty
, ospf
, ospf
->old_external_route
,
11134 // json_object_object_add(json_vrf, "areas",
11136 json_object_object_add(json
, ospf_get_name(ospf
),
11140 vty_out(vty
, "\n");
11143 return CMD_SUCCESS
;
11146 DEFUN (show_ip_ospf_route
,
11147 show_ip_ospf_route_cmd
,
11148 "show ip ospf [vrf <NAME|all>] route [json]",
11151 "OSPF information\n"
11154 "OSPF routing table\n"
11157 struct ospf
*ospf
= NULL
;
11158 struct listnode
*node
= NULL
;
11159 char *vrf_name
= NULL
;
11160 bool all_vrf
= false;
11161 int ret
= CMD_SUCCESS
;
11164 uint8_t use_vrf
= 0;
11165 bool uj
= use_json(argc
, argv
);
11166 json_object
*json
= NULL
;
11169 json
= json_object_new_object();
11171 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11173 /* vrf input is provided could be all or specific vrf*/
11175 bool ospf_output
= false;
11180 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11181 if (!ospf
->oi_running
)
11183 ospf_output
= true;
11184 ret
= show_ip_ospf_route_common(vty
, ospf
, json
,
11189 /* Keep Non-pretty format */
11190 vty_json(vty
, json
);
11191 } else if (!ospf_output
)
11192 vty_out(vty
, "%% OSPF is not enabled\n");
11196 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11197 if (ospf
== NULL
|| !ospf
->oi_running
) {
11199 vty_json(vty
, json
);
11202 "%% OSPF is not enabled in vrf %s\n",
11205 return CMD_SUCCESS
;
11208 /* Display default ospf (instance 0) info */
11209 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11210 if (ospf
== NULL
|| !ospf
->oi_running
) {
11212 vty_json(vty
, json
);
11215 "%% OSPF is not enabled in vrf default\n");
11217 return CMD_SUCCESS
;
11222 ret
= show_ip_ospf_route_common(vty
, ospf
, json
, use_vrf
);
11223 /* Keep Non-pretty format */
11225 vty_out(vty
, "%s\n",
11226 json_object_to_json_string_ext(
11227 json
, JSON_C_TO_STRING_NOSLASHESCAPE
));
11231 json_object_free(json
);
11236 DEFUN (show_ip_ospf_instance_route
,
11237 show_ip_ospf_instance_route_cmd
,
11238 "show ip ospf (1-65535) route",
11241 "OSPF information\n"
11243 "OSPF routing table\n")
11245 int idx_number
= 3;
11247 unsigned short instance
= 0;
11249 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
11250 if (instance
!= ospf_instance
)
11251 return CMD_NOT_MY_INSTANCE
;
11253 ospf
= ospf_lookup_instance(instance
);
11254 if (!ospf
|| !ospf
->oi_running
)
11255 return CMD_SUCCESS
;
11257 return show_ip_ospf_route_common(vty
, ospf
, NULL
, 0);
11261 DEFUN (show_ip_ospf_vrfs
,
11262 show_ip_ospf_vrfs_cmd
,
11263 "show ip ospf vrfs [json]",
11266 "OSPF information\n"
11267 "Show OSPF VRFs \n"
11270 bool uj
= use_json(argc
, argv
);
11271 json_object
*json
= NULL
;
11272 json_object
*json_vrfs
= NULL
;
11273 struct ospf
*ospf
= NULL
;
11274 struct listnode
*node
= NULL
;
11276 static const char header
[] = "Name Id RouterId ";
11279 json
= json_object_new_object();
11280 json_vrfs
= json_object_new_object();
11283 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11284 json_object
*json_vrf
= NULL
;
11285 const char *name
= NULL
;
11286 int64_t vrf_id_ui
= 0;
11290 if (!uj
&& count
== 1)
11291 vty_out(vty
, "%s\n", header
);
11293 json_vrf
= json_object_new_object();
11295 name
= ospf_get_name(ospf
);
11297 vrf_id_ui
= (ospf
->vrf_id
== VRF_UNKNOWN
)
11299 : (int64_t)ospf
->vrf_id
;
11302 json_object_int_add(json_vrf
, "vrfId", vrf_id_ui
);
11303 json_object_string_addf(json_vrf
, "routerId", "%pI4",
11306 json_object_object_add(json_vrfs
, name
, json_vrf
);
11309 vty_out(vty
, "%-25s %-5d %-16pI4 \n", name
,
11310 ospf
->vrf_id
, &ospf
->router_id
);
11315 json_object_object_add(json
, "vrfs", json_vrfs
);
11316 json_object_int_add(json
, "totalVrfs", count
);
11318 vty_json(vty
, json
);
11321 vty_out(vty
, "\nTotal number of OSPF VRFs: %d\n",
11325 return CMD_SUCCESS
;
11327 DEFPY (clear_ip_ospf_neighbor
,
11328 clear_ip_ospf_neighbor_cmd
,
11329 "clear ip ospf [(1-65535)]$instance neighbor [A.B.C.D$nbr_id]",
11332 "OSPF information\n"
11334 "Reset OSPF Neighbor\n"
11337 struct listnode
*node
;
11338 struct ospf
*ospf
= NULL
;
11340 /* If user does not specify the arguments,
11341 * instance = 0 and nbr_id = 0.0.0.0
11343 if (instance
!= 0) {
11344 /* This means clear only the particular ospf process */
11345 if (instance
!= ospf_instance
)
11346 return CMD_NOT_MY_INSTANCE
;
11349 /* Clear all the ospf processes */
11350 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11351 if (!ospf
->oi_running
)
11354 if (nbr_id_str
&& IPV4_ADDR_SAME(&ospf
->router_id
, &nbr_id
)) {
11355 vty_out(vty
, "Self router-id is not allowed.\r\n ");
11356 return CMD_SUCCESS
;
11359 ospf_neighbor_reset(ospf
, nbr_id
, nbr_id_str
);
11362 return CMD_SUCCESS
;
11365 DEFPY (clear_ip_ospf_process
,
11366 clear_ip_ospf_process_cmd
,
11367 "clear ip ospf [(1-65535)]$instance process",
11370 "OSPF information\n"
11372 "Reset OSPF Process\n")
11374 struct listnode
*node
;
11375 struct ospf
*ospf
= NULL
;
11377 /* Check if instance is not passed as an argument */
11378 if (instance
!= 0) {
11379 /* This means clear only the particular ospf process */
11380 if (instance
!= ospf_instance
)
11381 return CMD_NOT_MY_INSTANCE
;
11384 /* Clear all the ospf processes */
11385 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11386 if (!ospf
->oi_running
)
11389 ospf_process_reset(ospf
);
11392 return CMD_SUCCESS
;
11395 static const char *const ospf_abr_type_str
[] = {
11396 "unknown", "standard", "ibm", "cisco", "shortcut"
11399 static const char *const ospf_shortcut_mode_str
[] = {
11400 "default", "enable", "disable"
11402 static int ospf_vty_external_rt_walkcb(struct hash_bucket
*bucket
,
11405 struct external_info
*ei
= bucket
->data
;
11406 struct vty
*vty
= (struct vty
*)arg
;
11407 static unsigned int count
;
11409 vty_out(vty
, "%-4pI4/%d, ", &ei
->p
.prefix
, ei
->p
.prefixlen
);
11412 if (count
% 5 == 0)
11413 vty_out(vty
, "\n");
11415 if (OSPF_EXTERNAL_RT_COUNT(ei
->aggr_route
) == count
)
11418 return HASHWALK_CONTINUE
;
11421 static int ospf_json_external_rt_walkcb(struct hash_bucket
*bucket
,
11424 struct external_info
*ei
= bucket
->data
;
11425 struct json_object
*json
= (struct json_object
*)arg
;
11426 char buf
[PREFIX2STR_BUFFER
];
11428 static unsigned int count
;
11430 prefix2str(&ei
->p
, buf
, sizeof(buf
));
11432 snprintf(exnalbuf
, 20, "Exnl Addr-%d", count
);
11434 json_object_string_add(json
, exnalbuf
, buf
);
11438 if (OSPF_EXTERNAL_RT_COUNT(ei
->aggr_route
) == count
)
11441 return HASHWALK_CONTINUE
;
11444 static int ospf_show_summary_address(struct vty
*vty
, struct ospf
*ospf
,
11445 uint8_t use_vrf
, json_object
*json
,
11446 bool uj
, bool detail
)
11448 struct route_node
*rn
;
11449 json_object
*json_vrf
= NULL
;
11452 static char header
[] =
11453 "Summary-address Metric-type Metric Tag External_Rt_count\n";
11455 mtype
= metric_type(ospf
, 0, ospf
->instance
);
11456 mval
= metric_value(ospf
, 0, ospf
->instance
);
11459 vty_out(vty
, "%s\n", header
);
11463 json_vrf
= json_object_new_object();
11468 if (ospf
->instance
) {
11470 json_object_int_add(json
, "ospfInstance",
11473 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
11476 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
11479 vty_out(vty
, "aggregation delay interval :%u(in seconds)\n\n",
11480 ospf
->aggr_delay_interval
);
11482 json_object_int_add(json_vrf
, "aggregationDelayInterval",
11483 ospf
->aggr_delay_interval
);
11486 for (rn
= route_top(ospf
->rt_aggr_tbl
); rn
; rn
= route_next(rn
))
11488 struct ospf_external_aggr_rt
*aggr
= rn
->info
;
11489 json_object
*json_aggr
= NULL
;
11490 char buf
[PREFIX2STR_BUFFER
];
11492 prefix2str(&aggr
->p
, buf
, sizeof(buf
));
11496 json_aggr
= json_object_new_object();
11498 json_object_object_add(json_vrf
, buf
,
11500 json_object_string_add(json_aggr
,
11501 "summaryAddress", buf
);
11502 json_object_string_add(
11503 json_aggr
, "metricType",
11504 (mtype
== EXTERNAL_METRIC_TYPE_1
)
11508 json_object_int_add(json_aggr
, "metric", mval
);
11509 json_object_int_add(json_aggr
, "tag",
11511 json_object_int_add(
11512 json_aggr
, "externalRouteCount",
11513 OSPF_EXTERNAL_RT_COUNT(aggr
));
11515 if (OSPF_EXTERNAL_RT_COUNT(aggr
) && detail
) {
11517 aggr
->match_extnl_hash
,
11518 ospf_json_external_rt_walkcb
,
11523 vty_out(vty
, "%-20s", buf
);
11525 (mtype
== EXTERNAL_METRIC_TYPE_1
)
11526 ? vty_out(vty
, "%-16s", "E1")
11527 : vty_out(vty
, "%-16s", "E2");
11528 vty_out(vty
, "%-11d", mval
);
11530 vty_out(vty
, "%-12u", aggr
->tag
);
11532 vty_out(vty
, "%-5ld\n",
11533 OSPF_EXTERNAL_RT_COUNT(aggr
));
11535 if (OSPF_EXTERNAL_RT_COUNT(aggr
) && detail
) {
11537 "Matched External routes:\n");
11539 aggr
->match_extnl_hash
,
11540 ospf_vty_external_rt_walkcb
,
11542 vty_out(vty
, "\n");
11545 vty_out(vty
, "\n");
11551 json_object_object_add(json
, ospf_get_name(ospf
),
11554 vty_out(vty
, "\n");
11556 return CMD_SUCCESS
;
11559 DEFUN (show_ip_ospf_external_aggregator
,
11560 show_ip_ospf_external_aggregator_cmd
,
11561 "show ip ospf [vrf <NAME|all>] summary-address [detail] [json]",
11563 "OSPF information\n"
11566 "Show external summary addresses\n"
11567 "Detailed information\n"
11570 char *vrf_name
= NULL
;
11571 bool all_vrf
= false;
11572 int ret
= CMD_SUCCESS
;
11575 uint8_t use_vrf
= 0;
11576 bool uj
= use_json(argc
, argv
);
11577 struct ospf
*ospf
= NULL
;
11578 json_object
*json
= NULL
;
11579 struct listnode
*node
= NULL
;
11581 bool detail
= false;
11583 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11585 if (argv_find(argv
, argc
, "detail", &idx
))
11589 json
= json_object_new_object();
11591 /* vrf input is provided */
11595 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11596 if (!ospf
->oi_running
)
11598 ret
= ospf_show_summary_address(
11599 vty
, ospf
, use_vrf
, json
, uj
, detail
);
11603 vty_json(vty
, json
);
11608 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11610 if (ospf
== NULL
|| !ospf
->oi_running
) {
11612 vty_json(vty
, json
);
11615 "%% OSPF is not enabled in vrf %s\n",
11618 return CMD_SUCCESS
;
11620 ospf_show_summary_address(vty
, ospf
, use_vrf
, json
, uj
, detail
);
11624 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11625 if (ospf
== NULL
|| !ospf
->oi_running
) {
11627 vty_json(vty
, json
);
11630 "%% OSPF is not enabled in vrf default\n");
11632 return CMD_SUCCESS
;
11635 ospf_show_summary_address(vty
, ospf
, use_vrf
, json
, uj
, detail
);
11639 vty_json(vty
, json
);
11640 return CMD_SUCCESS
;
11643 static const char *const ospf_int_type_str
[] = {
11644 "unknown", /* should never be used. */
11648 "point-to-multipoint",
11649 "virtual-link", /* should never be used. */
11653 static const char *interface_config_auth_str(struct ospf_if_params
*params
)
11655 if (!OSPF_IF_PARAM_CONFIGURED(params
, auth_type
)
11656 || params
->auth_type
== OSPF_AUTH_NOTSET
)
11659 /* Translation tables are not that much help
11660 * here due to syntax
11661 * of the simple option */
11662 switch (params
->auth_type
) {
11664 case OSPF_AUTH_NULL
:
11667 case OSPF_AUTH_SIMPLE
:
11670 case OSPF_AUTH_CRYPTOGRAPHIC
:
11671 return " message-digest";
11677 static int config_write_interface_one(struct vty
*vty
, struct vrf
*vrf
)
11679 struct listnode
*node
;
11680 struct interface
*ifp
;
11681 struct crypt_key
*ck
;
11682 struct route_node
*rn
= NULL
;
11683 struct ospf_if_params
*params
;
11684 const char *auth_str
;
11687 FOR_ALL_INTERFACES (vrf
, ifp
) {
11689 if (memcmp(ifp
->name
, "VLINK", 5) == 0)
11692 if_vty_config_start(vty
, ifp
);
11695 vty_out(vty
, " description %s\n", ifp
->desc
);
11699 params
= IF_DEF_PARAMS(ifp
);
11702 /* Interface Network print. */
11703 if (OSPF_IF_PARAM_CONFIGURED(params
, type
)
11704 && params
->type
!= OSPF_IFTYPE_LOOPBACK
) {
11705 if (params
->type
!= ospf_default_iftype(ifp
)) {
11706 vty_out(vty
, " ip ospf network %s",
11710 == OSPF_IFTYPE_POINTOPOINT
11711 && params
->ptp_dmvpn
)
11712 vty_out(vty
, " dmvpn");
11713 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11714 vty_out(vty
, " %pI4",
11716 vty_out(vty
, "\n");
11720 /* OSPF interface authentication print */
11721 auth_str
= interface_config_auth_str(params
);
11723 vty_out(vty
, " ip ospf authentication%s",
11725 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11726 vty_out(vty
, " %pI4",
11728 vty_out(vty
, "\n");
11731 /* Simple Authentication Password print. */
11732 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_simple
)
11733 && params
->auth_simple
[0] != '\0') {
11734 vty_out(vty
, " ip ospf authentication-key %s",
11735 params
->auth_simple
);
11736 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11737 vty_out(vty
, " %pI4",
11739 vty_out(vty
, "\n");
11742 /* Cryptographic Authentication Key print. */
11743 if (params
&& params
->auth_crypt
) {
11744 for (ALL_LIST_ELEMENTS_RO(params
->auth_crypt
,
11747 " ip ospf message-digest-key %d md5 %s",
11748 ck
->key_id
, ck
->auth_key
);
11749 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11750 vty_out(vty
, " %pI4",
11752 vty_out(vty
, "\n");
11756 /* Interface Output Cost print. */
11757 if (OSPF_IF_PARAM_CONFIGURED(params
, output_cost_cmd
)) {
11758 vty_out(vty
, " ip ospf cost %u",
11759 params
->output_cost_cmd
);
11760 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11761 vty_out(vty
, " %pI4",
11763 vty_out(vty
, "\n");
11766 /* Hello Interval print. */
11767 if (OSPF_IF_PARAM_CONFIGURED(params
, v_hello
)
11768 && params
->v_hello
!= OSPF_HELLO_INTERVAL_DEFAULT
) {
11769 vty_out(vty
, " ip ospf hello-interval %u",
11771 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11772 vty_out(vty
, " %pI4",
11774 vty_out(vty
, "\n");
11778 /* Router Dead Interval print. */
11779 if (OSPF_IF_PARAM_CONFIGURED(params
, v_wait
)
11780 && params
->is_v_wait_set
) {
11781 vty_out(vty
, " ip ospf dead-interval ");
11784 if (OSPF_IF_PARAM_CONFIGURED(params
,
11787 "minimal hello-multiplier %d",
11788 params
->fast_hello
);
11790 vty_out(vty
, "%u", params
->v_wait
);
11792 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11793 vty_out(vty
, " %pI4",
11795 vty_out(vty
, "\n");
11798 /* Router Priority print. */
11799 if (OSPF_IF_PARAM_CONFIGURED(params
, priority
)
11800 && params
->priority
11801 != OSPF_ROUTER_PRIORITY_DEFAULT
) {
11802 vty_out(vty
, " ip ospf priority %u",
11804 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11805 vty_out(vty
, " %pI4",
11807 vty_out(vty
, "\n");
11810 /* Retransmit Interval print. */
11811 if (OSPF_IF_PARAM_CONFIGURED(params
,
11812 retransmit_interval
)
11813 && params
->retransmit_interval
11814 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
) {
11815 vty_out(vty
, " ip ospf retransmit-interval %u",
11816 params
->retransmit_interval
);
11817 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11818 vty_out(vty
, " %pI4",
11820 vty_out(vty
, "\n");
11823 /* Transmit Delay print. */
11824 if (OSPF_IF_PARAM_CONFIGURED(params
, transmit_delay
)
11825 && params
->transmit_delay
11826 != OSPF_TRANSMIT_DELAY_DEFAULT
) {
11827 vty_out(vty
, " ip ospf transmit-delay %u",
11828 params
->transmit_delay
);
11829 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11830 vty_out(vty
, " %pI4",
11832 vty_out(vty
, "\n");
11836 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
11838 vty_out(vty
, " ip ospf %d",
11841 vty_out(vty
, " ip ospf");
11843 char buf
[INET_ADDRSTRLEN
];
11845 area_id2str(buf
, sizeof(buf
), ¶ms
->if_area
,
11846 params
->if_area_id_fmt
);
11847 vty_out(vty
, " area %s", buf
);
11848 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11849 vty_out(vty
, " %pI4",
11851 vty_out(vty
, "\n");
11855 if (params
&& params
->bfd_config
)
11856 ospf_bfd_write_config(vty
, params
);
11858 /* MTU ignore print. */
11859 if (OSPF_IF_PARAM_CONFIGURED(params
, mtu_ignore
)
11860 && params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
) {
11861 if (params
->mtu_ignore
== 0)
11862 vty_out(vty
, " no ip ospf mtu-ignore");
11864 vty_out(vty
, " ip ospf mtu-ignore");
11865 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11866 vty_out(vty
, " %pI4",
11868 vty_out(vty
, "\n");
11871 if (OSPF_IF_PARAM_CONFIGURED(params
,
11872 passive_interface
)) {
11873 vty_out(vty
, " %sip ospf passive",
11874 params
->passive_interface
11878 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11879 vty_out(vty
, " %pI4", &rn
->p
.u
.prefix4
);
11880 vty_out(vty
, "\n");
11883 /* LDP-Sync print */
11884 if (params
&& params
->ldp_sync_info
)
11885 ospf_ldp_sync_if_write_config(vty
, params
);
11889 rn
= route_top(IF_OIFS_PARAMS(ifp
));
11891 rn
= route_next(rn
);
11896 if (params
!= NULL
)
11901 ospf_opaque_config_write_if(vty
, ifp
);
11903 if_vty_config_end(vty
);
11909 /* Configuration write function for ospfd. */
11910 static int config_write_interface(struct vty
*vty
)
11913 struct vrf
*vrf
= NULL
;
11915 /* Display all VRF aware OSPF interface configuration */
11916 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
11917 write
+= config_write_interface_one(vty
, vrf
);
11923 static int config_write_network_area(struct vty
*vty
, struct ospf
*ospf
)
11925 struct route_node
*rn
;
11926 char buf
[INET_ADDRSTRLEN
];
11928 /* `network area' print. */
11929 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
))
11931 struct ospf_network
*n
= rn
->info
;
11933 /* Create Area ID string by specified Area ID format. */
11934 if (n
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
11935 inet_ntop(AF_INET
, &n
->area_id
, buf
,
11938 snprintf(buf
, sizeof(buf
), "%lu",
11939 (unsigned long int)ntohl(
11940 n
->area_id
.s_addr
));
11942 /* Network print. */
11943 vty_out(vty
, " network %pFX area %s\n", &rn
->p
, buf
);
11949 static int config_write_ospf_area(struct vty
*vty
, struct ospf
*ospf
)
11951 struct listnode
*node
;
11952 struct ospf_area
*area
;
11953 char buf
[INET_ADDRSTRLEN
];
11955 /* Area configuration print. */
11956 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
11957 struct route_node
*rn1
;
11959 area_id2str(buf
, sizeof(buf
), &area
->area_id
,
11960 area
->area_id_fmt
);
11962 if (area
->auth_type
!= OSPF_AUTH_NULL
) {
11963 if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
11964 vty_out(vty
, " area %s authentication\n", buf
);
11967 " area %s authentication message-digest\n",
11971 if (area
->shortcut_configured
!= OSPF_SHORTCUT_DEFAULT
)
11972 vty_out(vty
, " area %s shortcut %s\n", buf
,
11973 ospf_shortcut_mode_str
11974 [area
->shortcut_configured
]);
11976 if ((area
->external_routing
== OSPF_AREA_STUB
)
11977 || (area
->external_routing
== OSPF_AREA_NSSA
)) {
11978 if (area
->external_routing
== OSPF_AREA_STUB
) {
11979 vty_out(vty
, " area %s stub", buf
);
11980 if (area
->no_summary
)
11981 vty_out(vty
, " no-summary\n");
11982 vty_out(vty
, "\n");
11983 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
11984 switch (area
->NSSATranslatorRole
) {
11985 case OSPF_NSSA_ROLE_NEVER
:
11987 " area %s nssa translate-never\n",
11990 case OSPF_NSSA_ROLE_ALWAYS
:
11992 " area %s nssa translate-always\n",
11995 case OSPF_NSSA_ROLE_CANDIDATE
:
11996 vty_out(vty
, " area %s nssa \n", buf
);
11999 if (area
->no_summary
)
12001 " area %s nssa no-summary\n",
12003 if (area
->suppress_fa
)
12005 " area %s nssa suppress-fa\n",
12009 if (area
->default_cost
!= 1)
12010 vty_out(vty
, " area %s default-cost %d\n", buf
,
12011 area
->default_cost
);
12014 for (rn1
= route_top(area
->ranges
); rn1
; rn1
= route_next(rn1
))
12016 struct ospf_area_range
*range
= rn1
->info
;
12018 vty_out(vty
, " area %s range %pFX", buf
,
12021 if (range
->cost_config
12022 != OSPF_AREA_RANGE_COST_UNSPEC
)
12023 vty_out(vty
, " cost %d",
12024 range
->cost_config
);
12026 if (!CHECK_FLAG(range
->flags
,
12027 OSPF_AREA_RANGE_ADVERTISE
))
12028 vty_out(vty
, " not-advertise");
12030 if (CHECK_FLAG(range
->flags
,
12031 OSPF_AREA_RANGE_SUBSTITUTE
))
12032 vty_out(vty
, " substitute %pI4/%d",
12033 &range
->subst_addr
,
12034 range
->subst_masklen
);
12036 vty_out(vty
, "\n");
12039 if (EXPORT_NAME(area
))
12040 vty_out(vty
, " area %s export-list %s\n", buf
,
12041 EXPORT_NAME(area
));
12043 if (IMPORT_NAME(area
))
12044 vty_out(vty
, " area %s import-list %s\n", buf
,
12045 IMPORT_NAME(area
));
12047 if (PREFIX_NAME_IN(area
))
12048 vty_out(vty
, " area %s filter-list prefix %s in\n", buf
,
12049 PREFIX_NAME_IN(area
));
12051 if (PREFIX_NAME_OUT(area
))
12052 vty_out(vty
, " area %s filter-list prefix %s out\n",
12053 buf
, PREFIX_NAME_OUT(area
));
12055 if (area
->fr_info
.configured
)
12056 vty_out(vty
, " area %s flood-reduction\n", buf
);
12062 static int config_write_ospf_nbr_nbma(struct vty
*vty
, struct ospf
*ospf
)
12064 struct ospf_nbr_nbma
*nbr_nbma
;
12065 struct route_node
*rn
;
12067 /* Static Neighbor configuration print. */
12068 for (rn
= route_top(ospf
->nbr_nbma
); rn
; rn
= route_next(rn
))
12069 if ((nbr_nbma
= rn
->info
)) {
12070 vty_out(vty
, " neighbor %pI4", &nbr_nbma
->addr
);
12072 if (nbr_nbma
->priority
12073 != OSPF_NEIGHBOR_PRIORITY_DEFAULT
)
12074 vty_out(vty
, " priority %d",
12075 nbr_nbma
->priority
);
12077 if (nbr_nbma
->v_poll
!= OSPF_POLL_INTERVAL_DEFAULT
)
12078 vty_out(vty
, " poll-interval %d",
12081 vty_out(vty
, "\n");
12087 static int config_write_virtual_link(struct vty
*vty
, struct ospf
*ospf
)
12089 struct listnode
*node
;
12090 struct ospf_vl_data
*vl_data
;
12091 const char *auth_str
;
12092 char buf
[INET_ADDRSTRLEN
];
12094 /* Virtual-Link print */
12095 for (ALL_LIST_ELEMENTS_RO(ospf
->vlinks
, node
, vl_data
)) {
12096 struct listnode
*n2
;
12097 struct crypt_key
*ck
;
12098 struct ospf_interface
*oi
;
12100 if (vl_data
!= NULL
) {
12101 area_id2str(buf
, sizeof(buf
), &vl_data
->vl_area_id
,
12102 vl_data
->vl_area_id_fmt
);
12103 oi
= vl_data
->vl_oi
;
12106 if (OSPF_IF_PARAM(oi
, v_hello
)
12107 != OSPF_HELLO_INTERVAL_DEFAULT
12108 || OSPF_IF_PARAM(oi
, v_wait
)
12109 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
12110 || OSPF_IF_PARAM(oi
, retransmit_interval
)
12111 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
12112 || OSPF_IF_PARAM(oi
, transmit_delay
)
12113 != OSPF_TRANSMIT_DELAY_DEFAULT
)
12115 " area %s virtual-link %pI4 hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n",
12116 buf
, &vl_data
->vl_peer
,
12117 OSPF_IF_PARAM(oi
, v_hello
),
12118 OSPF_IF_PARAM(oi
, retransmit_interval
),
12119 OSPF_IF_PARAM(oi
, transmit_delay
),
12120 OSPF_IF_PARAM(oi
, v_wait
));
12122 vty_out(vty
, " area %s virtual-link %pI4\n", buf
,
12123 &vl_data
->vl_peer
);
12125 auth_str
= interface_config_auth_str(
12126 IF_DEF_PARAMS(oi
->ifp
));
12129 " area %s virtual-link %pI4 authentication%s\n",
12130 buf
, &vl_data
->vl_peer
, auth_str
);
12132 if (IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)->auth_simple
[0]
12135 " area %s virtual-link %pI4 authentication-key %s\n",
12136 buf
, &vl_data
->vl_peer
,
12137 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
12140 for (ALL_LIST_ELEMENTS_RO(
12141 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
12145 " area %s virtual-link %pI4 message-digest-key %d md5 %s\n",
12146 buf
, &vl_data
->vl_peer
,
12147 ck
->key_id
, ck
->auth_key
);
12155 static int config_write_ospf_redistribute(struct vty
*vty
, struct ospf
*ospf
)
12159 /* redistribute print. */
12160 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
12161 struct list
*red_list
;
12162 struct listnode
*node
;
12163 struct ospf_redist
*red
;
12165 red_list
= ospf
->redist
[type
];
12169 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
12170 vty_out(vty
, " redistribute %s",
12171 zebra_route_string(type
));
12173 vty_out(vty
, " %d", red
->instance
);
12175 if (red
->dmetric
.value
>= 0)
12176 vty_out(vty
, " metric %d", red
->dmetric
.value
);
12178 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
12179 vty_out(vty
, " metric-type 1");
12181 if (ROUTEMAP_NAME(red
))
12182 vty_out(vty
, " route-map %s",
12183 ROUTEMAP_NAME(red
));
12185 vty_out(vty
, "\n");
12192 static int ospf_cfg_write_helper_dis_rtr_walkcb(struct hash_bucket
*bucket
,
12195 struct advRtr
*rtr
= bucket
->data
;
12196 struct vty
*vty
= (struct vty
*)arg
;
12198 vty_out(vty
, " graceful-restart helper enable %pI4\n",
12200 return HASHWALK_CONTINUE
;
12203 static void config_write_ospf_gr(struct vty
*vty
, struct ospf
*ospf
)
12205 if (!ospf
->gr_info
.restart_support
)
12208 if (ospf
->gr_info
.grace_period
== OSPF_DFLT_GRACE_INTERVAL
)
12209 vty_out(vty
, " graceful-restart\n");
12211 vty_out(vty
, " graceful-restart grace-period %u\n",
12212 ospf
->gr_info
.grace_period
);
12215 static int config_write_ospf_gr_helper(struct vty
*vty
, struct ospf
*ospf
)
12217 if (ospf
->is_helper_supported
)
12218 vty_out(vty
, " graceful-restart helper enable\n");
12220 if (!ospf
->strict_lsa_check
)
12222 " no graceful-restart helper strict-lsa-checking\n");
12224 if (ospf
->only_planned_restart
)
12225 vty_out(vty
, " graceful-restart helper planned-only\n");
12227 if (ospf
->supported_grace_time
!= OSPF_MAX_GRACE_INTERVAL
)
12229 " graceful-restart helper supported-grace-time %d\n",
12230 ospf
->supported_grace_time
);
12232 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf
)) {
12233 hash_walk(ospf
->enable_rtr_list
,
12234 ospf_cfg_write_helper_dis_rtr_walkcb
, vty
);
12239 static int config_write_ospf_external_aggregator(struct vty
*vty
,
12242 struct route_node
*rn
;
12244 if (ospf
->aggr_delay_interval
!= OSPF_EXTL_AGGR_DEFAULT_DELAY
)
12245 vty_out(vty
, " aggregation timer %u\n",
12246 ospf
->aggr_delay_interval
);
12248 /* print 'summary-address A.B.C.D/M' */
12249 for (rn
= route_top(ospf
->rt_aggr_tbl
); rn
; rn
= route_next(rn
))
12251 struct ospf_external_aggr_rt
*aggr
= rn
->info
;
12253 vty_out(vty
, " summary-address %pI4/%d",
12254 &aggr
->p
.prefix
, aggr
->p
.prefixlen
);
12256 vty_out(vty
, " tag %u", aggr
->tag
);
12258 if (CHECK_FLAG(aggr
->flags
,
12259 OSPF_EXTERNAL_AGGRT_NO_ADVERTISE
))
12260 vty_out(vty
, " no-advertise");
12262 vty_out(vty
, "\n");
12268 static int config_write_ospf_default_metric(struct vty
*vty
, struct ospf
*ospf
)
12270 if (ospf
->default_metric
!= -1)
12271 vty_out(vty
, " default-metric %d\n", ospf
->default_metric
);
12275 static int config_write_ospf_distribute(struct vty
*vty
, struct ospf
*ospf
)
12278 struct ospf_redist
*red
;
12281 /* distribute-list print. */
12282 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
12283 if (DISTRIBUTE_NAME(ospf
, type
))
12284 vty_out(vty
, " distribute-list %s out %s\n",
12285 DISTRIBUTE_NAME(ospf
, type
),
12286 zebra_route_string(type
));
12288 /* default-information print. */
12289 if (ospf
->default_originate
!= DEFAULT_ORIGINATE_NONE
) {
12290 vty_out(vty
, " default-information originate");
12291 if (ospf
->default_originate
== DEFAULT_ORIGINATE_ALWAYS
)
12292 vty_out(vty
, " always");
12294 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
12296 if (red
->dmetric
.value
>= 0)
12297 vty_out(vty
, " metric %d",
12298 red
->dmetric
.value
);
12300 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
12301 vty_out(vty
, " metric-type 1");
12303 if (ROUTEMAP_NAME(red
))
12304 vty_out(vty
, " route-map %s",
12305 ROUTEMAP_NAME(red
));
12308 vty_out(vty
, "\n");
12315 static int config_write_ospf_distance(struct vty
*vty
, struct ospf
*ospf
)
12317 struct route_node
*rn
;
12318 struct ospf_distance
*odistance
;
12320 if (ospf
->distance_all
)
12321 vty_out(vty
, " distance %d\n", ospf
->distance_all
);
12323 if (ospf
->distance_intra
|| ospf
->distance_inter
12324 || ospf
->distance_external
) {
12325 vty_out(vty
, " distance ospf");
12327 if (ospf
->distance_intra
)
12328 vty_out(vty
, " intra-area %d", ospf
->distance_intra
);
12329 if (ospf
->distance_inter
)
12330 vty_out(vty
, " inter-area %d", ospf
->distance_inter
);
12331 if (ospf
->distance_external
)
12332 vty_out(vty
, " external %d", ospf
->distance_external
);
12334 vty_out(vty
, "\n");
12337 for (rn
= route_top(ospf
->distance_table
); rn
; rn
= route_next(rn
))
12338 if ((odistance
= rn
->info
) != NULL
) {
12339 vty_out(vty
, " distance %d %pFX %s\n",
12340 odistance
->distance
, &rn
->p
,
12341 odistance
->access_list
? odistance
->access_list
12347 static int ospf_config_write_one(struct vty
*vty
, struct ospf
*ospf
)
12351 /* `router ospf' print. */
12352 if (ospf
->instance
&& strcmp(ospf
->name
, VRF_DEFAULT_NAME
)) {
12353 vty_out(vty
, "router ospf %d vrf %s\n", ospf
->instance
,
12355 } else if (ospf
->instance
) {
12356 vty_out(vty
, "router ospf %d\n", ospf
->instance
);
12357 } else if (strcmp(ospf
->name
, VRF_DEFAULT_NAME
)) {
12358 vty_out(vty
, "router ospf vrf %s\n", ospf
->name
);
12360 vty_out(vty
, "router ospf\n");
12362 if (!ospf
->networks
) {
12367 /* Router ID print. */
12368 if (ospf
->router_id_static
.s_addr
!= INADDR_ANY
)
12369 vty_out(vty
, " ospf router-id %pI4\n",
12370 &ospf
->router_id_static
);
12372 /* zebra opaque attributes configuration. */
12373 if (CHECK_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
))
12374 vty_out(vty
, " ospf send-extra-data zebra\n");
12376 /* ABR type print. */
12377 if (ospf
->abr_type
!= OSPF_ABR_DEFAULT
)
12378 vty_out(vty
, " ospf abr-type %s\n",
12379 ospf_abr_type_str
[ospf
->abr_type
]);
12381 /* log-adjacency-changes flag print. */
12382 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
12383 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
))
12384 vty_out(vty
, " log-adjacency-changes detail\n");
12385 else if (!SAVE_OSPF_LOG_ADJACENCY_CHANGES
)
12386 vty_out(vty
, " log-adjacency-changes\n");
12387 } else if (SAVE_OSPF_LOG_ADJACENCY_CHANGES
) {
12388 vty_out(vty
, " no log-adjacency-changes\n");
12391 /* RFC1583 compatibility flag print -- Compatible with CISCO
12393 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
))
12394 vty_out(vty
, " compatible rfc1583\n");
12396 /* auto-cost reference-bandwidth configuration. */
12397 if (ospf
->ref_bandwidth
!= OSPF_DEFAULT_REF_BANDWIDTH
) {
12399 "! Important: ensure reference bandwidth is consistent across all routers\n");
12400 vty_out(vty
, " auto-cost reference-bandwidth %d\n",
12401 ospf
->ref_bandwidth
);
12404 /* SPF timers print. */
12405 if (ospf
->spf_delay
!= OSPF_SPF_DELAY_DEFAULT
12406 || ospf
->spf_holdtime
!= OSPF_SPF_HOLDTIME_DEFAULT
12407 || ospf
->spf_max_holdtime
!= OSPF_SPF_MAX_HOLDTIME_DEFAULT
)
12408 vty_out(vty
, " timers throttle spf %d %d %d\n", ospf
->spf_delay
,
12409 ospf
->spf_holdtime
, ospf
->spf_max_holdtime
);
12411 /* LSA timers print. */
12412 if (ospf
->min_ls_interval
!= OSPF_MIN_LS_INTERVAL
)
12413 vty_out(vty
, " timers throttle lsa all %d\n",
12414 ospf
->min_ls_interval
);
12415 if (ospf
->min_ls_arrival
!= OSPF_MIN_LS_ARRIVAL
)
12416 vty_out(vty
, " timers lsa min-arrival %d\n",
12417 ospf
->min_ls_arrival
);
12419 /* Write multiplier print. */
12420 if (ospf
->write_oi_count
!= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
)
12421 vty_out(vty
, " ospf write-multiplier %d\n",
12422 ospf
->write_oi_count
);
12424 if (ospf
->max_multipath
!= MULTIPATH_NUM
)
12425 vty_out(vty
, " maximum-paths %d\n", ospf
->max_multipath
);
12427 /* Max-metric router-lsa print */
12428 config_write_stub_router(vty
, ospf
);
12430 /* SPF refresh parameters print. */
12431 if (ospf
->lsa_refresh_interval
!= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
12432 vty_out(vty
, " refresh timer %d\n", ospf
->lsa_refresh_interval
);
12434 if (ospf
->fr_configured
)
12435 vty_out(vty
, " flood-reduction\n");
12437 /* Redistribute information print. */
12438 config_write_ospf_redistribute(vty
, ospf
);
12440 /* Graceful Restart print */
12441 config_write_ospf_gr(vty
, ospf
);
12442 config_write_ospf_gr_helper(vty
, ospf
);
12444 /* Print external route aggregation. */
12445 config_write_ospf_external_aggregator(vty
, ospf
);
12447 /* passive-interface print. */
12448 if (ospf
->passive_interface_default
== OSPF_IF_PASSIVE
)
12449 vty_out(vty
, " passive-interface default\n");
12451 /* proactive-arp print. */
12452 if (ospf
->proactive_arp
!= OSPF_PROACTIVE_ARP_DEFAULT
) {
12453 if (ospf
->proactive_arp
)
12454 vty_out(vty
, " proactive-arp\n");
12456 vty_out(vty
, " no proactive-arp\n");
12459 /* TI-LFA print. */
12460 if (ospf
->ti_lfa_enabled
) {
12461 if (ospf
->ti_lfa_protection_type
== OSPF_TI_LFA_NODE_PROTECTION
)
12462 vty_out(vty
, " fast-reroute ti-lfa node-protection\n");
12464 vty_out(vty
, " fast-reroute ti-lfa\n");
12467 /* Network area print. */
12468 config_write_network_area(vty
, ospf
);
12470 /* Area config print. */
12471 config_write_ospf_area(vty
, ospf
);
12473 /* static neighbor print. */
12474 config_write_ospf_nbr_nbma(vty
, ospf
);
12476 /* Virtual-Link print. */
12477 config_write_virtual_link(vty
, ospf
);
12479 /* Default metric configuration. */
12480 config_write_ospf_default_metric(vty
, ospf
);
12482 /* Distribute-list and default-information print. */
12483 config_write_ospf_distribute(vty
, ospf
);
12485 /* Distance configuration. */
12486 config_write_ospf_distance(vty
, ospf
);
12488 ospf_opaque_config_write_router(vty
, ospf
);
12490 /* LDP-Sync print */
12491 ospf_ldp_sync_write_config(vty
, ospf
);
12493 vty_out(vty
, "exit\n");
12499 /* OSPF configuration write function. */
12500 static int ospf_config_write(struct vty
*vty
)
12503 struct listnode
*ospf_node
= NULL
;
12506 if (listcount(om
->ospf
) == 0)
12509 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, ospf_node
, ospf
)) {
12510 /* VRF Default check if it is running.
12511 * Upon daemon start, there could be default instance
12512 * in absence of 'router ospf'/oi_running is disabled. */
12513 if (ospf
->vrf_id
== VRF_DEFAULT
&& ospf
->oi_running
)
12514 write
+= ospf_config_write_one(vty
, ospf
);
12515 /* For Non-Default VRF simply display the configuration,
12516 * even if it is not oi_running. */
12517 else if (ospf
->vrf_id
!= VRF_DEFAULT
)
12518 write
+= ospf_config_write_one(vty
, ospf
);
12523 void ospf_vty_show_init(void)
12525 /* "show ip ospf" commands. */
12526 install_element(VIEW_NODE
, &show_ip_ospf_cmd
);
12528 install_element(VIEW_NODE
, &show_ip_ospf_instance_cmd
);
12530 /* "show ip ospf database" commands. */
12531 install_element(VIEW_NODE
, &show_ip_ospf_database_cmd
);
12533 /* "show ip ospf interface" commands. */
12534 install_element(VIEW_NODE
, &show_ip_ospf_interface_cmd
);
12536 install_element(VIEW_NODE
, &show_ip_ospf_instance_interface_cmd
);
12537 /* "show ip ospf interface traffic */
12538 install_element(VIEW_NODE
, &show_ip_ospf_interface_traffic_cmd
);
12540 /* "show ip ospf neighbor" commands. */
12541 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_detail_cmd
);
12542 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_cmd
);
12543 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_id_cmd
);
12544 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_all_cmd
);
12545 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_cmd
);
12546 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_cmd
);
12547 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_all_cmd
);
12549 install_element(VIEW_NODE
,
12550 &show_ip_ospf_instance_neighbor_int_detail_cmd
);
12551 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_int_cmd
);
12552 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_id_cmd
);
12553 install_element(VIEW_NODE
,
12554 &show_ip_ospf_instance_neighbor_detail_all_cmd
);
12555 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_detail_cmd
);
12556 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_cmd
);
12557 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_all_cmd
);
12559 /* "show ip ospf route" commands. */
12560 install_element(VIEW_NODE
, &show_ip_ospf_route_cmd
);
12561 install_element(VIEW_NODE
, &show_ip_ospf_border_routers_cmd
);
12562 install_element(VIEW_NODE
, &show_ip_ospf_reachable_routers_cmd
);
12564 install_element(VIEW_NODE
, &show_ip_ospf_instance_route_cmd
);
12565 install_element(VIEW_NODE
, &show_ip_ospf_instance_border_routers_cmd
);
12566 install_element(VIEW_NODE
,
12567 &show_ip_ospf_instance_reachable_routers_cmd
);
12569 /* "show ip ospf vrfs" commands. */
12570 install_element(VIEW_NODE
, &show_ip_ospf_vrfs_cmd
);
12572 /* "show ip ospf gr-helper details" command */
12573 install_element(VIEW_NODE
, &show_ip_ospf_gr_helper_cmd
);
12575 /* "show ip ospf summary-address" command */
12576 install_element(VIEW_NODE
, &show_ip_ospf_external_aggregator_cmd
);
12579 /* Initialization of OSPF interface. */
12580 static void ospf_vty_if_init(void)
12582 /* Install interface node. */
12583 if_cmd_init(config_write_interface
);
12585 /* "ip ospf authentication" commands. */
12586 install_element(INTERFACE_NODE
, &ip_ospf_authentication_args_addr_cmd
);
12587 install_element(INTERFACE_NODE
, &ip_ospf_authentication_addr_cmd
);
12588 install_element(INTERFACE_NODE
,
12589 &no_ip_ospf_authentication_args_addr_cmd
);
12590 install_element(INTERFACE_NODE
, &no_ip_ospf_authentication_addr_cmd
);
12591 install_element(INTERFACE_NODE
, &ip_ospf_authentication_key_addr_cmd
);
12592 install_element(INTERFACE_NODE
,
12593 &no_ip_ospf_authentication_key_authkey_addr_cmd
);
12594 install_element(INTERFACE_NODE
,
12595 &no_ospf_authentication_key_authkey_addr_cmd
);
12597 /* "ip ospf message-digest-key" commands. */
12598 install_element(INTERFACE_NODE
, &ip_ospf_message_digest_key_cmd
);
12599 install_element(INTERFACE_NODE
, &no_ip_ospf_message_digest_key_cmd
);
12601 /* "ip ospf cost" commands. */
12602 install_element(INTERFACE_NODE
, &ip_ospf_cost_cmd
);
12603 install_element(INTERFACE_NODE
, &no_ip_ospf_cost_cmd
);
12605 /* "ip ospf mtu-ignore" commands. */
12606 install_element(INTERFACE_NODE
, &ip_ospf_mtu_ignore_addr_cmd
);
12607 install_element(INTERFACE_NODE
, &no_ip_ospf_mtu_ignore_addr_cmd
);
12609 /* "ip ospf dead-interval" commands. */
12610 install_element(INTERFACE_NODE
, &ip_ospf_dead_interval_cmd
);
12611 install_element(INTERFACE_NODE
,
12612 &ip_ospf_dead_interval_minimal_addr_cmd
);
12613 install_element(INTERFACE_NODE
, &no_ip_ospf_dead_interval_cmd
);
12615 /* "ip ospf hello-interval" commands. */
12616 install_element(INTERFACE_NODE
, &ip_ospf_hello_interval_cmd
);
12617 install_element(INTERFACE_NODE
, &no_ip_ospf_hello_interval_cmd
);
12619 /* "ip ospf network" commands. */
12620 install_element(INTERFACE_NODE
, &ip_ospf_network_cmd
);
12621 install_element(INTERFACE_NODE
, &no_ip_ospf_network_cmd
);
12623 /* "ip ospf priority" commands. */
12624 install_element(INTERFACE_NODE
, &ip_ospf_priority_cmd
);
12625 install_element(INTERFACE_NODE
, &no_ip_ospf_priority_cmd
);
12627 /* "ip ospf retransmit-interval" commands. */
12628 install_element(INTERFACE_NODE
, &ip_ospf_retransmit_interval_addr_cmd
);
12629 install_element(INTERFACE_NODE
,
12630 &no_ip_ospf_retransmit_interval_addr_cmd
);
12632 /* "ip ospf transmit-delay" commands. */
12633 install_element(INTERFACE_NODE
, &ip_ospf_transmit_delay_addr_cmd
);
12634 install_element(INTERFACE_NODE
, &no_ip_ospf_transmit_delay_addr_cmd
);
12636 /* "ip ospf area" commands. */
12637 install_element(INTERFACE_NODE
, &ip_ospf_area_cmd
);
12638 install_element(INTERFACE_NODE
, &no_ip_ospf_area_cmd
);
12640 /* "ip ospf passive" commands. */
12641 install_element(INTERFACE_NODE
, &ip_ospf_passive_cmd
);
12642 install_element(INTERFACE_NODE
, &no_ip_ospf_passive_cmd
);
12644 /* These commands are compatibitliy for previous version. */
12645 install_element(INTERFACE_NODE
, &ospf_authentication_key_cmd
);
12646 install_element(INTERFACE_NODE
, &ospf_message_digest_key_cmd
);
12647 install_element(INTERFACE_NODE
, &no_ospf_message_digest_key_cmd
);
12648 install_element(INTERFACE_NODE
, &ospf_dead_interval_cmd
);
12649 install_element(INTERFACE_NODE
, &no_ospf_dead_interval_cmd
);
12650 install_element(INTERFACE_NODE
, &ospf_hello_interval_cmd
);
12651 install_element(INTERFACE_NODE
, &no_ospf_hello_interval_cmd
);
12652 install_element(INTERFACE_NODE
, &ospf_cost_cmd
);
12653 install_element(INTERFACE_NODE
, &no_ospf_cost_cmd
);
12654 install_element(INTERFACE_NODE
, &ospf_network_cmd
);
12655 install_element(INTERFACE_NODE
, &no_ospf_network_cmd
);
12656 install_element(INTERFACE_NODE
, &ospf_priority_cmd
);
12657 install_element(INTERFACE_NODE
, &no_ospf_priority_cmd
);
12658 install_element(INTERFACE_NODE
, &ospf_retransmit_interval_cmd
);
12659 install_element(INTERFACE_NODE
, &no_ospf_retransmit_interval_cmd
);
12660 install_element(INTERFACE_NODE
, &ospf_transmit_delay_cmd
);
12661 install_element(INTERFACE_NODE
, &no_ospf_transmit_delay_cmd
);
12664 static void ospf_vty_zebra_init(void)
12666 install_element(OSPF_NODE
, &ospf_redistribute_source_cmd
);
12667 install_element(OSPF_NODE
, &no_ospf_redistribute_source_cmd
);
12668 install_element(OSPF_NODE
, &ospf_redistribute_instance_source_cmd
);
12669 install_element(OSPF_NODE
, &no_ospf_redistribute_instance_source_cmd
);
12671 install_element(OSPF_NODE
, &ospf_distribute_list_out_cmd
);
12672 install_element(OSPF_NODE
, &no_ospf_distribute_list_out_cmd
);
12674 install_element(OSPF_NODE
, &ospf_default_information_originate_cmd
);
12675 install_element(OSPF_NODE
, &no_ospf_default_information_originate_cmd
);
12677 install_element(OSPF_NODE
, &ospf_default_metric_cmd
);
12678 install_element(OSPF_NODE
, &no_ospf_default_metric_cmd
);
12680 install_element(OSPF_NODE
, &ospf_distance_cmd
);
12681 install_element(OSPF_NODE
, &no_ospf_distance_cmd
);
12682 install_element(OSPF_NODE
, &no_ospf_distance_ospf_cmd
);
12683 install_element(OSPF_NODE
, &ospf_distance_ospf_cmd
);
12685 /*Ospf garcefull restart helper configurations */
12686 install_element(OSPF_NODE
, &ospf_gr_helper_enable_cmd
);
12687 install_element(OSPF_NODE
, &no_ospf_gr_helper_enable_cmd
);
12688 install_element(OSPF_NODE
, &ospf_gr_helper_enable_lsacheck_cmd
);
12689 install_element(OSPF_NODE
, &no_ospf_gr_helper_enable_lsacheck_cmd
);
12690 install_element(OSPF_NODE
, &ospf_gr_helper_supported_grace_time_cmd
);
12691 install_element(OSPF_NODE
, &no_ospf_gr_helper_supported_grace_time_cmd
);
12692 install_element(OSPF_NODE
, &ospf_gr_helper_planned_only_cmd
);
12693 install_element(OSPF_NODE
, &no_ospf_gr_helper_planned_only_cmd
);
12695 /* External LSA summarisation config commands.*/
12696 install_element(OSPF_NODE
, &ospf_external_route_aggregation_cmd
);
12697 install_element(OSPF_NODE
, &no_ospf_external_route_aggregation_cmd
);
12698 install_element(OSPF_NODE
,
12699 &ospf_external_route_aggregation_no_adrvertise_cmd
);
12700 install_element(OSPF_NODE
,
12701 &no_ospf_external_route_aggregation_no_adrvertise_cmd
);
12702 install_element(OSPF_NODE
, &ospf_route_aggregation_timer_cmd
);
12703 install_element(OSPF_NODE
, &no_ospf_route_aggregation_timer_cmd
);
12706 static int ospf_config_write(struct vty
*vty
);
12707 static struct cmd_node ospf_node
= {
12710 .parent_node
= CONFIG_NODE
,
12711 .prompt
= "%s(config-router)# ",
12712 .config_write
= ospf_config_write
,
12715 static void ospf_interface_clear(struct interface
*ifp
)
12717 if (!if_is_operative(ifp
))
12720 if (IS_DEBUG_OSPF(ism
, ISM_EVENTS
))
12721 zlog_debug("ISM[%s]: clear by reset", ifp
->name
);
12723 ospf_if_reset(ifp
);
12726 DEFUN (clear_ip_ospf_interface
,
12727 clear_ip_ospf_interface_cmd
,
12728 "clear ip ospf [vrf NAME] interface [IFNAME]",
12731 "OSPF information\n"
12733 "Interface information\n"
12734 "Interface name\n")
12736 int idx_ifname
= 0;
12738 struct interface
*ifp
;
12739 struct listnode
*node
;
12740 struct ospf
*ospf
= NULL
;
12741 char *vrf_name
= NULL
;
12742 vrf_id_t vrf_id
= VRF_DEFAULT
;
12743 struct vrf
*vrf
= NULL
;
12745 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
12746 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
12747 if (vrf_name
&& strmatch(vrf_name
, VRF_DEFAULT_NAME
))
12750 vrf
= vrf_lookup_by_name(vrf_name
);
12752 vrf_id
= vrf
->vrf_id
;
12754 if (!argv_find(argv
, argc
, "IFNAME", &idx_ifname
)) {
12755 /* Clear all the ospfv2 interfaces. */
12756 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
12757 if (vrf_id
!= ospf
->vrf_id
)
12760 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
12761 FOR_ALL_INTERFACES (vrf
, ifp
)
12762 ospf_interface_clear(ifp
);
12765 /* Interface name is specified. */
12766 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf_id
);
12768 vty_out(vty
, "No such interface name\n");
12770 ospf_interface_clear(ifp
);
12773 return CMD_SUCCESS
;
12776 DEFPY_HIDDEN(ospf_lsa_refresh_timer
, ospf_lsa_refresh_timer_cmd
,
12777 "[no$no] ospf lsa-refresh [(120-1800)]$value",
12779 "OSPF lsa refresh timer\n"
12780 "timer value in seconds\n")
12782 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
12785 ospf
->lsa_refresh_timer
= OSPF_LS_REFRESH_TIME
;
12787 ospf
->lsa_refresh_timer
= value
;
12789 return CMD_SUCCESS
;
12792 DEFPY_HIDDEN(ospf_maxage_delay_timer
, ospf_maxage_delay_timer_cmd
,
12793 "[no$no] ospf maxage-delay [(0-60)]$value",
12795 "OSPF lsa maxage delay timer\n"
12796 "timer value in seconds\n")
12798 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
12801 ospf
->maxage_delay
= OSPF_LSA_MAXAGE_REMOVE_DELAY_DEFAULT
;
12803 ospf
->maxage_delay
= value
;
12805 THREAD_OFF(ospf
->t_maxage
);
12806 OSPF_TIMER_ON(ospf
->t_maxage
, ospf_maxage_lsa_remover
,
12807 ospf
->maxage_delay
);
12809 return CMD_SUCCESS
;
12813 * ------------------------------------------------------------------------*
12814 * Following is (vty) configuration functions for flood-reduction handling.
12815 * ------------------------------------------------------------------------
12818 DEFPY(flood_reduction
, flood_reduction_cmd
, "flood-reduction",
12819 "flood reduction feature\n")
12821 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
12822 struct ospf_area
*area
;
12823 struct listnode
*node
;
12825 /* Turn on the Flood Reduction feature for the router. */
12826 if (!ospf
->fr_configured
) {
12827 ospf
->fr_configured
= true;
12828 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT
,
12829 "Flood Reduction: OFF -> ON");
12830 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
12832 ospf_area_update_fr_state(area
);
12833 ospf_refresh_area_self_lsas(area
);
12838 return CMD_SUCCESS
;
12841 DEFPY(flood_reduction_area
, flood_reduction_area_cmd
,
12842 "area <A.B.C.D|(0-4294967295)> flood-reduction",
12843 "OSPF area parameters\n"
12844 "OSPF area ID in IP address format\n"
12845 "OSPF area ID as a decimal value\n"
12846 "Enable flood reduction for area\n")
12848 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
12849 struct ospf_area
*oa
;
12853 const char *areaid
;
12854 struct in_addr area_id
;
12856 areaid
= argv
[idx
]->arg
;
12858 ret
= str2area_id(areaid
, &area_id
, &format
);
12860 vty_out(vty
, "Please specify area by A.B.C.D|<0-4294967295>\n");
12861 return CMD_WARNING_CONFIG_FAILED
;
12864 oa
= ospf_area_lookup_by_area_id(ospf
, area_id
);
12866 vty_out(vty
, "OSPF area ID not present\n");
12867 return CMD_WARNING_CONFIG_FAILED
;
12870 /* Turn on the Flood Reduction feature for the area. */
12871 if (!oa
->fr_info
.configured
) {
12872 oa
->fr_info
.configured
= true;
12873 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT
,
12874 "Flood Reduction area %pI4 : OFF -> ON",
12876 ospf_area_update_fr_state(oa
);
12877 ospf_refresh_area_self_lsas(oa
);
12880 return CMD_SUCCESS
;
12883 DEFPY(no_flood_reduction
, no_flood_reduction_cmd
, "no flood-reduction",
12884 NO_STR
"flood reduction feature\n")
12886 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
12887 struct listnode
*node
;
12888 struct ospf_area
*area
;
12890 /* Turn off the Flood Reduction feature for the router. */
12891 if (ospf
->fr_configured
) {
12892 ospf
->fr_configured
= false;
12893 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT
,
12894 "Flood Reduction: ON -> OFF");
12895 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
12897 ospf_area_update_fr_state(area
);
12898 ospf_refresh_area_self_lsas(area
);
12903 return CMD_SUCCESS
;
12906 DEFPY(no_flood_reduction_area
, no_flood_reduction_area_cmd
,
12907 "no area <A.B.C.D|(0-4294967295)> flood-reduction",
12909 "OSPF area parameters\n"
12910 "OSPF area ID in IP address format\n"
12911 "OSPF area ID as a decimal value\n"
12912 "Disable flood reduction for area\n")
12914 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
12915 struct ospf_area
*oa
;
12919 const char *areaid
;
12920 struct in_addr area_id
;
12922 areaid
= argv
[idx
]->arg
;
12924 ret
= str2area_id(areaid
, &area_id
, &format
);
12926 vty_out(vty
, "Please specify area by A.B.C.D|<0-4294967295>\n");
12927 return CMD_WARNING_CONFIG_FAILED
;
12930 oa
= ospf_area_lookup_by_area_id(ospf
, area_id
);
12932 vty_out(vty
, "OSPF area ID not present\n");
12933 return CMD_WARNING_CONFIG_FAILED
;
12936 /* Turn off the Flood Reduction feature for the area. */
12937 if (oa
->fr_info
.configured
) {
12938 oa
->fr_info
.configured
= false;
12939 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT
,
12940 "Flood Reduction area %pI4 : ON -> OFF",
12942 ospf_area_update_fr_state(oa
);
12943 ospf_refresh_area_self_lsas(oa
);
12946 return CMD_SUCCESS
;
12949 void ospf_vty_clear_init(void)
12951 install_element(ENABLE_NODE
, &clear_ip_ospf_interface_cmd
);
12952 install_element(ENABLE_NODE
, &clear_ip_ospf_process_cmd
);
12953 install_element(ENABLE_NODE
, &clear_ip_ospf_neighbor_cmd
);
12957 /* Install OSPF related vty commands. */
12958 void ospf_vty_init(void)
12960 /* Install ospf top node. */
12961 install_node(&ospf_node
);
12963 /* "router ospf" commands. */
12964 install_element(CONFIG_NODE
, &router_ospf_cmd
);
12965 install_element(CONFIG_NODE
, &no_router_ospf_cmd
);
12968 install_default(OSPF_NODE
);
12970 /* "ospf router-id" commands. */
12971 install_element(OSPF_NODE
, &ospf_router_id_cmd
);
12972 install_element(OSPF_NODE
, &ospf_router_id_old_cmd
);
12973 install_element(OSPF_NODE
, &no_ospf_router_id_cmd
);
12975 /* "passive-interface" commands. */
12976 install_element(OSPF_NODE
, &ospf_passive_interface_default_cmd
);
12977 install_element(OSPF_NODE
, &ospf_passive_interface_addr_cmd
);
12978 install_element(OSPF_NODE
, &no_ospf_passive_interface_default_cmd
);
12979 install_element(OSPF_NODE
, &no_ospf_passive_interface_addr_cmd
);
12981 /* "ospf abr-type" commands. */
12982 install_element(OSPF_NODE
, &ospf_abr_type_cmd
);
12983 install_element(OSPF_NODE
, &no_ospf_abr_type_cmd
);
12985 /* "ospf log-adjacency-changes" commands. */
12986 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_cmd
);
12987 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_detail_cmd
);
12988 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_cmd
);
12989 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_detail_cmd
);
12991 /* "ospf rfc1583-compatible" commands. */
12992 install_element(OSPF_NODE
, &ospf_compatible_rfc1583_cmd
);
12993 install_element(OSPF_NODE
, &no_ospf_compatible_rfc1583_cmd
);
12994 install_element(OSPF_NODE
, &ospf_rfc1583_flag_cmd
);
12995 install_element(OSPF_NODE
, &no_ospf_rfc1583_flag_cmd
);
12997 /* "ospf send-extra-data zebra" commands. */
12998 install_element(OSPF_NODE
, &ospf_send_extra_data_cmd
);
13000 /* "network area" commands. */
13001 install_element(OSPF_NODE
, &ospf_network_area_cmd
);
13002 install_element(OSPF_NODE
, &no_ospf_network_area_cmd
);
13004 /* "area authentication" commands. */
13005 install_element(OSPF_NODE
,
13006 &ospf_area_authentication_message_digest_cmd
);
13007 install_element(OSPF_NODE
, &ospf_area_authentication_cmd
);
13008 install_element(OSPF_NODE
, &no_ospf_area_authentication_cmd
);
13010 /* "area range" commands. */
13011 install_element(OSPF_NODE
, &ospf_area_range_cmd
);
13012 install_element(OSPF_NODE
, &ospf_area_range_cost_cmd
);
13013 install_element(OSPF_NODE
, &ospf_area_range_not_advertise_cmd
);
13014 install_element(OSPF_NODE
, &no_ospf_area_range_cmd
);
13015 install_element(OSPF_NODE
, &no_ospf_area_range_substitute_cmd
);
13017 /* "area virtual-link" commands. */
13018 install_element(OSPF_NODE
, &ospf_area_vlink_cmd
);
13019 install_element(OSPF_NODE
, &ospf_area_vlink_intervals_cmd
);
13020 install_element(OSPF_NODE
, &no_ospf_area_vlink_cmd
);
13021 install_element(OSPF_NODE
, &no_ospf_area_vlink_intervals_cmd
);
13024 /* "area stub" commands. */
13025 install_element(OSPF_NODE
, &ospf_area_stub_no_summary_cmd
);
13026 install_element(OSPF_NODE
, &ospf_area_stub_cmd
);
13027 install_element(OSPF_NODE
, &no_ospf_area_stub_no_summary_cmd
);
13028 install_element(OSPF_NODE
, &no_ospf_area_stub_cmd
);
13030 /* "area nssa" commands. */
13031 install_element(OSPF_NODE
, &ospf_area_nssa_cmd
);
13032 install_element(OSPF_NODE
, &ospf_area_nssa_translate_cmd
);
13033 install_element(OSPF_NODE
, &ospf_area_nssa_no_summary_cmd
);
13034 install_element(OSPF_NODE
, &no_ospf_area_nssa_no_summary_cmd
);
13035 install_element(OSPF_NODE
, &ospf_area_nssa_suppress_fa_cmd
);
13036 install_element(OSPF_NODE
, &no_ospf_area_nssa_suppress_fa_cmd
);
13037 install_element(OSPF_NODE
, &no_ospf_area_nssa_cmd
);
13039 install_element(OSPF_NODE
, &ospf_area_default_cost_cmd
);
13040 install_element(OSPF_NODE
, &no_ospf_area_default_cost_cmd
);
13042 install_element(OSPF_NODE
, &ospf_area_shortcut_cmd
);
13043 install_element(OSPF_NODE
, &no_ospf_area_shortcut_cmd
);
13045 install_element(OSPF_NODE
, &ospf_area_export_list_cmd
);
13046 install_element(OSPF_NODE
, &no_ospf_area_export_list_cmd
);
13048 install_element(OSPF_NODE
, &ospf_area_filter_list_cmd
);
13049 install_element(OSPF_NODE
, &no_ospf_area_filter_list_cmd
);
13051 install_element(OSPF_NODE
, &ospf_area_import_list_cmd
);
13052 install_element(OSPF_NODE
, &no_ospf_area_import_list_cmd
);
13054 /* SPF timer commands */
13055 install_element(OSPF_NODE
, &ospf_timers_throttle_spf_cmd
);
13056 install_element(OSPF_NODE
, &no_ospf_timers_throttle_spf_cmd
);
13058 /* LSA timers commands */
13059 install_element(OSPF_NODE
, &ospf_timers_min_ls_interval_cmd
);
13060 install_element(OSPF_NODE
, &no_ospf_timers_min_ls_interval_cmd
);
13061 install_element(OSPF_NODE
, &ospf_timers_lsa_min_arrival_cmd
);
13062 install_element(OSPF_NODE
, &no_ospf_timers_lsa_min_arrival_cmd
);
13064 /* refresh timer commands */
13065 install_element(OSPF_NODE
, &ospf_refresh_timer_cmd
);
13066 install_element(OSPF_NODE
, &no_ospf_refresh_timer_val_cmd
);
13068 /* max-metric commands */
13069 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_admin_cmd
);
13070 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_admin_cmd
);
13071 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_startup_cmd
);
13072 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_startup_cmd
);
13073 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_shutdown_cmd
);
13074 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_shutdown_cmd
);
13076 /* reference bandwidth commands */
13077 install_element(OSPF_NODE
, &ospf_auto_cost_reference_bandwidth_cmd
);
13078 install_element(OSPF_NODE
, &no_ospf_auto_cost_reference_bandwidth_cmd
);
13080 /* "neighbor" commands. */
13081 install_element(OSPF_NODE
, &ospf_neighbor_cmd
);
13082 install_element(OSPF_NODE
, &ospf_neighbor_poll_interval_cmd
);
13083 install_element(OSPF_NODE
, &no_ospf_neighbor_cmd
);
13084 install_element(OSPF_NODE
, &no_ospf_neighbor_poll_cmd
);
13086 /* write multiplier commands */
13087 install_element(OSPF_NODE
, &ospf_write_multiplier_cmd
);
13088 install_element(OSPF_NODE
, &write_multiplier_cmd
);
13089 install_element(OSPF_NODE
, &no_ospf_write_multiplier_cmd
);
13090 install_element(OSPF_NODE
, &no_write_multiplier_cmd
);
13092 /* "proactive-arp" commands. */
13093 install_element(OSPF_NODE
, &ospf_proactive_arp_cmd
);
13094 install_element(OSPF_NODE
, &no_ospf_proactive_arp_cmd
);
13096 /* TI-LFA commands */
13097 install_element(OSPF_NODE
, &ospf_ti_lfa_cmd
);
13098 install_element(OSPF_NODE
, &no_ospf_ti_lfa_cmd
);
13100 /* Max path configurations */
13101 install_element(OSPF_NODE
, &ospf_max_multipath_cmd
);
13102 install_element(OSPF_NODE
, &no_ospf_max_multipath_cmd
);
13104 vrf_cmd_init(NULL
);
13106 install_element(OSPF_NODE
, &ospf_lsa_refresh_timer_cmd
);
13107 install_element(OSPF_NODE
, &ospf_maxage_delay_timer_cmd
);
13109 /* Flood Reduction commands */
13110 install_element(OSPF_NODE
, &flood_reduction_cmd
);
13111 install_element(OSPF_NODE
, &no_flood_reduction_cmd
);
13112 install_element(OSPF_NODE
, &flood_reduction_area_cmd
);
13113 install_element(OSPF_NODE
, &no_flood_reduction_area_cmd
);
13115 /* Init interface related vty commands. */
13116 ospf_vty_if_init();
13118 /* Init zebra related vty commands. */
13119 ospf_vty_zebra_init();