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"
58 #include "ospfd/ospf_orr.h"
61 FRR_CFG_DEFAULT_BOOL(OSPF_LOG_ADJACENCY_CHANGES
,
62 { .val_bool
= true, .match_profile
= "datacenter", },
63 { .val_bool
= false },
66 static const char *const ospf_network_type_str
[] = {
67 "Null", "POINTOPOINT", "BROADCAST", "NBMA", "POINTOMULTIPOINT",
68 "VIRTUALLINK", "LOOPBACK"};
70 /* Utility functions. */
71 int str2area_id(const char *str
, struct in_addr
*area_id
, int *area_id_fmt
)
75 area_id
->s_addr
= htonl(strtoul(str
, &ep
, 10));
76 if (*ep
&& !inet_aton(str
, area_id
))
80 *ep
? OSPF_AREA_ID_FMT_DOTTEDQUAD
: OSPF_AREA_ID_FMT_DECIMAL
;
85 static void area_id2str(char *buf
, int length
, struct in_addr
*area_id
,
88 if (area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
89 inet_ntop(AF_INET
, area_id
, buf
, length
);
91 snprintf(buf
, length
, "%lu",
92 (unsigned long)ntohl(area_id
->s_addr
));
95 static int str2metric(const char *str
, int *metric
)
101 *metric
= strtol(str
, NULL
, 10);
102 if (*metric
< 0 || *metric
> 16777214) {
103 /* vty_out (vty, "OSPF metric value is invalid\n"); */
110 static int str2metric_type(const char *str
, int *metric_type
)
116 if (strncmp(str
, "1", 1) == 0)
117 *metric_type
= EXTERNAL_METRIC_TYPE_1
;
118 else if (strncmp(str
, "2", 1) == 0)
119 *metric_type
= EXTERNAL_METRIC_TYPE_2
;
126 int ospf_oi_count(struct interface
*ifp
)
128 struct route_node
*rn
;
131 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
138 #define OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf) \
139 if (argv_find(argv, argc, "vrf", &idx_vrf)) { \
140 vrf_name = argv[idx_vrf + 1]->arg; \
141 all_vrf = strmatch(vrf_name, "all"); \
144 static int ospf_router_cmd_parse(struct vty
*vty
, struct cmd_token
*argv
[],
145 const int argc
, unsigned short *instance
,
146 const char **vrf_name
)
148 int idx_vrf
= 0, idx_inst
= 0;
151 if (argv_find(argv
, argc
, "(1-65535)", &idx_inst
)) {
152 if (ospf_instance
== 0) {
154 "%% OSPF is not running in instance mode\n");
155 return CMD_WARNING_CONFIG_FAILED
;
158 *instance
= strtoul(argv
[idx_inst
]->arg
, NULL
, 10);
161 *vrf_name
= VRF_DEFAULT_NAME
;
162 if (argv_find(argv
, argc
, "vrf", &idx_vrf
)) {
163 if (ospf_instance
!= 0) {
165 "%% VRF is not supported in instance mode\n");
166 return CMD_WARNING_CONFIG_FAILED
;
169 *vrf_name
= argv
[idx_vrf
+ 1]->arg
;
175 static void ospf_show_vrf_name(struct ospf
*ospf
, struct vty
*vty
,
176 json_object
*json
, uint8_t use_vrf
)
180 json_object_string_add(json
, "vrfName",
181 ospf_get_name(ospf
));
182 json_object_int_add(json
, "vrfId", ospf
->vrf_id
);
184 vty_out(vty
, "VRF Name: %s\n", ospf_get_name(ospf
));
188 #ifndef VTYSH_EXTRACT_PL
189 #include "ospfd/ospf_vty_clippy.c"
192 DEFUN_NOSH (router_ospf
,
194 "router ospf [{(1-65535)|vrf NAME}]",
195 "Enable a routing process\n"
196 "Start OSPF configuration\n"
200 unsigned short instance
;
201 const char *vrf_name
;
202 bool created
= false;
206 ret
= ospf_router_cmd_parse(vty
, argv
, argc
, &instance
, &vrf_name
);
207 if (ret
!= CMD_SUCCESS
)
210 if (instance
!= ospf_instance
) {
211 VTY_PUSH_CONTEXT_NULL(OSPF_NODE
);
212 return CMD_NOT_MY_INSTANCE
;
215 ospf
= ospf_get(instance
, vrf_name
, &created
);
218 if (DFLT_OSPF_LOG_ADJACENCY_CHANGES
)
219 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
221 if (IS_DEBUG_OSPF_EVENT
)
223 "Config command 'router ospf %d' received, vrf %s id %u oi_running %u",
224 ospf
->instance
, ospf_get_name(ospf
), ospf
->vrf_id
,
227 VTY_PUSH_CONTEXT(OSPF_NODE
, ospf
);
232 DEFUN (no_router_ospf
,
234 "no router ospf [{(1-65535)|vrf NAME}]",
236 "Enable a routing process\n"
237 "Start OSPF configuration\n"
241 unsigned short instance
;
242 const char *vrf_name
;
246 ret
= ospf_router_cmd_parse(vty
, argv
, argc
, &instance
, &vrf_name
);
247 if (ret
!= CMD_SUCCESS
)
250 if (instance
!= ospf_instance
)
251 return CMD_NOT_MY_INSTANCE
;
253 ospf
= ospf_lookup(instance
, vrf_name
);
257 ret
= CMD_WARNING_CONFIG_FAILED
;
263 DEFPY (ospf_router_id
,
265 "ospf router-id A.B.C.D",
266 "OSPF specific commands\n"
267 "router-id for the OSPF process\n"
268 "OSPF router-id in IP address format\n")
270 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
272 struct listnode
*node
;
273 struct ospf_area
*area
;
275 ospf
->router_id_static
= router_id
;
277 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
278 if (area
->full_nbrs
) {
280 "For this router-id change to take effect, use \"clear ip ospf process\" command\n");
284 ospf_router_id_update(ospf
);
289 DEFUN_HIDDEN (ospf_router_id_old
,
290 ospf_router_id_old_cmd
,
292 "router-id for the OSPF process\n"
293 "OSPF router-id in IP address format\n")
295 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
297 struct listnode
*node
;
298 struct ospf_area
*area
;
299 struct in_addr router_id
;
302 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &router_id
);
304 vty_out(vty
, "Please specify Router ID by A.B.C.D\n");
305 return CMD_WARNING_CONFIG_FAILED
;
308 ospf
->router_id_static
= router_id
;
310 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
311 if (area
->full_nbrs
) {
313 "For this router-id change to take effect, use \"clear ip ospf process\" command\n");
317 ospf_router_id_update(ospf
);
322 DEFPY (no_ospf_router_id
,
323 no_ospf_router_id_cmd
,
324 "no ospf router-id [A.B.C.D]",
326 "OSPF specific commands\n"
327 "router-id for the OSPF process\n"
328 "OSPF router-id in IP address format\n")
330 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
331 struct listnode
*node
;
332 struct ospf_area
*area
;
335 if (!IPV4_ADDR_SAME(&ospf
->router_id_static
, &router_id
)) {
336 vty_out(vty
, "%% OSPF router-id doesn't match\n");
337 return CMD_WARNING_CONFIG_FAILED
;
341 ospf
->router_id_static
.s_addr
= 0;
343 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
344 if (area
->full_nbrs
) {
346 "For this router-id change to take effect, use \"clear ip ospf process\" command\n");
350 ospf_router_id_update(ospf
);
356 static void ospf_passive_interface_default_update(struct ospf
*ospf
,
360 struct ospf_interface
*oi
;
362 ospf
->passive_interface_default
= newval
;
364 /* update multicast memberships */
365 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, ln
, oi
))
366 ospf_if_set_multicast(oi
);
369 static void ospf_passive_interface_update(struct interface
*ifp
,
370 struct ospf_if_params
*params
,
371 struct in_addr addr
, uint8_t newval
)
373 struct route_node
*rn
;
375 if (OSPF_IF_PARAM_CONFIGURED(params
, passive_interface
)) {
376 if (params
->passive_interface
== newval
)
379 params
->passive_interface
= newval
;
380 UNSET_IF_PARAM(params
, passive_interface
);
381 if (params
!= IF_DEF_PARAMS(ifp
)) {
382 ospf_free_if_params(ifp
, addr
);
383 ospf_if_update_params(ifp
, addr
);
386 params
->passive_interface
= newval
;
387 SET_IF_PARAM(params
, passive_interface
);
391 * XXX We should call ospf_if_set_multicast on exactly those
392 * interfaces for which the passive property changed. It is too much
393 * work to determine this set, so we do this for every interface.
394 * This is safe and reasonable because ospf_if_set_multicast uses a
395 * record of joined groups to avoid systems calls if the desired
396 * memberships match the current memership.
399 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
400 struct ospf_interface
*oi
= rn
->info
;
403 ospf_if_set_multicast(oi
);
407 * XXX It is not clear what state transitions the interface needs to
408 * undergo when going from active to passive and vice versa. Fixing
409 * this will require precise identification of interfaces having such a
414 DEFUN (ospf_passive_interface_default
,
415 ospf_passive_interface_default_cmd
,
416 "passive-interface default",
417 "Suppress routing updates on an interface\n"
418 "Suppress routing updates on interfaces by default\n")
420 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
422 ospf_passive_interface_default_update(ospf
, OSPF_IF_PASSIVE
);
427 DEFUN_HIDDEN (ospf_passive_interface_addr
,
428 ospf_passive_interface_addr_cmd
,
429 "passive-interface IFNAME [A.B.C.D]",
430 "Suppress routing updates on an interface\n"
434 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
436 struct interface
*ifp
= NULL
;
437 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
438 struct ospf_if_params
*params
;
442 "This command is deprecated, because it is not VRF-aware.\n");
444 "Please, use \"ip ospf passive\" on an interface instead.\n");
446 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
447 ifp
= if_get_by_name(argv
[1]->arg
, ospf
->vrf_id
, ospf
->name
);
450 vty_out(vty
, "interface %s not found.\n", (char *)argv
[1]->arg
);
451 return CMD_WARNING_CONFIG_FAILED
;
455 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
458 "Please specify interface address by A.B.C.D\n");
459 return CMD_WARNING_CONFIG_FAILED
;
462 params
= ospf_get_if_params(ifp
, addr
);
463 ospf_if_update_params(ifp
, addr
);
465 params
= IF_DEF_PARAMS(ifp
);
468 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_PASSIVE
);
473 DEFUN (no_ospf_passive_interface_default
,
474 no_ospf_passive_interface_default_cmd
,
475 "no passive-interface default",
477 "Allow routing updates on an interface\n"
478 "Allow routing updates on interfaces by default\n")
480 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
482 ospf_passive_interface_default_update(ospf
, OSPF_IF_ACTIVE
);
487 DEFUN_HIDDEN (no_ospf_passive_interface
,
488 no_ospf_passive_interface_addr_cmd
,
489 "no passive-interface IFNAME [A.B.C.D]",
491 "Allow routing updates on an interface\n"
495 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
497 struct interface
*ifp
= NULL
;
498 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
499 struct ospf_if_params
*params
;
503 "This command is deprecated, because it is not VRF-aware.\n");
505 "Please, use \"no ip ospf passive\" on an interface instead.\n");
507 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
508 ifp
= if_get_by_name(argv
[2]->arg
, ospf
->vrf_id
, ospf
->name
);
511 vty_out(vty
, "interface %s not found.\n", (char *)argv
[2]->arg
);
512 return CMD_WARNING_CONFIG_FAILED
;
516 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
519 "Please specify interface address by A.B.C.D\n");
520 return CMD_WARNING_CONFIG_FAILED
;
522 params
= ospf_lookup_if_params(ifp
, addr
);
526 params
= IF_DEF_PARAMS(ifp
);
529 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_ACTIVE
);
535 DEFUN (ospf_network_area
,
536 ospf_network_area_cmd
,
537 "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
538 "Enable routing on an IP network\n"
539 "OSPF network prefix\n"
540 "Set the OSPF area ID\n"
541 "OSPF area ID in IP address format\n"
542 "OSPF area ID as a decimal value\n")
544 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
545 int idx_ipv4_prefixlen
= 1;
546 int idx_ipv4_number
= 3;
547 struct prefix_ipv4 p
;
548 struct in_addr area_id
;
552 if (ospf
->instance
) {
554 "The network command is not supported in multi-instance ospf\n");
555 return CMD_WARNING_CONFIG_FAILED
;
558 count
= ospf_count_area_params(ospf
);
561 "Please remove all ip ospf area x.x.x.x commands first.\n");
562 if (IS_DEBUG_OSPF_EVENT
)
564 "%s ospf vrf %s num of %u ip ospf area x config",
565 __func__
, ospf_get_name(ospf
), count
);
566 return CMD_WARNING_CONFIG_FAILED
;
569 /* Get network prefix and Area ID. */
570 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
571 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
573 ret
= ospf_network_set(ospf
, &p
, area_id
, format
);
575 vty_out(vty
, "There is already same network statement.\n");
576 return CMD_WARNING_CONFIG_FAILED
;
582 DEFUN (no_ospf_network_area
,
583 no_ospf_network_area_cmd
,
584 "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
586 "Enable routing on an IP network\n"
587 "OSPF network prefix\n"
588 "Set the OSPF area ID\n"
589 "OSPF area ID in IP address format\n"
590 "OSPF area ID as a decimal value\n")
592 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
593 int idx_ipv4_prefixlen
= 2;
594 int idx_ipv4_number
= 4;
595 struct prefix_ipv4 p
;
596 struct in_addr area_id
;
599 if (ospf
->instance
) {
601 "The network command is not supported in multi-instance ospf\n");
602 return CMD_WARNING_CONFIG_FAILED
;
605 /* Get network prefix and Area ID. */
606 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
607 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
609 ret
= ospf_network_unset(ospf
, &p
, area_id
);
612 "Can't find specified network area configuration.\n");
613 return CMD_WARNING_CONFIG_FAILED
;
619 DEFUN (ospf_area_range
,
621 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]",
622 "OSPF area parameters\n"
623 "OSPF area ID in IP address format\n"
624 "OSPF area ID as a decimal value\n"
625 "Summarize routes matching address/mask (border routers only)\n"
626 "Area range prefix\n"
627 "Advertise this range (default)\n"
628 "User specified metric for this range\n"
629 "Advertised metric for this range\n")
631 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
632 int idx_ipv4_number
= 1;
633 int idx_ipv4_prefixlen
= 3;
635 struct prefix_ipv4 p
;
636 struct in_addr area_id
;
640 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
641 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
643 ospf_area_range_set(ospf
, area_id
, &p
, OSPF_AREA_RANGE_ADVERTISE
);
644 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
647 cost
= strtoul(argv
[idx_cost
]->arg
, NULL
, 10);
648 ospf_area_range_cost_set(ospf
, area_id
, &p
, cost
);
654 DEFUN (ospf_area_range_cost
,
655 ospf_area_range_cost_cmd
,
656 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M {cost (0-16777215)|substitute A.B.C.D/M}",
657 "OSPF area parameters\n"
658 "OSPF area ID in IP address format\n"
659 "OSPF area ID as a decimal value\n"
660 "Summarize routes matching address/mask (border routers only)\n"
661 "Area range prefix\n"
662 "User specified metric for this range\n"
663 "Advertised metric for this range\n"
664 "Announce area range as another prefix\n"
665 "Network prefix to be announced instead of range\n")
667 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
668 int idx_ipv4_number
= 1;
669 int idx_ipv4_prefixlen
= 3;
671 struct prefix_ipv4 p
, s
;
672 struct in_addr area_id
;
676 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
677 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
679 ospf_area_range_set(ospf
, area_id
, &p
, OSPF_AREA_RANGE_ADVERTISE
);
680 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
683 if (argv_find(argv
, argc
, "cost", &idx
)) {
684 cost
= strtoul(argv
[idx
+ 1]->arg
, NULL
, 10);
685 ospf_area_range_cost_set(ospf
, area_id
, &p
, cost
);
689 if (argv_find(argv
, argc
, "substitute", &idx
)) {
690 str2prefix_ipv4(argv
[idx
+ 1]->arg
, &s
);
691 ospf_area_range_substitute_set(ospf
, area_id
, &p
, &s
);
697 DEFUN (ospf_area_range_not_advertise
,
698 ospf_area_range_not_advertise_cmd
,
699 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise",
700 "OSPF area parameters\n"
701 "OSPF area ID in IP address format\n"
702 "OSPF area ID as a decimal value\n"
703 "Summarize routes matching address/mask (border routers only)\n"
704 "Area range prefix\n"
705 "DoNotAdvertise this range\n")
707 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
708 int idx_ipv4_number
= 1;
709 int idx_ipv4_prefixlen
= 3;
710 struct prefix_ipv4 p
;
711 struct in_addr area_id
;
714 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
715 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
717 ospf_area_range_set(ospf
, area_id
, &p
, 0);
718 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
720 ospf_area_range_substitute_unset(ospf
, area_id
, &p
);
725 DEFUN (no_ospf_area_range
,
726 no_ospf_area_range_cmd
,
727 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]",
729 "OSPF area parameters\n"
730 "OSPF area ID in IP address format\n"
731 "OSPF area ID as a decimal value\n"
732 "Summarize routes matching address/mask (border routers only)\n"
733 "Area range prefix\n"
734 "User specified metric for this range\n"
735 "Advertised metric for this range\n"
736 "Advertise this range (default)\n"
737 "User specified metric for this range\n"
738 "Advertised metric for this range\n"
739 "DoNotAdvertise this range\n")
741 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
742 int idx_ipv4_number
= 2;
743 int idx_ipv4_prefixlen
= 4;
744 struct prefix_ipv4 p
;
745 struct in_addr area_id
;
748 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
749 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
751 ospf_area_range_unset(ospf
, area_id
, &p
);
756 DEFUN (no_ospf_area_range_substitute
,
757 no_ospf_area_range_substitute_cmd
,
758 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
760 "OSPF area parameters\n"
761 "OSPF area ID in IP address format\n"
762 "OSPF area ID as a decimal value\n"
763 "Summarize routes matching address/mask (border routers only)\n"
764 "Area range prefix\n"
765 "Announce area range as another prefix\n"
766 "Network prefix to be announced instead of range\n")
768 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
769 int idx_ipv4_number
= 2;
770 int idx_ipv4_prefixlen
= 4;
771 int idx_ipv4_prefixlen_2
= 6;
772 struct prefix_ipv4 p
, s
;
773 struct in_addr area_id
;
776 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
777 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
778 str2prefix_ipv4(argv
[idx_ipv4_prefixlen_2
]->arg
, &s
);
780 ospf_area_range_substitute_unset(ospf
, area_id
, &p
);
786 /* Command Handler Logic in VLink stuff is delicate!!
788 ALTER AT YOUR OWN RISK!!!!
790 Various dummy values are used to represent 'NoChange' state for
791 VLink configuration NOT being changed by a VLink command, and
792 special syntax is used within the command strings so that the
793 typed in command verbs can be seen in the configuration command
794 bacckend handler. This is to drastically reduce the verbeage
795 required to coe up with a reasonably compatible Cisco VLink command
797 - Matthew Grant <grantma@anathoth.gen.nz>
798 Wed, 21 Feb 2001 15:13:52 +1300
801 /* Configuration data for virtual links
803 struct ospf_vl_config_data
{
804 struct vty
*vty
; /* vty stuff */
805 struct in_addr area_id
; /* area ID from command line */
806 int area_id_fmt
; /* command line area ID format */
807 struct in_addr vl_peer
; /* command line vl_peer */
808 int auth_type
; /* Authehntication type, if given */
809 char *auth_key
; /* simple password if present */
810 int crypto_key_id
; /* Cryptographic key ID */
811 char *md5_key
; /* MD5 authentication key */
812 int hello_interval
; /* Obvious what these are... */
813 int retransmit_interval
;
818 static void ospf_vl_config_data_init(struct ospf_vl_config_data
*vl_config
,
821 memset(vl_config
, 0, sizeof(struct ospf_vl_config_data
));
822 vl_config
->auth_type
= OSPF_AUTH_CMD_NOTSEEN
;
823 vl_config
->vty
= vty
;
826 static struct ospf_vl_data
*
827 ospf_find_vl_data(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
829 struct ospf_area
*area
;
830 struct ospf_vl_data
*vl_data
;
832 struct in_addr area_id
;
834 vty
= vl_config
->vty
;
835 area_id
= vl_config
->area_id
;
837 if (area_id
.s_addr
== OSPF_AREA_BACKBONE
) {
839 "Configuring VLs over the backbone is not allowed\n");
842 area
= ospf_area_get(ospf
, area_id
);
843 ospf_area_display_format_set(ospf
, area
, vl_config
->area_id_fmt
);
845 if (area
->external_routing
!= OSPF_AREA_DEFAULT
) {
846 if (vl_config
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
847 vty_out(vty
, "Area %pI4 is %s\n", &area_id
,
848 area
->external_routing
== OSPF_AREA_NSSA
852 vty_out(vty
, "Area %ld is %s\n",
853 (unsigned long)ntohl(area_id
.s_addr
),
854 area
->external_routing
== OSPF_AREA_NSSA
860 if ((vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
->vl_peer
))
862 vl_data
= ospf_vl_data_new(area
, vl_config
->vl_peer
);
863 if (vl_data
->vl_oi
== NULL
) {
864 vl_data
->vl_oi
= ospf_vl_new(ospf
, vl_data
);
865 ospf_vl_add(ospf
, vl_data
);
866 ospf_spf_calculate_schedule(ospf
,
867 SPF_FLAG_CONFIG_CHANGE
);
874 static int ospf_vl_set_security(struct ospf_vl_data
*vl_data
,
875 struct ospf_vl_config_data
*vl_config
)
877 struct crypt_key
*ck
;
879 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
881 vty
= vl_config
->vty
;
883 if (vl_config
->auth_type
!= OSPF_AUTH_CMD_NOTSEEN
) {
884 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), auth_type
);
885 IF_DEF_PARAMS(ifp
)->auth_type
= vl_config
->auth_type
;
888 if (vl_config
->auth_key
) {
889 memset(IF_DEF_PARAMS(ifp
)->auth_simple
, 0,
890 OSPF_AUTH_SIMPLE_SIZE
+ 1);
891 strlcpy((char *)IF_DEF_PARAMS(ifp
)->auth_simple
,
893 sizeof(IF_DEF_PARAMS(ifp
)->auth_simple
));
894 } else if (vl_config
->md5_key
) {
895 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
896 vl_config
->crypto_key_id
)
898 vty_out(vty
, "OSPF: Key %d already exists\n",
899 vl_config
->crypto_key_id
);
902 ck
= ospf_crypt_key_new();
903 ck
->key_id
= vl_config
->crypto_key_id
;
904 memset(ck
->auth_key
, 0, OSPF_AUTH_MD5_SIZE
+ 1);
905 strlcpy((char *)ck
->auth_key
, vl_config
->md5_key
,
906 sizeof(ck
->auth_key
));
908 ospf_crypt_key_add(IF_DEF_PARAMS(ifp
)->auth_crypt
, ck
);
909 } else if (vl_config
->crypto_key_id
!= 0) {
912 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
913 vl_config
->crypto_key_id
)
915 vty_out(vty
, "OSPF: Key %d does not exist\n",
916 vl_config
->crypto_key_id
);
917 return CMD_WARNING_CONFIG_FAILED
;
920 ospf_crypt_key_delete(IF_DEF_PARAMS(ifp
)->auth_crypt
,
921 vl_config
->crypto_key_id
);
927 static int ospf_vl_set_timers(struct ospf_vl_data
*vl_data
,
928 struct ospf_vl_config_data
*vl_config
)
930 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
931 /* Virtual Link data initialised to defaults, so only set
933 if (vl_config
->hello_interval
) {
934 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_hello
);
935 IF_DEF_PARAMS(ifp
)->v_hello
= vl_config
->hello_interval
;
938 if (vl_config
->dead_interval
) {
939 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_wait
);
940 IF_DEF_PARAMS(ifp
)->v_wait
= vl_config
->dead_interval
;
943 if (vl_config
->retransmit_interval
) {
944 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), retransmit_interval
);
945 IF_DEF_PARAMS(ifp
)->retransmit_interval
=
946 vl_config
->retransmit_interval
;
949 if (vl_config
->transmit_delay
) {
950 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), transmit_delay
);
951 IF_DEF_PARAMS(ifp
)->transmit_delay
= vl_config
->transmit_delay
;
958 /* The business end of all of the above */
959 static int ospf_vl_set(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
961 struct ospf_vl_data
*vl_data
;
964 vl_data
= ospf_find_vl_data(ospf
, vl_config
);
966 return CMD_WARNING_CONFIG_FAILED
;
968 /* Process this one first as it can have a fatal result, which can
969 only logically occur if the virtual link exists already
970 Thus a command error does not result in a change to the
971 running configuration such as unexpectedly altered timer
973 ret
= ospf_vl_set_security(vl_data
, vl_config
);
974 if (ret
!= CMD_SUCCESS
)
977 /* Set any time based parameters, these area already range checked */
979 ret
= ospf_vl_set_timers(vl_data
, vl_config
);
980 if (ret
!= CMD_SUCCESS
)
986 /* This stuff exists to make specifying all the alias commands A LOT simpler
988 #define VLINK_HELPSTR_IPADDR \
989 "OSPF area parameters\n" \
990 "OSPF area ID in IP address format\n" \
991 "OSPF area ID as a decimal value\n" \
992 "Configure a virtual link\n" \
993 "Router ID of the remote ABR\n"
995 #define VLINK_HELPSTR_AUTHTYPE_SIMPLE \
996 "Enable authentication on this virtual link\n" \
999 #define VLINK_HELPSTR_AUTHTYPE_ALL \
1000 VLINK_HELPSTR_AUTHTYPE_SIMPLE \
1001 "Use null authentication\n" \
1002 "Use message-digest authentication\n"
1004 #define VLINK_HELPSTR_TIME_PARAM \
1005 "Time between HELLO packets\n" \
1007 "Time between retransmitting lost link state advertisements\n" \
1009 "Link state transmit delay\n" \
1011 "Interval time after which a neighbor is declared down\n" \
1014 #define VLINK_HELPSTR_AUTH_SIMPLE \
1015 "Authentication password (key)\n" \
1016 "The OSPF password (key)\n"
1018 #define VLINK_HELPSTR_AUTH_MD5 \
1019 "Message digest authentication password (key)\n" \
1021 "Use MD5 algorithm\n" \
1022 "The OSPF password (key)\n"
1024 DEFUN (ospf_area_vlink
,
1025 ospf_area_vlink_cmd
,
1026 "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>]",
1027 VLINK_HELPSTR_IPADDR
1028 "Enable authentication on this virtual link\n"
1029 "Use message-digest authentication\n"
1030 "Use null authentication\n"
1031 VLINK_HELPSTR_AUTH_MD5
1032 VLINK_HELPSTR_AUTH_SIMPLE
)
1034 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1035 int idx_ipv4_number
= 1;
1037 struct ospf_vl_config_data vl_config
;
1038 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1039 char md5_key
[OSPF_AUTH_MD5_SIZE
+ 1];
1043 ospf_vl_config_data_init(&vl_config
, vty
);
1045 /* Read off first 2 parameters and check them */
1046 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1047 &vl_config
.area_id_fmt
);
1049 vty_out(vty
, "OSPF area ID is invalid\n");
1050 return CMD_WARNING_CONFIG_FAILED
;
1053 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1055 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1056 return CMD_WARNING_CONFIG_FAILED
;
1060 /* Thats all folks! - BUGS B. strikes again!!!*/
1062 return ospf_vl_set(ospf
, &vl_config
);
1065 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1066 /* authentication - this option can only occur
1067 at start of command line */
1068 vl_config
.auth_type
= OSPF_AUTH_SIMPLE
;
1071 if (argv_find(argv
, argc
, "message-digest", &idx
)) {
1072 /* authentication message-digest */
1073 vl_config
.auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
1074 } else if (argv_find(argv
, argc
, "null", &idx
)) {
1075 /* "authentication null" */
1076 vl_config
.auth_type
= OSPF_AUTH_NULL
;
1079 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1080 vl_config
.md5_key
= NULL
;
1081 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1082 if (vl_config
.crypto_key_id
< 0)
1083 return CMD_WARNING_CONFIG_FAILED
;
1085 strlcpy(md5_key
, argv
[idx
+ 3]->arg
, sizeof(md5_key
));
1086 vl_config
.md5_key
= md5_key
;
1089 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1090 strlcpy(auth_key
, argv
[idx
+ 1]->arg
, sizeof(auth_key
));
1091 vl_config
.auth_key
= auth_key
;
1094 /* Action configuration */
1096 return ospf_vl_set(ospf
, &vl_config
);
1099 DEFUN (no_ospf_area_vlink
,
1100 no_ospf_area_vlink_cmd
,
1101 "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>]",
1103 VLINK_HELPSTR_IPADDR
1104 "Enable authentication on this virtual link\n"
1105 "Use message-digest authentication\n"
1106 "Use null authentication\n"
1107 VLINK_HELPSTR_AUTH_MD5
1108 VLINK_HELPSTR_AUTH_SIMPLE
)
1110 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1111 int idx_ipv4_number
= 2;
1113 struct ospf_area
*area
;
1114 struct ospf_vl_config_data vl_config
;
1115 struct ospf_vl_data
*vl_data
= NULL
;
1116 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1120 ospf_vl_config_data_init(&vl_config
, vty
);
1122 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1125 vty_out(vty
, "OSPF area ID is invalid\n");
1126 return CMD_WARNING_CONFIG_FAILED
;
1129 area
= ospf_area_lookup_by_area_id(ospf
, vl_config
.area_id
);
1131 vty_out(vty
, "Area does not exist\n");
1132 return CMD_WARNING_CONFIG_FAILED
;
1135 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1137 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1138 return CMD_WARNING_CONFIG_FAILED
;
1141 vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
.vl_peer
);
1143 vty_out(vty
, "Virtual link does not exist\n");
1144 return CMD_WARNING_CONFIG_FAILED
;
1148 /* Basic VLink no command */
1149 /* Thats all folks! - BUGS B. strikes again!!!*/
1150 ospf_vl_delete(ospf
, vl_data
);
1151 ospf_area_check_free(ospf
, vl_config
.area_id
);
1155 /* If we are down here, we are reseting parameters */
1156 /* Deal with other parameters */
1158 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1159 /* authentication - this option can only occur
1160 at start of command line */
1161 vl_config
.auth_type
= OSPF_AUTH_NOTSET
;
1164 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1165 vl_config
.md5_key
= NULL
;
1166 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1167 if (vl_config
.crypto_key_id
< 0)
1168 return CMD_WARNING_CONFIG_FAILED
;
1171 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1172 /* Reset authentication-key to 0 */
1173 memset(auth_key
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
1174 vl_config
.auth_key
= auth_key
;
1177 /* Action configuration */
1179 return ospf_vl_set(ospf
, &vl_config
);
1182 DEFUN (ospf_area_vlink_intervals
,
1183 ospf_area_vlink_intervals_cmd
,
1184 "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)}",
1185 VLINK_HELPSTR_IPADDR
1186 VLINK_HELPSTR_TIME_PARAM
)
1188 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1189 struct ospf_vl_config_data vl_config
;
1192 ospf_vl_config_data_init(&vl_config
, vty
);
1194 char *area_id
= argv
[1]->arg
;
1195 char *router_id
= argv
[3]->arg
;
1197 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1199 vty_out(vty
, "OSPF area ID is invalid\n");
1200 return CMD_WARNING_CONFIG_FAILED
;
1203 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1205 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1206 return CMD_WARNING_CONFIG_FAILED
;
1209 for (int idx
= 4; idx
< argc
; idx
++) {
1210 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1211 vl_config
.hello_interval
=
1212 strtol(argv
[++idx
]->arg
, NULL
, 10);
1213 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1214 vl_config
.retransmit_interval
=
1215 strtol(argv
[++idx
]->arg
, NULL
, 10);
1216 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1217 vl_config
.transmit_delay
=
1218 strtol(argv
[++idx
]->arg
, NULL
, 10);
1219 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1220 vl_config
.dead_interval
=
1221 strtol(argv
[++idx
]->arg
, NULL
, 10);
1224 /* Action configuration */
1225 return ospf_vl_set(ospf
, &vl_config
);
1228 DEFUN (no_ospf_area_vlink_intervals
,
1229 no_ospf_area_vlink_intervals_cmd
,
1230 "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)}",
1232 VLINK_HELPSTR_IPADDR
1233 VLINK_HELPSTR_TIME_PARAM
)
1235 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1236 struct ospf_vl_config_data vl_config
;
1239 ospf_vl_config_data_init(&vl_config
, vty
);
1241 char *area_id
= argv
[2]->arg
;
1242 char *router_id
= argv
[4]->arg
;
1244 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1246 vty_out(vty
, "OSPF area ID is invalid\n");
1247 return CMD_WARNING_CONFIG_FAILED
;
1250 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1252 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1253 return CMD_WARNING_CONFIG_FAILED
;
1256 for (int idx
= 5; idx
< argc
; idx
++) {
1257 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1258 vl_config
.hello_interval
= OSPF_HELLO_INTERVAL_DEFAULT
;
1259 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1260 vl_config
.retransmit_interval
=
1261 OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
1262 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1263 vl_config
.transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
1264 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1265 vl_config
.dead_interval
=
1266 OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
1269 /* Action configuration */
1270 return ospf_vl_set(ospf
, &vl_config
);
1273 DEFUN (ospf_area_shortcut
,
1274 ospf_area_shortcut_cmd
,
1275 "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>",
1276 "OSPF area parameters\n"
1277 "OSPF area ID in IP address format\n"
1278 "OSPF area ID as a decimal value\n"
1279 "Configure the area's shortcutting mode\n"
1280 "Set default shortcutting behavior\n"
1281 "Enable shortcutting through the area\n"
1282 "Disable shortcutting through the area\n")
1284 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1285 int idx_ipv4_number
= 1;
1286 int idx_enable_disable
= 3;
1287 struct ospf_area
*area
;
1288 struct in_addr area_id
;
1292 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1293 argv
[idx_ipv4_number
]->arg
);
1295 area
= ospf_area_get(ospf
, area_id
);
1296 ospf_area_display_format_set(ospf
, area
, format
);
1298 if (strncmp(argv
[idx_enable_disable
]->arg
, "de", 2) == 0)
1299 mode
= OSPF_SHORTCUT_DEFAULT
;
1300 else if (strncmp(argv
[idx_enable_disable
]->arg
, "di", 2) == 0)
1301 mode
= OSPF_SHORTCUT_DISABLE
;
1302 else if (strncmp(argv
[idx_enable_disable
]->arg
, "e", 1) == 0)
1303 mode
= OSPF_SHORTCUT_ENABLE
;
1305 return CMD_WARNING_CONFIG_FAILED
;
1307 ospf_area_shortcut_set(ospf
, area
, mode
);
1309 if (ospf
->abr_type
!= OSPF_ABR_SHORTCUT
)
1311 "Shortcut area setting will take effect only when the router is configured as Shortcut ABR\n");
1316 DEFUN (no_ospf_area_shortcut
,
1317 no_ospf_area_shortcut_cmd
,
1318 "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>",
1320 "OSPF area parameters\n"
1321 "OSPF area ID in IP address format\n"
1322 "OSPF area ID as a decimal value\n"
1323 "Deconfigure the area's shortcutting mode\n"
1324 "Deconfigure enabled shortcutting through the area\n"
1325 "Deconfigure disabled shortcutting through the area\n")
1327 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1328 int idx_ipv4_number
= 2;
1329 struct ospf_area
*area
;
1330 struct in_addr area_id
;
1333 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1334 argv
[idx_ipv4_number
]->arg
);
1336 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1340 ospf_area_shortcut_unset(ospf
, area
);
1346 DEFUN (ospf_area_stub
,
1348 "area <A.B.C.D|(0-4294967295)> stub",
1349 "OSPF area parameters\n"
1350 "OSPF area ID in IP address format\n"
1351 "OSPF area ID as a decimal value\n"
1352 "Configure OSPF area as stub\n")
1354 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1355 int idx_ipv4_number
= 1;
1356 struct in_addr area_id
;
1359 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1360 argv
[idx_ipv4_number
]->arg
);
1362 ret
= ospf_area_stub_set(ospf
, area_id
);
1363 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1367 "First deconfigure all virtual link through this area\n");
1368 return CMD_WARNING_CONFIG_FAILED
;
1371 /* Flush the external LSAs from the specified area */
1372 ospf_flush_lsa_from_area(ospf
, area_id
, OSPF_AS_EXTERNAL_LSA
);
1373 ospf_area_no_summary_unset(ospf
, area_id
);
1378 DEFUN (ospf_area_stub_no_summary
,
1379 ospf_area_stub_no_summary_cmd
,
1380 "area <A.B.C.D|(0-4294967295)> stub no-summary",
1381 "OSPF stub parameters\n"
1382 "OSPF area ID in IP address format\n"
1383 "OSPF area ID as a decimal value\n"
1384 "Configure OSPF area as stub\n"
1385 "Do not inject inter-area routes into stub\n")
1387 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1388 int idx_ipv4_number
= 1;
1389 struct in_addr area_id
;
1392 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1393 argv
[idx_ipv4_number
]->arg
);
1395 ret
= ospf_area_stub_set(ospf
, area_id
);
1396 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1400 "%% Area cannot be stub as it contains a virtual link\n");
1401 return CMD_WARNING_CONFIG_FAILED
;
1404 ospf_area_no_summary_set(ospf
, area_id
);
1409 DEFUN (no_ospf_area_stub
,
1410 no_ospf_area_stub_cmd
,
1411 "no area <A.B.C.D|(0-4294967295)> stub",
1413 "OSPF area parameters\n"
1414 "OSPF area ID in IP address format\n"
1415 "OSPF area ID as a decimal value\n"
1416 "Configure OSPF area as stub\n")
1418 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1419 int idx_ipv4_number
= 2;
1420 struct in_addr area_id
;
1423 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1424 argv
[idx_ipv4_number
]->arg
);
1426 ospf_area_stub_unset(ospf
, area_id
);
1427 ospf_area_no_summary_unset(ospf
, area_id
);
1432 DEFUN (no_ospf_area_stub_no_summary
,
1433 no_ospf_area_stub_no_summary_cmd
,
1434 "no area <A.B.C.D|(0-4294967295)> stub no-summary",
1436 "OSPF area parameters\n"
1437 "OSPF area ID in IP address format\n"
1438 "OSPF area ID as a decimal value\n"
1439 "Configure OSPF area as stub\n"
1440 "Do not inject inter-area routes into area\n")
1442 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1443 int idx_ipv4_number
= 2;
1444 struct in_addr area_id
;
1447 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1448 argv
[idx_ipv4_number
]->arg
);
1449 ospf_area_no_summary_unset(ospf
, area_id
);
1454 static int ospf_area_nssa_cmd_handler(struct vty
*vty
, int argc
,
1455 struct cmd_token
**argv
, int cfg_nosum
,
1458 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1459 struct in_addr area_id
;
1462 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
, argv
[1]->arg
);
1464 ret
= ospf_area_nssa_set(ospf
, area_id
);
1465 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1469 "%% Area cannot be nssa as it contains a virtual link\n");
1470 return CMD_WARNING_CONFIG_FAILED
;
1474 if (strncmp(argv
[3]->text
, "translate-c", 11) == 0)
1475 ospf_area_nssa_translator_role_set(
1476 ospf
, area_id
, OSPF_NSSA_ROLE_CANDIDATE
);
1477 else if (strncmp(argv
[3]->text
, "translate-n", 11) == 0)
1478 ospf_area_nssa_translator_role_set(
1479 ospf
, area_id
, OSPF_NSSA_ROLE_NEVER
);
1480 else if (strncmp(argv
[3]->text
, "translate-a", 11) == 0)
1481 ospf_area_nssa_translator_role_set(
1482 ospf
, area_id
, OSPF_NSSA_ROLE_ALWAYS
);
1484 ospf_area_nssa_translator_role_set(ospf
, area_id
,
1485 OSPF_NSSA_ROLE_CANDIDATE
);
1490 ospf_area_no_summary_set(ospf
, area_id
);
1492 ospf_area_no_summary_unset(ospf
, area_id
);
1495 /* Flush the external LSA for the specified area */
1496 ospf_flush_lsa_from_area(ospf
, area_id
, OSPF_AS_EXTERNAL_LSA
);
1497 ospf_schedule_abr_task(ospf
);
1498 ospf_schedule_asbr_nssa_redist_update(ospf
);
1504 DEFUN (ospf_area_nssa_translate
,
1505 ospf_area_nssa_translate_cmd
,
1506 "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always>",
1507 "OSPF area parameters\n"
1508 "OSPF area ID in IP address format\n"
1509 "OSPF area ID as a decimal value\n"
1510 "Configure OSPF area as nssa\n"
1511 "Configure NSSA-ABR for translate election (default)\n"
1512 "Configure NSSA-ABR to never translate\n"
1513 "Configure NSSA-ABR to always translate\n")
1515 return ospf_area_nssa_cmd_handler(vty
, argc
, argv
, 0, 0);
1518 DEFUN (ospf_area_nssa
,
1520 "area <A.B.C.D|(0-4294967295)> nssa",
1521 "OSPF area parameters\n"
1522 "OSPF area ID in IP address format\n"
1523 "OSPF area ID as a decimal value\n"
1524 "Configure OSPF area as nssa\n")
1526 return ospf_area_nssa_cmd_handler(vty
, argc
, argv
, 0, 0);
1529 DEFUN(ospf_area_nssa_suppress_fa
, ospf_area_nssa_suppress_fa_cmd
,
1530 "area <A.B.C.D|(0-4294967295)> nssa suppress-fa",
1531 "OSPF area parameters\n"
1532 "OSPF area ID in IP address format\n"
1533 "OSPF area ID as a decimal value\n"
1534 "Configure OSPF area as nssa\n"
1535 "Suppress forwarding address\n")
1537 int idx_ipv4_number
= 1;
1538 struct in_addr area_id
;
1541 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1542 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1543 argv
[idx_ipv4_number
]->arg
);
1545 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1547 ospf_area_nssa_suppress_fa_set(ospf
, area_id
);
1549 ospf_schedule_abr_task(ospf
);
1554 DEFUN(no_ospf_area_nssa_suppress_fa
, no_ospf_area_nssa_suppress_fa_cmd
,
1555 "no area <A.B.C.D|(0-4294967295)> nssa suppress-fa",
1557 "OSPF area parameters\n"
1558 "OSPF area ID in IP address format\n"
1559 "OSPF area ID as a decimal value\n"
1560 "Configure OSPF area as nssa\n"
1561 "Suppress forwarding address\n")
1563 int idx_ipv4_number
= 2;
1564 struct in_addr area_id
;
1567 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1569 VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id
, format
,
1570 argv
[idx_ipv4_number
]->arg
);
1572 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1574 ospf_area_nssa_suppress_fa_unset(ospf
, area_id
);
1576 ospf_schedule_abr_task(ospf
);
1581 DEFUN (ospf_area_nssa_no_summary
,
1582 ospf_area_nssa_no_summary_cmd
,
1583 "area <A.B.C.D|(0-4294967295)> nssa no-summary",
1584 "OSPF area parameters\n"
1585 "OSPF area ID in IP address format\n"
1586 "OSPF area ID as a decimal value\n"
1587 "Configure OSPF area as nssa\n"
1588 "Do not inject inter-area routes into nssa\n")
1590 int idx_ipv4_number
= 1;
1591 struct in_addr area_id
;
1594 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1595 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1596 argv
[idx_ipv4_number
]->arg
);
1598 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1600 ospf_area_nssa_no_summary_set(ospf
, area_id
);
1602 ospf_schedule_abr_task(ospf
);
1607 DEFUN (no_ospf_area_nssa_no_summary
,
1608 no_ospf_area_nssa_no_summary_cmd
,
1609 "no area <A.B.C.D|(0-4294967295)> nssa no-summary",
1611 "OSPF area parameters\n"
1612 "OSPF area ID in IP address format\n"
1613 "OSPF area ID as a decimal value\n"
1614 "Configure OSPF area as nssa\n"
1615 "Do not inject inter-area routes into nssa\n")
1617 int idx_ipv4_number
= 2;
1618 struct in_addr area_id
;
1621 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1623 VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id
, format
,
1624 argv
[idx_ipv4_number
]->arg
);
1626 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1628 ospf_area_no_summary_unset(ospf
, area_id
);
1630 ospf_schedule_abr_task(ospf
);
1635 DEFUN (no_ospf_area_nssa
,
1636 no_ospf_area_nssa_cmd
,
1637 "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always>]",
1639 "OSPF area parameters\n"
1640 "OSPF area ID in IP address format\n"
1641 "OSPF area ID as a decimal value\n"
1642 "Configure OSPF area as nssa\n"
1643 "Configure NSSA-ABR for translate election (default)\n"
1644 "Configure NSSA-ABR to never translate\n"
1645 "Configure NSSA-ABR to always translate\n")
1647 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1648 int idx_ipv4_number
= 2;
1649 struct in_addr area_id
;
1652 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1653 argv
[idx_ipv4_number
]->arg
);
1655 /* Flush the NSSA LSA for the specified area */
1656 ospf_flush_lsa_from_area(ospf
, area_id
, OSPF_AS_NSSA_LSA
);
1657 ospf_area_nssa_unset(ospf
, area_id
, argc
);
1659 ospf_schedule_abr_task(ospf
);
1665 DEFUN (ospf_area_default_cost
,
1666 ospf_area_default_cost_cmd
,
1667 "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1668 "OSPF area parameters\n"
1669 "OSPF area ID in IP address format\n"
1670 "OSPF area ID as a decimal value\n"
1671 "Set the summary-default cost of a NSSA or stub area\n"
1672 "Stub's advertised default summary cost\n")
1674 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1675 int idx_ipv4_number
= 1;
1677 struct ospf_area
*area
;
1678 struct in_addr area_id
;
1681 struct prefix_ipv4 p
;
1683 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1684 argv
[idx_ipv4_number
]->arg
);
1685 cost
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1687 area
= ospf_area_get(ospf
, area_id
);
1688 ospf_area_display_format_set(ospf
, area
, format
);
1690 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1691 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1692 return CMD_WARNING_CONFIG_FAILED
;
1695 area
->default_cost
= cost
;
1698 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1700 if (IS_DEBUG_OSPF_EVENT
)
1702 "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4",
1704 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1709 DEFUN (no_ospf_area_default_cost
,
1710 no_ospf_area_default_cost_cmd
,
1711 "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1713 "OSPF area parameters\n"
1714 "OSPF area ID in IP address format\n"
1715 "OSPF area ID as a decimal value\n"
1716 "Set the summary-default cost of a NSSA or stub area\n"
1717 "Stub's advertised default summary cost\n")
1719 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1720 int idx_ipv4_number
= 2;
1721 struct ospf_area
*area
;
1722 struct in_addr area_id
;
1724 struct prefix_ipv4 p
;
1726 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1727 argv
[idx_ipv4_number
]->arg
);
1729 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1733 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1734 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1735 return CMD_WARNING_CONFIG_FAILED
;
1738 area
->default_cost
= 1;
1741 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1743 if (IS_DEBUG_OSPF_EVENT
)
1745 "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4",
1747 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1750 ospf_area_check_free(ospf
, area_id
);
1755 DEFUN (ospf_area_export_list
,
1756 ospf_area_export_list_cmd
,
1757 "area <A.B.C.D|(0-4294967295)> export-list ACCESSLIST4_NAME",
1758 "OSPF area parameters\n"
1759 "OSPF area ID in IP address format\n"
1760 "OSPF area ID as a decimal value\n"
1761 "Set the filter for networks announced to other areas\n"
1762 "Name of the access-list\n")
1764 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1765 int idx_ipv4_number
= 1;
1766 struct ospf_area
*area
;
1767 struct in_addr area_id
;
1770 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1772 area
= ospf_area_get(ospf
, area_id
);
1773 ospf_area_display_format_set(ospf
, area
, format
);
1774 ospf_area_export_list_set(ospf
, area
, argv
[3]->arg
);
1779 DEFUN (no_ospf_area_export_list
,
1780 no_ospf_area_export_list_cmd
,
1781 "no area <A.B.C.D|(0-4294967295)> export-list ACCESSLIST4_NAME",
1783 "OSPF area parameters\n"
1784 "OSPF area ID in IP address format\n"
1785 "OSPF area ID as a decimal value\n"
1786 "Unset the filter for networks announced to other areas\n"
1787 "Name of the access-list\n")
1789 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1790 int idx_ipv4_number
= 2;
1791 struct ospf_area
*area
;
1792 struct in_addr area_id
;
1795 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1797 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1801 ospf_area_export_list_unset(ospf
, area
);
1807 DEFUN (ospf_area_import_list
,
1808 ospf_area_import_list_cmd
,
1809 "area <A.B.C.D|(0-4294967295)> import-list ACCESSLIST4_NAME",
1810 "OSPF area parameters\n"
1811 "OSPF area ID in IP address format\n"
1812 "OSPF area ID as a decimal value\n"
1813 "Set the filter for networks from other areas announced to the specified one\n"
1814 "Name of the access-list\n")
1816 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1817 int idx_ipv4_number
= 1;
1818 struct ospf_area
*area
;
1819 struct in_addr area_id
;
1822 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1824 area
= ospf_area_get(ospf
, area_id
);
1825 ospf_area_display_format_set(ospf
, area
, format
);
1826 ospf_area_import_list_set(ospf
, area
, argv
[3]->arg
);
1831 DEFUN (no_ospf_area_import_list
,
1832 no_ospf_area_import_list_cmd
,
1833 "no area <A.B.C.D|(0-4294967295)> import-list ACCESSLIST4_NAME",
1835 "OSPF area parameters\n"
1836 "OSPF area ID in IP address format\n"
1837 "OSPF area ID as a decimal value\n"
1838 "Unset the filter for networks announced to other areas\n"
1839 "Name of the access-list\n")
1841 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1842 int idx_ipv4_number
= 2;
1843 struct ospf_area
*area
;
1844 struct in_addr area_id
;
1847 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1849 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1853 ospf_area_import_list_unset(ospf
, area
);
1858 DEFUN (ospf_area_filter_list
,
1859 ospf_area_filter_list_cmd
,
1860 "area <A.B.C.D|(0-4294967295)> filter-list prefix PREFIXLIST_NAME <in|out>",
1861 "OSPF area parameters\n"
1862 "OSPF area ID in IP address format\n"
1863 "OSPF area ID as a decimal value\n"
1864 "Filter networks between OSPF areas\n"
1865 "Filter prefixes between OSPF areas\n"
1866 "Name of an IP prefix-list\n"
1867 "Filter networks sent to this area\n"
1868 "Filter networks sent from this area\n")
1870 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1871 int idx_ipv4_number
= 1;
1874 struct ospf_area
*area
;
1875 struct in_addr area_id
;
1876 struct prefix_list
*plist
;
1879 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1881 area
= ospf_area_get(ospf
, area_id
);
1882 ospf_area_display_format_set(ospf
, area
, format
);
1883 plist
= prefix_list_lookup(AFI_IP
, argv
[idx_word
]->arg
);
1884 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1885 PREFIX_LIST_IN(area
) = plist
;
1886 if (PREFIX_NAME_IN(area
))
1887 free(PREFIX_NAME_IN(area
));
1889 PREFIX_NAME_IN(area
) = strdup(argv
[idx_word
]->arg
);
1890 ospf_schedule_abr_task(ospf
);
1892 PREFIX_LIST_OUT(area
) = plist
;
1893 if (PREFIX_NAME_OUT(area
))
1894 free(PREFIX_NAME_OUT(area
));
1896 PREFIX_NAME_OUT(area
) = strdup(argv
[idx_word
]->arg
);
1897 ospf_schedule_abr_task(ospf
);
1903 DEFUN (no_ospf_area_filter_list
,
1904 no_ospf_area_filter_list_cmd
,
1905 "no area <A.B.C.D|(0-4294967295)> filter-list prefix PREFIXLIST_NAME <in|out>",
1907 "OSPF area parameters\n"
1908 "OSPF area ID in IP address format\n"
1909 "OSPF area ID as a decimal value\n"
1910 "Filter networks between OSPF areas\n"
1911 "Filter prefixes between OSPF areas\n"
1912 "Name of an IP prefix-list\n"
1913 "Filter networks sent to this area\n"
1914 "Filter networks sent from this area\n")
1916 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1917 int idx_ipv4_number
= 2;
1920 struct ospf_area
*area
;
1921 struct in_addr area_id
;
1924 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1926 if ((area
= ospf_area_lookup_by_area_id(ospf
, area_id
)) == NULL
)
1929 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1930 if (PREFIX_NAME_IN(area
))
1931 if (strcmp(PREFIX_NAME_IN(area
), argv
[idx_word
]->arg
)
1935 PREFIX_LIST_IN(area
) = NULL
;
1936 if (PREFIX_NAME_IN(area
))
1937 free(PREFIX_NAME_IN(area
));
1939 PREFIX_NAME_IN(area
) = NULL
;
1941 ospf_schedule_abr_task(ospf
);
1943 if (PREFIX_NAME_OUT(area
))
1944 if (strcmp(PREFIX_NAME_OUT(area
), argv
[idx_word
]->arg
)
1948 PREFIX_LIST_OUT(area
) = NULL
;
1949 if (PREFIX_NAME_OUT(area
))
1950 free(PREFIX_NAME_OUT(area
));
1952 PREFIX_NAME_OUT(area
) = NULL
;
1954 ospf_schedule_abr_task(ospf
);
1961 DEFUN (ospf_area_authentication_message_digest
,
1962 ospf_area_authentication_message_digest_cmd
,
1963 "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest",
1965 "OSPF area parameters\n"
1966 "OSPF area ID in IP address format\n"
1967 "OSPF area ID as a decimal value\n"
1968 "Enable authentication\n"
1969 "Use message-digest authentication\n")
1971 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1973 struct ospf_area
*area
;
1974 struct in_addr area_id
;
1977 argv_find(argv
, argc
, "area", &idx
);
1978 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx
+ 1]->arg
);
1980 area
= ospf_area_get(ospf
, area_id
);
1981 ospf_area_display_format_set(ospf
, area
, format
);
1982 area
->auth_type
= strmatch(argv
[0]->text
, "no")
1984 : OSPF_AUTH_CRYPTOGRAPHIC
;
1989 DEFUN (ospf_area_authentication
,
1990 ospf_area_authentication_cmd
,
1991 "area <A.B.C.D|(0-4294967295)> authentication",
1992 "OSPF area parameters\n"
1993 "OSPF area ID in IP address format\n"
1994 "OSPF area ID as a decimal value\n"
1995 "Enable authentication\n")
1997 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1998 int idx_ipv4_number
= 1;
1999 struct ospf_area
*area
;
2000 struct in_addr area_id
;
2003 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
2005 area
= ospf_area_get(ospf
, area_id
);
2006 ospf_area_display_format_set(ospf
, area
, format
);
2007 area
->auth_type
= OSPF_AUTH_SIMPLE
;
2012 DEFUN (no_ospf_area_authentication
,
2013 no_ospf_area_authentication_cmd
,
2014 "no area <A.B.C.D|(0-4294967295)> authentication",
2016 "OSPF area parameters\n"
2017 "OSPF area ID in IP address format\n"
2018 "OSPF area ID as a decimal value\n"
2019 "Enable authentication\n")
2021 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2022 int idx_ipv4_number
= 2;
2023 struct ospf_area
*area
;
2024 struct in_addr area_id
;
2027 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
2029 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
2033 area
->auth_type
= OSPF_AUTH_NULL
;
2035 ospf_area_check_free(ospf
, area_id
);
2041 DEFUN (ospf_abr_type
,
2043 "ospf abr-type <cisco|ibm|shortcut|standard>",
2044 "OSPF specific commands\n"
2045 "Set OSPF ABR type\n"
2046 "Alternative ABR, cisco implementation\n"
2047 "Alternative ABR, IBM implementation\n"
2049 "Standard behavior (RFC2328)\n")
2051 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2053 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2055 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2056 abr_type
= OSPF_ABR_CISCO
;
2057 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2058 abr_type
= OSPF_ABR_IBM
;
2059 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2060 abr_type
= OSPF_ABR_SHORTCUT
;
2061 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2062 abr_type
= OSPF_ABR_STAND
;
2064 return CMD_WARNING_CONFIG_FAILED
;
2066 /* If ABR type value is changed, schedule ABR task. */
2067 if (ospf
->abr_type
!= abr_type
) {
2068 ospf
->abr_type
= abr_type
;
2069 ospf_schedule_abr_task(ospf
);
2075 DEFUN (no_ospf_abr_type
,
2076 no_ospf_abr_type_cmd
,
2077 "no ospf abr-type <cisco|ibm|shortcut|standard>",
2079 "OSPF specific commands\n"
2080 "Set OSPF ABR type\n"
2081 "Alternative ABR, cisco implementation\n"
2082 "Alternative ABR, IBM implementation\n"
2086 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2088 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2090 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2091 abr_type
= OSPF_ABR_CISCO
;
2092 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2093 abr_type
= OSPF_ABR_IBM
;
2094 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2095 abr_type
= OSPF_ABR_SHORTCUT
;
2096 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2097 abr_type
= OSPF_ABR_STAND
;
2099 return CMD_WARNING_CONFIG_FAILED
;
2101 /* If ABR type value is changed, schedule ABR task. */
2102 if (ospf
->abr_type
== abr_type
) {
2103 ospf
->abr_type
= OSPF_ABR_DEFAULT
;
2104 ospf_schedule_abr_task(ospf
);
2110 DEFUN (ospf_log_adjacency_changes
,
2111 ospf_log_adjacency_changes_cmd
,
2112 "log-adjacency-changes",
2113 "Log changes in adjacency state\n")
2115 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2117 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2118 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2122 DEFUN (ospf_log_adjacency_changes_detail
,
2123 ospf_log_adjacency_changes_detail_cmd
,
2124 "log-adjacency-changes detail",
2125 "Log changes in adjacency state\n"
2126 "Log all state changes\n")
2128 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2130 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2131 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2135 DEFUN (no_ospf_log_adjacency_changes
,
2136 no_ospf_log_adjacency_changes_cmd
,
2137 "no log-adjacency-changes",
2139 "Log changes in adjacency state\n")
2141 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2143 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2144 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2148 DEFUN (no_ospf_log_adjacency_changes_detail
,
2149 no_ospf_log_adjacency_changes_detail_cmd
,
2150 "no log-adjacency-changes detail",
2152 "Log changes in adjacency state\n"
2153 "Log all state changes\n")
2155 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2157 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2161 DEFUN (ospf_compatible_rfc1583
,
2162 ospf_compatible_rfc1583_cmd
,
2163 "compatible rfc1583",
2164 "OSPF compatibility list\n"
2165 "compatible with RFC 1583\n")
2167 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2169 if (!CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2170 SET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2171 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2176 DEFUN (no_ospf_compatible_rfc1583
,
2177 no_ospf_compatible_rfc1583_cmd
,
2178 "no compatible rfc1583",
2180 "OSPF compatibility list\n"
2181 "compatible with RFC 1583\n")
2183 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2185 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2186 UNSET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2187 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2192 ALIAS(ospf_compatible_rfc1583
, ospf_rfc1583_flag_cmd
,
2193 "ospf rfc1583compatibility",
2194 "OSPF specific commands\n"
2195 "Enable the RFC1583Compatibility flag\n")
2197 ALIAS(no_ospf_compatible_rfc1583
, no_ospf_rfc1583_flag_cmd
,
2198 "no ospf rfc1583compatibility", NO_STR
2199 "OSPF specific commands\n"
2200 "Disable the RFC1583Compatibility flag\n")
2202 static void ospf_table_reinstall_routes(struct ospf
*ospf
,
2203 struct route_table
*rt
)
2205 struct route_node
*rn
;
2210 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
2211 struct ospf_route
*or;
2217 if (or->type
== OSPF_DESTINATION_NETWORK
)
2218 ospf_zebra_add(ospf
, (struct prefix_ipv4
*)&rn
->p
, or);
2219 else if (or->type
== OSPF_DESTINATION_DISCARD
)
2220 ospf_zebra_add_discard(ospf
,
2221 (struct prefix_ipv4
*)&rn
->p
);
2225 static void ospf_reinstall_routes(struct ospf
*ospf
)
2227 ospf_table_reinstall_routes(ospf
, ospf
->new_table
);
2228 ospf_table_reinstall_routes(ospf
, ospf
->new_external_route
);
2231 DEFPY (ospf_send_extra_data
,
2232 ospf_send_extra_data_cmd
,
2233 "[no] ospf send-extra-data zebra",
2236 "Extra data to Zebra for display/use\n"
2239 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2241 if (no
&& CHECK_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
)) {
2242 UNSET_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
);
2243 ospf_reinstall_routes(ospf
);
2244 } else if (!CHECK_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
)) {
2245 SET_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
);
2246 ospf_reinstall_routes(ospf
);
2252 static int ospf_timers_spf_set(struct vty
*vty
, unsigned int delay
,
2253 unsigned int hold
, unsigned int max
)
2255 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2257 ospf
->spf_delay
= delay
;
2258 ospf
->spf_holdtime
= hold
;
2259 ospf
->spf_max_holdtime
= max
;
2264 DEFUN (ospf_timers_min_ls_interval
,
2265 ospf_timers_min_ls_interval_cmd
,
2266 "timers throttle lsa all (0-5000)",
2267 "Adjust routing timers\n"
2268 "Throttling adaptive timer\n"
2269 "LSA delay between transmissions\n"
2271 "Delay (msec) between sending LSAs\n")
2273 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2275 unsigned int interval
;
2278 vty_out(vty
, "Insufficient arguments\n");
2279 return CMD_WARNING_CONFIG_FAILED
;
2282 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2284 ospf
->min_ls_interval
= interval
;
2289 DEFUN (no_ospf_timers_min_ls_interval
,
2290 no_ospf_timers_min_ls_interval_cmd
,
2291 "no timers throttle lsa all [(0-5000)]",
2293 "Adjust routing timers\n"
2294 "Throttling adaptive timer\n"
2295 "LSA delay between transmissions\n"
2297 "Delay (msec) between sending LSAs\n")
2299 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2300 ospf
->min_ls_interval
= OSPF_MIN_LS_INTERVAL
;
2305 DEFUN (ospf_timers_throttle_spf
,
2306 ospf_timers_throttle_spf_cmd
,
2307 "timers throttle spf (0-600000) (0-600000) (0-600000)",
2308 "Adjust routing timers\n"
2309 "Throttling adaptive timer\n"
2311 "Delay (msec) from first change received till SPF calculation\n"
2312 "Initial hold time (msec) between consecutive SPF calculations\n"
2313 "Maximum hold time (msec)\n")
2316 int idx_number_2
= 4;
2317 int idx_number_3
= 5;
2318 unsigned int delay
, hold
, max
;
2321 vty_out(vty
, "Insufficient arguments\n");
2322 return CMD_WARNING_CONFIG_FAILED
;
2325 delay
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2326 hold
= strtoul(argv
[idx_number_2
]->arg
, NULL
, 10);
2327 max
= strtoul(argv
[idx_number_3
]->arg
, NULL
, 10);
2329 return ospf_timers_spf_set(vty
, delay
, hold
, max
);
2332 DEFUN (no_ospf_timers_throttle_spf
,
2333 no_ospf_timers_throttle_spf_cmd
,
2334 "no timers throttle spf [(0-600000)(0-600000)(0-600000)]",
2336 "Adjust routing timers\n"
2337 "Throttling adaptive timer\n"
2339 "Delay (msec) from first change received till SPF calculation\n"
2340 "Initial hold time (msec) between consecutive SPF calculations\n"
2341 "Maximum hold time (msec)\n")
2343 return ospf_timers_spf_set(vty
, OSPF_SPF_DELAY_DEFAULT
,
2344 OSPF_SPF_HOLDTIME_DEFAULT
,
2345 OSPF_SPF_MAX_HOLDTIME_DEFAULT
);
2349 DEFUN (ospf_timers_lsa_min_arrival
,
2350 ospf_timers_lsa_min_arrival_cmd
,
2351 "timers lsa min-arrival (0-600000)",
2352 "Adjust routing timers\n"
2354 "Minimum delay in receiving new version of a LSA\n"
2355 "Delay in milliseconds\n")
2357 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2358 ospf
->min_ls_arrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2362 DEFUN (no_ospf_timers_lsa_min_arrival
,
2363 no_ospf_timers_lsa_min_arrival_cmd
,
2364 "no timers lsa min-arrival [(0-600000)]",
2366 "Adjust routing timers\n"
2368 "Minimum delay in receiving new version of a LSA\n"
2369 "Delay in milliseconds\n")
2371 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2372 unsigned int minarrival
;
2375 minarrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2377 if (ospf
->min_ls_arrival
!= minarrival
2378 || minarrival
== OSPF_MIN_LS_ARRIVAL
)
2382 ospf
->min_ls_arrival
= OSPF_MIN_LS_ARRIVAL
;
2387 DEFUN (ospf_neighbor
,
2389 "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]",
2391 "Neighbor IP address\n"
2392 "Neighbor Priority\n"
2394 "Dead Neighbor Polling interval\n"
2397 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2401 struct in_addr nbr_addr
;
2402 unsigned int priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2403 unsigned int interval
= OSPF_POLL_INTERVAL_DEFAULT
;
2405 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2406 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2407 return CMD_WARNING_CONFIG_FAILED
;
2411 priority
= strtoul(argv
[idx_pri
]->arg
, NULL
, 10);
2414 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2416 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2419 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2422 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2427 DEFUN (ospf_neighbor_poll_interval
,
2428 ospf_neighbor_poll_interval_cmd
,
2429 "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2431 "Neighbor IP address\n"
2432 "Dead Neighbor Polling interval\n"
2434 "OSPF priority of non-broadcast neighbor\n"
2437 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2441 struct in_addr nbr_addr
;
2442 unsigned int priority
;
2443 unsigned int interval
;
2445 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2446 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2447 return CMD_WARNING_CONFIG_FAILED
;
2450 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2452 priority
= argc
> 4 ? strtoul(argv
[idx_pri
]->arg
, NULL
, 10)
2453 : OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2455 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2456 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2459 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2464 DEFUN (no_ospf_neighbor
,
2465 no_ospf_neighbor_cmd
,
2466 "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]",
2469 "Neighbor IP address\n"
2470 "Neighbor Priority\n"
2472 "Dead Neighbor Polling interval\n"
2475 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2477 struct in_addr nbr_addr
;
2479 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2480 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2481 return CMD_WARNING_CONFIG_FAILED
;
2484 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2489 DEFUN (no_ospf_neighbor_poll
,
2490 no_ospf_neighbor_poll_cmd
,
2491 "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2494 "Neighbor IP address\n"
2495 "Dead Neighbor Polling interval\n"
2497 "Neighbor Priority\n"
2500 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2502 struct in_addr nbr_addr
;
2504 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2505 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2506 return CMD_WARNING_CONFIG_FAILED
;
2509 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2514 DEFUN (ospf_refresh_timer
,
2515 ospf_refresh_timer_cmd
,
2516 "refresh timer (10-1800)",
2517 "Adjust refresh parameters\n"
2518 "Set refresh timer\n"
2519 "Timer value in seconds\n")
2521 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2523 unsigned int interval
;
2525 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2526 interval
= (interval
/ OSPF_LSA_REFRESHER_GRANULARITY
)
2527 * OSPF_LSA_REFRESHER_GRANULARITY
;
2529 ospf_timers_refresh_set(ospf
, interval
);
2534 DEFUN (no_ospf_refresh_timer
,
2535 no_ospf_refresh_timer_val_cmd
,
2536 "no refresh timer [(10-1800)]",
2538 "Adjust refresh parameters\n"
2539 "Unset refresh timer\n"
2540 "Timer value in seconds\n")
2542 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2544 unsigned int interval
;
2547 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2549 if (ospf
->lsa_refresh_interval
!= interval
2550 || interval
== OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
2554 ospf_timers_refresh_unset(ospf
);
2560 DEFUN (ospf_auto_cost_reference_bandwidth
,
2561 ospf_auto_cost_reference_bandwidth_cmd
,
2562 "auto-cost reference-bandwidth (1-4294967)",
2563 "Calculate OSPF interface cost according to bandwidth\n"
2564 "Use reference bandwidth method to assign OSPF cost\n"
2565 "The reference bandwidth in terms of Mbits per second\n")
2567 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2568 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2571 struct interface
*ifp
;
2573 refbw
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2574 if (refbw
< 1 || refbw
> 4294967) {
2575 vty_out(vty
, "reference-bandwidth value is invalid\n");
2576 return CMD_WARNING_CONFIG_FAILED
;
2579 /* If reference bandwidth is changed. */
2580 if ((refbw
) == ospf
->ref_bandwidth
)
2583 ospf
->ref_bandwidth
= refbw
;
2584 FOR_ALL_INTERFACES (vrf
, ifp
)
2585 ospf_if_recalculate_output_cost(ifp
);
2590 DEFUN (no_ospf_auto_cost_reference_bandwidth
,
2591 no_ospf_auto_cost_reference_bandwidth_cmd
,
2592 "no auto-cost reference-bandwidth [(1-4294967)]",
2594 "Calculate OSPF interface cost according to bandwidth\n"
2595 "Use reference bandwidth method to assign OSPF cost\n"
2596 "The reference bandwidth in terms of Mbits per second\n")
2598 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2599 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2600 struct interface
*ifp
;
2602 if (ospf
->ref_bandwidth
== OSPF_DEFAULT_REF_BANDWIDTH
)
2605 ospf
->ref_bandwidth
= OSPF_DEFAULT_REF_BANDWIDTH
;
2606 vty_out(vty
, "%% OSPF: Reference bandwidth is changed.\n");
2608 " Please ensure reference bandwidth is consistent across all routers\n");
2610 FOR_ALL_INTERFACES (vrf
, ifp
)
2611 ospf_if_recalculate_output_cost(ifp
);
2616 DEFUN (ospf_write_multiplier
,
2617 ospf_write_multiplier_cmd
,
2618 "ospf write-multiplier (1-100)",
2619 "OSPF specific commands\n"
2620 "Write multiplier\n"
2621 "Maximum number of interface serviced per write\n")
2623 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2625 uint32_t write_oi_count
;
2632 write_oi_count
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2633 if (write_oi_count
< 1 || write_oi_count
> 100) {
2634 vty_out(vty
, "write-multiplier value is invalid\n");
2635 return CMD_WARNING_CONFIG_FAILED
;
2638 ospf
->write_oi_count
= write_oi_count
;
2642 ALIAS(ospf_write_multiplier
, write_multiplier_cmd
, "write-multiplier (1-100)",
2643 "Write multiplier\n"
2644 "Maximum number of interface serviced per write\n")
2646 DEFUN (no_ospf_write_multiplier
,
2647 no_ospf_write_multiplier_cmd
,
2648 "no ospf write-multiplier (1-100)",
2650 "OSPF specific commands\n"
2651 "Write multiplier\n"
2652 "Maximum number of interface serviced per write\n")
2654 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2656 ospf
->write_oi_count
= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
;
2660 ALIAS(no_ospf_write_multiplier
, no_write_multiplier_cmd
,
2661 "no write-multiplier (1-100)", NO_STR
2662 "Write multiplier\n"
2663 "Maximum number of interface serviced per write\n")
2665 DEFUN(ospf_ti_lfa
, ospf_ti_lfa_cmd
, "fast-reroute ti-lfa [node-protection]",
2666 "Fast Reroute for MPLS and IP resilience\n"
2667 "Topology Independent LFA (Loop-Free Alternate)\n"
2668 "TI-LFA node protection (default is link protection)\n")
2670 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2672 ospf
->ti_lfa_enabled
= true;
2675 ospf
->ti_lfa_protection_type
= OSPF_TI_LFA_NODE_PROTECTION
;
2677 ospf
->ti_lfa_protection_type
= OSPF_TI_LFA_LINK_PROTECTION
;
2679 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2684 DEFUN(no_ospf_ti_lfa
, no_ospf_ti_lfa_cmd
,
2685 "no fast-reroute ti-lfa [node-protection]",
2687 "Fast Reroute for MPLS and IP resilience\n"
2688 "Topology Independent LFA (Loop-Free Alternate)\n"
2689 "TI-LFA node protection (default is link protection)\n")
2691 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2693 ospf
->ti_lfa_enabled
= false;
2695 ospf
->ti_lfa_protection_type
= OSPF_TI_LFA_UNDEFINED_PROTECTION
;
2697 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2702 static void ospf_maxpath_set(struct vty
*vty
, struct ospf
*ospf
, uint16_t paths
)
2704 if (ospf
->max_multipath
== paths
)
2707 ospf
->max_multipath
= paths
;
2709 /* Send deletion notification to zebra to delete all
2710 * ospf specific routes and reinitiat SPF to reflect
2711 * the new max multipath.
2713 ospf_restart_spf(ospf
);
2716 /* Ospf Maximum multiple paths config support */
2717 DEFUN (ospf_max_multipath
,
2718 ospf_max_multipath_cmd
,
2719 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM
),
2720 "Max no of multiple paths for ECMP support\n"
2721 "Number of paths\n")
2723 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2727 maxpaths
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2729 ospf_maxpath_set(vty
, ospf
, maxpaths
);
2733 DEFUN (no_ospf_max_multipath
,
2734 no_ospf_max_multipath_cmd
,
2737 "Max no of multiple paths for ECMP support\n")
2739 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2740 uint16_t maxpaths
= MULTIPATH_NUM
;
2742 ospf_maxpath_set(vty
, ospf
, maxpaths
);
2746 static const char *const ospf_abr_type_descr_str
[] = {
2747 "Unknown", "Standard (RFC2328)", "Alternative IBM",
2748 "Alternative Cisco", "Alternative Shortcut"
2751 static const char *const ospf_shortcut_mode_descr_str
[] = {
2752 "Default", "Enabled", "Disabled"
2755 static void show_ip_ospf_area(struct vty
*vty
, struct ospf_area
*area
,
2756 json_object
*json_areas
, bool use_json
)
2758 json_object
*json_area
= NULL
;
2759 char buf
[PREFIX_STRLEN
];
2762 json_area
= json_object_new_object();
2766 vty_out(vty
, " Area ID: %pI4", &area
->area_id
);
2768 /* Show Area type/mode. */
2769 if (OSPF_IS_AREA_BACKBONE(area
)) {
2771 json_object_boolean_true_add(json_area
, "backbone");
2773 vty_out(vty
, " (Backbone)\n");
2776 if (area
->external_routing
== OSPF_AREA_STUB
) {
2777 if (area
->no_summary
)
2778 json_object_boolean_true_add(
2779 json_area
, "stubNoSummary");
2780 if (area
->shortcut_configured
)
2781 json_object_boolean_true_add(
2782 json_area
, "stubShortcut");
2783 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
2784 if (area
->no_summary
)
2785 json_object_boolean_true_add(
2786 json_area
, "nssaNoSummary");
2787 if (area
->shortcut_configured
)
2788 json_object_boolean_true_add(
2789 json_area
, "nssaShortcut");
2792 json_object_string_add(
2793 json_area
, "shortcuttingMode",
2794 ospf_shortcut_mode_descr_str
2795 [area
->shortcut_configured
]);
2796 if (area
->shortcut_capability
)
2797 json_object_boolean_true_add(json_area
,
2800 if (area
->external_routing
== OSPF_AREA_STUB
)
2801 vty_out(vty
, " (Stub%s%s)",
2802 area
->no_summary
? ", no summary" : "",
2803 area
->shortcut_configured
? "; " : "");
2804 else if (area
->external_routing
== OSPF_AREA_NSSA
)
2805 vty_out(vty
, " (NSSA%s%s)",
2806 area
->no_summary
? ", no summary" : "",
2807 area
->shortcut_configured
? "; " : "");
2810 vty_out(vty
, " Shortcutting mode: %s",
2811 ospf_shortcut_mode_descr_str
2812 [area
->shortcut_configured
]);
2813 vty_out(vty
, ", S-bit consensus: %s\n",
2814 area
->shortcut_capability
? "ok" : "no");
2818 /* Show number of interfaces */
2820 json_object_int_add(json_area
, "areaIfTotalCounter",
2821 listcount(area
->oiflist
));
2822 json_object_int_add(json_area
, "areaIfActiveCounter",
2826 " Number of interfaces in this area: Total: %d, Active: %d\n",
2827 listcount(area
->oiflist
), area
->act_ints
);
2829 if (area
->external_routing
== OSPF_AREA_NSSA
) {
2831 json_object_boolean_true_add(json_area
, "nssa");
2832 if (!IS_OSPF_ABR(area
->ospf
))
2833 json_object_boolean_false_add(json_area
, "abr");
2834 else if (area
->NSSATranslatorState
) {
2835 json_object_boolean_true_add(json_area
, "abr");
2836 if (area
->NSSATranslatorRole
2837 == OSPF_NSSA_ROLE_CANDIDATE
)
2838 json_object_boolean_true_add(
2840 "nssaTranslatorElected");
2841 else if (area
->NSSATranslatorRole
2842 == OSPF_NSSA_ROLE_ALWAYS
)
2843 json_object_boolean_true_add(
2845 "nssaTranslatorAlways");
2847 json_object_boolean_true_add(
2849 "nssaTranslatorNever");
2851 json_object_boolean_true_add(json_area
, "abr");
2852 if (area
->NSSATranslatorRole
2853 == OSPF_NSSA_ROLE_CANDIDATE
)
2854 json_object_boolean_false_add(
2856 "nssaTranslatorElected");
2858 json_object_boolean_true_add(
2860 "nssaTranslatorNever");
2864 " It is an NSSA configuration.\n Elected NSSA/ABR performs type-7/type-5 LSA translation.\n");
2865 if (!IS_OSPF_ABR(area
->ospf
))
2867 " It is not ABR, therefore not Translator.\n");
2868 else if (area
->NSSATranslatorState
) {
2869 vty_out(vty
, " We are an ABR and ");
2870 if (area
->NSSATranslatorRole
2871 == OSPF_NSSA_ROLE_CANDIDATE
)
2873 "the NSSA Elected Translator.\n");
2874 else if (area
->NSSATranslatorRole
2875 == OSPF_NSSA_ROLE_ALWAYS
)
2877 "always an NSSA Translator.\n");
2880 "never an NSSA Translator.\n");
2882 vty_out(vty
, " We are an ABR, but ");
2883 if (area
->NSSATranslatorRole
2884 == OSPF_NSSA_ROLE_CANDIDATE
)
2886 "not the NSSA Elected Translator.\n");
2889 "never an NSSA Translator.\n");
2894 /* Stub-router state for this area */
2895 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
)) {
2896 char timebuf
[OSPF_TIME_DUMP_SIZE
];
2899 json_object_boolean_true_add(
2900 json_area
, "originStubMaxDistRouterLsa");
2901 if (CHECK_FLAG(area
->stub_router_state
,
2902 OSPF_AREA_ADMIN_STUB_ROUTED
))
2903 json_object_boolean_true_add(
2904 json_area
, "indefiniteActiveAdmin");
2905 if (area
->t_stub_router
) {
2909 &area
->t_stub_router
->u
.sands
,
2912 json_object_int_add(
2914 "activeStartupRemainderMsecs",
2919 " Originating stub / maximum-distance Router-LSA\n");
2920 if (CHECK_FLAG(area
->stub_router_state
,
2921 OSPF_AREA_ADMIN_STUB_ROUTED
))
2923 " Administratively activated (indefinitely)\n");
2924 if (area
->t_stub_router
)
2926 " Active from startup, %s remaining\n",
2927 ospf_timer_dump(area
->t_stub_router
,
2934 /* Show number of fully adjacent neighbors. */
2935 json_object_int_add(json_area
, "nbrFullAdjacentCounter",
2938 /* Show authentication type. */
2939 if (area
->auth_type
== OSPF_AUTH_NULL
)
2940 json_object_string_add(json_area
, "authentication",
2941 "authenticationNone");
2942 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2943 json_object_string_add(json_area
, "authentication",
2944 "authenticationSimplePassword");
2945 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2946 json_object_string_add(json_area
, "authentication",
2947 "authenticationMessageDigest");
2949 if (!OSPF_IS_AREA_BACKBONE(area
))
2950 json_object_int_add(json_area
,
2951 "virtualAdjacenciesPassingCounter",
2954 /* Show SPF calculation times. */
2955 json_object_int_add(json_area
, "spfExecutedCounter",
2956 area
->spf_calculation
);
2957 json_object_int_add(json_area
, "lsaNumber", area
->lsdb
->total
);
2958 json_object_int_add(
2959 json_area
, "lsaRouterNumber",
2960 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
));
2961 json_object_int_add(
2962 json_area
, "lsaRouterChecksum",
2963 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
2964 json_object_int_add(
2965 json_area
, "lsaNetworkNumber",
2966 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
));
2967 json_object_int_add(
2968 json_area
, "lsaNetworkChecksum",
2969 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
2970 json_object_int_add(
2971 json_area
, "lsaSummaryNumber",
2972 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
));
2973 json_object_int_add(
2974 json_area
, "lsaSummaryChecksum",
2975 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
2976 json_object_int_add(
2977 json_area
, "lsaAsbrNumber",
2978 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2979 json_object_int_add(
2980 json_area
, "lsaAsbrChecksum",
2981 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2982 json_object_int_add(
2983 json_area
, "lsaNssaNumber",
2984 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2985 json_object_int_add(
2986 json_area
, "lsaNssaChecksum",
2987 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2989 /* Show number of fully adjacent neighbors. */
2991 " Number of fully adjacent neighbors in this area: %d\n",
2994 /* Show authentication type. */
2995 vty_out(vty
, " Area has ");
2996 if (area
->auth_type
== OSPF_AUTH_NULL
)
2997 vty_out(vty
, "no authentication\n");
2998 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2999 vty_out(vty
, "simple password authentication\n");
3000 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
3001 vty_out(vty
, "message digest authentication\n");
3003 if (!OSPF_IS_AREA_BACKBONE(area
))
3005 " Number of full virtual adjacencies going through this area: %d\n",
3008 /* Show SPF calculation times. */
3009 vty_out(vty
, " SPF algorithm executed %d times\n",
3010 area
->spf_calculation
);
3012 /* Show number of LSA. */
3013 vty_out(vty
, " Number of LSA %ld\n", area
->lsdb
->total
);
3015 " Number of router LSA %ld. Checksum Sum 0x%08x\n",
3016 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
),
3017 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
3019 " Number of network LSA %ld. Checksum Sum 0x%08x\n",
3020 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
),
3021 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
3023 " Number of summary LSA %ld. Checksum Sum 0x%08x\n",
3024 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
),
3025 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
3027 " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n",
3028 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
),
3029 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
3030 vty_out(vty
, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n",
3031 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
),
3032 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
3036 json_object_int_add(
3037 json_area
, "lsaOpaqueLinkNumber",
3038 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
3039 json_object_int_add(
3040 json_area
, "lsaOpaqueLinkChecksum",
3041 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
3042 json_object_int_add(
3043 json_area
, "lsaOpaqueAreaNumber",
3044 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
3045 json_object_int_add(
3046 json_area
, "lsaOpaqueAreaChecksum",
3047 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
3050 " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n",
3051 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
),
3052 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
3054 " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n",
3055 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
),
3056 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
3060 json_object_object_add(json_areas
,
3061 inet_ntop(AF_INET
, &area
->area_id
,
3068 static int show_ip_ospf_common(struct vty
*vty
, struct ospf
*ospf
,
3069 json_object
*json
, uint8_t use_vrf
)
3071 struct listnode
*node
, *nnode
;
3072 struct ospf_area
*area
;
3073 struct timeval result
;
3074 char timebuf
[OSPF_TIME_DUMP_SIZE
];
3075 json_object
*json_vrf
= NULL
;
3076 json_object
*json_areas
= NULL
;
3080 json_vrf
= json_object_new_object();
3083 json_areas
= json_object_new_object();
3086 if (ospf
->instance
) {
3088 json_object_int_add(json
, "ospfInstance",
3091 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
3095 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3097 /* Show Router ID. */
3099 json_object_string_addf(json_vrf
, "routerId", "%pI4",
3102 vty_out(vty
, " OSPF Routing Process, Router ID: %pI4\n",
3106 /* Graceful shutdown */
3107 if (ospf
->t_deferred_shutdown
) {
3112 &ospf
->t_deferred_shutdown
->u
.sands
,
3115 json_object_int_add(json_vrf
, "deferredShutdownMsecs",
3119 " Deferred shutdown in progress, %s remaining\n",
3120 ospf_timer_dump(ospf
->t_deferred_shutdown
,
3121 timebuf
, sizeof(timebuf
)));
3125 /* Show capability. */
3127 json_object_boolean_true_add(json_vrf
, "tosRoutesOnly");
3128 json_object_boolean_true_add(json_vrf
, "rfc2328Conform");
3129 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
3130 json_object_boolean_true_add(json_vrf
,
3131 "rfc1583Compatibility");
3134 vty_out(vty
, " Supports only single TOS (TOS0) routes\n");
3135 vty_out(vty
, " This implementation conforms to RFC2328\n");
3136 vty_out(vty
, " RFC1583Compatibility flag is %s\n",
3137 CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)
3143 if (CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)) {
3144 json_object_boolean_true_add(json_vrf
, "opaqueCapable");
3147 vty_out(vty
, " OpaqueCapability flag is %s\n",
3148 CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)
3153 /* Show stub-router configuration */
3154 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
3155 || ospf
->stub_router_shutdown_time
3156 != OSPF_STUB_ROUTER_UNCONFIGURED
) {
3158 json_object_boolean_true_add(json_vrf
,
3159 "stubAdvertisement");
3160 if (ospf
->stub_router_startup_time
3161 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3162 json_object_int_add(
3163 json_vrf
, "postStartEnabledSecs",
3164 ospf
->stub_router_startup_time
);
3165 if (ospf
->stub_router_shutdown_time
3166 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3167 json_object_int_add(
3168 json_vrf
, "preShutdownEnabledSecs",
3169 ospf
->stub_router_shutdown_time
);
3172 " Stub router advertisement is configured\n");
3173 if (ospf
->stub_router_startup_time
3174 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3176 " Enabled for %us after start-up\n",
3177 ospf
->stub_router_startup_time
);
3178 if (ospf
->stub_router_shutdown_time
3179 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3181 " Enabled for %us prior to full shutdown\n",
3182 ospf
->stub_router_shutdown_time
);
3186 /* Show SPF timers. */
3188 json_object_int_add(json_vrf
, "spfScheduleDelayMsecs",
3190 json_object_int_add(json_vrf
, "holdtimeMinMsecs",
3191 ospf
->spf_holdtime
);
3192 json_object_int_add(json_vrf
, "holdtimeMaxMsecs",
3193 ospf
->spf_max_holdtime
);
3194 json_object_int_add(json_vrf
, "holdtimeMultplier",
3195 ospf
->spf_hold_multiplier
);
3198 " Initial SPF scheduling delay %d millisec(s)\n"
3199 " Minimum hold time between consecutive SPFs %d millisec(s)\n"
3200 " Maximum hold time between consecutive SPFs %d millisec(s)\n"
3201 " Hold time multiplier is currently %d\n",
3202 ospf
->spf_delay
, ospf
->spf_holdtime
,
3203 ospf
->spf_max_holdtime
, ospf
->spf_hold_multiplier
);
3207 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3208 long time_store
= 0;
3211 monotime_since(&ospf
->ts_spf
, NULL
) / 1000LL;
3212 json_object_int_add(json_vrf
, "spfLastExecutedMsecs",
3215 time_store
= (1000 * ospf
->ts_spf_duration
.tv_sec
)
3216 + (ospf
->ts_spf_duration
.tv_usec
/ 1000);
3217 json_object_int_add(json_vrf
, "spfLastDurationMsecs",
3220 json_object_boolean_true_add(json_vrf
, "spfHasNotRun");
3222 vty_out(vty
, " SPF algorithm ");
3223 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3224 monotime_since(&ospf
->ts_spf
, &result
);
3225 vty_out(vty
, "last executed %s ago\n",
3226 ospf_timeval_dump(&result
, timebuf
,
3228 vty_out(vty
, " Last SPF duration %s\n",
3229 ospf_timeval_dump(&ospf
->ts_spf_duration
,
3230 timebuf
, sizeof(timebuf
)));
3232 vty_out(vty
, "has not been run\n");
3236 if (ospf
->t_spf_calc
) {
3239 monotime_until(&ospf
->t_spf_calc
->u
.sands
, NULL
)
3241 json_object_int_add(json_vrf
, "spfTimerDueInMsecs",
3245 json_object_int_add(json_vrf
, "lsaMinIntervalMsecs",
3246 ospf
->min_ls_interval
);
3247 json_object_int_add(json_vrf
, "lsaMinArrivalMsecs",
3248 ospf
->min_ls_arrival
);
3249 /* Show write multiplier values */
3250 json_object_int_add(json_vrf
, "writeMultiplier",
3251 ospf
->write_oi_count
);
3252 /* Show refresh parameters. */
3253 json_object_int_add(json_vrf
, "refreshTimerMsecs",
3254 ospf
->lsa_refresh_interval
* 1000);
3256 /* show max multipath */
3257 json_object_int_add(json_vrf
, "maximumPaths",
3258 ospf
->max_multipath
);
3260 /* show administrative distance */
3261 json_object_int_add(json_vrf
, "preference",
3263 ? ospf
->distance_all
3264 : ZEBRA_OSPF_DISTANCE_DEFAULT
);
3266 vty_out(vty
, " SPF timer %s%s\n",
3267 (ospf
->t_spf_calc
? "due in " : "is "),
3268 ospf_timer_dump(ospf
->t_spf_calc
, timebuf
,
3271 vty_out(vty
, " LSA minimum interval %d msecs\n",
3272 ospf
->min_ls_interval
);
3273 vty_out(vty
, " LSA minimum arrival %d msecs\n",
3274 ospf
->min_ls_arrival
);
3276 /* Show write multiplier values */
3277 vty_out(vty
, " Write Multiplier set to %d \n",
3278 ospf
->write_oi_count
);
3280 /* Show refresh parameters. */
3281 vty_out(vty
, " Refresh timer %d secs\n",
3282 ospf
->lsa_refresh_interval
);
3284 /* show max multipath */
3285 vty_out(vty
, " Maximum multiple paths(ECMP) supported %d\n",
3286 ospf
->max_multipath
);
3288 /* show administrative distance */
3289 vty_out(vty
, " Administrative distance %u\n",
3290 ospf
->distance_all
? ospf
->distance_all
3291 : ZEBRA_OSPF_DISTANCE_DEFAULT
);
3294 /* Show ABR/ASBR flags. */
3295 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ABR
)) {
3297 json_object_string_add(
3298 json_vrf
, "abrType",
3299 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3302 " This router is an ABR, ABR type is: %s\n",
3303 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3305 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ASBR
)) {
3307 json_object_string_add(
3308 json_vrf
, "asbrRouter",
3309 "injectingExternalRoutingInformation");
3312 " This router is an ASBR (injecting external routing information)\n");
3315 /* Show Number of AS-external-LSAs. */
3317 json_object_int_add(
3318 json_vrf
, "lsaExternalCounter",
3319 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3320 json_object_int_add(
3321 json_vrf
, "lsaExternalChecksum",
3322 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3325 " Number of external LSA %ld. Checksum Sum 0x%08x\n",
3326 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
),
3327 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3331 json_object_int_add(
3332 json_vrf
, "lsaAsopaqueCounter",
3333 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3334 json_object_int_add(
3335 json_vrf
, "lsaAsOpaqueChecksum",
3336 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3339 " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n",
3340 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
),
3341 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3344 /* Show number of areas attached. */
3346 json_object_int_add(json_vrf
, "attachedAreaCounter",
3347 listcount(ospf
->areas
));
3349 vty_out(vty
, " Number of areas attached to this router: %d\n",
3350 listcount(ospf
->areas
));
3352 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
3353 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
)) {
3355 json_object_boolean_true_add(
3356 json_vrf
, "adjacencyChangesLoggedAll");
3359 " All adjacency changes are logged\n");
3362 json_object_boolean_true_add(
3363 json_vrf
, "adjacencyChangesLogged");
3365 vty_out(vty
, " Adjacency changes are logged\n");
3369 /* show LDP-Sync status */
3370 ospf_ldp_sync_show_info(vty
, ospf
, json_vrf
, json
? 1 : 0);
3372 /* Show each area status. */
3373 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
3374 show_ip_ospf_area(vty
, area
, json_areas
, json
? 1 : 0);
3378 json_object_object_add(json_vrf
, "areas", json_areas
);
3379 json_object_object_add(json
, ospf_get_name(ospf
),
3382 json_object_object_add(json
, "areas", json_areas
);
3390 DEFUN (show_ip_ospf
,
3392 "show ip ospf [vrf <NAME|all>] [json]",
3395 "OSPF information\n"
3401 bool uj
= use_json(argc
, argv
);
3402 struct listnode
*node
= NULL
;
3403 char *vrf_name
= NULL
;
3404 bool all_vrf
= false;
3405 int ret
= CMD_SUCCESS
;
3408 json_object
*json
= NULL
;
3409 uint8_t use_vrf
= 0;
3411 if (listcount(om
->ospf
) == 0)
3414 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
3417 json
= json_object_new_object();
3419 /* vrf input is provided could be all or specific vrf*/
3421 bool ospf_output
= false;
3426 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
3427 if (!ospf
->oi_running
)
3430 ret
= show_ip_ospf_common(vty
, ospf
, json
,
3434 vty_json(vty
, json
);
3435 else if (!ospf_output
)
3436 vty_out(vty
, "%% OSPF is not enabled\n");
3439 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
3440 if ((ospf
== NULL
) || !ospf
->oi_running
) {
3442 vty_json(vty
, json
);
3445 "%% OSPF is not enabled in vrf %s\n",
3451 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
3452 /* Display default ospf (instance 0) info */
3453 if (ospf
== NULL
|| !ospf
->oi_running
) {
3455 vty_json(vty
, json
);
3458 "%% OSPF is not enabled in vrf default\n");
3465 show_ip_ospf_common(vty
, ospf
, json
, use_vrf
);
3467 vty_out(vty
, "%s\n",
3468 json_object_to_json_string_ext(
3469 json
, JSON_C_TO_STRING_PRETTY
));
3473 json_object_free(json
);
3478 DEFUN (show_ip_ospf_instance
,
3479 show_ip_ospf_instance_cmd
,
3480 "show ip ospf (1-65535) [json]",
3483 "OSPF information\n"
3489 unsigned short instance
= 0;
3490 bool uj
= use_json(argc
, argv
);
3491 int ret
= CMD_SUCCESS
;
3492 json_object
*json
= NULL
;
3494 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
3495 if (instance
!= ospf_instance
)
3496 return CMD_NOT_MY_INSTANCE
;
3498 ospf
= ospf_lookup_instance(instance
);
3499 if (!ospf
|| !ospf
->oi_running
)
3503 json
= json_object_new_object();
3505 ret
= show_ip_ospf_common(vty
, ospf
, json
, 0);
3508 vty_json(vty
, json
);
3513 static void ospf_interface_auth_show(struct vty
*vty
, struct ospf_interface
*oi
,
3514 json_object
*json
, bool use_json
)
3518 auth_type
= OSPF_IF_PARAM(oi
, auth_type
);
3520 switch (auth_type
) {
3521 case OSPF_AUTH_NULL
:
3523 json_object_string_add(json
, "authentication",
3524 "authenticationNone");
3526 vty_out(vty
, " Authentication NULL is enabled\n");
3528 case OSPF_AUTH_SIMPLE
: {
3530 json_object_string_add(json
, "authentication",
3531 "authenticationSimplePassword");
3534 " Simple password authentication enabled\n");
3537 case OSPF_AUTH_CRYPTOGRAPHIC
: {
3538 struct crypt_key
*ckey
;
3540 if (list_isempty(OSPF_IF_PARAM(oi
, auth_crypt
)))
3543 ckey
= listgetdata(listtail(OSPF_IF_PARAM(oi
, auth_crypt
)));
3546 json_object_string_add(json
, "authentication",
3547 "authenticationMessageDigest");
3550 " Cryptographic authentication enabled\n");
3551 vty_out(vty
, " Algorithm:MD5\n");
3561 static void show_ip_ospf_interface_sub(struct vty
*vty
, struct ospf
*ospf
,
3562 struct interface
*ifp
,
3563 json_object
*json_interface_sub
,
3567 struct ospf_neighbor
*nbr
;
3568 struct route_node
*rn
;
3569 uint32_t bandwidth
= ifp
->bandwidth
? ifp
->bandwidth
: ifp
->speed
;
3571 /* Is interface up? */
3573 is_up
= if_is_operative(ifp
);
3575 json_object_boolean_true_add(json_interface_sub
,
3578 json_object_boolean_false_add(json_interface_sub
,
3581 json_object_int_add(json_interface_sub
, "ifIndex",
3583 json_object_int_add(json_interface_sub
, "mtuBytes", ifp
->mtu
);
3584 json_object_int_add(json_interface_sub
, "bandwidthMbit",
3586 json_object_string_add(json_interface_sub
, "ifFlags",
3587 if_flag_dump(ifp
->flags
));
3589 vty_out(vty
, "%s is %s\n", ifp
->name
,
3590 ((is_up
= if_is_operative(ifp
)) ? "up" : "down"));
3591 vty_out(vty
, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n",
3592 ifp
->ifindex
, ifp
->mtu
, bandwidth
,
3593 if_flag_dump(ifp
->flags
));
3596 /* Is interface OSPF enabled? */
3598 if (ospf_oi_count(ifp
) == 0) {
3599 json_object_boolean_false_add(json_interface_sub
,
3602 } else if (!is_up
) {
3603 json_object_boolean_false_add(json_interface_sub
,
3607 json_object_boolean_true_add(json_interface_sub
,
3610 if (ospf_oi_count(ifp
) == 0) {
3611 vty_out(vty
, " OSPF not enabled on this interface\n");
3613 } else if (!is_up
) {
3615 " OSPF is enabled, but not running on this interface\n");
3620 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
3621 struct ospf_interface
*oi
= rn
->info
;
3626 if (CHECK_FLAG(oi
->connected
->flags
, ZEBRA_IFA_UNNUMBERED
)) {
3628 json_object_boolean_true_add(json_interface_sub
,
3631 vty_out(vty
, " This interface is UNNUMBERED,");
3633 struct in_addr dest
;
3636 /* Show OSPF interface information. */
3638 json_object_string_addf(
3639 json_interface_sub
, "ipAddress", "%pI4",
3640 &oi
->address
->u
.prefix4
);
3641 json_object_int_add(json_interface_sub
,
3642 "ipAddressPrefixlen",
3643 oi
->address
->prefixlen
);
3645 vty_out(vty
, " Internet Address %pFX,",
3648 /* For Vlinks, showing the peer address is
3649 * probably more informative than the local
3650 * interface that is being used */
3651 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
) {
3653 dest
= oi
->vl_data
->peer_addr
;
3654 } else if (CONNECTED_PEER(oi
->connected
)
3655 && oi
->connected
->destination
) {
3657 dest
= oi
->connected
->destination
->u
.prefix4
;
3660 dest
.s_addr
= ipv4_broadcast_addr(
3661 oi
->connected
->address
->u
.prefix4
.s_addr
,
3662 oi
->connected
->address
->prefixlen
);
3666 json_object_string_add(
3668 "ospfIfType", dstr
);
3669 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3670 json_object_string_addf(
3671 json_interface_sub
, "vlinkPeer",
3674 json_object_string_addf(
3676 "localIfUsed", "%pI4", &dest
);
3678 vty_out(vty
, " %s %pI4,", dstr
,
3682 json_object_string_add(json_interface_sub
, "area",
3683 ospf_area_desc_string(oi
->area
));
3684 if (OSPF_IF_PARAM(oi
, mtu_ignore
))
3685 json_object_boolean_true_add(
3687 "mtuMismatchDetect");
3688 json_object_string_addf(json_interface_sub
, "routerId",
3689 "%pI4", &ospf
->router_id
);
3690 json_object_string_add(json_interface_sub
,
3692 ospf_network_type_str
[oi
->type
]);
3693 json_object_int_add(json_interface_sub
, "cost",
3695 json_object_int_add(
3696 json_interface_sub
, "transmitDelaySecs",
3697 OSPF_IF_PARAM(oi
, transmit_delay
));
3698 json_object_string_add(json_interface_sub
, "state",
3699 lookup_msg(ospf_ism_state_msg
,
3701 json_object_int_add(json_interface_sub
, "priority",
3704 vty_out(vty
, " Area %s\n",
3705 ospf_area_desc_string(oi
->area
));
3707 vty_out(vty
, " MTU mismatch detection: %s\n",
3708 OSPF_IF_PARAM(oi
, mtu_ignore
) ? "disabled"
3712 " Router ID %pI4, Network Type %s, Cost: %d\n",
3714 ospf_network_type_str
[oi
->type
],
3718 " Transmit Delay is %d sec, State %s, Priority %d\n",
3719 OSPF_IF_PARAM(oi
, transmit_delay
),
3720 lookup_msg(ospf_ism_state_msg
, oi
->state
, NULL
),
3724 /* Show DR information. */
3725 if (DR(oi
).s_addr
== INADDR_ANY
) {
3728 " No backup designated router on this network\n");
3730 nbr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &DR(oi
));
3733 json_object_string_addf(
3734 json_interface_sub
, "drId",
3735 "%pI4", &nbr
->router_id
);
3736 json_object_string_addf(
3737 json_interface_sub
, "drAddress",
3739 &nbr
->address
.u
.prefix4
);
3742 " Designated Router (ID) %pI4",
3745 " Interface Address %pFX\n",
3751 nbr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &BDR(oi
));
3755 " No backup designated router on this network\n");
3758 json_object_string_addf(
3759 json_interface_sub
, "bdrId",
3760 "%pI4", &nbr
->router_id
);
3761 json_object_string_addf(
3763 "bdrAddress", "%pI4",
3764 &nbr
->address
.u
.prefix4
);
3767 " Backup Designated Router (ID) %pI4,",
3769 vty_out(vty
, " Interface Address %pI4\n",
3770 &nbr
->address
.u
.prefix4
);
3775 /* Next network-LSA sequence number we'll use, if we're elected
3778 && ntohl(oi
->params
->network_lsa_seqnum
)
3779 != OSPF_INITIAL_SEQUENCE_NUMBER
) {
3781 json_object_int_add(
3783 "networkLsaSequence",
3784 ntohl(oi
->params
->network_lsa_seqnum
));
3787 " Saved Network-LSA sequence number 0x%x\n",
3788 ntohl(oi
->params
->network_lsa_seqnum
));
3792 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3793 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3794 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3795 json_object_boolean_true_add(
3797 "mcastMemberOspfAllRouters");
3798 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3799 json_object_boolean_true_add(
3801 "mcastMemberOspfDesignatedRouters");
3804 vty_out(vty
, " Multicast group memberships:");
3805 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3806 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3807 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3808 vty_out(vty
, " OSPFAllRouters");
3809 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3810 vty_out(vty
, " OSPFDesignatedRouters");
3812 vty_out(vty
, " <None>");
3817 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3818 json_object_int_add(
3819 json_interface_sub
, "timerMsecs",
3820 OSPF_IF_PARAM(oi
, v_hello
) * 1000);
3822 json_object_int_add(
3823 json_interface_sub
, "timerMsecs",
3824 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3825 json_object_int_add(json_interface_sub
,
3827 OSPF_IF_PARAM(oi
, v_wait
));
3828 json_object_int_add(json_interface_sub
,
3830 OSPF_IF_PARAM(oi
, v_wait
));
3831 json_object_int_add(
3832 json_interface_sub
, "timerRetransmitSecs",
3833 OSPF_IF_PARAM(oi
, retransmit_interval
));
3835 vty_out(vty
, " Timer intervals configured,");
3836 vty_out(vty
, " Hello ");
3837 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3838 vty_out(vty
, "%ds,",
3839 OSPF_IF_PARAM(oi
, v_hello
));
3841 vty_out(vty
, "%dms,",
3842 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3843 vty_out(vty
, " Dead %ds, Wait %ds, Retransmit %d\n",
3844 OSPF_IF_PARAM(oi
, v_wait
),
3845 OSPF_IF_PARAM(oi
, v_wait
),
3846 OSPF_IF_PARAM(oi
, retransmit_interval
));
3849 if (OSPF_IF_PASSIVE_STATUS(oi
) == OSPF_IF_ACTIVE
) {
3850 char timebuf
[OSPF_TIME_DUMP_SIZE
];
3852 long time_store
= 0;
3856 &oi
->t_hello
->u
.sands
,
3859 json_object_int_add(json_interface_sub
,
3860 "timerHelloInMsecs",
3863 vty_out(vty
, " Hello due in %s\n",
3864 ospf_timer_dump(oi
->t_hello
, timebuf
,
3866 } else /* passive-interface is set */
3869 json_object_boolean_true_add(
3871 "timerPassiveIface");
3874 " No Hellos (Passive interface)\n");
3878 json_object_int_add(json_interface_sub
, "nbrCount",
3879 ospf_nbr_count(oi
, 0));
3880 json_object_int_add(json_interface_sub
,
3882 ospf_nbr_count(oi
, NSM_Full
));
3885 " Neighbor Count is %d, Adjacent neighbor count is %d\n",
3886 ospf_nbr_count(oi
, 0),
3887 ospf_nbr_count(oi
, NSM_Full
));
3889 ospf_interface_bfd_show(vty
, ifp
, json_interface_sub
);
3891 /* OSPF Authentication information */
3892 ospf_interface_auth_show(vty
, oi
, json_interface_sub
, use_json
);
3896 static int show_ip_ospf_interface_common(struct vty
*vty
, struct ospf
*ospf
,
3897 char *intf_name
, uint8_t use_vrf
,
3898 json_object
*json
, bool use_json
)
3900 struct interface
*ifp
;
3901 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
3902 json_object
*json_vrf
= NULL
;
3903 json_object
*json_interface_sub
= NULL
, *json_interface
= NULL
;
3907 json_vrf
= json_object_new_object();
3910 json_interface
= json_object_new_object();
3913 if (ospf
->instance
) {
3915 json_object_int_add(json
, "ospfInstance",
3918 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
3921 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3923 if (intf_name
== NULL
) {
3924 /* Show All Interfaces.*/
3925 FOR_ALL_INTERFACES (vrf
, ifp
) {
3926 if (ospf_oi_count(ifp
)) {
3928 json_interface_sub
=
3929 json_object_new_object();
3931 show_ip_ospf_interface_sub(vty
, ospf
, ifp
,
3936 json_object_object_add(
3937 json_interface
, ifp
->name
,
3938 json_interface_sub
);
3943 json_object_object_add(json_vrf
, "interfaces",
3946 /* Interface name is specified. */
3947 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
3950 json_object_boolean_true_add(json_vrf
,
3953 vty_out(vty
, "No such interface name\n");
3956 json_interface_sub
= json_object_new_object();
3957 json_interface
= json_object_new_object();
3960 show_ip_ospf_interface_sub(
3961 vty
, ospf
, ifp
, json_interface_sub
, use_json
);
3964 json_object_object_add(json_interface
,
3966 json_interface_sub
);
3967 json_object_object_add(json_vrf
, "interfaces",
3975 json_object_object_add(json
, ospf_get_name(ospf
),
3984 static void show_ip_ospf_interface_traffic_sub(struct vty
*vty
,
3985 struct ospf_interface
*oi
,
3986 json_object
*json_interface_sub
,
3990 json_object_int_add(json_interface_sub
, "ifIndex",
3992 json_object_int_add(json_interface_sub
, "helloIn",
3994 json_object_int_add(json_interface_sub
, "helloOut",
3996 json_object_int_add(json_interface_sub
, "dbDescIn",
3998 json_object_int_add(json_interface_sub
, "dbDescOut",
4000 json_object_int_add(json_interface_sub
, "lsReqIn",
4002 json_object_int_add(json_interface_sub
, "lsReqOut",
4004 json_object_int_add(json_interface_sub
, "lsUpdIn",
4006 json_object_int_add(json_interface_sub
, "lsUpdOut",
4008 json_object_int_add(json_interface_sub
, "lsAckIn",
4010 json_object_int_add(json_interface_sub
, "lsAckOut",
4012 json_object_int_add(json_interface_sub
, "packetsQueued",
4013 listcount(oi
->obuf
));
4016 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u %12lu\n",
4017 oi
->ifp
->name
, oi
->hello_in
, oi
->hello_out
,
4018 oi
->db_desc_in
, oi
->db_desc_out
, oi
->ls_req_in
,
4019 oi
->ls_req_out
, oi
->ls_upd_in
, oi
->ls_upd_out
,
4020 oi
->ls_ack_in
, oi
->ls_ack_out
, listcount(oi
->obuf
));
4024 /* OSPFv2 Packet Counters */
4025 static int show_ip_ospf_interface_traffic_common(
4026 struct vty
*vty
, struct ospf
*ospf
, char *intf_name
, json_object
*json
,
4027 int display_once
, uint8_t use_vrf
, bool use_json
)
4029 struct vrf
*vrf
= NULL
;
4030 struct interface
*ifp
= NULL
;
4031 json_object
*json_vrf
= NULL
;
4032 json_object
*json_interface_sub
= NULL
;
4034 if (!use_json
&& !display_once
) {
4036 vty_out(vty
, "%-12s%-17s%-17s%-17s%-17s%-17s%-17s\n",
4037 "Interface", " HELLO", " DB-Desc", " LS-Req",
4038 " LS-Update", " LS-Ack", " Packets");
4039 vty_out(vty
, "%-10s%-18s%-18s%-17s%-17s%-17s%-17s\n", "",
4040 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
4041 " Rx/Tx", " Queued");
4043 "-------------------------------------------------------------------------------------------------------------\n");
4044 } else if (use_json
) {
4046 json_vrf
= json_object_new_object();
4051 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4053 if (intf_name
== NULL
) {
4054 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
4055 FOR_ALL_INTERFACES (vrf
, ifp
) {
4056 struct route_node
*rn
;
4057 struct ospf_interface
*oi
;
4059 if (ospf_oi_count(ifp
) == 0)
4062 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
4063 rn
= route_next(rn
)) {
4070 json_interface_sub
=
4071 json_object_new_object();
4074 show_ip_ospf_interface_traffic_sub(
4075 vty
, oi
, json_interface_sub
, use_json
);
4077 json_object_object_add(
4078 json_vrf
, ifp
->name
,
4079 json_interface_sub
);
4084 /* Interface name is specified. */
4085 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
4087 struct route_node
*rn
;
4088 struct ospf_interface
*oi
;
4090 if (ospf_oi_count(ifp
) == 0) {
4092 " OSPF not enabled on this interface %s\n",
4097 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
4098 rn
= route_next(rn
)) {
4102 json_interface_sub
=
4103 json_object_new_object();
4106 show_ip_ospf_interface_traffic_sub(
4107 vty
, oi
, json_interface_sub
, use_json
);
4109 json_object_object_add(
4110 json_vrf
, ifp
->name
,
4111 json_interface_sub
);
4119 json_object_object_add(json
, ospf_get_name(ospf
),
4127 DEFUN (show_ip_ospf_interface
,
4128 show_ip_ospf_interface_cmd
,
4129 "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]",
4132 "OSPF information\n"
4135 "Interface information\n"
4140 bool uj
= use_json(argc
, argv
);
4141 struct listnode
*node
= NULL
;
4142 char *vrf_name
= NULL
, *intf_name
= NULL
;
4143 bool all_vrf
= false;
4144 int ret
= CMD_SUCCESS
;
4146 int idx_vrf
= 0, idx_intf
= 0;
4147 uint8_t use_vrf
= 0;
4148 json_object
*json
= NULL
;
4150 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4152 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4153 intf_name
= argv
[idx_intf
]->arg
;
4156 json
= json_object_new_object();
4158 /* vrf input is provided could be all or specific vrf*/
4162 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4163 if (!ospf
->oi_running
)
4165 ret
= show_ip_ospf_interface_common(
4166 vty
, ospf
, intf_name
, use_vrf
, json
,
4171 vty_json(vty
, json
);
4173 vty_out(vty
, "%% OSPF is not enabled\n");
4177 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4178 if (ospf
== NULL
|| !ospf
->oi_running
) {
4180 vty_json(vty
, json
);
4183 "%% OSPF is not enabled in vrf %s\n",
4188 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
4192 /* Display default ospf (instance 0) info */
4193 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4194 if (ospf
== NULL
|| !ospf
->oi_running
) {
4196 vty_json(vty
, json
);
4199 "%% OSPF is not enabled in vrf default\n");
4203 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
4208 vty_json(vty
, json
);
4213 DEFUN (show_ip_ospf_instance_interface
,
4214 show_ip_ospf_instance_interface_cmd
,
4215 "show ip ospf (1-65535) interface [INTERFACE] [json]",
4218 "OSPF information\n"
4220 "Interface information\n"
4227 unsigned short instance
= 0;
4228 bool uj
= use_json(argc
, argv
);
4229 char *intf_name
= NULL
;
4230 int ret
= CMD_SUCCESS
;
4231 json_object
*json
= NULL
;
4233 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4234 if (instance
!= ospf_instance
)
4235 return CMD_NOT_MY_INSTANCE
;
4237 ospf
= ospf_lookup_instance(instance
);
4238 if (!ospf
|| !ospf
->oi_running
)
4242 json
= json_object_new_object();
4244 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4245 intf_name
= argv
[idx_intf
]->arg
;
4247 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
, 0, json
, uj
);
4250 vty_json(vty
, json
);
4255 DEFUN (show_ip_ospf_interface_traffic
,
4256 show_ip_ospf_interface_traffic_cmd
,
4257 "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]",
4260 "OSPF information\n"
4263 "Interface information\n"
4264 "Protocol Packet counters\n"
4268 struct ospf
*ospf
= NULL
;
4269 struct listnode
*node
= NULL
;
4270 char *vrf_name
= NULL
, *intf_name
= NULL
;
4271 bool all_vrf
= false;
4273 int idx_vrf
= 0, idx_intf
= 0;
4274 bool uj
= use_json(argc
, argv
);
4275 json_object
*json
= NULL
;
4276 int ret
= CMD_SUCCESS
;
4277 int display_once
= 0;
4278 uint8_t use_vrf
= 0;
4280 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4282 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4283 intf_name
= argv
[idx_intf
]->arg
;
4286 json
= json_object_new_object();
4291 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4292 if (!ospf
->oi_running
)
4295 ret
= show_ip_ospf_interface_traffic_common(
4296 vty
, ospf
, intf_name
, json
,
4297 display_once
, use_vrf
, uj
);
4302 vty_json(vty
, json
);
4306 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4307 if (ospf
== NULL
|| !ospf
->oi_running
) {
4309 json_object_free(json
);
4313 ret
= show_ip_ospf_interface_traffic_common(
4314 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4316 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4317 if (ospf
== NULL
|| !ospf
->oi_running
) {
4319 json_object_free(json
);
4323 ret
= show_ip_ospf_interface_traffic_common(
4324 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4328 vty_json(vty
, json
);
4334 static void show_ip_ospf_neighbour_header(struct vty
*vty
)
4336 vty_out(vty
, "\n%-15s %-3s %-15s %-15s %-9s %-15s %-32s %5s %5s %5s\n",
4337 "Neighbor ID", "Pri", "State", "Up Time", "Dead Time",
4338 "Address", "Interface", "RXmtL", "RqstL", "DBsmL");
4341 static void show_ip_ospf_neighbour_brief(struct vty
*vty
,
4342 struct ospf_neighbor
*nbr
,
4343 struct ospf_neighbor
*prev_nbr
,
4344 json_object
*json
, bool use_json
)
4347 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4348 json_object
*json_neighbor
= NULL
, *json_neigh_array
= NULL
;
4349 struct timeval res
= {.tv_sec
= 0, .tv_usec
= 0};
4351 char uptime
[OSPF_TIME_DUMP_SIZE
];
4353 if (nbr
->ts_last_progress
.tv_sec
|| nbr
->ts_last_progress
.tv_usec
)
4355 monotime_since(&nbr
->ts_last_progress
, &res
) / 1000LL;
4358 char neigh_str
[INET_ADDRSTRLEN
];
4360 if (prev_nbr
&& !IPV4_ADDR_SAME(&prev_nbr
->src
, &nbr
->src
)) {
4361 /* Start new neigh list */
4362 json_neigh_array
= NULL
;
4365 if (nbr
->state
== NSM_Attempt
&&
4366 nbr
->router_id
.s_addr
== INADDR_ANY
)
4367 strlcpy(neigh_str
, "neighbor", sizeof(neigh_str
));
4369 inet_ntop(AF_INET
, &nbr
->router_id
, neigh_str
,
4372 json_object_object_get_ex(json
, neigh_str
, &json_neigh_array
);
4374 if (!json_neigh_array
) {
4375 json_neigh_array
= json_object_new_array();
4376 json_object_object_add(json
, neigh_str
,
4380 json_neighbor
= json_object_new_object();
4382 ospf_nbr_ism_state_message(nbr
, msgbuf
, sizeof(msgbuf
));
4383 #if CONFDATE > 20230321
4385 "Remove show_ip_ospf_neighbor_sub() JSON keys: priority, state, deadTimeMsecs, address, retransmitCounter, requestCounter, dbSummaryCounter")
4387 json_object_int_add(json_neighbor
, "priority", nbr
->priority
);
4388 json_object_string_add(json_neighbor
, "state", msgbuf
);
4389 json_object_int_add(json_neighbor
, "nbrPriority",
4391 json_object_string_add(json_neighbor
, "nbrState", msgbuf
);
4393 json_object_string_add(
4394 json_neighbor
, "converged",
4395 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
4396 json_object_string_add(json_neighbor
, "role",
4397 lookup_msg(ospf_ism_state_msg
,
4398 ospf_nbr_ism_state(nbr
),
4400 if (nbr
->t_inactivity
) {
4403 time_store
= monotime_until(&nbr
->t_inactivity
->u
.sands
,
4406 json_object_int_add(json_neighbor
, "upTimeInMsec",
4408 json_object_int_add(json_neighbor
, "deadTimeMsecs",
4410 json_object_int_add(json_neighbor
,
4411 "routerDeadIntervalTimerDueMsec",
4413 json_object_string_add(
4414 json_neighbor
, "upTime",
4415 ospf_timeval_dump(&res
, uptime
,
4417 json_object_string_add(
4418 json_neighbor
, "deadTime",
4419 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
4422 json_object_string_add(json_neighbor
, "deadTimeMsecs",
4424 json_object_string_add(json_neighbor
,
4425 "routerDeadIntervalTimerDueMsec",
4428 json_object_string_addf(json_neighbor
, "address", "%pI4",
4430 json_object_string_addf(json_neighbor
, "ifaceAddress", "%pI4",
4432 json_object_string_add(json_neighbor
, "ifaceName",
4434 json_object_int_add(json_neighbor
, "retransmitCounter",
4435 ospf_ls_retransmit_count(nbr
));
4436 json_object_int_add(json_neighbor
,
4437 "linkStateRetransmissionListCounter",
4438 ospf_ls_retransmit_count(nbr
));
4439 json_object_int_add(json_neighbor
, "requestCounter",
4440 ospf_ls_request_count(nbr
));
4441 json_object_int_add(json_neighbor
,
4442 "linkStateRequestListCounter",
4443 ospf_ls_request_count(nbr
));
4444 json_object_int_add(json_neighbor
, "dbSummaryCounter",
4445 ospf_db_summary_count(nbr
));
4446 json_object_int_add(json_neighbor
, "databaseSummaryListCounter",
4447 ospf_db_summary_count(nbr
));
4449 json_object_array_add(json_neigh_array
, json_neighbor
);
4451 ospf_nbr_ism_state_message(nbr
, msgbuf
, sizeof(msgbuf
));
4453 if (nbr
->state
== NSM_Attempt
&&
4454 nbr
->router_id
.s_addr
== INADDR_ANY
)
4455 vty_out(vty
, "%-15s %3d %-15s ", "-", nbr
->priority
,
4458 vty_out(vty
, "%-15pI4 %3d %-15s ", &nbr
->router_id
,
4459 nbr
->priority
, msgbuf
);
4461 vty_out(vty
, "%-15s ",
4462 ospf_timeval_dump(&res
, uptime
, sizeof(uptime
)));
4464 vty_out(vty
, "%9s ",
4465 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
4467 vty_out(vty
, "%-15pI4 ", &nbr
->src
);
4468 vty_out(vty
, "%-32s %5ld %5ld %5d\n", IF_NAME(nbr
->oi
),
4469 ospf_ls_retransmit_count(nbr
),
4470 ospf_ls_request_count(nbr
), ospf_db_summary_count(nbr
));
4474 static void show_ip_ospf_neighbor_sub(struct vty
*vty
,
4475 struct ospf_interface
*oi
,
4476 json_object
*json
, bool use_json
)
4478 struct route_node
*rn
;
4479 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
4481 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
4487 /* Do not show myself. */
4488 if (nbr
== oi
->nbr_self
)
4490 /* Down state is not shown. */
4491 if (nbr
->state
== NSM_Down
)
4496 show_ip_ospf_neighbour_brief(vty
, nbr
, prev_nbr
, json
,
4501 static int show_ip_ospf_neighbor_common(struct vty
*vty
, struct ospf
*ospf
,
4502 json_object
*json
, bool use_json
,
4505 struct ospf_interface
*oi
;
4506 struct listnode
*node
;
4507 json_object
*json_vrf
= NULL
;
4508 json_object
*json_nbr_sub
= NULL
;
4512 json_vrf
= json_object_new_object();
4515 json_nbr_sub
= json_object_new_object();
4518 if (ospf
->instance
) {
4520 json_object_int_add(json
, "ospfInstance",
4523 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4526 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4528 show_ip_ospf_neighbour_header(vty
);
4530 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4531 if (ospf_interface_neighbor_count(oi
) == 0)
4533 show_ip_ospf_neighbor_sub(vty
, oi
, json_nbr_sub
, use_json
);
4537 json_object_object_add(json_vrf
, "neighbors", json_nbr_sub
);
4539 json_object_object_add(json
, ospf_get_name(ospf
),
4547 DEFUN (show_ip_ospf_neighbor
,
4548 show_ip_ospf_neighbor_cmd
,
4549 "show ip ospf [vrf <NAME|all>] neighbor [json]",
4552 "OSPF information\n"
4559 bool uj
= use_json(argc
, argv
);
4560 struct listnode
*node
= NULL
;
4561 char *vrf_name
= NULL
;
4562 bool all_vrf
= false;
4563 int ret
= CMD_SUCCESS
;
4566 uint8_t use_vrf
= 0;
4567 json_object
*json
= NULL
;
4569 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4572 json
= json_object_new_object();
4574 /* vrf input is provided could be all or specific vrf*/
4578 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4579 if (!ospf
->oi_running
)
4581 ret
= show_ip_ospf_neighbor_common(
4582 vty
, ospf
, json
, uj
, use_vrf
);
4586 vty_json(vty
, json
);
4588 vty_out(vty
, "OSPF is not enabled\n");
4593 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4594 if (ospf
== NULL
|| !ospf
->oi_running
) {
4596 vty_json(vty
, json
);
4599 "%% OSPF is not enabled in vrf %s\n",
4605 /* Display default ospf (instance 0) info */
4606 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4607 if (ospf
== NULL
|| !ospf
->oi_running
) {
4609 vty_json(vty
, json
);
4612 "%% OSPF is not enabled in vrf default\n");
4619 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
,
4623 vty_out(vty
, "%s\n",
4624 json_object_to_json_string_ext(
4625 json
, JSON_C_TO_STRING_PRETTY
));
4630 json_object_free(json
);
4636 DEFUN (show_ip_ospf_instance_neighbor
,
4637 show_ip_ospf_instance_neighbor_cmd
,
4638 "show ip ospf (1-65535) neighbor [json]",
4641 "OSPF information\n"
4648 unsigned short instance
= 0;
4649 bool uj
= use_json(argc
, argv
);
4650 json_object
*json
= NULL
;
4651 int ret
= CMD_SUCCESS
;
4653 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4654 if (instance
!= ospf_instance
)
4655 return CMD_NOT_MY_INSTANCE
;
4657 ospf
= ospf_lookup_instance(instance
);
4658 if (!ospf
|| !ospf
->oi_running
)
4662 json
= json_object_new_object();
4664 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
, 0);
4667 vty_json(vty
, json
);
4672 static int show_ip_ospf_neighbor_all_common(struct vty
*vty
, struct ospf
*ospf
,
4673 json_object
*json
, bool use_json
,
4676 struct listnode
*node
;
4677 struct ospf_interface
*oi
;
4678 char buf
[PREFIX_STRLEN
];
4679 json_object
*json_vrf
= NULL
;
4680 json_object
*json_neighbor_sub
= NULL
;
4684 json_vrf
= json_object_new_object();
4689 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4691 show_ip_ospf_neighbour_header(vty
);
4693 if (ospf
->instance
) {
4695 json_object_int_add(json_vrf
, "ospfInstance",
4698 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4701 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4702 struct listnode
*nbr_node
;
4703 struct ospf_nbr_nbma
*nbr_nbma
;
4705 show_ip_ospf_neighbor_sub(vty
, oi
, json_vrf
, use_json
);
4707 /* print Down neighbor status */
4708 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nbr_node
, nbr_nbma
)) {
4709 if (nbr_nbma
->nbr
== NULL
4710 || nbr_nbma
->nbr
->state
== NSM_Down
) {
4713 json_object_new_object();
4714 json_object_int_add(json_neighbor_sub
,
4716 nbr_nbma
->priority
);
4717 json_object_boolean_true_add(
4720 json_object_string_add(
4724 json_object_int_add(
4726 "nbrNbmaRetransmitCounter", 0);
4727 json_object_int_add(
4729 "nbrNbmaRequestCounter", 0);
4730 json_object_int_add(
4732 "nbrNbmaDbSummaryCounter", 0);
4733 json_object_object_add(
4736 &nbr_nbma
->addr
, buf
,
4740 vty_out(vty
, "%-15s %3d %-15s %9s ",
4741 "-", nbr_nbma
->priority
, "Down",
4744 "%-32pI4 %-20s %5d %5d %5d\n",
4746 IF_NAME(oi
), 0, 0, 0);
4754 json_object_object_add(json
, ospf_get_name(ospf
),
4762 DEFUN (show_ip_ospf_neighbor_all
,
4763 show_ip_ospf_neighbor_all_cmd
,
4764 "show ip ospf [vrf <NAME|all>] neighbor all [json]",
4767 "OSPF information\n"
4771 "include down status neighbor\n"
4775 bool uj
= use_json(argc
, argv
);
4776 struct listnode
*node
= NULL
;
4777 char *vrf_name
= NULL
;
4778 bool all_vrf
= false;
4779 int ret
= CMD_SUCCESS
;
4782 uint8_t use_vrf
= 0;
4783 json_object
*json
= NULL
;
4785 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4788 json
= json_object_new_object();
4790 /* vrf input is provided could be all or specific vrf*/
4794 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4795 if (!ospf
->oi_running
)
4797 ret
= show_ip_ospf_neighbor_all_common(
4798 vty
, ospf
, json
, uj
, use_vrf
);
4802 vty_json(vty
, json
);
4807 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4808 if (ospf
== NULL
|| !ospf
->oi_running
) {
4810 json_object_free(json
);
4814 /* Display default ospf (instance 0) info */
4815 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4816 if (ospf
== NULL
|| !ospf
->oi_running
) {
4818 json_object_free(json
);
4824 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
,
4827 vty_out(vty
, "%s\n",
4828 json_object_to_json_string_ext(
4829 json
, JSON_C_TO_STRING_PRETTY
));
4834 json_object_free(json
);
4839 DEFUN (show_ip_ospf_instance_neighbor_all
,
4840 show_ip_ospf_instance_neighbor_all_cmd
,
4841 "show ip ospf (1-65535) neighbor all [json]",
4844 "OSPF information\n"
4847 "include down status neighbor\n"
4852 unsigned short instance
= 0;
4853 bool uj
= use_json(argc
, argv
);
4854 json_object
*json
= NULL
;
4855 int ret
= CMD_SUCCESS
;
4857 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4858 if (instance
!= ospf_instance
)
4859 return CMD_NOT_MY_INSTANCE
;
4861 ospf
= ospf_lookup_instance(instance
);
4862 if (!ospf
|| !ospf
->oi_running
)
4865 json
= json_object_new_object();
4867 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
, 0);
4870 vty_json(vty
, json
);
4875 static int show_ip_ospf_neighbor_int_common(struct vty
*vty
, struct ospf
*ospf
,
4877 struct cmd_token
**argv
,
4878 bool use_json
, uint8_t use_vrf
)
4880 struct interface
*ifp
;
4881 struct route_node
*rn
;
4882 json_object
*json
= NULL
;
4885 json
= json_object_new_object();
4887 if (ospf
->instance
) {
4889 json_object_int_add(json
, "ospfInstance",
4892 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4895 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
4897 ifp
= if_lookup_by_name(argv
[arg_base
]->arg
, ospf
->vrf_id
);
4900 json_object_boolean_true_add(json
, "noSuchIface");
4902 vty_out(vty
, "No such interface.\n");
4906 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
4907 struct ospf_interface
*oi
= rn
->info
;
4912 show_ip_ospf_neighbor_sub(vty
, oi
, json
, use_json
);
4916 vty_json(vty
, json
);
4923 DEFUN (show_ip_ospf_neighbor_int
,
4924 show_ip_ospf_neighbor_int_cmd
,
4925 "show ip ospf [vrf <NAME>] neighbor IFNAME [json]",
4928 "OSPF information\n"
4937 bool uj
= use_json(argc
, argv
);
4938 int ret
= CMD_SUCCESS
;
4939 struct interface
*ifp
= NULL
;
4940 char *vrf_name
= NULL
;
4941 vrf_id_t vrf_id
= VRF_DEFAULT
;
4942 struct vrf
*vrf
= NULL
;
4944 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
4945 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
4946 if (vrf_name
&& strmatch(vrf_name
, VRF_DEFAULT_NAME
))
4949 vrf
= vrf_lookup_by_name(vrf_name
);
4951 vrf_id
= vrf
->vrf_id
;
4953 ospf
= ospf_lookup_by_vrf_id(vrf_id
);
4955 if (!ospf
|| !ospf
->oi_running
)
4959 show_ip_ospf_neighbour_header(vty
);
4961 argv_find(argv
, argc
, "IFNAME", &idx_ifname
);
4963 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf_id
);
4967 ret
= show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
,
4972 DEFUN (show_ip_ospf_instance_neighbor_int
,
4973 show_ip_ospf_instance_neighbor_int_cmd
,
4974 "show ip ospf (1-65535) neighbor IFNAME [json]",
4977 "OSPF information\n"
4986 unsigned short instance
= 0;
4987 bool uj
= use_json(argc
, argv
);
4990 show_ip_ospf_neighbour_header(vty
);
4992 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4993 if (instance
!= ospf_instance
)
4994 return CMD_NOT_MY_INSTANCE
;
4996 ospf
= ospf_lookup_instance(instance
);
4997 if (!ospf
|| !ospf
->oi_running
)
5001 show_ip_ospf_neighbour_header(vty
);
5003 return show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
, argv
, uj
,
5007 static void show_ip_ospf_nbr_nbma_detail_sub(struct vty
*vty
,
5008 struct ospf_interface
*oi
,
5009 struct ospf_nbr_nbma
*nbr_nbma
,
5010 bool use_json
, json_object
*json
)
5012 char timebuf
[OSPF_TIME_DUMP_SIZE
];
5013 json_object
*json_sub
= NULL
;
5016 json_sub
= json_object_new_object();
5017 else /* Show neighbor ID. */
5018 vty_out(vty
, " Neighbor %s,", "-");
5020 /* Show interface address. */
5022 json_object_string_addf(json_sub
, "ifaceAddress", "%pI4",
5025 vty_out(vty
, " interface address %pI4\n",
5030 json_object_string_add(json_sub
, "areaId",
5031 ospf_area_desc_string(oi
->area
));
5032 json_object_string_add(json_sub
, "iface", IF_NAME(oi
));
5034 vty_out(vty
, " In the area %s via interface %s\n",
5035 ospf_area_desc_string(oi
->area
), IF_NAME(oi
));
5037 /* Show neighbor priority and state. */
5039 json_object_int_add(json_sub
, "nbrPriority",
5040 nbr_nbma
->priority
);
5041 json_object_string_add(json_sub
, "nbrState", "down");
5043 vty_out(vty
, " Neighbor priority is %d, State is %s,",
5044 nbr_nbma
->priority
, "Down");
5046 /* Show state changes. */
5048 json_object_int_add(json_sub
, "stateChangeCounter",
5049 nbr_nbma
->state_change
);
5051 vty_out(vty
, " %d state changes\n", nbr_nbma
->state_change
);
5053 /* Show PollInterval */
5055 json_object_int_add(json_sub
, "pollInterval", nbr_nbma
->v_poll
);
5057 vty_out(vty
, " Poll interval %d\n", nbr_nbma
->v_poll
);
5059 /* Show poll-interval timer. */
5060 if (nbr_nbma
->t_poll
) {
5063 time_store
= monotime_until(&nbr_nbma
->t_poll
->u
.sands
,
5065 json_object_int_add(json_sub
,
5066 "pollIntervalTimerDueMsec",
5069 vty_out(vty
, " Poll timer due in %s\n",
5070 ospf_timer_dump(nbr_nbma
->t_poll
, timebuf
,
5074 /* Show poll-interval timer thread. */
5076 if (nbr_nbma
->t_poll
!= NULL
)
5077 json_object_string_add(json_sub
,
5078 "pollIntervalTimerThread", "on");
5080 vty_out(vty
, " Thread Poll Timer %s\n",
5081 nbr_nbma
->t_poll
!= NULL
? "on" : "off");
5084 json_object_object_add(json
, "noNbrId", json_sub
);
5087 static void show_ip_ospf_neighbor_detail_sub(struct vty
*vty
,
5088 struct ospf_interface
*oi
,
5089 struct ospf_neighbor
*nbr
,
5090 struct ospf_neighbor
*prev_nbr
,
5091 json_object
*json
, bool use_json
)
5093 char timebuf
[OSPF_TIME_DUMP_SIZE
];
5094 json_object
*json_neigh
= NULL
, *json_neigh_array
= NULL
;
5095 char neigh_str
[INET_ADDRSTRLEN
] = {0};
5096 char neigh_state
[16] = {0};
5100 !IPV4_ADDR_SAME(&prev_nbr
->src
, &nbr
->src
)) {
5101 json_neigh_array
= NULL
;
5104 if (nbr
->state
== NSM_Attempt
5105 && nbr
->router_id
.s_addr
== INADDR_ANY
)
5106 strlcpy(neigh_str
, "noNbrId", sizeof(neigh_str
));
5108 inet_ntop(AF_INET
, &nbr
->router_id
,
5109 neigh_str
, sizeof(neigh_str
));
5111 json_object_object_get_ex(json
, neigh_str
, &json_neigh_array
);
5113 if (!json_neigh_array
) {
5114 json_neigh_array
= json_object_new_array();
5115 json_object_object_add(json
, neigh_str
,
5119 json_neigh
= json_object_new_object();
5122 /* Show neighbor ID. */
5123 if (nbr
->state
== NSM_Attempt
5124 && nbr
->router_id
.s_addr
== INADDR_ANY
)
5125 vty_out(vty
, " Neighbor %s,", "-");
5127 vty_out(vty
, " Neighbor %pI4,",
5131 /* Show interface address. */
5133 json_object_string_addf(json_neigh
, "ifaceAddress", "%pI4",
5134 &nbr
->address
.u
.prefix4
);
5136 vty_out(vty
, " interface address %pI4\n",
5137 &nbr
->address
.u
.prefix4
);
5141 json_object_string_add(json_neigh
, "areaId",
5142 ospf_area_desc_string(oi
->area
));
5143 json_object_string_add(json_neigh
, "ifaceName", oi
->ifp
->name
);
5145 vty_out(vty
, " In the area %s via interface %s\n",
5146 ospf_area_desc_string(oi
->area
), oi
->ifp
->name
);
5148 /* Show neighbor priority and state. */
5149 ospf_nbr_ism_state_message(nbr
, neigh_state
, sizeof(neigh_state
));
5151 json_object_int_add(json_neigh
, "nbrPriority", nbr
->priority
);
5152 json_object_string_add(json_neigh
, "nbrState", neigh_state
);
5154 vty_out(vty
, " Neighbor priority is %d, State is %s,",
5155 nbr
->priority
, neigh_state
);
5157 /* Show state changes. */
5159 json_object_int_add(json_neigh
, "stateChangeCounter",
5162 vty_out(vty
, " %d state changes\n", nbr
->state_change
);
5164 if (nbr
->ts_last_progress
.tv_sec
|| nbr
->ts_last_progress
.tv_usec
) {
5169 monotime_since(&nbr
->ts_last_progress
, &res
) / 1000LL;
5171 json_object_int_add(json_neigh
, "lastPrgrsvChangeMsec",
5175 " Most recent state change statistics:\n");
5176 vty_out(vty
, " Progressive change %s ago\n",
5177 ospf_timeval_dump(&res
, timebuf
,
5182 if (nbr
->ts_last_regress
.tv_sec
|| nbr
->ts_last_regress
.tv_usec
) {
5187 monotime_since(&nbr
->ts_last_regress
, &res
) / 1000LL;
5189 json_object_int_add(json_neigh
,
5190 "lastRegressiveChangeMsec",
5192 if (nbr
->last_regress_str
)
5193 json_object_string_add(
5195 "lastRegressiveChangeReason",
5196 nbr
->last_regress_str
);
5199 " Regressive change %s ago, due to %s\n",
5200 ospf_timeval_dump(&res
, timebuf
,
5202 (nbr
->last_regress_str
? nbr
->last_regress_str
5207 /* Show Designated Rotuer ID. */
5209 json_object_string_addf(json_neigh
, "routerDesignatedId",
5210 "%pI4", &nbr
->d_router
);
5212 vty_out(vty
, " DR is %pI4,", &nbr
->d_router
);
5214 /* Show Backup Designated Rotuer ID. */
5216 json_object_string_addf(json_neigh
, "routerDesignatedBackupId",
5217 "%pI4", &nbr
->bd_router
);
5219 vty_out(vty
, " BDR is %pI4\n", &nbr
->bd_router
);
5223 json_object_int_add(json_neigh
, "optionsCounter", nbr
->options
);
5224 json_object_string_add(json_neigh
, "optionsList",
5225 ospf_options_dump(nbr
->options
));
5227 vty_out(vty
, " Options %d %s\n", nbr
->options
,
5228 ospf_options_dump(nbr
->options
));
5230 /* Show Router Dead interval timer. */
5232 if (nbr
->t_inactivity
) {
5234 time_store
= monotime_until(&nbr
->t_inactivity
->u
.sands
,
5237 json_object_int_add(json_neigh
,
5238 "routerDeadIntervalTimerDueMsec",
5241 json_object_int_add(
5243 "routerDeadIntervalTimerDueMsec", -1);
5245 vty_out(vty
, " Dead timer due in %s\n",
5246 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
5249 /* Show Database Summary list. */
5251 json_object_int_add(json_neigh
, "databaseSummaryListCounter",
5252 ospf_db_summary_count(nbr
));
5254 vty_out(vty
, " Database Summary List %d\n",
5255 ospf_db_summary_count(nbr
));
5257 /* Show Link State Request list. */
5259 json_object_int_add(json_neigh
, "linkStateRequestListCounter",
5260 ospf_ls_request_count(nbr
));
5262 vty_out(vty
, " Link State Request List %ld\n",
5263 ospf_ls_request_count(nbr
));
5265 /* Show Link State Retransmission list. */
5267 json_object_int_add(json_neigh
,
5268 "linkStateRetransmissionListCounter",
5269 ospf_ls_retransmit_count(nbr
));
5271 vty_out(vty
, " Link State Retransmission List %ld\n",
5272 ospf_ls_retransmit_count(nbr
));
5274 /* Show inactivity timer thread. */
5276 if (nbr
->t_inactivity
!= NULL
)
5277 json_object_string_add(json_neigh
,
5278 "threadInactivityTimer", "on");
5280 vty_out(vty
, " Thread Inactivity Timer %s\n",
5281 nbr
->t_inactivity
!= NULL
? "on" : "off");
5283 /* Show Database Description retransmission thread. */
5285 if (nbr
->t_db_desc
!= NULL
)
5286 json_object_string_add(
5288 "threadDatabaseDescriptionRetransmission",
5292 " Thread Database Description Retransmision %s\n",
5293 nbr
->t_db_desc
!= NULL
? "on" : "off");
5295 /* Show Link State Request Retransmission thread. */
5297 if (nbr
->t_ls_req
!= NULL
)
5298 json_object_string_add(
5300 "threadLinkStateRequestRetransmission", "on");
5303 " Thread Link State Request Retransmission %s\n",
5304 nbr
->t_ls_req
!= NULL
? "on" : "off");
5306 /* Show Link State Update Retransmission thread. */
5308 if (nbr
->t_ls_upd
!= NULL
)
5309 json_object_string_add(
5311 "threadLinkStateUpdateRetransmission",
5315 " Thread Link State Update Retransmission %s\n\n",
5316 nbr
->t_ls_upd
!= NULL
? "on" : "off");
5319 vty_out(vty
, " Graceful restart Helper info:\n");
5321 if (OSPF_GR_IS_ACTIVE_HELPER(nbr
)) {
5323 " Graceful Restart HELPER Status : Inprogress.\n");
5326 " Graceful Restart grace period time: %d (seconds).\n",
5327 nbr
->gr_helper_info
.recvd_grace_period
);
5328 vty_out(vty
, " Graceful Restart reason: %s.\n",
5329 ospf_restart_reason2str(
5330 nbr
->gr_helper_info
.gr_restart_reason
));
5333 " Graceful Restart HELPER Status : None\n");
5336 if (nbr
->gr_helper_info
.rejected_reason
5337 != OSPF_HELPER_REJECTED_NONE
)
5338 vty_out(vty
, " Helper rejected reason: %s.\n",
5339 ospf_rejected_reason2str(
5340 nbr
->gr_helper_info
.rejected_reason
));
5342 if (nbr
->gr_helper_info
.helper_exit_reason
5343 != OSPF_GR_HELPER_EXIT_NONE
)
5344 vty_out(vty
, " Last helper exit reason: %s.\n\n",
5345 ospf_exit_reason2str(
5346 nbr
->gr_helper_info
.helper_exit_reason
));
5350 json_object_string_add(json_neigh
, "grHelperStatus",
5351 OSPF_GR_IS_ACTIVE_HELPER(nbr
) ?
5354 if (OSPF_GR_IS_ACTIVE_HELPER(nbr
)) {
5355 json_object_int_add(
5356 json_neigh
, "graceInterval",
5357 nbr
->gr_helper_info
.recvd_grace_period
);
5358 json_object_string_add(
5359 json_neigh
, "grRestartReason",
5360 ospf_restart_reason2str(
5361 nbr
->gr_helper_info
.gr_restart_reason
));
5364 if (nbr
->gr_helper_info
.rejected_reason
5365 != OSPF_HELPER_REJECTED_NONE
)
5366 json_object_string_add(
5367 json_neigh
, "helperRejectReason",
5368 ospf_rejected_reason2str(
5369 nbr
->gr_helper_info
.rejected_reason
));
5371 if (nbr
->gr_helper_info
.helper_exit_reason
5372 != OSPF_GR_HELPER_EXIT_NONE
)
5373 json_object_string_add(
5374 json_neigh
, "helperExitReason",
5375 ospf_exit_reason2str(
5377 .helper_exit_reason
));
5380 bfd_sess_show(vty
, json_neigh
, nbr
->bfd_session
);
5383 json_object_array_add(json_neigh_array
, json_neigh
);
5387 static int show_ip_ospf_neighbor_id_common(struct vty
*vty
, struct ospf
*ospf
,
5388 struct in_addr
*router_id
,
5389 bool use_json
, uint8_t use_vrf
,
5392 struct listnode
*node
;
5393 struct ospf_neighbor
*nbr
;
5394 struct ospf_interface
*oi
;
5395 json_object
*json
= NULL
;
5398 json
= json_object_new_object();
5400 if (ospf
->instance
) {
5402 json_object_int_add(json
, "ospfInstance",
5405 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5408 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
5410 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5411 nbr
= ospf_nbr_lookup_by_routerid(oi
->nbrs
, router_id
);
5417 show_ip_ospf_neighbor_detail_sub(vty
, oi
, nbr
, NULL
,
5420 show_ip_ospf_neighbour_brief(vty
, nbr
, NULL
, json
,
5425 vty_json(vty
, json
);
5432 DEFPY(show_ip_ospf_neighbor_id
, show_ip_ospf_neighbor_id_cmd
,
5433 "show ip ospf neighbor A.B.C.D$router_id [detail$detail] [json$json]",
5435 "OSPF information\n"
5438 "Detailed output\n" JSON_STR
)
5441 struct listnode
*node
;
5442 int ret
= CMD_SUCCESS
;
5444 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5445 if (!ospf
->oi_running
)
5447 ret
= show_ip_ospf_neighbor_id_common(vty
, ospf
, &router_id
,
5448 !!json
, 0, !!detail
);
5454 DEFPY(show_ip_ospf_instance_neighbor_id
, show_ip_ospf_instance_neighbor_id_cmd
,
5455 "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [detail$detail] [json$json]",
5457 "OSPF information\n"
5461 "Detailed output\n" JSON_STR
)
5465 if (instance
!= ospf_instance
)
5466 return CMD_NOT_MY_INSTANCE
;
5468 ospf
= ospf_lookup_instance(instance
);
5469 if (!ospf
|| !ospf
->oi_running
)
5472 return show_ip_ospf_neighbor_id_common(vty
, ospf
, &router_id
, !!json
, 0,
5476 static int show_ip_ospf_neighbor_detail_common(struct vty
*vty
,
5478 json_object
*json
, bool use_json
,
5481 struct ospf_interface
*oi
;
5482 struct listnode
*node
;
5483 json_object
*json_vrf
= NULL
;
5484 json_object
*json_nbr_sub
= NULL
;
5488 json_vrf
= json_object_new_object();
5492 json_nbr_sub
= json_object_new_object();
5495 if (ospf
->instance
) {
5497 json_object_int_add(json
, "ospfInstance",
5500 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5503 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5505 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5506 struct route_node
*rn
;
5507 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
5509 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5515 if (nbr
!= oi
->nbr_self
) {
5516 if (nbr
->state
!= NSM_Down
) {
5517 show_ip_ospf_neighbor_detail_sub(
5518 vty
, oi
, nbr
, prev_nbr
,
5519 json_nbr_sub
, use_json
);
5527 json_object_object_add(json_vrf
, "neighbors",
5530 json_object_object_add(json
, ospf_get_name(ospf
),
5538 DEFUN (show_ip_ospf_neighbor_detail
,
5539 show_ip_ospf_neighbor_detail_cmd
,
5540 "show ip ospf [vrf <NAME|all>] neighbor detail [json]",
5543 "OSPF information\n"
5547 "detail of all neighbors\n"
5551 bool uj
= use_json(argc
, argv
);
5552 struct listnode
*node
= NULL
;
5553 char *vrf_name
= NULL
;
5554 bool all_vrf
= false;
5555 int ret
= CMD_SUCCESS
;
5558 uint8_t use_vrf
= 0;
5559 json_object
*json
= NULL
;
5561 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5564 json
= json_object_new_object();
5566 /* vrf input is provided could be all or specific vrf*/
5570 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5571 if (!ospf
->oi_running
)
5573 ret
= show_ip_ospf_neighbor_detail_common(
5574 vty
, ospf
, json
, uj
, use_vrf
);
5577 vty_json(vty
, json
);
5581 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5582 if (ospf
== NULL
|| !ospf
->oi_running
) {
5584 json_object_free(json
);
5588 /* Display default ospf (instance 0) info */
5589 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5590 if (ospf
== NULL
|| !ospf
->oi_running
) {
5592 json_object_free(json
);
5598 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
,
5601 vty_out(vty
, "%s\n",
5602 json_object_to_json_string_ext(
5603 json
, JSON_C_TO_STRING_PRETTY
));
5608 json_object_free(json
);
5613 DEFUN (show_ip_ospf_instance_neighbor_detail
,
5614 show_ip_ospf_instance_neighbor_detail_cmd
,
5615 "show ip ospf (1-65535) neighbor detail [json]",
5618 "OSPF information\n"
5621 "detail of all neighbors\n"
5626 unsigned short instance
= 0;
5627 bool uj
= use_json(argc
, argv
);
5628 json_object
*json
= NULL
;
5629 int ret
= CMD_SUCCESS
;
5631 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5632 if (instance
!= ospf_instance
)
5633 return CMD_NOT_MY_INSTANCE
;
5635 ospf
= ospf_lookup_instance(instance
);
5636 if (!ospf
|| !ospf
->oi_running
)
5640 json
= json_object_new_object();
5642 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
, 0);
5645 vty_json(vty
, json
);
5650 static int show_ip_ospf_neighbor_detail_all_common(struct vty
*vty
,
5656 struct listnode
*node
;
5657 struct ospf_interface
*oi
;
5658 json_object
*json_vrf
= NULL
;
5662 json_vrf
= json_object_new_object();
5667 if (ospf
->instance
) {
5669 json_object_int_add(json
, "ospfInstance",
5672 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5675 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5677 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5678 struct route_node
*rn
;
5679 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
5680 struct ospf_nbr_nbma
*nbr_nbma
;
5682 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5688 if (nbr
!= oi
->nbr_self
)
5689 if (nbr
->state
!= NSM_Down
)
5690 show_ip_ospf_neighbor_detail_sub(
5691 vty
, oi
, rn
->info
, prev_nbr
,
5692 json_vrf
, use_json
);
5696 if (oi
->type
!= OSPF_IFTYPE_NBMA
)
5699 struct listnode
*nd
;
5701 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nd
, nbr_nbma
)) {
5702 if (nbr_nbma
->nbr
== NULL
||
5703 nbr_nbma
->nbr
->state
== NSM_Down
)
5704 show_ip_ospf_nbr_nbma_detail_sub(
5705 vty
, oi
, nbr_nbma
, use_json
, json_vrf
);
5711 json_object_object_add(json
, ospf_get_name(ospf
),
5720 DEFUN (show_ip_ospf_neighbor_detail_all
,
5721 show_ip_ospf_neighbor_detail_all_cmd
,
5722 "show ip ospf [vrf <NAME|all>] neighbor detail all [json]",
5725 "OSPF information\n"
5729 "detail of all neighbors\n"
5730 "include down status neighbor\n"
5734 bool uj
= use_json(argc
, argv
);
5735 struct listnode
*node
= NULL
;
5736 char *vrf_name
= NULL
;
5737 bool all_vrf
= false;
5738 int ret
= CMD_SUCCESS
;
5741 uint8_t use_vrf
= 0;
5742 json_object
*json
= NULL
;
5744 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5747 json
= json_object_new_object();
5749 /* vrf input is provided could be all or specific vrf*/
5753 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5754 if (!ospf
->oi_running
)
5756 ret
= show_ip_ospf_neighbor_detail_all_common(
5757 vty
, ospf
, json
, uj
, use_vrf
);
5761 vty_json(vty
, json
);
5765 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5766 if (ospf
== NULL
|| !ospf
->oi_running
) {
5768 json_object_free(json
);
5772 /* Display default ospf (instance 0) info */
5773 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5774 if (ospf
== NULL
|| !ospf
->oi_running
) {
5776 json_object_free(json
);
5782 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
,
5785 vty_out(vty
, "%s\n",
5786 json_object_to_json_string_ext(
5787 json
, JSON_C_TO_STRING_PRETTY
));
5792 json_object_free(json
);
5797 DEFUN (show_ip_ospf_instance_neighbor_detail_all
,
5798 show_ip_ospf_instance_neighbor_detail_all_cmd
,
5799 "show ip ospf (1-65535) neighbor detail all [json]",
5802 "OSPF information\n"
5805 "detail of all neighbors\n"
5806 "include down status neighbor\n"
5811 unsigned short instance
= 0;
5812 bool uj
= use_json(argc
, argv
);
5813 json_object
*json
= NULL
;
5814 int ret
= CMD_SUCCESS
;
5816 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5817 if (instance
!= ospf_instance
)
5818 return CMD_NOT_MY_INSTANCE
;
5820 ospf
= ospf_lookup_instance(instance
);
5821 if (!ospf
|| !ospf
->oi_running
)
5825 json
= json_object_new_object();
5827 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
, uj
, 0);
5830 vty_json(vty
, json
);
5835 static int show_ip_ospf_neighbor_int_detail_common(struct vty
*vty
,
5838 struct cmd_token
**argv
,
5841 struct ospf_interface
*oi
;
5842 struct interface
*ifp
;
5843 struct route_node
*rn
, *nrn
;
5844 struct ospf_neighbor
*nbr
;
5845 json_object
*json
= NULL
;
5848 json
= json_object_new_object();
5850 if (ospf
->instance
) {
5852 json_object_int_add(json
, "ospfInstance",
5855 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5858 ifp
= if_lookup_by_name(argv
[arg_base
]->arg
, ospf
->vrf_id
);
5861 vty_out(vty
, "No such interface.\n");
5863 vty_out(vty
, "{}\n");
5864 json_object_free(json
);
5869 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
5875 for (nrn
= route_top(oi
->nbrs
); nrn
; nrn
= route_next(nrn
)) {
5881 if (nbr
== oi
->nbr_self
)
5884 if (nbr
->state
== NSM_Down
)
5887 show_ip_ospf_neighbor_detail_sub(vty
, oi
, nbr
, NULL
,
5893 vty_json(vty
, json
);
5900 DEFUN (show_ip_ospf_neighbor_int_detail
,
5901 show_ip_ospf_neighbor_int_detail_cmd
,
5902 "show ip ospf neighbor IFNAME detail [json]",
5905 "OSPF information\n"
5908 "detail of all neighbors\n"
5912 bool uj
= use_json(argc
, argv
);
5913 struct listnode
*node
= NULL
;
5914 int ret
= CMD_SUCCESS
;
5915 bool ospf_output
= false;
5917 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5918 if (!ospf
->oi_running
)
5921 ret
= show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, 4,
5926 vty_out(vty
, "%% OSPF instance not found\n");
5931 DEFUN (show_ip_ospf_instance_neighbor_int_detail
,
5932 show_ip_ospf_instance_neighbor_int_detail_cmd
,
5933 "show ip ospf (1-65535) neighbor IFNAME detail [json]",
5936 "OSPF information\n"
5940 "detail of all neighbors\n"
5946 unsigned short instance
= 0;
5947 bool uj
= use_json(argc
, argv
);
5949 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5950 if (instance
!= ospf_instance
)
5951 return CMD_NOT_MY_INSTANCE
;
5953 ospf
= ospf_lookup_instance(instance
);
5954 if (!ospf
|| !ospf
->oi_running
)
5957 return show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, idx_ifname
,
5961 /* Show functions */
5962 static int show_lsa_summary(struct vty
*vty
, struct ospf_lsa
*lsa
, int self
,
5963 json_object
*json_lsa
)
5965 struct router_lsa
*rl
;
5966 struct summary_lsa
*sl
;
5967 struct as_external_lsa
*asel
;
5968 struct prefix_ipv4 p
;
5971 /* If self option is set, check LSA self flag. */
5972 if (self
== 0 || IS_LSA_SELF(lsa
)) {
5975 /* LSA common part show. */
5976 vty_out(vty
, "%-15pI4",
5978 vty_out(vty
, "%-15pI4 %4d 0x%08lx 0x%04x",
5979 &lsa
->data
->adv_router
, LS_AGE(lsa
),
5980 (unsigned long)ntohl(
5981 lsa
->data
->ls_seqnum
),
5982 ntohs(lsa
->data
->checksum
));
5987 snprintf(seqnum
, sizeof(seqnum
), "%x",
5988 ntohl(lsa
->data
->ls_seqnum
));
5989 snprintf(checksum
, sizeof(checksum
), "%x",
5990 ntohs(lsa
->data
->checksum
));
5991 json_object_string_addf(json_lsa
, "lsId",
5992 "%pI4", &lsa
->data
->id
);
5993 json_object_string_addf(
5994 json_lsa
, "advertisedRouter", "%pI4",
5995 &lsa
->data
->adv_router
);
5996 json_object_int_add(json_lsa
, "lsaAge",
5998 json_object_string_add(
5999 json_lsa
, "sequenceNumber", seqnum
);
6000 json_object_string_add(json_lsa
, "checksum",
6004 /* LSA specific part show. */
6005 switch (lsa
->data
->type
) {
6006 case OSPF_ROUTER_LSA
:
6007 rl
= (struct router_lsa
*)lsa
->data
;
6010 vty_out(vty
, " %-d", ntohs(rl
->links
));
6012 json_object_int_add(json_lsa
,
6016 case OSPF_SUMMARY_LSA
:
6017 sl
= (struct summary_lsa
*)lsa
->data
;
6020 p
.prefix
= sl
->header
.id
;
6021 p
.prefixlen
= ip_masklen(sl
->mask
);
6022 apply_mask_ipv4(&p
);
6025 vty_out(vty
, " %pFX", &p
);
6027 json_object_string_addf(
6028 json_lsa
, "summaryAddress",
6032 case OSPF_AS_EXTERNAL_LSA
:
6033 case OSPF_AS_NSSA_LSA
:
6034 asel
= (struct as_external_lsa
*)lsa
->data
;
6037 p
.prefix
= asel
->header
.id
;
6038 p
.prefixlen
= ip_masklen(asel
->mask
);
6039 apply_mask_ipv4(&p
);
6042 vty_out(vty
, " %s %pFX [0x%lx]",
6048 (unsigned long)ntohl(
6049 asel
->e
[0].route_tag
));
6051 json_object_string_add(
6052 json_lsa
, "metricType",
6057 json_object_string_addf(
6058 json_lsa
, "route", "%pFX", &p
);
6059 json_object_int_add(
6061 (unsigned long)ntohl(
6062 asel
->e
[0].route_tag
));
6065 case OSPF_NETWORK_LSA
:
6066 case OSPF_ASBR_SUMMARY_LSA
:
6067 case OSPF_OPAQUE_LINK_LSA
:
6068 case OSPF_OPAQUE_AREA_LSA
:
6069 case OSPF_OPAQUE_AS_LSA
:
6084 static const char *const show_database_desc
[] = {
6086 "Router Link States",
6088 "Summary Link States",
6089 "ASBR-Summary Link States",
6090 "AS External Link States",
6091 "Group Membership LSA",
6092 "NSSA-external Link States",
6094 "Link-Local Opaque-LSA",
6095 "Area-Local Opaque-LSA",
6096 "AS-external Opaque-LSA",
6099 static const char * const show_database_desc_json
[] = {
6102 "networkLinkStates",
6103 "summaryLinkStates",
6104 "asbrSummaryLinkStates",
6105 "asExternalLinkStates",
6106 "groupMembershipLsa",
6107 "nssaExternalLinkStates",
6109 "linkLocalOpaqueLsa",
6110 "areaLocalOpaqueLsa",
6111 "asExternalOpaqueLsa",
6114 static const char *const show_database_desc_count_json
[] = {
6116 "routerLinkStatesCount",
6117 "networkLinkStatesCount",
6118 "summaryLinkStatesCount",
6119 "asbrSummaryLinkStatesCount",
6120 "asExternalLinkStatesCount",
6121 "groupMembershipLsaCount",
6122 "nssaExternalLinkStatesCount",
6124 "linkLocalOpaqueLsaCount",
6125 "areaLocalOpaqueLsaCount",
6126 "asExternalOpaqueLsaCount",
6129 static const char *const show_database_header
[] = {
6131 "Link ID ADV Router Age Seq# CkSum Link count",
6132 "Link ID ADV Router Age Seq# CkSum",
6133 "Link ID ADV Router Age Seq# CkSum Route",
6134 "Link ID ADV Router Age Seq# CkSum",
6135 "Link ID ADV Router Age Seq# CkSum Route",
6136 " --- header for Group Member ----",
6137 "Link ID ADV Router Age Seq# CkSum Route",
6139 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6140 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6141 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6144 static void show_ip_ospf_database_header(struct vty
*vty
, struct ospf_lsa
*lsa
,
6147 struct router_lsa
*rlsa
= (struct router_lsa
*)lsa
->data
;
6150 vty_out(vty
, " LS age: %d\n", LS_AGE(lsa
));
6151 vty_out(vty
, " Options: 0x%-2x : %s\n", lsa
->data
->options
,
6152 ospf_options_dump(lsa
->data
->options
));
6153 vty_out(vty
, " LS Flags: 0x%-2x %s\n", lsa
->flags
,
6154 ((lsa
->flags
& OSPF_LSA_LOCAL_XLT
)
6155 ? "(Translated from Type-7)"
6158 if (lsa
->data
->type
== OSPF_ROUTER_LSA
) {
6159 vty_out(vty
, " Flags: 0x%x", rlsa
->flags
);
6162 vty_out(vty
, " :%s%s%s%s",
6163 IS_ROUTER_LSA_BORDER(rlsa
) ? " ABR"
6165 IS_ROUTER_LSA_EXTERNAL(rlsa
) ? " ASBR"
6167 IS_ROUTER_LSA_VIRTUAL(rlsa
)
6170 IS_ROUTER_LSA_SHORTCUT(rlsa
)
6176 vty_out(vty
, " LS Type: %s\n",
6177 lookup_msg(ospf_lsa_type_msg
, lsa
->data
->type
, NULL
));
6178 vty_out(vty
, " Link State ID: %pI4 %s\n",
6180 lookup_msg(ospf_link_state_id_type_msg
, lsa
->data
->type
,
6182 vty_out(vty
, " Advertising Router: %pI4\n",
6183 &lsa
->data
->adv_router
);
6184 vty_out(vty
, " LS Seq Number: %08lx\n",
6185 (unsigned long)ntohl(lsa
->data
->ls_seqnum
));
6186 vty_out(vty
, " Checksum: 0x%04x\n",
6187 ntohs(lsa
->data
->checksum
));
6188 vty_out(vty
, " Length: %d\n\n", ntohs(lsa
->data
->length
));
6193 snprintf(seqnum
, 10, "%x", ntohl(lsa
->data
->ls_seqnum
));
6194 snprintf(checksum
, 10, "%x", ntohs(lsa
->data
->checksum
));
6196 json_object_int_add(json
, "lsaAge", LS_AGE(lsa
));
6197 json_object_string_add(json
, "options",
6198 ospf_options_dump(lsa
->data
->options
));
6199 json_object_int_add(json
, "lsaFlags", lsa
->flags
);
6201 if (lsa
->flags
& OSPF_LSA_LOCAL_XLT
)
6202 json_object_boolean_true_add(json
,
6203 "translatedFromType7");
6205 if (lsa
->data
->type
== OSPF_ROUTER_LSA
) {
6206 json_object_int_add(json
, "flags", rlsa
->flags
);
6209 if (IS_ROUTER_LSA_BORDER(rlsa
))
6210 json_object_boolean_true_add(json
,
6212 if (IS_ROUTER_LSA_EXTERNAL(rlsa
))
6213 json_object_boolean_true_add(json
,
6215 if (IS_ROUTER_LSA_VIRTUAL(rlsa
))
6216 json_object_boolean_true_add(
6217 json
, "vlEndpoint");
6218 if (IS_ROUTER_LSA_SHORTCUT(rlsa
))
6219 json_object_boolean_true_add(
6224 json_object_string_add(
6226 lookup_msg(ospf_lsa_type_msg
, lsa
->data
->type
, NULL
));
6227 json_object_string_addf(json
, "linkStateId", "%pI4",
6229 json_object_string_addf(json
, "advertisingRouter", "%pI4",
6230 &lsa
->data
->adv_router
);
6231 json_object_string_add(json
, "lsaSeqNumber", seqnum
);
6232 json_object_string_add(json
, "checksum", checksum
);
6233 json_object_int_add(json
, "length", ntohs(lsa
->data
->length
));
6237 static const char *const link_type_desc
[] = {
6239 "another Router (point-to-point)",
6240 "a Transit Network",
6245 static const char *const link_id_desc
[] = {
6246 "(null)", "Neighboring Router ID", "Designated Router address",
6247 "Net", "Neighboring Router ID",
6250 static const char *const link_data_desc
[] = {
6251 "(null)", "Router Interface address", "Router Interface address",
6252 "Network Mask", "Router Interface address",
6255 static const char *const link_id_desc_json
[] = {
6256 "null", "neighborRouterId", "designatedRouterAddress",
6257 "networkAddress", "neighborRouterId",
6260 static const char *const link_data_desc_json
[] = {
6261 "null", "routerInterfaceAddress", "routerInterfaceAddress",
6262 "networkMask", "routerInterfaceAddress",
6265 /* Show router-LSA each Link information. */
6266 static void show_ip_ospf_database_router_links(struct vty
*vty
,
6267 struct router_lsa
*rl
,
6272 json_object
*json_links
= NULL
;
6273 json_object
*json_link
= NULL
;
6275 char buf
[PREFIX_STRLEN
];
6278 json_links
= json_object_new_object();
6280 len
= ntohs(rl
->header
.length
) - 4;
6281 for (i
= 0; i
< ntohs(rl
->links
) && len
> 0; len
-= 12, i
++) {
6282 type
= rl
->link
[i
].type
;
6287 snprintf(link
, sizeof(link
), "link%u", i
);
6288 json_link
= json_object_new_object();
6289 json_object_string_add(json_link
, "linkType",
6290 link_type_desc
[type
]);
6291 json_object_string_add(json_link
,
6292 link_id_desc_json
[type
],
6294 &rl
->link
[i
].link_id
,
6296 json_object_string_add(
6297 json_link
, link_data_desc_json
[type
],
6298 inet_ntop(AF_INET
, &rl
->link
[i
].link_data
,
6300 json_object_int_add(json_link
, "numOfTosMetrics",
6302 json_object_int_add(json_link
, "tos0Metric",
6303 ntohs(rl
->link
[i
].metric
));
6304 json_object_object_add(json_links
, link
, json_link
);
6306 vty_out(vty
, " Link connected to: %s\n",
6307 link_type_desc
[type
]);
6308 vty_out(vty
, " (Link ID) %s: %pI4\n",
6310 &rl
->link
[i
].link_id
);
6311 vty_out(vty
, " (Link Data) %s: %pI4\n",
6312 link_data_desc
[type
],
6313 &rl
->link
[i
].link_data
);
6314 vty_out(vty
, " Number of TOS metrics: 0\n");
6315 vty_out(vty
, " TOS 0 Metric: %d\n",
6316 ntohs(rl
->link
[i
].metric
));
6321 json_object_object_add(json
, "routerLinks", json_links
);
6324 /* Show router-LSA detail information. */
6325 static int show_router_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6329 struct router_lsa
*rl
= (struct router_lsa
*)lsa
->data
;
6331 show_ip_ospf_database_header(vty
, lsa
, json
);
6334 vty_out(vty
, " Number of Links: %d\n\n",
6337 json_object_int_add(json
, "numOfLinks",
6340 show_ip_ospf_database_router_links(vty
, rl
, json
);
6349 /* Show network-LSA detail information. */
6350 static int show_network_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6354 char buf
[PREFIX_STRLEN
];
6355 json_object
*json_attached_rt
= NULL
;
6356 json_object
*json_router
= NULL
;
6359 json_attached_rt
= json_object_new_object();
6362 struct network_lsa
*nl
= (struct network_lsa
*)lsa
->data
;
6363 struct in_addr
*addr
;
6365 show_ip_ospf_database_header(vty
, lsa
, json
);
6368 vty_out(vty
, " Network Mask: /%d\n",
6369 ip_masklen(nl
->mask
));
6371 json_object_int_add(json
, "networkMask",
6372 ip_masklen(nl
->mask
));
6374 length
= lsa
->size
- OSPF_LSA_HEADER_SIZE
- 4;
6375 addr
= &nl
->routers
[0];
6376 for (i
= 0; length
> 0 && addr
;
6377 length
-= 4, addr
= &nl
->routers
[++i
])
6379 vty_out(vty
, " Attached Router: %pI4\n",
6383 json_router
= json_object_new_object();
6384 json_object_string_add(
6385 json_router
, "attachedRouterId",
6386 inet_ntop(AF_INET
, addr
, buf
,
6388 json_object_object_add(json_attached_rt
,
6389 inet_ntop(AF_INET
, addr
,
6397 json_object_object_add(json
, "attchedRouters",
6403 /* Show summary-LSA detail information. */
6404 static int show_summary_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6408 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
6410 show_ip_ospf_database_header(vty
, lsa
, json
);
6413 vty_out(vty
, " Network Mask: /%d\n",
6414 ip_masklen(sl
->mask
));
6415 vty_out(vty
, " TOS: 0 Metric: %d\n",
6416 GET_METRIC(sl
->metric
));
6419 json_object_int_add(json
, "networkMask",
6420 ip_masklen(sl
->mask
));
6421 json_object_int_add(json
, "tos0Metric",
6422 GET_METRIC(sl
->metric
));
6429 /* Show summary-ASBR-LSA detail information. */
6430 static int show_summary_asbr_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6434 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
6436 show_ip_ospf_database_header(vty
, lsa
, json
);
6439 vty_out(vty
, " Network Mask: /%d\n",
6440 ip_masklen(sl
->mask
));
6441 vty_out(vty
, " TOS: 0 Metric: %d\n",
6442 GET_METRIC(sl
->metric
));
6445 json_object_int_add(json
, "networkMask",
6446 ip_masklen(sl
->mask
));
6447 json_object_int_add(json
, "tos0Metric",
6448 GET_METRIC(sl
->metric
));
6455 /* Show AS-external-LSA detail information. */
6456 static int show_as_external_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6462 struct as_external_lsa
*al
=
6463 (struct as_external_lsa
*)lsa
->data
;
6465 show_ip_ospf_database_header(vty
, lsa
, json
);
6468 vty_out(vty
, " Network Mask: /%d\n",
6469 ip_masklen(al
->mask
));
6470 vty_out(vty
, " Metric Type: %s\n",
6471 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6472 ? "2 (Larger than any link state path)"
6474 vty_out(vty
, " TOS: 0\n");
6475 vty_out(vty
, " Metric: %d\n",
6476 GET_METRIC(al
->e
[0].metric
));
6477 vty_out(vty
, " Forward Address: %pI4\n",
6478 &al
->e
[0].fwd_addr
);
6480 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
6481 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6483 json_object_int_add(json
, "networkMask",
6484 ip_masklen(al
->mask
));
6485 json_object_string_add(
6487 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6488 ? "E2 (Larger than any link state path)"
6490 json_object_int_add(json
, "tos", tos
);
6491 json_object_int_add(json
, "metric",
6492 GET_METRIC(al
->e
[0].metric
));
6493 json_object_string_addf(json
, "forwardAddress", "%pI4",
6494 &(al
->e
[0].fwd_addr
));
6495 json_object_int_add(
6496 json
, "externalRouteTag",
6497 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6504 /* Show AS-NSSA-LSA detail information. */
6505 static int show_as_nssa_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6511 struct as_external_lsa
*al
=
6512 (struct as_external_lsa
*)lsa
->data
;
6514 show_ip_ospf_database_header(vty
, lsa
, json
);
6517 vty_out(vty
, " Network Mask: /%d\n",
6518 ip_masklen(al
->mask
));
6519 vty_out(vty
, " Metric Type: %s\n",
6520 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6521 ? "2 (Larger than any link state path)"
6523 vty_out(vty
, " TOS: 0\n");
6524 vty_out(vty
, " Metric: %d\n",
6525 GET_METRIC(al
->e
[0].metric
));
6526 vty_out(vty
, " NSSA: Forward Address: %pI4\n",
6527 &al
->e
[0].fwd_addr
);
6529 " External Route Tag: %" ROUTE_TAG_PRI
6531 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6533 json_object_int_add(json
, "networkMask",
6534 ip_masklen(al
->mask
));
6535 json_object_string_add(
6537 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6538 ? "E2 (Larger than any link state path)"
6540 json_object_int_add(json
, "tos", tos
);
6541 json_object_int_add(json
, "metric",
6542 GET_METRIC(al
->e
[0].metric
));
6543 json_object_string_addf(json
, "nssaForwardAddress",
6544 "%pI4", &al
->e
[0].fwd_addr
);
6545 json_object_int_add(
6546 json
, "externalRouteTag",
6547 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6554 static int show_func_dummy(struct vty
*vty
, struct ospf_lsa
*lsa
,
6560 static int show_opaque_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6564 show_ip_ospf_database_header(vty
, lsa
, json
);
6565 show_opaque_info_detail(vty
, lsa
, json
);
6572 int (*show_function
[])(struct vty
*, struct ospf_lsa
*, json_object
*) = {
6574 show_router_lsa_detail
,
6575 show_network_lsa_detail
,
6576 show_summary_lsa_detail
,
6577 show_summary_asbr_lsa_detail
,
6578 show_as_external_lsa_detail
,
6580 show_as_nssa_lsa_detail
, /* almost same as external */
6582 show_opaque_lsa_detail
,
6583 show_opaque_lsa_detail
,
6584 show_opaque_lsa_detail
,
6587 static void show_lsa_prefix_set(struct vty
*vty
, struct prefix_ls
*lp
,
6588 struct in_addr
*id
, struct in_addr
*adv_router
)
6590 memset(lp
, 0, sizeof(struct prefix_ls
));
6591 lp
->family
= AF_UNSPEC
;
6594 else if (adv_router
== NULL
) {
6595 lp
->prefixlen
= IPV4_MAX_BITLEN
;
6600 lp
->adv_router
= *adv_router
;
6604 static void show_lsa_detail_proc(struct vty
*vty
, struct route_table
*rt
,
6605 struct in_addr
*id
, struct in_addr
*adv_router
,
6608 struct prefix_ls lp
;
6609 struct route_node
*rn
, *start
;
6610 struct ospf_lsa
*lsa
;
6611 json_object
*json_lsa
= NULL
;
6613 show_lsa_prefix_set(vty
, &lp
, id
, adv_router
);
6614 start
= route_node_get(rt
, (struct prefix
*)&lp
);
6616 route_lock_node(start
);
6617 for (rn
= start
; rn
; rn
= route_next_until(rn
, start
))
6618 if ((lsa
= rn
->info
)) {
6620 json_lsa
= json_object_new_object();
6621 json_object_array_add(json
, json_lsa
);
6624 if (show_function
[lsa
->data
->type
] != NULL
)
6625 show_function
[lsa
->data
->type
](
6626 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 json_lsa_type
= json_object_new_object();
6649 case OSPF_AS_EXTERNAL_LSA
:
6650 case OSPF_OPAQUE_AS_LSA
:
6652 vty_out(vty
, " %s \n\n",
6653 show_database_desc
[type
]);
6655 json_lsa_array
= json_object_new_array();
6657 show_lsa_detail_proc(vty
, AS_LSDB(ospf
, type
), id
, adv_router
,
6660 json_object_object_add(json
,
6661 show_database_desc_json
[type
],
6667 json_areas
= json_object_new_object();
6669 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6672 "\n %s (Area %s)\n\n",
6673 show_database_desc
[type
],
6674 ospf_area_desc_string(area
));
6676 json_lsa_array
= json_object_new_array();
6677 json_object_object_add(json_areas
,
6685 show_lsa_detail_proc(vty
, AREA_LSDB(area
, type
), id
,
6686 adv_router
, json_lsa_array
);
6690 json_object_object_add(json_lsa_type
, "areas",
6692 json_object_object_add(json
,
6693 show_database_desc_json
[type
],
6700 static void show_lsa_detail_adv_router_proc(struct vty
*vty
,
6701 struct route_table
*rt
,
6702 struct in_addr
*adv_router
,
6705 char buf
[PREFIX_STRLEN
];
6706 struct route_node
*rn
;
6707 struct ospf_lsa
*lsa
;
6709 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
))
6710 if ((lsa
= rn
->info
)) {
6711 json_object
*json_lsa
= NULL
;
6713 if (IPV4_ADDR_SAME(adv_router
,
6714 &lsa
->data
->adv_router
)) {
6715 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
6718 json_lsa
= json_object_new_object();
6720 if (show_function
[lsa
->data
->type
] != NULL
)
6721 show_function
[lsa
->data
->type
](
6722 vty
, lsa
, json_lsa
);
6724 json_object_object_add(
6734 /* Show detail LSA information. */
6735 static void show_lsa_detail_adv_router(struct vty
*vty
, struct ospf
*ospf
,
6736 int type
, struct in_addr
*adv_router
,
6739 struct listnode
*node
;
6740 struct ospf_area
*area
;
6741 char buf
[PREFIX_STRLEN
];
6742 json_object
*json_lstype
= NULL
;
6743 json_object
*json_area
= NULL
;
6746 json_lstype
= json_object_new_object();
6749 case OSPF_AS_EXTERNAL_LSA
:
6750 case OSPF_OPAQUE_AS_LSA
:
6752 vty_out(vty
, " %s \n\n",
6753 show_database_desc
[type
]);
6755 show_lsa_detail_adv_router_proc(vty
, AS_LSDB(ospf
, type
),
6756 adv_router
, json_lstype
);
6760 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6762 json_area
= json_object_new_object();
6765 "\n %s (Area %s)\n\n",
6766 show_database_desc
[type
],
6767 ospf_area_desc_string(area
));
6768 show_lsa_detail_adv_router_proc(vty
,
6769 AREA_LSDB(area
, type
),
6770 adv_router
, json_area
);
6773 json_object_object_add(json_lstype
,
6784 json_object_object_add(json
, show_database_desc
[type
],
6788 void show_ip_ospf_database_summary(struct vty
*vty
, struct ospf
*ospf
, int self
,
6791 struct ospf_lsa
*lsa
;
6792 struct route_node
*rn
;
6793 struct ospf_area
*area
;
6794 struct listnode
*node
;
6795 char buf
[PREFIX_STRLEN
];
6796 json_object
*json_areas
= NULL
;
6797 json_object
*json_area
= NULL
;
6798 json_object
*json_lsa
= NULL
;
6800 json_object
*json_lsa_array
= NULL
;
6804 json_areas
= json_object_new_object();
6806 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6808 json_area
= json_object_new_object();
6810 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6813 case OSPF_AS_EXTERNAL_LSA
:
6814 case OSPF_OPAQUE_AS_LSA
:
6819 if (ospf_lsdb_count_self(area
->lsdb
, type
) > 0
6821 && ospf_lsdb_count(area
->lsdb
, type
) > 0)) {
6825 " %s (Area %s)\n\n",
6826 show_database_desc
[type
],
6827 ospf_area_desc_string(area
));
6828 vty_out(vty
, "%s\n",
6829 show_database_header
[type
]);
6832 json_object_new_array();
6833 json_object_object_add(
6835 show_database_desc_json
[type
],
6839 LSDB_LOOP (AREA_LSDB(area
, type
), rn
, lsa
) {
6842 json_object_new_object();
6843 json_object_array_add(
6848 count
+= show_lsa_summary(
6849 vty
, lsa
, self
, json_lsa
);
6855 json_object_int_add(
6858 show_database_desc_count_json
6864 json_object_object_add(json_areas
,
6872 json_object_object_add(json
, "areas", json_areas
);
6874 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6877 case OSPF_AS_EXTERNAL_LSA
:
6878 case OSPF_OPAQUE_AS_LSA
:
6883 if (ospf_lsdb_count_self(ospf
->lsdb
, type
)
6884 || (!self
&& ospf_lsdb_count(ospf
->lsdb
, type
))) {
6886 vty_out(vty
, " %s\n\n",
6887 show_database_desc
[type
]);
6888 vty_out(vty
, "%s\n",
6889 show_database_header
[type
]);
6891 json_lsa_array
= json_object_new_array();
6892 json_object_object_add(
6893 json
, show_database_desc_json
[type
],
6897 LSDB_LOOP (AS_LSDB(ospf
, type
), rn
, lsa
) {
6899 json_lsa
= json_object_new_object();
6900 json_object_array_add(json_lsa_array
,
6904 count
+= show_lsa_summary(vty
, lsa
, self
,
6911 json_object_int_add(
6913 show_database_desc_count_json
[type
],
6922 static void show_ip_ospf_database_maxage(struct vty
*vty
, struct ospf
*ospf
,
6925 struct route_node
*rn
;
6926 char buf
[PREFIX_STRLEN
];
6927 json_object
*json_maxage
= NULL
;
6930 vty_out(vty
, "\n MaxAge Link States:\n\n");
6932 json_maxage
= json_object_new_object();
6934 for (rn
= route_top(ospf
->maxage_lsa
); rn
; rn
= route_next(rn
)) {
6935 struct ospf_lsa
*lsa
;
6936 json_object
*json_lsa
= NULL
;
6938 if ((lsa
= rn
->info
) != NULL
) {
6940 vty_out(vty
, "Link type: %d\n",
6942 vty_out(vty
, "Link State ID: %pI4\n",
6944 vty_out(vty
, "Advertising Router: %pI4\n",
6945 &lsa
->data
->adv_router
);
6946 vty_out(vty
, "LSA lock count: %d\n", lsa
->lock
);
6949 json_lsa
= json_object_new_object();
6950 json_object_int_add(json_lsa
, "linkType",
6952 json_object_string_addf(json_lsa
, "linkStateId",
6953 "%pI4", &lsa
->data
->id
);
6954 json_object_string_addf(
6955 json_lsa
, "advertisingRouter", "%pI4",
6956 &lsa
->data
->adv_router
);
6957 json_object_int_add(json_lsa
, "lsaLockCount",
6959 json_object_object_add(
6969 json_object_object_add(json
, "maxAgeLinkStates", json_maxage
);
6972 #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
6973 #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
6975 #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
6976 #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
6977 #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
6978 #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
6980 #define OSPF_LSA_TYPES_DESC \
6981 "ASBR summary link states\n" \
6982 "External link states\n" \
6983 "Network link states\n" \
6984 "Router link states\n" \
6985 "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \
6986 OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
6987 OSPF_LSA_TYPE_OPAQUE_AS_DESC
6989 static int show_ip_ospf_database_common(struct vty
*vty
, struct ospf
*ospf
,
6990 int arg_base
, int argc
,
6991 struct cmd_token
**argv
,
6992 uint8_t use_vrf
, json_object
*json
,
6997 struct in_addr id
, adv_router
;
6998 json_object
*json_vrf
= NULL
;
7002 json_vrf
= json_object_new_object();
7007 if (ospf
->instance
) {
7009 json_object_int_add(json_vrf
, "ospfInstance",
7012 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
7015 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
7017 /* Show Router ID. */
7019 json_object_string_addf(json_vrf
, "routerId", "%pI4",
7022 vty_out(vty
, "\n OSPF Router with ID (%pI4)\n\n",
7027 if ((argc
== arg_base
+ 4) || (uj
&& (argc
== arg_base
+ 5))) {
7028 show_ip_ospf_database_summary(vty
, ospf
, 0, json_vrf
);
7031 json_object_object_add(
7032 json
, ospf_get_name(ospf
), json_vrf
);
7037 /* Set database type to show. */
7038 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
7039 type
= OSPF_ROUTER_LSA
;
7040 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
7041 type
= OSPF_NETWORK_LSA
;
7042 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
7043 type
= OSPF_AS_NSSA_LSA
;
7044 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "su", 2) == 0)
7045 type
= OSPF_SUMMARY_LSA
;
7046 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
7047 type
= OSPF_ASBR_SUMMARY_LSA
;
7048 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
7049 type
= OSPF_AS_EXTERNAL_LSA
;
7050 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "se", 2) == 0) {
7051 show_ip_ospf_database_summary(vty
, ospf
, 1, json_vrf
);
7054 json_object_object_add(
7055 json
, ospf_get_name(ospf
), json_vrf
);
7058 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "m", 1) == 0) {
7059 show_ip_ospf_database_maxage(vty
, ospf
, json_vrf
);
7062 json_object_object_add(
7063 json
, ospf_get_name(ospf
), json_vrf
);
7066 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
7067 type
= OSPF_OPAQUE_LINK_LSA
;
7068 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
7069 type
= OSPF_OPAQUE_AREA_LSA
;
7070 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
7071 type
= OSPF_OPAQUE_AS_LSA
;
7075 /* `show ip ospf database LSA'. */
7076 if ((argc
== arg_base
+ 5) || (uj
&& (argc
== arg_base
+ 6)))
7077 show_lsa_detail(vty
, ospf
, type
, NULL
, NULL
, json_vrf
);
7078 else if (argc
>= arg_base
+ 6) {
7079 ret
= inet_aton(argv
[arg_base
+ 5]->arg
, &id
);
7083 /* `show ip ospf database LSA ID'. */
7084 if ((argc
== arg_base
+ 6) || (uj
&& (argc
== arg_base
+ 7)))
7085 show_lsa_detail(vty
, ospf
, type
, &id
, NULL
, json_vrf
);
7086 /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */
7087 else if ((argc
== arg_base
+ 7)
7088 || (uj
&& (argc
== arg_base
+ 8))) {
7089 if (strncmp(argv
[arg_base
+ 6]->text
, "s", 1) == 0)
7090 adv_router
= ospf
->router_id
;
7092 ret
= inet_aton(argv
[arg_base
+ 7]->arg
,
7097 show_lsa_detail(vty
, ospf
, type
, &id
, &adv_router
,
7104 json_object_object_add(json
, ospf_get_name(ospf
),
7111 DEFUN (show_ip_ospf_database_max
,
7112 show_ip_ospf_database_max_cmd
,
7113 "show ip ospf [vrf <NAME|all>] database <max-age|self-originate> [json]",
7116 "OSPF information\n"
7119 "Database summary\n"
7120 "LSAs in MaxAge list\n"
7121 "Self-originated link states\n"
7124 struct ospf
*ospf
= NULL
;
7125 struct listnode
*node
= NULL
;
7126 char *vrf_name
= NULL
;
7127 bool all_vrf
= false;
7128 int ret
= CMD_SUCCESS
;
7131 uint8_t use_vrf
= 0;
7132 bool uj
= use_json(argc
, argv
);
7133 json_object
*json
= NULL
;
7136 json
= json_object_new_object();
7138 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
7141 bool ospf_output
= false;
7146 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
7147 if (!ospf
->oi_running
)
7150 ret
= show_ip_ospf_database_common(
7151 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
,
7156 vty_out(vty
, "%% OSPF is not enabled\n");
7158 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
7159 if (ospf
== NULL
|| !ospf
->oi_running
) {
7161 "%% OSPF is not enabled in vrf %s\n",
7165 ret
= (show_ip_ospf_database_common(
7166 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
, use_vrf
,
7170 /* Display default ospf (instance 0) info */
7171 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
7172 if (ospf
== NULL
|| !ospf
->oi_running
) {
7173 vty_out(vty
, "%% OSPF is not enabled in vrf default\n");
7177 ret
= show_ip_ospf_database_common(vty
, ospf
, 0, argc
, argv
,
7182 vty_out(vty
, "%s\n", json_object_to_json_string(json
));
7183 json_object_free(json
);
7189 ALIAS (show_ip_ospf_database_max
,
7190 show_ip_ospf_database_cmd
,
7191 "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]",
7194 "OSPF information\n"
7197 "Database summary\n"
7199 "Link State ID (as an IP address)\n"
7200 "Self-originated link states\n"
7201 "Advertising Router link states\n"
7202 "Advertising Router (as an IP address)\n"
7205 DEFUN (show_ip_ospf_instance_database_max
,
7206 show_ip_ospf_instance_database_max_cmd
,
7207 "show ip ospf (1-65535) database <max-age|self-originate> [json]",
7210 "OSPF information\n"
7212 "Database summary\n"
7213 "LSAs in MaxAge list\n"
7214 "Self-originated link states\n"
7219 unsigned short instance
= 0;
7220 bool uj
= use_json(argc
, argv
);
7221 json_object
*json
= NULL
;
7224 json
= json_object_new_object();
7226 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
7227 if (instance
!= ospf_instance
)
7228 return CMD_NOT_MY_INSTANCE
;
7230 ospf
= ospf_lookup_instance(instance
);
7231 if (!ospf
|| !ospf
->oi_running
)
7234 show_ip_ospf_database_common(vty
, ospf
, 1, argc
, argv
, 0, json
, uj
);
7237 vty_json(vty
, json
);
7242 ALIAS (show_ip_ospf_instance_database_max
,
7243 show_ip_ospf_instance_database_cmd
,
7244 "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]",
7247 "OSPF information\n"
7249 "Database summary\n"
7251 "Link State ID (as an IP address)\n"
7252 "Self-originated link states\n"
7253 "Advertising Router link states\n"
7254 "Advertising Router (as an IP address)\n"
7257 static int show_ip_ospf_database_type_adv_router_common(struct vty
*vty
,
7259 int arg_base
, int argc
,
7260 struct cmd_token
**argv
,
7267 struct in_addr adv_router
;
7268 json_object
*json_vrf
= NULL
;
7272 json_vrf
= json_object_new_object();
7277 if (ospf
->instance
) {
7279 json_object_int_add(json
, "ospfInstance",
7282 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
7285 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
7287 /* Show Router ID. */
7289 json_object_string_addf(json_vrf
, "routerId", "%pI4",
7292 vty_out(vty
, "\n OSPF Router with ID (%pI4)\n\n",
7296 /* Set database type to show. */
7297 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
7298 type
= OSPF_ROUTER_LSA
;
7299 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
7300 type
= OSPF_NETWORK_LSA
;
7301 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
7302 type
= OSPF_AS_NSSA_LSA
;
7303 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "s", 1) == 0)
7304 type
= OSPF_SUMMARY_LSA
;
7305 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
7306 type
= OSPF_ASBR_SUMMARY_LSA
;
7307 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
7308 type
= OSPF_AS_EXTERNAL_LSA
;
7309 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
7310 type
= OSPF_OPAQUE_LINK_LSA
;
7311 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
7312 type
= OSPF_OPAQUE_AREA_LSA
;
7313 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
7314 type
= OSPF_OPAQUE_AS_LSA
;
7318 /* `show ip ospf database LSA adv-router ADV_ROUTER'. */
7319 if (strncmp(argv
[arg_base
+ 5]->text
, "s", 1) == 0)
7320 adv_router
= ospf
->router_id
;
7322 ret
= inet_aton(argv
[arg_base
+ 6]->arg
, &adv_router
);
7327 show_lsa_detail_adv_router(vty
, ospf
, type
, &adv_router
, json_vrf
);
7331 json_object_object_add(json
, ospf_get_name(ospf
),
7338 DEFUN (show_ip_ospf_database_type_adv_router
,
7339 show_ip_ospf_database_type_adv_router_cmd
,
7340 "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]",
7343 "OSPF information\n"
7346 "Database summary\n"
7348 "Advertising Router link states\n"
7349 "Advertising Router (as an IP address)\n"
7350 "Self-originated link states\n"
7353 struct ospf
*ospf
= NULL
;
7354 struct listnode
*node
= NULL
;
7355 char *vrf_name
= NULL
;
7356 bool all_vrf
= false;
7357 int ret
= CMD_SUCCESS
;
7360 uint8_t use_vrf
= 0;
7361 bool uj
= use_json(argc
, argv
);
7362 json_object
*json
= NULL
;
7365 json
= json_object_new_object();
7367 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
7370 bool ospf_output
= false;
7375 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
7376 if (!ospf
->oi_running
)
7379 ret
= show_ip_ospf_database_type_adv_router_common(
7380 vty
, ospf
, 2, argc
, argv
, use_vrf
, json
,
7384 vty_out(vty
, "%% OSPF is not enabled\n");
7386 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
7387 if ((ospf
== NULL
) || !ospf
->oi_running
) {
7389 "%% OSPF is not enabled in vrf %s\n",
7394 ret
= show_ip_ospf_database_type_adv_router_common(
7395 vty
, ospf
, 2, argc
, argv
, use_vrf
, json
, uj
);
7398 /* Display default ospf (instance 0) info */
7399 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
7400 if (ospf
== NULL
|| !ospf
->oi_running
) {
7401 vty_out(vty
, "%% OSPF is not enabled on vrf default\n");
7405 ret
= show_ip_ospf_database_type_adv_router_common(
7406 vty
, ospf
, 0, argc
, argv
, use_vrf
, json
, uj
);
7410 vty_out(vty
, "%s\n", json_object_to_json_string(json
));
7411 json_object_free(json
);
7417 DEFUN (show_ip_ospf_instance_database_type_adv_router
,
7418 show_ip_ospf_instance_database_type_adv_router_cmd
,
7419 "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]",
7422 "OSPF information\n"
7424 "Database summary\n"
7426 "Advertising Router link states\n"
7427 "Advertising Router (as an IP address)\n"
7428 "Self-originated link states\n"
7433 unsigned short instance
= 0;
7434 bool uj
= use_json(argc
, argv
);
7435 json_object
*json
= NULL
;
7438 json
= json_object_new_object();
7440 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
7441 if (instance
!= ospf_instance
)
7442 return CMD_NOT_MY_INSTANCE
;
7444 ospf
= ospf_lookup_instance(instance
);
7445 if (!ospf
|| !ospf
->oi_running
)
7448 show_ip_ospf_database_type_adv_router_common(vty
, ospf
, 1, argc
, argv
,
7452 vty_json(vty
, json
);
7457 DEFUN (ip_ospf_authentication_args
,
7458 ip_ospf_authentication_args_addr_cmd
,
7459 "ip ospf authentication <null|message-digest> [A.B.C.D]",
7461 "OSPF interface commands\n"
7462 "Enable authentication on this interface\n"
7463 "Use null authentication\n"
7464 "Use message-digest authentication\n"
7465 "Address of interface\n")
7467 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7468 int idx_encryption
= 3;
7470 struct in_addr addr
;
7472 struct ospf_if_params
*params
;
7474 params
= IF_DEF_PARAMS(ifp
);
7477 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7480 "Please specify interface address by A.B.C.D\n");
7481 return CMD_WARNING_CONFIG_FAILED
;
7484 params
= ospf_get_if_params(ifp
, addr
);
7485 ospf_if_update_params(ifp
, addr
);
7488 /* Handle null authentication */
7489 if (argv
[idx_encryption
]->arg
[0] == 'n') {
7490 SET_IF_PARAM(params
, auth_type
);
7491 params
->auth_type
= OSPF_AUTH_NULL
;
7495 /* Handle message-digest authentication */
7496 if (argv
[idx_encryption
]->arg
[0] == 'm') {
7497 SET_IF_PARAM(params
, auth_type
);
7498 params
->auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
7502 vty_out(vty
, "You shouldn't get here!\n");
7503 return CMD_WARNING_CONFIG_FAILED
;
7506 DEFUN (ip_ospf_authentication
,
7507 ip_ospf_authentication_addr_cmd
,
7508 "ip ospf authentication [A.B.C.D]",
7510 "OSPF interface commands\n"
7511 "Enable authentication on this interface\n"
7512 "Address of interface\n")
7514 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7516 struct in_addr addr
;
7518 struct ospf_if_params
*params
;
7520 params
= IF_DEF_PARAMS(ifp
);
7523 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7526 "Please specify interface address by A.B.C.D\n");
7527 return CMD_WARNING_CONFIG_FAILED
;
7530 params
= ospf_get_if_params(ifp
, addr
);
7531 ospf_if_update_params(ifp
, addr
);
7534 SET_IF_PARAM(params
, auth_type
);
7535 params
->auth_type
= OSPF_AUTH_SIMPLE
;
7540 DEFUN (no_ip_ospf_authentication_args
,
7541 no_ip_ospf_authentication_args_addr_cmd
,
7542 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
7545 "OSPF interface commands\n"
7546 "Enable authentication on this interface\n"
7547 "Use null authentication\n"
7548 "Use message-digest authentication\n"
7549 "Address of interface\n")
7551 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7552 int idx_encryption
= 4;
7554 struct in_addr addr
;
7556 struct ospf_if_params
*params
;
7557 struct route_node
*rn
;
7560 params
= IF_DEF_PARAMS(ifp
);
7563 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7566 "Please specify interface address by A.B.C.D\n");
7567 return CMD_WARNING_CONFIG_FAILED
;
7570 params
= ospf_lookup_if_params(ifp
, addr
);
7571 if (params
== NULL
) {
7572 vty_out(vty
, "Ip Address specified is unknown\n");
7573 return CMD_WARNING_CONFIG_FAILED
;
7575 params
->auth_type
= OSPF_AUTH_NOTSET
;
7576 UNSET_IF_PARAM(params
, auth_type
);
7577 if (params
!= IF_DEF_PARAMS(ifp
)) {
7578 ospf_free_if_params(ifp
, addr
);
7579 ospf_if_update_params(ifp
, addr
);
7582 if (argv
[idx_encryption
]->arg
[0] == 'n') {
7583 auth_type
= OSPF_AUTH_NULL
;
7584 } else if (argv
[idx_encryption
]->arg
[0] == 'm') {
7585 auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
7587 vty_out(vty
, "Unexpected input encountered\n");
7588 return CMD_WARNING_CONFIG_FAILED
;
7591 * Here we have a case where the user has entered
7592 * 'no ip ospf authentication (null | message_digest )'
7593 * we need to find if we have any ip addresses underneath it
7595 * correspond to the associated type.
7597 if (params
->auth_type
== auth_type
) {
7598 params
->auth_type
= OSPF_AUTH_NOTSET
;
7599 UNSET_IF_PARAM(params
, auth_type
);
7602 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
7603 rn
= route_next(rn
)) {
7604 if ((params
= rn
->info
)) {
7605 if (params
->auth_type
== auth_type
) {
7606 params
->auth_type
= OSPF_AUTH_NOTSET
;
7607 UNSET_IF_PARAM(params
, auth_type
);
7608 if (params
!= IF_DEF_PARAMS(ifp
)) {
7609 ospf_free_if_params(
7610 ifp
, rn
->p
.u
.prefix4
);
7611 ospf_if_update_params(
7612 ifp
, rn
->p
.u
.prefix4
);
7622 DEFUN (no_ip_ospf_authentication
,
7623 no_ip_ospf_authentication_addr_cmd
,
7624 "no ip ospf authentication [A.B.C.D]",
7627 "OSPF interface commands\n"
7628 "Enable authentication on this interface\n"
7629 "Address of interface\n")
7631 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7633 struct in_addr addr
;
7635 struct ospf_if_params
*params
;
7636 struct route_node
*rn
;
7638 params
= IF_DEF_PARAMS(ifp
);
7641 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7644 "Please specify interface address by A.B.C.D\n");
7645 return CMD_WARNING_CONFIG_FAILED
;
7648 params
= ospf_lookup_if_params(ifp
, addr
);
7649 if (params
== NULL
) {
7650 vty_out(vty
, "Ip Address specified is unknown\n");
7651 return CMD_WARNING_CONFIG_FAILED
;
7654 params
->auth_type
= OSPF_AUTH_NOTSET
;
7655 UNSET_IF_PARAM(params
, auth_type
);
7656 if (params
!= IF_DEF_PARAMS(ifp
)) {
7657 ospf_free_if_params(ifp
, addr
);
7658 ospf_if_update_params(ifp
, addr
);
7662 * When a user enters 'no ip ospf authentication'
7663 * We should remove all authentication types from
7666 if ((params
->auth_type
== OSPF_AUTH_NULL
)
7667 || (params
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
7668 || (params
->auth_type
== OSPF_AUTH_SIMPLE
)) {
7669 params
->auth_type
= OSPF_AUTH_NOTSET
;
7670 UNSET_IF_PARAM(params
, auth_type
);
7673 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
7674 rn
= route_next(rn
)) {
7675 if ((params
= rn
->info
)) {
7677 if ((params
->auth_type
== OSPF_AUTH_NULL
)
7678 || (params
->auth_type
7679 == OSPF_AUTH_CRYPTOGRAPHIC
)
7680 || (params
->auth_type
7681 == OSPF_AUTH_SIMPLE
)) {
7682 params
->auth_type
= OSPF_AUTH_NOTSET
;
7683 UNSET_IF_PARAM(params
, auth_type
);
7684 if (params
!= IF_DEF_PARAMS(ifp
)) {
7685 ospf_free_if_params(
7686 ifp
, rn
->p
.u
.prefix4
);
7687 ospf_if_update_params(
7688 ifp
, rn
->p
.u
.prefix4
);
7699 DEFUN (ip_ospf_authentication_key
,
7700 ip_ospf_authentication_key_addr_cmd
,
7701 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
7703 "OSPF interface commands\n"
7704 "Authentication password (key)\n"
7705 "The OSPF password (key)\n"
7706 "Address of interface\n")
7708 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7710 struct in_addr addr
;
7711 struct ospf_if_params
*params
;
7713 params
= IF_DEF_PARAMS(ifp
);
7715 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7716 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7718 "Please specify interface address by A.B.C.D\n");
7719 return CMD_WARNING_CONFIG_FAILED
;
7722 params
= ospf_get_if_params(ifp
, addr
);
7723 ospf_if_update_params(ifp
, addr
);
7726 strlcpy((char *)params
->auth_simple
, argv
[3]->arg
,
7727 sizeof(params
->auth_simple
));
7728 SET_IF_PARAM(params
, auth_simple
);
7733 DEFUN_HIDDEN (ospf_authentication_key
,
7734 ospf_authentication_key_cmd
,
7735 "ospf authentication-key AUTH_KEY [A.B.C.D]",
7736 "OSPF interface commands\n"
7737 VLINK_HELPSTR_AUTH_SIMPLE
7738 "Address of interface\n")
7740 return ip_ospf_authentication_key(self
, vty
, argc
, argv
);
7743 DEFUN (no_ip_ospf_authentication_key
,
7744 no_ip_ospf_authentication_key_authkey_addr_cmd
,
7745 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7748 "OSPF interface commands\n"
7749 VLINK_HELPSTR_AUTH_SIMPLE
7750 "Address of interface\n")
7752 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7754 struct in_addr addr
;
7755 struct ospf_if_params
*params
;
7756 params
= IF_DEF_PARAMS(ifp
);
7758 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7759 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7761 "Please specify interface address by A.B.C.D\n");
7762 return CMD_WARNING_CONFIG_FAILED
;
7765 params
= ospf_lookup_if_params(ifp
, addr
);
7770 memset(params
->auth_simple
, 0, OSPF_AUTH_SIMPLE_SIZE
);
7771 UNSET_IF_PARAM(params
, auth_simple
);
7773 if (params
!= IF_DEF_PARAMS(ifp
)) {
7774 ospf_free_if_params(ifp
, addr
);
7775 ospf_if_update_params(ifp
, addr
);
7781 DEFUN_HIDDEN (no_ospf_authentication_key
,
7782 no_ospf_authentication_key_authkey_addr_cmd
,
7783 "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7785 "OSPF interface commands\n"
7786 VLINK_HELPSTR_AUTH_SIMPLE
7787 "Address of interface\n")
7789 return no_ip_ospf_authentication_key(self
, vty
, argc
, argv
);
7792 DEFUN (ip_ospf_message_digest_key
,
7793 ip_ospf_message_digest_key_cmd
,
7794 "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7796 "OSPF interface commands\n"
7797 "Message digest authentication password (key)\n"
7799 "Use MD5 algorithm\n"
7800 "The OSPF password (key)\n"
7801 "Address of interface\n")
7803 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7804 struct crypt_key
*ck
;
7806 struct in_addr addr
;
7807 struct ospf_if_params
*params
;
7809 params
= IF_DEF_PARAMS(ifp
);
7812 argv_find(argv
, argc
, "(1-255)", &idx
);
7813 char *keyid
= argv
[idx
]->arg
;
7814 argv_find(argv
, argc
, "KEY", &idx
);
7815 char *cryptkey
= argv
[idx
]->arg
;
7817 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7818 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7820 "Please specify interface address by A.B.C.D\n");
7821 return CMD_WARNING_CONFIG_FAILED
;
7824 params
= ospf_get_if_params(ifp
, addr
);
7825 ospf_if_update_params(ifp
, addr
);
7828 key_id
= strtol(keyid
, NULL
, 10);
7830 /* Remove existing key, if any */
7831 ospf_crypt_key_delete(params
->auth_crypt
, key_id
);
7833 ck
= ospf_crypt_key_new();
7834 ck
->key_id
= (uint8_t)key_id
;
7835 strlcpy((char *)ck
->auth_key
, cryptkey
, sizeof(ck
->auth_key
));
7837 ospf_crypt_key_add(params
->auth_crypt
, ck
);
7838 SET_IF_PARAM(params
, auth_crypt
);
7843 DEFUN_HIDDEN (ospf_message_digest_key
,
7844 ospf_message_digest_key_cmd
,
7845 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7846 "OSPF interface commands\n"
7847 "Message digest authentication password (key)\n"
7849 "Use MD5 algorithm\n"
7850 "The OSPF password (key)\n"
7851 "Address of interface\n")
7853 return ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7856 DEFUN (no_ip_ospf_message_digest_key
,
7857 no_ip_ospf_message_digest_key_cmd
,
7858 "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7861 "OSPF interface commands\n"
7862 "Message digest authentication password (key)\n"
7864 "Use MD5 algorithm\n"
7865 "The OSPF password (key)\n"
7866 "Address of interface\n")
7868 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7870 struct crypt_key
*ck
;
7872 struct in_addr addr
;
7873 struct ospf_if_params
*params
;
7874 params
= IF_DEF_PARAMS(ifp
);
7876 argv_find(argv
, argc
, "(1-255)", &idx
);
7877 char *keyid
= argv
[idx
]->arg
;
7879 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7880 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7882 "Please specify interface address by A.B.C.D\n");
7883 return CMD_WARNING_CONFIG_FAILED
;
7886 params
= ospf_lookup_if_params(ifp
, addr
);
7891 key_id
= strtol(keyid
, NULL
, 10);
7892 ck
= ospf_crypt_key_lookup(params
->auth_crypt
, key_id
);
7894 vty_out(vty
, "OSPF: Key %d does not exist\n", key_id
);
7895 return CMD_WARNING_CONFIG_FAILED
;
7898 ospf_crypt_key_delete(params
->auth_crypt
, key_id
);
7900 if (params
!= IF_DEF_PARAMS(ifp
)) {
7901 ospf_free_if_params(ifp
, addr
);
7902 ospf_if_update_params(ifp
, addr
);
7908 DEFUN_HIDDEN (no_ospf_message_digest_key
,
7909 no_ospf_message_digest_key_cmd
,
7910 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7912 "OSPF interface commands\n"
7913 "Message digest authentication password (key)\n"
7915 "Use MD5 algorithm\n"
7916 "The OSPF password (key)\n"
7917 "Address of interface\n")
7919 return no_ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7922 DEFUN (ip_ospf_cost
,
7924 "ip ospf cost (1-65535) [A.B.C.D]",
7926 "OSPF interface commands\n"
7929 "Address of interface\n")
7931 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7933 uint32_t cost
= OSPF_OUTPUT_COST_DEFAULT
;
7934 struct in_addr addr
;
7935 struct ospf_if_params
*params
;
7936 params
= IF_DEF_PARAMS(ifp
);
7939 char *coststr
= NULL
, *ifaddr
= NULL
;
7941 argv_find(argv
, argc
, "(1-65535)", &idx
);
7942 coststr
= argv
[idx
]->arg
;
7943 cost
= strtol(coststr
, NULL
, 10);
7945 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7947 if (!inet_aton(ifaddr
, &addr
)) {
7949 "Please specify interface address by A.B.C.D\n");
7950 return CMD_WARNING_CONFIG_FAILED
;
7953 params
= ospf_get_if_params(ifp
, addr
);
7954 ospf_if_update_params(ifp
, addr
);
7957 SET_IF_PARAM(params
, output_cost_cmd
);
7958 params
->output_cost_cmd
= cost
;
7960 ospf_if_recalculate_output_cost(ifp
);
7965 DEFUN_HIDDEN (ospf_cost
,
7967 "ospf cost (1-65535) [A.B.C.D]",
7968 "OSPF interface commands\n"
7971 "Address of interface\n")
7973 return ip_ospf_cost(self
, vty
, argc
, argv
);
7976 DEFUN (no_ip_ospf_cost
,
7977 no_ip_ospf_cost_cmd
,
7978 "no ip ospf cost [(1-65535)] [A.B.C.D]",
7981 "OSPF interface commands\n"
7984 "Address of interface\n")
7986 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7988 struct in_addr addr
;
7989 struct ospf_if_params
*params
;
7991 params
= IF_DEF_PARAMS(ifp
);
7994 char *ifaddr
= NULL
;
7995 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7997 /* According to the semantics we are mimicking "no ip ospf cost N" is
7998 * always treated as "no ip ospf cost" regardless of the actual value
7999 * of N already configured for the interface. Thus ignore cost. */
8002 if (!inet_aton(ifaddr
, &addr
)) {
8004 "Please specify interface address by A.B.C.D\n");
8005 return CMD_WARNING_CONFIG_FAILED
;
8008 params
= ospf_lookup_if_params(ifp
, addr
);
8013 UNSET_IF_PARAM(params
, output_cost_cmd
);
8015 if (params
!= IF_DEF_PARAMS(ifp
)) {
8016 ospf_free_if_params(ifp
, addr
);
8017 ospf_if_update_params(ifp
, addr
);
8020 ospf_if_recalculate_output_cost(ifp
);
8025 DEFUN_HIDDEN (no_ospf_cost
,
8027 "no ospf cost [(1-65535)] [A.B.C.D]",
8029 "OSPF interface commands\n"
8032 "Address of interface\n")
8034 return no_ip_ospf_cost(self
, vty
, argc
, argv
);
8037 static void ospf_nbr_timer_update(struct ospf_interface
*oi
)
8039 struct route_node
*rn
;
8040 struct ospf_neighbor
*nbr
;
8042 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
8048 nbr
->v_inactivity
= OSPF_IF_PARAM(oi
, v_wait
);
8049 nbr
->v_db_desc
= OSPF_IF_PARAM(oi
, retransmit_interval
);
8050 nbr
->v_ls_req
= OSPF_IF_PARAM(oi
, retransmit_interval
);
8051 nbr
->v_ls_upd
= OSPF_IF_PARAM(oi
, retransmit_interval
);
8055 static int ospf_vty_dead_interval_set(struct vty
*vty
, const char *interval_str
,
8056 const char *nbr_str
,
8057 const char *fast_hello_str
)
8059 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8062 struct in_addr addr
;
8064 struct ospf_if_params
*params
;
8065 struct ospf_interface
*oi
;
8066 struct route_node
*rn
;
8068 params
= IF_DEF_PARAMS(ifp
);
8071 ret
= inet_aton(nbr_str
, &addr
);
8074 "Please specify interface address by A.B.C.D\n");
8075 return CMD_WARNING_CONFIG_FAILED
;
8078 params
= ospf_get_if_params(ifp
, addr
);
8079 ospf_if_update_params(ifp
, addr
);
8083 seconds
= strtoul(interval_str
, NULL
, 10);
8085 /* reset fast_hello too, just to be sure */
8086 UNSET_IF_PARAM(params
, fast_hello
);
8087 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
8088 } else if (fast_hello_str
) {
8089 hellomult
= strtoul(fast_hello_str
, NULL
, 10);
8090 /* 1s dead-interval with sub-second hellos desired */
8091 seconds
= OSPF_ROUTER_DEAD_INTERVAL_MINIMAL
;
8092 SET_IF_PARAM(params
, fast_hello
);
8093 params
->fast_hello
= hellomult
;
8096 "Please specify dead-interval or hello-multiplier\n");
8097 return CMD_WARNING_CONFIG_FAILED
;
8100 SET_IF_PARAM(params
, v_wait
);
8101 params
->v_wait
= seconds
;
8102 params
->is_v_wait_set
= true;
8104 /* Update timer values in neighbor structure. */
8106 struct ospf
*ospf
= NULL
;
8108 ospf
= ifp
->vrf
->info
;
8110 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
8112 ospf_nbr_timer_update(oi
);
8115 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
8116 if ((oi
= rn
->info
))
8117 ospf_nbr_timer_update(oi
);
8123 DEFUN (ip_ospf_dead_interval
,
8124 ip_ospf_dead_interval_cmd
,
8125 "ip ospf dead-interval (1-65535) [A.B.C.D]",
8127 "OSPF interface commands\n"
8128 "Interval time after which a neighbor is declared down\n"
8130 "Address of interface\n")
8133 char *interval
= argv_find(argv
, argc
, "(1-65535)", &idx
)
8137 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
8138 return ospf_vty_dead_interval_set(vty
, interval
, ifaddr
, NULL
);
8142 DEFUN_HIDDEN (ospf_dead_interval
,
8143 ospf_dead_interval_cmd
,
8144 "ospf dead-interval (1-65535) [A.B.C.D]",
8145 "OSPF interface commands\n"
8146 "Interval time after which a neighbor is declared down\n"
8148 "Address of interface\n")
8150 return ip_ospf_dead_interval(self
, vty
, argc
, argv
);
8153 DEFUN (ip_ospf_dead_interval_minimal
,
8154 ip_ospf_dead_interval_minimal_addr_cmd
,
8155 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
8157 "OSPF interface commands\n"
8158 "Interval time after which a neighbor is declared down\n"
8159 "Minimal 1s dead-interval with fast sub-second hellos\n"
8160 "Hello multiplier factor\n"
8161 "Number of Hellos to send each second\n"
8162 "Address of interface\n")
8167 return ospf_vty_dead_interval_set(
8168 vty
, NULL
, argv
[idx_ipv4
]->arg
, argv
[idx_number
]->arg
);
8170 return ospf_vty_dead_interval_set(vty
, NULL
, NULL
,
8171 argv
[idx_number
]->arg
);
8174 DEFUN (no_ip_ospf_dead_interval
,
8175 no_ip_ospf_dead_interval_cmd
,
8176 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8179 "OSPF interface commands\n"
8180 "Interval time after which a neighbor is declared down\n"
8182 "Minimal 1s dead-interval with fast sub-second hellos\n"
8183 "Hello multiplier factor\n"
8184 "Number of Hellos to send each second\n"
8185 "Address of interface\n")
8187 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8188 int idx_ipv4
= argc
- 1;
8189 struct in_addr addr
= {.s_addr
= 0L};
8191 struct ospf_if_params
*params
;
8192 struct ospf_interface
*oi
;
8193 struct route_node
*rn
;
8195 params
= IF_DEF_PARAMS(ifp
);
8197 if (argv
[idx_ipv4
]->type
== IPV4_TKN
) {
8198 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8201 "Please specify interface address by A.B.C.D\n");
8202 return CMD_WARNING_CONFIG_FAILED
;
8205 params
= ospf_lookup_if_params(ifp
, addr
);
8210 UNSET_IF_PARAM(params
, v_wait
);
8211 params
->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
8212 params
->is_v_wait_set
= false;
8214 UNSET_IF_PARAM(params
, fast_hello
);
8215 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
8217 if (params
!= IF_DEF_PARAMS(ifp
)) {
8218 ospf_free_if_params(ifp
, addr
);
8219 ospf_if_update_params(ifp
, addr
);
8222 /* Update timer values in neighbor structure. */
8224 struct ospf
*ospf
= NULL
;
8226 ospf
= ifp
->vrf
->info
;
8228 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
8230 ospf_nbr_timer_update(oi
);
8233 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
8234 if ((oi
= rn
->info
))
8235 ospf_nbr_timer_update(oi
);
8241 DEFUN_HIDDEN (no_ospf_dead_interval
,
8242 no_ospf_dead_interval_cmd
,
8243 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8245 "OSPF interface commands\n"
8246 "Interval time after which a neighbor is declared down\n"
8248 "Minimal 1s dead-interval with fast sub-second hellos\n"
8249 "Hello multiplier factor\n"
8250 "Number of Hellos to send each second\n"
8251 "Address of interface\n")
8253 return no_ip_ospf_dead_interval(self
, vty
, argc
, argv
);
8256 DEFUN (ip_ospf_hello_interval
,
8257 ip_ospf_hello_interval_cmd
,
8258 "ip ospf hello-interval (1-65535) [A.B.C.D]",
8260 "OSPF interface commands\n"
8261 "Time between HELLO packets\n"
8263 "Address of interface\n")
8265 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8267 struct in_addr addr
= {.s_addr
= 0L};
8268 struct ospf_if_params
*params
;
8269 params
= IF_DEF_PARAMS(ifp
);
8270 uint32_t seconds
= 0;
8271 bool is_addr
= false;
8272 uint32_t old_interval
= 0;
8274 argv_find(argv
, argc
, "(1-65535)", &idx
);
8275 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
8277 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8278 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8280 "Please specify interface address by A.B.C.D\n");
8281 return CMD_WARNING_CONFIG_FAILED
;
8284 params
= ospf_get_if_params(ifp
, addr
);
8285 ospf_if_update_params(ifp
, addr
);
8289 old_interval
= params
->v_hello
;
8291 /* Return, if same interval is configured. */
8292 if (old_interval
== seconds
)
8295 SET_IF_PARAM(params
, v_hello
);
8296 params
->v_hello
= seconds
;
8298 if (!params
->is_v_wait_set
) {
8299 SET_IF_PARAM(params
, v_wait
);
8301 * The router dead interval should
8302 * be some multiple of the HelloInterval (perhaps 4 times the
8303 * hello interval) and must be the same for all routers
8304 * attached to a common network.
8306 params
->v_wait
= 4 * seconds
;
8309 ospf_reset_hello_timer(ifp
, addr
, is_addr
);
8314 DEFUN_HIDDEN (ospf_hello_interval
,
8315 ospf_hello_interval_cmd
,
8316 "ospf hello-interval (1-65535) [A.B.C.D]",
8317 "OSPF interface commands\n"
8318 "Time between HELLO packets\n"
8320 "Address of interface\n")
8322 return ip_ospf_hello_interval(self
, vty
, argc
, argv
);
8325 DEFUN (no_ip_ospf_hello_interval
,
8326 no_ip_ospf_hello_interval_cmd
,
8327 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
8330 "OSPF interface commands\n"
8331 "Time between HELLO packets\n" // ignored
8333 "Address of interface\n")
8335 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8337 struct in_addr addr
= {.s_addr
= 0L};
8338 struct ospf_if_params
*params
;
8339 struct route_node
*rn
;
8341 params
= IF_DEF_PARAMS(ifp
);
8343 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8344 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8346 "Please specify interface address by A.B.C.D\n");
8347 return CMD_WARNING_CONFIG_FAILED
;
8350 params
= ospf_lookup_if_params(ifp
, addr
);
8355 UNSET_IF_PARAM(params
, v_hello
);
8356 params
->v_hello
= OSPF_HELLO_INTERVAL_DEFAULT
;
8358 if (!params
->is_v_wait_set
) {
8359 UNSET_IF_PARAM(params
, v_wait
);
8360 params
->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
8363 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8364 struct ospf_interface
*oi
= rn
->info
;
8369 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
8370 oi
->ptp_dmvpn
= IF_DEF_PARAMS(ifp
)->ptp_dmvpn
;
8372 if (oi
->state
> ISM_Down
) {
8373 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
8374 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
8378 if (params
!= IF_DEF_PARAMS(ifp
)) {
8379 ospf_free_if_params(ifp
, addr
);
8380 ospf_if_update_params(ifp
, addr
);
8386 DEFUN_HIDDEN (no_ospf_hello_interval
,
8387 no_ospf_hello_interval_cmd
,
8388 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
8390 "OSPF interface commands\n"
8391 "Time between HELLO packets\n" // ignored
8393 "Address of interface\n")
8395 return no_ip_ospf_hello_interval(self
, vty
, argc
, argv
);
8398 DEFUN(ip_ospf_network
, ip_ospf_network_cmd
,
8399 "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point [dmvpn]>",
8401 "OSPF interface commands\n"
8403 "Specify OSPF broadcast multi-access network\n"
8404 "Specify OSPF NBMA network\n"
8405 "Specify OSPF point-to-multipoint network\n"
8406 "Specify OSPF point-to-point network\n"
8407 "Specify OSPF point-to-point DMVPN network\n")
8409 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8411 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
8412 uint8_t old_ptp_dmvpn
= IF_DEF_PARAMS(ifp
)->ptp_dmvpn
;
8413 struct route_node
*rn
;
8415 if (old_type
== OSPF_IFTYPE_LOOPBACK
) {
8417 "This is a loopback interface. Can't set network type.\n");
8418 return CMD_WARNING_CONFIG_FAILED
;
8421 IF_DEF_PARAMS(ifp
)->ptp_dmvpn
= 0;
8423 if (argv_find(argv
, argc
, "broadcast", &idx
))
8424 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_BROADCAST
;
8425 else if (argv_find(argv
, argc
, "non-broadcast", &idx
))
8426 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_NBMA
;
8427 else if (argv_find(argv
, argc
, "point-to-multipoint", &idx
))
8428 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOMULTIPOINT
;
8429 else if (argv_find(argv
, argc
, "point-to-point", &idx
)) {
8430 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOPOINT
;
8431 if (argv_find(argv
, argc
, "dmvpn", &idx
))
8432 IF_DEF_PARAMS(ifp
)->ptp_dmvpn
= 1;
8435 if (IF_DEF_PARAMS(ifp
)->type
== old_type
8436 && IF_DEF_PARAMS(ifp
)->ptp_dmvpn
== old_ptp_dmvpn
)
8439 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), type
);
8441 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8442 struct ospf_interface
*oi
= rn
->info
;
8447 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
8449 if (oi
->state
> ISM_Down
) {
8450 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
8451 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
8458 DEFUN_HIDDEN (ospf_network
,
8460 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
8461 "OSPF interface commands\n"
8463 "Specify OSPF broadcast multi-access network\n"
8464 "Specify OSPF NBMA network\n"
8465 "Specify OSPF point-to-multipoint network\n"
8466 "Specify OSPF point-to-point network\n")
8468 return ip_ospf_network(self
, vty
, argc
, argv
);
8471 DEFUN (no_ip_ospf_network
,
8472 no_ip_ospf_network_cmd
,
8473 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8476 "OSPF interface commands\n"
8478 "Specify OSPF broadcast multi-access network\n"
8479 "Specify OSPF NBMA network\n"
8480 "Specify OSPF point-to-multipoint network\n"
8481 "Specify OSPF point-to-point network\n")
8483 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8484 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
8485 struct route_node
*rn
;
8487 IF_DEF_PARAMS(ifp
)->type
= ospf_default_iftype(ifp
);
8488 IF_DEF_PARAMS(ifp
)->ptp_dmvpn
= 0;
8490 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
8493 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8494 struct ospf_interface
*oi
= rn
->info
;
8499 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
8501 if (oi
->state
> ISM_Down
) {
8502 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
8503 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
8510 DEFUN_HIDDEN (no_ospf_network
,
8511 no_ospf_network_cmd
,
8512 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8514 "OSPF interface commands\n"
8516 "Specify OSPF broadcast multi-access network\n"
8517 "Specify OSPF NBMA network\n"
8518 "Specify OSPF point-to-multipoint network\n"
8519 "Specify OSPF point-to-point network\n")
8521 return no_ip_ospf_network(self
, vty
, argc
, argv
);
8524 DEFUN (ip_ospf_priority
,
8525 ip_ospf_priority_cmd
,
8526 "ip ospf priority (0-255) [A.B.C.D]",
8528 "OSPF interface commands\n"
8531 "Address of interface\n")
8533 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8536 struct route_node
*rn
;
8537 struct in_addr addr
;
8538 struct ospf_if_params
*params
;
8539 params
= IF_DEF_PARAMS(ifp
);
8541 argv_find(argv
, argc
, "(0-255)", &idx
);
8542 priority
= strtol(argv
[idx
]->arg
, NULL
, 10);
8544 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8545 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8547 "Please specify interface address by A.B.C.D\n");
8548 return CMD_WARNING_CONFIG_FAILED
;
8551 params
= ospf_get_if_params(ifp
, addr
);
8552 ospf_if_update_params(ifp
, addr
);
8555 SET_IF_PARAM(params
, priority
);
8556 params
->priority
= priority
;
8558 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8559 struct ospf_interface
*oi
= rn
->info
;
8564 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
8565 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
8566 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
8573 DEFUN_HIDDEN (ospf_priority
,
8575 "ospf priority (0-255) [A.B.C.D]",
8576 "OSPF interface commands\n"
8579 "Address of interface\n")
8581 return ip_ospf_priority(self
, vty
, argc
, argv
);
8584 DEFUN (no_ip_ospf_priority
,
8585 no_ip_ospf_priority_cmd
,
8586 "no ip ospf priority [(0-255) [A.B.C.D]]",
8589 "OSPF interface commands\n"
8590 "Router priority\n" // ignored
8592 "Address of interface\n")
8594 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8596 struct route_node
*rn
;
8597 struct in_addr addr
;
8598 struct ospf_if_params
*params
;
8600 params
= IF_DEF_PARAMS(ifp
);
8602 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8603 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8605 "Please specify interface address by A.B.C.D\n");
8606 return CMD_WARNING_CONFIG_FAILED
;
8609 params
= ospf_lookup_if_params(ifp
, addr
);
8614 UNSET_IF_PARAM(params
, priority
);
8615 params
->priority
= OSPF_ROUTER_PRIORITY_DEFAULT
;
8617 if (params
!= IF_DEF_PARAMS(ifp
)) {
8618 ospf_free_if_params(ifp
, addr
);
8619 ospf_if_update_params(ifp
, addr
);
8622 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8623 struct ospf_interface
*oi
= rn
->info
;
8628 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
8629 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
8630 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
8637 DEFUN_HIDDEN (no_ospf_priority
,
8638 no_ospf_priority_cmd
,
8639 "no ospf priority [(0-255) [A.B.C.D]]",
8641 "OSPF interface commands\n"
8644 "Address of interface\n")
8646 return no_ip_ospf_priority(self
, vty
, argc
, argv
);
8649 DEFUN (ip_ospf_retransmit_interval
,
8650 ip_ospf_retransmit_interval_addr_cmd
,
8651 "ip ospf retransmit-interval (1-65535) [A.B.C.D]",
8653 "OSPF interface commands\n"
8654 "Time between retransmitting lost link state advertisements\n"
8656 "Address of interface\n")
8658 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8661 struct in_addr addr
;
8662 struct ospf_if_params
*params
;
8663 params
= IF_DEF_PARAMS(ifp
);
8665 argv_find(argv
, argc
, "(1-65535)", &idx
);
8666 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
8668 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8669 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8671 "Please specify interface address by A.B.C.D\n");
8672 return CMD_WARNING_CONFIG_FAILED
;
8675 params
= ospf_get_if_params(ifp
, addr
);
8676 ospf_if_update_params(ifp
, addr
);
8679 SET_IF_PARAM(params
, retransmit_interval
);
8680 params
->retransmit_interval
= seconds
;
8685 DEFUN_HIDDEN (ospf_retransmit_interval
,
8686 ospf_retransmit_interval_cmd
,
8687 "ospf retransmit-interval (1-65535) [A.B.C.D]",
8688 "OSPF interface commands\n"
8689 "Time between retransmitting lost link state advertisements\n"
8691 "Address of interface\n")
8693 return ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
8696 DEFUN (no_ip_ospf_retransmit_interval
,
8697 no_ip_ospf_retransmit_interval_addr_cmd
,
8698 "no ip ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8701 "OSPF interface commands\n"
8702 "Time between retransmitting lost link state advertisements\n"
8704 "Address of interface\n")
8706 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8708 struct in_addr addr
;
8709 struct ospf_if_params
*params
;
8711 params
= IF_DEF_PARAMS(ifp
);
8713 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8714 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8716 "Please specify interface address by A.B.C.D\n");
8717 return CMD_WARNING_CONFIG_FAILED
;
8720 params
= ospf_lookup_if_params(ifp
, addr
);
8725 UNSET_IF_PARAM(params
, retransmit_interval
);
8726 params
->retransmit_interval
= OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
8728 if (params
!= IF_DEF_PARAMS(ifp
)) {
8729 ospf_free_if_params(ifp
, addr
);
8730 ospf_if_update_params(ifp
, addr
);
8736 DEFUN_HIDDEN (no_ospf_retransmit_interval
,
8737 no_ospf_retransmit_interval_cmd
,
8738 "no ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8740 "OSPF interface commands\n"
8741 "Time between retransmitting lost link state advertisements\n"
8743 "Address of interface\n")
8745 return no_ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
8748 DEFUN (ip_ospf_transmit_delay
,
8749 ip_ospf_transmit_delay_addr_cmd
,
8750 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
8752 "OSPF interface commands\n"
8753 "Link state transmit delay\n"
8755 "Address of interface\n")
8757 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8760 struct in_addr addr
;
8761 struct ospf_if_params
*params
;
8763 params
= IF_DEF_PARAMS(ifp
);
8764 argv_find(argv
, argc
, "(1-65535)", &idx
);
8765 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
8767 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8768 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8770 "Please specify interface address by A.B.C.D\n");
8771 return CMD_WARNING_CONFIG_FAILED
;
8774 params
= ospf_get_if_params(ifp
, addr
);
8775 ospf_if_update_params(ifp
, addr
);
8778 SET_IF_PARAM(params
, transmit_delay
);
8779 params
->transmit_delay
= seconds
;
8784 DEFUN_HIDDEN (ospf_transmit_delay
,
8785 ospf_transmit_delay_cmd
,
8786 "ospf transmit-delay (1-65535) [A.B.C.D]",
8787 "OSPF interface commands\n"
8788 "Link state transmit delay\n"
8790 "Address of interface\n")
8792 return ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
8795 DEFUN (no_ip_ospf_transmit_delay
,
8796 no_ip_ospf_transmit_delay_addr_cmd
,
8797 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
8800 "OSPF interface commands\n"
8801 "Link state transmit delay\n"
8803 "Address of interface\n")
8805 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8807 struct in_addr addr
;
8808 struct ospf_if_params
*params
;
8810 params
= IF_DEF_PARAMS(ifp
);
8812 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8813 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8815 "Please specify interface address by A.B.C.D\n");
8816 return CMD_WARNING_CONFIG_FAILED
;
8819 params
= ospf_lookup_if_params(ifp
, addr
);
8824 UNSET_IF_PARAM(params
, transmit_delay
);
8825 params
->transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
8827 if (params
!= IF_DEF_PARAMS(ifp
)) {
8828 ospf_free_if_params(ifp
, addr
);
8829 ospf_if_update_params(ifp
, addr
);
8836 DEFUN_HIDDEN (no_ospf_transmit_delay
,
8837 no_ospf_transmit_delay_cmd
,
8838 "no ospf transmit-delay [(1-65535) [A.B.C.D]]",
8840 "OSPF interface commands\n"
8841 "Link state transmit delay\n"
8843 "Address of interface\n")
8845 return no_ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
8848 DEFUN (ip_ospf_area
,
8850 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]",
8852 "OSPF interface commands\n"
8854 "Enable OSPF on this interface\n"
8855 "OSPF area ID in IP address format\n"
8856 "OSPF area ID as a decimal value\n"
8857 "Address of interface\n")
8859 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8862 struct in_addr area_id
;
8863 struct in_addr addr
;
8864 struct ospf_if_params
*params
= NULL
;
8865 struct route_node
*rn
;
8866 struct ospf
*ospf
= NULL
;
8867 unsigned short instance
= 0;
8871 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
8872 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
8874 argv_find(argv
, argc
, "area", &idx
);
8875 areaid
= argv
[idx
+ 1]->arg
;
8878 ospf
= ifp
->vrf
->info
;
8880 ospf
= ospf_lookup_instance(instance
);
8882 if (instance
&& instance
!= ospf_instance
) {
8884 * At this point we know we have received
8885 * an instance and there is no ospf instance
8886 * associated with it. This means we are
8887 * in a situation where we have an
8888 * ospf command that is setup for a different
8889 * process(instance). We need to safely
8890 * remove the command from ourselves and
8891 * allow the other instance(process) handle
8892 * the configuration command.
8896 params
= IF_DEF_PARAMS(ifp
);
8897 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8898 UNSET_IF_PARAM(params
, if_area
);
8902 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
; rn
= route_next(rn
))
8903 if ((params
= rn
->info
) && OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8904 UNSET_IF_PARAM(params
, if_area
);
8909 ospf
= ifp
->vrf
->info
;
8911 ospf_interface_area_unset(ospf
, ifp
);
8914 return CMD_NOT_MY_INSTANCE
;
8917 ret
= str2area_id(areaid
, &area_id
, &format
);
8919 vty_out(vty
, "Please specify area by A.B.C.D|<0-4294967295>\n");
8920 return CMD_WARNING_CONFIG_FAILED
;
8922 if (memcmp(ifp
->name
, "VLINK", 5) == 0) {
8923 vty_out(vty
, "Cannot enable OSPF on a virtual link.\n");
8924 return CMD_WARNING_CONFIG_FAILED
;
8928 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
)) {
8929 if (rn
->info
!= NULL
) {
8931 "Please remove all network commands first.\n");
8932 return CMD_WARNING_CONFIG_FAILED
;
8937 params
= IF_DEF_PARAMS(ifp
);
8938 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)
8939 && !IPV4_ADDR_SAME(¶ms
->if_area
, &area_id
)) {
8941 "Must remove previous area config before changing ospf area \n");
8942 return CMD_WARNING_CONFIG_FAILED
;
8945 // Check if we have an address arg and proccess it
8946 if (argc
== idx
+ 3) {
8947 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
8949 "Please specify Intf Address by A.B.C.D\n");
8950 return CMD_WARNING_CONFIG_FAILED
;
8952 // update/create address-level params
8953 params
= ospf_get_if_params((ifp
), (addr
));
8954 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8955 if (!IPV4_ADDR_SAME(¶ms
->if_area
, &area_id
)) {
8957 "Must remove previous area/address config before changing ospf area\n");
8958 return CMD_WARNING_CONFIG_FAILED
;
8962 ospf_if_update_params((ifp
), (addr
));
8965 /* enable ospf on this interface with area_id */
8967 SET_IF_PARAM(params
, if_area
);
8968 params
->if_area
= area_id
;
8969 params
->if_area_id_fmt
= format
;
8973 ospf_interface_area_set(ospf
, ifp
);
8978 DEFUN (no_ip_ospf_area
,
8979 no_ip_ospf_area_cmd
,
8980 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]",
8983 "OSPF interface commands\n"
8985 "Disable OSPF on this interface\n"
8986 "OSPF area ID in IP address format\n"
8987 "OSPF area ID as a decimal value\n"
8988 "Address of interface\n")
8990 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8993 struct ospf_if_params
*params
;
8994 unsigned short instance
= 0;
8995 struct in_addr addr
;
8996 struct in_addr area_id
;
8998 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
8999 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
9002 ospf
= ifp
->vrf
->info
;
9004 ospf
= ospf_lookup_instance(instance
);
9006 if (instance
&& instance
!= ospf_instance
)
9007 return CMD_NOT_MY_INSTANCE
;
9009 argv_find(argv
, argc
, "area", &idx
);
9011 // Check if we have an address arg and proccess it
9012 if (argc
== idx
+ 3) {
9013 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
9015 "Please specify Intf Address by A.B.C.D\n");
9016 return CMD_WARNING_CONFIG_FAILED
;
9018 params
= ospf_lookup_if_params(ifp
, addr
);
9019 if ((params
) == NULL
)
9022 params
= IF_DEF_PARAMS(ifp
);
9024 area_id
= params
->if_area
;
9025 if (!OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
9027 "Can't find specified interface area configuration.\n");
9028 return CMD_WARNING_CONFIG_FAILED
;
9031 UNSET_IF_PARAM(params
, if_area
);
9032 if (params
!= IF_DEF_PARAMS((ifp
))) {
9033 ospf_free_if_params((ifp
), (addr
));
9034 ospf_if_update_params((ifp
), (addr
));
9038 ospf_interface_area_unset(ospf
, ifp
);
9039 ospf_area_check_free(ospf
, area_id
);
9045 DEFUN (ip_ospf_passive
,
9046 ip_ospf_passive_cmd
,
9047 "ip ospf passive [A.B.C.D]",
9049 "OSPF interface commands\n"
9050 "Suppress routing updates on an interface\n"
9051 "Address of interface\n")
9053 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9055 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
9056 struct ospf_if_params
*params
;
9060 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9063 "Please specify interface address by A.B.C.D\n");
9064 return CMD_WARNING_CONFIG_FAILED
;
9066 params
= ospf_get_if_params(ifp
, addr
);
9067 ospf_if_update_params(ifp
, addr
);
9069 params
= IF_DEF_PARAMS(ifp
);
9072 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_PASSIVE
);
9077 DEFUN (no_ip_ospf_passive
,
9078 no_ip_ospf_passive_cmd
,
9079 "no ip ospf passive [A.B.C.D]",
9082 "OSPF interface commands\n"
9083 "Enable routing updates on an interface\n"
9084 "Address of interface\n")
9086 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9088 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
9089 struct ospf_if_params
*params
;
9093 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9096 "Please specify interface address by A.B.C.D\n");
9097 return CMD_WARNING_CONFIG_FAILED
;
9099 params
= ospf_lookup_if_params(ifp
, addr
);
9103 params
= IF_DEF_PARAMS(ifp
);
9106 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_ACTIVE
);
9111 DEFUN (ospf_redistribute_source
,
9112 ospf_redistribute_source_cmd
,
9113 "redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9115 FRR_REDIST_HELP_STR_OSPFD
9116 "Metric for redistributed routes\n"
9117 "OSPF default metric\n"
9118 "OSPF exterior metric type for redistributed routes\n"
9119 "Set OSPF External Type 1/2 metrics\n"
9120 "Route map reference\n"
9121 "Pointer to route-map entries\n")
9123 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9124 int idx_protocol
= 1;
9128 struct ospf_redist
*red
;
9130 bool update
= false;
9132 /* Get distribute source. */
9133 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
9135 return CMD_WARNING_CONFIG_FAILED
;
9137 /* Get metric value. */
9138 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
9139 if (!str2metric(argv
[idx
]->arg
, &metric
))
9140 return CMD_WARNING_CONFIG_FAILED
;
9143 /* Get metric type. */
9144 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
9145 if (!str2metric_type(argv
[idx
]->arg
, &type
))
9146 return CMD_WARNING_CONFIG_FAILED
;
9150 red
= ospf_redist_lookup(ospf
, source
, 0);
9152 red
= ospf_redist_add(ospf
, source
, 0);
9157 if (argv_find(argv
, argc
, "route-map", &idx
)) {
9158 ospf_routemap_set(red
, argv
[idx
+ 1]->arg
);
9160 ospf_routemap_unset(red
);
9163 return ospf_redistribute_update(ospf
, red
, source
, 0, type
,
9166 return ospf_redistribute_set(ospf
, red
, source
, 0, type
,
9170 DEFUN (no_ospf_redistribute_source
,
9171 no_ospf_redistribute_source_cmd
,
9172 "no redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9175 FRR_REDIST_HELP_STR_OSPFD
9176 "Metric for redistributed routes\n"
9177 "OSPF default metric\n"
9178 "OSPF exterior metric type for redistributed routes\n"
9179 "Set OSPF External Type 1/2 metrics\n"
9180 "Route map reference\n"
9181 "Pointer to route-map entries\n")
9183 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9184 int idx_protocol
= 2;
9186 struct ospf_redist
*red
;
9188 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
9190 return CMD_WARNING_CONFIG_FAILED
;
9192 red
= ospf_redist_lookup(ospf
, source
, 0);
9196 ospf_routemap_unset(red
);
9197 ospf_redist_del(ospf
, source
, 0);
9199 return ospf_redistribute_unset(ospf
, source
, 0);
9202 DEFUN (ospf_redistribute_instance_source
,
9203 ospf_redistribute_instance_source_cmd
,
9204 "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9206 "Open Shortest Path First\n"
9207 "Non-main Kernel Routing Table\n"
9208 "Instance ID/Table ID\n"
9209 "Metric for redistributed routes\n"
9210 "OSPF default metric\n"
9211 "OSPF exterior metric type for redistributed routes\n"
9212 "Set OSPF External Type 1/2 metrics\n"
9213 "Route map reference\n"
9214 "Pointer to route-map entries\n")
9216 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9217 int idx_ospf_table
= 1;
9223 unsigned short instance
;
9224 struct ospf_redist
*red
;
9225 bool update
= false;
9227 source
= proto_redistnum(AFI_IP
, argv
[idx_ospf_table
]->text
);
9230 vty_out(vty
, "Unknown instance redistribution\n");
9231 return CMD_WARNING_CONFIG_FAILED
;
9234 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9236 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
9238 "Instance redistribution in non-instanced OSPF not allowed\n");
9239 return CMD_WARNING_CONFIG_FAILED
;
9242 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
9243 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
9244 return CMD_WARNING_CONFIG_FAILED
;
9247 /* Get metric value. */
9248 if (argv_find(argv
, argc
, "metric", &idx
))
9249 if (!str2metric(argv
[idx
+ 1]->arg
, &metric
))
9250 return CMD_WARNING_CONFIG_FAILED
;
9253 /* Get metric type. */
9254 if (argv_find(argv
, argc
, "metric-type", &idx
))
9255 if (!str2metric_type(argv
[idx
+ 1]->arg
, &type
))
9256 return CMD_WARNING_CONFIG_FAILED
;
9258 red
= ospf_redist_lookup(ospf
, source
, instance
);
9260 red
= ospf_redist_add(ospf
, source
, instance
);
9265 if (argv_find(argv
, argc
, "route-map", &idx
))
9266 ospf_routemap_set(red
, argv
[idx
+ 1]->arg
);
9268 ospf_routemap_unset(red
);
9271 return ospf_redistribute_update(ospf
, red
, source
, instance
,
9274 return ospf_redistribute_set(ospf
, red
, source
, instance
, type
,
9278 DEFUN (no_ospf_redistribute_instance_source
,
9279 no_ospf_redistribute_instance_source_cmd
,
9280 "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9283 "Open Shortest Path First\n"
9284 "Non-main Kernel Routing Table\n"
9285 "Instance ID/Table Id\n"
9286 "Metric for redistributed routes\n"
9287 "OSPF default metric\n"
9288 "OSPF exterior metric type for redistributed routes\n"
9289 "Set OSPF External Type 1/2 metrics\n"
9290 "Route map reference\n"
9291 "Pointer to route-map entries\n")
9293 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9294 int idx_ospf_table
= 2;
9296 unsigned int instance
;
9297 struct ospf_redist
*red
;
9300 if (strncmp(argv
[idx_ospf_table
]->arg
, "o", 1) == 0)
9301 source
= ZEBRA_ROUTE_OSPF
;
9303 source
= ZEBRA_ROUTE_TABLE
;
9305 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9307 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
9309 "Instance redistribution in non-instanced OSPF not allowed\n");
9310 return CMD_WARNING_CONFIG_FAILED
;
9313 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
9314 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
9315 return CMD_WARNING_CONFIG_FAILED
;
9318 red
= ospf_redist_lookup(ospf
, source
, instance
);
9322 ospf_routemap_unset(red
);
9323 ospf_redist_del(ospf
, source
, instance
);
9325 return ospf_redistribute_unset(ospf
, source
, instance
);
9328 DEFUN (ospf_distribute_list_out
,
9329 ospf_distribute_list_out_cmd
,
9330 "distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD
,
9331 "Filter networks in routing updates\n"
9332 "Access-list name\n"
9334 FRR_REDIST_HELP_STR_OSPFD
)
9336 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9340 char *proto
= argv
[argc
- 1]->text
;
9342 /* Get distribute source. */
9343 source
= proto_redistnum(AFI_IP
, proto
);
9345 return CMD_WARNING_CONFIG_FAILED
;
9347 return ospf_distribute_list_out_set(ospf
, source
, argv
[idx_word
]->arg
);
9350 DEFUN (no_ospf_distribute_list_out
,
9351 no_ospf_distribute_list_out_cmd
,
9352 "no distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD
,
9354 "Filter networks in routing updates\n"
9355 "Access-list name\n"
9357 FRR_REDIST_HELP_STR_OSPFD
)
9359 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9363 char *proto
= argv
[argc
- 1]->text
;
9364 source
= proto_redistnum(AFI_IP
, proto
);
9366 return CMD_WARNING_CONFIG_FAILED
;
9368 return ospf_distribute_list_out_unset(ospf
, source
,
9369 argv
[idx_word
]->arg
);
9372 /* Default information originate. */
9373 DEFUN (ospf_default_information_originate
,
9374 ospf_default_information_originate_cmd
,
9375 "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9376 "Control distribution of default information\n"
9377 "Distribute a default route\n"
9378 "Always advertise default route\n"
9379 "OSPF default metric\n"
9381 "OSPF metric type for default routes\n"
9382 "Set OSPF External Type 1/2 metrics\n"
9383 "Route map reference\n"
9384 "Pointer to route-map entries\n")
9386 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9387 int default_originate
= DEFAULT_ORIGINATE_ZEBRA
;
9390 struct ospf_redist
*red
;
9392 int cur_originate
= ospf
->default_originate
;
9393 bool sameRtmap
= false;
9396 red
= ospf_redist_add(ospf
, DEFAULT_ROUTE
, 0);
9398 /* Check whether "always" was specified */
9399 if (argv_find(argv
, argc
, "always", &idx
))
9400 default_originate
= DEFAULT_ORIGINATE_ALWAYS
;
9402 /* Get metric value */
9403 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
9404 if (!str2metric(argv
[idx
]->arg
, &metric
))
9405 return CMD_WARNING_CONFIG_FAILED
;
9408 /* Get metric type. */
9409 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
9410 if (!str2metric_type(argv
[idx
]->arg
, &type
))
9411 return CMD_WARNING_CONFIG_FAILED
;
9415 if (argv_find(argv
, argc
, "route-map", &idx
))
9416 rtmap
= argv
[idx
]->arg
+ 1;
9418 /* To check if user is providing same route map */
9419 if ((!rtmap
&& !ROUTEMAP_NAME(red
)) ||
9420 (rtmap
&& ROUTEMAP_NAME(red
) &&
9421 (strcmp(rtmap
, ROUTEMAP_NAME(red
)) == 0)))
9424 /* Don't allow if the same lsa is already originated. */
9426 && (red
->dmetric
.type
== type
)
9427 && (red
->dmetric
.value
== metric
)
9428 && (cur_originate
== default_originate
))
9431 /* Updating Metric details */
9432 red
->dmetric
.type
= type
;
9433 red
->dmetric
.value
= metric
;
9435 /* updating route map details */
9437 ospf_routemap_set(red
, rtmap
);
9439 ospf_routemap_unset(red
);
9441 return ospf_redistribute_default_set(ospf
, default_originate
, type
,
9445 DEFUN (no_ospf_default_information_originate
,
9446 no_ospf_default_information_originate_cmd
,
9447 "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9449 "Control distribution of default information\n"
9450 "Distribute a default route\n"
9451 "Always advertise default route\n"
9452 "OSPF default metric\n"
9454 "OSPF metric type for default routes\n"
9455 "Set OSPF External Type 1/2 metrics\n"
9456 "Route map reference\n"
9457 "Pointer to route-map entries\n")
9459 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9460 struct ospf_redist
*red
;
9462 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
9466 ospf_routemap_unset(red
);
9467 ospf_redist_del(ospf
, DEFAULT_ROUTE
, 0);
9469 return ospf_redistribute_default_set(ospf
, DEFAULT_ORIGINATE_NONE
,
9473 DEFUN (ospf_default_metric
,
9474 ospf_default_metric_cmd
,
9475 "default-metric (0-16777214)",
9476 "Set metric of redistributed routes\n"
9479 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9483 if (!str2metric(argv
[idx_number
]->arg
, &metric
))
9484 return CMD_WARNING_CONFIG_FAILED
;
9486 ospf
->default_metric
= metric
;
9491 DEFUN (no_ospf_default_metric
,
9492 no_ospf_default_metric_cmd
,
9493 "no default-metric [(0-16777214)]",
9495 "Set metric of redistributed routes\n"
9498 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9500 ospf
->default_metric
= -1;
9506 DEFUN (ospf_distance
,
9509 "Administrative distance\n"
9510 "OSPF Administrative distance\n")
9512 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9516 distance
= atoi(argv
[idx_number
]->arg
);
9517 if (ospf
->distance_all
!= distance
) {
9518 ospf
->distance_all
= distance
;
9519 ospf_restart_spf(ospf
);
9525 DEFUN (no_ospf_distance
,
9526 no_ospf_distance_cmd
,
9527 "no distance (1-255)",
9529 "Administrative distance\n"
9530 "OSPF Administrative distance\n")
9532 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9534 if (ospf
->distance_all
) {
9535 ospf
->distance_all
= 0;
9536 ospf_restart_spf(ospf
);
9542 DEFUN (no_ospf_distance_ospf
,
9543 no_ospf_distance_ospf_cmd
,
9544 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
9546 "Administrative distance\n"
9547 "OSPF administrative distance\n"
9548 "Intra-area routes\n"
9549 "Distance for intra-area routes\n"
9550 "Inter-area routes\n"
9551 "Distance for inter-area routes\n"
9553 "Distance for external routes\n")
9555 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9558 if (argv_find(argv
, argc
, "intra-area", &idx
) || argc
== 3)
9559 idx
= ospf
->distance_intra
= 0;
9560 if (argv_find(argv
, argc
, "inter-area", &idx
) || argc
== 3)
9561 idx
= ospf
->distance_inter
= 0;
9562 if (argv_find(argv
, argc
, "external", &idx
) || argc
== 3)
9563 ospf
->distance_external
= 0;
9568 DEFUN (ospf_distance_ospf
,
9569 ospf_distance_ospf_cmd
,
9570 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
9571 "Administrative distance\n"
9572 "OSPF administrative distance\n"
9573 "Intra-area routes\n"
9574 "Distance for intra-area routes\n"
9575 "Inter-area routes\n"
9576 "Distance for inter-area routes\n"
9578 "Distance for external routes\n")
9580 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9583 ospf
->distance_intra
= 0;
9584 ospf
->distance_inter
= 0;
9585 ospf
->distance_external
= 0;
9587 if (argv_find(argv
, argc
, "intra-area", &idx
))
9588 ospf
->distance_intra
= atoi(argv
[idx
+ 1]->arg
);
9590 if (argv_find(argv
, argc
, "inter-area", &idx
))
9591 ospf
->distance_inter
= atoi(argv
[idx
+ 1]->arg
);
9593 if (argv_find(argv
, argc
, "external", &idx
))
9594 ospf
->distance_external
= atoi(argv
[idx
+ 1]->arg
);
9599 DEFUN (ip_ospf_mtu_ignore
,
9600 ip_ospf_mtu_ignore_addr_cmd
,
9601 "ip ospf mtu-ignore [A.B.C.D]",
9603 "OSPF interface commands\n"
9604 "Disable MTU mismatch detection on this interface\n"
9605 "Address of interface\n")
9607 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9609 struct in_addr addr
;
9612 struct ospf_if_params
*params
;
9613 params
= IF_DEF_PARAMS(ifp
);
9616 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9619 "Please specify interface address by A.B.C.D\n");
9620 return CMD_WARNING_CONFIG_FAILED
;
9622 params
= ospf_get_if_params(ifp
, addr
);
9623 ospf_if_update_params(ifp
, addr
);
9625 params
->mtu_ignore
= 1;
9626 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
9627 SET_IF_PARAM(params
, mtu_ignore
);
9629 UNSET_IF_PARAM(params
, mtu_ignore
);
9630 if (params
!= IF_DEF_PARAMS(ifp
)) {
9631 ospf_free_if_params(ifp
, addr
);
9632 ospf_if_update_params(ifp
, addr
);
9638 DEFUN (no_ip_ospf_mtu_ignore
,
9639 no_ip_ospf_mtu_ignore_addr_cmd
,
9640 "no ip ospf mtu-ignore [A.B.C.D]",
9643 "OSPF interface commands\n"
9644 "Disable MTU mismatch detection on this interface\n"
9645 "Address of interface\n")
9647 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9649 struct in_addr addr
;
9652 struct ospf_if_params
*params
;
9653 params
= IF_DEF_PARAMS(ifp
);
9656 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9659 "Please specify interface address by A.B.C.D\n");
9660 return CMD_WARNING_CONFIG_FAILED
;
9662 params
= ospf_get_if_params(ifp
, addr
);
9663 ospf_if_update_params(ifp
, addr
);
9665 params
->mtu_ignore
= 0;
9666 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
9667 SET_IF_PARAM(params
, mtu_ignore
);
9669 UNSET_IF_PARAM(params
, mtu_ignore
);
9670 if (params
!= IF_DEF_PARAMS(ifp
)) {
9671 ospf_free_if_params(ifp
, addr
);
9672 ospf_if_update_params(ifp
, addr
);
9679 DEFUN (ospf_max_metric_router_lsa_admin
,
9680 ospf_max_metric_router_lsa_admin_cmd
,
9681 "max-metric router-lsa administrative",
9682 "OSPF maximum / infinite-distance metric\n"
9683 "Advertise own Router-LSA with infinite distance (stub router)\n"
9684 "Administratively applied, for an indefinite period\n")
9686 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9687 struct listnode
*ln
;
9688 struct ospf_area
*area
;
9690 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
9691 SET_FLAG(area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
);
9693 if (!CHECK_FLAG(area
->stub_router_state
,
9694 OSPF_AREA_IS_STUB_ROUTED
))
9695 ospf_router_lsa_update_area(area
);
9698 /* Allows for areas configured later to get the property */
9699 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
;
9704 DEFUN (no_ospf_max_metric_router_lsa_admin
,
9705 no_ospf_max_metric_router_lsa_admin_cmd
,
9706 "no max-metric router-lsa administrative",
9708 "OSPF maximum / infinite-distance metric\n"
9709 "Advertise own Router-LSA with infinite distance (stub router)\n"
9710 "Administratively applied, for an indefinite period\n")
9712 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9713 struct listnode
*ln
;
9714 struct ospf_area
*area
;
9716 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
9717 UNSET_FLAG(area
->stub_router_state
,
9718 OSPF_AREA_ADMIN_STUB_ROUTED
);
9720 /* Don't trample on the start-up stub timer */
9721 if (CHECK_FLAG(area
->stub_router_state
,
9722 OSPF_AREA_IS_STUB_ROUTED
)
9723 && !area
->t_stub_router
) {
9724 UNSET_FLAG(area
->stub_router_state
,
9725 OSPF_AREA_IS_STUB_ROUTED
);
9726 ospf_router_lsa_update_area(area
);
9729 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET
;
9733 DEFUN (ospf_max_metric_router_lsa_startup
,
9734 ospf_max_metric_router_lsa_startup_cmd
,
9735 "max-metric router-lsa on-startup (5-86400)",
9736 "OSPF maximum / infinite-distance metric\n"
9737 "Advertise own Router-LSA with infinite distance (stub router)\n"
9738 "Automatically advertise stub Router-LSA on startup of OSPF\n"
9739 "Time (seconds) to advertise self as stub-router\n")
9741 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9743 unsigned int seconds
;
9746 vty_out(vty
, "%% Must supply stub-router period\n");
9747 return CMD_WARNING_CONFIG_FAILED
;
9750 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9752 ospf
->stub_router_startup_time
= seconds
;
9757 DEFUN (no_ospf_max_metric_router_lsa_startup
,
9758 no_ospf_max_metric_router_lsa_startup_cmd
,
9759 "no max-metric router-lsa on-startup [(5-86400)]",
9761 "OSPF maximum / infinite-distance metric\n"
9762 "Advertise own Router-LSA with infinite distance (stub router)\n"
9763 "Automatically advertise stub Router-LSA on startup of OSPF\n"
9764 "Time (seconds) to advertise self as stub-router\n")
9766 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9767 struct listnode
*ln
;
9768 struct ospf_area
*area
;
9770 ospf
->stub_router_startup_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
9772 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
9773 SET_FLAG(area
->stub_router_state
,
9774 OSPF_AREA_WAS_START_STUB_ROUTED
);
9775 THREAD_OFF(area
->t_stub_router
);
9777 /* Don't trample on admin stub routed */
9778 if (!CHECK_FLAG(area
->stub_router_state
,
9779 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
9780 UNSET_FLAG(area
->stub_router_state
,
9781 OSPF_AREA_IS_STUB_ROUTED
);
9782 ospf_router_lsa_update_area(area
);
9789 DEFUN (ospf_max_metric_router_lsa_shutdown
,
9790 ospf_max_metric_router_lsa_shutdown_cmd
,
9791 "max-metric router-lsa on-shutdown (5-100)",
9792 "OSPF maximum / infinite-distance metric\n"
9793 "Advertise own Router-LSA with infinite distance (stub router)\n"
9794 "Advertise stub-router prior to full shutdown of OSPF\n"
9795 "Time (seconds) to wait till full shutdown\n")
9797 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9799 unsigned int seconds
;
9802 vty_out(vty
, "%% Must supply stub-router shutdown period\n");
9803 return CMD_WARNING_CONFIG_FAILED
;
9806 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9808 ospf
->stub_router_shutdown_time
= seconds
;
9813 DEFUN (no_ospf_max_metric_router_lsa_shutdown
,
9814 no_ospf_max_metric_router_lsa_shutdown_cmd
,
9815 "no max-metric router-lsa on-shutdown [(5-100)]",
9817 "OSPF maximum / infinite-distance metric\n"
9818 "Advertise own Router-LSA with infinite distance (stub router)\n"
9819 "Advertise stub-router prior to full shutdown of OSPF\n"
9820 "Time (seconds) to wait till full shutdown\n")
9822 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9824 ospf
->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
9829 DEFUN (ospf_proactive_arp
,
9830 ospf_proactive_arp_cmd
,
9832 "Allow sending ARP requests proactively\n")
9834 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9836 ospf
->proactive_arp
= true;
9841 DEFUN (no_ospf_proactive_arp
,
9842 no_ospf_proactive_arp_cmd
,
9845 "Disallow sending ARP requests proactively\n")
9847 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9849 ospf
->proactive_arp
= false;
9854 /* Graceful Restart HELPER Commands */
9855 DEFPY(ospf_gr_helper_enable
, ospf_gr_helper_enable_cmd
,
9856 "graceful-restart helper enable [A.B.C.D$address]",
9857 "OSPF Graceful Restart\n"
9859 "Enable Helper support\n"
9860 "Advertising Router-ID\n")
9862 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9865 ospf_gr_helper_support_set_per_routerid(ospf
, &address
,
9870 ospf_gr_helper_support_set(ospf
, OSPF_GR_TRUE
);
9875 DEFPY(no_ospf_gr_helper_enable
,
9876 no_ospf_gr_helper_enable_cmd
,
9877 "no graceful-restart helper enable [A.B.C.D$address]",
9879 "OSPF Graceful Restart\n"
9881 "Enable Helper support\n"
9882 "Advertising Router-ID\n")
9884 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9887 ospf_gr_helper_support_set_per_routerid(ospf
, &address
,
9892 ospf_gr_helper_support_set(ospf
, OSPF_GR_FALSE
);
9896 DEFPY(ospf_gr_helper_enable_lsacheck
,
9897 ospf_gr_helper_enable_lsacheck_cmd
,
9898 "graceful-restart helper strict-lsa-checking",
9899 "OSPF Graceful Restart\n"
9901 "Enable strict LSA check\n")
9903 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9905 ospf_gr_helper_lsa_check_set(ospf
, OSPF_GR_TRUE
);
9909 DEFPY(no_ospf_gr_helper_enable_lsacheck
,
9910 no_ospf_gr_helper_enable_lsacheck_cmd
,
9911 "no graceful-restart helper strict-lsa-checking",
9913 "OSPF Graceful Restart\n"
9915 "Disable strict LSA check\n")
9917 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9919 ospf_gr_helper_lsa_check_set(ospf
, OSPF_GR_FALSE
);
9923 DEFPY(ospf_gr_helper_supported_grace_time
,
9924 ospf_gr_helper_supported_grace_time_cmd
,
9925 "graceful-restart helper supported-grace-time (10-1800)$interval",
9926 "OSPF Graceful Restart\n"
9928 "Supported grace timer\n"
9929 "Grace interval(in seconds)\n")
9931 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9933 ospf_gr_helper_supported_gracetime_set(ospf
, interval
);
9937 DEFPY(no_ospf_gr_helper_supported_grace_time
,
9938 no_ospf_gr_helper_supported_grace_time_cmd
,
9939 "no graceful-restart helper supported-grace-time (10-1800)$interval",
9941 "OSPF Graceful Restart\n"
9943 "Supported grace timer\n"
9944 "Grace interval(in seconds)\n")
9946 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9948 ospf_gr_helper_supported_gracetime_set(ospf
, OSPF_MAX_GRACE_INTERVAL
);
9952 DEFPY(ospf_gr_helper_planned_only
,
9953 ospf_gr_helper_planned_only_cmd
,
9954 "graceful-restart helper planned-only",
9955 "OSPF Graceful Restart\n"
9957 "Supported only planned restart\n")
9959 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9961 ospf_gr_helper_set_supported_planned_only_restart(ospf
, OSPF_GR_TRUE
);
9966 /* External Route Aggregation */
9967 DEFUN (ospf_external_route_aggregation
,
9968 ospf_external_route_aggregation_cmd
,
9969 "summary-address A.B.C.D/M [tag (1-4294967295)]",
9970 "External summary address\n"
9971 "Summary address prefix\n"
9973 "Router tag value\n")
9975 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9976 struct prefix_ipv4 p
;
9978 route_tag_t tag
= 0;
9979 int ret
= OSPF_SUCCESS
;
9981 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
9983 if (is_default_prefix4(&p
)) {
9985 "Default address shouldn't be configured as summary address.\n");
9989 /* Apply mask for given prefix. */
9992 if (!is_valid_summary_addr(&p
)) {
9993 vty_out(vty
, "Not a valid summary address.\n");
9994 return CMD_WARNING_CONFIG_FAILED
;
9998 tag
= strtoul(argv
[idx
+ 2]->arg
, NULL
, 10);
10000 ret
= ospf_asbr_external_aggregator_set(ospf
, &p
, tag
);
10001 if (ret
== OSPF_INVALID
)
10002 vty_out(vty
, "Invalid configuration!!\n");
10004 return CMD_SUCCESS
;
10007 DEFUN (no_ospf_external_route_aggregation
,
10008 no_ospf_external_route_aggregation_cmd
,
10009 "no summary-address A.B.C.D/M [tag (1-4294967295)]",
10011 "External summary address\n"
10012 "Summary address prefix\n"
10014 "Router tag value\n")
10016 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10017 struct prefix_ipv4 p
;
10019 route_tag_t tag
= 0;
10020 int ret
= OSPF_SUCCESS
;
10022 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
10024 if (is_default_prefix4(&p
)) {
10026 "Default address shouldn't be configured as summary address.\n");
10027 return CMD_SUCCESS
;
10030 /* Apply mask for given prefix. */
10033 if (!is_valid_summary_addr(&p
)) {
10034 vty_out(vty
, "Not a valid summary address.\n");
10035 return CMD_WARNING_CONFIG_FAILED
;
10039 tag
= strtoul(argv
[idx
+ 2]->arg
, NULL
, 10);
10041 ret
= ospf_asbr_external_aggregator_unset(ospf
, &p
, tag
);
10042 if (ret
== OSPF_INVALID
)
10043 vty_out(vty
, "Invalid configuration!!\n");
10045 return CMD_SUCCESS
;
10048 DEFPY(no_ospf_gr_helper_planned_only
,
10049 no_ospf_gr_helper_planned_only_cmd
,
10050 "no graceful-restart helper planned-only",
10052 "OSPF Graceful Restart\n"
10054 "Supported only for planned restart\n")
10056 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10058 ospf_gr_helper_set_supported_planned_only_restart(ospf
, OSPF_GR_FALSE
);
10060 return CMD_SUCCESS
;
10063 static int ospf_print_vty_helper_dis_rtr_walkcb(struct hash_bucket
*bucket
,
10066 struct advRtr
*rtr
= bucket
->data
;
10067 struct vty
*vty
= (struct vty
*)arg
;
10068 static unsigned int count
;
10070 vty_out(vty
, "%-6pI4,", &rtr
->advRtrAddr
);
10073 if (count
% 5 == 0)
10074 vty_out(vty
, "\n");
10076 return HASHWALK_CONTINUE
;
10079 static int ospf_print_json_helper_enabled_rtr_walkcb(struct hash_bucket
*bucket
,
10082 struct advRtr
*rtr
= bucket
->data
;
10083 struct json_object
*json_rid_array
= arg
;
10084 struct json_object
*json_rid
;
10086 json_rid
= json_object_new_object();
10088 json_object_string_addf(json_rid
, "routerId", "%pI4", &rtr
->advRtrAddr
);
10089 json_object_array_add(json_rid_array
, json_rid
);
10091 return HASHWALK_CONTINUE
;
10094 static int ospf_show_gr_helper_details(struct vty
*vty
, struct ospf
*ospf
,
10095 uint8_t use_vrf
, json_object
*json
,
10096 bool uj
, bool detail
)
10098 struct listnode
*node
;
10099 struct ospf_interface
*oi
;
10100 char buf
[PREFIX_STRLEN
];
10101 json_object
*json_vrf
= NULL
;
10105 json_vrf
= json_object_new_object();
10110 if (ospf
->instance
) {
10112 json_object_int_add(json
, "ospfInstance",
10115 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
10118 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
10122 json_object_object_add(json
, ospf_get_name(ospf
),
10125 vty_out(vty
, "\n");
10127 /* Show Router ID. */
10129 json_object_string_add(json_vrf
, "routerId",
10130 inet_ntop(AF_INET
, &ospf
->router_id
,
10131 buf
, sizeof(buf
)));
10133 vty_out(vty
, "\n OSPF Router with ID (%pI4)\n\n",
10139 if (ospf
->is_helper_supported
)
10141 " Graceful restart helper support enabled.\n");
10144 " Graceful restart helper support disabled.\n");
10146 if (ospf
->strict_lsa_check
)
10147 vty_out(vty
, " Strict LSA check is enabled.\n");
10149 vty_out(vty
, " Strict LSA check is disabled.\n");
10151 if (ospf
->only_planned_restart
)
10153 " Helper supported for planned restarts only.\n");
10156 " Helper supported for Planned and Unplanned Restarts.\n");
10159 " Supported Graceful restart interval: %d(in seconds).\n",
10160 ospf
->supported_grace_time
);
10162 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf
)) {
10163 vty_out(vty
, " Enable Router list:\n");
10165 hash_walk(ospf
->enable_rtr_list
,
10166 ospf_print_vty_helper_dis_rtr_walkcb
, vty
);
10167 vty_out(vty
, "\n\n");
10170 if (ospf
->last_exit_reason
!= OSPF_GR_HELPER_EXIT_NONE
) {
10171 vty_out(vty
, " Last Helper exit Reason :%s\n",
10172 ospf_exit_reason2str(ospf
->last_exit_reason
));
10175 if (ospf
->active_restarter_cnt
)
10177 " Number of Active neighbours in graceful restart: %d\n",
10178 ospf
->active_restarter_cnt
);
10180 vty_out(vty
, "\n");
10183 json_object_string_add(
10184 json_vrf
, "helperSupport",
10185 (ospf
->is_helper_supported
) ? "Enabled" : "Disabled");
10186 json_object_string_add(json_vrf
, "strictLsaCheck",
10187 (ospf
->strict_lsa_check
) ? "Enabled"
10189 json_object_string_add(
10190 json_vrf
, "restartSupoort",
10191 (ospf
->only_planned_restart
)
10192 ? "Planned Restart only"
10193 : "Planned and Unplanned Restarts");
10195 json_object_int_add(json_vrf
, "supportedGracePeriod",
10196 ospf
->supported_grace_time
);
10198 #if CONFDATE > 20230131
10199 CPP_NOTICE("Remove JSON object commands with keys starting with capital")
10201 if (ospf
->last_exit_reason
!= OSPF_GR_HELPER_EXIT_NONE
) {
10202 json_object_string_add(
10203 json_vrf
, "LastExitReason",
10204 ospf_exit_reason2str(ospf
->last_exit_reason
));
10205 json_object_string_add(
10206 json_vrf
, "lastExitReason",
10207 ospf_exit_reason2str(ospf
->last_exit_reason
));
10210 if (ospf
->active_restarter_cnt
)
10211 json_object_int_add(json_vrf
, "activeRestarterCnt",
10212 ospf
->active_restarter_cnt
);
10214 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf
)) {
10215 struct json_object
*json_rid_array
=
10216 json_object_new_array();
10218 json_object_object_add(json_vrf
, "enabledRouterIds",
10221 hash_walk(ospf
->enable_rtr_list
,
10222 ospf_print_json_helper_enabled_rtr_walkcb
,
10230 json_object
*json_neighbors
= NULL
;
10232 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
10233 struct route_node
*rn
;
10234 struct ospf_neighbor
*nbr
;
10235 json_object
*json_neigh
;
10237 if (ospf_interface_neighbor_count(oi
) == 0)
10241 json_object_object_get_ex(json_vrf
, "Neighbors",
10243 json_object_object_get_ex(json_vrf
, "neighbors",
10245 if (!json_neighbors
) {
10247 json_object_new_object();
10248 json_object_object_add(json_vrf
,
10251 json_object_object_add(json_vrf
,
10257 for (rn
= route_top(oi
->nbrs
); rn
;
10258 rn
= route_next(rn
)) {
10265 if (!OSPF_GR_IS_ACTIVE_HELPER(nbr
))
10269 vty_out(vty
, " Neighbour %d :\n", cnt
);
10270 vty_out(vty
, " Address : %pI4\n",
10271 &nbr
->address
.u
.prefix4
);
10272 vty_out(vty
, " Routerid : %pI4\n",
10275 " Received Grace period : %d(in seconds).\n",
10276 nbr
->gr_helper_info
10277 .recvd_grace_period
);
10279 " Actual Grace period : %d(in seconds)\n",
10280 nbr
->gr_helper_info
10281 .actual_grace_period
);
10283 " Remaining GraceTime:%ld(in seconds).\n",
10284 thread_timer_remain_second(
10285 nbr
->gr_helper_info
10288 " Graceful Restart reason: %s.\n\n",
10289 ospf_restart_reason2str(
10290 nbr
->gr_helper_info
10291 .gr_restart_reason
));
10294 json_neigh
= json_object_new_object();
10295 json_object_string_add(
10296 json_neigh
, "srcAddr",
10297 inet_ntop(AF_INET
, &nbr
->src
,
10298 buf
, sizeof(buf
)));
10300 json_object_string_add(
10301 json_neigh
, "routerid",
10304 buf
, sizeof(buf
)));
10305 json_object_int_add(
10307 "recvdGraceInterval",
10308 nbr
->gr_helper_info
10309 .recvd_grace_period
);
10310 json_object_int_add(
10312 "actualGraceInterval",
10313 nbr
->gr_helper_info
10314 .actual_grace_period
);
10315 json_object_int_add(
10316 json_neigh
, "remainGracetime",
10317 thread_timer_remain_second(
10318 nbr
->gr_helper_info
10320 json_object_string_add(
10321 json_neigh
, "restartReason",
10322 ospf_restart_reason2str(
10323 nbr
->gr_helper_info
10324 .gr_restart_reason
));
10325 json_object_object_add(
10327 inet_ntop(AF_INET
, &nbr
->src
,
10334 return CMD_SUCCESS
;
10337 DEFUN (ospf_external_route_aggregation_no_adrvertise
,
10338 ospf_external_route_aggregation_no_adrvertise_cmd
,
10339 "summary-address A.B.C.D/M no-advertise",
10340 "External summary address\n"
10341 "Summary address prefix\n"
10342 "Don't advertise summary route \n")
10344 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10345 struct prefix_ipv4 p
;
10347 int ret
= OSPF_SUCCESS
;
10349 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
10351 if (is_default_prefix4(&p
)) {
10353 "Default address shouldn't be configured as summary address.\n");
10354 return CMD_SUCCESS
;
10357 /* Apply mask for given prefix. */
10360 if (!is_valid_summary_addr(&p
)) {
10361 vty_out(vty
, "Not a valid summary address.\n");
10362 return CMD_WARNING_CONFIG_FAILED
;
10365 ret
= ospf_asbr_external_rt_no_advertise(ospf
, &p
);
10366 if (ret
== OSPF_INVALID
)
10367 vty_out(vty
, "Invalid configuration!!\n");
10369 return CMD_SUCCESS
;
10372 DEFUN (no_ospf_external_route_aggregation_no_adrvertise
,
10373 no_ospf_external_route_aggregation_no_adrvertise_cmd
,
10374 "no summary-address A.B.C.D/M no-advertise",
10376 "External summary address\n"
10377 "Summary address prefix\n"
10378 "Advertise summary route to the AS \n")
10380 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10381 struct prefix_ipv4 p
;
10383 int ret
= OSPF_SUCCESS
;
10385 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
10387 if (is_default_prefix4(&p
)) {
10389 "Default address shouldn't be configured as summary address.\n");
10390 return CMD_SUCCESS
;
10393 /* Apply mask for given prefix. */
10396 if (!is_valid_summary_addr(&p
)) {
10397 vty_out(vty
, "Not a valid summary address.\n");
10398 return CMD_WARNING_CONFIG_FAILED
;
10401 ret
= ospf_asbr_external_rt_advertise(ospf
, &p
);
10402 if (ret
== OSPF_INVALID
)
10403 vty_out(vty
, "Invalid configuration!!\n");
10405 return CMD_SUCCESS
;
10408 DEFUN (ospf_route_aggregation_timer
,
10409 ospf_route_aggregation_timer_cmd
,
10410 "aggregation timer (5-1800)",
10411 "External route aggregation\n"
10412 "Delay timer (in seconds)\n"
10413 "Timer interval(in seconds)\n")
10415 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10416 uint16_t interval
= 0;
10418 interval
= strtoul(argv
[2]->arg
, NULL
, 10);
10420 ospf_external_aggregator_timer_set(ospf
, interval
);
10422 return CMD_SUCCESS
;
10425 DEFPY (show_ip_ospf_gr_helper
,
10426 show_ip_ospf_gr_helper_cmd
,
10427 "show ip ospf [vrf <NAME|all>] graceful-restart helper [detail] [json]",
10430 "OSPF information\n"
10433 "OSPF Graceful Restart\n"
10434 "Helper details in the router\n"
10435 "Detailed information\n"
10438 char *vrf_name
= NULL
;
10439 bool all_vrf
= false;
10440 int ret
= CMD_SUCCESS
;
10443 uint8_t use_vrf
= 0;
10444 bool uj
= use_json(argc
, argv
);
10445 struct ospf
*ospf
= NULL
;
10446 json_object
*json
= NULL
;
10447 struct listnode
*node
= NULL
;
10449 bool detail
= false;
10451 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
10453 if (argv_find(argv
, argc
, "detail", &idx
))
10457 json
= json_object_new_object();
10459 /* vrf input is provided */
10464 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
10465 if (!ospf
->oi_running
)
10468 ret
= ospf_show_gr_helper_details(
10469 vty
, ospf
, use_vrf
, json
, uj
, detail
);
10473 vty_json(vty
, json
);
10478 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
10480 if (ospf
== NULL
|| !ospf
->oi_running
) {
10483 vty_json(vty
, json
);
10486 "%% OSPF is not enabled in vrf %s\n",
10489 return CMD_SUCCESS
;
10494 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
10496 if (ospf
== NULL
|| !ospf
->oi_running
) {
10499 vty_json(vty
, json
);
10502 "%% OSPF is not enabled in vrf default\n");
10504 return CMD_SUCCESS
;
10507 ospf_show_gr_helper_details(vty
, ospf
, use_vrf
, json
, uj
,
10512 vty_json(vty
, json
);
10514 return CMD_SUCCESS
;
10516 /* Graceful Restart HELPER commands end */
10517 DEFUN (no_ospf_route_aggregation_timer
,
10518 no_ospf_route_aggregation_timer_cmd
,
10519 "no aggregation timer",
10521 "External route aggregation\n"
10524 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10526 ospf_external_aggregator_timer_set(ospf
, OSPF_EXTL_AGGR_DEFAULT_DELAY
);
10528 return CMD_SUCCESS
;
10531 /* External Route Aggregation End */
10533 static void config_write_stub_router(struct vty
*vty
, struct ospf
*ospf
)
10535 struct listnode
*ln
;
10536 struct ospf_area
*area
;
10538 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
10539 vty_out(vty
, " max-metric router-lsa on-startup %u\n",
10540 ospf
->stub_router_startup_time
);
10541 if (ospf
->stub_router_shutdown_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
10542 vty_out(vty
, " max-metric router-lsa on-shutdown %u\n",
10543 ospf
->stub_router_shutdown_time
);
10544 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
10545 if (CHECK_FLAG(area
->stub_router_state
,
10546 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
10547 vty_out(vty
, " max-metric router-lsa administrative\n");
10554 #if CONFDATE > 20230131
10555 CPP_NOTICE("Remove JSON object commands with keys containing whitespaces")
10557 static void show_ip_ospf_route_network(struct vty
*vty
, struct ospf
*ospf
,
10558 struct route_table
*rt
,
10561 struct route_node
*rn
;
10562 struct ospf_route
* or ;
10563 struct listnode
*pnode
, *pnnode
;
10564 struct ospf_path
*path
;
10565 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
10566 *json_nexthop
= NULL
;
10570 "============ OSPF network routing table ============\n");
10572 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
10573 char buf1
[PREFIX2STR_BUFFER
];
10575 if ((or = rn
->info
) == NULL
)
10578 prefix2str(&rn
->p
, buf1
, sizeof(buf1
));
10581 json_route
= json_object_new_object();
10582 json_object_object_add(json
, buf1
, json_route
);
10585 switch (or->path_type
) {
10586 case OSPF_PATH_INTER_AREA
:
10587 if (or->type
== OSPF_DESTINATION_NETWORK
) {
10589 json_object_string_add(json_route
,
10592 json_object_int_add(json_route
, "cost",
10594 json_object_string_addf(
10595 json_route
, "area", "%pI4",
10596 &or->u
.std
.area_id
);
10599 "N IA %-18s [%d] area: %pI4\n",
10601 &or->u
.std
.area_id
);
10603 } else if (or->type
== OSPF_DESTINATION_DISCARD
) {
10605 json_object_string_add(json_route
,
10610 "D IA %-18s Discard entry\n",
10615 case OSPF_PATH_INTRA_AREA
:
10617 json_object_string_add(json_route
, "routeType",
10619 json_object_int_add(json_route
, "cost",
10621 json_object_string_addf(json_route
, "area",
10623 &or->u
.std
.area_id
);
10625 vty_out(vty
, "N %-18s [%d] area: %pI4\n",
10627 &or->u
.std
.area_id
);
10634 if (or->type
== OSPF_DESTINATION_NETWORK
) {
10636 json_nexthop_array
= json_object_new_array();
10637 json_object_object_add(json_route
, "nexthops",
10638 json_nexthop_array
);
10641 for (ALL_LIST_ELEMENTS(or->paths
, pnode
, pnnode
,
10644 json_nexthop
= json_object_new_object();
10645 json_object_array_add(
10646 json_nexthop_array
,
10649 if (if_lookup_by_index(path
->ifindex
,
10652 if (path
->nexthop
.s_addr
10655 json_object_string_add(
10658 json_object_string_add(
10660 "directly attached to",
10664 json_object_string_add(
10666 "directlyAttachedTo",
10672 "%24s directly attached to %s\n",
10680 json_object_string_addf(
10684 json_object_string_add(
10692 "%24s via %pI4, %s\n",
10705 vty_out(vty
, "\n");
10708 static void show_ip_ospf_route_router(struct vty
*vty
, struct ospf
*ospf
,
10709 struct route_table
*rtrs
,
10712 struct route_node
*rn
;
10713 struct ospf_route
* or ;
10714 struct listnode
*pnode
;
10715 struct listnode
*node
;
10716 struct ospf_path
*path
;
10717 char buf
[PREFIX_STRLEN
];
10718 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
10719 *json_nexthop
= NULL
;
10722 vty_out(vty
, "============ OSPF %s table =============\n",
10723 ospf
->all_rtrs
== rtrs
? "reachable routers"
10724 : "router routing");
10726 for (rn
= route_top(rtrs
); rn
; rn
= route_next(rn
)) {
10727 if (rn
->info
== NULL
)
10732 json_route
= json_object_new_object();
10733 json_object_object_add(
10734 json
, inet_ntop(AF_INET
, &rn
->p
.u
.prefix4
,
10737 json_object_string_add(json_route
, "routeType", "R ");
10739 vty_out(vty
, "R %-15pI4 ",
10743 for (ALL_LIST_ELEMENTS_RO((struct list
*)rn
->info
, node
, or)) {
10746 vty_out(vty
, "%24s", "");
10751 json_object_int_add(json_route
, "cost",
10753 json_object_string_addf(json_route
, "area",
10755 &or->u
.std
.area_id
);
10756 if (or->path_type
== OSPF_PATH_INTER_AREA
) {
10757 json_object_boolean_true_add(json_route
,
10759 json_object_boolean_true_add(json_route
,
10762 if (or->u
.std
.flags
& ROUTER_LSA_BORDER
)
10763 json_object_string_add(json_route
,
10766 else if (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
)
10767 json_object_string_add(json_route
,
10771 vty_out(vty
, "%s [%d] area: %pI4",
10772 (or->path_type
== OSPF_PATH_INTER_AREA
10775 or->cost
, &or->u
.std
.area_id
);
10777 vty_out(vty
, "%s%s\n",
10778 (or->u
.std
.flags
& ROUTER_LSA_BORDER
10781 (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
10787 json_nexthop_array
= json_object_new_array();
10788 json_object_object_add(json_route
, "nexthops",
10789 json_nexthop_array
);
10792 for (ALL_LIST_ELEMENTS_RO(or->paths
, pnode
, path
)) {
10794 json_nexthop
= json_object_new_object();
10795 json_object_array_add(
10796 json_nexthop_array
,
10799 if (if_lookup_by_index(path
->ifindex
,
10801 if (path
->nexthop
.s_addr
10804 json_object_string_add(
10807 json_object_string_add(
10809 "directly attached to",
10813 json_object_string_add(
10815 "directlyAttachedTo",
10821 "%24s directly attached to %s\n",
10829 json_object_string_addf(
10833 json_object_string_add(
10841 "%24s via %pI4, %s\n",
10854 vty_out(vty
, "\n");
10857 static void show_ip_ospf_route_external(struct vty
*vty
, struct ospf
*ospf
,
10858 struct route_table
*rt
,
10861 struct route_node
*rn
;
10862 struct ospf_route
*er
;
10863 struct listnode
*pnode
, *pnnode
;
10864 struct ospf_path
*path
;
10865 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
10866 *json_nexthop
= NULL
;
10870 "============ OSPF external routing table ===========\n");
10872 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
10873 if ((er
= rn
->info
) == NULL
)
10878 snprintfrr(buf1
, sizeof(buf1
), "%pFX", &rn
->p
);
10880 json_route
= json_object_new_object();
10881 json_object_object_add(json
, buf1
, json_route
);
10884 switch (er
->path_type
) {
10885 case OSPF_PATH_TYPE1_EXTERNAL
:
10887 json_object_string_add(json_route
, "routeType",
10889 json_object_int_add(json_route
, "cost",
10891 json_object_int_add(json_route
, "tag",
10895 "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI
10897 buf1
, er
->cost
, er
->u
.ext
.tag
);
10900 case OSPF_PATH_TYPE2_EXTERNAL
:
10902 json_object_string_add(json_route
, "routeType",
10904 json_object_int_add(json_route
, "cost",
10906 json_object_int_add(json_route
, "type2cost",
10907 er
->u
.ext
.type2_cost
);
10908 json_object_int_add(json_route
, "tag",
10912 "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI
10914 buf1
, er
->cost
, er
->u
.ext
.type2_cost
,
10921 json_nexthop_array
= json_object_new_array();
10922 json_object_object_add(json_route
, "nexthops",
10923 json_nexthop_array
);
10926 for (ALL_LIST_ELEMENTS(er
->paths
, pnode
, pnnode
, path
)) {
10928 json_nexthop
= json_object_new_object();
10929 json_object_array_add(json_nexthop_array
,
10933 if (if_lookup_by_index(path
->ifindex
, ospf
->vrf_id
)) {
10934 if (path
->nexthop
.s_addr
== INADDR_ANY
) {
10936 json_object_string_add(
10937 json_nexthop
, "ip",
10939 json_object_string_add(
10941 "directly attached to",
10945 json_object_string_add(
10947 "directlyAttachedTo",
10953 "%24s directly attached to %s\n",
10961 json_object_string_addf(
10962 json_nexthop
, "ip",
10963 "%pI4", &path
->nexthop
);
10964 json_object_string_add(
10965 json_nexthop
, "via",
10971 "%24s via %pI4, %s\n",
10983 vty_out(vty
, "\n");
10986 static void show_ip_ospf_route_orr_root(struct vty
*vty
, struct ospf
*ospf
,
10987 struct orr_root
*root
, bool use_vrf
)
10989 if (ospf
->instance
)
10990 vty_out(vty
, "\nOSPF Instance: %d\n", ospf
->instance
);
10992 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
10994 vty_out(vty
, "ORR Group: %s\n", root
->group_name
);
10995 vty_out(vty
, "Active Root: %pI4\n\n", &root
->router_id
);
10996 vty_out(vty
, "SPF calculated from %pI4\n\n", &root
->router_id
);
10998 if (root
->new_table
)
10999 show_ip_ospf_route_network(vty
, ospf
, root
->new_table
, NULL
);
11001 if (root
->new_rtrs
)
11002 show_ip_ospf_route_router(vty
, ospf
, root
->new_rtrs
, NULL
);
11004 vty_out(vty
, "\n");
11007 static void show_ip_ospf_route_orr_common(struct vty
*vty
, struct ospf
*ospf
,
11008 const char *orr_group
, bool use_vrf
)
11012 struct orr_root
*root
= NULL
;
11013 struct listnode
*node
= NULL
;
11014 struct list
*orr_root_list
= NULL
;
11016 if (!ospf
->orr_spf_request
)
11019 FOREACH_AFI_SAFI (afi
, safi
) {
11020 orr_root_list
= ospf
->orr_root
[afi
][safi
];
11021 if (!orr_root_list
)
11023 for (ALL_LIST_ELEMENTS_RO(orr_root_list
, node
, root
)) {
11025 if (!strmatch(root
->group_name
, orr_group
))
11027 show_ip_ospf_route_orr_root(vty
, ospf
, root
,
11030 show_ip_ospf_route_orr_root(vty
, ospf
, root
,
11036 DEFPY (show_ip_ospf_instance_route_orr
,
11037 show_ip_ospf_instance_route_orr_cmd
,
11038 "show ip ospf (1-65535)$instance route orr [WORD$orr_group]",
11043 "OSPF routing table\n"
11044 "Optimal Route Reflection\n"
11045 "ORR Group name\n")
11049 if (instance
!= ospf_instance
)
11050 return CMD_NOT_MY_INSTANCE
;
11052 ospf
= ospf_lookup_instance(instance
);
11053 if (!ospf
|| !ospf
->oi_running
)
11054 return CMD_SUCCESS
;
11056 show_ip_ospf_route_orr_common(vty
, ospf
, orr_group
, false);
11058 return CMD_SUCCESS
;
11061 DEFPY (show_ip_ospf_route_orr
,
11062 show_ip_ospf_route_orr_cmd
,
11063 "show ip ospf [vrf <NAME$vrf_name|all$all_vrf>] route orr [WORD$orr_group]",
11069 "OSPF routing table\n"
11070 "Optimal Route Reflection\n"
11071 "ORR Group name\n")
11073 struct ospf
*ospf
= NULL
;
11074 struct listnode
*node
= NULL
;
11075 int ret
= CMD_SUCCESS
;
11077 bool use_vrf
= vrf_name
|| all_vrf
;
11080 bool ospf_output
= false;
11082 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11083 if (!ospf
->oi_running
)
11085 ospf_output
= true;
11087 show_ip_ospf_route_orr_common(vty
, ospf
, orr_group
,
11091 vty_out(vty
, "%% OSPF is not enabled\n");
11096 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11098 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11100 if (!ospf
|| !ospf
->oi_running
) {
11101 vty_out(vty
, "%% OSPF is not enabled in vrf %s\n",
11102 vrf_name
? vrf_name
: "default");
11103 return CMD_SUCCESS
;
11106 show_ip_ospf_route_orr_common(vty
, ospf
, orr_group
, use_vrf
);
11111 static int show_ip_ospf_reachable_routers_common(struct vty
*vty
,
11115 if (ospf
->instance
)
11116 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
11118 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
11120 if (ospf
->all_rtrs
== NULL
) {
11121 vty_out(vty
, "No OSPF reachable router information exist\n");
11122 return CMD_SUCCESS
;
11125 /* Show Router routes. */
11126 show_ip_ospf_route_router(vty
, ospf
, ospf
->all_rtrs
, NULL
);
11128 vty_out(vty
, "\n");
11130 return CMD_SUCCESS
;
11133 DEFUN (show_ip_ospf_reachable_routers
,
11134 show_ip_ospf_reachable_routers_cmd
,
11135 "show ip ospf [vrf <NAME|all>] reachable-routers",
11138 "OSPF information\n"
11141 "Show all the reachable OSPF routers\n")
11143 struct ospf
*ospf
= NULL
;
11144 struct listnode
*node
= NULL
;
11145 char *vrf_name
= NULL
;
11146 bool all_vrf
= false;
11147 int ret
= CMD_SUCCESS
;
11150 uint8_t use_vrf
= 0;
11152 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11155 bool ospf_output
= false;
11160 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11161 if (!ospf
->oi_running
)
11164 ospf_output
= true;
11165 ret
= show_ip_ospf_reachable_routers_common(
11166 vty
, ospf
, use_vrf
);
11170 vty_out(vty
, "%% OSPF instance not found\n");
11172 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11173 if (ospf
== NULL
|| !ospf
->oi_running
) {
11174 vty_out(vty
, "%% OSPF instance not found\n");
11175 return CMD_SUCCESS
;
11178 ret
= show_ip_ospf_reachable_routers_common(vty
, ospf
,
11182 /* Display default ospf (instance 0) info */
11183 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11184 if (ospf
== NULL
|| !ospf
->oi_running
) {
11185 vty_out(vty
, "%% OSPF instance not found\n");
11186 return CMD_SUCCESS
;
11189 ret
= show_ip_ospf_reachable_routers_common(vty
, ospf
, use_vrf
);
11195 DEFUN (show_ip_ospf_instance_reachable_routers
,
11196 show_ip_ospf_instance_reachable_routers_cmd
,
11197 "show ip ospf (1-65535) reachable-routers",
11200 "OSPF information\n"
11202 "Show all the reachable OSPF routers\n")
11204 int idx_number
= 3;
11206 unsigned short instance
= 0;
11208 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
11209 if (instance
!= ospf_instance
)
11210 return CMD_NOT_MY_INSTANCE
;
11212 ospf
= ospf_lookup_instance(instance
);
11213 if (!ospf
|| !ospf
->oi_running
)
11214 return CMD_SUCCESS
;
11216 return show_ip_ospf_reachable_routers_common(vty
, ospf
, 0);
11219 static int show_ip_ospf_border_routers_common(struct vty
*vty
,
11223 if (ospf
->instance
)
11224 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
11226 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
11228 if (ospf
->new_table
== NULL
) {
11229 vty_out(vty
, "No OSPF routing information exist\n");
11230 return CMD_SUCCESS
;
11233 /* Show Network routes.
11234 show_ip_ospf_route_network (vty, ospf->new_table); */
11236 /* Show Router routes. */
11237 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, NULL
);
11239 vty_out(vty
, "\n");
11241 return CMD_SUCCESS
;
11244 DEFUN (show_ip_ospf_border_routers
,
11245 show_ip_ospf_border_routers_cmd
,
11246 "show ip ospf [vrf <NAME|all>] border-routers",
11249 "OSPF information\n"
11252 "Show all the ABR's and ASBR's\n")
11254 struct ospf
*ospf
= NULL
;
11255 struct listnode
*node
= NULL
;
11256 char *vrf_name
= NULL
;
11257 bool all_vrf
= false;
11258 int ret
= CMD_SUCCESS
;
11261 uint8_t use_vrf
= 0;
11263 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11266 bool ospf_output
= false;
11271 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11272 if (!ospf
->oi_running
)
11275 ospf_output
= true;
11276 ret
= show_ip_ospf_border_routers_common(
11277 vty
, ospf
, use_vrf
);
11281 vty_out(vty
, "%% OSPF is not enabled\n");
11283 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11284 if (ospf
== NULL
|| !ospf
->oi_running
) {
11286 "%% OSPF is not enabled in vrf %s\n",
11288 return CMD_SUCCESS
;
11291 ret
= show_ip_ospf_border_routers_common(vty
, ospf
,
11295 /* Display default ospf (instance 0) info */
11296 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11297 if (ospf
== NULL
|| !ospf
->oi_running
) {
11298 vty_out(vty
, "%% OSPF is not enabled in vrf default\n");
11299 return CMD_SUCCESS
;
11302 ret
= show_ip_ospf_border_routers_common(vty
, ospf
, use_vrf
);
11308 DEFUN (show_ip_ospf_instance_border_routers
,
11309 show_ip_ospf_instance_border_routers_cmd
,
11310 "show ip ospf (1-65535) border-routers",
11313 "OSPF information\n"
11315 "Show all the ABR's and ASBR's\n")
11317 int idx_number
= 3;
11319 unsigned short instance
= 0;
11321 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
11322 if (instance
!= ospf_instance
)
11323 return CMD_NOT_MY_INSTANCE
;
11325 ospf
= ospf_lookup_instance(instance
);
11326 if (!ospf
|| !ospf
->oi_running
)
11327 return CMD_SUCCESS
;
11329 return show_ip_ospf_border_routers_common(vty
, ospf
, 0);
11332 static int show_ip_ospf_route_common(struct vty
*vty
, struct ospf
*ospf
,
11333 json_object
*json
, uint8_t use_vrf
)
11335 json_object
*json_vrf
= NULL
;
11337 if (ospf
->instance
)
11338 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
11343 json_vrf
= json_object_new_object();
11348 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
11350 if (ospf
->new_table
== NULL
) {
11351 vty_out(vty
, "No OSPF routing information exist\n");
11352 return CMD_SUCCESS
;
11355 /* Show Network routes. */
11356 show_ip_ospf_route_network(vty
, ospf
, ospf
->new_table
, json_vrf
);
11358 /* Show Router routes. */
11359 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, json_vrf
);
11361 /* Show Router routes. */
11362 if (ospf
->all_rtrs
)
11363 show_ip_ospf_route_router(vty
, ospf
, ospf
->all_rtrs
, json_vrf
);
11365 /* Show AS External routes. */
11366 show_ip_ospf_route_external(vty
, ospf
, ospf
->old_external_route
,
11371 // json_object_object_add(json_vrf, "areas",
11373 json_object_object_add(json
, ospf_get_name(ospf
),
11377 vty_out(vty
, "\n");
11380 return CMD_SUCCESS
;
11383 DEFUN (show_ip_ospf_route
,
11384 show_ip_ospf_route_cmd
,
11385 "show ip ospf [vrf <NAME|all>] route [json]",
11388 "OSPF information\n"
11391 "OSPF routing table\n"
11394 struct ospf
*ospf
= NULL
;
11395 struct listnode
*node
= NULL
;
11396 char *vrf_name
= NULL
;
11397 bool all_vrf
= false;
11398 int ret
= CMD_SUCCESS
;
11401 uint8_t use_vrf
= 0;
11402 bool uj
= use_json(argc
, argv
);
11403 json_object
*json
= NULL
;
11406 json
= json_object_new_object();
11408 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11410 /* vrf input is provided could be all or specific vrf*/
11412 bool ospf_output
= false;
11417 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11418 if (!ospf
->oi_running
)
11420 ospf_output
= true;
11421 ret
= show_ip_ospf_route_common(vty
, ospf
, json
,
11426 /* Keep Non-pretty format */
11427 vty_json(vty
, json
);
11428 } else if (!ospf_output
)
11429 vty_out(vty
, "%% OSPF is not enabled\n");
11433 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11434 if (ospf
== NULL
|| !ospf
->oi_running
) {
11436 vty_json(vty
, json
);
11439 "%% OSPF is not enabled in vrf %s\n",
11442 return CMD_SUCCESS
;
11445 /* Display default ospf (instance 0) info */
11446 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11447 if (ospf
== NULL
|| !ospf
->oi_running
) {
11449 vty_json(vty
, json
);
11452 "%% OSPF is not enabled in vrf default\n");
11454 return CMD_SUCCESS
;
11459 ret
= show_ip_ospf_route_common(vty
, ospf
, json
, use_vrf
);
11460 /* Keep Non-pretty format */
11462 vty_out(vty
, "%s\n",
11463 json_object_to_json_string_ext(
11464 json
, JSON_C_TO_STRING_NOSLASHESCAPE
));
11468 json_object_free(json
);
11473 DEFUN (show_ip_ospf_instance_route
,
11474 show_ip_ospf_instance_route_cmd
,
11475 "show ip ospf (1-65535) route",
11478 "OSPF information\n"
11480 "OSPF routing table\n")
11482 int idx_number
= 3;
11484 unsigned short instance
= 0;
11486 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
11487 if (instance
!= ospf_instance
)
11488 return CMD_NOT_MY_INSTANCE
;
11490 ospf
= ospf_lookup_instance(instance
);
11491 if (!ospf
|| !ospf
->oi_running
)
11492 return CMD_SUCCESS
;
11494 return show_ip_ospf_route_common(vty
, ospf
, NULL
, 0);
11498 DEFUN (show_ip_ospf_vrfs
,
11499 show_ip_ospf_vrfs_cmd
,
11500 "show ip ospf vrfs [json]",
11503 "OSPF information\n"
11504 "Show OSPF VRFs \n"
11507 bool uj
= use_json(argc
, argv
);
11508 json_object
*json
= NULL
;
11509 json_object
*json_vrfs
= NULL
;
11510 struct ospf
*ospf
= NULL
;
11511 struct listnode
*node
= NULL
;
11513 static const char header
[] = "Name Id RouterId ";
11516 json
= json_object_new_object();
11517 json_vrfs
= json_object_new_object();
11520 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11521 json_object
*json_vrf
= NULL
;
11522 const char *name
= NULL
;
11523 int64_t vrf_id_ui
= 0;
11527 if (!uj
&& count
== 1)
11528 vty_out(vty
, "%s\n", header
);
11530 json_vrf
= json_object_new_object();
11532 name
= ospf_get_name(ospf
);
11534 vrf_id_ui
= (ospf
->vrf_id
== VRF_UNKNOWN
)
11536 : (int64_t)ospf
->vrf_id
;
11539 json_object_int_add(json_vrf
, "vrfId", vrf_id_ui
);
11540 json_object_string_addf(json_vrf
, "routerId", "%pI4",
11543 json_object_object_add(json_vrfs
, name
, json_vrf
);
11546 vty_out(vty
, "%-25s %-5d %-16pI4 \n", name
,
11547 ospf
->vrf_id
, &ospf
->router_id
);
11552 json_object_object_add(json
, "vrfs", json_vrfs
);
11553 json_object_int_add(json
, "totalVrfs", count
);
11555 vty_json(vty
, json
);
11558 vty_out(vty
, "\nTotal number of OSPF VRFs: %d\n",
11562 return CMD_SUCCESS
;
11564 DEFPY (clear_ip_ospf_neighbor
,
11565 clear_ip_ospf_neighbor_cmd
,
11566 "clear ip ospf [(1-65535)]$instance neighbor [A.B.C.D$nbr_id]",
11569 "OSPF information\n"
11571 "Reset OSPF Neighbor\n"
11574 struct listnode
*node
;
11575 struct ospf
*ospf
= NULL
;
11577 /* If user does not specify the arguments,
11578 * instance = 0 and nbr_id = 0.0.0.0
11580 if (instance
!= 0) {
11581 /* This means clear only the particular ospf process */
11582 if (instance
!= ospf_instance
)
11583 return CMD_NOT_MY_INSTANCE
;
11586 /* Clear all the ospf processes */
11587 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11588 if (!ospf
->oi_running
)
11591 if (nbr_id_str
&& IPV4_ADDR_SAME(&ospf
->router_id
, &nbr_id
)) {
11592 vty_out(vty
, "Self router-id is not allowed.\r\n ");
11593 return CMD_SUCCESS
;
11596 ospf_neighbor_reset(ospf
, nbr_id
, nbr_id_str
);
11599 return CMD_SUCCESS
;
11602 DEFPY (clear_ip_ospf_process
,
11603 clear_ip_ospf_process_cmd
,
11604 "clear ip ospf [(1-65535)]$instance process",
11607 "OSPF information\n"
11609 "Reset OSPF Process\n")
11611 struct listnode
*node
;
11612 struct ospf
*ospf
= NULL
;
11614 /* Check if instance is not passed as an argument */
11615 if (instance
!= 0) {
11616 /* This means clear only the particular ospf process */
11617 if (instance
!= ospf_instance
)
11618 return CMD_NOT_MY_INSTANCE
;
11621 /* Clear all the ospf processes */
11622 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11623 if (!ospf
->oi_running
)
11626 ospf_process_reset(ospf
);
11629 return CMD_SUCCESS
;
11632 static const char *const ospf_abr_type_str
[] = {
11633 "unknown", "standard", "ibm", "cisco", "shortcut"
11636 static const char *const ospf_shortcut_mode_str
[] = {
11637 "default", "enable", "disable"
11639 static int ospf_vty_external_rt_walkcb(struct hash_bucket
*bucket
,
11642 struct external_info
*ei
= bucket
->data
;
11643 struct vty
*vty
= (struct vty
*)arg
;
11644 static unsigned int count
;
11646 vty_out(vty
, "%-4pI4/%d, ", &ei
->p
.prefix
, ei
->p
.prefixlen
);
11649 if (count
% 5 == 0)
11650 vty_out(vty
, "\n");
11652 if (OSPF_EXTERNAL_RT_COUNT(ei
->aggr_route
) == count
)
11655 return HASHWALK_CONTINUE
;
11658 static int ospf_json_external_rt_walkcb(struct hash_bucket
*bucket
,
11661 struct external_info
*ei
= bucket
->data
;
11662 struct json_object
*json
= (struct json_object
*)arg
;
11663 char buf
[PREFIX2STR_BUFFER
];
11665 static unsigned int count
;
11667 prefix2str(&ei
->p
, buf
, sizeof(buf
));
11669 snprintf(exnalbuf
, 20, "Exnl Addr-%d", count
);
11671 json_object_string_add(json
, exnalbuf
, buf
);
11675 if (OSPF_EXTERNAL_RT_COUNT(ei
->aggr_route
) == count
)
11678 return HASHWALK_CONTINUE
;
11681 static int ospf_show_summary_address(struct vty
*vty
, struct ospf
*ospf
,
11682 uint8_t use_vrf
, json_object
*json
,
11683 bool uj
, bool detail
)
11685 struct route_node
*rn
;
11686 json_object
*json_vrf
= NULL
;
11689 static char header
[] =
11690 "Summary-address Metric-type Metric Tag External_Rt_count\n";
11692 mtype
= metric_type(ospf
, 0, ospf
->instance
);
11693 mval
= metric_value(ospf
, 0, ospf
->instance
);
11696 vty_out(vty
, "%s\n", header
);
11700 json_vrf
= json_object_new_object();
11705 if (ospf
->instance
) {
11707 json_object_int_add(json
, "ospfInstance",
11710 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
11713 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
11716 vty_out(vty
, "aggregation delay interval :%u(in seconds)\n\n",
11717 ospf
->aggr_delay_interval
);
11719 json_object_int_add(json_vrf
, "aggregation delay interval",
11720 ospf
->aggr_delay_interval
);
11721 json_object_int_add(json_vrf
, "aggregationDelayInterval",
11722 ospf
->aggr_delay_interval
);
11725 for (rn
= route_top(ospf
->rt_aggr_tbl
); rn
; rn
= route_next(rn
))
11727 struct ospf_external_aggr_rt
*aggr
= rn
->info
;
11728 json_object
*json_aggr
= NULL
;
11729 char buf
[PREFIX2STR_BUFFER
];
11731 prefix2str(&aggr
->p
, buf
, sizeof(buf
));
11735 json_aggr
= json_object_new_object();
11737 json_object_object_add(json_vrf
, buf
,
11740 json_object_string_add(json_aggr
,
11741 "Summary address", buf
);
11742 json_object_string_add(json_aggr
,
11743 "summaryAddress", buf
);
11745 json_object_string_add(
11746 json_aggr
, "Metric-type",
11747 (mtype
== EXTERNAL_METRIC_TYPE_1
)
11750 json_object_string_add(
11751 json_aggr
, "metricType",
11752 (mtype
== EXTERNAL_METRIC_TYPE_1
)
11756 #if CONFDATE > 20230131
11757 CPP_NOTICE("Remove JSON object commands with keys starting with capital")
11759 json_object_int_add(json_aggr
, "Metric", mval
);
11760 json_object_int_add(json_aggr
, "metric", mval
);
11762 json_object_int_add(json_aggr
, "Tag",
11764 json_object_int_add(json_aggr
, "tag",
11767 json_object_int_add(
11768 json_aggr
, "External route count",
11769 OSPF_EXTERNAL_RT_COUNT(aggr
));
11770 json_object_int_add(
11771 json_aggr
, "externalRouteCount",
11772 OSPF_EXTERNAL_RT_COUNT(aggr
));
11774 if (OSPF_EXTERNAL_RT_COUNT(aggr
) && detail
) {
11776 aggr
->match_extnl_hash
,
11777 ospf_json_external_rt_walkcb
,
11782 vty_out(vty
, "%-20s", buf
);
11784 (mtype
== EXTERNAL_METRIC_TYPE_1
)
11785 ? vty_out(vty
, "%-16s", "E1")
11786 : vty_out(vty
, "%-16s", "E2");
11787 vty_out(vty
, "%-11d", mval
);
11789 vty_out(vty
, "%-12u", aggr
->tag
);
11791 vty_out(vty
, "%-5ld\n",
11792 OSPF_EXTERNAL_RT_COUNT(aggr
));
11794 if (OSPF_EXTERNAL_RT_COUNT(aggr
) && detail
) {
11796 "Matched External routes:\n");
11798 aggr
->match_extnl_hash
,
11799 ospf_vty_external_rt_walkcb
,
11801 vty_out(vty
, "\n");
11804 vty_out(vty
, "\n");
11810 json_object_object_add(json
, ospf_get_name(ospf
),
11813 vty_out(vty
, "\n");
11815 return CMD_SUCCESS
;
11818 DEFUN (show_ip_ospf_external_aggregator
,
11819 show_ip_ospf_external_aggregator_cmd
,
11820 "show ip ospf [vrf <NAME|all>] summary-address [detail] [json]",
11822 "OSPF information\n"
11825 "Show external summary addresses\n"
11826 "Detailed information\n"
11829 char *vrf_name
= NULL
;
11830 bool all_vrf
= false;
11831 int ret
= CMD_SUCCESS
;
11834 uint8_t use_vrf
= 0;
11835 bool uj
= use_json(argc
, argv
);
11836 struct ospf
*ospf
= NULL
;
11837 json_object
*json
= NULL
;
11838 struct listnode
*node
= NULL
;
11840 bool detail
= false;
11842 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11844 if (argv_find(argv
, argc
, "detail", &idx
))
11848 json
= json_object_new_object();
11850 /* vrf input is provided */
11854 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11855 if (!ospf
->oi_running
)
11857 ret
= ospf_show_summary_address(
11858 vty
, ospf
, use_vrf
, json
, uj
, detail
);
11862 vty_json(vty
, json
);
11867 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11869 if (ospf
== NULL
|| !ospf
->oi_running
) {
11871 vty_json(vty
, json
);
11874 "%% OSPF is not enabled in vrf %s\n",
11877 return CMD_SUCCESS
;
11879 ospf_show_summary_address(vty
, ospf
, use_vrf
, json
, uj
, detail
);
11883 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11884 if (ospf
== NULL
|| !ospf
->oi_running
) {
11886 vty_json(vty
, json
);
11889 "%% OSPF is not enabled in vrf default\n");
11891 return CMD_SUCCESS
;
11894 ospf_show_summary_address(vty
, ospf
, use_vrf
, json
, uj
, detail
);
11898 vty_json(vty
, json
);
11899 return CMD_SUCCESS
;
11902 static const char *const ospf_int_type_str
[] = {
11903 "unknown", /* should never be used. */
11907 "point-to-multipoint",
11908 "virtual-link", /* should never be used. */
11912 static const char *interface_config_auth_str(struct ospf_if_params
*params
)
11914 if (!OSPF_IF_PARAM_CONFIGURED(params
, auth_type
)
11915 || params
->auth_type
== OSPF_AUTH_NOTSET
)
11918 /* Translation tables are not that much help
11919 * here due to syntax
11920 * of the simple option */
11921 switch (params
->auth_type
) {
11923 case OSPF_AUTH_NULL
:
11926 case OSPF_AUTH_SIMPLE
:
11929 case OSPF_AUTH_CRYPTOGRAPHIC
:
11930 return " message-digest";
11936 static int config_write_interface_one(struct vty
*vty
, struct vrf
*vrf
)
11938 struct listnode
*node
;
11939 struct interface
*ifp
;
11940 struct crypt_key
*ck
;
11941 struct route_node
*rn
= NULL
;
11942 struct ospf_if_params
*params
;
11943 const char *auth_str
;
11946 FOR_ALL_INTERFACES (vrf
, ifp
) {
11948 if (memcmp(ifp
->name
, "VLINK", 5) == 0)
11951 if_vty_config_start(vty
, ifp
);
11954 vty_out(vty
, " description %s\n", ifp
->desc
);
11958 params
= IF_DEF_PARAMS(ifp
);
11961 /* Interface Network print. */
11962 if (OSPF_IF_PARAM_CONFIGURED(params
, type
)
11963 && params
->type
!= OSPF_IFTYPE_LOOPBACK
) {
11964 if (params
->type
!= ospf_default_iftype(ifp
)) {
11965 vty_out(vty
, " ip ospf network %s",
11969 == OSPF_IFTYPE_POINTOPOINT
11970 && params
->ptp_dmvpn
)
11971 vty_out(vty
, " dmvpn");
11972 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11973 vty_out(vty
, " %pI4",
11975 vty_out(vty
, "\n");
11979 /* OSPF interface authentication print */
11980 auth_str
= interface_config_auth_str(params
);
11982 vty_out(vty
, " ip ospf authentication%s",
11984 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11985 vty_out(vty
, " %pI4",
11987 vty_out(vty
, "\n");
11990 /* Simple Authentication Password print. */
11991 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_simple
)
11992 && params
->auth_simple
[0] != '\0') {
11993 vty_out(vty
, " ip ospf authentication-key %s",
11994 params
->auth_simple
);
11995 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11996 vty_out(vty
, " %pI4",
11998 vty_out(vty
, "\n");
12001 /* Cryptographic Authentication Key print. */
12002 if (params
&& params
->auth_crypt
) {
12003 for (ALL_LIST_ELEMENTS_RO(params
->auth_crypt
,
12006 " ip ospf message-digest-key %d md5 %s",
12007 ck
->key_id
, ck
->auth_key
);
12008 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12009 vty_out(vty
, " %pI4",
12011 vty_out(vty
, "\n");
12015 /* Interface Output Cost print. */
12016 if (OSPF_IF_PARAM_CONFIGURED(params
, output_cost_cmd
)) {
12017 vty_out(vty
, " ip ospf cost %u",
12018 params
->output_cost_cmd
);
12019 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12020 vty_out(vty
, " %pI4",
12022 vty_out(vty
, "\n");
12025 /* Hello Interval print. */
12026 if (OSPF_IF_PARAM_CONFIGURED(params
, v_hello
)
12027 && params
->v_hello
!= OSPF_HELLO_INTERVAL_DEFAULT
) {
12028 vty_out(vty
, " ip ospf hello-interval %u",
12030 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12031 vty_out(vty
, " %pI4",
12033 vty_out(vty
, "\n");
12037 /* Router Dead Interval print. */
12038 if (OSPF_IF_PARAM_CONFIGURED(params
, v_wait
)
12039 && params
->is_v_wait_set
) {
12040 vty_out(vty
, " ip ospf dead-interval ");
12043 if (OSPF_IF_PARAM_CONFIGURED(params
,
12046 "minimal hello-multiplier %d",
12047 params
->fast_hello
);
12049 vty_out(vty
, "%u", params
->v_wait
);
12051 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12052 vty_out(vty
, " %pI4",
12054 vty_out(vty
, "\n");
12057 /* Router Priority print. */
12058 if (OSPF_IF_PARAM_CONFIGURED(params
, priority
)
12059 && params
->priority
12060 != OSPF_ROUTER_PRIORITY_DEFAULT
) {
12061 vty_out(vty
, " ip ospf priority %u",
12063 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12064 vty_out(vty
, " %pI4",
12066 vty_out(vty
, "\n");
12069 /* Retransmit Interval print. */
12070 if (OSPF_IF_PARAM_CONFIGURED(params
,
12071 retransmit_interval
)
12072 && params
->retransmit_interval
12073 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
) {
12074 vty_out(vty
, " ip ospf retransmit-interval %u",
12075 params
->retransmit_interval
);
12076 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12077 vty_out(vty
, " %pI4",
12079 vty_out(vty
, "\n");
12082 /* Transmit Delay print. */
12083 if (OSPF_IF_PARAM_CONFIGURED(params
, transmit_delay
)
12084 && params
->transmit_delay
12085 != OSPF_TRANSMIT_DELAY_DEFAULT
) {
12086 vty_out(vty
, " ip ospf transmit-delay %u",
12087 params
->transmit_delay
);
12088 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12089 vty_out(vty
, " %pI4",
12091 vty_out(vty
, "\n");
12095 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
12097 vty_out(vty
, " ip ospf %d",
12100 vty_out(vty
, " ip ospf");
12102 char buf
[INET_ADDRSTRLEN
];
12104 area_id2str(buf
, sizeof(buf
), ¶ms
->if_area
,
12105 params
->if_area_id_fmt
);
12106 vty_out(vty
, " area %s", buf
);
12107 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12108 vty_out(vty
, " %pI4",
12110 vty_out(vty
, "\n");
12114 if (params
&& params
->bfd_config
)
12115 ospf_bfd_write_config(vty
, params
);
12117 /* MTU ignore print. */
12118 if (OSPF_IF_PARAM_CONFIGURED(params
, mtu_ignore
)
12119 && params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
) {
12120 if (params
->mtu_ignore
== 0)
12121 vty_out(vty
, " no ip ospf mtu-ignore");
12123 vty_out(vty
, " ip ospf mtu-ignore");
12124 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12125 vty_out(vty
, " %pI4",
12127 vty_out(vty
, "\n");
12130 if (OSPF_IF_PARAM_CONFIGURED(params
,
12131 passive_interface
)) {
12132 vty_out(vty
, " %sip ospf passive",
12133 params
->passive_interface
12137 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12138 vty_out(vty
, " %pI4", &rn
->p
.u
.prefix4
);
12139 vty_out(vty
, "\n");
12142 /* LDP-Sync print */
12143 if (params
&& params
->ldp_sync_info
)
12144 ospf_ldp_sync_if_write_config(vty
, params
);
12148 rn
= route_top(IF_OIFS_PARAMS(ifp
));
12150 rn
= route_next(rn
);
12155 if (params
!= NULL
)
12160 ospf_opaque_config_write_if(vty
, ifp
);
12162 if_vty_config_end(vty
);
12168 /* Configuration write function for ospfd. */
12169 static int config_write_interface(struct vty
*vty
)
12172 struct vrf
*vrf
= NULL
;
12174 /* Display all VRF aware OSPF interface configuration */
12175 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
12176 write
+= config_write_interface_one(vty
, vrf
);
12182 static int config_write_network_area(struct vty
*vty
, struct ospf
*ospf
)
12184 struct route_node
*rn
;
12185 char buf
[INET_ADDRSTRLEN
];
12187 /* `network area' print. */
12188 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
))
12190 struct ospf_network
*n
= rn
->info
;
12192 /* Create Area ID string by specified Area ID format. */
12193 if (n
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
12194 inet_ntop(AF_INET
, &n
->area_id
, buf
,
12197 snprintf(buf
, sizeof(buf
), "%lu",
12198 (unsigned long int)ntohl(
12199 n
->area_id
.s_addr
));
12201 /* Network print. */
12202 vty_out(vty
, " network %pFX area %s\n", &rn
->p
, buf
);
12208 static int config_write_ospf_area(struct vty
*vty
, struct ospf
*ospf
)
12210 struct listnode
*node
;
12211 struct ospf_area
*area
;
12212 char buf
[INET_ADDRSTRLEN
];
12214 /* Area configuration print. */
12215 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
12216 struct route_node
*rn1
;
12218 area_id2str(buf
, sizeof(buf
), &area
->area_id
,
12219 area
->area_id_fmt
);
12221 if (area
->auth_type
!= OSPF_AUTH_NULL
) {
12222 if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
12223 vty_out(vty
, " area %s authentication\n", buf
);
12226 " area %s authentication message-digest\n",
12230 if (area
->shortcut_configured
!= OSPF_SHORTCUT_DEFAULT
)
12231 vty_out(vty
, " area %s shortcut %s\n", buf
,
12232 ospf_shortcut_mode_str
12233 [area
->shortcut_configured
]);
12235 if ((area
->external_routing
== OSPF_AREA_STUB
)
12236 || (area
->external_routing
== OSPF_AREA_NSSA
)) {
12237 if (area
->external_routing
== OSPF_AREA_STUB
) {
12238 vty_out(vty
, " area %s stub", buf
);
12239 if (area
->no_summary
)
12240 vty_out(vty
, " no-summary\n");
12241 vty_out(vty
, "\n");
12242 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
12243 switch (area
->NSSATranslatorRole
) {
12244 case OSPF_NSSA_ROLE_NEVER
:
12246 " area %s nssa translate-never\n",
12249 case OSPF_NSSA_ROLE_ALWAYS
:
12251 " area %s nssa translate-always\n",
12254 case OSPF_NSSA_ROLE_CANDIDATE
:
12255 vty_out(vty
, " area %s nssa \n", buf
);
12258 if (area
->no_summary
)
12260 " area %s nssa no-summary\n",
12262 if (area
->suppress_fa
)
12264 " area %s nssa suppress-fa\n",
12268 if (area
->default_cost
!= 1)
12269 vty_out(vty
, " area %s default-cost %d\n", buf
,
12270 area
->default_cost
);
12273 for (rn1
= route_top(area
->ranges
); rn1
; rn1
= route_next(rn1
))
12275 struct ospf_area_range
*range
= rn1
->info
;
12277 vty_out(vty
, " area %s range %pFX", buf
,
12280 if (range
->cost_config
12281 != OSPF_AREA_RANGE_COST_UNSPEC
)
12282 vty_out(vty
, " cost %d",
12283 range
->cost_config
);
12285 if (!CHECK_FLAG(range
->flags
,
12286 OSPF_AREA_RANGE_ADVERTISE
))
12287 vty_out(vty
, " not-advertise");
12289 if (CHECK_FLAG(range
->flags
,
12290 OSPF_AREA_RANGE_SUBSTITUTE
))
12291 vty_out(vty
, " substitute %pI4/%d",
12292 &range
->subst_addr
,
12293 range
->subst_masklen
);
12295 vty_out(vty
, "\n");
12298 if (EXPORT_NAME(area
))
12299 vty_out(vty
, " area %s export-list %s\n", buf
,
12300 EXPORT_NAME(area
));
12302 if (IMPORT_NAME(area
))
12303 vty_out(vty
, " area %s import-list %s\n", buf
,
12304 IMPORT_NAME(area
));
12306 if (PREFIX_NAME_IN(area
))
12307 vty_out(vty
, " area %s filter-list prefix %s in\n", buf
,
12308 PREFIX_NAME_IN(area
));
12310 if (PREFIX_NAME_OUT(area
))
12311 vty_out(vty
, " area %s filter-list prefix %s out\n",
12312 buf
, PREFIX_NAME_OUT(area
));
12318 static int config_write_ospf_nbr_nbma(struct vty
*vty
, struct ospf
*ospf
)
12320 struct ospf_nbr_nbma
*nbr_nbma
;
12321 struct route_node
*rn
;
12323 /* Static Neighbor configuration print. */
12324 for (rn
= route_top(ospf
->nbr_nbma
); rn
; rn
= route_next(rn
))
12325 if ((nbr_nbma
= rn
->info
)) {
12326 vty_out(vty
, " neighbor %pI4", &nbr_nbma
->addr
);
12328 if (nbr_nbma
->priority
12329 != OSPF_NEIGHBOR_PRIORITY_DEFAULT
)
12330 vty_out(vty
, " priority %d",
12331 nbr_nbma
->priority
);
12333 if (nbr_nbma
->v_poll
!= OSPF_POLL_INTERVAL_DEFAULT
)
12334 vty_out(vty
, " poll-interval %d",
12337 vty_out(vty
, "\n");
12343 static int config_write_virtual_link(struct vty
*vty
, struct ospf
*ospf
)
12345 struct listnode
*node
;
12346 struct ospf_vl_data
*vl_data
;
12347 const char *auth_str
;
12348 char buf
[INET_ADDRSTRLEN
];
12350 /* Virtual-Link print */
12351 for (ALL_LIST_ELEMENTS_RO(ospf
->vlinks
, node
, vl_data
)) {
12352 struct listnode
*n2
;
12353 struct crypt_key
*ck
;
12354 struct ospf_interface
*oi
;
12356 if (vl_data
!= NULL
) {
12357 area_id2str(buf
, sizeof(buf
), &vl_data
->vl_area_id
,
12358 vl_data
->vl_area_id_fmt
);
12359 oi
= vl_data
->vl_oi
;
12362 if (OSPF_IF_PARAM(oi
, v_hello
)
12363 != OSPF_HELLO_INTERVAL_DEFAULT
12364 || OSPF_IF_PARAM(oi
, v_wait
)
12365 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
12366 || OSPF_IF_PARAM(oi
, retransmit_interval
)
12367 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
12368 || OSPF_IF_PARAM(oi
, transmit_delay
)
12369 != OSPF_TRANSMIT_DELAY_DEFAULT
)
12371 " area %s virtual-link %pI4 hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n",
12372 buf
, &vl_data
->vl_peer
,
12373 OSPF_IF_PARAM(oi
, v_hello
),
12374 OSPF_IF_PARAM(oi
, retransmit_interval
),
12375 OSPF_IF_PARAM(oi
, transmit_delay
),
12376 OSPF_IF_PARAM(oi
, v_wait
));
12378 vty_out(vty
, " area %s virtual-link %pI4\n", buf
,
12379 &vl_data
->vl_peer
);
12381 auth_str
= interface_config_auth_str(
12382 IF_DEF_PARAMS(oi
->ifp
));
12385 " area %s virtual-link %pI4 authentication%s\n",
12386 buf
, &vl_data
->vl_peer
, auth_str
);
12388 if (IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)->auth_simple
[0]
12391 " area %s virtual-link %pI4 authentication-key %s\n",
12392 buf
, &vl_data
->vl_peer
,
12393 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
12396 for (ALL_LIST_ELEMENTS_RO(
12397 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
12401 " area %s virtual-link %pI4 message-digest-key %d md5 %s\n",
12402 buf
, &vl_data
->vl_peer
,
12403 ck
->key_id
, ck
->auth_key
);
12411 static int config_write_ospf_redistribute(struct vty
*vty
, struct ospf
*ospf
)
12415 /* redistribute print. */
12416 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
12417 struct list
*red_list
;
12418 struct listnode
*node
;
12419 struct ospf_redist
*red
;
12421 red_list
= ospf
->redist
[type
];
12425 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
12426 vty_out(vty
, " redistribute %s",
12427 zebra_route_string(type
));
12429 vty_out(vty
, " %d", red
->instance
);
12431 if (red
->dmetric
.value
>= 0)
12432 vty_out(vty
, " metric %d", red
->dmetric
.value
);
12434 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
12435 vty_out(vty
, " metric-type 1");
12437 if (ROUTEMAP_NAME(red
))
12438 vty_out(vty
, " route-map %s",
12439 ROUTEMAP_NAME(red
));
12441 vty_out(vty
, "\n");
12448 static int ospf_cfg_write_helper_dis_rtr_walkcb(struct hash_bucket
*bucket
,
12451 struct advRtr
*rtr
= bucket
->data
;
12452 struct vty
*vty
= (struct vty
*)arg
;
12454 vty_out(vty
, " graceful-restart helper enable %pI4\n",
12456 return HASHWALK_CONTINUE
;
12459 static void config_write_ospf_gr(struct vty
*vty
, struct ospf
*ospf
)
12461 if (!ospf
->gr_info
.restart_support
)
12464 if (ospf
->gr_info
.grace_period
== OSPF_DFLT_GRACE_INTERVAL
)
12465 vty_out(vty
, " graceful-restart\n");
12467 vty_out(vty
, " graceful-restart grace-period %u\n",
12468 ospf
->gr_info
.grace_period
);
12471 static int config_write_ospf_gr_helper(struct vty
*vty
, struct ospf
*ospf
)
12473 if (ospf
->is_helper_supported
)
12474 vty_out(vty
, " graceful-restart helper enable\n");
12476 if (!ospf
->strict_lsa_check
)
12478 " no graceful-restart helper strict-lsa-checking\n");
12480 if (ospf
->only_planned_restart
)
12481 vty_out(vty
, " graceful-restart helper planned-only\n");
12483 if (ospf
->supported_grace_time
!= OSPF_MAX_GRACE_INTERVAL
)
12485 " graceful-restart helper supported-grace-time %d\n",
12486 ospf
->supported_grace_time
);
12488 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf
)) {
12489 hash_walk(ospf
->enable_rtr_list
,
12490 ospf_cfg_write_helper_dis_rtr_walkcb
, vty
);
12495 static int config_write_ospf_external_aggregator(struct vty
*vty
,
12498 struct route_node
*rn
;
12500 if (ospf
->aggr_delay_interval
!= OSPF_EXTL_AGGR_DEFAULT_DELAY
)
12501 vty_out(vty
, " aggregation timer %u\n",
12502 ospf
->aggr_delay_interval
);
12504 /* print 'summary-address A.B.C.D/M' */
12505 for (rn
= route_top(ospf
->rt_aggr_tbl
); rn
; rn
= route_next(rn
))
12507 struct ospf_external_aggr_rt
*aggr
= rn
->info
;
12509 vty_out(vty
, " summary-address %pI4/%d",
12510 &aggr
->p
.prefix
, aggr
->p
.prefixlen
);
12512 vty_out(vty
, " tag %u", aggr
->tag
);
12514 if (CHECK_FLAG(aggr
->flags
,
12515 OSPF_EXTERNAL_AGGRT_NO_ADVERTISE
))
12516 vty_out(vty
, " no-advertise");
12518 vty_out(vty
, "\n");
12524 static int config_write_ospf_default_metric(struct vty
*vty
, struct ospf
*ospf
)
12526 if (ospf
->default_metric
!= -1)
12527 vty_out(vty
, " default-metric %d\n", ospf
->default_metric
);
12531 static int config_write_ospf_distribute(struct vty
*vty
, struct ospf
*ospf
)
12534 struct ospf_redist
*red
;
12537 /* distribute-list print. */
12538 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
12539 if (DISTRIBUTE_NAME(ospf
, type
))
12540 vty_out(vty
, " distribute-list %s out %s\n",
12541 DISTRIBUTE_NAME(ospf
, type
),
12542 zebra_route_string(type
));
12544 /* default-information print. */
12545 if (ospf
->default_originate
!= DEFAULT_ORIGINATE_NONE
) {
12546 vty_out(vty
, " default-information originate");
12547 if (ospf
->default_originate
== DEFAULT_ORIGINATE_ALWAYS
)
12548 vty_out(vty
, " always");
12550 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
12552 if (red
->dmetric
.value
>= 0)
12553 vty_out(vty
, " metric %d",
12554 red
->dmetric
.value
);
12556 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
12557 vty_out(vty
, " metric-type 1");
12559 if (ROUTEMAP_NAME(red
))
12560 vty_out(vty
, " route-map %s",
12561 ROUTEMAP_NAME(red
));
12564 vty_out(vty
, "\n");
12571 static int config_write_ospf_distance(struct vty
*vty
, struct ospf
*ospf
)
12573 struct route_node
*rn
;
12574 struct ospf_distance
*odistance
;
12576 if (ospf
->distance_all
)
12577 vty_out(vty
, " distance %d\n", ospf
->distance_all
);
12579 if (ospf
->distance_intra
|| ospf
->distance_inter
12580 || ospf
->distance_external
) {
12581 vty_out(vty
, " distance ospf");
12583 if (ospf
->distance_intra
)
12584 vty_out(vty
, " intra-area %d", ospf
->distance_intra
);
12585 if (ospf
->distance_inter
)
12586 vty_out(vty
, " inter-area %d", ospf
->distance_inter
);
12587 if (ospf
->distance_external
)
12588 vty_out(vty
, " external %d", ospf
->distance_external
);
12590 vty_out(vty
, "\n");
12593 for (rn
= route_top(ospf
->distance_table
); rn
; rn
= route_next(rn
))
12594 if ((odistance
= rn
->info
) != NULL
) {
12595 vty_out(vty
, " distance %d %pFX %s\n",
12596 odistance
->distance
, &rn
->p
,
12597 odistance
->access_list
? odistance
->access_list
12603 static int ospf_config_write_one(struct vty
*vty
, struct ospf
*ospf
)
12607 /* `router ospf' print. */
12608 if (ospf
->instance
&& strcmp(ospf
->name
, VRF_DEFAULT_NAME
)) {
12609 vty_out(vty
, "router ospf %d vrf %s\n", ospf
->instance
,
12611 } else if (ospf
->instance
) {
12612 vty_out(vty
, "router ospf %d\n", ospf
->instance
);
12613 } else if (strcmp(ospf
->name
, VRF_DEFAULT_NAME
)) {
12614 vty_out(vty
, "router ospf vrf %s\n", ospf
->name
);
12616 vty_out(vty
, "router ospf\n");
12618 if (!ospf
->networks
) {
12623 /* Router ID print. */
12624 if (ospf
->router_id_static
.s_addr
!= INADDR_ANY
)
12625 vty_out(vty
, " ospf router-id %pI4\n",
12626 &ospf
->router_id_static
);
12628 /* zebra opaque attributes configuration. */
12629 if (CHECK_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
))
12630 vty_out(vty
, " ospf send-extra-data zebra\n");
12632 /* ABR type print. */
12633 if (ospf
->abr_type
!= OSPF_ABR_DEFAULT
)
12634 vty_out(vty
, " ospf abr-type %s\n",
12635 ospf_abr_type_str
[ospf
->abr_type
]);
12637 /* log-adjacency-changes flag print. */
12638 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
12639 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
))
12640 vty_out(vty
, " log-adjacency-changes detail\n");
12641 else if (!SAVE_OSPF_LOG_ADJACENCY_CHANGES
)
12642 vty_out(vty
, " log-adjacency-changes\n");
12643 } else if (SAVE_OSPF_LOG_ADJACENCY_CHANGES
) {
12644 vty_out(vty
, " no log-adjacency-changes\n");
12647 /* RFC1583 compatibility flag print -- Compatible with CISCO
12649 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
))
12650 vty_out(vty
, " compatible rfc1583\n");
12652 /* auto-cost reference-bandwidth configuration. */
12653 if (ospf
->ref_bandwidth
!= OSPF_DEFAULT_REF_BANDWIDTH
) {
12655 "! Important: ensure reference bandwidth is consistent across all routers\n");
12656 vty_out(vty
, " auto-cost reference-bandwidth %d\n",
12657 ospf
->ref_bandwidth
);
12660 /* SPF timers print. */
12661 if (ospf
->spf_delay
!= OSPF_SPF_DELAY_DEFAULT
12662 || ospf
->spf_holdtime
!= OSPF_SPF_HOLDTIME_DEFAULT
12663 || ospf
->spf_max_holdtime
!= OSPF_SPF_MAX_HOLDTIME_DEFAULT
)
12664 vty_out(vty
, " timers throttle spf %d %d %d\n", ospf
->spf_delay
,
12665 ospf
->spf_holdtime
, ospf
->spf_max_holdtime
);
12667 /* LSA timers print. */
12668 if (ospf
->min_ls_interval
!= OSPF_MIN_LS_INTERVAL
)
12669 vty_out(vty
, " timers throttle lsa all %d\n",
12670 ospf
->min_ls_interval
);
12671 if (ospf
->min_ls_arrival
!= OSPF_MIN_LS_ARRIVAL
)
12672 vty_out(vty
, " timers lsa min-arrival %d\n",
12673 ospf
->min_ls_arrival
);
12675 /* Write multiplier print. */
12676 if (ospf
->write_oi_count
!= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
)
12677 vty_out(vty
, " ospf write-multiplier %d\n",
12678 ospf
->write_oi_count
);
12680 if (ospf
->max_multipath
!= MULTIPATH_NUM
)
12681 vty_out(vty
, " maximum-paths %d\n", ospf
->max_multipath
);
12683 /* Max-metric router-lsa print */
12684 config_write_stub_router(vty
, ospf
);
12686 /* SPF refresh parameters print. */
12687 if (ospf
->lsa_refresh_interval
!= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
12688 vty_out(vty
, " refresh timer %d\n", ospf
->lsa_refresh_interval
);
12690 /* Redistribute information print. */
12691 config_write_ospf_redistribute(vty
, ospf
);
12693 /* Graceful Restart print */
12694 config_write_ospf_gr(vty
, ospf
);
12695 config_write_ospf_gr_helper(vty
, ospf
);
12697 /* Print external route aggregation. */
12698 config_write_ospf_external_aggregator(vty
, ospf
);
12700 /* passive-interface print. */
12701 if (ospf
->passive_interface_default
== OSPF_IF_PASSIVE
)
12702 vty_out(vty
, " passive-interface default\n");
12704 /* proactive-arp print. */
12705 if (ospf
->proactive_arp
!= OSPF_PROACTIVE_ARP_DEFAULT
) {
12706 if (ospf
->proactive_arp
)
12707 vty_out(vty
, " proactive-arp\n");
12709 vty_out(vty
, " no proactive-arp\n");
12712 /* TI-LFA print. */
12713 if (ospf
->ti_lfa_enabled
) {
12714 if (ospf
->ti_lfa_protection_type
== OSPF_TI_LFA_NODE_PROTECTION
)
12715 vty_out(vty
, " fast-reroute ti-lfa node-protection\n");
12717 vty_out(vty
, " fast-reroute ti-lfa\n");
12720 /* Network area print. */
12721 config_write_network_area(vty
, ospf
);
12723 /* Area config print. */
12724 config_write_ospf_area(vty
, ospf
);
12726 /* static neighbor print. */
12727 config_write_ospf_nbr_nbma(vty
, ospf
);
12729 /* Virtual-Link print. */
12730 config_write_virtual_link(vty
, ospf
);
12732 /* Default metric configuration. */
12733 config_write_ospf_default_metric(vty
, ospf
);
12735 /* Distribute-list and default-information print. */
12736 config_write_ospf_distribute(vty
, ospf
);
12738 /* Distance configuration. */
12739 config_write_ospf_distance(vty
, ospf
);
12741 ospf_opaque_config_write_router(vty
, ospf
);
12743 /* LDP-Sync print */
12744 ospf_ldp_sync_write_config(vty
, ospf
);
12746 vty_out(vty
, "exit\n");
12752 /* OSPF configuration write function. */
12753 static int ospf_config_write(struct vty
*vty
)
12756 struct listnode
*ospf_node
= NULL
;
12759 if (listcount(om
->ospf
) == 0)
12762 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, ospf_node
, ospf
)) {
12763 /* VRF Default check if it is running.
12764 * Upon daemon start, there could be default instance
12765 * in absence of 'router ospf'/oi_running is disabled. */
12766 if (ospf
->vrf_id
== VRF_DEFAULT
&& ospf
->oi_running
)
12767 write
+= ospf_config_write_one(vty
, ospf
);
12768 /* For Non-Default VRF simply display the configuration,
12769 * even if it is not oi_running. */
12770 else if (ospf
->vrf_id
!= VRF_DEFAULT
)
12771 write
+= ospf_config_write_one(vty
, ospf
);
12776 void ospf_vty_show_init(void)
12778 /* "show ip ospf" commands. */
12779 install_element(VIEW_NODE
, &show_ip_ospf_cmd
);
12781 install_element(VIEW_NODE
, &show_ip_ospf_instance_cmd
);
12783 /* "show ip ospf database" commands. */
12784 install_element(VIEW_NODE
, &show_ip_ospf_database_cmd
);
12785 install_element(VIEW_NODE
, &show_ip_ospf_database_max_cmd
);
12786 install_element(VIEW_NODE
,
12787 &show_ip_ospf_database_type_adv_router_cmd
);
12788 install_element(VIEW_NODE
,
12789 &show_ip_ospf_instance_database_type_adv_router_cmd
);
12790 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_cmd
);
12791 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_max_cmd
);
12793 /* "show ip ospf interface" commands. */
12794 install_element(VIEW_NODE
, &show_ip_ospf_interface_cmd
);
12796 install_element(VIEW_NODE
, &show_ip_ospf_instance_interface_cmd
);
12797 /* "show ip ospf interface traffic */
12798 install_element(VIEW_NODE
, &show_ip_ospf_interface_traffic_cmd
);
12800 /* "show ip ospf neighbor" commands. */
12801 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_detail_cmd
);
12802 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_cmd
);
12803 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_id_cmd
);
12804 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_all_cmd
);
12805 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_cmd
);
12806 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_cmd
);
12807 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_all_cmd
);
12809 install_element(VIEW_NODE
,
12810 &show_ip_ospf_instance_neighbor_int_detail_cmd
);
12811 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_int_cmd
);
12812 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_id_cmd
);
12813 install_element(VIEW_NODE
,
12814 &show_ip_ospf_instance_neighbor_detail_all_cmd
);
12815 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_detail_cmd
);
12816 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_cmd
);
12817 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_all_cmd
);
12819 /* "show ip ospf route" commands. */
12820 install_element(VIEW_NODE
, &show_ip_ospf_route_cmd
);
12821 install_element(VIEW_NODE
, &show_ip_ospf_border_routers_cmd
);
12822 install_element(VIEW_NODE
, &show_ip_ospf_reachable_routers_cmd
);
12823 install_element(VIEW_NODE
, &show_ip_ospf_route_orr_cmd
);
12825 install_element(VIEW_NODE
, &show_ip_ospf_instance_route_cmd
);
12826 install_element(VIEW_NODE
, &show_ip_ospf_instance_border_routers_cmd
);
12827 install_element(VIEW_NODE
,
12828 &show_ip_ospf_instance_reachable_routers_cmd
);
12829 install_element(VIEW_NODE
, &show_ip_ospf_instance_route_orr_cmd
);
12831 /* "show ip ospf vrfs" commands. */
12832 install_element(VIEW_NODE
, &show_ip_ospf_vrfs_cmd
);
12834 /* "show ip ospf gr-helper details" command */
12835 install_element(VIEW_NODE
, &show_ip_ospf_gr_helper_cmd
);
12837 /* "show ip ospf summary-address" command */
12838 install_element(VIEW_NODE
, &show_ip_ospf_external_aggregator_cmd
);
12841 /* Initialization of OSPF interface. */
12842 static void ospf_vty_if_init(void)
12844 /* Install interface node. */
12845 if_cmd_init(config_write_interface
);
12847 /* "ip ospf authentication" commands. */
12848 install_element(INTERFACE_NODE
, &ip_ospf_authentication_args_addr_cmd
);
12849 install_element(INTERFACE_NODE
, &ip_ospf_authentication_addr_cmd
);
12850 install_element(INTERFACE_NODE
,
12851 &no_ip_ospf_authentication_args_addr_cmd
);
12852 install_element(INTERFACE_NODE
, &no_ip_ospf_authentication_addr_cmd
);
12853 install_element(INTERFACE_NODE
, &ip_ospf_authentication_key_addr_cmd
);
12854 install_element(INTERFACE_NODE
,
12855 &no_ip_ospf_authentication_key_authkey_addr_cmd
);
12856 install_element(INTERFACE_NODE
,
12857 &no_ospf_authentication_key_authkey_addr_cmd
);
12859 /* "ip ospf message-digest-key" commands. */
12860 install_element(INTERFACE_NODE
, &ip_ospf_message_digest_key_cmd
);
12861 install_element(INTERFACE_NODE
, &no_ip_ospf_message_digest_key_cmd
);
12863 /* "ip ospf cost" commands. */
12864 install_element(INTERFACE_NODE
, &ip_ospf_cost_cmd
);
12865 install_element(INTERFACE_NODE
, &no_ip_ospf_cost_cmd
);
12867 /* "ip ospf mtu-ignore" commands. */
12868 install_element(INTERFACE_NODE
, &ip_ospf_mtu_ignore_addr_cmd
);
12869 install_element(INTERFACE_NODE
, &no_ip_ospf_mtu_ignore_addr_cmd
);
12871 /* "ip ospf dead-interval" commands. */
12872 install_element(INTERFACE_NODE
, &ip_ospf_dead_interval_cmd
);
12873 install_element(INTERFACE_NODE
,
12874 &ip_ospf_dead_interval_minimal_addr_cmd
);
12875 install_element(INTERFACE_NODE
, &no_ip_ospf_dead_interval_cmd
);
12877 /* "ip ospf hello-interval" commands. */
12878 install_element(INTERFACE_NODE
, &ip_ospf_hello_interval_cmd
);
12879 install_element(INTERFACE_NODE
, &no_ip_ospf_hello_interval_cmd
);
12881 /* "ip ospf network" commands. */
12882 install_element(INTERFACE_NODE
, &ip_ospf_network_cmd
);
12883 install_element(INTERFACE_NODE
, &no_ip_ospf_network_cmd
);
12885 /* "ip ospf priority" commands. */
12886 install_element(INTERFACE_NODE
, &ip_ospf_priority_cmd
);
12887 install_element(INTERFACE_NODE
, &no_ip_ospf_priority_cmd
);
12889 /* "ip ospf retransmit-interval" commands. */
12890 install_element(INTERFACE_NODE
, &ip_ospf_retransmit_interval_addr_cmd
);
12891 install_element(INTERFACE_NODE
,
12892 &no_ip_ospf_retransmit_interval_addr_cmd
);
12894 /* "ip ospf transmit-delay" commands. */
12895 install_element(INTERFACE_NODE
, &ip_ospf_transmit_delay_addr_cmd
);
12896 install_element(INTERFACE_NODE
, &no_ip_ospf_transmit_delay_addr_cmd
);
12898 /* "ip ospf area" commands. */
12899 install_element(INTERFACE_NODE
, &ip_ospf_area_cmd
);
12900 install_element(INTERFACE_NODE
, &no_ip_ospf_area_cmd
);
12902 /* "ip ospf passive" commands. */
12903 install_element(INTERFACE_NODE
, &ip_ospf_passive_cmd
);
12904 install_element(INTERFACE_NODE
, &no_ip_ospf_passive_cmd
);
12906 /* These commands are compatibitliy for previous version. */
12907 install_element(INTERFACE_NODE
, &ospf_authentication_key_cmd
);
12908 install_element(INTERFACE_NODE
, &ospf_message_digest_key_cmd
);
12909 install_element(INTERFACE_NODE
, &no_ospf_message_digest_key_cmd
);
12910 install_element(INTERFACE_NODE
, &ospf_dead_interval_cmd
);
12911 install_element(INTERFACE_NODE
, &no_ospf_dead_interval_cmd
);
12912 install_element(INTERFACE_NODE
, &ospf_hello_interval_cmd
);
12913 install_element(INTERFACE_NODE
, &no_ospf_hello_interval_cmd
);
12914 install_element(INTERFACE_NODE
, &ospf_cost_cmd
);
12915 install_element(INTERFACE_NODE
, &no_ospf_cost_cmd
);
12916 install_element(INTERFACE_NODE
, &ospf_network_cmd
);
12917 install_element(INTERFACE_NODE
, &no_ospf_network_cmd
);
12918 install_element(INTERFACE_NODE
, &ospf_priority_cmd
);
12919 install_element(INTERFACE_NODE
, &no_ospf_priority_cmd
);
12920 install_element(INTERFACE_NODE
, &ospf_retransmit_interval_cmd
);
12921 install_element(INTERFACE_NODE
, &no_ospf_retransmit_interval_cmd
);
12922 install_element(INTERFACE_NODE
, &ospf_transmit_delay_cmd
);
12923 install_element(INTERFACE_NODE
, &no_ospf_transmit_delay_cmd
);
12926 static void ospf_vty_zebra_init(void)
12928 install_element(OSPF_NODE
, &ospf_redistribute_source_cmd
);
12929 install_element(OSPF_NODE
, &no_ospf_redistribute_source_cmd
);
12930 install_element(OSPF_NODE
, &ospf_redistribute_instance_source_cmd
);
12931 install_element(OSPF_NODE
, &no_ospf_redistribute_instance_source_cmd
);
12933 install_element(OSPF_NODE
, &ospf_distribute_list_out_cmd
);
12934 install_element(OSPF_NODE
, &no_ospf_distribute_list_out_cmd
);
12936 install_element(OSPF_NODE
, &ospf_default_information_originate_cmd
);
12937 install_element(OSPF_NODE
, &no_ospf_default_information_originate_cmd
);
12939 install_element(OSPF_NODE
, &ospf_default_metric_cmd
);
12940 install_element(OSPF_NODE
, &no_ospf_default_metric_cmd
);
12942 install_element(OSPF_NODE
, &ospf_distance_cmd
);
12943 install_element(OSPF_NODE
, &no_ospf_distance_cmd
);
12944 install_element(OSPF_NODE
, &no_ospf_distance_ospf_cmd
);
12945 install_element(OSPF_NODE
, &ospf_distance_ospf_cmd
);
12947 /*Ospf garcefull restart helper configurations */
12948 install_element(OSPF_NODE
, &ospf_gr_helper_enable_cmd
);
12949 install_element(OSPF_NODE
, &no_ospf_gr_helper_enable_cmd
);
12950 install_element(OSPF_NODE
, &ospf_gr_helper_enable_lsacheck_cmd
);
12951 install_element(OSPF_NODE
, &no_ospf_gr_helper_enable_lsacheck_cmd
);
12952 install_element(OSPF_NODE
, &ospf_gr_helper_supported_grace_time_cmd
);
12953 install_element(OSPF_NODE
, &no_ospf_gr_helper_supported_grace_time_cmd
);
12954 install_element(OSPF_NODE
, &ospf_gr_helper_planned_only_cmd
);
12955 install_element(OSPF_NODE
, &no_ospf_gr_helper_planned_only_cmd
);
12957 /* External LSA summarisation config commands.*/
12958 install_element(OSPF_NODE
, &ospf_external_route_aggregation_cmd
);
12959 install_element(OSPF_NODE
, &no_ospf_external_route_aggregation_cmd
);
12960 install_element(OSPF_NODE
,
12961 &ospf_external_route_aggregation_no_adrvertise_cmd
);
12962 install_element(OSPF_NODE
,
12963 &no_ospf_external_route_aggregation_no_adrvertise_cmd
);
12964 install_element(OSPF_NODE
, &ospf_route_aggregation_timer_cmd
);
12965 install_element(OSPF_NODE
, &no_ospf_route_aggregation_timer_cmd
);
12968 static int ospf_config_write(struct vty
*vty
);
12969 static struct cmd_node ospf_node
= {
12972 .parent_node
= CONFIG_NODE
,
12973 .prompt
= "%s(config-router)# ",
12974 .config_write
= ospf_config_write
,
12977 static void ospf_interface_clear(struct interface
*ifp
)
12979 if (!if_is_operative(ifp
))
12982 if (IS_DEBUG_OSPF(ism
, ISM_EVENTS
))
12983 zlog_debug("ISM[%s]: clear by reset", ifp
->name
);
12985 ospf_if_reset(ifp
);
12988 DEFUN (clear_ip_ospf_interface
,
12989 clear_ip_ospf_interface_cmd
,
12990 "clear ip ospf [vrf NAME] interface [IFNAME]",
12993 "OSPF information\n"
12995 "Interface information\n"
12996 "Interface name\n")
12998 int idx_ifname
= 0;
13000 struct interface
*ifp
;
13001 struct listnode
*node
;
13002 struct ospf
*ospf
= NULL
;
13003 char *vrf_name
= NULL
;
13004 vrf_id_t vrf_id
= VRF_DEFAULT
;
13005 struct vrf
*vrf
= NULL
;
13007 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
13008 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
13009 if (vrf_name
&& strmatch(vrf_name
, VRF_DEFAULT_NAME
))
13012 vrf
= vrf_lookup_by_name(vrf_name
);
13014 vrf_id
= vrf
->vrf_id
;
13016 if (!argv_find(argv
, argc
, "IFNAME", &idx_ifname
)) {
13017 /* Clear all the ospfv2 interfaces. */
13018 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
13019 if (vrf_id
!= ospf
->vrf_id
)
13022 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
13023 FOR_ALL_INTERFACES (vrf
, ifp
)
13024 ospf_interface_clear(ifp
);
13027 /* Interface name is specified. */
13028 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf_id
);
13030 vty_out(vty
, "No such interface name\n");
13032 ospf_interface_clear(ifp
);
13035 return CMD_SUCCESS
;
13038 DEFPY_HIDDEN(ospf_lsa_refresh_timer
, ospf_lsa_refresh_timer_cmd
,
13039 "[no$no] ospf lsa-refresh [(120-1800)]$value",
13041 "OSPF lsa refresh timer\n"
13042 "timer value in seconds\n")
13044 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
13047 ospf
->lsa_refresh_timer
= OSPF_LS_REFRESH_TIME
;
13049 ospf
->lsa_refresh_timer
= value
;
13051 return CMD_SUCCESS
;
13054 DEFPY_HIDDEN(ospf_maxage_delay_timer
, ospf_maxage_delay_timer_cmd
,
13055 "[no$no] ospf maxage-delay [(0-60)]$value",
13057 "OSPF lsa maxage delay timer\n"
13058 "timer value in seconds\n")
13060 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
13063 ospf
->maxage_delay
= OSPF_LSA_MAXAGE_REMOVE_DELAY_DEFAULT
;
13065 ospf
->maxage_delay
= value
;
13067 THREAD_OFF(ospf
->t_maxage
);
13068 OSPF_TIMER_ON(ospf
->t_maxage
, ospf_maxage_lsa_remover
,
13069 ospf
->maxage_delay
);
13071 return CMD_SUCCESS
;
13074 void ospf_vty_clear_init(void)
13076 install_element(ENABLE_NODE
, &clear_ip_ospf_interface_cmd
);
13077 install_element(ENABLE_NODE
, &clear_ip_ospf_process_cmd
);
13078 install_element(ENABLE_NODE
, &clear_ip_ospf_neighbor_cmd
);
13082 /* Install OSPF related vty commands. */
13083 void ospf_vty_init(void)
13085 /* Install ospf top node. */
13086 install_node(&ospf_node
);
13088 /* "router ospf" commands. */
13089 install_element(CONFIG_NODE
, &router_ospf_cmd
);
13090 install_element(CONFIG_NODE
, &no_router_ospf_cmd
);
13093 install_default(OSPF_NODE
);
13095 /* "ospf router-id" commands. */
13096 install_element(OSPF_NODE
, &ospf_router_id_cmd
);
13097 install_element(OSPF_NODE
, &ospf_router_id_old_cmd
);
13098 install_element(OSPF_NODE
, &no_ospf_router_id_cmd
);
13100 /* "passive-interface" commands. */
13101 install_element(OSPF_NODE
, &ospf_passive_interface_default_cmd
);
13102 install_element(OSPF_NODE
, &ospf_passive_interface_addr_cmd
);
13103 install_element(OSPF_NODE
, &no_ospf_passive_interface_default_cmd
);
13104 install_element(OSPF_NODE
, &no_ospf_passive_interface_addr_cmd
);
13106 /* "ospf abr-type" commands. */
13107 install_element(OSPF_NODE
, &ospf_abr_type_cmd
);
13108 install_element(OSPF_NODE
, &no_ospf_abr_type_cmd
);
13110 /* "ospf log-adjacency-changes" commands. */
13111 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_cmd
);
13112 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_detail_cmd
);
13113 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_cmd
);
13114 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_detail_cmd
);
13116 /* "ospf rfc1583-compatible" commands. */
13117 install_element(OSPF_NODE
, &ospf_compatible_rfc1583_cmd
);
13118 install_element(OSPF_NODE
, &no_ospf_compatible_rfc1583_cmd
);
13119 install_element(OSPF_NODE
, &ospf_rfc1583_flag_cmd
);
13120 install_element(OSPF_NODE
, &no_ospf_rfc1583_flag_cmd
);
13122 /* "ospf send-extra-data zebra" commands. */
13123 install_element(OSPF_NODE
, &ospf_send_extra_data_cmd
);
13125 /* "network area" commands. */
13126 install_element(OSPF_NODE
, &ospf_network_area_cmd
);
13127 install_element(OSPF_NODE
, &no_ospf_network_area_cmd
);
13129 /* "area authentication" commands. */
13130 install_element(OSPF_NODE
,
13131 &ospf_area_authentication_message_digest_cmd
);
13132 install_element(OSPF_NODE
, &ospf_area_authentication_cmd
);
13133 install_element(OSPF_NODE
, &no_ospf_area_authentication_cmd
);
13135 /* "area range" commands. */
13136 install_element(OSPF_NODE
, &ospf_area_range_cmd
);
13137 install_element(OSPF_NODE
, &ospf_area_range_cost_cmd
);
13138 install_element(OSPF_NODE
, &ospf_area_range_not_advertise_cmd
);
13139 install_element(OSPF_NODE
, &no_ospf_area_range_cmd
);
13140 install_element(OSPF_NODE
, &no_ospf_area_range_substitute_cmd
);
13142 /* "area virtual-link" commands. */
13143 install_element(OSPF_NODE
, &ospf_area_vlink_cmd
);
13144 install_element(OSPF_NODE
, &ospf_area_vlink_intervals_cmd
);
13145 install_element(OSPF_NODE
, &no_ospf_area_vlink_cmd
);
13146 install_element(OSPF_NODE
, &no_ospf_area_vlink_intervals_cmd
);
13149 /* "area stub" commands. */
13150 install_element(OSPF_NODE
, &ospf_area_stub_no_summary_cmd
);
13151 install_element(OSPF_NODE
, &ospf_area_stub_cmd
);
13152 install_element(OSPF_NODE
, &no_ospf_area_stub_no_summary_cmd
);
13153 install_element(OSPF_NODE
, &no_ospf_area_stub_cmd
);
13155 /* "area nssa" commands. */
13156 install_element(OSPF_NODE
, &ospf_area_nssa_cmd
);
13157 install_element(OSPF_NODE
, &ospf_area_nssa_translate_cmd
);
13158 install_element(OSPF_NODE
, &ospf_area_nssa_no_summary_cmd
);
13159 install_element(OSPF_NODE
, &no_ospf_area_nssa_no_summary_cmd
);
13160 install_element(OSPF_NODE
, &ospf_area_nssa_suppress_fa_cmd
);
13161 install_element(OSPF_NODE
, &no_ospf_area_nssa_suppress_fa_cmd
);
13162 install_element(OSPF_NODE
, &no_ospf_area_nssa_cmd
);
13164 install_element(OSPF_NODE
, &ospf_area_default_cost_cmd
);
13165 install_element(OSPF_NODE
, &no_ospf_area_default_cost_cmd
);
13167 install_element(OSPF_NODE
, &ospf_area_shortcut_cmd
);
13168 install_element(OSPF_NODE
, &no_ospf_area_shortcut_cmd
);
13170 install_element(OSPF_NODE
, &ospf_area_export_list_cmd
);
13171 install_element(OSPF_NODE
, &no_ospf_area_export_list_cmd
);
13173 install_element(OSPF_NODE
, &ospf_area_filter_list_cmd
);
13174 install_element(OSPF_NODE
, &no_ospf_area_filter_list_cmd
);
13176 install_element(OSPF_NODE
, &ospf_area_import_list_cmd
);
13177 install_element(OSPF_NODE
, &no_ospf_area_import_list_cmd
);
13179 /* SPF timer commands */
13180 install_element(OSPF_NODE
, &ospf_timers_throttle_spf_cmd
);
13181 install_element(OSPF_NODE
, &no_ospf_timers_throttle_spf_cmd
);
13183 /* LSA timers commands */
13184 install_element(OSPF_NODE
, &ospf_timers_min_ls_interval_cmd
);
13185 install_element(OSPF_NODE
, &no_ospf_timers_min_ls_interval_cmd
);
13186 install_element(OSPF_NODE
, &ospf_timers_lsa_min_arrival_cmd
);
13187 install_element(OSPF_NODE
, &no_ospf_timers_lsa_min_arrival_cmd
);
13189 /* refresh timer commands */
13190 install_element(OSPF_NODE
, &ospf_refresh_timer_cmd
);
13191 install_element(OSPF_NODE
, &no_ospf_refresh_timer_val_cmd
);
13193 /* max-metric commands */
13194 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_admin_cmd
);
13195 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_admin_cmd
);
13196 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_startup_cmd
);
13197 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_startup_cmd
);
13198 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_shutdown_cmd
);
13199 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_shutdown_cmd
);
13201 /* reference bandwidth commands */
13202 install_element(OSPF_NODE
, &ospf_auto_cost_reference_bandwidth_cmd
);
13203 install_element(OSPF_NODE
, &no_ospf_auto_cost_reference_bandwidth_cmd
);
13205 /* "neighbor" commands. */
13206 install_element(OSPF_NODE
, &ospf_neighbor_cmd
);
13207 install_element(OSPF_NODE
, &ospf_neighbor_poll_interval_cmd
);
13208 install_element(OSPF_NODE
, &no_ospf_neighbor_cmd
);
13209 install_element(OSPF_NODE
, &no_ospf_neighbor_poll_cmd
);
13211 /* write multiplier commands */
13212 install_element(OSPF_NODE
, &ospf_write_multiplier_cmd
);
13213 install_element(OSPF_NODE
, &write_multiplier_cmd
);
13214 install_element(OSPF_NODE
, &no_ospf_write_multiplier_cmd
);
13215 install_element(OSPF_NODE
, &no_write_multiplier_cmd
);
13217 /* "proactive-arp" commands. */
13218 install_element(OSPF_NODE
, &ospf_proactive_arp_cmd
);
13219 install_element(OSPF_NODE
, &no_ospf_proactive_arp_cmd
);
13221 /* TI-LFA commands */
13222 install_element(OSPF_NODE
, &ospf_ti_lfa_cmd
);
13223 install_element(OSPF_NODE
, &no_ospf_ti_lfa_cmd
);
13225 /* Max path configurations */
13226 install_element(OSPF_NODE
, &ospf_max_multipath_cmd
);
13227 install_element(OSPF_NODE
, &no_ospf_max_multipath_cmd
);
13229 vrf_cmd_init(NULL
);
13231 install_element(OSPF_NODE
, &ospf_lsa_refresh_timer_cmd
);
13232 install_element(OSPF_NODE
, &ospf_maxage_delay_timer_cmd
);
13234 /* Init interface related vty commands. */
13235 ospf_vty_if_init();
13237 /* Init zebra related vty commands. */
13238 ospf_vty_zebra_init();