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 #include "ospfd/ospf_vty_clippy.c"
190 DEFUN_NOSH (router_ospf
,
192 "router ospf [{(1-65535)|vrf NAME}]",
193 "Enable a routing process\n"
194 "Start OSPF configuration\n"
198 unsigned short instance
;
199 const char *vrf_name
;
200 bool created
= false;
204 ret
= ospf_router_cmd_parse(vty
, argv
, argc
, &instance
, &vrf_name
);
205 if (ret
!= CMD_SUCCESS
)
208 if (instance
!= ospf_instance
) {
209 VTY_PUSH_CONTEXT_NULL(OSPF_NODE
);
210 return CMD_NOT_MY_INSTANCE
;
213 ospf
= ospf_get(instance
, vrf_name
, &created
);
216 if (DFLT_OSPF_LOG_ADJACENCY_CHANGES
)
217 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
219 if (IS_DEBUG_OSPF_EVENT
)
221 "Config command 'router ospf %d' received, vrf %s id %u oi_running %u",
222 ospf
->instance
, ospf_get_name(ospf
), ospf
->vrf_id
,
225 VTY_PUSH_CONTEXT(OSPF_NODE
, ospf
);
230 DEFUN (no_router_ospf
,
232 "no router ospf [{(1-65535)|vrf NAME}]",
234 "Enable a routing process\n"
235 "Start OSPF configuration\n"
239 unsigned short instance
;
240 const char *vrf_name
;
244 ret
= ospf_router_cmd_parse(vty
, argv
, argc
, &instance
, &vrf_name
);
245 if (ret
!= CMD_SUCCESS
)
248 if (instance
!= ospf_instance
)
249 return CMD_NOT_MY_INSTANCE
;
251 ospf
= ospf_lookup(instance
, vrf_name
);
255 ret
= CMD_WARNING_CONFIG_FAILED
;
261 DEFPY (ospf_router_id
,
263 "ospf router-id A.B.C.D",
264 "OSPF specific commands\n"
265 "router-id for the OSPF process\n"
266 "OSPF router-id in IP address format\n")
268 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
270 struct listnode
*node
;
271 struct ospf_area
*area
;
273 ospf
->router_id_static
= router_id
;
275 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
276 if (area
->full_nbrs
) {
278 "For this router-id change to take effect, use \"clear ip ospf process\" command\n");
282 ospf_router_id_update(ospf
);
287 DEFUN_HIDDEN (ospf_router_id_old
,
288 ospf_router_id_old_cmd
,
290 "router-id for the OSPF process\n"
291 "OSPF router-id in IP address format\n")
293 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
295 struct listnode
*node
;
296 struct ospf_area
*area
;
297 struct in_addr router_id
;
300 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &router_id
);
302 vty_out(vty
, "Please specify Router ID by A.B.C.D\n");
303 return CMD_WARNING_CONFIG_FAILED
;
306 ospf
->router_id_static
= router_id
;
308 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
309 if (area
->full_nbrs
) {
311 "For this router-id change to take effect, use \"clear ip ospf process\" command\n");
315 ospf_router_id_update(ospf
);
320 DEFPY (no_ospf_router_id
,
321 no_ospf_router_id_cmd
,
322 "no ospf router-id [A.B.C.D]",
324 "OSPF specific commands\n"
325 "router-id for the OSPF process\n"
326 "OSPF router-id in IP address format\n")
328 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
329 struct listnode
*node
;
330 struct ospf_area
*area
;
333 if (!IPV4_ADDR_SAME(&ospf
->router_id_static
, &router_id
)) {
334 vty_out(vty
, "%% OSPF router-id doesn't match\n");
335 return CMD_WARNING_CONFIG_FAILED
;
339 ospf
->router_id_static
.s_addr
= 0;
341 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
342 if (area
->full_nbrs
) {
344 "For this router-id change to take effect, use \"clear ip ospf process\" command\n");
348 ospf_router_id_update(ospf
);
354 static void ospf_passive_interface_default_update(struct ospf
*ospf
,
358 struct ospf_interface
*oi
;
360 ospf
->passive_interface_default
= newval
;
362 /* update multicast memberships */
363 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, ln
, oi
))
364 ospf_if_set_multicast(oi
);
367 static void ospf_passive_interface_update(struct interface
*ifp
,
368 struct ospf_if_params
*params
,
369 struct in_addr addr
, uint8_t newval
)
371 struct route_node
*rn
;
373 if (OSPF_IF_PARAM_CONFIGURED(params
, passive_interface
)) {
374 if (params
->passive_interface
== newval
)
377 params
->passive_interface
= newval
;
378 UNSET_IF_PARAM(params
, passive_interface
);
379 if (params
!= IF_DEF_PARAMS(ifp
)) {
380 ospf_free_if_params(ifp
, addr
);
381 ospf_if_update_params(ifp
, addr
);
384 params
->passive_interface
= newval
;
385 SET_IF_PARAM(params
, passive_interface
);
389 * XXX We should call ospf_if_set_multicast on exactly those
390 * interfaces for which the passive property changed. It is too much
391 * work to determine this set, so we do this for every interface.
392 * This is safe and reasonable because ospf_if_set_multicast uses a
393 * record of joined groups to avoid systems calls if the desired
394 * memberships match the current memership.
397 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
398 struct ospf_interface
*oi
= rn
->info
;
401 ospf_if_set_multicast(oi
);
405 * XXX It is not clear what state transitions the interface needs to
406 * undergo when going from active to passive and vice versa. Fixing
407 * this will require precise identification of interfaces having such a
412 DEFUN (ospf_passive_interface_default
,
413 ospf_passive_interface_default_cmd
,
414 "passive-interface default",
415 "Suppress routing updates on an interface\n"
416 "Suppress routing updates on interfaces by default\n")
418 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
420 ospf_passive_interface_default_update(ospf
, OSPF_IF_PASSIVE
);
425 DEFUN_HIDDEN (ospf_passive_interface_addr
,
426 ospf_passive_interface_addr_cmd
,
427 "passive-interface IFNAME [A.B.C.D]",
428 "Suppress routing updates on an interface\n"
432 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
434 struct interface
*ifp
= NULL
;
435 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
436 struct ospf_if_params
*params
;
440 "This command is deprecated, because it is not VRF-aware.\n");
442 "Please, use \"ip ospf passive\" on an interface instead.\n");
444 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
445 ifp
= if_get_by_name(argv
[1]->arg
, ospf
->vrf_id
, ospf
->name
);
448 vty_out(vty
, "interface %s not found.\n", (char *)argv
[1]->arg
);
449 return CMD_WARNING_CONFIG_FAILED
;
453 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
456 "Please specify interface address by A.B.C.D\n");
457 return CMD_WARNING_CONFIG_FAILED
;
460 params
= ospf_get_if_params(ifp
, addr
);
461 ospf_if_update_params(ifp
, addr
);
463 params
= IF_DEF_PARAMS(ifp
);
466 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_PASSIVE
);
471 DEFUN (no_ospf_passive_interface_default
,
472 no_ospf_passive_interface_default_cmd
,
473 "no passive-interface default",
475 "Allow routing updates on an interface\n"
476 "Allow routing updates on interfaces by default\n")
478 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
480 ospf_passive_interface_default_update(ospf
, OSPF_IF_ACTIVE
);
485 DEFUN_HIDDEN (no_ospf_passive_interface
,
486 no_ospf_passive_interface_addr_cmd
,
487 "no passive-interface IFNAME [A.B.C.D]",
489 "Allow routing updates on an interface\n"
493 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
495 struct interface
*ifp
= NULL
;
496 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
497 struct ospf_if_params
*params
;
501 "This command is deprecated, because it is not VRF-aware.\n");
503 "Please, use \"no ip ospf passive\" on an interface instead.\n");
505 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
506 ifp
= if_get_by_name(argv
[2]->arg
, ospf
->vrf_id
, ospf
->name
);
509 vty_out(vty
, "interface %s not found.\n", (char *)argv
[2]->arg
);
510 return CMD_WARNING_CONFIG_FAILED
;
514 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
517 "Please specify interface address by A.B.C.D\n");
518 return CMD_WARNING_CONFIG_FAILED
;
520 params
= ospf_lookup_if_params(ifp
, addr
);
524 params
= IF_DEF_PARAMS(ifp
);
527 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_ACTIVE
);
533 DEFUN (ospf_network_area
,
534 ospf_network_area_cmd
,
535 "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
536 "Enable routing on an IP network\n"
537 "OSPF network prefix\n"
538 "Set the OSPF area ID\n"
539 "OSPF area ID in IP address format\n"
540 "OSPF area ID as a decimal value\n")
542 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
543 int idx_ipv4_prefixlen
= 1;
544 int idx_ipv4_number
= 3;
545 struct prefix_ipv4 p
;
546 struct in_addr area_id
;
550 if (ospf
->instance
) {
552 "The network command is not supported in multi-instance ospf\n");
553 return CMD_WARNING_CONFIG_FAILED
;
556 count
= ospf_count_area_params(ospf
);
559 "Please remove all ip ospf area x.x.x.x commands first.\n");
560 if (IS_DEBUG_OSPF_EVENT
)
562 "%s ospf vrf %s num of %u ip ospf area x config",
563 __func__
, ospf_get_name(ospf
), count
);
564 return CMD_WARNING_CONFIG_FAILED
;
567 /* Get network prefix and Area ID. */
568 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
569 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
571 ret
= ospf_network_set(ospf
, &p
, area_id
, format
);
573 vty_out(vty
, "There is already same network statement.\n");
574 return CMD_WARNING_CONFIG_FAILED
;
580 DEFUN (no_ospf_network_area
,
581 no_ospf_network_area_cmd
,
582 "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
584 "Enable routing on an IP network\n"
585 "OSPF network prefix\n"
586 "Set the OSPF area ID\n"
587 "OSPF area ID in IP address format\n"
588 "OSPF area ID as a decimal value\n")
590 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
591 int idx_ipv4_prefixlen
= 2;
592 int idx_ipv4_number
= 4;
593 struct prefix_ipv4 p
;
594 struct in_addr area_id
;
597 if (ospf
->instance
) {
599 "The network command is not supported in multi-instance ospf\n");
600 return CMD_WARNING_CONFIG_FAILED
;
603 /* Get network prefix and Area ID. */
604 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
605 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
607 ret
= ospf_network_unset(ospf
, &p
, area_id
);
610 "Can't find specified network area configuration.\n");
611 return CMD_WARNING_CONFIG_FAILED
;
617 DEFUN (ospf_area_range
,
619 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]",
620 "OSPF area parameters\n"
621 "OSPF area ID in IP address format\n"
622 "OSPF area ID as a decimal value\n"
623 "Summarize routes matching address/mask (border routers only)\n"
624 "Area range prefix\n"
625 "Advertise this range (default)\n"
626 "User specified metric for this range\n"
627 "Advertised metric for this range\n")
629 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
630 int idx_ipv4_number
= 1;
631 int idx_ipv4_prefixlen
= 3;
633 struct prefix_ipv4 p
;
634 struct in_addr area_id
;
638 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
639 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
641 ospf_area_range_set(ospf
, area_id
, &p
, OSPF_AREA_RANGE_ADVERTISE
);
642 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
645 cost
= strtoul(argv
[idx_cost
]->arg
, NULL
, 10);
646 ospf_area_range_cost_set(ospf
, area_id
, &p
, cost
);
652 DEFUN (ospf_area_range_cost
,
653 ospf_area_range_cost_cmd
,
654 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M {cost (0-16777215)|substitute A.B.C.D/M}",
655 "OSPF area parameters\n"
656 "OSPF area ID in IP address format\n"
657 "OSPF area ID as a decimal value\n"
658 "Summarize routes matching address/mask (border routers only)\n"
659 "Area range prefix\n"
660 "User specified metric for this range\n"
661 "Advertised metric for this range\n"
662 "Announce area range as another prefix\n"
663 "Network prefix to be announced instead of range\n")
665 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
666 int idx_ipv4_number
= 1;
667 int idx_ipv4_prefixlen
= 3;
669 struct prefix_ipv4 p
, s
;
670 struct in_addr area_id
;
674 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
675 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
677 ospf_area_range_set(ospf
, area_id
, &p
, OSPF_AREA_RANGE_ADVERTISE
);
678 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
681 if (argv_find(argv
, argc
, "cost", &idx
)) {
682 cost
= strtoul(argv
[idx
+ 1]->arg
, NULL
, 10);
683 ospf_area_range_cost_set(ospf
, area_id
, &p
, cost
);
687 if (argv_find(argv
, argc
, "substitute", &idx
)) {
688 str2prefix_ipv4(argv
[idx
+ 1]->arg
, &s
);
689 ospf_area_range_substitute_set(ospf
, area_id
, &p
, &s
);
695 DEFUN (ospf_area_range_not_advertise
,
696 ospf_area_range_not_advertise_cmd
,
697 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise",
698 "OSPF area parameters\n"
699 "OSPF area ID in IP address format\n"
700 "OSPF area ID as a decimal value\n"
701 "Summarize routes matching address/mask (border routers only)\n"
702 "Area range prefix\n"
703 "DoNotAdvertise this range\n")
705 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
706 int idx_ipv4_number
= 1;
707 int idx_ipv4_prefixlen
= 3;
708 struct prefix_ipv4 p
;
709 struct in_addr area_id
;
712 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
713 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
715 ospf_area_range_set(ospf
, area_id
, &p
, 0);
716 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
718 ospf_area_range_substitute_unset(ospf
, area_id
, &p
);
723 DEFUN (no_ospf_area_range
,
724 no_ospf_area_range_cmd
,
725 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]",
727 "OSPF area parameters\n"
728 "OSPF area ID in IP address format\n"
729 "OSPF area ID as a decimal value\n"
730 "Summarize routes matching address/mask (border routers only)\n"
731 "Area range prefix\n"
732 "User specified metric for this range\n"
733 "Advertised metric for this range\n"
734 "Advertise this range (default)\n"
735 "User specified metric for this range\n"
736 "Advertised metric for this range\n"
737 "DoNotAdvertise this range\n")
739 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
740 int idx_ipv4_number
= 2;
741 int idx_ipv4_prefixlen
= 4;
742 struct prefix_ipv4 p
;
743 struct in_addr area_id
;
746 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
747 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
749 ospf_area_range_unset(ospf
, area_id
, &p
);
754 DEFUN (no_ospf_area_range_substitute
,
755 no_ospf_area_range_substitute_cmd
,
756 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
758 "OSPF area parameters\n"
759 "OSPF area ID in IP address format\n"
760 "OSPF area ID as a decimal value\n"
761 "Summarize routes matching address/mask (border routers only)\n"
762 "Area range prefix\n"
763 "Announce area range as another prefix\n"
764 "Network prefix to be announced instead of range\n")
766 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
767 int idx_ipv4_number
= 2;
768 int idx_ipv4_prefixlen
= 4;
769 int idx_ipv4_prefixlen_2
= 6;
770 struct prefix_ipv4 p
, s
;
771 struct in_addr area_id
;
774 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
775 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
776 str2prefix_ipv4(argv
[idx_ipv4_prefixlen_2
]->arg
, &s
);
778 ospf_area_range_substitute_unset(ospf
, area_id
, &p
);
784 /* Command Handler Logic in VLink stuff is delicate!!
786 ALTER AT YOUR OWN RISK!!!!
788 Various dummy values are used to represent 'NoChange' state for
789 VLink configuration NOT being changed by a VLink command, and
790 special syntax is used within the command strings so that the
791 typed in command verbs can be seen in the configuration command
792 bacckend handler. This is to drastically reduce the verbeage
793 required to coe up with a reasonably compatible Cisco VLink command
795 - Matthew Grant <grantma@anathoth.gen.nz>
796 Wed, 21 Feb 2001 15:13:52 +1300
799 /* Configuration data for virtual links
801 struct ospf_vl_config_data
{
802 struct vty
*vty
; /* vty stuff */
803 struct in_addr area_id
; /* area ID from command line */
804 int area_id_fmt
; /* command line area ID format */
805 struct in_addr vl_peer
; /* command line vl_peer */
806 int auth_type
; /* Authehntication type, if given */
807 char *auth_key
; /* simple password if present */
808 int crypto_key_id
; /* Cryptographic key ID */
809 char *md5_key
; /* MD5 authentication key */
810 int hello_interval
; /* Obvious what these are... */
811 int retransmit_interval
;
816 static void ospf_vl_config_data_init(struct ospf_vl_config_data
*vl_config
,
819 memset(vl_config
, 0, sizeof(struct ospf_vl_config_data
));
820 vl_config
->auth_type
= OSPF_AUTH_CMD_NOTSEEN
;
821 vl_config
->vty
= vty
;
824 static struct ospf_vl_data
*
825 ospf_find_vl_data(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
827 struct ospf_area
*area
;
828 struct ospf_vl_data
*vl_data
;
830 struct in_addr area_id
;
832 vty
= vl_config
->vty
;
833 area_id
= vl_config
->area_id
;
835 if (area_id
.s_addr
== OSPF_AREA_BACKBONE
) {
837 "Configuring VLs over the backbone is not allowed\n");
840 area
= ospf_area_get(ospf
, area_id
);
841 ospf_area_display_format_set(ospf
, area
, vl_config
->area_id_fmt
);
843 if (area
->external_routing
!= OSPF_AREA_DEFAULT
) {
844 if (vl_config
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
845 vty_out(vty
, "Area %pI4 is %s\n", &area_id
,
846 area
->external_routing
== OSPF_AREA_NSSA
850 vty_out(vty
, "Area %ld is %s\n",
851 (unsigned long)ntohl(area_id
.s_addr
),
852 area
->external_routing
== OSPF_AREA_NSSA
858 if ((vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
->vl_peer
))
860 vl_data
= ospf_vl_data_new(area
, vl_config
->vl_peer
);
861 if (vl_data
->vl_oi
== NULL
) {
862 vl_data
->vl_oi
= ospf_vl_new(ospf
, vl_data
);
863 ospf_vl_add(ospf
, vl_data
);
864 ospf_spf_calculate_schedule(ospf
,
865 SPF_FLAG_CONFIG_CHANGE
);
872 static int ospf_vl_set_security(struct ospf_vl_data
*vl_data
,
873 struct ospf_vl_config_data
*vl_config
)
875 struct crypt_key
*ck
;
877 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
879 vty
= vl_config
->vty
;
881 if (vl_config
->auth_type
!= OSPF_AUTH_CMD_NOTSEEN
) {
882 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), auth_type
);
883 IF_DEF_PARAMS(ifp
)->auth_type
= vl_config
->auth_type
;
886 if (vl_config
->auth_key
) {
887 memset(IF_DEF_PARAMS(ifp
)->auth_simple
, 0,
888 OSPF_AUTH_SIMPLE_SIZE
+ 1);
889 strlcpy((char *)IF_DEF_PARAMS(ifp
)->auth_simple
,
891 sizeof(IF_DEF_PARAMS(ifp
)->auth_simple
));
892 } else if (vl_config
->md5_key
) {
893 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
894 vl_config
->crypto_key_id
)
896 vty_out(vty
, "OSPF: Key %d already exists\n",
897 vl_config
->crypto_key_id
);
900 ck
= ospf_crypt_key_new();
901 ck
->key_id
= vl_config
->crypto_key_id
;
902 memset(ck
->auth_key
, 0, OSPF_AUTH_MD5_SIZE
+ 1);
903 strlcpy((char *)ck
->auth_key
, vl_config
->md5_key
,
904 sizeof(ck
->auth_key
));
906 ospf_crypt_key_add(IF_DEF_PARAMS(ifp
)->auth_crypt
, ck
);
907 } else if (vl_config
->crypto_key_id
!= 0) {
910 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
911 vl_config
->crypto_key_id
)
913 vty_out(vty
, "OSPF: Key %d does not exist\n",
914 vl_config
->crypto_key_id
);
915 return CMD_WARNING_CONFIG_FAILED
;
918 ospf_crypt_key_delete(IF_DEF_PARAMS(ifp
)->auth_crypt
,
919 vl_config
->crypto_key_id
);
925 static int ospf_vl_set_timers(struct ospf_vl_data
*vl_data
,
926 struct ospf_vl_config_data
*vl_config
)
928 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
929 /* Virtual Link data initialised to defaults, so only set
931 if (vl_config
->hello_interval
) {
932 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_hello
);
933 IF_DEF_PARAMS(ifp
)->v_hello
= vl_config
->hello_interval
;
936 if (vl_config
->dead_interval
) {
937 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_wait
);
938 IF_DEF_PARAMS(ifp
)->v_wait
= vl_config
->dead_interval
;
941 if (vl_config
->retransmit_interval
) {
942 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), retransmit_interval
);
943 IF_DEF_PARAMS(ifp
)->retransmit_interval
=
944 vl_config
->retransmit_interval
;
947 if (vl_config
->transmit_delay
) {
948 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), transmit_delay
);
949 IF_DEF_PARAMS(ifp
)->transmit_delay
= vl_config
->transmit_delay
;
956 /* The business end of all of the above */
957 static int ospf_vl_set(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
959 struct ospf_vl_data
*vl_data
;
962 vl_data
= ospf_find_vl_data(ospf
, vl_config
);
964 return CMD_WARNING_CONFIG_FAILED
;
966 /* Process this one first as it can have a fatal result, which can
967 only logically occur if the virtual link exists already
968 Thus a command error does not result in a change to the
969 running configuration such as unexpectedly altered timer
971 ret
= ospf_vl_set_security(vl_data
, vl_config
);
972 if (ret
!= CMD_SUCCESS
)
975 /* Set any time based parameters, these area already range checked */
977 ret
= ospf_vl_set_timers(vl_data
, vl_config
);
978 if (ret
!= CMD_SUCCESS
)
984 /* This stuff exists to make specifying all the alias commands A LOT simpler
986 #define VLINK_HELPSTR_IPADDR \
987 "OSPF area parameters\n" \
988 "OSPF area ID in IP address format\n" \
989 "OSPF area ID as a decimal value\n" \
990 "Configure a virtual link\n" \
991 "Router ID of the remote ABR\n"
993 #define VLINK_HELPSTR_AUTHTYPE_SIMPLE \
994 "Enable authentication on this virtual link\n" \
997 #define VLINK_HELPSTR_AUTHTYPE_ALL \
998 VLINK_HELPSTR_AUTHTYPE_SIMPLE \
999 "Use null authentication\n" \
1000 "Use message-digest authentication\n"
1002 #define VLINK_HELPSTR_TIME_PARAM \
1003 "Time between HELLO packets\n" \
1005 "Time between retransmitting lost link state advertisements\n" \
1007 "Link state transmit delay\n" \
1009 "Interval time after which a neighbor is declared down\n" \
1012 #define VLINK_HELPSTR_AUTH_SIMPLE \
1013 "Authentication password (key)\n" \
1014 "The OSPF password (key)\n"
1016 #define VLINK_HELPSTR_AUTH_MD5 \
1017 "Message digest authentication password (key)\n" \
1019 "Use MD5 algorithm\n" \
1020 "The OSPF password (key)\n"
1022 DEFUN (ospf_area_vlink
,
1023 ospf_area_vlink_cmd
,
1024 "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>]",
1025 VLINK_HELPSTR_IPADDR
1026 "Enable authentication on this virtual link\n"
1027 "Use message-digest authentication\n"
1028 "Use null authentication\n"
1029 VLINK_HELPSTR_AUTH_MD5
1030 VLINK_HELPSTR_AUTH_SIMPLE
)
1032 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1033 int idx_ipv4_number
= 1;
1035 struct ospf_vl_config_data vl_config
;
1036 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1037 char md5_key
[OSPF_AUTH_MD5_SIZE
+ 1];
1041 ospf_vl_config_data_init(&vl_config
, vty
);
1043 /* Read off first 2 parameters and check them */
1044 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1045 &vl_config
.area_id_fmt
);
1047 vty_out(vty
, "OSPF area ID is invalid\n");
1048 return CMD_WARNING_CONFIG_FAILED
;
1051 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1053 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1054 return CMD_WARNING_CONFIG_FAILED
;
1058 /* Thats all folks! - BUGS B. strikes again!!!*/
1060 return ospf_vl_set(ospf
, &vl_config
);
1063 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1064 /* authentication - this option can only occur
1065 at start of command line */
1066 vl_config
.auth_type
= OSPF_AUTH_SIMPLE
;
1069 if (argv_find(argv
, argc
, "message-digest", &idx
)) {
1070 /* authentication message-digest */
1071 vl_config
.auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
1072 } else if (argv_find(argv
, argc
, "null", &idx
)) {
1073 /* "authentication null" */
1074 vl_config
.auth_type
= OSPF_AUTH_NULL
;
1077 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1078 vl_config
.md5_key
= NULL
;
1079 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1080 if (vl_config
.crypto_key_id
< 0)
1081 return CMD_WARNING_CONFIG_FAILED
;
1083 strlcpy(md5_key
, argv
[idx
+ 3]->arg
, sizeof(md5_key
));
1084 vl_config
.md5_key
= md5_key
;
1087 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1088 strlcpy(auth_key
, argv
[idx
+ 1]->arg
, sizeof(auth_key
));
1089 vl_config
.auth_key
= auth_key
;
1092 /* Action configuration */
1094 return ospf_vl_set(ospf
, &vl_config
);
1097 DEFUN (no_ospf_area_vlink
,
1098 no_ospf_area_vlink_cmd
,
1099 "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>]",
1101 VLINK_HELPSTR_IPADDR
1102 "Enable authentication on this virtual link\n"
1103 "Use message-digest authentication\n"
1104 "Use null authentication\n"
1105 VLINK_HELPSTR_AUTH_MD5
1106 VLINK_HELPSTR_AUTH_SIMPLE
)
1108 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1109 int idx_ipv4_number
= 2;
1111 struct ospf_area
*area
;
1112 struct ospf_vl_config_data vl_config
;
1113 struct ospf_vl_data
*vl_data
= NULL
;
1114 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1118 ospf_vl_config_data_init(&vl_config
, vty
);
1120 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1123 vty_out(vty
, "OSPF area ID is invalid\n");
1124 return CMD_WARNING_CONFIG_FAILED
;
1127 area
= ospf_area_lookup_by_area_id(ospf
, vl_config
.area_id
);
1129 vty_out(vty
, "Area does not exist\n");
1130 return CMD_WARNING_CONFIG_FAILED
;
1133 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1135 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1136 return CMD_WARNING_CONFIG_FAILED
;
1139 vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
.vl_peer
);
1141 vty_out(vty
, "Virtual link does not exist\n");
1142 return CMD_WARNING_CONFIG_FAILED
;
1146 /* Basic VLink no command */
1147 /* Thats all folks! - BUGS B. strikes again!!!*/
1148 ospf_vl_delete(ospf
, vl_data
);
1149 ospf_area_check_free(ospf
, vl_config
.area_id
);
1153 /* If we are down here, we are reseting parameters */
1154 /* Deal with other parameters */
1156 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1157 /* authentication - this option can only occur
1158 at start of command line */
1159 vl_config
.auth_type
= OSPF_AUTH_NOTSET
;
1162 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1163 vl_config
.md5_key
= NULL
;
1164 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1165 if (vl_config
.crypto_key_id
< 0)
1166 return CMD_WARNING_CONFIG_FAILED
;
1169 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1170 /* Reset authentication-key to 0 */
1171 memset(auth_key
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
1172 vl_config
.auth_key
= auth_key
;
1175 /* Action configuration */
1177 return ospf_vl_set(ospf
, &vl_config
);
1180 DEFUN (ospf_area_vlink_intervals
,
1181 ospf_area_vlink_intervals_cmd
,
1182 "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)}",
1183 VLINK_HELPSTR_IPADDR
1184 VLINK_HELPSTR_TIME_PARAM
)
1186 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1187 struct ospf_vl_config_data vl_config
;
1190 ospf_vl_config_data_init(&vl_config
, vty
);
1192 char *area_id
= argv
[1]->arg
;
1193 char *router_id
= argv
[3]->arg
;
1195 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1197 vty_out(vty
, "OSPF area ID is invalid\n");
1198 return CMD_WARNING_CONFIG_FAILED
;
1201 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1203 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1204 return CMD_WARNING_CONFIG_FAILED
;
1207 for (int idx
= 4; idx
< argc
; idx
++) {
1208 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1209 vl_config
.hello_interval
=
1210 strtol(argv
[++idx
]->arg
, NULL
, 10);
1211 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1212 vl_config
.retransmit_interval
=
1213 strtol(argv
[++idx
]->arg
, NULL
, 10);
1214 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1215 vl_config
.transmit_delay
=
1216 strtol(argv
[++idx
]->arg
, NULL
, 10);
1217 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1218 vl_config
.dead_interval
=
1219 strtol(argv
[++idx
]->arg
, NULL
, 10);
1222 /* Action configuration */
1223 return ospf_vl_set(ospf
, &vl_config
);
1226 DEFUN (no_ospf_area_vlink_intervals
,
1227 no_ospf_area_vlink_intervals_cmd
,
1228 "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)}",
1230 VLINK_HELPSTR_IPADDR
1231 VLINK_HELPSTR_TIME_PARAM
)
1233 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1234 struct ospf_vl_config_data vl_config
;
1237 ospf_vl_config_data_init(&vl_config
, vty
);
1239 char *area_id
= argv
[2]->arg
;
1240 char *router_id
= argv
[4]->arg
;
1242 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1244 vty_out(vty
, "OSPF area ID is invalid\n");
1245 return CMD_WARNING_CONFIG_FAILED
;
1248 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1250 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1251 return CMD_WARNING_CONFIG_FAILED
;
1254 for (int idx
= 5; idx
< argc
; idx
++) {
1255 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1256 vl_config
.hello_interval
= OSPF_HELLO_INTERVAL_DEFAULT
;
1257 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1258 vl_config
.retransmit_interval
=
1259 OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
1260 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1261 vl_config
.transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
1262 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1263 vl_config
.dead_interval
=
1264 OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
1267 /* Action configuration */
1268 return ospf_vl_set(ospf
, &vl_config
);
1271 DEFUN (ospf_area_shortcut
,
1272 ospf_area_shortcut_cmd
,
1273 "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>",
1274 "OSPF area parameters\n"
1275 "OSPF area ID in IP address format\n"
1276 "OSPF area ID as a decimal value\n"
1277 "Configure the area's shortcutting mode\n"
1278 "Set default shortcutting behavior\n"
1279 "Enable shortcutting through the area\n"
1280 "Disable shortcutting through the area\n")
1282 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1283 int idx_ipv4_number
= 1;
1284 int idx_enable_disable
= 3;
1285 struct ospf_area
*area
;
1286 struct in_addr area_id
;
1290 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1291 argv
[idx_ipv4_number
]->arg
);
1293 area
= ospf_area_get(ospf
, area_id
);
1294 ospf_area_display_format_set(ospf
, area
, format
);
1296 if (strncmp(argv
[idx_enable_disable
]->arg
, "de", 2) == 0)
1297 mode
= OSPF_SHORTCUT_DEFAULT
;
1298 else if (strncmp(argv
[idx_enable_disable
]->arg
, "di", 2) == 0)
1299 mode
= OSPF_SHORTCUT_DISABLE
;
1300 else if (strncmp(argv
[idx_enable_disable
]->arg
, "e", 1) == 0)
1301 mode
= OSPF_SHORTCUT_ENABLE
;
1303 return CMD_WARNING_CONFIG_FAILED
;
1305 ospf_area_shortcut_set(ospf
, area
, mode
);
1307 if (ospf
->abr_type
!= OSPF_ABR_SHORTCUT
)
1309 "Shortcut area setting will take effect only when the router is configured as Shortcut ABR\n");
1314 DEFUN (no_ospf_area_shortcut
,
1315 no_ospf_area_shortcut_cmd
,
1316 "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>",
1318 "OSPF area parameters\n"
1319 "OSPF area ID in IP address format\n"
1320 "OSPF area ID as a decimal value\n"
1321 "Deconfigure the area's shortcutting mode\n"
1322 "Deconfigure enabled shortcutting through the area\n"
1323 "Deconfigure disabled shortcutting through the area\n")
1325 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1326 int idx_ipv4_number
= 2;
1327 struct ospf_area
*area
;
1328 struct in_addr area_id
;
1331 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1332 argv
[idx_ipv4_number
]->arg
);
1334 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1338 ospf_area_shortcut_unset(ospf
, area
);
1344 DEFUN (ospf_area_stub
,
1346 "area <A.B.C.D|(0-4294967295)> stub",
1347 "OSPF area parameters\n"
1348 "OSPF area ID in IP address format\n"
1349 "OSPF area ID as a decimal value\n"
1350 "Configure OSPF area as stub\n")
1352 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1353 int idx_ipv4_number
= 1;
1354 struct in_addr area_id
;
1357 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1358 argv
[idx_ipv4_number
]->arg
);
1360 ret
= ospf_area_stub_set(ospf
, area_id
);
1361 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1365 "First deconfigure all virtual link through this area\n");
1366 return CMD_WARNING_CONFIG_FAILED
;
1369 /* Flush the external LSAs from the specified area */
1370 ospf_flush_lsa_from_area(ospf
, area_id
, OSPF_AS_EXTERNAL_LSA
);
1371 ospf_area_no_summary_unset(ospf
, area_id
);
1376 DEFUN (ospf_area_stub_no_summary
,
1377 ospf_area_stub_no_summary_cmd
,
1378 "area <A.B.C.D|(0-4294967295)> stub no-summary",
1379 "OSPF stub parameters\n"
1380 "OSPF area ID in IP address format\n"
1381 "OSPF area ID as a decimal value\n"
1382 "Configure OSPF area as stub\n"
1383 "Do not inject inter-area routes into stub\n")
1385 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1386 int idx_ipv4_number
= 1;
1387 struct in_addr area_id
;
1390 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1391 argv
[idx_ipv4_number
]->arg
);
1393 ret
= ospf_area_stub_set(ospf
, area_id
);
1394 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1398 "%% Area cannot be stub as it contains a virtual link\n");
1399 return CMD_WARNING_CONFIG_FAILED
;
1402 ospf_area_no_summary_set(ospf
, area_id
);
1407 DEFUN (no_ospf_area_stub
,
1408 no_ospf_area_stub_cmd
,
1409 "no area <A.B.C.D|(0-4294967295)> stub",
1411 "OSPF area parameters\n"
1412 "OSPF area ID in IP address format\n"
1413 "OSPF area ID as a decimal value\n"
1414 "Configure OSPF area as stub\n")
1416 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1417 int idx_ipv4_number
= 2;
1418 struct in_addr area_id
;
1421 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1422 argv
[idx_ipv4_number
]->arg
);
1424 ospf_area_stub_unset(ospf
, area_id
);
1425 ospf_area_no_summary_unset(ospf
, area_id
);
1430 DEFUN (no_ospf_area_stub_no_summary
,
1431 no_ospf_area_stub_no_summary_cmd
,
1432 "no area <A.B.C.D|(0-4294967295)> stub no-summary",
1434 "OSPF area parameters\n"
1435 "OSPF area ID in IP address format\n"
1436 "OSPF area ID as a decimal value\n"
1437 "Configure OSPF area as stub\n"
1438 "Do not inject inter-area routes into area\n")
1440 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1441 int idx_ipv4_number
= 2;
1442 struct in_addr area_id
;
1445 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1446 argv
[idx_ipv4_number
]->arg
);
1447 ospf_area_no_summary_unset(ospf
, area_id
);
1452 static int ospf_area_nssa_cmd_handler(struct vty
*vty
, int argc
,
1453 struct cmd_token
**argv
, int cfg_nosum
,
1456 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1457 struct in_addr area_id
;
1460 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
, argv
[1]->arg
);
1462 ret
= ospf_area_nssa_set(ospf
, area_id
);
1463 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1467 "%% Area cannot be nssa as it contains a virtual link\n");
1468 return CMD_WARNING_CONFIG_FAILED
;
1472 if (strncmp(argv
[3]->text
, "translate-c", 11) == 0)
1473 ospf_area_nssa_translator_role_set(
1474 ospf
, area_id
, OSPF_NSSA_ROLE_CANDIDATE
);
1475 else if (strncmp(argv
[3]->text
, "translate-n", 11) == 0)
1476 ospf_area_nssa_translator_role_set(
1477 ospf
, area_id
, OSPF_NSSA_ROLE_NEVER
);
1478 else if (strncmp(argv
[3]->text
, "translate-a", 11) == 0)
1479 ospf_area_nssa_translator_role_set(
1480 ospf
, area_id
, OSPF_NSSA_ROLE_ALWAYS
);
1482 ospf_area_nssa_translator_role_set(ospf
, area_id
,
1483 OSPF_NSSA_ROLE_CANDIDATE
);
1488 ospf_area_no_summary_set(ospf
, area_id
);
1490 ospf_area_no_summary_unset(ospf
, area_id
);
1493 /* Flush the external LSA for the specified area */
1494 ospf_flush_lsa_from_area(ospf
, area_id
, OSPF_AS_EXTERNAL_LSA
);
1495 ospf_schedule_abr_task(ospf
);
1496 ospf_schedule_asbr_nssa_redist_update(ospf
);
1502 DEFUN (ospf_area_nssa_translate
,
1503 ospf_area_nssa_translate_cmd
,
1504 "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always>",
1505 "OSPF area parameters\n"
1506 "OSPF area ID in IP address format\n"
1507 "OSPF area ID as a decimal value\n"
1508 "Configure OSPF area as nssa\n"
1509 "Configure NSSA-ABR for translate election (default)\n"
1510 "Configure NSSA-ABR to never translate\n"
1511 "Configure NSSA-ABR to always translate\n")
1513 return ospf_area_nssa_cmd_handler(vty
, argc
, argv
, 0, 0);
1516 DEFUN (ospf_area_nssa
,
1518 "area <A.B.C.D|(0-4294967295)> nssa",
1519 "OSPF area parameters\n"
1520 "OSPF area ID in IP address format\n"
1521 "OSPF area ID as a decimal value\n"
1522 "Configure OSPF area as nssa\n")
1524 return ospf_area_nssa_cmd_handler(vty
, argc
, argv
, 0, 0);
1527 DEFUN(ospf_area_nssa_suppress_fa
, ospf_area_nssa_suppress_fa_cmd
,
1528 "area <A.B.C.D|(0-4294967295)> nssa suppress-fa",
1529 "OSPF area parameters\n"
1530 "OSPF area ID in IP address format\n"
1531 "OSPF area ID as a decimal value\n"
1532 "Configure OSPF area as nssa\n"
1533 "Suppress forwarding address\n")
1535 int idx_ipv4_number
= 1;
1536 struct in_addr area_id
;
1539 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1540 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1541 argv
[idx_ipv4_number
]->arg
);
1543 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1545 ospf_area_nssa_suppress_fa_set(ospf
, area_id
);
1547 ospf_schedule_abr_task(ospf
);
1552 DEFUN(no_ospf_area_nssa_suppress_fa
, no_ospf_area_nssa_suppress_fa_cmd
,
1553 "no area <A.B.C.D|(0-4294967295)> nssa suppress-fa",
1555 "OSPF area parameters\n"
1556 "OSPF area ID in IP address format\n"
1557 "OSPF area ID as a decimal value\n"
1558 "Configure OSPF area as nssa\n"
1559 "Suppress forwarding address\n")
1561 int idx_ipv4_number
= 2;
1562 struct in_addr area_id
;
1565 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1567 VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id
, format
,
1568 argv
[idx_ipv4_number
]->arg
);
1570 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1572 ospf_area_nssa_suppress_fa_unset(ospf
, area_id
);
1574 ospf_schedule_abr_task(ospf
);
1579 DEFUN (ospf_area_nssa_no_summary
,
1580 ospf_area_nssa_no_summary_cmd
,
1581 "area <A.B.C.D|(0-4294967295)> nssa no-summary",
1582 "OSPF area parameters\n"
1583 "OSPF area ID in IP address format\n"
1584 "OSPF area ID as a decimal value\n"
1585 "Configure OSPF area as nssa\n"
1586 "Do not inject inter-area routes into nssa\n")
1588 int idx_ipv4_number
= 1;
1589 struct in_addr area_id
;
1592 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1593 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1594 argv
[idx_ipv4_number
]->arg
);
1596 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1598 ospf_area_nssa_no_summary_set(ospf
, area_id
);
1600 ospf_schedule_abr_task(ospf
);
1605 DEFUN (no_ospf_area_nssa_no_summary
,
1606 no_ospf_area_nssa_no_summary_cmd
,
1607 "no area <A.B.C.D|(0-4294967295)> nssa no-summary",
1609 "OSPF area parameters\n"
1610 "OSPF area ID in IP address format\n"
1611 "OSPF area ID as a decimal value\n"
1612 "Configure OSPF area as nssa\n"
1613 "Do not inject inter-area routes into nssa\n")
1615 int idx_ipv4_number
= 2;
1616 struct in_addr area_id
;
1619 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1621 VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id
, format
,
1622 argv
[idx_ipv4_number
]->arg
);
1624 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1626 ospf_area_no_summary_unset(ospf
, area_id
);
1628 ospf_schedule_abr_task(ospf
);
1633 DEFUN (no_ospf_area_nssa
,
1634 no_ospf_area_nssa_cmd
,
1635 "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always>]",
1637 "OSPF area parameters\n"
1638 "OSPF area ID in IP address format\n"
1639 "OSPF area ID as a decimal value\n"
1640 "Configure OSPF area as nssa\n"
1641 "Configure NSSA-ABR for translate election (default)\n"
1642 "Configure NSSA-ABR to never translate\n"
1643 "Configure NSSA-ABR to always translate\n")
1645 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1646 int idx_ipv4_number
= 2;
1647 struct in_addr area_id
;
1650 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1651 argv
[idx_ipv4_number
]->arg
);
1653 /* Flush the NSSA LSA for the specified area */
1654 ospf_flush_lsa_from_area(ospf
, area_id
, OSPF_AS_NSSA_LSA
);
1655 ospf_area_nssa_unset(ospf
, area_id
, argc
);
1657 ospf_schedule_abr_task(ospf
);
1663 DEFUN (ospf_area_default_cost
,
1664 ospf_area_default_cost_cmd
,
1665 "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1666 "OSPF area parameters\n"
1667 "OSPF area ID in IP address format\n"
1668 "OSPF area ID as a decimal value\n"
1669 "Set the summary-default cost of a NSSA or stub area\n"
1670 "Stub's advertised default summary cost\n")
1672 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1673 int idx_ipv4_number
= 1;
1675 struct ospf_area
*area
;
1676 struct in_addr area_id
;
1679 struct prefix_ipv4 p
;
1681 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1682 argv
[idx_ipv4_number
]->arg
);
1683 cost
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1685 area
= ospf_area_get(ospf
, area_id
);
1686 ospf_area_display_format_set(ospf
, area
, format
);
1688 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1689 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1690 return CMD_WARNING_CONFIG_FAILED
;
1693 area
->default_cost
= cost
;
1696 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1698 if (IS_DEBUG_OSPF_EVENT
)
1700 "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4",
1702 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1707 DEFUN (no_ospf_area_default_cost
,
1708 no_ospf_area_default_cost_cmd
,
1709 "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1711 "OSPF area parameters\n"
1712 "OSPF area ID in IP address format\n"
1713 "OSPF area ID as a decimal value\n"
1714 "Set the summary-default cost of a NSSA or stub area\n"
1715 "Stub's advertised default summary cost\n")
1717 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1718 int idx_ipv4_number
= 2;
1719 struct ospf_area
*area
;
1720 struct in_addr area_id
;
1722 struct prefix_ipv4 p
;
1724 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1725 argv
[idx_ipv4_number
]->arg
);
1727 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1731 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1732 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1733 return CMD_WARNING_CONFIG_FAILED
;
1736 area
->default_cost
= 1;
1739 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1741 if (IS_DEBUG_OSPF_EVENT
)
1743 "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4",
1745 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1748 ospf_area_check_free(ospf
, area_id
);
1753 DEFUN (ospf_area_export_list
,
1754 ospf_area_export_list_cmd
,
1755 "area <A.B.C.D|(0-4294967295)> export-list ACCESSLIST4_NAME",
1756 "OSPF area parameters\n"
1757 "OSPF area ID in IP address format\n"
1758 "OSPF area ID as a decimal value\n"
1759 "Set the filter for networks announced to other areas\n"
1760 "Name of the access-list\n")
1762 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1763 int idx_ipv4_number
= 1;
1764 struct ospf_area
*area
;
1765 struct in_addr area_id
;
1768 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1770 area
= ospf_area_get(ospf
, area_id
);
1771 ospf_area_display_format_set(ospf
, area
, format
);
1772 ospf_area_export_list_set(ospf
, area
, argv
[3]->arg
);
1777 DEFUN (no_ospf_area_export_list
,
1778 no_ospf_area_export_list_cmd
,
1779 "no area <A.B.C.D|(0-4294967295)> export-list ACCESSLIST4_NAME",
1781 "OSPF area parameters\n"
1782 "OSPF area ID in IP address format\n"
1783 "OSPF area ID as a decimal value\n"
1784 "Unset the filter for networks announced to other areas\n"
1785 "Name of the access-list\n")
1787 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1788 int idx_ipv4_number
= 2;
1789 struct ospf_area
*area
;
1790 struct in_addr area_id
;
1793 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1795 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1799 ospf_area_export_list_unset(ospf
, area
);
1805 DEFUN (ospf_area_import_list
,
1806 ospf_area_import_list_cmd
,
1807 "area <A.B.C.D|(0-4294967295)> import-list ACCESSLIST4_NAME",
1808 "OSPF area parameters\n"
1809 "OSPF area ID in IP address format\n"
1810 "OSPF area ID as a decimal value\n"
1811 "Set the filter for networks from other areas announced to the specified one\n"
1812 "Name of the access-list\n")
1814 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1815 int idx_ipv4_number
= 1;
1816 struct ospf_area
*area
;
1817 struct in_addr area_id
;
1820 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1822 area
= ospf_area_get(ospf
, area_id
);
1823 ospf_area_display_format_set(ospf
, area
, format
);
1824 ospf_area_import_list_set(ospf
, area
, argv
[3]->arg
);
1829 DEFUN (no_ospf_area_import_list
,
1830 no_ospf_area_import_list_cmd
,
1831 "no area <A.B.C.D|(0-4294967295)> import-list ACCESSLIST4_NAME",
1833 "OSPF area parameters\n"
1834 "OSPF area ID in IP address format\n"
1835 "OSPF area ID as a decimal value\n"
1836 "Unset the filter for networks announced to other areas\n"
1837 "Name of the access-list\n")
1839 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1840 int idx_ipv4_number
= 2;
1841 struct ospf_area
*area
;
1842 struct in_addr area_id
;
1845 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1847 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1851 ospf_area_import_list_unset(ospf
, area
);
1856 DEFUN (ospf_area_filter_list
,
1857 ospf_area_filter_list_cmd
,
1858 "area <A.B.C.D|(0-4294967295)> filter-list prefix PREFIXLIST_NAME <in|out>",
1859 "OSPF area parameters\n"
1860 "OSPF area ID in IP address format\n"
1861 "OSPF area ID as a decimal value\n"
1862 "Filter networks between OSPF areas\n"
1863 "Filter prefixes between OSPF areas\n"
1864 "Name of an IP prefix-list\n"
1865 "Filter networks sent to this area\n"
1866 "Filter networks sent from this area\n")
1868 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1869 int idx_ipv4_number
= 1;
1872 struct ospf_area
*area
;
1873 struct in_addr area_id
;
1874 struct prefix_list
*plist
;
1877 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1879 area
= ospf_area_get(ospf
, area_id
);
1880 ospf_area_display_format_set(ospf
, area
, format
);
1881 plist
= prefix_list_lookup(AFI_IP
, argv
[idx_word
]->arg
);
1882 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1883 PREFIX_LIST_IN(area
) = plist
;
1884 if (PREFIX_NAME_IN(area
))
1885 free(PREFIX_NAME_IN(area
));
1887 PREFIX_NAME_IN(area
) = strdup(argv
[idx_word
]->arg
);
1888 ospf_schedule_abr_task(ospf
);
1890 PREFIX_LIST_OUT(area
) = plist
;
1891 if (PREFIX_NAME_OUT(area
))
1892 free(PREFIX_NAME_OUT(area
));
1894 PREFIX_NAME_OUT(area
) = strdup(argv
[idx_word
]->arg
);
1895 ospf_schedule_abr_task(ospf
);
1901 DEFUN (no_ospf_area_filter_list
,
1902 no_ospf_area_filter_list_cmd
,
1903 "no area <A.B.C.D|(0-4294967295)> filter-list prefix PREFIXLIST_NAME <in|out>",
1905 "OSPF area parameters\n"
1906 "OSPF area ID in IP address format\n"
1907 "OSPF area ID as a decimal value\n"
1908 "Filter networks between OSPF areas\n"
1909 "Filter prefixes between OSPF areas\n"
1910 "Name of an IP prefix-list\n"
1911 "Filter networks sent to this area\n"
1912 "Filter networks sent from this area\n")
1914 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1915 int idx_ipv4_number
= 2;
1918 struct ospf_area
*area
;
1919 struct in_addr area_id
;
1922 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1924 if ((area
= ospf_area_lookup_by_area_id(ospf
, area_id
)) == NULL
)
1927 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1928 if (PREFIX_NAME_IN(area
))
1929 if (strcmp(PREFIX_NAME_IN(area
), argv
[idx_word
]->arg
)
1933 PREFIX_LIST_IN(area
) = NULL
;
1934 if (PREFIX_NAME_IN(area
))
1935 free(PREFIX_NAME_IN(area
));
1937 PREFIX_NAME_IN(area
) = NULL
;
1939 ospf_schedule_abr_task(ospf
);
1941 if (PREFIX_NAME_OUT(area
))
1942 if (strcmp(PREFIX_NAME_OUT(area
), argv
[idx_word
]->arg
)
1946 PREFIX_LIST_OUT(area
) = NULL
;
1947 if (PREFIX_NAME_OUT(area
))
1948 free(PREFIX_NAME_OUT(area
));
1950 PREFIX_NAME_OUT(area
) = NULL
;
1952 ospf_schedule_abr_task(ospf
);
1959 DEFUN (ospf_area_authentication_message_digest
,
1960 ospf_area_authentication_message_digest_cmd
,
1961 "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest",
1963 "OSPF area parameters\n"
1964 "OSPF area ID in IP address format\n"
1965 "OSPF area ID as a decimal value\n"
1966 "Enable authentication\n"
1967 "Use message-digest authentication\n")
1969 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1971 struct ospf_area
*area
;
1972 struct in_addr area_id
;
1975 argv_find(argv
, argc
, "area", &idx
);
1976 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx
+ 1]->arg
);
1978 area
= ospf_area_get(ospf
, area_id
);
1979 ospf_area_display_format_set(ospf
, area
, format
);
1980 area
->auth_type
= strmatch(argv
[0]->text
, "no")
1982 : OSPF_AUTH_CRYPTOGRAPHIC
;
1987 DEFUN (ospf_area_authentication
,
1988 ospf_area_authentication_cmd
,
1989 "area <A.B.C.D|(0-4294967295)> authentication",
1990 "OSPF area parameters\n"
1991 "OSPF area ID in IP address format\n"
1992 "OSPF area ID as a decimal value\n"
1993 "Enable authentication\n")
1995 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1996 int idx_ipv4_number
= 1;
1997 struct ospf_area
*area
;
1998 struct in_addr area_id
;
2001 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
2003 area
= ospf_area_get(ospf
, area_id
);
2004 ospf_area_display_format_set(ospf
, area
, format
);
2005 area
->auth_type
= OSPF_AUTH_SIMPLE
;
2010 DEFUN (no_ospf_area_authentication
,
2011 no_ospf_area_authentication_cmd
,
2012 "no area <A.B.C.D|(0-4294967295)> authentication",
2014 "OSPF area parameters\n"
2015 "OSPF area ID in IP address format\n"
2016 "OSPF area ID as a decimal value\n"
2017 "Enable authentication\n")
2019 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2020 int idx_ipv4_number
= 2;
2021 struct ospf_area
*area
;
2022 struct in_addr area_id
;
2025 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
2027 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
2031 area
->auth_type
= OSPF_AUTH_NULL
;
2033 ospf_area_check_free(ospf
, area_id
);
2039 DEFUN (ospf_abr_type
,
2041 "ospf abr-type <cisco|ibm|shortcut|standard>",
2042 "OSPF specific commands\n"
2043 "Set OSPF ABR type\n"
2044 "Alternative ABR, cisco implementation\n"
2045 "Alternative ABR, IBM implementation\n"
2047 "Standard behavior (RFC2328)\n")
2049 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2051 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2053 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2054 abr_type
= OSPF_ABR_CISCO
;
2055 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2056 abr_type
= OSPF_ABR_IBM
;
2057 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2058 abr_type
= OSPF_ABR_SHORTCUT
;
2059 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2060 abr_type
= OSPF_ABR_STAND
;
2062 return CMD_WARNING_CONFIG_FAILED
;
2064 /* If ABR type value is changed, schedule ABR task. */
2065 if (ospf
->abr_type
!= abr_type
) {
2066 ospf
->abr_type
= abr_type
;
2067 ospf_schedule_abr_task(ospf
);
2073 DEFUN (no_ospf_abr_type
,
2074 no_ospf_abr_type_cmd
,
2075 "no ospf abr-type <cisco|ibm|shortcut|standard>",
2077 "OSPF specific commands\n"
2078 "Set OSPF ABR type\n"
2079 "Alternative ABR, cisco implementation\n"
2080 "Alternative ABR, IBM implementation\n"
2084 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2086 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2088 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2089 abr_type
= OSPF_ABR_CISCO
;
2090 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2091 abr_type
= OSPF_ABR_IBM
;
2092 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2093 abr_type
= OSPF_ABR_SHORTCUT
;
2094 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2095 abr_type
= OSPF_ABR_STAND
;
2097 return CMD_WARNING_CONFIG_FAILED
;
2099 /* If ABR type value is changed, schedule ABR task. */
2100 if (ospf
->abr_type
== abr_type
) {
2101 ospf
->abr_type
= OSPF_ABR_DEFAULT
;
2102 ospf_schedule_abr_task(ospf
);
2108 DEFUN (ospf_log_adjacency_changes
,
2109 ospf_log_adjacency_changes_cmd
,
2110 "log-adjacency-changes",
2111 "Log changes in adjacency state\n")
2113 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2115 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2116 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2120 DEFUN (ospf_log_adjacency_changes_detail
,
2121 ospf_log_adjacency_changes_detail_cmd
,
2122 "log-adjacency-changes detail",
2123 "Log changes in adjacency state\n"
2124 "Log all state changes\n")
2126 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2128 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2129 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2133 DEFUN (no_ospf_log_adjacency_changes
,
2134 no_ospf_log_adjacency_changes_cmd
,
2135 "no log-adjacency-changes",
2137 "Log changes in adjacency state\n")
2139 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2141 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2142 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2146 DEFUN (no_ospf_log_adjacency_changes_detail
,
2147 no_ospf_log_adjacency_changes_detail_cmd
,
2148 "no log-adjacency-changes detail",
2150 "Log changes in adjacency state\n"
2151 "Log all state changes\n")
2153 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2155 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2159 DEFUN (ospf_compatible_rfc1583
,
2160 ospf_compatible_rfc1583_cmd
,
2161 "compatible rfc1583",
2162 "OSPF compatibility list\n"
2163 "compatible with RFC 1583\n")
2165 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2167 if (!CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2168 SET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2169 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2174 DEFUN (no_ospf_compatible_rfc1583
,
2175 no_ospf_compatible_rfc1583_cmd
,
2176 "no compatible rfc1583",
2178 "OSPF compatibility list\n"
2179 "compatible with RFC 1583\n")
2181 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2183 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2184 UNSET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2185 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2190 ALIAS(ospf_compatible_rfc1583
, ospf_rfc1583_flag_cmd
,
2191 "ospf rfc1583compatibility",
2192 "OSPF specific commands\n"
2193 "Enable the RFC1583Compatibility flag\n")
2195 ALIAS(no_ospf_compatible_rfc1583
, no_ospf_rfc1583_flag_cmd
,
2196 "no ospf rfc1583compatibility", NO_STR
2197 "OSPF specific commands\n"
2198 "Disable the RFC1583Compatibility flag\n")
2200 static void ospf_table_reinstall_routes(struct ospf
*ospf
,
2201 struct route_table
*rt
)
2203 struct route_node
*rn
;
2208 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
2209 struct ospf_route
*or;
2215 if (or->type
== OSPF_DESTINATION_NETWORK
)
2216 ospf_zebra_add(ospf
, (struct prefix_ipv4
*)&rn
->p
, or);
2217 else if (or->type
== OSPF_DESTINATION_DISCARD
)
2218 ospf_zebra_add_discard(ospf
,
2219 (struct prefix_ipv4
*)&rn
->p
);
2223 static void ospf_reinstall_routes(struct ospf
*ospf
)
2225 ospf_table_reinstall_routes(ospf
, ospf
->new_table
);
2226 ospf_table_reinstall_routes(ospf
, ospf
->new_external_route
);
2229 DEFPY (ospf_send_extra_data
,
2230 ospf_send_extra_data_cmd
,
2231 "[no] ospf send-extra-data zebra",
2234 "Extra data to Zebra for display/use\n"
2237 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2239 if (no
&& CHECK_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
)) {
2240 UNSET_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
);
2241 ospf_reinstall_routes(ospf
);
2242 } else if (!CHECK_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
)) {
2243 SET_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
);
2244 ospf_reinstall_routes(ospf
);
2250 static int ospf_timers_spf_set(struct vty
*vty
, unsigned int delay
,
2251 unsigned int hold
, unsigned int max
)
2253 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2255 ospf
->spf_delay
= delay
;
2256 ospf
->spf_holdtime
= hold
;
2257 ospf
->spf_max_holdtime
= max
;
2262 DEFUN (ospf_timers_min_ls_interval
,
2263 ospf_timers_min_ls_interval_cmd
,
2264 "timers throttle lsa all (0-5000)",
2265 "Adjust routing timers\n"
2266 "Throttling adaptive timer\n"
2267 "LSA delay between transmissions\n"
2269 "Delay (msec) between sending LSAs\n")
2271 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2273 unsigned int interval
;
2276 vty_out(vty
, "Insufficient arguments\n");
2277 return CMD_WARNING_CONFIG_FAILED
;
2280 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2282 ospf
->min_ls_interval
= interval
;
2287 DEFUN (no_ospf_timers_min_ls_interval
,
2288 no_ospf_timers_min_ls_interval_cmd
,
2289 "no timers throttle lsa all [(0-5000)]",
2291 "Adjust routing timers\n"
2292 "Throttling adaptive timer\n"
2293 "LSA delay between transmissions\n"
2295 "Delay (msec) between sending LSAs\n")
2297 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2298 ospf
->min_ls_interval
= OSPF_MIN_LS_INTERVAL
;
2303 DEFUN (ospf_timers_throttle_spf
,
2304 ospf_timers_throttle_spf_cmd
,
2305 "timers throttle spf (0-600000) (0-600000) (0-600000)",
2306 "Adjust routing timers\n"
2307 "Throttling adaptive timer\n"
2309 "Delay (msec) from first change received till SPF calculation\n"
2310 "Initial hold time (msec) between consecutive SPF calculations\n"
2311 "Maximum hold time (msec)\n")
2314 int idx_number_2
= 4;
2315 int idx_number_3
= 5;
2316 unsigned int delay
, hold
, max
;
2319 vty_out(vty
, "Insufficient arguments\n");
2320 return CMD_WARNING_CONFIG_FAILED
;
2323 delay
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2324 hold
= strtoul(argv
[idx_number_2
]->arg
, NULL
, 10);
2325 max
= strtoul(argv
[idx_number_3
]->arg
, NULL
, 10);
2327 return ospf_timers_spf_set(vty
, delay
, hold
, max
);
2330 DEFUN (no_ospf_timers_throttle_spf
,
2331 no_ospf_timers_throttle_spf_cmd
,
2332 "no timers throttle spf [(0-600000)(0-600000)(0-600000)]",
2334 "Adjust routing timers\n"
2335 "Throttling adaptive timer\n"
2337 "Delay (msec) from first change received till SPF calculation\n"
2338 "Initial hold time (msec) between consecutive SPF calculations\n"
2339 "Maximum hold time (msec)\n")
2341 return ospf_timers_spf_set(vty
, OSPF_SPF_DELAY_DEFAULT
,
2342 OSPF_SPF_HOLDTIME_DEFAULT
,
2343 OSPF_SPF_MAX_HOLDTIME_DEFAULT
);
2347 DEFUN (ospf_timers_lsa_min_arrival
,
2348 ospf_timers_lsa_min_arrival_cmd
,
2349 "timers lsa min-arrival (0-600000)",
2350 "Adjust routing timers\n"
2352 "Minimum delay in receiving new version of a LSA\n"
2353 "Delay in milliseconds\n")
2355 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2356 ospf
->min_ls_arrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2360 DEFUN (no_ospf_timers_lsa_min_arrival
,
2361 no_ospf_timers_lsa_min_arrival_cmd
,
2362 "no timers lsa min-arrival [(0-600000)]",
2364 "Adjust routing timers\n"
2366 "Minimum delay in receiving new version of a LSA\n"
2367 "Delay in milliseconds\n")
2369 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2370 unsigned int minarrival
;
2373 minarrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2375 if (ospf
->min_ls_arrival
!= minarrival
2376 || minarrival
== OSPF_MIN_LS_ARRIVAL
)
2380 ospf
->min_ls_arrival
= OSPF_MIN_LS_ARRIVAL
;
2385 DEFUN (ospf_neighbor
,
2387 "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]",
2389 "Neighbor IP address\n"
2390 "Neighbor Priority\n"
2392 "Dead Neighbor Polling interval\n"
2395 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2399 struct in_addr nbr_addr
;
2400 unsigned int priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2401 unsigned int interval
= OSPF_POLL_INTERVAL_DEFAULT
;
2403 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2404 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2405 return CMD_WARNING_CONFIG_FAILED
;
2409 priority
= strtoul(argv
[idx_pri
]->arg
, NULL
, 10);
2412 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2414 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2417 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2420 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2425 DEFUN (ospf_neighbor_poll_interval
,
2426 ospf_neighbor_poll_interval_cmd
,
2427 "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2429 "Neighbor IP address\n"
2430 "Dead Neighbor Polling interval\n"
2432 "OSPF priority of non-broadcast neighbor\n"
2435 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2439 struct in_addr nbr_addr
;
2440 unsigned int priority
;
2441 unsigned int interval
;
2443 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2444 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2445 return CMD_WARNING_CONFIG_FAILED
;
2448 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2450 priority
= argc
> 4 ? strtoul(argv
[idx_pri
]->arg
, NULL
, 10)
2451 : OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2453 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2454 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2457 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2462 DEFUN (no_ospf_neighbor
,
2463 no_ospf_neighbor_cmd
,
2464 "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]",
2467 "Neighbor IP address\n"
2468 "Neighbor Priority\n"
2470 "Dead Neighbor Polling interval\n"
2473 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2475 struct in_addr nbr_addr
;
2477 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2478 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2479 return CMD_WARNING_CONFIG_FAILED
;
2482 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2487 DEFUN (no_ospf_neighbor_poll
,
2488 no_ospf_neighbor_poll_cmd
,
2489 "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2492 "Neighbor IP address\n"
2493 "Dead Neighbor Polling interval\n"
2495 "Neighbor Priority\n"
2498 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2500 struct in_addr nbr_addr
;
2502 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2503 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2504 return CMD_WARNING_CONFIG_FAILED
;
2507 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2512 DEFUN (ospf_refresh_timer
,
2513 ospf_refresh_timer_cmd
,
2514 "refresh timer (10-1800)",
2515 "Adjust refresh parameters\n"
2516 "Set refresh timer\n"
2517 "Timer value in seconds\n")
2519 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2521 unsigned int interval
;
2523 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2524 interval
= (interval
/ OSPF_LSA_REFRESHER_GRANULARITY
)
2525 * OSPF_LSA_REFRESHER_GRANULARITY
;
2527 ospf_timers_refresh_set(ospf
, interval
);
2532 DEFUN (no_ospf_refresh_timer
,
2533 no_ospf_refresh_timer_val_cmd
,
2534 "no refresh timer [(10-1800)]",
2536 "Adjust refresh parameters\n"
2537 "Unset refresh timer\n"
2538 "Timer value in seconds\n")
2540 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2542 unsigned int interval
;
2545 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2547 if (ospf
->lsa_refresh_interval
!= interval
2548 || interval
== OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
2552 ospf_timers_refresh_unset(ospf
);
2558 DEFUN (ospf_auto_cost_reference_bandwidth
,
2559 ospf_auto_cost_reference_bandwidth_cmd
,
2560 "auto-cost reference-bandwidth (1-4294967)",
2561 "Calculate OSPF interface cost according to bandwidth\n"
2562 "Use reference bandwidth method to assign OSPF cost\n"
2563 "The reference bandwidth in terms of Mbits per second\n")
2565 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2566 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2569 struct interface
*ifp
;
2571 refbw
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2572 if (refbw
< 1 || refbw
> 4294967) {
2573 vty_out(vty
, "reference-bandwidth value is invalid\n");
2574 return CMD_WARNING_CONFIG_FAILED
;
2577 /* If reference bandwidth is changed. */
2578 if ((refbw
) == ospf
->ref_bandwidth
)
2581 ospf
->ref_bandwidth
= refbw
;
2582 FOR_ALL_INTERFACES (vrf
, ifp
)
2583 ospf_if_recalculate_output_cost(ifp
);
2588 DEFUN (no_ospf_auto_cost_reference_bandwidth
,
2589 no_ospf_auto_cost_reference_bandwidth_cmd
,
2590 "no auto-cost reference-bandwidth [(1-4294967)]",
2592 "Calculate OSPF interface cost according to bandwidth\n"
2593 "Use reference bandwidth method to assign OSPF cost\n"
2594 "The reference bandwidth in terms of Mbits per second\n")
2596 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2597 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2598 struct interface
*ifp
;
2600 if (ospf
->ref_bandwidth
== OSPF_DEFAULT_REF_BANDWIDTH
)
2603 ospf
->ref_bandwidth
= OSPF_DEFAULT_REF_BANDWIDTH
;
2604 vty_out(vty
, "%% OSPF: Reference bandwidth is changed.\n");
2606 " Please ensure reference bandwidth is consistent across all routers\n");
2608 FOR_ALL_INTERFACES (vrf
, ifp
)
2609 ospf_if_recalculate_output_cost(ifp
);
2614 DEFUN (ospf_write_multiplier
,
2615 ospf_write_multiplier_cmd
,
2616 "ospf write-multiplier (1-100)",
2617 "OSPF specific commands\n"
2618 "Write multiplier\n"
2619 "Maximum number of interface serviced per write\n")
2621 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2623 uint32_t write_oi_count
;
2630 write_oi_count
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2631 if (write_oi_count
< 1 || write_oi_count
> 100) {
2632 vty_out(vty
, "write-multiplier value is invalid\n");
2633 return CMD_WARNING_CONFIG_FAILED
;
2636 ospf
->write_oi_count
= write_oi_count
;
2640 ALIAS(ospf_write_multiplier
, write_multiplier_cmd
, "write-multiplier (1-100)",
2641 "Write multiplier\n"
2642 "Maximum number of interface serviced per write\n")
2644 DEFUN (no_ospf_write_multiplier
,
2645 no_ospf_write_multiplier_cmd
,
2646 "no ospf write-multiplier (1-100)",
2648 "OSPF specific commands\n"
2649 "Write multiplier\n"
2650 "Maximum number of interface serviced per write\n")
2652 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2654 ospf
->write_oi_count
= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
;
2658 ALIAS(no_ospf_write_multiplier
, no_write_multiplier_cmd
,
2659 "no write-multiplier (1-100)", NO_STR
2660 "Write multiplier\n"
2661 "Maximum number of interface serviced per write\n")
2663 DEFUN(ospf_ti_lfa
, ospf_ti_lfa_cmd
, "fast-reroute ti-lfa [node-protection]",
2664 "Fast Reroute for MPLS and IP resilience\n"
2665 "Topology Independent LFA (Loop-Free Alternate)\n"
2666 "TI-LFA node protection (default is link protection)\n")
2668 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2670 ospf
->ti_lfa_enabled
= true;
2673 ospf
->ti_lfa_protection_type
= OSPF_TI_LFA_NODE_PROTECTION
;
2675 ospf
->ti_lfa_protection_type
= OSPF_TI_LFA_LINK_PROTECTION
;
2677 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2682 DEFUN(no_ospf_ti_lfa
, no_ospf_ti_lfa_cmd
,
2683 "no fast-reroute ti-lfa [node-protection]",
2685 "Fast Reroute for MPLS and IP resilience\n"
2686 "Topology Independent LFA (Loop-Free Alternate)\n"
2687 "TI-LFA node protection (default is link protection)\n")
2689 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2691 ospf
->ti_lfa_enabled
= false;
2693 ospf
->ti_lfa_protection_type
= OSPF_TI_LFA_UNDEFINED_PROTECTION
;
2695 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2700 static void ospf_maxpath_set(struct vty
*vty
, struct ospf
*ospf
, uint16_t paths
)
2702 if (ospf
->max_multipath
== paths
)
2705 ospf
->max_multipath
= paths
;
2707 /* Send deletion notification to zebra to delete all
2708 * ospf specific routes and reinitiat SPF to reflect
2709 * the new max multipath.
2711 ospf_restart_spf(ospf
);
2714 /* Ospf Maximum multiple paths config support */
2715 DEFUN (ospf_max_multipath
,
2716 ospf_max_multipath_cmd
,
2717 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM
),
2718 "Max no of multiple paths for ECMP support\n"
2719 "Number of paths\n")
2721 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2725 maxpaths
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2727 ospf_maxpath_set(vty
, ospf
, maxpaths
);
2731 DEFUN (no_ospf_max_multipath
,
2732 no_ospf_max_multipath_cmd
,
2735 "Max no of multiple paths for ECMP support\n")
2737 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2738 uint16_t maxpaths
= MULTIPATH_NUM
;
2740 ospf_maxpath_set(vty
, ospf
, maxpaths
);
2744 static const char *const ospf_abr_type_descr_str
[] = {
2745 "Unknown", "Standard (RFC2328)", "Alternative IBM",
2746 "Alternative Cisco", "Alternative Shortcut"
2749 static const char *const ospf_shortcut_mode_descr_str
[] = {
2750 "Default", "Enabled", "Disabled"
2753 static void show_ip_ospf_area(struct vty
*vty
, struct ospf_area
*area
,
2754 json_object
*json_areas
, bool use_json
)
2756 json_object
*json_area
= NULL
;
2757 char buf
[PREFIX_STRLEN
];
2760 json_area
= json_object_new_object();
2764 vty_out(vty
, " Area ID: %pI4", &area
->area_id
);
2766 /* Show Area type/mode. */
2767 if (OSPF_IS_AREA_BACKBONE(area
)) {
2769 json_object_boolean_true_add(json_area
, "backbone");
2771 vty_out(vty
, " (Backbone)\n");
2774 if (area
->external_routing
== OSPF_AREA_STUB
) {
2775 if (area
->no_summary
)
2776 json_object_boolean_true_add(
2777 json_area
, "stubNoSummary");
2778 if (area
->shortcut_configured
)
2779 json_object_boolean_true_add(
2780 json_area
, "stubShortcut");
2781 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
2782 if (area
->no_summary
)
2783 json_object_boolean_true_add(
2784 json_area
, "nssaNoSummary");
2785 if (area
->shortcut_configured
)
2786 json_object_boolean_true_add(
2787 json_area
, "nssaShortcut");
2790 json_object_string_add(
2791 json_area
, "shortcuttingMode",
2792 ospf_shortcut_mode_descr_str
2793 [area
->shortcut_configured
]);
2794 if (area
->shortcut_capability
)
2795 json_object_boolean_true_add(json_area
,
2798 if (area
->external_routing
== OSPF_AREA_STUB
)
2799 vty_out(vty
, " (Stub%s%s)",
2800 area
->no_summary
? ", no summary" : "",
2801 area
->shortcut_configured
? "; " : "");
2802 else if (area
->external_routing
== OSPF_AREA_NSSA
)
2803 vty_out(vty
, " (NSSA%s%s)",
2804 area
->no_summary
? ", no summary" : "",
2805 area
->shortcut_configured
? "; " : "");
2808 vty_out(vty
, " Shortcutting mode: %s",
2809 ospf_shortcut_mode_descr_str
2810 [area
->shortcut_configured
]);
2811 vty_out(vty
, ", S-bit consensus: %s\n",
2812 area
->shortcut_capability
? "ok" : "no");
2816 /* Show number of interfaces */
2818 json_object_int_add(json_area
, "areaIfTotalCounter",
2819 listcount(area
->oiflist
));
2820 json_object_int_add(json_area
, "areaIfActiveCounter",
2824 " Number of interfaces in this area: Total: %d, Active: %d\n",
2825 listcount(area
->oiflist
), area
->act_ints
);
2827 if (area
->external_routing
== OSPF_AREA_NSSA
) {
2829 json_object_boolean_true_add(json_area
, "nssa");
2830 if (!IS_OSPF_ABR(area
->ospf
))
2831 json_object_boolean_false_add(json_area
, "abr");
2832 else if (area
->NSSATranslatorState
) {
2833 json_object_boolean_true_add(json_area
, "abr");
2834 if (area
->NSSATranslatorRole
2835 == OSPF_NSSA_ROLE_CANDIDATE
)
2836 json_object_boolean_true_add(
2838 "nssaTranslatorElected");
2839 else if (area
->NSSATranslatorRole
2840 == OSPF_NSSA_ROLE_ALWAYS
)
2841 json_object_boolean_true_add(
2843 "nssaTranslatorAlways");
2845 json_object_boolean_true_add(
2847 "nssaTranslatorNever");
2849 json_object_boolean_true_add(json_area
, "abr");
2850 if (area
->NSSATranslatorRole
2851 == OSPF_NSSA_ROLE_CANDIDATE
)
2852 json_object_boolean_false_add(
2854 "nssaTranslatorElected");
2856 json_object_boolean_true_add(
2858 "nssaTranslatorNever");
2862 " It is an NSSA configuration.\n Elected NSSA/ABR performs type-7/type-5 LSA translation.\n");
2863 if (!IS_OSPF_ABR(area
->ospf
))
2865 " It is not ABR, therefore not Translator.\n");
2866 else if (area
->NSSATranslatorState
) {
2867 vty_out(vty
, " We are an ABR and ");
2868 if (area
->NSSATranslatorRole
2869 == OSPF_NSSA_ROLE_CANDIDATE
)
2871 "the NSSA Elected Translator.\n");
2872 else if (area
->NSSATranslatorRole
2873 == OSPF_NSSA_ROLE_ALWAYS
)
2875 "always an NSSA Translator.\n");
2878 "never an NSSA Translator.\n");
2880 vty_out(vty
, " We are an ABR, but ");
2881 if (area
->NSSATranslatorRole
2882 == OSPF_NSSA_ROLE_CANDIDATE
)
2884 "not the NSSA Elected Translator.\n");
2887 "never an NSSA Translator.\n");
2892 /* Stub-router state for this area */
2893 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
)) {
2894 char timebuf
[OSPF_TIME_DUMP_SIZE
];
2897 json_object_boolean_true_add(
2898 json_area
, "originStubMaxDistRouterLsa");
2899 if (CHECK_FLAG(area
->stub_router_state
,
2900 OSPF_AREA_ADMIN_STUB_ROUTED
))
2901 json_object_boolean_true_add(
2902 json_area
, "indefiniteActiveAdmin");
2903 if (area
->t_stub_router
) {
2907 &area
->t_stub_router
->u
.sands
,
2910 json_object_int_add(
2912 "activeStartupRemainderMsecs",
2917 " Originating stub / maximum-distance Router-LSA\n");
2918 if (CHECK_FLAG(area
->stub_router_state
,
2919 OSPF_AREA_ADMIN_STUB_ROUTED
))
2921 " Administratively activated (indefinitely)\n");
2922 if (area
->t_stub_router
)
2924 " Active from startup, %s remaining\n",
2925 ospf_timer_dump(area
->t_stub_router
,
2932 /* Show number of fully adjacent neighbors. */
2933 json_object_int_add(json_area
, "nbrFullAdjacentCounter",
2936 /* Show authentication type. */
2937 if (area
->auth_type
== OSPF_AUTH_NULL
)
2938 json_object_string_add(json_area
, "authentication",
2939 "authenticationNone");
2940 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2941 json_object_string_add(json_area
, "authentication",
2942 "authenticationSimplePassword");
2943 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2944 json_object_string_add(json_area
, "authentication",
2945 "authenticationMessageDigest");
2947 if (!OSPF_IS_AREA_BACKBONE(area
))
2948 json_object_int_add(json_area
,
2949 "virtualAdjacenciesPassingCounter",
2952 /* Show SPF calculation times. */
2953 json_object_int_add(json_area
, "spfExecutedCounter",
2954 area
->spf_calculation
);
2955 json_object_int_add(json_area
, "lsaNumber", area
->lsdb
->total
);
2956 json_object_int_add(
2957 json_area
, "lsaRouterNumber",
2958 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
));
2959 json_object_int_add(
2960 json_area
, "lsaRouterChecksum",
2961 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
2962 json_object_int_add(
2963 json_area
, "lsaNetworkNumber",
2964 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
));
2965 json_object_int_add(
2966 json_area
, "lsaNetworkChecksum",
2967 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
2968 json_object_int_add(
2969 json_area
, "lsaSummaryNumber",
2970 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
));
2971 json_object_int_add(
2972 json_area
, "lsaSummaryChecksum",
2973 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
2974 json_object_int_add(
2975 json_area
, "lsaAsbrNumber",
2976 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2977 json_object_int_add(
2978 json_area
, "lsaAsbrChecksum",
2979 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2980 json_object_int_add(
2981 json_area
, "lsaNssaNumber",
2982 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2983 json_object_int_add(
2984 json_area
, "lsaNssaChecksum",
2985 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2987 /* Show number of fully adjacent neighbors. */
2989 " Number of fully adjacent neighbors in this area: %d\n",
2992 /* Show authentication type. */
2993 vty_out(vty
, " Area has ");
2994 if (area
->auth_type
== OSPF_AUTH_NULL
)
2995 vty_out(vty
, "no authentication\n");
2996 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2997 vty_out(vty
, "simple password authentication\n");
2998 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2999 vty_out(vty
, "message digest authentication\n");
3001 if (!OSPF_IS_AREA_BACKBONE(area
))
3003 " Number of full virtual adjacencies going through this area: %d\n",
3006 /* Show SPF calculation times. */
3007 vty_out(vty
, " SPF algorithm executed %d times\n",
3008 area
->spf_calculation
);
3010 /* Show number of LSA. */
3011 vty_out(vty
, " Number of LSA %ld\n", area
->lsdb
->total
);
3013 " Number of router LSA %ld. Checksum Sum 0x%08x\n",
3014 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
),
3015 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
3017 " Number of network LSA %ld. Checksum Sum 0x%08x\n",
3018 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
),
3019 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
3021 " Number of summary LSA %ld. Checksum Sum 0x%08x\n",
3022 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
),
3023 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
3025 " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n",
3026 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
),
3027 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
3028 vty_out(vty
, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n",
3029 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
),
3030 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
3034 json_object_int_add(
3035 json_area
, "lsaOpaqueLinkNumber",
3036 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
3037 json_object_int_add(
3038 json_area
, "lsaOpaqueLinkChecksum",
3039 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
3040 json_object_int_add(
3041 json_area
, "lsaOpaqueAreaNumber",
3042 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
3043 json_object_int_add(
3044 json_area
, "lsaOpaqueAreaChecksum",
3045 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
3048 " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n",
3049 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
),
3050 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
3052 " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n",
3053 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
),
3054 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
3058 json_object_object_add(json_areas
,
3059 inet_ntop(AF_INET
, &area
->area_id
,
3066 static int show_ip_ospf_common(struct vty
*vty
, struct ospf
*ospf
,
3067 json_object
*json
, uint8_t use_vrf
)
3069 struct listnode
*node
, *nnode
;
3070 struct ospf_area
*area
;
3071 struct timeval result
;
3072 char timebuf
[OSPF_TIME_DUMP_SIZE
];
3073 json_object
*json_vrf
= NULL
;
3074 json_object
*json_areas
= NULL
;
3078 json_vrf
= json_object_new_object();
3081 json_areas
= json_object_new_object();
3084 if (ospf
->instance
) {
3086 json_object_int_add(json
, "ospfInstance",
3089 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
3093 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3095 /* Show Router ID. */
3097 json_object_string_addf(json_vrf
, "routerId", "%pI4",
3100 vty_out(vty
, " OSPF Routing Process, Router ID: %pI4\n",
3104 /* Graceful shutdown */
3105 if (ospf
->t_deferred_shutdown
) {
3110 &ospf
->t_deferred_shutdown
->u
.sands
,
3113 json_object_int_add(json_vrf
, "deferredShutdownMsecs",
3117 " Deferred shutdown in progress, %s remaining\n",
3118 ospf_timer_dump(ospf
->t_deferred_shutdown
,
3119 timebuf
, sizeof(timebuf
)));
3123 /* Show capability. */
3125 json_object_boolean_true_add(json_vrf
, "tosRoutesOnly");
3126 json_object_boolean_true_add(json_vrf
, "rfc2328Conform");
3127 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
3128 json_object_boolean_true_add(json_vrf
,
3129 "rfc1583Compatibility");
3132 vty_out(vty
, " Supports only single TOS (TOS0) routes\n");
3133 vty_out(vty
, " This implementation conforms to RFC2328\n");
3134 vty_out(vty
, " RFC1583Compatibility flag is %s\n",
3135 CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)
3141 if (CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)) {
3142 json_object_boolean_true_add(json_vrf
, "opaqueCapable");
3145 vty_out(vty
, " OpaqueCapability flag is %s\n",
3146 CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)
3151 /* Show stub-router configuration */
3152 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
3153 || ospf
->stub_router_shutdown_time
3154 != OSPF_STUB_ROUTER_UNCONFIGURED
) {
3156 json_object_boolean_true_add(json_vrf
,
3157 "stubAdvertisement");
3158 if (ospf
->stub_router_startup_time
3159 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3160 json_object_int_add(
3161 json_vrf
, "postStartEnabledSecs",
3162 ospf
->stub_router_startup_time
);
3163 if (ospf
->stub_router_shutdown_time
3164 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3165 json_object_int_add(
3166 json_vrf
, "preShutdownEnabledSecs",
3167 ospf
->stub_router_shutdown_time
);
3170 " Stub router advertisement is configured\n");
3171 if (ospf
->stub_router_startup_time
3172 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3174 " Enabled for %us after start-up\n",
3175 ospf
->stub_router_startup_time
);
3176 if (ospf
->stub_router_shutdown_time
3177 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3179 " Enabled for %us prior to full shutdown\n",
3180 ospf
->stub_router_shutdown_time
);
3184 /* Show SPF timers. */
3186 json_object_int_add(json_vrf
, "spfScheduleDelayMsecs",
3188 json_object_int_add(json_vrf
, "holdtimeMinMsecs",
3189 ospf
->spf_holdtime
);
3190 json_object_int_add(json_vrf
, "holdtimeMaxMsecs",
3191 ospf
->spf_max_holdtime
);
3192 json_object_int_add(json_vrf
, "holdtimeMultplier",
3193 ospf
->spf_hold_multiplier
);
3196 " Initial SPF scheduling delay %d millisec(s)\n"
3197 " Minimum hold time between consecutive SPFs %d millisec(s)\n"
3198 " Maximum hold time between consecutive SPFs %d millisec(s)\n"
3199 " Hold time multiplier is currently %d\n",
3200 ospf
->spf_delay
, ospf
->spf_holdtime
,
3201 ospf
->spf_max_holdtime
, ospf
->spf_hold_multiplier
);
3205 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3206 long time_store
= 0;
3209 monotime_since(&ospf
->ts_spf
, NULL
) / 1000LL;
3210 json_object_int_add(json_vrf
, "spfLastExecutedMsecs",
3213 time_store
= (1000 * ospf
->ts_spf_duration
.tv_sec
)
3214 + (ospf
->ts_spf_duration
.tv_usec
/ 1000);
3215 json_object_int_add(json_vrf
, "spfLastDurationMsecs",
3218 json_object_boolean_true_add(json_vrf
, "spfHasNotRun");
3220 vty_out(vty
, " SPF algorithm ");
3221 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3222 monotime_since(&ospf
->ts_spf
, &result
);
3223 vty_out(vty
, "last executed %s ago\n",
3224 ospf_timeval_dump(&result
, timebuf
,
3226 vty_out(vty
, " Last SPF duration %s\n",
3227 ospf_timeval_dump(&ospf
->ts_spf_duration
,
3228 timebuf
, sizeof(timebuf
)));
3230 vty_out(vty
, "has not been run\n");
3234 if (ospf
->t_spf_calc
) {
3237 monotime_until(&ospf
->t_spf_calc
->u
.sands
, NULL
)
3239 json_object_int_add(json_vrf
, "spfTimerDueInMsecs",
3243 json_object_int_add(json_vrf
, "lsaMinIntervalMsecs",
3244 ospf
->min_ls_interval
);
3245 json_object_int_add(json_vrf
, "lsaMinArrivalMsecs",
3246 ospf
->min_ls_arrival
);
3247 /* Show write multiplier values */
3248 json_object_int_add(json_vrf
, "writeMultiplier",
3249 ospf
->write_oi_count
);
3250 /* Show refresh parameters. */
3251 json_object_int_add(json_vrf
, "refreshTimerMsecs",
3252 ospf
->lsa_refresh_interval
* 1000);
3254 /* show max multipath */
3255 json_object_int_add(json_vrf
, "maximumPaths",
3256 ospf
->max_multipath
);
3258 /* show administrative distance */
3259 json_object_int_add(json_vrf
, "preference",
3261 ? ospf
->distance_all
3262 : ZEBRA_OSPF_DISTANCE_DEFAULT
);
3264 vty_out(vty
, " SPF timer %s%s\n",
3265 (ospf
->t_spf_calc
? "due in " : "is "),
3266 ospf_timer_dump(ospf
->t_spf_calc
, timebuf
,
3269 vty_out(vty
, " LSA minimum interval %d msecs\n",
3270 ospf
->min_ls_interval
);
3271 vty_out(vty
, " LSA minimum arrival %d msecs\n",
3272 ospf
->min_ls_arrival
);
3274 /* Show write multiplier values */
3275 vty_out(vty
, " Write Multiplier set to %d \n",
3276 ospf
->write_oi_count
);
3278 /* Show refresh parameters. */
3279 vty_out(vty
, " Refresh timer %d secs\n",
3280 ospf
->lsa_refresh_interval
);
3282 /* show max multipath */
3283 vty_out(vty
, " Maximum multiple paths(ECMP) supported %d\n",
3284 ospf
->max_multipath
);
3286 /* show administrative distance */
3287 vty_out(vty
, " Administrative distance %u\n",
3288 ospf
->distance_all
? ospf
->distance_all
3289 : ZEBRA_OSPF_DISTANCE_DEFAULT
);
3292 /* Show ABR/ASBR flags. */
3293 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ABR
)) {
3295 json_object_string_add(
3296 json_vrf
, "abrType",
3297 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3300 " This router is an ABR, ABR type is: %s\n",
3301 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3303 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ASBR
)) {
3305 json_object_string_add(
3306 json_vrf
, "asbrRouter",
3307 "injectingExternalRoutingInformation");
3310 " This router is an ASBR (injecting external routing information)\n");
3313 /* Show Number of AS-external-LSAs. */
3315 json_object_int_add(
3316 json_vrf
, "lsaExternalCounter",
3317 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3318 json_object_int_add(
3319 json_vrf
, "lsaExternalChecksum",
3320 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3323 " Number of external LSA %ld. Checksum Sum 0x%08x\n",
3324 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
),
3325 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3329 json_object_int_add(
3330 json_vrf
, "lsaAsopaqueCounter",
3331 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3332 json_object_int_add(
3333 json_vrf
, "lsaAsOpaqueChecksum",
3334 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3337 " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n",
3338 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
),
3339 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3342 /* Show number of areas attached. */
3344 json_object_int_add(json_vrf
, "attachedAreaCounter",
3345 listcount(ospf
->areas
));
3347 vty_out(vty
, " Number of areas attached to this router: %d\n",
3348 listcount(ospf
->areas
));
3350 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
3351 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
)) {
3353 json_object_boolean_true_add(
3354 json_vrf
, "adjacencyChangesLoggedAll");
3357 " All adjacency changes are logged\n");
3360 json_object_boolean_true_add(
3361 json_vrf
, "adjacencyChangesLogged");
3363 vty_out(vty
, " Adjacency changes are logged\n");
3367 /* show LDP-Sync status */
3368 ospf_ldp_sync_show_info(vty
, ospf
, json_vrf
, json
? 1 : 0);
3370 /* Show each area status. */
3371 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
3372 show_ip_ospf_area(vty
, area
, json_areas
, json
? 1 : 0);
3376 json_object_object_add(json_vrf
, "areas", json_areas
);
3377 json_object_object_add(json
, ospf_get_name(ospf
),
3380 json_object_object_add(json
, "areas", json_areas
);
3388 DEFUN (show_ip_ospf
,
3390 "show ip ospf [vrf <NAME|all>] [json]",
3393 "OSPF information\n"
3399 bool uj
= use_json(argc
, argv
);
3400 struct listnode
*node
= NULL
;
3401 char *vrf_name
= NULL
;
3402 bool all_vrf
= false;
3403 int ret
= CMD_SUCCESS
;
3406 json_object
*json
= NULL
;
3407 uint8_t use_vrf
= 0;
3409 if (listcount(om
->ospf
) == 0)
3412 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
3415 json
= json_object_new_object();
3417 /* vrf input is provided could be all or specific vrf*/
3419 bool ospf_output
= false;
3424 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
3425 if (!ospf
->oi_running
)
3428 ret
= show_ip_ospf_common(vty
, ospf
, json
,
3432 vty_json(vty
, json
);
3433 else if (!ospf_output
)
3434 vty_out(vty
, "%% OSPF is not enabled\n");
3437 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
3438 if ((ospf
== NULL
) || !ospf
->oi_running
) {
3440 vty_json(vty
, json
);
3443 "%% OSPF is not enabled in vrf %s\n",
3449 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
3450 /* Display default ospf (instance 0) info */
3451 if (ospf
== NULL
|| !ospf
->oi_running
) {
3453 vty_json(vty
, json
);
3456 "%% OSPF is not enabled in vrf default\n");
3463 show_ip_ospf_common(vty
, ospf
, json
, use_vrf
);
3465 vty_out(vty
, "%s\n",
3466 json_object_to_json_string_ext(
3467 json
, JSON_C_TO_STRING_PRETTY
));
3471 json_object_free(json
);
3476 DEFUN (show_ip_ospf_instance
,
3477 show_ip_ospf_instance_cmd
,
3478 "show ip ospf (1-65535) [json]",
3481 "OSPF information\n"
3487 unsigned short instance
= 0;
3488 bool uj
= use_json(argc
, argv
);
3489 int ret
= CMD_SUCCESS
;
3490 json_object
*json
= NULL
;
3492 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
3493 if (instance
!= ospf_instance
)
3494 return CMD_NOT_MY_INSTANCE
;
3496 ospf
= ospf_lookup_instance(instance
);
3497 if (!ospf
|| !ospf
->oi_running
)
3501 json
= json_object_new_object();
3503 ret
= show_ip_ospf_common(vty
, ospf
, json
, 0);
3506 vty_json(vty
, json
);
3511 static void ospf_interface_auth_show(struct vty
*vty
, struct ospf_interface
*oi
,
3512 json_object
*json
, bool use_json
)
3516 auth_type
= OSPF_IF_PARAM(oi
, auth_type
);
3518 switch (auth_type
) {
3519 case OSPF_AUTH_NULL
:
3521 json_object_string_add(json
, "authentication",
3522 "authenticationNone");
3524 vty_out(vty
, " Authentication NULL is enabled\n");
3526 case OSPF_AUTH_SIMPLE
: {
3528 json_object_string_add(json
, "authentication",
3529 "authenticationSimplePassword");
3532 " Simple password authentication enabled\n");
3535 case OSPF_AUTH_CRYPTOGRAPHIC
: {
3536 struct crypt_key
*ckey
;
3538 if (list_isempty(OSPF_IF_PARAM(oi
, auth_crypt
)))
3541 ckey
= listgetdata(listtail(OSPF_IF_PARAM(oi
, auth_crypt
)));
3544 json_object_string_add(json
, "authentication",
3545 "authenticationMessageDigest");
3548 " Cryptographic authentication enabled\n");
3549 vty_out(vty
, " Algorithm:MD5\n");
3559 static void show_ip_ospf_interface_sub(struct vty
*vty
, struct ospf
*ospf
,
3560 struct interface
*ifp
,
3561 json_object
*json_interface_sub
,
3565 struct ospf_neighbor
*nbr
;
3566 struct route_node
*rn
;
3567 uint32_t bandwidth
= ifp
->bandwidth
? ifp
->bandwidth
: ifp
->speed
;
3569 /* Is interface up? */
3571 is_up
= if_is_operative(ifp
);
3573 json_object_boolean_true_add(json_interface_sub
,
3576 json_object_boolean_false_add(json_interface_sub
,
3579 json_object_int_add(json_interface_sub
, "ifIndex",
3581 json_object_int_add(json_interface_sub
, "mtuBytes", ifp
->mtu
);
3582 json_object_int_add(json_interface_sub
, "bandwidthMbit",
3584 json_object_string_add(json_interface_sub
, "ifFlags",
3585 if_flag_dump(ifp
->flags
));
3587 vty_out(vty
, "%s is %s\n", ifp
->name
,
3588 ((is_up
= if_is_operative(ifp
)) ? "up" : "down"));
3589 vty_out(vty
, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n",
3590 ifp
->ifindex
, ifp
->mtu
, bandwidth
,
3591 if_flag_dump(ifp
->flags
));
3594 /* Is interface OSPF enabled? */
3596 if (ospf_oi_count(ifp
) == 0) {
3597 json_object_boolean_false_add(json_interface_sub
,
3600 } else if (!is_up
) {
3601 json_object_boolean_false_add(json_interface_sub
,
3605 json_object_boolean_true_add(json_interface_sub
,
3608 if (ospf_oi_count(ifp
) == 0) {
3609 vty_out(vty
, " OSPF not enabled on this interface\n");
3611 } else if (!is_up
) {
3613 " OSPF is enabled, but not running on this interface\n");
3618 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
3619 struct ospf_interface
*oi
= rn
->info
;
3624 if (CHECK_FLAG(oi
->connected
->flags
, ZEBRA_IFA_UNNUMBERED
)) {
3626 json_object_boolean_true_add(json_interface_sub
,
3629 vty_out(vty
, " This interface is UNNUMBERED,");
3631 struct in_addr dest
;
3634 /* Show OSPF interface information. */
3636 json_object_string_addf(
3637 json_interface_sub
, "ipAddress", "%pI4",
3638 &oi
->address
->u
.prefix4
);
3639 json_object_int_add(json_interface_sub
,
3640 "ipAddressPrefixlen",
3641 oi
->address
->prefixlen
);
3643 vty_out(vty
, " Internet Address %pFX,",
3646 /* For Vlinks, showing the peer address is
3647 * probably more informative than the local
3648 * interface that is being used */
3649 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
) {
3651 dest
= oi
->vl_data
->peer_addr
;
3652 } else if (CONNECTED_PEER(oi
->connected
)
3653 && oi
->connected
->destination
) {
3655 dest
= oi
->connected
->destination
->u
.prefix4
;
3658 dest
.s_addr
= ipv4_broadcast_addr(
3659 oi
->connected
->address
->u
.prefix4
.s_addr
,
3660 oi
->connected
->address
->prefixlen
);
3664 json_object_string_add(
3666 "ospfIfType", dstr
);
3667 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3668 json_object_string_addf(
3669 json_interface_sub
, "vlinkPeer",
3672 json_object_string_addf(
3674 "localIfUsed", "%pI4", &dest
);
3676 vty_out(vty
, " %s %pI4,", dstr
,
3680 json_object_string_add(json_interface_sub
, "area",
3681 ospf_area_desc_string(oi
->area
));
3682 if (OSPF_IF_PARAM(oi
, mtu_ignore
))
3683 json_object_boolean_true_add(
3685 "mtuMismatchDetect");
3686 json_object_string_addf(json_interface_sub
, "routerId",
3687 "%pI4", &ospf
->router_id
);
3688 json_object_string_add(json_interface_sub
,
3690 ospf_network_type_str
[oi
->type
]);
3691 json_object_int_add(json_interface_sub
, "cost",
3693 json_object_int_add(
3694 json_interface_sub
, "transmitDelaySecs",
3695 OSPF_IF_PARAM(oi
, transmit_delay
));
3696 json_object_string_add(json_interface_sub
, "state",
3697 lookup_msg(ospf_ism_state_msg
,
3699 json_object_int_add(json_interface_sub
, "priority",
3702 vty_out(vty
, " Area %s\n",
3703 ospf_area_desc_string(oi
->area
));
3705 vty_out(vty
, " MTU mismatch detection: %s\n",
3706 OSPF_IF_PARAM(oi
, mtu_ignore
) ? "disabled"
3710 " Router ID %pI4, Network Type %s, Cost: %d\n",
3712 ospf_network_type_str
[oi
->type
],
3716 " Transmit Delay is %d sec, State %s, Priority %d\n",
3717 OSPF_IF_PARAM(oi
, transmit_delay
),
3718 lookup_msg(ospf_ism_state_msg
, oi
->state
, NULL
),
3722 /* Show DR information. */
3723 if (DR(oi
).s_addr
== INADDR_ANY
) {
3726 " No backup designated router on this network\n");
3728 nbr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &DR(oi
));
3731 json_object_string_addf(
3732 json_interface_sub
, "drId",
3733 "%pI4", &nbr
->router_id
);
3734 json_object_string_addf(
3735 json_interface_sub
, "drAddress",
3737 &nbr
->address
.u
.prefix4
);
3740 " Designated Router (ID) %pI4",
3743 " Interface Address %pFX\n",
3749 nbr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &BDR(oi
));
3753 " No backup designated router on this network\n");
3756 json_object_string_addf(
3757 json_interface_sub
, "bdrId",
3758 "%pI4", &nbr
->router_id
);
3759 json_object_string_addf(
3761 "bdrAddress", "%pI4",
3762 &nbr
->address
.u
.prefix4
);
3765 " Backup Designated Router (ID) %pI4,",
3767 vty_out(vty
, " Interface Address %pI4\n",
3768 &nbr
->address
.u
.prefix4
);
3773 /* Next network-LSA sequence number we'll use, if we're elected
3776 && ntohl(oi
->params
->network_lsa_seqnum
)
3777 != OSPF_INITIAL_SEQUENCE_NUMBER
) {
3779 json_object_int_add(
3781 "networkLsaSequence",
3782 ntohl(oi
->params
->network_lsa_seqnum
));
3785 " Saved Network-LSA sequence number 0x%x\n",
3786 ntohl(oi
->params
->network_lsa_seqnum
));
3790 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3791 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3792 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3793 json_object_boolean_true_add(
3795 "mcastMemberOspfAllRouters");
3796 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3797 json_object_boolean_true_add(
3799 "mcastMemberOspfDesignatedRouters");
3802 vty_out(vty
, " Multicast group memberships:");
3803 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3804 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3805 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3806 vty_out(vty
, " OSPFAllRouters");
3807 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3808 vty_out(vty
, " OSPFDesignatedRouters");
3810 vty_out(vty
, " <None>");
3815 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3816 json_object_int_add(
3817 json_interface_sub
, "timerMsecs",
3818 OSPF_IF_PARAM(oi
, v_hello
) * 1000);
3820 json_object_int_add(
3821 json_interface_sub
, "timerMsecs",
3822 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3823 json_object_int_add(json_interface_sub
,
3825 OSPF_IF_PARAM(oi
, v_wait
));
3826 json_object_int_add(json_interface_sub
,
3828 OSPF_IF_PARAM(oi
, v_wait
));
3829 json_object_int_add(
3830 json_interface_sub
, "timerRetransmitSecs",
3831 OSPF_IF_PARAM(oi
, retransmit_interval
));
3833 vty_out(vty
, " Timer intervals configured,");
3834 vty_out(vty
, " Hello ");
3835 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3836 vty_out(vty
, "%ds,",
3837 OSPF_IF_PARAM(oi
, v_hello
));
3839 vty_out(vty
, "%dms,",
3840 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3841 vty_out(vty
, " Dead %ds, Wait %ds, Retransmit %d\n",
3842 OSPF_IF_PARAM(oi
, v_wait
),
3843 OSPF_IF_PARAM(oi
, v_wait
),
3844 OSPF_IF_PARAM(oi
, retransmit_interval
));
3847 if (OSPF_IF_PASSIVE_STATUS(oi
) == OSPF_IF_ACTIVE
) {
3848 char timebuf
[OSPF_TIME_DUMP_SIZE
];
3850 long time_store
= 0;
3854 &oi
->t_hello
->u
.sands
,
3857 json_object_int_add(json_interface_sub
,
3858 "timerHelloInMsecs",
3861 vty_out(vty
, " Hello due in %s\n",
3862 ospf_timer_dump(oi
->t_hello
, timebuf
,
3864 } else /* passive-interface is set */
3867 json_object_boolean_true_add(
3869 "timerPassiveIface");
3872 " No Hellos (Passive interface)\n");
3876 json_object_int_add(json_interface_sub
, "nbrCount",
3877 ospf_nbr_count(oi
, 0));
3878 json_object_int_add(json_interface_sub
,
3880 ospf_nbr_count(oi
, NSM_Full
));
3883 " Neighbor Count is %d, Adjacent neighbor count is %d\n",
3884 ospf_nbr_count(oi
, 0),
3885 ospf_nbr_count(oi
, NSM_Full
));
3887 ospf_interface_bfd_show(vty
, ifp
, json_interface_sub
);
3889 /* OSPF Authentication information */
3890 ospf_interface_auth_show(vty
, oi
, json_interface_sub
, use_json
);
3894 static int show_ip_ospf_interface_common(struct vty
*vty
, struct ospf
*ospf
,
3895 char *intf_name
, uint8_t use_vrf
,
3896 json_object
*json
, bool use_json
)
3898 struct interface
*ifp
;
3899 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
3900 json_object
*json_vrf
= NULL
;
3901 json_object
*json_interface_sub
= NULL
, *json_interface
= NULL
;
3905 json_vrf
= json_object_new_object();
3908 json_interface
= json_object_new_object();
3911 if (ospf
->instance
) {
3913 json_object_int_add(json
, "ospfInstance",
3916 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
3919 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3921 if (intf_name
== NULL
) {
3922 /* Show All Interfaces.*/
3923 FOR_ALL_INTERFACES (vrf
, ifp
) {
3924 if (ospf_oi_count(ifp
)) {
3926 json_interface_sub
=
3927 json_object_new_object();
3929 show_ip_ospf_interface_sub(vty
, ospf
, ifp
,
3934 json_object_object_add(
3935 json_interface
, ifp
->name
,
3936 json_interface_sub
);
3941 json_object_object_add(json_vrf
, "interfaces",
3944 /* Interface name is specified. */
3945 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
3948 json_object_boolean_true_add(json_vrf
,
3951 vty_out(vty
, "No such interface name\n");
3954 json_interface_sub
= json_object_new_object();
3955 json_interface
= json_object_new_object();
3958 show_ip_ospf_interface_sub(
3959 vty
, ospf
, ifp
, json_interface_sub
, use_json
);
3962 json_object_object_add(json_interface
,
3964 json_interface_sub
);
3965 json_object_object_add(json_vrf
, "interfaces",
3973 json_object_object_add(json
, ospf_get_name(ospf
),
3982 static void show_ip_ospf_interface_traffic_sub(struct vty
*vty
,
3983 struct ospf_interface
*oi
,
3984 json_object
*json_interface_sub
,
3988 json_object_int_add(json_interface_sub
, "ifIndex",
3990 json_object_int_add(json_interface_sub
, "helloIn",
3992 json_object_int_add(json_interface_sub
, "helloOut",
3994 json_object_int_add(json_interface_sub
, "dbDescIn",
3996 json_object_int_add(json_interface_sub
, "dbDescOut",
3998 json_object_int_add(json_interface_sub
, "lsReqIn",
4000 json_object_int_add(json_interface_sub
, "lsReqOut",
4002 json_object_int_add(json_interface_sub
, "lsUpdIn",
4004 json_object_int_add(json_interface_sub
, "lsUpdOut",
4006 json_object_int_add(json_interface_sub
, "lsAckIn",
4008 json_object_int_add(json_interface_sub
, "lsAckOut",
4010 json_object_int_add(json_interface_sub
, "packetsQueued",
4011 listcount(oi
->obuf
));
4014 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u %12lu\n",
4015 oi
->ifp
->name
, oi
->hello_in
, oi
->hello_out
,
4016 oi
->db_desc_in
, oi
->db_desc_out
, oi
->ls_req_in
,
4017 oi
->ls_req_out
, oi
->ls_upd_in
, oi
->ls_upd_out
,
4018 oi
->ls_ack_in
, oi
->ls_ack_out
, listcount(oi
->obuf
));
4022 /* OSPFv2 Packet Counters */
4023 static int show_ip_ospf_interface_traffic_common(
4024 struct vty
*vty
, struct ospf
*ospf
, char *intf_name
, json_object
*json
,
4025 int display_once
, uint8_t use_vrf
, bool use_json
)
4027 struct vrf
*vrf
= NULL
;
4028 struct interface
*ifp
= NULL
;
4029 json_object
*json_vrf
= NULL
;
4030 json_object
*json_interface_sub
= NULL
;
4032 if (!use_json
&& !display_once
) {
4034 vty_out(vty
, "%-12s%-17s%-17s%-17s%-17s%-17s%-17s\n",
4035 "Interface", " HELLO", " DB-Desc", " LS-Req",
4036 " LS-Update", " LS-Ack", " Packets");
4037 vty_out(vty
, "%-10s%-18s%-18s%-17s%-17s%-17s%-17s\n", "",
4038 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
4039 " Rx/Tx", " Queued");
4041 "-------------------------------------------------------------------------------------------------------------\n");
4042 } else if (use_json
) {
4044 json_vrf
= json_object_new_object();
4049 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4051 if (intf_name
== NULL
) {
4052 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
4053 FOR_ALL_INTERFACES (vrf
, ifp
) {
4054 struct route_node
*rn
;
4055 struct ospf_interface
*oi
;
4057 if (ospf_oi_count(ifp
) == 0)
4060 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
4061 rn
= route_next(rn
)) {
4068 json_interface_sub
=
4069 json_object_new_object();
4072 show_ip_ospf_interface_traffic_sub(
4073 vty
, oi
, json_interface_sub
, use_json
);
4075 json_object_object_add(
4076 json_vrf
, ifp
->name
,
4077 json_interface_sub
);
4082 /* Interface name is specified. */
4083 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
4085 struct route_node
*rn
;
4086 struct ospf_interface
*oi
;
4088 if (ospf_oi_count(ifp
) == 0) {
4090 " OSPF not enabled on this interface %s\n",
4095 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
4096 rn
= route_next(rn
)) {
4100 json_interface_sub
=
4101 json_object_new_object();
4104 show_ip_ospf_interface_traffic_sub(
4105 vty
, oi
, json_interface_sub
, use_json
);
4107 json_object_object_add(
4108 json_vrf
, ifp
->name
,
4109 json_interface_sub
);
4117 json_object_object_add(json
, ospf_get_name(ospf
),
4125 DEFUN (show_ip_ospf_interface
,
4126 show_ip_ospf_interface_cmd
,
4127 "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]",
4130 "OSPF information\n"
4133 "Interface information\n"
4138 bool uj
= use_json(argc
, argv
);
4139 struct listnode
*node
= NULL
;
4140 char *vrf_name
= NULL
, *intf_name
= NULL
;
4141 bool all_vrf
= false;
4142 int ret
= CMD_SUCCESS
;
4144 int idx_vrf
= 0, idx_intf
= 0;
4145 uint8_t use_vrf
= 0;
4146 json_object
*json
= NULL
;
4148 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4150 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4151 intf_name
= argv
[idx_intf
]->arg
;
4154 json
= json_object_new_object();
4156 /* vrf input is provided could be all or specific vrf*/
4160 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4161 if (!ospf
->oi_running
)
4163 ret
= show_ip_ospf_interface_common(
4164 vty
, ospf
, intf_name
, use_vrf
, json
,
4169 vty_json(vty
, json
);
4171 vty_out(vty
, "%% OSPF is not enabled\n");
4175 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4176 if (ospf
== NULL
|| !ospf
->oi_running
) {
4178 vty_json(vty
, json
);
4181 "%% OSPF is not enabled in vrf %s\n",
4186 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
4190 /* Display default ospf (instance 0) info */
4191 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4192 if (ospf
== NULL
|| !ospf
->oi_running
) {
4194 vty_json(vty
, json
);
4197 "%% OSPF is not enabled in vrf default\n");
4201 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
4206 vty_json(vty
, json
);
4211 DEFUN (show_ip_ospf_instance_interface
,
4212 show_ip_ospf_instance_interface_cmd
,
4213 "show ip ospf (1-65535) interface [INTERFACE] [json]",
4216 "OSPF information\n"
4218 "Interface information\n"
4225 unsigned short instance
= 0;
4226 bool uj
= use_json(argc
, argv
);
4227 char *intf_name
= NULL
;
4228 int ret
= CMD_SUCCESS
;
4229 json_object
*json
= NULL
;
4231 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4232 if (instance
!= ospf_instance
)
4233 return CMD_NOT_MY_INSTANCE
;
4235 ospf
= ospf_lookup_instance(instance
);
4236 if (!ospf
|| !ospf
->oi_running
)
4240 json
= json_object_new_object();
4242 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4243 intf_name
= argv
[idx_intf
]->arg
;
4245 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
, 0, json
, uj
);
4248 vty_json(vty
, json
);
4253 DEFUN (show_ip_ospf_interface_traffic
,
4254 show_ip_ospf_interface_traffic_cmd
,
4255 "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]",
4258 "OSPF information\n"
4261 "Interface information\n"
4262 "Protocol Packet counters\n"
4266 struct ospf
*ospf
= NULL
;
4267 struct listnode
*node
= NULL
;
4268 char *vrf_name
= NULL
, *intf_name
= NULL
;
4269 bool all_vrf
= false;
4271 int idx_vrf
= 0, idx_intf
= 0;
4272 bool uj
= use_json(argc
, argv
);
4273 json_object
*json
= NULL
;
4274 int ret
= CMD_SUCCESS
;
4275 int display_once
= 0;
4276 uint8_t use_vrf
= 0;
4278 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4280 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4281 intf_name
= argv
[idx_intf
]->arg
;
4284 json
= json_object_new_object();
4289 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4290 if (!ospf
->oi_running
)
4293 ret
= show_ip_ospf_interface_traffic_common(
4294 vty
, ospf
, intf_name
, json
,
4295 display_once
, use_vrf
, uj
);
4300 vty_json(vty
, json
);
4304 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4305 if (ospf
== NULL
|| !ospf
->oi_running
) {
4307 json_object_free(json
);
4311 ret
= show_ip_ospf_interface_traffic_common(
4312 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4314 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4315 if (ospf
== NULL
|| !ospf
->oi_running
) {
4317 json_object_free(json
);
4321 ret
= show_ip_ospf_interface_traffic_common(
4322 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4326 vty_json(vty
, json
);
4332 static void show_ip_ospf_neighbour_header(struct vty
*vty
)
4334 vty_out(vty
, "\n%-15s %-3s %-15s %-15s %-9s %-15s %-32s %5s %5s %5s\n",
4335 "Neighbor ID", "Pri", "State", "Up Time", "Dead Time",
4336 "Address", "Interface", "RXmtL", "RqstL", "DBsmL");
4339 static void show_ip_ospf_neighbour_brief(struct vty
*vty
,
4340 struct ospf_neighbor
*nbr
,
4341 struct ospf_neighbor
*prev_nbr
,
4342 json_object
*json
, bool use_json
)
4345 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4346 json_object
*json_neighbor
= NULL
, *json_neigh_array
= NULL
;
4347 struct timeval res
= {.tv_sec
= 0, .tv_usec
= 0};
4349 char uptime
[OSPF_TIME_DUMP_SIZE
];
4351 if (nbr
->ts_last_progress
.tv_sec
|| nbr
->ts_last_progress
.tv_usec
)
4353 monotime_since(&nbr
->ts_last_progress
, &res
) / 1000LL;
4356 char neigh_str
[INET_ADDRSTRLEN
];
4358 if (prev_nbr
&& !IPV4_ADDR_SAME(&prev_nbr
->src
, &nbr
->src
)) {
4359 /* Start new neigh list */
4360 json_neigh_array
= NULL
;
4363 if (nbr
->state
== NSM_Attempt
&&
4364 nbr
->router_id
.s_addr
== INADDR_ANY
)
4365 strlcpy(neigh_str
, "neighbor", sizeof(neigh_str
));
4367 inet_ntop(AF_INET
, &nbr
->router_id
, neigh_str
,
4370 json_object_object_get_ex(json
, neigh_str
, &json_neigh_array
);
4372 if (!json_neigh_array
) {
4373 json_neigh_array
= json_object_new_array();
4374 json_object_object_add(json
, neigh_str
,
4378 json_neighbor
= json_object_new_object();
4380 ospf_nbr_ism_state_message(nbr
, msgbuf
, sizeof(msgbuf
));
4381 #if CONFDATE > 20230321
4383 "Remove show_ip_ospf_neighbor_sub() JSON keys: priority, state, deadTimeMsecs, address, retransmitCounter, requestCounter, dbSummaryCounter")
4385 json_object_int_add(json_neighbor
, "priority", nbr
->priority
);
4386 json_object_string_add(json_neighbor
, "state", msgbuf
);
4387 json_object_int_add(json_neighbor
, "nbrPriority",
4389 json_object_string_add(json_neighbor
, "nbrState", msgbuf
);
4391 json_object_string_add(
4392 json_neighbor
, "converged",
4393 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
4394 json_object_string_add(json_neighbor
, "role",
4395 lookup_msg(ospf_ism_state_msg
,
4396 ospf_nbr_ism_state(nbr
),
4398 if (nbr
->t_inactivity
) {
4401 time_store
= monotime_until(&nbr
->t_inactivity
->u
.sands
,
4404 json_object_int_add(json_neighbor
, "upTimeInMsec",
4406 json_object_int_add(json_neighbor
, "deadTimeMsecs",
4408 json_object_int_add(json_neighbor
,
4409 "routerDeadIntervalTimerDueMsec",
4411 json_object_string_add(
4412 json_neighbor
, "upTime",
4413 ospf_timeval_dump(&res
, uptime
,
4415 json_object_string_add(
4416 json_neighbor
, "deadTime",
4417 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
4420 json_object_string_add(json_neighbor
, "deadTimeMsecs",
4422 json_object_string_add(json_neighbor
,
4423 "routerDeadIntervalTimerDueMsec",
4426 json_object_string_addf(json_neighbor
, "address", "%pI4",
4428 json_object_string_addf(json_neighbor
, "ifaceAddress", "%pI4",
4430 json_object_string_add(json_neighbor
, "ifaceName",
4432 json_object_int_add(json_neighbor
, "retransmitCounter",
4433 ospf_ls_retransmit_count(nbr
));
4434 json_object_int_add(json_neighbor
,
4435 "linkStateRetransmissionListCounter",
4436 ospf_ls_retransmit_count(nbr
));
4437 json_object_int_add(json_neighbor
, "requestCounter",
4438 ospf_ls_request_count(nbr
));
4439 json_object_int_add(json_neighbor
,
4440 "linkStateRequestListCounter",
4441 ospf_ls_request_count(nbr
));
4442 json_object_int_add(json_neighbor
, "dbSummaryCounter",
4443 ospf_db_summary_count(nbr
));
4444 json_object_int_add(json_neighbor
, "databaseSummaryListCounter",
4445 ospf_db_summary_count(nbr
));
4447 json_object_array_add(json_neigh_array
, json_neighbor
);
4449 ospf_nbr_ism_state_message(nbr
, msgbuf
, sizeof(msgbuf
));
4451 if (nbr
->state
== NSM_Attempt
&&
4452 nbr
->router_id
.s_addr
== INADDR_ANY
)
4453 vty_out(vty
, "%-15s %3d %-15s ", "-", nbr
->priority
,
4456 vty_out(vty
, "%-15pI4 %3d %-15s ", &nbr
->router_id
,
4457 nbr
->priority
, msgbuf
);
4459 vty_out(vty
, "%-15s ",
4460 ospf_timeval_dump(&res
, uptime
, sizeof(uptime
)));
4462 vty_out(vty
, "%9s ",
4463 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
4465 vty_out(vty
, "%-15pI4 ", &nbr
->src
);
4466 vty_out(vty
, "%-32s %5ld %5ld %5d\n", IF_NAME(nbr
->oi
),
4467 ospf_ls_retransmit_count(nbr
),
4468 ospf_ls_request_count(nbr
), ospf_db_summary_count(nbr
));
4472 static void show_ip_ospf_neighbor_sub(struct vty
*vty
,
4473 struct ospf_interface
*oi
,
4474 json_object
*json
, bool use_json
)
4476 struct route_node
*rn
;
4477 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
4479 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
4485 /* Do not show myself. */
4486 if (nbr
== oi
->nbr_self
)
4488 /* Down state is not shown. */
4489 if (nbr
->state
== NSM_Down
)
4494 show_ip_ospf_neighbour_brief(vty
, nbr
, prev_nbr
, json
,
4499 static int show_ip_ospf_neighbor_common(struct vty
*vty
, struct ospf
*ospf
,
4500 json_object
*json
, bool use_json
,
4503 struct ospf_interface
*oi
;
4504 struct listnode
*node
;
4505 json_object
*json_vrf
= NULL
;
4506 json_object
*json_nbr_sub
= NULL
;
4510 json_vrf
= json_object_new_object();
4513 json_nbr_sub
= json_object_new_object();
4516 if (ospf
->instance
) {
4518 json_object_int_add(json
, "ospfInstance",
4521 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4524 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4526 show_ip_ospf_neighbour_header(vty
);
4528 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4529 if (ospf_interface_neighbor_count(oi
) == 0)
4531 show_ip_ospf_neighbor_sub(vty
, oi
, json_nbr_sub
, use_json
);
4535 json_object_object_add(json_vrf
, "neighbors", json_nbr_sub
);
4537 json_object_object_add(json
, ospf_get_name(ospf
),
4545 DEFUN (show_ip_ospf_neighbor
,
4546 show_ip_ospf_neighbor_cmd
,
4547 "show ip ospf [vrf <NAME|all>] neighbor [json]",
4550 "OSPF information\n"
4557 bool uj
= use_json(argc
, argv
);
4558 struct listnode
*node
= NULL
;
4559 char *vrf_name
= NULL
;
4560 bool all_vrf
= false;
4561 int ret
= CMD_SUCCESS
;
4564 uint8_t use_vrf
= 0;
4565 json_object
*json
= NULL
;
4567 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4570 json
= json_object_new_object();
4572 /* vrf input is provided could be all or specific vrf*/
4576 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4577 if (!ospf
->oi_running
)
4579 ret
= show_ip_ospf_neighbor_common(
4580 vty
, ospf
, json
, uj
, use_vrf
);
4584 vty_json(vty
, json
);
4586 vty_out(vty
, "OSPF is not enabled\n");
4591 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4592 if (ospf
== NULL
|| !ospf
->oi_running
) {
4594 vty_json(vty
, json
);
4597 "%% OSPF is not enabled in vrf %s\n",
4603 /* Display default ospf (instance 0) info */
4604 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4605 if (ospf
== NULL
|| !ospf
->oi_running
) {
4607 vty_json(vty
, json
);
4610 "%% OSPF is not enabled in vrf default\n");
4617 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
,
4621 vty_out(vty
, "%s\n",
4622 json_object_to_json_string_ext(
4623 json
, JSON_C_TO_STRING_PRETTY
));
4628 json_object_free(json
);
4634 DEFUN (show_ip_ospf_instance_neighbor
,
4635 show_ip_ospf_instance_neighbor_cmd
,
4636 "show ip ospf (1-65535) neighbor [json]",
4639 "OSPF information\n"
4646 unsigned short instance
= 0;
4647 bool uj
= use_json(argc
, argv
);
4648 json_object
*json
= NULL
;
4649 int ret
= CMD_SUCCESS
;
4651 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4652 if (instance
!= ospf_instance
)
4653 return CMD_NOT_MY_INSTANCE
;
4655 ospf
= ospf_lookup_instance(instance
);
4656 if (!ospf
|| !ospf
->oi_running
)
4660 json
= json_object_new_object();
4662 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
, 0);
4665 vty_json(vty
, json
);
4670 static int show_ip_ospf_neighbor_all_common(struct vty
*vty
, struct ospf
*ospf
,
4671 json_object
*json
, bool use_json
,
4674 struct listnode
*node
;
4675 struct ospf_interface
*oi
;
4676 char buf
[PREFIX_STRLEN
];
4677 json_object
*json_vrf
= NULL
;
4678 json_object
*json_neighbor_sub
= NULL
;
4682 json_vrf
= json_object_new_object();
4687 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4689 show_ip_ospf_neighbour_header(vty
);
4691 if (ospf
->instance
) {
4693 json_object_int_add(json_vrf
, "ospfInstance",
4696 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4699 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4700 struct listnode
*nbr_node
;
4701 struct ospf_nbr_nbma
*nbr_nbma
;
4703 show_ip_ospf_neighbor_sub(vty
, oi
, json_vrf
, use_json
);
4705 /* print Down neighbor status */
4706 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nbr_node
, nbr_nbma
)) {
4707 if (nbr_nbma
->nbr
== NULL
4708 || nbr_nbma
->nbr
->state
== NSM_Down
) {
4711 json_object_new_object();
4712 json_object_int_add(json_neighbor_sub
,
4714 nbr_nbma
->priority
);
4715 json_object_boolean_true_add(
4718 json_object_string_add(
4722 json_object_int_add(
4724 "nbrNbmaRetransmitCounter", 0);
4725 json_object_int_add(
4727 "nbrNbmaRequestCounter", 0);
4728 json_object_int_add(
4730 "nbrNbmaDbSummaryCounter", 0);
4731 json_object_object_add(
4734 &nbr_nbma
->addr
, buf
,
4738 vty_out(vty
, "%-15s %3d %-15s %9s ",
4739 "-", nbr_nbma
->priority
, "Down",
4742 "%-32pI4 %-20s %5d %5d %5d\n",
4744 IF_NAME(oi
), 0, 0, 0);
4752 json_object_object_add(json
, ospf_get_name(ospf
),
4760 DEFUN (show_ip_ospf_neighbor_all
,
4761 show_ip_ospf_neighbor_all_cmd
,
4762 "show ip ospf [vrf <NAME|all>] neighbor all [json]",
4765 "OSPF information\n"
4769 "include down status neighbor\n"
4773 bool uj
= use_json(argc
, argv
);
4774 struct listnode
*node
= NULL
;
4775 char *vrf_name
= NULL
;
4776 bool all_vrf
= false;
4777 int ret
= CMD_SUCCESS
;
4780 uint8_t use_vrf
= 0;
4781 json_object
*json
= NULL
;
4783 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4786 json
= json_object_new_object();
4788 /* vrf input is provided could be all or specific vrf*/
4792 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4793 if (!ospf
->oi_running
)
4795 ret
= show_ip_ospf_neighbor_all_common(
4796 vty
, ospf
, json
, uj
, use_vrf
);
4800 vty_json(vty
, json
);
4805 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4806 if (ospf
== NULL
|| !ospf
->oi_running
) {
4808 json_object_free(json
);
4812 /* Display default ospf (instance 0) info */
4813 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4814 if (ospf
== NULL
|| !ospf
->oi_running
) {
4816 json_object_free(json
);
4822 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
,
4825 vty_out(vty
, "%s\n",
4826 json_object_to_json_string_ext(
4827 json
, JSON_C_TO_STRING_PRETTY
));
4832 json_object_free(json
);
4837 DEFUN (show_ip_ospf_instance_neighbor_all
,
4838 show_ip_ospf_instance_neighbor_all_cmd
,
4839 "show ip ospf (1-65535) neighbor all [json]",
4842 "OSPF information\n"
4845 "include down status neighbor\n"
4850 unsigned short instance
= 0;
4851 bool uj
= use_json(argc
, argv
);
4852 json_object
*json
= NULL
;
4853 int ret
= CMD_SUCCESS
;
4855 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4856 if (instance
!= ospf_instance
)
4857 return CMD_NOT_MY_INSTANCE
;
4859 ospf
= ospf_lookup_instance(instance
);
4860 if (!ospf
|| !ospf
->oi_running
)
4863 json
= json_object_new_object();
4865 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
, 0);
4868 vty_json(vty
, json
);
4873 static int show_ip_ospf_neighbor_int_common(struct vty
*vty
, struct ospf
*ospf
,
4875 struct cmd_token
**argv
,
4876 bool use_json
, uint8_t use_vrf
)
4878 struct interface
*ifp
;
4879 struct route_node
*rn
;
4880 json_object
*json
= NULL
;
4883 json
= json_object_new_object();
4885 if (ospf
->instance
) {
4887 json_object_int_add(json
, "ospfInstance",
4890 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4893 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
4895 ifp
= if_lookup_by_name(argv
[arg_base
]->arg
, ospf
->vrf_id
);
4898 json_object_boolean_true_add(json
, "noSuchIface");
4900 vty_out(vty
, "No such interface.\n");
4904 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
4905 struct ospf_interface
*oi
= rn
->info
;
4910 show_ip_ospf_neighbor_sub(vty
, oi
, json
, use_json
);
4914 vty_json(vty
, json
);
4921 DEFUN (show_ip_ospf_neighbor_int
,
4922 show_ip_ospf_neighbor_int_cmd
,
4923 "show ip ospf [vrf <NAME>] neighbor IFNAME [json]",
4926 "OSPF information\n"
4935 bool uj
= use_json(argc
, argv
);
4936 int ret
= CMD_SUCCESS
;
4937 struct interface
*ifp
= NULL
;
4938 char *vrf_name
= NULL
;
4939 vrf_id_t vrf_id
= VRF_DEFAULT
;
4940 struct vrf
*vrf
= NULL
;
4942 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
4943 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
4944 if (vrf_name
&& strmatch(vrf_name
, VRF_DEFAULT_NAME
))
4947 vrf
= vrf_lookup_by_name(vrf_name
);
4949 vrf_id
= vrf
->vrf_id
;
4951 ospf
= ospf_lookup_by_vrf_id(vrf_id
);
4953 if (!ospf
|| !ospf
->oi_running
)
4957 show_ip_ospf_neighbour_header(vty
);
4959 argv_find(argv
, argc
, "IFNAME", &idx_ifname
);
4961 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf_id
);
4965 ret
= show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
,
4970 DEFUN (show_ip_ospf_instance_neighbor_int
,
4971 show_ip_ospf_instance_neighbor_int_cmd
,
4972 "show ip ospf (1-65535) neighbor IFNAME [json]",
4975 "OSPF information\n"
4984 unsigned short instance
= 0;
4985 bool uj
= use_json(argc
, argv
);
4988 show_ip_ospf_neighbour_header(vty
);
4990 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4991 if (instance
!= ospf_instance
)
4992 return CMD_NOT_MY_INSTANCE
;
4994 ospf
= ospf_lookup_instance(instance
);
4995 if (!ospf
|| !ospf
->oi_running
)
4999 show_ip_ospf_neighbour_header(vty
);
5001 return show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
, argv
, uj
,
5005 static void show_ip_ospf_nbr_nbma_detail_sub(struct vty
*vty
,
5006 struct ospf_interface
*oi
,
5007 struct ospf_nbr_nbma
*nbr_nbma
,
5008 bool use_json
, json_object
*json
)
5010 char timebuf
[OSPF_TIME_DUMP_SIZE
];
5011 json_object
*json_sub
= NULL
;
5014 json_sub
= json_object_new_object();
5015 else /* Show neighbor ID. */
5016 vty_out(vty
, " Neighbor %s,", "-");
5018 /* Show interface address. */
5020 json_object_string_addf(json_sub
, "ifaceAddress", "%pI4",
5023 vty_out(vty
, " interface address %pI4\n",
5028 json_object_string_add(json_sub
, "areaId",
5029 ospf_area_desc_string(oi
->area
));
5030 json_object_string_add(json_sub
, "iface", IF_NAME(oi
));
5032 vty_out(vty
, " In the area %s via interface %s\n",
5033 ospf_area_desc_string(oi
->area
), IF_NAME(oi
));
5035 /* Show neighbor priority and state. */
5037 json_object_int_add(json_sub
, "nbrPriority",
5038 nbr_nbma
->priority
);
5039 json_object_string_add(json_sub
, "nbrState", "down");
5041 vty_out(vty
, " Neighbor priority is %d, State is %s,",
5042 nbr_nbma
->priority
, "Down");
5044 /* Show state changes. */
5046 json_object_int_add(json_sub
, "stateChangeCounter",
5047 nbr_nbma
->state_change
);
5049 vty_out(vty
, " %d state changes\n", nbr_nbma
->state_change
);
5051 /* Show PollInterval */
5053 json_object_int_add(json_sub
, "pollInterval", nbr_nbma
->v_poll
);
5055 vty_out(vty
, " Poll interval %d\n", nbr_nbma
->v_poll
);
5057 /* Show poll-interval timer. */
5058 if (nbr_nbma
->t_poll
) {
5061 time_store
= monotime_until(&nbr_nbma
->t_poll
->u
.sands
,
5063 json_object_int_add(json_sub
,
5064 "pollIntervalTimerDueMsec",
5067 vty_out(vty
, " Poll timer due in %s\n",
5068 ospf_timer_dump(nbr_nbma
->t_poll
, timebuf
,
5072 /* Show poll-interval timer thread. */
5074 if (nbr_nbma
->t_poll
!= NULL
)
5075 json_object_string_add(json_sub
,
5076 "pollIntervalTimerThread", "on");
5078 vty_out(vty
, " Thread Poll Timer %s\n",
5079 nbr_nbma
->t_poll
!= NULL
? "on" : "off");
5082 json_object_object_add(json
, "noNbrId", json_sub
);
5085 static void show_ip_ospf_neighbor_detail_sub(struct vty
*vty
,
5086 struct ospf_interface
*oi
,
5087 struct ospf_neighbor
*nbr
,
5088 struct ospf_neighbor
*prev_nbr
,
5089 json_object
*json
, bool use_json
)
5091 char timebuf
[OSPF_TIME_DUMP_SIZE
];
5092 json_object
*json_neigh
= NULL
, *json_neigh_array
= NULL
;
5093 char neigh_str
[INET_ADDRSTRLEN
] = {0};
5094 char neigh_state
[16] = {0};
5098 !IPV4_ADDR_SAME(&prev_nbr
->src
, &nbr
->src
)) {
5099 json_neigh_array
= NULL
;
5102 if (nbr
->state
== NSM_Attempt
5103 && nbr
->router_id
.s_addr
== INADDR_ANY
)
5104 strlcpy(neigh_str
, "noNbrId", sizeof(neigh_str
));
5106 inet_ntop(AF_INET
, &nbr
->router_id
,
5107 neigh_str
, sizeof(neigh_str
));
5109 json_object_object_get_ex(json
, neigh_str
, &json_neigh_array
);
5111 if (!json_neigh_array
) {
5112 json_neigh_array
= json_object_new_array();
5113 json_object_object_add(json
, neigh_str
,
5117 json_neigh
= json_object_new_object();
5120 /* Show neighbor ID. */
5121 if (nbr
->state
== NSM_Attempt
5122 && nbr
->router_id
.s_addr
== INADDR_ANY
)
5123 vty_out(vty
, " Neighbor %s,", "-");
5125 vty_out(vty
, " Neighbor %pI4,",
5129 /* Show interface address. */
5131 json_object_string_addf(json_neigh
, "ifaceAddress", "%pI4",
5132 &nbr
->address
.u
.prefix4
);
5134 vty_out(vty
, " interface address %pI4\n",
5135 &nbr
->address
.u
.prefix4
);
5139 json_object_string_add(json_neigh
, "areaId",
5140 ospf_area_desc_string(oi
->area
));
5141 json_object_string_add(json_neigh
, "ifaceName", oi
->ifp
->name
);
5143 vty_out(vty
, " In the area %s via interface %s\n",
5144 ospf_area_desc_string(oi
->area
), oi
->ifp
->name
);
5146 /* Show neighbor priority and state. */
5147 ospf_nbr_ism_state_message(nbr
, neigh_state
, sizeof(neigh_state
));
5149 json_object_int_add(json_neigh
, "nbrPriority", nbr
->priority
);
5150 json_object_string_add(json_neigh
, "nbrState", neigh_state
);
5152 vty_out(vty
, " Neighbor priority is %d, State is %s,",
5153 nbr
->priority
, neigh_state
);
5155 /* Show state changes. */
5157 json_object_int_add(json_neigh
, "stateChangeCounter",
5160 vty_out(vty
, " %d state changes\n", nbr
->state_change
);
5162 if (nbr
->ts_last_progress
.tv_sec
|| nbr
->ts_last_progress
.tv_usec
) {
5167 monotime_since(&nbr
->ts_last_progress
, &res
) / 1000LL;
5169 json_object_int_add(json_neigh
, "lastPrgrsvChangeMsec",
5173 " Most recent state change statistics:\n");
5174 vty_out(vty
, " Progressive change %s ago\n",
5175 ospf_timeval_dump(&res
, timebuf
,
5180 if (nbr
->ts_last_regress
.tv_sec
|| nbr
->ts_last_regress
.tv_usec
) {
5185 monotime_since(&nbr
->ts_last_regress
, &res
) / 1000LL;
5187 json_object_int_add(json_neigh
,
5188 "lastRegressiveChangeMsec",
5190 if (nbr
->last_regress_str
)
5191 json_object_string_add(
5193 "lastRegressiveChangeReason",
5194 nbr
->last_regress_str
);
5197 " Regressive change %s ago, due to %s\n",
5198 ospf_timeval_dump(&res
, timebuf
,
5200 (nbr
->last_regress_str
? nbr
->last_regress_str
5205 /* Show Designated Rotuer ID. */
5207 json_object_string_addf(json_neigh
, "routerDesignatedId",
5208 "%pI4", &nbr
->d_router
);
5210 vty_out(vty
, " DR is %pI4,", &nbr
->d_router
);
5212 /* Show Backup Designated Rotuer ID. */
5214 json_object_string_addf(json_neigh
, "routerDesignatedBackupId",
5215 "%pI4", &nbr
->bd_router
);
5217 vty_out(vty
, " BDR is %pI4\n", &nbr
->bd_router
);
5221 json_object_int_add(json_neigh
, "optionsCounter", nbr
->options
);
5222 json_object_string_add(json_neigh
, "optionsList",
5223 ospf_options_dump(nbr
->options
));
5225 vty_out(vty
, " Options %d %s\n", nbr
->options
,
5226 ospf_options_dump(nbr
->options
));
5228 /* Show Router Dead interval timer. */
5230 if (nbr
->t_inactivity
) {
5232 time_store
= monotime_until(&nbr
->t_inactivity
->u
.sands
,
5235 json_object_int_add(json_neigh
,
5236 "routerDeadIntervalTimerDueMsec",
5239 json_object_int_add(
5241 "routerDeadIntervalTimerDueMsec", -1);
5243 vty_out(vty
, " Dead timer due in %s\n",
5244 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
5247 /* Show Database Summary list. */
5249 json_object_int_add(json_neigh
, "databaseSummaryListCounter",
5250 ospf_db_summary_count(nbr
));
5252 vty_out(vty
, " Database Summary List %d\n",
5253 ospf_db_summary_count(nbr
));
5255 /* Show Link State Request list. */
5257 json_object_int_add(json_neigh
, "linkStateRequestListCounter",
5258 ospf_ls_request_count(nbr
));
5260 vty_out(vty
, " Link State Request List %ld\n",
5261 ospf_ls_request_count(nbr
));
5263 /* Show Link State Retransmission list. */
5265 json_object_int_add(json_neigh
,
5266 "linkStateRetransmissionListCounter",
5267 ospf_ls_retransmit_count(nbr
));
5269 vty_out(vty
, " Link State Retransmission List %ld\n",
5270 ospf_ls_retransmit_count(nbr
));
5272 /* Show inactivity timer thread. */
5274 if (nbr
->t_inactivity
!= NULL
)
5275 json_object_string_add(json_neigh
,
5276 "threadInactivityTimer", "on");
5278 vty_out(vty
, " Thread Inactivity Timer %s\n",
5279 nbr
->t_inactivity
!= NULL
? "on" : "off");
5281 /* Show Database Description retransmission thread. */
5283 if (nbr
->t_db_desc
!= NULL
)
5284 json_object_string_add(
5286 "threadDatabaseDescriptionRetransmission",
5290 " Thread Database Description Retransmision %s\n",
5291 nbr
->t_db_desc
!= NULL
? "on" : "off");
5293 /* Show Link State Request Retransmission thread. */
5295 if (nbr
->t_ls_req
!= NULL
)
5296 json_object_string_add(
5298 "threadLinkStateRequestRetransmission", "on");
5301 " Thread Link State Request Retransmission %s\n",
5302 nbr
->t_ls_req
!= NULL
? "on" : "off");
5304 /* Show Link State Update Retransmission thread. */
5306 if (nbr
->t_ls_upd
!= NULL
)
5307 json_object_string_add(
5309 "threadLinkStateUpdateRetransmission",
5313 " Thread Link State Update Retransmission %s\n\n",
5314 nbr
->t_ls_upd
!= NULL
? "on" : "off");
5317 vty_out(vty
, " Graceful restart Helper info:\n");
5319 if (OSPF_GR_IS_ACTIVE_HELPER(nbr
)) {
5321 " Graceful Restart HELPER Status : Inprogress.\n");
5324 " Graceful Restart grace period time: %d (seconds).\n",
5325 nbr
->gr_helper_info
.recvd_grace_period
);
5326 vty_out(vty
, " Graceful Restart reason: %s.\n",
5327 ospf_restart_reason2str(
5328 nbr
->gr_helper_info
.gr_restart_reason
));
5331 " Graceful Restart HELPER Status : None\n");
5334 if (nbr
->gr_helper_info
.rejected_reason
5335 != OSPF_HELPER_REJECTED_NONE
)
5336 vty_out(vty
, " Helper rejected reason: %s.\n",
5337 ospf_rejected_reason2str(
5338 nbr
->gr_helper_info
.rejected_reason
));
5340 if (nbr
->gr_helper_info
.helper_exit_reason
5341 != OSPF_GR_HELPER_EXIT_NONE
)
5342 vty_out(vty
, " Last helper exit reason: %s.\n\n",
5343 ospf_exit_reason2str(
5344 nbr
->gr_helper_info
.helper_exit_reason
));
5348 json_object_string_add(json_neigh
, "grHelperStatus",
5349 OSPF_GR_IS_ACTIVE_HELPER(nbr
) ?
5352 if (OSPF_GR_IS_ACTIVE_HELPER(nbr
)) {
5353 json_object_int_add(
5354 json_neigh
, "graceInterval",
5355 nbr
->gr_helper_info
.recvd_grace_period
);
5356 json_object_string_add(
5357 json_neigh
, "grRestartReason",
5358 ospf_restart_reason2str(
5359 nbr
->gr_helper_info
.gr_restart_reason
));
5362 if (nbr
->gr_helper_info
.rejected_reason
5363 != OSPF_HELPER_REJECTED_NONE
)
5364 json_object_string_add(
5365 json_neigh
, "helperRejectReason",
5366 ospf_rejected_reason2str(
5367 nbr
->gr_helper_info
.rejected_reason
));
5369 if (nbr
->gr_helper_info
.helper_exit_reason
5370 != OSPF_GR_HELPER_EXIT_NONE
)
5371 json_object_string_add(
5372 json_neigh
, "helperExitReason",
5373 ospf_exit_reason2str(
5375 .helper_exit_reason
));
5378 bfd_sess_show(vty
, json_neigh
, nbr
->bfd_session
);
5381 json_object_array_add(json_neigh_array
, json_neigh
);
5385 static int show_ip_ospf_neighbor_id_common(struct vty
*vty
, struct ospf
*ospf
,
5386 struct in_addr
*router_id
,
5387 bool use_json
, uint8_t use_vrf
,
5390 struct listnode
*node
;
5391 struct ospf_neighbor
*nbr
;
5392 struct ospf_interface
*oi
;
5393 json_object
*json
= NULL
;
5396 json
= json_object_new_object();
5398 if (ospf
->instance
) {
5400 json_object_int_add(json
, "ospfInstance",
5403 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5406 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
5408 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5409 nbr
= ospf_nbr_lookup_by_routerid(oi
->nbrs
, router_id
);
5415 show_ip_ospf_neighbor_detail_sub(vty
, oi
, nbr
, NULL
,
5418 show_ip_ospf_neighbour_brief(vty
, nbr
, NULL
, json
,
5423 vty_json(vty
, json
);
5430 DEFPY(show_ip_ospf_neighbor_id
, show_ip_ospf_neighbor_id_cmd
,
5431 "show ip ospf neighbor A.B.C.D$router_id [detail$detail] [json$json]",
5433 "OSPF information\n"
5436 "Detailed output\n" JSON_STR
)
5439 struct listnode
*node
;
5440 int ret
= CMD_SUCCESS
;
5442 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5443 if (!ospf
->oi_running
)
5445 ret
= show_ip_ospf_neighbor_id_common(vty
, ospf
, &router_id
,
5446 !!json
, 0, !!detail
);
5452 DEFPY(show_ip_ospf_instance_neighbor_id
, show_ip_ospf_instance_neighbor_id_cmd
,
5453 "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [detail$detail] [json$json]",
5455 "OSPF information\n"
5459 "Detailed output\n" JSON_STR
)
5463 if (instance
!= ospf_instance
)
5464 return CMD_NOT_MY_INSTANCE
;
5466 ospf
= ospf_lookup_instance(instance
);
5467 if (!ospf
|| !ospf
->oi_running
)
5470 return show_ip_ospf_neighbor_id_common(vty
, ospf
, &router_id
, !!json
, 0,
5474 static int show_ip_ospf_neighbor_detail_common(struct vty
*vty
,
5476 json_object
*json
, bool use_json
,
5479 struct ospf_interface
*oi
;
5480 struct listnode
*node
;
5481 json_object
*json_vrf
= NULL
;
5482 json_object
*json_nbr_sub
= NULL
;
5486 json_vrf
= json_object_new_object();
5490 json_nbr_sub
= json_object_new_object();
5493 if (ospf
->instance
) {
5495 json_object_int_add(json
, "ospfInstance",
5498 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5501 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5503 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5504 struct route_node
*rn
;
5505 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
5507 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5513 if (nbr
!= oi
->nbr_self
) {
5514 if (nbr
->state
!= NSM_Down
) {
5515 show_ip_ospf_neighbor_detail_sub(
5516 vty
, oi
, nbr
, prev_nbr
,
5517 json_nbr_sub
, use_json
);
5525 json_object_object_add(json_vrf
, "neighbors",
5528 json_object_object_add(json
, ospf_get_name(ospf
),
5536 DEFUN (show_ip_ospf_neighbor_detail
,
5537 show_ip_ospf_neighbor_detail_cmd
,
5538 "show ip ospf [vrf <NAME|all>] neighbor detail [json]",
5541 "OSPF information\n"
5545 "detail of all neighbors\n"
5549 bool uj
= use_json(argc
, argv
);
5550 struct listnode
*node
= NULL
;
5551 char *vrf_name
= NULL
;
5552 bool all_vrf
= false;
5553 int ret
= CMD_SUCCESS
;
5556 uint8_t use_vrf
= 0;
5557 json_object
*json
= NULL
;
5559 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5562 json
= json_object_new_object();
5564 /* vrf input is provided could be all or specific vrf*/
5568 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5569 if (!ospf
->oi_running
)
5571 ret
= show_ip_ospf_neighbor_detail_common(
5572 vty
, ospf
, json
, uj
, use_vrf
);
5575 vty_json(vty
, json
);
5579 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5580 if (ospf
== NULL
|| !ospf
->oi_running
) {
5582 json_object_free(json
);
5586 /* Display default ospf (instance 0) info */
5587 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5588 if (ospf
== NULL
|| !ospf
->oi_running
) {
5590 json_object_free(json
);
5596 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
,
5599 vty_out(vty
, "%s\n",
5600 json_object_to_json_string_ext(
5601 json
, JSON_C_TO_STRING_PRETTY
));
5606 json_object_free(json
);
5611 DEFUN (show_ip_ospf_instance_neighbor_detail
,
5612 show_ip_ospf_instance_neighbor_detail_cmd
,
5613 "show ip ospf (1-65535) neighbor detail [json]",
5616 "OSPF information\n"
5619 "detail of all neighbors\n"
5624 unsigned short instance
= 0;
5625 bool uj
= use_json(argc
, argv
);
5626 json_object
*json
= NULL
;
5627 int ret
= CMD_SUCCESS
;
5629 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5630 if (instance
!= ospf_instance
)
5631 return CMD_NOT_MY_INSTANCE
;
5633 ospf
= ospf_lookup_instance(instance
);
5634 if (!ospf
|| !ospf
->oi_running
)
5638 json
= json_object_new_object();
5640 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
, 0);
5643 vty_json(vty
, json
);
5648 static int show_ip_ospf_neighbor_detail_all_common(struct vty
*vty
,
5654 struct listnode
*node
;
5655 struct ospf_interface
*oi
;
5656 json_object
*json_vrf
= NULL
;
5660 json_vrf
= json_object_new_object();
5665 if (ospf
->instance
) {
5667 json_object_int_add(json
, "ospfInstance",
5670 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5673 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5675 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5676 struct route_node
*rn
;
5677 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
5678 struct ospf_nbr_nbma
*nbr_nbma
;
5680 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5686 if (nbr
!= oi
->nbr_self
)
5687 if (nbr
->state
!= NSM_Down
)
5688 show_ip_ospf_neighbor_detail_sub(
5689 vty
, oi
, rn
->info
, prev_nbr
,
5690 json_vrf
, use_json
);
5694 if (oi
->type
!= OSPF_IFTYPE_NBMA
)
5697 struct listnode
*nd
;
5699 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nd
, nbr_nbma
)) {
5700 if (nbr_nbma
->nbr
== NULL
||
5701 nbr_nbma
->nbr
->state
== NSM_Down
)
5702 show_ip_ospf_nbr_nbma_detail_sub(
5703 vty
, oi
, nbr_nbma
, use_json
, json_vrf
);
5709 json_object_object_add(json
, ospf_get_name(ospf
),
5718 DEFUN (show_ip_ospf_neighbor_detail_all
,
5719 show_ip_ospf_neighbor_detail_all_cmd
,
5720 "show ip ospf [vrf <NAME|all>] neighbor detail all [json]",
5723 "OSPF information\n"
5727 "detail of all neighbors\n"
5728 "include down status neighbor\n"
5732 bool uj
= use_json(argc
, argv
);
5733 struct listnode
*node
= NULL
;
5734 char *vrf_name
= NULL
;
5735 bool all_vrf
= false;
5736 int ret
= CMD_SUCCESS
;
5739 uint8_t use_vrf
= 0;
5740 json_object
*json
= NULL
;
5742 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5745 json
= json_object_new_object();
5747 /* vrf input is provided could be all or specific vrf*/
5751 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5752 if (!ospf
->oi_running
)
5754 ret
= show_ip_ospf_neighbor_detail_all_common(
5755 vty
, ospf
, json
, uj
, use_vrf
);
5759 vty_json(vty
, json
);
5763 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5764 if (ospf
== NULL
|| !ospf
->oi_running
) {
5766 json_object_free(json
);
5770 /* Display default ospf (instance 0) info */
5771 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5772 if (ospf
== NULL
|| !ospf
->oi_running
) {
5774 json_object_free(json
);
5780 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
,
5783 vty_out(vty
, "%s\n",
5784 json_object_to_json_string_ext(
5785 json
, JSON_C_TO_STRING_PRETTY
));
5790 json_object_free(json
);
5795 DEFUN (show_ip_ospf_instance_neighbor_detail_all
,
5796 show_ip_ospf_instance_neighbor_detail_all_cmd
,
5797 "show ip ospf (1-65535) neighbor detail all [json]",
5800 "OSPF information\n"
5803 "detail of all neighbors\n"
5804 "include down status neighbor\n"
5809 unsigned short instance
= 0;
5810 bool uj
= use_json(argc
, argv
);
5811 json_object
*json
= NULL
;
5812 int ret
= CMD_SUCCESS
;
5814 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5815 if (instance
!= ospf_instance
)
5816 return CMD_NOT_MY_INSTANCE
;
5818 ospf
= ospf_lookup_instance(instance
);
5819 if (!ospf
|| !ospf
->oi_running
)
5823 json
= json_object_new_object();
5825 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
, uj
, 0);
5828 vty_json(vty
, json
);
5833 static int show_ip_ospf_neighbor_int_detail_common(struct vty
*vty
,
5836 struct cmd_token
**argv
,
5839 struct ospf_interface
*oi
;
5840 struct interface
*ifp
;
5841 struct route_node
*rn
, *nrn
;
5842 struct ospf_neighbor
*nbr
;
5843 json_object
*json
= NULL
;
5846 json
= json_object_new_object();
5848 if (ospf
->instance
) {
5850 json_object_int_add(json
, "ospfInstance",
5853 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5856 ifp
= if_lookup_by_name(argv
[arg_base
]->arg
, ospf
->vrf_id
);
5859 vty_out(vty
, "No such interface.\n");
5861 vty_out(vty
, "{}\n");
5862 json_object_free(json
);
5867 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
5873 for (nrn
= route_top(oi
->nbrs
); nrn
; nrn
= route_next(nrn
)) {
5879 if (nbr
== oi
->nbr_self
)
5882 if (nbr
->state
== NSM_Down
)
5885 show_ip_ospf_neighbor_detail_sub(vty
, oi
, nbr
, NULL
,
5891 vty_json(vty
, json
);
5898 DEFUN (show_ip_ospf_neighbor_int_detail
,
5899 show_ip_ospf_neighbor_int_detail_cmd
,
5900 "show ip ospf neighbor IFNAME detail [json]",
5903 "OSPF information\n"
5906 "detail of all neighbors\n"
5910 bool uj
= use_json(argc
, argv
);
5911 struct listnode
*node
= NULL
;
5912 int ret
= CMD_SUCCESS
;
5913 bool ospf_output
= false;
5915 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5916 if (!ospf
->oi_running
)
5919 ret
= show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, 4,
5924 vty_out(vty
, "%% OSPF instance not found\n");
5929 DEFUN (show_ip_ospf_instance_neighbor_int_detail
,
5930 show_ip_ospf_instance_neighbor_int_detail_cmd
,
5931 "show ip ospf (1-65535) neighbor IFNAME detail [json]",
5934 "OSPF information\n"
5938 "detail of all neighbors\n"
5944 unsigned short instance
= 0;
5945 bool uj
= use_json(argc
, argv
);
5947 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5948 if (instance
!= ospf_instance
)
5949 return CMD_NOT_MY_INSTANCE
;
5951 ospf
= ospf_lookup_instance(instance
);
5952 if (!ospf
|| !ospf
->oi_running
)
5955 return show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, idx_ifname
,
5959 /* Show functions */
5960 static int show_lsa_summary(struct vty
*vty
, struct ospf_lsa
*lsa
, int self
,
5961 json_object
*json_lsa
)
5963 struct router_lsa
*rl
;
5964 struct summary_lsa
*sl
;
5965 struct as_external_lsa
*asel
;
5966 struct prefix_ipv4 p
;
5969 /* If self option is set, check LSA self flag. */
5970 if (self
== 0 || IS_LSA_SELF(lsa
)) {
5973 /* LSA common part show. */
5974 vty_out(vty
, "%-15pI4",
5976 vty_out(vty
, "%-15pI4 %4d 0x%08lx 0x%04x",
5977 &lsa
->data
->adv_router
, LS_AGE(lsa
),
5978 (unsigned long)ntohl(
5979 lsa
->data
->ls_seqnum
),
5980 ntohs(lsa
->data
->checksum
));
5985 snprintf(seqnum
, sizeof(seqnum
), "%x",
5986 ntohl(lsa
->data
->ls_seqnum
));
5987 snprintf(checksum
, sizeof(checksum
), "%x",
5988 ntohs(lsa
->data
->checksum
));
5989 json_object_string_addf(json_lsa
, "lsId",
5990 "%pI4", &lsa
->data
->id
);
5991 json_object_string_addf(
5992 json_lsa
, "advertisedRouter", "%pI4",
5993 &lsa
->data
->adv_router
);
5994 json_object_int_add(json_lsa
, "lsaAge",
5996 json_object_string_add(
5997 json_lsa
, "sequenceNumber", seqnum
);
5998 json_object_string_add(json_lsa
, "checksum",
6002 /* LSA specific part show. */
6003 switch (lsa
->data
->type
) {
6004 case OSPF_ROUTER_LSA
:
6005 rl
= (struct router_lsa
*)lsa
->data
;
6008 vty_out(vty
, " %-d", ntohs(rl
->links
));
6010 json_object_int_add(json_lsa
,
6014 case OSPF_SUMMARY_LSA
:
6015 sl
= (struct summary_lsa
*)lsa
->data
;
6018 p
.prefix
= sl
->header
.id
;
6019 p
.prefixlen
= ip_masklen(sl
->mask
);
6020 apply_mask_ipv4(&p
);
6023 vty_out(vty
, " %pFX", &p
);
6025 json_object_string_addf(
6026 json_lsa
, "summaryAddress",
6030 case OSPF_AS_EXTERNAL_LSA
:
6031 case OSPF_AS_NSSA_LSA
:
6032 asel
= (struct as_external_lsa
*)lsa
->data
;
6035 p
.prefix
= asel
->header
.id
;
6036 p
.prefixlen
= ip_masklen(asel
->mask
);
6037 apply_mask_ipv4(&p
);
6040 vty_out(vty
, " %s %pFX [0x%lx]",
6046 (unsigned long)ntohl(
6047 asel
->e
[0].route_tag
));
6049 json_object_string_add(
6050 json_lsa
, "metricType",
6055 json_object_string_addf(
6056 json_lsa
, "route", "%pFX", &p
);
6057 json_object_int_add(
6059 (unsigned long)ntohl(
6060 asel
->e
[0].route_tag
));
6063 case OSPF_NETWORK_LSA
:
6064 case OSPF_ASBR_SUMMARY_LSA
:
6065 case OSPF_OPAQUE_LINK_LSA
:
6066 case OSPF_OPAQUE_AREA_LSA
:
6067 case OSPF_OPAQUE_AS_LSA
:
6082 static const char *const show_database_desc
[] = {
6084 "Router Link States",
6086 "Summary Link States",
6087 "ASBR-Summary Link States",
6088 "AS External Link States",
6089 "Group Membership LSA",
6090 "NSSA-external Link States",
6092 "Link-Local Opaque-LSA",
6093 "Area-Local Opaque-LSA",
6094 "AS-external Opaque-LSA",
6097 static const char * const show_database_desc_json
[] = {
6100 "networkLinkStates",
6101 "summaryLinkStates",
6102 "asbrSummaryLinkStates",
6103 "asExternalLinkStates",
6104 "groupMembershipLsa",
6105 "nssaExternalLinkStates",
6107 "linkLocalOpaqueLsa",
6108 "areaLocalOpaqueLsa",
6109 "asExternalOpaqueLsa",
6112 static const char *const show_database_desc_count_json
[] = {
6114 "routerLinkStatesCount",
6115 "networkLinkStatesCount",
6116 "summaryLinkStatesCount",
6117 "asbrSummaryLinkStatesCount",
6118 "asExternalLinkStatesCount",
6119 "groupMembershipLsaCount",
6120 "nssaExternalLinkStatesCount",
6122 "linkLocalOpaqueLsaCount",
6123 "areaLocalOpaqueLsaCount",
6124 "asExternalOpaqueLsaCount",
6127 static const char *const show_database_header
[] = {
6129 "Link ID ADV Router Age Seq# CkSum Link count",
6130 "Link ID ADV Router Age Seq# CkSum",
6131 "Link ID ADV Router Age Seq# CkSum Route",
6132 "Link ID ADV Router Age Seq# CkSum",
6133 "Link ID ADV Router Age Seq# CkSum Route",
6134 " --- header for Group Member ----",
6135 "Link ID ADV Router Age Seq# CkSum Route",
6137 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6138 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6139 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6142 static void show_ip_ospf_database_header(struct vty
*vty
, struct ospf_lsa
*lsa
,
6145 struct router_lsa
*rlsa
= (struct router_lsa
*)lsa
->data
;
6148 vty_out(vty
, " LS age: %d\n", LS_AGE(lsa
));
6149 vty_out(vty
, " Options: 0x%-2x : %s\n", lsa
->data
->options
,
6150 ospf_options_dump(lsa
->data
->options
));
6151 vty_out(vty
, " LS Flags: 0x%-2x %s\n", lsa
->flags
,
6152 ((lsa
->flags
& OSPF_LSA_LOCAL_XLT
)
6153 ? "(Translated from Type-7)"
6156 if (lsa
->data
->type
== OSPF_ROUTER_LSA
) {
6157 vty_out(vty
, " Flags: 0x%x", rlsa
->flags
);
6160 vty_out(vty
, " :%s%s%s%s",
6161 IS_ROUTER_LSA_BORDER(rlsa
) ? " ABR"
6163 IS_ROUTER_LSA_EXTERNAL(rlsa
) ? " ASBR"
6165 IS_ROUTER_LSA_VIRTUAL(rlsa
)
6168 IS_ROUTER_LSA_SHORTCUT(rlsa
)
6174 vty_out(vty
, " LS Type: %s\n",
6175 lookup_msg(ospf_lsa_type_msg
, lsa
->data
->type
, NULL
));
6176 vty_out(vty
, " Link State ID: %pI4 %s\n",
6178 lookup_msg(ospf_link_state_id_type_msg
, lsa
->data
->type
,
6180 vty_out(vty
, " Advertising Router: %pI4\n",
6181 &lsa
->data
->adv_router
);
6182 vty_out(vty
, " LS Seq Number: %08lx\n",
6183 (unsigned long)ntohl(lsa
->data
->ls_seqnum
));
6184 vty_out(vty
, " Checksum: 0x%04x\n",
6185 ntohs(lsa
->data
->checksum
));
6186 vty_out(vty
, " Length: %d\n\n", ntohs(lsa
->data
->length
));
6191 snprintf(seqnum
, 10, "%x", ntohl(lsa
->data
->ls_seqnum
));
6192 snprintf(checksum
, 10, "%x", ntohs(lsa
->data
->checksum
));
6194 json_object_int_add(json
, "lsaAge", LS_AGE(lsa
));
6195 json_object_string_add(json
, "options",
6196 ospf_options_dump(lsa
->data
->options
));
6197 json_object_int_add(json
, "lsaFlags", lsa
->flags
);
6199 if (lsa
->flags
& OSPF_LSA_LOCAL_XLT
)
6200 json_object_boolean_true_add(json
,
6201 "translatedFromType7");
6203 if (lsa
->data
->type
== OSPF_ROUTER_LSA
) {
6204 json_object_int_add(json
, "flags", rlsa
->flags
);
6207 if (IS_ROUTER_LSA_BORDER(rlsa
))
6208 json_object_boolean_true_add(json
,
6210 if (IS_ROUTER_LSA_EXTERNAL(rlsa
))
6211 json_object_boolean_true_add(json
,
6213 if (IS_ROUTER_LSA_VIRTUAL(rlsa
))
6214 json_object_boolean_true_add(
6215 json
, "vlEndpoint");
6216 if (IS_ROUTER_LSA_SHORTCUT(rlsa
))
6217 json_object_boolean_true_add(
6222 json_object_string_add(
6224 lookup_msg(ospf_lsa_type_msg
, lsa
->data
->type
, NULL
));
6225 json_object_string_addf(json
, "linkStateId", "%pI4",
6227 json_object_string_addf(json
, "advertisingRouter", "%pI4",
6228 &lsa
->data
->adv_router
);
6229 json_object_string_add(json
, "lsaSeqNumber", seqnum
);
6230 json_object_string_add(json
, "checksum", checksum
);
6231 json_object_int_add(json
, "length", ntohs(lsa
->data
->length
));
6235 static const char *const link_type_desc
[] = {
6237 "another Router (point-to-point)",
6238 "a Transit Network",
6243 static const char *const link_id_desc
[] = {
6244 "(null)", "Neighboring Router ID", "Designated Router address",
6245 "Net", "Neighboring Router ID",
6248 static const char *const link_data_desc
[] = {
6249 "(null)", "Router Interface address", "Router Interface address",
6250 "Network Mask", "Router Interface address",
6253 static const char *const link_id_desc_json
[] = {
6254 "null", "neighborRouterId", "designatedRouterAddress",
6255 "networkAddress", "neighborRouterId",
6258 static const char *const link_data_desc_json
[] = {
6259 "null", "routerInterfaceAddress", "routerInterfaceAddress",
6260 "networkMask", "routerInterfaceAddress",
6263 /* Show router-LSA each Link information. */
6264 static void show_ip_ospf_database_router_links(struct vty
*vty
,
6265 struct router_lsa
*rl
,
6270 json_object
*json_links
= NULL
;
6271 json_object
*json_link
= NULL
;
6273 char buf
[PREFIX_STRLEN
];
6276 json_links
= json_object_new_object();
6278 len
= ntohs(rl
->header
.length
) - 4;
6279 for (i
= 0; i
< ntohs(rl
->links
) && len
> 0; len
-= 12, i
++) {
6280 type
= rl
->link
[i
].type
;
6285 snprintf(link
, sizeof(link
), "link%u", i
);
6286 json_link
= json_object_new_object();
6287 json_object_string_add(json_link
, "linkType",
6288 link_type_desc
[type
]);
6289 json_object_string_add(json_link
,
6290 link_id_desc_json
[type
],
6292 &rl
->link
[i
].link_id
,
6294 json_object_string_add(
6295 json_link
, link_data_desc_json
[type
],
6296 inet_ntop(AF_INET
, &rl
->link
[i
].link_data
,
6298 json_object_int_add(json_link
, "numOfTosMetrics",
6300 json_object_int_add(json_link
, "tos0Metric",
6301 ntohs(rl
->link
[i
].metric
));
6302 json_object_object_add(json_links
, link
, json_link
);
6304 vty_out(vty
, " Link connected to: %s\n",
6305 link_type_desc
[type
]);
6306 vty_out(vty
, " (Link ID) %s: %pI4\n",
6308 &rl
->link
[i
].link_id
);
6309 vty_out(vty
, " (Link Data) %s: %pI4\n",
6310 link_data_desc
[type
],
6311 &rl
->link
[i
].link_data
);
6312 vty_out(vty
, " Number of TOS metrics: 0\n");
6313 vty_out(vty
, " TOS 0 Metric: %d\n",
6314 ntohs(rl
->link
[i
].metric
));
6319 json_object_object_add(json
, "routerLinks", json_links
);
6322 /* Show router-LSA detail information. */
6323 static int show_router_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6327 struct router_lsa
*rl
= (struct router_lsa
*)lsa
->data
;
6329 show_ip_ospf_database_header(vty
, lsa
, json
);
6332 vty_out(vty
, " Number of Links: %d\n\n",
6335 json_object_int_add(json
, "numOfLinks",
6338 show_ip_ospf_database_router_links(vty
, rl
, json
);
6347 /* Show network-LSA detail information. */
6348 static int show_network_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6352 char buf
[PREFIX_STRLEN
];
6353 json_object
*json_attached_rt
= NULL
;
6354 json_object
*json_router
= NULL
;
6357 json_attached_rt
= json_object_new_object();
6360 struct network_lsa
*nl
= (struct network_lsa
*)lsa
->data
;
6361 struct in_addr
*addr
;
6363 show_ip_ospf_database_header(vty
, lsa
, json
);
6366 vty_out(vty
, " Network Mask: /%d\n",
6367 ip_masklen(nl
->mask
));
6369 json_object_int_add(json
, "networkMask",
6370 ip_masklen(nl
->mask
));
6372 length
= lsa
->size
- OSPF_LSA_HEADER_SIZE
- 4;
6373 addr
= &nl
->routers
[0];
6374 for (i
= 0; length
> 0 && addr
;
6375 length
-= 4, addr
= &nl
->routers
[++i
])
6377 vty_out(vty
, " Attached Router: %pI4\n",
6381 json_router
= json_object_new_object();
6382 json_object_string_add(
6383 json_router
, "attachedRouterId",
6384 inet_ntop(AF_INET
, addr
, buf
,
6386 json_object_object_add(json_attached_rt
,
6387 inet_ntop(AF_INET
, addr
,
6395 json_object_object_add(json
, "attchedRouters",
6401 /* Show summary-LSA detail information. */
6402 static int show_summary_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6406 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
6408 show_ip_ospf_database_header(vty
, lsa
, json
);
6411 vty_out(vty
, " Network Mask: /%d\n",
6412 ip_masklen(sl
->mask
));
6413 vty_out(vty
, " TOS: 0 Metric: %d\n",
6414 GET_METRIC(sl
->metric
));
6417 json_object_int_add(json
, "networkMask",
6418 ip_masklen(sl
->mask
));
6419 json_object_int_add(json
, "tos0Metric",
6420 GET_METRIC(sl
->metric
));
6427 /* Show summary-ASBR-LSA detail information. */
6428 static int show_summary_asbr_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6432 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
6434 show_ip_ospf_database_header(vty
, lsa
, json
);
6437 vty_out(vty
, " Network Mask: /%d\n",
6438 ip_masklen(sl
->mask
));
6439 vty_out(vty
, " TOS: 0 Metric: %d\n",
6440 GET_METRIC(sl
->metric
));
6443 json_object_int_add(json
, "networkMask",
6444 ip_masklen(sl
->mask
));
6445 json_object_int_add(json
, "tos0Metric",
6446 GET_METRIC(sl
->metric
));
6453 /* Show AS-external-LSA detail information. */
6454 static int show_as_external_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6460 struct as_external_lsa
*al
=
6461 (struct as_external_lsa
*)lsa
->data
;
6463 show_ip_ospf_database_header(vty
, lsa
, json
);
6466 vty_out(vty
, " Network Mask: /%d\n",
6467 ip_masklen(al
->mask
));
6468 vty_out(vty
, " Metric Type: %s\n",
6469 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6470 ? "2 (Larger than any link state path)"
6472 vty_out(vty
, " TOS: 0\n");
6473 vty_out(vty
, " Metric: %d\n",
6474 GET_METRIC(al
->e
[0].metric
));
6475 vty_out(vty
, " Forward Address: %pI4\n",
6476 &al
->e
[0].fwd_addr
);
6478 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
6479 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6481 json_object_int_add(json
, "networkMask",
6482 ip_masklen(al
->mask
));
6483 json_object_string_add(
6485 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6486 ? "E2 (Larger than any link state path)"
6488 json_object_int_add(json
, "tos", tos
);
6489 json_object_int_add(json
, "metric",
6490 GET_METRIC(al
->e
[0].metric
));
6491 json_object_string_addf(json
, "forwardAddress", "%pI4",
6492 &(al
->e
[0].fwd_addr
));
6493 json_object_int_add(
6494 json
, "externalRouteTag",
6495 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6502 /* Show AS-NSSA-LSA detail information. */
6503 static int show_as_nssa_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6509 struct as_external_lsa
*al
=
6510 (struct as_external_lsa
*)lsa
->data
;
6512 show_ip_ospf_database_header(vty
, lsa
, json
);
6515 vty_out(vty
, " Network Mask: /%d\n",
6516 ip_masklen(al
->mask
));
6517 vty_out(vty
, " Metric Type: %s\n",
6518 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6519 ? "2 (Larger than any link state path)"
6521 vty_out(vty
, " TOS: 0\n");
6522 vty_out(vty
, " Metric: %d\n",
6523 GET_METRIC(al
->e
[0].metric
));
6524 vty_out(vty
, " NSSA: Forward Address: %pI4\n",
6525 &al
->e
[0].fwd_addr
);
6527 " External Route Tag: %" ROUTE_TAG_PRI
6529 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6531 json_object_int_add(json
, "networkMask",
6532 ip_masklen(al
->mask
));
6533 json_object_string_add(
6535 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6536 ? "E2 (Larger than any link state path)"
6538 json_object_int_add(json
, "tos", tos
);
6539 json_object_int_add(json
, "metric",
6540 GET_METRIC(al
->e
[0].metric
));
6541 json_object_string_addf(json
, "nssaForwardAddress",
6542 "%pI4", &al
->e
[0].fwd_addr
);
6543 json_object_int_add(
6544 json
, "externalRouteTag",
6545 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6552 static int show_func_dummy(struct vty
*vty
, struct ospf_lsa
*lsa
,
6558 static int show_opaque_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6562 show_ip_ospf_database_header(vty
, lsa
, json
);
6563 show_opaque_info_detail(vty
, lsa
, json
);
6570 int (*show_function
[])(struct vty
*, struct ospf_lsa
*, json_object
*) = {
6572 show_router_lsa_detail
,
6573 show_network_lsa_detail
,
6574 show_summary_lsa_detail
,
6575 show_summary_asbr_lsa_detail
,
6576 show_as_external_lsa_detail
,
6578 show_as_nssa_lsa_detail
, /* almost same as external */
6580 show_opaque_lsa_detail
,
6581 show_opaque_lsa_detail
,
6582 show_opaque_lsa_detail
,
6585 static void show_lsa_prefix_set(struct vty
*vty
, struct prefix_ls
*lp
,
6586 struct in_addr
*id
, struct in_addr
*adv_router
)
6588 memset(lp
, 0, sizeof(struct prefix_ls
));
6589 lp
->family
= AF_UNSPEC
;
6592 else if (adv_router
== NULL
) {
6593 lp
->prefixlen
= IPV4_MAX_BITLEN
;
6598 lp
->adv_router
= *adv_router
;
6602 static void show_lsa_detail_proc(struct vty
*vty
, struct route_table
*rt
,
6603 struct in_addr
*id
, struct in_addr
*adv_router
,
6606 struct prefix_ls lp
;
6607 struct route_node
*rn
, *start
;
6608 struct ospf_lsa
*lsa
;
6609 json_object
*json_lsa
= NULL
;
6611 show_lsa_prefix_set(vty
, &lp
, id
, adv_router
);
6612 start
= route_node_get(rt
, (struct prefix
*)&lp
);
6614 route_lock_node(start
);
6615 for (rn
= start
; rn
; rn
= route_next_until(rn
, start
))
6616 if ((lsa
= rn
->info
)) {
6617 if (show_function
[lsa
->data
->type
] != NULL
) {
6620 json_object_new_object();
6621 json_object_array_add(json
,
6625 show_function
[lsa
->data
->type
](
6626 vty
, lsa
, json_lsa
);
6629 route_unlock_node(start
);
6633 /* Show detail LSA information
6634 -- if id is NULL then show all LSAs. */
6635 static void show_lsa_detail(struct vty
*vty
, struct ospf
*ospf
, int type
,
6636 struct in_addr
*id
, struct in_addr
*adv_router
,
6639 struct listnode
*node
;
6640 struct ospf_area
*area
;
6641 char buf
[PREFIX_STRLEN
];
6642 json_object
*json_lsa_type
= NULL
;
6643 json_object
*json_areas
= NULL
;
6644 json_object
*json_lsa_array
= NULL
;
6647 case OSPF_AS_EXTERNAL_LSA
:
6648 case OSPF_OPAQUE_AS_LSA
:
6650 vty_out(vty
, " %s \n\n",
6651 show_database_desc
[type
]);
6653 json_lsa_array
= json_object_new_array();
6655 show_lsa_detail_proc(vty
, AS_LSDB(ospf
, type
), id
, adv_router
,
6658 json_object_object_add(json
,
6659 show_database_desc_json
[type
],
6665 json_areas
= json_object_new_object();
6667 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6670 "\n %s (Area %s)\n\n",
6671 show_database_desc
[type
],
6672 ospf_area_desc_string(area
));
6674 json_lsa_array
= json_object_new_array();
6675 json_object_object_add(json_areas
,
6683 show_lsa_detail_proc(vty
, AREA_LSDB(area
, type
), id
,
6684 adv_router
, json_lsa_array
);
6688 json_lsa_type
= json_object_new_object();
6689 json_object_object_add(json_lsa_type
, "areas",
6691 json_object_object_add(json
,
6692 show_database_desc_json
[type
],
6699 static void show_lsa_detail_adv_router_proc(struct vty
*vty
,
6700 struct route_table
*rt
,
6701 struct in_addr
*adv_router
,
6704 char buf
[PREFIX_STRLEN
];
6705 struct route_node
*rn
;
6706 struct ospf_lsa
*lsa
;
6708 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
))
6709 if ((lsa
= rn
->info
)) {
6710 json_object
*json_lsa
= NULL
;
6712 if (IPV4_ADDR_SAME(adv_router
,
6713 &lsa
->data
->adv_router
)) {
6714 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
6717 json_lsa
= json_object_new_object();
6719 if (show_function
[lsa
->data
->type
] != NULL
)
6720 show_function
[lsa
->data
->type
](
6721 vty
, lsa
, json_lsa
);
6723 json_object_object_add(
6733 /* Show detail LSA information. */
6734 static void show_lsa_detail_adv_router(struct vty
*vty
, struct ospf
*ospf
,
6735 int type
, struct in_addr
*adv_router
,
6738 struct listnode
*node
;
6739 struct ospf_area
*area
;
6740 char buf
[PREFIX_STRLEN
];
6741 json_object
*json_lstype
= NULL
;
6742 json_object
*json_area
= NULL
;
6745 json_lstype
= json_object_new_object();
6748 case OSPF_AS_EXTERNAL_LSA
:
6749 case OSPF_OPAQUE_AS_LSA
:
6751 vty_out(vty
, " %s \n\n",
6752 show_database_desc
[type
]);
6754 show_lsa_detail_adv_router_proc(vty
, AS_LSDB(ospf
, type
),
6755 adv_router
, json_lstype
);
6759 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6761 json_area
= json_object_new_object();
6764 "\n %s (Area %s)\n\n",
6765 show_database_desc
[type
],
6766 ospf_area_desc_string(area
));
6767 show_lsa_detail_adv_router_proc(vty
,
6768 AREA_LSDB(area
, type
),
6769 adv_router
, json_area
);
6772 json_object_object_add(json_lstype
,
6783 json_object_object_add(json
, show_database_desc
[type
],
6787 void show_ip_ospf_database_summary(struct vty
*vty
, struct ospf
*ospf
, int self
,
6790 struct ospf_lsa
*lsa
;
6791 struct route_node
*rn
;
6792 struct ospf_area
*area
;
6793 struct listnode
*node
;
6794 char buf
[PREFIX_STRLEN
];
6795 json_object
*json_areas
= NULL
;
6796 json_object
*json_area
= NULL
;
6797 json_object
*json_lsa
= NULL
;
6799 json_object
*json_lsa_array
= NULL
;
6803 json_areas
= json_object_new_object();
6805 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6807 json_area
= json_object_new_object();
6809 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6812 case OSPF_AS_EXTERNAL_LSA
:
6813 case OSPF_OPAQUE_AS_LSA
:
6818 if (ospf_lsdb_count_self(area
->lsdb
, type
) > 0
6820 && ospf_lsdb_count(area
->lsdb
, type
) > 0)) {
6824 " %s (Area %s)\n\n",
6825 show_database_desc
[type
],
6826 ospf_area_desc_string(area
));
6827 vty_out(vty
, "%s\n",
6828 show_database_header
[type
]);
6831 json_object_new_array();
6832 json_object_object_add(
6834 show_database_desc_json
[type
],
6838 LSDB_LOOP (AREA_LSDB(area
, type
), rn
, lsa
) {
6841 json_object_new_object();
6842 json_object_array_add(
6847 count
+= show_lsa_summary(
6848 vty
, lsa
, self
, json_lsa
);
6854 json_object_int_add(
6857 show_database_desc_count_json
6863 json_object_object_add(json_areas
,
6871 json_object_object_add(json
, "areas", json_areas
);
6873 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6876 case OSPF_AS_EXTERNAL_LSA
:
6877 case OSPF_OPAQUE_AS_LSA
:
6882 if (ospf_lsdb_count_self(ospf
->lsdb
, type
)
6883 || (!self
&& ospf_lsdb_count(ospf
->lsdb
, type
))) {
6885 vty_out(vty
, " %s\n\n",
6886 show_database_desc
[type
]);
6887 vty_out(vty
, "%s\n",
6888 show_database_header
[type
]);
6890 json_lsa_array
= json_object_new_array();
6891 json_object_object_add(
6892 json
, show_database_desc_json
[type
],
6896 LSDB_LOOP (AS_LSDB(ospf
, type
), rn
, lsa
) {
6898 json_lsa
= json_object_new_object();
6899 json_object_array_add(json_lsa_array
,
6903 count
+= show_lsa_summary(vty
, lsa
, self
,
6910 json_object_int_add(
6912 show_database_desc_count_json
[type
],
6921 static void show_ip_ospf_database_maxage(struct vty
*vty
, struct ospf
*ospf
,
6924 struct route_node
*rn
;
6925 char buf
[PREFIX_STRLEN
];
6926 json_object
*json_maxage
= NULL
;
6929 vty_out(vty
, "\n MaxAge Link States:\n\n");
6931 json_maxage
= json_object_new_object();
6933 for (rn
= route_top(ospf
->maxage_lsa
); rn
; rn
= route_next(rn
)) {
6934 struct ospf_lsa
*lsa
;
6935 json_object
*json_lsa
= NULL
;
6937 if ((lsa
= rn
->info
) != NULL
) {
6939 vty_out(vty
, "Link type: %d\n",
6941 vty_out(vty
, "Link State ID: %pI4\n",
6943 vty_out(vty
, "Advertising Router: %pI4\n",
6944 &lsa
->data
->adv_router
);
6945 vty_out(vty
, "LSA lock count: %d\n", lsa
->lock
);
6948 json_lsa
= json_object_new_object();
6949 json_object_int_add(json_lsa
, "linkType",
6951 json_object_string_addf(json_lsa
, "linkStateId",
6952 "%pI4", &lsa
->data
->id
);
6953 json_object_string_addf(
6954 json_lsa
, "advertisingRouter", "%pI4",
6955 &lsa
->data
->adv_router
);
6956 json_object_int_add(json_lsa
, "lsaLockCount",
6958 json_object_object_add(
6968 json_object_object_add(json
, "maxAgeLinkStates", json_maxage
);
6971 #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
6972 #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
6974 #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
6975 #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
6976 #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
6977 #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
6979 #define OSPF_LSA_TYPES_DESC \
6980 "ASBR summary link states\n" \
6981 "External link states\n" \
6982 "Network link states\n" \
6983 "Router link states\n" \
6984 "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \
6985 OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
6986 OSPF_LSA_TYPE_OPAQUE_AS_DESC
6988 static int show_ip_ospf_database_common(struct vty
*vty
, struct ospf
*ospf
,
6989 int arg_base
, int argc
,
6990 struct cmd_token
**argv
,
6991 uint8_t use_vrf
, json_object
*json
,
6996 struct in_addr id
, adv_router
;
6997 json_object
*json_vrf
= NULL
;
7001 json_vrf
= json_object_new_object();
7006 if (ospf
->instance
) {
7008 json_object_int_add(json_vrf
, "ospfInstance",
7011 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
7014 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
7016 /* Show Router ID. */
7018 json_object_string_addf(json_vrf
, "routerId", "%pI4",
7021 vty_out(vty
, "\n OSPF Router with ID (%pI4)\n\n",
7026 if ((argc
== arg_base
+ 4) || (uj
&& (argc
== arg_base
+ 5))) {
7027 show_ip_ospf_database_summary(vty
, ospf
, 0, json_vrf
);
7030 json_object_object_add(
7031 json
, ospf_get_name(ospf
), json_vrf
);
7036 /* Set database type to show. */
7037 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
7038 type
= OSPF_ROUTER_LSA
;
7039 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
7040 type
= OSPF_NETWORK_LSA
;
7041 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
7042 type
= OSPF_AS_NSSA_LSA
;
7043 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "su", 2) == 0)
7044 type
= OSPF_SUMMARY_LSA
;
7045 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
7046 type
= OSPF_ASBR_SUMMARY_LSA
;
7047 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
7048 type
= OSPF_AS_EXTERNAL_LSA
;
7049 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "se", 2) == 0) {
7050 show_ip_ospf_database_summary(vty
, ospf
, 1, json_vrf
);
7053 json_object_object_add(
7054 json
, ospf_get_name(ospf
), json_vrf
);
7057 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "m", 1) == 0) {
7058 show_ip_ospf_database_maxage(vty
, ospf
, json_vrf
);
7061 json_object_object_add(
7062 json
, ospf_get_name(ospf
), json_vrf
);
7065 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
7066 type
= OSPF_OPAQUE_LINK_LSA
;
7067 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
7068 type
= OSPF_OPAQUE_AREA_LSA
;
7069 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
7070 type
= OSPF_OPAQUE_AS_LSA
;
7074 /* `show ip ospf database LSA'. */
7075 if ((argc
== arg_base
+ 5) || (uj
&& (argc
== arg_base
+ 6)))
7076 show_lsa_detail(vty
, ospf
, type
, NULL
, NULL
, json_vrf
);
7077 else if (argc
>= arg_base
+ 6) {
7078 ret
= inet_aton(argv
[arg_base
+ 5]->arg
, &id
);
7082 /* `show ip ospf database LSA ID'. */
7083 if ((argc
== arg_base
+ 6) || (uj
&& (argc
== arg_base
+ 7)))
7084 show_lsa_detail(vty
, ospf
, type
, &id
, NULL
, json_vrf
);
7085 /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */
7086 else if ((argc
== arg_base
+ 7)
7087 || (uj
&& (argc
== arg_base
+ 8))) {
7088 if (strncmp(argv
[arg_base
+ 6]->text
, "s", 1) == 0)
7089 adv_router
= ospf
->router_id
;
7091 ret
= inet_aton(argv
[arg_base
+ 7]->arg
,
7096 show_lsa_detail(vty
, ospf
, type
, &id
, &adv_router
,
7103 json_object_object_add(json
, ospf_get_name(ospf
),
7110 DEFUN (show_ip_ospf_database_max
,
7111 show_ip_ospf_database_max_cmd
,
7112 "show ip ospf [vrf <NAME|all>] database <max-age|self-originate> [json]",
7115 "OSPF information\n"
7118 "Database summary\n"
7119 "LSAs in MaxAge list\n"
7120 "Self-originated link states\n"
7123 struct ospf
*ospf
= NULL
;
7124 struct listnode
*node
= NULL
;
7125 char *vrf_name
= NULL
;
7126 bool all_vrf
= false;
7127 int ret
= CMD_SUCCESS
;
7130 uint8_t use_vrf
= 0;
7131 bool uj
= use_json(argc
, argv
);
7132 json_object
*json
= NULL
;
7135 json
= json_object_new_object();
7137 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
7140 bool ospf_output
= false;
7145 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
7146 if (!ospf
->oi_running
)
7149 ret
= show_ip_ospf_database_common(
7150 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
,
7155 vty_out(vty
, "%% OSPF is not enabled\n");
7157 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
7158 if (ospf
== NULL
|| !ospf
->oi_running
) {
7160 "%% OSPF is not enabled in vrf %s\n",
7163 json_object_free(json
);
7167 ret
= (show_ip_ospf_database_common(
7168 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
, use_vrf
,
7172 /* Display default ospf (instance 0) info */
7173 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
7174 if (ospf
== NULL
|| !ospf
->oi_running
) {
7175 vty_out(vty
, "%% OSPF is not enabled in vrf default\n");
7177 json_object_free(json
);
7182 ret
= show_ip_ospf_database_common(vty
, ospf
, 0, argc
, argv
,
7187 vty_json(vty
, json
);
7192 ALIAS (show_ip_ospf_database_max
,
7193 show_ip_ospf_database_cmd
,
7194 "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]",
7197 "OSPF information\n"
7200 "Database summary\n"
7202 "Link State ID (as an IP address)\n"
7203 "Self-originated link states\n"
7204 "Advertising Router link states\n"
7205 "Advertising Router (as an IP address)\n"
7208 DEFUN (show_ip_ospf_instance_database_max
,
7209 show_ip_ospf_instance_database_max_cmd
,
7210 "show ip ospf (1-65535) database <max-age|self-originate> [json]",
7213 "OSPF information\n"
7215 "Database summary\n"
7216 "LSAs in MaxAge list\n"
7217 "Self-originated link states\n"
7222 unsigned short instance
= 0;
7223 bool uj
= use_json(argc
, argv
);
7224 json_object
*json
= NULL
;
7227 json
= json_object_new_object();
7229 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
7230 if (instance
!= ospf_instance
)
7231 return CMD_NOT_MY_INSTANCE
;
7233 ospf
= ospf_lookup_instance(instance
);
7234 if (!ospf
|| !ospf
->oi_running
)
7237 show_ip_ospf_database_common(vty
, ospf
, 1, argc
, argv
, 0, json
, uj
);
7240 vty_json(vty
, json
);
7245 ALIAS (show_ip_ospf_instance_database_max
,
7246 show_ip_ospf_instance_database_cmd
,
7247 "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]",
7250 "OSPF information\n"
7252 "Database summary\n"
7254 "Link State ID (as an IP address)\n"
7255 "Self-originated link states\n"
7256 "Advertising Router link states\n"
7257 "Advertising Router (as an IP address)\n"
7260 static int show_ip_ospf_database_type_adv_router_common(struct vty
*vty
,
7262 int arg_base
, int argc
,
7263 struct cmd_token
**argv
,
7270 struct in_addr adv_router
;
7271 json_object
*json_vrf
= NULL
;
7275 json_vrf
= json_object_new_object();
7280 if (ospf
->instance
) {
7282 json_object_int_add(json
, "ospfInstance",
7285 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
7288 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
7290 /* Show Router ID. */
7292 json_object_string_addf(json_vrf
, "routerId", "%pI4",
7295 vty_out(vty
, "\n OSPF Router with ID (%pI4)\n\n",
7299 /* Set database type to show. */
7300 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
7301 type
= OSPF_ROUTER_LSA
;
7302 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
7303 type
= OSPF_NETWORK_LSA
;
7304 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
7305 type
= OSPF_AS_NSSA_LSA
;
7306 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "s", 1) == 0)
7307 type
= OSPF_SUMMARY_LSA
;
7308 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
7309 type
= OSPF_ASBR_SUMMARY_LSA
;
7310 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
7311 type
= OSPF_AS_EXTERNAL_LSA
;
7312 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
7313 type
= OSPF_OPAQUE_LINK_LSA
;
7314 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
7315 type
= OSPF_OPAQUE_AREA_LSA
;
7316 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
7317 type
= OSPF_OPAQUE_AS_LSA
;
7321 /* `show ip ospf database LSA adv-router ADV_ROUTER'. */
7322 if (strncmp(argv
[arg_base
+ 5]->text
, "s", 1) == 0)
7323 adv_router
= ospf
->router_id
;
7325 ret
= inet_aton(argv
[arg_base
+ 6]->arg
, &adv_router
);
7330 show_lsa_detail_adv_router(vty
, ospf
, type
, &adv_router
, json_vrf
);
7334 json_object_object_add(json
, ospf_get_name(ospf
),
7341 DEFUN (show_ip_ospf_database_type_adv_router
,
7342 show_ip_ospf_database_type_adv_router_cmd
,
7343 "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]",
7346 "OSPF information\n"
7349 "Database summary\n"
7351 "Advertising Router link states\n"
7352 "Advertising Router (as an IP address)\n"
7353 "Self-originated link states\n"
7356 struct ospf
*ospf
= NULL
;
7357 struct listnode
*node
= NULL
;
7358 char *vrf_name
= NULL
;
7359 bool all_vrf
= false;
7360 int ret
= CMD_SUCCESS
;
7363 uint8_t use_vrf
= 0;
7364 bool uj
= use_json(argc
, argv
);
7365 json_object
*json
= NULL
;
7368 json
= json_object_new_object();
7370 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
7373 bool ospf_output
= false;
7378 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
7379 if (!ospf
->oi_running
)
7382 ret
= show_ip_ospf_database_type_adv_router_common(
7383 vty
, ospf
, 2, argc
, argv
, use_vrf
, json
,
7387 vty_out(vty
, "%% OSPF is not enabled\n");
7389 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
7390 if ((ospf
== NULL
) || !ospf
->oi_running
) {
7392 "%% OSPF is not enabled in vrf %s\n",
7397 ret
= show_ip_ospf_database_type_adv_router_common(
7398 vty
, ospf
, 2, argc
, argv
, use_vrf
, json
, uj
);
7401 /* Display default ospf (instance 0) info */
7402 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
7403 if (ospf
== NULL
|| !ospf
->oi_running
) {
7404 vty_out(vty
, "%% OSPF is not enabled on vrf default\n");
7408 ret
= show_ip_ospf_database_type_adv_router_common(
7409 vty
, ospf
, 0, argc
, argv
, use_vrf
, json
, uj
);
7413 vty_out(vty
, "%s\n", json_object_to_json_string(json
));
7414 json_object_free(json
);
7420 DEFUN (show_ip_ospf_instance_database_type_adv_router
,
7421 show_ip_ospf_instance_database_type_adv_router_cmd
,
7422 "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]",
7425 "OSPF information\n"
7427 "Database summary\n"
7429 "Advertising Router link states\n"
7430 "Advertising Router (as an IP address)\n"
7431 "Self-originated link states\n"
7436 unsigned short instance
= 0;
7437 bool uj
= use_json(argc
, argv
);
7438 json_object
*json
= NULL
;
7441 json
= json_object_new_object();
7443 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
7444 if (instance
!= ospf_instance
)
7445 return CMD_NOT_MY_INSTANCE
;
7447 ospf
= ospf_lookup_instance(instance
);
7448 if (!ospf
|| !ospf
->oi_running
)
7451 show_ip_ospf_database_type_adv_router_common(vty
, ospf
, 1, argc
, argv
,
7455 vty_json(vty
, json
);
7460 DEFUN (ip_ospf_authentication_args
,
7461 ip_ospf_authentication_args_addr_cmd
,
7462 "ip ospf authentication <null|message-digest> [A.B.C.D]",
7464 "OSPF interface commands\n"
7465 "Enable authentication on this interface\n"
7466 "Use null authentication\n"
7467 "Use message-digest authentication\n"
7468 "Address of interface\n")
7470 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7471 int idx_encryption
= 3;
7473 struct in_addr addr
;
7475 struct ospf_if_params
*params
;
7477 params
= IF_DEF_PARAMS(ifp
);
7480 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7483 "Please specify interface address by A.B.C.D\n");
7484 return CMD_WARNING_CONFIG_FAILED
;
7487 params
= ospf_get_if_params(ifp
, addr
);
7488 ospf_if_update_params(ifp
, addr
);
7491 /* Handle null authentication */
7492 if (argv
[idx_encryption
]->arg
[0] == 'n') {
7493 SET_IF_PARAM(params
, auth_type
);
7494 params
->auth_type
= OSPF_AUTH_NULL
;
7498 /* Handle message-digest authentication */
7499 if (argv
[idx_encryption
]->arg
[0] == 'm') {
7500 SET_IF_PARAM(params
, auth_type
);
7501 params
->auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
7505 vty_out(vty
, "You shouldn't get here!\n");
7506 return CMD_WARNING_CONFIG_FAILED
;
7509 DEFUN (ip_ospf_authentication
,
7510 ip_ospf_authentication_addr_cmd
,
7511 "ip ospf authentication [A.B.C.D]",
7513 "OSPF interface commands\n"
7514 "Enable authentication on this interface\n"
7515 "Address of interface\n")
7517 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7519 struct in_addr addr
;
7521 struct ospf_if_params
*params
;
7523 params
= IF_DEF_PARAMS(ifp
);
7526 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7529 "Please specify interface address by A.B.C.D\n");
7530 return CMD_WARNING_CONFIG_FAILED
;
7533 params
= ospf_get_if_params(ifp
, addr
);
7534 ospf_if_update_params(ifp
, addr
);
7537 SET_IF_PARAM(params
, auth_type
);
7538 params
->auth_type
= OSPF_AUTH_SIMPLE
;
7543 DEFUN (no_ip_ospf_authentication_args
,
7544 no_ip_ospf_authentication_args_addr_cmd
,
7545 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
7548 "OSPF interface commands\n"
7549 "Enable authentication on this interface\n"
7550 "Use null authentication\n"
7551 "Use message-digest authentication\n"
7552 "Address of interface\n")
7554 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7555 int idx_encryption
= 4;
7557 struct in_addr addr
;
7559 struct ospf_if_params
*params
;
7560 struct route_node
*rn
;
7563 params
= IF_DEF_PARAMS(ifp
);
7566 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7569 "Please specify interface address by A.B.C.D\n");
7570 return CMD_WARNING_CONFIG_FAILED
;
7573 params
= ospf_lookup_if_params(ifp
, addr
);
7574 if (params
== NULL
) {
7575 vty_out(vty
, "Ip Address specified is unknown\n");
7576 return CMD_WARNING_CONFIG_FAILED
;
7578 params
->auth_type
= OSPF_AUTH_NOTSET
;
7579 UNSET_IF_PARAM(params
, auth_type
);
7580 if (params
!= IF_DEF_PARAMS(ifp
)) {
7581 ospf_free_if_params(ifp
, addr
);
7582 ospf_if_update_params(ifp
, addr
);
7585 if (argv
[idx_encryption
]->arg
[0] == 'n') {
7586 auth_type
= OSPF_AUTH_NULL
;
7587 } else if (argv
[idx_encryption
]->arg
[0] == 'm') {
7588 auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
7590 vty_out(vty
, "Unexpected input encountered\n");
7591 return CMD_WARNING_CONFIG_FAILED
;
7594 * Here we have a case where the user has entered
7595 * 'no ip ospf authentication (null | message_digest )'
7596 * we need to find if we have any ip addresses underneath it
7598 * correspond to the associated type.
7600 if (params
->auth_type
== auth_type
) {
7601 params
->auth_type
= OSPF_AUTH_NOTSET
;
7602 UNSET_IF_PARAM(params
, auth_type
);
7605 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
7606 rn
= route_next(rn
)) {
7607 if ((params
= rn
->info
)) {
7608 if (params
->auth_type
== auth_type
) {
7609 params
->auth_type
= OSPF_AUTH_NOTSET
;
7610 UNSET_IF_PARAM(params
, auth_type
);
7611 if (params
!= IF_DEF_PARAMS(ifp
)) {
7612 ospf_free_if_params(
7613 ifp
, rn
->p
.u
.prefix4
);
7614 ospf_if_update_params(
7615 ifp
, rn
->p
.u
.prefix4
);
7625 DEFUN (no_ip_ospf_authentication
,
7626 no_ip_ospf_authentication_addr_cmd
,
7627 "no ip ospf authentication [A.B.C.D]",
7630 "OSPF interface commands\n"
7631 "Enable authentication on this interface\n"
7632 "Address of interface\n")
7634 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7636 struct in_addr addr
;
7638 struct ospf_if_params
*params
;
7639 struct route_node
*rn
;
7641 params
= IF_DEF_PARAMS(ifp
);
7644 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7647 "Please specify interface address by A.B.C.D\n");
7648 return CMD_WARNING_CONFIG_FAILED
;
7651 params
= ospf_lookup_if_params(ifp
, addr
);
7652 if (params
== NULL
) {
7653 vty_out(vty
, "Ip Address specified is unknown\n");
7654 return CMD_WARNING_CONFIG_FAILED
;
7657 params
->auth_type
= OSPF_AUTH_NOTSET
;
7658 UNSET_IF_PARAM(params
, auth_type
);
7659 if (params
!= IF_DEF_PARAMS(ifp
)) {
7660 ospf_free_if_params(ifp
, addr
);
7661 ospf_if_update_params(ifp
, addr
);
7665 * When a user enters 'no ip ospf authentication'
7666 * We should remove all authentication types from
7669 if ((params
->auth_type
== OSPF_AUTH_NULL
)
7670 || (params
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
7671 || (params
->auth_type
== OSPF_AUTH_SIMPLE
)) {
7672 params
->auth_type
= OSPF_AUTH_NOTSET
;
7673 UNSET_IF_PARAM(params
, auth_type
);
7676 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
7677 rn
= route_next(rn
)) {
7678 if ((params
= rn
->info
)) {
7680 if ((params
->auth_type
== OSPF_AUTH_NULL
)
7681 || (params
->auth_type
7682 == OSPF_AUTH_CRYPTOGRAPHIC
)
7683 || (params
->auth_type
7684 == OSPF_AUTH_SIMPLE
)) {
7685 params
->auth_type
= OSPF_AUTH_NOTSET
;
7686 UNSET_IF_PARAM(params
, auth_type
);
7687 if (params
!= IF_DEF_PARAMS(ifp
)) {
7688 ospf_free_if_params(
7689 ifp
, rn
->p
.u
.prefix4
);
7690 ospf_if_update_params(
7691 ifp
, rn
->p
.u
.prefix4
);
7702 DEFUN (ip_ospf_authentication_key
,
7703 ip_ospf_authentication_key_addr_cmd
,
7704 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
7706 "OSPF interface commands\n"
7707 "Authentication password (key)\n"
7708 "The OSPF password (key)\n"
7709 "Address of interface\n")
7711 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7713 struct in_addr addr
;
7714 struct ospf_if_params
*params
;
7716 params
= IF_DEF_PARAMS(ifp
);
7718 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7719 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7721 "Please specify interface address by A.B.C.D\n");
7722 return CMD_WARNING_CONFIG_FAILED
;
7725 params
= ospf_get_if_params(ifp
, addr
);
7726 ospf_if_update_params(ifp
, addr
);
7729 strlcpy((char *)params
->auth_simple
, argv
[3]->arg
,
7730 sizeof(params
->auth_simple
));
7731 SET_IF_PARAM(params
, auth_simple
);
7736 DEFUN_HIDDEN (ospf_authentication_key
,
7737 ospf_authentication_key_cmd
,
7738 "ospf authentication-key AUTH_KEY [A.B.C.D]",
7739 "OSPF interface commands\n"
7740 VLINK_HELPSTR_AUTH_SIMPLE
7741 "Address of interface\n")
7743 return ip_ospf_authentication_key(self
, vty
, argc
, argv
);
7746 DEFUN (no_ip_ospf_authentication_key
,
7747 no_ip_ospf_authentication_key_authkey_addr_cmd
,
7748 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7751 "OSPF interface commands\n"
7752 VLINK_HELPSTR_AUTH_SIMPLE
7753 "Address of interface\n")
7755 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7757 struct in_addr addr
;
7758 struct ospf_if_params
*params
;
7759 params
= IF_DEF_PARAMS(ifp
);
7761 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7762 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7764 "Please specify interface address by A.B.C.D\n");
7765 return CMD_WARNING_CONFIG_FAILED
;
7768 params
= ospf_lookup_if_params(ifp
, addr
);
7773 memset(params
->auth_simple
, 0, OSPF_AUTH_SIMPLE_SIZE
);
7774 UNSET_IF_PARAM(params
, auth_simple
);
7776 if (params
!= IF_DEF_PARAMS(ifp
)) {
7777 ospf_free_if_params(ifp
, addr
);
7778 ospf_if_update_params(ifp
, addr
);
7784 DEFUN_HIDDEN (no_ospf_authentication_key
,
7785 no_ospf_authentication_key_authkey_addr_cmd
,
7786 "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7788 "OSPF interface commands\n"
7789 VLINK_HELPSTR_AUTH_SIMPLE
7790 "Address of interface\n")
7792 return no_ip_ospf_authentication_key(self
, vty
, argc
, argv
);
7795 DEFUN (ip_ospf_message_digest_key
,
7796 ip_ospf_message_digest_key_cmd
,
7797 "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7799 "OSPF interface commands\n"
7800 "Message digest authentication password (key)\n"
7802 "Use MD5 algorithm\n"
7803 "The OSPF password (key)\n"
7804 "Address of interface\n")
7806 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7807 struct crypt_key
*ck
;
7809 struct in_addr addr
;
7810 struct ospf_if_params
*params
;
7812 params
= IF_DEF_PARAMS(ifp
);
7815 argv_find(argv
, argc
, "(1-255)", &idx
);
7816 char *keyid
= argv
[idx
]->arg
;
7817 argv_find(argv
, argc
, "KEY", &idx
);
7818 char *cryptkey
= argv
[idx
]->arg
;
7820 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7821 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7823 "Please specify interface address by A.B.C.D\n");
7824 return CMD_WARNING_CONFIG_FAILED
;
7827 params
= ospf_get_if_params(ifp
, addr
);
7828 ospf_if_update_params(ifp
, addr
);
7831 key_id
= strtol(keyid
, NULL
, 10);
7833 /* Remove existing key, if any */
7834 ospf_crypt_key_delete(params
->auth_crypt
, key_id
);
7836 ck
= ospf_crypt_key_new();
7837 ck
->key_id
= (uint8_t)key_id
;
7838 strlcpy((char *)ck
->auth_key
, cryptkey
, sizeof(ck
->auth_key
));
7840 ospf_crypt_key_add(params
->auth_crypt
, ck
);
7841 SET_IF_PARAM(params
, auth_crypt
);
7846 DEFUN_HIDDEN (ospf_message_digest_key
,
7847 ospf_message_digest_key_cmd
,
7848 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7849 "OSPF interface commands\n"
7850 "Message digest authentication password (key)\n"
7852 "Use MD5 algorithm\n"
7853 "The OSPF password (key)\n"
7854 "Address of interface\n")
7856 return ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7859 DEFUN (no_ip_ospf_message_digest_key
,
7860 no_ip_ospf_message_digest_key_cmd
,
7861 "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7864 "OSPF interface commands\n"
7865 "Message digest authentication password (key)\n"
7867 "Use MD5 algorithm\n"
7868 "The OSPF password (key)\n"
7869 "Address of interface\n")
7871 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7873 struct crypt_key
*ck
;
7875 struct in_addr addr
;
7876 struct ospf_if_params
*params
;
7877 params
= IF_DEF_PARAMS(ifp
);
7879 argv_find(argv
, argc
, "(1-255)", &idx
);
7880 char *keyid
= argv
[idx
]->arg
;
7882 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7883 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7885 "Please specify interface address by A.B.C.D\n");
7886 return CMD_WARNING_CONFIG_FAILED
;
7889 params
= ospf_lookup_if_params(ifp
, addr
);
7894 key_id
= strtol(keyid
, NULL
, 10);
7895 ck
= ospf_crypt_key_lookup(params
->auth_crypt
, key_id
);
7897 vty_out(vty
, "OSPF: Key %d does not exist\n", key_id
);
7898 return CMD_WARNING_CONFIG_FAILED
;
7901 ospf_crypt_key_delete(params
->auth_crypt
, key_id
);
7903 if (params
!= IF_DEF_PARAMS(ifp
)) {
7904 ospf_free_if_params(ifp
, addr
);
7905 ospf_if_update_params(ifp
, addr
);
7911 DEFUN_HIDDEN (no_ospf_message_digest_key
,
7912 no_ospf_message_digest_key_cmd
,
7913 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7915 "OSPF interface commands\n"
7916 "Message digest authentication password (key)\n"
7918 "Use MD5 algorithm\n"
7919 "The OSPF password (key)\n"
7920 "Address of interface\n")
7922 return no_ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7925 DEFUN (ip_ospf_cost
,
7927 "ip ospf cost (1-65535) [A.B.C.D]",
7929 "OSPF interface commands\n"
7932 "Address of interface\n")
7934 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7936 uint32_t cost
= OSPF_OUTPUT_COST_DEFAULT
;
7937 struct in_addr addr
;
7938 struct ospf_if_params
*params
;
7939 params
= IF_DEF_PARAMS(ifp
);
7942 char *coststr
= NULL
, *ifaddr
= NULL
;
7944 argv_find(argv
, argc
, "(1-65535)", &idx
);
7945 coststr
= argv
[idx
]->arg
;
7946 cost
= strtol(coststr
, NULL
, 10);
7948 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7950 if (!inet_aton(ifaddr
, &addr
)) {
7952 "Please specify interface address by A.B.C.D\n");
7953 return CMD_WARNING_CONFIG_FAILED
;
7956 params
= ospf_get_if_params(ifp
, addr
);
7957 ospf_if_update_params(ifp
, addr
);
7960 SET_IF_PARAM(params
, output_cost_cmd
);
7961 params
->output_cost_cmd
= cost
;
7963 ospf_if_recalculate_output_cost(ifp
);
7968 DEFUN_HIDDEN (ospf_cost
,
7970 "ospf cost (1-65535) [A.B.C.D]",
7971 "OSPF interface commands\n"
7974 "Address of interface\n")
7976 return ip_ospf_cost(self
, vty
, argc
, argv
);
7979 DEFUN (no_ip_ospf_cost
,
7980 no_ip_ospf_cost_cmd
,
7981 "no ip ospf cost [(1-65535)] [A.B.C.D]",
7984 "OSPF interface commands\n"
7987 "Address of interface\n")
7989 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7991 struct in_addr addr
;
7992 struct ospf_if_params
*params
;
7994 params
= IF_DEF_PARAMS(ifp
);
7997 char *ifaddr
= NULL
;
7998 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
8000 /* According to the semantics we are mimicking "no ip ospf cost N" is
8001 * always treated as "no ip ospf cost" regardless of the actual value
8002 * of N already configured for the interface. Thus ignore cost. */
8005 if (!inet_aton(ifaddr
, &addr
)) {
8007 "Please specify interface address by A.B.C.D\n");
8008 return CMD_WARNING_CONFIG_FAILED
;
8011 params
= ospf_lookup_if_params(ifp
, addr
);
8016 UNSET_IF_PARAM(params
, output_cost_cmd
);
8018 if (params
!= IF_DEF_PARAMS(ifp
)) {
8019 ospf_free_if_params(ifp
, addr
);
8020 ospf_if_update_params(ifp
, addr
);
8023 ospf_if_recalculate_output_cost(ifp
);
8028 DEFUN_HIDDEN (no_ospf_cost
,
8030 "no ospf cost [(1-65535)] [A.B.C.D]",
8032 "OSPF interface commands\n"
8035 "Address of interface\n")
8037 return no_ip_ospf_cost(self
, vty
, argc
, argv
);
8040 static void ospf_nbr_timer_update(struct ospf_interface
*oi
)
8042 struct route_node
*rn
;
8043 struct ospf_neighbor
*nbr
;
8045 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
8051 nbr
->v_inactivity
= OSPF_IF_PARAM(oi
, v_wait
);
8052 nbr
->v_db_desc
= OSPF_IF_PARAM(oi
, retransmit_interval
);
8053 nbr
->v_ls_req
= OSPF_IF_PARAM(oi
, retransmit_interval
);
8054 nbr
->v_ls_upd
= OSPF_IF_PARAM(oi
, retransmit_interval
);
8058 static int ospf_vty_dead_interval_set(struct vty
*vty
, const char *interval_str
,
8059 const char *nbr_str
,
8060 const char *fast_hello_str
)
8062 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8065 struct in_addr addr
;
8067 struct ospf_if_params
*params
;
8068 struct ospf_interface
*oi
;
8069 struct route_node
*rn
;
8071 params
= IF_DEF_PARAMS(ifp
);
8074 ret
= inet_aton(nbr_str
, &addr
);
8077 "Please specify interface address by A.B.C.D\n");
8078 return CMD_WARNING_CONFIG_FAILED
;
8081 params
= ospf_get_if_params(ifp
, addr
);
8082 ospf_if_update_params(ifp
, addr
);
8086 seconds
= strtoul(interval_str
, NULL
, 10);
8088 /* reset fast_hello too, just to be sure */
8089 UNSET_IF_PARAM(params
, fast_hello
);
8090 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
8091 } else if (fast_hello_str
) {
8092 hellomult
= strtoul(fast_hello_str
, NULL
, 10);
8093 /* 1s dead-interval with sub-second hellos desired */
8094 seconds
= OSPF_ROUTER_DEAD_INTERVAL_MINIMAL
;
8095 SET_IF_PARAM(params
, fast_hello
);
8096 params
->fast_hello
= hellomult
;
8099 "Please specify dead-interval or hello-multiplier\n");
8100 return CMD_WARNING_CONFIG_FAILED
;
8103 SET_IF_PARAM(params
, v_wait
);
8104 params
->v_wait
= seconds
;
8105 params
->is_v_wait_set
= true;
8107 /* Update timer values in neighbor structure. */
8109 struct ospf
*ospf
= NULL
;
8111 ospf
= ifp
->vrf
->info
;
8113 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
8115 ospf_nbr_timer_update(oi
);
8118 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
8119 if ((oi
= rn
->info
))
8120 ospf_nbr_timer_update(oi
);
8126 DEFUN (ip_ospf_dead_interval
,
8127 ip_ospf_dead_interval_cmd
,
8128 "ip ospf dead-interval (1-65535) [A.B.C.D]",
8130 "OSPF interface commands\n"
8131 "Interval time after which a neighbor is declared down\n"
8133 "Address of interface\n")
8136 char *interval
= argv_find(argv
, argc
, "(1-65535)", &idx
)
8140 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
8141 return ospf_vty_dead_interval_set(vty
, interval
, ifaddr
, NULL
);
8145 DEFUN_HIDDEN (ospf_dead_interval
,
8146 ospf_dead_interval_cmd
,
8147 "ospf dead-interval (1-65535) [A.B.C.D]",
8148 "OSPF interface commands\n"
8149 "Interval time after which a neighbor is declared down\n"
8151 "Address of interface\n")
8153 return ip_ospf_dead_interval(self
, vty
, argc
, argv
);
8156 DEFUN (ip_ospf_dead_interval_minimal
,
8157 ip_ospf_dead_interval_minimal_addr_cmd
,
8158 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
8160 "OSPF interface commands\n"
8161 "Interval time after which a neighbor is declared down\n"
8162 "Minimal 1s dead-interval with fast sub-second hellos\n"
8163 "Hello multiplier factor\n"
8164 "Number of Hellos to send each second\n"
8165 "Address of interface\n")
8170 return ospf_vty_dead_interval_set(
8171 vty
, NULL
, argv
[idx_ipv4
]->arg
, argv
[idx_number
]->arg
);
8173 return ospf_vty_dead_interval_set(vty
, NULL
, NULL
,
8174 argv
[idx_number
]->arg
);
8177 DEFUN (no_ip_ospf_dead_interval
,
8178 no_ip_ospf_dead_interval_cmd
,
8179 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8182 "OSPF interface commands\n"
8183 "Interval time after which a neighbor is declared down\n"
8185 "Minimal 1s dead-interval with fast sub-second hellos\n"
8186 "Hello multiplier factor\n"
8187 "Number of Hellos to send each second\n"
8188 "Address of interface\n")
8190 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8191 int idx_ipv4
= argc
- 1;
8192 struct in_addr addr
= {.s_addr
= 0L};
8194 struct ospf_if_params
*params
;
8195 struct ospf_interface
*oi
;
8196 struct route_node
*rn
;
8198 params
= IF_DEF_PARAMS(ifp
);
8200 if (argv
[idx_ipv4
]->type
== IPV4_TKN
) {
8201 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8204 "Please specify interface address by A.B.C.D\n");
8205 return CMD_WARNING_CONFIG_FAILED
;
8208 params
= ospf_lookup_if_params(ifp
, addr
);
8213 UNSET_IF_PARAM(params
, v_wait
);
8214 params
->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
8215 params
->is_v_wait_set
= false;
8217 UNSET_IF_PARAM(params
, fast_hello
);
8218 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
8220 if (params
!= IF_DEF_PARAMS(ifp
)) {
8221 ospf_free_if_params(ifp
, addr
);
8222 ospf_if_update_params(ifp
, addr
);
8225 /* Update timer values in neighbor structure. */
8227 struct ospf
*ospf
= NULL
;
8229 ospf
= ifp
->vrf
->info
;
8231 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
8233 ospf_nbr_timer_update(oi
);
8236 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
8237 if ((oi
= rn
->info
))
8238 ospf_nbr_timer_update(oi
);
8244 DEFUN_HIDDEN (no_ospf_dead_interval
,
8245 no_ospf_dead_interval_cmd
,
8246 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8248 "OSPF interface commands\n"
8249 "Interval time after which a neighbor is declared down\n"
8251 "Minimal 1s dead-interval with fast sub-second hellos\n"
8252 "Hello multiplier factor\n"
8253 "Number of Hellos to send each second\n"
8254 "Address of interface\n")
8256 return no_ip_ospf_dead_interval(self
, vty
, argc
, argv
);
8259 DEFUN (ip_ospf_hello_interval
,
8260 ip_ospf_hello_interval_cmd
,
8261 "ip ospf hello-interval (1-65535) [A.B.C.D]",
8263 "OSPF interface commands\n"
8264 "Time between HELLO packets\n"
8266 "Address of interface\n")
8268 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8270 struct in_addr addr
= {.s_addr
= 0L};
8271 struct ospf_if_params
*params
;
8272 params
= IF_DEF_PARAMS(ifp
);
8273 uint32_t seconds
= 0;
8274 bool is_addr
= false;
8275 uint32_t old_interval
= 0;
8277 argv_find(argv
, argc
, "(1-65535)", &idx
);
8278 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
8280 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8281 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8283 "Please specify interface address by A.B.C.D\n");
8284 return CMD_WARNING_CONFIG_FAILED
;
8287 params
= ospf_get_if_params(ifp
, addr
);
8288 ospf_if_update_params(ifp
, addr
);
8292 old_interval
= params
->v_hello
;
8294 /* Return, if same interval is configured. */
8295 if (old_interval
== seconds
)
8298 SET_IF_PARAM(params
, v_hello
);
8299 params
->v_hello
= seconds
;
8301 if (!params
->is_v_wait_set
) {
8302 SET_IF_PARAM(params
, v_wait
);
8304 * The router dead interval should
8305 * be some multiple of the HelloInterval (perhaps 4 times the
8306 * hello interval) and must be the same for all routers
8307 * attached to a common network.
8309 params
->v_wait
= 4 * seconds
;
8312 ospf_reset_hello_timer(ifp
, addr
, is_addr
);
8317 DEFUN_HIDDEN (ospf_hello_interval
,
8318 ospf_hello_interval_cmd
,
8319 "ospf hello-interval (1-65535) [A.B.C.D]",
8320 "OSPF interface commands\n"
8321 "Time between HELLO packets\n"
8323 "Address of interface\n")
8325 return ip_ospf_hello_interval(self
, vty
, argc
, argv
);
8328 DEFUN (no_ip_ospf_hello_interval
,
8329 no_ip_ospf_hello_interval_cmd
,
8330 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
8333 "OSPF interface commands\n"
8334 "Time between HELLO packets\n" // ignored
8336 "Address of interface\n")
8338 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8340 struct in_addr addr
= {.s_addr
= 0L};
8341 struct ospf_if_params
*params
;
8342 struct route_node
*rn
;
8344 params
= IF_DEF_PARAMS(ifp
);
8346 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8347 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8349 "Please specify interface address by A.B.C.D\n");
8350 return CMD_WARNING_CONFIG_FAILED
;
8353 params
= ospf_lookup_if_params(ifp
, addr
);
8358 UNSET_IF_PARAM(params
, v_hello
);
8359 params
->v_hello
= OSPF_HELLO_INTERVAL_DEFAULT
;
8361 if (!params
->is_v_wait_set
) {
8362 UNSET_IF_PARAM(params
, v_wait
);
8363 params
->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
8366 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8367 struct ospf_interface
*oi
= rn
->info
;
8372 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
8373 oi
->ptp_dmvpn
= IF_DEF_PARAMS(ifp
)->ptp_dmvpn
;
8375 if (oi
->state
> ISM_Down
) {
8376 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
8377 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
8381 if (params
!= IF_DEF_PARAMS(ifp
)) {
8382 ospf_free_if_params(ifp
, addr
);
8383 ospf_if_update_params(ifp
, addr
);
8389 DEFUN_HIDDEN (no_ospf_hello_interval
,
8390 no_ospf_hello_interval_cmd
,
8391 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
8393 "OSPF interface commands\n"
8394 "Time between HELLO packets\n" // ignored
8396 "Address of interface\n")
8398 return no_ip_ospf_hello_interval(self
, vty
, argc
, argv
);
8401 DEFUN(ip_ospf_network
, ip_ospf_network_cmd
,
8402 "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point [dmvpn]>",
8404 "OSPF interface commands\n"
8406 "Specify OSPF broadcast multi-access network\n"
8407 "Specify OSPF NBMA network\n"
8408 "Specify OSPF point-to-multipoint network\n"
8409 "Specify OSPF point-to-point network\n"
8410 "Specify OSPF point-to-point DMVPN network\n")
8412 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8414 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
8415 uint8_t old_ptp_dmvpn
= IF_DEF_PARAMS(ifp
)->ptp_dmvpn
;
8416 struct route_node
*rn
;
8418 if (old_type
== OSPF_IFTYPE_LOOPBACK
) {
8420 "This is a loopback interface. Can't set network type.\n");
8421 return CMD_WARNING_CONFIG_FAILED
;
8424 IF_DEF_PARAMS(ifp
)->ptp_dmvpn
= 0;
8426 if (argv_find(argv
, argc
, "broadcast", &idx
))
8427 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_BROADCAST
;
8428 else if (argv_find(argv
, argc
, "non-broadcast", &idx
))
8429 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_NBMA
;
8430 else if (argv_find(argv
, argc
, "point-to-multipoint", &idx
))
8431 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOMULTIPOINT
;
8432 else if (argv_find(argv
, argc
, "point-to-point", &idx
)) {
8433 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOPOINT
;
8434 if (argv_find(argv
, argc
, "dmvpn", &idx
))
8435 IF_DEF_PARAMS(ifp
)->ptp_dmvpn
= 1;
8438 if (IF_DEF_PARAMS(ifp
)->type
== old_type
8439 && IF_DEF_PARAMS(ifp
)->ptp_dmvpn
== old_ptp_dmvpn
)
8442 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), type
);
8444 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8445 struct ospf_interface
*oi
= rn
->info
;
8450 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
8452 if (oi
->state
> ISM_Down
) {
8453 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
8454 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
8461 DEFUN_HIDDEN (ospf_network
,
8463 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
8464 "OSPF interface commands\n"
8466 "Specify OSPF broadcast multi-access network\n"
8467 "Specify OSPF NBMA network\n"
8468 "Specify OSPF point-to-multipoint network\n"
8469 "Specify OSPF point-to-point network\n")
8471 return ip_ospf_network(self
, vty
, argc
, argv
);
8474 DEFUN (no_ip_ospf_network
,
8475 no_ip_ospf_network_cmd
,
8476 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8479 "OSPF interface commands\n"
8481 "Specify OSPF broadcast multi-access network\n"
8482 "Specify OSPF NBMA network\n"
8483 "Specify OSPF point-to-multipoint network\n"
8484 "Specify OSPF point-to-point network\n")
8486 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8487 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
8488 struct route_node
*rn
;
8490 IF_DEF_PARAMS(ifp
)->type
= ospf_default_iftype(ifp
);
8491 IF_DEF_PARAMS(ifp
)->ptp_dmvpn
= 0;
8493 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
8496 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8497 struct ospf_interface
*oi
= rn
->info
;
8502 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
8504 if (oi
->state
> ISM_Down
) {
8505 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
8506 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
8513 DEFUN_HIDDEN (no_ospf_network
,
8514 no_ospf_network_cmd
,
8515 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8517 "OSPF interface commands\n"
8519 "Specify OSPF broadcast multi-access network\n"
8520 "Specify OSPF NBMA network\n"
8521 "Specify OSPF point-to-multipoint network\n"
8522 "Specify OSPF point-to-point network\n")
8524 return no_ip_ospf_network(self
, vty
, argc
, argv
);
8527 DEFUN (ip_ospf_priority
,
8528 ip_ospf_priority_cmd
,
8529 "ip ospf priority (0-255) [A.B.C.D]",
8531 "OSPF interface commands\n"
8534 "Address of interface\n")
8536 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8539 struct route_node
*rn
;
8540 struct in_addr addr
;
8541 struct ospf_if_params
*params
;
8542 params
= IF_DEF_PARAMS(ifp
);
8544 argv_find(argv
, argc
, "(0-255)", &idx
);
8545 priority
= strtol(argv
[idx
]->arg
, NULL
, 10);
8547 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8548 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8550 "Please specify interface address by A.B.C.D\n");
8551 return CMD_WARNING_CONFIG_FAILED
;
8554 params
= ospf_get_if_params(ifp
, addr
);
8555 ospf_if_update_params(ifp
, addr
);
8558 SET_IF_PARAM(params
, priority
);
8559 params
->priority
= priority
;
8561 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8562 struct ospf_interface
*oi
= rn
->info
;
8567 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
8568 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
8569 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
8576 DEFUN_HIDDEN (ospf_priority
,
8578 "ospf priority (0-255) [A.B.C.D]",
8579 "OSPF interface commands\n"
8582 "Address of interface\n")
8584 return ip_ospf_priority(self
, vty
, argc
, argv
);
8587 DEFUN (no_ip_ospf_priority
,
8588 no_ip_ospf_priority_cmd
,
8589 "no ip ospf priority [(0-255) [A.B.C.D]]",
8592 "OSPF interface commands\n"
8593 "Router priority\n" // ignored
8595 "Address of interface\n")
8597 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8599 struct route_node
*rn
;
8600 struct in_addr addr
;
8601 struct ospf_if_params
*params
;
8603 params
= IF_DEF_PARAMS(ifp
);
8605 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8606 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8608 "Please specify interface address by A.B.C.D\n");
8609 return CMD_WARNING_CONFIG_FAILED
;
8612 params
= ospf_lookup_if_params(ifp
, addr
);
8617 UNSET_IF_PARAM(params
, priority
);
8618 params
->priority
= OSPF_ROUTER_PRIORITY_DEFAULT
;
8620 if (params
!= IF_DEF_PARAMS(ifp
)) {
8621 ospf_free_if_params(ifp
, addr
);
8622 ospf_if_update_params(ifp
, addr
);
8625 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8626 struct ospf_interface
*oi
= rn
->info
;
8631 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
8632 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
8633 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
8640 DEFUN_HIDDEN (no_ospf_priority
,
8641 no_ospf_priority_cmd
,
8642 "no ospf priority [(0-255) [A.B.C.D]]",
8644 "OSPF interface commands\n"
8647 "Address of interface\n")
8649 return no_ip_ospf_priority(self
, vty
, argc
, argv
);
8652 DEFUN (ip_ospf_retransmit_interval
,
8653 ip_ospf_retransmit_interval_addr_cmd
,
8654 "ip ospf retransmit-interval (1-65535) [A.B.C.D]",
8656 "OSPF interface commands\n"
8657 "Time between retransmitting lost link state advertisements\n"
8659 "Address of interface\n")
8661 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8664 struct in_addr addr
;
8665 struct ospf_if_params
*params
;
8666 params
= IF_DEF_PARAMS(ifp
);
8668 argv_find(argv
, argc
, "(1-65535)", &idx
);
8669 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
8671 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8672 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8674 "Please specify interface address by A.B.C.D\n");
8675 return CMD_WARNING_CONFIG_FAILED
;
8678 params
= ospf_get_if_params(ifp
, addr
);
8679 ospf_if_update_params(ifp
, addr
);
8682 SET_IF_PARAM(params
, retransmit_interval
);
8683 params
->retransmit_interval
= seconds
;
8688 DEFUN_HIDDEN (ospf_retransmit_interval
,
8689 ospf_retransmit_interval_cmd
,
8690 "ospf retransmit-interval (1-65535) [A.B.C.D]",
8691 "OSPF interface commands\n"
8692 "Time between retransmitting lost link state advertisements\n"
8694 "Address of interface\n")
8696 return ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
8699 DEFUN (no_ip_ospf_retransmit_interval
,
8700 no_ip_ospf_retransmit_interval_addr_cmd
,
8701 "no ip ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8704 "OSPF interface commands\n"
8705 "Time between retransmitting lost link state advertisements\n"
8707 "Address of interface\n")
8709 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8711 struct in_addr addr
;
8712 struct ospf_if_params
*params
;
8714 params
= IF_DEF_PARAMS(ifp
);
8716 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8717 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8719 "Please specify interface address by A.B.C.D\n");
8720 return CMD_WARNING_CONFIG_FAILED
;
8723 params
= ospf_lookup_if_params(ifp
, addr
);
8728 UNSET_IF_PARAM(params
, retransmit_interval
);
8729 params
->retransmit_interval
= OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
8731 if (params
!= IF_DEF_PARAMS(ifp
)) {
8732 ospf_free_if_params(ifp
, addr
);
8733 ospf_if_update_params(ifp
, addr
);
8739 DEFUN_HIDDEN (no_ospf_retransmit_interval
,
8740 no_ospf_retransmit_interval_cmd
,
8741 "no ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8743 "OSPF interface commands\n"
8744 "Time between retransmitting lost link state advertisements\n"
8746 "Address of interface\n")
8748 return no_ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
8751 DEFUN (ip_ospf_transmit_delay
,
8752 ip_ospf_transmit_delay_addr_cmd
,
8753 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
8755 "OSPF interface commands\n"
8756 "Link state transmit delay\n"
8758 "Address of interface\n")
8760 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8763 struct in_addr addr
;
8764 struct ospf_if_params
*params
;
8766 params
= IF_DEF_PARAMS(ifp
);
8767 argv_find(argv
, argc
, "(1-65535)", &idx
);
8768 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
8770 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8771 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8773 "Please specify interface address by A.B.C.D\n");
8774 return CMD_WARNING_CONFIG_FAILED
;
8777 params
= ospf_get_if_params(ifp
, addr
);
8778 ospf_if_update_params(ifp
, addr
);
8781 SET_IF_PARAM(params
, transmit_delay
);
8782 params
->transmit_delay
= seconds
;
8787 DEFUN_HIDDEN (ospf_transmit_delay
,
8788 ospf_transmit_delay_cmd
,
8789 "ospf transmit-delay (1-65535) [A.B.C.D]",
8790 "OSPF interface commands\n"
8791 "Link state transmit delay\n"
8793 "Address of interface\n")
8795 return ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
8798 DEFUN (no_ip_ospf_transmit_delay
,
8799 no_ip_ospf_transmit_delay_addr_cmd
,
8800 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
8803 "OSPF interface commands\n"
8804 "Link state transmit delay\n"
8806 "Address of interface\n")
8808 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8810 struct in_addr addr
;
8811 struct ospf_if_params
*params
;
8813 params
= IF_DEF_PARAMS(ifp
);
8815 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8816 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8818 "Please specify interface address by A.B.C.D\n");
8819 return CMD_WARNING_CONFIG_FAILED
;
8822 params
= ospf_lookup_if_params(ifp
, addr
);
8827 UNSET_IF_PARAM(params
, transmit_delay
);
8828 params
->transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
8830 if (params
!= IF_DEF_PARAMS(ifp
)) {
8831 ospf_free_if_params(ifp
, addr
);
8832 ospf_if_update_params(ifp
, addr
);
8839 DEFUN_HIDDEN (no_ospf_transmit_delay
,
8840 no_ospf_transmit_delay_cmd
,
8841 "no ospf transmit-delay [(1-65535) [A.B.C.D]]",
8843 "OSPF interface commands\n"
8844 "Link state transmit delay\n"
8846 "Address of interface\n")
8848 return no_ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
8851 DEFUN (ip_ospf_area
,
8853 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]",
8855 "OSPF interface commands\n"
8857 "Enable OSPF on this interface\n"
8858 "OSPF area ID in IP address format\n"
8859 "OSPF area ID as a decimal value\n"
8860 "Address of interface\n")
8862 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8865 struct in_addr area_id
;
8866 struct in_addr addr
;
8867 struct ospf_if_params
*params
= NULL
;
8868 struct route_node
*rn
;
8869 struct ospf
*ospf
= NULL
;
8870 unsigned short instance
= 0;
8874 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
8875 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
8877 argv_find(argv
, argc
, "area", &idx
);
8878 areaid
= argv
[idx
+ 1]->arg
;
8881 ospf
= ifp
->vrf
->info
;
8883 ospf
= ospf_lookup_instance(instance
);
8885 if (instance
&& instance
!= ospf_instance
) {
8887 * At this point we know we have received
8888 * an instance and there is no ospf instance
8889 * associated with it. This means we are
8890 * in a situation where we have an
8891 * ospf command that is setup for a different
8892 * process(instance). We need to safely
8893 * remove the command from ourselves and
8894 * allow the other instance(process) handle
8895 * the configuration command.
8899 params
= IF_DEF_PARAMS(ifp
);
8900 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8901 UNSET_IF_PARAM(params
, if_area
);
8905 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
; rn
= route_next(rn
))
8906 if ((params
= rn
->info
) && OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8907 UNSET_IF_PARAM(params
, if_area
);
8912 ospf
= ifp
->vrf
->info
;
8914 ospf_interface_area_unset(ospf
, ifp
);
8917 return CMD_NOT_MY_INSTANCE
;
8920 ret
= str2area_id(areaid
, &area_id
, &format
);
8922 vty_out(vty
, "Please specify area by A.B.C.D|<0-4294967295>\n");
8923 return CMD_WARNING_CONFIG_FAILED
;
8925 if (memcmp(ifp
->name
, "VLINK", 5) == 0) {
8926 vty_out(vty
, "Cannot enable OSPF on a virtual link.\n");
8927 return CMD_WARNING_CONFIG_FAILED
;
8931 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
)) {
8932 if (rn
->info
!= NULL
) {
8934 "Please remove all network commands first.\n");
8935 return CMD_WARNING_CONFIG_FAILED
;
8940 params
= IF_DEF_PARAMS(ifp
);
8941 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)
8942 && !IPV4_ADDR_SAME(¶ms
->if_area
, &area_id
)) {
8944 "Must remove previous area config before changing ospf area \n");
8945 return CMD_WARNING_CONFIG_FAILED
;
8948 // Check if we have an address arg and proccess it
8949 if (argc
== idx
+ 3) {
8950 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
8952 "Please specify Intf Address by A.B.C.D\n");
8953 return CMD_WARNING_CONFIG_FAILED
;
8955 // update/create address-level params
8956 params
= ospf_get_if_params((ifp
), (addr
));
8957 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8958 if (!IPV4_ADDR_SAME(¶ms
->if_area
, &area_id
)) {
8960 "Must remove previous area/address config before changing ospf area\n");
8961 return CMD_WARNING_CONFIG_FAILED
;
8965 ospf_if_update_params((ifp
), (addr
));
8968 /* enable ospf on this interface with area_id */
8970 SET_IF_PARAM(params
, if_area
);
8971 params
->if_area
= area_id
;
8972 params
->if_area_id_fmt
= format
;
8976 ospf_interface_area_set(ospf
, ifp
);
8981 DEFUN (no_ip_ospf_area
,
8982 no_ip_ospf_area_cmd
,
8983 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]",
8986 "OSPF interface commands\n"
8988 "Disable OSPF on this interface\n"
8989 "OSPF area ID in IP address format\n"
8990 "OSPF area ID as a decimal value\n"
8991 "Address of interface\n")
8993 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8996 struct ospf_if_params
*params
;
8997 unsigned short instance
= 0;
8998 struct in_addr addr
;
8999 struct in_addr area_id
;
9001 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
9002 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
9005 ospf
= ifp
->vrf
->info
;
9007 ospf
= ospf_lookup_instance(instance
);
9009 if (instance
&& instance
!= ospf_instance
)
9010 return CMD_NOT_MY_INSTANCE
;
9012 argv_find(argv
, argc
, "area", &idx
);
9014 // Check if we have an address arg and proccess it
9015 if (argc
== idx
+ 3) {
9016 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
9018 "Please specify Intf Address by A.B.C.D\n");
9019 return CMD_WARNING_CONFIG_FAILED
;
9021 params
= ospf_lookup_if_params(ifp
, addr
);
9022 if ((params
) == NULL
)
9025 params
= IF_DEF_PARAMS(ifp
);
9027 area_id
= params
->if_area
;
9028 if (!OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
9030 "Can't find specified interface area configuration.\n");
9031 return CMD_WARNING_CONFIG_FAILED
;
9034 UNSET_IF_PARAM(params
, if_area
);
9035 if (params
!= IF_DEF_PARAMS((ifp
))) {
9036 ospf_free_if_params((ifp
), (addr
));
9037 ospf_if_update_params((ifp
), (addr
));
9041 ospf_interface_area_unset(ospf
, ifp
);
9042 ospf_area_check_free(ospf
, area_id
);
9048 DEFUN (ip_ospf_passive
,
9049 ip_ospf_passive_cmd
,
9050 "ip ospf passive [A.B.C.D]",
9052 "OSPF interface commands\n"
9053 "Suppress routing updates on an interface\n"
9054 "Address of interface\n")
9056 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9058 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
9059 struct ospf_if_params
*params
;
9063 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9066 "Please specify interface address by A.B.C.D\n");
9067 return CMD_WARNING_CONFIG_FAILED
;
9069 params
= ospf_get_if_params(ifp
, addr
);
9070 ospf_if_update_params(ifp
, addr
);
9072 params
= IF_DEF_PARAMS(ifp
);
9075 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_PASSIVE
);
9080 DEFUN (no_ip_ospf_passive
,
9081 no_ip_ospf_passive_cmd
,
9082 "no ip ospf passive [A.B.C.D]",
9085 "OSPF interface commands\n"
9086 "Enable routing updates on an interface\n"
9087 "Address of interface\n")
9089 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9091 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
9092 struct ospf_if_params
*params
;
9096 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9099 "Please specify interface address by A.B.C.D\n");
9100 return CMD_WARNING_CONFIG_FAILED
;
9102 params
= ospf_lookup_if_params(ifp
, addr
);
9106 params
= IF_DEF_PARAMS(ifp
);
9109 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_ACTIVE
);
9114 DEFUN (ospf_redistribute_source
,
9115 ospf_redistribute_source_cmd
,
9116 "redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9118 FRR_REDIST_HELP_STR_OSPFD
9119 "Metric for redistributed routes\n"
9120 "OSPF default metric\n"
9121 "OSPF exterior metric type for redistributed routes\n"
9122 "Set OSPF External Type 1/2 metrics\n"
9123 "Route map reference\n"
9124 "Pointer to route-map entries\n")
9126 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9127 int idx_protocol
= 1;
9131 struct ospf_redist
*red
;
9133 bool update
= false;
9135 /* Get distribute source. */
9136 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
9138 return CMD_WARNING_CONFIG_FAILED
;
9140 /* Get metric value. */
9141 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
9142 if (!str2metric(argv
[idx
]->arg
, &metric
))
9143 return CMD_WARNING_CONFIG_FAILED
;
9146 /* Get metric type. */
9147 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
9148 if (!str2metric_type(argv
[idx
]->arg
, &type
))
9149 return CMD_WARNING_CONFIG_FAILED
;
9153 red
= ospf_redist_lookup(ospf
, source
, 0);
9155 red
= ospf_redist_add(ospf
, source
, 0);
9160 if (argv_find(argv
, argc
, "route-map", &idx
)) {
9161 ospf_routemap_set(red
, argv
[idx
+ 1]->arg
);
9163 ospf_routemap_unset(red
);
9166 return ospf_redistribute_update(ospf
, red
, source
, 0, type
,
9169 return ospf_redistribute_set(ospf
, red
, source
, 0, type
,
9173 DEFUN (no_ospf_redistribute_source
,
9174 no_ospf_redistribute_source_cmd
,
9175 "no redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9178 FRR_REDIST_HELP_STR_OSPFD
9179 "Metric for redistributed routes\n"
9180 "OSPF default metric\n"
9181 "OSPF exterior metric type for redistributed routes\n"
9182 "Set OSPF External Type 1/2 metrics\n"
9183 "Route map reference\n"
9184 "Pointer to route-map entries\n")
9186 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9187 int idx_protocol
= 2;
9189 struct ospf_redist
*red
;
9191 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
9193 return CMD_WARNING_CONFIG_FAILED
;
9195 red
= ospf_redist_lookup(ospf
, source
, 0);
9199 ospf_routemap_unset(red
);
9200 ospf_redist_del(ospf
, source
, 0);
9202 return ospf_redistribute_unset(ospf
, source
, 0);
9205 DEFUN (ospf_redistribute_instance_source
,
9206 ospf_redistribute_instance_source_cmd
,
9207 "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9209 "Open Shortest Path First\n"
9210 "Non-main Kernel Routing Table\n"
9211 "Instance ID/Table ID\n"
9212 "Metric for redistributed routes\n"
9213 "OSPF default metric\n"
9214 "OSPF exterior metric type for redistributed routes\n"
9215 "Set OSPF External Type 1/2 metrics\n"
9216 "Route map reference\n"
9217 "Pointer to route-map entries\n")
9219 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9220 int idx_ospf_table
= 1;
9226 unsigned short instance
;
9227 struct ospf_redist
*red
;
9228 bool update
= false;
9230 source
= proto_redistnum(AFI_IP
, argv
[idx_ospf_table
]->text
);
9233 vty_out(vty
, "Unknown instance redistribution\n");
9234 return CMD_WARNING_CONFIG_FAILED
;
9237 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9239 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
9241 "Instance redistribution in non-instanced OSPF not allowed\n");
9242 return CMD_WARNING_CONFIG_FAILED
;
9245 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
9246 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
9247 return CMD_WARNING_CONFIG_FAILED
;
9250 /* Get metric value. */
9251 if (argv_find(argv
, argc
, "metric", &idx
))
9252 if (!str2metric(argv
[idx
+ 1]->arg
, &metric
))
9253 return CMD_WARNING_CONFIG_FAILED
;
9256 /* Get metric type. */
9257 if (argv_find(argv
, argc
, "metric-type", &idx
))
9258 if (!str2metric_type(argv
[idx
+ 1]->arg
, &type
))
9259 return CMD_WARNING_CONFIG_FAILED
;
9261 red
= ospf_redist_lookup(ospf
, source
, instance
);
9263 red
= ospf_redist_add(ospf
, source
, instance
);
9268 if (argv_find(argv
, argc
, "route-map", &idx
))
9269 ospf_routemap_set(red
, argv
[idx
+ 1]->arg
);
9271 ospf_routemap_unset(red
);
9274 return ospf_redistribute_update(ospf
, red
, source
, instance
,
9277 return ospf_redistribute_set(ospf
, red
, source
, instance
, type
,
9281 DEFUN (no_ospf_redistribute_instance_source
,
9282 no_ospf_redistribute_instance_source_cmd
,
9283 "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9286 "Open Shortest Path First\n"
9287 "Non-main Kernel Routing Table\n"
9288 "Instance ID/Table Id\n"
9289 "Metric for redistributed routes\n"
9290 "OSPF default metric\n"
9291 "OSPF exterior metric type for redistributed routes\n"
9292 "Set OSPF External Type 1/2 metrics\n"
9293 "Route map reference\n"
9294 "Pointer to route-map entries\n")
9296 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9297 int idx_ospf_table
= 2;
9299 unsigned int instance
;
9300 struct ospf_redist
*red
;
9303 if (strncmp(argv
[idx_ospf_table
]->arg
, "o", 1) == 0)
9304 source
= ZEBRA_ROUTE_OSPF
;
9306 source
= ZEBRA_ROUTE_TABLE
;
9308 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9310 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
9312 "Instance redistribution in non-instanced OSPF not allowed\n");
9313 return CMD_WARNING_CONFIG_FAILED
;
9316 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
9317 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
9318 return CMD_WARNING_CONFIG_FAILED
;
9321 red
= ospf_redist_lookup(ospf
, source
, instance
);
9325 ospf_routemap_unset(red
);
9326 ospf_redist_del(ospf
, source
, instance
);
9328 return ospf_redistribute_unset(ospf
, source
, instance
);
9331 DEFUN (ospf_distribute_list_out
,
9332 ospf_distribute_list_out_cmd
,
9333 "distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD
,
9334 "Filter networks in routing updates\n"
9335 "Access-list name\n"
9337 FRR_REDIST_HELP_STR_OSPFD
)
9339 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9343 char *proto
= argv
[argc
- 1]->text
;
9345 /* Get distribute source. */
9346 source
= proto_redistnum(AFI_IP
, proto
);
9348 return CMD_WARNING_CONFIG_FAILED
;
9350 return ospf_distribute_list_out_set(ospf
, source
, argv
[idx_word
]->arg
);
9353 DEFUN (no_ospf_distribute_list_out
,
9354 no_ospf_distribute_list_out_cmd
,
9355 "no distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD
,
9357 "Filter networks in routing updates\n"
9358 "Access-list name\n"
9360 FRR_REDIST_HELP_STR_OSPFD
)
9362 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9366 char *proto
= argv
[argc
- 1]->text
;
9367 source
= proto_redistnum(AFI_IP
, proto
);
9369 return CMD_WARNING_CONFIG_FAILED
;
9371 return ospf_distribute_list_out_unset(ospf
, source
,
9372 argv
[idx_word
]->arg
);
9375 /* Default information originate. */
9376 DEFUN (ospf_default_information_originate
,
9377 ospf_default_information_originate_cmd
,
9378 "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9379 "Control distribution of default information\n"
9380 "Distribute a default route\n"
9381 "Always advertise default route\n"
9382 "OSPF default metric\n"
9384 "OSPF metric type for default routes\n"
9385 "Set OSPF External Type 1/2 metrics\n"
9386 "Route map reference\n"
9387 "Pointer to route-map entries\n")
9389 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9390 int default_originate
= DEFAULT_ORIGINATE_ZEBRA
;
9393 struct ospf_redist
*red
;
9395 int cur_originate
= ospf
->default_originate
;
9396 bool sameRtmap
= false;
9399 red
= ospf_redist_add(ospf
, DEFAULT_ROUTE
, 0);
9401 /* Check whether "always" was specified */
9402 if (argv_find(argv
, argc
, "always", &idx
))
9403 default_originate
= DEFAULT_ORIGINATE_ALWAYS
;
9405 /* Get metric value */
9406 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
9407 if (!str2metric(argv
[idx
]->arg
, &metric
))
9408 return CMD_WARNING_CONFIG_FAILED
;
9411 /* Get metric type. */
9412 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
9413 if (!str2metric_type(argv
[idx
]->arg
, &type
))
9414 return CMD_WARNING_CONFIG_FAILED
;
9418 if (argv_find(argv
, argc
, "route-map", &idx
))
9419 rtmap
= argv
[idx
+ 1]->arg
;
9421 /* To check if user is providing same route map */
9422 if ((!rtmap
&& !ROUTEMAP_NAME(red
)) ||
9423 (rtmap
&& ROUTEMAP_NAME(red
) &&
9424 (strcmp(rtmap
, ROUTEMAP_NAME(red
)) == 0)))
9427 /* Don't allow if the same lsa is already originated. */
9429 && (red
->dmetric
.type
== type
)
9430 && (red
->dmetric
.value
== metric
)
9431 && (cur_originate
== default_originate
))
9434 /* Updating Metric details */
9435 red
->dmetric
.type
= type
;
9436 red
->dmetric
.value
= metric
;
9438 /* updating route map details */
9440 ospf_routemap_set(red
, rtmap
);
9442 ospf_routemap_unset(red
);
9444 return ospf_redistribute_default_set(ospf
, default_originate
, type
,
9448 DEFUN (no_ospf_default_information_originate
,
9449 no_ospf_default_information_originate_cmd
,
9450 "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9452 "Control distribution of default information\n"
9453 "Distribute a default route\n"
9454 "Always advertise default route\n"
9455 "OSPF default metric\n"
9457 "OSPF metric type for default routes\n"
9458 "Set OSPF External Type 1/2 metrics\n"
9459 "Route map reference\n"
9460 "Pointer to route-map entries\n")
9462 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9463 struct ospf_redist
*red
;
9465 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
9469 ospf_routemap_unset(red
);
9470 ospf_redist_del(ospf
, DEFAULT_ROUTE
, 0);
9472 return ospf_redistribute_default_set(ospf
, DEFAULT_ORIGINATE_NONE
,
9476 DEFUN (ospf_default_metric
,
9477 ospf_default_metric_cmd
,
9478 "default-metric (0-16777214)",
9479 "Set metric of redistributed routes\n"
9482 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9486 if (!str2metric(argv
[idx_number
]->arg
, &metric
))
9487 return CMD_WARNING_CONFIG_FAILED
;
9489 ospf
->default_metric
= metric
;
9494 DEFUN (no_ospf_default_metric
,
9495 no_ospf_default_metric_cmd
,
9496 "no default-metric [(0-16777214)]",
9498 "Set metric of redistributed routes\n"
9501 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9503 ospf
->default_metric
= -1;
9509 DEFUN (ospf_distance
,
9512 "Administrative distance\n"
9513 "OSPF Administrative distance\n")
9515 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9519 distance
= atoi(argv
[idx_number
]->arg
);
9520 if (ospf
->distance_all
!= distance
) {
9521 ospf
->distance_all
= distance
;
9522 ospf_restart_spf(ospf
);
9528 DEFUN (no_ospf_distance
,
9529 no_ospf_distance_cmd
,
9530 "no distance (1-255)",
9532 "Administrative distance\n"
9533 "OSPF Administrative distance\n")
9535 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9537 if (ospf
->distance_all
) {
9538 ospf
->distance_all
= 0;
9539 ospf_restart_spf(ospf
);
9545 DEFUN (no_ospf_distance_ospf
,
9546 no_ospf_distance_ospf_cmd
,
9547 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
9549 "Administrative distance\n"
9550 "OSPF administrative distance\n"
9551 "Intra-area routes\n"
9552 "Distance for intra-area routes\n"
9553 "Inter-area routes\n"
9554 "Distance for inter-area routes\n"
9556 "Distance for external routes\n")
9558 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9561 if (argv_find(argv
, argc
, "intra-area", &idx
) || argc
== 3)
9562 idx
= ospf
->distance_intra
= 0;
9563 if (argv_find(argv
, argc
, "inter-area", &idx
) || argc
== 3)
9564 idx
= ospf
->distance_inter
= 0;
9565 if (argv_find(argv
, argc
, "external", &idx
) || argc
== 3)
9566 ospf
->distance_external
= 0;
9571 DEFUN (ospf_distance_ospf
,
9572 ospf_distance_ospf_cmd
,
9573 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
9574 "Administrative distance\n"
9575 "OSPF administrative distance\n"
9576 "Intra-area routes\n"
9577 "Distance for intra-area routes\n"
9578 "Inter-area routes\n"
9579 "Distance for inter-area routes\n"
9581 "Distance for external routes\n")
9583 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9586 ospf
->distance_intra
= 0;
9587 ospf
->distance_inter
= 0;
9588 ospf
->distance_external
= 0;
9590 if (argv_find(argv
, argc
, "intra-area", &idx
))
9591 ospf
->distance_intra
= atoi(argv
[idx
+ 1]->arg
);
9593 if (argv_find(argv
, argc
, "inter-area", &idx
))
9594 ospf
->distance_inter
= atoi(argv
[idx
+ 1]->arg
);
9596 if (argv_find(argv
, argc
, "external", &idx
))
9597 ospf
->distance_external
= atoi(argv
[idx
+ 1]->arg
);
9602 DEFUN (ip_ospf_mtu_ignore
,
9603 ip_ospf_mtu_ignore_addr_cmd
,
9604 "ip ospf mtu-ignore [A.B.C.D]",
9606 "OSPF interface commands\n"
9607 "Disable MTU mismatch detection on this interface\n"
9608 "Address of interface\n")
9610 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9612 struct in_addr addr
;
9615 struct ospf_if_params
*params
;
9616 params
= IF_DEF_PARAMS(ifp
);
9619 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9622 "Please specify interface address by A.B.C.D\n");
9623 return CMD_WARNING_CONFIG_FAILED
;
9625 params
= ospf_get_if_params(ifp
, addr
);
9626 ospf_if_update_params(ifp
, addr
);
9628 params
->mtu_ignore
= 1;
9629 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
9630 SET_IF_PARAM(params
, mtu_ignore
);
9632 UNSET_IF_PARAM(params
, mtu_ignore
);
9633 if (params
!= IF_DEF_PARAMS(ifp
)) {
9634 ospf_free_if_params(ifp
, addr
);
9635 ospf_if_update_params(ifp
, addr
);
9641 DEFUN (no_ip_ospf_mtu_ignore
,
9642 no_ip_ospf_mtu_ignore_addr_cmd
,
9643 "no ip ospf mtu-ignore [A.B.C.D]",
9646 "OSPF interface commands\n"
9647 "Disable MTU mismatch detection on this interface\n"
9648 "Address of interface\n")
9650 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9652 struct in_addr addr
;
9655 struct ospf_if_params
*params
;
9656 params
= IF_DEF_PARAMS(ifp
);
9659 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9662 "Please specify interface address by A.B.C.D\n");
9663 return CMD_WARNING_CONFIG_FAILED
;
9665 params
= ospf_get_if_params(ifp
, addr
);
9666 ospf_if_update_params(ifp
, addr
);
9668 params
->mtu_ignore
= 0;
9669 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
9670 SET_IF_PARAM(params
, mtu_ignore
);
9672 UNSET_IF_PARAM(params
, mtu_ignore
);
9673 if (params
!= IF_DEF_PARAMS(ifp
)) {
9674 ospf_free_if_params(ifp
, addr
);
9675 ospf_if_update_params(ifp
, addr
);
9682 DEFUN (ospf_max_metric_router_lsa_admin
,
9683 ospf_max_metric_router_lsa_admin_cmd
,
9684 "max-metric router-lsa administrative",
9685 "OSPF maximum / infinite-distance metric\n"
9686 "Advertise own Router-LSA with infinite distance (stub router)\n"
9687 "Administratively applied, for an indefinite period\n")
9689 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9690 struct listnode
*ln
;
9691 struct ospf_area
*area
;
9693 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
9694 SET_FLAG(area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
);
9696 if (!CHECK_FLAG(area
->stub_router_state
,
9697 OSPF_AREA_IS_STUB_ROUTED
))
9698 ospf_router_lsa_update_area(area
);
9701 /* Allows for areas configured later to get the property */
9702 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
;
9707 DEFUN (no_ospf_max_metric_router_lsa_admin
,
9708 no_ospf_max_metric_router_lsa_admin_cmd
,
9709 "no max-metric router-lsa administrative",
9711 "OSPF maximum / infinite-distance metric\n"
9712 "Advertise own Router-LSA with infinite distance (stub router)\n"
9713 "Administratively applied, for an indefinite period\n")
9715 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9716 struct listnode
*ln
;
9717 struct ospf_area
*area
;
9719 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
9720 UNSET_FLAG(area
->stub_router_state
,
9721 OSPF_AREA_ADMIN_STUB_ROUTED
);
9723 /* Don't trample on the start-up stub timer */
9724 if (CHECK_FLAG(area
->stub_router_state
,
9725 OSPF_AREA_IS_STUB_ROUTED
)
9726 && !area
->t_stub_router
) {
9727 UNSET_FLAG(area
->stub_router_state
,
9728 OSPF_AREA_IS_STUB_ROUTED
);
9729 ospf_router_lsa_update_area(area
);
9732 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET
;
9736 DEFUN (ospf_max_metric_router_lsa_startup
,
9737 ospf_max_metric_router_lsa_startup_cmd
,
9738 "max-metric router-lsa on-startup (5-86400)",
9739 "OSPF maximum / infinite-distance metric\n"
9740 "Advertise own Router-LSA with infinite distance (stub router)\n"
9741 "Automatically advertise stub Router-LSA on startup of OSPF\n"
9742 "Time (seconds) to advertise self as stub-router\n")
9744 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9746 unsigned int seconds
;
9749 vty_out(vty
, "%% Must supply stub-router period\n");
9750 return CMD_WARNING_CONFIG_FAILED
;
9753 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9755 ospf
->stub_router_startup_time
= seconds
;
9760 DEFUN (no_ospf_max_metric_router_lsa_startup
,
9761 no_ospf_max_metric_router_lsa_startup_cmd
,
9762 "no max-metric router-lsa on-startup [(5-86400)]",
9764 "OSPF maximum / infinite-distance metric\n"
9765 "Advertise own Router-LSA with infinite distance (stub router)\n"
9766 "Automatically advertise stub Router-LSA on startup of OSPF\n"
9767 "Time (seconds) to advertise self as stub-router\n")
9769 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9770 struct listnode
*ln
;
9771 struct ospf_area
*area
;
9773 ospf
->stub_router_startup_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
9775 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
9776 SET_FLAG(area
->stub_router_state
,
9777 OSPF_AREA_WAS_START_STUB_ROUTED
);
9778 THREAD_OFF(area
->t_stub_router
);
9780 /* Don't trample on admin stub routed */
9781 if (!CHECK_FLAG(area
->stub_router_state
,
9782 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
9783 UNSET_FLAG(area
->stub_router_state
,
9784 OSPF_AREA_IS_STUB_ROUTED
);
9785 ospf_router_lsa_update_area(area
);
9792 DEFUN (ospf_max_metric_router_lsa_shutdown
,
9793 ospf_max_metric_router_lsa_shutdown_cmd
,
9794 "max-metric router-lsa on-shutdown (5-100)",
9795 "OSPF maximum / infinite-distance metric\n"
9796 "Advertise own Router-LSA with infinite distance (stub router)\n"
9797 "Advertise stub-router prior to full shutdown of OSPF\n"
9798 "Time (seconds) to wait till full shutdown\n")
9800 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9802 unsigned int seconds
;
9805 vty_out(vty
, "%% Must supply stub-router shutdown period\n");
9806 return CMD_WARNING_CONFIG_FAILED
;
9809 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9811 ospf
->stub_router_shutdown_time
= seconds
;
9816 DEFUN (no_ospf_max_metric_router_lsa_shutdown
,
9817 no_ospf_max_metric_router_lsa_shutdown_cmd
,
9818 "no max-metric router-lsa on-shutdown [(5-100)]",
9820 "OSPF maximum / infinite-distance metric\n"
9821 "Advertise own Router-LSA with infinite distance (stub router)\n"
9822 "Advertise stub-router prior to full shutdown of OSPF\n"
9823 "Time (seconds) to wait till full shutdown\n")
9825 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9827 ospf
->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
9832 DEFUN (ospf_proactive_arp
,
9833 ospf_proactive_arp_cmd
,
9835 "Allow sending ARP requests proactively\n")
9837 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9839 ospf
->proactive_arp
= true;
9844 DEFUN (no_ospf_proactive_arp
,
9845 no_ospf_proactive_arp_cmd
,
9848 "Disallow sending ARP requests proactively\n")
9850 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9852 ospf
->proactive_arp
= false;
9857 /* Graceful Restart HELPER Commands */
9858 DEFPY(ospf_gr_helper_enable
, ospf_gr_helper_enable_cmd
,
9859 "graceful-restart helper enable [A.B.C.D$address]",
9860 "OSPF Graceful Restart\n"
9862 "Enable Helper support\n"
9863 "Advertising Router-ID\n")
9865 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9868 ospf_gr_helper_support_set_per_routerid(ospf
, &address
,
9873 ospf_gr_helper_support_set(ospf
, OSPF_GR_TRUE
);
9878 DEFPY(no_ospf_gr_helper_enable
,
9879 no_ospf_gr_helper_enable_cmd
,
9880 "no graceful-restart helper enable [A.B.C.D$address]",
9882 "OSPF Graceful Restart\n"
9884 "Enable Helper support\n"
9885 "Advertising Router-ID\n")
9887 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9890 ospf_gr_helper_support_set_per_routerid(ospf
, &address
,
9895 ospf_gr_helper_support_set(ospf
, OSPF_GR_FALSE
);
9899 DEFPY(ospf_gr_helper_enable_lsacheck
,
9900 ospf_gr_helper_enable_lsacheck_cmd
,
9901 "graceful-restart helper strict-lsa-checking",
9902 "OSPF Graceful Restart\n"
9904 "Enable strict LSA check\n")
9906 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9908 ospf_gr_helper_lsa_check_set(ospf
, OSPF_GR_TRUE
);
9912 DEFPY(no_ospf_gr_helper_enable_lsacheck
,
9913 no_ospf_gr_helper_enable_lsacheck_cmd
,
9914 "no graceful-restart helper strict-lsa-checking",
9916 "OSPF Graceful Restart\n"
9918 "Disable strict LSA check\n")
9920 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9922 ospf_gr_helper_lsa_check_set(ospf
, OSPF_GR_FALSE
);
9926 DEFPY(ospf_gr_helper_supported_grace_time
,
9927 ospf_gr_helper_supported_grace_time_cmd
,
9928 "graceful-restart helper supported-grace-time (10-1800)$interval",
9929 "OSPF Graceful Restart\n"
9931 "Supported grace timer\n"
9932 "Grace interval(in seconds)\n")
9934 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9936 ospf_gr_helper_supported_gracetime_set(ospf
, interval
);
9940 DEFPY(no_ospf_gr_helper_supported_grace_time
,
9941 no_ospf_gr_helper_supported_grace_time_cmd
,
9942 "no graceful-restart helper supported-grace-time (10-1800)$interval",
9944 "OSPF Graceful Restart\n"
9946 "Supported grace timer\n"
9947 "Grace interval(in seconds)\n")
9949 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9951 ospf_gr_helper_supported_gracetime_set(ospf
, OSPF_MAX_GRACE_INTERVAL
);
9955 DEFPY(ospf_gr_helper_planned_only
,
9956 ospf_gr_helper_planned_only_cmd
,
9957 "graceful-restart helper planned-only",
9958 "OSPF Graceful Restart\n"
9960 "Supported only planned restart\n")
9962 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9964 ospf_gr_helper_set_supported_planned_only_restart(ospf
, OSPF_GR_TRUE
);
9969 /* External Route Aggregation */
9970 DEFUN (ospf_external_route_aggregation
,
9971 ospf_external_route_aggregation_cmd
,
9972 "summary-address A.B.C.D/M [tag (1-4294967295)]",
9973 "External summary address\n"
9974 "Summary address prefix\n"
9976 "Router tag value\n")
9978 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9979 struct prefix_ipv4 p
;
9981 route_tag_t tag
= 0;
9982 int ret
= OSPF_SUCCESS
;
9984 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
9986 if (is_default_prefix4(&p
)) {
9988 "Default address shouldn't be configured as summary address.\n");
9992 /* Apply mask for given prefix. */
9995 if (!is_valid_summary_addr(&p
)) {
9996 vty_out(vty
, "Not a valid summary address.\n");
9997 return CMD_WARNING_CONFIG_FAILED
;
10001 tag
= strtoul(argv
[idx
+ 2]->arg
, NULL
, 10);
10003 ret
= ospf_asbr_external_aggregator_set(ospf
, &p
, tag
);
10004 if (ret
== OSPF_INVALID
)
10005 vty_out(vty
, "Invalid configuration!!\n");
10007 return CMD_SUCCESS
;
10010 DEFUN (no_ospf_external_route_aggregation
,
10011 no_ospf_external_route_aggregation_cmd
,
10012 "no summary-address A.B.C.D/M [tag (1-4294967295)]",
10014 "External summary address\n"
10015 "Summary address prefix\n"
10017 "Router tag value\n")
10019 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10020 struct prefix_ipv4 p
;
10022 route_tag_t tag
= 0;
10023 int ret
= OSPF_SUCCESS
;
10025 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
10027 if (is_default_prefix4(&p
)) {
10029 "Default address shouldn't be configured as summary address.\n");
10030 return CMD_SUCCESS
;
10033 /* Apply mask for given prefix. */
10036 if (!is_valid_summary_addr(&p
)) {
10037 vty_out(vty
, "Not a valid summary address.\n");
10038 return CMD_WARNING_CONFIG_FAILED
;
10042 tag
= strtoul(argv
[idx
+ 2]->arg
, NULL
, 10);
10044 ret
= ospf_asbr_external_aggregator_unset(ospf
, &p
, tag
);
10045 if (ret
== OSPF_INVALID
)
10046 vty_out(vty
, "Invalid configuration!!\n");
10048 return CMD_SUCCESS
;
10051 DEFPY(no_ospf_gr_helper_planned_only
,
10052 no_ospf_gr_helper_planned_only_cmd
,
10053 "no graceful-restart helper planned-only",
10055 "OSPF Graceful Restart\n"
10057 "Supported only for planned restart\n")
10059 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10061 ospf_gr_helper_set_supported_planned_only_restart(ospf
, OSPF_GR_FALSE
);
10063 return CMD_SUCCESS
;
10066 static int ospf_print_vty_helper_dis_rtr_walkcb(struct hash_bucket
*bucket
,
10069 struct advRtr
*rtr
= bucket
->data
;
10070 struct vty
*vty
= (struct vty
*)arg
;
10071 static unsigned int count
;
10073 vty_out(vty
, "%-6pI4,", &rtr
->advRtrAddr
);
10076 if (count
% 5 == 0)
10077 vty_out(vty
, "\n");
10079 return HASHWALK_CONTINUE
;
10082 static int ospf_print_json_helper_enabled_rtr_walkcb(struct hash_bucket
*bucket
,
10085 struct advRtr
*rtr
= bucket
->data
;
10086 struct json_object
*json_rid_array
= arg
;
10087 struct json_object
*json_rid
;
10089 json_rid
= json_object_new_object();
10091 json_object_string_addf(json_rid
, "routerId", "%pI4", &rtr
->advRtrAddr
);
10092 json_object_array_add(json_rid_array
, json_rid
);
10094 return HASHWALK_CONTINUE
;
10097 static int ospf_show_gr_helper_details(struct vty
*vty
, struct ospf
*ospf
,
10098 uint8_t use_vrf
, json_object
*json
,
10099 bool uj
, bool detail
)
10101 struct listnode
*node
;
10102 struct ospf_interface
*oi
;
10103 char buf
[PREFIX_STRLEN
];
10104 json_object
*json_vrf
= NULL
;
10108 json_vrf
= json_object_new_object();
10113 if (ospf
->instance
) {
10115 json_object_int_add(json
, "ospfInstance",
10118 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
10121 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
10125 json_object_object_add(json
, ospf_get_name(ospf
),
10128 vty_out(vty
, "\n");
10130 /* Show Router ID. */
10132 json_object_string_add(json_vrf
, "routerId",
10133 inet_ntop(AF_INET
, &ospf
->router_id
,
10134 buf
, sizeof(buf
)));
10136 vty_out(vty
, "\n OSPF Router with ID (%pI4)\n\n",
10142 if (ospf
->is_helper_supported
)
10144 " Graceful restart helper support enabled.\n");
10147 " Graceful restart helper support disabled.\n");
10149 if (ospf
->strict_lsa_check
)
10150 vty_out(vty
, " Strict LSA check is enabled.\n");
10152 vty_out(vty
, " Strict LSA check is disabled.\n");
10154 if (ospf
->only_planned_restart
)
10156 " Helper supported for planned restarts only.\n");
10159 " Helper supported for Planned and Unplanned Restarts.\n");
10162 " Supported Graceful restart interval: %d(in seconds).\n",
10163 ospf
->supported_grace_time
);
10165 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf
)) {
10166 vty_out(vty
, " Enable Router list:\n");
10168 hash_walk(ospf
->enable_rtr_list
,
10169 ospf_print_vty_helper_dis_rtr_walkcb
, vty
);
10170 vty_out(vty
, "\n\n");
10173 if (ospf
->last_exit_reason
!= OSPF_GR_HELPER_EXIT_NONE
) {
10174 vty_out(vty
, " Last Helper exit Reason :%s\n",
10175 ospf_exit_reason2str(ospf
->last_exit_reason
));
10178 if (ospf
->active_restarter_cnt
)
10180 " Number of Active neighbours in graceful restart: %d\n",
10181 ospf
->active_restarter_cnt
);
10183 vty_out(vty
, "\n");
10186 json_object_string_add(
10187 json_vrf
, "helperSupport",
10188 (ospf
->is_helper_supported
) ? "Enabled" : "Disabled");
10189 json_object_string_add(json_vrf
, "strictLsaCheck",
10190 (ospf
->strict_lsa_check
) ? "Enabled"
10192 json_object_string_add(
10193 json_vrf
, "restartSupoort",
10194 (ospf
->only_planned_restart
)
10195 ? "Planned Restart only"
10196 : "Planned and Unplanned Restarts");
10198 json_object_int_add(json_vrf
, "supportedGracePeriod",
10199 ospf
->supported_grace_time
);
10201 #if CONFDATE > 20230131
10202 CPP_NOTICE("Remove JSON object commands with keys starting with capital")
10204 if (ospf
->last_exit_reason
!= OSPF_GR_HELPER_EXIT_NONE
) {
10205 json_object_string_add(
10206 json_vrf
, "LastExitReason",
10207 ospf_exit_reason2str(ospf
->last_exit_reason
));
10208 json_object_string_add(
10209 json_vrf
, "lastExitReason",
10210 ospf_exit_reason2str(ospf
->last_exit_reason
));
10213 if (ospf
->active_restarter_cnt
)
10214 json_object_int_add(json_vrf
, "activeRestarterCnt",
10215 ospf
->active_restarter_cnt
);
10217 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf
)) {
10218 struct json_object
*json_rid_array
=
10219 json_object_new_array();
10221 json_object_object_add(json_vrf
, "enabledRouterIds",
10224 hash_walk(ospf
->enable_rtr_list
,
10225 ospf_print_json_helper_enabled_rtr_walkcb
,
10233 json_object
*json_neighbors
= NULL
;
10235 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
10236 struct route_node
*rn
;
10237 struct ospf_neighbor
*nbr
;
10238 json_object
*json_neigh
;
10240 if (ospf_interface_neighbor_count(oi
) == 0)
10244 json_object_object_get_ex(json_vrf
, "Neighbors",
10246 json_object_object_get_ex(json_vrf
, "neighbors",
10248 if (!json_neighbors
) {
10250 json_object_new_object();
10251 json_object_object_add(json_vrf
,
10254 json_object_object_add(json_vrf
,
10260 for (rn
= route_top(oi
->nbrs
); rn
;
10261 rn
= route_next(rn
)) {
10268 if (!OSPF_GR_IS_ACTIVE_HELPER(nbr
))
10272 vty_out(vty
, " Neighbour %d :\n", cnt
);
10273 vty_out(vty
, " Address : %pI4\n",
10274 &nbr
->address
.u
.prefix4
);
10275 vty_out(vty
, " Routerid : %pI4\n",
10278 " Received Grace period : %d(in seconds).\n",
10279 nbr
->gr_helper_info
10280 .recvd_grace_period
);
10282 " Actual Grace period : %d(in seconds)\n",
10283 nbr
->gr_helper_info
10284 .actual_grace_period
);
10286 " Remaining GraceTime:%ld(in seconds).\n",
10287 thread_timer_remain_second(
10288 nbr
->gr_helper_info
10291 " Graceful Restart reason: %s.\n\n",
10292 ospf_restart_reason2str(
10293 nbr
->gr_helper_info
10294 .gr_restart_reason
));
10297 json_neigh
= json_object_new_object();
10298 json_object_string_add(
10299 json_neigh
, "srcAddr",
10300 inet_ntop(AF_INET
, &nbr
->src
,
10301 buf
, sizeof(buf
)));
10303 json_object_string_add(
10304 json_neigh
, "routerid",
10307 buf
, sizeof(buf
)));
10308 json_object_int_add(
10310 "recvdGraceInterval",
10311 nbr
->gr_helper_info
10312 .recvd_grace_period
);
10313 json_object_int_add(
10315 "actualGraceInterval",
10316 nbr
->gr_helper_info
10317 .actual_grace_period
);
10318 json_object_int_add(
10319 json_neigh
, "remainGracetime",
10320 thread_timer_remain_second(
10321 nbr
->gr_helper_info
10323 json_object_string_add(
10324 json_neigh
, "restartReason",
10325 ospf_restart_reason2str(
10326 nbr
->gr_helper_info
10327 .gr_restart_reason
));
10328 json_object_object_add(
10330 inet_ntop(AF_INET
, &nbr
->src
,
10337 return CMD_SUCCESS
;
10340 DEFUN (ospf_external_route_aggregation_no_adrvertise
,
10341 ospf_external_route_aggregation_no_adrvertise_cmd
,
10342 "summary-address A.B.C.D/M no-advertise",
10343 "External summary address\n"
10344 "Summary address prefix\n"
10345 "Don't advertise summary route \n")
10347 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10348 struct prefix_ipv4 p
;
10350 int ret
= OSPF_SUCCESS
;
10352 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
10354 if (is_default_prefix4(&p
)) {
10356 "Default address shouldn't be configured as summary address.\n");
10357 return CMD_SUCCESS
;
10360 /* Apply mask for given prefix. */
10363 if (!is_valid_summary_addr(&p
)) {
10364 vty_out(vty
, "Not a valid summary address.\n");
10365 return CMD_WARNING_CONFIG_FAILED
;
10368 ret
= ospf_asbr_external_rt_no_advertise(ospf
, &p
);
10369 if (ret
== OSPF_INVALID
)
10370 vty_out(vty
, "Invalid configuration!!\n");
10372 return CMD_SUCCESS
;
10375 DEFUN (no_ospf_external_route_aggregation_no_adrvertise
,
10376 no_ospf_external_route_aggregation_no_adrvertise_cmd
,
10377 "no summary-address A.B.C.D/M no-advertise",
10379 "External summary address\n"
10380 "Summary address prefix\n"
10381 "Advertise summary route to the AS \n")
10383 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10384 struct prefix_ipv4 p
;
10386 int ret
= OSPF_SUCCESS
;
10388 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
10390 if (is_default_prefix4(&p
)) {
10392 "Default address shouldn't be configured as summary address.\n");
10393 return CMD_SUCCESS
;
10396 /* Apply mask for given prefix. */
10399 if (!is_valid_summary_addr(&p
)) {
10400 vty_out(vty
, "Not a valid summary address.\n");
10401 return CMD_WARNING_CONFIG_FAILED
;
10404 ret
= ospf_asbr_external_rt_advertise(ospf
, &p
);
10405 if (ret
== OSPF_INVALID
)
10406 vty_out(vty
, "Invalid configuration!!\n");
10408 return CMD_SUCCESS
;
10411 DEFUN (ospf_route_aggregation_timer
,
10412 ospf_route_aggregation_timer_cmd
,
10413 "aggregation timer (5-1800)",
10414 "External route aggregation\n"
10415 "Delay timer (in seconds)\n"
10416 "Timer interval(in seconds)\n")
10418 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10419 uint16_t interval
= 0;
10421 interval
= strtoul(argv
[2]->arg
, NULL
, 10);
10423 ospf_external_aggregator_timer_set(ospf
, interval
);
10425 return CMD_SUCCESS
;
10428 DEFPY (show_ip_ospf_gr_helper
,
10429 show_ip_ospf_gr_helper_cmd
,
10430 "show ip ospf [vrf <NAME|all>] graceful-restart helper [detail] [json]",
10433 "OSPF information\n"
10436 "OSPF Graceful Restart\n"
10437 "Helper details in the router\n"
10438 "Detailed information\n"
10441 char *vrf_name
= NULL
;
10442 bool all_vrf
= false;
10443 int ret
= CMD_SUCCESS
;
10446 uint8_t use_vrf
= 0;
10447 bool uj
= use_json(argc
, argv
);
10448 struct ospf
*ospf
= NULL
;
10449 json_object
*json
= NULL
;
10450 struct listnode
*node
= NULL
;
10452 bool detail
= false;
10454 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
10456 if (argv_find(argv
, argc
, "detail", &idx
))
10460 json
= json_object_new_object();
10462 /* vrf input is provided */
10467 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
10468 if (!ospf
->oi_running
)
10471 ret
= ospf_show_gr_helper_details(
10472 vty
, ospf
, use_vrf
, json
, uj
, detail
);
10476 vty_json(vty
, json
);
10481 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
10483 if (ospf
== NULL
|| !ospf
->oi_running
) {
10486 vty_json(vty
, json
);
10489 "%% OSPF is not enabled in vrf %s\n",
10492 return CMD_SUCCESS
;
10497 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
10499 if (ospf
== NULL
|| !ospf
->oi_running
) {
10502 vty_json(vty
, json
);
10505 "%% OSPF is not enabled in vrf default\n");
10507 return CMD_SUCCESS
;
10510 ospf_show_gr_helper_details(vty
, ospf
, use_vrf
, json
, uj
,
10515 vty_json(vty
, json
);
10517 return CMD_SUCCESS
;
10519 /* Graceful Restart HELPER commands end */
10520 DEFUN (no_ospf_route_aggregation_timer
,
10521 no_ospf_route_aggregation_timer_cmd
,
10522 "no aggregation timer",
10524 "External route aggregation\n"
10527 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10529 ospf_external_aggregator_timer_set(ospf
, OSPF_EXTL_AGGR_DEFAULT_DELAY
);
10531 return CMD_SUCCESS
;
10534 /* External Route Aggregation End */
10536 static void config_write_stub_router(struct vty
*vty
, struct ospf
*ospf
)
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 if (ospf
->stub_router_admin_set
== OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
)
10545 vty_out(vty
, " max-metric router-lsa administrative\n");
10550 #if CONFDATE > 20230131
10551 CPP_NOTICE("Remove JSON object commands with keys containing whitespaces")
10553 static void show_ip_ospf_route_network(struct vty
*vty
, struct ospf
*ospf
,
10554 struct route_table
*rt
,
10557 struct route_node
*rn
;
10558 struct ospf_route
* or ;
10559 struct listnode
*pnode
, *pnnode
;
10560 struct ospf_path
*path
;
10561 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
10562 *json_nexthop
= NULL
;
10566 "============ OSPF network routing table ============\n");
10568 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
10569 char buf1
[PREFIX2STR_BUFFER
];
10571 if ((or = rn
->info
) == NULL
)
10574 prefix2str(&rn
->p
, buf1
, sizeof(buf1
));
10577 json_route
= json_object_new_object();
10578 json_object_object_add(json
, buf1
, json_route
);
10581 switch (or->path_type
) {
10582 case OSPF_PATH_INTER_AREA
:
10583 if (or->type
== OSPF_DESTINATION_NETWORK
) {
10585 json_object_string_add(json_route
,
10588 json_object_int_add(json_route
, "cost",
10590 json_object_string_addf(
10591 json_route
, "area", "%pI4",
10592 &or->u
.std
.area_id
);
10595 "N IA %-18s [%d] area: %pI4\n",
10597 &or->u
.std
.area_id
);
10599 } else if (or->type
== OSPF_DESTINATION_DISCARD
) {
10601 json_object_string_add(json_route
,
10606 "D IA %-18s Discard entry\n",
10611 case OSPF_PATH_INTRA_AREA
:
10613 json_object_string_add(json_route
, "routeType",
10615 json_object_int_add(json_route
, "cost",
10617 json_object_string_addf(json_route
, "area",
10619 &or->u
.std
.area_id
);
10621 vty_out(vty
, "N %-18s [%d] area: %pI4\n",
10623 &or->u
.std
.area_id
);
10630 if (or->type
== OSPF_DESTINATION_NETWORK
) {
10632 json_nexthop_array
= json_object_new_array();
10633 json_object_object_add(json_route
, "nexthops",
10634 json_nexthop_array
);
10637 for (ALL_LIST_ELEMENTS(or->paths
, pnode
, pnnode
,
10640 json_nexthop
= json_object_new_object();
10641 json_object_array_add(
10642 json_nexthop_array
,
10645 if (if_lookup_by_index(path
->ifindex
,
10648 if (path
->nexthop
.s_addr
10651 json_object_string_add(
10654 json_object_string_add(
10656 "directly attached to",
10660 json_object_string_add(
10662 "directlyAttachedTo",
10668 "%24s directly attached to %s\n",
10676 json_object_string_addf(
10680 json_object_string_add(
10688 "%24s via %pI4, %s\n",
10701 vty_out(vty
, "\n");
10704 static void show_ip_ospf_route_router(struct vty
*vty
, struct ospf
*ospf
,
10705 struct route_table
*rtrs
,
10708 struct route_node
*rn
;
10709 struct ospf_route
* or ;
10710 struct listnode
*pnode
;
10711 struct listnode
*node
;
10712 struct ospf_path
*path
;
10713 char buf
[PREFIX_STRLEN
];
10714 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
10715 *json_nexthop
= NULL
;
10718 vty_out(vty
, "============ OSPF %s table =============\n",
10719 ospf
->all_rtrs
== rtrs
? "reachable routers"
10720 : "router routing");
10722 for (rn
= route_top(rtrs
); rn
; rn
= route_next(rn
)) {
10723 if (rn
->info
== NULL
)
10728 json_route
= json_object_new_object();
10729 json_object_object_add(
10730 json
, inet_ntop(AF_INET
, &rn
->p
.u
.prefix4
,
10733 json_object_string_add(json_route
, "routeType", "R ");
10735 vty_out(vty
, "R %-15pI4 ",
10739 for (ALL_LIST_ELEMENTS_RO((struct list
*)rn
->info
, node
, or)) {
10742 vty_out(vty
, "%24s", "");
10747 json_object_int_add(json_route
, "cost",
10749 json_object_string_addf(json_route
, "area",
10751 &or->u
.std
.area_id
);
10752 if (or->path_type
== OSPF_PATH_INTER_AREA
) {
10753 json_object_boolean_true_add(json_route
,
10755 json_object_boolean_true_add(json_route
,
10758 if (or->u
.std
.flags
& ROUTER_LSA_BORDER
)
10759 json_object_string_add(json_route
,
10762 else if (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
)
10763 json_object_string_add(json_route
,
10767 vty_out(vty
, "%s [%d] area: %pI4",
10768 (or->path_type
== OSPF_PATH_INTER_AREA
10771 or->cost
, &or->u
.std
.area_id
);
10773 vty_out(vty
, "%s%s\n",
10774 (or->u
.std
.flags
& ROUTER_LSA_BORDER
10777 (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
10783 json_nexthop_array
= json_object_new_array();
10784 json_object_object_add(json_route
, "nexthops",
10785 json_nexthop_array
);
10788 for (ALL_LIST_ELEMENTS_RO(or->paths
, pnode
, path
)) {
10790 json_nexthop
= json_object_new_object();
10791 json_object_array_add(
10792 json_nexthop_array
,
10795 if (if_lookup_by_index(path
->ifindex
,
10797 if (path
->nexthop
.s_addr
10800 json_object_string_add(
10803 json_object_string_add(
10805 "directly attached to",
10809 json_object_string_add(
10811 "directlyAttachedTo",
10817 "%24s directly attached to %s\n",
10825 json_object_string_addf(
10829 json_object_string_add(
10837 "%24s via %pI4, %s\n",
10850 vty_out(vty
, "\n");
10853 static void show_ip_ospf_route_external(struct vty
*vty
, struct ospf
*ospf
,
10854 struct route_table
*rt
,
10857 struct route_node
*rn
;
10858 struct ospf_route
*er
;
10859 struct listnode
*pnode
, *pnnode
;
10860 struct ospf_path
*path
;
10861 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
10862 *json_nexthop
= NULL
;
10866 "============ OSPF external routing table ===========\n");
10868 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
10869 if ((er
= rn
->info
) == NULL
)
10874 snprintfrr(buf1
, sizeof(buf1
), "%pFX", &rn
->p
);
10876 json_route
= json_object_new_object();
10877 json_object_object_add(json
, buf1
, json_route
);
10880 switch (er
->path_type
) {
10881 case OSPF_PATH_TYPE1_EXTERNAL
:
10883 json_object_string_add(json_route
, "routeType",
10885 json_object_int_add(json_route
, "cost",
10887 json_object_int_add(json_route
, "tag",
10891 "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI
10893 buf1
, er
->cost
, er
->u
.ext
.tag
);
10896 case OSPF_PATH_TYPE2_EXTERNAL
:
10898 json_object_string_add(json_route
, "routeType",
10900 json_object_int_add(json_route
, "cost",
10902 json_object_int_add(json_route
, "type2cost",
10903 er
->u
.ext
.type2_cost
);
10904 json_object_int_add(json_route
, "tag",
10908 "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI
10910 buf1
, er
->cost
, er
->u
.ext
.type2_cost
,
10917 json_nexthop_array
= json_object_new_array();
10918 json_object_object_add(json_route
, "nexthops",
10919 json_nexthop_array
);
10922 for (ALL_LIST_ELEMENTS(er
->paths
, pnode
, pnnode
, path
)) {
10924 json_nexthop
= json_object_new_object();
10925 json_object_array_add(json_nexthop_array
,
10929 if (if_lookup_by_index(path
->ifindex
, ospf
->vrf_id
)) {
10930 if (path
->nexthop
.s_addr
== INADDR_ANY
) {
10932 json_object_string_add(
10933 json_nexthop
, "ip",
10935 json_object_string_add(
10937 "directly attached to",
10941 json_object_string_add(
10943 "directlyAttachedTo",
10949 "%24s directly attached to %s\n",
10957 json_object_string_addf(
10958 json_nexthop
, "ip",
10959 "%pI4", &path
->nexthop
);
10960 json_object_string_add(
10961 json_nexthop
, "via",
10967 "%24s via %pI4, %s\n",
10979 vty_out(vty
, "\n");
10982 static void show_ip_ospf_route_orr_root(struct vty
*vty
, struct ospf
*ospf
,
10983 struct orr_root
*root
, bool use_vrf
)
10985 if (ospf
->instance
)
10986 vty_out(vty
, "\nOSPF Instance: %d\n", ospf
->instance
);
10988 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
10990 vty_out(vty
, "ORR Group: %s\n", root
->group_name
);
10991 vty_out(vty
, "Active Root: %pI4\n\n", &root
->router_id
);
10992 vty_out(vty
, "SPF calculated from %pI4\n\n", &root
->router_id
);
10994 if (root
->new_table
)
10995 show_ip_ospf_route_network(vty
, ospf
, root
->new_table
, NULL
);
10997 if (root
->new_rtrs
)
10998 show_ip_ospf_route_router(vty
, ospf
, root
->new_rtrs
, NULL
);
11000 vty_out(vty
, "\n");
11003 static void show_ip_ospf_route_orr_common(struct vty
*vty
, struct ospf
*ospf
,
11004 const char *orr_group
, bool use_vrf
)
11008 struct orr_root
*root
= NULL
;
11009 struct listnode
*node
= NULL
;
11010 struct list
*orr_root_list
= NULL
;
11012 if (!ospf
->orr_spf_request
)
11015 FOREACH_AFI_SAFI (afi
, safi
) {
11016 orr_root_list
= ospf
->orr_root
[afi
][safi
];
11017 if (!orr_root_list
)
11019 for (ALL_LIST_ELEMENTS_RO(orr_root_list
, node
, root
)) {
11021 if (!strmatch(root
->group_name
, orr_group
))
11023 show_ip_ospf_route_orr_root(vty
, ospf
, root
,
11026 show_ip_ospf_route_orr_root(vty
, ospf
, root
,
11032 DEFPY (show_ip_ospf_instance_route_orr
,
11033 show_ip_ospf_instance_route_orr_cmd
,
11034 "show ip ospf (1-65535)$instance route orr [WORD$orr_group]",
11039 "OSPF routing table\n"
11040 "Optimal Route Reflection\n"
11041 "ORR Group name\n")
11045 if (instance
!= ospf_instance
)
11046 return CMD_NOT_MY_INSTANCE
;
11048 ospf
= ospf_lookup_instance(instance
);
11049 if (!ospf
|| !ospf
->oi_running
)
11050 return CMD_SUCCESS
;
11052 show_ip_ospf_route_orr_common(vty
, ospf
, orr_group
, false);
11054 return CMD_SUCCESS
;
11057 DEFPY (show_ip_ospf_route_orr
,
11058 show_ip_ospf_route_orr_cmd
,
11059 "show ip ospf [vrf <NAME$vrf_name|all$all_vrf>] route orr [WORD$orr_group]",
11065 "OSPF routing table\n"
11066 "Optimal Route Reflection\n"
11067 "ORR Group name\n")
11069 struct ospf
*ospf
= NULL
;
11070 struct listnode
*node
= NULL
;
11071 int ret
= CMD_SUCCESS
;
11073 bool use_vrf
= vrf_name
|| all_vrf
;
11076 bool ospf_output
= false;
11078 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11079 if (!ospf
->oi_running
)
11081 ospf_output
= true;
11083 show_ip_ospf_route_orr_common(vty
, ospf
, orr_group
,
11087 vty_out(vty
, "%% OSPF is not enabled\n");
11092 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11094 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11096 if (!ospf
|| !ospf
->oi_running
) {
11097 vty_out(vty
, "%% OSPF is not enabled in vrf %s\n",
11098 vrf_name
? vrf_name
: "default");
11099 return CMD_SUCCESS
;
11102 show_ip_ospf_route_orr_common(vty
, ospf
, orr_group
, use_vrf
);
11107 static int show_ip_ospf_reachable_routers_common(struct vty
*vty
,
11111 if (ospf
->instance
)
11112 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
11114 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
11116 if (ospf
->all_rtrs
== NULL
) {
11117 vty_out(vty
, "No OSPF reachable router information exist\n");
11118 return CMD_SUCCESS
;
11121 /* Show Router routes. */
11122 show_ip_ospf_route_router(vty
, ospf
, ospf
->all_rtrs
, NULL
);
11124 vty_out(vty
, "\n");
11126 return CMD_SUCCESS
;
11129 DEFUN (show_ip_ospf_reachable_routers
,
11130 show_ip_ospf_reachable_routers_cmd
,
11131 "show ip ospf [vrf <NAME|all>] reachable-routers",
11134 "OSPF information\n"
11137 "Show all the reachable OSPF routers\n")
11139 struct ospf
*ospf
= NULL
;
11140 struct listnode
*node
= NULL
;
11141 char *vrf_name
= NULL
;
11142 bool all_vrf
= false;
11143 int ret
= CMD_SUCCESS
;
11146 uint8_t use_vrf
= 0;
11148 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11151 bool ospf_output
= false;
11156 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11157 if (!ospf
->oi_running
)
11160 ospf_output
= true;
11161 ret
= show_ip_ospf_reachable_routers_common(
11162 vty
, ospf
, use_vrf
);
11166 vty_out(vty
, "%% OSPF instance not found\n");
11168 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11169 if (ospf
== NULL
|| !ospf
->oi_running
) {
11170 vty_out(vty
, "%% OSPF instance not found\n");
11171 return CMD_SUCCESS
;
11174 ret
= show_ip_ospf_reachable_routers_common(vty
, ospf
,
11178 /* Display default ospf (instance 0) info */
11179 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11180 if (ospf
== NULL
|| !ospf
->oi_running
) {
11181 vty_out(vty
, "%% OSPF instance not found\n");
11182 return CMD_SUCCESS
;
11185 ret
= show_ip_ospf_reachable_routers_common(vty
, ospf
, use_vrf
);
11191 DEFUN (show_ip_ospf_instance_reachable_routers
,
11192 show_ip_ospf_instance_reachable_routers_cmd
,
11193 "show ip ospf (1-65535) reachable-routers",
11196 "OSPF information\n"
11198 "Show all the reachable OSPF routers\n")
11200 int idx_number
= 3;
11202 unsigned short instance
= 0;
11204 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
11205 if (instance
!= ospf_instance
)
11206 return CMD_NOT_MY_INSTANCE
;
11208 ospf
= ospf_lookup_instance(instance
);
11209 if (!ospf
|| !ospf
->oi_running
)
11210 return CMD_SUCCESS
;
11212 return show_ip_ospf_reachable_routers_common(vty
, ospf
, 0);
11215 static int show_ip_ospf_border_routers_common(struct vty
*vty
,
11220 json_object
*json_vrf
= NULL
;
11221 json_object
*json_router
= NULL
;
11225 json_vrf
= json_object_new_object();
11228 json_router
= json_object_new_object();
11231 if (ospf
->instance
) {
11233 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
11235 json_object_int_add(json_vrf
, "ospfInstance",
11239 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
11241 if (ospf
->new_table
== NULL
) {
11243 vty_out(vty
, "No OSPF routing information exist\n");
11245 json_object_free(json_router
);
11246 json_object_free(json_vrf
);
11248 return CMD_SUCCESS
;
11251 /* Show Network routes.
11252 show_ip_ospf_route_network (vty, ospf->new_table); */
11254 /* Show Router routes. */
11255 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, json_router
);
11258 json_object_object_add(json_vrf
, "routers", json_router
);
11260 if (ospf
->vrf_id
== VRF_DEFAULT
)
11261 json_object_object_add(json
, "default",
11264 json_object_object_add(json
, ospf
->name
,
11268 vty_out(vty
, "\n");
11271 return CMD_SUCCESS
;
11274 DEFPY (show_ip_ospf_border_routers
,
11275 show_ip_ospf_border_routers_cmd
,
11276 "show ip ospf [vrf <NAME|all>] border-routers [json]",
11279 "OSPF information\n"
11282 "Show all the ABR's and ASBR's\n"
11285 struct ospf
*ospf
= NULL
;
11286 struct listnode
*node
= NULL
;
11287 char *vrf_name
= NULL
;
11288 bool all_vrf
= false;
11289 int ret
= CMD_SUCCESS
;
11292 uint8_t use_vrf
= 0;
11293 bool uj
= use_json(argc
, argv
);
11294 json_object
*json
= NULL
;
11297 json
= json_object_new_object();
11299 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11302 bool ospf_output
= false;
11307 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11308 if (!ospf
->oi_running
)
11311 ospf_output
= true;
11312 ret
= show_ip_ospf_border_routers_common(
11313 vty
, ospf
, use_vrf
, json
);
11317 vty_json(vty
, json
);
11318 else if (!ospf_output
)
11319 vty_out(vty
, "%% OSPF is not enabled\n");
11323 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11324 if (ospf
== NULL
|| !ospf
->oi_running
) {
11326 vty_json(vty
, json
);
11329 "%% OSPF is not enabled in vrf %s\n",
11332 return CMD_SUCCESS
;
11336 /* Display default ospf (instance 0) info */
11337 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11338 if (ospf
== NULL
|| !ospf
->oi_running
) {
11340 vty_json(vty
, json
);
11343 "%% OSPF is not enabled in vrf default\n");
11345 return CMD_SUCCESS
;
11350 ret
= show_ip_ospf_border_routers_common(vty
, ospf
, use_vrf
,
11353 vty_json(vty
, json
);
11359 DEFUN (show_ip_ospf_instance_border_routers
,
11360 show_ip_ospf_instance_border_routers_cmd
,
11361 "show ip ospf (1-65535) border-routers",
11364 "OSPF information\n"
11366 "Show all the ABR's and ASBR's\n")
11368 int idx_number
= 3;
11370 unsigned short instance
= 0;
11372 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
11373 if (instance
!= ospf_instance
)
11374 return CMD_NOT_MY_INSTANCE
;
11376 ospf
= ospf_lookup_instance(instance
);
11377 if (!ospf
|| !ospf
->oi_running
)
11378 return CMD_SUCCESS
;
11380 return show_ip_ospf_border_routers_common(vty
, ospf
, 0, NULL
);
11383 static int show_ip_ospf_route_common(struct vty
*vty
, struct ospf
*ospf
,
11384 json_object
*json
, uint8_t use_vrf
)
11386 json_object
*json_vrf
= NULL
;
11388 if (ospf
->instance
)
11389 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
11394 json_vrf
= json_object_new_object();
11399 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
11401 if (ospf
->new_table
== NULL
) {
11402 vty_out(vty
, "No OSPF routing information exist\n");
11403 return CMD_SUCCESS
;
11406 /* Show Network routes. */
11407 show_ip_ospf_route_network(vty
, ospf
, ospf
->new_table
, json_vrf
);
11409 /* Show Router routes. */
11410 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, json_vrf
);
11412 /* Show Router routes. */
11413 if (ospf
->all_rtrs
)
11414 show_ip_ospf_route_router(vty
, ospf
, ospf
->all_rtrs
, json_vrf
);
11416 /* Show AS External routes. */
11417 show_ip_ospf_route_external(vty
, ospf
, ospf
->old_external_route
,
11422 // json_object_object_add(json_vrf, "areas",
11424 json_object_object_add(json
, ospf_get_name(ospf
),
11428 vty_out(vty
, "\n");
11431 return CMD_SUCCESS
;
11434 DEFUN (show_ip_ospf_route
,
11435 show_ip_ospf_route_cmd
,
11436 "show ip ospf [vrf <NAME|all>] route [json]",
11439 "OSPF information\n"
11442 "OSPF routing table\n"
11445 struct ospf
*ospf
= NULL
;
11446 struct listnode
*node
= NULL
;
11447 char *vrf_name
= NULL
;
11448 bool all_vrf
= false;
11449 int ret
= CMD_SUCCESS
;
11452 uint8_t use_vrf
= 0;
11453 bool uj
= use_json(argc
, argv
);
11454 json_object
*json
= NULL
;
11457 json
= json_object_new_object();
11459 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11461 /* vrf input is provided could be all or specific vrf*/
11463 bool ospf_output
= false;
11468 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11469 if (!ospf
->oi_running
)
11471 ospf_output
= true;
11472 ret
= show_ip_ospf_route_common(vty
, ospf
, json
,
11477 /* Keep Non-pretty format */
11478 vty_json(vty
, json
);
11479 } else if (!ospf_output
)
11480 vty_out(vty
, "%% OSPF is not enabled\n");
11484 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11485 if (ospf
== NULL
|| !ospf
->oi_running
) {
11487 vty_json(vty
, json
);
11490 "%% OSPF is not enabled in vrf %s\n",
11493 return CMD_SUCCESS
;
11496 /* Display default ospf (instance 0) info */
11497 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11498 if (ospf
== NULL
|| !ospf
->oi_running
) {
11500 vty_json(vty
, json
);
11503 "%% OSPF is not enabled in vrf default\n");
11505 return CMD_SUCCESS
;
11510 ret
= show_ip_ospf_route_common(vty
, ospf
, json
, use_vrf
);
11511 /* Keep Non-pretty format */
11513 vty_out(vty
, "%s\n",
11514 json_object_to_json_string_ext(
11515 json
, JSON_C_TO_STRING_NOSLASHESCAPE
));
11519 json_object_free(json
);
11524 DEFUN (show_ip_ospf_instance_route
,
11525 show_ip_ospf_instance_route_cmd
,
11526 "show ip ospf (1-65535) route",
11529 "OSPF information\n"
11531 "OSPF routing table\n")
11533 int idx_number
= 3;
11535 unsigned short instance
= 0;
11537 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
11538 if (instance
!= ospf_instance
)
11539 return CMD_NOT_MY_INSTANCE
;
11541 ospf
= ospf_lookup_instance(instance
);
11542 if (!ospf
|| !ospf
->oi_running
)
11543 return CMD_SUCCESS
;
11545 return show_ip_ospf_route_common(vty
, ospf
, NULL
, 0);
11549 DEFUN (show_ip_ospf_vrfs
,
11550 show_ip_ospf_vrfs_cmd
,
11551 "show ip ospf vrfs [json]",
11554 "OSPF information\n"
11555 "Show OSPF VRFs \n"
11558 bool uj
= use_json(argc
, argv
);
11559 json_object
*json
= NULL
;
11560 json_object
*json_vrfs
= NULL
;
11561 struct ospf
*ospf
= NULL
;
11562 struct listnode
*node
= NULL
;
11564 static const char header
[] = "Name Id RouterId ";
11567 json
= json_object_new_object();
11568 json_vrfs
= json_object_new_object();
11571 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11572 json_object
*json_vrf
= NULL
;
11573 const char *name
= NULL
;
11574 int64_t vrf_id_ui
= 0;
11578 if (!uj
&& count
== 1)
11579 vty_out(vty
, "%s\n", header
);
11581 json_vrf
= json_object_new_object();
11583 name
= ospf_get_name(ospf
);
11585 vrf_id_ui
= (ospf
->vrf_id
== VRF_UNKNOWN
)
11587 : (int64_t)ospf
->vrf_id
;
11590 json_object_int_add(json_vrf
, "vrfId", vrf_id_ui
);
11591 json_object_string_addf(json_vrf
, "routerId", "%pI4",
11594 json_object_object_add(json_vrfs
, name
, json_vrf
);
11597 vty_out(vty
, "%-25s %-5d %-16pI4 \n", name
,
11598 ospf
->vrf_id
, &ospf
->router_id
);
11603 json_object_object_add(json
, "vrfs", json_vrfs
);
11604 json_object_int_add(json
, "totalVrfs", count
);
11606 vty_json(vty
, json
);
11609 vty_out(vty
, "\nTotal number of OSPF VRFs: %d\n",
11613 return CMD_SUCCESS
;
11615 DEFPY (clear_ip_ospf_neighbor
,
11616 clear_ip_ospf_neighbor_cmd
,
11617 "clear ip ospf [(1-65535)]$instance neighbor [A.B.C.D$nbr_id]",
11620 "OSPF information\n"
11622 "Reset OSPF Neighbor\n"
11625 struct listnode
*node
;
11626 struct ospf
*ospf
= NULL
;
11628 /* If user does not specify the arguments,
11629 * instance = 0 and nbr_id = 0.0.0.0
11631 if (instance
!= 0) {
11632 /* This means clear only the particular ospf process */
11633 if (instance
!= ospf_instance
)
11634 return CMD_NOT_MY_INSTANCE
;
11637 /* Clear all the ospf processes */
11638 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11639 if (!ospf
->oi_running
)
11642 if (nbr_id_str
&& IPV4_ADDR_SAME(&ospf
->router_id
, &nbr_id
)) {
11643 vty_out(vty
, "Self router-id is not allowed.\r\n ");
11644 return CMD_SUCCESS
;
11647 ospf_neighbor_reset(ospf
, nbr_id
, nbr_id_str
);
11650 return CMD_SUCCESS
;
11653 DEFPY (clear_ip_ospf_process
,
11654 clear_ip_ospf_process_cmd
,
11655 "clear ip ospf [(1-65535)]$instance process",
11658 "OSPF information\n"
11660 "Reset OSPF Process\n")
11662 struct listnode
*node
;
11663 struct ospf
*ospf
= NULL
;
11665 /* Check if instance is not passed as an argument */
11666 if (instance
!= 0) {
11667 /* This means clear only the particular ospf process */
11668 if (instance
!= ospf_instance
)
11669 return CMD_NOT_MY_INSTANCE
;
11672 /* Clear all the ospf processes */
11673 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11674 if (!ospf
->oi_running
)
11677 ospf_process_reset(ospf
);
11680 return CMD_SUCCESS
;
11683 static const char *const ospf_abr_type_str
[] = {
11684 "unknown", "standard", "ibm", "cisco", "shortcut"
11687 static const char *const ospf_shortcut_mode_str
[] = {
11688 "default", "enable", "disable"
11690 static int ospf_vty_external_rt_walkcb(struct hash_bucket
*bucket
,
11693 struct external_info
*ei
= bucket
->data
;
11694 struct vty
*vty
= (struct vty
*)arg
;
11695 static unsigned int count
;
11697 vty_out(vty
, "%-4pI4/%d, ", &ei
->p
.prefix
, ei
->p
.prefixlen
);
11700 if (count
% 5 == 0)
11701 vty_out(vty
, "\n");
11703 if (OSPF_EXTERNAL_RT_COUNT(ei
->aggr_route
) == count
)
11706 return HASHWALK_CONTINUE
;
11709 static int ospf_json_external_rt_walkcb(struct hash_bucket
*bucket
,
11712 struct external_info
*ei
= bucket
->data
;
11713 struct json_object
*json
= (struct json_object
*)arg
;
11714 char buf
[PREFIX2STR_BUFFER
];
11716 static unsigned int count
;
11718 prefix2str(&ei
->p
, buf
, sizeof(buf
));
11720 snprintf(exnalbuf
, 20, "Exnl Addr-%d", count
);
11722 json_object_string_add(json
, exnalbuf
, buf
);
11726 if (OSPF_EXTERNAL_RT_COUNT(ei
->aggr_route
) == count
)
11729 return HASHWALK_CONTINUE
;
11732 static int ospf_show_summary_address(struct vty
*vty
, struct ospf
*ospf
,
11733 uint8_t use_vrf
, json_object
*json
,
11734 bool uj
, bool detail
)
11736 struct route_node
*rn
;
11737 json_object
*json_vrf
= NULL
;
11740 static char header
[] =
11741 "Summary-address Metric-type Metric Tag External_Rt_count\n";
11743 mtype
= metric_type(ospf
, 0, ospf
->instance
);
11744 mval
= metric_value(ospf
, 0, ospf
->instance
);
11747 vty_out(vty
, "%s\n", header
);
11751 json_vrf
= json_object_new_object();
11756 if (ospf
->instance
) {
11758 json_object_int_add(json
, "ospfInstance",
11761 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
11764 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
11767 vty_out(vty
, "aggregation delay interval :%u(in seconds)\n\n",
11768 ospf
->aggr_delay_interval
);
11770 json_object_int_add(json_vrf
, "aggregation delay interval",
11771 ospf
->aggr_delay_interval
);
11772 json_object_int_add(json_vrf
, "aggregationDelayInterval",
11773 ospf
->aggr_delay_interval
);
11776 for (rn
= route_top(ospf
->rt_aggr_tbl
); rn
; rn
= route_next(rn
))
11778 struct ospf_external_aggr_rt
*aggr
= rn
->info
;
11779 json_object
*json_aggr
= NULL
;
11780 char buf
[PREFIX2STR_BUFFER
];
11782 prefix2str(&aggr
->p
, buf
, sizeof(buf
));
11786 json_aggr
= json_object_new_object();
11788 json_object_object_add(json_vrf
, buf
,
11791 json_object_string_add(json_aggr
,
11792 "Summary address", buf
);
11793 json_object_string_add(json_aggr
,
11794 "summaryAddress", buf
);
11796 json_object_string_add(
11797 json_aggr
, "Metric-type",
11798 (mtype
== EXTERNAL_METRIC_TYPE_1
)
11801 json_object_string_add(
11802 json_aggr
, "metricType",
11803 (mtype
== EXTERNAL_METRIC_TYPE_1
)
11807 #if CONFDATE > 20230131
11808 CPP_NOTICE("Remove JSON object commands with keys starting with capital")
11810 json_object_int_add(json_aggr
, "Metric", mval
);
11811 json_object_int_add(json_aggr
, "metric", mval
);
11813 json_object_int_add(json_aggr
, "Tag",
11815 json_object_int_add(json_aggr
, "tag",
11818 json_object_int_add(
11819 json_aggr
, "External route count",
11820 OSPF_EXTERNAL_RT_COUNT(aggr
));
11821 json_object_int_add(
11822 json_aggr
, "externalRouteCount",
11823 OSPF_EXTERNAL_RT_COUNT(aggr
));
11825 if (OSPF_EXTERNAL_RT_COUNT(aggr
) && detail
) {
11827 aggr
->match_extnl_hash
,
11828 ospf_json_external_rt_walkcb
,
11833 vty_out(vty
, "%-20s", buf
);
11835 (mtype
== EXTERNAL_METRIC_TYPE_1
)
11836 ? vty_out(vty
, "%-16s", "E1")
11837 : vty_out(vty
, "%-16s", "E2");
11838 vty_out(vty
, "%-11d", mval
);
11840 vty_out(vty
, "%-12u", aggr
->tag
);
11842 vty_out(vty
, "%-5ld\n",
11843 OSPF_EXTERNAL_RT_COUNT(aggr
));
11845 if (OSPF_EXTERNAL_RT_COUNT(aggr
) && detail
) {
11847 "Matched External routes:\n");
11849 aggr
->match_extnl_hash
,
11850 ospf_vty_external_rt_walkcb
,
11852 vty_out(vty
, "\n");
11855 vty_out(vty
, "\n");
11861 json_object_object_add(json
, ospf_get_name(ospf
),
11864 vty_out(vty
, "\n");
11866 return CMD_SUCCESS
;
11869 DEFUN (show_ip_ospf_external_aggregator
,
11870 show_ip_ospf_external_aggregator_cmd
,
11871 "show ip ospf [vrf <NAME|all>] summary-address [detail] [json]",
11873 "OSPF information\n"
11876 "Show external summary addresses\n"
11877 "Detailed information\n"
11880 char *vrf_name
= NULL
;
11881 bool all_vrf
= false;
11882 int ret
= CMD_SUCCESS
;
11885 uint8_t use_vrf
= 0;
11886 bool uj
= use_json(argc
, argv
);
11887 struct ospf
*ospf
= NULL
;
11888 json_object
*json
= NULL
;
11889 struct listnode
*node
= NULL
;
11891 bool detail
= false;
11893 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11895 if (argv_find(argv
, argc
, "detail", &idx
))
11899 json
= json_object_new_object();
11901 /* vrf input is provided */
11905 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11906 if (!ospf
->oi_running
)
11908 ret
= ospf_show_summary_address(
11909 vty
, ospf
, use_vrf
, json
, uj
, detail
);
11913 vty_json(vty
, json
);
11918 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11920 if (ospf
== NULL
|| !ospf
->oi_running
) {
11922 vty_json(vty
, json
);
11925 "%% OSPF is not enabled in vrf %s\n",
11928 return CMD_SUCCESS
;
11930 ospf_show_summary_address(vty
, ospf
, use_vrf
, json
, uj
, detail
);
11934 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11935 if (ospf
== NULL
|| !ospf
->oi_running
) {
11937 vty_json(vty
, json
);
11940 "%% OSPF is not enabled in vrf default\n");
11942 return CMD_SUCCESS
;
11945 ospf_show_summary_address(vty
, ospf
, use_vrf
, json
, uj
, detail
);
11949 vty_json(vty
, json
);
11950 return CMD_SUCCESS
;
11953 static const char *const ospf_int_type_str
[] = {
11954 "unknown", /* should never be used. */
11958 "point-to-multipoint",
11959 "virtual-link", /* should never be used. */
11963 static const char *interface_config_auth_str(struct ospf_if_params
*params
)
11965 if (!OSPF_IF_PARAM_CONFIGURED(params
, auth_type
)
11966 || params
->auth_type
== OSPF_AUTH_NOTSET
)
11969 /* Translation tables are not that much help
11970 * here due to syntax
11971 * of the simple option */
11972 switch (params
->auth_type
) {
11974 case OSPF_AUTH_NULL
:
11977 case OSPF_AUTH_SIMPLE
:
11980 case OSPF_AUTH_CRYPTOGRAPHIC
:
11981 return " message-digest";
11987 static int config_write_interface_one(struct vty
*vty
, struct vrf
*vrf
)
11989 struct listnode
*node
;
11990 struct interface
*ifp
;
11991 struct crypt_key
*ck
;
11992 struct route_node
*rn
= NULL
;
11993 struct ospf_if_params
*params
;
11994 const char *auth_str
;
11997 FOR_ALL_INTERFACES (vrf
, ifp
) {
11999 if (memcmp(ifp
->name
, "VLINK", 5) == 0)
12002 if_vty_config_start(vty
, ifp
);
12005 vty_out(vty
, " description %s\n", ifp
->desc
);
12009 params
= IF_DEF_PARAMS(ifp
);
12012 /* Interface Network print. */
12013 if (OSPF_IF_PARAM_CONFIGURED(params
, type
)
12014 && params
->type
!= OSPF_IFTYPE_LOOPBACK
) {
12015 if (params
->type
!= ospf_default_iftype(ifp
)) {
12016 vty_out(vty
, " ip ospf network %s",
12020 == OSPF_IFTYPE_POINTOPOINT
12021 && params
->ptp_dmvpn
)
12022 vty_out(vty
, " dmvpn");
12023 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12024 vty_out(vty
, " %pI4",
12026 vty_out(vty
, "\n");
12030 /* OSPF interface authentication print */
12031 auth_str
= interface_config_auth_str(params
);
12033 vty_out(vty
, " ip ospf authentication%s",
12035 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12036 vty_out(vty
, " %pI4",
12038 vty_out(vty
, "\n");
12041 /* Simple Authentication Password print. */
12042 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_simple
)
12043 && params
->auth_simple
[0] != '\0') {
12044 vty_out(vty
, " ip ospf authentication-key %s",
12045 params
->auth_simple
);
12046 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12047 vty_out(vty
, " %pI4",
12049 vty_out(vty
, "\n");
12052 /* Cryptographic Authentication Key print. */
12053 if (params
&& params
->auth_crypt
) {
12054 for (ALL_LIST_ELEMENTS_RO(params
->auth_crypt
,
12057 " ip ospf message-digest-key %d md5 %s",
12058 ck
->key_id
, ck
->auth_key
);
12059 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12060 vty_out(vty
, " %pI4",
12062 vty_out(vty
, "\n");
12066 /* Interface Output Cost print. */
12067 if (OSPF_IF_PARAM_CONFIGURED(params
, output_cost_cmd
)) {
12068 vty_out(vty
, " ip ospf cost %u",
12069 params
->output_cost_cmd
);
12070 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12071 vty_out(vty
, " %pI4",
12073 vty_out(vty
, "\n");
12076 /* Hello Interval print. */
12077 if (OSPF_IF_PARAM_CONFIGURED(params
, v_hello
)
12078 && params
->v_hello
!= OSPF_HELLO_INTERVAL_DEFAULT
) {
12079 vty_out(vty
, " ip ospf hello-interval %u",
12081 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12082 vty_out(vty
, " %pI4",
12084 vty_out(vty
, "\n");
12088 /* Router Dead Interval print. */
12089 if (OSPF_IF_PARAM_CONFIGURED(params
, v_wait
)
12090 && params
->is_v_wait_set
) {
12091 vty_out(vty
, " ip ospf dead-interval ");
12094 if (OSPF_IF_PARAM_CONFIGURED(params
,
12097 "minimal hello-multiplier %d",
12098 params
->fast_hello
);
12100 vty_out(vty
, "%u", params
->v_wait
);
12102 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12103 vty_out(vty
, " %pI4",
12105 vty_out(vty
, "\n");
12108 /* Router Priority print. */
12109 if (OSPF_IF_PARAM_CONFIGURED(params
, priority
)
12110 && params
->priority
12111 != OSPF_ROUTER_PRIORITY_DEFAULT
) {
12112 vty_out(vty
, " ip ospf priority %u",
12114 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12115 vty_out(vty
, " %pI4",
12117 vty_out(vty
, "\n");
12120 /* Retransmit Interval print. */
12121 if (OSPF_IF_PARAM_CONFIGURED(params
,
12122 retransmit_interval
)
12123 && params
->retransmit_interval
12124 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
) {
12125 vty_out(vty
, " ip ospf retransmit-interval %u",
12126 params
->retransmit_interval
);
12127 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12128 vty_out(vty
, " %pI4",
12130 vty_out(vty
, "\n");
12133 /* Transmit Delay print. */
12134 if (OSPF_IF_PARAM_CONFIGURED(params
, transmit_delay
)
12135 && params
->transmit_delay
12136 != OSPF_TRANSMIT_DELAY_DEFAULT
) {
12137 vty_out(vty
, " ip ospf transmit-delay %u",
12138 params
->transmit_delay
);
12139 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12140 vty_out(vty
, " %pI4",
12142 vty_out(vty
, "\n");
12146 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
12148 vty_out(vty
, " ip ospf %d",
12151 vty_out(vty
, " ip ospf");
12153 char buf
[INET_ADDRSTRLEN
];
12155 area_id2str(buf
, sizeof(buf
), ¶ms
->if_area
,
12156 params
->if_area_id_fmt
);
12157 vty_out(vty
, " area %s", buf
);
12158 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12159 vty_out(vty
, " %pI4",
12161 vty_out(vty
, "\n");
12165 if (params
&& params
->bfd_config
)
12166 ospf_bfd_write_config(vty
, params
);
12168 /* MTU ignore print. */
12169 if (OSPF_IF_PARAM_CONFIGURED(params
, mtu_ignore
)
12170 && params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
) {
12171 if (params
->mtu_ignore
== 0)
12172 vty_out(vty
, " no ip ospf mtu-ignore");
12174 vty_out(vty
, " ip ospf mtu-ignore");
12175 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12176 vty_out(vty
, " %pI4",
12178 vty_out(vty
, "\n");
12181 if (OSPF_IF_PARAM_CONFIGURED(params
,
12182 passive_interface
)) {
12183 vty_out(vty
, " %sip ospf passive",
12184 params
->passive_interface
12188 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12189 vty_out(vty
, " %pI4", &rn
->p
.u
.prefix4
);
12190 vty_out(vty
, "\n");
12193 /* LDP-Sync print */
12194 if (params
&& params
->ldp_sync_info
)
12195 ospf_ldp_sync_if_write_config(vty
, params
);
12199 rn
= route_top(IF_OIFS_PARAMS(ifp
));
12201 rn
= route_next(rn
);
12206 if (params
!= NULL
)
12211 ospf_opaque_config_write_if(vty
, ifp
);
12213 if_vty_config_end(vty
);
12219 /* Configuration write function for ospfd. */
12220 static int config_write_interface(struct vty
*vty
)
12223 struct vrf
*vrf
= NULL
;
12225 /* Display all VRF aware OSPF interface configuration */
12226 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
12227 write
+= config_write_interface_one(vty
, vrf
);
12233 static int config_write_network_area(struct vty
*vty
, struct ospf
*ospf
)
12235 struct route_node
*rn
;
12236 char buf
[INET_ADDRSTRLEN
];
12238 /* `network area' print. */
12239 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
))
12241 struct ospf_network
*n
= rn
->info
;
12243 /* Create Area ID string by specified Area ID format. */
12244 if (n
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
12245 inet_ntop(AF_INET
, &n
->area_id
, buf
,
12248 snprintf(buf
, sizeof(buf
), "%lu",
12249 (unsigned long int)ntohl(
12250 n
->area_id
.s_addr
));
12252 /* Network print. */
12253 vty_out(vty
, " network %pFX area %s\n", &rn
->p
, buf
);
12259 static int config_write_ospf_area(struct vty
*vty
, struct ospf
*ospf
)
12261 struct listnode
*node
;
12262 struct ospf_area
*area
;
12263 char buf
[INET_ADDRSTRLEN
];
12265 /* Area configuration print. */
12266 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
12267 struct route_node
*rn1
;
12269 area_id2str(buf
, sizeof(buf
), &area
->area_id
,
12270 area
->area_id_fmt
);
12272 if (area
->auth_type
!= OSPF_AUTH_NULL
) {
12273 if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
12274 vty_out(vty
, " area %s authentication\n", buf
);
12277 " area %s authentication message-digest\n",
12281 if (area
->shortcut_configured
!= OSPF_SHORTCUT_DEFAULT
)
12282 vty_out(vty
, " area %s shortcut %s\n", buf
,
12283 ospf_shortcut_mode_str
12284 [area
->shortcut_configured
]);
12286 if ((area
->external_routing
== OSPF_AREA_STUB
)
12287 || (area
->external_routing
== OSPF_AREA_NSSA
)) {
12288 if (area
->external_routing
== OSPF_AREA_STUB
) {
12289 vty_out(vty
, " area %s stub", buf
);
12290 if (area
->no_summary
)
12291 vty_out(vty
, " no-summary\n");
12292 vty_out(vty
, "\n");
12293 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
12294 switch (area
->NSSATranslatorRole
) {
12295 case OSPF_NSSA_ROLE_NEVER
:
12297 " area %s nssa translate-never\n",
12300 case OSPF_NSSA_ROLE_ALWAYS
:
12302 " area %s nssa translate-always\n",
12305 case OSPF_NSSA_ROLE_CANDIDATE
:
12306 vty_out(vty
, " area %s nssa \n", buf
);
12309 if (area
->no_summary
)
12311 " area %s nssa no-summary\n",
12313 if (area
->suppress_fa
)
12315 " area %s nssa suppress-fa\n",
12319 if (area
->default_cost
!= 1)
12320 vty_out(vty
, " area %s default-cost %d\n", buf
,
12321 area
->default_cost
);
12324 for (rn1
= route_top(area
->ranges
); rn1
; rn1
= route_next(rn1
))
12326 struct ospf_area_range
*range
= rn1
->info
;
12328 vty_out(vty
, " area %s range %pFX", buf
,
12331 if (range
->cost_config
12332 != OSPF_AREA_RANGE_COST_UNSPEC
)
12333 vty_out(vty
, " cost %d",
12334 range
->cost_config
);
12336 if (!CHECK_FLAG(range
->flags
,
12337 OSPF_AREA_RANGE_ADVERTISE
))
12338 vty_out(vty
, " not-advertise");
12340 if (CHECK_FLAG(range
->flags
,
12341 OSPF_AREA_RANGE_SUBSTITUTE
))
12342 vty_out(vty
, " substitute %pI4/%d",
12343 &range
->subst_addr
,
12344 range
->subst_masklen
);
12346 vty_out(vty
, "\n");
12349 if (EXPORT_NAME(area
))
12350 vty_out(vty
, " area %s export-list %s\n", buf
,
12351 EXPORT_NAME(area
));
12353 if (IMPORT_NAME(area
))
12354 vty_out(vty
, " area %s import-list %s\n", buf
,
12355 IMPORT_NAME(area
));
12357 if (PREFIX_NAME_IN(area
))
12358 vty_out(vty
, " area %s filter-list prefix %s in\n", buf
,
12359 PREFIX_NAME_IN(area
));
12361 if (PREFIX_NAME_OUT(area
))
12362 vty_out(vty
, " area %s filter-list prefix %s out\n",
12363 buf
, PREFIX_NAME_OUT(area
));
12369 static int config_write_ospf_nbr_nbma(struct vty
*vty
, struct ospf
*ospf
)
12371 struct ospf_nbr_nbma
*nbr_nbma
;
12372 struct route_node
*rn
;
12374 /* Static Neighbor configuration print. */
12375 for (rn
= route_top(ospf
->nbr_nbma
); rn
; rn
= route_next(rn
))
12376 if ((nbr_nbma
= rn
->info
)) {
12377 vty_out(vty
, " neighbor %pI4", &nbr_nbma
->addr
);
12379 if (nbr_nbma
->priority
12380 != OSPF_NEIGHBOR_PRIORITY_DEFAULT
)
12381 vty_out(vty
, " priority %d",
12382 nbr_nbma
->priority
);
12384 if (nbr_nbma
->v_poll
!= OSPF_POLL_INTERVAL_DEFAULT
)
12385 vty_out(vty
, " poll-interval %d",
12388 vty_out(vty
, "\n");
12394 static int config_write_virtual_link(struct vty
*vty
, struct ospf
*ospf
)
12396 struct listnode
*node
;
12397 struct ospf_vl_data
*vl_data
;
12398 const char *auth_str
;
12399 char buf
[INET_ADDRSTRLEN
];
12401 /* Virtual-Link print */
12402 for (ALL_LIST_ELEMENTS_RO(ospf
->vlinks
, node
, vl_data
)) {
12403 struct listnode
*n2
;
12404 struct crypt_key
*ck
;
12405 struct ospf_interface
*oi
;
12407 if (vl_data
!= NULL
) {
12408 area_id2str(buf
, sizeof(buf
), &vl_data
->vl_area_id
,
12409 vl_data
->vl_area_id_fmt
);
12410 oi
= vl_data
->vl_oi
;
12413 if (OSPF_IF_PARAM(oi
, v_hello
)
12414 != OSPF_HELLO_INTERVAL_DEFAULT
12415 || OSPF_IF_PARAM(oi
, v_wait
)
12416 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
12417 || OSPF_IF_PARAM(oi
, retransmit_interval
)
12418 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
12419 || OSPF_IF_PARAM(oi
, transmit_delay
)
12420 != OSPF_TRANSMIT_DELAY_DEFAULT
)
12422 " area %s virtual-link %pI4 hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n",
12423 buf
, &vl_data
->vl_peer
,
12424 OSPF_IF_PARAM(oi
, v_hello
),
12425 OSPF_IF_PARAM(oi
, retransmit_interval
),
12426 OSPF_IF_PARAM(oi
, transmit_delay
),
12427 OSPF_IF_PARAM(oi
, v_wait
));
12429 vty_out(vty
, " area %s virtual-link %pI4\n", buf
,
12430 &vl_data
->vl_peer
);
12432 auth_str
= interface_config_auth_str(
12433 IF_DEF_PARAMS(oi
->ifp
));
12436 " area %s virtual-link %pI4 authentication%s\n",
12437 buf
, &vl_data
->vl_peer
, auth_str
);
12439 if (IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)->auth_simple
[0]
12442 " area %s virtual-link %pI4 authentication-key %s\n",
12443 buf
, &vl_data
->vl_peer
,
12444 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
12447 for (ALL_LIST_ELEMENTS_RO(
12448 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
12452 " area %s virtual-link %pI4 message-digest-key %d md5 %s\n",
12453 buf
, &vl_data
->vl_peer
,
12454 ck
->key_id
, ck
->auth_key
);
12462 static int config_write_ospf_redistribute(struct vty
*vty
, struct ospf
*ospf
)
12466 /* redistribute print. */
12467 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
12468 struct list
*red_list
;
12469 struct listnode
*node
;
12470 struct ospf_redist
*red
;
12472 red_list
= ospf
->redist
[type
];
12476 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
12477 vty_out(vty
, " redistribute %s",
12478 zebra_route_string(type
));
12480 vty_out(vty
, " %d", red
->instance
);
12482 if (red
->dmetric
.value
>= 0)
12483 vty_out(vty
, " metric %d", red
->dmetric
.value
);
12485 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
12486 vty_out(vty
, " metric-type 1");
12488 if (ROUTEMAP_NAME(red
))
12489 vty_out(vty
, " route-map %s",
12490 ROUTEMAP_NAME(red
));
12492 vty_out(vty
, "\n");
12499 static int ospf_cfg_write_helper_dis_rtr_walkcb(struct hash_bucket
*bucket
,
12502 struct advRtr
*rtr
= bucket
->data
;
12503 struct vty
*vty
= (struct vty
*)arg
;
12505 vty_out(vty
, " graceful-restart helper enable %pI4\n",
12507 return HASHWALK_CONTINUE
;
12510 static void config_write_ospf_gr(struct vty
*vty
, struct ospf
*ospf
)
12512 if (!ospf
->gr_info
.restart_support
)
12515 if (ospf
->gr_info
.grace_period
== OSPF_DFLT_GRACE_INTERVAL
)
12516 vty_out(vty
, " graceful-restart\n");
12518 vty_out(vty
, " graceful-restart grace-period %u\n",
12519 ospf
->gr_info
.grace_period
);
12522 static int config_write_ospf_gr_helper(struct vty
*vty
, struct ospf
*ospf
)
12524 if (ospf
->is_helper_supported
)
12525 vty_out(vty
, " graceful-restart helper enable\n");
12527 if (!ospf
->strict_lsa_check
)
12529 " no graceful-restart helper strict-lsa-checking\n");
12531 if (ospf
->only_planned_restart
)
12532 vty_out(vty
, " graceful-restart helper planned-only\n");
12534 if (ospf
->supported_grace_time
!= OSPF_MAX_GRACE_INTERVAL
)
12536 " graceful-restart helper supported-grace-time %d\n",
12537 ospf
->supported_grace_time
);
12539 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf
)) {
12540 hash_walk(ospf
->enable_rtr_list
,
12541 ospf_cfg_write_helper_dis_rtr_walkcb
, vty
);
12546 static int config_write_ospf_external_aggregator(struct vty
*vty
,
12549 struct route_node
*rn
;
12551 if (ospf
->aggr_delay_interval
!= OSPF_EXTL_AGGR_DEFAULT_DELAY
)
12552 vty_out(vty
, " aggregation timer %u\n",
12553 ospf
->aggr_delay_interval
);
12555 /* print 'summary-address A.B.C.D/M' */
12556 for (rn
= route_top(ospf
->rt_aggr_tbl
); rn
; rn
= route_next(rn
))
12558 struct ospf_external_aggr_rt
*aggr
= rn
->info
;
12560 vty_out(vty
, " summary-address %pI4/%d",
12561 &aggr
->p
.prefix
, aggr
->p
.prefixlen
);
12563 vty_out(vty
, " tag %u", aggr
->tag
);
12565 if (CHECK_FLAG(aggr
->flags
,
12566 OSPF_EXTERNAL_AGGRT_NO_ADVERTISE
))
12567 vty_out(vty
, " no-advertise");
12569 vty_out(vty
, "\n");
12575 static int config_write_ospf_default_metric(struct vty
*vty
, struct ospf
*ospf
)
12577 if (ospf
->default_metric
!= -1)
12578 vty_out(vty
, " default-metric %d\n", ospf
->default_metric
);
12582 static int config_write_ospf_distribute(struct vty
*vty
, struct ospf
*ospf
)
12585 struct ospf_redist
*red
;
12588 /* distribute-list print. */
12589 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
12590 if (DISTRIBUTE_NAME(ospf
, type
))
12591 vty_out(vty
, " distribute-list %s out %s\n",
12592 DISTRIBUTE_NAME(ospf
, type
),
12593 zebra_route_string(type
));
12595 /* default-information print. */
12596 if (ospf
->default_originate
!= DEFAULT_ORIGINATE_NONE
) {
12597 vty_out(vty
, " default-information originate");
12598 if (ospf
->default_originate
== DEFAULT_ORIGINATE_ALWAYS
)
12599 vty_out(vty
, " always");
12601 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
12603 if (red
->dmetric
.value
>= 0)
12604 vty_out(vty
, " metric %d",
12605 red
->dmetric
.value
);
12607 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
12608 vty_out(vty
, " metric-type 1");
12610 if (ROUTEMAP_NAME(red
))
12611 vty_out(vty
, " route-map %s",
12612 ROUTEMAP_NAME(red
));
12615 vty_out(vty
, "\n");
12622 static int config_write_ospf_distance(struct vty
*vty
, struct ospf
*ospf
)
12624 struct route_node
*rn
;
12625 struct ospf_distance
*odistance
;
12627 if (ospf
->distance_all
)
12628 vty_out(vty
, " distance %d\n", ospf
->distance_all
);
12630 if (ospf
->distance_intra
|| ospf
->distance_inter
12631 || ospf
->distance_external
) {
12632 vty_out(vty
, " distance ospf");
12634 if (ospf
->distance_intra
)
12635 vty_out(vty
, " intra-area %d", ospf
->distance_intra
);
12636 if (ospf
->distance_inter
)
12637 vty_out(vty
, " inter-area %d", ospf
->distance_inter
);
12638 if (ospf
->distance_external
)
12639 vty_out(vty
, " external %d", ospf
->distance_external
);
12641 vty_out(vty
, "\n");
12644 for (rn
= route_top(ospf
->distance_table
); rn
; rn
= route_next(rn
))
12645 if ((odistance
= rn
->info
) != NULL
) {
12646 vty_out(vty
, " distance %d %pFX %s\n",
12647 odistance
->distance
, &rn
->p
,
12648 odistance
->access_list
? odistance
->access_list
12654 static int ospf_config_write_one(struct vty
*vty
, struct ospf
*ospf
)
12658 /* `router ospf' print. */
12659 if (ospf
->instance
&& strcmp(ospf
->name
, VRF_DEFAULT_NAME
)) {
12660 vty_out(vty
, "router ospf %d vrf %s\n", ospf
->instance
,
12662 } else if (ospf
->instance
) {
12663 vty_out(vty
, "router ospf %d\n", ospf
->instance
);
12664 } else if (strcmp(ospf
->name
, VRF_DEFAULT_NAME
)) {
12665 vty_out(vty
, "router ospf vrf %s\n", ospf
->name
);
12667 vty_out(vty
, "router ospf\n");
12669 if (!ospf
->networks
) {
12674 /* Router ID print. */
12675 if (ospf
->router_id_static
.s_addr
!= INADDR_ANY
)
12676 vty_out(vty
, " ospf router-id %pI4\n",
12677 &ospf
->router_id_static
);
12679 /* zebra opaque attributes configuration. */
12680 if (CHECK_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
))
12681 vty_out(vty
, " ospf send-extra-data zebra\n");
12683 /* ABR type print. */
12684 if (ospf
->abr_type
!= OSPF_ABR_DEFAULT
)
12685 vty_out(vty
, " ospf abr-type %s\n",
12686 ospf_abr_type_str
[ospf
->abr_type
]);
12688 /* log-adjacency-changes flag print. */
12689 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
12690 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
))
12691 vty_out(vty
, " log-adjacency-changes detail\n");
12692 else if (!SAVE_OSPF_LOG_ADJACENCY_CHANGES
)
12693 vty_out(vty
, " log-adjacency-changes\n");
12694 } else if (SAVE_OSPF_LOG_ADJACENCY_CHANGES
) {
12695 vty_out(vty
, " no log-adjacency-changes\n");
12698 /* RFC1583 compatibility flag print -- Compatible with CISCO
12700 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
))
12701 vty_out(vty
, " compatible rfc1583\n");
12703 /* auto-cost reference-bandwidth configuration. */
12704 if (ospf
->ref_bandwidth
!= OSPF_DEFAULT_REF_BANDWIDTH
) {
12706 "! Important: ensure reference bandwidth is consistent across all routers\n");
12707 vty_out(vty
, " auto-cost reference-bandwidth %d\n",
12708 ospf
->ref_bandwidth
);
12711 /* SPF timers print. */
12712 if (ospf
->spf_delay
!= OSPF_SPF_DELAY_DEFAULT
12713 || ospf
->spf_holdtime
!= OSPF_SPF_HOLDTIME_DEFAULT
12714 || ospf
->spf_max_holdtime
!= OSPF_SPF_MAX_HOLDTIME_DEFAULT
)
12715 vty_out(vty
, " timers throttle spf %d %d %d\n", ospf
->spf_delay
,
12716 ospf
->spf_holdtime
, ospf
->spf_max_holdtime
);
12718 /* LSA timers print. */
12719 if (ospf
->min_ls_interval
!= OSPF_MIN_LS_INTERVAL
)
12720 vty_out(vty
, " timers throttle lsa all %d\n",
12721 ospf
->min_ls_interval
);
12722 if (ospf
->min_ls_arrival
!= OSPF_MIN_LS_ARRIVAL
)
12723 vty_out(vty
, " timers lsa min-arrival %d\n",
12724 ospf
->min_ls_arrival
);
12726 /* Write multiplier print. */
12727 if (ospf
->write_oi_count
!= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
)
12728 vty_out(vty
, " ospf write-multiplier %d\n",
12729 ospf
->write_oi_count
);
12731 if (ospf
->max_multipath
!= MULTIPATH_NUM
)
12732 vty_out(vty
, " maximum-paths %d\n", ospf
->max_multipath
);
12734 /* Max-metric router-lsa print */
12735 config_write_stub_router(vty
, ospf
);
12737 /* SPF refresh parameters print. */
12738 if (ospf
->lsa_refresh_interval
!= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
12739 vty_out(vty
, " refresh timer %d\n", ospf
->lsa_refresh_interval
);
12741 /* Redistribute information print. */
12742 config_write_ospf_redistribute(vty
, ospf
);
12744 /* Graceful Restart print */
12745 config_write_ospf_gr(vty
, ospf
);
12746 config_write_ospf_gr_helper(vty
, ospf
);
12748 /* Print external route aggregation. */
12749 config_write_ospf_external_aggregator(vty
, ospf
);
12751 /* passive-interface print. */
12752 if (ospf
->passive_interface_default
== OSPF_IF_PASSIVE
)
12753 vty_out(vty
, " passive-interface default\n");
12755 /* proactive-arp print. */
12756 if (ospf
->proactive_arp
!= OSPF_PROACTIVE_ARP_DEFAULT
) {
12757 if (ospf
->proactive_arp
)
12758 vty_out(vty
, " proactive-arp\n");
12760 vty_out(vty
, " no proactive-arp\n");
12763 /* TI-LFA print. */
12764 if (ospf
->ti_lfa_enabled
) {
12765 if (ospf
->ti_lfa_protection_type
== OSPF_TI_LFA_NODE_PROTECTION
)
12766 vty_out(vty
, " fast-reroute ti-lfa node-protection\n");
12768 vty_out(vty
, " fast-reroute ti-lfa\n");
12771 /* Network area print. */
12772 config_write_network_area(vty
, ospf
);
12774 /* Area config print. */
12775 config_write_ospf_area(vty
, ospf
);
12777 /* static neighbor print. */
12778 config_write_ospf_nbr_nbma(vty
, ospf
);
12780 /* Virtual-Link print. */
12781 config_write_virtual_link(vty
, ospf
);
12783 /* Default metric configuration. */
12784 config_write_ospf_default_metric(vty
, ospf
);
12786 /* Distribute-list and default-information print. */
12787 config_write_ospf_distribute(vty
, ospf
);
12789 /* Distance configuration. */
12790 config_write_ospf_distance(vty
, ospf
);
12792 ospf_opaque_config_write_router(vty
, ospf
);
12794 /* LDP-Sync print */
12795 ospf_ldp_sync_write_config(vty
, ospf
);
12797 vty_out(vty
, "exit\n");
12803 /* OSPF configuration write function. */
12804 static int ospf_config_write(struct vty
*vty
)
12807 struct listnode
*ospf_node
= NULL
;
12810 if (listcount(om
->ospf
) == 0)
12813 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, ospf_node
, ospf
)) {
12814 /* VRF Default check if it is running.
12815 * Upon daemon start, there could be default instance
12816 * in absence of 'router ospf'/oi_running is disabled. */
12817 if (ospf
->vrf_id
== VRF_DEFAULT
&& ospf
->oi_running
)
12818 write
+= ospf_config_write_one(vty
, ospf
);
12819 /* For Non-Default VRF simply display the configuration,
12820 * even if it is not oi_running. */
12821 else if (ospf
->vrf_id
!= VRF_DEFAULT
)
12822 write
+= ospf_config_write_one(vty
, ospf
);
12827 void ospf_vty_show_init(void)
12829 /* "show ip ospf" commands. */
12830 install_element(VIEW_NODE
, &show_ip_ospf_cmd
);
12832 install_element(VIEW_NODE
, &show_ip_ospf_instance_cmd
);
12834 /* "show ip ospf database" commands. */
12835 install_element(VIEW_NODE
, &show_ip_ospf_database_cmd
);
12836 install_element(VIEW_NODE
, &show_ip_ospf_database_max_cmd
);
12837 install_element(VIEW_NODE
,
12838 &show_ip_ospf_database_type_adv_router_cmd
);
12839 install_element(VIEW_NODE
,
12840 &show_ip_ospf_instance_database_type_adv_router_cmd
);
12841 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_cmd
);
12842 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_max_cmd
);
12844 /* "show ip ospf interface" commands. */
12845 install_element(VIEW_NODE
, &show_ip_ospf_interface_cmd
);
12847 install_element(VIEW_NODE
, &show_ip_ospf_instance_interface_cmd
);
12848 /* "show ip ospf interface traffic */
12849 install_element(VIEW_NODE
, &show_ip_ospf_interface_traffic_cmd
);
12851 /* "show ip ospf neighbor" commands. */
12852 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_detail_cmd
);
12853 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_cmd
);
12854 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_id_cmd
);
12855 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_all_cmd
);
12856 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_cmd
);
12857 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_cmd
);
12858 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_all_cmd
);
12860 install_element(VIEW_NODE
,
12861 &show_ip_ospf_instance_neighbor_int_detail_cmd
);
12862 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_int_cmd
);
12863 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_id_cmd
);
12864 install_element(VIEW_NODE
,
12865 &show_ip_ospf_instance_neighbor_detail_all_cmd
);
12866 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_detail_cmd
);
12867 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_cmd
);
12868 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_all_cmd
);
12870 /* "show ip ospf route" commands. */
12871 install_element(VIEW_NODE
, &show_ip_ospf_route_cmd
);
12872 install_element(VIEW_NODE
, &show_ip_ospf_border_routers_cmd
);
12873 install_element(VIEW_NODE
, &show_ip_ospf_reachable_routers_cmd
);
12874 install_element(VIEW_NODE
, &show_ip_ospf_route_orr_cmd
);
12876 install_element(VIEW_NODE
, &show_ip_ospf_instance_route_cmd
);
12877 install_element(VIEW_NODE
, &show_ip_ospf_instance_border_routers_cmd
);
12878 install_element(VIEW_NODE
,
12879 &show_ip_ospf_instance_reachable_routers_cmd
);
12880 install_element(VIEW_NODE
, &show_ip_ospf_instance_route_orr_cmd
);
12882 /* "show ip ospf vrfs" commands. */
12883 install_element(VIEW_NODE
, &show_ip_ospf_vrfs_cmd
);
12885 /* "show ip ospf gr-helper details" command */
12886 install_element(VIEW_NODE
, &show_ip_ospf_gr_helper_cmd
);
12888 /* "show ip ospf summary-address" command */
12889 install_element(VIEW_NODE
, &show_ip_ospf_external_aggregator_cmd
);
12892 /* Initialization of OSPF interface. */
12893 static void ospf_vty_if_init(void)
12895 /* Install interface node. */
12896 if_cmd_init(config_write_interface
);
12898 /* "ip ospf authentication" commands. */
12899 install_element(INTERFACE_NODE
, &ip_ospf_authentication_args_addr_cmd
);
12900 install_element(INTERFACE_NODE
, &ip_ospf_authentication_addr_cmd
);
12901 install_element(INTERFACE_NODE
,
12902 &no_ip_ospf_authentication_args_addr_cmd
);
12903 install_element(INTERFACE_NODE
, &no_ip_ospf_authentication_addr_cmd
);
12904 install_element(INTERFACE_NODE
, &ip_ospf_authentication_key_addr_cmd
);
12905 install_element(INTERFACE_NODE
,
12906 &no_ip_ospf_authentication_key_authkey_addr_cmd
);
12907 install_element(INTERFACE_NODE
,
12908 &no_ospf_authentication_key_authkey_addr_cmd
);
12910 /* "ip ospf message-digest-key" commands. */
12911 install_element(INTERFACE_NODE
, &ip_ospf_message_digest_key_cmd
);
12912 install_element(INTERFACE_NODE
, &no_ip_ospf_message_digest_key_cmd
);
12914 /* "ip ospf cost" commands. */
12915 install_element(INTERFACE_NODE
, &ip_ospf_cost_cmd
);
12916 install_element(INTERFACE_NODE
, &no_ip_ospf_cost_cmd
);
12918 /* "ip ospf mtu-ignore" commands. */
12919 install_element(INTERFACE_NODE
, &ip_ospf_mtu_ignore_addr_cmd
);
12920 install_element(INTERFACE_NODE
, &no_ip_ospf_mtu_ignore_addr_cmd
);
12922 /* "ip ospf dead-interval" commands. */
12923 install_element(INTERFACE_NODE
, &ip_ospf_dead_interval_cmd
);
12924 install_element(INTERFACE_NODE
,
12925 &ip_ospf_dead_interval_minimal_addr_cmd
);
12926 install_element(INTERFACE_NODE
, &no_ip_ospf_dead_interval_cmd
);
12928 /* "ip ospf hello-interval" commands. */
12929 install_element(INTERFACE_NODE
, &ip_ospf_hello_interval_cmd
);
12930 install_element(INTERFACE_NODE
, &no_ip_ospf_hello_interval_cmd
);
12932 /* "ip ospf network" commands. */
12933 install_element(INTERFACE_NODE
, &ip_ospf_network_cmd
);
12934 install_element(INTERFACE_NODE
, &no_ip_ospf_network_cmd
);
12936 /* "ip ospf priority" commands. */
12937 install_element(INTERFACE_NODE
, &ip_ospf_priority_cmd
);
12938 install_element(INTERFACE_NODE
, &no_ip_ospf_priority_cmd
);
12940 /* "ip ospf retransmit-interval" commands. */
12941 install_element(INTERFACE_NODE
, &ip_ospf_retransmit_interval_addr_cmd
);
12942 install_element(INTERFACE_NODE
,
12943 &no_ip_ospf_retransmit_interval_addr_cmd
);
12945 /* "ip ospf transmit-delay" commands. */
12946 install_element(INTERFACE_NODE
, &ip_ospf_transmit_delay_addr_cmd
);
12947 install_element(INTERFACE_NODE
, &no_ip_ospf_transmit_delay_addr_cmd
);
12949 /* "ip ospf area" commands. */
12950 install_element(INTERFACE_NODE
, &ip_ospf_area_cmd
);
12951 install_element(INTERFACE_NODE
, &no_ip_ospf_area_cmd
);
12953 /* "ip ospf passive" commands. */
12954 install_element(INTERFACE_NODE
, &ip_ospf_passive_cmd
);
12955 install_element(INTERFACE_NODE
, &no_ip_ospf_passive_cmd
);
12957 /* These commands are compatibitliy for previous version. */
12958 install_element(INTERFACE_NODE
, &ospf_authentication_key_cmd
);
12959 install_element(INTERFACE_NODE
, &ospf_message_digest_key_cmd
);
12960 install_element(INTERFACE_NODE
, &no_ospf_message_digest_key_cmd
);
12961 install_element(INTERFACE_NODE
, &ospf_dead_interval_cmd
);
12962 install_element(INTERFACE_NODE
, &no_ospf_dead_interval_cmd
);
12963 install_element(INTERFACE_NODE
, &ospf_hello_interval_cmd
);
12964 install_element(INTERFACE_NODE
, &no_ospf_hello_interval_cmd
);
12965 install_element(INTERFACE_NODE
, &ospf_cost_cmd
);
12966 install_element(INTERFACE_NODE
, &no_ospf_cost_cmd
);
12967 install_element(INTERFACE_NODE
, &ospf_network_cmd
);
12968 install_element(INTERFACE_NODE
, &no_ospf_network_cmd
);
12969 install_element(INTERFACE_NODE
, &ospf_priority_cmd
);
12970 install_element(INTERFACE_NODE
, &no_ospf_priority_cmd
);
12971 install_element(INTERFACE_NODE
, &ospf_retransmit_interval_cmd
);
12972 install_element(INTERFACE_NODE
, &no_ospf_retransmit_interval_cmd
);
12973 install_element(INTERFACE_NODE
, &ospf_transmit_delay_cmd
);
12974 install_element(INTERFACE_NODE
, &no_ospf_transmit_delay_cmd
);
12977 static void ospf_vty_zebra_init(void)
12979 install_element(OSPF_NODE
, &ospf_redistribute_source_cmd
);
12980 install_element(OSPF_NODE
, &no_ospf_redistribute_source_cmd
);
12981 install_element(OSPF_NODE
, &ospf_redistribute_instance_source_cmd
);
12982 install_element(OSPF_NODE
, &no_ospf_redistribute_instance_source_cmd
);
12984 install_element(OSPF_NODE
, &ospf_distribute_list_out_cmd
);
12985 install_element(OSPF_NODE
, &no_ospf_distribute_list_out_cmd
);
12987 install_element(OSPF_NODE
, &ospf_default_information_originate_cmd
);
12988 install_element(OSPF_NODE
, &no_ospf_default_information_originate_cmd
);
12990 install_element(OSPF_NODE
, &ospf_default_metric_cmd
);
12991 install_element(OSPF_NODE
, &no_ospf_default_metric_cmd
);
12993 install_element(OSPF_NODE
, &ospf_distance_cmd
);
12994 install_element(OSPF_NODE
, &no_ospf_distance_cmd
);
12995 install_element(OSPF_NODE
, &no_ospf_distance_ospf_cmd
);
12996 install_element(OSPF_NODE
, &ospf_distance_ospf_cmd
);
12998 /*Ospf garcefull restart helper configurations */
12999 install_element(OSPF_NODE
, &ospf_gr_helper_enable_cmd
);
13000 install_element(OSPF_NODE
, &no_ospf_gr_helper_enable_cmd
);
13001 install_element(OSPF_NODE
, &ospf_gr_helper_enable_lsacheck_cmd
);
13002 install_element(OSPF_NODE
, &no_ospf_gr_helper_enable_lsacheck_cmd
);
13003 install_element(OSPF_NODE
, &ospf_gr_helper_supported_grace_time_cmd
);
13004 install_element(OSPF_NODE
, &no_ospf_gr_helper_supported_grace_time_cmd
);
13005 install_element(OSPF_NODE
, &ospf_gr_helper_planned_only_cmd
);
13006 install_element(OSPF_NODE
, &no_ospf_gr_helper_planned_only_cmd
);
13008 /* External LSA summarisation config commands.*/
13009 install_element(OSPF_NODE
, &ospf_external_route_aggregation_cmd
);
13010 install_element(OSPF_NODE
, &no_ospf_external_route_aggregation_cmd
);
13011 install_element(OSPF_NODE
,
13012 &ospf_external_route_aggregation_no_adrvertise_cmd
);
13013 install_element(OSPF_NODE
,
13014 &no_ospf_external_route_aggregation_no_adrvertise_cmd
);
13015 install_element(OSPF_NODE
, &ospf_route_aggregation_timer_cmd
);
13016 install_element(OSPF_NODE
, &no_ospf_route_aggregation_timer_cmd
);
13019 static int ospf_config_write(struct vty
*vty
);
13020 static struct cmd_node ospf_node
= {
13023 .parent_node
= CONFIG_NODE
,
13024 .prompt
= "%s(config-router)# ",
13025 .config_write
= ospf_config_write
,
13028 static void ospf_interface_clear(struct interface
*ifp
)
13030 if (!if_is_operative(ifp
))
13033 if (IS_DEBUG_OSPF(ism
, ISM_EVENTS
))
13034 zlog_debug("ISM[%s]: clear by reset", ifp
->name
);
13036 ospf_if_reset(ifp
);
13039 DEFUN (clear_ip_ospf_interface
,
13040 clear_ip_ospf_interface_cmd
,
13041 "clear ip ospf [vrf NAME] interface [IFNAME]",
13044 "OSPF information\n"
13046 "Interface information\n"
13047 "Interface name\n")
13049 int idx_ifname
= 0;
13051 struct interface
*ifp
;
13052 struct listnode
*node
;
13053 struct ospf
*ospf
= NULL
;
13054 char *vrf_name
= NULL
;
13055 vrf_id_t vrf_id
= VRF_DEFAULT
;
13056 struct vrf
*vrf
= NULL
;
13058 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
13059 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
13060 if (vrf_name
&& strmatch(vrf_name
, VRF_DEFAULT_NAME
))
13063 vrf
= vrf_lookup_by_name(vrf_name
);
13065 vrf_id
= vrf
->vrf_id
;
13067 if (!argv_find(argv
, argc
, "IFNAME", &idx_ifname
)) {
13068 /* Clear all the ospfv2 interfaces. */
13069 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
13070 if (vrf_id
!= ospf
->vrf_id
)
13073 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
13074 FOR_ALL_INTERFACES (vrf
, ifp
)
13075 ospf_interface_clear(ifp
);
13078 /* Interface name is specified. */
13079 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf_id
);
13081 vty_out(vty
, "No such interface name\n");
13083 ospf_interface_clear(ifp
);
13086 return CMD_SUCCESS
;
13089 DEFPY_HIDDEN(ospf_lsa_refresh_timer
, ospf_lsa_refresh_timer_cmd
,
13090 "[no$no] ospf lsa-refresh [(120-1800)]$value",
13092 "OSPF lsa refresh timer\n"
13093 "timer value in seconds\n")
13095 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
13098 ospf
->lsa_refresh_timer
= OSPF_LS_REFRESH_TIME
;
13100 ospf
->lsa_refresh_timer
= value
;
13102 return CMD_SUCCESS
;
13105 DEFPY_HIDDEN(ospf_maxage_delay_timer
, ospf_maxage_delay_timer_cmd
,
13106 "[no$no] ospf maxage-delay [(0-60)]$value",
13108 "OSPF lsa maxage delay timer\n"
13109 "timer value in seconds\n")
13111 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
13114 ospf
->maxage_delay
= OSPF_LSA_MAXAGE_REMOVE_DELAY_DEFAULT
;
13116 ospf
->maxage_delay
= value
;
13118 THREAD_OFF(ospf
->t_maxage
);
13119 OSPF_TIMER_ON(ospf
->t_maxage
, ospf_maxage_lsa_remover
,
13120 ospf
->maxage_delay
);
13122 return CMD_SUCCESS
;
13125 void ospf_vty_clear_init(void)
13127 install_element(ENABLE_NODE
, &clear_ip_ospf_interface_cmd
);
13128 install_element(ENABLE_NODE
, &clear_ip_ospf_process_cmd
);
13129 install_element(ENABLE_NODE
, &clear_ip_ospf_neighbor_cmd
);
13133 /* Install OSPF related vty commands. */
13134 void ospf_vty_init(void)
13136 /* Install ospf top node. */
13137 install_node(&ospf_node
);
13139 /* "router ospf" commands. */
13140 install_element(CONFIG_NODE
, &router_ospf_cmd
);
13141 install_element(CONFIG_NODE
, &no_router_ospf_cmd
);
13144 install_default(OSPF_NODE
);
13146 /* "ospf router-id" commands. */
13147 install_element(OSPF_NODE
, &ospf_router_id_cmd
);
13148 install_element(OSPF_NODE
, &ospf_router_id_old_cmd
);
13149 install_element(OSPF_NODE
, &no_ospf_router_id_cmd
);
13151 /* "passive-interface" commands. */
13152 install_element(OSPF_NODE
, &ospf_passive_interface_default_cmd
);
13153 install_element(OSPF_NODE
, &ospf_passive_interface_addr_cmd
);
13154 install_element(OSPF_NODE
, &no_ospf_passive_interface_default_cmd
);
13155 install_element(OSPF_NODE
, &no_ospf_passive_interface_addr_cmd
);
13157 /* "ospf abr-type" commands. */
13158 install_element(OSPF_NODE
, &ospf_abr_type_cmd
);
13159 install_element(OSPF_NODE
, &no_ospf_abr_type_cmd
);
13161 /* "ospf log-adjacency-changes" commands. */
13162 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_cmd
);
13163 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_detail_cmd
);
13164 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_cmd
);
13165 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_detail_cmd
);
13167 /* "ospf rfc1583-compatible" commands. */
13168 install_element(OSPF_NODE
, &ospf_compatible_rfc1583_cmd
);
13169 install_element(OSPF_NODE
, &no_ospf_compatible_rfc1583_cmd
);
13170 install_element(OSPF_NODE
, &ospf_rfc1583_flag_cmd
);
13171 install_element(OSPF_NODE
, &no_ospf_rfc1583_flag_cmd
);
13173 /* "ospf send-extra-data zebra" commands. */
13174 install_element(OSPF_NODE
, &ospf_send_extra_data_cmd
);
13176 /* "network area" commands. */
13177 install_element(OSPF_NODE
, &ospf_network_area_cmd
);
13178 install_element(OSPF_NODE
, &no_ospf_network_area_cmd
);
13180 /* "area authentication" commands. */
13181 install_element(OSPF_NODE
,
13182 &ospf_area_authentication_message_digest_cmd
);
13183 install_element(OSPF_NODE
, &ospf_area_authentication_cmd
);
13184 install_element(OSPF_NODE
, &no_ospf_area_authentication_cmd
);
13186 /* "area range" commands. */
13187 install_element(OSPF_NODE
, &ospf_area_range_cmd
);
13188 install_element(OSPF_NODE
, &ospf_area_range_cost_cmd
);
13189 install_element(OSPF_NODE
, &ospf_area_range_not_advertise_cmd
);
13190 install_element(OSPF_NODE
, &no_ospf_area_range_cmd
);
13191 install_element(OSPF_NODE
, &no_ospf_area_range_substitute_cmd
);
13193 /* "area virtual-link" commands. */
13194 install_element(OSPF_NODE
, &ospf_area_vlink_cmd
);
13195 install_element(OSPF_NODE
, &ospf_area_vlink_intervals_cmd
);
13196 install_element(OSPF_NODE
, &no_ospf_area_vlink_cmd
);
13197 install_element(OSPF_NODE
, &no_ospf_area_vlink_intervals_cmd
);
13200 /* "area stub" commands. */
13201 install_element(OSPF_NODE
, &ospf_area_stub_no_summary_cmd
);
13202 install_element(OSPF_NODE
, &ospf_area_stub_cmd
);
13203 install_element(OSPF_NODE
, &no_ospf_area_stub_no_summary_cmd
);
13204 install_element(OSPF_NODE
, &no_ospf_area_stub_cmd
);
13206 /* "area nssa" commands. */
13207 install_element(OSPF_NODE
, &ospf_area_nssa_cmd
);
13208 install_element(OSPF_NODE
, &ospf_area_nssa_translate_cmd
);
13209 install_element(OSPF_NODE
, &ospf_area_nssa_no_summary_cmd
);
13210 install_element(OSPF_NODE
, &no_ospf_area_nssa_no_summary_cmd
);
13211 install_element(OSPF_NODE
, &ospf_area_nssa_suppress_fa_cmd
);
13212 install_element(OSPF_NODE
, &no_ospf_area_nssa_suppress_fa_cmd
);
13213 install_element(OSPF_NODE
, &no_ospf_area_nssa_cmd
);
13215 install_element(OSPF_NODE
, &ospf_area_default_cost_cmd
);
13216 install_element(OSPF_NODE
, &no_ospf_area_default_cost_cmd
);
13218 install_element(OSPF_NODE
, &ospf_area_shortcut_cmd
);
13219 install_element(OSPF_NODE
, &no_ospf_area_shortcut_cmd
);
13221 install_element(OSPF_NODE
, &ospf_area_export_list_cmd
);
13222 install_element(OSPF_NODE
, &no_ospf_area_export_list_cmd
);
13224 install_element(OSPF_NODE
, &ospf_area_filter_list_cmd
);
13225 install_element(OSPF_NODE
, &no_ospf_area_filter_list_cmd
);
13227 install_element(OSPF_NODE
, &ospf_area_import_list_cmd
);
13228 install_element(OSPF_NODE
, &no_ospf_area_import_list_cmd
);
13230 /* SPF timer commands */
13231 install_element(OSPF_NODE
, &ospf_timers_throttle_spf_cmd
);
13232 install_element(OSPF_NODE
, &no_ospf_timers_throttle_spf_cmd
);
13234 /* LSA timers commands */
13235 install_element(OSPF_NODE
, &ospf_timers_min_ls_interval_cmd
);
13236 install_element(OSPF_NODE
, &no_ospf_timers_min_ls_interval_cmd
);
13237 install_element(OSPF_NODE
, &ospf_timers_lsa_min_arrival_cmd
);
13238 install_element(OSPF_NODE
, &no_ospf_timers_lsa_min_arrival_cmd
);
13240 /* refresh timer commands */
13241 install_element(OSPF_NODE
, &ospf_refresh_timer_cmd
);
13242 install_element(OSPF_NODE
, &no_ospf_refresh_timer_val_cmd
);
13244 /* max-metric commands */
13245 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_admin_cmd
);
13246 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_admin_cmd
);
13247 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_startup_cmd
);
13248 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_startup_cmd
);
13249 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_shutdown_cmd
);
13250 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_shutdown_cmd
);
13252 /* reference bandwidth commands */
13253 install_element(OSPF_NODE
, &ospf_auto_cost_reference_bandwidth_cmd
);
13254 install_element(OSPF_NODE
, &no_ospf_auto_cost_reference_bandwidth_cmd
);
13256 /* "neighbor" commands. */
13257 install_element(OSPF_NODE
, &ospf_neighbor_cmd
);
13258 install_element(OSPF_NODE
, &ospf_neighbor_poll_interval_cmd
);
13259 install_element(OSPF_NODE
, &no_ospf_neighbor_cmd
);
13260 install_element(OSPF_NODE
, &no_ospf_neighbor_poll_cmd
);
13262 /* write multiplier commands */
13263 install_element(OSPF_NODE
, &ospf_write_multiplier_cmd
);
13264 install_element(OSPF_NODE
, &write_multiplier_cmd
);
13265 install_element(OSPF_NODE
, &no_ospf_write_multiplier_cmd
);
13266 install_element(OSPF_NODE
, &no_write_multiplier_cmd
);
13268 /* "proactive-arp" commands. */
13269 install_element(OSPF_NODE
, &ospf_proactive_arp_cmd
);
13270 install_element(OSPF_NODE
, &no_ospf_proactive_arp_cmd
);
13272 /* TI-LFA commands */
13273 install_element(OSPF_NODE
, &ospf_ti_lfa_cmd
);
13274 install_element(OSPF_NODE
, &no_ospf_ti_lfa_cmd
);
13276 /* Max path configurations */
13277 install_element(OSPF_NODE
, &ospf_max_multipath_cmd
);
13278 install_element(OSPF_NODE
, &no_ospf_max_multipath_cmd
);
13280 vrf_cmd_init(NULL
);
13282 install_element(OSPF_NODE
, &ospf_lsa_refresh_timer_cmd
);
13283 install_element(OSPF_NODE
, &ospf_maxage_delay_timer_cmd
);
13285 /* Init interface related vty commands. */
13286 ospf_vty_if_init();
13288 /* Init zebra related vty commands. */
13289 ospf_vty_zebra_init();