1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2005 6WIND <alain.ritoux@6wind.com>
4 * Copyright (C) 2000 Toshiaki Takada
23 #include "lib/printfrr.h"
25 #include "ospfd/ospfd.h"
26 #include "ospfd/ospf_asbr.h"
27 #include "ospfd/ospf_lsa.h"
28 #include "ospfd/ospf_lsdb.h"
29 #include "ospfd/ospf_ism.h"
30 #include "ospfd/ospf_interface.h"
31 #include "ospfd/ospf_nsm.h"
32 #include "ospfd/ospf_neighbor.h"
33 #include "ospfd/ospf_flood.h"
34 #include "ospfd/ospf_abr.h"
35 #include "ospfd/ospf_spf.h"
36 #include "ospfd/ospf_route.h"
37 #include "ospfd/ospf_zebra.h"
38 /*#include "ospfd/ospf_routemap.h" */
39 #include "ospfd/ospf_vty.h"
40 #include "ospfd/ospf_dump.h"
41 #include "ospfd/ospf_bfd.h"
42 #include "ospfd/ospf_ldp_sync.h"
45 FRR_CFG_DEFAULT_BOOL(OSPF_LOG_ADJACENCY_CHANGES
,
46 { .val_bool
= true, .match_profile
= "datacenter", },
47 { .val_bool
= false },
50 static const char *const ospf_network_type_str
[] = {
51 "Null", "POINTOPOINT", "BROADCAST", "NBMA", "POINTOMULTIPOINT",
52 "VIRTUALLINK", "LOOPBACK"};
54 /* Utility functions. */
55 int str2area_id(const char *str
, struct in_addr
*area_id
, int *area_id_fmt
)
59 area_id
->s_addr
= htonl(strtoul(str
, &ep
, 10));
60 if (*ep
&& !inet_aton(str
, area_id
))
64 *ep
? OSPF_AREA_ID_FMT_DOTTEDQUAD
: OSPF_AREA_ID_FMT_DECIMAL
;
69 static void area_id2str(char *buf
, int length
, struct in_addr
*area_id
,
72 if (area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
73 inet_ntop(AF_INET
, area_id
, buf
, length
);
75 snprintf(buf
, length
, "%lu",
76 (unsigned long)ntohl(area_id
->s_addr
));
79 static int str2metric(const char *str
, int *metric
)
85 *metric
= strtol(str
, NULL
, 10);
86 if (*metric
< 0 || *metric
> 16777214) {
87 /* vty_out (vty, "OSPF metric value is invalid\n"); */
94 static int str2metric_type(const char *str
, int *metric_type
)
100 if (strncmp(str
, "1", 1) == 0)
101 *metric_type
= EXTERNAL_METRIC_TYPE_1
;
102 else if (strncmp(str
, "2", 1) == 0)
103 *metric_type
= EXTERNAL_METRIC_TYPE_2
;
110 int ospf_oi_count(struct interface
*ifp
)
112 struct route_node
*rn
;
115 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
122 #define OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf) \
123 if (argv_find(argv, argc, "vrf", &idx_vrf)) { \
124 vrf_name = argv[idx_vrf + 1]->arg; \
125 all_vrf = strmatch(vrf_name, "all"); \
128 static int ospf_router_cmd_parse(struct vty
*vty
, struct cmd_token
*argv
[],
129 const int argc
, unsigned short *instance
,
130 const char **vrf_name
)
132 int idx_vrf
= 0, idx_inst
= 0;
135 if (argv_find(argv
, argc
, "(1-65535)", &idx_inst
)) {
136 if (ospf_instance
== 0) {
138 "%% OSPF is not running in instance mode\n");
139 return CMD_WARNING_CONFIG_FAILED
;
142 *instance
= strtoul(argv
[idx_inst
]->arg
, NULL
, 10);
145 *vrf_name
= VRF_DEFAULT_NAME
;
146 if (argv_find(argv
, argc
, "vrf", &idx_vrf
)) {
147 if (ospf_instance
!= 0) {
149 "%% VRF is not supported in instance mode\n");
150 return CMD_WARNING_CONFIG_FAILED
;
153 *vrf_name
= argv
[idx_vrf
+ 1]->arg
;
159 static void ospf_show_vrf_name(struct ospf
*ospf
, struct vty
*vty
,
160 json_object
*json
, uint8_t use_vrf
)
164 json_object_string_add(json
, "vrfName",
165 ospf_get_name(ospf
));
166 json_object_int_add(json
, "vrfId", ospf
->vrf_id
);
168 vty_out(vty
, "VRF Name: %s\n", ospf_get_name(ospf
));
172 #include "ospfd/ospf_vty_clippy.c"
174 DEFUN_NOSH (router_ospf
,
176 "router ospf [{(1-65535)|vrf NAME}]",
177 "Enable a routing process\n"
178 "Start OSPF configuration\n"
182 unsigned short instance
;
183 const char *vrf_name
;
184 bool created
= false;
188 ret
= ospf_router_cmd_parse(vty
, argv
, argc
, &instance
, &vrf_name
);
189 if (ret
!= CMD_SUCCESS
)
192 if (instance
!= ospf_instance
) {
193 VTY_PUSH_CONTEXT_NULL(OSPF_NODE
);
194 return CMD_NOT_MY_INSTANCE
;
197 ospf
= ospf_get(instance
, vrf_name
, &created
);
200 if (DFLT_OSPF_LOG_ADJACENCY_CHANGES
)
201 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
203 if (IS_DEBUG_OSPF_EVENT
)
205 "Config command 'router ospf %d' received, vrf %s id %u oi_running %u",
206 ospf
->instance
, ospf_get_name(ospf
), ospf
->vrf_id
,
209 VTY_PUSH_CONTEXT(OSPF_NODE
, ospf
);
214 DEFUN (no_router_ospf
,
216 "no router ospf [{(1-65535)|vrf NAME}]",
218 "Enable a routing process\n"
219 "Start OSPF configuration\n"
223 unsigned short instance
;
224 const char *vrf_name
;
228 ret
= ospf_router_cmd_parse(vty
, argv
, argc
, &instance
, &vrf_name
);
229 if (ret
!= CMD_SUCCESS
)
232 if (instance
!= ospf_instance
)
233 return CMD_NOT_MY_INSTANCE
;
235 ospf
= ospf_lookup(instance
, vrf_name
);
239 ret
= CMD_WARNING_CONFIG_FAILED
;
245 DEFPY (ospf_router_id
,
247 "ospf router-id A.B.C.D",
248 "OSPF specific commands\n"
249 "router-id for the OSPF process\n"
250 "OSPF router-id in IP address format\n")
252 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
254 struct listnode
*node
;
255 struct ospf_area
*area
;
257 ospf
->router_id_static
= router_id
;
259 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
260 if (area
->full_nbrs
) {
262 "For this router-id change to take effect, use \"clear ip ospf process\" command\n");
266 ospf_router_id_update(ospf
);
271 DEFUN_HIDDEN (ospf_router_id_old
,
272 ospf_router_id_old_cmd
,
274 "router-id for the OSPF process\n"
275 "OSPF router-id in IP address format\n")
277 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
279 struct listnode
*node
;
280 struct ospf_area
*area
;
281 struct in_addr router_id
;
284 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &router_id
);
286 vty_out(vty
, "Please specify Router ID by A.B.C.D\n");
287 return CMD_WARNING_CONFIG_FAILED
;
290 ospf
->router_id_static
= router_id
;
292 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
293 if (area
->full_nbrs
) {
295 "For this router-id change to take effect, use \"clear ip ospf process\" command\n");
299 ospf_router_id_update(ospf
);
304 DEFPY (no_ospf_router_id
,
305 no_ospf_router_id_cmd
,
306 "no ospf router-id [A.B.C.D]",
308 "OSPF specific commands\n"
309 "router-id for the OSPF process\n"
310 "OSPF router-id in IP address format\n")
312 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
313 struct listnode
*node
;
314 struct ospf_area
*area
;
317 if (!IPV4_ADDR_SAME(&ospf
->router_id_static
, &router_id
)) {
318 vty_out(vty
, "%% OSPF router-id doesn't match\n");
319 return CMD_WARNING_CONFIG_FAILED
;
323 ospf
->router_id_static
.s_addr
= 0;
325 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
326 if (area
->full_nbrs
) {
328 "For this router-id change to take effect, use \"clear ip ospf process\" command\n");
332 ospf_router_id_update(ospf
);
338 static void ospf_passive_interface_default_update(struct ospf
*ospf
,
342 struct ospf_interface
*oi
;
344 ospf
->passive_interface_default
= newval
;
346 /* update multicast memberships */
347 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, ln
, oi
))
348 ospf_if_set_multicast(oi
);
351 static void ospf_passive_interface_update(struct interface
*ifp
,
352 struct ospf_if_params
*params
,
353 struct in_addr addr
, uint8_t newval
)
355 struct route_node
*rn
;
357 if (OSPF_IF_PARAM_CONFIGURED(params
, passive_interface
)) {
358 if (params
->passive_interface
== newval
)
361 params
->passive_interface
= newval
;
362 UNSET_IF_PARAM(params
, passive_interface
);
363 if (params
!= IF_DEF_PARAMS(ifp
)) {
364 ospf_free_if_params(ifp
, addr
);
365 ospf_if_update_params(ifp
, addr
);
368 params
->passive_interface
= newval
;
369 SET_IF_PARAM(params
, passive_interface
);
373 * XXX We should call ospf_if_set_multicast on exactly those
374 * interfaces for which the passive property changed. It is too much
375 * work to determine this set, so we do this for every interface.
376 * This is safe and reasonable because ospf_if_set_multicast uses a
377 * record of joined groups to avoid systems calls if the desired
378 * memberships match the current memership.
381 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
382 struct ospf_interface
*oi
= rn
->info
;
385 ospf_if_set_multicast(oi
);
389 * XXX It is not clear what state transitions the interface needs to
390 * undergo when going from active to passive and vice versa. Fixing
391 * this will require precise identification of interfaces having such a
396 DEFUN (ospf_passive_interface_default
,
397 ospf_passive_interface_default_cmd
,
398 "passive-interface default",
399 "Suppress routing updates on an interface\n"
400 "Suppress routing updates on interfaces by default\n")
402 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
404 ospf_passive_interface_default_update(ospf
, OSPF_IF_PASSIVE
);
409 DEFUN_HIDDEN (ospf_passive_interface_addr
,
410 ospf_passive_interface_addr_cmd
,
411 "passive-interface IFNAME [A.B.C.D]",
412 "Suppress routing updates on an interface\n"
416 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
418 struct interface
*ifp
= NULL
;
419 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
420 struct ospf_if_params
*params
;
424 "This command is deprecated, because it is not VRF-aware.\n");
426 "Please, use \"ip ospf passive\" on an interface instead.\n");
428 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
429 ifp
= if_get_by_name(argv
[1]->arg
, ospf
->vrf_id
, ospf
->name
);
432 vty_out(vty
, "interface %s not found.\n", (char *)argv
[1]->arg
);
433 return CMD_WARNING_CONFIG_FAILED
;
437 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
440 "Please specify interface address by A.B.C.D\n");
441 return CMD_WARNING_CONFIG_FAILED
;
444 params
= ospf_get_if_params(ifp
, addr
);
445 ospf_if_update_params(ifp
, addr
);
447 params
= IF_DEF_PARAMS(ifp
);
450 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_PASSIVE
);
455 DEFUN (no_ospf_passive_interface_default
,
456 no_ospf_passive_interface_default_cmd
,
457 "no passive-interface default",
459 "Allow routing updates on an interface\n"
460 "Allow routing updates on interfaces by default\n")
462 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
464 ospf_passive_interface_default_update(ospf
, OSPF_IF_ACTIVE
);
469 DEFUN_HIDDEN (no_ospf_passive_interface
,
470 no_ospf_passive_interface_addr_cmd
,
471 "no passive-interface IFNAME [A.B.C.D]",
473 "Allow routing updates on an interface\n"
477 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
479 struct interface
*ifp
= NULL
;
480 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
481 struct ospf_if_params
*params
;
485 "This command is deprecated, because it is not VRF-aware.\n");
487 "Please, use \"no ip ospf passive\" on an interface instead.\n");
489 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
490 ifp
= if_get_by_name(argv
[2]->arg
, ospf
->vrf_id
, ospf
->name
);
493 vty_out(vty
, "interface %s not found.\n", (char *)argv
[2]->arg
);
494 return CMD_WARNING_CONFIG_FAILED
;
498 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
501 "Please specify interface address by A.B.C.D\n");
502 return CMD_WARNING_CONFIG_FAILED
;
504 params
= ospf_lookup_if_params(ifp
, addr
);
508 params
= IF_DEF_PARAMS(ifp
);
511 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_ACTIVE
);
517 DEFUN (ospf_network_area
,
518 ospf_network_area_cmd
,
519 "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
520 "Enable routing on an IP network\n"
521 "OSPF network prefix\n"
522 "Set the OSPF area ID\n"
523 "OSPF area ID in IP address format\n"
524 "OSPF area ID as a decimal value\n")
526 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
527 int idx_ipv4_prefixlen
= 1;
528 int idx_ipv4_number
= 3;
529 struct prefix_ipv4 p
;
530 struct in_addr area_id
;
534 if (ospf
->instance
) {
536 "The network command is not supported in multi-instance ospf\n");
537 return CMD_WARNING_CONFIG_FAILED
;
540 count
= ospf_count_area_params(ospf
);
543 "Please remove all ip ospf area x.x.x.x commands first.\n");
544 if (IS_DEBUG_OSPF_EVENT
)
546 "%s ospf vrf %s num of %u ip ospf area x config",
547 __func__
, ospf_get_name(ospf
), count
);
548 return CMD_WARNING_CONFIG_FAILED
;
551 /* Get network prefix and Area ID. */
552 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
553 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
555 ret
= ospf_network_set(ospf
, &p
, area_id
, format
);
557 vty_out(vty
, "There is already same network statement.\n");
558 return CMD_WARNING_CONFIG_FAILED
;
564 DEFUN (no_ospf_network_area
,
565 no_ospf_network_area_cmd
,
566 "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
568 "Enable routing on an IP network\n"
569 "OSPF network prefix\n"
570 "Set the OSPF area ID\n"
571 "OSPF area ID in IP address format\n"
572 "OSPF area ID as a decimal value\n")
574 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
575 int idx_ipv4_prefixlen
= 2;
576 int idx_ipv4_number
= 4;
577 struct prefix_ipv4 p
;
578 struct in_addr area_id
;
581 if (ospf
->instance
) {
583 "The network command is not supported in multi-instance ospf\n");
584 return CMD_WARNING_CONFIG_FAILED
;
587 /* Get network prefix and Area ID. */
588 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
589 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
591 ret
= ospf_network_unset(ospf
, &p
, area_id
);
594 "Can't find specified network area configuration.\n");
595 return CMD_WARNING_CONFIG_FAILED
;
601 DEFUN (ospf_area_range
,
603 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]",
604 "OSPF area parameters\n"
605 "OSPF area ID in IP address format\n"
606 "OSPF area ID as a decimal value\n"
607 "Summarize routes matching address/mask (border routers only)\n"
608 "Area range prefix\n"
609 "Advertise this range (default)\n"
610 "User specified metric for this range\n"
611 "Advertised metric for this range\n")
613 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
614 int idx_ipv4_number
= 1;
615 int idx_ipv4_prefixlen
= 3;
617 struct prefix_ipv4 p
;
618 struct in_addr area_id
;
622 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
623 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
625 ospf_area_range_set(ospf
, area_id
, &p
, OSPF_AREA_RANGE_ADVERTISE
);
626 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
629 cost
= strtoul(argv
[idx_cost
]->arg
, NULL
, 10);
630 ospf_area_range_cost_set(ospf
, area_id
, &p
, cost
);
636 DEFUN (ospf_area_range_cost
,
637 ospf_area_range_cost_cmd
,
638 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M {cost (0-16777215)|substitute A.B.C.D/M}",
639 "OSPF area parameters\n"
640 "OSPF area ID in IP address format\n"
641 "OSPF area ID as a decimal value\n"
642 "Summarize routes matching address/mask (border routers only)\n"
643 "Area range prefix\n"
644 "User specified metric for this range\n"
645 "Advertised metric for this range\n"
646 "Announce area range as another prefix\n"
647 "Network prefix to be announced instead of range\n")
649 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
650 int idx_ipv4_number
= 1;
651 int idx_ipv4_prefixlen
= 3;
653 struct prefix_ipv4 p
, s
;
654 struct in_addr area_id
;
658 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
659 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
661 ospf_area_range_set(ospf
, area_id
, &p
, OSPF_AREA_RANGE_ADVERTISE
);
662 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
665 if (argv_find(argv
, argc
, "cost", &idx
)) {
666 cost
= strtoul(argv
[idx
+ 1]->arg
, NULL
, 10);
667 ospf_area_range_cost_set(ospf
, area_id
, &p
, cost
);
671 if (argv_find(argv
, argc
, "substitute", &idx
)) {
672 str2prefix_ipv4(argv
[idx
+ 1]->arg
, &s
);
673 ospf_area_range_substitute_set(ospf
, area_id
, &p
, &s
);
679 DEFUN (ospf_area_range_not_advertise
,
680 ospf_area_range_not_advertise_cmd
,
681 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise",
682 "OSPF area parameters\n"
683 "OSPF area ID in IP address format\n"
684 "OSPF area ID as a decimal value\n"
685 "Summarize routes matching address/mask (border routers only)\n"
686 "Area range prefix\n"
687 "DoNotAdvertise this range\n")
689 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
690 int idx_ipv4_number
= 1;
691 int idx_ipv4_prefixlen
= 3;
692 struct prefix_ipv4 p
;
693 struct in_addr area_id
;
696 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
697 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
699 ospf_area_range_set(ospf
, area_id
, &p
, 0);
700 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
702 ospf_area_range_substitute_unset(ospf
, area_id
, &p
);
707 DEFUN (no_ospf_area_range
,
708 no_ospf_area_range_cmd
,
709 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]",
711 "OSPF area parameters\n"
712 "OSPF area ID in IP address format\n"
713 "OSPF area ID as a decimal value\n"
714 "Summarize routes matching address/mask (border routers only)\n"
715 "Area range prefix\n"
716 "User specified metric for this range\n"
717 "Advertised metric for this range\n"
718 "Advertise this range (default)\n"
719 "User specified metric for this range\n"
720 "Advertised metric for this range\n"
721 "DoNotAdvertise this range\n")
723 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
724 int idx_ipv4_number
= 2;
725 int idx_ipv4_prefixlen
= 4;
726 struct prefix_ipv4 p
;
727 struct in_addr area_id
;
730 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
731 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
733 ospf_area_range_unset(ospf
, area_id
, &p
);
738 DEFUN (no_ospf_area_range_substitute
,
739 no_ospf_area_range_substitute_cmd
,
740 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
742 "OSPF area parameters\n"
743 "OSPF area ID in IP address format\n"
744 "OSPF area ID as a decimal value\n"
745 "Summarize routes matching address/mask (border routers only)\n"
746 "Area range prefix\n"
747 "Announce area range as another prefix\n"
748 "Network prefix to be announced instead of range\n")
750 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
751 int idx_ipv4_number
= 2;
752 int idx_ipv4_prefixlen
= 4;
753 int idx_ipv4_prefixlen_2
= 6;
754 struct prefix_ipv4 p
, s
;
755 struct in_addr area_id
;
758 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
759 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
760 str2prefix_ipv4(argv
[idx_ipv4_prefixlen_2
]->arg
, &s
);
762 ospf_area_range_substitute_unset(ospf
, area_id
, &p
);
768 /* Command Handler Logic in VLink stuff is delicate!!
770 ALTER AT YOUR OWN RISK!!!!
772 Various dummy values are used to represent 'NoChange' state for
773 VLink configuration NOT being changed by a VLink command, and
774 special syntax is used within the command strings so that the
775 typed in command verbs can be seen in the configuration command
776 bacckend handler. This is to drastically reduce the verbeage
777 required to coe up with a reasonably compatible Cisco VLink command
779 - Matthew Grant <grantma@anathoth.gen.nz>
780 Wed, 21 Feb 2001 15:13:52 +1300
783 /* Configuration data for virtual links
785 struct ospf_vl_config_data
{
786 struct vty
*vty
; /* vty stuff */
787 struct in_addr area_id
; /* area ID from command line */
788 int area_id_fmt
; /* command line area ID format */
789 struct in_addr vl_peer
; /* command line vl_peer */
790 int auth_type
; /* Authehntication type, if given */
791 char *auth_key
; /* simple password if present */
792 int crypto_key_id
; /* Cryptographic key ID */
793 char *md5_key
; /* MD5 authentication key */
794 int hello_interval
; /* Obvious what these are... */
795 int retransmit_interval
;
800 static void ospf_vl_config_data_init(struct ospf_vl_config_data
*vl_config
,
803 memset(vl_config
, 0, sizeof(struct ospf_vl_config_data
));
804 vl_config
->auth_type
= OSPF_AUTH_CMD_NOTSEEN
;
805 vl_config
->vty
= vty
;
808 static struct ospf_vl_data
*
809 ospf_find_vl_data(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
811 struct ospf_area
*area
;
812 struct ospf_vl_data
*vl_data
;
814 struct in_addr area_id
;
816 vty
= vl_config
->vty
;
817 area_id
= vl_config
->area_id
;
819 if (area_id
.s_addr
== OSPF_AREA_BACKBONE
) {
821 "Configuring VLs over the backbone is not allowed\n");
824 area
= ospf_area_get(ospf
, area_id
);
825 ospf_area_display_format_set(ospf
, area
, vl_config
->area_id_fmt
);
827 if (area
->external_routing
!= OSPF_AREA_DEFAULT
) {
828 if (vl_config
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
829 vty_out(vty
, "Area %pI4 is %s\n", &area_id
,
830 area
->external_routing
== OSPF_AREA_NSSA
834 vty_out(vty
, "Area %ld is %s\n",
835 (unsigned long)ntohl(area_id
.s_addr
),
836 area
->external_routing
== OSPF_AREA_NSSA
842 if ((vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
->vl_peer
))
844 vl_data
= ospf_vl_data_new(area
, vl_config
->vl_peer
);
845 if (vl_data
->vl_oi
== NULL
) {
846 vl_data
->vl_oi
= ospf_vl_new(ospf
, vl_data
);
847 ospf_vl_add(ospf
, vl_data
);
848 ospf_spf_calculate_schedule(ospf
,
849 SPF_FLAG_CONFIG_CHANGE
);
856 static int ospf_vl_set_security(struct ospf_vl_data
*vl_data
,
857 struct ospf_vl_config_data
*vl_config
)
859 struct crypt_key
*ck
;
861 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
863 vty
= vl_config
->vty
;
865 if (vl_config
->auth_type
!= OSPF_AUTH_CMD_NOTSEEN
) {
866 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), auth_type
);
867 IF_DEF_PARAMS(ifp
)->auth_type
= vl_config
->auth_type
;
870 if (vl_config
->auth_key
) {
871 memset(IF_DEF_PARAMS(ifp
)->auth_simple
, 0,
872 OSPF_AUTH_SIMPLE_SIZE
+ 1);
873 strlcpy((char *)IF_DEF_PARAMS(ifp
)->auth_simple
,
875 sizeof(IF_DEF_PARAMS(ifp
)->auth_simple
));
876 } else if (vl_config
->md5_key
) {
877 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
878 vl_config
->crypto_key_id
)
880 vty_out(vty
, "OSPF: Key %d already exists\n",
881 vl_config
->crypto_key_id
);
884 ck
= ospf_crypt_key_new();
885 ck
->key_id
= vl_config
->crypto_key_id
;
886 memset(ck
->auth_key
, 0, OSPF_AUTH_MD5_SIZE
+ 1);
887 strlcpy((char *)ck
->auth_key
, vl_config
->md5_key
,
888 sizeof(ck
->auth_key
));
890 ospf_crypt_key_add(IF_DEF_PARAMS(ifp
)->auth_crypt
, ck
);
891 } else if (vl_config
->crypto_key_id
!= 0) {
894 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
895 vl_config
->crypto_key_id
)
897 vty_out(vty
, "OSPF: Key %d does not exist\n",
898 vl_config
->crypto_key_id
);
899 return CMD_WARNING_CONFIG_FAILED
;
902 ospf_crypt_key_delete(IF_DEF_PARAMS(ifp
)->auth_crypt
,
903 vl_config
->crypto_key_id
);
909 static int ospf_vl_set_timers(struct ospf_vl_data
*vl_data
,
910 struct ospf_vl_config_data
*vl_config
)
912 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
913 /* Virtual Link data initialised to defaults, so only set
915 if (vl_config
->hello_interval
) {
916 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_hello
);
917 IF_DEF_PARAMS(ifp
)->v_hello
= vl_config
->hello_interval
;
920 if (vl_config
->dead_interval
) {
921 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_wait
);
922 IF_DEF_PARAMS(ifp
)->v_wait
= vl_config
->dead_interval
;
925 if (vl_config
->retransmit_interval
) {
926 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), retransmit_interval
);
927 IF_DEF_PARAMS(ifp
)->retransmit_interval
=
928 vl_config
->retransmit_interval
;
931 if (vl_config
->transmit_delay
) {
932 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), transmit_delay
);
933 IF_DEF_PARAMS(ifp
)->transmit_delay
= vl_config
->transmit_delay
;
940 /* The business end of all of the above */
941 static int ospf_vl_set(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
943 struct ospf_vl_data
*vl_data
;
946 vl_data
= ospf_find_vl_data(ospf
, vl_config
);
948 return CMD_WARNING_CONFIG_FAILED
;
950 /* Process this one first as it can have a fatal result, which can
951 only logically occur if the virtual link exists already
952 Thus a command error does not result in a change to the
953 running configuration such as unexpectedly altered timer
955 ret
= ospf_vl_set_security(vl_data
, vl_config
);
956 if (ret
!= CMD_SUCCESS
)
959 /* Set any time based parameters, these area already range checked */
961 ret
= ospf_vl_set_timers(vl_data
, vl_config
);
962 if (ret
!= CMD_SUCCESS
)
968 /* This stuff exists to make specifying all the alias commands A LOT simpler
970 #define VLINK_HELPSTR_IPADDR \
971 "OSPF area parameters\n" \
972 "OSPF area ID in IP address format\n" \
973 "OSPF area ID as a decimal value\n" \
974 "Configure a virtual link\n" \
975 "Router ID of the remote ABR\n"
977 #define VLINK_HELPSTR_AUTHTYPE_SIMPLE \
978 "Enable authentication on this virtual link\n" \
981 #define VLINK_HELPSTR_AUTHTYPE_ALL \
982 VLINK_HELPSTR_AUTHTYPE_SIMPLE \
983 "Use null authentication\n" \
984 "Use message-digest authentication\n"
986 #define VLINK_HELPSTR_TIME_PARAM \
987 "Time between HELLO packets\n" \
989 "Time between retransmitting lost link state advertisements\n" \
991 "Link state transmit delay\n" \
993 "Interval time after which a neighbor is declared down\n" \
996 #define VLINK_HELPSTR_AUTH_SIMPLE \
997 "Authentication password (key)\n" \
998 "The OSPF password (key)\n"
1000 #define VLINK_HELPSTR_AUTH_MD5 \
1001 "Message digest authentication password (key)\n" \
1003 "Use MD5 algorithm\n" \
1004 "The OSPF password (key)\n"
1006 DEFUN (ospf_area_vlink
,
1007 ospf_area_vlink_cmd
,
1008 "area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D [authentication [<message-digest|null>]] [<message-digest-key (1-255) md5 KEY|authentication-key AUTH_KEY>]",
1009 VLINK_HELPSTR_IPADDR
1010 "Enable authentication on this virtual link\n"
1011 "Use message-digest authentication\n"
1012 "Use null authentication\n"
1013 VLINK_HELPSTR_AUTH_MD5
1014 VLINK_HELPSTR_AUTH_SIMPLE
)
1016 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1017 int idx_ipv4_number
= 1;
1019 struct ospf_vl_config_data vl_config
;
1020 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1021 char md5_key
[OSPF_AUTH_MD5_SIZE
+ 1];
1025 ospf_vl_config_data_init(&vl_config
, vty
);
1027 /* Read off first 2 parameters and check them */
1028 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1029 &vl_config
.area_id_fmt
);
1031 vty_out(vty
, "OSPF area ID is invalid\n");
1032 return CMD_WARNING_CONFIG_FAILED
;
1035 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1037 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1038 return CMD_WARNING_CONFIG_FAILED
;
1042 /* Thats all folks! - BUGS B. strikes again!!!*/
1044 return ospf_vl_set(ospf
, &vl_config
);
1047 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1048 /* authentication - this option can only occur
1049 at start of command line */
1050 vl_config
.auth_type
= OSPF_AUTH_SIMPLE
;
1053 if (argv_find(argv
, argc
, "message-digest", &idx
)) {
1054 /* authentication message-digest */
1055 vl_config
.auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
1056 } else if (argv_find(argv
, argc
, "null", &idx
)) {
1057 /* "authentication null" */
1058 vl_config
.auth_type
= OSPF_AUTH_NULL
;
1061 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1062 vl_config
.md5_key
= NULL
;
1063 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1064 if (vl_config
.crypto_key_id
< 0)
1065 return CMD_WARNING_CONFIG_FAILED
;
1067 strlcpy(md5_key
, argv
[idx
+ 3]->arg
, sizeof(md5_key
));
1068 vl_config
.md5_key
= md5_key
;
1071 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1072 strlcpy(auth_key
, argv
[idx
+ 1]->arg
, sizeof(auth_key
));
1073 vl_config
.auth_key
= auth_key
;
1076 /* Action configuration */
1078 return ospf_vl_set(ospf
, &vl_config
);
1081 DEFUN (no_ospf_area_vlink
,
1082 no_ospf_area_vlink_cmd
,
1083 "no area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D [authentication [<message-digest|null>]] [<message-digest-key (1-255) md5 KEY|authentication-key AUTH_KEY>]",
1085 VLINK_HELPSTR_IPADDR
1086 "Enable authentication on this virtual link\n"
1087 "Use message-digest authentication\n"
1088 "Use null authentication\n"
1089 VLINK_HELPSTR_AUTH_MD5
1090 VLINK_HELPSTR_AUTH_SIMPLE
)
1092 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1093 int idx_ipv4_number
= 2;
1095 struct ospf_area
*area
;
1096 struct ospf_vl_config_data vl_config
;
1097 struct ospf_vl_data
*vl_data
= NULL
;
1098 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1102 ospf_vl_config_data_init(&vl_config
, vty
);
1104 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1107 vty_out(vty
, "OSPF area ID is invalid\n");
1108 return CMD_WARNING_CONFIG_FAILED
;
1111 area
= ospf_area_lookup_by_area_id(ospf
, vl_config
.area_id
);
1113 vty_out(vty
, "Area does not exist\n");
1114 return CMD_WARNING_CONFIG_FAILED
;
1117 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1119 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1120 return CMD_WARNING_CONFIG_FAILED
;
1123 vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
.vl_peer
);
1125 vty_out(vty
, "Virtual link does not exist\n");
1126 return CMD_WARNING_CONFIG_FAILED
;
1130 /* Basic VLink no command */
1131 /* Thats all folks! - BUGS B. strikes again!!!*/
1132 ospf_vl_delete(ospf
, vl_data
);
1133 ospf_area_check_free(ospf
, vl_config
.area_id
);
1137 /* If we are down here, we are reseting parameters */
1138 /* Deal with other parameters */
1140 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1141 /* authentication - this option can only occur
1142 at start of command line */
1143 vl_config
.auth_type
= OSPF_AUTH_NOTSET
;
1146 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1147 vl_config
.md5_key
= NULL
;
1148 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1149 if (vl_config
.crypto_key_id
< 0)
1150 return CMD_WARNING_CONFIG_FAILED
;
1153 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1154 /* Reset authentication-key to 0 */
1155 memset(auth_key
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
1156 vl_config
.auth_key
= auth_key
;
1159 /* Action configuration */
1161 return ospf_vl_set(ospf
, &vl_config
);
1164 DEFUN (ospf_area_vlink_intervals
,
1165 ospf_area_vlink_intervals_cmd
,
1166 "area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D {hello-interval (1-65535)|retransmit-interval (1-65535)|transmit-delay (1-65535)|dead-interval (1-65535)}",
1167 VLINK_HELPSTR_IPADDR
1168 VLINK_HELPSTR_TIME_PARAM
)
1170 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1171 struct ospf_vl_config_data vl_config
;
1174 ospf_vl_config_data_init(&vl_config
, vty
);
1176 char *area_id
= argv
[1]->arg
;
1177 char *router_id
= argv
[3]->arg
;
1179 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1181 vty_out(vty
, "OSPF area ID is invalid\n");
1182 return CMD_WARNING_CONFIG_FAILED
;
1185 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1187 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1188 return CMD_WARNING_CONFIG_FAILED
;
1191 for (int idx
= 4; idx
< argc
; idx
++) {
1192 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1193 vl_config
.hello_interval
=
1194 strtol(argv
[++idx
]->arg
, NULL
, 10);
1195 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1196 vl_config
.retransmit_interval
=
1197 strtol(argv
[++idx
]->arg
, NULL
, 10);
1198 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1199 vl_config
.transmit_delay
=
1200 strtol(argv
[++idx
]->arg
, NULL
, 10);
1201 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1202 vl_config
.dead_interval
=
1203 strtol(argv
[++idx
]->arg
, NULL
, 10);
1206 /* Action configuration */
1207 return ospf_vl_set(ospf
, &vl_config
);
1210 DEFUN (no_ospf_area_vlink_intervals
,
1211 no_ospf_area_vlink_intervals_cmd
,
1212 "no area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D {hello-interval (1-65535)|retransmit-interval (1-65535)|transmit-delay (1-65535)|dead-interval (1-65535)}",
1214 VLINK_HELPSTR_IPADDR
1215 VLINK_HELPSTR_TIME_PARAM
)
1217 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1218 struct ospf_vl_config_data vl_config
;
1221 ospf_vl_config_data_init(&vl_config
, vty
);
1223 char *area_id
= argv
[2]->arg
;
1224 char *router_id
= argv
[4]->arg
;
1226 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1228 vty_out(vty
, "OSPF area ID is invalid\n");
1229 return CMD_WARNING_CONFIG_FAILED
;
1232 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1234 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1235 return CMD_WARNING_CONFIG_FAILED
;
1238 for (int idx
= 5; idx
< argc
; idx
++) {
1239 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1240 vl_config
.hello_interval
= OSPF_HELLO_INTERVAL_DEFAULT
;
1241 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1242 vl_config
.retransmit_interval
=
1243 OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
1244 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1245 vl_config
.transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
1246 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1247 vl_config
.dead_interval
=
1248 OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
1251 /* Action configuration */
1252 return ospf_vl_set(ospf
, &vl_config
);
1255 DEFUN (ospf_area_shortcut
,
1256 ospf_area_shortcut_cmd
,
1257 "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>",
1258 "OSPF area parameters\n"
1259 "OSPF area ID in IP address format\n"
1260 "OSPF area ID as a decimal value\n"
1261 "Configure the area's shortcutting mode\n"
1262 "Set default shortcutting behavior\n"
1263 "Enable shortcutting through the area\n"
1264 "Disable shortcutting through the area\n")
1266 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1267 int idx_ipv4_number
= 1;
1268 int idx_enable_disable
= 3;
1269 struct ospf_area
*area
;
1270 struct in_addr area_id
;
1274 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1275 argv
[idx_ipv4_number
]->arg
);
1277 area
= ospf_area_get(ospf
, area_id
);
1278 ospf_area_display_format_set(ospf
, area
, format
);
1280 if (strncmp(argv
[idx_enable_disable
]->arg
, "de", 2) == 0)
1281 mode
= OSPF_SHORTCUT_DEFAULT
;
1282 else if (strncmp(argv
[idx_enable_disable
]->arg
, "di", 2) == 0)
1283 mode
= OSPF_SHORTCUT_DISABLE
;
1284 else if (strncmp(argv
[idx_enable_disable
]->arg
, "e", 1) == 0)
1285 mode
= OSPF_SHORTCUT_ENABLE
;
1287 return CMD_WARNING_CONFIG_FAILED
;
1289 ospf_area_shortcut_set(ospf
, area
, mode
);
1291 if (ospf
->abr_type
!= OSPF_ABR_SHORTCUT
)
1293 "Shortcut area setting will take effect only when the router is configured as Shortcut ABR\n");
1298 DEFUN (no_ospf_area_shortcut
,
1299 no_ospf_area_shortcut_cmd
,
1300 "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>",
1302 "OSPF area parameters\n"
1303 "OSPF area ID in IP address format\n"
1304 "OSPF area ID as a decimal value\n"
1305 "Deconfigure the area's shortcutting mode\n"
1306 "Deconfigure enabled shortcutting through the area\n"
1307 "Deconfigure disabled shortcutting through the area\n")
1309 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1310 int idx_ipv4_number
= 2;
1311 struct ospf_area
*area
;
1312 struct in_addr area_id
;
1315 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1316 argv
[idx_ipv4_number
]->arg
);
1318 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1322 ospf_area_shortcut_unset(ospf
, area
);
1328 DEFUN (ospf_area_stub
,
1330 "area <A.B.C.D|(0-4294967295)> stub",
1331 "OSPF area parameters\n"
1332 "OSPF area ID in IP address format\n"
1333 "OSPF area ID as a decimal value\n"
1334 "Configure OSPF area as stub\n")
1336 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1337 int idx_ipv4_number
= 1;
1338 struct in_addr area_id
;
1341 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1342 argv
[idx_ipv4_number
]->arg
);
1344 ret
= ospf_area_stub_set(ospf
, area_id
);
1345 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1349 "First deconfigure all virtual link through this area\n");
1350 return CMD_WARNING_CONFIG_FAILED
;
1353 /* Flush the external LSAs from the specified area */
1354 ospf_flush_lsa_from_area(ospf
, area_id
, OSPF_AS_EXTERNAL_LSA
);
1355 ospf_area_no_summary_unset(ospf
, area_id
);
1360 DEFUN (ospf_area_stub_no_summary
,
1361 ospf_area_stub_no_summary_cmd
,
1362 "area <A.B.C.D|(0-4294967295)> stub no-summary",
1363 "OSPF stub parameters\n"
1364 "OSPF area ID in IP address format\n"
1365 "OSPF area ID as a decimal value\n"
1366 "Configure OSPF area as stub\n"
1367 "Do not inject inter-area routes into stub\n")
1369 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1370 int idx_ipv4_number
= 1;
1371 struct in_addr area_id
;
1374 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1375 argv
[idx_ipv4_number
]->arg
);
1377 ret
= ospf_area_stub_set(ospf
, area_id
);
1378 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1382 "%% Area cannot be stub as it contains a virtual link\n");
1383 return CMD_WARNING_CONFIG_FAILED
;
1386 ospf_area_no_summary_set(ospf
, area_id
);
1391 DEFUN (no_ospf_area_stub
,
1392 no_ospf_area_stub_cmd
,
1393 "no area <A.B.C.D|(0-4294967295)> stub",
1395 "OSPF area parameters\n"
1396 "OSPF area ID in IP address format\n"
1397 "OSPF area ID as a decimal value\n"
1398 "Configure OSPF area as stub\n")
1400 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1401 int idx_ipv4_number
= 2;
1402 struct in_addr area_id
;
1405 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1406 argv
[idx_ipv4_number
]->arg
);
1408 ospf_area_stub_unset(ospf
, area_id
);
1409 ospf_area_no_summary_unset(ospf
, area_id
);
1414 DEFUN (no_ospf_area_stub_no_summary
,
1415 no_ospf_area_stub_no_summary_cmd
,
1416 "no area <A.B.C.D|(0-4294967295)> stub no-summary",
1418 "OSPF area parameters\n"
1419 "OSPF area ID in IP address format\n"
1420 "OSPF area ID as a decimal value\n"
1421 "Configure OSPF area as stub\n"
1422 "Do not inject inter-area routes into area\n")
1424 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1425 int idx_ipv4_number
= 2;
1426 struct in_addr area_id
;
1429 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1430 argv
[idx_ipv4_number
]->arg
);
1431 ospf_area_no_summary_unset(ospf
, area_id
);
1436 static int ospf_area_nssa_cmd_handler(struct vty
*vty
, int argc
,
1437 struct cmd_token
**argv
, int cfg_nosum
,
1440 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1441 struct in_addr area_id
;
1444 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
, argv
[1]->arg
);
1446 ret
= ospf_area_nssa_set(ospf
, area_id
);
1447 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1451 "%% Area cannot be nssa as it contains a virtual link\n");
1452 return CMD_WARNING_CONFIG_FAILED
;
1456 if (strncmp(argv
[3]->text
, "translate-c", 11) == 0)
1457 ospf_area_nssa_translator_role_set(
1458 ospf
, area_id
, OSPF_NSSA_ROLE_CANDIDATE
);
1459 else if (strncmp(argv
[3]->text
, "translate-n", 11) == 0)
1460 ospf_area_nssa_translator_role_set(
1461 ospf
, area_id
, OSPF_NSSA_ROLE_NEVER
);
1462 else if (strncmp(argv
[3]->text
, "translate-a", 11) == 0)
1463 ospf_area_nssa_translator_role_set(
1464 ospf
, area_id
, OSPF_NSSA_ROLE_ALWAYS
);
1466 ospf_area_nssa_translator_role_set(ospf
, area_id
,
1467 OSPF_NSSA_ROLE_CANDIDATE
);
1472 ospf_area_no_summary_set(ospf
, area_id
);
1474 ospf_area_no_summary_unset(ospf
, area_id
);
1477 /* Flush the external LSA for the specified area */
1478 ospf_flush_lsa_from_area(ospf
, area_id
, OSPF_AS_EXTERNAL_LSA
);
1479 ospf_schedule_abr_task(ospf
);
1480 ospf_schedule_asbr_nssa_redist_update(ospf
);
1486 DEFUN (ospf_area_nssa_translate
,
1487 ospf_area_nssa_translate_cmd
,
1488 "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always>",
1489 "OSPF area parameters\n"
1490 "OSPF area ID in IP address format\n"
1491 "OSPF area ID as a decimal value\n"
1492 "Configure OSPF area as nssa\n"
1493 "Configure NSSA-ABR for translate election (default)\n"
1494 "Configure NSSA-ABR to never translate\n"
1495 "Configure NSSA-ABR to always translate\n")
1497 return ospf_area_nssa_cmd_handler(vty
, argc
, argv
, 0, 0);
1500 DEFUN (ospf_area_nssa
,
1502 "area <A.B.C.D|(0-4294967295)> nssa",
1503 "OSPF area parameters\n"
1504 "OSPF area ID in IP address format\n"
1505 "OSPF area ID as a decimal value\n"
1506 "Configure OSPF area as nssa\n")
1508 return ospf_area_nssa_cmd_handler(vty
, argc
, argv
, 0, 0);
1511 DEFUN(ospf_area_nssa_suppress_fa
, ospf_area_nssa_suppress_fa_cmd
,
1512 "area <A.B.C.D|(0-4294967295)> nssa suppress-fa",
1513 "OSPF area parameters\n"
1514 "OSPF area ID in IP address format\n"
1515 "OSPF area ID as a decimal value\n"
1516 "Configure OSPF area as nssa\n"
1517 "Suppress forwarding address\n")
1519 int idx_ipv4_number
= 1;
1520 struct in_addr area_id
;
1523 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1524 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1525 argv
[idx_ipv4_number
]->arg
);
1527 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1529 ospf_area_nssa_suppress_fa_set(ospf
, area_id
);
1531 ospf_schedule_abr_task(ospf
);
1536 DEFUN(no_ospf_area_nssa_suppress_fa
, no_ospf_area_nssa_suppress_fa_cmd
,
1537 "no area <A.B.C.D|(0-4294967295)> nssa suppress-fa",
1539 "OSPF area parameters\n"
1540 "OSPF area ID in IP address format\n"
1541 "OSPF area ID as a decimal value\n"
1542 "Configure OSPF area as nssa\n"
1543 "Suppress forwarding address\n")
1545 int idx_ipv4_number
= 2;
1546 struct in_addr area_id
;
1549 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1551 VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id
, format
,
1552 argv
[idx_ipv4_number
]->arg
);
1554 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1556 ospf_area_nssa_suppress_fa_unset(ospf
, area_id
);
1558 ospf_schedule_abr_task(ospf
);
1563 DEFUN (ospf_area_nssa_no_summary
,
1564 ospf_area_nssa_no_summary_cmd
,
1565 "area <A.B.C.D|(0-4294967295)> nssa no-summary",
1566 "OSPF area parameters\n"
1567 "OSPF area ID in IP address format\n"
1568 "OSPF area ID as a decimal value\n"
1569 "Configure OSPF area as nssa\n"
1570 "Do not inject inter-area routes into nssa\n")
1572 int idx_ipv4_number
= 1;
1573 struct in_addr area_id
;
1576 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1577 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1578 argv
[idx_ipv4_number
]->arg
);
1580 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1582 ospf_area_nssa_no_summary_set(ospf
, area_id
);
1584 ospf_schedule_abr_task(ospf
);
1589 DEFUN (no_ospf_area_nssa_no_summary
,
1590 no_ospf_area_nssa_no_summary_cmd
,
1591 "no area <A.B.C.D|(0-4294967295)> nssa no-summary",
1593 "OSPF area parameters\n"
1594 "OSPF area ID in IP address format\n"
1595 "OSPF area ID as a decimal value\n"
1596 "Configure OSPF area as nssa\n"
1597 "Do not inject inter-area routes into nssa\n")
1599 int idx_ipv4_number
= 2;
1600 struct in_addr area_id
;
1603 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1605 VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id
, format
,
1606 argv
[idx_ipv4_number
]->arg
);
1608 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1610 ospf_area_no_summary_unset(ospf
, area_id
);
1612 ospf_schedule_abr_task(ospf
);
1617 DEFUN (no_ospf_area_nssa
,
1618 no_ospf_area_nssa_cmd
,
1619 "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always>]",
1621 "OSPF area parameters\n"
1622 "OSPF area ID in IP address format\n"
1623 "OSPF area ID as a decimal value\n"
1624 "Configure OSPF area as nssa\n"
1625 "Configure NSSA-ABR for translate election (default)\n"
1626 "Configure NSSA-ABR to never translate\n"
1627 "Configure NSSA-ABR to always translate\n")
1629 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1630 int idx_ipv4_number
= 2;
1631 struct in_addr area_id
;
1634 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1635 argv
[idx_ipv4_number
]->arg
);
1637 /* Flush the NSSA LSA for the specified area */
1638 ospf_flush_lsa_from_area(ospf
, area_id
, OSPF_AS_NSSA_LSA
);
1639 ospf_area_nssa_unset(ospf
, area_id
, argc
);
1641 ospf_schedule_abr_task(ospf
);
1647 DEFUN (ospf_area_default_cost
,
1648 ospf_area_default_cost_cmd
,
1649 "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1650 "OSPF area parameters\n"
1651 "OSPF area ID in IP address format\n"
1652 "OSPF area ID as a decimal value\n"
1653 "Set the summary-default cost of a NSSA or stub area\n"
1654 "Stub's advertised default summary cost\n")
1656 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1657 int idx_ipv4_number
= 1;
1659 struct ospf_area
*area
;
1660 struct in_addr area_id
;
1663 struct prefix_ipv4 p
;
1665 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1666 argv
[idx_ipv4_number
]->arg
);
1667 cost
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1669 area
= ospf_area_get(ospf
, area_id
);
1670 ospf_area_display_format_set(ospf
, area
, format
);
1672 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1673 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1674 return CMD_WARNING_CONFIG_FAILED
;
1677 area
->default_cost
= cost
;
1680 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1682 if (IS_DEBUG_OSPF_EVENT
)
1684 "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4",
1686 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1691 DEFUN (no_ospf_area_default_cost
,
1692 no_ospf_area_default_cost_cmd
,
1693 "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1695 "OSPF area parameters\n"
1696 "OSPF area ID in IP address format\n"
1697 "OSPF area ID as a decimal value\n"
1698 "Set the summary-default cost of a NSSA or stub area\n"
1699 "Stub's advertised default summary cost\n")
1701 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1702 int idx_ipv4_number
= 2;
1703 struct ospf_area
*area
;
1704 struct in_addr area_id
;
1706 struct prefix_ipv4 p
;
1708 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1709 argv
[idx_ipv4_number
]->arg
);
1711 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1715 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1716 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1717 return CMD_WARNING_CONFIG_FAILED
;
1720 area
->default_cost
= 1;
1723 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1725 if (IS_DEBUG_OSPF_EVENT
)
1727 "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4",
1729 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1732 ospf_area_check_free(ospf
, area_id
);
1737 DEFUN (ospf_area_export_list
,
1738 ospf_area_export_list_cmd
,
1739 "area <A.B.C.D|(0-4294967295)> export-list ACCESSLIST4_NAME",
1740 "OSPF area parameters\n"
1741 "OSPF area ID in IP address format\n"
1742 "OSPF area ID as a decimal value\n"
1743 "Set the filter for networks announced to other areas\n"
1744 "Name of the access-list\n")
1746 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1747 int idx_ipv4_number
= 1;
1748 struct ospf_area
*area
;
1749 struct in_addr area_id
;
1752 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1754 area
= ospf_area_get(ospf
, area_id
);
1755 ospf_area_display_format_set(ospf
, area
, format
);
1756 ospf_area_export_list_set(ospf
, area
, argv
[3]->arg
);
1761 DEFUN (no_ospf_area_export_list
,
1762 no_ospf_area_export_list_cmd
,
1763 "no area <A.B.C.D|(0-4294967295)> export-list ACCESSLIST4_NAME",
1765 "OSPF area parameters\n"
1766 "OSPF area ID in IP address format\n"
1767 "OSPF area ID as a decimal value\n"
1768 "Unset the filter for networks announced to other areas\n"
1769 "Name of the access-list\n")
1771 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1772 int idx_ipv4_number
= 2;
1773 struct ospf_area
*area
;
1774 struct in_addr area_id
;
1777 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1779 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1783 ospf_area_export_list_unset(ospf
, area
);
1789 DEFUN (ospf_area_import_list
,
1790 ospf_area_import_list_cmd
,
1791 "area <A.B.C.D|(0-4294967295)> import-list ACCESSLIST4_NAME",
1792 "OSPF area parameters\n"
1793 "OSPF area ID in IP address format\n"
1794 "OSPF area ID as a decimal value\n"
1795 "Set the filter for networks from other areas announced to the specified one\n"
1796 "Name of the access-list\n")
1798 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1799 int idx_ipv4_number
= 1;
1800 struct ospf_area
*area
;
1801 struct in_addr area_id
;
1804 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1806 area
= ospf_area_get(ospf
, area_id
);
1807 ospf_area_display_format_set(ospf
, area
, format
);
1808 ospf_area_import_list_set(ospf
, area
, argv
[3]->arg
);
1813 DEFUN (no_ospf_area_import_list
,
1814 no_ospf_area_import_list_cmd
,
1815 "no area <A.B.C.D|(0-4294967295)> import-list ACCESSLIST4_NAME",
1817 "OSPF area parameters\n"
1818 "OSPF area ID in IP address format\n"
1819 "OSPF area ID as a decimal value\n"
1820 "Unset the filter for networks announced to other areas\n"
1821 "Name of the access-list\n")
1823 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1824 int idx_ipv4_number
= 2;
1825 struct ospf_area
*area
;
1826 struct in_addr area_id
;
1829 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1831 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1835 ospf_area_import_list_unset(ospf
, area
);
1840 DEFUN (ospf_area_filter_list
,
1841 ospf_area_filter_list_cmd
,
1842 "area <A.B.C.D|(0-4294967295)> filter-list prefix PREFIXLIST_NAME <in|out>",
1843 "OSPF area parameters\n"
1844 "OSPF area ID in IP address format\n"
1845 "OSPF area ID as a decimal value\n"
1846 "Filter networks between OSPF areas\n"
1847 "Filter prefixes between OSPF areas\n"
1848 "Name of an IP prefix-list\n"
1849 "Filter networks sent to this area\n"
1850 "Filter networks sent from this area\n")
1852 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1853 int idx_ipv4_number
= 1;
1856 struct ospf_area
*area
;
1857 struct in_addr area_id
;
1858 struct prefix_list
*plist
;
1861 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1863 area
= ospf_area_get(ospf
, area_id
);
1864 ospf_area_display_format_set(ospf
, area
, format
);
1865 plist
= prefix_list_lookup(AFI_IP
, argv
[idx_word
]->arg
);
1866 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1867 PREFIX_LIST_IN(area
) = plist
;
1868 if (PREFIX_NAME_IN(area
))
1869 free(PREFIX_NAME_IN(area
));
1871 PREFIX_NAME_IN(area
) = strdup(argv
[idx_word
]->arg
);
1872 ospf_schedule_abr_task(ospf
);
1874 PREFIX_LIST_OUT(area
) = plist
;
1875 if (PREFIX_NAME_OUT(area
))
1876 free(PREFIX_NAME_OUT(area
));
1878 PREFIX_NAME_OUT(area
) = strdup(argv
[idx_word
]->arg
);
1879 ospf_schedule_abr_task(ospf
);
1885 DEFUN (no_ospf_area_filter_list
,
1886 no_ospf_area_filter_list_cmd
,
1887 "no area <A.B.C.D|(0-4294967295)> filter-list prefix PREFIXLIST_NAME <in|out>",
1889 "OSPF area parameters\n"
1890 "OSPF area ID in IP address format\n"
1891 "OSPF area ID as a decimal value\n"
1892 "Filter networks between OSPF areas\n"
1893 "Filter prefixes between OSPF areas\n"
1894 "Name of an IP prefix-list\n"
1895 "Filter networks sent to this area\n"
1896 "Filter networks sent from this area\n")
1898 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1899 int idx_ipv4_number
= 2;
1902 struct ospf_area
*area
;
1903 struct in_addr area_id
;
1906 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1908 if ((area
= ospf_area_lookup_by_area_id(ospf
, area_id
)) == NULL
)
1911 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1912 if (PREFIX_NAME_IN(area
))
1913 if (strcmp(PREFIX_NAME_IN(area
), argv
[idx_word
]->arg
)
1917 PREFIX_LIST_IN(area
) = NULL
;
1918 if (PREFIX_NAME_IN(area
))
1919 free(PREFIX_NAME_IN(area
));
1921 PREFIX_NAME_IN(area
) = NULL
;
1923 ospf_schedule_abr_task(ospf
);
1925 if (PREFIX_NAME_OUT(area
))
1926 if (strcmp(PREFIX_NAME_OUT(area
), argv
[idx_word
]->arg
)
1930 PREFIX_LIST_OUT(area
) = NULL
;
1931 if (PREFIX_NAME_OUT(area
))
1932 free(PREFIX_NAME_OUT(area
));
1934 PREFIX_NAME_OUT(area
) = NULL
;
1936 ospf_schedule_abr_task(ospf
);
1943 DEFUN (ospf_area_authentication_message_digest
,
1944 ospf_area_authentication_message_digest_cmd
,
1945 "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest",
1947 "OSPF area parameters\n"
1948 "OSPF area ID in IP address format\n"
1949 "OSPF area ID as a decimal value\n"
1950 "Enable authentication\n"
1951 "Use message-digest authentication\n")
1953 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1955 struct ospf_area
*area
;
1956 struct in_addr area_id
;
1959 argv_find(argv
, argc
, "area", &idx
);
1960 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx
+ 1]->arg
);
1962 area
= ospf_area_get(ospf
, area_id
);
1963 ospf_area_display_format_set(ospf
, area
, format
);
1964 area
->auth_type
= strmatch(argv
[0]->text
, "no")
1966 : OSPF_AUTH_CRYPTOGRAPHIC
;
1971 DEFUN (ospf_area_authentication
,
1972 ospf_area_authentication_cmd
,
1973 "area <A.B.C.D|(0-4294967295)> authentication",
1974 "OSPF area parameters\n"
1975 "OSPF area ID in IP address format\n"
1976 "OSPF area ID as a decimal value\n"
1977 "Enable authentication\n")
1979 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1980 int idx_ipv4_number
= 1;
1981 struct ospf_area
*area
;
1982 struct in_addr area_id
;
1985 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1987 area
= ospf_area_get(ospf
, area_id
);
1988 ospf_area_display_format_set(ospf
, area
, format
);
1989 area
->auth_type
= OSPF_AUTH_SIMPLE
;
1994 DEFUN (no_ospf_area_authentication
,
1995 no_ospf_area_authentication_cmd
,
1996 "no area <A.B.C.D|(0-4294967295)> authentication",
1998 "OSPF area parameters\n"
1999 "OSPF area ID in IP address format\n"
2000 "OSPF area ID as a decimal value\n"
2001 "Enable authentication\n")
2003 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2004 int idx_ipv4_number
= 2;
2005 struct ospf_area
*area
;
2006 struct in_addr area_id
;
2009 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
2011 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
2015 area
->auth_type
= OSPF_AUTH_NULL
;
2017 ospf_area_check_free(ospf
, area_id
);
2023 DEFUN (ospf_abr_type
,
2025 "ospf abr-type <cisco|ibm|shortcut|standard>",
2026 "OSPF specific commands\n"
2027 "Set OSPF ABR type\n"
2028 "Alternative ABR, cisco implementation\n"
2029 "Alternative ABR, IBM implementation\n"
2031 "Standard behavior (RFC2328)\n")
2033 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2035 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2037 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2038 abr_type
= OSPF_ABR_CISCO
;
2039 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2040 abr_type
= OSPF_ABR_IBM
;
2041 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2042 abr_type
= OSPF_ABR_SHORTCUT
;
2043 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2044 abr_type
= OSPF_ABR_STAND
;
2046 return CMD_WARNING_CONFIG_FAILED
;
2048 /* If ABR type value is changed, schedule ABR task. */
2049 if (ospf
->abr_type
!= abr_type
) {
2050 ospf
->abr_type
= abr_type
;
2051 ospf_schedule_abr_task(ospf
);
2057 DEFUN (no_ospf_abr_type
,
2058 no_ospf_abr_type_cmd
,
2059 "no ospf abr-type <cisco|ibm|shortcut|standard>",
2061 "OSPF specific commands\n"
2062 "Set OSPF ABR type\n"
2063 "Alternative ABR, cisco implementation\n"
2064 "Alternative ABR, IBM implementation\n"
2068 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2070 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2072 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2073 abr_type
= OSPF_ABR_CISCO
;
2074 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2075 abr_type
= OSPF_ABR_IBM
;
2076 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2077 abr_type
= OSPF_ABR_SHORTCUT
;
2078 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2079 abr_type
= OSPF_ABR_STAND
;
2081 return CMD_WARNING_CONFIG_FAILED
;
2083 /* If ABR type value is changed, schedule ABR task. */
2084 if (ospf
->abr_type
== abr_type
) {
2085 ospf
->abr_type
= OSPF_ABR_DEFAULT
;
2086 ospf_schedule_abr_task(ospf
);
2092 DEFUN (ospf_log_adjacency_changes
,
2093 ospf_log_adjacency_changes_cmd
,
2094 "log-adjacency-changes",
2095 "Log changes in adjacency state\n")
2097 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2099 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2100 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2104 DEFUN (ospf_log_adjacency_changes_detail
,
2105 ospf_log_adjacency_changes_detail_cmd
,
2106 "log-adjacency-changes detail",
2107 "Log changes in adjacency state\n"
2108 "Log all state changes\n")
2110 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2112 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2113 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2117 DEFUN (no_ospf_log_adjacency_changes
,
2118 no_ospf_log_adjacency_changes_cmd
,
2119 "no log-adjacency-changes",
2121 "Log changes in adjacency state\n")
2123 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2125 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2126 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2130 DEFUN (no_ospf_log_adjacency_changes_detail
,
2131 no_ospf_log_adjacency_changes_detail_cmd
,
2132 "no log-adjacency-changes detail",
2134 "Log changes in adjacency state\n"
2135 "Log all state changes\n")
2137 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2139 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2143 DEFUN (ospf_compatible_rfc1583
,
2144 ospf_compatible_rfc1583_cmd
,
2145 "compatible rfc1583",
2146 "OSPF compatibility list\n"
2147 "compatible with RFC 1583\n")
2149 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2151 if (!CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2152 SET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2153 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2158 DEFUN (no_ospf_compatible_rfc1583
,
2159 no_ospf_compatible_rfc1583_cmd
,
2160 "no compatible rfc1583",
2162 "OSPF compatibility list\n"
2163 "compatible with RFC 1583\n")
2165 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2167 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2168 UNSET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2169 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2174 ALIAS(ospf_compatible_rfc1583
, ospf_rfc1583_flag_cmd
,
2175 "ospf rfc1583compatibility",
2176 "OSPF specific commands\n"
2177 "Enable the RFC1583Compatibility flag\n")
2179 ALIAS(no_ospf_compatible_rfc1583
, no_ospf_rfc1583_flag_cmd
,
2180 "no ospf rfc1583compatibility", NO_STR
2181 "OSPF specific commands\n"
2182 "Disable the RFC1583Compatibility flag\n")
2184 static void ospf_table_reinstall_routes(struct ospf
*ospf
,
2185 struct route_table
*rt
)
2187 struct route_node
*rn
;
2192 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
2193 struct ospf_route
*or;
2199 if (or->type
== OSPF_DESTINATION_NETWORK
)
2200 ospf_zebra_add(ospf
, (struct prefix_ipv4
*)&rn
->p
, or);
2201 else if (or->type
== OSPF_DESTINATION_DISCARD
)
2202 ospf_zebra_add_discard(ospf
,
2203 (struct prefix_ipv4
*)&rn
->p
);
2207 static void ospf_reinstall_routes(struct ospf
*ospf
)
2209 ospf_table_reinstall_routes(ospf
, ospf
->new_table
);
2210 ospf_table_reinstall_routes(ospf
, ospf
->new_external_route
);
2213 DEFPY (ospf_send_extra_data
,
2214 ospf_send_extra_data_cmd
,
2215 "[no] ospf send-extra-data zebra",
2218 "Extra data to Zebra for display/use\n"
2221 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2223 if (no
&& CHECK_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
)) {
2224 UNSET_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
);
2225 ospf_reinstall_routes(ospf
);
2226 } else if (!CHECK_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
)) {
2227 SET_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
);
2228 ospf_reinstall_routes(ospf
);
2234 static int ospf_timers_spf_set(struct vty
*vty
, unsigned int delay
,
2235 unsigned int hold
, unsigned int max
)
2237 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2239 ospf
->spf_delay
= delay
;
2240 ospf
->spf_holdtime
= hold
;
2241 ospf
->spf_max_holdtime
= max
;
2246 DEFUN (ospf_timers_min_ls_interval
,
2247 ospf_timers_min_ls_interval_cmd
,
2248 "timers throttle lsa all (0-5000)",
2249 "Adjust routing timers\n"
2250 "Throttling adaptive timer\n"
2251 "LSA delay between transmissions\n"
2253 "Delay (msec) between sending LSAs\n")
2255 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2257 unsigned int interval
;
2260 vty_out(vty
, "Insufficient arguments\n");
2261 return CMD_WARNING_CONFIG_FAILED
;
2264 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2266 ospf
->min_ls_interval
= interval
;
2271 DEFUN (no_ospf_timers_min_ls_interval
,
2272 no_ospf_timers_min_ls_interval_cmd
,
2273 "no timers throttle lsa all [(0-5000)]",
2275 "Adjust routing timers\n"
2276 "Throttling adaptive timer\n"
2277 "LSA delay between transmissions\n"
2279 "Delay (msec) between sending LSAs\n")
2281 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2282 ospf
->min_ls_interval
= OSPF_MIN_LS_INTERVAL
;
2287 DEFUN (ospf_timers_throttle_spf
,
2288 ospf_timers_throttle_spf_cmd
,
2289 "timers throttle spf (0-600000) (0-600000) (0-600000)",
2290 "Adjust routing timers\n"
2291 "Throttling adaptive timer\n"
2293 "Delay (msec) from first change received till SPF calculation\n"
2294 "Initial hold time (msec) between consecutive SPF calculations\n"
2295 "Maximum hold time (msec)\n")
2298 int idx_number_2
= 4;
2299 int idx_number_3
= 5;
2300 unsigned int delay
, hold
, max
;
2303 vty_out(vty
, "Insufficient arguments\n");
2304 return CMD_WARNING_CONFIG_FAILED
;
2307 delay
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2308 hold
= strtoul(argv
[idx_number_2
]->arg
, NULL
, 10);
2309 max
= strtoul(argv
[idx_number_3
]->arg
, NULL
, 10);
2311 return ospf_timers_spf_set(vty
, delay
, hold
, max
);
2314 DEFUN (no_ospf_timers_throttle_spf
,
2315 no_ospf_timers_throttle_spf_cmd
,
2316 "no timers throttle spf [(0-600000)(0-600000)(0-600000)]",
2318 "Adjust routing timers\n"
2319 "Throttling adaptive timer\n"
2321 "Delay (msec) from first change received till SPF calculation\n"
2322 "Initial hold time (msec) between consecutive SPF calculations\n"
2323 "Maximum hold time (msec)\n")
2325 return ospf_timers_spf_set(vty
, OSPF_SPF_DELAY_DEFAULT
,
2326 OSPF_SPF_HOLDTIME_DEFAULT
,
2327 OSPF_SPF_MAX_HOLDTIME_DEFAULT
);
2331 DEFUN (ospf_timers_lsa_min_arrival
,
2332 ospf_timers_lsa_min_arrival_cmd
,
2333 "timers lsa min-arrival (0-600000)",
2334 "Adjust routing timers\n"
2336 "Minimum delay in receiving new version of a LSA\n"
2337 "Delay in milliseconds\n")
2339 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2340 ospf
->min_ls_arrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2344 DEFUN (no_ospf_timers_lsa_min_arrival
,
2345 no_ospf_timers_lsa_min_arrival_cmd
,
2346 "no timers lsa min-arrival [(0-600000)]",
2348 "Adjust routing timers\n"
2350 "Minimum delay in receiving new version of a LSA\n"
2351 "Delay in milliseconds\n")
2353 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2354 unsigned int minarrival
;
2357 minarrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2359 if (ospf
->min_ls_arrival
!= minarrival
2360 || minarrival
== OSPF_MIN_LS_ARRIVAL
)
2364 ospf
->min_ls_arrival
= OSPF_MIN_LS_ARRIVAL
;
2369 DEFUN (ospf_neighbor
,
2371 "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]",
2373 "Neighbor IP address\n"
2374 "Neighbor Priority\n"
2376 "Dead Neighbor Polling interval\n"
2379 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2383 struct in_addr nbr_addr
;
2384 unsigned int priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2385 unsigned int interval
= OSPF_POLL_INTERVAL_DEFAULT
;
2387 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2388 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2389 return CMD_WARNING_CONFIG_FAILED
;
2393 priority
= strtoul(argv
[idx_pri
]->arg
, NULL
, 10);
2396 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2398 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2401 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2404 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2409 DEFUN (ospf_neighbor_poll_interval
,
2410 ospf_neighbor_poll_interval_cmd
,
2411 "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2413 "Neighbor IP address\n"
2414 "Dead Neighbor Polling interval\n"
2416 "OSPF priority of non-broadcast neighbor\n"
2419 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2423 struct in_addr nbr_addr
;
2424 unsigned int priority
;
2425 unsigned int interval
;
2427 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2428 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2429 return CMD_WARNING_CONFIG_FAILED
;
2432 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2434 priority
= argc
> 4 ? strtoul(argv
[idx_pri
]->arg
, NULL
, 10)
2435 : OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2437 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2438 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2441 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2446 DEFUN (no_ospf_neighbor
,
2447 no_ospf_neighbor_cmd
,
2448 "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]",
2451 "Neighbor IP address\n"
2452 "Neighbor Priority\n"
2454 "Dead Neighbor Polling interval\n"
2457 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2459 struct in_addr nbr_addr
;
2461 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2462 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2463 return CMD_WARNING_CONFIG_FAILED
;
2466 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2471 DEFUN (no_ospf_neighbor_poll
,
2472 no_ospf_neighbor_poll_cmd
,
2473 "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2476 "Neighbor IP address\n"
2477 "Dead Neighbor Polling interval\n"
2479 "Neighbor Priority\n"
2482 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2484 struct in_addr nbr_addr
;
2486 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2487 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2488 return CMD_WARNING_CONFIG_FAILED
;
2491 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2496 DEFUN (ospf_refresh_timer
,
2497 ospf_refresh_timer_cmd
,
2498 "refresh timer (10-1800)",
2499 "Adjust refresh parameters\n"
2500 "Set refresh timer\n"
2501 "Timer value in seconds\n")
2503 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2505 unsigned int interval
;
2507 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2508 interval
= (interval
/ OSPF_LSA_REFRESHER_GRANULARITY
)
2509 * OSPF_LSA_REFRESHER_GRANULARITY
;
2511 ospf_timers_refresh_set(ospf
, interval
);
2516 DEFUN (no_ospf_refresh_timer
,
2517 no_ospf_refresh_timer_val_cmd
,
2518 "no refresh timer [(10-1800)]",
2520 "Adjust refresh parameters\n"
2521 "Unset refresh timer\n"
2522 "Timer value in seconds\n")
2524 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2526 unsigned int interval
;
2529 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2531 if (ospf
->lsa_refresh_interval
!= interval
2532 || interval
== OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
2536 ospf_timers_refresh_unset(ospf
);
2542 DEFUN (ospf_auto_cost_reference_bandwidth
,
2543 ospf_auto_cost_reference_bandwidth_cmd
,
2544 "auto-cost reference-bandwidth (1-4294967)",
2545 "Calculate OSPF interface cost according to bandwidth\n"
2546 "Use reference bandwidth method to assign OSPF cost\n"
2547 "The reference bandwidth in terms of Mbits per second\n")
2549 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2550 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2553 struct interface
*ifp
;
2555 refbw
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2556 if (refbw
< 1 || refbw
> 4294967) {
2557 vty_out(vty
, "reference-bandwidth value is invalid\n");
2558 return CMD_WARNING_CONFIG_FAILED
;
2561 /* If reference bandwidth is changed. */
2562 if ((refbw
) == ospf
->ref_bandwidth
)
2565 ospf
->ref_bandwidth
= refbw
;
2566 FOR_ALL_INTERFACES (vrf
, ifp
)
2567 ospf_if_recalculate_output_cost(ifp
);
2572 DEFUN (no_ospf_auto_cost_reference_bandwidth
,
2573 no_ospf_auto_cost_reference_bandwidth_cmd
,
2574 "no auto-cost reference-bandwidth [(1-4294967)]",
2576 "Calculate OSPF interface cost according to bandwidth\n"
2577 "Use reference bandwidth method to assign OSPF cost\n"
2578 "The reference bandwidth in terms of Mbits per second\n")
2580 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2581 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2582 struct interface
*ifp
;
2584 if (ospf
->ref_bandwidth
== OSPF_DEFAULT_REF_BANDWIDTH
)
2587 ospf
->ref_bandwidth
= OSPF_DEFAULT_REF_BANDWIDTH
;
2588 vty_out(vty
, "%% OSPF: Reference bandwidth is changed.\n");
2590 " Please ensure reference bandwidth is consistent across all routers\n");
2592 FOR_ALL_INTERFACES (vrf
, ifp
)
2593 ospf_if_recalculate_output_cost(ifp
);
2598 DEFUN (ospf_write_multiplier
,
2599 ospf_write_multiplier_cmd
,
2600 "ospf write-multiplier (1-100)",
2601 "OSPF specific commands\n"
2602 "Write multiplier\n"
2603 "Maximum number of interface serviced per write\n")
2605 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2607 uint32_t write_oi_count
;
2614 write_oi_count
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2615 if (write_oi_count
< 1 || write_oi_count
> 100) {
2616 vty_out(vty
, "write-multiplier value is invalid\n");
2617 return CMD_WARNING_CONFIG_FAILED
;
2620 ospf
->write_oi_count
= write_oi_count
;
2624 ALIAS(ospf_write_multiplier
, write_multiplier_cmd
, "write-multiplier (1-100)",
2625 "Write multiplier\n"
2626 "Maximum number of interface serviced per write\n")
2628 DEFUN (no_ospf_write_multiplier
,
2629 no_ospf_write_multiplier_cmd
,
2630 "no ospf write-multiplier (1-100)",
2632 "OSPF specific commands\n"
2633 "Write multiplier\n"
2634 "Maximum number of interface serviced per write\n")
2636 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2638 ospf
->write_oi_count
= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
;
2642 ALIAS(no_ospf_write_multiplier
, no_write_multiplier_cmd
,
2643 "no write-multiplier (1-100)", NO_STR
2644 "Write multiplier\n"
2645 "Maximum number of interface serviced per write\n")
2647 DEFUN(ospf_ti_lfa
, ospf_ti_lfa_cmd
, "fast-reroute ti-lfa [node-protection]",
2648 "Fast Reroute for MPLS and IP resilience\n"
2649 "Topology Independent LFA (Loop-Free Alternate)\n"
2650 "TI-LFA node protection (default is link protection)\n")
2652 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2654 ospf
->ti_lfa_enabled
= true;
2657 ospf
->ti_lfa_protection_type
= OSPF_TI_LFA_NODE_PROTECTION
;
2659 ospf
->ti_lfa_protection_type
= OSPF_TI_LFA_LINK_PROTECTION
;
2661 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2666 DEFUN(no_ospf_ti_lfa
, no_ospf_ti_lfa_cmd
,
2667 "no fast-reroute ti-lfa [node-protection]",
2669 "Fast Reroute for MPLS and IP resilience\n"
2670 "Topology Independent LFA (Loop-Free Alternate)\n"
2671 "TI-LFA node protection (default is link protection)\n")
2673 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2675 ospf
->ti_lfa_enabled
= false;
2677 ospf
->ti_lfa_protection_type
= OSPF_TI_LFA_UNDEFINED_PROTECTION
;
2679 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2684 static void ospf_maxpath_set(struct vty
*vty
, struct ospf
*ospf
, uint16_t paths
)
2686 if (ospf
->max_multipath
== paths
)
2689 ospf
->max_multipath
= paths
;
2691 /* Send deletion notification to zebra to delete all
2692 * ospf specific routes and reinitiat SPF to reflect
2693 * the new max multipath.
2695 ospf_restart_spf(ospf
);
2698 /* Ospf Maximum multiple paths config support */
2699 DEFUN (ospf_max_multipath
,
2700 ospf_max_multipath_cmd
,
2701 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM
),
2702 "Max no of multiple paths for ECMP support\n"
2703 "Number of paths\n")
2705 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2709 maxpaths
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2711 ospf_maxpath_set(vty
, ospf
, maxpaths
);
2715 DEFUN (no_ospf_max_multipath
,
2716 no_ospf_max_multipath_cmd
,
2719 "Max no of multiple paths for ECMP support\n")
2721 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2722 uint16_t maxpaths
= MULTIPATH_NUM
;
2724 ospf_maxpath_set(vty
, ospf
, maxpaths
);
2728 static const char *const ospf_abr_type_descr_str
[] = {
2729 "Unknown", "Standard (RFC2328)", "Alternative IBM",
2730 "Alternative Cisco", "Alternative Shortcut"
2733 static const char *const ospf_shortcut_mode_descr_str
[] = {
2734 "Default", "Enabled", "Disabled"
2737 static void show_ip_ospf_area(struct vty
*vty
, struct ospf_area
*area
,
2738 json_object
*json_areas
, bool use_json
)
2740 json_object
*json_area
= NULL
;
2741 char buf
[PREFIX_STRLEN
];
2744 json_area
= json_object_new_object();
2748 vty_out(vty
, " Area ID: %pI4", &area
->area_id
);
2750 /* Show Area type/mode. */
2751 if (OSPF_IS_AREA_BACKBONE(area
)) {
2753 json_object_boolean_true_add(json_area
, "backbone");
2755 vty_out(vty
, " (Backbone)\n");
2758 if (area
->external_routing
== OSPF_AREA_STUB
) {
2759 if (area
->no_summary
)
2760 json_object_boolean_true_add(
2761 json_area
, "stubNoSummary");
2762 if (area
->shortcut_configured
)
2763 json_object_boolean_true_add(
2764 json_area
, "stubShortcut");
2765 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
2766 if (area
->no_summary
)
2767 json_object_boolean_true_add(
2768 json_area
, "nssaNoSummary");
2769 if (area
->shortcut_configured
)
2770 json_object_boolean_true_add(
2771 json_area
, "nssaShortcut");
2774 json_object_string_add(
2775 json_area
, "shortcuttingMode",
2776 ospf_shortcut_mode_descr_str
2777 [area
->shortcut_configured
]);
2778 if (area
->shortcut_capability
)
2779 json_object_boolean_true_add(json_area
,
2782 if (area
->external_routing
== OSPF_AREA_STUB
)
2783 vty_out(vty
, " (Stub%s%s)",
2784 area
->no_summary
? ", no summary" : "",
2785 area
->shortcut_configured
? "; " : "");
2786 else if (area
->external_routing
== OSPF_AREA_NSSA
)
2787 vty_out(vty
, " (NSSA%s%s)",
2788 area
->no_summary
? ", no summary" : "",
2789 area
->shortcut_configured
? "; " : "");
2792 vty_out(vty
, " Shortcutting mode: %s",
2793 ospf_shortcut_mode_descr_str
2794 [area
->shortcut_configured
]);
2795 vty_out(vty
, ", S-bit consensus: %s\n",
2796 area
->shortcut_capability
? "ok" : "no");
2800 /* Show number of interfaces */
2802 json_object_int_add(json_area
, "areaIfTotalCounter",
2803 listcount(area
->oiflist
));
2804 json_object_int_add(json_area
, "areaIfActiveCounter",
2808 " Number of interfaces in this area: Total: %d, Active: %d\n",
2809 listcount(area
->oiflist
), area
->act_ints
);
2811 if (area
->external_routing
== OSPF_AREA_NSSA
) {
2813 json_object_boolean_true_add(json_area
, "nssa");
2814 if (!IS_OSPF_ABR(area
->ospf
))
2815 json_object_boolean_false_add(json_area
, "abr");
2816 else if (area
->NSSATranslatorState
) {
2817 json_object_boolean_true_add(json_area
, "abr");
2818 if (area
->NSSATranslatorRole
2819 == OSPF_NSSA_ROLE_CANDIDATE
)
2820 json_object_boolean_true_add(
2822 "nssaTranslatorElected");
2823 else if (area
->NSSATranslatorRole
2824 == OSPF_NSSA_ROLE_ALWAYS
)
2825 json_object_boolean_true_add(
2827 "nssaTranslatorAlways");
2829 json_object_boolean_true_add(
2831 "nssaTranslatorNever");
2833 json_object_boolean_true_add(json_area
, "abr");
2834 if (area
->NSSATranslatorRole
2835 == OSPF_NSSA_ROLE_CANDIDATE
)
2836 json_object_boolean_false_add(
2838 "nssaTranslatorElected");
2840 json_object_boolean_true_add(
2842 "nssaTranslatorNever");
2846 " It is an NSSA configuration.\n Elected NSSA/ABR performs type-7/type-5 LSA translation.\n");
2847 if (!IS_OSPF_ABR(area
->ospf
))
2849 " It is not ABR, therefore not Translator.\n");
2850 else if (area
->NSSATranslatorState
) {
2851 vty_out(vty
, " We are an ABR and ");
2852 if (area
->NSSATranslatorRole
2853 == OSPF_NSSA_ROLE_CANDIDATE
)
2855 "the NSSA Elected Translator.\n");
2856 else if (area
->NSSATranslatorRole
2857 == OSPF_NSSA_ROLE_ALWAYS
)
2859 "always an NSSA Translator.\n");
2862 "never an NSSA Translator.\n");
2864 vty_out(vty
, " We are an ABR, but ");
2865 if (area
->NSSATranslatorRole
2866 == OSPF_NSSA_ROLE_CANDIDATE
)
2868 "not the NSSA Elected Translator.\n");
2871 "never an NSSA Translator.\n");
2876 /* Stub-router state for this area */
2877 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
)) {
2878 char timebuf
[OSPF_TIME_DUMP_SIZE
];
2881 json_object_boolean_true_add(
2882 json_area
, "originStubMaxDistRouterLsa");
2883 if (CHECK_FLAG(area
->stub_router_state
,
2884 OSPF_AREA_ADMIN_STUB_ROUTED
))
2885 json_object_boolean_true_add(
2886 json_area
, "indefiniteActiveAdmin");
2887 if (area
->t_stub_router
) {
2891 &area
->t_stub_router
->u
.sands
,
2894 json_object_int_add(
2896 "activeStartupRemainderMsecs",
2901 " Originating stub / maximum-distance Router-LSA\n");
2902 if (CHECK_FLAG(area
->stub_router_state
,
2903 OSPF_AREA_ADMIN_STUB_ROUTED
))
2905 " Administratively activated (indefinitely)\n");
2906 if (area
->t_stub_router
)
2908 " Active from startup, %s remaining\n",
2909 ospf_timer_dump(area
->t_stub_router
,
2916 /* Show number of fully adjacent neighbors. */
2917 json_object_int_add(json_area
, "nbrFullAdjacentCounter",
2920 /* Show authentication type. */
2921 if (area
->auth_type
== OSPF_AUTH_NULL
)
2922 json_object_string_add(json_area
, "authentication",
2923 "authenticationNone");
2924 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2925 json_object_string_add(json_area
, "authentication",
2926 "authenticationSimplePassword");
2927 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2928 json_object_string_add(json_area
, "authentication",
2929 "authenticationMessageDigest");
2931 if (!OSPF_IS_AREA_BACKBONE(area
))
2932 json_object_int_add(json_area
,
2933 "virtualAdjacenciesPassingCounter",
2936 /* Show SPF calculation times. */
2937 json_object_int_add(json_area
, "spfExecutedCounter",
2938 area
->spf_calculation
);
2939 json_object_int_add(json_area
, "lsaNumber", area
->lsdb
->total
);
2940 json_object_int_add(
2941 json_area
, "lsaRouterNumber",
2942 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
));
2943 json_object_int_add(
2944 json_area
, "lsaRouterChecksum",
2945 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
2946 json_object_int_add(
2947 json_area
, "lsaNetworkNumber",
2948 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
));
2949 json_object_int_add(
2950 json_area
, "lsaNetworkChecksum",
2951 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
2952 json_object_int_add(
2953 json_area
, "lsaSummaryNumber",
2954 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
));
2955 json_object_int_add(
2956 json_area
, "lsaSummaryChecksum",
2957 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
2958 json_object_int_add(
2959 json_area
, "lsaAsbrNumber",
2960 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2961 json_object_int_add(
2962 json_area
, "lsaAsbrChecksum",
2963 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2964 json_object_int_add(
2965 json_area
, "lsaNssaNumber",
2966 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2967 json_object_int_add(
2968 json_area
, "lsaNssaChecksum",
2969 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2971 /* Show number of fully adjacent neighbors. */
2973 " Number of fully adjacent neighbors in this area: %d\n",
2976 /* Show authentication type. */
2977 vty_out(vty
, " Area has ");
2978 if (area
->auth_type
== OSPF_AUTH_NULL
)
2979 vty_out(vty
, "no authentication\n");
2980 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2981 vty_out(vty
, "simple password authentication\n");
2982 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2983 vty_out(vty
, "message digest authentication\n");
2985 if (!OSPF_IS_AREA_BACKBONE(area
))
2987 " Number of full virtual adjacencies going through this area: %d\n",
2990 /* Show SPF calculation times. */
2991 vty_out(vty
, " SPF algorithm executed %d times\n",
2992 area
->spf_calculation
);
2994 /* Show number of LSA. */
2995 vty_out(vty
, " Number of LSA %ld\n", area
->lsdb
->total
);
2997 " Number of router LSA %ld. Checksum Sum 0x%08x\n",
2998 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
),
2999 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
3001 " Number of network LSA %ld. Checksum Sum 0x%08x\n",
3002 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
),
3003 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
3005 " Number of summary LSA %ld. Checksum Sum 0x%08x\n",
3006 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
),
3007 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
3009 " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n",
3010 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
),
3011 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
3012 vty_out(vty
, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n",
3013 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
),
3014 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
3018 json_object_int_add(
3019 json_area
, "lsaOpaqueLinkNumber",
3020 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
3021 json_object_int_add(
3022 json_area
, "lsaOpaqueLinkChecksum",
3023 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
3024 json_object_int_add(
3025 json_area
, "lsaOpaqueAreaNumber",
3026 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
3027 json_object_int_add(
3028 json_area
, "lsaOpaqueAreaChecksum",
3029 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
3032 " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n",
3033 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
),
3034 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
3036 " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n",
3037 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
),
3038 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
3041 if (area
->fr_info
.configured
) {
3043 json_object_string_add(json_area
, "areaFloodReduction",
3046 vty_out(vty
, " Flood Reduction is configured.\n");
3049 if (area
->fr_info
.enabled
) {
3051 json_object_boolean_true_add(
3052 json_area
, "areaFloodReductionEnabled");
3053 if (area
->fr_info
.router_lsas_recv_dc_bit
)
3054 json_object_boolean_true_add(
3055 json_area
, "lsasRecvDCbitSet");
3056 if (area
->fr_info
.area_ind_lsa_recvd
)
3057 json_object_string_add(json_area
,
3058 "areaIndicationLsaRecv",
3060 if (area
->fr_info
.indication_lsa_self
)
3061 json_object_string_addf(
3062 json_area
, "areaIndicationLsa", "%pI4",
3063 &area
->fr_info
.indication_lsa_self
->data
3066 vty_out(vty
, " Flood Reduction is enabled.\n");
3067 vty_out(vty
, " No of LSAs rcv'd with DC bit set %d\n",
3068 area
->fr_info
.router_lsas_recv_dc_bit
);
3069 if (area
->fr_info
.area_ind_lsa_recvd
)
3070 vty_out(vty
, " Ind LSA by other abr.\n");
3071 if (area
->fr_info
.indication_lsa_self
)
3072 vty_out(vty
, " Ind LSA generated %pI4\n",
3073 &area
->fr_info
.indication_lsa_self
->data
3079 json_object_object_add(json_areas
,
3080 inet_ntop(AF_INET
, &area
->area_id
,
3087 static int show_ip_ospf_common(struct vty
*vty
, struct ospf
*ospf
,
3088 json_object
*json
, uint8_t use_vrf
)
3090 struct listnode
*node
, *nnode
;
3091 struct ospf_area
*area
;
3092 struct timeval result
;
3093 char timebuf
[OSPF_TIME_DUMP_SIZE
];
3094 json_object
*json_vrf
= NULL
;
3095 json_object
*json_areas
= NULL
;
3099 json_vrf
= json_object_new_object();
3102 json_areas
= json_object_new_object();
3105 if (ospf
->instance
) {
3107 json_object_int_add(json
, "ospfInstance",
3110 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
3114 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3116 /* Show Router ID. */
3118 json_object_string_addf(json_vrf
, "routerId", "%pI4",
3121 vty_out(vty
, " OSPF Routing Process, Router ID: %pI4\n",
3125 /* Graceful shutdown */
3126 if (ospf
->t_deferred_shutdown
) {
3131 &ospf
->t_deferred_shutdown
->u
.sands
,
3134 json_object_int_add(json_vrf
, "deferredShutdownMsecs",
3138 " Deferred shutdown in progress, %s remaining\n",
3139 ospf_timer_dump(ospf
->t_deferred_shutdown
,
3140 timebuf
, sizeof(timebuf
)));
3144 /* Show capability. */
3146 json_object_boolean_true_add(json_vrf
, "tosRoutesOnly");
3147 json_object_boolean_true_add(json_vrf
, "rfc2328Conform");
3148 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
3149 json_object_boolean_true_add(json_vrf
,
3150 "rfc1583Compatibility");
3153 vty_out(vty
, " Supports only single TOS (TOS0) routes\n");
3154 vty_out(vty
, " This implementation conforms to RFC2328\n");
3155 vty_out(vty
, " RFC1583Compatibility flag is %s\n",
3156 CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)
3162 if (CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)) {
3163 json_object_boolean_true_add(json_vrf
, "opaqueCapable");
3166 vty_out(vty
, " OpaqueCapability flag is %s\n",
3167 CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)
3172 /* Show stub-router configuration */
3173 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
3174 || ospf
->stub_router_shutdown_time
3175 != OSPF_STUB_ROUTER_UNCONFIGURED
) {
3177 json_object_boolean_true_add(json_vrf
,
3178 "stubAdvertisement");
3179 if (ospf
->stub_router_startup_time
3180 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3181 json_object_int_add(
3182 json_vrf
, "postStartEnabledSecs",
3183 ospf
->stub_router_startup_time
);
3184 if (ospf
->stub_router_shutdown_time
3185 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3186 json_object_int_add(
3187 json_vrf
, "preShutdownEnabledSecs",
3188 ospf
->stub_router_shutdown_time
);
3191 " Stub router advertisement is configured\n");
3192 if (ospf
->stub_router_startup_time
3193 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3195 " Enabled for %us after start-up\n",
3196 ospf
->stub_router_startup_time
);
3197 if (ospf
->stub_router_shutdown_time
3198 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3200 " Enabled for %us prior to full shutdown\n",
3201 ospf
->stub_router_shutdown_time
);
3205 /* Show SPF timers. */
3207 json_object_int_add(json_vrf
, "spfScheduleDelayMsecs",
3209 json_object_int_add(json_vrf
, "holdtimeMinMsecs",
3210 ospf
->spf_holdtime
);
3211 json_object_int_add(json_vrf
, "holdtimeMaxMsecs",
3212 ospf
->spf_max_holdtime
);
3213 json_object_int_add(json_vrf
, "holdtimeMultplier",
3214 ospf
->spf_hold_multiplier
);
3217 " Initial SPF scheduling delay %d millisec(s)\n"
3218 " Minimum hold time between consecutive SPFs %d millisec(s)\n"
3219 " Maximum hold time between consecutive SPFs %d millisec(s)\n"
3220 " Hold time multiplier is currently %d\n",
3221 ospf
->spf_delay
, ospf
->spf_holdtime
,
3222 ospf
->spf_max_holdtime
, ospf
->spf_hold_multiplier
);
3226 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3227 long time_store
= 0;
3230 monotime_since(&ospf
->ts_spf
, NULL
) / 1000LL;
3231 json_object_int_add(json_vrf
, "spfLastExecutedMsecs",
3234 time_store
= (1000 * ospf
->ts_spf_duration
.tv_sec
)
3235 + (ospf
->ts_spf_duration
.tv_usec
/ 1000);
3236 json_object_int_add(json_vrf
, "spfLastDurationMsecs",
3239 json_object_boolean_true_add(json_vrf
, "spfHasNotRun");
3241 vty_out(vty
, " SPF algorithm ");
3242 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3243 monotime_since(&ospf
->ts_spf
, &result
);
3244 vty_out(vty
, "last executed %s ago\n",
3245 ospf_timeval_dump(&result
, timebuf
,
3247 vty_out(vty
, " Last SPF duration %s\n",
3248 ospf_timeval_dump(&ospf
->ts_spf_duration
,
3249 timebuf
, sizeof(timebuf
)));
3251 vty_out(vty
, "has not been run\n");
3255 if (ospf
->t_spf_calc
) {
3258 monotime_until(&ospf
->t_spf_calc
->u
.sands
, NULL
)
3260 json_object_int_add(json_vrf
, "spfTimerDueInMsecs",
3264 json_object_int_add(json_vrf
, "lsaMinIntervalMsecs",
3265 ospf
->min_ls_interval
);
3266 json_object_int_add(json_vrf
, "lsaMinArrivalMsecs",
3267 ospf
->min_ls_arrival
);
3268 /* Show write multiplier values */
3269 json_object_int_add(json_vrf
, "writeMultiplier",
3270 ospf
->write_oi_count
);
3271 /* Show refresh parameters. */
3272 json_object_int_add(json_vrf
, "refreshTimerMsecs",
3273 ospf
->lsa_refresh_interval
* 1000);
3275 /* show max multipath */
3276 json_object_int_add(json_vrf
, "maximumPaths",
3277 ospf
->max_multipath
);
3279 /* show administrative distance */
3280 json_object_int_add(json_vrf
, "preference",
3282 ? ospf
->distance_all
3283 : ZEBRA_OSPF_DISTANCE_DEFAULT
);
3285 vty_out(vty
, " SPF timer %s%s\n",
3286 (ospf
->t_spf_calc
? "due in " : "is "),
3287 ospf_timer_dump(ospf
->t_spf_calc
, timebuf
,
3290 vty_out(vty
, " LSA minimum interval %d msecs\n",
3291 ospf
->min_ls_interval
);
3292 vty_out(vty
, " LSA minimum arrival %d msecs\n",
3293 ospf
->min_ls_arrival
);
3295 /* Show write multiplier values */
3296 vty_out(vty
, " Write Multiplier set to %d \n",
3297 ospf
->write_oi_count
);
3299 /* Show refresh parameters. */
3300 vty_out(vty
, " Refresh timer %d secs\n",
3301 ospf
->lsa_refresh_interval
);
3303 /* show max multipath */
3304 vty_out(vty
, " Maximum multiple paths(ECMP) supported %d\n",
3305 ospf
->max_multipath
);
3307 /* show administrative distance */
3308 vty_out(vty
, " Administrative distance %u\n",
3309 ospf
->distance_all
? ospf
->distance_all
3310 : ZEBRA_OSPF_DISTANCE_DEFAULT
);
3313 if (ospf
->fr_configured
) {
3315 json_object_string_add(json_vrf
, "floodReduction",
3318 vty_out(vty
, " Flood Reduction is configured.\n");
3321 /* Show ABR/ASBR flags. */
3322 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ABR
)) {
3324 json_object_string_add(
3325 json_vrf
, "abrType",
3326 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3329 " This router is an ABR, ABR type is: %s\n",
3330 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3332 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ASBR
)) {
3334 json_object_string_add(
3335 json_vrf
, "asbrRouter",
3336 "injectingExternalRoutingInformation");
3339 " This router is an ASBR (injecting external routing information)\n");
3342 /* Show Number of AS-external-LSAs. */
3344 json_object_int_add(
3345 json_vrf
, "lsaExternalCounter",
3346 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3347 json_object_int_add(
3348 json_vrf
, "lsaExternalChecksum",
3349 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3352 " Number of external LSA %ld. Checksum Sum 0x%08x\n",
3353 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
),
3354 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3358 json_object_int_add(
3359 json_vrf
, "lsaAsopaqueCounter",
3360 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3361 json_object_int_add(
3362 json_vrf
, "lsaAsOpaqueChecksum",
3363 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3366 " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n",
3367 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
),
3368 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3371 /* Show number of areas attached. */
3373 json_object_int_add(json_vrf
, "attachedAreaCounter",
3374 listcount(ospf
->areas
));
3376 vty_out(vty
, " Number of areas attached to this router: %d\n",
3377 listcount(ospf
->areas
));
3379 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
3380 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
)) {
3382 json_object_boolean_true_add(
3383 json_vrf
, "adjacencyChangesLoggedAll");
3386 " All adjacency changes are logged\n");
3389 json_object_boolean_true_add(
3390 json_vrf
, "adjacencyChangesLogged");
3392 vty_out(vty
, " Adjacency changes are logged\n");
3396 /* show LDP-Sync status */
3397 ospf_ldp_sync_show_info(vty
, ospf
, json_vrf
, json
? 1 : 0);
3399 /* Show each area status. */
3400 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
3401 show_ip_ospf_area(vty
, area
, json_areas
, json
? 1 : 0);
3405 json_object_object_add(json_vrf
, "areas", json_areas
);
3406 json_object_object_add(json
, ospf_get_name(ospf
),
3409 json_object_object_add(json
, "areas", json_areas
);
3417 DEFUN (show_ip_ospf
,
3419 "show ip ospf [vrf <NAME|all>] [json]",
3422 "OSPF information\n"
3428 bool uj
= use_json(argc
, argv
);
3429 struct listnode
*node
= NULL
;
3430 char *vrf_name
= NULL
;
3431 bool all_vrf
= false;
3432 int ret
= CMD_SUCCESS
;
3435 json_object
*json
= NULL
;
3436 uint8_t use_vrf
= 0;
3438 if (listcount(om
->ospf
) == 0)
3441 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
3444 json
= json_object_new_object();
3446 /* vrf input is provided could be all or specific vrf*/
3448 bool ospf_output
= false;
3453 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
3454 if (!ospf
->oi_running
)
3457 ret
= show_ip_ospf_common(vty
, ospf
, json
,
3461 vty_json(vty
, json
);
3462 else if (!ospf_output
)
3463 vty_out(vty
, "%% OSPF is not enabled\n");
3466 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
3467 if ((ospf
== NULL
) || !ospf
->oi_running
) {
3469 vty_json(vty
, json
);
3472 "%% OSPF is not enabled in vrf %s\n",
3478 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
3479 /* Display default ospf (instance 0) info */
3480 if (ospf
== NULL
|| !ospf
->oi_running
) {
3482 vty_json(vty
, json
);
3485 "%% OSPF is not enabled in vrf default\n");
3492 show_ip_ospf_common(vty
, ospf
, json
, use_vrf
);
3494 vty_out(vty
, "%s\n",
3495 json_object_to_json_string_ext(
3496 json
, JSON_C_TO_STRING_PRETTY
));
3500 json_object_free(json
);
3505 DEFUN (show_ip_ospf_instance
,
3506 show_ip_ospf_instance_cmd
,
3507 "show ip ospf (1-65535) [json]",
3510 "OSPF information\n"
3516 unsigned short instance
= 0;
3517 bool uj
= use_json(argc
, argv
);
3518 int ret
= CMD_SUCCESS
;
3519 json_object
*json
= NULL
;
3521 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
3522 if (instance
!= ospf_instance
)
3523 return CMD_NOT_MY_INSTANCE
;
3525 ospf
= ospf_lookup_instance(instance
);
3526 if (!ospf
|| !ospf
->oi_running
)
3530 json
= json_object_new_object();
3532 ret
= show_ip_ospf_common(vty
, ospf
, json
, 0);
3535 vty_json(vty
, json
);
3540 static void ospf_interface_auth_show(struct vty
*vty
, struct ospf_interface
*oi
,
3541 json_object
*json
, bool use_json
)
3545 auth_type
= OSPF_IF_PARAM(oi
, auth_type
);
3547 switch (auth_type
) {
3548 case OSPF_AUTH_NULL
:
3550 json_object_string_add(json
, "authentication",
3551 "authenticationNone");
3553 vty_out(vty
, " Authentication NULL is enabled\n");
3555 case OSPF_AUTH_SIMPLE
: {
3557 json_object_string_add(json
, "authentication",
3558 "authenticationSimplePassword");
3561 " Simple password authentication enabled\n");
3564 case OSPF_AUTH_CRYPTOGRAPHIC
: {
3565 struct crypt_key
*ckey
;
3567 if (list_isempty(OSPF_IF_PARAM(oi
, auth_crypt
)))
3570 ckey
= listgetdata(listtail(OSPF_IF_PARAM(oi
, auth_crypt
)));
3573 json_object_string_add(json
, "authentication",
3574 "authenticationMessageDigest");
3577 " Cryptographic authentication enabled\n");
3578 vty_out(vty
, " Algorithm:MD5\n");
3588 static void show_ip_ospf_interface_sub(struct vty
*vty
, struct ospf
*ospf
,
3589 struct interface
*ifp
,
3590 json_object
*json_interface_sub
,
3594 struct ospf_neighbor
*nbr
;
3595 struct route_node
*rn
;
3596 uint32_t bandwidth
= ifp
->bandwidth
? ifp
->bandwidth
: ifp
->speed
;
3598 /* Is interface up? */
3600 is_up
= if_is_operative(ifp
);
3602 json_object_boolean_true_add(json_interface_sub
,
3605 json_object_boolean_false_add(json_interface_sub
,
3608 json_object_int_add(json_interface_sub
, "ifIndex",
3610 json_object_int_add(json_interface_sub
, "mtuBytes", ifp
->mtu
);
3611 json_object_int_add(json_interface_sub
, "bandwidthMbit",
3613 json_object_string_add(json_interface_sub
, "ifFlags",
3614 if_flag_dump(ifp
->flags
));
3616 vty_out(vty
, "%s is %s\n", ifp
->name
,
3617 ((is_up
= if_is_operative(ifp
)) ? "up" : "down"));
3618 vty_out(vty
, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n",
3619 ifp
->ifindex
, ifp
->mtu
, bandwidth
,
3620 if_flag_dump(ifp
->flags
));
3623 /* Is interface OSPF enabled? */
3625 if (ospf_oi_count(ifp
) == 0) {
3626 json_object_boolean_false_add(json_interface_sub
,
3629 } else if (!is_up
) {
3630 json_object_boolean_false_add(json_interface_sub
,
3634 json_object_boolean_true_add(json_interface_sub
,
3637 if (ospf_oi_count(ifp
) == 0) {
3638 vty_out(vty
, " OSPF not enabled on this interface\n");
3640 } else if (!is_up
) {
3642 " OSPF is enabled, but not running on this interface\n");
3647 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
3648 struct ospf_interface
*oi
= rn
->info
;
3653 if (CHECK_FLAG(oi
->connected
->flags
, ZEBRA_IFA_UNNUMBERED
)) {
3655 json_object_boolean_true_add(json_interface_sub
,
3658 vty_out(vty
, " This interface is UNNUMBERED,");
3660 struct in_addr dest
;
3663 /* Show OSPF interface information. */
3665 json_object_string_addf(
3666 json_interface_sub
, "ipAddress", "%pI4",
3667 &oi
->address
->u
.prefix4
);
3668 json_object_int_add(json_interface_sub
,
3669 "ipAddressPrefixlen",
3670 oi
->address
->prefixlen
);
3672 vty_out(vty
, " Internet Address %pFX,",
3675 /* For Vlinks, showing the peer address is
3676 * probably more informative than the local
3677 * interface that is being used */
3678 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
) {
3680 dest
= oi
->vl_data
->peer_addr
;
3681 } else if (CONNECTED_PEER(oi
->connected
)
3682 && oi
->connected
->destination
) {
3684 dest
= oi
->connected
->destination
->u
.prefix4
;
3687 dest
.s_addr
= ipv4_broadcast_addr(
3688 oi
->connected
->address
->u
.prefix4
.s_addr
,
3689 oi
->connected
->address
->prefixlen
);
3693 json_object_string_add(
3695 "ospfIfType", dstr
);
3696 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3697 json_object_string_addf(
3698 json_interface_sub
, "vlinkPeer",
3701 json_object_string_addf(
3703 "localIfUsed", "%pI4", &dest
);
3705 vty_out(vty
, " %s %pI4,", dstr
,
3709 json_object_string_add(json_interface_sub
, "area",
3710 ospf_area_desc_string(oi
->area
));
3711 if (OSPF_IF_PARAM(oi
, mtu_ignore
))
3712 json_object_boolean_true_add(
3714 "mtuMismatchDetect");
3715 json_object_string_addf(json_interface_sub
, "routerId",
3716 "%pI4", &ospf
->router_id
);
3717 json_object_string_add(json_interface_sub
,
3719 ospf_network_type_str
[oi
->type
]);
3720 json_object_int_add(json_interface_sub
, "cost",
3722 json_object_int_add(
3723 json_interface_sub
, "transmitDelaySecs",
3724 OSPF_IF_PARAM(oi
, transmit_delay
));
3725 json_object_string_add(json_interface_sub
, "state",
3726 lookup_msg(ospf_ism_state_msg
,
3728 json_object_int_add(json_interface_sub
, "priority",
3731 vty_out(vty
, " Area %s\n",
3732 ospf_area_desc_string(oi
->area
));
3734 vty_out(vty
, " MTU mismatch detection: %s\n",
3735 OSPF_IF_PARAM(oi
, mtu_ignore
) ? "disabled"
3739 " Router ID %pI4, Network Type %s, Cost: %d\n",
3741 ospf_network_type_str
[oi
->type
],
3745 " Transmit Delay is %d sec, State %s, Priority %d\n",
3746 OSPF_IF_PARAM(oi
, transmit_delay
),
3747 lookup_msg(ospf_ism_state_msg
, oi
->state
, NULL
),
3751 /* Show DR information. */
3752 if (DR(oi
).s_addr
== INADDR_ANY
) {
3755 " No backup designated router on this network\n");
3757 nbr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &DR(oi
));
3760 json_object_string_addf(
3761 json_interface_sub
, "drId",
3762 "%pI4", &nbr
->router_id
);
3763 json_object_string_addf(
3764 json_interface_sub
, "drAddress",
3766 &nbr
->address
.u
.prefix4
);
3769 " Designated Router (ID) %pI4",
3772 " Interface Address %pFX\n",
3778 nbr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &BDR(oi
));
3782 " No backup designated router on this network\n");
3785 json_object_string_addf(
3786 json_interface_sub
, "bdrId",
3787 "%pI4", &nbr
->router_id
);
3788 json_object_string_addf(
3790 "bdrAddress", "%pI4",
3791 &nbr
->address
.u
.prefix4
);
3794 " Backup Designated Router (ID) %pI4,",
3796 vty_out(vty
, " Interface Address %pI4\n",
3797 &nbr
->address
.u
.prefix4
);
3802 /* Next network-LSA sequence number we'll use, if we're elected
3805 && ntohl(oi
->params
->network_lsa_seqnum
)
3806 != OSPF_INITIAL_SEQUENCE_NUMBER
) {
3808 json_object_int_add(
3810 "networkLsaSequence",
3811 ntohl(oi
->params
->network_lsa_seqnum
));
3814 " Saved Network-LSA sequence number 0x%x\n",
3815 ntohl(oi
->params
->network_lsa_seqnum
));
3819 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3820 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3821 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3822 json_object_boolean_true_add(
3824 "mcastMemberOspfAllRouters");
3825 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3826 json_object_boolean_true_add(
3828 "mcastMemberOspfDesignatedRouters");
3831 vty_out(vty
, " Multicast group memberships:");
3832 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3833 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3834 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3835 vty_out(vty
, " OSPFAllRouters");
3836 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3837 vty_out(vty
, " OSPFDesignatedRouters");
3839 vty_out(vty
, " <None>");
3844 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3845 json_object_int_add(
3846 json_interface_sub
, "timerMsecs",
3847 OSPF_IF_PARAM(oi
, v_hello
) * 1000);
3849 json_object_int_add(
3850 json_interface_sub
, "timerMsecs",
3851 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3852 json_object_int_add(json_interface_sub
,
3854 OSPF_IF_PARAM(oi
, v_wait
));
3855 json_object_int_add(json_interface_sub
,
3857 OSPF_IF_PARAM(oi
, v_wait
));
3858 json_object_int_add(
3859 json_interface_sub
, "timerRetransmitSecs",
3860 OSPF_IF_PARAM(oi
, retransmit_interval
));
3862 vty_out(vty
, " Timer intervals configured,");
3863 vty_out(vty
, " Hello ");
3864 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3865 vty_out(vty
, "%ds,",
3866 OSPF_IF_PARAM(oi
, v_hello
));
3868 vty_out(vty
, "%dms,",
3869 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3870 vty_out(vty
, " Dead %ds, Wait %ds, Retransmit %d\n",
3871 OSPF_IF_PARAM(oi
, v_wait
),
3872 OSPF_IF_PARAM(oi
, v_wait
),
3873 OSPF_IF_PARAM(oi
, retransmit_interval
));
3876 if (OSPF_IF_PASSIVE_STATUS(oi
) == OSPF_IF_ACTIVE
) {
3877 char timebuf
[OSPF_TIME_DUMP_SIZE
];
3879 long time_store
= 0;
3883 &oi
->t_hello
->u
.sands
,
3886 json_object_int_add(json_interface_sub
,
3887 "timerHelloInMsecs",
3890 vty_out(vty
, " Hello due in %s\n",
3891 ospf_timer_dump(oi
->t_hello
, timebuf
,
3893 } else /* passive-interface is set */
3896 json_object_boolean_true_add(
3898 "timerPassiveIface");
3901 " No Hellos (Passive interface)\n");
3905 json_object_int_add(json_interface_sub
, "nbrCount",
3906 ospf_nbr_count(oi
, 0));
3907 json_object_int_add(json_interface_sub
,
3909 ospf_nbr_count(oi
, NSM_Full
));
3912 " Neighbor Count is %d, Adjacent neighbor count is %d\n",
3913 ospf_nbr_count(oi
, 0),
3914 ospf_nbr_count(oi
, NSM_Full
));
3916 ospf_interface_bfd_show(vty
, ifp
, json_interface_sub
);
3918 /* OSPF Authentication information */
3919 ospf_interface_auth_show(vty
, oi
, json_interface_sub
, use_json
);
3923 static int show_ip_ospf_interface_common(struct vty
*vty
, struct ospf
*ospf
,
3924 char *intf_name
, uint8_t use_vrf
,
3925 json_object
*json
, bool use_json
)
3927 struct interface
*ifp
;
3928 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
3929 json_object
*json_vrf
= NULL
;
3930 json_object
*json_interface_sub
= NULL
, *json_interface
= NULL
;
3934 json_vrf
= json_object_new_object();
3937 json_interface
= json_object_new_object();
3940 if (ospf
->instance
) {
3942 json_object_int_add(json
, "ospfInstance",
3945 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
3948 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3950 if (intf_name
== NULL
) {
3951 /* Show All Interfaces.*/
3952 FOR_ALL_INTERFACES (vrf
, ifp
) {
3953 if (ospf_oi_count(ifp
)) {
3955 json_interface_sub
=
3956 json_object_new_object();
3958 show_ip_ospf_interface_sub(vty
, ospf
, ifp
,
3963 json_object_object_add(
3964 json_interface
, ifp
->name
,
3965 json_interface_sub
);
3970 json_object_object_add(json_vrf
, "interfaces",
3973 /* Interface name is specified. */
3974 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
3977 json_object_boolean_true_add(json_vrf
,
3980 vty_out(vty
, "No such interface name\n");
3983 json_interface_sub
= json_object_new_object();
3984 json_interface
= json_object_new_object();
3987 show_ip_ospf_interface_sub(
3988 vty
, ospf
, ifp
, json_interface_sub
, use_json
);
3991 json_object_object_add(json_interface
,
3993 json_interface_sub
);
3994 json_object_object_add(json_vrf
, "interfaces",
4002 json_object_object_add(json
, ospf_get_name(ospf
),
4011 static void show_ip_ospf_interface_traffic_sub(struct vty
*vty
,
4012 struct ospf_interface
*oi
,
4013 json_object
*json_interface_sub
,
4017 json_object_int_add(json_interface_sub
, "ifIndex",
4019 json_object_int_add(json_interface_sub
, "helloIn",
4021 json_object_int_add(json_interface_sub
, "helloOut",
4023 json_object_int_add(json_interface_sub
, "dbDescIn",
4025 json_object_int_add(json_interface_sub
, "dbDescOut",
4027 json_object_int_add(json_interface_sub
, "lsReqIn",
4029 json_object_int_add(json_interface_sub
, "lsReqOut",
4031 json_object_int_add(json_interface_sub
, "lsUpdIn",
4033 json_object_int_add(json_interface_sub
, "lsUpdOut",
4035 json_object_int_add(json_interface_sub
, "lsAckIn",
4037 json_object_int_add(json_interface_sub
, "lsAckOut",
4039 json_object_int_add(json_interface_sub
, "packetsQueued",
4040 listcount(oi
->obuf
));
4043 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u %12lu\n",
4044 oi
->ifp
->name
, oi
->hello_in
, oi
->hello_out
,
4045 oi
->db_desc_in
, oi
->db_desc_out
, oi
->ls_req_in
,
4046 oi
->ls_req_out
, oi
->ls_upd_in
, oi
->ls_upd_out
,
4047 oi
->ls_ack_in
, oi
->ls_ack_out
, listcount(oi
->obuf
));
4051 /* OSPFv2 Packet Counters */
4052 static int show_ip_ospf_interface_traffic_common(
4053 struct vty
*vty
, struct ospf
*ospf
, char *intf_name
, json_object
*json
,
4054 int display_once
, uint8_t use_vrf
, bool use_json
)
4056 struct vrf
*vrf
= NULL
;
4057 struct interface
*ifp
= NULL
;
4058 json_object
*json_vrf
= NULL
;
4059 json_object
*json_interface_sub
= NULL
;
4061 if (!use_json
&& !display_once
) {
4063 vty_out(vty
, "%-12s%-17s%-17s%-17s%-17s%-17s%-17s\n",
4064 "Interface", " HELLO", " DB-Desc", " LS-Req",
4065 " LS-Update", " LS-Ack", " Packets");
4066 vty_out(vty
, "%-10s%-18s%-18s%-17s%-17s%-17s%-17s\n", "",
4067 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
4068 " Rx/Tx", " Queued");
4070 "-------------------------------------------------------------------------------------------------------------\n");
4071 } else if (use_json
) {
4073 json_vrf
= json_object_new_object();
4078 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4080 if (intf_name
== NULL
) {
4081 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
4082 FOR_ALL_INTERFACES (vrf
, ifp
) {
4083 struct route_node
*rn
;
4084 struct ospf_interface
*oi
;
4086 if (ospf_oi_count(ifp
) == 0)
4089 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
4090 rn
= route_next(rn
)) {
4097 json_interface_sub
=
4098 json_object_new_object();
4101 show_ip_ospf_interface_traffic_sub(
4102 vty
, oi
, json_interface_sub
, use_json
);
4104 json_object_object_add(
4105 json_vrf
, ifp
->name
,
4106 json_interface_sub
);
4111 /* Interface name is specified. */
4112 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
4114 struct route_node
*rn
;
4115 struct ospf_interface
*oi
;
4117 if (ospf_oi_count(ifp
) == 0) {
4119 " OSPF not enabled on this interface %s\n",
4124 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
4125 rn
= route_next(rn
)) {
4129 json_interface_sub
=
4130 json_object_new_object();
4133 show_ip_ospf_interface_traffic_sub(
4134 vty
, oi
, json_interface_sub
, use_json
);
4136 json_object_object_add(
4137 json_vrf
, ifp
->name
,
4138 json_interface_sub
);
4146 json_object_object_add(json
, ospf_get_name(ospf
),
4154 DEFUN (show_ip_ospf_interface
,
4155 show_ip_ospf_interface_cmd
,
4156 "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]",
4159 "OSPF information\n"
4162 "Interface information\n"
4167 bool uj
= use_json(argc
, argv
);
4168 struct listnode
*node
= NULL
;
4169 char *vrf_name
= NULL
, *intf_name
= NULL
;
4170 bool all_vrf
= false;
4171 int ret
= CMD_SUCCESS
;
4173 int idx_vrf
= 0, idx_intf
= 0;
4174 uint8_t use_vrf
= 0;
4175 json_object
*json
= NULL
;
4177 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4179 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4180 intf_name
= argv
[idx_intf
]->arg
;
4183 json
= json_object_new_object();
4185 /* vrf input is provided could be all or specific vrf*/
4189 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4190 if (!ospf
->oi_running
)
4192 ret
= show_ip_ospf_interface_common(
4193 vty
, ospf
, intf_name
, use_vrf
, json
,
4198 vty_json(vty
, json
);
4200 vty_out(vty
, "%% OSPF is not enabled\n");
4204 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4205 if (ospf
== NULL
|| !ospf
->oi_running
) {
4207 vty_json(vty
, json
);
4210 "%% OSPF is not enabled in vrf %s\n",
4215 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
4219 /* Display default ospf (instance 0) info */
4220 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4221 if (ospf
== NULL
|| !ospf
->oi_running
) {
4223 vty_json(vty
, json
);
4226 "%% OSPF is not enabled in vrf default\n");
4230 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
4235 vty_json(vty
, json
);
4240 DEFUN (show_ip_ospf_instance_interface
,
4241 show_ip_ospf_instance_interface_cmd
,
4242 "show ip ospf (1-65535) interface [INTERFACE] [json]",
4245 "OSPF information\n"
4247 "Interface information\n"
4254 unsigned short instance
= 0;
4255 bool uj
= use_json(argc
, argv
);
4256 char *intf_name
= NULL
;
4257 int ret
= CMD_SUCCESS
;
4258 json_object
*json
= NULL
;
4260 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4261 if (instance
!= ospf_instance
)
4262 return CMD_NOT_MY_INSTANCE
;
4264 ospf
= ospf_lookup_instance(instance
);
4265 if (!ospf
|| !ospf
->oi_running
)
4269 json
= json_object_new_object();
4271 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4272 intf_name
= argv
[idx_intf
]->arg
;
4274 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
, 0, json
, uj
);
4277 vty_json(vty
, json
);
4282 DEFUN (show_ip_ospf_interface_traffic
,
4283 show_ip_ospf_interface_traffic_cmd
,
4284 "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]",
4287 "OSPF information\n"
4290 "Interface information\n"
4291 "Protocol Packet counters\n"
4295 struct ospf
*ospf
= NULL
;
4296 struct listnode
*node
= NULL
;
4297 char *vrf_name
= NULL
, *intf_name
= NULL
;
4298 bool all_vrf
= false;
4300 int idx_vrf
= 0, idx_intf
= 0;
4301 bool uj
= use_json(argc
, argv
);
4302 json_object
*json
= NULL
;
4303 int ret
= CMD_SUCCESS
;
4304 int display_once
= 0;
4305 uint8_t use_vrf
= 0;
4307 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4309 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4310 intf_name
= argv
[idx_intf
]->arg
;
4313 json
= json_object_new_object();
4318 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4319 if (!ospf
->oi_running
)
4322 ret
= show_ip_ospf_interface_traffic_common(
4323 vty
, ospf
, intf_name
, json
,
4324 display_once
, use_vrf
, uj
);
4329 vty_json(vty
, json
);
4333 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4334 if (ospf
== NULL
|| !ospf
->oi_running
) {
4336 json_object_free(json
);
4340 ret
= show_ip_ospf_interface_traffic_common(
4341 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4343 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4344 if (ospf
== NULL
|| !ospf
->oi_running
) {
4346 json_object_free(json
);
4350 ret
= show_ip_ospf_interface_traffic_common(
4351 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4355 vty_json(vty
, json
);
4361 static void show_ip_ospf_neighbour_header(struct vty
*vty
)
4363 vty_out(vty
, "\n%-15s %-3s %-15s %-15s %-9s %-15s %-32s %5s %5s %5s\n",
4364 "Neighbor ID", "Pri", "State", "Up Time", "Dead Time",
4365 "Address", "Interface", "RXmtL", "RqstL", "DBsmL");
4368 static void show_ip_ospf_neighbour_brief(struct vty
*vty
,
4369 struct ospf_neighbor
*nbr
,
4370 struct ospf_neighbor
*prev_nbr
,
4371 json_object
*json
, bool use_json
)
4374 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4375 json_object
*json_neighbor
= NULL
, *json_neigh_array
= NULL
;
4376 struct timeval res
= {.tv_sec
= 0, .tv_usec
= 0};
4378 char uptime
[OSPF_TIME_DUMP_SIZE
];
4380 if (nbr
->ts_last_progress
.tv_sec
|| nbr
->ts_last_progress
.tv_usec
)
4382 monotime_since(&nbr
->ts_last_progress
, &res
) / 1000LL;
4385 char neigh_str
[INET_ADDRSTRLEN
];
4387 if (prev_nbr
&& !IPV4_ADDR_SAME(&prev_nbr
->src
, &nbr
->src
)) {
4388 /* Start new neigh list */
4389 json_neigh_array
= NULL
;
4392 if (nbr
->state
== NSM_Attempt
&&
4393 nbr
->router_id
.s_addr
== INADDR_ANY
)
4394 strlcpy(neigh_str
, "neighbor", sizeof(neigh_str
));
4396 inet_ntop(AF_INET
, &nbr
->router_id
, neigh_str
,
4399 json_object_object_get_ex(json
, neigh_str
, &json_neigh_array
);
4401 if (!json_neigh_array
) {
4402 json_neigh_array
= json_object_new_array();
4403 json_object_object_add(json
, neigh_str
,
4407 json_neighbor
= json_object_new_object();
4409 ospf_nbr_ism_state_message(nbr
, msgbuf
, sizeof(msgbuf
));
4410 #if CONFDATE > 20230321
4412 "Remove show_ip_ospf_neighbor_sub() JSON keys: priority, state, deadTimeMsecs, address, retransmitCounter, requestCounter, dbSummaryCounter")
4414 json_object_int_add(json_neighbor
, "priority", nbr
->priority
);
4415 json_object_string_add(json_neighbor
, "state", msgbuf
);
4416 json_object_int_add(json_neighbor
, "nbrPriority",
4418 json_object_string_add(json_neighbor
, "nbrState", msgbuf
);
4420 json_object_string_add(
4421 json_neighbor
, "converged",
4422 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
4423 json_object_string_add(json_neighbor
, "role",
4424 lookup_msg(ospf_ism_state_msg
,
4425 ospf_nbr_ism_state(nbr
),
4427 if (nbr
->t_inactivity
) {
4430 time_store
= monotime_until(&nbr
->t_inactivity
->u
.sands
,
4433 json_object_int_add(json_neighbor
, "upTimeInMsec",
4435 json_object_int_add(json_neighbor
, "deadTimeMsecs",
4437 json_object_int_add(json_neighbor
,
4438 "routerDeadIntervalTimerDueMsec",
4440 json_object_string_add(
4441 json_neighbor
, "upTime",
4442 ospf_timeval_dump(&res
, uptime
,
4444 json_object_string_add(
4445 json_neighbor
, "deadTime",
4446 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
4449 json_object_string_add(json_neighbor
, "deadTimeMsecs",
4451 json_object_string_add(json_neighbor
,
4452 "routerDeadIntervalTimerDueMsec",
4455 json_object_string_addf(json_neighbor
, "address", "%pI4",
4457 json_object_string_addf(json_neighbor
, "ifaceAddress", "%pI4",
4459 json_object_string_add(json_neighbor
, "ifaceName",
4461 json_object_int_add(json_neighbor
, "retransmitCounter",
4462 ospf_ls_retransmit_count(nbr
));
4463 json_object_int_add(json_neighbor
,
4464 "linkStateRetransmissionListCounter",
4465 ospf_ls_retransmit_count(nbr
));
4466 json_object_int_add(json_neighbor
, "requestCounter",
4467 ospf_ls_request_count(nbr
));
4468 json_object_int_add(json_neighbor
,
4469 "linkStateRequestListCounter",
4470 ospf_ls_request_count(nbr
));
4471 json_object_int_add(json_neighbor
, "dbSummaryCounter",
4472 ospf_db_summary_count(nbr
));
4473 json_object_int_add(json_neighbor
, "databaseSummaryListCounter",
4474 ospf_db_summary_count(nbr
));
4476 json_object_array_add(json_neigh_array
, json_neighbor
);
4478 ospf_nbr_ism_state_message(nbr
, msgbuf
, sizeof(msgbuf
));
4480 if (nbr
->state
== NSM_Attempt
&&
4481 nbr
->router_id
.s_addr
== INADDR_ANY
)
4482 vty_out(vty
, "%-15s %3d %-15s ", "-", nbr
->priority
,
4485 vty_out(vty
, "%-15pI4 %3d %-15s ", &nbr
->router_id
,
4486 nbr
->priority
, msgbuf
);
4488 vty_out(vty
, "%-15s ",
4489 ospf_timeval_dump(&res
, uptime
, sizeof(uptime
)));
4491 vty_out(vty
, "%9s ",
4492 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
4494 vty_out(vty
, "%-15pI4 ", &nbr
->src
);
4495 vty_out(vty
, "%-32s %5ld %5ld %5d\n", IF_NAME(nbr
->oi
),
4496 ospf_ls_retransmit_count(nbr
),
4497 ospf_ls_request_count(nbr
), ospf_db_summary_count(nbr
));
4501 static void show_ip_ospf_neighbor_sub(struct vty
*vty
,
4502 struct ospf_interface
*oi
,
4503 json_object
*json
, bool use_json
)
4505 struct route_node
*rn
;
4506 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
4508 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
4514 /* Do not show myself. */
4515 if (nbr
== oi
->nbr_self
)
4517 /* Down state is not shown. */
4518 if (nbr
->state
== NSM_Down
)
4523 show_ip_ospf_neighbour_brief(vty
, nbr
, prev_nbr
, json
,
4528 static int show_ip_ospf_neighbor_common(struct vty
*vty
, struct ospf
*ospf
,
4529 json_object
*json
, bool use_json
,
4532 struct ospf_interface
*oi
;
4533 struct listnode
*node
;
4534 json_object
*json_vrf
= NULL
;
4535 json_object
*json_nbr_sub
= NULL
;
4539 json_vrf
= json_object_new_object();
4542 json_nbr_sub
= json_object_new_object();
4545 if (ospf
->instance
) {
4547 json_object_int_add(json
, "ospfInstance",
4550 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4553 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4555 show_ip_ospf_neighbour_header(vty
);
4557 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4558 if (ospf_interface_neighbor_count(oi
) == 0)
4560 show_ip_ospf_neighbor_sub(vty
, oi
, json_nbr_sub
, use_json
);
4564 json_object_object_add(json_vrf
, "neighbors", json_nbr_sub
);
4566 json_object_object_add(json
, ospf_get_name(ospf
),
4574 DEFUN (show_ip_ospf_neighbor
,
4575 show_ip_ospf_neighbor_cmd
,
4576 "show ip ospf [vrf <NAME|all>] neighbor [json]",
4579 "OSPF information\n"
4586 bool uj
= use_json(argc
, argv
);
4587 struct listnode
*node
= NULL
;
4588 char *vrf_name
= NULL
;
4589 bool all_vrf
= false;
4590 int ret
= CMD_SUCCESS
;
4593 uint8_t use_vrf
= 0;
4594 json_object
*json
= NULL
;
4596 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4599 json
= json_object_new_object();
4601 /* vrf input is provided could be all or specific vrf*/
4605 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4606 if (!ospf
->oi_running
)
4608 ret
= show_ip_ospf_neighbor_common(
4609 vty
, ospf
, json
, uj
, use_vrf
);
4613 vty_json(vty
, json
);
4615 vty_out(vty
, "OSPF is not enabled\n");
4620 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4621 if (ospf
== NULL
|| !ospf
->oi_running
) {
4623 vty_json(vty
, json
);
4626 "%% OSPF is not enabled in vrf %s\n",
4632 /* Display default ospf (instance 0) info */
4633 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4634 if (ospf
== NULL
|| !ospf
->oi_running
) {
4636 vty_json(vty
, json
);
4639 "%% OSPF is not enabled in vrf default\n");
4646 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
,
4650 vty_out(vty
, "%s\n",
4651 json_object_to_json_string_ext(
4652 json
, JSON_C_TO_STRING_PRETTY
));
4657 json_object_free(json
);
4663 DEFUN (show_ip_ospf_instance_neighbor
,
4664 show_ip_ospf_instance_neighbor_cmd
,
4665 "show ip ospf (1-65535) neighbor [json]",
4668 "OSPF information\n"
4675 unsigned short instance
= 0;
4676 bool uj
= use_json(argc
, argv
);
4677 json_object
*json
= NULL
;
4678 int ret
= CMD_SUCCESS
;
4680 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4681 if (instance
!= ospf_instance
)
4682 return CMD_NOT_MY_INSTANCE
;
4684 ospf
= ospf_lookup_instance(instance
);
4685 if (!ospf
|| !ospf
->oi_running
)
4689 json
= json_object_new_object();
4691 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
, 0);
4694 vty_json(vty
, json
);
4699 static int show_ip_ospf_neighbor_all_common(struct vty
*vty
, struct ospf
*ospf
,
4700 json_object
*json
, bool use_json
,
4703 struct listnode
*node
;
4704 struct ospf_interface
*oi
;
4705 char buf
[PREFIX_STRLEN
];
4706 json_object
*json_vrf
= NULL
;
4707 json_object
*json_neighbor_sub
= NULL
;
4711 json_vrf
= json_object_new_object();
4716 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4718 show_ip_ospf_neighbour_header(vty
);
4720 if (ospf
->instance
) {
4722 json_object_int_add(json_vrf
, "ospfInstance",
4725 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4728 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4729 struct listnode
*nbr_node
;
4730 struct ospf_nbr_nbma
*nbr_nbma
;
4732 show_ip_ospf_neighbor_sub(vty
, oi
, json_vrf
, use_json
);
4734 /* print Down neighbor status */
4735 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nbr_node
, nbr_nbma
)) {
4736 if (nbr_nbma
->nbr
== NULL
4737 || nbr_nbma
->nbr
->state
== NSM_Down
) {
4740 json_object_new_object();
4741 json_object_int_add(json_neighbor_sub
,
4743 nbr_nbma
->priority
);
4744 json_object_boolean_true_add(
4747 json_object_string_add(
4751 json_object_int_add(
4753 "nbrNbmaRetransmitCounter", 0);
4754 json_object_int_add(
4756 "nbrNbmaRequestCounter", 0);
4757 json_object_int_add(
4759 "nbrNbmaDbSummaryCounter", 0);
4760 json_object_object_add(
4763 &nbr_nbma
->addr
, buf
,
4767 vty_out(vty
, "%-15s %3d %-15s %9s ",
4768 "-", nbr_nbma
->priority
, "Down",
4771 "%-32pI4 %-20s %5d %5d %5d\n",
4773 IF_NAME(oi
), 0, 0, 0);
4781 json_object_object_add(json
, ospf_get_name(ospf
),
4789 DEFUN (show_ip_ospf_neighbor_all
,
4790 show_ip_ospf_neighbor_all_cmd
,
4791 "show ip ospf [vrf <NAME|all>] neighbor all [json]",
4794 "OSPF information\n"
4798 "include down status neighbor\n"
4802 bool uj
= use_json(argc
, argv
);
4803 struct listnode
*node
= NULL
;
4804 char *vrf_name
= NULL
;
4805 bool all_vrf
= false;
4806 int ret
= CMD_SUCCESS
;
4809 uint8_t use_vrf
= 0;
4810 json_object
*json
= NULL
;
4812 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4815 json
= json_object_new_object();
4817 /* vrf input is provided could be all or specific vrf*/
4821 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4822 if (!ospf
->oi_running
)
4824 ret
= show_ip_ospf_neighbor_all_common(
4825 vty
, ospf
, json
, uj
, use_vrf
);
4829 vty_json(vty
, json
);
4834 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4835 if (ospf
== NULL
|| !ospf
->oi_running
) {
4837 json_object_free(json
);
4841 /* Display default ospf (instance 0) info */
4842 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4843 if (ospf
== NULL
|| !ospf
->oi_running
) {
4845 json_object_free(json
);
4851 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
,
4854 vty_out(vty
, "%s\n",
4855 json_object_to_json_string_ext(
4856 json
, JSON_C_TO_STRING_PRETTY
));
4861 json_object_free(json
);
4866 DEFUN (show_ip_ospf_instance_neighbor_all
,
4867 show_ip_ospf_instance_neighbor_all_cmd
,
4868 "show ip ospf (1-65535) neighbor all [json]",
4871 "OSPF information\n"
4874 "include down status neighbor\n"
4879 unsigned short instance
= 0;
4880 bool uj
= use_json(argc
, argv
);
4881 json_object
*json
= NULL
;
4882 int ret
= CMD_SUCCESS
;
4884 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4885 if (instance
!= ospf_instance
)
4886 return CMD_NOT_MY_INSTANCE
;
4888 ospf
= ospf_lookup_instance(instance
);
4889 if (!ospf
|| !ospf
->oi_running
)
4892 json
= json_object_new_object();
4894 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
, 0);
4897 vty_json(vty
, json
);
4902 static int show_ip_ospf_neighbor_int_common(struct vty
*vty
, struct ospf
*ospf
,
4903 const char *ifname
, bool use_json
,
4906 struct interface
*ifp
;
4907 struct route_node
*rn
;
4908 json_object
*json
= NULL
;
4911 json
= json_object_new_object();
4913 if (ospf
->instance
) {
4915 json_object_int_add(json
, "ospfInstance",
4918 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4921 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
4923 ifp
= if_lookup_by_name(ifname
, ospf
->vrf_id
);
4926 json_object_boolean_true_add(json
, "noSuchIface");
4928 vty_out(vty
, "No such interface.\n");
4932 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
4933 struct ospf_interface
*oi
= rn
->info
;
4938 show_ip_ospf_neighbor_sub(vty
, oi
, json
, use_json
);
4942 vty_json(vty
, json
);
4949 DEFPY(show_ip_ospf_instance_neighbor_int
,
4950 show_ip_ospf_instance_neighbor_int_cmd
,
4951 "show ip ospf (1-65535)$instance neighbor IFNAME$ifname [json$json]",
4954 "OSPF information\n"
4963 show_ip_ospf_neighbour_header(vty
);
4965 if (instance
!= ospf_instance
)
4966 return CMD_NOT_MY_INSTANCE
;
4968 ospf
= ospf_lookup_instance(instance
);
4969 if (!ospf
|| !ospf
->oi_running
)
4973 show_ip_ospf_neighbour_header(vty
);
4975 return show_ip_ospf_neighbor_int_common(vty
, ospf
, ifname
, !!json
, 0);
4978 static void show_ip_ospf_nbr_nbma_detail_sub(struct vty
*vty
,
4979 struct ospf_interface
*oi
,
4980 struct ospf_nbr_nbma
*nbr_nbma
,
4981 bool use_json
, json_object
*json
)
4983 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4984 json_object
*json_sub
= NULL
;
4987 json_sub
= json_object_new_object();
4988 else /* Show neighbor ID. */
4989 vty_out(vty
, " Neighbor %s,", "-");
4991 /* Show interface address. */
4993 json_object_string_addf(json_sub
, "ifaceAddress", "%pI4",
4996 vty_out(vty
, " interface address %pI4\n",
5001 json_object_string_add(json_sub
, "areaId",
5002 ospf_area_desc_string(oi
->area
));
5003 json_object_string_add(json_sub
, "iface", IF_NAME(oi
));
5005 vty_out(vty
, " In the area %s via interface %s\n",
5006 ospf_area_desc_string(oi
->area
), IF_NAME(oi
));
5008 /* Show neighbor priority and state. */
5010 json_object_int_add(json_sub
, "nbrPriority",
5011 nbr_nbma
->priority
);
5012 json_object_string_add(json_sub
, "nbrState", "down");
5014 vty_out(vty
, " Neighbor priority is %d, State is %s,",
5015 nbr_nbma
->priority
, "Down");
5017 /* Show state changes. */
5019 json_object_int_add(json_sub
, "stateChangeCounter",
5020 nbr_nbma
->state_change
);
5022 vty_out(vty
, " %d state changes\n", nbr_nbma
->state_change
);
5024 /* Show PollInterval */
5026 json_object_int_add(json_sub
, "pollInterval", nbr_nbma
->v_poll
);
5028 vty_out(vty
, " Poll interval %d\n", nbr_nbma
->v_poll
);
5030 /* Show poll-interval timer. */
5031 if (nbr_nbma
->t_poll
) {
5034 time_store
= monotime_until(&nbr_nbma
->t_poll
->u
.sands
,
5036 json_object_int_add(json_sub
,
5037 "pollIntervalTimerDueMsec",
5040 vty_out(vty
, " Poll timer due in %s\n",
5041 ospf_timer_dump(nbr_nbma
->t_poll
, timebuf
,
5045 /* Show poll-interval timer thread. */
5047 if (nbr_nbma
->t_poll
!= NULL
)
5048 json_object_string_add(json_sub
,
5049 "pollIntervalTimerThread", "on");
5051 vty_out(vty
, " Thread Poll Timer %s\n",
5052 nbr_nbma
->t_poll
!= NULL
? "on" : "off");
5055 json_object_object_add(json
, "noNbrId", json_sub
);
5058 static void show_ip_ospf_neighbor_detail_sub(struct vty
*vty
,
5059 struct ospf_interface
*oi
,
5060 struct ospf_neighbor
*nbr
,
5061 struct ospf_neighbor
*prev_nbr
,
5062 json_object
*json
, bool use_json
)
5064 char timebuf
[OSPF_TIME_DUMP_SIZE
];
5065 json_object
*json_neigh
= NULL
, *json_neigh_array
= NULL
;
5066 char neigh_str
[INET_ADDRSTRLEN
] = {0};
5067 char neigh_state
[16] = {0};
5071 !IPV4_ADDR_SAME(&prev_nbr
->src
, &nbr
->src
)) {
5072 json_neigh_array
= NULL
;
5075 if (nbr
->state
== NSM_Attempt
5076 && nbr
->router_id
.s_addr
== INADDR_ANY
)
5077 strlcpy(neigh_str
, "noNbrId", sizeof(neigh_str
));
5079 inet_ntop(AF_INET
, &nbr
->router_id
,
5080 neigh_str
, sizeof(neigh_str
));
5082 json_object_object_get_ex(json
, neigh_str
, &json_neigh_array
);
5084 if (!json_neigh_array
) {
5085 json_neigh_array
= json_object_new_array();
5086 json_object_object_add(json
, neigh_str
,
5090 json_neigh
= json_object_new_object();
5093 /* Show neighbor ID. */
5094 if (nbr
->state
== NSM_Attempt
5095 && nbr
->router_id
.s_addr
== INADDR_ANY
)
5096 vty_out(vty
, " Neighbor %s,", "-");
5098 vty_out(vty
, " Neighbor %pI4,",
5102 /* Show interface address. */
5104 json_object_string_addf(json_neigh
, "ifaceAddress", "%pI4",
5105 &nbr
->address
.u
.prefix4
);
5107 vty_out(vty
, " interface address %pI4\n",
5108 &nbr
->address
.u
.prefix4
);
5112 json_object_string_add(json_neigh
, "areaId",
5113 ospf_area_desc_string(oi
->area
));
5114 json_object_string_add(json_neigh
, "ifaceName", oi
->ifp
->name
);
5116 json_object_string_addf(json_neigh
, "localIfaceAddress",
5118 &oi
->address
->u
.prefix4
);
5120 vty_out(vty
, " In the area %s via interface %s",
5121 ospf_area_desc_string(oi
->area
), oi
->ifp
->name
);
5123 vty_out(vty
, " local interface IP %pI4\n",
5124 &oi
->address
->u
.prefix4
);
5129 /* Show neighbor priority and state. */
5130 ospf_nbr_ism_state_message(nbr
, neigh_state
, sizeof(neigh_state
));
5132 json_object_int_add(json_neigh
, "nbrPriority", nbr
->priority
);
5133 json_object_string_add(json_neigh
, "nbrState", neigh_state
);
5134 json_object_string_add(json_neigh
, "role",
5135 lookup_msg(ospf_ism_state_msg
,
5136 ospf_nbr_ism_state(nbr
),
5140 " Neighbor priority is %d, State is %s, Role is %s,",
5141 nbr
->priority
, neigh_state
,
5142 lookup_msg(ospf_ism_state_msg
, ospf_nbr_ism_state(nbr
),
5145 /* Show state changes. */
5147 json_object_int_add(json_neigh
, "stateChangeCounter",
5150 vty_out(vty
, " %d state changes\n", nbr
->state_change
);
5152 if (nbr
->ts_last_progress
.tv_sec
|| nbr
->ts_last_progress
.tv_usec
) {
5157 monotime_since(&nbr
->ts_last_progress
, &res
) / 1000LL;
5159 json_object_int_add(json_neigh
, "lastPrgrsvChangeMsec",
5163 " Most recent state change statistics:\n");
5164 vty_out(vty
, " Progressive change %s ago\n",
5165 ospf_timeval_dump(&res
, timebuf
,
5170 if (nbr
->ts_last_regress
.tv_sec
|| nbr
->ts_last_regress
.tv_usec
) {
5175 monotime_since(&nbr
->ts_last_regress
, &res
) / 1000LL;
5177 json_object_int_add(json_neigh
,
5178 "lastRegressiveChangeMsec",
5180 if (nbr
->last_regress_str
)
5181 json_object_string_add(
5183 "lastRegressiveChangeReason",
5184 nbr
->last_regress_str
);
5187 " Regressive change %s ago, due to %s\n",
5188 ospf_timeval_dump(&res
, timebuf
,
5190 (nbr
->last_regress_str
? nbr
->last_regress_str
5195 /* Show Designated Rotuer ID. */
5197 json_object_string_addf(json_neigh
, "routerDesignatedId",
5198 "%pI4", &nbr
->d_router
);
5200 vty_out(vty
, " DR is %pI4,", &nbr
->d_router
);
5202 /* Show Backup Designated Rotuer ID. */
5204 json_object_string_addf(json_neigh
, "routerDesignatedBackupId",
5205 "%pI4", &nbr
->bd_router
);
5207 vty_out(vty
, " BDR is %pI4\n", &nbr
->bd_router
);
5211 json_object_int_add(json_neigh
, "optionsCounter", nbr
->options
);
5212 json_object_string_add(json_neigh
, "optionsList",
5213 ospf_options_dump(nbr
->options
));
5215 vty_out(vty
, " Options %d %s\n", nbr
->options
,
5216 ospf_options_dump(nbr
->options
));
5218 /* Show Router Dead interval timer. */
5220 if (nbr
->t_inactivity
) {
5222 time_store
= monotime_until(&nbr
->t_inactivity
->u
.sands
,
5225 json_object_int_add(json_neigh
,
5226 "routerDeadIntervalTimerDueMsec",
5229 json_object_int_add(
5231 "routerDeadIntervalTimerDueMsec", -1);
5233 vty_out(vty
, " Dead timer due in %s\n",
5234 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
5237 /* Show Database Summary list. */
5239 json_object_int_add(json_neigh
, "databaseSummaryListCounter",
5240 ospf_db_summary_count(nbr
));
5242 vty_out(vty
, " Database Summary List %d\n",
5243 ospf_db_summary_count(nbr
));
5245 /* Show Link State Request list. */
5247 json_object_int_add(json_neigh
, "linkStateRequestListCounter",
5248 ospf_ls_request_count(nbr
));
5250 vty_out(vty
, " Link State Request List %ld\n",
5251 ospf_ls_request_count(nbr
));
5253 /* Show Link State Retransmission list. */
5255 json_object_int_add(json_neigh
,
5256 "linkStateRetransmissionListCounter",
5257 ospf_ls_retransmit_count(nbr
));
5259 vty_out(vty
, " Link State Retransmission List %ld\n",
5260 ospf_ls_retransmit_count(nbr
));
5262 /* Show inactivity timer thread. */
5264 if (nbr
->t_inactivity
!= NULL
)
5265 json_object_string_add(json_neigh
,
5266 "threadInactivityTimer", "on");
5268 vty_out(vty
, " Thread Inactivity Timer %s\n",
5269 nbr
->t_inactivity
!= NULL
? "on" : "off");
5271 /* Show Database Description retransmission thread. */
5273 if (nbr
->t_db_desc
!= NULL
)
5274 json_object_string_add(
5276 "threadDatabaseDescriptionRetransmission",
5280 " Thread Database Description Retransmision %s\n",
5281 nbr
->t_db_desc
!= NULL
? "on" : "off");
5283 /* Show Link State Request Retransmission thread. */
5285 if (nbr
->t_ls_req
!= NULL
)
5286 json_object_string_add(
5288 "threadLinkStateRequestRetransmission", "on");
5291 " Thread Link State Request Retransmission %s\n",
5292 nbr
->t_ls_req
!= NULL
? "on" : "off");
5294 /* Show Link State Update Retransmission thread. */
5296 if (nbr
->t_ls_upd
!= NULL
)
5297 json_object_string_add(
5299 "threadLinkStateUpdateRetransmission",
5303 " Thread Link State Update Retransmission %s\n\n",
5304 nbr
->t_ls_upd
!= NULL
? "on" : "off");
5307 vty_out(vty
, " Graceful restart Helper info:\n");
5309 if (OSPF_GR_IS_ACTIVE_HELPER(nbr
)) {
5311 " Graceful Restart HELPER Status : Inprogress.\n");
5314 " Graceful Restart grace period time: %d (seconds).\n",
5315 nbr
->gr_helper_info
.recvd_grace_period
);
5316 vty_out(vty
, " Graceful Restart reason: %s.\n",
5317 ospf_restart_reason2str(
5318 nbr
->gr_helper_info
.gr_restart_reason
));
5321 " Graceful Restart HELPER Status : None\n");
5324 if (nbr
->gr_helper_info
.rejected_reason
5325 != OSPF_HELPER_REJECTED_NONE
)
5326 vty_out(vty
, " Helper rejected reason: %s.\n",
5327 ospf_rejected_reason2str(
5328 nbr
->gr_helper_info
.rejected_reason
));
5330 if (nbr
->gr_helper_info
.helper_exit_reason
5331 != OSPF_GR_HELPER_EXIT_NONE
)
5332 vty_out(vty
, " Last helper exit reason: %s.\n\n",
5333 ospf_exit_reason2str(
5334 nbr
->gr_helper_info
.helper_exit_reason
));
5338 json_object_string_add(json_neigh
, "grHelperStatus",
5339 OSPF_GR_IS_ACTIVE_HELPER(nbr
) ?
5342 if (OSPF_GR_IS_ACTIVE_HELPER(nbr
)) {
5343 json_object_int_add(
5344 json_neigh
, "graceInterval",
5345 nbr
->gr_helper_info
.recvd_grace_period
);
5346 json_object_string_add(
5347 json_neigh
, "grRestartReason",
5348 ospf_restart_reason2str(
5349 nbr
->gr_helper_info
.gr_restart_reason
));
5352 if (nbr
->gr_helper_info
.rejected_reason
5353 != OSPF_HELPER_REJECTED_NONE
)
5354 json_object_string_add(
5355 json_neigh
, "helperRejectReason",
5356 ospf_rejected_reason2str(
5357 nbr
->gr_helper_info
.rejected_reason
));
5359 if (nbr
->gr_helper_info
.helper_exit_reason
5360 != OSPF_GR_HELPER_EXIT_NONE
)
5361 json_object_string_add(
5362 json_neigh
, "helperExitReason",
5363 ospf_exit_reason2str(
5365 .helper_exit_reason
));
5368 bfd_sess_show(vty
, json_neigh
, nbr
->bfd_session
);
5371 json_object_array_add(json_neigh_array
, json_neigh
);
5375 static int show_ip_ospf_neighbor_id_common(struct vty
*vty
, struct ospf
*ospf
,
5376 struct in_addr
*router_id
,
5377 bool use_json
, uint8_t use_vrf
,
5379 json_object
*json_vrf
)
5381 struct listnode
*node
;
5382 struct ospf_neighbor
*nbr
;
5383 struct ospf_interface
*oi
;
5384 json_object
*json
= NULL
;
5387 json
= json_object_new_object();
5389 if (ospf
->instance
) {
5391 json_object_int_add(json
, "ospfInstance",
5394 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5397 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
5399 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5400 nbr
= ospf_nbr_lookup_by_routerid(oi
->nbrs
, router_id
);
5406 show_ip_ospf_neighbor_detail_sub(vty
, oi
, nbr
, NULL
,
5409 show_ip_ospf_neighbour_brief(vty
, nbr
, NULL
, json
,
5413 if (json_vrf
&& use_json
) {
5414 json_object_object_add(
5416 (ospf
->vrf_id
== VRF_DEFAULT
) ? "default" : ospf
->name
,
5422 vty_json(vty
, json
);
5429 DEFPY(show_ip_ospf_neighbor_id
,
5430 show_ip_ospf_neighbor_id_cmd
,
5431 "show ip ospf [vrf NAME$vrf_name] neighbor A.B.C.D$router_id [detail$detail] [json$json]",
5434 "OSPF information\n"
5442 struct listnode
*node
;
5443 int ret
= CMD_SUCCESS
;
5446 if (vrf_name
&& !strmatch(vrf_name
, "all")) {
5447 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5448 if (ospf
== NULL
|| !ospf
->oi_running
) {
5451 "%% OSPF is not enabled in vrf %s\n",
5454 vty_json_empty(vty
);
5457 ret
= show_ip_ospf_neighbor_id_common(
5458 vty
, ospf
, &router_id
, !!json
, 0, !!detail
, NULL
);
5460 json_object
*json_vrf
= NULL
;
5463 json_vrf
= json_object_new_object();
5464 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5465 if (!ospf
->oi_running
)
5467 ret
= show_ip_ospf_neighbor_id_common(
5468 vty
, ospf
, &router_id
, !!json
, 0, !!detail
,
5472 vty_json(vty
, json_vrf
);
5478 DEFPY(show_ip_ospf_instance_neighbor_id
, show_ip_ospf_instance_neighbor_id_cmd
,
5479 "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [detail$detail] [json$json]",
5481 "OSPF information\n"
5485 "Detailed output\n" JSON_STR
)
5489 if (instance
!= ospf_instance
)
5490 return CMD_NOT_MY_INSTANCE
;
5492 ospf
= ospf_lookup_instance(instance
);
5493 if (!ospf
|| !ospf
->oi_running
)
5496 return show_ip_ospf_neighbor_id_common(vty
, ospf
, &router_id
, !!json
, 0,
5500 static int show_ip_ospf_neighbor_detail_common(struct vty
*vty
,
5502 json_object
*json
, bool use_json
,
5505 struct ospf_interface
*oi
;
5506 struct listnode
*node
;
5507 json_object
*json_vrf
= NULL
;
5508 json_object
*json_nbr_sub
= NULL
;
5512 json_vrf
= json_object_new_object();
5516 json_nbr_sub
= json_object_new_object();
5519 if (ospf
->instance
) {
5521 json_object_int_add(json
, "ospfInstance",
5524 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5527 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5529 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5530 struct route_node
*rn
;
5531 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
5533 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5539 if (nbr
!= oi
->nbr_self
) {
5540 if (nbr
->state
!= NSM_Down
) {
5541 show_ip_ospf_neighbor_detail_sub(
5542 vty
, oi
, nbr
, prev_nbr
,
5543 json_nbr_sub
, use_json
);
5551 json_object_object_add(json_vrf
, "neighbors",
5554 json_object_object_add(json
, ospf_get_name(ospf
),
5562 DEFPY(show_ip_ospf_neighbor_detail
,
5563 show_ip_ospf_neighbor_detail_cmd
,
5564 "show ip ospf [vrf <NAME|all>$vrf_name] neighbor detail [json$json]",
5567 "OSPF information\n"
5571 "detail of all neighbors\n"
5575 struct listnode
*node
= NULL
;
5576 int ret
= CMD_SUCCESS
;
5578 uint8_t use_vrf
= 0;
5579 json_object
*json_vrf
= NULL
;
5582 json_vrf
= json_object_new_object();
5584 /* vrf input is provided could be all or specific vrf*/
5587 if (strmatch(vrf_name
, "all")) {
5588 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5589 if (!ospf
->oi_running
)
5591 ret
= show_ip_ospf_neighbor_detail_common(
5592 vty
, ospf
, json_vrf
, !!json
, use_vrf
);
5595 vty_json(vty
, json_vrf
);
5599 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5600 if (ospf
== NULL
|| !ospf
->oi_running
) {
5602 vty_json(vty
, json_vrf
);
5605 "%% OSPF is not enabled in vrf %s\n",
5610 /* Display default ospf (instance 0) info */
5611 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5612 if (ospf
== NULL
|| !ospf
->oi_running
) {
5614 vty_json(vty
, json_vrf
);
5616 vty_out(vty
, "%% OSPF is not enabled\n");
5622 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json_vrf
,
5626 vty_json(vty
, json_vrf
);
5631 DEFUN (show_ip_ospf_instance_neighbor_detail
,
5632 show_ip_ospf_instance_neighbor_detail_cmd
,
5633 "show ip ospf (1-65535) neighbor detail [json]",
5636 "OSPF information\n"
5639 "detail of all neighbors\n"
5644 unsigned short instance
= 0;
5645 bool uj
= use_json(argc
, argv
);
5646 json_object
*json
= NULL
;
5647 int ret
= CMD_SUCCESS
;
5649 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5650 if (instance
!= ospf_instance
)
5651 return CMD_NOT_MY_INSTANCE
;
5653 ospf
= ospf_lookup_instance(instance
);
5654 if (!ospf
|| !ospf
->oi_running
)
5658 json
= json_object_new_object();
5660 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
, 0);
5663 vty_json(vty
, json
);
5668 static int show_ip_ospf_neighbor_detail_all_common(struct vty
*vty
,
5674 struct listnode
*node
;
5675 struct ospf_interface
*oi
;
5676 json_object
*json_vrf
= NULL
;
5680 json_vrf
= json_object_new_object();
5685 if (ospf
->instance
) {
5687 json_object_int_add(json
, "ospfInstance",
5690 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5693 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5695 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5696 struct route_node
*rn
;
5697 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
5698 struct ospf_nbr_nbma
*nbr_nbma
;
5700 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5706 if (nbr
!= oi
->nbr_self
)
5707 if (nbr
->state
!= NSM_Down
)
5708 show_ip_ospf_neighbor_detail_sub(
5709 vty
, oi
, rn
->info
, prev_nbr
,
5710 json_vrf
, use_json
);
5714 if (oi
->type
!= OSPF_IFTYPE_NBMA
)
5717 struct listnode
*nd
;
5719 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nd
, nbr_nbma
)) {
5720 if (nbr_nbma
->nbr
== NULL
||
5721 nbr_nbma
->nbr
->state
== NSM_Down
)
5722 show_ip_ospf_nbr_nbma_detail_sub(
5723 vty
, oi
, nbr_nbma
, use_json
, json_vrf
);
5729 json_object_object_add(json
, ospf_get_name(ospf
),
5738 DEFUN (show_ip_ospf_neighbor_detail_all
,
5739 show_ip_ospf_neighbor_detail_all_cmd
,
5740 "show ip ospf [vrf <NAME|all>] neighbor detail all [json]",
5743 "OSPF information\n"
5747 "detail of all neighbors\n"
5748 "include down status neighbor\n"
5752 bool uj
= use_json(argc
, argv
);
5753 struct listnode
*node
= NULL
;
5754 char *vrf_name
= NULL
;
5755 bool all_vrf
= false;
5756 int ret
= CMD_SUCCESS
;
5759 uint8_t use_vrf
= 0;
5760 json_object
*json
= NULL
;
5762 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5765 json
= json_object_new_object();
5767 /* vrf input is provided could be all or specific vrf*/
5771 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5772 if (!ospf
->oi_running
)
5774 ret
= show_ip_ospf_neighbor_detail_all_common(
5775 vty
, ospf
, json
, uj
, use_vrf
);
5779 vty_json(vty
, json
);
5783 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5784 if (ospf
== NULL
|| !ospf
->oi_running
) {
5786 json_object_free(json
);
5790 /* Display default ospf (instance 0) info */
5791 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5792 if (ospf
== NULL
|| !ospf
->oi_running
) {
5794 json_object_free(json
);
5800 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
,
5803 vty_out(vty
, "%s\n",
5804 json_object_to_json_string_ext(
5805 json
, JSON_C_TO_STRING_PRETTY
));
5810 json_object_free(json
);
5815 DEFUN (show_ip_ospf_instance_neighbor_detail_all
,
5816 show_ip_ospf_instance_neighbor_detail_all_cmd
,
5817 "show ip ospf (1-65535) neighbor detail all [json]",
5820 "OSPF information\n"
5823 "detail of all neighbors\n"
5824 "include down status neighbor\n"
5829 unsigned short instance
= 0;
5830 bool uj
= use_json(argc
, argv
);
5831 json_object
*json
= NULL
;
5832 int ret
= CMD_SUCCESS
;
5834 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5835 if (instance
!= ospf_instance
)
5836 return CMD_NOT_MY_INSTANCE
;
5838 ospf
= ospf_lookup_instance(instance
);
5839 if (!ospf
|| !ospf
->oi_running
)
5843 json
= json_object_new_object();
5845 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
, uj
, 0);
5848 vty_json(vty
, json
);
5853 static int show_ip_ospf_neighbor_int_detail_common(struct vty
*vty
,
5857 json_object
*json_vrf
)
5859 struct ospf_interface
*oi
;
5860 struct interface
*ifp
;
5861 struct route_node
*rn
, *nrn
;
5862 struct ospf_neighbor
*nbr
;
5863 json_object
*json
= NULL
;
5866 json
= json_object_new_object();
5868 json_object_object_add(json_vrf
,
5869 (ospf
->vrf_id
== VRF_DEFAULT
)
5875 if (ospf
->instance
) {
5877 json_object_int_add(json
, "ospfInstance",
5880 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5883 ifp
= if_lookup_by_name(ifname
, ospf
->vrf_id
);
5886 vty_out(vty
, "No such interface.\n");
5889 vty_json(vty
, json
);
5894 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
5900 for (nrn
= route_top(oi
->nbrs
); nrn
; nrn
= route_next(nrn
)) {
5906 if (nbr
== oi
->nbr_self
)
5909 if (nbr
->state
== NSM_Down
)
5912 show_ip_ospf_neighbor_detail_sub(vty
, oi
, nbr
, NULL
,
5919 vty_json(vty
, json
);
5927 DEFPY(show_ip_ospf_neighbor_int
,
5928 show_ip_ospf_neighbor_int_cmd
,
5929 "show ip ospf [vrf NAME$vrf_name] neighbor IFNAME$ifname [json$json]",
5932 "OSPF information\n"
5939 int ret
= CMD_SUCCESS
;
5940 struct interface
*ifp
= NULL
;
5941 vrf_id_t vrf_id
= VRF_DEFAULT
;
5942 struct vrf
*vrf
= NULL
;
5944 if (vrf_name
&& strmatch(vrf_name
, VRF_DEFAULT_NAME
))
5947 vrf
= vrf_lookup_by_name(vrf_name
);
5949 vrf_id
= vrf
->vrf_id
;
5951 ospf
= ospf_lookup_by_vrf_id(vrf_id
);
5953 if (!ospf
|| !ospf
->oi_running
) {
5955 vty_json_empty(vty
);
5960 show_ip_ospf_neighbour_header(vty
);
5962 ifp
= if_lookup_by_name(ifname
, vrf_id
);
5965 vty_json_empty(vty
);
5967 vty_out(vty
, "No such interface.\n");
5971 ret
= show_ip_ospf_neighbor_int_common(vty
, ospf
, ifname
, !!json
, 0);
5975 DEFPY(show_ip_ospf_neighbor_int_detail
,
5976 show_ip_ospf_neighbor_int_detail_cmd
,
5977 "show ip ospf [vrf NAME$vrf_name] neighbor IFNAME$ifname detail [json$json]",
5980 "OSPF information\n"
5984 "detail of all neighbors\n"
5988 struct listnode
*node
= NULL
;
5989 int ret
= CMD_SUCCESS
;
5990 bool ospf_output
= false;
5992 if (vrf_name
&& !strmatch(vrf_name
, "all")) {
5995 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5996 if (ospf
== NULL
|| !ospf
->oi_running
) {
5999 "%% OSPF is not enabled in vrf %s\n",
6002 vty_json_empty(vty
);
6005 return show_ip_ospf_neighbor_int_detail_common(
6006 vty
, ospf
, ifname
, !!json
, NULL
);
6009 json_object
*json_vrf
= NULL
;
6012 json_vrf
= json_object_new_object();
6014 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6015 if (!ospf
->oi_running
)
6018 ret
= show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, ifname
,
6023 vty_json(vty
, json_vrf
);
6028 vty_out(vty
, "%% OSPF instance not found\n");
6033 DEFPY(show_ip_ospf_instance_neighbor_int_detail
,
6034 show_ip_ospf_instance_neighbor_int_detail_cmd
,
6035 "show ip ospf (1-65535)$instance neighbor IFNAME$ifname detail [json$json]",
6038 "OSPF information\n"
6042 "detail of all neighbors\n"
6047 if (instance
!= ospf_instance
)
6048 return CMD_NOT_MY_INSTANCE
;
6050 ospf
= ospf_lookup_instance(instance
);
6051 if (!ospf
|| !ospf
->oi_running
)
6054 return show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, ifname
,
6058 /* Show functions */
6059 static int show_lsa_summary(struct vty
*vty
, struct ospf_lsa
*lsa
, int self
,
6060 json_object
*json_lsa
)
6062 struct router_lsa
*rl
;
6063 struct summary_lsa
*sl
;
6064 struct as_external_lsa
*asel
;
6065 struct prefix_ipv4 p
;
6070 /* If self option is set, check LSA self flag. */
6071 if (self
== 0 || IS_LSA_SELF(lsa
)) {
6074 /* LSA common part show. */
6075 vty_out(vty
, "%-15pI4", &lsa
->data
->id
);
6076 vty_out(vty
, "%-15pI4 %4d 0x%08lx 0x%04x",
6077 &lsa
->data
->adv_router
, LS_AGE(lsa
),
6078 (unsigned long)ntohl(lsa
->data
->ls_seqnum
),
6079 ntohs(lsa
->data
->checksum
));
6084 snprintf(seqnum
, sizeof(seqnum
), "%x",
6085 ntohl(lsa
->data
->ls_seqnum
));
6086 snprintf(checksum
, sizeof(checksum
), "%x",
6087 ntohs(lsa
->data
->checksum
));
6088 json_object_string_addf(json_lsa
, "lsId", "%pI4",
6090 json_object_string_addf(json_lsa
, "advertisedRouter",
6091 "%pI4", &lsa
->data
->adv_router
);
6092 json_object_int_add(json_lsa
, "lsaAge", LS_AGE(lsa
));
6093 json_object_string_add(json_lsa
, "sequenceNumber",
6095 json_object_string_add(json_lsa
, "checksum", checksum
);
6098 /* LSA specific part show. */
6099 switch (lsa
->data
->type
) {
6100 case OSPF_ROUTER_LSA
:
6101 rl
= (struct router_lsa
*)lsa
->data
;
6104 vty_out(vty
, " %-d", ntohs(rl
->links
));
6106 json_object_int_add(json_lsa
,
6110 case OSPF_SUMMARY_LSA
:
6111 sl
= (struct summary_lsa
*)lsa
->data
;
6114 p
.prefix
= sl
->header
.id
;
6115 p
.prefixlen
= ip_masklen(sl
->mask
);
6116 apply_mask_ipv4(&p
);
6119 vty_out(vty
, " %pFX", &p
);
6121 json_object_string_addf(
6122 json_lsa
, "summaryAddress", "%pFX", &p
);
6125 case OSPF_AS_EXTERNAL_LSA
:
6126 case OSPF_AS_NSSA_LSA
:
6127 asel
= (struct as_external_lsa
*)lsa
->data
;
6130 p
.prefix
= asel
->header
.id
;
6131 p
.prefixlen
= ip_masklen(asel
->mask
);
6132 apply_mask_ipv4(&p
);
6135 vty_out(vty
, " %s %pFX [0x%lx]",
6136 IS_EXTERNAL_METRIC(asel
->e
[0].tos
)
6140 (unsigned long)ntohl(
6141 asel
->e
[0].route_tag
));
6143 json_object_string_add(
6144 json_lsa
, "metricType",
6145 IS_EXTERNAL_METRIC(asel
->e
[0].tos
)
6148 json_object_string_addf(json_lsa
, "route",
6150 json_object_int_add(
6152 (unsigned long)ntohl(
6153 asel
->e
[0].route_tag
));
6156 case OSPF_NETWORK_LSA
:
6157 case OSPF_ASBR_SUMMARY_LSA
:
6158 case OSPF_OPAQUE_LINK_LSA
:
6159 case OSPF_OPAQUE_AREA_LSA
:
6160 case OSPF_OPAQUE_AS_LSA
:
6172 static const char *const show_database_desc
[] = {
6174 "Router Link States",
6176 "Summary Link States",
6177 "ASBR-Summary Link States",
6178 "AS External Link States",
6179 "Group Membership LSA",
6180 "NSSA-external Link States",
6182 "Link-Local Opaque-LSA",
6183 "Area-Local Opaque-LSA",
6184 "AS-external Opaque-LSA",
6187 static const char * const show_database_desc_json
[] = {
6190 "networkLinkStates",
6191 "summaryLinkStates",
6192 "asbrSummaryLinkStates",
6193 "asExternalLinkStates",
6194 "groupMembershipLsa",
6195 "nssaExternalLinkStates",
6197 "linkLocalOpaqueLsa",
6198 "areaLocalOpaqueLsa",
6199 "asExternalOpaqueLsa",
6202 static const char *const show_database_desc_count_json
[] = {
6204 "routerLinkStatesCount",
6205 "networkLinkStatesCount",
6206 "summaryLinkStatesCount",
6207 "asbrSummaryLinkStatesCount",
6208 "asExternalLinkStatesCount",
6209 "groupMembershipLsaCount",
6210 "nssaExternalLinkStatesCount",
6212 "linkLocalOpaqueLsaCount",
6213 "areaLocalOpaqueLsaCount",
6214 "asExternalOpaqueLsaCount",
6217 static const char *const show_database_header
[] = {
6219 "Link ID ADV Router Age Seq# CkSum Link count",
6220 "Link ID ADV Router Age Seq# CkSum",
6221 "Link ID ADV Router Age Seq# CkSum Route",
6222 "Link ID ADV Router Age Seq# CkSum",
6223 "Link ID ADV Router Age Seq# CkSum Route",
6224 " --- header for Group Member ----",
6225 "Link ID ADV Router Age Seq# CkSum Route",
6227 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6228 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6229 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6232 static void show_ip_ospf_database_header(struct vty
*vty
, struct ospf_lsa
*lsa
,
6235 struct router_lsa
*rlsa
= (struct router_lsa
*)lsa
->data
;
6238 if (IS_LSA_SELF(lsa
))
6239 vty_out(vty
, " LS age: %d%s\n", LS_AGE(lsa
),
6240 CHECK_FLAG(lsa
->data
->ls_age
, DO_NOT_AGE
)
6244 vty_out(vty
, " LS age: %d%s\n", LS_AGE(lsa
),
6245 CHECK_FLAG(lsa
->data
->ls_age
, DO_NOT_AGE
)
6248 vty_out(vty
, " Options: 0x%-2x : %s\n", lsa
->data
->options
,
6249 ospf_options_dump(lsa
->data
->options
));
6250 vty_out(vty
, " LS Flags: 0x%-2x %s\n", lsa
->flags
,
6251 ((lsa
->flags
& OSPF_LSA_LOCAL_XLT
)
6252 ? "(Translated from Type-7)"
6255 if (lsa
->data
->type
== OSPF_ROUTER_LSA
) {
6256 vty_out(vty
, " Flags: 0x%x", rlsa
->flags
);
6259 vty_out(vty
, " :%s%s%s%s",
6260 IS_ROUTER_LSA_BORDER(rlsa
) ? " ABR"
6262 IS_ROUTER_LSA_EXTERNAL(rlsa
) ? " ASBR"
6264 IS_ROUTER_LSA_VIRTUAL(rlsa
)
6267 IS_ROUTER_LSA_SHORTCUT(rlsa
)
6273 vty_out(vty
, " LS Type: %s\n",
6274 lookup_msg(ospf_lsa_type_msg
, lsa
->data
->type
, NULL
));
6275 vty_out(vty
, " Link State ID: %pI4 %s\n",
6277 lookup_msg(ospf_link_state_id_type_msg
, lsa
->data
->type
,
6279 vty_out(vty
, " Advertising Router: %pI4\n",
6280 &lsa
->data
->adv_router
);
6281 vty_out(vty
, " LS Seq Number: %08lx\n",
6282 (unsigned long)ntohl(lsa
->data
->ls_seqnum
));
6283 vty_out(vty
, " Checksum: 0x%04x\n",
6284 ntohs(lsa
->data
->checksum
));
6285 vty_out(vty
, " Length: %d\n\n", ntohs(lsa
->data
->length
));
6290 snprintf(seqnum
, 10, "%x", ntohl(lsa
->data
->ls_seqnum
));
6291 snprintf(checksum
, 10, "%x", ntohs(lsa
->data
->checksum
));
6293 json_object_int_add(json
, "lsaAge", LS_AGE(lsa
));
6294 json_object_string_add(json
, "options",
6295 ospf_options_dump(lsa
->data
->options
));
6296 json_object_int_add(json
, "lsaFlags", lsa
->flags
);
6298 if (lsa
->flags
& OSPF_LSA_LOCAL_XLT
)
6299 json_object_boolean_true_add(json
,
6300 "translatedFromType7");
6302 if (lsa
->data
->type
== OSPF_ROUTER_LSA
) {
6303 json_object_int_add(json
, "flags", rlsa
->flags
);
6306 if (IS_ROUTER_LSA_BORDER(rlsa
))
6307 json_object_boolean_true_add(json
,
6309 if (IS_ROUTER_LSA_EXTERNAL(rlsa
))
6310 json_object_boolean_true_add(json
,
6312 if (IS_ROUTER_LSA_VIRTUAL(rlsa
))
6313 json_object_boolean_true_add(
6314 json
, "vlEndpoint");
6315 if (IS_ROUTER_LSA_SHORTCUT(rlsa
))
6316 json_object_boolean_true_add(
6321 json_object_string_add(
6323 lookup_msg(ospf_lsa_type_msg
, lsa
->data
->type
, NULL
));
6324 json_object_string_addf(json
, "linkStateId", "%pI4",
6326 json_object_string_addf(json
, "advertisingRouter", "%pI4",
6327 &lsa
->data
->adv_router
);
6328 json_object_string_add(json
, "lsaSeqNumber", seqnum
);
6329 json_object_string_add(json
, "checksum", checksum
);
6330 json_object_int_add(json
, "length", ntohs(lsa
->data
->length
));
6334 static const char *const link_type_desc
[] = {
6336 "another Router (point-to-point)",
6337 "a Transit Network",
6342 static const char *const link_id_desc
[] = {
6343 "(null)", "Neighboring Router ID", "Designated Router address",
6344 "Net", "Neighboring Router ID",
6347 static const char *const link_data_desc
[] = {
6348 "(null)", "Router Interface address", "Router Interface address",
6349 "Network Mask", "Router Interface address",
6352 static const char *const link_id_desc_json
[] = {
6353 "null", "neighborRouterId", "designatedRouterAddress",
6354 "networkAddress", "neighborRouterId",
6357 static const char *const link_data_desc_json
[] = {
6358 "null", "routerInterfaceAddress", "routerInterfaceAddress",
6359 "networkMask", "routerInterfaceAddress",
6362 /* Show router-LSA each Link information. */
6363 static void show_ip_ospf_database_router_links(struct vty
*vty
,
6364 struct router_lsa
*rl
,
6369 json_object
*json_links
= NULL
;
6370 json_object
*json_link
= NULL
;
6372 char buf
[PREFIX_STRLEN
];
6375 json_links
= json_object_new_object();
6377 len
= ntohs(rl
->header
.length
) - 4;
6378 for (i
= 0; i
< ntohs(rl
->links
) && len
> 0; len
-= 12, i
++) {
6379 type
= rl
->link
[i
].type
;
6384 snprintf(link
, sizeof(link
), "link%u", i
);
6385 json_link
= json_object_new_object();
6386 json_object_string_add(json_link
, "linkType",
6387 link_type_desc
[type
]);
6388 json_object_string_add(json_link
,
6389 link_id_desc_json
[type
],
6391 &rl
->link
[i
].link_id
,
6393 json_object_string_add(
6394 json_link
, link_data_desc_json
[type
],
6395 inet_ntop(AF_INET
, &rl
->link
[i
].link_data
,
6397 json_object_int_add(json_link
, "numOfTosMetrics",
6399 json_object_int_add(json_link
, "tos0Metric",
6400 ntohs(rl
->link
[i
].metric
));
6401 json_object_object_add(json_links
, link
, json_link
);
6403 vty_out(vty
, " Link connected to: %s\n",
6404 link_type_desc
[type
]);
6405 vty_out(vty
, " (Link ID) %s: %pI4\n",
6407 &rl
->link
[i
].link_id
);
6408 vty_out(vty
, " (Link Data) %s: %pI4\n",
6409 link_data_desc
[type
],
6410 &rl
->link
[i
].link_data
);
6411 vty_out(vty
, " Number of TOS metrics: 0\n");
6412 vty_out(vty
, " TOS 0 Metric: %d\n",
6413 ntohs(rl
->link
[i
].metric
));
6418 json_object_object_add(json
, "routerLinks", json_links
);
6421 /* Show router-LSA detail information. */
6422 static int show_router_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6426 struct router_lsa
*rl
= (struct router_lsa
*)lsa
->data
;
6428 show_ip_ospf_database_header(vty
, lsa
, json
);
6431 vty_out(vty
, " Number of Links: %d\n\n",
6434 json_object_int_add(json
, "numOfLinks",
6437 show_ip_ospf_database_router_links(vty
, rl
, json
);
6446 /* Show network-LSA detail information. */
6447 static int show_network_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6451 char buf
[PREFIX_STRLEN
];
6452 json_object
*json_attached_rt
= NULL
;
6453 json_object
*json_router
= NULL
;
6456 json_attached_rt
= json_object_new_object();
6459 struct network_lsa
*nl
= (struct network_lsa
*)lsa
->data
;
6460 struct in_addr
*addr
;
6462 show_ip_ospf_database_header(vty
, lsa
, json
);
6465 vty_out(vty
, " Network Mask: /%d\n",
6466 ip_masklen(nl
->mask
));
6468 json_object_int_add(json
, "networkMask",
6469 ip_masklen(nl
->mask
));
6471 length
= lsa
->size
- OSPF_LSA_HEADER_SIZE
- 4;
6472 addr
= &nl
->routers
[0];
6473 for (i
= 0; length
> 0 && addr
;
6474 length
-= 4, addr
= &nl
->routers
[++i
])
6476 vty_out(vty
, " Attached Router: %pI4\n",
6480 json_router
= json_object_new_object();
6481 json_object_string_add(
6482 json_router
, "attachedRouterId",
6483 inet_ntop(AF_INET
, addr
, buf
,
6485 json_object_object_add(json_attached_rt
,
6486 inet_ntop(AF_INET
, addr
,
6494 json_object_object_add(json
, "attchedRouters",
6500 /* Show summary-LSA detail information. */
6501 static int show_summary_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6505 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
6507 show_ip_ospf_database_header(vty
, lsa
, json
);
6510 vty_out(vty
, " Network Mask: /%d\n",
6511 ip_masklen(sl
->mask
));
6512 vty_out(vty
, " TOS: 0 Metric: %d\n",
6513 GET_METRIC(sl
->metric
));
6516 json_object_int_add(json
, "networkMask",
6517 ip_masklen(sl
->mask
));
6518 json_object_int_add(json
, "tos0Metric",
6519 GET_METRIC(sl
->metric
));
6526 /* Show summary-ASBR-LSA detail information. */
6527 static int show_summary_asbr_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6531 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
6533 show_ip_ospf_database_header(vty
, lsa
, json
);
6536 vty_out(vty
, " Network Mask: /%d\n",
6537 ip_masklen(sl
->mask
));
6538 vty_out(vty
, " TOS: 0 Metric: %d\n",
6539 GET_METRIC(sl
->metric
));
6542 json_object_int_add(json
, "networkMask",
6543 ip_masklen(sl
->mask
));
6544 json_object_int_add(json
, "tos0Metric",
6545 GET_METRIC(sl
->metric
));
6552 /* Show AS-external-LSA detail information. */
6553 static int show_as_external_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6559 struct as_external_lsa
*al
=
6560 (struct as_external_lsa
*)lsa
->data
;
6562 show_ip_ospf_database_header(vty
, lsa
, json
);
6565 vty_out(vty
, " Network Mask: /%d\n",
6566 ip_masklen(al
->mask
));
6567 vty_out(vty
, " Metric Type: %s\n",
6568 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6569 ? "2 (Larger than any link state path)"
6571 vty_out(vty
, " TOS: 0\n");
6572 vty_out(vty
, " Metric: %d\n",
6573 GET_METRIC(al
->e
[0].metric
));
6574 vty_out(vty
, " Forward Address: %pI4\n",
6575 &al
->e
[0].fwd_addr
);
6577 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
6578 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6580 json_object_int_add(json
, "networkMask",
6581 ip_masklen(al
->mask
));
6582 json_object_string_add(
6584 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6585 ? "E2 (Larger than any link state path)"
6587 json_object_int_add(json
, "tos", tos
);
6588 json_object_int_add(json
, "metric",
6589 GET_METRIC(al
->e
[0].metric
));
6590 json_object_string_addf(json
, "forwardAddress", "%pI4",
6591 &(al
->e
[0].fwd_addr
));
6592 json_object_int_add(
6593 json
, "externalRouteTag",
6594 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6601 /* Show AS-NSSA-LSA detail information. */
6602 static int show_as_nssa_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6608 struct as_external_lsa
*al
=
6609 (struct as_external_lsa
*)lsa
->data
;
6611 show_ip_ospf_database_header(vty
, lsa
, json
);
6614 vty_out(vty
, " Network Mask: /%d\n",
6615 ip_masklen(al
->mask
));
6616 vty_out(vty
, " Metric Type: %s\n",
6617 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6618 ? "2 (Larger than any link state path)"
6620 vty_out(vty
, " TOS: 0\n");
6621 vty_out(vty
, " Metric: %d\n",
6622 GET_METRIC(al
->e
[0].metric
));
6623 vty_out(vty
, " NSSA: Forward Address: %pI4\n",
6624 &al
->e
[0].fwd_addr
);
6626 " External Route Tag: %" ROUTE_TAG_PRI
6628 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6630 json_object_int_add(json
, "networkMask",
6631 ip_masklen(al
->mask
));
6632 json_object_string_add(
6634 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6635 ? "E2 (Larger than any link state path)"
6637 json_object_int_add(json
, "tos", tos
);
6638 json_object_int_add(json
, "metric",
6639 GET_METRIC(al
->e
[0].metric
));
6640 json_object_string_addf(json
, "nssaForwardAddress",
6641 "%pI4", &al
->e
[0].fwd_addr
);
6642 json_object_int_add(
6643 json
, "externalRouteTag",
6644 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6651 static int show_func_dummy(struct vty
*vty
, struct ospf_lsa
*lsa
,
6657 static int show_opaque_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6661 show_ip_ospf_database_header(vty
, lsa
, json
);
6662 show_opaque_info_detail(vty
, lsa
, json
);
6669 int (*show_function
[])(struct vty
*, struct ospf_lsa
*, json_object
*) = {
6671 show_router_lsa_detail
,
6672 show_network_lsa_detail
,
6673 show_summary_lsa_detail
,
6674 show_summary_asbr_lsa_detail
,
6675 show_as_external_lsa_detail
,
6677 show_as_nssa_lsa_detail
, /* almost same as external */
6679 show_opaque_lsa_detail
,
6680 show_opaque_lsa_detail
,
6681 show_opaque_lsa_detail
,
6684 static void show_lsa_prefix_set(struct vty
*vty
, struct prefix_ls
*lp
,
6685 struct in_addr
*id
, struct in_addr
*adv_router
)
6687 memset(lp
, 0, sizeof(struct prefix_ls
));
6688 lp
->family
= AF_UNSPEC
;
6691 else if (adv_router
== NULL
) {
6692 lp
->prefixlen
= IPV4_MAX_BITLEN
;
6697 lp
->adv_router
= *adv_router
;
6701 static void show_lsa_detail_proc(struct vty
*vty
, struct route_table
*rt
,
6702 struct in_addr
*id
, struct in_addr
*adv_router
,
6705 struct prefix_ls lp
;
6706 struct route_node
*rn
, *start
;
6707 struct ospf_lsa
*lsa
;
6708 json_object
*json_lsa
= NULL
;
6710 show_lsa_prefix_set(vty
, &lp
, id
, adv_router
);
6711 start
= route_node_get(rt
, (struct prefix
*)&lp
);
6713 route_lock_node(start
);
6714 for (rn
= start
; rn
; rn
= route_next_until(rn
, start
))
6715 if ((lsa
= rn
->info
)) {
6716 if (show_function
[lsa
->data
->type
] != NULL
) {
6719 json_object_new_object();
6720 json_object_array_add(json
,
6724 show_function
[lsa
->data
->type
](
6725 vty
, lsa
, json_lsa
);
6728 route_unlock_node(start
);
6732 /* Show detail LSA information
6733 -- if id is NULL then show all LSAs. */
6734 static void show_lsa_detail(struct vty
*vty
, struct ospf
*ospf
, int type
,
6735 struct in_addr
*id
, struct in_addr
*adv_router
,
6738 struct listnode
*node
;
6739 struct ospf_area
*area
;
6740 char buf
[PREFIX_STRLEN
];
6741 json_object
*json_lsa_type
= NULL
;
6742 json_object
*json_areas
= NULL
;
6743 json_object
*json_lsa_array
= NULL
;
6746 case OSPF_AS_EXTERNAL_LSA
:
6747 case OSPF_OPAQUE_AS_LSA
:
6749 vty_out(vty
, " %s \n\n",
6750 show_database_desc
[type
]);
6752 json_lsa_array
= json_object_new_array();
6754 show_lsa_detail_proc(vty
, AS_LSDB(ospf
, type
), id
, adv_router
,
6757 json_object_object_add(json
,
6758 show_database_desc_json
[type
],
6764 json_areas
= json_object_new_object();
6766 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6769 "\n %s (Area %s)\n\n",
6770 show_database_desc
[type
],
6771 ospf_area_desc_string(area
));
6773 json_lsa_array
= json_object_new_array();
6774 json_object_object_add(json_areas
,
6782 show_lsa_detail_proc(vty
, AREA_LSDB(area
, type
), id
,
6783 adv_router
, json_lsa_array
);
6787 json_lsa_type
= json_object_new_object();
6788 json_object_object_add(json_lsa_type
, "areas",
6790 json_object_object_add(json
,
6791 show_database_desc_json
[type
],
6798 static void show_lsa_detail_adv_router_proc(struct vty
*vty
,
6799 struct route_table
*rt
,
6800 struct in_addr
*adv_router
,
6803 char buf
[PREFIX_STRLEN
];
6804 struct route_node
*rn
;
6805 struct ospf_lsa
*lsa
;
6807 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
))
6808 if ((lsa
= rn
->info
)) {
6809 json_object
*json_lsa
= NULL
;
6811 if (IPV4_ADDR_SAME(adv_router
,
6812 &lsa
->data
->adv_router
)) {
6813 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
6816 json_lsa
= json_object_new_object();
6818 if (show_function
[lsa
->data
->type
] != NULL
)
6819 show_function
[lsa
->data
->type
](
6820 vty
, lsa
, json_lsa
);
6822 json_object_object_add(
6832 /* Show detail LSA information. */
6833 static void show_lsa_detail_adv_router(struct vty
*vty
, struct ospf
*ospf
,
6834 int type
, struct in_addr
*adv_router
,
6837 struct listnode
*node
;
6838 struct ospf_area
*area
;
6839 char buf
[PREFIX_STRLEN
];
6840 json_object
*json_lstype
= NULL
;
6841 json_object
*json_area
= NULL
;
6844 json_lstype
= json_object_new_object();
6847 case OSPF_AS_EXTERNAL_LSA
:
6848 case OSPF_OPAQUE_AS_LSA
:
6850 vty_out(vty
, " %s \n\n",
6851 show_database_desc
[type
]);
6853 show_lsa_detail_adv_router_proc(vty
, AS_LSDB(ospf
, type
),
6854 adv_router
, json_lstype
);
6858 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6860 json_area
= json_object_new_object();
6863 "\n %s (Area %s)\n\n",
6864 show_database_desc
[type
],
6865 ospf_area_desc_string(area
));
6866 show_lsa_detail_adv_router_proc(vty
,
6867 AREA_LSDB(area
, type
),
6868 adv_router
, json_area
);
6871 json_object_object_add(json_lstype
,
6882 json_object_object_add(json
, show_database_desc
[type
],
6886 void show_ip_ospf_database_summary(struct vty
*vty
, struct ospf
*ospf
, int self
,
6889 struct ospf_lsa
*lsa
;
6890 struct route_node
*rn
;
6891 struct ospf_area
*area
;
6892 struct listnode
*node
;
6893 char buf
[PREFIX_STRLEN
];
6894 json_object
*json_areas
= NULL
;
6895 json_object
*json_area
= NULL
;
6896 json_object
*json_lsa
= NULL
;
6898 json_object
*json_lsa_array
= NULL
;
6902 json_areas
= json_object_new_object();
6904 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6906 json_area
= json_object_new_object();
6908 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6911 case OSPF_AS_EXTERNAL_LSA
:
6912 case OSPF_OPAQUE_AS_LSA
:
6917 if (ospf_lsdb_count_self(area
->lsdb
, type
) > 0
6919 && ospf_lsdb_count(area
->lsdb
, type
) > 0)) {
6923 " %s (Area %s)\n\n",
6924 show_database_desc
[type
],
6925 ospf_area_desc_string(area
));
6926 vty_out(vty
, "%s\n",
6927 show_database_header
[type
]);
6930 json_object_new_array();
6931 json_object_object_add(
6933 show_database_desc_json
[type
],
6937 LSDB_LOOP (AREA_LSDB(area
, type
), rn
, lsa
) {
6940 json_object_new_object();
6941 json_object_array_add(
6946 count
+= show_lsa_summary(
6947 vty
, lsa
, self
, json_lsa
);
6953 json_object_int_add(
6956 show_database_desc_count_json
6962 json_object_object_add(json_areas
,
6970 json_object_object_add(json
, "areas", json_areas
);
6972 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6975 case OSPF_AS_EXTERNAL_LSA
:
6976 case OSPF_OPAQUE_AS_LSA
:
6981 if (ospf_lsdb_count_self(ospf
->lsdb
, type
)
6982 || (!self
&& ospf_lsdb_count(ospf
->lsdb
, type
))) {
6984 vty_out(vty
, " %s\n\n",
6985 show_database_desc
[type
]);
6986 vty_out(vty
, "%s\n",
6987 show_database_header
[type
]);
6989 json_lsa_array
= json_object_new_array();
6990 json_object_object_add(
6991 json
, show_database_desc_json
[type
],
6995 LSDB_LOOP (AS_LSDB(ospf
, type
), rn
, lsa
) {
6997 json_lsa
= json_object_new_object();
6998 json_object_array_add(json_lsa_array
,
7002 count
+= show_lsa_summary(vty
, lsa
, self
,
7009 json_object_int_add(
7011 show_database_desc_count_json
[type
],
7020 static void show_ip_ospf_database_maxage(struct vty
*vty
, struct ospf
*ospf
,
7023 struct route_node
*rn
;
7024 char buf
[PREFIX_STRLEN
];
7025 json_object
*json_maxage
= NULL
;
7028 vty_out(vty
, "\n MaxAge Link States:\n\n");
7030 json_maxage
= json_object_new_object();
7032 for (rn
= route_top(ospf
->maxage_lsa
); rn
; rn
= route_next(rn
)) {
7033 struct ospf_lsa
*lsa
;
7034 json_object
*json_lsa
= NULL
;
7036 if ((lsa
= rn
->info
) != NULL
) {
7038 vty_out(vty
, "Link type: %d\n",
7040 vty_out(vty
, "Link State ID: %pI4\n",
7042 vty_out(vty
, "Advertising Router: %pI4\n",
7043 &lsa
->data
->adv_router
);
7044 vty_out(vty
, "LSA lock count: %d\n", lsa
->lock
);
7047 json_lsa
= json_object_new_object();
7048 json_object_int_add(json_lsa
, "linkType",
7050 json_object_string_addf(json_lsa
, "linkStateId",
7051 "%pI4", &lsa
->data
->id
);
7052 json_object_string_addf(
7053 json_lsa
, "advertisingRouter", "%pI4",
7054 &lsa
->data
->adv_router
);
7055 json_object_int_add(json_lsa
, "lsaLockCount",
7057 json_object_object_add(
7067 json_object_object_add(json
, "maxAgeLinkStates", json_maxage
);
7070 #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
7071 #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
7073 #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
7074 #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
7075 #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
7076 #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
7078 #define OSPF_LSA_TYPES_DESC \
7079 "ASBR summary link states\n" \
7080 "External link states\n" \
7081 "Network link states\n" \
7082 "Router link states\n" \
7083 "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \
7084 OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
7085 OSPF_LSA_TYPE_OPAQUE_AS_DESC
7087 static int show_ip_ospf_database_common(struct vty
*vty
, struct ospf
*ospf
,
7088 int arg_base
, int argc
,
7089 struct cmd_token
**argv
,
7090 uint8_t use_vrf
, json_object
*json
,
7095 struct in_addr id
, adv_router
;
7096 json_object
*json_vrf
= NULL
;
7100 json_vrf
= json_object_new_object();
7105 if (ospf
->instance
) {
7107 json_object_int_add(json_vrf
, "ospfInstance",
7110 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
7113 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
7115 /* Show Router ID. */
7117 json_object_string_addf(json_vrf
, "routerId", "%pI4",
7120 vty_out(vty
, "\n OSPF Router with ID (%pI4)\n\n",
7125 if ((argc
== arg_base
+ 4) || (uj
&& (argc
== arg_base
+ 5))) {
7126 show_ip_ospf_database_summary(vty
, ospf
, 0, json_vrf
);
7129 json_object_object_add(
7130 json
, ospf_get_name(ospf
), json_vrf
);
7135 /* Set database type to show. */
7136 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
7137 type
= OSPF_ROUTER_LSA
;
7138 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
7139 type
= OSPF_NETWORK_LSA
;
7140 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
7141 type
= OSPF_AS_NSSA_LSA
;
7142 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "su", 2) == 0)
7143 type
= OSPF_SUMMARY_LSA
;
7144 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
7145 type
= OSPF_ASBR_SUMMARY_LSA
;
7146 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
7147 type
= OSPF_AS_EXTERNAL_LSA
;
7148 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "se", 2) == 0) {
7149 show_ip_ospf_database_summary(vty
, ospf
, 1, json_vrf
);
7152 json_object_object_add(
7153 json
, ospf_get_name(ospf
), json_vrf
);
7156 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "m", 1) == 0) {
7157 show_ip_ospf_database_maxage(vty
, ospf
, json_vrf
);
7160 json_object_object_add(
7161 json
, ospf_get_name(ospf
), json_vrf
);
7164 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
7165 type
= OSPF_OPAQUE_LINK_LSA
;
7166 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
7167 type
= OSPF_OPAQUE_AREA_LSA
;
7168 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
7169 type
= OSPF_OPAQUE_AS_LSA
;
7173 /* `show ip ospf database LSA'. */
7174 if ((argc
== arg_base
+ 5) || (uj
&& (argc
== arg_base
+ 6)))
7175 show_lsa_detail(vty
, ospf
, type
, NULL
, NULL
, json_vrf
);
7176 else if (argc
>= arg_base
+ 6) {
7177 ret
= inet_aton(argv
[arg_base
+ 5]->arg
, &id
);
7181 /* `show ip ospf database LSA ID'. */
7182 if ((argc
== arg_base
+ 6) || (uj
&& (argc
== arg_base
+ 7)))
7183 show_lsa_detail(vty
, ospf
, type
, &id
, NULL
, json_vrf
);
7184 /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */
7185 else if ((argc
== arg_base
+ 7)
7186 || (uj
&& (argc
== arg_base
+ 8))) {
7187 if (strncmp(argv
[arg_base
+ 6]->text
, "s", 1) == 0)
7188 adv_router
= ospf
->router_id
;
7190 ret
= inet_aton(argv
[arg_base
+ 7]->arg
,
7195 show_lsa_detail(vty
, ospf
, type
, &id
, &adv_router
,
7202 json_object_object_add(json
, ospf_get_name(ospf
),
7209 DEFUN (show_ip_ospf_database_max
,
7210 show_ip_ospf_database_max_cmd
,
7211 "show ip ospf [vrf <NAME|all>] database <max-age|self-originate> [json]",
7214 "OSPF information\n"
7217 "Database summary\n"
7218 "LSAs in MaxAge list\n"
7219 "Self-originated link states\n"
7222 struct ospf
*ospf
= NULL
;
7223 struct listnode
*node
= NULL
;
7224 char *vrf_name
= NULL
;
7225 bool all_vrf
= false;
7226 int ret
= CMD_SUCCESS
;
7229 uint8_t use_vrf
= 0;
7230 bool uj
= use_json(argc
, argv
);
7231 json_object
*json
= NULL
;
7234 json
= json_object_new_object();
7236 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
7239 bool ospf_output
= false;
7244 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
7245 if (!ospf
->oi_running
)
7248 ret
= show_ip_ospf_database_common(
7249 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
,
7254 vty_out(vty
, "%% OSPF is not enabled\n");
7256 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
7257 if (ospf
== NULL
|| !ospf
->oi_running
) {
7259 "%% OSPF is not enabled in vrf %s\n",
7262 json_object_free(json
);
7266 ret
= (show_ip_ospf_database_common(
7267 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
, use_vrf
,
7271 /* Display default ospf (instance 0) info */
7272 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
7273 if (ospf
== NULL
|| !ospf
->oi_running
) {
7274 vty_out(vty
, "%% OSPF is not enabled in vrf default\n");
7276 json_object_free(json
);
7281 ret
= show_ip_ospf_database_common(vty
, ospf
, 0, argc
, argv
,
7286 vty_json(vty
, json
);
7291 ALIAS (show_ip_ospf_database_max
,
7292 show_ip_ospf_database_cmd
,
7293 "show ip ospf [vrf <NAME|all>] database [<asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as> [A.B.C.D [<self-originate|adv-router A.B.C.D>]]] [json]",
7296 "OSPF information\n"
7299 "Database summary\n"
7301 "Link State ID (as an IP address)\n"
7302 "Self-originated link states\n"
7303 "Advertising Router link states\n"
7304 "Advertising Router (as an IP address)\n"
7307 DEFUN (show_ip_ospf_instance_database_max
,
7308 show_ip_ospf_instance_database_max_cmd
,
7309 "show ip ospf (1-65535) database <max-age|self-originate> [json]",
7312 "OSPF information\n"
7314 "Database summary\n"
7315 "LSAs in MaxAge list\n"
7316 "Self-originated link states\n"
7321 unsigned short instance
= 0;
7322 bool uj
= use_json(argc
, argv
);
7323 json_object
*json
= NULL
;
7326 json
= json_object_new_object();
7328 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
7329 if (instance
!= ospf_instance
)
7330 return CMD_NOT_MY_INSTANCE
;
7332 ospf
= ospf_lookup_instance(instance
);
7333 if (!ospf
|| !ospf
->oi_running
)
7336 show_ip_ospf_database_common(vty
, ospf
, 1, argc
, argv
, 0, json
, uj
);
7339 vty_json(vty
, json
);
7344 ALIAS (show_ip_ospf_instance_database_max
,
7345 show_ip_ospf_instance_database_cmd
,
7346 "show ip ospf (1-65535) database [<asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as> [A.B.C.D [<self-originate|adv-router A.B.C.D>]]] [json]",
7349 "OSPF information\n"
7351 "Database summary\n"
7353 "Link State ID (as an IP address)\n"
7354 "Self-originated link states\n"
7355 "Advertising Router link states\n"
7356 "Advertising Router (as an IP address)\n"
7359 static int show_ip_ospf_database_type_adv_router_common(struct vty
*vty
,
7361 int arg_base
, int argc
,
7362 struct cmd_token
**argv
,
7369 struct in_addr adv_router
;
7370 json_object
*json_vrf
= NULL
;
7374 json_vrf
= json_object_new_object();
7379 if (ospf
->instance
) {
7381 json_object_int_add(json
, "ospfInstance",
7384 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
7387 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
7389 /* Show Router ID. */
7391 json_object_string_addf(json_vrf
, "routerId", "%pI4",
7394 vty_out(vty
, "\n OSPF Router with ID (%pI4)\n\n",
7398 /* Set database type to show. */
7399 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
7400 type
= OSPF_ROUTER_LSA
;
7401 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
7402 type
= OSPF_NETWORK_LSA
;
7403 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
7404 type
= OSPF_AS_NSSA_LSA
;
7405 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "s", 1) == 0)
7406 type
= OSPF_SUMMARY_LSA
;
7407 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
7408 type
= OSPF_ASBR_SUMMARY_LSA
;
7409 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
7410 type
= OSPF_AS_EXTERNAL_LSA
;
7411 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
7412 type
= OSPF_OPAQUE_LINK_LSA
;
7413 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
7414 type
= OSPF_OPAQUE_AREA_LSA
;
7415 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
7416 type
= OSPF_OPAQUE_AS_LSA
;
7420 json_object_free(json_vrf
);
7425 /* `show ip ospf database LSA adv-router ADV_ROUTER'. */
7426 if (strncmp(argv
[arg_base
+ 5]->text
, "s", 1) == 0)
7427 adv_router
= ospf
->router_id
;
7429 ret
= inet_aton(argv
[arg_base
+ 6]->arg
, &adv_router
);
7433 json_object_free(json_vrf
);
7439 show_lsa_detail_adv_router(vty
, ospf
, type
, &adv_router
, json_vrf
);
7443 json_object_object_add(json
, ospf_get_name(ospf
),
7450 DEFUN (show_ip_ospf_database_type_adv_router
,
7451 show_ip_ospf_database_type_adv_router_cmd
,
7452 "show ip ospf [vrf <NAME|all>] database <asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as> <adv-router A.B.C.D|self-originate> [json]",
7455 "OSPF information\n"
7458 "Database summary\n"
7460 "Advertising Router link states\n"
7461 "Advertising Router (as an IP address)\n"
7462 "Self-originated link states\n"
7465 struct ospf
*ospf
= NULL
;
7466 struct listnode
*node
= NULL
;
7467 char *vrf_name
= NULL
;
7468 bool all_vrf
= false;
7469 int ret
= CMD_SUCCESS
;
7472 uint8_t use_vrf
= 0;
7473 bool uj
= use_json(argc
, argv
);
7474 json_object
*json
= NULL
;
7477 json
= json_object_new_object();
7479 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
7482 bool ospf_output
= false;
7487 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
7488 if (!ospf
->oi_running
)
7491 ret
= show_ip_ospf_database_type_adv_router_common(
7492 vty
, ospf
, 2, argc
, argv
, use_vrf
, json
,
7496 vty_out(vty
, "%% OSPF is not enabled\n");
7498 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
7499 if ((ospf
== NULL
) || !ospf
->oi_running
) {
7501 vty_json(vty
, json
);
7504 "%% OSPF is not enabled in vrf %s\n",
7509 ret
= show_ip_ospf_database_type_adv_router_common(
7510 vty
, ospf
, 2, argc
, argv
, use_vrf
, json
, uj
);
7513 /* Display default ospf (instance 0) info */
7514 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
7515 if (ospf
== NULL
|| !ospf
->oi_running
) {
7517 vty_json(vty
, json
);
7520 "%% OSPF is not enabled on vrf default\n");
7524 ret
= show_ip_ospf_database_type_adv_router_common(
7525 vty
, ospf
, 0, argc
, argv
, use_vrf
, json
, uj
);
7529 vty_out(vty
, "%s\n", json_object_to_json_string(json
));
7530 json_object_free(json
);
7536 DEFUN (show_ip_ospf_instance_database_type_adv_router
,
7537 show_ip_ospf_instance_database_type_adv_router_cmd
,
7538 "show ip ospf (1-65535) database <asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as> <adv-router A.B.C.D|self-originate> [json]",
7541 "OSPF information\n"
7543 "Database summary\n"
7545 "Advertising Router link states\n"
7546 "Advertising Router (as an IP address)\n"
7547 "Self-originated link states\n"
7552 unsigned short instance
= 0;
7553 bool uj
= use_json(argc
, argv
);
7554 json_object
*json
= NULL
;
7557 json
= json_object_new_object();
7559 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
7560 if (instance
!= ospf_instance
)
7561 return CMD_NOT_MY_INSTANCE
;
7563 ospf
= ospf_lookup_instance(instance
);
7564 if (!ospf
|| !ospf
->oi_running
)
7567 show_ip_ospf_database_type_adv_router_common(vty
, ospf
, 1, argc
, argv
,
7571 vty_json(vty
, json
);
7576 DEFUN (ip_ospf_authentication_args
,
7577 ip_ospf_authentication_args_addr_cmd
,
7578 "ip ospf authentication <null|message-digest> [A.B.C.D]",
7580 "OSPF interface commands\n"
7581 "Enable authentication on this interface\n"
7582 "Use null authentication\n"
7583 "Use message-digest authentication\n"
7584 "Address of interface\n")
7586 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7587 int idx_encryption
= 3;
7589 struct in_addr addr
;
7591 struct ospf_if_params
*params
;
7593 params
= IF_DEF_PARAMS(ifp
);
7596 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7599 "Please specify interface address by A.B.C.D\n");
7600 return CMD_WARNING_CONFIG_FAILED
;
7603 params
= ospf_get_if_params(ifp
, addr
);
7604 ospf_if_update_params(ifp
, addr
);
7607 /* Handle null authentication */
7608 if (argv
[idx_encryption
]->arg
[0] == 'n') {
7609 SET_IF_PARAM(params
, auth_type
);
7610 params
->auth_type
= OSPF_AUTH_NULL
;
7614 /* Handle message-digest authentication */
7615 if (argv
[idx_encryption
]->arg
[0] == 'm') {
7616 SET_IF_PARAM(params
, auth_type
);
7617 params
->auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
7621 vty_out(vty
, "You shouldn't get here!\n");
7622 return CMD_WARNING_CONFIG_FAILED
;
7625 DEFUN (ip_ospf_authentication
,
7626 ip_ospf_authentication_addr_cmd
,
7627 "ip ospf authentication [A.B.C.D]",
7629 "OSPF interface commands\n"
7630 "Enable authentication on this interface\n"
7631 "Address of interface\n")
7633 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7635 struct in_addr addr
;
7637 struct ospf_if_params
*params
;
7639 params
= IF_DEF_PARAMS(ifp
);
7642 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7645 "Please specify interface address by A.B.C.D\n");
7646 return CMD_WARNING_CONFIG_FAILED
;
7649 params
= ospf_get_if_params(ifp
, addr
);
7650 ospf_if_update_params(ifp
, addr
);
7653 SET_IF_PARAM(params
, auth_type
);
7654 params
->auth_type
= OSPF_AUTH_SIMPLE
;
7659 DEFUN (no_ip_ospf_authentication_args
,
7660 no_ip_ospf_authentication_args_addr_cmd
,
7661 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
7664 "OSPF interface commands\n"
7665 "Enable authentication on this interface\n"
7666 "Use null authentication\n"
7667 "Use message-digest authentication\n"
7668 "Address of interface\n")
7670 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7671 int idx_encryption
= 4;
7673 struct in_addr addr
;
7675 struct ospf_if_params
*params
;
7676 struct route_node
*rn
;
7679 params
= IF_DEF_PARAMS(ifp
);
7682 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7685 "Please specify interface address by A.B.C.D\n");
7686 return CMD_WARNING_CONFIG_FAILED
;
7689 params
= ospf_lookup_if_params(ifp
, addr
);
7690 if (params
== NULL
) {
7691 vty_out(vty
, "Ip Address specified is unknown\n");
7692 return CMD_WARNING_CONFIG_FAILED
;
7694 params
->auth_type
= OSPF_AUTH_NOTSET
;
7695 UNSET_IF_PARAM(params
, auth_type
);
7696 if (params
!= IF_DEF_PARAMS(ifp
)) {
7697 ospf_free_if_params(ifp
, addr
);
7698 ospf_if_update_params(ifp
, addr
);
7701 if (argv
[idx_encryption
]->arg
[0] == 'n') {
7702 auth_type
= OSPF_AUTH_NULL
;
7703 } else if (argv
[idx_encryption
]->arg
[0] == 'm') {
7704 auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
7706 vty_out(vty
, "Unexpected input encountered\n");
7707 return CMD_WARNING_CONFIG_FAILED
;
7710 * Here we have a case where the user has entered
7711 * 'no ip ospf authentication (null | message_digest )'
7712 * we need to find if we have any ip addresses underneath it
7714 * correspond to the associated type.
7716 if (params
->auth_type
== auth_type
) {
7717 params
->auth_type
= OSPF_AUTH_NOTSET
;
7718 UNSET_IF_PARAM(params
, auth_type
);
7721 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
7722 rn
= route_next(rn
)) {
7723 if ((params
= rn
->info
)) {
7724 if (params
->auth_type
== auth_type
) {
7725 params
->auth_type
= OSPF_AUTH_NOTSET
;
7726 UNSET_IF_PARAM(params
, auth_type
);
7727 if (params
!= IF_DEF_PARAMS(ifp
)) {
7728 ospf_free_if_params(
7729 ifp
, rn
->p
.u
.prefix4
);
7730 ospf_if_update_params(
7731 ifp
, rn
->p
.u
.prefix4
);
7741 DEFUN (no_ip_ospf_authentication
,
7742 no_ip_ospf_authentication_addr_cmd
,
7743 "no ip ospf authentication [A.B.C.D]",
7746 "OSPF interface commands\n"
7747 "Enable authentication on this interface\n"
7748 "Address of interface\n")
7750 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7752 struct in_addr addr
;
7754 struct ospf_if_params
*params
;
7755 struct route_node
*rn
;
7757 params
= IF_DEF_PARAMS(ifp
);
7760 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7763 "Please specify interface address by A.B.C.D\n");
7764 return CMD_WARNING_CONFIG_FAILED
;
7767 params
= ospf_lookup_if_params(ifp
, addr
);
7768 if (params
== NULL
) {
7769 vty_out(vty
, "Ip Address specified is unknown\n");
7770 return CMD_WARNING_CONFIG_FAILED
;
7773 params
->auth_type
= OSPF_AUTH_NOTSET
;
7774 UNSET_IF_PARAM(params
, auth_type
);
7775 if (params
!= IF_DEF_PARAMS(ifp
)) {
7776 ospf_free_if_params(ifp
, addr
);
7777 ospf_if_update_params(ifp
, addr
);
7781 * When a user enters 'no ip ospf authentication'
7782 * We should remove all authentication types from
7785 if ((params
->auth_type
== OSPF_AUTH_NULL
)
7786 || (params
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
7787 || (params
->auth_type
== OSPF_AUTH_SIMPLE
)) {
7788 params
->auth_type
= OSPF_AUTH_NOTSET
;
7789 UNSET_IF_PARAM(params
, auth_type
);
7792 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
7793 rn
= route_next(rn
)) {
7794 if ((params
= rn
->info
)) {
7796 if ((params
->auth_type
== OSPF_AUTH_NULL
)
7797 || (params
->auth_type
7798 == OSPF_AUTH_CRYPTOGRAPHIC
)
7799 || (params
->auth_type
7800 == OSPF_AUTH_SIMPLE
)) {
7801 params
->auth_type
= OSPF_AUTH_NOTSET
;
7802 UNSET_IF_PARAM(params
, auth_type
);
7803 if (params
!= IF_DEF_PARAMS(ifp
)) {
7804 ospf_free_if_params(
7805 ifp
, rn
->p
.u
.prefix4
);
7806 ospf_if_update_params(
7807 ifp
, rn
->p
.u
.prefix4
);
7818 DEFUN (ip_ospf_authentication_key
,
7819 ip_ospf_authentication_key_addr_cmd
,
7820 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
7822 "OSPF interface commands\n"
7823 "Authentication password (key)\n"
7824 "The OSPF password (key)\n"
7825 "Address of interface\n")
7827 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7829 struct in_addr addr
;
7830 struct ospf_if_params
*params
;
7832 params
= IF_DEF_PARAMS(ifp
);
7834 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7835 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7837 "Please specify interface address by A.B.C.D\n");
7838 return CMD_WARNING_CONFIG_FAILED
;
7841 params
= ospf_get_if_params(ifp
, addr
);
7842 ospf_if_update_params(ifp
, addr
);
7845 strlcpy((char *)params
->auth_simple
, argv
[3]->arg
,
7846 sizeof(params
->auth_simple
));
7847 SET_IF_PARAM(params
, auth_simple
);
7852 DEFUN_HIDDEN (ospf_authentication_key
,
7853 ospf_authentication_key_cmd
,
7854 "ospf authentication-key AUTH_KEY [A.B.C.D]",
7855 "OSPF interface commands\n"
7856 VLINK_HELPSTR_AUTH_SIMPLE
7857 "Address of interface\n")
7859 return ip_ospf_authentication_key(self
, vty
, argc
, argv
);
7862 DEFUN (no_ip_ospf_authentication_key
,
7863 no_ip_ospf_authentication_key_authkey_addr_cmd
,
7864 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7867 "OSPF interface commands\n"
7868 VLINK_HELPSTR_AUTH_SIMPLE
7869 "Address of interface\n")
7871 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7873 struct in_addr addr
;
7874 struct ospf_if_params
*params
;
7875 params
= IF_DEF_PARAMS(ifp
);
7877 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7878 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7880 "Please specify interface address by A.B.C.D\n");
7881 return CMD_WARNING_CONFIG_FAILED
;
7884 params
= ospf_lookup_if_params(ifp
, addr
);
7889 memset(params
->auth_simple
, 0, OSPF_AUTH_SIMPLE_SIZE
);
7890 UNSET_IF_PARAM(params
, auth_simple
);
7892 if (params
!= IF_DEF_PARAMS(ifp
)) {
7893 ospf_free_if_params(ifp
, addr
);
7894 ospf_if_update_params(ifp
, addr
);
7900 DEFUN_HIDDEN (no_ospf_authentication_key
,
7901 no_ospf_authentication_key_authkey_addr_cmd
,
7902 "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7904 "OSPF interface commands\n"
7905 VLINK_HELPSTR_AUTH_SIMPLE
7906 "Address of interface\n")
7908 return no_ip_ospf_authentication_key(self
, vty
, argc
, argv
);
7911 DEFUN (ip_ospf_message_digest_key
,
7912 ip_ospf_message_digest_key_cmd
,
7913 "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7915 "OSPF interface commands\n"
7916 "Message digest authentication password (key)\n"
7918 "Use MD5 algorithm\n"
7919 "The OSPF password (key)\n"
7920 "Address of interface\n")
7922 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7923 struct crypt_key
*ck
;
7925 struct in_addr addr
;
7926 struct ospf_if_params
*params
;
7928 params
= IF_DEF_PARAMS(ifp
);
7931 argv_find(argv
, argc
, "(1-255)", &idx
);
7932 char *keyid
= argv
[idx
]->arg
;
7933 argv_find(argv
, argc
, "KEY", &idx
);
7934 char *cryptkey
= argv
[idx
]->arg
;
7936 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7937 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7939 "Please specify interface address by A.B.C.D\n");
7940 return CMD_WARNING_CONFIG_FAILED
;
7943 params
= ospf_get_if_params(ifp
, addr
);
7944 ospf_if_update_params(ifp
, addr
);
7947 key_id
= strtol(keyid
, NULL
, 10);
7949 /* Remove existing key, if any */
7950 ospf_crypt_key_delete(params
->auth_crypt
, key_id
);
7952 ck
= ospf_crypt_key_new();
7953 ck
->key_id
= (uint8_t)key_id
;
7954 strlcpy((char *)ck
->auth_key
, cryptkey
, sizeof(ck
->auth_key
));
7956 ospf_crypt_key_add(params
->auth_crypt
, ck
);
7957 SET_IF_PARAM(params
, auth_crypt
);
7962 DEFUN_HIDDEN (ospf_message_digest_key
,
7963 ospf_message_digest_key_cmd
,
7964 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7965 "OSPF interface commands\n"
7966 "Message digest authentication password (key)\n"
7968 "Use MD5 algorithm\n"
7969 "The OSPF password (key)\n"
7970 "Address of interface\n")
7972 return ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7975 DEFUN (no_ip_ospf_message_digest_key
,
7976 no_ip_ospf_message_digest_key_cmd
,
7977 "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7980 "OSPF interface commands\n"
7981 "Message digest authentication password (key)\n"
7983 "Use MD5 algorithm\n"
7984 "The OSPF password (key)\n"
7985 "Address of interface\n")
7987 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7989 struct crypt_key
*ck
;
7991 struct in_addr addr
;
7992 struct ospf_if_params
*params
;
7993 params
= IF_DEF_PARAMS(ifp
);
7995 argv_find(argv
, argc
, "(1-255)", &idx
);
7996 char *keyid
= argv
[idx
]->arg
;
7998 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7999 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8001 "Please specify interface address by A.B.C.D\n");
8002 return CMD_WARNING_CONFIG_FAILED
;
8005 params
= ospf_lookup_if_params(ifp
, addr
);
8010 key_id
= strtol(keyid
, NULL
, 10);
8011 ck
= ospf_crypt_key_lookup(params
->auth_crypt
, key_id
);
8013 vty_out(vty
, "OSPF: Key %d does not exist\n", key_id
);
8014 return CMD_WARNING_CONFIG_FAILED
;
8017 ospf_crypt_key_delete(params
->auth_crypt
, key_id
);
8019 if (params
!= IF_DEF_PARAMS(ifp
)) {
8020 ospf_free_if_params(ifp
, addr
);
8021 ospf_if_update_params(ifp
, addr
);
8027 DEFUN_HIDDEN (no_ospf_message_digest_key
,
8028 no_ospf_message_digest_key_cmd
,
8029 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
8031 "OSPF interface commands\n"
8032 "Message digest authentication password (key)\n"
8034 "Use MD5 algorithm\n"
8035 "The OSPF password (key)\n"
8036 "Address of interface\n")
8038 return no_ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
8041 DEFUN (ip_ospf_cost
,
8043 "ip ospf cost (1-65535) [A.B.C.D]",
8045 "OSPF interface commands\n"
8048 "Address of interface\n")
8050 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8052 uint32_t cost
= OSPF_OUTPUT_COST_DEFAULT
;
8053 struct in_addr addr
;
8054 struct ospf_if_params
*params
;
8055 params
= IF_DEF_PARAMS(ifp
);
8058 char *coststr
= NULL
, *ifaddr
= NULL
;
8060 argv_find(argv
, argc
, "(1-65535)", &idx
);
8061 coststr
= argv
[idx
]->arg
;
8062 cost
= strtol(coststr
, NULL
, 10);
8064 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
8066 if (!inet_aton(ifaddr
, &addr
)) {
8068 "Please specify interface address by A.B.C.D\n");
8069 return CMD_WARNING_CONFIG_FAILED
;
8072 params
= ospf_get_if_params(ifp
, addr
);
8073 ospf_if_update_params(ifp
, addr
);
8076 SET_IF_PARAM(params
, output_cost_cmd
);
8077 params
->output_cost_cmd
= cost
;
8079 ospf_if_recalculate_output_cost(ifp
);
8084 DEFUN_HIDDEN (ospf_cost
,
8086 "ospf cost (1-65535) [A.B.C.D]",
8087 "OSPF interface commands\n"
8090 "Address of interface\n")
8092 return ip_ospf_cost(self
, vty
, argc
, argv
);
8095 DEFUN (no_ip_ospf_cost
,
8096 no_ip_ospf_cost_cmd
,
8097 "no ip ospf cost [(1-65535)] [A.B.C.D]",
8100 "OSPF interface commands\n"
8103 "Address of interface\n")
8105 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8107 struct in_addr addr
;
8108 struct ospf_if_params
*params
;
8110 params
= IF_DEF_PARAMS(ifp
);
8113 char *ifaddr
= NULL
;
8114 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
8116 /* According to the semantics we are mimicking "no ip ospf cost N" is
8117 * always treated as "no ip ospf cost" regardless of the actual value
8118 * of N already configured for the interface. Thus ignore cost. */
8121 if (!inet_aton(ifaddr
, &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
, output_cost_cmd
);
8134 if (params
!= IF_DEF_PARAMS(ifp
)) {
8135 ospf_free_if_params(ifp
, addr
);
8136 ospf_if_update_params(ifp
, addr
);
8139 ospf_if_recalculate_output_cost(ifp
);
8144 DEFUN_HIDDEN (no_ospf_cost
,
8146 "no ospf cost [(1-65535)] [A.B.C.D]",
8148 "OSPF interface commands\n"
8151 "Address of interface\n")
8153 return no_ip_ospf_cost(self
, vty
, argc
, argv
);
8156 static void ospf_nbr_timer_update(struct ospf_interface
*oi
)
8158 struct route_node
*rn
;
8159 struct ospf_neighbor
*nbr
;
8161 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
8167 nbr
->v_inactivity
= OSPF_IF_PARAM(oi
, v_wait
);
8168 nbr
->v_db_desc
= OSPF_IF_PARAM(oi
, retransmit_interval
);
8169 nbr
->v_ls_req
= OSPF_IF_PARAM(oi
, retransmit_interval
);
8170 nbr
->v_ls_upd
= OSPF_IF_PARAM(oi
, retransmit_interval
);
8174 static int ospf_vty_dead_interval_set(struct vty
*vty
, const char *interval_str
,
8175 const char *nbr_str
,
8176 const char *fast_hello_str
)
8178 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8181 struct in_addr addr
;
8183 struct ospf_if_params
*params
;
8184 struct ospf_interface
*oi
;
8185 struct route_node
*rn
;
8187 params
= IF_DEF_PARAMS(ifp
);
8190 ret
= inet_aton(nbr_str
, &addr
);
8193 "Please specify interface address by A.B.C.D\n");
8194 return CMD_WARNING_CONFIG_FAILED
;
8197 params
= ospf_get_if_params(ifp
, addr
);
8198 ospf_if_update_params(ifp
, addr
);
8202 seconds
= strtoul(interval_str
, NULL
, 10);
8204 /* reset fast_hello too, just to be sure */
8205 UNSET_IF_PARAM(params
, fast_hello
);
8206 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
8207 } else if (fast_hello_str
) {
8208 hellomult
= strtoul(fast_hello_str
, NULL
, 10);
8209 /* 1s dead-interval with sub-second hellos desired */
8210 seconds
= OSPF_ROUTER_DEAD_INTERVAL_MINIMAL
;
8211 SET_IF_PARAM(params
, fast_hello
);
8212 params
->fast_hello
= hellomult
;
8215 "Please specify dead-interval or hello-multiplier\n");
8216 return CMD_WARNING_CONFIG_FAILED
;
8219 SET_IF_PARAM(params
, v_wait
);
8220 params
->v_wait
= seconds
;
8221 params
->is_v_wait_set
= true;
8223 /* Update timer values in neighbor structure. */
8225 struct ospf
*ospf
= NULL
;
8227 ospf
= ifp
->vrf
->info
;
8229 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
8231 ospf_nbr_timer_update(oi
);
8234 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
8235 if ((oi
= rn
->info
))
8236 ospf_nbr_timer_update(oi
);
8242 DEFUN (ip_ospf_dead_interval
,
8243 ip_ospf_dead_interval_cmd
,
8244 "ip ospf dead-interval (1-65535) [A.B.C.D]",
8246 "OSPF interface commands\n"
8247 "Interval time after which a neighbor is declared down\n"
8249 "Address of interface\n")
8252 char *interval
= argv_find(argv
, argc
, "(1-65535)", &idx
)
8256 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
8257 return ospf_vty_dead_interval_set(vty
, interval
, ifaddr
, NULL
);
8261 DEFUN_HIDDEN (ospf_dead_interval
,
8262 ospf_dead_interval_cmd
,
8263 "ospf dead-interval (1-65535) [A.B.C.D]",
8264 "OSPF interface commands\n"
8265 "Interval time after which a neighbor is declared down\n"
8267 "Address of interface\n")
8269 return ip_ospf_dead_interval(self
, vty
, argc
, argv
);
8272 DEFUN (ip_ospf_dead_interval_minimal
,
8273 ip_ospf_dead_interval_minimal_addr_cmd
,
8274 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
8276 "OSPF interface commands\n"
8277 "Interval time after which a neighbor is declared down\n"
8278 "Minimal 1s dead-interval with fast sub-second hellos\n"
8279 "Hello multiplier factor\n"
8280 "Number of Hellos to send each second\n"
8281 "Address of interface\n")
8286 return ospf_vty_dead_interval_set(
8287 vty
, NULL
, argv
[idx_ipv4
]->arg
, argv
[idx_number
]->arg
);
8289 return ospf_vty_dead_interval_set(vty
, NULL
, NULL
,
8290 argv
[idx_number
]->arg
);
8293 DEFUN (no_ip_ospf_dead_interval
,
8294 no_ip_ospf_dead_interval_cmd
,
8295 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8298 "OSPF interface commands\n"
8299 "Interval time after which a neighbor is declared down\n"
8301 "Minimal 1s dead-interval with fast sub-second hellos\n"
8302 "Hello multiplier factor\n"
8303 "Number of Hellos to send each second\n"
8304 "Address of interface\n")
8306 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8307 int idx_ipv4
= argc
- 1;
8308 struct in_addr addr
= {.s_addr
= 0L};
8310 struct ospf_if_params
*params
;
8311 struct ospf_interface
*oi
;
8312 struct route_node
*rn
;
8314 params
= IF_DEF_PARAMS(ifp
);
8316 if (argv
[idx_ipv4
]->type
== IPV4_TKN
) {
8317 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8320 "Please specify interface address by A.B.C.D\n");
8321 return CMD_WARNING_CONFIG_FAILED
;
8324 params
= ospf_lookup_if_params(ifp
, addr
);
8329 UNSET_IF_PARAM(params
, v_wait
);
8330 params
->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
8331 params
->is_v_wait_set
= false;
8333 UNSET_IF_PARAM(params
, fast_hello
);
8334 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
8336 if (params
!= IF_DEF_PARAMS(ifp
)) {
8337 ospf_free_if_params(ifp
, addr
);
8338 ospf_if_update_params(ifp
, addr
);
8341 /* Update timer values in neighbor structure. */
8343 struct ospf
*ospf
= NULL
;
8345 ospf
= ifp
->vrf
->info
;
8347 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
8349 ospf_nbr_timer_update(oi
);
8352 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
8353 if ((oi
= rn
->info
))
8354 ospf_nbr_timer_update(oi
);
8360 DEFUN_HIDDEN (no_ospf_dead_interval
,
8361 no_ospf_dead_interval_cmd
,
8362 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8364 "OSPF interface commands\n"
8365 "Interval time after which a neighbor is declared down\n"
8367 "Minimal 1s dead-interval with fast sub-second hellos\n"
8368 "Hello multiplier factor\n"
8369 "Number of Hellos to send each second\n"
8370 "Address of interface\n")
8372 return no_ip_ospf_dead_interval(self
, vty
, argc
, argv
);
8375 DEFUN (ip_ospf_hello_interval
,
8376 ip_ospf_hello_interval_cmd
,
8377 "ip ospf hello-interval (1-65535) [A.B.C.D]",
8379 "OSPF interface commands\n"
8380 "Time between HELLO packets\n"
8382 "Address of interface\n")
8384 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8386 struct in_addr addr
= {.s_addr
= 0L};
8387 struct ospf_if_params
*params
;
8388 params
= IF_DEF_PARAMS(ifp
);
8389 uint32_t seconds
= 0;
8390 bool is_addr
= false;
8391 uint32_t old_interval
= 0;
8393 argv_find(argv
, argc
, "(1-65535)", &idx
);
8394 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
8396 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8397 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8399 "Please specify interface address by A.B.C.D\n");
8400 return CMD_WARNING_CONFIG_FAILED
;
8403 params
= ospf_get_if_params(ifp
, addr
);
8404 ospf_if_update_params(ifp
, addr
);
8408 old_interval
= params
->v_hello
;
8410 /* Return, if same interval is configured. */
8411 if (old_interval
== seconds
)
8414 SET_IF_PARAM(params
, v_hello
);
8415 params
->v_hello
= seconds
;
8417 if (!params
->is_v_wait_set
) {
8418 SET_IF_PARAM(params
, v_wait
);
8420 * The router dead interval should
8421 * be some multiple of the HelloInterval (perhaps 4 times the
8422 * hello interval) and must be the same for all routers
8423 * attached to a common network.
8425 params
->v_wait
= 4 * seconds
;
8428 ospf_reset_hello_timer(ifp
, addr
, is_addr
);
8433 DEFUN_HIDDEN (ospf_hello_interval
,
8434 ospf_hello_interval_cmd
,
8435 "ospf hello-interval (1-65535) [A.B.C.D]",
8436 "OSPF interface commands\n"
8437 "Time between HELLO packets\n"
8439 "Address of interface\n")
8441 return ip_ospf_hello_interval(self
, vty
, argc
, argv
);
8444 DEFUN (no_ip_ospf_hello_interval
,
8445 no_ip_ospf_hello_interval_cmd
,
8446 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
8449 "OSPF interface commands\n"
8450 "Time between HELLO packets\n" // ignored
8452 "Address of interface\n")
8454 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8456 struct in_addr addr
= {.s_addr
= 0L};
8457 struct ospf_if_params
*params
;
8458 struct route_node
*rn
;
8460 params
= IF_DEF_PARAMS(ifp
);
8462 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8463 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8465 "Please specify interface address by A.B.C.D\n");
8466 return CMD_WARNING_CONFIG_FAILED
;
8469 params
= ospf_lookup_if_params(ifp
, addr
);
8474 UNSET_IF_PARAM(params
, v_hello
);
8475 params
->v_hello
= OSPF_HELLO_INTERVAL_DEFAULT
;
8477 if (!params
->is_v_wait_set
) {
8478 UNSET_IF_PARAM(params
, v_wait
);
8479 params
->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
8482 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8483 struct ospf_interface
*oi
= rn
->info
;
8488 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
8489 oi
->ptp_dmvpn
= IF_DEF_PARAMS(ifp
)->ptp_dmvpn
;
8491 if (oi
->state
> ISM_Down
) {
8492 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
8493 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
8497 if (params
!= IF_DEF_PARAMS(ifp
)) {
8498 ospf_free_if_params(ifp
, addr
);
8499 ospf_if_update_params(ifp
, addr
);
8505 DEFUN_HIDDEN (no_ospf_hello_interval
,
8506 no_ospf_hello_interval_cmd
,
8507 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
8509 "OSPF interface commands\n"
8510 "Time between HELLO packets\n" // ignored
8512 "Address of interface\n")
8514 return no_ip_ospf_hello_interval(self
, vty
, argc
, argv
);
8517 DEFUN(ip_ospf_network
, ip_ospf_network_cmd
,
8518 "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point [dmvpn]>",
8520 "OSPF interface commands\n"
8522 "Specify OSPF broadcast multi-access network\n"
8523 "Specify OSPF NBMA network\n"
8524 "Specify OSPF point-to-multipoint network\n"
8525 "Specify OSPF point-to-point network\n"
8526 "Specify OSPF point-to-point DMVPN network\n")
8528 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8530 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
8531 uint8_t old_ptp_dmvpn
= IF_DEF_PARAMS(ifp
)->ptp_dmvpn
;
8532 struct route_node
*rn
;
8534 if (old_type
== OSPF_IFTYPE_LOOPBACK
) {
8536 "This is a loopback interface. Can't set network type.\n");
8537 return CMD_WARNING_CONFIG_FAILED
;
8540 IF_DEF_PARAMS(ifp
)->ptp_dmvpn
= 0;
8542 if (argv_find(argv
, argc
, "broadcast", &idx
))
8543 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_BROADCAST
;
8544 else if (argv_find(argv
, argc
, "non-broadcast", &idx
))
8545 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_NBMA
;
8546 else if (argv_find(argv
, argc
, "point-to-multipoint", &idx
))
8547 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOMULTIPOINT
;
8548 else if (argv_find(argv
, argc
, "point-to-point", &idx
)) {
8549 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOPOINT
;
8550 if (argv_find(argv
, argc
, "dmvpn", &idx
))
8551 IF_DEF_PARAMS(ifp
)->ptp_dmvpn
= 1;
8554 if (IF_DEF_PARAMS(ifp
)->type
== old_type
8555 && IF_DEF_PARAMS(ifp
)->ptp_dmvpn
== old_ptp_dmvpn
)
8558 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), type
);
8560 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8561 struct ospf_interface
*oi
= rn
->info
;
8566 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
8568 if (oi
->state
> ISM_Down
) {
8569 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
8570 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
8577 DEFUN_HIDDEN (ospf_network
,
8579 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
8580 "OSPF interface commands\n"
8582 "Specify OSPF broadcast multi-access network\n"
8583 "Specify OSPF NBMA network\n"
8584 "Specify OSPF point-to-multipoint network\n"
8585 "Specify OSPF point-to-point network\n")
8587 return ip_ospf_network(self
, vty
, argc
, argv
);
8590 DEFUN (no_ip_ospf_network
,
8591 no_ip_ospf_network_cmd
,
8592 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8595 "OSPF interface commands\n"
8597 "Specify OSPF broadcast multi-access network\n"
8598 "Specify OSPF NBMA network\n"
8599 "Specify OSPF point-to-multipoint network\n"
8600 "Specify OSPF point-to-point network\n")
8602 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8603 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
8604 struct route_node
*rn
;
8606 IF_DEF_PARAMS(ifp
)->type
= ospf_default_iftype(ifp
);
8607 IF_DEF_PARAMS(ifp
)->ptp_dmvpn
= 0;
8609 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
8612 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8613 struct ospf_interface
*oi
= rn
->info
;
8618 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
8620 if (oi
->state
> ISM_Down
) {
8621 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
8622 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
8629 DEFUN_HIDDEN (no_ospf_network
,
8630 no_ospf_network_cmd
,
8631 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8633 "OSPF interface commands\n"
8635 "Specify OSPF broadcast multi-access network\n"
8636 "Specify OSPF NBMA network\n"
8637 "Specify OSPF point-to-multipoint network\n"
8638 "Specify OSPF point-to-point network\n")
8640 return no_ip_ospf_network(self
, vty
, argc
, argv
);
8643 DEFUN (ip_ospf_priority
,
8644 ip_ospf_priority_cmd
,
8645 "ip ospf priority (0-255) [A.B.C.D]",
8647 "OSPF interface commands\n"
8650 "Address of interface\n")
8652 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8655 struct route_node
*rn
;
8656 struct in_addr addr
;
8657 struct ospf_if_params
*params
;
8658 params
= IF_DEF_PARAMS(ifp
);
8660 argv_find(argv
, argc
, "(0-255)", &idx
);
8661 priority
= strtol(argv
[idx
]->arg
, NULL
, 10);
8663 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8664 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8666 "Please specify interface address by A.B.C.D\n");
8667 return CMD_WARNING_CONFIG_FAILED
;
8670 params
= ospf_get_if_params(ifp
, addr
);
8671 ospf_if_update_params(ifp
, addr
);
8674 SET_IF_PARAM(params
, priority
);
8675 params
->priority
= priority
;
8677 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8678 struct ospf_interface
*oi
= rn
->info
;
8683 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
8684 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
8685 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
8692 DEFUN_HIDDEN (ospf_priority
,
8694 "ospf priority (0-255) [A.B.C.D]",
8695 "OSPF interface commands\n"
8698 "Address of interface\n")
8700 return ip_ospf_priority(self
, vty
, argc
, argv
);
8703 DEFUN (no_ip_ospf_priority
,
8704 no_ip_ospf_priority_cmd
,
8705 "no ip ospf priority [(0-255) [A.B.C.D]]",
8708 "OSPF interface commands\n"
8709 "Router priority\n" // ignored
8711 "Address of interface\n")
8713 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8715 struct route_node
*rn
;
8716 struct in_addr addr
;
8717 struct ospf_if_params
*params
;
8719 params
= IF_DEF_PARAMS(ifp
);
8721 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8722 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8724 "Please specify interface address by A.B.C.D\n");
8725 return CMD_WARNING_CONFIG_FAILED
;
8728 params
= ospf_lookup_if_params(ifp
, addr
);
8733 UNSET_IF_PARAM(params
, priority
);
8734 params
->priority
= OSPF_ROUTER_PRIORITY_DEFAULT
;
8736 if (params
!= IF_DEF_PARAMS(ifp
)) {
8737 ospf_free_if_params(ifp
, addr
);
8738 ospf_if_update_params(ifp
, addr
);
8741 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8742 struct ospf_interface
*oi
= rn
->info
;
8747 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
8748 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
8749 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
8756 DEFUN_HIDDEN (no_ospf_priority
,
8757 no_ospf_priority_cmd
,
8758 "no ospf priority [(0-255) [A.B.C.D]]",
8760 "OSPF interface commands\n"
8763 "Address of interface\n")
8765 return no_ip_ospf_priority(self
, vty
, argc
, argv
);
8768 DEFUN (ip_ospf_retransmit_interval
,
8769 ip_ospf_retransmit_interval_addr_cmd
,
8770 "ip ospf retransmit-interval (1-65535) [A.B.C.D]",
8772 "OSPF interface commands\n"
8773 "Time between retransmitting lost link state advertisements\n"
8775 "Address of interface\n")
8777 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8780 struct in_addr addr
;
8781 struct ospf_if_params
*params
;
8782 params
= IF_DEF_PARAMS(ifp
);
8784 argv_find(argv
, argc
, "(1-65535)", &idx
);
8785 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
8787 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8788 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8790 "Please specify interface address by A.B.C.D\n");
8791 return CMD_WARNING_CONFIG_FAILED
;
8794 params
= ospf_get_if_params(ifp
, addr
);
8795 ospf_if_update_params(ifp
, addr
);
8798 SET_IF_PARAM(params
, retransmit_interval
);
8799 params
->retransmit_interval
= seconds
;
8804 DEFUN_HIDDEN (ospf_retransmit_interval
,
8805 ospf_retransmit_interval_cmd
,
8806 "ospf retransmit-interval (1-65535) [A.B.C.D]",
8807 "OSPF interface commands\n"
8808 "Time between retransmitting lost link state advertisements\n"
8810 "Address of interface\n")
8812 return ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
8815 DEFUN (no_ip_ospf_retransmit_interval
,
8816 no_ip_ospf_retransmit_interval_addr_cmd
,
8817 "no ip ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8820 "OSPF interface commands\n"
8821 "Time between retransmitting lost link state advertisements\n"
8823 "Address of interface\n")
8825 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8827 struct in_addr addr
;
8828 struct ospf_if_params
*params
;
8830 params
= IF_DEF_PARAMS(ifp
);
8832 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8833 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8835 "Please specify interface address by A.B.C.D\n");
8836 return CMD_WARNING_CONFIG_FAILED
;
8839 params
= ospf_lookup_if_params(ifp
, addr
);
8844 UNSET_IF_PARAM(params
, retransmit_interval
);
8845 params
->retransmit_interval
= OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
8847 if (params
!= IF_DEF_PARAMS(ifp
)) {
8848 ospf_free_if_params(ifp
, addr
);
8849 ospf_if_update_params(ifp
, addr
);
8855 DEFUN_HIDDEN (no_ospf_retransmit_interval
,
8856 no_ospf_retransmit_interval_cmd
,
8857 "no ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8859 "OSPF interface commands\n"
8860 "Time between retransmitting lost link state advertisements\n"
8862 "Address of interface\n")
8864 return no_ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
8867 DEFUN (ip_ospf_transmit_delay
,
8868 ip_ospf_transmit_delay_addr_cmd
,
8869 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
8871 "OSPF interface commands\n"
8872 "Link state transmit delay\n"
8874 "Address of interface\n")
8876 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8879 struct in_addr addr
;
8880 struct ospf_if_params
*params
;
8882 params
= IF_DEF_PARAMS(ifp
);
8883 argv_find(argv
, argc
, "(1-65535)", &idx
);
8884 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
8886 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8887 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8889 "Please specify interface address by A.B.C.D\n");
8890 return CMD_WARNING_CONFIG_FAILED
;
8893 params
= ospf_get_if_params(ifp
, addr
);
8894 ospf_if_update_params(ifp
, addr
);
8897 SET_IF_PARAM(params
, transmit_delay
);
8898 params
->transmit_delay
= seconds
;
8903 DEFUN_HIDDEN (ospf_transmit_delay
,
8904 ospf_transmit_delay_cmd
,
8905 "ospf transmit-delay (1-65535) [A.B.C.D]",
8906 "OSPF interface commands\n"
8907 "Link state transmit delay\n"
8909 "Address of interface\n")
8911 return ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
8914 DEFUN (no_ip_ospf_transmit_delay
,
8915 no_ip_ospf_transmit_delay_addr_cmd
,
8916 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
8919 "OSPF interface commands\n"
8920 "Link state transmit delay\n"
8922 "Address of interface\n")
8924 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8926 struct in_addr addr
;
8927 struct ospf_if_params
*params
;
8929 params
= IF_DEF_PARAMS(ifp
);
8931 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8932 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8934 "Please specify interface address by A.B.C.D\n");
8935 return CMD_WARNING_CONFIG_FAILED
;
8938 params
= ospf_lookup_if_params(ifp
, addr
);
8943 UNSET_IF_PARAM(params
, transmit_delay
);
8944 params
->transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
8946 if (params
!= IF_DEF_PARAMS(ifp
)) {
8947 ospf_free_if_params(ifp
, addr
);
8948 ospf_if_update_params(ifp
, addr
);
8955 DEFUN_HIDDEN (no_ospf_transmit_delay
,
8956 no_ospf_transmit_delay_cmd
,
8957 "no ospf transmit-delay [(1-65535) [A.B.C.D]]",
8959 "OSPF interface commands\n"
8960 "Link state transmit delay\n"
8962 "Address of interface\n")
8964 return no_ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
8967 DEFUN (ip_ospf_area
,
8969 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]",
8971 "OSPF interface commands\n"
8973 "Enable OSPF on this interface\n"
8974 "OSPF area ID in IP address format\n"
8975 "OSPF area ID as a decimal value\n"
8976 "Address of interface\n")
8978 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8981 struct in_addr area_id
;
8982 struct in_addr addr
;
8983 struct ospf_if_params
*params
= NULL
;
8984 struct route_node
*rn
;
8985 struct ospf
*ospf
= NULL
;
8986 unsigned short instance
= 0;
8990 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
8991 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
8993 argv_find(argv
, argc
, "area", &idx
);
8994 areaid
= argv
[idx
+ 1]->arg
;
8997 ospf
= ifp
->vrf
->info
;
8999 ospf
= ospf_lookup_instance(instance
);
9001 if (instance
&& instance
!= ospf_instance
) {
9003 * At this point we know we have received
9004 * an instance and there is no ospf instance
9005 * associated with it. This means we are
9006 * in a situation where we have an
9007 * ospf command that is setup for a different
9008 * process(instance). We need to safely
9009 * remove the command from ourselves and
9010 * allow the other instance(process) handle
9011 * the configuration command.
9015 params
= IF_DEF_PARAMS(ifp
);
9016 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
9017 UNSET_IF_PARAM(params
, if_area
);
9021 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
; rn
= route_next(rn
))
9022 if ((params
= rn
->info
) && OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
9023 UNSET_IF_PARAM(params
, if_area
);
9028 ospf
= ifp
->vrf
->info
;
9030 ospf_interface_area_unset(ospf
, ifp
);
9033 return CMD_NOT_MY_INSTANCE
;
9036 ret
= str2area_id(areaid
, &area_id
, &format
);
9038 vty_out(vty
, "Please specify area by A.B.C.D|<0-4294967295>\n");
9039 return CMD_WARNING_CONFIG_FAILED
;
9041 if (memcmp(ifp
->name
, "VLINK", 5) == 0) {
9042 vty_out(vty
, "Cannot enable OSPF on a virtual link.\n");
9043 return CMD_WARNING_CONFIG_FAILED
;
9047 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
)) {
9048 if (rn
->info
!= NULL
) {
9050 "Please remove all network commands first.\n");
9051 return CMD_WARNING_CONFIG_FAILED
;
9056 params
= IF_DEF_PARAMS(ifp
);
9057 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)
9058 && !IPV4_ADDR_SAME(¶ms
->if_area
, &area_id
)) {
9060 "Must remove previous area config before changing ospf area \n");
9061 return CMD_WARNING_CONFIG_FAILED
;
9064 // Check if we have an address arg and proccess it
9065 if (argc
== idx
+ 3) {
9066 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
9068 "Please specify Intf Address by A.B.C.D\n");
9069 return CMD_WARNING_CONFIG_FAILED
;
9071 // update/create address-level params
9072 params
= ospf_get_if_params((ifp
), (addr
));
9073 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
9074 if (!IPV4_ADDR_SAME(¶ms
->if_area
, &area_id
)) {
9076 "Must remove previous area/address config before changing ospf area\n");
9077 return CMD_WARNING_CONFIG_FAILED
;
9081 ospf_if_update_params((ifp
), (addr
));
9084 /* enable ospf on this interface with area_id */
9086 SET_IF_PARAM(params
, if_area
);
9087 params
->if_area
= area_id
;
9088 params
->if_area_id_fmt
= format
;
9092 ospf_interface_area_set(ospf
, ifp
);
9097 DEFUN (no_ip_ospf_area
,
9098 no_ip_ospf_area_cmd
,
9099 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]",
9102 "OSPF interface commands\n"
9104 "Disable OSPF on this interface\n"
9105 "OSPF area ID in IP address format\n"
9106 "OSPF area ID as a decimal value\n"
9107 "Address of interface\n")
9109 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9112 struct ospf_if_params
*params
;
9113 unsigned short instance
= 0;
9114 struct in_addr addr
;
9115 struct in_addr area_id
;
9117 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
9118 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
9121 ospf
= ifp
->vrf
->info
;
9123 ospf
= ospf_lookup_instance(instance
);
9125 if (instance
&& instance
!= ospf_instance
)
9126 return CMD_NOT_MY_INSTANCE
;
9128 argv_find(argv
, argc
, "area", &idx
);
9130 // Check if we have an address arg and proccess it
9131 if (argc
== idx
+ 3) {
9132 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
9134 "Please specify Intf Address by A.B.C.D\n");
9135 return CMD_WARNING_CONFIG_FAILED
;
9137 params
= ospf_lookup_if_params(ifp
, addr
);
9138 if ((params
) == NULL
)
9141 params
= IF_DEF_PARAMS(ifp
);
9143 area_id
= params
->if_area
;
9144 if (!OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
9146 "Can't find specified interface area configuration.\n");
9147 return CMD_WARNING_CONFIG_FAILED
;
9150 UNSET_IF_PARAM(params
, if_area
);
9151 if (params
!= IF_DEF_PARAMS((ifp
))) {
9152 ospf_free_if_params((ifp
), (addr
));
9153 ospf_if_update_params((ifp
), (addr
));
9157 ospf_interface_area_unset(ospf
, ifp
);
9158 ospf_area_check_free(ospf
, area_id
);
9164 DEFUN (ip_ospf_passive
,
9165 ip_ospf_passive_cmd
,
9166 "ip ospf passive [A.B.C.D]",
9168 "OSPF interface commands\n"
9169 "Suppress routing updates on an interface\n"
9170 "Address of interface\n")
9172 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9174 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
9175 struct ospf_if_params
*params
;
9179 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9182 "Please specify interface address by A.B.C.D\n");
9183 return CMD_WARNING_CONFIG_FAILED
;
9185 params
= ospf_get_if_params(ifp
, addr
);
9186 ospf_if_update_params(ifp
, addr
);
9188 params
= IF_DEF_PARAMS(ifp
);
9191 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_PASSIVE
);
9196 DEFUN (no_ip_ospf_passive
,
9197 no_ip_ospf_passive_cmd
,
9198 "no ip ospf passive [A.B.C.D]",
9201 "OSPF interface commands\n"
9202 "Enable routing updates on an interface\n"
9203 "Address of interface\n")
9205 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9207 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
9208 struct ospf_if_params
*params
;
9212 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9215 "Please specify interface address by A.B.C.D\n");
9216 return CMD_WARNING_CONFIG_FAILED
;
9218 params
= ospf_lookup_if_params(ifp
, addr
);
9222 params
= IF_DEF_PARAMS(ifp
);
9225 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_ACTIVE
);
9230 DEFUN (ospf_redistribute_source
,
9231 ospf_redistribute_source_cmd
,
9232 "redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9234 FRR_REDIST_HELP_STR_OSPFD
9235 "Metric for redistributed routes\n"
9236 "OSPF default metric\n"
9237 "OSPF exterior metric type for redistributed routes\n"
9238 "Set OSPF External Type 1/2 metrics\n"
9239 "Route map reference\n"
9240 "Pointer to route-map entries\n")
9242 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9243 int idx_protocol
= 1;
9247 struct ospf_redist
*red
;
9249 bool update
= false;
9251 /* Get distribute source. */
9252 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
9254 return CMD_WARNING_CONFIG_FAILED
;
9256 /* Get metric value. */
9257 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
9258 if (!str2metric(argv
[idx
]->arg
, &metric
))
9259 return CMD_WARNING_CONFIG_FAILED
;
9262 /* Get metric type. */
9263 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
9264 if (!str2metric_type(argv
[idx
]->arg
, &type
))
9265 return CMD_WARNING_CONFIG_FAILED
;
9269 red
= ospf_redist_lookup(ospf
, source
, 0);
9271 red
= ospf_redist_add(ospf
, source
, 0);
9276 if (argv_find(argv
, argc
, "route-map", &idx
)) {
9277 ospf_routemap_set(red
, argv
[idx
+ 1]->arg
);
9279 ospf_routemap_unset(red
);
9282 return ospf_redistribute_update(ospf
, red
, source
, 0, type
,
9285 return ospf_redistribute_set(ospf
, red
, source
, 0, type
,
9289 DEFUN (no_ospf_redistribute_source
,
9290 no_ospf_redistribute_source_cmd
,
9291 "no redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9294 FRR_REDIST_HELP_STR_OSPFD
9295 "Metric for redistributed routes\n"
9296 "OSPF default metric\n"
9297 "OSPF exterior metric type for redistributed routes\n"
9298 "Set OSPF External Type 1/2 metrics\n"
9299 "Route map reference\n"
9300 "Pointer to route-map entries\n")
9302 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9303 int idx_protocol
= 2;
9305 struct ospf_redist
*red
;
9307 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
9309 return CMD_WARNING_CONFIG_FAILED
;
9311 red
= ospf_redist_lookup(ospf
, source
, 0);
9315 ospf_routemap_unset(red
);
9316 ospf_redist_del(ospf
, source
, 0);
9318 return ospf_redistribute_unset(ospf
, source
, 0);
9321 DEFUN (ospf_redistribute_instance_source
,
9322 ospf_redistribute_instance_source_cmd
,
9323 "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9325 "Open Shortest Path First\n"
9326 "Non-main Kernel Routing Table\n"
9327 "Instance ID/Table ID\n"
9328 "Metric for redistributed routes\n"
9329 "OSPF default metric\n"
9330 "OSPF exterior metric type for redistributed routes\n"
9331 "Set OSPF External Type 1/2 metrics\n"
9332 "Route map reference\n"
9333 "Pointer to route-map entries\n")
9335 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9336 int idx_ospf_table
= 1;
9342 unsigned short instance
;
9343 struct ospf_redist
*red
;
9344 bool update
= false;
9346 source
= proto_redistnum(AFI_IP
, argv
[idx_ospf_table
]->text
);
9349 vty_out(vty
, "Unknown instance redistribution\n");
9350 return CMD_WARNING_CONFIG_FAILED
;
9353 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9355 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
9357 "Instance redistribution in non-instanced OSPF not allowed\n");
9358 return CMD_WARNING_CONFIG_FAILED
;
9361 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
9362 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
9363 return CMD_WARNING_CONFIG_FAILED
;
9366 /* Get metric value. */
9367 if (argv_find(argv
, argc
, "metric", &idx
))
9368 if (!str2metric(argv
[idx
+ 1]->arg
, &metric
))
9369 return CMD_WARNING_CONFIG_FAILED
;
9372 /* Get metric type. */
9373 if (argv_find(argv
, argc
, "metric-type", &idx
))
9374 if (!str2metric_type(argv
[idx
+ 1]->arg
, &type
))
9375 return CMD_WARNING_CONFIG_FAILED
;
9377 red
= ospf_redist_lookup(ospf
, source
, instance
);
9379 red
= ospf_redist_add(ospf
, source
, instance
);
9384 if (argv_find(argv
, argc
, "route-map", &idx
))
9385 ospf_routemap_set(red
, argv
[idx
+ 1]->arg
);
9387 ospf_routemap_unset(red
);
9390 return ospf_redistribute_update(ospf
, red
, source
, instance
,
9393 return ospf_redistribute_set(ospf
, red
, source
, instance
, type
,
9397 DEFUN (no_ospf_redistribute_instance_source
,
9398 no_ospf_redistribute_instance_source_cmd
,
9399 "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9402 "Open Shortest Path First\n"
9403 "Non-main Kernel Routing Table\n"
9404 "Instance ID/Table Id\n"
9405 "Metric for redistributed routes\n"
9406 "OSPF default metric\n"
9407 "OSPF exterior metric type for redistributed routes\n"
9408 "Set OSPF External Type 1/2 metrics\n"
9409 "Route map reference\n"
9410 "Pointer to route-map entries\n")
9412 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9413 int idx_ospf_table
= 2;
9415 unsigned int instance
;
9416 struct ospf_redist
*red
;
9419 if (strncmp(argv
[idx_ospf_table
]->arg
, "o", 1) == 0)
9420 source
= ZEBRA_ROUTE_OSPF
;
9422 source
= ZEBRA_ROUTE_TABLE
;
9424 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9426 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
9428 "Instance redistribution in non-instanced OSPF not allowed\n");
9429 return CMD_WARNING_CONFIG_FAILED
;
9432 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
9433 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
9434 return CMD_WARNING_CONFIG_FAILED
;
9437 red
= ospf_redist_lookup(ospf
, source
, instance
);
9441 ospf_routemap_unset(red
);
9442 ospf_redist_del(ospf
, source
, instance
);
9444 return ospf_redistribute_unset(ospf
, source
, instance
);
9447 DEFUN (ospf_distribute_list_out
,
9448 ospf_distribute_list_out_cmd
,
9449 "distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD
,
9450 "Filter networks in routing updates\n"
9451 "Access-list name\n"
9453 FRR_REDIST_HELP_STR_OSPFD
)
9455 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9459 char *proto
= argv
[argc
- 1]->text
;
9461 /* Get distribute source. */
9462 source
= proto_redistnum(AFI_IP
, proto
);
9464 return CMD_WARNING_CONFIG_FAILED
;
9466 return ospf_distribute_list_out_set(ospf
, source
, argv
[idx_word
]->arg
);
9469 DEFUN (no_ospf_distribute_list_out
,
9470 no_ospf_distribute_list_out_cmd
,
9471 "no distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD
,
9473 "Filter networks in routing updates\n"
9474 "Access-list name\n"
9476 FRR_REDIST_HELP_STR_OSPFD
)
9478 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9482 char *proto
= argv
[argc
- 1]->text
;
9483 source
= proto_redistnum(AFI_IP
, proto
);
9485 return CMD_WARNING_CONFIG_FAILED
;
9487 return ospf_distribute_list_out_unset(ospf
, source
,
9488 argv
[idx_word
]->arg
);
9491 /* Default information originate. */
9492 DEFUN (ospf_default_information_originate
,
9493 ospf_default_information_originate_cmd
,
9494 "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9495 "Control distribution of default information\n"
9496 "Distribute a default route\n"
9497 "Always advertise default route\n"
9498 "OSPF default metric\n"
9500 "OSPF metric type for default routes\n"
9501 "Set OSPF External Type 1/2 metrics\n"
9502 "Route map reference\n"
9503 "Pointer to route-map entries\n")
9505 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9506 int default_originate
= DEFAULT_ORIGINATE_ZEBRA
;
9509 struct ospf_redist
*red
;
9511 int cur_originate
= ospf
->default_originate
;
9512 bool sameRtmap
= false;
9515 red
= ospf_redist_add(ospf
, DEFAULT_ROUTE
, 0);
9517 /* Check whether "always" was specified */
9518 if (argv_find(argv
, argc
, "always", &idx
))
9519 default_originate
= DEFAULT_ORIGINATE_ALWAYS
;
9521 /* Get metric value */
9522 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
9523 if (!str2metric(argv
[idx
]->arg
, &metric
))
9524 return CMD_WARNING_CONFIG_FAILED
;
9527 /* Get metric type. */
9528 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
9529 if (!str2metric_type(argv
[idx
]->arg
, &type
))
9530 return CMD_WARNING_CONFIG_FAILED
;
9534 if (argv_find(argv
, argc
, "route-map", &idx
))
9535 rtmap
= argv
[idx
+ 1]->arg
;
9537 /* To check if user is providing same route map */
9538 if ((!rtmap
&& !ROUTEMAP_NAME(red
)) ||
9539 (rtmap
&& ROUTEMAP_NAME(red
) &&
9540 (strcmp(rtmap
, ROUTEMAP_NAME(red
)) == 0)))
9543 /* Don't allow if the same lsa is already originated. */
9545 && (red
->dmetric
.type
== type
)
9546 && (red
->dmetric
.value
== metric
)
9547 && (cur_originate
== default_originate
))
9550 /* Updating Metric details */
9551 red
->dmetric
.type
= type
;
9552 red
->dmetric
.value
= metric
;
9554 /* updating route map details */
9556 ospf_routemap_set(red
, rtmap
);
9558 ospf_routemap_unset(red
);
9560 return ospf_redistribute_default_set(ospf
, default_originate
, type
,
9564 DEFUN (no_ospf_default_information_originate
,
9565 no_ospf_default_information_originate_cmd
,
9566 "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9568 "Control distribution of default information\n"
9569 "Distribute a default route\n"
9570 "Always advertise default route\n"
9571 "OSPF default metric\n"
9573 "OSPF metric type for default routes\n"
9574 "Set OSPF External Type 1/2 metrics\n"
9575 "Route map reference\n"
9576 "Pointer to route-map entries\n")
9578 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9579 struct ospf_redist
*red
;
9581 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
9585 ospf_routemap_unset(red
);
9586 ospf_redist_del(ospf
, DEFAULT_ROUTE
, 0);
9588 return ospf_redistribute_default_set(ospf
, DEFAULT_ORIGINATE_NONE
,
9592 DEFUN (ospf_default_metric
,
9593 ospf_default_metric_cmd
,
9594 "default-metric (0-16777214)",
9595 "Set metric of redistributed routes\n"
9598 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9602 if (!str2metric(argv
[idx_number
]->arg
, &metric
))
9603 return CMD_WARNING_CONFIG_FAILED
;
9605 ospf
->default_metric
= metric
;
9610 DEFUN (no_ospf_default_metric
,
9611 no_ospf_default_metric_cmd
,
9612 "no default-metric [(0-16777214)]",
9614 "Set metric of redistributed routes\n"
9617 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9619 ospf
->default_metric
= -1;
9625 DEFUN (ospf_distance
,
9628 "Administrative distance\n"
9629 "OSPF Administrative distance\n")
9631 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9635 distance
= atoi(argv
[idx_number
]->arg
);
9636 if (ospf
->distance_all
!= distance
) {
9637 ospf
->distance_all
= distance
;
9638 ospf_restart_spf(ospf
);
9644 DEFUN (no_ospf_distance
,
9645 no_ospf_distance_cmd
,
9646 "no distance (1-255)",
9648 "Administrative distance\n"
9649 "OSPF Administrative distance\n")
9651 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9653 if (ospf
->distance_all
) {
9654 ospf
->distance_all
= 0;
9655 ospf_restart_spf(ospf
);
9661 DEFUN (no_ospf_distance_ospf
,
9662 no_ospf_distance_ospf_cmd
,
9663 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
9665 "Administrative distance\n"
9666 "OSPF administrative distance\n"
9667 "Intra-area routes\n"
9668 "Distance for intra-area routes\n"
9669 "Inter-area routes\n"
9670 "Distance for inter-area routes\n"
9672 "Distance for external routes\n")
9674 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9677 if (argv_find(argv
, argc
, "intra-area", &idx
) || argc
== 3)
9678 idx
= ospf
->distance_intra
= 0;
9679 if (argv_find(argv
, argc
, "inter-area", &idx
) || argc
== 3)
9680 idx
= ospf
->distance_inter
= 0;
9681 if (argv_find(argv
, argc
, "external", &idx
) || argc
== 3)
9682 ospf
->distance_external
= 0;
9687 DEFUN (ospf_distance_ospf
,
9688 ospf_distance_ospf_cmd
,
9689 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
9690 "Administrative distance\n"
9691 "OSPF administrative distance\n"
9692 "Intra-area routes\n"
9693 "Distance for intra-area routes\n"
9694 "Inter-area routes\n"
9695 "Distance for inter-area routes\n"
9697 "Distance for external routes\n")
9699 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9702 ospf
->distance_intra
= 0;
9703 ospf
->distance_inter
= 0;
9704 ospf
->distance_external
= 0;
9706 if (argv_find(argv
, argc
, "intra-area", &idx
))
9707 ospf
->distance_intra
= atoi(argv
[idx
+ 1]->arg
);
9709 if (argv_find(argv
, argc
, "inter-area", &idx
))
9710 ospf
->distance_inter
= atoi(argv
[idx
+ 1]->arg
);
9712 if (argv_find(argv
, argc
, "external", &idx
))
9713 ospf
->distance_external
= atoi(argv
[idx
+ 1]->arg
);
9718 DEFUN (ip_ospf_mtu_ignore
,
9719 ip_ospf_mtu_ignore_addr_cmd
,
9720 "ip ospf mtu-ignore [A.B.C.D]",
9722 "OSPF interface commands\n"
9723 "Disable MTU mismatch detection on this interface\n"
9724 "Address of interface\n")
9726 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9728 struct in_addr addr
;
9731 struct ospf_if_params
*params
;
9732 params
= IF_DEF_PARAMS(ifp
);
9735 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9738 "Please specify interface address by A.B.C.D\n");
9739 return CMD_WARNING_CONFIG_FAILED
;
9741 params
= ospf_get_if_params(ifp
, addr
);
9742 ospf_if_update_params(ifp
, addr
);
9744 params
->mtu_ignore
= 1;
9745 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
9746 SET_IF_PARAM(params
, mtu_ignore
);
9748 UNSET_IF_PARAM(params
, mtu_ignore
);
9749 if (params
!= IF_DEF_PARAMS(ifp
)) {
9750 ospf_free_if_params(ifp
, addr
);
9751 ospf_if_update_params(ifp
, addr
);
9757 DEFUN (no_ip_ospf_mtu_ignore
,
9758 no_ip_ospf_mtu_ignore_addr_cmd
,
9759 "no ip ospf mtu-ignore [A.B.C.D]",
9762 "OSPF interface commands\n"
9763 "Disable MTU mismatch detection on this interface\n"
9764 "Address of interface\n")
9766 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9768 struct in_addr addr
;
9771 struct ospf_if_params
*params
;
9772 params
= IF_DEF_PARAMS(ifp
);
9775 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9778 "Please specify interface address by A.B.C.D\n");
9779 return CMD_WARNING_CONFIG_FAILED
;
9781 params
= ospf_get_if_params(ifp
, addr
);
9782 ospf_if_update_params(ifp
, addr
);
9784 params
->mtu_ignore
= 0;
9785 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
9786 SET_IF_PARAM(params
, mtu_ignore
);
9788 UNSET_IF_PARAM(params
, mtu_ignore
);
9789 if (params
!= IF_DEF_PARAMS(ifp
)) {
9790 ospf_free_if_params(ifp
, addr
);
9791 ospf_if_update_params(ifp
, addr
);
9798 DEFUN (ospf_max_metric_router_lsa_admin
,
9799 ospf_max_metric_router_lsa_admin_cmd
,
9800 "max-metric router-lsa administrative",
9801 "OSPF maximum / infinite-distance metric\n"
9802 "Advertise own Router-LSA with infinite distance (stub router)\n"
9803 "Administratively applied, for an indefinite period\n")
9805 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9806 struct listnode
*ln
;
9807 struct ospf_area
*area
;
9809 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
9810 SET_FLAG(area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
);
9812 if (!CHECK_FLAG(area
->stub_router_state
,
9813 OSPF_AREA_IS_STUB_ROUTED
))
9814 ospf_router_lsa_update_area(area
);
9817 /* Allows for areas configured later to get the property */
9818 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
;
9823 DEFUN (no_ospf_max_metric_router_lsa_admin
,
9824 no_ospf_max_metric_router_lsa_admin_cmd
,
9825 "no max-metric router-lsa administrative",
9827 "OSPF maximum / infinite-distance metric\n"
9828 "Advertise own Router-LSA with infinite distance (stub router)\n"
9829 "Administratively applied, for an indefinite period\n")
9831 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9832 struct listnode
*ln
;
9833 struct ospf_area
*area
;
9835 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
9836 UNSET_FLAG(area
->stub_router_state
,
9837 OSPF_AREA_ADMIN_STUB_ROUTED
);
9839 /* Don't trample on the start-up stub timer */
9840 if (CHECK_FLAG(area
->stub_router_state
,
9841 OSPF_AREA_IS_STUB_ROUTED
)
9842 && !area
->t_stub_router
) {
9843 UNSET_FLAG(area
->stub_router_state
,
9844 OSPF_AREA_IS_STUB_ROUTED
);
9845 ospf_router_lsa_update_area(area
);
9848 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET
;
9852 DEFUN (ospf_max_metric_router_lsa_startup
,
9853 ospf_max_metric_router_lsa_startup_cmd
,
9854 "max-metric router-lsa on-startup (5-86400)",
9855 "OSPF maximum / infinite-distance metric\n"
9856 "Advertise own Router-LSA with infinite distance (stub router)\n"
9857 "Automatically advertise stub Router-LSA on startup of OSPF\n"
9858 "Time (seconds) to advertise self as stub-router\n")
9860 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9862 unsigned int seconds
;
9865 vty_out(vty
, "%% Must supply stub-router period\n");
9866 return CMD_WARNING_CONFIG_FAILED
;
9869 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9871 ospf
->stub_router_startup_time
= seconds
;
9876 DEFUN (no_ospf_max_metric_router_lsa_startup
,
9877 no_ospf_max_metric_router_lsa_startup_cmd
,
9878 "no max-metric router-lsa on-startup [(5-86400)]",
9880 "OSPF maximum / infinite-distance metric\n"
9881 "Advertise own Router-LSA with infinite distance (stub router)\n"
9882 "Automatically advertise stub Router-LSA on startup of OSPF\n"
9883 "Time (seconds) to advertise self as stub-router\n")
9885 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9886 struct listnode
*ln
;
9887 struct ospf_area
*area
;
9889 ospf
->stub_router_startup_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
9891 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
9892 SET_FLAG(area
->stub_router_state
,
9893 OSPF_AREA_WAS_START_STUB_ROUTED
);
9894 THREAD_OFF(area
->t_stub_router
);
9896 /* Don't trample on admin stub routed */
9897 if (!CHECK_FLAG(area
->stub_router_state
,
9898 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
9899 UNSET_FLAG(area
->stub_router_state
,
9900 OSPF_AREA_IS_STUB_ROUTED
);
9901 ospf_router_lsa_update_area(area
);
9908 DEFUN (ospf_max_metric_router_lsa_shutdown
,
9909 ospf_max_metric_router_lsa_shutdown_cmd
,
9910 "max-metric router-lsa on-shutdown (5-100)",
9911 "OSPF maximum / infinite-distance metric\n"
9912 "Advertise own Router-LSA with infinite distance (stub router)\n"
9913 "Advertise stub-router prior to full shutdown of OSPF\n"
9914 "Time (seconds) to wait till full shutdown\n")
9916 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9918 unsigned int seconds
;
9921 vty_out(vty
, "%% Must supply stub-router shutdown period\n");
9922 return CMD_WARNING_CONFIG_FAILED
;
9925 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9927 ospf
->stub_router_shutdown_time
= seconds
;
9932 DEFUN (no_ospf_max_metric_router_lsa_shutdown
,
9933 no_ospf_max_metric_router_lsa_shutdown_cmd
,
9934 "no max-metric router-lsa on-shutdown [(5-100)]",
9936 "OSPF maximum / infinite-distance metric\n"
9937 "Advertise own Router-LSA with infinite distance (stub router)\n"
9938 "Advertise stub-router prior to full shutdown of OSPF\n"
9939 "Time (seconds) to wait till full shutdown\n")
9941 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9943 ospf
->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
9948 DEFUN (ospf_proactive_arp
,
9949 ospf_proactive_arp_cmd
,
9951 "Allow sending ARP requests proactively\n")
9953 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9955 ospf
->proactive_arp
= true;
9960 DEFUN (no_ospf_proactive_arp
,
9961 no_ospf_proactive_arp_cmd
,
9964 "Disallow sending ARP requests proactively\n")
9966 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9968 ospf
->proactive_arp
= false;
9973 /* Graceful Restart HELPER Commands */
9974 DEFPY(ospf_gr_helper_enable
, ospf_gr_helper_enable_cmd
,
9975 "graceful-restart helper enable [A.B.C.D$address]",
9976 "OSPF Graceful Restart\n"
9978 "Enable Helper support\n"
9979 "Advertising Router-ID\n")
9981 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9984 ospf_gr_helper_support_set_per_routerid(ospf
, &address
,
9989 ospf_gr_helper_support_set(ospf
, OSPF_GR_TRUE
);
9994 DEFPY(no_ospf_gr_helper_enable
,
9995 no_ospf_gr_helper_enable_cmd
,
9996 "no graceful-restart helper enable [A.B.C.D$address]",
9998 "OSPF Graceful Restart\n"
10000 "Enable Helper support\n"
10001 "Advertising Router-ID\n")
10003 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10006 ospf_gr_helper_support_set_per_routerid(ospf
, &address
,
10008 return CMD_SUCCESS
;
10011 ospf_gr_helper_support_set(ospf
, OSPF_GR_FALSE
);
10012 return CMD_SUCCESS
;
10015 DEFPY(ospf_gr_helper_enable_lsacheck
,
10016 ospf_gr_helper_enable_lsacheck_cmd
,
10017 "graceful-restart helper strict-lsa-checking",
10018 "OSPF Graceful Restart\n"
10020 "Enable strict LSA check\n")
10022 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10024 ospf_gr_helper_lsa_check_set(ospf
, OSPF_GR_TRUE
);
10025 return CMD_SUCCESS
;
10028 DEFPY(no_ospf_gr_helper_enable_lsacheck
,
10029 no_ospf_gr_helper_enable_lsacheck_cmd
,
10030 "no graceful-restart helper strict-lsa-checking",
10032 "OSPF Graceful Restart\n"
10034 "Disable strict LSA check\n")
10036 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10038 ospf_gr_helper_lsa_check_set(ospf
, OSPF_GR_FALSE
);
10039 return CMD_SUCCESS
;
10042 DEFPY(ospf_gr_helper_supported_grace_time
,
10043 ospf_gr_helper_supported_grace_time_cmd
,
10044 "graceful-restart helper supported-grace-time (10-1800)$interval",
10045 "OSPF Graceful Restart\n"
10047 "Supported grace timer\n"
10048 "Grace interval(in seconds)\n")
10050 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10052 ospf_gr_helper_supported_gracetime_set(ospf
, interval
);
10053 return CMD_SUCCESS
;
10056 DEFPY(no_ospf_gr_helper_supported_grace_time
,
10057 no_ospf_gr_helper_supported_grace_time_cmd
,
10058 "no graceful-restart helper supported-grace-time (10-1800)$interval",
10060 "OSPF Graceful Restart\n"
10062 "Supported grace timer\n"
10063 "Grace interval(in seconds)\n")
10065 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10067 ospf_gr_helper_supported_gracetime_set(ospf
, OSPF_MAX_GRACE_INTERVAL
);
10068 return CMD_SUCCESS
;
10071 DEFPY(ospf_gr_helper_planned_only
,
10072 ospf_gr_helper_planned_only_cmd
,
10073 "graceful-restart helper planned-only",
10074 "OSPF Graceful Restart\n"
10076 "Supported only planned restart\n")
10078 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10080 ospf_gr_helper_set_supported_planned_only_restart(ospf
, OSPF_GR_TRUE
);
10082 return CMD_SUCCESS
;
10085 /* External Route Aggregation */
10086 DEFUN (ospf_external_route_aggregation
,
10087 ospf_external_route_aggregation_cmd
,
10088 "summary-address A.B.C.D/M [tag (1-4294967295)]",
10089 "External summary address\n"
10090 "Summary address prefix\n"
10092 "Router tag value\n")
10094 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10095 struct prefix_ipv4 p
;
10097 route_tag_t tag
= 0;
10098 int ret
= OSPF_SUCCESS
;
10100 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
10102 if (is_default_prefix4(&p
)) {
10104 "Default address shouldn't be configured as summary address.\n");
10105 return CMD_SUCCESS
;
10108 /* Apply mask for given prefix. */
10111 if (!is_valid_summary_addr(&p
)) {
10112 vty_out(vty
, "Not a valid summary address.\n");
10113 return CMD_WARNING_CONFIG_FAILED
;
10117 tag
= strtoul(argv
[idx
+ 2]->arg
, NULL
, 10);
10119 ret
= ospf_asbr_external_aggregator_set(ospf
, &p
, tag
);
10120 if (ret
== OSPF_INVALID
)
10121 vty_out(vty
, "Invalid configuration!!\n");
10123 return CMD_SUCCESS
;
10126 DEFUN (no_ospf_external_route_aggregation
,
10127 no_ospf_external_route_aggregation_cmd
,
10128 "no summary-address A.B.C.D/M [tag (1-4294967295)]",
10130 "External summary address\n"
10131 "Summary address prefix\n"
10133 "Router tag value\n")
10135 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10136 struct prefix_ipv4 p
;
10138 route_tag_t tag
= 0;
10139 int ret
= OSPF_SUCCESS
;
10141 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
10143 if (is_default_prefix4(&p
)) {
10145 "Default address shouldn't be configured as summary address.\n");
10146 return CMD_SUCCESS
;
10149 /* Apply mask for given prefix. */
10152 if (!is_valid_summary_addr(&p
)) {
10153 vty_out(vty
, "Not a valid summary address.\n");
10154 return CMD_WARNING_CONFIG_FAILED
;
10158 tag
= strtoul(argv
[idx
+ 2]->arg
, NULL
, 10);
10160 ret
= ospf_asbr_external_aggregator_unset(ospf
, &p
, tag
);
10161 if (ret
== OSPF_INVALID
)
10162 vty_out(vty
, "Invalid configuration!!\n");
10164 return CMD_SUCCESS
;
10167 DEFPY(no_ospf_gr_helper_planned_only
,
10168 no_ospf_gr_helper_planned_only_cmd
,
10169 "no graceful-restart helper planned-only",
10171 "OSPF Graceful Restart\n"
10173 "Supported only for planned restart\n")
10175 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10177 ospf_gr_helper_set_supported_planned_only_restart(ospf
, OSPF_GR_FALSE
);
10179 return CMD_SUCCESS
;
10182 static int ospf_print_vty_helper_dis_rtr_walkcb(struct hash_bucket
*bucket
,
10185 struct advRtr
*rtr
= bucket
->data
;
10186 struct vty
*vty
= (struct vty
*)arg
;
10187 static unsigned int count
;
10189 vty_out(vty
, "%-6pI4,", &rtr
->advRtrAddr
);
10192 if (count
% 5 == 0)
10193 vty_out(vty
, "\n");
10195 return HASHWALK_CONTINUE
;
10198 static int ospf_print_json_helper_enabled_rtr_walkcb(struct hash_bucket
*bucket
,
10201 struct advRtr
*rtr
= bucket
->data
;
10202 struct json_object
*json_rid_array
= arg
;
10203 struct json_object
*json_rid
;
10205 json_rid
= json_object_new_object();
10207 json_object_string_addf(json_rid
, "routerId", "%pI4", &rtr
->advRtrAddr
);
10208 json_object_array_add(json_rid_array
, json_rid
);
10210 return HASHWALK_CONTINUE
;
10213 static int ospf_show_gr_helper_details(struct vty
*vty
, struct ospf
*ospf
,
10214 uint8_t use_vrf
, json_object
*json
,
10215 bool uj
, bool detail
)
10217 struct listnode
*node
;
10218 struct ospf_interface
*oi
;
10219 char buf
[PREFIX_STRLEN
];
10220 json_object
*json_vrf
= NULL
;
10224 json_vrf
= json_object_new_object();
10229 if (ospf
->instance
) {
10231 json_object_int_add(json
, "ospfInstance",
10234 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
10237 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
10241 json_object_object_add(json
, ospf_get_name(ospf
),
10244 vty_out(vty
, "\n");
10246 /* Show Router ID. */
10248 json_object_string_add(json_vrf
, "routerId",
10249 inet_ntop(AF_INET
, &ospf
->router_id
,
10250 buf
, sizeof(buf
)));
10252 vty_out(vty
, "\n OSPF Router with ID (%pI4)\n\n",
10258 if (ospf
->is_helper_supported
)
10260 " Graceful restart helper support enabled.\n");
10263 " Graceful restart helper support disabled.\n");
10265 if (ospf
->strict_lsa_check
)
10266 vty_out(vty
, " Strict LSA check is enabled.\n");
10268 vty_out(vty
, " Strict LSA check is disabled.\n");
10270 if (ospf
->only_planned_restart
)
10272 " Helper supported for planned restarts only.\n");
10275 " Helper supported for Planned and Unplanned Restarts.\n");
10278 " Supported Graceful restart interval: %d(in seconds).\n",
10279 ospf
->supported_grace_time
);
10281 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf
)) {
10282 vty_out(vty
, " Enable Router list:\n");
10284 hash_walk(ospf
->enable_rtr_list
,
10285 ospf_print_vty_helper_dis_rtr_walkcb
, vty
);
10286 vty_out(vty
, "\n\n");
10289 if (ospf
->last_exit_reason
!= OSPF_GR_HELPER_EXIT_NONE
) {
10290 vty_out(vty
, " Last Helper exit Reason :%s\n",
10291 ospf_exit_reason2str(ospf
->last_exit_reason
));
10294 if (ospf
->active_restarter_cnt
)
10296 " Number of Active neighbours in graceful restart: %d\n",
10297 ospf
->active_restarter_cnt
);
10299 vty_out(vty
, "\n");
10302 json_object_string_add(
10303 json_vrf
, "helperSupport",
10304 (ospf
->is_helper_supported
) ? "Enabled" : "Disabled");
10305 json_object_string_add(json_vrf
, "strictLsaCheck",
10306 (ospf
->strict_lsa_check
) ? "Enabled"
10308 json_object_string_add(
10309 json_vrf
, "restartSupoort",
10310 (ospf
->only_planned_restart
)
10311 ? "Planned Restart only"
10312 : "Planned and Unplanned Restarts");
10314 json_object_int_add(json_vrf
, "supportedGracePeriod",
10315 ospf
->supported_grace_time
);
10317 if (ospf
->last_exit_reason
!= OSPF_GR_HELPER_EXIT_NONE
)
10318 json_object_string_add(
10319 json_vrf
, "lastExitReason",
10320 ospf_exit_reason2str(ospf
->last_exit_reason
));
10322 if (ospf
->active_restarter_cnt
)
10323 json_object_int_add(json_vrf
, "activeRestarterCnt",
10324 ospf
->active_restarter_cnt
);
10326 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf
)) {
10327 struct json_object
*json_rid_array
=
10328 json_object_new_array();
10330 json_object_object_add(json_vrf
, "enabledRouterIds",
10333 hash_walk(ospf
->enable_rtr_list
,
10334 ospf_print_json_helper_enabled_rtr_walkcb
,
10342 json_object
*json_neighbors
= NULL
;
10344 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
10345 struct route_node
*rn
;
10346 struct ospf_neighbor
*nbr
;
10347 json_object
*json_neigh
;
10349 if (ospf_interface_neighbor_count(oi
) == 0)
10353 json_object_object_get_ex(json_vrf
, "neighbors",
10355 if (!json_neighbors
) {
10357 json_object_new_object();
10358 json_object_object_add(json_vrf
,
10364 for (rn
= route_top(oi
->nbrs
); rn
;
10365 rn
= route_next(rn
)) {
10372 if (!OSPF_GR_IS_ACTIVE_HELPER(nbr
))
10376 vty_out(vty
, " Neighbour %d :\n", cnt
);
10377 vty_out(vty
, " Address : %pI4\n",
10378 &nbr
->address
.u
.prefix4
);
10379 vty_out(vty
, " Routerid : %pI4\n",
10382 " Received Grace period : %d(in seconds).\n",
10383 nbr
->gr_helper_info
10384 .recvd_grace_period
);
10386 " Actual Grace period : %d(in seconds)\n",
10387 nbr
->gr_helper_info
10388 .actual_grace_period
);
10390 " Remaining GraceTime:%ld(in seconds).\n",
10391 thread_timer_remain_second(
10392 nbr
->gr_helper_info
10395 " Graceful Restart reason: %s.\n\n",
10396 ospf_restart_reason2str(
10397 nbr
->gr_helper_info
10398 .gr_restart_reason
));
10401 json_neigh
= json_object_new_object();
10402 json_object_string_add(
10403 json_neigh
, "srcAddr",
10404 inet_ntop(AF_INET
, &nbr
->src
,
10405 buf
, sizeof(buf
)));
10407 json_object_string_add(
10408 json_neigh
, "routerid",
10411 buf
, sizeof(buf
)));
10412 json_object_int_add(
10414 "recvdGraceInterval",
10415 nbr
->gr_helper_info
10416 .recvd_grace_period
);
10417 json_object_int_add(
10419 "actualGraceInterval",
10420 nbr
->gr_helper_info
10421 .actual_grace_period
);
10422 json_object_int_add(
10423 json_neigh
, "remainGracetime",
10424 thread_timer_remain_second(
10425 nbr
->gr_helper_info
10427 json_object_string_add(
10428 json_neigh
, "restartReason",
10429 ospf_restart_reason2str(
10430 nbr
->gr_helper_info
10431 .gr_restart_reason
));
10432 json_object_object_add(
10434 inet_ntop(AF_INET
, &nbr
->src
,
10441 return CMD_SUCCESS
;
10444 DEFUN (ospf_external_route_aggregation_no_adrvertise
,
10445 ospf_external_route_aggregation_no_adrvertise_cmd
,
10446 "summary-address A.B.C.D/M no-advertise",
10447 "External summary address\n"
10448 "Summary address prefix\n"
10449 "Don't advertise summary route \n")
10451 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10452 struct prefix_ipv4 p
;
10454 int ret
= OSPF_SUCCESS
;
10456 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
10458 if (is_default_prefix4(&p
)) {
10460 "Default address shouldn't be configured as summary address.\n");
10461 return CMD_SUCCESS
;
10464 /* Apply mask for given prefix. */
10467 if (!is_valid_summary_addr(&p
)) {
10468 vty_out(vty
, "Not a valid summary address.\n");
10469 return CMD_WARNING_CONFIG_FAILED
;
10472 ret
= ospf_asbr_external_rt_no_advertise(ospf
, &p
);
10473 if (ret
== OSPF_INVALID
)
10474 vty_out(vty
, "Invalid configuration!!\n");
10476 return CMD_SUCCESS
;
10479 DEFUN (no_ospf_external_route_aggregation_no_adrvertise
,
10480 no_ospf_external_route_aggregation_no_adrvertise_cmd
,
10481 "no summary-address A.B.C.D/M no-advertise",
10483 "External summary address\n"
10484 "Summary address prefix\n"
10485 "Advertise summary route to the AS \n")
10487 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10488 struct prefix_ipv4 p
;
10490 int ret
= OSPF_SUCCESS
;
10492 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
10494 if (is_default_prefix4(&p
)) {
10496 "Default address shouldn't be configured as summary address.\n");
10497 return CMD_SUCCESS
;
10500 /* Apply mask for given prefix. */
10503 if (!is_valid_summary_addr(&p
)) {
10504 vty_out(vty
, "Not a valid summary address.\n");
10505 return CMD_WARNING_CONFIG_FAILED
;
10508 ret
= ospf_asbr_external_rt_advertise(ospf
, &p
);
10509 if (ret
== OSPF_INVALID
)
10510 vty_out(vty
, "Invalid configuration!!\n");
10512 return CMD_SUCCESS
;
10515 DEFUN (ospf_route_aggregation_timer
,
10516 ospf_route_aggregation_timer_cmd
,
10517 "aggregation timer (5-1800)",
10518 "External route aggregation\n"
10519 "Delay timer (in seconds)\n"
10520 "Timer interval(in seconds)\n")
10522 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10523 uint16_t interval
= 0;
10525 interval
= strtoul(argv
[2]->arg
, NULL
, 10);
10527 ospf_external_aggregator_timer_set(ospf
, interval
);
10529 return CMD_SUCCESS
;
10532 DEFPY (show_ip_ospf_gr_helper
,
10533 show_ip_ospf_gr_helper_cmd
,
10534 "show ip ospf [vrf <NAME|all>] graceful-restart helper [detail] [json]",
10537 "OSPF information\n"
10540 "OSPF Graceful Restart\n"
10541 "Helper details in the router\n"
10542 "Detailed information\n"
10545 char *vrf_name
= NULL
;
10546 bool all_vrf
= false;
10547 int ret
= CMD_SUCCESS
;
10550 uint8_t use_vrf
= 0;
10551 bool uj
= use_json(argc
, argv
);
10552 struct ospf
*ospf
= NULL
;
10553 json_object
*json
= NULL
;
10554 struct listnode
*node
= NULL
;
10556 bool detail
= false;
10558 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
10560 if (argv_find(argv
, argc
, "detail", &idx
))
10564 json
= json_object_new_object();
10566 /* vrf input is provided */
10571 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
10572 if (!ospf
->oi_running
)
10575 ret
= ospf_show_gr_helper_details(
10576 vty
, ospf
, use_vrf
, json
, uj
, detail
);
10580 vty_json(vty
, json
);
10585 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
10587 if (ospf
== NULL
|| !ospf
->oi_running
) {
10590 vty_json(vty
, json
);
10593 "%% OSPF is not enabled in vrf %s\n",
10596 return CMD_SUCCESS
;
10601 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
10603 if (ospf
== NULL
|| !ospf
->oi_running
) {
10606 vty_json(vty
, json
);
10609 "%% OSPF is not enabled in vrf default\n");
10611 return CMD_SUCCESS
;
10614 ospf_show_gr_helper_details(vty
, ospf
, use_vrf
, json
, uj
,
10619 vty_json(vty
, json
);
10621 return CMD_SUCCESS
;
10623 /* Graceful Restart HELPER commands end */
10624 DEFUN (no_ospf_route_aggregation_timer
,
10625 no_ospf_route_aggregation_timer_cmd
,
10626 "no aggregation timer",
10628 "External route aggregation\n"
10631 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10633 ospf_external_aggregator_timer_set(ospf
, OSPF_EXTL_AGGR_DEFAULT_DELAY
);
10635 return CMD_SUCCESS
;
10638 /* External Route Aggregation End */
10640 static void config_write_stub_router(struct vty
*vty
, struct ospf
*ospf
)
10642 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
10643 vty_out(vty
, " max-metric router-lsa on-startup %u\n",
10644 ospf
->stub_router_startup_time
);
10645 if (ospf
->stub_router_shutdown_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
10646 vty_out(vty
, " max-metric router-lsa on-shutdown %u\n",
10647 ospf
->stub_router_shutdown_time
);
10648 if (ospf
->stub_router_admin_set
== OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
)
10649 vty_out(vty
, " max-metric router-lsa administrative\n");
10654 static void show_ip_ospf_route_network(struct vty
*vty
, struct ospf
*ospf
,
10655 struct route_table
*rt
,
10658 struct route_node
*rn
;
10659 struct ospf_route
* or ;
10660 struct listnode
*pnode
, *pnnode
;
10661 struct ospf_path
*path
;
10662 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
10663 *json_nexthop
= NULL
;
10667 "============ OSPF network routing table ============\n");
10669 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
10670 char buf1
[PREFIX2STR_BUFFER
];
10672 if ((or = rn
->info
) == NULL
)
10675 prefix2str(&rn
->p
, buf1
, sizeof(buf1
));
10678 json_route
= json_object_new_object();
10679 json_object_object_add(json
, buf1
, json_route
);
10682 switch (or->path_type
) {
10683 case OSPF_PATH_INTER_AREA
:
10684 if (or->type
== OSPF_DESTINATION_NETWORK
) {
10686 json_object_string_add(json_route
,
10689 json_object_int_add(json_route
, "cost",
10691 json_object_string_addf(
10692 json_route
, "area", "%pI4",
10693 &or->u
.std
.area_id
);
10696 "N IA %-18s [%d] area: %pI4\n",
10698 &or->u
.std
.area_id
);
10700 } else if (or->type
== OSPF_DESTINATION_DISCARD
) {
10702 json_object_string_add(json_route
,
10707 "D IA %-18s Discard entry\n",
10712 case OSPF_PATH_INTRA_AREA
:
10714 json_object_string_add(json_route
, "routeType",
10716 json_object_int_add(json_route
, "cost",
10718 json_object_string_addf(json_route
, "area",
10720 &or->u
.std
.area_id
);
10722 vty_out(vty
, "N %-18s [%d] area: %pI4\n",
10724 &or->u
.std
.area_id
);
10731 if (or->type
== OSPF_DESTINATION_NETWORK
) {
10733 json_nexthop_array
= json_object_new_array();
10734 json_object_object_add(json_route
, "nexthops",
10735 json_nexthop_array
);
10738 for (ALL_LIST_ELEMENTS(or->paths
, pnode
, pnnode
,
10741 json_nexthop
= json_object_new_object();
10742 json_object_array_add(
10743 json_nexthop_array
,
10746 if (if_lookup_by_index(path
->ifindex
,
10749 if (path
->nexthop
.s_addr
10752 json_object_string_add(
10755 json_object_string_add(
10757 "directlyAttachedTo",
10763 "%24s directly attached to %s\n",
10771 json_object_string_addf(
10775 json_object_string_add(
10783 "%24s via %pI4, %s\n",
10796 vty_out(vty
, "\n");
10799 static void show_ip_ospf_route_router(struct vty
*vty
, struct ospf
*ospf
,
10800 struct route_table
*rtrs
,
10803 struct route_node
*rn
;
10804 struct ospf_route
* or ;
10805 struct listnode
*pnode
;
10806 struct listnode
*node
;
10807 struct ospf_path
*path
;
10808 char buf
[PREFIX_STRLEN
];
10809 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
10810 *json_nexthop
= NULL
;
10813 vty_out(vty
, "============ OSPF %s table =============\n",
10814 ospf
->all_rtrs
== rtrs
? "reachable routers"
10815 : "router routing");
10817 for (rn
= route_top(rtrs
); rn
; rn
= route_next(rn
)) {
10818 if (rn
->info
== NULL
)
10823 json_route
= json_object_new_object();
10824 json_object_object_add(
10825 json
, inet_ntop(AF_INET
, &rn
->p
.u
.prefix4
,
10828 json_object_string_add(json_route
, "routeType", "R ");
10830 vty_out(vty
, "R %-15pI4 ",
10834 for (ALL_LIST_ELEMENTS_RO((struct list
*)rn
->info
, node
, or)) {
10837 vty_out(vty
, "%24s", "");
10842 json_object_int_add(json_route
, "cost",
10844 json_object_string_addf(json_route
, "area",
10846 &or->u
.std
.area_id
);
10847 if (or->path_type
== OSPF_PATH_INTER_AREA
) {
10848 json_object_boolean_true_add(json_route
,
10850 json_object_boolean_true_add(json_route
,
10853 if (or->u
.std
.flags
& ROUTER_LSA_BORDER
)
10854 json_object_string_add(json_route
,
10857 else if (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
)
10858 json_object_string_add(json_route
,
10862 vty_out(vty
, "%s [%d] area: %pI4",
10863 (or->path_type
== OSPF_PATH_INTER_AREA
10866 or->cost
, &or->u
.std
.area_id
);
10868 vty_out(vty
, "%s%s\n",
10869 (or->u
.std
.flags
& ROUTER_LSA_BORDER
10872 (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
10878 json_nexthop_array
= json_object_new_array();
10879 json_object_object_add(json_route
, "nexthops",
10880 json_nexthop_array
);
10883 for (ALL_LIST_ELEMENTS_RO(or->paths
, pnode
, path
)) {
10885 json_nexthop
= json_object_new_object();
10886 json_object_array_add(
10887 json_nexthop_array
,
10890 if (if_lookup_by_index(path
->ifindex
,
10892 if (path
->nexthop
.s_addr
10895 json_object_string_add(
10898 json_object_string_add(
10900 "directlyAttachedTo",
10906 "%24s directly attached to %s\n",
10914 json_object_string_addf(
10918 json_object_string_add(
10926 "%24s via %pI4, %s\n",
10939 vty_out(vty
, "\n");
10942 static void show_ip_ospf_route_external(struct vty
*vty
, struct ospf
*ospf
,
10943 struct route_table
*rt
,
10946 struct route_node
*rn
;
10947 struct ospf_route
*er
;
10948 struct listnode
*pnode
, *pnnode
;
10949 struct ospf_path
*path
;
10950 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
10951 *json_nexthop
= NULL
;
10955 "============ OSPF external routing table ===========\n");
10957 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
10958 if ((er
= rn
->info
) == NULL
)
10963 snprintfrr(buf1
, sizeof(buf1
), "%pFX", &rn
->p
);
10965 json_route
= json_object_new_object();
10966 json_object_object_add(json
, buf1
, json_route
);
10969 switch (er
->path_type
) {
10970 case OSPF_PATH_TYPE1_EXTERNAL
:
10972 json_object_string_add(json_route
, "routeType",
10974 json_object_int_add(json_route
, "cost",
10976 json_object_int_add(json_route
, "tag",
10980 "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI
10982 buf1
, er
->cost
, er
->u
.ext
.tag
);
10985 case OSPF_PATH_TYPE2_EXTERNAL
:
10987 json_object_string_add(json_route
, "routeType",
10989 json_object_int_add(json_route
, "cost",
10991 json_object_int_add(json_route
, "type2cost",
10992 er
->u
.ext
.type2_cost
);
10993 json_object_int_add(json_route
, "tag",
10997 "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI
10999 buf1
, er
->cost
, er
->u
.ext
.type2_cost
,
11006 json_nexthop_array
= json_object_new_array();
11007 json_object_object_add(json_route
, "nexthops",
11008 json_nexthop_array
);
11011 for (ALL_LIST_ELEMENTS(er
->paths
, pnode
, pnnode
, path
)) {
11013 json_nexthop
= json_object_new_object();
11014 json_object_array_add(json_nexthop_array
,
11018 if (if_lookup_by_index(path
->ifindex
, ospf
->vrf_id
)) {
11019 if (path
->nexthop
.s_addr
== INADDR_ANY
) {
11021 json_object_string_add(
11022 json_nexthop
, "ip",
11024 json_object_string_add(
11026 "directlyAttachedTo",
11032 "%24s directly attached to %s\n",
11040 json_object_string_addf(
11041 json_nexthop
, "ip",
11042 "%pI4", &path
->nexthop
);
11043 json_object_string_add(
11044 json_nexthop
, "via",
11050 "%24s via %pI4, %s\n",
11062 vty_out(vty
, "\n");
11065 static int show_ip_ospf_reachable_routers_common(struct vty
*vty
,
11069 if (ospf
->instance
)
11070 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
11072 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
11074 if (ospf
->all_rtrs
== NULL
) {
11075 vty_out(vty
, "No OSPF reachable router information exist\n");
11076 return CMD_SUCCESS
;
11079 /* Show Router routes. */
11080 show_ip_ospf_route_router(vty
, ospf
, ospf
->all_rtrs
, NULL
);
11082 vty_out(vty
, "\n");
11084 return CMD_SUCCESS
;
11087 DEFUN (show_ip_ospf_reachable_routers
,
11088 show_ip_ospf_reachable_routers_cmd
,
11089 "show ip ospf [vrf <NAME|all>] reachable-routers",
11092 "OSPF information\n"
11095 "Show all the reachable OSPF routers\n")
11097 struct ospf
*ospf
= NULL
;
11098 struct listnode
*node
= NULL
;
11099 char *vrf_name
= NULL
;
11100 bool all_vrf
= false;
11101 int ret
= CMD_SUCCESS
;
11104 uint8_t use_vrf
= 0;
11106 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11109 bool ospf_output
= false;
11114 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11115 if (!ospf
->oi_running
)
11118 ospf_output
= true;
11119 ret
= show_ip_ospf_reachable_routers_common(
11120 vty
, ospf
, use_vrf
);
11124 vty_out(vty
, "%% OSPF instance not found\n");
11126 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11127 if (ospf
== NULL
|| !ospf
->oi_running
) {
11128 vty_out(vty
, "%% OSPF instance not found\n");
11129 return CMD_SUCCESS
;
11132 ret
= show_ip_ospf_reachable_routers_common(vty
, ospf
,
11136 /* Display default ospf (instance 0) info */
11137 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11138 if (ospf
== NULL
|| !ospf
->oi_running
) {
11139 vty_out(vty
, "%% OSPF instance not found\n");
11140 return CMD_SUCCESS
;
11143 ret
= show_ip_ospf_reachable_routers_common(vty
, ospf
, use_vrf
);
11149 DEFUN (show_ip_ospf_instance_reachable_routers
,
11150 show_ip_ospf_instance_reachable_routers_cmd
,
11151 "show ip ospf (1-65535) reachable-routers",
11154 "OSPF information\n"
11156 "Show all the reachable OSPF routers\n")
11158 int idx_number
= 3;
11160 unsigned short instance
= 0;
11162 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
11163 if (instance
!= ospf_instance
)
11164 return CMD_NOT_MY_INSTANCE
;
11166 ospf
= ospf_lookup_instance(instance
);
11167 if (!ospf
|| !ospf
->oi_running
)
11168 return CMD_SUCCESS
;
11170 return show_ip_ospf_reachable_routers_common(vty
, ospf
, 0);
11173 static int show_ip_ospf_border_routers_common(struct vty
*vty
,
11178 json_object
*json_vrf
= NULL
;
11179 json_object
*json_router
= NULL
;
11183 json_vrf
= json_object_new_object();
11186 json_router
= json_object_new_object();
11189 if (ospf
->instance
) {
11191 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
11193 json_object_int_add(json_vrf
, "ospfInstance",
11197 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
11199 if (ospf
->new_table
== NULL
) {
11201 vty_out(vty
, "No OSPF routing information exist\n");
11203 json_object_free(json_router
);
11205 json_object_free(json_vrf
);
11207 return CMD_SUCCESS
;
11210 /* Show Network routes.
11211 show_ip_ospf_route_network (vty, ospf->new_table); */
11213 /* Show Router routes. */
11214 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, json_router
);
11217 json_object_object_add(json_vrf
, "routers", json_router
);
11219 if (ospf
->vrf_id
== VRF_DEFAULT
)
11220 json_object_object_add(json
, "default",
11223 json_object_object_add(json
, ospf
->name
,
11227 vty_out(vty
, "\n");
11230 return CMD_SUCCESS
;
11233 DEFPY (show_ip_ospf_border_routers
,
11234 show_ip_ospf_border_routers_cmd
,
11235 "show ip ospf [vrf <NAME|all>] border-routers [json]",
11238 "OSPF information\n"
11241 "Show all the ABR's and ASBR's\n"
11244 struct ospf
*ospf
= NULL
;
11245 struct listnode
*node
= NULL
;
11246 char *vrf_name
= NULL
;
11247 bool all_vrf
= false;
11248 int ret
= CMD_SUCCESS
;
11251 uint8_t use_vrf
= 0;
11252 bool uj
= use_json(argc
, argv
);
11253 json_object
*json
= NULL
;
11256 json
= json_object_new_object();
11258 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11261 bool ospf_output
= false;
11266 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11267 if (!ospf
->oi_running
)
11270 ospf_output
= true;
11271 ret
= show_ip_ospf_border_routers_common(
11272 vty
, ospf
, use_vrf
, json
);
11276 vty_json(vty
, json
);
11277 else if (!ospf_output
)
11278 vty_out(vty
, "%% OSPF is not enabled\n");
11282 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11283 if (ospf
== NULL
|| !ospf
->oi_running
) {
11285 vty_json(vty
, json
);
11288 "%% OSPF is not enabled in vrf %s\n",
11291 return CMD_SUCCESS
;
11295 /* Display default ospf (instance 0) info */
11296 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11297 if (ospf
== NULL
|| !ospf
->oi_running
) {
11299 vty_json(vty
, json
);
11302 "%% OSPF is not enabled in vrf default\n");
11304 return CMD_SUCCESS
;
11309 ret
= show_ip_ospf_border_routers_common(vty
, ospf
, use_vrf
,
11312 vty_json(vty
, json
);
11318 DEFUN (show_ip_ospf_instance_border_routers
,
11319 show_ip_ospf_instance_border_routers_cmd
,
11320 "show ip ospf (1-65535) border-routers",
11323 "OSPF information\n"
11325 "Show all the ABR's and ASBR's\n")
11327 int idx_number
= 3;
11329 unsigned short instance
= 0;
11331 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
11332 if (instance
!= ospf_instance
)
11333 return CMD_NOT_MY_INSTANCE
;
11335 ospf
= ospf_lookup_instance(instance
);
11336 if (!ospf
|| !ospf
->oi_running
)
11337 return CMD_SUCCESS
;
11339 return show_ip_ospf_border_routers_common(vty
, ospf
, 0, NULL
);
11342 static int show_ip_ospf_route_common(struct vty
*vty
, struct ospf
*ospf
,
11343 json_object
*json
, uint8_t use_vrf
)
11345 json_object
*json_vrf
= NULL
;
11347 if (ospf
->instance
)
11348 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
11353 json_vrf
= json_object_new_object();
11358 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
11360 if (ospf
->new_table
== NULL
) {
11363 json_object_free(json_vrf
);
11365 vty_out(vty
, "No OSPF routing information exist\n");
11367 return CMD_SUCCESS
;
11370 /* Show Network routes. */
11371 show_ip_ospf_route_network(vty
, ospf
, ospf
->new_table
, json_vrf
);
11373 /* Show Router routes. */
11374 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, json_vrf
);
11376 /* Show Router routes. */
11377 if (ospf
->all_rtrs
)
11378 show_ip_ospf_route_router(vty
, ospf
, ospf
->all_rtrs
, json_vrf
);
11380 /* Show AS External routes. */
11381 show_ip_ospf_route_external(vty
, ospf
, ospf
->old_external_route
,
11386 // json_object_object_add(json_vrf, "areas",
11388 json_object_object_add(json
, ospf_get_name(ospf
),
11392 vty_out(vty
, "\n");
11395 return CMD_SUCCESS
;
11398 DEFUN (show_ip_ospf_route
,
11399 show_ip_ospf_route_cmd
,
11400 "show ip ospf [vrf <NAME|all>] route [json]",
11403 "OSPF information\n"
11406 "OSPF routing table\n"
11409 struct ospf
*ospf
= NULL
;
11410 struct listnode
*node
= NULL
;
11411 char *vrf_name
= NULL
;
11412 bool all_vrf
= false;
11413 int ret
= CMD_SUCCESS
;
11416 uint8_t use_vrf
= 0;
11417 bool uj
= use_json(argc
, argv
);
11418 json_object
*json
= NULL
;
11421 json
= json_object_new_object();
11423 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11425 /* vrf input is provided could be all or specific vrf*/
11427 bool ospf_output
= false;
11432 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11433 if (!ospf
->oi_running
)
11435 ospf_output
= true;
11436 ret
= show_ip_ospf_route_common(vty
, ospf
, json
,
11441 /* Keep Non-pretty format */
11442 vty_json(vty
, json
);
11443 } else if (!ospf_output
)
11444 vty_out(vty
, "%% OSPF is not enabled\n");
11448 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11449 if (ospf
== NULL
|| !ospf
->oi_running
) {
11451 vty_json(vty
, json
);
11454 "%% OSPF is not enabled in vrf %s\n",
11457 return CMD_SUCCESS
;
11460 /* Display default ospf (instance 0) info */
11461 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11462 if (ospf
== NULL
|| !ospf
->oi_running
) {
11464 vty_json(vty
, json
);
11467 "%% OSPF is not enabled in vrf default\n");
11469 return CMD_SUCCESS
;
11474 ret
= show_ip_ospf_route_common(vty
, ospf
, json
, use_vrf
);
11475 /* Keep Non-pretty format */
11477 vty_out(vty
, "%s\n",
11478 json_object_to_json_string_ext(
11479 json
, JSON_C_TO_STRING_NOSLASHESCAPE
));
11483 json_object_free(json
);
11488 DEFUN (show_ip_ospf_instance_route
,
11489 show_ip_ospf_instance_route_cmd
,
11490 "show ip ospf (1-65535) route",
11493 "OSPF information\n"
11495 "OSPF routing table\n")
11497 int idx_number
= 3;
11499 unsigned short instance
= 0;
11501 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
11502 if (instance
!= ospf_instance
)
11503 return CMD_NOT_MY_INSTANCE
;
11505 ospf
= ospf_lookup_instance(instance
);
11506 if (!ospf
|| !ospf
->oi_running
)
11507 return CMD_SUCCESS
;
11509 return show_ip_ospf_route_common(vty
, ospf
, NULL
, 0);
11513 DEFUN (show_ip_ospf_vrfs
,
11514 show_ip_ospf_vrfs_cmd
,
11515 "show ip ospf vrfs [json]",
11518 "OSPF information\n"
11519 "Show OSPF VRFs \n"
11522 bool uj
= use_json(argc
, argv
);
11523 json_object
*json
= NULL
;
11524 json_object
*json_vrfs
= NULL
;
11525 struct ospf
*ospf
= NULL
;
11526 struct listnode
*node
= NULL
;
11528 static const char header
[] = "Name Id RouterId ";
11531 json
= json_object_new_object();
11532 json_vrfs
= json_object_new_object();
11535 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11536 json_object
*json_vrf
= NULL
;
11537 const char *name
= NULL
;
11538 int64_t vrf_id_ui
= 0;
11542 if (!uj
&& count
== 1)
11543 vty_out(vty
, "%s\n", header
);
11545 json_vrf
= json_object_new_object();
11547 name
= ospf_get_name(ospf
);
11549 vrf_id_ui
= (ospf
->vrf_id
== VRF_UNKNOWN
)
11551 : (int64_t)ospf
->vrf_id
;
11554 json_object_int_add(json_vrf
, "vrfId", vrf_id_ui
);
11555 json_object_string_addf(json_vrf
, "routerId", "%pI4",
11558 json_object_object_add(json_vrfs
, name
, json_vrf
);
11561 vty_out(vty
, "%-25s %-5d %-16pI4 \n", name
,
11562 ospf
->vrf_id
, &ospf
->router_id
);
11567 json_object_object_add(json
, "vrfs", json_vrfs
);
11568 json_object_int_add(json
, "totalVrfs", count
);
11570 vty_json(vty
, json
);
11573 vty_out(vty
, "\nTotal number of OSPF VRFs: %d\n",
11577 return CMD_SUCCESS
;
11579 DEFPY (clear_ip_ospf_neighbor
,
11580 clear_ip_ospf_neighbor_cmd
,
11581 "clear ip ospf [(1-65535)]$instance neighbor [A.B.C.D$nbr_id]",
11584 "OSPF information\n"
11586 "Reset OSPF Neighbor\n"
11589 struct listnode
*node
;
11590 struct ospf
*ospf
= NULL
;
11592 /* If user does not specify the arguments,
11593 * instance = 0 and nbr_id = 0.0.0.0
11595 if (instance
!= 0) {
11596 /* This means clear only the particular ospf process */
11597 if (instance
!= ospf_instance
)
11598 return CMD_NOT_MY_INSTANCE
;
11601 /* Clear all the ospf processes */
11602 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11603 if (!ospf
->oi_running
)
11606 if (nbr_id_str
&& IPV4_ADDR_SAME(&ospf
->router_id
, &nbr_id
)) {
11607 vty_out(vty
, "Self router-id is not allowed.\r\n ");
11608 return CMD_SUCCESS
;
11611 ospf_neighbor_reset(ospf
, nbr_id
, nbr_id_str
);
11614 return CMD_SUCCESS
;
11617 DEFPY (clear_ip_ospf_process
,
11618 clear_ip_ospf_process_cmd
,
11619 "clear ip ospf [(1-65535)]$instance process",
11622 "OSPF information\n"
11624 "Reset OSPF Process\n")
11626 struct listnode
*node
;
11627 struct ospf
*ospf
= NULL
;
11629 /* Check if instance is not passed as an argument */
11630 if (instance
!= 0) {
11631 /* This means clear only the particular ospf process */
11632 if (instance
!= ospf_instance
)
11633 return CMD_NOT_MY_INSTANCE
;
11636 /* Clear all the ospf processes */
11637 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11638 if (!ospf
->oi_running
)
11641 ospf_process_reset(ospf
);
11644 return CMD_SUCCESS
;
11647 static const char *const ospf_abr_type_str
[] = {
11648 "unknown", "standard", "ibm", "cisco", "shortcut"
11651 static const char *const ospf_shortcut_mode_str
[] = {
11652 "default", "enable", "disable"
11654 static int ospf_vty_external_rt_walkcb(struct hash_bucket
*bucket
,
11657 struct external_info
*ei
= bucket
->data
;
11658 struct vty
*vty
= (struct vty
*)arg
;
11659 static unsigned int count
;
11661 vty_out(vty
, "%-4pI4/%d, ", &ei
->p
.prefix
, ei
->p
.prefixlen
);
11664 if (count
% 5 == 0)
11665 vty_out(vty
, "\n");
11667 if (OSPF_EXTERNAL_RT_COUNT(ei
->aggr_route
) == count
)
11670 return HASHWALK_CONTINUE
;
11673 static int ospf_json_external_rt_walkcb(struct hash_bucket
*bucket
,
11676 struct external_info
*ei
= bucket
->data
;
11677 struct json_object
*json
= (struct json_object
*)arg
;
11678 char buf
[PREFIX2STR_BUFFER
];
11680 static unsigned int count
;
11682 prefix2str(&ei
->p
, buf
, sizeof(buf
));
11684 snprintf(exnalbuf
, 20, "Exnl Addr-%d", count
);
11686 json_object_string_add(json
, exnalbuf
, buf
);
11690 if (OSPF_EXTERNAL_RT_COUNT(ei
->aggr_route
) == count
)
11693 return HASHWALK_CONTINUE
;
11696 static int ospf_show_summary_address(struct vty
*vty
, struct ospf
*ospf
,
11697 uint8_t use_vrf
, json_object
*json
,
11698 bool uj
, bool detail
)
11700 struct route_node
*rn
;
11701 json_object
*json_vrf
= NULL
;
11704 static char header
[] =
11705 "Summary-address Metric-type Metric Tag External_Rt_count\n";
11707 mtype
= metric_type(ospf
, 0, ospf
->instance
);
11708 mval
= metric_value(ospf
, 0, ospf
->instance
);
11711 vty_out(vty
, "%s\n", header
);
11715 json_vrf
= json_object_new_object();
11720 if (ospf
->instance
) {
11722 json_object_int_add(json
, "ospfInstance",
11725 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
11728 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
11731 vty_out(vty
, "aggregation delay interval :%u(in seconds)\n\n",
11732 ospf
->aggr_delay_interval
);
11734 json_object_int_add(json_vrf
, "aggregationDelayInterval",
11735 ospf
->aggr_delay_interval
);
11738 for (rn
= route_top(ospf
->rt_aggr_tbl
); rn
; rn
= route_next(rn
))
11740 struct ospf_external_aggr_rt
*aggr
= rn
->info
;
11741 json_object
*json_aggr
= NULL
;
11742 char buf
[PREFIX2STR_BUFFER
];
11744 prefix2str(&aggr
->p
, buf
, sizeof(buf
));
11748 json_aggr
= json_object_new_object();
11750 json_object_object_add(json_vrf
, buf
,
11752 json_object_string_add(json_aggr
,
11753 "summaryAddress", buf
);
11754 json_object_string_add(
11755 json_aggr
, "metricType",
11756 (mtype
== EXTERNAL_METRIC_TYPE_1
)
11760 json_object_int_add(json_aggr
, "metric", mval
);
11761 json_object_int_add(json_aggr
, "tag",
11763 json_object_int_add(
11764 json_aggr
, "externalRouteCount",
11765 OSPF_EXTERNAL_RT_COUNT(aggr
));
11767 if (OSPF_EXTERNAL_RT_COUNT(aggr
) && detail
) {
11769 aggr
->match_extnl_hash
,
11770 ospf_json_external_rt_walkcb
,
11775 vty_out(vty
, "%-20s", buf
);
11777 (mtype
== EXTERNAL_METRIC_TYPE_1
)
11778 ? vty_out(vty
, "%-16s", "E1")
11779 : vty_out(vty
, "%-16s", "E2");
11780 vty_out(vty
, "%-11d", mval
);
11782 vty_out(vty
, "%-12u", aggr
->tag
);
11784 vty_out(vty
, "%-5ld\n",
11785 OSPF_EXTERNAL_RT_COUNT(aggr
));
11787 if (OSPF_EXTERNAL_RT_COUNT(aggr
) && detail
) {
11789 "Matched External routes:\n");
11791 aggr
->match_extnl_hash
,
11792 ospf_vty_external_rt_walkcb
,
11794 vty_out(vty
, "\n");
11797 vty_out(vty
, "\n");
11803 json_object_object_add(json
, ospf_get_name(ospf
),
11806 vty_out(vty
, "\n");
11808 return CMD_SUCCESS
;
11811 DEFUN (show_ip_ospf_external_aggregator
,
11812 show_ip_ospf_external_aggregator_cmd
,
11813 "show ip ospf [vrf <NAME|all>] summary-address [detail] [json]",
11815 "OSPF information\n"
11818 "Show external summary addresses\n"
11819 "Detailed information\n"
11822 char *vrf_name
= NULL
;
11823 bool all_vrf
= false;
11824 int ret
= CMD_SUCCESS
;
11827 uint8_t use_vrf
= 0;
11828 bool uj
= use_json(argc
, argv
);
11829 struct ospf
*ospf
= NULL
;
11830 json_object
*json
= NULL
;
11831 struct listnode
*node
= NULL
;
11833 bool detail
= false;
11835 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11837 if (argv_find(argv
, argc
, "detail", &idx
))
11841 json
= json_object_new_object();
11843 /* vrf input is provided */
11847 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11848 if (!ospf
->oi_running
)
11850 ret
= ospf_show_summary_address(
11851 vty
, ospf
, use_vrf
, json
, uj
, detail
);
11855 vty_json(vty
, json
);
11860 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11862 if (ospf
== NULL
|| !ospf
->oi_running
) {
11864 vty_json(vty
, json
);
11867 "%% OSPF is not enabled in vrf %s\n",
11870 return CMD_SUCCESS
;
11872 ospf_show_summary_address(vty
, ospf
, use_vrf
, json
, uj
, detail
);
11876 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11877 if (ospf
== NULL
|| !ospf
->oi_running
) {
11879 vty_json(vty
, json
);
11882 "%% OSPF is not enabled in vrf default\n");
11884 return CMD_SUCCESS
;
11887 ospf_show_summary_address(vty
, ospf
, use_vrf
, json
, uj
, detail
);
11891 vty_json(vty
, json
);
11892 return CMD_SUCCESS
;
11895 static const char *const ospf_int_type_str
[] = {
11896 "unknown", /* should never be used. */
11900 "point-to-multipoint",
11901 "virtual-link", /* should never be used. */
11905 static const char *interface_config_auth_str(struct ospf_if_params
*params
)
11907 if (!OSPF_IF_PARAM_CONFIGURED(params
, auth_type
)
11908 || params
->auth_type
== OSPF_AUTH_NOTSET
)
11911 /* Translation tables are not that much help
11912 * here due to syntax
11913 * of the simple option */
11914 switch (params
->auth_type
) {
11916 case OSPF_AUTH_NULL
:
11919 case OSPF_AUTH_SIMPLE
:
11922 case OSPF_AUTH_CRYPTOGRAPHIC
:
11923 return " message-digest";
11929 static int config_write_interface_one(struct vty
*vty
, struct vrf
*vrf
)
11931 struct listnode
*node
;
11932 struct interface
*ifp
;
11933 struct crypt_key
*ck
;
11934 struct route_node
*rn
= NULL
;
11935 struct ospf_if_params
*params
;
11936 const char *auth_str
;
11939 FOR_ALL_INTERFACES (vrf
, ifp
) {
11941 if (memcmp(ifp
->name
, "VLINK", 5) == 0)
11944 if_vty_config_start(vty
, ifp
);
11947 vty_out(vty
, " description %s\n", ifp
->desc
);
11951 params
= IF_DEF_PARAMS(ifp
);
11954 /* Interface Network print. */
11955 if (OSPF_IF_PARAM_CONFIGURED(params
, type
)
11956 && params
->type
!= OSPF_IFTYPE_LOOPBACK
) {
11957 if (params
->type
!= ospf_default_iftype(ifp
)) {
11958 vty_out(vty
, " ip ospf network %s",
11962 == OSPF_IFTYPE_POINTOPOINT
11963 && params
->ptp_dmvpn
)
11964 vty_out(vty
, " dmvpn");
11965 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11966 vty_out(vty
, " %pI4",
11968 vty_out(vty
, "\n");
11972 /* OSPF interface authentication print */
11973 auth_str
= interface_config_auth_str(params
);
11975 vty_out(vty
, " ip ospf authentication%s",
11977 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11978 vty_out(vty
, " %pI4",
11980 vty_out(vty
, "\n");
11983 /* Simple Authentication Password print. */
11984 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_simple
)
11985 && params
->auth_simple
[0] != '\0') {
11986 vty_out(vty
, " ip ospf authentication-key %s",
11987 params
->auth_simple
);
11988 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11989 vty_out(vty
, " %pI4",
11991 vty_out(vty
, "\n");
11994 /* Cryptographic Authentication Key print. */
11995 if (params
&& params
->auth_crypt
) {
11996 for (ALL_LIST_ELEMENTS_RO(params
->auth_crypt
,
11999 " ip ospf message-digest-key %d md5 %s",
12000 ck
->key_id
, ck
->auth_key
);
12001 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12002 vty_out(vty
, " %pI4",
12004 vty_out(vty
, "\n");
12008 /* Interface Output Cost print. */
12009 if (OSPF_IF_PARAM_CONFIGURED(params
, output_cost_cmd
)) {
12010 vty_out(vty
, " ip ospf cost %u",
12011 params
->output_cost_cmd
);
12012 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12013 vty_out(vty
, " %pI4",
12015 vty_out(vty
, "\n");
12018 /* Hello Interval print. */
12019 if (OSPF_IF_PARAM_CONFIGURED(params
, v_hello
)
12020 && params
->v_hello
!= OSPF_HELLO_INTERVAL_DEFAULT
) {
12021 vty_out(vty
, " ip ospf hello-interval %u",
12023 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12024 vty_out(vty
, " %pI4",
12026 vty_out(vty
, "\n");
12030 /* Router Dead Interval print. */
12031 if (OSPF_IF_PARAM_CONFIGURED(params
, v_wait
)
12032 && params
->is_v_wait_set
) {
12033 vty_out(vty
, " ip ospf dead-interval ");
12036 if (OSPF_IF_PARAM_CONFIGURED(params
,
12039 "minimal hello-multiplier %d",
12040 params
->fast_hello
);
12042 vty_out(vty
, "%u", params
->v_wait
);
12044 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12045 vty_out(vty
, " %pI4",
12047 vty_out(vty
, "\n");
12050 /* Router Priority print. */
12051 if (OSPF_IF_PARAM_CONFIGURED(params
, priority
)
12052 && params
->priority
12053 != OSPF_ROUTER_PRIORITY_DEFAULT
) {
12054 vty_out(vty
, " ip ospf priority %u",
12056 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12057 vty_out(vty
, " %pI4",
12059 vty_out(vty
, "\n");
12062 /* Retransmit Interval print. */
12063 if (OSPF_IF_PARAM_CONFIGURED(params
,
12064 retransmit_interval
)
12065 && params
->retransmit_interval
12066 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
) {
12067 vty_out(vty
, " ip ospf retransmit-interval %u",
12068 params
->retransmit_interval
);
12069 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12070 vty_out(vty
, " %pI4",
12072 vty_out(vty
, "\n");
12075 /* Transmit Delay print. */
12076 if (OSPF_IF_PARAM_CONFIGURED(params
, transmit_delay
)
12077 && params
->transmit_delay
12078 != OSPF_TRANSMIT_DELAY_DEFAULT
) {
12079 vty_out(vty
, " ip ospf transmit-delay %u",
12080 params
->transmit_delay
);
12081 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12082 vty_out(vty
, " %pI4",
12084 vty_out(vty
, "\n");
12088 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
12090 vty_out(vty
, " ip ospf %d",
12093 vty_out(vty
, " ip ospf");
12095 char buf
[INET_ADDRSTRLEN
];
12097 area_id2str(buf
, sizeof(buf
), ¶ms
->if_area
,
12098 params
->if_area_id_fmt
);
12099 vty_out(vty
, " area %s", buf
);
12100 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12101 vty_out(vty
, " %pI4",
12103 vty_out(vty
, "\n");
12107 if (params
&& params
->bfd_config
)
12108 ospf_bfd_write_config(vty
, params
);
12110 /* MTU ignore print. */
12111 if (OSPF_IF_PARAM_CONFIGURED(params
, mtu_ignore
)
12112 && params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
) {
12113 if (params
->mtu_ignore
== 0)
12114 vty_out(vty
, " no ip ospf mtu-ignore");
12116 vty_out(vty
, " ip ospf mtu-ignore");
12117 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12118 vty_out(vty
, " %pI4",
12120 vty_out(vty
, "\n");
12123 if (OSPF_IF_PARAM_CONFIGURED(params
,
12124 passive_interface
)) {
12125 vty_out(vty
, " %sip ospf passive",
12126 params
->passive_interface
12130 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12131 vty_out(vty
, " %pI4", &rn
->p
.u
.prefix4
);
12132 vty_out(vty
, "\n");
12135 /* LDP-Sync print */
12136 if (params
&& params
->ldp_sync_info
)
12137 ospf_ldp_sync_if_write_config(vty
, params
);
12141 rn
= route_top(IF_OIFS_PARAMS(ifp
));
12143 rn
= route_next(rn
);
12148 if (params
!= NULL
)
12153 ospf_opaque_config_write_if(vty
, ifp
);
12155 if_vty_config_end(vty
);
12161 /* Configuration write function for ospfd. */
12162 static int config_write_interface(struct vty
*vty
)
12165 struct vrf
*vrf
= NULL
;
12167 /* Display all VRF aware OSPF interface configuration */
12168 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
12169 write
+= config_write_interface_one(vty
, vrf
);
12175 static int config_write_network_area(struct vty
*vty
, struct ospf
*ospf
)
12177 struct route_node
*rn
;
12178 char buf
[INET_ADDRSTRLEN
];
12180 /* `network area' print. */
12181 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
))
12183 struct ospf_network
*n
= rn
->info
;
12185 /* Create Area ID string by specified Area ID format. */
12186 if (n
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
12187 inet_ntop(AF_INET
, &n
->area_id
, buf
,
12190 snprintf(buf
, sizeof(buf
), "%lu",
12191 (unsigned long int)ntohl(
12192 n
->area_id
.s_addr
));
12194 /* Network print. */
12195 vty_out(vty
, " network %pFX area %s\n", &rn
->p
, buf
);
12201 static int config_write_ospf_area(struct vty
*vty
, struct ospf
*ospf
)
12203 struct listnode
*node
;
12204 struct ospf_area
*area
;
12205 char buf
[INET_ADDRSTRLEN
];
12207 /* Area configuration print. */
12208 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
12209 struct route_node
*rn1
;
12211 area_id2str(buf
, sizeof(buf
), &area
->area_id
,
12212 area
->area_id_fmt
);
12214 if (area
->auth_type
!= OSPF_AUTH_NULL
) {
12215 if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
12216 vty_out(vty
, " area %s authentication\n", buf
);
12219 " area %s authentication message-digest\n",
12223 if (area
->shortcut_configured
!= OSPF_SHORTCUT_DEFAULT
)
12224 vty_out(vty
, " area %s shortcut %s\n", buf
,
12225 ospf_shortcut_mode_str
12226 [area
->shortcut_configured
]);
12228 if ((area
->external_routing
== OSPF_AREA_STUB
)
12229 || (area
->external_routing
== OSPF_AREA_NSSA
)) {
12230 if (area
->external_routing
== OSPF_AREA_STUB
) {
12231 vty_out(vty
, " area %s stub", buf
);
12232 if (area
->no_summary
)
12233 vty_out(vty
, " no-summary\n");
12234 vty_out(vty
, "\n");
12235 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
12236 switch (area
->NSSATranslatorRole
) {
12237 case OSPF_NSSA_ROLE_NEVER
:
12239 " area %s nssa translate-never\n",
12242 case OSPF_NSSA_ROLE_ALWAYS
:
12244 " area %s nssa translate-always\n",
12247 case OSPF_NSSA_ROLE_CANDIDATE
:
12248 vty_out(vty
, " area %s nssa \n", buf
);
12251 if (area
->no_summary
)
12253 " area %s nssa no-summary\n",
12255 if (area
->suppress_fa
)
12257 " area %s nssa suppress-fa\n",
12261 if (area
->default_cost
!= 1)
12262 vty_out(vty
, " area %s default-cost %d\n", buf
,
12263 area
->default_cost
);
12266 for (rn1
= route_top(area
->ranges
); rn1
; rn1
= route_next(rn1
))
12268 struct ospf_area_range
*range
= rn1
->info
;
12270 vty_out(vty
, " area %s range %pFX", buf
,
12273 if (range
->cost_config
12274 != OSPF_AREA_RANGE_COST_UNSPEC
)
12275 vty_out(vty
, " cost %d",
12276 range
->cost_config
);
12278 if (!CHECK_FLAG(range
->flags
,
12279 OSPF_AREA_RANGE_ADVERTISE
))
12280 vty_out(vty
, " not-advertise");
12282 if (CHECK_FLAG(range
->flags
,
12283 OSPF_AREA_RANGE_SUBSTITUTE
))
12284 vty_out(vty
, " substitute %pI4/%d",
12285 &range
->subst_addr
,
12286 range
->subst_masklen
);
12288 vty_out(vty
, "\n");
12291 if (EXPORT_NAME(area
))
12292 vty_out(vty
, " area %s export-list %s\n", buf
,
12293 EXPORT_NAME(area
));
12295 if (IMPORT_NAME(area
))
12296 vty_out(vty
, " area %s import-list %s\n", buf
,
12297 IMPORT_NAME(area
));
12299 if (PREFIX_NAME_IN(area
))
12300 vty_out(vty
, " area %s filter-list prefix %s in\n", buf
,
12301 PREFIX_NAME_IN(area
));
12303 if (PREFIX_NAME_OUT(area
))
12304 vty_out(vty
, " area %s filter-list prefix %s out\n",
12305 buf
, PREFIX_NAME_OUT(area
));
12307 if (area
->fr_info
.configured
)
12308 vty_out(vty
, " area %s flood-reduction\n", buf
);
12314 static int config_write_ospf_nbr_nbma(struct vty
*vty
, struct ospf
*ospf
)
12316 struct ospf_nbr_nbma
*nbr_nbma
;
12317 struct route_node
*rn
;
12319 /* Static Neighbor configuration print. */
12320 for (rn
= route_top(ospf
->nbr_nbma
); rn
; rn
= route_next(rn
))
12321 if ((nbr_nbma
= rn
->info
)) {
12322 vty_out(vty
, " neighbor %pI4", &nbr_nbma
->addr
);
12324 if (nbr_nbma
->priority
12325 != OSPF_NEIGHBOR_PRIORITY_DEFAULT
)
12326 vty_out(vty
, " priority %d",
12327 nbr_nbma
->priority
);
12329 if (nbr_nbma
->v_poll
!= OSPF_POLL_INTERVAL_DEFAULT
)
12330 vty_out(vty
, " poll-interval %d",
12333 vty_out(vty
, "\n");
12339 static int config_write_virtual_link(struct vty
*vty
, struct ospf
*ospf
)
12341 struct listnode
*node
;
12342 struct ospf_vl_data
*vl_data
;
12343 const char *auth_str
;
12344 char buf
[INET_ADDRSTRLEN
];
12346 /* Virtual-Link print */
12347 for (ALL_LIST_ELEMENTS_RO(ospf
->vlinks
, node
, vl_data
)) {
12348 struct listnode
*n2
;
12349 struct crypt_key
*ck
;
12350 struct ospf_interface
*oi
;
12352 if (vl_data
!= NULL
) {
12353 area_id2str(buf
, sizeof(buf
), &vl_data
->vl_area_id
,
12354 vl_data
->vl_area_id_fmt
);
12355 oi
= vl_data
->vl_oi
;
12358 if (OSPF_IF_PARAM(oi
, v_hello
)
12359 != OSPF_HELLO_INTERVAL_DEFAULT
12360 || OSPF_IF_PARAM(oi
, v_wait
)
12361 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
12362 || OSPF_IF_PARAM(oi
, retransmit_interval
)
12363 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
12364 || OSPF_IF_PARAM(oi
, transmit_delay
)
12365 != OSPF_TRANSMIT_DELAY_DEFAULT
)
12367 " area %s virtual-link %pI4 hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n",
12368 buf
, &vl_data
->vl_peer
,
12369 OSPF_IF_PARAM(oi
, v_hello
),
12370 OSPF_IF_PARAM(oi
, retransmit_interval
),
12371 OSPF_IF_PARAM(oi
, transmit_delay
),
12372 OSPF_IF_PARAM(oi
, v_wait
));
12374 vty_out(vty
, " area %s virtual-link %pI4\n", buf
,
12375 &vl_data
->vl_peer
);
12377 auth_str
= interface_config_auth_str(
12378 IF_DEF_PARAMS(oi
->ifp
));
12381 " area %s virtual-link %pI4 authentication%s\n",
12382 buf
, &vl_data
->vl_peer
, auth_str
);
12384 if (IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)->auth_simple
[0]
12387 " area %s virtual-link %pI4 authentication-key %s\n",
12388 buf
, &vl_data
->vl_peer
,
12389 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
12392 for (ALL_LIST_ELEMENTS_RO(
12393 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
12397 " area %s virtual-link %pI4 message-digest-key %d md5 %s\n",
12398 buf
, &vl_data
->vl_peer
,
12399 ck
->key_id
, ck
->auth_key
);
12407 static int config_write_ospf_redistribute(struct vty
*vty
, struct ospf
*ospf
)
12411 /* redistribute print. */
12412 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
12413 struct list
*red_list
;
12414 struct listnode
*node
;
12415 struct ospf_redist
*red
;
12417 red_list
= ospf
->redist
[type
];
12421 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
12422 vty_out(vty
, " redistribute %s",
12423 zebra_route_string(type
));
12425 vty_out(vty
, " %d", red
->instance
);
12427 if (red
->dmetric
.value
>= 0)
12428 vty_out(vty
, " metric %d", red
->dmetric
.value
);
12430 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
12431 vty_out(vty
, " metric-type 1");
12433 if (ROUTEMAP_NAME(red
))
12434 vty_out(vty
, " route-map %s",
12435 ROUTEMAP_NAME(red
));
12437 vty_out(vty
, "\n");
12444 static int ospf_cfg_write_helper_dis_rtr_walkcb(struct hash_bucket
*bucket
,
12447 struct advRtr
*rtr
= bucket
->data
;
12448 struct vty
*vty
= (struct vty
*)arg
;
12450 vty_out(vty
, " graceful-restart helper enable %pI4\n",
12452 return HASHWALK_CONTINUE
;
12455 static void config_write_ospf_gr(struct vty
*vty
, struct ospf
*ospf
)
12457 if (!ospf
->gr_info
.restart_support
)
12460 if (ospf
->gr_info
.grace_period
== OSPF_DFLT_GRACE_INTERVAL
)
12461 vty_out(vty
, " graceful-restart\n");
12463 vty_out(vty
, " graceful-restart grace-period %u\n",
12464 ospf
->gr_info
.grace_period
);
12467 static int config_write_ospf_gr_helper(struct vty
*vty
, struct ospf
*ospf
)
12469 if (ospf
->is_helper_supported
)
12470 vty_out(vty
, " graceful-restart helper enable\n");
12472 if (!ospf
->strict_lsa_check
)
12474 " no graceful-restart helper strict-lsa-checking\n");
12476 if (ospf
->only_planned_restart
)
12477 vty_out(vty
, " graceful-restart helper planned-only\n");
12479 if (ospf
->supported_grace_time
!= OSPF_MAX_GRACE_INTERVAL
)
12481 " graceful-restart helper supported-grace-time %d\n",
12482 ospf
->supported_grace_time
);
12484 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf
)) {
12485 hash_walk(ospf
->enable_rtr_list
,
12486 ospf_cfg_write_helper_dis_rtr_walkcb
, vty
);
12491 static int config_write_ospf_external_aggregator(struct vty
*vty
,
12494 struct route_node
*rn
;
12496 if (ospf
->aggr_delay_interval
!= OSPF_EXTL_AGGR_DEFAULT_DELAY
)
12497 vty_out(vty
, " aggregation timer %u\n",
12498 ospf
->aggr_delay_interval
);
12500 /* print 'summary-address A.B.C.D/M' */
12501 for (rn
= route_top(ospf
->rt_aggr_tbl
); rn
; rn
= route_next(rn
))
12503 struct ospf_external_aggr_rt
*aggr
= rn
->info
;
12505 vty_out(vty
, " summary-address %pI4/%d",
12506 &aggr
->p
.prefix
, aggr
->p
.prefixlen
);
12508 vty_out(vty
, " tag %u", aggr
->tag
);
12510 if (CHECK_FLAG(aggr
->flags
,
12511 OSPF_EXTERNAL_AGGRT_NO_ADVERTISE
))
12512 vty_out(vty
, " no-advertise");
12514 vty_out(vty
, "\n");
12520 static int config_write_ospf_default_metric(struct vty
*vty
, struct ospf
*ospf
)
12522 if (ospf
->default_metric
!= -1)
12523 vty_out(vty
, " default-metric %d\n", ospf
->default_metric
);
12527 static int config_write_ospf_distribute(struct vty
*vty
, struct ospf
*ospf
)
12530 struct ospf_redist
*red
;
12533 /* distribute-list print. */
12534 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
12535 if (DISTRIBUTE_NAME(ospf
, type
))
12536 vty_out(vty
, " distribute-list %s out %s\n",
12537 DISTRIBUTE_NAME(ospf
, type
),
12538 zebra_route_string(type
));
12540 /* default-information print. */
12541 if (ospf
->default_originate
!= DEFAULT_ORIGINATE_NONE
) {
12542 vty_out(vty
, " default-information originate");
12543 if (ospf
->default_originate
== DEFAULT_ORIGINATE_ALWAYS
)
12544 vty_out(vty
, " always");
12546 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
12548 if (red
->dmetric
.value
>= 0)
12549 vty_out(vty
, " metric %d",
12550 red
->dmetric
.value
);
12552 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
12553 vty_out(vty
, " metric-type 1");
12555 if (ROUTEMAP_NAME(red
))
12556 vty_out(vty
, " route-map %s",
12557 ROUTEMAP_NAME(red
));
12560 vty_out(vty
, "\n");
12567 static int config_write_ospf_distance(struct vty
*vty
, struct ospf
*ospf
)
12569 struct route_node
*rn
;
12570 struct ospf_distance
*odistance
;
12572 if (ospf
->distance_all
)
12573 vty_out(vty
, " distance %d\n", ospf
->distance_all
);
12575 if (ospf
->distance_intra
|| ospf
->distance_inter
12576 || ospf
->distance_external
) {
12577 vty_out(vty
, " distance ospf");
12579 if (ospf
->distance_intra
)
12580 vty_out(vty
, " intra-area %d", ospf
->distance_intra
);
12581 if (ospf
->distance_inter
)
12582 vty_out(vty
, " inter-area %d", ospf
->distance_inter
);
12583 if (ospf
->distance_external
)
12584 vty_out(vty
, " external %d", ospf
->distance_external
);
12586 vty_out(vty
, "\n");
12589 for (rn
= route_top(ospf
->distance_table
); rn
; rn
= route_next(rn
))
12590 if ((odistance
= rn
->info
) != NULL
) {
12591 vty_out(vty
, " distance %d %pFX %s\n",
12592 odistance
->distance
, &rn
->p
,
12593 odistance
->access_list
? odistance
->access_list
12599 static int ospf_config_write_one(struct vty
*vty
, struct ospf
*ospf
)
12603 /* `router ospf' print. */
12604 if (ospf
->instance
&& strcmp(ospf
->name
, VRF_DEFAULT_NAME
)) {
12605 vty_out(vty
, "router ospf %d vrf %s\n", ospf
->instance
,
12607 } else if (ospf
->instance
) {
12608 vty_out(vty
, "router ospf %d\n", ospf
->instance
);
12609 } else if (strcmp(ospf
->name
, VRF_DEFAULT_NAME
)) {
12610 vty_out(vty
, "router ospf vrf %s\n", ospf
->name
);
12612 vty_out(vty
, "router ospf\n");
12614 if (!ospf
->networks
) {
12619 /* Router ID print. */
12620 if (ospf
->router_id_static
.s_addr
!= INADDR_ANY
)
12621 vty_out(vty
, " ospf router-id %pI4\n",
12622 &ospf
->router_id_static
);
12624 /* zebra opaque attributes configuration. */
12625 if (CHECK_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
))
12626 vty_out(vty
, " ospf send-extra-data zebra\n");
12628 /* ABR type print. */
12629 if (ospf
->abr_type
!= OSPF_ABR_DEFAULT
)
12630 vty_out(vty
, " ospf abr-type %s\n",
12631 ospf_abr_type_str
[ospf
->abr_type
]);
12633 /* log-adjacency-changes flag print. */
12634 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
12635 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
))
12636 vty_out(vty
, " log-adjacency-changes detail\n");
12637 else if (!SAVE_OSPF_LOG_ADJACENCY_CHANGES
)
12638 vty_out(vty
, " log-adjacency-changes\n");
12639 } else if (SAVE_OSPF_LOG_ADJACENCY_CHANGES
) {
12640 vty_out(vty
, " no log-adjacency-changes\n");
12643 /* RFC1583 compatibility flag print -- Compatible with CISCO
12645 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
))
12646 vty_out(vty
, " compatible rfc1583\n");
12648 /* auto-cost reference-bandwidth configuration. */
12649 if (ospf
->ref_bandwidth
!= OSPF_DEFAULT_REF_BANDWIDTH
) {
12651 "! Important: ensure reference bandwidth is consistent across all routers\n");
12652 vty_out(vty
, " auto-cost reference-bandwidth %d\n",
12653 ospf
->ref_bandwidth
);
12656 /* SPF timers print. */
12657 if (ospf
->spf_delay
!= OSPF_SPF_DELAY_DEFAULT
12658 || ospf
->spf_holdtime
!= OSPF_SPF_HOLDTIME_DEFAULT
12659 || ospf
->spf_max_holdtime
!= OSPF_SPF_MAX_HOLDTIME_DEFAULT
)
12660 vty_out(vty
, " timers throttle spf %d %d %d\n", ospf
->spf_delay
,
12661 ospf
->spf_holdtime
, ospf
->spf_max_holdtime
);
12663 /* LSA timers print. */
12664 if (ospf
->min_ls_interval
!= OSPF_MIN_LS_INTERVAL
)
12665 vty_out(vty
, " timers throttle lsa all %d\n",
12666 ospf
->min_ls_interval
);
12667 if (ospf
->min_ls_arrival
!= OSPF_MIN_LS_ARRIVAL
)
12668 vty_out(vty
, " timers lsa min-arrival %d\n",
12669 ospf
->min_ls_arrival
);
12671 /* Write multiplier print. */
12672 if (ospf
->write_oi_count
!= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
)
12673 vty_out(vty
, " ospf write-multiplier %d\n",
12674 ospf
->write_oi_count
);
12676 if (ospf
->max_multipath
!= MULTIPATH_NUM
)
12677 vty_out(vty
, " maximum-paths %d\n", ospf
->max_multipath
);
12679 /* Max-metric router-lsa print */
12680 config_write_stub_router(vty
, ospf
);
12682 /* SPF refresh parameters print. */
12683 if (ospf
->lsa_refresh_interval
!= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
12684 vty_out(vty
, " refresh timer %d\n", ospf
->lsa_refresh_interval
);
12686 if (ospf
->fr_configured
)
12687 vty_out(vty
, " flood-reduction\n");
12689 /* Redistribute information print. */
12690 config_write_ospf_redistribute(vty
, ospf
);
12692 /* Graceful Restart print */
12693 config_write_ospf_gr(vty
, ospf
);
12694 config_write_ospf_gr_helper(vty
, ospf
);
12696 /* Print external route aggregation. */
12697 config_write_ospf_external_aggregator(vty
, ospf
);
12699 /* passive-interface print. */
12700 if (ospf
->passive_interface_default
== OSPF_IF_PASSIVE
)
12701 vty_out(vty
, " passive-interface default\n");
12703 /* proactive-arp print. */
12704 if (ospf
->proactive_arp
!= OSPF_PROACTIVE_ARP_DEFAULT
) {
12705 if (ospf
->proactive_arp
)
12706 vty_out(vty
, " proactive-arp\n");
12708 vty_out(vty
, " no proactive-arp\n");
12711 /* TI-LFA print. */
12712 if (ospf
->ti_lfa_enabled
) {
12713 if (ospf
->ti_lfa_protection_type
== OSPF_TI_LFA_NODE_PROTECTION
)
12714 vty_out(vty
, " fast-reroute ti-lfa node-protection\n");
12716 vty_out(vty
, " fast-reroute ti-lfa\n");
12719 /* Network area print. */
12720 config_write_network_area(vty
, ospf
);
12722 /* Area config print. */
12723 config_write_ospf_area(vty
, ospf
);
12725 /* static neighbor print. */
12726 config_write_ospf_nbr_nbma(vty
, ospf
);
12728 /* Virtual-Link print. */
12729 config_write_virtual_link(vty
, ospf
);
12731 /* Default metric configuration. */
12732 config_write_ospf_default_metric(vty
, ospf
);
12734 /* Distribute-list and default-information print. */
12735 config_write_ospf_distribute(vty
, ospf
);
12737 /* Distance configuration. */
12738 config_write_ospf_distance(vty
, ospf
);
12740 ospf_opaque_config_write_router(vty
, ospf
);
12742 /* LDP-Sync print */
12743 ospf_ldp_sync_write_config(vty
, ospf
);
12745 vty_out(vty
, "exit\n");
12751 /* OSPF configuration write function. */
12752 static int ospf_config_write(struct vty
*vty
)
12755 struct listnode
*ospf_node
= NULL
;
12758 if (listcount(om
->ospf
) == 0)
12761 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, ospf_node
, ospf
)) {
12762 /* VRF Default check if it is running.
12763 * Upon daemon start, there could be default instance
12764 * in absence of 'router ospf'/oi_running is disabled. */
12765 if (ospf
->vrf_id
== VRF_DEFAULT
&& ospf
->oi_running
)
12766 write
+= ospf_config_write_one(vty
, ospf
);
12767 /* For Non-Default VRF simply display the configuration,
12768 * even if it is not oi_running. */
12769 else if (ospf
->vrf_id
!= VRF_DEFAULT
)
12770 write
+= ospf_config_write_one(vty
, ospf
);
12775 void ospf_vty_show_init(void)
12777 /* "show ip ospf" commands. */
12778 install_element(VIEW_NODE
, &show_ip_ospf_cmd
);
12780 install_element(VIEW_NODE
, &show_ip_ospf_instance_cmd
);
12782 /* "show ip ospf database" commands. */
12783 install_element(VIEW_NODE
, &show_ip_ospf_database_cmd
);
12784 install_element(VIEW_NODE
, &show_ip_ospf_database_max_cmd
);
12785 install_element(VIEW_NODE
,
12786 &show_ip_ospf_database_type_adv_router_cmd
);
12787 install_element(VIEW_NODE
,
12788 &show_ip_ospf_instance_database_type_adv_router_cmd
);
12789 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_cmd
);
12790 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_max_cmd
);
12792 /* "show ip ospf interface" commands. */
12793 install_element(VIEW_NODE
, &show_ip_ospf_interface_cmd
);
12795 install_element(VIEW_NODE
, &show_ip_ospf_instance_interface_cmd
);
12796 /* "show ip ospf interface traffic */
12797 install_element(VIEW_NODE
, &show_ip_ospf_interface_traffic_cmd
);
12799 /* "show ip ospf neighbor" commands. */
12800 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_detail_cmd
);
12801 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_cmd
);
12802 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_id_cmd
);
12803 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_all_cmd
);
12804 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_cmd
);
12805 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_cmd
);
12806 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_all_cmd
);
12808 install_element(VIEW_NODE
,
12809 &show_ip_ospf_instance_neighbor_int_detail_cmd
);
12810 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_int_cmd
);
12811 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_id_cmd
);
12812 install_element(VIEW_NODE
,
12813 &show_ip_ospf_instance_neighbor_detail_all_cmd
);
12814 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_detail_cmd
);
12815 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_cmd
);
12816 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_all_cmd
);
12818 /* "show ip ospf route" commands. */
12819 install_element(VIEW_NODE
, &show_ip_ospf_route_cmd
);
12820 install_element(VIEW_NODE
, &show_ip_ospf_border_routers_cmd
);
12821 install_element(VIEW_NODE
, &show_ip_ospf_reachable_routers_cmd
);
12823 install_element(VIEW_NODE
, &show_ip_ospf_instance_route_cmd
);
12824 install_element(VIEW_NODE
, &show_ip_ospf_instance_border_routers_cmd
);
12825 install_element(VIEW_NODE
,
12826 &show_ip_ospf_instance_reachable_routers_cmd
);
12828 /* "show ip ospf vrfs" commands. */
12829 install_element(VIEW_NODE
, &show_ip_ospf_vrfs_cmd
);
12831 /* "show ip ospf gr-helper details" command */
12832 install_element(VIEW_NODE
, &show_ip_ospf_gr_helper_cmd
);
12834 /* "show ip ospf summary-address" command */
12835 install_element(VIEW_NODE
, &show_ip_ospf_external_aggregator_cmd
);
12838 /* Initialization of OSPF interface. */
12839 static void ospf_vty_if_init(void)
12841 /* Install interface node. */
12842 if_cmd_init(config_write_interface
);
12844 /* "ip ospf authentication" commands. */
12845 install_element(INTERFACE_NODE
, &ip_ospf_authentication_args_addr_cmd
);
12846 install_element(INTERFACE_NODE
, &ip_ospf_authentication_addr_cmd
);
12847 install_element(INTERFACE_NODE
,
12848 &no_ip_ospf_authentication_args_addr_cmd
);
12849 install_element(INTERFACE_NODE
, &no_ip_ospf_authentication_addr_cmd
);
12850 install_element(INTERFACE_NODE
, &ip_ospf_authentication_key_addr_cmd
);
12851 install_element(INTERFACE_NODE
,
12852 &no_ip_ospf_authentication_key_authkey_addr_cmd
);
12853 install_element(INTERFACE_NODE
,
12854 &no_ospf_authentication_key_authkey_addr_cmd
);
12856 /* "ip ospf message-digest-key" commands. */
12857 install_element(INTERFACE_NODE
, &ip_ospf_message_digest_key_cmd
);
12858 install_element(INTERFACE_NODE
, &no_ip_ospf_message_digest_key_cmd
);
12860 /* "ip ospf cost" commands. */
12861 install_element(INTERFACE_NODE
, &ip_ospf_cost_cmd
);
12862 install_element(INTERFACE_NODE
, &no_ip_ospf_cost_cmd
);
12864 /* "ip ospf mtu-ignore" commands. */
12865 install_element(INTERFACE_NODE
, &ip_ospf_mtu_ignore_addr_cmd
);
12866 install_element(INTERFACE_NODE
, &no_ip_ospf_mtu_ignore_addr_cmd
);
12868 /* "ip ospf dead-interval" commands. */
12869 install_element(INTERFACE_NODE
, &ip_ospf_dead_interval_cmd
);
12870 install_element(INTERFACE_NODE
,
12871 &ip_ospf_dead_interval_minimal_addr_cmd
);
12872 install_element(INTERFACE_NODE
, &no_ip_ospf_dead_interval_cmd
);
12874 /* "ip ospf hello-interval" commands. */
12875 install_element(INTERFACE_NODE
, &ip_ospf_hello_interval_cmd
);
12876 install_element(INTERFACE_NODE
, &no_ip_ospf_hello_interval_cmd
);
12878 /* "ip ospf network" commands. */
12879 install_element(INTERFACE_NODE
, &ip_ospf_network_cmd
);
12880 install_element(INTERFACE_NODE
, &no_ip_ospf_network_cmd
);
12882 /* "ip ospf priority" commands. */
12883 install_element(INTERFACE_NODE
, &ip_ospf_priority_cmd
);
12884 install_element(INTERFACE_NODE
, &no_ip_ospf_priority_cmd
);
12886 /* "ip ospf retransmit-interval" commands. */
12887 install_element(INTERFACE_NODE
, &ip_ospf_retransmit_interval_addr_cmd
);
12888 install_element(INTERFACE_NODE
,
12889 &no_ip_ospf_retransmit_interval_addr_cmd
);
12891 /* "ip ospf transmit-delay" commands. */
12892 install_element(INTERFACE_NODE
, &ip_ospf_transmit_delay_addr_cmd
);
12893 install_element(INTERFACE_NODE
, &no_ip_ospf_transmit_delay_addr_cmd
);
12895 /* "ip ospf area" commands. */
12896 install_element(INTERFACE_NODE
, &ip_ospf_area_cmd
);
12897 install_element(INTERFACE_NODE
, &no_ip_ospf_area_cmd
);
12899 /* "ip ospf passive" commands. */
12900 install_element(INTERFACE_NODE
, &ip_ospf_passive_cmd
);
12901 install_element(INTERFACE_NODE
, &no_ip_ospf_passive_cmd
);
12903 /* These commands are compatibitliy for previous version. */
12904 install_element(INTERFACE_NODE
, &ospf_authentication_key_cmd
);
12905 install_element(INTERFACE_NODE
, &ospf_message_digest_key_cmd
);
12906 install_element(INTERFACE_NODE
, &no_ospf_message_digest_key_cmd
);
12907 install_element(INTERFACE_NODE
, &ospf_dead_interval_cmd
);
12908 install_element(INTERFACE_NODE
, &no_ospf_dead_interval_cmd
);
12909 install_element(INTERFACE_NODE
, &ospf_hello_interval_cmd
);
12910 install_element(INTERFACE_NODE
, &no_ospf_hello_interval_cmd
);
12911 install_element(INTERFACE_NODE
, &ospf_cost_cmd
);
12912 install_element(INTERFACE_NODE
, &no_ospf_cost_cmd
);
12913 install_element(INTERFACE_NODE
, &ospf_network_cmd
);
12914 install_element(INTERFACE_NODE
, &no_ospf_network_cmd
);
12915 install_element(INTERFACE_NODE
, &ospf_priority_cmd
);
12916 install_element(INTERFACE_NODE
, &no_ospf_priority_cmd
);
12917 install_element(INTERFACE_NODE
, &ospf_retransmit_interval_cmd
);
12918 install_element(INTERFACE_NODE
, &no_ospf_retransmit_interval_cmd
);
12919 install_element(INTERFACE_NODE
, &ospf_transmit_delay_cmd
);
12920 install_element(INTERFACE_NODE
, &no_ospf_transmit_delay_cmd
);
12923 static void ospf_vty_zebra_init(void)
12925 install_element(OSPF_NODE
, &ospf_redistribute_source_cmd
);
12926 install_element(OSPF_NODE
, &no_ospf_redistribute_source_cmd
);
12927 install_element(OSPF_NODE
, &ospf_redistribute_instance_source_cmd
);
12928 install_element(OSPF_NODE
, &no_ospf_redistribute_instance_source_cmd
);
12930 install_element(OSPF_NODE
, &ospf_distribute_list_out_cmd
);
12931 install_element(OSPF_NODE
, &no_ospf_distribute_list_out_cmd
);
12933 install_element(OSPF_NODE
, &ospf_default_information_originate_cmd
);
12934 install_element(OSPF_NODE
, &no_ospf_default_information_originate_cmd
);
12936 install_element(OSPF_NODE
, &ospf_default_metric_cmd
);
12937 install_element(OSPF_NODE
, &no_ospf_default_metric_cmd
);
12939 install_element(OSPF_NODE
, &ospf_distance_cmd
);
12940 install_element(OSPF_NODE
, &no_ospf_distance_cmd
);
12941 install_element(OSPF_NODE
, &no_ospf_distance_ospf_cmd
);
12942 install_element(OSPF_NODE
, &ospf_distance_ospf_cmd
);
12944 /*Ospf garcefull restart helper configurations */
12945 install_element(OSPF_NODE
, &ospf_gr_helper_enable_cmd
);
12946 install_element(OSPF_NODE
, &no_ospf_gr_helper_enable_cmd
);
12947 install_element(OSPF_NODE
, &ospf_gr_helper_enable_lsacheck_cmd
);
12948 install_element(OSPF_NODE
, &no_ospf_gr_helper_enable_lsacheck_cmd
);
12949 install_element(OSPF_NODE
, &ospf_gr_helper_supported_grace_time_cmd
);
12950 install_element(OSPF_NODE
, &no_ospf_gr_helper_supported_grace_time_cmd
);
12951 install_element(OSPF_NODE
, &ospf_gr_helper_planned_only_cmd
);
12952 install_element(OSPF_NODE
, &no_ospf_gr_helper_planned_only_cmd
);
12954 /* External LSA summarisation config commands.*/
12955 install_element(OSPF_NODE
, &ospf_external_route_aggregation_cmd
);
12956 install_element(OSPF_NODE
, &no_ospf_external_route_aggregation_cmd
);
12957 install_element(OSPF_NODE
,
12958 &ospf_external_route_aggregation_no_adrvertise_cmd
);
12959 install_element(OSPF_NODE
,
12960 &no_ospf_external_route_aggregation_no_adrvertise_cmd
);
12961 install_element(OSPF_NODE
, &ospf_route_aggregation_timer_cmd
);
12962 install_element(OSPF_NODE
, &no_ospf_route_aggregation_timer_cmd
);
12965 static int ospf_config_write(struct vty
*vty
);
12966 static struct cmd_node ospf_node
= {
12969 .parent_node
= CONFIG_NODE
,
12970 .prompt
= "%s(config-router)# ",
12971 .config_write
= ospf_config_write
,
12974 static void ospf_interface_clear(struct interface
*ifp
)
12976 if (!if_is_operative(ifp
))
12979 if (IS_DEBUG_OSPF(ism
, ISM_EVENTS
))
12980 zlog_debug("ISM[%s]: clear by reset", ifp
->name
);
12982 ospf_if_reset(ifp
);
12985 DEFUN (clear_ip_ospf_interface
,
12986 clear_ip_ospf_interface_cmd
,
12987 "clear ip ospf [vrf NAME] interface [IFNAME]",
12990 "OSPF information\n"
12992 "Interface information\n"
12993 "Interface name\n")
12995 int idx_ifname
= 0;
12997 struct interface
*ifp
;
12998 struct listnode
*node
;
12999 struct ospf
*ospf
= NULL
;
13000 char *vrf_name
= NULL
;
13001 vrf_id_t vrf_id
= VRF_DEFAULT
;
13002 struct vrf
*vrf
= NULL
;
13004 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
13005 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
13006 if (vrf_name
&& strmatch(vrf_name
, VRF_DEFAULT_NAME
))
13009 vrf
= vrf_lookup_by_name(vrf_name
);
13011 vrf_id
= vrf
->vrf_id
;
13013 if (!argv_find(argv
, argc
, "IFNAME", &idx_ifname
)) {
13014 /* Clear all the ospfv2 interfaces. */
13015 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
13016 if (vrf_id
!= ospf
->vrf_id
)
13019 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
13020 FOR_ALL_INTERFACES (vrf
, ifp
)
13021 ospf_interface_clear(ifp
);
13024 /* Interface name is specified. */
13025 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf_id
);
13027 vty_out(vty
, "No such interface name\n");
13029 ospf_interface_clear(ifp
);
13032 return CMD_SUCCESS
;
13035 DEFPY_HIDDEN(ospf_lsa_refresh_timer
, ospf_lsa_refresh_timer_cmd
,
13036 "[no$no] ospf lsa-refresh [(120-1800)]$value",
13038 "OSPF lsa refresh timer\n"
13039 "timer value in seconds\n")
13041 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
13044 ospf
->lsa_refresh_timer
= OSPF_LS_REFRESH_TIME
;
13046 ospf
->lsa_refresh_timer
= value
;
13048 return CMD_SUCCESS
;
13051 DEFPY_HIDDEN(ospf_maxage_delay_timer
, ospf_maxage_delay_timer_cmd
,
13052 "[no$no] ospf maxage-delay [(0-60)]$value",
13054 "OSPF lsa maxage delay timer\n"
13055 "timer value in seconds\n")
13057 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
13060 ospf
->maxage_delay
= OSPF_LSA_MAXAGE_REMOVE_DELAY_DEFAULT
;
13062 ospf
->maxage_delay
= value
;
13064 THREAD_OFF(ospf
->t_maxage
);
13065 OSPF_TIMER_ON(ospf
->t_maxage
, ospf_maxage_lsa_remover
,
13066 ospf
->maxage_delay
);
13068 return CMD_SUCCESS
;
13072 * ------------------------------------------------------------------------*
13073 * Following is (vty) configuration functions for flood-reduction handling.
13074 * ------------------------------------------------------------------------
13077 DEFPY(flood_reduction
, flood_reduction_cmd
, "flood-reduction",
13078 "flood reduction feature\n")
13080 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
13081 struct ospf_area
*area
;
13082 struct listnode
*node
;
13084 /* Turn on the Flood Reduction feature for the router. */
13085 if (!ospf
->fr_configured
) {
13086 ospf
->fr_configured
= true;
13087 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT
,
13088 "Flood Reduction: OFF -> ON");
13089 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
13091 ospf_area_update_fr_state(area
);
13092 ospf_refresh_area_self_lsas(area
);
13097 return CMD_SUCCESS
;
13100 DEFPY(flood_reduction_area
, flood_reduction_area_cmd
,
13101 "area <A.B.C.D|(0-4294967295)> flood-reduction",
13102 "OSPF area parameters\n"
13103 "OSPF area ID in IP address format\n"
13104 "OSPF area ID as a decimal value\n"
13105 "Enable flood reduction for area\n")
13107 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
13108 struct ospf_area
*oa
;
13112 const char *areaid
;
13113 struct in_addr area_id
;
13115 areaid
= argv
[idx
]->arg
;
13117 ret
= str2area_id(areaid
, &area_id
, &format
);
13119 vty_out(vty
, "Please specify area by A.B.C.D|<0-4294967295>\n");
13120 return CMD_WARNING_CONFIG_FAILED
;
13123 oa
= ospf_area_lookup_by_area_id(ospf
, area_id
);
13125 vty_out(vty
, "OSPF area ID not present\n");
13126 return CMD_WARNING_CONFIG_FAILED
;
13129 /* Turn on the Flood Reduction feature for the area. */
13130 if (!oa
->fr_info
.configured
) {
13131 oa
->fr_info
.configured
= true;
13132 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT
,
13133 "Flood Reduction area %pI4 : OFF -> ON",
13135 ospf_area_update_fr_state(oa
);
13136 ospf_refresh_area_self_lsas(oa
);
13139 return CMD_SUCCESS
;
13142 DEFPY(no_flood_reduction
, no_flood_reduction_cmd
, "no flood-reduction",
13143 NO_STR
"flood reduction feature\n")
13145 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
13146 struct listnode
*node
;
13147 struct ospf_area
*area
;
13149 /* Turn off the Flood Reduction feature for the router. */
13150 if (ospf
->fr_configured
) {
13151 ospf
->fr_configured
= false;
13152 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT
,
13153 "Flood Reduction: ON -> OFF");
13154 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
13156 ospf_area_update_fr_state(area
);
13157 ospf_refresh_area_self_lsas(area
);
13162 return CMD_SUCCESS
;
13165 DEFPY(no_flood_reduction_area
, no_flood_reduction_area_cmd
,
13166 "no area <A.B.C.D|(0-4294967295)> flood-reduction",
13168 "OSPF area parameters\n"
13169 "OSPF area ID in IP address format\n"
13170 "OSPF area ID as a decimal value\n"
13171 "Disable flood reduction for area\n")
13173 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
13174 struct ospf_area
*oa
;
13178 const char *areaid
;
13179 struct in_addr area_id
;
13181 areaid
= argv
[idx
]->arg
;
13183 ret
= str2area_id(areaid
, &area_id
, &format
);
13185 vty_out(vty
, "Please specify area by A.B.C.D|<0-4294967295>\n");
13186 return CMD_WARNING_CONFIG_FAILED
;
13189 oa
= ospf_area_lookup_by_area_id(ospf
, area_id
);
13191 vty_out(vty
, "OSPF area ID not present\n");
13192 return CMD_WARNING_CONFIG_FAILED
;
13195 /* Turn off the Flood Reduction feature for the area. */
13196 if (oa
->fr_info
.configured
) {
13197 oa
->fr_info
.configured
= false;
13198 OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT
,
13199 "Flood Reduction area %pI4 : ON -> OFF",
13201 ospf_area_update_fr_state(oa
);
13202 ospf_refresh_area_self_lsas(oa
);
13205 return CMD_SUCCESS
;
13208 void ospf_vty_clear_init(void)
13210 install_element(ENABLE_NODE
, &clear_ip_ospf_interface_cmd
);
13211 install_element(ENABLE_NODE
, &clear_ip_ospf_process_cmd
);
13212 install_element(ENABLE_NODE
, &clear_ip_ospf_neighbor_cmd
);
13216 /* Install OSPF related vty commands. */
13217 void ospf_vty_init(void)
13219 /* Install ospf top node. */
13220 install_node(&ospf_node
);
13222 /* "router ospf" commands. */
13223 install_element(CONFIG_NODE
, &router_ospf_cmd
);
13224 install_element(CONFIG_NODE
, &no_router_ospf_cmd
);
13227 install_default(OSPF_NODE
);
13229 /* "ospf router-id" commands. */
13230 install_element(OSPF_NODE
, &ospf_router_id_cmd
);
13231 install_element(OSPF_NODE
, &ospf_router_id_old_cmd
);
13232 install_element(OSPF_NODE
, &no_ospf_router_id_cmd
);
13234 /* "passive-interface" commands. */
13235 install_element(OSPF_NODE
, &ospf_passive_interface_default_cmd
);
13236 install_element(OSPF_NODE
, &ospf_passive_interface_addr_cmd
);
13237 install_element(OSPF_NODE
, &no_ospf_passive_interface_default_cmd
);
13238 install_element(OSPF_NODE
, &no_ospf_passive_interface_addr_cmd
);
13240 /* "ospf abr-type" commands. */
13241 install_element(OSPF_NODE
, &ospf_abr_type_cmd
);
13242 install_element(OSPF_NODE
, &no_ospf_abr_type_cmd
);
13244 /* "ospf log-adjacency-changes" commands. */
13245 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_cmd
);
13246 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_detail_cmd
);
13247 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_cmd
);
13248 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_detail_cmd
);
13250 /* "ospf rfc1583-compatible" commands. */
13251 install_element(OSPF_NODE
, &ospf_compatible_rfc1583_cmd
);
13252 install_element(OSPF_NODE
, &no_ospf_compatible_rfc1583_cmd
);
13253 install_element(OSPF_NODE
, &ospf_rfc1583_flag_cmd
);
13254 install_element(OSPF_NODE
, &no_ospf_rfc1583_flag_cmd
);
13256 /* "ospf send-extra-data zebra" commands. */
13257 install_element(OSPF_NODE
, &ospf_send_extra_data_cmd
);
13259 /* "network area" commands. */
13260 install_element(OSPF_NODE
, &ospf_network_area_cmd
);
13261 install_element(OSPF_NODE
, &no_ospf_network_area_cmd
);
13263 /* "area authentication" commands. */
13264 install_element(OSPF_NODE
,
13265 &ospf_area_authentication_message_digest_cmd
);
13266 install_element(OSPF_NODE
, &ospf_area_authentication_cmd
);
13267 install_element(OSPF_NODE
, &no_ospf_area_authentication_cmd
);
13269 /* "area range" commands. */
13270 install_element(OSPF_NODE
, &ospf_area_range_cmd
);
13271 install_element(OSPF_NODE
, &ospf_area_range_cost_cmd
);
13272 install_element(OSPF_NODE
, &ospf_area_range_not_advertise_cmd
);
13273 install_element(OSPF_NODE
, &no_ospf_area_range_cmd
);
13274 install_element(OSPF_NODE
, &no_ospf_area_range_substitute_cmd
);
13276 /* "area virtual-link" commands. */
13277 install_element(OSPF_NODE
, &ospf_area_vlink_cmd
);
13278 install_element(OSPF_NODE
, &ospf_area_vlink_intervals_cmd
);
13279 install_element(OSPF_NODE
, &no_ospf_area_vlink_cmd
);
13280 install_element(OSPF_NODE
, &no_ospf_area_vlink_intervals_cmd
);
13283 /* "area stub" commands. */
13284 install_element(OSPF_NODE
, &ospf_area_stub_no_summary_cmd
);
13285 install_element(OSPF_NODE
, &ospf_area_stub_cmd
);
13286 install_element(OSPF_NODE
, &no_ospf_area_stub_no_summary_cmd
);
13287 install_element(OSPF_NODE
, &no_ospf_area_stub_cmd
);
13289 /* "area nssa" commands. */
13290 install_element(OSPF_NODE
, &ospf_area_nssa_cmd
);
13291 install_element(OSPF_NODE
, &ospf_area_nssa_translate_cmd
);
13292 install_element(OSPF_NODE
, &ospf_area_nssa_no_summary_cmd
);
13293 install_element(OSPF_NODE
, &no_ospf_area_nssa_no_summary_cmd
);
13294 install_element(OSPF_NODE
, &ospf_area_nssa_suppress_fa_cmd
);
13295 install_element(OSPF_NODE
, &no_ospf_area_nssa_suppress_fa_cmd
);
13296 install_element(OSPF_NODE
, &no_ospf_area_nssa_cmd
);
13298 install_element(OSPF_NODE
, &ospf_area_default_cost_cmd
);
13299 install_element(OSPF_NODE
, &no_ospf_area_default_cost_cmd
);
13301 install_element(OSPF_NODE
, &ospf_area_shortcut_cmd
);
13302 install_element(OSPF_NODE
, &no_ospf_area_shortcut_cmd
);
13304 install_element(OSPF_NODE
, &ospf_area_export_list_cmd
);
13305 install_element(OSPF_NODE
, &no_ospf_area_export_list_cmd
);
13307 install_element(OSPF_NODE
, &ospf_area_filter_list_cmd
);
13308 install_element(OSPF_NODE
, &no_ospf_area_filter_list_cmd
);
13310 install_element(OSPF_NODE
, &ospf_area_import_list_cmd
);
13311 install_element(OSPF_NODE
, &no_ospf_area_import_list_cmd
);
13313 /* SPF timer commands */
13314 install_element(OSPF_NODE
, &ospf_timers_throttle_spf_cmd
);
13315 install_element(OSPF_NODE
, &no_ospf_timers_throttle_spf_cmd
);
13317 /* LSA timers commands */
13318 install_element(OSPF_NODE
, &ospf_timers_min_ls_interval_cmd
);
13319 install_element(OSPF_NODE
, &no_ospf_timers_min_ls_interval_cmd
);
13320 install_element(OSPF_NODE
, &ospf_timers_lsa_min_arrival_cmd
);
13321 install_element(OSPF_NODE
, &no_ospf_timers_lsa_min_arrival_cmd
);
13323 /* refresh timer commands */
13324 install_element(OSPF_NODE
, &ospf_refresh_timer_cmd
);
13325 install_element(OSPF_NODE
, &no_ospf_refresh_timer_val_cmd
);
13327 /* max-metric commands */
13328 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_admin_cmd
);
13329 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_admin_cmd
);
13330 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_startup_cmd
);
13331 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_startup_cmd
);
13332 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_shutdown_cmd
);
13333 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_shutdown_cmd
);
13335 /* reference bandwidth commands */
13336 install_element(OSPF_NODE
, &ospf_auto_cost_reference_bandwidth_cmd
);
13337 install_element(OSPF_NODE
, &no_ospf_auto_cost_reference_bandwidth_cmd
);
13339 /* "neighbor" commands. */
13340 install_element(OSPF_NODE
, &ospf_neighbor_cmd
);
13341 install_element(OSPF_NODE
, &ospf_neighbor_poll_interval_cmd
);
13342 install_element(OSPF_NODE
, &no_ospf_neighbor_cmd
);
13343 install_element(OSPF_NODE
, &no_ospf_neighbor_poll_cmd
);
13345 /* write multiplier commands */
13346 install_element(OSPF_NODE
, &ospf_write_multiplier_cmd
);
13347 install_element(OSPF_NODE
, &write_multiplier_cmd
);
13348 install_element(OSPF_NODE
, &no_ospf_write_multiplier_cmd
);
13349 install_element(OSPF_NODE
, &no_write_multiplier_cmd
);
13351 /* "proactive-arp" commands. */
13352 install_element(OSPF_NODE
, &ospf_proactive_arp_cmd
);
13353 install_element(OSPF_NODE
, &no_ospf_proactive_arp_cmd
);
13355 /* TI-LFA commands */
13356 install_element(OSPF_NODE
, &ospf_ti_lfa_cmd
);
13357 install_element(OSPF_NODE
, &no_ospf_ti_lfa_cmd
);
13359 /* Max path configurations */
13360 install_element(OSPF_NODE
, &ospf_max_multipath_cmd
);
13361 install_element(OSPF_NODE
, &no_ospf_max_multipath_cmd
);
13363 vrf_cmd_init(NULL
);
13365 install_element(OSPF_NODE
, &ospf_lsa_refresh_timer_cmd
);
13366 install_element(OSPF_NODE
, &ospf_maxage_delay_timer_cmd
);
13368 /* Flood Reduction commands */
13369 install_element(OSPF_NODE
, &flood_reduction_cmd
);
13370 install_element(OSPF_NODE
, &no_flood_reduction_cmd
);
13371 install_element(OSPF_NODE
, &flood_reduction_area_cmd
);
13372 install_element(OSPF_NODE
, &no_flood_reduction_area_cmd
);
13374 /* Init interface related vty commands. */
13375 ospf_vty_if_init();
13377 /* Init zebra related vty commands. */
13378 ospf_vty_zebra_init();