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
);
236 if (ospf
->gr_info
.restart_support
)
237 ospf_gr_nvm_delete(ospf
);
241 ret
= CMD_WARNING_CONFIG_FAILED
;
247 DEFPY (ospf_router_id
,
249 "ospf router-id A.B.C.D",
250 "OSPF specific commands\n"
251 "router-id for the OSPF process\n"
252 "OSPF router-id in IP address format\n")
254 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
256 struct listnode
*node
;
257 struct ospf_area
*area
;
259 ospf
->router_id_static
= router_id
;
261 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
262 if (area
->full_nbrs
) {
264 "For this router-id change to take effect, use \"clear ip ospf process\" command\n");
268 ospf_router_id_update(ospf
);
273 DEFUN_HIDDEN (ospf_router_id_old
,
274 ospf_router_id_old_cmd
,
276 "router-id for the OSPF process\n"
277 "OSPF router-id in IP address format\n")
279 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
281 struct listnode
*node
;
282 struct ospf_area
*area
;
283 struct in_addr router_id
;
286 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &router_id
);
288 vty_out(vty
, "Please specify Router ID by A.B.C.D\n");
289 return CMD_WARNING_CONFIG_FAILED
;
292 ospf
->router_id_static
= router_id
;
294 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
295 if (area
->full_nbrs
) {
297 "For this router-id change to take effect, use \"clear ip ospf process\" command\n");
301 ospf_router_id_update(ospf
);
306 DEFPY (no_ospf_router_id
,
307 no_ospf_router_id_cmd
,
308 "no ospf router-id [A.B.C.D]",
310 "OSPF specific commands\n"
311 "router-id for the OSPF process\n"
312 "OSPF router-id in IP address format\n")
314 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
315 struct listnode
*node
;
316 struct ospf_area
*area
;
319 if (!IPV4_ADDR_SAME(&ospf
->router_id_static
, &router_id
)) {
320 vty_out(vty
, "%% OSPF router-id doesn't match\n");
321 return CMD_WARNING_CONFIG_FAILED
;
325 ospf
->router_id_static
.s_addr
= 0;
327 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
328 if (area
->full_nbrs
) {
330 "For this router-id change to take effect, use \"clear ip ospf process\" command\n");
334 ospf_router_id_update(ospf
);
340 static void ospf_passive_interface_default_update(struct ospf
*ospf
,
344 struct ospf_interface
*oi
;
346 ospf
->passive_interface_default
= newval
;
348 /* update multicast memberships */
349 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, ln
, oi
))
350 ospf_if_set_multicast(oi
);
353 static void ospf_passive_interface_update(struct interface
*ifp
,
354 struct ospf_if_params
*params
,
355 struct in_addr addr
, uint8_t newval
)
357 struct route_node
*rn
;
359 if (OSPF_IF_PARAM_CONFIGURED(params
, passive_interface
)) {
360 if (params
->passive_interface
== newval
)
363 params
->passive_interface
= newval
;
364 UNSET_IF_PARAM(params
, passive_interface
);
365 if (params
!= IF_DEF_PARAMS(ifp
)) {
366 ospf_free_if_params(ifp
, addr
);
367 ospf_if_update_params(ifp
, addr
);
370 params
->passive_interface
= newval
;
371 SET_IF_PARAM(params
, passive_interface
);
375 * XXX We should call ospf_if_set_multicast on exactly those
376 * interfaces for which the passive property changed. It is too much
377 * work to determine this set, so we do this for every interface.
378 * This is safe and reasonable because ospf_if_set_multicast uses a
379 * record of joined groups to avoid systems calls if the desired
380 * memberships match the current memership.
383 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
384 struct ospf_interface
*oi
= rn
->info
;
387 ospf_if_set_multicast(oi
);
391 * XXX It is not clear what state transitions the interface needs to
392 * undergo when going from active to passive and vice versa. Fixing
393 * this will require precise identification of interfaces having such a
398 DEFUN (ospf_passive_interface_default
,
399 ospf_passive_interface_default_cmd
,
400 "passive-interface default",
401 "Suppress routing updates on an interface\n"
402 "Suppress routing updates on interfaces by default\n")
404 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
406 ospf_passive_interface_default_update(ospf
, OSPF_IF_PASSIVE
);
411 DEFUN_HIDDEN (ospf_passive_interface_addr
,
412 ospf_passive_interface_addr_cmd
,
413 "passive-interface IFNAME [A.B.C.D]",
414 "Suppress routing updates on an interface\n"
418 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
420 struct interface
*ifp
= NULL
;
421 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
422 struct ospf_if_params
*params
;
426 "This command is deprecated, because it is not VRF-aware.\n");
428 "Please, use \"ip ospf passive\" on an interface instead.\n");
430 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
431 ifp
= if_get_by_name(argv
[1]->arg
, ospf
->vrf_id
, ospf
->name
);
434 vty_out(vty
, "interface %s not found.\n", (char *)argv
[1]->arg
);
435 return CMD_WARNING_CONFIG_FAILED
;
439 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
442 "Please specify interface address by A.B.C.D\n");
443 return CMD_WARNING_CONFIG_FAILED
;
446 params
= ospf_get_if_params(ifp
, addr
);
447 ospf_if_update_params(ifp
, addr
);
449 params
= IF_DEF_PARAMS(ifp
);
452 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_PASSIVE
);
457 DEFUN (no_ospf_passive_interface_default
,
458 no_ospf_passive_interface_default_cmd
,
459 "no passive-interface default",
461 "Allow routing updates on an interface\n"
462 "Allow routing updates on interfaces by default\n")
464 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
466 ospf_passive_interface_default_update(ospf
, OSPF_IF_ACTIVE
);
471 DEFUN_HIDDEN (no_ospf_passive_interface
,
472 no_ospf_passive_interface_addr_cmd
,
473 "no passive-interface IFNAME [A.B.C.D]",
475 "Allow routing updates on an interface\n"
479 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
481 struct interface
*ifp
= NULL
;
482 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
483 struct ospf_if_params
*params
;
487 "This command is deprecated, because it is not VRF-aware.\n");
489 "Please, use \"no ip ospf passive\" on an interface instead.\n");
491 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
492 ifp
= if_get_by_name(argv
[2]->arg
, ospf
->vrf_id
, ospf
->name
);
495 vty_out(vty
, "interface %s not found.\n", (char *)argv
[2]->arg
);
496 return CMD_WARNING_CONFIG_FAILED
;
500 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
503 "Please specify interface address by A.B.C.D\n");
504 return CMD_WARNING_CONFIG_FAILED
;
506 params
= ospf_lookup_if_params(ifp
, addr
);
510 params
= IF_DEF_PARAMS(ifp
);
513 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_ACTIVE
);
519 DEFUN (ospf_network_area
,
520 ospf_network_area_cmd
,
521 "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
522 "Enable routing on an IP network\n"
523 "OSPF network prefix\n"
524 "Set the OSPF area ID\n"
525 "OSPF area ID in IP address format\n"
526 "OSPF area ID as a decimal value\n")
528 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
529 int idx_ipv4_prefixlen
= 1;
530 int idx_ipv4_number
= 3;
531 struct prefix_ipv4 p
;
532 struct in_addr area_id
;
536 if (ospf
->instance
) {
538 "The network command is not supported in multi-instance ospf\n");
539 return CMD_WARNING_CONFIG_FAILED
;
542 count
= ospf_count_area_params(ospf
);
545 "Please remove all ip ospf area x.x.x.x commands first.\n");
546 if (IS_DEBUG_OSPF_EVENT
)
548 "%s ospf vrf %s num of %u ip ospf area x config",
549 __func__
, ospf_get_name(ospf
), count
);
550 return CMD_WARNING_CONFIG_FAILED
;
553 /* Get network prefix and Area ID. */
554 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
555 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
557 ret
= ospf_network_set(ospf
, &p
, area_id
, format
);
559 vty_out(vty
, "There is already same network statement.\n");
560 return CMD_WARNING_CONFIG_FAILED
;
566 DEFUN (no_ospf_network_area
,
567 no_ospf_network_area_cmd
,
568 "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
570 "Enable routing on an IP network\n"
571 "OSPF network prefix\n"
572 "Set the OSPF area ID\n"
573 "OSPF area ID in IP address format\n"
574 "OSPF area ID as a decimal value\n")
576 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
577 int idx_ipv4_prefixlen
= 2;
578 int idx_ipv4_number
= 4;
579 struct prefix_ipv4 p
;
580 struct in_addr area_id
;
583 if (ospf
->instance
) {
585 "The network command is not supported in multi-instance ospf\n");
586 return CMD_WARNING_CONFIG_FAILED
;
589 /* Get network prefix and Area ID. */
590 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
591 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
593 ret
= ospf_network_unset(ospf
, &p
, area_id
);
596 "Can't find specified network area configuration.\n");
597 return CMD_WARNING_CONFIG_FAILED
;
603 DEFUN (ospf_area_range
,
605 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]",
606 "OSPF area parameters\n"
607 "OSPF area ID in IP address format\n"
608 "OSPF area ID as a decimal value\n"
609 "Summarize routes matching address/mask (border routers only)\n"
610 "Area range prefix\n"
611 "Advertise this range (default)\n"
612 "User specified metric for this range\n"
613 "Advertised metric for this range\n")
615 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
616 struct ospf_area
*area
;
617 int idx_ipv4_number
= 1;
618 int idx_ipv4_prefixlen
= 3;
620 struct prefix_ipv4 p
;
621 struct in_addr area_id
;
625 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
626 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
628 area
= ospf_area_get(ospf
, area_id
);
629 ospf_area_display_format_set(ospf
, area
, format
);
631 ospf_area_range_set(ospf
, area
, area
->ranges
, &p
,
632 OSPF_AREA_RANGE_ADVERTISE
, false);
634 cost
= strtoul(argv
[idx_cost
]->arg
, NULL
, 10);
635 ospf_area_range_cost_set(ospf
, area
, area
->ranges
, &p
, cost
);
641 DEFUN (ospf_area_range_cost
,
642 ospf_area_range_cost_cmd
,
643 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M {cost (0-16777215)|substitute A.B.C.D/M}",
644 "OSPF area parameters\n"
645 "OSPF area ID in IP address format\n"
646 "OSPF area ID as a decimal value\n"
647 "Summarize routes matching address/mask (border routers only)\n"
648 "Area range prefix\n"
649 "User specified metric for this range\n"
650 "Advertised metric for this range\n"
651 "Announce area range as another prefix\n"
652 "Network prefix to be announced instead of range\n")
654 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
655 struct ospf_area
*area
;
656 int idx_ipv4_number
= 1;
657 int idx_ipv4_prefixlen
= 3;
659 struct prefix_ipv4 p
, s
;
660 struct in_addr area_id
;
664 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
665 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
667 area
= ospf_area_get(ospf
, area_id
);
668 ospf_area_display_format_set(ospf
, area
, format
);
670 ospf_area_range_set(ospf
, area
, area
->ranges
, &p
,
671 OSPF_AREA_RANGE_ADVERTISE
, false);
672 if (argv_find(argv
, argc
, "cost", &idx
)) {
673 cost
= strtoul(argv
[idx
+ 1]->arg
, NULL
, 10);
674 ospf_area_range_cost_set(ospf
, area
, area
->ranges
, &p
, cost
);
678 if (argv_find(argv
, argc
, "substitute", &idx
)) {
679 str2prefix_ipv4(argv
[idx
+ 1]->arg
, &s
);
680 ospf_area_range_substitute_set(ospf
, area
, &p
, &s
);
686 DEFUN (ospf_area_range_not_advertise
,
687 ospf_area_range_not_advertise_cmd
,
688 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise",
689 "OSPF area parameters\n"
690 "OSPF area ID in IP address format\n"
691 "OSPF area ID as a decimal value\n"
692 "Summarize routes matching address/mask (border routers only)\n"
693 "Area range prefix\n"
694 "DoNotAdvertise this range\n")
696 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
697 struct ospf_area
*area
;
698 int idx_ipv4_number
= 1;
699 int idx_ipv4_prefixlen
= 3;
700 struct prefix_ipv4 p
;
701 struct in_addr area_id
;
704 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
705 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
707 area
= ospf_area_get(ospf
, area_id
);
708 ospf_area_display_format_set(ospf
, area
, format
);
710 ospf_area_range_set(ospf
, area
, area
->ranges
, &p
, 0, false);
711 ospf_area_range_substitute_unset(ospf
, area
, &p
);
716 DEFUN (no_ospf_area_range
,
717 no_ospf_area_range_cmd
,
718 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]",
720 "OSPF area parameters\n"
721 "OSPF area ID in IP address format\n"
722 "OSPF area ID as a decimal value\n"
723 "Summarize routes matching address/mask (border routers only)\n"
724 "Area range prefix\n"
725 "User specified metric for this range\n"
726 "Advertised metric for this range\n"
727 "Advertise this range (default)\n"
728 "User specified metric for this range\n"
729 "Advertised metric for this range\n"
730 "DoNotAdvertise this range\n")
732 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
733 struct ospf_area
*area
;
734 int idx_ipv4_number
= 2;
735 int idx_ipv4_prefixlen
= 4;
736 struct prefix_ipv4 p
;
737 struct in_addr area_id
;
740 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
741 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
743 area
= ospf_area_get(ospf
, area_id
);
744 ospf_area_display_format_set(ospf
, area
, format
);
746 ospf_area_range_unset(ospf
, area
, area
->ranges
, &p
);
751 DEFUN (no_ospf_area_range_substitute
,
752 no_ospf_area_range_substitute_cmd
,
753 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
755 "OSPF area parameters\n"
756 "OSPF area ID in IP address format\n"
757 "OSPF area ID as a decimal value\n"
758 "Summarize routes matching address/mask (border routers only)\n"
759 "Area range prefix\n"
760 "Announce area range as another prefix\n"
761 "Network prefix to be announced instead of range\n")
763 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
764 struct ospf_area
*area
;
765 int idx_ipv4_number
= 2;
766 int idx_ipv4_prefixlen
= 4;
767 int idx_ipv4_prefixlen_2
= 6;
768 struct prefix_ipv4 p
, s
;
769 struct in_addr area_id
;
772 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
773 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
774 str2prefix_ipv4(argv
[idx_ipv4_prefixlen_2
]->arg
, &s
);
776 area
= ospf_area_get(ospf
, area_id
);
777 ospf_area_display_format_set(ospf
, area
, format
);
779 ospf_area_range_substitute_unset(ospf
, area
, &p
);
785 /* Command Handler Logic in VLink stuff is delicate!!
787 ALTER AT YOUR OWN RISK!!!!
789 Various dummy values are used to represent 'NoChange' state for
790 VLink configuration NOT being changed by a VLink command, and
791 special syntax is used within the command strings so that the
792 typed in command verbs can be seen in the configuration command
793 bacckend handler. This is to drastically reduce the verbeage
794 required to coe up with a reasonably compatible Cisco VLink command
796 - Matthew Grant <grantma@anathoth.gen.nz>
797 Wed, 21 Feb 2001 15:13:52 +1300
800 /* Configuration data for virtual links
802 struct ospf_vl_config_data
{
803 struct vty
*vty
; /* vty stuff */
804 struct in_addr area_id
; /* area ID from command line */
805 int area_id_fmt
; /* command line area ID format */
806 struct in_addr vl_peer
; /* command line vl_peer */
807 int auth_type
; /* Authehntication type, if given */
808 char *auth_key
; /* simple password if present */
809 int crypto_key_id
; /* Cryptographic key ID */
810 char *md5_key
; /* MD5 authentication key */
811 int hello_interval
; /* Obvious what these are... */
812 int retransmit_interval
;
817 static void ospf_vl_config_data_init(struct ospf_vl_config_data
*vl_config
,
820 memset(vl_config
, 0, sizeof(struct ospf_vl_config_data
));
821 vl_config
->auth_type
= OSPF_AUTH_CMD_NOTSEEN
;
822 vl_config
->vty
= vty
;
825 static struct ospf_vl_data
*
826 ospf_find_vl_data(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
828 struct ospf_area
*area
;
829 struct ospf_vl_data
*vl_data
;
831 struct in_addr area_id
;
833 vty
= vl_config
->vty
;
834 area_id
= vl_config
->area_id
;
836 if (area_id
.s_addr
== OSPF_AREA_BACKBONE
) {
838 "Configuring VLs over the backbone is not allowed\n");
841 area
= ospf_area_get(ospf
, area_id
);
842 ospf_area_display_format_set(ospf
, area
, vl_config
->area_id_fmt
);
844 if (area
->external_routing
!= OSPF_AREA_DEFAULT
) {
845 if (vl_config
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
846 vty_out(vty
, "Area %pI4 is %s\n", &area_id
,
847 area
->external_routing
== OSPF_AREA_NSSA
851 vty_out(vty
, "Area %ld is %s\n",
852 (unsigned long)ntohl(area_id
.s_addr
),
853 area
->external_routing
== OSPF_AREA_NSSA
859 if ((vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
->vl_peer
))
861 vl_data
= ospf_vl_data_new(area
, vl_config
->vl_peer
);
862 if (vl_data
->vl_oi
== NULL
) {
863 vl_data
->vl_oi
= ospf_vl_new(ospf
, vl_data
);
864 ospf_vl_add(ospf
, vl_data
);
865 ospf_spf_calculate_schedule(ospf
,
866 SPF_FLAG_CONFIG_CHANGE
);
873 static int ospf_vl_set_security(struct ospf_vl_data
*vl_data
,
874 struct ospf_vl_config_data
*vl_config
)
876 struct crypt_key
*ck
;
878 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
880 vty
= vl_config
->vty
;
882 if (vl_config
->auth_type
!= OSPF_AUTH_CMD_NOTSEEN
) {
883 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), auth_type
);
884 IF_DEF_PARAMS(ifp
)->auth_type
= vl_config
->auth_type
;
887 if (vl_config
->auth_key
) {
888 memset(IF_DEF_PARAMS(ifp
)->auth_simple
, 0,
889 OSPF_AUTH_SIMPLE_SIZE
+ 1);
890 strlcpy((char *)IF_DEF_PARAMS(ifp
)->auth_simple
,
892 sizeof(IF_DEF_PARAMS(ifp
)->auth_simple
));
893 } else if (vl_config
->md5_key
) {
894 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
895 vl_config
->crypto_key_id
)
897 vty_out(vty
, "OSPF: Key %d already exists\n",
898 vl_config
->crypto_key_id
);
901 ck
= ospf_crypt_key_new();
902 ck
->key_id
= vl_config
->crypto_key_id
;
903 memset(ck
->auth_key
, 0, OSPF_AUTH_MD5_SIZE
+ 1);
904 strlcpy((char *)ck
->auth_key
, vl_config
->md5_key
,
905 sizeof(ck
->auth_key
));
907 ospf_crypt_key_add(IF_DEF_PARAMS(ifp
)->auth_crypt
, ck
);
908 } else if (vl_config
->crypto_key_id
!= 0) {
911 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
912 vl_config
->crypto_key_id
)
914 vty_out(vty
, "OSPF: Key %d does not exist\n",
915 vl_config
->crypto_key_id
);
916 return CMD_WARNING_CONFIG_FAILED
;
919 ospf_crypt_key_delete(IF_DEF_PARAMS(ifp
)->auth_crypt
,
920 vl_config
->crypto_key_id
);
926 static int ospf_vl_set_timers(struct ospf_vl_data
*vl_data
,
927 struct ospf_vl_config_data
*vl_config
)
929 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
930 /* Virtual Link data initialised to defaults, so only set
932 if (vl_config
->hello_interval
) {
933 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_hello
);
934 IF_DEF_PARAMS(ifp
)->v_hello
= vl_config
->hello_interval
;
937 if (vl_config
->dead_interval
) {
938 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_wait
);
939 IF_DEF_PARAMS(ifp
)->v_wait
= vl_config
->dead_interval
;
942 if (vl_config
->retransmit_interval
) {
943 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), retransmit_interval
);
944 IF_DEF_PARAMS(ifp
)->retransmit_interval
=
945 vl_config
->retransmit_interval
;
948 if (vl_config
->transmit_delay
) {
949 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), transmit_delay
);
950 IF_DEF_PARAMS(ifp
)->transmit_delay
= vl_config
->transmit_delay
;
957 /* The business end of all of the above */
958 static int ospf_vl_set(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
960 struct ospf_vl_data
*vl_data
;
963 vl_data
= ospf_find_vl_data(ospf
, vl_config
);
965 return CMD_WARNING_CONFIG_FAILED
;
967 /* Process this one first as it can have a fatal result, which can
968 only logically occur if the virtual link exists already
969 Thus a command error does not result in a change to the
970 running configuration such as unexpectedly altered timer
972 ret
= ospf_vl_set_security(vl_data
, vl_config
);
973 if (ret
!= CMD_SUCCESS
)
976 /* Set any time based parameters, these area already range checked */
978 ret
= ospf_vl_set_timers(vl_data
, vl_config
);
979 if (ret
!= CMD_SUCCESS
)
985 /* This stuff exists to make specifying all the alias commands A LOT simpler
987 #define VLINK_HELPSTR_IPADDR \
988 "OSPF area parameters\n" \
989 "OSPF area ID in IP address format\n" \
990 "OSPF area ID as a decimal value\n" \
991 "Configure a virtual link\n" \
992 "Router ID of the remote ABR\n"
994 #define VLINK_HELPSTR_AUTHTYPE_SIMPLE \
995 "Enable authentication on this virtual link\n" \
998 #define VLINK_HELPSTR_AUTHTYPE_ALL \
999 VLINK_HELPSTR_AUTHTYPE_SIMPLE \
1000 "Use null authentication\n" \
1001 "Use message-digest authentication\n"
1003 #define VLINK_HELPSTR_TIME_PARAM \
1004 "Time between HELLO packets\n" \
1006 "Time between retransmitting lost link state advertisements\n" \
1008 "Link state transmit delay\n" \
1010 "Interval time after which a neighbor is declared down\n" \
1013 #define VLINK_HELPSTR_AUTH_SIMPLE \
1014 "Authentication password (key)\n" \
1015 "The OSPF password (key)\n"
1017 #define VLINK_HELPSTR_AUTH_MD5 \
1018 "Message digest authentication password (key)\n" \
1020 "Use MD5 algorithm\n" \
1021 "The OSPF password (key)\n"
1023 DEFUN (ospf_area_vlink
,
1024 ospf_area_vlink_cmd
,
1025 "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>]",
1026 VLINK_HELPSTR_IPADDR
1027 "Enable authentication on this virtual link\n"
1028 "Use message-digest authentication\n"
1029 "Use null authentication\n"
1030 VLINK_HELPSTR_AUTH_MD5
1031 VLINK_HELPSTR_AUTH_SIMPLE
)
1033 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1034 int idx_ipv4_number
= 1;
1036 struct ospf_vl_config_data vl_config
;
1037 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1038 char md5_key
[OSPF_AUTH_MD5_SIZE
+ 1];
1042 ospf_vl_config_data_init(&vl_config
, vty
);
1044 /* Read off first 2 parameters and check them */
1045 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1046 &vl_config
.area_id_fmt
);
1048 vty_out(vty
, "OSPF area ID is invalid\n");
1049 return CMD_WARNING_CONFIG_FAILED
;
1052 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1054 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1055 return CMD_WARNING_CONFIG_FAILED
;
1059 /* Thats all folks! - BUGS B. strikes again!!!*/
1061 return ospf_vl_set(ospf
, &vl_config
);
1064 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1065 /* authentication - this option can only occur
1066 at start of command line */
1067 vl_config
.auth_type
= OSPF_AUTH_SIMPLE
;
1070 if (argv_find(argv
, argc
, "message-digest", &idx
)) {
1071 /* authentication message-digest */
1072 vl_config
.auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
1073 } else if (argv_find(argv
, argc
, "null", &idx
)) {
1074 /* "authentication null" */
1075 vl_config
.auth_type
= OSPF_AUTH_NULL
;
1078 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1079 vl_config
.md5_key
= NULL
;
1080 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1081 if (vl_config
.crypto_key_id
< 0)
1082 return CMD_WARNING_CONFIG_FAILED
;
1084 strlcpy(md5_key
, argv
[idx
+ 3]->arg
, sizeof(md5_key
));
1085 vl_config
.md5_key
= md5_key
;
1088 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1089 strlcpy(auth_key
, argv
[idx
+ 1]->arg
, sizeof(auth_key
));
1090 vl_config
.auth_key
= auth_key
;
1093 /* Action configuration */
1095 return ospf_vl_set(ospf
, &vl_config
);
1098 DEFUN (no_ospf_area_vlink
,
1099 no_ospf_area_vlink_cmd
,
1100 "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>]",
1102 VLINK_HELPSTR_IPADDR
1103 "Enable authentication on this virtual link\n"
1104 "Use message-digest authentication\n"
1105 "Use null authentication\n"
1106 VLINK_HELPSTR_AUTH_MD5
1107 VLINK_HELPSTR_AUTH_SIMPLE
)
1109 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1110 int idx_ipv4_number
= 2;
1112 struct ospf_area
*area
;
1113 struct ospf_vl_config_data vl_config
;
1114 struct ospf_vl_data
*vl_data
= NULL
;
1115 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1119 ospf_vl_config_data_init(&vl_config
, vty
);
1121 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1124 vty_out(vty
, "OSPF area ID is invalid\n");
1125 return CMD_WARNING_CONFIG_FAILED
;
1128 area
= ospf_area_lookup_by_area_id(ospf
, vl_config
.area_id
);
1130 vty_out(vty
, "Area does not exist\n");
1131 return CMD_WARNING_CONFIG_FAILED
;
1134 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1136 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1137 return CMD_WARNING_CONFIG_FAILED
;
1140 vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
.vl_peer
);
1142 vty_out(vty
, "Virtual link does not exist\n");
1143 return CMD_WARNING_CONFIG_FAILED
;
1147 /* Basic VLink no command */
1148 /* Thats all folks! - BUGS B. strikes again!!!*/
1149 ospf_vl_delete(ospf
, vl_data
);
1150 ospf_area_check_free(ospf
, vl_config
.area_id
);
1154 /* If we are down here, we are reseting parameters */
1155 /* Deal with other parameters */
1157 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1158 /* authentication - this option can only occur
1159 at start of command line */
1160 vl_config
.auth_type
= OSPF_AUTH_NOTSET
;
1163 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1164 vl_config
.md5_key
= NULL
;
1165 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1166 if (vl_config
.crypto_key_id
< 0)
1167 return CMD_WARNING_CONFIG_FAILED
;
1170 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1171 /* Reset authentication-key to 0 */
1172 memset(auth_key
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
1173 vl_config
.auth_key
= auth_key
;
1176 /* Action configuration */
1178 return ospf_vl_set(ospf
, &vl_config
);
1181 DEFUN (ospf_area_vlink_intervals
,
1182 ospf_area_vlink_intervals_cmd
,
1183 "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)}",
1184 VLINK_HELPSTR_IPADDR
1185 VLINK_HELPSTR_TIME_PARAM
)
1187 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1188 struct ospf_vl_config_data vl_config
;
1191 ospf_vl_config_data_init(&vl_config
, vty
);
1193 char *area_id
= argv
[1]->arg
;
1194 char *router_id
= argv
[3]->arg
;
1196 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1198 vty_out(vty
, "OSPF area ID is invalid\n");
1199 return CMD_WARNING_CONFIG_FAILED
;
1202 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1204 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1205 return CMD_WARNING_CONFIG_FAILED
;
1208 for (int idx
= 4; idx
< argc
; idx
++) {
1209 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1210 vl_config
.hello_interval
=
1211 strtol(argv
[++idx
]->arg
, NULL
, 10);
1212 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1213 vl_config
.retransmit_interval
=
1214 strtol(argv
[++idx
]->arg
, NULL
, 10);
1215 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1216 vl_config
.transmit_delay
=
1217 strtol(argv
[++idx
]->arg
, NULL
, 10);
1218 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1219 vl_config
.dead_interval
=
1220 strtol(argv
[++idx
]->arg
, NULL
, 10);
1223 /* Action configuration */
1224 return ospf_vl_set(ospf
, &vl_config
);
1227 DEFUN (no_ospf_area_vlink_intervals
,
1228 no_ospf_area_vlink_intervals_cmd
,
1229 "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)}",
1231 VLINK_HELPSTR_IPADDR
1232 VLINK_HELPSTR_TIME_PARAM
)
1234 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1235 struct ospf_vl_config_data vl_config
;
1238 ospf_vl_config_data_init(&vl_config
, vty
);
1240 char *area_id
= argv
[2]->arg
;
1241 char *router_id
= argv
[4]->arg
;
1243 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1245 vty_out(vty
, "OSPF area ID is invalid\n");
1246 return CMD_WARNING_CONFIG_FAILED
;
1249 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1251 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1252 return CMD_WARNING_CONFIG_FAILED
;
1255 for (int idx
= 5; idx
< argc
; idx
++) {
1256 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1257 vl_config
.hello_interval
= OSPF_HELLO_INTERVAL_DEFAULT
;
1258 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1259 vl_config
.retransmit_interval
=
1260 OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
1261 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1262 vl_config
.transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
1263 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1264 vl_config
.dead_interval
=
1265 OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
1268 /* Action configuration */
1269 return ospf_vl_set(ospf
, &vl_config
);
1272 DEFUN (ospf_area_shortcut
,
1273 ospf_area_shortcut_cmd
,
1274 "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>",
1275 "OSPF area parameters\n"
1276 "OSPF area ID in IP address format\n"
1277 "OSPF area ID as a decimal value\n"
1278 "Configure the area's shortcutting mode\n"
1279 "Set default shortcutting behavior\n"
1280 "Enable shortcutting through the area\n"
1281 "Disable shortcutting through the area\n")
1283 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1284 int idx_ipv4_number
= 1;
1285 int idx_enable_disable
= 3;
1286 struct ospf_area
*area
;
1287 struct in_addr area_id
;
1291 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1292 argv
[idx_ipv4_number
]->arg
);
1294 area
= ospf_area_get(ospf
, area_id
);
1295 ospf_area_display_format_set(ospf
, area
, format
);
1297 if (strncmp(argv
[idx_enable_disable
]->arg
, "de", 2) == 0)
1298 mode
= OSPF_SHORTCUT_DEFAULT
;
1299 else if (strncmp(argv
[idx_enable_disable
]->arg
, "di", 2) == 0)
1300 mode
= OSPF_SHORTCUT_DISABLE
;
1301 else if (strncmp(argv
[idx_enable_disable
]->arg
, "e", 1) == 0)
1302 mode
= OSPF_SHORTCUT_ENABLE
;
1304 return CMD_WARNING_CONFIG_FAILED
;
1306 ospf_area_shortcut_set(ospf
, area
, mode
);
1308 if (ospf
->abr_type
!= OSPF_ABR_SHORTCUT
)
1310 "Shortcut area setting will take effect only when the router is configured as Shortcut ABR\n");
1315 DEFUN (no_ospf_area_shortcut
,
1316 no_ospf_area_shortcut_cmd
,
1317 "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>",
1319 "OSPF area parameters\n"
1320 "OSPF area ID in IP address format\n"
1321 "OSPF area ID as a decimal value\n"
1322 "Deconfigure the area's shortcutting mode\n"
1323 "Deconfigure enabled shortcutting through the area\n"
1324 "Deconfigure disabled shortcutting through the area\n")
1326 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1327 int idx_ipv4_number
= 2;
1328 struct ospf_area
*area
;
1329 struct in_addr area_id
;
1332 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1333 argv
[idx_ipv4_number
]->arg
);
1335 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1339 ospf_area_shortcut_unset(ospf
, area
);
1345 DEFUN (ospf_area_stub
,
1347 "area <A.B.C.D|(0-4294967295)> stub",
1348 "OSPF area parameters\n"
1349 "OSPF area ID in IP address format\n"
1350 "OSPF area ID as a decimal value\n"
1351 "Configure OSPF area as stub\n")
1353 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1354 int idx_ipv4_number
= 1;
1355 struct in_addr area_id
;
1358 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1359 argv
[idx_ipv4_number
]->arg
);
1361 ret
= ospf_area_stub_set(ospf
, area_id
);
1362 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1366 "First deconfigure all virtual link through this area\n");
1367 return CMD_WARNING_CONFIG_FAILED
;
1370 /* Flush the external LSAs from the specified area */
1371 ospf_flush_lsa_from_area(ospf
, area_id
, OSPF_AS_EXTERNAL_LSA
);
1372 ospf_area_no_summary_unset(ospf
, area_id
);
1377 DEFUN (ospf_area_stub_no_summary
,
1378 ospf_area_stub_no_summary_cmd
,
1379 "area <A.B.C.D|(0-4294967295)> stub no-summary",
1380 "OSPF stub parameters\n"
1381 "OSPF area ID in IP address format\n"
1382 "OSPF area ID as a decimal value\n"
1383 "Configure OSPF area as stub\n"
1384 "Do not inject inter-area routes into stub\n")
1386 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1387 int idx_ipv4_number
= 1;
1388 struct in_addr area_id
;
1391 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1392 argv
[idx_ipv4_number
]->arg
);
1394 ret
= ospf_area_stub_set(ospf
, area_id
);
1395 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1399 "%% Area cannot be stub as it contains a virtual link\n");
1400 return CMD_WARNING_CONFIG_FAILED
;
1403 ospf_area_no_summary_set(ospf
, area_id
);
1408 DEFUN (no_ospf_area_stub
,
1409 no_ospf_area_stub_cmd
,
1410 "no area <A.B.C.D|(0-4294967295)> stub",
1412 "OSPF area parameters\n"
1413 "OSPF area ID in IP address format\n"
1414 "OSPF area ID as a decimal value\n"
1415 "Configure OSPF area as stub\n")
1417 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1418 int idx_ipv4_number
= 2;
1419 struct in_addr area_id
;
1422 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1423 argv
[idx_ipv4_number
]->arg
);
1425 ospf_area_stub_unset(ospf
, area_id
);
1426 ospf_area_no_summary_unset(ospf
, area_id
);
1431 DEFUN (no_ospf_area_stub_no_summary
,
1432 no_ospf_area_stub_no_summary_cmd
,
1433 "no area <A.B.C.D|(0-4294967295)> stub no-summary",
1435 "OSPF area parameters\n"
1436 "OSPF area ID in IP address format\n"
1437 "OSPF area ID as a decimal value\n"
1438 "Configure OSPF area as stub\n"
1439 "Do not inject inter-area routes into area\n")
1441 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1442 int idx_ipv4_number
= 2;
1443 struct in_addr area_id
;
1446 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1447 argv
[idx_ipv4_number
]->arg
);
1448 ospf_area_no_summary_unset(ospf
, area_id
);
1453 DEFPY (ospf_area_nssa
,
1455 "area <A.B.C.D|(0-4294967295)>$area_str nssa\
1457 <translate-candidate|translate-never|translate-always>$translator_role\
1458 |default-information-originate$dflt_originate [{metric (0-16777214)$mval|metric-type (1-2)$mtype}]\
1459 |no-summary$no_summary\
1460 |suppress-fa$suppress_fa\
1462 "OSPF area parameters\n"
1463 "OSPF area ID in IP address format\n"
1464 "OSPF area ID as a decimal value\n"
1465 "Configure OSPF area as nssa\n"
1466 "Configure NSSA-ABR for translate election (default)\n"
1467 "Configure NSSA-ABR to never translate\n"
1468 "Configure NSSA-ABR to always translate\n"
1469 "Originate Type 7 default into NSSA area\n"
1470 "OSPF default metric\n"
1472 "OSPF metric type for default routes\n"
1473 "Set OSPF External Type 1/2 metrics\n"
1474 "Do not inject inter-area routes into nssa\n"
1475 "Suppress forwarding address\n")
1477 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1478 struct in_addr area_id
;
1481 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
, area_str
);
1483 ret
= ospf_area_nssa_set(ospf
, area_id
);
1484 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1488 "%% Area cannot be nssa as it contains a virtual link\n");
1489 return CMD_WARNING_CONFIG_FAILED
;
1492 if (translator_role
) {
1493 if (strncmp(translator_role
, "translate-c", 11) == 0)
1494 ospf_area_nssa_translator_role_set(
1495 ospf
, area_id
, OSPF_NSSA_ROLE_CANDIDATE
);
1496 else if (strncmp(translator_role
, "translate-n", 11) == 0)
1497 ospf_area_nssa_translator_role_set(
1498 ospf
, area_id
, OSPF_NSSA_ROLE_NEVER
);
1499 else if (strncmp(translator_role
, "translate-a", 11) == 0)
1500 ospf_area_nssa_translator_role_set(
1501 ospf
, area_id
, OSPF_NSSA_ROLE_ALWAYS
);
1503 ospf_area_nssa_translator_role_set(ospf
, area_id
,
1504 OSPF_NSSA_ROLE_CANDIDATE
);
1507 if (dflt_originate
) {
1508 int metric_type
= DEFAULT_METRIC_TYPE
;
1510 if (mval_str
== NULL
)
1513 (void)str2metric_type(mtype_str
, &metric_type
);
1514 ospf_area_nssa_default_originate_set(ospf
, area_id
, mval
,
1517 ospf_area_nssa_default_originate_unset(ospf
, area_id
);
1520 ospf_area_nssa_no_summary_set(ospf
, area_id
);
1522 ospf_area_no_summary_unset(ospf
, area_id
);
1525 ospf_area_nssa_suppress_fa_set(ospf
, area_id
);
1527 ospf_area_nssa_suppress_fa_unset(ospf
, area_id
);
1529 /* Flush the external LSA for the specified area */
1530 ospf_flush_lsa_from_area(ospf
, area_id
, OSPF_AS_EXTERNAL_LSA
);
1531 ospf_schedule_abr_task(ospf
);
1532 ospf_schedule_asbr_nssa_redist_update(ospf
);
1537 DEFPY (no_ospf_area_nssa
,
1538 no_ospf_area_nssa_cmd
,
1539 "no area <A.B.C.D|(0-4294967295)>$area_str nssa\
1541 <translate-candidate|translate-never|translate-always>\
1542 |default-information-originate [{metric (0-16777214)|metric-type (1-2)}]\
1547 "OSPF area parameters\n"
1548 "OSPF area ID in IP address format\n"
1549 "OSPF area ID as a decimal value\n"
1550 "Configure OSPF area as nssa\n"
1551 "Configure NSSA-ABR for translate election (default)\n"
1552 "Configure NSSA-ABR to never translate\n"
1553 "Configure NSSA-ABR to always translate\n"
1554 "Originate Type 7 default into NSSA area\n"
1555 "OSPF default metric\n"
1557 "OSPF metric type for default routes\n"
1558 "Set OSPF External Type 1/2 metrics\n"
1559 "Do not inject inter-area routes into nssa\n"
1560 "Suppress forwarding address\n")
1562 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1563 struct in_addr area_id
;
1566 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
, area_str
);
1568 /* Flush the NSSA LSA for the specified area */
1569 ospf_flush_lsa_from_area(ospf
, area_id
, OSPF_AS_NSSA_LSA
);
1570 ospf_area_no_summary_unset(ospf
, area_id
);
1571 ospf_area_nssa_default_originate_unset(ospf
, area_id
);
1572 ospf_area_nssa_suppress_fa_unset(ospf
, area_id
);
1573 ospf_area_nssa_unset(ospf
, area_id
);
1575 ospf_schedule_abr_task(ospf
);
1580 DEFPY (ospf_area_nssa_range
,
1581 ospf_area_nssa_range_cmd
,
1582 "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>]",
1583 "OSPF area parameters\n"
1584 "OSPF area ID in IP address format\n"
1585 "OSPF area ID as a decimal value\n"
1586 "Configure OSPF area as nssa\n"
1587 "Configured address range\n"
1588 "Specify IPv4 prefix\n"
1589 "Do not advertise\n"
1590 "User specified metric for this range\n"
1591 "Advertised metric for this range\n")
1593 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1594 struct ospf_area
*area
;
1595 struct in_addr area_id
;
1599 VTY_GET_OSPF_AREA_ID(area_id
, format
, area_str
);
1600 area
= ospf_area_get(ospf
, area_id
);
1601 ospf_area_display_format_set(ospf
, area
, format
);
1603 if (area
->external_routing
!= OSPF_AREA_NSSA
) {
1604 vty_out(vty
, "%% First configure %s as an NSSA area\n",
1610 advertise
= OSPF_AREA_RANGE_ADVERTISE
;
1612 ospf_area_range_set(ospf
, area
, area
->nssa_ranges
,
1613 (struct prefix_ipv4
*)prefix
, advertise
, true);
1615 ospf_area_range_cost_set(ospf
, area
, area
->nssa_ranges
,
1616 (struct prefix_ipv4
*)prefix
, cost
);
1621 DEFPY (no_ospf_area_nssa_range
,
1622 no_ospf_area_nssa_range_cmd
,
1623 "no area <A.B.C.D|(0-4294967295)>$area_str nssa range A.B.C.D/M$prefix [<not-advertise|cost (0-16777215)>]",
1625 "OSPF area parameters\n"
1626 "OSPF area ID in IP address format\n"
1627 "OSPF area ID as a decimal value\n"
1628 "Configure OSPF area as nssa\n"
1629 "Configured address range\n"
1630 "Specify IPv4 prefix\n"
1631 "Do not advertise\n"
1632 "User specified metric for this range\n"
1633 "Advertised metric for this range\n")
1635 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1636 struct ospf_area
*area
;
1637 struct in_addr area_id
;
1640 VTY_GET_OSPF_AREA_ID(area_id
, format
, area_str
);
1641 area
= ospf_area_get(ospf
, area_id
);
1642 ospf_area_display_format_set(ospf
, area
, format
);
1644 if (area
->external_routing
!= OSPF_AREA_NSSA
) {
1645 vty_out(vty
, "%% First configure %s as an NSSA area\n",
1650 ospf_area_range_unset(ospf
, area
, area
->nssa_ranges
,
1651 (struct prefix_ipv4
*)prefix
);
1656 DEFUN (ospf_area_default_cost
,
1657 ospf_area_default_cost_cmd
,
1658 "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1659 "OSPF area parameters\n"
1660 "OSPF area ID in IP address format\n"
1661 "OSPF area ID as a decimal value\n"
1662 "Set the summary-default cost of a NSSA or stub area\n"
1663 "Stub's advertised default summary cost\n")
1665 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1666 int idx_ipv4_number
= 1;
1668 struct ospf_area
*area
;
1669 struct in_addr area_id
;
1672 struct prefix_ipv4 p
;
1674 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1675 argv
[idx_ipv4_number
]->arg
);
1676 cost
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1678 area
= ospf_area_get(ospf
, area_id
);
1679 ospf_area_display_format_set(ospf
, area
, format
);
1681 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1682 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1683 return CMD_WARNING_CONFIG_FAILED
;
1686 area
->default_cost
= cost
;
1689 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1691 if (IS_DEBUG_OSPF_EVENT
)
1693 "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4",
1695 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1700 DEFUN (no_ospf_area_default_cost
,
1701 no_ospf_area_default_cost_cmd
,
1702 "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1704 "OSPF area parameters\n"
1705 "OSPF area ID in IP address format\n"
1706 "OSPF area ID as a decimal value\n"
1707 "Set the summary-default cost of a NSSA or stub area\n"
1708 "Stub's advertised default summary cost\n")
1710 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1711 int idx_ipv4_number
= 2;
1712 struct ospf_area
*area
;
1713 struct in_addr area_id
;
1715 struct prefix_ipv4 p
;
1717 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1718 argv
[idx_ipv4_number
]->arg
);
1720 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1724 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1725 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1726 return CMD_WARNING_CONFIG_FAILED
;
1729 area
->default_cost
= 1;
1732 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1734 if (IS_DEBUG_OSPF_EVENT
)
1736 "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4",
1738 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1741 ospf_area_check_free(ospf
, area_id
);
1746 DEFUN (ospf_area_export_list
,
1747 ospf_area_export_list_cmd
,
1748 "area <A.B.C.D|(0-4294967295)> export-list ACCESSLIST4_NAME",
1749 "OSPF area parameters\n"
1750 "OSPF area ID in IP address format\n"
1751 "OSPF area ID as a decimal value\n"
1752 "Set the filter for networks announced to other areas\n"
1753 "Name of the access-list\n")
1755 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1756 int idx_ipv4_number
= 1;
1757 struct ospf_area
*area
;
1758 struct in_addr area_id
;
1761 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1763 area
= ospf_area_get(ospf
, area_id
);
1764 ospf_area_display_format_set(ospf
, area
, format
);
1765 ospf_area_export_list_set(ospf
, area
, argv
[3]->arg
);
1770 DEFUN (no_ospf_area_export_list
,
1771 no_ospf_area_export_list_cmd
,
1772 "no area <A.B.C.D|(0-4294967295)> export-list ACCESSLIST4_NAME",
1774 "OSPF area parameters\n"
1775 "OSPF area ID in IP address format\n"
1776 "OSPF area ID as a decimal value\n"
1777 "Unset the filter for networks announced to other areas\n"
1778 "Name of the access-list\n")
1780 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1781 int idx_ipv4_number
= 2;
1782 struct ospf_area
*area
;
1783 struct in_addr area_id
;
1786 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1788 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1792 ospf_area_export_list_unset(ospf
, area
);
1798 DEFUN (ospf_area_import_list
,
1799 ospf_area_import_list_cmd
,
1800 "area <A.B.C.D|(0-4294967295)> import-list ACCESSLIST4_NAME",
1801 "OSPF area parameters\n"
1802 "OSPF area ID in IP address format\n"
1803 "OSPF area ID as a decimal value\n"
1804 "Set the filter for networks from other areas announced to the specified one\n"
1805 "Name of the access-list\n")
1807 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1808 int idx_ipv4_number
= 1;
1809 struct ospf_area
*area
;
1810 struct in_addr area_id
;
1813 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1815 area
= ospf_area_get(ospf
, area_id
);
1816 ospf_area_display_format_set(ospf
, area
, format
);
1817 ospf_area_import_list_set(ospf
, area
, argv
[3]->arg
);
1822 DEFUN (no_ospf_area_import_list
,
1823 no_ospf_area_import_list_cmd
,
1824 "no area <A.B.C.D|(0-4294967295)> import-list ACCESSLIST4_NAME",
1826 "OSPF area parameters\n"
1827 "OSPF area ID in IP address format\n"
1828 "OSPF area ID as a decimal value\n"
1829 "Unset the filter for networks announced to other areas\n"
1830 "Name of the access-list\n")
1832 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1833 int idx_ipv4_number
= 2;
1834 struct ospf_area
*area
;
1835 struct in_addr area_id
;
1838 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1840 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1844 ospf_area_import_list_unset(ospf
, area
);
1849 DEFUN (ospf_area_filter_list
,
1850 ospf_area_filter_list_cmd
,
1851 "area <A.B.C.D|(0-4294967295)> filter-list prefix PREFIXLIST_NAME <in|out>",
1852 "OSPF area parameters\n"
1853 "OSPF area ID in IP address format\n"
1854 "OSPF area ID as a decimal value\n"
1855 "Filter networks between OSPF areas\n"
1856 "Filter prefixes between OSPF areas\n"
1857 "Name of an IP prefix-list\n"
1858 "Filter networks sent to this area\n"
1859 "Filter networks sent from this area\n")
1861 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1862 int idx_ipv4_number
= 1;
1865 struct ospf_area
*area
;
1866 struct in_addr area_id
;
1867 struct prefix_list
*plist
;
1870 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1872 area
= ospf_area_get(ospf
, area_id
);
1873 ospf_area_display_format_set(ospf
, area
, format
);
1874 plist
= prefix_list_lookup(AFI_IP
, argv
[idx_word
]->arg
);
1875 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1876 PREFIX_LIST_IN(area
) = plist
;
1877 if (PREFIX_NAME_IN(area
))
1878 free(PREFIX_NAME_IN(area
));
1880 PREFIX_NAME_IN(area
) = strdup(argv
[idx_word
]->arg
);
1881 ospf_schedule_abr_task(ospf
);
1883 PREFIX_LIST_OUT(area
) = plist
;
1884 if (PREFIX_NAME_OUT(area
))
1885 free(PREFIX_NAME_OUT(area
));
1887 PREFIX_NAME_OUT(area
) = strdup(argv
[idx_word
]->arg
);
1888 ospf_schedule_abr_task(ospf
);
1894 DEFUN (no_ospf_area_filter_list
,
1895 no_ospf_area_filter_list_cmd
,
1896 "no area <A.B.C.D|(0-4294967295)> filter-list prefix PREFIXLIST_NAME <in|out>",
1898 "OSPF area parameters\n"
1899 "OSPF area ID in IP address format\n"
1900 "OSPF area ID as a decimal value\n"
1901 "Filter networks between OSPF areas\n"
1902 "Filter prefixes between OSPF areas\n"
1903 "Name of an IP prefix-list\n"
1904 "Filter networks sent to this area\n"
1905 "Filter networks sent from this area\n")
1907 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1908 int idx_ipv4_number
= 2;
1911 struct ospf_area
*area
;
1912 struct in_addr area_id
;
1915 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1917 if ((area
= ospf_area_lookup_by_area_id(ospf
, area_id
)) == NULL
)
1920 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1921 if (PREFIX_NAME_IN(area
))
1922 if (strcmp(PREFIX_NAME_IN(area
), argv
[idx_word
]->arg
)
1926 PREFIX_LIST_IN(area
) = NULL
;
1927 if (PREFIX_NAME_IN(area
))
1928 free(PREFIX_NAME_IN(area
));
1930 PREFIX_NAME_IN(area
) = NULL
;
1932 ospf_schedule_abr_task(ospf
);
1934 if (PREFIX_NAME_OUT(area
))
1935 if (strcmp(PREFIX_NAME_OUT(area
), argv
[idx_word
]->arg
)
1939 PREFIX_LIST_OUT(area
) = NULL
;
1940 if (PREFIX_NAME_OUT(area
))
1941 free(PREFIX_NAME_OUT(area
));
1943 PREFIX_NAME_OUT(area
) = NULL
;
1945 ospf_schedule_abr_task(ospf
);
1952 DEFUN (ospf_area_authentication_message_digest
,
1953 ospf_area_authentication_message_digest_cmd
,
1954 "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest",
1956 "OSPF area parameters\n"
1957 "OSPF area ID in IP address format\n"
1958 "OSPF area ID as a decimal value\n"
1959 "Enable authentication\n"
1960 "Use message-digest authentication\n")
1962 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1964 struct ospf_area
*area
;
1965 struct in_addr area_id
;
1968 argv_find(argv
, argc
, "area", &idx
);
1969 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx
+ 1]->arg
);
1971 area
= ospf_area_get(ospf
, area_id
);
1972 ospf_area_display_format_set(ospf
, area
, format
);
1973 area
->auth_type
= strmatch(argv
[0]->text
, "no")
1975 : OSPF_AUTH_CRYPTOGRAPHIC
;
1980 DEFUN (ospf_area_authentication
,
1981 ospf_area_authentication_cmd
,
1982 "area <A.B.C.D|(0-4294967295)> authentication",
1983 "OSPF area parameters\n"
1984 "OSPF area ID in IP address format\n"
1985 "OSPF area ID as a decimal value\n"
1986 "Enable authentication\n")
1988 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1989 int idx_ipv4_number
= 1;
1990 struct ospf_area
*area
;
1991 struct in_addr area_id
;
1994 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1996 area
= ospf_area_get(ospf
, area_id
);
1997 ospf_area_display_format_set(ospf
, area
, format
);
1998 area
->auth_type
= OSPF_AUTH_SIMPLE
;
2003 DEFUN (no_ospf_area_authentication
,
2004 no_ospf_area_authentication_cmd
,
2005 "no area <A.B.C.D|(0-4294967295)> authentication",
2007 "OSPF area parameters\n"
2008 "OSPF area ID in IP address format\n"
2009 "OSPF area ID as a decimal value\n"
2010 "Enable authentication\n")
2012 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2013 int idx_ipv4_number
= 2;
2014 struct ospf_area
*area
;
2015 struct in_addr area_id
;
2018 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
2020 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
2024 area
->auth_type
= OSPF_AUTH_NULL
;
2026 ospf_area_check_free(ospf
, area_id
);
2032 DEFUN (ospf_abr_type
,
2034 "ospf abr-type <cisco|ibm|shortcut|standard>",
2035 "OSPF specific commands\n"
2036 "Set OSPF ABR type\n"
2037 "Alternative ABR, cisco implementation\n"
2038 "Alternative ABR, IBM implementation\n"
2040 "Standard behavior (RFC2328)\n")
2042 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2044 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2046 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2047 abr_type
= OSPF_ABR_CISCO
;
2048 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2049 abr_type
= OSPF_ABR_IBM
;
2050 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2051 abr_type
= OSPF_ABR_SHORTCUT
;
2052 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2053 abr_type
= OSPF_ABR_STAND
;
2055 return CMD_WARNING_CONFIG_FAILED
;
2057 /* If ABR type value is changed, schedule ABR task. */
2058 if (ospf
->abr_type
!= abr_type
) {
2059 ospf
->abr_type
= abr_type
;
2060 ospf_schedule_abr_task(ospf
);
2066 DEFUN (no_ospf_abr_type
,
2067 no_ospf_abr_type_cmd
,
2068 "no ospf abr-type <cisco|ibm|shortcut|standard>",
2070 "OSPF specific commands\n"
2071 "Set OSPF ABR type\n"
2072 "Alternative ABR, cisco implementation\n"
2073 "Alternative ABR, IBM implementation\n"
2077 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2079 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2081 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2082 abr_type
= OSPF_ABR_CISCO
;
2083 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2084 abr_type
= OSPF_ABR_IBM
;
2085 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2086 abr_type
= OSPF_ABR_SHORTCUT
;
2087 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2088 abr_type
= OSPF_ABR_STAND
;
2090 return CMD_WARNING_CONFIG_FAILED
;
2092 /* If ABR type value is changed, schedule ABR task. */
2093 if (ospf
->abr_type
== abr_type
) {
2094 ospf
->abr_type
= OSPF_ABR_DEFAULT
;
2095 ospf_schedule_abr_task(ospf
);
2101 DEFUN (ospf_log_adjacency_changes
,
2102 ospf_log_adjacency_changes_cmd
,
2103 "log-adjacency-changes",
2104 "Log changes in adjacency state\n")
2106 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2108 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2109 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2113 DEFUN (ospf_log_adjacency_changes_detail
,
2114 ospf_log_adjacency_changes_detail_cmd
,
2115 "log-adjacency-changes detail",
2116 "Log changes in adjacency state\n"
2117 "Log all state changes\n")
2119 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2121 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2122 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2126 DEFUN (no_ospf_log_adjacency_changes
,
2127 no_ospf_log_adjacency_changes_cmd
,
2128 "no log-adjacency-changes",
2130 "Log changes in adjacency state\n")
2132 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2134 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2135 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2139 DEFUN (no_ospf_log_adjacency_changes_detail
,
2140 no_ospf_log_adjacency_changes_detail_cmd
,
2141 "no log-adjacency-changes detail",
2143 "Log changes in adjacency state\n"
2144 "Log all state changes\n")
2146 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2148 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2152 DEFUN (ospf_compatible_rfc1583
,
2153 ospf_compatible_rfc1583_cmd
,
2154 "compatible rfc1583",
2155 "OSPF compatibility list\n"
2156 "compatible with RFC 1583\n")
2158 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2160 if (!CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2161 SET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2162 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2167 DEFUN (no_ospf_compatible_rfc1583
,
2168 no_ospf_compatible_rfc1583_cmd
,
2169 "no compatible rfc1583",
2171 "OSPF compatibility list\n"
2172 "compatible with RFC 1583\n")
2174 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2176 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2177 UNSET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2178 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2183 ALIAS(ospf_compatible_rfc1583
, ospf_rfc1583_flag_cmd
,
2184 "ospf rfc1583compatibility",
2185 "OSPF specific commands\n"
2186 "Enable the RFC1583Compatibility flag\n")
2188 ALIAS(no_ospf_compatible_rfc1583
, no_ospf_rfc1583_flag_cmd
,
2189 "no ospf rfc1583compatibility", NO_STR
2190 "OSPF specific commands\n"
2191 "Disable the RFC1583Compatibility flag\n")
2193 static void ospf_table_reinstall_routes(struct ospf
*ospf
,
2194 struct route_table
*rt
)
2196 struct route_node
*rn
;
2201 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
2202 struct ospf_route
*or;
2208 if (or->type
== OSPF_DESTINATION_NETWORK
)
2209 ospf_zebra_add(ospf
, (struct prefix_ipv4
*)&rn
->p
, or);
2210 else if (or->type
== OSPF_DESTINATION_DISCARD
)
2211 ospf_zebra_add_discard(ospf
,
2212 (struct prefix_ipv4
*)&rn
->p
);
2216 static void ospf_reinstall_routes(struct ospf
*ospf
)
2218 ospf_table_reinstall_routes(ospf
, ospf
->new_table
);
2219 ospf_table_reinstall_routes(ospf
, ospf
->new_external_route
);
2222 DEFPY (ospf_send_extra_data
,
2223 ospf_send_extra_data_cmd
,
2224 "[no] ospf send-extra-data zebra",
2227 "Extra data to Zebra for display/use\n"
2230 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2232 if (no
&& CHECK_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
)) {
2233 UNSET_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
);
2234 ospf_reinstall_routes(ospf
);
2235 } else if (!CHECK_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
)) {
2236 SET_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
);
2237 ospf_reinstall_routes(ospf
);
2243 static int ospf_timers_spf_set(struct vty
*vty
, unsigned int delay
,
2244 unsigned int hold
, unsigned int max
)
2246 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2248 ospf
->spf_delay
= delay
;
2249 ospf
->spf_holdtime
= hold
;
2250 ospf
->spf_max_holdtime
= max
;
2255 DEFUN (ospf_timers_min_ls_interval
,
2256 ospf_timers_min_ls_interval_cmd
,
2257 "timers throttle lsa all (0-5000)",
2258 "Adjust routing timers\n"
2259 "Throttling adaptive timer\n"
2260 "LSA delay between transmissions\n"
2262 "Delay (msec) between sending LSAs\n")
2264 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2266 unsigned int interval
;
2269 vty_out(vty
, "Insufficient arguments\n");
2270 return CMD_WARNING_CONFIG_FAILED
;
2273 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2275 ospf
->min_ls_interval
= interval
;
2280 DEFUN (no_ospf_timers_min_ls_interval
,
2281 no_ospf_timers_min_ls_interval_cmd
,
2282 "no timers throttle lsa all [(0-5000)]",
2284 "Adjust routing timers\n"
2285 "Throttling adaptive timer\n"
2286 "LSA delay between transmissions\n"
2288 "Delay (msec) between sending LSAs\n")
2290 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2291 ospf
->min_ls_interval
= OSPF_MIN_LS_INTERVAL
;
2296 DEFUN (ospf_timers_throttle_spf
,
2297 ospf_timers_throttle_spf_cmd
,
2298 "timers throttle spf (0-600000) (0-600000) (0-600000)",
2299 "Adjust routing timers\n"
2300 "Throttling adaptive timer\n"
2302 "Delay (msec) from first change received till SPF calculation\n"
2303 "Initial hold time (msec) between consecutive SPF calculations\n"
2304 "Maximum hold time (msec)\n")
2307 int idx_number_2
= 4;
2308 int idx_number_3
= 5;
2309 unsigned int delay
, hold
, max
;
2312 vty_out(vty
, "Insufficient arguments\n");
2313 return CMD_WARNING_CONFIG_FAILED
;
2316 delay
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2317 hold
= strtoul(argv
[idx_number_2
]->arg
, NULL
, 10);
2318 max
= strtoul(argv
[idx_number_3
]->arg
, NULL
, 10);
2320 return ospf_timers_spf_set(vty
, delay
, hold
, max
);
2323 DEFUN (no_ospf_timers_throttle_spf
,
2324 no_ospf_timers_throttle_spf_cmd
,
2325 "no timers throttle spf [(0-600000)(0-600000)(0-600000)]",
2327 "Adjust routing timers\n"
2328 "Throttling adaptive timer\n"
2330 "Delay (msec) from first change received till SPF calculation\n"
2331 "Initial hold time (msec) between consecutive SPF calculations\n"
2332 "Maximum hold time (msec)\n")
2334 return ospf_timers_spf_set(vty
, OSPF_SPF_DELAY_DEFAULT
,
2335 OSPF_SPF_HOLDTIME_DEFAULT
,
2336 OSPF_SPF_MAX_HOLDTIME_DEFAULT
);
2340 DEFUN (ospf_timers_lsa_min_arrival
,
2341 ospf_timers_lsa_min_arrival_cmd
,
2342 "timers lsa min-arrival (0-600000)",
2343 "Adjust routing timers\n"
2345 "Minimum delay in receiving new version of a LSA\n"
2346 "Delay in milliseconds\n")
2348 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2349 ospf
->min_ls_arrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2353 DEFUN (no_ospf_timers_lsa_min_arrival
,
2354 no_ospf_timers_lsa_min_arrival_cmd
,
2355 "no timers lsa min-arrival [(0-600000)]",
2357 "Adjust routing timers\n"
2359 "Minimum delay in receiving new version of a LSA\n"
2360 "Delay in milliseconds\n")
2362 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2363 unsigned int minarrival
;
2366 minarrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2368 if (ospf
->min_ls_arrival
!= minarrival
2369 || minarrival
== OSPF_MIN_LS_ARRIVAL
)
2373 ospf
->min_ls_arrival
= OSPF_MIN_LS_ARRIVAL
;
2378 DEFUN (ospf_neighbor
,
2380 "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]",
2382 "Neighbor IP address\n"
2383 "Neighbor Priority\n"
2385 "Dead Neighbor Polling interval\n"
2388 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2392 struct in_addr nbr_addr
;
2393 unsigned int priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2394 unsigned int interval
= OSPF_POLL_INTERVAL_DEFAULT
;
2396 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2397 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2398 return CMD_WARNING_CONFIG_FAILED
;
2402 priority
= strtoul(argv
[idx_pri
]->arg
, NULL
, 10);
2405 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2407 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2410 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2413 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2418 DEFUN (ospf_neighbor_poll_interval
,
2419 ospf_neighbor_poll_interval_cmd
,
2420 "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2422 "Neighbor IP address\n"
2423 "Dead Neighbor Polling interval\n"
2425 "OSPF priority of non-broadcast neighbor\n"
2428 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2432 struct in_addr nbr_addr
;
2433 unsigned int priority
;
2434 unsigned int interval
;
2436 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2437 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2438 return CMD_WARNING_CONFIG_FAILED
;
2441 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2443 priority
= argc
> 4 ? strtoul(argv
[idx_pri
]->arg
, NULL
, 10)
2444 : OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2446 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2447 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2450 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2455 DEFUN (no_ospf_neighbor
,
2456 no_ospf_neighbor_cmd
,
2457 "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]",
2460 "Neighbor IP address\n"
2461 "Neighbor Priority\n"
2463 "Dead Neighbor Polling interval\n"
2466 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2468 struct in_addr nbr_addr
;
2470 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2471 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2472 return CMD_WARNING_CONFIG_FAILED
;
2475 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2480 DEFUN (no_ospf_neighbor_poll
,
2481 no_ospf_neighbor_poll_cmd
,
2482 "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2485 "Neighbor IP address\n"
2486 "Dead Neighbor Polling interval\n"
2488 "Neighbor Priority\n"
2491 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2493 struct in_addr nbr_addr
;
2495 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2496 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2497 return CMD_WARNING_CONFIG_FAILED
;
2500 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2505 DEFUN (ospf_refresh_timer
,
2506 ospf_refresh_timer_cmd
,
2507 "refresh timer (10-1800)",
2508 "Adjust refresh parameters\n"
2509 "Set refresh timer\n"
2510 "Timer value in seconds\n")
2512 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2514 unsigned int interval
;
2516 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2517 interval
= (interval
/ OSPF_LSA_REFRESHER_GRANULARITY
)
2518 * OSPF_LSA_REFRESHER_GRANULARITY
;
2520 ospf_timers_refresh_set(ospf
, interval
);
2525 DEFUN (no_ospf_refresh_timer
,
2526 no_ospf_refresh_timer_val_cmd
,
2527 "no refresh timer [(10-1800)]",
2529 "Adjust refresh parameters\n"
2530 "Unset refresh timer\n"
2531 "Timer value in seconds\n")
2533 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2535 unsigned int interval
;
2538 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2540 if (ospf
->lsa_refresh_interval
!= interval
2541 || interval
== OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
2545 ospf_timers_refresh_unset(ospf
);
2551 DEFUN (ospf_auto_cost_reference_bandwidth
,
2552 ospf_auto_cost_reference_bandwidth_cmd
,
2553 "auto-cost reference-bandwidth (1-4294967)",
2554 "Calculate OSPF interface cost according to bandwidth\n"
2555 "Use reference bandwidth method to assign OSPF cost\n"
2556 "The reference bandwidth in terms of Mbits per second\n")
2558 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2559 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2562 struct interface
*ifp
;
2564 refbw
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2565 if (refbw
< 1 || refbw
> 4294967) {
2566 vty_out(vty
, "reference-bandwidth value is invalid\n");
2567 return CMD_WARNING_CONFIG_FAILED
;
2570 /* If reference bandwidth is changed. */
2571 if ((refbw
) == ospf
->ref_bandwidth
)
2574 ospf
->ref_bandwidth
= refbw
;
2575 FOR_ALL_INTERFACES (vrf
, ifp
)
2576 ospf_if_recalculate_output_cost(ifp
);
2581 DEFUN (no_ospf_auto_cost_reference_bandwidth
,
2582 no_ospf_auto_cost_reference_bandwidth_cmd
,
2583 "no auto-cost reference-bandwidth [(1-4294967)]",
2585 "Calculate OSPF interface cost according to bandwidth\n"
2586 "Use reference bandwidth method to assign OSPF cost\n"
2587 "The reference bandwidth in terms of Mbits per second\n")
2589 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2590 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2591 struct interface
*ifp
;
2593 if (ospf
->ref_bandwidth
== OSPF_DEFAULT_REF_BANDWIDTH
)
2596 ospf
->ref_bandwidth
= OSPF_DEFAULT_REF_BANDWIDTH
;
2597 vty_out(vty
, "%% OSPF: Reference bandwidth is changed.\n");
2599 " Please ensure reference bandwidth is consistent across all routers\n");
2601 FOR_ALL_INTERFACES (vrf
, ifp
)
2602 ospf_if_recalculate_output_cost(ifp
);
2607 DEFUN (ospf_write_multiplier
,
2608 ospf_write_multiplier_cmd
,
2609 "ospf write-multiplier (1-100)",
2610 "OSPF specific commands\n"
2611 "Write multiplier\n"
2612 "Maximum number of interface serviced per write\n")
2614 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2616 uint32_t write_oi_count
;
2623 write_oi_count
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2624 if (write_oi_count
< 1 || write_oi_count
> 100) {
2625 vty_out(vty
, "write-multiplier value is invalid\n");
2626 return CMD_WARNING_CONFIG_FAILED
;
2629 ospf
->write_oi_count
= write_oi_count
;
2633 ALIAS(ospf_write_multiplier
, write_multiplier_cmd
, "write-multiplier (1-100)",
2634 "Write multiplier\n"
2635 "Maximum number of interface serviced per write\n")
2637 DEFUN (no_ospf_write_multiplier
,
2638 no_ospf_write_multiplier_cmd
,
2639 "no ospf write-multiplier (1-100)",
2641 "OSPF specific commands\n"
2642 "Write multiplier\n"
2643 "Maximum number of interface serviced per write\n")
2645 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2647 ospf
->write_oi_count
= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
;
2651 ALIAS(no_ospf_write_multiplier
, no_write_multiplier_cmd
,
2652 "no write-multiplier (1-100)", NO_STR
2653 "Write multiplier\n"
2654 "Maximum number of interface serviced per write\n")
2656 DEFUN(ospf_ti_lfa
, ospf_ti_lfa_cmd
, "fast-reroute ti-lfa [node-protection]",
2657 "Fast Reroute for MPLS and IP resilience\n"
2658 "Topology Independent LFA (Loop-Free Alternate)\n"
2659 "TI-LFA node protection (default is link protection)\n")
2661 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2663 ospf
->ti_lfa_enabled
= true;
2666 ospf
->ti_lfa_protection_type
= OSPF_TI_LFA_NODE_PROTECTION
;
2668 ospf
->ti_lfa_protection_type
= OSPF_TI_LFA_LINK_PROTECTION
;
2670 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2675 DEFUN(no_ospf_ti_lfa
, no_ospf_ti_lfa_cmd
,
2676 "no fast-reroute ti-lfa [node-protection]",
2678 "Fast Reroute for MPLS and IP resilience\n"
2679 "Topology Independent LFA (Loop-Free Alternate)\n"
2680 "TI-LFA node protection (default is link protection)\n")
2682 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2684 ospf
->ti_lfa_enabled
= false;
2686 ospf
->ti_lfa_protection_type
= OSPF_TI_LFA_UNDEFINED_PROTECTION
;
2688 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2693 static void ospf_maxpath_set(struct vty
*vty
, struct ospf
*ospf
, uint16_t paths
)
2695 if (ospf
->max_multipath
== paths
)
2698 ospf
->max_multipath
= paths
;
2700 /* Send deletion notification to zebra to delete all
2701 * ospf specific routes and reinitiat SPF to reflect
2702 * the new max multipath.
2704 ospf_restart_spf(ospf
);
2707 /* Ospf Maximum multiple paths config support */
2708 DEFUN (ospf_max_multipath
,
2709 ospf_max_multipath_cmd
,
2710 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM
),
2711 "Max no of multiple paths for ECMP support\n"
2712 "Number of paths\n")
2714 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2718 maxpaths
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2720 ospf_maxpath_set(vty
, ospf
, maxpaths
);
2724 DEFUN (no_ospf_max_multipath
,
2725 no_ospf_max_multipath_cmd
,
2728 "Max no of multiple paths for ECMP support\n")
2730 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2731 uint16_t maxpaths
= MULTIPATH_NUM
;
2733 ospf_maxpath_set(vty
, ospf
, maxpaths
);
2737 static const char *const ospf_abr_type_descr_str
[] = {
2738 "Unknown", "Standard (RFC2328)", "Alternative IBM",
2739 "Alternative Cisco", "Alternative Shortcut"
2742 static const char *const ospf_shortcut_mode_descr_str
[] = {
2743 "Default", "Enabled", "Disabled"
2746 static void show_ip_ospf_area(struct vty
*vty
, struct ospf_area
*area
,
2747 json_object
*json_areas
, bool use_json
)
2749 json_object
*json_area
= NULL
;
2750 char buf
[PREFIX_STRLEN
];
2753 json_area
= json_object_new_object();
2757 vty_out(vty
, " Area ID: %pI4", &area
->area_id
);
2759 /* Show Area type/mode. */
2760 if (OSPF_IS_AREA_BACKBONE(area
)) {
2762 json_object_boolean_true_add(json_area
, "backbone");
2764 vty_out(vty
, " (Backbone)\n");
2767 if (area
->external_routing
== OSPF_AREA_STUB
) {
2768 if (area
->no_summary
)
2769 json_object_boolean_true_add(
2770 json_area
, "stubNoSummary");
2771 if (area
->shortcut_configured
)
2772 json_object_boolean_true_add(
2773 json_area
, "stubShortcut");
2774 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
2775 if (area
->no_summary
)
2776 json_object_boolean_true_add(
2777 json_area
, "nssaNoSummary");
2778 if (area
->shortcut_configured
)
2779 json_object_boolean_true_add(
2780 json_area
, "nssaShortcut");
2783 json_object_string_add(
2784 json_area
, "shortcuttingMode",
2785 ospf_shortcut_mode_descr_str
2786 [area
->shortcut_configured
]);
2787 if (area
->shortcut_capability
)
2788 json_object_boolean_true_add(json_area
,
2791 if (area
->external_routing
== OSPF_AREA_STUB
)
2792 vty_out(vty
, " (Stub%s%s)",
2793 area
->no_summary
? ", no summary" : "",
2794 area
->shortcut_configured
? "; " : "");
2795 else if (area
->external_routing
== OSPF_AREA_NSSA
)
2796 vty_out(vty
, " (NSSA%s%s)",
2797 area
->no_summary
? ", no summary" : "",
2798 area
->shortcut_configured
? "; " : "");
2801 vty_out(vty
, " Shortcutting mode: %s",
2802 ospf_shortcut_mode_descr_str
2803 [area
->shortcut_configured
]);
2804 vty_out(vty
, ", S-bit consensus: %s\n",
2805 area
->shortcut_capability
? "ok" : "no");
2809 /* Show number of interfaces */
2811 json_object_int_add(json_area
, "areaIfTotalCounter",
2812 listcount(area
->oiflist
));
2813 json_object_int_add(json_area
, "areaIfActiveCounter",
2817 " Number of interfaces in this area: Total: %d, Active: %d\n",
2818 listcount(area
->oiflist
), area
->act_ints
);
2820 if (area
->external_routing
== OSPF_AREA_NSSA
) {
2822 json_object_boolean_true_add(json_area
, "nssa");
2823 if (!IS_OSPF_ABR(area
->ospf
))
2824 json_object_boolean_false_add(json_area
, "abr");
2825 else if (area
->NSSATranslatorState
) {
2826 json_object_boolean_true_add(json_area
, "abr");
2827 if (area
->NSSATranslatorRole
2828 == OSPF_NSSA_ROLE_CANDIDATE
)
2829 json_object_boolean_true_add(
2831 "nssaTranslatorElected");
2832 else if (area
->NSSATranslatorRole
2833 == OSPF_NSSA_ROLE_ALWAYS
)
2834 json_object_boolean_true_add(
2836 "nssaTranslatorAlways");
2838 json_object_boolean_true_add(
2840 "nssaTranslatorNever");
2842 json_object_boolean_true_add(json_area
, "abr");
2843 if (area
->NSSATranslatorRole
2844 == OSPF_NSSA_ROLE_CANDIDATE
)
2845 json_object_boolean_false_add(
2847 "nssaTranslatorElected");
2849 json_object_boolean_true_add(
2851 "nssaTranslatorNever");
2855 " It is an NSSA configuration.\n Elected NSSA/ABR performs type-7/type-5 LSA translation.\n");
2856 if (!IS_OSPF_ABR(area
->ospf
))
2858 " It is not ABR, therefore not Translator.\n");
2859 else if (area
->NSSATranslatorState
) {
2860 vty_out(vty
, " We are an ABR and ");
2861 if (area
->NSSATranslatorRole
2862 == OSPF_NSSA_ROLE_CANDIDATE
)
2864 "the NSSA Elected Translator.\n");
2865 else if (area
->NSSATranslatorRole
2866 == OSPF_NSSA_ROLE_ALWAYS
)
2868 "always an NSSA Translator.\n");
2871 "never an NSSA Translator.\n");
2873 vty_out(vty
, " We are an ABR, but ");
2874 if (area
->NSSATranslatorRole
2875 == OSPF_NSSA_ROLE_CANDIDATE
)
2877 "not the NSSA Elected Translator.\n");
2880 "never an NSSA Translator.\n");
2885 /* Stub-router state for this area */
2886 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
)) {
2887 char timebuf
[OSPF_TIME_DUMP_SIZE
];
2890 json_object_boolean_true_add(
2891 json_area
, "originStubMaxDistRouterLsa");
2892 if (CHECK_FLAG(area
->stub_router_state
,
2893 OSPF_AREA_ADMIN_STUB_ROUTED
))
2894 json_object_boolean_true_add(
2895 json_area
, "indefiniteActiveAdmin");
2896 if (area
->t_stub_router
) {
2900 &area
->t_stub_router
->u
.sands
,
2903 json_object_int_add(
2905 "activeStartupRemainderMsecs",
2910 " Originating stub / maximum-distance Router-LSA\n");
2911 if (CHECK_FLAG(area
->stub_router_state
,
2912 OSPF_AREA_ADMIN_STUB_ROUTED
))
2914 " Administratively activated (indefinitely)\n");
2915 if (area
->t_stub_router
)
2917 " Active from startup, %s remaining\n",
2918 ospf_timer_dump(area
->t_stub_router
,
2925 /* Show number of fully adjacent neighbors. */
2926 json_object_int_add(json_area
, "nbrFullAdjacentCounter",
2929 /* Show authentication type. */
2930 if (area
->auth_type
== OSPF_AUTH_NULL
)
2931 json_object_string_add(json_area
, "authentication",
2932 "authenticationNone");
2933 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2934 json_object_string_add(json_area
, "authentication",
2935 "authenticationSimplePassword");
2936 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2937 json_object_string_add(json_area
, "authentication",
2938 "authenticationMessageDigest");
2940 if (!OSPF_IS_AREA_BACKBONE(area
))
2941 json_object_int_add(json_area
,
2942 "virtualAdjacenciesPassingCounter",
2945 /* Show SPF calculation times. */
2946 json_object_int_add(json_area
, "spfExecutedCounter",
2947 area
->spf_calculation
);
2948 json_object_int_add(json_area
, "lsaNumber", area
->lsdb
->total
);
2949 json_object_int_add(
2950 json_area
, "lsaRouterNumber",
2951 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
));
2952 json_object_int_add(
2953 json_area
, "lsaRouterChecksum",
2954 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
2955 json_object_int_add(
2956 json_area
, "lsaNetworkNumber",
2957 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
));
2958 json_object_int_add(
2959 json_area
, "lsaNetworkChecksum",
2960 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
2961 json_object_int_add(
2962 json_area
, "lsaSummaryNumber",
2963 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
));
2964 json_object_int_add(
2965 json_area
, "lsaSummaryChecksum",
2966 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
2967 json_object_int_add(
2968 json_area
, "lsaAsbrNumber",
2969 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2970 json_object_int_add(
2971 json_area
, "lsaAsbrChecksum",
2972 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2973 json_object_int_add(
2974 json_area
, "lsaNssaNumber",
2975 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2976 json_object_int_add(
2977 json_area
, "lsaNssaChecksum",
2978 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2980 /* Show number of fully adjacent neighbors. */
2982 " Number of fully adjacent neighbors in this area: %d\n",
2985 /* Show authentication type. */
2986 vty_out(vty
, " Area has ");
2987 if (area
->auth_type
== OSPF_AUTH_NULL
)
2988 vty_out(vty
, "no authentication\n");
2989 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2990 vty_out(vty
, "simple password authentication\n");
2991 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2992 vty_out(vty
, "message digest authentication\n");
2994 if (!OSPF_IS_AREA_BACKBONE(area
))
2996 " Number of full virtual adjacencies going through this area: %d\n",
2999 /* Show SPF calculation times. */
3000 vty_out(vty
, " SPF algorithm executed %d times\n",
3001 area
->spf_calculation
);
3003 /* Show number of LSA. */
3004 vty_out(vty
, " Number of LSA %ld\n", area
->lsdb
->total
);
3006 " Number of router LSA %ld. Checksum Sum 0x%08x\n",
3007 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
),
3008 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
3010 " Number of network LSA %ld. Checksum Sum 0x%08x\n",
3011 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
),
3012 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
3014 " Number of summary LSA %ld. Checksum Sum 0x%08x\n",
3015 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
),
3016 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
3018 " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n",
3019 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
),
3020 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
3021 vty_out(vty
, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n",
3022 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
),
3023 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
3027 json_object_int_add(
3028 json_area
, "lsaOpaqueLinkNumber",
3029 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
3030 json_object_int_add(
3031 json_area
, "lsaOpaqueLinkChecksum",
3032 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
3033 json_object_int_add(
3034 json_area
, "lsaOpaqueAreaNumber",
3035 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
3036 json_object_int_add(
3037 json_area
, "lsaOpaqueAreaChecksum",
3038 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
3041 " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n",
3042 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
),
3043 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
3045 " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n",
3046 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
),
3047 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
3050 if (area
->fr_info
.configured
) {
3052 json_object_string_add(json_area
, "areaFloodReduction",
3055 vty_out(vty
, " Flood Reduction is configured.\n");
3058 if (area
->fr_info
.enabled
) {
3060 json_object_boolean_true_add(
3061 json_area
, "areaFloodReductionEnabled");
3062 if (area
->fr_info
.router_lsas_recv_dc_bit
)
3063 json_object_boolean_true_add(
3064 json_area
, "lsasRecvDCbitSet");
3065 if (area
->fr_info
.area_ind_lsa_recvd
)
3066 json_object_string_add(json_area
,
3067 "areaIndicationLsaRecv",
3069 if (area
->fr_info
.indication_lsa_self
)
3070 json_object_string_addf(
3071 json_area
, "areaIndicationLsa", "%pI4",
3072 &area
->fr_info
.indication_lsa_self
->data
3075 vty_out(vty
, " Flood Reduction is enabled.\n");
3076 vty_out(vty
, " No of LSAs rcv'd with DC bit set %d\n",
3077 area
->fr_info
.router_lsas_recv_dc_bit
);
3078 if (area
->fr_info
.area_ind_lsa_recvd
)
3079 vty_out(vty
, " Ind LSA by other abr.\n");
3080 if (area
->fr_info
.indication_lsa_self
)
3081 vty_out(vty
, " Ind LSA generated %pI4\n",
3082 &area
->fr_info
.indication_lsa_self
->data
3088 json_object_object_add(json_areas
,
3089 inet_ntop(AF_INET
, &area
->area_id
,
3096 static int show_ip_ospf_common(struct vty
*vty
, struct ospf
*ospf
,
3097 json_object
*json
, uint8_t use_vrf
)
3099 struct listnode
*node
, *nnode
;
3100 struct ospf_area
*area
;
3101 struct timeval result
;
3102 char timebuf
[OSPF_TIME_DUMP_SIZE
];
3103 json_object
*json_vrf
= NULL
;
3104 json_object
*json_areas
= NULL
;
3108 json_vrf
= json_object_new_object();
3111 json_areas
= json_object_new_object();
3114 if (ospf
->instance
) {
3116 json_object_int_add(json
, "ospfInstance",
3119 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
3123 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3125 /* Show Router ID. */
3127 json_object_string_addf(json_vrf
, "routerId", "%pI4",
3130 vty_out(vty
, " OSPF Routing Process, Router ID: %pI4\n",
3134 /* Graceful shutdown */
3135 if (ospf
->t_deferred_shutdown
) {
3140 &ospf
->t_deferred_shutdown
->u
.sands
,
3143 json_object_int_add(json_vrf
, "deferredShutdownMsecs",
3147 " Deferred shutdown in progress, %s remaining\n",
3148 ospf_timer_dump(ospf
->t_deferred_shutdown
,
3149 timebuf
, sizeof(timebuf
)));
3153 /* Show capability. */
3155 json_object_boolean_true_add(json_vrf
, "tosRoutesOnly");
3156 json_object_boolean_true_add(json_vrf
, "rfc2328Conform");
3157 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
3158 json_object_boolean_true_add(json_vrf
,
3159 "rfc1583Compatibility");
3162 vty_out(vty
, " Supports only single TOS (TOS0) routes\n");
3163 vty_out(vty
, " This implementation conforms to RFC2328\n");
3164 vty_out(vty
, " RFC1583Compatibility flag is %s\n",
3165 CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)
3171 if (CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)) {
3172 json_object_boolean_true_add(json_vrf
, "opaqueCapable");
3175 vty_out(vty
, " OpaqueCapability flag is %s\n",
3176 CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)
3181 /* Show stub-router configuration */
3182 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
3183 || ospf
->stub_router_shutdown_time
3184 != OSPF_STUB_ROUTER_UNCONFIGURED
) {
3186 json_object_boolean_true_add(json_vrf
,
3187 "stubAdvertisement");
3188 if (ospf
->stub_router_startup_time
3189 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3190 json_object_int_add(
3191 json_vrf
, "postStartEnabledSecs",
3192 ospf
->stub_router_startup_time
);
3193 if (ospf
->stub_router_shutdown_time
3194 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3195 json_object_int_add(
3196 json_vrf
, "preShutdownEnabledSecs",
3197 ospf
->stub_router_shutdown_time
);
3200 " Stub router advertisement is configured\n");
3201 if (ospf
->stub_router_startup_time
3202 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3204 " Enabled for %us after start-up\n",
3205 ospf
->stub_router_startup_time
);
3206 if (ospf
->stub_router_shutdown_time
3207 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3209 " Enabled for %us prior to full shutdown\n",
3210 ospf
->stub_router_shutdown_time
);
3214 /* Show SPF timers. */
3216 json_object_int_add(json_vrf
, "spfScheduleDelayMsecs",
3218 json_object_int_add(json_vrf
, "holdtimeMinMsecs",
3219 ospf
->spf_holdtime
);
3220 json_object_int_add(json_vrf
, "holdtimeMaxMsecs",
3221 ospf
->spf_max_holdtime
);
3222 json_object_int_add(json_vrf
, "holdtimeMultplier",
3223 ospf
->spf_hold_multiplier
);
3226 " Initial SPF scheduling delay %d millisec(s)\n"
3227 " Minimum hold time between consecutive SPFs %d millisec(s)\n"
3228 " Maximum hold time between consecutive SPFs %d millisec(s)\n"
3229 " Hold time multiplier is currently %d\n",
3230 ospf
->spf_delay
, ospf
->spf_holdtime
,
3231 ospf
->spf_max_holdtime
, ospf
->spf_hold_multiplier
);
3235 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3236 long time_store
= 0;
3239 monotime_since(&ospf
->ts_spf
, NULL
) / 1000LL;
3240 json_object_int_add(json_vrf
, "spfLastExecutedMsecs",
3243 time_store
= (1000 * ospf
->ts_spf_duration
.tv_sec
)
3244 + (ospf
->ts_spf_duration
.tv_usec
/ 1000);
3245 json_object_int_add(json_vrf
, "spfLastDurationMsecs",
3248 json_object_boolean_true_add(json_vrf
, "spfHasNotRun");
3250 vty_out(vty
, " SPF algorithm ");
3251 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3252 monotime_since(&ospf
->ts_spf
, &result
);
3253 vty_out(vty
, "last executed %s ago\n",
3254 ospf_timeval_dump(&result
, timebuf
,
3256 vty_out(vty
, " Last SPF duration %s\n",
3257 ospf_timeval_dump(&ospf
->ts_spf_duration
,
3258 timebuf
, sizeof(timebuf
)));
3260 vty_out(vty
, "has not been run\n");
3264 if (ospf
->t_spf_calc
) {
3267 monotime_until(&ospf
->t_spf_calc
->u
.sands
, NULL
)
3269 json_object_int_add(json_vrf
, "spfTimerDueInMsecs",
3273 json_object_int_add(json_vrf
, "lsaMinIntervalMsecs",
3274 ospf
->min_ls_interval
);
3275 json_object_int_add(json_vrf
, "lsaMinArrivalMsecs",
3276 ospf
->min_ls_arrival
);
3277 /* Show write multiplier values */
3278 json_object_int_add(json_vrf
, "writeMultiplier",
3279 ospf
->write_oi_count
);
3280 /* Show refresh parameters. */
3281 json_object_int_add(json_vrf
, "refreshTimerMsecs",
3282 ospf
->lsa_refresh_interval
* 1000);
3284 /* show max multipath */
3285 json_object_int_add(json_vrf
, "maximumPaths",
3286 ospf
->max_multipath
);
3288 /* show administrative distance */
3289 json_object_int_add(json_vrf
, "preference",
3291 ? ospf
->distance_all
3292 : ZEBRA_OSPF_DISTANCE_DEFAULT
);
3294 vty_out(vty
, " SPF timer %s%s\n",
3295 (ospf
->t_spf_calc
? "due in " : "is "),
3296 ospf_timer_dump(ospf
->t_spf_calc
, timebuf
,
3299 vty_out(vty
, " LSA minimum interval %d msecs\n",
3300 ospf
->min_ls_interval
);
3301 vty_out(vty
, " LSA minimum arrival %d msecs\n",
3302 ospf
->min_ls_arrival
);
3304 /* Show write multiplier values */
3305 vty_out(vty
, " Write Multiplier set to %d \n",
3306 ospf
->write_oi_count
);
3308 /* Show refresh parameters. */
3309 vty_out(vty
, " Refresh timer %d secs\n",
3310 ospf
->lsa_refresh_interval
);
3312 /* show max multipath */
3313 vty_out(vty
, " Maximum multiple paths(ECMP) supported %d\n",
3314 ospf
->max_multipath
);
3316 /* show administrative distance */
3317 vty_out(vty
, " Administrative distance %u\n",
3318 ospf
->distance_all
? ospf
->distance_all
3319 : ZEBRA_OSPF_DISTANCE_DEFAULT
);
3322 if (ospf
->fr_configured
) {
3324 json_object_string_add(json_vrf
, "floodReduction",
3327 vty_out(vty
, " Flood Reduction is configured.\n");
3330 /* Show ABR/ASBR flags. */
3331 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ABR
)) {
3333 json_object_string_add(
3334 json_vrf
, "abrType",
3335 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3338 " This router is an ABR, ABR type is: %s\n",
3339 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3341 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ASBR
)) {
3343 json_object_string_add(
3344 json_vrf
, "asbrRouter",
3345 "injectingExternalRoutingInformation");
3348 " This router is an ASBR (injecting external routing information)\n");
3351 /* Show Number of AS-external-LSAs. */
3353 json_object_int_add(
3354 json_vrf
, "lsaExternalCounter",
3355 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3356 json_object_int_add(
3357 json_vrf
, "lsaExternalChecksum",
3358 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3361 " Number of external LSA %ld. Checksum Sum 0x%08x\n",
3362 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
),
3363 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3367 json_object_int_add(
3368 json_vrf
, "lsaAsopaqueCounter",
3369 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3370 json_object_int_add(
3371 json_vrf
, "lsaAsOpaqueChecksum",
3372 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3375 " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n",
3376 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
),
3377 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3380 /* Show number of areas attached. */
3382 json_object_int_add(json_vrf
, "attachedAreaCounter",
3383 listcount(ospf
->areas
));
3385 vty_out(vty
, " Number of areas attached to this router: %d\n",
3386 listcount(ospf
->areas
));
3388 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
3389 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
)) {
3391 json_object_boolean_true_add(
3392 json_vrf
, "adjacencyChangesLoggedAll");
3395 " All adjacency changes are logged\n");
3398 json_object_boolean_true_add(
3399 json_vrf
, "adjacencyChangesLogged");
3401 vty_out(vty
, " Adjacency changes are logged\n");
3405 /* show LDP-Sync status */
3406 ospf_ldp_sync_show_info(vty
, ospf
, json_vrf
, json
? 1 : 0);
3408 /* Socket buffer sizes */
3410 if (ospf
->recv_sock_bufsize
!= OSPF_DEFAULT_SOCK_BUFSIZE
)
3411 json_object_int_add(json_vrf
, "recvSockBufsize",
3412 ospf
->recv_sock_bufsize
);
3413 if (ospf
->send_sock_bufsize
!= OSPF_DEFAULT_SOCK_BUFSIZE
)
3414 json_object_int_add(json_vrf
, "sendSockBufsize",
3415 ospf
->send_sock_bufsize
);
3417 if (ospf
->recv_sock_bufsize
!= OSPF_DEFAULT_SOCK_BUFSIZE
)
3418 vty_out(vty
, " Receive socket bufsize: %u\n",
3419 ospf
->recv_sock_bufsize
);
3420 if (ospf
->send_sock_bufsize
!= OSPF_DEFAULT_SOCK_BUFSIZE
)
3421 vty_out(vty
, " Send socket bufsize: %u\n",
3422 ospf
->send_sock_bufsize
);
3425 /* Show each area status. */
3426 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
3427 show_ip_ospf_area(vty
, area
, json_areas
, json
? 1 : 0);
3431 json_object_object_add(json_vrf
, "areas", json_areas
);
3432 json_object_object_add(json
, ospf_get_name(ospf
),
3435 json_object_object_add(json
, "areas", json_areas
);
3443 DEFUN (show_ip_ospf
,
3445 "show ip ospf [vrf <NAME|all>] [json]",
3448 "OSPF information\n"
3454 bool uj
= use_json(argc
, argv
);
3455 struct listnode
*node
= NULL
;
3456 char *vrf_name
= NULL
;
3457 bool all_vrf
= false;
3458 int ret
= CMD_SUCCESS
;
3461 json_object
*json
= NULL
;
3462 uint8_t use_vrf
= 0;
3464 if (listcount(om
->ospf
) == 0)
3467 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
3470 json
= json_object_new_object();
3472 /* vrf input is provided could be all or specific vrf*/
3474 bool ospf_output
= false;
3479 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
3480 if (!ospf
->oi_running
)
3483 ret
= show_ip_ospf_common(vty
, ospf
, json
,
3487 vty_json(vty
, json
);
3488 else if (!ospf_output
)
3489 vty_out(vty
, "%% OSPF is not enabled\n");
3492 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
3493 if ((ospf
== NULL
) || !ospf
->oi_running
) {
3495 vty_json(vty
, json
);
3498 "%% OSPF is not enabled in vrf %s\n",
3504 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
3505 /* Display default ospf (instance 0) info */
3506 if (ospf
== NULL
|| !ospf
->oi_running
) {
3508 vty_json(vty
, json
);
3511 "%% OSPF is not enabled in vrf default\n");
3518 show_ip_ospf_common(vty
, ospf
, json
, use_vrf
);
3520 vty_out(vty
, "%s\n",
3521 json_object_to_json_string_ext(
3522 json
, JSON_C_TO_STRING_PRETTY
));
3526 json_object_free(json
);
3531 DEFUN (show_ip_ospf_instance
,
3532 show_ip_ospf_instance_cmd
,
3533 "show ip ospf (1-65535) [json]",
3536 "OSPF information\n"
3542 unsigned short instance
= 0;
3543 bool uj
= use_json(argc
, argv
);
3544 int ret
= CMD_SUCCESS
;
3545 json_object
*json
= NULL
;
3547 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
3548 if (instance
!= ospf_instance
)
3549 return CMD_NOT_MY_INSTANCE
;
3551 ospf
= ospf_lookup_instance(instance
);
3552 if (!ospf
|| !ospf
->oi_running
)
3556 json
= json_object_new_object();
3558 ret
= show_ip_ospf_common(vty
, ospf
, json
, 0);
3561 vty_json(vty
, json
);
3566 static void ospf_interface_auth_show(struct vty
*vty
, struct ospf_interface
*oi
,
3567 json_object
*json
, bool use_json
)
3571 auth_type
= OSPF_IF_PARAM(oi
, auth_type
);
3573 switch (auth_type
) {
3574 case OSPF_AUTH_NULL
:
3576 json_object_string_add(json
, "authentication",
3577 "authenticationNone");
3579 vty_out(vty
, " Authentication NULL is enabled\n");
3581 case OSPF_AUTH_SIMPLE
: {
3583 json_object_string_add(json
, "authentication",
3584 "authenticationSimplePassword");
3587 " Simple password authentication enabled\n");
3590 case OSPF_AUTH_CRYPTOGRAPHIC
: {
3591 struct crypt_key
*ckey
;
3593 if (list_isempty(OSPF_IF_PARAM(oi
, auth_crypt
)))
3596 ckey
= listgetdata(listtail(OSPF_IF_PARAM(oi
, auth_crypt
)));
3599 json_object_string_add(json
, "authentication",
3600 "authenticationMessageDigest");
3603 " Cryptographic authentication enabled\n");
3604 vty_out(vty
, " Algorithm:MD5\n");
3614 static void show_ip_ospf_interface_sub(struct vty
*vty
, struct ospf
*ospf
,
3615 struct interface
*ifp
,
3616 json_object
*json_interface_sub
,
3620 struct ospf_neighbor
*nbr
;
3621 struct route_node
*rn
;
3622 uint32_t bandwidth
= ifp
->bandwidth
? ifp
->bandwidth
: ifp
->speed
;
3623 struct ospf_if_params
*params
;
3625 /* Is interface up? */
3627 is_up
= if_is_operative(ifp
);
3629 json_object_boolean_true_add(json_interface_sub
,
3632 json_object_boolean_false_add(json_interface_sub
,
3635 json_object_int_add(json_interface_sub
, "ifIndex",
3637 json_object_int_add(json_interface_sub
, "mtuBytes", ifp
->mtu
);
3638 json_object_int_add(json_interface_sub
, "bandwidthMbit",
3640 json_object_string_add(json_interface_sub
, "ifFlags",
3641 if_flag_dump(ifp
->flags
));
3643 vty_out(vty
, "%s is %s\n", ifp
->name
,
3644 ((is_up
= if_is_operative(ifp
)) ? "up" : "down"));
3645 vty_out(vty
, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n",
3646 ifp
->ifindex
, ifp
->mtu
, bandwidth
,
3647 if_flag_dump(ifp
->flags
));
3650 /* Is interface OSPF enabled? */
3652 if (ospf_oi_count(ifp
) == 0) {
3653 json_object_boolean_false_add(json_interface_sub
,
3656 } else if (!is_up
) {
3657 json_object_boolean_false_add(json_interface_sub
,
3661 json_object_boolean_true_add(json_interface_sub
,
3664 if (ospf_oi_count(ifp
) == 0) {
3665 vty_out(vty
, " OSPF not enabled on this interface\n");
3667 } else if (!is_up
) {
3669 " OSPF is enabled, but not running on this interface\n");
3674 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
3675 struct ospf_interface
*oi
= rn
->info
;
3680 if (CHECK_FLAG(oi
->connected
->flags
, ZEBRA_IFA_UNNUMBERED
)) {
3682 json_object_boolean_true_add(json_interface_sub
,
3685 vty_out(vty
, " This interface is UNNUMBERED,");
3687 struct in_addr dest
;
3690 /* Show OSPF interface information. */
3692 json_object_string_addf(
3693 json_interface_sub
, "ipAddress", "%pI4",
3694 &oi
->address
->u
.prefix4
);
3695 json_object_int_add(json_interface_sub
,
3696 "ipAddressPrefixlen",
3697 oi
->address
->prefixlen
);
3699 vty_out(vty
, " Internet Address %pFX,",
3702 /* For Vlinks, showing the peer address is
3703 * probably more informative than the local
3704 * interface that is being used */
3705 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
) {
3707 dest
= oi
->vl_data
->peer_addr
;
3708 } else if (CONNECTED_PEER(oi
->connected
)
3709 && oi
->connected
->destination
) {
3711 dest
= oi
->connected
->destination
->u
.prefix4
;
3714 dest
.s_addr
= ipv4_broadcast_addr(
3715 oi
->connected
->address
->u
.prefix4
.s_addr
,
3716 oi
->connected
->address
->prefixlen
);
3720 json_object_string_add(
3722 "ospfIfType", dstr
);
3723 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3724 json_object_string_addf(
3725 json_interface_sub
, "vlinkPeer",
3728 json_object_string_addf(
3730 "localIfUsed", "%pI4", &dest
);
3732 vty_out(vty
, " %s %pI4,", dstr
,
3736 json_object_string_add(json_interface_sub
, "area",
3737 ospf_area_desc_string(oi
->area
));
3738 if (OSPF_IF_PARAM(oi
, mtu_ignore
))
3739 json_object_boolean_true_add(
3741 "mtuMismatchDetect");
3742 json_object_string_addf(json_interface_sub
, "routerId",
3743 "%pI4", &ospf
->router_id
);
3744 json_object_string_add(json_interface_sub
,
3746 ospf_network_type_str
[oi
->type
]);
3747 json_object_int_add(json_interface_sub
, "cost",
3749 json_object_int_add(
3750 json_interface_sub
, "transmitDelaySecs",
3751 OSPF_IF_PARAM(oi
, transmit_delay
));
3752 json_object_string_add(json_interface_sub
, "state",
3753 lookup_msg(ospf_ism_state_msg
,
3755 json_object_int_add(json_interface_sub
, "priority",
3758 vty_out(vty
, " Area %s\n",
3759 ospf_area_desc_string(oi
->area
));
3761 vty_out(vty
, " MTU mismatch detection: %s\n",
3762 OSPF_IF_PARAM(oi
, mtu_ignore
) ? "disabled"
3766 " Router ID %pI4, Network Type %s, Cost: %d\n",
3768 ospf_network_type_str
[oi
->type
],
3772 " Transmit Delay is %d sec, State %s, Priority %d\n",
3773 OSPF_IF_PARAM(oi
, transmit_delay
),
3774 lookup_msg(ospf_ism_state_msg
, oi
->state
, NULL
),
3778 /* Show DR information. */
3779 if (DR(oi
).s_addr
== INADDR_ANY
) {
3782 " No backup designated router on this network\n");
3784 nbr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &DR(oi
));
3787 json_object_string_addf(
3788 json_interface_sub
, "drId",
3789 "%pI4", &nbr
->router_id
);
3790 json_object_string_addf(
3791 json_interface_sub
, "drAddress",
3793 &nbr
->address
.u
.prefix4
);
3796 " Designated Router (ID) %pI4",
3799 " Interface Address %pFX\n",
3805 nbr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &BDR(oi
));
3809 " No backup designated router on this network\n");
3812 json_object_string_addf(
3813 json_interface_sub
, "bdrId",
3814 "%pI4", &nbr
->router_id
);
3815 json_object_string_addf(
3817 "bdrAddress", "%pI4",
3818 &nbr
->address
.u
.prefix4
);
3821 " Backup Designated Router (ID) %pI4,",
3823 vty_out(vty
, " Interface Address %pI4\n",
3824 &nbr
->address
.u
.prefix4
);
3829 /* Next network-LSA sequence number we'll use, if we're elected
3832 && ntohl(oi
->params
->network_lsa_seqnum
)
3833 != OSPF_INITIAL_SEQUENCE_NUMBER
) {
3835 json_object_int_add(
3837 "networkLsaSequence",
3838 ntohl(oi
->params
->network_lsa_seqnum
));
3841 " Saved Network-LSA sequence number 0x%x\n",
3842 ntohl(oi
->params
->network_lsa_seqnum
));
3846 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3847 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3848 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3849 json_object_boolean_true_add(
3851 "mcastMemberOspfAllRouters");
3852 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3853 json_object_boolean_true_add(
3855 "mcastMemberOspfDesignatedRouters");
3858 vty_out(vty
, " Multicast group memberships:");
3859 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3860 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3861 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3862 vty_out(vty
, " OSPFAllRouters");
3863 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3864 vty_out(vty
, " OSPFDesignatedRouters");
3866 vty_out(vty
, " <None>");
3871 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3872 json_object_int_add(
3873 json_interface_sub
, "timerMsecs",
3874 OSPF_IF_PARAM(oi
, v_hello
) * 1000);
3876 json_object_int_add(
3877 json_interface_sub
, "timerMsecs",
3878 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3879 json_object_int_add(json_interface_sub
,
3881 OSPF_IF_PARAM(oi
, v_wait
));
3882 json_object_int_add(json_interface_sub
,
3884 OSPF_IF_PARAM(oi
, v_wait
));
3885 json_object_int_add(
3886 json_interface_sub
, "timerRetransmitSecs",
3887 OSPF_IF_PARAM(oi
, retransmit_interval
));
3889 vty_out(vty
, " Timer intervals configured,");
3890 vty_out(vty
, " Hello ");
3891 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3892 vty_out(vty
, "%ds,",
3893 OSPF_IF_PARAM(oi
, v_hello
));
3895 vty_out(vty
, "%dms,",
3896 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3897 vty_out(vty
, " Dead %ds, Wait %ds, Retransmit %d\n",
3898 OSPF_IF_PARAM(oi
, v_wait
),
3899 OSPF_IF_PARAM(oi
, v_wait
),
3900 OSPF_IF_PARAM(oi
, retransmit_interval
));
3903 if (OSPF_IF_PASSIVE_STATUS(oi
) == OSPF_IF_ACTIVE
) {
3904 char timebuf
[OSPF_TIME_DUMP_SIZE
];
3906 long time_store
= 0;
3910 &oi
->t_hello
->u
.sands
,
3913 json_object_int_add(json_interface_sub
,
3914 "timerHelloInMsecs",
3917 vty_out(vty
, " Hello due in %s\n",
3918 ospf_timer_dump(oi
->t_hello
, timebuf
,
3920 } else /* passive-interface is set */
3923 json_object_boolean_true_add(
3925 "timerPassiveIface");
3928 " No Hellos (Passive interface)\n");
3932 json_object_int_add(json_interface_sub
, "nbrCount",
3933 ospf_nbr_count(oi
, 0));
3934 json_object_int_add(json_interface_sub
,
3936 ospf_nbr_count(oi
, NSM_Full
));
3939 " Neighbor Count is %d, Adjacent neighbor count is %d\n",
3940 ospf_nbr_count(oi
, 0),
3941 ospf_nbr_count(oi
, NSM_Full
));
3944 params
= IF_DEF_PARAMS(ifp
);
3946 OSPF_IF_PARAM_CONFIGURED(params
, v_gr_hello_delay
)) {
3948 json_object_int_add(json_interface_sub
,
3950 params
->v_gr_hello_delay
);
3953 " Graceful Restart hello delay: %us\n",
3954 params
->v_gr_hello_delay
);
3957 ospf_interface_bfd_show(vty
, ifp
, json_interface_sub
);
3959 /* OSPF Authentication information */
3960 ospf_interface_auth_show(vty
, oi
, json_interface_sub
, use_json
);
3961 if (oi
->type
== OSPF_IFTYPE_POINTOMULTIPOINT
) {
3963 json_object_boolean_add(json_interface_sub
,
3965 oi
->p2mp_delay_reflood
);
3968 " %sDelay reflooding LSAs received on P2MP interface\n",
3969 oi
->p2mp_delay_reflood
? "" : "Don't ");
3974 static int show_ip_ospf_interface_common(struct vty
*vty
, struct ospf
*ospf
,
3975 char *intf_name
, uint8_t use_vrf
,
3976 json_object
*json
, bool use_json
)
3978 struct interface
*ifp
;
3979 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
3980 json_object
*json_vrf
= NULL
;
3981 json_object
*json_interface_sub
= NULL
, *json_interface
= NULL
;
3985 json_vrf
= json_object_new_object();
3988 json_interface
= json_object_new_object();
3991 if (ospf
->instance
) {
3993 json_object_int_add(json
, "ospfInstance",
3996 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
3999 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4001 if (intf_name
== NULL
) {
4002 /* Show All Interfaces.*/
4003 FOR_ALL_INTERFACES (vrf
, ifp
) {
4004 if (ospf_oi_count(ifp
)) {
4006 json_interface_sub
=
4007 json_object_new_object();
4009 show_ip_ospf_interface_sub(vty
, ospf
, ifp
,
4014 json_object_object_add(
4015 json_interface
, ifp
->name
,
4016 json_interface_sub
);
4021 json_object_object_add(json_vrf
, "interfaces",
4024 /* Interface name is specified. */
4025 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
4028 json_object_boolean_true_add(json_vrf
,
4030 json_object_free(json_interface
);
4032 vty_out(vty
, "No such interface name\n");
4035 json_interface_sub
= json_object_new_object();
4037 show_ip_ospf_interface_sub(
4038 vty
, ospf
, ifp
, json_interface_sub
, use_json
);
4041 json_object_object_add(json_interface
,
4043 json_interface_sub
);
4044 json_object_object_add(json_vrf
, "interfaces",
4052 json_object_object_add(json
, ospf_get_name(ospf
),
4061 static void show_ip_ospf_interface_traffic_sub(struct vty
*vty
,
4062 struct ospf_interface
*oi
,
4063 json_object
*json_interface_sub
,
4067 json_object_int_add(json_interface_sub
, "ifIndex",
4069 json_object_int_add(json_interface_sub
, "helloIn",
4071 json_object_int_add(json_interface_sub
, "helloOut",
4073 json_object_int_add(json_interface_sub
, "dbDescIn",
4075 json_object_int_add(json_interface_sub
, "dbDescOut",
4077 json_object_int_add(json_interface_sub
, "lsReqIn",
4079 json_object_int_add(json_interface_sub
, "lsReqOut",
4081 json_object_int_add(json_interface_sub
, "lsUpdIn",
4083 json_object_int_add(json_interface_sub
, "lsUpdOut",
4085 json_object_int_add(json_interface_sub
, "lsAckIn",
4087 json_object_int_add(json_interface_sub
, "lsAckOut",
4089 json_object_int_add(json_interface_sub
, "packetsQueued",
4090 listcount(oi
->obuf
));
4093 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u %12lu\n",
4094 oi
->ifp
->name
, oi
->hello_in
, oi
->hello_out
,
4095 oi
->db_desc_in
, oi
->db_desc_out
, oi
->ls_req_in
,
4096 oi
->ls_req_out
, oi
->ls_upd_in
, oi
->ls_upd_out
,
4097 oi
->ls_ack_in
, oi
->ls_ack_out
, listcount(oi
->obuf
));
4101 /* OSPFv2 Packet Counters */
4102 static int show_ip_ospf_interface_traffic_common(
4103 struct vty
*vty
, struct ospf
*ospf
, char *intf_name
, json_object
*json
,
4104 int display_once
, uint8_t use_vrf
, bool use_json
)
4106 struct vrf
*vrf
= NULL
;
4107 struct interface
*ifp
= NULL
;
4108 json_object
*json_vrf
= NULL
;
4109 json_object
*json_interface_sub
= NULL
;
4111 if (!use_json
&& !display_once
) {
4113 vty_out(vty
, "%-12s%-17s%-17s%-17s%-17s%-17s%-17s\n",
4114 "Interface", " HELLO", " DB-Desc", " LS-Req",
4115 " LS-Update", " LS-Ack", " Packets");
4116 vty_out(vty
, "%-10s%-18s%-18s%-17s%-17s%-17s%-17s\n", "",
4117 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
4118 " Rx/Tx", " Queued");
4120 "-------------------------------------------------------------------------------------------------------------\n");
4121 } else if (use_json
) {
4123 json_vrf
= json_object_new_object();
4128 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4130 if (intf_name
== NULL
) {
4131 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
4132 FOR_ALL_INTERFACES (vrf
, ifp
) {
4133 struct route_node
*rn
;
4134 struct ospf_interface
*oi
;
4136 if (ospf_oi_count(ifp
) == 0)
4139 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
4140 rn
= route_next(rn
)) {
4147 json_interface_sub
=
4148 json_object_new_object();
4151 show_ip_ospf_interface_traffic_sub(
4152 vty
, oi
, json_interface_sub
, use_json
);
4154 json_object_object_add(
4155 json_vrf
, ifp
->name
,
4156 json_interface_sub
);
4161 /* Interface name is specified. */
4162 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
4164 struct route_node
*rn
;
4165 struct ospf_interface
*oi
;
4167 if (ospf_oi_count(ifp
) == 0) {
4169 " OSPF not enabled on this interface %s\n",
4174 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
4175 rn
= route_next(rn
)) {
4179 json_interface_sub
=
4180 json_object_new_object();
4183 show_ip_ospf_interface_traffic_sub(
4184 vty
, oi
, json_interface_sub
, use_json
);
4186 json_object_object_add(
4187 json_vrf
, ifp
->name
,
4188 json_interface_sub
);
4196 json_object_object_add(json
, ospf_get_name(ospf
),
4204 DEFUN (show_ip_ospf_interface
,
4205 show_ip_ospf_interface_cmd
,
4206 "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]",
4209 "OSPF information\n"
4212 "Interface information\n"
4217 bool uj
= use_json(argc
, argv
);
4218 struct listnode
*node
= NULL
;
4219 char *vrf_name
= NULL
, *intf_name
= NULL
;
4220 bool all_vrf
= false;
4221 int ret
= CMD_SUCCESS
;
4223 int idx_vrf
= 0, idx_intf
= 0;
4224 uint8_t use_vrf
= 0;
4225 json_object
*json
= NULL
;
4227 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4229 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4230 intf_name
= argv
[idx_intf
]->arg
;
4233 json
= json_object_new_object();
4235 /* vrf input is provided could be all or specific vrf*/
4239 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4240 if (!ospf
->oi_running
)
4242 ret
= show_ip_ospf_interface_common(
4243 vty
, ospf
, intf_name
, use_vrf
, json
,
4248 vty_json(vty
, json
);
4250 vty_out(vty
, "%% OSPF is not enabled\n");
4254 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4255 if (ospf
== NULL
|| !ospf
->oi_running
) {
4257 vty_json(vty
, json
);
4260 "%% OSPF is not enabled in vrf %s\n",
4265 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
4269 /* Display default ospf (instance 0) info */
4270 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4271 if (ospf
== NULL
|| !ospf
->oi_running
) {
4273 vty_json(vty
, json
);
4276 "%% OSPF is not enabled in vrf default\n");
4280 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
4285 vty_json(vty
, json
);
4290 DEFUN (show_ip_ospf_instance_interface
,
4291 show_ip_ospf_instance_interface_cmd
,
4292 "show ip ospf (1-65535) interface [INTERFACE] [json]",
4295 "OSPF information\n"
4297 "Interface information\n"
4304 unsigned short instance
= 0;
4305 bool uj
= use_json(argc
, argv
);
4306 char *intf_name
= NULL
;
4307 int ret
= CMD_SUCCESS
;
4308 json_object
*json
= NULL
;
4310 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4311 if (instance
!= ospf_instance
)
4312 return CMD_NOT_MY_INSTANCE
;
4314 ospf
= ospf_lookup_instance(instance
);
4315 if (!ospf
|| !ospf
->oi_running
)
4319 json
= json_object_new_object();
4321 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4322 intf_name
= argv
[idx_intf
]->arg
;
4324 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
, 0, json
, uj
);
4327 vty_json(vty
, json
);
4332 DEFUN (show_ip_ospf_interface_traffic
,
4333 show_ip_ospf_interface_traffic_cmd
,
4334 "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]",
4337 "OSPF information\n"
4340 "Interface information\n"
4341 "Protocol Packet counters\n"
4345 struct ospf
*ospf
= NULL
;
4346 struct listnode
*node
= NULL
;
4347 char *vrf_name
= NULL
, *intf_name
= NULL
;
4348 bool all_vrf
= false;
4350 int idx_vrf
= 0, idx_intf
= 0;
4351 bool uj
= use_json(argc
, argv
);
4352 json_object
*json
= NULL
;
4353 int ret
= CMD_SUCCESS
;
4354 int display_once
= 0;
4355 uint8_t use_vrf
= 0;
4357 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4359 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4360 intf_name
= argv
[idx_intf
]->arg
;
4363 json
= json_object_new_object();
4368 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4369 if (!ospf
->oi_running
)
4372 ret
= show_ip_ospf_interface_traffic_common(
4373 vty
, ospf
, intf_name
, json
,
4374 display_once
, use_vrf
, uj
);
4379 vty_json(vty
, json
);
4383 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4384 if (ospf
== NULL
|| !ospf
->oi_running
) {
4386 json_object_free(json
);
4390 ret
= show_ip_ospf_interface_traffic_common(
4391 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4393 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4394 if (ospf
== NULL
|| !ospf
->oi_running
) {
4396 json_object_free(json
);
4400 ret
= show_ip_ospf_interface_traffic_common(
4401 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4405 vty_json(vty
, json
);
4411 static void show_ip_ospf_neighbour_header(struct vty
*vty
)
4413 vty_out(vty
, "\n%-15s %-3s %-15s %-15s %-9s %-15s %-32s %5s %5s %5s\n",
4414 "Neighbor ID", "Pri", "State", "Up Time", "Dead Time",
4415 "Address", "Interface", "RXmtL", "RqstL", "DBsmL");
4418 static void show_ip_ospf_neighbour_brief(struct vty
*vty
,
4419 struct ospf_neighbor
*nbr
,
4420 struct ospf_neighbor
*prev_nbr
,
4421 json_object
*json
, bool use_json
)
4424 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4425 json_object
*json_neighbor
= NULL
, *json_neigh_array
= NULL
;
4426 struct timeval res
= {.tv_sec
= 0, .tv_usec
= 0};
4428 char uptime
[OSPF_TIME_DUMP_SIZE
];
4430 if (nbr
->ts_last_progress
.tv_sec
|| nbr
->ts_last_progress
.tv_usec
)
4432 monotime_since(&nbr
->ts_last_progress
, &res
) / 1000LL;
4435 char neigh_str
[INET_ADDRSTRLEN
];
4437 if (prev_nbr
&& !IPV4_ADDR_SAME(&prev_nbr
->src
, &nbr
->src
)) {
4438 /* Start new neigh list */
4439 json_neigh_array
= NULL
;
4442 if (nbr
->state
== NSM_Attempt
&&
4443 nbr
->router_id
.s_addr
== INADDR_ANY
)
4444 strlcpy(neigh_str
, "neighbor", sizeof(neigh_str
));
4446 inet_ntop(AF_INET
, &nbr
->router_id
, neigh_str
,
4449 json_object_object_get_ex(json
, neigh_str
, &json_neigh_array
);
4451 if (!json_neigh_array
) {
4452 json_neigh_array
= json_object_new_array();
4453 json_object_object_add(json
, neigh_str
,
4457 json_neighbor
= json_object_new_object();
4459 ospf_nbr_ism_state_message(nbr
, msgbuf
, sizeof(msgbuf
));
4460 json_object_string_add(json_neighbor
, "nbrState", msgbuf
);
4462 json_object_int_add(json_neighbor
, "nbrPriority",
4465 json_object_string_add(
4466 json_neighbor
, "converged",
4467 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
4468 json_object_string_add(json_neighbor
, "role",
4469 lookup_msg(ospf_ism_state_msg
,
4470 ospf_nbr_ism_state(nbr
),
4472 if (nbr
->t_inactivity
) {
4475 time_store
= monotime_until(&nbr
->t_inactivity
->u
.sands
,
4478 json_object_int_add(json_neighbor
, "upTimeInMsec",
4480 json_object_int_add(json_neighbor
,
4481 "routerDeadIntervalTimerDueMsec",
4483 json_object_string_add(
4484 json_neighbor
, "upTime",
4485 ospf_timeval_dump(&res
, uptime
,
4487 json_object_string_add(
4488 json_neighbor
, "deadTime",
4489 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
4492 json_object_string_add(json_neighbor
, "deadTimeMsecs",
4494 json_object_string_add(json_neighbor
,
4495 "routerDeadIntervalTimerDueMsec",
4498 json_object_string_addf(json_neighbor
, "ifaceAddress", "%pI4",
4500 json_object_string_add(json_neighbor
, "ifaceName",
4502 json_object_int_add(json_neighbor
,
4503 "linkStateRetransmissionListCounter",
4504 ospf_ls_retransmit_count(nbr
));
4505 json_object_int_add(json_neighbor
,
4506 "linkStateRequestListCounter",
4507 ospf_ls_request_count(nbr
));
4508 json_object_int_add(json_neighbor
, "databaseSummaryListCounter",
4509 ospf_db_summary_count(nbr
));
4511 json_object_array_add(json_neigh_array
, json_neighbor
);
4513 ospf_nbr_ism_state_message(nbr
, msgbuf
, sizeof(msgbuf
));
4515 if (nbr
->state
== NSM_Attempt
&&
4516 nbr
->router_id
.s_addr
== INADDR_ANY
)
4517 vty_out(vty
, "%-15s %3d %-15s ", "-", nbr
->priority
,
4520 vty_out(vty
, "%-15pI4 %3d %-15s ", &nbr
->router_id
,
4521 nbr
->priority
, msgbuf
);
4523 vty_out(vty
, "%-15s ",
4524 ospf_timeval_dump(&res
, uptime
, sizeof(uptime
)));
4526 vty_out(vty
, "%9s ",
4527 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
4529 vty_out(vty
, "%-15pI4 ", &nbr
->src
);
4530 vty_out(vty
, "%-32s %5ld %5ld %5d\n", IF_NAME(nbr
->oi
),
4531 ospf_ls_retransmit_count(nbr
),
4532 ospf_ls_request_count(nbr
), ospf_db_summary_count(nbr
));
4536 static void show_ip_ospf_neighbor_sub(struct vty
*vty
,
4537 struct ospf_interface
*oi
,
4538 json_object
*json
, bool use_json
)
4540 struct route_node
*rn
;
4541 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
4543 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
4549 /* Do not show myself. */
4550 if (nbr
== oi
->nbr_self
)
4552 /* Down state is not shown. */
4553 if (nbr
->state
== NSM_Down
)
4558 show_ip_ospf_neighbour_brief(vty
, nbr
, prev_nbr
, json
,
4563 static int show_ip_ospf_neighbor_common(struct vty
*vty
, struct ospf
*ospf
,
4564 json_object
*json
, bool use_json
,
4567 struct ospf_interface
*oi
;
4568 struct listnode
*node
;
4569 json_object
*json_vrf
= NULL
;
4570 json_object
*json_nbr_sub
= NULL
;
4574 json_vrf
= json_object_new_object();
4577 json_nbr_sub
= json_object_new_object();
4580 if (ospf
->instance
) {
4582 json_object_int_add(json
, "ospfInstance",
4585 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4588 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4590 show_ip_ospf_neighbour_header(vty
);
4592 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4593 if (ospf_interface_neighbor_count(oi
) == 0)
4595 show_ip_ospf_neighbor_sub(vty
, oi
, json_nbr_sub
, use_json
);
4599 json_object_object_add(json_vrf
, "neighbors", json_nbr_sub
);
4601 json_object_object_add(json
, ospf_get_name(ospf
),
4609 DEFUN (show_ip_ospf_neighbor
,
4610 show_ip_ospf_neighbor_cmd
,
4611 "show ip ospf [vrf <NAME|all>] neighbor [json]",
4614 "OSPF information\n"
4621 bool uj
= use_json(argc
, argv
);
4622 struct listnode
*node
= NULL
;
4623 char *vrf_name
= NULL
;
4624 bool all_vrf
= false;
4625 int ret
= CMD_SUCCESS
;
4628 uint8_t use_vrf
= 0;
4629 json_object
*json
= NULL
;
4631 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4634 json
= json_object_new_object();
4636 /* vrf input is provided could be all or specific vrf*/
4640 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4641 if (!ospf
->oi_running
)
4643 ret
= show_ip_ospf_neighbor_common(
4644 vty
, ospf
, json
, uj
, use_vrf
);
4648 vty_json(vty
, json
);
4650 vty_out(vty
, "OSPF is not enabled\n");
4655 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4656 if (ospf
== NULL
|| !ospf
->oi_running
) {
4658 vty_json(vty
, json
);
4661 "%% OSPF is not enabled in vrf %s\n",
4667 /* Display default ospf (instance 0) info */
4668 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4669 if (ospf
== NULL
|| !ospf
->oi_running
) {
4671 vty_json(vty
, json
);
4674 "%% OSPF is not enabled in vrf default\n");
4681 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
,
4685 vty_out(vty
, "%s\n",
4686 json_object_to_json_string_ext(
4687 json
, JSON_C_TO_STRING_PRETTY
));
4692 json_object_free(json
);
4698 DEFUN (show_ip_ospf_instance_neighbor
,
4699 show_ip_ospf_instance_neighbor_cmd
,
4700 "show ip ospf (1-65535) neighbor [json]",
4703 "OSPF information\n"
4710 unsigned short instance
= 0;
4711 bool uj
= use_json(argc
, argv
);
4712 json_object
*json
= NULL
;
4713 int ret
= CMD_SUCCESS
;
4715 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4716 if (instance
!= ospf_instance
)
4717 return CMD_NOT_MY_INSTANCE
;
4719 ospf
= ospf_lookup_instance(instance
);
4720 if (!ospf
|| !ospf
->oi_running
)
4724 json
= json_object_new_object();
4726 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
, 0);
4729 vty_json(vty
, json
);
4734 static int show_ip_ospf_neighbor_all_common(struct vty
*vty
, struct ospf
*ospf
,
4735 json_object
*json
, bool use_json
,
4738 struct listnode
*node
;
4739 struct ospf_interface
*oi
;
4740 char buf
[PREFIX_STRLEN
];
4741 json_object
*json_vrf
= NULL
;
4742 json_object
*json_neighbor_sub
= NULL
;
4746 json_vrf
= json_object_new_object();
4751 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4753 show_ip_ospf_neighbour_header(vty
);
4755 if (ospf
->instance
) {
4757 json_object_int_add(json_vrf
, "ospfInstance",
4760 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4763 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4764 struct listnode
*nbr_node
;
4765 struct ospf_nbr_nbma
*nbr_nbma
;
4767 show_ip_ospf_neighbor_sub(vty
, oi
, json_vrf
, use_json
);
4769 /* print Down neighbor status */
4770 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nbr_node
, nbr_nbma
)) {
4771 if (nbr_nbma
->nbr
== NULL
4772 || nbr_nbma
->nbr
->state
== NSM_Down
) {
4775 json_object_new_object();
4776 json_object_int_add(json_neighbor_sub
,
4778 nbr_nbma
->priority
);
4779 json_object_boolean_true_add(
4782 json_object_string_add(
4786 json_object_int_add(
4788 "nbrNbmaRetransmitCounter", 0);
4789 json_object_int_add(
4791 "nbrNbmaRequestCounter", 0);
4792 json_object_int_add(
4794 "nbrNbmaDbSummaryCounter", 0);
4795 json_object_object_add(
4798 &nbr_nbma
->addr
, buf
,
4802 vty_out(vty
, "%-15s %3d %-15s %9s ",
4803 "-", nbr_nbma
->priority
, "Down",
4806 "%-32pI4 %-20s %5d %5d %5d\n",
4808 IF_NAME(oi
), 0, 0, 0);
4816 json_object_object_add(json
, ospf_get_name(ospf
),
4824 DEFUN (show_ip_ospf_neighbor_all
,
4825 show_ip_ospf_neighbor_all_cmd
,
4826 "show ip ospf [vrf <NAME|all>] neighbor all [json]",
4829 "OSPF information\n"
4833 "include down status neighbor\n"
4837 bool uj
= use_json(argc
, argv
);
4838 struct listnode
*node
= NULL
;
4839 char *vrf_name
= NULL
;
4840 bool all_vrf
= false;
4841 int ret
= CMD_SUCCESS
;
4844 uint8_t use_vrf
= 0;
4845 json_object
*json
= NULL
;
4847 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4850 json
= json_object_new_object();
4852 /* vrf input is provided could be all or specific vrf*/
4856 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4857 if (!ospf
->oi_running
)
4859 ret
= show_ip_ospf_neighbor_all_common(
4860 vty
, ospf
, json
, uj
, use_vrf
);
4864 vty_json(vty
, json
);
4869 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4870 if (ospf
== NULL
|| !ospf
->oi_running
) {
4872 json_object_free(json
);
4876 /* Display default ospf (instance 0) info */
4877 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4878 if (ospf
== NULL
|| !ospf
->oi_running
) {
4880 json_object_free(json
);
4886 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
,
4889 vty_out(vty
, "%s\n",
4890 json_object_to_json_string_ext(
4891 json
, JSON_C_TO_STRING_PRETTY
));
4896 json_object_free(json
);
4901 DEFUN (show_ip_ospf_instance_neighbor_all
,
4902 show_ip_ospf_instance_neighbor_all_cmd
,
4903 "show ip ospf (1-65535) neighbor all [json]",
4906 "OSPF information\n"
4909 "include down status neighbor\n"
4914 unsigned short instance
= 0;
4915 bool uj
= use_json(argc
, argv
);
4916 json_object
*json
= NULL
;
4917 int ret
= CMD_SUCCESS
;
4919 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4920 if (instance
!= ospf_instance
)
4921 return CMD_NOT_MY_INSTANCE
;
4923 ospf
= ospf_lookup_instance(instance
);
4924 if (!ospf
|| !ospf
->oi_running
)
4927 json
= json_object_new_object();
4929 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
, 0);
4932 vty_json(vty
, json
);
4937 static int show_ip_ospf_neighbor_int_common(struct vty
*vty
, struct ospf
*ospf
,
4938 const char *ifname
, bool use_json
,
4941 struct interface
*ifp
;
4942 struct route_node
*rn
;
4943 json_object
*json
= NULL
;
4946 json
= json_object_new_object();
4948 if (ospf
->instance
) {
4950 json_object_int_add(json
, "ospfInstance",
4953 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4956 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
4958 ifp
= if_lookup_by_name(ifname
, ospf
->vrf_id
);
4961 json_object_boolean_true_add(json
, "noSuchIface");
4963 vty_out(vty
, "No such interface.\n");
4967 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
4968 struct ospf_interface
*oi
= rn
->info
;
4973 show_ip_ospf_neighbor_sub(vty
, oi
, json
, use_json
);
4977 vty_json(vty
, json
);
4984 DEFPY(show_ip_ospf_instance_neighbor_int
,
4985 show_ip_ospf_instance_neighbor_int_cmd
,
4986 "show ip ospf (1-65535)$instance neighbor IFNAME$ifname [json$json]",
4989 "OSPF information\n"
4998 show_ip_ospf_neighbour_header(vty
);
5000 if (instance
!= ospf_instance
)
5001 return CMD_NOT_MY_INSTANCE
;
5003 ospf
= ospf_lookup_instance(instance
);
5004 if (!ospf
|| !ospf
->oi_running
)
5008 show_ip_ospf_neighbour_header(vty
);
5010 return show_ip_ospf_neighbor_int_common(vty
, ospf
, ifname
, !!json
, 0);
5013 static void show_ip_ospf_nbr_nbma_detail_sub(struct vty
*vty
,
5014 struct ospf_interface
*oi
,
5015 struct ospf_nbr_nbma
*nbr_nbma
,
5016 bool use_json
, json_object
*json
)
5018 char timebuf
[OSPF_TIME_DUMP_SIZE
];
5019 json_object
*json_sub
= NULL
;
5022 json_sub
= json_object_new_object();
5023 else /* Show neighbor ID. */
5024 vty_out(vty
, " Neighbor %s,", "-");
5026 /* Show interface address. */
5028 json_object_string_addf(json_sub
, "ifaceAddress", "%pI4",
5031 vty_out(vty
, " interface address %pI4\n",
5036 json_object_string_add(json_sub
, "areaId",
5037 ospf_area_desc_string(oi
->area
));
5038 json_object_string_add(json_sub
, "iface", IF_NAME(oi
));
5040 vty_out(vty
, " In the area %s via interface %s\n",
5041 ospf_area_desc_string(oi
->area
), IF_NAME(oi
));
5043 /* Show neighbor priority and state. */
5045 json_object_int_add(json_sub
, "nbrPriority",
5046 nbr_nbma
->priority
);
5047 json_object_string_add(json_sub
, "nbrState", "down");
5049 vty_out(vty
, " Neighbor priority is %d, State is %s,",
5050 nbr_nbma
->priority
, "Down");
5052 /* Show state changes. */
5054 json_object_int_add(json_sub
, "stateChangeCounter",
5055 nbr_nbma
->state_change
);
5057 vty_out(vty
, " %d state changes\n", nbr_nbma
->state_change
);
5059 /* Show PollInterval */
5061 json_object_int_add(json_sub
, "pollInterval", nbr_nbma
->v_poll
);
5063 vty_out(vty
, " Poll interval %d\n", nbr_nbma
->v_poll
);
5065 /* Show poll-interval timer. */
5066 if (nbr_nbma
->t_poll
) {
5069 time_store
= monotime_until(&nbr_nbma
->t_poll
->u
.sands
,
5071 json_object_int_add(json_sub
,
5072 "pollIntervalTimerDueMsec",
5075 vty_out(vty
, " Poll timer due in %s\n",
5076 ospf_timer_dump(nbr_nbma
->t_poll
, timebuf
,
5080 /* Show poll-interval timer thread. */
5082 if (nbr_nbma
->t_poll
!= NULL
)
5083 json_object_string_add(json_sub
,
5084 "pollIntervalTimerThread", "on");
5086 vty_out(vty
, " Thread Poll Timer %s\n",
5087 nbr_nbma
->t_poll
!= NULL
? "on" : "off");
5090 json_object_object_add(json
, "noNbrId", json_sub
);
5093 static void show_ip_ospf_neighbor_detail_sub(struct vty
*vty
,
5094 struct ospf_interface
*oi
,
5095 struct ospf_neighbor
*nbr
,
5096 struct ospf_neighbor
*prev_nbr
,
5097 json_object
*json
, bool use_json
)
5099 char timebuf
[OSPF_TIME_DUMP_SIZE
];
5100 json_object
*json_neigh
= NULL
, *json_neigh_array
= NULL
;
5101 char neigh_str
[INET_ADDRSTRLEN
] = {0};
5102 char neigh_state
[16] = {0};
5103 struct ospf_neighbor
*nbr_dr
, *nbr_bdr
;
5107 !IPV4_ADDR_SAME(&prev_nbr
->src
, &nbr
->src
)) {
5108 json_neigh_array
= NULL
;
5111 if (nbr
->state
== NSM_Attempt
5112 && nbr
->router_id
.s_addr
== INADDR_ANY
)
5113 strlcpy(neigh_str
, "noNbrId", sizeof(neigh_str
));
5115 inet_ntop(AF_INET
, &nbr
->router_id
,
5116 neigh_str
, sizeof(neigh_str
));
5118 json_object_object_get_ex(json
, neigh_str
, &json_neigh_array
);
5120 if (!json_neigh_array
) {
5121 json_neigh_array
= json_object_new_array();
5122 json_object_object_add(json
, neigh_str
,
5126 json_neigh
= json_object_new_object();
5129 /* Show neighbor ID. */
5130 if (nbr
->state
== NSM_Attempt
5131 && nbr
->router_id
.s_addr
== INADDR_ANY
)
5132 vty_out(vty
, " Neighbor %s,", "-");
5134 vty_out(vty
, " Neighbor %pI4,",
5138 /* Show interface address. */
5140 json_object_string_addf(json_neigh
, "ifaceAddress", "%pI4",
5141 &nbr
->address
.u
.prefix4
);
5143 vty_out(vty
, " interface address %pI4\n",
5144 &nbr
->address
.u
.prefix4
);
5148 json_object_string_add(json_neigh
, "areaId",
5149 ospf_area_desc_string(oi
->area
));
5150 json_object_string_add(json_neigh
, "ifaceName", oi
->ifp
->name
);
5152 json_object_string_addf(json_neigh
, "localIfaceAddress",
5154 &oi
->address
->u
.prefix4
);
5156 vty_out(vty
, " In the area %s via interface %s",
5157 ospf_area_desc_string(oi
->area
), oi
->ifp
->name
);
5159 vty_out(vty
, " local interface IP %pI4\n",
5160 &oi
->address
->u
.prefix4
);
5165 /* Show neighbor priority and state. */
5166 ospf_nbr_ism_state_message(nbr
, neigh_state
, sizeof(neigh_state
));
5168 json_object_int_add(json_neigh
, "nbrPriority", nbr
->priority
);
5169 json_object_string_add(json_neigh
, "nbrState", neigh_state
);
5170 json_object_string_add(json_neigh
, "role",
5171 lookup_msg(ospf_ism_state_msg
,
5172 ospf_nbr_ism_state(nbr
),
5176 " Neighbor priority is %d, State is %s, Role is %s,",
5177 nbr
->priority
, neigh_state
,
5178 lookup_msg(ospf_ism_state_msg
, ospf_nbr_ism_state(nbr
),
5181 /* Show state changes. */
5183 json_object_int_add(json_neigh
, "stateChangeCounter",
5186 vty_out(vty
, " %d state changes\n", nbr
->state_change
);
5188 if (nbr
->ts_last_progress
.tv_sec
|| nbr
->ts_last_progress
.tv_usec
) {
5193 monotime_since(&nbr
->ts_last_progress
, &res
) / 1000LL;
5195 json_object_int_add(json_neigh
, "lastPrgrsvChangeMsec",
5199 " Most recent state change statistics:\n");
5200 vty_out(vty
, " Progressive change %s ago\n",
5201 ospf_timeval_dump(&res
, timebuf
,
5206 if (nbr
->ts_last_regress
.tv_sec
|| nbr
->ts_last_regress
.tv_usec
) {
5211 monotime_since(&nbr
->ts_last_regress
, &res
) / 1000LL;
5213 json_object_int_add(json_neigh
,
5214 "lastRegressiveChangeMsec",
5216 if (nbr
->last_regress_str
)
5217 json_object_string_add(
5219 "lastRegressiveChangeReason",
5220 nbr
->last_regress_str
);
5223 " Regressive change %s ago, due to %s\n",
5224 ospf_timeval_dump(&res
, timebuf
,
5226 (nbr
->last_regress_str
? nbr
->last_regress_str
5231 /* Show Designated Router ID. */
5232 if (DR(oi
).s_addr
== INADDR_ANY
) {
5235 " No designated router on this network\n");
5237 nbr_dr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &DR(oi
));
5240 json_object_string_addf(
5241 json_neigh
, "routerDesignatedId",
5242 "%pI4", &nbr_dr
->router_id
);
5244 vty_out(vty
, " DR is %pI4,",
5245 &nbr_dr
->router_id
);
5249 /* Show Backup Designated Router ID. */
5250 nbr_bdr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &BDR(oi
));
5251 if (nbr_bdr
== NULL
) {
5254 " No backup designated router on this network\n");
5257 json_object_string_addf(json_neigh
,
5258 "routerDesignatedBackupId",
5259 "%pI4", &nbr_bdr
->router_id
);
5261 vty_out(vty
, " BDR is %pI4\n", &nbr_bdr
->router_id
);
5266 json_object_int_add(json_neigh
, "optionsCounter", nbr
->options
);
5267 json_object_string_add(json_neigh
, "optionsList",
5268 ospf_options_dump(nbr
->options
));
5270 vty_out(vty
, " Options %d %s\n", nbr
->options
,
5271 ospf_options_dump(nbr
->options
));
5273 /* Show Router Dead interval timer. */
5275 if (nbr
->t_inactivity
) {
5277 time_store
= monotime_until(&nbr
->t_inactivity
->u
.sands
,
5280 json_object_int_add(json_neigh
,
5281 "routerDeadIntervalTimerDueMsec",
5284 json_object_int_add(
5286 "routerDeadIntervalTimerDueMsec", -1);
5288 vty_out(vty
, " Dead timer due in %s\n",
5289 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
5292 /* Show Database Summary list. */
5294 json_object_int_add(json_neigh
, "databaseSummaryListCounter",
5295 ospf_db_summary_count(nbr
));
5297 vty_out(vty
, " Database Summary List %d\n",
5298 ospf_db_summary_count(nbr
));
5300 /* Show Link State Request list. */
5302 json_object_int_add(json_neigh
, "linkStateRequestListCounter",
5303 ospf_ls_request_count(nbr
));
5305 vty_out(vty
, " Link State Request List %ld\n",
5306 ospf_ls_request_count(nbr
));
5308 /* Show Link State Retransmission list. */
5310 json_object_int_add(json_neigh
,
5311 "linkStateRetransmissionListCounter",
5312 ospf_ls_retransmit_count(nbr
));
5314 vty_out(vty
, " Link State Retransmission List %ld\n",
5315 ospf_ls_retransmit_count(nbr
));
5317 /* Show inactivity timer thread. */
5319 if (nbr
->t_inactivity
!= NULL
)
5320 json_object_string_add(json_neigh
,
5321 "threadInactivityTimer", "on");
5323 vty_out(vty
, " Thread Inactivity Timer %s\n",
5324 nbr
->t_inactivity
!= NULL
? "on" : "off");
5326 /* Show Database Description retransmission thread. */
5328 if (nbr
->t_db_desc
!= NULL
)
5329 json_object_string_add(
5331 "threadDatabaseDescriptionRetransmission",
5335 " Thread Database Description Retransmision %s\n",
5336 nbr
->t_db_desc
!= NULL
? "on" : "off");
5338 /* Show Link State Request Retransmission thread. */
5340 if (nbr
->t_ls_req
!= NULL
)
5341 json_object_string_add(
5343 "threadLinkStateRequestRetransmission", "on");
5346 " Thread Link State Request Retransmission %s\n",
5347 nbr
->t_ls_req
!= NULL
? "on" : "off");
5349 /* Show Link State Update Retransmission thread. */
5351 if (nbr
->t_ls_upd
!= NULL
)
5352 json_object_string_add(
5354 "threadLinkStateUpdateRetransmission",
5358 " Thread Link State Update Retransmission %s\n\n",
5359 nbr
->t_ls_upd
!= NULL
? "on" : "off");
5362 vty_out(vty
, " Graceful restart Helper info:\n");
5364 if (OSPF_GR_IS_ACTIVE_HELPER(nbr
)) {
5366 " Graceful Restart HELPER Status : Inprogress.\n");
5369 " Graceful Restart grace period time: %d (seconds).\n",
5370 nbr
->gr_helper_info
.recvd_grace_period
);
5371 vty_out(vty
, " Graceful Restart reason: %s.\n",
5372 ospf_restart_reason2str(
5373 nbr
->gr_helper_info
.gr_restart_reason
));
5376 " Graceful Restart HELPER Status : None\n");
5379 if (nbr
->gr_helper_info
.rejected_reason
5380 != OSPF_HELPER_REJECTED_NONE
)
5381 vty_out(vty
, " Helper rejected reason: %s.\n",
5382 ospf_rejected_reason2str(
5383 nbr
->gr_helper_info
.rejected_reason
));
5385 if (nbr
->gr_helper_info
.helper_exit_reason
5386 != OSPF_GR_HELPER_EXIT_NONE
)
5387 vty_out(vty
, " Last helper exit reason: %s.\n\n",
5388 ospf_exit_reason2str(
5389 nbr
->gr_helper_info
.helper_exit_reason
));
5393 json_object_string_add(json_neigh
, "grHelperStatus",
5394 OSPF_GR_IS_ACTIVE_HELPER(nbr
) ?
5397 if (OSPF_GR_IS_ACTIVE_HELPER(nbr
)) {
5398 json_object_int_add(
5399 json_neigh
, "graceInterval",
5400 nbr
->gr_helper_info
.recvd_grace_period
);
5401 json_object_string_add(
5402 json_neigh
, "grRestartReason",
5403 ospf_restart_reason2str(
5404 nbr
->gr_helper_info
.gr_restart_reason
));
5407 if (nbr
->gr_helper_info
.rejected_reason
5408 != OSPF_HELPER_REJECTED_NONE
)
5409 json_object_string_add(
5410 json_neigh
, "helperRejectReason",
5411 ospf_rejected_reason2str(
5412 nbr
->gr_helper_info
.rejected_reason
));
5414 if (nbr
->gr_helper_info
.helper_exit_reason
5415 != OSPF_GR_HELPER_EXIT_NONE
)
5416 json_object_string_add(
5417 json_neigh
, "helperExitReason",
5418 ospf_exit_reason2str(
5420 .helper_exit_reason
));
5423 bfd_sess_show(vty
, json_neigh
, nbr
->bfd_session
);
5426 json_object_array_add(json_neigh_array
, json_neigh
);
5430 static int show_ip_ospf_neighbor_id_common(struct vty
*vty
, struct ospf
*ospf
,
5431 struct in_addr
*router_id
,
5432 bool use_json
, uint8_t use_vrf
,
5434 json_object
*json_vrf
)
5436 struct listnode
*node
;
5437 struct ospf_neighbor
*nbr
;
5438 struct ospf_interface
*oi
;
5439 json_object
*json
= NULL
;
5442 json
= json_object_new_object();
5444 if (ospf
->instance
) {
5446 json_object_int_add(json
, "ospfInstance",
5449 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5452 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
5454 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5455 nbr
= ospf_nbr_lookup_by_routerid(oi
->nbrs
, router_id
);
5461 show_ip_ospf_neighbor_detail_sub(vty
, oi
, nbr
, NULL
,
5464 show_ip_ospf_neighbour_brief(vty
, nbr
, NULL
, json
,
5468 if (json_vrf
&& use_json
) {
5469 json_object_object_add(
5471 (ospf
->vrf_id
== VRF_DEFAULT
) ? "default" : ospf
->name
,
5477 vty_json(vty
, json
);
5484 DEFPY(show_ip_ospf_neighbor_id
,
5485 show_ip_ospf_neighbor_id_cmd
,
5486 "show ip ospf [vrf NAME$vrf_name] neighbor A.B.C.D$router_id [detail$detail] [json$json]",
5489 "OSPF information\n"
5497 struct listnode
*node
;
5498 int ret
= CMD_SUCCESS
;
5501 if (vrf_name
&& !strmatch(vrf_name
, "all")) {
5502 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5503 if (ospf
== NULL
|| !ospf
->oi_running
) {
5506 "%% OSPF is not enabled in vrf %s\n",
5509 vty_json_empty(vty
);
5512 ret
= show_ip_ospf_neighbor_id_common(
5513 vty
, ospf
, &router_id
, !!json
, 0, !!detail
, NULL
);
5515 json_object
*json_vrf
= NULL
;
5518 json_vrf
= json_object_new_object();
5519 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5520 if (!ospf
->oi_running
)
5522 ret
= show_ip_ospf_neighbor_id_common(
5523 vty
, ospf
, &router_id
, !!json
, 0, !!detail
,
5527 vty_json(vty
, json_vrf
);
5533 DEFPY(show_ip_ospf_instance_neighbor_id
, show_ip_ospf_instance_neighbor_id_cmd
,
5534 "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [detail$detail] [json$json]",
5536 "OSPF information\n"
5540 "Detailed output\n" JSON_STR
)
5544 if (instance
!= ospf_instance
)
5545 return CMD_NOT_MY_INSTANCE
;
5547 ospf
= ospf_lookup_instance(instance
);
5548 if (!ospf
|| !ospf
->oi_running
)
5551 return show_ip_ospf_neighbor_id_common(vty
, ospf
, &router_id
, !!json
, 0,
5555 static int show_ip_ospf_neighbor_detail_common(struct vty
*vty
,
5557 json_object
*json
, bool use_json
,
5560 struct ospf_interface
*oi
;
5561 struct listnode
*node
;
5562 json_object
*json_vrf
= NULL
;
5563 json_object
*json_nbr_sub
= NULL
;
5567 json_vrf
= json_object_new_object();
5571 json_nbr_sub
= json_object_new_object();
5574 if (ospf
->instance
) {
5576 json_object_int_add(json
, "ospfInstance",
5579 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5582 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5584 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5585 struct route_node
*rn
;
5586 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
5588 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5594 if (nbr
!= oi
->nbr_self
) {
5595 if (nbr
->state
!= NSM_Down
) {
5596 show_ip_ospf_neighbor_detail_sub(
5597 vty
, oi
, nbr
, prev_nbr
,
5598 json_nbr_sub
, use_json
);
5606 json_object_object_add(json_vrf
, "neighbors",
5609 json_object_object_add(json
, ospf_get_name(ospf
),
5617 DEFPY(show_ip_ospf_neighbor_detail
,
5618 show_ip_ospf_neighbor_detail_cmd
,
5619 "show ip ospf [vrf <NAME|all>$vrf_name] neighbor detail [json$json]",
5622 "OSPF information\n"
5626 "detail of all neighbors\n"
5630 struct listnode
*node
= NULL
;
5631 int ret
= CMD_SUCCESS
;
5633 uint8_t use_vrf
= 0;
5634 json_object
*json_vrf
= NULL
;
5637 json_vrf
= json_object_new_object();
5639 /* vrf input is provided could be all or specific vrf*/
5642 if (strmatch(vrf_name
, "all")) {
5643 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5644 if (!ospf
->oi_running
)
5646 ret
= show_ip_ospf_neighbor_detail_common(
5647 vty
, ospf
, json_vrf
, !!json
, use_vrf
);
5650 vty_json(vty
, json_vrf
);
5654 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5655 if (ospf
== NULL
|| !ospf
->oi_running
) {
5657 vty_json(vty
, json_vrf
);
5660 "%% OSPF is not enabled in vrf %s\n",
5665 /* Display default ospf (instance 0) info */
5666 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5667 if (ospf
== NULL
|| !ospf
->oi_running
) {
5669 vty_json(vty
, json_vrf
);
5671 vty_out(vty
, "%% OSPF is not enabled\n");
5677 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json_vrf
,
5681 vty_json(vty
, json_vrf
);
5686 DEFUN (show_ip_ospf_instance_neighbor_detail
,
5687 show_ip_ospf_instance_neighbor_detail_cmd
,
5688 "show ip ospf (1-65535) neighbor detail [json]",
5691 "OSPF information\n"
5694 "detail of all neighbors\n"
5699 unsigned short instance
= 0;
5700 bool uj
= use_json(argc
, argv
);
5701 json_object
*json
= NULL
;
5702 int ret
= CMD_SUCCESS
;
5704 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5705 if (instance
!= ospf_instance
)
5706 return CMD_NOT_MY_INSTANCE
;
5708 ospf
= ospf_lookup_instance(instance
);
5709 if (!ospf
|| !ospf
->oi_running
)
5713 json
= json_object_new_object();
5715 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
, 0);
5718 vty_json(vty
, json
);
5723 static int show_ip_ospf_neighbor_detail_all_common(struct vty
*vty
,
5729 struct listnode
*node
;
5730 struct ospf_interface
*oi
;
5731 json_object
*json_vrf
= NULL
;
5735 json_vrf
= json_object_new_object();
5740 if (ospf
->instance
) {
5742 json_object_int_add(json
, "ospfInstance",
5745 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5748 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5750 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5751 struct route_node
*rn
;
5752 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
5753 struct ospf_nbr_nbma
*nbr_nbma
;
5755 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5761 if (nbr
!= oi
->nbr_self
)
5762 if (nbr
->state
!= NSM_Down
)
5763 show_ip_ospf_neighbor_detail_sub(
5764 vty
, oi
, rn
->info
, prev_nbr
,
5765 json_vrf
, use_json
);
5769 if (oi
->type
!= OSPF_IFTYPE_NBMA
)
5772 struct listnode
*nd
;
5774 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nd
, nbr_nbma
)) {
5775 if (nbr_nbma
->nbr
== NULL
||
5776 nbr_nbma
->nbr
->state
== NSM_Down
)
5777 show_ip_ospf_nbr_nbma_detail_sub(
5778 vty
, oi
, nbr_nbma
, use_json
, json_vrf
);
5784 json_object_object_add(json
, ospf_get_name(ospf
),
5793 DEFUN (show_ip_ospf_neighbor_detail_all
,
5794 show_ip_ospf_neighbor_detail_all_cmd
,
5795 "show ip ospf [vrf <NAME|all>] neighbor detail all [json]",
5798 "OSPF information\n"
5802 "detail of all neighbors\n"
5803 "include down status neighbor\n"
5807 bool uj
= use_json(argc
, argv
);
5808 struct listnode
*node
= NULL
;
5809 char *vrf_name
= NULL
;
5810 bool all_vrf
= false;
5811 int ret
= CMD_SUCCESS
;
5814 uint8_t use_vrf
= 0;
5815 json_object
*json
= NULL
;
5817 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5820 json
= json_object_new_object();
5822 /* vrf input is provided could be all or specific vrf*/
5826 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5827 if (!ospf
->oi_running
)
5829 ret
= show_ip_ospf_neighbor_detail_all_common(
5830 vty
, ospf
, json
, uj
, use_vrf
);
5834 vty_json(vty
, json
);
5838 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5839 if (ospf
== NULL
|| !ospf
->oi_running
) {
5841 json_object_free(json
);
5845 /* Display default ospf (instance 0) info */
5846 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5847 if (ospf
== NULL
|| !ospf
->oi_running
) {
5849 json_object_free(json
);
5855 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
,
5858 vty_out(vty
, "%s\n",
5859 json_object_to_json_string_ext(
5860 json
, JSON_C_TO_STRING_PRETTY
));
5865 json_object_free(json
);
5870 DEFUN (show_ip_ospf_instance_neighbor_detail_all
,
5871 show_ip_ospf_instance_neighbor_detail_all_cmd
,
5872 "show ip ospf (1-65535) neighbor detail all [json]",
5875 "OSPF information\n"
5878 "detail of all neighbors\n"
5879 "include down status neighbor\n"
5884 unsigned short instance
= 0;
5885 bool uj
= use_json(argc
, argv
);
5886 json_object
*json
= NULL
;
5887 int ret
= CMD_SUCCESS
;
5889 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5890 if (instance
!= ospf_instance
)
5891 return CMD_NOT_MY_INSTANCE
;
5893 ospf
= ospf_lookup_instance(instance
);
5894 if (!ospf
|| !ospf
->oi_running
)
5898 json
= json_object_new_object();
5900 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
, uj
, 0);
5903 vty_json(vty
, json
);
5908 static int show_ip_ospf_neighbor_int_detail_common(struct vty
*vty
,
5912 json_object
*json_vrf
)
5914 struct ospf_interface
*oi
;
5915 struct interface
*ifp
;
5916 struct route_node
*rn
, *nrn
;
5917 struct ospf_neighbor
*nbr
;
5918 json_object
*json
= NULL
;
5921 json
= json_object_new_object();
5923 json_object_object_add(json_vrf
,
5924 (ospf
->vrf_id
== VRF_DEFAULT
)
5930 if (ospf
->instance
) {
5932 json_object_int_add(json
, "ospfInstance",
5935 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5938 ifp
= if_lookup_by_name(ifname
, ospf
->vrf_id
);
5941 vty_out(vty
, "No such interface.\n");
5944 vty_json(vty
, json
);
5949 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
5955 for (nrn
= route_top(oi
->nbrs
); nrn
; nrn
= route_next(nrn
)) {
5961 if (nbr
== oi
->nbr_self
)
5964 if (nbr
->state
== NSM_Down
)
5967 show_ip_ospf_neighbor_detail_sub(vty
, oi
, nbr
, NULL
,
5974 vty_json(vty
, json
);
5982 DEFPY(show_ip_ospf_neighbor_int
,
5983 show_ip_ospf_neighbor_int_cmd
,
5984 "show ip ospf [vrf NAME$vrf_name] neighbor IFNAME$ifname [json$json]",
5987 "OSPF information\n"
5994 int ret
= CMD_SUCCESS
;
5995 struct interface
*ifp
= NULL
;
5996 vrf_id_t vrf_id
= VRF_DEFAULT
;
5997 struct vrf
*vrf
= NULL
;
5999 if (vrf_name
&& strmatch(vrf_name
, VRF_DEFAULT_NAME
))
6002 vrf
= vrf_lookup_by_name(vrf_name
);
6004 vrf_id
= vrf
->vrf_id
;
6006 ospf
= ospf_lookup_by_vrf_id(vrf_id
);
6008 if (!ospf
|| !ospf
->oi_running
) {
6010 vty_json_empty(vty
);
6015 show_ip_ospf_neighbour_header(vty
);
6017 ifp
= if_lookup_by_name(ifname
, vrf_id
);
6020 vty_json_empty(vty
);
6022 vty_out(vty
, "No such interface.\n");
6026 ret
= show_ip_ospf_neighbor_int_common(vty
, ospf
, ifname
, !!json
, 0);
6030 DEFPY(show_ip_ospf_neighbor_int_detail
,
6031 show_ip_ospf_neighbor_int_detail_cmd
,
6032 "show ip ospf [vrf NAME$vrf_name] neighbor IFNAME$ifname detail [json$json]",
6035 "OSPF information\n"
6039 "detail of all neighbors\n"
6043 struct listnode
*node
= NULL
;
6044 int ret
= CMD_SUCCESS
;
6045 bool ospf_output
= false;
6047 if (vrf_name
&& !strmatch(vrf_name
, "all")) {
6050 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6051 if (ospf
== NULL
|| !ospf
->oi_running
) {
6054 "%% OSPF is not enabled in vrf %s\n",
6057 vty_json_empty(vty
);
6060 return show_ip_ospf_neighbor_int_detail_common(
6061 vty
, ospf
, ifname
, !!json
, NULL
);
6064 json_object
*json_vrf
= NULL
;
6067 json_vrf
= json_object_new_object();
6069 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6070 if (!ospf
->oi_running
)
6073 ret
= show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, ifname
,
6078 vty_json(vty
, json_vrf
);
6083 vty_out(vty
, "%% OSPF instance not found\n");
6088 DEFPY(show_ip_ospf_instance_neighbor_int_detail
,
6089 show_ip_ospf_instance_neighbor_int_detail_cmd
,
6090 "show ip ospf (1-65535)$instance neighbor IFNAME$ifname detail [json$json]",
6093 "OSPF information\n"
6097 "detail of all neighbors\n"
6102 if (instance
!= ospf_instance
)
6103 return CMD_NOT_MY_INSTANCE
;
6105 ospf
= ospf_lookup_instance(instance
);
6106 if (!ospf
|| !ospf
->oi_running
)
6109 return show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, ifname
,
6113 /* Show functions */
6114 static int show_lsa_summary(struct vty
*vty
, struct ospf_lsa
*lsa
, int self
,
6115 json_object
*json_lsa
)
6117 struct router_lsa
*rl
;
6118 struct summary_lsa
*sl
;
6119 struct as_external_lsa
*asel
;
6120 struct prefix_ipv4 p
;
6125 /* If self option is set, check LSA self flag. */
6126 if (self
== 0 || IS_LSA_SELF(lsa
)) {
6129 /* LSA common part show. */
6130 vty_out(vty
, "%-15pI4", &lsa
->data
->id
);
6131 vty_out(vty
, "%-15pI4 %4d 0x%08lx 0x%04x",
6132 &lsa
->data
->adv_router
, LS_AGE(lsa
),
6133 (unsigned long)ntohl(lsa
->data
->ls_seqnum
),
6134 ntohs(lsa
->data
->checksum
));
6139 snprintf(seqnum
, sizeof(seqnum
), "%x",
6140 ntohl(lsa
->data
->ls_seqnum
));
6141 snprintf(checksum
, sizeof(checksum
), "%x",
6142 ntohs(lsa
->data
->checksum
));
6143 json_object_string_addf(json_lsa
, "lsId", "%pI4",
6145 json_object_string_addf(json_lsa
, "advertisedRouter",
6146 "%pI4", &lsa
->data
->adv_router
);
6147 json_object_int_add(json_lsa
, "lsaAge", LS_AGE(lsa
));
6148 json_object_string_add(json_lsa
, "sequenceNumber",
6150 json_object_string_add(json_lsa
, "checksum", checksum
);
6153 /* LSA specific part show. */
6154 switch (lsa
->data
->type
) {
6155 case OSPF_ROUTER_LSA
:
6156 rl
= (struct router_lsa
*)lsa
->data
;
6159 vty_out(vty
, " %-d", ntohs(rl
->links
));
6161 json_object_int_add(json_lsa
,
6165 case OSPF_SUMMARY_LSA
:
6166 sl
= (struct summary_lsa
*)lsa
->data
;
6169 p
.prefix
= sl
->header
.id
;
6170 p
.prefixlen
= ip_masklen(sl
->mask
);
6171 apply_mask_ipv4(&p
);
6174 vty_out(vty
, " %pFX", &p
);
6176 json_object_string_addf(
6177 json_lsa
, "summaryAddress", "%pFX", &p
);
6180 case OSPF_AS_EXTERNAL_LSA
:
6181 case OSPF_AS_NSSA_LSA
:
6182 asel
= (struct as_external_lsa
*)lsa
->data
;
6185 p
.prefix
= asel
->header
.id
;
6186 p
.prefixlen
= ip_masklen(asel
->mask
);
6187 apply_mask_ipv4(&p
);
6190 vty_out(vty
, " %s %pFX [0x%lx]",
6191 IS_EXTERNAL_METRIC(asel
->e
[0].tos
)
6195 (unsigned long)ntohl(
6196 asel
->e
[0].route_tag
));
6198 json_object_string_add(
6199 json_lsa
, "metricType",
6200 IS_EXTERNAL_METRIC(asel
->e
[0].tos
)
6203 json_object_string_addf(json_lsa
, "route",
6205 json_object_int_add(
6207 (unsigned long)ntohl(
6208 asel
->e
[0].route_tag
));
6211 case OSPF_NETWORK_LSA
:
6212 case OSPF_ASBR_SUMMARY_LSA
:
6213 case OSPF_OPAQUE_LINK_LSA
:
6214 case OSPF_OPAQUE_AREA_LSA
:
6215 case OSPF_OPAQUE_AS_LSA
:
6227 static const char *const show_database_desc
[] = {
6229 "Router Link States",
6231 "Summary Link States",
6232 "ASBR-Summary Link States",
6233 "AS External Link States",
6234 "Group Membership LSA",
6235 "NSSA-external Link States",
6237 "Link-Local Opaque-LSA",
6238 "Area-Local Opaque-LSA",
6239 "AS-external Opaque-LSA",
6242 static const char * const show_database_desc_json
[] = {
6245 "networkLinkStates",
6246 "summaryLinkStates",
6247 "asbrSummaryLinkStates",
6248 "asExternalLinkStates",
6249 "groupMembershipLsa",
6250 "nssaExternalLinkStates",
6252 "linkLocalOpaqueLsa",
6253 "areaLocalOpaqueLsa",
6254 "asExternalOpaqueLsa",
6257 static const char *const show_database_desc_count_json
[] = {
6259 "routerLinkStatesCount",
6260 "networkLinkStatesCount",
6261 "summaryLinkStatesCount",
6262 "asbrSummaryLinkStatesCount",
6263 "asExternalLinkStatesCount",
6264 "groupMembershipLsaCount",
6265 "nssaExternalLinkStatesCount",
6267 "linkLocalOpaqueLsaCount",
6268 "areaLocalOpaqueLsaCount",
6269 "asExternalOpaqueLsaCount",
6272 static const char *const show_database_header
[] = {
6274 "Link ID ADV Router Age Seq# CkSum Link count",
6275 "Link ID ADV Router Age Seq# CkSum",
6276 "Link ID ADV Router Age Seq# CkSum Route",
6277 "Link ID ADV Router Age Seq# CkSum",
6278 "Link ID ADV Router Age Seq# CkSum Route",
6279 " --- header for Group Member ----",
6280 "Link ID ADV Router Age Seq# CkSum Route",
6282 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6283 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6284 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6287 static void show_ip_ospf_database_header(struct vty
*vty
, struct ospf_lsa
*lsa
,
6290 struct router_lsa
*rlsa
= (struct router_lsa
*)lsa
->data
;
6293 if (IS_LSA_SELF(lsa
))
6294 vty_out(vty
, " LS age: %d%s\n", LS_AGE(lsa
),
6295 CHECK_FLAG(lsa
->data
->ls_age
, DO_NOT_AGE
)
6299 vty_out(vty
, " LS age: %d%s\n", LS_AGE(lsa
),
6300 CHECK_FLAG(lsa
->data
->ls_age
, DO_NOT_AGE
)
6303 vty_out(vty
, " Options: 0x%-2x : %s\n", lsa
->data
->options
,
6304 ospf_options_dump(lsa
->data
->options
));
6305 vty_out(vty
, " LS Flags: 0x%-2x %s\n", lsa
->flags
,
6306 ((lsa
->flags
& OSPF_LSA_LOCAL_XLT
)
6307 ? "(Translated from Type-7)"
6310 if (lsa
->data
->type
== OSPF_ROUTER_LSA
) {
6311 vty_out(vty
, " Flags: 0x%x", rlsa
->flags
);
6314 vty_out(vty
, " :%s%s%s%s",
6315 IS_ROUTER_LSA_BORDER(rlsa
) ? " ABR"
6317 IS_ROUTER_LSA_EXTERNAL(rlsa
) ? " ASBR"
6319 IS_ROUTER_LSA_VIRTUAL(rlsa
)
6322 IS_ROUTER_LSA_SHORTCUT(rlsa
)
6328 vty_out(vty
, " LS Type: %s\n",
6329 lookup_msg(ospf_lsa_type_msg
, lsa
->data
->type
, NULL
));
6330 vty_out(vty
, " Link State ID: %pI4 %s\n",
6332 lookup_msg(ospf_link_state_id_type_msg
, lsa
->data
->type
,
6334 vty_out(vty
, " Advertising Router: %pI4\n",
6335 &lsa
->data
->adv_router
);
6336 vty_out(vty
, " LS Seq Number: %08lx\n",
6337 (unsigned long)ntohl(lsa
->data
->ls_seqnum
));
6338 vty_out(vty
, " Checksum: 0x%04x\n",
6339 ntohs(lsa
->data
->checksum
));
6340 vty_out(vty
, " Length: %d\n\n", ntohs(lsa
->data
->length
));
6345 snprintf(seqnum
, 10, "%x", ntohl(lsa
->data
->ls_seqnum
));
6346 snprintf(checksum
, 10, "%x", ntohs(lsa
->data
->checksum
));
6348 json_object_int_add(json
, "lsaAge", LS_AGE(lsa
));
6349 json_object_string_add(json
, "options",
6350 ospf_options_dump(lsa
->data
->options
));
6351 json_object_int_add(json
, "lsaFlags", lsa
->flags
);
6353 if (lsa
->flags
& OSPF_LSA_LOCAL_XLT
)
6354 json_object_boolean_true_add(json
,
6355 "translatedFromType7");
6357 if (lsa
->data
->type
== OSPF_ROUTER_LSA
) {
6358 json_object_int_add(json
, "flags", rlsa
->flags
);
6361 if (IS_ROUTER_LSA_BORDER(rlsa
))
6362 json_object_boolean_true_add(json
,
6364 if (IS_ROUTER_LSA_EXTERNAL(rlsa
))
6365 json_object_boolean_true_add(json
,
6367 if (IS_ROUTER_LSA_VIRTUAL(rlsa
))
6368 json_object_boolean_true_add(
6369 json
, "vlEndpoint");
6370 if (IS_ROUTER_LSA_SHORTCUT(rlsa
))
6371 json_object_boolean_true_add(
6376 json_object_string_add(
6378 lookup_msg(ospf_lsa_type_msg
, lsa
->data
->type
, NULL
));
6379 json_object_string_addf(json
, "linkStateId", "%pI4",
6381 json_object_string_addf(json
, "advertisingRouter", "%pI4",
6382 &lsa
->data
->adv_router
);
6383 json_object_string_add(json
, "lsaSeqNumber", seqnum
);
6384 json_object_string_add(json
, "checksum", checksum
);
6385 json_object_int_add(json
, "length", ntohs(lsa
->data
->length
));
6389 static const char *const link_type_desc
[] = {
6391 "another Router (point-to-point)",
6392 "a Transit Network",
6397 static const char *const link_id_desc
[] = {
6398 "(null)", "Neighboring Router ID", "Designated Router address",
6399 "Net", "Neighboring Router ID",
6402 static const char *const link_data_desc
[] = {
6403 "(null)", "Router Interface address", "Router Interface address",
6404 "Network Mask", "Router Interface address",
6407 static const char *const link_id_desc_json
[] = {
6408 "null", "neighborRouterId", "designatedRouterAddress",
6409 "networkAddress", "neighborRouterId",
6412 static const char *const link_data_desc_json
[] = {
6413 "null", "routerInterfaceAddress", "routerInterfaceAddress",
6414 "networkMask", "routerInterfaceAddress",
6417 /* Show router-LSA each Link information. */
6418 static void show_ip_ospf_database_router_links(struct vty
*vty
,
6419 struct router_lsa
*rl
,
6424 json_object
*json_links
= NULL
;
6425 json_object
*json_link
= NULL
;
6427 char buf
[PREFIX_STRLEN
];
6430 json_links
= json_object_new_object();
6432 len
= ntohs(rl
->header
.length
) - 4;
6433 for (i
= 0; i
< ntohs(rl
->links
) && len
> 0; len
-= 12, i
++) {
6434 type
= rl
->link
[i
].type
;
6439 snprintf(link
, sizeof(link
), "link%u", i
);
6440 json_link
= json_object_new_object();
6441 json_object_string_add(json_link
, "linkType",
6442 link_type_desc
[type
]);
6443 json_object_string_add(json_link
,
6444 link_id_desc_json
[type
],
6446 &rl
->link
[i
].link_id
,
6448 json_object_string_add(
6449 json_link
, link_data_desc_json
[type
],
6450 inet_ntop(AF_INET
, &rl
->link
[i
].link_data
,
6452 json_object_int_add(json_link
, "numOfTosMetrics",
6454 json_object_int_add(json_link
, "tos0Metric",
6455 ntohs(rl
->link
[i
].metric
));
6456 json_object_object_add(json_links
, link
, json_link
);
6458 vty_out(vty
, " Link connected to: %s\n",
6459 link_type_desc
[type
]);
6460 vty_out(vty
, " (Link ID) %s: %pI4\n",
6462 &rl
->link
[i
].link_id
);
6463 vty_out(vty
, " (Link Data) %s: %pI4\n",
6464 link_data_desc
[type
],
6465 &rl
->link
[i
].link_data
);
6466 vty_out(vty
, " Number of TOS metrics: 0\n");
6467 vty_out(vty
, " TOS 0 Metric: %d\n",
6468 ntohs(rl
->link
[i
].metric
));
6473 json_object_object_add(json
, "routerLinks", json_links
);
6476 /* Show router-LSA detail information. */
6477 static int show_router_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6481 struct router_lsa
*rl
= (struct router_lsa
*)lsa
->data
;
6483 show_ip_ospf_database_header(vty
, lsa
, json
);
6486 vty_out(vty
, " Number of Links: %d\n\n",
6489 json_object_int_add(json
, "numOfLinks",
6492 show_ip_ospf_database_router_links(vty
, rl
, json
);
6501 /* Show network-LSA detail information. */
6502 static int show_network_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6506 char buf
[PREFIX_STRLEN
];
6507 json_object
*json_attached_rt
= NULL
;
6508 json_object
*json_router
= NULL
;
6511 json_attached_rt
= json_object_new_object();
6514 struct network_lsa
*nl
= (struct network_lsa
*)lsa
->data
;
6515 struct in_addr
*addr
;
6517 show_ip_ospf_database_header(vty
, lsa
, json
);
6520 vty_out(vty
, " Network Mask: /%d\n",
6521 ip_masklen(nl
->mask
));
6523 json_object_int_add(json
, "networkMask",
6524 ip_masklen(nl
->mask
));
6526 length
= lsa
->size
- OSPF_LSA_HEADER_SIZE
- 4;
6527 addr
= &nl
->routers
[0];
6528 for (i
= 0; length
> 0 && addr
;
6529 length
-= 4, addr
= &nl
->routers
[++i
])
6531 vty_out(vty
, " Attached Router: %pI4\n",
6535 json_router
= json_object_new_object();
6536 json_object_string_add(
6537 json_router
, "attachedRouterId",
6538 inet_ntop(AF_INET
, addr
, buf
,
6540 json_object_object_add(json_attached_rt
,
6541 inet_ntop(AF_INET
, addr
,
6549 json_object_object_add(json
, "attchedRouters",
6555 /* Show summary-LSA detail information. */
6556 static int show_summary_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6560 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
6562 show_ip_ospf_database_header(vty
, lsa
, json
);
6565 vty_out(vty
, " Network Mask: /%d\n",
6566 ip_masklen(sl
->mask
));
6567 vty_out(vty
, " TOS: 0 Metric: %d\n",
6568 GET_METRIC(sl
->metric
));
6571 json_object_int_add(json
, "networkMask",
6572 ip_masklen(sl
->mask
));
6573 json_object_int_add(json
, "tos0Metric",
6574 GET_METRIC(sl
->metric
));
6581 /* Show summary-ASBR-LSA detail information. */
6582 static int show_summary_asbr_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6586 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
6588 show_ip_ospf_database_header(vty
, lsa
, json
);
6591 vty_out(vty
, " Network Mask: /%d\n",
6592 ip_masklen(sl
->mask
));
6593 vty_out(vty
, " TOS: 0 Metric: %d\n",
6594 GET_METRIC(sl
->metric
));
6597 json_object_int_add(json
, "networkMask",
6598 ip_masklen(sl
->mask
));
6599 json_object_int_add(json
, "tos0Metric",
6600 GET_METRIC(sl
->metric
));
6607 /* Show AS-external-LSA detail information. */
6608 static int show_as_external_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6614 struct as_external_lsa
*al
=
6615 (struct as_external_lsa
*)lsa
->data
;
6617 show_ip_ospf_database_header(vty
, lsa
, json
);
6620 vty_out(vty
, " Network Mask: /%d\n",
6621 ip_masklen(al
->mask
));
6622 vty_out(vty
, " Metric Type: %s\n",
6623 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6624 ? "2 (Larger than any link state path)"
6626 vty_out(vty
, " TOS: 0\n");
6627 vty_out(vty
, " Metric: %d\n",
6628 GET_METRIC(al
->e
[0].metric
));
6629 vty_out(vty
, " Forward Address: %pI4\n",
6630 &al
->e
[0].fwd_addr
);
6632 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
6633 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6635 json_object_int_add(json
, "networkMask",
6636 ip_masklen(al
->mask
));
6637 json_object_string_add(
6639 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6640 ? "E2 (Larger than any link state path)"
6642 json_object_int_add(json
, "tos", tos
);
6643 json_object_int_add(json
, "metric",
6644 GET_METRIC(al
->e
[0].metric
));
6645 json_object_string_addf(json
, "forwardAddress", "%pI4",
6646 &(al
->e
[0].fwd_addr
));
6647 json_object_int_add(
6648 json
, "externalRouteTag",
6649 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6656 /* Show AS-NSSA-LSA detail information. */
6657 static int show_as_nssa_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6663 struct as_external_lsa
*al
=
6664 (struct as_external_lsa
*)lsa
->data
;
6666 show_ip_ospf_database_header(vty
, lsa
, json
);
6669 vty_out(vty
, " Network Mask: /%d\n",
6670 ip_masklen(al
->mask
));
6671 vty_out(vty
, " Metric Type: %s\n",
6672 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6673 ? "2 (Larger than any link state path)"
6675 vty_out(vty
, " TOS: 0\n");
6676 vty_out(vty
, " Metric: %d\n",
6677 GET_METRIC(al
->e
[0].metric
));
6678 vty_out(vty
, " NSSA: Forward Address: %pI4\n",
6679 &al
->e
[0].fwd_addr
);
6681 " External Route Tag: %" ROUTE_TAG_PRI
6683 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6685 json_object_int_add(json
, "networkMask",
6686 ip_masklen(al
->mask
));
6687 json_object_string_add(
6689 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6690 ? "E2 (Larger than any link state path)"
6692 json_object_int_add(json
, "tos", tos
);
6693 json_object_int_add(json
, "metric",
6694 GET_METRIC(al
->e
[0].metric
));
6695 json_object_string_addf(json
, "nssaForwardAddress",
6696 "%pI4", &al
->e
[0].fwd_addr
);
6697 json_object_int_add(
6698 json
, "externalRouteTag",
6699 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6706 static int show_func_dummy(struct vty
*vty
, struct ospf_lsa
*lsa
,
6712 static int show_opaque_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6716 show_ip_ospf_database_header(vty
, lsa
, json
);
6717 show_opaque_info_detail(vty
, lsa
, json
);
6724 int (*show_function
[])(struct vty
*, struct ospf_lsa
*, json_object
*) = {
6726 show_router_lsa_detail
,
6727 show_network_lsa_detail
,
6728 show_summary_lsa_detail
,
6729 show_summary_asbr_lsa_detail
,
6730 show_as_external_lsa_detail
,
6732 show_as_nssa_lsa_detail
, /* almost same as external */
6734 show_opaque_lsa_detail
,
6735 show_opaque_lsa_detail
,
6736 show_opaque_lsa_detail
,
6739 static void show_lsa_prefix_set(struct vty
*vty
, struct prefix_ls
*lp
,
6740 struct in_addr
*id
, struct in_addr
*adv_router
)
6742 memset(lp
, 0, sizeof(struct prefix_ls
));
6743 lp
->family
= AF_UNSPEC
;
6746 else if (adv_router
== NULL
) {
6747 lp
->prefixlen
= IPV4_MAX_BITLEN
;
6752 lp
->adv_router
= *adv_router
;
6756 static void show_lsa_detail_proc(struct vty
*vty
, struct route_table
*rt
,
6757 struct in_addr
*id
, struct in_addr
*adv_router
,
6760 struct prefix_ls lp
;
6761 struct route_node
*rn
, *start
;
6762 struct ospf_lsa
*lsa
;
6763 json_object
*json_lsa
= NULL
;
6765 show_lsa_prefix_set(vty
, &lp
, id
, adv_router
);
6766 start
= route_node_get(rt
, (struct prefix
*)&lp
);
6768 route_lock_node(start
);
6769 for (rn
= start
; rn
; rn
= route_next_until(rn
, start
))
6770 if ((lsa
= rn
->info
)) {
6771 if (show_function
[lsa
->data
->type
] != NULL
) {
6774 json_object_new_object();
6775 json_object_array_add(json
,
6779 show_function
[lsa
->data
->type
](
6780 vty
, lsa
, json_lsa
);
6783 route_unlock_node(start
);
6787 /* Show detail LSA information
6788 -- if id is NULL then show all LSAs. */
6789 static void show_lsa_detail(struct vty
*vty
, struct ospf
*ospf
, int type
,
6790 struct in_addr
*id
, struct in_addr
*adv_router
,
6793 struct listnode
*node
;
6794 struct ospf_area
*area
;
6795 char buf
[PREFIX_STRLEN
];
6796 json_object
*json_lsa_type
= NULL
;
6797 json_object
*json_areas
= NULL
;
6798 json_object
*json_lsa_array
= NULL
;
6801 case OSPF_AS_EXTERNAL_LSA
:
6802 case OSPF_OPAQUE_AS_LSA
:
6804 vty_out(vty
, " %s \n\n",
6805 show_database_desc
[type
]);
6807 json_lsa_array
= json_object_new_array();
6809 show_lsa_detail_proc(vty
, AS_LSDB(ospf
, type
), id
, adv_router
,
6812 json_object_object_add(json
,
6813 show_database_desc_json
[type
],
6819 json_areas
= json_object_new_object();
6821 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6824 "\n %s (Area %s)\n\n",
6825 show_database_desc
[type
],
6826 ospf_area_desc_string(area
));
6828 json_lsa_array
= json_object_new_array();
6829 json_object_object_add(json_areas
,
6837 show_lsa_detail_proc(vty
, AREA_LSDB(area
, type
), id
,
6838 adv_router
, json_lsa_array
);
6842 json_lsa_type
= json_object_new_object();
6843 json_object_object_add(json_lsa_type
, "areas",
6845 json_object_object_add(json
,
6846 show_database_desc_json
[type
],
6853 static void show_lsa_detail_adv_router_proc(struct vty
*vty
,
6854 struct route_table
*rt
,
6855 struct in_addr
*adv_router
,
6858 struct route_node
*rn
;
6859 struct ospf_lsa
*lsa
;
6860 json_object
*json_lsa
= NULL
;
6862 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
))
6863 if ((lsa
= rn
->info
)) {
6864 if (IPV4_ADDR_SAME(adv_router
,
6865 &lsa
->data
->adv_router
)) {
6866 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
6869 json_lsa
= json_object_new_object();
6870 json_object_array_add(json
, json_lsa
);
6873 if (show_function
[lsa
->data
->type
] != NULL
)
6874 show_function
[lsa
->data
->type
](
6875 vty
, lsa
, json_lsa
);
6880 /* Show detail LSA information. */
6881 static void show_lsa_detail_adv_router(struct vty
*vty
, struct ospf
*ospf
,
6882 int type
, struct in_addr
*adv_router
,
6885 struct listnode
*node
;
6886 struct ospf_area
*area
;
6887 char buf
[PREFIX_STRLEN
];
6888 json_object
*json_lsa_type
= NULL
;
6889 json_object
*json_areas
= NULL
;
6890 json_object
*json_lsa_array
= NULL
;
6893 json_lsa_type
= json_object_new_object();
6896 case OSPF_AS_EXTERNAL_LSA
:
6897 case OSPF_OPAQUE_AS_LSA
:
6899 vty_out(vty
, " %s \n\n",
6900 show_database_desc
[type
]);
6902 json_lsa_array
= json_object_new_array();
6904 show_lsa_detail_adv_router_proc(vty
, AS_LSDB(ospf
, type
),
6905 adv_router
, json_lsa_array
);
6907 json_object_object_add(json
,
6908 show_database_desc_json
[type
],
6913 json_areas
= json_object_new_object();
6915 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6918 "\n %s (Area %s)\n\n",
6919 show_database_desc
[type
],
6920 ospf_area_desc_string(area
));
6922 json_lsa_array
= json_object_new_array();
6923 json_object_object_add(
6925 inet_ntop(AF_INET
, &area
->area_id
, buf
,
6930 show_lsa_detail_adv_router_proc(
6931 vty
, AREA_LSDB(area
, type
), adv_router
,
6936 json_object_object_add(json_lsa_type
, "areas",
6938 json_object_object_add(json
,
6939 show_database_desc_json
[type
],
6946 void show_ip_ospf_database_summary(struct vty
*vty
, struct ospf
*ospf
, int self
,
6949 struct ospf_lsa
*lsa
;
6950 struct route_node
*rn
;
6951 struct ospf_area
*area
;
6952 struct listnode
*node
;
6953 char buf
[PREFIX_STRLEN
];
6954 json_object
*json_areas
= NULL
;
6955 json_object
*json_area
= NULL
;
6956 json_object
*json_lsa
= NULL
;
6958 json_object
*json_lsa_array
= NULL
;
6962 json_areas
= json_object_new_object();
6964 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6966 json_area
= json_object_new_object();
6968 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6971 case OSPF_AS_EXTERNAL_LSA
:
6972 case OSPF_OPAQUE_AS_LSA
:
6977 if (ospf_lsdb_count_self(area
->lsdb
, type
) > 0
6979 && ospf_lsdb_count(area
->lsdb
, type
) > 0)) {
6983 " %s (Area %s)\n\n",
6984 show_database_desc
[type
],
6985 ospf_area_desc_string(area
));
6986 vty_out(vty
, "%s\n",
6987 show_database_header
[type
]);
6990 json_object_new_array();
6991 json_object_object_add(
6993 show_database_desc_json
[type
],
6997 LSDB_LOOP (AREA_LSDB(area
, type
), rn
, lsa
) {
7000 json_object_new_object();
7001 json_object_array_add(
7006 count
+= show_lsa_summary(
7007 vty
, lsa
, self
, json_lsa
);
7013 json_object_int_add(
7016 show_database_desc_count_json
7022 json_object_object_add(json_areas
,
7030 json_object_object_add(json
, "areas", json_areas
);
7032 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
7035 case OSPF_AS_EXTERNAL_LSA
:
7036 case OSPF_OPAQUE_AS_LSA
:
7041 if (ospf_lsdb_count_self(ospf
->lsdb
, type
)
7042 || (!self
&& ospf_lsdb_count(ospf
->lsdb
, type
))) {
7044 vty_out(vty
, " %s\n\n",
7045 show_database_desc
[type
]);
7046 vty_out(vty
, "%s\n",
7047 show_database_header
[type
]);
7049 json_lsa_array
= json_object_new_array();
7050 json_object_object_add(
7051 json
, show_database_desc_json
[type
],
7055 LSDB_LOOP (AS_LSDB(ospf
, type
), rn
, lsa
) {
7057 json_lsa
= json_object_new_object();
7058 json_object_array_add(json_lsa_array
,
7062 count
+= show_lsa_summary(vty
, lsa
, self
,
7069 json_object_int_add(
7071 show_database_desc_count_json
[type
],
7080 static void show_ip_ospf_database_maxage(struct vty
*vty
, struct ospf
*ospf
,
7083 struct route_node
*rn
;
7084 char buf
[PREFIX_STRLEN
];
7085 json_object
*json_maxage
= NULL
;
7088 vty_out(vty
, "\n MaxAge Link States:\n\n");
7090 json_maxage
= json_object_new_object();
7092 for (rn
= route_top(ospf
->maxage_lsa
); rn
; rn
= route_next(rn
)) {
7093 struct ospf_lsa
*lsa
;
7094 json_object
*json_lsa
= NULL
;
7096 if ((lsa
= rn
->info
) != NULL
) {
7098 vty_out(vty
, "Link type: %d\n",
7100 vty_out(vty
, "Link State ID: %pI4\n",
7102 vty_out(vty
, "Advertising Router: %pI4\n",
7103 &lsa
->data
->adv_router
);
7104 vty_out(vty
, "LSA lock count: %d\n", lsa
->lock
);
7107 json_lsa
= json_object_new_object();
7108 json_object_int_add(json_lsa
, "linkType",
7110 json_object_string_addf(json_lsa
, "linkStateId",
7111 "%pI4", &lsa
->data
->id
);
7112 json_object_string_addf(
7113 json_lsa
, "advertisingRouter", "%pI4",
7114 &lsa
->data
->adv_router
);
7115 json_object_int_add(json_lsa
, "lsaLockCount",
7117 json_object_object_add(
7127 json_object_object_add(json
, "maxAgeLinkStates", json_maxage
);
7130 #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
7131 #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
7133 #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
7134 #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
7135 #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
7136 #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
7138 #define OSPF_LSA_TYPES_DESC \
7139 "ASBR summary link states\n" \
7140 "External link states\n" \
7141 "Network link states\n" \
7142 "Router link states\n" \
7143 "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \
7144 OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
7145 OSPF_LSA_TYPE_OPAQUE_AS_DESC
7148 show_ip_ospf_database_common(struct vty
*vty
, struct ospf
*ospf
, bool maxage
,
7149 bool self
, bool detail
, const char *type_name
,
7150 struct in_addr
*lsid
, struct in_addr
*adv_router
,
7151 bool use_vrf
, json_object
*json
, bool uj
)
7154 json_object
*json_vrf
= NULL
;
7158 json_vrf
= json_object_new_object();
7163 if (ospf
->instance
) {
7165 json_object_int_add(json_vrf
, "ospfInstance",
7168 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
7171 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
7173 /* Show Router ID. */
7175 json_object_string_addf(json_vrf
, "routerId", "%pI4",
7178 vty_out(vty
, "\n OSPF Router with ID (%pI4)\n\n",
7182 /* Show MaxAge LSAs */
7184 show_ip_ospf_database_maxage(vty
, ospf
, json_vrf
);
7187 if (ospf
->vrf_id
== VRF_DEFAULT
)
7188 json_object_object_add(json
, "default",
7191 json_object_object_add(json
, ospf
->name
,
7198 /* Show all LSAs. */
7201 for (int i
= OSPF_ROUTER_LSA
; i
<= OSPF_OPAQUE_AS_LSA
;
7204 case OSPF_GROUP_MEMBER_LSA
:
7205 case OSPF_EXTERNAL_ATTRIBUTES_LSA
:
7206 /* ignore deprecated LSA types */
7212 if (adv_router
&& !lsid
)
7213 show_lsa_detail_adv_router(vty
, ospf
, i
,
7217 show_lsa_detail(vty
, ospf
, i
, lsid
,
7218 adv_router
, json_vrf
);
7221 show_ip_ospf_database_summary(vty
, ospf
, self
,
7226 if (ospf
->vrf_id
== VRF_DEFAULT
)
7227 json_object_object_add(json
, "default",
7230 json_object_object_add(json
, ospf
->name
,
7237 /* Set database type to show. */
7238 if (strncmp(type_name
, "r", 1) == 0)
7239 type
= OSPF_ROUTER_LSA
;
7240 else if (strncmp(type_name
, "ne", 2) == 0)
7241 type
= OSPF_NETWORK_LSA
;
7242 else if (strncmp(type_name
, "ns", 2) == 0)
7243 type
= OSPF_AS_NSSA_LSA
;
7244 else if (strncmp(type_name
, "su", 2) == 0)
7245 type
= OSPF_SUMMARY_LSA
;
7246 else if (strncmp(type_name
, "a", 1) == 0)
7247 type
= OSPF_ASBR_SUMMARY_LSA
;
7248 else if (strncmp(type_name
, "e", 1) == 0)
7249 type
= OSPF_AS_EXTERNAL_LSA
;
7250 else if (strncmp(type_name
, "opaque-l", 8) == 0)
7251 type
= OSPF_OPAQUE_LINK_LSA
;
7252 else if (strncmp(type_name
, "opaque-ar", 9) == 0)
7253 type
= OSPF_OPAQUE_AREA_LSA
;
7254 else if (strncmp(type_name
, "opaque-as", 9) == 0)
7255 type
= OSPF_OPAQUE_AS_LSA
;
7259 json_object_free(json_vrf
);
7264 if (adv_router
&& !lsid
)
7265 show_lsa_detail_adv_router(vty
, ospf
, type
, adv_router
,
7268 show_lsa_detail(vty
, ospf
, type
, lsid
, adv_router
, json_vrf
);
7272 if (ospf
->vrf_id
== VRF_DEFAULT
)
7273 json_object_object_add(json
, "default",
7276 json_object_object_add(json
, ospf
->name
,
7284 DEFPY (show_ip_ospf_database
,
7285 show_ip_ospf_database_cmd
,
7286 "show ip ospf [(1-65535)$instance_id] [vrf <NAME|all>$vrf_name] database\
7289 |self-originate$selforig\
7292 |<asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as>$type_name\
7296 |<adv-router A.B.C.D$adv_router|self-originate$adv_router_self>\
7302 "OSPF information\n"
7306 "Database summary\n"
7307 "LSAs in MaxAge list\n"
7308 "Self-originated link states\n"
7309 "Show detailed information\n"
7311 "Link State ID (as an IP address)\n"
7312 "Advertising Router link states\n"
7313 "Advertising Router (as an IP address)\n"
7314 "Self-originated link states\n"
7318 int ret
= CMD_SUCCESS
;
7319 bool use_vrf
= !!vrf_name
;
7320 bool uj
= use_json(argc
, argv
);
7321 struct in_addr
*lsid_p
= NULL
;
7322 struct in_addr
*adv_router_p
= NULL
;
7323 json_object
*json
= NULL
;
7326 json
= json_object_new_object();
7330 adv_router_p
= &adv_router
;
7332 if (vrf_name
&& strmatch(vrf_name
, "all")) {
7333 struct listnode
*node
;
7334 bool ospf_output
= false;
7336 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
7337 if (!ospf
->oi_running
)
7339 if (ospf
->instance
!= instance_id
)
7342 if (adv_router_self
)
7343 adv_router_p
= &ospf
->router_id
;
7346 ret
= show_ip_ospf_database_common(
7347 vty
, ospf
, !!maxage
, !!selforig
, !!detail
,
7348 type_name
, lsid_p
, adv_router_p
, use_vrf
, json
,
7352 if (!ospf_output
&& !uj
)
7353 vty_out(vty
, "%% OSPF is not enabled\n");
7356 vrf_name
= VRF_DEFAULT_NAME
;
7357 ospf
= ospf_lookup_by_inst_name(instance_id
, vrf_name
);
7358 if (ospf
== NULL
|| !ospf
->oi_running
) {
7360 vty_json(vty
, json
);
7362 vty_out(vty
, "%% OSPF instance not found\n");
7365 if (adv_router_self
)
7366 adv_router_p
= &ospf
->router_id
;
7368 ret
= (show_ip_ospf_database_common(
7369 vty
, ospf
, !!maxage
, !!selforig
, !!detail
, type_name
,
7370 lsid_p
, adv_router_p
, use_vrf
, json
, uj
));
7374 vty_json(vty
, json
);
7379 DEFUN (ip_ospf_authentication_args
,
7380 ip_ospf_authentication_args_addr_cmd
,
7381 "ip ospf authentication <null|message-digest> [A.B.C.D]",
7383 "OSPF interface commands\n"
7384 "Enable authentication on this interface\n"
7385 "Use null authentication\n"
7386 "Use message-digest authentication\n"
7387 "Address of interface\n")
7389 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7390 int idx_encryption
= 3;
7392 struct in_addr addr
;
7394 struct ospf_if_params
*params
;
7396 params
= IF_DEF_PARAMS(ifp
);
7399 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7402 "Please specify interface address by A.B.C.D\n");
7403 return CMD_WARNING_CONFIG_FAILED
;
7406 params
= ospf_get_if_params(ifp
, addr
);
7407 ospf_if_update_params(ifp
, addr
);
7410 /* Handle null authentication */
7411 if (argv
[idx_encryption
]->arg
[0] == 'n') {
7412 SET_IF_PARAM(params
, auth_type
);
7413 params
->auth_type
= OSPF_AUTH_NULL
;
7417 /* Handle message-digest authentication */
7418 if (argv
[idx_encryption
]->arg
[0] == 'm') {
7419 SET_IF_PARAM(params
, auth_type
);
7420 params
->auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
7424 vty_out(vty
, "You shouldn't get here!\n");
7425 return CMD_WARNING_CONFIG_FAILED
;
7428 DEFUN (ip_ospf_authentication
,
7429 ip_ospf_authentication_addr_cmd
,
7430 "ip ospf authentication [A.B.C.D]",
7432 "OSPF interface commands\n"
7433 "Enable authentication on this interface\n"
7434 "Address of interface\n")
7436 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7438 struct in_addr addr
;
7440 struct ospf_if_params
*params
;
7442 params
= IF_DEF_PARAMS(ifp
);
7445 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7448 "Please specify interface address by A.B.C.D\n");
7449 return CMD_WARNING_CONFIG_FAILED
;
7452 params
= ospf_get_if_params(ifp
, addr
);
7453 ospf_if_update_params(ifp
, addr
);
7456 SET_IF_PARAM(params
, auth_type
);
7457 params
->auth_type
= OSPF_AUTH_SIMPLE
;
7462 DEFUN (no_ip_ospf_authentication_args
,
7463 no_ip_ospf_authentication_args_addr_cmd
,
7464 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
7467 "OSPF interface commands\n"
7468 "Enable authentication on this interface\n"
7469 "Use null authentication\n"
7470 "Use message-digest authentication\n"
7471 "Address of interface\n")
7473 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7474 int idx_encryption
= 4;
7476 struct in_addr addr
;
7478 struct ospf_if_params
*params
;
7479 struct route_node
*rn
;
7482 params
= IF_DEF_PARAMS(ifp
);
7485 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7488 "Please specify interface address by A.B.C.D\n");
7489 return CMD_WARNING_CONFIG_FAILED
;
7492 params
= ospf_lookup_if_params(ifp
, addr
);
7493 if (params
== NULL
) {
7494 vty_out(vty
, "Ip Address specified is unknown\n");
7495 return CMD_WARNING_CONFIG_FAILED
;
7497 params
->auth_type
= OSPF_AUTH_NOTSET
;
7498 UNSET_IF_PARAM(params
, auth_type
);
7499 if (params
!= IF_DEF_PARAMS(ifp
)) {
7500 ospf_free_if_params(ifp
, addr
);
7501 ospf_if_update_params(ifp
, addr
);
7504 if (argv
[idx_encryption
]->arg
[0] == 'n') {
7505 auth_type
= OSPF_AUTH_NULL
;
7506 } else if (argv
[idx_encryption
]->arg
[0] == 'm') {
7507 auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
7509 vty_out(vty
, "Unexpected input encountered\n");
7510 return CMD_WARNING_CONFIG_FAILED
;
7513 * Here we have a case where the user has entered
7514 * 'no ip ospf authentication (null | message_digest )'
7515 * we need to find if we have any ip addresses underneath it
7517 * correspond to the associated type.
7519 if (params
->auth_type
== auth_type
) {
7520 params
->auth_type
= OSPF_AUTH_NOTSET
;
7521 UNSET_IF_PARAM(params
, auth_type
);
7524 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
7525 rn
= route_next(rn
)) {
7526 if ((params
= rn
->info
)) {
7527 if (params
->auth_type
== auth_type
) {
7528 params
->auth_type
= OSPF_AUTH_NOTSET
;
7529 UNSET_IF_PARAM(params
, auth_type
);
7530 if (params
!= IF_DEF_PARAMS(ifp
)) {
7531 ospf_free_if_params(
7532 ifp
, rn
->p
.u
.prefix4
);
7533 ospf_if_update_params(
7534 ifp
, rn
->p
.u
.prefix4
);
7544 DEFUN (no_ip_ospf_authentication
,
7545 no_ip_ospf_authentication_addr_cmd
,
7546 "no ip ospf authentication [A.B.C.D]",
7549 "OSPF interface commands\n"
7550 "Enable authentication on this interface\n"
7551 "Address of interface\n")
7553 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7555 struct in_addr addr
;
7557 struct ospf_if_params
*params
;
7558 struct route_node
*rn
;
7560 params
= IF_DEF_PARAMS(ifp
);
7563 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7566 "Please specify interface address by A.B.C.D\n");
7567 return CMD_WARNING_CONFIG_FAILED
;
7570 params
= ospf_lookup_if_params(ifp
, addr
);
7571 if (params
== NULL
) {
7572 vty_out(vty
, "Ip Address specified is unknown\n");
7573 return CMD_WARNING_CONFIG_FAILED
;
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(ifp
, addr
);
7580 ospf_if_update_params(ifp
, addr
);
7584 * When a user enters 'no ip ospf authentication'
7585 * We should remove all authentication types from
7588 if ((params
->auth_type
== OSPF_AUTH_NULL
)
7589 || (params
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
7590 || (params
->auth_type
== OSPF_AUTH_SIMPLE
)) {
7591 params
->auth_type
= OSPF_AUTH_NOTSET
;
7592 UNSET_IF_PARAM(params
, auth_type
);
7595 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
7596 rn
= route_next(rn
)) {
7597 if ((params
= rn
->info
)) {
7599 if ((params
->auth_type
== OSPF_AUTH_NULL
)
7600 || (params
->auth_type
7601 == OSPF_AUTH_CRYPTOGRAPHIC
)
7602 || (params
->auth_type
7603 == OSPF_AUTH_SIMPLE
)) {
7604 params
->auth_type
= OSPF_AUTH_NOTSET
;
7605 UNSET_IF_PARAM(params
, auth_type
);
7606 if (params
!= IF_DEF_PARAMS(ifp
)) {
7607 ospf_free_if_params(
7608 ifp
, rn
->p
.u
.prefix4
);
7609 ospf_if_update_params(
7610 ifp
, rn
->p
.u
.prefix4
);
7621 DEFUN (ip_ospf_authentication_key
,
7622 ip_ospf_authentication_key_addr_cmd
,
7623 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
7625 "OSPF interface commands\n"
7626 "Authentication password (key)\n"
7627 "The OSPF password (key)\n"
7628 "Address of interface\n")
7630 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7632 struct in_addr addr
;
7633 struct ospf_if_params
*params
;
7635 params
= IF_DEF_PARAMS(ifp
);
7637 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7638 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7640 "Please specify interface address by A.B.C.D\n");
7641 return CMD_WARNING_CONFIG_FAILED
;
7644 params
= ospf_get_if_params(ifp
, addr
);
7645 ospf_if_update_params(ifp
, addr
);
7648 strlcpy((char *)params
->auth_simple
, argv
[3]->arg
,
7649 sizeof(params
->auth_simple
));
7650 SET_IF_PARAM(params
, auth_simple
);
7655 DEFUN_HIDDEN (ospf_authentication_key
,
7656 ospf_authentication_key_cmd
,
7657 "ospf authentication-key AUTH_KEY [A.B.C.D]",
7658 "OSPF interface commands\n"
7659 VLINK_HELPSTR_AUTH_SIMPLE
7660 "Address of interface\n")
7662 return ip_ospf_authentication_key(self
, vty
, argc
, argv
);
7665 DEFUN (no_ip_ospf_authentication_key
,
7666 no_ip_ospf_authentication_key_authkey_addr_cmd
,
7667 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7670 "OSPF interface commands\n"
7671 VLINK_HELPSTR_AUTH_SIMPLE
7672 "Address of interface\n")
7674 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7676 struct in_addr addr
;
7677 struct ospf_if_params
*params
;
7678 params
= IF_DEF_PARAMS(ifp
);
7680 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7681 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7683 "Please specify interface address by A.B.C.D\n");
7684 return CMD_WARNING_CONFIG_FAILED
;
7687 params
= ospf_lookup_if_params(ifp
, addr
);
7692 memset(params
->auth_simple
, 0, OSPF_AUTH_SIMPLE_SIZE
);
7693 UNSET_IF_PARAM(params
, auth_simple
);
7695 if (params
!= IF_DEF_PARAMS(ifp
)) {
7696 ospf_free_if_params(ifp
, addr
);
7697 ospf_if_update_params(ifp
, addr
);
7703 DEFUN_HIDDEN (no_ospf_authentication_key
,
7704 no_ospf_authentication_key_authkey_addr_cmd
,
7705 "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7707 "OSPF interface commands\n"
7708 VLINK_HELPSTR_AUTH_SIMPLE
7709 "Address of interface\n")
7711 return no_ip_ospf_authentication_key(self
, vty
, argc
, argv
);
7714 DEFUN (ip_ospf_message_digest_key
,
7715 ip_ospf_message_digest_key_cmd
,
7716 "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7718 "OSPF interface commands\n"
7719 "Message digest authentication password (key)\n"
7721 "Use MD5 algorithm\n"
7722 "The OSPF password (key)\n"
7723 "Address of interface\n")
7725 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7726 struct crypt_key
*ck
;
7728 struct in_addr addr
;
7729 struct ospf_if_params
*params
;
7731 params
= IF_DEF_PARAMS(ifp
);
7734 argv_find(argv
, argc
, "(1-255)", &idx
);
7735 char *keyid
= argv
[idx
]->arg
;
7736 argv_find(argv
, argc
, "KEY", &idx
);
7737 char *cryptkey
= argv
[idx
]->arg
;
7739 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7740 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7742 "Please specify interface address by A.B.C.D\n");
7743 return CMD_WARNING_CONFIG_FAILED
;
7746 params
= ospf_get_if_params(ifp
, addr
);
7747 ospf_if_update_params(ifp
, addr
);
7750 key_id
= strtol(keyid
, NULL
, 10);
7752 /* Remove existing key, if any */
7753 ospf_crypt_key_delete(params
->auth_crypt
, key_id
);
7755 ck
= ospf_crypt_key_new();
7756 ck
->key_id
= (uint8_t)key_id
;
7757 strlcpy((char *)ck
->auth_key
, cryptkey
, sizeof(ck
->auth_key
));
7759 ospf_crypt_key_add(params
->auth_crypt
, ck
);
7760 SET_IF_PARAM(params
, auth_crypt
);
7765 DEFUN_HIDDEN (ospf_message_digest_key
,
7766 ospf_message_digest_key_cmd
,
7767 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7768 "OSPF interface commands\n"
7769 "Message digest authentication password (key)\n"
7771 "Use MD5 algorithm\n"
7772 "The OSPF password (key)\n"
7773 "Address of interface\n")
7775 return ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7778 DEFUN (no_ip_ospf_message_digest_key
,
7779 no_ip_ospf_message_digest_key_cmd
,
7780 "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7783 "OSPF interface commands\n"
7784 "Message digest authentication password (key)\n"
7786 "Use MD5 algorithm\n"
7787 "The OSPF password (key)\n"
7788 "Address of interface\n")
7790 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7792 struct crypt_key
*ck
;
7794 struct in_addr addr
;
7795 struct ospf_if_params
*params
;
7796 params
= IF_DEF_PARAMS(ifp
);
7798 argv_find(argv
, argc
, "(1-255)", &idx
);
7799 char *keyid
= argv
[idx
]->arg
;
7801 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7802 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7804 "Please specify interface address by A.B.C.D\n");
7805 return CMD_WARNING_CONFIG_FAILED
;
7808 params
= ospf_lookup_if_params(ifp
, addr
);
7813 key_id
= strtol(keyid
, NULL
, 10);
7814 ck
= ospf_crypt_key_lookup(params
->auth_crypt
, key_id
);
7816 vty_out(vty
, "OSPF: Key %d does not exist\n", key_id
);
7817 return CMD_WARNING_CONFIG_FAILED
;
7820 ospf_crypt_key_delete(params
->auth_crypt
, key_id
);
7822 if (params
!= IF_DEF_PARAMS(ifp
)) {
7823 ospf_free_if_params(ifp
, addr
);
7824 ospf_if_update_params(ifp
, addr
);
7830 DEFUN_HIDDEN (no_ospf_message_digest_key
,
7831 no_ospf_message_digest_key_cmd
,
7832 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7834 "OSPF interface commands\n"
7835 "Message digest authentication password (key)\n"
7837 "Use MD5 algorithm\n"
7838 "The OSPF password (key)\n"
7839 "Address of interface\n")
7841 return no_ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7844 DEFUN (ip_ospf_cost
,
7846 "ip ospf cost (1-65535) [A.B.C.D]",
7848 "OSPF interface commands\n"
7851 "Address of interface\n")
7853 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7855 uint32_t cost
= OSPF_OUTPUT_COST_DEFAULT
;
7856 struct in_addr addr
;
7857 struct ospf_if_params
*params
;
7858 params
= IF_DEF_PARAMS(ifp
);
7861 char *coststr
= NULL
, *ifaddr
= NULL
;
7863 argv_find(argv
, argc
, "(1-65535)", &idx
);
7864 coststr
= argv
[idx
]->arg
;
7865 cost
= strtol(coststr
, NULL
, 10);
7867 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7869 if (!inet_aton(ifaddr
, &addr
)) {
7871 "Please specify interface address by A.B.C.D\n");
7872 return CMD_WARNING_CONFIG_FAILED
;
7875 params
= ospf_get_if_params(ifp
, addr
);
7876 ospf_if_update_params(ifp
, addr
);
7879 SET_IF_PARAM(params
, output_cost_cmd
);
7880 params
->output_cost_cmd
= cost
;
7882 ospf_if_recalculate_output_cost(ifp
);
7887 DEFUN_HIDDEN (ospf_cost
,
7889 "ospf cost (1-65535) [A.B.C.D]",
7890 "OSPF interface commands\n"
7893 "Address of interface\n")
7895 return ip_ospf_cost(self
, vty
, argc
, argv
);
7898 DEFUN (no_ip_ospf_cost
,
7899 no_ip_ospf_cost_cmd
,
7900 "no ip ospf cost [(1-65535)] [A.B.C.D]",
7903 "OSPF interface commands\n"
7906 "Address of interface\n")
7908 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7910 struct in_addr addr
;
7911 struct ospf_if_params
*params
;
7913 params
= IF_DEF_PARAMS(ifp
);
7916 char *ifaddr
= NULL
;
7917 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7919 /* According to the semantics we are mimicking "no ip ospf cost N" is
7920 * always treated as "no ip ospf cost" regardless of the actual value
7921 * of N already configured for the interface. Thus ignore cost. */
7924 if (!inet_aton(ifaddr
, &addr
)) {
7926 "Please specify interface address by A.B.C.D\n");
7927 return CMD_WARNING_CONFIG_FAILED
;
7930 params
= ospf_lookup_if_params(ifp
, addr
);
7935 UNSET_IF_PARAM(params
, output_cost_cmd
);
7937 if (params
!= IF_DEF_PARAMS(ifp
)) {
7938 ospf_free_if_params(ifp
, addr
);
7939 ospf_if_update_params(ifp
, addr
);
7942 ospf_if_recalculate_output_cost(ifp
);
7947 DEFUN_HIDDEN (no_ospf_cost
,
7949 "no ospf cost [(1-65535)] [A.B.C.D]",
7951 "OSPF interface commands\n"
7954 "Address of interface\n")
7956 return no_ip_ospf_cost(self
, vty
, argc
, argv
);
7959 static void ospf_nbr_timer_update(struct ospf_interface
*oi
)
7961 struct route_node
*rn
;
7962 struct ospf_neighbor
*nbr
;
7964 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
7970 nbr
->v_inactivity
= OSPF_IF_PARAM(oi
, v_wait
);
7971 nbr
->v_db_desc
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7972 nbr
->v_ls_req
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7973 nbr
->v_ls_upd
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7977 static int ospf_vty_dead_interval_set(struct vty
*vty
, const char *interval_str
,
7978 const char *nbr_str
,
7979 const char *fast_hello_str
)
7981 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7984 struct in_addr addr
;
7986 struct ospf_if_params
*params
;
7987 struct ospf_interface
*oi
;
7988 struct route_node
*rn
;
7990 params
= IF_DEF_PARAMS(ifp
);
7993 ret
= inet_aton(nbr_str
, &addr
);
7996 "Please specify interface address by A.B.C.D\n");
7997 return CMD_WARNING_CONFIG_FAILED
;
8000 params
= ospf_get_if_params(ifp
, addr
);
8001 ospf_if_update_params(ifp
, addr
);
8005 seconds
= strtoul(interval_str
, NULL
, 10);
8007 /* reset fast_hello too, just to be sure */
8008 UNSET_IF_PARAM(params
, fast_hello
);
8009 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
8010 } else if (fast_hello_str
) {
8011 hellomult
= strtoul(fast_hello_str
, NULL
, 10);
8012 /* 1s dead-interval with sub-second hellos desired */
8013 seconds
= OSPF_ROUTER_DEAD_INTERVAL_MINIMAL
;
8014 SET_IF_PARAM(params
, fast_hello
);
8015 params
->fast_hello
= hellomult
;
8018 "Please specify dead-interval or hello-multiplier\n");
8019 return CMD_WARNING_CONFIG_FAILED
;
8022 SET_IF_PARAM(params
, v_wait
);
8023 params
->v_wait
= seconds
;
8024 params
->is_v_wait_set
= true;
8026 /* Update timer values in neighbor structure. */
8028 struct ospf
*ospf
= NULL
;
8030 ospf
= ifp
->vrf
->info
;
8032 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
8034 ospf_nbr_timer_update(oi
);
8037 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
8038 if ((oi
= rn
->info
))
8039 ospf_nbr_timer_update(oi
);
8045 DEFUN (ip_ospf_dead_interval
,
8046 ip_ospf_dead_interval_cmd
,
8047 "ip ospf dead-interval (1-65535) [A.B.C.D]",
8049 "OSPF interface commands\n"
8050 "Interval time after which a neighbor is declared down\n"
8052 "Address of interface\n")
8055 char *interval
= argv_find(argv
, argc
, "(1-65535)", &idx
)
8059 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
8060 return ospf_vty_dead_interval_set(vty
, interval
, ifaddr
, NULL
);
8064 DEFUN_HIDDEN (ospf_dead_interval
,
8065 ospf_dead_interval_cmd
,
8066 "ospf dead-interval (1-65535) [A.B.C.D]",
8067 "OSPF interface commands\n"
8068 "Interval time after which a neighbor is declared down\n"
8070 "Address of interface\n")
8072 return ip_ospf_dead_interval(self
, vty
, argc
, argv
);
8075 DEFUN (ip_ospf_dead_interval_minimal
,
8076 ip_ospf_dead_interval_minimal_addr_cmd
,
8077 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
8079 "OSPF interface commands\n"
8080 "Interval time after which a neighbor is declared down\n"
8081 "Minimal 1s dead-interval with fast sub-second hellos\n"
8082 "Hello multiplier factor\n"
8083 "Number of Hellos to send each second\n"
8084 "Address of interface\n")
8089 return ospf_vty_dead_interval_set(
8090 vty
, NULL
, argv
[idx_ipv4
]->arg
, argv
[idx_number
]->arg
);
8092 return ospf_vty_dead_interval_set(vty
, NULL
, NULL
,
8093 argv
[idx_number
]->arg
);
8096 DEFUN (no_ip_ospf_dead_interval
,
8097 no_ip_ospf_dead_interval_cmd
,
8098 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8101 "OSPF interface commands\n"
8102 "Interval time after which a neighbor is declared down\n"
8104 "Minimal 1s dead-interval with fast sub-second hellos\n"
8105 "Hello multiplier factor\n"
8106 "Number of Hellos to send each second\n"
8107 "Address of interface\n")
8109 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8110 int idx_ipv4
= argc
- 1;
8111 struct in_addr addr
= {.s_addr
= 0L};
8113 struct ospf_if_params
*params
;
8114 struct ospf_interface
*oi
;
8115 struct route_node
*rn
;
8117 params
= IF_DEF_PARAMS(ifp
);
8119 if (argv
[idx_ipv4
]->type
== IPV4_TKN
) {
8120 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8123 "Please specify interface address by A.B.C.D\n");
8124 return CMD_WARNING_CONFIG_FAILED
;
8127 params
= ospf_lookup_if_params(ifp
, addr
);
8132 UNSET_IF_PARAM(params
, v_wait
);
8133 params
->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
8134 params
->is_v_wait_set
= false;
8136 UNSET_IF_PARAM(params
, fast_hello
);
8137 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
8139 if (params
!= IF_DEF_PARAMS(ifp
)) {
8140 ospf_free_if_params(ifp
, addr
);
8141 ospf_if_update_params(ifp
, addr
);
8144 /* Update timer values in neighbor structure. */
8146 struct ospf
*ospf
= NULL
;
8148 ospf
= ifp
->vrf
->info
;
8150 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
8152 ospf_nbr_timer_update(oi
);
8155 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
8156 if ((oi
= rn
->info
))
8157 ospf_nbr_timer_update(oi
);
8163 DEFUN_HIDDEN (no_ospf_dead_interval
,
8164 no_ospf_dead_interval_cmd
,
8165 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8167 "OSPF interface commands\n"
8168 "Interval time after which a neighbor is declared down\n"
8170 "Minimal 1s dead-interval with fast sub-second hellos\n"
8171 "Hello multiplier factor\n"
8172 "Number of Hellos to send each second\n"
8173 "Address of interface\n")
8175 return no_ip_ospf_dead_interval(self
, vty
, argc
, argv
);
8178 DEFUN (ip_ospf_hello_interval
,
8179 ip_ospf_hello_interval_cmd
,
8180 "ip ospf hello-interval (1-65535) [A.B.C.D]",
8182 "OSPF interface commands\n"
8183 "Time between HELLO packets\n"
8185 "Address of interface\n")
8187 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8189 struct in_addr addr
= {.s_addr
= 0L};
8190 struct ospf_if_params
*params
;
8191 params
= IF_DEF_PARAMS(ifp
);
8192 uint32_t seconds
= 0;
8193 bool is_addr
= false;
8194 uint32_t old_interval
= 0;
8196 argv_find(argv
, argc
, "(1-65535)", &idx
);
8197 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
8199 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8200 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8202 "Please specify interface address by A.B.C.D\n");
8203 return CMD_WARNING_CONFIG_FAILED
;
8206 params
= ospf_get_if_params(ifp
, addr
);
8207 ospf_if_update_params(ifp
, addr
);
8211 old_interval
= params
->v_hello
;
8213 /* Return, if same interval is configured. */
8214 if (old_interval
== seconds
)
8217 SET_IF_PARAM(params
, v_hello
);
8218 params
->v_hello
= seconds
;
8220 if (!params
->is_v_wait_set
) {
8221 SET_IF_PARAM(params
, v_wait
);
8223 * The router dead interval should
8224 * be some multiple of the HelloInterval (perhaps 4 times the
8225 * hello interval) and must be the same for all routers
8226 * attached to a common network.
8228 params
->v_wait
= 4 * seconds
;
8231 ospf_reset_hello_timer(ifp
, addr
, is_addr
);
8236 DEFUN_HIDDEN (ospf_hello_interval
,
8237 ospf_hello_interval_cmd
,
8238 "ospf hello-interval (1-65535) [A.B.C.D]",
8239 "OSPF interface commands\n"
8240 "Time between HELLO packets\n"
8242 "Address of interface\n")
8244 return ip_ospf_hello_interval(self
, vty
, argc
, argv
);
8247 DEFUN (no_ip_ospf_hello_interval
,
8248 no_ip_ospf_hello_interval_cmd
,
8249 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
8252 "OSPF interface commands\n"
8253 "Time between HELLO packets\n" // ignored
8255 "Address of interface\n")
8257 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8259 struct in_addr addr
= {.s_addr
= 0L};
8260 struct ospf_if_params
*params
;
8261 struct route_node
*rn
;
8263 params
= IF_DEF_PARAMS(ifp
);
8265 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8266 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8268 "Please specify interface address by A.B.C.D\n");
8269 return CMD_WARNING_CONFIG_FAILED
;
8272 params
= ospf_lookup_if_params(ifp
, addr
);
8277 UNSET_IF_PARAM(params
, v_hello
);
8278 params
->v_hello
= OSPF_HELLO_INTERVAL_DEFAULT
;
8280 if (!params
->is_v_wait_set
) {
8281 UNSET_IF_PARAM(params
, v_wait
);
8282 params
->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
8285 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8286 struct ospf_interface
*oi
= rn
->info
;
8291 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
8292 oi
->ptp_dmvpn
= IF_DEF_PARAMS(ifp
)->ptp_dmvpn
;
8294 if (oi
->state
> ISM_Down
) {
8295 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
8296 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
8300 if (params
!= IF_DEF_PARAMS(ifp
)) {
8301 ospf_free_if_params(ifp
, addr
);
8302 ospf_if_update_params(ifp
, addr
);
8308 DEFUN_HIDDEN (no_ospf_hello_interval
,
8309 no_ospf_hello_interval_cmd
,
8310 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
8312 "OSPF interface commands\n"
8313 "Time between HELLO packets\n" // ignored
8315 "Address of interface\n")
8317 return no_ip_ospf_hello_interval(self
, vty
, argc
, argv
);
8320 DEFUN(ip_ospf_network
, ip_ospf_network_cmd
,
8321 "ip ospf network <broadcast|"
8323 "point-to-multipoint [delay-reflood]|"
8324 "point-to-point [dmvpn]>",
8326 "OSPF interface commands\n"
8328 "Specify OSPF broadcast multi-access network\n"
8329 "Specify OSPF NBMA network\n"
8330 "Specify OSPF point-to-multipoint network\n"
8331 "Specify OSPF delayed reflooding of LSAs received on P2MP interface\n"
8332 "Specify OSPF point-to-point network\n"
8333 "Specify OSPF point-to-point DMVPN network\n")
8335 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8337 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
8338 uint8_t old_ptp_dmvpn
= IF_DEF_PARAMS(ifp
)->ptp_dmvpn
;
8339 uint8_t old_p2mp_delay_reflood
= IF_DEF_PARAMS(ifp
)->p2mp_delay_reflood
;
8340 struct route_node
*rn
;
8342 if (old_type
== OSPF_IFTYPE_LOOPBACK
) {
8344 "This is a loopback interface. Can't set network type.\n");
8345 return CMD_WARNING_CONFIG_FAILED
;
8348 IF_DEF_PARAMS(ifp
)->ptp_dmvpn
= 0;
8349 IF_DEF_PARAMS(ifp
)->p2mp_delay_reflood
=
8350 OSPF_P2MP_DELAY_REFLOOD_DEFAULT
;
8352 if (argv_find(argv
, argc
, "broadcast", &idx
))
8353 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_BROADCAST
;
8354 else if (argv_find(argv
, argc
, "non-broadcast", &idx
))
8355 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_NBMA
;
8356 else if (argv_find(argv
, argc
, "point-to-multipoint", &idx
)) {
8357 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOMULTIPOINT
;
8358 if (argv_find(argv
, argc
, "delay-reflood", &idx
))
8359 IF_DEF_PARAMS(ifp
)->p2mp_delay_reflood
= true;
8360 } else if (argv_find(argv
, argc
, "point-to-point", &idx
)) {
8361 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOPOINT
;
8362 if (argv_find(argv
, argc
, "dmvpn", &idx
))
8363 IF_DEF_PARAMS(ifp
)->ptp_dmvpn
= 1;
8366 if (IF_DEF_PARAMS(ifp
)->type
== old_type
&&
8367 IF_DEF_PARAMS(ifp
)->ptp_dmvpn
== old_ptp_dmvpn
&&
8368 IF_DEF_PARAMS(ifp
)->p2mp_delay_reflood
== old_p2mp_delay_reflood
)
8371 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), type
);
8373 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8374 struct ospf_interface
*oi
= rn
->info
;
8379 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
8380 oi
->ptp_dmvpn
= IF_DEF_PARAMS(ifp
)->ptp_dmvpn
;
8381 oi
->p2mp_delay_reflood
= IF_DEF_PARAMS(ifp
)->p2mp_delay_reflood
;
8384 * The OSPF interface only needs to be flapped if the network
8385 * type or DMVPN parameter changes.
8387 if (IF_DEF_PARAMS(ifp
)->type
!= old_type
||
8388 IF_DEF_PARAMS(ifp
)->ptp_dmvpn
!= old_ptp_dmvpn
) {
8389 if (oi
->state
> ISM_Down
) {
8390 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
8391 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
8399 DEFUN_HIDDEN (ospf_network
,
8401 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
8402 "OSPF interface commands\n"
8404 "Specify OSPF broadcast multi-access network\n"
8405 "Specify OSPF NBMA network\n"
8406 "Specify OSPF point-to-multipoint network\n"
8407 "Specify OSPF point-to-point network\n")
8409 return ip_ospf_network(self
, vty
, argc
, argv
);
8412 DEFUN (no_ip_ospf_network
,
8413 no_ip_ospf_network_cmd
,
8414 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8417 "OSPF interface commands\n"
8419 "Specify OSPF broadcast multi-access network\n"
8420 "Specify OSPF NBMA network\n"
8421 "Specify OSPF point-to-multipoint network\n"
8422 "Specify OSPF point-to-point network\n")
8424 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8425 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
8426 struct route_node
*rn
;
8428 IF_DEF_PARAMS(ifp
)->type
= ospf_default_iftype(ifp
);
8429 IF_DEF_PARAMS(ifp
)->ptp_dmvpn
= 0;
8430 IF_DEF_PARAMS(ifp
)->p2mp_delay_reflood
=
8431 OSPF_P2MP_DELAY_REFLOOD_DEFAULT
;
8433 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
8436 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8437 struct ospf_interface
*oi
= rn
->info
;
8442 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
8443 oi
->ptp_dmvpn
= IF_DEF_PARAMS(ifp
)->ptp_dmvpn
;
8444 oi
->p2mp_delay_reflood
= IF_DEF_PARAMS(ifp
)->p2mp_delay_reflood
;
8446 if (oi
->state
> ISM_Down
) {
8447 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
8448 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
8455 DEFUN_HIDDEN (no_ospf_network
,
8456 no_ospf_network_cmd
,
8457 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8459 "OSPF interface commands\n"
8461 "Specify OSPF broadcast multi-access network\n"
8462 "Specify OSPF NBMA network\n"
8463 "Specify OSPF point-to-multipoint network\n"
8464 "Specify OSPF point-to-point network\n")
8466 return no_ip_ospf_network(self
, vty
, argc
, argv
);
8469 DEFUN (ip_ospf_priority
,
8470 ip_ospf_priority_cmd
,
8471 "ip ospf priority (0-255) [A.B.C.D]",
8473 "OSPF interface commands\n"
8476 "Address of interface\n")
8478 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8481 struct route_node
*rn
;
8482 struct in_addr addr
;
8483 struct ospf_if_params
*params
;
8484 params
= IF_DEF_PARAMS(ifp
);
8486 argv_find(argv
, argc
, "(0-255)", &idx
);
8487 priority
= strtol(argv
[idx
]->arg
, NULL
, 10);
8489 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8490 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8492 "Please specify interface address by A.B.C.D\n");
8493 return CMD_WARNING_CONFIG_FAILED
;
8496 params
= ospf_get_if_params(ifp
, addr
);
8497 ospf_if_update_params(ifp
, addr
);
8500 SET_IF_PARAM(params
, priority
);
8501 params
->priority
= priority
;
8503 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8504 struct ospf_interface
*oi
= rn
->info
;
8509 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
8510 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
8511 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
8518 DEFUN_HIDDEN (ospf_priority
,
8520 "ospf priority (0-255) [A.B.C.D]",
8521 "OSPF interface commands\n"
8524 "Address of interface\n")
8526 return ip_ospf_priority(self
, vty
, argc
, argv
);
8529 DEFUN (no_ip_ospf_priority
,
8530 no_ip_ospf_priority_cmd
,
8531 "no ip ospf priority [(0-255) [A.B.C.D]]",
8534 "OSPF interface commands\n"
8535 "Router priority\n" // ignored
8537 "Address of interface\n")
8539 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8541 struct route_node
*rn
;
8542 struct in_addr addr
;
8543 struct ospf_if_params
*params
;
8545 params
= IF_DEF_PARAMS(ifp
);
8547 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8548 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8550 "Please specify interface address by A.B.C.D\n");
8551 return CMD_WARNING_CONFIG_FAILED
;
8554 params
= ospf_lookup_if_params(ifp
, addr
);
8559 UNSET_IF_PARAM(params
, priority
);
8560 params
->priority
= OSPF_ROUTER_PRIORITY_DEFAULT
;
8562 if (params
!= IF_DEF_PARAMS(ifp
)) {
8563 ospf_free_if_params(ifp
, addr
);
8564 ospf_if_update_params(ifp
, addr
);
8567 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8568 struct ospf_interface
*oi
= rn
->info
;
8573 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
8574 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
8575 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
8582 DEFUN_HIDDEN (no_ospf_priority
,
8583 no_ospf_priority_cmd
,
8584 "no ospf priority [(0-255) [A.B.C.D]]",
8586 "OSPF interface commands\n"
8589 "Address of interface\n")
8591 return no_ip_ospf_priority(self
, vty
, argc
, argv
);
8594 DEFUN (ip_ospf_retransmit_interval
,
8595 ip_ospf_retransmit_interval_addr_cmd
,
8596 "ip ospf retransmit-interval (1-65535) [A.B.C.D]",
8598 "OSPF interface commands\n"
8599 "Time between retransmitting lost link state advertisements\n"
8601 "Address of interface\n")
8603 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8606 struct in_addr addr
;
8607 struct ospf_if_params
*params
;
8608 params
= IF_DEF_PARAMS(ifp
);
8610 argv_find(argv
, argc
, "(1-65535)", &idx
);
8611 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
8613 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8614 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8616 "Please specify interface address by A.B.C.D\n");
8617 return CMD_WARNING_CONFIG_FAILED
;
8620 params
= ospf_get_if_params(ifp
, addr
);
8621 ospf_if_update_params(ifp
, addr
);
8624 SET_IF_PARAM(params
, retransmit_interval
);
8625 params
->retransmit_interval
= seconds
;
8630 DEFUN_HIDDEN (ospf_retransmit_interval
,
8631 ospf_retransmit_interval_cmd
,
8632 "ospf retransmit-interval (1-65535) [A.B.C.D]",
8633 "OSPF interface commands\n"
8634 "Time between retransmitting lost link state advertisements\n"
8636 "Address of interface\n")
8638 return ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
8641 DEFUN (no_ip_ospf_retransmit_interval
,
8642 no_ip_ospf_retransmit_interval_addr_cmd
,
8643 "no ip ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8646 "OSPF interface commands\n"
8647 "Time between retransmitting lost link state advertisements\n"
8649 "Address of interface\n")
8651 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8653 struct in_addr addr
;
8654 struct ospf_if_params
*params
;
8656 params
= IF_DEF_PARAMS(ifp
);
8658 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8659 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8661 "Please specify interface address by A.B.C.D\n");
8662 return CMD_WARNING_CONFIG_FAILED
;
8665 params
= ospf_lookup_if_params(ifp
, addr
);
8670 UNSET_IF_PARAM(params
, retransmit_interval
);
8671 params
->retransmit_interval
= OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
8673 if (params
!= IF_DEF_PARAMS(ifp
)) {
8674 ospf_free_if_params(ifp
, addr
);
8675 ospf_if_update_params(ifp
, addr
);
8681 DEFUN_HIDDEN (no_ospf_retransmit_interval
,
8682 no_ospf_retransmit_interval_cmd
,
8683 "no ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8685 "OSPF interface commands\n"
8686 "Time between retransmitting lost link state advertisements\n"
8688 "Address of interface\n")
8690 return no_ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
8693 DEFPY (ip_ospf_gr_hdelay
,
8694 ip_ospf_gr_hdelay_cmd
,
8695 "ip ospf graceful-restart hello-delay (1-1800)",
8697 "OSPF interface commands\n"
8698 "Graceful Restart parameters\n"
8699 "Delay the sending of the first hello packets.\n"
8700 "Delay in seconds\n")
8702 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8703 struct ospf_if_params
*params
;
8705 params
= IF_DEF_PARAMS(ifp
);
8707 /* Note: new or updated value won't affect ongoing graceful restart. */
8708 SET_IF_PARAM(params
, v_gr_hello_delay
);
8709 params
->v_gr_hello_delay
= hello_delay
;
8714 DEFPY (no_ip_ospf_gr_hdelay
,
8715 no_ip_ospf_gr_hdelay_cmd
,
8716 "no ip ospf graceful-restart hello-delay [(1-1800)]",
8719 "OSPF interface commands\n"
8720 "Graceful Restart parameters\n"
8721 "Delay the sending of the first hello packets.\n"
8722 "Delay in seconds\n")
8724 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8725 struct ospf_if_params
*params
;
8726 struct route_node
*rn
;
8728 params
= IF_DEF_PARAMS(ifp
);
8729 UNSET_IF_PARAM(params
, v_gr_hello_delay
);
8730 params
->v_gr_hello_delay
= OSPF_HELLO_DELAY_DEFAULT
;
8732 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8733 struct ospf_interface
*oi
;
8739 oi
->gr
.hello_delay
.elapsed_seconds
= 0;
8740 EVENT_OFF(oi
->gr
.hello_delay
.t_grace_send
);
8746 DEFUN (ip_ospf_transmit_delay
,
8747 ip_ospf_transmit_delay_addr_cmd
,
8748 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
8750 "OSPF interface commands\n"
8751 "Link state transmit delay\n"
8753 "Address of interface\n")
8755 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8758 struct in_addr addr
;
8759 struct ospf_if_params
*params
;
8761 params
= IF_DEF_PARAMS(ifp
);
8762 argv_find(argv
, argc
, "(1-65535)", &idx
);
8763 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
8765 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8766 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8768 "Please specify interface address by A.B.C.D\n");
8769 return CMD_WARNING_CONFIG_FAILED
;
8772 params
= ospf_get_if_params(ifp
, addr
);
8773 ospf_if_update_params(ifp
, addr
);
8776 SET_IF_PARAM(params
, transmit_delay
);
8777 params
->transmit_delay
= seconds
;
8782 DEFUN_HIDDEN (ospf_transmit_delay
,
8783 ospf_transmit_delay_cmd
,
8784 "ospf transmit-delay (1-65535) [A.B.C.D]",
8785 "OSPF interface commands\n"
8786 "Link state transmit delay\n"
8788 "Address of interface\n")
8790 return ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
8793 DEFUN (no_ip_ospf_transmit_delay
,
8794 no_ip_ospf_transmit_delay_addr_cmd
,
8795 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
8798 "OSPF interface commands\n"
8799 "Link state transmit delay\n"
8801 "Address of interface\n")
8803 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8805 struct in_addr addr
;
8806 struct ospf_if_params
*params
;
8808 params
= IF_DEF_PARAMS(ifp
);
8810 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8811 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8813 "Please specify interface address by A.B.C.D\n");
8814 return CMD_WARNING_CONFIG_FAILED
;
8817 params
= ospf_lookup_if_params(ifp
, addr
);
8822 UNSET_IF_PARAM(params
, transmit_delay
);
8823 params
->transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
8825 if (params
!= IF_DEF_PARAMS(ifp
)) {
8826 ospf_free_if_params(ifp
, addr
);
8827 ospf_if_update_params(ifp
, addr
);
8834 DEFUN_HIDDEN (no_ospf_transmit_delay
,
8835 no_ospf_transmit_delay_cmd
,
8836 "no ospf transmit-delay [(1-65535) [A.B.C.D]]",
8838 "OSPF interface commands\n"
8839 "Link state transmit delay\n"
8841 "Address of interface\n")
8843 return no_ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
8846 DEFUN (ip_ospf_area
,
8848 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]",
8850 "OSPF interface commands\n"
8852 "Enable OSPF on this interface\n"
8853 "OSPF area ID in IP address format\n"
8854 "OSPF area ID as a decimal value\n"
8855 "Address of interface\n")
8857 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8860 struct in_addr area_id
;
8861 struct in_addr addr
;
8862 struct ospf_if_params
*params
= NULL
;
8863 struct route_node
*rn
;
8864 struct ospf
*ospf
= NULL
;
8865 unsigned short instance
= 0;
8869 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
8870 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
8872 argv_find(argv
, argc
, "area", &idx
);
8873 areaid
= argv
[idx
+ 1]->arg
;
8876 ospf
= ifp
->vrf
->info
;
8878 ospf
= ospf_lookup_instance(instance
);
8880 if (instance
&& instance
!= ospf_instance
) {
8882 * At this point we know we have received
8883 * an instance and there is no ospf instance
8884 * associated with it. This means we are
8885 * in a situation where we have an
8886 * ospf command that is setup for a different
8887 * process(instance). We need to safely
8888 * remove the command from ourselves and
8889 * allow the other instance(process) handle
8890 * the configuration command.
8894 params
= IF_DEF_PARAMS(ifp
);
8895 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8896 UNSET_IF_PARAM(params
, if_area
);
8900 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
; rn
= route_next(rn
))
8901 if ((params
= rn
->info
) && OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8902 UNSET_IF_PARAM(params
, if_area
);
8907 ospf
= ifp
->vrf
->info
;
8909 ospf_interface_area_unset(ospf
, ifp
);
8912 return CMD_NOT_MY_INSTANCE
;
8915 ret
= str2area_id(areaid
, &area_id
, &format
);
8917 vty_out(vty
, "Please specify area by A.B.C.D|<0-4294967295>\n");
8918 return CMD_WARNING_CONFIG_FAILED
;
8920 if (memcmp(ifp
->name
, "VLINK", 5) == 0) {
8921 vty_out(vty
, "Cannot enable OSPF on a virtual link.\n");
8922 return CMD_WARNING_CONFIG_FAILED
;
8926 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
)) {
8927 if (rn
->info
!= NULL
) {
8929 "Please remove all network commands first.\n");
8930 return CMD_WARNING_CONFIG_FAILED
;
8935 params
= IF_DEF_PARAMS(ifp
);
8936 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)
8937 && !IPV4_ADDR_SAME(¶ms
->if_area
, &area_id
)) {
8939 "Must remove previous area config before changing ospf area \n");
8940 return CMD_WARNING_CONFIG_FAILED
;
8943 // Check if we have an address arg and proccess it
8944 if (argc
== idx
+ 3) {
8945 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
8947 "Please specify Intf Address by A.B.C.D\n");
8948 return CMD_WARNING_CONFIG_FAILED
;
8950 // update/create address-level params
8951 params
= ospf_get_if_params((ifp
), (addr
));
8952 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8953 if (!IPV4_ADDR_SAME(¶ms
->if_area
, &area_id
)) {
8955 "Must remove previous area/address config before changing ospf area\n");
8956 return CMD_WARNING_CONFIG_FAILED
;
8960 ospf_if_update_params((ifp
), (addr
));
8963 /* enable ospf on this interface with area_id */
8965 SET_IF_PARAM(params
, if_area
);
8966 params
->if_area
= area_id
;
8967 params
->if_area_id_fmt
= format
;
8971 ospf_interface_area_set(ospf
, ifp
);
8976 DEFUN (no_ip_ospf_area
,
8977 no_ip_ospf_area_cmd
,
8978 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]",
8981 "OSPF interface commands\n"
8983 "Disable OSPF on this interface\n"
8984 "OSPF area ID in IP address format\n"
8985 "OSPF area ID as a decimal value\n"
8986 "Address of interface\n")
8988 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8991 struct ospf_if_params
*params
;
8992 unsigned short instance
= 0;
8993 struct in_addr addr
;
8994 struct in_addr area_id
;
8996 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
8997 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
9000 ospf
= ifp
->vrf
->info
;
9002 ospf
= ospf_lookup_instance(instance
);
9004 if (instance
&& instance
!= ospf_instance
)
9005 return CMD_NOT_MY_INSTANCE
;
9007 argv_find(argv
, argc
, "area", &idx
);
9009 // Check if we have an address arg and proccess it
9010 if (argc
== idx
+ 3) {
9011 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
9013 "Please specify Intf Address by A.B.C.D\n");
9014 return CMD_WARNING_CONFIG_FAILED
;
9016 params
= ospf_lookup_if_params(ifp
, addr
);
9017 if ((params
) == NULL
)
9020 params
= IF_DEF_PARAMS(ifp
);
9022 area_id
= params
->if_area
;
9023 if (!OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
9025 "Can't find specified interface area configuration.\n");
9026 return CMD_WARNING_CONFIG_FAILED
;
9029 UNSET_IF_PARAM(params
, if_area
);
9030 if (params
!= IF_DEF_PARAMS((ifp
))) {
9031 ospf_free_if_params((ifp
), (addr
));
9032 ospf_if_update_params((ifp
), (addr
));
9036 ospf_interface_area_unset(ospf
, ifp
);
9037 ospf_area_check_free(ospf
, area_id
);
9043 DEFUN (ip_ospf_passive
,
9044 ip_ospf_passive_cmd
,
9045 "ip ospf passive [A.B.C.D]",
9047 "OSPF interface commands\n"
9048 "Suppress routing updates on an interface\n"
9049 "Address of interface\n")
9051 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9053 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
9054 struct ospf_if_params
*params
;
9058 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9061 "Please specify interface address by A.B.C.D\n");
9062 return CMD_WARNING_CONFIG_FAILED
;
9064 params
= ospf_get_if_params(ifp
, addr
);
9065 ospf_if_update_params(ifp
, addr
);
9067 params
= IF_DEF_PARAMS(ifp
);
9070 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_PASSIVE
);
9075 DEFUN (no_ip_ospf_passive
,
9076 no_ip_ospf_passive_cmd
,
9077 "no ip ospf passive [A.B.C.D]",
9080 "OSPF interface commands\n"
9081 "Enable routing updates on an interface\n"
9082 "Address of interface\n")
9084 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9086 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
9087 struct ospf_if_params
*params
;
9091 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9094 "Please specify interface address by A.B.C.D\n");
9095 return CMD_WARNING_CONFIG_FAILED
;
9097 params
= ospf_lookup_if_params(ifp
, addr
);
9101 params
= IF_DEF_PARAMS(ifp
);
9104 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_ACTIVE
);
9109 DEFUN (ospf_redistribute_source
,
9110 ospf_redistribute_source_cmd
,
9111 "redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9113 FRR_REDIST_HELP_STR_OSPFD
9114 "Metric for redistributed routes\n"
9115 "OSPF default metric\n"
9116 "OSPF exterior metric type for redistributed routes\n"
9117 "Set OSPF External Type 1/2 metrics\n"
9118 "Route map reference\n"
9119 "Pointer to route-map entries\n")
9121 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9122 int idx_protocol
= 1;
9126 struct ospf_redist
*red
;
9128 bool update
= false;
9130 /* Get distribute source. */
9131 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
9133 return CMD_WARNING_CONFIG_FAILED
;
9135 /* Get metric value. */
9136 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
9137 if (!str2metric(argv
[idx
]->arg
, &metric
))
9138 return CMD_WARNING_CONFIG_FAILED
;
9141 /* Get metric type. */
9142 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
9143 if (!str2metric_type(argv
[idx
]->arg
, &type
))
9144 return CMD_WARNING_CONFIG_FAILED
;
9148 red
= ospf_redist_lookup(ospf
, source
, 0);
9150 red
= ospf_redist_add(ospf
, source
, 0);
9155 if (argv_find(argv
, argc
, "route-map", &idx
)) {
9156 ospf_routemap_set(red
, argv
[idx
+ 1]->arg
);
9158 ospf_routemap_unset(red
);
9161 return ospf_redistribute_update(ospf
, red
, source
, 0, type
,
9164 return ospf_redistribute_set(ospf
, red
, source
, 0, type
,
9168 DEFUN (no_ospf_redistribute_source
,
9169 no_ospf_redistribute_source_cmd
,
9170 "no redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9173 FRR_REDIST_HELP_STR_OSPFD
9174 "Metric for redistributed routes\n"
9175 "OSPF default metric\n"
9176 "OSPF exterior metric type for redistributed routes\n"
9177 "Set OSPF External Type 1/2 metrics\n"
9178 "Route map reference\n"
9179 "Pointer to route-map entries\n")
9181 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9182 int idx_protocol
= 2;
9184 struct ospf_redist
*red
;
9186 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
9188 return CMD_WARNING_CONFIG_FAILED
;
9190 red
= ospf_redist_lookup(ospf
, source
, 0);
9194 ospf_routemap_unset(red
);
9195 ospf_redist_del(ospf
, source
, 0);
9197 return ospf_redistribute_unset(ospf
, source
, 0);
9200 DEFUN (ospf_redistribute_instance_source
,
9201 ospf_redistribute_instance_source_cmd
,
9202 "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9204 "Open Shortest Path First\n"
9205 "Non-main Kernel Routing Table\n"
9206 "Instance ID/Table ID\n"
9207 "Metric for redistributed routes\n"
9208 "OSPF default metric\n"
9209 "OSPF exterior metric type for redistributed routes\n"
9210 "Set OSPF External Type 1/2 metrics\n"
9211 "Route map reference\n"
9212 "Pointer to route-map entries\n")
9214 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9215 int idx_ospf_table
= 1;
9221 unsigned short instance
;
9222 struct ospf_redist
*red
;
9223 bool update
= false;
9225 source
= proto_redistnum(AFI_IP
, argv
[idx_ospf_table
]->text
);
9228 vty_out(vty
, "Unknown instance redistribution\n");
9229 return CMD_WARNING_CONFIG_FAILED
;
9232 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9234 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
9236 "Instance redistribution in non-instanced OSPF not allowed\n");
9237 return CMD_WARNING_CONFIG_FAILED
;
9240 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
9241 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
9242 return CMD_WARNING_CONFIG_FAILED
;
9245 /* Get metric value. */
9246 if (argv_find(argv
, argc
, "metric", &idx
))
9247 if (!str2metric(argv
[idx
+ 1]->arg
, &metric
))
9248 return CMD_WARNING_CONFIG_FAILED
;
9251 /* Get metric type. */
9252 if (argv_find(argv
, argc
, "metric-type", &idx
))
9253 if (!str2metric_type(argv
[idx
+ 1]->arg
, &type
))
9254 return CMD_WARNING_CONFIG_FAILED
;
9256 red
= ospf_redist_lookup(ospf
, source
, instance
);
9258 red
= ospf_redist_add(ospf
, source
, instance
);
9263 if (argv_find(argv
, argc
, "route-map", &idx
))
9264 ospf_routemap_set(red
, argv
[idx
+ 1]->arg
);
9266 ospf_routemap_unset(red
);
9269 return ospf_redistribute_update(ospf
, red
, source
, instance
,
9272 return ospf_redistribute_set(ospf
, red
, source
, instance
, type
,
9276 DEFUN (no_ospf_redistribute_instance_source
,
9277 no_ospf_redistribute_instance_source_cmd
,
9278 "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9281 "Open Shortest Path First\n"
9282 "Non-main Kernel Routing Table\n"
9283 "Instance ID/Table Id\n"
9284 "Metric for redistributed routes\n"
9285 "OSPF default metric\n"
9286 "OSPF exterior metric type for redistributed routes\n"
9287 "Set OSPF External Type 1/2 metrics\n"
9288 "Route map reference\n"
9289 "Pointer to route-map entries\n")
9291 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9292 int idx_ospf_table
= 2;
9294 unsigned int instance
;
9295 struct ospf_redist
*red
;
9298 if (strncmp(argv
[idx_ospf_table
]->arg
, "o", 1) == 0)
9299 source
= ZEBRA_ROUTE_OSPF
;
9301 source
= ZEBRA_ROUTE_TABLE
;
9303 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9305 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
9307 "Instance redistribution in non-instanced OSPF not allowed\n");
9308 return CMD_WARNING_CONFIG_FAILED
;
9311 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
9312 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
9313 return CMD_WARNING_CONFIG_FAILED
;
9316 red
= ospf_redist_lookup(ospf
, source
, instance
);
9320 ospf_routemap_unset(red
);
9321 ospf_redist_del(ospf
, source
, instance
);
9323 return ospf_redistribute_unset(ospf
, source
, instance
);
9326 DEFUN (ospf_distribute_list_out
,
9327 ospf_distribute_list_out_cmd
,
9328 "distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD
,
9329 "Filter networks in routing updates\n"
9330 "Access-list name\n"
9332 FRR_REDIST_HELP_STR_OSPFD
)
9334 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9338 char *proto
= argv
[argc
- 1]->text
;
9340 /* Get distribute source. */
9341 source
= proto_redistnum(AFI_IP
, proto
);
9343 return CMD_WARNING_CONFIG_FAILED
;
9345 return ospf_distribute_list_out_set(ospf
, source
, argv
[idx_word
]->arg
);
9348 DEFUN (no_ospf_distribute_list_out
,
9349 no_ospf_distribute_list_out_cmd
,
9350 "no distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD
,
9352 "Filter networks in routing updates\n"
9353 "Access-list name\n"
9355 FRR_REDIST_HELP_STR_OSPFD
)
9357 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9361 char *proto
= argv
[argc
- 1]->text
;
9362 source
= proto_redistnum(AFI_IP
, proto
);
9364 return CMD_WARNING_CONFIG_FAILED
;
9366 return ospf_distribute_list_out_unset(ospf
, source
,
9367 argv
[idx_word
]->arg
);
9370 /* Default information originate. */
9371 DEFUN (ospf_default_information_originate
,
9372 ospf_default_information_originate_cmd
,
9373 "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9374 "Control distribution of default information\n"
9375 "Distribute a default route\n"
9376 "Always advertise default route\n"
9377 "OSPF default metric\n"
9379 "OSPF metric type for default routes\n"
9380 "Set OSPF External Type 1/2 metrics\n"
9381 "Route map reference\n"
9382 "Pointer to route-map entries\n")
9384 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9385 int default_originate
= DEFAULT_ORIGINATE_ZEBRA
;
9388 struct ospf_redist
*red
;
9390 int cur_originate
= ospf
->default_originate
;
9391 bool sameRtmap
= false;
9394 red
= ospf_redist_add(ospf
, DEFAULT_ROUTE
, 0);
9396 /* Check whether "always" was specified */
9397 if (argv_find(argv
, argc
, "always", &idx
))
9398 default_originate
= DEFAULT_ORIGINATE_ALWAYS
;
9400 /* Get metric value */
9401 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
9402 if (!str2metric(argv
[idx
]->arg
, &metric
))
9403 return CMD_WARNING_CONFIG_FAILED
;
9406 /* Get metric type. */
9407 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
9408 if (!str2metric_type(argv
[idx
]->arg
, &type
))
9409 return CMD_WARNING_CONFIG_FAILED
;
9413 if (argv_find(argv
, argc
, "route-map", &idx
))
9414 rtmap
= argv
[idx
+ 1]->arg
;
9416 /* To check if user is providing same route map */
9417 if ((!rtmap
&& !ROUTEMAP_NAME(red
)) ||
9418 (rtmap
&& ROUTEMAP_NAME(red
) &&
9419 (strcmp(rtmap
, ROUTEMAP_NAME(red
)) == 0)))
9422 /* Don't allow if the same lsa is already originated. */
9424 && (red
->dmetric
.type
== type
)
9425 && (red
->dmetric
.value
== metric
)
9426 && (cur_originate
== default_originate
))
9429 /* Updating Metric details */
9430 red
->dmetric
.type
= type
;
9431 red
->dmetric
.value
= metric
;
9433 /* updating route map details */
9435 ospf_routemap_set(red
, rtmap
);
9437 ospf_routemap_unset(red
);
9439 return ospf_redistribute_default_set(ospf
, default_originate
, type
,
9443 DEFUN (no_ospf_default_information_originate
,
9444 no_ospf_default_information_originate_cmd
,
9445 "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9447 "Control distribution of default information\n"
9448 "Distribute a default route\n"
9449 "Always advertise default route\n"
9450 "OSPF default metric\n"
9452 "OSPF metric type for default routes\n"
9453 "Set OSPF External Type 1/2 metrics\n"
9454 "Route map reference\n"
9455 "Pointer to route-map entries\n")
9457 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9458 struct ospf_redist
*red
;
9460 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
9464 ospf_routemap_unset(red
);
9465 ospf_redist_del(ospf
, DEFAULT_ROUTE
, 0);
9467 return ospf_redistribute_default_set(ospf
, DEFAULT_ORIGINATE_NONE
,
9471 DEFUN (ospf_default_metric
,
9472 ospf_default_metric_cmd
,
9473 "default-metric (0-16777214)",
9474 "Set metric of redistributed routes\n"
9477 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9481 if (!str2metric(argv
[idx_number
]->arg
, &metric
))
9482 return CMD_WARNING_CONFIG_FAILED
;
9484 ospf
->default_metric
= metric
;
9489 DEFUN (no_ospf_default_metric
,
9490 no_ospf_default_metric_cmd
,
9491 "no default-metric [(0-16777214)]",
9493 "Set metric of redistributed routes\n"
9496 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9498 ospf
->default_metric
= -1;
9504 DEFUN (ospf_distance
,
9507 "Administrative distance\n"
9508 "OSPF Administrative distance\n")
9510 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9514 distance
= atoi(argv
[idx_number
]->arg
);
9515 if (ospf
->distance_all
!= distance
) {
9516 ospf
->distance_all
= distance
;
9517 ospf_restart_spf(ospf
);
9523 DEFUN (no_ospf_distance
,
9524 no_ospf_distance_cmd
,
9525 "no distance (1-255)",
9527 "Administrative distance\n"
9528 "OSPF Administrative distance\n")
9530 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9532 if (ospf
->distance_all
) {
9533 ospf
->distance_all
= 0;
9534 ospf_restart_spf(ospf
);
9540 DEFUN (no_ospf_distance_ospf
,
9541 no_ospf_distance_ospf_cmd
,
9542 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
9544 "Administrative distance\n"
9545 "OSPF administrative distance\n"
9546 "Intra-area routes\n"
9547 "Distance for intra-area routes\n"
9548 "Inter-area routes\n"
9549 "Distance for inter-area routes\n"
9551 "Distance for external routes\n")
9553 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9556 if (argv_find(argv
, argc
, "intra-area", &idx
) || argc
== 3)
9557 idx
= ospf
->distance_intra
= 0;
9558 if (argv_find(argv
, argc
, "inter-area", &idx
) || argc
== 3)
9559 idx
= ospf
->distance_inter
= 0;
9560 if (argv_find(argv
, argc
, "external", &idx
) || argc
== 3)
9561 ospf
->distance_external
= 0;
9566 DEFUN (ospf_distance_ospf
,
9567 ospf_distance_ospf_cmd
,
9568 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
9569 "Administrative distance\n"
9570 "OSPF administrative distance\n"
9571 "Intra-area routes\n"
9572 "Distance for intra-area routes\n"
9573 "Inter-area routes\n"
9574 "Distance for inter-area routes\n"
9576 "Distance for external routes\n")
9578 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9581 ospf
->distance_intra
= 0;
9582 ospf
->distance_inter
= 0;
9583 ospf
->distance_external
= 0;
9585 if (argv_find(argv
, argc
, "intra-area", &idx
))
9586 ospf
->distance_intra
= atoi(argv
[idx
+ 1]->arg
);
9588 if (argv_find(argv
, argc
, "inter-area", &idx
))
9589 ospf
->distance_inter
= atoi(argv
[idx
+ 1]->arg
);
9591 if (argv_find(argv
, argc
, "external", &idx
))
9592 ospf
->distance_external
= atoi(argv
[idx
+ 1]->arg
);
9597 DEFUN (ip_ospf_mtu_ignore
,
9598 ip_ospf_mtu_ignore_addr_cmd
,
9599 "ip ospf mtu-ignore [A.B.C.D]",
9601 "OSPF interface commands\n"
9602 "Disable MTU mismatch detection on this interface\n"
9603 "Address of interface\n")
9605 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9607 struct in_addr addr
;
9610 struct ospf_if_params
*params
;
9611 params
= IF_DEF_PARAMS(ifp
);
9614 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9617 "Please specify interface address by A.B.C.D\n");
9618 return CMD_WARNING_CONFIG_FAILED
;
9620 params
= ospf_get_if_params(ifp
, addr
);
9621 ospf_if_update_params(ifp
, addr
);
9623 params
->mtu_ignore
= 1;
9624 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
9625 SET_IF_PARAM(params
, mtu_ignore
);
9627 UNSET_IF_PARAM(params
, mtu_ignore
);
9628 if (params
!= IF_DEF_PARAMS(ifp
)) {
9629 ospf_free_if_params(ifp
, addr
);
9630 ospf_if_update_params(ifp
, addr
);
9636 DEFUN (no_ip_ospf_mtu_ignore
,
9637 no_ip_ospf_mtu_ignore_addr_cmd
,
9638 "no ip ospf mtu-ignore [A.B.C.D]",
9641 "OSPF interface commands\n"
9642 "Disable MTU mismatch detection on this interface\n"
9643 "Address of interface\n")
9645 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9647 struct in_addr addr
;
9650 struct ospf_if_params
*params
;
9651 params
= IF_DEF_PARAMS(ifp
);
9654 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9657 "Please specify interface address by A.B.C.D\n");
9658 return CMD_WARNING_CONFIG_FAILED
;
9660 params
= ospf_get_if_params(ifp
, addr
);
9661 ospf_if_update_params(ifp
, addr
);
9663 params
->mtu_ignore
= 0;
9664 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
9665 SET_IF_PARAM(params
, mtu_ignore
);
9667 UNSET_IF_PARAM(params
, mtu_ignore
);
9668 if (params
!= IF_DEF_PARAMS(ifp
)) {
9669 ospf_free_if_params(ifp
, addr
);
9670 ospf_if_update_params(ifp
, addr
);
9677 DEFUN (ospf_max_metric_router_lsa_admin
,
9678 ospf_max_metric_router_lsa_admin_cmd
,
9679 "max-metric router-lsa administrative",
9680 "OSPF maximum / infinite-distance metric\n"
9681 "Advertise own Router-LSA with infinite distance (stub router)\n"
9682 "Administratively applied, for an indefinite period\n")
9684 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9685 struct listnode
*ln
;
9686 struct ospf_area
*area
;
9688 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
9689 SET_FLAG(area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
);
9691 if (!CHECK_FLAG(area
->stub_router_state
,
9692 OSPF_AREA_IS_STUB_ROUTED
))
9693 ospf_router_lsa_update_area(area
);
9696 /* Allows for areas configured later to get the property */
9697 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
;
9702 DEFUN (no_ospf_max_metric_router_lsa_admin
,
9703 no_ospf_max_metric_router_lsa_admin_cmd
,
9704 "no max-metric router-lsa administrative",
9706 "OSPF maximum / infinite-distance metric\n"
9707 "Advertise own Router-LSA with infinite distance (stub router)\n"
9708 "Administratively applied, for an indefinite period\n")
9710 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9711 struct listnode
*ln
;
9712 struct ospf_area
*area
;
9714 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
9715 UNSET_FLAG(area
->stub_router_state
,
9716 OSPF_AREA_ADMIN_STUB_ROUTED
);
9718 /* Don't trample on the start-up stub timer */
9719 if (CHECK_FLAG(area
->stub_router_state
,
9720 OSPF_AREA_IS_STUB_ROUTED
)
9721 && !area
->t_stub_router
) {
9722 UNSET_FLAG(area
->stub_router_state
,
9723 OSPF_AREA_IS_STUB_ROUTED
);
9724 ospf_router_lsa_update_area(area
);
9727 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET
;
9731 DEFUN (ospf_max_metric_router_lsa_startup
,
9732 ospf_max_metric_router_lsa_startup_cmd
,
9733 "max-metric router-lsa on-startup (5-86400)",
9734 "OSPF maximum / infinite-distance metric\n"
9735 "Advertise own Router-LSA with infinite distance (stub router)\n"
9736 "Automatically advertise stub Router-LSA on startup of OSPF\n"
9737 "Time (seconds) to advertise self as stub-router\n")
9739 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9741 unsigned int seconds
;
9744 vty_out(vty
, "%% Must supply stub-router period\n");
9745 return CMD_WARNING_CONFIG_FAILED
;
9748 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9750 ospf
->stub_router_startup_time
= seconds
;
9755 DEFUN (no_ospf_max_metric_router_lsa_startup
,
9756 no_ospf_max_metric_router_lsa_startup_cmd
,
9757 "no max-metric router-lsa on-startup [(5-86400)]",
9759 "OSPF maximum / infinite-distance metric\n"
9760 "Advertise own Router-LSA with infinite distance (stub router)\n"
9761 "Automatically advertise stub Router-LSA on startup of OSPF\n"
9762 "Time (seconds) to advertise self as stub-router\n")
9764 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9765 struct listnode
*ln
;
9766 struct ospf_area
*area
;
9768 ospf
->stub_router_startup_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
9770 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
9771 SET_FLAG(area
->stub_router_state
,
9772 OSPF_AREA_WAS_START_STUB_ROUTED
);
9773 EVENT_OFF(area
->t_stub_router
);
9775 /* Don't trample on admin stub routed */
9776 if (!CHECK_FLAG(area
->stub_router_state
,
9777 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
9778 UNSET_FLAG(area
->stub_router_state
,
9779 OSPF_AREA_IS_STUB_ROUTED
);
9780 ospf_router_lsa_update_area(area
);
9787 DEFUN (ospf_max_metric_router_lsa_shutdown
,
9788 ospf_max_metric_router_lsa_shutdown_cmd
,
9789 "max-metric router-lsa on-shutdown (5-100)",
9790 "OSPF maximum / infinite-distance metric\n"
9791 "Advertise own Router-LSA with infinite distance (stub router)\n"
9792 "Advertise stub-router prior to full shutdown of OSPF\n"
9793 "Time (seconds) to wait till full shutdown\n")
9795 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9797 unsigned int seconds
;
9800 vty_out(vty
, "%% Must supply stub-router shutdown period\n");
9801 return CMD_WARNING_CONFIG_FAILED
;
9804 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9806 ospf
->stub_router_shutdown_time
= seconds
;
9811 DEFUN (no_ospf_max_metric_router_lsa_shutdown
,
9812 no_ospf_max_metric_router_lsa_shutdown_cmd
,
9813 "no max-metric router-lsa on-shutdown [(5-100)]",
9815 "OSPF maximum / infinite-distance metric\n"
9816 "Advertise own Router-LSA with infinite distance (stub router)\n"
9817 "Advertise stub-router prior to full shutdown of OSPF\n"
9818 "Time (seconds) to wait till full shutdown\n")
9820 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9822 ospf
->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
9827 DEFUN (ospf_proactive_arp
,
9828 ospf_proactive_arp_cmd
,
9830 "Allow sending ARP requests proactively\n")
9832 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9834 ospf
->proactive_arp
= true;
9839 DEFUN (no_ospf_proactive_arp
,
9840 no_ospf_proactive_arp_cmd
,
9843 "Disallow sending ARP requests proactively\n")
9845 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9847 ospf
->proactive_arp
= false;
9852 /* Graceful Restart HELPER Commands */
9853 DEFPY(ospf_gr_helper_enable
, ospf_gr_helper_enable_cmd
,
9854 "graceful-restart helper enable [A.B.C.D$address]",
9855 "OSPF Graceful Restart\n"
9857 "Enable Helper support\n"
9858 "Advertising Router-ID\n")
9860 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9863 ospf_gr_helper_support_set_per_routerid(ospf
, &address
,
9868 ospf_gr_helper_support_set(ospf
, OSPF_GR_TRUE
);
9873 DEFPY(no_ospf_gr_helper_enable
,
9874 no_ospf_gr_helper_enable_cmd
,
9875 "no graceful-restart helper enable [A.B.C.D$address]",
9877 "OSPF Graceful Restart\n"
9879 "Enable Helper support\n"
9880 "Advertising Router-ID\n")
9882 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9885 ospf_gr_helper_support_set_per_routerid(ospf
, &address
,
9890 ospf_gr_helper_support_set(ospf
, OSPF_GR_FALSE
);
9894 DEFPY(ospf_gr_helper_enable_lsacheck
,
9895 ospf_gr_helper_enable_lsacheck_cmd
,
9896 "graceful-restart helper strict-lsa-checking",
9897 "OSPF Graceful Restart\n"
9899 "Enable strict LSA check\n")
9901 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9903 ospf_gr_helper_lsa_check_set(ospf
, OSPF_GR_TRUE
);
9907 DEFPY(no_ospf_gr_helper_enable_lsacheck
,
9908 no_ospf_gr_helper_enable_lsacheck_cmd
,
9909 "no graceful-restart helper strict-lsa-checking",
9911 "OSPF Graceful Restart\n"
9913 "Disable strict LSA check\n")
9915 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9917 ospf_gr_helper_lsa_check_set(ospf
, OSPF_GR_FALSE
);
9921 DEFPY(ospf_gr_helper_supported_grace_time
,
9922 ospf_gr_helper_supported_grace_time_cmd
,
9923 "graceful-restart helper supported-grace-time (10-1800)$interval",
9924 "OSPF Graceful Restart\n"
9926 "Supported grace timer\n"
9927 "Grace interval(in seconds)\n")
9929 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9931 ospf_gr_helper_supported_gracetime_set(ospf
, interval
);
9935 DEFPY(no_ospf_gr_helper_supported_grace_time
,
9936 no_ospf_gr_helper_supported_grace_time_cmd
,
9937 "no graceful-restart helper supported-grace-time (10-1800)$interval",
9939 "OSPF Graceful Restart\n"
9941 "Supported grace timer\n"
9942 "Grace interval(in seconds)\n")
9944 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9946 ospf_gr_helper_supported_gracetime_set(ospf
, OSPF_MAX_GRACE_INTERVAL
);
9950 DEFPY(ospf_gr_helper_planned_only
,
9951 ospf_gr_helper_planned_only_cmd
,
9952 "graceful-restart helper planned-only",
9953 "OSPF Graceful Restart\n"
9955 "Supported only planned restart\n")
9957 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9959 ospf_gr_helper_set_supported_planned_only_restart(ospf
, OSPF_GR_TRUE
);
9964 /* External Route Aggregation */
9965 DEFUN (ospf_external_route_aggregation
,
9966 ospf_external_route_aggregation_cmd
,
9967 "summary-address A.B.C.D/M [tag (1-4294967295)]",
9968 "External summary address\n"
9969 "Summary address prefix\n"
9971 "Router tag value\n")
9973 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9974 struct prefix_ipv4 p
;
9976 route_tag_t tag
= 0;
9977 int ret
= OSPF_SUCCESS
;
9979 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
9981 if (is_default_prefix4(&p
)) {
9983 "Default address shouldn't be configured as summary address.\n");
9987 /* Apply mask for given prefix. */
9990 if (!is_valid_summary_addr(&p
)) {
9991 vty_out(vty
, "Not a valid summary address.\n");
9992 return CMD_WARNING_CONFIG_FAILED
;
9996 tag
= strtoul(argv
[idx
+ 2]->arg
, NULL
, 10);
9998 ret
= ospf_asbr_external_aggregator_set(ospf
, &p
, tag
);
9999 if (ret
== OSPF_INVALID
)
10000 vty_out(vty
, "Invalid configuration!!\n");
10002 return CMD_SUCCESS
;
10005 DEFUN (no_ospf_external_route_aggregation
,
10006 no_ospf_external_route_aggregation_cmd
,
10007 "no summary-address A.B.C.D/M [tag (1-4294967295)]",
10009 "External summary address\n"
10010 "Summary address prefix\n"
10012 "Router tag value\n")
10014 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10015 struct prefix_ipv4 p
;
10017 route_tag_t tag
= 0;
10018 int ret
= OSPF_SUCCESS
;
10020 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
10022 if (is_default_prefix4(&p
)) {
10024 "Default address shouldn't be configured as summary address.\n");
10025 return CMD_SUCCESS
;
10028 /* Apply mask for given prefix. */
10031 if (!is_valid_summary_addr(&p
)) {
10032 vty_out(vty
, "Not a valid summary address.\n");
10033 return CMD_WARNING_CONFIG_FAILED
;
10037 tag
= strtoul(argv
[idx
+ 2]->arg
, NULL
, 10);
10039 ret
= ospf_asbr_external_aggregator_unset(ospf
, &p
, tag
);
10040 if (ret
== OSPF_INVALID
)
10041 vty_out(vty
, "Invalid configuration!!\n");
10043 return CMD_SUCCESS
;
10046 DEFPY(no_ospf_gr_helper_planned_only
,
10047 no_ospf_gr_helper_planned_only_cmd
,
10048 "no graceful-restart helper planned-only",
10050 "OSPF Graceful Restart\n"
10052 "Supported only for planned restart\n")
10054 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10056 ospf_gr_helper_set_supported_planned_only_restart(ospf
, OSPF_GR_FALSE
);
10058 return CMD_SUCCESS
;
10061 static int ospf_print_vty_helper_dis_rtr_walkcb(struct hash_bucket
*bucket
,
10064 struct advRtr
*rtr
= bucket
->data
;
10065 struct vty
*vty
= (struct vty
*)arg
;
10066 static unsigned int count
;
10068 vty_out(vty
, "%-6pI4,", &rtr
->advRtrAddr
);
10071 if (count
% 5 == 0)
10072 vty_out(vty
, "\n");
10074 return HASHWALK_CONTINUE
;
10077 static int ospf_print_json_helper_enabled_rtr_walkcb(struct hash_bucket
*bucket
,
10080 struct advRtr
*rtr
= bucket
->data
;
10081 struct json_object
*json_rid_array
= arg
;
10082 struct json_object
*json_rid
;
10084 json_rid
= json_object_new_object();
10086 json_object_string_addf(json_rid
, "routerId", "%pI4", &rtr
->advRtrAddr
);
10087 json_object_array_add(json_rid_array
, json_rid
);
10089 return HASHWALK_CONTINUE
;
10092 static int ospf_show_gr_helper_details(struct vty
*vty
, struct ospf
*ospf
,
10093 uint8_t use_vrf
, json_object
*json
,
10094 bool uj
, bool detail
)
10096 struct listnode
*node
;
10097 struct ospf_interface
*oi
;
10098 char buf
[PREFIX_STRLEN
];
10099 json_object
*json_vrf
= NULL
;
10103 json_vrf
= json_object_new_object();
10108 if (ospf
->instance
) {
10110 json_object_int_add(json
, "ospfInstance",
10113 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
10116 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
10120 json_object_object_add(json
, ospf_get_name(ospf
),
10123 vty_out(vty
, "\n");
10125 /* Show Router ID. */
10127 json_object_string_add(json_vrf
, "routerId",
10128 inet_ntop(AF_INET
, &ospf
->router_id
,
10129 buf
, sizeof(buf
)));
10131 vty_out(vty
, "\n OSPF Router with ID (%pI4)\n\n",
10137 if (ospf
->is_helper_supported
)
10139 " Graceful restart helper support enabled.\n");
10142 " Graceful restart helper support disabled.\n");
10144 if (ospf
->strict_lsa_check
)
10145 vty_out(vty
, " Strict LSA check is enabled.\n");
10147 vty_out(vty
, " Strict LSA check is disabled.\n");
10149 if (ospf
->only_planned_restart
)
10151 " Helper supported for planned restarts only.\n");
10154 " Helper supported for Planned and Unplanned Restarts.\n");
10157 " Supported Graceful restart interval: %d(in seconds).\n",
10158 ospf
->supported_grace_time
);
10160 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf
)) {
10161 vty_out(vty
, " Enable Router list:\n");
10163 hash_walk(ospf
->enable_rtr_list
,
10164 ospf_print_vty_helper_dis_rtr_walkcb
, vty
);
10165 vty_out(vty
, "\n\n");
10168 if (ospf
->last_exit_reason
!= OSPF_GR_HELPER_EXIT_NONE
) {
10169 vty_out(vty
, " Last Helper exit Reason :%s\n",
10170 ospf_exit_reason2str(ospf
->last_exit_reason
));
10173 if (ospf
->active_restarter_cnt
)
10175 " Number of Active neighbours in graceful restart: %d\n",
10176 ospf
->active_restarter_cnt
);
10178 vty_out(vty
, "\n");
10181 json_object_string_add(
10182 json_vrf
, "helperSupport",
10183 (ospf
->is_helper_supported
) ? "Enabled" : "Disabled");
10184 json_object_string_add(json_vrf
, "strictLsaCheck",
10185 (ospf
->strict_lsa_check
) ? "Enabled"
10187 #if CONFDATE > 20240401
10188 CPP_NOTICE("Remove deprecated json key: restartSupoort")
10190 json_object_string_add(
10191 json_vrf
, "restartSupoort",
10192 (ospf
->only_planned_restart
)
10193 ? "Planned Restart only"
10194 : "Planned and Unplanned Restarts");
10196 json_object_string_add(
10197 json_vrf
, "restartSupport",
10198 (ospf
->only_planned_restart
)
10199 ? "Planned Restart only"
10200 : "Planned and Unplanned Restarts");
10202 json_object_int_add(json_vrf
, "supportedGracePeriod",
10203 ospf
->supported_grace_time
);
10205 if (ospf
->last_exit_reason
!= OSPF_GR_HELPER_EXIT_NONE
)
10206 json_object_string_add(
10207 json_vrf
, "lastExitReason",
10208 ospf_exit_reason2str(ospf
->last_exit_reason
));
10210 if (ospf
->active_restarter_cnt
)
10211 json_object_int_add(json_vrf
, "activeRestarterCnt",
10212 ospf
->active_restarter_cnt
);
10214 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf
)) {
10215 struct json_object
*json_rid_array
=
10216 json_object_new_array();
10218 json_object_object_add(json_vrf
, "enabledRouterIds",
10221 hash_walk(ospf
->enable_rtr_list
,
10222 ospf_print_json_helper_enabled_rtr_walkcb
,
10230 json_object
*json_neighbors
= NULL
;
10232 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
10233 struct route_node
*rn
;
10234 struct ospf_neighbor
*nbr
;
10235 json_object
*json_neigh
;
10237 if (ospf_interface_neighbor_count(oi
) == 0)
10241 json_object_object_get_ex(json_vrf
, "neighbors",
10243 if (!json_neighbors
) {
10245 json_object_new_object();
10246 json_object_object_add(json_vrf
,
10252 for (rn
= route_top(oi
->nbrs
); rn
;
10253 rn
= route_next(rn
)) {
10260 if (!OSPF_GR_IS_ACTIVE_HELPER(nbr
))
10264 vty_out(vty
, " Neighbour %d :\n", cnt
);
10265 vty_out(vty
, " Address : %pI4\n",
10266 &nbr
->address
.u
.prefix4
);
10267 vty_out(vty
, " Routerid : %pI4\n",
10270 " Received Grace period : %d(in seconds).\n",
10271 nbr
->gr_helper_info
10272 .recvd_grace_period
);
10274 " Actual Grace period : %d(in seconds)\n",
10275 nbr
->gr_helper_info
10276 .actual_grace_period
);
10278 " Remaining GraceTime:%ld(in seconds).\n",
10279 event_timer_remain_second(
10280 nbr
->gr_helper_info
10283 " Graceful Restart reason: %s.\n\n",
10284 ospf_restart_reason2str(
10285 nbr
->gr_helper_info
10286 .gr_restart_reason
));
10289 json_neigh
= json_object_new_object();
10290 json_object_string_add(
10291 json_neigh
, "srcAddr",
10292 inet_ntop(AF_INET
, &nbr
->src
,
10293 buf
, sizeof(buf
)));
10295 json_object_string_add(
10296 json_neigh
, "routerid",
10299 buf
, sizeof(buf
)));
10300 json_object_int_add(
10302 "recvdGraceInterval",
10303 nbr
->gr_helper_info
10304 .recvd_grace_period
);
10305 json_object_int_add(
10307 "actualGraceInterval",
10308 nbr
->gr_helper_info
10309 .actual_grace_period
);
10310 json_object_int_add(
10311 json_neigh
, "remainGracetime",
10312 event_timer_remain_second(
10313 nbr
->gr_helper_info
10315 json_object_string_add(
10316 json_neigh
, "restartReason",
10317 ospf_restart_reason2str(
10318 nbr
->gr_helper_info
10319 .gr_restart_reason
));
10320 json_object_object_add(
10322 inet_ntop(AF_INET
, &nbr
->src
,
10329 return CMD_SUCCESS
;
10332 DEFUN (ospf_external_route_aggregation_no_adrvertise
,
10333 ospf_external_route_aggregation_no_adrvertise_cmd
,
10334 "summary-address A.B.C.D/M no-advertise",
10335 "External summary address\n"
10336 "Summary address prefix\n"
10337 "Don't advertise summary route \n")
10339 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10340 struct prefix_ipv4 p
;
10342 int ret
= OSPF_SUCCESS
;
10344 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
10346 if (is_default_prefix4(&p
)) {
10348 "Default address shouldn't be configured as summary address.\n");
10349 return CMD_SUCCESS
;
10352 /* Apply mask for given prefix. */
10355 if (!is_valid_summary_addr(&p
)) {
10356 vty_out(vty
, "Not a valid summary address.\n");
10357 return CMD_WARNING_CONFIG_FAILED
;
10360 ret
= ospf_asbr_external_rt_no_advertise(ospf
, &p
);
10361 if (ret
== OSPF_INVALID
)
10362 vty_out(vty
, "Invalid configuration!!\n");
10364 return CMD_SUCCESS
;
10367 DEFUN (no_ospf_external_route_aggregation_no_adrvertise
,
10368 no_ospf_external_route_aggregation_no_adrvertise_cmd
,
10369 "no summary-address A.B.C.D/M no-advertise",
10371 "External summary address\n"
10372 "Summary address prefix\n"
10373 "Advertise summary route to the AS \n")
10375 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10376 struct prefix_ipv4 p
;
10378 int ret
= OSPF_SUCCESS
;
10380 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
10382 if (is_default_prefix4(&p
)) {
10384 "Default address shouldn't be configured as summary address.\n");
10385 return CMD_SUCCESS
;
10388 /* Apply mask for given prefix. */
10391 if (!is_valid_summary_addr(&p
)) {
10392 vty_out(vty
, "Not a valid summary address.\n");
10393 return CMD_WARNING_CONFIG_FAILED
;
10396 ret
= ospf_asbr_external_rt_advertise(ospf
, &p
);
10397 if (ret
== OSPF_INVALID
)
10398 vty_out(vty
, "Invalid configuration!!\n");
10400 return CMD_SUCCESS
;
10403 DEFUN (ospf_route_aggregation_timer
,
10404 ospf_route_aggregation_timer_cmd
,
10405 "aggregation timer (5-1800)",
10406 "External route aggregation\n"
10407 "Delay timer (in seconds)\n"
10408 "Timer interval(in seconds)\n")
10410 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10411 uint16_t interval
= 0;
10413 interval
= strtoul(argv
[2]->arg
, NULL
, 10);
10415 ospf_external_aggregator_timer_set(ospf
, interval
);
10417 return CMD_SUCCESS
;
10420 DEFPY (show_ip_ospf_gr_helper
,
10421 show_ip_ospf_gr_helper_cmd
,
10422 "show ip ospf [vrf <NAME|all>] graceful-restart helper [detail] [json]",
10425 "OSPF information\n"
10428 "OSPF Graceful Restart\n"
10429 "Helper details in the router\n"
10430 "Detailed information\n"
10433 char *vrf_name
= NULL
;
10434 bool all_vrf
= false;
10435 int ret
= CMD_SUCCESS
;
10438 uint8_t use_vrf
= 0;
10439 bool uj
= use_json(argc
, argv
);
10440 struct ospf
*ospf
= NULL
;
10441 json_object
*json
= NULL
;
10442 struct listnode
*node
= NULL
;
10444 bool detail
= false;
10446 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
10448 if (argv_find(argv
, argc
, "detail", &idx
))
10452 json
= json_object_new_object();
10454 /* vrf input is provided */
10459 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
10460 if (!ospf
->oi_running
)
10463 ret
= ospf_show_gr_helper_details(
10464 vty
, ospf
, use_vrf
, json
, uj
, detail
);
10468 vty_json(vty
, json
);
10473 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
10475 if (ospf
== NULL
|| !ospf
->oi_running
) {
10478 vty_json(vty
, json
);
10481 "%% OSPF is not enabled in vrf %s\n",
10484 return CMD_SUCCESS
;
10489 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
10491 if (ospf
== NULL
|| !ospf
->oi_running
) {
10494 vty_json(vty
, json
);
10497 "%% OSPF is not enabled in vrf default\n");
10499 return CMD_SUCCESS
;
10502 ospf_show_gr_helper_details(vty
, ospf
, use_vrf
, json
, uj
,
10507 vty_json(vty
, json
);
10509 return CMD_SUCCESS
;
10511 /* Graceful Restart HELPER commands end */
10512 DEFUN (no_ospf_route_aggregation_timer
,
10513 no_ospf_route_aggregation_timer_cmd
,
10514 "no aggregation timer",
10516 "External route aggregation\n"
10519 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10521 ospf_external_aggregator_timer_set(ospf
, OSPF_EXTL_AGGR_DEFAULT_DELAY
);
10523 return CMD_SUCCESS
;
10526 /* External Route Aggregation End */
10528 static void config_write_stub_router(struct vty
*vty
, struct ospf
*ospf
)
10530 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
10531 vty_out(vty
, " max-metric router-lsa on-startup %u\n",
10532 ospf
->stub_router_startup_time
);
10533 if (ospf
->stub_router_shutdown_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
10534 vty_out(vty
, " max-metric router-lsa on-shutdown %u\n",
10535 ospf
->stub_router_shutdown_time
);
10536 if (ospf
->stub_router_admin_set
== OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
)
10537 vty_out(vty
, " max-metric router-lsa administrative\n");
10542 static void show_ip_ospf_route_network(struct vty
*vty
, struct ospf
*ospf
,
10543 struct route_table
*rt
,
10546 struct route_node
*rn
;
10547 struct ospf_route
* or ;
10548 struct listnode
*pnode
, *pnnode
;
10549 struct ospf_path
*path
;
10550 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
10551 *json_nexthop
= NULL
;
10555 "============ OSPF network routing table ============\n");
10557 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
10558 char buf1
[PREFIX2STR_BUFFER
];
10560 if ((or = rn
->info
) == NULL
)
10563 prefix2str(&rn
->p
, buf1
, sizeof(buf1
));
10566 json_route
= json_object_new_object();
10567 json_object_object_add(json
, buf1
, json_route
);
10570 switch (or->path_type
) {
10571 case OSPF_PATH_INTER_AREA
:
10572 if (or->type
== OSPF_DESTINATION_NETWORK
) {
10574 json_object_string_add(json_route
,
10577 json_object_int_add(json_route
, "cost",
10579 json_object_string_addf(
10580 json_route
, "area", "%pI4",
10581 &or->u
.std
.area_id
);
10584 "N IA %-18s [%d] area: %pI4\n",
10586 &or->u
.std
.area_id
);
10588 } else if (or->type
== OSPF_DESTINATION_DISCARD
) {
10590 json_object_string_add(json_route
,
10595 "D IA %-18s Discard entry\n",
10600 case OSPF_PATH_INTRA_AREA
:
10602 json_object_string_add(json_route
, "routeType",
10604 json_object_int_add(json_route
, "cost",
10606 json_object_string_addf(json_route
, "area",
10608 &or->u
.std
.area_id
);
10610 vty_out(vty
, "N %-18s [%d] area: %pI4\n",
10612 &or->u
.std
.area_id
);
10619 if (or->type
== OSPF_DESTINATION_NETWORK
) {
10621 json_nexthop_array
= json_object_new_array();
10622 json_object_object_add(json_route
, "nexthops",
10623 json_nexthop_array
);
10626 for (ALL_LIST_ELEMENTS(or->paths
, pnode
, pnnode
,
10629 json_nexthop
= json_object_new_object();
10630 json_object_array_add(
10631 json_nexthop_array
,
10634 if (if_lookup_by_index(path
->ifindex
,
10637 if (path
->nexthop
.s_addr
10640 json_object_string_add(
10643 json_object_string_add(
10645 "directlyAttachedTo",
10651 "%24s directly attached to %s\n",
10659 json_object_string_addf(
10663 json_object_string_add(
10671 "%24s via %pI4, %s\n",
10684 vty_out(vty
, "\n");
10687 static void show_ip_ospf_route_router(struct vty
*vty
, struct ospf
*ospf
,
10688 struct route_table
*rtrs
,
10691 struct route_node
*rn
;
10692 struct ospf_route
* or ;
10693 struct listnode
*pnode
;
10694 struct listnode
*node
;
10695 struct ospf_path
*path
;
10696 char buf
[PREFIX_STRLEN
];
10697 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
10698 *json_nexthop
= NULL
;
10701 vty_out(vty
, "============ OSPF %s table =============\n",
10702 ospf
->all_rtrs
== rtrs
? "reachable routers"
10703 : "router routing");
10705 for (rn
= route_top(rtrs
); rn
; rn
= route_next(rn
)) {
10706 if (rn
->info
== NULL
)
10711 json_route
= json_object_new_object();
10712 json_object_object_add(
10713 json
, inet_ntop(AF_INET
, &rn
->p
.u
.prefix4
,
10716 json_object_string_add(json_route
, "routeType", "R ");
10718 vty_out(vty
, "R %-15pI4 ",
10722 for (ALL_LIST_ELEMENTS_RO((struct list
*)rn
->info
, node
, or)) {
10725 vty_out(vty
, "%24s", "");
10730 json_object_int_add(json_route
, "cost",
10732 json_object_string_addf(json_route
, "area",
10734 &or->u
.std
.area_id
);
10735 if (or->path_type
== OSPF_PATH_INTER_AREA
) {
10736 json_object_boolean_true_add(json_route
,
10738 json_object_boolean_true_add(json_route
,
10741 if (or->u
.std
.flags
& ROUTER_LSA_BORDER
)
10742 json_object_string_add(json_route
,
10745 else if (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
)
10746 json_object_string_add(json_route
,
10750 vty_out(vty
, "%s [%d] area: %pI4",
10751 (or->path_type
== OSPF_PATH_INTER_AREA
10754 or->cost
, &or->u
.std
.area_id
);
10756 vty_out(vty
, "%s%s\n",
10757 (or->u
.std
.flags
& ROUTER_LSA_BORDER
10760 (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
10766 json_nexthop_array
= json_object_new_array();
10767 json_object_object_add(json_route
, "nexthops",
10768 json_nexthop_array
);
10771 for (ALL_LIST_ELEMENTS_RO(or->paths
, pnode
, path
)) {
10773 json_nexthop
= json_object_new_object();
10774 json_object_array_add(
10775 json_nexthop_array
,
10778 if (if_lookup_by_index(path
->ifindex
,
10780 if (path
->nexthop
.s_addr
10783 json_object_string_add(
10786 json_object_string_add(
10788 "directlyAttachedTo",
10794 "%24s directly attached to %s\n",
10802 json_object_string_addf(
10806 json_object_string_add(
10814 "%24s via %pI4, %s\n",
10827 vty_out(vty
, "\n");
10830 static void show_ip_ospf_route_external(struct vty
*vty
, struct ospf
*ospf
,
10831 struct route_table
*rt
,
10834 struct route_node
*rn
;
10835 struct ospf_route
*er
;
10836 struct listnode
*pnode
, *pnnode
;
10837 struct ospf_path
*path
;
10838 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
10839 *json_nexthop
= NULL
;
10843 "============ OSPF external routing table ===========\n");
10845 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
10846 if ((er
= rn
->info
) == NULL
)
10851 snprintfrr(buf1
, sizeof(buf1
), "%pFX", &rn
->p
);
10853 json_route
= json_object_new_object();
10854 json_object_object_add(json
, buf1
, json_route
);
10857 switch (er
->path_type
) {
10858 case OSPF_PATH_TYPE1_EXTERNAL
:
10860 json_object_string_add(json_route
, "routeType",
10862 json_object_int_add(json_route
, "cost",
10864 json_object_int_add(json_route
, "tag",
10868 "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI
10870 buf1
, er
->cost
, er
->u
.ext
.tag
);
10873 case OSPF_PATH_TYPE2_EXTERNAL
:
10875 json_object_string_add(json_route
, "routeType",
10877 json_object_int_add(json_route
, "cost",
10879 json_object_int_add(json_route
, "type2cost",
10880 er
->u
.ext
.type2_cost
);
10881 json_object_int_add(json_route
, "tag",
10885 "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI
10887 buf1
, er
->cost
, er
->u
.ext
.type2_cost
,
10894 json_nexthop_array
= json_object_new_array();
10895 json_object_object_add(json_route
, "nexthops",
10896 json_nexthop_array
);
10899 for (ALL_LIST_ELEMENTS(er
->paths
, pnode
, pnnode
, path
)) {
10901 json_nexthop
= json_object_new_object();
10902 json_object_array_add(json_nexthop_array
,
10906 if (if_lookup_by_index(path
->ifindex
, ospf
->vrf_id
)) {
10907 if (path
->nexthop
.s_addr
== INADDR_ANY
) {
10909 json_object_string_add(
10910 json_nexthop
, "ip",
10912 json_object_string_add(
10914 "directlyAttachedTo",
10920 "%24s directly attached to %s\n",
10928 json_object_string_addf(
10929 json_nexthop
, "ip",
10930 "%pI4", &path
->nexthop
);
10931 json_object_string_add(
10932 json_nexthop
, "via",
10938 "%24s via %pI4, %s\n",
10950 vty_out(vty
, "\n");
10953 static int show_ip_ospf_reachable_routers_common(struct vty
*vty
,
10957 if (ospf
->instance
)
10958 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
10960 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
10962 if (ospf
->all_rtrs
== NULL
) {
10963 vty_out(vty
, "No OSPF reachable router information exist\n");
10964 return CMD_SUCCESS
;
10967 /* Show Router routes. */
10968 show_ip_ospf_route_router(vty
, ospf
, ospf
->all_rtrs
, NULL
);
10970 vty_out(vty
, "\n");
10972 return CMD_SUCCESS
;
10975 DEFUN (show_ip_ospf_reachable_routers
,
10976 show_ip_ospf_reachable_routers_cmd
,
10977 "show ip ospf [vrf <NAME|all>] reachable-routers",
10980 "OSPF information\n"
10983 "Show all the reachable OSPF routers\n")
10985 struct ospf
*ospf
= NULL
;
10986 struct listnode
*node
= NULL
;
10987 char *vrf_name
= NULL
;
10988 bool all_vrf
= false;
10989 int ret
= CMD_SUCCESS
;
10992 uint8_t use_vrf
= 0;
10994 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
10997 bool ospf_output
= false;
11002 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11003 if (!ospf
->oi_running
)
11006 ospf_output
= true;
11007 ret
= show_ip_ospf_reachable_routers_common(
11008 vty
, ospf
, use_vrf
);
11012 vty_out(vty
, "%% OSPF instance not found\n");
11014 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11015 if (ospf
== NULL
|| !ospf
->oi_running
) {
11016 vty_out(vty
, "%% OSPF instance not found\n");
11017 return CMD_SUCCESS
;
11020 ret
= show_ip_ospf_reachable_routers_common(vty
, ospf
,
11024 /* Display default ospf (instance 0) info */
11025 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11026 if (ospf
== NULL
|| !ospf
->oi_running
) {
11027 vty_out(vty
, "%% OSPF instance not found\n");
11028 return CMD_SUCCESS
;
11031 ret
= show_ip_ospf_reachable_routers_common(vty
, ospf
, use_vrf
);
11037 DEFUN (show_ip_ospf_instance_reachable_routers
,
11038 show_ip_ospf_instance_reachable_routers_cmd
,
11039 "show ip ospf (1-65535) reachable-routers",
11042 "OSPF information\n"
11044 "Show all the reachable OSPF routers\n")
11046 int idx_number
= 3;
11048 unsigned short instance
= 0;
11050 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
11051 if (instance
!= ospf_instance
)
11052 return CMD_NOT_MY_INSTANCE
;
11054 ospf
= ospf_lookup_instance(instance
);
11055 if (!ospf
|| !ospf
->oi_running
)
11056 return CMD_SUCCESS
;
11058 return show_ip_ospf_reachable_routers_common(vty
, ospf
, 0);
11061 static int show_ip_ospf_border_routers_common(struct vty
*vty
,
11066 json_object
*json_vrf
= NULL
;
11067 json_object
*json_router
= NULL
;
11071 json_vrf
= json_object_new_object();
11074 json_router
= json_object_new_object();
11077 if (ospf
->instance
) {
11079 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
11081 json_object_int_add(json_vrf
, "ospfInstance",
11085 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
11087 if (ospf
->new_table
== NULL
) {
11089 vty_out(vty
, "No OSPF routing information exist\n");
11091 json_object_free(json_router
);
11093 json_object_free(json_vrf
);
11095 return CMD_SUCCESS
;
11098 /* Show Network routes.
11099 show_ip_ospf_route_network (vty, ospf->new_table); */
11101 /* Show Router routes. */
11102 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, json_router
);
11105 json_object_object_add(json_vrf
, "routers", json_router
);
11107 if (ospf
->vrf_id
== VRF_DEFAULT
)
11108 json_object_object_add(json
, "default",
11111 json_object_object_add(json
, ospf
->name
,
11115 vty_out(vty
, "\n");
11118 return CMD_SUCCESS
;
11121 DEFPY (show_ip_ospf_border_routers
,
11122 show_ip_ospf_border_routers_cmd
,
11123 "show ip ospf [vrf <NAME|all>] border-routers [json]",
11126 "OSPF information\n"
11129 "Show all the ABR's and ASBR's\n"
11132 struct ospf
*ospf
= NULL
;
11133 struct listnode
*node
= NULL
;
11134 char *vrf_name
= NULL
;
11135 bool all_vrf
= false;
11136 int ret
= CMD_SUCCESS
;
11139 uint8_t use_vrf
= 0;
11140 bool uj
= use_json(argc
, argv
);
11141 json_object
*json
= NULL
;
11144 json
= json_object_new_object();
11146 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11149 bool ospf_output
= false;
11154 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11155 if (!ospf
->oi_running
)
11158 ospf_output
= true;
11159 ret
= show_ip_ospf_border_routers_common(
11160 vty
, ospf
, use_vrf
, json
);
11164 vty_json(vty
, json
);
11165 else if (!ospf_output
)
11166 vty_out(vty
, "%% OSPF is not enabled\n");
11170 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11171 if (ospf
== NULL
|| !ospf
->oi_running
) {
11173 vty_json(vty
, json
);
11176 "%% OSPF is not enabled in vrf %s\n",
11179 return CMD_SUCCESS
;
11183 /* Display default ospf (instance 0) info */
11184 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11185 if (ospf
== NULL
|| !ospf
->oi_running
) {
11187 vty_json(vty
, json
);
11190 "%% OSPF is not enabled in vrf default\n");
11192 return CMD_SUCCESS
;
11197 ret
= show_ip_ospf_border_routers_common(vty
, ospf
, use_vrf
,
11200 vty_json(vty
, json
);
11206 DEFUN (show_ip_ospf_instance_border_routers
,
11207 show_ip_ospf_instance_border_routers_cmd
,
11208 "show ip ospf (1-65535) border-routers",
11211 "OSPF information\n"
11213 "Show all the ABR's and ASBR's\n")
11215 int idx_number
= 3;
11217 unsigned short instance
= 0;
11219 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
11220 if (instance
!= ospf_instance
)
11221 return CMD_NOT_MY_INSTANCE
;
11223 ospf
= ospf_lookup_instance(instance
);
11224 if (!ospf
|| !ospf
->oi_running
)
11225 return CMD_SUCCESS
;
11227 return show_ip_ospf_border_routers_common(vty
, ospf
, 0, NULL
);
11230 static int show_ip_ospf_route_common(struct vty
*vty
, struct ospf
*ospf
,
11231 json_object
*json
, uint8_t use_vrf
)
11233 json_object
*json_vrf
= NULL
;
11235 if (ospf
->instance
)
11236 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
11241 json_vrf
= json_object_new_object();
11246 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
11248 if (ospf
->new_table
== NULL
) {
11251 json_object_free(json_vrf
);
11253 vty_out(vty
, "No OSPF routing information exist\n");
11255 return CMD_SUCCESS
;
11258 /* Show Network routes. */
11259 show_ip_ospf_route_network(vty
, ospf
, ospf
->new_table
, json_vrf
);
11261 /* Show Router routes. */
11262 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, json_vrf
);
11264 /* Show Router routes. */
11265 if (ospf
->all_rtrs
)
11266 show_ip_ospf_route_router(vty
, ospf
, ospf
->all_rtrs
, json_vrf
);
11268 /* Show AS External routes. */
11269 show_ip_ospf_route_external(vty
, ospf
, ospf
->old_external_route
,
11274 // json_object_object_add(json_vrf, "areas",
11276 json_object_object_add(json
, ospf_get_name(ospf
),
11280 vty_out(vty
, "\n");
11283 return CMD_SUCCESS
;
11286 DEFUN (show_ip_ospf_route
,
11287 show_ip_ospf_route_cmd
,
11288 "show ip ospf [vrf <NAME|all>] route [json]",
11291 "OSPF information\n"
11294 "OSPF routing table\n"
11297 struct ospf
*ospf
= NULL
;
11298 struct listnode
*node
= NULL
;
11299 char *vrf_name
= NULL
;
11300 bool all_vrf
= false;
11301 int ret
= CMD_SUCCESS
;
11304 uint8_t use_vrf
= 0;
11305 bool uj
= use_json(argc
, argv
);
11306 json_object
*json
= NULL
;
11309 json
= json_object_new_object();
11311 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11313 /* vrf input is provided could be all or specific vrf*/
11315 bool ospf_output
= false;
11320 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11321 if (!ospf
->oi_running
)
11323 ospf_output
= true;
11324 ret
= show_ip_ospf_route_common(vty
, ospf
, json
,
11329 /* Keep Non-pretty format */
11330 vty_json(vty
, json
);
11331 } else if (!ospf_output
)
11332 vty_out(vty
, "%% OSPF is not enabled\n");
11336 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11337 if (ospf
== NULL
|| !ospf
->oi_running
) {
11339 vty_json(vty
, json
);
11342 "%% OSPF is not enabled in vrf %s\n",
11345 return CMD_SUCCESS
;
11348 /* Display default ospf (instance 0) info */
11349 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11350 if (ospf
== NULL
|| !ospf
->oi_running
) {
11352 vty_json(vty
, json
);
11355 "%% OSPF is not enabled in vrf default\n");
11357 return CMD_SUCCESS
;
11362 ret
= show_ip_ospf_route_common(vty
, ospf
, json
, use_vrf
);
11363 /* Keep Non-pretty format */
11365 vty_out(vty
, "%s\n",
11366 json_object_to_json_string_ext(
11367 json
, JSON_C_TO_STRING_NOSLASHESCAPE
));
11371 json_object_free(json
);
11376 DEFUN (show_ip_ospf_instance_route
,
11377 show_ip_ospf_instance_route_cmd
,
11378 "show ip ospf (1-65535) route",
11381 "OSPF information\n"
11383 "OSPF routing table\n")
11385 int idx_number
= 3;
11387 unsigned short instance
= 0;
11389 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
11390 if (instance
!= ospf_instance
)
11391 return CMD_NOT_MY_INSTANCE
;
11393 ospf
= ospf_lookup_instance(instance
);
11394 if (!ospf
|| !ospf
->oi_running
)
11395 return CMD_SUCCESS
;
11397 return show_ip_ospf_route_common(vty
, ospf
, NULL
, 0);
11401 DEFUN (show_ip_ospf_vrfs
,
11402 show_ip_ospf_vrfs_cmd
,
11403 "show ip ospf vrfs [json]",
11406 "OSPF information\n"
11407 "Show OSPF VRFs \n"
11410 bool uj
= use_json(argc
, argv
);
11411 json_object
*json
= NULL
;
11412 json_object
*json_vrfs
= NULL
;
11413 struct ospf
*ospf
= NULL
;
11414 struct listnode
*node
= NULL
;
11416 static const char header
[] = "Name Id RouterId ";
11419 json
= json_object_new_object();
11420 json_vrfs
= json_object_new_object();
11423 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11424 json_object
*json_vrf
= NULL
;
11425 const char *name
= NULL
;
11426 int64_t vrf_id_ui
= 0;
11430 if (!uj
&& count
== 1)
11431 vty_out(vty
, "%s\n", header
);
11433 json_vrf
= json_object_new_object();
11435 name
= ospf_get_name(ospf
);
11437 vrf_id_ui
= (ospf
->vrf_id
== VRF_UNKNOWN
)
11439 : (int64_t)ospf
->vrf_id
;
11442 json_object_int_add(json_vrf
, "vrfId", vrf_id_ui
);
11443 json_object_string_addf(json_vrf
, "routerId", "%pI4",
11446 json_object_object_add(json_vrfs
, name
, json_vrf
);
11449 vty_out(vty
, "%-25s %-5d %-16pI4 \n", name
,
11450 ospf
->vrf_id
, &ospf
->router_id
);
11455 json_object_object_add(json
, "vrfs", json_vrfs
);
11456 json_object_int_add(json
, "totalVrfs", count
);
11458 vty_json(vty
, json
);
11461 vty_out(vty
, "\nTotal number of OSPF VRFs: %d\n",
11465 return CMD_SUCCESS
;
11467 DEFPY (clear_ip_ospf_neighbor
,
11468 clear_ip_ospf_neighbor_cmd
,
11469 "clear ip ospf [(1-65535)]$instance neighbor [A.B.C.D$nbr_id]",
11472 "OSPF information\n"
11474 "Reset OSPF Neighbor\n"
11477 struct listnode
*node
;
11478 struct ospf
*ospf
= NULL
;
11480 /* If user does not specify the arguments,
11481 * instance = 0 and nbr_id = 0.0.0.0
11483 if (instance
!= 0) {
11484 /* This means clear only the particular ospf process */
11485 if (instance
!= ospf_instance
)
11486 return CMD_NOT_MY_INSTANCE
;
11489 /* Clear all the ospf processes */
11490 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11491 if (!ospf
->oi_running
)
11494 if (nbr_id_str
&& IPV4_ADDR_SAME(&ospf
->router_id
, &nbr_id
)) {
11495 vty_out(vty
, "Self router-id is not allowed.\r\n ");
11496 return CMD_SUCCESS
;
11499 ospf_neighbor_reset(ospf
, nbr_id
, nbr_id_str
);
11502 return CMD_SUCCESS
;
11505 DEFPY (clear_ip_ospf_process
,
11506 clear_ip_ospf_process_cmd
,
11507 "clear ip ospf [(1-65535)]$instance process",
11510 "OSPF information\n"
11512 "Reset OSPF Process\n")
11514 struct listnode
*node
;
11515 struct ospf
*ospf
= NULL
;
11517 /* Check if instance is not passed as an argument */
11518 if (instance
!= 0) {
11519 /* This means clear only the particular ospf process */
11520 if (instance
!= ospf_instance
)
11521 return CMD_NOT_MY_INSTANCE
;
11524 /* Clear all the ospf processes */
11525 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11526 if (!ospf
->oi_running
)
11529 ospf_process_reset(ospf
);
11532 return CMD_SUCCESS
;
11535 static const char *const ospf_abr_type_str
[] = {
11536 "unknown", "standard", "ibm", "cisco", "shortcut"
11539 static const char *const ospf_shortcut_mode_str
[] = {
11540 "default", "enable", "disable"
11542 static int ospf_vty_external_rt_walkcb(struct hash_bucket
*bucket
,
11545 struct external_info
*ei
= bucket
->data
;
11546 struct vty
*vty
= (struct vty
*)arg
;
11547 static unsigned int count
;
11549 vty_out(vty
, "%-4pI4/%d, ", &ei
->p
.prefix
, ei
->p
.prefixlen
);
11552 if (count
% 5 == 0)
11553 vty_out(vty
, "\n");
11555 if (OSPF_EXTERNAL_RT_COUNT(ei
->aggr_route
) == count
)
11558 return HASHWALK_CONTINUE
;
11561 static int ospf_json_external_rt_walkcb(struct hash_bucket
*bucket
,
11564 struct external_info
*ei
= bucket
->data
;
11565 struct json_object
*json
= (struct json_object
*)arg
;
11566 char buf
[PREFIX2STR_BUFFER
];
11568 static unsigned int count
;
11570 prefix2str(&ei
->p
, buf
, sizeof(buf
));
11572 snprintf(exnalbuf
, 20, "Exnl Addr-%d", count
);
11574 json_object_string_add(json
, exnalbuf
, buf
);
11578 if (OSPF_EXTERNAL_RT_COUNT(ei
->aggr_route
) == count
)
11581 return HASHWALK_CONTINUE
;
11584 static int ospf_show_summary_address(struct vty
*vty
, struct ospf
*ospf
,
11585 uint8_t use_vrf
, json_object
*json
,
11586 bool uj
, bool detail
)
11588 struct route_node
*rn
;
11589 json_object
*json_vrf
= NULL
;
11592 static char header
[] =
11593 "Summary-address Metric-type Metric Tag External_Rt_count\n";
11595 mtype
= metric_type(ospf
, 0, ospf
->instance
);
11596 mval
= metric_value(ospf
, 0, ospf
->instance
);
11599 vty_out(vty
, "%s\n", header
);
11603 json_vrf
= json_object_new_object();
11608 if (ospf
->instance
) {
11610 json_object_int_add(json
, "ospfInstance",
11613 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
11616 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
11619 vty_out(vty
, "aggregation delay interval :%u(in seconds)\n\n",
11620 ospf
->aggr_delay_interval
);
11622 json_object_int_add(json_vrf
, "aggregationDelayInterval",
11623 ospf
->aggr_delay_interval
);
11626 for (rn
= route_top(ospf
->rt_aggr_tbl
); rn
; rn
= route_next(rn
))
11628 struct ospf_external_aggr_rt
*aggr
= rn
->info
;
11629 json_object
*json_aggr
= NULL
;
11630 char buf
[PREFIX2STR_BUFFER
];
11632 prefix2str(&aggr
->p
, buf
, sizeof(buf
));
11636 json_aggr
= json_object_new_object();
11638 json_object_object_add(json_vrf
, buf
,
11640 json_object_string_add(json_aggr
,
11641 "summaryAddress", buf
);
11642 json_object_string_add(
11643 json_aggr
, "metricType",
11644 (mtype
== EXTERNAL_METRIC_TYPE_1
)
11648 json_object_int_add(json_aggr
, "metric", mval
);
11649 json_object_int_add(json_aggr
, "tag",
11651 json_object_int_add(
11652 json_aggr
, "externalRouteCount",
11653 OSPF_EXTERNAL_RT_COUNT(aggr
));
11655 if (OSPF_EXTERNAL_RT_COUNT(aggr
) && detail
) {
11657 aggr
->match_extnl_hash
,
11658 ospf_json_external_rt_walkcb
,
11663 vty_out(vty
, "%-20s", buf
);
11665 (mtype
== EXTERNAL_METRIC_TYPE_1
)
11666 ? vty_out(vty
, "%-16s", "E1")
11667 : vty_out(vty
, "%-16s", "E2");
11668 vty_out(vty
, "%-11d", mval
);
11670 vty_out(vty
, "%-12u", aggr
->tag
);
11672 vty_out(vty
, "%-5ld\n",
11673 OSPF_EXTERNAL_RT_COUNT(aggr
));
11675 if (OSPF_EXTERNAL_RT_COUNT(aggr
) && detail
) {
11677 "Matched External routes:\n");
11679 aggr
->match_extnl_hash
,
11680 ospf_vty_external_rt_walkcb
,
11682 vty_out(vty
, "\n");
11685 vty_out(vty
, "\n");
11691 json_object_object_add(json
, ospf_get_name(ospf
),
11694 vty_out(vty
, "\n");
11696 return CMD_SUCCESS
;
11699 DEFUN (show_ip_ospf_external_aggregator
,
11700 show_ip_ospf_external_aggregator_cmd
,
11701 "show ip ospf [vrf <NAME|all>] summary-address [detail] [json]",
11703 "OSPF information\n"
11706 "Show external summary addresses\n"
11707 "Detailed information\n"
11710 char *vrf_name
= NULL
;
11711 bool all_vrf
= false;
11712 int ret
= CMD_SUCCESS
;
11715 uint8_t use_vrf
= 0;
11716 bool uj
= use_json(argc
, argv
);
11717 struct ospf
*ospf
= NULL
;
11718 json_object
*json
= NULL
;
11719 struct listnode
*node
= NULL
;
11721 bool detail
= false;
11723 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11725 if (argv_find(argv
, argc
, "detail", &idx
))
11729 json
= json_object_new_object();
11731 /* vrf input is provided */
11735 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11736 if (!ospf
->oi_running
)
11738 ret
= ospf_show_summary_address(
11739 vty
, ospf
, use_vrf
, json
, uj
, detail
);
11743 vty_json(vty
, json
);
11748 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11750 if (ospf
== NULL
|| !ospf
->oi_running
) {
11752 vty_json(vty
, json
);
11755 "%% OSPF is not enabled in vrf %s\n",
11758 return CMD_SUCCESS
;
11760 ospf_show_summary_address(vty
, ospf
, use_vrf
, json
, uj
, detail
);
11764 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11765 if (ospf
== NULL
|| !ospf
->oi_running
) {
11767 vty_json(vty
, json
);
11770 "%% OSPF is not enabled in vrf default\n");
11772 return CMD_SUCCESS
;
11775 ospf_show_summary_address(vty
, ospf
, use_vrf
, json
, uj
, detail
);
11779 vty_json(vty
, json
);
11780 return CMD_SUCCESS
;
11783 static const char *const ospf_int_type_str
[] = {
11784 "unknown", /* should never be used. */
11788 "point-to-multipoint",
11789 "virtual-link", /* should never be used. */
11793 static const char *interface_config_auth_str(struct ospf_if_params
*params
)
11795 if (!OSPF_IF_PARAM_CONFIGURED(params
, auth_type
)
11796 || params
->auth_type
== OSPF_AUTH_NOTSET
)
11799 /* Translation tables are not that much help
11800 * here due to syntax
11801 * of the simple option */
11802 switch (params
->auth_type
) {
11804 case OSPF_AUTH_NULL
:
11807 case OSPF_AUTH_SIMPLE
:
11810 case OSPF_AUTH_CRYPTOGRAPHIC
:
11811 return " message-digest";
11817 static int config_write_interface_one(struct vty
*vty
, struct vrf
*vrf
)
11819 struct listnode
*node
;
11820 struct interface
*ifp
;
11821 struct crypt_key
*ck
;
11822 struct route_node
*rn
= NULL
;
11823 struct ospf_if_params
*params
;
11824 const char *auth_str
;
11827 FOR_ALL_INTERFACES (vrf
, ifp
) {
11829 if (memcmp(ifp
->name
, "VLINK", 5) == 0)
11832 if_vty_config_start(vty
, ifp
);
11835 vty_out(vty
, " description %s\n", ifp
->desc
);
11839 params
= IF_DEF_PARAMS(ifp
);
11842 /* Interface Network print. */
11843 if (OSPF_IF_PARAM_CONFIGURED(params
, type
)
11844 && params
->type
!= OSPF_IFTYPE_LOOPBACK
) {
11845 if (params
->type
!= ospf_default_iftype(ifp
)) {
11846 vty_out(vty
, " ip ospf network %s",
11850 == OSPF_IFTYPE_POINTOPOINT
11851 && params
->ptp_dmvpn
)
11852 vty_out(vty
, " dmvpn");
11853 if (params
->type
==
11854 OSPF_IFTYPE_POINTOMULTIPOINT
&&
11855 params
->p2mp_delay_reflood
)
11856 vty_out(vty
, " delay-reflood");
11857 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11858 vty_out(vty
, " %pI4",
11860 vty_out(vty
, "\n");
11864 /* OSPF interface authentication print */
11865 auth_str
= interface_config_auth_str(params
);
11867 vty_out(vty
, " ip ospf authentication%s",
11869 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11870 vty_out(vty
, " %pI4",
11872 vty_out(vty
, "\n");
11875 /* Simple Authentication Password print. */
11876 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_simple
)
11877 && params
->auth_simple
[0] != '\0') {
11878 vty_out(vty
, " ip ospf authentication-key %s",
11879 params
->auth_simple
);
11880 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11881 vty_out(vty
, " %pI4",
11883 vty_out(vty
, "\n");
11886 /* Cryptographic Authentication Key print. */
11887 if (params
&& params
->auth_crypt
) {
11888 for (ALL_LIST_ELEMENTS_RO(params
->auth_crypt
,
11891 " ip ospf message-digest-key %d md5 %s",
11892 ck
->key_id
, ck
->auth_key
);
11893 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11894 vty_out(vty
, " %pI4",
11896 vty_out(vty
, "\n");
11900 /* Interface Output Cost print. */
11901 if (OSPF_IF_PARAM_CONFIGURED(params
, output_cost_cmd
)) {
11902 vty_out(vty
, " ip ospf cost %u",
11903 params
->output_cost_cmd
);
11904 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11905 vty_out(vty
, " %pI4",
11907 vty_out(vty
, "\n");
11910 /* Hello Interval print. */
11911 if (OSPF_IF_PARAM_CONFIGURED(params
, v_hello
)
11912 && params
->v_hello
!= OSPF_HELLO_INTERVAL_DEFAULT
) {
11913 vty_out(vty
, " ip ospf hello-interval %u",
11915 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11916 vty_out(vty
, " %pI4",
11918 vty_out(vty
, "\n");
11922 /* Router Dead Interval print. */
11923 if (OSPF_IF_PARAM_CONFIGURED(params
, v_wait
)
11924 && params
->is_v_wait_set
) {
11925 vty_out(vty
, " ip ospf dead-interval ");
11928 if (OSPF_IF_PARAM_CONFIGURED(params
,
11931 "minimal hello-multiplier %d",
11932 params
->fast_hello
);
11934 vty_out(vty
, "%u", params
->v_wait
);
11936 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11937 vty_out(vty
, " %pI4",
11939 vty_out(vty
, "\n");
11942 /* Hello Graceful-Restart Delay print. */
11943 if (OSPF_IF_PARAM_CONFIGURED(params
,
11944 v_gr_hello_delay
) &&
11945 params
->v_gr_hello_delay
!=
11946 OSPF_HELLO_DELAY_DEFAULT
)
11948 " ip ospf graceful-restart hello-delay %u\n",
11949 params
->v_gr_hello_delay
);
11951 /* Router Priority print. */
11952 if (OSPF_IF_PARAM_CONFIGURED(params
, priority
)
11953 && params
->priority
11954 != OSPF_ROUTER_PRIORITY_DEFAULT
) {
11955 vty_out(vty
, " ip ospf priority %u",
11957 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11958 vty_out(vty
, " %pI4",
11960 vty_out(vty
, "\n");
11963 /* Retransmit Interval print. */
11964 if (OSPF_IF_PARAM_CONFIGURED(params
,
11965 retransmit_interval
)
11966 && params
->retransmit_interval
11967 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
) {
11968 vty_out(vty
, " ip ospf retransmit-interval %u",
11969 params
->retransmit_interval
);
11970 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11971 vty_out(vty
, " %pI4",
11973 vty_out(vty
, "\n");
11976 /* Transmit Delay print. */
11977 if (OSPF_IF_PARAM_CONFIGURED(params
, transmit_delay
)
11978 && params
->transmit_delay
11979 != OSPF_TRANSMIT_DELAY_DEFAULT
) {
11980 vty_out(vty
, " ip ospf transmit-delay %u",
11981 params
->transmit_delay
);
11982 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11983 vty_out(vty
, " %pI4",
11985 vty_out(vty
, "\n");
11989 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
11991 vty_out(vty
, " ip ospf %d",
11994 vty_out(vty
, " ip ospf");
11996 char buf
[INET_ADDRSTRLEN
];
11998 area_id2str(buf
, sizeof(buf
), ¶ms
->if_area
,
11999 params
->if_area_id_fmt
);
12000 vty_out(vty
, " area %s", buf
);
12001 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12002 vty_out(vty
, " %pI4",
12004 vty_out(vty
, "\n");
12008 if (params
&& params
->bfd_config
)
12009 ospf_bfd_write_config(vty
, params
);
12011 /* MTU ignore print. */
12012 if (OSPF_IF_PARAM_CONFIGURED(params
, mtu_ignore
)
12013 && params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
) {
12014 if (params
->mtu_ignore
== 0)
12015 vty_out(vty
, " no ip ospf mtu-ignore");
12017 vty_out(vty
, " ip ospf mtu-ignore");
12018 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12019 vty_out(vty
, " %pI4",
12021 vty_out(vty
, "\n");
12024 if (OSPF_IF_PARAM_CONFIGURED(params
,
12025 passive_interface
)) {
12026 vty_out(vty
, " %sip ospf passive",
12027 params
->passive_interface
12031 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12032 vty_out(vty
, " %pI4", &rn
->p
.u
.prefix4
);
12033 vty_out(vty
, "\n");
12036 /* LDP-Sync print */
12037 if (params
&& params
->ldp_sync_info
)
12038 ospf_ldp_sync_if_write_config(vty
, params
);
12042 rn
= route_top(IF_OIFS_PARAMS(ifp
));
12044 rn
= route_next(rn
);
12049 if (params
!= NULL
)
12054 ospf_opaque_config_write_if(vty
, ifp
);
12056 if_vty_config_end(vty
);
12062 /* Configuration write function for ospfd. */
12063 static int config_write_interface(struct vty
*vty
)
12066 struct vrf
*vrf
= NULL
;
12068 /* Display all VRF aware OSPF interface configuration */
12069 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
12070 write
+= config_write_interface_one(vty
, vrf
);
12076 static int config_write_network_area(struct vty
*vty
, struct ospf
*ospf
)
12078 struct route_node
*rn
;
12079 char buf
[INET_ADDRSTRLEN
];
12081 /* `network area' print. */
12082 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
))
12084 struct ospf_network
*n
= rn
->info
;
12086 /* Create Area ID string by specified Area ID format. */
12087 if (n
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
12088 inet_ntop(AF_INET
, &n
->area_id
, buf
,
12091 snprintf(buf
, sizeof(buf
), "%lu",
12092 (unsigned long int)ntohl(
12093 n
->area_id
.s_addr
));
12095 /* Network print. */
12096 vty_out(vty
, " network %pFX area %s\n", &rn
->p
, buf
);
12102 static int config_write_ospf_area(struct vty
*vty
, struct ospf
*ospf
)
12104 struct listnode
*node
;
12105 struct ospf_area
*area
;
12106 char buf
[INET_ADDRSTRLEN
];
12108 /* Area configuration print. */
12109 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
12110 struct route_node
*rn1
;
12112 area_id2str(buf
, sizeof(buf
), &area
->area_id
,
12113 area
->area_id_fmt
);
12115 if (area
->auth_type
!= OSPF_AUTH_NULL
) {
12116 if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
12117 vty_out(vty
, " area %s authentication\n", buf
);
12120 " area %s authentication message-digest\n",
12124 if (area
->shortcut_configured
!= OSPF_SHORTCUT_DEFAULT
)
12125 vty_out(vty
, " area %s shortcut %s\n", buf
,
12126 ospf_shortcut_mode_str
12127 [area
->shortcut_configured
]);
12129 if ((area
->external_routing
== OSPF_AREA_STUB
)
12130 || (area
->external_routing
== OSPF_AREA_NSSA
)) {
12131 if (area
->external_routing
== OSPF_AREA_STUB
) {
12132 vty_out(vty
, " area %s stub", buf
);
12133 if (area
->no_summary
)
12134 vty_out(vty
, " no-summary\n");
12135 vty_out(vty
, "\n");
12136 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
12137 vty_out(vty
, " area %s nssa", buf
);
12139 switch (area
->NSSATranslatorRole
) {
12140 case OSPF_NSSA_ROLE_NEVER
:
12141 vty_out(vty
, " translate-never");
12143 case OSPF_NSSA_ROLE_ALWAYS
:
12144 vty_out(vty
, " translate-always");
12146 case OSPF_NSSA_ROLE_CANDIDATE
:
12150 if (area
->nssa_default_originate
.enabled
) {
12152 " default-information-originate");
12153 if (area
->nssa_default_originate
12154 .metric_value
!= -1)
12155 vty_out(vty
, " metric %d",
12156 area
->nssa_default_originate
12158 if (area
->nssa_default_originate
12160 DEFAULT_METRIC_TYPE
)
12161 vty_out(vty
, " metric-type 1");
12164 if (area
->no_summary
)
12165 vty_out(vty
, " no-summary");
12166 if (area
->suppress_fa
)
12167 vty_out(vty
, " suppress-fa");
12168 vty_out(vty
, "\n");
12170 for (rn1
= route_top(area
->nssa_ranges
); rn1
;
12171 rn1
= route_next(rn1
)) {
12172 struct ospf_area_range
*range
;
12178 vty_out(vty
, " area %s nssa range %pFX",
12181 if (range
->cost_config
!=
12182 OSPF_AREA_RANGE_COST_UNSPEC
)
12183 vty_out(vty
, " cost %u",
12184 range
->cost_config
);
12188 OSPF_AREA_RANGE_ADVERTISE
))
12189 vty_out(vty
, " not-advertise");
12191 vty_out(vty
, "\n");
12195 if (area
->default_cost
!= 1)
12196 vty_out(vty
, " area %s default-cost %d\n", buf
,
12197 area
->default_cost
);
12200 for (rn1
= route_top(area
->ranges
); rn1
; rn1
= route_next(rn1
))
12202 struct ospf_area_range
*range
= rn1
->info
;
12204 vty_out(vty
, " area %s range %pFX", buf
,
12207 if (range
->cost_config
12208 != OSPF_AREA_RANGE_COST_UNSPEC
)
12209 vty_out(vty
, " cost %d",
12210 range
->cost_config
);
12212 if (!CHECK_FLAG(range
->flags
,
12213 OSPF_AREA_RANGE_ADVERTISE
))
12214 vty_out(vty
, " not-advertise");
12216 if (CHECK_FLAG(range
->flags
,
12217 OSPF_AREA_RANGE_SUBSTITUTE
))
12218 vty_out(vty
, " substitute %pI4/%d",
12219 &range
->subst_addr
,
12220 range
->subst_masklen
);
12222 vty_out(vty
, "\n");
12225 if (EXPORT_NAME(area
))
12226 vty_out(vty
, " area %s export-list %s\n", buf
,
12227 EXPORT_NAME(area
));
12229 if (IMPORT_NAME(area
))
12230 vty_out(vty
, " area %s import-list %s\n", buf
,
12231 IMPORT_NAME(area
));
12233 if (PREFIX_NAME_IN(area
))
12234 vty_out(vty
, " area %s filter-list prefix %s in\n", buf
,
12235 PREFIX_NAME_IN(area
));
12237 if (PREFIX_NAME_OUT(area
))
12238 vty_out(vty
, " area %s filter-list prefix %s out\n",
12239 buf
, PREFIX_NAME_OUT(area
));
12241 if (area
->fr_info
.configured
)
12242 vty_out(vty
, " area %s flood-reduction\n", buf
);
12248 static int config_write_ospf_nbr_nbma(struct vty
*vty
, struct ospf
*ospf
)
12250 struct ospf_nbr_nbma
*nbr_nbma
;
12251 struct route_node
*rn
;
12253 /* Static Neighbor configuration print. */
12254 for (rn
= route_top(ospf
->nbr_nbma
); rn
; rn
= route_next(rn
))
12255 if ((nbr_nbma
= rn
->info
)) {
12256 vty_out(vty
, " neighbor %pI4", &nbr_nbma
->addr
);
12258 if (nbr_nbma
->priority
12259 != OSPF_NEIGHBOR_PRIORITY_DEFAULT
)
12260 vty_out(vty
, " priority %d",
12261 nbr_nbma
->priority
);
12263 if (nbr_nbma
->v_poll
!= OSPF_POLL_INTERVAL_DEFAULT
)
12264 vty_out(vty
, " poll-interval %d",
12267 vty_out(vty
, "\n");
12273 static int config_write_virtual_link(struct vty
*vty
, struct ospf
*ospf
)
12275 struct listnode
*node
;
12276 struct ospf_vl_data
*vl_data
;
12277 const char *auth_str
;
12278 char buf
[INET_ADDRSTRLEN
];
12280 /* Virtual-Link print */
12281 for (ALL_LIST_ELEMENTS_RO(ospf
->vlinks
, node
, vl_data
)) {
12282 struct listnode
*n2
;
12283 struct crypt_key
*ck
;
12284 struct ospf_interface
*oi
;
12286 if (vl_data
!= NULL
) {
12287 area_id2str(buf
, sizeof(buf
), &vl_data
->vl_area_id
,
12288 vl_data
->vl_area_id_fmt
);
12289 oi
= vl_data
->vl_oi
;
12292 if (OSPF_IF_PARAM(oi
, v_hello
)
12293 != OSPF_HELLO_INTERVAL_DEFAULT
12294 || OSPF_IF_PARAM(oi
, v_wait
)
12295 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
12296 || OSPF_IF_PARAM(oi
, retransmit_interval
)
12297 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
12298 || OSPF_IF_PARAM(oi
, transmit_delay
)
12299 != OSPF_TRANSMIT_DELAY_DEFAULT
)
12301 " area %s virtual-link %pI4 hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n",
12302 buf
, &vl_data
->vl_peer
,
12303 OSPF_IF_PARAM(oi
, v_hello
),
12304 OSPF_IF_PARAM(oi
, retransmit_interval
),
12305 OSPF_IF_PARAM(oi
, transmit_delay
),
12306 OSPF_IF_PARAM(oi
, v_wait
));
12308 vty_out(vty
, " area %s virtual-link %pI4\n", buf
,
12309 &vl_data
->vl_peer
);
12311 auth_str
= interface_config_auth_str(
12312 IF_DEF_PARAMS(oi
->ifp
));
12315 " area %s virtual-link %pI4 authentication%s\n",
12316 buf
, &vl_data
->vl_peer
, auth_str
);
12318 if (IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)->auth_simple
[0]
12321 " area %s virtual-link %pI4 authentication-key %s\n",
12322 buf
, &vl_data
->vl_peer
,
12323 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
12326 for (ALL_LIST_ELEMENTS_RO(
12327 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
12331 " area %s virtual-link %pI4 message-digest-key %d md5 %s\n",
12332 buf
, &vl_data
->vl_peer
,
12333 ck
->key_id
, ck
->auth_key
);
12341 static int config_write_ospf_redistribute(struct vty
*vty
, struct ospf
*ospf
)
12345 /* redistribute print. */
12346 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
12347 struct list
*red_list
;
12348 struct listnode
*node
;
12349 struct ospf_redist
*red
;
12351 red_list
= ospf
->redist
[type
];
12355 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
12356 vty_out(vty
, " redistribute %s",
12357 zebra_route_string(type
));
12359 vty_out(vty
, " %d", red
->instance
);
12361 if (red
->dmetric
.value
>= 0)
12362 vty_out(vty
, " metric %d", red
->dmetric
.value
);
12364 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
12365 vty_out(vty
, " metric-type 1");
12367 if (ROUTEMAP_NAME(red
))
12368 vty_out(vty
, " route-map %s",
12369 ROUTEMAP_NAME(red
));
12371 vty_out(vty
, "\n");
12378 static int ospf_cfg_write_helper_dis_rtr_walkcb(struct hash_bucket
*bucket
,
12381 struct advRtr
*rtr
= bucket
->data
;
12382 struct vty
*vty
= (struct vty
*)arg
;
12384 vty_out(vty
, " graceful-restart helper enable %pI4\n",
12386 return HASHWALK_CONTINUE
;
12389 static void config_write_ospf_gr(struct vty
*vty
, struct ospf
*ospf
)
12391 if (!ospf
->gr_info
.restart_support
)
12394 if (ospf
->gr_info
.grace_period
== OSPF_DFLT_GRACE_INTERVAL
)
12395 vty_out(vty
, " graceful-restart\n");
12397 vty_out(vty
, " graceful-restart grace-period %u\n",
12398 ospf
->gr_info
.grace_period
);
12401 static int config_write_ospf_gr_helper(struct vty
*vty
, struct ospf
*ospf
)
12403 if (ospf
->is_helper_supported
)
12404 vty_out(vty
, " graceful-restart helper enable\n");
12406 if (!ospf
->strict_lsa_check
)
12408 " no graceful-restart helper strict-lsa-checking\n");
12410 if (ospf
->only_planned_restart
)
12411 vty_out(vty
, " graceful-restart helper planned-only\n");
12413 if (ospf
->supported_grace_time
!= OSPF_MAX_GRACE_INTERVAL
)
12415 " graceful-restart helper supported-grace-time %d\n",
12416 ospf
->supported_grace_time
);
12418 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf
)) {
12419 hash_walk(ospf
->enable_rtr_list
,
12420 ospf_cfg_write_helper_dis_rtr_walkcb
, vty
);
12425 static int config_write_ospf_external_aggregator(struct vty
*vty
,
12428 struct route_node
*rn
;
12430 if (ospf
->aggr_delay_interval
!= OSPF_EXTL_AGGR_DEFAULT_DELAY
)
12431 vty_out(vty
, " aggregation timer %u\n",
12432 ospf
->aggr_delay_interval
);
12434 /* print 'summary-address A.B.C.D/M' */
12435 for (rn
= route_top(ospf
->rt_aggr_tbl
); rn
; rn
= route_next(rn
))
12437 struct ospf_external_aggr_rt
*aggr
= rn
->info
;
12439 vty_out(vty
, " summary-address %pI4/%d",
12440 &aggr
->p
.prefix
, aggr
->p
.prefixlen
);
12442 vty_out(vty
, " tag %u", aggr
->tag
);
12444 if (CHECK_FLAG(aggr
->flags
,
12445 OSPF_EXTERNAL_AGGRT_NO_ADVERTISE
))
12446 vty_out(vty
, " no-advertise");
12448 vty_out(vty
, "\n");
12454 static int config_write_ospf_default_metric(struct vty
*vty
, struct ospf
*ospf
)
12456 if (ospf
->default_metric
!= -1)
12457 vty_out(vty
, " default-metric %d\n", ospf
->default_metric
);
12461 static int config_write_ospf_distribute(struct vty
*vty
, struct ospf
*ospf
)
12464 struct ospf_redist
*red
;
12467 /* distribute-list print. */
12468 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
12469 if (DISTRIBUTE_NAME(ospf
, type
))
12470 vty_out(vty
, " distribute-list %s out %s\n",
12471 DISTRIBUTE_NAME(ospf
, type
),
12472 zebra_route_string(type
));
12474 /* default-information print. */
12475 if (ospf
->default_originate
!= DEFAULT_ORIGINATE_NONE
) {
12476 vty_out(vty
, " default-information originate");
12477 if (ospf
->default_originate
== DEFAULT_ORIGINATE_ALWAYS
)
12478 vty_out(vty
, " always");
12480 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
12482 if (red
->dmetric
.value
>= 0)
12483 vty_out(vty
, " metric %d",
12484 red
->dmetric
.value
);
12486 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
12487 vty_out(vty
, " metric-type 1");
12489 if (ROUTEMAP_NAME(red
))
12490 vty_out(vty
, " route-map %s",
12491 ROUTEMAP_NAME(red
));
12494 vty_out(vty
, "\n");
12501 static int config_write_ospf_distance(struct vty
*vty
, struct ospf
*ospf
)
12503 struct route_node
*rn
;
12504 struct ospf_distance
*odistance
;
12506 if (ospf
->distance_all
)
12507 vty_out(vty
, " distance %d\n", ospf
->distance_all
);
12509 if (ospf
->distance_intra
|| ospf
->distance_inter
12510 || ospf
->distance_external
) {
12511 vty_out(vty
, " distance ospf");
12513 if (ospf
->distance_intra
)
12514 vty_out(vty
, " intra-area %d", ospf
->distance_intra
);
12515 if (ospf
->distance_inter
)
12516 vty_out(vty
, " inter-area %d", ospf
->distance_inter
);
12517 if (ospf
->distance_external
)
12518 vty_out(vty
, " external %d", ospf
->distance_external
);
12520 vty_out(vty
, "\n");
12523 for (rn
= route_top(ospf
->distance_table
); rn
; rn
= route_next(rn
))
12524 if ((odistance
= rn
->info
) != NULL
) {
12525 vty_out(vty
, " distance %d %pFX %s\n",
12526 odistance
->distance
, &rn
->p
,
12527 odistance
->access_list
? odistance
->access_list
12533 static int ospf_config_write_one(struct vty
*vty
, struct ospf
*ospf
)
12537 /* `router ospf' print. */
12538 if (ospf
->instance
&& strcmp(ospf
->name
, VRF_DEFAULT_NAME
)) {
12539 vty_out(vty
, "router ospf %d vrf %s\n", ospf
->instance
,
12541 } else if (ospf
->instance
) {
12542 vty_out(vty
, "router ospf %d\n", ospf
->instance
);
12543 } else if (strcmp(ospf
->name
, VRF_DEFAULT_NAME
)) {
12544 vty_out(vty
, "router ospf vrf %s\n", ospf
->name
);
12546 vty_out(vty
, "router ospf\n");
12548 if (!ospf
->networks
) {
12553 /* Router ID print. */
12554 if (ospf
->router_id_static
.s_addr
!= INADDR_ANY
)
12555 vty_out(vty
, " ospf router-id %pI4\n",
12556 &ospf
->router_id_static
);
12558 /* zebra opaque attributes configuration. */
12559 if (CHECK_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
))
12560 vty_out(vty
, " ospf send-extra-data zebra\n");
12562 /* ABR type print. */
12563 if (ospf
->abr_type
!= OSPF_ABR_DEFAULT
)
12564 vty_out(vty
, " ospf abr-type %s\n",
12565 ospf_abr_type_str
[ospf
->abr_type
]);
12567 /* log-adjacency-changes flag print. */
12568 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
12569 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
))
12570 vty_out(vty
, " log-adjacency-changes detail\n");
12571 else if (!SAVE_OSPF_LOG_ADJACENCY_CHANGES
)
12572 vty_out(vty
, " log-adjacency-changes\n");
12573 } else if (SAVE_OSPF_LOG_ADJACENCY_CHANGES
) {
12574 vty_out(vty
, " no log-adjacency-changes\n");
12577 /* RFC1583 compatibility flag print -- Compatible with CISCO
12579 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
))
12580 vty_out(vty
, " compatible rfc1583\n");
12582 /* auto-cost reference-bandwidth configuration. */
12583 if (ospf
->ref_bandwidth
!= OSPF_DEFAULT_REF_BANDWIDTH
) {
12585 "! Important: ensure reference bandwidth is consistent across all routers\n");
12586 vty_out(vty
, " auto-cost reference-bandwidth %d\n",
12587 ospf
->ref_bandwidth
);
12590 /* SPF timers print. */
12591 if (ospf
->spf_delay
!= OSPF_SPF_DELAY_DEFAULT
12592 || ospf
->spf_holdtime
!= OSPF_SPF_HOLDTIME_DEFAULT
12593 || ospf
->spf_max_holdtime
!= OSPF_SPF_MAX_HOLDTIME_DEFAULT
)
12594 vty_out(vty
, " timers throttle spf %d %d %d\n", ospf
->spf_delay
,
12595 ospf
->spf_holdtime
, ospf
->spf_max_holdtime
);
12597 /* LSA timers print. */
12598 if (ospf
->min_ls_interval
!= OSPF_MIN_LS_INTERVAL
)
12599 vty_out(vty
, " timers throttle lsa all %d\n",
12600 ospf
->min_ls_interval
);
12601 if (ospf
->min_ls_arrival
!= OSPF_MIN_LS_ARRIVAL
)
12602 vty_out(vty
, " timers lsa min-arrival %d\n",
12603 ospf
->min_ls_arrival
);
12605 /* Write multiplier print. */
12606 if (ospf
->write_oi_count
!= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
)
12607 vty_out(vty
, " ospf write-multiplier %d\n",
12608 ospf
->write_oi_count
);
12610 if (ospf
->max_multipath
!= MULTIPATH_NUM
)
12611 vty_out(vty
, " maximum-paths %d\n", ospf
->max_multipath
);
12613 /* Max-metric router-lsa print */
12614 config_write_stub_router(vty
, ospf
);
12616 /* SPF refresh parameters print. */
12617 if (ospf
->lsa_refresh_interval
!= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
12618 vty_out(vty
, " refresh timer %d\n", ospf
->lsa_refresh_interval
);
12620 if (ospf
->fr_configured
)
12621 vty_out(vty
, " flood-reduction\n");
12623 if (!ospf
->intf_socket_enabled
)
12624 vty_out(vty
, " no socket-per-interface\n");
12626 /* Redistribute information print. */
12627 config_write_ospf_redistribute(vty
, ospf
);
12629 /* Graceful Restart print */
12630 config_write_ospf_gr(vty
, ospf
);
12631 config_write_ospf_gr_helper(vty
, ospf
);
12633 /* Print external route aggregation. */
12634 config_write_ospf_external_aggregator(vty
, ospf
);
12636 /* passive-interface print. */
12637 if (ospf
->passive_interface_default
== OSPF_IF_PASSIVE
)
12638 vty_out(vty
, " passive-interface default\n");
12640 /* proactive-arp print. */
12641 if (ospf
->proactive_arp
!= OSPF_PROACTIVE_ARP_DEFAULT
) {
12642 if (ospf
->proactive_arp
)
12643 vty_out(vty
, " proactive-arp\n");
12645 vty_out(vty
, " no proactive-arp\n");
12648 /* TI-LFA print. */
12649 if (ospf
->ti_lfa_enabled
) {
12650 if (ospf
->ti_lfa_protection_type
== OSPF_TI_LFA_NODE_PROTECTION
)
12651 vty_out(vty
, " fast-reroute ti-lfa node-protection\n");
12653 vty_out(vty
, " fast-reroute ti-lfa\n");
12656 /* Network area print. */
12657 config_write_network_area(vty
, ospf
);
12659 /* Area config print. */
12660 config_write_ospf_area(vty
, ospf
);
12662 /* static neighbor print. */
12663 config_write_ospf_nbr_nbma(vty
, ospf
);
12665 /* Virtual-Link print. */
12666 config_write_virtual_link(vty
, ospf
);
12668 /* Default metric configuration. */
12669 config_write_ospf_default_metric(vty
, ospf
);
12671 /* Distribute-list and default-information print. */
12672 config_write_ospf_distribute(vty
, ospf
);
12674 /* Distance configuration. */
12675 config_write_ospf_distance(vty
, ospf
);
12677 ospf_opaque_config_write_router(vty
, ospf
);
12679 /* LDP-Sync print */
12680 ospf_ldp_sync_write_config(vty
, ospf
);
12682 /* Socket buffer sizes */
12683 if (ospf
->recv_sock_bufsize
!= OSPF_DEFAULT_SOCK_BUFSIZE
) {
12684 if (ospf
->send_sock_bufsize
== ospf
->recv_sock_bufsize
)
12685 vty_out(vty
, " socket buffer all %u\n",
12686 ospf
->recv_sock_bufsize
);
12688 vty_out(vty
, " socket buffer recv %u\n",
12689 ospf
->recv_sock_bufsize
);
12692 if (ospf
->send_sock_bufsize
!= OSPF_DEFAULT_SOCK_BUFSIZE
&&
12693 ospf
->send_sock_bufsize
!= ospf
->recv_sock_bufsize
)
12694 vty_out(vty
, " socket buffer send %u\n",
12695 ospf
->send_sock_bufsize
);
12698 vty_out(vty
, "exit\n");
12704 /* OSPF configuration write function. */
12705 static int ospf_config_write(struct vty
*vty
)
12708 struct listnode
*ospf_node
= NULL
;
12711 if (listcount(om
->ospf
) == 0)
12714 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, ospf_node
, ospf
)) {
12715 /* VRF Default check if it is running.
12716 * Upon daemon start, there could be default instance
12717 * in absence of 'router ospf'/oi_running is disabled. */
12718 if (ospf
->vrf_id
== VRF_DEFAULT
&& ospf
->oi_running
)
12719 write
+= ospf_config_write_one(vty
, ospf
);
12720 /* For Non-Default VRF simply display the configuration,
12721 * even if it is not oi_running. */
12722 else if (ospf
->vrf_id
!= VRF_DEFAULT
)
12723 write
+= ospf_config_write_one(vty
, ospf
);
12728 void ospf_vty_show_init(void)
12730 /* "show ip ospf" commands. */
12731 install_element(VIEW_NODE
, &show_ip_ospf_cmd
);
12733 install_element(VIEW_NODE
, &show_ip_ospf_instance_cmd
);
12735 /* "show ip ospf database" commands. */
12736 install_element(VIEW_NODE
, &show_ip_ospf_database_cmd
);
12738 /* "show ip ospf interface" commands. */
12739 install_element(VIEW_NODE
, &show_ip_ospf_interface_cmd
);
12741 install_element(VIEW_NODE
, &show_ip_ospf_instance_interface_cmd
);
12742 /* "show ip ospf interface traffic */
12743 install_element(VIEW_NODE
, &show_ip_ospf_interface_traffic_cmd
);
12745 /* "show ip ospf neighbor" commands. */
12746 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_detail_cmd
);
12747 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_cmd
);
12748 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_id_cmd
);
12749 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_all_cmd
);
12750 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_cmd
);
12751 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_cmd
);
12752 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_all_cmd
);
12754 install_element(VIEW_NODE
,
12755 &show_ip_ospf_instance_neighbor_int_detail_cmd
);
12756 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_int_cmd
);
12757 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_id_cmd
);
12758 install_element(VIEW_NODE
,
12759 &show_ip_ospf_instance_neighbor_detail_all_cmd
);
12760 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_detail_cmd
);
12761 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_cmd
);
12762 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_all_cmd
);
12764 /* "show ip ospf route" commands. */
12765 install_element(VIEW_NODE
, &show_ip_ospf_route_cmd
);
12766 install_element(VIEW_NODE
, &show_ip_ospf_border_routers_cmd
);
12767 install_element(VIEW_NODE
, &show_ip_ospf_reachable_routers_cmd
);
12769 install_element(VIEW_NODE
, &show_ip_ospf_instance_route_cmd
);
12770 install_element(VIEW_NODE
, &show_ip_ospf_instance_border_routers_cmd
);
12771 install_element(VIEW_NODE
,
12772 &show_ip_ospf_instance_reachable_routers_cmd
);
12774 /* "show ip ospf vrfs" commands. */
12775 install_element(VIEW_NODE
, &show_ip_ospf_vrfs_cmd
);
12777 /* "show ip ospf gr-helper details" command */
12778 install_element(VIEW_NODE
, &show_ip_ospf_gr_helper_cmd
);
12780 /* "show ip ospf summary-address" command */
12781 install_element(VIEW_NODE
, &show_ip_ospf_external_aggregator_cmd
);
12784 /* Initialization of OSPF interface. */
12785 static void ospf_vty_if_init(void)
12787 /* Install interface node. */
12788 if_cmd_init(config_write_interface
);
12790 /* "ip ospf authentication" commands. */
12791 install_element(INTERFACE_NODE
, &ip_ospf_authentication_args_addr_cmd
);
12792 install_element(INTERFACE_NODE
, &ip_ospf_authentication_addr_cmd
);
12793 install_element(INTERFACE_NODE
,
12794 &no_ip_ospf_authentication_args_addr_cmd
);
12795 install_element(INTERFACE_NODE
, &no_ip_ospf_authentication_addr_cmd
);
12796 install_element(INTERFACE_NODE
, &ip_ospf_authentication_key_addr_cmd
);
12797 install_element(INTERFACE_NODE
,
12798 &no_ip_ospf_authentication_key_authkey_addr_cmd
);
12799 install_element(INTERFACE_NODE
,
12800 &no_ospf_authentication_key_authkey_addr_cmd
);
12802 /* "ip ospf message-digest-key" commands. */
12803 install_element(INTERFACE_NODE
, &ip_ospf_message_digest_key_cmd
);
12804 install_element(INTERFACE_NODE
, &no_ip_ospf_message_digest_key_cmd
);
12806 /* "ip ospf cost" commands. */
12807 install_element(INTERFACE_NODE
, &ip_ospf_cost_cmd
);
12808 install_element(INTERFACE_NODE
, &no_ip_ospf_cost_cmd
);
12810 /* "ip ospf mtu-ignore" commands. */
12811 install_element(INTERFACE_NODE
, &ip_ospf_mtu_ignore_addr_cmd
);
12812 install_element(INTERFACE_NODE
, &no_ip_ospf_mtu_ignore_addr_cmd
);
12814 /* "ip ospf dead-interval" commands. */
12815 install_element(INTERFACE_NODE
, &ip_ospf_dead_interval_cmd
);
12816 install_element(INTERFACE_NODE
,
12817 &ip_ospf_dead_interval_minimal_addr_cmd
);
12818 install_element(INTERFACE_NODE
, &no_ip_ospf_dead_interval_cmd
);
12820 /* "ip ospf hello-interval" commands. */
12821 install_element(INTERFACE_NODE
, &ip_ospf_hello_interval_cmd
);
12822 install_element(INTERFACE_NODE
, &no_ip_ospf_hello_interval_cmd
);
12824 /* "ip ospf network" commands. */
12825 install_element(INTERFACE_NODE
, &ip_ospf_network_cmd
);
12826 install_element(INTERFACE_NODE
, &no_ip_ospf_network_cmd
);
12828 /* "ip ospf priority" commands. */
12829 install_element(INTERFACE_NODE
, &ip_ospf_priority_cmd
);
12830 install_element(INTERFACE_NODE
, &no_ip_ospf_priority_cmd
);
12832 /* "ip ospf retransmit-interval" commands. */
12833 install_element(INTERFACE_NODE
, &ip_ospf_retransmit_interval_addr_cmd
);
12834 install_element(INTERFACE_NODE
,
12835 &no_ip_ospf_retransmit_interval_addr_cmd
);
12837 /* "ip ospf transmit-delay" commands. */
12838 install_element(INTERFACE_NODE
, &ip_ospf_transmit_delay_addr_cmd
);
12839 install_element(INTERFACE_NODE
, &no_ip_ospf_transmit_delay_addr_cmd
);
12841 /* "ip ospf area" commands. */
12842 install_element(INTERFACE_NODE
, &ip_ospf_area_cmd
);
12843 install_element(INTERFACE_NODE
, &no_ip_ospf_area_cmd
);
12845 /* "ip ospf passive" commands. */
12846 install_element(INTERFACE_NODE
, &ip_ospf_passive_cmd
);
12847 install_element(INTERFACE_NODE
, &no_ip_ospf_passive_cmd
);
12849 /* These commands are compatibitliy for previous version. */
12850 install_element(INTERFACE_NODE
, &ospf_authentication_key_cmd
);
12851 install_element(INTERFACE_NODE
, &ospf_message_digest_key_cmd
);
12852 install_element(INTERFACE_NODE
, &no_ospf_message_digest_key_cmd
);
12853 install_element(INTERFACE_NODE
, &ospf_dead_interval_cmd
);
12854 install_element(INTERFACE_NODE
, &no_ospf_dead_interval_cmd
);
12855 install_element(INTERFACE_NODE
, &ospf_hello_interval_cmd
);
12856 install_element(INTERFACE_NODE
, &no_ospf_hello_interval_cmd
);
12857 install_element(INTERFACE_NODE
, &ospf_cost_cmd
);
12858 install_element(INTERFACE_NODE
, &no_ospf_cost_cmd
);
12859 install_element(INTERFACE_NODE
, &ospf_network_cmd
);
12860 install_element(INTERFACE_NODE
, &no_ospf_network_cmd
);
12861 install_element(INTERFACE_NODE
, &ospf_priority_cmd
);
12862 install_element(INTERFACE_NODE
, &no_ospf_priority_cmd
);
12863 install_element(INTERFACE_NODE
, &ospf_retransmit_interval_cmd
);
12864 install_element(INTERFACE_NODE
, &no_ospf_retransmit_interval_cmd
);
12865 install_element(INTERFACE_NODE
, &ospf_transmit_delay_cmd
);
12866 install_element(INTERFACE_NODE
, &no_ospf_transmit_delay_cmd
);
12869 static void ospf_vty_zebra_init(void)
12871 install_element(OSPF_NODE
, &ospf_redistribute_source_cmd
);
12872 install_element(OSPF_NODE
, &no_ospf_redistribute_source_cmd
);
12873 install_element(OSPF_NODE
, &ospf_redistribute_instance_source_cmd
);
12874 install_element(OSPF_NODE
, &no_ospf_redistribute_instance_source_cmd
);
12876 install_element(OSPF_NODE
, &ospf_distribute_list_out_cmd
);
12877 install_element(OSPF_NODE
, &no_ospf_distribute_list_out_cmd
);
12879 install_element(OSPF_NODE
, &ospf_default_information_originate_cmd
);
12880 install_element(OSPF_NODE
, &no_ospf_default_information_originate_cmd
);
12882 install_element(OSPF_NODE
, &ospf_default_metric_cmd
);
12883 install_element(OSPF_NODE
, &no_ospf_default_metric_cmd
);
12885 install_element(OSPF_NODE
, &ospf_distance_cmd
);
12886 install_element(OSPF_NODE
, &no_ospf_distance_cmd
);
12887 install_element(OSPF_NODE
, &no_ospf_distance_ospf_cmd
);
12888 install_element(OSPF_NODE
, &ospf_distance_ospf_cmd
);
12890 /*Ospf garcefull restart helper configurations */
12891 install_element(OSPF_NODE
, &ospf_gr_helper_enable_cmd
);
12892 install_element(OSPF_NODE
, &no_ospf_gr_helper_enable_cmd
);
12893 install_element(OSPF_NODE
, &ospf_gr_helper_enable_lsacheck_cmd
);
12894 install_element(OSPF_NODE
, &no_ospf_gr_helper_enable_lsacheck_cmd
);
12895 install_element(OSPF_NODE
, &ospf_gr_helper_supported_grace_time_cmd
);
12896 install_element(OSPF_NODE
, &no_ospf_gr_helper_supported_grace_time_cmd
);
12897 install_element(OSPF_NODE
, &ospf_gr_helper_planned_only_cmd
);
12898 install_element(OSPF_NODE
, &no_ospf_gr_helper_planned_only_cmd
);
12900 /* External LSA summarisation config commands.*/
12901 install_element(OSPF_NODE
, &ospf_external_route_aggregation_cmd
);
12902 install_element(OSPF_NODE
, &no_ospf_external_route_aggregation_cmd
);
12903 install_element(OSPF_NODE
,
12904 &ospf_external_route_aggregation_no_adrvertise_cmd
);
12905 install_element(OSPF_NODE
,
12906 &no_ospf_external_route_aggregation_no_adrvertise_cmd
);
12907 install_element(OSPF_NODE
, &ospf_route_aggregation_timer_cmd
);
12908 install_element(OSPF_NODE
, &no_ospf_route_aggregation_timer_cmd
);
12911 static int ospf_config_write(struct vty
*vty
);
12912 static struct cmd_node ospf_node
= {
12915 .parent_node
= CONFIG_NODE
,
12916 .prompt
= "%s(config-router)# ",
12917 .config_write
= ospf_config_write
,
12920 static void ospf_interface_clear(struct interface
*ifp
)
12922 if (!if_is_operative(ifp
))
12925 if (IS_DEBUG_OSPF(ism
, ISM_EVENTS
))
12926 zlog_debug("ISM[%s]: clear by reset", ifp
->name
);
12928 ospf_if_reset(ifp
);
12931 DEFUN (clear_ip_ospf_interface
,
12932 clear_ip_ospf_interface_cmd
,
12933 "clear ip ospf [vrf NAME] interface [IFNAME]",
12936 "OSPF information\n"
12938 "Interface information\n"
12939 "Interface name\n")
12941 int idx_ifname
= 0;
12943 struct interface
*ifp
;
12944 struct listnode
*node
;
12945 struct ospf
*ospf
= NULL
;
12946 char *vrf_name
= NULL
;
12947 vrf_id_t vrf_id
= VRF_DEFAULT
;
12948 struct vrf
*vrf
= NULL
;
12950 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
12951 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
12952 if (vrf_name
&& strmatch(vrf_name
, VRF_DEFAULT_NAME
))
12955 vrf
= vrf_lookup_by_name(vrf_name
);
12957 vrf_id
= vrf
->vrf_id
;
12959 if (!argv_find(argv
, argc
, "IFNAME", &idx_ifname
)) {
12960 /* Clear all the ospfv2 interfaces. */
12961 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
12962 if (vrf_id
!= ospf
->vrf_id
)
12965 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
12966 FOR_ALL_INTERFACES (vrf
, ifp
)
12967 ospf_interface_clear(ifp
);
12970 /* Interface name is specified. */
12971 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf_id
);
12973 vty_out(vty
, "No such interface name\n");
12975 ospf_interface_clear(ifp
);
12978 return CMD_SUCCESS
;
12981 DEFPY_HIDDEN(ospf_lsa_refresh_timer
, ospf_lsa_refresh_timer_cmd
,
12982 "[no$no] ospf lsa-refresh [(120-1800)]$value",
12984 "OSPF lsa refresh timer\n"
12985 "timer value in seconds\n")
12987 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
12990 ospf
->lsa_refresh_timer
= OSPF_LS_REFRESH_TIME
;
12992 ospf
->lsa_refresh_timer
= value
;
12994 return CMD_SUCCESS
;
12997 DEFPY_HIDDEN(ospf_maxage_delay_timer
, ospf_maxage_delay_timer_cmd
,
12998 "[no$no] ospf maxage-delay [(0-60)]$value",
13000 "OSPF lsa maxage delay timer\n"
13001 "timer value in seconds\n")
13003 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
13006 ospf
->maxage_delay
= OSPF_LSA_MAXAGE_REMOVE_DELAY_DEFAULT
;
13008 ospf
->maxage_delay
= value
;
13010 EVENT_OFF(ospf
->t_maxage
);
13011 OSPF_TIMER_ON(ospf
->t_maxage
, ospf_maxage_lsa_remover
,
13012 ospf
->maxage_delay
);
13014 return CMD_SUCCESS
;
13018 * ------------------------------------------------------------------------*
13019 * Following is (vty) configuration functions for flood-reduction handling.
13020 * ------------------------------------------------------------------------
13023 DEFPY(flood_reduction
, flood_reduction_cmd
, "flood-reduction",
13024 "flood reduction feature\n")
13026 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
13027 struct ospf_area
*area
;
13028 struct listnode
*node
;
13030 /* Turn on the Flood Reduction feature for the router. */
13031 if (!ospf
->fr_configured
) {
13032 ospf
->fr_configured
= true;
13033 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT
,
13034 "Flood Reduction: OFF -> ON");
13035 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
13037 ospf_area_update_fr_state(area
);
13038 ospf_refresh_area_self_lsas(area
);
13043 return CMD_SUCCESS
;
13046 DEFPY(flood_reduction_area
, flood_reduction_area_cmd
,
13047 "area <A.B.C.D|(0-4294967295)> flood-reduction",
13048 "OSPF area parameters\n"
13049 "OSPF area ID in IP address format\n"
13050 "OSPF area ID as a decimal value\n"
13051 "Enable flood reduction for area\n")
13053 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
13054 struct ospf_area
*oa
;
13058 const char *areaid
;
13059 struct in_addr area_id
;
13061 areaid
= argv
[idx
]->arg
;
13063 ret
= str2area_id(areaid
, &area_id
, &format
);
13065 vty_out(vty
, "Please specify area by A.B.C.D|<0-4294967295>\n");
13066 return CMD_WARNING_CONFIG_FAILED
;
13069 oa
= ospf_area_lookup_by_area_id(ospf
, area_id
);
13071 vty_out(vty
, "OSPF area ID not present\n");
13072 return CMD_WARNING_CONFIG_FAILED
;
13075 /* Turn on the Flood Reduction feature for the area. */
13076 if (!oa
->fr_info
.configured
) {
13077 oa
->fr_info
.configured
= true;
13078 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT
,
13079 "Flood Reduction area %pI4 : OFF -> ON",
13081 ospf_area_update_fr_state(oa
);
13082 ospf_refresh_area_self_lsas(oa
);
13085 return CMD_SUCCESS
;
13088 DEFPY(no_flood_reduction
, no_flood_reduction_cmd
, "no flood-reduction",
13089 NO_STR
"flood reduction feature\n")
13091 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
13092 struct listnode
*node
;
13093 struct ospf_area
*area
;
13095 /* Turn off the Flood Reduction feature for the router. */
13096 if (ospf
->fr_configured
) {
13097 ospf
->fr_configured
= false;
13098 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT
,
13099 "Flood Reduction: ON -> OFF");
13100 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
13102 ospf_area_update_fr_state(area
);
13103 ospf_refresh_area_self_lsas(area
);
13108 return CMD_SUCCESS
;
13111 DEFPY(no_flood_reduction_area
, no_flood_reduction_area_cmd
,
13112 "no area <A.B.C.D|(0-4294967295)> flood-reduction",
13114 "OSPF area parameters\n"
13115 "OSPF area ID in IP address format\n"
13116 "OSPF area ID as a decimal value\n"
13117 "Disable flood reduction for area\n")
13119 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
13120 struct ospf_area
*oa
;
13124 const char *areaid
;
13125 struct in_addr area_id
;
13127 areaid
= argv
[idx
]->arg
;
13129 ret
= str2area_id(areaid
, &area_id
, &format
);
13131 vty_out(vty
, "Please specify area by A.B.C.D|<0-4294967295>\n");
13132 return CMD_WARNING_CONFIG_FAILED
;
13135 oa
= ospf_area_lookup_by_area_id(ospf
, area_id
);
13137 vty_out(vty
, "OSPF area ID not present\n");
13138 return CMD_WARNING_CONFIG_FAILED
;
13141 /* Turn off the Flood Reduction feature for the area. */
13142 if (oa
->fr_info
.configured
) {
13143 oa
->fr_info
.configured
= false;
13144 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT
,
13145 "Flood Reduction area %pI4 : ON -> OFF",
13147 ospf_area_update_fr_state(oa
);
13148 ospf_refresh_area_self_lsas(oa
);
13151 return CMD_SUCCESS
;
13154 DEFPY(ospf_socket_bufsizes
,
13155 ospf_socket_bufsizes_cmd
,
13156 "[no] socket buffer <send$send_val | recv$recv_val | all$all_val> \
13157 ![(1-4000000000)$bufsize]",
13159 "Socket parameters\n"
13160 "Buffer size configuration\n"
13161 "Send buffer size\n"
13162 "Receive buffer size\n"
13163 "Both send and receive buffer sizes\n"
13164 "Buffer size, in bytes\n")
13166 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
13167 uint32_t recvsz
, sendsz
;
13170 bufsize
= OSPF_DEFAULT_SOCK_BUFSIZE
;
13175 } else if (send_val
) {
13177 recvsz
= ospf
->recv_sock_bufsize
;
13178 } else if (recv_val
) {
13180 sendsz
= ospf
->send_sock_bufsize
;
13182 return CMD_SUCCESS
;
13184 /* React to a change by modifying existing sockets */
13185 ospf_update_bufsize(ospf
, recvsz
, sendsz
);
13187 return CMD_SUCCESS
;
13190 DEFPY (per_intf_socket
,
13191 per_intf_socket_cmd
,
13192 "[no] socket-per-interface",
13194 "Use write socket per interface\n")
13196 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
13197 struct listnode
*node
;
13198 struct ospf_interface
*oi
;
13201 if (ospf
->intf_socket_enabled
) {
13202 ospf
->intf_socket_enabled
= false;
13204 /* Iterate and close any sockets */
13205 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
))
13206 ospf_ifp_sock_close(oi
->ifp
);
13208 } else if (!ospf
->intf_socket_enabled
) {
13209 ospf
->intf_socket_enabled
= true;
13211 /* Iterate and open sockets */
13212 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
))
13213 ospf_ifp_sock_init(oi
->ifp
);
13216 return CMD_SUCCESS
;
13219 void ospf_vty_clear_init(void)
13221 install_element(ENABLE_NODE
, &clear_ip_ospf_interface_cmd
);
13222 install_element(ENABLE_NODE
, &clear_ip_ospf_process_cmd
);
13223 install_element(ENABLE_NODE
, &clear_ip_ospf_neighbor_cmd
);
13227 /* Install OSPF related vty commands. */
13228 void ospf_vty_init(void)
13230 /* Install ospf top node. */
13231 install_node(&ospf_node
);
13233 /* "router ospf" commands. */
13234 install_element(CONFIG_NODE
, &router_ospf_cmd
);
13235 install_element(CONFIG_NODE
, &no_router_ospf_cmd
);
13238 install_default(OSPF_NODE
);
13240 /* "ospf router-id" commands. */
13241 install_element(OSPF_NODE
, &ospf_router_id_cmd
);
13242 install_element(OSPF_NODE
, &ospf_router_id_old_cmd
);
13243 install_element(OSPF_NODE
, &no_ospf_router_id_cmd
);
13245 /* "passive-interface" commands. */
13246 install_element(OSPF_NODE
, &ospf_passive_interface_default_cmd
);
13247 install_element(OSPF_NODE
, &ospf_passive_interface_addr_cmd
);
13248 install_element(OSPF_NODE
, &no_ospf_passive_interface_default_cmd
);
13249 install_element(OSPF_NODE
, &no_ospf_passive_interface_addr_cmd
);
13251 /* "ospf abr-type" commands. */
13252 install_element(OSPF_NODE
, &ospf_abr_type_cmd
);
13253 install_element(OSPF_NODE
, &no_ospf_abr_type_cmd
);
13255 /* "ospf log-adjacency-changes" commands. */
13256 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_cmd
);
13257 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_detail_cmd
);
13258 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_cmd
);
13259 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_detail_cmd
);
13261 /* "ospf rfc1583-compatible" commands. */
13262 install_element(OSPF_NODE
, &ospf_compatible_rfc1583_cmd
);
13263 install_element(OSPF_NODE
, &no_ospf_compatible_rfc1583_cmd
);
13264 install_element(OSPF_NODE
, &ospf_rfc1583_flag_cmd
);
13265 install_element(OSPF_NODE
, &no_ospf_rfc1583_flag_cmd
);
13267 /* "ospf send-extra-data zebra" commands. */
13268 install_element(OSPF_NODE
, &ospf_send_extra_data_cmd
);
13270 /* "network area" commands. */
13271 install_element(OSPF_NODE
, &ospf_network_area_cmd
);
13272 install_element(OSPF_NODE
, &no_ospf_network_area_cmd
);
13274 /* "area authentication" commands. */
13275 install_element(OSPF_NODE
,
13276 &ospf_area_authentication_message_digest_cmd
);
13277 install_element(OSPF_NODE
, &ospf_area_authentication_cmd
);
13278 install_element(OSPF_NODE
, &no_ospf_area_authentication_cmd
);
13280 /* "area range" commands. */
13281 install_element(OSPF_NODE
, &ospf_area_range_cmd
);
13282 install_element(OSPF_NODE
, &ospf_area_range_cost_cmd
);
13283 install_element(OSPF_NODE
, &ospf_area_range_not_advertise_cmd
);
13284 install_element(OSPF_NODE
, &no_ospf_area_range_cmd
);
13285 install_element(OSPF_NODE
, &no_ospf_area_range_substitute_cmd
);
13287 /* "area virtual-link" commands. */
13288 install_element(OSPF_NODE
, &ospf_area_vlink_cmd
);
13289 install_element(OSPF_NODE
, &ospf_area_vlink_intervals_cmd
);
13290 install_element(OSPF_NODE
, &no_ospf_area_vlink_cmd
);
13291 install_element(OSPF_NODE
, &no_ospf_area_vlink_intervals_cmd
);
13294 /* "area stub" commands. */
13295 install_element(OSPF_NODE
, &ospf_area_stub_no_summary_cmd
);
13296 install_element(OSPF_NODE
, &ospf_area_stub_cmd
);
13297 install_element(OSPF_NODE
, &no_ospf_area_stub_no_summary_cmd
);
13298 install_element(OSPF_NODE
, &no_ospf_area_stub_cmd
);
13300 /* "area nssa" commands. */
13301 install_element(OSPF_NODE
, &ospf_area_nssa_cmd
);
13302 install_element(OSPF_NODE
, &no_ospf_area_nssa_cmd
);
13303 install_element(OSPF_NODE
, &ospf_area_nssa_range_cmd
);
13304 install_element(OSPF_NODE
, &no_ospf_area_nssa_range_cmd
);
13306 install_element(OSPF_NODE
, &ospf_area_default_cost_cmd
);
13307 install_element(OSPF_NODE
, &no_ospf_area_default_cost_cmd
);
13309 install_element(OSPF_NODE
, &ospf_area_shortcut_cmd
);
13310 install_element(OSPF_NODE
, &no_ospf_area_shortcut_cmd
);
13312 install_element(OSPF_NODE
, &ospf_area_export_list_cmd
);
13313 install_element(OSPF_NODE
, &no_ospf_area_export_list_cmd
);
13315 install_element(OSPF_NODE
, &ospf_area_filter_list_cmd
);
13316 install_element(OSPF_NODE
, &no_ospf_area_filter_list_cmd
);
13318 install_element(OSPF_NODE
, &ospf_area_import_list_cmd
);
13319 install_element(OSPF_NODE
, &no_ospf_area_import_list_cmd
);
13321 /* SPF timer commands */
13322 install_element(OSPF_NODE
, &ospf_timers_throttle_spf_cmd
);
13323 install_element(OSPF_NODE
, &no_ospf_timers_throttle_spf_cmd
);
13325 /* LSA timers commands */
13326 install_element(OSPF_NODE
, &ospf_timers_min_ls_interval_cmd
);
13327 install_element(OSPF_NODE
, &no_ospf_timers_min_ls_interval_cmd
);
13328 install_element(OSPF_NODE
, &ospf_timers_lsa_min_arrival_cmd
);
13329 install_element(OSPF_NODE
, &no_ospf_timers_lsa_min_arrival_cmd
);
13331 /* refresh timer commands */
13332 install_element(OSPF_NODE
, &ospf_refresh_timer_cmd
);
13333 install_element(OSPF_NODE
, &no_ospf_refresh_timer_val_cmd
);
13335 /* max-metric commands */
13336 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_admin_cmd
);
13337 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_admin_cmd
);
13338 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_startup_cmd
);
13339 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_startup_cmd
);
13340 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_shutdown_cmd
);
13341 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_shutdown_cmd
);
13343 /* reference bandwidth commands */
13344 install_element(OSPF_NODE
, &ospf_auto_cost_reference_bandwidth_cmd
);
13345 install_element(OSPF_NODE
, &no_ospf_auto_cost_reference_bandwidth_cmd
);
13347 /* "neighbor" commands. */
13348 install_element(OSPF_NODE
, &ospf_neighbor_cmd
);
13349 install_element(OSPF_NODE
, &ospf_neighbor_poll_interval_cmd
);
13350 install_element(OSPF_NODE
, &no_ospf_neighbor_cmd
);
13351 install_element(OSPF_NODE
, &no_ospf_neighbor_poll_cmd
);
13353 /* write multiplier commands */
13354 install_element(OSPF_NODE
, &ospf_write_multiplier_cmd
);
13355 install_element(OSPF_NODE
, &write_multiplier_cmd
);
13356 install_element(OSPF_NODE
, &no_ospf_write_multiplier_cmd
);
13357 install_element(OSPF_NODE
, &no_write_multiplier_cmd
);
13359 /* "proactive-arp" commands. */
13360 install_element(OSPF_NODE
, &ospf_proactive_arp_cmd
);
13361 install_element(OSPF_NODE
, &no_ospf_proactive_arp_cmd
);
13363 /* TI-LFA commands */
13364 install_element(OSPF_NODE
, &ospf_ti_lfa_cmd
);
13365 install_element(OSPF_NODE
, &no_ospf_ti_lfa_cmd
);
13367 /* Max path configurations */
13368 install_element(OSPF_NODE
, &ospf_max_multipath_cmd
);
13369 install_element(OSPF_NODE
, &no_ospf_max_multipath_cmd
);
13371 vrf_cmd_init(NULL
);
13373 install_element(OSPF_NODE
, &ospf_lsa_refresh_timer_cmd
);
13374 install_element(OSPF_NODE
, &ospf_maxage_delay_timer_cmd
);
13376 /* Flood Reduction commands */
13377 install_element(OSPF_NODE
, &flood_reduction_cmd
);
13378 install_element(OSPF_NODE
, &no_flood_reduction_cmd
);
13379 install_element(OSPF_NODE
, &flood_reduction_area_cmd
);
13380 install_element(OSPF_NODE
, &no_flood_reduction_area_cmd
);
13382 install_element(OSPF_NODE
, &ospf_socket_bufsizes_cmd
);
13383 install_element(OSPF_NODE
, &per_intf_socket_cmd
);
13385 /* Init interface related vty commands. */
13386 ospf_vty_if_init();
13388 /* Init zebra related vty commands. */
13389 ospf_vty_zebra_init();