2 * Copyright (C) 2005 6WIND <alain.ritoux@6wind.com>
3 * Copyright (C) 2000 Toshiaki Takada
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
38 #include "lib/printfrr.h"
40 #include "ospfd/ospfd.h"
41 #include "ospfd/ospf_asbr.h"
42 #include "ospfd/ospf_lsa.h"
43 #include "ospfd/ospf_lsdb.h"
44 #include "ospfd/ospf_ism.h"
45 #include "ospfd/ospf_interface.h"
46 #include "ospfd/ospf_nsm.h"
47 #include "ospfd/ospf_neighbor.h"
48 #include "ospfd/ospf_flood.h"
49 #include "ospfd/ospf_abr.h"
50 #include "ospfd/ospf_spf.h"
51 #include "ospfd/ospf_route.h"
52 #include "ospfd/ospf_zebra.h"
53 /*#include "ospfd/ospf_routemap.h" */
54 #include "ospfd/ospf_vty.h"
55 #include "ospfd/ospf_dump.h"
56 #include "ospfd/ospf_bfd.h"
57 #include "ospfd/ospf_ldp_sync.h"
60 FRR_CFG_DEFAULT_BOOL(OSPF_LOG_ADJACENCY_CHANGES
,
61 { .val_bool
= true, .match_profile
= "datacenter", },
62 { .val_bool
= false },
65 static const char *const ospf_network_type_str
[] = {
66 "Null", "POINTOPOINT", "BROADCAST", "NBMA", "POINTOMULTIPOINT",
67 "VIRTUALLINK", "LOOPBACK"};
69 /* Utility functions. */
70 int str2area_id(const char *str
, struct in_addr
*area_id
, int *area_id_fmt
)
74 area_id
->s_addr
= htonl(strtoul(str
, &ep
, 10));
75 if (*ep
&& !inet_aton(str
, area_id
))
79 *ep
? OSPF_AREA_ID_FMT_DOTTEDQUAD
: OSPF_AREA_ID_FMT_DECIMAL
;
84 static void area_id2str(char *buf
, int length
, struct in_addr
*area_id
,
87 if (area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
88 inet_ntop(AF_INET
, area_id
, buf
, length
);
90 snprintf(buf
, length
, "%lu",
91 (unsigned long)ntohl(area_id
->s_addr
));
94 static int str2metric(const char *str
, int *metric
)
100 *metric
= strtol(str
, NULL
, 10);
101 if (*metric
< 0 || *metric
> 16777214) {
102 /* vty_out (vty, "OSPF metric value is invalid\n"); */
109 static int str2metric_type(const char *str
, int *metric_type
)
115 if (strncmp(str
, "1", 1) == 0)
116 *metric_type
= EXTERNAL_METRIC_TYPE_1
;
117 else if (strncmp(str
, "2", 1) == 0)
118 *metric_type
= EXTERNAL_METRIC_TYPE_2
;
125 int ospf_oi_count(struct interface
*ifp
)
127 struct route_node
*rn
;
130 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
137 #define OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf) \
138 if (argv_find(argv, argc, "vrf", &idx_vrf)) { \
139 vrf_name = argv[idx_vrf + 1]->arg; \
140 all_vrf = strmatch(vrf_name, "all"); \
143 static int ospf_router_cmd_parse(struct vty
*vty
, struct cmd_token
*argv
[],
144 const int argc
, unsigned short *instance
,
145 const char **vrf_name
)
147 int idx_vrf
= 0, idx_inst
= 0;
150 if (argv_find(argv
, argc
, "(1-65535)", &idx_inst
)) {
151 if (ospf_instance
== 0) {
153 "%% OSPF is not running in instance mode\n");
154 return CMD_WARNING_CONFIG_FAILED
;
157 *instance
= strtoul(argv
[idx_inst
]->arg
, NULL
, 10);
160 *vrf_name
= VRF_DEFAULT_NAME
;
161 if (argv_find(argv
, argc
, "vrf", &idx_vrf
)) {
162 if (ospf_instance
!= 0) {
164 "%% VRF is not supported in instance mode\n");
165 return CMD_WARNING_CONFIG_FAILED
;
168 *vrf_name
= argv
[idx_vrf
+ 1]->arg
;
174 static void ospf_show_vrf_name(struct ospf
*ospf
, struct vty
*vty
,
175 json_object
*json
, uint8_t use_vrf
)
179 json_object_string_add(json
, "vrfName",
180 ospf_get_name(ospf
));
181 json_object_int_add(json
, "vrfId", ospf
->vrf_id
);
183 vty_out(vty
, "VRF Name: %s\n", ospf_get_name(ospf
));
187 #include "ospfd/ospf_vty_clippy.c"
189 DEFUN_NOSH (router_ospf
,
191 "router ospf [{(1-65535)|vrf NAME}]",
192 "Enable a routing process\n"
193 "Start OSPF configuration\n"
197 unsigned short instance
;
198 const char *vrf_name
;
199 bool created
= false;
203 ret
= ospf_router_cmd_parse(vty
, argv
, argc
, &instance
, &vrf_name
);
204 if (ret
!= CMD_SUCCESS
)
207 if (instance
!= ospf_instance
) {
208 VTY_PUSH_CONTEXT_NULL(OSPF_NODE
);
209 return CMD_NOT_MY_INSTANCE
;
212 ospf
= ospf_get(instance
, vrf_name
, &created
);
215 if (DFLT_OSPF_LOG_ADJACENCY_CHANGES
)
216 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
218 if (IS_DEBUG_OSPF_EVENT
)
220 "Config command 'router ospf %d' received, vrf %s id %u oi_running %u",
221 ospf
->instance
, ospf_get_name(ospf
), ospf
->vrf_id
,
224 VTY_PUSH_CONTEXT(OSPF_NODE
, ospf
);
229 DEFUN (no_router_ospf
,
231 "no router ospf [{(1-65535)|vrf NAME}]",
233 "Enable a routing process\n"
234 "Start OSPF configuration\n"
238 unsigned short instance
;
239 const char *vrf_name
;
243 ret
= ospf_router_cmd_parse(vty
, argv
, argc
, &instance
, &vrf_name
);
244 if (ret
!= CMD_SUCCESS
)
247 if (instance
!= ospf_instance
)
248 return CMD_NOT_MY_INSTANCE
;
250 ospf
= ospf_lookup(instance
, vrf_name
);
254 ret
= CMD_WARNING_CONFIG_FAILED
;
260 DEFPY (ospf_router_id
,
262 "ospf router-id A.B.C.D",
263 "OSPF specific commands\n"
264 "router-id for the OSPF process\n"
265 "OSPF router-id in IP address format\n")
267 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
269 struct listnode
*node
;
270 struct ospf_area
*area
;
272 ospf
->router_id_static
= router_id
;
274 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
275 if (area
->full_nbrs
) {
277 "For this router-id change to take effect, use \"clear ip ospf process\" command\n");
281 ospf_router_id_update(ospf
);
286 DEFUN_HIDDEN (ospf_router_id_old
,
287 ospf_router_id_old_cmd
,
289 "router-id for the OSPF process\n"
290 "OSPF router-id in IP address format\n")
292 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
294 struct listnode
*node
;
295 struct ospf_area
*area
;
296 struct in_addr router_id
;
299 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &router_id
);
301 vty_out(vty
, "Please specify Router ID by A.B.C.D\n");
302 return CMD_WARNING_CONFIG_FAILED
;
305 ospf
->router_id_static
= router_id
;
307 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
308 if (area
->full_nbrs
) {
310 "For this router-id change to take effect, use \"clear ip ospf process\" command\n");
314 ospf_router_id_update(ospf
);
319 DEFPY (no_ospf_router_id
,
320 no_ospf_router_id_cmd
,
321 "no ospf router-id [A.B.C.D]",
323 "OSPF specific commands\n"
324 "router-id for the OSPF process\n"
325 "OSPF router-id in IP address format\n")
327 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
328 struct listnode
*node
;
329 struct ospf_area
*area
;
332 if (!IPV4_ADDR_SAME(&ospf
->router_id_static
, &router_id
)) {
333 vty_out(vty
, "%% OSPF router-id doesn't match\n");
334 return CMD_WARNING_CONFIG_FAILED
;
338 ospf
->router_id_static
.s_addr
= 0;
340 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
341 if (area
->full_nbrs
) {
343 "For this router-id change to take effect, use \"clear ip ospf process\" command\n");
347 ospf_router_id_update(ospf
);
353 static void ospf_passive_interface_default_update(struct ospf
*ospf
,
357 struct ospf_interface
*oi
;
359 ospf
->passive_interface_default
= newval
;
361 /* update multicast memberships */
362 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, ln
, oi
))
363 ospf_if_set_multicast(oi
);
366 static void ospf_passive_interface_update(struct interface
*ifp
,
367 struct ospf_if_params
*params
,
368 struct in_addr addr
, uint8_t newval
)
370 struct route_node
*rn
;
372 if (OSPF_IF_PARAM_CONFIGURED(params
, passive_interface
)) {
373 if (params
->passive_interface
== newval
)
376 params
->passive_interface
= newval
;
377 UNSET_IF_PARAM(params
, passive_interface
);
378 if (params
!= IF_DEF_PARAMS(ifp
)) {
379 ospf_free_if_params(ifp
, addr
);
380 ospf_if_update_params(ifp
, addr
);
383 params
->passive_interface
= newval
;
384 SET_IF_PARAM(params
, passive_interface
);
388 * XXX We should call ospf_if_set_multicast on exactly those
389 * interfaces for which the passive property changed. It is too much
390 * work to determine this set, so we do this for every interface.
391 * This is safe and reasonable because ospf_if_set_multicast uses a
392 * record of joined groups to avoid systems calls if the desired
393 * memberships match the current memership.
396 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
397 struct ospf_interface
*oi
= rn
->info
;
400 ospf_if_set_multicast(oi
);
404 * XXX It is not clear what state transitions the interface needs to
405 * undergo when going from active to passive and vice versa. Fixing
406 * this will require precise identification of interfaces having such a
411 DEFUN (ospf_passive_interface_default
,
412 ospf_passive_interface_default_cmd
,
413 "passive-interface default",
414 "Suppress routing updates on an interface\n"
415 "Suppress routing updates on interfaces by default\n")
417 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
419 ospf_passive_interface_default_update(ospf
, OSPF_IF_PASSIVE
);
424 DEFUN_HIDDEN (ospf_passive_interface_addr
,
425 ospf_passive_interface_addr_cmd
,
426 "passive-interface IFNAME [A.B.C.D]",
427 "Suppress routing updates on an interface\n"
431 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
433 struct interface
*ifp
= NULL
;
434 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
435 struct ospf_if_params
*params
;
439 "This command is deprecated, because it is not VRF-aware.\n");
441 "Please, use \"ip ospf passive\" on an interface instead.\n");
443 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
444 ifp
= if_get_by_name(argv
[1]->arg
, ospf
->vrf_id
, ospf
->name
);
447 vty_out(vty
, "interface %s not found.\n", (char *)argv
[1]->arg
);
448 return CMD_WARNING_CONFIG_FAILED
;
452 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
455 "Please specify interface address by A.B.C.D\n");
456 return CMD_WARNING_CONFIG_FAILED
;
459 params
= ospf_get_if_params(ifp
, addr
);
460 ospf_if_update_params(ifp
, addr
);
462 params
= IF_DEF_PARAMS(ifp
);
465 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_PASSIVE
);
470 DEFUN (no_ospf_passive_interface_default
,
471 no_ospf_passive_interface_default_cmd
,
472 "no passive-interface default",
474 "Allow routing updates on an interface\n"
475 "Allow routing updates on interfaces by default\n")
477 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
479 ospf_passive_interface_default_update(ospf
, OSPF_IF_ACTIVE
);
484 DEFUN_HIDDEN (no_ospf_passive_interface
,
485 no_ospf_passive_interface_addr_cmd
,
486 "no passive-interface IFNAME [A.B.C.D]",
488 "Allow routing updates on an interface\n"
492 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
494 struct interface
*ifp
= NULL
;
495 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
496 struct ospf_if_params
*params
;
500 "This command is deprecated, because it is not VRF-aware.\n");
502 "Please, use \"no ip ospf passive\" on an interface instead.\n");
504 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
505 ifp
= if_get_by_name(argv
[2]->arg
, ospf
->vrf_id
, ospf
->name
);
508 vty_out(vty
, "interface %s not found.\n", (char *)argv
[2]->arg
);
509 return CMD_WARNING_CONFIG_FAILED
;
513 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
516 "Please specify interface address by A.B.C.D\n");
517 return CMD_WARNING_CONFIG_FAILED
;
519 params
= ospf_lookup_if_params(ifp
, addr
);
523 params
= IF_DEF_PARAMS(ifp
);
526 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_ACTIVE
);
532 DEFUN (ospf_network_area
,
533 ospf_network_area_cmd
,
534 "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
535 "Enable routing on an IP network\n"
536 "OSPF network prefix\n"
537 "Set the OSPF area ID\n"
538 "OSPF area ID in IP address format\n"
539 "OSPF area ID as a decimal value\n")
541 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
542 int idx_ipv4_prefixlen
= 1;
543 int idx_ipv4_number
= 3;
544 struct prefix_ipv4 p
;
545 struct in_addr area_id
;
549 if (ospf
->instance
) {
551 "The network command is not supported in multi-instance ospf\n");
552 return CMD_WARNING_CONFIG_FAILED
;
555 count
= ospf_count_area_params(ospf
);
558 "Please remove all ip ospf area x.x.x.x commands first.\n");
559 if (IS_DEBUG_OSPF_EVENT
)
561 "%s ospf vrf %s num of %u ip ospf area x config",
562 __func__
, ospf_get_name(ospf
), count
);
563 return CMD_WARNING_CONFIG_FAILED
;
566 /* Get network prefix and Area ID. */
567 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
568 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
570 ret
= ospf_network_set(ospf
, &p
, area_id
, format
);
572 vty_out(vty
, "There is already same network statement.\n");
573 return CMD_WARNING_CONFIG_FAILED
;
579 DEFUN (no_ospf_network_area
,
580 no_ospf_network_area_cmd
,
581 "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
583 "Enable routing on an IP network\n"
584 "OSPF network prefix\n"
585 "Set the OSPF area ID\n"
586 "OSPF area ID in IP address format\n"
587 "OSPF area ID as a decimal value\n")
589 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
590 int idx_ipv4_prefixlen
= 2;
591 int idx_ipv4_number
= 4;
592 struct prefix_ipv4 p
;
593 struct in_addr area_id
;
596 if (ospf
->instance
) {
598 "The network command is not supported in multi-instance ospf\n");
599 return CMD_WARNING_CONFIG_FAILED
;
602 /* Get network prefix and Area ID. */
603 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
604 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
606 ret
= ospf_network_unset(ospf
, &p
, area_id
);
609 "Can't find specified network area configuration.\n");
610 return CMD_WARNING_CONFIG_FAILED
;
616 DEFUN (ospf_area_range
,
618 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]",
619 "OSPF area parameters\n"
620 "OSPF area ID in IP address format\n"
621 "OSPF area ID as a decimal value\n"
622 "Summarize routes matching address/mask (border routers only)\n"
623 "Area range prefix\n"
624 "Advertise this range (default)\n"
625 "User specified metric for this range\n"
626 "Advertised metric for this range\n")
628 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
629 int idx_ipv4_number
= 1;
630 int idx_ipv4_prefixlen
= 3;
632 struct prefix_ipv4 p
;
633 struct in_addr area_id
;
637 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
638 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
640 ospf_area_range_set(ospf
, area_id
, &p
, OSPF_AREA_RANGE_ADVERTISE
);
641 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
644 cost
= strtoul(argv
[idx_cost
]->arg
, NULL
, 10);
645 ospf_area_range_cost_set(ospf
, area_id
, &p
, cost
);
651 DEFUN (ospf_area_range_cost
,
652 ospf_area_range_cost_cmd
,
653 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M {cost (0-16777215)|substitute A.B.C.D/M}",
654 "OSPF area parameters\n"
655 "OSPF area ID in IP address format\n"
656 "OSPF area ID as a decimal value\n"
657 "Summarize routes matching address/mask (border routers only)\n"
658 "Area range prefix\n"
659 "User specified metric for this range\n"
660 "Advertised metric for this range\n"
661 "Announce area range as another prefix\n"
662 "Network prefix to be announced instead of range\n")
664 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
665 int idx_ipv4_number
= 1;
666 int idx_ipv4_prefixlen
= 3;
668 struct prefix_ipv4 p
, s
;
669 struct in_addr area_id
;
673 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
674 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
676 ospf_area_range_set(ospf
, area_id
, &p
, OSPF_AREA_RANGE_ADVERTISE
);
677 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
680 if (argv_find(argv
, argc
, "cost", &idx
)) {
681 cost
= strtoul(argv
[idx
+ 1]->arg
, NULL
, 10);
682 ospf_area_range_cost_set(ospf
, area_id
, &p
, cost
);
686 if (argv_find(argv
, argc
, "substitute", &idx
)) {
687 str2prefix_ipv4(argv
[idx
+ 1]->arg
, &s
);
688 ospf_area_range_substitute_set(ospf
, area_id
, &p
, &s
);
694 DEFUN (ospf_area_range_not_advertise
,
695 ospf_area_range_not_advertise_cmd
,
696 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise",
697 "OSPF area parameters\n"
698 "OSPF area ID in IP address format\n"
699 "OSPF area ID as a decimal value\n"
700 "Summarize routes matching address/mask (border routers only)\n"
701 "Area range prefix\n"
702 "DoNotAdvertise this range\n")
704 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
705 int idx_ipv4_number
= 1;
706 int idx_ipv4_prefixlen
= 3;
707 struct prefix_ipv4 p
;
708 struct in_addr area_id
;
711 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
712 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
714 ospf_area_range_set(ospf
, area_id
, &p
, 0);
715 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
717 ospf_area_range_substitute_unset(ospf
, area_id
, &p
);
722 DEFUN (no_ospf_area_range
,
723 no_ospf_area_range_cmd
,
724 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]",
726 "OSPF area parameters\n"
727 "OSPF area ID in IP address format\n"
728 "OSPF area ID as a decimal value\n"
729 "Summarize routes matching address/mask (border routers only)\n"
730 "Area range prefix\n"
731 "User specified metric for this range\n"
732 "Advertised metric for this range\n"
733 "Advertise this range (default)\n"
734 "User specified metric for this range\n"
735 "Advertised metric for this range\n"
736 "DoNotAdvertise this range\n")
738 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
739 int idx_ipv4_number
= 2;
740 int idx_ipv4_prefixlen
= 4;
741 struct prefix_ipv4 p
;
742 struct in_addr area_id
;
745 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
746 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
748 ospf_area_range_unset(ospf
, area_id
, &p
);
753 DEFUN (no_ospf_area_range_substitute
,
754 no_ospf_area_range_substitute_cmd
,
755 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
757 "OSPF area parameters\n"
758 "OSPF area ID in IP address format\n"
759 "OSPF area ID as a decimal value\n"
760 "Summarize routes matching address/mask (border routers only)\n"
761 "Area range prefix\n"
762 "Announce area range as another prefix\n"
763 "Network prefix to be announced instead of range\n")
765 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
766 int idx_ipv4_number
= 2;
767 int idx_ipv4_prefixlen
= 4;
768 int idx_ipv4_prefixlen_2
= 6;
769 struct prefix_ipv4 p
, s
;
770 struct in_addr area_id
;
773 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
774 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
775 str2prefix_ipv4(argv
[idx_ipv4_prefixlen_2
]->arg
, &s
);
777 ospf_area_range_substitute_unset(ospf
, area_id
, &p
);
783 /* Command Handler Logic in VLink stuff is delicate!!
785 ALTER AT YOUR OWN RISK!!!!
787 Various dummy values are used to represent 'NoChange' state for
788 VLink configuration NOT being changed by a VLink command, and
789 special syntax is used within the command strings so that the
790 typed in command verbs can be seen in the configuration command
791 bacckend handler. This is to drastically reduce the verbeage
792 required to coe up with a reasonably compatible Cisco VLink command
794 - Matthew Grant <grantma@anathoth.gen.nz>
795 Wed, 21 Feb 2001 15:13:52 +1300
798 /* Configuration data for virtual links
800 struct ospf_vl_config_data
{
801 struct vty
*vty
; /* vty stuff */
802 struct in_addr area_id
; /* area ID from command line */
803 int area_id_fmt
; /* command line area ID format */
804 struct in_addr vl_peer
; /* command line vl_peer */
805 int auth_type
; /* Authehntication type, if given */
806 char *auth_key
; /* simple password if present */
807 int crypto_key_id
; /* Cryptographic key ID */
808 char *md5_key
; /* MD5 authentication key */
809 int hello_interval
; /* Obvious what these are... */
810 int retransmit_interval
;
815 static void ospf_vl_config_data_init(struct ospf_vl_config_data
*vl_config
,
818 memset(vl_config
, 0, sizeof(struct ospf_vl_config_data
));
819 vl_config
->auth_type
= OSPF_AUTH_CMD_NOTSEEN
;
820 vl_config
->vty
= vty
;
823 static struct ospf_vl_data
*
824 ospf_find_vl_data(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
826 struct ospf_area
*area
;
827 struct ospf_vl_data
*vl_data
;
829 struct in_addr area_id
;
831 vty
= vl_config
->vty
;
832 area_id
= vl_config
->area_id
;
834 if (area_id
.s_addr
== OSPF_AREA_BACKBONE
) {
836 "Configuring VLs over the backbone is not allowed\n");
839 area
= ospf_area_get(ospf
, area_id
);
840 ospf_area_display_format_set(ospf
, area
, vl_config
->area_id_fmt
);
842 if (area
->external_routing
!= OSPF_AREA_DEFAULT
) {
843 if (vl_config
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
844 vty_out(vty
, "Area %pI4 is %s\n", &area_id
,
845 area
->external_routing
== OSPF_AREA_NSSA
849 vty_out(vty
, "Area %ld is %s\n",
850 (unsigned long)ntohl(area_id
.s_addr
),
851 area
->external_routing
== OSPF_AREA_NSSA
857 if ((vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
->vl_peer
))
859 vl_data
= ospf_vl_data_new(area
, vl_config
->vl_peer
);
860 if (vl_data
->vl_oi
== NULL
) {
861 vl_data
->vl_oi
= ospf_vl_new(ospf
, vl_data
);
862 ospf_vl_add(ospf
, vl_data
);
863 ospf_spf_calculate_schedule(ospf
,
864 SPF_FLAG_CONFIG_CHANGE
);
871 static int ospf_vl_set_security(struct ospf_vl_data
*vl_data
,
872 struct ospf_vl_config_data
*vl_config
)
874 struct crypt_key
*ck
;
876 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
878 vty
= vl_config
->vty
;
880 if (vl_config
->auth_type
!= OSPF_AUTH_CMD_NOTSEEN
) {
881 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), auth_type
);
882 IF_DEF_PARAMS(ifp
)->auth_type
= vl_config
->auth_type
;
885 if (vl_config
->auth_key
) {
886 memset(IF_DEF_PARAMS(ifp
)->auth_simple
, 0,
887 OSPF_AUTH_SIMPLE_SIZE
+ 1);
888 strlcpy((char *)IF_DEF_PARAMS(ifp
)->auth_simple
,
890 sizeof(IF_DEF_PARAMS(ifp
)->auth_simple
));
891 } else if (vl_config
->md5_key
) {
892 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
893 vl_config
->crypto_key_id
)
895 vty_out(vty
, "OSPF: Key %d already exists\n",
896 vl_config
->crypto_key_id
);
899 ck
= ospf_crypt_key_new();
900 ck
->key_id
= vl_config
->crypto_key_id
;
901 memset(ck
->auth_key
, 0, OSPF_AUTH_MD5_SIZE
+ 1);
902 strlcpy((char *)ck
->auth_key
, vl_config
->md5_key
,
903 sizeof(ck
->auth_key
));
905 ospf_crypt_key_add(IF_DEF_PARAMS(ifp
)->auth_crypt
, ck
);
906 } else if (vl_config
->crypto_key_id
!= 0) {
909 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
910 vl_config
->crypto_key_id
)
912 vty_out(vty
, "OSPF: Key %d does not exist\n",
913 vl_config
->crypto_key_id
);
914 return CMD_WARNING_CONFIG_FAILED
;
917 ospf_crypt_key_delete(IF_DEF_PARAMS(ifp
)->auth_crypt
,
918 vl_config
->crypto_key_id
);
924 static int ospf_vl_set_timers(struct ospf_vl_data
*vl_data
,
925 struct ospf_vl_config_data
*vl_config
)
927 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
928 /* Virtual Link data initialised to defaults, so only set
930 if (vl_config
->hello_interval
) {
931 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_hello
);
932 IF_DEF_PARAMS(ifp
)->v_hello
= vl_config
->hello_interval
;
935 if (vl_config
->dead_interval
) {
936 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_wait
);
937 IF_DEF_PARAMS(ifp
)->v_wait
= vl_config
->dead_interval
;
940 if (vl_config
->retransmit_interval
) {
941 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), retransmit_interval
);
942 IF_DEF_PARAMS(ifp
)->retransmit_interval
=
943 vl_config
->retransmit_interval
;
946 if (vl_config
->transmit_delay
) {
947 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), transmit_delay
);
948 IF_DEF_PARAMS(ifp
)->transmit_delay
= vl_config
->transmit_delay
;
955 /* The business end of all of the above */
956 static int ospf_vl_set(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
958 struct ospf_vl_data
*vl_data
;
961 vl_data
= ospf_find_vl_data(ospf
, vl_config
);
963 return CMD_WARNING_CONFIG_FAILED
;
965 /* Process this one first as it can have a fatal result, which can
966 only logically occur if the virtual link exists already
967 Thus a command error does not result in a change to the
968 running configuration such as unexpectedly altered timer
970 ret
= ospf_vl_set_security(vl_data
, vl_config
);
971 if (ret
!= CMD_SUCCESS
)
974 /* Set any time based parameters, these area already range checked */
976 ret
= ospf_vl_set_timers(vl_data
, vl_config
);
977 if (ret
!= CMD_SUCCESS
)
983 /* This stuff exists to make specifying all the alias commands A LOT simpler
985 #define VLINK_HELPSTR_IPADDR \
986 "OSPF area parameters\n" \
987 "OSPF area ID in IP address format\n" \
988 "OSPF area ID as a decimal value\n" \
989 "Configure a virtual link\n" \
990 "Router ID of the remote ABR\n"
992 #define VLINK_HELPSTR_AUTHTYPE_SIMPLE \
993 "Enable authentication on this virtual link\n" \
996 #define VLINK_HELPSTR_AUTHTYPE_ALL \
997 VLINK_HELPSTR_AUTHTYPE_SIMPLE \
998 "Use null authentication\n" \
999 "Use message-digest authentication\n"
1001 #define VLINK_HELPSTR_TIME_PARAM \
1002 "Time between HELLO packets\n" \
1004 "Time between retransmitting lost link state advertisements\n" \
1006 "Link state transmit delay\n" \
1008 "Interval time after which a neighbor is declared down\n" \
1011 #define VLINK_HELPSTR_AUTH_SIMPLE \
1012 "Authentication password (key)\n" \
1013 "The OSPF password (key)\n"
1015 #define VLINK_HELPSTR_AUTH_MD5 \
1016 "Message digest authentication password (key)\n" \
1018 "Use MD5 algorithm\n" \
1019 "The OSPF password (key)\n"
1021 DEFUN (ospf_area_vlink
,
1022 ospf_area_vlink_cmd
,
1023 "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>]",
1024 VLINK_HELPSTR_IPADDR
1025 "Enable authentication on this virtual link\n"
1026 "Use message-digest authentication\n"
1027 "Use null authentication\n"
1028 VLINK_HELPSTR_AUTH_MD5
1029 VLINK_HELPSTR_AUTH_SIMPLE
)
1031 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1032 int idx_ipv4_number
= 1;
1034 struct ospf_vl_config_data vl_config
;
1035 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1036 char md5_key
[OSPF_AUTH_MD5_SIZE
+ 1];
1040 ospf_vl_config_data_init(&vl_config
, vty
);
1042 /* Read off first 2 parameters and check them */
1043 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1044 &vl_config
.area_id_fmt
);
1046 vty_out(vty
, "OSPF area ID is invalid\n");
1047 return CMD_WARNING_CONFIG_FAILED
;
1050 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1052 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1053 return CMD_WARNING_CONFIG_FAILED
;
1057 /* Thats all folks! - BUGS B. strikes again!!!*/
1059 return ospf_vl_set(ospf
, &vl_config
);
1062 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1063 /* authentication - this option can only occur
1064 at start of command line */
1065 vl_config
.auth_type
= OSPF_AUTH_SIMPLE
;
1068 if (argv_find(argv
, argc
, "message-digest", &idx
)) {
1069 /* authentication message-digest */
1070 vl_config
.auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
1071 } else if (argv_find(argv
, argc
, "null", &idx
)) {
1072 /* "authentication null" */
1073 vl_config
.auth_type
= OSPF_AUTH_NULL
;
1076 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1077 vl_config
.md5_key
= NULL
;
1078 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1079 if (vl_config
.crypto_key_id
< 0)
1080 return CMD_WARNING_CONFIG_FAILED
;
1082 strlcpy(md5_key
, argv
[idx
+ 3]->arg
, sizeof(md5_key
));
1083 vl_config
.md5_key
= md5_key
;
1086 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1087 strlcpy(auth_key
, argv
[idx
+ 1]->arg
, sizeof(auth_key
));
1088 vl_config
.auth_key
= auth_key
;
1091 /* Action configuration */
1093 return ospf_vl_set(ospf
, &vl_config
);
1096 DEFUN (no_ospf_area_vlink
,
1097 no_ospf_area_vlink_cmd
,
1098 "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>]",
1100 VLINK_HELPSTR_IPADDR
1101 "Enable authentication on this virtual link\n"
1102 "Use message-digest authentication\n"
1103 "Use null authentication\n"
1104 VLINK_HELPSTR_AUTH_MD5
1105 VLINK_HELPSTR_AUTH_SIMPLE
)
1107 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1108 int idx_ipv4_number
= 2;
1110 struct ospf_area
*area
;
1111 struct ospf_vl_config_data vl_config
;
1112 struct ospf_vl_data
*vl_data
= NULL
;
1113 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1117 ospf_vl_config_data_init(&vl_config
, vty
);
1119 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1122 vty_out(vty
, "OSPF area ID is invalid\n");
1123 return CMD_WARNING_CONFIG_FAILED
;
1126 area
= ospf_area_lookup_by_area_id(ospf
, vl_config
.area_id
);
1128 vty_out(vty
, "Area does not exist\n");
1129 return CMD_WARNING_CONFIG_FAILED
;
1132 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1134 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1135 return CMD_WARNING_CONFIG_FAILED
;
1138 vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
.vl_peer
);
1140 vty_out(vty
, "Virtual link does not exist\n");
1141 return CMD_WARNING_CONFIG_FAILED
;
1145 /* Basic VLink no command */
1146 /* Thats all folks! - BUGS B. strikes again!!!*/
1147 ospf_vl_delete(ospf
, vl_data
);
1148 ospf_area_check_free(ospf
, vl_config
.area_id
);
1152 /* If we are down here, we are reseting parameters */
1153 /* Deal with other parameters */
1155 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1156 /* authentication - this option can only occur
1157 at start of command line */
1158 vl_config
.auth_type
= OSPF_AUTH_NOTSET
;
1161 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1162 vl_config
.md5_key
= NULL
;
1163 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1164 if (vl_config
.crypto_key_id
< 0)
1165 return CMD_WARNING_CONFIG_FAILED
;
1168 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1169 /* Reset authentication-key to 0 */
1170 memset(auth_key
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
1171 vl_config
.auth_key
= auth_key
;
1174 /* Action configuration */
1176 return ospf_vl_set(ospf
, &vl_config
);
1179 DEFUN (ospf_area_vlink_intervals
,
1180 ospf_area_vlink_intervals_cmd
,
1181 "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)}",
1182 VLINK_HELPSTR_IPADDR
1183 VLINK_HELPSTR_TIME_PARAM
)
1185 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1186 struct ospf_vl_config_data vl_config
;
1189 ospf_vl_config_data_init(&vl_config
, vty
);
1191 char *area_id
= argv
[1]->arg
;
1192 char *router_id
= argv
[3]->arg
;
1194 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1196 vty_out(vty
, "OSPF area ID is invalid\n");
1197 return CMD_WARNING_CONFIG_FAILED
;
1200 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1202 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1203 return CMD_WARNING_CONFIG_FAILED
;
1206 for (int idx
= 4; idx
< argc
; idx
++) {
1207 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1208 vl_config
.hello_interval
=
1209 strtol(argv
[++idx
]->arg
, NULL
, 10);
1210 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1211 vl_config
.retransmit_interval
=
1212 strtol(argv
[++idx
]->arg
, NULL
, 10);
1213 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1214 vl_config
.transmit_delay
=
1215 strtol(argv
[++idx
]->arg
, NULL
, 10);
1216 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1217 vl_config
.dead_interval
=
1218 strtol(argv
[++idx
]->arg
, NULL
, 10);
1221 /* Action configuration */
1222 return ospf_vl_set(ospf
, &vl_config
);
1225 DEFUN (no_ospf_area_vlink_intervals
,
1226 no_ospf_area_vlink_intervals_cmd
,
1227 "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)}",
1229 VLINK_HELPSTR_IPADDR
1230 VLINK_HELPSTR_TIME_PARAM
)
1232 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1233 struct ospf_vl_config_data vl_config
;
1236 ospf_vl_config_data_init(&vl_config
, vty
);
1238 char *area_id
= argv
[2]->arg
;
1239 char *router_id
= argv
[4]->arg
;
1241 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1243 vty_out(vty
, "OSPF area ID is invalid\n");
1244 return CMD_WARNING_CONFIG_FAILED
;
1247 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1249 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1250 return CMD_WARNING_CONFIG_FAILED
;
1253 for (int idx
= 5; idx
< argc
; idx
++) {
1254 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1255 vl_config
.hello_interval
= OSPF_HELLO_INTERVAL_DEFAULT
;
1256 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1257 vl_config
.retransmit_interval
=
1258 OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
1259 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1260 vl_config
.transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
1261 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1262 vl_config
.dead_interval
=
1263 OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
1266 /* Action configuration */
1267 return ospf_vl_set(ospf
, &vl_config
);
1270 DEFUN (ospf_area_shortcut
,
1271 ospf_area_shortcut_cmd
,
1272 "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>",
1273 "OSPF area parameters\n"
1274 "OSPF area ID in IP address format\n"
1275 "OSPF area ID as a decimal value\n"
1276 "Configure the area's shortcutting mode\n"
1277 "Set default shortcutting behavior\n"
1278 "Enable shortcutting through the area\n"
1279 "Disable shortcutting through the area\n")
1281 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1282 int idx_ipv4_number
= 1;
1283 int idx_enable_disable
= 3;
1284 struct ospf_area
*area
;
1285 struct in_addr area_id
;
1289 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1290 argv
[idx_ipv4_number
]->arg
);
1292 area
= ospf_area_get(ospf
, area_id
);
1293 ospf_area_display_format_set(ospf
, area
, format
);
1295 if (strncmp(argv
[idx_enable_disable
]->arg
, "de", 2) == 0)
1296 mode
= OSPF_SHORTCUT_DEFAULT
;
1297 else if (strncmp(argv
[idx_enable_disable
]->arg
, "di", 2) == 0)
1298 mode
= OSPF_SHORTCUT_DISABLE
;
1299 else if (strncmp(argv
[idx_enable_disable
]->arg
, "e", 1) == 0)
1300 mode
= OSPF_SHORTCUT_ENABLE
;
1302 return CMD_WARNING_CONFIG_FAILED
;
1304 ospf_area_shortcut_set(ospf
, area
, mode
);
1306 if (ospf
->abr_type
!= OSPF_ABR_SHORTCUT
)
1308 "Shortcut area setting will take effect only when the router is configured as Shortcut ABR\n");
1313 DEFUN (no_ospf_area_shortcut
,
1314 no_ospf_area_shortcut_cmd
,
1315 "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>",
1317 "OSPF area parameters\n"
1318 "OSPF area ID in IP address format\n"
1319 "OSPF area ID as a decimal value\n"
1320 "Deconfigure the area's shortcutting mode\n"
1321 "Deconfigure enabled shortcutting through the area\n"
1322 "Deconfigure disabled shortcutting through the area\n")
1324 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1325 int idx_ipv4_number
= 2;
1326 struct ospf_area
*area
;
1327 struct in_addr area_id
;
1330 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1331 argv
[idx_ipv4_number
]->arg
);
1333 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1337 ospf_area_shortcut_unset(ospf
, area
);
1343 DEFUN (ospf_area_stub
,
1345 "area <A.B.C.D|(0-4294967295)> stub",
1346 "OSPF area parameters\n"
1347 "OSPF area ID in IP address format\n"
1348 "OSPF area ID as a decimal value\n"
1349 "Configure OSPF area as stub\n")
1351 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1352 int idx_ipv4_number
= 1;
1353 struct in_addr area_id
;
1356 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1357 argv
[idx_ipv4_number
]->arg
);
1359 ret
= ospf_area_stub_set(ospf
, area_id
);
1360 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1364 "First deconfigure all virtual link through this area\n");
1365 return CMD_WARNING_CONFIG_FAILED
;
1368 /* Flush the external LSAs from the specified area */
1369 ospf_flush_lsa_from_area(ospf
, area_id
, OSPF_AS_EXTERNAL_LSA
);
1370 ospf_area_no_summary_unset(ospf
, area_id
);
1375 DEFUN (ospf_area_stub_no_summary
,
1376 ospf_area_stub_no_summary_cmd
,
1377 "area <A.B.C.D|(0-4294967295)> stub no-summary",
1378 "OSPF stub parameters\n"
1379 "OSPF area ID in IP address format\n"
1380 "OSPF area ID as a decimal value\n"
1381 "Configure OSPF area as stub\n"
1382 "Do not inject inter-area routes into stub\n")
1384 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1385 int idx_ipv4_number
= 1;
1386 struct in_addr area_id
;
1389 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1390 argv
[idx_ipv4_number
]->arg
);
1392 ret
= ospf_area_stub_set(ospf
, area_id
);
1393 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1397 "%% Area cannot be stub as it contains a virtual link\n");
1398 return CMD_WARNING_CONFIG_FAILED
;
1401 ospf_area_no_summary_set(ospf
, area_id
);
1406 DEFUN (no_ospf_area_stub
,
1407 no_ospf_area_stub_cmd
,
1408 "no area <A.B.C.D|(0-4294967295)> stub",
1410 "OSPF area parameters\n"
1411 "OSPF area ID in IP address format\n"
1412 "OSPF area ID as a decimal value\n"
1413 "Configure OSPF area as stub\n")
1415 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1416 int idx_ipv4_number
= 2;
1417 struct in_addr area_id
;
1420 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1421 argv
[idx_ipv4_number
]->arg
);
1423 ospf_area_stub_unset(ospf
, area_id
);
1424 ospf_area_no_summary_unset(ospf
, area_id
);
1429 DEFUN (no_ospf_area_stub_no_summary
,
1430 no_ospf_area_stub_no_summary_cmd
,
1431 "no area <A.B.C.D|(0-4294967295)> stub no-summary",
1433 "OSPF area parameters\n"
1434 "OSPF area ID in IP address format\n"
1435 "OSPF area ID as a decimal value\n"
1436 "Configure OSPF area as stub\n"
1437 "Do not inject inter-area routes into area\n")
1439 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1440 int idx_ipv4_number
= 2;
1441 struct in_addr area_id
;
1444 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1445 argv
[idx_ipv4_number
]->arg
);
1446 ospf_area_no_summary_unset(ospf
, area_id
);
1451 static int ospf_area_nssa_cmd_handler(struct vty
*vty
, int argc
,
1452 struct cmd_token
**argv
, int cfg_nosum
,
1455 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1456 struct in_addr area_id
;
1459 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
, argv
[1]->arg
);
1461 ret
= ospf_area_nssa_set(ospf
, area_id
);
1462 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1466 "%% Area cannot be nssa as it contains a virtual link\n");
1467 return CMD_WARNING_CONFIG_FAILED
;
1471 if (strncmp(argv
[3]->text
, "translate-c", 11) == 0)
1472 ospf_area_nssa_translator_role_set(
1473 ospf
, area_id
, OSPF_NSSA_ROLE_CANDIDATE
);
1474 else if (strncmp(argv
[3]->text
, "translate-n", 11) == 0)
1475 ospf_area_nssa_translator_role_set(
1476 ospf
, area_id
, OSPF_NSSA_ROLE_NEVER
);
1477 else if (strncmp(argv
[3]->text
, "translate-a", 11) == 0)
1478 ospf_area_nssa_translator_role_set(
1479 ospf
, area_id
, OSPF_NSSA_ROLE_ALWAYS
);
1481 ospf_area_nssa_translator_role_set(ospf
, area_id
,
1482 OSPF_NSSA_ROLE_CANDIDATE
);
1487 ospf_area_no_summary_set(ospf
, area_id
);
1489 ospf_area_no_summary_unset(ospf
, area_id
);
1492 /* Flush the external LSA for the specified area */
1493 ospf_flush_lsa_from_area(ospf
, area_id
, OSPF_AS_EXTERNAL_LSA
);
1494 ospf_schedule_abr_task(ospf
);
1495 ospf_schedule_asbr_nssa_redist_update(ospf
);
1501 DEFUN (ospf_area_nssa_translate
,
1502 ospf_area_nssa_translate_cmd
,
1503 "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always>",
1504 "OSPF area parameters\n"
1505 "OSPF area ID in IP address format\n"
1506 "OSPF area ID as a decimal value\n"
1507 "Configure OSPF area as nssa\n"
1508 "Configure NSSA-ABR for translate election (default)\n"
1509 "Configure NSSA-ABR to never translate\n"
1510 "Configure NSSA-ABR to always translate\n")
1512 return ospf_area_nssa_cmd_handler(vty
, argc
, argv
, 0, 0);
1515 DEFUN (ospf_area_nssa
,
1517 "area <A.B.C.D|(0-4294967295)> nssa",
1518 "OSPF area parameters\n"
1519 "OSPF area ID in IP address format\n"
1520 "OSPF area ID as a decimal value\n"
1521 "Configure OSPF area as nssa\n")
1523 return ospf_area_nssa_cmd_handler(vty
, argc
, argv
, 0, 0);
1526 DEFUN(ospf_area_nssa_suppress_fa
, ospf_area_nssa_suppress_fa_cmd
,
1527 "area <A.B.C.D|(0-4294967295)> nssa suppress-fa",
1528 "OSPF area parameters\n"
1529 "OSPF area ID in IP address format\n"
1530 "OSPF area ID as a decimal value\n"
1531 "Configure OSPF area as nssa\n"
1532 "Suppress forwarding address\n")
1534 int idx_ipv4_number
= 1;
1535 struct in_addr area_id
;
1538 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1539 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1540 argv
[idx_ipv4_number
]->arg
);
1542 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1544 ospf_area_nssa_suppress_fa_set(ospf
, area_id
);
1546 ospf_schedule_abr_task(ospf
);
1551 DEFUN(no_ospf_area_nssa_suppress_fa
, no_ospf_area_nssa_suppress_fa_cmd
,
1552 "no area <A.B.C.D|(0-4294967295)> nssa suppress-fa",
1554 "OSPF area parameters\n"
1555 "OSPF area ID in IP address format\n"
1556 "OSPF area ID as a decimal value\n"
1557 "Configure OSPF area as nssa\n"
1558 "Suppress forwarding address\n")
1560 int idx_ipv4_number
= 2;
1561 struct in_addr area_id
;
1564 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1566 VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id
, format
,
1567 argv
[idx_ipv4_number
]->arg
);
1569 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1571 ospf_area_nssa_suppress_fa_unset(ospf
, area_id
);
1573 ospf_schedule_abr_task(ospf
);
1578 DEFUN (ospf_area_nssa_no_summary
,
1579 ospf_area_nssa_no_summary_cmd
,
1580 "area <A.B.C.D|(0-4294967295)> nssa no-summary",
1581 "OSPF area parameters\n"
1582 "OSPF area ID in IP address format\n"
1583 "OSPF area ID as a decimal value\n"
1584 "Configure OSPF area as nssa\n"
1585 "Do not inject inter-area routes into nssa\n")
1587 int idx_ipv4_number
= 1;
1588 struct in_addr area_id
;
1591 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1592 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1593 argv
[idx_ipv4_number
]->arg
);
1595 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1597 ospf_area_nssa_no_summary_set(ospf
, area_id
);
1599 ospf_schedule_abr_task(ospf
);
1604 DEFUN (no_ospf_area_nssa_no_summary
,
1605 no_ospf_area_nssa_no_summary_cmd
,
1606 "no area <A.B.C.D|(0-4294967295)> nssa no-summary",
1608 "OSPF area parameters\n"
1609 "OSPF area ID in IP address format\n"
1610 "OSPF area ID as a decimal value\n"
1611 "Configure OSPF area as nssa\n"
1612 "Do not inject inter-area routes into nssa\n")
1614 int idx_ipv4_number
= 2;
1615 struct in_addr area_id
;
1618 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1620 VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id
, format
,
1621 argv
[idx_ipv4_number
]->arg
);
1623 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1625 ospf_area_no_summary_unset(ospf
, area_id
);
1627 ospf_schedule_abr_task(ospf
);
1632 DEFUN (no_ospf_area_nssa
,
1633 no_ospf_area_nssa_cmd
,
1634 "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always>]",
1636 "OSPF area parameters\n"
1637 "OSPF area ID in IP address format\n"
1638 "OSPF area ID as a decimal value\n"
1639 "Configure OSPF area as nssa\n"
1640 "Configure NSSA-ABR for translate election (default)\n"
1641 "Configure NSSA-ABR to never translate\n"
1642 "Configure NSSA-ABR to always translate\n")
1644 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1645 int idx_ipv4_number
= 2;
1646 struct in_addr area_id
;
1649 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1650 argv
[idx_ipv4_number
]->arg
);
1652 /* Flush the NSSA LSA for the specified area */
1653 ospf_flush_lsa_from_area(ospf
, area_id
, OSPF_AS_NSSA_LSA
);
1654 ospf_area_nssa_unset(ospf
, area_id
, argc
);
1656 ospf_schedule_abr_task(ospf
);
1662 DEFUN (ospf_area_default_cost
,
1663 ospf_area_default_cost_cmd
,
1664 "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1665 "OSPF area parameters\n"
1666 "OSPF area ID in IP address format\n"
1667 "OSPF area ID as a decimal value\n"
1668 "Set the summary-default cost of a NSSA or stub area\n"
1669 "Stub's advertised default summary cost\n")
1671 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1672 int idx_ipv4_number
= 1;
1674 struct ospf_area
*area
;
1675 struct in_addr area_id
;
1678 struct prefix_ipv4 p
;
1680 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1681 argv
[idx_ipv4_number
]->arg
);
1682 cost
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1684 area
= ospf_area_get(ospf
, area_id
);
1685 ospf_area_display_format_set(ospf
, area
, format
);
1687 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1688 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1689 return CMD_WARNING_CONFIG_FAILED
;
1692 area
->default_cost
= cost
;
1695 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1697 if (IS_DEBUG_OSPF_EVENT
)
1699 "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4",
1701 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1706 DEFUN (no_ospf_area_default_cost
,
1707 no_ospf_area_default_cost_cmd
,
1708 "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1710 "OSPF area parameters\n"
1711 "OSPF area ID in IP address format\n"
1712 "OSPF area ID as a decimal value\n"
1713 "Set the summary-default cost of a NSSA or stub area\n"
1714 "Stub's advertised default summary cost\n")
1716 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1717 int idx_ipv4_number
= 2;
1718 struct ospf_area
*area
;
1719 struct in_addr area_id
;
1721 struct prefix_ipv4 p
;
1723 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1724 argv
[idx_ipv4_number
]->arg
);
1726 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1730 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1731 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1732 return CMD_WARNING_CONFIG_FAILED
;
1735 area
->default_cost
= 1;
1738 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1740 if (IS_DEBUG_OSPF_EVENT
)
1742 "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4",
1744 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1747 ospf_area_check_free(ospf
, area_id
);
1752 DEFUN (ospf_area_export_list
,
1753 ospf_area_export_list_cmd
,
1754 "area <A.B.C.D|(0-4294967295)> export-list ACCESSLIST4_NAME",
1755 "OSPF area parameters\n"
1756 "OSPF area ID in IP address format\n"
1757 "OSPF area ID as a decimal value\n"
1758 "Set the filter for networks announced to other areas\n"
1759 "Name of the access-list\n")
1761 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1762 int idx_ipv4_number
= 1;
1763 struct ospf_area
*area
;
1764 struct in_addr area_id
;
1767 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1769 area
= ospf_area_get(ospf
, area_id
);
1770 ospf_area_display_format_set(ospf
, area
, format
);
1771 ospf_area_export_list_set(ospf
, area
, argv
[3]->arg
);
1776 DEFUN (no_ospf_area_export_list
,
1777 no_ospf_area_export_list_cmd
,
1778 "no area <A.B.C.D|(0-4294967295)> export-list ACCESSLIST4_NAME",
1780 "OSPF area parameters\n"
1781 "OSPF area ID in IP address format\n"
1782 "OSPF area ID as a decimal value\n"
1783 "Unset the filter for networks announced to other areas\n"
1784 "Name of the access-list\n")
1786 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1787 int idx_ipv4_number
= 2;
1788 struct ospf_area
*area
;
1789 struct in_addr area_id
;
1792 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1794 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1798 ospf_area_export_list_unset(ospf
, area
);
1804 DEFUN (ospf_area_import_list
,
1805 ospf_area_import_list_cmd
,
1806 "area <A.B.C.D|(0-4294967295)> import-list ACCESSLIST4_NAME",
1807 "OSPF area parameters\n"
1808 "OSPF area ID in IP address format\n"
1809 "OSPF area ID as a decimal value\n"
1810 "Set the filter for networks from other areas announced to the specified one\n"
1811 "Name of the access-list\n")
1813 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1814 int idx_ipv4_number
= 1;
1815 struct ospf_area
*area
;
1816 struct in_addr area_id
;
1819 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1821 area
= ospf_area_get(ospf
, area_id
);
1822 ospf_area_display_format_set(ospf
, area
, format
);
1823 ospf_area_import_list_set(ospf
, area
, argv
[3]->arg
);
1828 DEFUN (no_ospf_area_import_list
,
1829 no_ospf_area_import_list_cmd
,
1830 "no area <A.B.C.D|(0-4294967295)> import-list ACCESSLIST4_NAME",
1832 "OSPF area parameters\n"
1833 "OSPF area ID in IP address format\n"
1834 "OSPF area ID as a decimal value\n"
1835 "Unset the filter for networks announced to other areas\n"
1836 "Name of the access-list\n")
1838 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1839 int idx_ipv4_number
= 2;
1840 struct ospf_area
*area
;
1841 struct in_addr area_id
;
1844 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1846 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1850 ospf_area_import_list_unset(ospf
, area
);
1855 DEFUN (ospf_area_filter_list
,
1856 ospf_area_filter_list_cmd
,
1857 "area <A.B.C.D|(0-4294967295)> filter-list prefix PREFIXLIST_NAME <in|out>",
1858 "OSPF area parameters\n"
1859 "OSPF area ID in IP address format\n"
1860 "OSPF area ID as a decimal value\n"
1861 "Filter networks between OSPF areas\n"
1862 "Filter prefixes between OSPF areas\n"
1863 "Name of an IP prefix-list\n"
1864 "Filter networks sent to this area\n"
1865 "Filter networks sent from this area\n")
1867 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1868 int idx_ipv4_number
= 1;
1871 struct ospf_area
*area
;
1872 struct in_addr area_id
;
1873 struct prefix_list
*plist
;
1876 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1878 area
= ospf_area_get(ospf
, area_id
);
1879 ospf_area_display_format_set(ospf
, area
, format
);
1880 plist
= prefix_list_lookup(AFI_IP
, argv
[idx_word
]->arg
);
1881 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1882 PREFIX_LIST_IN(area
) = plist
;
1883 if (PREFIX_NAME_IN(area
))
1884 free(PREFIX_NAME_IN(area
));
1886 PREFIX_NAME_IN(area
) = strdup(argv
[idx_word
]->arg
);
1887 ospf_schedule_abr_task(ospf
);
1889 PREFIX_LIST_OUT(area
) = plist
;
1890 if (PREFIX_NAME_OUT(area
))
1891 free(PREFIX_NAME_OUT(area
));
1893 PREFIX_NAME_OUT(area
) = strdup(argv
[idx_word
]->arg
);
1894 ospf_schedule_abr_task(ospf
);
1900 DEFUN (no_ospf_area_filter_list
,
1901 no_ospf_area_filter_list_cmd
,
1902 "no area <A.B.C.D|(0-4294967295)> filter-list prefix PREFIXLIST_NAME <in|out>",
1904 "OSPF area parameters\n"
1905 "OSPF area ID in IP address format\n"
1906 "OSPF area ID as a decimal value\n"
1907 "Filter networks between OSPF areas\n"
1908 "Filter prefixes between OSPF areas\n"
1909 "Name of an IP prefix-list\n"
1910 "Filter networks sent to this area\n"
1911 "Filter networks sent from this area\n")
1913 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1914 int idx_ipv4_number
= 2;
1917 struct ospf_area
*area
;
1918 struct in_addr area_id
;
1921 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1923 if ((area
= ospf_area_lookup_by_area_id(ospf
, area_id
)) == NULL
)
1926 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1927 if (PREFIX_NAME_IN(area
))
1928 if (strcmp(PREFIX_NAME_IN(area
), argv
[idx_word
]->arg
)
1932 PREFIX_LIST_IN(area
) = NULL
;
1933 if (PREFIX_NAME_IN(area
))
1934 free(PREFIX_NAME_IN(area
));
1936 PREFIX_NAME_IN(area
) = NULL
;
1938 ospf_schedule_abr_task(ospf
);
1940 if (PREFIX_NAME_OUT(area
))
1941 if (strcmp(PREFIX_NAME_OUT(area
), argv
[idx_word
]->arg
)
1945 PREFIX_LIST_OUT(area
) = NULL
;
1946 if (PREFIX_NAME_OUT(area
))
1947 free(PREFIX_NAME_OUT(area
));
1949 PREFIX_NAME_OUT(area
) = NULL
;
1951 ospf_schedule_abr_task(ospf
);
1958 DEFUN (ospf_area_authentication_message_digest
,
1959 ospf_area_authentication_message_digest_cmd
,
1960 "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest",
1962 "OSPF area parameters\n"
1963 "OSPF area ID in IP address format\n"
1964 "OSPF area ID as a decimal value\n"
1965 "Enable authentication\n"
1966 "Use message-digest authentication\n")
1968 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1970 struct ospf_area
*area
;
1971 struct in_addr area_id
;
1974 argv_find(argv
, argc
, "area", &idx
);
1975 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx
+ 1]->arg
);
1977 area
= ospf_area_get(ospf
, area_id
);
1978 ospf_area_display_format_set(ospf
, area
, format
);
1979 area
->auth_type
= strmatch(argv
[0]->text
, "no")
1981 : OSPF_AUTH_CRYPTOGRAPHIC
;
1986 DEFUN (ospf_area_authentication
,
1987 ospf_area_authentication_cmd
,
1988 "area <A.B.C.D|(0-4294967295)> authentication",
1989 "OSPF area parameters\n"
1990 "OSPF area ID in IP address format\n"
1991 "OSPF area ID as a decimal value\n"
1992 "Enable authentication\n")
1994 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1995 int idx_ipv4_number
= 1;
1996 struct ospf_area
*area
;
1997 struct in_addr area_id
;
2000 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
2002 area
= ospf_area_get(ospf
, area_id
);
2003 ospf_area_display_format_set(ospf
, area
, format
);
2004 area
->auth_type
= OSPF_AUTH_SIMPLE
;
2009 DEFUN (no_ospf_area_authentication
,
2010 no_ospf_area_authentication_cmd
,
2011 "no area <A.B.C.D|(0-4294967295)> authentication",
2013 "OSPF area parameters\n"
2014 "OSPF area ID in IP address format\n"
2015 "OSPF area ID as a decimal value\n"
2016 "Enable authentication\n")
2018 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2019 int idx_ipv4_number
= 2;
2020 struct ospf_area
*area
;
2021 struct in_addr area_id
;
2024 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
2026 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
2030 area
->auth_type
= OSPF_AUTH_NULL
;
2032 ospf_area_check_free(ospf
, area_id
);
2038 DEFUN (ospf_abr_type
,
2040 "ospf abr-type <cisco|ibm|shortcut|standard>",
2041 "OSPF specific commands\n"
2042 "Set OSPF ABR type\n"
2043 "Alternative ABR, cisco implementation\n"
2044 "Alternative ABR, IBM implementation\n"
2046 "Standard behavior (RFC2328)\n")
2048 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2050 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2052 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2053 abr_type
= OSPF_ABR_CISCO
;
2054 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2055 abr_type
= OSPF_ABR_IBM
;
2056 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2057 abr_type
= OSPF_ABR_SHORTCUT
;
2058 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2059 abr_type
= OSPF_ABR_STAND
;
2061 return CMD_WARNING_CONFIG_FAILED
;
2063 /* If ABR type value is changed, schedule ABR task. */
2064 if (ospf
->abr_type
!= abr_type
) {
2065 ospf
->abr_type
= abr_type
;
2066 ospf_schedule_abr_task(ospf
);
2072 DEFUN (no_ospf_abr_type
,
2073 no_ospf_abr_type_cmd
,
2074 "no ospf abr-type <cisco|ibm|shortcut|standard>",
2076 "OSPF specific commands\n"
2077 "Set OSPF ABR type\n"
2078 "Alternative ABR, cisco implementation\n"
2079 "Alternative ABR, IBM implementation\n"
2083 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2085 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2087 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2088 abr_type
= OSPF_ABR_CISCO
;
2089 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2090 abr_type
= OSPF_ABR_IBM
;
2091 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2092 abr_type
= OSPF_ABR_SHORTCUT
;
2093 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2094 abr_type
= OSPF_ABR_STAND
;
2096 return CMD_WARNING_CONFIG_FAILED
;
2098 /* If ABR type value is changed, schedule ABR task. */
2099 if (ospf
->abr_type
== abr_type
) {
2100 ospf
->abr_type
= OSPF_ABR_DEFAULT
;
2101 ospf_schedule_abr_task(ospf
);
2107 DEFUN (ospf_log_adjacency_changes
,
2108 ospf_log_adjacency_changes_cmd
,
2109 "log-adjacency-changes",
2110 "Log changes in adjacency state\n")
2112 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2114 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2115 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2119 DEFUN (ospf_log_adjacency_changes_detail
,
2120 ospf_log_adjacency_changes_detail_cmd
,
2121 "log-adjacency-changes detail",
2122 "Log changes in adjacency state\n"
2123 "Log all state changes\n")
2125 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2127 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2128 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2132 DEFUN (no_ospf_log_adjacency_changes
,
2133 no_ospf_log_adjacency_changes_cmd
,
2134 "no log-adjacency-changes",
2136 "Log changes in adjacency state\n")
2138 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2140 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2141 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2145 DEFUN (no_ospf_log_adjacency_changes_detail
,
2146 no_ospf_log_adjacency_changes_detail_cmd
,
2147 "no log-adjacency-changes detail",
2149 "Log changes in adjacency state\n"
2150 "Log all state changes\n")
2152 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2154 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2158 DEFUN (ospf_compatible_rfc1583
,
2159 ospf_compatible_rfc1583_cmd
,
2160 "compatible rfc1583",
2161 "OSPF compatibility list\n"
2162 "compatible with RFC 1583\n")
2164 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2166 if (!CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2167 SET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2168 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2173 DEFUN (no_ospf_compatible_rfc1583
,
2174 no_ospf_compatible_rfc1583_cmd
,
2175 "no compatible rfc1583",
2177 "OSPF compatibility list\n"
2178 "compatible with RFC 1583\n")
2180 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2182 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2183 UNSET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2184 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2189 ALIAS(ospf_compatible_rfc1583
, ospf_rfc1583_flag_cmd
,
2190 "ospf rfc1583compatibility",
2191 "OSPF specific commands\n"
2192 "Enable the RFC1583Compatibility flag\n")
2194 ALIAS(no_ospf_compatible_rfc1583
, no_ospf_rfc1583_flag_cmd
,
2195 "no ospf rfc1583compatibility", NO_STR
2196 "OSPF specific commands\n"
2197 "Disable the RFC1583Compatibility flag\n")
2199 static void ospf_table_reinstall_routes(struct ospf
*ospf
,
2200 struct route_table
*rt
)
2202 struct route_node
*rn
;
2207 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
2208 struct ospf_route
*or;
2214 if (or->type
== OSPF_DESTINATION_NETWORK
)
2215 ospf_zebra_add(ospf
, (struct prefix_ipv4
*)&rn
->p
, or);
2216 else if (or->type
== OSPF_DESTINATION_DISCARD
)
2217 ospf_zebra_add_discard(ospf
,
2218 (struct prefix_ipv4
*)&rn
->p
);
2222 static void ospf_reinstall_routes(struct ospf
*ospf
)
2224 ospf_table_reinstall_routes(ospf
, ospf
->new_table
);
2225 ospf_table_reinstall_routes(ospf
, ospf
->new_external_route
);
2228 DEFPY (ospf_send_extra_data
,
2229 ospf_send_extra_data_cmd
,
2230 "[no] ospf send-extra-data zebra",
2233 "Extra data to Zebra for display/use\n"
2236 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2238 if (no
&& CHECK_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
)) {
2239 UNSET_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
);
2240 ospf_reinstall_routes(ospf
);
2241 } else if (!CHECK_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
)) {
2242 SET_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
);
2243 ospf_reinstall_routes(ospf
);
2249 static int ospf_timers_spf_set(struct vty
*vty
, unsigned int delay
,
2250 unsigned int hold
, unsigned int max
)
2252 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2254 ospf
->spf_delay
= delay
;
2255 ospf
->spf_holdtime
= hold
;
2256 ospf
->spf_max_holdtime
= max
;
2261 DEFUN (ospf_timers_min_ls_interval
,
2262 ospf_timers_min_ls_interval_cmd
,
2263 "timers throttle lsa all (0-5000)",
2264 "Adjust routing timers\n"
2265 "Throttling adaptive timer\n"
2266 "LSA delay between transmissions\n"
2268 "Delay (msec) between sending LSAs\n")
2270 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2272 unsigned int interval
;
2275 vty_out(vty
, "Insufficient arguments\n");
2276 return CMD_WARNING_CONFIG_FAILED
;
2279 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2281 ospf
->min_ls_interval
= interval
;
2286 DEFUN (no_ospf_timers_min_ls_interval
,
2287 no_ospf_timers_min_ls_interval_cmd
,
2288 "no timers throttle lsa all [(0-5000)]",
2290 "Adjust routing timers\n"
2291 "Throttling adaptive timer\n"
2292 "LSA delay between transmissions\n"
2294 "Delay (msec) between sending LSAs\n")
2296 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2297 ospf
->min_ls_interval
= OSPF_MIN_LS_INTERVAL
;
2302 DEFUN (ospf_timers_throttle_spf
,
2303 ospf_timers_throttle_spf_cmd
,
2304 "timers throttle spf (0-600000) (0-600000) (0-600000)",
2305 "Adjust routing timers\n"
2306 "Throttling adaptive timer\n"
2308 "Delay (msec) from first change received till SPF calculation\n"
2309 "Initial hold time (msec) between consecutive SPF calculations\n"
2310 "Maximum hold time (msec)\n")
2313 int idx_number_2
= 4;
2314 int idx_number_3
= 5;
2315 unsigned int delay
, hold
, max
;
2318 vty_out(vty
, "Insufficient arguments\n");
2319 return CMD_WARNING_CONFIG_FAILED
;
2322 delay
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2323 hold
= strtoul(argv
[idx_number_2
]->arg
, NULL
, 10);
2324 max
= strtoul(argv
[idx_number_3
]->arg
, NULL
, 10);
2326 return ospf_timers_spf_set(vty
, delay
, hold
, max
);
2329 DEFUN (no_ospf_timers_throttle_spf
,
2330 no_ospf_timers_throttle_spf_cmd
,
2331 "no timers throttle spf [(0-600000)(0-600000)(0-600000)]",
2333 "Adjust routing timers\n"
2334 "Throttling adaptive timer\n"
2336 "Delay (msec) from first change received till SPF calculation\n"
2337 "Initial hold time (msec) between consecutive SPF calculations\n"
2338 "Maximum hold time (msec)\n")
2340 return ospf_timers_spf_set(vty
, OSPF_SPF_DELAY_DEFAULT
,
2341 OSPF_SPF_HOLDTIME_DEFAULT
,
2342 OSPF_SPF_MAX_HOLDTIME_DEFAULT
);
2346 DEFUN (ospf_timers_lsa_min_arrival
,
2347 ospf_timers_lsa_min_arrival_cmd
,
2348 "timers lsa min-arrival (0-600000)",
2349 "Adjust routing timers\n"
2351 "Minimum delay in receiving new version of a LSA\n"
2352 "Delay in milliseconds\n")
2354 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2355 ospf
->min_ls_arrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2359 DEFUN (no_ospf_timers_lsa_min_arrival
,
2360 no_ospf_timers_lsa_min_arrival_cmd
,
2361 "no timers lsa min-arrival [(0-600000)]",
2363 "Adjust routing timers\n"
2365 "Minimum delay in receiving new version of a LSA\n"
2366 "Delay in milliseconds\n")
2368 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2369 unsigned int minarrival
;
2372 minarrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2374 if (ospf
->min_ls_arrival
!= minarrival
2375 || minarrival
== OSPF_MIN_LS_ARRIVAL
)
2379 ospf
->min_ls_arrival
= OSPF_MIN_LS_ARRIVAL
;
2384 DEFUN (ospf_neighbor
,
2386 "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]",
2388 "Neighbor IP address\n"
2389 "Neighbor Priority\n"
2391 "Dead Neighbor Polling interval\n"
2394 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2398 struct in_addr nbr_addr
;
2399 unsigned int priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2400 unsigned int interval
= OSPF_POLL_INTERVAL_DEFAULT
;
2402 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2403 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2404 return CMD_WARNING_CONFIG_FAILED
;
2408 priority
= strtoul(argv
[idx_pri
]->arg
, NULL
, 10);
2411 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2413 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2416 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2419 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2424 DEFUN (ospf_neighbor_poll_interval
,
2425 ospf_neighbor_poll_interval_cmd
,
2426 "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2428 "Neighbor IP address\n"
2429 "Dead Neighbor Polling interval\n"
2431 "OSPF priority of non-broadcast neighbor\n"
2434 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2438 struct in_addr nbr_addr
;
2439 unsigned int priority
;
2440 unsigned int interval
;
2442 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2443 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2444 return CMD_WARNING_CONFIG_FAILED
;
2447 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2449 priority
= argc
> 4 ? strtoul(argv
[idx_pri
]->arg
, NULL
, 10)
2450 : OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2452 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2453 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2456 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2461 DEFUN (no_ospf_neighbor
,
2462 no_ospf_neighbor_cmd
,
2463 "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]",
2466 "Neighbor IP address\n"
2467 "Neighbor Priority\n"
2469 "Dead Neighbor Polling interval\n"
2472 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2474 struct in_addr nbr_addr
;
2476 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2477 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2478 return CMD_WARNING_CONFIG_FAILED
;
2481 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2486 DEFUN (no_ospf_neighbor_poll
,
2487 no_ospf_neighbor_poll_cmd
,
2488 "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2491 "Neighbor IP address\n"
2492 "Dead Neighbor Polling interval\n"
2494 "Neighbor Priority\n"
2497 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2499 struct in_addr nbr_addr
;
2501 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2502 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2503 return CMD_WARNING_CONFIG_FAILED
;
2506 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2511 DEFUN (ospf_refresh_timer
,
2512 ospf_refresh_timer_cmd
,
2513 "refresh timer (10-1800)",
2514 "Adjust refresh parameters\n"
2515 "Set refresh timer\n"
2516 "Timer value in seconds\n")
2518 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2520 unsigned int interval
;
2522 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2523 interval
= (interval
/ OSPF_LSA_REFRESHER_GRANULARITY
)
2524 * OSPF_LSA_REFRESHER_GRANULARITY
;
2526 ospf_timers_refresh_set(ospf
, interval
);
2531 DEFUN (no_ospf_refresh_timer
,
2532 no_ospf_refresh_timer_val_cmd
,
2533 "no refresh timer [(10-1800)]",
2535 "Adjust refresh parameters\n"
2536 "Unset refresh timer\n"
2537 "Timer value in seconds\n")
2539 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2541 unsigned int interval
;
2544 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2546 if (ospf
->lsa_refresh_interval
!= interval
2547 || interval
== OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
2551 ospf_timers_refresh_unset(ospf
);
2557 DEFUN (ospf_auto_cost_reference_bandwidth
,
2558 ospf_auto_cost_reference_bandwidth_cmd
,
2559 "auto-cost reference-bandwidth (1-4294967)",
2560 "Calculate OSPF interface cost according to bandwidth\n"
2561 "Use reference bandwidth method to assign OSPF cost\n"
2562 "The reference bandwidth in terms of Mbits per second\n")
2564 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2565 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2568 struct interface
*ifp
;
2570 refbw
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2571 if (refbw
< 1 || refbw
> 4294967) {
2572 vty_out(vty
, "reference-bandwidth value is invalid\n");
2573 return CMD_WARNING_CONFIG_FAILED
;
2576 /* If reference bandwidth is changed. */
2577 if ((refbw
) == ospf
->ref_bandwidth
)
2580 ospf
->ref_bandwidth
= refbw
;
2581 FOR_ALL_INTERFACES (vrf
, ifp
)
2582 ospf_if_recalculate_output_cost(ifp
);
2587 DEFUN (no_ospf_auto_cost_reference_bandwidth
,
2588 no_ospf_auto_cost_reference_bandwidth_cmd
,
2589 "no auto-cost reference-bandwidth [(1-4294967)]",
2591 "Calculate OSPF interface cost according to bandwidth\n"
2592 "Use reference bandwidth method to assign OSPF cost\n"
2593 "The reference bandwidth in terms of Mbits per second\n")
2595 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2596 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2597 struct interface
*ifp
;
2599 if (ospf
->ref_bandwidth
== OSPF_DEFAULT_REF_BANDWIDTH
)
2602 ospf
->ref_bandwidth
= OSPF_DEFAULT_REF_BANDWIDTH
;
2603 vty_out(vty
, "%% OSPF: Reference bandwidth is changed.\n");
2605 " Please ensure reference bandwidth is consistent across all routers\n");
2607 FOR_ALL_INTERFACES (vrf
, ifp
)
2608 ospf_if_recalculate_output_cost(ifp
);
2613 DEFUN (ospf_write_multiplier
,
2614 ospf_write_multiplier_cmd
,
2615 "ospf write-multiplier (1-100)",
2616 "OSPF specific commands\n"
2617 "Write multiplier\n"
2618 "Maximum number of interface serviced per write\n")
2620 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2622 uint32_t write_oi_count
;
2629 write_oi_count
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2630 if (write_oi_count
< 1 || write_oi_count
> 100) {
2631 vty_out(vty
, "write-multiplier value is invalid\n");
2632 return CMD_WARNING_CONFIG_FAILED
;
2635 ospf
->write_oi_count
= write_oi_count
;
2639 ALIAS(ospf_write_multiplier
, write_multiplier_cmd
, "write-multiplier (1-100)",
2640 "Write multiplier\n"
2641 "Maximum number of interface serviced per write\n")
2643 DEFUN (no_ospf_write_multiplier
,
2644 no_ospf_write_multiplier_cmd
,
2645 "no ospf write-multiplier (1-100)",
2647 "OSPF specific commands\n"
2648 "Write multiplier\n"
2649 "Maximum number of interface serviced per write\n")
2651 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2653 ospf
->write_oi_count
= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
;
2657 ALIAS(no_ospf_write_multiplier
, no_write_multiplier_cmd
,
2658 "no write-multiplier (1-100)", NO_STR
2659 "Write multiplier\n"
2660 "Maximum number of interface serviced per write\n")
2662 DEFUN(ospf_ti_lfa
, ospf_ti_lfa_cmd
, "fast-reroute ti-lfa [node-protection]",
2663 "Fast Reroute for MPLS and IP resilience\n"
2664 "Topology Independent LFA (Loop-Free Alternate)\n"
2665 "TI-LFA node protection (default is link protection)\n")
2667 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2669 ospf
->ti_lfa_enabled
= true;
2672 ospf
->ti_lfa_protection_type
= OSPF_TI_LFA_NODE_PROTECTION
;
2674 ospf
->ti_lfa_protection_type
= OSPF_TI_LFA_LINK_PROTECTION
;
2676 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2681 DEFUN(no_ospf_ti_lfa
, no_ospf_ti_lfa_cmd
,
2682 "no fast-reroute ti-lfa [node-protection]",
2684 "Fast Reroute for MPLS and IP resilience\n"
2685 "Topology Independent LFA (Loop-Free Alternate)\n"
2686 "TI-LFA node protection (default is link protection)\n")
2688 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2690 ospf
->ti_lfa_enabled
= false;
2692 ospf
->ti_lfa_protection_type
= OSPF_TI_LFA_UNDEFINED_PROTECTION
;
2694 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2699 static void ospf_maxpath_set(struct vty
*vty
, struct ospf
*ospf
, uint16_t paths
)
2701 if (ospf
->max_multipath
== paths
)
2704 ospf
->max_multipath
= paths
;
2706 /* Send deletion notification to zebra to delete all
2707 * ospf specific routes and reinitiat SPF to reflect
2708 * the new max multipath.
2710 ospf_restart_spf(ospf
);
2713 /* Ospf Maximum multiple paths config support */
2714 DEFUN (ospf_max_multipath
,
2715 ospf_max_multipath_cmd
,
2716 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM
),
2717 "Max no of multiple paths for ECMP support\n"
2718 "Number of paths\n")
2720 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2724 maxpaths
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2726 ospf_maxpath_set(vty
, ospf
, maxpaths
);
2730 DEFUN (no_ospf_max_multipath
,
2731 no_ospf_max_multipath_cmd
,
2734 "Max no of multiple paths for ECMP support\n")
2736 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2737 uint16_t maxpaths
= MULTIPATH_NUM
;
2739 ospf_maxpath_set(vty
, ospf
, maxpaths
);
2743 static const char *const ospf_abr_type_descr_str
[] = {
2744 "Unknown", "Standard (RFC2328)", "Alternative IBM",
2745 "Alternative Cisco", "Alternative Shortcut"
2748 static const char *const ospf_shortcut_mode_descr_str
[] = {
2749 "Default", "Enabled", "Disabled"
2752 static void show_ip_ospf_area(struct vty
*vty
, struct ospf_area
*area
,
2753 json_object
*json_areas
, bool use_json
)
2755 json_object
*json_area
= NULL
;
2756 char buf
[PREFIX_STRLEN
];
2759 json_area
= json_object_new_object();
2763 vty_out(vty
, " Area ID: %pI4", &area
->area_id
);
2765 /* Show Area type/mode. */
2766 if (OSPF_IS_AREA_BACKBONE(area
)) {
2768 json_object_boolean_true_add(json_area
, "backbone");
2770 vty_out(vty
, " (Backbone)\n");
2773 if (area
->external_routing
== OSPF_AREA_STUB
) {
2774 if (area
->no_summary
)
2775 json_object_boolean_true_add(
2776 json_area
, "stubNoSummary");
2777 if (area
->shortcut_configured
)
2778 json_object_boolean_true_add(
2779 json_area
, "stubShortcut");
2780 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
2781 if (area
->no_summary
)
2782 json_object_boolean_true_add(
2783 json_area
, "nssaNoSummary");
2784 if (area
->shortcut_configured
)
2785 json_object_boolean_true_add(
2786 json_area
, "nssaShortcut");
2789 json_object_string_add(
2790 json_area
, "shortcuttingMode",
2791 ospf_shortcut_mode_descr_str
2792 [area
->shortcut_configured
]);
2793 if (area
->shortcut_capability
)
2794 json_object_boolean_true_add(json_area
,
2797 if (area
->external_routing
== OSPF_AREA_STUB
)
2798 vty_out(vty
, " (Stub%s%s)",
2799 area
->no_summary
? ", no summary" : "",
2800 area
->shortcut_configured
? "; " : "");
2801 else if (area
->external_routing
== OSPF_AREA_NSSA
)
2802 vty_out(vty
, " (NSSA%s%s)",
2803 area
->no_summary
? ", no summary" : "",
2804 area
->shortcut_configured
? "; " : "");
2807 vty_out(vty
, " Shortcutting mode: %s",
2808 ospf_shortcut_mode_descr_str
2809 [area
->shortcut_configured
]);
2810 vty_out(vty
, ", S-bit consensus: %s\n",
2811 area
->shortcut_capability
? "ok" : "no");
2815 /* Show number of interfaces */
2817 json_object_int_add(json_area
, "areaIfTotalCounter",
2818 listcount(area
->oiflist
));
2819 json_object_int_add(json_area
, "areaIfActiveCounter",
2823 " Number of interfaces in this area: Total: %d, Active: %d\n",
2824 listcount(area
->oiflist
), area
->act_ints
);
2826 if (area
->external_routing
== OSPF_AREA_NSSA
) {
2828 json_object_boolean_true_add(json_area
, "nssa");
2829 if (!IS_OSPF_ABR(area
->ospf
))
2830 json_object_boolean_false_add(json_area
, "abr");
2831 else if (area
->NSSATranslatorState
) {
2832 json_object_boolean_true_add(json_area
, "abr");
2833 if (area
->NSSATranslatorRole
2834 == OSPF_NSSA_ROLE_CANDIDATE
)
2835 json_object_boolean_true_add(
2837 "nssaTranslatorElected");
2838 else if (area
->NSSATranslatorRole
2839 == OSPF_NSSA_ROLE_ALWAYS
)
2840 json_object_boolean_true_add(
2842 "nssaTranslatorAlways");
2844 json_object_boolean_true_add(
2846 "nssaTranslatorNever");
2848 json_object_boolean_true_add(json_area
, "abr");
2849 if (area
->NSSATranslatorRole
2850 == OSPF_NSSA_ROLE_CANDIDATE
)
2851 json_object_boolean_false_add(
2853 "nssaTranslatorElected");
2855 json_object_boolean_true_add(
2857 "nssaTranslatorNever");
2861 " It is an NSSA configuration.\n Elected NSSA/ABR performs type-7/type-5 LSA translation.\n");
2862 if (!IS_OSPF_ABR(area
->ospf
))
2864 " It is not ABR, therefore not Translator.\n");
2865 else if (area
->NSSATranslatorState
) {
2866 vty_out(vty
, " We are an ABR and ");
2867 if (area
->NSSATranslatorRole
2868 == OSPF_NSSA_ROLE_CANDIDATE
)
2870 "the NSSA Elected Translator.\n");
2871 else if (area
->NSSATranslatorRole
2872 == OSPF_NSSA_ROLE_ALWAYS
)
2874 "always an NSSA Translator.\n");
2877 "never an NSSA Translator.\n");
2879 vty_out(vty
, " We are an ABR, but ");
2880 if (area
->NSSATranslatorRole
2881 == OSPF_NSSA_ROLE_CANDIDATE
)
2883 "not the NSSA Elected Translator.\n");
2886 "never an NSSA Translator.\n");
2891 /* Stub-router state for this area */
2892 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
)) {
2893 char timebuf
[OSPF_TIME_DUMP_SIZE
];
2896 json_object_boolean_true_add(
2897 json_area
, "originStubMaxDistRouterLsa");
2898 if (CHECK_FLAG(area
->stub_router_state
,
2899 OSPF_AREA_ADMIN_STUB_ROUTED
))
2900 json_object_boolean_true_add(
2901 json_area
, "indefiniteActiveAdmin");
2902 if (area
->t_stub_router
) {
2906 &area
->t_stub_router
->u
.sands
,
2909 json_object_int_add(
2911 "activeStartupRemainderMsecs",
2916 " Originating stub / maximum-distance Router-LSA\n");
2917 if (CHECK_FLAG(area
->stub_router_state
,
2918 OSPF_AREA_ADMIN_STUB_ROUTED
))
2920 " Administratively activated (indefinitely)\n");
2921 if (area
->t_stub_router
)
2923 " Active from startup, %s remaining\n",
2924 ospf_timer_dump(area
->t_stub_router
,
2931 /* Show number of fully adjacent neighbors. */
2932 json_object_int_add(json_area
, "nbrFullAdjacentCounter",
2935 /* Show authentication type. */
2936 if (area
->auth_type
== OSPF_AUTH_NULL
)
2937 json_object_string_add(json_area
, "authentication",
2938 "authenticationNone");
2939 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2940 json_object_string_add(json_area
, "authentication",
2941 "authenticationSimplePassword");
2942 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2943 json_object_string_add(json_area
, "authentication",
2944 "authenticationMessageDigest");
2946 if (!OSPF_IS_AREA_BACKBONE(area
))
2947 json_object_int_add(json_area
,
2948 "virtualAdjacenciesPassingCounter",
2951 /* Show SPF calculation times. */
2952 json_object_int_add(json_area
, "spfExecutedCounter",
2953 area
->spf_calculation
);
2954 json_object_int_add(json_area
, "lsaNumber", area
->lsdb
->total
);
2955 json_object_int_add(
2956 json_area
, "lsaRouterNumber",
2957 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
));
2958 json_object_int_add(
2959 json_area
, "lsaRouterChecksum",
2960 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
2961 json_object_int_add(
2962 json_area
, "lsaNetworkNumber",
2963 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
));
2964 json_object_int_add(
2965 json_area
, "lsaNetworkChecksum",
2966 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
2967 json_object_int_add(
2968 json_area
, "lsaSummaryNumber",
2969 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
));
2970 json_object_int_add(
2971 json_area
, "lsaSummaryChecksum",
2972 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
2973 json_object_int_add(
2974 json_area
, "lsaAsbrNumber",
2975 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2976 json_object_int_add(
2977 json_area
, "lsaAsbrChecksum",
2978 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2979 json_object_int_add(
2980 json_area
, "lsaNssaNumber",
2981 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2982 json_object_int_add(
2983 json_area
, "lsaNssaChecksum",
2984 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2986 /* Show number of fully adjacent neighbors. */
2988 " Number of fully adjacent neighbors in this area: %d\n",
2991 /* Show authentication type. */
2992 vty_out(vty
, " Area has ");
2993 if (area
->auth_type
== OSPF_AUTH_NULL
)
2994 vty_out(vty
, "no authentication\n");
2995 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2996 vty_out(vty
, "simple password authentication\n");
2997 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2998 vty_out(vty
, "message digest authentication\n");
3000 if (!OSPF_IS_AREA_BACKBONE(area
))
3002 " Number of full virtual adjacencies going through this area: %d\n",
3005 /* Show SPF calculation times. */
3006 vty_out(vty
, " SPF algorithm executed %d times\n",
3007 area
->spf_calculation
);
3009 /* Show number of LSA. */
3010 vty_out(vty
, " Number of LSA %ld\n", area
->lsdb
->total
);
3012 " Number of router LSA %ld. Checksum Sum 0x%08x\n",
3013 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
),
3014 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
3016 " Number of network LSA %ld. Checksum Sum 0x%08x\n",
3017 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
),
3018 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
3020 " Number of summary LSA %ld. Checksum Sum 0x%08x\n",
3021 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
),
3022 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
3024 " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n",
3025 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
),
3026 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
3027 vty_out(vty
, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n",
3028 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
),
3029 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
3033 json_object_int_add(
3034 json_area
, "lsaOpaqueLinkNumber",
3035 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
3036 json_object_int_add(
3037 json_area
, "lsaOpaqueLinkChecksum",
3038 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
3039 json_object_int_add(
3040 json_area
, "lsaOpaqueAreaNumber",
3041 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
3042 json_object_int_add(
3043 json_area
, "lsaOpaqueAreaChecksum",
3044 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
3047 " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n",
3048 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
),
3049 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
3051 " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n",
3052 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
),
3053 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
3057 json_object_object_add(json_areas
,
3058 inet_ntop(AF_INET
, &area
->area_id
,
3065 static int show_ip_ospf_common(struct vty
*vty
, struct ospf
*ospf
,
3066 json_object
*json
, uint8_t use_vrf
)
3068 struct listnode
*node
, *nnode
;
3069 struct ospf_area
*area
;
3070 struct timeval result
;
3071 char timebuf
[OSPF_TIME_DUMP_SIZE
];
3072 json_object
*json_vrf
= NULL
;
3073 json_object
*json_areas
= NULL
;
3077 json_vrf
= json_object_new_object();
3080 json_areas
= json_object_new_object();
3083 if (ospf
->instance
) {
3085 json_object_int_add(json
, "ospfInstance",
3088 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
3092 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3094 /* Show Router ID. */
3096 json_object_string_addf(json_vrf
, "routerId", "%pI4",
3099 vty_out(vty
, " OSPF Routing Process, Router ID: %pI4\n",
3103 /* Graceful shutdown */
3104 if (ospf
->t_deferred_shutdown
) {
3109 &ospf
->t_deferred_shutdown
->u
.sands
,
3112 json_object_int_add(json_vrf
, "deferredShutdownMsecs",
3116 " Deferred shutdown in progress, %s remaining\n",
3117 ospf_timer_dump(ospf
->t_deferred_shutdown
,
3118 timebuf
, sizeof(timebuf
)));
3122 /* Show capability. */
3124 json_object_boolean_true_add(json_vrf
, "tosRoutesOnly");
3125 json_object_boolean_true_add(json_vrf
, "rfc2328Conform");
3126 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
3127 json_object_boolean_true_add(json_vrf
,
3128 "rfc1583Compatibility");
3131 vty_out(vty
, " Supports only single TOS (TOS0) routes\n");
3132 vty_out(vty
, " This implementation conforms to RFC2328\n");
3133 vty_out(vty
, " RFC1583Compatibility flag is %s\n",
3134 CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)
3140 if (CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)) {
3141 json_object_boolean_true_add(json_vrf
, "opaqueCapable");
3144 vty_out(vty
, " OpaqueCapability flag is %s\n",
3145 CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)
3150 /* Show stub-router configuration */
3151 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
3152 || ospf
->stub_router_shutdown_time
3153 != OSPF_STUB_ROUTER_UNCONFIGURED
) {
3155 json_object_boolean_true_add(json_vrf
,
3156 "stubAdvertisement");
3157 if (ospf
->stub_router_startup_time
3158 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3159 json_object_int_add(
3160 json_vrf
, "postStartEnabledSecs",
3161 ospf
->stub_router_startup_time
);
3162 if (ospf
->stub_router_shutdown_time
3163 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3164 json_object_int_add(
3165 json_vrf
, "preShutdownEnabledSecs",
3166 ospf
->stub_router_shutdown_time
);
3169 " Stub router advertisement is configured\n");
3170 if (ospf
->stub_router_startup_time
3171 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3173 " Enabled for %us after start-up\n",
3174 ospf
->stub_router_startup_time
);
3175 if (ospf
->stub_router_shutdown_time
3176 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3178 " Enabled for %us prior to full shutdown\n",
3179 ospf
->stub_router_shutdown_time
);
3183 /* Show SPF timers. */
3185 json_object_int_add(json_vrf
, "spfScheduleDelayMsecs",
3187 json_object_int_add(json_vrf
, "holdtimeMinMsecs",
3188 ospf
->spf_holdtime
);
3189 json_object_int_add(json_vrf
, "holdtimeMaxMsecs",
3190 ospf
->spf_max_holdtime
);
3191 json_object_int_add(json_vrf
, "holdtimeMultplier",
3192 ospf
->spf_hold_multiplier
);
3195 " Initial SPF scheduling delay %d millisec(s)\n"
3196 " Minimum hold time between consecutive SPFs %d millisec(s)\n"
3197 " Maximum hold time between consecutive SPFs %d millisec(s)\n"
3198 " Hold time multiplier is currently %d\n",
3199 ospf
->spf_delay
, ospf
->spf_holdtime
,
3200 ospf
->spf_max_holdtime
, ospf
->spf_hold_multiplier
);
3204 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3205 long time_store
= 0;
3208 monotime_since(&ospf
->ts_spf
, NULL
) / 1000LL;
3209 json_object_int_add(json_vrf
, "spfLastExecutedMsecs",
3212 time_store
= (1000 * ospf
->ts_spf_duration
.tv_sec
)
3213 + (ospf
->ts_spf_duration
.tv_usec
/ 1000);
3214 json_object_int_add(json_vrf
, "spfLastDurationMsecs",
3217 json_object_boolean_true_add(json_vrf
, "spfHasNotRun");
3219 vty_out(vty
, " SPF algorithm ");
3220 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3221 monotime_since(&ospf
->ts_spf
, &result
);
3222 vty_out(vty
, "last executed %s ago\n",
3223 ospf_timeval_dump(&result
, timebuf
,
3225 vty_out(vty
, " Last SPF duration %s\n",
3226 ospf_timeval_dump(&ospf
->ts_spf_duration
,
3227 timebuf
, sizeof(timebuf
)));
3229 vty_out(vty
, "has not been run\n");
3233 if (ospf
->t_spf_calc
) {
3236 monotime_until(&ospf
->t_spf_calc
->u
.sands
, NULL
)
3238 json_object_int_add(json_vrf
, "spfTimerDueInMsecs",
3242 json_object_int_add(json_vrf
, "lsaMinIntervalMsecs",
3243 ospf
->min_ls_interval
);
3244 json_object_int_add(json_vrf
, "lsaMinArrivalMsecs",
3245 ospf
->min_ls_arrival
);
3246 /* Show write multiplier values */
3247 json_object_int_add(json_vrf
, "writeMultiplier",
3248 ospf
->write_oi_count
);
3249 /* Show refresh parameters. */
3250 json_object_int_add(json_vrf
, "refreshTimerMsecs",
3251 ospf
->lsa_refresh_interval
* 1000);
3253 /* show max multipath */
3254 json_object_int_add(json_vrf
, "maximumPaths",
3255 ospf
->max_multipath
);
3257 /* show administrative distance */
3258 json_object_int_add(json_vrf
, "preference",
3260 ? ospf
->distance_all
3261 : ZEBRA_OSPF_DISTANCE_DEFAULT
);
3263 vty_out(vty
, " SPF timer %s%s\n",
3264 (ospf
->t_spf_calc
? "due in " : "is "),
3265 ospf_timer_dump(ospf
->t_spf_calc
, timebuf
,
3268 vty_out(vty
, " LSA minimum interval %d msecs\n",
3269 ospf
->min_ls_interval
);
3270 vty_out(vty
, " LSA minimum arrival %d msecs\n",
3271 ospf
->min_ls_arrival
);
3273 /* Show write multiplier values */
3274 vty_out(vty
, " Write Multiplier set to %d \n",
3275 ospf
->write_oi_count
);
3277 /* Show refresh parameters. */
3278 vty_out(vty
, " Refresh timer %d secs\n",
3279 ospf
->lsa_refresh_interval
);
3281 /* show max multipath */
3282 vty_out(vty
, " Maximum multiple paths(ECMP) supported %d\n",
3283 ospf
->max_multipath
);
3285 /* show administrative distance */
3286 vty_out(vty
, " Administrative distance %u\n",
3287 ospf
->distance_all
? ospf
->distance_all
3288 : ZEBRA_OSPF_DISTANCE_DEFAULT
);
3291 /* Show ABR/ASBR flags. */
3292 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ABR
)) {
3294 json_object_string_add(
3295 json_vrf
, "abrType",
3296 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3299 " This router is an ABR, ABR type is: %s\n",
3300 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3302 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ASBR
)) {
3304 json_object_string_add(
3305 json_vrf
, "asbrRouter",
3306 "injectingExternalRoutingInformation");
3309 " This router is an ASBR (injecting external routing information)\n");
3312 /* Show Number of AS-external-LSAs. */
3314 json_object_int_add(
3315 json_vrf
, "lsaExternalCounter",
3316 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3317 json_object_int_add(
3318 json_vrf
, "lsaExternalChecksum",
3319 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3322 " Number of external LSA %ld. Checksum Sum 0x%08x\n",
3323 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
),
3324 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3328 json_object_int_add(
3329 json_vrf
, "lsaAsopaqueCounter",
3330 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3331 json_object_int_add(
3332 json_vrf
, "lsaAsOpaqueChecksum",
3333 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3336 " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n",
3337 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
),
3338 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3341 /* Show number of areas attached. */
3343 json_object_int_add(json_vrf
, "attachedAreaCounter",
3344 listcount(ospf
->areas
));
3346 vty_out(vty
, " Number of areas attached to this router: %d\n",
3347 listcount(ospf
->areas
));
3349 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
3350 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
)) {
3352 json_object_boolean_true_add(
3353 json_vrf
, "adjacencyChangesLoggedAll");
3356 " All adjacency changes are logged\n");
3359 json_object_boolean_true_add(
3360 json_vrf
, "adjacencyChangesLogged");
3362 vty_out(vty
, " Adjacency changes are logged\n");
3366 /* show LDP-Sync status */
3367 ospf_ldp_sync_show_info(vty
, ospf
, json_vrf
, json
? 1 : 0);
3369 /* Show each area status. */
3370 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
3371 show_ip_ospf_area(vty
, area
, json_areas
, json
? 1 : 0);
3375 json_object_object_add(json_vrf
, "areas", json_areas
);
3376 json_object_object_add(json
, ospf_get_name(ospf
),
3379 json_object_object_add(json
, "areas", json_areas
);
3387 DEFUN (show_ip_ospf
,
3389 "show ip ospf [vrf <NAME|all>] [json]",
3392 "OSPF information\n"
3398 bool uj
= use_json(argc
, argv
);
3399 struct listnode
*node
= NULL
;
3400 char *vrf_name
= NULL
;
3401 bool all_vrf
= false;
3402 int ret
= CMD_SUCCESS
;
3405 json_object
*json
= NULL
;
3406 uint8_t use_vrf
= 0;
3408 if (listcount(om
->ospf
) == 0)
3411 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
3414 json
= json_object_new_object();
3416 /* vrf input is provided could be all or specific vrf*/
3418 bool ospf_output
= false;
3423 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
3424 if (!ospf
->oi_running
)
3427 ret
= show_ip_ospf_common(vty
, ospf
, json
,
3431 vty_json(vty
, json
);
3432 else if (!ospf_output
)
3433 vty_out(vty
, "%% OSPF is not enabled\n");
3436 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
3437 if ((ospf
== NULL
) || !ospf
->oi_running
) {
3439 vty_json(vty
, json
);
3442 "%% OSPF is not enabled in vrf %s\n",
3448 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
3449 /* Display default ospf (instance 0) info */
3450 if (ospf
== NULL
|| !ospf
->oi_running
) {
3452 vty_json(vty
, json
);
3455 "%% OSPF is not enabled in vrf default\n");
3462 show_ip_ospf_common(vty
, ospf
, json
, use_vrf
);
3464 vty_out(vty
, "%s\n",
3465 json_object_to_json_string_ext(
3466 json
, JSON_C_TO_STRING_PRETTY
));
3470 json_object_free(json
);
3475 DEFUN (show_ip_ospf_instance
,
3476 show_ip_ospf_instance_cmd
,
3477 "show ip ospf (1-65535) [json]",
3480 "OSPF information\n"
3486 unsigned short instance
= 0;
3487 bool uj
= use_json(argc
, argv
);
3488 int ret
= CMD_SUCCESS
;
3489 json_object
*json
= NULL
;
3491 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
3492 if (instance
!= ospf_instance
)
3493 return CMD_NOT_MY_INSTANCE
;
3495 ospf
= ospf_lookup_instance(instance
);
3496 if (!ospf
|| !ospf
->oi_running
)
3500 json
= json_object_new_object();
3502 ret
= show_ip_ospf_common(vty
, ospf
, json
, 0);
3505 vty_json(vty
, json
);
3510 static void ospf_interface_auth_show(struct vty
*vty
, struct ospf_interface
*oi
,
3511 json_object
*json
, bool use_json
)
3515 auth_type
= OSPF_IF_PARAM(oi
, auth_type
);
3517 switch (auth_type
) {
3518 case OSPF_AUTH_NULL
:
3520 json_object_string_add(json
, "authentication",
3521 "authenticationNone");
3523 vty_out(vty
, " Authentication NULL is enabled\n");
3525 case OSPF_AUTH_SIMPLE
: {
3527 json_object_string_add(json
, "authentication",
3528 "authenticationSimplePassword");
3531 " Simple password authentication enabled\n");
3534 case OSPF_AUTH_CRYPTOGRAPHIC
: {
3535 struct crypt_key
*ckey
;
3537 if (list_isempty(OSPF_IF_PARAM(oi
, auth_crypt
)))
3540 ckey
= listgetdata(listtail(OSPF_IF_PARAM(oi
, auth_crypt
)));
3543 json_object_string_add(json
, "authentication",
3544 "authenticationMessageDigest");
3547 " Cryptographic authentication enabled\n");
3548 vty_out(vty
, " Algorithm:MD5\n");
3558 static void show_ip_ospf_interface_sub(struct vty
*vty
, struct ospf
*ospf
,
3559 struct interface
*ifp
,
3560 json_object
*json_interface_sub
,
3564 struct ospf_neighbor
*nbr
;
3565 struct route_node
*rn
;
3566 uint32_t bandwidth
= ifp
->bandwidth
? ifp
->bandwidth
: ifp
->speed
;
3568 /* Is interface up? */
3570 is_up
= if_is_operative(ifp
);
3572 json_object_boolean_true_add(json_interface_sub
,
3575 json_object_boolean_false_add(json_interface_sub
,
3578 json_object_int_add(json_interface_sub
, "ifIndex",
3580 json_object_int_add(json_interface_sub
, "mtuBytes", ifp
->mtu
);
3581 json_object_int_add(json_interface_sub
, "bandwidthMbit",
3583 json_object_string_add(json_interface_sub
, "ifFlags",
3584 if_flag_dump(ifp
->flags
));
3586 vty_out(vty
, "%s is %s\n", ifp
->name
,
3587 ((is_up
= if_is_operative(ifp
)) ? "up" : "down"));
3588 vty_out(vty
, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n",
3589 ifp
->ifindex
, ifp
->mtu
, bandwidth
,
3590 if_flag_dump(ifp
->flags
));
3593 /* Is interface OSPF enabled? */
3595 if (ospf_oi_count(ifp
) == 0) {
3596 json_object_boolean_false_add(json_interface_sub
,
3599 } else if (!is_up
) {
3600 json_object_boolean_false_add(json_interface_sub
,
3604 json_object_boolean_true_add(json_interface_sub
,
3607 if (ospf_oi_count(ifp
) == 0) {
3608 vty_out(vty
, " OSPF not enabled on this interface\n");
3610 } else if (!is_up
) {
3612 " OSPF is enabled, but not running on this interface\n");
3617 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
3618 struct ospf_interface
*oi
= rn
->info
;
3623 if (CHECK_FLAG(oi
->connected
->flags
, ZEBRA_IFA_UNNUMBERED
)) {
3625 json_object_boolean_true_add(json_interface_sub
,
3628 vty_out(vty
, " This interface is UNNUMBERED,");
3630 struct in_addr dest
;
3633 /* Show OSPF interface information. */
3635 json_object_string_addf(
3636 json_interface_sub
, "ipAddress", "%pI4",
3637 &oi
->address
->u
.prefix4
);
3638 json_object_int_add(json_interface_sub
,
3639 "ipAddressPrefixlen",
3640 oi
->address
->prefixlen
);
3642 vty_out(vty
, " Internet Address %pFX,",
3645 /* For Vlinks, showing the peer address is
3646 * probably more informative than the local
3647 * interface that is being used */
3648 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
) {
3650 dest
= oi
->vl_data
->peer_addr
;
3651 } else if (CONNECTED_PEER(oi
->connected
)
3652 && oi
->connected
->destination
) {
3654 dest
= oi
->connected
->destination
->u
.prefix4
;
3657 dest
.s_addr
= ipv4_broadcast_addr(
3658 oi
->connected
->address
->u
.prefix4
.s_addr
,
3659 oi
->connected
->address
->prefixlen
);
3663 json_object_string_add(
3665 "ospfIfType", dstr
);
3666 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3667 json_object_string_addf(
3668 json_interface_sub
, "vlinkPeer",
3671 json_object_string_addf(
3673 "localIfUsed", "%pI4", &dest
);
3675 vty_out(vty
, " %s %pI4,", dstr
,
3679 json_object_string_add(json_interface_sub
, "area",
3680 ospf_area_desc_string(oi
->area
));
3681 if (OSPF_IF_PARAM(oi
, mtu_ignore
))
3682 json_object_boolean_true_add(
3684 "mtuMismatchDetect");
3685 json_object_string_addf(json_interface_sub
, "routerId",
3686 "%pI4", &ospf
->router_id
);
3687 json_object_string_add(json_interface_sub
,
3689 ospf_network_type_str
[oi
->type
]);
3690 json_object_int_add(json_interface_sub
, "cost",
3692 json_object_int_add(
3693 json_interface_sub
, "transmitDelaySecs",
3694 OSPF_IF_PARAM(oi
, transmit_delay
));
3695 json_object_string_add(json_interface_sub
, "state",
3696 lookup_msg(ospf_ism_state_msg
,
3698 json_object_int_add(json_interface_sub
, "priority",
3701 vty_out(vty
, " Area %s\n",
3702 ospf_area_desc_string(oi
->area
));
3704 vty_out(vty
, " MTU mismatch detection: %s\n",
3705 OSPF_IF_PARAM(oi
, mtu_ignore
) ? "disabled"
3709 " Router ID %pI4, Network Type %s, Cost: %d\n",
3711 ospf_network_type_str
[oi
->type
],
3715 " Transmit Delay is %d sec, State %s, Priority %d\n",
3716 OSPF_IF_PARAM(oi
, transmit_delay
),
3717 lookup_msg(ospf_ism_state_msg
, oi
->state
, NULL
),
3721 /* Show DR information. */
3722 if (DR(oi
).s_addr
== INADDR_ANY
) {
3725 " No backup designated router on this network\n");
3727 nbr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &DR(oi
));
3730 json_object_string_addf(
3731 json_interface_sub
, "drId",
3732 "%pI4", &nbr
->router_id
);
3733 json_object_string_addf(
3734 json_interface_sub
, "drAddress",
3736 &nbr
->address
.u
.prefix4
);
3739 " Designated Router (ID) %pI4",
3742 " Interface Address %pFX\n",
3748 nbr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &BDR(oi
));
3752 " No backup designated router on this network\n");
3755 json_object_string_addf(
3756 json_interface_sub
, "bdrId",
3757 "%pI4", &nbr
->router_id
);
3758 json_object_string_addf(
3760 "bdrAddress", "%pI4",
3761 &nbr
->address
.u
.prefix4
);
3764 " Backup Designated Router (ID) %pI4,",
3766 vty_out(vty
, " Interface Address %pI4\n",
3767 &nbr
->address
.u
.prefix4
);
3772 /* Next network-LSA sequence number we'll use, if we're elected
3775 && ntohl(oi
->params
->network_lsa_seqnum
)
3776 != OSPF_INITIAL_SEQUENCE_NUMBER
) {
3778 json_object_int_add(
3780 "networkLsaSequence",
3781 ntohl(oi
->params
->network_lsa_seqnum
));
3784 " Saved Network-LSA sequence number 0x%x\n",
3785 ntohl(oi
->params
->network_lsa_seqnum
));
3789 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3790 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3791 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3792 json_object_boolean_true_add(
3794 "mcastMemberOspfAllRouters");
3795 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3796 json_object_boolean_true_add(
3798 "mcastMemberOspfDesignatedRouters");
3801 vty_out(vty
, " Multicast group memberships:");
3802 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3803 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3804 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3805 vty_out(vty
, " OSPFAllRouters");
3806 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3807 vty_out(vty
, " OSPFDesignatedRouters");
3809 vty_out(vty
, " <None>");
3814 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3815 json_object_int_add(
3816 json_interface_sub
, "timerMsecs",
3817 OSPF_IF_PARAM(oi
, v_hello
) * 1000);
3819 json_object_int_add(
3820 json_interface_sub
, "timerMsecs",
3821 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3822 json_object_int_add(json_interface_sub
,
3824 OSPF_IF_PARAM(oi
, v_wait
));
3825 json_object_int_add(json_interface_sub
,
3827 OSPF_IF_PARAM(oi
, v_wait
));
3828 json_object_int_add(
3829 json_interface_sub
, "timerRetransmitSecs",
3830 OSPF_IF_PARAM(oi
, retransmit_interval
));
3832 vty_out(vty
, " Timer intervals configured,");
3833 vty_out(vty
, " Hello ");
3834 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3835 vty_out(vty
, "%ds,",
3836 OSPF_IF_PARAM(oi
, v_hello
));
3838 vty_out(vty
, "%dms,",
3839 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3840 vty_out(vty
, " Dead %ds, Wait %ds, Retransmit %d\n",
3841 OSPF_IF_PARAM(oi
, v_wait
),
3842 OSPF_IF_PARAM(oi
, v_wait
),
3843 OSPF_IF_PARAM(oi
, retransmit_interval
));
3846 if (OSPF_IF_PASSIVE_STATUS(oi
) == OSPF_IF_ACTIVE
) {
3847 char timebuf
[OSPF_TIME_DUMP_SIZE
];
3849 long time_store
= 0;
3853 &oi
->t_hello
->u
.sands
,
3856 json_object_int_add(json_interface_sub
,
3857 "timerHelloInMsecs",
3860 vty_out(vty
, " Hello due in %s\n",
3861 ospf_timer_dump(oi
->t_hello
, timebuf
,
3863 } else /* passive-interface is set */
3866 json_object_boolean_true_add(
3868 "timerPassiveIface");
3871 " No Hellos (Passive interface)\n");
3875 json_object_int_add(json_interface_sub
, "nbrCount",
3876 ospf_nbr_count(oi
, 0));
3877 json_object_int_add(json_interface_sub
,
3879 ospf_nbr_count(oi
, NSM_Full
));
3882 " Neighbor Count is %d, Adjacent neighbor count is %d\n",
3883 ospf_nbr_count(oi
, 0),
3884 ospf_nbr_count(oi
, NSM_Full
));
3886 ospf_interface_bfd_show(vty
, ifp
, json_interface_sub
);
3888 /* OSPF Authentication information */
3889 ospf_interface_auth_show(vty
, oi
, json_interface_sub
, use_json
);
3893 static int show_ip_ospf_interface_common(struct vty
*vty
, struct ospf
*ospf
,
3894 char *intf_name
, uint8_t use_vrf
,
3895 json_object
*json
, bool use_json
)
3897 struct interface
*ifp
;
3898 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
3899 json_object
*json_vrf
= NULL
;
3900 json_object
*json_interface_sub
= NULL
, *json_interface
= NULL
;
3904 json_vrf
= json_object_new_object();
3907 json_interface
= json_object_new_object();
3910 if (ospf
->instance
) {
3912 json_object_int_add(json
, "ospfInstance",
3915 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
3918 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3920 if (intf_name
== NULL
) {
3921 /* Show All Interfaces.*/
3922 FOR_ALL_INTERFACES (vrf
, ifp
) {
3923 if (ospf_oi_count(ifp
)) {
3925 json_interface_sub
=
3926 json_object_new_object();
3928 show_ip_ospf_interface_sub(vty
, ospf
, ifp
,
3933 json_object_object_add(
3934 json_interface
, ifp
->name
,
3935 json_interface_sub
);
3940 json_object_object_add(json_vrf
, "interfaces",
3943 /* Interface name is specified. */
3944 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
3947 json_object_boolean_true_add(json_vrf
,
3950 vty_out(vty
, "No such interface name\n");
3953 json_interface_sub
= json_object_new_object();
3954 json_interface
= json_object_new_object();
3957 show_ip_ospf_interface_sub(
3958 vty
, ospf
, ifp
, json_interface_sub
, use_json
);
3961 json_object_object_add(json_interface
,
3963 json_interface_sub
);
3964 json_object_object_add(json_vrf
, "interfaces",
3972 json_object_object_add(json
, ospf_get_name(ospf
),
3981 static void show_ip_ospf_interface_traffic_sub(struct vty
*vty
,
3982 struct ospf_interface
*oi
,
3983 json_object
*json_interface_sub
,
3987 json_object_int_add(json_interface_sub
, "ifIndex",
3989 json_object_int_add(json_interface_sub
, "helloIn",
3991 json_object_int_add(json_interface_sub
, "helloOut",
3993 json_object_int_add(json_interface_sub
, "dbDescIn",
3995 json_object_int_add(json_interface_sub
, "dbDescOut",
3997 json_object_int_add(json_interface_sub
, "lsReqIn",
3999 json_object_int_add(json_interface_sub
, "lsReqOut",
4001 json_object_int_add(json_interface_sub
, "lsUpdIn",
4003 json_object_int_add(json_interface_sub
, "lsUpdOut",
4005 json_object_int_add(json_interface_sub
, "lsAckIn",
4007 json_object_int_add(json_interface_sub
, "lsAckOut",
4009 json_object_int_add(json_interface_sub
, "packetsQueued",
4010 listcount(oi
->obuf
));
4013 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u %12lu\n",
4014 oi
->ifp
->name
, oi
->hello_in
, oi
->hello_out
,
4015 oi
->db_desc_in
, oi
->db_desc_out
, oi
->ls_req_in
,
4016 oi
->ls_req_out
, oi
->ls_upd_in
, oi
->ls_upd_out
,
4017 oi
->ls_ack_in
, oi
->ls_ack_out
, listcount(oi
->obuf
));
4021 /* OSPFv2 Packet Counters */
4022 static int show_ip_ospf_interface_traffic_common(
4023 struct vty
*vty
, struct ospf
*ospf
, char *intf_name
, json_object
*json
,
4024 int display_once
, uint8_t use_vrf
, bool use_json
)
4026 struct vrf
*vrf
= NULL
;
4027 struct interface
*ifp
= NULL
;
4028 json_object
*json_vrf
= NULL
;
4029 json_object
*json_interface_sub
= NULL
;
4031 if (!use_json
&& !display_once
) {
4033 vty_out(vty
, "%-12s%-17s%-17s%-17s%-17s%-17s%-17s\n",
4034 "Interface", " HELLO", " DB-Desc", " LS-Req",
4035 " LS-Update", " LS-Ack", " Packets");
4036 vty_out(vty
, "%-10s%-18s%-18s%-17s%-17s%-17s%-17s\n", "",
4037 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
4038 " Rx/Tx", " Queued");
4040 "-------------------------------------------------------------------------------------------------------------\n");
4041 } else if (use_json
) {
4043 json_vrf
= json_object_new_object();
4048 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4050 if (intf_name
== NULL
) {
4051 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
4052 FOR_ALL_INTERFACES (vrf
, ifp
) {
4053 struct route_node
*rn
;
4054 struct ospf_interface
*oi
;
4056 if (ospf_oi_count(ifp
) == 0)
4059 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
4060 rn
= route_next(rn
)) {
4067 json_interface_sub
=
4068 json_object_new_object();
4071 show_ip_ospf_interface_traffic_sub(
4072 vty
, oi
, json_interface_sub
, use_json
);
4074 json_object_object_add(
4075 json_vrf
, ifp
->name
,
4076 json_interface_sub
);
4081 /* Interface name is specified. */
4082 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
4084 struct route_node
*rn
;
4085 struct ospf_interface
*oi
;
4087 if (ospf_oi_count(ifp
) == 0) {
4089 " OSPF not enabled on this interface %s\n",
4094 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
4095 rn
= route_next(rn
)) {
4099 json_interface_sub
=
4100 json_object_new_object();
4103 show_ip_ospf_interface_traffic_sub(
4104 vty
, oi
, json_interface_sub
, use_json
);
4106 json_object_object_add(
4107 json_vrf
, ifp
->name
,
4108 json_interface_sub
);
4116 json_object_object_add(json
, ospf_get_name(ospf
),
4124 DEFUN (show_ip_ospf_interface
,
4125 show_ip_ospf_interface_cmd
,
4126 "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]",
4129 "OSPF information\n"
4132 "Interface information\n"
4137 bool uj
= use_json(argc
, argv
);
4138 struct listnode
*node
= NULL
;
4139 char *vrf_name
= NULL
, *intf_name
= NULL
;
4140 bool all_vrf
= false;
4141 int ret
= CMD_SUCCESS
;
4143 int idx_vrf
= 0, idx_intf
= 0;
4144 uint8_t use_vrf
= 0;
4145 json_object
*json
= NULL
;
4147 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4149 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4150 intf_name
= argv
[idx_intf
]->arg
;
4153 json
= json_object_new_object();
4155 /* vrf input is provided could be all or specific vrf*/
4159 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4160 if (!ospf
->oi_running
)
4162 ret
= show_ip_ospf_interface_common(
4163 vty
, ospf
, intf_name
, use_vrf
, json
,
4168 vty_json(vty
, json
);
4170 vty_out(vty
, "%% OSPF is not enabled\n");
4174 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4175 if (ospf
== NULL
|| !ospf
->oi_running
) {
4177 vty_json(vty
, json
);
4180 "%% OSPF is not enabled in vrf %s\n",
4185 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
4189 /* Display default ospf (instance 0) info */
4190 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4191 if (ospf
== NULL
|| !ospf
->oi_running
) {
4193 vty_json(vty
, json
);
4196 "%% OSPF is not enabled in vrf default\n");
4200 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
4205 vty_json(vty
, json
);
4210 DEFUN (show_ip_ospf_instance_interface
,
4211 show_ip_ospf_instance_interface_cmd
,
4212 "show ip ospf (1-65535) interface [INTERFACE] [json]",
4215 "OSPF information\n"
4217 "Interface information\n"
4224 unsigned short instance
= 0;
4225 bool uj
= use_json(argc
, argv
);
4226 char *intf_name
= NULL
;
4227 int ret
= CMD_SUCCESS
;
4228 json_object
*json
= NULL
;
4230 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4231 if (instance
!= ospf_instance
)
4232 return CMD_NOT_MY_INSTANCE
;
4234 ospf
= ospf_lookup_instance(instance
);
4235 if (!ospf
|| !ospf
->oi_running
)
4239 json
= json_object_new_object();
4241 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4242 intf_name
= argv
[idx_intf
]->arg
;
4244 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
, 0, json
, uj
);
4247 vty_json(vty
, json
);
4252 DEFUN (show_ip_ospf_interface_traffic
,
4253 show_ip_ospf_interface_traffic_cmd
,
4254 "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]",
4257 "OSPF information\n"
4260 "Interface information\n"
4261 "Protocol Packet counters\n"
4265 struct ospf
*ospf
= NULL
;
4266 struct listnode
*node
= NULL
;
4267 char *vrf_name
= NULL
, *intf_name
= NULL
;
4268 bool all_vrf
= false;
4270 int idx_vrf
= 0, idx_intf
= 0;
4271 bool uj
= use_json(argc
, argv
);
4272 json_object
*json
= NULL
;
4273 int ret
= CMD_SUCCESS
;
4274 int display_once
= 0;
4275 uint8_t use_vrf
= 0;
4277 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4279 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4280 intf_name
= argv
[idx_intf
]->arg
;
4283 json
= json_object_new_object();
4288 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4289 if (!ospf
->oi_running
)
4292 ret
= show_ip_ospf_interface_traffic_common(
4293 vty
, ospf
, intf_name
, json
,
4294 display_once
, use_vrf
, uj
);
4299 vty_json(vty
, json
);
4303 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4304 if (ospf
== NULL
|| !ospf
->oi_running
) {
4306 json_object_free(json
);
4310 ret
= show_ip_ospf_interface_traffic_common(
4311 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4313 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4314 if (ospf
== NULL
|| !ospf
->oi_running
) {
4316 json_object_free(json
);
4320 ret
= show_ip_ospf_interface_traffic_common(
4321 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4325 vty_json(vty
, json
);
4331 static void show_ip_ospf_neighbour_header(struct vty
*vty
)
4333 vty_out(vty
, "\n%-15s %-3s %-15s %-15s %-9s %-15s %-32s %5s %5s %5s\n",
4334 "Neighbor ID", "Pri", "State", "Up Time", "Dead Time",
4335 "Address", "Interface", "RXmtL", "RqstL", "DBsmL");
4338 static void show_ip_ospf_neighbour_brief(struct vty
*vty
,
4339 struct ospf_neighbor
*nbr
,
4340 struct ospf_neighbor
*prev_nbr
,
4341 json_object
*json
, bool use_json
)
4344 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4345 json_object
*json_neighbor
= NULL
, *json_neigh_array
= NULL
;
4346 struct timeval res
= {.tv_sec
= 0, .tv_usec
= 0};
4348 char uptime
[OSPF_TIME_DUMP_SIZE
];
4350 if (nbr
->ts_last_progress
.tv_sec
|| nbr
->ts_last_progress
.tv_usec
)
4352 monotime_since(&nbr
->ts_last_progress
, &res
) / 1000LL;
4355 char neigh_str
[INET_ADDRSTRLEN
];
4357 if (prev_nbr
&& !IPV4_ADDR_SAME(&prev_nbr
->src
, &nbr
->src
)) {
4358 /* Start new neigh list */
4359 json_neigh_array
= NULL
;
4362 if (nbr
->state
== NSM_Attempt
&&
4363 nbr
->router_id
.s_addr
== INADDR_ANY
)
4364 strlcpy(neigh_str
, "neighbor", sizeof(neigh_str
));
4366 inet_ntop(AF_INET
, &nbr
->router_id
, neigh_str
,
4369 json_object_object_get_ex(json
, neigh_str
, &json_neigh_array
);
4371 if (!json_neigh_array
) {
4372 json_neigh_array
= json_object_new_array();
4373 json_object_object_add(json
, neigh_str
,
4377 json_neighbor
= json_object_new_object();
4379 ospf_nbr_ism_state_message(nbr
, msgbuf
, sizeof(msgbuf
));
4380 #if CONFDATE > 20230321
4382 "Remove show_ip_ospf_neighbor_sub() JSON keys: priority, state, deadTimeMsecs, address, retransmitCounter, requestCounter, dbSummaryCounter")
4384 json_object_int_add(json_neighbor
, "priority", nbr
->priority
);
4385 json_object_string_add(json_neighbor
, "state", msgbuf
);
4386 json_object_int_add(json_neighbor
, "nbrPriority",
4388 json_object_string_add(json_neighbor
, "nbrState", msgbuf
);
4390 json_object_string_add(
4391 json_neighbor
, "converged",
4392 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
4393 json_object_string_add(json_neighbor
, "role",
4394 lookup_msg(ospf_ism_state_msg
,
4395 ospf_nbr_ism_state(nbr
),
4397 if (nbr
->t_inactivity
) {
4400 time_store
= monotime_until(&nbr
->t_inactivity
->u
.sands
,
4403 json_object_int_add(json_neighbor
, "upTimeInMsec",
4405 json_object_int_add(json_neighbor
, "deadTimeMsecs",
4407 json_object_int_add(json_neighbor
,
4408 "routerDeadIntervalTimerDueMsec",
4410 json_object_string_add(
4411 json_neighbor
, "upTime",
4412 ospf_timeval_dump(&res
, uptime
,
4414 json_object_string_add(
4415 json_neighbor
, "deadTime",
4416 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
4419 json_object_string_add(json_neighbor
, "deadTimeMsecs",
4421 json_object_string_add(json_neighbor
,
4422 "routerDeadIntervalTimerDueMsec",
4425 json_object_string_addf(json_neighbor
, "address", "%pI4",
4427 json_object_string_addf(json_neighbor
, "ifaceAddress", "%pI4",
4429 json_object_string_add(json_neighbor
, "ifaceName",
4431 json_object_int_add(json_neighbor
, "retransmitCounter",
4432 ospf_ls_retransmit_count(nbr
));
4433 json_object_int_add(json_neighbor
,
4434 "linkStateRetransmissionListCounter",
4435 ospf_ls_retransmit_count(nbr
));
4436 json_object_int_add(json_neighbor
, "requestCounter",
4437 ospf_ls_request_count(nbr
));
4438 json_object_int_add(json_neighbor
,
4439 "linkStateRequestListCounter",
4440 ospf_ls_request_count(nbr
));
4441 json_object_int_add(json_neighbor
, "dbSummaryCounter",
4442 ospf_db_summary_count(nbr
));
4443 json_object_int_add(json_neighbor
, "databaseSummaryListCounter",
4444 ospf_db_summary_count(nbr
));
4446 json_object_array_add(json_neigh_array
, json_neighbor
);
4448 ospf_nbr_ism_state_message(nbr
, msgbuf
, sizeof(msgbuf
));
4450 if (nbr
->state
== NSM_Attempt
&&
4451 nbr
->router_id
.s_addr
== INADDR_ANY
)
4452 vty_out(vty
, "%-15s %3d %-15s ", "-", nbr
->priority
,
4455 vty_out(vty
, "%-15pI4 %3d %-15s ", &nbr
->router_id
,
4456 nbr
->priority
, msgbuf
);
4458 vty_out(vty
, "%-15s ",
4459 ospf_timeval_dump(&res
, uptime
, sizeof(uptime
)));
4461 vty_out(vty
, "%9s ",
4462 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
4464 vty_out(vty
, "%-15pI4 ", &nbr
->src
);
4465 vty_out(vty
, "%-32s %5ld %5ld %5d\n", IF_NAME(nbr
->oi
),
4466 ospf_ls_retransmit_count(nbr
),
4467 ospf_ls_request_count(nbr
), ospf_db_summary_count(nbr
));
4471 static void show_ip_ospf_neighbor_sub(struct vty
*vty
,
4472 struct ospf_interface
*oi
,
4473 json_object
*json
, bool use_json
)
4475 struct route_node
*rn
;
4476 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
4478 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
4484 /* Do not show myself. */
4485 if (nbr
== oi
->nbr_self
)
4487 /* Down state is not shown. */
4488 if (nbr
->state
== NSM_Down
)
4493 show_ip_ospf_neighbour_brief(vty
, nbr
, prev_nbr
, json
,
4498 static int show_ip_ospf_neighbor_common(struct vty
*vty
, struct ospf
*ospf
,
4499 json_object
*json
, bool use_json
,
4502 struct ospf_interface
*oi
;
4503 struct listnode
*node
;
4504 json_object
*json_vrf
= NULL
;
4505 json_object
*json_nbr_sub
= NULL
;
4509 json_vrf
= json_object_new_object();
4512 json_nbr_sub
= json_object_new_object();
4515 if (ospf
->instance
) {
4517 json_object_int_add(json
, "ospfInstance",
4520 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4523 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4525 show_ip_ospf_neighbour_header(vty
);
4527 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4528 if (ospf_interface_neighbor_count(oi
) == 0)
4530 show_ip_ospf_neighbor_sub(vty
, oi
, json_nbr_sub
, use_json
);
4534 json_object_object_add(json_vrf
, "neighbors", json_nbr_sub
);
4536 json_object_object_add(json
, ospf_get_name(ospf
),
4544 DEFUN (show_ip_ospf_neighbor
,
4545 show_ip_ospf_neighbor_cmd
,
4546 "show ip ospf [vrf <NAME|all>] neighbor [json]",
4549 "OSPF information\n"
4556 bool uj
= use_json(argc
, argv
);
4557 struct listnode
*node
= NULL
;
4558 char *vrf_name
= NULL
;
4559 bool all_vrf
= false;
4560 int ret
= CMD_SUCCESS
;
4563 uint8_t use_vrf
= 0;
4564 json_object
*json
= NULL
;
4566 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4569 json
= json_object_new_object();
4571 /* vrf input is provided could be all or specific vrf*/
4575 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4576 if (!ospf
->oi_running
)
4578 ret
= show_ip_ospf_neighbor_common(
4579 vty
, ospf
, json
, uj
, use_vrf
);
4583 vty_json(vty
, json
);
4585 vty_out(vty
, "OSPF is not enabled\n");
4590 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4591 if (ospf
== NULL
|| !ospf
->oi_running
) {
4593 vty_json(vty
, json
);
4596 "%% OSPF is not enabled in vrf %s\n",
4602 /* Display default ospf (instance 0) info */
4603 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4604 if (ospf
== NULL
|| !ospf
->oi_running
) {
4606 vty_json(vty
, json
);
4609 "%% OSPF is not enabled in vrf default\n");
4616 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
,
4620 vty_out(vty
, "%s\n",
4621 json_object_to_json_string_ext(
4622 json
, JSON_C_TO_STRING_PRETTY
));
4627 json_object_free(json
);
4633 DEFUN (show_ip_ospf_instance_neighbor
,
4634 show_ip_ospf_instance_neighbor_cmd
,
4635 "show ip ospf (1-65535) neighbor [json]",
4638 "OSPF information\n"
4645 unsigned short instance
= 0;
4646 bool uj
= use_json(argc
, argv
);
4647 json_object
*json
= NULL
;
4648 int ret
= CMD_SUCCESS
;
4650 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4651 if (instance
!= ospf_instance
)
4652 return CMD_NOT_MY_INSTANCE
;
4654 ospf
= ospf_lookup_instance(instance
);
4655 if (!ospf
|| !ospf
->oi_running
)
4659 json
= json_object_new_object();
4661 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
, 0);
4664 vty_json(vty
, json
);
4669 static int show_ip_ospf_neighbor_all_common(struct vty
*vty
, struct ospf
*ospf
,
4670 json_object
*json
, bool use_json
,
4673 struct listnode
*node
;
4674 struct ospf_interface
*oi
;
4675 char buf
[PREFIX_STRLEN
];
4676 json_object
*json_vrf
= NULL
;
4677 json_object
*json_neighbor_sub
= NULL
;
4681 json_vrf
= json_object_new_object();
4686 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4688 show_ip_ospf_neighbour_header(vty
);
4690 if (ospf
->instance
) {
4692 json_object_int_add(json_vrf
, "ospfInstance",
4695 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4698 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4699 struct listnode
*nbr_node
;
4700 struct ospf_nbr_nbma
*nbr_nbma
;
4702 show_ip_ospf_neighbor_sub(vty
, oi
, json_vrf
, use_json
);
4704 /* print Down neighbor status */
4705 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nbr_node
, nbr_nbma
)) {
4706 if (nbr_nbma
->nbr
== NULL
4707 || nbr_nbma
->nbr
->state
== NSM_Down
) {
4710 json_object_new_object();
4711 json_object_int_add(json_neighbor_sub
,
4713 nbr_nbma
->priority
);
4714 json_object_boolean_true_add(
4717 json_object_string_add(
4721 json_object_int_add(
4723 "nbrNbmaRetransmitCounter", 0);
4724 json_object_int_add(
4726 "nbrNbmaRequestCounter", 0);
4727 json_object_int_add(
4729 "nbrNbmaDbSummaryCounter", 0);
4730 json_object_object_add(
4733 &nbr_nbma
->addr
, buf
,
4737 vty_out(vty
, "%-15s %3d %-15s %9s ",
4738 "-", nbr_nbma
->priority
, "Down",
4741 "%-32pI4 %-20s %5d %5d %5d\n",
4743 IF_NAME(oi
), 0, 0, 0);
4751 json_object_object_add(json
, ospf_get_name(ospf
),
4759 DEFUN (show_ip_ospf_neighbor_all
,
4760 show_ip_ospf_neighbor_all_cmd
,
4761 "show ip ospf [vrf <NAME|all>] neighbor all [json]",
4764 "OSPF information\n"
4768 "include down status neighbor\n"
4772 bool uj
= use_json(argc
, argv
);
4773 struct listnode
*node
= NULL
;
4774 char *vrf_name
= NULL
;
4775 bool all_vrf
= false;
4776 int ret
= CMD_SUCCESS
;
4779 uint8_t use_vrf
= 0;
4780 json_object
*json
= NULL
;
4782 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4785 json
= json_object_new_object();
4787 /* vrf input is provided could be all or specific vrf*/
4791 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4792 if (!ospf
->oi_running
)
4794 ret
= show_ip_ospf_neighbor_all_common(
4795 vty
, ospf
, json
, uj
, use_vrf
);
4799 vty_json(vty
, json
);
4804 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4805 if (ospf
== NULL
|| !ospf
->oi_running
) {
4807 json_object_free(json
);
4811 /* Display default ospf (instance 0) info */
4812 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4813 if (ospf
== NULL
|| !ospf
->oi_running
) {
4815 json_object_free(json
);
4821 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
,
4824 vty_out(vty
, "%s\n",
4825 json_object_to_json_string_ext(
4826 json
, JSON_C_TO_STRING_PRETTY
));
4831 json_object_free(json
);
4836 DEFUN (show_ip_ospf_instance_neighbor_all
,
4837 show_ip_ospf_instance_neighbor_all_cmd
,
4838 "show ip ospf (1-65535) neighbor all [json]",
4841 "OSPF information\n"
4844 "include down status neighbor\n"
4849 unsigned short instance
= 0;
4850 bool uj
= use_json(argc
, argv
);
4851 json_object
*json
= NULL
;
4852 int ret
= CMD_SUCCESS
;
4854 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4855 if (instance
!= ospf_instance
)
4856 return CMD_NOT_MY_INSTANCE
;
4858 ospf
= ospf_lookup_instance(instance
);
4859 if (!ospf
|| !ospf
->oi_running
)
4862 json
= json_object_new_object();
4864 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
, 0);
4867 vty_json(vty
, json
);
4872 static int show_ip_ospf_neighbor_int_common(struct vty
*vty
, struct ospf
*ospf
,
4874 struct cmd_token
**argv
,
4875 bool use_json
, uint8_t use_vrf
)
4877 struct interface
*ifp
;
4878 struct route_node
*rn
;
4879 json_object
*json
= NULL
;
4882 json
= json_object_new_object();
4884 if (ospf
->instance
) {
4886 json_object_int_add(json
, "ospfInstance",
4889 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4892 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
4894 ifp
= if_lookup_by_name(argv
[arg_base
]->arg
, ospf
->vrf_id
);
4897 json_object_boolean_true_add(json
, "noSuchIface");
4899 vty_out(vty
, "No such interface.\n");
4903 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
4904 struct ospf_interface
*oi
= rn
->info
;
4909 show_ip_ospf_neighbor_sub(vty
, oi
, json
, use_json
);
4913 vty_json(vty
, json
);
4920 DEFUN (show_ip_ospf_neighbor_int
,
4921 show_ip_ospf_neighbor_int_cmd
,
4922 "show ip ospf [vrf <NAME>] neighbor IFNAME [json]",
4925 "OSPF information\n"
4934 bool uj
= use_json(argc
, argv
);
4935 int ret
= CMD_SUCCESS
;
4936 struct interface
*ifp
= NULL
;
4937 char *vrf_name
= NULL
;
4938 vrf_id_t vrf_id
= VRF_DEFAULT
;
4939 struct vrf
*vrf
= NULL
;
4941 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
4942 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
4943 if (vrf_name
&& strmatch(vrf_name
, VRF_DEFAULT_NAME
))
4946 vrf
= vrf_lookup_by_name(vrf_name
);
4948 vrf_id
= vrf
->vrf_id
;
4950 ospf
= ospf_lookup_by_vrf_id(vrf_id
);
4952 if (!ospf
|| !ospf
->oi_running
)
4956 show_ip_ospf_neighbour_header(vty
);
4958 argv_find(argv
, argc
, "IFNAME", &idx_ifname
);
4960 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf_id
);
4964 ret
= show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
,
4969 DEFUN (show_ip_ospf_instance_neighbor_int
,
4970 show_ip_ospf_instance_neighbor_int_cmd
,
4971 "show ip ospf (1-65535) neighbor IFNAME [json]",
4974 "OSPF information\n"
4983 unsigned short instance
= 0;
4984 bool uj
= use_json(argc
, argv
);
4987 show_ip_ospf_neighbour_header(vty
);
4989 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4990 if (instance
!= ospf_instance
)
4991 return CMD_NOT_MY_INSTANCE
;
4993 ospf
= ospf_lookup_instance(instance
);
4994 if (!ospf
|| !ospf
->oi_running
)
4998 show_ip_ospf_neighbour_header(vty
);
5000 return show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
, argv
, uj
,
5004 static void show_ip_ospf_nbr_nbma_detail_sub(struct vty
*vty
,
5005 struct ospf_interface
*oi
,
5006 struct ospf_nbr_nbma
*nbr_nbma
,
5007 bool use_json
, json_object
*json
)
5009 char timebuf
[OSPF_TIME_DUMP_SIZE
];
5010 json_object
*json_sub
= NULL
;
5013 json_sub
= json_object_new_object();
5014 else /* Show neighbor ID. */
5015 vty_out(vty
, " Neighbor %s,", "-");
5017 /* Show interface address. */
5019 json_object_string_addf(json_sub
, "ifaceAddress", "%pI4",
5022 vty_out(vty
, " interface address %pI4\n",
5027 json_object_string_add(json_sub
, "areaId",
5028 ospf_area_desc_string(oi
->area
));
5029 json_object_string_add(json_sub
, "iface", IF_NAME(oi
));
5031 vty_out(vty
, " In the area %s via interface %s\n",
5032 ospf_area_desc_string(oi
->area
), IF_NAME(oi
));
5034 /* Show neighbor priority and state. */
5036 json_object_int_add(json_sub
, "nbrPriority",
5037 nbr_nbma
->priority
);
5038 json_object_string_add(json_sub
, "nbrState", "down");
5040 vty_out(vty
, " Neighbor priority is %d, State is %s,",
5041 nbr_nbma
->priority
, "Down");
5043 /* Show state changes. */
5045 json_object_int_add(json_sub
, "stateChangeCounter",
5046 nbr_nbma
->state_change
);
5048 vty_out(vty
, " %d state changes\n", nbr_nbma
->state_change
);
5050 /* Show PollInterval */
5052 json_object_int_add(json_sub
, "pollInterval", nbr_nbma
->v_poll
);
5054 vty_out(vty
, " Poll interval %d\n", nbr_nbma
->v_poll
);
5056 /* Show poll-interval timer. */
5057 if (nbr_nbma
->t_poll
) {
5060 time_store
= monotime_until(&nbr_nbma
->t_poll
->u
.sands
,
5062 json_object_int_add(json_sub
,
5063 "pollIntervalTimerDueMsec",
5066 vty_out(vty
, " Poll timer due in %s\n",
5067 ospf_timer_dump(nbr_nbma
->t_poll
, timebuf
,
5071 /* Show poll-interval timer thread. */
5073 if (nbr_nbma
->t_poll
!= NULL
)
5074 json_object_string_add(json_sub
,
5075 "pollIntervalTimerThread", "on");
5077 vty_out(vty
, " Thread Poll Timer %s\n",
5078 nbr_nbma
->t_poll
!= NULL
? "on" : "off");
5081 json_object_object_add(json
, "noNbrId", json_sub
);
5084 static void show_ip_ospf_neighbor_detail_sub(struct vty
*vty
,
5085 struct ospf_interface
*oi
,
5086 struct ospf_neighbor
*nbr
,
5087 struct ospf_neighbor
*prev_nbr
,
5088 json_object
*json
, bool use_json
)
5090 char timebuf
[OSPF_TIME_DUMP_SIZE
];
5091 json_object
*json_neigh
= NULL
, *json_neigh_array
= NULL
;
5092 char neigh_str
[INET_ADDRSTRLEN
] = {0};
5093 char neigh_state
[16] = {0};
5097 !IPV4_ADDR_SAME(&prev_nbr
->src
, &nbr
->src
)) {
5098 json_neigh_array
= NULL
;
5101 if (nbr
->state
== NSM_Attempt
5102 && nbr
->router_id
.s_addr
== INADDR_ANY
)
5103 strlcpy(neigh_str
, "noNbrId", sizeof(neigh_str
));
5105 inet_ntop(AF_INET
, &nbr
->router_id
,
5106 neigh_str
, sizeof(neigh_str
));
5108 json_object_object_get_ex(json
, neigh_str
, &json_neigh_array
);
5110 if (!json_neigh_array
) {
5111 json_neigh_array
= json_object_new_array();
5112 json_object_object_add(json
, neigh_str
,
5116 json_neigh
= json_object_new_object();
5119 /* Show neighbor ID. */
5120 if (nbr
->state
== NSM_Attempt
5121 && nbr
->router_id
.s_addr
== INADDR_ANY
)
5122 vty_out(vty
, " Neighbor %s,", "-");
5124 vty_out(vty
, " Neighbor %pI4,",
5128 /* Show interface address. */
5130 json_object_string_addf(json_neigh
, "ifaceAddress", "%pI4",
5131 &nbr
->address
.u
.prefix4
);
5133 vty_out(vty
, " interface address %pI4\n",
5134 &nbr
->address
.u
.prefix4
);
5138 json_object_string_add(json_neigh
, "areaId",
5139 ospf_area_desc_string(oi
->area
));
5140 json_object_string_add(json_neigh
, "ifaceName", oi
->ifp
->name
);
5142 vty_out(vty
, " In the area %s via interface %s\n",
5143 ospf_area_desc_string(oi
->area
), oi
->ifp
->name
);
5145 /* Show neighbor priority and state. */
5146 ospf_nbr_ism_state_message(nbr
, neigh_state
, sizeof(neigh_state
));
5148 json_object_int_add(json_neigh
, "nbrPriority", nbr
->priority
);
5149 json_object_string_add(json_neigh
, "nbrState", neigh_state
);
5151 vty_out(vty
, " Neighbor priority is %d, State is %s,",
5152 nbr
->priority
, neigh_state
);
5154 /* Show state changes. */
5156 json_object_int_add(json_neigh
, "stateChangeCounter",
5159 vty_out(vty
, " %d state changes\n", nbr
->state_change
);
5161 if (nbr
->ts_last_progress
.tv_sec
|| nbr
->ts_last_progress
.tv_usec
) {
5166 monotime_since(&nbr
->ts_last_progress
, &res
) / 1000LL;
5168 json_object_int_add(json_neigh
, "lastPrgrsvChangeMsec",
5172 " Most recent state change statistics:\n");
5173 vty_out(vty
, " Progressive change %s ago\n",
5174 ospf_timeval_dump(&res
, timebuf
,
5179 if (nbr
->ts_last_regress
.tv_sec
|| nbr
->ts_last_regress
.tv_usec
) {
5184 monotime_since(&nbr
->ts_last_regress
, &res
) / 1000LL;
5186 json_object_int_add(json_neigh
,
5187 "lastRegressiveChangeMsec",
5189 if (nbr
->last_regress_str
)
5190 json_object_string_add(
5192 "lastRegressiveChangeReason",
5193 nbr
->last_regress_str
);
5196 " Regressive change %s ago, due to %s\n",
5197 ospf_timeval_dump(&res
, timebuf
,
5199 (nbr
->last_regress_str
? nbr
->last_regress_str
5204 /* Show Designated Rotuer ID. */
5206 json_object_string_addf(json_neigh
, "routerDesignatedId",
5207 "%pI4", &nbr
->d_router
);
5209 vty_out(vty
, " DR is %pI4,", &nbr
->d_router
);
5211 /* Show Backup Designated Rotuer ID. */
5213 json_object_string_addf(json_neigh
, "routerDesignatedBackupId",
5214 "%pI4", &nbr
->bd_router
);
5216 vty_out(vty
, " BDR is %pI4\n", &nbr
->bd_router
);
5220 json_object_int_add(json_neigh
, "optionsCounter", nbr
->options
);
5221 json_object_string_add(json_neigh
, "optionsList",
5222 ospf_options_dump(nbr
->options
));
5224 vty_out(vty
, " Options %d %s\n", nbr
->options
,
5225 ospf_options_dump(nbr
->options
));
5227 /* Show Router Dead interval timer. */
5229 if (nbr
->t_inactivity
) {
5231 time_store
= monotime_until(&nbr
->t_inactivity
->u
.sands
,
5234 json_object_int_add(json_neigh
,
5235 "routerDeadIntervalTimerDueMsec",
5238 json_object_int_add(
5240 "routerDeadIntervalTimerDueMsec", -1);
5242 vty_out(vty
, " Dead timer due in %s\n",
5243 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
5246 /* Show Database Summary list. */
5248 json_object_int_add(json_neigh
, "databaseSummaryListCounter",
5249 ospf_db_summary_count(nbr
));
5251 vty_out(vty
, " Database Summary List %d\n",
5252 ospf_db_summary_count(nbr
));
5254 /* Show Link State Request list. */
5256 json_object_int_add(json_neigh
, "linkStateRequestListCounter",
5257 ospf_ls_request_count(nbr
));
5259 vty_out(vty
, " Link State Request List %ld\n",
5260 ospf_ls_request_count(nbr
));
5262 /* Show Link State Retransmission list. */
5264 json_object_int_add(json_neigh
,
5265 "linkStateRetransmissionListCounter",
5266 ospf_ls_retransmit_count(nbr
));
5268 vty_out(vty
, " Link State Retransmission List %ld\n",
5269 ospf_ls_retransmit_count(nbr
));
5271 /* Show inactivity timer thread. */
5273 if (nbr
->t_inactivity
!= NULL
)
5274 json_object_string_add(json_neigh
,
5275 "threadInactivityTimer", "on");
5277 vty_out(vty
, " Thread Inactivity Timer %s\n",
5278 nbr
->t_inactivity
!= NULL
? "on" : "off");
5280 /* Show Database Description retransmission thread. */
5282 if (nbr
->t_db_desc
!= NULL
)
5283 json_object_string_add(
5285 "threadDatabaseDescriptionRetransmission",
5289 " Thread Database Description Retransmision %s\n",
5290 nbr
->t_db_desc
!= NULL
? "on" : "off");
5292 /* Show Link State Request Retransmission thread. */
5294 if (nbr
->t_ls_req
!= NULL
)
5295 json_object_string_add(
5297 "threadLinkStateRequestRetransmission", "on");
5300 " Thread Link State Request Retransmission %s\n",
5301 nbr
->t_ls_req
!= NULL
? "on" : "off");
5303 /* Show Link State Update Retransmission thread. */
5305 if (nbr
->t_ls_upd
!= NULL
)
5306 json_object_string_add(
5308 "threadLinkStateUpdateRetransmission",
5312 " Thread Link State Update Retransmission %s\n\n",
5313 nbr
->t_ls_upd
!= NULL
? "on" : "off");
5316 vty_out(vty
, " Graceful restart Helper info:\n");
5318 if (OSPF_GR_IS_ACTIVE_HELPER(nbr
)) {
5320 " Graceful Restart HELPER Status : Inprogress.\n");
5323 " Graceful Restart grace period time: %d (seconds).\n",
5324 nbr
->gr_helper_info
.recvd_grace_period
);
5325 vty_out(vty
, " Graceful Restart reason: %s.\n",
5326 ospf_restart_reason2str(
5327 nbr
->gr_helper_info
.gr_restart_reason
));
5330 " Graceful Restart HELPER Status : None\n");
5333 if (nbr
->gr_helper_info
.rejected_reason
5334 != OSPF_HELPER_REJECTED_NONE
)
5335 vty_out(vty
, " Helper rejected reason: %s.\n",
5336 ospf_rejected_reason2str(
5337 nbr
->gr_helper_info
.rejected_reason
));
5339 if (nbr
->gr_helper_info
.helper_exit_reason
5340 != OSPF_GR_HELPER_EXIT_NONE
)
5341 vty_out(vty
, " Last helper exit reason: %s.\n\n",
5342 ospf_exit_reason2str(
5343 nbr
->gr_helper_info
.helper_exit_reason
));
5347 json_object_string_add(json_neigh
, "grHelperStatus",
5348 OSPF_GR_IS_ACTIVE_HELPER(nbr
) ?
5351 if (OSPF_GR_IS_ACTIVE_HELPER(nbr
)) {
5352 json_object_int_add(
5353 json_neigh
, "graceInterval",
5354 nbr
->gr_helper_info
.recvd_grace_period
);
5355 json_object_string_add(
5356 json_neigh
, "grRestartReason",
5357 ospf_restart_reason2str(
5358 nbr
->gr_helper_info
.gr_restart_reason
));
5361 if (nbr
->gr_helper_info
.rejected_reason
5362 != OSPF_HELPER_REJECTED_NONE
)
5363 json_object_string_add(
5364 json_neigh
, "helperRejectReason",
5365 ospf_rejected_reason2str(
5366 nbr
->gr_helper_info
.rejected_reason
));
5368 if (nbr
->gr_helper_info
.helper_exit_reason
5369 != OSPF_GR_HELPER_EXIT_NONE
)
5370 json_object_string_add(
5371 json_neigh
, "helperExitReason",
5372 ospf_exit_reason2str(
5374 .helper_exit_reason
));
5377 bfd_sess_show(vty
, json_neigh
, nbr
->bfd_session
);
5380 json_object_array_add(json_neigh_array
, json_neigh
);
5384 static int show_ip_ospf_neighbor_id_common(struct vty
*vty
, struct ospf
*ospf
,
5385 struct in_addr
*router_id
,
5386 bool use_json
, uint8_t use_vrf
,
5389 struct listnode
*node
;
5390 struct ospf_neighbor
*nbr
;
5391 struct ospf_interface
*oi
;
5392 json_object
*json
= NULL
;
5395 json
= json_object_new_object();
5397 if (ospf
->instance
) {
5399 json_object_int_add(json
, "ospfInstance",
5402 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5405 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
5407 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5408 nbr
= ospf_nbr_lookup_by_routerid(oi
->nbrs
, router_id
);
5414 show_ip_ospf_neighbor_detail_sub(vty
, oi
, nbr
, NULL
,
5417 show_ip_ospf_neighbour_brief(vty
, nbr
, NULL
, json
,
5422 vty_json(vty
, json
);
5429 DEFPY(show_ip_ospf_neighbor_id
, show_ip_ospf_neighbor_id_cmd
,
5430 "show ip ospf neighbor A.B.C.D$router_id [detail$detail] [json$json]",
5432 "OSPF information\n"
5435 "Detailed output\n" JSON_STR
)
5438 struct listnode
*node
;
5439 int ret
= CMD_SUCCESS
;
5441 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5442 if (!ospf
->oi_running
)
5444 ret
= show_ip_ospf_neighbor_id_common(vty
, ospf
, &router_id
,
5445 !!json
, 0, !!detail
);
5451 DEFPY(show_ip_ospf_instance_neighbor_id
, show_ip_ospf_instance_neighbor_id_cmd
,
5452 "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [detail$detail] [json$json]",
5454 "OSPF information\n"
5458 "Detailed output\n" JSON_STR
)
5462 if (instance
!= ospf_instance
)
5463 return CMD_NOT_MY_INSTANCE
;
5465 ospf
= ospf_lookup_instance(instance
);
5466 if (!ospf
|| !ospf
->oi_running
)
5469 return show_ip_ospf_neighbor_id_common(vty
, ospf
, &router_id
, !!json
, 0,
5473 static int show_ip_ospf_neighbor_detail_common(struct vty
*vty
,
5475 json_object
*json
, bool use_json
,
5478 struct ospf_interface
*oi
;
5479 struct listnode
*node
;
5480 json_object
*json_vrf
= NULL
;
5481 json_object
*json_nbr_sub
= NULL
;
5485 json_vrf
= json_object_new_object();
5489 json_nbr_sub
= json_object_new_object();
5492 if (ospf
->instance
) {
5494 json_object_int_add(json
, "ospfInstance",
5497 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5500 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5502 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5503 struct route_node
*rn
;
5504 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
5506 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5512 if (nbr
!= oi
->nbr_self
) {
5513 if (nbr
->state
!= NSM_Down
) {
5514 show_ip_ospf_neighbor_detail_sub(
5515 vty
, oi
, nbr
, prev_nbr
,
5516 json_nbr_sub
, use_json
);
5524 json_object_object_add(json_vrf
, "neighbors",
5527 json_object_object_add(json
, ospf_get_name(ospf
),
5535 DEFUN (show_ip_ospf_neighbor_detail
,
5536 show_ip_ospf_neighbor_detail_cmd
,
5537 "show ip ospf [vrf <NAME|all>] neighbor detail [json]",
5540 "OSPF information\n"
5544 "detail of all neighbors\n"
5548 bool uj
= use_json(argc
, argv
);
5549 struct listnode
*node
= NULL
;
5550 char *vrf_name
= NULL
;
5551 bool all_vrf
= false;
5552 int ret
= CMD_SUCCESS
;
5555 uint8_t use_vrf
= 0;
5556 json_object
*json
= NULL
;
5558 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5561 json
= json_object_new_object();
5563 /* vrf input is provided could be all or specific vrf*/
5567 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5568 if (!ospf
->oi_running
)
5570 ret
= show_ip_ospf_neighbor_detail_common(
5571 vty
, ospf
, json
, uj
, use_vrf
);
5574 vty_json(vty
, json
);
5578 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5579 if (ospf
== NULL
|| !ospf
->oi_running
) {
5581 json_object_free(json
);
5585 /* Display default ospf (instance 0) info */
5586 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5587 if (ospf
== NULL
|| !ospf
->oi_running
) {
5589 json_object_free(json
);
5595 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
,
5598 vty_out(vty
, "%s\n",
5599 json_object_to_json_string_ext(
5600 json
, JSON_C_TO_STRING_PRETTY
));
5605 json_object_free(json
);
5610 DEFUN (show_ip_ospf_instance_neighbor_detail
,
5611 show_ip_ospf_instance_neighbor_detail_cmd
,
5612 "show ip ospf (1-65535) neighbor detail [json]",
5615 "OSPF information\n"
5618 "detail of all neighbors\n"
5623 unsigned short instance
= 0;
5624 bool uj
= use_json(argc
, argv
);
5625 json_object
*json
= NULL
;
5626 int ret
= CMD_SUCCESS
;
5628 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5629 if (instance
!= ospf_instance
)
5630 return CMD_NOT_MY_INSTANCE
;
5632 ospf
= ospf_lookup_instance(instance
);
5633 if (!ospf
|| !ospf
->oi_running
)
5637 json
= json_object_new_object();
5639 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
, 0);
5642 vty_json(vty
, json
);
5647 static int show_ip_ospf_neighbor_detail_all_common(struct vty
*vty
,
5653 struct listnode
*node
;
5654 struct ospf_interface
*oi
;
5655 json_object
*json_vrf
= NULL
;
5659 json_vrf
= json_object_new_object();
5664 if (ospf
->instance
) {
5666 json_object_int_add(json
, "ospfInstance",
5669 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5672 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5674 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5675 struct route_node
*rn
;
5676 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
5677 struct ospf_nbr_nbma
*nbr_nbma
;
5679 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5685 if (nbr
!= oi
->nbr_self
)
5686 if (nbr
->state
!= NSM_Down
)
5687 show_ip_ospf_neighbor_detail_sub(
5688 vty
, oi
, rn
->info
, prev_nbr
,
5689 json_vrf
, use_json
);
5693 if (oi
->type
!= OSPF_IFTYPE_NBMA
)
5696 struct listnode
*nd
;
5698 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nd
, nbr_nbma
)) {
5699 if (nbr_nbma
->nbr
== NULL
||
5700 nbr_nbma
->nbr
->state
== NSM_Down
)
5701 show_ip_ospf_nbr_nbma_detail_sub(
5702 vty
, oi
, nbr_nbma
, use_json
, json_vrf
);
5708 json_object_object_add(json
, ospf_get_name(ospf
),
5717 DEFUN (show_ip_ospf_neighbor_detail_all
,
5718 show_ip_ospf_neighbor_detail_all_cmd
,
5719 "show ip ospf [vrf <NAME|all>] neighbor detail all [json]",
5722 "OSPF information\n"
5726 "detail of all neighbors\n"
5727 "include down status neighbor\n"
5731 bool uj
= use_json(argc
, argv
);
5732 struct listnode
*node
= NULL
;
5733 char *vrf_name
= NULL
;
5734 bool all_vrf
= false;
5735 int ret
= CMD_SUCCESS
;
5738 uint8_t use_vrf
= 0;
5739 json_object
*json
= NULL
;
5741 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5744 json
= json_object_new_object();
5746 /* vrf input is provided could be all or specific vrf*/
5750 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5751 if (!ospf
->oi_running
)
5753 ret
= show_ip_ospf_neighbor_detail_all_common(
5754 vty
, ospf
, json
, uj
, use_vrf
);
5758 vty_json(vty
, json
);
5762 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5763 if (ospf
== NULL
|| !ospf
->oi_running
) {
5765 json_object_free(json
);
5769 /* Display default ospf (instance 0) info */
5770 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5771 if (ospf
== NULL
|| !ospf
->oi_running
) {
5773 json_object_free(json
);
5779 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
,
5782 vty_out(vty
, "%s\n",
5783 json_object_to_json_string_ext(
5784 json
, JSON_C_TO_STRING_PRETTY
));
5789 json_object_free(json
);
5794 DEFUN (show_ip_ospf_instance_neighbor_detail_all
,
5795 show_ip_ospf_instance_neighbor_detail_all_cmd
,
5796 "show ip ospf (1-65535) neighbor detail all [json]",
5799 "OSPF information\n"
5802 "detail of all neighbors\n"
5803 "include down status neighbor\n"
5808 unsigned short instance
= 0;
5809 bool uj
= use_json(argc
, argv
);
5810 json_object
*json
= NULL
;
5811 int ret
= CMD_SUCCESS
;
5813 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5814 if (instance
!= ospf_instance
)
5815 return CMD_NOT_MY_INSTANCE
;
5817 ospf
= ospf_lookup_instance(instance
);
5818 if (!ospf
|| !ospf
->oi_running
)
5822 json
= json_object_new_object();
5824 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
, uj
, 0);
5827 vty_json(vty
, json
);
5832 static int show_ip_ospf_neighbor_int_detail_common(struct vty
*vty
,
5835 struct cmd_token
**argv
,
5838 struct ospf_interface
*oi
;
5839 struct interface
*ifp
;
5840 struct route_node
*rn
, *nrn
;
5841 struct ospf_neighbor
*nbr
;
5842 json_object
*json
= NULL
;
5845 json
= json_object_new_object();
5847 if (ospf
->instance
) {
5849 json_object_int_add(json
, "ospfInstance",
5852 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5855 ifp
= if_lookup_by_name(argv
[arg_base
]->arg
, ospf
->vrf_id
);
5858 vty_out(vty
, "No such interface.\n");
5860 vty_out(vty
, "{}\n");
5861 json_object_free(json
);
5866 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
5872 for (nrn
= route_top(oi
->nbrs
); nrn
; nrn
= route_next(nrn
)) {
5878 if (nbr
== oi
->nbr_self
)
5881 if (nbr
->state
== NSM_Down
)
5884 show_ip_ospf_neighbor_detail_sub(vty
, oi
, nbr
, NULL
,
5890 vty_json(vty
, json
);
5897 DEFUN (show_ip_ospf_neighbor_int_detail
,
5898 show_ip_ospf_neighbor_int_detail_cmd
,
5899 "show ip ospf neighbor IFNAME detail [json]",
5902 "OSPF information\n"
5905 "detail of all neighbors\n"
5909 bool uj
= use_json(argc
, argv
);
5910 struct listnode
*node
= NULL
;
5911 int ret
= CMD_SUCCESS
;
5912 bool ospf_output
= false;
5914 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5915 if (!ospf
->oi_running
)
5918 ret
= show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, 4,
5923 vty_out(vty
, "%% OSPF instance not found\n");
5928 DEFUN (show_ip_ospf_instance_neighbor_int_detail
,
5929 show_ip_ospf_instance_neighbor_int_detail_cmd
,
5930 "show ip ospf (1-65535) neighbor IFNAME detail [json]",
5933 "OSPF information\n"
5937 "detail of all neighbors\n"
5943 unsigned short instance
= 0;
5944 bool uj
= use_json(argc
, argv
);
5946 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5947 if (instance
!= ospf_instance
)
5948 return CMD_NOT_MY_INSTANCE
;
5950 ospf
= ospf_lookup_instance(instance
);
5951 if (!ospf
|| !ospf
->oi_running
)
5954 return show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, idx_ifname
,
5958 /* Show functions */
5959 static int show_lsa_summary(struct vty
*vty
, struct ospf_lsa
*lsa
, int self
,
5960 json_object
*json_lsa
)
5962 struct router_lsa
*rl
;
5963 struct summary_lsa
*sl
;
5964 struct as_external_lsa
*asel
;
5965 struct prefix_ipv4 p
;
5968 /* If self option is set, check LSA self flag. */
5969 if (self
== 0 || IS_LSA_SELF(lsa
)) {
5972 /* LSA common part show. */
5973 vty_out(vty
, "%-15pI4",
5975 vty_out(vty
, "%-15pI4 %4d 0x%08lx 0x%04x",
5976 &lsa
->data
->adv_router
, LS_AGE(lsa
),
5977 (unsigned long)ntohl(
5978 lsa
->data
->ls_seqnum
),
5979 ntohs(lsa
->data
->checksum
));
5984 snprintf(seqnum
, sizeof(seqnum
), "%x",
5985 ntohl(lsa
->data
->ls_seqnum
));
5986 snprintf(checksum
, sizeof(checksum
), "%x",
5987 ntohs(lsa
->data
->checksum
));
5988 json_object_string_addf(json_lsa
, "lsId",
5989 "%pI4", &lsa
->data
->id
);
5990 json_object_string_addf(
5991 json_lsa
, "advertisedRouter", "%pI4",
5992 &lsa
->data
->adv_router
);
5993 json_object_int_add(json_lsa
, "lsaAge",
5995 json_object_string_add(
5996 json_lsa
, "sequenceNumber", seqnum
);
5997 json_object_string_add(json_lsa
, "checksum",
6001 /* LSA specific part show. */
6002 switch (lsa
->data
->type
) {
6003 case OSPF_ROUTER_LSA
:
6004 rl
= (struct router_lsa
*)lsa
->data
;
6007 vty_out(vty
, " %-d", ntohs(rl
->links
));
6009 json_object_int_add(json_lsa
,
6013 case OSPF_SUMMARY_LSA
:
6014 sl
= (struct summary_lsa
*)lsa
->data
;
6017 p
.prefix
= sl
->header
.id
;
6018 p
.prefixlen
= ip_masklen(sl
->mask
);
6019 apply_mask_ipv4(&p
);
6022 vty_out(vty
, " %pFX", &p
);
6024 json_object_string_addf(
6025 json_lsa
, "summaryAddress",
6029 case OSPF_AS_EXTERNAL_LSA
:
6030 case OSPF_AS_NSSA_LSA
:
6031 asel
= (struct as_external_lsa
*)lsa
->data
;
6034 p
.prefix
= asel
->header
.id
;
6035 p
.prefixlen
= ip_masklen(asel
->mask
);
6036 apply_mask_ipv4(&p
);
6039 vty_out(vty
, " %s %pFX [0x%lx]",
6045 (unsigned long)ntohl(
6046 asel
->e
[0].route_tag
));
6048 json_object_string_add(
6049 json_lsa
, "metricType",
6054 json_object_string_addf(
6055 json_lsa
, "route", "%pFX", &p
);
6056 json_object_int_add(
6058 (unsigned long)ntohl(
6059 asel
->e
[0].route_tag
));
6062 case OSPF_NETWORK_LSA
:
6063 case OSPF_ASBR_SUMMARY_LSA
:
6064 case OSPF_OPAQUE_LINK_LSA
:
6065 case OSPF_OPAQUE_AREA_LSA
:
6066 case OSPF_OPAQUE_AS_LSA
:
6081 static const char *const show_database_desc
[] = {
6083 "Router Link States",
6085 "Summary Link States",
6086 "ASBR-Summary Link States",
6087 "AS External Link States",
6088 "Group Membership LSA",
6089 "NSSA-external Link States",
6091 "Link-Local Opaque-LSA",
6092 "Area-Local Opaque-LSA",
6093 "AS-external Opaque-LSA",
6096 static const char * const show_database_desc_json
[] = {
6099 "networkLinkStates",
6100 "summaryLinkStates",
6101 "asbrSummaryLinkStates",
6102 "asExternalLinkStates",
6103 "groupMembershipLsa",
6104 "nssaExternalLinkStates",
6106 "linkLocalOpaqueLsa",
6107 "areaLocalOpaqueLsa",
6108 "asExternalOpaqueLsa",
6111 static const char *const show_database_desc_count_json
[] = {
6113 "routerLinkStatesCount",
6114 "networkLinkStatesCount",
6115 "summaryLinkStatesCount",
6116 "asbrSummaryLinkStatesCount",
6117 "asExternalLinkStatesCount",
6118 "groupMembershipLsaCount",
6119 "nssaExternalLinkStatesCount",
6121 "linkLocalOpaqueLsaCount",
6122 "areaLocalOpaqueLsaCount",
6123 "asExternalOpaqueLsaCount",
6126 static const char *const show_database_header
[] = {
6128 "Link ID ADV Router Age Seq# CkSum Link count",
6129 "Link ID ADV Router Age Seq# CkSum",
6130 "Link ID ADV Router Age Seq# CkSum Route",
6131 "Link ID ADV Router Age Seq# CkSum",
6132 "Link ID ADV Router Age Seq# CkSum Route",
6133 " --- header for Group Member ----",
6134 "Link ID ADV Router Age Seq# CkSum Route",
6136 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6137 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6138 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6141 static void show_ip_ospf_database_header(struct vty
*vty
, struct ospf_lsa
*lsa
,
6144 struct router_lsa
*rlsa
= (struct router_lsa
*)lsa
->data
;
6147 vty_out(vty
, " LS age: %d\n", LS_AGE(lsa
));
6148 vty_out(vty
, " Options: 0x%-2x : %s\n", lsa
->data
->options
,
6149 ospf_options_dump(lsa
->data
->options
));
6150 vty_out(vty
, " LS Flags: 0x%-2x %s\n", lsa
->flags
,
6151 ((lsa
->flags
& OSPF_LSA_LOCAL_XLT
)
6152 ? "(Translated from Type-7)"
6155 if (lsa
->data
->type
== OSPF_ROUTER_LSA
) {
6156 vty_out(vty
, " Flags: 0x%x", rlsa
->flags
);
6159 vty_out(vty
, " :%s%s%s%s",
6160 IS_ROUTER_LSA_BORDER(rlsa
) ? " ABR"
6162 IS_ROUTER_LSA_EXTERNAL(rlsa
) ? " ASBR"
6164 IS_ROUTER_LSA_VIRTUAL(rlsa
)
6167 IS_ROUTER_LSA_SHORTCUT(rlsa
)
6173 vty_out(vty
, " LS Type: %s\n",
6174 lookup_msg(ospf_lsa_type_msg
, lsa
->data
->type
, NULL
));
6175 vty_out(vty
, " Link State ID: %pI4 %s\n",
6177 lookup_msg(ospf_link_state_id_type_msg
, lsa
->data
->type
,
6179 vty_out(vty
, " Advertising Router: %pI4\n",
6180 &lsa
->data
->adv_router
);
6181 vty_out(vty
, " LS Seq Number: %08lx\n",
6182 (unsigned long)ntohl(lsa
->data
->ls_seqnum
));
6183 vty_out(vty
, " Checksum: 0x%04x\n",
6184 ntohs(lsa
->data
->checksum
));
6185 vty_out(vty
, " Length: %d\n\n", ntohs(lsa
->data
->length
));
6190 snprintf(seqnum
, 10, "%x", ntohl(lsa
->data
->ls_seqnum
));
6191 snprintf(checksum
, 10, "%x", ntohs(lsa
->data
->checksum
));
6193 json_object_int_add(json
, "lsaAge", LS_AGE(lsa
));
6194 json_object_string_add(json
, "options",
6195 ospf_options_dump(lsa
->data
->options
));
6196 json_object_int_add(json
, "lsaFlags", lsa
->flags
);
6198 if (lsa
->flags
& OSPF_LSA_LOCAL_XLT
)
6199 json_object_boolean_true_add(json
,
6200 "translatedFromType7");
6202 if (lsa
->data
->type
== OSPF_ROUTER_LSA
) {
6203 json_object_int_add(json
, "flags", rlsa
->flags
);
6206 if (IS_ROUTER_LSA_BORDER(rlsa
))
6207 json_object_boolean_true_add(json
,
6209 if (IS_ROUTER_LSA_EXTERNAL(rlsa
))
6210 json_object_boolean_true_add(json
,
6212 if (IS_ROUTER_LSA_VIRTUAL(rlsa
))
6213 json_object_boolean_true_add(
6214 json
, "vlEndpoint");
6215 if (IS_ROUTER_LSA_SHORTCUT(rlsa
))
6216 json_object_boolean_true_add(
6221 json_object_string_add(
6223 lookup_msg(ospf_lsa_type_msg
, lsa
->data
->type
, NULL
));
6224 json_object_string_addf(json
, "linkStateId", "%pI4",
6226 json_object_string_addf(json
, "advertisingRouter", "%pI4",
6227 &lsa
->data
->adv_router
);
6228 json_object_string_add(json
, "lsaSeqNumber", seqnum
);
6229 json_object_string_add(json
, "checksum", checksum
);
6230 json_object_int_add(json
, "length", ntohs(lsa
->data
->length
));
6234 static const char *const link_type_desc
[] = {
6236 "another Router (point-to-point)",
6237 "a Transit Network",
6242 static const char *const link_id_desc
[] = {
6243 "(null)", "Neighboring Router ID", "Designated Router address",
6244 "Net", "Neighboring Router ID",
6247 static const char *const link_data_desc
[] = {
6248 "(null)", "Router Interface address", "Router Interface address",
6249 "Network Mask", "Router Interface address",
6252 static const char *const link_id_desc_json
[] = {
6253 "null", "neighborRouterId", "designatedRouterAddress",
6254 "networkAddress", "neighborRouterId",
6257 static const char *const link_data_desc_json
[] = {
6258 "null", "routerInterfaceAddress", "routerInterfaceAddress",
6259 "networkMask", "routerInterfaceAddress",
6262 /* Show router-LSA each Link information. */
6263 static void show_ip_ospf_database_router_links(struct vty
*vty
,
6264 struct router_lsa
*rl
,
6269 json_object
*json_links
= NULL
;
6270 json_object
*json_link
= NULL
;
6272 char buf
[PREFIX_STRLEN
];
6275 json_links
= json_object_new_object();
6277 len
= ntohs(rl
->header
.length
) - 4;
6278 for (i
= 0; i
< ntohs(rl
->links
) && len
> 0; len
-= 12, i
++) {
6279 type
= rl
->link
[i
].type
;
6284 snprintf(link
, sizeof(link
), "link%u", i
);
6285 json_link
= json_object_new_object();
6286 json_object_string_add(json_link
, "linkType",
6287 link_type_desc
[type
]);
6288 json_object_string_add(json_link
,
6289 link_id_desc_json
[type
],
6291 &rl
->link
[i
].link_id
,
6293 json_object_string_add(
6294 json_link
, link_data_desc_json
[type
],
6295 inet_ntop(AF_INET
, &rl
->link
[i
].link_data
,
6297 json_object_int_add(json_link
, "numOfTosMetrics",
6299 json_object_int_add(json_link
, "tos0Metric",
6300 ntohs(rl
->link
[i
].metric
));
6301 json_object_object_add(json_links
, link
, json_link
);
6303 vty_out(vty
, " Link connected to: %s\n",
6304 link_type_desc
[type
]);
6305 vty_out(vty
, " (Link ID) %s: %pI4\n",
6307 &rl
->link
[i
].link_id
);
6308 vty_out(vty
, " (Link Data) %s: %pI4\n",
6309 link_data_desc
[type
],
6310 &rl
->link
[i
].link_data
);
6311 vty_out(vty
, " Number of TOS metrics: 0\n");
6312 vty_out(vty
, " TOS 0 Metric: %d\n",
6313 ntohs(rl
->link
[i
].metric
));
6318 json_object_object_add(json
, "routerLinks", json_links
);
6321 /* Show router-LSA detail information. */
6322 static int show_router_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6326 struct router_lsa
*rl
= (struct router_lsa
*)lsa
->data
;
6328 show_ip_ospf_database_header(vty
, lsa
, json
);
6331 vty_out(vty
, " Number of Links: %d\n\n",
6334 json_object_int_add(json
, "numOfLinks",
6337 show_ip_ospf_database_router_links(vty
, rl
, json
);
6346 /* Show network-LSA detail information. */
6347 static int show_network_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6351 char buf
[PREFIX_STRLEN
];
6352 json_object
*json_attached_rt
= NULL
;
6353 json_object
*json_router
= NULL
;
6356 json_attached_rt
= json_object_new_object();
6359 struct network_lsa
*nl
= (struct network_lsa
*)lsa
->data
;
6360 struct in_addr
*addr
;
6362 show_ip_ospf_database_header(vty
, lsa
, json
);
6365 vty_out(vty
, " Network Mask: /%d\n",
6366 ip_masklen(nl
->mask
));
6368 json_object_int_add(json
, "networkMask",
6369 ip_masklen(nl
->mask
));
6371 length
= lsa
->size
- OSPF_LSA_HEADER_SIZE
- 4;
6372 addr
= &nl
->routers
[0];
6373 for (i
= 0; length
> 0 && addr
;
6374 length
-= 4, addr
= &nl
->routers
[++i
])
6376 vty_out(vty
, " Attached Router: %pI4\n",
6380 json_router
= json_object_new_object();
6381 json_object_string_add(
6382 json_router
, "attachedRouterId",
6383 inet_ntop(AF_INET
, addr
, buf
,
6385 json_object_object_add(json_attached_rt
,
6386 inet_ntop(AF_INET
, addr
,
6394 json_object_object_add(json
, "attchedRouters",
6400 /* Show summary-LSA detail information. */
6401 static int show_summary_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6405 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
6407 show_ip_ospf_database_header(vty
, lsa
, json
);
6410 vty_out(vty
, " Network Mask: /%d\n",
6411 ip_masklen(sl
->mask
));
6412 vty_out(vty
, " TOS: 0 Metric: %d\n",
6413 GET_METRIC(sl
->metric
));
6416 json_object_int_add(json
, "networkMask",
6417 ip_masklen(sl
->mask
));
6418 json_object_int_add(json
, "tos0Metric",
6419 GET_METRIC(sl
->metric
));
6426 /* Show summary-ASBR-LSA detail information. */
6427 static int show_summary_asbr_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6431 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
6433 show_ip_ospf_database_header(vty
, lsa
, json
);
6436 vty_out(vty
, " Network Mask: /%d\n",
6437 ip_masklen(sl
->mask
));
6438 vty_out(vty
, " TOS: 0 Metric: %d\n",
6439 GET_METRIC(sl
->metric
));
6442 json_object_int_add(json
, "networkMask",
6443 ip_masklen(sl
->mask
));
6444 json_object_int_add(json
, "tos0Metric",
6445 GET_METRIC(sl
->metric
));
6452 /* Show AS-external-LSA detail information. */
6453 static int show_as_external_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6459 struct as_external_lsa
*al
=
6460 (struct as_external_lsa
*)lsa
->data
;
6462 show_ip_ospf_database_header(vty
, lsa
, json
);
6465 vty_out(vty
, " Network Mask: /%d\n",
6466 ip_masklen(al
->mask
));
6467 vty_out(vty
, " Metric Type: %s\n",
6468 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6469 ? "2 (Larger than any link state path)"
6471 vty_out(vty
, " TOS: 0\n");
6472 vty_out(vty
, " Metric: %d\n",
6473 GET_METRIC(al
->e
[0].metric
));
6474 vty_out(vty
, " Forward Address: %pI4\n",
6475 &al
->e
[0].fwd_addr
);
6477 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
6478 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6480 json_object_int_add(json
, "networkMask",
6481 ip_masklen(al
->mask
));
6482 json_object_string_add(
6484 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6485 ? "E2 (Larger than any link state path)"
6487 json_object_int_add(json
, "tos", tos
);
6488 json_object_int_add(json
, "metric",
6489 GET_METRIC(al
->e
[0].metric
));
6490 json_object_string_addf(json
, "forwardAddress", "%pI4",
6491 &(al
->e
[0].fwd_addr
));
6492 json_object_int_add(
6493 json
, "externalRouteTag",
6494 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6501 /* Show AS-NSSA-LSA detail information. */
6502 static int show_as_nssa_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6508 struct as_external_lsa
*al
=
6509 (struct as_external_lsa
*)lsa
->data
;
6511 show_ip_ospf_database_header(vty
, lsa
, json
);
6514 vty_out(vty
, " Network Mask: /%d\n",
6515 ip_masklen(al
->mask
));
6516 vty_out(vty
, " Metric Type: %s\n",
6517 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6518 ? "2 (Larger than any link state path)"
6520 vty_out(vty
, " TOS: 0\n");
6521 vty_out(vty
, " Metric: %d\n",
6522 GET_METRIC(al
->e
[0].metric
));
6523 vty_out(vty
, " NSSA: Forward Address: %pI4\n",
6524 &al
->e
[0].fwd_addr
);
6526 " External Route Tag: %" ROUTE_TAG_PRI
6528 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6530 json_object_int_add(json
, "networkMask",
6531 ip_masklen(al
->mask
));
6532 json_object_string_add(
6534 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6535 ? "E2 (Larger than any link state path)"
6537 json_object_int_add(json
, "tos", tos
);
6538 json_object_int_add(json
, "metric",
6539 GET_METRIC(al
->e
[0].metric
));
6540 json_object_string_addf(json
, "nssaForwardAddress",
6541 "%pI4", &al
->e
[0].fwd_addr
);
6542 json_object_int_add(
6543 json
, "externalRouteTag",
6544 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6551 static int show_func_dummy(struct vty
*vty
, struct ospf_lsa
*lsa
,
6557 static int show_opaque_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6561 show_ip_ospf_database_header(vty
, lsa
, json
);
6562 show_opaque_info_detail(vty
, lsa
, json
);
6569 int (*show_function
[])(struct vty
*, struct ospf_lsa
*, json_object
*) = {
6571 show_router_lsa_detail
,
6572 show_network_lsa_detail
,
6573 show_summary_lsa_detail
,
6574 show_summary_asbr_lsa_detail
,
6575 show_as_external_lsa_detail
,
6577 show_as_nssa_lsa_detail
, /* almost same as external */
6579 show_opaque_lsa_detail
,
6580 show_opaque_lsa_detail
,
6581 show_opaque_lsa_detail
,
6584 static void show_lsa_prefix_set(struct vty
*vty
, struct prefix_ls
*lp
,
6585 struct in_addr
*id
, struct in_addr
*adv_router
)
6587 memset(lp
, 0, sizeof(struct prefix_ls
));
6588 lp
->family
= AF_UNSPEC
;
6591 else if (adv_router
== NULL
) {
6592 lp
->prefixlen
= IPV4_MAX_BITLEN
;
6597 lp
->adv_router
= *adv_router
;
6601 static void show_lsa_detail_proc(struct vty
*vty
, struct route_table
*rt
,
6602 struct in_addr
*id
, struct in_addr
*adv_router
,
6605 struct prefix_ls lp
;
6606 struct route_node
*rn
, *start
;
6607 struct ospf_lsa
*lsa
;
6608 json_object
*json_lsa
= NULL
;
6610 show_lsa_prefix_set(vty
, &lp
, id
, adv_router
);
6611 start
= route_node_get(rt
, (struct prefix
*)&lp
);
6613 route_lock_node(start
);
6614 for (rn
= start
; rn
; rn
= route_next_until(rn
, start
))
6615 if ((lsa
= rn
->info
)) {
6616 if (show_function
[lsa
->data
->type
] != NULL
) {
6619 json_object_new_object();
6620 json_object_array_add(json
,
6624 show_function
[lsa
->data
->type
](
6625 vty
, lsa
, json_lsa
);
6628 route_unlock_node(start
);
6632 /* Show detail LSA information
6633 -- if id is NULL then show all LSAs. */
6634 static void show_lsa_detail(struct vty
*vty
, struct ospf
*ospf
, int type
,
6635 struct in_addr
*id
, struct in_addr
*adv_router
,
6638 struct listnode
*node
;
6639 struct ospf_area
*area
;
6640 char buf
[PREFIX_STRLEN
];
6641 json_object
*json_lsa_type
= NULL
;
6642 json_object
*json_areas
= NULL
;
6643 json_object
*json_lsa_array
= NULL
;
6646 case OSPF_AS_EXTERNAL_LSA
:
6647 case OSPF_OPAQUE_AS_LSA
:
6649 vty_out(vty
, " %s \n\n",
6650 show_database_desc
[type
]);
6652 json_lsa_array
= json_object_new_array();
6654 show_lsa_detail_proc(vty
, AS_LSDB(ospf
, type
), id
, adv_router
,
6657 json_object_object_add(json
,
6658 show_database_desc_json
[type
],
6664 json_areas
= json_object_new_object();
6666 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6669 "\n %s (Area %s)\n\n",
6670 show_database_desc
[type
],
6671 ospf_area_desc_string(area
));
6673 json_lsa_array
= json_object_new_array();
6674 json_object_object_add(json_areas
,
6682 show_lsa_detail_proc(vty
, AREA_LSDB(area
, type
), id
,
6683 adv_router
, json_lsa_array
);
6687 json_lsa_type
= json_object_new_object();
6688 json_object_object_add(json_lsa_type
, "areas",
6690 json_object_object_add(json
,
6691 show_database_desc_json
[type
],
6698 static void show_lsa_detail_adv_router_proc(struct vty
*vty
,
6699 struct route_table
*rt
,
6700 struct in_addr
*adv_router
,
6703 char buf
[PREFIX_STRLEN
];
6704 struct route_node
*rn
;
6705 struct ospf_lsa
*lsa
;
6707 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
))
6708 if ((lsa
= rn
->info
)) {
6709 json_object
*json_lsa
= NULL
;
6711 if (IPV4_ADDR_SAME(adv_router
,
6712 &lsa
->data
->adv_router
)) {
6713 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
6716 json_lsa
= json_object_new_object();
6718 if (show_function
[lsa
->data
->type
] != NULL
)
6719 show_function
[lsa
->data
->type
](
6720 vty
, lsa
, json_lsa
);
6722 json_object_object_add(
6732 /* Show detail LSA information. */
6733 static void show_lsa_detail_adv_router(struct vty
*vty
, struct ospf
*ospf
,
6734 int type
, struct in_addr
*adv_router
,
6737 struct listnode
*node
;
6738 struct ospf_area
*area
;
6739 char buf
[PREFIX_STRLEN
];
6740 json_object
*json_lstype
= NULL
;
6741 json_object
*json_area
= NULL
;
6744 json_lstype
= json_object_new_object();
6747 case OSPF_AS_EXTERNAL_LSA
:
6748 case OSPF_OPAQUE_AS_LSA
:
6750 vty_out(vty
, " %s \n\n",
6751 show_database_desc
[type
]);
6753 show_lsa_detail_adv_router_proc(vty
, AS_LSDB(ospf
, type
),
6754 adv_router
, json_lstype
);
6758 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6760 json_area
= json_object_new_object();
6763 "\n %s (Area %s)\n\n",
6764 show_database_desc
[type
],
6765 ospf_area_desc_string(area
));
6766 show_lsa_detail_adv_router_proc(vty
,
6767 AREA_LSDB(area
, type
),
6768 adv_router
, json_area
);
6771 json_object_object_add(json_lstype
,
6782 json_object_object_add(json
, show_database_desc
[type
],
6786 void show_ip_ospf_database_summary(struct vty
*vty
, struct ospf
*ospf
, int self
,
6789 struct ospf_lsa
*lsa
;
6790 struct route_node
*rn
;
6791 struct ospf_area
*area
;
6792 struct listnode
*node
;
6793 char buf
[PREFIX_STRLEN
];
6794 json_object
*json_areas
= NULL
;
6795 json_object
*json_area
= NULL
;
6796 json_object
*json_lsa
= NULL
;
6798 json_object
*json_lsa_array
= NULL
;
6802 json_areas
= json_object_new_object();
6804 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6806 json_area
= json_object_new_object();
6808 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6811 case OSPF_AS_EXTERNAL_LSA
:
6812 case OSPF_OPAQUE_AS_LSA
:
6817 if (ospf_lsdb_count_self(area
->lsdb
, type
) > 0
6819 && ospf_lsdb_count(area
->lsdb
, type
) > 0)) {
6823 " %s (Area %s)\n\n",
6824 show_database_desc
[type
],
6825 ospf_area_desc_string(area
));
6826 vty_out(vty
, "%s\n",
6827 show_database_header
[type
]);
6830 json_object_new_array();
6831 json_object_object_add(
6833 show_database_desc_json
[type
],
6837 LSDB_LOOP (AREA_LSDB(area
, type
), rn
, lsa
) {
6840 json_object_new_object();
6841 json_object_array_add(
6846 count
+= show_lsa_summary(
6847 vty
, lsa
, self
, json_lsa
);
6853 json_object_int_add(
6856 show_database_desc_count_json
6862 json_object_object_add(json_areas
,
6870 json_object_object_add(json
, "areas", json_areas
);
6872 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6875 case OSPF_AS_EXTERNAL_LSA
:
6876 case OSPF_OPAQUE_AS_LSA
:
6881 if (ospf_lsdb_count_self(ospf
->lsdb
, type
)
6882 || (!self
&& ospf_lsdb_count(ospf
->lsdb
, type
))) {
6884 vty_out(vty
, " %s\n\n",
6885 show_database_desc
[type
]);
6886 vty_out(vty
, "%s\n",
6887 show_database_header
[type
]);
6889 json_lsa_array
= json_object_new_array();
6890 json_object_object_add(
6891 json
, show_database_desc_json
[type
],
6895 LSDB_LOOP (AS_LSDB(ospf
, type
), rn
, lsa
) {
6897 json_lsa
= json_object_new_object();
6898 json_object_array_add(json_lsa_array
,
6902 count
+= show_lsa_summary(vty
, lsa
, self
,
6909 json_object_int_add(
6911 show_database_desc_count_json
[type
],
6920 static void show_ip_ospf_database_maxage(struct vty
*vty
, struct ospf
*ospf
,
6923 struct route_node
*rn
;
6924 char buf
[PREFIX_STRLEN
];
6925 json_object
*json_maxage
= NULL
;
6928 vty_out(vty
, "\n MaxAge Link States:\n\n");
6930 json_maxage
= json_object_new_object();
6932 for (rn
= route_top(ospf
->maxage_lsa
); rn
; rn
= route_next(rn
)) {
6933 struct ospf_lsa
*lsa
;
6934 json_object
*json_lsa
= NULL
;
6936 if ((lsa
= rn
->info
) != NULL
) {
6938 vty_out(vty
, "Link type: %d\n",
6940 vty_out(vty
, "Link State ID: %pI4\n",
6942 vty_out(vty
, "Advertising Router: %pI4\n",
6943 &lsa
->data
->adv_router
);
6944 vty_out(vty
, "LSA lock count: %d\n", lsa
->lock
);
6947 json_lsa
= json_object_new_object();
6948 json_object_int_add(json_lsa
, "linkType",
6950 json_object_string_addf(json_lsa
, "linkStateId",
6951 "%pI4", &lsa
->data
->id
);
6952 json_object_string_addf(
6953 json_lsa
, "advertisingRouter", "%pI4",
6954 &lsa
->data
->adv_router
);
6955 json_object_int_add(json_lsa
, "lsaLockCount",
6957 json_object_object_add(
6967 json_object_object_add(json
, "maxAgeLinkStates", json_maxage
);
6970 #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
6971 #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
6973 #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
6974 #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
6975 #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
6976 #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
6978 #define OSPF_LSA_TYPES_DESC \
6979 "ASBR summary link states\n" \
6980 "External link states\n" \
6981 "Network link states\n" \
6982 "Router link states\n" \
6983 "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \
6984 OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
6985 OSPF_LSA_TYPE_OPAQUE_AS_DESC
6987 static int show_ip_ospf_database_common(struct vty
*vty
, struct ospf
*ospf
,
6988 int arg_base
, int argc
,
6989 struct cmd_token
**argv
,
6990 uint8_t use_vrf
, json_object
*json
,
6995 struct in_addr id
, adv_router
;
6996 json_object
*json_vrf
= NULL
;
7000 json_vrf
= json_object_new_object();
7005 if (ospf
->instance
) {
7007 json_object_int_add(json_vrf
, "ospfInstance",
7010 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
7013 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
7015 /* Show Router ID. */
7017 json_object_string_addf(json_vrf
, "routerId", "%pI4",
7020 vty_out(vty
, "\n OSPF Router with ID (%pI4)\n\n",
7025 if ((argc
== arg_base
+ 4) || (uj
&& (argc
== arg_base
+ 5))) {
7026 show_ip_ospf_database_summary(vty
, ospf
, 0, json_vrf
);
7029 json_object_object_add(
7030 json
, ospf_get_name(ospf
), json_vrf
);
7035 /* Set database type to show. */
7036 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
7037 type
= OSPF_ROUTER_LSA
;
7038 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
7039 type
= OSPF_NETWORK_LSA
;
7040 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
7041 type
= OSPF_AS_NSSA_LSA
;
7042 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "su", 2) == 0)
7043 type
= OSPF_SUMMARY_LSA
;
7044 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
7045 type
= OSPF_ASBR_SUMMARY_LSA
;
7046 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
7047 type
= OSPF_AS_EXTERNAL_LSA
;
7048 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "se", 2) == 0) {
7049 show_ip_ospf_database_summary(vty
, ospf
, 1, json_vrf
);
7052 json_object_object_add(
7053 json
, ospf_get_name(ospf
), json_vrf
);
7056 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "m", 1) == 0) {
7057 show_ip_ospf_database_maxage(vty
, ospf
, json_vrf
);
7060 json_object_object_add(
7061 json
, ospf_get_name(ospf
), json_vrf
);
7064 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
7065 type
= OSPF_OPAQUE_LINK_LSA
;
7066 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
7067 type
= OSPF_OPAQUE_AREA_LSA
;
7068 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
7069 type
= OSPF_OPAQUE_AS_LSA
;
7073 /* `show ip ospf database LSA'. */
7074 if ((argc
== arg_base
+ 5) || (uj
&& (argc
== arg_base
+ 6)))
7075 show_lsa_detail(vty
, ospf
, type
, NULL
, NULL
, json_vrf
);
7076 else if (argc
>= arg_base
+ 6) {
7077 ret
= inet_aton(argv
[arg_base
+ 5]->arg
, &id
);
7081 /* `show ip ospf database LSA ID'. */
7082 if ((argc
== arg_base
+ 6) || (uj
&& (argc
== arg_base
+ 7)))
7083 show_lsa_detail(vty
, ospf
, type
, &id
, NULL
, json_vrf
);
7084 /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */
7085 else if ((argc
== arg_base
+ 7)
7086 || (uj
&& (argc
== arg_base
+ 8))) {
7087 if (strncmp(argv
[arg_base
+ 6]->text
, "s", 1) == 0)
7088 adv_router
= ospf
->router_id
;
7090 ret
= inet_aton(argv
[arg_base
+ 7]->arg
,
7095 show_lsa_detail(vty
, ospf
, type
, &id
, &adv_router
,
7102 json_object_object_add(json
, ospf_get_name(ospf
),
7109 DEFUN (show_ip_ospf_database_max
,
7110 show_ip_ospf_database_max_cmd
,
7111 "show ip ospf [vrf <NAME|all>] database <max-age|self-originate> [json]",
7114 "OSPF information\n"
7117 "Database summary\n"
7118 "LSAs in MaxAge list\n"
7119 "Self-originated link states\n"
7122 struct ospf
*ospf
= NULL
;
7123 struct listnode
*node
= NULL
;
7124 char *vrf_name
= NULL
;
7125 bool all_vrf
= false;
7126 int ret
= CMD_SUCCESS
;
7129 uint8_t use_vrf
= 0;
7130 bool uj
= use_json(argc
, argv
);
7131 json_object
*json
= NULL
;
7134 json
= json_object_new_object();
7136 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
7139 bool ospf_output
= false;
7144 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
7145 if (!ospf
->oi_running
)
7148 ret
= show_ip_ospf_database_common(
7149 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
,
7154 vty_out(vty
, "%% OSPF is not enabled\n");
7156 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
7157 if (ospf
== NULL
|| !ospf
->oi_running
) {
7159 "%% OSPF is not enabled in vrf %s\n",
7162 json_object_free(json
);
7166 ret
= (show_ip_ospf_database_common(
7167 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
, use_vrf
,
7171 /* Display default ospf (instance 0) info */
7172 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
7173 if (ospf
== NULL
|| !ospf
->oi_running
) {
7174 vty_out(vty
, "%% OSPF is not enabled in vrf default\n");
7176 json_object_free(json
);
7181 ret
= show_ip_ospf_database_common(vty
, ospf
, 0, argc
, argv
,
7186 vty_json(vty
, json
);
7191 ALIAS (show_ip_ospf_database_max
,
7192 show_ip_ospf_database_cmd
,
7193 "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]",
7196 "OSPF information\n"
7199 "Database summary\n"
7201 "Link State ID (as an IP address)\n"
7202 "Self-originated link states\n"
7203 "Advertising Router link states\n"
7204 "Advertising Router (as an IP address)\n"
7207 DEFUN (show_ip_ospf_instance_database_max
,
7208 show_ip_ospf_instance_database_max_cmd
,
7209 "show ip ospf (1-65535) database <max-age|self-originate> [json]",
7212 "OSPF information\n"
7214 "Database summary\n"
7215 "LSAs in MaxAge list\n"
7216 "Self-originated link states\n"
7221 unsigned short instance
= 0;
7222 bool uj
= use_json(argc
, argv
);
7223 json_object
*json
= NULL
;
7226 json
= json_object_new_object();
7228 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
7229 if (instance
!= ospf_instance
)
7230 return CMD_NOT_MY_INSTANCE
;
7232 ospf
= ospf_lookup_instance(instance
);
7233 if (!ospf
|| !ospf
->oi_running
)
7236 show_ip_ospf_database_common(vty
, ospf
, 1, argc
, argv
, 0, json
, uj
);
7239 vty_json(vty
, json
);
7244 ALIAS (show_ip_ospf_instance_database_max
,
7245 show_ip_ospf_instance_database_cmd
,
7246 "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]",
7249 "OSPF information\n"
7251 "Database summary\n"
7253 "Link State ID (as an IP address)\n"
7254 "Self-originated link states\n"
7255 "Advertising Router link states\n"
7256 "Advertising Router (as an IP address)\n"
7259 static int show_ip_ospf_database_type_adv_router_common(struct vty
*vty
,
7261 int arg_base
, int argc
,
7262 struct cmd_token
**argv
,
7269 struct in_addr adv_router
;
7270 json_object
*json_vrf
= NULL
;
7274 json_vrf
= json_object_new_object();
7279 if (ospf
->instance
) {
7281 json_object_int_add(json
, "ospfInstance",
7284 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
7287 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
7289 /* Show Router ID. */
7291 json_object_string_addf(json_vrf
, "routerId", "%pI4",
7294 vty_out(vty
, "\n OSPF Router with ID (%pI4)\n\n",
7298 /* Set database type to show. */
7299 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
7300 type
= OSPF_ROUTER_LSA
;
7301 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
7302 type
= OSPF_NETWORK_LSA
;
7303 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
7304 type
= OSPF_AS_NSSA_LSA
;
7305 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "s", 1) == 0)
7306 type
= OSPF_SUMMARY_LSA
;
7307 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
7308 type
= OSPF_ASBR_SUMMARY_LSA
;
7309 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
7310 type
= OSPF_AS_EXTERNAL_LSA
;
7311 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
7312 type
= OSPF_OPAQUE_LINK_LSA
;
7313 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
7314 type
= OSPF_OPAQUE_AREA_LSA
;
7315 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
7316 type
= OSPF_OPAQUE_AS_LSA
;
7320 json_object_free(json_vrf
);
7325 /* `show ip ospf database LSA adv-router ADV_ROUTER'. */
7326 if (strncmp(argv
[arg_base
+ 5]->text
, "s", 1) == 0)
7327 adv_router
= ospf
->router_id
;
7329 ret
= inet_aton(argv
[arg_base
+ 6]->arg
, &adv_router
);
7333 json_object_free(json_vrf
);
7339 show_lsa_detail_adv_router(vty
, ospf
, type
, &adv_router
, json_vrf
);
7343 json_object_object_add(json
, ospf_get_name(ospf
),
7350 DEFUN (show_ip_ospf_database_type_adv_router
,
7351 show_ip_ospf_database_type_adv_router_cmd
,
7352 "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]",
7355 "OSPF information\n"
7358 "Database summary\n"
7360 "Advertising Router link states\n"
7361 "Advertising Router (as an IP address)\n"
7362 "Self-originated link states\n"
7365 struct ospf
*ospf
= NULL
;
7366 struct listnode
*node
= NULL
;
7367 char *vrf_name
= NULL
;
7368 bool all_vrf
= false;
7369 int ret
= CMD_SUCCESS
;
7372 uint8_t use_vrf
= 0;
7373 bool uj
= use_json(argc
, argv
);
7374 json_object
*json
= NULL
;
7377 json
= json_object_new_object();
7379 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
7382 bool ospf_output
= false;
7387 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
7388 if (!ospf
->oi_running
)
7391 ret
= show_ip_ospf_database_type_adv_router_common(
7392 vty
, ospf
, 2, argc
, argv
, use_vrf
, json
,
7396 vty_out(vty
, "%% OSPF is not enabled\n");
7398 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
7399 if ((ospf
== NULL
) || !ospf
->oi_running
) {
7401 vty_json(vty
, json
);
7404 "%% OSPF is not enabled in vrf %s\n",
7409 ret
= show_ip_ospf_database_type_adv_router_common(
7410 vty
, ospf
, 2, argc
, argv
, use_vrf
, json
, uj
);
7413 /* Display default ospf (instance 0) info */
7414 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
7415 if (ospf
== NULL
|| !ospf
->oi_running
) {
7417 vty_json(vty
, json
);
7420 "%% OSPF is not enabled on vrf default\n");
7424 ret
= show_ip_ospf_database_type_adv_router_common(
7425 vty
, ospf
, 0, argc
, argv
, use_vrf
, json
, uj
);
7429 vty_out(vty
, "%s\n", json_object_to_json_string(json
));
7430 json_object_free(json
);
7436 DEFUN (show_ip_ospf_instance_database_type_adv_router
,
7437 show_ip_ospf_instance_database_type_adv_router_cmd
,
7438 "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]",
7441 "OSPF information\n"
7443 "Database summary\n"
7445 "Advertising Router link states\n"
7446 "Advertising Router (as an IP address)\n"
7447 "Self-originated link states\n"
7452 unsigned short instance
= 0;
7453 bool uj
= use_json(argc
, argv
);
7454 json_object
*json
= NULL
;
7457 json
= json_object_new_object();
7459 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
7460 if (instance
!= ospf_instance
)
7461 return CMD_NOT_MY_INSTANCE
;
7463 ospf
= ospf_lookup_instance(instance
);
7464 if (!ospf
|| !ospf
->oi_running
)
7467 show_ip_ospf_database_type_adv_router_common(vty
, ospf
, 1, argc
, argv
,
7471 vty_json(vty
, json
);
7476 DEFUN (ip_ospf_authentication_args
,
7477 ip_ospf_authentication_args_addr_cmd
,
7478 "ip ospf authentication <null|message-digest> [A.B.C.D]",
7480 "OSPF interface commands\n"
7481 "Enable authentication on this interface\n"
7482 "Use null authentication\n"
7483 "Use message-digest authentication\n"
7484 "Address of interface\n")
7486 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7487 int idx_encryption
= 3;
7489 struct in_addr addr
;
7491 struct ospf_if_params
*params
;
7493 params
= IF_DEF_PARAMS(ifp
);
7496 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7499 "Please specify interface address by A.B.C.D\n");
7500 return CMD_WARNING_CONFIG_FAILED
;
7503 params
= ospf_get_if_params(ifp
, addr
);
7504 ospf_if_update_params(ifp
, addr
);
7507 /* Handle null authentication */
7508 if (argv
[idx_encryption
]->arg
[0] == 'n') {
7509 SET_IF_PARAM(params
, auth_type
);
7510 params
->auth_type
= OSPF_AUTH_NULL
;
7514 /* Handle message-digest authentication */
7515 if (argv
[idx_encryption
]->arg
[0] == 'm') {
7516 SET_IF_PARAM(params
, auth_type
);
7517 params
->auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
7521 vty_out(vty
, "You shouldn't get here!\n");
7522 return CMD_WARNING_CONFIG_FAILED
;
7525 DEFUN (ip_ospf_authentication
,
7526 ip_ospf_authentication_addr_cmd
,
7527 "ip ospf authentication [A.B.C.D]",
7529 "OSPF interface commands\n"
7530 "Enable authentication on this interface\n"
7531 "Address of interface\n")
7533 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7535 struct in_addr addr
;
7537 struct ospf_if_params
*params
;
7539 params
= IF_DEF_PARAMS(ifp
);
7542 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7545 "Please specify interface address by A.B.C.D\n");
7546 return CMD_WARNING_CONFIG_FAILED
;
7549 params
= ospf_get_if_params(ifp
, addr
);
7550 ospf_if_update_params(ifp
, addr
);
7553 SET_IF_PARAM(params
, auth_type
);
7554 params
->auth_type
= OSPF_AUTH_SIMPLE
;
7559 DEFUN (no_ip_ospf_authentication_args
,
7560 no_ip_ospf_authentication_args_addr_cmd
,
7561 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
7564 "OSPF interface commands\n"
7565 "Enable authentication on this interface\n"
7566 "Use null authentication\n"
7567 "Use message-digest authentication\n"
7568 "Address of interface\n")
7570 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7571 int idx_encryption
= 4;
7573 struct in_addr addr
;
7575 struct ospf_if_params
*params
;
7576 struct route_node
*rn
;
7579 params
= IF_DEF_PARAMS(ifp
);
7582 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7585 "Please specify interface address by A.B.C.D\n");
7586 return CMD_WARNING_CONFIG_FAILED
;
7589 params
= ospf_lookup_if_params(ifp
, addr
);
7590 if (params
== NULL
) {
7591 vty_out(vty
, "Ip Address specified is unknown\n");
7592 return CMD_WARNING_CONFIG_FAILED
;
7594 params
->auth_type
= OSPF_AUTH_NOTSET
;
7595 UNSET_IF_PARAM(params
, auth_type
);
7596 if (params
!= IF_DEF_PARAMS(ifp
)) {
7597 ospf_free_if_params(ifp
, addr
);
7598 ospf_if_update_params(ifp
, addr
);
7601 if (argv
[idx_encryption
]->arg
[0] == 'n') {
7602 auth_type
= OSPF_AUTH_NULL
;
7603 } else if (argv
[idx_encryption
]->arg
[0] == 'm') {
7604 auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
7606 vty_out(vty
, "Unexpected input encountered\n");
7607 return CMD_WARNING_CONFIG_FAILED
;
7610 * Here we have a case where the user has entered
7611 * 'no ip ospf authentication (null | message_digest )'
7612 * we need to find if we have any ip addresses underneath it
7614 * correspond to the associated type.
7616 if (params
->auth_type
== auth_type
) {
7617 params
->auth_type
= OSPF_AUTH_NOTSET
;
7618 UNSET_IF_PARAM(params
, auth_type
);
7621 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
7622 rn
= route_next(rn
)) {
7623 if ((params
= rn
->info
)) {
7624 if (params
->auth_type
== auth_type
) {
7625 params
->auth_type
= OSPF_AUTH_NOTSET
;
7626 UNSET_IF_PARAM(params
, auth_type
);
7627 if (params
!= IF_DEF_PARAMS(ifp
)) {
7628 ospf_free_if_params(
7629 ifp
, rn
->p
.u
.prefix4
);
7630 ospf_if_update_params(
7631 ifp
, rn
->p
.u
.prefix4
);
7641 DEFUN (no_ip_ospf_authentication
,
7642 no_ip_ospf_authentication_addr_cmd
,
7643 "no ip ospf authentication [A.B.C.D]",
7646 "OSPF interface commands\n"
7647 "Enable authentication on this interface\n"
7648 "Address of interface\n")
7650 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7652 struct in_addr addr
;
7654 struct ospf_if_params
*params
;
7655 struct route_node
*rn
;
7657 params
= IF_DEF_PARAMS(ifp
);
7660 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7663 "Please specify interface address by A.B.C.D\n");
7664 return CMD_WARNING_CONFIG_FAILED
;
7667 params
= ospf_lookup_if_params(ifp
, addr
);
7668 if (params
== NULL
) {
7669 vty_out(vty
, "Ip Address specified is unknown\n");
7670 return CMD_WARNING_CONFIG_FAILED
;
7673 params
->auth_type
= OSPF_AUTH_NOTSET
;
7674 UNSET_IF_PARAM(params
, auth_type
);
7675 if (params
!= IF_DEF_PARAMS(ifp
)) {
7676 ospf_free_if_params(ifp
, addr
);
7677 ospf_if_update_params(ifp
, addr
);
7681 * When a user enters 'no ip ospf authentication'
7682 * We should remove all authentication types from
7685 if ((params
->auth_type
== OSPF_AUTH_NULL
)
7686 || (params
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
7687 || (params
->auth_type
== OSPF_AUTH_SIMPLE
)) {
7688 params
->auth_type
= OSPF_AUTH_NOTSET
;
7689 UNSET_IF_PARAM(params
, auth_type
);
7692 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
7693 rn
= route_next(rn
)) {
7694 if ((params
= rn
->info
)) {
7696 if ((params
->auth_type
== OSPF_AUTH_NULL
)
7697 || (params
->auth_type
7698 == OSPF_AUTH_CRYPTOGRAPHIC
)
7699 || (params
->auth_type
7700 == OSPF_AUTH_SIMPLE
)) {
7701 params
->auth_type
= OSPF_AUTH_NOTSET
;
7702 UNSET_IF_PARAM(params
, auth_type
);
7703 if (params
!= IF_DEF_PARAMS(ifp
)) {
7704 ospf_free_if_params(
7705 ifp
, rn
->p
.u
.prefix4
);
7706 ospf_if_update_params(
7707 ifp
, rn
->p
.u
.prefix4
);
7718 DEFUN (ip_ospf_authentication_key
,
7719 ip_ospf_authentication_key_addr_cmd
,
7720 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
7722 "OSPF interface commands\n"
7723 "Authentication password (key)\n"
7724 "The OSPF password (key)\n"
7725 "Address of interface\n")
7727 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7729 struct in_addr addr
;
7730 struct ospf_if_params
*params
;
7732 params
= IF_DEF_PARAMS(ifp
);
7734 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7735 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7737 "Please specify interface address by A.B.C.D\n");
7738 return CMD_WARNING_CONFIG_FAILED
;
7741 params
= ospf_get_if_params(ifp
, addr
);
7742 ospf_if_update_params(ifp
, addr
);
7745 strlcpy((char *)params
->auth_simple
, argv
[3]->arg
,
7746 sizeof(params
->auth_simple
));
7747 SET_IF_PARAM(params
, auth_simple
);
7752 DEFUN_HIDDEN (ospf_authentication_key
,
7753 ospf_authentication_key_cmd
,
7754 "ospf authentication-key AUTH_KEY [A.B.C.D]",
7755 "OSPF interface commands\n"
7756 VLINK_HELPSTR_AUTH_SIMPLE
7757 "Address of interface\n")
7759 return ip_ospf_authentication_key(self
, vty
, argc
, argv
);
7762 DEFUN (no_ip_ospf_authentication_key
,
7763 no_ip_ospf_authentication_key_authkey_addr_cmd
,
7764 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7767 "OSPF interface commands\n"
7768 VLINK_HELPSTR_AUTH_SIMPLE
7769 "Address of interface\n")
7771 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7773 struct in_addr addr
;
7774 struct ospf_if_params
*params
;
7775 params
= IF_DEF_PARAMS(ifp
);
7777 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7778 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7780 "Please specify interface address by A.B.C.D\n");
7781 return CMD_WARNING_CONFIG_FAILED
;
7784 params
= ospf_lookup_if_params(ifp
, addr
);
7789 memset(params
->auth_simple
, 0, OSPF_AUTH_SIMPLE_SIZE
);
7790 UNSET_IF_PARAM(params
, auth_simple
);
7792 if (params
!= IF_DEF_PARAMS(ifp
)) {
7793 ospf_free_if_params(ifp
, addr
);
7794 ospf_if_update_params(ifp
, addr
);
7800 DEFUN_HIDDEN (no_ospf_authentication_key
,
7801 no_ospf_authentication_key_authkey_addr_cmd
,
7802 "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7804 "OSPF interface commands\n"
7805 VLINK_HELPSTR_AUTH_SIMPLE
7806 "Address of interface\n")
7808 return no_ip_ospf_authentication_key(self
, vty
, argc
, argv
);
7811 DEFUN (ip_ospf_message_digest_key
,
7812 ip_ospf_message_digest_key_cmd
,
7813 "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7815 "OSPF interface commands\n"
7816 "Message digest authentication password (key)\n"
7818 "Use MD5 algorithm\n"
7819 "The OSPF password (key)\n"
7820 "Address of interface\n")
7822 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7823 struct crypt_key
*ck
;
7825 struct in_addr addr
;
7826 struct ospf_if_params
*params
;
7828 params
= IF_DEF_PARAMS(ifp
);
7831 argv_find(argv
, argc
, "(1-255)", &idx
);
7832 char *keyid
= argv
[idx
]->arg
;
7833 argv_find(argv
, argc
, "KEY", &idx
);
7834 char *cryptkey
= argv
[idx
]->arg
;
7836 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7837 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7839 "Please specify interface address by A.B.C.D\n");
7840 return CMD_WARNING_CONFIG_FAILED
;
7843 params
= ospf_get_if_params(ifp
, addr
);
7844 ospf_if_update_params(ifp
, addr
);
7847 key_id
= strtol(keyid
, NULL
, 10);
7849 /* Remove existing key, if any */
7850 ospf_crypt_key_delete(params
->auth_crypt
, key_id
);
7852 ck
= ospf_crypt_key_new();
7853 ck
->key_id
= (uint8_t)key_id
;
7854 strlcpy((char *)ck
->auth_key
, cryptkey
, sizeof(ck
->auth_key
));
7856 ospf_crypt_key_add(params
->auth_crypt
, ck
);
7857 SET_IF_PARAM(params
, auth_crypt
);
7862 DEFUN_HIDDEN (ospf_message_digest_key
,
7863 ospf_message_digest_key_cmd
,
7864 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7865 "OSPF interface commands\n"
7866 "Message digest authentication password (key)\n"
7868 "Use MD5 algorithm\n"
7869 "The OSPF password (key)\n"
7870 "Address of interface\n")
7872 return ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7875 DEFUN (no_ip_ospf_message_digest_key
,
7876 no_ip_ospf_message_digest_key_cmd
,
7877 "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7880 "OSPF interface commands\n"
7881 "Message digest authentication password (key)\n"
7883 "Use MD5 algorithm\n"
7884 "The OSPF password (key)\n"
7885 "Address of interface\n")
7887 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7889 struct crypt_key
*ck
;
7891 struct in_addr addr
;
7892 struct ospf_if_params
*params
;
7893 params
= IF_DEF_PARAMS(ifp
);
7895 argv_find(argv
, argc
, "(1-255)", &idx
);
7896 char *keyid
= argv
[idx
]->arg
;
7898 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7899 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7901 "Please specify interface address by A.B.C.D\n");
7902 return CMD_WARNING_CONFIG_FAILED
;
7905 params
= ospf_lookup_if_params(ifp
, addr
);
7910 key_id
= strtol(keyid
, NULL
, 10);
7911 ck
= ospf_crypt_key_lookup(params
->auth_crypt
, key_id
);
7913 vty_out(vty
, "OSPF: Key %d does not exist\n", key_id
);
7914 return CMD_WARNING_CONFIG_FAILED
;
7917 ospf_crypt_key_delete(params
->auth_crypt
, key_id
);
7919 if (params
!= IF_DEF_PARAMS(ifp
)) {
7920 ospf_free_if_params(ifp
, addr
);
7921 ospf_if_update_params(ifp
, addr
);
7927 DEFUN_HIDDEN (no_ospf_message_digest_key
,
7928 no_ospf_message_digest_key_cmd
,
7929 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7931 "OSPF interface commands\n"
7932 "Message digest authentication password (key)\n"
7934 "Use MD5 algorithm\n"
7935 "The OSPF password (key)\n"
7936 "Address of interface\n")
7938 return no_ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7941 DEFUN (ip_ospf_cost
,
7943 "ip ospf cost (1-65535) [A.B.C.D]",
7945 "OSPF interface commands\n"
7948 "Address of interface\n")
7950 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7952 uint32_t cost
= OSPF_OUTPUT_COST_DEFAULT
;
7953 struct in_addr addr
;
7954 struct ospf_if_params
*params
;
7955 params
= IF_DEF_PARAMS(ifp
);
7958 char *coststr
= NULL
, *ifaddr
= NULL
;
7960 argv_find(argv
, argc
, "(1-65535)", &idx
);
7961 coststr
= argv
[idx
]->arg
;
7962 cost
= strtol(coststr
, NULL
, 10);
7964 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7966 if (!inet_aton(ifaddr
, &addr
)) {
7968 "Please specify interface address by A.B.C.D\n");
7969 return CMD_WARNING_CONFIG_FAILED
;
7972 params
= ospf_get_if_params(ifp
, addr
);
7973 ospf_if_update_params(ifp
, addr
);
7976 SET_IF_PARAM(params
, output_cost_cmd
);
7977 params
->output_cost_cmd
= cost
;
7979 ospf_if_recalculate_output_cost(ifp
);
7984 DEFUN_HIDDEN (ospf_cost
,
7986 "ospf cost (1-65535) [A.B.C.D]",
7987 "OSPF interface commands\n"
7990 "Address of interface\n")
7992 return ip_ospf_cost(self
, vty
, argc
, argv
);
7995 DEFUN (no_ip_ospf_cost
,
7996 no_ip_ospf_cost_cmd
,
7997 "no ip ospf cost [(1-65535)] [A.B.C.D]",
8000 "OSPF interface commands\n"
8003 "Address of interface\n")
8005 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8007 struct in_addr addr
;
8008 struct ospf_if_params
*params
;
8010 params
= IF_DEF_PARAMS(ifp
);
8013 char *ifaddr
= NULL
;
8014 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
8016 /* According to the semantics we are mimicking "no ip ospf cost N" is
8017 * always treated as "no ip ospf cost" regardless of the actual value
8018 * of N already configured for the interface. Thus ignore cost. */
8021 if (!inet_aton(ifaddr
, &addr
)) {
8023 "Please specify interface address by A.B.C.D\n");
8024 return CMD_WARNING_CONFIG_FAILED
;
8027 params
= ospf_lookup_if_params(ifp
, addr
);
8032 UNSET_IF_PARAM(params
, output_cost_cmd
);
8034 if (params
!= IF_DEF_PARAMS(ifp
)) {
8035 ospf_free_if_params(ifp
, addr
);
8036 ospf_if_update_params(ifp
, addr
);
8039 ospf_if_recalculate_output_cost(ifp
);
8044 DEFUN_HIDDEN (no_ospf_cost
,
8046 "no ospf cost [(1-65535)] [A.B.C.D]",
8048 "OSPF interface commands\n"
8051 "Address of interface\n")
8053 return no_ip_ospf_cost(self
, vty
, argc
, argv
);
8056 static void ospf_nbr_timer_update(struct ospf_interface
*oi
)
8058 struct route_node
*rn
;
8059 struct ospf_neighbor
*nbr
;
8061 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
8067 nbr
->v_inactivity
= OSPF_IF_PARAM(oi
, v_wait
);
8068 nbr
->v_db_desc
= OSPF_IF_PARAM(oi
, retransmit_interval
);
8069 nbr
->v_ls_req
= OSPF_IF_PARAM(oi
, retransmit_interval
);
8070 nbr
->v_ls_upd
= OSPF_IF_PARAM(oi
, retransmit_interval
);
8074 static int ospf_vty_dead_interval_set(struct vty
*vty
, const char *interval_str
,
8075 const char *nbr_str
,
8076 const char *fast_hello_str
)
8078 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8081 struct in_addr addr
;
8083 struct ospf_if_params
*params
;
8084 struct ospf_interface
*oi
;
8085 struct route_node
*rn
;
8087 params
= IF_DEF_PARAMS(ifp
);
8090 ret
= inet_aton(nbr_str
, &addr
);
8093 "Please specify interface address by A.B.C.D\n");
8094 return CMD_WARNING_CONFIG_FAILED
;
8097 params
= ospf_get_if_params(ifp
, addr
);
8098 ospf_if_update_params(ifp
, addr
);
8102 seconds
= strtoul(interval_str
, NULL
, 10);
8104 /* reset fast_hello too, just to be sure */
8105 UNSET_IF_PARAM(params
, fast_hello
);
8106 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
8107 } else if (fast_hello_str
) {
8108 hellomult
= strtoul(fast_hello_str
, NULL
, 10);
8109 /* 1s dead-interval with sub-second hellos desired */
8110 seconds
= OSPF_ROUTER_DEAD_INTERVAL_MINIMAL
;
8111 SET_IF_PARAM(params
, fast_hello
);
8112 params
->fast_hello
= hellomult
;
8115 "Please specify dead-interval or hello-multiplier\n");
8116 return CMD_WARNING_CONFIG_FAILED
;
8119 SET_IF_PARAM(params
, v_wait
);
8120 params
->v_wait
= seconds
;
8121 params
->is_v_wait_set
= true;
8123 /* Update timer values in neighbor structure. */
8125 struct ospf
*ospf
= NULL
;
8127 ospf
= ifp
->vrf
->info
;
8129 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
8131 ospf_nbr_timer_update(oi
);
8134 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
8135 if ((oi
= rn
->info
))
8136 ospf_nbr_timer_update(oi
);
8142 DEFUN (ip_ospf_dead_interval
,
8143 ip_ospf_dead_interval_cmd
,
8144 "ip ospf dead-interval (1-65535) [A.B.C.D]",
8146 "OSPF interface commands\n"
8147 "Interval time after which a neighbor is declared down\n"
8149 "Address of interface\n")
8152 char *interval
= argv_find(argv
, argc
, "(1-65535)", &idx
)
8156 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
8157 return ospf_vty_dead_interval_set(vty
, interval
, ifaddr
, NULL
);
8161 DEFUN_HIDDEN (ospf_dead_interval
,
8162 ospf_dead_interval_cmd
,
8163 "ospf dead-interval (1-65535) [A.B.C.D]",
8164 "OSPF interface commands\n"
8165 "Interval time after which a neighbor is declared down\n"
8167 "Address of interface\n")
8169 return ip_ospf_dead_interval(self
, vty
, argc
, argv
);
8172 DEFUN (ip_ospf_dead_interval_minimal
,
8173 ip_ospf_dead_interval_minimal_addr_cmd
,
8174 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
8176 "OSPF interface commands\n"
8177 "Interval time after which a neighbor is declared down\n"
8178 "Minimal 1s dead-interval with fast sub-second hellos\n"
8179 "Hello multiplier factor\n"
8180 "Number of Hellos to send each second\n"
8181 "Address of interface\n")
8186 return ospf_vty_dead_interval_set(
8187 vty
, NULL
, argv
[idx_ipv4
]->arg
, argv
[idx_number
]->arg
);
8189 return ospf_vty_dead_interval_set(vty
, NULL
, NULL
,
8190 argv
[idx_number
]->arg
);
8193 DEFUN (no_ip_ospf_dead_interval
,
8194 no_ip_ospf_dead_interval_cmd
,
8195 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8198 "OSPF interface commands\n"
8199 "Interval time after which a neighbor is declared down\n"
8201 "Minimal 1s dead-interval with fast sub-second hellos\n"
8202 "Hello multiplier factor\n"
8203 "Number of Hellos to send each second\n"
8204 "Address of interface\n")
8206 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8207 int idx_ipv4
= argc
- 1;
8208 struct in_addr addr
= {.s_addr
= 0L};
8210 struct ospf_if_params
*params
;
8211 struct ospf_interface
*oi
;
8212 struct route_node
*rn
;
8214 params
= IF_DEF_PARAMS(ifp
);
8216 if (argv
[idx_ipv4
]->type
== IPV4_TKN
) {
8217 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8220 "Please specify interface address by A.B.C.D\n");
8221 return CMD_WARNING_CONFIG_FAILED
;
8224 params
= ospf_lookup_if_params(ifp
, addr
);
8229 UNSET_IF_PARAM(params
, v_wait
);
8230 params
->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
8231 params
->is_v_wait_set
= false;
8233 UNSET_IF_PARAM(params
, fast_hello
);
8234 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
8236 if (params
!= IF_DEF_PARAMS(ifp
)) {
8237 ospf_free_if_params(ifp
, addr
);
8238 ospf_if_update_params(ifp
, addr
);
8241 /* Update timer values in neighbor structure. */
8243 struct ospf
*ospf
= NULL
;
8245 ospf
= ifp
->vrf
->info
;
8247 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
8249 ospf_nbr_timer_update(oi
);
8252 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
8253 if ((oi
= rn
->info
))
8254 ospf_nbr_timer_update(oi
);
8260 DEFUN_HIDDEN (no_ospf_dead_interval
,
8261 no_ospf_dead_interval_cmd
,
8262 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8264 "OSPF interface commands\n"
8265 "Interval time after which a neighbor is declared down\n"
8267 "Minimal 1s dead-interval with fast sub-second hellos\n"
8268 "Hello multiplier factor\n"
8269 "Number of Hellos to send each second\n"
8270 "Address of interface\n")
8272 return no_ip_ospf_dead_interval(self
, vty
, argc
, argv
);
8275 DEFUN (ip_ospf_hello_interval
,
8276 ip_ospf_hello_interval_cmd
,
8277 "ip ospf hello-interval (1-65535) [A.B.C.D]",
8279 "OSPF interface commands\n"
8280 "Time between HELLO packets\n"
8282 "Address of interface\n")
8284 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8286 struct in_addr addr
= {.s_addr
= 0L};
8287 struct ospf_if_params
*params
;
8288 params
= IF_DEF_PARAMS(ifp
);
8289 uint32_t seconds
= 0;
8290 bool is_addr
= false;
8291 uint32_t old_interval
= 0;
8293 argv_find(argv
, argc
, "(1-65535)", &idx
);
8294 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
8296 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8297 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8299 "Please specify interface address by A.B.C.D\n");
8300 return CMD_WARNING_CONFIG_FAILED
;
8303 params
= ospf_get_if_params(ifp
, addr
);
8304 ospf_if_update_params(ifp
, addr
);
8308 old_interval
= params
->v_hello
;
8310 /* Return, if same interval is configured. */
8311 if (old_interval
== seconds
)
8314 SET_IF_PARAM(params
, v_hello
);
8315 params
->v_hello
= seconds
;
8317 if (!params
->is_v_wait_set
) {
8318 SET_IF_PARAM(params
, v_wait
);
8320 * The router dead interval should
8321 * be some multiple of the HelloInterval (perhaps 4 times the
8322 * hello interval) and must be the same for all routers
8323 * attached to a common network.
8325 params
->v_wait
= 4 * seconds
;
8328 ospf_reset_hello_timer(ifp
, addr
, is_addr
);
8333 DEFUN_HIDDEN (ospf_hello_interval
,
8334 ospf_hello_interval_cmd
,
8335 "ospf hello-interval (1-65535) [A.B.C.D]",
8336 "OSPF interface commands\n"
8337 "Time between HELLO packets\n"
8339 "Address of interface\n")
8341 return ip_ospf_hello_interval(self
, vty
, argc
, argv
);
8344 DEFUN (no_ip_ospf_hello_interval
,
8345 no_ip_ospf_hello_interval_cmd
,
8346 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
8349 "OSPF interface commands\n"
8350 "Time between HELLO packets\n" // ignored
8352 "Address of interface\n")
8354 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8356 struct in_addr addr
= {.s_addr
= 0L};
8357 struct ospf_if_params
*params
;
8358 struct route_node
*rn
;
8360 params
= IF_DEF_PARAMS(ifp
);
8362 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8363 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8365 "Please specify interface address by A.B.C.D\n");
8366 return CMD_WARNING_CONFIG_FAILED
;
8369 params
= ospf_lookup_if_params(ifp
, addr
);
8374 UNSET_IF_PARAM(params
, v_hello
);
8375 params
->v_hello
= OSPF_HELLO_INTERVAL_DEFAULT
;
8377 if (!params
->is_v_wait_set
) {
8378 UNSET_IF_PARAM(params
, v_wait
);
8379 params
->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
8382 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8383 struct ospf_interface
*oi
= rn
->info
;
8388 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
8389 oi
->ptp_dmvpn
= IF_DEF_PARAMS(ifp
)->ptp_dmvpn
;
8391 if (oi
->state
> ISM_Down
) {
8392 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
8393 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
8397 if (params
!= IF_DEF_PARAMS(ifp
)) {
8398 ospf_free_if_params(ifp
, addr
);
8399 ospf_if_update_params(ifp
, addr
);
8405 DEFUN_HIDDEN (no_ospf_hello_interval
,
8406 no_ospf_hello_interval_cmd
,
8407 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
8409 "OSPF interface commands\n"
8410 "Time between HELLO packets\n" // ignored
8412 "Address of interface\n")
8414 return no_ip_ospf_hello_interval(self
, vty
, argc
, argv
);
8417 DEFUN(ip_ospf_network
, ip_ospf_network_cmd
,
8418 "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point [dmvpn]>",
8420 "OSPF interface commands\n"
8422 "Specify OSPF broadcast multi-access network\n"
8423 "Specify OSPF NBMA network\n"
8424 "Specify OSPF point-to-multipoint network\n"
8425 "Specify OSPF point-to-point network\n"
8426 "Specify OSPF point-to-point DMVPN network\n")
8428 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8430 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
8431 uint8_t old_ptp_dmvpn
= IF_DEF_PARAMS(ifp
)->ptp_dmvpn
;
8432 struct route_node
*rn
;
8434 if (old_type
== OSPF_IFTYPE_LOOPBACK
) {
8436 "This is a loopback interface. Can't set network type.\n");
8437 return CMD_WARNING_CONFIG_FAILED
;
8440 IF_DEF_PARAMS(ifp
)->ptp_dmvpn
= 0;
8442 if (argv_find(argv
, argc
, "broadcast", &idx
))
8443 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_BROADCAST
;
8444 else if (argv_find(argv
, argc
, "non-broadcast", &idx
))
8445 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_NBMA
;
8446 else if (argv_find(argv
, argc
, "point-to-multipoint", &idx
))
8447 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOMULTIPOINT
;
8448 else if (argv_find(argv
, argc
, "point-to-point", &idx
)) {
8449 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOPOINT
;
8450 if (argv_find(argv
, argc
, "dmvpn", &idx
))
8451 IF_DEF_PARAMS(ifp
)->ptp_dmvpn
= 1;
8454 if (IF_DEF_PARAMS(ifp
)->type
== old_type
8455 && IF_DEF_PARAMS(ifp
)->ptp_dmvpn
== old_ptp_dmvpn
)
8458 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), type
);
8460 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8461 struct ospf_interface
*oi
= rn
->info
;
8466 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
8468 if (oi
->state
> ISM_Down
) {
8469 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
8470 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
8477 DEFUN_HIDDEN (ospf_network
,
8479 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
8480 "OSPF interface commands\n"
8482 "Specify OSPF broadcast multi-access network\n"
8483 "Specify OSPF NBMA network\n"
8484 "Specify OSPF point-to-multipoint network\n"
8485 "Specify OSPF point-to-point network\n")
8487 return ip_ospf_network(self
, vty
, argc
, argv
);
8490 DEFUN (no_ip_ospf_network
,
8491 no_ip_ospf_network_cmd
,
8492 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8495 "OSPF interface commands\n"
8497 "Specify OSPF broadcast multi-access network\n"
8498 "Specify OSPF NBMA network\n"
8499 "Specify OSPF point-to-multipoint network\n"
8500 "Specify OSPF point-to-point network\n")
8502 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8503 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
8504 struct route_node
*rn
;
8506 IF_DEF_PARAMS(ifp
)->type
= ospf_default_iftype(ifp
);
8507 IF_DEF_PARAMS(ifp
)->ptp_dmvpn
= 0;
8509 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
8512 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8513 struct ospf_interface
*oi
= rn
->info
;
8518 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
8520 if (oi
->state
> ISM_Down
) {
8521 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
8522 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
8529 DEFUN_HIDDEN (no_ospf_network
,
8530 no_ospf_network_cmd
,
8531 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8533 "OSPF interface commands\n"
8535 "Specify OSPF broadcast multi-access network\n"
8536 "Specify OSPF NBMA network\n"
8537 "Specify OSPF point-to-multipoint network\n"
8538 "Specify OSPF point-to-point network\n")
8540 return no_ip_ospf_network(self
, vty
, argc
, argv
);
8543 DEFUN (ip_ospf_priority
,
8544 ip_ospf_priority_cmd
,
8545 "ip ospf priority (0-255) [A.B.C.D]",
8547 "OSPF interface commands\n"
8550 "Address of interface\n")
8552 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8555 struct route_node
*rn
;
8556 struct in_addr addr
;
8557 struct ospf_if_params
*params
;
8558 params
= IF_DEF_PARAMS(ifp
);
8560 argv_find(argv
, argc
, "(0-255)", &idx
);
8561 priority
= strtol(argv
[idx
]->arg
, NULL
, 10);
8563 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8564 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8566 "Please specify interface address by A.B.C.D\n");
8567 return CMD_WARNING_CONFIG_FAILED
;
8570 params
= ospf_get_if_params(ifp
, addr
);
8571 ospf_if_update_params(ifp
, addr
);
8574 SET_IF_PARAM(params
, priority
);
8575 params
->priority
= priority
;
8577 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8578 struct ospf_interface
*oi
= rn
->info
;
8583 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
8584 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
8585 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
8592 DEFUN_HIDDEN (ospf_priority
,
8594 "ospf priority (0-255) [A.B.C.D]",
8595 "OSPF interface commands\n"
8598 "Address of interface\n")
8600 return ip_ospf_priority(self
, vty
, argc
, argv
);
8603 DEFUN (no_ip_ospf_priority
,
8604 no_ip_ospf_priority_cmd
,
8605 "no ip ospf priority [(0-255) [A.B.C.D]]",
8608 "OSPF interface commands\n"
8609 "Router priority\n" // ignored
8611 "Address of interface\n")
8613 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8615 struct route_node
*rn
;
8616 struct in_addr addr
;
8617 struct ospf_if_params
*params
;
8619 params
= IF_DEF_PARAMS(ifp
);
8621 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8622 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8624 "Please specify interface address by A.B.C.D\n");
8625 return CMD_WARNING_CONFIG_FAILED
;
8628 params
= ospf_lookup_if_params(ifp
, addr
);
8633 UNSET_IF_PARAM(params
, priority
);
8634 params
->priority
= OSPF_ROUTER_PRIORITY_DEFAULT
;
8636 if (params
!= IF_DEF_PARAMS(ifp
)) {
8637 ospf_free_if_params(ifp
, addr
);
8638 ospf_if_update_params(ifp
, addr
);
8641 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8642 struct ospf_interface
*oi
= rn
->info
;
8647 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
8648 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
8649 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
8656 DEFUN_HIDDEN (no_ospf_priority
,
8657 no_ospf_priority_cmd
,
8658 "no ospf priority [(0-255) [A.B.C.D]]",
8660 "OSPF interface commands\n"
8663 "Address of interface\n")
8665 return no_ip_ospf_priority(self
, vty
, argc
, argv
);
8668 DEFUN (ip_ospf_retransmit_interval
,
8669 ip_ospf_retransmit_interval_addr_cmd
,
8670 "ip ospf retransmit-interval (1-65535) [A.B.C.D]",
8672 "OSPF interface commands\n"
8673 "Time between retransmitting lost link state advertisements\n"
8675 "Address of interface\n")
8677 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8680 struct in_addr addr
;
8681 struct ospf_if_params
*params
;
8682 params
= IF_DEF_PARAMS(ifp
);
8684 argv_find(argv
, argc
, "(1-65535)", &idx
);
8685 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
8687 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8688 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8690 "Please specify interface address by A.B.C.D\n");
8691 return CMD_WARNING_CONFIG_FAILED
;
8694 params
= ospf_get_if_params(ifp
, addr
);
8695 ospf_if_update_params(ifp
, addr
);
8698 SET_IF_PARAM(params
, retransmit_interval
);
8699 params
->retransmit_interval
= seconds
;
8704 DEFUN_HIDDEN (ospf_retransmit_interval
,
8705 ospf_retransmit_interval_cmd
,
8706 "ospf retransmit-interval (1-65535) [A.B.C.D]",
8707 "OSPF interface commands\n"
8708 "Time between retransmitting lost link state advertisements\n"
8710 "Address of interface\n")
8712 return ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
8715 DEFUN (no_ip_ospf_retransmit_interval
,
8716 no_ip_ospf_retransmit_interval_addr_cmd
,
8717 "no ip ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8720 "OSPF interface commands\n"
8721 "Time between retransmitting lost link state advertisements\n"
8723 "Address of interface\n")
8725 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8727 struct in_addr addr
;
8728 struct ospf_if_params
*params
;
8730 params
= IF_DEF_PARAMS(ifp
);
8732 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8733 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8735 "Please specify interface address by A.B.C.D\n");
8736 return CMD_WARNING_CONFIG_FAILED
;
8739 params
= ospf_lookup_if_params(ifp
, addr
);
8744 UNSET_IF_PARAM(params
, retransmit_interval
);
8745 params
->retransmit_interval
= OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
8747 if (params
!= IF_DEF_PARAMS(ifp
)) {
8748 ospf_free_if_params(ifp
, addr
);
8749 ospf_if_update_params(ifp
, addr
);
8755 DEFUN_HIDDEN (no_ospf_retransmit_interval
,
8756 no_ospf_retransmit_interval_cmd
,
8757 "no ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8759 "OSPF interface commands\n"
8760 "Time between retransmitting lost link state advertisements\n"
8762 "Address of interface\n")
8764 return no_ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
8767 DEFUN (ip_ospf_transmit_delay
,
8768 ip_ospf_transmit_delay_addr_cmd
,
8769 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
8771 "OSPF interface commands\n"
8772 "Link state transmit delay\n"
8774 "Address of interface\n")
8776 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8779 struct in_addr addr
;
8780 struct ospf_if_params
*params
;
8782 params
= IF_DEF_PARAMS(ifp
);
8783 argv_find(argv
, argc
, "(1-65535)", &idx
);
8784 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
8786 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8787 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8789 "Please specify interface address by A.B.C.D\n");
8790 return CMD_WARNING_CONFIG_FAILED
;
8793 params
= ospf_get_if_params(ifp
, addr
);
8794 ospf_if_update_params(ifp
, addr
);
8797 SET_IF_PARAM(params
, transmit_delay
);
8798 params
->transmit_delay
= seconds
;
8803 DEFUN_HIDDEN (ospf_transmit_delay
,
8804 ospf_transmit_delay_cmd
,
8805 "ospf transmit-delay (1-65535) [A.B.C.D]",
8806 "OSPF interface commands\n"
8807 "Link state transmit delay\n"
8809 "Address of interface\n")
8811 return ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
8814 DEFUN (no_ip_ospf_transmit_delay
,
8815 no_ip_ospf_transmit_delay_addr_cmd
,
8816 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
8819 "OSPF interface commands\n"
8820 "Link state transmit delay\n"
8822 "Address of interface\n")
8824 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8826 struct in_addr addr
;
8827 struct ospf_if_params
*params
;
8829 params
= IF_DEF_PARAMS(ifp
);
8831 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8832 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8834 "Please specify interface address by A.B.C.D\n");
8835 return CMD_WARNING_CONFIG_FAILED
;
8838 params
= ospf_lookup_if_params(ifp
, addr
);
8843 UNSET_IF_PARAM(params
, transmit_delay
);
8844 params
->transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
8846 if (params
!= IF_DEF_PARAMS(ifp
)) {
8847 ospf_free_if_params(ifp
, addr
);
8848 ospf_if_update_params(ifp
, addr
);
8855 DEFUN_HIDDEN (no_ospf_transmit_delay
,
8856 no_ospf_transmit_delay_cmd
,
8857 "no ospf transmit-delay [(1-65535) [A.B.C.D]]",
8859 "OSPF interface commands\n"
8860 "Link state transmit delay\n"
8862 "Address of interface\n")
8864 return no_ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
8867 DEFUN (ip_ospf_area
,
8869 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]",
8871 "OSPF interface commands\n"
8873 "Enable OSPF on this interface\n"
8874 "OSPF area ID in IP address format\n"
8875 "OSPF area ID as a decimal value\n"
8876 "Address of interface\n")
8878 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8881 struct in_addr area_id
;
8882 struct in_addr addr
;
8883 struct ospf_if_params
*params
= NULL
;
8884 struct route_node
*rn
;
8885 struct ospf
*ospf
= NULL
;
8886 unsigned short instance
= 0;
8890 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
8891 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
8893 argv_find(argv
, argc
, "area", &idx
);
8894 areaid
= argv
[idx
+ 1]->arg
;
8897 ospf
= ifp
->vrf
->info
;
8899 ospf
= ospf_lookup_instance(instance
);
8901 if (instance
&& instance
!= ospf_instance
) {
8903 * At this point we know we have received
8904 * an instance and there is no ospf instance
8905 * associated with it. This means we are
8906 * in a situation where we have an
8907 * ospf command that is setup for a different
8908 * process(instance). We need to safely
8909 * remove the command from ourselves and
8910 * allow the other instance(process) handle
8911 * the configuration command.
8915 params
= IF_DEF_PARAMS(ifp
);
8916 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8917 UNSET_IF_PARAM(params
, if_area
);
8921 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
; rn
= route_next(rn
))
8922 if ((params
= rn
->info
) && OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8923 UNSET_IF_PARAM(params
, if_area
);
8928 ospf
= ifp
->vrf
->info
;
8930 ospf_interface_area_unset(ospf
, ifp
);
8933 return CMD_NOT_MY_INSTANCE
;
8936 ret
= str2area_id(areaid
, &area_id
, &format
);
8938 vty_out(vty
, "Please specify area by A.B.C.D|<0-4294967295>\n");
8939 return CMD_WARNING_CONFIG_FAILED
;
8941 if (memcmp(ifp
->name
, "VLINK", 5) == 0) {
8942 vty_out(vty
, "Cannot enable OSPF on a virtual link.\n");
8943 return CMD_WARNING_CONFIG_FAILED
;
8947 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
)) {
8948 if (rn
->info
!= NULL
) {
8950 "Please remove all network commands first.\n");
8951 return CMD_WARNING_CONFIG_FAILED
;
8956 params
= IF_DEF_PARAMS(ifp
);
8957 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)
8958 && !IPV4_ADDR_SAME(¶ms
->if_area
, &area_id
)) {
8960 "Must remove previous area config before changing ospf area \n");
8961 return CMD_WARNING_CONFIG_FAILED
;
8964 // Check if we have an address arg and proccess it
8965 if (argc
== idx
+ 3) {
8966 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
8968 "Please specify Intf Address by A.B.C.D\n");
8969 return CMD_WARNING_CONFIG_FAILED
;
8971 // update/create address-level params
8972 params
= ospf_get_if_params((ifp
), (addr
));
8973 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8974 if (!IPV4_ADDR_SAME(¶ms
->if_area
, &area_id
)) {
8976 "Must remove previous area/address config before changing ospf area\n");
8977 return CMD_WARNING_CONFIG_FAILED
;
8981 ospf_if_update_params((ifp
), (addr
));
8984 /* enable ospf on this interface with area_id */
8986 SET_IF_PARAM(params
, if_area
);
8987 params
->if_area
= area_id
;
8988 params
->if_area_id_fmt
= format
;
8992 ospf_interface_area_set(ospf
, ifp
);
8997 DEFUN (no_ip_ospf_area
,
8998 no_ip_ospf_area_cmd
,
8999 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]",
9002 "OSPF interface commands\n"
9004 "Disable OSPF on this interface\n"
9005 "OSPF area ID in IP address format\n"
9006 "OSPF area ID as a decimal value\n"
9007 "Address of interface\n")
9009 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9012 struct ospf_if_params
*params
;
9013 unsigned short instance
= 0;
9014 struct in_addr addr
;
9015 struct in_addr area_id
;
9017 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
9018 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
9021 ospf
= ifp
->vrf
->info
;
9023 ospf
= ospf_lookup_instance(instance
);
9025 if (instance
&& instance
!= ospf_instance
)
9026 return CMD_NOT_MY_INSTANCE
;
9028 argv_find(argv
, argc
, "area", &idx
);
9030 // Check if we have an address arg and proccess it
9031 if (argc
== idx
+ 3) {
9032 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
9034 "Please specify Intf Address by A.B.C.D\n");
9035 return CMD_WARNING_CONFIG_FAILED
;
9037 params
= ospf_lookup_if_params(ifp
, addr
);
9038 if ((params
) == NULL
)
9041 params
= IF_DEF_PARAMS(ifp
);
9043 area_id
= params
->if_area
;
9044 if (!OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
9046 "Can't find specified interface area configuration.\n");
9047 return CMD_WARNING_CONFIG_FAILED
;
9050 UNSET_IF_PARAM(params
, if_area
);
9051 if (params
!= IF_DEF_PARAMS((ifp
))) {
9052 ospf_free_if_params((ifp
), (addr
));
9053 ospf_if_update_params((ifp
), (addr
));
9057 ospf_interface_area_unset(ospf
, ifp
);
9058 ospf_area_check_free(ospf
, area_id
);
9064 DEFUN (ip_ospf_passive
,
9065 ip_ospf_passive_cmd
,
9066 "ip ospf passive [A.B.C.D]",
9068 "OSPF interface commands\n"
9069 "Suppress routing updates on an interface\n"
9070 "Address of interface\n")
9072 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9074 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
9075 struct ospf_if_params
*params
;
9079 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9082 "Please specify interface address by A.B.C.D\n");
9083 return CMD_WARNING_CONFIG_FAILED
;
9085 params
= ospf_get_if_params(ifp
, addr
);
9086 ospf_if_update_params(ifp
, addr
);
9088 params
= IF_DEF_PARAMS(ifp
);
9091 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_PASSIVE
);
9096 DEFUN (no_ip_ospf_passive
,
9097 no_ip_ospf_passive_cmd
,
9098 "no ip ospf passive [A.B.C.D]",
9101 "OSPF interface commands\n"
9102 "Enable routing updates on an interface\n"
9103 "Address of interface\n")
9105 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9107 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
9108 struct ospf_if_params
*params
;
9112 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9115 "Please specify interface address by A.B.C.D\n");
9116 return CMD_WARNING_CONFIG_FAILED
;
9118 params
= ospf_lookup_if_params(ifp
, addr
);
9122 params
= IF_DEF_PARAMS(ifp
);
9125 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_ACTIVE
);
9130 DEFUN (ospf_redistribute_source
,
9131 ospf_redistribute_source_cmd
,
9132 "redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9134 FRR_REDIST_HELP_STR_OSPFD
9135 "Metric for redistributed routes\n"
9136 "OSPF default metric\n"
9137 "OSPF exterior metric type for redistributed routes\n"
9138 "Set OSPF External Type 1/2 metrics\n"
9139 "Route map reference\n"
9140 "Pointer to route-map entries\n")
9142 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9143 int idx_protocol
= 1;
9147 struct ospf_redist
*red
;
9149 bool update
= false;
9151 /* Get distribute source. */
9152 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
9154 return CMD_WARNING_CONFIG_FAILED
;
9156 /* Get metric value. */
9157 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
9158 if (!str2metric(argv
[idx
]->arg
, &metric
))
9159 return CMD_WARNING_CONFIG_FAILED
;
9162 /* Get metric type. */
9163 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
9164 if (!str2metric_type(argv
[idx
]->arg
, &type
))
9165 return CMD_WARNING_CONFIG_FAILED
;
9169 red
= ospf_redist_lookup(ospf
, source
, 0);
9171 red
= ospf_redist_add(ospf
, source
, 0);
9176 if (argv_find(argv
, argc
, "route-map", &idx
)) {
9177 ospf_routemap_set(red
, argv
[idx
+ 1]->arg
);
9179 ospf_routemap_unset(red
);
9182 return ospf_redistribute_update(ospf
, red
, source
, 0, type
,
9185 return ospf_redistribute_set(ospf
, red
, source
, 0, type
,
9189 DEFUN (no_ospf_redistribute_source
,
9190 no_ospf_redistribute_source_cmd
,
9191 "no redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9194 FRR_REDIST_HELP_STR_OSPFD
9195 "Metric for redistributed routes\n"
9196 "OSPF default metric\n"
9197 "OSPF exterior metric type for redistributed routes\n"
9198 "Set OSPF External Type 1/2 metrics\n"
9199 "Route map reference\n"
9200 "Pointer to route-map entries\n")
9202 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9203 int idx_protocol
= 2;
9205 struct ospf_redist
*red
;
9207 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
9209 return CMD_WARNING_CONFIG_FAILED
;
9211 red
= ospf_redist_lookup(ospf
, source
, 0);
9215 ospf_routemap_unset(red
);
9216 ospf_redist_del(ospf
, source
, 0);
9218 return ospf_redistribute_unset(ospf
, source
, 0);
9221 DEFUN (ospf_redistribute_instance_source
,
9222 ospf_redistribute_instance_source_cmd
,
9223 "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9225 "Open Shortest Path First\n"
9226 "Non-main Kernel Routing Table\n"
9227 "Instance ID/Table ID\n"
9228 "Metric for redistributed routes\n"
9229 "OSPF default metric\n"
9230 "OSPF exterior metric type for redistributed routes\n"
9231 "Set OSPF External Type 1/2 metrics\n"
9232 "Route map reference\n"
9233 "Pointer to route-map entries\n")
9235 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9236 int idx_ospf_table
= 1;
9242 unsigned short instance
;
9243 struct ospf_redist
*red
;
9244 bool update
= false;
9246 source
= proto_redistnum(AFI_IP
, argv
[idx_ospf_table
]->text
);
9249 vty_out(vty
, "Unknown instance redistribution\n");
9250 return CMD_WARNING_CONFIG_FAILED
;
9253 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9255 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
9257 "Instance redistribution in non-instanced OSPF not allowed\n");
9258 return CMD_WARNING_CONFIG_FAILED
;
9261 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
9262 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
9263 return CMD_WARNING_CONFIG_FAILED
;
9266 /* Get metric value. */
9267 if (argv_find(argv
, argc
, "metric", &idx
))
9268 if (!str2metric(argv
[idx
+ 1]->arg
, &metric
))
9269 return CMD_WARNING_CONFIG_FAILED
;
9272 /* Get metric type. */
9273 if (argv_find(argv
, argc
, "metric-type", &idx
))
9274 if (!str2metric_type(argv
[idx
+ 1]->arg
, &type
))
9275 return CMD_WARNING_CONFIG_FAILED
;
9277 red
= ospf_redist_lookup(ospf
, source
, instance
);
9279 red
= ospf_redist_add(ospf
, source
, instance
);
9284 if (argv_find(argv
, argc
, "route-map", &idx
))
9285 ospf_routemap_set(red
, argv
[idx
+ 1]->arg
);
9287 ospf_routemap_unset(red
);
9290 return ospf_redistribute_update(ospf
, red
, source
, instance
,
9293 return ospf_redistribute_set(ospf
, red
, source
, instance
, type
,
9297 DEFUN (no_ospf_redistribute_instance_source
,
9298 no_ospf_redistribute_instance_source_cmd
,
9299 "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9302 "Open Shortest Path First\n"
9303 "Non-main Kernel Routing Table\n"
9304 "Instance ID/Table Id\n"
9305 "Metric for redistributed routes\n"
9306 "OSPF default metric\n"
9307 "OSPF exterior metric type for redistributed routes\n"
9308 "Set OSPF External Type 1/2 metrics\n"
9309 "Route map reference\n"
9310 "Pointer to route-map entries\n")
9312 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9313 int idx_ospf_table
= 2;
9315 unsigned int instance
;
9316 struct ospf_redist
*red
;
9319 if (strncmp(argv
[idx_ospf_table
]->arg
, "o", 1) == 0)
9320 source
= ZEBRA_ROUTE_OSPF
;
9322 source
= ZEBRA_ROUTE_TABLE
;
9324 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9326 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
9328 "Instance redistribution in non-instanced OSPF not allowed\n");
9329 return CMD_WARNING_CONFIG_FAILED
;
9332 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
9333 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
9334 return CMD_WARNING_CONFIG_FAILED
;
9337 red
= ospf_redist_lookup(ospf
, source
, instance
);
9341 ospf_routemap_unset(red
);
9342 ospf_redist_del(ospf
, source
, instance
);
9344 return ospf_redistribute_unset(ospf
, source
, instance
);
9347 DEFUN (ospf_distribute_list_out
,
9348 ospf_distribute_list_out_cmd
,
9349 "distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD
,
9350 "Filter networks in routing updates\n"
9351 "Access-list name\n"
9353 FRR_REDIST_HELP_STR_OSPFD
)
9355 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9359 char *proto
= argv
[argc
- 1]->text
;
9361 /* Get distribute source. */
9362 source
= proto_redistnum(AFI_IP
, proto
);
9364 return CMD_WARNING_CONFIG_FAILED
;
9366 return ospf_distribute_list_out_set(ospf
, source
, argv
[idx_word
]->arg
);
9369 DEFUN (no_ospf_distribute_list_out
,
9370 no_ospf_distribute_list_out_cmd
,
9371 "no distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD
,
9373 "Filter networks in routing updates\n"
9374 "Access-list name\n"
9376 FRR_REDIST_HELP_STR_OSPFD
)
9378 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9382 char *proto
= argv
[argc
- 1]->text
;
9383 source
= proto_redistnum(AFI_IP
, proto
);
9385 return CMD_WARNING_CONFIG_FAILED
;
9387 return ospf_distribute_list_out_unset(ospf
, source
,
9388 argv
[idx_word
]->arg
);
9391 /* Default information originate. */
9392 DEFUN (ospf_default_information_originate
,
9393 ospf_default_information_originate_cmd
,
9394 "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9395 "Control distribution of default information\n"
9396 "Distribute a default route\n"
9397 "Always advertise default route\n"
9398 "OSPF default metric\n"
9400 "OSPF metric type for default routes\n"
9401 "Set OSPF External Type 1/2 metrics\n"
9402 "Route map reference\n"
9403 "Pointer to route-map entries\n")
9405 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9406 int default_originate
= DEFAULT_ORIGINATE_ZEBRA
;
9409 struct ospf_redist
*red
;
9411 int cur_originate
= ospf
->default_originate
;
9412 bool sameRtmap
= false;
9415 red
= ospf_redist_add(ospf
, DEFAULT_ROUTE
, 0);
9417 /* Check whether "always" was specified */
9418 if (argv_find(argv
, argc
, "always", &idx
))
9419 default_originate
= DEFAULT_ORIGINATE_ALWAYS
;
9421 /* Get metric value */
9422 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
9423 if (!str2metric(argv
[idx
]->arg
, &metric
))
9424 return CMD_WARNING_CONFIG_FAILED
;
9427 /* Get metric type. */
9428 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
9429 if (!str2metric_type(argv
[idx
]->arg
, &type
))
9430 return CMD_WARNING_CONFIG_FAILED
;
9434 if (argv_find(argv
, argc
, "route-map", &idx
))
9435 rtmap
= argv
[idx
+ 1]->arg
;
9437 /* To check if user is providing same route map */
9438 if ((!rtmap
&& !ROUTEMAP_NAME(red
)) ||
9439 (rtmap
&& ROUTEMAP_NAME(red
) &&
9440 (strcmp(rtmap
, ROUTEMAP_NAME(red
)) == 0)))
9443 /* Don't allow if the same lsa is already originated. */
9445 && (red
->dmetric
.type
== type
)
9446 && (red
->dmetric
.value
== metric
)
9447 && (cur_originate
== default_originate
))
9450 /* Updating Metric details */
9451 red
->dmetric
.type
= type
;
9452 red
->dmetric
.value
= metric
;
9454 /* updating route map details */
9456 ospf_routemap_set(red
, rtmap
);
9458 ospf_routemap_unset(red
);
9460 return ospf_redistribute_default_set(ospf
, default_originate
, type
,
9464 DEFUN (no_ospf_default_information_originate
,
9465 no_ospf_default_information_originate_cmd
,
9466 "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9468 "Control distribution of default information\n"
9469 "Distribute a default route\n"
9470 "Always advertise default route\n"
9471 "OSPF default metric\n"
9473 "OSPF metric type for default routes\n"
9474 "Set OSPF External Type 1/2 metrics\n"
9475 "Route map reference\n"
9476 "Pointer to route-map entries\n")
9478 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9479 struct ospf_redist
*red
;
9481 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
9485 ospf_routemap_unset(red
);
9486 ospf_redist_del(ospf
, DEFAULT_ROUTE
, 0);
9488 return ospf_redistribute_default_set(ospf
, DEFAULT_ORIGINATE_NONE
,
9492 DEFUN (ospf_default_metric
,
9493 ospf_default_metric_cmd
,
9494 "default-metric (0-16777214)",
9495 "Set metric of redistributed routes\n"
9498 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9502 if (!str2metric(argv
[idx_number
]->arg
, &metric
))
9503 return CMD_WARNING_CONFIG_FAILED
;
9505 ospf
->default_metric
= metric
;
9510 DEFUN (no_ospf_default_metric
,
9511 no_ospf_default_metric_cmd
,
9512 "no default-metric [(0-16777214)]",
9514 "Set metric of redistributed routes\n"
9517 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9519 ospf
->default_metric
= -1;
9525 DEFUN (ospf_distance
,
9528 "Administrative distance\n"
9529 "OSPF Administrative distance\n")
9531 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9535 distance
= atoi(argv
[idx_number
]->arg
);
9536 if (ospf
->distance_all
!= distance
) {
9537 ospf
->distance_all
= distance
;
9538 ospf_restart_spf(ospf
);
9544 DEFUN (no_ospf_distance
,
9545 no_ospf_distance_cmd
,
9546 "no distance (1-255)",
9548 "Administrative distance\n"
9549 "OSPF Administrative distance\n")
9551 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9553 if (ospf
->distance_all
) {
9554 ospf
->distance_all
= 0;
9555 ospf_restart_spf(ospf
);
9561 DEFUN (no_ospf_distance_ospf
,
9562 no_ospf_distance_ospf_cmd
,
9563 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
9565 "Administrative distance\n"
9566 "OSPF administrative distance\n"
9567 "Intra-area routes\n"
9568 "Distance for intra-area routes\n"
9569 "Inter-area routes\n"
9570 "Distance for inter-area routes\n"
9572 "Distance for external routes\n")
9574 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9577 if (argv_find(argv
, argc
, "intra-area", &idx
) || argc
== 3)
9578 idx
= ospf
->distance_intra
= 0;
9579 if (argv_find(argv
, argc
, "inter-area", &idx
) || argc
== 3)
9580 idx
= ospf
->distance_inter
= 0;
9581 if (argv_find(argv
, argc
, "external", &idx
) || argc
== 3)
9582 ospf
->distance_external
= 0;
9587 DEFUN (ospf_distance_ospf
,
9588 ospf_distance_ospf_cmd
,
9589 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
9590 "Administrative distance\n"
9591 "OSPF administrative distance\n"
9592 "Intra-area routes\n"
9593 "Distance for intra-area routes\n"
9594 "Inter-area routes\n"
9595 "Distance for inter-area routes\n"
9597 "Distance for external routes\n")
9599 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9602 ospf
->distance_intra
= 0;
9603 ospf
->distance_inter
= 0;
9604 ospf
->distance_external
= 0;
9606 if (argv_find(argv
, argc
, "intra-area", &idx
))
9607 ospf
->distance_intra
= atoi(argv
[idx
+ 1]->arg
);
9609 if (argv_find(argv
, argc
, "inter-area", &idx
))
9610 ospf
->distance_inter
= atoi(argv
[idx
+ 1]->arg
);
9612 if (argv_find(argv
, argc
, "external", &idx
))
9613 ospf
->distance_external
= atoi(argv
[idx
+ 1]->arg
);
9618 DEFUN (ip_ospf_mtu_ignore
,
9619 ip_ospf_mtu_ignore_addr_cmd
,
9620 "ip ospf mtu-ignore [A.B.C.D]",
9622 "OSPF interface commands\n"
9623 "Disable MTU mismatch detection on this interface\n"
9624 "Address of interface\n")
9626 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9628 struct in_addr addr
;
9631 struct ospf_if_params
*params
;
9632 params
= IF_DEF_PARAMS(ifp
);
9635 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9638 "Please specify interface address by A.B.C.D\n");
9639 return CMD_WARNING_CONFIG_FAILED
;
9641 params
= ospf_get_if_params(ifp
, addr
);
9642 ospf_if_update_params(ifp
, addr
);
9644 params
->mtu_ignore
= 1;
9645 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
9646 SET_IF_PARAM(params
, mtu_ignore
);
9648 UNSET_IF_PARAM(params
, mtu_ignore
);
9649 if (params
!= IF_DEF_PARAMS(ifp
)) {
9650 ospf_free_if_params(ifp
, addr
);
9651 ospf_if_update_params(ifp
, addr
);
9657 DEFUN (no_ip_ospf_mtu_ignore
,
9658 no_ip_ospf_mtu_ignore_addr_cmd
,
9659 "no ip ospf mtu-ignore [A.B.C.D]",
9662 "OSPF interface commands\n"
9663 "Disable MTU mismatch detection on this interface\n"
9664 "Address of interface\n")
9666 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9668 struct in_addr addr
;
9671 struct ospf_if_params
*params
;
9672 params
= IF_DEF_PARAMS(ifp
);
9675 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9678 "Please specify interface address by A.B.C.D\n");
9679 return CMD_WARNING_CONFIG_FAILED
;
9681 params
= ospf_get_if_params(ifp
, addr
);
9682 ospf_if_update_params(ifp
, addr
);
9684 params
->mtu_ignore
= 0;
9685 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
9686 SET_IF_PARAM(params
, mtu_ignore
);
9688 UNSET_IF_PARAM(params
, mtu_ignore
);
9689 if (params
!= IF_DEF_PARAMS(ifp
)) {
9690 ospf_free_if_params(ifp
, addr
);
9691 ospf_if_update_params(ifp
, addr
);
9698 DEFUN (ospf_max_metric_router_lsa_admin
,
9699 ospf_max_metric_router_lsa_admin_cmd
,
9700 "max-metric router-lsa administrative",
9701 "OSPF maximum / infinite-distance metric\n"
9702 "Advertise own Router-LSA with infinite distance (stub router)\n"
9703 "Administratively applied, for an indefinite period\n")
9705 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9706 struct listnode
*ln
;
9707 struct ospf_area
*area
;
9709 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
9710 SET_FLAG(area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
);
9712 if (!CHECK_FLAG(area
->stub_router_state
,
9713 OSPF_AREA_IS_STUB_ROUTED
))
9714 ospf_router_lsa_update_area(area
);
9717 /* Allows for areas configured later to get the property */
9718 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
;
9723 DEFUN (no_ospf_max_metric_router_lsa_admin
,
9724 no_ospf_max_metric_router_lsa_admin_cmd
,
9725 "no max-metric router-lsa administrative",
9727 "OSPF maximum / infinite-distance metric\n"
9728 "Advertise own Router-LSA with infinite distance (stub router)\n"
9729 "Administratively applied, for an indefinite period\n")
9731 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9732 struct listnode
*ln
;
9733 struct ospf_area
*area
;
9735 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
9736 UNSET_FLAG(area
->stub_router_state
,
9737 OSPF_AREA_ADMIN_STUB_ROUTED
);
9739 /* Don't trample on the start-up stub timer */
9740 if (CHECK_FLAG(area
->stub_router_state
,
9741 OSPF_AREA_IS_STUB_ROUTED
)
9742 && !area
->t_stub_router
) {
9743 UNSET_FLAG(area
->stub_router_state
,
9744 OSPF_AREA_IS_STUB_ROUTED
);
9745 ospf_router_lsa_update_area(area
);
9748 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET
;
9752 DEFUN (ospf_max_metric_router_lsa_startup
,
9753 ospf_max_metric_router_lsa_startup_cmd
,
9754 "max-metric router-lsa on-startup (5-86400)",
9755 "OSPF maximum / infinite-distance metric\n"
9756 "Advertise own Router-LSA with infinite distance (stub router)\n"
9757 "Automatically advertise stub Router-LSA on startup of OSPF\n"
9758 "Time (seconds) to advertise self as stub-router\n")
9760 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9762 unsigned int seconds
;
9765 vty_out(vty
, "%% Must supply stub-router period\n");
9766 return CMD_WARNING_CONFIG_FAILED
;
9769 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9771 ospf
->stub_router_startup_time
= seconds
;
9776 DEFUN (no_ospf_max_metric_router_lsa_startup
,
9777 no_ospf_max_metric_router_lsa_startup_cmd
,
9778 "no max-metric router-lsa on-startup [(5-86400)]",
9780 "OSPF maximum / infinite-distance metric\n"
9781 "Advertise own Router-LSA with infinite distance (stub router)\n"
9782 "Automatically advertise stub Router-LSA on startup of OSPF\n"
9783 "Time (seconds) to advertise self as stub-router\n")
9785 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9786 struct listnode
*ln
;
9787 struct ospf_area
*area
;
9789 ospf
->stub_router_startup_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
9791 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
9792 SET_FLAG(area
->stub_router_state
,
9793 OSPF_AREA_WAS_START_STUB_ROUTED
);
9794 THREAD_OFF(area
->t_stub_router
);
9796 /* Don't trample on admin stub routed */
9797 if (!CHECK_FLAG(area
->stub_router_state
,
9798 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
9799 UNSET_FLAG(area
->stub_router_state
,
9800 OSPF_AREA_IS_STUB_ROUTED
);
9801 ospf_router_lsa_update_area(area
);
9808 DEFUN (ospf_max_metric_router_lsa_shutdown
,
9809 ospf_max_metric_router_lsa_shutdown_cmd
,
9810 "max-metric router-lsa on-shutdown (5-100)",
9811 "OSPF maximum / infinite-distance metric\n"
9812 "Advertise own Router-LSA with infinite distance (stub router)\n"
9813 "Advertise stub-router prior to full shutdown of OSPF\n"
9814 "Time (seconds) to wait till full shutdown\n")
9816 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9818 unsigned int seconds
;
9821 vty_out(vty
, "%% Must supply stub-router shutdown period\n");
9822 return CMD_WARNING_CONFIG_FAILED
;
9825 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9827 ospf
->stub_router_shutdown_time
= seconds
;
9832 DEFUN (no_ospf_max_metric_router_lsa_shutdown
,
9833 no_ospf_max_metric_router_lsa_shutdown_cmd
,
9834 "no max-metric router-lsa on-shutdown [(5-100)]",
9836 "OSPF maximum / infinite-distance metric\n"
9837 "Advertise own Router-LSA with infinite distance (stub router)\n"
9838 "Advertise stub-router prior to full shutdown of OSPF\n"
9839 "Time (seconds) to wait till full shutdown\n")
9841 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9843 ospf
->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
9848 DEFUN (ospf_proactive_arp
,
9849 ospf_proactive_arp_cmd
,
9851 "Allow sending ARP requests proactively\n")
9853 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9855 ospf
->proactive_arp
= true;
9860 DEFUN (no_ospf_proactive_arp
,
9861 no_ospf_proactive_arp_cmd
,
9864 "Disallow sending ARP requests proactively\n")
9866 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9868 ospf
->proactive_arp
= false;
9873 /* Graceful Restart HELPER Commands */
9874 DEFPY(ospf_gr_helper_enable
, ospf_gr_helper_enable_cmd
,
9875 "graceful-restart helper enable [A.B.C.D$address]",
9876 "OSPF Graceful Restart\n"
9878 "Enable Helper support\n"
9879 "Advertising Router-ID\n")
9881 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9884 ospf_gr_helper_support_set_per_routerid(ospf
, &address
,
9889 ospf_gr_helper_support_set(ospf
, OSPF_GR_TRUE
);
9894 DEFPY(no_ospf_gr_helper_enable
,
9895 no_ospf_gr_helper_enable_cmd
,
9896 "no graceful-restart helper enable [A.B.C.D$address]",
9898 "OSPF Graceful Restart\n"
9900 "Enable Helper support\n"
9901 "Advertising Router-ID\n")
9903 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9906 ospf_gr_helper_support_set_per_routerid(ospf
, &address
,
9911 ospf_gr_helper_support_set(ospf
, OSPF_GR_FALSE
);
9915 DEFPY(ospf_gr_helper_enable_lsacheck
,
9916 ospf_gr_helper_enable_lsacheck_cmd
,
9917 "graceful-restart helper strict-lsa-checking",
9918 "OSPF Graceful Restart\n"
9920 "Enable strict LSA check\n")
9922 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9924 ospf_gr_helper_lsa_check_set(ospf
, OSPF_GR_TRUE
);
9928 DEFPY(no_ospf_gr_helper_enable_lsacheck
,
9929 no_ospf_gr_helper_enable_lsacheck_cmd
,
9930 "no graceful-restart helper strict-lsa-checking",
9932 "OSPF Graceful Restart\n"
9934 "Disable strict LSA check\n")
9936 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9938 ospf_gr_helper_lsa_check_set(ospf
, OSPF_GR_FALSE
);
9942 DEFPY(ospf_gr_helper_supported_grace_time
,
9943 ospf_gr_helper_supported_grace_time_cmd
,
9944 "graceful-restart helper supported-grace-time (10-1800)$interval",
9945 "OSPF Graceful Restart\n"
9947 "Supported grace timer\n"
9948 "Grace interval(in seconds)\n")
9950 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9952 ospf_gr_helper_supported_gracetime_set(ospf
, interval
);
9956 DEFPY(no_ospf_gr_helper_supported_grace_time
,
9957 no_ospf_gr_helper_supported_grace_time_cmd
,
9958 "no graceful-restart helper supported-grace-time (10-1800)$interval",
9960 "OSPF Graceful Restart\n"
9962 "Supported grace timer\n"
9963 "Grace interval(in seconds)\n")
9965 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9967 ospf_gr_helper_supported_gracetime_set(ospf
, OSPF_MAX_GRACE_INTERVAL
);
9971 DEFPY(ospf_gr_helper_planned_only
,
9972 ospf_gr_helper_planned_only_cmd
,
9973 "graceful-restart helper planned-only",
9974 "OSPF Graceful Restart\n"
9976 "Supported only planned restart\n")
9978 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9980 ospf_gr_helper_set_supported_planned_only_restart(ospf
, OSPF_GR_TRUE
);
9985 /* External Route Aggregation */
9986 DEFUN (ospf_external_route_aggregation
,
9987 ospf_external_route_aggregation_cmd
,
9988 "summary-address A.B.C.D/M [tag (1-4294967295)]",
9989 "External summary address\n"
9990 "Summary address prefix\n"
9992 "Router tag value\n")
9994 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9995 struct prefix_ipv4 p
;
9997 route_tag_t tag
= 0;
9998 int ret
= OSPF_SUCCESS
;
10000 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
10002 if (is_default_prefix4(&p
)) {
10004 "Default address shouldn't be configured as summary address.\n");
10005 return CMD_SUCCESS
;
10008 /* Apply mask for given prefix. */
10011 if (!is_valid_summary_addr(&p
)) {
10012 vty_out(vty
, "Not a valid summary address.\n");
10013 return CMD_WARNING_CONFIG_FAILED
;
10017 tag
= strtoul(argv
[idx
+ 2]->arg
, NULL
, 10);
10019 ret
= ospf_asbr_external_aggregator_set(ospf
, &p
, tag
);
10020 if (ret
== OSPF_INVALID
)
10021 vty_out(vty
, "Invalid configuration!!\n");
10023 return CMD_SUCCESS
;
10026 DEFUN (no_ospf_external_route_aggregation
,
10027 no_ospf_external_route_aggregation_cmd
,
10028 "no summary-address A.B.C.D/M [tag (1-4294967295)]",
10030 "External summary address\n"
10031 "Summary address prefix\n"
10033 "Router tag value\n")
10035 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10036 struct prefix_ipv4 p
;
10038 route_tag_t tag
= 0;
10039 int ret
= OSPF_SUCCESS
;
10041 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
10043 if (is_default_prefix4(&p
)) {
10045 "Default address shouldn't be configured as summary address.\n");
10046 return CMD_SUCCESS
;
10049 /* Apply mask for given prefix. */
10052 if (!is_valid_summary_addr(&p
)) {
10053 vty_out(vty
, "Not a valid summary address.\n");
10054 return CMD_WARNING_CONFIG_FAILED
;
10058 tag
= strtoul(argv
[idx
+ 2]->arg
, NULL
, 10);
10060 ret
= ospf_asbr_external_aggregator_unset(ospf
, &p
, tag
);
10061 if (ret
== OSPF_INVALID
)
10062 vty_out(vty
, "Invalid configuration!!\n");
10064 return CMD_SUCCESS
;
10067 DEFPY(no_ospf_gr_helper_planned_only
,
10068 no_ospf_gr_helper_planned_only_cmd
,
10069 "no graceful-restart helper planned-only",
10071 "OSPF Graceful Restart\n"
10073 "Supported only for planned restart\n")
10075 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10077 ospf_gr_helper_set_supported_planned_only_restart(ospf
, OSPF_GR_FALSE
);
10079 return CMD_SUCCESS
;
10082 static int ospf_print_vty_helper_dis_rtr_walkcb(struct hash_bucket
*bucket
,
10085 struct advRtr
*rtr
= bucket
->data
;
10086 struct vty
*vty
= (struct vty
*)arg
;
10087 static unsigned int count
;
10089 vty_out(vty
, "%-6pI4,", &rtr
->advRtrAddr
);
10092 if (count
% 5 == 0)
10093 vty_out(vty
, "\n");
10095 return HASHWALK_CONTINUE
;
10098 static int ospf_print_json_helper_enabled_rtr_walkcb(struct hash_bucket
*bucket
,
10101 struct advRtr
*rtr
= bucket
->data
;
10102 struct json_object
*json_rid_array
= arg
;
10103 struct json_object
*json_rid
;
10105 json_rid
= json_object_new_object();
10107 json_object_string_addf(json_rid
, "routerId", "%pI4", &rtr
->advRtrAddr
);
10108 json_object_array_add(json_rid_array
, json_rid
);
10110 return HASHWALK_CONTINUE
;
10113 static int ospf_show_gr_helper_details(struct vty
*vty
, struct ospf
*ospf
,
10114 uint8_t use_vrf
, json_object
*json
,
10115 bool uj
, bool detail
)
10117 struct listnode
*node
;
10118 struct ospf_interface
*oi
;
10119 char buf
[PREFIX_STRLEN
];
10120 json_object
*json_vrf
= NULL
;
10124 json_vrf
= json_object_new_object();
10129 if (ospf
->instance
) {
10131 json_object_int_add(json
, "ospfInstance",
10134 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
10137 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
10141 json_object_object_add(json
, ospf_get_name(ospf
),
10144 vty_out(vty
, "\n");
10146 /* Show Router ID. */
10148 json_object_string_add(json_vrf
, "routerId",
10149 inet_ntop(AF_INET
, &ospf
->router_id
,
10150 buf
, sizeof(buf
)));
10152 vty_out(vty
, "\n OSPF Router with ID (%pI4)\n\n",
10158 if (ospf
->is_helper_supported
)
10160 " Graceful restart helper support enabled.\n");
10163 " Graceful restart helper support disabled.\n");
10165 if (ospf
->strict_lsa_check
)
10166 vty_out(vty
, " Strict LSA check is enabled.\n");
10168 vty_out(vty
, " Strict LSA check is disabled.\n");
10170 if (ospf
->only_planned_restart
)
10172 " Helper supported for planned restarts only.\n");
10175 " Helper supported for Planned and Unplanned Restarts.\n");
10178 " Supported Graceful restart interval: %d(in seconds).\n",
10179 ospf
->supported_grace_time
);
10181 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf
)) {
10182 vty_out(vty
, " Enable Router list:\n");
10184 hash_walk(ospf
->enable_rtr_list
,
10185 ospf_print_vty_helper_dis_rtr_walkcb
, vty
);
10186 vty_out(vty
, "\n\n");
10189 if (ospf
->last_exit_reason
!= OSPF_GR_HELPER_EXIT_NONE
) {
10190 vty_out(vty
, " Last Helper exit Reason :%s\n",
10191 ospf_exit_reason2str(ospf
->last_exit_reason
));
10194 if (ospf
->active_restarter_cnt
)
10196 " Number of Active neighbours in graceful restart: %d\n",
10197 ospf
->active_restarter_cnt
);
10199 vty_out(vty
, "\n");
10202 json_object_string_add(
10203 json_vrf
, "helperSupport",
10204 (ospf
->is_helper_supported
) ? "Enabled" : "Disabled");
10205 json_object_string_add(json_vrf
, "strictLsaCheck",
10206 (ospf
->strict_lsa_check
) ? "Enabled"
10208 json_object_string_add(
10209 json_vrf
, "restartSupoort",
10210 (ospf
->only_planned_restart
)
10211 ? "Planned Restart only"
10212 : "Planned and Unplanned Restarts");
10214 json_object_int_add(json_vrf
, "supportedGracePeriod",
10215 ospf
->supported_grace_time
);
10217 #if CONFDATE > 20230131
10218 CPP_NOTICE("Remove JSON object commands with keys starting with capital")
10220 if (ospf
->last_exit_reason
!= OSPF_GR_HELPER_EXIT_NONE
) {
10221 json_object_string_add(
10222 json_vrf
, "LastExitReason",
10223 ospf_exit_reason2str(ospf
->last_exit_reason
));
10224 json_object_string_add(
10225 json_vrf
, "lastExitReason",
10226 ospf_exit_reason2str(ospf
->last_exit_reason
));
10229 if (ospf
->active_restarter_cnt
)
10230 json_object_int_add(json_vrf
, "activeRestarterCnt",
10231 ospf
->active_restarter_cnt
);
10233 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf
)) {
10234 struct json_object
*json_rid_array
=
10235 json_object_new_array();
10237 json_object_object_add(json_vrf
, "enabledRouterIds",
10240 hash_walk(ospf
->enable_rtr_list
,
10241 ospf_print_json_helper_enabled_rtr_walkcb
,
10249 json_object
*json_neighbors
= NULL
;
10251 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
10252 struct route_node
*rn
;
10253 struct ospf_neighbor
*nbr
;
10254 json_object
*json_neigh
;
10256 if (ospf_interface_neighbor_count(oi
) == 0)
10260 json_object_object_get_ex(json_vrf
, "Neighbors",
10262 json_object_object_get_ex(json_vrf
, "neighbors",
10264 if (!json_neighbors
) {
10266 json_object_new_object();
10267 json_object_object_add(json_vrf
,
10270 json_object_object_add(json_vrf
,
10276 for (rn
= route_top(oi
->nbrs
); rn
;
10277 rn
= route_next(rn
)) {
10284 if (!OSPF_GR_IS_ACTIVE_HELPER(nbr
))
10288 vty_out(vty
, " Neighbour %d :\n", cnt
);
10289 vty_out(vty
, " Address : %pI4\n",
10290 &nbr
->address
.u
.prefix4
);
10291 vty_out(vty
, " Routerid : %pI4\n",
10294 " Received Grace period : %d(in seconds).\n",
10295 nbr
->gr_helper_info
10296 .recvd_grace_period
);
10298 " Actual Grace period : %d(in seconds)\n",
10299 nbr
->gr_helper_info
10300 .actual_grace_period
);
10302 " Remaining GraceTime:%ld(in seconds).\n",
10303 thread_timer_remain_second(
10304 nbr
->gr_helper_info
10307 " Graceful Restart reason: %s.\n\n",
10308 ospf_restart_reason2str(
10309 nbr
->gr_helper_info
10310 .gr_restart_reason
));
10313 json_neigh
= json_object_new_object();
10314 json_object_string_add(
10315 json_neigh
, "srcAddr",
10316 inet_ntop(AF_INET
, &nbr
->src
,
10317 buf
, sizeof(buf
)));
10319 json_object_string_add(
10320 json_neigh
, "routerid",
10323 buf
, sizeof(buf
)));
10324 json_object_int_add(
10326 "recvdGraceInterval",
10327 nbr
->gr_helper_info
10328 .recvd_grace_period
);
10329 json_object_int_add(
10331 "actualGraceInterval",
10332 nbr
->gr_helper_info
10333 .actual_grace_period
);
10334 json_object_int_add(
10335 json_neigh
, "remainGracetime",
10336 thread_timer_remain_second(
10337 nbr
->gr_helper_info
10339 json_object_string_add(
10340 json_neigh
, "restartReason",
10341 ospf_restart_reason2str(
10342 nbr
->gr_helper_info
10343 .gr_restart_reason
));
10344 json_object_object_add(
10346 inet_ntop(AF_INET
, &nbr
->src
,
10353 return CMD_SUCCESS
;
10356 DEFUN (ospf_external_route_aggregation_no_adrvertise
,
10357 ospf_external_route_aggregation_no_adrvertise_cmd
,
10358 "summary-address A.B.C.D/M no-advertise",
10359 "External summary address\n"
10360 "Summary address prefix\n"
10361 "Don't advertise summary route \n")
10363 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10364 struct prefix_ipv4 p
;
10366 int ret
= OSPF_SUCCESS
;
10368 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
10370 if (is_default_prefix4(&p
)) {
10372 "Default address shouldn't be configured as summary address.\n");
10373 return CMD_SUCCESS
;
10376 /* Apply mask for given prefix. */
10379 if (!is_valid_summary_addr(&p
)) {
10380 vty_out(vty
, "Not a valid summary address.\n");
10381 return CMD_WARNING_CONFIG_FAILED
;
10384 ret
= ospf_asbr_external_rt_no_advertise(ospf
, &p
);
10385 if (ret
== OSPF_INVALID
)
10386 vty_out(vty
, "Invalid configuration!!\n");
10388 return CMD_SUCCESS
;
10391 DEFUN (no_ospf_external_route_aggregation_no_adrvertise
,
10392 no_ospf_external_route_aggregation_no_adrvertise_cmd
,
10393 "no summary-address A.B.C.D/M no-advertise",
10395 "External summary address\n"
10396 "Summary address prefix\n"
10397 "Advertise summary route to the AS \n")
10399 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10400 struct prefix_ipv4 p
;
10402 int ret
= OSPF_SUCCESS
;
10404 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
10406 if (is_default_prefix4(&p
)) {
10408 "Default address shouldn't be configured as summary address.\n");
10409 return CMD_SUCCESS
;
10412 /* Apply mask for given prefix. */
10415 if (!is_valid_summary_addr(&p
)) {
10416 vty_out(vty
, "Not a valid summary address.\n");
10417 return CMD_WARNING_CONFIG_FAILED
;
10420 ret
= ospf_asbr_external_rt_advertise(ospf
, &p
);
10421 if (ret
== OSPF_INVALID
)
10422 vty_out(vty
, "Invalid configuration!!\n");
10424 return CMD_SUCCESS
;
10427 DEFUN (ospf_route_aggregation_timer
,
10428 ospf_route_aggregation_timer_cmd
,
10429 "aggregation timer (5-1800)",
10430 "External route aggregation\n"
10431 "Delay timer (in seconds)\n"
10432 "Timer interval(in seconds)\n")
10434 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10435 uint16_t interval
= 0;
10437 interval
= strtoul(argv
[2]->arg
, NULL
, 10);
10439 ospf_external_aggregator_timer_set(ospf
, interval
);
10441 return CMD_SUCCESS
;
10444 DEFPY (show_ip_ospf_gr_helper
,
10445 show_ip_ospf_gr_helper_cmd
,
10446 "show ip ospf [vrf <NAME|all>] graceful-restart helper [detail] [json]",
10449 "OSPF information\n"
10452 "OSPF Graceful Restart\n"
10453 "Helper details in the router\n"
10454 "Detailed information\n"
10457 char *vrf_name
= NULL
;
10458 bool all_vrf
= false;
10459 int ret
= CMD_SUCCESS
;
10462 uint8_t use_vrf
= 0;
10463 bool uj
= use_json(argc
, argv
);
10464 struct ospf
*ospf
= NULL
;
10465 json_object
*json
= NULL
;
10466 struct listnode
*node
= NULL
;
10468 bool detail
= false;
10470 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
10472 if (argv_find(argv
, argc
, "detail", &idx
))
10476 json
= json_object_new_object();
10478 /* vrf input is provided */
10483 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
10484 if (!ospf
->oi_running
)
10487 ret
= ospf_show_gr_helper_details(
10488 vty
, ospf
, use_vrf
, json
, uj
, detail
);
10492 vty_json(vty
, json
);
10497 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
10499 if (ospf
== NULL
|| !ospf
->oi_running
) {
10502 vty_json(vty
, json
);
10505 "%% OSPF is not enabled in vrf %s\n",
10508 return CMD_SUCCESS
;
10513 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
10515 if (ospf
== NULL
|| !ospf
->oi_running
) {
10518 vty_json(vty
, json
);
10521 "%% OSPF is not enabled in vrf default\n");
10523 return CMD_SUCCESS
;
10526 ospf_show_gr_helper_details(vty
, ospf
, use_vrf
, json
, uj
,
10531 vty_json(vty
, json
);
10533 return CMD_SUCCESS
;
10535 /* Graceful Restart HELPER commands end */
10536 DEFUN (no_ospf_route_aggregation_timer
,
10537 no_ospf_route_aggregation_timer_cmd
,
10538 "no aggregation timer",
10540 "External route aggregation\n"
10543 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10545 ospf_external_aggregator_timer_set(ospf
, OSPF_EXTL_AGGR_DEFAULT_DELAY
);
10547 return CMD_SUCCESS
;
10550 /* External Route Aggregation End */
10552 static void config_write_stub_router(struct vty
*vty
, struct ospf
*ospf
)
10554 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
10555 vty_out(vty
, " max-metric router-lsa on-startup %u\n",
10556 ospf
->stub_router_startup_time
);
10557 if (ospf
->stub_router_shutdown_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
10558 vty_out(vty
, " max-metric router-lsa on-shutdown %u\n",
10559 ospf
->stub_router_shutdown_time
);
10560 if (ospf
->stub_router_admin_set
== OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
)
10561 vty_out(vty
, " max-metric router-lsa administrative\n");
10566 #if CONFDATE > 20230131
10567 CPP_NOTICE("Remove JSON object commands with keys containing whitespaces")
10569 static void show_ip_ospf_route_network(struct vty
*vty
, struct ospf
*ospf
,
10570 struct route_table
*rt
,
10573 struct route_node
*rn
;
10574 struct ospf_route
* or ;
10575 struct listnode
*pnode
, *pnnode
;
10576 struct ospf_path
*path
;
10577 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
10578 *json_nexthop
= NULL
;
10582 "============ OSPF network routing table ============\n");
10584 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
10585 char buf1
[PREFIX2STR_BUFFER
];
10587 if ((or = rn
->info
) == NULL
)
10590 prefix2str(&rn
->p
, buf1
, sizeof(buf1
));
10593 json_route
= json_object_new_object();
10594 json_object_object_add(json
, buf1
, json_route
);
10597 switch (or->path_type
) {
10598 case OSPF_PATH_INTER_AREA
:
10599 if (or->type
== OSPF_DESTINATION_NETWORK
) {
10601 json_object_string_add(json_route
,
10604 json_object_int_add(json_route
, "cost",
10606 json_object_string_addf(
10607 json_route
, "area", "%pI4",
10608 &or->u
.std
.area_id
);
10611 "N IA %-18s [%d] area: %pI4\n",
10613 &or->u
.std
.area_id
);
10615 } else if (or->type
== OSPF_DESTINATION_DISCARD
) {
10617 json_object_string_add(json_route
,
10622 "D IA %-18s Discard entry\n",
10627 case OSPF_PATH_INTRA_AREA
:
10629 json_object_string_add(json_route
, "routeType",
10631 json_object_int_add(json_route
, "cost",
10633 json_object_string_addf(json_route
, "area",
10635 &or->u
.std
.area_id
);
10637 vty_out(vty
, "N %-18s [%d] area: %pI4\n",
10639 &or->u
.std
.area_id
);
10646 if (or->type
== OSPF_DESTINATION_NETWORK
) {
10648 json_nexthop_array
= json_object_new_array();
10649 json_object_object_add(json_route
, "nexthops",
10650 json_nexthop_array
);
10653 for (ALL_LIST_ELEMENTS(or->paths
, pnode
, pnnode
,
10656 json_nexthop
= json_object_new_object();
10657 json_object_array_add(
10658 json_nexthop_array
,
10661 if (if_lookup_by_index(path
->ifindex
,
10664 if (path
->nexthop
.s_addr
10667 json_object_string_add(
10670 json_object_string_add(
10672 "directly attached to",
10676 json_object_string_add(
10678 "directlyAttachedTo",
10684 "%24s directly attached to %s\n",
10692 json_object_string_addf(
10696 json_object_string_add(
10704 "%24s via %pI4, %s\n",
10717 vty_out(vty
, "\n");
10720 static void show_ip_ospf_route_router(struct vty
*vty
, struct ospf
*ospf
,
10721 struct route_table
*rtrs
,
10724 struct route_node
*rn
;
10725 struct ospf_route
* or ;
10726 struct listnode
*pnode
;
10727 struct listnode
*node
;
10728 struct ospf_path
*path
;
10729 char buf
[PREFIX_STRLEN
];
10730 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
10731 *json_nexthop
= NULL
;
10734 vty_out(vty
, "============ OSPF %s table =============\n",
10735 ospf
->all_rtrs
== rtrs
? "reachable routers"
10736 : "router routing");
10738 for (rn
= route_top(rtrs
); rn
; rn
= route_next(rn
)) {
10739 if (rn
->info
== NULL
)
10744 json_route
= json_object_new_object();
10745 json_object_object_add(
10746 json
, inet_ntop(AF_INET
, &rn
->p
.u
.prefix4
,
10749 json_object_string_add(json_route
, "routeType", "R ");
10751 vty_out(vty
, "R %-15pI4 ",
10755 for (ALL_LIST_ELEMENTS_RO((struct list
*)rn
->info
, node
, or)) {
10758 vty_out(vty
, "%24s", "");
10763 json_object_int_add(json_route
, "cost",
10765 json_object_string_addf(json_route
, "area",
10767 &or->u
.std
.area_id
);
10768 if (or->path_type
== OSPF_PATH_INTER_AREA
) {
10769 json_object_boolean_true_add(json_route
,
10771 json_object_boolean_true_add(json_route
,
10774 if (or->u
.std
.flags
& ROUTER_LSA_BORDER
)
10775 json_object_string_add(json_route
,
10778 else if (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
)
10779 json_object_string_add(json_route
,
10783 vty_out(vty
, "%s [%d] area: %pI4",
10784 (or->path_type
== OSPF_PATH_INTER_AREA
10787 or->cost
, &or->u
.std
.area_id
);
10789 vty_out(vty
, "%s%s\n",
10790 (or->u
.std
.flags
& ROUTER_LSA_BORDER
10793 (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
10799 json_nexthop_array
= json_object_new_array();
10800 json_object_object_add(json_route
, "nexthops",
10801 json_nexthop_array
);
10804 for (ALL_LIST_ELEMENTS_RO(or->paths
, pnode
, path
)) {
10806 json_nexthop
= json_object_new_object();
10807 json_object_array_add(
10808 json_nexthop_array
,
10811 if (if_lookup_by_index(path
->ifindex
,
10813 if (path
->nexthop
.s_addr
10816 json_object_string_add(
10819 json_object_string_add(
10821 "directly attached to",
10825 json_object_string_add(
10827 "directlyAttachedTo",
10833 "%24s directly attached to %s\n",
10841 json_object_string_addf(
10845 json_object_string_add(
10853 "%24s via %pI4, %s\n",
10866 vty_out(vty
, "\n");
10869 static void show_ip_ospf_route_external(struct vty
*vty
, struct ospf
*ospf
,
10870 struct route_table
*rt
,
10873 struct route_node
*rn
;
10874 struct ospf_route
*er
;
10875 struct listnode
*pnode
, *pnnode
;
10876 struct ospf_path
*path
;
10877 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
10878 *json_nexthop
= NULL
;
10882 "============ OSPF external routing table ===========\n");
10884 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
10885 if ((er
= rn
->info
) == NULL
)
10890 snprintfrr(buf1
, sizeof(buf1
), "%pFX", &rn
->p
);
10892 json_route
= json_object_new_object();
10893 json_object_object_add(json
, buf1
, json_route
);
10896 switch (er
->path_type
) {
10897 case OSPF_PATH_TYPE1_EXTERNAL
:
10899 json_object_string_add(json_route
, "routeType",
10901 json_object_int_add(json_route
, "cost",
10903 json_object_int_add(json_route
, "tag",
10907 "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI
10909 buf1
, er
->cost
, er
->u
.ext
.tag
);
10912 case OSPF_PATH_TYPE2_EXTERNAL
:
10914 json_object_string_add(json_route
, "routeType",
10916 json_object_int_add(json_route
, "cost",
10918 json_object_int_add(json_route
, "type2cost",
10919 er
->u
.ext
.type2_cost
);
10920 json_object_int_add(json_route
, "tag",
10924 "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI
10926 buf1
, er
->cost
, er
->u
.ext
.type2_cost
,
10933 json_nexthop_array
= json_object_new_array();
10934 json_object_object_add(json_route
, "nexthops",
10935 json_nexthop_array
);
10938 for (ALL_LIST_ELEMENTS(er
->paths
, pnode
, pnnode
, path
)) {
10940 json_nexthop
= json_object_new_object();
10941 json_object_array_add(json_nexthop_array
,
10945 if (if_lookup_by_index(path
->ifindex
, ospf
->vrf_id
)) {
10946 if (path
->nexthop
.s_addr
== INADDR_ANY
) {
10948 json_object_string_add(
10949 json_nexthop
, "ip",
10951 json_object_string_add(
10953 "directly attached to",
10957 json_object_string_add(
10959 "directlyAttachedTo",
10965 "%24s directly attached to %s\n",
10973 json_object_string_addf(
10974 json_nexthop
, "ip",
10975 "%pI4", &path
->nexthop
);
10976 json_object_string_add(
10977 json_nexthop
, "via",
10983 "%24s via %pI4, %s\n",
10995 vty_out(vty
, "\n");
10998 static int show_ip_ospf_reachable_routers_common(struct vty
*vty
,
11002 if (ospf
->instance
)
11003 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
11005 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
11007 if (ospf
->all_rtrs
== NULL
) {
11008 vty_out(vty
, "No OSPF reachable router information exist\n");
11009 return CMD_SUCCESS
;
11012 /* Show Router routes. */
11013 show_ip_ospf_route_router(vty
, ospf
, ospf
->all_rtrs
, NULL
);
11015 vty_out(vty
, "\n");
11017 return CMD_SUCCESS
;
11020 DEFUN (show_ip_ospf_reachable_routers
,
11021 show_ip_ospf_reachable_routers_cmd
,
11022 "show ip ospf [vrf <NAME|all>] reachable-routers",
11025 "OSPF information\n"
11028 "Show all the reachable OSPF routers\n")
11030 struct ospf
*ospf
= NULL
;
11031 struct listnode
*node
= NULL
;
11032 char *vrf_name
= NULL
;
11033 bool all_vrf
= false;
11034 int ret
= CMD_SUCCESS
;
11037 uint8_t use_vrf
= 0;
11039 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11042 bool ospf_output
= false;
11047 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11048 if (!ospf
->oi_running
)
11051 ospf_output
= true;
11052 ret
= show_ip_ospf_reachable_routers_common(
11053 vty
, ospf
, use_vrf
);
11057 vty_out(vty
, "%% OSPF instance not found\n");
11059 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11060 if (ospf
== NULL
|| !ospf
->oi_running
) {
11061 vty_out(vty
, "%% OSPF instance not found\n");
11062 return CMD_SUCCESS
;
11065 ret
= show_ip_ospf_reachable_routers_common(vty
, ospf
,
11069 /* Display default ospf (instance 0) info */
11070 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11071 if (ospf
== NULL
|| !ospf
->oi_running
) {
11072 vty_out(vty
, "%% OSPF instance not found\n");
11073 return CMD_SUCCESS
;
11076 ret
= show_ip_ospf_reachable_routers_common(vty
, ospf
, use_vrf
);
11082 DEFUN (show_ip_ospf_instance_reachable_routers
,
11083 show_ip_ospf_instance_reachable_routers_cmd
,
11084 "show ip ospf (1-65535) reachable-routers",
11087 "OSPF information\n"
11089 "Show all the reachable OSPF routers\n")
11091 int idx_number
= 3;
11093 unsigned short instance
= 0;
11095 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
11096 if (instance
!= ospf_instance
)
11097 return CMD_NOT_MY_INSTANCE
;
11099 ospf
= ospf_lookup_instance(instance
);
11100 if (!ospf
|| !ospf
->oi_running
)
11101 return CMD_SUCCESS
;
11103 return show_ip_ospf_reachable_routers_common(vty
, ospf
, 0);
11106 static int show_ip_ospf_border_routers_common(struct vty
*vty
,
11111 json_object
*json_vrf
= NULL
;
11112 json_object
*json_router
= NULL
;
11116 json_vrf
= json_object_new_object();
11119 json_router
= json_object_new_object();
11122 if (ospf
->instance
) {
11124 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
11126 json_object_int_add(json_vrf
, "ospfInstance",
11130 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
11132 if (ospf
->new_table
== NULL
) {
11134 vty_out(vty
, "No OSPF routing information exist\n");
11136 json_object_free(json_router
);
11138 json_object_free(json_vrf
);
11140 return CMD_SUCCESS
;
11143 /* Show Network routes.
11144 show_ip_ospf_route_network (vty, ospf->new_table); */
11146 /* Show Router routes. */
11147 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, json_router
);
11150 json_object_object_add(json_vrf
, "routers", json_router
);
11152 if (ospf
->vrf_id
== VRF_DEFAULT
)
11153 json_object_object_add(json
, "default",
11156 json_object_object_add(json
, ospf
->name
,
11160 vty_out(vty
, "\n");
11163 return CMD_SUCCESS
;
11166 DEFPY (show_ip_ospf_border_routers
,
11167 show_ip_ospf_border_routers_cmd
,
11168 "show ip ospf [vrf <NAME|all>] border-routers [json]",
11171 "OSPF information\n"
11174 "Show all the ABR's and ASBR's\n"
11177 struct ospf
*ospf
= NULL
;
11178 struct listnode
*node
= NULL
;
11179 char *vrf_name
= NULL
;
11180 bool all_vrf
= false;
11181 int ret
= CMD_SUCCESS
;
11184 uint8_t use_vrf
= 0;
11185 bool uj
= use_json(argc
, argv
);
11186 json_object
*json
= NULL
;
11189 json
= json_object_new_object();
11191 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11194 bool ospf_output
= false;
11199 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11200 if (!ospf
->oi_running
)
11203 ospf_output
= true;
11204 ret
= show_ip_ospf_border_routers_common(
11205 vty
, ospf
, use_vrf
, json
);
11209 vty_json(vty
, json
);
11210 else if (!ospf_output
)
11211 vty_out(vty
, "%% OSPF is not enabled\n");
11215 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11216 if (ospf
== NULL
|| !ospf
->oi_running
) {
11218 vty_json(vty
, json
);
11221 "%% OSPF is not enabled in vrf %s\n",
11224 return CMD_SUCCESS
;
11228 /* Display default ospf (instance 0) info */
11229 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11230 if (ospf
== NULL
|| !ospf
->oi_running
) {
11232 vty_json(vty
, json
);
11235 "%% OSPF is not enabled in vrf default\n");
11237 return CMD_SUCCESS
;
11242 ret
= show_ip_ospf_border_routers_common(vty
, ospf
, use_vrf
,
11245 vty_json(vty
, json
);
11251 DEFUN (show_ip_ospf_instance_border_routers
,
11252 show_ip_ospf_instance_border_routers_cmd
,
11253 "show ip ospf (1-65535) border-routers",
11256 "OSPF information\n"
11258 "Show all the ABR's and ASBR's\n")
11260 int idx_number
= 3;
11262 unsigned short instance
= 0;
11264 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
11265 if (instance
!= ospf_instance
)
11266 return CMD_NOT_MY_INSTANCE
;
11268 ospf
= ospf_lookup_instance(instance
);
11269 if (!ospf
|| !ospf
->oi_running
)
11270 return CMD_SUCCESS
;
11272 return show_ip_ospf_border_routers_common(vty
, ospf
, 0, NULL
);
11275 static int show_ip_ospf_route_common(struct vty
*vty
, struct ospf
*ospf
,
11276 json_object
*json
, uint8_t use_vrf
)
11278 json_object
*json_vrf
= NULL
;
11280 if (ospf
->instance
)
11281 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
11286 json_vrf
= json_object_new_object();
11291 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
11293 if (ospf
->new_table
== NULL
) {
11296 json_object_free(json_vrf
);
11298 vty_out(vty
, "No OSPF routing information exist\n");
11300 return CMD_SUCCESS
;
11303 /* Show Network routes. */
11304 show_ip_ospf_route_network(vty
, ospf
, ospf
->new_table
, json_vrf
);
11306 /* Show Router routes. */
11307 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, json_vrf
);
11309 /* Show Router routes. */
11310 if (ospf
->all_rtrs
)
11311 show_ip_ospf_route_router(vty
, ospf
, ospf
->all_rtrs
, json_vrf
);
11313 /* Show AS External routes. */
11314 show_ip_ospf_route_external(vty
, ospf
, ospf
->old_external_route
,
11319 // json_object_object_add(json_vrf, "areas",
11321 json_object_object_add(json
, ospf_get_name(ospf
),
11325 vty_out(vty
, "\n");
11328 return CMD_SUCCESS
;
11331 DEFUN (show_ip_ospf_route
,
11332 show_ip_ospf_route_cmd
,
11333 "show ip ospf [vrf <NAME|all>] route [json]",
11336 "OSPF information\n"
11339 "OSPF routing table\n"
11342 struct ospf
*ospf
= NULL
;
11343 struct listnode
*node
= NULL
;
11344 char *vrf_name
= NULL
;
11345 bool all_vrf
= false;
11346 int ret
= CMD_SUCCESS
;
11349 uint8_t use_vrf
= 0;
11350 bool uj
= use_json(argc
, argv
);
11351 json_object
*json
= NULL
;
11354 json
= json_object_new_object();
11356 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11358 /* vrf input is provided could be all or specific vrf*/
11360 bool ospf_output
= false;
11365 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11366 if (!ospf
->oi_running
)
11368 ospf_output
= true;
11369 ret
= show_ip_ospf_route_common(vty
, ospf
, json
,
11374 /* Keep Non-pretty format */
11375 vty_json(vty
, json
);
11376 } else if (!ospf_output
)
11377 vty_out(vty
, "%% OSPF is not enabled\n");
11381 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11382 if (ospf
== NULL
|| !ospf
->oi_running
) {
11384 vty_json(vty
, json
);
11387 "%% OSPF is not enabled in vrf %s\n",
11390 return CMD_SUCCESS
;
11393 /* Display default ospf (instance 0) info */
11394 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11395 if (ospf
== NULL
|| !ospf
->oi_running
) {
11397 vty_json(vty
, json
);
11400 "%% OSPF is not enabled in vrf default\n");
11402 return CMD_SUCCESS
;
11407 ret
= show_ip_ospf_route_common(vty
, ospf
, json
, use_vrf
);
11408 /* Keep Non-pretty format */
11410 vty_out(vty
, "%s\n",
11411 json_object_to_json_string_ext(
11412 json
, JSON_C_TO_STRING_NOSLASHESCAPE
));
11416 json_object_free(json
);
11421 DEFUN (show_ip_ospf_instance_route
,
11422 show_ip_ospf_instance_route_cmd
,
11423 "show ip ospf (1-65535) route",
11426 "OSPF information\n"
11428 "OSPF routing table\n")
11430 int idx_number
= 3;
11432 unsigned short instance
= 0;
11434 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
11435 if (instance
!= ospf_instance
)
11436 return CMD_NOT_MY_INSTANCE
;
11438 ospf
= ospf_lookup_instance(instance
);
11439 if (!ospf
|| !ospf
->oi_running
)
11440 return CMD_SUCCESS
;
11442 return show_ip_ospf_route_common(vty
, ospf
, NULL
, 0);
11446 DEFUN (show_ip_ospf_vrfs
,
11447 show_ip_ospf_vrfs_cmd
,
11448 "show ip ospf vrfs [json]",
11451 "OSPF information\n"
11452 "Show OSPF VRFs \n"
11455 bool uj
= use_json(argc
, argv
);
11456 json_object
*json
= NULL
;
11457 json_object
*json_vrfs
= NULL
;
11458 struct ospf
*ospf
= NULL
;
11459 struct listnode
*node
= NULL
;
11461 static const char header
[] = "Name Id RouterId ";
11464 json
= json_object_new_object();
11465 json_vrfs
= json_object_new_object();
11468 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11469 json_object
*json_vrf
= NULL
;
11470 const char *name
= NULL
;
11471 int64_t vrf_id_ui
= 0;
11475 if (!uj
&& count
== 1)
11476 vty_out(vty
, "%s\n", header
);
11478 json_vrf
= json_object_new_object();
11480 name
= ospf_get_name(ospf
);
11482 vrf_id_ui
= (ospf
->vrf_id
== VRF_UNKNOWN
)
11484 : (int64_t)ospf
->vrf_id
;
11487 json_object_int_add(json_vrf
, "vrfId", vrf_id_ui
);
11488 json_object_string_addf(json_vrf
, "routerId", "%pI4",
11491 json_object_object_add(json_vrfs
, name
, json_vrf
);
11494 vty_out(vty
, "%-25s %-5d %-16pI4 \n", name
,
11495 ospf
->vrf_id
, &ospf
->router_id
);
11500 json_object_object_add(json
, "vrfs", json_vrfs
);
11501 json_object_int_add(json
, "totalVrfs", count
);
11503 vty_json(vty
, json
);
11506 vty_out(vty
, "\nTotal number of OSPF VRFs: %d\n",
11510 return CMD_SUCCESS
;
11512 DEFPY (clear_ip_ospf_neighbor
,
11513 clear_ip_ospf_neighbor_cmd
,
11514 "clear ip ospf [(1-65535)]$instance neighbor [A.B.C.D$nbr_id]",
11517 "OSPF information\n"
11519 "Reset OSPF Neighbor\n"
11522 struct listnode
*node
;
11523 struct ospf
*ospf
= NULL
;
11525 /* If user does not specify the arguments,
11526 * instance = 0 and nbr_id = 0.0.0.0
11528 if (instance
!= 0) {
11529 /* This means clear only the particular ospf process */
11530 if (instance
!= ospf_instance
)
11531 return CMD_NOT_MY_INSTANCE
;
11534 /* Clear all the ospf processes */
11535 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11536 if (!ospf
->oi_running
)
11539 if (nbr_id_str
&& IPV4_ADDR_SAME(&ospf
->router_id
, &nbr_id
)) {
11540 vty_out(vty
, "Self router-id is not allowed.\r\n ");
11541 return CMD_SUCCESS
;
11544 ospf_neighbor_reset(ospf
, nbr_id
, nbr_id_str
);
11547 return CMD_SUCCESS
;
11550 DEFPY (clear_ip_ospf_process
,
11551 clear_ip_ospf_process_cmd
,
11552 "clear ip ospf [(1-65535)]$instance process",
11555 "OSPF information\n"
11557 "Reset OSPF Process\n")
11559 struct listnode
*node
;
11560 struct ospf
*ospf
= NULL
;
11562 /* Check if instance is not passed as an argument */
11563 if (instance
!= 0) {
11564 /* This means clear only the particular ospf process */
11565 if (instance
!= ospf_instance
)
11566 return CMD_NOT_MY_INSTANCE
;
11569 /* Clear all the ospf processes */
11570 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11571 if (!ospf
->oi_running
)
11574 ospf_process_reset(ospf
);
11577 return CMD_SUCCESS
;
11580 static const char *const ospf_abr_type_str
[] = {
11581 "unknown", "standard", "ibm", "cisco", "shortcut"
11584 static const char *const ospf_shortcut_mode_str
[] = {
11585 "default", "enable", "disable"
11587 static int ospf_vty_external_rt_walkcb(struct hash_bucket
*bucket
,
11590 struct external_info
*ei
= bucket
->data
;
11591 struct vty
*vty
= (struct vty
*)arg
;
11592 static unsigned int count
;
11594 vty_out(vty
, "%-4pI4/%d, ", &ei
->p
.prefix
, ei
->p
.prefixlen
);
11597 if (count
% 5 == 0)
11598 vty_out(vty
, "\n");
11600 if (OSPF_EXTERNAL_RT_COUNT(ei
->aggr_route
) == count
)
11603 return HASHWALK_CONTINUE
;
11606 static int ospf_json_external_rt_walkcb(struct hash_bucket
*bucket
,
11609 struct external_info
*ei
= bucket
->data
;
11610 struct json_object
*json
= (struct json_object
*)arg
;
11611 char buf
[PREFIX2STR_BUFFER
];
11613 static unsigned int count
;
11615 prefix2str(&ei
->p
, buf
, sizeof(buf
));
11617 snprintf(exnalbuf
, 20, "Exnl Addr-%d", count
);
11619 json_object_string_add(json
, exnalbuf
, buf
);
11623 if (OSPF_EXTERNAL_RT_COUNT(ei
->aggr_route
) == count
)
11626 return HASHWALK_CONTINUE
;
11629 static int ospf_show_summary_address(struct vty
*vty
, struct ospf
*ospf
,
11630 uint8_t use_vrf
, json_object
*json
,
11631 bool uj
, bool detail
)
11633 struct route_node
*rn
;
11634 json_object
*json_vrf
= NULL
;
11637 static char header
[] =
11638 "Summary-address Metric-type Metric Tag External_Rt_count\n";
11640 mtype
= metric_type(ospf
, 0, ospf
->instance
);
11641 mval
= metric_value(ospf
, 0, ospf
->instance
);
11644 vty_out(vty
, "%s\n", header
);
11648 json_vrf
= json_object_new_object();
11653 if (ospf
->instance
) {
11655 json_object_int_add(json
, "ospfInstance",
11658 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
11661 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
11664 vty_out(vty
, "aggregation delay interval :%u(in seconds)\n\n",
11665 ospf
->aggr_delay_interval
);
11667 json_object_int_add(json_vrf
, "aggregation delay interval",
11668 ospf
->aggr_delay_interval
);
11669 json_object_int_add(json_vrf
, "aggregationDelayInterval",
11670 ospf
->aggr_delay_interval
);
11673 for (rn
= route_top(ospf
->rt_aggr_tbl
); rn
; rn
= route_next(rn
))
11675 struct ospf_external_aggr_rt
*aggr
= rn
->info
;
11676 json_object
*json_aggr
= NULL
;
11677 char buf
[PREFIX2STR_BUFFER
];
11679 prefix2str(&aggr
->p
, buf
, sizeof(buf
));
11683 json_aggr
= json_object_new_object();
11685 json_object_object_add(json_vrf
, buf
,
11688 json_object_string_add(json_aggr
,
11689 "Summary address", buf
);
11690 json_object_string_add(json_aggr
,
11691 "summaryAddress", buf
);
11693 json_object_string_add(
11694 json_aggr
, "Metric-type",
11695 (mtype
== EXTERNAL_METRIC_TYPE_1
)
11698 json_object_string_add(
11699 json_aggr
, "metricType",
11700 (mtype
== EXTERNAL_METRIC_TYPE_1
)
11704 #if CONFDATE > 20230131
11705 CPP_NOTICE("Remove JSON object commands with keys starting with capital")
11707 json_object_int_add(json_aggr
, "Metric", mval
);
11708 json_object_int_add(json_aggr
, "metric", mval
);
11710 json_object_int_add(json_aggr
, "Tag",
11712 json_object_int_add(json_aggr
, "tag",
11715 json_object_int_add(
11716 json_aggr
, "External route count",
11717 OSPF_EXTERNAL_RT_COUNT(aggr
));
11718 json_object_int_add(
11719 json_aggr
, "externalRouteCount",
11720 OSPF_EXTERNAL_RT_COUNT(aggr
));
11722 if (OSPF_EXTERNAL_RT_COUNT(aggr
) && detail
) {
11724 aggr
->match_extnl_hash
,
11725 ospf_json_external_rt_walkcb
,
11730 vty_out(vty
, "%-20s", buf
);
11732 (mtype
== EXTERNAL_METRIC_TYPE_1
)
11733 ? vty_out(vty
, "%-16s", "E1")
11734 : vty_out(vty
, "%-16s", "E2");
11735 vty_out(vty
, "%-11d", mval
);
11737 vty_out(vty
, "%-12u", aggr
->tag
);
11739 vty_out(vty
, "%-5ld\n",
11740 OSPF_EXTERNAL_RT_COUNT(aggr
));
11742 if (OSPF_EXTERNAL_RT_COUNT(aggr
) && detail
) {
11744 "Matched External routes:\n");
11746 aggr
->match_extnl_hash
,
11747 ospf_vty_external_rt_walkcb
,
11749 vty_out(vty
, "\n");
11752 vty_out(vty
, "\n");
11758 json_object_object_add(json
, ospf_get_name(ospf
),
11761 vty_out(vty
, "\n");
11763 return CMD_SUCCESS
;
11766 DEFUN (show_ip_ospf_external_aggregator
,
11767 show_ip_ospf_external_aggregator_cmd
,
11768 "show ip ospf [vrf <NAME|all>] summary-address [detail] [json]",
11770 "OSPF information\n"
11773 "Show external summary addresses\n"
11774 "Detailed information\n"
11777 char *vrf_name
= NULL
;
11778 bool all_vrf
= false;
11779 int ret
= CMD_SUCCESS
;
11782 uint8_t use_vrf
= 0;
11783 bool uj
= use_json(argc
, argv
);
11784 struct ospf
*ospf
= NULL
;
11785 json_object
*json
= NULL
;
11786 struct listnode
*node
= NULL
;
11788 bool detail
= false;
11790 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11792 if (argv_find(argv
, argc
, "detail", &idx
))
11796 json
= json_object_new_object();
11798 /* vrf input is provided */
11802 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11803 if (!ospf
->oi_running
)
11805 ret
= ospf_show_summary_address(
11806 vty
, ospf
, use_vrf
, json
, uj
, detail
);
11810 vty_json(vty
, json
);
11815 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11817 if (ospf
== NULL
|| !ospf
->oi_running
) {
11819 vty_json(vty
, json
);
11822 "%% OSPF is not enabled in vrf %s\n",
11825 return CMD_SUCCESS
;
11827 ospf_show_summary_address(vty
, ospf
, use_vrf
, json
, uj
, detail
);
11831 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11832 if (ospf
== NULL
|| !ospf
->oi_running
) {
11834 vty_json(vty
, json
);
11837 "%% OSPF is not enabled in vrf default\n");
11839 return CMD_SUCCESS
;
11842 ospf_show_summary_address(vty
, ospf
, use_vrf
, json
, uj
, detail
);
11846 vty_json(vty
, json
);
11847 return CMD_SUCCESS
;
11850 static const char *const ospf_int_type_str
[] = {
11851 "unknown", /* should never be used. */
11855 "point-to-multipoint",
11856 "virtual-link", /* should never be used. */
11860 static const char *interface_config_auth_str(struct ospf_if_params
*params
)
11862 if (!OSPF_IF_PARAM_CONFIGURED(params
, auth_type
)
11863 || params
->auth_type
== OSPF_AUTH_NOTSET
)
11866 /* Translation tables are not that much help
11867 * here due to syntax
11868 * of the simple option */
11869 switch (params
->auth_type
) {
11871 case OSPF_AUTH_NULL
:
11874 case OSPF_AUTH_SIMPLE
:
11877 case OSPF_AUTH_CRYPTOGRAPHIC
:
11878 return " message-digest";
11884 static int config_write_interface_one(struct vty
*vty
, struct vrf
*vrf
)
11886 struct listnode
*node
;
11887 struct interface
*ifp
;
11888 struct crypt_key
*ck
;
11889 struct route_node
*rn
= NULL
;
11890 struct ospf_if_params
*params
;
11891 const char *auth_str
;
11894 FOR_ALL_INTERFACES (vrf
, ifp
) {
11896 if (memcmp(ifp
->name
, "VLINK", 5) == 0)
11899 if_vty_config_start(vty
, ifp
);
11902 vty_out(vty
, " description %s\n", ifp
->desc
);
11906 params
= IF_DEF_PARAMS(ifp
);
11909 /* Interface Network print. */
11910 if (OSPF_IF_PARAM_CONFIGURED(params
, type
)
11911 && params
->type
!= OSPF_IFTYPE_LOOPBACK
) {
11912 if (params
->type
!= ospf_default_iftype(ifp
)) {
11913 vty_out(vty
, " ip ospf network %s",
11917 == OSPF_IFTYPE_POINTOPOINT
11918 && params
->ptp_dmvpn
)
11919 vty_out(vty
, " dmvpn");
11920 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11921 vty_out(vty
, " %pI4",
11923 vty_out(vty
, "\n");
11927 /* OSPF interface authentication print */
11928 auth_str
= interface_config_auth_str(params
);
11930 vty_out(vty
, " ip ospf authentication%s",
11932 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11933 vty_out(vty
, " %pI4",
11935 vty_out(vty
, "\n");
11938 /* Simple Authentication Password print. */
11939 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_simple
)
11940 && params
->auth_simple
[0] != '\0') {
11941 vty_out(vty
, " ip ospf authentication-key %s",
11942 params
->auth_simple
);
11943 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11944 vty_out(vty
, " %pI4",
11946 vty_out(vty
, "\n");
11949 /* Cryptographic Authentication Key print. */
11950 if (params
&& params
->auth_crypt
) {
11951 for (ALL_LIST_ELEMENTS_RO(params
->auth_crypt
,
11954 " ip ospf message-digest-key %d md5 %s",
11955 ck
->key_id
, ck
->auth_key
);
11956 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11957 vty_out(vty
, " %pI4",
11959 vty_out(vty
, "\n");
11963 /* Interface Output Cost print. */
11964 if (OSPF_IF_PARAM_CONFIGURED(params
, output_cost_cmd
)) {
11965 vty_out(vty
, " ip ospf cost %u",
11966 params
->output_cost_cmd
);
11967 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11968 vty_out(vty
, " %pI4",
11970 vty_out(vty
, "\n");
11973 /* Hello Interval print. */
11974 if (OSPF_IF_PARAM_CONFIGURED(params
, v_hello
)
11975 && params
->v_hello
!= OSPF_HELLO_INTERVAL_DEFAULT
) {
11976 vty_out(vty
, " ip ospf hello-interval %u",
11978 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11979 vty_out(vty
, " %pI4",
11981 vty_out(vty
, "\n");
11985 /* Router Dead Interval print. */
11986 if (OSPF_IF_PARAM_CONFIGURED(params
, v_wait
)
11987 && params
->is_v_wait_set
) {
11988 vty_out(vty
, " ip ospf dead-interval ");
11991 if (OSPF_IF_PARAM_CONFIGURED(params
,
11994 "minimal hello-multiplier %d",
11995 params
->fast_hello
);
11997 vty_out(vty
, "%u", params
->v_wait
);
11999 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12000 vty_out(vty
, " %pI4",
12002 vty_out(vty
, "\n");
12005 /* Router Priority print. */
12006 if (OSPF_IF_PARAM_CONFIGURED(params
, priority
)
12007 && params
->priority
12008 != OSPF_ROUTER_PRIORITY_DEFAULT
) {
12009 vty_out(vty
, " ip ospf priority %u",
12011 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12012 vty_out(vty
, " %pI4",
12014 vty_out(vty
, "\n");
12017 /* Retransmit Interval print. */
12018 if (OSPF_IF_PARAM_CONFIGURED(params
,
12019 retransmit_interval
)
12020 && params
->retransmit_interval
12021 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
) {
12022 vty_out(vty
, " ip ospf retransmit-interval %u",
12023 params
->retransmit_interval
);
12024 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12025 vty_out(vty
, " %pI4",
12027 vty_out(vty
, "\n");
12030 /* Transmit Delay print. */
12031 if (OSPF_IF_PARAM_CONFIGURED(params
, transmit_delay
)
12032 && params
->transmit_delay
12033 != OSPF_TRANSMIT_DELAY_DEFAULT
) {
12034 vty_out(vty
, " ip ospf transmit-delay %u",
12035 params
->transmit_delay
);
12036 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12037 vty_out(vty
, " %pI4",
12039 vty_out(vty
, "\n");
12043 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
12045 vty_out(vty
, " ip ospf %d",
12048 vty_out(vty
, " ip ospf");
12050 char buf
[INET_ADDRSTRLEN
];
12052 area_id2str(buf
, sizeof(buf
), ¶ms
->if_area
,
12053 params
->if_area_id_fmt
);
12054 vty_out(vty
, " area %s", buf
);
12055 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12056 vty_out(vty
, " %pI4",
12058 vty_out(vty
, "\n");
12062 if (params
&& params
->bfd_config
)
12063 ospf_bfd_write_config(vty
, params
);
12065 /* MTU ignore print. */
12066 if (OSPF_IF_PARAM_CONFIGURED(params
, mtu_ignore
)
12067 && params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
) {
12068 if (params
->mtu_ignore
== 0)
12069 vty_out(vty
, " no ip ospf mtu-ignore");
12071 vty_out(vty
, " ip ospf mtu-ignore");
12072 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12073 vty_out(vty
, " %pI4",
12075 vty_out(vty
, "\n");
12078 if (OSPF_IF_PARAM_CONFIGURED(params
,
12079 passive_interface
)) {
12080 vty_out(vty
, " %sip ospf passive",
12081 params
->passive_interface
12085 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12086 vty_out(vty
, " %pI4", &rn
->p
.u
.prefix4
);
12087 vty_out(vty
, "\n");
12090 /* LDP-Sync print */
12091 if (params
&& params
->ldp_sync_info
)
12092 ospf_ldp_sync_if_write_config(vty
, params
);
12096 rn
= route_top(IF_OIFS_PARAMS(ifp
));
12098 rn
= route_next(rn
);
12103 if (params
!= NULL
)
12108 ospf_opaque_config_write_if(vty
, ifp
);
12110 if_vty_config_end(vty
);
12116 /* Configuration write function for ospfd. */
12117 static int config_write_interface(struct vty
*vty
)
12120 struct vrf
*vrf
= NULL
;
12122 /* Display all VRF aware OSPF interface configuration */
12123 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
12124 write
+= config_write_interface_one(vty
, vrf
);
12130 static int config_write_network_area(struct vty
*vty
, struct ospf
*ospf
)
12132 struct route_node
*rn
;
12133 char buf
[INET_ADDRSTRLEN
];
12135 /* `network area' print. */
12136 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
))
12138 struct ospf_network
*n
= rn
->info
;
12140 /* Create Area ID string by specified Area ID format. */
12141 if (n
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
12142 inet_ntop(AF_INET
, &n
->area_id
, buf
,
12145 snprintf(buf
, sizeof(buf
), "%lu",
12146 (unsigned long int)ntohl(
12147 n
->area_id
.s_addr
));
12149 /* Network print. */
12150 vty_out(vty
, " network %pFX area %s\n", &rn
->p
, buf
);
12156 static int config_write_ospf_area(struct vty
*vty
, struct ospf
*ospf
)
12158 struct listnode
*node
;
12159 struct ospf_area
*area
;
12160 char buf
[INET_ADDRSTRLEN
];
12162 /* Area configuration print. */
12163 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
12164 struct route_node
*rn1
;
12166 area_id2str(buf
, sizeof(buf
), &area
->area_id
,
12167 area
->area_id_fmt
);
12169 if (area
->auth_type
!= OSPF_AUTH_NULL
) {
12170 if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
12171 vty_out(vty
, " area %s authentication\n", buf
);
12174 " area %s authentication message-digest\n",
12178 if (area
->shortcut_configured
!= OSPF_SHORTCUT_DEFAULT
)
12179 vty_out(vty
, " area %s shortcut %s\n", buf
,
12180 ospf_shortcut_mode_str
12181 [area
->shortcut_configured
]);
12183 if ((area
->external_routing
== OSPF_AREA_STUB
)
12184 || (area
->external_routing
== OSPF_AREA_NSSA
)) {
12185 if (area
->external_routing
== OSPF_AREA_STUB
) {
12186 vty_out(vty
, " area %s stub", buf
);
12187 if (area
->no_summary
)
12188 vty_out(vty
, " no-summary\n");
12189 vty_out(vty
, "\n");
12190 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
12191 switch (area
->NSSATranslatorRole
) {
12192 case OSPF_NSSA_ROLE_NEVER
:
12194 " area %s nssa translate-never\n",
12197 case OSPF_NSSA_ROLE_ALWAYS
:
12199 " area %s nssa translate-always\n",
12202 case OSPF_NSSA_ROLE_CANDIDATE
:
12203 vty_out(vty
, " area %s nssa \n", buf
);
12206 if (area
->no_summary
)
12208 " area %s nssa no-summary\n",
12210 if (area
->suppress_fa
)
12212 " area %s nssa suppress-fa\n",
12216 if (area
->default_cost
!= 1)
12217 vty_out(vty
, " area %s default-cost %d\n", buf
,
12218 area
->default_cost
);
12221 for (rn1
= route_top(area
->ranges
); rn1
; rn1
= route_next(rn1
))
12223 struct ospf_area_range
*range
= rn1
->info
;
12225 vty_out(vty
, " area %s range %pFX", buf
,
12228 if (range
->cost_config
12229 != OSPF_AREA_RANGE_COST_UNSPEC
)
12230 vty_out(vty
, " cost %d",
12231 range
->cost_config
);
12233 if (!CHECK_FLAG(range
->flags
,
12234 OSPF_AREA_RANGE_ADVERTISE
))
12235 vty_out(vty
, " not-advertise");
12237 if (CHECK_FLAG(range
->flags
,
12238 OSPF_AREA_RANGE_SUBSTITUTE
))
12239 vty_out(vty
, " substitute %pI4/%d",
12240 &range
->subst_addr
,
12241 range
->subst_masklen
);
12243 vty_out(vty
, "\n");
12246 if (EXPORT_NAME(area
))
12247 vty_out(vty
, " area %s export-list %s\n", buf
,
12248 EXPORT_NAME(area
));
12250 if (IMPORT_NAME(area
))
12251 vty_out(vty
, " area %s import-list %s\n", buf
,
12252 IMPORT_NAME(area
));
12254 if (PREFIX_NAME_IN(area
))
12255 vty_out(vty
, " area %s filter-list prefix %s in\n", buf
,
12256 PREFIX_NAME_IN(area
));
12258 if (PREFIX_NAME_OUT(area
))
12259 vty_out(vty
, " area %s filter-list prefix %s out\n",
12260 buf
, PREFIX_NAME_OUT(area
));
12266 static int config_write_ospf_nbr_nbma(struct vty
*vty
, struct ospf
*ospf
)
12268 struct ospf_nbr_nbma
*nbr_nbma
;
12269 struct route_node
*rn
;
12271 /* Static Neighbor configuration print. */
12272 for (rn
= route_top(ospf
->nbr_nbma
); rn
; rn
= route_next(rn
))
12273 if ((nbr_nbma
= rn
->info
)) {
12274 vty_out(vty
, " neighbor %pI4", &nbr_nbma
->addr
);
12276 if (nbr_nbma
->priority
12277 != OSPF_NEIGHBOR_PRIORITY_DEFAULT
)
12278 vty_out(vty
, " priority %d",
12279 nbr_nbma
->priority
);
12281 if (nbr_nbma
->v_poll
!= OSPF_POLL_INTERVAL_DEFAULT
)
12282 vty_out(vty
, " poll-interval %d",
12285 vty_out(vty
, "\n");
12291 static int config_write_virtual_link(struct vty
*vty
, struct ospf
*ospf
)
12293 struct listnode
*node
;
12294 struct ospf_vl_data
*vl_data
;
12295 const char *auth_str
;
12296 char buf
[INET_ADDRSTRLEN
];
12298 /* Virtual-Link print */
12299 for (ALL_LIST_ELEMENTS_RO(ospf
->vlinks
, node
, vl_data
)) {
12300 struct listnode
*n2
;
12301 struct crypt_key
*ck
;
12302 struct ospf_interface
*oi
;
12304 if (vl_data
!= NULL
) {
12305 area_id2str(buf
, sizeof(buf
), &vl_data
->vl_area_id
,
12306 vl_data
->vl_area_id_fmt
);
12307 oi
= vl_data
->vl_oi
;
12310 if (OSPF_IF_PARAM(oi
, v_hello
)
12311 != OSPF_HELLO_INTERVAL_DEFAULT
12312 || OSPF_IF_PARAM(oi
, v_wait
)
12313 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
12314 || OSPF_IF_PARAM(oi
, retransmit_interval
)
12315 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
12316 || OSPF_IF_PARAM(oi
, transmit_delay
)
12317 != OSPF_TRANSMIT_DELAY_DEFAULT
)
12319 " area %s virtual-link %pI4 hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n",
12320 buf
, &vl_data
->vl_peer
,
12321 OSPF_IF_PARAM(oi
, v_hello
),
12322 OSPF_IF_PARAM(oi
, retransmit_interval
),
12323 OSPF_IF_PARAM(oi
, transmit_delay
),
12324 OSPF_IF_PARAM(oi
, v_wait
));
12326 vty_out(vty
, " area %s virtual-link %pI4\n", buf
,
12327 &vl_data
->vl_peer
);
12329 auth_str
= interface_config_auth_str(
12330 IF_DEF_PARAMS(oi
->ifp
));
12333 " area %s virtual-link %pI4 authentication%s\n",
12334 buf
, &vl_data
->vl_peer
, auth_str
);
12336 if (IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)->auth_simple
[0]
12339 " area %s virtual-link %pI4 authentication-key %s\n",
12340 buf
, &vl_data
->vl_peer
,
12341 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
12344 for (ALL_LIST_ELEMENTS_RO(
12345 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
12349 " area %s virtual-link %pI4 message-digest-key %d md5 %s\n",
12350 buf
, &vl_data
->vl_peer
,
12351 ck
->key_id
, ck
->auth_key
);
12359 static int config_write_ospf_redistribute(struct vty
*vty
, struct ospf
*ospf
)
12363 /* redistribute print. */
12364 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
12365 struct list
*red_list
;
12366 struct listnode
*node
;
12367 struct ospf_redist
*red
;
12369 red_list
= ospf
->redist
[type
];
12373 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
12374 vty_out(vty
, " redistribute %s",
12375 zebra_route_string(type
));
12377 vty_out(vty
, " %d", red
->instance
);
12379 if (red
->dmetric
.value
>= 0)
12380 vty_out(vty
, " metric %d", red
->dmetric
.value
);
12382 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
12383 vty_out(vty
, " metric-type 1");
12385 if (ROUTEMAP_NAME(red
))
12386 vty_out(vty
, " route-map %s",
12387 ROUTEMAP_NAME(red
));
12389 vty_out(vty
, "\n");
12396 static int ospf_cfg_write_helper_dis_rtr_walkcb(struct hash_bucket
*bucket
,
12399 struct advRtr
*rtr
= bucket
->data
;
12400 struct vty
*vty
= (struct vty
*)arg
;
12402 vty_out(vty
, " graceful-restart helper enable %pI4\n",
12404 return HASHWALK_CONTINUE
;
12407 static void config_write_ospf_gr(struct vty
*vty
, struct ospf
*ospf
)
12409 if (!ospf
->gr_info
.restart_support
)
12412 if (ospf
->gr_info
.grace_period
== OSPF_DFLT_GRACE_INTERVAL
)
12413 vty_out(vty
, " graceful-restart\n");
12415 vty_out(vty
, " graceful-restart grace-period %u\n",
12416 ospf
->gr_info
.grace_period
);
12419 static int config_write_ospf_gr_helper(struct vty
*vty
, struct ospf
*ospf
)
12421 if (ospf
->is_helper_supported
)
12422 vty_out(vty
, " graceful-restart helper enable\n");
12424 if (!ospf
->strict_lsa_check
)
12426 " no graceful-restart helper strict-lsa-checking\n");
12428 if (ospf
->only_planned_restart
)
12429 vty_out(vty
, " graceful-restart helper planned-only\n");
12431 if (ospf
->supported_grace_time
!= OSPF_MAX_GRACE_INTERVAL
)
12433 " graceful-restart helper supported-grace-time %d\n",
12434 ospf
->supported_grace_time
);
12436 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf
)) {
12437 hash_walk(ospf
->enable_rtr_list
,
12438 ospf_cfg_write_helper_dis_rtr_walkcb
, vty
);
12443 static int config_write_ospf_external_aggregator(struct vty
*vty
,
12446 struct route_node
*rn
;
12448 if (ospf
->aggr_delay_interval
!= OSPF_EXTL_AGGR_DEFAULT_DELAY
)
12449 vty_out(vty
, " aggregation timer %u\n",
12450 ospf
->aggr_delay_interval
);
12452 /* print 'summary-address A.B.C.D/M' */
12453 for (rn
= route_top(ospf
->rt_aggr_tbl
); rn
; rn
= route_next(rn
))
12455 struct ospf_external_aggr_rt
*aggr
= rn
->info
;
12457 vty_out(vty
, " summary-address %pI4/%d",
12458 &aggr
->p
.prefix
, aggr
->p
.prefixlen
);
12460 vty_out(vty
, " tag %u", aggr
->tag
);
12462 if (CHECK_FLAG(aggr
->flags
,
12463 OSPF_EXTERNAL_AGGRT_NO_ADVERTISE
))
12464 vty_out(vty
, " no-advertise");
12466 vty_out(vty
, "\n");
12472 static int config_write_ospf_default_metric(struct vty
*vty
, struct ospf
*ospf
)
12474 if (ospf
->default_metric
!= -1)
12475 vty_out(vty
, " default-metric %d\n", ospf
->default_metric
);
12479 static int config_write_ospf_distribute(struct vty
*vty
, struct ospf
*ospf
)
12482 struct ospf_redist
*red
;
12485 /* distribute-list print. */
12486 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
12487 if (DISTRIBUTE_NAME(ospf
, type
))
12488 vty_out(vty
, " distribute-list %s out %s\n",
12489 DISTRIBUTE_NAME(ospf
, type
),
12490 zebra_route_string(type
));
12492 /* default-information print. */
12493 if (ospf
->default_originate
!= DEFAULT_ORIGINATE_NONE
) {
12494 vty_out(vty
, " default-information originate");
12495 if (ospf
->default_originate
== DEFAULT_ORIGINATE_ALWAYS
)
12496 vty_out(vty
, " always");
12498 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
12500 if (red
->dmetric
.value
>= 0)
12501 vty_out(vty
, " metric %d",
12502 red
->dmetric
.value
);
12504 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
12505 vty_out(vty
, " metric-type 1");
12507 if (ROUTEMAP_NAME(red
))
12508 vty_out(vty
, " route-map %s",
12509 ROUTEMAP_NAME(red
));
12512 vty_out(vty
, "\n");
12519 static int config_write_ospf_distance(struct vty
*vty
, struct ospf
*ospf
)
12521 struct route_node
*rn
;
12522 struct ospf_distance
*odistance
;
12524 if (ospf
->distance_all
)
12525 vty_out(vty
, " distance %d\n", ospf
->distance_all
);
12527 if (ospf
->distance_intra
|| ospf
->distance_inter
12528 || ospf
->distance_external
) {
12529 vty_out(vty
, " distance ospf");
12531 if (ospf
->distance_intra
)
12532 vty_out(vty
, " intra-area %d", ospf
->distance_intra
);
12533 if (ospf
->distance_inter
)
12534 vty_out(vty
, " inter-area %d", ospf
->distance_inter
);
12535 if (ospf
->distance_external
)
12536 vty_out(vty
, " external %d", ospf
->distance_external
);
12538 vty_out(vty
, "\n");
12541 for (rn
= route_top(ospf
->distance_table
); rn
; rn
= route_next(rn
))
12542 if ((odistance
= rn
->info
) != NULL
) {
12543 vty_out(vty
, " distance %d %pFX %s\n",
12544 odistance
->distance
, &rn
->p
,
12545 odistance
->access_list
? odistance
->access_list
12551 static int ospf_config_write_one(struct vty
*vty
, struct ospf
*ospf
)
12555 /* `router ospf' print. */
12556 if (ospf
->instance
&& strcmp(ospf
->name
, VRF_DEFAULT_NAME
)) {
12557 vty_out(vty
, "router ospf %d vrf %s\n", ospf
->instance
,
12559 } else if (ospf
->instance
) {
12560 vty_out(vty
, "router ospf %d\n", ospf
->instance
);
12561 } else if (strcmp(ospf
->name
, VRF_DEFAULT_NAME
)) {
12562 vty_out(vty
, "router ospf vrf %s\n", ospf
->name
);
12564 vty_out(vty
, "router ospf\n");
12566 if (!ospf
->networks
) {
12571 /* Router ID print. */
12572 if (ospf
->router_id_static
.s_addr
!= INADDR_ANY
)
12573 vty_out(vty
, " ospf router-id %pI4\n",
12574 &ospf
->router_id_static
);
12576 /* zebra opaque attributes configuration. */
12577 if (CHECK_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
))
12578 vty_out(vty
, " ospf send-extra-data zebra\n");
12580 /* ABR type print. */
12581 if (ospf
->abr_type
!= OSPF_ABR_DEFAULT
)
12582 vty_out(vty
, " ospf abr-type %s\n",
12583 ospf_abr_type_str
[ospf
->abr_type
]);
12585 /* log-adjacency-changes flag print. */
12586 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
12587 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
))
12588 vty_out(vty
, " log-adjacency-changes detail\n");
12589 else if (!SAVE_OSPF_LOG_ADJACENCY_CHANGES
)
12590 vty_out(vty
, " log-adjacency-changes\n");
12591 } else if (SAVE_OSPF_LOG_ADJACENCY_CHANGES
) {
12592 vty_out(vty
, " no log-adjacency-changes\n");
12595 /* RFC1583 compatibility flag print -- Compatible with CISCO
12597 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
))
12598 vty_out(vty
, " compatible rfc1583\n");
12600 /* auto-cost reference-bandwidth configuration. */
12601 if (ospf
->ref_bandwidth
!= OSPF_DEFAULT_REF_BANDWIDTH
) {
12603 "! Important: ensure reference bandwidth is consistent across all routers\n");
12604 vty_out(vty
, " auto-cost reference-bandwidth %d\n",
12605 ospf
->ref_bandwidth
);
12608 /* SPF timers print. */
12609 if (ospf
->spf_delay
!= OSPF_SPF_DELAY_DEFAULT
12610 || ospf
->spf_holdtime
!= OSPF_SPF_HOLDTIME_DEFAULT
12611 || ospf
->spf_max_holdtime
!= OSPF_SPF_MAX_HOLDTIME_DEFAULT
)
12612 vty_out(vty
, " timers throttle spf %d %d %d\n", ospf
->spf_delay
,
12613 ospf
->spf_holdtime
, ospf
->spf_max_holdtime
);
12615 /* LSA timers print. */
12616 if (ospf
->min_ls_interval
!= OSPF_MIN_LS_INTERVAL
)
12617 vty_out(vty
, " timers throttle lsa all %d\n",
12618 ospf
->min_ls_interval
);
12619 if (ospf
->min_ls_arrival
!= OSPF_MIN_LS_ARRIVAL
)
12620 vty_out(vty
, " timers lsa min-arrival %d\n",
12621 ospf
->min_ls_arrival
);
12623 /* Write multiplier print. */
12624 if (ospf
->write_oi_count
!= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
)
12625 vty_out(vty
, " ospf write-multiplier %d\n",
12626 ospf
->write_oi_count
);
12628 if (ospf
->max_multipath
!= MULTIPATH_NUM
)
12629 vty_out(vty
, " maximum-paths %d\n", ospf
->max_multipath
);
12631 /* Max-metric router-lsa print */
12632 config_write_stub_router(vty
, ospf
);
12634 /* SPF refresh parameters print. */
12635 if (ospf
->lsa_refresh_interval
!= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
12636 vty_out(vty
, " refresh timer %d\n", ospf
->lsa_refresh_interval
);
12638 /* Redistribute information print. */
12639 config_write_ospf_redistribute(vty
, ospf
);
12641 /* Graceful Restart print */
12642 config_write_ospf_gr(vty
, ospf
);
12643 config_write_ospf_gr_helper(vty
, ospf
);
12645 /* Print external route aggregation. */
12646 config_write_ospf_external_aggregator(vty
, ospf
);
12648 /* passive-interface print. */
12649 if (ospf
->passive_interface_default
== OSPF_IF_PASSIVE
)
12650 vty_out(vty
, " passive-interface default\n");
12652 /* proactive-arp print. */
12653 if (ospf
->proactive_arp
!= OSPF_PROACTIVE_ARP_DEFAULT
) {
12654 if (ospf
->proactive_arp
)
12655 vty_out(vty
, " proactive-arp\n");
12657 vty_out(vty
, " no proactive-arp\n");
12660 /* TI-LFA print. */
12661 if (ospf
->ti_lfa_enabled
) {
12662 if (ospf
->ti_lfa_protection_type
== OSPF_TI_LFA_NODE_PROTECTION
)
12663 vty_out(vty
, " fast-reroute ti-lfa node-protection\n");
12665 vty_out(vty
, " fast-reroute ti-lfa\n");
12668 /* Network area print. */
12669 config_write_network_area(vty
, ospf
);
12671 /* Area config print. */
12672 config_write_ospf_area(vty
, ospf
);
12674 /* static neighbor print. */
12675 config_write_ospf_nbr_nbma(vty
, ospf
);
12677 /* Virtual-Link print. */
12678 config_write_virtual_link(vty
, ospf
);
12680 /* Default metric configuration. */
12681 config_write_ospf_default_metric(vty
, ospf
);
12683 /* Distribute-list and default-information print. */
12684 config_write_ospf_distribute(vty
, ospf
);
12686 /* Distance configuration. */
12687 config_write_ospf_distance(vty
, ospf
);
12689 ospf_opaque_config_write_router(vty
, ospf
);
12691 /* LDP-Sync print */
12692 ospf_ldp_sync_write_config(vty
, ospf
);
12694 vty_out(vty
, "exit\n");
12700 /* OSPF configuration write function. */
12701 static int ospf_config_write(struct vty
*vty
)
12704 struct listnode
*ospf_node
= NULL
;
12707 if (listcount(om
->ospf
) == 0)
12710 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, ospf_node
, ospf
)) {
12711 /* VRF Default check if it is running.
12712 * Upon daemon start, there could be default instance
12713 * in absence of 'router ospf'/oi_running is disabled. */
12714 if (ospf
->vrf_id
== VRF_DEFAULT
&& ospf
->oi_running
)
12715 write
+= ospf_config_write_one(vty
, ospf
);
12716 /* For Non-Default VRF simply display the configuration,
12717 * even if it is not oi_running. */
12718 else if (ospf
->vrf_id
!= VRF_DEFAULT
)
12719 write
+= ospf_config_write_one(vty
, ospf
);
12724 void ospf_vty_show_init(void)
12726 /* "show ip ospf" commands. */
12727 install_element(VIEW_NODE
, &show_ip_ospf_cmd
);
12729 install_element(VIEW_NODE
, &show_ip_ospf_instance_cmd
);
12731 /* "show ip ospf database" commands. */
12732 install_element(VIEW_NODE
, &show_ip_ospf_database_cmd
);
12733 install_element(VIEW_NODE
, &show_ip_ospf_database_max_cmd
);
12734 install_element(VIEW_NODE
,
12735 &show_ip_ospf_database_type_adv_router_cmd
);
12736 install_element(VIEW_NODE
,
12737 &show_ip_ospf_instance_database_type_adv_router_cmd
);
12738 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_cmd
);
12739 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_max_cmd
);
12741 /* "show ip ospf interface" commands. */
12742 install_element(VIEW_NODE
, &show_ip_ospf_interface_cmd
);
12744 install_element(VIEW_NODE
, &show_ip_ospf_instance_interface_cmd
);
12745 /* "show ip ospf interface traffic */
12746 install_element(VIEW_NODE
, &show_ip_ospf_interface_traffic_cmd
);
12748 /* "show ip ospf neighbor" commands. */
12749 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_detail_cmd
);
12750 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_cmd
);
12751 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_id_cmd
);
12752 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_all_cmd
);
12753 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_cmd
);
12754 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_cmd
);
12755 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_all_cmd
);
12757 install_element(VIEW_NODE
,
12758 &show_ip_ospf_instance_neighbor_int_detail_cmd
);
12759 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_int_cmd
);
12760 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_id_cmd
);
12761 install_element(VIEW_NODE
,
12762 &show_ip_ospf_instance_neighbor_detail_all_cmd
);
12763 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_detail_cmd
);
12764 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_cmd
);
12765 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_all_cmd
);
12767 /* "show ip ospf route" commands. */
12768 install_element(VIEW_NODE
, &show_ip_ospf_route_cmd
);
12769 install_element(VIEW_NODE
, &show_ip_ospf_border_routers_cmd
);
12770 install_element(VIEW_NODE
, &show_ip_ospf_reachable_routers_cmd
);
12772 install_element(VIEW_NODE
, &show_ip_ospf_instance_route_cmd
);
12773 install_element(VIEW_NODE
, &show_ip_ospf_instance_border_routers_cmd
);
12774 install_element(VIEW_NODE
,
12775 &show_ip_ospf_instance_reachable_routers_cmd
);
12777 /* "show ip ospf vrfs" commands. */
12778 install_element(VIEW_NODE
, &show_ip_ospf_vrfs_cmd
);
12780 /* "show ip ospf gr-helper details" command */
12781 install_element(VIEW_NODE
, &show_ip_ospf_gr_helper_cmd
);
12783 /* "show ip ospf summary-address" command */
12784 install_element(VIEW_NODE
, &show_ip_ospf_external_aggregator_cmd
);
12787 /* Initialization of OSPF interface. */
12788 static void ospf_vty_if_init(void)
12790 /* Install interface node. */
12791 if_cmd_init(config_write_interface
);
12793 /* "ip ospf authentication" commands. */
12794 install_element(INTERFACE_NODE
, &ip_ospf_authentication_args_addr_cmd
);
12795 install_element(INTERFACE_NODE
, &ip_ospf_authentication_addr_cmd
);
12796 install_element(INTERFACE_NODE
,
12797 &no_ip_ospf_authentication_args_addr_cmd
);
12798 install_element(INTERFACE_NODE
, &no_ip_ospf_authentication_addr_cmd
);
12799 install_element(INTERFACE_NODE
, &ip_ospf_authentication_key_addr_cmd
);
12800 install_element(INTERFACE_NODE
,
12801 &no_ip_ospf_authentication_key_authkey_addr_cmd
);
12802 install_element(INTERFACE_NODE
,
12803 &no_ospf_authentication_key_authkey_addr_cmd
);
12805 /* "ip ospf message-digest-key" commands. */
12806 install_element(INTERFACE_NODE
, &ip_ospf_message_digest_key_cmd
);
12807 install_element(INTERFACE_NODE
, &no_ip_ospf_message_digest_key_cmd
);
12809 /* "ip ospf cost" commands. */
12810 install_element(INTERFACE_NODE
, &ip_ospf_cost_cmd
);
12811 install_element(INTERFACE_NODE
, &no_ip_ospf_cost_cmd
);
12813 /* "ip ospf mtu-ignore" commands. */
12814 install_element(INTERFACE_NODE
, &ip_ospf_mtu_ignore_addr_cmd
);
12815 install_element(INTERFACE_NODE
, &no_ip_ospf_mtu_ignore_addr_cmd
);
12817 /* "ip ospf dead-interval" commands. */
12818 install_element(INTERFACE_NODE
, &ip_ospf_dead_interval_cmd
);
12819 install_element(INTERFACE_NODE
,
12820 &ip_ospf_dead_interval_minimal_addr_cmd
);
12821 install_element(INTERFACE_NODE
, &no_ip_ospf_dead_interval_cmd
);
12823 /* "ip ospf hello-interval" commands. */
12824 install_element(INTERFACE_NODE
, &ip_ospf_hello_interval_cmd
);
12825 install_element(INTERFACE_NODE
, &no_ip_ospf_hello_interval_cmd
);
12827 /* "ip ospf network" commands. */
12828 install_element(INTERFACE_NODE
, &ip_ospf_network_cmd
);
12829 install_element(INTERFACE_NODE
, &no_ip_ospf_network_cmd
);
12831 /* "ip ospf priority" commands. */
12832 install_element(INTERFACE_NODE
, &ip_ospf_priority_cmd
);
12833 install_element(INTERFACE_NODE
, &no_ip_ospf_priority_cmd
);
12835 /* "ip ospf retransmit-interval" commands. */
12836 install_element(INTERFACE_NODE
, &ip_ospf_retransmit_interval_addr_cmd
);
12837 install_element(INTERFACE_NODE
,
12838 &no_ip_ospf_retransmit_interval_addr_cmd
);
12840 /* "ip ospf transmit-delay" commands. */
12841 install_element(INTERFACE_NODE
, &ip_ospf_transmit_delay_addr_cmd
);
12842 install_element(INTERFACE_NODE
, &no_ip_ospf_transmit_delay_addr_cmd
);
12844 /* "ip ospf area" commands. */
12845 install_element(INTERFACE_NODE
, &ip_ospf_area_cmd
);
12846 install_element(INTERFACE_NODE
, &no_ip_ospf_area_cmd
);
12848 /* "ip ospf passive" commands. */
12849 install_element(INTERFACE_NODE
, &ip_ospf_passive_cmd
);
12850 install_element(INTERFACE_NODE
, &no_ip_ospf_passive_cmd
);
12852 /* These commands are compatibitliy for previous version. */
12853 install_element(INTERFACE_NODE
, &ospf_authentication_key_cmd
);
12854 install_element(INTERFACE_NODE
, &ospf_message_digest_key_cmd
);
12855 install_element(INTERFACE_NODE
, &no_ospf_message_digest_key_cmd
);
12856 install_element(INTERFACE_NODE
, &ospf_dead_interval_cmd
);
12857 install_element(INTERFACE_NODE
, &no_ospf_dead_interval_cmd
);
12858 install_element(INTERFACE_NODE
, &ospf_hello_interval_cmd
);
12859 install_element(INTERFACE_NODE
, &no_ospf_hello_interval_cmd
);
12860 install_element(INTERFACE_NODE
, &ospf_cost_cmd
);
12861 install_element(INTERFACE_NODE
, &no_ospf_cost_cmd
);
12862 install_element(INTERFACE_NODE
, &ospf_network_cmd
);
12863 install_element(INTERFACE_NODE
, &no_ospf_network_cmd
);
12864 install_element(INTERFACE_NODE
, &ospf_priority_cmd
);
12865 install_element(INTERFACE_NODE
, &no_ospf_priority_cmd
);
12866 install_element(INTERFACE_NODE
, &ospf_retransmit_interval_cmd
);
12867 install_element(INTERFACE_NODE
, &no_ospf_retransmit_interval_cmd
);
12868 install_element(INTERFACE_NODE
, &ospf_transmit_delay_cmd
);
12869 install_element(INTERFACE_NODE
, &no_ospf_transmit_delay_cmd
);
12872 static void ospf_vty_zebra_init(void)
12874 install_element(OSPF_NODE
, &ospf_redistribute_source_cmd
);
12875 install_element(OSPF_NODE
, &no_ospf_redistribute_source_cmd
);
12876 install_element(OSPF_NODE
, &ospf_redistribute_instance_source_cmd
);
12877 install_element(OSPF_NODE
, &no_ospf_redistribute_instance_source_cmd
);
12879 install_element(OSPF_NODE
, &ospf_distribute_list_out_cmd
);
12880 install_element(OSPF_NODE
, &no_ospf_distribute_list_out_cmd
);
12882 install_element(OSPF_NODE
, &ospf_default_information_originate_cmd
);
12883 install_element(OSPF_NODE
, &no_ospf_default_information_originate_cmd
);
12885 install_element(OSPF_NODE
, &ospf_default_metric_cmd
);
12886 install_element(OSPF_NODE
, &no_ospf_default_metric_cmd
);
12888 install_element(OSPF_NODE
, &ospf_distance_cmd
);
12889 install_element(OSPF_NODE
, &no_ospf_distance_cmd
);
12890 install_element(OSPF_NODE
, &no_ospf_distance_ospf_cmd
);
12891 install_element(OSPF_NODE
, &ospf_distance_ospf_cmd
);
12893 /*Ospf garcefull restart helper configurations */
12894 install_element(OSPF_NODE
, &ospf_gr_helper_enable_cmd
);
12895 install_element(OSPF_NODE
, &no_ospf_gr_helper_enable_cmd
);
12896 install_element(OSPF_NODE
, &ospf_gr_helper_enable_lsacheck_cmd
);
12897 install_element(OSPF_NODE
, &no_ospf_gr_helper_enable_lsacheck_cmd
);
12898 install_element(OSPF_NODE
, &ospf_gr_helper_supported_grace_time_cmd
);
12899 install_element(OSPF_NODE
, &no_ospf_gr_helper_supported_grace_time_cmd
);
12900 install_element(OSPF_NODE
, &ospf_gr_helper_planned_only_cmd
);
12901 install_element(OSPF_NODE
, &no_ospf_gr_helper_planned_only_cmd
);
12903 /* External LSA summarisation config commands.*/
12904 install_element(OSPF_NODE
, &ospf_external_route_aggregation_cmd
);
12905 install_element(OSPF_NODE
, &no_ospf_external_route_aggregation_cmd
);
12906 install_element(OSPF_NODE
,
12907 &ospf_external_route_aggregation_no_adrvertise_cmd
);
12908 install_element(OSPF_NODE
,
12909 &no_ospf_external_route_aggregation_no_adrvertise_cmd
);
12910 install_element(OSPF_NODE
, &ospf_route_aggregation_timer_cmd
);
12911 install_element(OSPF_NODE
, &no_ospf_route_aggregation_timer_cmd
);
12914 static int ospf_config_write(struct vty
*vty
);
12915 static struct cmd_node ospf_node
= {
12918 .parent_node
= CONFIG_NODE
,
12919 .prompt
= "%s(config-router)# ",
12920 .config_write
= ospf_config_write
,
12923 static void ospf_interface_clear(struct interface
*ifp
)
12925 if (!if_is_operative(ifp
))
12928 if (IS_DEBUG_OSPF(ism
, ISM_EVENTS
))
12929 zlog_debug("ISM[%s]: clear by reset", ifp
->name
);
12931 ospf_if_reset(ifp
);
12934 DEFUN (clear_ip_ospf_interface
,
12935 clear_ip_ospf_interface_cmd
,
12936 "clear ip ospf [vrf NAME] interface [IFNAME]",
12939 "OSPF information\n"
12941 "Interface information\n"
12942 "Interface name\n")
12944 int idx_ifname
= 0;
12946 struct interface
*ifp
;
12947 struct listnode
*node
;
12948 struct ospf
*ospf
= NULL
;
12949 char *vrf_name
= NULL
;
12950 vrf_id_t vrf_id
= VRF_DEFAULT
;
12951 struct vrf
*vrf
= NULL
;
12953 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
12954 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
12955 if (vrf_name
&& strmatch(vrf_name
, VRF_DEFAULT_NAME
))
12958 vrf
= vrf_lookup_by_name(vrf_name
);
12960 vrf_id
= vrf
->vrf_id
;
12962 if (!argv_find(argv
, argc
, "IFNAME", &idx_ifname
)) {
12963 /* Clear all the ospfv2 interfaces. */
12964 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
12965 if (vrf_id
!= ospf
->vrf_id
)
12968 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
12969 FOR_ALL_INTERFACES (vrf
, ifp
)
12970 ospf_interface_clear(ifp
);
12973 /* Interface name is specified. */
12974 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf_id
);
12976 vty_out(vty
, "No such interface name\n");
12978 ospf_interface_clear(ifp
);
12981 return CMD_SUCCESS
;
12984 DEFPY_HIDDEN(ospf_lsa_refresh_timer
, ospf_lsa_refresh_timer_cmd
,
12985 "[no$no] ospf lsa-refresh [(120-1800)]$value",
12987 "OSPF lsa refresh timer\n"
12988 "timer value in seconds\n")
12990 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
12993 ospf
->lsa_refresh_timer
= OSPF_LS_REFRESH_TIME
;
12995 ospf
->lsa_refresh_timer
= value
;
12997 return CMD_SUCCESS
;
13000 DEFPY_HIDDEN(ospf_maxage_delay_timer
, ospf_maxage_delay_timer_cmd
,
13001 "[no$no] ospf maxage-delay [(0-60)]$value",
13003 "OSPF lsa maxage delay timer\n"
13004 "timer value in seconds\n")
13006 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
13009 ospf
->maxage_delay
= OSPF_LSA_MAXAGE_REMOVE_DELAY_DEFAULT
;
13011 ospf
->maxage_delay
= value
;
13013 THREAD_OFF(ospf
->t_maxage
);
13014 OSPF_TIMER_ON(ospf
->t_maxage
, ospf_maxage_lsa_remover
,
13015 ospf
->maxage_delay
);
13017 return CMD_SUCCESS
;
13020 void ospf_vty_clear_init(void)
13022 install_element(ENABLE_NODE
, &clear_ip_ospf_interface_cmd
);
13023 install_element(ENABLE_NODE
, &clear_ip_ospf_process_cmd
);
13024 install_element(ENABLE_NODE
, &clear_ip_ospf_neighbor_cmd
);
13028 /* Install OSPF related vty commands. */
13029 void ospf_vty_init(void)
13031 /* Install ospf top node. */
13032 install_node(&ospf_node
);
13034 /* "router ospf" commands. */
13035 install_element(CONFIG_NODE
, &router_ospf_cmd
);
13036 install_element(CONFIG_NODE
, &no_router_ospf_cmd
);
13039 install_default(OSPF_NODE
);
13041 /* "ospf router-id" commands. */
13042 install_element(OSPF_NODE
, &ospf_router_id_cmd
);
13043 install_element(OSPF_NODE
, &ospf_router_id_old_cmd
);
13044 install_element(OSPF_NODE
, &no_ospf_router_id_cmd
);
13046 /* "passive-interface" commands. */
13047 install_element(OSPF_NODE
, &ospf_passive_interface_default_cmd
);
13048 install_element(OSPF_NODE
, &ospf_passive_interface_addr_cmd
);
13049 install_element(OSPF_NODE
, &no_ospf_passive_interface_default_cmd
);
13050 install_element(OSPF_NODE
, &no_ospf_passive_interface_addr_cmd
);
13052 /* "ospf abr-type" commands. */
13053 install_element(OSPF_NODE
, &ospf_abr_type_cmd
);
13054 install_element(OSPF_NODE
, &no_ospf_abr_type_cmd
);
13056 /* "ospf log-adjacency-changes" commands. */
13057 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_cmd
);
13058 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_detail_cmd
);
13059 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_cmd
);
13060 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_detail_cmd
);
13062 /* "ospf rfc1583-compatible" commands. */
13063 install_element(OSPF_NODE
, &ospf_compatible_rfc1583_cmd
);
13064 install_element(OSPF_NODE
, &no_ospf_compatible_rfc1583_cmd
);
13065 install_element(OSPF_NODE
, &ospf_rfc1583_flag_cmd
);
13066 install_element(OSPF_NODE
, &no_ospf_rfc1583_flag_cmd
);
13068 /* "ospf send-extra-data zebra" commands. */
13069 install_element(OSPF_NODE
, &ospf_send_extra_data_cmd
);
13071 /* "network area" commands. */
13072 install_element(OSPF_NODE
, &ospf_network_area_cmd
);
13073 install_element(OSPF_NODE
, &no_ospf_network_area_cmd
);
13075 /* "area authentication" commands. */
13076 install_element(OSPF_NODE
,
13077 &ospf_area_authentication_message_digest_cmd
);
13078 install_element(OSPF_NODE
, &ospf_area_authentication_cmd
);
13079 install_element(OSPF_NODE
, &no_ospf_area_authentication_cmd
);
13081 /* "area range" commands. */
13082 install_element(OSPF_NODE
, &ospf_area_range_cmd
);
13083 install_element(OSPF_NODE
, &ospf_area_range_cost_cmd
);
13084 install_element(OSPF_NODE
, &ospf_area_range_not_advertise_cmd
);
13085 install_element(OSPF_NODE
, &no_ospf_area_range_cmd
);
13086 install_element(OSPF_NODE
, &no_ospf_area_range_substitute_cmd
);
13088 /* "area virtual-link" commands. */
13089 install_element(OSPF_NODE
, &ospf_area_vlink_cmd
);
13090 install_element(OSPF_NODE
, &ospf_area_vlink_intervals_cmd
);
13091 install_element(OSPF_NODE
, &no_ospf_area_vlink_cmd
);
13092 install_element(OSPF_NODE
, &no_ospf_area_vlink_intervals_cmd
);
13095 /* "area stub" commands. */
13096 install_element(OSPF_NODE
, &ospf_area_stub_no_summary_cmd
);
13097 install_element(OSPF_NODE
, &ospf_area_stub_cmd
);
13098 install_element(OSPF_NODE
, &no_ospf_area_stub_no_summary_cmd
);
13099 install_element(OSPF_NODE
, &no_ospf_area_stub_cmd
);
13101 /* "area nssa" commands. */
13102 install_element(OSPF_NODE
, &ospf_area_nssa_cmd
);
13103 install_element(OSPF_NODE
, &ospf_area_nssa_translate_cmd
);
13104 install_element(OSPF_NODE
, &ospf_area_nssa_no_summary_cmd
);
13105 install_element(OSPF_NODE
, &no_ospf_area_nssa_no_summary_cmd
);
13106 install_element(OSPF_NODE
, &ospf_area_nssa_suppress_fa_cmd
);
13107 install_element(OSPF_NODE
, &no_ospf_area_nssa_suppress_fa_cmd
);
13108 install_element(OSPF_NODE
, &no_ospf_area_nssa_cmd
);
13110 install_element(OSPF_NODE
, &ospf_area_default_cost_cmd
);
13111 install_element(OSPF_NODE
, &no_ospf_area_default_cost_cmd
);
13113 install_element(OSPF_NODE
, &ospf_area_shortcut_cmd
);
13114 install_element(OSPF_NODE
, &no_ospf_area_shortcut_cmd
);
13116 install_element(OSPF_NODE
, &ospf_area_export_list_cmd
);
13117 install_element(OSPF_NODE
, &no_ospf_area_export_list_cmd
);
13119 install_element(OSPF_NODE
, &ospf_area_filter_list_cmd
);
13120 install_element(OSPF_NODE
, &no_ospf_area_filter_list_cmd
);
13122 install_element(OSPF_NODE
, &ospf_area_import_list_cmd
);
13123 install_element(OSPF_NODE
, &no_ospf_area_import_list_cmd
);
13125 /* SPF timer commands */
13126 install_element(OSPF_NODE
, &ospf_timers_throttle_spf_cmd
);
13127 install_element(OSPF_NODE
, &no_ospf_timers_throttle_spf_cmd
);
13129 /* LSA timers commands */
13130 install_element(OSPF_NODE
, &ospf_timers_min_ls_interval_cmd
);
13131 install_element(OSPF_NODE
, &no_ospf_timers_min_ls_interval_cmd
);
13132 install_element(OSPF_NODE
, &ospf_timers_lsa_min_arrival_cmd
);
13133 install_element(OSPF_NODE
, &no_ospf_timers_lsa_min_arrival_cmd
);
13135 /* refresh timer commands */
13136 install_element(OSPF_NODE
, &ospf_refresh_timer_cmd
);
13137 install_element(OSPF_NODE
, &no_ospf_refresh_timer_val_cmd
);
13139 /* max-metric commands */
13140 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_admin_cmd
);
13141 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_admin_cmd
);
13142 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_startup_cmd
);
13143 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_startup_cmd
);
13144 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_shutdown_cmd
);
13145 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_shutdown_cmd
);
13147 /* reference bandwidth commands */
13148 install_element(OSPF_NODE
, &ospf_auto_cost_reference_bandwidth_cmd
);
13149 install_element(OSPF_NODE
, &no_ospf_auto_cost_reference_bandwidth_cmd
);
13151 /* "neighbor" commands. */
13152 install_element(OSPF_NODE
, &ospf_neighbor_cmd
);
13153 install_element(OSPF_NODE
, &ospf_neighbor_poll_interval_cmd
);
13154 install_element(OSPF_NODE
, &no_ospf_neighbor_cmd
);
13155 install_element(OSPF_NODE
, &no_ospf_neighbor_poll_cmd
);
13157 /* write multiplier commands */
13158 install_element(OSPF_NODE
, &ospf_write_multiplier_cmd
);
13159 install_element(OSPF_NODE
, &write_multiplier_cmd
);
13160 install_element(OSPF_NODE
, &no_ospf_write_multiplier_cmd
);
13161 install_element(OSPF_NODE
, &no_write_multiplier_cmd
);
13163 /* "proactive-arp" commands. */
13164 install_element(OSPF_NODE
, &ospf_proactive_arp_cmd
);
13165 install_element(OSPF_NODE
, &no_ospf_proactive_arp_cmd
);
13167 /* TI-LFA commands */
13168 install_element(OSPF_NODE
, &ospf_ti_lfa_cmd
);
13169 install_element(OSPF_NODE
, &no_ospf_ti_lfa_cmd
);
13171 /* Max path configurations */
13172 install_element(OSPF_NODE
, &ospf_max_multipath_cmd
);
13173 install_element(OSPF_NODE
, &no_ospf_max_multipath_cmd
);
13175 vrf_cmd_init(NULL
);
13177 install_element(OSPF_NODE
, &ospf_lsa_refresh_timer_cmd
);
13178 install_element(OSPF_NODE
, &ospf_maxage_delay_timer_cmd
);
13180 /* Init interface related vty commands. */
13181 ospf_vty_if_init();
13183 /* Init zebra related vty commands. */
13184 ospf_vty_zebra_init();