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_vty.h"
39 #include "ospfd/ospf_dump.h"
40 #include "ospfd/ospf_bfd.h"
41 #include "ospfd/ospf_ldp_sync.h"
42 #include "ospfd/ospf_network.h"
44 FRR_CFG_DEFAULT_BOOL(OSPF_LOG_ADJACENCY_CHANGES
,
45 { .val_bool
= true, .match_profile
= "datacenter", },
46 { .val_bool
= false },
49 static const char *const ospf_network_type_str
[] = {
50 "Null", "POINTOPOINT", "BROADCAST", "NBMA", "POINTOMULTIPOINT",
51 "VIRTUALLINK", "LOOPBACK"};
53 /* Utility functions. */
54 int str2area_id(const char *str
, struct in_addr
*area_id
, int *area_id_fmt
)
58 area_id
->s_addr
= htonl(strtoul(str
, &ep
, 10));
59 if (*ep
&& !inet_aton(str
, area_id
))
63 *ep
? OSPF_AREA_ID_FMT_DOTTEDQUAD
: OSPF_AREA_ID_FMT_DECIMAL
;
68 static void area_id2str(char *buf
, int length
, struct in_addr
*area_id
,
71 if (area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
72 inet_ntop(AF_INET
, area_id
, buf
, length
);
74 snprintf(buf
, length
, "%lu",
75 (unsigned long)ntohl(area_id
->s_addr
));
78 static int str2metric(const char *str
, int *metric
)
84 *metric
= strtol(str
, NULL
, 10);
85 if (*metric
< 0 || *metric
> 16777214) {
86 /* vty_out (vty, "OSPF metric value is invalid\n"); */
93 static int str2metric_type(const char *str
, int *metric_type
)
99 if (strncmp(str
, "1", 1) == 0)
100 *metric_type
= EXTERNAL_METRIC_TYPE_1
;
101 else if (strncmp(str
, "2", 1) == 0)
102 *metric_type
= EXTERNAL_METRIC_TYPE_2
;
109 int ospf_oi_count(struct interface
*ifp
)
111 struct route_node
*rn
;
114 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
121 #define OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf) \
122 if (argv_find(argv, argc, "vrf", &idx_vrf)) { \
123 vrf_name = argv[idx_vrf + 1]->arg; \
124 all_vrf = strmatch(vrf_name, "all"); \
127 static int ospf_router_cmd_parse(struct vty
*vty
, struct cmd_token
*argv
[],
128 const int argc
, unsigned short *instance
,
129 const char **vrf_name
)
131 int idx_vrf
= 0, idx_inst
= 0;
134 if (argv_find(argv
, argc
, "(1-65535)", &idx_inst
)) {
135 if (ospf_instance
== 0) {
137 "%% OSPF is not running in instance mode\n");
138 return CMD_WARNING_CONFIG_FAILED
;
141 *instance
= strtoul(argv
[idx_inst
]->arg
, NULL
, 10);
144 *vrf_name
= VRF_DEFAULT_NAME
;
145 if (argv_find(argv
, argc
, "vrf", &idx_vrf
)) {
146 if (ospf_instance
!= 0) {
148 "%% VRF is not supported in instance mode\n");
149 return CMD_WARNING_CONFIG_FAILED
;
152 *vrf_name
= argv
[idx_vrf
+ 1]->arg
;
158 static void ospf_show_vrf_name(struct ospf
*ospf
, struct vty
*vty
,
159 json_object
*json
, uint8_t use_vrf
)
163 json_object_string_add(json
, "vrfName",
164 ospf_get_name(ospf
));
165 json_object_int_add(json
, "vrfId", ospf
->vrf_id
);
167 vty_out(vty
, "VRF Name: %s\n", ospf_get_name(ospf
));
171 #include "ospfd/ospf_vty_clippy.c"
173 DEFUN_NOSH (router_ospf
,
175 "router ospf [{(1-65535)|vrf NAME}]",
176 "Enable a routing process\n"
177 "Start OSPF configuration\n"
181 unsigned short instance
;
182 const char *vrf_name
;
183 bool created
= false;
187 ret
= ospf_router_cmd_parse(vty
, argv
, argc
, &instance
, &vrf_name
);
188 if (ret
!= CMD_SUCCESS
)
191 if (instance
!= ospf_instance
) {
192 VTY_PUSH_CONTEXT_NULL(OSPF_NODE
);
193 return CMD_NOT_MY_INSTANCE
;
196 ospf
= ospf_get(instance
, vrf_name
, &created
);
199 if (DFLT_OSPF_LOG_ADJACENCY_CHANGES
)
200 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
202 if (IS_DEBUG_OSPF_EVENT
)
204 "Config command 'router ospf %d' received, vrf %s id %u oi_running %u",
205 ospf
->instance
, ospf_get_name(ospf
), ospf
->vrf_id
,
208 VTY_PUSH_CONTEXT(OSPF_NODE
, ospf
);
213 DEFUN (no_router_ospf
,
215 "no router ospf [{(1-65535)|vrf NAME}]",
217 "Enable a routing process\n"
218 "Start OSPF configuration\n"
222 unsigned short instance
;
223 const char *vrf_name
;
227 ret
= ospf_router_cmd_parse(vty
, argv
, argc
, &instance
, &vrf_name
);
228 if (ret
!= CMD_SUCCESS
)
231 if (instance
!= ospf_instance
)
232 return CMD_NOT_MY_INSTANCE
;
234 ospf
= ospf_lookup(instance
, vrf_name
);
238 ret
= CMD_WARNING_CONFIG_FAILED
;
244 DEFPY (ospf_router_id
,
246 "ospf router-id A.B.C.D",
247 "OSPF specific commands\n"
248 "router-id for the OSPF process\n"
249 "OSPF router-id in IP address format\n")
251 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
253 struct listnode
*node
;
254 struct ospf_area
*area
;
256 ospf
->router_id_static
= router_id
;
258 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
259 if (area
->full_nbrs
) {
261 "For this router-id change to take effect, use \"clear ip ospf process\" command\n");
265 ospf_router_id_update(ospf
);
270 DEFUN_HIDDEN (ospf_router_id_old
,
271 ospf_router_id_old_cmd
,
273 "router-id for the OSPF process\n"
274 "OSPF router-id in IP address format\n")
276 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
278 struct listnode
*node
;
279 struct ospf_area
*area
;
280 struct in_addr router_id
;
283 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &router_id
);
285 vty_out(vty
, "Please specify Router ID by A.B.C.D\n");
286 return CMD_WARNING_CONFIG_FAILED
;
289 ospf
->router_id_static
= router_id
;
291 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
292 if (area
->full_nbrs
) {
294 "For this router-id change to take effect, use \"clear ip ospf process\" command\n");
298 ospf_router_id_update(ospf
);
303 DEFPY (no_ospf_router_id
,
304 no_ospf_router_id_cmd
,
305 "no ospf router-id [A.B.C.D]",
307 "OSPF specific commands\n"
308 "router-id for the OSPF process\n"
309 "OSPF router-id in IP address format\n")
311 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
312 struct listnode
*node
;
313 struct ospf_area
*area
;
316 if (!IPV4_ADDR_SAME(&ospf
->router_id_static
, &router_id
)) {
317 vty_out(vty
, "%% OSPF router-id doesn't match\n");
318 return CMD_WARNING_CONFIG_FAILED
;
322 ospf
->router_id_static
.s_addr
= 0;
324 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
325 if (area
->full_nbrs
) {
327 "For this router-id change to take effect, use \"clear ip ospf process\" command\n");
331 ospf_router_id_update(ospf
);
337 static void ospf_passive_interface_default_update(struct ospf
*ospf
,
341 struct ospf_interface
*oi
;
343 ospf
->passive_interface_default
= newval
;
345 /* update multicast memberships */
346 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, ln
, oi
))
347 ospf_if_set_multicast(oi
);
350 static void ospf_passive_interface_update(struct interface
*ifp
,
351 struct ospf_if_params
*params
,
352 struct in_addr addr
, uint8_t newval
)
354 struct route_node
*rn
;
356 if (OSPF_IF_PARAM_CONFIGURED(params
, passive_interface
)) {
357 if (params
->passive_interface
== newval
)
360 params
->passive_interface
= newval
;
361 UNSET_IF_PARAM(params
, passive_interface
);
362 if (params
!= IF_DEF_PARAMS(ifp
)) {
363 ospf_free_if_params(ifp
, addr
);
364 ospf_if_update_params(ifp
, addr
);
367 params
->passive_interface
= newval
;
368 SET_IF_PARAM(params
, passive_interface
);
372 * XXX We should call ospf_if_set_multicast on exactly those
373 * interfaces for which the passive property changed. It is too much
374 * work to determine this set, so we do this for every interface.
375 * This is safe and reasonable because ospf_if_set_multicast uses a
376 * record of joined groups to avoid systems calls if the desired
377 * memberships match the current memership.
380 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
381 struct ospf_interface
*oi
= rn
->info
;
384 ospf_if_set_multicast(oi
);
388 * XXX It is not clear what state transitions the interface needs to
389 * undergo when going from active to passive and vice versa. Fixing
390 * this will require precise identification of interfaces having such a
395 DEFUN (ospf_passive_interface_default
,
396 ospf_passive_interface_default_cmd
,
397 "passive-interface default",
398 "Suppress routing updates on an interface\n"
399 "Suppress routing updates on interfaces by default\n")
401 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
403 ospf_passive_interface_default_update(ospf
, OSPF_IF_PASSIVE
);
408 DEFUN_HIDDEN (ospf_passive_interface_addr
,
409 ospf_passive_interface_addr_cmd
,
410 "passive-interface IFNAME [A.B.C.D]",
411 "Suppress routing updates on an interface\n"
415 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
417 struct interface
*ifp
= NULL
;
418 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
419 struct ospf_if_params
*params
;
423 "This command is deprecated, because it is not VRF-aware.\n");
425 "Please, use \"ip ospf passive\" on an interface instead.\n");
427 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
428 ifp
= if_get_by_name(argv
[1]->arg
, ospf
->vrf_id
, ospf
->name
);
431 vty_out(vty
, "interface %s not found.\n", (char *)argv
[1]->arg
);
432 return CMD_WARNING_CONFIG_FAILED
;
436 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
439 "Please specify interface address by A.B.C.D\n");
440 return CMD_WARNING_CONFIG_FAILED
;
443 params
= ospf_get_if_params(ifp
, addr
);
444 ospf_if_update_params(ifp
, addr
);
446 params
= IF_DEF_PARAMS(ifp
);
449 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_PASSIVE
);
454 DEFUN (no_ospf_passive_interface_default
,
455 no_ospf_passive_interface_default_cmd
,
456 "no passive-interface default",
458 "Allow routing updates on an interface\n"
459 "Allow routing updates on interfaces by default\n")
461 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
463 ospf_passive_interface_default_update(ospf
, OSPF_IF_ACTIVE
);
468 DEFUN_HIDDEN (no_ospf_passive_interface
,
469 no_ospf_passive_interface_addr_cmd
,
470 "no passive-interface IFNAME [A.B.C.D]",
472 "Allow routing updates on an interface\n"
476 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
478 struct interface
*ifp
= NULL
;
479 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
480 struct ospf_if_params
*params
;
484 "This command is deprecated, because it is not VRF-aware.\n");
486 "Please, use \"no ip ospf passive\" on an interface instead.\n");
488 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
489 ifp
= if_get_by_name(argv
[2]->arg
, ospf
->vrf_id
, ospf
->name
);
492 vty_out(vty
, "interface %s not found.\n", (char *)argv
[2]->arg
);
493 return CMD_WARNING_CONFIG_FAILED
;
497 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
500 "Please specify interface address by A.B.C.D\n");
501 return CMD_WARNING_CONFIG_FAILED
;
503 params
= ospf_lookup_if_params(ifp
, addr
);
507 params
= IF_DEF_PARAMS(ifp
);
510 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_ACTIVE
);
516 DEFUN (ospf_network_area
,
517 ospf_network_area_cmd
,
518 "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
519 "Enable routing on an IP network\n"
520 "OSPF network prefix\n"
521 "Set the OSPF area ID\n"
522 "OSPF area ID in IP address format\n"
523 "OSPF area ID as a decimal value\n")
525 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
526 int idx_ipv4_prefixlen
= 1;
527 int idx_ipv4_number
= 3;
528 struct prefix_ipv4 p
;
529 struct in_addr area_id
;
533 if (ospf
->instance
) {
535 "The network command is not supported in multi-instance ospf\n");
536 return CMD_WARNING_CONFIG_FAILED
;
539 count
= ospf_count_area_params(ospf
);
542 "Please remove all ip ospf area x.x.x.x commands first.\n");
543 if (IS_DEBUG_OSPF_EVENT
)
545 "%s ospf vrf %s num of %u ip ospf area x config",
546 __func__
, ospf_get_name(ospf
), count
);
547 return CMD_WARNING_CONFIG_FAILED
;
550 /* Get network prefix and Area ID. */
551 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
552 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
554 ret
= ospf_network_set(ospf
, &p
, area_id
, format
);
556 vty_out(vty
, "There is already same network statement.\n");
557 return CMD_WARNING_CONFIG_FAILED
;
563 DEFUN (no_ospf_network_area
,
564 no_ospf_network_area_cmd
,
565 "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
567 "Enable routing on an IP network\n"
568 "OSPF network prefix\n"
569 "Set the OSPF area ID\n"
570 "OSPF area ID in IP address format\n"
571 "OSPF area ID as a decimal value\n")
573 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
574 int idx_ipv4_prefixlen
= 2;
575 int idx_ipv4_number
= 4;
576 struct prefix_ipv4 p
;
577 struct in_addr area_id
;
580 if (ospf
->instance
) {
582 "The network command is not supported in multi-instance ospf\n");
583 return CMD_WARNING_CONFIG_FAILED
;
586 /* Get network prefix and Area ID. */
587 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
588 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
590 ret
= ospf_network_unset(ospf
, &p
, area_id
);
593 "Can't find specified network area configuration.\n");
594 return CMD_WARNING_CONFIG_FAILED
;
600 DEFUN (ospf_area_range
,
602 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]",
603 "OSPF area parameters\n"
604 "OSPF area ID in IP address format\n"
605 "OSPF area ID as a decimal value\n"
606 "Summarize routes matching address/mask (border routers only)\n"
607 "Area range prefix\n"
608 "Advertise this range (default)\n"
609 "User specified metric for this range\n"
610 "Advertised metric for this range\n")
612 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
613 struct ospf_area
*area
;
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 area
= ospf_area_get(ospf
, area_id
);
626 ospf_area_display_format_set(ospf
, area
, format
);
628 ospf_area_range_set(ospf
, area
, area
->ranges
, &p
,
629 OSPF_AREA_RANGE_ADVERTISE
, false);
631 cost
= strtoul(argv
[idx_cost
]->arg
, NULL
, 10);
632 ospf_area_range_cost_set(ospf
, area
, area
->ranges
, &p
, cost
);
638 DEFUN (ospf_area_range_cost
,
639 ospf_area_range_cost_cmd
,
640 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M {cost (0-16777215)|substitute A.B.C.D/M}",
641 "OSPF area parameters\n"
642 "OSPF area ID in IP address format\n"
643 "OSPF area ID as a decimal value\n"
644 "Summarize routes matching address/mask (border routers only)\n"
645 "Area range prefix\n"
646 "User specified metric for this range\n"
647 "Advertised metric for this range\n"
648 "Announce area range as another prefix\n"
649 "Network prefix to be announced instead of range\n")
651 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
652 struct ospf_area
*area
;
653 int idx_ipv4_number
= 1;
654 int idx_ipv4_prefixlen
= 3;
656 struct prefix_ipv4 p
, s
;
657 struct in_addr area_id
;
661 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
662 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
664 area
= ospf_area_get(ospf
, area_id
);
665 ospf_area_display_format_set(ospf
, area
, format
);
667 ospf_area_range_set(ospf
, area
, area
->ranges
, &p
,
668 OSPF_AREA_RANGE_ADVERTISE
, false);
669 if (argv_find(argv
, argc
, "cost", &idx
)) {
670 cost
= strtoul(argv
[idx
+ 1]->arg
, NULL
, 10);
671 ospf_area_range_cost_set(ospf
, area
, area
->ranges
, &p
, cost
);
675 if (argv_find(argv
, argc
, "substitute", &idx
)) {
676 str2prefix_ipv4(argv
[idx
+ 1]->arg
, &s
);
677 ospf_area_range_substitute_set(ospf
, area
, &p
, &s
);
683 DEFUN (ospf_area_range_not_advertise
,
684 ospf_area_range_not_advertise_cmd
,
685 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise",
686 "OSPF area parameters\n"
687 "OSPF area ID in IP address format\n"
688 "OSPF area ID as a decimal value\n"
689 "Summarize routes matching address/mask (border routers only)\n"
690 "Area range prefix\n"
691 "DoNotAdvertise this range\n")
693 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
694 struct ospf_area
*area
;
695 int idx_ipv4_number
= 1;
696 int idx_ipv4_prefixlen
= 3;
697 struct prefix_ipv4 p
;
698 struct in_addr area_id
;
701 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
702 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
704 area
= ospf_area_get(ospf
, area_id
);
705 ospf_area_display_format_set(ospf
, area
, format
);
707 ospf_area_range_set(ospf
, area
, area
->ranges
, &p
, 0, false);
708 ospf_area_range_substitute_unset(ospf
, area
, &p
);
713 DEFUN (no_ospf_area_range
,
714 no_ospf_area_range_cmd
,
715 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]",
717 "OSPF area parameters\n"
718 "OSPF area ID in IP address format\n"
719 "OSPF area ID as a decimal value\n"
720 "Summarize routes matching address/mask (border routers only)\n"
721 "Area range prefix\n"
722 "User specified metric for this range\n"
723 "Advertised metric for this range\n"
724 "Advertise this range (default)\n"
725 "User specified metric for this range\n"
726 "Advertised metric for this range\n"
727 "DoNotAdvertise this range\n")
729 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
730 struct ospf_area
*area
;
731 int idx_ipv4_number
= 2;
732 int idx_ipv4_prefixlen
= 4;
733 struct prefix_ipv4 p
;
734 struct in_addr area_id
;
737 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
738 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
740 area
= ospf_area_get(ospf
, area_id
);
741 ospf_area_display_format_set(ospf
, area
, format
);
743 ospf_area_range_unset(ospf
, area
, area
->ranges
, &p
);
748 DEFUN (no_ospf_area_range_substitute
,
749 no_ospf_area_range_substitute_cmd
,
750 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
752 "OSPF area parameters\n"
753 "OSPF area ID in IP address format\n"
754 "OSPF area ID as a decimal value\n"
755 "Summarize routes matching address/mask (border routers only)\n"
756 "Area range prefix\n"
757 "Announce area range as another prefix\n"
758 "Network prefix to be announced instead of range\n")
760 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
761 struct ospf_area
*area
;
762 int idx_ipv4_number
= 2;
763 int idx_ipv4_prefixlen
= 4;
764 int idx_ipv4_prefixlen_2
= 6;
765 struct prefix_ipv4 p
, s
;
766 struct in_addr area_id
;
769 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
770 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
771 str2prefix_ipv4(argv
[idx_ipv4_prefixlen_2
]->arg
, &s
);
773 area
= ospf_area_get(ospf
, area_id
);
774 ospf_area_display_format_set(ospf
, area
, format
);
776 ospf_area_range_substitute_unset(ospf
, area
, &p
);
782 /* Command Handler Logic in VLink stuff is delicate!!
784 ALTER AT YOUR OWN RISK!!!!
786 Various dummy values are used to represent 'NoChange' state for
787 VLink configuration NOT being changed by a VLink command, and
788 special syntax is used within the command strings so that the
789 typed in command verbs can be seen in the configuration command
790 bacckend handler. This is to drastically reduce the verbeage
791 required to coe up with a reasonably compatible Cisco VLink command
793 - Matthew Grant <grantma@anathoth.gen.nz>
794 Wed, 21 Feb 2001 15:13:52 +1300
797 /* Configuration data for virtual links
799 struct ospf_vl_config_data
{
800 struct vty
*vty
; /* vty stuff */
801 struct in_addr area_id
; /* area ID from command line */
802 int area_id_fmt
; /* command line area ID format */
803 struct in_addr vl_peer
; /* command line vl_peer */
804 int auth_type
; /* Authehntication type, if given */
805 char *auth_key
; /* simple password if present */
806 int crypto_key_id
; /* Cryptographic key ID */
807 char *md5_key
; /* MD5 authentication key */
808 int hello_interval
; /* Obvious what these are... */
809 int retransmit_interval
;
814 static void ospf_vl_config_data_init(struct ospf_vl_config_data
*vl_config
,
817 memset(vl_config
, 0, sizeof(struct ospf_vl_config_data
));
818 vl_config
->auth_type
= OSPF_AUTH_CMD_NOTSEEN
;
819 vl_config
->vty
= vty
;
822 static struct ospf_vl_data
*
823 ospf_find_vl_data(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
825 struct ospf_area
*area
;
826 struct ospf_vl_data
*vl_data
;
828 struct in_addr area_id
;
830 vty
= vl_config
->vty
;
831 area_id
= vl_config
->area_id
;
833 if (area_id
.s_addr
== OSPF_AREA_BACKBONE
) {
835 "Configuring VLs over the backbone is not allowed\n");
838 area
= ospf_area_get(ospf
, area_id
);
839 ospf_area_display_format_set(ospf
, area
, vl_config
->area_id_fmt
);
841 if (area
->external_routing
!= OSPF_AREA_DEFAULT
) {
842 if (vl_config
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
843 vty_out(vty
, "Area %pI4 is %s\n", &area_id
,
844 area
->external_routing
== OSPF_AREA_NSSA
848 vty_out(vty
, "Area %ld is %s\n",
849 (unsigned long)ntohl(area_id
.s_addr
),
850 area
->external_routing
== OSPF_AREA_NSSA
856 if ((vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
->vl_peer
))
858 vl_data
= ospf_vl_data_new(area
, vl_config
->vl_peer
);
859 if (vl_data
->vl_oi
== NULL
) {
860 vl_data
->vl_oi
= ospf_vl_new(ospf
, vl_data
);
861 ospf_vl_add(ospf
, vl_data
);
862 ospf_spf_calculate_schedule(ospf
,
863 SPF_FLAG_CONFIG_CHANGE
);
870 static int ospf_vl_set_security(struct ospf_vl_data
*vl_data
,
871 struct ospf_vl_config_data
*vl_config
)
873 struct crypt_key
*ck
;
875 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
877 vty
= vl_config
->vty
;
879 if (vl_config
->auth_type
!= OSPF_AUTH_CMD_NOTSEEN
) {
880 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), auth_type
);
881 IF_DEF_PARAMS(ifp
)->auth_type
= vl_config
->auth_type
;
884 if (vl_config
->auth_key
) {
885 memset(IF_DEF_PARAMS(ifp
)->auth_simple
, 0,
886 OSPF_AUTH_SIMPLE_SIZE
+ 1);
887 strlcpy((char *)IF_DEF_PARAMS(ifp
)->auth_simple
,
889 sizeof(IF_DEF_PARAMS(ifp
)->auth_simple
));
890 } else if (vl_config
->md5_key
) {
891 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
892 vl_config
->crypto_key_id
)
894 vty_out(vty
, "OSPF: Key %d already exists\n",
895 vl_config
->crypto_key_id
);
898 ck
= ospf_crypt_key_new();
899 ck
->key_id
= vl_config
->crypto_key_id
;
900 memset(ck
->auth_key
, 0, OSPF_AUTH_MD5_SIZE
+ 1);
901 strlcpy((char *)ck
->auth_key
, vl_config
->md5_key
,
902 sizeof(ck
->auth_key
));
904 ospf_crypt_key_add(IF_DEF_PARAMS(ifp
)->auth_crypt
, ck
);
905 } else if (vl_config
->crypto_key_id
!= 0) {
908 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
909 vl_config
->crypto_key_id
)
911 vty_out(vty
, "OSPF: Key %d does not exist\n",
912 vl_config
->crypto_key_id
);
913 return CMD_WARNING_CONFIG_FAILED
;
916 ospf_crypt_key_delete(IF_DEF_PARAMS(ifp
)->auth_crypt
,
917 vl_config
->crypto_key_id
);
923 static int ospf_vl_set_timers(struct ospf_vl_data
*vl_data
,
924 struct ospf_vl_config_data
*vl_config
)
926 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
927 /* Virtual Link data initialised to defaults, so only set
929 if (vl_config
->hello_interval
) {
930 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_hello
);
931 IF_DEF_PARAMS(ifp
)->v_hello
= vl_config
->hello_interval
;
934 if (vl_config
->dead_interval
) {
935 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_wait
);
936 IF_DEF_PARAMS(ifp
)->v_wait
= vl_config
->dead_interval
;
939 if (vl_config
->retransmit_interval
) {
940 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), retransmit_interval
);
941 IF_DEF_PARAMS(ifp
)->retransmit_interval
=
942 vl_config
->retransmit_interval
;
945 if (vl_config
->transmit_delay
) {
946 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), transmit_delay
);
947 IF_DEF_PARAMS(ifp
)->transmit_delay
= vl_config
->transmit_delay
;
954 /* The business end of all of the above */
955 static int ospf_vl_set(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
957 struct ospf_vl_data
*vl_data
;
960 vl_data
= ospf_find_vl_data(ospf
, vl_config
);
962 return CMD_WARNING_CONFIG_FAILED
;
964 /* Process this one first as it can have a fatal result, which can
965 only logically occur if the virtual link exists already
966 Thus a command error does not result in a change to the
967 running configuration such as unexpectedly altered timer
969 ret
= ospf_vl_set_security(vl_data
, vl_config
);
970 if (ret
!= CMD_SUCCESS
)
973 /* Set any time based parameters, these area already range checked */
975 ret
= ospf_vl_set_timers(vl_data
, vl_config
);
976 if (ret
!= CMD_SUCCESS
)
982 /* This stuff exists to make specifying all the alias commands A LOT simpler
984 #define VLINK_HELPSTR_IPADDR \
985 "OSPF area parameters\n" \
986 "OSPF area ID in IP address format\n" \
987 "OSPF area ID as a decimal value\n" \
988 "Configure a virtual link\n" \
989 "Router ID of the remote ABR\n"
991 #define VLINK_HELPSTR_AUTHTYPE_SIMPLE \
992 "Enable authentication on this virtual link\n" \
995 #define VLINK_HELPSTR_AUTHTYPE_ALL \
996 VLINK_HELPSTR_AUTHTYPE_SIMPLE \
997 "Use null authentication\n" \
998 "Use message-digest authentication\n"
1000 #define VLINK_HELPSTR_TIME_PARAM \
1001 "Time between HELLO packets\n" \
1003 "Time between retransmitting lost link state advertisements\n" \
1005 "Link state transmit delay\n" \
1007 "Interval time after which a neighbor is declared down\n" \
1010 #define VLINK_HELPSTR_AUTH_SIMPLE \
1011 "Authentication password (key)\n" \
1012 "The OSPF password (key)\n"
1014 #define VLINK_HELPSTR_AUTH_MD5 \
1015 "Message digest authentication password (key)\n" \
1017 "Use MD5 algorithm\n" \
1018 "The OSPF password (key)\n"
1020 DEFUN (ospf_area_vlink
,
1021 ospf_area_vlink_cmd
,
1022 "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>]",
1023 VLINK_HELPSTR_IPADDR
1024 "Enable authentication on this virtual link\n"
1025 "Use message-digest authentication\n"
1026 "Use null authentication\n"
1027 VLINK_HELPSTR_AUTH_MD5
1028 VLINK_HELPSTR_AUTH_SIMPLE
)
1030 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1031 int idx_ipv4_number
= 1;
1033 struct ospf_vl_config_data vl_config
;
1034 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1035 char md5_key
[OSPF_AUTH_MD5_SIZE
+ 1];
1039 ospf_vl_config_data_init(&vl_config
, vty
);
1041 /* Read off first 2 parameters and check them */
1042 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1043 &vl_config
.area_id_fmt
);
1045 vty_out(vty
, "OSPF area ID is invalid\n");
1046 return CMD_WARNING_CONFIG_FAILED
;
1049 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1051 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1052 return CMD_WARNING_CONFIG_FAILED
;
1056 /* Thats all folks! - BUGS B. strikes again!!!*/
1058 return ospf_vl_set(ospf
, &vl_config
);
1061 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1062 /* authentication - this option can only occur
1063 at start of command line */
1064 vl_config
.auth_type
= OSPF_AUTH_SIMPLE
;
1067 if (argv_find(argv
, argc
, "message-digest", &idx
)) {
1068 /* authentication message-digest */
1069 vl_config
.auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
1070 } else if (argv_find(argv
, argc
, "null", &idx
)) {
1071 /* "authentication null" */
1072 vl_config
.auth_type
= OSPF_AUTH_NULL
;
1075 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1076 vl_config
.md5_key
= NULL
;
1077 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1078 if (vl_config
.crypto_key_id
< 0)
1079 return CMD_WARNING_CONFIG_FAILED
;
1081 strlcpy(md5_key
, argv
[idx
+ 3]->arg
, sizeof(md5_key
));
1082 vl_config
.md5_key
= md5_key
;
1085 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1086 strlcpy(auth_key
, argv
[idx
+ 1]->arg
, sizeof(auth_key
));
1087 vl_config
.auth_key
= auth_key
;
1090 /* Action configuration */
1092 return ospf_vl_set(ospf
, &vl_config
);
1095 DEFUN (no_ospf_area_vlink
,
1096 no_ospf_area_vlink_cmd
,
1097 "no area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D [authentication [<message-digest|null>]] [<message-digest-key (1-255) md5 KEY|authentication-key AUTH_KEY>]",
1099 VLINK_HELPSTR_IPADDR
1100 "Enable authentication on this virtual link\n"
1101 "Use message-digest authentication\n"
1102 "Use null authentication\n"
1103 VLINK_HELPSTR_AUTH_MD5
1104 VLINK_HELPSTR_AUTH_SIMPLE
)
1106 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1107 int idx_ipv4_number
= 2;
1109 struct ospf_area
*area
;
1110 struct ospf_vl_config_data vl_config
;
1111 struct ospf_vl_data
*vl_data
= NULL
;
1112 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1116 ospf_vl_config_data_init(&vl_config
, vty
);
1118 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1121 vty_out(vty
, "OSPF area ID is invalid\n");
1122 return CMD_WARNING_CONFIG_FAILED
;
1125 area
= ospf_area_lookup_by_area_id(ospf
, vl_config
.area_id
);
1127 vty_out(vty
, "Area does not exist\n");
1128 return CMD_WARNING_CONFIG_FAILED
;
1131 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1133 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1134 return CMD_WARNING_CONFIG_FAILED
;
1137 vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
.vl_peer
);
1139 vty_out(vty
, "Virtual link does not exist\n");
1140 return CMD_WARNING_CONFIG_FAILED
;
1144 /* Basic VLink no command */
1145 /* Thats all folks! - BUGS B. strikes again!!!*/
1146 ospf_vl_delete(ospf
, vl_data
);
1147 ospf_area_check_free(ospf
, vl_config
.area_id
);
1151 /* If we are down here, we are reseting parameters */
1152 /* Deal with other parameters */
1154 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1155 /* authentication - this option can only occur
1156 at start of command line */
1157 vl_config
.auth_type
= OSPF_AUTH_NOTSET
;
1160 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1161 vl_config
.md5_key
= NULL
;
1162 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1163 if (vl_config
.crypto_key_id
< 0)
1164 return CMD_WARNING_CONFIG_FAILED
;
1167 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1168 /* Reset authentication-key to 0 */
1169 memset(auth_key
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
1170 vl_config
.auth_key
= auth_key
;
1173 /* Action configuration */
1175 return ospf_vl_set(ospf
, &vl_config
);
1178 DEFUN (ospf_area_vlink_intervals
,
1179 ospf_area_vlink_intervals_cmd
,
1180 "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)}",
1181 VLINK_HELPSTR_IPADDR
1182 VLINK_HELPSTR_TIME_PARAM
)
1184 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1185 struct ospf_vl_config_data vl_config
;
1188 ospf_vl_config_data_init(&vl_config
, vty
);
1190 char *area_id
= argv
[1]->arg
;
1191 char *router_id
= argv
[3]->arg
;
1193 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1195 vty_out(vty
, "OSPF area ID is invalid\n");
1196 return CMD_WARNING_CONFIG_FAILED
;
1199 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1201 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1202 return CMD_WARNING_CONFIG_FAILED
;
1205 for (int idx
= 4; idx
< argc
; idx
++) {
1206 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1207 vl_config
.hello_interval
=
1208 strtol(argv
[++idx
]->arg
, NULL
, 10);
1209 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1210 vl_config
.retransmit_interval
=
1211 strtol(argv
[++idx
]->arg
, NULL
, 10);
1212 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1213 vl_config
.transmit_delay
=
1214 strtol(argv
[++idx
]->arg
, NULL
, 10);
1215 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1216 vl_config
.dead_interval
=
1217 strtol(argv
[++idx
]->arg
, NULL
, 10);
1220 /* Action configuration */
1221 return ospf_vl_set(ospf
, &vl_config
);
1224 DEFUN (no_ospf_area_vlink_intervals
,
1225 no_ospf_area_vlink_intervals_cmd
,
1226 "no area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D {hello-interval (1-65535)|retransmit-interval (1-65535)|transmit-delay (1-65535)|dead-interval (1-65535)}",
1228 VLINK_HELPSTR_IPADDR
1229 VLINK_HELPSTR_TIME_PARAM
)
1231 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1232 struct ospf_vl_config_data vl_config
;
1235 ospf_vl_config_data_init(&vl_config
, vty
);
1237 char *area_id
= argv
[2]->arg
;
1238 char *router_id
= argv
[4]->arg
;
1240 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1242 vty_out(vty
, "OSPF area ID is invalid\n");
1243 return CMD_WARNING_CONFIG_FAILED
;
1246 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1248 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1249 return CMD_WARNING_CONFIG_FAILED
;
1252 for (int idx
= 5; idx
< argc
; idx
++) {
1253 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1254 vl_config
.hello_interval
= OSPF_HELLO_INTERVAL_DEFAULT
;
1255 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1256 vl_config
.retransmit_interval
=
1257 OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
1258 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1259 vl_config
.transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
1260 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1261 vl_config
.dead_interval
=
1262 OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
1265 /* Action configuration */
1266 return ospf_vl_set(ospf
, &vl_config
);
1269 DEFUN (ospf_area_shortcut
,
1270 ospf_area_shortcut_cmd
,
1271 "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>",
1272 "OSPF area parameters\n"
1273 "OSPF area ID in IP address format\n"
1274 "OSPF area ID as a decimal value\n"
1275 "Configure the area's shortcutting mode\n"
1276 "Set default shortcutting behavior\n"
1277 "Enable shortcutting through the area\n"
1278 "Disable shortcutting through the area\n")
1280 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1281 int idx_ipv4_number
= 1;
1282 int idx_enable_disable
= 3;
1283 struct ospf_area
*area
;
1284 struct in_addr area_id
;
1288 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1289 argv
[idx_ipv4_number
]->arg
);
1291 area
= ospf_area_get(ospf
, area_id
);
1292 ospf_area_display_format_set(ospf
, area
, format
);
1294 if (strncmp(argv
[idx_enable_disable
]->arg
, "de", 2) == 0)
1295 mode
= OSPF_SHORTCUT_DEFAULT
;
1296 else if (strncmp(argv
[idx_enable_disable
]->arg
, "di", 2) == 0)
1297 mode
= OSPF_SHORTCUT_DISABLE
;
1298 else if (strncmp(argv
[idx_enable_disable
]->arg
, "e", 1) == 0)
1299 mode
= OSPF_SHORTCUT_ENABLE
;
1301 return CMD_WARNING_CONFIG_FAILED
;
1303 ospf_area_shortcut_set(ospf
, area
, mode
);
1305 if (ospf
->abr_type
!= OSPF_ABR_SHORTCUT
)
1307 "Shortcut area setting will take effect only when the router is configured as Shortcut ABR\n");
1312 DEFUN (no_ospf_area_shortcut
,
1313 no_ospf_area_shortcut_cmd
,
1314 "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>",
1316 "OSPF area parameters\n"
1317 "OSPF area ID in IP address format\n"
1318 "OSPF area ID as a decimal value\n"
1319 "Deconfigure the area's shortcutting mode\n"
1320 "Deconfigure enabled shortcutting through the area\n"
1321 "Deconfigure disabled shortcutting through the area\n")
1323 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1324 int idx_ipv4_number
= 2;
1325 struct ospf_area
*area
;
1326 struct in_addr area_id
;
1329 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1330 argv
[idx_ipv4_number
]->arg
);
1332 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1336 ospf_area_shortcut_unset(ospf
, area
);
1342 DEFUN (ospf_area_stub
,
1344 "area <A.B.C.D|(0-4294967295)> stub",
1345 "OSPF area parameters\n"
1346 "OSPF area ID in IP address format\n"
1347 "OSPF area ID as a decimal value\n"
1348 "Configure OSPF area as stub\n")
1350 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1351 int idx_ipv4_number
= 1;
1352 struct in_addr area_id
;
1355 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1356 argv
[idx_ipv4_number
]->arg
);
1358 ret
= ospf_area_stub_set(ospf
, area_id
);
1359 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1363 "First deconfigure all virtual link through this area\n");
1364 return CMD_WARNING_CONFIG_FAILED
;
1367 /* Flush the external LSAs from the specified area */
1368 ospf_flush_lsa_from_area(ospf
, area_id
, OSPF_AS_EXTERNAL_LSA
);
1369 ospf_area_no_summary_unset(ospf
, area_id
);
1374 DEFUN (ospf_area_stub_no_summary
,
1375 ospf_area_stub_no_summary_cmd
,
1376 "area <A.B.C.D|(0-4294967295)> stub no-summary",
1377 "OSPF stub parameters\n"
1378 "OSPF area ID in IP address format\n"
1379 "OSPF area ID as a decimal value\n"
1380 "Configure OSPF area as stub\n"
1381 "Do not inject inter-area routes into stub\n")
1383 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1384 int idx_ipv4_number
= 1;
1385 struct in_addr area_id
;
1388 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1389 argv
[idx_ipv4_number
]->arg
);
1391 ret
= ospf_area_stub_set(ospf
, area_id
);
1392 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1396 "%% Area cannot be stub as it contains a virtual link\n");
1397 return CMD_WARNING_CONFIG_FAILED
;
1400 ospf_area_no_summary_set(ospf
, area_id
);
1405 DEFUN (no_ospf_area_stub
,
1406 no_ospf_area_stub_cmd
,
1407 "no area <A.B.C.D|(0-4294967295)> stub",
1409 "OSPF area parameters\n"
1410 "OSPF area ID in IP address format\n"
1411 "OSPF area ID as a decimal value\n"
1412 "Configure OSPF area as stub\n")
1414 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1415 int idx_ipv4_number
= 2;
1416 struct in_addr area_id
;
1419 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1420 argv
[idx_ipv4_number
]->arg
);
1422 ospf_area_stub_unset(ospf
, area_id
);
1423 ospf_area_no_summary_unset(ospf
, area_id
);
1428 DEFUN (no_ospf_area_stub_no_summary
,
1429 no_ospf_area_stub_no_summary_cmd
,
1430 "no area <A.B.C.D|(0-4294967295)> stub no-summary",
1432 "OSPF area parameters\n"
1433 "OSPF area ID in IP address format\n"
1434 "OSPF area ID as a decimal value\n"
1435 "Configure OSPF area as stub\n"
1436 "Do not inject inter-area routes into area\n")
1438 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1439 int idx_ipv4_number
= 2;
1440 struct in_addr area_id
;
1443 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1444 argv
[idx_ipv4_number
]->arg
);
1445 ospf_area_no_summary_unset(ospf
, area_id
);
1450 DEFPY (ospf_area_nssa
,
1452 "area <A.B.C.D|(0-4294967295)>$area_str nssa\
1454 <translate-candidate|translate-never|translate-always>$translator_role\
1455 |default-information-originate$dflt_originate [{metric (0-16777214)$mval|metric-type (1-2)$mtype}]\
1456 |no-summary$no_summary\
1457 |suppress-fa$suppress_fa\
1459 "OSPF area parameters\n"
1460 "OSPF area ID in IP address format\n"
1461 "OSPF area ID as a decimal value\n"
1462 "Configure OSPF area as nssa\n"
1463 "Configure NSSA-ABR for translate election (default)\n"
1464 "Configure NSSA-ABR to never translate\n"
1465 "Configure NSSA-ABR to always translate\n"
1466 "Originate Type 7 default into NSSA area\n"
1467 "OSPF default metric\n"
1469 "OSPF metric type for default routes\n"
1470 "Set OSPF External Type 1/2 metrics\n"
1471 "Do not inject inter-area routes into nssa\n"
1472 "Suppress forwarding address\n")
1474 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1475 struct in_addr area_id
;
1478 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
, area_str
);
1480 ret
= ospf_area_nssa_set(ospf
, area_id
);
1481 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1485 "%% Area cannot be nssa as it contains a virtual link\n");
1486 return CMD_WARNING_CONFIG_FAILED
;
1489 if (translator_role
) {
1490 if (strncmp(translator_role
, "translate-c", 11) == 0)
1491 ospf_area_nssa_translator_role_set(
1492 ospf
, area_id
, OSPF_NSSA_ROLE_CANDIDATE
);
1493 else if (strncmp(translator_role
, "translate-n", 11) == 0)
1494 ospf_area_nssa_translator_role_set(
1495 ospf
, area_id
, OSPF_NSSA_ROLE_NEVER
);
1496 else if (strncmp(translator_role
, "translate-a", 11) == 0)
1497 ospf_area_nssa_translator_role_set(
1498 ospf
, area_id
, OSPF_NSSA_ROLE_ALWAYS
);
1500 ospf_area_nssa_translator_role_set(ospf
, area_id
,
1501 OSPF_NSSA_ROLE_CANDIDATE
);
1504 if (dflt_originate
) {
1505 int metric_type
= DEFAULT_METRIC_TYPE
;
1507 if (mval_str
== NULL
)
1510 (void)str2metric_type(mtype_str
, &metric_type
);
1511 ospf_area_nssa_default_originate_set(ospf
, area_id
, mval
,
1514 ospf_area_nssa_default_originate_unset(ospf
, area_id
);
1517 ospf_area_nssa_no_summary_set(ospf
, area_id
);
1519 ospf_area_no_summary_unset(ospf
, area_id
);
1522 ospf_area_nssa_suppress_fa_set(ospf
, area_id
);
1524 ospf_area_nssa_suppress_fa_unset(ospf
, area_id
);
1526 /* Flush the external LSA for the specified area */
1527 ospf_flush_lsa_from_area(ospf
, area_id
, OSPF_AS_EXTERNAL_LSA
);
1528 ospf_schedule_abr_task(ospf
);
1529 ospf_schedule_asbr_nssa_redist_update(ospf
);
1534 DEFPY (no_ospf_area_nssa
,
1535 no_ospf_area_nssa_cmd
,
1536 "no area <A.B.C.D|(0-4294967295)>$area_str nssa\
1538 <translate-candidate|translate-never|translate-always>\
1539 |default-information-originate [{metric (0-16777214)|metric-type (1-2)}]\
1544 "OSPF area parameters\n"
1545 "OSPF area ID in IP address format\n"
1546 "OSPF area ID as a decimal value\n"
1547 "Configure OSPF area as nssa\n"
1548 "Configure NSSA-ABR for translate election (default)\n"
1549 "Configure NSSA-ABR to never translate\n"
1550 "Configure NSSA-ABR to always translate\n"
1551 "Originate Type 7 default into NSSA area\n"
1552 "OSPF default metric\n"
1554 "OSPF metric type for default routes\n"
1555 "Set OSPF External Type 1/2 metrics\n"
1556 "Do not inject inter-area routes into nssa\n"
1557 "Suppress forwarding address\n")
1559 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1560 struct in_addr area_id
;
1563 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
, area_str
);
1565 /* Flush the NSSA LSA for the specified area */
1566 ospf_flush_lsa_from_area(ospf
, area_id
, OSPF_AS_NSSA_LSA
);
1567 ospf_area_no_summary_unset(ospf
, area_id
);
1568 ospf_area_nssa_default_originate_unset(ospf
, area_id
);
1569 ospf_area_nssa_suppress_fa_unset(ospf
, area_id
);
1570 ospf_area_nssa_unset(ospf
, area_id
);
1572 ospf_schedule_abr_task(ospf
);
1577 DEFPY (ospf_area_nssa_range
,
1578 ospf_area_nssa_range_cmd
,
1579 "area <A.B.C.D|(0-4294967295)>$area_str nssa range A.B.C.D/M$prefix [<not-advertise$not_adv|cost (0-16777215)$cost>]",
1580 "OSPF area parameters\n"
1581 "OSPF area ID in IP address format\n"
1582 "OSPF area ID as a decimal value\n"
1583 "Configure OSPF area as nssa\n"
1584 "Configured address range\n"
1585 "Specify IPv4 prefix\n"
1586 "Do not advertise\n"
1587 "User specified metric for this range\n"
1588 "Advertised metric for this range\n")
1590 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1591 struct ospf_area
*area
;
1592 struct in_addr area_id
;
1596 VTY_GET_OSPF_AREA_ID(area_id
, format
, area_str
);
1597 area
= ospf_area_get(ospf
, area_id
);
1598 ospf_area_display_format_set(ospf
, area
, format
);
1600 if (area
->external_routing
!= OSPF_AREA_NSSA
) {
1601 vty_out(vty
, "%% First configure %s as an NSSA area\n",
1607 advertise
= OSPF_AREA_RANGE_ADVERTISE
;
1609 ospf_area_range_set(ospf
, area
, area
->nssa_ranges
,
1610 (struct prefix_ipv4
*)prefix
, advertise
, true);
1612 ospf_area_range_cost_set(ospf
, area
, area
->nssa_ranges
,
1613 (struct prefix_ipv4
*)prefix
, cost
);
1618 DEFPY (no_ospf_area_nssa_range
,
1619 no_ospf_area_nssa_range_cmd
,
1620 "no area <A.B.C.D|(0-4294967295)>$area_str nssa range A.B.C.D/M$prefix [<not-advertise|cost (0-16777215)>]",
1622 "OSPF area parameters\n"
1623 "OSPF area ID in IP address format\n"
1624 "OSPF area ID as a decimal value\n"
1625 "Configure OSPF area as nssa\n"
1626 "Configured address range\n"
1627 "Specify IPv4 prefix\n"
1628 "Do not advertise\n"
1629 "User specified metric for this range\n"
1630 "Advertised metric for this range\n")
1632 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1633 struct ospf_area
*area
;
1634 struct in_addr area_id
;
1637 VTY_GET_OSPF_AREA_ID(area_id
, format
, area_str
);
1638 area
= ospf_area_get(ospf
, area_id
);
1639 ospf_area_display_format_set(ospf
, area
, format
);
1641 if (area
->external_routing
!= OSPF_AREA_NSSA
) {
1642 vty_out(vty
, "%% First configure %s as an NSSA area\n",
1647 ospf_area_range_unset(ospf
, area
, area
->nssa_ranges
,
1648 (struct prefix_ipv4
*)prefix
);
1653 DEFUN (ospf_area_default_cost
,
1654 ospf_area_default_cost_cmd
,
1655 "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1656 "OSPF area parameters\n"
1657 "OSPF area ID in IP address format\n"
1658 "OSPF area ID as a decimal value\n"
1659 "Set the summary-default cost of a NSSA or stub area\n"
1660 "Stub's advertised default summary cost\n")
1662 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1663 int idx_ipv4_number
= 1;
1665 struct ospf_area
*area
;
1666 struct in_addr area_id
;
1669 struct prefix_ipv4 p
;
1671 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1672 argv
[idx_ipv4_number
]->arg
);
1673 cost
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1675 area
= ospf_area_get(ospf
, area_id
);
1676 ospf_area_display_format_set(ospf
, area
, format
);
1678 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1679 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1680 return CMD_WARNING_CONFIG_FAILED
;
1683 area
->default_cost
= cost
;
1686 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1688 if (IS_DEBUG_OSPF_EVENT
)
1690 "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4",
1692 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1697 DEFUN (no_ospf_area_default_cost
,
1698 no_ospf_area_default_cost_cmd
,
1699 "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1701 "OSPF area parameters\n"
1702 "OSPF area ID in IP address format\n"
1703 "OSPF area ID as a decimal value\n"
1704 "Set the summary-default cost of a NSSA or stub area\n"
1705 "Stub's advertised default summary cost\n")
1707 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1708 int idx_ipv4_number
= 2;
1709 struct ospf_area
*area
;
1710 struct in_addr area_id
;
1712 struct prefix_ipv4 p
;
1714 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1715 argv
[idx_ipv4_number
]->arg
);
1717 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1721 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1722 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1723 return CMD_WARNING_CONFIG_FAILED
;
1726 area
->default_cost
= 1;
1729 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1731 if (IS_DEBUG_OSPF_EVENT
)
1733 "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4",
1735 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1738 ospf_area_check_free(ospf
, area_id
);
1743 DEFUN (ospf_area_export_list
,
1744 ospf_area_export_list_cmd
,
1745 "area <A.B.C.D|(0-4294967295)> export-list ACCESSLIST4_NAME",
1746 "OSPF area parameters\n"
1747 "OSPF area ID in IP address format\n"
1748 "OSPF area ID as a decimal value\n"
1749 "Set the filter for networks announced to other areas\n"
1750 "Name of the access-list\n")
1752 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1753 int idx_ipv4_number
= 1;
1754 struct ospf_area
*area
;
1755 struct in_addr area_id
;
1758 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1760 area
= ospf_area_get(ospf
, area_id
);
1761 ospf_area_display_format_set(ospf
, area
, format
);
1762 ospf_area_export_list_set(ospf
, area
, argv
[3]->arg
);
1767 DEFUN (no_ospf_area_export_list
,
1768 no_ospf_area_export_list_cmd
,
1769 "no area <A.B.C.D|(0-4294967295)> export-list ACCESSLIST4_NAME",
1771 "OSPF area parameters\n"
1772 "OSPF area ID in IP address format\n"
1773 "OSPF area ID as a decimal value\n"
1774 "Unset the filter for networks announced to other areas\n"
1775 "Name of the access-list\n")
1777 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1778 int idx_ipv4_number
= 2;
1779 struct ospf_area
*area
;
1780 struct in_addr area_id
;
1783 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1785 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1789 ospf_area_export_list_unset(ospf
, area
);
1795 DEFUN (ospf_area_import_list
,
1796 ospf_area_import_list_cmd
,
1797 "area <A.B.C.D|(0-4294967295)> import-list ACCESSLIST4_NAME",
1798 "OSPF area parameters\n"
1799 "OSPF area ID in IP address format\n"
1800 "OSPF area ID as a decimal value\n"
1801 "Set the filter for networks from other areas announced to the specified one\n"
1802 "Name of the access-list\n")
1804 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1805 int idx_ipv4_number
= 1;
1806 struct ospf_area
*area
;
1807 struct in_addr area_id
;
1810 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1812 area
= ospf_area_get(ospf
, area_id
);
1813 ospf_area_display_format_set(ospf
, area
, format
);
1814 ospf_area_import_list_set(ospf
, area
, argv
[3]->arg
);
1819 DEFUN (no_ospf_area_import_list
,
1820 no_ospf_area_import_list_cmd
,
1821 "no area <A.B.C.D|(0-4294967295)> import-list ACCESSLIST4_NAME",
1823 "OSPF area parameters\n"
1824 "OSPF area ID in IP address format\n"
1825 "OSPF area ID as a decimal value\n"
1826 "Unset the filter for networks announced to other areas\n"
1827 "Name of the access-list\n")
1829 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1830 int idx_ipv4_number
= 2;
1831 struct ospf_area
*area
;
1832 struct in_addr area_id
;
1835 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1837 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1841 ospf_area_import_list_unset(ospf
, area
);
1846 DEFUN (ospf_area_filter_list
,
1847 ospf_area_filter_list_cmd
,
1848 "area <A.B.C.D|(0-4294967295)> filter-list prefix PREFIXLIST_NAME <in|out>",
1849 "OSPF area parameters\n"
1850 "OSPF area ID in IP address format\n"
1851 "OSPF area ID as a decimal value\n"
1852 "Filter networks between OSPF areas\n"
1853 "Filter prefixes between OSPF areas\n"
1854 "Name of an IP prefix-list\n"
1855 "Filter networks sent to this area\n"
1856 "Filter networks sent from this area\n")
1858 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1859 int idx_ipv4_number
= 1;
1862 struct ospf_area
*area
;
1863 struct in_addr area_id
;
1864 struct prefix_list
*plist
;
1867 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1869 area
= ospf_area_get(ospf
, area_id
);
1870 ospf_area_display_format_set(ospf
, area
, format
);
1871 plist
= prefix_list_lookup(AFI_IP
, argv
[idx_word
]->arg
);
1872 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1873 PREFIX_LIST_IN(area
) = plist
;
1874 if (PREFIX_NAME_IN(area
))
1875 free(PREFIX_NAME_IN(area
));
1877 PREFIX_NAME_IN(area
) = strdup(argv
[idx_word
]->arg
);
1878 ospf_schedule_abr_task(ospf
);
1880 PREFIX_LIST_OUT(area
) = plist
;
1881 if (PREFIX_NAME_OUT(area
))
1882 free(PREFIX_NAME_OUT(area
));
1884 PREFIX_NAME_OUT(area
) = strdup(argv
[idx_word
]->arg
);
1885 ospf_schedule_abr_task(ospf
);
1891 DEFUN (no_ospf_area_filter_list
,
1892 no_ospf_area_filter_list_cmd
,
1893 "no area <A.B.C.D|(0-4294967295)> filter-list prefix PREFIXLIST_NAME <in|out>",
1895 "OSPF area parameters\n"
1896 "OSPF area ID in IP address format\n"
1897 "OSPF area ID as a decimal value\n"
1898 "Filter networks between OSPF areas\n"
1899 "Filter prefixes between OSPF areas\n"
1900 "Name of an IP prefix-list\n"
1901 "Filter networks sent to this area\n"
1902 "Filter networks sent from this area\n")
1904 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1905 int idx_ipv4_number
= 2;
1908 struct ospf_area
*area
;
1909 struct in_addr area_id
;
1912 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1914 if ((area
= ospf_area_lookup_by_area_id(ospf
, area_id
)) == NULL
)
1917 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1918 if (PREFIX_NAME_IN(area
))
1919 if (strcmp(PREFIX_NAME_IN(area
), argv
[idx_word
]->arg
)
1923 PREFIX_LIST_IN(area
) = NULL
;
1924 if (PREFIX_NAME_IN(area
))
1925 free(PREFIX_NAME_IN(area
));
1927 PREFIX_NAME_IN(area
) = NULL
;
1929 ospf_schedule_abr_task(ospf
);
1931 if (PREFIX_NAME_OUT(area
))
1932 if (strcmp(PREFIX_NAME_OUT(area
), argv
[idx_word
]->arg
)
1936 PREFIX_LIST_OUT(area
) = NULL
;
1937 if (PREFIX_NAME_OUT(area
))
1938 free(PREFIX_NAME_OUT(area
));
1940 PREFIX_NAME_OUT(area
) = NULL
;
1942 ospf_schedule_abr_task(ospf
);
1949 DEFUN (ospf_area_authentication_message_digest
,
1950 ospf_area_authentication_message_digest_cmd
,
1951 "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest",
1953 "OSPF area parameters\n"
1954 "OSPF area ID in IP address format\n"
1955 "OSPF area ID as a decimal value\n"
1956 "Enable authentication\n"
1957 "Use message-digest authentication\n")
1959 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1961 struct ospf_area
*area
;
1962 struct in_addr area_id
;
1965 argv_find(argv
, argc
, "area", &idx
);
1966 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx
+ 1]->arg
);
1968 area
= ospf_area_get(ospf
, area_id
);
1969 ospf_area_display_format_set(ospf
, area
, format
);
1970 area
->auth_type
= strmatch(argv
[0]->text
, "no")
1972 : OSPF_AUTH_CRYPTOGRAPHIC
;
1977 DEFUN (ospf_area_authentication
,
1978 ospf_area_authentication_cmd
,
1979 "area <A.B.C.D|(0-4294967295)> authentication",
1980 "OSPF area parameters\n"
1981 "OSPF area ID in IP address format\n"
1982 "OSPF area ID as a decimal value\n"
1983 "Enable authentication\n")
1985 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1986 int idx_ipv4_number
= 1;
1987 struct ospf_area
*area
;
1988 struct in_addr area_id
;
1991 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1993 area
= ospf_area_get(ospf
, area_id
);
1994 ospf_area_display_format_set(ospf
, area
, format
);
1995 area
->auth_type
= OSPF_AUTH_SIMPLE
;
2000 DEFUN (no_ospf_area_authentication
,
2001 no_ospf_area_authentication_cmd
,
2002 "no area <A.B.C.D|(0-4294967295)> authentication",
2004 "OSPF area parameters\n"
2005 "OSPF area ID in IP address format\n"
2006 "OSPF area ID as a decimal value\n"
2007 "Enable authentication\n")
2009 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2010 int idx_ipv4_number
= 2;
2011 struct ospf_area
*area
;
2012 struct in_addr area_id
;
2015 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
2017 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
2021 area
->auth_type
= OSPF_AUTH_NULL
;
2023 ospf_area_check_free(ospf
, area_id
);
2029 DEFUN (ospf_abr_type
,
2031 "ospf abr-type <cisco|ibm|shortcut|standard>",
2032 "OSPF specific commands\n"
2033 "Set OSPF ABR type\n"
2034 "Alternative ABR, cisco implementation\n"
2035 "Alternative ABR, IBM implementation\n"
2037 "Standard behavior (RFC2328)\n")
2039 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2041 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2043 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2044 abr_type
= OSPF_ABR_CISCO
;
2045 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2046 abr_type
= OSPF_ABR_IBM
;
2047 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2048 abr_type
= OSPF_ABR_SHORTCUT
;
2049 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2050 abr_type
= OSPF_ABR_STAND
;
2052 return CMD_WARNING_CONFIG_FAILED
;
2054 /* If ABR type value is changed, schedule ABR task. */
2055 if (ospf
->abr_type
!= abr_type
) {
2056 ospf
->abr_type
= abr_type
;
2057 ospf_schedule_abr_task(ospf
);
2063 DEFUN (no_ospf_abr_type
,
2064 no_ospf_abr_type_cmd
,
2065 "no ospf abr-type <cisco|ibm|shortcut|standard>",
2067 "OSPF specific commands\n"
2068 "Set OSPF ABR type\n"
2069 "Alternative ABR, cisco implementation\n"
2070 "Alternative ABR, IBM implementation\n"
2074 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2076 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2078 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2079 abr_type
= OSPF_ABR_CISCO
;
2080 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2081 abr_type
= OSPF_ABR_IBM
;
2082 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2083 abr_type
= OSPF_ABR_SHORTCUT
;
2084 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2085 abr_type
= OSPF_ABR_STAND
;
2087 return CMD_WARNING_CONFIG_FAILED
;
2089 /* If ABR type value is changed, schedule ABR task. */
2090 if (ospf
->abr_type
== abr_type
) {
2091 ospf
->abr_type
= OSPF_ABR_DEFAULT
;
2092 ospf_schedule_abr_task(ospf
);
2098 DEFUN (ospf_log_adjacency_changes
,
2099 ospf_log_adjacency_changes_cmd
,
2100 "log-adjacency-changes",
2101 "Log changes in adjacency state\n")
2103 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2105 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2106 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2110 DEFUN (ospf_log_adjacency_changes_detail
,
2111 ospf_log_adjacency_changes_detail_cmd
,
2112 "log-adjacency-changes detail",
2113 "Log changes in adjacency state\n"
2114 "Log all state changes\n")
2116 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2118 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2119 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2123 DEFUN (no_ospf_log_adjacency_changes
,
2124 no_ospf_log_adjacency_changes_cmd
,
2125 "no log-adjacency-changes",
2127 "Log changes in adjacency state\n")
2129 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2131 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2132 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2136 DEFUN (no_ospf_log_adjacency_changes_detail
,
2137 no_ospf_log_adjacency_changes_detail_cmd
,
2138 "no log-adjacency-changes detail",
2140 "Log changes in adjacency state\n"
2141 "Log all state changes\n")
2143 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2145 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2149 DEFUN (ospf_compatible_rfc1583
,
2150 ospf_compatible_rfc1583_cmd
,
2151 "compatible rfc1583",
2152 "OSPF compatibility list\n"
2153 "compatible with RFC 1583\n")
2155 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2157 if (!CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2158 SET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2159 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2164 DEFUN (no_ospf_compatible_rfc1583
,
2165 no_ospf_compatible_rfc1583_cmd
,
2166 "no compatible rfc1583",
2168 "OSPF compatibility list\n"
2169 "compatible with RFC 1583\n")
2171 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2173 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2174 UNSET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2175 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2180 ALIAS(ospf_compatible_rfc1583
, ospf_rfc1583_flag_cmd
,
2181 "ospf rfc1583compatibility",
2182 "OSPF specific commands\n"
2183 "Enable the RFC1583Compatibility flag\n")
2185 ALIAS(no_ospf_compatible_rfc1583
, no_ospf_rfc1583_flag_cmd
,
2186 "no ospf rfc1583compatibility", NO_STR
2187 "OSPF specific commands\n"
2188 "Disable the RFC1583Compatibility flag\n")
2190 static void ospf_table_reinstall_routes(struct ospf
*ospf
,
2191 struct route_table
*rt
)
2193 struct route_node
*rn
;
2198 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
2199 struct ospf_route
*or;
2205 if (or->type
== OSPF_DESTINATION_NETWORK
)
2206 ospf_zebra_add(ospf
, (struct prefix_ipv4
*)&rn
->p
, or);
2207 else if (or->type
== OSPF_DESTINATION_DISCARD
)
2208 ospf_zebra_add_discard(ospf
,
2209 (struct prefix_ipv4
*)&rn
->p
);
2213 static void ospf_reinstall_routes(struct ospf
*ospf
)
2215 ospf_table_reinstall_routes(ospf
, ospf
->new_table
);
2216 ospf_table_reinstall_routes(ospf
, ospf
->new_external_route
);
2219 DEFPY (ospf_send_extra_data
,
2220 ospf_send_extra_data_cmd
,
2221 "[no] ospf send-extra-data zebra",
2224 "Extra data to Zebra for display/use\n"
2227 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2229 if (no
&& CHECK_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
)) {
2230 UNSET_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
);
2231 ospf_reinstall_routes(ospf
);
2232 } else if (!CHECK_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
)) {
2233 SET_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
);
2234 ospf_reinstall_routes(ospf
);
2240 static int ospf_timers_spf_set(struct vty
*vty
, unsigned int delay
,
2241 unsigned int hold
, unsigned int max
)
2243 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2245 ospf
->spf_delay
= delay
;
2246 ospf
->spf_holdtime
= hold
;
2247 ospf
->spf_max_holdtime
= max
;
2252 DEFUN (ospf_timers_min_ls_interval
,
2253 ospf_timers_min_ls_interval_cmd
,
2254 "timers throttle lsa all (0-5000)",
2255 "Adjust routing timers\n"
2256 "Throttling adaptive timer\n"
2257 "LSA delay between transmissions\n"
2259 "Delay (msec) between sending LSAs\n")
2261 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2263 unsigned int interval
;
2266 vty_out(vty
, "Insufficient arguments\n");
2267 return CMD_WARNING_CONFIG_FAILED
;
2270 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2272 ospf
->min_ls_interval
= interval
;
2277 DEFUN (no_ospf_timers_min_ls_interval
,
2278 no_ospf_timers_min_ls_interval_cmd
,
2279 "no timers throttle lsa all [(0-5000)]",
2281 "Adjust routing timers\n"
2282 "Throttling adaptive timer\n"
2283 "LSA delay between transmissions\n"
2285 "Delay (msec) between sending LSAs\n")
2287 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2288 ospf
->min_ls_interval
= OSPF_MIN_LS_INTERVAL
;
2293 DEFUN (ospf_timers_throttle_spf
,
2294 ospf_timers_throttle_spf_cmd
,
2295 "timers throttle spf (0-600000) (0-600000) (0-600000)",
2296 "Adjust routing timers\n"
2297 "Throttling adaptive timer\n"
2299 "Delay (msec) from first change received till SPF calculation\n"
2300 "Initial hold time (msec) between consecutive SPF calculations\n"
2301 "Maximum hold time (msec)\n")
2304 int idx_number_2
= 4;
2305 int idx_number_3
= 5;
2306 unsigned int delay
, hold
, max
;
2309 vty_out(vty
, "Insufficient arguments\n");
2310 return CMD_WARNING_CONFIG_FAILED
;
2313 delay
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2314 hold
= strtoul(argv
[idx_number_2
]->arg
, NULL
, 10);
2315 max
= strtoul(argv
[idx_number_3
]->arg
, NULL
, 10);
2317 return ospf_timers_spf_set(vty
, delay
, hold
, max
);
2320 DEFUN (no_ospf_timers_throttle_spf
,
2321 no_ospf_timers_throttle_spf_cmd
,
2322 "no timers throttle spf [(0-600000)(0-600000)(0-600000)]",
2324 "Adjust routing timers\n"
2325 "Throttling adaptive timer\n"
2327 "Delay (msec) from first change received till SPF calculation\n"
2328 "Initial hold time (msec) between consecutive SPF calculations\n"
2329 "Maximum hold time (msec)\n")
2331 return ospf_timers_spf_set(vty
, OSPF_SPF_DELAY_DEFAULT
,
2332 OSPF_SPF_HOLDTIME_DEFAULT
,
2333 OSPF_SPF_MAX_HOLDTIME_DEFAULT
);
2337 DEFUN (ospf_timers_lsa_min_arrival
,
2338 ospf_timers_lsa_min_arrival_cmd
,
2339 "timers lsa min-arrival (0-600000)",
2340 "Adjust routing timers\n"
2342 "Minimum delay in receiving new version of a LSA\n"
2343 "Delay in milliseconds\n")
2345 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2346 ospf
->min_ls_arrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2350 DEFUN (no_ospf_timers_lsa_min_arrival
,
2351 no_ospf_timers_lsa_min_arrival_cmd
,
2352 "no timers lsa min-arrival [(0-600000)]",
2354 "Adjust routing timers\n"
2356 "Minimum delay in receiving new version of a LSA\n"
2357 "Delay in milliseconds\n")
2359 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2360 unsigned int minarrival
;
2363 minarrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2365 if (ospf
->min_ls_arrival
!= minarrival
2366 || minarrival
== OSPF_MIN_LS_ARRIVAL
)
2370 ospf
->min_ls_arrival
= OSPF_MIN_LS_ARRIVAL
;
2375 DEFUN (ospf_neighbor
,
2377 "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]",
2379 "Neighbor IP address\n"
2380 "Neighbor Priority\n"
2382 "Dead Neighbor Polling interval\n"
2385 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2389 struct in_addr nbr_addr
;
2390 unsigned int priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2391 unsigned int interval
= OSPF_POLL_INTERVAL_DEFAULT
;
2393 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2394 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2395 return CMD_WARNING_CONFIG_FAILED
;
2399 priority
= strtoul(argv
[idx_pri
]->arg
, NULL
, 10);
2402 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2404 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2407 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2410 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2415 DEFUN (ospf_neighbor_poll_interval
,
2416 ospf_neighbor_poll_interval_cmd
,
2417 "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2419 "Neighbor IP address\n"
2420 "Dead Neighbor Polling interval\n"
2422 "OSPF priority of non-broadcast neighbor\n"
2425 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2429 struct in_addr nbr_addr
;
2430 unsigned int priority
;
2431 unsigned int interval
;
2433 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2434 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2435 return CMD_WARNING_CONFIG_FAILED
;
2438 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2440 priority
= argc
> 4 ? strtoul(argv
[idx_pri
]->arg
, NULL
, 10)
2441 : OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2443 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2444 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2447 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2452 DEFUN (no_ospf_neighbor
,
2453 no_ospf_neighbor_cmd
,
2454 "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]",
2457 "Neighbor IP address\n"
2458 "Neighbor Priority\n"
2460 "Dead Neighbor Polling interval\n"
2463 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2465 struct in_addr nbr_addr
;
2467 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2468 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2469 return CMD_WARNING_CONFIG_FAILED
;
2472 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2477 DEFUN (no_ospf_neighbor_poll
,
2478 no_ospf_neighbor_poll_cmd
,
2479 "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2482 "Neighbor IP address\n"
2483 "Dead Neighbor Polling interval\n"
2485 "Neighbor Priority\n"
2488 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2490 struct in_addr nbr_addr
;
2492 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2493 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2494 return CMD_WARNING_CONFIG_FAILED
;
2497 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2502 DEFUN (ospf_refresh_timer
,
2503 ospf_refresh_timer_cmd
,
2504 "refresh timer (10-1800)",
2505 "Adjust refresh parameters\n"
2506 "Set refresh timer\n"
2507 "Timer value in seconds\n")
2509 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2511 unsigned int interval
;
2513 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2514 interval
= (interval
/ OSPF_LSA_REFRESHER_GRANULARITY
)
2515 * OSPF_LSA_REFRESHER_GRANULARITY
;
2517 ospf_timers_refresh_set(ospf
, interval
);
2522 DEFUN (no_ospf_refresh_timer
,
2523 no_ospf_refresh_timer_val_cmd
,
2524 "no refresh timer [(10-1800)]",
2526 "Adjust refresh parameters\n"
2527 "Unset refresh timer\n"
2528 "Timer value in seconds\n")
2530 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2532 unsigned int interval
;
2535 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2537 if (ospf
->lsa_refresh_interval
!= interval
2538 || interval
== OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
2542 ospf_timers_refresh_unset(ospf
);
2548 DEFUN (ospf_auto_cost_reference_bandwidth
,
2549 ospf_auto_cost_reference_bandwidth_cmd
,
2550 "auto-cost reference-bandwidth (1-4294967)",
2551 "Calculate OSPF interface cost according to bandwidth\n"
2552 "Use reference bandwidth method to assign OSPF cost\n"
2553 "The reference bandwidth in terms of Mbits per second\n")
2555 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2556 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2559 struct interface
*ifp
;
2561 refbw
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2562 if (refbw
< 1 || refbw
> 4294967) {
2563 vty_out(vty
, "reference-bandwidth value is invalid\n");
2564 return CMD_WARNING_CONFIG_FAILED
;
2567 /* If reference bandwidth is changed. */
2568 if ((refbw
) == ospf
->ref_bandwidth
)
2571 ospf
->ref_bandwidth
= refbw
;
2572 FOR_ALL_INTERFACES (vrf
, ifp
)
2573 ospf_if_recalculate_output_cost(ifp
);
2578 DEFUN (no_ospf_auto_cost_reference_bandwidth
,
2579 no_ospf_auto_cost_reference_bandwidth_cmd
,
2580 "no auto-cost reference-bandwidth [(1-4294967)]",
2582 "Calculate OSPF interface cost according to bandwidth\n"
2583 "Use reference bandwidth method to assign OSPF cost\n"
2584 "The reference bandwidth in terms of Mbits per second\n")
2586 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2587 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2588 struct interface
*ifp
;
2590 if (ospf
->ref_bandwidth
== OSPF_DEFAULT_REF_BANDWIDTH
)
2593 ospf
->ref_bandwidth
= OSPF_DEFAULT_REF_BANDWIDTH
;
2594 vty_out(vty
, "%% OSPF: Reference bandwidth is changed.\n");
2596 " Please ensure reference bandwidth is consistent across all routers\n");
2598 FOR_ALL_INTERFACES (vrf
, ifp
)
2599 ospf_if_recalculate_output_cost(ifp
);
2604 DEFUN (ospf_write_multiplier
,
2605 ospf_write_multiplier_cmd
,
2606 "ospf write-multiplier (1-100)",
2607 "OSPF specific commands\n"
2608 "Write multiplier\n"
2609 "Maximum number of interface serviced per write\n")
2611 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2613 uint32_t write_oi_count
;
2620 write_oi_count
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2621 if (write_oi_count
< 1 || write_oi_count
> 100) {
2622 vty_out(vty
, "write-multiplier value is invalid\n");
2623 return CMD_WARNING_CONFIG_FAILED
;
2626 ospf
->write_oi_count
= write_oi_count
;
2630 ALIAS(ospf_write_multiplier
, write_multiplier_cmd
, "write-multiplier (1-100)",
2631 "Write multiplier\n"
2632 "Maximum number of interface serviced per write\n")
2634 DEFUN (no_ospf_write_multiplier
,
2635 no_ospf_write_multiplier_cmd
,
2636 "no ospf write-multiplier (1-100)",
2638 "OSPF specific commands\n"
2639 "Write multiplier\n"
2640 "Maximum number of interface serviced per write\n")
2642 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2644 ospf
->write_oi_count
= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
;
2648 ALIAS(no_ospf_write_multiplier
, no_write_multiplier_cmd
,
2649 "no write-multiplier (1-100)", NO_STR
2650 "Write multiplier\n"
2651 "Maximum number of interface serviced per write\n")
2653 DEFUN(ospf_ti_lfa
, ospf_ti_lfa_cmd
, "fast-reroute ti-lfa [node-protection]",
2654 "Fast Reroute for MPLS and IP resilience\n"
2655 "Topology Independent LFA (Loop-Free Alternate)\n"
2656 "TI-LFA node protection (default is link protection)\n")
2658 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2660 ospf
->ti_lfa_enabled
= true;
2663 ospf
->ti_lfa_protection_type
= OSPF_TI_LFA_NODE_PROTECTION
;
2665 ospf
->ti_lfa_protection_type
= OSPF_TI_LFA_LINK_PROTECTION
;
2667 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2672 DEFUN(no_ospf_ti_lfa
, no_ospf_ti_lfa_cmd
,
2673 "no fast-reroute ti-lfa [node-protection]",
2675 "Fast Reroute for MPLS and IP resilience\n"
2676 "Topology Independent LFA (Loop-Free Alternate)\n"
2677 "TI-LFA node protection (default is link protection)\n")
2679 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2681 ospf
->ti_lfa_enabled
= false;
2683 ospf
->ti_lfa_protection_type
= OSPF_TI_LFA_UNDEFINED_PROTECTION
;
2685 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2690 static void ospf_maxpath_set(struct vty
*vty
, struct ospf
*ospf
, uint16_t paths
)
2692 if (ospf
->max_multipath
== paths
)
2695 ospf
->max_multipath
= paths
;
2697 /* Send deletion notification to zebra to delete all
2698 * ospf specific routes and reinitiat SPF to reflect
2699 * the new max multipath.
2701 ospf_restart_spf(ospf
);
2704 /* Ospf Maximum multiple paths config support */
2705 DEFUN (ospf_max_multipath
,
2706 ospf_max_multipath_cmd
,
2707 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM
),
2708 "Max no of multiple paths for ECMP support\n"
2709 "Number of paths\n")
2711 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2715 maxpaths
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2717 ospf_maxpath_set(vty
, ospf
, maxpaths
);
2721 DEFUN (no_ospf_max_multipath
,
2722 no_ospf_max_multipath_cmd
,
2725 "Max no of multiple paths for ECMP support\n")
2727 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2728 uint16_t maxpaths
= MULTIPATH_NUM
;
2730 ospf_maxpath_set(vty
, ospf
, maxpaths
);
2734 static const char *const ospf_abr_type_descr_str
[] = {
2735 "Unknown", "Standard (RFC2328)", "Alternative IBM",
2736 "Alternative Cisco", "Alternative Shortcut"
2739 static const char *const ospf_shortcut_mode_descr_str
[] = {
2740 "Default", "Enabled", "Disabled"
2743 static void show_ip_ospf_area(struct vty
*vty
, struct ospf_area
*area
,
2744 json_object
*json_areas
, bool use_json
)
2746 json_object
*json_area
= NULL
;
2747 char buf
[PREFIX_STRLEN
];
2750 json_area
= json_object_new_object();
2754 vty_out(vty
, " Area ID: %pI4", &area
->area_id
);
2756 /* Show Area type/mode. */
2757 if (OSPF_IS_AREA_BACKBONE(area
)) {
2759 json_object_boolean_true_add(json_area
, "backbone");
2761 vty_out(vty
, " (Backbone)\n");
2764 if (area
->external_routing
== OSPF_AREA_STUB
) {
2765 if (area
->no_summary
)
2766 json_object_boolean_true_add(
2767 json_area
, "stubNoSummary");
2768 if (area
->shortcut_configured
)
2769 json_object_boolean_true_add(
2770 json_area
, "stubShortcut");
2771 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
2772 if (area
->no_summary
)
2773 json_object_boolean_true_add(
2774 json_area
, "nssaNoSummary");
2775 if (area
->shortcut_configured
)
2776 json_object_boolean_true_add(
2777 json_area
, "nssaShortcut");
2780 json_object_string_add(
2781 json_area
, "shortcuttingMode",
2782 ospf_shortcut_mode_descr_str
2783 [area
->shortcut_configured
]);
2784 if (area
->shortcut_capability
)
2785 json_object_boolean_true_add(json_area
,
2788 if (area
->external_routing
== OSPF_AREA_STUB
)
2789 vty_out(vty
, " (Stub%s%s)",
2790 area
->no_summary
? ", no summary" : "",
2791 area
->shortcut_configured
? "; " : "");
2792 else if (area
->external_routing
== OSPF_AREA_NSSA
)
2793 vty_out(vty
, " (NSSA%s%s)",
2794 area
->no_summary
? ", no summary" : "",
2795 area
->shortcut_configured
? "; " : "");
2798 vty_out(vty
, " Shortcutting mode: %s",
2799 ospf_shortcut_mode_descr_str
2800 [area
->shortcut_configured
]);
2801 vty_out(vty
, ", S-bit consensus: %s\n",
2802 area
->shortcut_capability
? "ok" : "no");
2806 /* Show number of interfaces */
2808 json_object_int_add(json_area
, "areaIfTotalCounter",
2809 listcount(area
->oiflist
));
2810 json_object_int_add(json_area
, "areaIfActiveCounter",
2814 " Number of interfaces in this area: Total: %d, Active: %d\n",
2815 listcount(area
->oiflist
), area
->act_ints
);
2817 if (area
->external_routing
== OSPF_AREA_NSSA
) {
2819 json_object_boolean_true_add(json_area
, "nssa");
2820 if (!IS_OSPF_ABR(area
->ospf
))
2821 json_object_boolean_false_add(json_area
, "abr");
2822 else if (area
->NSSATranslatorState
) {
2823 json_object_boolean_true_add(json_area
, "abr");
2824 if (area
->NSSATranslatorRole
2825 == OSPF_NSSA_ROLE_CANDIDATE
)
2826 json_object_boolean_true_add(
2828 "nssaTranslatorElected");
2829 else if (area
->NSSATranslatorRole
2830 == OSPF_NSSA_ROLE_ALWAYS
)
2831 json_object_boolean_true_add(
2833 "nssaTranslatorAlways");
2835 json_object_boolean_true_add(
2837 "nssaTranslatorNever");
2839 json_object_boolean_true_add(json_area
, "abr");
2840 if (area
->NSSATranslatorRole
2841 == OSPF_NSSA_ROLE_CANDIDATE
)
2842 json_object_boolean_false_add(
2844 "nssaTranslatorElected");
2846 json_object_boolean_true_add(
2848 "nssaTranslatorNever");
2852 " It is an NSSA configuration.\n Elected NSSA/ABR performs type-7/type-5 LSA translation.\n");
2853 if (!IS_OSPF_ABR(area
->ospf
))
2855 " It is not ABR, therefore not Translator.\n");
2856 else if (area
->NSSATranslatorState
) {
2857 vty_out(vty
, " We are an ABR and ");
2858 if (area
->NSSATranslatorRole
2859 == OSPF_NSSA_ROLE_CANDIDATE
)
2861 "the NSSA Elected Translator.\n");
2862 else if (area
->NSSATranslatorRole
2863 == OSPF_NSSA_ROLE_ALWAYS
)
2865 "always an NSSA Translator.\n");
2868 "never an NSSA Translator.\n");
2870 vty_out(vty
, " We are an ABR, but ");
2871 if (area
->NSSATranslatorRole
2872 == OSPF_NSSA_ROLE_CANDIDATE
)
2874 "not the NSSA Elected Translator.\n");
2877 "never an NSSA Translator.\n");
2882 /* Stub-router state for this area */
2883 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
)) {
2884 char timebuf
[OSPF_TIME_DUMP_SIZE
];
2887 json_object_boolean_true_add(
2888 json_area
, "originStubMaxDistRouterLsa");
2889 if (CHECK_FLAG(area
->stub_router_state
,
2890 OSPF_AREA_ADMIN_STUB_ROUTED
))
2891 json_object_boolean_true_add(
2892 json_area
, "indefiniteActiveAdmin");
2893 if (area
->t_stub_router
) {
2897 &area
->t_stub_router
->u
.sands
,
2900 json_object_int_add(
2902 "activeStartupRemainderMsecs",
2907 " Originating stub / maximum-distance Router-LSA\n");
2908 if (CHECK_FLAG(area
->stub_router_state
,
2909 OSPF_AREA_ADMIN_STUB_ROUTED
))
2911 " Administratively activated (indefinitely)\n");
2912 if (area
->t_stub_router
)
2914 " Active from startup, %s remaining\n",
2915 ospf_timer_dump(area
->t_stub_router
,
2922 /* Show number of fully adjacent neighbors. */
2923 json_object_int_add(json_area
, "nbrFullAdjacentCounter",
2926 /* Show authentication type. */
2927 if (area
->auth_type
== OSPF_AUTH_NULL
)
2928 json_object_string_add(json_area
, "authentication",
2929 "authenticationNone");
2930 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2931 json_object_string_add(json_area
, "authentication",
2932 "authenticationSimplePassword");
2933 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2934 json_object_string_add(json_area
, "authentication",
2935 "authenticationMessageDigest");
2937 if (!OSPF_IS_AREA_BACKBONE(area
))
2938 json_object_int_add(json_area
,
2939 "virtualAdjacenciesPassingCounter",
2942 /* Show SPF calculation times. */
2943 json_object_int_add(json_area
, "spfExecutedCounter",
2944 area
->spf_calculation
);
2945 json_object_int_add(json_area
, "lsaNumber", area
->lsdb
->total
);
2946 json_object_int_add(
2947 json_area
, "lsaRouterNumber",
2948 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
));
2949 json_object_int_add(
2950 json_area
, "lsaRouterChecksum",
2951 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
2952 json_object_int_add(
2953 json_area
, "lsaNetworkNumber",
2954 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
));
2955 json_object_int_add(
2956 json_area
, "lsaNetworkChecksum",
2957 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
2958 json_object_int_add(
2959 json_area
, "lsaSummaryNumber",
2960 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
));
2961 json_object_int_add(
2962 json_area
, "lsaSummaryChecksum",
2963 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
2964 json_object_int_add(
2965 json_area
, "lsaAsbrNumber",
2966 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2967 json_object_int_add(
2968 json_area
, "lsaAsbrChecksum",
2969 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2970 json_object_int_add(
2971 json_area
, "lsaNssaNumber",
2972 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2973 json_object_int_add(
2974 json_area
, "lsaNssaChecksum",
2975 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2977 /* Show number of fully adjacent neighbors. */
2979 " Number of fully adjacent neighbors in this area: %d\n",
2982 /* Show authentication type. */
2983 vty_out(vty
, " Area has ");
2984 if (area
->auth_type
== OSPF_AUTH_NULL
)
2985 vty_out(vty
, "no authentication\n");
2986 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2987 vty_out(vty
, "simple password authentication\n");
2988 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2989 vty_out(vty
, "message digest authentication\n");
2991 if (!OSPF_IS_AREA_BACKBONE(area
))
2993 " Number of full virtual adjacencies going through this area: %d\n",
2996 /* Show SPF calculation times. */
2997 vty_out(vty
, " SPF algorithm executed %d times\n",
2998 area
->spf_calculation
);
3000 /* Show number of LSA. */
3001 vty_out(vty
, " Number of LSA %ld\n", area
->lsdb
->total
);
3003 " Number of router LSA %ld. Checksum Sum 0x%08x\n",
3004 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
),
3005 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
3007 " Number of network LSA %ld. Checksum Sum 0x%08x\n",
3008 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
),
3009 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
3011 " Number of summary LSA %ld. Checksum Sum 0x%08x\n",
3012 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
),
3013 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
3015 " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n",
3016 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
),
3017 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
3018 vty_out(vty
, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n",
3019 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
),
3020 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
3024 json_object_int_add(
3025 json_area
, "lsaOpaqueLinkNumber",
3026 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
3027 json_object_int_add(
3028 json_area
, "lsaOpaqueLinkChecksum",
3029 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
3030 json_object_int_add(
3031 json_area
, "lsaOpaqueAreaNumber",
3032 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
3033 json_object_int_add(
3034 json_area
, "lsaOpaqueAreaChecksum",
3035 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
3038 " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n",
3039 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
),
3040 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
3042 " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n",
3043 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
),
3044 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
3047 if (area
->fr_info
.configured
) {
3049 json_object_string_add(json_area
, "areaFloodReduction",
3052 vty_out(vty
, " Flood Reduction is configured.\n");
3055 if (area
->fr_info
.enabled
) {
3057 json_object_boolean_true_add(
3058 json_area
, "areaFloodReductionEnabled");
3059 if (area
->fr_info
.router_lsas_recv_dc_bit
)
3060 json_object_boolean_true_add(
3061 json_area
, "lsasRecvDCbitSet");
3062 if (area
->fr_info
.area_ind_lsa_recvd
)
3063 json_object_string_add(json_area
,
3064 "areaIndicationLsaRecv",
3066 if (area
->fr_info
.indication_lsa_self
)
3067 json_object_string_addf(
3068 json_area
, "areaIndicationLsa", "%pI4",
3069 &area
->fr_info
.indication_lsa_self
->data
3072 vty_out(vty
, " Flood Reduction is enabled.\n");
3073 vty_out(vty
, " No of LSAs rcv'd with DC bit set %d\n",
3074 area
->fr_info
.router_lsas_recv_dc_bit
);
3075 if (area
->fr_info
.area_ind_lsa_recvd
)
3076 vty_out(vty
, " Ind LSA by other abr.\n");
3077 if (area
->fr_info
.indication_lsa_self
)
3078 vty_out(vty
, " Ind LSA generated %pI4\n",
3079 &area
->fr_info
.indication_lsa_self
->data
3085 json_object_object_add(json_areas
,
3086 inet_ntop(AF_INET
, &area
->area_id
,
3093 static int show_ip_ospf_common(struct vty
*vty
, struct ospf
*ospf
,
3094 json_object
*json
, uint8_t use_vrf
)
3096 struct listnode
*node
, *nnode
;
3097 struct ospf_area
*area
;
3098 struct timeval result
;
3099 char timebuf
[OSPF_TIME_DUMP_SIZE
];
3100 json_object
*json_vrf
= NULL
;
3101 json_object
*json_areas
= NULL
;
3105 json_vrf
= json_object_new_object();
3108 json_areas
= json_object_new_object();
3111 if (ospf
->instance
) {
3113 json_object_int_add(json
, "ospfInstance",
3116 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
3120 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3122 /* Show Router ID. */
3124 json_object_string_addf(json_vrf
, "routerId", "%pI4",
3127 vty_out(vty
, " OSPF Routing Process, Router ID: %pI4\n",
3131 /* Graceful shutdown */
3132 if (ospf
->t_deferred_shutdown
) {
3137 &ospf
->t_deferred_shutdown
->u
.sands
,
3140 json_object_int_add(json_vrf
, "deferredShutdownMsecs",
3144 " Deferred shutdown in progress, %s remaining\n",
3145 ospf_timer_dump(ospf
->t_deferred_shutdown
,
3146 timebuf
, sizeof(timebuf
)));
3150 /* Show capability. */
3152 json_object_boolean_true_add(json_vrf
, "tosRoutesOnly");
3153 json_object_boolean_true_add(json_vrf
, "rfc2328Conform");
3154 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
3155 json_object_boolean_true_add(json_vrf
,
3156 "rfc1583Compatibility");
3159 vty_out(vty
, " Supports only single TOS (TOS0) routes\n");
3160 vty_out(vty
, " This implementation conforms to RFC2328\n");
3161 vty_out(vty
, " RFC1583Compatibility flag is %s\n",
3162 CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)
3168 if (CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)) {
3169 json_object_boolean_true_add(json_vrf
, "opaqueCapable");
3172 vty_out(vty
, " OpaqueCapability flag is %s\n",
3173 CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)
3178 /* Show stub-router configuration */
3179 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
3180 || ospf
->stub_router_shutdown_time
3181 != OSPF_STUB_ROUTER_UNCONFIGURED
) {
3183 json_object_boolean_true_add(json_vrf
,
3184 "stubAdvertisement");
3185 if (ospf
->stub_router_startup_time
3186 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3187 json_object_int_add(
3188 json_vrf
, "postStartEnabledSecs",
3189 ospf
->stub_router_startup_time
);
3190 if (ospf
->stub_router_shutdown_time
3191 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3192 json_object_int_add(
3193 json_vrf
, "preShutdownEnabledSecs",
3194 ospf
->stub_router_shutdown_time
);
3197 " Stub router advertisement is configured\n");
3198 if (ospf
->stub_router_startup_time
3199 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3201 " Enabled for %us after start-up\n",
3202 ospf
->stub_router_startup_time
);
3203 if (ospf
->stub_router_shutdown_time
3204 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3206 " Enabled for %us prior to full shutdown\n",
3207 ospf
->stub_router_shutdown_time
);
3211 /* Show SPF timers. */
3213 json_object_int_add(json_vrf
, "spfScheduleDelayMsecs",
3215 json_object_int_add(json_vrf
, "holdtimeMinMsecs",
3216 ospf
->spf_holdtime
);
3217 json_object_int_add(json_vrf
, "holdtimeMaxMsecs",
3218 ospf
->spf_max_holdtime
);
3219 json_object_int_add(json_vrf
, "holdtimeMultplier",
3220 ospf
->spf_hold_multiplier
);
3223 " Initial SPF scheduling delay %d millisec(s)\n"
3224 " Minimum hold time between consecutive SPFs %d millisec(s)\n"
3225 " Maximum hold time between consecutive SPFs %d millisec(s)\n"
3226 " Hold time multiplier is currently %d\n",
3227 ospf
->spf_delay
, ospf
->spf_holdtime
,
3228 ospf
->spf_max_holdtime
, ospf
->spf_hold_multiplier
);
3232 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3233 long time_store
= 0;
3236 monotime_since(&ospf
->ts_spf
, NULL
) / 1000LL;
3237 json_object_int_add(json_vrf
, "spfLastExecutedMsecs",
3240 time_store
= (1000 * ospf
->ts_spf_duration
.tv_sec
)
3241 + (ospf
->ts_spf_duration
.tv_usec
/ 1000);
3242 json_object_int_add(json_vrf
, "spfLastDurationMsecs",
3245 json_object_boolean_true_add(json_vrf
, "spfHasNotRun");
3247 vty_out(vty
, " SPF algorithm ");
3248 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3249 monotime_since(&ospf
->ts_spf
, &result
);
3250 vty_out(vty
, "last executed %s ago\n",
3251 ospf_timeval_dump(&result
, timebuf
,
3253 vty_out(vty
, " Last SPF duration %s\n",
3254 ospf_timeval_dump(&ospf
->ts_spf_duration
,
3255 timebuf
, sizeof(timebuf
)));
3257 vty_out(vty
, "has not been run\n");
3261 if (ospf
->t_spf_calc
) {
3264 monotime_until(&ospf
->t_spf_calc
->u
.sands
, NULL
)
3266 json_object_int_add(json_vrf
, "spfTimerDueInMsecs",
3270 json_object_int_add(json_vrf
, "lsaMinIntervalMsecs",
3271 ospf
->min_ls_interval
);
3272 json_object_int_add(json_vrf
, "lsaMinArrivalMsecs",
3273 ospf
->min_ls_arrival
);
3274 /* Show write multiplier values */
3275 json_object_int_add(json_vrf
, "writeMultiplier",
3276 ospf
->write_oi_count
);
3277 /* Show refresh parameters. */
3278 json_object_int_add(json_vrf
, "refreshTimerMsecs",
3279 ospf
->lsa_refresh_interval
* 1000);
3281 /* show max multipath */
3282 json_object_int_add(json_vrf
, "maximumPaths",
3283 ospf
->max_multipath
);
3285 /* show administrative distance */
3286 json_object_int_add(json_vrf
, "preference",
3288 ? ospf
->distance_all
3289 : ZEBRA_OSPF_DISTANCE_DEFAULT
);
3291 vty_out(vty
, " SPF timer %s%s\n",
3292 (ospf
->t_spf_calc
? "due in " : "is "),
3293 ospf_timer_dump(ospf
->t_spf_calc
, timebuf
,
3296 vty_out(vty
, " LSA minimum interval %d msecs\n",
3297 ospf
->min_ls_interval
);
3298 vty_out(vty
, " LSA minimum arrival %d msecs\n",
3299 ospf
->min_ls_arrival
);
3301 /* Show write multiplier values */
3302 vty_out(vty
, " Write Multiplier set to %d \n",
3303 ospf
->write_oi_count
);
3305 /* Show refresh parameters. */
3306 vty_out(vty
, " Refresh timer %d secs\n",
3307 ospf
->lsa_refresh_interval
);
3309 /* show max multipath */
3310 vty_out(vty
, " Maximum multiple paths(ECMP) supported %d\n",
3311 ospf
->max_multipath
);
3313 /* show administrative distance */
3314 vty_out(vty
, " Administrative distance %u\n",
3315 ospf
->distance_all
? ospf
->distance_all
3316 : ZEBRA_OSPF_DISTANCE_DEFAULT
);
3319 if (ospf
->fr_configured
) {
3321 json_object_string_add(json_vrf
, "floodReduction",
3324 vty_out(vty
, " Flood Reduction is configured.\n");
3327 /* Show ABR/ASBR flags. */
3328 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ABR
)) {
3330 json_object_string_add(
3331 json_vrf
, "abrType",
3332 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3335 " This router is an ABR, ABR type is: %s\n",
3336 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3338 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ASBR
)) {
3340 json_object_string_add(
3341 json_vrf
, "asbrRouter",
3342 "injectingExternalRoutingInformation");
3345 " This router is an ASBR (injecting external routing information)\n");
3348 /* Show Number of AS-external-LSAs. */
3350 json_object_int_add(
3351 json_vrf
, "lsaExternalCounter",
3352 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3353 json_object_int_add(
3354 json_vrf
, "lsaExternalChecksum",
3355 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3358 " Number of external LSA %ld. Checksum Sum 0x%08x\n",
3359 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
),
3360 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3364 json_object_int_add(
3365 json_vrf
, "lsaAsopaqueCounter",
3366 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3367 json_object_int_add(
3368 json_vrf
, "lsaAsOpaqueChecksum",
3369 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3372 " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n",
3373 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
),
3374 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3377 /* Show number of areas attached. */
3379 json_object_int_add(json_vrf
, "attachedAreaCounter",
3380 listcount(ospf
->areas
));
3382 vty_out(vty
, " Number of areas attached to this router: %d\n",
3383 listcount(ospf
->areas
));
3385 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
3386 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
)) {
3388 json_object_boolean_true_add(
3389 json_vrf
, "adjacencyChangesLoggedAll");
3392 " All adjacency changes are logged\n");
3395 json_object_boolean_true_add(
3396 json_vrf
, "adjacencyChangesLogged");
3398 vty_out(vty
, " Adjacency changes are logged\n");
3402 /* show LDP-Sync status */
3403 ospf_ldp_sync_show_info(vty
, ospf
, json_vrf
, json
? 1 : 0);
3405 /* Socket buffer sizes */
3407 if (ospf
->recv_sock_bufsize
!= OSPF_DEFAULT_SOCK_BUFSIZE
)
3408 json_object_int_add(json_vrf
, "recvSockBufsize",
3409 ospf
->recv_sock_bufsize
);
3410 if (ospf
->send_sock_bufsize
!= OSPF_DEFAULT_SOCK_BUFSIZE
)
3411 json_object_int_add(json_vrf
, "sendSockBufsize",
3412 ospf
->send_sock_bufsize
);
3414 if (ospf
->recv_sock_bufsize
!= OSPF_DEFAULT_SOCK_BUFSIZE
)
3415 vty_out(vty
, " Receive socket bufsize: %u\n",
3416 ospf
->recv_sock_bufsize
);
3417 if (ospf
->send_sock_bufsize
!= OSPF_DEFAULT_SOCK_BUFSIZE
)
3418 vty_out(vty
, " Send socket bufsize: %u\n",
3419 ospf
->send_sock_bufsize
);
3422 /* Show each area status. */
3423 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
3424 show_ip_ospf_area(vty
, area
, json_areas
, json
? 1 : 0);
3428 json_object_object_add(json_vrf
, "areas", json_areas
);
3429 json_object_object_add(json
, ospf_get_name(ospf
),
3432 json_object_object_add(json
, "areas", json_areas
);
3440 DEFUN (show_ip_ospf
,
3442 "show ip ospf [vrf <NAME|all>] [json]",
3445 "OSPF information\n"
3451 bool uj
= use_json(argc
, argv
);
3452 struct listnode
*node
= NULL
;
3453 char *vrf_name
= NULL
;
3454 bool all_vrf
= false;
3455 int ret
= CMD_SUCCESS
;
3458 json_object
*json
= NULL
;
3459 uint8_t use_vrf
= 0;
3461 if (listcount(om
->ospf
) == 0)
3464 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
3467 json
= json_object_new_object();
3469 /* vrf input is provided could be all or specific vrf*/
3471 bool ospf_output
= false;
3476 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
3477 if (!ospf
->oi_running
)
3480 ret
= show_ip_ospf_common(vty
, ospf
, json
,
3484 vty_json(vty
, json
);
3485 else if (!ospf_output
)
3486 vty_out(vty
, "%% OSPF is not enabled\n");
3489 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
3490 if ((ospf
== NULL
) || !ospf
->oi_running
) {
3492 vty_json(vty
, json
);
3495 "%% OSPF is not enabled in vrf %s\n",
3501 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
3502 /* Display default ospf (instance 0) info */
3503 if (ospf
== NULL
|| !ospf
->oi_running
) {
3505 vty_json(vty
, json
);
3508 "%% OSPF is not enabled in vrf default\n");
3515 show_ip_ospf_common(vty
, ospf
, json
, use_vrf
);
3517 vty_out(vty
, "%s\n",
3518 json_object_to_json_string_ext(
3519 json
, JSON_C_TO_STRING_PRETTY
));
3523 json_object_free(json
);
3528 DEFUN (show_ip_ospf_instance
,
3529 show_ip_ospf_instance_cmd
,
3530 "show ip ospf (1-65535) [json]",
3533 "OSPF information\n"
3539 unsigned short instance
= 0;
3540 bool uj
= use_json(argc
, argv
);
3541 int ret
= CMD_SUCCESS
;
3542 json_object
*json
= NULL
;
3544 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
3545 if (instance
!= ospf_instance
)
3546 return CMD_NOT_MY_INSTANCE
;
3548 ospf
= ospf_lookup_instance(instance
);
3549 if (!ospf
|| !ospf
->oi_running
)
3553 json
= json_object_new_object();
3555 ret
= show_ip_ospf_common(vty
, ospf
, json
, 0);
3558 vty_json(vty
, json
);
3563 static void ospf_interface_auth_show(struct vty
*vty
, struct ospf_interface
*oi
,
3564 json_object
*json
, bool use_json
)
3568 auth_type
= OSPF_IF_PARAM(oi
, auth_type
);
3570 switch (auth_type
) {
3571 case OSPF_AUTH_NULL
:
3573 json_object_string_add(json
, "authentication",
3574 "authenticationNone");
3576 vty_out(vty
, " Authentication NULL is enabled\n");
3578 case OSPF_AUTH_SIMPLE
: {
3580 json_object_string_add(json
, "authentication",
3581 "authenticationSimplePassword");
3584 " Simple password authentication enabled\n");
3587 case OSPF_AUTH_CRYPTOGRAPHIC
: {
3588 struct crypt_key
*ckey
;
3590 if (list_isempty(OSPF_IF_PARAM(oi
, auth_crypt
)))
3593 ckey
= listgetdata(listtail(OSPF_IF_PARAM(oi
, auth_crypt
)));
3596 json_object_string_add(json
, "authentication",
3597 "authenticationMessageDigest");
3600 " Cryptographic authentication enabled\n");
3601 vty_out(vty
, " Algorithm:MD5\n");
3611 static void show_ip_ospf_interface_sub(struct vty
*vty
, struct ospf
*ospf
,
3612 struct interface
*ifp
,
3613 json_object
*json_interface_sub
,
3617 struct ospf_neighbor
*nbr
;
3618 struct route_node
*rn
;
3619 uint32_t bandwidth
= ifp
->bandwidth
? ifp
->bandwidth
: ifp
->speed
;
3621 /* Is interface up? */
3623 is_up
= if_is_operative(ifp
);
3625 json_object_boolean_true_add(json_interface_sub
,
3628 json_object_boolean_false_add(json_interface_sub
,
3631 json_object_int_add(json_interface_sub
, "ifIndex",
3633 json_object_int_add(json_interface_sub
, "mtuBytes", ifp
->mtu
);
3634 json_object_int_add(json_interface_sub
, "bandwidthMbit",
3636 json_object_string_add(json_interface_sub
, "ifFlags",
3637 if_flag_dump(ifp
->flags
));
3639 vty_out(vty
, "%s is %s\n", ifp
->name
,
3640 ((is_up
= if_is_operative(ifp
)) ? "up" : "down"));
3641 vty_out(vty
, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n",
3642 ifp
->ifindex
, ifp
->mtu
, bandwidth
,
3643 if_flag_dump(ifp
->flags
));
3646 /* Is interface OSPF enabled? */
3648 if (ospf_oi_count(ifp
) == 0) {
3649 json_object_boolean_false_add(json_interface_sub
,
3652 } else if (!is_up
) {
3653 json_object_boolean_false_add(json_interface_sub
,
3657 json_object_boolean_true_add(json_interface_sub
,
3660 if (ospf_oi_count(ifp
) == 0) {
3661 vty_out(vty
, " OSPF not enabled on this interface\n");
3663 } else if (!is_up
) {
3665 " OSPF is enabled, but not running on this interface\n");
3670 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
3671 struct ospf_interface
*oi
= rn
->info
;
3676 if (CHECK_FLAG(oi
->connected
->flags
, ZEBRA_IFA_UNNUMBERED
)) {
3678 json_object_boolean_true_add(json_interface_sub
,
3681 vty_out(vty
, " This interface is UNNUMBERED,");
3683 struct in_addr dest
;
3686 /* Show OSPF interface information. */
3688 json_object_string_addf(
3689 json_interface_sub
, "ipAddress", "%pI4",
3690 &oi
->address
->u
.prefix4
);
3691 json_object_int_add(json_interface_sub
,
3692 "ipAddressPrefixlen",
3693 oi
->address
->prefixlen
);
3695 vty_out(vty
, " Internet Address %pFX,",
3698 /* For Vlinks, showing the peer address is
3699 * probably more informative than the local
3700 * interface that is being used */
3701 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
) {
3703 dest
= oi
->vl_data
->peer_addr
;
3704 } else if (CONNECTED_PEER(oi
->connected
)
3705 && oi
->connected
->destination
) {
3707 dest
= oi
->connected
->destination
->u
.prefix4
;
3710 dest
.s_addr
= ipv4_broadcast_addr(
3711 oi
->connected
->address
->u
.prefix4
.s_addr
,
3712 oi
->connected
->address
->prefixlen
);
3716 json_object_string_add(
3718 "ospfIfType", dstr
);
3719 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3720 json_object_string_addf(
3721 json_interface_sub
, "vlinkPeer",
3724 json_object_string_addf(
3726 "localIfUsed", "%pI4", &dest
);
3728 vty_out(vty
, " %s %pI4,", dstr
,
3732 json_object_string_add(json_interface_sub
, "area",
3733 ospf_area_desc_string(oi
->area
));
3734 if (OSPF_IF_PARAM(oi
, mtu_ignore
))
3735 json_object_boolean_true_add(
3737 "mtuMismatchDetect");
3738 json_object_string_addf(json_interface_sub
, "routerId",
3739 "%pI4", &ospf
->router_id
);
3740 json_object_string_add(json_interface_sub
,
3742 ospf_network_type_str
[oi
->type
]);
3743 json_object_int_add(json_interface_sub
, "cost",
3745 json_object_int_add(
3746 json_interface_sub
, "transmitDelaySecs",
3747 OSPF_IF_PARAM(oi
, transmit_delay
));
3748 json_object_string_add(json_interface_sub
, "state",
3749 lookup_msg(ospf_ism_state_msg
,
3751 json_object_int_add(json_interface_sub
, "priority",
3754 vty_out(vty
, " Area %s\n",
3755 ospf_area_desc_string(oi
->area
));
3757 vty_out(vty
, " MTU mismatch detection: %s\n",
3758 OSPF_IF_PARAM(oi
, mtu_ignore
) ? "disabled"
3762 " Router ID %pI4, Network Type %s, Cost: %d\n",
3764 ospf_network_type_str
[oi
->type
],
3768 " Transmit Delay is %d sec, State %s, Priority %d\n",
3769 OSPF_IF_PARAM(oi
, transmit_delay
),
3770 lookup_msg(ospf_ism_state_msg
, oi
->state
, NULL
),
3774 /* Show DR information. */
3775 if (DR(oi
).s_addr
== INADDR_ANY
) {
3778 " No backup designated router on this network\n");
3780 nbr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &DR(oi
));
3783 json_object_string_addf(
3784 json_interface_sub
, "drId",
3785 "%pI4", &nbr
->router_id
);
3786 json_object_string_addf(
3787 json_interface_sub
, "drAddress",
3789 &nbr
->address
.u
.prefix4
);
3792 " Designated Router (ID) %pI4",
3795 " Interface Address %pFX\n",
3801 nbr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &BDR(oi
));
3805 " No backup designated router on this network\n");
3808 json_object_string_addf(
3809 json_interface_sub
, "bdrId",
3810 "%pI4", &nbr
->router_id
);
3811 json_object_string_addf(
3813 "bdrAddress", "%pI4",
3814 &nbr
->address
.u
.prefix4
);
3817 " Backup Designated Router (ID) %pI4,",
3819 vty_out(vty
, " Interface Address %pI4\n",
3820 &nbr
->address
.u
.prefix4
);
3825 /* Next network-LSA sequence number we'll use, if we're elected
3828 && ntohl(oi
->params
->network_lsa_seqnum
)
3829 != OSPF_INITIAL_SEQUENCE_NUMBER
) {
3831 json_object_int_add(
3833 "networkLsaSequence",
3834 ntohl(oi
->params
->network_lsa_seqnum
));
3837 " Saved Network-LSA sequence number 0x%x\n",
3838 ntohl(oi
->params
->network_lsa_seqnum
));
3842 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3843 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3844 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3845 json_object_boolean_true_add(
3847 "mcastMemberOspfAllRouters");
3848 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3849 json_object_boolean_true_add(
3851 "mcastMemberOspfDesignatedRouters");
3854 vty_out(vty
, " Multicast group memberships:");
3855 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3856 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3857 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3858 vty_out(vty
, " OSPFAllRouters");
3859 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3860 vty_out(vty
, " OSPFDesignatedRouters");
3862 vty_out(vty
, " <None>");
3867 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3868 json_object_int_add(
3869 json_interface_sub
, "timerMsecs",
3870 OSPF_IF_PARAM(oi
, v_hello
) * 1000);
3872 json_object_int_add(
3873 json_interface_sub
, "timerMsecs",
3874 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3875 json_object_int_add(json_interface_sub
,
3877 OSPF_IF_PARAM(oi
, v_wait
));
3878 json_object_int_add(json_interface_sub
,
3880 OSPF_IF_PARAM(oi
, v_wait
));
3881 json_object_int_add(
3882 json_interface_sub
, "timerRetransmitSecs",
3883 OSPF_IF_PARAM(oi
, retransmit_interval
));
3885 vty_out(vty
, " Timer intervals configured,");
3886 vty_out(vty
, " Hello ");
3887 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3888 vty_out(vty
, "%ds,",
3889 OSPF_IF_PARAM(oi
, v_hello
));
3891 vty_out(vty
, "%dms,",
3892 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3893 vty_out(vty
, " Dead %ds, Wait %ds, Retransmit %d\n",
3894 OSPF_IF_PARAM(oi
, v_wait
),
3895 OSPF_IF_PARAM(oi
, v_wait
),
3896 OSPF_IF_PARAM(oi
, retransmit_interval
));
3899 if (OSPF_IF_PASSIVE_STATUS(oi
) == OSPF_IF_ACTIVE
) {
3900 char timebuf
[OSPF_TIME_DUMP_SIZE
];
3902 long time_store
= 0;
3906 &oi
->t_hello
->u
.sands
,
3909 json_object_int_add(json_interface_sub
,
3910 "timerHelloInMsecs",
3913 vty_out(vty
, " Hello due in %s\n",
3914 ospf_timer_dump(oi
->t_hello
, timebuf
,
3916 } else /* passive-interface is set */
3919 json_object_boolean_true_add(
3921 "timerPassiveIface");
3924 " No Hellos (Passive interface)\n");
3928 json_object_int_add(json_interface_sub
, "nbrCount",
3929 ospf_nbr_count(oi
, 0));
3930 json_object_int_add(json_interface_sub
,
3932 ospf_nbr_count(oi
, NSM_Full
));
3935 " Neighbor Count is %d, Adjacent neighbor count is %d\n",
3936 ospf_nbr_count(oi
, 0),
3937 ospf_nbr_count(oi
, NSM_Full
));
3939 ospf_interface_bfd_show(vty
, ifp
, json_interface_sub
);
3941 /* OSPF Authentication information */
3942 ospf_interface_auth_show(vty
, oi
, json_interface_sub
, use_json
);
3946 static int show_ip_ospf_interface_common(struct vty
*vty
, struct ospf
*ospf
,
3947 char *intf_name
, uint8_t use_vrf
,
3948 json_object
*json
, bool use_json
)
3950 struct interface
*ifp
;
3951 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
3952 json_object
*json_vrf
= NULL
;
3953 json_object
*json_interface_sub
= NULL
, *json_interface
= NULL
;
3957 json_vrf
= json_object_new_object();
3960 json_interface
= json_object_new_object();
3963 if (ospf
->instance
) {
3965 json_object_int_add(json
, "ospfInstance",
3968 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
3971 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3973 if (intf_name
== NULL
) {
3974 /* Show All Interfaces.*/
3975 FOR_ALL_INTERFACES (vrf
, ifp
) {
3976 if (ospf_oi_count(ifp
)) {
3978 json_interface_sub
=
3979 json_object_new_object();
3981 show_ip_ospf_interface_sub(vty
, ospf
, ifp
,
3986 json_object_object_add(
3987 json_interface
, ifp
->name
,
3988 json_interface_sub
);
3993 json_object_object_add(json_vrf
, "interfaces",
3996 /* Interface name is specified. */
3997 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
4000 json_object_boolean_true_add(json_vrf
,
4003 vty_out(vty
, "No such interface name\n");
4006 json_interface_sub
= json_object_new_object();
4007 json_interface
= json_object_new_object();
4010 show_ip_ospf_interface_sub(
4011 vty
, ospf
, ifp
, json_interface_sub
, use_json
);
4014 json_object_object_add(json_interface
,
4016 json_interface_sub
);
4017 json_object_object_add(json_vrf
, "interfaces",
4025 json_object_object_add(json
, ospf_get_name(ospf
),
4034 static void show_ip_ospf_interface_traffic_sub(struct vty
*vty
,
4035 struct ospf_interface
*oi
,
4036 json_object
*json_interface_sub
,
4040 json_object_int_add(json_interface_sub
, "ifIndex",
4042 json_object_int_add(json_interface_sub
, "helloIn",
4044 json_object_int_add(json_interface_sub
, "helloOut",
4046 json_object_int_add(json_interface_sub
, "dbDescIn",
4048 json_object_int_add(json_interface_sub
, "dbDescOut",
4050 json_object_int_add(json_interface_sub
, "lsReqIn",
4052 json_object_int_add(json_interface_sub
, "lsReqOut",
4054 json_object_int_add(json_interface_sub
, "lsUpdIn",
4056 json_object_int_add(json_interface_sub
, "lsUpdOut",
4058 json_object_int_add(json_interface_sub
, "lsAckIn",
4060 json_object_int_add(json_interface_sub
, "lsAckOut",
4062 json_object_int_add(json_interface_sub
, "packetsQueued",
4063 listcount(oi
->obuf
));
4066 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u %12lu\n",
4067 oi
->ifp
->name
, oi
->hello_in
, oi
->hello_out
,
4068 oi
->db_desc_in
, oi
->db_desc_out
, oi
->ls_req_in
,
4069 oi
->ls_req_out
, oi
->ls_upd_in
, oi
->ls_upd_out
,
4070 oi
->ls_ack_in
, oi
->ls_ack_out
, listcount(oi
->obuf
));
4074 /* OSPFv2 Packet Counters */
4075 static int show_ip_ospf_interface_traffic_common(
4076 struct vty
*vty
, struct ospf
*ospf
, char *intf_name
, json_object
*json
,
4077 int display_once
, uint8_t use_vrf
, bool use_json
)
4079 struct vrf
*vrf
= NULL
;
4080 struct interface
*ifp
= NULL
;
4081 json_object
*json_vrf
= NULL
;
4082 json_object
*json_interface_sub
= NULL
;
4084 if (!use_json
&& !display_once
) {
4086 vty_out(vty
, "%-12s%-17s%-17s%-17s%-17s%-17s%-17s\n",
4087 "Interface", " HELLO", " DB-Desc", " LS-Req",
4088 " LS-Update", " LS-Ack", " Packets");
4089 vty_out(vty
, "%-10s%-18s%-18s%-17s%-17s%-17s%-17s\n", "",
4090 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
4091 " Rx/Tx", " Queued");
4093 "-------------------------------------------------------------------------------------------------------------\n");
4094 } else if (use_json
) {
4096 json_vrf
= json_object_new_object();
4101 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4103 if (intf_name
== NULL
) {
4104 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
4105 FOR_ALL_INTERFACES (vrf
, ifp
) {
4106 struct route_node
*rn
;
4107 struct ospf_interface
*oi
;
4109 if (ospf_oi_count(ifp
) == 0)
4112 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
4113 rn
= route_next(rn
)) {
4120 json_interface_sub
=
4121 json_object_new_object();
4124 show_ip_ospf_interface_traffic_sub(
4125 vty
, oi
, json_interface_sub
, use_json
);
4127 json_object_object_add(
4128 json_vrf
, ifp
->name
,
4129 json_interface_sub
);
4134 /* Interface name is specified. */
4135 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
4137 struct route_node
*rn
;
4138 struct ospf_interface
*oi
;
4140 if (ospf_oi_count(ifp
) == 0) {
4142 " OSPF not enabled on this interface %s\n",
4147 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
4148 rn
= route_next(rn
)) {
4152 json_interface_sub
=
4153 json_object_new_object();
4156 show_ip_ospf_interface_traffic_sub(
4157 vty
, oi
, json_interface_sub
, use_json
);
4159 json_object_object_add(
4160 json_vrf
, ifp
->name
,
4161 json_interface_sub
);
4169 json_object_object_add(json
, ospf_get_name(ospf
),
4177 DEFUN (show_ip_ospf_interface
,
4178 show_ip_ospf_interface_cmd
,
4179 "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]",
4182 "OSPF information\n"
4185 "Interface information\n"
4190 bool uj
= use_json(argc
, argv
);
4191 struct listnode
*node
= NULL
;
4192 char *vrf_name
= NULL
, *intf_name
= NULL
;
4193 bool all_vrf
= false;
4194 int ret
= CMD_SUCCESS
;
4196 int idx_vrf
= 0, idx_intf
= 0;
4197 uint8_t use_vrf
= 0;
4198 json_object
*json
= NULL
;
4200 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4202 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4203 intf_name
= argv
[idx_intf
]->arg
;
4206 json
= json_object_new_object();
4208 /* vrf input is provided could be all or specific vrf*/
4212 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4213 if (!ospf
->oi_running
)
4215 ret
= show_ip_ospf_interface_common(
4216 vty
, ospf
, intf_name
, use_vrf
, json
,
4221 vty_json(vty
, json
);
4223 vty_out(vty
, "%% OSPF is not enabled\n");
4227 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4228 if (ospf
== NULL
|| !ospf
->oi_running
) {
4230 vty_json(vty
, json
);
4233 "%% OSPF is not enabled in vrf %s\n",
4238 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
4242 /* Display default ospf (instance 0) info */
4243 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4244 if (ospf
== NULL
|| !ospf
->oi_running
) {
4246 vty_json(vty
, json
);
4249 "%% OSPF is not enabled in vrf default\n");
4253 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
4258 vty_json(vty
, json
);
4263 DEFUN (show_ip_ospf_instance_interface
,
4264 show_ip_ospf_instance_interface_cmd
,
4265 "show ip ospf (1-65535) interface [INTERFACE] [json]",
4268 "OSPF information\n"
4270 "Interface information\n"
4277 unsigned short instance
= 0;
4278 bool uj
= use_json(argc
, argv
);
4279 char *intf_name
= NULL
;
4280 int ret
= CMD_SUCCESS
;
4281 json_object
*json
= NULL
;
4283 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4284 if (instance
!= ospf_instance
)
4285 return CMD_NOT_MY_INSTANCE
;
4287 ospf
= ospf_lookup_instance(instance
);
4288 if (!ospf
|| !ospf
->oi_running
)
4292 json
= json_object_new_object();
4294 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4295 intf_name
= argv
[idx_intf
]->arg
;
4297 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
, 0, json
, uj
);
4300 vty_json(vty
, json
);
4305 DEFUN (show_ip_ospf_interface_traffic
,
4306 show_ip_ospf_interface_traffic_cmd
,
4307 "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]",
4310 "OSPF information\n"
4313 "Interface information\n"
4314 "Protocol Packet counters\n"
4318 struct ospf
*ospf
= NULL
;
4319 struct listnode
*node
= NULL
;
4320 char *vrf_name
= NULL
, *intf_name
= NULL
;
4321 bool all_vrf
= false;
4323 int idx_vrf
= 0, idx_intf
= 0;
4324 bool uj
= use_json(argc
, argv
);
4325 json_object
*json
= NULL
;
4326 int ret
= CMD_SUCCESS
;
4327 int display_once
= 0;
4328 uint8_t use_vrf
= 0;
4330 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4332 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4333 intf_name
= argv
[idx_intf
]->arg
;
4336 json
= json_object_new_object();
4341 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4342 if (!ospf
->oi_running
)
4345 ret
= show_ip_ospf_interface_traffic_common(
4346 vty
, ospf
, intf_name
, json
,
4347 display_once
, use_vrf
, uj
);
4352 vty_json(vty
, json
);
4356 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4357 if (ospf
== NULL
|| !ospf
->oi_running
) {
4359 json_object_free(json
);
4363 ret
= show_ip_ospf_interface_traffic_common(
4364 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4366 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4367 if (ospf
== NULL
|| !ospf
->oi_running
) {
4369 json_object_free(json
);
4373 ret
= show_ip_ospf_interface_traffic_common(
4374 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4378 vty_json(vty
, json
);
4384 static void show_ip_ospf_neighbour_header(struct vty
*vty
)
4386 vty_out(vty
, "\n%-15s %-3s %-15s %-15s %-9s %-15s %-32s %5s %5s %5s\n",
4387 "Neighbor ID", "Pri", "State", "Up Time", "Dead Time",
4388 "Address", "Interface", "RXmtL", "RqstL", "DBsmL");
4391 static void show_ip_ospf_neighbour_brief(struct vty
*vty
,
4392 struct ospf_neighbor
*nbr
,
4393 struct ospf_neighbor
*prev_nbr
,
4394 json_object
*json
, bool use_json
)
4397 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4398 json_object
*json_neighbor
= NULL
, *json_neigh_array
= NULL
;
4399 struct timeval res
= {.tv_sec
= 0, .tv_usec
= 0};
4401 char uptime
[OSPF_TIME_DUMP_SIZE
];
4403 if (nbr
->ts_last_progress
.tv_sec
|| nbr
->ts_last_progress
.tv_usec
)
4405 monotime_since(&nbr
->ts_last_progress
, &res
) / 1000LL;
4408 char neigh_str
[INET_ADDRSTRLEN
];
4410 if (prev_nbr
&& !IPV4_ADDR_SAME(&prev_nbr
->src
, &nbr
->src
)) {
4411 /* Start new neigh list */
4412 json_neigh_array
= NULL
;
4415 if (nbr
->state
== NSM_Attempt
&&
4416 nbr
->router_id
.s_addr
== INADDR_ANY
)
4417 strlcpy(neigh_str
, "neighbor", sizeof(neigh_str
));
4419 inet_ntop(AF_INET
, &nbr
->router_id
, neigh_str
,
4422 json_object_object_get_ex(json
, neigh_str
, &json_neigh_array
);
4424 if (!json_neigh_array
) {
4425 json_neigh_array
= json_object_new_array();
4426 json_object_object_add(json
, neigh_str
,
4430 json_neighbor
= json_object_new_object();
4432 ospf_nbr_ism_state_message(nbr
, msgbuf
, sizeof(msgbuf
));
4433 json_object_string_add(json_neighbor
, "nbrState", msgbuf
);
4435 json_object_int_add(json_neighbor
, "nbrPriority",
4438 json_object_string_add(
4439 json_neighbor
, "converged",
4440 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
4441 json_object_string_add(json_neighbor
, "role",
4442 lookup_msg(ospf_ism_state_msg
,
4443 ospf_nbr_ism_state(nbr
),
4445 if (nbr
->t_inactivity
) {
4448 time_store
= monotime_until(&nbr
->t_inactivity
->u
.sands
,
4451 json_object_int_add(json_neighbor
, "upTimeInMsec",
4453 json_object_int_add(json_neighbor
,
4454 "routerDeadIntervalTimerDueMsec",
4456 json_object_string_add(
4457 json_neighbor
, "upTime",
4458 ospf_timeval_dump(&res
, uptime
,
4460 json_object_string_add(
4461 json_neighbor
, "deadTime",
4462 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
4465 json_object_string_add(json_neighbor
, "deadTimeMsecs",
4467 json_object_string_add(json_neighbor
,
4468 "routerDeadIntervalTimerDueMsec",
4471 json_object_string_addf(json_neighbor
, "ifaceAddress", "%pI4",
4473 json_object_string_add(json_neighbor
, "ifaceName",
4475 json_object_int_add(json_neighbor
,
4476 "linkStateRetransmissionListCounter",
4477 ospf_ls_retransmit_count(nbr
));
4478 json_object_int_add(json_neighbor
,
4479 "linkStateRequestListCounter",
4480 ospf_ls_request_count(nbr
));
4481 json_object_int_add(json_neighbor
, "databaseSummaryListCounter",
4482 ospf_db_summary_count(nbr
));
4484 json_object_array_add(json_neigh_array
, json_neighbor
);
4486 ospf_nbr_ism_state_message(nbr
, msgbuf
, sizeof(msgbuf
));
4488 if (nbr
->state
== NSM_Attempt
&&
4489 nbr
->router_id
.s_addr
== INADDR_ANY
)
4490 vty_out(vty
, "%-15s %3d %-15s ", "-", nbr
->priority
,
4493 vty_out(vty
, "%-15pI4 %3d %-15s ", &nbr
->router_id
,
4494 nbr
->priority
, msgbuf
);
4496 vty_out(vty
, "%-15s ",
4497 ospf_timeval_dump(&res
, uptime
, sizeof(uptime
)));
4499 vty_out(vty
, "%9s ",
4500 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
4502 vty_out(vty
, "%-15pI4 ", &nbr
->src
);
4503 vty_out(vty
, "%-32s %5ld %5ld %5d\n", IF_NAME(nbr
->oi
),
4504 ospf_ls_retransmit_count(nbr
),
4505 ospf_ls_request_count(nbr
), ospf_db_summary_count(nbr
));
4509 static void show_ip_ospf_neighbor_sub(struct vty
*vty
,
4510 struct ospf_interface
*oi
,
4511 json_object
*json
, bool use_json
)
4513 struct route_node
*rn
;
4514 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
4516 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
4522 /* Do not show myself. */
4523 if (nbr
== oi
->nbr_self
)
4525 /* Down state is not shown. */
4526 if (nbr
->state
== NSM_Down
)
4531 show_ip_ospf_neighbour_brief(vty
, nbr
, prev_nbr
, json
,
4536 static int show_ip_ospf_neighbor_common(struct vty
*vty
, struct ospf
*ospf
,
4537 json_object
*json
, bool use_json
,
4540 struct ospf_interface
*oi
;
4541 struct listnode
*node
;
4542 json_object
*json_vrf
= NULL
;
4543 json_object
*json_nbr_sub
= NULL
;
4547 json_vrf
= json_object_new_object();
4550 json_nbr_sub
= json_object_new_object();
4553 if (ospf
->instance
) {
4555 json_object_int_add(json
, "ospfInstance",
4558 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4561 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4563 show_ip_ospf_neighbour_header(vty
);
4565 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4566 if (ospf_interface_neighbor_count(oi
) == 0)
4568 show_ip_ospf_neighbor_sub(vty
, oi
, json_nbr_sub
, use_json
);
4572 json_object_object_add(json_vrf
, "neighbors", json_nbr_sub
);
4574 json_object_object_add(json
, ospf_get_name(ospf
),
4582 DEFUN (show_ip_ospf_neighbor
,
4583 show_ip_ospf_neighbor_cmd
,
4584 "show ip ospf [vrf <NAME|all>] neighbor [json]",
4587 "OSPF information\n"
4594 bool uj
= use_json(argc
, argv
);
4595 struct listnode
*node
= NULL
;
4596 char *vrf_name
= NULL
;
4597 bool all_vrf
= false;
4598 int ret
= CMD_SUCCESS
;
4601 uint8_t use_vrf
= 0;
4602 json_object
*json
= NULL
;
4604 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4607 json
= json_object_new_object();
4609 /* vrf input is provided could be all or specific vrf*/
4613 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4614 if (!ospf
->oi_running
)
4616 ret
= show_ip_ospf_neighbor_common(
4617 vty
, ospf
, json
, uj
, use_vrf
);
4621 vty_json(vty
, json
);
4623 vty_out(vty
, "OSPF is not enabled\n");
4628 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4629 if (ospf
== NULL
|| !ospf
->oi_running
) {
4631 vty_json(vty
, json
);
4634 "%% OSPF is not enabled in vrf %s\n",
4640 /* Display default ospf (instance 0) info */
4641 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4642 if (ospf
== NULL
|| !ospf
->oi_running
) {
4644 vty_json(vty
, json
);
4647 "%% OSPF is not enabled in vrf default\n");
4654 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
,
4658 vty_out(vty
, "%s\n",
4659 json_object_to_json_string_ext(
4660 json
, JSON_C_TO_STRING_PRETTY
));
4665 json_object_free(json
);
4671 DEFUN (show_ip_ospf_instance_neighbor
,
4672 show_ip_ospf_instance_neighbor_cmd
,
4673 "show ip ospf (1-65535) neighbor [json]",
4676 "OSPF information\n"
4683 unsigned short instance
= 0;
4684 bool uj
= use_json(argc
, argv
);
4685 json_object
*json
= NULL
;
4686 int ret
= CMD_SUCCESS
;
4688 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4689 if (instance
!= ospf_instance
)
4690 return CMD_NOT_MY_INSTANCE
;
4692 ospf
= ospf_lookup_instance(instance
);
4693 if (!ospf
|| !ospf
->oi_running
)
4697 json
= json_object_new_object();
4699 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
, 0);
4702 vty_json(vty
, json
);
4707 static int show_ip_ospf_neighbor_all_common(struct vty
*vty
, struct ospf
*ospf
,
4708 json_object
*json
, bool use_json
,
4711 struct listnode
*node
;
4712 struct ospf_interface
*oi
;
4713 char buf
[PREFIX_STRLEN
];
4714 json_object
*json_vrf
= NULL
;
4715 json_object
*json_neighbor_sub
= NULL
;
4719 json_vrf
= json_object_new_object();
4724 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4726 show_ip_ospf_neighbour_header(vty
);
4728 if (ospf
->instance
) {
4730 json_object_int_add(json_vrf
, "ospfInstance",
4733 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4736 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4737 struct listnode
*nbr_node
;
4738 struct ospf_nbr_nbma
*nbr_nbma
;
4740 show_ip_ospf_neighbor_sub(vty
, oi
, json_vrf
, use_json
);
4742 /* print Down neighbor status */
4743 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nbr_node
, nbr_nbma
)) {
4744 if (nbr_nbma
->nbr
== NULL
4745 || nbr_nbma
->nbr
->state
== NSM_Down
) {
4748 json_object_new_object();
4749 json_object_int_add(json_neighbor_sub
,
4751 nbr_nbma
->priority
);
4752 json_object_boolean_true_add(
4755 json_object_string_add(
4759 json_object_int_add(
4761 "nbrNbmaRetransmitCounter", 0);
4762 json_object_int_add(
4764 "nbrNbmaRequestCounter", 0);
4765 json_object_int_add(
4767 "nbrNbmaDbSummaryCounter", 0);
4768 json_object_object_add(
4771 &nbr_nbma
->addr
, buf
,
4775 vty_out(vty
, "%-15s %3d %-15s %9s ",
4776 "-", nbr_nbma
->priority
, "Down",
4779 "%-32pI4 %-20s %5d %5d %5d\n",
4781 IF_NAME(oi
), 0, 0, 0);
4789 json_object_object_add(json
, ospf_get_name(ospf
),
4797 DEFUN (show_ip_ospf_neighbor_all
,
4798 show_ip_ospf_neighbor_all_cmd
,
4799 "show ip ospf [vrf <NAME|all>] neighbor all [json]",
4802 "OSPF information\n"
4806 "include down status neighbor\n"
4810 bool uj
= use_json(argc
, argv
);
4811 struct listnode
*node
= NULL
;
4812 char *vrf_name
= NULL
;
4813 bool all_vrf
= false;
4814 int ret
= CMD_SUCCESS
;
4817 uint8_t use_vrf
= 0;
4818 json_object
*json
= NULL
;
4820 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4823 json
= json_object_new_object();
4825 /* vrf input is provided could be all or specific vrf*/
4829 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4830 if (!ospf
->oi_running
)
4832 ret
= show_ip_ospf_neighbor_all_common(
4833 vty
, ospf
, json
, uj
, use_vrf
);
4837 vty_json(vty
, json
);
4842 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4843 if (ospf
== NULL
|| !ospf
->oi_running
) {
4845 json_object_free(json
);
4849 /* Display default ospf (instance 0) info */
4850 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4851 if (ospf
== NULL
|| !ospf
->oi_running
) {
4853 json_object_free(json
);
4859 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
,
4862 vty_out(vty
, "%s\n",
4863 json_object_to_json_string_ext(
4864 json
, JSON_C_TO_STRING_PRETTY
));
4869 json_object_free(json
);
4874 DEFUN (show_ip_ospf_instance_neighbor_all
,
4875 show_ip_ospf_instance_neighbor_all_cmd
,
4876 "show ip ospf (1-65535) neighbor all [json]",
4879 "OSPF information\n"
4882 "include down status neighbor\n"
4887 unsigned short instance
= 0;
4888 bool uj
= use_json(argc
, argv
);
4889 json_object
*json
= NULL
;
4890 int ret
= CMD_SUCCESS
;
4892 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4893 if (instance
!= ospf_instance
)
4894 return CMD_NOT_MY_INSTANCE
;
4896 ospf
= ospf_lookup_instance(instance
);
4897 if (!ospf
|| !ospf
->oi_running
)
4900 json
= json_object_new_object();
4902 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
, 0);
4905 vty_json(vty
, json
);
4910 static int show_ip_ospf_neighbor_int_common(struct vty
*vty
, struct ospf
*ospf
,
4911 const char *ifname
, bool use_json
,
4914 struct interface
*ifp
;
4915 struct route_node
*rn
;
4916 json_object
*json
= NULL
;
4919 json
= json_object_new_object();
4921 if (ospf
->instance
) {
4923 json_object_int_add(json
, "ospfInstance",
4926 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4929 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
4931 ifp
= if_lookup_by_name(ifname
, ospf
->vrf_id
);
4934 json_object_boolean_true_add(json
, "noSuchIface");
4936 vty_out(vty
, "No such interface.\n");
4940 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
4941 struct ospf_interface
*oi
= rn
->info
;
4946 show_ip_ospf_neighbor_sub(vty
, oi
, json
, use_json
);
4950 vty_json(vty
, json
);
4957 DEFPY(show_ip_ospf_instance_neighbor_int
,
4958 show_ip_ospf_instance_neighbor_int_cmd
,
4959 "show ip ospf (1-65535)$instance neighbor IFNAME$ifname [json$json]",
4962 "OSPF information\n"
4971 show_ip_ospf_neighbour_header(vty
);
4973 if (instance
!= ospf_instance
)
4974 return CMD_NOT_MY_INSTANCE
;
4976 ospf
= ospf_lookup_instance(instance
);
4977 if (!ospf
|| !ospf
->oi_running
)
4981 show_ip_ospf_neighbour_header(vty
);
4983 return show_ip_ospf_neighbor_int_common(vty
, ospf
, ifname
, !!json
, 0);
4986 static void show_ip_ospf_nbr_nbma_detail_sub(struct vty
*vty
,
4987 struct ospf_interface
*oi
,
4988 struct ospf_nbr_nbma
*nbr_nbma
,
4989 bool use_json
, json_object
*json
)
4991 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4992 json_object
*json_sub
= NULL
;
4995 json_sub
= json_object_new_object();
4996 else /* Show neighbor ID. */
4997 vty_out(vty
, " Neighbor %s,", "-");
4999 /* Show interface address. */
5001 json_object_string_addf(json_sub
, "ifaceAddress", "%pI4",
5004 vty_out(vty
, " interface address %pI4\n",
5009 json_object_string_add(json_sub
, "areaId",
5010 ospf_area_desc_string(oi
->area
));
5011 json_object_string_add(json_sub
, "iface", IF_NAME(oi
));
5013 vty_out(vty
, " In the area %s via interface %s\n",
5014 ospf_area_desc_string(oi
->area
), IF_NAME(oi
));
5016 /* Show neighbor priority and state. */
5018 json_object_int_add(json_sub
, "nbrPriority",
5019 nbr_nbma
->priority
);
5020 json_object_string_add(json_sub
, "nbrState", "down");
5022 vty_out(vty
, " Neighbor priority is %d, State is %s,",
5023 nbr_nbma
->priority
, "Down");
5025 /* Show state changes. */
5027 json_object_int_add(json_sub
, "stateChangeCounter",
5028 nbr_nbma
->state_change
);
5030 vty_out(vty
, " %d state changes\n", nbr_nbma
->state_change
);
5032 /* Show PollInterval */
5034 json_object_int_add(json_sub
, "pollInterval", nbr_nbma
->v_poll
);
5036 vty_out(vty
, " Poll interval %d\n", nbr_nbma
->v_poll
);
5038 /* Show poll-interval timer. */
5039 if (nbr_nbma
->t_poll
) {
5042 time_store
= monotime_until(&nbr_nbma
->t_poll
->u
.sands
,
5044 json_object_int_add(json_sub
,
5045 "pollIntervalTimerDueMsec",
5048 vty_out(vty
, " Poll timer due in %s\n",
5049 ospf_timer_dump(nbr_nbma
->t_poll
, timebuf
,
5053 /* Show poll-interval timer thread. */
5055 if (nbr_nbma
->t_poll
!= NULL
)
5056 json_object_string_add(json_sub
,
5057 "pollIntervalTimerThread", "on");
5059 vty_out(vty
, " Thread Poll Timer %s\n",
5060 nbr_nbma
->t_poll
!= NULL
? "on" : "off");
5063 json_object_object_add(json
, "noNbrId", json_sub
);
5066 static void show_ip_ospf_neighbor_detail_sub(struct vty
*vty
,
5067 struct ospf_interface
*oi
,
5068 struct ospf_neighbor
*nbr
,
5069 struct ospf_neighbor
*prev_nbr
,
5070 json_object
*json
, bool use_json
)
5072 char timebuf
[OSPF_TIME_DUMP_SIZE
];
5073 json_object
*json_neigh
= NULL
, *json_neigh_array
= NULL
;
5074 char neigh_str
[INET_ADDRSTRLEN
] = {0};
5075 char neigh_state
[16] = {0};
5076 struct ospf_neighbor
*nbr_dr
, *nbr_bdr
;
5080 !IPV4_ADDR_SAME(&prev_nbr
->src
, &nbr
->src
)) {
5081 json_neigh_array
= NULL
;
5084 if (nbr
->state
== NSM_Attempt
5085 && nbr
->router_id
.s_addr
== INADDR_ANY
)
5086 strlcpy(neigh_str
, "noNbrId", sizeof(neigh_str
));
5088 inet_ntop(AF_INET
, &nbr
->router_id
,
5089 neigh_str
, sizeof(neigh_str
));
5091 json_object_object_get_ex(json
, neigh_str
, &json_neigh_array
);
5093 if (!json_neigh_array
) {
5094 json_neigh_array
= json_object_new_array();
5095 json_object_object_add(json
, neigh_str
,
5099 json_neigh
= json_object_new_object();
5102 /* Show neighbor ID. */
5103 if (nbr
->state
== NSM_Attempt
5104 && nbr
->router_id
.s_addr
== INADDR_ANY
)
5105 vty_out(vty
, " Neighbor %s,", "-");
5107 vty_out(vty
, " Neighbor %pI4,",
5111 /* Show interface address. */
5113 json_object_string_addf(json_neigh
, "ifaceAddress", "%pI4",
5114 &nbr
->address
.u
.prefix4
);
5116 vty_out(vty
, " interface address %pI4\n",
5117 &nbr
->address
.u
.prefix4
);
5121 json_object_string_add(json_neigh
, "areaId",
5122 ospf_area_desc_string(oi
->area
));
5123 json_object_string_add(json_neigh
, "ifaceName", oi
->ifp
->name
);
5125 json_object_string_addf(json_neigh
, "localIfaceAddress",
5127 &oi
->address
->u
.prefix4
);
5129 vty_out(vty
, " In the area %s via interface %s",
5130 ospf_area_desc_string(oi
->area
), oi
->ifp
->name
);
5132 vty_out(vty
, " local interface IP %pI4\n",
5133 &oi
->address
->u
.prefix4
);
5138 /* Show neighbor priority and state. */
5139 ospf_nbr_ism_state_message(nbr
, neigh_state
, sizeof(neigh_state
));
5141 json_object_int_add(json_neigh
, "nbrPriority", nbr
->priority
);
5142 json_object_string_add(json_neigh
, "nbrState", neigh_state
);
5143 json_object_string_add(json_neigh
, "role",
5144 lookup_msg(ospf_ism_state_msg
,
5145 ospf_nbr_ism_state(nbr
),
5149 " Neighbor priority is %d, State is %s, Role is %s,",
5150 nbr
->priority
, neigh_state
,
5151 lookup_msg(ospf_ism_state_msg
, ospf_nbr_ism_state(nbr
),
5154 /* Show state changes. */
5156 json_object_int_add(json_neigh
, "stateChangeCounter",
5159 vty_out(vty
, " %d state changes\n", nbr
->state_change
);
5161 if (nbr
->ts_last_progress
.tv_sec
|| nbr
->ts_last_progress
.tv_usec
) {
5166 monotime_since(&nbr
->ts_last_progress
, &res
) / 1000LL;
5168 json_object_int_add(json_neigh
, "lastPrgrsvChangeMsec",
5172 " Most recent state change statistics:\n");
5173 vty_out(vty
, " Progressive change %s ago\n",
5174 ospf_timeval_dump(&res
, timebuf
,
5179 if (nbr
->ts_last_regress
.tv_sec
|| nbr
->ts_last_regress
.tv_usec
) {
5184 monotime_since(&nbr
->ts_last_regress
, &res
) / 1000LL;
5186 json_object_int_add(json_neigh
,
5187 "lastRegressiveChangeMsec",
5189 if (nbr
->last_regress_str
)
5190 json_object_string_add(
5192 "lastRegressiveChangeReason",
5193 nbr
->last_regress_str
);
5196 " Regressive change %s ago, due to %s\n",
5197 ospf_timeval_dump(&res
, timebuf
,
5199 (nbr
->last_regress_str
? nbr
->last_regress_str
5204 /* Show Designated Router ID. */
5205 if (DR(oi
).s_addr
== INADDR_ANY
) {
5208 " No designated router on this network\n");
5210 nbr_dr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &DR(oi
));
5213 json_object_string_addf(
5214 json_neigh
, "routerDesignatedId",
5215 "%pI4", &nbr_dr
->router_id
);
5217 vty_out(vty
, " DR is %pI4,",
5218 &nbr_dr
->router_id
);
5222 /* Show Backup Designated Router ID. */
5223 nbr_bdr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &BDR(oi
));
5224 if (nbr_bdr
== NULL
) {
5227 " No backup designated router on this network\n");
5230 json_object_string_addf(json_neigh
,
5231 "routerDesignatedBackupId",
5232 "%pI4", &nbr_bdr
->router_id
);
5234 vty_out(vty
, " BDR is %pI4\n", &nbr_bdr
->router_id
);
5239 json_object_int_add(json_neigh
, "optionsCounter", nbr
->options
);
5240 json_object_string_add(json_neigh
, "optionsList",
5241 ospf_options_dump(nbr
->options
));
5243 vty_out(vty
, " Options %d %s\n", nbr
->options
,
5244 ospf_options_dump(nbr
->options
));
5246 /* Show Router Dead interval timer. */
5248 if (nbr
->t_inactivity
) {
5250 time_store
= monotime_until(&nbr
->t_inactivity
->u
.sands
,
5253 json_object_int_add(json_neigh
,
5254 "routerDeadIntervalTimerDueMsec",
5257 json_object_int_add(
5259 "routerDeadIntervalTimerDueMsec", -1);
5261 vty_out(vty
, " Dead timer due in %s\n",
5262 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
5265 /* Show Database Summary list. */
5267 json_object_int_add(json_neigh
, "databaseSummaryListCounter",
5268 ospf_db_summary_count(nbr
));
5270 vty_out(vty
, " Database Summary List %d\n",
5271 ospf_db_summary_count(nbr
));
5273 /* Show Link State Request list. */
5275 json_object_int_add(json_neigh
, "linkStateRequestListCounter",
5276 ospf_ls_request_count(nbr
));
5278 vty_out(vty
, " Link State Request List %ld\n",
5279 ospf_ls_request_count(nbr
));
5281 /* Show Link State Retransmission list. */
5283 json_object_int_add(json_neigh
,
5284 "linkStateRetransmissionListCounter",
5285 ospf_ls_retransmit_count(nbr
));
5287 vty_out(vty
, " Link State Retransmission List %ld\n",
5288 ospf_ls_retransmit_count(nbr
));
5290 /* Show inactivity timer thread. */
5292 if (nbr
->t_inactivity
!= NULL
)
5293 json_object_string_add(json_neigh
,
5294 "threadInactivityTimer", "on");
5296 vty_out(vty
, " Thread Inactivity Timer %s\n",
5297 nbr
->t_inactivity
!= NULL
? "on" : "off");
5299 /* Show Database Description retransmission thread. */
5301 if (nbr
->t_db_desc
!= NULL
)
5302 json_object_string_add(
5304 "threadDatabaseDescriptionRetransmission",
5308 " Thread Database Description Retransmision %s\n",
5309 nbr
->t_db_desc
!= NULL
? "on" : "off");
5311 /* Show Link State Request Retransmission thread. */
5313 if (nbr
->t_ls_req
!= NULL
)
5314 json_object_string_add(
5316 "threadLinkStateRequestRetransmission", "on");
5319 " Thread Link State Request Retransmission %s\n",
5320 nbr
->t_ls_req
!= NULL
? "on" : "off");
5322 /* Show Link State Update Retransmission thread. */
5324 if (nbr
->t_ls_upd
!= NULL
)
5325 json_object_string_add(
5327 "threadLinkStateUpdateRetransmission",
5331 " Thread Link State Update Retransmission %s\n\n",
5332 nbr
->t_ls_upd
!= NULL
? "on" : "off");
5335 vty_out(vty
, " Graceful restart Helper info:\n");
5337 if (OSPF_GR_IS_ACTIVE_HELPER(nbr
)) {
5339 " Graceful Restart HELPER Status : Inprogress.\n");
5342 " Graceful Restart grace period time: %d (seconds).\n",
5343 nbr
->gr_helper_info
.recvd_grace_period
);
5344 vty_out(vty
, " Graceful Restart reason: %s.\n",
5345 ospf_restart_reason2str(
5346 nbr
->gr_helper_info
.gr_restart_reason
));
5349 " Graceful Restart HELPER Status : None\n");
5352 if (nbr
->gr_helper_info
.rejected_reason
5353 != OSPF_HELPER_REJECTED_NONE
)
5354 vty_out(vty
, " Helper rejected reason: %s.\n",
5355 ospf_rejected_reason2str(
5356 nbr
->gr_helper_info
.rejected_reason
));
5358 if (nbr
->gr_helper_info
.helper_exit_reason
5359 != OSPF_GR_HELPER_EXIT_NONE
)
5360 vty_out(vty
, " Last helper exit reason: %s.\n\n",
5361 ospf_exit_reason2str(
5362 nbr
->gr_helper_info
.helper_exit_reason
));
5366 json_object_string_add(json_neigh
, "grHelperStatus",
5367 OSPF_GR_IS_ACTIVE_HELPER(nbr
) ?
5370 if (OSPF_GR_IS_ACTIVE_HELPER(nbr
)) {
5371 json_object_int_add(
5372 json_neigh
, "graceInterval",
5373 nbr
->gr_helper_info
.recvd_grace_period
);
5374 json_object_string_add(
5375 json_neigh
, "grRestartReason",
5376 ospf_restart_reason2str(
5377 nbr
->gr_helper_info
.gr_restart_reason
));
5380 if (nbr
->gr_helper_info
.rejected_reason
5381 != OSPF_HELPER_REJECTED_NONE
)
5382 json_object_string_add(
5383 json_neigh
, "helperRejectReason",
5384 ospf_rejected_reason2str(
5385 nbr
->gr_helper_info
.rejected_reason
));
5387 if (nbr
->gr_helper_info
.helper_exit_reason
5388 != OSPF_GR_HELPER_EXIT_NONE
)
5389 json_object_string_add(
5390 json_neigh
, "helperExitReason",
5391 ospf_exit_reason2str(
5393 .helper_exit_reason
));
5396 bfd_sess_show(vty
, json_neigh
, nbr
->bfd_session
);
5399 json_object_array_add(json_neigh_array
, json_neigh
);
5403 static int show_ip_ospf_neighbor_id_common(struct vty
*vty
, struct ospf
*ospf
,
5404 struct in_addr
*router_id
,
5405 bool use_json
, uint8_t use_vrf
,
5407 json_object
*json_vrf
)
5409 struct listnode
*node
;
5410 struct ospf_neighbor
*nbr
;
5411 struct ospf_interface
*oi
;
5412 json_object
*json
= NULL
;
5415 json
= json_object_new_object();
5417 if (ospf
->instance
) {
5419 json_object_int_add(json
, "ospfInstance",
5422 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5425 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
5427 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5428 nbr
= ospf_nbr_lookup_by_routerid(oi
->nbrs
, router_id
);
5434 show_ip_ospf_neighbor_detail_sub(vty
, oi
, nbr
, NULL
,
5437 show_ip_ospf_neighbour_brief(vty
, nbr
, NULL
, json
,
5441 if (json_vrf
&& use_json
) {
5442 json_object_object_add(
5444 (ospf
->vrf_id
== VRF_DEFAULT
) ? "default" : ospf
->name
,
5450 vty_json(vty
, json
);
5457 DEFPY(show_ip_ospf_neighbor_id
,
5458 show_ip_ospf_neighbor_id_cmd
,
5459 "show ip ospf [vrf NAME$vrf_name] neighbor A.B.C.D$router_id [detail$detail] [json$json]",
5462 "OSPF information\n"
5470 struct listnode
*node
;
5471 int ret
= CMD_SUCCESS
;
5474 if (vrf_name
&& !strmatch(vrf_name
, "all")) {
5475 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5476 if (ospf
== NULL
|| !ospf
->oi_running
) {
5479 "%% OSPF is not enabled in vrf %s\n",
5482 vty_json_empty(vty
);
5485 ret
= show_ip_ospf_neighbor_id_common(
5486 vty
, ospf
, &router_id
, !!json
, 0, !!detail
, NULL
);
5488 json_object
*json_vrf
= NULL
;
5491 json_vrf
= json_object_new_object();
5492 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5493 if (!ospf
->oi_running
)
5495 ret
= show_ip_ospf_neighbor_id_common(
5496 vty
, ospf
, &router_id
, !!json
, 0, !!detail
,
5500 vty_json(vty
, json_vrf
);
5506 DEFPY(show_ip_ospf_instance_neighbor_id
, show_ip_ospf_instance_neighbor_id_cmd
,
5507 "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [detail$detail] [json$json]",
5509 "OSPF information\n"
5513 "Detailed output\n" JSON_STR
)
5517 if (instance
!= ospf_instance
)
5518 return CMD_NOT_MY_INSTANCE
;
5520 ospf
= ospf_lookup_instance(instance
);
5521 if (!ospf
|| !ospf
->oi_running
)
5524 return show_ip_ospf_neighbor_id_common(vty
, ospf
, &router_id
, !!json
, 0,
5528 static int show_ip_ospf_neighbor_detail_common(struct vty
*vty
,
5530 json_object
*json
, bool use_json
,
5533 struct ospf_interface
*oi
;
5534 struct listnode
*node
;
5535 json_object
*json_vrf
= NULL
;
5536 json_object
*json_nbr_sub
= NULL
;
5540 json_vrf
= json_object_new_object();
5544 json_nbr_sub
= json_object_new_object();
5547 if (ospf
->instance
) {
5549 json_object_int_add(json
, "ospfInstance",
5552 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5555 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5557 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5558 struct route_node
*rn
;
5559 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
5561 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5567 if (nbr
!= oi
->nbr_self
) {
5568 if (nbr
->state
!= NSM_Down
) {
5569 show_ip_ospf_neighbor_detail_sub(
5570 vty
, oi
, nbr
, prev_nbr
,
5571 json_nbr_sub
, use_json
);
5579 json_object_object_add(json_vrf
, "neighbors",
5582 json_object_object_add(json
, ospf_get_name(ospf
),
5590 DEFPY(show_ip_ospf_neighbor_detail
,
5591 show_ip_ospf_neighbor_detail_cmd
,
5592 "show ip ospf [vrf <NAME|all>$vrf_name] neighbor detail [json$json]",
5595 "OSPF information\n"
5599 "detail of all neighbors\n"
5603 struct listnode
*node
= NULL
;
5604 int ret
= CMD_SUCCESS
;
5606 uint8_t use_vrf
= 0;
5607 json_object
*json_vrf
= NULL
;
5610 json_vrf
= json_object_new_object();
5612 /* vrf input is provided could be all or specific vrf*/
5615 if (strmatch(vrf_name
, "all")) {
5616 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5617 if (!ospf
->oi_running
)
5619 ret
= show_ip_ospf_neighbor_detail_common(
5620 vty
, ospf
, json_vrf
, !!json
, use_vrf
);
5623 vty_json(vty
, json_vrf
);
5627 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5628 if (ospf
== NULL
|| !ospf
->oi_running
) {
5630 vty_json(vty
, json_vrf
);
5633 "%% OSPF is not enabled in vrf %s\n",
5638 /* Display default ospf (instance 0) info */
5639 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5640 if (ospf
== NULL
|| !ospf
->oi_running
) {
5642 vty_json(vty
, json_vrf
);
5644 vty_out(vty
, "%% OSPF is not enabled\n");
5650 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json_vrf
,
5654 vty_json(vty
, json_vrf
);
5659 DEFUN (show_ip_ospf_instance_neighbor_detail
,
5660 show_ip_ospf_instance_neighbor_detail_cmd
,
5661 "show ip ospf (1-65535) neighbor detail [json]",
5664 "OSPF information\n"
5667 "detail of all neighbors\n"
5672 unsigned short instance
= 0;
5673 bool uj
= use_json(argc
, argv
);
5674 json_object
*json
= NULL
;
5675 int ret
= CMD_SUCCESS
;
5677 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5678 if (instance
!= ospf_instance
)
5679 return CMD_NOT_MY_INSTANCE
;
5681 ospf
= ospf_lookup_instance(instance
);
5682 if (!ospf
|| !ospf
->oi_running
)
5686 json
= json_object_new_object();
5688 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
, 0);
5691 vty_json(vty
, json
);
5696 static int show_ip_ospf_neighbor_detail_all_common(struct vty
*vty
,
5702 struct listnode
*node
;
5703 struct ospf_interface
*oi
;
5704 json_object
*json_vrf
= NULL
;
5708 json_vrf
= json_object_new_object();
5713 if (ospf
->instance
) {
5715 json_object_int_add(json
, "ospfInstance",
5718 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5721 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5723 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5724 struct route_node
*rn
;
5725 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
5726 struct ospf_nbr_nbma
*nbr_nbma
;
5728 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5734 if (nbr
!= oi
->nbr_self
)
5735 if (nbr
->state
!= NSM_Down
)
5736 show_ip_ospf_neighbor_detail_sub(
5737 vty
, oi
, rn
->info
, prev_nbr
,
5738 json_vrf
, use_json
);
5742 if (oi
->type
!= OSPF_IFTYPE_NBMA
)
5745 struct listnode
*nd
;
5747 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nd
, nbr_nbma
)) {
5748 if (nbr_nbma
->nbr
== NULL
||
5749 nbr_nbma
->nbr
->state
== NSM_Down
)
5750 show_ip_ospf_nbr_nbma_detail_sub(
5751 vty
, oi
, nbr_nbma
, use_json
, json_vrf
);
5757 json_object_object_add(json
, ospf_get_name(ospf
),
5766 DEFUN (show_ip_ospf_neighbor_detail_all
,
5767 show_ip_ospf_neighbor_detail_all_cmd
,
5768 "show ip ospf [vrf <NAME|all>] neighbor detail all [json]",
5771 "OSPF information\n"
5775 "detail of all neighbors\n"
5776 "include down status neighbor\n"
5780 bool uj
= use_json(argc
, argv
);
5781 struct listnode
*node
= NULL
;
5782 char *vrf_name
= NULL
;
5783 bool all_vrf
= false;
5784 int ret
= CMD_SUCCESS
;
5787 uint8_t use_vrf
= 0;
5788 json_object
*json
= NULL
;
5790 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5793 json
= json_object_new_object();
5795 /* vrf input is provided could be all or specific vrf*/
5799 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5800 if (!ospf
->oi_running
)
5802 ret
= show_ip_ospf_neighbor_detail_all_common(
5803 vty
, ospf
, json
, uj
, use_vrf
);
5807 vty_json(vty
, json
);
5811 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5812 if (ospf
== NULL
|| !ospf
->oi_running
) {
5814 json_object_free(json
);
5818 /* Display default ospf (instance 0) info */
5819 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5820 if (ospf
== NULL
|| !ospf
->oi_running
) {
5822 json_object_free(json
);
5828 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
,
5831 vty_out(vty
, "%s\n",
5832 json_object_to_json_string_ext(
5833 json
, JSON_C_TO_STRING_PRETTY
));
5838 json_object_free(json
);
5843 DEFUN (show_ip_ospf_instance_neighbor_detail_all
,
5844 show_ip_ospf_instance_neighbor_detail_all_cmd
,
5845 "show ip ospf (1-65535) neighbor detail all [json]",
5848 "OSPF information\n"
5851 "detail of all neighbors\n"
5852 "include down status neighbor\n"
5857 unsigned short instance
= 0;
5858 bool uj
= use_json(argc
, argv
);
5859 json_object
*json
= NULL
;
5860 int ret
= CMD_SUCCESS
;
5862 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5863 if (instance
!= ospf_instance
)
5864 return CMD_NOT_MY_INSTANCE
;
5866 ospf
= ospf_lookup_instance(instance
);
5867 if (!ospf
|| !ospf
->oi_running
)
5871 json
= json_object_new_object();
5873 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
, uj
, 0);
5876 vty_json(vty
, json
);
5881 static int show_ip_ospf_neighbor_int_detail_common(struct vty
*vty
,
5885 json_object
*json_vrf
)
5887 struct ospf_interface
*oi
;
5888 struct interface
*ifp
;
5889 struct route_node
*rn
, *nrn
;
5890 struct ospf_neighbor
*nbr
;
5891 json_object
*json
= NULL
;
5894 json
= json_object_new_object();
5896 json_object_object_add(json_vrf
,
5897 (ospf
->vrf_id
== VRF_DEFAULT
)
5903 if (ospf
->instance
) {
5905 json_object_int_add(json
, "ospfInstance",
5908 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5911 ifp
= if_lookup_by_name(ifname
, ospf
->vrf_id
);
5914 vty_out(vty
, "No such interface.\n");
5917 vty_json(vty
, json
);
5922 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
5928 for (nrn
= route_top(oi
->nbrs
); nrn
; nrn
= route_next(nrn
)) {
5934 if (nbr
== oi
->nbr_self
)
5937 if (nbr
->state
== NSM_Down
)
5940 show_ip_ospf_neighbor_detail_sub(vty
, oi
, nbr
, NULL
,
5947 vty_json(vty
, json
);
5955 DEFPY(show_ip_ospf_neighbor_int
,
5956 show_ip_ospf_neighbor_int_cmd
,
5957 "show ip ospf [vrf NAME$vrf_name] neighbor IFNAME$ifname [json$json]",
5960 "OSPF information\n"
5967 int ret
= CMD_SUCCESS
;
5968 struct interface
*ifp
= NULL
;
5969 vrf_id_t vrf_id
= VRF_DEFAULT
;
5970 struct vrf
*vrf
= NULL
;
5972 if (vrf_name
&& strmatch(vrf_name
, VRF_DEFAULT_NAME
))
5975 vrf
= vrf_lookup_by_name(vrf_name
);
5977 vrf_id
= vrf
->vrf_id
;
5979 ospf
= ospf_lookup_by_vrf_id(vrf_id
);
5981 if (!ospf
|| !ospf
->oi_running
) {
5983 vty_json_empty(vty
);
5988 show_ip_ospf_neighbour_header(vty
);
5990 ifp
= if_lookup_by_name(ifname
, vrf_id
);
5993 vty_json_empty(vty
);
5995 vty_out(vty
, "No such interface.\n");
5999 ret
= show_ip_ospf_neighbor_int_common(vty
, ospf
, ifname
, !!json
, 0);
6003 DEFPY(show_ip_ospf_neighbor_int_detail
,
6004 show_ip_ospf_neighbor_int_detail_cmd
,
6005 "show ip ospf [vrf NAME$vrf_name] neighbor IFNAME$ifname detail [json$json]",
6008 "OSPF information\n"
6012 "detail of all neighbors\n"
6016 struct listnode
*node
= NULL
;
6017 int ret
= CMD_SUCCESS
;
6018 bool ospf_output
= false;
6020 if (vrf_name
&& !strmatch(vrf_name
, "all")) {
6023 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6024 if (ospf
== NULL
|| !ospf
->oi_running
) {
6027 "%% OSPF is not enabled in vrf %s\n",
6030 vty_json_empty(vty
);
6033 return show_ip_ospf_neighbor_int_detail_common(
6034 vty
, ospf
, ifname
, !!json
, NULL
);
6037 json_object
*json_vrf
= NULL
;
6040 json_vrf
= json_object_new_object();
6042 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6043 if (!ospf
->oi_running
)
6046 ret
= show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, ifname
,
6051 vty_json(vty
, json_vrf
);
6056 vty_out(vty
, "%% OSPF instance not found\n");
6061 DEFPY(show_ip_ospf_instance_neighbor_int_detail
,
6062 show_ip_ospf_instance_neighbor_int_detail_cmd
,
6063 "show ip ospf (1-65535)$instance neighbor IFNAME$ifname detail [json$json]",
6066 "OSPF information\n"
6070 "detail of all neighbors\n"
6075 if (instance
!= ospf_instance
)
6076 return CMD_NOT_MY_INSTANCE
;
6078 ospf
= ospf_lookup_instance(instance
);
6079 if (!ospf
|| !ospf
->oi_running
)
6082 return show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, ifname
,
6086 /* Show functions */
6087 static int show_lsa_summary(struct vty
*vty
, struct ospf_lsa
*lsa
, int self
,
6088 json_object
*json_lsa
)
6090 struct router_lsa
*rl
;
6091 struct summary_lsa
*sl
;
6092 struct as_external_lsa
*asel
;
6093 struct prefix_ipv4 p
;
6098 /* If self option is set, check LSA self flag. */
6099 if (self
== 0 || IS_LSA_SELF(lsa
)) {
6102 /* LSA common part show. */
6103 vty_out(vty
, "%-15pI4", &lsa
->data
->id
);
6104 vty_out(vty
, "%-15pI4 %4d 0x%08lx 0x%04x",
6105 &lsa
->data
->adv_router
, LS_AGE(lsa
),
6106 (unsigned long)ntohl(lsa
->data
->ls_seqnum
),
6107 ntohs(lsa
->data
->checksum
));
6112 snprintf(seqnum
, sizeof(seqnum
), "%x",
6113 ntohl(lsa
->data
->ls_seqnum
));
6114 snprintf(checksum
, sizeof(checksum
), "%x",
6115 ntohs(lsa
->data
->checksum
));
6116 json_object_string_addf(json_lsa
, "lsId", "%pI4",
6118 json_object_string_addf(json_lsa
, "advertisedRouter",
6119 "%pI4", &lsa
->data
->adv_router
);
6120 json_object_int_add(json_lsa
, "lsaAge", LS_AGE(lsa
));
6121 json_object_string_add(json_lsa
, "sequenceNumber",
6123 json_object_string_add(json_lsa
, "checksum", checksum
);
6126 /* LSA specific part show. */
6127 switch (lsa
->data
->type
) {
6128 case OSPF_ROUTER_LSA
:
6129 rl
= (struct router_lsa
*)lsa
->data
;
6132 vty_out(vty
, " %-d", ntohs(rl
->links
));
6134 json_object_int_add(json_lsa
,
6138 case OSPF_SUMMARY_LSA
:
6139 sl
= (struct summary_lsa
*)lsa
->data
;
6142 p
.prefix
= sl
->header
.id
;
6143 p
.prefixlen
= ip_masklen(sl
->mask
);
6144 apply_mask_ipv4(&p
);
6147 vty_out(vty
, " %pFX", &p
);
6149 json_object_string_addf(
6150 json_lsa
, "summaryAddress", "%pFX", &p
);
6153 case OSPF_AS_EXTERNAL_LSA
:
6154 case OSPF_AS_NSSA_LSA
:
6155 asel
= (struct as_external_lsa
*)lsa
->data
;
6158 p
.prefix
= asel
->header
.id
;
6159 p
.prefixlen
= ip_masklen(asel
->mask
);
6160 apply_mask_ipv4(&p
);
6163 vty_out(vty
, " %s %pFX [0x%lx]",
6164 IS_EXTERNAL_METRIC(asel
->e
[0].tos
)
6168 (unsigned long)ntohl(
6169 asel
->e
[0].route_tag
));
6171 json_object_string_add(
6172 json_lsa
, "metricType",
6173 IS_EXTERNAL_METRIC(asel
->e
[0].tos
)
6176 json_object_string_addf(json_lsa
, "route",
6178 json_object_int_add(
6180 (unsigned long)ntohl(
6181 asel
->e
[0].route_tag
));
6184 case OSPF_NETWORK_LSA
:
6185 case OSPF_ASBR_SUMMARY_LSA
:
6186 case OSPF_OPAQUE_LINK_LSA
:
6187 case OSPF_OPAQUE_AREA_LSA
:
6188 case OSPF_OPAQUE_AS_LSA
:
6200 static const char *const show_database_desc
[] = {
6202 "Router Link States",
6204 "Summary Link States",
6205 "ASBR-Summary Link States",
6206 "AS External Link States",
6207 "Group Membership LSA",
6208 "NSSA-external Link States",
6210 "Link-Local Opaque-LSA",
6211 "Area-Local Opaque-LSA",
6212 "AS-external Opaque-LSA",
6215 static const char * const show_database_desc_json
[] = {
6218 "networkLinkStates",
6219 "summaryLinkStates",
6220 "asbrSummaryLinkStates",
6221 "asExternalLinkStates",
6222 "groupMembershipLsa",
6223 "nssaExternalLinkStates",
6225 "linkLocalOpaqueLsa",
6226 "areaLocalOpaqueLsa",
6227 "asExternalOpaqueLsa",
6230 static const char *const show_database_desc_count_json
[] = {
6232 "routerLinkStatesCount",
6233 "networkLinkStatesCount",
6234 "summaryLinkStatesCount",
6235 "asbrSummaryLinkStatesCount",
6236 "asExternalLinkStatesCount",
6237 "groupMembershipLsaCount",
6238 "nssaExternalLinkStatesCount",
6240 "linkLocalOpaqueLsaCount",
6241 "areaLocalOpaqueLsaCount",
6242 "asExternalOpaqueLsaCount",
6245 static const char *const show_database_header
[] = {
6247 "Link ID ADV Router Age Seq# CkSum Link count",
6248 "Link ID ADV Router Age Seq# CkSum",
6249 "Link ID ADV Router Age Seq# CkSum Route",
6250 "Link ID ADV Router Age Seq# CkSum",
6251 "Link ID ADV Router Age Seq# CkSum Route",
6252 " --- header for Group Member ----",
6253 "Link ID ADV Router Age Seq# CkSum Route",
6255 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6256 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6257 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6260 static void show_ip_ospf_database_header(struct vty
*vty
, struct ospf_lsa
*lsa
,
6263 struct router_lsa
*rlsa
= (struct router_lsa
*)lsa
->data
;
6266 if (IS_LSA_SELF(lsa
))
6267 vty_out(vty
, " LS age: %d%s\n", LS_AGE(lsa
),
6268 CHECK_FLAG(lsa
->data
->ls_age
, DO_NOT_AGE
)
6272 vty_out(vty
, " LS age: %d%s\n", LS_AGE(lsa
),
6273 CHECK_FLAG(lsa
->data
->ls_age
, DO_NOT_AGE
)
6276 vty_out(vty
, " Options: 0x%-2x : %s\n", lsa
->data
->options
,
6277 ospf_options_dump(lsa
->data
->options
));
6278 vty_out(vty
, " LS Flags: 0x%-2x %s\n", lsa
->flags
,
6279 ((lsa
->flags
& OSPF_LSA_LOCAL_XLT
)
6280 ? "(Translated from Type-7)"
6283 if (lsa
->data
->type
== OSPF_ROUTER_LSA
) {
6284 vty_out(vty
, " Flags: 0x%x", rlsa
->flags
);
6287 vty_out(vty
, " :%s%s%s%s",
6288 IS_ROUTER_LSA_BORDER(rlsa
) ? " ABR"
6290 IS_ROUTER_LSA_EXTERNAL(rlsa
) ? " ASBR"
6292 IS_ROUTER_LSA_VIRTUAL(rlsa
)
6295 IS_ROUTER_LSA_SHORTCUT(rlsa
)
6301 vty_out(vty
, " LS Type: %s\n",
6302 lookup_msg(ospf_lsa_type_msg
, lsa
->data
->type
, NULL
));
6303 vty_out(vty
, " Link State ID: %pI4 %s\n",
6305 lookup_msg(ospf_link_state_id_type_msg
, lsa
->data
->type
,
6307 vty_out(vty
, " Advertising Router: %pI4\n",
6308 &lsa
->data
->adv_router
);
6309 vty_out(vty
, " LS Seq Number: %08lx\n",
6310 (unsigned long)ntohl(lsa
->data
->ls_seqnum
));
6311 vty_out(vty
, " Checksum: 0x%04x\n",
6312 ntohs(lsa
->data
->checksum
));
6313 vty_out(vty
, " Length: %d\n\n", ntohs(lsa
->data
->length
));
6318 snprintf(seqnum
, 10, "%x", ntohl(lsa
->data
->ls_seqnum
));
6319 snprintf(checksum
, 10, "%x", ntohs(lsa
->data
->checksum
));
6321 json_object_int_add(json
, "lsaAge", LS_AGE(lsa
));
6322 json_object_string_add(json
, "options",
6323 ospf_options_dump(lsa
->data
->options
));
6324 json_object_int_add(json
, "lsaFlags", lsa
->flags
);
6326 if (lsa
->flags
& OSPF_LSA_LOCAL_XLT
)
6327 json_object_boolean_true_add(json
,
6328 "translatedFromType7");
6330 if (lsa
->data
->type
== OSPF_ROUTER_LSA
) {
6331 json_object_int_add(json
, "flags", rlsa
->flags
);
6334 if (IS_ROUTER_LSA_BORDER(rlsa
))
6335 json_object_boolean_true_add(json
,
6337 if (IS_ROUTER_LSA_EXTERNAL(rlsa
))
6338 json_object_boolean_true_add(json
,
6340 if (IS_ROUTER_LSA_VIRTUAL(rlsa
))
6341 json_object_boolean_true_add(
6342 json
, "vlEndpoint");
6343 if (IS_ROUTER_LSA_SHORTCUT(rlsa
))
6344 json_object_boolean_true_add(
6349 json_object_string_add(
6351 lookup_msg(ospf_lsa_type_msg
, lsa
->data
->type
, NULL
));
6352 json_object_string_addf(json
, "linkStateId", "%pI4",
6354 json_object_string_addf(json
, "advertisingRouter", "%pI4",
6355 &lsa
->data
->adv_router
);
6356 json_object_string_add(json
, "lsaSeqNumber", seqnum
);
6357 json_object_string_add(json
, "checksum", checksum
);
6358 json_object_int_add(json
, "length", ntohs(lsa
->data
->length
));
6362 static const char *const link_type_desc
[] = {
6364 "another Router (point-to-point)",
6365 "a Transit Network",
6370 static const char *const link_id_desc
[] = {
6371 "(null)", "Neighboring Router ID", "Designated Router address",
6372 "Net", "Neighboring Router ID",
6375 static const char *const link_data_desc
[] = {
6376 "(null)", "Router Interface address", "Router Interface address",
6377 "Network Mask", "Router Interface address",
6380 static const char *const link_id_desc_json
[] = {
6381 "null", "neighborRouterId", "designatedRouterAddress",
6382 "networkAddress", "neighborRouterId",
6385 static const char *const link_data_desc_json
[] = {
6386 "null", "routerInterfaceAddress", "routerInterfaceAddress",
6387 "networkMask", "routerInterfaceAddress",
6390 /* Show router-LSA each Link information. */
6391 static void show_ip_ospf_database_router_links(struct vty
*vty
,
6392 struct router_lsa
*rl
,
6397 json_object
*json_links
= NULL
;
6398 json_object
*json_link
= NULL
;
6400 char buf
[PREFIX_STRLEN
];
6403 json_links
= json_object_new_object();
6405 len
= ntohs(rl
->header
.length
) - 4;
6406 for (i
= 0; i
< ntohs(rl
->links
) && len
> 0; len
-= 12, i
++) {
6407 type
= rl
->link
[i
].type
;
6412 snprintf(link
, sizeof(link
), "link%u", i
);
6413 json_link
= json_object_new_object();
6414 json_object_string_add(json_link
, "linkType",
6415 link_type_desc
[type
]);
6416 json_object_string_add(json_link
,
6417 link_id_desc_json
[type
],
6419 &rl
->link
[i
].link_id
,
6421 json_object_string_add(
6422 json_link
, link_data_desc_json
[type
],
6423 inet_ntop(AF_INET
, &rl
->link
[i
].link_data
,
6425 json_object_int_add(json_link
, "numOfTosMetrics",
6427 json_object_int_add(json_link
, "tos0Metric",
6428 ntohs(rl
->link
[i
].metric
));
6429 json_object_object_add(json_links
, link
, json_link
);
6431 vty_out(vty
, " Link connected to: %s\n",
6432 link_type_desc
[type
]);
6433 vty_out(vty
, " (Link ID) %s: %pI4\n",
6435 &rl
->link
[i
].link_id
);
6436 vty_out(vty
, " (Link Data) %s: %pI4\n",
6437 link_data_desc
[type
],
6438 &rl
->link
[i
].link_data
);
6439 vty_out(vty
, " Number of TOS metrics: 0\n");
6440 vty_out(vty
, " TOS 0 Metric: %d\n",
6441 ntohs(rl
->link
[i
].metric
));
6446 json_object_object_add(json
, "routerLinks", json_links
);
6449 /* Show router-LSA detail information. */
6450 static int show_router_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6454 struct router_lsa
*rl
= (struct router_lsa
*)lsa
->data
;
6456 show_ip_ospf_database_header(vty
, lsa
, json
);
6459 vty_out(vty
, " Number of Links: %d\n\n",
6462 json_object_int_add(json
, "numOfLinks",
6465 show_ip_ospf_database_router_links(vty
, rl
, json
);
6474 /* Show network-LSA detail information. */
6475 static int show_network_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6479 char buf
[PREFIX_STRLEN
];
6480 json_object
*json_attached_rt
= NULL
;
6481 json_object
*json_router
= NULL
;
6484 json_attached_rt
= json_object_new_object();
6487 struct network_lsa
*nl
= (struct network_lsa
*)lsa
->data
;
6488 struct in_addr
*addr
;
6490 show_ip_ospf_database_header(vty
, lsa
, json
);
6493 vty_out(vty
, " Network Mask: /%d\n",
6494 ip_masklen(nl
->mask
));
6496 json_object_int_add(json
, "networkMask",
6497 ip_masklen(nl
->mask
));
6499 length
= lsa
->size
- OSPF_LSA_HEADER_SIZE
- 4;
6500 addr
= &nl
->routers
[0];
6501 for (i
= 0; length
> 0 && addr
;
6502 length
-= 4, addr
= &nl
->routers
[++i
])
6504 vty_out(vty
, " Attached Router: %pI4\n",
6508 json_router
= json_object_new_object();
6509 json_object_string_add(
6510 json_router
, "attachedRouterId",
6511 inet_ntop(AF_INET
, addr
, buf
,
6513 json_object_object_add(json_attached_rt
,
6514 inet_ntop(AF_INET
, addr
,
6522 json_object_object_add(json
, "attchedRouters",
6528 /* Show summary-LSA detail information. */
6529 static int show_summary_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6533 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
6535 show_ip_ospf_database_header(vty
, lsa
, json
);
6538 vty_out(vty
, " Network Mask: /%d\n",
6539 ip_masklen(sl
->mask
));
6540 vty_out(vty
, " TOS: 0 Metric: %d\n",
6541 GET_METRIC(sl
->metric
));
6544 json_object_int_add(json
, "networkMask",
6545 ip_masklen(sl
->mask
));
6546 json_object_int_add(json
, "tos0Metric",
6547 GET_METRIC(sl
->metric
));
6554 /* Show summary-ASBR-LSA detail information. */
6555 static int show_summary_asbr_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6559 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
6561 show_ip_ospf_database_header(vty
, lsa
, json
);
6564 vty_out(vty
, " Network Mask: /%d\n",
6565 ip_masklen(sl
->mask
));
6566 vty_out(vty
, " TOS: 0 Metric: %d\n",
6567 GET_METRIC(sl
->metric
));
6570 json_object_int_add(json
, "networkMask",
6571 ip_masklen(sl
->mask
));
6572 json_object_int_add(json
, "tos0Metric",
6573 GET_METRIC(sl
->metric
));
6580 /* Show AS-external-LSA detail information. */
6581 static int show_as_external_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6587 struct as_external_lsa
*al
=
6588 (struct as_external_lsa
*)lsa
->data
;
6590 show_ip_ospf_database_header(vty
, lsa
, json
);
6593 vty_out(vty
, " Network Mask: /%d\n",
6594 ip_masklen(al
->mask
));
6595 vty_out(vty
, " Metric Type: %s\n",
6596 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6597 ? "2 (Larger than any link state path)"
6599 vty_out(vty
, " TOS: 0\n");
6600 vty_out(vty
, " Metric: %d\n",
6601 GET_METRIC(al
->e
[0].metric
));
6602 vty_out(vty
, " Forward Address: %pI4\n",
6603 &al
->e
[0].fwd_addr
);
6605 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
6606 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6608 json_object_int_add(json
, "networkMask",
6609 ip_masklen(al
->mask
));
6610 json_object_string_add(
6612 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6613 ? "E2 (Larger than any link state path)"
6615 json_object_int_add(json
, "tos", tos
);
6616 json_object_int_add(json
, "metric",
6617 GET_METRIC(al
->e
[0].metric
));
6618 json_object_string_addf(json
, "forwardAddress", "%pI4",
6619 &(al
->e
[0].fwd_addr
));
6620 json_object_int_add(
6621 json
, "externalRouteTag",
6622 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6629 /* Show AS-NSSA-LSA detail information. */
6630 static int show_as_nssa_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6636 struct as_external_lsa
*al
=
6637 (struct as_external_lsa
*)lsa
->data
;
6639 show_ip_ospf_database_header(vty
, lsa
, json
);
6642 vty_out(vty
, " Network Mask: /%d\n",
6643 ip_masklen(al
->mask
));
6644 vty_out(vty
, " Metric Type: %s\n",
6645 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6646 ? "2 (Larger than any link state path)"
6648 vty_out(vty
, " TOS: 0\n");
6649 vty_out(vty
, " Metric: %d\n",
6650 GET_METRIC(al
->e
[0].metric
));
6651 vty_out(vty
, " NSSA: Forward Address: %pI4\n",
6652 &al
->e
[0].fwd_addr
);
6654 " External Route Tag: %" ROUTE_TAG_PRI
6656 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6658 json_object_int_add(json
, "networkMask",
6659 ip_masklen(al
->mask
));
6660 json_object_string_add(
6662 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6663 ? "E2 (Larger than any link state path)"
6665 json_object_int_add(json
, "tos", tos
);
6666 json_object_int_add(json
, "metric",
6667 GET_METRIC(al
->e
[0].metric
));
6668 json_object_string_addf(json
, "nssaForwardAddress",
6669 "%pI4", &al
->e
[0].fwd_addr
);
6670 json_object_int_add(
6671 json
, "externalRouteTag",
6672 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6679 static int show_func_dummy(struct vty
*vty
, struct ospf_lsa
*lsa
,
6685 static int show_opaque_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6689 show_ip_ospf_database_header(vty
, lsa
, json
);
6690 show_opaque_info_detail(vty
, lsa
, json
);
6697 int (*show_function
[])(struct vty
*, struct ospf_lsa
*, json_object
*) = {
6699 show_router_lsa_detail
,
6700 show_network_lsa_detail
,
6701 show_summary_lsa_detail
,
6702 show_summary_asbr_lsa_detail
,
6703 show_as_external_lsa_detail
,
6705 show_as_nssa_lsa_detail
, /* almost same as external */
6707 show_opaque_lsa_detail
,
6708 show_opaque_lsa_detail
,
6709 show_opaque_lsa_detail
,
6712 static void show_lsa_prefix_set(struct vty
*vty
, struct prefix_ls
*lp
,
6713 struct in_addr
*id
, struct in_addr
*adv_router
)
6715 memset(lp
, 0, sizeof(struct prefix_ls
));
6716 lp
->family
= AF_UNSPEC
;
6719 else if (adv_router
== NULL
) {
6720 lp
->prefixlen
= IPV4_MAX_BITLEN
;
6725 lp
->adv_router
= *adv_router
;
6729 static void show_lsa_detail_proc(struct vty
*vty
, struct route_table
*rt
,
6730 struct in_addr
*id
, struct in_addr
*adv_router
,
6733 struct prefix_ls lp
;
6734 struct route_node
*rn
, *start
;
6735 struct ospf_lsa
*lsa
;
6736 json_object
*json_lsa
= NULL
;
6738 show_lsa_prefix_set(vty
, &lp
, id
, adv_router
);
6739 start
= route_node_get(rt
, (struct prefix
*)&lp
);
6741 route_lock_node(start
);
6742 for (rn
= start
; rn
; rn
= route_next_until(rn
, start
))
6743 if ((lsa
= rn
->info
)) {
6744 if (show_function
[lsa
->data
->type
] != NULL
) {
6747 json_object_new_object();
6748 json_object_array_add(json
,
6752 show_function
[lsa
->data
->type
](
6753 vty
, lsa
, json_lsa
);
6756 route_unlock_node(start
);
6760 /* Show detail LSA information
6761 -- if id is NULL then show all LSAs. */
6762 static void show_lsa_detail(struct vty
*vty
, struct ospf
*ospf
, int type
,
6763 struct in_addr
*id
, struct in_addr
*adv_router
,
6766 struct listnode
*node
;
6767 struct ospf_area
*area
;
6768 char buf
[PREFIX_STRLEN
];
6769 json_object
*json_lsa_type
= NULL
;
6770 json_object
*json_areas
= NULL
;
6771 json_object
*json_lsa_array
= NULL
;
6774 case OSPF_AS_EXTERNAL_LSA
:
6775 case OSPF_OPAQUE_AS_LSA
:
6777 vty_out(vty
, " %s \n\n",
6778 show_database_desc
[type
]);
6780 json_lsa_array
= json_object_new_array();
6782 show_lsa_detail_proc(vty
, AS_LSDB(ospf
, type
), id
, adv_router
,
6785 json_object_object_add(json
,
6786 show_database_desc_json
[type
],
6792 json_areas
= json_object_new_object();
6794 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6797 "\n %s (Area %s)\n\n",
6798 show_database_desc
[type
],
6799 ospf_area_desc_string(area
));
6801 json_lsa_array
= json_object_new_array();
6802 json_object_object_add(json_areas
,
6810 show_lsa_detail_proc(vty
, AREA_LSDB(area
, type
), id
,
6811 adv_router
, json_lsa_array
);
6815 json_lsa_type
= json_object_new_object();
6816 json_object_object_add(json_lsa_type
, "areas",
6818 json_object_object_add(json
,
6819 show_database_desc_json
[type
],
6826 static void show_lsa_detail_adv_router_proc(struct vty
*vty
,
6827 struct route_table
*rt
,
6828 struct in_addr
*adv_router
,
6831 struct route_node
*rn
;
6832 struct ospf_lsa
*lsa
;
6833 json_object
*json_lsa
= NULL
;
6835 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
))
6836 if ((lsa
= rn
->info
)) {
6837 if (IPV4_ADDR_SAME(adv_router
,
6838 &lsa
->data
->adv_router
)) {
6839 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
6842 json_lsa
= json_object_new_object();
6843 json_object_array_add(json
, json_lsa
);
6846 if (show_function
[lsa
->data
->type
] != NULL
)
6847 show_function
[lsa
->data
->type
](
6848 vty
, lsa
, json_lsa
);
6853 /* Show detail LSA information. */
6854 static void show_lsa_detail_adv_router(struct vty
*vty
, struct ospf
*ospf
,
6855 int type
, struct in_addr
*adv_router
,
6858 struct listnode
*node
;
6859 struct ospf_area
*area
;
6860 char buf
[PREFIX_STRLEN
];
6861 json_object
*json_lsa_type
= NULL
;
6862 json_object
*json_areas
= NULL
;
6863 json_object
*json_lsa_array
= NULL
;
6866 json_lsa_type
= json_object_new_object();
6869 case OSPF_AS_EXTERNAL_LSA
:
6870 case OSPF_OPAQUE_AS_LSA
:
6872 vty_out(vty
, " %s \n\n",
6873 show_database_desc
[type
]);
6875 json_lsa_array
= json_object_new_array();
6877 show_lsa_detail_adv_router_proc(vty
, AS_LSDB(ospf
, type
),
6878 adv_router
, json_lsa_array
);
6880 json_object_object_add(json
,
6881 show_database_desc_json
[type
],
6886 json_areas
= json_object_new_object();
6888 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6891 "\n %s (Area %s)\n\n",
6892 show_database_desc
[type
],
6893 ospf_area_desc_string(area
));
6895 json_lsa_array
= json_object_new_array();
6896 json_object_object_add(
6898 inet_ntop(AF_INET
, &area
->area_id
, buf
,
6903 show_lsa_detail_adv_router_proc(
6904 vty
, AREA_LSDB(area
, type
), adv_router
,
6909 json_object_object_add(json_lsa_type
, "areas",
6911 json_object_object_add(json
,
6912 show_database_desc_json
[type
],
6919 void show_ip_ospf_database_summary(struct vty
*vty
, struct ospf
*ospf
, int self
,
6922 struct ospf_lsa
*lsa
;
6923 struct route_node
*rn
;
6924 struct ospf_area
*area
;
6925 struct listnode
*node
;
6926 char buf
[PREFIX_STRLEN
];
6927 json_object
*json_areas
= NULL
;
6928 json_object
*json_area
= NULL
;
6929 json_object
*json_lsa
= NULL
;
6931 json_object
*json_lsa_array
= NULL
;
6935 json_areas
= json_object_new_object();
6937 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6939 json_area
= json_object_new_object();
6941 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6944 case OSPF_AS_EXTERNAL_LSA
:
6945 case OSPF_OPAQUE_AS_LSA
:
6950 if (ospf_lsdb_count_self(area
->lsdb
, type
) > 0
6952 && ospf_lsdb_count(area
->lsdb
, type
) > 0)) {
6956 " %s (Area %s)\n\n",
6957 show_database_desc
[type
],
6958 ospf_area_desc_string(area
));
6959 vty_out(vty
, "%s\n",
6960 show_database_header
[type
]);
6963 json_object_new_array();
6964 json_object_object_add(
6966 show_database_desc_json
[type
],
6970 LSDB_LOOP (AREA_LSDB(area
, type
), rn
, lsa
) {
6973 json_object_new_object();
6974 json_object_array_add(
6979 count
+= show_lsa_summary(
6980 vty
, lsa
, self
, json_lsa
);
6986 json_object_int_add(
6989 show_database_desc_count_json
6995 json_object_object_add(json_areas
,
7003 json_object_object_add(json
, "areas", json_areas
);
7005 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
7008 case OSPF_AS_EXTERNAL_LSA
:
7009 case OSPF_OPAQUE_AS_LSA
:
7014 if (ospf_lsdb_count_self(ospf
->lsdb
, type
)
7015 || (!self
&& ospf_lsdb_count(ospf
->lsdb
, type
))) {
7017 vty_out(vty
, " %s\n\n",
7018 show_database_desc
[type
]);
7019 vty_out(vty
, "%s\n",
7020 show_database_header
[type
]);
7022 json_lsa_array
= json_object_new_array();
7023 json_object_object_add(
7024 json
, show_database_desc_json
[type
],
7028 LSDB_LOOP (AS_LSDB(ospf
, type
), rn
, lsa
) {
7030 json_lsa
= json_object_new_object();
7031 json_object_array_add(json_lsa_array
,
7035 count
+= show_lsa_summary(vty
, lsa
, self
,
7042 json_object_int_add(
7044 show_database_desc_count_json
[type
],
7053 static void show_ip_ospf_database_maxage(struct vty
*vty
, struct ospf
*ospf
,
7056 struct route_node
*rn
;
7057 char buf
[PREFIX_STRLEN
];
7058 json_object
*json_maxage
= NULL
;
7061 vty_out(vty
, "\n MaxAge Link States:\n\n");
7063 json_maxage
= json_object_new_object();
7065 for (rn
= route_top(ospf
->maxage_lsa
); rn
; rn
= route_next(rn
)) {
7066 struct ospf_lsa
*lsa
;
7067 json_object
*json_lsa
= NULL
;
7069 if ((lsa
= rn
->info
) != NULL
) {
7071 vty_out(vty
, "Link type: %d\n",
7073 vty_out(vty
, "Link State ID: %pI4\n",
7075 vty_out(vty
, "Advertising Router: %pI4\n",
7076 &lsa
->data
->adv_router
);
7077 vty_out(vty
, "LSA lock count: %d\n", lsa
->lock
);
7080 json_lsa
= json_object_new_object();
7081 json_object_int_add(json_lsa
, "linkType",
7083 json_object_string_addf(json_lsa
, "linkStateId",
7084 "%pI4", &lsa
->data
->id
);
7085 json_object_string_addf(
7086 json_lsa
, "advertisingRouter", "%pI4",
7087 &lsa
->data
->adv_router
);
7088 json_object_int_add(json_lsa
, "lsaLockCount",
7090 json_object_object_add(
7100 json_object_object_add(json
, "maxAgeLinkStates", json_maxage
);
7103 #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
7104 #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
7106 #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
7107 #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
7108 #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
7109 #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
7111 #define OSPF_LSA_TYPES_DESC \
7112 "ASBR summary link states\n" \
7113 "External link states\n" \
7114 "Network link states\n" \
7115 "Router link states\n" \
7116 "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \
7117 OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
7118 OSPF_LSA_TYPE_OPAQUE_AS_DESC
7121 show_ip_ospf_database_common(struct vty
*vty
, struct ospf
*ospf
, bool maxage
,
7122 bool self
, bool detail
, const char *type_name
,
7123 struct in_addr
*lsid
, struct in_addr
*adv_router
,
7124 bool use_vrf
, json_object
*json
, bool uj
)
7127 json_object
*json_vrf
= NULL
;
7131 json_vrf
= json_object_new_object();
7136 if (ospf
->instance
) {
7138 json_object_int_add(json_vrf
, "ospfInstance",
7141 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
7144 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
7146 /* Show Router ID. */
7148 json_object_string_addf(json_vrf
, "routerId", "%pI4",
7151 vty_out(vty
, "\n OSPF Router with ID (%pI4)\n\n",
7155 /* Show MaxAge LSAs */
7157 show_ip_ospf_database_maxage(vty
, ospf
, json_vrf
);
7160 if (ospf
->vrf_id
== VRF_DEFAULT
)
7161 json_object_object_add(json
, "default",
7164 json_object_object_add(json
, ospf
->name
,
7171 /* Show all LSAs. */
7174 for (int i
= OSPF_ROUTER_LSA
; i
<= OSPF_OPAQUE_AS_LSA
;
7177 case OSPF_GROUP_MEMBER_LSA
:
7178 case OSPF_EXTERNAL_ATTRIBUTES_LSA
:
7179 /* ignore deprecated LSA types */
7185 if (adv_router
&& !lsid
)
7186 show_lsa_detail_adv_router(vty
, ospf
, i
,
7190 show_lsa_detail(vty
, ospf
, i
, lsid
,
7191 adv_router
, json_vrf
);
7194 show_ip_ospf_database_summary(vty
, ospf
, self
,
7199 if (ospf
->vrf_id
== VRF_DEFAULT
)
7200 json_object_object_add(json
, "default",
7203 json_object_object_add(json
, ospf
->name
,
7210 /* Set database type to show. */
7211 if (strncmp(type_name
, "r", 1) == 0)
7212 type
= OSPF_ROUTER_LSA
;
7213 else if (strncmp(type_name
, "ne", 2) == 0)
7214 type
= OSPF_NETWORK_LSA
;
7215 else if (strncmp(type_name
, "ns", 2) == 0)
7216 type
= OSPF_AS_NSSA_LSA
;
7217 else if (strncmp(type_name
, "su", 2) == 0)
7218 type
= OSPF_SUMMARY_LSA
;
7219 else if (strncmp(type_name
, "a", 1) == 0)
7220 type
= OSPF_ASBR_SUMMARY_LSA
;
7221 else if (strncmp(type_name
, "e", 1) == 0)
7222 type
= OSPF_AS_EXTERNAL_LSA
;
7223 else if (strncmp(type_name
, "opaque-l", 8) == 0)
7224 type
= OSPF_OPAQUE_LINK_LSA
;
7225 else if (strncmp(type_name
, "opaque-ar", 9) == 0)
7226 type
= OSPF_OPAQUE_AREA_LSA
;
7227 else if (strncmp(type_name
, "opaque-as", 9) == 0)
7228 type
= OSPF_OPAQUE_AS_LSA
;
7232 json_object_free(json_vrf
);
7237 if (adv_router
&& !lsid
)
7238 show_lsa_detail_adv_router(vty
, ospf
, type
, adv_router
,
7241 show_lsa_detail(vty
, ospf
, type
, lsid
, adv_router
, json_vrf
);
7245 if (ospf
->vrf_id
== VRF_DEFAULT
)
7246 json_object_object_add(json
, "default",
7249 json_object_object_add(json
, ospf
->name
,
7257 DEFPY (show_ip_ospf_database
,
7258 show_ip_ospf_database_cmd
,
7259 "show ip ospf [(1-65535)$instance_id] [vrf <NAME|all>$vrf_name] database\
7262 |self-originate$selforig\
7265 |<asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as>$type_name\
7269 |<adv-router A.B.C.D$adv_router|self-originate$adv_router_self>\
7275 "OSPF information\n"
7279 "Database summary\n"
7280 "LSAs in MaxAge list\n"
7281 "Self-originated link states\n"
7282 "Show detailed information\n"
7284 "Link State ID (as an IP address)\n"
7285 "Advertising Router link states\n"
7286 "Advertising Router (as an IP address)\n"
7287 "Self-originated link states\n"
7291 int ret
= CMD_SUCCESS
;
7292 bool use_vrf
= !!vrf_name
;
7293 bool uj
= use_json(argc
, argv
);
7294 struct in_addr
*lsid_p
= NULL
;
7295 struct in_addr
*adv_router_p
= NULL
;
7296 json_object
*json
= NULL
;
7299 json
= json_object_new_object();
7303 adv_router_p
= &adv_router
;
7305 if (vrf_name
&& strmatch(vrf_name
, "all")) {
7306 struct listnode
*node
;
7307 bool ospf_output
= false;
7309 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
7310 if (!ospf
->oi_running
)
7312 if (ospf
->instance
!= instance_id
)
7315 if (adv_router_self
)
7316 adv_router_p
= &ospf
->router_id
;
7319 ret
= show_ip_ospf_database_common(
7320 vty
, ospf
, !!maxage
, !!selforig
, !!detail
,
7321 type_name
, lsid_p
, adv_router_p
, use_vrf
, json
,
7325 if (!ospf_output
&& !uj
)
7326 vty_out(vty
, "%% OSPF is not enabled\n");
7329 vrf_name
= VRF_DEFAULT_NAME
;
7330 ospf
= ospf_lookup_by_inst_name(instance_id
, vrf_name
);
7331 if (ospf
== NULL
|| !ospf
->oi_running
) {
7333 vty_json(vty
, json
);
7335 vty_out(vty
, "%% OSPF instance not found\n");
7338 if (adv_router_self
)
7339 adv_router_p
= &ospf
->router_id
;
7341 ret
= (show_ip_ospf_database_common(
7342 vty
, ospf
, !!maxage
, !!selforig
, !!detail
, type_name
,
7343 lsid_p
, adv_router_p
, use_vrf
, json
, uj
));
7347 vty_json(vty
, json
);
7352 DEFUN (ip_ospf_authentication_args
,
7353 ip_ospf_authentication_args_addr_cmd
,
7354 "ip ospf authentication <null|message-digest> [A.B.C.D]",
7356 "OSPF interface commands\n"
7357 "Enable authentication on this interface\n"
7358 "Use null authentication\n"
7359 "Use message-digest authentication\n"
7360 "Address of interface\n")
7362 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7363 int idx_encryption
= 3;
7365 struct in_addr addr
;
7367 struct ospf_if_params
*params
;
7369 params
= IF_DEF_PARAMS(ifp
);
7372 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7375 "Please specify interface address by A.B.C.D\n");
7376 return CMD_WARNING_CONFIG_FAILED
;
7379 params
= ospf_get_if_params(ifp
, addr
);
7380 ospf_if_update_params(ifp
, addr
);
7383 /* Handle null authentication */
7384 if (argv
[idx_encryption
]->arg
[0] == 'n') {
7385 SET_IF_PARAM(params
, auth_type
);
7386 params
->auth_type
= OSPF_AUTH_NULL
;
7390 /* Handle message-digest authentication */
7391 if (argv
[idx_encryption
]->arg
[0] == 'm') {
7392 SET_IF_PARAM(params
, auth_type
);
7393 params
->auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
7397 vty_out(vty
, "You shouldn't get here!\n");
7398 return CMD_WARNING_CONFIG_FAILED
;
7401 DEFUN (ip_ospf_authentication
,
7402 ip_ospf_authentication_addr_cmd
,
7403 "ip ospf authentication [A.B.C.D]",
7405 "OSPF interface commands\n"
7406 "Enable authentication on this interface\n"
7407 "Address of interface\n")
7409 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7411 struct in_addr addr
;
7413 struct ospf_if_params
*params
;
7415 params
= IF_DEF_PARAMS(ifp
);
7418 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7421 "Please specify interface address by A.B.C.D\n");
7422 return CMD_WARNING_CONFIG_FAILED
;
7425 params
= ospf_get_if_params(ifp
, addr
);
7426 ospf_if_update_params(ifp
, addr
);
7429 SET_IF_PARAM(params
, auth_type
);
7430 params
->auth_type
= OSPF_AUTH_SIMPLE
;
7435 DEFUN (no_ip_ospf_authentication_args
,
7436 no_ip_ospf_authentication_args_addr_cmd
,
7437 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
7440 "OSPF interface commands\n"
7441 "Enable authentication on this interface\n"
7442 "Use null authentication\n"
7443 "Use message-digest authentication\n"
7444 "Address of interface\n")
7446 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7447 int idx_encryption
= 4;
7449 struct in_addr addr
;
7451 struct ospf_if_params
*params
;
7452 struct route_node
*rn
;
7455 params
= IF_DEF_PARAMS(ifp
);
7458 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7461 "Please specify interface address by A.B.C.D\n");
7462 return CMD_WARNING_CONFIG_FAILED
;
7465 params
= ospf_lookup_if_params(ifp
, addr
);
7466 if (params
== NULL
) {
7467 vty_out(vty
, "Ip Address specified is unknown\n");
7468 return CMD_WARNING_CONFIG_FAILED
;
7470 params
->auth_type
= OSPF_AUTH_NOTSET
;
7471 UNSET_IF_PARAM(params
, auth_type
);
7472 if (params
!= IF_DEF_PARAMS(ifp
)) {
7473 ospf_free_if_params(ifp
, addr
);
7474 ospf_if_update_params(ifp
, addr
);
7477 if (argv
[idx_encryption
]->arg
[0] == 'n') {
7478 auth_type
= OSPF_AUTH_NULL
;
7479 } else if (argv
[idx_encryption
]->arg
[0] == 'm') {
7480 auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
7482 vty_out(vty
, "Unexpected input encountered\n");
7483 return CMD_WARNING_CONFIG_FAILED
;
7486 * Here we have a case where the user has entered
7487 * 'no ip ospf authentication (null | message_digest )'
7488 * we need to find if we have any ip addresses underneath it
7490 * correspond to the associated type.
7492 if (params
->auth_type
== auth_type
) {
7493 params
->auth_type
= OSPF_AUTH_NOTSET
;
7494 UNSET_IF_PARAM(params
, auth_type
);
7497 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
7498 rn
= route_next(rn
)) {
7499 if ((params
= rn
->info
)) {
7500 if (params
->auth_type
== auth_type
) {
7501 params
->auth_type
= OSPF_AUTH_NOTSET
;
7502 UNSET_IF_PARAM(params
, auth_type
);
7503 if (params
!= IF_DEF_PARAMS(ifp
)) {
7504 ospf_free_if_params(
7505 ifp
, rn
->p
.u
.prefix4
);
7506 ospf_if_update_params(
7507 ifp
, rn
->p
.u
.prefix4
);
7517 DEFUN (no_ip_ospf_authentication
,
7518 no_ip_ospf_authentication_addr_cmd
,
7519 "no ip ospf authentication [A.B.C.D]",
7522 "OSPF interface commands\n"
7523 "Enable authentication on this interface\n"
7524 "Address of interface\n")
7526 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7528 struct in_addr addr
;
7530 struct ospf_if_params
*params
;
7531 struct route_node
*rn
;
7533 params
= IF_DEF_PARAMS(ifp
);
7536 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7539 "Please specify interface address by A.B.C.D\n");
7540 return CMD_WARNING_CONFIG_FAILED
;
7543 params
= ospf_lookup_if_params(ifp
, addr
);
7544 if (params
== NULL
) {
7545 vty_out(vty
, "Ip Address specified is unknown\n");
7546 return CMD_WARNING_CONFIG_FAILED
;
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(ifp
, addr
);
7553 ospf_if_update_params(ifp
, addr
);
7557 * When a user enters 'no ip ospf authentication'
7558 * We should remove all authentication types from
7561 if ((params
->auth_type
== OSPF_AUTH_NULL
)
7562 || (params
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
7563 || (params
->auth_type
== OSPF_AUTH_SIMPLE
)) {
7564 params
->auth_type
= OSPF_AUTH_NOTSET
;
7565 UNSET_IF_PARAM(params
, auth_type
);
7568 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
7569 rn
= route_next(rn
)) {
7570 if ((params
= rn
->info
)) {
7572 if ((params
->auth_type
== OSPF_AUTH_NULL
)
7573 || (params
->auth_type
7574 == OSPF_AUTH_CRYPTOGRAPHIC
)
7575 || (params
->auth_type
7576 == OSPF_AUTH_SIMPLE
)) {
7577 params
->auth_type
= OSPF_AUTH_NOTSET
;
7578 UNSET_IF_PARAM(params
, auth_type
);
7579 if (params
!= IF_DEF_PARAMS(ifp
)) {
7580 ospf_free_if_params(
7581 ifp
, rn
->p
.u
.prefix4
);
7582 ospf_if_update_params(
7583 ifp
, rn
->p
.u
.prefix4
);
7594 DEFUN (ip_ospf_authentication_key
,
7595 ip_ospf_authentication_key_addr_cmd
,
7596 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
7598 "OSPF interface commands\n"
7599 "Authentication password (key)\n"
7600 "The OSPF password (key)\n"
7601 "Address of interface\n")
7603 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7605 struct in_addr addr
;
7606 struct ospf_if_params
*params
;
7608 params
= IF_DEF_PARAMS(ifp
);
7610 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7611 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7613 "Please specify interface address by A.B.C.D\n");
7614 return CMD_WARNING_CONFIG_FAILED
;
7617 params
= ospf_get_if_params(ifp
, addr
);
7618 ospf_if_update_params(ifp
, addr
);
7621 strlcpy((char *)params
->auth_simple
, argv
[3]->arg
,
7622 sizeof(params
->auth_simple
));
7623 SET_IF_PARAM(params
, auth_simple
);
7628 DEFUN_HIDDEN (ospf_authentication_key
,
7629 ospf_authentication_key_cmd
,
7630 "ospf authentication-key AUTH_KEY [A.B.C.D]",
7631 "OSPF interface commands\n"
7632 VLINK_HELPSTR_AUTH_SIMPLE
7633 "Address of interface\n")
7635 return ip_ospf_authentication_key(self
, vty
, argc
, argv
);
7638 DEFUN (no_ip_ospf_authentication_key
,
7639 no_ip_ospf_authentication_key_authkey_addr_cmd
,
7640 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7643 "OSPF interface commands\n"
7644 VLINK_HELPSTR_AUTH_SIMPLE
7645 "Address of interface\n")
7647 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7649 struct in_addr addr
;
7650 struct ospf_if_params
*params
;
7651 params
= IF_DEF_PARAMS(ifp
);
7653 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7654 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7656 "Please specify interface address by A.B.C.D\n");
7657 return CMD_WARNING_CONFIG_FAILED
;
7660 params
= ospf_lookup_if_params(ifp
, addr
);
7665 memset(params
->auth_simple
, 0, OSPF_AUTH_SIMPLE_SIZE
);
7666 UNSET_IF_PARAM(params
, auth_simple
);
7668 if (params
!= IF_DEF_PARAMS(ifp
)) {
7669 ospf_free_if_params(ifp
, addr
);
7670 ospf_if_update_params(ifp
, addr
);
7676 DEFUN_HIDDEN (no_ospf_authentication_key
,
7677 no_ospf_authentication_key_authkey_addr_cmd
,
7678 "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7680 "OSPF interface commands\n"
7681 VLINK_HELPSTR_AUTH_SIMPLE
7682 "Address of interface\n")
7684 return no_ip_ospf_authentication_key(self
, vty
, argc
, argv
);
7687 DEFUN (ip_ospf_message_digest_key
,
7688 ip_ospf_message_digest_key_cmd
,
7689 "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7691 "OSPF interface commands\n"
7692 "Message digest authentication password (key)\n"
7694 "Use MD5 algorithm\n"
7695 "The OSPF password (key)\n"
7696 "Address of interface\n")
7698 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7699 struct crypt_key
*ck
;
7701 struct in_addr addr
;
7702 struct ospf_if_params
*params
;
7704 params
= IF_DEF_PARAMS(ifp
);
7707 argv_find(argv
, argc
, "(1-255)", &idx
);
7708 char *keyid
= argv
[idx
]->arg
;
7709 argv_find(argv
, argc
, "KEY", &idx
);
7710 char *cryptkey
= argv
[idx
]->arg
;
7712 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7713 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7715 "Please specify interface address by A.B.C.D\n");
7716 return CMD_WARNING_CONFIG_FAILED
;
7719 params
= ospf_get_if_params(ifp
, addr
);
7720 ospf_if_update_params(ifp
, addr
);
7723 key_id
= strtol(keyid
, NULL
, 10);
7725 /* Remove existing key, if any */
7726 ospf_crypt_key_delete(params
->auth_crypt
, key_id
);
7728 ck
= ospf_crypt_key_new();
7729 ck
->key_id
= (uint8_t)key_id
;
7730 strlcpy((char *)ck
->auth_key
, cryptkey
, sizeof(ck
->auth_key
));
7732 ospf_crypt_key_add(params
->auth_crypt
, ck
);
7733 SET_IF_PARAM(params
, auth_crypt
);
7738 DEFUN_HIDDEN (ospf_message_digest_key
,
7739 ospf_message_digest_key_cmd
,
7740 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7741 "OSPF interface commands\n"
7742 "Message digest authentication password (key)\n"
7744 "Use MD5 algorithm\n"
7745 "The OSPF password (key)\n"
7746 "Address of interface\n")
7748 return ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7751 DEFUN (no_ip_ospf_message_digest_key
,
7752 no_ip_ospf_message_digest_key_cmd
,
7753 "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7756 "OSPF interface commands\n"
7757 "Message digest authentication password (key)\n"
7759 "Use MD5 algorithm\n"
7760 "The OSPF password (key)\n"
7761 "Address of interface\n")
7763 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7765 struct crypt_key
*ck
;
7767 struct in_addr addr
;
7768 struct ospf_if_params
*params
;
7769 params
= IF_DEF_PARAMS(ifp
);
7771 argv_find(argv
, argc
, "(1-255)", &idx
);
7772 char *keyid
= argv
[idx
]->arg
;
7774 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7775 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7777 "Please specify interface address by A.B.C.D\n");
7778 return CMD_WARNING_CONFIG_FAILED
;
7781 params
= ospf_lookup_if_params(ifp
, addr
);
7786 key_id
= strtol(keyid
, NULL
, 10);
7787 ck
= ospf_crypt_key_lookup(params
->auth_crypt
, key_id
);
7789 vty_out(vty
, "OSPF: Key %d does not exist\n", key_id
);
7790 return CMD_WARNING_CONFIG_FAILED
;
7793 ospf_crypt_key_delete(params
->auth_crypt
, key_id
);
7795 if (params
!= IF_DEF_PARAMS(ifp
)) {
7796 ospf_free_if_params(ifp
, addr
);
7797 ospf_if_update_params(ifp
, addr
);
7803 DEFUN_HIDDEN (no_ospf_message_digest_key
,
7804 no_ospf_message_digest_key_cmd
,
7805 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7807 "OSPF interface commands\n"
7808 "Message digest authentication password (key)\n"
7810 "Use MD5 algorithm\n"
7811 "The OSPF password (key)\n"
7812 "Address of interface\n")
7814 return no_ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7817 DEFUN (ip_ospf_cost
,
7819 "ip ospf cost (1-65535) [A.B.C.D]",
7821 "OSPF interface commands\n"
7824 "Address of interface\n")
7826 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7828 uint32_t cost
= OSPF_OUTPUT_COST_DEFAULT
;
7829 struct in_addr addr
;
7830 struct ospf_if_params
*params
;
7831 params
= IF_DEF_PARAMS(ifp
);
7834 char *coststr
= NULL
, *ifaddr
= NULL
;
7836 argv_find(argv
, argc
, "(1-65535)", &idx
);
7837 coststr
= argv
[idx
]->arg
;
7838 cost
= strtol(coststr
, NULL
, 10);
7840 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7842 if (!inet_aton(ifaddr
, &addr
)) {
7844 "Please specify interface address by A.B.C.D\n");
7845 return CMD_WARNING_CONFIG_FAILED
;
7848 params
= ospf_get_if_params(ifp
, addr
);
7849 ospf_if_update_params(ifp
, addr
);
7852 SET_IF_PARAM(params
, output_cost_cmd
);
7853 params
->output_cost_cmd
= cost
;
7855 ospf_if_recalculate_output_cost(ifp
);
7860 DEFUN_HIDDEN (ospf_cost
,
7862 "ospf cost (1-65535) [A.B.C.D]",
7863 "OSPF interface commands\n"
7866 "Address of interface\n")
7868 return ip_ospf_cost(self
, vty
, argc
, argv
);
7871 DEFUN (no_ip_ospf_cost
,
7872 no_ip_ospf_cost_cmd
,
7873 "no ip ospf cost [(1-65535)] [A.B.C.D]",
7876 "OSPF interface commands\n"
7879 "Address of interface\n")
7881 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7883 struct in_addr addr
;
7884 struct ospf_if_params
*params
;
7886 params
= IF_DEF_PARAMS(ifp
);
7889 char *ifaddr
= NULL
;
7890 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7892 /* According to the semantics we are mimicking "no ip ospf cost N" is
7893 * always treated as "no ip ospf cost" regardless of the actual value
7894 * of N already configured for the interface. Thus ignore cost. */
7897 if (!inet_aton(ifaddr
, &addr
)) {
7899 "Please specify interface address by A.B.C.D\n");
7900 return CMD_WARNING_CONFIG_FAILED
;
7903 params
= ospf_lookup_if_params(ifp
, addr
);
7908 UNSET_IF_PARAM(params
, output_cost_cmd
);
7910 if (params
!= IF_DEF_PARAMS(ifp
)) {
7911 ospf_free_if_params(ifp
, addr
);
7912 ospf_if_update_params(ifp
, addr
);
7915 ospf_if_recalculate_output_cost(ifp
);
7920 DEFUN_HIDDEN (no_ospf_cost
,
7922 "no ospf cost [(1-65535)] [A.B.C.D]",
7924 "OSPF interface commands\n"
7927 "Address of interface\n")
7929 return no_ip_ospf_cost(self
, vty
, argc
, argv
);
7932 static void ospf_nbr_timer_update(struct ospf_interface
*oi
)
7934 struct route_node
*rn
;
7935 struct ospf_neighbor
*nbr
;
7937 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
7943 nbr
->v_inactivity
= OSPF_IF_PARAM(oi
, v_wait
);
7944 nbr
->v_db_desc
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7945 nbr
->v_ls_req
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7946 nbr
->v_ls_upd
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7950 static int ospf_vty_dead_interval_set(struct vty
*vty
, const char *interval_str
,
7951 const char *nbr_str
,
7952 const char *fast_hello_str
)
7954 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7957 struct in_addr addr
;
7959 struct ospf_if_params
*params
;
7960 struct ospf_interface
*oi
;
7961 struct route_node
*rn
;
7963 params
= IF_DEF_PARAMS(ifp
);
7966 ret
= inet_aton(nbr_str
, &addr
);
7969 "Please specify interface address by A.B.C.D\n");
7970 return CMD_WARNING_CONFIG_FAILED
;
7973 params
= ospf_get_if_params(ifp
, addr
);
7974 ospf_if_update_params(ifp
, addr
);
7978 seconds
= strtoul(interval_str
, NULL
, 10);
7980 /* reset fast_hello too, just to be sure */
7981 UNSET_IF_PARAM(params
, fast_hello
);
7982 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
7983 } else if (fast_hello_str
) {
7984 hellomult
= strtoul(fast_hello_str
, NULL
, 10);
7985 /* 1s dead-interval with sub-second hellos desired */
7986 seconds
= OSPF_ROUTER_DEAD_INTERVAL_MINIMAL
;
7987 SET_IF_PARAM(params
, fast_hello
);
7988 params
->fast_hello
= hellomult
;
7991 "Please specify dead-interval or hello-multiplier\n");
7992 return CMD_WARNING_CONFIG_FAILED
;
7995 SET_IF_PARAM(params
, v_wait
);
7996 params
->v_wait
= seconds
;
7997 params
->is_v_wait_set
= true;
7999 /* Update timer values in neighbor structure. */
8001 struct ospf
*ospf
= NULL
;
8003 ospf
= ifp
->vrf
->info
;
8005 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
8007 ospf_nbr_timer_update(oi
);
8010 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
8011 if ((oi
= rn
->info
))
8012 ospf_nbr_timer_update(oi
);
8018 DEFUN (ip_ospf_dead_interval
,
8019 ip_ospf_dead_interval_cmd
,
8020 "ip ospf dead-interval (1-65535) [A.B.C.D]",
8022 "OSPF interface commands\n"
8023 "Interval time after which a neighbor is declared down\n"
8025 "Address of interface\n")
8028 char *interval
= argv_find(argv
, argc
, "(1-65535)", &idx
)
8032 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
8033 return ospf_vty_dead_interval_set(vty
, interval
, ifaddr
, NULL
);
8037 DEFUN_HIDDEN (ospf_dead_interval
,
8038 ospf_dead_interval_cmd
,
8039 "ospf dead-interval (1-65535) [A.B.C.D]",
8040 "OSPF interface commands\n"
8041 "Interval time after which a neighbor is declared down\n"
8043 "Address of interface\n")
8045 return ip_ospf_dead_interval(self
, vty
, argc
, argv
);
8048 DEFUN (ip_ospf_dead_interval_minimal
,
8049 ip_ospf_dead_interval_minimal_addr_cmd
,
8050 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
8052 "OSPF interface commands\n"
8053 "Interval time after which a neighbor is declared down\n"
8054 "Minimal 1s dead-interval with fast sub-second hellos\n"
8055 "Hello multiplier factor\n"
8056 "Number of Hellos to send each second\n"
8057 "Address of interface\n")
8062 return ospf_vty_dead_interval_set(
8063 vty
, NULL
, argv
[idx_ipv4
]->arg
, argv
[idx_number
]->arg
);
8065 return ospf_vty_dead_interval_set(vty
, NULL
, NULL
,
8066 argv
[idx_number
]->arg
);
8069 DEFUN (no_ip_ospf_dead_interval
,
8070 no_ip_ospf_dead_interval_cmd
,
8071 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8074 "OSPF interface commands\n"
8075 "Interval time after which a neighbor is declared down\n"
8077 "Minimal 1s dead-interval with fast sub-second hellos\n"
8078 "Hello multiplier factor\n"
8079 "Number of Hellos to send each second\n"
8080 "Address of interface\n")
8082 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8083 int idx_ipv4
= argc
- 1;
8084 struct in_addr addr
= {.s_addr
= 0L};
8086 struct ospf_if_params
*params
;
8087 struct ospf_interface
*oi
;
8088 struct route_node
*rn
;
8090 params
= IF_DEF_PARAMS(ifp
);
8092 if (argv
[idx_ipv4
]->type
== IPV4_TKN
) {
8093 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8096 "Please specify interface address by A.B.C.D\n");
8097 return CMD_WARNING_CONFIG_FAILED
;
8100 params
= ospf_lookup_if_params(ifp
, addr
);
8105 UNSET_IF_PARAM(params
, v_wait
);
8106 params
->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
8107 params
->is_v_wait_set
= false;
8109 UNSET_IF_PARAM(params
, fast_hello
);
8110 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
8112 if (params
!= IF_DEF_PARAMS(ifp
)) {
8113 ospf_free_if_params(ifp
, addr
);
8114 ospf_if_update_params(ifp
, addr
);
8117 /* Update timer values in neighbor structure. */
8119 struct ospf
*ospf
= NULL
;
8121 ospf
= ifp
->vrf
->info
;
8123 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
8125 ospf_nbr_timer_update(oi
);
8128 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
8129 if ((oi
= rn
->info
))
8130 ospf_nbr_timer_update(oi
);
8136 DEFUN_HIDDEN (no_ospf_dead_interval
,
8137 no_ospf_dead_interval_cmd
,
8138 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8140 "OSPF interface commands\n"
8141 "Interval time after which a neighbor is declared down\n"
8143 "Minimal 1s dead-interval with fast sub-second hellos\n"
8144 "Hello multiplier factor\n"
8145 "Number of Hellos to send each second\n"
8146 "Address of interface\n")
8148 return no_ip_ospf_dead_interval(self
, vty
, argc
, argv
);
8151 DEFUN (ip_ospf_hello_interval
,
8152 ip_ospf_hello_interval_cmd
,
8153 "ip ospf hello-interval (1-65535) [A.B.C.D]",
8155 "OSPF interface commands\n"
8156 "Time between HELLO packets\n"
8158 "Address of interface\n")
8160 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8162 struct in_addr addr
= {.s_addr
= 0L};
8163 struct ospf_if_params
*params
;
8164 params
= IF_DEF_PARAMS(ifp
);
8165 uint32_t seconds
= 0;
8166 bool is_addr
= false;
8167 uint32_t old_interval
= 0;
8169 argv_find(argv
, argc
, "(1-65535)", &idx
);
8170 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
8172 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8173 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8175 "Please specify interface address by A.B.C.D\n");
8176 return CMD_WARNING_CONFIG_FAILED
;
8179 params
= ospf_get_if_params(ifp
, addr
);
8180 ospf_if_update_params(ifp
, addr
);
8184 old_interval
= params
->v_hello
;
8186 /* Return, if same interval is configured. */
8187 if (old_interval
== seconds
)
8190 SET_IF_PARAM(params
, v_hello
);
8191 params
->v_hello
= seconds
;
8193 if (!params
->is_v_wait_set
) {
8194 SET_IF_PARAM(params
, v_wait
);
8196 * The router dead interval should
8197 * be some multiple of the HelloInterval (perhaps 4 times the
8198 * hello interval) and must be the same for all routers
8199 * attached to a common network.
8201 params
->v_wait
= 4 * seconds
;
8204 ospf_reset_hello_timer(ifp
, addr
, is_addr
);
8209 DEFUN_HIDDEN (ospf_hello_interval
,
8210 ospf_hello_interval_cmd
,
8211 "ospf hello-interval (1-65535) [A.B.C.D]",
8212 "OSPF interface commands\n"
8213 "Time between HELLO packets\n"
8215 "Address of interface\n")
8217 return ip_ospf_hello_interval(self
, vty
, argc
, argv
);
8220 DEFUN (no_ip_ospf_hello_interval
,
8221 no_ip_ospf_hello_interval_cmd
,
8222 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
8225 "OSPF interface commands\n"
8226 "Time between HELLO packets\n" // ignored
8228 "Address of interface\n")
8230 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8232 struct in_addr addr
= {.s_addr
= 0L};
8233 struct ospf_if_params
*params
;
8234 struct route_node
*rn
;
8236 params
= IF_DEF_PARAMS(ifp
);
8238 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8239 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8241 "Please specify interface address by A.B.C.D\n");
8242 return CMD_WARNING_CONFIG_FAILED
;
8245 params
= ospf_lookup_if_params(ifp
, addr
);
8250 UNSET_IF_PARAM(params
, v_hello
);
8251 params
->v_hello
= OSPF_HELLO_INTERVAL_DEFAULT
;
8253 if (!params
->is_v_wait_set
) {
8254 UNSET_IF_PARAM(params
, v_wait
);
8255 params
->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
8258 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8259 struct ospf_interface
*oi
= rn
->info
;
8264 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
8265 oi
->ptp_dmvpn
= IF_DEF_PARAMS(ifp
)->ptp_dmvpn
;
8267 if (oi
->state
> ISM_Down
) {
8268 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
8269 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
8273 if (params
!= IF_DEF_PARAMS(ifp
)) {
8274 ospf_free_if_params(ifp
, addr
);
8275 ospf_if_update_params(ifp
, addr
);
8281 DEFUN_HIDDEN (no_ospf_hello_interval
,
8282 no_ospf_hello_interval_cmd
,
8283 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
8285 "OSPF interface commands\n"
8286 "Time between HELLO packets\n" // ignored
8288 "Address of interface\n")
8290 return no_ip_ospf_hello_interval(self
, vty
, argc
, argv
);
8293 DEFUN(ip_ospf_network
, ip_ospf_network_cmd
,
8294 "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point [dmvpn]>",
8296 "OSPF interface commands\n"
8298 "Specify OSPF broadcast multi-access network\n"
8299 "Specify OSPF NBMA network\n"
8300 "Specify OSPF point-to-multipoint network\n"
8301 "Specify OSPF point-to-point network\n"
8302 "Specify OSPF point-to-point DMVPN network\n")
8304 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8306 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
8307 uint8_t old_ptp_dmvpn
= IF_DEF_PARAMS(ifp
)->ptp_dmvpn
;
8308 struct route_node
*rn
;
8310 if (old_type
== OSPF_IFTYPE_LOOPBACK
) {
8312 "This is a loopback interface. Can't set network type.\n");
8313 return CMD_WARNING_CONFIG_FAILED
;
8316 IF_DEF_PARAMS(ifp
)->ptp_dmvpn
= 0;
8318 if (argv_find(argv
, argc
, "broadcast", &idx
))
8319 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_BROADCAST
;
8320 else if (argv_find(argv
, argc
, "non-broadcast", &idx
))
8321 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_NBMA
;
8322 else if (argv_find(argv
, argc
, "point-to-multipoint", &idx
))
8323 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOMULTIPOINT
;
8324 else if (argv_find(argv
, argc
, "point-to-point", &idx
)) {
8325 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOPOINT
;
8326 if (argv_find(argv
, argc
, "dmvpn", &idx
))
8327 IF_DEF_PARAMS(ifp
)->ptp_dmvpn
= 1;
8330 if (IF_DEF_PARAMS(ifp
)->type
== old_type
8331 && IF_DEF_PARAMS(ifp
)->ptp_dmvpn
== old_ptp_dmvpn
)
8334 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), type
);
8336 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8337 struct ospf_interface
*oi
= rn
->info
;
8342 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
8344 if (oi
->state
> ISM_Down
) {
8345 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
8346 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
8353 DEFUN_HIDDEN (ospf_network
,
8355 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
8356 "OSPF interface commands\n"
8358 "Specify OSPF broadcast multi-access network\n"
8359 "Specify OSPF NBMA network\n"
8360 "Specify OSPF point-to-multipoint network\n"
8361 "Specify OSPF point-to-point network\n")
8363 return ip_ospf_network(self
, vty
, argc
, argv
);
8366 DEFUN (no_ip_ospf_network
,
8367 no_ip_ospf_network_cmd
,
8368 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8371 "OSPF interface commands\n"
8373 "Specify OSPF broadcast multi-access network\n"
8374 "Specify OSPF NBMA network\n"
8375 "Specify OSPF point-to-multipoint network\n"
8376 "Specify OSPF point-to-point network\n")
8378 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8379 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
8380 struct route_node
*rn
;
8382 IF_DEF_PARAMS(ifp
)->type
= ospf_default_iftype(ifp
);
8383 IF_DEF_PARAMS(ifp
)->ptp_dmvpn
= 0;
8385 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
8388 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8389 struct ospf_interface
*oi
= rn
->info
;
8394 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
8396 if (oi
->state
> ISM_Down
) {
8397 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
8398 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
8405 DEFUN_HIDDEN (no_ospf_network
,
8406 no_ospf_network_cmd
,
8407 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8409 "OSPF interface commands\n"
8411 "Specify OSPF broadcast multi-access network\n"
8412 "Specify OSPF NBMA network\n"
8413 "Specify OSPF point-to-multipoint network\n"
8414 "Specify OSPF point-to-point network\n")
8416 return no_ip_ospf_network(self
, vty
, argc
, argv
);
8419 DEFUN (ip_ospf_priority
,
8420 ip_ospf_priority_cmd
,
8421 "ip ospf priority (0-255) [A.B.C.D]",
8423 "OSPF interface commands\n"
8426 "Address of interface\n")
8428 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8431 struct route_node
*rn
;
8432 struct in_addr addr
;
8433 struct ospf_if_params
*params
;
8434 params
= IF_DEF_PARAMS(ifp
);
8436 argv_find(argv
, argc
, "(0-255)", &idx
);
8437 priority
= strtol(argv
[idx
]->arg
, NULL
, 10);
8439 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8440 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8442 "Please specify interface address by A.B.C.D\n");
8443 return CMD_WARNING_CONFIG_FAILED
;
8446 params
= ospf_get_if_params(ifp
, addr
);
8447 ospf_if_update_params(ifp
, addr
);
8450 SET_IF_PARAM(params
, priority
);
8451 params
->priority
= priority
;
8453 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8454 struct ospf_interface
*oi
= rn
->info
;
8459 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
8460 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
8461 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
8468 DEFUN_HIDDEN (ospf_priority
,
8470 "ospf priority (0-255) [A.B.C.D]",
8471 "OSPF interface commands\n"
8474 "Address of interface\n")
8476 return ip_ospf_priority(self
, vty
, argc
, argv
);
8479 DEFUN (no_ip_ospf_priority
,
8480 no_ip_ospf_priority_cmd
,
8481 "no ip ospf priority [(0-255) [A.B.C.D]]",
8484 "OSPF interface commands\n"
8485 "Router priority\n" // ignored
8487 "Address of interface\n")
8489 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8491 struct route_node
*rn
;
8492 struct in_addr addr
;
8493 struct ospf_if_params
*params
;
8495 params
= IF_DEF_PARAMS(ifp
);
8497 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8498 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8500 "Please specify interface address by A.B.C.D\n");
8501 return CMD_WARNING_CONFIG_FAILED
;
8504 params
= ospf_lookup_if_params(ifp
, addr
);
8509 UNSET_IF_PARAM(params
, priority
);
8510 params
->priority
= OSPF_ROUTER_PRIORITY_DEFAULT
;
8512 if (params
!= IF_DEF_PARAMS(ifp
)) {
8513 ospf_free_if_params(ifp
, addr
);
8514 ospf_if_update_params(ifp
, addr
);
8517 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8518 struct ospf_interface
*oi
= rn
->info
;
8523 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
8524 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
8525 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
8532 DEFUN_HIDDEN (no_ospf_priority
,
8533 no_ospf_priority_cmd
,
8534 "no ospf priority [(0-255) [A.B.C.D]]",
8536 "OSPF interface commands\n"
8539 "Address of interface\n")
8541 return no_ip_ospf_priority(self
, vty
, argc
, argv
);
8544 DEFUN (ip_ospf_retransmit_interval
,
8545 ip_ospf_retransmit_interval_addr_cmd
,
8546 "ip ospf retransmit-interval (1-65535) [A.B.C.D]",
8548 "OSPF interface commands\n"
8549 "Time between retransmitting lost link state advertisements\n"
8551 "Address of interface\n")
8553 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8556 struct in_addr addr
;
8557 struct ospf_if_params
*params
;
8558 params
= IF_DEF_PARAMS(ifp
);
8560 argv_find(argv
, argc
, "(1-65535)", &idx
);
8561 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
8563 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8564 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8566 "Please specify interface address by A.B.C.D\n");
8567 return CMD_WARNING_CONFIG_FAILED
;
8570 params
= ospf_get_if_params(ifp
, addr
);
8571 ospf_if_update_params(ifp
, addr
);
8574 SET_IF_PARAM(params
, retransmit_interval
);
8575 params
->retransmit_interval
= seconds
;
8580 DEFUN_HIDDEN (ospf_retransmit_interval
,
8581 ospf_retransmit_interval_cmd
,
8582 "ospf retransmit-interval (1-65535) [A.B.C.D]",
8583 "OSPF interface commands\n"
8584 "Time between retransmitting lost link state advertisements\n"
8586 "Address of interface\n")
8588 return ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
8591 DEFUN (no_ip_ospf_retransmit_interval
,
8592 no_ip_ospf_retransmit_interval_addr_cmd
,
8593 "no ip ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8596 "OSPF interface commands\n"
8597 "Time between retransmitting lost link state advertisements\n"
8599 "Address of interface\n")
8601 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8603 struct in_addr addr
;
8604 struct ospf_if_params
*params
;
8606 params
= IF_DEF_PARAMS(ifp
);
8608 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8609 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8611 "Please specify interface address by A.B.C.D\n");
8612 return CMD_WARNING_CONFIG_FAILED
;
8615 params
= ospf_lookup_if_params(ifp
, addr
);
8620 UNSET_IF_PARAM(params
, retransmit_interval
);
8621 params
->retransmit_interval
= OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
8623 if (params
!= IF_DEF_PARAMS(ifp
)) {
8624 ospf_free_if_params(ifp
, addr
);
8625 ospf_if_update_params(ifp
, addr
);
8631 DEFUN_HIDDEN (no_ospf_retransmit_interval
,
8632 no_ospf_retransmit_interval_cmd
,
8633 "no ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8635 "OSPF interface commands\n"
8636 "Time between retransmitting lost link state advertisements\n"
8638 "Address of interface\n")
8640 return no_ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
8643 DEFUN (ip_ospf_transmit_delay
,
8644 ip_ospf_transmit_delay_addr_cmd
,
8645 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
8647 "OSPF interface commands\n"
8648 "Link state transmit delay\n"
8650 "Address of interface\n")
8652 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8655 struct in_addr addr
;
8656 struct ospf_if_params
*params
;
8658 params
= IF_DEF_PARAMS(ifp
);
8659 argv_find(argv
, argc
, "(1-65535)", &idx
);
8660 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
8662 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8663 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8665 "Please specify interface address by A.B.C.D\n");
8666 return CMD_WARNING_CONFIG_FAILED
;
8669 params
= ospf_get_if_params(ifp
, addr
);
8670 ospf_if_update_params(ifp
, addr
);
8673 SET_IF_PARAM(params
, transmit_delay
);
8674 params
->transmit_delay
= seconds
;
8679 DEFUN_HIDDEN (ospf_transmit_delay
,
8680 ospf_transmit_delay_cmd
,
8681 "ospf transmit-delay (1-65535) [A.B.C.D]",
8682 "OSPF interface commands\n"
8683 "Link state transmit delay\n"
8685 "Address of interface\n")
8687 return ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
8690 DEFUN (no_ip_ospf_transmit_delay
,
8691 no_ip_ospf_transmit_delay_addr_cmd
,
8692 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
8695 "OSPF interface commands\n"
8696 "Link state transmit delay\n"
8698 "Address of interface\n")
8700 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8702 struct in_addr addr
;
8703 struct ospf_if_params
*params
;
8705 params
= IF_DEF_PARAMS(ifp
);
8707 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8708 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8710 "Please specify interface address by A.B.C.D\n");
8711 return CMD_WARNING_CONFIG_FAILED
;
8714 params
= ospf_lookup_if_params(ifp
, addr
);
8719 UNSET_IF_PARAM(params
, transmit_delay
);
8720 params
->transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
8722 if (params
!= IF_DEF_PARAMS(ifp
)) {
8723 ospf_free_if_params(ifp
, addr
);
8724 ospf_if_update_params(ifp
, addr
);
8731 DEFUN_HIDDEN (no_ospf_transmit_delay
,
8732 no_ospf_transmit_delay_cmd
,
8733 "no ospf transmit-delay [(1-65535) [A.B.C.D]]",
8735 "OSPF interface commands\n"
8736 "Link state transmit delay\n"
8738 "Address of interface\n")
8740 return no_ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
8743 DEFUN (ip_ospf_area
,
8745 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]",
8747 "OSPF interface commands\n"
8749 "Enable OSPF on this interface\n"
8750 "OSPF area ID in IP address format\n"
8751 "OSPF area ID as a decimal value\n"
8752 "Address of interface\n")
8754 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8757 struct in_addr area_id
;
8758 struct in_addr addr
;
8759 struct ospf_if_params
*params
= NULL
;
8760 struct route_node
*rn
;
8761 struct ospf
*ospf
= NULL
;
8762 unsigned short instance
= 0;
8766 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
8767 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
8769 argv_find(argv
, argc
, "area", &idx
);
8770 areaid
= argv
[idx
+ 1]->arg
;
8773 ospf
= ifp
->vrf
->info
;
8775 ospf
= ospf_lookup_instance(instance
);
8777 if (instance
&& instance
!= ospf_instance
) {
8779 * At this point we know we have received
8780 * an instance and there is no ospf instance
8781 * associated with it. This means we are
8782 * in a situation where we have an
8783 * ospf command that is setup for a different
8784 * process(instance). We need to safely
8785 * remove the command from ourselves and
8786 * allow the other instance(process) handle
8787 * the configuration command.
8791 params
= IF_DEF_PARAMS(ifp
);
8792 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8793 UNSET_IF_PARAM(params
, if_area
);
8797 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
; rn
= route_next(rn
))
8798 if ((params
= rn
->info
) && OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8799 UNSET_IF_PARAM(params
, if_area
);
8804 ospf
= ifp
->vrf
->info
;
8806 ospf_interface_area_unset(ospf
, ifp
);
8809 return CMD_NOT_MY_INSTANCE
;
8812 ret
= str2area_id(areaid
, &area_id
, &format
);
8814 vty_out(vty
, "Please specify area by A.B.C.D|<0-4294967295>\n");
8815 return CMD_WARNING_CONFIG_FAILED
;
8817 if (memcmp(ifp
->name
, "VLINK", 5) == 0) {
8818 vty_out(vty
, "Cannot enable OSPF on a virtual link.\n");
8819 return CMD_WARNING_CONFIG_FAILED
;
8823 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
)) {
8824 if (rn
->info
!= NULL
) {
8826 "Please remove all network commands first.\n");
8827 return CMD_WARNING_CONFIG_FAILED
;
8832 params
= IF_DEF_PARAMS(ifp
);
8833 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)
8834 && !IPV4_ADDR_SAME(¶ms
->if_area
, &area_id
)) {
8836 "Must remove previous area config before changing ospf area \n");
8837 return CMD_WARNING_CONFIG_FAILED
;
8840 // Check if we have an address arg and proccess it
8841 if (argc
== idx
+ 3) {
8842 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
8844 "Please specify Intf Address by A.B.C.D\n");
8845 return CMD_WARNING_CONFIG_FAILED
;
8847 // update/create address-level params
8848 params
= ospf_get_if_params((ifp
), (addr
));
8849 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8850 if (!IPV4_ADDR_SAME(¶ms
->if_area
, &area_id
)) {
8852 "Must remove previous area/address config before changing ospf area\n");
8853 return CMD_WARNING_CONFIG_FAILED
;
8857 ospf_if_update_params((ifp
), (addr
));
8860 /* enable ospf on this interface with area_id */
8862 SET_IF_PARAM(params
, if_area
);
8863 params
->if_area
= area_id
;
8864 params
->if_area_id_fmt
= format
;
8868 ospf_interface_area_set(ospf
, ifp
);
8873 DEFUN (no_ip_ospf_area
,
8874 no_ip_ospf_area_cmd
,
8875 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]",
8878 "OSPF interface commands\n"
8880 "Disable OSPF on this interface\n"
8881 "OSPF area ID in IP address format\n"
8882 "OSPF area ID as a decimal value\n"
8883 "Address of interface\n")
8885 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8888 struct ospf_if_params
*params
;
8889 unsigned short instance
= 0;
8890 struct in_addr addr
;
8891 struct in_addr area_id
;
8893 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
8894 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
8897 ospf
= ifp
->vrf
->info
;
8899 ospf
= ospf_lookup_instance(instance
);
8901 if (instance
&& instance
!= ospf_instance
)
8902 return CMD_NOT_MY_INSTANCE
;
8904 argv_find(argv
, argc
, "area", &idx
);
8906 // Check if we have an address arg and proccess it
8907 if (argc
== idx
+ 3) {
8908 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
8910 "Please specify Intf Address by A.B.C.D\n");
8911 return CMD_WARNING_CONFIG_FAILED
;
8913 params
= ospf_lookup_if_params(ifp
, addr
);
8914 if ((params
) == NULL
)
8917 params
= IF_DEF_PARAMS(ifp
);
8919 area_id
= params
->if_area
;
8920 if (!OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8922 "Can't find specified interface area configuration.\n");
8923 return CMD_WARNING_CONFIG_FAILED
;
8926 UNSET_IF_PARAM(params
, if_area
);
8927 if (params
!= IF_DEF_PARAMS((ifp
))) {
8928 ospf_free_if_params((ifp
), (addr
));
8929 ospf_if_update_params((ifp
), (addr
));
8933 ospf_interface_area_unset(ospf
, ifp
);
8934 ospf_area_check_free(ospf
, area_id
);
8940 DEFUN (ip_ospf_passive
,
8941 ip_ospf_passive_cmd
,
8942 "ip ospf passive [A.B.C.D]",
8944 "OSPF interface commands\n"
8945 "Suppress routing updates on an interface\n"
8946 "Address of interface\n")
8948 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8950 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
8951 struct ospf_if_params
*params
;
8955 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8958 "Please specify interface address by A.B.C.D\n");
8959 return CMD_WARNING_CONFIG_FAILED
;
8961 params
= ospf_get_if_params(ifp
, addr
);
8962 ospf_if_update_params(ifp
, addr
);
8964 params
= IF_DEF_PARAMS(ifp
);
8967 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_PASSIVE
);
8972 DEFUN (no_ip_ospf_passive
,
8973 no_ip_ospf_passive_cmd
,
8974 "no ip ospf passive [A.B.C.D]",
8977 "OSPF interface commands\n"
8978 "Enable routing updates on an interface\n"
8979 "Address of interface\n")
8981 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8983 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
8984 struct ospf_if_params
*params
;
8988 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8991 "Please specify interface address by A.B.C.D\n");
8992 return CMD_WARNING_CONFIG_FAILED
;
8994 params
= ospf_lookup_if_params(ifp
, addr
);
8998 params
= IF_DEF_PARAMS(ifp
);
9001 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_ACTIVE
);
9006 DEFUN (ospf_redistribute_source
,
9007 ospf_redistribute_source_cmd
,
9008 "redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9010 FRR_REDIST_HELP_STR_OSPFD
9011 "Metric for redistributed routes\n"
9012 "OSPF default metric\n"
9013 "OSPF exterior metric type for redistributed routes\n"
9014 "Set OSPF External Type 1/2 metrics\n"
9015 "Route map reference\n"
9016 "Pointer to route-map entries\n")
9018 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9019 int idx_protocol
= 1;
9023 struct ospf_redist
*red
;
9025 bool update
= false;
9027 /* Get distribute source. */
9028 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
9030 return CMD_WARNING_CONFIG_FAILED
;
9032 /* Get metric value. */
9033 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
9034 if (!str2metric(argv
[idx
]->arg
, &metric
))
9035 return CMD_WARNING_CONFIG_FAILED
;
9038 /* Get metric type. */
9039 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
9040 if (!str2metric_type(argv
[idx
]->arg
, &type
))
9041 return CMD_WARNING_CONFIG_FAILED
;
9045 red
= ospf_redist_lookup(ospf
, source
, 0);
9047 red
= ospf_redist_add(ospf
, source
, 0);
9052 if (argv_find(argv
, argc
, "route-map", &idx
)) {
9053 ospf_routemap_set(red
, argv
[idx
+ 1]->arg
);
9055 ospf_routemap_unset(red
);
9058 return ospf_redistribute_update(ospf
, red
, source
, 0, type
,
9061 return ospf_redistribute_set(ospf
, red
, source
, 0, type
,
9065 DEFUN (no_ospf_redistribute_source
,
9066 no_ospf_redistribute_source_cmd
,
9067 "no redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9070 FRR_REDIST_HELP_STR_OSPFD
9071 "Metric for redistributed routes\n"
9072 "OSPF default metric\n"
9073 "OSPF exterior metric type for redistributed routes\n"
9074 "Set OSPF External Type 1/2 metrics\n"
9075 "Route map reference\n"
9076 "Pointer to route-map entries\n")
9078 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9079 int idx_protocol
= 2;
9081 struct ospf_redist
*red
;
9083 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
9085 return CMD_WARNING_CONFIG_FAILED
;
9087 red
= ospf_redist_lookup(ospf
, source
, 0);
9091 ospf_routemap_unset(red
);
9092 ospf_redist_del(ospf
, source
, 0);
9094 return ospf_redistribute_unset(ospf
, source
, 0);
9097 DEFUN (ospf_redistribute_instance_source
,
9098 ospf_redistribute_instance_source_cmd
,
9099 "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9101 "Open Shortest Path First\n"
9102 "Non-main Kernel Routing Table\n"
9103 "Instance ID/Table ID\n"
9104 "Metric for redistributed routes\n"
9105 "OSPF default metric\n"
9106 "OSPF exterior metric type for redistributed routes\n"
9107 "Set OSPF External Type 1/2 metrics\n"
9108 "Route map reference\n"
9109 "Pointer to route-map entries\n")
9111 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9112 int idx_ospf_table
= 1;
9118 unsigned short instance
;
9119 struct ospf_redist
*red
;
9120 bool update
= false;
9122 source
= proto_redistnum(AFI_IP
, argv
[idx_ospf_table
]->text
);
9125 vty_out(vty
, "Unknown instance redistribution\n");
9126 return CMD_WARNING_CONFIG_FAILED
;
9129 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9131 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
9133 "Instance redistribution in non-instanced OSPF not allowed\n");
9134 return CMD_WARNING_CONFIG_FAILED
;
9137 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
9138 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
9139 return CMD_WARNING_CONFIG_FAILED
;
9142 /* Get metric value. */
9143 if (argv_find(argv
, argc
, "metric", &idx
))
9144 if (!str2metric(argv
[idx
+ 1]->arg
, &metric
))
9145 return CMD_WARNING_CONFIG_FAILED
;
9148 /* Get metric type. */
9149 if (argv_find(argv
, argc
, "metric-type", &idx
))
9150 if (!str2metric_type(argv
[idx
+ 1]->arg
, &type
))
9151 return CMD_WARNING_CONFIG_FAILED
;
9153 red
= ospf_redist_lookup(ospf
, source
, instance
);
9155 red
= ospf_redist_add(ospf
, source
, instance
);
9160 if (argv_find(argv
, argc
, "route-map", &idx
))
9161 ospf_routemap_set(red
, argv
[idx
+ 1]->arg
);
9163 ospf_routemap_unset(red
);
9166 return ospf_redistribute_update(ospf
, red
, source
, instance
,
9169 return ospf_redistribute_set(ospf
, red
, source
, instance
, type
,
9173 DEFUN (no_ospf_redistribute_instance_source
,
9174 no_ospf_redistribute_instance_source_cmd
,
9175 "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9178 "Open Shortest Path First\n"
9179 "Non-main Kernel Routing Table\n"
9180 "Instance ID/Table Id\n"
9181 "Metric for redistributed routes\n"
9182 "OSPF default metric\n"
9183 "OSPF exterior metric type for redistributed routes\n"
9184 "Set OSPF External Type 1/2 metrics\n"
9185 "Route map reference\n"
9186 "Pointer to route-map entries\n")
9188 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9189 int idx_ospf_table
= 2;
9191 unsigned int instance
;
9192 struct ospf_redist
*red
;
9195 if (strncmp(argv
[idx_ospf_table
]->arg
, "o", 1) == 0)
9196 source
= ZEBRA_ROUTE_OSPF
;
9198 source
= ZEBRA_ROUTE_TABLE
;
9200 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9202 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
9204 "Instance redistribution in non-instanced OSPF not allowed\n");
9205 return CMD_WARNING_CONFIG_FAILED
;
9208 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
9209 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
9210 return CMD_WARNING_CONFIG_FAILED
;
9213 red
= ospf_redist_lookup(ospf
, source
, instance
);
9217 ospf_routemap_unset(red
);
9218 ospf_redist_del(ospf
, source
, instance
);
9220 return ospf_redistribute_unset(ospf
, source
, instance
);
9223 DEFUN (ospf_distribute_list_out
,
9224 ospf_distribute_list_out_cmd
,
9225 "distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD
,
9226 "Filter networks in routing updates\n"
9227 "Access-list name\n"
9229 FRR_REDIST_HELP_STR_OSPFD
)
9231 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9235 char *proto
= argv
[argc
- 1]->text
;
9237 /* Get distribute source. */
9238 source
= proto_redistnum(AFI_IP
, proto
);
9240 return CMD_WARNING_CONFIG_FAILED
;
9242 return ospf_distribute_list_out_set(ospf
, source
, argv
[idx_word
]->arg
);
9245 DEFUN (no_ospf_distribute_list_out
,
9246 no_ospf_distribute_list_out_cmd
,
9247 "no distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD
,
9249 "Filter networks in routing updates\n"
9250 "Access-list name\n"
9252 FRR_REDIST_HELP_STR_OSPFD
)
9254 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9258 char *proto
= argv
[argc
- 1]->text
;
9259 source
= proto_redistnum(AFI_IP
, proto
);
9261 return CMD_WARNING_CONFIG_FAILED
;
9263 return ospf_distribute_list_out_unset(ospf
, source
,
9264 argv
[idx_word
]->arg
);
9267 /* Default information originate. */
9268 DEFUN (ospf_default_information_originate
,
9269 ospf_default_information_originate_cmd
,
9270 "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9271 "Control distribution of default information\n"
9272 "Distribute a default route\n"
9273 "Always advertise default route\n"
9274 "OSPF default metric\n"
9276 "OSPF metric type for default routes\n"
9277 "Set OSPF External Type 1/2 metrics\n"
9278 "Route map reference\n"
9279 "Pointer to route-map entries\n")
9281 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9282 int default_originate
= DEFAULT_ORIGINATE_ZEBRA
;
9285 struct ospf_redist
*red
;
9287 int cur_originate
= ospf
->default_originate
;
9288 bool sameRtmap
= false;
9291 red
= ospf_redist_add(ospf
, DEFAULT_ROUTE
, 0);
9293 /* Check whether "always" was specified */
9294 if (argv_find(argv
, argc
, "always", &idx
))
9295 default_originate
= DEFAULT_ORIGINATE_ALWAYS
;
9297 /* Get metric value */
9298 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
9299 if (!str2metric(argv
[idx
]->arg
, &metric
))
9300 return CMD_WARNING_CONFIG_FAILED
;
9303 /* Get metric type. */
9304 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
9305 if (!str2metric_type(argv
[idx
]->arg
, &type
))
9306 return CMD_WARNING_CONFIG_FAILED
;
9310 if (argv_find(argv
, argc
, "route-map", &idx
))
9311 rtmap
= argv
[idx
+ 1]->arg
;
9313 /* To check if user is providing same route map */
9314 if ((!rtmap
&& !ROUTEMAP_NAME(red
)) ||
9315 (rtmap
&& ROUTEMAP_NAME(red
) &&
9316 (strcmp(rtmap
, ROUTEMAP_NAME(red
)) == 0)))
9319 /* Don't allow if the same lsa is already originated. */
9321 && (red
->dmetric
.type
== type
)
9322 && (red
->dmetric
.value
== metric
)
9323 && (cur_originate
== default_originate
))
9326 /* Updating Metric details */
9327 red
->dmetric
.type
= type
;
9328 red
->dmetric
.value
= metric
;
9330 /* updating route map details */
9332 ospf_routemap_set(red
, rtmap
);
9334 ospf_routemap_unset(red
);
9336 return ospf_redistribute_default_set(ospf
, default_originate
, type
,
9340 DEFUN (no_ospf_default_information_originate
,
9341 no_ospf_default_information_originate_cmd
,
9342 "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9344 "Control distribution of default information\n"
9345 "Distribute a default route\n"
9346 "Always advertise default route\n"
9347 "OSPF default metric\n"
9349 "OSPF metric type for default routes\n"
9350 "Set OSPF External Type 1/2 metrics\n"
9351 "Route map reference\n"
9352 "Pointer to route-map entries\n")
9354 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9355 struct ospf_redist
*red
;
9357 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
9361 ospf_routemap_unset(red
);
9362 ospf_redist_del(ospf
, DEFAULT_ROUTE
, 0);
9364 return ospf_redistribute_default_set(ospf
, DEFAULT_ORIGINATE_NONE
,
9368 DEFUN (ospf_default_metric
,
9369 ospf_default_metric_cmd
,
9370 "default-metric (0-16777214)",
9371 "Set metric of redistributed routes\n"
9374 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9378 if (!str2metric(argv
[idx_number
]->arg
, &metric
))
9379 return CMD_WARNING_CONFIG_FAILED
;
9381 ospf
->default_metric
= metric
;
9386 DEFUN (no_ospf_default_metric
,
9387 no_ospf_default_metric_cmd
,
9388 "no default-metric [(0-16777214)]",
9390 "Set metric of redistributed routes\n"
9393 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9395 ospf
->default_metric
= -1;
9401 DEFUN (ospf_distance
,
9404 "Administrative distance\n"
9405 "OSPF Administrative distance\n")
9407 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9411 distance
= atoi(argv
[idx_number
]->arg
);
9412 if (ospf
->distance_all
!= distance
) {
9413 ospf
->distance_all
= distance
;
9414 ospf_restart_spf(ospf
);
9420 DEFUN (no_ospf_distance
,
9421 no_ospf_distance_cmd
,
9422 "no distance (1-255)",
9424 "Administrative distance\n"
9425 "OSPF Administrative distance\n")
9427 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9429 if (ospf
->distance_all
) {
9430 ospf
->distance_all
= 0;
9431 ospf_restart_spf(ospf
);
9437 DEFUN (no_ospf_distance_ospf
,
9438 no_ospf_distance_ospf_cmd
,
9439 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
9441 "Administrative distance\n"
9442 "OSPF administrative distance\n"
9443 "Intra-area routes\n"
9444 "Distance for intra-area routes\n"
9445 "Inter-area routes\n"
9446 "Distance for inter-area routes\n"
9448 "Distance for external routes\n")
9450 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9453 if (argv_find(argv
, argc
, "intra-area", &idx
) || argc
== 3)
9454 idx
= ospf
->distance_intra
= 0;
9455 if (argv_find(argv
, argc
, "inter-area", &idx
) || argc
== 3)
9456 idx
= ospf
->distance_inter
= 0;
9457 if (argv_find(argv
, argc
, "external", &idx
) || argc
== 3)
9458 ospf
->distance_external
= 0;
9463 DEFUN (ospf_distance_ospf
,
9464 ospf_distance_ospf_cmd
,
9465 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
9466 "Administrative distance\n"
9467 "OSPF administrative distance\n"
9468 "Intra-area routes\n"
9469 "Distance for intra-area routes\n"
9470 "Inter-area routes\n"
9471 "Distance for inter-area routes\n"
9473 "Distance for external routes\n")
9475 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9478 ospf
->distance_intra
= 0;
9479 ospf
->distance_inter
= 0;
9480 ospf
->distance_external
= 0;
9482 if (argv_find(argv
, argc
, "intra-area", &idx
))
9483 ospf
->distance_intra
= atoi(argv
[idx
+ 1]->arg
);
9485 if (argv_find(argv
, argc
, "inter-area", &idx
))
9486 ospf
->distance_inter
= atoi(argv
[idx
+ 1]->arg
);
9488 if (argv_find(argv
, argc
, "external", &idx
))
9489 ospf
->distance_external
= atoi(argv
[idx
+ 1]->arg
);
9494 DEFUN (ip_ospf_mtu_ignore
,
9495 ip_ospf_mtu_ignore_addr_cmd
,
9496 "ip ospf mtu-ignore [A.B.C.D]",
9498 "OSPF interface commands\n"
9499 "Disable MTU mismatch detection on this interface\n"
9500 "Address of interface\n")
9502 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9504 struct in_addr addr
;
9507 struct ospf_if_params
*params
;
9508 params
= IF_DEF_PARAMS(ifp
);
9511 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9514 "Please specify interface address by A.B.C.D\n");
9515 return CMD_WARNING_CONFIG_FAILED
;
9517 params
= ospf_get_if_params(ifp
, addr
);
9518 ospf_if_update_params(ifp
, addr
);
9520 params
->mtu_ignore
= 1;
9521 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
9522 SET_IF_PARAM(params
, mtu_ignore
);
9524 UNSET_IF_PARAM(params
, mtu_ignore
);
9525 if (params
!= IF_DEF_PARAMS(ifp
)) {
9526 ospf_free_if_params(ifp
, addr
);
9527 ospf_if_update_params(ifp
, addr
);
9533 DEFUN (no_ip_ospf_mtu_ignore
,
9534 no_ip_ospf_mtu_ignore_addr_cmd
,
9535 "no ip ospf mtu-ignore [A.B.C.D]",
9538 "OSPF interface commands\n"
9539 "Disable MTU mismatch detection on this interface\n"
9540 "Address of interface\n")
9542 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9544 struct in_addr addr
;
9547 struct ospf_if_params
*params
;
9548 params
= IF_DEF_PARAMS(ifp
);
9551 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9554 "Please specify interface address by A.B.C.D\n");
9555 return CMD_WARNING_CONFIG_FAILED
;
9557 params
= ospf_get_if_params(ifp
, addr
);
9558 ospf_if_update_params(ifp
, addr
);
9560 params
->mtu_ignore
= 0;
9561 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
9562 SET_IF_PARAM(params
, mtu_ignore
);
9564 UNSET_IF_PARAM(params
, mtu_ignore
);
9565 if (params
!= IF_DEF_PARAMS(ifp
)) {
9566 ospf_free_if_params(ifp
, addr
);
9567 ospf_if_update_params(ifp
, addr
);
9574 DEFUN (ospf_max_metric_router_lsa_admin
,
9575 ospf_max_metric_router_lsa_admin_cmd
,
9576 "max-metric router-lsa administrative",
9577 "OSPF maximum / infinite-distance metric\n"
9578 "Advertise own Router-LSA with infinite distance (stub router)\n"
9579 "Administratively applied, for an indefinite period\n")
9581 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9582 struct listnode
*ln
;
9583 struct ospf_area
*area
;
9585 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
9586 SET_FLAG(area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
);
9588 if (!CHECK_FLAG(area
->stub_router_state
,
9589 OSPF_AREA_IS_STUB_ROUTED
))
9590 ospf_router_lsa_update_area(area
);
9593 /* Allows for areas configured later to get the property */
9594 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
;
9599 DEFUN (no_ospf_max_metric_router_lsa_admin
,
9600 no_ospf_max_metric_router_lsa_admin_cmd
,
9601 "no max-metric router-lsa administrative",
9603 "OSPF maximum / infinite-distance metric\n"
9604 "Advertise own Router-LSA with infinite distance (stub router)\n"
9605 "Administratively applied, for an indefinite period\n")
9607 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9608 struct listnode
*ln
;
9609 struct ospf_area
*area
;
9611 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
9612 UNSET_FLAG(area
->stub_router_state
,
9613 OSPF_AREA_ADMIN_STUB_ROUTED
);
9615 /* Don't trample on the start-up stub timer */
9616 if (CHECK_FLAG(area
->stub_router_state
,
9617 OSPF_AREA_IS_STUB_ROUTED
)
9618 && !area
->t_stub_router
) {
9619 UNSET_FLAG(area
->stub_router_state
,
9620 OSPF_AREA_IS_STUB_ROUTED
);
9621 ospf_router_lsa_update_area(area
);
9624 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET
;
9628 DEFUN (ospf_max_metric_router_lsa_startup
,
9629 ospf_max_metric_router_lsa_startup_cmd
,
9630 "max-metric router-lsa on-startup (5-86400)",
9631 "OSPF maximum / infinite-distance metric\n"
9632 "Advertise own Router-LSA with infinite distance (stub router)\n"
9633 "Automatically advertise stub Router-LSA on startup of OSPF\n"
9634 "Time (seconds) to advertise self as stub-router\n")
9636 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9638 unsigned int seconds
;
9641 vty_out(vty
, "%% Must supply stub-router period\n");
9642 return CMD_WARNING_CONFIG_FAILED
;
9645 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9647 ospf
->stub_router_startup_time
= seconds
;
9652 DEFUN (no_ospf_max_metric_router_lsa_startup
,
9653 no_ospf_max_metric_router_lsa_startup_cmd
,
9654 "no max-metric router-lsa on-startup [(5-86400)]",
9656 "OSPF maximum / infinite-distance metric\n"
9657 "Advertise own Router-LSA with infinite distance (stub router)\n"
9658 "Automatically advertise stub Router-LSA on startup of OSPF\n"
9659 "Time (seconds) to advertise self as stub-router\n")
9661 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9662 struct listnode
*ln
;
9663 struct ospf_area
*area
;
9665 ospf
->stub_router_startup_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
9667 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
9668 SET_FLAG(area
->stub_router_state
,
9669 OSPF_AREA_WAS_START_STUB_ROUTED
);
9670 EVENT_OFF(area
->t_stub_router
);
9672 /* Don't trample on admin stub routed */
9673 if (!CHECK_FLAG(area
->stub_router_state
,
9674 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
9675 UNSET_FLAG(area
->stub_router_state
,
9676 OSPF_AREA_IS_STUB_ROUTED
);
9677 ospf_router_lsa_update_area(area
);
9684 DEFUN (ospf_max_metric_router_lsa_shutdown
,
9685 ospf_max_metric_router_lsa_shutdown_cmd
,
9686 "max-metric router-lsa on-shutdown (5-100)",
9687 "OSPF maximum / infinite-distance metric\n"
9688 "Advertise own Router-LSA with infinite distance (stub router)\n"
9689 "Advertise stub-router prior to full shutdown of OSPF\n"
9690 "Time (seconds) to wait till full shutdown\n")
9692 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9694 unsigned int seconds
;
9697 vty_out(vty
, "%% Must supply stub-router shutdown period\n");
9698 return CMD_WARNING_CONFIG_FAILED
;
9701 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9703 ospf
->stub_router_shutdown_time
= seconds
;
9708 DEFUN (no_ospf_max_metric_router_lsa_shutdown
,
9709 no_ospf_max_metric_router_lsa_shutdown_cmd
,
9710 "no max-metric router-lsa on-shutdown [(5-100)]",
9712 "OSPF maximum / infinite-distance metric\n"
9713 "Advertise own Router-LSA with infinite distance (stub router)\n"
9714 "Advertise stub-router prior to full shutdown of OSPF\n"
9715 "Time (seconds) to wait till full shutdown\n")
9717 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9719 ospf
->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
9724 DEFUN (ospf_proactive_arp
,
9725 ospf_proactive_arp_cmd
,
9727 "Allow sending ARP requests proactively\n")
9729 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9731 ospf
->proactive_arp
= true;
9736 DEFUN (no_ospf_proactive_arp
,
9737 no_ospf_proactive_arp_cmd
,
9740 "Disallow sending ARP requests proactively\n")
9742 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9744 ospf
->proactive_arp
= false;
9749 /* Graceful Restart HELPER Commands */
9750 DEFPY(ospf_gr_helper_enable
, ospf_gr_helper_enable_cmd
,
9751 "graceful-restart helper enable [A.B.C.D$address]",
9752 "OSPF Graceful Restart\n"
9754 "Enable Helper support\n"
9755 "Advertising Router-ID\n")
9757 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9760 ospf_gr_helper_support_set_per_routerid(ospf
, &address
,
9765 ospf_gr_helper_support_set(ospf
, OSPF_GR_TRUE
);
9770 DEFPY(no_ospf_gr_helper_enable
,
9771 no_ospf_gr_helper_enable_cmd
,
9772 "no graceful-restart helper enable [A.B.C.D$address]",
9774 "OSPF Graceful Restart\n"
9776 "Enable Helper support\n"
9777 "Advertising Router-ID\n")
9779 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9782 ospf_gr_helper_support_set_per_routerid(ospf
, &address
,
9787 ospf_gr_helper_support_set(ospf
, OSPF_GR_FALSE
);
9791 DEFPY(ospf_gr_helper_enable_lsacheck
,
9792 ospf_gr_helper_enable_lsacheck_cmd
,
9793 "graceful-restart helper strict-lsa-checking",
9794 "OSPF Graceful Restart\n"
9796 "Enable strict LSA check\n")
9798 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9800 ospf_gr_helper_lsa_check_set(ospf
, OSPF_GR_TRUE
);
9804 DEFPY(no_ospf_gr_helper_enable_lsacheck
,
9805 no_ospf_gr_helper_enable_lsacheck_cmd
,
9806 "no graceful-restart helper strict-lsa-checking",
9808 "OSPF Graceful Restart\n"
9810 "Disable strict LSA check\n")
9812 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9814 ospf_gr_helper_lsa_check_set(ospf
, OSPF_GR_FALSE
);
9818 DEFPY(ospf_gr_helper_supported_grace_time
,
9819 ospf_gr_helper_supported_grace_time_cmd
,
9820 "graceful-restart helper supported-grace-time (10-1800)$interval",
9821 "OSPF Graceful Restart\n"
9823 "Supported grace timer\n"
9824 "Grace interval(in seconds)\n")
9826 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9828 ospf_gr_helper_supported_gracetime_set(ospf
, interval
);
9832 DEFPY(no_ospf_gr_helper_supported_grace_time
,
9833 no_ospf_gr_helper_supported_grace_time_cmd
,
9834 "no graceful-restart helper supported-grace-time (10-1800)$interval",
9836 "OSPF Graceful Restart\n"
9838 "Supported grace timer\n"
9839 "Grace interval(in seconds)\n")
9841 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9843 ospf_gr_helper_supported_gracetime_set(ospf
, OSPF_MAX_GRACE_INTERVAL
);
9847 DEFPY(ospf_gr_helper_planned_only
,
9848 ospf_gr_helper_planned_only_cmd
,
9849 "graceful-restart helper planned-only",
9850 "OSPF Graceful Restart\n"
9852 "Supported only planned restart\n")
9854 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9856 ospf_gr_helper_set_supported_planned_only_restart(ospf
, OSPF_GR_TRUE
);
9861 /* External Route Aggregation */
9862 DEFUN (ospf_external_route_aggregation
,
9863 ospf_external_route_aggregation_cmd
,
9864 "summary-address A.B.C.D/M [tag (1-4294967295)]",
9865 "External summary address\n"
9866 "Summary address prefix\n"
9868 "Router tag value\n")
9870 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9871 struct prefix_ipv4 p
;
9873 route_tag_t tag
= 0;
9874 int ret
= OSPF_SUCCESS
;
9876 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
9878 if (is_default_prefix4(&p
)) {
9880 "Default address shouldn't be configured as summary address.\n");
9884 /* Apply mask for given prefix. */
9887 if (!is_valid_summary_addr(&p
)) {
9888 vty_out(vty
, "Not a valid summary address.\n");
9889 return CMD_WARNING_CONFIG_FAILED
;
9893 tag
= strtoul(argv
[idx
+ 2]->arg
, NULL
, 10);
9895 ret
= ospf_asbr_external_aggregator_set(ospf
, &p
, tag
);
9896 if (ret
== OSPF_INVALID
)
9897 vty_out(vty
, "Invalid configuration!!\n");
9902 DEFUN (no_ospf_external_route_aggregation
,
9903 no_ospf_external_route_aggregation_cmd
,
9904 "no summary-address A.B.C.D/M [tag (1-4294967295)]",
9906 "External summary address\n"
9907 "Summary address prefix\n"
9909 "Router tag value\n")
9911 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9912 struct prefix_ipv4 p
;
9914 route_tag_t tag
= 0;
9915 int ret
= OSPF_SUCCESS
;
9917 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
9919 if (is_default_prefix4(&p
)) {
9921 "Default address shouldn't be configured as summary address.\n");
9925 /* Apply mask for given prefix. */
9928 if (!is_valid_summary_addr(&p
)) {
9929 vty_out(vty
, "Not a valid summary address.\n");
9930 return CMD_WARNING_CONFIG_FAILED
;
9934 tag
= strtoul(argv
[idx
+ 2]->arg
, NULL
, 10);
9936 ret
= ospf_asbr_external_aggregator_unset(ospf
, &p
, tag
);
9937 if (ret
== OSPF_INVALID
)
9938 vty_out(vty
, "Invalid configuration!!\n");
9943 DEFPY(no_ospf_gr_helper_planned_only
,
9944 no_ospf_gr_helper_planned_only_cmd
,
9945 "no graceful-restart helper planned-only",
9947 "OSPF Graceful Restart\n"
9949 "Supported only for planned restart\n")
9951 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9953 ospf_gr_helper_set_supported_planned_only_restart(ospf
, OSPF_GR_FALSE
);
9958 static int ospf_print_vty_helper_dis_rtr_walkcb(struct hash_bucket
*bucket
,
9961 struct advRtr
*rtr
= bucket
->data
;
9962 struct vty
*vty
= (struct vty
*)arg
;
9963 static unsigned int count
;
9965 vty_out(vty
, "%-6pI4,", &rtr
->advRtrAddr
);
9971 return HASHWALK_CONTINUE
;
9974 static int ospf_print_json_helper_enabled_rtr_walkcb(struct hash_bucket
*bucket
,
9977 struct advRtr
*rtr
= bucket
->data
;
9978 struct json_object
*json_rid_array
= arg
;
9979 struct json_object
*json_rid
;
9981 json_rid
= json_object_new_object();
9983 json_object_string_addf(json_rid
, "routerId", "%pI4", &rtr
->advRtrAddr
);
9984 json_object_array_add(json_rid_array
, json_rid
);
9986 return HASHWALK_CONTINUE
;
9989 static int ospf_show_gr_helper_details(struct vty
*vty
, struct ospf
*ospf
,
9990 uint8_t use_vrf
, json_object
*json
,
9991 bool uj
, bool detail
)
9993 struct listnode
*node
;
9994 struct ospf_interface
*oi
;
9995 char buf
[PREFIX_STRLEN
];
9996 json_object
*json_vrf
= NULL
;
10000 json_vrf
= json_object_new_object();
10005 if (ospf
->instance
) {
10007 json_object_int_add(json
, "ospfInstance",
10010 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
10013 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
10017 json_object_object_add(json
, ospf_get_name(ospf
),
10020 vty_out(vty
, "\n");
10022 /* Show Router ID. */
10024 json_object_string_add(json_vrf
, "routerId",
10025 inet_ntop(AF_INET
, &ospf
->router_id
,
10026 buf
, sizeof(buf
)));
10028 vty_out(vty
, "\n OSPF Router with ID (%pI4)\n\n",
10034 if (ospf
->is_helper_supported
)
10036 " Graceful restart helper support enabled.\n");
10039 " Graceful restart helper support disabled.\n");
10041 if (ospf
->strict_lsa_check
)
10042 vty_out(vty
, " Strict LSA check is enabled.\n");
10044 vty_out(vty
, " Strict LSA check is disabled.\n");
10046 if (ospf
->only_planned_restart
)
10048 " Helper supported for planned restarts only.\n");
10051 " Helper supported for Planned and Unplanned Restarts.\n");
10054 " Supported Graceful restart interval: %d(in seconds).\n",
10055 ospf
->supported_grace_time
);
10057 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf
)) {
10058 vty_out(vty
, " Enable Router list:\n");
10060 hash_walk(ospf
->enable_rtr_list
,
10061 ospf_print_vty_helper_dis_rtr_walkcb
, vty
);
10062 vty_out(vty
, "\n\n");
10065 if (ospf
->last_exit_reason
!= OSPF_GR_HELPER_EXIT_NONE
) {
10066 vty_out(vty
, " Last Helper exit Reason :%s\n",
10067 ospf_exit_reason2str(ospf
->last_exit_reason
));
10070 if (ospf
->active_restarter_cnt
)
10072 " Number of Active neighbours in graceful restart: %d\n",
10073 ospf
->active_restarter_cnt
);
10075 vty_out(vty
, "\n");
10078 json_object_string_add(
10079 json_vrf
, "helperSupport",
10080 (ospf
->is_helper_supported
) ? "Enabled" : "Disabled");
10081 json_object_string_add(json_vrf
, "strictLsaCheck",
10082 (ospf
->strict_lsa_check
) ? "Enabled"
10084 #if CONFDATE > 20240401
10085 CPP_NOTICE("Remove deprecated json key: restartSupoort")
10087 json_object_string_add(
10088 json_vrf
, "restartSupoort",
10089 (ospf
->only_planned_restart
)
10090 ? "Planned Restart only"
10091 : "Planned and Unplanned Restarts");
10093 json_object_string_add(
10094 json_vrf
, "restartSupport",
10095 (ospf
->only_planned_restart
)
10096 ? "Planned Restart only"
10097 : "Planned and Unplanned Restarts");
10099 json_object_int_add(json_vrf
, "supportedGracePeriod",
10100 ospf
->supported_grace_time
);
10102 if (ospf
->last_exit_reason
!= OSPF_GR_HELPER_EXIT_NONE
)
10103 json_object_string_add(
10104 json_vrf
, "lastExitReason",
10105 ospf_exit_reason2str(ospf
->last_exit_reason
));
10107 if (ospf
->active_restarter_cnt
)
10108 json_object_int_add(json_vrf
, "activeRestarterCnt",
10109 ospf
->active_restarter_cnt
);
10111 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf
)) {
10112 struct json_object
*json_rid_array
=
10113 json_object_new_array();
10115 json_object_object_add(json_vrf
, "enabledRouterIds",
10118 hash_walk(ospf
->enable_rtr_list
,
10119 ospf_print_json_helper_enabled_rtr_walkcb
,
10127 json_object
*json_neighbors
= NULL
;
10129 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
10130 struct route_node
*rn
;
10131 struct ospf_neighbor
*nbr
;
10132 json_object
*json_neigh
;
10134 if (ospf_interface_neighbor_count(oi
) == 0)
10138 json_object_object_get_ex(json_vrf
, "neighbors",
10140 if (!json_neighbors
) {
10142 json_object_new_object();
10143 json_object_object_add(json_vrf
,
10149 for (rn
= route_top(oi
->nbrs
); rn
;
10150 rn
= route_next(rn
)) {
10157 if (!OSPF_GR_IS_ACTIVE_HELPER(nbr
))
10161 vty_out(vty
, " Neighbour %d :\n", cnt
);
10162 vty_out(vty
, " Address : %pI4\n",
10163 &nbr
->address
.u
.prefix4
);
10164 vty_out(vty
, " Routerid : %pI4\n",
10167 " Received Grace period : %d(in seconds).\n",
10168 nbr
->gr_helper_info
10169 .recvd_grace_period
);
10171 " Actual Grace period : %d(in seconds)\n",
10172 nbr
->gr_helper_info
10173 .actual_grace_period
);
10175 " Remaining GraceTime:%ld(in seconds).\n",
10176 event_timer_remain_second(
10177 nbr
->gr_helper_info
10180 " Graceful Restart reason: %s.\n\n",
10181 ospf_restart_reason2str(
10182 nbr
->gr_helper_info
10183 .gr_restart_reason
));
10186 json_neigh
= json_object_new_object();
10187 json_object_string_add(
10188 json_neigh
, "srcAddr",
10189 inet_ntop(AF_INET
, &nbr
->src
,
10190 buf
, sizeof(buf
)));
10192 json_object_string_add(
10193 json_neigh
, "routerid",
10196 buf
, sizeof(buf
)));
10197 json_object_int_add(
10199 "recvdGraceInterval",
10200 nbr
->gr_helper_info
10201 .recvd_grace_period
);
10202 json_object_int_add(
10204 "actualGraceInterval",
10205 nbr
->gr_helper_info
10206 .actual_grace_period
);
10207 json_object_int_add(
10208 json_neigh
, "remainGracetime",
10209 event_timer_remain_second(
10210 nbr
->gr_helper_info
10212 json_object_string_add(
10213 json_neigh
, "restartReason",
10214 ospf_restart_reason2str(
10215 nbr
->gr_helper_info
10216 .gr_restart_reason
));
10217 json_object_object_add(
10219 inet_ntop(AF_INET
, &nbr
->src
,
10226 return CMD_SUCCESS
;
10229 DEFUN (ospf_external_route_aggregation_no_adrvertise
,
10230 ospf_external_route_aggregation_no_adrvertise_cmd
,
10231 "summary-address A.B.C.D/M no-advertise",
10232 "External summary address\n"
10233 "Summary address prefix\n"
10234 "Don't advertise summary route \n")
10236 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10237 struct prefix_ipv4 p
;
10239 int ret
= OSPF_SUCCESS
;
10241 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
10243 if (is_default_prefix4(&p
)) {
10245 "Default address shouldn't be configured as summary address.\n");
10246 return CMD_SUCCESS
;
10249 /* Apply mask for given prefix. */
10252 if (!is_valid_summary_addr(&p
)) {
10253 vty_out(vty
, "Not a valid summary address.\n");
10254 return CMD_WARNING_CONFIG_FAILED
;
10257 ret
= ospf_asbr_external_rt_no_advertise(ospf
, &p
);
10258 if (ret
== OSPF_INVALID
)
10259 vty_out(vty
, "Invalid configuration!!\n");
10261 return CMD_SUCCESS
;
10264 DEFUN (no_ospf_external_route_aggregation_no_adrvertise
,
10265 no_ospf_external_route_aggregation_no_adrvertise_cmd
,
10266 "no summary-address A.B.C.D/M no-advertise",
10268 "External summary address\n"
10269 "Summary address prefix\n"
10270 "Advertise summary route to the AS \n")
10272 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10273 struct prefix_ipv4 p
;
10275 int ret
= OSPF_SUCCESS
;
10277 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
10279 if (is_default_prefix4(&p
)) {
10281 "Default address shouldn't be configured as summary address.\n");
10282 return CMD_SUCCESS
;
10285 /* Apply mask for given prefix. */
10288 if (!is_valid_summary_addr(&p
)) {
10289 vty_out(vty
, "Not a valid summary address.\n");
10290 return CMD_WARNING_CONFIG_FAILED
;
10293 ret
= ospf_asbr_external_rt_advertise(ospf
, &p
);
10294 if (ret
== OSPF_INVALID
)
10295 vty_out(vty
, "Invalid configuration!!\n");
10297 return CMD_SUCCESS
;
10300 DEFUN (ospf_route_aggregation_timer
,
10301 ospf_route_aggregation_timer_cmd
,
10302 "aggregation timer (5-1800)",
10303 "External route aggregation\n"
10304 "Delay timer (in seconds)\n"
10305 "Timer interval(in seconds)\n")
10307 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10308 uint16_t interval
= 0;
10310 interval
= strtoul(argv
[2]->arg
, NULL
, 10);
10312 ospf_external_aggregator_timer_set(ospf
, interval
);
10314 return CMD_SUCCESS
;
10317 DEFPY (show_ip_ospf_gr_helper
,
10318 show_ip_ospf_gr_helper_cmd
,
10319 "show ip ospf [vrf <NAME|all>] graceful-restart helper [detail] [json]",
10322 "OSPF information\n"
10325 "OSPF Graceful Restart\n"
10326 "Helper details in the router\n"
10327 "Detailed information\n"
10330 char *vrf_name
= NULL
;
10331 bool all_vrf
= false;
10332 int ret
= CMD_SUCCESS
;
10335 uint8_t use_vrf
= 0;
10336 bool uj
= use_json(argc
, argv
);
10337 struct ospf
*ospf
= NULL
;
10338 json_object
*json
= NULL
;
10339 struct listnode
*node
= NULL
;
10341 bool detail
= false;
10343 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
10345 if (argv_find(argv
, argc
, "detail", &idx
))
10349 json
= json_object_new_object();
10351 /* vrf input is provided */
10356 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
10357 if (!ospf
->oi_running
)
10360 ret
= ospf_show_gr_helper_details(
10361 vty
, ospf
, use_vrf
, json
, uj
, detail
);
10365 vty_json(vty
, json
);
10370 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
10372 if (ospf
== NULL
|| !ospf
->oi_running
) {
10375 vty_json(vty
, json
);
10378 "%% OSPF is not enabled in vrf %s\n",
10381 return CMD_SUCCESS
;
10386 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
10388 if (ospf
== NULL
|| !ospf
->oi_running
) {
10391 vty_json(vty
, json
);
10394 "%% OSPF is not enabled in vrf default\n");
10396 return CMD_SUCCESS
;
10399 ospf_show_gr_helper_details(vty
, ospf
, use_vrf
, json
, uj
,
10404 vty_json(vty
, json
);
10406 return CMD_SUCCESS
;
10408 /* Graceful Restart HELPER commands end */
10409 DEFUN (no_ospf_route_aggregation_timer
,
10410 no_ospf_route_aggregation_timer_cmd
,
10411 "no aggregation timer",
10413 "External route aggregation\n"
10416 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10418 ospf_external_aggregator_timer_set(ospf
, OSPF_EXTL_AGGR_DEFAULT_DELAY
);
10420 return CMD_SUCCESS
;
10423 /* External Route Aggregation End */
10425 static void config_write_stub_router(struct vty
*vty
, struct ospf
*ospf
)
10427 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
10428 vty_out(vty
, " max-metric router-lsa on-startup %u\n",
10429 ospf
->stub_router_startup_time
);
10430 if (ospf
->stub_router_shutdown_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
10431 vty_out(vty
, " max-metric router-lsa on-shutdown %u\n",
10432 ospf
->stub_router_shutdown_time
);
10433 if (ospf
->stub_router_admin_set
== OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
)
10434 vty_out(vty
, " max-metric router-lsa administrative\n");
10439 static void show_ip_ospf_route_network(struct vty
*vty
, struct ospf
*ospf
,
10440 struct route_table
*rt
,
10443 struct route_node
*rn
;
10444 struct ospf_route
* or ;
10445 struct listnode
*pnode
, *pnnode
;
10446 struct ospf_path
*path
;
10447 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
10448 *json_nexthop
= NULL
;
10452 "============ OSPF network routing table ============\n");
10454 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
10455 char buf1
[PREFIX2STR_BUFFER
];
10457 if ((or = rn
->info
) == NULL
)
10460 prefix2str(&rn
->p
, buf1
, sizeof(buf1
));
10463 json_route
= json_object_new_object();
10464 json_object_object_add(json
, buf1
, json_route
);
10467 switch (or->path_type
) {
10468 case OSPF_PATH_INTER_AREA
:
10469 if (or->type
== OSPF_DESTINATION_NETWORK
) {
10471 json_object_string_add(json_route
,
10474 json_object_int_add(json_route
, "cost",
10476 json_object_string_addf(
10477 json_route
, "area", "%pI4",
10478 &or->u
.std
.area_id
);
10481 "N IA %-18s [%d] area: %pI4\n",
10483 &or->u
.std
.area_id
);
10485 } else if (or->type
== OSPF_DESTINATION_DISCARD
) {
10487 json_object_string_add(json_route
,
10492 "D IA %-18s Discard entry\n",
10497 case OSPF_PATH_INTRA_AREA
:
10499 json_object_string_add(json_route
, "routeType",
10501 json_object_int_add(json_route
, "cost",
10503 json_object_string_addf(json_route
, "area",
10505 &or->u
.std
.area_id
);
10507 vty_out(vty
, "N %-18s [%d] area: %pI4\n",
10509 &or->u
.std
.area_id
);
10516 if (or->type
== OSPF_DESTINATION_NETWORK
) {
10518 json_nexthop_array
= json_object_new_array();
10519 json_object_object_add(json_route
, "nexthops",
10520 json_nexthop_array
);
10523 for (ALL_LIST_ELEMENTS(or->paths
, pnode
, pnnode
,
10526 json_nexthop
= json_object_new_object();
10527 json_object_array_add(
10528 json_nexthop_array
,
10531 if (if_lookup_by_index(path
->ifindex
,
10534 if (path
->nexthop
.s_addr
10537 json_object_string_add(
10540 json_object_string_add(
10542 "directlyAttachedTo",
10548 "%24s directly attached to %s\n",
10556 json_object_string_addf(
10560 json_object_string_add(
10568 "%24s via %pI4, %s\n",
10581 vty_out(vty
, "\n");
10584 static void show_ip_ospf_route_router(struct vty
*vty
, struct ospf
*ospf
,
10585 struct route_table
*rtrs
,
10588 struct route_node
*rn
;
10589 struct ospf_route
* or ;
10590 struct listnode
*pnode
;
10591 struct listnode
*node
;
10592 struct ospf_path
*path
;
10593 char buf
[PREFIX_STRLEN
];
10594 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
10595 *json_nexthop
= NULL
;
10598 vty_out(vty
, "============ OSPF %s table =============\n",
10599 ospf
->all_rtrs
== rtrs
? "reachable routers"
10600 : "router routing");
10602 for (rn
= route_top(rtrs
); rn
; rn
= route_next(rn
)) {
10603 if (rn
->info
== NULL
)
10608 json_route
= json_object_new_object();
10609 json_object_object_add(
10610 json
, inet_ntop(AF_INET
, &rn
->p
.u
.prefix4
,
10613 json_object_string_add(json_route
, "routeType", "R ");
10615 vty_out(vty
, "R %-15pI4 ",
10619 for (ALL_LIST_ELEMENTS_RO((struct list
*)rn
->info
, node
, or)) {
10622 vty_out(vty
, "%24s", "");
10627 json_object_int_add(json_route
, "cost",
10629 json_object_string_addf(json_route
, "area",
10631 &or->u
.std
.area_id
);
10632 if (or->path_type
== OSPF_PATH_INTER_AREA
) {
10633 json_object_boolean_true_add(json_route
,
10635 json_object_boolean_true_add(json_route
,
10638 if (or->u
.std
.flags
& ROUTER_LSA_BORDER
)
10639 json_object_string_add(json_route
,
10642 else if (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
)
10643 json_object_string_add(json_route
,
10647 vty_out(vty
, "%s [%d] area: %pI4",
10648 (or->path_type
== OSPF_PATH_INTER_AREA
10651 or->cost
, &or->u
.std
.area_id
);
10653 vty_out(vty
, "%s%s\n",
10654 (or->u
.std
.flags
& ROUTER_LSA_BORDER
10657 (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
10663 json_nexthop_array
= json_object_new_array();
10664 json_object_object_add(json_route
, "nexthops",
10665 json_nexthop_array
);
10668 for (ALL_LIST_ELEMENTS_RO(or->paths
, pnode
, path
)) {
10670 json_nexthop
= json_object_new_object();
10671 json_object_array_add(
10672 json_nexthop_array
,
10675 if (if_lookup_by_index(path
->ifindex
,
10677 if (path
->nexthop
.s_addr
10680 json_object_string_add(
10683 json_object_string_add(
10685 "directlyAttachedTo",
10691 "%24s directly attached to %s\n",
10699 json_object_string_addf(
10703 json_object_string_add(
10711 "%24s via %pI4, %s\n",
10724 vty_out(vty
, "\n");
10727 static void show_ip_ospf_route_external(struct vty
*vty
, struct ospf
*ospf
,
10728 struct route_table
*rt
,
10731 struct route_node
*rn
;
10732 struct ospf_route
*er
;
10733 struct listnode
*pnode
, *pnnode
;
10734 struct ospf_path
*path
;
10735 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
10736 *json_nexthop
= NULL
;
10740 "============ OSPF external routing table ===========\n");
10742 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
10743 if ((er
= rn
->info
) == NULL
)
10748 snprintfrr(buf1
, sizeof(buf1
), "%pFX", &rn
->p
);
10750 json_route
= json_object_new_object();
10751 json_object_object_add(json
, buf1
, json_route
);
10754 switch (er
->path_type
) {
10755 case OSPF_PATH_TYPE1_EXTERNAL
:
10757 json_object_string_add(json_route
, "routeType",
10759 json_object_int_add(json_route
, "cost",
10761 json_object_int_add(json_route
, "tag",
10765 "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI
10767 buf1
, er
->cost
, er
->u
.ext
.tag
);
10770 case OSPF_PATH_TYPE2_EXTERNAL
:
10772 json_object_string_add(json_route
, "routeType",
10774 json_object_int_add(json_route
, "cost",
10776 json_object_int_add(json_route
, "type2cost",
10777 er
->u
.ext
.type2_cost
);
10778 json_object_int_add(json_route
, "tag",
10782 "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI
10784 buf1
, er
->cost
, er
->u
.ext
.type2_cost
,
10791 json_nexthop_array
= json_object_new_array();
10792 json_object_object_add(json_route
, "nexthops",
10793 json_nexthop_array
);
10796 for (ALL_LIST_ELEMENTS(er
->paths
, pnode
, pnnode
, path
)) {
10798 json_nexthop
= json_object_new_object();
10799 json_object_array_add(json_nexthop_array
,
10803 if (if_lookup_by_index(path
->ifindex
, ospf
->vrf_id
)) {
10804 if (path
->nexthop
.s_addr
== INADDR_ANY
) {
10806 json_object_string_add(
10807 json_nexthop
, "ip",
10809 json_object_string_add(
10811 "directlyAttachedTo",
10817 "%24s directly attached to %s\n",
10825 json_object_string_addf(
10826 json_nexthop
, "ip",
10827 "%pI4", &path
->nexthop
);
10828 json_object_string_add(
10829 json_nexthop
, "via",
10835 "%24s via %pI4, %s\n",
10847 vty_out(vty
, "\n");
10850 static int show_ip_ospf_reachable_routers_common(struct vty
*vty
,
10854 if (ospf
->instance
)
10855 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
10857 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
10859 if (ospf
->all_rtrs
== NULL
) {
10860 vty_out(vty
, "No OSPF reachable router information exist\n");
10861 return CMD_SUCCESS
;
10864 /* Show Router routes. */
10865 show_ip_ospf_route_router(vty
, ospf
, ospf
->all_rtrs
, NULL
);
10867 vty_out(vty
, "\n");
10869 return CMD_SUCCESS
;
10872 DEFUN (show_ip_ospf_reachable_routers
,
10873 show_ip_ospf_reachable_routers_cmd
,
10874 "show ip ospf [vrf <NAME|all>] reachable-routers",
10877 "OSPF information\n"
10880 "Show all the reachable OSPF routers\n")
10882 struct ospf
*ospf
= NULL
;
10883 struct listnode
*node
= NULL
;
10884 char *vrf_name
= NULL
;
10885 bool all_vrf
= false;
10886 int ret
= CMD_SUCCESS
;
10889 uint8_t use_vrf
= 0;
10891 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
10894 bool ospf_output
= false;
10899 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
10900 if (!ospf
->oi_running
)
10903 ospf_output
= true;
10904 ret
= show_ip_ospf_reachable_routers_common(
10905 vty
, ospf
, use_vrf
);
10909 vty_out(vty
, "%% OSPF instance not found\n");
10911 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
10912 if (ospf
== NULL
|| !ospf
->oi_running
) {
10913 vty_out(vty
, "%% OSPF instance not found\n");
10914 return CMD_SUCCESS
;
10917 ret
= show_ip_ospf_reachable_routers_common(vty
, ospf
,
10921 /* Display default ospf (instance 0) info */
10922 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
10923 if (ospf
== NULL
|| !ospf
->oi_running
) {
10924 vty_out(vty
, "%% OSPF instance not found\n");
10925 return CMD_SUCCESS
;
10928 ret
= show_ip_ospf_reachable_routers_common(vty
, ospf
, use_vrf
);
10934 DEFUN (show_ip_ospf_instance_reachable_routers
,
10935 show_ip_ospf_instance_reachable_routers_cmd
,
10936 "show ip ospf (1-65535) reachable-routers",
10939 "OSPF information\n"
10941 "Show all the reachable OSPF routers\n")
10943 int idx_number
= 3;
10945 unsigned short instance
= 0;
10947 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
10948 if (instance
!= ospf_instance
)
10949 return CMD_NOT_MY_INSTANCE
;
10951 ospf
= ospf_lookup_instance(instance
);
10952 if (!ospf
|| !ospf
->oi_running
)
10953 return CMD_SUCCESS
;
10955 return show_ip_ospf_reachable_routers_common(vty
, ospf
, 0);
10958 static int show_ip_ospf_border_routers_common(struct vty
*vty
,
10963 json_object
*json_vrf
= NULL
;
10964 json_object
*json_router
= NULL
;
10968 json_vrf
= json_object_new_object();
10971 json_router
= json_object_new_object();
10974 if (ospf
->instance
) {
10976 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
10978 json_object_int_add(json_vrf
, "ospfInstance",
10982 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
10984 if (ospf
->new_table
== NULL
) {
10986 vty_out(vty
, "No OSPF routing information exist\n");
10988 json_object_free(json_router
);
10990 json_object_free(json_vrf
);
10992 return CMD_SUCCESS
;
10995 /* Show Network routes.
10996 show_ip_ospf_route_network (vty, ospf->new_table); */
10998 /* Show Router routes. */
10999 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, json_router
);
11002 json_object_object_add(json_vrf
, "routers", json_router
);
11004 if (ospf
->vrf_id
== VRF_DEFAULT
)
11005 json_object_object_add(json
, "default",
11008 json_object_object_add(json
, ospf
->name
,
11012 vty_out(vty
, "\n");
11015 return CMD_SUCCESS
;
11018 DEFPY (show_ip_ospf_border_routers
,
11019 show_ip_ospf_border_routers_cmd
,
11020 "show ip ospf [vrf <NAME|all>] border-routers [json]",
11023 "OSPF information\n"
11026 "Show all the ABR's and ASBR's\n"
11029 struct ospf
*ospf
= NULL
;
11030 struct listnode
*node
= NULL
;
11031 char *vrf_name
= NULL
;
11032 bool all_vrf
= false;
11033 int ret
= CMD_SUCCESS
;
11036 uint8_t use_vrf
= 0;
11037 bool uj
= use_json(argc
, argv
);
11038 json_object
*json
= NULL
;
11041 json
= json_object_new_object();
11043 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11046 bool ospf_output
= false;
11051 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11052 if (!ospf
->oi_running
)
11055 ospf_output
= true;
11056 ret
= show_ip_ospf_border_routers_common(
11057 vty
, ospf
, use_vrf
, json
);
11061 vty_json(vty
, json
);
11062 else if (!ospf_output
)
11063 vty_out(vty
, "%% OSPF is not enabled\n");
11067 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11068 if (ospf
== NULL
|| !ospf
->oi_running
) {
11070 vty_json(vty
, json
);
11073 "%% OSPF is not enabled in vrf %s\n",
11076 return CMD_SUCCESS
;
11080 /* Display default ospf (instance 0) info */
11081 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11082 if (ospf
== NULL
|| !ospf
->oi_running
) {
11084 vty_json(vty
, json
);
11087 "%% OSPF is not enabled in vrf default\n");
11089 return CMD_SUCCESS
;
11094 ret
= show_ip_ospf_border_routers_common(vty
, ospf
, use_vrf
,
11097 vty_json(vty
, json
);
11103 DEFUN (show_ip_ospf_instance_border_routers
,
11104 show_ip_ospf_instance_border_routers_cmd
,
11105 "show ip ospf (1-65535) border-routers",
11108 "OSPF information\n"
11110 "Show all the ABR's and ASBR's\n")
11112 int idx_number
= 3;
11114 unsigned short instance
= 0;
11116 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
11117 if (instance
!= ospf_instance
)
11118 return CMD_NOT_MY_INSTANCE
;
11120 ospf
= ospf_lookup_instance(instance
);
11121 if (!ospf
|| !ospf
->oi_running
)
11122 return CMD_SUCCESS
;
11124 return show_ip_ospf_border_routers_common(vty
, ospf
, 0, NULL
);
11127 static int show_ip_ospf_route_common(struct vty
*vty
, struct ospf
*ospf
,
11128 json_object
*json
, uint8_t use_vrf
)
11130 json_object
*json_vrf
= NULL
;
11132 if (ospf
->instance
)
11133 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
11138 json_vrf
= json_object_new_object();
11143 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
11145 if (ospf
->new_table
== NULL
) {
11148 json_object_free(json_vrf
);
11150 vty_out(vty
, "No OSPF routing information exist\n");
11152 return CMD_SUCCESS
;
11155 /* Show Network routes. */
11156 show_ip_ospf_route_network(vty
, ospf
, ospf
->new_table
, json_vrf
);
11158 /* Show Router routes. */
11159 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, json_vrf
);
11161 /* Show Router routes. */
11162 if (ospf
->all_rtrs
)
11163 show_ip_ospf_route_router(vty
, ospf
, ospf
->all_rtrs
, json_vrf
);
11165 /* Show AS External routes. */
11166 show_ip_ospf_route_external(vty
, ospf
, ospf
->old_external_route
,
11171 // json_object_object_add(json_vrf, "areas",
11173 json_object_object_add(json
, ospf_get_name(ospf
),
11177 vty_out(vty
, "\n");
11180 return CMD_SUCCESS
;
11183 DEFUN (show_ip_ospf_route
,
11184 show_ip_ospf_route_cmd
,
11185 "show ip ospf [vrf <NAME|all>] route [json]",
11188 "OSPF information\n"
11191 "OSPF routing table\n"
11194 struct ospf
*ospf
= NULL
;
11195 struct listnode
*node
= NULL
;
11196 char *vrf_name
= NULL
;
11197 bool all_vrf
= false;
11198 int ret
= CMD_SUCCESS
;
11201 uint8_t use_vrf
= 0;
11202 bool uj
= use_json(argc
, argv
);
11203 json_object
*json
= NULL
;
11206 json
= json_object_new_object();
11208 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11210 /* vrf input is provided could be all or specific vrf*/
11212 bool ospf_output
= false;
11217 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11218 if (!ospf
->oi_running
)
11220 ospf_output
= true;
11221 ret
= show_ip_ospf_route_common(vty
, ospf
, json
,
11226 /* Keep Non-pretty format */
11227 vty_json(vty
, json
);
11228 } else if (!ospf_output
)
11229 vty_out(vty
, "%% OSPF is not enabled\n");
11233 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11234 if (ospf
== NULL
|| !ospf
->oi_running
) {
11236 vty_json(vty
, json
);
11239 "%% OSPF is not enabled in vrf %s\n",
11242 return CMD_SUCCESS
;
11245 /* Display default ospf (instance 0) info */
11246 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11247 if (ospf
== NULL
|| !ospf
->oi_running
) {
11249 vty_json(vty
, json
);
11252 "%% OSPF is not enabled in vrf default\n");
11254 return CMD_SUCCESS
;
11259 ret
= show_ip_ospf_route_common(vty
, ospf
, json
, use_vrf
);
11260 /* Keep Non-pretty format */
11262 vty_out(vty
, "%s\n",
11263 json_object_to_json_string_ext(
11264 json
, JSON_C_TO_STRING_NOSLASHESCAPE
));
11268 json_object_free(json
);
11273 DEFUN (show_ip_ospf_instance_route
,
11274 show_ip_ospf_instance_route_cmd
,
11275 "show ip ospf (1-65535) route",
11278 "OSPF information\n"
11280 "OSPF routing table\n")
11282 int idx_number
= 3;
11284 unsigned short instance
= 0;
11286 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
11287 if (instance
!= ospf_instance
)
11288 return CMD_NOT_MY_INSTANCE
;
11290 ospf
= ospf_lookup_instance(instance
);
11291 if (!ospf
|| !ospf
->oi_running
)
11292 return CMD_SUCCESS
;
11294 return show_ip_ospf_route_common(vty
, ospf
, NULL
, 0);
11298 DEFUN (show_ip_ospf_vrfs
,
11299 show_ip_ospf_vrfs_cmd
,
11300 "show ip ospf vrfs [json]",
11303 "OSPF information\n"
11304 "Show OSPF VRFs \n"
11307 bool uj
= use_json(argc
, argv
);
11308 json_object
*json
= NULL
;
11309 json_object
*json_vrfs
= NULL
;
11310 struct ospf
*ospf
= NULL
;
11311 struct listnode
*node
= NULL
;
11313 static const char header
[] = "Name Id RouterId ";
11316 json
= json_object_new_object();
11317 json_vrfs
= json_object_new_object();
11320 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11321 json_object
*json_vrf
= NULL
;
11322 const char *name
= NULL
;
11323 int64_t vrf_id_ui
= 0;
11327 if (!uj
&& count
== 1)
11328 vty_out(vty
, "%s\n", header
);
11330 json_vrf
= json_object_new_object();
11332 name
= ospf_get_name(ospf
);
11334 vrf_id_ui
= (ospf
->vrf_id
== VRF_UNKNOWN
)
11336 : (int64_t)ospf
->vrf_id
;
11339 json_object_int_add(json_vrf
, "vrfId", vrf_id_ui
);
11340 json_object_string_addf(json_vrf
, "routerId", "%pI4",
11343 json_object_object_add(json_vrfs
, name
, json_vrf
);
11346 vty_out(vty
, "%-25s %-5d %-16pI4 \n", name
,
11347 ospf
->vrf_id
, &ospf
->router_id
);
11352 json_object_object_add(json
, "vrfs", json_vrfs
);
11353 json_object_int_add(json
, "totalVrfs", count
);
11355 vty_json(vty
, json
);
11358 vty_out(vty
, "\nTotal number of OSPF VRFs: %d\n",
11362 return CMD_SUCCESS
;
11364 DEFPY (clear_ip_ospf_neighbor
,
11365 clear_ip_ospf_neighbor_cmd
,
11366 "clear ip ospf [(1-65535)]$instance neighbor [A.B.C.D$nbr_id]",
11369 "OSPF information\n"
11371 "Reset OSPF Neighbor\n"
11374 struct listnode
*node
;
11375 struct ospf
*ospf
= NULL
;
11377 /* If user does not specify the arguments,
11378 * instance = 0 and nbr_id = 0.0.0.0
11380 if (instance
!= 0) {
11381 /* This means clear only the particular ospf process */
11382 if (instance
!= ospf_instance
)
11383 return CMD_NOT_MY_INSTANCE
;
11386 /* Clear all the ospf processes */
11387 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11388 if (!ospf
->oi_running
)
11391 if (nbr_id_str
&& IPV4_ADDR_SAME(&ospf
->router_id
, &nbr_id
)) {
11392 vty_out(vty
, "Self router-id is not allowed.\r\n ");
11393 return CMD_SUCCESS
;
11396 ospf_neighbor_reset(ospf
, nbr_id
, nbr_id_str
);
11399 return CMD_SUCCESS
;
11402 DEFPY (clear_ip_ospf_process
,
11403 clear_ip_ospf_process_cmd
,
11404 "clear ip ospf [(1-65535)]$instance process",
11407 "OSPF information\n"
11409 "Reset OSPF Process\n")
11411 struct listnode
*node
;
11412 struct ospf
*ospf
= NULL
;
11414 /* Check if instance is not passed as an argument */
11415 if (instance
!= 0) {
11416 /* This means clear only the particular ospf process */
11417 if (instance
!= ospf_instance
)
11418 return CMD_NOT_MY_INSTANCE
;
11421 /* Clear all the ospf processes */
11422 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11423 if (!ospf
->oi_running
)
11426 ospf_process_reset(ospf
);
11429 return CMD_SUCCESS
;
11432 static const char *const ospf_abr_type_str
[] = {
11433 "unknown", "standard", "ibm", "cisco", "shortcut"
11436 static const char *const ospf_shortcut_mode_str
[] = {
11437 "default", "enable", "disable"
11439 static int ospf_vty_external_rt_walkcb(struct hash_bucket
*bucket
,
11442 struct external_info
*ei
= bucket
->data
;
11443 struct vty
*vty
= (struct vty
*)arg
;
11444 static unsigned int count
;
11446 vty_out(vty
, "%-4pI4/%d, ", &ei
->p
.prefix
, ei
->p
.prefixlen
);
11449 if (count
% 5 == 0)
11450 vty_out(vty
, "\n");
11452 if (OSPF_EXTERNAL_RT_COUNT(ei
->aggr_route
) == count
)
11455 return HASHWALK_CONTINUE
;
11458 static int ospf_json_external_rt_walkcb(struct hash_bucket
*bucket
,
11461 struct external_info
*ei
= bucket
->data
;
11462 struct json_object
*json
= (struct json_object
*)arg
;
11463 char buf
[PREFIX2STR_BUFFER
];
11465 static unsigned int count
;
11467 prefix2str(&ei
->p
, buf
, sizeof(buf
));
11469 snprintf(exnalbuf
, 20, "Exnl Addr-%d", count
);
11471 json_object_string_add(json
, exnalbuf
, buf
);
11475 if (OSPF_EXTERNAL_RT_COUNT(ei
->aggr_route
) == count
)
11478 return HASHWALK_CONTINUE
;
11481 static int ospf_show_summary_address(struct vty
*vty
, struct ospf
*ospf
,
11482 uint8_t use_vrf
, json_object
*json
,
11483 bool uj
, bool detail
)
11485 struct route_node
*rn
;
11486 json_object
*json_vrf
= NULL
;
11489 static char header
[] =
11490 "Summary-address Metric-type Metric Tag External_Rt_count\n";
11492 mtype
= metric_type(ospf
, 0, ospf
->instance
);
11493 mval
= metric_value(ospf
, 0, ospf
->instance
);
11496 vty_out(vty
, "%s\n", header
);
11500 json_vrf
= json_object_new_object();
11505 if (ospf
->instance
) {
11507 json_object_int_add(json
, "ospfInstance",
11510 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
11513 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
11516 vty_out(vty
, "aggregation delay interval :%u(in seconds)\n\n",
11517 ospf
->aggr_delay_interval
);
11519 json_object_int_add(json_vrf
, "aggregationDelayInterval",
11520 ospf
->aggr_delay_interval
);
11523 for (rn
= route_top(ospf
->rt_aggr_tbl
); rn
; rn
= route_next(rn
))
11525 struct ospf_external_aggr_rt
*aggr
= rn
->info
;
11526 json_object
*json_aggr
= NULL
;
11527 char buf
[PREFIX2STR_BUFFER
];
11529 prefix2str(&aggr
->p
, buf
, sizeof(buf
));
11533 json_aggr
= json_object_new_object();
11535 json_object_object_add(json_vrf
, buf
,
11537 json_object_string_add(json_aggr
,
11538 "summaryAddress", buf
);
11539 json_object_string_add(
11540 json_aggr
, "metricType",
11541 (mtype
== EXTERNAL_METRIC_TYPE_1
)
11545 json_object_int_add(json_aggr
, "metric", mval
);
11546 json_object_int_add(json_aggr
, "tag",
11548 json_object_int_add(
11549 json_aggr
, "externalRouteCount",
11550 OSPF_EXTERNAL_RT_COUNT(aggr
));
11552 if (OSPF_EXTERNAL_RT_COUNT(aggr
) && detail
) {
11554 aggr
->match_extnl_hash
,
11555 ospf_json_external_rt_walkcb
,
11560 vty_out(vty
, "%-20s", buf
);
11562 (mtype
== EXTERNAL_METRIC_TYPE_1
)
11563 ? vty_out(vty
, "%-16s", "E1")
11564 : vty_out(vty
, "%-16s", "E2");
11565 vty_out(vty
, "%-11d", mval
);
11567 vty_out(vty
, "%-12u", aggr
->tag
);
11569 vty_out(vty
, "%-5ld\n",
11570 OSPF_EXTERNAL_RT_COUNT(aggr
));
11572 if (OSPF_EXTERNAL_RT_COUNT(aggr
) && detail
) {
11574 "Matched External routes:\n");
11576 aggr
->match_extnl_hash
,
11577 ospf_vty_external_rt_walkcb
,
11579 vty_out(vty
, "\n");
11582 vty_out(vty
, "\n");
11588 json_object_object_add(json
, ospf_get_name(ospf
),
11591 vty_out(vty
, "\n");
11593 return CMD_SUCCESS
;
11596 DEFUN (show_ip_ospf_external_aggregator
,
11597 show_ip_ospf_external_aggregator_cmd
,
11598 "show ip ospf [vrf <NAME|all>] summary-address [detail] [json]",
11600 "OSPF information\n"
11603 "Show external summary addresses\n"
11604 "Detailed information\n"
11607 char *vrf_name
= NULL
;
11608 bool all_vrf
= false;
11609 int ret
= CMD_SUCCESS
;
11612 uint8_t use_vrf
= 0;
11613 bool uj
= use_json(argc
, argv
);
11614 struct ospf
*ospf
= NULL
;
11615 json_object
*json
= NULL
;
11616 struct listnode
*node
= NULL
;
11618 bool detail
= false;
11620 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11622 if (argv_find(argv
, argc
, "detail", &idx
))
11626 json
= json_object_new_object();
11628 /* vrf input is provided */
11632 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11633 if (!ospf
->oi_running
)
11635 ret
= ospf_show_summary_address(
11636 vty
, ospf
, use_vrf
, json
, uj
, detail
);
11640 vty_json(vty
, json
);
11645 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11647 if (ospf
== NULL
|| !ospf
->oi_running
) {
11649 vty_json(vty
, json
);
11652 "%% OSPF is not enabled in vrf %s\n",
11655 return CMD_SUCCESS
;
11657 ospf_show_summary_address(vty
, ospf
, use_vrf
, json
, uj
, detail
);
11661 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11662 if (ospf
== NULL
|| !ospf
->oi_running
) {
11664 vty_json(vty
, json
);
11667 "%% OSPF is not enabled in vrf default\n");
11669 return CMD_SUCCESS
;
11672 ospf_show_summary_address(vty
, ospf
, use_vrf
, json
, uj
, detail
);
11676 vty_json(vty
, json
);
11677 return CMD_SUCCESS
;
11680 static const char *const ospf_int_type_str
[] = {
11681 "unknown", /* should never be used. */
11685 "point-to-multipoint",
11686 "virtual-link", /* should never be used. */
11690 static const char *interface_config_auth_str(struct ospf_if_params
*params
)
11692 if (!OSPF_IF_PARAM_CONFIGURED(params
, auth_type
)
11693 || params
->auth_type
== OSPF_AUTH_NOTSET
)
11696 /* Translation tables are not that much help
11697 * here due to syntax
11698 * of the simple option */
11699 switch (params
->auth_type
) {
11701 case OSPF_AUTH_NULL
:
11704 case OSPF_AUTH_SIMPLE
:
11707 case OSPF_AUTH_CRYPTOGRAPHIC
:
11708 return " message-digest";
11714 static int config_write_interface_one(struct vty
*vty
, struct vrf
*vrf
)
11716 struct listnode
*node
;
11717 struct interface
*ifp
;
11718 struct crypt_key
*ck
;
11719 struct route_node
*rn
= NULL
;
11720 struct ospf_if_params
*params
;
11721 const char *auth_str
;
11724 FOR_ALL_INTERFACES (vrf
, ifp
) {
11726 if (memcmp(ifp
->name
, "VLINK", 5) == 0)
11729 if_vty_config_start(vty
, ifp
);
11732 vty_out(vty
, " description %s\n", ifp
->desc
);
11736 params
= IF_DEF_PARAMS(ifp
);
11739 /* Interface Network print. */
11740 if (OSPF_IF_PARAM_CONFIGURED(params
, type
)
11741 && params
->type
!= OSPF_IFTYPE_LOOPBACK
) {
11742 if (params
->type
!= ospf_default_iftype(ifp
)) {
11743 vty_out(vty
, " ip ospf network %s",
11747 == OSPF_IFTYPE_POINTOPOINT
11748 && params
->ptp_dmvpn
)
11749 vty_out(vty
, " dmvpn");
11750 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11751 vty_out(vty
, " %pI4",
11753 vty_out(vty
, "\n");
11757 /* OSPF interface authentication print */
11758 auth_str
= interface_config_auth_str(params
);
11760 vty_out(vty
, " ip ospf authentication%s",
11762 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11763 vty_out(vty
, " %pI4",
11765 vty_out(vty
, "\n");
11768 /* Simple Authentication Password print. */
11769 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_simple
)
11770 && params
->auth_simple
[0] != '\0') {
11771 vty_out(vty
, " ip ospf authentication-key %s",
11772 params
->auth_simple
);
11773 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11774 vty_out(vty
, " %pI4",
11776 vty_out(vty
, "\n");
11779 /* Cryptographic Authentication Key print. */
11780 if (params
&& params
->auth_crypt
) {
11781 for (ALL_LIST_ELEMENTS_RO(params
->auth_crypt
,
11784 " ip ospf message-digest-key %d md5 %s",
11785 ck
->key_id
, ck
->auth_key
);
11786 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11787 vty_out(vty
, " %pI4",
11789 vty_out(vty
, "\n");
11793 /* Interface Output Cost print. */
11794 if (OSPF_IF_PARAM_CONFIGURED(params
, output_cost_cmd
)) {
11795 vty_out(vty
, " ip ospf cost %u",
11796 params
->output_cost_cmd
);
11797 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11798 vty_out(vty
, " %pI4",
11800 vty_out(vty
, "\n");
11803 /* Hello Interval print. */
11804 if (OSPF_IF_PARAM_CONFIGURED(params
, v_hello
)
11805 && params
->v_hello
!= OSPF_HELLO_INTERVAL_DEFAULT
) {
11806 vty_out(vty
, " ip ospf hello-interval %u",
11808 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11809 vty_out(vty
, " %pI4",
11811 vty_out(vty
, "\n");
11815 /* Router Dead Interval print. */
11816 if (OSPF_IF_PARAM_CONFIGURED(params
, v_wait
)
11817 && params
->is_v_wait_set
) {
11818 vty_out(vty
, " ip ospf dead-interval ");
11821 if (OSPF_IF_PARAM_CONFIGURED(params
,
11824 "minimal hello-multiplier %d",
11825 params
->fast_hello
);
11827 vty_out(vty
, "%u", params
->v_wait
);
11829 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11830 vty_out(vty
, " %pI4",
11832 vty_out(vty
, "\n");
11835 /* Router Priority print. */
11836 if (OSPF_IF_PARAM_CONFIGURED(params
, priority
)
11837 && params
->priority
11838 != OSPF_ROUTER_PRIORITY_DEFAULT
) {
11839 vty_out(vty
, " ip ospf priority %u",
11841 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11842 vty_out(vty
, " %pI4",
11844 vty_out(vty
, "\n");
11847 /* Retransmit Interval print. */
11848 if (OSPF_IF_PARAM_CONFIGURED(params
,
11849 retransmit_interval
)
11850 && params
->retransmit_interval
11851 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
) {
11852 vty_out(vty
, " ip ospf retransmit-interval %u",
11853 params
->retransmit_interval
);
11854 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11855 vty_out(vty
, " %pI4",
11857 vty_out(vty
, "\n");
11860 /* Transmit Delay print. */
11861 if (OSPF_IF_PARAM_CONFIGURED(params
, transmit_delay
)
11862 && params
->transmit_delay
11863 != OSPF_TRANSMIT_DELAY_DEFAULT
) {
11864 vty_out(vty
, " ip ospf transmit-delay %u",
11865 params
->transmit_delay
);
11866 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11867 vty_out(vty
, " %pI4",
11869 vty_out(vty
, "\n");
11873 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
11875 vty_out(vty
, " ip ospf %d",
11878 vty_out(vty
, " ip ospf");
11880 char buf
[INET_ADDRSTRLEN
];
11882 area_id2str(buf
, sizeof(buf
), ¶ms
->if_area
,
11883 params
->if_area_id_fmt
);
11884 vty_out(vty
, " area %s", buf
);
11885 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11886 vty_out(vty
, " %pI4",
11888 vty_out(vty
, "\n");
11892 if (params
&& params
->bfd_config
)
11893 ospf_bfd_write_config(vty
, params
);
11895 /* MTU ignore print. */
11896 if (OSPF_IF_PARAM_CONFIGURED(params
, mtu_ignore
)
11897 && params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
) {
11898 if (params
->mtu_ignore
== 0)
11899 vty_out(vty
, " no ip ospf mtu-ignore");
11901 vty_out(vty
, " ip ospf mtu-ignore");
11902 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11903 vty_out(vty
, " %pI4",
11905 vty_out(vty
, "\n");
11908 if (OSPF_IF_PARAM_CONFIGURED(params
,
11909 passive_interface
)) {
11910 vty_out(vty
, " %sip ospf passive",
11911 params
->passive_interface
11915 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11916 vty_out(vty
, " %pI4", &rn
->p
.u
.prefix4
);
11917 vty_out(vty
, "\n");
11920 /* LDP-Sync print */
11921 if (params
&& params
->ldp_sync_info
)
11922 ospf_ldp_sync_if_write_config(vty
, params
);
11926 rn
= route_top(IF_OIFS_PARAMS(ifp
));
11928 rn
= route_next(rn
);
11933 if (params
!= NULL
)
11938 ospf_opaque_config_write_if(vty
, ifp
);
11940 if_vty_config_end(vty
);
11946 /* Configuration write function for ospfd. */
11947 static int config_write_interface(struct vty
*vty
)
11950 struct vrf
*vrf
= NULL
;
11952 /* Display all VRF aware OSPF interface configuration */
11953 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
11954 write
+= config_write_interface_one(vty
, vrf
);
11960 static int config_write_network_area(struct vty
*vty
, struct ospf
*ospf
)
11962 struct route_node
*rn
;
11963 char buf
[INET_ADDRSTRLEN
];
11965 /* `network area' print. */
11966 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
))
11968 struct ospf_network
*n
= rn
->info
;
11970 /* Create Area ID string by specified Area ID format. */
11971 if (n
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
11972 inet_ntop(AF_INET
, &n
->area_id
, buf
,
11975 snprintf(buf
, sizeof(buf
), "%lu",
11976 (unsigned long int)ntohl(
11977 n
->area_id
.s_addr
));
11979 /* Network print. */
11980 vty_out(vty
, " network %pFX area %s\n", &rn
->p
, buf
);
11986 static int config_write_ospf_area(struct vty
*vty
, struct ospf
*ospf
)
11988 struct listnode
*node
;
11989 struct ospf_area
*area
;
11990 char buf
[INET_ADDRSTRLEN
];
11992 /* Area configuration print. */
11993 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
11994 struct route_node
*rn1
;
11996 area_id2str(buf
, sizeof(buf
), &area
->area_id
,
11997 area
->area_id_fmt
);
11999 if (area
->auth_type
!= OSPF_AUTH_NULL
) {
12000 if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
12001 vty_out(vty
, " area %s authentication\n", buf
);
12004 " area %s authentication message-digest\n",
12008 if (area
->shortcut_configured
!= OSPF_SHORTCUT_DEFAULT
)
12009 vty_out(vty
, " area %s shortcut %s\n", buf
,
12010 ospf_shortcut_mode_str
12011 [area
->shortcut_configured
]);
12013 if ((area
->external_routing
== OSPF_AREA_STUB
)
12014 || (area
->external_routing
== OSPF_AREA_NSSA
)) {
12015 if (area
->external_routing
== OSPF_AREA_STUB
) {
12016 vty_out(vty
, " area %s stub", buf
);
12017 if (area
->no_summary
)
12018 vty_out(vty
, " no-summary\n");
12019 vty_out(vty
, "\n");
12020 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
12021 vty_out(vty
, " area %s nssa", buf
);
12023 switch (area
->NSSATranslatorRole
) {
12024 case OSPF_NSSA_ROLE_NEVER
:
12025 vty_out(vty
, " translate-never");
12027 case OSPF_NSSA_ROLE_ALWAYS
:
12028 vty_out(vty
, " translate-always");
12030 case OSPF_NSSA_ROLE_CANDIDATE
:
12034 if (area
->nssa_default_originate
.enabled
) {
12036 " default-information-originate");
12037 if (area
->nssa_default_originate
12038 .metric_value
!= -1)
12039 vty_out(vty
, " metric %d",
12040 area
->nssa_default_originate
12042 if (area
->nssa_default_originate
12044 DEFAULT_METRIC_TYPE
)
12045 vty_out(vty
, " metric-type 1");
12048 if (area
->no_summary
)
12049 vty_out(vty
, " no-summary");
12050 if (area
->suppress_fa
)
12051 vty_out(vty
, " suppress-fa");
12052 vty_out(vty
, "\n");
12054 for (rn1
= route_top(area
->nssa_ranges
); rn1
;
12055 rn1
= route_next(rn1
)) {
12056 struct ospf_area_range
*range
;
12062 vty_out(vty
, " area %s nssa range %pFX",
12065 if (range
->cost_config
!=
12066 OSPF_AREA_RANGE_COST_UNSPEC
)
12067 vty_out(vty
, " cost %u",
12068 range
->cost_config
);
12072 OSPF_AREA_RANGE_ADVERTISE
))
12073 vty_out(vty
, " not-advertise");
12075 vty_out(vty
, "\n");
12079 if (area
->default_cost
!= 1)
12080 vty_out(vty
, " area %s default-cost %d\n", buf
,
12081 area
->default_cost
);
12084 for (rn1
= route_top(area
->ranges
); rn1
; rn1
= route_next(rn1
))
12086 struct ospf_area_range
*range
= rn1
->info
;
12088 vty_out(vty
, " area %s range %pFX", buf
,
12091 if (range
->cost_config
12092 != OSPF_AREA_RANGE_COST_UNSPEC
)
12093 vty_out(vty
, " cost %d",
12094 range
->cost_config
);
12096 if (!CHECK_FLAG(range
->flags
,
12097 OSPF_AREA_RANGE_ADVERTISE
))
12098 vty_out(vty
, " not-advertise");
12100 if (CHECK_FLAG(range
->flags
,
12101 OSPF_AREA_RANGE_SUBSTITUTE
))
12102 vty_out(vty
, " substitute %pI4/%d",
12103 &range
->subst_addr
,
12104 range
->subst_masklen
);
12106 vty_out(vty
, "\n");
12109 if (EXPORT_NAME(area
))
12110 vty_out(vty
, " area %s export-list %s\n", buf
,
12111 EXPORT_NAME(area
));
12113 if (IMPORT_NAME(area
))
12114 vty_out(vty
, " area %s import-list %s\n", buf
,
12115 IMPORT_NAME(area
));
12117 if (PREFIX_NAME_IN(area
))
12118 vty_out(vty
, " area %s filter-list prefix %s in\n", buf
,
12119 PREFIX_NAME_IN(area
));
12121 if (PREFIX_NAME_OUT(area
))
12122 vty_out(vty
, " area %s filter-list prefix %s out\n",
12123 buf
, PREFIX_NAME_OUT(area
));
12125 if (area
->fr_info
.configured
)
12126 vty_out(vty
, " area %s flood-reduction\n", buf
);
12132 static int config_write_ospf_nbr_nbma(struct vty
*vty
, struct ospf
*ospf
)
12134 struct ospf_nbr_nbma
*nbr_nbma
;
12135 struct route_node
*rn
;
12137 /* Static Neighbor configuration print. */
12138 for (rn
= route_top(ospf
->nbr_nbma
); rn
; rn
= route_next(rn
))
12139 if ((nbr_nbma
= rn
->info
)) {
12140 vty_out(vty
, " neighbor %pI4", &nbr_nbma
->addr
);
12142 if (nbr_nbma
->priority
12143 != OSPF_NEIGHBOR_PRIORITY_DEFAULT
)
12144 vty_out(vty
, " priority %d",
12145 nbr_nbma
->priority
);
12147 if (nbr_nbma
->v_poll
!= OSPF_POLL_INTERVAL_DEFAULT
)
12148 vty_out(vty
, " poll-interval %d",
12151 vty_out(vty
, "\n");
12157 static int config_write_virtual_link(struct vty
*vty
, struct ospf
*ospf
)
12159 struct listnode
*node
;
12160 struct ospf_vl_data
*vl_data
;
12161 const char *auth_str
;
12162 char buf
[INET_ADDRSTRLEN
];
12164 /* Virtual-Link print */
12165 for (ALL_LIST_ELEMENTS_RO(ospf
->vlinks
, node
, vl_data
)) {
12166 struct listnode
*n2
;
12167 struct crypt_key
*ck
;
12168 struct ospf_interface
*oi
;
12170 if (vl_data
!= NULL
) {
12171 area_id2str(buf
, sizeof(buf
), &vl_data
->vl_area_id
,
12172 vl_data
->vl_area_id_fmt
);
12173 oi
= vl_data
->vl_oi
;
12176 if (OSPF_IF_PARAM(oi
, v_hello
)
12177 != OSPF_HELLO_INTERVAL_DEFAULT
12178 || OSPF_IF_PARAM(oi
, v_wait
)
12179 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
12180 || OSPF_IF_PARAM(oi
, retransmit_interval
)
12181 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
12182 || OSPF_IF_PARAM(oi
, transmit_delay
)
12183 != OSPF_TRANSMIT_DELAY_DEFAULT
)
12185 " area %s virtual-link %pI4 hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n",
12186 buf
, &vl_data
->vl_peer
,
12187 OSPF_IF_PARAM(oi
, v_hello
),
12188 OSPF_IF_PARAM(oi
, retransmit_interval
),
12189 OSPF_IF_PARAM(oi
, transmit_delay
),
12190 OSPF_IF_PARAM(oi
, v_wait
));
12192 vty_out(vty
, " area %s virtual-link %pI4\n", buf
,
12193 &vl_data
->vl_peer
);
12195 auth_str
= interface_config_auth_str(
12196 IF_DEF_PARAMS(oi
->ifp
));
12199 " area %s virtual-link %pI4 authentication%s\n",
12200 buf
, &vl_data
->vl_peer
, auth_str
);
12202 if (IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)->auth_simple
[0]
12205 " area %s virtual-link %pI4 authentication-key %s\n",
12206 buf
, &vl_data
->vl_peer
,
12207 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
12210 for (ALL_LIST_ELEMENTS_RO(
12211 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
12215 " area %s virtual-link %pI4 message-digest-key %d md5 %s\n",
12216 buf
, &vl_data
->vl_peer
,
12217 ck
->key_id
, ck
->auth_key
);
12225 static int config_write_ospf_redistribute(struct vty
*vty
, struct ospf
*ospf
)
12229 /* redistribute print. */
12230 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
12231 struct list
*red_list
;
12232 struct listnode
*node
;
12233 struct ospf_redist
*red
;
12235 red_list
= ospf
->redist
[type
];
12239 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
12240 vty_out(vty
, " redistribute %s",
12241 zebra_route_string(type
));
12243 vty_out(vty
, " %d", red
->instance
);
12245 if (red
->dmetric
.value
>= 0)
12246 vty_out(vty
, " metric %d", red
->dmetric
.value
);
12248 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
12249 vty_out(vty
, " metric-type 1");
12251 if (ROUTEMAP_NAME(red
))
12252 vty_out(vty
, " route-map %s",
12253 ROUTEMAP_NAME(red
));
12255 vty_out(vty
, "\n");
12262 static int ospf_cfg_write_helper_dis_rtr_walkcb(struct hash_bucket
*bucket
,
12265 struct advRtr
*rtr
= bucket
->data
;
12266 struct vty
*vty
= (struct vty
*)arg
;
12268 vty_out(vty
, " graceful-restart helper enable %pI4\n",
12270 return HASHWALK_CONTINUE
;
12273 static void config_write_ospf_gr(struct vty
*vty
, struct ospf
*ospf
)
12275 if (!ospf
->gr_info
.restart_support
)
12278 if (ospf
->gr_info
.grace_period
== OSPF_DFLT_GRACE_INTERVAL
)
12279 vty_out(vty
, " graceful-restart\n");
12281 vty_out(vty
, " graceful-restart grace-period %u\n",
12282 ospf
->gr_info
.grace_period
);
12285 static int config_write_ospf_gr_helper(struct vty
*vty
, struct ospf
*ospf
)
12287 if (ospf
->is_helper_supported
)
12288 vty_out(vty
, " graceful-restart helper enable\n");
12290 if (!ospf
->strict_lsa_check
)
12292 " no graceful-restart helper strict-lsa-checking\n");
12294 if (ospf
->only_planned_restart
)
12295 vty_out(vty
, " graceful-restart helper planned-only\n");
12297 if (ospf
->supported_grace_time
!= OSPF_MAX_GRACE_INTERVAL
)
12299 " graceful-restart helper supported-grace-time %d\n",
12300 ospf
->supported_grace_time
);
12302 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf
)) {
12303 hash_walk(ospf
->enable_rtr_list
,
12304 ospf_cfg_write_helper_dis_rtr_walkcb
, vty
);
12309 static int config_write_ospf_external_aggregator(struct vty
*vty
,
12312 struct route_node
*rn
;
12314 if (ospf
->aggr_delay_interval
!= OSPF_EXTL_AGGR_DEFAULT_DELAY
)
12315 vty_out(vty
, " aggregation timer %u\n",
12316 ospf
->aggr_delay_interval
);
12318 /* print 'summary-address A.B.C.D/M' */
12319 for (rn
= route_top(ospf
->rt_aggr_tbl
); rn
; rn
= route_next(rn
))
12321 struct ospf_external_aggr_rt
*aggr
= rn
->info
;
12323 vty_out(vty
, " summary-address %pI4/%d",
12324 &aggr
->p
.prefix
, aggr
->p
.prefixlen
);
12326 vty_out(vty
, " tag %u", aggr
->tag
);
12328 if (CHECK_FLAG(aggr
->flags
,
12329 OSPF_EXTERNAL_AGGRT_NO_ADVERTISE
))
12330 vty_out(vty
, " no-advertise");
12332 vty_out(vty
, "\n");
12338 static int config_write_ospf_default_metric(struct vty
*vty
, struct ospf
*ospf
)
12340 if (ospf
->default_metric
!= -1)
12341 vty_out(vty
, " default-metric %d\n", ospf
->default_metric
);
12345 static int config_write_ospf_distribute(struct vty
*vty
, struct ospf
*ospf
)
12348 struct ospf_redist
*red
;
12351 /* distribute-list print. */
12352 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
12353 if (DISTRIBUTE_NAME(ospf
, type
))
12354 vty_out(vty
, " distribute-list %s out %s\n",
12355 DISTRIBUTE_NAME(ospf
, type
),
12356 zebra_route_string(type
));
12358 /* default-information print. */
12359 if (ospf
->default_originate
!= DEFAULT_ORIGINATE_NONE
) {
12360 vty_out(vty
, " default-information originate");
12361 if (ospf
->default_originate
== DEFAULT_ORIGINATE_ALWAYS
)
12362 vty_out(vty
, " always");
12364 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
12366 if (red
->dmetric
.value
>= 0)
12367 vty_out(vty
, " metric %d",
12368 red
->dmetric
.value
);
12370 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
12371 vty_out(vty
, " metric-type 1");
12373 if (ROUTEMAP_NAME(red
))
12374 vty_out(vty
, " route-map %s",
12375 ROUTEMAP_NAME(red
));
12378 vty_out(vty
, "\n");
12385 static int config_write_ospf_distance(struct vty
*vty
, struct ospf
*ospf
)
12387 struct route_node
*rn
;
12388 struct ospf_distance
*odistance
;
12390 if (ospf
->distance_all
)
12391 vty_out(vty
, " distance %d\n", ospf
->distance_all
);
12393 if (ospf
->distance_intra
|| ospf
->distance_inter
12394 || ospf
->distance_external
) {
12395 vty_out(vty
, " distance ospf");
12397 if (ospf
->distance_intra
)
12398 vty_out(vty
, " intra-area %d", ospf
->distance_intra
);
12399 if (ospf
->distance_inter
)
12400 vty_out(vty
, " inter-area %d", ospf
->distance_inter
);
12401 if (ospf
->distance_external
)
12402 vty_out(vty
, " external %d", ospf
->distance_external
);
12404 vty_out(vty
, "\n");
12407 for (rn
= route_top(ospf
->distance_table
); rn
; rn
= route_next(rn
))
12408 if ((odistance
= rn
->info
) != NULL
) {
12409 vty_out(vty
, " distance %d %pFX %s\n",
12410 odistance
->distance
, &rn
->p
,
12411 odistance
->access_list
? odistance
->access_list
12417 static int ospf_config_write_one(struct vty
*vty
, struct ospf
*ospf
)
12421 /* `router ospf' print. */
12422 if (ospf
->instance
&& strcmp(ospf
->name
, VRF_DEFAULT_NAME
)) {
12423 vty_out(vty
, "router ospf %d vrf %s\n", ospf
->instance
,
12425 } else if (ospf
->instance
) {
12426 vty_out(vty
, "router ospf %d\n", ospf
->instance
);
12427 } else if (strcmp(ospf
->name
, VRF_DEFAULT_NAME
)) {
12428 vty_out(vty
, "router ospf vrf %s\n", ospf
->name
);
12430 vty_out(vty
, "router ospf\n");
12432 if (!ospf
->networks
) {
12437 /* Router ID print. */
12438 if (ospf
->router_id_static
.s_addr
!= INADDR_ANY
)
12439 vty_out(vty
, " ospf router-id %pI4\n",
12440 &ospf
->router_id_static
);
12442 /* zebra opaque attributes configuration. */
12443 if (CHECK_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
))
12444 vty_out(vty
, " ospf send-extra-data zebra\n");
12446 /* ABR type print. */
12447 if (ospf
->abr_type
!= OSPF_ABR_DEFAULT
)
12448 vty_out(vty
, " ospf abr-type %s\n",
12449 ospf_abr_type_str
[ospf
->abr_type
]);
12451 /* log-adjacency-changes flag print. */
12452 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
12453 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
))
12454 vty_out(vty
, " log-adjacency-changes detail\n");
12455 else if (!SAVE_OSPF_LOG_ADJACENCY_CHANGES
)
12456 vty_out(vty
, " log-adjacency-changes\n");
12457 } else if (SAVE_OSPF_LOG_ADJACENCY_CHANGES
) {
12458 vty_out(vty
, " no log-adjacency-changes\n");
12461 /* RFC1583 compatibility flag print -- Compatible with CISCO
12463 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
))
12464 vty_out(vty
, " compatible rfc1583\n");
12466 /* auto-cost reference-bandwidth configuration. */
12467 if (ospf
->ref_bandwidth
!= OSPF_DEFAULT_REF_BANDWIDTH
) {
12469 "! Important: ensure reference bandwidth is consistent across all routers\n");
12470 vty_out(vty
, " auto-cost reference-bandwidth %d\n",
12471 ospf
->ref_bandwidth
);
12474 /* SPF timers print. */
12475 if (ospf
->spf_delay
!= OSPF_SPF_DELAY_DEFAULT
12476 || ospf
->spf_holdtime
!= OSPF_SPF_HOLDTIME_DEFAULT
12477 || ospf
->spf_max_holdtime
!= OSPF_SPF_MAX_HOLDTIME_DEFAULT
)
12478 vty_out(vty
, " timers throttle spf %d %d %d\n", ospf
->spf_delay
,
12479 ospf
->spf_holdtime
, ospf
->spf_max_holdtime
);
12481 /* LSA timers print. */
12482 if (ospf
->min_ls_interval
!= OSPF_MIN_LS_INTERVAL
)
12483 vty_out(vty
, " timers throttle lsa all %d\n",
12484 ospf
->min_ls_interval
);
12485 if (ospf
->min_ls_arrival
!= OSPF_MIN_LS_ARRIVAL
)
12486 vty_out(vty
, " timers lsa min-arrival %d\n",
12487 ospf
->min_ls_arrival
);
12489 /* Write multiplier print. */
12490 if (ospf
->write_oi_count
!= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
)
12491 vty_out(vty
, " ospf write-multiplier %d\n",
12492 ospf
->write_oi_count
);
12494 if (ospf
->max_multipath
!= MULTIPATH_NUM
)
12495 vty_out(vty
, " maximum-paths %d\n", ospf
->max_multipath
);
12497 /* Max-metric router-lsa print */
12498 config_write_stub_router(vty
, ospf
);
12500 /* SPF refresh parameters print. */
12501 if (ospf
->lsa_refresh_interval
!= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
12502 vty_out(vty
, " refresh timer %d\n", ospf
->lsa_refresh_interval
);
12504 if (ospf
->fr_configured
)
12505 vty_out(vty
, " flood-reduction\n");
12507 if (!ospf
->intf_socket_enabled
)
12508 vty_out(vty
, " no socket-per-interface\n");
12510 /* Redistribute information print. */
12511 config_write_ospf_redistribute(vty
, ospf
);
12513 /* Graceful Restart print */
12514 config_write_ospf_gr(vty
, ospf
);
12515 config_write_ospf_gr_helper(vty
, ospf
);
12517 /* Print external route aggregation. */
12518 config_write_ospf_external_aggregator(vty
, ospf
);
12520 /* passive-interface print. */
12521 if (ospf
->passive_interface_default
== OSPF_IF_PASSIVE
)
12522 vty_out(vty
, " passive-interface default\n");
12524 /* proactive-arp print. */
12525 if (ospf
->proactive_arp
!= OSPF_PROACTIVE_ARP_DEFAULT
) {
12526 if (ospf
->proactive_arp
)
12527 vty_out(vty
, " proactive-arp\n");
12529 vty_out(vty
, " no proactive-arp\n");
12532 /* TI-LFA print. */
12533 if (ospf
->ti_lfa_enabled
) {
12534 if (ospf
->ti_lfa_protection_type
== OSPF_TI_LFA_NODE_PROTECTION
)
12535 vty_out(vty
, " fast-reroute ti-lfa node-protection\n");
12537 vty_out(vty
, " fast-reroute ti-lfa\n");
12540 /* Network area print. */
12541 config_write_network_area(vty
, ospf
);
12543 /* Area config print. */
12544 config_write_ospf_area(vty
, ospf
);
12546 /* static neighbor print. */
12547 config_write_ospf_nbr_nbma(vty
, ospf
);
12549 /* Virtual-Link print. */
12550 config_write_virtual_link(vty
, ospf
);
12552 /* Default metric configuration. */
12553 config_write_ospf_default_metric(vty
, ospf
);
12555 /* Distribute-list and default-information print. */
12556 config_write_ospf_distribute(vty
, ospf
);
12558 /* Distance configuration. */
12559 config_write_ospf_distance(vty
, ospf
);
12561 ospf_opaque_config_write_router(vty
, ospf
);
12563 /* LDP-Sync print */
12564 ospf_ldp_sync_write_config(vty
, ospf
);
12566 /* Socket buffer sizes */
12567 if (ospf
->recv_sock_bufsize
!= OSPF_DEFAULT_SOCK_BUFSIZE
) {
12568 if (ospf
->send_sock_bufsize
== ospf
->recv_sock_bufsize
)
12569 vty_out(vty
, " socket buffer all %u\n",
12570 ospf
->recv_sock_bufsize
);
12572 vty_out(vty
, " socket buffer recv %u\n",
12573 ospf
->recv_sock_bufsize
);
12576 if (ospf
->send_sock_bufsize
!= OSPF_DEFAULT_SOCK_BUFSIZE
&&
12577 ospf
->send_sock_bufsize
!= ospf
->recv_sock_bufsize
)
12578 vty_out(vty
, " socket buffer send %u\n",
12579 ospf
->send_sock_bufsize
);
12582 vty_out(vty
, "exit\n");
12588 /* OSPF configuration write function. */
12589 static int ospf_config_write(struct vty
*vty
)
12592 struct listnode
*ospf_node
= NULL
;
12595 if (listcount(om
->ospf
) == 0)
12598 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, ospf_node
, ospf
)) {
12599 /* VRF Default check if it is running.
12600 * Upon daemon start, there could be default instance
12601 * in absence of 'router ospf'/oi_running is disabled. */
12602 if (ospf
->vrf_id
== VRF_DEFAULT
&& ospf
->oi_running
)
12603 write
+= ospf_config_write_one(vty
, ospf
);
12604 /* For Non-Default VRF simply display the configuration,
12605 * even if it is not oi_running. */
12606 else if (ospf
->vrf_id
!= VRF_DEFAULT
)
12607 write
+= ospf_config_write_one(vty
, ospf
);
12612 void ospf_vty_show_init(void)
12614 /* "show ip ospf" commands. */
12615 install_element(VIEW_NODE
, &show_ip_ospf_cmd
);
12617 install_element(VIEW_NODE
, &show_ip_ospf_instance_cmd
);
12619 /* "show ip ospf database" commands. */
12620 install_element(VIEW_NODE
, &show_ip_ospf_database_cmd
);
12622 /* "show ip ospf interface" commands. */
12623 install_element(VIEW_NODE
, &show_ip_ospf_interface_cmd
);
12625 install_element(VIEW_NODE
, &show_ip_ospf_instance_interface_cmd
);
12626 /* "show ip ospf interface traffic */
12627 install_element(VIEW_NODE
, &show_ip_ospf_interface_traffic_cmd
);
12629 /* "show ip ospf neighbor" commands. */
12630 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_detail_cmd
);
12631 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_cmd
);
12632 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_id_cmd
);
12633 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_all_cmd
);
12634 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_cmd
);
12635 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_cmd
);
12636 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_all_cmd
);
12638 install_element(VIEW_NODE
,
12639 &show_ip_ospf_instance_neighbor_int_detail_cmd
);
12640 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_int_cmd
);
12641 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_id_cmd
);
12642 install_element(VIEW_NODE
,
12643 &show_ip_ospf_instance_neighbor_detail_all_cmd
);
12644 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_detail_cmd
);
12645 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_cmd
);
12646 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_all_cmd
);
12648 /* "show ip ospf route" commands. */
12649 install_element(VIEW_NODE
, &show_ip_ospf_route_cmd
);
12650 install_element(VIEW_NODE
, &show_ip_ospf_border_routers_cmd
);
12651 install_element(VIEW_NODE
, &show_ip_ospf_reachable_routers_cmd
);
12653 install_element(VIEW_NODE
, &show_ip_ospf_instance_route_cmd
);
12654 install_element(VIEW_NODE
, &show_ip_ospf_instance_border_routers_cmd
);
12655 install_element(VIEW_NODE
,
12656 &show_ip_ospf_instance_reachable_routers_cmd
);
12658 /* "show ip ospf vrfs" commands. */
12659 install_element(VIEW_NODE
, &show_ip_ospf_vrfs_cmd
);
12661 /* "show ip ospf gr-helper details" command */
12662 install_element(VIEW_NODE
, &show_ip_ospf_gr_helper_cmd
);
12664 /* "show ip ospf summary-address" command */
12665 install_element(VIEW_NODE
, &show_ip_ospf_external_aggregator_cmd
);
12668 /* Initialization of OSPF interface. */
12669 static void ospf_vty_if_init(void)
12671 /* Install interface node. */
12672 if_cmd_init(config_write_interface
);
12674 /* "ip ospf authentication" commands. */
12675 install_element(INTERFACE_NODE
, &ip_ospf_authentication_args_addr_cmd
);
12676 install_element(INTERFACE_NODE
, &ip_ospf_authentication_addr_cmd
);
12677 install_element(INTERFACE_NODE
,
12678 &no_ip_ospf_authentication_args_addr_cmd
);
12679 install_element(INTERFACE_NODE
, &no_ip_ospf_authentication_addr_cmd
);
12680 install_element(INTERFACE_NODE
, &ip_ospf_authentication_key_addr_cmd
);
12681 install_element(INTERFACE_NODE
,
12682 &no_ip_ospf_authentication_key_authkey_addr_cmd
);
12683 install_element(INTERFACE_NODE
,
12684 &no_ospf_authentication_key_authkey_addr_cmd
);
12686 /* "ip ospf message-digest-key" commands. */
12687 install_element(INTERFACE_NODE
, &ip_ospf_message_digest_key_cmd
);
12688 install_element(INTERFACE_NODE
, &no_ip_ospf_message_digest_key_cmd
);
12690 /* "ip ospf cost" commands. */
12691 install_element(INTERFACE_NODE
, &ip_ospf_cost_cmd
);
12692 install_element(INTERFACE_NODE
, &no_ip_ospf_cost_cmd
);
12694 /* "ip ospf mtu-ignore" commands. */
12695 install_element(INTERFACE_NODE
, &ip_ospf_mtu_ignore_addr_cmd
);
12696 install_element(INTERFACE_NODE
, &no_ip_ospf_mtu_ignore_addr_cmd
);
12698 /* "ip ospf dead-interval" commands. */
12699 install_element(INTERFACE_NODE
, &ip_ospf_dead_interval_cmd
);
12700 install_element(INTERFACE_NODE
,
12701 &ip_ospf_dead_interval_minimal_addr_cmd
);
12702 install_element(INTERFACE_NODE
, &no_ip_ospf_dead_interval_cmd
);
12704 /* "ip ospf hello-interval" commands. */
12705 install_element(INTERFACE_NODE
, &ip_ospf_hello_interval_cmd
);
12706 install_element(INTERFACE_NODE
, &no_ip_ospf_hello_interval_cmd
);
12708 /* "ip ospf network" commands. */
12709 install_element(INTERFACE_NODE
, &ip_ospf_network_cmd
);
12710 install_element(INTERFACE_NODE
, &no_ip_ospf_network_cmd
);
12712 /* "ip ospf priority" commands. */
12713 install_element(INTERFACE_NODE
, &ip_ospf_priority_cmd
);
12714 install_element(INTERFACE_NODE
, &no_ip_ospf_priority_cmd
);
12716 /* "ip ospf retransmit-interval" commands. */
12717 install_element(INTERFACE_NODE
, &ip_ospf_retransmit_interval_addr_cmd
);
12718 install_element(INTERFACE_NODE
,
12719 &no_ip_ospf_retransmit_interval_addr_cmd
);
12721 /* "ip ospf transmit-delay" commands. */
12722 install_element(INTERFACE_NODE
, &ip_ospf_transmit_delay_addr_cmd
);
12723 install_element(INTERFACE_NODE
, &no_ip_ospf_transmit_delay_addr_cmd
);
12725 /* "ip ospf area" commands. */
12726 install_element(INTERFACE_NODE
, &ip_ospf_area_cmd
);
12727 install_element(INTERFACE_NODE
, &no_ip_ospf_area_cmd
);
12729 /* "ip ospf passive" commands. */
12730 install_element(INTERFACE_NODE
, &ip_ospf_passive_cmd
);
12731 install_element(INTERFACE_NODE
, &no_ip_ospf_passive_cmd
);
12733 /* These commands are compatibitliy for previous version. */
12734 install_element(INTERFACE_NODE
, &ospf_authentication_key_cmd
);
12735 install_element(INTERFACE_NODE
, &ospf_message_digest_key_cmd
);
12736 install_element(INTERFACE_NODE
, &no_ospf_message_digest_key_cmd
);
12737 install_element(INTERFACE_NODE
, &ospf_dead_interval_cmd
);
12738 install_element(INTERFACE_NODE
, &no_ospf_dead_interval_cmd
);
12739 install_element(INTERFACE_NODE
, &ospf_hello_interval_cmd
);
12740 install_element(INTERFACE_NODE
, &no_ospf_hello_interval_cmd
);
12741 install_element(INTERFACE_NODE
, &ospf_cost_cmd
);
12742 install_element(INTERFACE_NODE
, &no_ospf_cost_cmd
);
12743 install_element(INTERFACE_NODE
, &ospf_network_cmd
);
12744 install_element(INTERFACE_NODE
, &no_ospf_network_cmd
);
12745 install_element(INTERFACE_NODE
, &ospf_priority_cmd
);
12746 install_element(INTERFACE_NODE
, &no_ospf_priority_cmd
);
12747 install_element(INTERFACE_NODE
, &ospf_retransmit_interval_cmd
);
12748 install_element(INTERFACE_NODE
, &no_ospf_retransmit_interval_cmd
);
12749 install_element(INTERFACE_NODE
, &ospf_transmit_delay_cmd
);
12750 install_element(INTERFACE_NODE
, &no_ospf_transmit_delay_cmd
);
12753 static void ospf_vty_zebra_init(void)
12755 install_element(OSPF_NODE
, &ospf_redistribute_source_cmd
);
12756 install_element(OSPF_NODE
, &no_ospf_redistribute_source_cmd
);
12757 install_element(OSPF_NODE
, &ospf_redistribute_instance_source_cmd
);
12758 install_element(OSPF_NODE
, &no_ospf_redistribute_instance_source_cmd
);
12760 install_element(OSPF_NODE
, &ospf_distribute_list_out_cmd
);
12761 install_element(OSPF_NODE
, &no_ospf_distribute_list_out_cmd
);
12763 install_element(OSPF_NODE
, &ospf_default_information_originate_cmd
);
12764 install_element(OSPF_NODE
, &no_ospf_default_information_originate_cmd
);
12766 install_element(OSPF_NODE
, &ospf_default_metric_cmd
);
12767 install_element(OSPF_NODE
, &no_ospf_default_metric_cmd
);
12769 install_element(OSPF_NODE
, &ospf_distance_cmd
);
12770 install_element(OSPF_NODE
, &no_ospf_distance_cmd
);
12771 install_element(OSPF_NODE
, &no_ospf_distance_ospf_cmd
);
12772 install_element(OSPF_NODE
, &ospf_distance_ospf_cmd
);
12774 /*Ospf garcefull restart helper configurations */
12775 install_element(OSPF_NODE
, &ospf_gr_helper_enable_cmd
);
12776 install_element(OSPF_NODE
, &no_ospf_gr_helper_enable_cmd
);
12777 install_element(OSPF_NODE
, &ospf_gr_helper_enable_lsacheck_cmd
);
12778 install_element(OSPF_NODE
, &no_ospf_gr_helper_enable_lsacheck_cmd
);
12779 install_element(OSPF_NODE
, &ospf_gr_helper_supported_grace_time_cmd
);
12780 install_element(OSPF_NODE
, &no_ospf_gr_helper_supported_grace_time_cmd
);
12781 install_element(OSPF_NODE
, &ospf_gr_helper_planned_only_cmd
);
12782 install_element(OSPF_NODE
, &no_ospf_gr_helper_planned_only_cmd
);
12784 /* External LSA summarisation config commands.*/
12785 install_element(OSPF_NODE
, &ospf_external_route_aggregation_cmd
);
12786 install_element(OSPF_NODE
, &no_ospf_external_route_aggregation_cmd
);
12787 install_element(OSPF_NODE
,
12788 &ospf_external_route_aggregation_no_adrvertise_cmd
);
12789 install_element(OSPF_NODE
,
12790 &no_ospf_external_route_aggregation_no_adrvertise_cmd
);
12791 install_element(OSPF_NODE
, &ospf_route_aggregation_timer_cmd
);
12792 install_element(OSPF_NODE
, &no_ospf_route_aggregation_timer_cmd
);
12795 static int ospf_config_write(struct vty
*vty
);
12796 static struct cmd_node ospf_node
= {
12799 .parent_node
= CONFIG_NODE
,
12800 .prompt
= "%s(config-router)# ",
12801 .config_write
= ospf_config_write
,
12804 static void ospf_interface_clear(struct interface
*ifp
)
12806 if (!if_is_operative(ifp
))
12809 if (IS_DEBUG_OSPF(ism
, ISM_EVENTS
))
12810 zlog_debug("ISM[%s]: clear by reset", ifp
->name
);
12812 ospf_if_reset(ifp
);
12815 DEFUN (clear_ip_ospf_interface
,
12816 clear_ip_ospf_interface_cmd
,
12817 "clear ip ospf [vrf NAME] interface [IFNAME]",
12820 "OSPF information\n"
12822 "Interface information\n"
12823 "Interface name\n")
12825 int idx_ifname
= 0;
12827 struct interface
*ifp
;
12828 struct listnode
*node
;
12829 struct ospf
*ospf
= NULL
;
12830 char *vrf_name
= NULL
;
12831 vrf_id_t vrf_id
= VRF_DEFAULT
;
12832 struct vrf
*vrf
= NULL
;
12834 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
12835 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
12836 if (vrf_name
&& strmatch(vrf_name
, VRF_DEFAULT_NAME
))
12839 vrf
= vrf_lookup_by_name(vrf_name
);
12841 vrf_id
= vrf
->vrf_id
;
12843 if (!argv_find(argv
, argc
, "IFNAME", &idx_ifname
)) {
12844 /* Clear all the ospfv2 interfaces. */
12845 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
12846 if (vrf_id
!= ospf
->vrf_id
)
12849 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
12850 FOR_ALL_INTERFACES (vrf
, ifp
)
12851 ospf_interface_clear(ifp
);
12854 /* Interface name is specified. */
12855 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf_id
);
12857 vty_out(vty
, "No such interface name\n");
12859 ospf_interface_clear(ifp
);
12862 return CMD_SUCCESS
;
12865 DEFPY_HIDDEN(ospf_lsa_refresh_timer
, ospf_lsa_refresh_timer_cmd
,
12866 "[no$no] ospf lsa-refresh [(120-1800)]$value",
12868 "OSPF lsa refresh timer\n"
12869 "timer value in seconds\n")
12871 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
12874 ospf
->lsa_refresh_timer
= OSPF_LS_REFRESH_TIME
;
12876 ospf
->lsa_refresh_timer
= value
;
12878 return CMD_SUCCESS
;
12881 DEFPY_HIDDEN(ospf_maxage_delay_timer
, ospf_maxage_delay_timer_cmd
,
12882 "[no$no] ospf maxage-delay [(0-60)]$value",
12884 "OSPF lsa maxage delay timer\n"
12885 "timer value in seconds\n")
12887 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
12890 ospf
->maxage_delay
= OSPF_LSA_MAXAGE_REMOVE_DELAY_DEFAULT
;
12892 ospf
->maxage_delay
= value
;
12894 EVENT_OFF(ospf
->t_maxage
);
12895 OSPF_TIMER_ON(ospf
->t_maxage
, ospf_maxage_lsa_remover
,
12896 ospf
->maxage_delay
);
12898 return CMD_SUCCESS
;
12902 * ------------------------------------------------------------------------*
12903 * Following is (vty) configuration functions for flood-reduction handling.
12904 * ------------------------------------------------------------------------
12907 DEFPY(flood_reduction
, flood_reduction_cmd
, "flood-reduction",
12908 "flood reduction feature\n")
12910 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
12911 struct ospf_area
*area
;
12912 struct listnode
*node
;
12914 /* Turn on the Flood Reduction feature for the router. */
12915 if (!ospf
->fr_configured
) {
12916 ospf
->fr_configured
= true;
12917 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT
,
12918 "Flood Reduction: OFF -> ON");
12919 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
12921 ospf_area_update_fr_state(area
);
12922 ospf_refresh_area_self_lsas(area
);
12927 return CMD_SUCCESS
;
12930 DEFPY(flood_reduction_area
, flood_reduction_area_cmd
,
12931 "area <A.B.C.D|(0-4294967295)> flood-reduction",
12932 "OSPF area parameters\n"
12933 "OSPF area ID in IP address format\n"
12934 "OSPF area ID as a decimal value\n"
12935 "Enable flood reduction for area\n")
12937 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
12938 struct ospf_area
*oa
;
12942 const char *areaid
;
12943 struct in_addr area_id
;
12945 areaid
= argv
[idx
]->arg
;
12947 ret
= str2area_id(areaid
, &area_id
, &format
);
12949 vty_out(vty
, "Please specify area by A.B.C.D|<0-4294967295>\n");
12950 return CMD_WARNING_CONFIG_FAILED
;
12953 oa
= ospf_area_lookup_by_area_id(ospf
, area_id
);
12955 vty_out(vty
, "OSPF area ID not present\n");
12956 return CMD_WARNING_CONFIG_FAILED
;
12959 /* Turn on the Flood Reduction feature for the area. */
12960 if (!oa
->fr_info
.configured
) {
12961 oa
->fr_info
.configured
= true;
12962 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT
,
12963 "Flood Reduction area %pI4 : OFF -> ON",
12965 ospf_area_update_fr_state(oa
);
12966 ospf_refresh_area_self_lsas(oa
);
12969 return CMD_SUCCESS
;
12972 DEFPY(no_flood_reduction
, no_flood_reduction_cmd
, "no flood-reduction",
12973 NO_STR
"flood reduction feature\n")
12975 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
12976 struct listnode
*node
;
12977 struct ospf_area
*area
;
12979 /* Turn off the Flood Reduction feature for the router. */
12980 if (ospf
->fr_configured
) {
12981 ospf
->fr_configured
= false;
12982 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT
,
12983 "Flood Reduction: ON -> OFF");
12984 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
12986 ospf_area_update_fr_state(area
);
12987 ospf_refresh_area_self_lsas(area
);
12992 return CMD_SUCCESS
;
12995 DEFPY(no_flood_reduction_area
, no_flood_reduction_area_cmd
,
12996 "no area <A.B.C.D|(0-4294967295)> flood-reduction",
12998 "OSPF area parameters\n"
12999 "OSPF area ID in IP address format\n"
13000 "OSPF area ID as a decimal value\n"
13001 "Disable flood reduction for area\n")
13003 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
13004 struct ospf_area
*oa
;
13008 const char *areaid
;
13009 struct in_addr area_id
;
13011 areaid
= argv
[idx
]->arg
;
13013 ret
= str2area_id(areaid
, &area_id
, &format
);
13015 vty_out(vty
, "Please specify area by A.B.C.D|<0-4294967295>\n");
13016 return CMD_WARNING_CONFIG_FAILED
;
13019 oa
= ospf_area_lookup_by_area_id(ospf
, area_id
);
13021 vty_out(vty
, "OSPF area ID not present\n");
13022 return CMD_WARNING_CONFIG_FAILED
;
13025 /* Turn off the Flood Reduction feature for the area. */
13026 if (oa
->fr_info
.configured
) {
13027 oa
->fr_info
.configured
= false;
13028 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT
,
13029 "Flood Reduction area %pI4 : ON -> OFF",
13031 ospf_area_update_fr_state(oa
);
13032 ospf_refresh_area_self_lsas(oa
);
13035 return CMD_SUCCESS
;
13038 DEFPY(ospf_socket_bufsizes
,
13039 ospf_socket_bufsizes_cmd
,
13040 "[no] socket buffer <send$send_val | recv$recv_val | all$all_val> \
13041 ![(1-4000000000)$bufsize]",
13043 "Socket parameters\n"
13044 "Buffer size configuration\n"
13045 "Send buffer size\n"
13046 "Receive buffer size\n"
13047 "Both send and receive buffer sizes\n"
13048 "Buffer size, in bytes\n")
13050 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
13051 uint32_t recvsz
, sendsz
;
13054 bufsize
= OSPF_DEFAULT_SOCK_BUFSIZE
;
13059 } else if (send_val
) {
13061 recvsz
= ospf
->recv_sock_bufsize
;
13062 } else if (recv_val
) {
13064 sendsz
= ospf
->send_sock_bufsize
;
13066 return CMD_SUCCESS
;
13068 /* React to a change by modifying existing sockets */
13069 ospf_update_bufsize(ospf
, recvsz
, sendsz
);
13071 return CMD_SUCCESS
;
13074 DEFPY (per_intf_socket
,
13075 per_intf_socket_cmd
,
13076 "[no] socket-per-interface",
13078 "Use write socket per interface\n")
13080 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
13081 struct listnode
*node
;
13082 struct ospf_interface
*oi
;
13085 if (ospf
->intf_socket_enabled
) {
13086 ospf
->intf_socket_enabled
= false;
13088 /* Iterate and close any sockets */
13089 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
))
13090 ospf_ifp_sock_close(oi
->ifp
);
13092 } else if (!ospf
->intf_socket_enabled
) {
13093 ospf
->intf_socket_enabled
= true;
13095 /* Iterate and open sockets */
13096 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
))
13097 ospf_ifp_sock_init(oi
->ifp
);
13100 return CMD_SUCCESS
;
13103 void ospf_vty_clear_init(void)
13105 install_element(ENABLE_NODE
, &clear_ip_ospf_interface_cmd
);
13106 install_element(ENABLE_NODE
, &clear_ip_ospf_process_cmd
);
13107 install_element(ENABLE_NODE
, &clear_ip_ospf_neighbor_cmd
);
13111 /* Install OSPF related vty commands. */
13112 void ospf_vty_init(void)
13114 /* Install ospf top node. */
13115 install_node(&ospf_node
);
13117 /* "router ospf" commands. */
13118 install_element(CONFIG_NODE
, &router_ospf_cmd
);
13119 install_element(CONFIG_NODE
, &no_router_ospf_cmd
);
13122 install_default(OSPF_NODE
);
13124 /* "ospf router-id" commands. */
13125 install_element(OSPF_NODE
, &ospf_router_id_cmd
);
13126 install_element(OSPF_NODE
, &ospf_router_id_old_cmd
);
13127 install_element(OSPF_NODE
, &no_ospf_router_id_cmd
);
13129 /* "passive-interface" commands. */
13130 install_element(OSPF_NODE
, &ospf_passive_interface_default_cmd
);
13131 install_element(OSPF_NODE
, &ospf_passive_interface_addr_cmd
);
13132 install_element(OSPF_NODE
, &no_ospf_passive_interface_default_cmd
);
13133 install_element(OSPF_NODE
, &no_ospf_passive_interface_addr_cmd
);
13135 /* "ospf abr-type" commands. */
13136 install_element(OSPF_NODE
, &ospf_abr_type_cmd
);
13137 install_element(OSPF_NODE
, &no_ospf_abr_type_cmd
);
13139 /* "ospf log-adjacency-changes" commands. */
13140 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_cmd
);
13141 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_detail_cmd
);
13142 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_cmd
);
13143 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_detail_cmd
);
13145 /* "ospf rfc1583-compatible" commands. */
13146 install_element(OSPF_NODE
, &ospf_compatible_rfc1583_cmd
);
13147 install_element(OSPF_NODE
, &no_ospf_compatible_rfc1583_cmd
);
13148 install_element(OSPF_NODE
, &ospf_rfc1583_flag_cmd
);
13149 install_element(OSPF_NODE
, &no_ospf_rfc1583_flag_cmd
);
13151 /* "ospf send-extra-data zebra" commands. */
13152 install_element(OSPF_NODE
, &ospf_send_extra_data_cmd
);
13154 /* "network area" commands. */
13155 install_element(OSPF_NODE
, &ospf_network_area_cmd
);
13156 install_element(OSPF_NODE
, &no_ospf_network_area_cmd
);
13158 /* "area authentication" commands. */
13159 install_element(OSPF_NODE
,
13160 &ospf_area_authentication_message_digest_cmd
);
13161 install_element(OSPF_NODE
, &ospf_area_authentication_cmd
);
13162 install_element(OSPF_NODE
, &no_ospf_area_authentication_cmd
);
13164 /* "area range" commands. */
13165 install_element(OSPF_NODE
, &ospf_area_range_cmd
);
13166 install_element(OSPF_NODE
, &ospf_area_range_cost_cmd
);
13167 install_element(OSPF_NODE
, &ospf_area_range_not_advertise_cmd
);
13168 install_element(OSPF_NODE
, &no_ospf_area_range_cmd
);
13169 install_element(OSPF_NODE
, &no_ospf_area_range_substitute_cmd
);
13171 /* "area virtual-link" commands. */
13172 install_element(OSPF_NODE
, &ospf_area_vlink_cmd
);
13173 install_element(OSPF_NODE
, &ospf_area_vlink_intervals_cmd
);
13174 install_element(OSPF_NODE
, &no_ospf_area_vlink_cmd
);
13175 install_element(OSPF_NODE
, &no_ospf_area_vlink_intervals_cmd
);
13178 /* "area stub" commands. */
13179 install_element(OSPF_NODE
, &ospf_area_stub_no_summary_cmd
);
13180 install_element(OSPF_NODE
, &ospf_area_stub_cmd
);
13181 install_element(OSPF_NODE
, &no_ospf_area_stub_no_summary_cmd
);
13182 install_element(OSPF_NODE
, &no_ospf_area_stub_cmd
);
13184 /* "area nssa" commands. */
13185 install_element(OSPF_NODE
, &ospf_area_nssa_cmd
);
13186 install_element(OSPF_NODE
, &no_ospf_area_nssa_cmd
);
13187 install_element(OSPF_NODE
, &ospf_area_nssa_range_cmd
);
13188 install_element(OSPF_NODE
, &no_ospf_area_nssa_range_cmd
);
13190 install_element(OSPF_NODE
, &ospf_area_default_cost_cmd
);
13191 install_element(OSPF_NODE
, &no_ospf_area_default_cost_cmd
);
13193 install_element(OSPF_NODE
, &ospf_area_shortcut_cmd
);
13194 install_element(OSPF_NODE
, &no_ospf_area_shortcut_cmd
);
13196 install_element(OSPF_NODE
, &ospf_area_export_list_cmd
);
13197 install_element(OSPF_NODE
, &no_ospf_area_export_list_cmd
);
13199 install_element(OSPF_NODE
, &ospf_area_filter_list_cmd
);
13200 install_element(OSPF_NODE
, &no_ospf_area_filter_list_cmd
);
13202 install_element(OSPF_NODE
, &ospf_area_import_list_cmd
);
13203 install_element(OSPF_NODE
, &no_ospf_area_import_list_cmd
);
13205 /* SPF timer commands */
13206 install_element(OSPF_NODE
, &ospf_timers_throttle_spf_cmd
);
13207 install_element(OSPF_NODE
, &no_ospf_timers_throttle_spf_cmd
);
13209 /* LSA timers commands */
13210 install_element(OSPF_NODE
, &ospf_timers_min_ls_interval_cmd
);
13211 install_element(OSPF_NODE
, &no_ospf_timers_min_ls_interval_cmd
);
13212 install_element(OSPF_NODE
, &ospf_timers_lsa_min_arrival_cmd
);
13213 install_element(OSPF_NODE
, &no_ospf_timers_lsa_min_arrival_cmd
);
13215 /* refresh timer commands */
13216 install_element(OSPF_NODE
, &ospf_refresh_timer_cmd
);
13217 install_element(OSPF_NODE
, &no_ospf_refresh_timer_val_cmd
);
13219 /* max-metric commands */
13220 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_admin_cmd
);
13221 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_admin_cmd
);
13222 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_startup_cmd
);
13223 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_startup_cmd
);
13224 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_shutdown_cmd
);
13225 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_shutdown_cmd
);
13227 /* reference bandwidth commands */
13228 install_element(OSPF_NODE
, &ospf_auto_cost_reference_bandwidth_cmd
);
13229 install_element(OSPF_NODE
, &no_ospf_auto_cost_reference_bandwidth_cmd
);
13231 /* "neighbor" commands. */
13232 install_element(OSPF_NODE
, &ospf_neighbor_cmd
);
13233 install_element(OSPF_NODE
, &ospf_neighbor_poll_interval_cmd
);
13234 install_element(OSPF_NODE
, &no_ospf_neighbor_cmd
);
13235 install_element(OSPF_NODE
, &no_ospf_neighbor_poll_cmd
);
13237 /* write multiplier commands */
13238 install_element(OSPF_NODE
, &ospf_write_multiplier_cmd
);
13239 install_element(OSPF_NODE
, &write_multiplier_cmd
);
13240 install_element(OSPF_NODE
, &no_ospf_write_multiplier_cmd
);
13241 install_element(OSPF_NODE
, &no_write_multiplier_cmd
);
13243 /* "proactive-arp" commands. */
13244 install_element(OSPF_NODE
, &ospf_proactive_arp_cmd
);
13245 install_element(OSPF_NODE
, &no_ospf_proactive_arp_cmd
);
13247 /* TI-LFA commands */
13248 install_element(OSPF_NODE
, &ospf_ti_lfa_cmd
);
13249 install_element(OSPF_NODE
, &no_ospf_ti_lfa_cmd
);
13251 /* Max path configurations */
13252 install_element(OSPF_NODE
, &ospf_max_multipath_cmd
);
13253 install_element(OSPF_NODE
, &no_ospf_max_multipath_cmd
);
13255 vrf_cmd_init(NULL
);
13257 install_element(OSPF_NODE
, &ospf_lsa_refresh_timer_cmd
);
13258 install_element(OSPF_NODE
, &ospf_maxage_delay_timer_cmd
);
13260 /* Flood Reduction commands */
13261 install_element(OSPF_NODE
, &flood_reduction_cmd
);
13262 install_element(OSPF_NODE
, &no_flood_reduction_cmd
);
13263 install_element(OSPF_NODE
, &flood_reduction_area_cmd
);
13264 install_element(OSPF_NODE
, &no_flood_reduction_area_cmd
);
13266 install_element(OSPF_NODE
, &ospf_socket_bufsizes_cmd
);
13267 install_element(OSPF_NODE
, &per_intf_socket_cmd
);
13269 /* Init interface related vty commands. */
13270 ospf_vty_if_init();
13272 /* Init zebra related vty commands. */
13273 ospf_vty_zebra_init();