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
,
4002 json_object_free(json_interface
);
4004 vty_out(vty
, "No such interface name\n");
4007 json_interface_sub
= json_object_new_object();
4009 show_ip_ospf_interface_sub(
4010 vty
, ospf
, ifp
, json_interface_sub
, use_json
);
4013 json_object_object_add(json_interface
,
4015 json_interface_sub
);
4016 json_object_object_add(json_vrf
, "interfaces",
4024 json_object_object_add(json
, ospf_get_name(ospf
),
4033 static void show_ip_ospf_interface_traffic_sub(struct vty
*vty
,
4034 struct ospf_interface
*oi
,
4035 json_object
*json_interface_sub
,
4039 json_object_int_add(json_interface_sub
, "ifIndex",
4041 json_object_int_add(json_interface_sub
, "helloIn",
4043 json_object_int_add(json_interface_sub
, "helloOut",
4045 json_object_int_add(json_interface_sub
, "dbDescIn",
4047 json_object_int_add(json_interface_sub
, "dbDescOut",
4049 json_object_int_add(json_interface_sub
, "lsReqIn",
4051 json_object_int_add(json_interface_sub
, "lsReqOut",
4053 json_object_int_add(json_interface_sub
, "lsUpdIn",
4055 json_object_int_add(json_interface_sub
, "lsUpdOut",
4057 json_object_int_add(json_interface_sub
, "lsAckIn",
4059 json_object_int_add(json_interface_sub
, "lsAckOut",
4061 json_object_int_add(json_interface_sub
, "packetsQueued",
4062 listcount(oi
->obuf
));
4065 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u %12lu\n",
4066 oi
->ifp
->name
, oi
->hello_in
, oi
->hello_out
,
4067 oi
->db_desc_in
, oi
->db_desc_out
, oi
->ls_req_in
,
4068 oi
->ls_req_out
, oi
->ls_upd_in
, oi
->ls_upd_out
,
4069 oi
->ls_ack_in
, oi
->ls_ack_out
, listcount(oi
->obuf
));
4073 /* OSPFv2 Packet Counters */
4074 static int show_ip_ospf_interface_traffic_common(
4075 struct vty
*vty
, struct ospf
*ospf
, char *intf_name
, json_object
*json
,
4076 int display_once
, uint8_t use_vrf
, bool use_json
)
4078 struct vrf
*vrf
= NULL
;
4079 struct interface
*ifp
= NULL
;
4080 json_object
*json_vrf
= NULL
;
4081 json_object
*json_interface_sub
= NULL
;
4083 if (!use_json
&& !display_once
) {
4085 vty_out(vty
, "%-12s%-17s%-17s%-17s%-17s%-17s%-17s\n",
4086 "Interface", " HELLO", " DB-Desc", " LS-Req",
4087 " LS-Update", " LS-Ack", " Packets");
4088 vty_out(vty
, "%-10s%-18s%-18s%-17s%-17s%-17s%-17s\n", "",
4089 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
4090 " Rx/Tx", " Queued");
4092 "-------------------------------------------------------------------------------------------------------------\n");
4093 } else if (use_json
) {
4095 json_vrf
= json_object_new_object();
4100 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4102 if (intf_name
== NULL
) {
4103 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
4104 FOR_ALL_INTERFACES (vrf
, ifp
) {
4105 struct route_node
*rn
;
4106 struct ospf_interface
*oi
;
4108 if (ospf_oi_count(ifp
) == 0)
4111 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
4112 rn
= route_next(rn
)) {
4119 json_interface_sub
=
4120 json_object_new_object();
4123 show_ip_ospf_interface_traffic_sub(
4124 vty
, oi
, json_interface_sub
, use_json
);
4126 json_object_object_add(
4127 json_vrf
, ifp
->name
,
4128 json_interface_sub
);
4133 /* Interface name is specified. */
4134 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
4136 struct route_node
*rn
;
4137 struct ospf_interface
*oi
;
4139 if (ospf_oi_count(ifp
) == 0) {
4141 " OSPF not enabled on this interface %s\n",
4146 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
4147 rn
= route_next(rn
)) {
4151 json_interface_sub
=
4152 json_object_new_object();
4155 show_ip_ospf_interface_traffic_sub(
4156 vty
, oi
, json_interface_sub
, use_json
);
4158 json_object_object_add(
4159 json_vrf
, ifp
->name
,
4160 json_interface_sub
);
4168 json_object_object_add(json
, ospf_get_name(ospf
),
4176 DEFUN (show_ip_ospf_interface
,
4177 show_ip_ospf_interface_cmd
,
4178 "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]",
4181 "OSPF information\n"
4184 "Interface information\n"
4189 bool uj
= use_json(argc
, argv
);
4190 struct listnode
*node
= NULL
;
4191 char *vrf_name
= NULL
, *intf_name
= NULL
;
4192 bool all_vrf
= false;
4193 int ret
= CMD_SUCCESS
;
4195 int idx_vrf
= 0, idx_intf
= 0;
4196 uint8_t use_vrf
= 0;
4197 json_object
*json
= NULL
;
4199 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4201 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4202 intf_name
= argv
[idx_intf
]->arg
;
4205 json
= json_object_new_object();
4207 /* vrf input is provided could be all or specific vrf*/
4211 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4212 if (!ospf
->oi_running
)
4214 ret
= show_ip_ospf_interface_common(
4215 vty
, ospf
, intf_name
, use_vrf
, json
,
4220 vty_json(vty
, json
);
4222 vty_out(vty
, "%% OSPF is not enabled\n");
4226 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4227 if (ospf
== NULL
|| !ospf
->oi_running
) {
4229 vty_json(vty
, json
);
4232 "%% OSPF is not enabled in vrf %s\n",
4237 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
4241 /* Display default ospf (instance 0) info */
4242 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4243 if (ospf
== NULL
|| !ospf
->oi_running
) {
4245 vty_json(vty
, json
);
4248 "%% OSPF is not enabled in vrf default\n");
4252 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
4257 vty_json(vty
, json
);
4262 DEFUN (show_ip_ospf_instance_interface
,
4263 show_ip_ospf_instance_interface_cmd
,
4264 "show ip ospf (1-65535) interface [INTERFACE] [json]",
4267 "OSPF information\n"
4269 "Interface information\n"
4276 unsigned short instance
= 0;
4277 bool uj
= use_json(argc
, argv
);
4278 char *intf_name
= NULL
;
4279 int ret
= CMD_SUCCESS
;
4280 json_object
*json
= NULL
;
4282 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4283 if (instance
!= ospf_instance
)
4284 return CMD_NOT_MY_INSTANCE
;
4286 ospf
= ospf_lookup_instance(instance
);
4287 if (!ospf
|| !ospf
->oi_running
)
4291 json
= json_object_new_object();
4293 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4294 intf_name
= argv
[idx_intf
]->arg
;
4296 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
, 0, json
, uj
);
4299 vty_json(vty
, json
);
4304 DEFUN (show_ip_ospf_interface_traffic
,
4305 show_ip_ospf_interface_traffic_cmd
,
4306 "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]",
4309 "OSPF information\n"
4312 "Interface information\n"
4313 "Protocol Packet counters\n"
4317 struct ospf
*ospf
= NULL
;
4318 struct listnode
*node
= NULL
;
4319 char *vrf_name
= NULL
, *intf_name
= NULL
;
4320 bool all_vrf
= false;
4322 int idx_vrf
= 0, idx_intf
= 0;
4323 bool uj
= use_json(argc
, argv
);
4324 json_object
*json
= NULL
;
4325 int ret
= CMD_SUCCESS
;
4326 int display_once
= 0;
4327 uint8_t use_vrf
= 0;
4329 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4331 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4332 intf_name
= argv
[idx_intf
]->arg
;
4335 json
= json_object_new_object();
4340 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4341 if (!ospf
->oi_running
)
4344 ret
= show_ip_ospf_interface_traffic_common(
4345 vty
, ospf
, intf_name
, json
,
4346 display_once
, use_vrf
, uj
);
4351 vty_json(vty
, json
);
4355 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4356 if (ospf
== NULL
|| !ospf
->oi_running
) {
4358 json_object_free(json
);
4362 ret
= show_ip_ospf_interface_traffic_common(
4363 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4365 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4366 if (ospf
== NULL
|| !ospf
->oi_running
) {
4368 json_object_free(json
);
4372 ret
= show_ip_ospf_interface_traffic_common(
4373 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4377 vty_json(vty
, json
);
4383 static void show_ip_ospf_neighbour_header(struct vty
*vty
)
4385 vty_out(vty
, "\n%-15s %-3s %-15s %-15s %-9s %-15s %-32s %5s %5s %5s\n",
4386 "Neighbor ID", "Pri", "State", "Up Time", "Dead Time",
4387 "Address", "Interface", "RXmtL", "RqstL", "DBsmL");
4390 static void show_ip_ospf_neighbour_brief(struct vty
*vty
,
4391 struct ospf_neighbor
*nbr
,
4392 struct ospf_neighbor
*prev_nbr
,
4393 json_object
*json
, bool use_json
)
4396 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4397 json_object
*json_neighbor
= NULL
, *json_neigh_array
= NULL
;
4398 struct timeval res
= {.tv_sec
= 0, .tv_usec
= 0};
4400 char uptime
[OSPF_TIME_DUMP_SIZE
];
4402 if (nbr
->ts_last_progress
.tv_sec
|| nbr
->ts_last_progress
.tv_usec
)
4404 monotime_since(&nbr
->ts_last_progress
, &res
) / 1000LL;
4407 char neigh_str
[INET_ADDRSTRLEN
];
4409 if (prev_nbr
&& !IPV4_ADDR_SAME(&prev_nbr
->src
, &nbr
->src
)) {
4410 /* Start new neigh list */
4411 json_neigh_array
= NULL
;
4414 if (nbr
->state
== NSM_Attempt
&&
4415 nbr
->router_id
.s_addr
== INADDR_ANY
)
4416 strlcpy(neigh_str
, "neighbor", sizeof(neigh_str
));
4418 inet_ntop(AF_INET
, &nbr
->router_id
, neigh_str
,
4421 json_object_object_get_ex(json
, neigh_str
, &json_neigh_array
);
4423 if (!json_neigh_array
) {
4424 json_neigh_array
= json_object_new_array();
4425 json_object_object_add(json
, neigh_str
,
4429 json_neighbor
= json_object_new_object();
4431 ospf_nbr_ism_state_message(nbr
, msgbuf
, sizeof(msgbuf
));
4432 json_object_string_add(json_neighbor
, "nbrState", msgbuf
);
4434 json_object_int_add(json_neighbor
, "nbrPriority",
4437 json_object_string_add(
4438 json_neighbor
, "converged",
4439 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
4440 json_object_string_add(json_neighbor
, "role",
4441 lookup_msg(ospf_ism_state_msg
,
4442 ospf_nbr_ism_state(nbr
),
4444 if (nbr
->t_inactivity
) {
4447 time_store
= monotime_until(&nbr
->t_inactivity
->u
.sands
,
4450 json_object_int_add(json_neighbor
, "upTimeInMsec",
4452 json_object_int_add(json_neighbor
,
4453 "routerDeadIntervalTimerDueMsec",
4455 json_object_string_add(
4456 json_neighbor
, "upTime",
4457 ospf_timeval_dump(&res
, uptime
,
4459 json_object_string_add(
4460 json_neighbor
, "deadTime",
4461 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
4464 json_object_string_add(json_neighbor
, "deadTimeMsecs",
4466 json_object_string_add(json_neighbor
,
4467 "routerDeadIntervalTimerDueMsec",
4470 json_object_string_addf(json_neighbor
, "ifaceAddress", "%pI4",
4472 json_object_string_add(json_neighbor
, "ifaceName",
4474 json_object_int_add(json_neighbor
,
4475 "linkStateRetransmissionListCounter",
4476 ospf_ls_retransmit_count(nbr
));
4477 json_object_int_add(json_neighbor
,
4478 "linkStateRequestListCounter",
4479 ospf_ls_request_count(nbr
));
4480 json_object_int_add(json_neighbor
, "databaseSummaryListCounter",
4481 ospf_db_summary_count(nbr
));
4483 json_object_array_add(json_neigh_array
, json_neighbor
);
4485 ospf_nbr_ism_state_message(nbr
, msgbuf
, sizeof(msgbuf
));
4487 if (nbr
->state
== NSM_Attempt
&&
4488 nbr
->router_id
.s_addr
== INADDR_ANY
)
4489 vty_out(vty
, "%-15s %3d %-15s ", "-", nbr
->priority
,
4492 vty_out(vty
, "%-15pI4 %3d %-15s ", &nbr
->router_id
,
4493 nbr
->priority
, msgbuf
);
4495 vty_out(vty
, "%-15s ",
4496 ospf_timeval_dump(&res
, uptime
, sizeof(uptime
)));
4498 vty_out(vty
, "%9s ",
4499 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
4501 vty_out(vty
, "%-15pI4 ", &nbr
->src
);
4502 vty_out(vty
, "%-32s %5ld %5ld %5d\n", IF_NAME(nbr
->oi
),
4503 ospf_ls_retransmit_count(nbr
),
4504 ospf_ls_request_count(nbr
), ospf_db_summary_count(nbr
));
4508 static void show_ip_ospf_neighbor_sub(struct vty
*vty
,
4509 struct ospf_interface
*oi
,
4510 json_object
*json
, bool use_json
)
4512 struct route_node
*rn
;
4513 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
4515 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
4521 /* Do not show myself. */
4522 if (nbr
== oi
->nbr_self
)
4524 /* Down state is not shown. */
4525 if (nbr
->state
== NSM_Down
)
4530 show_ip_ospf_neighbour_brief(vty
, nbr
, prev_nbr
, json
,
4535 static int show_ip_ospf_neighbor_common(struct vty
*vty
, struct ospf
*ospf
,
4536 json_object
*json
, bool use_json
,
4539 struct ospf_interface
*oi
;
4540 struct listnode
*node
;
4541 json_object
*json_vrf
= NULL
;
4542 json_object
*json_nbr_sub
= NULL
;
4546 json_vrf
= json_object_new_object();
4549 json_nbr_sub
= json_object_new_object();
4552 if (ospf
->instance
) {
4554 json_object_int_add(json
, "ospfInstance",
4557 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4560 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4562 show_ip_ospf_neighbour_header(vty
);
4564 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4565 if (ospf_interface_neighbor_count(oi
) == 0)
4567 show_ip_ospf_neighbor_sub(vty
, oi
, json_nbr_sub
, use_json
);
4571 json_object_object_add(json_vrf
, "neighbors", json_nbr_sub
);
4573 json_object_object_add(json
, ospf_get_name(ospf
),
4581 DEFUN (show_ip_ospf_neighbor
,
4582 show_ip_ospf_neighbor_cmd
,
4583 "show ip ospf [vrf <NAME|all>] neighbor [json]",
4586 "OSPF information\n"
4593 bool uj
= use_json(argc
, argv
);
4594 struct listnode
*node
= NULL
;
4595 char *vrf_name
= NULL
;
4596 bool all_vrf
= false;
4597 int ret
= CMD_SUCCESS
;
4600 uint8_t use_vrf
= 0;
4601 json_object
*json
= NULL
;
4603 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4606 json
= json_object_new_object();
4608 /* vrf input is provided could be all or specific vrf*/
4612 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4613 if (!ospf
->oi_running
)
4615 ret
= show_ip_ospf_neighbor_common(
4616 vty
, ospf
, json
, uj
, use_vrf
);
4620 vty_json(vty
, json
);
4622 vty_out(vty
, "OSPF is not enabled\n");
4627 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4628 if (ospf
== NULL
|| !ospf
->oi_running
) {
4630 vty_json(vty
, json
);
4633 "%% OSPF is not enabled in vrf %s\n",
4639 /* Display default ospf (instance 0) info */
4640 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4641 if (ospf
== NULL
|| !ospf
->oi_running
) {
4643 vty_json(vty
, json
);
4646 "%% OSPF is not enabled in vrf default\n");
4653 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
,
4657 vty_out(vty
, "%s\n",
4658 json_object_to_json_string_ext(
4659 json
, JSON_C_TO_STRING_PRETTY
));
4664 json_object_free(json
);
4670 DEFUN (show_ip_ospf_instance_neighbor
,
4671 show_ip_ospf_instance_neighbor_cmd
,
4672 "show ip ospf (1-65535) neighbor [json]",
4675 "OSPF information\n"
4682 unsigned short instance
= 0;
4683 bool uj
= use_json(argc
, argv
);
4684 json_object
*json
= NULL
;
4685 int ret
= CMD_SUCCESS
;
4687 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4688 if (instance
!= ospf_instance
)
4689 return CMD_NOT_MY_INSTANCE
;
4691 ospf
= ospf_lookup_instance(instance
);
4692 if (!ospf
|| !ospf
->oi_running
)
4696 json
= json_object_new_object();
4698 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
, 0);
4701 vty_json(vty
, json
);
4706 static int show_ip_ospf_neighbor_all_common(struct vty
*vty
, struct ospf
*ospf
,
4707 json_object
*json
, bool use_json
,
4710 struct listnode
*node
;
4711 struct ospf_interface
*oi
;
4712 char buf
[PREFIX_STRLEN
];
4713 json_object
*json_vrf
= NULL
;
4714 json_object
*json_neighbor_sub
= NULL
;
4718 json_vrf
= json_object_new_object();
4723 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4725 show_ip_ospf_neighbour_header(vty
);
4727 if (ospf
->instance
) {
4729 json_object_int_add(json_vrf
, "ospfInstance",
4732 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4735 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4736 struct listnode
*nbr_node
;
4737 struct ospf_nbr_nbma
*nbr_nbma
;
4739 show_ip_ospf_neighbor_sub(vty
, oi
, json_vrf
, use_json
);
4741 /* print Down neighbor status */
4742 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nbr_node
, nbr_nbma
)) {
4743 if (nbr_nbma
->nbr
== NULL
4744 || nbr_nbma
->nbr
->state
== NSM_Down
) {
4747 json_object_new_object();
4748 json_object_int_add(json_neighbor_sub
,
4750 nbr_nbma
->priority
);
4751 json_object_boolean_true_add(
4754 json_object_string_add(
4758 json_object_int_add(
4760 "nbrNbmaRetransmitCounter", 0);
4761 json_object_int_add(
4763 "nbrNbmaRequestCounter", 0);
4764 json_object_int_add(
4766 "nbrNbmaDbSummaryCounter", 0);
4767 json_object_object_add(
4770 &nbr_nbma
->addr
, buf
,
4774 vty_out(vty
, "%-15s %3d %-15s %9s ",
4775 "-", nbr_nbma
->priority
, "Down",
4778 "%-32pI4 %-20s %5d %5d %5d\n",
4780 IF_NAME(oi
), 0, 0, 0);
4788 json_object_object_add(json
, ospf_get_name(ospf
),
4796 DEFUN (show_ip_ospf_neighbor_all
,
4797 show_ip_ospf_neighbor_all_cmd
,
4798 "show ip ospf [vrf <NAME|all>] neighbor all [json]",
4801 "OSPF information\n"
4805 "include down status neighbor\n"
4809 bool uj
= use_json(argc
, argv
);
4810 struct listnode
*node
= NULL
;
4811 char *vrf_name
= NULL
;
4812 bool all_vrf
= false;
4813 int ret
= CMD_SUCCESS
;
4816 uint8_t use_vrf
= 0;
4817 json_object
*json
= NULL
;
4819 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4822 json
= json_object_new_object();
4824 /* vrf input is provided could be all or specific vrf*/
4828 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4829 if (!ospf
->oi_running
)
4831 ret
= show_ip_ospf_neighbor_all_common(
4832 vty
, ospf
, json
, uj
, use_vrf
);
4836 vty_json(vty
, json
);
4841 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4842 if (ospf
== NULL
|| !ospf
->oi_running
) {
4844 json_object_free(json
);
4848 /* Display default ospf (instance 0) info */
4849 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4850 if (ospf
== NULL
|| !ospf
->oi_running
) {
4852 json_object_free(json
);
4858 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
,
4861 vty_out(vty
, "%s\n",
4862 json_object_to_json_string_ext(
4863 json
, JSON_C_TO_STRING_PRETTY
));
4868 json_object_free(json
);
4873 DEFUN (show_ip_ospf_instance_neighbor_all
,
4874 show_ip_ospf_instance_neighbor_all_cmd
,
4875 "show ip ospf (1-65535) neighbor all [json]",
4878 "OSPF information\n"
4881 "include down status neighbor\n"
4886 unsigned short instance
= 0;
4887 bool uj
= use_json(argc
, argv
);
4888 json_object
*json
= NULL
;
4889 int ret
= CMD_SUCCESS
;
4891 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4892 if (instance
!= ospf_instance
)
4893 return CMD_NOT_MY_INSTANCE
;
4895 ospf
= ospf_lookup_instance(instance
);
4896 if (!ospf
|| !ospf
->oi_running
)
4899 json
= json_object_new_object();
4901 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
, 0);
4904 vty_json(vty
, json
);
4909 static int show_ip_ospf_neighbor_int_common(struct vty
*vty
, struct ospf
*ospf
,
4910 const char *ifname
, bool use_json
,
4913 struct interface
*ifp
;
4914 struct route_node
*rn
;
4915 json_object
*json
= NULL
;
4918 json
= json_object_new_object();
4920 if (ospf
->instance
) {
4922 json_object_int_add(json
, "ospfInstance",
4925 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4928 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
4930 ifp
= if_lookup_by_name(ifname
, ospf
->vrf_id
);
4933 json_object_boolean_true_add(json
, "noSuchIface");
4935 vty_out(vty
, "No such interface.\n");
4939 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
4940 struct ospf_interface
*oi
= rn
->info
;
4945 show_ip_ospf_neighbor_sub(vty
, oi
, json
, use_json
);
4949 vty_json(vty
, json
);
4956 DEFPY(show_ip_ospf_instance_neighbor_int
,
4957 show_ip_ospf_instance_neighbor_int_cmd
,
4958 "show ip ospf (1-65535)$instance neighbor IFNAME$ifname [json$json]",
4961 "OSPF information\n"
4970 show_ip_ospf_neighbour_header(vty
);
4972 if (instance
!= ospf_instance
)
4973 return CMD_NOT_MY_INSTANCE
;
4975 ospf
= ospf_lookup_instance(instance
);
4976 if (!ospf
|| !ospf
->oi_running
)
4980 show_ip_ospf_neighbour_header(vty
);
4982 return show_ip_ospf_neighbor_int_common(vty
, ospf
, ifname
, !!json
, 0);
4985 static void show_ip_ospf_nbr_nbma_detail_sub(struct vty
*vty
,
4986 struct ospf_interface
*oi
,
4987 struct ospf_nbr_nbma
*nbr_nbma
,
4988 bool use_json
, json_object
*json
)
4990 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4991 json_object
*json_sub
= NULL
;
4994 json_sub
= json_object_new_object();
4995 else /* Show neighbor ID. */
4996 vty_out(vty
, " Neighbor %s,", "-");
4998 /* Show interface address. */
5000 json_object_string_addf(json_sub
, "ifaceAddress", "%pI4",
5003 vty_out(vty
, " interface address %pI4\n",
5008 json_object_string_add(json_sub
, "areaId",
5009 ospf_area_desc_string(oi
->area
));
5010 json_object_string_add(json_sub
, "iface", IF_NAME(oi
));
5012 vty_out(vty
, " In the area %s via interface %s\n",
5013 ospf_area_desc_string(oi
->area
), IF_NAME(oi
));
5015 /* Show neighbor priority and state. */
5017 json_object_int_add(json_sub
, "nbrPriority",
5018 nbr_nbma
->priority
);
5019 json_object_string_add(json_sub
, "nbrState", "down");
5021 vty_out(vty
, " Neighbor priority is %d, State is %s,",
5022 nbr_nbma
->priority
, "Down");
5024 /* Show state changes. */
5026 json_object_int_add(json_sub
, "stateChangeCounter",
5027 nbr_nbma
->state_change
);
5029 vty_out(vty
, " %d state changes\n", nbr_nbma
->state_change
);
5031 /* Show PollInterval */
5033 json_object_int_add(json_sub
, "pollInterval", nbr_nbma
->v_poll
);
5035 vty_out(vty
, " Poll interval %d\n", nbr_nbma
->v_poll
);
5037 /* Show poll-interval timer. */
5038 if (nbr_nbma
->t_poll
) {
5041 time_store
= monotime_until(&nbr_nbma
->t_poll
->u
.sands
,
5043 json_object_int_add(json_sub
,
5044 "pollIntervalTimerDueMsec",
5047 vty_out(vty
, " Poll timer due in %s\n",
5048 ospf_timer_dump(nbr_nbma
->t_poll
, timebuf
,
5052 /* Show poll-interval timer thread. */
5054 if (nbr_nbma
->t_poll
!= NULL
)
5055 json_object_string_add(json_sub
,
5056 "pollIntervalTimerThread", "on");
5058 vty_out(vty
, " Thread Poll Timer %s\n",
5059 nbr_nbma
->t_poll
!= NULL
? "on" : "off");
5062 json_object_object_add(json
, "noNbrId", json_sub
);
5065 static void show_ip_ospf_neighbor_detail_sub(struct vty
*vty
,
5066 struct ospf_interface
*oi
,
5067 struct ospf_neighbor
*nbr
,
5068 struct ospf_neighbor
*prev_nbr
,
5069 json_object
*json
, bool use_json
)
5071 char timebuf
[OSPF_TIME_DUMP_SIZE
];
5072 json_object
*json_neigh
= NULL
, *json_neigh_array
= NULL
;
5073 char neigh_str
[INET_ADDRSTRLEN
] = {0};
5074 char neigh_state
[16] = {0};
5075 struct ospf_neighbor
*nbr_dr
, *nbr_bdr
;
5079 !IPV4_ADDR_SAME(&prev_nbr
->src
, &nbr
->src
)) {
5080 json_neigh_array
= NULL
;
5083 if (nbr
->state
== NSM_Attempt
5084 && nbr
->router_id
.s_addr
== INADDR_ANY
)
5085 strlcpy(neigh_str
, "noNbrId", sizeof(neigh_str
));
5087 inet_ntop(AF_INET
, &nbr
->router_id
,
5088 neigh_str
, sizeof(neigh_str
));
5090 json_object_object_get_ex(json
, neigh_str
, &json_neigh_array
);
5092 if (!json_neigh_array
) {
5093 json_neigh_array
= json_object_new_array();
5094 json_object_object_add(json
, neigh_str
,
5098 json_neigh
= json_object_new_object();
5101 /* Show neighbor ID. */
5102 if (nbr
->state
== NSM_Attempt
5103 && nbr
->router_id
.s_addr
== INADDR_ANY
)
5104 vty_out(vty
, " Neighbor %s,", "-");
5106 vty_out(vty
, " Neighbor %pI4,",
5110 /* Show interface address. */
5112 json_object_string_addf(json_neigh
, "ifaceAddress", "%pI4",
5113 &nbr
->address
.u
.prefix4
);
5115 vty_out(vty
, " interface address %pI4\n",
5116 &nbr
->address
.u
.prefix4
);
5120 json_object_string_add(json_neigh
, "areaId",
5121 ospf_area_desc_string(oi
->area
));
5122 json_object_string_add(json_neigh
, "ifaceName", oi
->ifp
->name
);
5124 json_object_string_addf(json_neigh
, "localIfaceAddress",
5126 &oi
->address
->u
.prefix4
);
5128 vty_out(vty
, " In the area %s via interface %s",
5129 ospf_area_desc_string(oi
->area
), oi
->ifp
->name
);
5131 vty_out(vty
, " local interface IP %pI4\n",
5132 &oi
->address
->u
.prefix4
);
5137 /* Show neighbor priority and state. */
5138 ospf_nbr_ism_state_message(nbr
, neigh_state
, sizeof(neigh_state
));
5140 json_object_int_add(json_neigh
, "nbrPriority", nbr
->priority
);
5141 json_object_string_add(json_neigh
, "nbrState", neigh_state
);
5142 json_object_string_add(json_neigh
, "role",
5143 lookup_msg(ospf_ism_state_msg
,
5144 ospf_nbr_ism_state(nbr
),
5148 " Neighbor priority is %d, State is %s, Role is %s,",
5149 nbr
->priority
, neigh_state
,
5150 lookup_msg(ospf_ism_state_msg
, ospf_nbr_ism_state(nbr
),
5153 /* Show state changes. */
5155 json_object_int_add(json_neigh
, "stateChangeCounter",
5158 vty_out(vty
, " %d state changes\n", nbr
->state_change
);
5160 if (nbr
->ts_last_progress
.tv_sec
|| nbr
->ts_last_progress
.tv_usec
) {
5165 monotime_since(&nbr
->ts_last_progress
, &res
) / 1000LL;
5167 json_object_int_add(json_neigh
, "lastPrgrsvChangeMsec",
5171 " Most recent state change statistics:\n");
5172 vty_out(vty
, " Progressive change %s ago\n",
5173 ospf_timeval_dump(&res
, timebuf
,
5178 if (nbr
->ts_last_regress
.tv_sec
|| nbr
->ts_last_regress
.tv_usec
) {
5183 monotime_since(&nbr
->ts_last_regress
, &res
) / 1000LL;
5185 json_object_int_add(json_neigh
,
5186 "lastRegressiveChangeMsec",
5188 if (nbr
->last_regress_str
)
5189 json_object_string_add(
5191 "lastRegressiveChangeReason",
5192 nbr
->last_regress_str
);
5195 " Regressive change %s ago, due to %s\n",
5196 ospf_timeval_dump(&res
, timebuf
,
5198 (nbr
->last_regress_str
? nbr
->last_regress_str
5203 /* Show Designated Router ID. */
5204 if (DR(oi
).s_addr
== INADDR_ANY
) {
5207 " No designated router on this network\n");
5209 nbr_dr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &DR(oi
));
5212 json_object_string_addf(
5213 json_neigh
, "routerDesignatedId",
5214 "%pI4", &nbr_dr
->router_id
);
5216 vty_out(vty
, " DR is %pI4,",
5217 &nbr_dr
->router_id
);
5221 /* Show Backup Designated Router ID. */
5222 nbr_bdr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &BDR(oi
));
5223 if (nbr_bdr
== NULL
) {
5226 " No backup designated router on this network\n");
5229 json_object_string_addf(json_neigh
,
5230 "routerDesignatedBackupId",
5231 "%pI4", &nbr_bdr
->router_id
);
5233 vty_out(vty
, " BDR is %pI4\n", &nbr_bdr
->router_id
);
5238 json_object_int_add(json_neigh
, "optionsCounter", nbr
->options
);
5239 json_object_string_add(json_neigh
, "optionsList",
5240 ospf_options_dump(nbr
->options
));
5242 vty_out(vty
, " Options %d %s\n", nbr
->options
,
5243 ospf_options_dump(nbr
->options
));
5245 /* Show Router Dead interval timer. */
5247 if (nbr
->t_inactivity
) {
5249 time_store
= monotime_until(&nbr
->t_inactivity
->u
.sands
,
5252 json_object_int_add(json_neigh
,
5253 "routerDeadIntervalTimerDueMsec",
5256 json_object_int_add(
5258 "routerDeadIntervalTimerDueMsec", -1);
5260 vty_out(vty
, " Dead timer due in %s\n",
5261 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
5264 /* Show Database Summary list. */
5266 json_object_int_add(json_neigh
, "databaseSummaryListCounter",
5267 ospf_db_summary_count(nbr
));
5269 vty_out(vty
, " Database Summary List %d\n",
5270 ospf_db_summary_count(nbr
));
5272 /* Show Link State Request list. */
5274 json_object_int_add(json_neigh
, "linkStateRequestListCounter",
5275 ospf_ls_request_count(nbr
));
5277 vty_out(vty
, " Link State Request List %ld\n",
5278 ospf_ls_request_count(nbr
));
5280 /* Show Link State Retransmission list. */
5282 json_object_int_add(json_neigh
,
5283 "linkStateRetransmissionListCounter",
5284 ospf_ls_retransmit_count(nbr
));
5286 vty_out(vty
, " Link State Retransmission List %ld\n",
5287 ospf_ls_retransmit_count(nbr
));
5289 /* Show inactivity timer thread. */
5291 if (nbr
->t_inactivity
!= NULL
)
5292 json_object_string_add(json_neigh
,
5293 "threadInactivityTimer", "on");
5295 vty_out(vty
, " Thread Inactivity Timer %s\n",
5296 nbr
->t_inactivity
!= NULL
? "on" : "off");
5298 /* Show Database Description retransmission thread. */
5300 if (nbr
->t_db_desc
!= NULL
)
5301 json_object_string_add(
5303 "threadDatabaseDescriptionRetransmission",
5307 " Thread Database Description Retransmision %s\n",
5308 nbr
->t_db_desc
!= NULL
? "on" : "off");
5310 /* Show Link State Request Retransmission thread. */
5312 if (nbr
->t_ls_req
!= NULL
)
5313 json_object_string_add(
5315 "threadLinkStateRequestRetransmission", "on");
5318 " Thread Link State Request Retransmission %s\n",
5319 nbr
->t_ls_req
!= NULL
? "on" : "off");
5321 /* Show Link State Update Retransmission thread. */
5323 if (nbr
->t_ls_upd
!= NULL
)
5324 json_object_string_add(
5326 "threadLinkStateUpdateRetransmission",
5330 " Thread Link State Update Retransmission %s\n\n",
5331 nbr
->t_ls_upd
!= NULL
? "on" : "off");
5334 vty_out(vty
, " Graceful restart Helper info:\n");
5336 if (OSPF_GR_IS_ACTIVE_HELPER(nbr
)) {
5338 " Graceful Restart HELPER Status : Inprogress.\n");
5341 " Graceful Restart grace period time: %d (seconds).\n",
5342 nbr
->gr_helper_info
.recvd_grace_period
);
5343 vty_out(vty
, " Graceful Restart reason: %s.\n",
5344 ospf_restart_reason2str(
5345 nbr
->gr_helper_info
.gr_restart_reason
));
5348 " Graceful Restart HELPER Status : None\n");
5351 if (nbr
->gr_helper_info
.rejected_reason
5352 != OSPF_HELPER_REJECTED_NONE
)
5353 vty_out(vty
, " Helper rejected reason: %s.\n",
5354 ospf_rejected_reason2str(
5355 nbr
->gr_helper_info
.rejected_reason
));
5357 if (nbr
->gr_helper_info
.helper_exit_reason
5358 != OSPF_GR_HELPER_EXIT_NONE
)
5359 vty_out(vty
, " Last helper exit reason: %s.\n\n",
5360 ospf_exit_reason2str(
5361 nbr
->gr_helper_info
.helper_exit_reason
));
5365 json_object_string_add(json_neigh
, "grHelperStatus",
5366 OSPF_GR_IS_ACTIVE_HELPER(nbr
) ?
5369 if (OSPF_GR_IS_ACTIVE_HELPER(nbr
)) {
5370 json_object_int_add(
5371 json_neigh
, "graceInterval",
5372 nbr
->gr_helper_info
.recvd_grace_period
);
5373 json_object_string_add(
5374 json_neigh
, "grRestartReason",
5375 ospf_restart_reason2str(
5376 nbr
->gr_helper_info
.gr_restart_reason
));
5379 if (nbr
->gr_helper_info
.rejected_reason
5380 != OSPF_HELPER_REJECTED_NONE
)
5381 json_object_string_add(
5382 json_neigh
, "helperRejectReason",
5383 ospf_rejected_reason2str(
5384 nbr
->gr_helper_info
.rejected_reason
));
5386 if (nbr
->gr_helper_info
.helper_exit_reason
5387 != OSPF_GR_HELPER_EXIT_NONE
)
5388 json_object_string_add(
5389 json_neigh
, "helperExitReason",
5390 ospf_exit_reason2str(
5392 .helper_exit_reason
));
5395 bfd_sess_show(vty
, json_neigh
, nbr
->bfd_session
);
5398 json_object_array_add(json_neigh_array
, json_neigh
);
5402 static int show_ip_ospf_neighbor_id_common(struct vty
*vty
, struct ospf
*ospf
,
5403 struct in_addr
*router_id
,
5404 bool use_json
, uint8_t use_vrf
,
5406 json_object
*json_vrf
)
5408 struct listnode
*node
;
5409 struct ospf_neighbor
*nbr
;
5410 struct ospf_interface
*oi
;
5411 json_object
*json
= NULL
;
5414 json
= json_object_new_object();
5416 if (ospf
->instance
) {
5418 json_object_int_add(json
, "ospfInstance",
5421 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5424 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
5426 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5427 nbr
= ospf_nbr_lookup_by_routerid(oi
->nbrs
, router_id
);
5433 show_ip_ospf_neighbor_detail_sub(vty
, oi
, nbr
, NULL
,
5436 show_ip_ospf_neighbour_brief(vty
, nbr
, NULL
, json
,
5440 if (json_vrf
&& use_json
) {
5441 json_object_object_add(
5443 (ospf
->vrf_id
== VRF_DEFAULT
) ? "default" : ospf
->name
,
5449 vty_json(vty
, json
);
5456 DEFPY(show_ip_ospf_neighbor_id
,
5457 show_ip_ospf_neighbor_id_cmd
,
5458 "show ip ospf [vrf NAME$vrf_name] neighbor A.B.C.D$router_id [detail$detail] [json$json]",
5461 "OSPF information\n"
5469 struct listnode
*node
;
5470 int ret
= CMD_SUCCESS
;
5473 if (vrf_name
&& !strmatch(vrf_name
, "all")) {
5474 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5475 if (ospf
== NULL
|| !ospf
->oi_running
) {
5478 "%% OSPF is not enabled in vrf %s\n",
5481 vty_json_empty(vty
);
5484 ret
= show_ip_ospf_neighbor_id_common(
5485 vty
, ospf
, &router_id
, !!json
, 0, !!detail
, NULL
);
5487 json_object
*json_vrf
= NULL
;
5490 json_vrf
= json_object_new_object();
5491 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5492 if (!ospf
->oi_running
)
5494 ret
= show_ip_ospf_neighbor_id_common(
5495 vty
, ospf
, &router_id
, !!json
, 0, !!detail
,
5499 vty_json(vty
, json_vrf
);
5505 DEFPY(show_ip_ospf_instance_neighbor_id
, show_ip_ospf_instance_neighbor_id_cmd
,
5506 "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [detail$detail] [json$json]",
5508 "OSPF information\n"
5512 "Detailed output\n" JSON_STR
)
5516 if (instance
!= ospf_instance
)
5517 return CMD_NOT_MY_INSTANCE
;
5519 ospf
= ospf_lookup_instance(instance
);
5520 if (!ospf
|| !ospf
->oi_running
)
5523 return show_ip_ospf_neighbor_id_common(vty
, ospf
, &router_id
, !!json
, 0,
5527 static int show_ip_ospf_neighbor_detail_common(struct vty
*vty
,
5529 json_object
*json
, bool use_json
,
5532 struct ospf_interface
*oi
;
5533 struct listnode
*node
;
5534 json_object
*json_vrf
= NULL
;
5535 json_object
*json_nbr_sub
= NULL
;
5539 json_vrf
= json_object_new_object();
5543 json_nbr_sub
= json_object_new_object();
5546 if (ospf
->instance
) {
5548 json_object_int_add(json
, "ospfInstance",
5551 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5554 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5556 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5557 struct route_node
*rn
;
5558 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
5560 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5566 if (nbr
!= oi
->nbr_self
) {
5567 if (nbr
->state
!= NSM_Down
) {
5568 show_ip_ospf_neighbor_detail_sub(
5569 vty
, oi
, nbr
, prev_nbr
,
5570 json_nbr_sub
, use_json
);
5578 json_object_object_add(json_vrf
, "neighbors",
5581 json_object_object_add(json
, ospf_get_name(ospf
),
5589 DEFPY(show_ip_ospf_neighbor_detail
,
5590 show_ip_ospf_neighbor_detail_cmd
,
5591 "show ip ospf [vrf <NAME|all>$vrf_name] neighbor detail [json$json]",
5594 "OSPF information\n"
5598 "detail of all neighbors\n"
5602 struct listnode
*node
= NULL
;
5603 int ret
= CMD_SUCCESS
;
5605 uint8_t use_vrf
= 0;
5606 json_object
*json_vrf
= NULL
;
5609 json_vrf
= json_object_new_object();
5611 /* vrf input is provided could be all or specific vrf*/
5614 if (strmatch(vrf_name
, "all")) {
5615 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5616 if (!ospf
->oi_running
)
5618 ret
= show_ip_ospf_neighbor_detail_common(
5619 vty
, ospf
, json_vrf
, !!json
, use_vrf
);
5622 vty_json(vty
, json_vrf
);
5626 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5627 if (ospf
== NULL
|| !ospf
->oi_running
) {
5629 vty_json(vty
, json_vrf
);
5632 "%% OSPF is not enabled in vrf %s\n",
5637 /* Display default ospf (instance 0) info */
5638 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5639 if (ospf
== NULL
|| !ospf
->oi_running
) {
5641 vty_json(vty
, json_vrf
);
5643 vty_out(vty
, "%% OSPF is not enabled\n");
5649 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json_vrf
,
5653 vty_json(vty
, json_vrf
);
5658 DEFUN (show_ip_ospf_instance_neighbor_detail
,
5659 show_ip_ospf_instance_neighbor_detail_cmd
,
5660 "show ip ospf (1-65535) neighbor detail [json]",
5663 "OSPF information\n"
5666 "detail of all neighbors\n"
5671 unsigned short instance
= 0;
5672 bool uj
= use_json(argc
, argv
);
5673 json_object
*json
= NULL
;
5674 int ret
= CMD_SUCCESS
;
5676 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5677 if (instance
!= ospf_instance
)
5678 return CMD_NOT_MY_INSTANCE
;
5680 ospf
= ospf_lookup_instance(instance
);
5681 if (!ospf
|| !ospf
->oi_running
)
5685 json
= json_object_new_object();
5687 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
, 0);
5690 vty_json(vty
, json
);
5695 static int show_ip_ospf_neighbor_detail_all_common(struct vty
*vty
,
5701 struct listnode
*node
;
5702 struct ospf_interface
*oi
;
5703 json_object
*json_vrf
= NULL
;
5707 json_vrf
= json_object_new_object();
5712 if (ospf
->instance
) {
5714 json_object_int_add(json
, "ospfInstance",
5717 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5720 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5722 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5723 struct route_node
*rn
;
5724 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
5725 struct ospf_nbr_nbma
*nbr_nbma
;
5727 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5733 if (nbr
!= oi
->nbr_self
)
5734 if (nbr
->state
!= NSM_Down
)
5735 show_ip_ospf_neighbor_detail_sub(
5736 vty
, oi
, rn
->info
, prev_nbr
,
5737 json_vrf
, use_json
);
5741 if (oi
->type
!= OSPF_IFTYPE_NBMA
)
5744 struct listnode
*nd
;
5746 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nd
, nbr_nbma
)) {
5747 if (nbr_nbma
->nbr
== NULL
||
5748 nbr_nbma
->nbr
->state
== NSM_Down
)
5749 show_ip_ospf_nbr_nbma_detail_sub(
5750 vty
, oi
, nbr_nbma
, use_json
, json_vrf
);
5756 json_object_object_add(json
, ospf_get_name(ospf
),
5765 DEFUN (show_ip_ospf_neighbor_detail_all
,
5766 show_ip_ospf_neighbor_detail_all_cmd
,
5767 "show ip ospf [vrf <NAME|all>] neighbor detail all [json]",
5770 "OSPF information\n"
5774 "detail of all neighbors\n"
5775 "include down status neighbor\n"
5779 bool uj
= use_json(argc
, argv
);
5780 struct listnode
*node
= NULL
;
5781 char *vrf_name
= NULL
;
5782 bool all_vrf
= false;
5783 int ret
= CMD_SUCCESS
;
5786 uint8_t use_vrf
= 0;
5787 json_object
*json
= NULL
;
5789 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5792 json
= json_object_new_object();
5794 /* vrf input is provided could be all or specific vrf*/
5798 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5799 if (!ospf
->oi_running
)
5801 ret
= show_ip_ospf_neighbor_detail_all_common(
5802 vty
, ospf
, json
, uj
, use_vrf
);
5806 vty_json(vty
, json
);
5810 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5811 if (ospf
== NULL
|| !ospf
->oi_running
) {
5813 json_object_free(json
);
5817 /* Display default ospf (instance 0) info */
5818 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5819 if (ospf
== NULL
|| !ospf
->oi_running
) {
5821 json_object_free(json
);
5827 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
,
5830 vty_out(vty
, "%s\n",
5831 json_object_to_json_string_ext(
5832 json
, JSON_C_TO_STRING_PRETTY
));
5837 json_object_free(json
);
5842 DEFUN (show_ip_ospf_instance_neighbor_detail_all
,
5843 show_ip_ospf_instance_neighbor_detail_all_cmd
,
5844 "show ip ospf (1-65535) neighbor detail all [json]",
5847 "OSPF information\n"
5850 "detail of all neighbors\n"
5851 "include down status neighbor\n"
5856 unsigned short instance
= 0;
5857 bool uj
= use_json(argc
, argv
);
5858 json_object
*json
= NULL
;
5859 int ret
= CMD_SUCCESS
;
5861 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5862 if (instance
!= ospf_instance
)
5863 return CMD_NOT_MY_INSTANCE
;
5865 ospf
= ospf_lookup_instance(instance
);
5866 if (!ospf
|| !ospf
->oi_running
)
5870 json
= json_object_new_object();
5872 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
, uj
, 0);
5875 vty_json(vty
, json
);
5880 static int show_ip_ospf_neighbor_int_detail_common(struct vty
*vty
,
5884 json_object
*json_vrf
)
5886 struct ospf_interface
*oi
;
5887 struct interface
*ifp
;
5888 struct route_node
*rn
, *nrn
;
5889 struct ospf_neighbor
*nbr
;
5890 json_object
*json
= NULL
;
5893 json
= json_object_new_object();
5895 json_object_object_add(json_vrf
,
5896 (ospf
->vrf_id
== VRF_DEFAULT
)
5902 if (ospf
->instance
) {
5904 json_object_int_add(json
, "ospfInstance",
5907 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5910 ifp
= if_lookup_by_name(ifname
, ospf
->vrf_id
);
5913 vty_out(vty
, "No such interface.\n");
5916 vty_json(vty
, json
);
5921 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
5927 for (nrn
= route_top(oi
->nbrs
); nrn
; nrn
= route_next(nrn
)) {
5933 if (nbr
== oi
->nbr_self
)
5936 if (nbr
->state
== NSM_Down
)
5939 show_ip_ospf_neighbor_detail_sub(vty
, oi
, nbr
, NULL
,
5946 vty_json(vty
, json
);
5954 DEFPY(show_ip_ospf_neighbor_int
,
5955 show_ip_ospf_neighbor_int_cmd
,
5956 "show ip ospf [vrf NAME$vrf_name] neighbor IFNAME$ifname [json$json]",
5959 "OSPF information\n"
5966 int ret
= CMD_SUCCESS
;
5967 struct interface
*ifp
= NULL
;
5968 vrf_id_t vrf_id
= VRF_DEFAULT
;
5969 struct vrf
*vrf
= NULL
;
5971 if (vrf_name
&& strmatch(vrf_name
, VRF_DEFAULT_NAME
))
5974 vrf
= vrf_lookup_by_name(vrf_name
);
5976 vrf_id
= vrf
->vrf_id
;
5978 ospf
= ospf_lookup_by_vrf_id(vrf_id
);
5980 if (!ospf
|| !ospf
->oi_running
) {
5982 vty_json_empty(vty
);
5987 show_ip_ospf_neighbour_header(vty
);
5989 ifp
= if_lookup_by_name(ifname
, vrf_id
);
5992 vty_json_empty(vty
);
5994 vty_out(vty
, "No such interface.\n");
5998 ret
= show_ip_ospf_neighbor_int_common(vty
, ospf
, ifname
, !!json
, 0);
6002 DEFPY(show_ip_ospf_neighbor_int_detail
,
6003 show_ip_ospf_neighbor_int_detail_cmd
,
6004 "show ip ospf [vrf NAME$vrf_name] neighbor IFNAME$ifname detail [json$json]",
6007 "OSPF information\n"
6011 "detail of all neighbors\n"
6015 struct listnode
*node
= NULL
;
6016 int ret
= CMD_SUCCESS
;
6017 bool ospf_output
= false;
6019 if (vrf_name
&& !strmatch(vrf_name
, "all")) {
6022 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6023 if (ospf
== NULL
|| !ospf
->oi_running
) {
6026 "%% OSPF is not enabled in vrf %s\n",
6029 vty_json_empty(vty
);
6032 return show_ip_ospf_neighbor_int_detail_common(
6033 vty
, ospf
, ifname
, !!json
, NULL
);
6036 json_object
*json_vrf
= NULL
;
6039 json_vrf
= json_object_new_object();
6041 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6042 if (!ospf
->oi_running
)
6045 ret
= show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, ifname
,
6050 vty_json(vty
, json_vrf
);
6055 vty_out(vty
, "%% OSPF instance not found\n");
6060 DEFPY(show_ip_ospf_instance_neighbor_int_detail
,
6061 show_ip_ospf_instance_neighbor_int_detail_cmd
,
6062 "show ip ospf (1-65535)$instance neighbor IFNAME$ifname detail [json$json]",
6065 "OSPF information\n"
6069 "detail of all neighbors\n"
6074 if (instance
!= ospf_instance
)
6075 return CMD_NOT_MY_INSTANCE
;
6077 ospf
= ospf_lookup_instance(instance
);
6078 if (!ospf
|| !ospf
->oi_running
)
6081 return show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, ifname
,
6085 /* Show functions */
6086 static int show_lsa_summary(struct vty
*vty
, struct ospf_lsa
*lsa
, int self
,
6087 json_object
*json_lsa
)
6089 struct router_lsa
*rl
;
6090 struct summary_lsa
*sl
;
6091 struct as_external_lsa
*asel
;
6092 struct prefix_ipv4 p
;
6097 /* If self option is set, check LSA self flag. */
6098 if (self
== 0 || IS_LSA_SELF(lsa
)) {
6101 /* LSA common part show. */
6102 vty_out(vty
, "%-15pI4", &lsa
->data
->id
);
6103 vty_out(vty
, "%-15pI4 %4d 0x%08lx 0x%04x",
6104 &lsa
->data
->adv_router
, LS_AGE(lsa
),
6105 (unsigned long)ntohl(lsa
->data
->ls_seqnum
),
6106 ntohs(lsa
->data
->checksum
));
6111 snprintf(seqnum
, sizeof(seqnum
), "%x",
6112 ntohl(lsa
->data
->ls_seqnum
));
6113 snprintf(checksum
, sizeof(checksum
), "%x",
6114 ntohs(lsa
->data
->checksum
));
6115 json_object_string_addf(json_lsa
, "lsId", "%pI4",
6117 json_object_string_addf(json_lsa
, "advertisedRouter",
6118 "%pI4", &lsa
->data
->adv_router
);
6119 json_object_int_add(json_lsa
, "lsaAge", LS_AGE(lsa
));
6120 json_object_string_add(json_lsa
, "sequenceNumber",
6122 json_object_string_add(json_lsa
, "checksum", checksum
);
6125 /* LSA specific part show. */
6126 switch (lsa
->data
->type
) {
6127 case OSPF_ROUTER_LSA
:
6128 rl
= (struct router_lsa
*)lsa
->data
;
6131 vty_out(vty
, " %-d", ntohs(rl
->links
));
6133 json_object_int_add(json_lsa
,
6137 case OSPF_SUMMARY_LSA
:
6138 sl
= (struct summary_lsa
*)lsa
->data
;
6141 p
.prefix
= sl
->header
.id
;
6142 p
.prefixlen
= ip_masklen(sl
->mask
);
6143 apply_mask_ipv4(&p
);
6146 vty_out(vty
, " %pFX", &p
);
6148 json_object_string_addf(
6149 json_lsa
, "summaryAddress", "%pFX", &p
);
6152 case OSPF_AS_EXTERNAL_LSA
:
6153 case OSPF_AS_NSSA_LSA
:
6154 asel
= (struct as_external_lsa
*)lsa
->data
;
6157 p
.prefix
= asel
->header
.id
;
6158 p
.prefixlen
= ip_masklen(asel
->mask
);
6159 apply_mask_ipv4(&p
);
6162 vty_out(vty
, " %s %pFX [0x%lx]",
6163 IS_EXTERNAL_METRIC(asel
->e
[0].tos
)
6167 (unsigned long)ntohl(
6168 asel
->e
[0].route_tag
));
6170 json_object_string_add(
6171 json_lsa
, "metricType",
6172 IS_EXTERNAL_METRIC(asel
->e
[0].tos
)
6175 json_object_string_addf(json_lsa
, "route",
6177 json_object_int_add(
6179 (unsigned long)ntohl(
6180 asel
->e
[0].route_tag
));
6183 case OSPF_NETWORK_LSA
:
6184 case OSPF_ASBR_SUMMARY_LSA
:
6185 case OSPF_OPAQUE_LINK_LSA
:
6186 case OSPF_OPAQUE_AREA_LSA
:
6187 case OSPF_OPAQUE_AS_LSA
:
6199 static const char *const show_database_desc
[] = {
6201 "Router Link States",
6203 "Summary Link States",
6204 "ASBR-Summary Link States",
6205 "AS External Link States",
6206 "Group Membership LSA",
6207 "NSSA-external Link States",
6209 "Link-Local Opaque-LSA",
6210 "Area-Local Opaque-LSA",
6211 "AS-external Opaque-LSA",
6214 static const char * const show_database_desc_json
[] = {
6217 "networkLinkStates",
6218 "summaryLinkStates",
6219 "asbrSummaryLinkStates",
6220 "asExternalLinkStates",
6221 "groupMembershipLsa",
6222 "nssaExternalLinkStates",
6224 "linkLocalOpaqueLsa",
6225 "areaLocalOpaqueLsa",
6226 "asExternalOpaqueLsa",
6229 static const char *const show_database_desc_count_json
[] = {
6231 "routerLinkStatesCount",
6232 "networkLinkStatesCount",
6233 "summaryLinkStatesCount",
6234 "asbrSummaryLinkStatesCount",
6235 "asExternalLinkStatesCount",
6236 "groupMembershipLsaCount",
6237 "nssaExternalLinkStatesCount",
6239 "linkLocalOpaqueLsaCount",
6240 "areaLocalOpaqueLsaCount",
6241 "asExternalOpaqueLsaCount",
6244 static const char *const show_database_header
[] = {
6246 "Link ID ADV Router Age Seq# CkSum Link count",
6247 "Link ID ADV Router Age Seq# CkSum",
6248 "Link ID ADV Router Age Seq# CkSum Route",
6249 "Link ID ADV Router Age Seq# CkSum",
6250 "Link ID ADV Router Age Seq# CkSum Route",
6251 " --- header for Group Member ----",
6252 "Link ID ADV Router Age Seq# CkSum Route",
6254 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6255 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6256 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6259 static void show_ip_ospf_database_header(struct vty
*vty
, struct ospf_lsa
*lsa
,
6262 struct router_lsa
*rlsa
= (struct router_lsa
*)lsa
->data
;
6265 if (IS_LSA_SELF(lsa
))
6266 vty_out(vty
, " LS age: %d%s\n", LS_AGE(lsa
),
6267 CHECK_FLAG(lsa
->data
->ls_age
, DO_NOT_AGE
)
6271 vty_out(vty
, " LS age: %d%s\n", LS_AGE(lsa
),
6272 CHECK_FLAG(lsa
->data
->ls_age
, DO_NOT_AGE
)
6275 vty_out(vty
, " Options: 0x%-2x : %s\n", lsa
->data
->options
,
6276 ospf_options_dump(lsa
->data
->options
));
6277 vty_out(vty
, " LS Flags: 0x%-2x %s\n", lsa
->flags
,
6278 ((lsa
->flags
& OSPF_LSA_LOCAL_XLT
)
6279 ? "(Translated from Type-7)"
6282 if (lsa
->data
->type
== OSPF_ROUTER_LSA
) {
6283 vty_out(vty
, " Flags: 0x%x", rlsa
->flags
);
6286 vty_out(vty
, " :%s%s%s%s",
6287 IS_ROUTER_LSA_BORDER(rlsa
) ? " ABR"
6289 IS_ROUTER_LSA_EXTERNAL(rlsa
) ? " ASBR"
6291 IS_ROUTER_LSA_VIRTUAL(rlsa
)
6294 IS_ROUTER_LSA_SHORTCUT(rlsa
)
6300 vty_out(vty
, " LS Type: %s\n",
6301 lookup_msg(ospf_lsa_type_msg
, lsa
->data
->type
, NULL
));
6302 vty_out(vty
, " Link State ID: %pI4 %s\n",
6304 lookup_msg(ospf_link_state_id_type_msg
, lsa
->data
->type
,
6306 vty_out(vty
, " Advertising Router: %pI4\n",
6307 &lsa
->data
->adv_router
);
6308 vty_out(vty
, " LS Seq Number: %08lx\n",
6309 (unsigned long)ntohl(lsa
->data
->ls_seqnum
));
6310 vty_out(vty
, " Checksum: 0x%04x\n",
6311 ntohs(lsa
->data
->checksum
));
6312 vty_out(vty
, " Length: %d\n\n", ntohs(lsa
->data
->length
));
6317 snprintf(seqnum
, 10, "%x", ntohl(lsa
->data
->ls_seqnum
));
6318 snprintf(checksum
, 10, "%x", ntohs(lsa
->data
->checksum
));
6320 json_object_int_add(json
, "lsaAge", LS_AGE(lsa
));
6321 json_object_string_add(json
, "options",
6322 ospf_options_dump(lsa
->data
->options
));
6323 json_object_int_add(json
, "lsaFlags", lsa
->flags
);
6325 if (lsa
->flags
& OSPF_LSA_LOCAL_XLT
)
6326 json_object_boolean_true_add(json
,
6327 "translatedFromType7");
6329 if (lsa
->data
->type
== OSPF_ROUTER_LSA
) {
6330 json_object_int_add(json
, "flags", rlsa
->flags
);
6333 if (IS_ROUTER_LSA_BORDER(rlsa
))
6334 json_object_boolean_true_add(json
,
6336 if (IS_ROUTER_LSA_EXTERNAL(rlsa
))
6337 json_object_boolean_true_add(json
,
6339 if (IS_ROUTER_LSA_VIRTUAL(rlsa
))
6340 json_object_boolean_true_add(
6341 json
, "vlEndpoint");
6342 if (IS_ROUTER_LSA_SHORTCUT(rlsa
))
6343 json_object_boolean_true_add(
6348 json_object_string_add(
6350 lookup_msg(ospf_lsa_type_msg
, lsa
->data
->type
, NULL
));
6351 json_object_string_addf(json
, "linkStateId", "%pI4",
6353 json_object_string_addf(json
, "advertisingRouter", "%pI4",
6354 &lsa
->data
->adv_router
);
6355 json_object_string_add(json
, "lsaSeqNumber", seqnum
);
6356 json_object_string_add(json
, "checksum", checksum
);
6357 json_object_int_add(json
, "length", ntohs(lsa
->data
->length
));
6361 static const char *const link_type_desc
[] = {
6363 "another Router (point-to-point)",
6364 "a Transit Network",
6369 static const char *const link_id_desc
[] = {
6370 "(null)", "Neighboring Router ID", "Designated Router address",
6371 "Net", "Neighboring Router ID",
6374 static const char *const link_data_desc
[] = {
6375 "(null)", "Router Interface address", "Router Interface address",
6376 "Network Mask", "Router Interface address",
6379 static const char *const link_id_desc_json
[] = {
6380 "null", "neighborRouterId", "designatedRouterAddress",
6381 "networkAddress", "neighborRouterId",
6384 static const char *const link_data_desc_json
[] = {
6385 "null", "routerInterfaceAddress", "routerInterfaceAddress",
6386 "networkMask", "routerInterfaceAddress",
6389 /* Show router-LSA each Link information. */
6390 static void show_ip_ospf_database_router_links(struct vty
*vty
,
6391 struct router_lsa
*rl
,
6396 json_object
*json_links
= NULL
;
6397 json_object
*json_link
= NULL
;
6399 char buf
[PREFIX_STRLEN
];
6402 json_links
= json_object_new_object();
6404 len
= ntohs(rl
->header
.length
) - 4;
6405 for (i
= 0; i
< ntohs(rl
->links
) && len
> 0; len
-= 12, i
++) {
6406 type
= rl
->link
[i
].type
;
6411 snprintf(link
, sizeof(link
), "link%u", i
);
6412 json_link
= json_object_new_object();
6413 json_object_string_add(json_link
, "linkType",
6414 link_type_desc
[type
]);
6415 json_object_string_add(json_link
,
6416 link_id_desc_json
[type
],
6418 &rl
->link
[i
].link_id
,
6420 json_object_string_add(
6421 json_link
, link_data_desc_json
[type
],
6422 inet_ntop(AF_INET
, &rl
->link
[i
].link_data
,
6424 json_object_int_add(json_link
, "numOfTosMetrics",
6426 json_object_int_add(json_link
, "tos0Metric",
6427 ntohs(rl
->link
[i
].metric
));
6428 json_object_object_add(json_links
, link
, json_link
);
6430 vty_out(vty
, " Link connected to: %s\n",
6431 link_type_desc
[type
]);
6432 vty_out(vty
, " (Link ID) %s: %pI4\n",
6434 &rl
->link
[i
].link_id
);
6435 vty_out(vty
, " (Link Data) %s: %pI4\n",
6436 link_data_desc
[type
],
6437 &rl
->link
[i
].link_data
);
6438 vty_out(vty
, " Number of TOS metrics: 0\n");
6439 vty_out(vty
, " TOS 0 Metric: %d\n",
6440 ntohs(rl
->link
[i
].metric
));
6445 json_object_object_add(json
, "routerLinks", json_links
);
6448 /* Show router-LSA detail information. */
6449 static int show_router_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6453 struct router_lsa
*rl
= (struct router_lsa
*)lsa
->data
;
6455 show_ip_ospf_database_header(vty
, lsa
, json
);
6458 vty_out(vty
, " Number of Links: %d\n\n",
6461 json_object_int_add(json
, "numOfLinks",
6464 show_ip_ospf_database_router_links(vty
, rl
, json
);
6473 /* Show network-LSA detail information. */
6474 static int show_network_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6478 char buf
[PREFIX_STRLEN
];
6479 json_object
*json_attached_rt
= NULL
;
6480 json_object
*json_router
= NULL
;
6483 json_attached_rt
= json_object_new_object();
6486 struct network_lsa
*nl
= (struct network_lsa
*)lsa
->data
;
6487 struct in_addr
*addr
;
6489 show_ip_ospf_database_header(vty
, lsa
, json
);
6492 vty_out(vty
, " Network Mask: /%d\n",
6493 ip_masklen(nl
->mask
));
6495 json_object_int_add(json
, "networkMask",
6496 ip_masklen(nl
->mask
));
6498 length
= lsa
->size
- OSPF_LSA_HEADER_SIZE
- 4;
6499 addr
= &nl
->routers
[0];
6500 for (i
= 0; length
> 0 && addr
;
6501 length
-= 4, addr
= &nl
->routers
[++i
])
6503 vty_out(vty
, " Attached Router: %pI4\n",
6507 json_router
= json_object_new_object();
6508 json_object_string_add(
6509 json_router
, "attachedRouterId",
6510 inet_ntop(AF_INET
, addr
, buf
,
6512 json_object_object_add(json_attached_rt
,
6513 inet_ntop(AF_INET
, addr
,
6521 json_object_object_add(json
, "attchedRouters",
6527 /* Show summary-LSA detail information. */
6528 static int show_summary_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6532 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
6534 show_ip_ospf_database_header(vty
, lsa
, json
);
6537 vty_out(vty
, " Network Mask: /%d\n",
6538 ip_masklen(sl
->mask
));
6539 vty_out(vty
, " TOS: 0 Metric: %d\n",
6540 GET_METRIC(sl
->metric
));
6543 json_object_int_add(json
, "networkMask",
6544 ip_masklen(sl
->mask
));
6545 json_object_int_add(json
, "tos0Metric",
6546 GET_METRIC(sl
->metric
));
6553 /* Show summary-ASBR-LSA detail information. */
6554 static int show_summary_asbr_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6558 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
6560 show_ip_ospf_database_header(vty
, lsa
, json
);
6563 vty_out(vty
, " Network Mask: /%d\n",
6564 ip_masklen(sl
->mask
));
6565 vty_out(vty
, " TOS: 0 Metric: %d\n",
6566 GET_METRIC(sl
->metric
));
6569 json_object_int_add(json
, "networkMask",
6570 ip_masklen(sl
->mask
));
6571 json_object_int_add(json
, "tos0Metric",
6572 GET_METRIC(sl
->metric
));
6579 /* Show AS-external-LSA detail information. */
6580 static int show_as_external_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6586 struct as_external_lsa
*al
=
6587 (struct as_external_lsa
*)lsa
->data
;
6589 show_ip_ospf_database_header(vty
, lsa
, json
);
6592 vty_out(vty
, " Network Mask: /%d\n",
6593 ip_masklen(al
->mask
));
6594 vty_out(vty
, " Metric Type: %s\n",
6595 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6596 ? "2 (Larger than any link state path)"
6598 vty_out(vty
, " TOS: 0\n");
6599 vty_out(vty
, " Metric: %d\n",
6600 GET_METRIC(al
->e
[0].metric
));
6601 vty_out(vty
, " Forward Address: %pI4\n",
6602 &al
->e
[0].fwd_addr
);
6604 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
6605 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6607 json_object_int_add(json
, "networkMask",
6608 ip_masklen(al
->mask
));
6609 json_object_string_add(
6611 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6612 ? "E2 (Larger than any link state path)"
6614 json_object_int_add(json
, "tos", tos
);
6615 json_object_int_add(json
, "metric",
6616 GET_METRIC(al
->e
[0].metric
));
6617 json_object_string_addf(json
, "forwardAddress", "%pI4",
6618 &(al
->e
[0].fwd_addr
));
6619 json_object_int_add(
6620 json
, "externalRouteTag",
6621 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6628 /* Show AS-NSSA-LSA detail information. */
6629 static int show_as_nssa_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6635 struct as_external_lsa
*al
=
6636 (struct as_external_lsa
*)lsa
->data
;
6638 show_ip_ospf_database_header(vty
, lsa
, json
);
6641 vty_out(vty
, " Network Mask: /%d\n",
6642 ip_masklen(al
->mask
));
6643 vty_out(vty
, " Metric Type: %s\n",
6644 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6645 ? "2 (Larger than any link state path)"
6647 vty_out(vty
, " TOS: 0\n");
6648 vty_out(vty
, " Metric: %d\n",
6649 GET_METRIC(al
->e
[0].metric
));
6650 vty_out(vty
, " NSSA: Forward Address: %pI4\n",
6651 &al
->e
[0].fwd_addr
);
6653 " External Route Tag: %" ROUTE_TAG_PRI
6655 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6657 json_object_int_add(json
, "networkMask",
6658 ip_masklen(al
->mask
));
6659 json_object_string_add(
6661 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6662 ? "E2 (Larger than any link state path)"
6664 json_object_int_add(json
, "tos", tos
);
6665 json_object_int_add(json
, "metric",
6666 GET_METRIC(al
->e
[0].metric
));
6667 json_object_string_addf(json
, "nssaForwardAddress",
6668 "%pI4", &al
->e
[0].fwd_addr
);
6669 json_object_int_add(
6670 json
, "externalRouteTag",
6671 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6678 static int show_func_dummy(struct vty
*vty
, struct ospf_lsa
*lsa
,
6684 static int show_opaque_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6688 show_ip_ospf_database_header(vty
, lsa
, json
);
6689 show_opaque_info_detail(vty
, lsa
, json
);
6696 int (*show_function
[])(struct vty
*, struct ospf_lsa
*, json_object
*) = {
6698 show_router_lsa_detail
,
6699 show_network_lsa_detail
,
6700 show_summary_lsa_detail
,
6701 show_summary_asbr_lsa_detail
,
6702 show_as_external_lsa_detail
,
6704 show_as_nssa_lsa_detail
, /* almost same as external */
6706 show_opaque_lsa_detail
,
6707 show_opaque_lsa_detail
,
6708 show_opaque_lsa_detail
,
6711 static void show_lsa_prefix_set(struct vty
*vty
, struct prefix_ls
*lp
,
6712 struct in_addr
*id
, struct in_addr
*adv_router
)
6714 memset(lp
, 0, sizeof(struct prefix_ls
));
6715 lp
->family
= AF_UNSPEC
;
6718 else if (adv_router
== NULL
) {
6719 lp
->prefixlen
= IPV4_MAX_BITLEN
;
6724 lp
->adv_router
= *adv_router
;
6728 static void show_lsa_detail_proc(struct vty
*vty
, struct route_table
*rt
,
6729 struct in_addr
*id
, struct in_addr
*adv_router
,
6732 struct prefix_ls lp
;
6733 struct route_node
*rn
, *start
;
6734 struct ospf_lsa
*lsa
;
6735 json_object
*json_lsa
= NULL
;
6737 show_lsa_prefix_set(vty
, &lp
, id
, adv_router
);
6738 start
= route_node_get(rt
, (struct prefix
*)&lp
);
6740 route_lock_node(start
);
6741 for (rn
= start
; rn
; rn
= route_next_until(rn
, start
))
6742 if ((lsa
= rn
->info
)) {
6743 if (show_function
[lsa
->data
->type
] != NULL
) {
6746 json_object_new_object();
6747 json_object_array_add(json
,
6751 show_function
[lsa
->data
->type
](
6752 vty
, lsa
, json_lsa
);
6755 route_unlock_node(start
);
6759 /* Show detail LSA information
6760 -- if id is NULL then show all LSAs. */
6761 static void show_lsa_detail(struct vty
*vty
, struct ospf
*ospf
, int type
,
6762 struct in_addr
*id
, struct in_addr
*adv_router
,
6765 struct listnode
*node
;
6766 struct ospf_area
*area
;
6767 char buf
[PREFIX_STRLEN
];
6768 json_object
*json_lsa_type
= NULL
;
6769 json_object
*json_areas
= NULL
;
6770 json_object
*json_lsa_array
= NULL
;
6773 case OSPF_AS_EXTERNAL_LSA
:
6774 case OSPF_OPAQUE_AS_LSA
:
6776 vty_out(vty
, " %s \n\n",
6777 show_database_desc
[type
]);
6779 json_lsa_array
= json_object_new_array();
6781 show_lsa_detail_proc(vty
, AS_LSDB(ospf
, type
), id
, adv_router
,
6784 json_object_object_add(json
,
6785 show_database_desc_json
[type
],
6791 json_areas
= json_object_new_object();
6793 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6796 "\n %s (Area %s)\n\n",
6797 show_database_desc
[type
],
6798 ospf_area_desc_string(area
));
6800 json_lsa_array
= json_object_new_array();
6801 json_object_object_add(json_areas
,
6809 show_lsa_detail_proc(vty
, AREA_LSDB(area
, type
), id
,
6810 adv_router
, json_lsa_array
);
6814 json_lsa_type
= json_object_new_object();
6815 json_object_object_add(json_lsa_type
, "areas",
6817 json_object_object_add(json
,
6818 show_database_desc_json
[type
],
6825 static void show_lsa_detail_adv_router_proc(struct vty
*vty
,
6826 struct route_table
*rt
,
6827 struct in_addr
*adv_router
,
6830 struct route_node
*rn
;
6831 struct ospf_lsa
*lsa
;
6832 json_object
*json_lsa
= NULL
;
6834 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
))
6835 if ((lsa
= rn
->info
)) {
6836 if (IPV4_ADDR_SAME(adv_router
,
6837 &lsa
->data
->adv_router
)) {
6838 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
6841 json_lsa
= json_object_new_object();
6842 json_object_array_add(json
, json_lsa
);
6845 if (show_function
[lsa
->data
->type
] != NULL
)
6846 show_function
[lsa
->data
->type
](
6847 vty
, lsa
, json_lsa
);
6852 /* Show detail LSA information. */
6853 static void show_lsa_detail_adv_router(struct vty
*vty
, struct ospf
*ospf
,
6854 int type
, struct in_addr
*adv_router
,
6857 struct listnode
*node
;
6858 struct ospf_area
*area
;
6859 char buf
[PREFIX_STRLEN
];
6860 json_object
*json_lsa_type
= NULL
;
6861 json_object
*json_areas
= NULL
;
6862 json_object
*json_lsa_array
= NULL
;
6865 json_lsa_type
= json_object_new_object();
6868 case OSPF_AS_EXTERNAL_LSA
:
6869 case OSPF_OPAQUE_AS_LSA
:
6871 vty_out(vty
, " %s \n\n",
6872 show_database_desc
[type
]);
6874 json_lsa_array
= json_object_new_array();
6876 show_lsa_detail_adv_router_proc(vty
, AS_LSDB(ospf
, type
),
6877 adv_router
, json_lsa_array
);
6879 json_object_object_add(json
,
6880 show_database_desc_json
[type
],
6885 json_areas
= json_object_new_object();
6887 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6890 "\n %s (Area %s)\n\n",
6891 show_database_desc
[type
],
6892 ospf_area_desc_string(area
));
6894 json_lsa_array
= json_object_new_array();
6895 json_object_object_add(
6897 inet_ntop(AF_INET
, &area
->area_id
, buf
,
6902 show_lsa_detail_adv_router_proc(
6903 vty
, AREA_LSDB(area
, type
), adv_router
,
6908 json_object_object_add(json_lsa_type
, "areas",
6910 json_object_object_add(json
,
6911 show_database_desc_json
[type
],
6918 void show_ip_ospf_database_summary(struct vty
*vty
, struct ospf
*ospf
, int self
,
6921 struct ospf_lsa
*lsa
;
6922 struct route_node
*rn
;
6923 struct ospf_area
*area
;
6924 struct listnode
*node
;
6925 char buf
[PREFIX_STRLEN
];
6926 json_object
*json_areas
= NULL
;
6927 json_object
*json_area
= NULL
;
6928 json_object
*json_lsa
= NULL
;
6930 json_object
*json_lsa_array
= NULL
;
6934 json_areas
= json_object_new_object();
6936 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6938 json_area
= json_object_new_object();
6940 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6943 case OSPF_AS_EXTERNAL_LSA
:
6944 case OSPF_OPAQUE_AS_LSA
:
6949 if (ospf_lsdb_count_self(area
->lsdb
, type
) > 0
6951 && ospf_lsdb_count(area
->lsdb
, type
) > 0)) {
6955 " %s (Area %s)\n\n",
6956 show_database_desc
[type
],
6957 ospf_area_desc_string(area
));
6958 vty_out(vty
, "%s\n",
6959 show_database_header
[type
]);
6962 json_object_new_array();
6963 json_object_object_add(
6965 show_database_desc_json
[type
],
6969 LSDB_LOOP (AREA_LSDB(area
, type
), rn
, lsa
) {
6972 json_object_new_object();
6973 json_object_array_add(
6978 count
+= show_lsa_summary(
6979 vty
, lsa
, self
, json_lsa
);
6985 json_object_int_add(
6988 show_database_desc_count_json
6994 json_object_object_add(json_areas
,
7002 json_object_object_add(json
, "areas", json_areas
);
7004 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
7007 case OSPF_AS_EXTERNAL_LSA
:
7008 case OSPF_OPAQUE_AS_LSA
:
7013 if (ospf_lsdb_count_self(ospf
->lsdb
, type
)
7014 || (!self
&& ospf_lsdb_count(ospf
->lsdb
, type
))) {
7016 vty_out(vty
, " %s\n\n",
7017 show_database_desc
[type
]);
7018 vty_out(vty
, "%s\n",
7019 show_database_header
[type
]);
7021 json_lsa_array
= json_object_new_array();
7022 json_object_object_add(
7023 json
, show_database_desc_json
[type
],
7027 LSDB_LOOP (AS_LSDB(ospf
, type
), rn
, lsa
) {
7029 json_lsa
= json_object_new_object();
7030 json_object_array_add(json_lsa_array
,
7034 count
+= show_lsa_summary(vty
, lsa
, self
,
7041 json_object_int_add(
7043 show_database_desc_count_json
[type
],
7052 static void show_ip_ospf_database_maxage(struct vty
*vty
, struct ospf
*ospf
,
7055 struct route_node
*rn
;
7056 char buf
[PREFIX_STRLEN
];
7057 json_object
*json_maxage
= NULL
;
7060 vty_out(vty
, "\n MaxAge Link States:\n\n");
7062 json_maxage
= json_object_new_object();
7064 for (rn
= route_top(ospf
->maxage_lsa
); rn
; rn
= route_next(rn
)) {
7065 struct ospf_lsa
*lsa
;
7066 json_object
*json_lsa
= NULL
;
7068 if ((lsa
= rn
->info
) != NULL
) {
7070 vty_out(vty
, "Link type: %d\n",
7072 vty_out(vty
, "Link State ID: %pI4\n",
7074 vty_out(vty
, "Advertising Router: %pI4\n",
7075 &lsa
->data
->adv_router
);
7076 vty_out(vty
, "LSA lock count: %d\n", lsa
->lock
);
7079 json_lsa
= json_object_new_object();
7080 json_object_int_add(json_lsa
, "linkType",
7082 json_object_string_addf(json_lsa
, "linkStateId",
7083 "%pI4", &lsa
->data
->id
);
7084 json_object_string_addf(
7085 json_lsa
, "advertisingRouter", "%pI4",
7086 &lsa
->data
->adv_router
);
7087 json_object_int_add(json_lsa
, "lsaLockCount",
7089 json_object_object_add(
7099 json_object_object_add(json
, "maxAgeLinkStates", json_maxage
);
7102 #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
7103 #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
7105 #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
7106 #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
7107 #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
7108 #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
7110 #define OSPF_LSA_TYPES_DESC \
7111 "ASBR summary link states\n" \
7112 "External link states\n" \
7113 "Network link states\n" \
7114 "Router link states\n" \
7115 "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \
7116 OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
7117 OSPF_LSA_TYPE_OPAQUE_AS_DESC
7120 show_ip_ospf_database_common(struct vty
*vty
, struct ospf
*ospf
, bool maxage
,
7121 bool self
, bool detail
, const char *type_name
,
7122 struct in_addr
*lsid
, struct in_addr
*adv_router
,
7123 bool use_vrf
, json_object
*json
, bool uj
)
7126 json_object
*json_vrf
= NULL
;
7130 json_vrf
= json_object_new_object();
7135 if (ospf
->instance
) {
7137 json_object_int_add(json_vrf
, "ospfInstance",
7140 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
7143 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
7145 /* Show Router ID. */
7147 json_object_string_addf(json_vrf
, "routerId", "%pI4",
7150 vty_out(vty
, "\n OSPF Router with ID (%pI4)\n\n",
7154 /* Show MaxAge LSAs */
7156 show_ip_ospf_database_maxage(vty
, ospf
, json_vrf
);
7159 if (ospf
->vrf_id
== VRF_DEFAULT
)
7160 json_object_object_add(json
, "default",
7163 json_object_object_add(json
, ospf
->name
,
7170 /* Show all LSAs. */
7173 for (int i
= OSPF_ROUTER_LSA
; i
<= OSPF_OPAQUE_AS_LSA
;
7176 case OSPF_GROUP_MEMBER_LSA
:
7177 case OSPF_EXTERNAL_ATTRIBUTES_LSA
:
7178 /* ignore deprecated LSA types */
7184 if (adv_router
&& !lsid
)
7185 show_lsa_detail_adv_router(vty
, ospf
, i
,
7189 show_lsa_detail(vty
, ospf
, i
, lsid
,
7190 adv_router
, json_vrf
);
7193 show_ip_ospf_database_summary(vty
, ospf
, self
,
7198 if (ospf
->vrf_id
== VRF_DEFAULT
)
7199 json_object_object_add(json
, "default",
7202 json_object_object_add(json
, ospf
->name
,
7209 /* Set database type to show. */
7210 if (strncmp(type_name
, "r", 1) == 0)
7211 type
= OSPF_ROUTER_LSA
;
7212 else if (strncmp(type_name
, "ne", 2) == 0)
7213 type
= OSPF_NETWORK_LSA
;
7214 else if (strncmp(type_name
, "ns", 2) == 0)
7215 type
= OSPF_AS_NSSA_LSA
;
7216 else if (strncmp(type_name
, "su", 2) == 0)
7217 type
= OSPF_SUMMARY_LSA
;
7218 else if (strncmp(type_name
, "a", 1) == 0)
7219 type
= OSPF_ASBR_SUMMARY_LSA
;
7220 else if (strncmp(type_name
, "e", 1) == 0)
7221 type
= OSPF_AS_EXTERNAL_LSA
;
7222 else if (strncmp(type_name
, "opaque-l", 8) == 0)
7223 type
= OSPF_OPAQUE_LINK_LSA
;
7224 else if (strncmp(type_name
, "opaque-ar", 9) == 0)
7225 type
= OSPF_OPAQUE_AREA_LSA
;
7226 else if (strncmp(type_name
, "opaque-as", 9) == 0)
7227 type
= OSPF_OPAQUE_AS_LSA
;
7231 json_object_free(json_vrf
);
7236 if (adv_router
&& !lsid
)
7237 show_lsa_detail_adv_router(vty
, ospf
, type
, adv_router
,
7240 show_lsa_detail(vty
, ospf
, type
, lsid
, adv_router
, json_vrf
);
7244 if (ospf
->vrf_id
== VRF_DEFAULT
)
7245 json_object_object_add(json
, "default",
7248 json_object_object_add(json
, ospf
->name
,
7256 DEFPY (show_ip_ospf_database
,
7257 show_ip_ospf_database_cmd
,
7258 "show ip ospf [(1-65535)$instance_id] [vrf <NAME|all>$vrf_name] database\
7261 |self-originate$selforig\
7264 |<asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as>$type_name\
7268 |<adv-router A.B.C.D$adv_router|self-originate$adv_router_self>\
7274 "OSPF information\n"
7278 "Database summary\n"
7279 "LSAs in MaxAge list\n"
7280 "Self-originated link states\n"
7281 "Show detailed information\n"
7283 "Link State ID (as an IP address)\n"
7284 "Advertising Router link states\n"
7285 "Advertising Router (as an IP address)\n"
7286 "Self-originated link states\n"
7290 int ret
= CMD_SUCCESS
;
7291 bool use_vrf
= !!vrf_name
;
7292 bool uj
= use_json(argc
, argv
);
7293 struct in_addr
*lsid_p
= NULL
;
7294 struct in_addr
*adv_router_p
= NULL
;
7295 json_object
*json
= NULL
;
7298 json
= json_object_new_object();
7302 adv_router_p
= &adv_router
;
7304 if (vrf_name
&& strmatch(vrf_name
, "all")) {
7305 struct listnode
*node
;
7306 bool ospf_output
= false;
7308 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
7309 if (!ospf
->oi_running
)
7311 if (ospf
->instance
!= instance_id
)
7314 if (adv_router_self
)
7315 adv_router_p
= &ospf
->router_id
;
7318 ret
= show_ip_ospf_database_common(
7319 vty
, ospf
, !!maxage
, !!selforig
, !!detail
,
7320 type_name
, lsid_p
, adv_router_p
, use_vrf
, json
,
7324 if (!ospf_output
&& !uj
)
7325 vty_out(vty
, "%% OSPF is not enabled\n");
7328 vrf_name
= VRF_DEFAULT_NAME
;
7329 ospf
= ospf_lookup_by_inst_name(instance_id
, vrf_name
);
7330 if (ospf
== NULL
|| !ospf
->oi_running
) {
7332 vty_json(vty
, json
);
7334 vty_out(vty
, "%% OSPF instance not found\n");
7337 if (adv_router_self
)
7338 adv_router_p
= &ospf
->router_id
;
7340 ret
= (show_ip_ospf_database_common(
7341 vty
, ospf
, !!maxage
, !!selforig
, !!detail
, type_name
,
7342 lsid_p
, adv_router_p
, use_vrf
, json
, uj
));
7346 vty_json(vty
, json
);
7351 DEFUN (ip_ospf_authentication_args
,
7352 ip_ospf_authentication_args_addr_cmd
,
7353 "ip ospf authentication <null|message-digest> [A.B.C.D]",
7355 "OSPF interface commands\n"
7356 "Enable authentication on this interface\n"
7357 "Use null authentication\n"
7358 "Use message-digest authentication\n"
7359 "Address of interface\n")
7361 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7362 int idx_encryption
= 3;
7364 struct in_addr addr
;
7366 struct ospf_if_params
*params
;
7368 params
= IF_DEF_PARAMS(ifp
);
7371 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7374 "Please specify interface address by A.B.C.D\n");
7375 return CMD_WARNING_CONFIG_FAILED
;
7378 params
= ospf_get_if_params(ifp
, addr
);
7379 ospf_if_update_params(ifp
, addr
);
7382 /* Handle null authentication */
7383 if (argv
[idx_encryption
]->arg
[0] == 'n') {
7384 SET_IF_PARAM(params
, auth_type
);
7385 params
->auth_type
= OSPF_AUTH_NULL
;
7389 /* Handle message-digest authentication */
7390 if (argv
[idx_encryption
]->arg
[0] == 'm') {
7391 SET_IF_PARAM(params
, auth_type
);
7392 params
->auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
7396 vty_out(vty
, "You shouldn't get here!\n");
7397 return CMD_WARNING_CONFIG_FAILED
;
7400 DEFUN (ip_ospf_authentication
,
7401 ip_ospf_authentication_addr_cmd
,
7402 "ip ospf authentication [A.B.C.D]",
7404 "OSPF interface commands\n"
7405 "Enable authentication on this interface\n"
7406 "Address of interface\n")
7408 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7410 struct in_addr addr
;
7412 struct ospf_if_params
*params
;
7414 params
= IF_DEF_PARAMS(ifp
);
7417 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7420 "Please specify interface address by A.B.C.D\n");
7421 return CMD_WARNING_CONFIG_FAILED
;
7424 params
= ospf_get_if_params(ifp
, addr
);
7425 ospf_if_update_params(ifp
, addr
);
7428 SET_IF_PARAM(params
, auth_type
);
7429 params
->auth_type
= OSPF_AUTH_SIMPLE
;
7434 DEFUN (no_ip_ospf_authentication_args
,
7435 no_ip_ospf_authentication_args_addr_cmd
,
7436 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
7439 "OSPF interface commands\n"
7440 "Enable authentication on this interface\n"
7441 "Use null authentication\n"
7442 "Use message-digest authentication\n"
7443 "Address of interface\n")
7445 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7446 int idx_encryption
= 4;
7448 struct in_addr addr
;
7450 struct ospf_if_params
*params
;
7451 struct route_node
*rn
;
7454 params
= IF_DEF_PARAMS(ifp
);
7457 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7460 "Please specify interface address by A.B.C.D\n");
7461 return CMD_WARNING_CONFIG_FAILED
;
7464 params
= ospf_lookup_if_params(ifp
, addr
);
7465 if (params
== NULL
) {
7466 vty_out(vty
, "Ip Address specified is unknown\n");
7467 return CMD_WARNING_CONFIG_FAILED
;
7469 params
->auth_type
= OSPF_AUTH_NOTSET
;
7470 UNSET_IF_PARAM(params
, auth_type
);
7471 if (params
!= IF_DEF_PARAMS(ifp
)) {
7472 ospf_free_if_params(ifp
, addr
);
7473 ospf_if_update_params(ifp
, addr
);
7476 if (argv
[idx_encryption
]->arg
[0] == 'n') {
7477 auth_type
= OSPF_AUTH_NULL
;
7478 } else if (argv
[idx_encryption
]->arg
[0] == 'm') {
7479 auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
7481 vty_out(vty
, "Unexpected input encountered\n");
7482 return CMD_WARNING_CONFIG_FAILED
;
7485 * Here we have a case where the user has entered
7486 * 'no ip ospf authentication (null | message_digest )'
7487 * we need to find if we have any ip addresses underneath it
7489 * correspond to the associated type.
7491 if (params
->auth_type
== auth_type
) {
7492 params
->auth_type
= OSPF_AUTH_NOTSET
;
7493 UNSET_IF_PARAM(params
, auth_type
);
7496 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
7497 rn
= route_next(rn
)) {
7498 if ((params
= rn
->info
)) {
7499 if (params
->auth_type
== auth_type
) {
7500 params
->auth_type
= OSPF_AUTH_NOTSET
;
7501 UNSET_IF_PARAM(params
, auth_type
);
7502 if (params
!= IF_DEF_PARAMS(ifp
)) {
7503 ospf_free_if_params(
7504 ifp
, rn
->p
.u
.prefix4
);
7505 ospf_if_update_params(
7506 ifp
, rn
->p
.u
.prefix4
);
7516 DEFUN (no_ip_ospf_authentication
,
7517 no_ip_ospf_authentication_addr_cmd
,
7518 "no ip ospf authentication [A.B.C.D]",
7521 "OSPF interface commands\n"
7522 "Enable authentication on this interface\n"
7523 "Address of interface\n")
7525 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7527 struct in_addr addr
;
7529 struct ospf_if_params
*params
;
7530 struct route_node
*rn
;
7532 params
= IF_DEF_PARAMS(ifp
);
7535 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7538 "Please specify interface address by A.B.C.D\n");
7539 return CMD_WARNING_CONFIG_FAILED
;
7542 params
= ospf_lookup_if_params(ifp
, addr
);
7543 if (params
== NULL
) {
7544 vty_out(vty
, "Ip Address specified is unknown\n");
7545 return CMD_WARNING_CONFIG_FAILED
;
7548 params
->auth_type
= OSPF_AUTH_NOTSET
;
7549 UNSET_IF_PARAM(params
, auth_type
);
7550 if (params
!= IF_DEF_PARAMS(ifp
)) {
7551 ospf_free_if_params(ifp
, addr
);
7552 ospf_if_update_params(ifp
, addr
);
7556 * When a user enters 'no ip ospf authentication'
7557 * We should remove all authentication types from
7560 if ((params
->auth_type
== OSPF_AUTH_NULL
)
7561 || (params
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
7562 || (params
->auth_type
== OSPF_AUTH_SIMPLE
)) {
7563 params
->auth_type
= OSPF_AUTH_NOTSET
;
7564 UNSET_IF_PARAM(params
, auth_type
);
7567 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
7568 rn
= route_next(rn
)) {
7569 if ((params
= rn
->info
)) {
7571 if ((params
->auth_type
== OSPF_AUTH_NULL
)
7572 || (params
->auth_type
7573 == OSPF_AUTH_CRYPTOGRAPHIC
)
7574 || (params
->auth_type
7575 == OSPF_AUTH_SIMPLE
)) {
7576 params
->auth_type
= OSPF_AUTH_NOTSET
;
7577 UNSET_IF_PARAM(params
, auth_type
);
7578 if (params
!= IF_DEF_PARAMS(ifp
)) {
7579 ospf_free_if_params(
7580 ifp
, rn
->p
.u
.prefix4
);
7581 ospf_if_update_params(
7582 ifp
, rn
->p
.u
.prefix4
);
7593 DEFUN (ip_ospf_authentication_key
,
7594 ip_ospf_authentication_key_addr_cmd
,
7595 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
7597 "OSPF interface commands\n"
7598 "Authentication password (key)\n"
7599 "The OSPF password (key)\n"
7600 "Address of interface\n")
7602 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7604 struct in_addr addr
;
7605 struct ospf_if_params
*params
;
7607 params
= IF_DEF_PARAMS(ifp
);
7609 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7610 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7612 "Please specify interface address by A.B.C.D\n");
7613 return CMD_WARNING_CONFIG_FAILED
;
7616 params
= ospf_get_if_params(ifp
, addr
);
7617 ospf_if_update_params(ifp
, addr
);
7620 strlcpy((char *)params
->auth_simple
, argv
[3]->arg
,
7621 sizeof(params
->auth_simple
));
7622 SET_IF_PARAM(params
, auth_simple
);
7627 DEFUN_HIDDEN (ospf_authentication_key
,
7628 ospf_authentication_key_cmd
,
7629 "ospf authentication-key AUTH_KEY [A.B.C.D]",
7630 "OSPF interface commands\n"
7631 VLINK_HELPSTR_AUTH_SIMPLE
7632 "Address of interface\n")
7634 return ip_ospf_authentication_key(self
, vty
, argc
, argv
);
7637 DEFUN (no_ip_ospf_authentication_key
,
7638 no_ip_ospf_authentication_key_authkey_addr_cmd
,
7639 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7642 "OSPF interface commands\n"
7643 VLINK_HELPSTR_AUTH_SIMPLE
7644 "Address of interface\n")
7646 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7648 struct in_addr addr
;
7649 struct ospf_if_params
*params
;
7650 params
= IF_DEF_PARAMS(ifp
);
7652 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7653 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7655 "Please specify interface address by A.B.C.D\n");
7656 return CMD_WARNING_CONFIG_FAILED
;
7659 params
= ospf_lookup_if_params(ifp
, addr
);
7664 memset(params
->auth_simple
, 0, OSPF_AUTH_SIMPLE_SIZE
);
7665 UNSET_IF_PARAM(params
, auth_simple
);
7667 if (params
!= IF_DEF_PARAMS(ifp
)) {
7668 ospf_free_if_params(ifp
, addr
);
7669 ospf_if_update_params(ifp
, addr
);
7675 DEFUN_HIDDEN (no_ospf_authentication_key
,
7676 no_ospf_authentication_key_authkey_addr_cmd
,
7677 "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7679 "OSPF interface commands\n"
7680 VLINK_HELPSTR_AUTH_SIMPLE
7681 "Address of interface\n")
7683 return no_ip_ospf_authentication_key(self
, vty
, argc
, argv
);
7686 DEFUN (ip_ospf_message_digest_key
,
7687 ip_ospf_message_digest_key_cmd
,
7688 "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7690 "OSPF interface commands\n"
7691 "Message digest authentication password (key)\n"
7693 "Use MD5 algorithm\n"
7694 "The OSPF password (key)\n"
7695 "Address of interface\n")
7697 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7698 struct crypt_key
*ck
;
7700 struct in_addr addr
;
7701 struct ospf_if_params
*params
;
7703 params
= IF_DEF_PARAMS(ifp
);
7706 argv_find(argv
, argc
, "(1-255)", &idx
);
7707 char *keyid
= argv
[idx
]->arg
;
7708 argv_find(argv
, argc
, "KEY", &idx
);
7709 char *cryptkey
= argv
[idx
]->arg
;
7711 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7712 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7714 "Please specify interface address by A.B.C.D\n");
7715 return CMD_WARNING_CONFIG_FAILED
;
7718 params
= ospf_get_if_params(ifp
, addr
);
7719 ospf_if_update_params(ifp
, addr
);
7722 key_id
= strtol(keyid
, NULL
, 10);
7724 /* Remove existing key, if any */
7725 ospf_crypt_key_delete(params
->auth_crypt
, key_id
);
7727 ck
= ospf_crypt_key_new();
7728 ck
->key_id
= (uint8_t)key_id
;
7729 strlcpy((char *)ck
->auth_key
, cryptkey
, sizeof(ck
->auth_key
));
7731 ospf_crypt_key_add(params
->auth_crypt
, ck
);
7732 SET_IF_PARAM(params
, auth_crypt
);
7737 DEFUN_HIDDEN (ospf_message_digest_key
,
7738 ospf_message_digest_key_cmd
,
7739 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7740 "OSPF interface commands\n"
7741 "Message digest authentication password (key)\n"
7743 "Use MD5 algorithm\n"
7744 "The OSPF password (key)\n"
7745 "Address of interface\n")
7747 return ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7750 DEFUN (no_ip_ospf_message_digest_key
,
7751 no_ip_ospf_message_digest_key_cmd
,
7752 "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7755 "OSPF interface commands\n"
7756 "Message digest authentication password (key)\n"
7758 "Use MD5 algorithm\n"
7759 "The OSPF password (key)\n"
7760 "Address of interface\n")
7762 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7764 struct crypt_key
*ck
;
7766 struct in_addr addr
;
7767 struct ospf_if_params
*params
;
7768 params
= IF_DEF_PARAMS(ifp
);
7770 argv_find(argv
, argc
, "(1-255)", &idx
);
7771 char *keyid
= argv
[idx
]->arg
;
7773 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7774 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7776 "Please specify interface address by A.B.C.D\n");
7777 return CMD_WARNING_CONFIG_FAILED
;
7780 params
= ospf_lookup_if_params(ifp
, addr
);
7785 key_id
= strtol(keyid
, NULL
, 10);
7786 ck
= ospf_crypt_key_lookup(params
->auth_crypt
, key_id
);
7788 vty_out(vty
, "OSPF: Key %d does not exist\n", key_id
);
7789 return CMD_WARNING_CONFIG_FAILED
;
7792 ospf_crypt_key_delete(params
->auth_crypt
, key_id
);
7794 if (params
!= IF_DEF_PARAMS(ifp
)) {
7795 ospf_free_if_params(ifp
, addr
);
7796 ospf_if_update_params(ifp
, addr
);
7802 DEFUN_HIDDEN (no_ospf_message_digest_key
,
7803 no_ospf_message_digest_key_cmd
,
7804 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7806 "OSPF interface commands\n"
7807 "Message digest authentication password (key)\n"
7809 "Use MD5 algorithm\n"
7810 "The OSPF password (key)\n"
7811 "Address of interface\n")
7813 return no_ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7816 DEFUN (ip_ospf_cost
,
7818 "ip ospf cost (1-65535) [A.B.C.D]",
7820 "OSPF interface commands\n"
7823 "Address of interface\n")
7825 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7827 uint32_t cost
= OSPF_OUTPUT_COST_DEFAULT
;
7828 struct in_addr addr
;
7829 struct ospf_if_params
*params
;
7830 params
= IF_DEF_PARAMS(ifp
);
7833 char *coststr
= NULL
, *ifaddr
= NULL
;
7835 argv_find(argv
, argc
, "(1-65535)", &idx
);
7836 coststr
= argv
[idx
]->arg
;
7837 cost
= strtol(coststr
, NULL
, 10);
7839 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7841 if (!inet_aton(ifaddr
, &addr
)) {
7843 "Please specify interface address by A.B.C.D\n");
7844 return CMD_WARNING_CONFIG_FAILED
;
7847 params
= ospf_get_if_params(ifp
, addr
);
7848 ospf_if_update_params(ifp
, addr
);
7851 SET_IF_PARAM(params
, output_cost_cmd
);
7852 params
->output_cost_cmd
= cost
;
7854 ospf_if_recalculate_output_cost(ifp
);
7859 DEFUN_HIDDEN (ospf_cost
,
7861 "ospf cost (1-65535) [A.B.C.D]",
7862 "OSPF interface commands\n"
7865 "Address of interface\n")
7867 return ip_ospf_cost(self
, vty
, argc
, argv
);
7870 DEFUN (no_ip_ospf_cost
,
7871 no_ip_ospf_cost_cmd
,
7872 "no ip ospf cost [(1-65535)] [A.B.C.D]",
7875 "OSPF interface commands\n"
7878 "Address of interface\n")
7880 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7882 struct in_addr addr
;
7883 struct ospf_if_params
*params
;
7885 params
= IF_DEF_PARAMS(ifp
);
7888 char *ifaddr
= NULL
;
7889 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7891 /* According to the semantics we are mimicking "no ip ospf cost N" is
7892 * always treated as "no ip ospf cost" regardless of the actual value
7893 * of N already configured for the interface. Thus ignore cost. */
7896 if (!inet_aton(ifaddr
, &addr
)) {
7898 "Please specify interface address by A.B.C.D\n");
7899 return CMD_WARNING_CONFIG_FAILED
;
7902 params
= ospf_lookup_if_params(ifp
, addr
);
7907 UNSET_IF_PARAM(params
, output_cost_cmd
);
7909 if (params
!= IF_DEF_PARAMS(ifp
)) {
7910 ospf_free_if_params(ifp
, addr
);
7911 ospf_if_update_params(ifp
, addr
);
7914 ospf_if_recalculate_output_cost(ifp
);
7919 DEFUN_HIDDEN (no_ospf_cost
,
7921 "no ospf cost [(1-65535)] [A.B.C.D]",
7923 "OSPF interface commands\n"
7926 "Address of interface\n")
7928 return no_ip_ospf_cost(self
, vty
, argc
, argv
);
7931 static void ospf_nbr_timer_update(struct ospf_interface
*oi
)
7933 struct route_node
*rn
;
7934 struct ospf_neighbor
*nbr
;
7936 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
7942 nbr
->v_inactivity
= OSPF_IF_PARAM(oi
, v_wait
);
7943 nbr
->v_db_desc
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7944 nbr
->v_ls_req
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7945 nbr
->v_ls_upd
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7949 static int ospf_vty_dead_interval_set(struct vty
*vty
, const char *interval_str
,
7950 const char *nbr_str
,
7951 const char *fast_hello_str
)
7953 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7956 struct in_addr addr
;
7958 struct ospf_if_params
*params
;
7959 struct ospf_interface
*oi
;
7960 struct route_node
*rn
;
7962 params
= IF_DEF_PARAMS(ifp
);
7965 ret
= inet_aton(nbr_str
, &addr
);
7968 "Please specify interface address by A.B.C.D\n");
7969 return CMD_WARNING_CONFIG_FAILED
;
7972 params
= ospf_get_if_params(ifp
, addr
);
7973 ospf_if_update_params(ifp
, addr
);
7977 seconds
= strtoul(interval_str
, NULL
, 10);
7979 /* reset fast_hello too, just to be sure */
7980 UNSET_IF_PARAM(params
, fast_hello
);
7981 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
7982 } else if (fast_hello_str
) {
7983 hellomult
= strtoul(fast_hello_str
, NULL
, 10);
7984 /* 1s dead-interval with sub-second hellos desired */
7985 seconds
= OSPF_ROUTER_DEAD_INTERVAL_MINIMAL
;
7986 SET_IF_PARAM(params
, fast_hello
);
7987 params
->fast_hello
= hellomult
;
7990 "Please specify dead-interval or hello-multiplier\n");
7991 return CMD_WARNING_CONFIG_FAILED
;
7994 SET_IF_PARAM(params
, v_wait
);
7995 params
->v_wait
= seconds
;
7996 params
->is_v_wait_set
= true;
7998 /* Update timer values in neighbor structure. */
8000 struct ospf
*ospf
= NULL
;
8002 ospf
= ifp
->vrf
->info
;
8004 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
8006 ospf_nbr_timer_update(oi
);
8009 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
8010 if ((oi
= rn
->info
))
8011 ospf_nbr_timer_update(oi
);
8017 DEFUN (ip_ospf_dead_interval
,
8018 ip_ospf_dead_interval_cmd
,
8019 "ip ospf dead-interval (1-65535) [A.B.C.D]",
8021 "OSPF interface commands\n"
8022 "Interval time after which a neighbor is declared down\n"
8024 "Address of interface\n")
8027 char *interval
= argv_find(argv
, argc
, "(1-65535)", &idx
)
8031 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
8032 return ospf_vty_dead_interval_set(vty
, interval
, ifaddr
, NULL
);
8036 DEFUN_HIDDEN (ospf_dead_interval
,
8037 ospf_dead_interval_cmd
,
8038 "ospf dead-interval (1-65535) [A.B.C.D]",
8039 "OSPF interface commands\n"
8040 "Interval time after which a neighbor is declared down\n"
8042 "Address of interface\n")
8044 return ip_ospf_dead_interval(self
, vty
, argc
, argv
);
8047 DEFUN (ip_ospf_dead_interval_minimal
,
8048 ip_ospf_dead_interval_minimal_addr_cmd
,
8049 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
8051 "OSPF interface commands\n"
8052 "Interval time after which a neighbor is declared down\n"
8053 "Minimal 1s dead-interval with fast sub-second hellos\n"
8054 "Hello multiplier factor\n"
8055 "Number of Hellos to send each second\n"
8056 "Address of interface\n")
8061 return ospf_vty_dead_interval_set(
8062 vty
, NULL
, argv
[idx_ipv4
]->arg
, argv
[idx_number
]->arg
);
8064 return ospf_vty_dead_interval_set(vty
, NULL
, NULL
,
8065 argv
[idx_number
]->arg
);
8068 DEFUN (no_ip_ospf_dead_interval
,
8069 no_ip_ospf_dead_interval_cmd
,
8070 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8073 "OSPF interface commands\n"
8074 "Interval time after which a neighbor is declared down\n"
8076 "Minimal 1s dead-interval with fast sub-second hellos\n"
8077 "Hello multiplier factor\n"
8078 "Number of Hellos to send each second\n"
8079 "Address of interface\n")
8081 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8082 int idx_ipv4
= argc
- 1;
8083 struct in_addr addr
= {.s_addr
= 0L};
8085 struct ospf_if_params
*params
;
8086 struct ospf_interface
*oi
;
8087 struct route_node
*rn
;
8089 params
= IF_DEF_PARAMS(ifp
);
8091 if (argv
[idx_ipv4
]->type
== IPV4_TKN
) {
8092 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8095 "Please specify interface address by A.B.C.D\n");
8096 return CMD_WARNING_CONFIG_FAILED
;
8099 params
= ospf_lookup_if_params(ifp
, addr
);
8104 UNSET_IF_PARAM(params
, v_wait
);
8105 params
->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
8106 params
->is_v_wait_set
= false;
8108 UNSET_IF_PARAM(params
, fast_hello
);
8109 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
8111 if (params
!= IF_DEF_PARAMS(ifp
)) {
8112 ospf_free_if_params(ifp
, addr
);
8113 ospf_if_update_params(ifp
, addr
);
8116 /* Update timer values in neighbor structure. */
8118 struct ospf
*ospf
= NULL
;
8120 ospf
= ifp
->vrf
->info
;
8122 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
8124 ospf_nbr_timer_update(oi
);
8127 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
8128 if ((oi
= rn
->info
))
8129 ospf_nbr_timer_update(oi
);
8135 DEFUN_HIDDEN (no_ospf_dead_interval
,
8136 no_ospf_dead_interval_cmd
,
8137 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8139 "OSPF interface commands\n"
8140 "Interval time after which a neighbor is declared down\n"
8142 "Minimal 1s dead-interval with fast sub-second hellos\n"
8143 "Hello multiplier factor\n"
8144 "Number of Hellos to send each second\n"
8145 "Address of interface\n")
8147 return no_ip_ospf_dead_interval(self
, vty
, argc
, argv
);
8150 DEFUN (ip_ospf_hello_interval
,
8151 ip_ospf_hello_interval_cmd
,
8152 "ip ospf hello-interval (1-65535) [A.B.C.D]",
8154 "OSPF interface commands\n"
8155 "Time between HELLO packets\n"
8157 "Address of interface\n")
8159 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8161 struct in_addr addr
= {.s_addr
= 0L};
8162 struct ospf_if_params
*params
;
8163 params
= IF_DEF_PARAMS(ifp
);
8164 uint32_t seconds
= 0;
8165 bool is_addr
= false;
8166 uint32_t old_interval
= 0;
8168 argv_find(argv
, argc
, "(1-65535)", &idx
);
8169 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
8171 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8172 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8174 "Please specify interface address by A.B.C.D\n");
8175 return CMD_WARNING_CONFIG_FAILED
;
8178 params
= ospf_get_if_params(ifp
, addr
);
8179 ospf_if_update_params(ifp
, addr
);
8183 old_interval
= params
->v_hello
;
8185 /* Return, if same interval is configured. */
8186 if (old_interval
== seconds
)
8189 SET_IF_PARAM(params
, v_hello
);
8190 params
->v_hello
= seconds
;
8192 if (!params
->is_v_wait_set
) {
8193 SET_IF_PARAM(params
, v_wait
);
8195 * The router dead interval should
8196 * be some multiple of the HelloInterval (perhaps 4 times the
8197 * hello interval) and must be the same for all routers
8198 * attached to a common network.
8200 params
->v_wait
= 4 * seconds
;
8203 ospf_reset_hello_timer(ifp
, addr
, is_addr
);
8208 DEFUN_HIDDEN (ospf_hello_interval
,
8209 ospf_hello_interval_cmd
,
8210 "ospf hello-interval (1-65535) [A.B.C.D]",
8211 "OSPF interface commands\n"
8212 "Time between HELLO packets\n"
8214 "Address of interface\n")
8216 return ip_ospf_hello_interval(self
, vty
, argc
, argv
);
8219 DEFUN (no_ip_ospf_hello_interval
,
8220 no_ip_ospf_hello_interval_cmd
,
8221 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
8224 "OSPF interface commands\n"
8225 "Time between HELLO packets\n" // ignored
8227 "Address of interface\n")
8229 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8231 struct in_addr addr
= {.s_addr
= 0L};
8232 struct ospf_if_params
*params
;
8233 struct route_node
*rn
;
8235 params
= IF_DEF_PARAMS(ifp
);
8237 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8238 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8240 "Please specify interface address by A.B.C.D\n");
8241 return CMD_WARNING_CONFIG_FAILED
;
8244 params
= ospf_lookup_if_params(ifp
, addr
);
8249 UNSET_IF_PARAM(params
, v_hello
);
8250 params
->v_hello
= OSPF_HELLO_INTERVAL_DEFAULT
;
8252 if (!params
->is_v_wait_set
) {
8253 UNSET_IF_PARAM(params
, v_wait
);
8254 params
->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
8257 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8258 struct ospf_interface
*oi
= rn
->info
;
8263 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
8264 oi
->ptp_dmvpn
= IF_DEF_PARAMS(ifp
)->ptp_dmvpn
;
8266 if (oi
->state
> ISM_Down
) {
8267 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
8268 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
8272 if (params
!= IF_DEF_PARAMS(ifp
)) {
8273 ospf_free_if_params(ifp
, addr
);
8274 ospf_if_update_params(ifp
, addr
);
8280 DEFUN_HIDDEN (no_ospf_hello_interval
,
8281 no_ospf_hello_interval_cmd
,
8282 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
8284 "OSPF interface commands\n"
8285 "Time between HELLO packets\n" // ignored
8287 "Address of interface\n")
8289 return no_ip_ospf_hello_interval(self
, vty
, argc
, argv
);
8292 DEFUN(ip_ospf_network
, ip_ospf_network_cmd
,
8293 "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point [dmvpn]>",
8295 "OSPF interface commands\n"
8297 "Specify OSPF broadcast multi-access network\n"
8298 "Specify OSPF NBMA network\n"
8299 "Specify OSPF point-to-multipoint network\n"
8300 "Specify OSPF point-to-point network\n"
8301 "Specify OSPF point-to-point DMVPN network\n")
8303 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8305 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
8306 uint8_t old_ptp_dmvpn
= IF_DEF_PARAMS(ifp
)->ptp_dmvpn
;
8307 struct route_node
*rn
;
8309 if (old_type
== OSPF_IFTYPE_LOOPBACK
) {
8311 "This is a loopback interface. Can't set network type.\n");
8312 return CMD_WARNING_CONFIG_FAILED
;
8315 IF_DEF_PARAMS(ifp
)->ptp_dmvpn
= 0;
8317 if (argv_find(argv
, argc
, "broadcast", &idx
))
8318 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_BROADCAST
;
8319 else if (argv_find(argv
, argc
, "non-broadcast", &idx
))
8320 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_NBMA
;
8321 else if (argv_find(argv
, argc
, "point-to-multipoint", &idx
))
8322 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOMULTIPOINT
;
8323 else if (argv_find(argv
, argc
, "point-to-point", &idx
)) {
8324 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOPOINT
;
8325 if (argv_find(argv
, argc
, "dmvpn", &idx
))
8326 IF_DEF_PARAMS(ifp
)->ptp_dmvpn
= 1;
8329 if (IF_DEF_PARAMS(ifp
)->type
== old_type
8330 && IF_DEF_PARAMS(ifp
)->ptp_dmvpn
== old_ptp_dmvpn
)
8333 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), type
);
8335 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8336 struct ospf_interface
*oi
= rn
->info
;
8341 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
8343 if (oi
->state
> ISM_Down
) {
8344 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
8345 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
8352 DEFUN_HIDDEN (ospf_network
,
8354 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
8355 "OSPF interface commands\n"
8357 "Specify OSPF broadcast multi-access network\n"
8358 "Specify OSPF NBMA network\n"
8359 "Specify OSPF point-to-multipoint network\n"
8360 "Specify OSPF point-to-point network\n")
8362 return ip_ospf_network(self
, vty
, argc
, argv
);
8365 DEFUN (no_ip_ospf_network
,
8366 no_ip_ospf_network_cmd
,
8367 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8370 "OSPF interface commands\n"
8372 "Specify OSPF broadcast multi-access network\n"
8373 "Specify OSPF NBMA network\n"
8374 "Specify OSPF point-to-multipoint network\n"
8375 "Specify OSPF point-to-point network\n")
8377 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8378 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
8379 struct route_node
*rn
;
8381 IF_DEF_PARAMS(ifp
)->type
= ospf_default_iftype(ifp
);
8382 IF_DEF_PARAMS(ifp
)->ptp_dmvpn
= 0;
8384 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
8387 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8388 struct ospf_interface
*oi
= rn
->info
;
8393 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
8395 if (oi
->state
> ISM_Down
) {
8396 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
8397 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
8404 DEFUN_HIDDEN (no_ospf_network
,
8405 no_ospf_network_cmd
,
8406 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8408 "OSPF interface commands\n"
8410 "Specify OSPF broadcast multi-access network\n"
8411 "Specify OSPF NBMA network\n"
8412 "Specify OSPF point-to-multipoint network\n"
8413 "Specify OSPF point-to-point network\n")
8415 return no_ip_ospf_network(self
, vty
, argc
, argv
);
8418 DEFUN (ip_ospf_priority
,
8419 ip_ospf_priority_cmd
,
8420 "ip ospf priority (0-255) [A.B.C.D]",
8422 "OSPF interface commands\n"
8425 "Address of interface\n")
8427 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8430 struct route_node
*rn
;
8431 struct in_addr addr
;
8432 struct ospf_if_params
*params
;
8433 params
= IF_DEF_PARAMS(ifp
);
8435 argv_find(argv
, argc
, "(0-255)", &idx
);
8436 priority
= strtol(argv
[idx
]->arg
, NULL
, 10);
8438 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8439 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8441 "Please specify interface address by A.B.C.D\n");
8442 return CMD_WARNING_CONFIG_FAILED
;
8445 params
= ospf_get_if_params(ifp
, addr
);
8446 ospf_if_update_params(ifp
, addr
);
8449 SET_IF_PARAM(params
, priority
);
8450 params
->priority
= priority
;
8452 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8453 struct ospf_interface
*oi
= rn
->info
;
8458 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
8459 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
8460 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
8467 DEFUN_HIDDEN (ospf_priority
,
8469 "ospf priority (0-255) [A.B.C.D]",
8470 "OSPF interface commands\n"
8473 "Address of interface\n")
8475 return ip_ospf_priority(self
, vty
, argc
, argv
);
8478 DEFUN (no_ip_ospf_priority
,
8479 no_ip_ospf_priority_cmd
,
8480 "no ip ospf priority [(0-255) [A.B.C.D]]",
8483 "OSPF interface commands\n"
8484 "Router priority\n" // ignored
8486 "Address of interface\n")
8488 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8490 struct route_node
*rn
;
8491 struct in_addr addr
;
8492 struct ospf_if_params
*params
;
8494 params
= IF_DEF_PARAMS(ifp
);
8496 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8497 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8499 "Please specify interface address by A.B.C.D\n");
8500 return CMD_WARNING_CONFIG_FAILED
;
8503 params
= ospf_lookup_if_params(ifp
, addr
);
8508 UNSET_IF_PARAM(params
, priority
);
8509 params
->priority
= OSPF_ROUTER_PRIORITY_DEFAULT
;
8511 if (params
!= IF_DEF_PARAMS(ifp
)) {
8512 ospf_free_if_params(ifp
, addr
);
8513 ospf_if_update_params(ifp
, addr
);
8516 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8517 struct ospf_interface
*oi
= rn
->info
;
8522 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
8523 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
8524 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
8531 DEFUN_HIDDEN (no_ospf_priority
,
8532 no_ospf_priority_cmd
,
8533 "no ospf priority [(0-255) [A.B.C.D]]",
8535 "OSPF interface commands\n"
8538 "Address of interface\n")
8540 return no_ip_ospf_priority(self
, vty
, argc
, argv
);
8543 DEFUN (ip_ospf_retransmit_interval
,
8544 ip_ospf_retransmit_interval_addr_cmd
,
8545 "ip ospf retransmit-interval (1-65535) [A.B.C.D]",
8547 "OSPF interface commands\n"
8548 "Time between retransmitting lost link state advertisements\n"
8550 "Address of interface\n")
8552 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8555 struct in_addr addr
;
8556 struct ospf_if_params
*params
;
8557 params
= IF_DEF_PARAMS(ifp
);
8559 argv_find(argv
, argc
, "(1-65535)", &idx
);
8560 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
8562 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8563 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8565 "Please specify interface address by A.B.C.D\n");
8566 return CMD_WARNING_CONFIG_FAILED
;
8569 params
= ospf_get_if_params(ifp
, addr
);
8570 ospf_if_update_params(ifp
, addr
);
8573 SET_IF_PARAM(params
, retransmit_interval
);
8574 params
->retransmit_interval
= seconds
;
8579 DEFUN_HIDDEN (ospf_retransmit_interval
,
8580 ospf_retransmit_interval_cmd
,
8581 "ospf retransmit-interval (1-65535) [A.B.C.D]",
8582 "OSPF interface commands\n"
8583 "Time between retransmitting lost link state advertisements\n"
8585 "Address of interface\n")
8587 return ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
8590 DEFUN (no_ip_ospf_retransmit_interval
,
8591 no_ip_ospf_retransmit_interval_addr_cmd
,
8592 "no ip ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8595 "OSPF interface commands\n"
8596 "Time between retransmitting lost link state advertisements\n"
8598 "Address of interface\n")
8600 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8602 struct in_addr addr
;
8603 struct ospf_if_params
*params
;
8605 params
= IF_DEF_PARAMS(ifp
);
8607 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8608 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8610 "Please specify interface address by A.B.C.D\n");
8611 return CMD_WARNING_CONFIG_FAILED
;
8614 params
= ospf_lookup_if_params(ifp
, addr
);
8619 UNSET_IF_PARAM(params
, retransmit_interval
);
8620 params
->retransmit_interval
= OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
8622 if (params
!= IF_DEF_PARAMS(ifp
)) {
8623 ospf_free_if_params(ifp
, addr
);
8624 ospf_if_update_params(ifp
, addr
);
8630 DEFUN_HIDDEN (no_ospf_retransmit_interval
,
8631 no_ospf_retransmit_interval_cmd
,
8632 "no ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8634 "OSPF interface commands\n"
8635 "Time between retransmitting lost link state advertisements\n"
8637 "Address of interface\n")
8639 return no_ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
8642 DEFUN (ip_ospf_transmit_delay
,
8643 ip_ospf_transmit_delay_addr_cmd
,
8644 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
8646 "OSPF interface commands\n"
8647 "Link state transmit delay\n"
8649 "Address of interface\n")
8651 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8654 struct in_addr addr
;
8655 struct ospf_if_params
*params
;
8657 params
= IF_DEF_PARAMS(ifp
);
8658 argv_find(argv
, argc
, "(1-65535)", &idx
);
8659 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
8661 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8662 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8664 "Please specify interface address by A.B.C.D\n");
8665 return CMD_WARNING_CONFIG_FAILED
;
8668 params
= ospf_get_if_params(ifp
, addr
);
8669 ospf_if_update_params(ifp
, addr
);
8672 SET_IF_PARAM(params
, transmit_delay
);
8673 params
->transmit_delay
= seconds
;
8678 DEFUN_HIDDEN (ospf_transmit_delay
,
8679 ospf_transmit_delay_cmd
,
8680 "ospf transmit-delay (1-65535) [A.B.C.D]",
8681 "OSPF interface commands\n"
8682 "Link state transmit delay\n"
8684 "Address of interface\n")
8686 return ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
8689 DEFUN (no_ip_ospf_transmit_delay
,
8690 no_ip_ospf_transmit_delay_addr_cmd
,
8691 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
8694 "OSPF interface commands\n"
8695 "Link state transmit delay\n"
8697 "Address of interface\n")
8699 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8701 struct in_addr addr
;
8702 struct ospf_if_params
*params
;
8704 params
= IF_DEF_PARAMS(ifp
);
8706 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8707 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8709 "Please specify interface address by A.B.C.D\n");
8710 return CMD_WARNING_CONFIG_FAILED
;
8713 params
= ospf_lookup_if_params(ifp
, addr
);
8718 UNSET_IF_PARAM(params
, transmit_delay
);
8719 params
->transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
8721 if (params
!= IF_DEF_PARAMS(ifp
)) {
8722 ospf_free_if_params(ifp
, addr
);
8723 ospf_if_update_params(ifp
, addr
);
8730 DEFUN_HIDDEN (no_ospf_transmit_delay
,
8731 no_ospf_transmit_delay_cmd
,
8732 "no ospf transmit-delay [(1-65535) [A.B.C.D]]",
8734 "OSPF interface commands\n"
8735 "Link state transmit delay\n"
8737 "Address of interface\n")
8739 return no_ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
8742 DEFUN (ip_ospf_area
,
8744 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]",
8746 "OSPF interface commands\n"
8748 "Enable OSPF on this interface\n"
8749 "OSPF area ID in IP address format\n"
8750 "OSPF area ID as a decimal value\n"
8751 "Address of interface\n")
8753 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8756 struct in_addr area_id
;
8757 struct in_addr addr
;
8758 struct ospf_if_params
*params
= NULL
;
8759 struct route_node
*rn
;
8760 struct ospf
*ospf
= NULL
;
8761 unsigned short instance
= 0;
8765 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
8766 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
8768 argv_find(argv
, argc
, "area", &idx
);
8769 areaid
= argv
[idx
+ 1]->arg
;
8772 ospf
= ifp
->vrf
->info
;
8774 ospf
= ospf_lookup_instance(instance
);
8776 if (instance
&& instance
!= ospf_instance
) {
8778 * At this point we know we have received
8779 * an instance and there is no ospf instance
8780 * associated with it. This means we are
8781 * in a situation where we have an
8782 * ospf command that is setup for a different
8783 * process(instance). We need to safely
8784 * remove the command from ourselves and
8785 * allow the other instance(process) handle
8786 * the configuration command.
8790 params
= IF_DEF_PARAMS(ifp
);
8791 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8792 UNSET_IF_PARAM(params
, if_area
);
8796 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
; rn
= route_next(rn
))
8797 if ((params
= rn
->info
) && OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8798 UNSET_IF_PARAM(params
, if_area
);
8803 ospf
= ifp
->vrf
->info
;
8805 ospf_interface_area_unset(ospf
, ifp
);
8808 return CMD_NOT_MY_INSTANCE
;
8811 ret
= str2area_id(areaid
, &area_id
, &format
);
8813 vty_out(vty
, "Please specify area by A.B.C.D|<0-4294967295>\n");
8814 return CMD_WARNING_CONFIG_FAILED
;
8816 if (memcmp(ifp
->name
, "VLINK", 5) == 0) {
8817 vty_out(vty
, "Cannot enable OSPF on a virtual link.\n");
8818 return CMD_WARNING_CONFIG_FAILED
;
8822 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
)) {
8823 if (rn
->info
!= NULL
) {
8825 "Please remove all network commands first.\n");
8826 return CMD_WARNING_CONFIG_FAILED
;
8831 params
= IF_DEF_PARAMS(ifp
);
8832 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)
8833 && !IPV4_ADDR_SAME(¶ms
->if_area
, &area_id
)) {
8835 "Must remove previous area config before changing ospf area \n");
8836 return CMD_WARNING_CONFIG_FAILED
;
8839 // Check if we have an address arg and proccess it
8840 if (argc
== idx
+ 3) {
8841 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
8843 "Please specify Intf Address by A.B.C.D\n");
8844 return CMD_WARNING_CONFIG_FAILED
;
8846 // update/create address-level params
8847 params
= ospf_get_if_params((ifp
), (addr
));
8848 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8849 if (!IPV4_ADDR_SAME(¶ms
->if_area
, &area_id
)) {
8851 "Must remove previous area/address config before changing ospf area\n");
8852 return CMD_WARNING_CONFIG_FAILED
;
8856 ospf_if_update_params((ifp
), (addr
));
8859 /* enable ospf on this interface with area_id */
8861 SET_IF_PARAM(params
, if_area
);
8862 params
->if_area
= area_id
;
8863 params
->if_area_id_fmt
= format
;
8867 ospf_interface_area_set(ospf
, ifp
);
8872 DEFUN (no_ip_ospf_area
,
8873 no_ip_ospf_area_cmd
,
8874 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]",
8877 "OSPF interface commands\n"
8879 "Disable OSPF on this interface\n"
8880 "OSPF area ID in IP address format\n"
8881 "OSPF area ID as a decimal value\n"
8882 "Address of interface\n")
8884 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8887 struct ospf_if_params
*params
;
8888 unsigned short instance
= 0;
8889 struct in_addr addr
;
8890 struct in_addr area_id
;
8892 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
8893 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
8896 ospf
= ifp
->vrf
->info
;
8898 ospf
= ospf_lookup_instance(instance
);
8900 if (instance
&& instance
!= ospf_instance
)
8901 return CMD_NOT_MY_INSTANCE
;
8903 argv_find(argv
, argc
, "area", &idx
);
8905 // Check if we have an address arg and proccess it
8906 if (argc
== idx
+ 3) {
8907 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
8909 "Please specify Intf Address by A.B.C.D\n");
8910 return CMD_WARNING_CONFIG_FAILED
;
8912 params
= ospf_lookup_if_params(ifp
, addr
);
8913 if ((params
) == NULL
)
8916 params
= IF_DEF_PARAMS(ifp
);
8918 area_id
= params
->if_area
;
8919 if (!OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8921 "Can't find specified interface area configuration.\n");
8922 return CMD_WARNING_CONFIG_FAILED
;
8925 UNSET_IF_PARAM(params
, if_area
);
8926 if (params
!= IF_DEF_PARAMS((ifp
))) {
8927 ospf_free_if_params((ifp
), (addr
));
8928 ospf_if_update_params((ifp
), (addr
));
8932 ospf_interface_area_unset(ospf
, ifp
);
8933 ospf_area_check_free(ospf
, area_id
);
8939 DEFUN (ip_ospf_passive
,
8940 ip_ospf_passive_cmd
,
8941 "ip ospf passive [A.B.C.D]",
8943 "OSPF interface commands\n"
8944 "Suppress routing updates on an interface\n"
8945 "Address of interface\n")
8947 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8949 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
8950 struct ospf_if_params
*params
;
8954 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8957 "Please specify interface address by A.B.C.D\n");
8958 return CMD_WARNING_CONFIG_FAILED
;
8960 params
= ospf_get_if_params(ifp
, addr
);
8961 ospf_if_update_params(ifp
, addr
);
8963 params
= IF_DEF_PARAMS(ifp
);
8966 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_PASSIVE
);
8971 DEFUN (no_ip_ospf_passive
,
8972 no_ip_ospf_passive_cmd
,
8973 "no ip ospf passive [A.B.C.D]",
8976 "OSPF interface commands\n"
8977 "Enable routing updates on an interface\n"
8978 "Address of interface\n")
8980 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8982 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
8983 struct ospf_if_params
*params
;
8987 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8990 "Please specify interface address by A.B.C.D\n");
8991 return CMD_WARNING_CONFIG_FAILED
;
8993 params
= ospf_lookup_if_params(ifp
, addr
);
8997 params
= IF_DEF_PARAMS(ifp
);
9000 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_ACTIVE
);
9005 DEFUN (ospf_redistribute_source
,
9006 ospf_redistribute_source_cmd
,
9007 "redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9009 FRR_REDIST_HELP_STR_OSPFD
9010 "Metric for redistributed routes\n"
9011 "OSPF default metric\n"
9012 "OSPF exterior metric type for redistributed routes\n"
9013 "Set OSPF External Type 1/2 metrics\n"
9014 "Route map reference\n"
9015 "Pointer to route-map entries\n")
9017 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9018 int idx_protocol
= 1;
9022 struct ospf_redist
*red
;
9024 bool update
= false;
9026 /* Get distribute source. */
9027 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
9029 return CMD_WARNING_CONFIG_FAILED
;
9031 /* Get metric value. */
9032 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
9033 if (!str2metric(argv
[idx
]->arg
, &metric
))
9034 return CMD_WARNING_CONFIG_FAILED
;
9037 /* Get metric type. */
9038 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
9039 if (!str2metric_type(argv
[idx
]->arg
, &type
))
9040 return CMD_WARNING_CONFIG_FAILED
;
9044 red
= ospf_redist_lookup(ospf
, source
, 0);
9046 red
= ospf_redist_add(ospf
, source
, 0);
9051 if (argv_find(argv
, argc
, "route-map", &idx
)) {
9052 ospf_routemap_set(red
, argv
[idx
+ 1]->arg
);
9054 ospf_routemap_unset(red
);
9057 return ospf_redistribute_update(ospf
, red
, source
, 0, type
,
9060 return ospf_redistribute_set(ospf
, red
, source
, 0, type
,
9064 DEFUN (no_ospf_redistribute_source
,
9065 no_ospf_redistribute_source_cmd
,
9066 "no redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9069 FRR_REDIST_HELP_STR_OSPFD
9070 "Metric for redistributed routes\n"
9071 "OSPF default metric\n"
9072 "OSPF exterior metric type for redistributed routes\n"
9073 "Set OSPF External Type 1/2 metrics\n"
9074 "Route map reference\n"
9075 "Pointer to route-map entries\n")
9077 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9078 int idx_protocol
= 2;
9080 struct ospf_redist
*red
;
9082 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
9084 return CMD_WARNING_CONFIG_FAILED
;
9086 red
= ospf_redist_lookup(ospf
, source
, 0);
9090 ospf_routemap_unset(red
);
9091 ospf_redist_del(ospf
, source
, 0);
9093 return ospf_redistribute_unset(ospf
, source
, 0);
9096 DEFUN (ospf_redistribute_instance_source
,
9097 ospf_redistribute_instance_source_cmd
,
9098 "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9100 "Open Shortest Path First\n"
9101 "Non-main Kernel Routing Table\n"
9102 "Instance ID/Table ID\n"
9103 "Metric for redistributed routes\n"
9104 "OSPF default metric\n"
9105 "OSPF exterior metric type for redistributed routes\n"
9106 "Set OSPF External Type 1/2 metrics\n"
9107 "Route map reference\n"
9108 "Pointer to route-map entries\n")
9110 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9111 int idx_ospf_table
= 1;
9117 unsigned short instance
;
9118 struct ospf_redist
*red
;
9119 bool update
= false;
9121 source
= proto_redistnum(AFI_IP
, argv
[idx_ospf_table
]->text
);
9124 vty_out(vty
, "Unknown instance redistribution\n");
9125 return CMD_WARNING_CONFIG_FAILED
;
9128 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9130 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
9132 "Instance redistribution in non-instanced OSPF not allowed\n");
9133 return CMD_WARNING_CONFIG_FAILED
;
9136 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
9137 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
9138 return CMD_WARNING_CONFIG_FAILED
;
9141 /* Get metric value. */
9142 if (argv_find(argv
, argc
, "metric", &idx
))
9143 if (!str2metric(argv
[idx
+ 1]->arg
, &metric
))
9144 return CMD_WARNING_CONFIG_FAILED
;
9147 /* Get metric type. */
9148 if (argv_find(argv
, argc
, "metric-type", &idx
))
9149 if (!str2metric_type(argv
[idx
+ 1]->arg
, &type
))
9150 return CMD_WARNING_CONFIG_FAILED
;
9152 red
= ospf_redist_lookup(ospf
, source
, instance
);
9154 red
= ospf_redist_add(ospf
, source
, instance
);
9159 if (argv_find(argv
, argc
, "route-map", &idx
))
9160 ospf_routemap_set(red
, argv
[idx
+ 1]->arg
);
9162 ospf_routemap_unset(red
);
9165 return ospf_redistribute_update(ospf
, red
, source
, instance
,
9168 return ospf_redistribute_set(ospf
, red
, source
, instance
, type
,
9172 DEFUN (no_ospf_redistribute_instance_source
,
9173 no_ospf_redistribute_instance_source_cmd
,
9174 "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9177 "Open Shortest Path First\n"
9178 "Non-main Kernel Routing Table\n"
9179 "Instance ID/Table Id\n"
9180 "Metric for redistributed routes\n"
9181 "OSPF default metric\n"
9182 "OSPF exterior metric type for redistributed routes\n"
9183 "Set OSPF External Type 1/2 metrics\n"
9184 "Route map reference\n"
9185 "Pointer to route-map entries\n")
9187 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9188 int idx_ospf_table
= 2;
9190 unsigned int instance
;
9191 struct ospf_redist
*red
;
9194 if (strncmp(argv
[idx_ospf_table
]->arg
, "o", 1) == 0)
9195 source
= ZEBRA_ROUTE_OSPF
;
9197 source
= ZEBRA_ROUTE_TABLE
;
9199 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9201 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
9203 "Instance redistribution in non-instanced OSPF not allowed\n");
9204 return CMD_WARNING_CONFIG_FAILED
;
9207 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
9208 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
9209 return CMD_WARNING_CONFIG_FAILED
;
9212 red
= ospf_redist_lookup(ospf
, source
, instance
);
9216 ospf_routemap_unset(red
);
9217 ospf_redist_del(ospf
, source
, instance
);
9219 return ospf_redistribute_unset(ospf
, source
, instance
);
9222 DEFUN (ospf_distribute_list_out
,
9223 ospf_distribute_list_out_cmd
,
9224 "distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD
,
9225 "Filter networks in routing updates\n"
9226 "Access-list name\n"
9228 FRR_REDIST_HELP_STR_OSPFD
)
9230 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9234 char *proto
= argv
[argc
- 1]->text
;
9236 /* Get distribute source. */
9237 source
= proto_redistnum(AFI_IP
, proto
);
9239 return CMD_WARNING_CONFIG_FAILED
;
9241 return ospf_distribute_list_out_set(ospf
, source
, argv
[idx_word
]->arg
);
9244 DEFUN (no_ospf_distribute_list_out
,
9245 no_ospf_distribute_list_out_cmd
,
9246 "no distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD
,
9248 "Filter networks in routing updates\n"
9249 "Access-list name\n"
9251 FRR_REDIST_HELP_STR_OSPFD
)
9253 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9257 char *proto
= argv
[argc
- 1]->text
;
9258 source
= proto_redistnum(AFI_IP
, proto
);
9260 return CMD_WARNING_CONFIG_FAILED
;
9262 return ospf_distribute_list_out_unset(ospf
, source
,
9263 argv
[idx_word
]->arg
);
9266 /* Default information originate. */
9267 DEFUN (ospf_default_information_originate
,
9268 ospf_default_information_originate_cmd
,
9269 "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9270 "Control distribution of default information\n"
9271 "Distribute a default route\n"
9272 "Always advertise default route\n"
9273 "OSPF default metric\n"
9275 "OSPF metric type for default routes\n"
9276 "Set OSPF External Type 1/2 metrics\n"
9277 "Route map reference\n"
9278 "Pointer to route-map entries\n")
9280 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9281 int default_originate
= DEFAULT_ORIGINATE_ZEBRA
;
9284 struct ospf_redist
*red
;
9286 int cur_originate
= ospf
->default_originate
;
9287 bool sameRtmap
= false;
9290 red
= ospf_redist_add(ospf
, DEFAULT_ROUTE
, 0);
9292 /* Check whether "always" was specified */
9293 if (argv_find(argv
, argc
, "always", &idx
))
9294 default_originate
= DEFAULT_ORIGINATE_ALWAYS
;
9296 /* Get metric value */
9297 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
9298 if (!str2metric(argv
[idx
]->arg
, &metric
))
9299 return CMD_WARNING_CONFIG_FAILED
;
9302 /* Get metric type. */
9303 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
9304 if (!str2metric_type(argv
[idx
]->arg
, &type
))
9305 return CMD_WARNING_CONFIG_FAILED
;
9309 if (argv_find(argv
, argc
, "route-map", &idx
))
9310 rtmap
= argv
[idx
+ 1]->arg
;
9312 /* To check if user is providing same route map */
9313 if ((!rtmap
&& !ROUTEMAP_NAME(red
)) ||
9314 (rtmap
&& ROUTEMAP_NAME(red
) &&
9315 (strcmp(rtmap
, ROUTEMAP_NAME(red
)) == 0)))
9318 /* Don't allow if the same lsa is already originated. */
9320 && (red
->dmetric
.type
== type
)
9321 && (red
->dmetric
.value
== metric
)
9322 && (cur_originate
== default_originate
))
9325 /* Updating Metric details */
9326 red
->dmetric
.type
= type
;
9327 red
->dmetric
.value
= metric
;
9329 /* updating route map details */
9331 ospf_routemap_set(red
, rtmap
);
9333 ospf_routemap_unset(red
);
9335 return ospf_redistribute_default_set(ospf
, default_originate
, type
,
9339 DEFUN (no_ospf_default_information_originate
,
9340 no_ospf_default_information_originate_cmd
,
9341 "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9343 "Control distribution of default information\n"
9344 "Distribute a default route\n"
9345 "Always advertise default route\n"
9346 "OSPF default metric\n"
9348 "OSPF metric type for default routes\n"
9349 "Set OSPF External Type 1/2 metrics\n"
9350 "Route map reference\n"
9351 "Pointer to route-map entries\n")
9353 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9354 struct ospf_redist
*red
;
9356 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
9360 ospf_routemap_unset(red
);
9361 ospf_redist_del(ospf
, DEFAULT_ROUTE
, 0);
9363 return ospf_redistribute_default_set(ospf
, DEFAULT_ORIGINATE_NONE
,
9367 DEFUN (ospf_default_metric
,
9368 ospf_default_metric_cmd
,
9369 "default-metric (0-16777214)",
9370 "Set metric of redistributed routes\n"
9373 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9377 if (!str2metric(argv
[idx_number
]->arg
, &metric
))
9378 return CMD_WARNING_CONFIG_FAILED
;
9380 ospf
->default_metric
= metric
;
9385 DEFUN (no_ospf_default_metric
,
9386 no_ospf_default_metric_cmd
,
9387 "no default-metric [(0-16777214)]",
9389 "Set metric of redistributed routes\n"
9392 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9394 ospf
->default_metric
= -1;
9400 DEFUN (ospf_distance
,
9403 "Administrative distance\n"
9404 "OSPF Administrative distance\n")
9406 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9410 distance
= atoi(argv
[idx_number
]->arg
);
9411 if (ospf
->distance_all
!= distance
) {
9412 ospf
->distance_all
= distance
;
9413 ospf_restart_spf(ospf
);
9419 DEFUN (no_ospf_distance
,
9420 no_ospf_distance_cmd
,
9421 "no distance (1-255)",
9423 "Administrative distance\n"
9424 "OSPF Administrative distance\n")
9426 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9428 if (ospf
->distance_all
) {
9429 ospf
->distance_all
= 0;
9430 ospf_restart_spf(ospf
);
9436 DEFUN (no_ospf_distance_ospf
,
9437 no_ospf_distance_ospf_cmd
,
9438 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
9440 "Administrative distance\n"
9441 "OSPF administrative distance\n"
9442 "Intra-area routes\n"
9443 "Distance for intra-area routes\n"
9444 "Inter-area routes\n"
9445 "Distance for inter-area routes\n"
9447 "Distance for external routes\n")
9449 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9452 if (argv_find(argv
, argc
, "intra-area", &idx
) || argc
== 3)
9453 idx
= ospf
->distance_intra
= 0;
9454 if (argv_find(argv
, argc
, "inter-area", &idx
) || argc
== 3)
9455 idx
= ospf
->distance_inter
= 0;
9456 if (argv_find(argv
, argc
, "external", &idx
) || argc
== 3)
9457 ospf
->distance_external
= 0;
9462 DEFUN (ospf_distance_ospf
,
9463 ospf_distance_ospf_cmd
,
9464 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
9465 "Administrative distance\n"
9466 "OSPF administrative distance\n"
9467 "Intra-area routes\n"
9468 "Distance for intra-area routes\n"
9469 "Inter-area routes\n"
9470 "Distance for inter-area routes\n"
9472 "Distance for external routes\n")
9474 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9477 ospf
->distance_intra
= 0;
9478 ospf
->distance_inter
= 0;
9479 ospf
->distance_external
= 0;
9481 if (argv_find(argv
, argc
, "intra-area", &idx
))
9482 ospf
->distance_intra
= atoi(argv
[idx
+ 1]->arg
);
9484 if (argv_find(argv
, argc
, "inter-area", &idx
))
9485 ospf
->distance_inter
= atoi(argv
[idx
+ 1]->arg
);
9487 if (argv_find(argv
, argc
, "external", &idx
))
9488 ospf
->distance_external
= atoi(argv
[idx
+ 1]->arg
);
9493 DEFUN (ip_ospf_mtu_ignore
,
9494 ip_ospf_mtu_ignore_addr_cmd
,
9495 "ip ospf mtu-ignore [A.B.C.D]",
9497 "OSPF interface commands\n"
9498 "Disable MTU mismatch detection on this interface\n"
9499 "Address of interface\n")
9501 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9503 struct in_addr addr
;
9506 struct ospf_if_params
*params
;
9507 params
= IF_DEF_PARAMS(ifp
);
9510 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9513 "Please specify interface address by A.B.C.D\n");
9514 return CMD_WARNING_CONFIG_FAILED
;
9516 params
= ospf_get_if_params(ifp
, addr
);
9517 ospf_if_update_params(ifp
, addr
);
9519 params
->mtu_ignore
= 1;
9520 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
9521 SET_IF_PARAM(params
, mtu_ignore
);
9523 UNSET_IF_PARAM(params
, mtu_ignore
);
9524 if (params
!= IF_DEF_PARAMS(ifp
)) {
9525 ospf_free_if_params(ifp
, addr
);
9526 ospf_if_update_params(ifp
, addr
);
9532 DEFUN (no_ip_ospf_mtu_ignore
,
9533 no_ip_ospf_mtu_ignore_addr_cmd
,
9534 "no ip ospf mtu-ignore [A.B.C.D]",
9537 "OSPF interface commands\n"
9538 "Disable MTU mismatch detection on this interface\n"
9539 "Address of interface\n")
9541 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9543 struct in_addr addr
;
9546 struct ospf_if_params
*params
;
9547 params
= IF_DEF_PARAMS(ifp
);
9550 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9553 "Please specify interface address by A.B.C.D\n");
9554 return CMD_WARNING_CONFIG_FAILED
;
9556 params
= ospf_get_if_params(ifp
, addr
);
9557 ospf_if_update_params(ifp
, addr
);
9559 params
->mtu_ignore
= 0;
9560 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
9561 SET_IF_PARAM(params
, mtu_ignore
);
9563 UNSET_IF_PARAM(params
, mtu_ignore
);
9564 if (params
!= IF_DEF_PARAMS(ifp
)) {
9565 ospf_free_if_params(ifp
, addr
);
9566 ospf_if_update_params(ifp
, addr
);
9573 DEFUN (ospf_max_metric_router_lsa_admin
,
9574 ospf_max_metric_router_lsa_admin_cmd
,
9575 "max-metric router-lsa administrative",
9576 "OSPF maximum / infinite-distance metric\n"
9577 "Advertise own Router-LSA with infinite distance (stub router)\n"
9578 "Administratively applied, for an indefinite period\n")
9580 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9581 struct listnode
*ln
;
9582 struct ospf_area
*area
;
9584 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
9585 SET_FLAG(area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
);
9587 if (!CHECK_FLAG(area
->stub_router_state
,
9588 OSPF_AREA_IS_STUB_ROUTED
))
9589 ospf_router_lsa_update_area(area
);
9592 /* Allows for areas configured later to get the property */
9593 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
;
9598 DEFUN (no_ospf_max_metric_router_lsa_admin
,
9599 no_ospf_max_metric_router_lsa_admin_cmd
,
9600 "no max-metric router-lsa administrative",
9602 "OSPF maximum / infinite-distance metric\n"
9603 "Advertise own Router-LSA with infinite distance (stub router)\n"
9604 "Administratively applied, for an indefinite period\n")
9606 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9607 struct listnode
*ln
;
9608 struct ospf_area
*area
;
9610 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
9611 UNSET_FLAG(area
->stub_router_state
,
9612 OSPF_AREA_ADMIN_STUB_ROUTED
);
9614 /* Don't trample on the start-up stub timer */
9615 if (CHECK_FLAG(area
->stub_router_state
,
9616 OSPF_AREA_IS_STUB_ROUTED
)
9617 && !area
->t_stub_router
) {
9618 UNSET_FLAG(area
->stub_router_state
,
9619 OSPF_AREA_IS_STUB_ROUTED
);
9620 ospf_router_lsa_update_area(area
);
9623 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET
;
9627 DEFUN (ospf_max_metric_router_lsa_startup
,
9628 ospf_max_metric_router_lsa_startup_cmd
,
9629 "max-metric router-lsa on-startup (5-86400)",
9630 "OSPF maximum / infinite-distance metric\n"
9631 "Advertise own Router-LSA with infinite distance (stub router)\n"
9632 "Automatically advertise stub Router-LSA on startup of OSPF\n"
9633 "Time (seconds) to advertise self as stub-router\n")
9635 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9637 unsigned int seconds
;
9640 vty_out(vty
, "%% Must supply stub-router period\n");
9641 return CMD_WARNING_CONFIG_FAILED
;
9644 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9646 ospf
->stub_router_startup_time
= seconds
;
9651 DEFUN (no_ospf_max_metric_router_lsa_startup
,
9652 no_ospf_max_metric_router_lsa_startup_cmd
,
9653 "no max-metric router-lsa on-startup [(5-86400)]",
9655 "OSPF maximum / infinite-distance metric\n"
9656 "Advertise own Router-LSA with infinite distance (stub router)\n"
9657 "Automatically advertise stub Router-LSA on startup of OSPF\n"
9658 "Time (seconds) to advertise self as stub-router\n")
9660 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9661 struct listnode
*ln
;
9662 struct ospf_area
*area
;
9664 ospf
->stub_router_startup_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
9666 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
9667 SET_FLAG(area
->stub_router_state
,
9668 OSPF_AREA_WAS_START_STUB_ROUTED
);
9669 EVENT_OFF(area
->t_stub_router
);
9671 /* Don't trample on admin stub routed */
9672 if (!CHECK_FLAG(area
->stub_router_state
,
9673 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
9674 UNSET_FLAG(area
->stub_router_state
,
9675 OSPF_AREA_IS_STUB_ROUTED
);
9676 ospf_router_lsa_update_area(area
);
9683 DEFUN (ospf_max_metric_router_lsa_shutdown
,
9684 ospf_max_metric_router_lsa_shutdown_cmd
,
9685 "max-metric router-lsa on-shutdown (5-100)",
9686 "OSPF maximum / infinite-distance metric\n"
9687 "Advertise own Router-LSA with infinite distance (stub router)\n"
9688 "Advertise stub-router prior to full shutdown of OSPF\n"
9689 "Time (seconds) to wait till full shutdown\n")
9691 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9693 unsigned int seconds
;
9696 vty_out(vty
, "%% Must supply stub-router shutdown period\n");
9697 return CMD_WARNING_CONFIG_FAILED
;
9700 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9702 ospf
->stub_router_shutdown_time
= seconds
;
9707 DEFUN (no_ospf_max_metric_router_lsa_shutdown
,
9708 no_ospf_max_metric_router_lsa_shutdown_cmd
,
9709 "no max-metric router-lsa on-shutdown [(5-100)]",
9711 "OSPF maximum / infinite-distance metric\n"
9712 "Advertise own Router-LSA with infinite distance (stub router)\n"
9713 "Advertise stub-router prior to full shutdown of OSPF\n"
9714 "Time (seconds) to wait till full shutdown\n")
9716 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9718 ospf
->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
9723 DEFUN (ospf_proactive_arp
,
9724 ospf_proactive_arp_cmd
,
9726 "Allow sending ARP requests proactively\n")
9728 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9730 ospf
->proactive_arp
= true;
9735 DEFUN (no_ospf_proactive_arp
,
9736 no_ospf_proactive_arp_cmd
,
9739 "Disallow sending ARP requests proactively\n")
9741 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9743 ospf
->proactive_arp
= false;
9748 /* Graceful Restart HELPER Commands */
9749 DEFPY(ospf_gr_helper_enable
, ospf_gr_helper_enable_cmd
,
9750 "graceful-restart helper enable [A.B.C.D$address]",
9751 "OSPF Graceful Restart\n"
9753 "Enable Helper support\n"
9754 "Advertising Router-ID\n")
9756 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9759 ospf_gr_helper_support_set_per_routerid(ospf
, &address
,
9764 ospf_gr_helper_support_set(ospf
, OSPF_GR_TRUE
);
9769 DEFPY(no_ospf_gr_helper_enable
,
9770 no_ospf_gr_helper_enable_cmd
,
9771 "no graceful-restart helper enable [A.B.C.D$address]",
9773 "OSPF Graceful Restart\n"
9775 "Enable Helper support\n"
9776 "Advertising Router-ID\n")
9778 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9781 ospf_gr_helper_support_set_per_routerid(ospf
, &address
,
9786 ospf_gr_helper_support_set(ospf
, OSPF_GR_FALSE
);
9790 DEFPY(ospf_gr_helper_enable_lsacheck
,
9791 ospf_gr_helper_enable_lsacheck_cmd
,
9792 "graceful-restart helper strict-lsa-checking",
9793 "OSPF Graceful Restart\n"
9795 "Enable strict LSA check\n")
9797 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9799 ospf_gr_helper_lsa_check_set(ospf
, OSPF_GR_TRUE
);
9803 DEFPY(no_ospf_gr_helper_enable_lsacheck
,
9804 no_ospf_gr_helper_enable_lsacheck_cmd
,
9805 "no graceful-restart helper strict-lsa-checking",
9807 "OSPF Graceful Restart\n"
9809 "Disable strict LSA check\n")
9811 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9813 ospf_gr_helper_lsa_check_set(ospf
, OSPF_GR_FALSE
);
9817 DEFPY(ospf_gr_helper_supported_grace_time
,
9818 ospf_gr_helper_supported_grace_time_cmd
,
9819 "graceful-restart helper supported-grace-time (10-1800)$interval",
9820 "OSPF Graceful Restart\n"
9822 "Supported grace timer\n"
9823 "Grace interval(in seconds)\n")
9825 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9827 ospf_gr_helper_supported_gracetime_set(ospf
, interval
);
9831 DEFPY(no_ospf_gr_helper_supported_grace_time
,
9832 no_ospf_gr_helper_supported_grace_time_cmd
,
9833 "no graceful-restart helper supported-grace-time (10-1800)$interval",
9835 "OSPF Graceful Restart\n"
9837 "Supported grace timer\n"
9838 "Grace interval(in seconds)\n")
9840 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9842 ospf_gr_helper_supported_gracetime_set(ospf
, OSPF_MAX_GRACE_INTERVAL
);
9846 DEFPY(ospf_gr_helper_planned_only
,
9847 ospf_gr_helper_planned_only_cmd
,
9848 "graceful-restart helper planned-only",
9849 "OSPF Graceful Restart\n"
9851 "Supported only planned restart\n")
9853 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9855 ospf_gr_helper_set_supported_planned_only_restart(ospf
, OSPF_GR_TRUE
);
9860 /* External Route Aggregation */
9861 DEFUN (ospf_external_route_aggregation
,
9862 ospf_external_route_aggregation_cmd
,
9863 "summary-address A.B.C.D/M [tag (1-4294967295)]",
9864 "External summary address\n"
9865 "Summary address prefix\n"
9867 "Router tag value\n")
9869 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9870 struct prefix_ipv4 p
;
9872 route_tag_t tag
= 0;
9873 int ret
= OSPF_SUCCESS
;
9875 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
9877 if (is_default_prefix4(&p
)) {
9879 "Default address shouldn't be configured as summary address.\n");
9883 /* Apply mask for given prefix. */
9886 if (!is_valid_summary_addr(&p
)) {
9887 vty_out(vty
, "Not a valid summary address.\n");
9888 return CMD_WARNING_CONFIG_FAILED
;
9892 tag
= strtoul(argv
[idx
+ 2]->arg
, NULL
, 10);
9894 ret
= ospf_asbr_external_aggregator_set(ospf
, &p
, tag
);
9895 if (ret
== OSPF_INVALID
)
9896 vty_out(vty
, "Invalid configuration!!\n");
9901 DEFUN (no_ospf_external_route_aggregation
,
9902 no_ospf_external_route_aggregation_cmd
,
9903 "no summary-address A.B.C.D/M [tag (1-4294967295)]",
9905 "External summary address\n"
9906 "Summary address prefix\n"
9908 "Router tag value\n")
9910 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9911 struct prefix_ipv4 p
;
9913 route_tag_t tag
= 0;
9914 int ret
= OSPF_SUCCESS
;
9916 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
9918 if (is_default_prefix4(&p
)) {
9920 "Default address shouldn't be configured as summary address.\n");
9924 /* Apply mask for given prefix. */
9927 if (!is_valid_summary_addr(&p
)) {
9928 vty_out(vty
, "Not a valid summary address.\n");
9929 return CMD_WARNING_CONFIG_FAILED
;
9933 tag
= strtoul(argv
[idx
+ 2]->arg
, NULL
, 10);
9935 ret
= ospf_asbr_external_aggregator_unset(ospf
, &p
, tag
);
9936 if (ret
== OSPF_INVALID
)
9937 vty_out(vty
, "Invalid configuration!!\n");
9942 DEFPY(no_ospf_gr_helper_planned_only
,
9943 no_ospf_gr_helper_planned_only_cmd
,
9944 "no graceful-restart helper planned-only",
9946 "OSPF Graceful Restart\n"
9948 "Supported only for planned restart\n")
9950 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9952 ospf_gr_helper_set_supported_planned_only_restart(ospf
, OSPF_GR_FALSE
);
9957 static int ospf_print_vty_helper_dis_rtr_walkcb(struct hash_bucket
*bucket
,
9960 struct advRtr
*rtr
= bucket
->data
;
9961 struct vty
*vty
= (struct vty
*)arg
;
9962 static unsigned int count
;
9964 vty_out(vty
, "%-6pI4,", &rtr
->advRtrAddr
);
9970 return HASHWALK_CONTINUE
;
9973 static int ospf_print_json_helper_enabled_rtr_walkcb(struct hash_bucket
*bucket
,
9976 struct advRtr
*rtr
= bucket
->data
;
9977 struct json_object
*json_rid_array
= arg
;
9978 struct json_object
*json_rid
;
9980 json_rid
= json_object_new_object();
9982 json_object_string_addf(json_rid
, "routerId", "%pI4", &rtr
->advRtrAddr
);
9983 json_object_array_add(json_rid_array
, json_rid
);
9985 return HASHWALK_CONTINUE
;
9988 static int ospf_show_gr_helper_details(struct vty
*vty
, struct ospf
*ospf
,
9989 uint8_t use_vrf
, json_object
*json
,
9990 bool uj
, bool detail
)
9992 struct listnode
*node
;
9993 struct ospf_interface
*oi
;
9994 char buf
[PREFIX_STRLEN
];
9995 json_object
*json_vrf
= NULL
;
9999 json_vrf
= json_object_new_object();
10004 if (ospf
->instance
) {
10006 json_object_int_add(json
, "ospfInstance",
10009 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
10012 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
10016 json_object_object_add(json
, ospf_get_name(ospf
),
10019 vty_out(vty
, "\n");
10021 /* Show Router ID. */
10023 json_object_string_add(json_vrf
, "routerId",
10024 inet_ntop(AF_INET
, &ospf
->router_id
,
10025 buf
, sizeof(buf
)));
10027 vty_out(vty
, "\n OSPF Router with ID (%pI4)\n\n",
10033 if (ospf
->is_helper_supported
)
10035 " Graceful restart helper support enabled.\n");
10038 " Graceful restart helper support disabled.\n");
10040 if (ospf
->strict_lsa_check
)
10041 vty_out(vty
, " Strict LSA check is enabled.\n");
10043 vty_out(vty
, " Strict LSA check is disabled.\n");
10045 if (ospf
->only_planned_restart
)
10047 " Helper supported for planned restarts only.\n");
10050 " Helper supported for Planned and Unplanned Restarts.\n");
10053 " Supported Graceful restart interval: %d(in seconds).\n",
10054 ospf
->supported_grace_time
);
10056 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf
)) {
10057 vty_out(vty
, " Enable Router list:\n");
10059 hash_walk(ospf
->enable_rtr_list
,
10060 ospf_print_vty_helper_dis_rtr_walkcb
, vty
);
10061 vty_out(vty
, "\n\n");
10064 if (ospf
->last_exit_reason
!= OSPF_GR_HELPER_EXIT_NONE
) {
10065 vty_out(vty
, " Last Helper exit Reason :%s\n",
10066 ospf_exit_reason2str(ospf
->last_exit_reason
));
10069 if (ospf
->active_restarter_cnt
)
10071 " Number of Active neighbours in graceful restart: %d\n",
10072 ospf
->active_restarter_cnt
);
10074 vty_out(vty
, "\n");
10077 json_object_string_add(
10078 json_vrf
, "helperSupport",
10079 (ospf
->is_helper_supported
) ? "Enabled" : "Disabled");
10080 json_object_string_add(json_vrf
, "strictLsaCheck",
10081 (ospf
->strict_lsa_check
) ? "Enabled"
10083 #if CONFDATE > 20240401
10084 CPP_NOTICE("Remove deprecated json key: restartSupoort")
10086 json_object_string_add(
10087 json_vrf
, "restartSupoort",
10088 (ospf
->only_planned_restart
)
10089 ? "Planned Restart only"
10090 : "Planned and Unplanned Restarts");
10092 json_object_string_add(
10093 json_vrf
, "restartSupport",
10094 (ospf
->only_planned_restart
)
10095 ? "Planned Restart only"
10096 : "Planned and Unplanned Restarts");
10098 json_object_int_add(json_vrf
, "supportedGracePeriod",
10099 ospf
->supported_grace_time
);
10101 if (ospf
->last_exit_reason
!= OSPF_GR_HELPER_EXIT_NONE
)
10102 json_object_string_add(
10103 json_vrf
, "lastExitReason",
10104 ospf_exit_reason2str(ospf
->last_exit_reason
));
10106 if (ospf
->active_restarter_cnt
)
10107 json_object_int_add(json_vrf
, "activeRestarterCnt",
10108 ospf
->active_restarter_cnt
);
10110 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf
)) {
10111 struct json_object
*json_rid_array
=
10112 json_object_new_array();
10114 json_object_object_add(json_vrf
, "enabledRouterIds",
10117 hash_walk(ospf
->enable_rtr_list
,
10118 ospf_print_json_helper_enabled_rtr_walkcb
,
10126 json_object
*json_neighbors
= NULL
;
10128 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
10129 struct route_node
*rn
;
10130 struct ospf_neighbor
*nbr
;
10131 json_object
*json_neigh
;
10133 if (ospf_interface_neighbor_count(oi
) == 0)
10137 json_object_object_get_ex(json_vrf
, "neighbors",
10139 if (!json_neighbors
) {
10141 json_object_new_object();
10142 json_object_object_add(json_vrf
,
10148 for (rn
= route_top(oi
->nbrs
); rn
;
10149 rn
= route_next(rn
)) {
10156 if (!OSPF_GR_IS_ACTIVE_HELPER(nbr
))
10160 vty_out(vty
, " Neighbour %d :\n", cnt
);
10161 vty_out(vty
, " Address : %pI4\n",
10162 &nbr
->address
.u
.prefix4
);
10163 vty_out(vty
, " Routerid : %pI4\n",
10166 " Received Grace period : %d(in seconds).\n",
10167 nbr
->gr_helper_info
10168 .recvd_grace_period
);
10170 " Actual Grace period : %d(in seconds)\n",
10171 nbr
->gr_helper_info
10172 .actual_grace_period
);
10174 " Remaining GraceTime:%ld(in seconds).\n",
10175 event_timer_remain_second(
10176 nbr
->gr_helper_info
10179 " Graceful Restart reason: %s.\n\n",
10180 ospf_restart_reason2str(
10181 nbr
->gr_helper_info
10182 .gr_restart_reason
));
10185 json_neigh
= json_object_new_object();
10186 json_object_string_add(
10187 json_neigh
, "srcAddr",
10188 inet_ntop(AF_INET
, &nbr
->src
,
10189 buf
, sizeof(buf
)));
10191 json_object_string_add(
10192 json_neigh
, "routerid",
10195 buf
, sizeof(buf
)));
10196 json_object_int_add(
10198 "recvdGraceInterval",
10199 nbr
->gr_helper_info
10200 .recvd_grace_period
);
10201 json_object_int_add(
10203 "actualGraceInterval",
10204 nbr
->gr_helper_info
10205 .actual_grace_period
);
10206 json_object_int_add(
10207 json_neigh
, "remainGracetime",
10208 event_timer_remain_second(
10209 nbr
->gr_helper_info
10211 json_object_string_add(
10212 json_neigh
, "restartReason",
10213 ospf_restart_reason2str(
10214 nbr
->gr_helper_info
10215 .gr_restart_reason
));
10216 json_object_object_add(
10218 inet_ntop(AF_INET
, &nbr
->src
,
10225 return CMD_SUCCESS
;
10228 DEFUN (ospf_external_route_aggregation_no_adrvertise
,
10229 ospf_external_route_aggregation_no_adrvertise_cmd
,
10230 "summary-address A.B.C.D/M no-advertise",
10231 "External summary address\n"
10232 "Summary address prefix\n"
10233 "Don't advertise summary route \n")
10235 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10236 struct prefix_ipv4 p
;
10238 int ret
= OSPF_SUCCESS
;
10240 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
10242 if (is_default_prefix4(&p
)) {
10244 "Default address shouldn't be configured as summary address.\n");
10245 return CMD_SUCCESS
;
10248 /* Apply mask for given prefix. */
10251 if (!is_valid_summary_addr(&p
)) {
10252 vty_out(vty
, "Not a valid summary address.\n");
10253 return CMD_WARNING_CONFIG_FAILED
;
10256 ret
= ospf_asbr_external_rt_no_advertise(ospf
, &p
);
10257 if (ret
== OSPF_INVALID
)
10258 vty_out(vty
, "Invalid configuration!!\n");
10260 return CMD_SUCCESS
;
10263 DEFUN (no_ospf_external_route_aggregation_no_adrvertise
,
10264 no_ospf_external_route_aggregation_no_adrvertise_cmd
,
10265 "no summary-address A.B.C.D/M no-advertise",
10267 "External summary address\n"
10268 "Summary address prefix\n"
10269 "Advertise summary route to the AS \n")
10271 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10272 struct prefix_ipv4 p
;
10274 int ret
= OSPF_SUCCESS
;
10276 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
10278 if (is_default_prefix4(&p
)) {
10280 "Default address shouldn't be configured as summary address.\n");
10281 return CMD_SUCCESS
;
10284 /* Apply mask for given prefix. */
10287 if (!is_valid_summary_addr(&p
)) {
10288 vty_out(vty
, "Not a valid summary address.\n");
10289 return CMD_WARNING_CONFIG_FAILED
;
10292 ret
= ospf_asbr_external_rt_advertise(ospf
, &p
);
10293 if (ret
== OSPF_INVALID
)
10294 vty_out(vty
, "Invalid configuration!!\n");
10296 return CMD_SUCCESS
;
10299 DEFUN (ospf_route_aggregation_timer
,
10300 ospf_route_aggregation_timer_cmd
,
10301 "aggregation timer (5-1800)",
10302 "External route aggregation\n"
10303 "Delay timer (in seconds)\n"
10304 "Timer interval(in seconds)\n")
10306 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10307 uint16_t interval
= 0;
10309 interval
= strtoul(argv
[2]->arg
, NULL
, 10);
10311 ospf_external_aggregator_timer_set(ospf
, interval
);
10313 return CMD_SUCCESS
;
10316 DEFPY (show_ip_ospf_gr_helper
,
10317 show_ip_ospf_gr_helper_cmd
,
10318 "show ip ospf [vrf <NAME|all>] graceful-restart helper [detail] [json]",
10321 "OSPF information\n"
10324 "OSPF Graceful Restart\n"
10325 "Helper details in the router\n"
10326 "Detailed information\n"
10329 char *vrf_name
= NULL
;
10330 bool all_vrf
= false;
10331 int ret
= CMD_SUCCESS
;
10334 uint8_t use_vrf
= 0;
10335 bool uj
= use_json(argc
, argv
);
10336 struct ospf
*ospf
= NULL
;
10337 json_object
*json
= NULL
;
10338 struct listnode
*node
= NULL
;
10340 bool detail
= false;
10342 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
10344 if (argv_find(argv
, argc
, "detail", &idx
))
10348 json
= json_object_new_object();
10350 /* vrf input is provided */
10355 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
10356 if (!ospf
->oi_running
)
10359 ret
= ospf_show_gr_helper_details(
10360 vty
, ospf
, use_vrf
, json
, uj
, detail
);
10364 vty_json(vty
, json
);
10369 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
10371 if (ospf
== NULL
|| !ospf
->oi_running
) {
10374 vty_json(vty
, json
);
10377 "%% OSPF is not enabled in vrf %s\n",
10380 return CMD_SUCCESS
;
10385 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
10387 if (ospf
== NULL
|| !ospf
->oi_running
) {
10390 vty_json(vty
, json
);
10393 "%% OSPF is not enabled in vrf default\n");
10395 return CMD_SUCCESS
;
10398 ospf_show_gr_helper_details(vty
, ospf
, use_vrf
, json
, uj
,
10403 vty_json(vty
, json
);
10405 return CMD_SUCCESS
;
10407 /* Graceful Restart HELPER commands end */
10408 DEFUN (no_ospf_route_aggregation_timer
,
10409 no_ospf_route_aggregation_timer_cmd
,
10410 "no aggregation timer",
10412 "External route aggregation\n"
10415 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10417 ospf_external_aggregator_timer_set(ospf
, OSPF_EXTL_AGGR_DEFAULT_DELAY
);
10419 return CMD_SUCCESS
;
10422 /* External Route Aggregation End */
10424 static void config_write_stub_router(struct vty
*vty
, struct ospf
*ospf
)
10426 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
10427 vty_out(vty
, " max-metric router-lsa on-startup %u\n",
10428 ospf
->stub_router_startup_time
);
10429 if (ospf
->stub_router_shutdown_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
10430 vty_out(vty
, " max-metric router-lsa on-shutdown %u\n",
10431 ospf
->stub_router_shutdown_time
);
10432 if (ospf
->stub_router_admin_set
== OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
)
10433 vty_out(vty
, " max-metric router-lsa administrative\n");
10438 static void show_ip_ospf_route_network(struct vty
*vty
, struct ospf
*ospf
,
10439 struct route_table
*rt
,
10442 struct route_node
*rn
;
10443 struct ospf_route
* or ;
10444 struct listnode
*pnode
, *pnnode
;
10445 struct ospf_path
*path
;
10446 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
10447 *json_nexthop
= NULL
;
10451 "============ OSPF network routing table ============\n");
10453 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
10454 char buf1
[PREFIX2STR_BUFFER
];
10456 if ((or = rn
->info
) == NULL
)
10459 prefix2str(&rn
->p
, buf1
, sizeof(buf1
));
10462 json_route
= json_object_new_object();
10463 json_object_object_add(json
, buf1
, json_route
);
10466 switch (or->path_type
) {
10467 case OSPF_PATH_INTER_AREA
:
10468 if (or->type
== OSPF_DESTINATION_NETWORK
) {
10470 json_object_string_add(json_route
,
10473 json_object_int_add(json_route
, "cost",
10475 json_object_string_addf(
10476 json_route
, "area", "%pI4",
10477 &or->u
.std
.area_id
);
10480 "N IA %-18s [%d] area: %pI4\n",
10482 &or->u
.std
.area_id
);
10484 } else if (or->type
== OSPF_DESTINATION_DISCARD
) {
10486 json_object_string_add(json_route
,
10491 "D IA %-18s Discard entry\n",
10496 case OSPF_PATH_INTRA_AREA
:
10498 json_object_string_add(json_route
, "routeType",
10500 json_object_int_add(json_route
, "cost",
10502 json_object_string_addf(json_route
, "area",
10504 &or->u
.std
.area_id
);
10506 vty_out(vty
, "N %-18s [%d] area: %pI4\n",
10508 &or->u
.std
.area_id
);
10515 if (or->type
== OSPF_DESTINATION_NETWORK
) {
10517 json_nexthop_array
= json_object_new_array();
10518 json_object_object_add(json_route
, "nexthops",
10519 json_nexthop_array
);
10522 for (ALL_LIST_ELEMENTS(or->paths
, pnode
, pnnode
,
10525 json_nexthop
= json_object_new_object();
10526 json_object_array_add(
10527 json_nexthop_array
,
10530 if (if_lookup_by_index(path
->ifindex
,
10533 if (path
->nexthop
.s_addr
10536 json_object_string_add(
10539 json_object_string_add(
10541 "directlyAttachedTo",
10547 "%24s directly attached to %s\n",
10555 json_object_string_addf(
10559 json_object_string_add(
10567 "%24s via %pI4, %s\n",
10580 vty_out(vty
, "\n");
10583 static void show_ip_ospf_route_router(struct vty
*vty
, struct ospf
*ospf
,
10584 struct route_table
*rtrs
,
10587 struct route_node
*rn
;
10588 struct ospf_route
* or ;
10589 struct listnode
*pnode
;
10590 struct listnode
*node
;
10591 struct ospf_path
*path
;
10592 char buf
[PREFIX_STRLEN
];
10593 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
10594 *json_nexthop
= NULL
;
10597 vty_out(vty
, "============ OSPF %s table =============\n",
10598 ospf
->all_rtrs
== rtrs
? "reachable routers"
10599 : "router routing");
10601 for (rn
= route_top(rtrs
); rn
; rn
= route_next(rn
)) {
10602 if (rn
->info
== NULL
)
10607 json_route
= json_object_new_object();
10608 json_object_object_add(
10609 json
, inet_ntop(AF_INET
, &rn
->p
.u
.prefix4
,
10612 json_object_string_add(json_route
, "routeType", "R ");
10614 vty_out(vty
, "R %-15pI4 ",
10618 for (ALL_LIST_ELEMENTS_RO((struct list
*)rn
->info
, node
, or)) {
10621 vty_out(vty
, "%24s", "");
10626 json_object_int_add(json_route
, "cost",
10628 json_object_string_addf(json_route
, "area",
10630 &or->u
.std
.area_id
);
10631 if (or->path_type
== OSPF_PATH_INTER_AREA
) {
10632 json_object_boolean_true_add(json_route
,
10634 json_object_boolean_true_add(json_route
,
10637 if (or->u
.std
.flags
& ROUTER_LSA_BORDER
)
10638 json_object_string_add(json_route
,
10641 else if (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
)
10642 json_object_string_add(json_route
,
10646 vty_out(vty
, "%s [%d] area: %pI4",
10647 (or->path_type
== OSPF_PATH_INTER_AREA
10650 or->cost
, &or->u
.std
.area_id
);
10652 vty_out(vty
, "%s%s\n",
10653 (or->u
.std
.flags
& ROUTER_LSA_BORDER
10656 (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
10662 json_nexthop_array
= json_object_new_array();
10663 json_object_object_add(json_route
, "nexthops",
10664 json_nexthop_array
);
10667 for (ALL_LIST_ELEMENTS_RO(or->paths
, pnode
, path
)) {
10669 json_nexthop
= json_object_new_object();
10670 json_object_array_add(
10671 json_nexthop_array
,
10674 if (if_lookup_by_index(path
->ifindex
,
10676 if (path
->nexthop
.s_addr
10679 json_object_string_add(
10682 json_object_string_add(
10684 "directlyAttachedTo",
10690 "%24s directly attached to %s\n",
10698 json_object_string_addf(
10702 json_object_string_add(
10710 "%24s via %pI4, %s\n",
10723 vty_out(vty
, "\n");
10726 static void show_ip_ospf_route_external(struct vty
*vty
, struct ospf
*ospf
,
10727 struct route_table
*rt
,
10730 struct route_node
*rn
;
10731 struct ospf_route
*er
;
10732 struct listnode
*pnode
, *pnnode
;
10733 struct ospf_path
*path
;
10734 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
10735 *json_nexthop
= NULL
;
10739 "============ OSPF external routing table ===========\n");
10741 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
10742 if ((er
= rn
->info
) == NULL
)
10747 snprintfrr(buf1
, sizeof(buf1
), "%pFX", &rn
->p
);
10749 json_route
= json_object_new_object();
10750 json_object_object_add(json
, buf1
, json_route
);
10753 switch (er
->path_type
) {
10754 case OSPF_PATH_TYPE1_EXTERNAL
:
10756 json_object_string_add(json_route
, "routeType",
10758 json_object_int_add(json_route
, "cost",
10760 json_object_int_add(json_route
, "tag",
10764 "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI
10766 buf1
, er
->cost
, er
->u
.ext
.tag
);
10769 case OSPF_PATH_TYPE2_EXTERNAL
:
10771 json_object_string_add(json_route
, "routeType",
10773 json_object_int_add(json_route
, "cost",
10775 json_object_int_add(json_route
, "type2cost",
10776 er
->u
.ext
.type2_cost
);
10777 json_object_int_add(json_route
, "tag",
10781 "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI
10783 buf1
, er
->cost
, er
->u
.ext
.type2_cost
,
10790 json_nexthop_array
= json_object_new_array();
10791 json_object_object_add(json_route
, "nexthops",
10792 json_nexthop_array
);
10795 for (ALL_LIST_ELEMENTS(er
->paths
, pnode
, pnnode
, path
)) {
10797 json_nexthop
= json_object_new_object();
10798 json_object_array_add(json_nexthop_array
,
10802 if (if_lookup_by_index(path
->ifindex
, ospf
->vrf_id
)) {
10803 if (path
->nexthop
.s_addr
== INADDR_ANY
) {
10805 json_object_string_add(
10806 json_nexthop
, "ip",
10808 json_object_string_add(
10810 "directlyAttachedTo",
10816 "%24s directly attached to %s\n",
10824 json_object_string_addf(
10825 json_nexthop
, "ip",
10826 "%pI4", &path
->nexthop
);
10827 json_object_string_add(
10828 json_nexthop
, "via",
10834 "%24s via %pI4, %s\n",
10846 vty_out(vty
, "\n");
10849 static int show_ip_ospf_reachable_routers_common(struct vty
*vty
,
10853 if (ospf
->instance
)
10854 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
10856 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
10858 if (ospf
->all_rtrs
== NULL
) {
10859 vty_out(vty
, "No OSPF reachable router information exist\n");
10860 return CMD_SUCCESS
;
10863 /* Show Router routes. */
10864 show_ip_ospf_route_router(vty
, ospf
, ospf
->all_rtrs
, NULL
);
10866 vty_out(vty
, "\n");
10868 return CMD_SUCCESS
;
10871 DEFUN (show_ip_ospf_reachable_routers
,
10872 show_ip_ospf_reachable_routers_cmd
,
10873 "show ip ospf [vrf <NAME|all>] reachable-routers",
10876 "OSPF information\n"
10879 "Show all the reachable OSPF routers\n")
10881 struct ospf
*ospf
= NULL
;
10882 struct listnode
*node
= NULL
;
10883 char *vrf_name
= NULL
;
10884 bool all_vrf
= false;
10885 int ret
= CMD_SUCCESS
;
10888 uint8_t use_vrf
= 0;
10890 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
10893 bool ospf_output
= false;
10898 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
10899 if (!ospf
->oi_running
)
10902 ospf_output
= true;
10903 ret
= show_ip_ospf_reachable_routers_common(
10904 vty
, ospf
, use_vrf
);
10908 vty_out(vty
, "%% OSPF instance not found\n");
10910 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
10911 if (ospf
== NULL
|| !ospf
->oi_running
) {
10912 vty_out(vty
, "%% OSPF instance not found\n");
10913 return CMD_SUCCESS
;
10916 ret
= show_ip_ospf_reachable_routers_common(vty
, ospf
,
10920 /* Display default ospf (instance 0) info */
10921 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
10922 if (ospf
== NULL
|| !ospf
->oi_running
) {
10923 vty_out(vty
, "%% OSPF instance not found\n");
10924 return CMD_SUCCESS
;
10927 ret
= show_ip_ospf_reachable_routers_common(vty
, ospf
, use_vrf
);
10933 DEFUN (show_ip_ospf_instance_reachable_routers
,
10934 show_ip_ospf_instance_reachable_routers_cmd
,
10935 "show ip ospf (1-65535) reachable-routers",
10938 "OSPF information\n"
10940 "Show all the reachable OSPF routers\n")
10942 int idx_number
= 3;
10944 unsigned short instance
= 0;
10946 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
10947 if (instance
!= ospf_instance
)
10948 return CMD_NOT_MY_INSTANCE
;
10950 ospf
= ospf_lookup_instance(instance
);
10951 if (!ospf
|| !ospf
->oi_running
)
10952 return CMD_SUCCESS
;
10954 return show_ip_ospf_reachable_routers_common(vty
, ospf
, 0);
10957 static int show_ip_ospf_border_routers_common(struct vty
*vty
,
10962 json_object
*json_vrf
= NULL
;
10963 json_object
*json_router
= NULL
;
10967 json_vrf
= json_object_new_object();
10970 json_router
= json_object_new_object();
10973 if (ospf
->instance
) {
10975 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
10977 json_object_int_add(json_vrf
, "ospfInstance",
10981 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
10983 if (ospf
->new_table
== NULL
) {
10985 vty_out(vty
, "No OSPF routing information exist\n");
10987 json_object_free(json_router
);
10989 json_object_free(json_vrf
);
10991 return CMD_SUCCESS
;
10994 /* Show Network routes.
10995 show_ip_ospf_route_network (vty, ospf->new_table); */
10997 /* Show Router routes. */
10998 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, json_router
);
11001 json_object_object_add(json_vrf
, "routers", json_router
);
11003 if (ospf
->vrf_id
== VRF_DEFAULT
)
11004 json_object_object_add(json
, "default",
11007 json_object_object_add(json
, ospf
->name
,
11011 vty_out(vty
, "\n");
11014 return CMD_SUCCESS
;
11017 DEFPY (show_ip_ospf_border_routers
,
11018 show_ip_ospf_border_routers_cmd
,
11019 "show ip ospf [vrf <NAME|all>] border-routers [json]",
11022 "OSPF information\n"
11025 "Show all the ABR's and ASBR's\n"
11028 struct ospf
*ospf
= NULL
;
11029 struct listnode
*node
= NULL
;
11030 char *vrf_name
= NULL
;
11031 bool all_vrf
= false;
11032 int ret
= CMD_SUCCESS
;
11035 uint8_t use_vrf
= 0;
11036 bool uj
= use_json(argc
, argv
);
11037 json_object
*json
= NULL
;
11040 json
= json_object_new_object();
11042 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11045 bool ospf_output
= false;
11050 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11051 if (!ospf
->oi_running
)
11054 ospf_output
= true;
11055 ret
= show_ip_ospf_border_routers_common(
11056 vty
, ospf
, use_vrf
, json
);
11060 vty_json(vty
, json
);
11061 else if (!ospf_output
)
11062 vty_out(vty
, "%% OSPF is not enabled\n");
11066 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11067 if (ospf
== NULL
|| !ospf
->oi_running
) {
11069 vty_json(vty
, json
);
11072 "%% OSPF is not enabled in vrf %s\n",
11075 return CMD_SUCCESS
;
11079 /* Display default ospf (instance 0) info */
11080 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11081 if (ospf
== NULL
|| !ospf
->oi_running
) {
11083 vty_json(vty
, json
);
11086 "%% OSPF is not enabled in vrf default\n");
11088 return CMD_SUCCESS
;
11093 ret
= show_ip_ospf_border_routers_common(vty
, ospf
, use_vrf
,
11096 vty_json(vty
, json
);
11102 DEFUN (show_ip_ospf_instance_border_routers
,
11103 show_ip_ospf_instance_border_routers_cmd
,
11104 "show ip ospf (1-65535) border-routers",
11107 "OSPF information\n"
11109 "Show all the ABR's and ASBR's\n")
11111 int idx_number
= 3;
11113 unsigned short instance
= 0;
11115 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
11116 if (instance
!= ospf_instance
)
11117 return CMD_NOT_MY_INSTANCE
;
11119 ospf
= ospf_lookup_instance(instance
);
11120 if (!ospf
|| !ospf
->oi_running
)
11121 return CMD_SUCCESS
;
11123 return show_ip_ospf_border_routers_common(vty
, ospf
, 0, NULL
);
11126 static int show_ip_ospf_route_common(struct vty
*vty
, struct ospf
*ospf
,
11127 json_object
*json
, uint8_t use_vrf
)
11129 json_object
*json_vrf
= NULL
;
11131 if (ospf
->instance
)
11132 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
11137 json_vrf
= json_object_new_object();
11142 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
11144 if (ospf
->new_table
== NULL
) {
11147 json_object_free(json_vrf
);
11149 vty_out(vty
, "No OSPF routing information exist\n");
11151 return CMD_SUCCESS
;
11154 /* Show Network routes. */
11155 show_ip_ospf_route_network(vty
, ospf
, ospf
->new_table
, json_vrf
);
11157 /* Show Router routes. */
11158 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, json_vrf
);
11160 /* Show Router routes. */
11161 if (ospf
->all_rtrs
)
11162 show_ip_ospf_route_router(vty
, ospf
, ospf
->all_rtrs
, json_vrf
);
11164 /* Show AS External routes. */
11165 show_ip_ospf_route_external(vty
, ospf
, ospf
->old_external_route
,
11170 // json_object_object_add(json_vrf, "areas",
11172 json_object_object_add(json
, ospf_get_name(ospf
),
11176 vty_out(vty
, "\n");
11179 return CMD_SUCCESS
;
11182 DEFUN (show_ip_ospf_route
,
11183 show_ip_ospf_route_cmd
,
11184 "show ip ospf [vrf <NAME|all>] route [json]",
11187 "OSPF information\n"
11190 "OSPF routing table\n"
11193 struct ospf
*ospf
= NULL
;
11194 struct listnode
*node
= NULL
;
11195 char *vrf_name
= NULL
;
11196 bool all_vrf
= false;
11197 int ret
= CMD_SUCCESS
;
11200 uint8_t use_vrf
= 0;
11201 bool uj
= use_json(argc
, argv
);
11202 json_object
*json
= NULL
;
11205 json
= json_object_new_object();
11207 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11209 /* vrf input is provided could be all or specific vrf*/
11211 bool ospf_output
= false;
11216 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11217 if (!ospf
->oi_running
)
11219 ospf_output
= true;
11220 ret
= show_ip_ospf_route_common(vty
, ospf
, json
,
11225 /* Keep Non-pretty format */
11226 vty_json(vty
, json
);
11227 } else if (!ospf_output
)
11228 vty_out(vty
, "%% OSPF is not enabled\n");
11232 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11233 if (ospf
== NULL
|| !ospf
->oi_running
) {
11235 vty_json(vty
, json
);
11238 "%% OSPF is not enabled in vrf %s\n",
11241 return CMD_SUCCESS
;
11244 /* Display default ospf (instance 0) info */
11245 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11246 if (ospf
== NULL
|| !ospf
->oi_running
) {
11248 vty_json(vty
, json
);
11251 "%% OSPF is not enabled in vrf default\n");
11253 return CMD_SUCCESS
;
11258 ret
= show_ip_ospf_route_common(vty
, ospf
, json
, use_vrf
);
11259 /* Keep Non-pretty format */
11261 vty_out(vty
, "%s\n",
11262 json_object_to_json_string_ext(
11263 json
, JSON_C_TO_STRING_NOSLASHESCAPE
));
11267 json_object_free(json
);
11272 DEFUN (show_ip_ospf_instance_route
,
11273 show_ip_ospf_instance_route_cmd
,
11274 "show ip ospf (1-65535) route",
11277 "OSPF information\n"
11279 "OSPF routing table\n")
11281 int idx_number
= 3;
11283 unsigned short instance
= 0;
11285 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
11286 if (instance
!= ospf_instance
)
11287 return CMD_NOT_MY_INSTANCE
;
11289 ospf
= ospf_lookup_instance(instance
);
11290 if (!ospf
|| !ospf
->oi_running
)
11291 return CMD_SUCCESS
;
11293 return show_ip_ospf_route_common(vty
, ospf
, NULL
, 0);
11297 DEFUN (show_ip_ospf_vrfs
,
11298 show_ip_ospf_vrfs_cmd
,
11299 "show ip ospf vrfs [json]",
11302 "OSPF information\n"
11303 "Show OSPF VRFs \n"
11306 bool uj
= use_json(argc
, argv
);
11307 json_object
*json
= NULL
;
11308 json_object
*json_vrfs
= NULL
;
11309 struct ospf
*ospf
= NULL
;
11310 struct listnode
*node
= NULL
;
11312 static const char header
[] = "Name Id RouterId ";
11315 json
= json_object_new_object();
11316 json_vrfs
= json_object_new_object();
11319 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11320 json_object
*json_vrf
= NULL
;
11321 const char *name
= NULL
;
11322 int64_t vrf_id_ui
= 0;
11326 if (!uj
&& count
== 1)
11327 vty_out(vty
, "%s\n", header
);
11329 json_vrf
= json_object_new_object();
11331 name
= ospf_get_name(ospf
);
11333 vrf_id_ui
= (ospf
->vrf_id
== VRF_UNKNOWN
)
11335 : (int64_t)ospf
->vrf_id
;
11338 json_object_int_add(json_vrf
, "vrfId", vrf_id_ui
);
11339 json_object_string_addf(json_vrf
, "routerId", "%pI4",
11342 json_object_object_add(json_vrfs
, name
, json_vrf
);
11345 vty_out(vty
, "%-25s %-5d %-16pI4 \n", name
,
11346 ospf
->vrf_id
, &ospf
->router_id
);
11351 json_object_object_add(json
, "vrfs", json_vrfs
);
11352 json_object_int_add(json
, "totalVrfs", count
);
11354 vty_json(vty
, json
);
11357 vty_out(vty
, "\nTotal number of OSPF VRFs: %d\n",
11361 return CMD_SUCCESS
;
11363 DEFPY (clear_ip_ospf_neighbor
,
11364 clear_ip_ospf_neighbor_cmd
,
11365 "clear ip ospf [(1-65535)]$instance neighbor [A.B.C.D$nbr_id]",
11368 "OSPF information\n"
11370 "Reset OSPF Neighbor\n"
11373 struct listnode
*node
;
11374 struct ospf
*ospf
= NULL
;
11376 /* If user does not specify the arguments,
11377 * instance = 0 and nbr_id = 0.0.0.0
11379 if (instance
!= 0) {
11380 /* This means clear only the particular ospf process */
11381 if (instance
!= ospf_instance
)
11382 return CMD_NOT_MY_INSTANCE
;
11385 /* Clear all the ospf processes */
11386 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11387 if (!ospf
->oi_running
)
11390 if (nbr_id_str
&& IPV4_ADDR_SAME(&ospf
->router_id
, &nbr_id
)) {
11391 vty_out(vty
, "Self router-id is not allowed.\r\n ");
11392 return CMD_SUCCESS
;
11395 ospf_neighbor_reset(ospf
, nbr_id
, nbr_id_str
);
11398 return CMD_SUCCESS
;
11401 DEFPY (clear_ip_ospf_process
,
11402 clear_ip_ospf_process_cmd
,
11403 "clear ip ospf [(1-65535)]$instance process",
11406 "OSPF information\n"
11408 "Reset OSPF Process\n")
11410 struct listnode
*node
;
11411 struct ospf
*ospf
= NULL
;
11413 /* Check if instance is not passed as an argument */
11414 if (instance
!= 0) {
11415 /* This means clear only the particular ospf process */
11416 if (instance
!= ospf_instance
)
11417 return CMD_NOT_MY_INSTANCE
;
11420 /* Clear all the ospf processes */
11421 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11422 if (!ospf
->oi_running
)
11425 ospf_process_reset(ospf
);
11428 return CMD_SUCCESS
;
11431 static const char *const ospf_abr_type_str
[] = {
11432 "unknown", "standard", "ibm", "cisco", "shortcut"
11435 static const char *const ospf_shortcut_mode_str
[] = {
11436 "default", "enable", "disable"
11438 static int ospf_vty_external_rt_walkcb(struct hash_bucket
*bucket
,
11441 struct external_info
*ei
= bucket
->data
;
11442 struct vty
*vty
= (struct vty
*)arg
;
11443 static unsigned int count
;
11445 vty_out(vty
, "%-4pI4/%d, ", &ei
->p
.prefix
, ei
->p
.prefixlen
);
11448 if (count
% 5 == 0)
11449 vty_out(vty
, "\n");
11451 if (OSPF_EXTERNAL_RT_COUNT(ei
->aggr_route
) == count
)
11454 return HASHWALK_CONTINUE
;
11457 static int ospf_json_external_rt_walkcb(struct hash_bucket
*bucket
,
11460 struct external_info
*ei
= bucket
->data
;
11461 struct json_object
*json
= (struct json_object
*)arg
;
11462 char buf
[PREFIX2STR_BUFFER
];
11464 static unsigned int count
;
11466 prefix2str(&ei
->p
, buf
, sizeof(buf
));
11468 snprintf(exnalbuf
, 20, "Exnl Addr-%d", count
);
11470 json_object_string_add(json
, exnalbuf
, buf
);
11474 if (OSPF_EXTERNAL_RT_COUNT(ei
->aggr_route
) == count
)
11477 return HASHWALK_CONTINUE
;
11480 static int ospf_show_summary_address(struct vty
*vty
, struct ospf
*ospf
,
11481 uint8_t use_vrf
, json_object
*json
,
11482 bool uj
, bool detail
)
11484 struct route_node
*rn
;
11485 json_object
*json_vrf
= NULL
;
11488 static char header
[] =
11489 "Summary-address Metric-type Metric Tag External_Rt_count\n";
11491 mtype
= metric_type(ospf
, 0, ospf
->instance
);
11492 mval
= metric_value(ospf
, 0, ospf
->instance
);
11495 vty_out(vty
, "%s\n", header
);
11499 json_vrf
= json_object_new_object();
11504 if (ospf
->instance
) {
11506 json_object_int_add(json
, "ospfInstance",
11509 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
11512 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
11515 vty_out(vty
, "aggregation delay interval :%u(in seconds)\n\n",
11516 ospf
->aggr_delay_interval
);
11518 json_object_int_add(json_vrf
, "aggregationDelayInterval",
11519 ospf
->aggr_delay_interval
);
11522 for (rn
= route_top(ospf
->rt_aggr_tbl
); rn
; rn
= route_next(rn
))
11524 struct ospf_external_aggr_rt
*aggr
= rn
->info
;
11525 json_object
*json_aggr
= NULL
;
11526 char buf
[PREFIX2STR_BUFFER
];
11528 prefix2str(&aggr
->p
, buf
, sizeof(buf
));
11532 json_aggr
= json_object_new_object();
11534 json_object_object_add(json_vrf
, buf
,
11536 json_object_string_add(json_aggr
,
11537 "summaryAddress", buf
);
11538 json_object_string_add(
11539 json_aggr
, "metricType",
11540 (mtype
== EXTERNAL_METRIC_TYPE_1
)
11544 json_object_int_add(json_aggr
, "metric", mval
);
11545 json_object_int_add(json_aggr
, "tag",
11547 json_object_int_add(
11548 json_aggr
, "externalRouteCount",
11549 OSPF_EXTERNAL_RT_COUNT(aggr
));
11551 if (OSPF_EXTERNAL_RT_COUNT(aggr
) && detail
) {
11553 aggr
->match_extnl_hash
,
11554 ospf_json_external_rt_walkcb
,
11559 vty_out(vty
, "%-20s", buf
);
11561 (mtype
== EXTERNAL_METRIC_TYPE_1
)
11562 ? vty_out(vty
, "%-16s", "E1")
11563 : vty_out(vty
, "%-16s", "E2");
11564 vty_out(vty
, "%-11d", mval
);
11566 vty_out(vty
, "%-12u", aggr
->tag
);
11568 vty_out(vty
, "%-5ld\n",
11569 OSPF_EXTERNAL_RT_COUNT(aggr
));
11571 if (OSPF_EXTERNAL_RT_COUNT(aggr
) && detail
) {
11573 "Matched External routes:\n");
11575 aggr
->match_extnl_hash
,
11576 ospf_vty_external_rt_walkcb
,
11578 vty_out(vty
, "\n");
11581 vty_out(vty
, "\n");
11587 json_object_object_add(json
, ospf_get_name(ospf
),
11590 vty_out(vty
, "\n");
11592 return CMD_SUCCESS
;
11595 DEFUN (show_ip_ospf_external_aggregator
,
11596 show_ip_ospf_external_aggregator_cmd
,
11597 "show ip ospf [vrf <NAME|all>] summary-address [detail] [json]",
11599 "OSPF information\n"
11602 "Show external summary addresses\n"
11603 "Detailed information\n"
11606 char *vrf_name
= NULL
;
11607 bool all_vrf
= false;
11608 int ret
= CMD_SUCCESS
;
11611 uint8_t use_vrf
= 0;
11612 bool uj
= use_json(argc
, argv
);
11613 struct ospf
*ospf
= NULL
;
11614 json_object
*json
= NULL
;
11615 struct listnode
*node
= NULL
;
11617 bool detail
= false;
11619 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11621 if (argv_find(argv
, argc
, "detail", &idx
))
11625 json
= json_object_new_object();
11627 /* vrf input is provided */
11631 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11632 if (!ospf
->oi_running
)
11634 ret
= ospf_show_summary_address(
11635 vty
, ospf
, use_vrf
, json
, uj
, detail
);
11639 vty_json(vty
, json
);
11644 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11646 if (ospf
== NULL
|| !ospf
->oi_running
) {
11648 vty_json(vty
, json
);
11651 "%% OSPF is not enabled in vrf %s\n",
11654 return CMD_SUCCESS
;
11656 ospf_show_summary_address(vty
, ospf
, use_vrf
, json
, uj
, detail
);
11660 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11661 if (ospf
== NULL
|| !ospf
->oi_running
) {
11663 vty_json(vty
, json
);
11666 "%% OSPF is not enabled in vrf default\n");
11668 return CMD_SUCCESS
;
11671 ospf_show_summary_address(vty
, ospf
, use_vrf
, json
, uj
, detail
);
11675 vty_json(vty
, json
);
11676 return CMD_SUCCESS
;
11679 static const char *const ospf_int_type_str
[] = {
11680 "unknown", /* should never be used. */
11684 "point-to-multipoint",
11685 "virtual-link", /* should never be used. */
11689 static const char *interface_config_auth_str(struct ospf_if_params
*params
)
11691 if (!OSPF_IF_PARAM_CONFIGURED(params
, auth_type
)
11692 || params
->auth_type
== OSPF_AUTH_NOTSET
)
11695 /* Translation tables are not that much help
11696 * here due to syntax
11697 * of the simple option */
11698 switch (params
->auth_type
) {
11700 case OSPF_AUTH_NULL
:
11703 case OSPF_AUTH_SIMPLE
:
11706 case OSPF_AUTH_CRYPTOGRAPHIC
:
11707 return " message-digest";
11713 static int config_write_interface_one(struct vty
*vty
, struct vrf
*vrf
)
11715 struct listnode
*node
;
11716 struct interface
*ifp
;
11717 struct crypt_key
*ck
;
11718 struct route_node
*rn
= NULL
;
11719 struct ospf_if_params
*params
;
11720 const char *auth_str
;
11723 FOR_ALL_INTERFACES (vrf
, ifp
) {
11725 if (memcmp(ifp
->name
, "VLINK", 5) == 0)
11728 if_vty_config_start(vty
, ifp
);
11731 vty_out(vty
, " description %s\n", ifp
->desc
);
11735 params
= IF_DEF_PARAMS(ifp
);
11738 /* Interface Network print. */
11739 if (OSPF_IF_PARAM_CONFIGURED(params
, type
)
11740 && params
->type
!= OSPF_IFTYPE_LOOPBACK
) {
11741 if (params
->type
!= ospf_default_iftype(ifp
)) {
11742 vty_out(vty
, " ip ospf network %s",
11746 == OSPF_IFTYPE_POINTOPOINT
11747 && params
->ptp_dmvpn
)
11748 vty_out(vty
, " dmvpn");
11749 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11750 vty_out(vty
, " %pI4",
11752 vty_out(vty
, "\n");
11756 /* OSPF interface authentication print */
11757 auth_str
= interface_config_auth_str(params
);
11759 vty_out(vty
, " ip ospf authentication%s",
11761 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11762 vty_out(vty
, " %pI4",
11764 vty_out(vty
, "\n");
11767 /* Simple Authentication Password print. */
11768 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_simple
)
11769 && params
->auth_simple
[0] != '\0') {
11770 vty_out(vty
, " ip ospf authentication-key %s",
11771 params
->auth_simple
);
11772 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11773 vty_out(vty
, " %pI4",
11775 vty_out(vty
, "\n");
11778 /* Cryptographic Authentication Key print. */
11779 if (params
&& params
->auth_crypt
) {
11780 for (ALL_LIST_ELEMENTS_RO(params
->auth_crypt
,
11783 " ip ospf message-digest-key %d md5 %s",
11784 ck
->key_id
, ck
->auth_key
);
11785 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11786 vty_out(vty
, " %pI4",
11788 vty_out(vty
, "\n");
11792 /* Interface Output Cost print. */
11793 if (OSPF_IF_PARAM_CONFIGURED(params
, output_cost_cmd
)) {
11794 vty_out(vty
, " ip ospf cost %u",
11795 params
->output_cost_cmd
);
11796 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11797 vty_out(vty
, " %pI4",
11799 vty_out(vty
, "\n");
11802 /* Hello Interval print. */
11803 if (OSPF_IF_PARAM_CONFIGURED(params
, v_hello
)
11804 && params
->v_hello
!= OSPF_HELLO_INTERVAL_DEFAULT
) {
11805 vty_out(vty
, " ip ospf hello-interval %u",
11807 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11808 vty_out(vty
, " %pI4",
11810 vty_out(vty
, "\n");
11814 /* Router Dead Interval print. */
11815 if (OSPF_IF_PARAM_CONFIGURED(params
, v_wait
)
11816 && params
->is_v_wait_set
) {
11817 vty_out(vty
, " ip ospf dead-interval ");
11820 if (OSPF_IF_PARAM_CONFIGURED(params
,
11823 "minimal hello-multiplier %d",
11824 params
->fast_hello
);
11826 vty_out(vty
, "%u", params
->v_wait
);
11828 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11829 vty_out(vty
, " %pI4",
11831 vty_out(vty
, "\n");
11834 /* Router Priority print. */
11835 if (OSPF_IF_PARAM_CONFIGURED(params
, priority
)
11836 && params
->priority
11837 != OSPF_ROUTER_PRIORITY_DEFAULT
) {
11838 vty_out(vty
, " ip ospf priority %u",
11840 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11841 vty_out(vty
, " %pI4",
11843 vty_out(vty
, "\n");
11846 /* Retransmit Interval print. */
11847 if (OSPF_IF_PARAM_CONFIGURED(params
,
11848 retransmit_interval
)
11849 && params
->retransmit_interval
11850 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
) {
11851 vty_out(vty
, " ip ospf retransmit-interval %u",
11852 params
->retransmit_interval
);
11853 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11854 vty_out(vty
, " %pI4",
11856 vty_out(vty
, "\n");
11859 /* Transmit Delay print. */
11860 if (OSPF_IF_PARAM_CONFIGURED(params
, transmit_delay
)
11861 && params
->transmit_delay
11862 != OSPF_TRANSMIT_DELAY_DEFAULT
) {
11863 vty_out(vty
, " ip ospf transmit-delay %u",
11864 params
->transmit_delay
);
11865 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11866 vty_out(vty
, " %pI4",
11868 vty_out(vty
, "\n");
11872 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
11874 vty_out(vty
, " ip ospf %d",
11877 vty_out(vty
, " ip ospf");
11879 char buf
[INET_ADDRSTRLEN
];
11881 area_id2str(buf
, sizeof(buf
), ¶ms
->if_area
,
11882 params
->if_area_id_fmt
);
11883 vty_out(vty
, " area %s", buf
);
11884 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11885 vty_out(vty
, " %pI4",
11887 vty_out(vty
, "\n");
11891 if (params
&& params
->bfd_config
)
11892 ospf_bfd_write_config(vty
, params
);
11894 /* MTU ignore print. */
11895 if (OSPF_IF_PARAM_CONFIGURED(params
, mtu_ignore
)
11896 && params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
) {
11897 if (params
->mtu_ignore
== 0)
11898 vty_out(vty
, " no ip ospf mtu-ignore");
11900 vty_out(vty
, " ip ospf mtu-ignore");
11901 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11902 vty_out(vty
, " %pI4",
11904 vty_out(vty
, "\n");
11907 if (OSPF_IF_PARAM_CONFIGURED(params
,
11908 passive_interface
)) {
11909 vty_out(vty
, " %sip ospf passive",
11910 params
->passive_interface
11914 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11915 vty_out(vty
, " %pI4", &rn
->p
.u
.prefix4
);
11916 vty_out(vty
, "\n");
11919 /* LDP-Sync print */
11920 if (params
&& params
->ldp_sync_info
)
11921 ospf_ldp_sync_if_write_config(vty
, params
);
11925 rn
= route_top(IF_OIFS_PARAMS(ifp
));
11927 rn
= route_next(rn
);
11932 if (params
!= NULL
)
11937 ospf_opaque_config_write_if(vty
, ifp
);
11939 if_vty_config_end(vty
);
11945 /* Configuration write function for ospfd. */
11946 static int config_write_interface(struct vty
*vty
)
11949 struct vrf
*vrf
= NULL
;
11951 /* Display all VRF aware OSPF interface configuration */
11952 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
11953 write
+= config_write_interface_one(vty
, vrf
);
11959 static int config_write_network_area(struct vty
*vty
, struct ospf
*ospf
)
11961 struct route_node
*rn
;
11962 char buf
[INET_ADDRSTRLEN
];
11964 /* `network area' print. */
11965 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
))
11967 struct ospf_network
*n
= rn
->info
;
11969 /* Create Area ID string by specified Area ID format. */
11970 if (n
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
11971 inet_ntop(AF_INET
, &n
->area_id
, buf
,
11974 snprintf(buf
, sizeof(buf
), "%lu",
11975 (unsigned long int)ntohl(
11976 n
->area_id
.s_addr
));
11978 /* Network print. */
11979 vty_out(vty
, " network %pFX area %s\n", &rn
->p
, buf
);
11985 static int config_write_ospf_area(struct vty
*vty
, struct ospf
*ospf
)
11987 struct listnode
*node
;
11988 struct ospf_area
*area
;
11989 char buf
[INET_ADDRSTRLEN
];
11991 /* Area configuration print. */
11992 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
11993 struct route_node
*rn1
;
11995 area_id2str(buf
, sizeof(buf
), &area
->area_id
,
11996 area
->area_id_fmt
);
11998 if (area
->auth_type
!= OSPF_AUTH_NULL
) {
11999 if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
12000 vty_out(vty
, " area %s authentication\n", buf
);
12003 " area %s authentication message-digest\n",
12007 if (area
->shortcut_configured
!= OSPF_SHORTCUT_DEFAULT
)
12008 vty_out(vty
, " area %s shortcut %s\n", buf
,
12009 ospf_shortcut_mode_str
12010 [area
->shortcut_configured
]);
12012 if ((area
->external_routing
== OSPF_AREA_STUB
)
12013 || (area
->external_routing
== OSPF_AREA_NSSA
)) {
12014 if (area
->external_routing
== OSPF_AREA_STUB
) {
12015 vty_out(vty
, " area %s stub", buf
);
12016 if (area
->no_summary
)
12017 vty_out(vty
, " no-summary\n");
12018 vty_out(vty
, "\n");
12019 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
12020 vty_out(vty
, " area %s nssa", buf
);
12022 switch (area
->NSSATranslatorRole
) {
12023 case OSPF_NSSA_ROLE_NEVER
:
12024 vty_out(vty
, " translate-never");
12026 case OSPF_NSSA_ROLE_ALWAYS
:
12027 vty_out(vty
, " translate-always");
12029 case OSPF_NSSA_ROLE_CANDIDATE
:
12033 if (area
->nssa_default_originate
.enabled
) {
12035 " default-information-originate");
12036 if (area
->nssa_default_originate
12037 .metric_value
!= -1)
12038 vty_out(vty
, " metric %d",
12039 area
->nssa_default_originate
12041 if (area
->nssa_default_originate
12043 DEFAULT_METRIC_TYPE
)
12044 vty_out(vty
, " metric-type 1");
12047 if (area
->no_summary
)
12048 vty_out(vty
, " no-summary");
12049 if (area
->suppress_fa
)
12050 vty_out(vty
, " suppress-fa");
12051 vty_out(vty
, "\n");
12053 for (rn1
= route_top(area
->nssa_ranges
); rn1
;
12054 rn1
= route_next(rn1
)) {
12055 struct ospf_area_range
*range
;
12061 vty_out(vty
, " area %s nssa range %pFX",
12064 if (range
->cost_config
!=
12065 OSPF_AREA_RANGE_COST_UNSPEC
)
12066 vty_out(vty
, " cost %u",
12067 range
->cost_config
);
12071 OSPF_AREA_RANGE_ADVERTISE
))
12072 vty_out(vty
, " not-advertise");
12074 vty_out(vty
, "\n");
12078 if (area
->default_cost
!= 1)
12079 vty_out(vty
, " area %s default-cost %d\n", buf
,
12080 area
->default_cost
);
12083 for (rn1
= route_top(area
->ranges
); rn1
; rn1
= route_next(rn1
))
12085 struct ospf_area_range
*range
= rn1
->info
;
12087 vty_out(vty
, " area %s range %pFX", buf
,
12090 if (range
->cost_config
12091 != OSPF_AREA_RANGE_COST_UNSPEC
)
12092 vty_out(vty
, " cost %d",
12093 range
->cost_config
);
12095 if (!CHECK_FLAG(range
->flags
,
12096 OSPF_AREA_RANGE_ADVERTISE
))
12097 vty_out(vty
, " not-advertise");
12099 if (CHECK_FLAG(range
->flags
,
12100 OSPF_AREA_RANGE_SUBSTITUTE
))
12101 vty_out(vty
, " substitute %pI4/%d",
12102 &range
->subst_addr
,
12103 range
->subst_masklen
);
12105 vty_out(vty
, "\n");
12108 if (EXPORT_NAME(area
))
12109 vty_out(vty
, " area %s export-list %s\n", buf
,
12110 EXPORT_NAME(area
));
12112 if (IMPORT_NAME(area
))
12113 vty_out(vty
, " area %s import-list %s\n", buf
,
12114 IMPORT_NAME(area
));
12116 if (PREFIX_NAME_IN(area
))
12117 vty_out(vty
, " area %s filter-list prefix %s in\n", buf
,
12118 PREFIX_NAME_IN(area
));
12120 if (PREFIX_NAME_OUT(area
))
12121 vty_out(vty
, " area %s filter-list prefix %s out\n",
12122 buf
, PREFIX_NAME_OUT(area
));
12124 if (area
->fr_info
.configured
)
12125 vty_out(vty
, " area %s flood-reduction\n", buf
);
12131 static int config_write_ospf_nbr_nbma(struct vty
*vty
, struct ospf
*ospf
)
12133 struct ospf_nbr_nbma
*nbr_nbma
;
12134 struct route_node
*rn
;
12136 /* Static Neighbor configuration print. */
12137 for (rn
= route_top(ospf
->nbr_nbma
); rn
; rn
= route_next(rn
))
12138 if ((nbr_nbma
= rn
->info
)) {
12139 vty_out(vty
, " neighbor %pI4", &nbr_nbma
->addr
);
12141 if (nbr_nbma
->priority
12142 != OSPF_NEIGHBOR_PRIORITY_DEFAULT
)
12143 vty_out(vty
, " priority %d",
12144 nbr_nbma
->priority
);
12146 if (nbr_nbma
->v_poll
!= OSPF_POLL_INTERVAL_DEFAULT
)
12147 vty_out(vty
, " poll-interval %d",
12150 vty_out(vty
, "\n");
12156 static int config_write_virtual_link(struct vty
*vty
, struct ospf
*ospf
)
12158 struct listnode
*node
;
12159 struct ospf_vl_data
*vl_data
;
12160 const char *auth_str
;
12161 char buf
[INET_ADDRSTRLEN
];
12163 /* Virtual-Link print */
12164 for (ALL_LIST_ELEMENTS_RO(ospf
->vlinks
, node
, vl_data
)) {
12165 struct listnode
*n2
;
12166 struct crypt_key
*ck
;
12167 struct ospf_interface
*oi
;
12169 if (vl_data
!= NULL
) {
12170 area_id2str(buf
, sizeof(buf
), &vl_data
->vl_area_id
,
12171 vl_data
->vl_area_id_fmt
);
12172 oi
= vl_data
->vl_oi
;
12175 if (OSPF_IF_PARAM(oi
, v_hello
)
12176 != OSPF_HELLO_INTERVAL_DEFAULT
12177 || OSPF_IF_PARAM(oi
, v_wait
)
12178 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
12179 || OSPF_IF_PARAM(oi
, retransmit_interval
)
12180 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
12181 || OSPF_IF_PARAM(oi
, transmit_delay
)
12182 != OSPF_TRANSMIT_DELAY_DEFAULT
)
12184 " area %s virtual-link %pI4 hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n",
12185 buf
, &vl_data
->vl_peer
,
12186 OSPF_IF_PARAM(oi
, v_hello
),
12187 OSPF_IF_PARAM(oi
, retransmit_interval
),
12188 OSPF_IF_PARAM(oi
, transmit_delay
),
12189 OSPF_IF_PARAM(oi
, v_wait
));
12191 vty_out(vty
, " area %s virtual-link %pI4\n", buf
,
12192 &vl_data
->vl_peer
);
12194 auth_str
= interface_config_auth_str(
12195 IF_DEF_PARAMS(oi
->ifp
));
12198 " area %s virtual-link %pI4 authentication%s\n",
12199 buf
, &vl_data
->vl_peer
, auth_str
);
12201 if (IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)->auth_simple
[0]
12204 " area %s virtual-link %pI4 authentication-key %s\n",
12205 buf
, &vl_data
->vl_peer
,
12206 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
12209 for (ALL_LIST_ELEMENTS_RO(
12210 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
12214 " area %s virtual-link %pI4 message-digest-key %d md5 %s\n",
12215 buf
, &vl_data
->vl_peer
,
12216 ck
->key_id
, ck
->auth_key
);
12224 static int config_write_ospf_redistribute(struct vty
*vty
, struct ospf
*ospf
)
12228 /* redistribute print. */
12229 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
12230 struct list
*red_list
;
12231 struct listnode
*node
;
12232 struct ospf_redist
*red
;
12234 red_list
= ospf
->redist
[type
];
12238 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
12239 vty_out(vty
, " redistribute %s",
12240 zebra_route_string(type
));
12242 vty_out(vty
, " %d", red
->instance
);
12244 if (red
->dmetric
.value
>= 0)
12245 vty_out(vty
, " metric %d", red
->dmetric
.value
);
12247 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
12248 vty_out(vty
, " metric-type 1");
12250 if (ROUTEMAP_NAME(red
))
12251 vty_out(vty
, " route-map %s",
12252 ROUTEMAP_NAME(red
));
12254 vty_out(vty
, "\n");
12261 static int ospf_cfg_write_helper_dis_rtr_walkcb(struct hash_bucket
*bucket
,
12264 struct advRtr
*rtr
= bucket
->data
;
12265 struct vty
*vty
= (struct vty
*)arg
;
12267 vty_out(vty
, " graceful-restart helper enable %pI4\n",
12269 return HASHWALK_CONTINUE
;
12272 static void config_write_ospf_gr(struct vty
*vty
, struct ospf
*ospf
)
12274 if (!ospf
->gr_info
.restart_support
)
12277 if (ospf
->gr_info
.grace_period
== OSPF_DFLT_GRACE_INTERVAL
)
12278 vty_out(vty
, " graceful-restart\n");
12280 vty_out(vty
, " graceful-restart grace-period %u\n",
12281 ospf
->gr_info
.grace_period
);
12284 static int config_write_ospf_gr_helper(struct vty
*vty
, struct ospf
*ospf
)
12286 if (ospf
->is_helper_supported
)
12287 vty_out(vty
, " graceful-restart helper enable\n");
12289 if (!ospf
->strict_lsa_check
)
12291 " no graceful-restart helper strict-lsa-checking\n");
12293 if (ospf
->only_planned_restart
)
12294 vty_out(vty
, " graceful-restart helper planned-only\n");
12296 if (ospf
->supported_grace_time
!= OSPF_MAX_GRACE_INTERVAL
)
12298 " graceful-restart helper supported-grace-time %d\n",
12299 ospf
->supported_grace_time
);
12301 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf
)) {
12302 hash_walk(ospf
->enable_rtr_list
,
12303 ospf_cfg_write_helper_dis_rtr_walkcb
, vty
);
12308 static int config_write_ospf_external_aggregator(struct vty
*vty
,
12311 struct route_node
*rn
;
12313 if (ospf
->aggr_delay_interval
!= OSPF_EXTL_AGGR_DEFAULT_DELAY
)
12314 vty_out(vty
, " aggregation timer %u\n",
12315 ospf
->aggr_delay_interval
);
12317 /* print 'summary-address A.B.C.D/M' */
12318 for (rn
= route_top(ospf
->rt_aggr_tbl
); rn
; rn
= route_next(rn
))
12320 struct ospf_external_aggr_rt
*aggr
= rn
->info
;
12322 vty_out(vty
, " summary-address %pI4/%d",
12323 &aggr
->p
.prefix
, aggr
->p
.prefixlen
);
12325 vty_out(vty
, " tag %u", aggr
->tag
);
12327 if (CHECK_FLAG(aggr
->flags
,
12328 OSPF_EXTERNAL_AGGRT_NO_ADVERTISE
))
12329 vty_out(vty
, " no-advertise");
12331 vty_out(vty
, "\n");
12337 static int config_write_ospf_default_metric(struct vty
*vty
, struct ospf
*ospf
)
12339 if (ospf
->default_metric
!= -1)
12340 vty_out(vty
, " default-metric %d\n", ospf
->default_metric
);
12344 static int config_write_ospf_distribute(struct vty
*vty
, struct ospf
*ospf
)
12347 struct ospf_redist
*red
;
12350 /* distribute-list print. */
12351 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
12352 if (DISTRIBUTE_NAME(ospf
, type
))
12353 vty_out(vty
, " distribute-list %s out %s\n",
12354 DISTRIBUTE_NAME(ospf
, type
),
12355 zebra_route_string(type
));
12357 /* default-information print. */
12358 if (ospf
->default_originate
!= DEFAULT_ORIGINATE_NONE
) {
12359 vty_out(vty
, " default-information originate");
12360 if (ospf
->default_originate
== DEFAULT_ORIGINATE_ALWAYS
)
12361 vty_out(vty
, " always");
12363 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
12365 if (red
->dmetric
.value
>= 0)
12366 vty_out(vty
, " metric %d",
12367 red
->dmetric
.value
);
12369 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
12370 vty_out(vty
, " metric-type 1");
12372 if (ROUTEMAP_NAME(red
))
12373 vty_out(vty
, " route-map %s",
12374 ROUTEMAP_NAME(red
));
12377 vty_out(vty
, "\n");
12384 static int config_write_ospf_distance(struct vty
*vty
, struct ospf
*ospf
)
12386 struct route_node
*rn
;
12387 struct ospf_distance
*odistance
;
12389 if (ospf
->distance_all
)
12390 vty_out(vty
, " distance %d\n", ospf
->distance_all
);
12392 if (ospf
->distance_intra
|| ospf
->distance_inter
12393 || ospf
->distance_external
) {
12394 vty_out(vty
, " distance ospf");
12396 if (ospf
->distance_intra
)
12397 vty_out(vty
, " intra-area %d", ospf
->distance_intra
);
12398 if (ospf
->distance_inter
)
12399 vty_out(vty
, " inter-area %d", ospf
->distance_inter
);
12400 if (ospf
->distance_external
)
12401 vty_out(vty
, " external %d", ospf
->distance_external
);
12403 vty_out(vty
, "\n");
12406 for (rn
= route_top(ospf
->distance_table
); rn
; rn
= route_next(rn
))
12407 if ((odistance
= rn
->info
) != NULL
) {
12408 vty_out(vty
, " distance %d %pFX %s\n",
12409 odistance
->distance
, &rn
->p
,
12410 odistance
->access_list
? odistance
->access_list
12416 static int ospf_config_write_one(struct vty
*vty
, struct ospf
*ospf
)
12420 /* `router ospf' print. */
12421 if (ospf
->instance
&& strcmp(ospf
->name
, VRF_DEFAULT_NAME
)) {
12422 vty_out(vty
, "router ospf %d vrf %s\n", ospf
->instance
,
12424 } else if (ospf
->instance
) {
12425 vty_out(vty
, "router ospf %d\n", ospf
->instance
);
12426 } else if (strcmp(ospf
->name
, VRF_DEFAULT_NAME
)) {
12427 vty_out(vty
, "router ospf vrf %s\n", ospf
->name
);
12429 vty_out(vty
, "router ospf\n");
12431 if (!ospf
->networks
) {
12436 /* Router ID print. */
12437 if (ospf
->router_id_static
.s_addr
!= INADDR_ANY
)
12438 vty_out(vty
, " ospf router-id %pI4\n",
12439 &ospf
->router_id_static
);
12441 /* zebra opaque attributes configuration. */
12442 if (CHECK_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
))
12443 vty_out(vty
, " ospf send-extra-data zebra\n");
12445 /* ABR type print. */
12446 if (ospf
->abr_type
!= OSPF_ABR_DEFAULT
)
12447 vty_out(vty
, " ospf abr-type %s\n",
12448 ospf_abr_type_str
[ospf
->abr_type
]);
12450 /* log-adjacency-changes flag print. */
12451 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
12452 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
))
12453 vty_out(vty
, " log-adjacency-changes detail\n");
12454 else if (!SAVE_OSPF_LOG_ADJACENCY_CHANGES
)
12455 vty_out(vty
, " log-adjacency-changes\n");
12456 } else if (SAVE_OSPF_LOG_ADJACENCY_CHANGES
) {
12457 vty_out(vty
, " no log-adjacency-changes\n");
12460 /* RFC1583 compatibility flag print -- Compatible with CISCO
12462 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
))
12463 vty_out(vty
, " compatible rfc1583\n");
12465 /* auto-cost reference-bandwidth configuration. */
12466 if (ospf
->ref_bandwidth
!= OSPF_DEFAULT_REF_BANDWIDTH
) {
12468 "! Important: ensure reference bandwidth is consistent across all routers\n");
12469 vty_out(vty
, " auto-cost reference-bandwidth %d\n",
12470 ospf
->ref_bandwidth
);
12473 /* SPF timers print. */
12474 if (ospf
->spf_delay
!= OSPF_SPF_DELAY_DEFAULT
12475 || ospf
->spf_holdtime
!= OSPF_SPF_HOLDTIME_DEFAULT
12476 || ospf
->spf_max_holdtime
!= OSPF_SPF_MAX_HOLDTIME_DEFAULT
)
12477 vty_out(vty
, " timers throttle spf %d %d %d\n", ospf
->spf_delay
,
12478 ospf
->spf_holdtime
, ospf
->spf_max_holdtime
);
12480 /* LSA timers print. */
12481 if (ospf
->min_ls_interval
!= OSPF_MIN_LS_INTERVAL
)
12482 vty_out(vty
, " timers throttle lsa all %d\n",
12483 ospf
->min_ls_interval
);
12484 if (ospf
->min_ls_arrival
!= OSPF_MIN_LS_ARRIVAL
)
12485 vty_out(vty
, " timers lsa min-arrival %d\n",
12486 ospf
->min_ls_arrival
);
12488 /* Write multiplier print. */
12489 if (ospf
->write_oi_count
!= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
)
12490 vty_out(vty
, " ospf write-multiplier %d\n",
12491 ospf
->write_oi_count
);
12493 if (ospf
->max_multipath
!= MULTIPATH_NUM
)
12494 vty_out(vty
, " maximum-paths %d\n", ospf
->max_multipath
);
12496 /* Max-metric router-lsa print */
12497 config_write_stub_router(vty
, ospf
);
12499 /* SPF refresh parameters print. */
12500 if (ospf
->lsa_refresh_interval
!= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
12501 vty_out(vty
, " refresh timer %d\n", ospf
->lsa_refresh_interval
);
12503 if (ospf
->fr_configured
)
12504 vty_out(vty
, " flood-reduction\n");
12506 if (!ospf
->intf_socket_enabled
)
12507 vty_out(vty
, " no socket-per-interface\n");
12509 /* Redistribute information print. */
12510 config_write_ospf_redistribute(vty
, ospf
);
12512 /* Graceful Restart print */
12513 config_write_ospf_gr(vty
, ospf
);
12514 config_write_ospf_gr_helper(vty
, ospf
);
12516 /* Print external route aggregation. */
12517 config_write_ospf_external_aggregator(vty
, ospf
);
12519 /* passive-interface print. */
12520 if (ospf
->passive_interface_default
== OSPF_IF_PASSIVE
)
12521 vty_out(vty
, " passive-interface default\n");
12523 /* proactive-arp print. */
12524 if (ospf
->proactive_arp
!= OSPF_PROACTIVE_ARP_DEFAULT
) {
12525 if (ospf
->proactive_arp
)
12526 vty_out(vty
, " proactive-arp\n");
12528 vty_out(vty
, " no proactive-arp\n");
12531 /* TI-LFA print. */
12532 if (ospf
->ti_lfa_enabled
) {
12533 if (ospf
->ti_lfa_protection_type
== OSPF_TI_LFA_NODE_PROTECTION
)
12534 vty_out(vty
, " fast-reroute ti-lfa node-protection\n");
12536 vty_out(vty
, " fast-reroute ti-lfa\n");
12539 /* Network area print. */
12540 config_write_network_area(vty
, ospf
);
12542 /* Area config print. */
12543 config_write_ospf_area(vty
, ospf
);
12545 /* static neighbor print. */
12546 config_write_ospf_nbr_nbma(vty
, ospf
);
12548 /* Virtual-Link print. */
12549 config_write_virtual_link(vty
, ospf
);
12551 /* Default metric configuration. */
12552 config_write_ospf_default_metric(vty
, ospf
);
12554 /* Distribute-list and default-information print. */
12555 config_write_ospf_distribute(vty
, ospf
);
12557 /* Distance configuration. */
12558 config_write_ospf_distance(vty
, ospf
);
12560 ospf_opaque_config_write_router(vty
, ospf
);
12562 /* LDP-Sync print */
12563 ospf_ldp_sync_write_config(vty
, ospf
);
12565 /* Socket buffer sizes */
12566 if (ospf
->recv_sock_bufsize
!= OSPF_DEFAULT_SOCK_BUFSIZE
) {
12567 if (ospf
->send_sock_bufsize
== ospf
->recv_sock_bufsize
)
12568 vty_out(vty
, " socket buffer all %u\n",
12569 ospf
->recv_sock_bufsize
);
12571 vty_out(vty
, " socket buffer recv %u\n",
12572 ospf
->recv_sock_bufsize
);
12575 if (ospf
->send_sock_bufsize
!= OSPF_DEFAULT_SOCK_BUFSIZE
&&
12576 ospf
->send_sock_bufsize
!= ospf
->recv_sock_bufsize
)
12577 vty_out(vty
, " socket buffer send %u\n",
12578 ospf
->send_sock_bufsize
);
12581 vty_out(vty
, "exit\n");
12587 /* OSPF configuration write function. */
12588 static int ospf_config_write(struct vty
*vty
)
12591 struct listnode
*ospf_node
= NULL
;
12594 if (listcount(om
->ospf
) == 0)
12597 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, ospf_node
, ospf
)) {
12598 /* VRF Default check if it is running.
12599 * Upon daemon start, there could be default instance
12600 * in absence of 'router ospf'/oi_running is disabled. */
12601 if (ospf
->vrf_id
== VRF_DEFAULT
&& ospf
->oi_running
)
12602 write
+= ospf_config_write_one(vty
, ospf
);
12603 /* For Non-Default VRF simply display the configuration,
12604 * even if it is not oi_running. */
12605 else if (ospf
->vrf_id
!= VRF_DEFAULT
)
12606 write
+= ospf_config_write_one(vty
, ospf
);
12611 void ospf_vty_show_init(void)
12613 /* "show ip ospf" commands. */
12614 install_element(VIEW_NODE
, &show_ip_ospf_cmd
);
12616 install_element(VIEW_NODE
, &show_ip_ospf_instance_cmd
);
12618 /* "show ip ospf database" commands. */
12619 install_element(VIEW_NODE
, &show_ip_ospf_database_cmd
);
12621 /* "show ip ospf interface" commands. */
12622 install_element(VIEW_NODE
, &show_ip_ospf_interface_cmd
);
12624 install_element(VIEW_NODE
, &show_ip_ospf_instance_interface_cmd
);
12625 /* "show ip ospf interface traffic */
12626 install_element(VIEW_NODE
, &show_ip_ospf_interface_traffic_cmd
);
12628 /* "show ip ospf neighbor" commands. */
12629 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_detail_cmd
);
12630 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_cmd
);
12631 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_id_cmd
);
12632 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_all_cmd
);
12633 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_cmd
);
12634 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_cmd
);
12635 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_all_cmd
);
12637 install_element(VIEW_NODE
,
12638 &show_ip_ospf_instance_neighbor_int_detail_cmd
);
12639 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_int_cmd
);
12640 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_id_cmd
);
12641 install_element(VIEW_NODE
,
12642 &show_ip_ospf_instance_neighbor_detail_all_cmd
);
12643 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_detail_cmd
);
12644 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_cmd
);
12645 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_all_cmd
);
12647 /* "show ip ospf route" commands. */
12648 install_element(VIEW_NODE
, &show_ip_ospf_route_cmd
);
12649 install_element(VIEW_NODE
, &show_ip_ospf_border_routers_cmd
);
12650 install_element(VIEW_NODE
, &show_ip_ospf_reachable_routers_cmd
);
12652 install_element(VIEW_NODE
, &show_ip_ospf_instance_route_cmd
);
12653 install_element(VIEW_NODE
, &show_ip_ospf_instance_border_routers_cmd
);
12654 install_element(VIEW_NODE
,
12655 &show_ip_ospf_instance_reachable_routers_cmd
);
12657 /* "show ip ospf vrfs" commands. */
12658 install_element(VIEW_NODE
, &show_ip_ospf_vrfs_cmd
);
12660 /* "show ip ospf gr-helper details" command */
12661 install_element(VIEW_NODE
, &show_ip_ospf_gr_helper_cmd
);
12663 /* "show ip ospf summary-address" command */
12664 install_element(VIEW_NODE
, &show_ip_ospf_external_aggregator_cmd
);
12667 /* Initialization of OSPF interface. */
12668 static void ospf_vty_if_init(void)
12670 /* Install interface node. */
12671 if_cmd_init(config_write_interface
);
12673 /* "ip ospf authentication" commands. */
12674 install_element(INTERFACE_NODE
, &ip_ospf_authentication_args_addr_cmd
);
12675 install_element(INTERFACE_NODE
, &ip_ospf_authentication_addr_cmd
);
12676 install_element(INTERFACE_NODE
,
12677 &no_ip_ospf_authentication_args_addr_cmd
);
12678 install_element(INTERFACE_NODE
, &no_ip_ospf_authentication_addr_cmd
);
12679 install_element(INTERFACE_NODE
, &ip_ospf_authentication_key_addr_cmd
);
12680 install_element(INTERFACE_NODE
,
12681 &no_ip_ospf_authentication_key_authkey_addr_cmd
);
12682 install_element(INTERFACE_NODE
,
12683 &no_ospf_authentication_key_authkey_addr_cmd
);
12685 /* "ip ospf message-digest-key" commands. */
12686 install_element(INTERFACE_NODE
, &ip_ospf_message_digest_key_cmd
);
12687 install_element(INTERFACE_NODE
, &no_ip_ospf_message_digest_key_cmd
);
12689 /* "ip ospf cost" commands. */
12690 install_element(INTERFACE_NODE
, &ip_ospf_cost_cmd
);
12691 install_element(INTERFACE_NODE
, &no_ip_ospf_cost_cmd
);
12693 /* "ip ospf mtu-ignore" commands. */
12694 install_element(INTERFACE_NODE
, &ip_ospf_mtu_ignore_addr_cmd
);
12695 install_element(INTERFACE_NODE
, &no_ip_ospf_mtu_ignore_addr_cmd
);
12697 /* "ip ospf dead-interval" commands. */
12698 install_element(INTERFACE_NODE
, &ip_ospf_dead_interval_cmd
);
12699 install_element(INTERFACE_NODE
,
12700 &ip_ospf_dead_interval_minimal_addr_cmd
);
12701 install_element(INTERFACE_NODE
, &no_ip_ospf_dead_interval_cmd
);
12703 /* "ip ospf hello-interval" commands. */
12704 install_element(INTERFACE_NODE
, &ip_ospf_hello_interval_cmd
);
12705 install_element(INTERFACE_NODE
, &no_ip_ospf_hello_interval_cmd
);
12707 /* "ip ospf network" commands. */
12708 install_element(INTERFACE_NODE
, &ip_ospf_network_cmd
);
12709 install_element(INTERFACE_NODE
, &no_ip_ospf_network_cmd
);
12711 /* "ip ospf priority" commands. */
12712 install_element(INTERFACE_NODE
, &ip_ospf_priority_cmd
);
12713 install_element(INTERFACE_NODE
, &no_ip_ospf_priority_cmd
);
12715 /* "ip ospf retransmit-interval" commands. */
12716 install_element(INTERFACE_NODE
, &ip_ospf_retransmit_interval_addr_cmd
);
12717 install_element(INTERFACE_NODE
,
12718 &no_ip_ospf_retransmit_interval_addr_cmd
);
12720 /* "ip ospf transmit-delay" commands. */
12721 install_element(INTERFACE_NODE
, &ip_ospf_transmit_delay_addr_cmd
);
12722 install_element(INTERFACE_NODE
, &no_ip_ospf_transmit_delay_addr_cmd
);
12724 /* "ip ospf area" commands. */
12725 install_element(INTERFACE_NODE
, &ip_ospf_area_cmd
);
12726 install_element(INTERFACE_NODE
, &no_ip_ospf_area_cmd
);
12728 /* "ip ospf passive" commands. */
12729 install_element(INTERFACE_NODE
, &ip_ospf_passive_cmd
);
12730 install_element(INTERFACE_NODE
, &no_ip_ospf_passive_cmd
);
12732 /* These commands are compatibitliy for previous version. */
12733 install_element(INTERFACE_NODE
, &ospf_authentication_key_cmd
);
12734 install_element(INTERFACE_NODE
, &ospf_message_digest_key_cmd
);
12735 install_element(INTERFACE_NODE
, &no_ospf_message_digest_key_cmd
);
12736 install_element(INTERFACE_NODE
, &ospf_dead_interval_cmd
);
12737 install_element(INTERFACE_NODE
, &no_ospf_dead_interval_cmd
);
12738 install_element(INTERFACE_NODE
, &ospf_hello_interval_cmd
);
12739 install_element(INTERFACE_NODE
, &no_ospf_hello_interval_cmd
);
12740 install_element(INTERFACE_NODE
, &ospf_cost_cmd
);
12741 install_element(INTERFACE_NODE
, &no_ospf_cost_cmd
);
12742 install_element(INTERFACE_NODE
, &ospf_network_cmd
);
12743 install_element(INTERFACE_NODE
, &no_ospf_network_cmd
);
12744 install_element(INTERFACE_NODE
, &ospf_priority_cmd
);
12745 install_element(INTERFACE_NODE
, &no_ospf_priority_cmd
);
12746 install_element(INTERFACE_NODE
, &ospf_retransmit_interval_cmd
);
12747 install_element(INTERFACE_NODE
, &no_ospf_retransmit_interval_cmd
);
12748 install_element(INTERFACE_NODE
, &ospf_transmit_delay_cmd
);
12749 install_element(INTERFACE_NODE
, &no_ospf_transmit_delay_cmd
);
12752 static void ospf_vty_zebra_init(void)
12754 install_element(OSPF_NODE
, &ospf_redistribute_source_cmd
);
12755 install_element(OSPF_NODE
, &no_ospf_redistribute_source_cmd
);
12756 install_element(OSPF_NODE
, &ospf_redistribute_instance_source_cmd
);
12757 install_element(OSPF_NODE
, &no_ospf_redistribute_instance_source_cmd
);
12759 install_element(OSPF_NODE
, &ospf_distribute_list_out_cmd
);
12760 install_element(OSPF_NODE
, &no_ospf_distribute_list_out_cmd
);
12762 install_element(OSPF_NODE
, &ospf_default_information_originate_cmd
);
12763 install_element(OSPF_NODE
, &no_ospf_default_information_originate_cmd
);
12765 install_element(OSPF_NODE
, &ospf_default_metric_cmd
);
12766 install_element(OSPF_NODE
, &no_ospf_default_metric_cmd
);
12768 install_element(OSPF_NODE
, &ospf_distance_cmd
);
12769 install_element(OSPF_NODE
, &no_ospf_distance_cmd
);
12770 install_element(OSPF_NODE
, &no_ospf_distance_ospf_cmd
);
12771 install_element(OSPF_NODE
, &ospf_distance_ospf_cmd
);
12773 /*Ospf garcefull restart helper configurations */
12774 install_element(OSPF_NODE
, &ospf_gr_helper_enable_cmd
);
12775 install_element(OSPF_NODE
, &no_ospf_gr_helper_enable_cmd
);
12776 install_element(OSPF_NODE
, &ospf_gr_helper_enable_lsacheck_cmd
);
12777 install_element(OSPF_NODE
, &no_ospf_gr_helper_enable_lsacheck_cmd
);
12778 install_element(OSPF_NODE
, &ospf_gr_helper_supported_grace_time_cmd
);
12779 install_element(OSPF_NODE
, &no_ospf_gr_helper_supported_grace_time_cmd
);
12780 install_element(OSPF_NODE
, &ospf_gr_helper_planned_only_cmd
);
12781 install_element(OSPF_NODE
, &no_ospf_gr_helper_planned_only_cmd
);
12783 /* External LSA summarisation config commands.*/
12784 install_element(OSPF_NODE
, &ospf_external_route_aggregation_cmd
);
12785 install_element(OSPF_NODE
, &no_ospf_external_route_aggregation_cmd
);
12786 install_element(OSPF_NODE
,
12787 &ospf_external_route_aggregation_no_adrvertise_cmd
);
12788 install_element(OSPF_NODE
,
12789 &no_ospf_external_route_aggregation_no_adrvertise_cmd
);
12790 install_element(OSPF_NODE
, &ospf_route_aggregation_timer_cmd
);
12791 install_element(OSPF_NODE
, &no_ospf_route_aggregation_timer_cmd
);
12794 static int ospf_config_write(struct vty
*vty
);
12795 static struct cmd_node ospf_node
= {
12798 .parent_node
= CONFIG_NODE
,
12799 .prompt
= "%s(config-router)# ",
12800 .config_write
= ospf_config_write
,
12803 static void ospf_interface_clear(struct interface
*ifp
)
12805 if (!if_is_operative(ifp
))
12808 if (IS_DEBUG_OSPF(ism
, ISM_EVENTS
))
12809 zlog_debug("ISM[%s]: clear by reset", ifp
->name
);
12811 ospf_if_reset(ifp
);
12814 DEFUN (clear_ip_ospf_interface
,
12815 clear_ip_ospf_interface_cmd
,
12816 "clear ip ospf [vrf NAME] interface [IFNAME]",
12819 "OSPF information\n"
12821 "Interface information\n"
12822 "Interface name\n")
12824 int idx_ifname
= 0;
12826 struct interface
*ifp
;
12827 struct listnode
*node
;
12828 struct ospf
*ospf
= NULL
;
12829 char *vrf_name
= NULL
;
12830 vrf_id_t vrf_id
= VRF_DEFAULT
;
12831 struct vrf
*vrf
= NULL
;
12833 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
12834 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
12835 if (vrf_name
&& strmatch(vrf_name
, VRF_DEFAULT_NAME
))
12838 vrf
= vrf_lookup_by_name(vrf_name
);
12840 vrf_id
= vrf
->vrf_id
;
12842 if (!argv_find(argv
, argc
, "IFNAME", &idx_ifname
)) {
12843 /* Clear all the ospfv2 interfaces. */
12844 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
12845 if (vrf_id
!= ospf
->vrf_id
)
12848 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
12849 FOR_ALL_INTERFACES (vrf
, ifp
)
12850 ospf_interface_clear(ifp
);
12853 /* Interface name is specified. */
12854 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf_id
);
12856 vty_out(vty
, "No such interface name\n");
12858 ospf_interface_clear(ifp
);
12861 return CMD_SUCCESS
;
12864 DEFPY_HIDDEN(ospf_lsa_refresh_timer
, ospf_lsa_refresh_timer_cmd
,
12865 "[no$no] ospf lsa-refresh [(120-1800)]$value",
12867 "OSPF lsa refresh timer\n"
12868 "timer value in seconds\n")
12870 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
12873 ospf
->lsa_refresh_timer
= OSPF_LS_REFRESH_TIME
;
12875 ospf
->lsa_refresh_timer
= value
;
12877 return CMD_SUCCESS
;
12880 DEFPY_HIDDEN(ospf_maxage_delay_timer
, ospf_maxage_delay_timer_cmd
,
12881 "[no$no] ospf maxage-delay [(0-60)]$value",
12883 "OSPF lsa maxage delay timer\n"
12884 "timer value in seconds\n")
12886 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
12889 ospf
->maxage_delay
= OSPF_LSA_MAXAGE_REMOVE_DELAY_DEFAULT
;
12891 ospf
->maxage_delay
= value
;
12893 EVENT_OFF(ospf
->t_maxage
);
12894 OSPF_TIMER_ON(ospf
->t_maxage
, ospf_maxage_lsa_remover
,
12895 ospf
->maxage_delay
);
12897 return CMD_SUCCESS
;
12901 * ------------------------------------------------------------------------*
12902 * Following is (vty) configuration functions for flood-reduction handling.
12903 * ------------------------------------------------------------------------
12906 DEFPY(flood_reduction
, flood_reduction_cmd
, "flood-reduction",
12907 "flood reduction feature\n")
12909 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
12910 struct ospf_area
*area
;
12911 struct listnode
*node
;
12913 /* Turn on the Flood Reduction feature for the router. */
12914 if (!ospf
->fr_configured
) {
12915 ospf
->fr_configured
= true;
12916 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT
,
12917 "Flood Reduction: OFF -> ON");
12918 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
12920 ospf_area_update_fr_state(area
);
12921 ospf_refresh_area_self_lsas(area
);
12926 return CMD_SUCCESS
;
12929 DEFPY(flood_reduction_area
, flood_reduction_area_cmd
,
12930 "area <A.B.C.D|(0-4294967295)> flood-reduction",
12931 "OSPF area parameters\n"
12932 "OSPF area ID in IP address format\n"
12933 "OSPF area ID as a decimal value\n"
12934 "Enable flood reduction for area\n")
12936 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
12937 struct ospf_area
*oa
;
12941 const char *areaid
;
12942 struct in_addr area_id
;
12944 areaid
= argv
[idx
]->arg
;
12946 ret
= str2area_id(areaid
, &area_id
, &format
);
12948 vty_out(vty
, "Please specify area by A.B.C.D|<0-4294967295>\n");
12949 return CMD_WARNING_CONFIG_FAILED
;
12952 oa
= ospf_area_lookup_by_area_id(ospf
, area_id
);
12954 vty_out(vty
, "OSPF area ID not present\n");
12955 return CMD_WARNING_CONFIG_FAILED
;
12958 /* Turn on the Flood Reduction feature for the area. */
12959 if (!oa
->fr_info
.configured
) {
12960 oa
->fr_info
.configured
= true;
12961 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT
,
12962 "Flood Reduction area %pI4 : OFF -> ON",
12964 ospf_area_update_fr_state(oa
);
12965 ospf_refresh_area_self_lsas(oa
);
12968 return CMD_SUCCESS
;
12971 DEFPY(no_flood_reduction
, no_flood_reduction_cmd
, "no flood-reduction",
12972 NO_STR
"flood reduction feature\n")
12974 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
12975 struct listnode
*node
;
12976 struct ospf_area
*area
;
12978 /* Turn off the Flood Reduction feature for the router. */
12979 if (ospf
->fr_configured
) {
12980 ospf
->fr_configured
= false;
12981 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT
,
12982 "Flood Reduction: ON -> OFF");
12983 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
12985 ospf_area_update_fr_state(area
);
12986 ospf_refresh_area_self_lsas(area
);
12991 return CMD_SUCCESS
;
12994 DEFPY(no_flood_reduction_area
, no_flood_reduction_area_cmd
,
12995 "no area <A.B.C.D|(0-4294967295)> flood-reduction",
12997 "OSPF area parameters\n"
12998 "OSPF area ID in IP address format\n"
12999 "OSPF area ID as a decimal value\n"
13000 "Disable flood reduction for area\n")
13002 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
13003 struct ospf_area
*oa
;
13007 const char *areaid
;
13008 struct in_addr area_id
;
13010 areaid
= argv
[idx
]->arg
;
13012 ret
= str2area_id(areaid
, &area_id
, &format
);
13014 vty_out(vty
, "Please specify area by A.B.C.D|<0-4294967295>\n");
13015 return CMD_WARNING_CONFIG_FAILED
;
13018 oa
= ospf_area_lookup_by_area_id(ospf
, area_id
);
13020 vty_out(vty
, "OSPF area ID not present\n");
13021 return CMD_WARNING_CONFIG_FAILED
;
13024 /* Turn off the Flood Reduction feature for the area. */
13025 if (oa
->fr_info
.configured
) {
13026 oa
->fr_info
.configured
= false;
13027 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT
,
13028 "Flood Reduction area %pI4 : ON -> OFF",
13030 ospf_area_update_fr_state(oa
);
13031 ospf_refresh_area_self_lsas(oa
);
13034 return CMD_SUCCESS
;
13037 DEFPY(ospf_socket_bufsizes
,
13038 ospf_socket_bufsizes_cmd
,
13039 "[no] socket buffer <send$send_val | recv$recv_val | all$all_val> \
13040 ![(1-4000000000)$bufsize]",
13042 "Socket parameters\n"
13043 "Buffer size configuration\n"
13044 "Send buffer size\n"
13045 "Receive buffer size\n"
13046 "Both send and receive buffer sizes\n"
13047 "Buffer size, in bytes\n")
13049 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
13050 uint32_t recvsz
, sendsz
;
13053 bufsize
= OSPF_DEFAULT_SOCK_BUFSIZE
;
13058 } else if (send_val
) {
13060 recvsz
= ospf
->recv_sock_bufsize
;
13061 } else if (recv_val
) {
13063 sendsz
= ospf
->send_sock_bufsize
;
13065 return CMD_SUCCESS
;
13067 /* React to a change by modifying existing sockets */
13068 ospf_update_bufsize(ospf
, recvsz
, sendsz
);
13070 return CMD_SUCCESS
;
13073 DEFPY (per_intf_socket
,
13074 per_intf_socket_cmd
,
13075 "[no] socket-per-interface",
13077 "Use write socket per interface\n")
13079 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
13080 struct listnode
*node
;
13081 struct ospf_interface
*oi
;
13084 if (ospf
->intf_socket_enabled
) {
13085 ospf
->intf_socket_enabled
= false;
13087 /* Iterate and close any sockets */
13088 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
))
13089 ospf_ifp_sock_close(oi
->ifp
);
13091 } else if (!ospf
->intf_socket_enabled
) {
13092 ospf
->intf_socket_enabled
= true;
13094 /* Iterate and open sockets */
13095 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
))
13096 ospf_ifp_sock_init(oi
->ifp
);
13099 return CMD_SUCCESS
;
13102 void ospf_vty_clear_init(void)
13104 install_element(ENABLE_NODE
, &clear_ip_ospf_interface_cmd
);
13105 install_element(ENABLE_NODE
, &clear_ip_ospf_process_cmd
);
13106 install_element(ENABLE_NODE
, &clear_ip_ospf_neighbor_cmd
);
13110 /* Install OSPF related vty commands. */
13111 void ospf_vty_init(void)
13113 /* Install ospf top node. */
13114 install_node(&ospf_node
);
13116 /* "router ospf" commands. */
13117 install_element(CONFIG_NODE
, &router_ospf_cmd
);
13118 install_element(CONFIG_NODE
, &no_router_ospf_cmd
);
13121 install_default(OSPF_NODE
);
13123 /* "ospf router-id" commands. */
13124 install_element(OSPF_NODE
, &ospf_router_id_cmd
);
13125 install_element(OSPF_NODE
, &ospf_router_id_old_cmd
);
13126 install_element(OSPF_NODE
, &no_ospf_router_id_cmd
);
13128 /* "passive-interface" commands. */
13129 install_element(OSPF_NODE
, &ospf_passive_interface_default_cmd
);
13130 install_element(OSPF_NODE
, &ospf_passive_interface_addr_cmd
);
13131 install_element(OSPF_NODE
, &no_ospf_passive_interface_default_cmd
);
13132 install_element(OSPF_NODE
, &no_ospf_passive_interface_addr_cmd
);
13134 /* "ospf abr-type" commands. */
13135 install_element(OSPF_NODE
, &ospf_abr_type_cmd
);
13136 install_element(OSPF_NODE
, &no_ospf_abr_type_cmd
);
13138 /* "ospf log-adjacency-changes" commands. */
13139 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_cmd
);
13140 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_detail_cmd
);
13141 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_cmd
);
13142 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_detail_cmd
);
13144 /* "ospf rfc1583-compatible" commands. */
13145 install_element(OSPF_NODE
, &ospf_compatible_rfc1583_cmd
);
13146 install_element(OSPF_NODE
, &no_ospf_compatible_rfc1583_cmd
);
13147 install_element(OSPF_NODE
, &ospf_rfc1583_flag_cmd
);
13148 install_element(OSPF_NODE
, &no_ospf_rfc1583_flag_cmd
);
13150 /* "ospf send-extra-data zebra" commands. */
13151 install_element(OSPF_NODE
, &ospf_send_extra_data_cmd
);
13153 /* "network area" commands. */
13154 install_element(OSPF_NODE
, &ospf_network_area_cmd
);
13155 install_element(OSPF_NODE
, &no_ospf_network_area_cmd
);
13157 /* "area authentication" commands. */
13158 install_element(OSPF_NODE
,
13159 &ospf_area_authentication_message_digest_cmd
);
13160 install_element(OSPF_NODE
, &ospf_area_authentication_cmd
);
13161 install_element(OSPF_NODE
, &no_ospf_area_authentication_cmd
);
13163 /* "area range" commands. */
13164 install_element(OSPF_NODE
, &ospf_area_range_cmd
);
13165 install_element(OSPF_NODE
, &ospf_area_range_cost_cmd
);
13166 install_element(OSPF_NODE
, &ospf_area_range_not_advertise_cmd
);
13167 install_element(OSPF_NODE
, &no_ospf_area_range_cmd
);
13168 install_element(OSPF_NODE
, &no_ospf_area_range_substitute_cmd
);
13170 /* "area virtual-link" commands. */
13171 install_element(OSPF_NODE
, &ospf_area_vlink_cmd
);
13172 install_element(OSPF_NODE
, &ospf_area_vlink_intervals_cmd
);
13173 install_element(OSPF_NODE
, &no_ospf_area_vlink_cmd
);
13174 install_element(OSPF_NODE
, &no_ospf_area_vlink_intervals_cmd
);
13177 /* "area stub" commands. */
13178 install_element(OSPF_NODE
, &ospf_area_stub_no_summary_cmd
);
13179 install_element(OSPF_NODE
, &ospf_area_stub_cmd
);
13180 install_element(OSPF_NODE
, &no_ospf_area_stub_no_summary_cmd
);
13181 install_element(OSPF_NODE
, &no_ospf_area_stub_cmd
);
13183 /* "area nssa" commands. */
13184 install_element(OSPF_NODE
, &ospf_area_nssa_cmd
);
13185 install_element(OSPF_NODE
, &no_ospf_area_nssa_cmd
);
13186 install_element(OSPF_NODE
, &ospf_area_nssa_range_cmd
);
13187 install_element(OSPF_NODE
, &no_ospf_area_nssa_range_cmd
);
13189 install_element(OSPF_NODE
, &ospf_area_default_cost_cmd
);
13190 install_element(OSPF_NODE
, &no_ospf_area_default_cost_cmd
);
13192 install_element(OSPF_NODE
, &ospf_area_shortcut_cmd
);
13193 install_element(OSPF_NODE
, &no_ospf_area_shortcut_cmd
);
13195 install_element(OSPF_NODE
, &ospf_area_export_list_cmd
);
13196 install_element(OSPF_NODE
, &no_ospf_area_export_list_cmd
);
13198 install_element(OSPF_NODE
, &ospf_area_filter_list_cmd
);
13199 install_element(OSPF_NODE
, &no_ospf_area_filter_list_cmd
);
13201 install_element(OSPF_NODE
, &ospf_area_import_list_cmd
);
13202 install_element(OSPF_NODE
, &no_ospf_area_import_list_cmd
);
13204 /* SPF timer commands */
13205 install_element(OSPF_NODE
, &ospf_timers_throttle_spf_cmd
);
13206 install_element(OSPF_NODE
, &no_ospf_timers_throttle_spf_cmd
);
13208 /* LSA timers commands */
13209 install_element(OSPF_NODE
, &ospf_timers_min_ls_interval_cmd
);
13210 install_element(OSPF_NODE
, &no_ospf_timers_min_ls_interval_cmd
);
13211 install_element(OSPF_NODE
, &ospf_timers_lsa_min_arrival_cmd
);
13212 install_element(OSPF_NODE
, &no_ospf_timers_lsa_min_arrival_cmd
);
13214 /* refresh timer commands */
13215 install_element(OSPF_NODE
, &ospf_refresh_timer_cmd
);
13216 install_element(OSPF_NODE
, &no_ospf_refresh_timer_val_cmd
);
13218 /* max-metric commands */
13219 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_admin_cmd
);
13220 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_admin_cmd
);
13221 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_startup_cmd
);
13222 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_startup_cmd
);
13223 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_shutdown_cmd
);
13224 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_shutdown_cmd
);
13226 /* reference bandwidth commands */
13227 install_element(OSPF_NODE
, &ospf_auto_cost_reference_bandwidth_cmd
);
13228 install_element(OSPF_NODE
, &no_ospf_auto_cost_reference_bandwidth_cmd
);
13230 /* "neighbor" commands. */
13231 install_element(OSPF_NODE
, &ospf_neighbor_cmd
);
13232 install_element(OSPF_NODE
, &ospf_neighbor_poll_interval_cmd
);
13233 install_element(OSPF_NODE
, &no_ospf_neighbor_cmd
);
13234 install_element(OSPF_NODE
, &no_ospf_neighbor_poll_cmd
);
13236 /* write multiplier commands */
13237 install_element(OSPF_NODE
, &ospf_write_multiplier_cmd
);
13238 install_element(OSPF_NODE
, &write_multiplier_cmd
);
13239 install_element(OSPF_NODE
, &no_ospf_write_multiplier_cmd
);
13240 install_element(OSPF_NODE
, &no_write_multiplier_cmd
);
13242 /* "proactive-arp" commands. */
13243 install_element(OSPF_NODE
, &ospf_proactive_arp_cmd
);
13244 install_element(OSPF_NODE
, &no_ospf_proactive_arp_cmd
);
13246 /* TI-LFA commands */
13247 install_element(OSPF_NODE
, &ospf_ti_lfa_cmd
);
13248 install_element(OSPF_NODE
, &no_ospf_ti_lfa_cmd
);
13250 /* Max path configurations */
13251 install_element(OSPF_NODE
, &ospf_max_multipath_cmd
);
13252 install_element(OSPF_NODE
, &no_ospf_max_multipath_cmd
);
13254 vrf_cmd_init(NULL
);
13256 install_element(OSPF_NODE
, &ospf_lsa_refresh_timer_cmd
);
13257 install_element(OSPF_NODE
, &ospf_maxage_delay_timer_cmd
);
13259 /* Flood Reduction commands */
13260 install_element(OSPF_NODE
, &flood_reduction_cmd
);
13261 install_element(OSPF_NODE
, &no_flood_reduction_cmd
);
13262 install_element(OSPF_NODE
, &flood_reduction_area_cmd
);
13263 install_element(OSPF_NODE
, &no_flood_reduction_area_cmd
);
13265 install_element(OSPF_NODE
, &ospf_socket_bufsizes_cmd
);
13266 install_element(OSPF_NODE
, &per_intf_socket_cmd
);
13268 /* Init interface related vty commands. */
13269 ospf_vty_if_init();
13271 /* Init zebra related vty commands. */
13272 ospf_vty_zebra_init();