2 * Copyright (C) 2005 6WIND <alain.ritoux@6wind.com>
3 * Copyright (C) 2000 Toshiaki Takada
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
38 #include "lib/printfrr.h"
40 #include "ospfd/ospfd.h"
41 #include "ospfd/ospf_asbr.h"
42 #include "ospfd/ospf_lsa.h"
43 #include "ospfd/ospf_lsdb.h"
44 #include "ospfd/ospf_ism.h"
45 #include "ospfd/ospf_interface.h"
46 #include "ospfd/ospf_nsm.h"
47 #include "ospfd/ospf_neighbor.h"
48 #include "ospfd/ospf_flood.h"
49 #include "ospfd/ospf_abr.h"
50 #include "ospfd/ospf_spf.h"
51 #include "ospfd/ospf_route.h"
52 #include "ospfd/ospf_zebra.h"
53 /*#include "ospfd/ospf_routemap.h" */
54 #include "ospfd/ospf_vty.h"
55 #include "ospfd/ospf_dump.h"
56 #include "ospfd/ospf_bfd.h"
57 #include "ospfd/ospf_ldp_sync.h"
60 FRR_CFG_DEFAULT_BOOL(OSPF_LOG_ADJACENCY_CHANGES
,
61 { .val_bool
= true, .match_profile
= "datacenter", },
62 { .val_bool
= false },
65 static const char *const ospf_network_type_str
[] = {
66 "Null", "POINTOPOINT", "BROADCAST", "NBMA", "POINTOMULTIPOINT",
67 "VIRTUALLINK", "LOOPBACK"};
69 /* Utility functions. */
70 int str2area_id(const char *str
, struct in_addr
*area_id
, int *area_id_fmt
)
74 area_id
->s_addr
= htonl(strtoul(str
, &ep
, 10));
75 if (*ep
&& !inet_aton(str
, area_id
))
79 *ep
? OSPF_AREA_ID_FMT_DOTTEDQUAD
: OSPF_AREA_ID_FMT_DECIMAL
;
84 static void area_id2str(char *buf
, int length
, struct in_addr
*area_id
,
87 if (area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
88 inet_ntop(AF_INET
, area_id
, buf
, length
);
90 snprintf(buf
, length
, "%lu",
91 (unsigned long)ntohl(area_id
->s_addr
));
94 static int str2metric(const char *str
, int *metric
)
100 *metric
= strtol(str
, NULL
, 10);
101 if (*metric
< 0 || *metric
> 16777214) {
102 /* vty_out (vty, "OSPF metric value is invalid\n"); */
109 static int str2metric_type(const char *str
, int *metric_type
)
115 if (strncmp(str
, "1", 1) == 0)
116 *metric_type
= EXTERNAL_METRIC_TYPE_1
;
117 else if (strncmp(str
, "2", 1) == 0)
118 *metric_type
= EXTERNAL_METRIC_TYPE_2
;
125 int ospf_oi_count(struct interface
*ifp
)
127 struct route_node
*rn
;
130 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
137 #define OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf) \
138 if (argv_find(argv, argc, "vrf", &idx_vrf)) { \
139 vrf_name = argv[idx_vrf + 1]->arg; \
140 all_vrf = strmatch(vrf_name, "all"); \
143 static int ospf_router_cmd_parse(struct vty
*vty
, struct cmd_token
*argv
[],
144 const int argc
, unsigned short *instance
,
145 const char **vrf_name
)
147 int idx_vrf
= 0, idx_inst
= 0;
150 if (argv_find(argv
, argc
, "(1-65535)", &idx_inst
)) {
151 if (ospf_instance
== 0) {
153 "%% OSPF is not running in instance mode\n");
154 return CMD_WARNING_CONFIG_FAILED
;
157 *instance
= strtoul(argv
[idx_inst
]->arg
, NULL
, 10);
160 *vrf_name
= VRF_DEFAULT_NAME
;
161 if (argv_find(argv
, argc
, "vrf", &idx_vrf
)) {
162 if (ospf_instance
!= 0) {
164 "%% VRF is not supported in instance mode\n");
165 return CMD_WARNING_CONFIG_FAILED
;
168 *vrf_name
= argv
[idx_vrf
+ 1]->arg
;
174 static void ospf_show_vrf_name(struct ospf
*ospf
, struct vty
*vty
,
175 json_object
*json
, uint8_t use_vrf
)
179 json_object_string_add(json
, "vrfName",
180 ospf_get_name(ospf
));
181 json_object_int_add(json
, "vrfId", ospf
->vrf_id
);
183 vty_out(vty
, "VRF Name: %s\n", ospf_get_name(ospf
));
187 #include "ospfd/ospf_vty_clippy.c"
189 DEFUN_NOSH (router_ospf
,
191 "router ospf [{(1-65535)|vrf NAME}]",
192 "Enable a routing process\n"
193 "Start OSPF configuration\n"
197 unsigned short instance
;
198 const char *vrf_name
;
199 bool created
= false;
203 ret
= ospf_router_cmd_parse(vty
, argv
, argc
, &instance
, &vrf_name
);
204 if (ret
!= CMD_SUCCESS
)
207 if (instance
!= ospf_instance
) {
208 VTY_PUSH_CONTEXT_NULL(OSPF_NODE
);
209 return CMD_NOT_MY_INSTANCE
;
212 ospf
= ospf_get(instance
, vrf_name
, &created
);
215 if (DFLT_OSPF_LOG_ADJACENCY_CHANGES
)
216 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
218 if (IS_DEBUG_OSPF_EVENT
)
220 "Config command 'router ospf %d' received, vrf %s id %u oi_running %u",
221 ospf
->instance
, ospf_get_name(ospf
), ospf
->vrf_id
,
224 VTY_PUSH_CONTEXT(OSPF_NODE
, ospf
);
229 DEFUN (no_router_ospf
,
231 "no router ospf [{(1-65535)|vrf NAME}]",
233 "Enable a routing process\n"
234 "Start OSPF configuration\n"
238 unsigned short instance
;
239 const char *vrf_name
;
243 ret
= ospf_router_cmd_parse(vty
, argv
, argc
, &instance
, &vrf_name
);
244 if (ret
!= CMD_SUCCESS
)
247 if (instance
!= ospf_instance
)
248 return CMD_NOT_MY_INSTANCE
;
250 ospf
= ospf_lookup(instance
, vrf_name
);
254 ret
= CMD_WARNING_CONFIG_FAILED
;
260 DEFPY (ospf_router_id
,
262 "ospf router-id A.B.C.D",
263 "OSPF specific commands\n"
264 "router-id for the OSPF process\n"
265 "OSPF router-id in IP address format\n")
267 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
269 struct listnode
*node
;
270 struct ospf_area
*area
;
272 ospf
->router_id_static
= router_id
;
274 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
275 if (area
->full_nbrs
) {
277 "For this router-id change to take effect, use \"clear ip ospf process\" command\n");
281 ospf_router_id_update(ospf
);
286 DEFUN_HIDDEN (ospf_router_id_old
,
287 ospf_router_id_old_cmd
,
289 "router-id for the OSPF process\n"
290 "OSPF router-id in IP address format\n")
292 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
294 struct listnode
*node
;
295 struct ospf_area
*area
;
296 struct in_addr router_id
;
299 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &router_id
);
301 vty_out(vty
, "Please specify Router ID by A.B.C.D\n");
302 return CMD_WARNING_CONFIG_FAILED
;
305 ospf
->router_id_static
= router_id
;
307 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
308 if (area
->full_nbrs
) {
310 "For this router-id change to take effect, use \"clear ip ospf process\" command\n");
314 ospf_router_id_update(ospf
);
319 DEFPY (no_ospf_router_id
,
320 no_ospf_router_id_cmd
,
321 "no ospf router-id [A.B.C.D]",
323 "OSPF specific commands\n"
324 "router-id for the OSPF process\n"
325 "OSPF router-id in IP address format\n")
327 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
328 struct listnode
*node
;
329 struct ospf_area
*area
;
332 if (!IPV4_ADDR_SAME(&ospf
->router_id_static
, &router_id
)) {
333 vty_out(vty
, "%% OSPF router-id doesn't match\n");
334 return CMD_WARNING_CONFIG_FAILED
;
338 ospf
->router_id_static
.s_addr
= 0;
340 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
341 if (area
->full_nbrs
) {
343 "For this router-id change to take effect, use \"clear ip ospf process\" command\n");
347 ospf_router_id_update(ospf
);
353 static void ospf_passive_interface_default_update(struct ospf
*ospf
,
357 struct ospf_interface
*oi
;
359 ospf
->passive_interface_default
= newval
;
361 /* update multicast memberships */
362 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, ln
, oi
))
363 ospf_if_set_multicast(oi
);
366 static void ospf_passive_interface_update(struct interface
*ifp
,
367 struct ospf_if_params
*params
,
368 struct in_addr addr
, uint8_t newval
)
370 struct route_node
*rn
;
372 if (OSPF_IF_PARAM_CONFIGURED(params
, passive_interface
)) {
373 if (params
->passive_interface
== newval
)
376 params
->passive_interface
= newval
;
377 UNSET_IF_PARAM(params
, passive_interface
);
378 if (params
!= IF_DEF_PARAMS(ifp
)) {
379 ospf_free_if_params(ifp
, addr
);
380 ospf_if_update_params(ifp
, addr
);
383 params
->passive_interface
= newval
;
384 SET_IF_PARAM(params
, passive_interface
);
388 * XXX We should call ospf_if_set_multicast on exactly those
389 * interfaces for which the passive property changed. It is too much
390 * work to determine this set, so we do this for every interface.
391 * This is safe and reasonable because ospf_if_set_multicast uses a
392 * record of joined groups to avoid systems calls if the desired
393 * memberships match the current memership.
396 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
397 struct ospf_interface
*oi
= rn
->info
;
400 ospf_if_set_multicast(oi
);
404 * XXX It is not clear what state transitions the interface needs to
405 * undergo when going from active to passive and vice versa. Fixing
406 * this will require precise identification of interfaces having such a
411 DEFUN (ospf_passive_interface_default
,
412 ospf_passive_interface_default_cmd
,
413 "passive-interface default",
414 "Suppress routing updates on an interface\n"
415 "Suppress routing updates on interfaces by default\n")
417 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
419 ospf_passive_interface_default_update(ospf
, OSPF_IF_PASSIVE
);
424 DEFUN_HIDDEN (ospf_passive_interface_addr
,
425 ospf_passive_interface_addr_cmd
,
426 "passive-interface IFNAME [A.B.C.D]",
427 "Suppress routing updates on an interface\n"
431 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
433 struct interface
*ifp
= NULL
;
434 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
435 struct ospf_if_params
*params
;
439 "This command is deprecated, because it is not VRF-aware.\n");
441 "Please, use \"ip ospf passive\" on an interface instead.\n");
443 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
444 ifp
= if_get_by_name(argv
[1]->arg
, ospf
->vrf_id
, ospf
->name
);
447 vty_out(vty
, "interface %s not found.\n", (char *)argv
[1]->arg
);
448 return CMD_WARNING_CONFIG_FAILED
;
452 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
455 "Please specify interface address by A.B.C.D\n");
456 return CMD_WARNING_CONFIG_FAILED
;
459 params
= ospf_get_if_params(ifp
, addr
);
460 ospf_if_update_params(ifp
, addr
);
462 params
= IF_DEF_PARAMS(ifp
);
465 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_PASSIVE
);
470 DEFUN (no_ospf_passive_interface_default
,
471 no_ospf_passive_interface_default_cmd
,
472 "no passive-interface default",
474 "Allow routing updates on an interface\n"
475 "Allow routing updates on interfaces by default\n")
477 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
479 ospf_passive_interface_default_update(ospf
, OSPF_IF_ACTIVE
);
484 DEFUN_HIDDEN (no_ospf_passive_interface
,
485 no_ospf_passive_interface_addr_cmd
,
486 "no passive-interface IFNAME [A.B.C.D]",
488 "Allow routing updates on an interface\n"
492 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
494 struct interface
*ifp
= NULL
;
495 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
496 struct ospf_if_params
*params
;
500 "This command is deprecated, because it is not VRF-aware.\n");
502 "Please, use \"no ip ospf passive\" on an interface instead.\n");
504 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
505 ifp
= if_get_by_name(argv
[2]->arg
, ospf
->vrf_id
, ospf
->name
);
508 vty_out(vty
, "interface %s not found.\n", (char *)argv
[2]->arg
);
509 return CMD_WARNING_CONFIG_FAILED
;
513 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
516 "Please specify interface address by A.B.C.D\n");
517 return CMD_WARNING_CONFIG_FAILED
;
519 params
= ospf_lookup_if_params(ifp
, addr
);
523 params
= IF_DEF_PARAMS(ifp
);
526 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_ACTIVE
);
532 DEFUN (ospf_network_area
,
533 ospf_network_area_cmd
,
534 "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
535 "Enable routing on an IP network\n"
536 "OSPF network prefix\n"
537 "Set the OSPF area ID\n"
538 "OSPF area ID in IP address format\n"
539 "OSPF area ID as a decimal value\n")
541 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
542 int idx_ipv4_prefixlen
= 1;
543 int idx_ipv4_number
= 3;
544 struct prefix_ipv4 p
;
545 struct in_addr area_id
;
549 if (ospf
->instance
) {
551 "The network command is not supported in multi-instance ospf\n");
552 return CMD_WARNING_CONFIG_FAILED
;
555 count
= ospf_count_area_params(ospf
);
558 "Please remove all ip ospf area x.x.x.x commands first.\n");
559 if (IS_DEBUG_OSPF_EVENT
)
561 "%s ospf vrf %s num of %u ip ospf area x config",
562 __func__
, ospf_get_name(ospf
), count
);
563 return CMD_WARNING_CONFIG_FAILED
;
566 /* Get network prefix and Area ID. */
567 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
568 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
570 ret
= ospf_network_set(ospf
, &p
, area_id
, format
);
572 vty_out(vty
, "There is already same network statement.\n");
573 return CMD_WARNING_CONFIG_FAILED
;
579 DEFUN (no_ospf_network_area
,
580 no_ospf_network_area_cmd
,
581 "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
583 "Enable routing on an IP network\n"
584 "OSPF network prefix\n"
585 "Set the OSPF area ID\n"
586 "OSPF area ID in IP address format\n"
587 "OSPF area ID as a decimal value\n")
589 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
590 int idx_ipv4_prefixlen
= 2;
591 int idx_ipv4_number
= 4;
592 struct prefix_ipv4 p
;
593 struct in_addr area_id
;
596 if (ospf
->instance
) {
598 "The network command is not supported in multi-instance ospf\n");
599 return CMD_WARNING_CONFIG_FAILED
;
602 /* Get network prefix and Area ID. */
603 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
604 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
606 ret
= ospf_network_unset(ospf
, &p
, area_id
);
609 "Can't find specified network area configuration.\n");
610 return CMD_WARNING_CONFIG_FAILED
;
616 DEFUN (ospf_area_range
,
618 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]",
619 "OSPF area parameters\n"
620 "OSPF area ID in IP address format\n"
621 "OSPF area ID as a decimal value\n"
622 "Summarize routes matching address/mask (border routers only)\n"
623 "Area range prefix\n"
624 "Advertise this range (default)\n"
625 "User specified metric for this range\n"
626 "Advertised metric for this range\n")
628 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
629 int idx_ipv4_number
= 1;
630 int idx_ipv4_prefixlen
= 3;
632 struct prefix_ipv4 p
;
633 struct in_addr area_id
;
637 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
638 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
640 ospf_area_range_set(ospf
, area_id
, &p
, OSPF_AREA_RANGE_ADVERTISE
);
641 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
644 cost
= strtoul(argv
[idx_cost
]->arg
, NULL
, 10);
645 ospf_area_range_cost_set(ospf
, area_id
, &p
, cost
);
651 DEFUN (ospf_area_range_cost
,
652 ospf_area_range_cost_cmd
,
653 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M {cost (0-16777215)|substitute A.B.C.D/M}",
654 "OSPF area parameters\n"
655 "OSPF area ID in IP address format\n"
656 "OSPF area ID as a decimal value\n"
657 "Summarize routes matching address/mask (border routers only)\n"
658 "Area range prefix\n"
659 "User specified metric for this range\n"
660 "Advertised metric for this range\n"
661 "Announce area range as another prefix\n"
662 "Network prefix to be announced instead of range\n")
664 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
665 int idx_ipv4_number
= 1;
666 int idx_ipv4_prefixlen
= 3;
668 struct prefix_ipv4 p
, s
;
669 struct in_addr area_id
;
673 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
674 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
676 ospf_area_range_set(ospf
, area_id
, &p
, OSPF_AREA_RANGE_ADVERTISE
);
677 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
680 if (argv_find(argv
, argc
, "cost", &idx
)) {
681 cost
= strtoul(argv
[idx
+ 1]->arg
, NULL
, 10);
682 ospf_area_range_cost_set(ospf
, area_id
, &p
, cost
);
686 if (argv_find(argv
, argc
, "substitute", &idx
)) {
687 str2prefix_ipv4(argv
[idx
+ 1]->arg
, &s
);
688 ospf_area_range_substitute_set(ospf
, area_id
, &p
, &s
);
694 DEFUN (ospf_area_range_not_advertise
,
695 ospf_area_range_not_advertise_cmd
,
696 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise",
697 "OSPF area parameters\n"
698 "OSPF area ID in IP address format\n"
699 "OSPF area ID as a decimal value\n"
700 "Summarize routes matching address/mask (border routers only)\n"
701 "Area range prefix\n"
702 "DoNotAdvertise this range\n")
704 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
705 int idx_ipv4_number
= 1;
706 int idx_ipv4_prefixlen
= 3;
707 struct prefix_ipv4 p
;
708 struct in_addr area_id
;
711 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
712 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
714 ospf_area_range_set(ospf
, area_id
, &p
, 0);
715 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
717 ospf_area_range_substitute_unset(ospf
, area_id
, &p
);
722 DEFUN (no_ospf_area_range
,
723 no_ospf_area_range_cmd
,
724 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]",
726 "OSPF area parameters\n"
727 "OSPF area ID in IP address format\n"
728 "OSPF area ID as a decimal value\n"
729 "Summarize routes matching address/mask (border routers only)\n"
730 "Area range prefix\n"
731 "User specified metric for this range\n"
732 "Advertised metric for this range\n"
733 "Advertise this range (default)\n"
734 "User specified metric for this range\n"
735 "Advertised metric for this range\n"
736 "DoNotAdvertise this range\n")
738 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
739 int idx_ipv4_number
= 2;
740 int idx_ipv4_prefixlen
= 4;
741 struct prefix_ipv4 p
;
742 struct in_addr area_id
;
745 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
746 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
748 ospf_area_range_unset(ospf
, area_id
, &p
);
753 DEFUN (no_ospf_area_range_substitute
,
754 no_ospf_area_range_substitute_cmd
,
755 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
757 "OSPF area parameters\n"
758 "OSPF area ID in IP address format\n"
759 "OSPF area ID as a decimal value\n"
760 "Summarize routes matching address/mask (border routers only)\n"
761 "Area range prefix\n"
762 "Announce area range as another prefix\n"
763 "Network prefix to be announced instead of range\n")
765 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
766 int idx_ipv4_number
= 2;
767 int idx_ipv4_prefixlen
= 4;
768 int idx_ipv4_prefixlen_2
= 6;
769 struct prefix_ipv4 p
, s
;
770 struct in_addr area_id
;
773 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
774 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
775 str2prefix_ipv4(argv
[idx_ipv4_prefixlen_2
]->arg
, &s
);
777 ospf_area_range_substitute_unset(ospf
, area_id
, &p
);
783 /* Command Handler Logic in VLink stuff is delicate!!
785 ALTER AT YOUR OWN RISK!!!!
787 Various dummy values are used to represent 'NoChange' state for
788 VLink configuration NOT being changed by a VLink command, and
789 special syntax is used within the command strings so that the
790 typed in command verbs can be seen in the configuration command
791 bacckend handler. This is to drastically reduce the verbeage
792 required to coe up with a reasonably compatible Cisco VLink command
794 - Matthew Grant <grantma@anathoth.gen.nz>
795 Wed, 21 Feb 2001 15:13:52 +1300
798 /* Configuration data for virtual links
800 struct ospf_vl_config_data
{
801 struct vty
*vty
; /* vty stuff */
802 struct in_addr area_id
; /* area ID from command line */
803 int area_id_fmt
; /* command line area ID format */
804 struct in_addr vl_peer
; /* command line vl_peer */
805 int auth_type
; /* Authehntication type, if given */
806 char *auth_key
; /* simple password if present */
807 int crypto_key_id
; /* Cryptographic key ID */
808 char *md5_key
; /* MD5 authentication key */
809 int hello_interval
; /* Obvious what these are... */
810 int retransmit_interval
;
815 static void ospf_vl_config_data_init(struct ospf_vl_config_data
*vl_config
,
818 memset(vl_config
, 0, sizeof(struct ospf_vl_config_data
));
819 vl_config
->auth_type
= OSPF_AUTH_CMD_NOTSEEN
;
820 vl_config
->vty
= vty
;
823 static struct ospf_vl_data
*
824 ospf_find_vl_data(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
826 struct ospf_area
*area
;
827 struct ospf_vl_data
*vl_data
;
829 struct in_addr area_id
;
831 vty
= vl_config
->vty
;
832 area_id
= vl_config
->area_id
;
834 if (area_id
.s_addr
== OSPF_AREA_BACKBONE
) {
836 "Configuring VLs over the backbone is not allowed\n");
839 area
= ospf_area_get(ospf
, area_id
);
840 ospf_area_display_format_set(ospf
, area
, vl_config
->area_id_fmt
);
842 if (area
->external_routing
!= OSPF_AREA_DEFAULT
) {
843 if (vl_config
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
844 vty_out(vty
, "Area %pI4 is %s\n", &area_id
,
845 area
->external_routing
== OSPF_AREA_NSSA
849 vty_out(vty
, "Area %ld is %s\n",
850 (unsigned long)ntohl(area_id
.s_addr
),
851 area
->external_routing
== OSPF_AREA_NSSA
857 if ((vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
->vl_peer
))
859 vl_data
= ospf_vl_data_new(area
, vl_config
->vl_peer
);
860 if (vl_data
->vl_oi
== NULL
) {
861 vl_data
->vl_oi
= ospf_vl_new(ospf
, vl_data
);
862 ospf_vl_add(ospf
, vl_data
);
863 ospf_spf_calculate_schedule(ospf
,
864 SPF_FLAG_CONFIG_CHANGE
);
871 static int ospf_vl_set_security(struct ospf_vl_data
*vl_data
,
872 struct ospf_vl_config_data
*vl_config
)
874 struct crypt_key
*ck
;
876 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
878 vty
= vl_config
->vty
;
880 if (vl_config
->auth_type
!= OSPF_AUTH_CMD_NOTSEEN
) {
881 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), auth_type
);
882 IF_DEF_PARAMS(ifp
)->auth_type
= vl_config
->auth_type
;
885 if (vl_config
->auth_key
) {
886 memset(IF_DEF_PARAMS(ifp
)->auth_simple
, 0,
887 OSPF_AUTH_SIMPLE_SIZE
+ 1);
888 strlcpy((char *)IF_DEF_PARAMS(ifp
)->auth_simple
,
890 sizeof(IF_DEF_PARAMS(ifp
)->auth_simple
));
891 } else if (vl_config
->md5_key
) {
892 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
893 vl_config
->crypto_key_id
)
895 vty_out(vty
, "OSPF: Key %d already exists\n",
896 vl_config
->crypto_key_id
);
899 ck
= ospf_crypt_key_new();
900 ck
->key_id
= vl_config
->crypto_key_id
;
901 memset(ck
->auth_key
, 0, OSPF_AUTH_MD5_SIZE
+ 1);
902 strlcpy((char *)ck
->auth_key
, vl_config
->md5_key
,
903 sizeof(ck
->auth_key
));
905 ospf_crypt_key_add(IF_DEF_PARAMS(ifp
)->auth_crypt
, ck
);
906 } else if (vl_config
->crypto_key_id
!= 0) {
909 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
910 vl_config
->crypto_key_id
)
912 vty_out(vty
, "OSPF: Key %d does not exist\n",
913 vl_config
->crypto_key_id
);
914 return CMD_WARNING_CONFIG_FAILED
;
917 ospf_crypt_key_delete(IF_DEF_PARAMS(ifp
)->auth_crypt
,
918 vl_config
->crypto_key_id
);
924 static int ospf_vl_set_timers(struct ospf_vl_data
*vl_data
,
925 struct ospf_vl_config_data
*vl_config
)
927 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
928 /* Virtual Link data initialised to defaults, so only set
930 if (vl_config
->hello_interval
) {
931 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_hello
);
932 IF_DEF_PARAMS(ifp
)->v_hello
= vl_config
->hello_interval
;
935 if (vl_config
->dead_interval
) {
936 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_wait
);
937 IF_DEF_PARAMS(ifp
)->v_wait
= vl_config
->dead_interval
;
940 if (vl_config
->retransmit_interval
) {
941 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), retransmit_interval
);
942 IF_DEF_PARAMS(ifp
)->retransmit_interval
=
943 vl_config
->retransmit_interval
;
946 if (vl_config
->transmit_delay
) {
947 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), transmit_delay
);
948 IF_DEF_PARAMS(ifp
)->transmit_delay
= vl_config
->transmit_delay
;
955 /* The business end of all of the above */
956 static int ospf_vl_set(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
958 struct ospf_vl_data
*vl_data
;
961 vl_data
= ospf_find_vl_data(ospf
, vl_config
);
963 return CMD_WARNING_CONFIG_FAILED
;
965 /* Process this one first as it can have a fatal result, which can
966 only logically occur if the virtual link exists already
967 Thus a command error does not result in a change to the
968 running configuration such as unexpectedly altered timer
970 ret
= ospf_vl_set_security(vl_data
, vl_config
);
971 if (ret
!= CMD_SUCCESS
)
974 /* Set any time based parameters, these area already range checked */
976 ret
= ospf_vl_set_timers(vl_data
, vl_config
);
977 if (ret
!= CMD_SUCCESS
)
983 /* This stuff exists to make specifying all the alias commands A LOT simpler
985 #define VLINK_HELPSTR_IPADDR \
986 "OSPF area parameters\n" \
987 "OSPF area ID in IP address format\n" \
988 "OSPF area ID as a decimal value\n" \
989 "Configure a virtual link\n" \
990 "Router ID of the remote ABR\n"
992 #define VLINK_HELPSTR_AUTHTYPE_SIMPLE \
993 "Enable authentication on this virtual link\n" \
996 #define VLINK_HELPSTR_AUTHTYPE_ALL \
997 VLINK_HELPSTR_AUTHTYPE_SIMPLE \
998 "Use null authentication\n" \
999 "Use message-digest authentication\n"
1001 #define VLINK_HELPSTR_TIME_PARAM \
1002 "Time between HELLO packets\n" \
1004 "Time between retransmitting lost link state advertisements\n" \
1006 "Link state transmit delay\n" \
1008 "Interval time after which a neighbor is declared down\n" \
1011 #define VLINK_HELPSTR_AUTH_SIMPLE \
1012 "Authentication password (key)\n" \
1013 "The OSPF password (key)\n"
1015 #define VLINK_HELPSTR_AUTH_MD5 \
1016 "Message digest authentication password (key)\n" \
1018 "Use MD5 algorithm\n" \
1019 "The OSPF password (key)\n"
1021 DEFUN (ospf_area_vlink
,
1022 ospf_area_vlink_cmd
,
1023 "area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D [authentication [<message-digest|null>]] [<message-digest-key (1-255) md5 KEY|authentication-key AUTH_KEY>]",
1024 VLINK_HELPSTR_IPADDR
1025 "Enable authentication on this virtual link\n"
1026 "Use message-digest authentication\n"
1027 "Use null authentication\n"
1028 VLINK_HELPSTR_AUTH_MD5
1029 VLINK_HELPSTR_AUTH_SIMPLE
)
1031 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1032 int idx_ipv4_number
= 1;
1034 struct ospf_vl_config_data vl_config
;
1035 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1036 char md5_key
[OSPF_AUTH_MD5_SIZE
+ 1];
1040 ospf_vl_config_data_init(&vl_config
, vty
);
1042 /* Read off first 2 parameters and check them */
1043 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1044 &vl_config
.area_id_fmt
);
1046 vty_out(vty
, "OSPF area ID is invalid\n");
1047 return CMD_WARNING_CONFIG_FAILED
;
1050 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1052 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1053 return CMD_WARNING_CONFIG_FAILED
;
1057 /* Thats all folks! - BUGS B. strikes again!!!*/
1059 return ospf_vl_set(ospf
, &vl_config
);
1062 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1063 /* authentication - this option can only occur
1064 at start of command line */
1065 vl_config
.auth_type
= OSPF_AUTH_SIMPLE
;
1068 if (argv_find(argv
, argc
, "message-digest", &idx
)) {
1069 /* authentication message-digest */
1070 vl_config
.auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
1071 } else if (argv_find(argv
, argc
, "null", &idx
)) {
1072 /* "authentication null" */
1073 vl_config
.auth_type
= OSPF_AUTH_NULL
;
1076 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1077 vl_config
.md5_key
= NULL
;
1078 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1079 if (vl_config
.crypto_key_id
< 0)
1080 return CMD_WARNING_CONFIG_FAILED
;
1082 strlcpy(md5_key
, argv
[idx
+ 3]->arg
, sizeof(md5_key
));
1083 vl_config
.md5_key
= md5_key
;
1086 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1087 strlcpy(auth_key
, argv
[idx
+ 1]->arg
, sizeof(auth_key
));
1088 vl_config
.auth_key
= auth_key
;
1091 /* Action configuration */
1093 return ospf_vl_set(ospf
, &vl_config
);
1096 DEFUN (no_ospf_area_vlink
,
1097 no_ospf_area_vlink_cmd
,
1098 "no area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D [authentication [<message-digest|null>]] [<message-digest-key (1-255) md5 KEY|authentication-key AUTH_KEY>]",
1100 VLINK_HELPSTR_IPADDR
1101 "Enable authentication on this virtual link\n"
1102 "Use message-digest authentication\n"
1103 "Use null authentication\n"
1104 VLINK_HELPSTR_AUTH_MD5
1105 VLINK_HELPSTR_AUTH_SIMPLE
)
1107 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1108 int idx_ipv4_number
= 2;
1110 struct ospf_area
*area
;
1111 struct ospf_vl_config_data vl_config
;
1112 struct ospf_vl_data
*vl_data
= NULL
;
1113 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1117 ospf_vl_config_data_init(&vl_config
, vty
);
1119 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1122 vty_out(vty
, "OSPF area ID is invalid\n");
1123 return CMD_WARNING_CONFIG_FAILED
;
1126 area
= ospf_area_lookup_by_area_id(ospf
, vl_config
.area_id
);
1128 vty_out(vty
, "Area does not exist\n");
1129 return CMD_WARNING_CONFIG_FAILED
;
1132 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1134 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1135 return CMD_WARNING_CONFIG_FAILED
;
1138 vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
.vl_peer
);
1140 vty_out(vty
, "Virtual link does not exist\n");
1141 return CMD_WARNING_CONFIG_FAILED
;
1145 /* Basic VLink no command */
1146 /* Thats all folks! - BUGS B. strikes again!!!*/
1147 ospf_vl_delete(ospf
, vl_data
);
1148 ospf_area_check_free(ospf
, vl_config
.area_id
);
1152 /* If we are down here, we are reseting parameters */
1153 /* Deal with other parameters */
1155 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1156 /* authentication - this option can only occur
1157 at start of command line */
1158 vl_config
.auth_type
= OSPF_AUTH_NOTSET
;
1161 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1162 vl_config
.md5_key
= NULL
;
1163 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1164 if (vl_config
.crypto_key_id
< 0)
1165 return CMD_WARNING_CONFIG_FAILED
;
1168 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1169 /* Reset authentication-key to 0 */
1170 memset(auth_key
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
1171 vl_config
.auth_key
= auth_key
;
1174 /* Action configuration */
1176 return ospf_vl_set(ospf
, &vl_config
);
1179 DEFUN (ospf_area_vlink_intervals
,
1180 ospf_area_vlink_intervals_cmd
,
1181 "area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D {hello-interval (1-65535)|retransmit-interval (1-65535)|transmit-delay (1-65535)|dead-interval (1-65535)}",
1182 VLINK_HELPSTR_IPADDR
1183 VLINK_HELPSTR_TIME_PARAM
)
1185 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1186 struct ospf_vl_config_data vl_config
;
1189 ospf_vl_config_data_init(&vl_config
, vty
);
1191 char *area_id
= argv
[1]->arg
;
1192 char *router_id
= argv
[3]->arg
;
1194 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1196 vty_out(vty
, "OSPF area ID is invalid\n");
1197 return CMD_WARNING_CONFIG_FAILED
;
1200 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1202 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1203 return CMD_WARNING_CONFIG_FAILED
;
1206 for (int idx
= 4; idx
< argc
; idx
++) {
1207 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1208 vl_config
.hello_interval
=
1209 strtol(argv
[++idx
]->arg
, NULL
, 10);
1210 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1211 vl_config
.retransmit_interval
=
1212 strtol(argv
[++idx
]->arg
, NULL
, 10);
1213 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1214 vl_config
.transmit_delay
=
1215 strtol(argv
[++idx
]->arg
, NULL
, 10);
1216 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1217 vl_config
.dead_interval
=
1218 strtol(argv
[++idx
]->arg
, NULL
, 10);
1221 /* Action configuration */
1222 return ospf_vl_set(ospf
, &vl_config
);
1225 DEFUN (no_ospf_area_vlink_intervals
,
1226 no_ospf_area_vlink_intervals_cmd
,
1227 "no area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D {hello-interval (1-65535)|retransmit-interval (1-65535)|transmit-delay (1-65535)|dead-interval (1-65535)}",
1229 VLINK_HELPSTR_IPADDR
1230 VLINK_HELPSTR_TIME_PARAM
)
1232 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1233 struct ospf_vl_config_data vl_config
;
1236 ospf_vl_config_data_init(&vl_config
, vty
);
1238 char *area_id
= argv
[2]->arg
;
1239 char *router_id
= argv
[4]->arg
;
1241 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1243 vty_out(vty
, "OSPF area ID is invalid\n");
1244 return CMD_WARNING_CONFIG_FAILED
;
1247 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1249 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1250 return CMD_WARNING_CONFIG_FAILED
;
1253 for (int idx
= 5; idx
< argc
; idx
++) {
1254 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1255 vl_config
.hello_interval
= OSPF_HELLO_INTERVAL_DEFAULT
;
1256 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1257 vl_config
.retransmit_interval
=
1258 OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
1259 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1260 vl_config
.transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
1261 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1262 vl_config
.dead_interval
=
1263 OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
1266 /* Action configuration */
1267 return ospf_vl_set(ospf
, &vl_config
);
1270 DEFUN (ospf_area_shortcut
,
1271 ospf_area_shortcut_cmd
,
1272 "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>",
1273 "OSPF area parameters\n"
1274 "OSPF area ID in IP address format\n"
1275 "OSPF area ID as a decimal value\n"
1276 "Configure the area's shortcutting mode\n"
1277 "Set default shortcutting behavior\n"
1278 "Enable shortcutting through the area\n"
1279 "Disable shortcutting through the area\n")
1281 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1282 int idx_ipv4_number
= 1;
1283 int idx_enable_disable
= 3;
1284 struct ospf_area
*area
;
1285 struct in_addr area_id
;
1289 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1290 argv
[idx_ipv4_number
]->arg
);
1292 area
= ospf_area_get(ospf
, area_id
);
1293 ospf_area_display_format_set(ospf
, area
, format
);
1295 if (strncmp(argv
[idx_enable_disable
]->arg
, "de", 2) == 0)
1296 mode
= OSPF_SHORTCUT_DEFAULT
;
1297 else if (strncmp(argv
[idx_enable_disable
]->arg
, "di", 2) == 0)
1298 mode
= OSPF_SHORTCUT_DISABLE
;
1299 else if (strncmp(argv
[idx_enable_disable
]->arg
, "e", 1) == 0)
1300 mode
= OSPF_SHORTCUT_ENABLE
;
1302 return CMD_WARNING_CONFIG_FAILED
;
1304 ospf_area_shortcut_set(ospf
, area
, mode
);
1306 if (ospf
->abr_type
!= OSPF_ABR_SHORTCUT
)
1308 "Shortcut area setting will take effect only when the router is configured as Shortcut ABR\n");
1313 DEFUN (no_ospf_area_shortcut
,
1314 no_ospf_area_shortcut_cmd
,
1315 "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>",
1317 "OSPF area parameters\n"
1318 "OSPF area ID in IP address format\n"
1319 "OSPF area ID as a decimal value\n"
1320 "Deconfigure the area's shortcutting mode\n"
1321 "Deconfigure enabled shortcutting through the area\n"
1322 "Deconfigure disabled shortcutting through the area\n")
1324 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1325 int idx_ipv4_number
= 2;
1326 struct ospf_area
*area
;
1327 struct in_addr area_id
;
1330 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1331 argv
[idx_ipv4_number
]->arg
);
1333 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1337 ospf_area_shortcut_unset(ospf
, area
);
1343 DEFUN (ospf_area_stub
,
1345 "area <A.B.C.D|(0-4294967295)> stub",
1346 "OSPF area parameters\n"
1347 "OSPF area ID in IP address format\n"
1348 "OSPF area ID as a decimal value\n"
1349 "Configure OSPF area as stub\n")
1351 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1352 int idx_ipv4_number
= 1;
1353 struct in_addr area_id
;
1356 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1357 argv
[idx_ipv4_number
]->arg
);
1359 ret
= ospf_area_stub_set(ospf
, area_id
);
1360 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1364 "First deconfigure all virtual link through this area\n");
1365 return CMD_WARNING_CONFIG_FAILED
;
1368 /* Flush the external LSAs from the specified area */
1369 ospf_flush_lsa_from_area(ospf
, area_id
, OSPF_AS_EXTERNAL_LSA
);
1370 ospf_area_no_summary_unset(ospf
, area_id
);
1375 DEFUN (ospf_area_stub_no_summary
,
1376 ospf_area_stub_no_summary_cmd
,
1377 "area <A.B.C.D|(0-4294967295)> stub no-summary",
1378 "OSPF stub parameters\n"
1379 "OSPF area ID in IP address format\n"
1380 "OSPF area ID as a decimal value\n"
1381 "Configure OSPF area as stub\n"
1382 "Do not inject inter-area routes into stub\n")
1384 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1385 int idx_ipv4_number
= 1;
1386 struct in_addr area_id
;
1389 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1390 argv
[idx_ipv4_number
]->arg
);
1392 ret
= ospf_area_stub_set(ospf
, area_id
);
1393 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1397 "%% Area cannot be stub as it contains a virtual link\n");
1398 return CMD_WARNING_CONFIG_FAILED
;
1401 ospf_area_no_summary_set(ospf
, area_id
);
1406 DEFUN (no_ospf_area_stub
,
1407 no_ospf_area_stub_cmd
,
1408 "no area <A.B.C.D|(0-4294967295)> stub",
1410 "OSPF area parameters\n"
1411 "OSPF area ID in IP address format\n"
1412 "OSPF area ID as a decimal value\n"
1413 "Configure OSPF area as stub\n")
1415 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1416 int idx_ipv4_number
= 2;
1417 struct in_addr area_id
;
1420 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1421 argv
[idx_ipv4_number
]->arg
);
1423 ospf_area_stub_unset(ospf
, area_id
);
1424 ospf_area_no_summary_unset(ospf
, area_id
);
1429 DEFUN (no_ospf_area_stub_no_summary
,
1430 no_ospf_area_stub_no_summary_cmd
,
1431 "no area <A.B.C.D|(0-4294967295)> stub no-summary",
1433 "OSPF area parameters\n"
1434 "OSPF area ID in IP address format\n"
1435 "OSPF area ID as a decimal value\n"
1436 "Configure OSPF area as stub\n"
1437 "Do not inject inter-area routes into area\n")
1439 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1440 int idx_ipv4_number
= 2;
1441 struct in_addr area_id
;
1444 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1445 argv
[idx_ipv4_number
]->arg
);
1446 ospf_area_no_summary_unset(ospf
, area_id
);
1451 static int ospf_area_nssa_cmd_handler(struct vty
*vty
, int argc
,
1452 struct cmd_token
**argv
, int cfg_nosum
,
1455 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1456 struct in_addr area_id
;
1459 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
, argv
[1]->arg
);
1461 ret
= ospf_area_nssa_set(ospf
, area_id
);
1462 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1466 "%% Area cannot be nssa as it contains a virtual link\n");
1467 return CMD_WARNING_CONFIG_FAILED
;
1471 if (strncmp(argv
[3]->text
, "translate-c", 11) == 0)
1472 ospf_area_nssa_translator_role_set(
1473 ospf
, area_id
, OSPF_NSSA_ROLE_CANDIDATE
);
1474 else if (strncmp(argv
[3]->text
, "translate-n", 11) == 0)
1475 ospf_area_nssa_translator_role_set(
1476 ospf
, area_id
, OSPF_NSSA_ROLE_NEVER
);
1477 else if (strncmp(argv
[3]->text
, "translate-a", 11) == 0)
1478 ospf_area_nssa_translator_role_set(
1479 ospf
, area_id
, OSPF_NSSA_ROLE_ALWAYS
);
1481 ospf_area_nssa_translator_role_set(ospf
, area_id
,
1482 OSPF_NSSA_ROLE_CANDIDATE
);
1487 ospf_area_no_summary_set(ospf
, area_id
);
1489 ospf_area_no_summary_unset(ospf
, area_id
);
1492 /* Flush the external LSA for the specified area */
1493 ospf_flush_lsa_from_area(ospf
, area_id
, OSPF_AS_EXTERNAL_LSA
);
1494 ospf_schedule_abr_task(ospf
);
1495 ospf_schedule_asbr_nssa_redist_update(ospf
);
1501 DEFUN (ospf_area_nssa_translate
,
1502 ospf_area_nssa_translate_cmd
,
1503 "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always>",
1504 "OSPF area parameters\n"
1505 "OSPF area ID in IP address format\n"
1506 "OSPF area ID as a decimal value\n"
1507 "Configure OSPF area as nssa\n"
1508 "Configure NSSA-ABR for translate election (default)\n"
1509 "Configure NSSA-ABR to never translate\n"
1510 "Configure NSSA-ABR to always translate\n")
1512 return ospf_area_nssa_cmd_handler(vty
, argc
, argv
, 0, 0);
1515 DEFUN (ospf_area_nssa
,
1517 "area <A.B.C.D|(0-4294967295)> nssa",
1518 "OSPF area parameters\n"
1519 "OSPF area ID in IP address format\n"
1520 "OSPF area ID as a decimal value\n"
1521 "Configure OSPF area as nssa\n")
1523 return ospf_area_nssa_cmd_handler(vty
, argc
, argv
, 0, 0);
1526 DEFUN(ospf_area_nssa_suppress_fa
, ospf_area_nssa_suppress_fa_cmd
,
1527 "area <A.B.C.D|(0-4294967295)> nssa suppress-fa",
1528 "OSPF area parameters\n"
1529 "OSPF area ID in IP address format\n"
1530 "OSPF area ID as a decimal value\n"
1531 "Configure OSPF area as nssa\n"
1532 "Suppress forwarding address\n")
1534 int idx_ipv4_number
= 1;
1535 struct in_addr area_id
;
1538 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1539 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1540 argv
[idx_ipv4_number
]->arg
);
1542 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1544 ospf_area_nssa_suppress_fa_set(ospf
, area_id
);
1546 ospf_schedule_abr_task(ospf
);
1551 DEFUN(no_ospf_area_nssa_suppress_fa
, no_ospf_area_nssa_suppress_fa_cmd
,
1552 "no area <A.B.C.D|(0-4294967295)> nssa suppress-fa",
1554 "OSPF area parameters\n"
1555 "OSPF area ID in IP address format\n"
1556 "OSPF area ID as a decimal value\n"
1557 "Configure OSPF area as nssa\n"
1558 "Suppress forwarding address\n")
1560 int idx_ipv4_number
= 2;
1561 struct in_addr area_id
;
1564 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1566 VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id
, format
,
1567 argv
[idx_ipv4_number
]->arg
);
1569 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1571 ospf_area_nssa_suppress_fa_unset(ospf
, area_id
);
1573 ospf_schedule_abr_task(ospf
);
1578 DEFUN (ospf_area_nssa_no_summary
,
1579 ospf_area_nssa_no_summary_cmd
,
1580 "area <A.B.C.D|(0-4294967295)> nssa no-summary",
1581 "OSPF area parameters\n"
1582 "OSPF area ID in IP address format\n"
1583 "OSPF area ID as a decimal value\n"
1584 "Configure OSPF area as nssa\n"
1585 "Do not inject inter-area routes into nssa\n")
1587 int idx_ipv4_number
= 1;
1588 struct in_addr area_id
;
1591 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1592 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1593 argv
[idx_ipv4_number
]->arg
);
1595 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1597 ospf_area_nssa_no_summary_set(ospf
, area_id
);
1599 ospf_schedule_abr_task(ospf
);
1604 DEFUN (no_ospf_area_nssa_no_summary
,
1605 no_ospf_area_nssa_no_summary_cmd
,
1606 "no area <A.B.C.D|(0-4294967295)> nssa no-summary",
1608 "OSPF area parameters\n"
1609 "OSPF area ID in IP address format\n"
1610 "OSPF area ID as a decimal value\n"
1611 "Configure OSPF area as nssa\n"
1612 "Do not inject inter-area routes into nssa\n")
1614 int idx_ipv4_number
= 2;
1615 struct in_addr area_id
;
1618 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1620 VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id
, format
,
1621 argv
[idx_ipv4_number
]->arg
);
1623 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1625 ospf_area_no_summary_unset(ospf
, area_id
);
1627 ospf_schedule_abr_task(ospf
);
1632 DEFUN (no_ospf_area_nssa
,
1633 no_ospf_area_nssa_cmd
,
1634 "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always>]",
1636 "OSPF area parameters\n"
1637 "OSPF area ID in IP address format\n"
1638 "OSPF area ID as a decimal value\n"
1639 "Configure OSPF area as nssa\n"
1640 "Configure NSSA-ABR for translate election (default)\n"
1641 "Configure NSSA-ABR to never translate\n"
1642 "Configure NSSA-ABR to always translate\n")
1644 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1645 int idx_ipv4_number
= 2;
1646 struct in_addr area_id
;
1649 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1650 argv
[idx_ipv4_number
]->arg
);
1652 /* Flush the NSSA LSA for the specified area */
1653 ospf_flush_lsa_from_area(ospf
, area_id
, OSPF_AS_NSSA_LSA
);
1654 ospf_area_nssa_unset(ospf
, area_id
, argc
);
1656 ospf_schedule_abr_task(ospf
);
1662 DEFUN (ospf_area_default_cost
,
1663 ospf_area_default_cost_cmd
,
1664 "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1665 "OSPF area parameters\n"
1666 "OSPF area ID in IP address format\n"
1667 "OSPF area ID as a decimal value\n"
1668 "Set the summary-default cost of a NSSA or stub area\n"
1669 "Stub's advertised default summary cost\n")
1671 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1672 int idx_ipv4_number
= 1;
1674 struct ospf_area
*area
;
1675 struct in_addr area_id
;
1678 struct prefix_ipv4 p
;
1680 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1681 argv
[idx_ipv4_number
]->arg
);
1682 cost
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1684 area
= ospf_area_get(ospf
, area_id
);
1685 ospf_area_display_format_set(ospf
, area
, format
);
1687 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1688 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1689 return CMD_WARNING_CONFIG_FAILED
;
1692 area
->default_cost
= cost
;
1695 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1697 if (IS_DEBUG_OSPF_EVENT
)
1699 "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4",
1701 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1706 DEFUN (no_ospf_area_default_cost
,
1707 no_ospf_area_default_cost_cmd
,
1708 "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1710 "OSPF area parameters\n"
1711 "OSPF area ID in IP address format\n"
1712 "OSPF area ID as a decimal value\n"
1713 "Set the summary-default cost of a NSSA or stub area\n"
1714 "Stub's advertised default summary cost\n")
1716 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1717 int idx_ipv4_number
= 2;
1718 struct ospf_area
*area
;
1719 struct in_addr area_id
;
1721 struct prefix_ipv4 p
;
1723 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1724 argv
[idx_ipv4_number
]->arg
);
1726 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1730 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1731 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1732 return CMD_WARNING_CONFIG_FAILED
;
1735 area
->default_cost
= 1;
1738 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1740 if (IS_DEBUG_OSPF_EVENT
)
1742 "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4",
1744 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1747 ospf_area_check_free(ospf
, area_id
);
1752 DEFUN (ospf_area_export_list
,
1753 ospf_area_export_list_cmd
,
1754 "area <A.B.C.D|(0-4294967295)> export-list ACCESSLIST4_NAME",
1755 "OSPF area parameters\n"
1756 "OSPF area ID in IP address format\n"
1757 "OSPF area ID as a decimal value\n"
1758 "Set the filter for networks announced to other areas\n"
1759 "Name of the access-list\n")
1761 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1762 int idx_ipv4_number
= 1;
1763 struct ospf_area
*area
;
1764 struct in_addr area_id
;
1767 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1769 area
= ospf_area_get(ospf
, area_id
);
1770 ospf_area_display_format_set(ospf
, area
, format
);
1771 ospf_area_export_list_set(ospf
, area
, argv
[3]->arg
);
1776 DEFUN (no_ospf_area_export_list
,
1777 no_ospf_area_export_list_cmd
,
1778 "no area <A.B.C.D|(0-4294967295)> export-list ACCESSLIST4_NAME",
1780 "OSPF area parameters\n"
1781 "OSPF area ID in IP address format\n"
1782 "OSPF area ID as a decimal value\n"
1783 "Unset the filter for networks announced to other areas\n"
1784 "Name of the access-list\n")
1786 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1787 int idx_ipv4_number
= 2;
1788 struct ospf_area
*area
;
1789 struct in_addr area_id
;
1792 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1794 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1798 ospf_area_export_list_unset(ospf
, area
);
1804 DEFUN (ospf_area_import_list
,
1805 ospf_area_import_list_cmd
,
1806 "area <A.B.C.D|(0-4294967295)> import-list ACCESSLIST4_NAME",
1807 "OSPF area parameters\n"
1808 "OSPF area ID in IP address format\n"
1809 "OSPF area ID as a decimal value\n"
1810 "Set the filter for networks from other areas announced to the specified one\n"
1811 "Name of the access-list\n")
1813 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1814 int idx_ipv4_number
= 1;
1815 struct ospf_area
*area
;
1816 struct in_addr area_id
;
1819 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1821 area
= ospf_area_get(ospf
, area_id
);
1822 ospf_area_display_format_set(ospf
, area
, format
);
1823 ospf_area_import_list_set(ospf
, area
, argv
[3]->arg
);
1828 DEFUN (no_ospf_area_import_list
,
1829 no_ospf_area_import_list_cmd
,
1830 "no area <A.B.C.D|(0-4294967295)> import-list ACCESSLIST4_NAME",
1832 "OSPF area parameters\n"
1833 "OSPF area ID in IP address format\n"
1834 "OSPF area ID as a decimal value\n"
1835 "Unset the filter for networks announced to other areas\n"
1836 "Name of the access-list\n")
1838 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1839 int idx_ipv4_number
= 2;
1840 struct ospf_area
*area
;
1841 struct in_addr area_id
;
1844 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1846 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1850 ospf_area_import_list_unset(ospf
, area
);
1855 DEFUN (ospf_area_filter_list
,
1856 ospf_area_filter_list_cmd
,
1857 "area <A.B.C.D|(0-4294967295)> filter-list prefix PREFIXLIST_NAME <in|out>",
1858 "OSPF area parameters\n"
1859 "OSPF area ID in IP address format\n"
1860 "OSPF area ID as a decimal value\n"
1861 "Filter networks between OSPF areas\n"
1862 "Filter prefixes between OSPF areas\n"
1863 "Name of an IP prefix-list\n"
1864 "Filter networks sent to this area\n"
1865 "Filter networks sent from this area\n")
1867 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1868 int idx_ipv4_number
= 1;
1871 struct ospf_area
*area
;
1872 struct in_addr area_id
;
1873 struct prefix_list
*plist
;
1876 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1878 area
= ospf_area_get(ospf
, area_id
);
1879 ospf_area_display_format_set(ospf
, area
, format
);
1880 plist
= prefix_list_lookup(AFI_IP
, argv
[idx_word
]->arg
);
1881 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1882 PREFIX_LIST_IN(area
) = plist
;
1883 if (PREFIX_NAME_IN(area
))
1884 free(PREFIX_NAME_IN(area
));
1886 PREFIX_NAME_IN(area
) = strdup(argv
[idx_word
]->arg
);
1887 ospf_schedule_abr_task(ospf
);
1889 PREFIX_LIST_OUT(area
) = plist
;
1890 if (PREFIX_NAME_OUT(area
))
1891 free(PREFIX_NAME_OUT(area
));
1893 PREFIX_NAME_OUT(area
) = strdup(argv
[idx_word
]->arg
);
1894 ospf_schedule_abr_task(ospf
);
1900 DEFUN (no_ospf_area_filter_list
,
1901 no_ospf_area_filter_list_cmd
,
1902 "no area <A.B.C.D|(0-4294967295)> filter-list prefix PREFIXLIST_NAME <in|out>",
1904 "OSPF area parameters\n"
1905 "OSPF area ID in IP address format\n"
1906 "OSPF area ID as a decimal value\n"
1907 "Filter networks between OSPF areas\n"
1908 "Filter prefixes between OSPF areas\n"
1909 "Name of an IP prefix-list\n"
1910 "Filter networks sent to this area\n"
1911 "Filter networks sent from this area\n")
1913 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1914 int idx_ipv4_number
= 2;
1917 struct ospf_area
*area
;
1918 struct in_addr area_id
;
1921 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1923 if ((area
= ospf_area_lookup_by_area_id(ospf
, area_id
)) == NULL
)
1926 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1927 if (PREFIX_NAME_IN(area
))
1928 if (strcmp(PREFIX_NAME_IN(area
), argv
[idx_word
]->arg
)
1932 PREFIX_LIST_IN(area
) = NULL
;
1933 if (PREFIX_NAME_IN(area
))
1934 free(PREFIX_NAME_IN(area
));
1936 PREFIX_NAME_IN(area
) = NULL
;
1938 ospf_schedule_abr_task(ospf
);
1940 if (PREFIX_NAME_OUT(area
))
1941 if (strcmp(PREFIX_NAME_OUT(area
), argv
[idx_word
]->arg
)
1945 PREFIX_LIST_OUT(area
) = NULL
;
1946 if (PREFIX_NAME_OUT(area
))
1947 free(PREFIX_NAME_OUT(area
));
1949 PREFIX_NAME_OUT(area
) = NULL
;
1951 ospf_schedule_abr_task(ospf
);
1958 DEFUN (ospf_area_authentication_message_digest
,
1959 ospf_area_authentication_message_digest_cmd
,
1960 "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest",
1962 "OSPF area parameters\n"
1963 "OSPF area ID in IP address format\n"
1964 "OSPF area ID as a decimal value\n"
1965 "Enable authentication\n"
1966 "Use message-digest authentication\n")
1968 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1970 struct ospf_area
*area
;
1971 struct in_addr area_id
;
1974 argv_find(argv
, argc
, "area", &idx
);
1975 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx
+ 1]->arg
);
1977 area
= ospf_area_get(ospf
, area_id
);
1978 ospf_area_display_format_set(ospf
, area
, format
);
1979 area
->auth_type
= strmatch(argv
[0]->text
, "no")
1981 : OSPF_AUTH_CRYPTOGRAPHIC
;
1986 DEFUN (ospf_area_authentication
,
1987 ospf_area_authentication_cmd
,
1988 "area <A.B.C.D|(0-4294967295)> authentication",
1989 "OSPF area parameters\n"
1990 "OSPF area ID in IP address format\n"
1991 "OSPF area ID as a decimal value\n"
1992 "Enable authentication\n")
1994 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1995 int idx_ipv4_number
= 1;
1996 struct ospf_area
*area
;
1997 struct in_addr area_id
;
2000 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
2002 area
= ospf_area_get(ospf
, area_id
);
2003 ospf_area_display_format_set(ospf
, area
, format
);
2004 area
->auth_type
= OSPF_AUTH_SIMPLE
;
2009 DEFUN (no_ospf_area_authentication
,
2010 no_ospf_area_authentication_cmd
,
2011 "no area <A.B.C.D|(0-4294967295)> authentication",
2013 "OSPF area parameters\n"
2014 "OSPF area ID in IP address format\n"
2015 "OSPF area ID as a decimal value\n"
2016 "Enable authentication\n")
2018 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2019 int idx_ipv4_number
= 2;
2020 struct ospf_area
*area
;
2021 struct in_addr area_id
;
2024 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
2026 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
2030 area
->auth_type
= OSPF_AUTH_NULL
;
2032 ospf_area_check_free(ospf
, area_id
);
2038 DEFUN (ospf_abr_type
,
2040 "ospf abr-type <cisco|ibm|shortcut|standard>",
2041 "OSPF specific commands\n"
2042 "Set OSPF ABR type\n"
2043 "Alternative ABR, cisco implementation\n"
2044 "Alternative ABR, IBM implementation\n"
2046 "Standard behavior (RFC2328)\n")
2048 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2050 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2052 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2053 abr_type
= OSPF_ABR_CISCO
;
2054 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2055 abr_type
= OSPF_ABR_IBM
;
2056 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2057 abr_type
= OSPF_ABR_SHORTCUT
;
2058 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2059 abr_type
= OSPF_ABR_STAND
;
2061 return CMD_WARNING_CONFIG_FAILED
;
2063 /* If ABR type value is changed, schedule ABR task. */
2064 if (ospf
->abr_type
!= abr_type
) {
2065 ospf
->abr_type
= abr_type
;
2066 ospf_schedule_abr_task(ospf
);
2072 DEFUN (no_ospf_abr_type
,
2073 no_ospf_abr_type_cmd
,
2074 "no ospf abr-type <cisco|ibm|shortcut|standard>",
2076 "OSPF specific commands\n"
2077 "Set OSPF ABR type\n"
2078 "Alternative ABR, cisco implementation\n"
2079 "Alternative ABR, IBM implementation\n"
2083 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2085 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2087 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2088 abr_type
= OSPF_ABR_CISCO
;
2089 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2090 abr_type
= OSPF_ABR_IBM
;
2091 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2092 abr_type
= OSPF_ABR_SHORTCUT
;
2093 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2094 abr_type
= OSPF_ABR_STAND
;
2096 return CMD_WARNING_CONFIG_FAILED
;
2098 /* If ABR type value is changed, schedule ABR task. */
2099 if (ospf
->abr_type
== abr_type
) {
2100 ospf
->abr_type
= OSPF_ABR_DEFAULT
;
2101 ospf_schedule_abr_task(ospf
);
2107 DEFUN (ospf_log_adjacency_changes
,
2108 ospf_log_adjacency_changes_cmd
,
2109 "log-adjacency-changes",
2110 "Log changes in adjacency state\n")
2112 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2114 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2115 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2119 DEFUN (ospf_log_adjacency_changes_detail
,
2120 ospf_log_adjacency_changes_detail_cmd
,
2121 "log-adjacency-changes detail",
2122 "Log changes in adjacency state\n"
2123 "Log all state changes\n")
2125 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2127 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2128 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2132 DEFUN (no_ospf_log_adjacency_changes
,
2133 no_ospf_log_adjacency_changes_cmd
,
2134 "no log-adjacency-changes",
2136 "Log changes in adjacency state\n")
2138 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2140 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2141 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2145 DEFUN (no_ospf_log_adjacency_changes_detail
,
2146 no_ospf_log_adjacency_changes_detail_cmd
,
2147 "no log-adjacency-changes detail",
2149 "Log changes in adjacency state\n"
2150 "Log all state changes\n")
2152 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2154 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2158 DEFUN (ospf_compatible_rfc1583
,
2159 ospf_compatible_rfc1583_cmd
,
2160 "compatible rfc1583",
2161 "OSPF compatibility list\n"
2162 "compatible with RFC 1583\n")
2164 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2166 if (!CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2167 SET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2168 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2173 DEFUN (no_ospf_compatible_rfc1583
,
2174 no_ospf_compatible_rfc1583_cmd
,
2175 "no compatible rfc1583",
2177 "OSPF compatibility list\n"
2178 "compatible with RFC 1583\n")
2180 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2182 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2183 UNSET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2184 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2189 ALIAS(ospf_compatible_rfc1583
, ospf_rfc1583_flag_cmd
,
2190 "ospf rfc1583compatibility",
2191 "OSPF specific commands\n"
2192 "Enable the RFC1583Compatibility flag\n")
2194 ALIAS(no_ospf_compatible_rfc1583
, no_ospf_rfc1583_flag_cmd
,
2195 "no ospf rfc1583compatibility", NO_STR
2196 "OSPF specific commands\n"
2197 "Disable the RFC1583Compatibility flag\n")
2199 static void ospf_table_reinstall_routes(struct ospf
*ospf
,
2200 struct route_table
*rt
)
2202 struct route_node
*rn
;
2207 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
2208 struct ospf_route
*or;
2214 if (or->type
== OSPF_DESTINATION_NETWORK
)
2215 ospf_zebra_add(ospf
, (struct prefix_ipv4
*)&rn
->p
, or);
2216 else if (or->type
== OSPF_DESTINATION_DISCARD
)
2217 ospf_zebra_add_discard(ospf
,
2218 (struct prefix_ipv4
*)&rn
->p
);
2222 static void ospf_reinstall_routes(struct ospf
*ospf
)
2224 ospf_table_reinstall_routes(ospf
, ospf
->new_table
);
2225 ospf_table_reinstall_routes(ospf
, ospf
->new_external_route
);
2228 DEFPY (ospf_send_extra_data
,
2229 ospf_send_extra_data_cmd
,
2230 "[no] ospf send-extra-data zebra",
2233 "Extra data to Zebra for display/use\n"
2236 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2238 if (no
&& CHECK_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
)) {
2239 UNSET_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
);
2240 ospf_reinstall_routes(ospf
);
2241 } else if (!CHECK_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
)) {
2242 SET_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
);
2243 ospf_reinstall_routes(ospf
);
2249 static int ospf_timers_spf_set(struct vty
*vty
, unsigned int delay
,
2250 unsigned int hold
, unsigned int max
)
2252 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2254 ospf
->spf_delay
= delay
;
2255 ospf
->spf_holdtime
= hold
;
2256 ospf
->spf_max_holdtime
= max
;
2261 DEFUN (ospf_timers_min_ls_interval
,
2262 ospf_timers_min_ls_interval_cmd
,
2263 "timers throttle lsa all (0-5000)",
2264 "Adjust routing timers\n"
2265 "Throttling adaptive timer\n"
2266 "LSA delay between transmissions\n"
2268 "Delay (msec) between sending LSAs\n")
2270 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2272 unsigned int interval
;
2275 vty_out(vty
, "Insufficient arguments\n");
2276 return CMD_WARNING_CONFIG_FAILED
;
2279 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2281 ospf
->min_ls_interval
= interval
;
2286 DEFUN (no_ospf_timers_min_ls_interval
,
2287 no_ospf_timers_min_ls_interval_cmd
,
2288 "no timers throttle lsa all [(0-5000)]",
2290 "Adjust routing timers\n"
2291 "Throttling adaptive timer\n"
2292 "LSA delay between transmissions\n"
2294 "Delay (msec) between sending LSAs\n")
2296 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2297 ospf
->min_ls_interval
= OSPF_MIN_LS_INTERVAL
;
2302 DEFUN (ospf_timers_throttle_spf
,
2303 ospf_timers_throttle_spf_cmd
,
2304 "timers throttle spf (0-600000) (0-600000) (0-600000)",
2305 "Adjust routing timers\n"
2306 "Throttling adaptive timer\n"
2308 "Delay (msec) from first change received till SPF calculation\n"
2309 "Initial hold time (msec) between consecutive SPF calculations\n"
2310 "Maximum hold time (msec)\n")
2313 int idx_number_2
= 4;
2314 int idx_number_3
= 5;
2315 unsigned int delay
, hold
, max
;
2318 vty_out(vty
, "Insufficient arguments\n");
2319 return CMD_WARNING_CONFIG_FAILED
;
2322 delay
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2323 hold
= strtoul(argv
[idx_number_2
]->arg
, NULL
, 10);
2324 max
= strtoul(argv
[idx_number_3
]->arg
, NULL
, 10);
2326 return ospf_timers_spf_set(vty
, delay
, hold
, max
);
2329 DEFUN (no_ospf_timers_throttle_spf
,
2330 no_ospf_timers_throttle_spf_cmd
,
2331 "no timers throttle spf [(0-600000)(0-600000)(0-600000)]",
2333 "Adjust routing timers\n"
2334 "Throttling adaptive timer\n"
2336 "Delay (msec) from first change received till SPF calculation\n"
2337 "Initial hold time (msec) between consecutive SPF calculations\n"
2338 "Maximum hold time (msec)\n")
2340 return ospf_timers_spf_set(vty
, OSPF_SPF_DELAY_DEFAULT
,
2341 OSPF_SPF_HOLDTIME_DEFAULT
,
2342 OSPF_SPF_MAX_HOLDTIME_DEFAULT
);
2346 DEFUN (ospf_timers_lsa_min_arrival
,
2347 ospf_timers_lsa_min_arrival_cmd
,
2348 "timers lsa min-arrival (0-600000)",
2349 "Adjust routing timers\n"
2351 "Minimum delay in receiving new version of a LSA\n"
2352 "Delay in milliseconds\n")
2354 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2355 ospf
->min_ls_arrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2359 DEFUN (no_ospf_timers_lsa_min_arrival
,
2360 no_ospf_timers_lsa_min_arrival_cmd
,
2361 "no timers lsa min-arrival [(0-600000)]",
2363 "Adjust routing timers\n"
2365 "Minimum delay in receiving new version of a LSA\n"
2366 "Delay in milliseconds\n")
2368 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2369 unsigned int minarrival
;
2372 minarrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2374 if (ospf
->min_ls_arrival
!= minarrival
2375 || minarrival
== OSPF_MIN_LS_ARRIVAL
)
2379 ospf
->min_ls_arrival
= OSPF_MIN_LS_ARRIVAL
;
2384 DEFUN (ospf_neighbor
,
2386 "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]",
2388 "Neighbor IP address\n"
2389 "Neighbor Priority\n"
2391 "Dead Neighbor Polling interval\n"
2394 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2398 struct in_addr nbr_addr
;
2399 unsigned int priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2400 unsigned int interval
= OSPF_POLL_INTERVAL_DEFAULT
;
2402 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2403 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2404 return CMD_WARNING_CONFIG_FAILED
;
2408 priority
= strtoul(argv
[idx_pri
]->arg
, NULL
, 10);
2411 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2413 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2416 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2419 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2424 DEFUN (ospf_neighbor_poll_interval
,
2425 ospf_neighbor_poll_interval_cmd
,
2426 "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2428 "Neighbor IP address\n"
2429 "Dead Neighbor Polling interval\n"
2431 "OSPF priority of non-broadcast neighbor\n"
2434 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2438 struct in_addr nbr_addr
;
2439 unsigned int priority
;
2440 unsigned int interval
;
2442 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2443 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2444 return CMD_WARNING_CONFIG_FAILED
;
2447 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2449 priority
= argc
> 4 ? strtoul(argv
[idx_pri
]->arg
, NULL
, 10)
2450 : OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2452 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2453 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2456 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2461 DEFUN (no_ospf_neighbor
,
2462 no_ospf_neighbor_cmd
,
2463 "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]",
2466 "Neighbor IP address\n"
2467 "Neighbor Priority\n"
2469 "Dead Neighbor Polling interval\n"
2472 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2474 struct in_addr nbr_addr
;
2476 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2477 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2478 return CMD_WARNING_CONFIG_FAILED
;
2481 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2486 DEFUN (no_ospf_neighbor_poll
,
2487 no_ospf_neighbor_poll_cmd
,
2488 "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2491 "Neighbor IP address\n"
2492 "Dead Neighbor Polling interval\n"
2494 "Neighbor Priority\n"
2497 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2499 struct in_addr nbr_addr
;
2501 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2502 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2503 return CMD_WARNING_CONFIG_FAILED
;
2506 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2511 DEFUN (ospf_refresh_timer
,
2512 ospf_refresh_timer_cmd
,
2513 "refresh timer (10-1800)",
2514 "Adjust refresh parameters\n"
2515 "Set refresh timer\n"
2516 "Timer value in seconds\n")
2518 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2520 unsigned int interval
;
2522 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2523 interval
= (interval
/ OSPF_LSA_REFRESHER_GRANULARITY
)
2524 * OSPF_LSA_REFRESHER_GRANULARITY
;
2526 ospf_timers_refresh_set(ospf
, interval
);
2531 DEFUN (no_ospf_refresh_timer
,
2532 no_ospf_refresh_timer_val_cmd
,
2533 "no refresh timer [(10-1800)]",
2535 "Adjust refresh parameters\n"
2536 "Unset refresh timer\n"
2537 "Timer value in seconds\n")
2539 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2541 unsigned int interval
;
2544 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2546 if (ospf
->lsa_refresh_interval
!= interval
2547 || interval
== OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
2551 ospf_timers_refresh_unset(ospf
);
2557 DEFUN (ospf_auto_cost_reference_bandwidth
,
2558 ospf_auto_cost_reference_bandwidth_cmd
,
2559 "auto-cost reference-bandwidth (1-4294967)",
2560 "Calculate OSPF interface cost according to bandwidth\n"
2561 "Use reference bandwidth method to assign OSPF cost\n"
2562 "The reference bandwidth in terms of Mbits per second\n")
2564 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2565 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2568 struct interface
*ifp
;
2570 refbw
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2571 if (refbw
< 1 || refbw
> 4294967) {
2572 vty_out(vty
, "reference-bandwidth value is invalid\n");
2573 return CMD_WARNING_CONFIG_FAILED
;
2576 /* If reference bandwidth is changed. */
2577 if ((refbw
) == ospf
->ref_bandwidth
)
2580 ospf
->ref_bandwidth
= refbw
;
2581 FOR_ALL_INTERFACES (vrf
, ifp
)
2582 ospf_if_recalculate_output_cost(ifp
);
2587 DEFUN (no_ospf_auto_cost_reference_bandwidth
,
2588 no_ospf_auto_cost_reference_bandwidth_cmd
,
2589 "no auto-cost reference-bandwidth [(1-4294967)]",
2591 "Calculate OSPF interface cost according to bandwidth\n"
2592 "Use reference bandwidth method to assign OSPF cost\n"
2593 "The reference bandwidth in terms of Mbits per second\n")
2595 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2596 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2597 struct interface
*ifp
;
2599 if (ospf
->ref_bandwidth
== OSPF_DEFAULT_REF_BANDWIDTH
)
2602 ospf
->ref_bandwidth
= OSPF_DEFAULT_REF_BANDWIDTH
;
2603 vty_out(vty
, "%% OSPF: Reference bandwidth is changed.\n");
2605 " Please ensure reference bandwidth is consistent across all routers\n");
2607 FOR_ALL_INTERFACES (vrf
, ifp
)
2608 ospf_if_recalculate_output_cost(ifp
);
2613 DEFUN (ospf_write_multiplier
,
2614 ospf_write_multiplier_cmd
,
2615 "ospf write-multiplier (1-100)",
2616 "OSPF specific commands\n"
2617 "Write multiplier\n"
2618 "Maximum number of interface serviced per write\n")
2620 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2622 uint32_t write_oi_count
;
2629 write_oi_count
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2630 if (write_oi_count
< 1 || write_oi_count
> 100) {
2631 vty_out(vty
, "write-multiplier value is invalid\n");
2632 return CMD_WARNING_CONFIG_FAILED
;
2635 ospf
->write_oi_count
= write_oi_count
;
2639 ALIAS(ospf_write_multiplier
, write_multiplier_cmd
, "write-multiplier (1-100)",
2640 "Write multiplier\n"
2641 "Maximum number of interface serviced per write\n")
2643 DEFUN (no_ospf_write_multiplier
,
2644 no_ospf_write_multiplier_cmd
,
2645 "no ospf write-multiplier (1-100)",
2647 "OSPF specific commands\n"
2648 "Write multiplier\n"
2649 "Maximum number of interface serviced per write\n")
2651 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2653 ospf
->write_oi_count
= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
;
2657 ALIAS(no_ospf_write_multiplier
, no_write_multiplier_cmd
,
2658 "no write-multiplier (1-100)", NO_STR
2659 "Write multiplier\n"
2660 "Maximum number of interface serviced per write\n")
2662 DEFUN(ospf_ti_lfa
, ospf_ti_lfa_cmd
, "fast-reroute ti-lfa [node-protection]",
2663 "Fast Reroute for MPLS and IP resilience\n"
2664 "Topology Independent LFA (Loop-Free Alternate)\n"
2665 "TI-LFA node protection (default is link protection)\n")
2667 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2669 ospf
->ti_lfa_enabled
= true;
2672 ospf
->ti_lfa_protection_type
= OSPF_TI_LFA_NODE_PROTECTION
;
2674 ospf
->ti_lfa_protection_type
= OSPF_TI_LFA_LINK_PROTECTION
;
2676 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2681 DEFUN(no_ospf_ti_lfa
, no_ospf_ti_lfa_cmd
,
2682 "no fast-reroute ti-lfa [node-protection]",
2684 "Fast Reroute for MPLS and IP resilience\n"
2685 "Topology Independent LFA (Loop-Free Alternate)\n"
2686 "TI-LFA node protection (default is link protection)\n")
2688 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2690 ospf
->ti_lfa_enabled
= false;
2692 ospf
->ti_lfa_protection_type
= OSPF_TI_LFA_UNDEFINED_PROTECTION
;
2694 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2699 static void ospf_maxpath_set(struct vty
*vty
, struct ospf
*ospf
, uint16_t paths
)
2701 if (ospf
->max_multipath
== paths
)
2704 ospf
->max_multipath
= paths
;
2706 /* Send deletion notification to zebra to delete all
2707 * ospf specific routes and reinitiat SPF to reflect
2708 * the new max multipath.
2710 ospf_restart_spf(ospf
);
2713 /* Ospf Maximum multiple paths config support */
2714 DEFUN (ospf_max_multipath
,
2715 ospf_max_multipath_cmd
,
2716 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM
),
2717 "Max no of multiple paths for ECMP support\n"
2718 "Number of paths\n")
2720 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2724 maxpaths
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2726 ospf_maxpath_set(vty
, ospf
, maxpaths
);
2730 DEFUN (no_ospf_max_multipath
,
2731 no_ospf_max_multipath_cmd
,
2734 "Max no of multiple paths for ECMP support\n")
2736 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2737 uint16_t maxpaths
= MULTIPATH_NUM
;
2739 ospf_maxpath_set(vty
, ospf
, maxpaths
);
2743 static const char *const ospf_abr_type_descr_str
[] = {
2744 "Unknown", "Standard (RFC2328)", "Alternative IBM",
2745 "Alternative Cisco", "Alternative Shortcut"
2748 static const char *const ospf_shortcut_mode_descr_str
[] = {
2749 "Default", "Enabled", "Disabled"
2752 static void show_ip_ospf_area(struct vty
*vty
, struct ospf_area
*area
,
2753 json_object
*json_areas
, bool use_json
)
2755 json_object
*json_area
= NULL
;
2756 char buf
[PREFIX_STRLEN
];
2759 json_area
= json_object_new_object();
2763 vty_out(vty
, " Area ID: %pI4", &area
->area_id
);
2765 /* Show Area type/mode. */
2766 if (OSPF_IS_AREA_BACKBONE(area
)) {
2768 json_object_boolean_true_add(json_area
, "backbone");
2770 vty_out(vty
, " (Backbone)\n");
2773 if (area
->external_routing
== OSPF_AREA_STUB
) {
2774 if (area
->no_summary
)
2775 json_object_boolean_true_add(
2776 json_area
, "stubNoSummary");
2777 if (area
->shortcut_configured
)
2778 json_object_boolean_true_add(
2779 json_area
, "stubShortcut");
2780 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
2781 if (area
->no_summary
)
2782 json_object_boolean_true_add(
2783 json_area
, "nssaNoSummary");
2784 if (area
->shortcut_configured
)
2785 json_object_boolean_true_add(
2786 json_area
, "nssaShortcut");
2789 json_object_string_add(
2790 json_area
, "shortcuttingMode",
2791 ospf_shortcut_mode_descr_str
2792 [area
->shortcut_configured
]);
2793 if (area
->shortcut_capability
)
2794 json_object_boolean_true_add(json_area
,
2797 if (area
->external_routing
== OSPF_AREA_STUB
)
2798 vty_out(vty
, " (Stub%s%s)",
2799 area
->no_summary
? ", no summary" : "",
2800 area
->shortcut_configured
? "; " : "");
2801 else if (area
->external_routing
== OSPF_AREA_NSSA
)
2802 vty_out(vty
, " (NSSA%s%s)",
2803 area
->no_summary
? ", no summary" : "",
2804 area
->shortcut_configured
? "; " : "");
2807 vty_out(vty
, " Shortcutting mode: %s",
2808 ospf_shortcut_mode_descr_str
2809 [area
->shortcut_configured
]);
2810 vty_out(vty
, ", S-bit consensus: %s\n",
2811 area
->shortcut_capability
? "ok" : "no");
2815 /* Show number of interfaces */
2817 json_object_int_add(json_area
, "areaIfTotalCounter",
2818 listcount(area
->oiflist
));
2819 json_object_int_add(json_area
, "areaIfActiveCounter",
2823 " Number of interfaces in this area: Total: %d, Active: %d\n",
2824 listcount(area
->oiflist
), area
->act_ints
);
2826 if (area
->external_routing
== OSPF_AREA_NSSA
) {
2828 json_object_boolean_true_add(json_area
, "nssa");
2829 if (!IS_OSPF_ABR(area
->ospf
))
2830 json_object_boolean_false_add(json_area
, "abr");
2831 else if (area
->NSSATranslatorState
) {
2832 json_object_boolean_true_add(json_area
, "abr");
2833 if (area
->NSSATranslatorRole
2834 == OSPF_NSSA_ROLE_CANDIDATE
)
2835 json_object_boolean_true_add(
2837 "nssaTranslatorElected");
2838 else if (area
->NSSATranslatorRole
2839 == OSPF_NSSA_ROLE_ALWAYS
)
2840 json_object_boolean_true_add(
2842 "nssaTranslatorAlways");
2844 json_object_boolean_true_add(
2846 "nssaTranslatorNever");
2848 json_object_boolean_true_add(json_area
, "abr");
2849 if (area
->NSSATranslatorRole
2850 == OSPF_NSSA_ROLE_CANDIDATE
)
2851 json_object_boolean_false_add(
2853 "nssaTranslatorElected");
2855 json_object_boolean_true_add(
2857 "nssaTranslatorNever");
2861 " It is an NSSA configuration.\n Elected NSSA/ABR performs type-7/type-5 LSA translation.\n");
2862 if (!IS_OSPF_ABR(area
->ospf
))
2864 " It is not ABR, therefore not Translator.\n");
2865 else if (area
->NSSATranslatorState
) {
2866 vty_out(vty
, " We are an ABR and ");
2867 if (area
->NSSATranslatorRole
2868 == OSPF_NSSA_ROLE_CANDIDATE
)
2870 "the NSSA Elected Translator.\n");
2871 else if (area
->NSSATranslatorRole
2872 == OSPF_NSSA_ROLE_ALWAYS
)
2874 "always an NSSA Translator.\n");
2877 "never an NSSA Translator.\n");
2879 vty_out(vty
, " We are an ABR, but ");
2880 if (area
->NSSATranslatorRole
2881 == OSPF_NSSA_ROLE_CANDIDATE
)
2883 "not the NSSA Elected Translator.\n");
2886 "never an NSSA Translator.\n");
2891 /* Stub-router state for this area */
2892 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
)) {
2893 char timebuf
[OSPF_TIME_DUMP_SIZE
];
2896 json_object_boolean_true_add(
2897 json_area
, "originStubMaxDistRouterLsa");
2898 if (CHECK_FLAG(area
->stub_router_state
,
2899 OSPF_AREA_ADMIN_STUB_ROUTED
))
2900 json_object_boolean_true_add(
2901 json_area
, "indefiniteActiveAdmin");
2902 if (area
->t_stub_router
) {
2906 &area
->t_stub_router
->u
.sands
,
2909 json_object_int_add(
2911 "activeStartupRemainderMsecs",
2916 " Originating stub / maximum-distance Router-LSA\n");
2917 if (CHECK_FLAG(area
->stub_router_state
,
2918 OSPF_AREA_ADMIN_STUB_ROUTED
))
2920 " Administratively activated (indefinitely)\n");
2921 if (area
->t_stub_router
)
2923 " Active from startup, %s remaining\n",
2924 ospf_timer_dump(area
->t_stub_router
,
2931 /* Show number of fully adjacent neighbors. */
2932 json_object_int_add(json_area
, "nbrFullAdjacentCounter",
2935 /* Show authentication type. */
2936 if (area
->auth_type
== OSPF_AUTH_NULL
)
2937 json_object_string_add(json_area
, "authentication",
2938 "authenticationNone");
2939 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2940 json_object_string_add(json_area
, "authentication",
2941 "authenticationSimplePassword");
2942 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2943 json_object_string_add(json_area
, "authentication",
2944 "authenticationMessageDigest");
2946 if (!OSPF_IS_AREA_BACKBONE(area
))
2947 json_object_int_add(json_area
,
2948 "virtualAdjacenciesPassingCounter",
2951 /* Show SPF calculation times. */
2952 json_object_int_add(json_area
, "spfExecutedCounter",
2953 area
->spf_calculation
);
2954 json_object_int_add(json_area
, "lsaNumber", area
->lsdb
->total
);
2955 json_object_int_add(
2956 json_area
, "lsaRouterNumber",
2957 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
));
2958 json_object_int_add(
2959 json_area
, "lsaRouterChecksum",
2960 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
2961 json_object_int_add(
2962 json_area
, "lsaNetworkNumber",
2963 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
));
2964 json_object_int_add(
2965 json_area
, "lsaNetworkChecksum",
2966 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
2967 json_object_int_add(
2968 json_area
, "lsaSummaryNumber",
2969 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
));
2970 json_object_int_add(
2971 json_area
, "lsaSummaryChecksum",
2972 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
2973 json_object_int_add(
2974 json_area
, "lsaAsbrNumber",
2975 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2976 json_object_int_add(
2977 json_area
, "lsaAsbrChecksum",
2978 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2979 json_object_int_add(
2980 json_area
, "lsaNssaNumber",
2981 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2982 json_object_int_add(
2983 json_area
, "lsaNssaChecksum",
2984 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2986 /* Show number of fully adjacent neighbors. */
2988 " Number of fully adjacent neighbors in this area: %d\n",
2991 /* Show authentication type. */
2992 vty_out(vty
, " Area has ");
2993 if (area
->auth_type
== OSPF_AUTH_NULL
)
2994 vty_out(vty
, "no authentication\n");
2995 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2996 vty_out(vty
, "simple password authentication\n");
2997 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2998 vty_out(vty
, "message digest authentication\n");
3000 if (!OSPF_IS_AREA_BACKBONE(area
))
3002 " Number of full virtual adjacencies going through this area: %d\n",
3005 /* Show SPF calculation times. */
3006 vty_out(vty
, " SPF algorithm executed %d times\n",
3007 area
->spf_calculation
);
3009 /* Show number of LSA. */
3010 vty_out(vty
, " Number of LSA %ld\n", area
->lsdb
->total
);
3012 " Number of router LSA %ld. Checksum Sum 0x%08x\n",
3013 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
),
3014 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
3016 " Number of network LSA %ld. Checksum Sum 0x%08x\n",
3017 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
),
3018 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
3020 " Number of summary LSA %ld. Checksum Sum 0x%08x\n",
3021 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
),
3022 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
3024 " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n",
3025 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
),
3026 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
3027 vty_out(vty
, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n",
3028 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
),
3029 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
3033 json_object_int_add(
3034 json_area
, "lsaOpaqueLinkNumber",
3035 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
3036 json_object_int_add(
3037 json_area
, "lsaOpaqueLinkChecksum",
3038 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
3039 json_object_int_add(
3040 json_area
, "lsaOpaqueAreaNumber",
3041 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
3042 json_object_int_add(
3043 json_area
, "lsaOpaqueAreaChecksum",
3044 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
3047 " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n",
3048 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
),
3049 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
3051 " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n",
3052 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
),
3053 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
3057 json_object_object_add(json_areas
,
3058 inet_ntop(AF_INET
, &area
->area_id
,
3065 static int show_ip_ospf_common(struct vty
*vty
, struct ospf
*ospf
,
3066 json_object
*json
, uint8_t use_vrf
)
3068 struct listnode
*node
, *nnode
;
3069 struct ospf_area
*area
;
3070 struct timeval result
;
3071 char timebuf
[OSPF_TIME_DUMP_SIZE
];
3072 json_object
*json_vrf
= NULL
;
3073 json_object
*json_areas
= NULL
;
3077 json_vrf
= json_object_new_object();
3080 json_areas
= json_object_new_object();
3083 if (ospf
->instance
) {
3085 json_object_int_add(json
, "ospfInstance",
3088 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
3092 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3094 /* Show Router ID. */
3096 json_object_string_addf(json_vrf
, "routerId", "%pI4",
3099 vty_out(vty
, " OSPF Routing Process, Router ID: %pI4\n",
3103 /* Graceful shutdown */
3104 if (ospf
->t_deferred_shutdown
) {
3109 &ospf
->t_deferred_shutdown
->u
.sands
,
3112 json_object_int_add(json_vrf
, "deferredShutdownMsecs",
3116 " Deferred shutdown in progress, %s remaining\n",
3117 ospf_timer_dump(ospf
->t_deferred_shutdown
,
3118 timebuf
, sizeof(timebuf
)));
3122 /* Show capability. */
3124 json_object_boolean_true_add(json_vrf
, "tosRoutesOnly");
3125 json_object_boolean_true_add(json_vrf
, "rfc2328Conform");
3126 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
3127 json_object_boolean_true_add(json_vrf
,
3128 "rfc1583Compatibility");
3131 vty_out(vty
, " Supports only single TOS (TOS0) routes\n");
3132 vty_out(vty
, " This implementation conforms to RFC2328\n");
3133 vty_out(vty
, " RFC1583Compatibility flag is %s\n",
3134 CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)
3140 if (CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)) {
3141 json_object_boolean_true_add(json_vrf
, "opaqueCapable");
3144 vty_out(vty
, " OpaqueCapability flag is %s\n",
3145 CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)
3150 /* Show stub-router configuration */
3151 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
3152 || ospf
->stub_router_shutdown_time
3153 != OSPF_STUB_ROUTER_UNCONFIGURED
) {
3155 json_object_boolean_true_add(json_vrf
,
3156 "stubAdvertisement");
3157 if (ospf
->stub_router_startup_time
3158 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3159 json_object_int_add(
3160 json_vrf
, "postStartEnabledSecs",
3161 ospf
->stub_router_startup_time
);
3162 if (ospf
->stub_router_shutdown_time
3163 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3164 json_object_int_add(
3165 json_vrf
, "preShutdownEnabledSecs",
3166 ospf
->stub_router_shutdown_time
);
3169 " Stub router advertisement is configured\n");
3170 if (ospf
->stub_router_startup_time
3171 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3173 " Enabled for %us after start-up\n",
3174 ospf
->stub_router_startup_time
);
3175 if (ospf
->stub_router_shutdown_time
3176 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3178 " Enabled for %us prior to full shutdown\n",
3179 ospf
->stub_router_shutdown_time
);
3183 /* Show SPF timers. */
3185 json_object_int_add(json_vrf
, "spfScheduleDelayMsecs",
3187 json_object_int_add(json_vrf
, "holdtimeMinMsecs",
3188 ospf
->spf_holdtime
);
3189 json_object_int_add(json_vrf
, "holdtimeMaxMsecs",
3190 ospf
->spf_max_holdtime
);
3191 json_object_int_add(json_vrf
, "holdtimeMultplier",
3192 ospf
->spf_hold_multiplier
);
3195 " Initial SPF scheduling delay %d millisec(s)\n"
3196 " Minimum hold time between consecutive SPFs %d millisec(s)\n"
3197 " Maximum hold time between consecutive SPFs %d millisec(s)\n"
3198 " Hold time multiplier is currently %d\n",
3199 ospf
->spf_delay
, ospf
->spf_holdtime
,
3200 ospf
->spf_max_holdtime
, ospf
->spf_hold_multiplier
);
3204 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3205 long time_store
= 0;
3208 monotime_since(&ospf
->ts_spf
, NULL
) / 1000LL;
3209 json_object_int_add(json_vrf
, "spfLastExecutedMsecs",
3212 time_store
= (1000 * ospf
->ts_spf_duration
.tv_sec
)
3213 + (ospf
->ts_spf_duration
.tv_usec
/ 1000);
3214 json_object_int_add(json_vrf
, "spfLastDurationMsecs",
3217 json_object_boolean_true_add(json_vrf
, "spfHasNotRun");
3219 vty_out(vty
, " SPF algorithm ");
3220 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3221 monotime_since(&ospf
->ts_spf
, &result
);
3222 vty_out(vty
, "last executed %s ago\n",
3223 ospf_timeval_dump(&result
, timebuf
,
3225 vty_out(vty
, " Last SPF duration %s\n",
3226 ospf_timeval_dump(&ospf
->ts_spf_duration
,
3227 timebuf
, sizeof(timebuf
)));
3229 vty_out(vty
, "has not been run\n");
3233 if (ospf
->t_spf_calc
) {
3236 monotime_until(&ospf
->t_spf_calc
->u
.sands
, NULL
)
3238 json_object_int_add(json_vrf
, "spfTimerDueInMsecs",
3242 json_object_int_add(json_vrf
, "lsaMinIntervalMsecs",
3243 ospf
->min_ls_interval
);
3244 json_object_int_add(json_vrf
, "lsaMinArrivalMsecs",
3245 ospf
->min_ls_arrival
);
3246 /* Show write multiplier values */
3247 json_object_int_add(json_vrf
, "writeMultiplier",
3248 ospf
->write_oi_count
);
3249 /* Show refresh parameters. */
3250 json_object_int_add(json_vrf
, "refreshTimerMsecs",
3251 ospf
->lsa_refresh_interval
* 1000);
3253 /* show max multipath */
3254 json_object_int_add(json_vrf
, "maximumPaths",
3255 ospf
->max_multipath
);
3257 /* show administrative distance */
3258 json_object_int_add(json_vrf
, "preference",
3260 ? ospf
->distance_all
3261 : ZEBRA_OSPF_DISTANCE_DEFAULT
);
3263 vty_out(vty
, " SPF timer %s%s\n",
3264 (ospf
->t_spf_calc
? "due in " : "is "),
3265 ospf_timer_dump(ospf
->t_spf_calc
, timebuf
,
3268 vty_out(vty
, " LSA minimum interval %d msecs\n",
3269 ospf
->min_ls_interval
);
3270 vty_out(vty
, " LSA minimum arrival %d msecs\n",
3271 ospf
->min_ls_arrival
);
3273 /* Show write multiplier values */
3274 vty_out(vty
, " Write Multiplier set to %d \n",
3275 ospf
->write_oi_count
);
3277 /* Show refresh parameters. */
3278 vty_out(vty
, " Refresh timer %d secs\n",
3279 ospf
->lsa_refresh_interval
);
3281 /* show max multipath */
3282 vty_out(vty
, " Maximum multiple paths(ECMP) supported %d\n",
3283 ospf
->max_multipath
);
3285 /* show administrative distance */
3286 vty_out(vty
, " Administrative distance %u\n",
3287 ospf
->distance_all
? ospf
->distance_all
3288 : ZEBRA_OSPF_DISTANCE_DEFAULT
);
3291 /* Show ABR/ASBR flags. */
3292 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ABR
)) {
3294 json_object_string_add(
3295 json_vrf
, "abrType",
3296 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3299 " This router is an ABR, ABR type is: %s\n",
3300 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3302 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ASBR
)) {
3304 json_object_string_add(
3305 json_vrf
, "asbrRouter",
3306 "injectingExternalRoutingInformation");
3309 " This router is an ASBR (injecting external routing information)\n");
3312 /* Show Number of AS-external-LSAs. */
3314 json_object_int_add(
3315 json_vrf
, "lsaExternalCounter",
3316 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3317 json_object_int_add(
3318 json_vrf
, "lsaExternalChecksum",
3319 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3322 " Number of external LSA %ld. Checksum Sum 0x%08x\n",
3323 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
),
3324 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3328 json_object_int_add(
3329 json_vrf
, "lsaAsopaqueCounter",
3330 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3331 json_object_int_add(
3332 json_vrf
, "lsaAsOpaqueChecksum",
3333 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3336 " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n",
3337 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
),
3338 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3341 /* Show number of areas attached. */
3343 json_object_int_add(json_vrf
, "attachedAreaCounter",
3344 listcount(ospf
->areas
));
3346 vty_out(vty
, " Number of areas attached to this router: %d\n",
3347 listcount(ospf
->areas
));
3349 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
3350 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
)) {
3352 json_object_boolean_true_add(
3353 json_vrf
, "adjacencyChangesLoggedAll");
3356 " All adjacency changes are logged\n");
3359 json_object_boolean_true_add(
3360 json_vrf
, "adjacencyChangesLogged");
3362 vty_out(vty
, " Adjacency changes are logged\n");
3366 /* show LDP-Sync status */
3367 ospf_ldp_sync_show_info(vty
, ospf
, json_vrf
, json
? 1 : 0);
3369 /* Show each area status. */
3370 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
3371 show_ip_ospf_area(vty
, area
, json_areas
, json
? 1 : 0);
3375 json_object_object_add(json_vrf
, "areas", json_areas
);
3376 json_object_object_add(json
, ospf_get_name(ospf
),
3379 json_object_object_add(json
, "areas", json_areas
);
3387 DEFUN (show_ip_ospf
,
3389 "show ip ospf [vrf <NAME|all>] [json]",
3392 "OSPF information\n"
3398 bool uj
= use_json(argc
, argv
);
3399 struct listnode
*node
= NULL
;
3400 char *vrf_name
= NULL
;
3401 bool all_vrf
= false;
3402 int ret
= CMD_SUCCESS
;
3405 json_object
*json
= NULL
;
3406 uint8_t use_vrf
= 0;
3408 if (listcount(om
->ospf
) == 0)
3411 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
3414 json
= json_object_new_object();
3416 /* vrf input is provided could be all or specific vrf*/
3418 bool ospf_output
= false;
3423 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
3424 if (!ospf
->oi_running
)
3427 ret
= show_ip_ospf_common(vty
, ospf
, json
,
3431 vty_json(vty
, json
);
3432 else if (!ospf_output
)
3433 vty_out(vty
, "%% OSPF is not enabled\n");
3436 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
3437 if ((ospf
== NULL
) || !ospf
->oi_running
) {
3439 vty_json(vty
, json
);
3442 "%% OSPF is not enabled in vrf %s\n",
3448 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
3449 /* Display default ospf (instance 0) info */
3450 if (ospf
== NULL
|| !ospf
->oi_running
) {
3452 vty_json(vty
, json
);
3455 "%% OSPF is not enabled in vrf default\n");
3462 show_ip_ospf_common(vty
, ospf
, json
, use_vrf
);
3464 vty_out(vty
, "%s\n",
3465 json_object_to_json_string_ext(
3466 json
, JSON_C_TO_STRING_PRETTY
));
3470 json_object_free(json
);
3475 DEFUN (show_ip_ospf_instance
,
3476 show_ip_ospf_instance_cmd
,
3477 "show ip ospf (1-65535) [json]",
3480 "OSPF information\n"
3486 unsigned short instance
= 0;
3487 bool uj
= use_json(argc
, argv
);
3488 int ret
= CMD_SUCCESS
;
3489 json_object
*json
= NULL
;
3491 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
3492 if (instance
!= ospf_instance
)
3493 return CMD_NOT_MY_INSTANCE
;
3495 ospf
= ospf_lookup_instance(instance
);
3496 if (!ospf
|| !ospf
->oi_running
)
3500 json
= json_object_new_object();
3502 ret
= show_ip_ospf_common(vty
, ospf
, json
, 0);
3505 vty_json(vty
, json
);
3510 static void ospf_interface_auth_show(struct vty
*vty
, struct ospf_interface
*oi
,
3511 json_object
*json
, bool use_json
)
3515 auth_type
= OSPF_IF_PARAM(oi
, auth_type
);
3517 switch (auth_type
) {
3518 case OSPF_AUTH_NULL
:
3520 json_object_string_add(json
, "authentication",
3521 "authenticationNone");
3523 vty_out(vty
, " Authentication NULL is enabled\n");
3525 case OSPF_AUTH_SIMPLE
: {
3527 json_object_string_add(json
, "authentication",
3528 "authenticationSimplePassword");
3531 " Simple password authentication enabled\n");
3534 case OSPF_AUTH_CRYPTOGRAPHIC
: {
3535 struct crypt_key
*ckey
;
3537 if (list_isempty(OSPF_IF_PARAM(oi
, auth_crypt
)))
3540 ckey
= listgetdata(listtail(OSPF_IF_PARAM(oi
, auth_crypt
)));
3543 json_object_string_add(json
, "authentication",
3544 "authenticationMessageDigest");
3547 " Cryptographic authentication enabled\n");
3548 vty_out(vty
, " Algorithm:MD5\n");
3558 static void show_ip_ospf_interface_sub(struct vty
*vty
, struct ospf
*ospf
,
3559 struct interface
*ifp
,
3560 json_object
*json_interface_sub
,
3564 struct ospf_neighbor
*nbr
;
3565 struct route_node
*rn
;
3566 uint32_t bandwidth
= ifp
->bandwidth
? ifp
->bandwidth
: ifp
->speed
;
3568 /* Is interface up? */
3570 is_up
= if_is_operative(ifp
);
3572 json_object_boolean_true_add(json_interface_sub
,
3575 json_object_boolean_false_add(json_interface_sub
,
3578 json_object_int_add(json_interface_sub
, "ifIndex",
3580 json_object_int_add(json_interface_sub
, "mtuBytes", ifp
->mtu
);
3581 json_object_int_add(json_interface_sub
, "bandwidthMbit",
3583 json_object_string_add(json_interface_sub
, "ifFlags",
3584 if_flag_dump(ifp
->flags
));
3586 vty_out(vty
, "%s is %s\n", ifp
->name
,
3587 ((is_up
= if_is_operative(ifp
)) ? "up" : "down"));
3588 vty_out(vty
, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n",
3589 ifp
->ifindex
, ifp
->mtu
, bandwidth
,
3590 if_flag_dump(ifp
->flags
));
3593 /* Is interface OSPF enabled? */
3595 if (ospf_oi_count(ifp
) == 0) {
3596 json_object_boolean_false_add(json_interface_sub
,
3599 } else if (!is_up
) {
3600 json_object_boolean_false_add(json_interface_sub
,
3604 json_object_boolean_true_add(json_interface_sub
,
3607 if (ospf_oi_count(ifp
) == 0) {
3608 vty_out(vty
, " OSPF not enabled on this interface\n");
3610 } else if (!is_up
) {
3612 " OSPF is enabled, but not running on this interface\n");
3617 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
3618 struct ospf_interface
*oi
= rn
->info
;
3623 if (CHECK_FLAG(oi
->connected
->flags
, ZEBRA_IFA_UNNUMBERED
)) {
3625 json_object_boolean_true_add(json_interface_sub
,
3628 vty_out(vty
, " This interface is UNNUMBERED,");
3630 struct in_addr dest
;
3633 /* Show OSPF interface information. */
3635 json_object_string_addf(
3636 json_interface_sub
, "ipAddress", "%pI4",
3637 &oi
->address
->u
.prefix4
);
3638 json_object_int_add(json_interface_sub
,
3639 "ipAddressPrefixlen",
3640 oi
->address
->prefixlen
);
3642 vty_out(vty
, " Internet Address %pFX,",
3645 /* For Vlinks, showing the peer address is
3646 * probably more informative than the local
3647 * interface that is being used */
3648 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
) {
3650 dest
= oi
->vl_data
->peer_addr
;
3651 } else if (CONNECTED_PEER(oi
->connected
)
3652 && oi
->connected
->destination
) {
3654 dest
= oi
->connected
->destination
->u
.prefix4
;
3657 dest
.s_addr
= ipv4_broadcast_addr(
3658 oi
->connected
->address
->u
.prefix4
.s_addr
,
3659 oi
->connected
->address
->prefixlen
);
3663 json_object_string_add(
3665 "ospfIfType", dstr
);
3666 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3667 json_object_string_addf(
3668 json_interface_sub
, "vlinkPeer",
3671 json_object_string_addf(
3673 "localIfUsed", "%pI4", &dest
);
3675 vty_out(vty
, " %s %pI4,", dstr
,
3679 json_object_string_add(json_interface_sub
, "area",
3680 ospf_area_desc_string(oi
->area
));
3681 if (OSPF_IF_PARAM(oi
, mtu_ignore
))
3682 json_object_boolean_true_add(
3684 "mtuMismatchDetect");
3685 json_object_string_addf(json_interface_sub
, "routerId",
3686 "%pI4", &ospf
->router_id
);
3687 json_object_string_add(json_interface_sub
,
3689 ospf_network_type_str
[oi
->type
]);
3690 json_object_int_add(json_interface_sub
, "cost",
3692 json_object_int_add(
3693 json_interface_sub
, "transmitDelaySecs",
3694 OSPF_IF_PARAM(oi
, transmit_delay
));
3695 json_object_string_add(json_interface_sub
, "state",
3696 lookup_msg(ospf_ism_state_msg
,
3698 json_object_int_add(json_interface_sub
, "priority",
3701 vty_out(vty
, " Area %s\n",
3702 ospf_area_desc_string(oi
->area
));
3704 vty_out(vty
, " MTU mismatch detection: %s\n",
3705 OSPF_IF_PARAM(oi
, mtu_ignore
) ? "disabled"
3709 " Router ID %pI4, Network Type %s, Cost: %d\n",
3711 ospf_network_type_str
[oi
->type
],
3715 " Transmit Delay is %d sec, State %s, Priority %d\n",
3716 OSPF_IF_PARAM(oi
, transmit_delay
),
3717 lookup_msg(ospf_ism_state_msg
, oi
->state
, NULL
),
3721 /* Show DR information. */
3722 if (DR(oi
).s_addr
== INADDR_ANY
) {
3725 " No backup designated router on this network\n");
3727 nbr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &DR(oi
));
3730 json_object_string_addf(
3731 json_interface_sub
, "drId",
3732 "%pI4", &nbr
->router_id
);
3733 json_object_string_addf(
3734 json_interface_sub
, "drAddress",
3736 &nbr
->address
.u
.prefix4
);
3739 " Designated Router (ID) %pI4",
3742 " Interface Address %pFX\n",
3748 nbr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &BDR(oi
));
3752 " No backup designated router on this network\n");
3755 json_object_string_addf(
3756 json_interface_sub
, "bdrId",
3757 "%pI4", &nbr
->router_id
);
3758 json_object_string_addf(
3760 "bdrAddress", "%pI4",
3761 &nbr
->address
.u
.prefix4
);
3764 " Backup Designated Router (ID) %pI4,",
3766 vty_out(vty
, " Interface Address %pI4\n",
3767 &nbr
->address
.u
.prefix4
);
3772 /* Next network-LSA sequence number we'll use, if we're elected
3775 && ntohl(oi
->params
->network_lsa_seqnum
)
3776 != OSPF_INITIAL_SEQUENCE_NUMBER
) {
3778 json_object_int_add(
3780 "networkLsaSequence",
3781 ntohl(oi
->params
->network_lsa_seqnum
));
3784 " Saved Network-LSA sequence number 0x%x\n",
3785 ntohl(oi
->params
->network_lsa_seqnum
));
3789 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3790 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3791 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3792 json_object_boolean_true_add(
3794 "mcastMemberOspfAllRouters");
3795 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3796 json_object_boolean_true_add(
3798 "mcastMemberOspfDesignatedRouters");
3801 vty_out(vty
, " Multicast group memberships:");
3802 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3803 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3804 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3805 vty_out(vty
, " OSPFAllRouters");
3806 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3807 vty_out(vty
, " OSPFDesignatedRouters");
3809 vty_out(vty
, " <None>");
3814 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3815 json_object_int_add(
3816 json_interface_sub
, "timerMsecs",
3817 OSPF_IF_PARAM(oi
, v_hello
) * 1000);
3819 json_object_int_add(
3820 json_interface_sub
, "timerMsecs",
3821 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3822 json_object_int_add(json_interface_sub
,
3824 OSPF_IF_PARAM(oi
, v_wait
));
3825 json_object_int_add(json_interface_sub
,
3827 OSPF_IF_PARAM(oi
, v_wait
));
3828 json_object_int_add(
3829 json_interface_sub
, "timerRetransmitSecs",
3830 OSPF_IF_PARAM(oi
, retransmit_interval
));
3832 vty_out(vty
, " Timer intervals configured,");
3833 vty_out(vty
, " Hello ");
3834 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3835 vty_out(vty
, "%ds,",
3836 OSPF_IF_PARAM(oi
, v_hello
));
3838 vty_out(vty
, "%dms,",
3839 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3840 vty_out(vty
, " Dead %ds, Wait %ds, Retransmit %d\n",
3841 OSPF_IF_PARAM(oi
, v_wait
),
3842 OSPF_IF_PARAM(oi
, v_wait
),
3843 OSPF_IF_PARAM(oi
, retransmit_interval
));
3846 if (OSPF_IF_PASSIVE_STATUS(oi
) == OSPF_IF_ACTIVE
) {
3847 char timebuf
[OSPF_TIME_DUMP_SIZE
];
3849 long time_store
= 0;
3853 &oi
->t_hello
->u
.sands
,
3856 json_object_int_add(json_interface_sub
,
3857 "timerHelloInMsecs",
3860 vty_out(vty
, " Hello due in %s\n",
3861 ospf_timer_dump(oi
->t_hello
, timebuf
,
3863 } else /* passive-interface is set */
3866 json_object_boolean_true_add(
3868 "timerPassiveIface");
3871 " No Hellos (Passive interface)\n");
3875 json_object_int_add(json_interface_sub
, "nbrCount",
3876 ospf_nbr_count(oi
, 0));
3877 json_object_int_add(json_interface_sub
,
3879 ospf_nbr_count(oi
, NSM_Full
));
3882 " Neighbor Count is %d, Adjacent neighbor count is %d\n",
3883 ospf_nbr_count(oi
, 0),
3884 ospf_nbr_count(oi
, NSM_Full
));
3886 ospf_interface_bfd_show(vty
, ifp
, json_interface_sub
);
3888 /* OSPF Authentication information */
3889 ospf_interface_auth_show(vty
, oi
, json_interface_sub
, use_json
);
3893 static int show_ip_ospf_interface_common(struct vty
*vty
, struct ospf
*ospf
,
3894 char *intf_name
, uint8_t use_vrf
,
3895 json_object
*json
, bool use_json
)
3897 struct interface
*ifp
;
3898 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
3899 json_object
*json_vrf
= NULL
;
3900 json_object
*json_interface_sub
= NULL
, *json_interface
= NULL
;
3904 json_vrf
= json_object_new_object();
3907 json_interface
= json_object_new_object();
3910 if (ospf
->instance
) {
3912 json_object_int_add(json
, "ospfInstance",
3915 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
3918 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3920 if (intf_name
== NULL
) {
3921 /* Show All Interfaces.*/
3922 FOR_ALL_INTERFACES (vrf
, ifp
) {
3923 if (ospf_oi_count(ifp
)) {
3925 json_interface_sub
=
3926 json_object_new_object();
3928 show_ip_ospf_interface_sub(vty
, ospf
, ifp
,
3933 json_object_object_add(
3934 json_interface
, ifp
->name
,
3935 json_interface_sub
);
3940 json_object_object_add(json_vrf
, "interfaces",
3943 /* Interface name is specified. */
3944 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
3947 json_object_boolean_true_add(json_vrf
,
3950 vty_out(vty
, "No such interface name\n");
3953 json_interface_sub
= json_object_new_object();
3954 json_interface
= json_object_new_object();
3957 show_ip_ospf_interface_sub(
3958 vty
, ospf
, ifp
, json_interface_sub
, use_json
);
3961 json_object_object_add(json_interface
,
3963 json_interface_sub
);
3964 json_object_object_add(json_vrf
, "interfaces",
3972 json_object_object_add(json
, ospf_get_name(ospf
),
3981 static void show_ip_ospf_interface_traffic_sub(struct vty
*vty
,
3982 struct ospf_interface
*oi
,
3983 json_object
*json_interface_sub
,
3987 json_object_int_add(json_interface_sub
, "ifIndex",
3989 json_object_int_add(json_interface_sub
, "helloIn",
3991 json_object_int_add(json_interface_sub
, "helloOut",
3993 json_object_int_add(json_interface_sub
, "dbDescIn",
3995 json_object_int_add(json_interface_sub
, "dbDescOut",
3997 json_object_int_add(json_interface_sub
, "lsReqIn",
3999 json_object_int_add(json_interface_sub
, "lsReqOut",
4001 json_object_int_add(json_interface_sub
, "lsUpdIn",
4003 json_object_int_add(json_interface_sub
, "lsUpdOut",
4005 json_object_int_add(json_interface_sub
, "lsAckIn",
4007 json_object_int_add(json_interface_sub
, "lsAckOut",
4009 json_object_int_add(json_interface_sub
, "packetsQueued",
4010 listcount(oi
->obuf
));
4013 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u %12lu\n",
4014 oi
->ifp
->name
, oi
->hello_in
, oi
->hello_out
,
4015 oi
->db_desc_in
, oi
->db_desc_out
, oi
->ls_req_in
,
4016 oi
->ls_req_out
, oi
->ls_upd_in
, oi
->ls_upd_out
,
4017 oi
->ls_ack_in
, oi
->ls_ack_out
, listcount(oi
->obuf
));
4021 /* OSPFv2 Packet Counters */
4022 static int show_ip_ospf_interface_traffic_common(
4023 struct vty
*vty
, struct ospf
*ospf
, char *intf_name
, json_object
*json
,
4024 int display_once
, uint8_t use_vrf
, bool use_json
)
4026 struct vrf
*vrf
= NULL
;
4027 struct interface
*ifp
= NULL
;
4028 json_object
*json_vrf
= NULL
;
4029 json_object
*json_interface_sub
= NULL
;
4031 if (!use_json
&& !display_once
) {
4033 vty_out(vty
, "%-12s%-17s%-17s%-17s%-17s%-17s%-17s\n",
4034 "Interface", " HELLO", " DB-Desc", " LS-Req",
4035 " LS-Update", " LS-Ack", " Packets");
4036 vty_out(vty
, "%-10s%-18s%-18s%-17s%-17s%-17s%-17s\n", "",
4037 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
4038 " Rx/Tx", " Queued");
4040 "-------------------------------------------------------------------------------------------------------------\n");
4041 } else if (use_json
) {
4043 json_vrf
= json_object_new_object();
4048 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4050 if (intf_name
== NULL
) {
4051 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
4052 FOR_ALL_INTERFACES (vrf
, ifp
) {
4053 struct route_node
*rn
;
4054 struct ospf_interface
*oi
;
4056 if (ospf_oi_count(ifp
) == 0)
4059 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
4060 rn
= route_next(rn
)) {
4067 json_interface_sub
=
4068 json_object_new_object();
4071 show_ip_ospf_interface_traffic_sub(
4072 vty
, oi
, json_interface_sub
, use_json
);
4074 json_object_object_add(
4075 json_vrf
, ifp
->name
,
4076 json_interface_sub
);
4081 /* Interface name is specified. */
4082 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
4084 struct route_node
*rn
;
4085 struct ospf_interface
*oi
;
4087 if (ospf_oi_count(ifp
) == 0) {
4089 " OSPF not enabled on this interface %s\n",
4094 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
4095 rn
= route_next(rn
)) {
4099 json_interface_sub
=
4100 json_object_new_object();
4103 show_ip_ospf_interface_traffic_sub(
4104 vty
, oi
, json_interface_sub
, use_json
);
4106 json_object_object_add(
4107 json_vrf
, ifp
->name
,
4108 json_interface_sub
);
4116 json_object_object_add(json
, ospf_get_name(ospf
),
4124 DEFUN (show_ip_ospf_interface
,
4125 show_ip_ospf_interface_cmd
,
4126 "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]",
4129 "OSPF information\n"
4132 "Interface information\n"
4137 bool uj
= use_json(argc
, argv
);
4138 struct listnode
*node
= NULL
;
4139 char *vrf_name
= NULL
, *intf_name
= NULL
;
4140 bool all_vrf
= false;
4141 int ret
= CMD_SUCCESS
;
4143 int idx_vrf
= 0, idx_intf
= 0;
4144 uint8_t use_vrf
= 0;
4145 json_object
*json
= NULL
;
4147 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4149 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4150 intf_name
= argv
[idx_intf
]->arg
;
4153 json
= json_object_new_object();
4155 /* vrf input is provided could be all or specific vrf*/
4159 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4160 if (!ospf
->oi_running
)
4162 ret
= show_ip_ospf_interface_common(
4163 vty
, ospf
, intf_name
, use_vrf
, json
,
4168 vty_json(vty
, json
);
4170 vty_out(vty
, "%% OSPF is not enabled\n");
4174 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4175 if (ospf
== NULL
|| !ospf
->oi_running
) {
4177 vty_json(vty
, json
);
4180 "%% OSPF is not enabled in vrf %s\n",
4185 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
4189 /* Display default ospf (instance 0) info */
4190 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4191 if (ospf
== NULL
|| !ospf
->oi_running
) {
4193 vty_json(vty
, json
);
4196 "%% OSPF is not enabled in vrf default\n");
4200 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
4205 vty_json(vty
, json
);
4210 DEFUN (show_ip_ospf_instance_interface
,
4211 show_ip_ospf_instance_interface_cmd
,
4212 "show ip ospf (1-65535) interface [INTERFACE] [json]",
4215 "OSPF information\n"
4217 "Interface information\n"
4224 unsigned short instance
= 0;
4225 bool uj
= use_json(argc
, argv
);
4226 char *intf_name
= NULL
;
4227 int ret
= CMD_SUCCESS
;
4228 json_object
*json
= NULL
;
4230 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4231 if (instance
!= ospf_instance
)
4232 return CMD_NOT_MY_INSTANCE
;
4234 ospf
= ospf_lookup_instance(instance
);
4235 if (!ospf
|| !ospf
->oi_running
)
4239 json
= json_object_new_object();
4241 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4242 intf_name
= argv
[idx_intf
]->arg
;
4244 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
, 0, json
, uj
);
4247 vty_json(vty
, json
);
4252 DEFUN (show_ip_ospf_interface_traffic
,
4253 show_ip_ospf_interface_traffic_cmd
,
4254 "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]",
4257 "OSPF information\n"
4260 "Interface information\n"
4261 "Protocol Packet counters\n"
4265 struct ospf
*ospf
= NULL
;
4266 struct listnode
*node
= NULL
;
4267 char *vrf_name
= NULL
, *intf_name
= NULL
;
4268 bool all_vrf
= false;
4270 int idx_vrf
= 0, idx_intf
= 0;
4271 bool uj
= use_json(argc
, argv
);
4272 json_object
*json
= NULL
;
4273 int ret
= CMD_SUCCESS
;
4274 int display_once
= 0;
4275 uint8_t use_vrf
= 0;
4277 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4279 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4280 intf_name
= argv
[idx_intf
]->arg
;
4283 json
= json_object_new_object();
4288 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4289 if (!ospf
->oi_running
)
4292 ret
= show_ip_ospf_interface_traffic_common(
4293 vty
, ospf
, intf_name
, json
,
4294 display_once
, use_vrf
, uj
);
4299 vty_json(vty
, json
);
4303 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4304 if (ospf
== NULL
|| !ospf
->oi_running
) {
4306 json_object_free(json
);
4310 ret
= show_ip_ospf_interface_traffic_common(
4311 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4313 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4314 if (ospf
== NULL
|| !ospf
->oi_running
) {
4316 json_object_free(json
);
4320 ret
= show_ip_ospf_interface_traffic_common(
4321 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4325 vty_json(vty
, json
);
4331 static void show_ip_ospf_neighbour_header(struct vty
*vty
)
4333 vty_out(vty
, "\n%-15s %-3s %-15s %-15s %-9s %-15s %-32s %5s %5s %5s\n",
4334 "Neighbor ID", "Pri", "State", "Up Time", "Dead Time",
4335 "Address", "Interface", "RXmtL", "RqstL", "DBsmL");
4338 static void show_ip_ospf_neighbour_brief(struct vty
*vty
,
4339 struct ospf_neighbor
*nbr
,
4340 struct ospf_neighbor
*prev_nbr
,
4341 json_object
*json
, bool use_json
)
4344 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4345 json_object
*json_neighbor
= NULL
, *json_neigh_array
= NULL
;
4346 struct timeval res
= {.tv_sec
= 0, .tv_usec
= 0};
4348 char uptime
[OSPF_TIME_DUMP_SIZE
];
4350 if (nbr
->ts_last_progress
.tv_sec
|| nbr
->ts_last_progress
.tv_usec
)
4352 monotime_since(&nbr
->ts_last_progress
, &res
) / 1000LL;
4355 char neigh_str
[INET_ADDRSTRLEN
];
4357 if (prev_nbr
&& !IPV4_ADDR_SAME(&prev_nbr
->src
, &nbr
->src
)) {
4358 /* Start new neigh list */
4359 json_neigh_array
= NULL
;
4362 if (nbr
->state
== NSM_Attempt
&&
4363 nbr
->router_id
.s_addr
== INADDR_ANY
)
4364 strlcpy(neigh_str
, "neighbor", sizeof(neigh_str
));
4366 inet_ntop(AF_INET
, &nbr
->router_id
, neigh_str
,
4369 json_object_object_get_ex(json
, neigh_str
, &json_neigh_array
);
4371 if (!json_neigh_array
) {
4372 json_neigh_array
= json_object_new_array();
4373 json_object_object_add(json
, neigh_str
,
4377 json_neighbor
= json_object_new_object();
4379 ospf_nbr_ism_state_message(nbr
, msgbuf
, sizeof(msgbuf
));
4380 #if CONFDATE > 20230321
4382 "Remove show_ip_ospf_neighbor_sub() JSON keys: priority, state, deadTimeMsecs, address, retransmitCounter, requestCounter, dbSummaryCounter")
4384 json_object_int_add(json_neighbor
, "priority", nbr
->priority
);
4385 json_object_string_add(json_neighbor
, "state", msgbuf
);
4386 json_object_int_add(json_neighbor
, "nbrPriority",
4388 json_object_string_add(json_neighbor
, "nbrState", msgbuf
);
4390 json_object_string_add(
4391 json_neighbor
, "converged",
4392 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
4393 json_object_string_add(json_neighbor
, "role",
4394 lookup_msg(ospf_ism_state_msg
,
4395 ospf_nbr_ism_state(nbr
),
4397 if (nbr
->t_inactivity
) {
4400 time_store
= monotime_until(&nbr
->t_inactivity
->u
.sands
,
4403 json_object_int_add(json_neighbor
, "upTimeInMsec",
4405 json_object_int_add(json_neighbor
, "deadTimeMsecs",
4407 json_object_int_add(json_neighbor
,
4408 "routerDeadIntervalTimerDueMsec",
4410 json_object_string_add(
4411 json_neighbor
, "upTime",
4412 ospf_timeval_dump(&res
, uptime
,
4414 json_object_string_add(
4415 json_neighbor
, "deadTime",
4416 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
4419 json_object_string_add(json_neighbor
, "deadTimeMsecs",
4421 json_object_string_add(json_neighbor
,
4422 "routerDeadIntervalTimerDueMsec",
4425 json_object_string_addf(json_neighbor
, "address", "%pI4",
4427 json_object_string_addf(json_neighbor
, "ifaceAddress", "%pI4",
4429 json_object_string_add(json_neighbor
, "ifaceName",
4431 json_object_int_add(json_neighbor
, "retransmitCounter",
4432 ospf_ls_retransmit_count(nbr
));
4433 json_object_int_add(json_neighbor
,
4434 "linkStateRetransmissionListCounter",
4435 ospf_ls_retransmit_count(nbr
));
4436 json_object_int_add(json_neighbor
, "requestCounter",
4437 ospf_ls_request_count(nbr
));
4438 json_object_int_add(json_neighbor
,
4439 "linkStateRequestListCounter",
4440 ospf_ls_request_count(nbr
));
4441 json_object_int_add(json_neighbor
, "dbSummaryCounter",
4442 ospf_db_summary_count(nbr
));
4443 json_object_int_add(json_neighbor
, "databaseSummaryListCounter",
4444 ospf_db_summary_count(nbr
));
4446 json_object_array_add(json_neigh_array
, json_neighbor
);
4448 ospf_nbr_ism_state_message(nbr
, msgbuf
, sizeof(msgbuf
));
4450 if (nbr
->state
== NSM_Attempt
&&
4451 nbr
->router_id
.s_addr
== INADDR_ANY
)
4452 vty_out(vty
, "%-15s %3d %-15s ", "-", nbr
->priority
,
4455 vty_out(vty
, "%-15pI4 %3d %-15s ", &nbr
->router_id
,
4456 nbr
->priority
, msgbuf
);
4458 vty_out(vty
, "%-15s ",
4459 ospf_timeval_dump(&res
, uptime
, sizeof(uptime
)));
4461 vty_out(vty
, "%9s ",
4462 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
4464 vty_out(vty
, "%-15pI4 ", &nbr
->src
);
4465 vty_out(vty
, "%-32s %5ld %5ld %5d\n", IF_NAME(nbr
->oi
),
4466 ospf_ls_retransmit_count(nbr
),
4467 ospf_ls_request_count(nbr
), ospf_db_summary_count(nbr
));
4471 static void show_ip_ospf_neighbor_sub(struct vty
*vty
,
4472 struct ospf_interface
*oi
,
4473 json_object
*json
, bool use_json
)
4475 struct route_node
*rn
;
4476 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
4478 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
4484 /* Do not show myself. */
4485 if (nbr
== oi
->nbr_self
)
4487 /* Down state is not shown. */
4488 if (nbr
->state
== NSM_Down
)
4493 show_ip_ospf_neighbour_brief(vty
, nbr
, prev_nbr
, json
,
4498 static int show_ip_ospf_neighbor_common(struct vty
*vty
, struct ospf
*ospf
,
4499 json_object
*json
, bool use_json
,
4502 struct ospf_interface
*oi
;
4503 struct listnode
*node
;
4504 json_object
*json_vrf
= NULL
;
4505 json_object
*json_nbr_sub
= NULL
;
4509 json_vrf
= json_object_new_object();
4512 json_nbr_sub
= json_object_new_object();
4515 if (ospf
->instance
) {
4517 json_object_int_add(json
, "ospfInstance",
4520 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4523 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4525 show_ip_ospf_neighbour_header(vty
);
4527 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4528 if (ospf_interface_neighbor_count(oi
) == 0)
4530 show_ip_ospf_neighbor_sub(vty
, oi
, json_nbr_sub
, use_json
);
4534 json_object_object_add(json_vrf
, "neighbors", json_nbr_sub
);
4536 json_object_object_add(json
, ospf_get_name(ospf
),
4544 DEFUN (show_ip_ospf_neighbor
,
4545 show_ip_ospf_neighbor_cmd
,
4546 "show ip ospf [vrf <NAME|all>] neighbor [json]",
4549 "OSPF information\n"
4556 bool uj
= use_json(argc
, argv
);
4557 struct listnode
*node
= NULL
;
4558 char *vrf_name
= NULL
;
4559 bool all_vrf
= false;
4560 int ret
= CMD_SUCCESS
;
4563 uint8_t use_vrf
= 0;
4564 json_object
*json
= NULL
;
4566 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4569 json
= json_object_new_object();
4571 /* vrf input is provided could be all or specific vrf*/
4575 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4576 if (!ospf
->oi_running
)
4578 ret
= show_ip_ospf_neighbor_common(
4579 vty
, ospf
, json
, uj
, use_vrf
);
4583 vty_json(vty
, json
);
4585 vty_out(vty
, "OSPF is not enabled\n");
4590 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4591 if (ospf
== NULL
|| !ospf
->oi_running
) {
4593 vty_json(vty
, json
);
4596 "%% OSPF is not enabled in vrf %s\n",
4602 /* Display default ospf (instance 0) info */
4603 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4604 if (ospf
== NULL
|| !ospf
->oi_running
) {
4606 vty_json(vty
, json
);
4609 "%% OSPF is not enabled in vrf default\n");
4616 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
,
4620 vty_out(vty
, "%s\n",
4621 json_object_to_json_string_ext(
4622 json
, JSON_C_TO_STRING_PRETTY
));
4627 json_object_free(json
);
4633 DEFUN (show_ip_ospf_instance_neighbor
,
4634 show_ip_ospf_instance_neighbor_cmd
,
4635 "show ip ospf (1-65535) neighbor [json]",
4638 "OSPF information\n"
4645 unsigned short instance
= 0;
4646 bool uj
= use_json(argc
, argv
);
4647 json_object
*json
= NULL
;
4648 int ret
= CMD_SUCCESS
;
4650 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4651 if (instance
!= ospf_instance
)
4652 return CMD_NOT_MY_INSTANCE
;
4654 ospf
= ospf_lookup_instance(instance
);
4655 if (!ospf
|| !ospf
->oi_running
)
4659 json
= json_object_new_object();
4661 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
, 0);
4664 vty_json(vty
, json
);
4669 static int show_ip_ospf_neighbor_all_common(struct vty
*vty
, struct ospf
*ospf
,
4670 json_object
*json
, bool use_json
,
4673 struct listnode
*node
;
4674 struct ospf_interface
*oi
;
4675 char buf
[PREFIX_STRLEN
];
4676 json_object
*json_vrf
= NULL
;
4677 json_object
*json_neighbor_sub
= NULL
;
4681 json_vrf
= json_object_new_object();
4686 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4688 show_ip_ospf_neighbour_header(vty
);
4690 if (ospf
->instance
) {
4692 json_object_int_add(json_vrf
, "ospfInstance",
4695 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4698 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4699 struct listnode
*nbr_node
;
4700 struct ospf_nbr_nbma
*nbr_nbma
;
4702 show_ip_ospf_neighbor_sub(vty
, oi
, json_vrf
, use_json
);
4704 /* print Down neighbor status */
4705 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nbr_node
, nbr_nbma
)) {
4706 if (nbr_nbma
->nbr
== NULL
4707 || nbr_nbma
->nbr
->state
== NSM_Down
) {
4710 json_object_new_object();
4711 json_object_int_add(json_neighbor_sub
,
4713 nbr_nbma
->priority
);
4714 json_object_boolean_true_add(
4717 json_object_string_add(
4721 json_object_int_add(
4723 "nbrNbmaRetransmitCounter", 0);
4724 json_object_int_add(
4726 "nbrNbmaRequestCounter", 0);
4727 json_object_int_add(
4729 "nbrNbmaDbSummaryCounter", 0);
4730 json_object_object_add(
4733 &nbr_nbma
->addr
, buf
,
4737 vty_out(vty
, "%-15s %3d %-15s %9s ",
4738 "-", nbr_nbma
->priority
, "Down",
4741 "%-32pI4 %-20s %5d %5d %5d\n",
4743 IF_NAME(oi
), 0, 0, 0);
4751 json_object_object_add(json
, ospf_get_name(ospf
),
4759 DEFUN (show_ip_ospf_neighbor_all
,
4760 show_ip_ospf_neighbor_all_cmd
,
4761 "show ip ospf [vrf <NAME|all>] neighbor all [json]",
4764 "OSPF information\n"
4768 "include down status neighbor\n"
4772 bool uj
= use_json(argc
, argv
);
4773 struct listnode
*node
= NULL
;
4774 char *vrf_name
= NULL
;
4775 bool all_vrf
= false;
4776 int ret
= CMD_SUCCESS
;
4779 uint8_t use_vrf
= 0;
4780 json_object
*json
= NULL
;
4782 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4785 json
= json_object_new_object();
4787 /* vrf input is provided could be all or specific vrf*/
4791 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4792 if (!ospf
->oi_running
)
4794 ret
= show_ip_ospf_neighbor_all_common(
4795 vty
, ospf
, json
, uj
, use_vrf
);
4799 vty_json(vty
, json
);
4804 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4805 if (ospf
== NULL
|| !ospf
->oi_running
) {
4807 json_object_free(json
);
4811 /* Display default ospf (instance 0) info */
4812 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4813 if (ospf
== NULL
|| !ospf
->oi_running
) {
4815 json_object_free(json
);
4821 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
,
4824 vty_out(vty
, "%s\n",
4825 json_object_to_json_string_ext(
4826 json
, JSON_C_TO_STRING_PRETTY
));
4831 json_object_free(json
);
4836 DEFUN (show_ip_ospf_instance_neighbor_all
,
4837 show_ip_ospf_instance_neighbor_all_cmd
,
4838 "show ip ospf (1-65535) neighbor all [json]",
4841 "OSPF information\n"
4844 "include down status neighbor\n"
4849 unsigned short instance
= 0;
4850 bool uj
= use_json(argc
, argv
);
4851 json_object
*json
= NULL
;
4852 int ret
= CMD_SUCCESS
;
4854 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4855 if (instance
!= ospf_instance
)
4856 return CMD_NOT_MY_INSTANCE
;
4858 ospf
= ospf_lookup_instance(instance
);
4859 if (!ospf
|| !ospf
->oi_running
)
4862 json
= json_object_new_object();
4864 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
, 0);
4867 vty_json(vty
, json
);
4872 static int show_ip_ospf_neighbor_int_common(struct vty
*vty
, struct ospf
*ospf
,
4874 struct cmd_token
**argv
,
4875 bool use_json
, uint8_t use_vrf
)
4877 struct interface
*ifp
;
4878 struct route_node
*rn
;
4879 json_object
*json
= NULL
;
4882 json
= json_object_new_object();
4884 if (ospf
->instance
) {
4886 json_object_int_add(json
, "ospfInstance",
4889 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4892 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
4894 ifp
= if_lookup_by_name(argv
[arg_base
]->arg
, ospf
->vrf_id
);
4897 json_object_boolean_true_add(json
, "noSuchIface");
4899 vty_out(vty
, "No such interface.\n");
4903 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
4904 struct ospf_interface
*oi
= rn
->info
;
4909 show_ip_ospf_neighbor_sub(vty
, oi
, json
, use_json
);
4913 vty_json(vty
, json
);
4920 DEFUN (show_ip_ospf_neighbor_int
,
4921 show_ip_ospf_neighbor_int_cmd
,
4922 "show ip ospf [vrf <NAME>] neighbor IFNAME [json]",
4925 "OSPF information\n"
4934 bool uj
= use_json(argc
, argv
);
4935 int ret
= CMD_SUCCESS
;
4936 struct interface
*ifp
= NULL
;
4937 char *vrf_name
= NULL
;
4938 vrf_id_t vrf_id
= VRF_DEFAULT
;
4939 struct vrf
*vrf
= NULL
;
4941 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
4942 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
4943 if (vrf_name
&& strmatch(vrf_name
, VRF_DEFAULT_NAME
))
4946 vrf
= vrf_lookup_by_name(vrf_name
);
4948 vrf_id
= vrf
->vrf_id
;
4950 ospf
= ospf_lookup_by_vrf_id(vrf_id
);
4952 if (!ospf
|| !ospf
->oi_running
)
4956 show_ip_ospf_neighbour_header(vty
);
4958 argv_find(argv
, argc
, "IFNAME", &idx_ifname
);
4960 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf_id
);
4964 ret
= show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
,
4969 DEFUN (show_ip_ospf_instance_neighbor_int
,
4970 show_ip_ospf_instance_neighbor_int_cmd
,
4971 "show ip ospf (1-65535) neighbor IFNAME [json]",
4974 "OSPF information\n"
4983 unsigned short instance
= 0;
4984 bool uj
= use_json(argc
, argv
);
4987 show_ip_ospf_neighbour_header(vty
);
4989 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4990 if (instance
!= ospf_instance
)
4991 return CMD_NOT_MY_INSTANCE
;
4993 ospf
= ospf_lookup_instance(instance
);
4994 if (!ospf
|| !ospf
->oi_running
)
4998 show_ip_ospf_neighbour_header(vty
);
5000 return show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
, argv
, uj
,
5004 static void show_ip_ospf_nbr_nbma_detail_sub(struct vty
*vty
,
5005 struct ospf_interface
*oi
,
5006 struct ospf_nbr_nbma
*nbr_nbma
,
5007 bool use_json
, json_object
*json
)
5009 char timebuf
[OSPF_TIME_DUMP_SIZE
];
5010 json_object
*json_sub
= NULL
;
5013 json_sub
= json_object_new_object();
5014 else /* Show neighbor ID. */
5015 vty_out(vty
, " Neighbor %s,", "-");
5017 /* Show interface address. */
5019 json_object_string_addf(json_sub
, "ifaceAddress", "%pI4",
5022 vty_out(vty
, " interface address %pI4\n",
5027 json_object_string_add(json_sub
, "areaId",
5028 ospf_area_desc_string(oi
->area
));
5029 json_object_string_add(json_sub
, "iface", IF_NAME(oi
));
5031 vty_out(vty
, " In the area %s via interface %s\n",
5032 ospf_area_desc_string(oi
->area
), IF_NAME(oi
));
5034 /* Show neighbor priority and state. */
5036 json_object_int_add(json_sub
, "nbrPriority",
5037 nbr_nbma
->priority
);
5038 json_object_string_add(json_sub
, "nbrState", "down");
5040 vty_out(vty
, " Neighbor priority is %d, State is %s,",
5041 nbr_nbma
->priority
, "Down");
5043 /* Show state changes. */
5045 json_object_int_add(json_sub
, "stateChangeCounter",
5046 nbr_nbma
->state_change
);
5048 vty_out(vty
, " %d state changes\n", nbr_nbma
->state_change
);
5050 /* Show PollInterval */
5052 json_object_int_add(json_sub
, "pollInterval", nbr_nbma
->v_poll
);
5054 vty_out(vty
, " Poll interval %d\n", nbr_nbma
->v_poll
);
5056 /* Show poll-interval timer. */
5057 if (nbr_nbma
->t_poll
) {
5060 time_store
= monotime_until(&nbr_nbma
->t_poll
->u
.sands
,
5062 json_object_int_add(json_sub
,
5063 "pollIntervalTimerDueMsec",
5066 vty_out(vty
, " Poll timer due in %s\n",
5067 ospf_timer_dump(nbr_nbma
->t_poll
, timebuf
,
5071 /* Show poll-interval timer thread. */
5073 if (nbr_nbma
->t_poll
!= NULL
)
5074 json_object_string_add(json_sub
,
5075 "pollIntervalTimerThread", "on");
5077 vty_out(vty
, " Thread Poll Timer %s\n",
5078 nbr_nbma
->t_poll
!= NULL
? "on" : "off");
5081 json_object_object_add(json
, "noNbrId", json_sub
);
5084 static void show_ip_ospf_neighbor_detail_sub(struct vty
*vty
,
5085 struct ospf_interface
*oi
,
5086 struct ospf_neighbor
*nbr
,
5087 struct ospf_neighbor
*prev_nbr
,
5088 json_object
*json
, bool use_json
)
5090 char timebuf
[OSPF_TIME_DUMP_SIZE
];
5091 json_object
*json_neigh
= NULL
, *json_neigh_array
= NULL
;
5092 char neigh_str
[INET_ADDRSTRLEN
] = {0};
5093 char neigh_state
[16] = {0};
5097 !IPV4_ADDR_SAME(&prev_nbr
->src
, &nbr
->src
)) {
5098 json_neigh_array
= NULL
;
5101 if (nbr
->state
== NSM_Attempt
5102 && nbr
->router_id
.s_addr
== INADDR_ANY
)
5103 strlcpy(neigh_str
, "noNbrId", sizeof(neigh_str
));
5105 inet_ntop(AF_INET
, &nbr
->router_id
,
5106 neigh_str
, sizeof(neigh_str
));
5108 json_object_object_get_ex(json
, neigh_str
, &json_neigh_array
);
5110 if (!json_neigh_array
) {
5111 json_neigh_array
= json_object_new_array();
5112 json_object_object_add(json
, neigh_str
,
5116 json_neigh
= json_object_new_object();
5119 /* Show neighbor ID. */
5120 if (nbr
->state
== NSM_Attempt
5121 && nbr
->router_id
.s_addr
== INADDR_ANY
)
5122 vty_out(vty
, " Neighbor %s,", "-");
5124 vty_out(vty
, " Neighbor %pI4,",
5128 /* Show interface address. */
5130 json_object_string_addf(json_neigh
, "ifaceAddress", "%pI4",
5131 &nbr
->address
.u
.prefix4
);
5133 vty_out(vty
, " interface address %pI4\n",
5134 &nbr
->address
.u
.prefix4
);
5138 json_object_string_add(json_neigh
, "areaId",
5139 ospf_area_desc_string(oi
->area
));
5140 json_object_string_add(json_neigh
, "ifaceName", oi
->ifp
->name
);
5142 vty_out(vty
, " In the area %s via interface %s\n",
5143 ospf_area_desc_string(oi
->area
), oi
->ifp
->name
);
5145 /* Show neighbor priority and state. */
5146 ospf_nbr_ism_state_message(nbr
, neigh_state
, sizeof(neigh_state
));
5148 json_object_int_add(json_neigh
, "nbrPriority", nbr
->priority
);
5149 json_object_string_add(json_neigh
, "nbrState", neigh_state
);
5151 vty_out(vty
, " Neighbor priority is %d, State is %s,",
5152 nbr
->priority
, neigh_state
);
5154 /* Show state changes. */
5156 json_object_int_add(json_neigh
, "stateChangeCounter",
5159 vty_out(vty
, " %d state changes\n", nbr
->state_change
);
5161 if (nbr
->ts_last_progress
.tv_sec
|| nbr
->ts_last_progress
.tv_usec
) {
5166 monotime_since(&nbr
->ts_last_progress
, &res
) / 1000LL;
5168 json_object_int_add(json_neigh
, "lastPrgrsvChangeMsec",
5172 " Most recent state change statistics:\n");
5173 vty_out(vty
, " Progressive change %s ago\n",
5174 ospf_timeval_dump(&res
, timebuf
,
5179 if (nbr
->ts_last_regress
.tv_sec
|| nbr
->ts_last_regress
.tv_usec
) {
5184 monotime_since(&nbr
->ts_last_regress
, &res
) / 1000LL;
5186 json_object_int_add(json_neigh
,
5187 "lastRegressiveChangeMsec",
5189 if (nbr
->last_regress_str
)
5190 json_object_string_add(
5192 "lastRegressiveChangeReason",
5193 nbr
->last_regress_str
);
5196 " Regressive change %s ago, due to %s\n",
5197 ospf_timeval_dump(&res
, timebuf
,
5199 (nbr
->last_regress_str
? nbr
->last_regress_str
5204 /* Show Designated Rotuer ID. */
5206 json_object_string_addf(json_neigh
, "routerDesignatedId",
5207 "%pI4", &nbr
->d_router
);
5209 vty_out(vty
, " DR is %pI4,", &nbr
->d_router
);
5211 /* Show Backup Designated Rotuer ID. */
5213 json_object_string_addf(json_neigh
, "routerDesignatedBackupId",
5214 "%pI4", &nbr
->bd_router
);
5216 vty_out(vty
, " BDR is %pI4\n", &nbr
->bd_router
);
5220 json_object_int_add(json_neigh
, "optionsCounter", nbr
->options
);
5221 json_object_string_add(json_neigh
, "optionsList",
5222 ospf_options_dump(nbr
->options
));
5224 vty_out(vty
, " Options %d %s\n", nbr
->options
,
5225 ospf_options_dump(nbr
->options
));
5227 /* Show Router Dead interval timer. */
5229 if (nbr
->t_inactivity
) {
5231 time_store
= monotime_until(&nbr
->t_inactivity
->u
.sands
,
5234 json_object_int_add(json_neigh
,
5235 "routerDeadIntervalTimerDueMsec",
5238 json_object_int_add(
5240 "routerDeadIntervalTimerDueMsec", -1);
5242 vty_out(vty
, " Dead timer due in %s\n",
5243 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
5246 /* Show Database Summary list. */
5248 json_object_int_add(json_neigh
, "databaseSummaryListCounter",
5249 ospf_db_summary_count(nbr
));
5251 vty_out(vty
, " Database Summary List %d\n",
5252 ospf_db_summary_count(nbr
));
5254 /* Show Link State Request list. */
5256 json_object_int_add(json_neigh
, "linkStateRequestListCounter",
5257 ospf_ls_request_count(nbr
));
5259 vty_out(vty
, " Link State Request List %ld\n",
5260 ospf_ls_request_count(nbr
));
5262 /* Show Link State Retransmission list. */
5264 json_object_int_add(json_neigh
,
5265 "linkStateRetransmissionListCounter",
5266 ospf_ls_retransmit_count(nbr
));
5268 vty_out(vty
, " Link State Retransmission List %ld\n",
5269 ospf_ls_retransmit_count(nbr
));
5271 /* Show inactivity timer thread. */
5273 if (nbr
->t_inactivity
!= NULL
)
5274 json_object_string_add(json_neigh
,
5275 "threadInactivityTimer", "on");
5277 vty_out(vty
, " Thread Inactivity Timer %s\n",
5278 nbr
->t_inactivity
!= NULL
? "on" : "off");
5280 /* Show Database Description retransmission thread. */
5282 if (nbr
->t_db_desc
!= NULL
)
5283 json_object_string_add(
5285 "threadDatabaseDescriptionRetransmission",
5289 " Thread Database Description Retransmision %s\n",
5290 nbr
->t_db_desc
!= NULL
? "on" : "off");
5292 /* Show Link State Request Retransmission thread. */
5294 if (nbr
->t_ls_req
!= NULL
)
5295 json_object_string_add(
5297 "threadLinkStateRequestRetransmission", "on");
5300 " Thread Link State Request Retransmission %s\n",
5301 nbr
->t_ls_req
!= NULL
? "on" : "off");
5303 /* Show Link State Update Retransmission thread. */
5305 if (nbr
->t_ls_upd
!= NULL
)
5306 json_object_string_add(
5308 "threadLinkStateUpdateRetransmission",
5312 " Thread Link State Update Retransmission %s\n\n",
5313 nbr
->t_ls_upd
!= NULL
? "on" : "off");
5316 vty_out(vty
, " Graceful restart Helper info:\n");
5318 if (OSPF_GR_IS_ACTIVE_HELPER(nbr
)) {
5320 " Graceful Restart HELPER Status : Inprogress.\n");
5323 " Graceful Restart grace period time: %d (seconds).\n",
5324 nbr
->gr_helper_info
.recvd_grace_period
);
5325 vty_out(vty
, " Graceful Restart reason: %s.\n",
5326 ospf_restart_reason2str(
5327 nbr
->gr_helper_info
.gr_restart_reason
));
5330 " Graceful Restart HELPER Status : None\n");
5333 if (nbr
->gr_helper_info
.rejected_reason
5334 != OSPF_HELPER_REJECTED_NONE
)
5335 vty_out(vty
, " Helper rejected reason: %s.\n",
5336 ospf_rejected_reason2str(
5337 nbr
->gr_helper_info
.rejected_reason
));
5339 if (nbr
->gr_helper_info
.helper_exit_reason
5340 != OSPF_GR_HELPER_EXIT_NONE
)
5341 vty_out(vty
, " Last helper exit reason: %s.\n\n",
5342 ospf_exit_reason2str(
5343 nbr
->gr_helper_info
.helper_exit_reason
));
5347 json_object_string_add(json_neigh
, "grHelperStatus",
5348 OSPF_GR_IS_ACTIVE_HELPER(nbr
) ?
5351 if (OSPF_GR_IS_ACTIVE_HELPER(nbr
)) {
5352 json_object_int_add(
5353 json_neigh
, "graceInterval",
5354 nbr
->gr_helper_info
.recvd_grace_period
);
5355 json_object_string_add(
5356 json_neigh
, "grRestartReason",
5357 ospf_restart_reason2str(
5358 nbr
->gr_helper_info
.gr_restart_reason
));
5361 if (nbr
->gr_helper_info
.rejected_reason
5362 != OSPF_HELPER_REJECTED_NONE
)
5363 json_object_string_add(
5364 json_neigh
, "helperRejectReason",
5365 ospf_rejected_reason2str(
5366 nbr
->gr_helper_info
.rejected_reason
));
5368 if (nbr
->gr_helper_info
.helper_exit_reason
5369 != OSPF_GR_HELPER_EXIT_NONE
)
5370 json_object_string_add(
5371 json_neigh
, "helperExitReason",
5372 ospf_exit_reason2str(
5374 .helper_exit_reason
));
5377 bfd_sess_show(vty
, json_neigh
, nbr
->bfd_session
);
5380 json_object_array_add(json_neigh_array
, json_neigh
);
5384 static int show_ip_ospf_neighbor_id_common(struct vty
*vty
, struct ospf
*ospf
,
5385 struct in_addr
*router_id
,
5386 bool use_json
, uint8_t use_vrf
,
5389 struct listnode
*node
;
5390 struct ospf_neighbor
*nbr
;
5391 struct ospf_interface
*oi
;
5392 json_object
*json
= NULL
;
5395 json
= json_object_new_object();
5397 if (ospf
->instance
) {
5399 json_object_int_add(json
, "ospfInstance",
5402 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5405 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
5407 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5408 nbr
= ospf_nbr_lookup_by_routerid(oi
->nbrs
, router_id
);
5414 show_ip_ospf_neighbor_detail_sub(vty
, oi
, nbr
, NULL
,
5417 show_ip_ospf_neighbour_brief(vty
, nbr
, NULL
, json
,
5422 vty_json(vty
, json
);
5429 DEFPY(show_ip_ospf_neighbor_id
, show_ip_ospf_neighbor_id_cmd
,
5430 "show ip ospf neighbor A.B.C.D$router_id [detail$detail] [json$json]",
5432 "OSPF information\n"
5435 "Detailed output\n" JSON_STR
)
5438 struct listnode
*node
;
5439 int ret
= CMD_SUCCESS
;
5441 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5442 if (!ospf
->oi_running
)
5444 ret
= show_ip_ospf_neighbor_id_common(vty
, ospf
, &router_id
,
5445 !!json
, 0, !!detail
);
5451 DEFPY(show_ip_ospf_instance_neighbor_id
, show_ip_ospf_instance_neighbor_id_cmd
,
5452 "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [detail$detail] [json$json]",
5454 "OSPF information\n"
5458 "Detailed output\n" JSON_STR
)
5462 if (instance
!= ospf_instance
)
5463 return CMD_NOT_MY_INSTANCE
;
5465 ospf
= ospf_lookup_instance(instance
);
5466 if (!ospf
|| !ospf
->oi_running
)
5469 return show_ip_ospf_neighbor_id_common(vty
, ospf
, &router_id
, !!json
, 0,
5473 static int show_ip_ospf_neighbor_detail_common(struct vty
*vty
,
5475 json_object
*json
, bool use_json
,
5478 struct ospf_interface
*oi
;
5479 struct listnode
*node
;
5480 json_object
*json_vrf
= NULL
;
5481 json_object
*json_nbr_sub
= NULL
;
5485 json_vrf
= json_object_new_object();
5489 json_nbr_sub
= json_object_new_object();
5492 if (ospf
->instance
) {
5494 json_object_int_add(json
, "ospfInstance",
5497 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5500 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5502 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5503 struct route_node
*rn
;
5504 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
5506 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5512 if (nbr
!= oi
->nbr_self
) {
5513 if (nbr
->state
!= NSM_Down
) {
5514 show_ip_ospf_neighbor_detail_sub(
5515 vty
, oi
, nbr
, prev_nbr
,
5516 json_nbr_sub
, use_json
);
5524 json_object_object_add(json_vrf
, "neighbors",
5527 json_object_object_add(json
, ospf_get_name(ospf
),
5535 DEFUN (show_ip_ospf_neighbor_detail
,
5536 show_ip_ospf_neighbor_detail_cmd
,
5537 "show ip ospf [vrf <NAME|all>] neighbor detail [json]",
5540 "OSPF information\n"
5544 "detail of all neighbors\n"
5548 bool uj
= use_json(argc
, argv
);
5549 struct listnode
*node
= NULL
;
5550 char *vrf_name
= NULL
;
5551 bool all_vrf
= false;
5552 int ret
= CMD_SUCCESS
;
5555 uint8_t use_vrf
= 0;
5556 json_object
*json
= NULL
;
5558 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5561 json
= json_object_new_object();
5563 /* vrf input is provided could be all or specific vrf*/
5567 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5568 if (!ospf
->oi_running
)
5570 ret
= show_ip_ospf_neighbor_detail_common(
5571 vty
, ospf
, json
, uj
, use_vrf
);
5574 vty_json(vty
, json
);
5578 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5579 if (ospf
== NULL
|| !ospf
->oi_running
) {
5581 json_object_free(json
);
5585 /* Display default ospf (instance 0) info */
5586 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5587 if (ospf
== NULL
|| !ospf
->oi_running
) {
5589 json_object_free(json
);
5595 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
,
5598 vty_out(vty
, "%s\n",
5599 json_object_to_json_string_ext(
5600 json
, JSON_C_TO_STRING_PRETTY
));
5605 json_object_free(json
);
5610 DEFUN (show_ip_ospf_instance_neighbor_detail
,
5611 show_ip_ospf_instance_neighbor_detail_cmd
,
5612 "show ip ospf (1-65535) neighbor detail [json]",
5615 "OSPF information\n"
5618 "detail of all neighbors\n"
5623 unsigned short instance
= 0;
5624 bool uj
= use_json(argc
, argv
);
5625 json_object
*json
= NULL
;
5626 int ret
= CMD_SUCCESS
;
5628 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5629 if (instance
!= ospf_instance
)
5630 return CMD_NOT_MY_INSTANCE
;
5632 ospf
= ospf_lookup_instance(instance
);
5633 if (!ospf
|| !ospf
->oi_running
)
5637 json
= json_object_new_object();
5639 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
, 0);
5642 vty_json(vty
, json
);
5647 static int show_ip_ospf_neighbor_detail_all_common(struct vty
*vty
,
5653 struct listnode
*node
;
5654 struct ospf_interface
*oi
;
5655 json_object
*json_vrf
= NULL
;
5659 json_vrf
= json_object_new_object();
5664 if (ospf
->instance
) {
5666 json_object_int_add(json
, "ospfInstance",
5669 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5672 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5674 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5675 struct route_node
*rn
;
5676 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
5677 struct ospf_nbr_nbma
*nbr_nbma
;
5679 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5685 if (nbr
!= oi
->nbr_self
)
5686 if (nbr
->state
!= NSM_Down
)
5687 show_ip_ospf_neighbor_detail_sub(
5688 vty
, oi
, rn
->info
, prev_nbr
,
5689 json_vrf
, use_json
);
5693 if (oi
->type
!= OSPF_IFTYPE_NBMA
)
5696 struct listnode
*nd
;
5698 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nd
, nbr_nbma
)) {
5699 if (nbr_nbma
->nbr
== NULL
||
5700 nbr_nbma
->nbr
->state
== NSM_Down
)
5701 show_ip_ospf_nbr_nbma_detail_sub(
5702 vty
, oi
, nbr_nbma
, use_json
, json_vrf
);
5708 json_object_object_add(json
, ospf_get_name(ospf
),
5717 DEFUN (show_ip_ospf_neighbor_detail_all
,
5718 show_ip_ospf_neighbor_detail_all_cmd
,
5719 "show ip ospf [vrf <NAME|all>] neighbor detail all [json]",
5722 "OSPF information\n"
5726 "detail of all neighbors\n"
5727 "include down status neighbor\n"
5731 bool uj
= use_json(argc
, argv
);
5732 struct listnode
*node
= NULL
;
5733 char *vrf_name
= NULL
;
5734 bool all_vrf
= false;
5735 int ret
= CMD_SUCCESS
;
5738 uint8_t use_vrf
= 0;
5739 json_object
*json
= NULL
;
5741 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5744 json
= json_object_new_object();
5746 /* vrf input is provided could be all or specific vrf*/
5750 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5751 if (!ospf
->oi_running
)
5753 ret
= show_ip_ospf_neighbor_detail_all_common(
5754 vty
, ospf
, json
, uj
, use_vrf
);
5758 vty_json(vty
, json
);
5762 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5763 if (ospf
== NULL
|| !ospf
->oi_running
) {
5765 json_object_free(json
);
5769 /* Display default ospf (instance 0) info */
5770 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5771 if (ospf
== NULL
|| !ospf
->oi_running
) {
5773 json_object_free(json
);
5779 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
,
5782 vty_out(vty
, "%s\n",
5783 json_object_to_json_string_ext(
5784 json
, JSON_C_TO_STRING_PRETTY
));
5789 json_object_free(json
);
5794 DEFUN (show_ip_ospf_instance_neighbor_detail_all
,
5795 show_ip_ospf_instance_neighbor_detail_all_cmd
,
5796 "show ip ospf (1-65535) neighbor detail all [json]",
5799 "OSPF information\n"
5802 "detail of all neighbors\n"
5803 "include down status neighbor\n"
5808 unsigned short instance
= 0;
5809 bool uj
= use_json(argc
, argv
);
5810 json_object
*json
= NULL
;
5811 int ret
= CMD_SUCCESS
;
5813 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5814 if (instance
!= ospf_instance
)
5815 return CMD_NOT_MY_INSTANCE
;
5817 ospf
= ospf_lookup_instance(instance
);
5818 if (!ospf
|| !ospf
->oi_running
)
5822 json
= json_object_new_object();
5824 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
, uj
, 0);
5827 vty_json(vty
, json
);
5832 static int show_ip_ospf_neighbor_int_detail_common(struct vty
*vty
,
5835 struct cmd_token
**argv
,
5838 struct ospf_interface
*oi
;
5839 struct interface
*ifp
;
5840 struct route_node
*rn
, *nrn
;
5841 struct ospf_neighbor
*nbr
;
5842 json_object
*json
= NULL
;
5845 json
= json_object_new_object();
5847 if (ospf
->instance
) {
5849 json_object_int_add(json
, "ospfInstance",
5852 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5855 ifp
= if_lookup_by_name(argv
[arg_base
]->arg
, ospf
->vrf_id
);
5858 vty_out(vty
, "No such interface.\n");
5860 vty_out(vty
, "{}\n");
5861 json_object_free(json
);
5866 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
5872 for (nrn
= route_top(oi
->nbrs
); nrn
; nrn
= route_next(nrn
)) {
5878 if (nbr
== oi
->nbr_self
)
5881 if (nbr
->state
== NSM_Down
)
5884 show_ip_ospf_neighbor_detail_sub(vty
, oi
, nbr
, NULL
,
5890 vty_json(vty
, json
);
5897 DEFUN (show_ip_ospf_neighbor_int_detail
,
5898 show_ip_ospf_neighbor_int_detail_cmd
,
5899 "show ip ospf neighbor IFNAME detail [json]",
5902 "OSPF information\n"
5905 "detail of all neighbors\n"
5909 bool uj
= use_json(argc
, argv
);
5910 struct listnode
*node
= NULL
;
5911 int ret
= CMD_SUCCESS
;
5912 bool ospf_output
= false;
5914 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5915 if (!ospf
->oi_running
)
5918 ret
= show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, 4,
5923 vty_out(vty
, "%% OSPF instance not found\n");
5928 DEFUN (show_ip_ospf_instance_neighbor_int_detail
,
5929 show_ip_ospf_instance_neighbor_int_detail_cmd
,
5930 "show ip ospf (1-65535) neighbor IFNAME detail [json]",
5933 "OSPF information\n"
5937 "detail of all neighbors\n"
5943 unsigned short instance
= 0;
5944 bool uj
= use_json(argc
, argv
);
5946 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5947 if (instance
!= ospf_instance
)
5948 return CMD_NOT_MY_INSTANCE
;
5950 ospf
= ospf_lookup_instance(instance
);
5951 if (!ospf
|| !ospf
->oi_running
)
5954 return show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, idx_ifname
,
5958 /* Show functions */
5959 static int show_lsa_summary(struct vty
*vty
, struct ospf_lsa
*lsa
, int self
,
5960 json_object
*json_lsa
)
5962 struct router_lsa
*rl
;
5963 struct summary_lsa
*sl
;
5964 struct as_external_lsa
*asel
;
5965 struct prefix_ipv4 p
;
5968 /* If self option is set, check LSA self flag. */
5969 if (self
== 0 || IS_LSA_SELF(lsa
)) {
5972 /* LSA common part show. */
5973 vty_out(vty
, "%-15pI4",
5975 vty_out(vty
, "%-15pI4 %4d 0x%08lx 0x%04x",
5976 &lsa
->data
->adv_router
, LS_AGE(lsa
),
5977 (unsigned long)ntohl(
5978 lsa
->data
->ls_seqnum
),
5979 ntohs(lsa
->data
->checksum
));
5984 snprintf(seqnum
, sizeof(seqnum
), "%x",
5985 ntohl(lsa
->data
->ls_seqnum
));
5986 snprintf(checksum
, sizeof(checksum
), "%x",
5987 ntohs(lsa
->data
->checksum
));
5988 json_object_string_addf(json_lsa
, "lsId",
5989 "%pI4", &lsa
->data
->id
);
5990 json_object_string_addf(
5991 json_lsa
, "advertisedRouter", "%pI4",
5992 &lsa
->data
->adv_router
);
5993 json_object_int_add(json_lsa
, "lsaAge",
5995 json_object_string_add(
5996 json_lsa
, "sequenceNumber", seqnum
);
5997 json_object_string_add(json_lsa
, "checksum",
6001 /* LSA specific part show. */
6002 switch (lsa
->data
->type
) {
6003 case OSPF_ROUTER_LSA
:
6004 rl
= (struct router_lsa
*)lsa
->data
;
6007 vty_out(vty
, " %-d", ntohs(rl
->links
));
6009 json_object_int_add(json_lsa
,
6013 case OSPF_SUMMARY_LSA
:
6014 sl
= (struct summary_lsa
*)lsa
->data
;
6017 p
.prefix
= sl
->header
.id
;
6018 p
.prefixlen
= ip_masklen(sl
->mask
);
6019 apply_mask_ipv4(&p
);
6022 vty_out(vty
, " %pFX", &p
);
6024 json_object_string_addf(
6025 json_lsa
, "summaryAddress",
6029 case OSPF_AS_EXTERNAL_LSA
:
6030 case OSPF_AS_NSSA_LSA
:
6031 asel
= (struct as_external_lsa
*)lsa
->data
;
6034 p
.prefix
= asel
->header
.id
;
6035 p
.prefixlen
= ip_masklen(asel
->mask
);
6036 apply_mask_ipv4(&p
);
6039 vty_out(vty
, " %s %pFX [0x%lx]",
6045 (unsigned long)ntohl(
6046 asel
->e
[0].route_tag
));
6048 json_object_string_add(
6049 json_lsa
, "metricType",
6054 json_object_string_addf(
6055 json_lsa
, "route", "%pFX", &p
);
6056 json_object_int_add(
6058 (unsigned long)ntohl(
6059 asel
->e
[0].route_tag
));
6062 case OSPF_NETWORK_LSA
:
6063 case OSPF_ASBR_SUMMARY_LSA
:
6064 case OSPF_OPAQUE_LINK_LSA
:
6065 case OSPF_OPAQUE_AREA_LSA
:
6066 case OSPF_OPAQUE_AS_LSA
:
6081 static const char *const show_database_desc
[] = {
6083 "Router Link States",
6085 "Summary Link States",
6086 "ASBR-Summary Link States",
6087 "AS External Link States",
6088 "Group Membership LSA",
6089 "NSSA-external Link States",
6091 "Link-Local Opaque-LSA",
6092 "Area-Local Opaque-LSA",
6093 "AS-external Opaque-LSA",
6096 static const char * const show_database_desc_json
[] = {
6099 "networkLinkStates",
6100 "summaryLinkStates",
6101 "asbrSummaryLinkStates",
6102 "asExternalLinkStates",
6103 "groupMembershipLsa",
6104 "nssaExternalLinkStates",
6106 "linkLocalOpaqueLsa",
6107 "areaLocalOpaqueLsa",
6108 "asExternalOpaqueLsa",
6111 static const char *const show_database_desc_count_json
[] = {
6113 "routerLinkStatesCount",
6114 "networkLinkStatesCount",
6115 "summaryLinkStatesCount",
6116 "asbrSummaryLinkStatesCount",
6117 "asExternalLinkStatesCount",
6118 "groupMembershipLsaCount",
6119 "nssaExternalLinkStatesCount",
6121 "linkLocalOpaqueLsaCount",
6122 "areaLocalOpaqueLsaCount",
6123 "asExternalOpaqueLsaCount",
6126 static const char *const show_database_header
[] = {
6128 "Link ID ADV Router Age Seq# CkSum Link count",
6129 "Link ID ADV Router Age Seq# CkSum",
6130 "Link ID ADV Router Age Seq# CkSum Route",
6131 "Link ID ADV Router Age Seq# CkSum",
6132 "Link ID ADV Router Age Seq# CkSum Route",
6133 " --- header for Group Member ----",
6134 "Link ID ADV Router Age Seq# CkSum Route",
6136 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6137 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6138 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6141 static void show_ip_ospf_database_header(struct vty
*vty
, struct ospf_lsa
*lsa
,
6144 struct router_lsa
*rlsa
= (struct router_lsa
*)lsa
->data
;
6147 vty_out(vty
, " LS age: %d\n", LS_AGE(lsa
));
6148 vty_out(vty
, " Options: 0x%-2x : %s\n", lsa
->data
->options
,
6149 ospf_options_dump(lsa
->data
->options
));
6150 vty_out(vty
, " LS Flags: 0x%-2x %s\n", lsa
->flags
,
6151 ((lsa
->flags
& OSPF_LSA_LOCAL_XLT
)
6152 ? "(Translated from Type-7)"
6155 if (lsa
->data
->type
== OSPF_ROUTER_LSA
) {
6156 vty_out(vty
, " Flags: 0x%x", rlsa
->flags
);
6159 vty_out(vty
, " :%s%s%s%s",
6160 IS_ROUTER_LSA_BORDER(rlsa
) ? " ABR"
6162 IS_ROUTER_LSA_EXTERNAL(rlsa
) ? " ASBR"
6164 IS_ROUTER_LSA_VIRTUAL(rlsa
)
6167 IS_ROUTER_LSA_SHORTCUT(rlsa
)
6173 vty_out(vty
, " LS Type: %s\n",
6174 lookup_msg(ospf_lsa_type_msg
, lsa
->data
->type
, NULL
));
6175 vty_out(vty
, " Link State ID: %pI4 %s\n",
6177 lookup_msg(ospf_link_state_id_type_msg
, lsa
->data
->type
,
6179 vty_out(vty
, " Advertising Router: %pI4\n",
6180 &lsa
->data
->adv_router
);
6181 vty_out(vty
, " LS Seq Number: %08lx\n",
6182 (unsigned long)ntohl(lsa
->data
->ls_seqnum
));
6183 vty_out(vty
, " Checksum: 0x%04x\n",
6184 ntohs(lsa
->data
->checksum
));
6185 vty_out(vty
, " Length: %d\n\n", ntohs(lsa
->data
->length
));
6190 snprintf(seqnum
, 10, "%x", ntohl(lsa
->data
->ls_seqnum
));
6191 snprintf(checksum
, 10, "%x", ntohs(lsa
->data
->checksum
));
6193 json_object_int_add(json
, "lsaAge", LS_AGE(lsa
));
6194 json_object_string_add(json
, "options",
6195 ospf_options_dump(lsa
->data
->options
));
6196 json_object_int_add(json
, "lsaFlags", lsa
->flags
);
6198 if (lsa
->flags
& OSPF_LSA_LOCAL_XLT
)
6199 json_object_boolean_true_add(json
,
6200 "translatedFromType7");
6202 if (lsa
->data
->type
== OSPF_ROUTER_LSA
) {
6203 json_object_int_add(json
, "flags", rlsa
->flags
);
6206 if (IS_ROUTER_LSA_BORDER(rlsa
))
6207 json_object_boolean_true_add(json
,
6209 if (IS_ROUTER_LSA_EXTERNAL(rlsa
))
6210 json_object_boolean_true_add(json
,
6212 if (IS_ROUTER_LSA_VIRTUAL(rlsa
))
6213 json_object_boolean_true_add(
6214 json
, "vlEndpoint");
6215 if (IS_ROUTER_LSA_SHORTCUT(rlsa
))
6216 json_object_boolean_true_add(
6221 json_object_string_add(
6223 lookup_msg(ospf_lsa_type_msg
, lsa
->data
->type
, NULL
));
6224 json_object_string_addf(json
, "linkStateId", "%pI4",
6226 json_object_string_addf(json
, "advertisingRouter", "%pI4",
6227 &lsa
->data
->adv_router
);
6228 json_object_string_add(json
, "lsaSeqNumber", seqnum
);
6229 json_object_string_add(json
, "checksum", checksum
);
6230 json_object_int_add(json
, "length", ntohs(lsa
->data
->length
));
6234 static const char *const link_type_desc
[] = {
6236 "another Router (point-to-point)",
6237 "a Transit Network",
6242 static const char *const link_id_desc
[] = {
6243 "(null)", "Neighboring Router ID", "Designated Router address",
6244 "Net", "Neighboring Router ID",
6247 static const char *const link_data_desc
[] = {
6248 "(null)", "Router Interface address", "Router Interface address",
6249 "Network Mask", "Router Interface address",
6252 static const char *const link_id_desc_json
[] = {
6253 "null", "neighborRouterId", "designatedRouterAddress",
6254 "networkAddress", "neighborRouterId",
6257 static const char *const link_data_desc_json
[] = {
6258 "null", "routerInterfaceAddress", "routerInterfaceAddress",
6259 "networkMask", "routerInterfaceAddress",
6262 /* Show router-LSA each Link information. */
6263 static void show_ip_ospf_database_router_links(struct vty
*vty
,
6264 struct router_lsa
*rl
,
6269 json_object
*json_links
= NULL
;
6270 json_object
*json_link
= NULL
;
6272 char buf
[PREFIX_STRLEN
];
6275 json_links
= json_object_new_object();
6277 len
= ntohs(rl
->header
.length
) - 4;
6278 for (i
= 0; i
< ntohs(rl
->links
) && len
> 0; len
-= 12, i
++) {
6279 type
= rl
->link
[i
].type
;
6284 snprintf(link
, sizeof(link
), "link%u", i
);
6285 json_link
= json_object_new_object();
6286 json_object_string_add(json_link
, "linkType",
6287 link_type_desc
[type
]);
6288 json_object_string_add(json_link
,
6289 link_id_desc_json
[type
],
6291 &rl
->link
[i
].link_id
,
6293 json_object_string_add(
6294 json_link
, link_data_desc_json
[type
],
6295 inet_ntop(AF_INET
, &rl
->link
[i
].link_data
,
6297 json_object_int_add(json_link
, "numOfTosMetrics",
6299 json_object_int_add(json_link
, "tos0Metric",
6300 ntohs(rl
->link
[i
].metric
));
6301 json_object_object_add(json_links
, link
, json_link
);
6303 vty_out(vty
, " Link connected to: %s\n",
6304 link_type_desc
[type
]);
6305 vty_out(vty
, " (Link ID) %s: %pI4\n",
6307 &rl
->link
[i
].link_id
);
6308 vty_out(vty
, " (Link Data) %s: %pI4\n",
6309 link_data_desc
[type
],
6310 &rl
->link
[i
].link_data
);
6311 vty_out(vty
, " Number of TOS metrics: 0\n");
6312 vty_out(vty
, " TOS 0 Metric: %d\n",
6313 ntohs(rl
->link
[i
].metric
));
6318 json_object_object_add(json
, "routerLinks", json_links
);
6321 /* Show router-LSA detail information. */
6322 static int show_router_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6326 struct router_lsa
*rl
= (struct router_lsa
*)lsa
->data
;
6328 show_ip_ospf_database_header(vty
, lsa
, json
);
6331 vty_out(vty
, " Number of Links: %d\n\n",
6334 json_object_int_add(json
, "numOfLinks",
6337 show_ip_ospf_database_router_links(vty
, rl
, json
);
6346 /* Show network-LSA detail information. */
6347 static int show_network_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6351 char buf
[PREFIX_STRLEN
];
6352 json_object
*json_attached_rt
= NULL
;
6353 json_object
*json_router
= NULL
;
6356 json_attached_rt
= json_object_new_object();
6359 struct network_lsa
*nl
= (struct network_lsa
*)lsa
->data
;
6360 struct in_addr
*addr
;
6362 show_ip_ospf_database_header(vty
, lsa
, json
);
6365 vty_out(vty
, " Network Mask: /%d\n",
6366 ip_masklen(nl
->mask
));
6368 json_object_int_add(json
, "networkMask",
6369 ip_masklen(nl
->mask
));
6371 length
= lsa
->size
- OSPF_LSA_HEADER_SIZE
- 4;
6372 addr
= &nl
->routers
[0];
6373 for (i
= 0; length
> 0 && addr
;
6374 length
-= 4, addr
= &nl
->routers
[++i
])
6376 vty_out(vty
, " Attached Router: %pI4\n",
6380 json_router
= json_object_new_object();
6381 json_object_string_add(
6382 json_router
, "attachedRouterId",
6383 inet_ntop(AF_INET
, addr
, buf
,
6385 json_object_object_add(json_attached_rt
,
6386 inet_ntop(AF_INET
, addr
,
6394 json_object_object_add(json
, "attchedRouters",
6400 /* Show summary-LSA detail information. */
6401 static int show_summary_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6405 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
6407 show_ip_ospf_database_header(vty
, lsa
, json
);
6410 vty_out(vty
, " Network Mask: /%d\n",
6411 ip_masklen(sl
->mask
));
6412 vty_out(vty
, " TOS: 0 Metric: %d\n",
6413 GET_METRIC(sl
->metric
));
6416 json_object_int_add(json
, "networkMask",
6417 ip_masklen(sl
->mask
));
6418 json_object_int_add(json
, "tos0Metric",
6419 GET_METRIC(sl
->metric
));
6426 /* Show summary-ASBR-LSA detail information. */
6427 static int show_summary_asbr_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6431 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
6433 show_ip_ospf_database_header(vty
, lsa
, json
);
6436 vty_out(vty
, " Network Mask: /%d\n",
6437 ip_masklen(sl
->mask
));
6438 vty_out(vty
, " TOS: 0 Metric: %d\n",
6439 GET_METRIC(sl
->metric
));
6442 json_object_int_add(json
, "networkMask",
6443 ip_masklen(sl
->mask
));
6444 json_object_int_add(json
, "tos0Metric",
6445 GET_METRIC(sl
->metric
));
6452 /* Show AS-external-LSA detail information. */
6453 static int show_as_external_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6459 struct as_external_lsa
*al
=
6460 (struct as_external_lsa
*)lsa
->data
;
6462 show_ip_ospf_database_header(vty
, lsa
, json
);
6465 vty_out(vty
, " Network Mask: /%d\n",
6466 ip_masklen(al
->mask
));
6467 vty_out(vty
, " Metric Type: %s\n",
6468 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6469 ? "2 (Larger than any link state path)"
6471 vty_out(vty
, " TOS: 0\n");
6472 vty_out(vty
, " Metric: %d\n",
6473 GET_METRIC(al
->e
[0].metric
));
6474 vty_out(vty
, " Forward Address: %pI4\n",
6475 &al
->e
[0].fwd_addr
);
6477 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
6478 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6480 json_object_int_add(json
, "networkMask",
6481 ip_masklen(al
->mask
));
6482 json_object_string_add(
6484 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6485 ? "E2 (Larger than any link state path)"
6487 json_object_int_add(json
, "tos", tos
);
6488 json_object_int_add(json
, "metric",
6489 GET_METRIC(al
->e
[0].metric
));
6490 json_object_string_addf(json
, "forwardAddress", "%pI4",
6491 &(al
->e
[0].fwd_addr
));
6492 json_object_int_add(
6493 json
, "externalRouteTag",
6494 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6501 /* Show AS-NSSA-LSA detail information. */
6502 static int show_as_nssa_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6508 struct as_external_lsa
*al
=
6509 (struct as_external_lsa
*)lsa
->data
;
6511 show_ip_ospf_database_header(vty
, lsa
, json
);
6514 vty_out(vty
, " Network Mask: /%d\n",
6515 ip_masklen(al
->mask
));
6516 vty_out(vty
, " Metric Type: %s\n",
6517 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6518 ? "2 (Larger than any link state path)"
6520 vty_out(vty
, " TOS: 0\n");
6521 vty_out(vty
, " Metric: %d\n",
6522 GET_METRIC(al
->e
[0].metric
));
6523 vty_out(vty
, " NSSA: Forward Address: %pI4\n",
6524 &al
->e
[0].fwd_addr
);
6526 " External Route Tag: %" ROUTE_TAG_PRI
6528 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6530 json_object_int_add(json
, "networkMask",
6531 ip_masklen(al
->mask
));
6532 json_object_string_add(
6534 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6535 ? "E2 (Larger than any link state path)"
6537 json_object_int_add(json
, "tos", tos
);
6538 json_object_int_add(json
, "metric",
6539 GET_METRIC(al
->e
[0].metric
));
6540 json_object_string_addf(json
, "nssaForwardAddress",
6541 "%pI4", &al
->e
[0].fwd_addr
);
6542 json_object_int_add(
6543 json
, "externalRouteTag",
6544 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6551 static int show_func_dummy(struct vty
*vty
, struct ospf_lsa
*lsa
,
6557 static int show_opaque_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6561 show_ip_ospf_database_header(vty
, lsa
, json
);
6562 show_opaque_info_detail(vty
, lsa
, json
);
6569 int (*show_function
[])(struct vty
*, struct ospf_lsa
*, json_object
*) = {
6571 show_router_lsa_detail
,
6572 show_network_lsa_detail
,
6573 show_summary_lsa_detail
,
6574 show_summary_asbr_lsa_detail
,
6575 show_as_external_lsa_detail
,
6577 show_as_nssa_lsa_detail
, /* almost same as external */
6579 show_opaque_lsa_detail
,
6580 show_opaque_lsa_detail
,
6581 show_opaque_lsa_detail
,
6584 static void show_lsa_prefix_set(struct vty
*vty
, struct prefix_ls
*lp
,
6585 struct in_addr
*id
, struct in_addr
*adv_router
)
6587 memset(lp
, 0, sizeof(struct prefix_ls
));
6588 lp
->family
= AF_UNSPEC
;
6591 else if (adv_router
== NULL
) {
6592 lp
->prefixlen
= IPV4_MAX_BITLEN
;
6597 lp
->adv_router
= *adv_router
;
6601 static void show_lsa_detail_proc(struct vty
*vty
, struct route_table
*rt
,
6602 struct in_addr
*id
, struct in_addr
*adv_router
,
6605 struct prefix_ls lp
;
6606 struct route_node
*rn
, *start
;
6607 struct ospf_lsa
*lsa
;
6608 json_object
*json_lsa
= NULL
;
6610 show_lsa_prefix_set(vty
, &lp
, id
, adv_router
);
6611 start
= route_node_get(rt
, (struct prefix
*)&lp
);
6613 route_lock_node(start
);
6614 for (rn
= start
; rn
; rn
= route_next_until(rn
, start
))
6615 if ((lsa
= rn
->info
)) {
6616 if (show_function
[lsa
->data
->type
] != NULL
) {
6619 json_object_new_object();
6620 json_object_array_add(json
,
6624 show_function
[lsa
->data
->type
](
6625 vty
, lsa
, json_lsa
);
6628 route_unlock_node(start
);
6632 /* Show detail LSA information
6633 -- if id is NULL then show all LSAs. */
6634 static void show_lsa_detail(struct vty
*vty
, struct ospf
*ospf
, int type
,
6635 struct in_addr
*id
, struct in_addr
*adv_router
,
6638 struct listnode
*node
;
6639 struct ospf_area
*area
;
6640 char buf
[PREFIX_STRLEN
];
6641 json_object
*json_lsa_type
= NULL
;
6642 json_object
*json_areas
= NULL
;
6643 json_object
*json_lsa_array
= NULL
;
6646 case OSPF_AS_EXTERNAL_LSA
:
6647 case OSPF_OPAQUE_AS_LSA
:
6649 vty_out(vty
, " %s \n\n",
6650 show_database_desc
[type
]);
6652 json_lsa_array
= json_object_new_array();
6654 show_lsa_detail_proc(vty
, AS_LSDB(ospf
, type
), id
, adv_router
,
6657 json_object_object_add(json
,
6658 show_database_desc_json
[type
],
6664 json_areas
= json_object_new_object();
6666 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6669 "\n %s (Area %s)\n\n",
6670 show_database_desc
[type
],
6671 ospf_area_desc_string(area
));
6673 json_lsa_array
= json_object_new_array();
6674 json_object_object_add(json_areas
,
6682 show_lsa_detail_proc(vty
, AREA_LSDB(area
, type
), id
,
6683 adv_router
, json_lsa_array
);
6687 json_lsa_type
= json_object_new_object();
6688 json_object_object_add(json_lsa_type
, "areas",
6690 json_object_object_add(json
,
6691 show_database_desc_json
[type
],
6698 static void show_lsa_detail_adv_router_proc(struct vty
*vty
,
6699 struct route_table
*rt
,
6700 struct in_addr
*adv_router
,
6703 char buf
[PREFIX_STRLEN
];
6704 struct route_node
*rn
;
6705 struct ospf_lsa
*lsa
;
6707 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
))
6708 if ((lsa
= rn
->info
)) {
6709 json_object
*json_lsa
= NULL
;
6711 if (IPV4_ADDR_SAME(adv_router
,
6712 &lsa
->data
->adv_router
)) {
6713 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
6716 json_lsa
= json_object_new_object();
6718 if (show_function
[lsa
->data
->type
] != NULL
)
6719 show_function
[lsa
->data
->type
](
6720 vty
, lsa
, json_lsa
);
6722 json_object_object_add(
6732 /* Show detail LSA information. */
6733 static void show_lsa_detail_adv_router(struct vty
*vty
, struct ospf
*ospf
,
6734 int type
, struct in_addr
*adv_router
,
6737 struct listnode
*node
;
6738 struct ospf_area
*area
;
6739 char buf
[PREFIX_STRLEN
];
6740 json_object
*json_lstype
= NULL
;
6741 json_object
*json_area
= NULL
;
6744 json_lstype
= json_object_new_object();
6747 case OSPF_AS_EXTERNAL_LSA
:
6748 case OSPF_OPAQUE_AS_LSA
:
6750 vty_out(vty
, " %s \n\n",
6751 show_database_desc
[type
]);
6753 show_lsa_detail_adv_router_proc(vty
, AS_LSDB(ospf
, type
),
6754 adv_router
, json_lstype
);
6758 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6760 json_area
= json_object_new_object();
6763 "\n %s (Area %s)\n\n",
6764 show_database_desc
[type
],
6765 ospf_area_desc_string(area
));
6766 show_lsa_detail_adv_router_proc(vty
,
6767 AREA_LSDB(area
, type
),
6768 adv_router
, json_area
);
6771 json_object_object_add(json_lstype
,
6782 json_object_object_add(json
, show_database_desc
[type
],
6786 void show_ip_ospf_database_summary(struct vty
*vty
, struct ospf
*ospf
, int self
,
6789 struct ospf_lsa
*lsa
;
6790 struct route_node
*rn
;
6791 struct ospf_area
*area
;
6792 struct listnode
*node
;
6793 char buf
[PREFIX_STRLEN
];
6794 json_object
*json_areas
= NULL
;
6795 json_object
*json_area
= NULL
;
6796 json_object
*json_lsa
= NULL
;
6798 json_object
*json_lsa_array
= NULL
;
6802 json_areas
= json_object_new_object();
6804 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6806 json_area
= json_object_new_object();
6808 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6811 case OSPF_AS_EXTERNAL_LSA
:
6812 case OSPF_OPAQUE_AS_LSA
:
6817 if (ospf_lsdb_count_self(area
->lsdb
, type
) > 0
6819 && ospf_lsdb_count(area
->lsdb
, type
) > 0)) {
6823 " %s (Area %s)\n\n",
6824 show_database_desc
[type
],
6825 ospf_area_desc_string(area
));
6826 vty_out(vty
, "%s\n",
6827 show_database_header
[type
]);
6830 json_object_new_array();
6831 json_object_object_add(
6833 show_database_desc_json
[type
],
6837 LSDB_LOOP (AREA_LSDB(area
, type
), rn
, lsa
) {
6840 json_object_new_object();
6841 json_object_array_add(
6846 count
+= show_lsa_summary(
6847 vty
, lsa
, self
, json_lsa
);
6853 json_object_int_add(
6856 show_database_desc_count_json
6862 json_object_object_add(json_areas
,
6870 json_object_object_add(json
, "areas", json_areas
);
6872 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6875 case OSPF_AS_EXTERNAL_LSA
:
6876 case OSPF_OPAQUE_AS_LSA
:
6881 if (ospf_lsdb_count_self(ospf
->lsdb
, type
)
6882 || (!self
&& ospf_lsdb_count(ospf
->lsdb
, type
))) {
6884 vty_out(vty
, " %s\n\n",
6885 show_database_desc
[type
]);
6886 vty_out(vty
, "%s\n",
6887 show_database_header
[type
]);
6889 json_lsa_array
= json_object_new_array();
6890 json_object_object_add(
6891 json
, show_database_desc_json
[type
],
6895 LSDB_LOOP (AS_LSDB(ospf
, type
), rn
, lsa
) {
6897 json_lsa
= json_object_new_object();
6898 json_object_array_add(json_lsa_array
,
6902 count
+= show_lsa_summary(vty
, lsa
, self
,
6909 json_object_int_add(
6911 show_database_desc_count_json
[type
],
6920 static void show_ip_ospf_database_maxage(struct vty
*vty
, struct ospf
*ospf
,
6923 struct route_node
*rn
;
6924 char buf
[PREFIX_STRLEN
];
6925 json_object
*json_maxage
= NULL
;
6928 vty_out(vty
, "\n MaxAge Link States:\n\n");
6930 json_maxage
= json_object_new_object();
6932 for (rn
= route_top(ospf
->maxage_lsa
); rn
; rn
= route_next(rn
)) {
6933 struct ospf_lsa
*lsa
;
6934 json_object
*json_lsa
= NULL
;
6936 if ((lsa
= rn
->info
) != NULL
) {
6938 vty_out(vty
, "Link type: %d\n",
6940 vty_out(vty
, "Link State ID: %pI4\n",
6942 vty_out(vty
, "Advertising Router: %pI4\n",
6943 &lsa
->data
->adv_router
);
6944 vty_out(vty
, "LSA lock count: %d\n", lsa
->lock
);
6947 json_lsa
= json_object_new_object();
6948 json_object_int_add(json_lsa
, "linkType",
6950 json_object_string_addf(json_lsa
, "linkStateId",
6951 "%pI4", &lsa
->data
->id
);
6952 json_object_string_addf(
6953 json_lsa
, "advertisingRouter", "%pI4",
6954 &lsa
->data
->adv_router
);
6955 json_object_int_add(json_lsa
, "lsaLockCount",
6957 json_object_object_add(
6967 json_object_object_add(json
, "maxAgeLinkStates", json_maxage
);
6970 #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
6971 #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
6973 #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
6974 #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
6975 #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
6976 #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
6978 #define OSPF_LSA_TYPES_DESC \
6979 "ASBR summary link states\n" \
6980 "External link states\n" \
6981 "Network link states\n" \
6982 "Router link states\n" \
6983 "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \
6984 OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
6985 OSPF_LSA_TYPE_OPAQUE_AS_DESC
6987 static int show_ip_ospf_database_common(struct vty
*vty
, struct ospf
*ospf
,
6988 int arg_base
, int argc
,
6989 struct cmd_token
**argv
,
6990 uint8_t use_vrf
, json_object
*json
,
6995 struct in_addr id
, adv_router
;
6996 json_object
*json_vrf
= NULL
;
7000 json_vrf
= json_object_new_object();
7005 if (ospf
->instance
) {
7007 json_object_int_add(json_vrf
, "ospfInstance",
7010 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
7013 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
7015 /* Show Router ID. */
7017 json_object_string_addf(json_vrf
, "routerId", "%pI4",
7020 vty_out(vty
, "\n OSPF Router with ID (%pI4)\n\n",
7025 if ((argc
== arg_base
+ 4) || (uj
&& (argc
== arg_base
+ 5))) {
7026 show_ip_ospf_database_summary(vty
, ospf
, 0, json_vrf
);
7029 json_object_object_add(
7030 json
, ospf_get_name(ospf
), json_vrf
);
7035 /* Set database type to show. */
7036 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
7037 type
= OSPF_ROUTER_LSA
;
7038 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
7039 type
= OSPF_NETWORK_LSA
;
7040 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
7041 type
= OSPF_AS_NSSA_LSA
;
7042 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "su", 2) == 0)
7043 type
= OSPF_SUMMARY_LSA
;
7044 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
7045 type
= OSPF_ASBR_SUMMARY_LSA
;
7046 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
7047 type
= OSPF_AS_EXTERNAL_LSA
;
7048 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "se", 2) == 0) {
7049 show_ip_ospf_database_summary(vty
, ospf
, 1, json_vrf
);
7052 json_object_object_add(
7053 json
, ospf_get_name(ospf
), json_vrf
);
7056 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "m", 1) == 0) {
7057 show_ip_ospf_database_maxage(vty
, ospf
, json_vrf
);
7060 json_object_object_add(
7061 json
, ospf_get_name(ospf
), json_vrf
);
7064 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
7065 type
= OSPF_OPAQUE_LINK_LSA
;
7066 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
7067 type
= OSPF_OPAQUE_AREA_LSA
;
7068 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
7069 type
= OSPF_OPAQUE_AS_LSA
;
7073 /* `show ip ospf database LSA'. */
7074 if ((argc
== arg_base
+ 5) || (uj
&& (argc
== arg_base
+ 6)))
7075 show_lsa_detail(vty
, ospf
, type
, NULL
, NULL
, json_vrf
);
7076 else if (argc
>= arg_base
+ 6) {
7077 ret
= inet_aton(argv
[arg_base
+ 5]->arg
, &id
);
7081 /* `show ip ospf database LSA ID'. */
7082 if ((argc
== arg_base
+ 6) || (uj
&& (argc
== arg_base
+ 7)))
7083 show_lsa_detail(vty
, ospf
, type
, &id
, NULL
, json_vrf
);
7084 /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */
7085 else if ((argc
== arg_base
+ 7)
7086 || (uj
&& (argc
== arg_base
+ 8))) {
7087 if (strncmp(argv
[arg_base
+ 6]->text
, "s", 1) == 0)
7088 adv_router
= ospf
->router_id
;
7090 ret
= inet_aton(argv
[arg_base
+ 7]->arg
,
7095 show_lsa_detail(vty
, ospf
, type
, &id
, &adv_router
,
7102 json_object_object_add(json
, ospf_get_name(ospf
),
7109 DEFUN (show_ip_ospf_database_max
,
7110 show_ip_ospf_database_max_cmd
,
7111 "show ip ospf [vrf <NAME|all>] database <max-age|self-originate> [json]",
7114 "OSPF information\n"
7117 "Database summary\n"
7118 "LSAs in MaxAge list\n"
7119 "Self-originated link states\n"
7122 struct ospf
*ospf
= NULL
;
7123 struct listnode
*node
= NULL
;
7124 char *vrf_name
= NULL
;
7125 bool all_vrf
= false;
7126 int ret
= CMD_SUCCESS
;
7129 uint8_t use_vrf
= 0;
7130 bool uj
= use_json(argc
, argv
);
7131 json_object
*json
= NULL
;
7134 json
= json_object_new_object();
7136 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
7139 bool ospf_output
= false;
7144 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
7145 if (!ospf
->oi_running
)
7148 ret
= show_ip_ospf_database_common(
7149 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
,
7154 vty_out(vty
, "%% OSPF is not enabled\n");
7156 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
7157 if (ospf
== NULL
|| !ospf
->oi_running
) {
7159 "%% OSPF is not enabled in vrf %s\n",
7162 json_object_free(json
);
7166 ret
= (show_ip_ospf_database_common(
7167 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
, use_vrf
,
7171 /* Display default ospf (instance 0) info */
7172 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
7173 if (ospf
== NULL
|| !ospf
->oi_running
) {
7174 vty_out(vty
, "%% OSPF is not enabled in vrf default\n");
7176 json_object_free(json
);
7181 ret
= show_ip_ospf_database_common(vty
, ospf
, 0, argc
, argv
,
7186 vty_json(vty
, json
);
7191 ALIAS (show_ip_ospf_database_max
,
7192 show_ip_ospf_database_cmd
,
7193 "show ip ospf [vrf <NAME|all>] database [<asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as> [A.B.C.D [<self-originate|adv-router A.B.C.D>]]] [json]",
7196 "OSPF information\n"
7199 "Database summary\n"
7201 "Link State ID (as an IP address)\n"
7202 "Self-originated link states\n"
7203 "Advertising Router link states\n"
7204 "Advertising Router (as an IP address)\n"
7207 DEFUN (show_ip_ospf_instance_database_max
,
7208 show_ip_ospf_instance_database_max_cmd
,
7209 "show ip ospf (1-65535) database <max-age|self-originate> [json]",
7212 "OSPF information\n"
7214 "Database summary\n"
7215 "LSAs in MaxAge list\n"
7216 "Self-originated link states\n"
7221 unsigned short instance
= 0;
7222 bool uj
= use_json(argc
, argv
);
7223 json_object
*json
= NULL
;
7226 json
= json_object_new_object();
7228 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
7229 if (instance
!= ospf_instance
)
7230 return CMD_NOT_MY_INSTANCE
;
7232 ospf
= ospf_lookup_instance(instance
);
7233 if (!ospf
|| !ospf
->oi_running
)
7236 show_ip_ospf_database_common(vty
, ospf
, 1, argc
, argv
, 0, json
, uj
);
7239 vty_json(vty
, json
);
7244 ALIAS (show_ip_ospf_instance_database_max
,
7245 show_ip_ospf_instance_database_cmd
,
7246 "show ip ospf (1-65535) database [<asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as> [A.B.C.D [<self-originate|adv-router A.B.C.D>]]] [json]",
7249 "OSPF information\n"
7251 "Database summary\n"
7253 "Link State ID (as an IP address)\n"
7254 "Self-originated link states\n"
7255 "Advertising Router link states\n"
7256 "Advertising Router (as an IP address)\n"
7259 static int show_ip_ospf_database_type_adv_router_common(struct vty
*vty
,
7261 int arg_base
, int argc
,
7262 struct cmd_token
**argv
,
7269 struct in_addr adv_router
;
7270 json_object
*json_vrf
= NULL
;
7274 json_vrf
= json_object_new_object();
7279 if (ospf
->instance
) {
7281 json_object_int_add(json
, "ospfInstance",
7284 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
7287 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
7289 /* Show Router ID. */
7291 json_object_string_addf(json_vrf
, "routerId", "%pI4",
7294 vty_out(vty
, "\n OSPF Router with ID (%pI4)\n\n",
7298 /* Set database type to show. */
7299 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
7300 type
= OSPF_ROUTER_LSA
;
7301 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
7302 type
= OSPF_NETWORK_LSA
;
7303 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
7304 type
= OSPF_AS_NSSA_LSA
;
7305 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "s", 1) == 0)
7306 type
= OSPF_SUMMARY_LSA
;
7307 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
7308 type
= OSPF_ASBR_SUMMARY_LSA
;
7309 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
7310 type
= OSPF_AS_EXTERNAL_LSA
;
7311 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
7312 type
= OSPF_OPAQUE_LINK_LSA
;
7313 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
7314 type
= OSPF_OPAQUE_AREA_LSA
;
7315 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
7316 type
= OSPF_OPAQUE_AS_LSA
;
7320 /* `show ip ospf database LSA adv-router ADV_ROUTER'. */
7321 if (strncmp(argv
[arg_base
+ 5]->text
, "s", 1) == 0)
7322 adv_router
= ospf
->router_id
;
7324 ret
= inet_aton(argv
[arg_base
+ 6]->arg
, &adv_router
);
7329 show_lsa_detail_adv_router(vty
, ospf
, type
, &adv_router
, json_vrf
);
7333 json_object_object_add(json
, ospf_get_name(ospf
),
7340 DEFUN (show_ip_ospf_database_type_adv_router
,
7341 show_ip_ospf_database_type_adv_router_cmd
,
7342 "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]",
7345 "OSPF information\n"
7348 "Database summary\n"
7350 "Advertising Router link states\n"
7351 "Advertising Router (as an IP address)\n"
7352 "Self-originated link states\n"
7355 struct ospf
*ospf
= NULL
;
7356 struct listnode
*node
= NULL
;
7357 char *vrf_name
= NULL
;
7358 bool all_vrf
= false;
7359 int ret
= CMD_SUCCESS
;
7362 uint8_t use_vrf
= 0;
7363 bool uj
= use_json(argc
, argv
);
7364 json_object
*json
= NULL
;
7367 json
= json_object_new_object();
7369 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
7372 bool ospf_output
= false;
7377 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
7378 if (!ospf
->oi_running
)
7381 ret
= show_ip_ospf_database_type_adv_router_common(
7382 vty
, ospf
, 2, argc
, argv
, use_vrf
, json
,
7386 vty_out(vty
, "%% OSPF is not enabled\n");
7388 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
7389 if ((ospf
== NULL
) || !ospf
->oi_running
) {
7391 "%% OSPF is not enabled in vrf %s\n",
7396 ret
= show_ip_ospf_database_type_adv_router_common(
7397 vty
, ospf
, 2, argc
, argv
, use_vrf
, json
, uj
);
7400 /* Display default ospf (instance 0) info */
7401 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
7402 if (ospf
== NULL
|| !ospf
->oi_running
) {
7403 vty_out(vty
, "%% OSPF is not enabled on vrf default\n");
7407 ret
= show_ip_ospf_database_type_adv_router_common(
7408 vty
, ospf
, 0, argc
, argv
, use_vrf
, json
, uj
);
7412 vty_out(vty
, "%s\n", json_object_to_json_string(json
));
7413 json_object_free(json
);
7419 DEFUN (show_ip_ospf_instance_database_type_adv_router
,
7420 show_ip_ospf_instance_database_type_adv_router_cmd
,
7421 "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]",
7424 "OSPF information\n"
7426 "Database summary\n"
7428 "Advertising Router link states\n"
7429 "Advertising Router (as an IP address)\n"
7430 "Self-originated link states\n"
7435 unsigned short instance
= 0;
7436 bool uj
= use_json(argc
, argv
);
7437 json_object
*json
= NULL
;
7440 json
= json_object_new_object();
7442 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
7443 if (instance
!= ospf_instance
)
7444 return CMD_NOT_MY_INSTANCE
;
7446 ospf
= ospf_lookup_instance(instance
);
7447 if (!ospf
|| !ospf
->oi_running
)
7450 show_ip_ospf_database_type_adv_router_common(vty
, ospf
, 1, argc
, argv
,
7454 vty_json(vty
, json
);
7459 DEFUN (ip_ospf_authentication_args
,
7460 ip_ospf_authentication_args_addr_cmd
,
7461 "ip ospf authentication <null|message-digest> [A.B.C.D]",
7463 "OSPF interface commands\n"
7464 "Enable authentication on this interface\n"
7465 "Use null authentication\n"
7466 "Use message-digest authentication\n"
7467 "Address of interface\n")
7469 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7470 int idx_encryption
= 3;
7472 struct in_addr addr
;
7474 struct ospf_if_params
*params
;
7476 params
= IF_DEF_PARAMS(ifp
);
7479 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7482 "Please specify interface address by A.B.C.D\n");
7483 return CMD_WARNING_CONFIG_FAILED
;
7486 params
= ospf_get_if_params(ifp
, addr
);
7487 ospf_if_update_params(ifp
, addr
);
7490 /* Handle null authentication */
7491 if (argv
[idx_encryption
]->arg
[0] == 'n') {
7492 SET_IF_PARAM(params
, auth_type
);
7493 params
->auth_type
= OSPF_AUTH_NULL
;
7497 /* Handle message-digest authentication */
7498 if (argv
[idx_encryption
]->arg
[0] == 'm') {
7499 SET_IF_PARAM(params
, auth_type
);
7500 params
->auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
7504 vty_out(vty
, "You shouldn't get here!\n");
7505 return CMD_WARNING_CONFIG_FAILED
;
7508 DEFUN (ip_ospf_authentication
,
7509 ip_ospf_authentication_addr_cmd
,
7510 "ip ospf authentication [A.B.C.D]",
7512 "OSPF interface commands\n"
7513 "Enable authentication on this interface\n"
7514 "Address of interface\n")
7516 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7518 struct in_addr addr
;
7520 struct ospf_if_params
*params
;
7522 params
= IF_DEF_PARAMS(ifp
);
7525 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7528 "Please specify interface address by A.B.C.D\n");
7529 return CMD_WARNING_CONFIG_FAILED
;
7532 params
= ospf_get_if_params(ifp
, addr
);
7533 ospf_if_update_params(ifp
, addr
);
7536 SET_IF_PARAM(params
, auth_type
);
7537 params
->auth_type
= OSPF_AUTH_SIMPLE
;
7542 DEFUN (no_ip_ospf_authentication_args
,
7543 no_ip_ospf_authentication_args_addr_cmd
,
7544 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
7547 "OSPF interface commands\n"
7548 "Enable authentication on this interface\n"
7549 "Use null authentication\n"
7550 "Use message-digest authentication\n"
7551 "Address of interface\n")
7553 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7554 int idx_encryption
= 4;
7556 struct in_addr addr
;
7558 struct ospf_if_params
*params
;
7559 struct route_node
*rn
;
7562 params
= IF_DEF_PARAMS(ifp
);
7565 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7568 "Please specify interface address by A.B.C.D\n");
7569 return CMD_WARNING_CONFIG_FAILED
;
7572 params
= ospf_lookup_if_params(ifp
, addr
);
7573 if (params
== NULL
) {
7574 vty_out(vty
, "Ip Address specified is unknown\n");
7575 return CMD_WARNING_CONFIG_FAILED
;
7577 params
->auth_type
= OSPF_AUTH_NOTSET
;
7578 UNSET_IF_PARAM(params
, auth_type
);
7579 if (params
!= IF_DEF_PARAMS(ifp
)) {
7580 ospf_free_if_params(ifp
, addr
);
7581 ospf_if_update_params(ifp
, addr
);
7584 if (argv
[idx_encryption
]->arg
[0] == 'n') {
7585 auth_type
= OSPF_AUTH_NULL
;
7586 } else if (argv
[idx_encryption
]->arg
[0] == 'm') {
7587 auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
7589 vty_out(vty
, "Unexpected input encountered\n");
7590 return CMD_WARNING_CONFIG_FAILED
;
7593 * Here we have a case where the user has entered
7594 * 'no ip ospf authentication (null | message_digest )'
7595 * we need to find if we have any ip addresses underneath it
7597 * correspond to the associated type.
7599 if (params
->auth_type
== auth_type
) {
7600 params
->auth_type
= OSPF_AUTH_NOTSET
;
7601 UNSET_IF_PARAM(params
, auth_type
);
7604 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
7605 rn
= route_next(rn
)) {
7606 if ((params
= rn
->info
)) {
7607 if (params
->auth_type
== auth_type
) {
7608 params
->auth_type
= OSPF_AUTH_NOTSET
;
7609 UNSET_IF_PARAM(params
, auth_type
);
7610 if (params
!= IF_DEF_PARAMS(ifp
)) {
7611 ospf_free_if_params(
7612 ifp
, rn
->p
.u
.prefix4
);
7613 ospf_if_update_params(
7614 ifp
, rn
->p
.u
.prefix4
);
7624 DEFUN (no_ip_ospf_authentication
,
7625 no_ip_ospf_authentication_addr_cmd
,
7626 "no ip ospf authentication [A.B.C.D]",
7629 "OSPF interface commands\n"
7630 "Enable authentication on this interface\n"
7631 "Address of interface\n")
7633 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7635 struct in_addr addr
;
7637 struct ospf_if_params
*params
;
7638 struct route_node
*rn
;
7640 params
= IF_DEF_PARAMS(ifp
);
7643 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7646 "Please specify interface address by A.B.C.D\n");
7647 return CMD_WARNING_CONFIG_FAILED
;
7650 params
= ospf_lookup_if_params(ifp
, addr
);
7651 if (params
== NULL
) {
7652 vty_out(vty
, "Ip Address specified is unknown\n");
7653 return CMD_WARNING_CONFIG_FAILED
;
7656 params
->auth_type
= OSPF_AUTH_NOTSET
;
7657 UNSET_IF_PARAM(params
, auth_type
);
7658 if (params
!= IF_DEF_PARAMS(ifp
)) {
7659 ospf_free_if_params(ifp
, addr
);
7660 ospf_if_update_params(ifp
, addr
);
7664 * When a user enters 'no ip ospf authentication'
7665 * We should remove all authentication types from
7668 if ((params
->auth_type
== OSPF_AUTH_NULL
)
7669 || (params
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
7670 || (params
->auth_type
== OSPF_AUTH_SIMPLE
)) {
7671 params
->auth_type
= OSPF_AUTH_NOTSET
;
7672 UNSET_IF_PARAM(params
, auth_type
);
7675 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
7676 rn
= route_next(rn
)) {
7677 if ((params
= rn
->info
)) {
7679 if ((params
->auth_type
== OSPF_AUTH_NULL
)
7680 || (params
->auth_type
7681 == OSPF_AUTH_CRYPTOGRAPHIC
)
7682 || (params
->auth_type
7683 == OSPF_AUTH_SIMPLE
)) {
7684 params
->auth_type
= OSPF_AUTH_NOTSET
;
7685 UNSET_IF_PARAM(params
, auth_type
);
7686 if (params
!= IF_DEF_PARAMS(ifp
)) {
7687 ospf_free_if_params(
7688 ifp
, rn
->p
.u
.prefix4
);
7689 ospf_if_update_params(
7690 ifp
, rn
->p
.u
.prefix4
);
7701 DEFUN (ip_ospf_authentication_key
,
7702 ip_ospf_authentication_key_addr_cmd
,
7703 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
7705 "OSPF interface commands\n"
7706 "Authentication password (key)\n"
7707 "The OSPF password (key)\n"
7708 "Address of interface\n")
7710 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7712 struct in_addr addr
;
7713 struct ospf_if_params
*params
;
7715 params
= IF_DEF_PARAMS(ifp
);
7717 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7718 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7720 "Please specify interface address by A.B.C.D\n");
7721 return CMD_WARNING_CONFIG_FAILED
;
7724 params
= ospf_get_if_params(ifp
, addr
);
7725 ospf_if_update_params(ifp
, addr
);
7728 strlcpy((char *)params
->auth_simple
, argv
[3]->arg
,
7729 sizeof(params
->auth_simple
));
7730 SET_IF_PARAM(params
, auth_simple
);
7735 DEFUN_HIDDEN (ospf_authentication_key
,
7736 ospf_authentication_key_cmd
,
7737 "ospf authentication-key AUTH_KEY [A.B.C.D]",
7738 "OSPF interface commands\n"
7739 VLINK_HELPSTR_AUTH_SIMPLE
7740 "Address of interface\n")
7742 return ip_ospf_authentication_key(self
, vty
, argc
, argv
);
7745 DEFUN (no_ip_ospf_authentication_key
,
7746 no_ip_ospf_authentication_key_authkey_addr_cmd
,
7747 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7750 "OSPF interface commands\n"
7751 VLINK_HELPSTR_AUTH_SIMPLE
7752 "Address of interface\n")
7754 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7756 struct in_addr addr
;
7757 struct ospf_if_params
*params
;
7758 params
= IF_DEF_PARAMS(ifp
);
7760 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7761 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7763 "Please specify interface address by A.B.C.D\n");
7764 return CMD_WARNING_CONFIG_FAILED
;
7767 params
= ospf_lookup_if_params(ifp
, addr
);
7772 memset(params
->auth_simple
, 0, OSPF_AUTH_SIMPLE_SIZE
);
7773 UNSET_IF_PARAM(params
, auth_simple
);
7775 if (params
!= IF_DEF_PARAMS(ifp
)) {
7776 ospf_free_if_params(ifp
, addr
);
7777 ospf_if_update_params(ifp
, addr
);
7783 DEFUN_HIDDEN (no_ospf_authentication_key
,
7784 no_ospf_authentication_key_authkey_addr_cmd
,
7785 "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7787 "OSPF interface commands\n"
7788 VLINK_HELPSTR_AUTH_SIMPLE
7789 "Address of interface\n")
7791 return no_ip_ospf_authentication_key(self
, vty
, argc
, argv
);
7794 DEFUN (ip_ospf_message_digest_key
,
7795 ip_ospf_message_digest_key_cmd
,
7796 "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7798 "OSPF interface commands\n"
7799 "Message digest authentication password (key)\n"
7801 "Use MD5 algorithm\n"
7802 "The OSPF password (key)\n"
7803 "Address of interface\n")
7805 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7806 struct crypt_key
*ck
;
7808 struct in_addr addr
;
7809 struct ospf_if_params
*params
;
7811 params
= IF_DEF_PARAMS(ifp
);
7814 argv_find(argv
, argc
, "(1-255)", &idx
);
7815 char *keyid
= argv
[idx
]->arg
;
7816 argv_find(argv
, argc
, "KEY", &idx
);
7817 char *cryptkey
= argv
[idx
]->arg
;
7819 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7820 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7822 "Please specify interface address by A.B.C.D\n");
7823 return CMD_WARNING_CONFIG_FAILED
;
7826 params
= ospf_get_if_params(ifp
, addr
);
7827 ospf_if_update_params(ifp
, addr
);
7830 key_id
= strtol(keyid
, NULL
, 10);
7832 /* Remove existing key, if any */
7833 ospf_crypt_key_delete(params
->auth_crypt
, key_id
);
7835 ck
= ospf_crypt_key_new();
7836 ck
->key_id
= (uint8_t)key_id
;
7837 strlcpy((char *)ck
->auth_key
, cryptkey
, sizeof(ck
->auth_key
));
7839 ospf_crypt_key_add(params
->auth_crypt
, ck
);
7840 SET_IF_PARAM(params
, auth_crypt
);
7845 DEFUN_HIDDEN (ospf_message_digest_key
,
7846 ospf_message_digest_key_cmd
,
7847 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7848 "OSPF interface commands\n"
7849 "Message digest authentication password (key)\n"
7851 "Use MD5 algorithm\n"
7852 "The OSPF password (key)\n"
7853 "Address of interface\n")
7855 return ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7858 DEFUN (no_ip_ospf_message_digest_key
,
7859 no_ip_ospf_message_digest_key_cmd
,
7860 "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7863 "OSPF interface commands\n"
7864 "Message digest authentication password (key)\n"
7866 "Use MD5 algorithm\n"
7867 "The OSPF password (key)\n"
7868 "Address of interface\n")
7870 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7872 struct crypt_key
*ck
;
7874 struct in_addr addr
;
7875 struct ospf_if_params
*params
;
7876 params
= IF_DEF_PARAMS(ifp
);
7878 argv_find(argv
, argc
, "(1-255)", &idx
);
7879 char *keyid
= argv
[idx
]->arg
;
7881 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7882 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7884 "Please specify interface address by A.B.C.D\n");
7885 return CMD_WARNING_CONFIG_FAILED
;
7888 params
= ospf_lookup_if_params(ifp
, addr
);
7893 key_id
= strtol(keyid
, NULL
, 10);
7894 ck
= ospf_crypt_key_lookup(params
->auth_crypt
, key_id
);
7896 vty_out(vty
, "OSPF: Key %d does not exist\n", key_id
);
7897 return CMD_WARNING_CONFIG_FAILED
;
7900 ospf_crypt_key_delete(params
->auth_crypt
, key_id
);
7902 if (params
!= IF_DEF_PARAMS(ifp
)) {
7903 ospf_free_if_params(ifp
, addr
);
7904 ospf_if_update_params(ifp
, addr
);
7910 DEFUN_HIDDEN (no_ospf_message_digest_key
,
7911 no_ospf_message_digest_key_cmd
,
7912 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7914 "OSPF interface commands\n"
7915 "Message digest authentication password (key)\n"
7917 "Use MD5 algorithm\n"
7918 "The OSPF password (key)\n"
7919 "Address of interface\n")
7921 return no_ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7924 DEFUN (ip_ospf_cost
,
7926 "ip ospf cost (1-65535) [A.B.C.D]",
7928 "OSPF interface commands\n"
7931 "Address of interface\n")
7933 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7935 uint32_t cost
= OSPF_OUTPUT_COST_DEFAULT
;
7936 struct in_addr addr
;
7937 struct ospf_if_params
*params
;
7938 params
= IF_DEF_PARAMS(ifp
);
7941 char *coststr
= NULL
, *ifaddr
= NULL
;
7943 argv_find(argv
, argc
, "(1-65535)", &idx
);
7944 coststr
= argv
[idx
]->arg
;
7945 cost
= strtol(coststr
, NULL
, 10);
7947 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7949 if (!inet_aton(ifaddr
, &addr
)) {
7951 "Please specify interface address by A.B.C.D\n");
7952 return CMD_WARNING_CONFIG_FAILED
;
7955 params
= ospf_get_if_params(ifp
, addr
);
7956 ospf_if_update_params(ifp
, addr
);
7959 SET_IF_PARAM(params
, output_cost_cmd
);
7960 params
->output_cost_cmd
= cost
;
7962 ospf_if_recalculate_output_cost(ifp
);
7967 DEFUN_HIDDEN (ospf_cost
,
7969 "ospf cost (1-65535) [A.B.C.D]",
7970 "OSPF interface commands\n"
7973 "Address of interface\n")
7975 return ip_ospf_cost(self
, vty
, argc
, argv
);
7978 DEFUN (no_ip_ospf_cost
,
7979 no_ip_ospf_cost_cmd
,
7980 "no ip ospf cost [(1-65535)] [A.B.C.D]",
7983 "OSPF interface commands\n"
7986 "Address of interface\n")
7988 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7990 struct in_addr addr
;
7991 struct ospf_if_params
*params
;
7993 params
= IF_DEF_PARAMS(ifp
);
7996 char *ifaddr
= NULL
;
7997 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7999 /* According to the semantics we are mimicking "no ip ospf cost N" is
8000 * always treated as "no ip ospf cost" regardless of the actual value
8001 * of N already configured for the interface. Thus ignore cost. */
8004 if (!inet_aton(ifaddr
, &addr
)) {
8006 "Please specify interface address by A.B.C.D\n");
8007 return CMD_WARNING_CONFIG_FAILED
;
8010 params
= ospf_lookup_if_params(ifp
, addr
);
8015 UNSET_IF_PARAM(params
, output_cost_cmd
);
8017 if (params
!= IF_DEF_PARAMS(ifp
)) {
8018 ospf_free_if_params(ifp
, addr
);
8019 ospf_if_update_params(ifp
, addr
);
8022 ospf_if_recalculate_output_cost(ifp
);
8027 DEFUN_HIDDEN (no_ospf_cost
,
8029 "no ospf cost [(1-65535)] [A.B.C.D]",
8031 "OSPF interface commands\n"
8034 "Address of interface\n")
8036 return no_ip_ospf_cost(self
, vty
, argc
, argv
);
8039 static void ospf_nbr_timer_update(struct ospf_interface
*oi
)
8041 struct route_node
*rn
;
8042 struct ospf_neighbor
*nbr
;
8044 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
8050 nbr
->v_inactivity
= OSPF_IF_PARAM(oi
, v_wait
);
8051 nbr
->v_db_desc
= OSPF_IF_PARAM(oi
, retransmit_interval
);
8052 nbr
->v_ls_req
= OSPF_IF_PARAM(oi
, retransmit_interval
);
8053 nbr
->v_ls_upd
= OSPF_IF_PARAM(oi
, retransmit_interval
);
8057 static int ospf_vty_dead_interval_set(struct vty
*vty
, const char *interval_str
,
8058 const char *nbr_str
,
8059 const char *fast_hello_str
)
8061 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8064 struct in_addr addr
;
8066 struct ospf_if_params
*params
;
8067 struct ospf_interface
*oi
;
8068 struct route_node
*rn
;
8070 params
= IF_DEF_PARAMS(ifp
);
8073 ret
= inet_aton(nbr_str
, &addr
);
8076 "Please specify interface address by A.B.C.D\n");
8077 return CMD_WARNING_CONFIG_FAILED
;
8080 params
= ospf_get_if_params(ifp
, addr
);
8081 ospf_if_update_params(ifp
, addr
);
8085 seconds
= strtoul(interval_str
, NULL
, 10);
8087 /* reset fast_hello too, just to be sure */
8088 UNSET_IF_PARAM(params
, fast_hello
);
8089 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
8090 } else if (fast_hello_str
) {
8091 hellomult
= strtoul(fast_hello_str
, NULL
, 10);
8092 /* 1s dead-interval with sub-second hellos desired */
8093 seconds
= OSPF_ROUTER_DEAD_INTERVAL_MINIMAL
;
8094 SET_IF_PARAM(params
, fast_hello
);
8095 params
->fast_hello
= hellomult
;
8098 "Please specify dead-interval or hello-multiplier\n");
8099 return CMD_WARNING_CONFIG_FAILED
;
8102 SET_IF_PARAM(params
, v_wait
);
8103 params
->v_wait
= seconds
;
8104 params
->is_v_wait_set
= true;
8106 /* Update timer values in neighbor structure. */
8108 struct ospf
*ospf
= NULL
;
8110 ospf
= ifp
->vrf
->info
;
8112 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
8114 ospf_nbr_timer_update(oi
);
8117 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
8118 if ((oi
= rn
->info
))
8119 ospf_nbr_timer_update(oi
);
8125 DEFUN (ip_ospf_dead_interval
,
8126 ip_ospf_dead_interval_cmd
,
8127 "ip ospf dead-interval (1-65535) [A.B.C.D]",
8129 "OSPF interface commands\n"
8130 "Interval time after which a neighbor is declared down\n"
8132 "Address of interface\n")
8135 char *interval
= argv_find(argv
, argc
, "(1-65535)", &idx
)
8139 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
8140 return ospf_vty_dead_interval_set(vty
, interval
, ifaddr
, NULL
);
8144 DEFUN_HIDDEN (ospf_dead_interval
,
8145 ospf_dead_interval_cmd
,
8146 "ospf dead-interval (1-65535) [A.B.C.D]",
8147 "OSPF interface commands\n"
8148 "Interval time after which a neighbor is declared down\n"
8150 "Address of interface\n")
8152 return ip_ospf_dead_interval(self
, vty
, argc
, argv
);
8155 DEFUN (ip_ospf_dead_interval_minimal
,
8156 ip_ospf_dead_interval_minimal_addr_cmd
,
8157 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
8159 "OSPF interface commands\n"
8160 "Interval time after which a neighbor is declared down\n"
8161 "Minimal 1s dead-interval with fast sub-second hellos\n"
8162 "Hello multiplier factor\n"
8163 "Number of Hellos to send each second\n"
8164 "Address of interface\n")
8169 return ospf_vty_dead_interval_set(
8170 vty
, NULL
, argv
[idx_ipv4
]->arg
, argv
[idx_number
]->arg
);
8172 return ospf_vty_dead_interval_set(vty
, NULL
, NULL
,
8173 argv
[idx_number
]->arg
);
8176 DEFUN (no_ip_ospf_dead_interval
,
8177 no_ip_ospf_dead_interval_cmd
,
8178 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8181 "OSPF interface commands\n"
8182 "Interval time after which a neighbor is declared down\n"
8184 "Minimal 1s dead-interval with fast sub-second hellos\n"
8185 "Hello multiplier factor\n"
8186 "Number of Hellos to send each second\n"
8187 "Address of interface\n")
8189 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8190 int idx_ipv4
= argc
- 1;
8191 struct in_addr addr
= {.s_addr
= 0L};
8193 struct ospf_if_params
*params
;
8194 struct ospf_interface
*oi
;
8195 struct route_node
*rn
;
8197 params
= IF_DEF_PARAMS(ifp
);
8199 if (argv
[idx_ipv4
]->type
== IPV4_TKN
) {
8200 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8203 "Please specify interface address by A.B.C.D\n");
8204 return CMD_WARNING_CONFIG_FAILED
;
8207 params
= ospf_lookup_if_params(ifp
, addr
);
8212 UNSET_IF_PARAM(params
, v_wait
);
8213 params
->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
8214 params
->is_v_wait_set
= false;
8216 UNSET_IF_PARAM(params
, fast_hello
);
8217 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
8219 if (params
!= IF_DEF_PARAMS(ifp
)) {
8220 ospf_free_if_params(ifp
, addr
);
8221 ospf_if_update_params(ifp
, addr
);
8224 /* Update timer values in neighbor structure. */
8226 struct ospf
*ospf
= NULL
;
8228 ospf
= ifp
->vrf
->info
;
8230 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
8232 ospf_nbr_timer_update(oi
);
8235 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
8236 if ((oi
= rn
->info
))
8237 ospf_nbr_timer_update(oi
);
8243 DEFUN_HIDDEN (no_ospf_dead_interval
,
8244 no_ospf_dead_interval_cmd
,
8245 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8247 "OSPF interface commands\n"
8248 "Interval time after which a neighbor is declared down\n"
8250 "Minimal 1s dead-interval with fast sub-second hellos\n"
8251 "Hello multiplier factor\n"
8252 "Number of Hellos to send each second\n"
8253 "Address of interface\n")
8255 return no_ip_ospf_dead_interval(self
, vty
, argc
, argv
);
8258 DEFUN (ip_ospf_hello_interval
,
8259 ip_ospf_hello_interval_cmd
,
8260 "ip ospf hello-interval (1-65535) [A.B.C.D]",
8262 "OSPF interface commands\n"
8263 "Time between HELLO packets\n"
8265 "Address of interface\n")
8267 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8269 struct in_addr addr
= {.s_addr
= 0L};
8270 struct ospf_if_params
*params
;
8271 params
= IF_DEF_PARAMS(ifp
);
8272 uint32_t seconds
= 0;
8273 bool is_addr
= false;
8274 uint32_t old_interval
= 0;
8276 argv_find(argv
, argc
, "(1-65535)", &idx
);
8277 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
8279 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8280 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8282 "Please specify interface address by A.B.C.D\n");
8283 return CMD_WARNING_CONFIG_FAILED
;
8286 params
= ospf_get_if_params(ifp
, addr
);
8287 ospf_if_update_params(ifp
, addr
);
8291 old_interval
= params
->v_hello
;
8293 /* Return, if same interval is configured. */
8294 if (old_interval
== seconds
)
8297 SET_IF_PARAM(params
, v_hello
);
8298 params
->v_hello
= seconds
;
8300 if (!params
->is_v_wait_set
) {
8301 SET_IF_PARAM(params
, v_wait
);
8303 * The router dead interval should
8304 * be some multiple of the HelloInterval (perhaps 4 times the
8305 * hello interval) and must be the same for all routers
8306 * attached to a common network.
8308 params
->v_wait
= 4 * seconds
;
8311 ospf_reset_hello_timer(ifp
, addr
, is_addr
);
8316 DEFUN_HIDDEN (ospf_hello_interval
,
8317 ospf_hello_interval_cmd
,
8318 "ospf hello-interval (1-65535) [A.B.C.D]",
8319 "OSPF interface commands\n"
8320 "Time between HELLO packets\n"
8322 "Address of interface\n")
8324 return ip_ospf_hello_interval(self
, vty
, argc
, argv
);
8327 DEFUN (no_ip_ospf_hello_interval
,
8328 no_ip_ospf_hello_interval_cmd
,
8329 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
8332 "OSPF interface commands\n"
8333 "Time between HELLO packets\n" // ignored
8335 "Address of interface\n")
8337 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8339 struct in_addr addr
= {.s_addr
= 0L};
8340 struct ospf_if_params
*params
;
8341 struct route_node
*rn
;
8343 params
= IF_DEF_PARAMS(ifp
);
8345 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8346 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8348 "Please specify interface address by A.B.C.D\n");
8349 return CMD_WARNING_CONFIG_FAILED
;
8352 params
= ospf_lookup_if_params(ifp
, addr
);
8357 UNSET_IF_PARAM(params
, v_hello
);
8358 params
->v_hello
= OSPF_HELLO_INTERVAL_DEFAULT
;
8360 if (!params
->is_v_wait_set
) {
8361 UNSET_IF_PARAM(params
, v_wait
);
8362 params
->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
8365 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8366 struct ospf_interface
*oi
= rn
->info
;
8371 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
8372 oi
->ptp_dmvpn
= IF_DEF_PARAMS(ifp
)->ptp_dmvpn
;
8374 if (oi
->state
> ISM_Down
) {
8375 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
8376 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
8380 if (params
!= IF_DEF_PARAMS(ifp
)) {
8381 ospf_free_if_params(ifp
, addr
);
8382 ospf_if_update_params(ifp
, addr
);
8388 DEFUN_HIDDEN (no_ospf_hello_interval
,
8389 no_ospf_hello_interval_cmd
,
8390 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
8392 "OSPF interface commands\n"
8393 "Time between HELLO packets\n" // ignored
8395 "Address of interface\n")
8397 return no_ip_ospf_hello_interval(self
, vty
, argc
, argv
);
8400 DEFUN(ip_ospf_network
, ip_ospf_network_cmd
,
8401 "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point [dmvpn]>",
8403 "OSPF interface commands\n"
8405 "Specify OSPF broadcast multi-access network\n"
8406 "Specify OSPF NBMA network\n"
8407 "Specify OSPF point-to-multipoint network\n"
8408 "Specify OSPF point-to-point network\n"
8409 "Specify OSPF point-to-point DMVPN network\n")
8411 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8413 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
8414 uint8_t old_ptp_dmvpn
= IF_DEF_PARAMS(ifp
)->ptp_dmvpn
;
8415 struct route_node
*rn
;
8417 if (old_type
== OSPF_IFTYPE_LOOPBACK
) {
8419 "This is a loopback interface. Can't set network type.\n");
8420 return CMD_WARNING_CONFIG_FAILED
;
8423 IF_DEF_PARAMS(ifp
)->ptp_dmvpn
= 0;
8425 if (argv_find(argv
, argc
, "broadcast", &idx
))
8426 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_BROADCAST
;
8427 else if (argv_find(argv
, argc
, "non-broadcast", &idx
))
8428 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_NBMA
;
8429 else if (argv_find(argv
, argc
, "point-to-multipoint", &idx
))
8430 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOMULTIPOINT
;
8431 else if (argv_find(argv
, argc
, "point-to-point", &idx
)) {
8432 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOPOINT
;
8433 if (argv_find(argv
, argc
, "dmvpn", &idx
))
8434 IF_DEF_PARAMS(ifp
)->ptp_dmvpn
= 1;
8437 if (IF_DEF_PARAMS(ifp
)->type
== old_type
8438 && IF_DEF_PARAMS(ifp
)->ptp_dmvpn
== old_ptp_dmvpn
)
8441 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), type
);
8443 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8444 struct ospf_interface
*oi
= rn
->info
;
8449 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
8451 if (oi
->state
> ISM_Down
) {
8452 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
8453 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
8460 DEFUN_HIDDEN (ospf_network
,
8462 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
8463 "OSPF interface commands\n"
8465 "Specify OSPF broadcast multi-access network\n"
8466 "Specify OSPF NBMA network\n"
8467 "Specify OSPF point-to-multipoint network\n"
8468 "Specify OSPF point-to-point network\n")
8470 return ip_ospf_network(self
, vty
, argc
, argv
);
8473 DEFUN (no_ip_ospf_network
,
8474 no_ip_ospf_network_cmd
,
8475 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8478 "OSPF interface commands\n"
8480 "Specify OSPF broadcast multi-access network\n"
8481 "Specify OSPF NBMA network\n"
8482 "Specify OSPF point-to-multipoint network\n"
8483 "Specify OSPF point-to-point network\n")
8485 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8486 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
8487 struct route_node
*rn
;
8489 IF_DEF_PARAMS(ifp
)->type
= ospf_default_iftype(ifp
);
8490 IF_DEF_PARAMS(ifp
)->ptp_dmvpn
= 0;
8492 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
8495 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8496 struct ospf_interface
*oi
= rn
->info
;
8501 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
8503 if (oi
->state
> ISM_Down
) {
8504 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
8505 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
8512 DEFUN_HIDDEN (no_ospf_network
,
8513 no_ospf_network_cmd
,
8514 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8516 "OSPF interface commands\n"
8518 "Specify OSPF broadcast multi-access network\n"
8519 "Specify OSPF NBMA network\n"
8520 "Specify OSPF point-to-multipoint network\n"
8521 "Specify OSPF point-to-point network\n")
8523 return no_ip_ospf_network(self
, vty
, argc
, argv
);
8526 DEFUN (ip_ospf_priority
,
8527 ip_ospf_priority_cmd
,
8528 "ip ospf priority (0-255) [A.B.C.D]",
8530 "OSPF interface commands\n"
8533 "Address of interface\n")
8535 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8538 struct route_node
*rn
;
8539 struct in_addr addr
;
8540 struct ospf_if_params
*params
;
8541 params
= IF_DEF_PARAMS(ifp
);
8543 argv_find(argv
, argc
, "(0-255)", &idx
);
8544 priority
= strtol(argv
[idx
]->arg
, NULL
, 10);
8546 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8547 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8549 "Please specify interface address by A.B.C.D\n");
8550 return CMD_WARNING_CONFIG_FAILED
;
8553 params
= ospf_get_if_params(ifp
, addr
);
8554 ospf_if_update_params(ifp
, addr
);
8557 SET_IF_PARAM(params
, priority
);
8558 params
->priority
= priority
;
8560 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8561 struct ospf_interface
*oi
= rn
->info
;
8566 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
8567 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
8568 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
8575 DEFUN_HIDDEN (ospf_priority
,
8577 "ospf priority (0-255) [A.B.C.D]",
8578 "OSPF interface commands\n"
8581 "Address of interface\n")
8583 return ip_ospf_priority(self
, vty
, argc
, argv
);
8586 DEFUN (no_ip_ospf_priority
,
8587 no_ip_ospf_priority_cmd
,
8588 "no ip ospf priority [(0-255) [A.B.C.D]]",
8591 "OSPF interface commands\n"
8592 "Router priority\n" // ignored
8594 "Address of interface\n")
8596 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8598 struct route_node
*rn
;
8599 struct in_addr addr
;
8600 struct ospf_if_params
*params
;
8602 params
= IF_DEF_PARAMS(ifp
);
8604 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8605 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8607 "Please specify interface address by A.B.C.D\n");
8608 return CMD_WARNING_CONFIG_FAILED
;
8611 params
= ospf_lookup_if_params(ifp
, addr
);
8616 UNSET_IF_PARAM(params
, priority
);
8617 params
->priority
= OSPF_ROUTER_PRIORITY_DEFAULT
;
8619 if (params
!= IF_DEF_PARAMS(ifp
)) {
8620 ospf_free_if_params(ifp
, addr
);
8621 ospf_if_update_params(ifp
, addr
);
8624 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8625 struct ospf_interface
*oi
= rn
->info
;
8630 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
8631 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
8632 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
8639 DEFUN_HIDDEN (no_ospf_priority
,
8640 no_ospf_priority_cmd
,
8641 "no ospf priority [(0-255) [A.B.C.D]]",
8643 "OSPF interface commands\n"
8646 "Address of interface\n")
8648 return no_ip_ospf_priority(self
, vty
, argc
, argv
);
8651 DEFUN (ip_ospf_retransmit_interval
,
8652 ip_ospf_retransmit_interval_addr_cmd
,
8653 "ip ospf retransmit-interval (1-65535) [A.B.C.D]",
8655 "OSPF interface commands\n"
8656 "Time between retransmitting lost link state advertisements\n"
8658 "Address of interface\n")
8660 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8663 struct in_addr addr
;
8664 struct ospf_if_params
*params
;
8665 params
= IF_DEF_PARAMS(ifp
);
8667 argv_find(argv
, argc
, "(1-65535)", &idx
);
8668 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
8670 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8671 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8673 "Please specify interface address by A.B.C.D\n");
8674 return CMD_WARNING_CONFIG_FAILED
;
8677 params
= ospf_get_if_params(ifp
, addr
);
8678 ospf_if_update_params(ifp
, addr
);
8681 SET_IF_PARAM(params
, retransmit_interval
);
8682 params
->retransmit_interval
= seconds
;
8687 DEFUN_HIDDEN (ospf_retransmit_interval
,
8688 ospf_retransmit_interval_cmd
,
8689 "ospf retransmit-interval (1-65535) [A.B.C.D]",
8690 "OSPF interface commands\n"
8691 "Time between retransmitting lost link state advertisements\n"
8693 "Address of interface\n")
8695 return ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
8698 DEFUN (no_ip_ospf_retransmit_interval
,
8699 no_ip_ospf_retransmit_interval_addr_cmd
,
8700 "no ip ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8703 "OSPF interface commands\n"
8704 "Time between retransmitting lost link state advertisements\n"
8706 "Address of interface\n")
8708 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8710 struct in_addr addr
;
8711 struct ospf_if_params
*params
;
8713 params
= IF_DEF_PARAMS(ifp
);
8715 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8716 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8718 "Please specify interface address by A.B.C.D\n");
8719 return CMD_WARNING_CONFIG_FAILED
;
8722 params
= ospf_lookup_if_params(ifp
, addr
);
8727 UNSET_IF_PARAM(params
, retransmit_interval
);
8728 params
->retransmit_interval
= OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
8730 if (params
!= IF_DEF_PARAMS(ifp
)) {
8731 ospf_free_if_params(ifp
, addr
);
8732 ospf_if_update_params(ifp
, addr
);
8738 DEFUN_HIDDEN (no_ospf_retransmit_interval
,
8739 no_ospf_retransmit_interval_cmd
,
8740 "no ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8742 "OSPF interface commands\n"
8743 "Time between retransmitting lost link state advertisements\n"
8745 "Address of interface\n")
8747 return no_ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
8750 DEFUN (ip_ospf_transmit_delay
,
8751 ip_ospf_transmit_delay_addr_cmd
,
8752 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
8754 "OSPF interface commands\n"
8755 "Link state transmit delay\n"
8757 "Address of interface\n")
8759 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8762 struct in_addr addr
;
8763 struct ospf_if_params
*params
;
8765 params
= IF_DEF_PARAMS(ifp
);
8766 argv_find(argv
, argc
, "(1-65535)", &idx
);
8767 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
8769 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8770 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8772 "Please specify interface address by A.B.C.D\n");
8773 return CMD_WARNING_CONFIG_FAILED
;
8776 params
= ospf_get_if_params(ifp
, addr
);
8777 ospf_if_update_params(ifp
, addr
);
8780 SET_IF_PARAM(params
, transmit_delay
);
8781 params
->transmit_delay
= seconds
;
8786 DEFUN_HIDDEN (ospf_transmit_delay
,
8787 ospf_transmit_delay_cmd
,
8788 "ospf transmit-delay (1-65535) [A.B.C.D]",
8789 "OSPF interface commands\n"
8790 "Link state transmit delay\n"
8792 "Address of interface\n")
8794 return ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
8797 DEFUN (no_ip_ospf_transmit_delay
,
8798 no_ip_ospf_transmit_delay_addr_cmd
,
8799 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
8802 "OSPF interface commands\n"
8803 "Link state transmit delay\n"
8805 "Address of interface\n")
8807 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8809 struct in_addr addr
;
8810 struct ospf_if_params
*params
;
8812 params
= IF_DEF_PARAMS(ifp
);
8814 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8815 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8817 "Please specify interface address by A.B.C.D\n");
8818 return CMD_WARNING_CONFIG_FAILED
;
8821 params
= ospf_lookup_if_params(ifp
, addr
);
8826 UNSET_IF_PARAM(params
, transmit_delay
);
8827 params
->transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
8829 if (params
!= IF_DEF_PARAMS(ifp
)) {
8830 ospf_free_if_params(ifp
, addr
);
8831 ospf_if_update_params(ifp
, addr
);
8838 DEFUN_HIDDEN (no_ospf_transmit_delay
,
8839 no_ospf_transmit_delay_cmd
,
8840 "no ospf transmit-delay [(1-65535) [A.B.C.D]]",
8842 "OSPF interface commands\n"
8843 "Link state transmit delay\n"
8845 "Address of interface\n")
8847 return no_ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
8850 DEFUN (ip_ospf_area
,
8852 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]",
8854 "OSPF interface commands\n"
8856 "Enable OSPF on this interface\n"
8857 "OSPF area ID in IP address format\n"
8858 "OSPF area ID as a decimal value\n"
8859 "Address of interface\n")
8861 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8864 struct in_addr area_id
;
8865 struct in_addr addr
;
8866 struct ospf_if_params
*params
= NULL
;
8867 struct route_node
*rn
;
8868 struct ospf
*ospf
= NULL
;
8869 unsigned short instance
= 0;
8873 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
8874 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
8876 argv_find(argv
, argc
, "area", &idx
);
8877 areaid
= argv
[idx
+ 1]->arg
;
8880 ospf
= ifp
->vrf
->info
;
8882 ospf
= ospf_lookup_instance(instance
);
8884 if (instance
&& instance
!= ospf_instance
) {
8886 * At this point we know we have received
8887 * an instance and there is no ospf instance
8888 * associated with it. This means we are
8889 * in a situation where we have an
8890 * ospf command that is setup for a different
8891 * process(instance). We need to safely
8892 * remove the command from ourselves and
8893 * allow the other instance(process) handle
8894 * the configuration command.
8898 params
= IF_DEF_PARAMS(ifp
);
8899 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8900 UNSET_IF_PARAM(params
, if_area
);
8904 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
; rn
= route_next(rn
))
8905 if ((params
= rn
->info
) && OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8906 UNSET_IF_PARAM(params
, if_area
);
8911 ospf
= ifp
->vrf
->info
;
8913 ospf_interface_area_unset(ospf
, ifp
);
8916 return CMD_NOT_MY_INSTANCE
;
8919 ret
= str2area_id(areaid
, &area_id
, &format
);
8921 vty_out(vty
, "Please specify area by A.B.C.D|<0-4294967295>\n");
8922 return CMD_WARNING_CONFIG_FAILED
;
8924 if (memcmp(ifp
->name
, "VLINK", 5) == 0) {
8925 vty_out(vty
, "Cannot enable OSPF on a virtual link.\n");
8926 return CMD_WARNING_CONFIG_FAILED
;
8930 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
)) {
8931 if (rn
->info
!= NULL
) {
8933 "Please remove all network commands first.\n");
8934 return CMD_WARNING_CONFIG_FAILED
;
8939 params
= IF_DEF_PARAMS(ifp
);
8940 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)
8941 && !IPV4_ADDR_SAME(¶ms
->if_area
, &area_id
)) {
8943 "Must remove previous area config before changing ospf area \n");
8944 return CMD_WARNING_CONFIG_FAILED
;
8947 // Check if we have an address arg and proccess it
8948 if (argc
== idx
+ 3) {
8949 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
8951 "Please specify Intf Address by A.B.C.D\n");
8952 return CMD_WARNING_CONFIG_FAILED
;
8954 // update/create address-level params
8955 params
= ospf_get_if_params((ifp
), (addr
));
8956 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8957 if (!IPV4_ADDR_SAME(¶ms
->if_area
, &area_id
)) {
8959 "Must remove previous area/address config before changing ospf area\n");
8960 return CMD_WARNING_CONFIG_FAILED
;
8964 ospf_if_update_params((ifp
), (addr
));
8967 /* enable ospf on this interface with area_id */
8969 SET_IF_PARAM(params
, if_area
);
8970 params
->if_area
= area_id
;
8971 params
->if_area_id_fmt
= format
;
8975 ospf_interface_area_set(ospf
, ifp
);
8980 DEFUN (no_ip_ospf_area
,
8981 no_ip_ospf_area_cmd
,
8982 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]",
8985 "OSPF interface commands\n"
8987 "Disable OSPF on this interface\n"
8988 "OSPF area ID in IP address format\n"
8989 "OSPF area ID as a decimal value\n"
8990 "Address of interface\n")
8992 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8995 struct ospf_if_params
*params
;
8996 unsigned short instance
= 0;
8997 struct in_addr addr
;
8998 struct in_addr area_id
;
9000 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
9001 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
9004 ospf
= ifp
->vrf
->info
;
9006 ospf
= ospf_lookup_instance(instance
);
9008 if (instance
&& instance
!= ospf_instance
)
9009 return CMD_NOT_MY_INSTANCE
;
9011 argv_find(argv
, argc
, "area", &idx
);
9013 // Check if we have an address arg and proccess it
9014 if (argc
== idx
+ 3) {
9015 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
9017 "Please specify Intf Address by A.B.C.D\n");
9018 return CMD_WARNING_CONFIG_FAILED
;
9020 params
= ospf_lookup_if_params(ifp
, addr
);
9021 if ((params
) == NULL
)
9024 params
= IF_DEF_PARAMS(ifp
);
9026 area_id
= params
->if_area
;
9027 if (!OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
9029 "Can't find specified interface area configuration.\n");
9030 return CMD_WARNING_CONFIG_FAILED
;
9033 UNSET_IF_PARAM(params
, if_area
);
9034 if (params
!= IF_DEF_PARAMS((ifp
))) {
9035 ospf_free_if_params((ifp
), (addr
));
9036 ospf_if_update_params((ifp
), (addr
));
9040 ospf_interface_area_unset(ospf
, ifp
);
9041 ospf_area_check_free(ospf
, area_id
);
9047 DEFUN (ip_ospf_passive
,
9048 ip_ospf_passive_cmd
,
9049 "ip ospf passive [A.B.C.D]",
9051 "OSPF interface commands\n"
9052 "Suppress routing updates on an interface\n"
9053 "Address of interface\n")
9055 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9057 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
9058 struct ospf_if_params
*params
;
9062 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9065 "Please specify interface address by A.B.C.D\n");
9066 return CMD_WARNING_CONFIG_FAILED
;
9068 params
= ospf_get_if_params(ifp
, addr
);
9069 ospf_if_update_params(ifp
, addr
);
9071 params
= IF_DEF_PARAMS(ifp
);
9074 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_PASSIVE
);
9079 DEFUN (no_ip_ospf_passive
,
9080 no_ip_ospf_passive_cmd
,
9081 "no ip ospf passive [A.B.C.D]",
9084 "OSPF interface commands\n"
9085 "Enable routing updates on an interface\n"
9086 "Address of interface\n")
9088 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9090 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
9091 struct ospf_if_params
*params
;
9095 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9098 "Please specify interface address by A.B.C.D\n");
9099 return CMD_WARNING_CONFIG_FAILED
;
9101 params
= ospf_lookup_if_params(ifp
, addr
);
9105 params
= IF_DEF_PARAMS(ifp
);
9108 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_ACTIVE
);
9113 DEFUN (ospf_redistribute_source
,
9114 ospf_redistribute_source_cmd
,
9115 "redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9117 FRR_REDIST_HELP_STR_OSPFD
9118 "Metric for redistributed routes\n"
9119 "OSPF default metric\n"
9120 "OSPF exterior metric type for redistributed routes\n"
9121 "Set OSPF External Type 1/2 metrics\n"
9122 "Route map reference\n"
9123 "Pointer to route-map entries\n")
9125 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9126 int idx_protocol
= 1;
9130 struct ospf_redist
*red
;
9132 bool update
= false;
9134 /* Get distribute source. */
9135 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
9137 return CMD_WARNING_CONFIG_FAILED
;
9139 /* Get metric value. */
9140 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
9141 if (!str2metric(argv
[idx
]->arg
, &metric
))
9142 return CMD_WARNING_CONFIG_FAILED
;
9145 /* Get metric type. */
9146 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
9147 if (!str2metric_type(argv
[idx
]->arg
, &type
))
9148 return CMD_WARNING_CONFIG_FAILED
;
9152 red
= ospf_redist_lookup(ospf
, source
, 0);
9154 red
= ospf_redist_add(ospf
, source
, 0);
9159 if (argv_find(argv
, argc
, "route-map", &idx
)) {
9160 ospf_routemap_set(red
, argv
[idx
+ 1]->arg
);
9162 ospf_routemap_unset(red
);
9165 return ospf_redistribute_update(ospf
, red
, source
, 0, type
,
9168 return ospf_redistribute_set(ospf
, red
, source
, 0, type
,
9172 DEFUN (no_ospf_redistribute_source
,
9173 no_ospf_redistribute_source_cmd
,
9174 "no redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9177 FRR_REDIST_HELP_STR_OSPFD
9178 "Metric for redistributed routes\n"
9179 "OSPF default metric\n"
9180 "OSPF exterior metric type for redistributed routes\n"
9181 "Set OSPF External Type 1/2 metrics\n"
9182 "Route map reference\n"
9183 "Pointer to route-map entries\n")
9185 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9186 int idx_protocol
= 2;
9188 struct ospf_redist
*red
;
9190 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
9192 return CMD_WARNING_CONFIG_FAILED
;
9194 red
= ospf_redist_lookup(ospf
, source
, 0);
9198 ospf_routemap_unset(red
);
9199 ospf_redist_del(ospf
, source
, 0);
9201 return ospf_redistribute_unset(ospf
, source
, 0);
9204 DEFUN (ospf_redistribute_instance_source
,
9205 ospf_redistribute_instance_source_cmd
,
9206 "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9208 "Open Shortest Path First\n"
9209 "Non-main Kernel Routing Table\n"
9210 "Instance ID/Table ID\n"
9211 "Metric for redistributed routes\n"
9212 "OSPF default metric\n"
9213 "OSPF exterior metric type for redistributed routes\n"
9214 "Set OSPF External Type 1/2 metrics\n"
9215 "Route map reference\n"
9216 "Pointer to route-map entries\n")
9218 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9219 int idx_ospf_table
= 1;
9225 unsigned short instance
;
9226 struct ospf_redist
*red
;
9227 bool update
= false;
9229 source
= proto_redistnum(AFI_IP
, argv
[idx_ospf_table
]->text
);
9232 vty_out(vty
, "Unknown instance redistribution\n");
9233 return CMD_WARNING_CONFIG_FAILED
;
9236 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9238 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
9240 "Instance redistribution in non-instanced OSPF not allowed\n");
9241 return CMD_WARNING_CONFIG_FAILED
;
9244 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
9245 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
9246 return CMD_WARNING_CONFIG_FAILED
;
9249 /* Get metric value. */
9250 if (argv_find(argv
, argc
, "metric", &idx
))
9251 if (!str2metric(argv
[idx
+ 1]->arg
, &metric
))
9252 return CMD_WARNING_CONFIG_FAILED
;
9255 /* Get metric type. */
9256 if (argv_find(argv
, argc
, "metric-type", &idx
))
9257 if (!str2metric_type(argv
[idx
+ 1]->arg
, &type
))
9258 return CMD_WARNING_CONFIG_FAILED
;
9260 red
= ospf_redist_lookup(ospf
, source
, instance
);
9262 red
= ospf_redist_add(ospf
, source
, instance
);
9267 if (argv_find(argv
, argc
, "route-map", &idx
))
9268 ospf_routemap_set(red
, argv
[idx
+ 1]->arg
);
9270 ospf_routemap_unset(red
);
9273 return ospf_redistribute_update(ospf
, red
, source
, instance
,
9276 return ospf_redistribute_set(ospf
, red
, source
, instance
, type
,
9280 DEFUN (no_ospf_redistribute_instance_source
,
9281 no_ospf_redistribute_instance_source_cmd
,
9282 "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9285 "Open Shortest Path First\n"
9286 "Non-main Kernel Routing Table\n"
9287 "Instance ID/Table Id\n"
9288 "Metric for redistributed routes\n"
9289 "OSPF default metric\n"
9290 "OSPF exterior metric type for redistributed routes\n"
9291 "Set OSPF External Type 1/2 metrics\n"
9292 "Route map reference\n"
9293 "Pointer to route-map entries\n")
9295 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9296 int idx_ospf_table
= 2;
9298 unsigned int instance
;
9299 struct ospf_redist
*red
;
9302 if (strncmp(argv
[idx_ospf_table
]->arg
, "o", 1) == 0)
9303 source
= ZEBRA_ROUTE_OSPF
;
9305 source
= ZEBRA_ROUTE_TABLE
;
9307 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9309 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
9311 "Instance redistribution in non-instanced OSPF not allowed\n");
9312 return CMD_WARNING_CONFIG_FAILED
;
9315 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
9316 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
9317 return CMD_WARNING_CONFIG_FAILED
;
9320 red
= ospf_redist_lookup(ospf
, source
, instance
);
9324 ospf_routemap_unset(red
);
9325 ospf_redist_del(ospf
, source
, instance
);
9327 return ospf_redistribute_unset(ospf
, source
, instance
);
9330 DEFUN (ospf_distribute_list_out
,
9331 ospf_distribute_list_out_cmd
,
9332 "distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD
,
9333 "Filter networks in routing updates\n"
9334 "Access-list name\n"
9336 FRR_REDIST_HELP_STR_OSPFD
)
9338 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9342 char *proto
= argv
[argc
- 1]->text
;
9344 /* Get distribute source. */
9345 source
= proto_redistnum(AFI_IP
, proto
);
9347 return CMD_WARNING_CONFIG_FAILED
;
9349 return ospf_distribute_list_out_set(ospf
, source
, argv
[idx_word
]->arg
);
9352 DEFUN (no_ospf_distribute_list_out
,
9353 no_ospf_distribute_list_out_cmd
,
9354 "no distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD
,
9356 "Filter networks in routing updates\n"
9357 "Access-list name\n"
9359 FRR_REDIST_HELP_STR_OSPFD
)
9361 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9365 char *proto
= argv
[argc
- 1]->text
;
9366 source
= proto_redistnum(AFI_IP
, proto
);
9368 return CMD_WARNING_CONFIG_FAILED
;
9370 return ospf_distribute_list_out_unset(ospf
, source
,
9371 argv
[idx_word
]->arg
);
9374 /* Default information originate. */
9375 DEFUN (ospf_default_information_originate
,
9376 ospf_default_information_originate_cmd
,
9377 "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9378 "Control distribution of default information\n"
9379 "Distribute a default route\n"
9380 "Always advertise default route\n"
9381 "OSPF default metric\n"
9383 "OSPF metric type for default routes\n"
9384 "Set OSPF External Type 1/2 metrics\n"
9385 "Route map reference\n"
9386 "Pointer to route-map entries\n")
9388 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9389 int default_originate
= DEFAULT_ORIGINATE_ZEBRA
;
9392 struct ospf_redist
*red
;
9394 int cur_originate
= ospf
->default_originate
;
9395 bool sameRtmap
= false;
9398 red
= ospf_redist_add(ospf
, DEFAULT_ROUTE
, 0);
9400 /* Check whether "always" was specified */
9401 if (argv_find(argv
, argc
, "always", &idx
))
9402 default_originate
= DEFAULT_ORIGINATE_ALWAYS
;
9404 /* Get metric value */
9405 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
9406 if (!str2metric(argv
[idx
]->arg
, &metric
))
9407 return CMD_WARNING_CONFIG_FAILED
;
9410 /* Get metric type. */
9411 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
9412 if (!str2metric_type(argv
[idx
]->arg
, &type
))
9413 return CMD_WARNING_CONFIG_FAILED
;
9417 if (argv_find(argv
, argc
, "route-map", &idx
))
9418 rtmap
= argv
[idx
+ 1]->arg
;
9420 /* To check if user is providing same route map */
9421 if ((!rtmap
&& !ROUTEMAP_NAME(red
)) ||
9422 (rtmap
&& ROUTEMAP_NAME(red
) &&
9423 (strcmp(rtmap
, ROUTEMAP_NAME(red
)) == 0)))
9426 /* Don't allow if the same lsa is already originated. */
9428 && (red
->dmetric
.type
== type
)
9429 && (red
->dmetric
.value
== metric
)
9430 && (cur_originate
== default_originate
))
9433 /* Updating Metric details */
9434 red
->dmetric
.type
= type
;
9435 red
->dmetric
.value
= metric
;
9437 /* updating route map details */
9439 ospf_routemap_set(red
, rtmap
);
9441 ospf_routemap_unset(red
);
9443 return ospf_redistribute_default_set(ospf
, default_originate
, type
,
9447 DEFUN (no_ospf_default_information_originate
,
9448 no_ospf_default_information_originate_cmd
,
9449 "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9451 "Control distribution of default information\n"
9452 "Distribute a default route\n"
9453 "Always advertise default route\n"
9454 "OSPF default metric\n"
9456 "OSPF metric type for default routes\n"
9457 "Set OSPF External Type 1/2 metrics\n"
9458 "Route map reference\n"
9459 "Pointer to route-map entries\n")
9461 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9462 struct ospf_redist
*red
;
9464 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
9468 ospf_routemap_unset(red
);
9469 ospf_redist_del(ospf
, DEFAULT_ROUTE
, 0);
9471 return ospf_redistribute_default_set(ospf
, DEFAULT_ORIGINATE_NONE
,
9475 DEFUN (ospf_default_metric
,
9476 ospf_default_metric_cmd
,
9477 "default-metric (0-16777214)",
9478 "Set metric of redistributed routes\n"
9481 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9485 if (!str2metric(argv
[idx_number
]->arg
, &metric
))
9486 return CMD_WARNING_CONFIG_FAILED
;
9488 ospf
->default_metric
= metric
;
9493 DEFUN (no_ospf_default_metric
,
9494 no_ospf_default_metric_cmd
,
9495 "no default-metric [(0-16777214)]",
9497 "Set metric of redistributed routes\n"
9500 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9502 ospf
->default_metric
= -1;
9508 DEFUN (ospf_distance
,
9511 "Administrative distance\n"
9512 "OSPF Administrative distance\n")
9514 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9518 distance
= atoi(argv
[idx_number
]->arg
);
9519 if (ospf
->distance_all
!= distance
) {
9520 ospf
->distance_all
= distance
;
9521 ospf_restart_spf(ospf
);
9527 DEFUN (no_ospf_distance
,
9528 no_ospf_distance_cmd
,
9529 "no distance (1-255)",
9531 "Administrative distance\n"
9532 "OSPF Administrative distance\n")
9534 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9536 if (ospf
->distance_all
) {
9537 ospf
->distance_all
= 0;
9538 ospf_restart_spf(ospf
);
9544 DEFUN (no_ospf_distance_ospf
,
9545 no_ospf_distance_ospf_cmd
,
9546 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
9548 "Administrative distance\n"
9549 "OSPF administrative distance\n"
9550 "Intra-area routes\n"
9551 "Distance for intra-area routes\n"
9552 "Inter-area routes\n"
9553 "Distance for inter-area routes\n"
9555 "Distance for external routes\n")
9557 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9560 if (argv_find(argv
, argc
, "intra-area", &idx
) || argc
== 3)
9561 idx
= ospf
->distance_intra
= 0;
9562 if (argv_find(argv
, argc
, "inter-area", &idx
) || argc
== 3)
9563 idx
= ospf
->distance_inter
= 0;
9564 if (argv_find(argv
, argc
, "external", &idx
) || argc
== 3)
9565 ospf
->distance_external
= 0;
9570 DEFUN (ospf_distance_ospf
,
9571 ospf_distance_ospf_cmd
,
9572 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
9573 "Administrative distance\n"
9574 "OSPF administrative distance\n"
9575 "Intra-area routes\n"
9576 "Distance for intra-area routes\n"
9577 "Inter-area routes\n"
9578 "Distance for inter-area routes\n"
9580 "Distance for external routes\n")
9582 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9585 ospf
->distance_intra
= 0;
9586 ospf
->distance_inter
= 0;
9587 ospf
->distance_external
= 0;
9589 if (argv_find(argv
, argc
, "intra-area", &idx
))
9590 ospf
->distance_intra
= atoi(argv
[idx
+ 1]->arg
);
9592 if (argv_find(argv
, argc
, "inter-area", &idx
))
9593 ospf
->distance_inter
= atoi(argv
[idx
+ 1]->arg
);
9595 if (argv_find(argv
, argc
, "external", &idx
))
9596 ospf
->distance_external
= atoi(argv
[idx
+ 1]->arg
);
9601 DEFUN (ip_ospf_mtu_ignore
,
9602 ip_ospf_mtu_ignore_addr_cmd
,
9603 "ip ospf mtu-ignore [A.B.C.D]",
9605 "OSPF interface commands\n"
9606 "Disable MTU mismatch detection on this interface\n"
9607 "Address of interface\n")
9609 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9611 struct in_addr addr
;
9614 struct ospf_if_params
*params
;
9615 params
= IF_DEF_PARAMS(ifp
);
9618 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9621 "Please specify interface address by A.B.C.D\n");
9622 return CMD_WARNING_CONFIG_FAILED
;
9624 params
= ospf_get_if_params(ifp
, addr
);
9625 ospf_if_update_params(ifp
, addr
);
9627 params
->mtu_ignore
= 1;
9628 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
9629 SET_IF_PARAM(params
, mtu_ignore
);
9631 UNSET_IF_PARAM(params
, mtu_ignore
);
9632 if (params
!= IF_DEF_PARAMS(ifp
)) {
9633 ospf_free_if_params(ifp
, addr
);
9634 ospf_if_update_params(ifp
, addr
);
9640 DEFUN (no_ip_ospf_mtu_ignore
,
9641 no_ip_ospf_mtu_ignore_addr_cmd
,
9642 "no ip ospf mtu-ignore [A.B.C.D]",
9645 "OSPF interface commands\n"
9646 "Disable MTU mismatch detection on this interface\n"
9647 "Address of interface\n")
9649 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9651 struct in_addr addr
;
9654 struct ospf_if_params
*params
;
9655 params
= IF_DEF_PARAMS(ifp
);
9658 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9661 "Please specify interface address by A.B.C.D\n");
9662 return CMD_WARNING_CONFIG_FAILED
;
9664 params
= ospf_get_if_params(ifp
, addr
);
9665 ospf_if_update_params(ifp
, addr
);
9667 params
->mtu_ignore
= 0;
9668 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
9669 SET_IF_PARAM(params
, mtu_ignore
);
9671 UNSET_IF_PARAM(params
, mtu_ignore
);
9672 if (params
!= IF_DEF_PARAMS(ifp
)) {
9673 ospf_free_if_params(ifp
, addr
);
9674 ospf_if_update_params(ifp
, addr
);
9681 DEFUN (ospf_max_metric_router_lsa_admin
,
9682 ospf_max_metric_router_lsa_admin_cmd
,
9683 "max-metric router-lsa administrative",
9684 "OSPF maximum / infinite-distance metric\n"
9685 "Advertise own Router-LSA with infinite distance (stub router)\n"
9686 "Administratively applied, for an indefinite period\n")
9688 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9689 struct listnode
*ln
;
9690 struct ospf_area
*area
;
9692 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
9693 SET_FLAG(area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
);
9695 if (!CHECK_FLAG(area
->stub_router_state
,
9696 OSPF_AREA_IS_STUB_ROUTED
))
9697 ospf_router_lsa_update_area(area
);
9700 /* Allows for areas configured later to get the property */
9701 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
;
9706 DEFUN (no_ospf_max_metric_router_lsa_admin
,
9707 no_ospf_max_metric_router_lsa_admin_cmd
,
9708 "no max-metric router-lsa administrative",
9710 "OSPF maximum / infinite-distance metric\n"
9711 "Advertise own Router-LSA with infinite distance (stub router)\n"
9712 "Administratively applied, for an indefinite period\n")
9714 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9715 struct listnode
*ln
;
9716 struct ospf_area
*area
;
9718 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
9719 UNSET_FLAG(area
->stub_router_state
,
9720 OSPF_AREA_ADMIN_STUB_ROUTED
);
9722 /* Don't trample on the start-up stub timer */
9723 if (CHECK_FLAG(area
->stub_router_state
,
9724 OSPF_AREA_IS_STUB_ROUTED
)
9725 && !area
->t_stub_router
) {
9726 UNSET_FLAG(area
->stub_router_state
,
9727 OSPF_AREA_IS_STUB_ROUTED
);
9728 ospf_router_lsa_update_area(area
);
9731 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET
;
9735 DEFUN (ospf_max_metric_router_lsa_startup
,
9736 ospf_max_metric_router_lsa_startup_cmd
,
9737 "max-metric router-lsa on-startup (5-86400)",
9738 "OSPF maximum / infinite-distance metric\n"
9739 "Advertise own Router-LSA with infinite distance (stub router)\n"
9740 "Automatically advertise stub Router-LSA on startup of OSPF\n"
9741 "Time (seconds) to advertise self as stub-router\n")
9743 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9745 unsigned int seconds
;
9748 vty_out(vty
, "%% Must supply stub-router period\n");
9749 return CMD_WARNING_CONFIG_FAILED
;
9752 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9754 ospf
->stub_router_startup_time
= seconds
;
9759 DEFUN (no_ospf_max_metric_router_lsa_startup
,
9760 no_ospf_max_metric_router_lsa_startup_cmd
,
9761 "no max-metric router-lsa on-startup [(5-86400)]",
9763 "OSPF maximum / infinite-distance metric\n"
9764 "Advertise own Router-LSA with infinite distance (stub router)\n"
9765 "Automatically advertise stub Router-LSA on startup of OSPF\n"
9766 "Time (seconds) to advertise self as stub-router\n")
9768 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9769 struct listnode
*ln
;
9770 struct ospf_area
*area
;
9772 ospf
->stub_router_startup_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
9774 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
9775 SET_FLAG(area
->stub_router_state
,
9776 OSPF_AREA_WAS_START_STUB_ROUTED
);
9777 THREAD_OFF(area
->t_stub_router
);
9779 /* Don't trample on admin stub routed */
9780 if (!CHECK_FLAG(area
->stub_router_state
,
9781 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
9782 UNSET_FLAG(area
->stub_router_state
,
9783 OSPF_AREA_IS_STUB_ROUTED
);
9784 ospf_router_lsa_update_area(area
);
9791 DEFUN (ospf_max_metric_router_lsa_shutdown
,
9792 ospf_max_metric_router_lsa_shutdown_cmd
,
9793 "max-metric router-lsa on-shutdown (5-100)",
9794 "OSPF maximum / infinite-distance metric\n"
9795 "Advertise own Router-LSA with infinite distance (stub router)\n"
9796 "Advertise stub-router prior to full shutdown of OSPF\n"
9797 "Time (seconds) to wait till full shutdown\n")
9799 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9801 unsigned int seconds
;
9804 vty_out(vty
, "%% Must supply stub-router shutdown period\n");
9805 return CMD_WARNING_CONFIG_FAILED
;
9808 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9810 ospf
->stub_router_shutdown_time
= seconds
;
9815 DEFUN (no_ospf_max_metric_router_lsa_shutdown
,
9816 no_ospf_max_metric_router_lsa_shutdown_cmd
,
9817 "no max-metric router-lsa on-shutdown [(5-100)]",
9819 "OSPF maximum / infinite-distance metric\n"
9820 "Advertise own Router-LSA with infinite distance (stub router)\n"
9821 "Advertise stub-router prior to full shutdown of OSPF\n"
9822 "Time (seconds) to wait till full shutdown\n")
9824 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9826 ospf
->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
9831 DEFUN (ospf_proactive_arp
,
9832 ospf_proactive_arp_cmd
,
9834 "Allow sending ARP requests proactively\n")
9836 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9838 ospf
->proactive_arp
= true;
9843 DEFUN (no_ospf_proactive_arp
,
9844 no_ospf_proactive_arp_cmd
,
9847 "Disallow sending ARP requests proactively\n")
9849 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9851 ospf
->proactive_arp
= false;
9856 /* Graceful Restart HELPER Commands */
9857 DEFPY(ospf_gr_helper_enable
, ospf_gr_helper_enable_cmd
,
9858 "graceful-restart helper enable [A.B.C.D$address]",
9859 "OSPF Graceful Restart\n"
9861 "Enable Helper support\n"
9862 "Advertising Router-ID\n")
9864 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9867 ospf_gr_helper_support_set_per_routerid(ospf
, &address
,
9872 ospf_gr_helper_support_set(ospf
, OSPF_GR_TRUE
);
9877 DEFPY(no_ospf_gr_helper_enable
,
9878 no_ospf_gr_helper_enable_cmd
,
9879 "no graceful-restart helper enable [A.B.C.D$address]",
9881 "OSPF Graceful Restart\n"
9883 "Enable Helper support\n"
9884 "Advertising Router-ID\n")
9886 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9889 ospf_gr_helper_support_set_per_routerid(ospf
, &address
,
9894 ospf_gr_helper_support_set(ospf
, OSPF_GR_FALSE
);
9898 DEFPY(ospf_gr_helper_enable_lsacheck
,
9899 ospf_gr_helper_enable_lsacheck_cmd
,
9900 "graceful-restart helper strict-lsa-checking",
9901 "OSPF Graceful Restart\n"
9903 "Enable strict LSA check\n")
9905 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9907 ospf_gr_helper_lsa_check_set(ospf
, OSPF_GR_TRUE
);
9911 DEFPY(no_ospf_gr_helper_enable_lsacheck
,
9912 no_ospf_gr_helper_enable_lsacheck_cmd
,
9913 "no graceful-restart helper strict-lsa-checking",
9915 "OSPF Graceful Restart\n"
9917 "Disable strict LSA check\n")
9919 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9921 ospf_gr_helper_lsa_check_set(ospf
, OSPF_GR_FALSE
);
9925 DEFPY(ospf_gr_helper_supported_grace_time
,
9926 ospf_gr_helper_supported_grace_time_cmd
,
9927 "graceful-restart helper supported-grace-time (10-1800)$interval",
9928 "OSPF Graceful Restart\n"
9930 "Supported grace timer\n"
9931 "Grace interval(in seconds)\n")
9933 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9935 ospf_gr_helper_supported_gracetime_set(ospf
, interval
);
9939 DEFPY(no_ospf_gr_helper_supported_grace_time
,
9940 no_ospf_gr_helper_supported_grace_time_cmd
,
9941 "no graceful-restart helper supported-grace-time (10-1800)$interval",
9943 "OSPF Graceful Restart\n"
9945 "Supported grace timer\n"
9946 "Grace interval(in seconds)\n")
9948 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9950 ospf_gr_helper_supported_gracetime_set(ospf
, OSPF_MAX_GRACE_INTERVAL
);
9954 DEFPY(ospf_gr_helper_planned_only
,
9955 ospf_gr_helper_planned_only_cmd
,
9956 "graceful-restart helper planned-only",
9957 "OSPF Graceful Restart\n"
9959 "Supported only planned restart\n")
9961 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9963 ospf_gr_helper_set_supported_planned_only_restart(ospf
, OSPF_GR_TRUE
);
9968 /* External Route Aggregation */
9969 DEFUN (ospf_external_route_aggregation
,
9970 ospf_external_route_aggregation_cmd
,
9971 "summary-address A.B.C.D/M [tag (1-4294967295)]",
9972 "External summary address\n"
9973 "Summary address prefix\n"
9975 "Router tag value\n")
9977 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9978 struct prefix_ipv4 p
;
9980 route_tag_t tag
= 0;
9981 int ret
= OSPF_SUCCESS
;
9983 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
9985 if (is_default_prefix4(&p
)) {
9987 "Default address shouldn't be configured as summary address.\n");
9991 /* Apply mask for given prefix. */
9994 if (!is_valid_summary_addr(&p
)) {
9995 vty_out(vty
, "Not a valid summary address.\n");
9996 return CMD_WARNING_CONFIG_FAILED
;
10000 tag
= strtoul(argv
[idx
+ 2]->arg
, NULL
, 10);
10002 ret
= ospf_asbr_external_aggregator_set(ospf
, &p
, tag
);
10003 if (ret
== OSPF_INVALID
)
10004 vty_out(vty
, "Invalid configuration!!\n");
10006 return CMD_SUCCESS
;
10009 DEFUN (no_ospf_external_route_aggregation
,
10010 no_ospf_external_route_aggregation_cmd
,
10011 "no summary-address A.B.C.D/M [tag (1-4294967295)]",
10013 "External summary address\n"
10014 "Summary address prefix\n"
10016 "Router tag value\n")
10018 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10019 struct prefix_ipv4 p
;
10021 route_tag_t tag
= 0;
10022 int ret
= OSPF_SUCCESS
;
10024 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
10026 if (is_default_prefix4(&p
)) {
10028 "Default address shouldn't be configured as summary address.\n");
10029 return CMD_SUCCESS
;
10032 /* Apply mask for given prefix. */
10035 if (!is_valid_summary_addr(&p
)) {
10036 vty_out(vty
, "Not a valid summary address.\n");
10037 return CMD_WARNING_CONFIG_FAILED
;
10041 tag
= strtoul(argv
[idx
+ 2]->arg
, NULL
, 10);
10043 ret
= ospf_asbr_external_aggregator_unset(ospf
, &p
, tag
);
10044 if (ret
== OSPF_INVALID
)
10045 vty_out(vty
, "Invalid configuration!!\n");
10047 return CMD_SUCCESS
;
10050 DEFPY(no_ospf_gr_helper_planned_only
,
10051 no_ospf_gr_helper_planned_only_cmd
,
10052 "no graceful-restart helper planned-only",
10054 "OSPF Graceful Restart\n"
10056 "Supported only for planned restart\n")
10058 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10060 ospf_gr_helper_set_supported_planned_only_restart(ospf
, OSPF_GR_FALSE
);
10062 return CMD_SUCCESS
;
10065 static int ospf_print_vty_helper_dis_rtr_walkcb(struct hash_bucket
*bucket
,
10068 struct advRtr
*rtr
= bucket
->data
;
10069 struct vty
*vty
= (struct vty
*)arg
;
10070 static unsigned int count
;
10072 vty_out(vty
, "%-6pI4,", &rtr
->advRtrAddr
);
10075 if (count
% 5 == 0)
10076 vty_out(vty
, "\n");
10078 return HASHWALK_CONTINUE
;
10081 static int ospf_print_json_helper_enabled_rtr_walkcb(struct hash_bucket
*bucket
,
10084 struct advRtr
*rtr
= bucket
->data
;
10085 struct json_object
*json_rid_array
= arg
;
10086 struct json_object
*json_rid
;
10088 json_rid
= json_object_new_object();
10090 json_object_string_addf(json_rid
, "routerId", "%pI4", &rtr
->advRtrAddr
);
10091 json_object_array_add(json_rid_array
, json_rid
);
10093 return HASHWALK_CONTINUE
;
10096 static int ospf_show_gr_helper_details(struct vty
*vty
, struct ospf
*ospf
,
10097 uint8_t use_vrf
, json_object
*json
,
10098 bool uj
, bool detail
)
10100 struct listnode
*node
;
10101 struct ospf_interface
*oi
;
10102 char buf
[PREFIX_STRLEN
];
10103 json_object
*json_vrf
= NULL
;
10107 json_vrf
= json_object_new_object();
10112 if (ospf
->instance
) {
10114 json_object_int_add(json
, "ospfInstance",
10117 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
10120 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
10124 json_object_object_add(json
, ospf_get_name(ospf
),
10127 vty_out(vty
, "\n");
10129 /* Show Router ID. */
10131 json_object_string_add(json_vrf
, "routerId",
10132 inet_ntop(AF_INET
, &ospf
->router_id
,
10133 buf
, sizeof(buf
)));
10135 vty_out(vty
, "\n OSPF Router with ID (%pI4)\n\n",
10141 if (ospf
->is_helper_supported
)
10143 " Graceful restart helper support enabled.\n");
10146 " Graceful restart helper support disabled.\n");
10148 if (ospf
->strict_lsa_check
)
10149 vty_out(vty
, " Strict LSA check is enabled.\n");
10151 vty_out(vty
, " Strict LSA check is disabled.\n");
10153 if (ospf
->only_planned_restart
)
10155 " Helper supported for planned restarts only.\n");
10158 " Helper supported for Planned and Unplanned Restarts.\n");
10161 " Supported Graceful restart interval: %d(in seconds).\n",
10162 ospf
->supported_grace_time
);
10164 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf
)) {
10165 vty_out(vty
, " Enable Router list:\n");
10167 hash_walk(ospf
->enable_rtr_list
,
10168 ospf_print_vty_helper_dis_rtr_walkcb
, vty
);
10169 vty_out(vty
, "\n\n");
10172 if (ospf
->last_exit_reason
!= OSPF_GR_HELPER_EXIT_NONE
) {
10173 vty_out(vty
, " Last Helper exit Reason :%s\n",
10174 ospf_exit_reason2str(ospf
->last_exit_reason
));
10177 if (ospf
->active_restarter_cnt
)
10179 " Number of Active neighbours in graceful restart: %d\n",
10180 ospf
->active_restarter_cnt
);
10182 vty_out(vty
, "\n");
10185 json_object_string_add(
10186 json_vrf
, "helperSupport",
10187 (ospf
->is_helper_supported
) ? "Enabled" : "Disabled");
10188 json_object_string_add(json_vrf
, "strictLsaCheck",
10189 (ospf
->strict_lsa_check
) ? "Enabled"
10191 json_object_string_add(
10192 json_vrf
, "restartSupoort",
10193 (ospf
->only_planned_restart
)
10194 ? "Planned Restart only"
10195 : "Planned and Unplanned Restarts");
10197 json_object_int_add(json_vrf
, "supportedGracePeriod",
10198 ospf
->supported_grace_time
);
10200 #if CONFDATE > 20230131
10201 CPP_NOTICE("Remove JSON object commands with keys starting with capital")
10203 if (ospf
->last_exit_reason
!= OSPF_GR_HELPER_EXIT_NONE
) {
10204 json_object_string_add(
10205 json_vrf
, "LastExitReason",
10206 ospf_exit_reason2str(ospf
->last_exit_reason
));
10207 json_object_string_add(
10208 json_vrf
, "lastExitReason",
10209 ospf_exit_reason2str(ospf
->last_exit_reason
));
10212 if (ospf
->active_restarter_cnt
)
10213 json_object_int_add(json_vrf
, "activeRestarterCnt",
10214 ospf
->active_restarter_cnt
);
10216 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf
)) {
10217 struct json_object
*json_rid_array
=
10218 json_object_new_array();
10220 json_object_object_add(json_vrf
, "enabledRouterIds",
10223 hash_walk(ospf
->enable_rtr_list
,
10224 ospf_print_json_helper_enabled_rtr_walkcb
,
10232 json_object
*json_neighbors
= NULL
;
10234 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
10235 struct route_node
*rn
;
10236 struct ospf_neighbor
*nbr
;
10237 json_object
*json_neigh
;
10239 if (ospf_interface_neighbor_count(oi
) == 0)
10243 json_object_object_get_ex(json_vrf
, "Neighbors",
10245 json_object_object_get_ex(json_vrf
, "neighbors",
10247 if (!json_neighbors
) {
10249 json_object_new_object();
10250 json_object_object_add(json_vrf
,
10253 json_object_object_add(json_vrf
,
10259 for (rn
= route_top(oi
->nbrs
); rn
;
10260 rn
= route_next(rn
)) {
10267 if (!OSPF_GR_IS_ACTIVE_HELPER(nbr
))
10271 vty_out(vty
, " Neighbour %d :\n", cnt
);
10272 vty_out(vty
, " Address : %pI4\n",
10273 &nbr
->address
.u
.prefix4
);
10274 vty_out(vty
, " Routerid : %pI4\n",
10277 " Received Grace period : %d(in seconds).\n",
10278 nbr
->gr_helper_info
10279 .recvd_grace_period
);
10281 " Actual Grace period : %d(in seconds)\n",
10282 nbr
->gr_helper_info
10283 .actual_grace_period
);
10285 " Remaining GraceTime:%ld(in seconds).\n",
10286 thread_timer_remain_second(
10287 nbr
->gr_helper_info
10290 " Graceful Restart reason: %s.\n\n",
10291 ospf_restart_reason2str(
10292 nbr
->gr_helper_info
10293 .gr_restart_reason
));
10296 json_neigh
= json_object_new_object();
10297 json_object_string_add(
10298 json_neigh
, "srcAddr",
10299 inet_ntop(AF_INET
, &nbr
->src
,
10300 buf
, sizeof(buf
)));
10302 json_object_string_add(
10303 json_neigh
, "routerid",
10306 buf
, sizeof(buf
)));
10307 json_object_int_add(
10309 "recvdGraceInterval",
10310 nbr
->gr_helper_info
10311 .recvd_grace_period
);
10312 json_object_int_add(
10314 "actualGraceInterval",
10315 nbr
->gr_helper_info
10316 .actual_grace_period
);
10317 json_object_int_add(
10318 json_neigh
, "remainGracetime",
10319 thread_timer_remain_second(
10320 nbr
->gr_helper_info
10322 json_object_string_add(
10323 json_neigh
, "restartReason",
10324 ospf_restart_reason2str(
10325 nbr
->gr_helper_info
10326 .gr_restart_reason
));
10327 json_object_object_add(
10329 inet_ntop(AF_INET
, &nbr
->src
,
10336 return CMD_SUCCESS
;
10339 DEFUN (ospf_external_route_aggregation_no_adrvertise
,
10340 ospf_external_route_aggregation_no_adrvertise_cmd
,
10341 "summary-address A.B.C.D/M no-advertise",
10342 "External summary address\n"
10343 "Summary address prefix\n"
10344 "Don't advertise summary route \n")
10346 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10347 struct prefix_ipv4 p
;
10349 int ret
= OSPF_SUCCESS
;
10351 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
10353 if (is_default_prefix4(&p
)) {
10355 "Default address shouldn't be configured as summary address.\n");
10356 return CMD_SUCCESS
;
10359 /* Apply mask for given prefix. */
10362 if (!is_valid_summary_addr(&p
)) {
10363 vty_out(vty
, "Not a valid summary address.\n");
10364 return CMD_WARNING_CONFIG_FAILED
;
10367 ret
= ospf_asbr_external_rt_no_advertise(ospf
, &p
);
10368 if (ret
== OSPF_INVALID
)
10369 vty_out(vty
, "Invalid configuration!!\n");
10371 return CMD_SUCCESS
;
10374 DEFUN (no_ospf_external_route_aggregation_no_adrvertise
,
10375 no_ospf_external_route_aggregation_no_adrvertise_cmd
,
10376 "no summary-address A.B.C.D/M no-advertise",
10378 "External summary address\n"
10379 "Summary address prefix\n"
10380 "Advertise summary route to the AS \n")
10382 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10383 struct prefix_ipv4 p
;
10385 int ret
= OSPF_SUCCESS
;
10387 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
10389 if (is_default_prefix4(&p
)) {
10391 "Default address shouldn't be configured as summary address.\n");
10392 return CMD_SUCCESS
;
10395 /* Apply mask for given prefix. */
10398 if (!is_valid_summary_addr(&p
)) {
10399 vty_out(vty
, "Not a valid summary address.\n");
10400 return CMD_WARNING_CONFIG_FAILED
;
10403 ret
= ospf_asbr_external_rt_advertise(ospf
, &p
);
10404 if (ret
== OSPF_INVALID
)
10405 vty_out(vty
, "Invalid configuration!!\n");
10407 return CMD_SUCCESS
;
10410 DEFUN (ospf_route_aggregation_timer
,
10411 ospf_route_aggregation_timer_cmd
,
10412 "aggregation timer (5-1800)",
10413 "External route aggregation\n"
10414 "Delay timer (in seconds)\n"
10415 "Timer interval(in seconds)\n")
10417 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10418 uint16_t interval
= 0;
10420 interval
= strtoul(argv
[2]->arg
, NULL
, 10);
10422 ospf_external_aggregator_timer_set(ospf
, interval
);
10424 return CMD_SUCCESS
;
10427 DEFPY (show_ip_ospf_gr_helper
,
10428 show_ip_ospf_gr_helper_cmd
,
10429 "show ip ospf [vrf <NAME|all>] graceful-restart helper [detail] [json]",
10432 "OSPF information\n"
10435 "OSPF Graceful Restart\n"
10436 "Helper details in the router\n"
10437 "Detailed information\n"
10440 char *vrf_name
= NULL
;
10441 bool all_vrf
= false;
10442 int ret
= CMD_SUCCESS
;
10445 uint8_t use_vrf
= 0;
10446 bool uj
= use_json(argc
, argv
);
10447 struct ospf
*ospf
= NULL
;
10448 json_object
*json
= NULL
;
10449 struct listnode
*node
= NULL
;
10451 bool detail
= false;
10453 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
10455 if (argv_find(argv
, argc
, "detail", &idx
))
10459 json
= json_object_new_object();
10461 /* vrf input is provided */
10466 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
10467 if (!ospf
->oi_running
)
10470 ret
= ospf_show_gr_helper_details(
10471 vty
, ospf
, use_vrf
, json
, uj
, detail
);
10475 vty_json(vty
, json
);
10480 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
10482 if (ospf
== NULL
|| !ospf
->oi_running
) {
10485 vty_json(vty
, json
);
10488 "%% OSPF is not enabled in vrf %s\n",
10491 return CMD_SUCCESS
;
10496 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
10498 if (ospf
== NULL
|| !ospf
->oi_running
) {
10501 vty_json(vty
, json
);
10504 "%% OSPF is not enabled in vrf default\n");
10506 return CMD_SUCCESS
;
10509 ospf_show_gr_helper_details(vty
, ospf
, use_vrf
, json
, uj
,
10514 vty_json(vty
, json
);
10516 return CMD_SUCCESS
;
10518 /* Graceful Restart HELPER commands end */
10519 DEFUN (no_ospf_route_aggregation_timer
,
10520 no_ospf_route_aggregation_timer_cmd
,
10521 "no aggregation timer",
10523 "External route aggregation\n"
10526 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10528 ospf_external_aggregator_timer_set(ospf
, OSPF_EXTL_AGGR_DEFAULT_DELAY
);
10530 return CMD_SUCCESS
;
10533 /* External Route Aggregation End */
10535 static void config_write_stub_router(struct vty
*vty
, struct ospf
*ospf
)
10537 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
10538 vty_out(vty
, " max-metric router-lsa on-startup %u\n",
10539 ospf
->stub_router_startup_time
);
10540 if (ospf
->stub_router_shutdown_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
10541 vty_out(vty
, " max-metric router-lsa on-shutdown %u\n",
10542 ospf
->stub_router_shutdown_time
);
10543 if (ospf
->stub_router_admin_set
== OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
)
10544 vty_out(vty
, " max-metric router-lsa administrative\n");
10549 #if CONFDATE > 20230131
10550 CPP_NOTICE("Remove JSON object commands with keys containing whitespaces")
10552 static void show_ip_ospf_route_network(struct vty
*vty
, struct ospf
*ospf
,
10553 struct route_table
*rt
,
10556 struct route_node
*rn
;
10557 struct ospf_route
* or ;
10558 struct listnode
*pnode
, *pnnode
;
10559 struct ospf_path
*path
;
10560 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
10561 *json_nexthop
= NULL
;
10565 "============ OSPF network routing table ============\n");
10567 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
10568 char buf1
[PREFIX2STR_BUFFER
];
10570 if ((or = rn
->info
) == NULL
)
10573 prefix2str(&rn
->p
, buf1
, sizeof(buf1
));
10576 json_route
= json_object_new_object();
10577 json_object_object_add(json
, buf1
, json_route
);
10580 switch (or->path_type
) {
10581 case OSPF_PATH_INTER_AREA
:
10582 if (or->type
== OSPF_DESTINATION_NETWORK
) {
10584 json_object_string_add(json_route
,
10587 json_object_int_add(json_route
, "cost",
10589 json_object_string_addf(
10590 json_route
, "area", "%pI4",
10591 &or->u
.std
.area_id
);
10594 "N IA %-18s [%d] area: %pI4\n",
10596 &or->u
.std
.area_id
);
10598 } else if (or->type
== OSPF_DESTINATION_DISCARD
) {
10600 json_object_string_add(json_route
,
10605 "D IA %-18s Discard entry\n",
10610 case OSPF_PATH_INTRA_AREA
:
10612 json_object_string_add(json_route
, "routeType",
10614 json_object_int_add(json_route
, "cost",
10616 json_object_string_addf(json_route
, "area",
10618 &or->u
.std
.area_id
);
10620 vty_out(vty
, "N %-18s [%d] area: %pI4\n",
10622 &or->u
.std
.area_id
);
10629 if (or->type
== OSPF_DESTINATION_NETWORK
) {
10631 json_nexthop_array
= json_object_new_array();
10632 json_object_object_add(json_route
, "nexthops",
10633 json_nexthop_array
);
10636 for (ALL_LIST_ELEMENTS(or->paths
, pnode
, pnnode
,
10639 json_nexthop
= json_object_new_object();
10640 json_object_array_add(
10641 json_nexthop_array
,
10644 if (if_lookup_by_index(path
->ifindex
,
10647 if (path
->nexthop
.s_addr
10650 json_object_string_add(
10653 json_object_string_add(
10655 "directly attached to",
10659 json_object_string_add(
10661 "directlyAttachedTo",
10667 "%24s directly attached to %s\n",
10675 json_object_string_addf(
10679 json_object_string_add(
10687 "%24s via %pI4, %s\n",
10700 vty_out(vty
, "\n");
10703 static void show_ip_ospf_route_router(struct vty
*vty
, struct ospf
*ospf
,
10704 struct route_table
*rtrs
,
10707 struct route_node
*rn
;
10708 struct ospf_route
* or ;
10709 struct listnode
*pnode
;
10710 struct listnode
*node
;
10711 struct ospf_path
*path
;
10712 char buf
[PREFIX_STRLEN
];
10713 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
10714 *json_nexthop
= NULL
;
10717 vty_out(vty
, "============ OSPF %s table =============\n",
10718 ospf
->all_rtrs
== rtrs
? "reachable routers"
10719 : "router routing");
10721 for (rn
= route_top(rtrs
); rn
; rn
= route_next(rn
)) {
10722 if (rn
->info
== NULL
)
10727 json_route
= json_object_new_object();
10728 json_object_object_add(
10729 json
, inet_ntop(AF_INET
, &rn
->p
.u
.prefix4
,
10732 json_object_string_add(json_route
, "routeType", "R ");
10734 vty_out(vty
, "R %-15pI4 ",
10738 for (ALL_LIST_ELEMENTS_RO((struct list
*)rn
->info
, node
, or)) {
10741 vty_out(vty
, "%24s", "");
10746 json_object_int_add(json_route
, "cost",
10748 json_object_string_addf(json_route
, "area",
10750 &or->u
.std
.area_id
);
10751 if (or->path_type
== OSPF_PATH_INTER_AREA
) {
10752 json_object_boolean_true_add(json_route
,
10754 json_object_boolean_true_add(json_route
,
10757 if (or->u
.std
.flags
& ROUTER_LSA_BORDER
)
10758 json_object_string_add(json_route
,
10761 else if (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
)
10762 json_object_string_add(json_route
,
10766 vty_out(vty
, "%s [%d] area: %pI4",
10767 (or->path_type
== OSPF_PATH_INTER_AREA
10770 or->cost
, &or->u
.std
.area_id
);
10772 vty_out(vty
, "%s%s\n",
10773 (or->u
.std
.flags
& ROUTER_LSA_BORDER
10776 (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
10782 json_nexthop_array
= json_object_new_array();
10783 json_object_object_add(json_route
, "nexthops",
10784 json_nexthop_array
);
10787 for (ALL_LIST_ELEMENTS_RO(or->paths
, pnode
, path
)) {
10789 json_nexthop
= json_object_new_object();
10790 json_object_array_add(
10791 json_nexthop_array
,
10794 if (if_lookup_by_index(path
->ifindex
,
10796 if (path
->nexthop
.s_addr
10799 json_object_string_add(
10802 json_object_string_add(
10804 "directly attached to",
10808 json_object_string_add(
10810 "directlyAttachedTo",
10816 "%24s directly attached to %s\n",
10824 json_object_string_addf(
10828 json_object_string_add(
10836 "%24s via %pI4, %s\n",
10849 vty_out(vty
, "\n");
10852 static void show_ip_ospf_route_external(struct vty
*vty
, struct ospf
*ospf
,
10853 struct route_table
*rt
,
10856 struct route_node
*rn
;
10857 struct ospf_route
*er
;
10858 struct listnode
*pnode
, *pnnode
;
10859 struct ospf_path
*path
;
10860 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
10861 *json_nexthop
= NULL
;
10865 "============ OSPF external routing table ===========\n");
10867 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
10868 if ((er
= rn
->info
) == NULL
)
10873 snprintfrr(buf1
, sizeof(buf1
), "%pFX", &rn
->p
);
10875 json_route
= json_object_new_object();
10876 json_object_object_add(json
, buf1
, json_route
);
10879 switch (er
->path_type
) {
10880 case OSPF_PATH_TYPE1_EXTERNAL
:
10882 json_object_string_add(json_route
, "routeType",
10884 json_object_int_add(json_route
, "cost",
10886 json_object_int_add(json_route
, "tag",
10890 "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI
10892 buf1
, er
->cost
, er
->u
.ext
.tag
);
10895 case OSPF_PATH_TYPE2_EXTERNAL
:
10897 json_object_string_add(json_route
, "routeType",
10899 json_object_int_add(json_route
, "cost",
10901 json_object_int_add(json_route
, "type2cost",
10902 er
->u
.ext
.type2_cost
);
10903 json_object_int_add(json_route
, "tag",
10907 "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI
10909 buf1
, er
->cost
, er
->u
.ext
.type2_cost
,
10916 json_nexthop_array
= json_object_new_array();
10917 json_object_object_add(json_route
, "nexthops",
10918 json_nexthop_array
);
10921 for (ALL_LIST_ELEMENTS(er
->paths
, pnode
, pnnode
, path
)) {
10923 json_nexthop
= json_object_new_object();
10924 json_object_array_add(json_nexthop_array
,
10928 if (if_lookup_by_index(path
->ifindex
, ospf
->vrf_id
)) {
10929 if (path
->nexthop
.s_addr
== INADDR_ANY
) {
10931 json_object_string_add(
10932 json_nexthop
, "ip",
10934 json_object_string_add(
10936 "directly attached to",
10940 json_object_string_add(
10942 "directlyAttachedTo",
10948 "%24s directly attached to %s\n",
10956 json_object_string_addf(
10957 json_nexthop
, "ip",
10958 "%pI4", &path
->nexthop
);
10959 json_object_string_add(
10960 json_nexthop
, "via",
10966 "%24s via %pI4, %s\n",
10978 vty_out(vty
, "\n");
10981 static int show_ip_ospf_reachable_routers_common(struct vty
*vty
,
10985 if (ospf
->instance
)
10986 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
10988 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
10990 if (ospf
->all_rtrs
== NULL
) {
10991 vty_out(vty
, "No OSPF reachable router information exist\n");
10992 return CMD_SUCCESS
;
10995 /* Show Router routes. */
10996 show_ip_ospf_route_router(vty
, ospf
, ospf
->all_rtrs
, NULL
);
10998 vty_out(vty
, "\n");
11000 return CMD_SUCCESS
;
11003 DEFUN (show_ip_ospf_reachable_routers
,
11004 show_ip_ospf_reachable_routers_cmd
,
11005 "show ip ospf [vrf <NAME|all>] reachable-routers",
11008 "OSPF information\n"
11011 "Show all the reachable OSPF routers\n")
11013 struct ospf
*ospf
= NULL
;
11014 struct listnode
*node
= NULL
;
11015 char *vrf_name
= NULL
;
11016 bool all_vrf
= false;
11017 int ret
= CMD_SUCCESS
;
11020 uint8_t use_vrf
= 0;
11022 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11025 bool ospf_output
= false;
11030 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11031 if (!ospf
->oi_running
)
11034 ospf_output
= true;
11035 ret
= show_ip_ospf_reachable_routers_common(
11036 vty
, ospf
, use_vrf
);
11040 vty_out(vty
, "%% OSPF instance not found\n");
11042 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11043 if (ospf
== NULL
|| !ospf
->oi_running
) {
11044 vty_out(vty
, "%% OSPF instance not found\n");
11045 return CMD_SUCCESS
;
11048 ret
= show_ip_ospf_reachable_routers_common(vty
, ospf
,
11052 /* Display default ospf (instance 0) info */
11053 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11054 if (ospf
== NULL
|| !ospf
->oi_running
) {
11055 vty_out(vty
, "%% OSPF instance not found\n");
11056 return CMD_SUCCESS
;
11059 ret
= show_ip_ospf_reachable_routers_common(vty
, ospf
, use_vrf
);
11065 DEFUN (show_ip_ospf_instance_reachable_routers
,
11066 show_ip_ospf_instance_reachable_routers_cmd
,
11067 "show ip ospf (1-65535) reachable-routers",
11070 "OSPF information\n"
11072 "Show all the reachable OSPF routers\n")
11074 int idx_number
= 3;
11076 unsigned short instance
= 0;
11078 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
11079 if (instance
!= ospf_instance
)
11080 return CMD_NOT_MY_INSTANCE
;
11082 ospf
= ospf_lookup_instance(instance
);
11083 if (!ospf
|| !ospf
->oi_running
)
11084 return CMD_SUCCESS
;
11086 return show_ip_ospf_reachable_routers_common(vty
, ospf
, 0);
11089 static int show_ip_ospf_border_routers_common(struct vty
*vty
,
11094 json_object
*json_vrf
= NULL
;
11095 json_object
*json_router
= NULL
;
11099 json_vrf
= json_object_new_object();
11102 json_router
= json_object_new_object();
11105 if (ospf
->instance
) {
11107 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
11109 json_object_int_add(json_vrf
, "ospfInstance",
11113 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
11115 if (ospf
->new_table
== NULL
) {
11117 vty_out(vty
, "No OSPF routing information exist\n");
11119 json_object_free(json_router
);
11120 json_object_free(json_vrf
);
11122 return CMD_SUCCESS
;
11125 /* Show Network routes.
11126 show_ip_ospf_route_network (vty, ospf->new_table); */
11128 /* Show Router routes. */
11129 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, json_router
);
11132 json_object_object_add(json_vrf
, "routers", json_router
);
11134 if (ospf
->vrf_id
== VRF_DEFAULT
)
11135 json_object_object_add(json
, "default",
11138 json_object_object_add(json
, ospf
->name
,
11142 vty_out(vty
, "\n");
11145 return CMD_SUCCESS
;
11148 DEFPY (show_ip_ospf_border_routers
,
11149 show_ip_ospf_border_routers_cmd
,
11150 "show ip ospf [vrf <NAME|all>] border-routers [json]",
11153 "OSPF information\n"
11156 "Show all the ABR's and ASBR's\n"
11159 struct ospf
*ospf
= NULL
;
11160 struct listnode
*node
= NULL
;
11161 char *vrf_name
= NULL
;
11162 bool all_vrf
= false;
11163 int ret
= CMD_SUCCESS
;
11166 uint8_t use_vrf
= 0;
11167 bool uj
= use_json(argc
, argv
);
11168 json_object
*json
= NULL
;
11171 json
= json_object_new_object();
11173 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11176 bool ospf_output
= false;
11181 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11182 if (!ospf
->oi_running
)
11185 ospf_output
= true;
11186 ret
= show_ip_ospf_border_routers_common(
11187 vty
, ospf
, use_vrf
, json
);
11191 vty_json(vty
, json
);
11192 else if (!ospf_output
)
11193 vty_out(vty
, "%% OSPF is not enabled\n");
11197 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11198 if (ospf
== NULL
|| !ospf
->oi_running
) {
11200 vty_json(vty
, json
);
11203 "%% OSPF is not enabled in vrf %s\n",
11206 return CMD_SUCCESS
;
11210 /* Display default ospf (instance 0) info */
11211 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11212 if (ospf
== NULL
|| !ospf
->oi_running
) {
11214 vty_json(vty
, json
);
11217 "%% OSPF is not enabled in vrf default\n");
11219 return CMD_SUCCESS
;
11224 ret
= show_ip_ospf_border_routers_common(vty
, ospf
, use_vrf
,
11227 vty_json(vty
, json
);
11233 DEFUN (show_ip_ospf_instance_border_routers
,
11234 show_ip_ospf_instance_border_routers_cmd
,
11235 "show ip ospf (1-65535) border-routers",
11238 "OSPF information\n"
11240 "Show all the ABR's and ASBR's\n")
11242 int idx_number
= 3;
11244 unsigned short instance
= 0;
11246 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
11247 if (instance
!= ospf_instance
)
11248 return CMD_NOT_MY_INSTANCE
;
11250 ospf
= ospf_lookup_instance(instance
);
11251 if (!ospf
|| !ospf
->oi_running
)
11252 return CMD_SUCCESS
;
11254 return show_ip_ospf_border_routers_common(vty
, ospf
, 0, NULL
);
11257 static int show_ip_ospf_route_common(struct vty
*vty
, struct ospf
*ospf
,
11258 json_object
*json
, uint8_t use_vrf
)
11260 json_object
*json_vrf
= NULL
;
11262 if (ospf
->instance
)
11263 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
11268 json_vrf
= json_object_new_object();
11273 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
11275 if (ospf
->new_table
== NULL
) {
11276 vty_out(vty
, "No OSPF routing information exist\n");
11277 return CMD_SUCCESS
;
11280 /* Show Network routes. */
11281 show_ip_ospf_route_network(vty
, ospf
, ospf
->new_table
, json_vrf
);
11283 /* Show Router routes. */
11284 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, json_vrf
);
11286 /* Show Router routes. */
11287 if (ospf
->all_rtrs
)
11288 show_ip_ospf_route_router(vty
, ospf
, ospf
->all_rtrs
, json_vrf
);
11290 /* Show AS External routes. */
11291 show_ip_ospf_route_external(vty
, ospf
, ospf
->old_external_route
,
11296 // json_object_object_add(json_vrf, "areas",
11298 json_object_object_add(json
, ospf_get_name(ospf
),
11302 vty_out(vty
, "\n");
11305 return CMD_SUCCESS
;
11308 DEFUN (show_ip_ospf_route
,
11309 show_ip_ospf_route_cmd
,
11310 "show ip ospf [vrf <NAME|all>] route [json]",
11313 "OSPF information\n"
11316 "OSPF routing table\n"
11319 struct ospf
*ospf
= NULL
;
11320 struct listnode
*node
= NULL
;
11321 char *vrf_name
= NULL
;
11322 bool all_vrf
= false;
11323 int ret
= CMD_SUCCESS
;
11326 uint8_t use_vrf
= 0;
11327 bool uj
= use_json(argc
, argv
);
11328 json_object
*json
= NULL
;
11331 json
= json_object_new_object();
11333 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11335 /* vrf input is provided could be all or specific vrf*/
11337 bool ospf_output
= false;
11342 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11343 if (!ospf
->oi_running
)
11345 ospf_output
= true;
11346 ret
= show_ip_ospf_route_common(vty
, ospf
, json
,
11351 /* Keep Non-pretty format */
11352 vty_json(vty
, json
);
11353 } else if (!ospf_output
)
11354 vty_out(vty
, "%% OSPF is not enabled\n");
11358 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11359 if (ospf
== NULL
|| !ospf
->oi_running
) {
11361 vty_json(vty
, json
);
11364 "%% OSPF is not enabled in vrf %s\n",
11367 return CMD_SUCCESS
;
11370 /* Display default ospf (instance 0) info */
11371 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11372 if (ospf
== NULL
|| !ospf
->oi_running
) {
11374 vty_json(vty
, json
);
11377 "%% OSPF is not enabled in vrf default\n");
11379 return CMD_SUCCESS
;
11384 ret
= show_ip_ospf_route_common(vty
, ospf
, json
, use_vrf
);
11385 /* Keep Non-pretty format */
11387 vty_out(vty
, "%s\n",
11388 json_object_to_json_string_ext(
11389 json
, JSON_C_TO_STRING_NOSLASHESCAPE
));
11393 json_object_free(json
);
11398 DEFUN (show_ip_ospf_instance_route
,
11399 show_ip_ospf_instance_route_cmd
,
11400 "show ip ospf (1-65535) route",
11403 "OSPF information\n"
11405 "OSPF routing table\n")
11407 int idx_number
= 3;
11409 unsigned short instance
= 0;
11411 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
11412 if (instance
!= ospf_instance
)
11413 return CMD_NOT_MY_INSTANCE
;
11415 ospf
= ospf_lookup_instance(instance
);
11416 if (!ospf
|| !ospf
->oi_running
)
11417 return CMD_SUCCESS
;
11419 return show_ip_ospf_route_common(vty
, ospf
, NULL
, 0);
11423 DEFUN (show_ip_ospf_vrfs
,
11424 show_ip_ospf_vrfs_cmd
,
11425 "show ip ospf vrfs [json]",
11428 "OSPF information\n"
11429 "Show OSPF VRFs \n"
11432 bool uj
= use_json(argc
, argv
);
11433 json_object
*json
= NULL
;
11434 json_object
*json_vrfs
= NULL
;
11435 struct ospf
*ospf
= NULL
;
11436 struct listnode
*node
= NULL
;
11438 static const char header
[] = "Name Id RouterId ";
11441 json
= json_object_new_object();
11442 json_vrfs
= json_object_new_object();
11445 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11446 json_object
*json_vrf
= NULL
;
11447 const char *name
= NULL
;
11448 int64_t vrf_id_ui
= 0;
11452 if (!uj
&& count
== 1)
11453 vty_out(vty
, "%s\n", header
);
11455 json_vrf
= json_object_new_object();
11457 name
= ospf_get_name(ospf
);
11459 vrf_id_ui
= (ospf
->vrf_id
== VRF_UNKNOWN
)
11461 : (int64_t)ospf
->vrf_id
;
11464 json_object_int_add(json_vrf
, "vrfId", vrf_id_ui
);
11465 json_object_string_addf(json_vrf
, "routerId", "%pI4",
11468 json_object_object_add(json_vrfs
, name
, json_vrf
);
11471 vty_out(vty
, "%-25s %-5d %-16pI4 \n", name
,
11472 ospf
->vrf_id
, &ospf
->router_id
);
11477 json_object_object_add(json
, "vrfs", json_vrfs
);
11478 json_object_int_add(json
, "totalVrfs", count
);
11480 vty_json(vty
, json
);
11483 vty_out(vty
, "\nTotal number of OSPF VRFs: %d\n",
11487 return CMD_SUCCESS
;
11489 DEFPY (clear_ip_ospf_neighbor
,
11490 clear_ip_ospf_neighbor_cmd
,
11491 "clear ip ospf [(1-65535)]$instance neighbor [A.B.C.D$nbr_id]",
11494 "OSPF information\n"
11496 "Reset OSPF Neighbor\n"
11499 struct listnode
*node
;
11500 struct ospf
*ospf
= NULL
;
11502 /* If user does not specify the arguments,
11503 * instance = 0 and nbr_id = 0.0.0.0
11505 if (instance
!= 0) {
11506 /* This means clear only the particular ospf process */
11507 if (instance
!= ospf_instance
)
11508 return CMD_NOT_MY_INSTANCE
;
11511 /* Clear all the ospf processes */
11512 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11513 if (!ospf
->oi_running
)
11516 if (nbr_id_str
&& IPV4_ADDR_SAME(&ospf
->router_id
, &nbr_id
)) {
11517 vty_out(vty
, "Self router-id is not allowed.\r\n ");
11518 return CMD_SUCCESS
;
11521 ospf_neighbor_reset(ospf
, nbr_id
, nbr_id_str
);
11524 return CMD_SUCCESS
;
11527 DEFPY (clear_ip_ospf_process
,
11528 clear_ip_ospf_process_cmd
,
11529 "clear ip ospf [(1-65535)]$instance process",
11532 "OSPF information\n"
11534 "Reset OSPF Process\n")
11536 struct listnode
*node
;
11537 struct ospf
*ospf
= NULL
;
11539 /* Check if instance is not passed as an argument */
11540 if (instance
!= 0) {
11541 /* This means clear only the particular ospf process */
11542 if (instance
!= ospf_instance
)
11543 return CMD_NOT_MY_INSTANCE
;
11546 /* Clear all the ospf processes */
11547 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11548 if (!ospf
->oi_running
)
11551 ospf_process_reset(ospf
);
11554 return CMD_SUCCESS
;
11557 static const char *const ospf_abr_type_str
[] = {
11558 "unknown", "standard", "ibm", "cisco", "shortcut"
11561 static const char *const ospf_shortcut_mode_str
[] = {
11562 "default", "enable", "disable"
11564 static int ospf_vty_external_rt_walkcb(struct hash_bucket
*bucket
,
11567 struct external_info
*ei
= bucket
->data
;
11568 struct vty
*vty
= (struct vty
*)arg
;
11569 static unsigned int count
;
11571 vty_out(vty
, "%-4pI4/%d, ", &ei
->p
.prefix
, ei
->p
.prefixlen
);
11574 if (count
% 5 == 0)
11575 vty_out(vty
, "\n");
11577 if (OSPF_EXTERNAL_RT_COUNT(ei
->aggr_route
) == count
)
11580 return HASHWALK_CONTINUE
;
11583 static int ospf_json_external_rt_walkcb(struct hash_bucket
*bucket
,
11586 struct external_info
*ei
= bucket
->data
;
11587 struct json_object
*json
= (struct json_object
*)arg
;
11588 char buf
[PREFIX2STR_BUFFER
];
11590 static unsigned int count
;
11592 prefix2str(&ei
->p
, buf
, sizeof(buf
));
11594 snprintf(exnalbuf
, 20, "Exnl Addr-%d", count
);
11596 json_object_string_add(json
, exnalbuf
, buf
);
11600 if (OSPF_EXTERNAL_RT_COUNT(ei
->aggr_route
) == count
)
11603 return HASHWALK_CONTINUE
;
11606 static int ospf_show_summary_address(struct vty
*vty
, struct ospf
*ospf
,
11607 uint8_t use_vrf
, json_object
*json
,
11608 bool uj
, bool detail
)
11610 struct route_node
*rn
;
11611 json_object
*json_vrf
= NULL
;
11614 static char header
[] =
11615 "Summary-address Metric-type Metric Tag External_Rt_count\n";
11617 mtype
= metric_type(ospf
, 0, ospf
->instance
);
11618 mval
= metric_value(ospf
, 0, ospf
->instance
);
11621 vty_out(vty
, "%s\n", header
);
11625 json_vrf
= json_object_new_object();
11630 if (ospf
->instance
) {
11632 json_object_int_add(json
, "ospfInstance",
11635 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
11638 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
11641 vty_out(vty
, "aggregation delay interval :%u(in seconds)\n\n",
11642 ospf
->aggr_delay_interval
);
11644 json_object_int_add(json_vrf
, "aggregation delay interval",
11645 ospf
->aggr_delay_interval
);
11646 json_object_int_add(json_vrf
, "aggregationDelayInterval",
11647 ospf
->aggr_delay_interval
);
11650 for (rn
= route_top(ospf
->rt_aggr_tbl
); rn
; rn
= route_next(rn
))
11652 struct ospf_external_aggr_rt
*aggr
= rn
->info
;
11653 json_object
*json_aggr
= NULL
;
11654 char buf
[PREFIX2STR_BUFFER
];
11656 prefix2str(&aggr
->p
, buf
, sizeof(buf
));
11660 json_aggr
= json_object_new_object();
11662 json_object_object_add(json_vrf
, buf
,
11665 json_object_string_add(json_aggr
,
11666 "Summary address", buf
);
11667 json_object_string_add(json_aggr
,
11668 "summaryAddress", buf
);
11670 json_object_string_add(
11671 json_aggr
, "Metric-type",
11672 (mtype
== EXTERNAL_METRIC_TYPE_1
)
11675 json_object_string_add(
11676 json_aggr
, "metricType",
11677 (mtype
== EXTERNAL_METRIC_TYPE_1
)
11681 #if CONFDATE > 20230131
11682 CPP_NOTICE("Remove JSON object commands with keys starting with capital")
11684 json_object_int_add(json_aggr
, "Metric", mval
);
11685 json_object_int_add(json_aggr
, "metric", mval
);
11687 json_object_int_add(json_aggr
, "Tag",
11689 json_object_int_add(json_aggr
, "tag",
11692 json_object_int_add(
11693 json_aggr
, "External route count",
11694 OSPF_EXTERNAL_RT_COUNT(aggr
));
11695 json_object_int_add(
11696 json_aggr
, "externalRouteCount",
11697 OSPF_EXTERNAL_RT_COUNT(aggr
));
11699 if (OSPF_EXTERNAL_RT_COUNT(aggr
) && detail
) {
11701 aggr
->match_extnl_hash
,
11702 ospf_json_external_rt_walkcb
,
11707 vty_out(vty
, "%-20s", buf
);
11709 (mtype
== EXTERNAL_METRIC_TYPE_1
)
11710 ? vty_out(vty
, "%-16s", "E1")
11711 : vty_out(vty
, "%-16s", "E2");
11712 vty_out(vty
, "%-11d", mval
);
11714 vty_out(vty
, "%-12u", aggr
->tag
);
11716 vty_out(vty
, "%-5ld\n",
11717 OSPF_EXTERNAL_RT_COUNT(aggr
));
11719 if (OSPF_EXTERNAL_RT_COUNT(aggr
) && detail
) {
11721 "Matched External routes:\n");
11723 aggr
->match_extnl_hash
,
11724 ospf_vty_external_rt_walkcb
,
11726 vty_out(vty
, "\n");
11729 vty_out(vty
, "\n");
11735 json_object_object_add(json
, ospf_get_name(ospf
),
11738 vty_out(vty
, "\n");
11740 return CMD_SUCCESS
;
11743 DEFUN (show_ip_ospf_external_aggregator
,
11744 show_ip_ospf_external_aggregator_cmd
,
11745 "show ip ospf [vrf <NAME|all>] summary-address [detail] [json]",
11747 "OSPF information\n"
11750 "Show external summary addresses\n"
11751 "Detailed information\n"
11754 char *vrf_name
= NULL
;
11755 bool all_vrf
= false;
11756 int ret
= CMD_SUCCESS
;
11759 uint8_t use_vrf
= 0;
11760 bool uj
= use_json(argc
, argv
);
11761 struct ospf
*ospf
= NULL
;
11762 json_object
*json
= NULL
;
11763 struct listnode
*node
= NULL
;
11765 bool detail
= false;
11767 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11769 if (argv_find(argv
, argc
, "detail", &idx
))
11773 json
= json_object_new_object();
11775 /* vrf input is provided */
11779 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11780 if (!ospf
->oi_running
)
11782 ret
= ospf_show_summary_address(
11783 vty
, ospf
, use_vrf
, json
, uj
, detail
);
11787 vty_json(vty
, json
);
11792 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11794 if (ospf
== NULL
|| !ospf
->oi_running
) {
11796 vty_json(vty
, json
);
11799 "%% OSPF is not enabled in vrf %s\n",
11802 return CMD_SUCCESS
;
11804 ospf_show_summary_address(vty
, ospf
, use_vrf
, json
, uj
, detail
);
11808 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11809 if (ospf
== NULL
|| !ospf
->oi_running
) {
11811 vty_json(vty
, json
);
11814 "%% OSPF is not enabled in vrf default\n");
11816 return CMD_SUCCESS
;
11819 ospf_show_summary_address(vty
, ospf
, use_vrf
, json
, uj
, detail
);
11823 vty_json(vty
, json
);
11824 return CMD_SUCCESS
;
11827 static const char *const ospf_int_type_str
[] = {
11828 "unknown", /* should never be used. */
11832 "point-to-multipoint",
11833 "virtual-link", /* should never be used. */
11837 static const char *interface_config_auth_str(struct ospf_if_params
*params
)
11839 if (!OSPF_IF_PARAM_CONFIGURED(params
, auth_type
)
11840 || params
->auth_type
== OSPF_AUTH_NOTSET
)
11843 /* Translation tables are not that much help
11844 * here due to syntax
11845 * of the simple option */
11846 switch (params
->auth_type
) {
11848 case OSPF_AUTH_NULL
:
11851 case OSPF_AUTH_SIMPLE
:
11854 case OSPF_AUTH_CRYPTOGRAPHIC
:
11855 return " message-digest";
11861 static int config_write_interface_one(struct vty
*vty
, struct vrf
*vrf
)
11863 struct listnode
*node
;
11864 struct interface
*ifp
;
11865 struct crypt_key
*ck
;
11866 struct route_node
*rn
= NULL
;
11867 struct ospf_if_params
*params
;
11868 const char *auth_str
;
11871 FOR_ALL_INTERFACES (vrf
, ifp
) {
11873 if (memcmp(ifp
->name
, "VLINK", 5) == 0)
11876 if_vty_config_start(vty
, ifp
);
11879 vty_out(vty
, " description %s\n", ifp
->desc
);
11883 params
= IF_DEF_PARAMS(ifp
);
11886 /* Interface Network print. */
11887 if (OSPF_IF_PARAM_CONFIGURED(params
, type
)
11888 && params
->type
!= OSPF_IFTYPE_LOOPBACK
) {
11889 if (params
->type
!= ospf_default_iftype(ifp
)) {
11890 vty_out(vty
, " ip ospf network %s",
11894 == OSPF_IFTYPE_POINTOPOINT
11895 && params
->ptp_dmvpn
)
11896 vty_out(vty
, " dmvpn");
11897 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11898 vty_out(vty
, " %pI4",
11900 vty_out(vty
, "\n");
11904 /* OSPF interface authentication print */
11905 auth_str
= interface_config_auth_str(params
);
11907 vty_out(vty
, " ip ospf authentication%s",
11909 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11910 vty_out(vty
, " %pI4",
11912 vty_out(vty
, "\n");
11915 /* Simple Authentication Password print. */
11916 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_simple
)
11917 && params
->auth_simple
[0] != '\0') {
11918 vty_out(vty
, " ip ospf authentication-key %s",
11919 params
->auth_simple
);
11920 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11921 vty_out(vty
, " %pI4",
11923 vty_out(vty
, "\n");
11926 /* Cryptographic Authentication Key print. */
11927 if (params
&& params
->auth_crypt
) {
11928 for (ALL_LIST_ELEMENTS_RO(params
->auth_crypt
,
11931 " ip ospf message-digest-key %d md5 %s",
11932 ck
->key_id
, ck
->auth_key
);
11933 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11934 vty_out(vty
, " %pI4",
11936 vty_out(vty
, "\n");
11940 /* Interface Output Cost print. */
11941 if (OSPF_IF_PARAM_CONFIGURED(params
, output_cost_cmd
)) {
11942 vty_out(vty
, " ip ospf cost %u",
11943 params
->output_cost_cmd
);
11944 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11945 vty_out(vty
, " %pI4",
11947 vty_out(vty
, "\n");
11950 /* Hello Interval print. */
11951 if (OSPF_IF_PARAM_CONFIGURED(params
, v_hello
)
11952 && params
->v_hello
!= OSPF_HELLO_INTERVAL_DEFAULT
) {
11953 vty_out(vty
, " ip ospf hello-interval %u",
11955 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11956 vty_out(vty
, " %pI4",
11958 vty_out(vty
, "\n");
11962 /* Router Dead Interval print. */
11963 if (OSPF_IF_PARAM_CONFIGURED(params
, v_wait
)
11964 && params
->is_v_wait_set
) {
11965 vty_out(vty
, " ip ospf dead-interval ");
11968 if (OSPF_IF_PARAM_CONFIGURED(params
,
11971 "minimal hello-multiplier %d",
11972 params
->fast_hello
);
11974 vty_out(vty
, "%u", params
->v_wait
);
11976 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11977 vty_out(vty
, " %pI4",
11979 vty_out(vty
, "\n");
11982 /* Router Priority print. */
11983 if (OSPF_IF_PARAM_CONFIGURED(params
, priority
)
11984 && params
->priority
11985 != OSPF_ROUTER_PRIORITY_DEFAULT
) {
11986 vty_out(vty
, " ip ospf priority %u",
11988 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11989 vty_out(vty
, " %pI4",
11991 vty_out(vty
, "\n");
11994 /* Retransmit Interval print. */
11995 if (OSPF_IF_PARAM_CONFIGURED(params
,
11996 retransmit_interval
)
11997 && params
->retransmit_interval
11998 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
) {
11999 vty_out(vty
, " ip ospf retransmit-interval %u",
12000 params
->retransmit_interval
);
12001 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12002 vty_out(vty
, " %pI4",
12004 vty_out(vty
, "\n");
12007 /* Transmit Delay print. */
12008 if (OSPF_IF_PARAM_CONFIGURED(params
, transmit_delay
)
12009 && params
->transmit_delay
12010 != OSPF_TRANSMIT_DELAY_DEFAULT
) {
12011 vty_out(vty
, " ip ospf transmit-delay %u",
12012 params
->transmit_delay
);
12013 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12014 vty_out(vty
, " %pI4",
12016 vty_out(vty
, "\n");
12020 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
12022 vty_out(vty
, " ip ospf %d",
12025 vty_out(vty
, " ip ospf");
12027 char buf
[INET_ADDRSTRLEN
];
12029 area_id2str(buf
, sizeof(buf
), ¶ms
->if_area
,
12030 params
->if_area_id_fmt
);
12031 vty_out(vty
, " area %s", buf
);
12032 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12033 vty_out(vty
, " %pI4",
12035 vty_out(vty
, "\n");
12039 if (params
&& params
->bfd_config
)
12040 ospf_bfd_write_config(vty
, params
);
12042 /* MTU ignore print. */
12043 if (OSPF_IF_PARAM_CONFIGURED(params
, mtu_ignore
)
12044 && params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
) {
12045 if (params
->mtu_ignore
== 0)
12046 vty_out(vty
, " no ip ospf mtu-ignore");
12048 vty_out(vty
, " ip ospf mtu-ignore");
12049 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12050 vty_out(vty
, " %pI4",
12052 vty_out(vty
, "\n");
12055 if (OSPF_IF_PARAM_CONFIGURED(params
,
12056 passive_interface
)) {
12057 vty_out(vty
, " %sip ospf passive",
12058 params
->passive_interface
12062 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
12063 vty_out(vty
, " %pI4", &rn
->p
.u
.prefix4
);
12064 vty_out(vty
, "\n");
12067 /* LDP-Sync print */
12068 if (params
&& params
->ldp_sync_info
)
12069 ospf_ldp_sync_if_write_config(vty
, params
);
12073 rn
= route_top(IF_OIFS_PARAMS(ifp
));
12075 rn
= route_next(rn
);
12080 if (params
!= NULL
)
12085 ospf_opaque_config_write_if(vty
, ifp
);
12087 if_vty_config_end(vty
);
12093 /* Configuration write function for ospfd. */
12094 static int config_write_interface(struct vty
*vty
)
12097 struct vrf
*vrf
= NULL
;
12099 /* Display all VRF aware OSPF interface configuration */
12100 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
12101 write
+= config_write_interface_one(vty
, vrf
);
12107 static int config_write_network_area(struct vty
*vty
, struct ospf
*ospf
)
12109 struct route_node
*rn
;
12110 char buf
[INET_ADDRSTRLEN
];
12112 /* `network area' print. */
12113 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
))
12115 struct ospf_network
*n
= rn
->info
;
12117 /* Create Area ID string by specified Area ID format. */
12118 if (n
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
12119 inet_ntop(AF_INET
, &n
->area_id
, buf
,
12122 snprintf(buf
, sizeof(buf
), "%lu",
12123 (unsigned long int)ntohl(
12124 n
->area_id
.s_addr
));
12126 /* Network print. */
12127 vty_out(vty
, " network %pFX area %s\n", &rn
->p
, buf
);
12133 static int config_write_ospf_area(struct vty
*vty
, struct ospf
*ospf
)
12135 struct listnode
*node
;
12136 struct ospf_area
*area
;
12137 char buf
[INET_ADDRSTRLEN
];
12139 /* Area configuration print. */
12140 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
12141 struct route_node
*rn1
;
12143 area_id2str(buf
, sizeof(buf
), &area
->area_id
,
12144 area
->area_id_fmt
);
12146 if (area
->auth_type
!= OSPF_AUTH_NULL
) {
12147 if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
12148 vty_out(vty
, " area %s authentication\n", buf
);
12151 " area %s authentication message-digest\n",
12155 if (area
->shortcut_configured
!= OSPF_SHORTCUT_DEFAULT
)
12156 vty_out(vty
, " area %s shortcut %s\n", buf
,
12157 ospf_shortcut_mode_str
12158 [area
->shortcut_configured
]);
12160 if ((area
->external_routing
== OSPF_AREA_STUB
)
12161 || (area
->external_routing
== OSPF_AREA_NSSA
)) {
12162 if (area
->external_routing
== OSPF_AREA_STUB
) {
12163 vty_out(vty
, " area %s stub", buf
);
12164 if (area
->no_summary
)
12165 vty_out(vty
, " no-summary\n");
12166 vty_out(vty
, "\n");
12167 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
12168 switch (area
->NSSATranslatorRole
) {
12169 case OSPF_NSSA_ROLE_NEVER
:
12171 " area %s nssa translate-never\n",
12174 case OSPF_NSSA_ROLE_ALWAYS
:
12176 " area %s nssa translate-always\n",
12179 case OSPF_NSSA_ROLE_CANDIDATE
:
12180 vty_out(vty
, " area %s nssa \n", buf
);
12183 if (area
->no_summary
)
12185 " area %s nssa no-summary\n",
12187 if (area
->suppress_fa
)
12189 " area %s nssa suppress-fa\n",
12193 if (area
->default_cost
!= 1)
12194 vty_out(vty
, " area %s default-cost %d\n", buf
,
12195 area
->default_cost
);
12198 for (rn1
= route_top(area
->ranges
); rn1
; rn1
= route_next(rn1
))
12200 struct ospf_area_range
*range
= rn1
->info
;
12202 vty_out(vty
, " area %s range %pFX", buf
,
12205 if (range
->cost_config
12206 != OSPF_AREA_RANGE_COST_UNSPEC
)
12207 vty_out(vty
, " cost %d",
12208 range
->cost_config
);
12210 if (!CHECK_FLAG(range
->flags
,
12211 OSPF_AREA_RANGE_ADVERTISE
))
12212 vty_out(vty
, " not-advertise");
12214 if (CHECK_FLAG(range
->flags
,
12215 OSPF_AREA_RANGE_SUBSTITUTE
))
12216 vty_out(vty
, " substitute %pI4/%d",
12217 &range
->subst_addr
,
12218 range
->subst_masklen
);
12220 vty_out(vty
, "\n");
12223 if (EXPORT_NAME(area
))
12224 vty_out(vty
, " area %s export-list %s\n", buf
,
12225 EXPORT_NAME(area
));
12227 if (IMPORT_NAME(area
))
12228 vty_out(vty
, " area %s import-list %s\n", buf
,
12229 IMPORT_NAME(area
));
12231 if (PREFIX_NAME_IN(area
))
12232 vty_out(vty
, " area %s filter-list prefix %s in\n", buf
,
12233 PREFIX_NAME_IN(area
));
12235 if (PREFIX_NAME_OUT(area
))
12236 vty_out(vty
, " area %s filter-list prefix %s out\n",
12237 buf
, PREFIX_NAME_OUT(area
));
12243 static int config_write_ospf_nbr_nbma(struct vty
*vty
, struct ospf
*ospf
)
12245 struct ospf_nbr_nbma
*nbr_nbma
;
12246 struct route_node
*rn
;
12248 /* Static Neighbor configuration print. */
12249 for (rn
= route_top(ospf
->nbr_nbma
); rn
; rn
= route_next(rn
))
12250 if ((nbr_nbma
= rn
->info
)) {
12251 vty_out(vty
, " neighbor %pI4", &nbr_nbma
->addr
);
12253 if (nbr_nbma
->priority
12254 != OSPF_NEIGHBOR_PRIORITY_DEFAULT
)
12255 vty_out(vty
, " priority %d",
12256 nbr_nbma
->priority
);
12258 if (nbr_nbma
->v_poll
!= OSPF_POLL_INTERVAL_DEFAULT
)
12259 vty_out(vty
, " poll-interval %d",
12262 vty_out(vty
, "\n");
12268 static int config_write_virtual_link(struct vty
*vty
, struct ospf
*ospf
)
12270 struct listnode
*node
;
12271 struct ospf_vl_data
*vl_data
;
12272 const char *auth_str
;
12273 char buf
[INET_ADDRSTRLEN
];
12275 /* Virtual-Link print */
12276 for (ALL_LIST_ELEMENTS_RO(ospf
->vlinks
, node
, vl_data
)) {
12277 struct listnode
*n2
;
12278 struct crypt_key
*ck
;
12279 struct ospf_interface
*oi
;
12281 if (vl_data
!= NULL
) {
12282 area_id2str(buf
, sizeof(buf
), &vl_data
->vl_area_id
,
12283 vl_data
->vl_area_id_fmt
);
12284 oi
= vl_data
->vl_oi
;
12287 if (OSPF_IF_PARAM(oi
, v_hello
)
12288 != OSPF_HELLO_INTERVAL_DEFAULT
12289 || OSPF_IF_PARAM(oi
, v_wait
)
12290 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
12291 || OSPF_IF_PARAM(oi
, retransmit_interval
)
12292 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
12293 || OSPF_IF_PARAM(oi
, transmit_delay
)
12294 != OSPF_TRANSMIT_DELAY_DEFAULT
)
12296 " area %s virtual-link %pI4 hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n",
12297 buf
, &vl_data
->vl_peer
,
12298 OSPF_IF_PARAM(oi
, v_hello
),
12299 OSPF_IF_PARAM(oi
, retransmit_interval
),
12300 OSPF_IF_PARAM(oi
, transmit_delay
),
12301 OSPF_IF_PARAM(oi
, v_wait
));
12303 vty_out(vty
, " area %s virtual-link %pI4\n", buf
,
12304 &vl_data
->vl_peer
);
12306 auth_str
= interface_config_auth_str(
12307 IF_DEF_PARAMS(oi
->ifp
));
12310 " area %s virtual-link %pI4 authentication%s\n",
12311 buf
, &vl_data
->vl_peer
, auth_str
);
12313 if (IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)->auth_simple
[0]
12316 " area %s virtual-link %pI4 authentication-key %s\n",
12317 buf
, &vl_data
->vl_peer
,
12318 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
12321 for (ALL_LIST_ELEMENTS_RO(
12322 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
12326 " area %s virtual-link %pI4 message-digest-key %d md5 %s\n",
12327 buf
, &vl_data
->vl_peer
,
12328 ck
->key_id
, ck
->auth_key
);
12336 static int config_write_ospf_redistribute(struct vty
*vty
, struct ospf
*ospf
)
12340 /* redistribute print. */
12341 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
12342 struct list
*red_list
;
12343 struct listnode
*node
;
12344 struct ospf_redist
*red
;
12346 red_list
= ospf
->redist
[type
];
12350 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
12351 vty_out(vty
, " redistribute %s",
12352 zebra_route_string(type
));
12354 vty_out(vty
, " %d", red
->instance
);
12356 if (red
->dmetric
.value
>= 0)
12357 vty_out(vty
, " metric %d", red
->dmetric
.value
);
12359 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
12360 vty_out(vty
, " metric-type 1");
12362 if (ROUTEMAP_NAME(red
))
12363 vty_out(vty
, " route-map %s",
12364 ROUTEMAP_NAME(red
));
12366 vty_out(vty
, "\n");
12373 static int ospf_cfg_write_helper_dis_rtr_walkcb(struct hash_bucket
*bucket
,
12376 struct advRtr
*rtr
= bucket
->data
;
12377 struct vty
*vty
= (struct vty
*)arg
;
12379 vty_out(vty
, " graceful-restart helper enable %pI4\n",
12381 return HASHWALK_CONTINUE
;
12384 static void config_write_ospf_gr(struct vty
*vty
, struct ospf
*ospf
)
12386 if (!ospf
->gr_info
.restart_support
)
12389 if (ospf
->gr_info
.grace_period
== OSPF_DFLT_GRACE_INTERVAL
)
12390 vty_out(vty
, " graceful-restart\n");
12392 vty_out(vty
, " graceful-restart grace-period %u\n",
12393 ospf
->gr_info
.grace_period
);
12396 static int config_write_ospf_gr_helper(struct vty
*vty
, struct ospf
*ospf
)
12398 if (ospf
->is_helper_supported
)
12399 vty_out(vty
, " graceful-restart helper enable\n");
12401 if (!ospf
->strict_lsa_check
)
12403 " no graceful-restart helper strict-lsa-checking\n");
12405 if (ospf
->only_planned_restart
)
12406 vty_out(vty
, " graceful-restart helper planned-only\n");
12408 if (ospf
->supported_grace_time
!= OSPF_MAX_GRACE_INTERVAL
)
12410 " graceful-restart helper supported-grace-time %d\n",
12411 ospf
->supported_grace_time
);
12413 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf
)) {
12414 hash_walk(ospf
->enable_rtr_list
,
12415 ospf_cfg_write_helper_dis_rtr_walkcb
, vty
);
12420 static int config_write_ospf_external_aggregator(struct vty
*vty
,
12423 struct route_node
*rn
;
12425 if (ospf
->aggr_delay_interval
!= OSPF_EXTL_AGGR_DEFAULT_DELAY
)
12426 vty_out(vty
, " aggregation timer %u\n",
12427 ospf
->aggr_delay_interval
);
12429 /* print 'summary-address A.B.C.D/M' */
12430 for (rn
= route_top(ospf
->rt_aggr_tbl
); rn
; rn
= route_next(rn
))
12432 struct ospf_external_aggr_rt
*aggr
= rn
->info
;
12434 vty_out(vty
, " summary-address %pI4/%d",
12435 &aggr
->p
.prefix
, aggr
->p
.prefixlen
);
12437 vty_out(vty
, " tag %u", aggr
->tag
);
12439 if (CHECK_FLAG(aggr
->flags
,
12440 OSPF_EXTERNAL_AGGRT_NO_ADVERTISE
))
12441 vty_out(vty
, " no-advertise");
12443 vty_out(vty
, "\n");
12449 static int config_write_ospf_default_metric(struct vty
*vty
, struct ospf
*ospf
)
12451 if (ospf
->default_metric
!= -1)
12452 vty_out(vty
, " default-metric %d\n", ospf
->default_metric
);
12456 static int config_write_ospf_distribute(struct vty
*vty
, struct ospf
*ospf
)
12459 struct ospf_redist
*red
;
12462 /* distribute-list print. */
12463 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
12464 if (DISTRIBUTE_NAME(ospf
, type
))
12465 vty_out(vty
, " distribute-list %s out %s\n",
12466 DISTRIBUTE_NAME(ospf
, type
),
12467 zebra_route_string(type
));
12469 /* default-information print. */
12470 if (ospf
->default_originate
!= DEFAULT_ORIGINATE_NONE
) {
12471 vty_out(vty
, " default-information originate");
12472 if (ospf
->default_originate
== DEFAULT_ORIGINATE_ALWAYS
)
12473 vty_out(vty
, " always");
12475 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
12477 if (red
->dmetric
.value
>= 0)
12478 vty_out(vty
, " metric %d",
12479 red
->dmetric
.value
);
12481 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
12482 vty_out(vty
, " metric-type 1");
12484 if (ROUTEMAP_NAME(red
))
12485 vty_out(vty
, " route-map %s",
12486 ROUTEMAP_NAME(red
));
12489 vty_out(vty
, "\n");
12496 static int config_write_ospf_distance(struct vty
*vty
, struct ospf
*ospf
)
12498 struct route_node
*rn
;
12499 struct ospf_distance
*odistance
;
12501 if (ospf
->distance_all
)
12502 vty_out(vty
, " distance %d\n", ospf
->distance_all
);
12504 if (ospf
->distance_intra
|| ospf
->distance_inter
12505 || ospf
->distance_external
) {
12506 vty_out(vty
, " distance ospf");
12508 if (ospf
->distance_intra
)
12509 vty_out(vty
, " intra-area %d", ospf
->distance_intra
);
12510 if (ospf
->distance_inter
)
12511 vty_out(vty
, " inter-area %d", ospf
->distance_inter
);
12512 if (ospf
->distance_external
)
12513 vty_out(vty
, " external %d", ospf
->distance_external
);
12515 vty_out(vty
, "\n");
12518 for (rn
= route_top(ospf
->distance_table
); rn
; rn
= route_next(rn
))
12519 if ((odistance
= rn
->info
) != NULL
) {
12520 vty_out(vty
, " distance %d %pFX %s\n",
12521 odistance
->distance
, &rn
->p
,
12522 odistance
->access_list
? odistance
->access_list
12528 static int ospf_config_write_one(struct vty
*vty
, struct ospf
*ospf
)
12532 /* `router ospf' print. */
12533 if (ospf
->instance
&& strcmp(ospf
->name
, VRF_DEFAULT_NAME
)) {
12534 vty_out(vty
, "router ospf %d vrf %s\n", ospf
->instance
,
12536 } else if (ospf
->instance
) {
12537 vty_out(vty
, "router ospf %d\n", ospf
->instance
);
12538 } else if (strcmp(ospf
->name
, VRF_DEFAULT_NAME
)) {
12539 vty_out(vty
, "router ospf vrf %s\n", ospf
->name
);
12541 vty_out(vty
, "router ospf\n");
12543 if (!ospf
->networks
) {
12548 /* Router ID print. */
12549 if (ospf
->router_id_static
.s_addr
!= INADDR_ANY
)
12550 vty_out(vty
, " ospf router-id %pI4\n",
12551 &ospf
->router_id_static
);
12553 /* zebra opaque attributes configuration. */
12554 if (CHECK_FLAG(ospf
->config
, OSPF_SEND_EXTRA_DATA_TO_ZEBRA
))
12555 vty_out(vty
, " ospf send-extra-data zebra\n");
12557 /* ABR type print. */
12558 if (ospf
->abr_type
!= OSPF_ABR_DEFAULT
)
12559 vty_out(vty
, " ospf abr-type %s\n",
12560 ospf_abr_type_str
[ospf
->abr_type
]);
12562 /* log-adjacency-changes flag print. */
12563 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
12564 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
))
12565 vty_out(vty
, " log-adjacency-changes detail\n");
12566 else if (!SAVE_OSPF_LOG_ADJACENCY_CHANGES
)
12567 vty_out(vty
, " log-adjacency-changes\n");
12568 } else if (SAVE_OSPF_LOG_ADJACENCY_CHANGES
) {
12569 vty_out(vty
, " no log-adjacency-changes\n");
12572 /* RFC1583 compatibility flag print -- Compatible with CISCO
12574 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
))
12575 vty_out(vty
, " compatible rfc1583\n");
12577 /* auto-cost reference-bandwidth configuration. */
12578 if (ospf
->ref_bandwidth
!= OSPF_DEFAULT_REF_BANDWIDTH
) {
12580 "! Important: ensure reference bandwidth is consistent across all routers\n");
12581 vty_out(vty
, " auto-cost reference-bandwidth %d\n",
12582 ospf
->ref_bandwidth
);
12585 /* SPF timers print. */
12586 if (ospf
->spf_delay
!= OSPF_SPF_DELAY_DEFAULT
12587 || ospf
->spf_holdtime
!= OSPF_SPF_HOLDTIME_DEFAULT
12588 || ospf
->spf_max_holdtime
!= OSPF_SPF_MAX_HOLDTIME_DEFAULT
)
12589 vty_out(vty
, " timers throttle spf %d %d %d\n", ospf
->spf_delay
,
12590 ospf
->spf_holdtime
, ospf
->spf_max_holdtime
);
12592 /* LSA timers print. */
12593 if (ospf
->min_ls_interval
!= OSPF_MIN_LS_INTERVAL
)
12594 vty_out(vty
, " timers throttle lsa all %d\n",
12595 ospf
->min_ls_interval
);
12596 if (ospf
->min_ls_arrival
!= OSPF_MIN_LS_ARRIVAL
)
12597 vty_out(vty
, " timers lsa min-arrival %d\n",
12598 ospf
->min_ls_arrival
);
12600 /* Write multiplier print. */
12601 if (ospf
->write_oi_count
!= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
)
12602 vty_out(vty
, " ospf write-multiplier %d\n",
12603 ospf
->write_oi_count
);
12605 if (ospf
->max_multipath
!= MULTIPATH_NUM
)
12606 vty_out(vty
, " maximum-paths %d\n", ospf
->max_multipath
);
12608 /* Max-metric router-lsa print */
12609 config_write_stub_router(vty
, ospf
);
12611 /* SPF refresh parameters print. */
12612 if (ospf
->lsa_refresh_interval
!= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
12613 vty_out(vty
, " refresh timer %d\n", ospf
->lsa_refresh_interval
);
12615 /* Redistribute information print. */
12616 config_write_ospf_redistribute(vty
, ospf
);
12618 /* Graceful Restart print */
12619 config_write_ospf_gr(vty
, ospf
);
12620 config_write_ospf_gr_helper(vty
, ospf
);
12622 /* Print external route aggregation. */
12623 config_write_ospf_external_aggregator(vty
, ospf
);
12625 /* passive-interface print. */
12626 if (ospf
->passive_interface_default
== OSPF_IF_PASSIVE
)
12627 vty_out(vty
, " passive-interface default\n");
12629 /* proactive-arp print. */
12630 if (ospf
->proactive_arp
!= OSPF_PROACTIVE_ARP_DEFAULT
) {
12631 if (ospf
->proactive_arp
)
12632 vty_out(vty
, " proactive-arp\n");
12634 vty_out(vty
, " no proactive-arp\n");
12637 /* TI-LFA print. */
12638 if (ospf
->ti_lfa_enabled
) {
12639 if (ospf
->ti_lfa_protection_type
== OSPF_TI_LFA_NODE_PROTECTION
)
12640 vty_out(vty
, " fast-reroute ti-lfa node-protection\n");
12642 vty_out(vty
, " fast-reroute ti-lfa\n");
12645 /* Network area print. */
12646 config_write_network_area(vty
, ospf
);
12648 /* Area config print. */
12649 config_write_ospf_area(vty
, ospf
);
12651 /* static neighbor print. */
12652 config_write_ospf_nbr_nbma(vty
, ospf
);
12654 /* Virtual-Link print. */
12655 config_write_virtual_link(vty
, ospf
);
12657 /* Default metric configuration. */
12658 config_write_ospf_default_metric(vty
, ospf
);
12660 /* Distribute-list and default-information print. */
12661 config_write_ospf_distribute(vty
, ospf
);
12663 /* Distance configuration. */
12664 config_write_ospf_distance(vty
, ospf
);
12666 ospf_opaque_config_write_router(vty
, ospf
);
12668 /* LDP-Sync print */
12669 ospf_ldp_sync_write_config(vty
, ospf
);
12671 vty_out(vty
, "exit\n");
12677 /* OSPF configuration write function. */
12678 static int ospf_config_write(struct vty
*vty
)
12681 struct listnode
*ospf_node
= NULL
;
12684 if (listcount(om
->ospf
) == 0)
12687 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, ospf_node
, ospf
)) {
12688 /* VRF Default check if it is running.
12689 * Upon daemon start, there could be default instance
12690 * in absence of 'router ospf'/oi_running is disabled. */
12691 if (ospf
->vrf_id
== VRF_DEFAULT
&& ospf
->oi_running
)
12692 write
+= ospf_config_write_one(vty
, ospf
);
12693 /* For Non-Default VRF simply display the configuration,
12694 * even if it is not oi_running. */
12695 else if (ospf
->vrf_id
!= VRF_DEFAULT
)
12696 write
+= ospf_config_write_one(vty
, ospf
);
12701 void ospf_vty_show_init(void)
12703 /* "show ip ospf" commands. */
12704 install_element(VIEW_NODE
, &show_ip_ospf_cmd
);
12706 install_element(VIEW_NODE
, &show_ip_ospf_instance_cmd
);
12708 /* "show ip ospf database" commands. */
12709 install_element(VIEW_NODE
, &show_ip_ospf_database_cmd
);
12710 install_element(VIEW_NODE
, &show_ip_ospf_database_max_cmd
);
12711 install_element(VIEW_NODE
,
12712 &show_ip_ospf_database_type_adv_router_cmd
);
12713 install_element(VIEW_NODE
,
12714 &show_ip_ospf_instance_database_type_adv_router_cmd
);
12715 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_cmd
);
12716 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_max_cmd
);
12718 /* "show ip ospf interface" commands. */
12719 install_element(VIEW_NODE
, &show_ip_ospf_interface_cmd
);
12721 install_element(VIEW_NODE
, &show_ip_ospf_instance_interface_cmd
);
12722 /* "show ip ospf interface traffic */
12723 install_element(VIEW_NODE
, &show_ip_ospf_interface_traffic_cmd
);
12725 /* "show ip ospf neighbor" commands. */
12726 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_detail_cmd
);
12727 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_cmd
);
12728 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_id_cmd
);
12729 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_all_cmd
);
12730 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_cmd
);
12731 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_cmd
);
12732 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_all_cmd
);
12734 install_element(VIEW_NODE
,
12735 &show_ip_ospf_instance_neighbor_int_detail_cmd
);
12736 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_int_cmd
);
12737 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_id_cmd
);
12738 install_element(VIEW_NODE
,
12739 &show_ip_ospf_instance_neighbor_detail_all_cmd
);
12740 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_detail_cmd
);
12741 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_cmd
);
12742 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_all_cmd
);
12744 /* "show ip ospf route" commands. */
12745 install_element(VIEW_NODE
, &show_ip_ospf_route_cmd
);
12746 install_element(VIEW_NODE
, &show_ip_ospf_border_routers_cmd
);
12747 install_element(VIEW_NODE
, &show_ip_ospf_reachable_routers_cmd
);
12749 install_element(VIEW_NODE
, &show_ip_ospf_instance_route_cmd
);
12750 install_element(VIEW_NODE
, &show_ip_ospf_instance_border_routers_cmd
);
12751 install_element(VIEW_NODE
,
12752 &show_ip_ospf_instance_reachable_routers_cmd
);
12754 /* "show ip ospf vrfs" commands. */
12755 install_element(VIEW_NODE
, &show_ip_ospf_vrfs_cmd
);
12757 /* "show ip ospf gr-helper details" command */
12758 install_element(VIEW_NODE
, &show_ip_ospf_gr_helper_cmd
);
12760 /* "show ip ospf summary-address" command */
12761 install_element(VIEW_NODE
, &show_ip_ospf_external_aggregator_cmd
);
12764 /* Initialization of OSPF interface. */
12765 static void ospf_vty_if_init(void)
12767 /* Install interface node. */
12768 if_cmd_init(config_write_interface
);
12770 /* "ip ospf authentication" commands. */
12771 install_element(INTERFACE_NODE
, &ip_ospf_authentication_args_addr_cmd
);
12772 install_element(INTERFACE_NODE
, &ip_ospf_authentication_addr_cmd
);
12773 install_element(INTERFACE_NODE
,
12774 &no_ip_ospf_authentication_args_addr_cmd
);
12775 install_element(INTERFACE_NODE
, &no_ip_ospf_authentication_addr_cmd
);
12776 install_element(INTERFACE_NODE
, &ip_ospf_authentication_key_addr_cmd
);
12777 install_element(INTERFACE_NODE
,
12778 &no_ip_ospf_authentication_key_authkey_addr_cmd
);
12779 install_element(INTERFACE_NODE
,
12780 &no_ospf_authentication_key_authkey_addr_cmd
);
12782 /* "ip ospf message-digest-key" commands. */
12783 install_element(INTERFACE_NODE
, &ip_ospf_message_digest_key_cmd
);
12784 install_element(INTERFACE_NODE
, &no_ip_ospf_message_digest_key_cmd
);
12786 /* "ip ospf cost" commands. */
12787 install_element(INTERFACE_NODE
, &ip_ospf_cost_cmd
);
12788 install_element(INTERFACE_NODE
, &no_ip_ospf_cost_cmd
);
12790 /* "ip ospf mtu-ignore" commands. */
12791 install_element(INTERFACE_NODE
, &ip_ospf_mtu_ignore_addr_cmd
);
12792 install_element(INTERFACE_NODE
, &no_ip_ospf_mtu_ignore_addr_cmd
);
12794 /* "ip ospf dead-interval" commands. */
12795 install_element(INTERFACE_NODE
, &ip_ospf_dead_interval_cmd
);
12796 install_element(INTERFACE_NODE
,
12797 &ip_ospf_dead_interval_minimal_addr_cmd
);
12798 install_element(INTERFACE_NODE
, &no_ip_ospf_dead_interval_cmd
);
12800 /* "ip ospf hello-interval" commands. */
12801 install_element(INTERFACE_NODE
, &ip_ospf_hello_interval_cmd
);
12802 install_element(INTERFACE_NODE
, &no_ip_ospf_hello_interval_cmd
);
12804 /* "ip ospf network" commands. */
12805 install_element(INTERFACE_NODE
, &ip_ospf_network_cmd
);
12806 install_element(INTERFACE_NODE
, &no_ip_ospf_network_cmd
);
12808 /* "ip ospf priority" commands. */
12809 install_element(INTERFACE_NODE
, &ip_ospf_priority_cmd
);
12810 install_element(INTERFACE_NODE
, &no_ip_ospf_priority_cmd
);
12812 /* "ip ospf retransmit-interval" commands. */
12813 install_element(INTERFACE_NODE
, &ip_ospf_retransmit_interval_addr_cmd
);
12814 install_element(INTERFACE_NODE
,
12815 &no_ip_ospf_retransmit_interval_addr_cmd
);
12817 /* "ip ospf transmit-delay" commands. */
12818 install_element(INTERFACE_NODE
, &ip_ospf_transmit_delay_addr_cmd
);
12819 install_element(INTERFACE_NODE
, &no_ip_ospf_transmit_delay_addr_cmd
);
12821 /* "ip ospf area" commands. */
12822 install_element(INTERFACE_NODE
, &ip_ospf_area_cmd
);
12823 install_element(INTERFACE_NODE
, &no_ip_ospf_area_cmd
);
12825 /* "ip ospf passive" commands. */
12826 install_element(INTERFACE_NODE
, &ip_ospf_passive_cmd
);
12827 install_element(INTERFACE_NODE
, &no_ip_ospf_passive_cmd
);
12829 /* These commands are compatibitliy for previous version. */
12830 install_element(INTERFACE_NODE
, &ospf_authentication_key_cmd
);
12831 install_element(INTERFACE_NODE
, &ospf_message_digest_key_cmd
);
12832 install_element(INTERFACE_NODE
, &no_ospf_message_digest_key_cmd
);
12833 install_element(INTERFACE_NODE
, &ospf_dead_interval_cmd
);
12834 install_element(INTERFACE_NODE
, &no_ospf_dead_interval_cmd
);
12835 install_element(INTERFACE_NODE
, &ospf_hello_interval_cmd
);
12836 install_element(INTERFACE_NODE
, &no_ospf_hello_interval_cmd
);
12837 install_element(INTERFACE_NODE
, &ospf_cost_cmd
);
12838 install_element(INTERFACE_NODE
, &no_ospf_cost_cmd
);
12839 install_element(INTERFACE_NODE
, &ospf_network_cmd
);
12840 install_element(INTERFACE_NODE
, &no_ospf_network_cmd
);
12841 install_element(INTERFACE_NODE
, &ospf_priority_cmd
);
12842 install_element(INTERFACE_NODE
, &no_ospf_priority_cmd
);
12843 install_element(INTERFACE_NODE
, &ospf_retransmit_interval_cmd
);
12844 install_element(INTERFACE_NODE
, &no_ospf_retransmit_interval_cmd
);
12845 install_element(INTERFACE_NODE
, &ospf_transmit_delay_cmd
);
12846 install_element(INTERFACE_NODE
, &no_ospf_transmit_delay_cmd
);
12849 static void ospf_vty_zebra_init(void)
12851 install_element(OSPF_NODE
, &ospf_redistribute_source_cmd
);
12852 install_element(OSPF_NODE
, &no_ospf_redistribute_source_cmd
);
12853 install_element(OSPF_NODE
, &ospf_redistribute_instance_source_cmd
);
12854 install_element(OSPF_NODE
, &no_ospf_redistribute_instance_source_cmd
);
12856 install_element(OSPF_NODE
, &ospf_distribute_list_out_cmd
);
12857 install_element(OSPF_NODE
, &no_ospf_distribute_list_out_cmd
);
12859 install_element(OSPF_NODE
, &ospf_default_information_originate_cmd
);
12860 install_element(OSPF_NODE
, &no_ospf_default_information_originate_cmd
);
12862 install_element(OSPF_NODE
, &ospf_default_metric_cmd
);
12863 install_element(OSPF_NODE
, &no_ospf_default_metric_cmd
);
12865 install_element(OSPF_NODE
, &ospf_distance_cmd
);
12866 install_element(OSPF_NODE
, &no_ospf_distance_cmd
);
12867 install_element(OSPF_NODE
, &no_ospf_distance_ospf_cmd
);
12868 install_element(OSPF_NODE
, &ospf_distance_ospf_cmd
);
12870 /*Ospf garcefull restart helper configurations */
12871 install_element(OSPF_NODE
, &ospf_gr_helper_enable_cmd
);
12872 install_element(OSPF_NODE
, &no_ospf_gr_helper_enable_cmd
);
12873 install_element(OSPF_NODE
, &ospf_gr_helper_enable_lsacheck_cmd
);
12874 install_element(OSPF_NODE
, &no_ospf_gr_helper_enable_lsacheck_cmd
);
12875 install_element(OSPF_NODE
, &ospf_gr_helper_supported_grace_time_cmd
);
12876 install_element(OSPF_NODE
, &no_ospf_gr_helper_supported_grace_time_cmd
);
12877 install_element(OSPF_NODE
, &ospf_gr_helper_planned_only_cmd
);
12878 install_element(OSPF_NODE
, &no_ospf_gr_helper_planned_only_cmd
);
12880 /* External LSA summarisation config commands.*/
12881 install_element(OSPF_NODE
, &ospf_external_route_aggregation_cmd
);
12882 install_element(OSPF_NODE
, &no_ospf_external_route_aggregation_cmd
);
12883 install_element(OSPF_NODE
,
12884 &ospf_external_route_aggregation_no_adrvertise_cmd
);
12885 install_element(OSPF_NODE
,
12886 &no_ospf_external_route_aggregation_no_adrvertise_cmd
);
12887 install_element(OSPF_NODE
, &ospf_route_aggregation_timer_cmd
);
12888 install_element(OSPF_NODE
, &no_ospf_route_aggregation_timer_cmd
);
12891 static int ospf_config_write(struct vty
*vty
);
12892 static struct cmd_node ospf_node
= {
12895 .parent_node
= CONFIG_NODE
,
12896 .prompt
= "%s(config-router)# ",
12897 .config_write
= ospf_config_write
,
12900 static void ospf_interface_clear(struct interface
*ifp
)
12902 if (!if_is_operative(ifp
))
12905 if (IS_DEBUG_OSPF(ism
, ISM_EVENTS
))
12906 zlog_debug("ISM[%s]: clear by reset", ifp
->name
);
12908 ospf_if_reset(ifp
);
12911 DEFUN (clear_ip_ospf_interface
,
12912 clear_ip_ospf_interface_cmd
,
12913 "clear ip ospf [vrf NAME] interface [IFNAME]",
12916 "OSPF information\n"
12918 "Interface information\n"
12919 "Interface name\n")
12921 int idx_ifname
= 0;
12923 struct interface
*ifp
;
12924 struct listnode
*node
;
12925 struct ospf
*ospf
= NULL
;
12926 char *vrf_name
= NULL
;
12927 vrf_id_t vrf_id
= VRF_DEFAULT
;
12928 struct vrf
*vrf
= NULL
;
12930 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
12931 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
12932 if (vrf_name
&& strmatch(vrf_name
, VRF_DEFAULT_NAME
))
12935 vrf
= vrf_lookup_by_name(vrf_name
);
12937 vrf_id
= vrf
->vrf_id
;
12939 if (!argv_find(argv
, argc
, "IFNAME", &idx_ifname
)) {
12940 /* Clear all the ospfv2 interfaces. */
12941 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
12942 if (vrf_id
!= ospf
->vrf_id
)
12945 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
12946 FOR_ALL_INTERFACES (vrf
, ifp
)
12947 ospf_interface_clear(ifp
);
12950 /* Interface name is specified. */
12951 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf_id
);
12953 vty_out(vty
, "No such interface name\n");
12955 ospf_interface_clear(ifp
);
12958 return CMD_SUCCESS
;
12961 DEFPY_HIDDEN(ospf_lsa_refresh_timer
, ospf_lsa_refresh_timer_cmd
,
12962 "[no$no] ospf lsa-refresh [(120-1800)]$value",
12964 "OSPF lsa refresh timer\n"
12965 "timer value in seconds\n")
12967 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
12970 ospf
->lsa_refresh_timer
= OSPF_LS_REFRESH_TIME
;
12972 ospf
->lsa_refresh_timer
= value
;
12974 return CMD_SUCCESS
;
12977 DEFPY_HIDDEN(ospf_maxage_delay_timer
, ospf_maxage_delay_timer_cmd
,
12978 "[no$no] ospf maxage-delay [(0-60)]$value",
12980 "OSPF lsa maxage delay timer\n"
12981 "timer value in seconds\n")
12983 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
)
12986 ospf
->maxage_delay
= OSPF_LSA_MAXAGE_REMOVE_DELAY_DEFAULT
;
12988 ospf
->maxage_delay
= value
;
12990 THREAD_OFF(ospf
->t_maxage
);
12991 OSPF_TIMER_ON(ospf
->t_maxage
, ospf_maxage_lsa_remover
,
12992 ospf
->maxage_delay
);
12994 return CMD_SUCCESS
;
12997 void ospf_vty_clear_init(void)
12999 install_element(ENABLE_NODE
, &clear_ip_ospf_interface_cmd
);
13000 install_element(ENABLE_NODE
, &clear_ip_ospf_process_cmd
);
13001 install_element(ENABLE_NODE
, &clear_ip_ospf_neighbor_cmd
);
13005 /* Install OSPF related vty commands. */
13006 void ospf_vty_init(void)
13008 /* Install ospf top node. */
13009 install_node(&ospf_node
);
13011 /* "router ospf" commands. */
13012 install_element(CONFIG_NODE
, &router_ospf_cmd
);
13013 install_element(CONFIG_NODE
, &no_router_ospf_cmd
);
13016 install_default(OSPF_NODE
);
13018 /* "ospf router-id" commands. */
13019 install_element(OSPF_NODE
, &ospf_router_id_cmd
);
13020 install_element(OSPF_NODE
, &ospf_router_id_old_cmd
);
13021 install_element(OSPF_NODE
, &no_ospf_router_id_cmd
);
13023 /* "passive-interface" commands. */
13024 install_element(OSPF_NODE
, &ospf_passive_interface_default_cmd
);
13025 install_element(OSPF_NODE
, &ospf_passive_interface_addr_cmd
);
13026 install_element(OSPF_NODE
, &no_ospf_passive_interface_default_cmd
);
13027 install_element(OSPF_NODE
, &no_ospf_passive_interface_addr_cmd
);
13029 /* "ospf abr-type" commands. */
13030 install_element(OSPF_NODE
, &ospf_abr_type_cmd
);
13031 install_element(OSPF_NODE
, &no_ospf_abr_type_cmd
);
13033 /* "ospf log-adjacency-changes" commands. */
13034 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_cmd
);
13035 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_detail_cmd
);
13036 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_cmd
);
13037 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_detail_cmd
);
13039 /* "ospf rfc1583-compatible" commands. */
13040 install_element(OSPF_NODE
, &ospf_compatible_rfc1583_cmd
);
13041 install_element(OSPF_NODE
, &no_ospf_compatible_rfc1583_cmd
);
13042 install_element(OSPF_NODE
, &ospf_rfc1583_flag_cmd
);
13043 install_element(OSPF_NODE
, &no_ospf_rfc1583_flag_cmd
);
13045 /* "ospf send-extra-data zebra" commands. */
13046 install_element(OSPF_NODE
, &ospf_send_extra_data_cmd
);
13048 /* "network area" commands. */
13049 install_element(OSPF_NODE
, &ospf_network_area_cmd
);
13050 install_element(OSPF_NODE
, &no_ospf_network_area_cmd
);
13052 /* "area authentication" commands. */
13053 install_element(OSPF_NODE
,
13054 &ospf_area_authentication_message_digest_cmd
);
13055 install_element(OSPF_NODE
, &ospf_area_authentication_cmd
);
13056 install_element(OSPF_NODE
, &no_ospf_area_authentication_cmd
);
13058 /* "area range" commands. */
13059 install_element(OSPF_NODE
, &ospf_area_range_cmd
);
13060 install_element(OSPF_NODE
, &ospf_area_range_cost_cmd
);
13061 install_element(OSPF_NODE
, &ospf_area_range_not_advertise_cmd
);
13062 install_element(OSPF_NODE
, &no_ospf_area_range_cmd
);
13063 install_element(OSPF_NODE
, &no_ospf_area_range_substitute_cmd
);
13065 /* "area virtual-link" commands. */
13066 install_element(OSPF_NODE
, &ospf_area_vlink_cmd
);
13067 install_element(OSPF_NODE
, &ospf_area_vlink_intervals_cmd
);
13068 install_element(OSPF_NODE
, &no_ospf_area_vlink_cmd
);
13069 install_element(OSPF_NODE
, &no_ospf_area_vlink_intervals_cmd
);
13072 /* "area stub" commands. */
13073 install_element(OSPF_NODE
, &ospf_area_stub_no_summary_cmd
);
13074 install_element(OSPF_NODE
, &ospf_area_stub_cmd
);
13075 install_element(OSPF_NODE
, &no_ospf_area_stub_no_summary_cmd
);
13076 install_element(OSPF_NODE
, &no_ospf_area_stub_cmd
);
13078 /* "area nssa" commands. */
13079 install_element(OSPF_NODE
, &ospf_area_nssa_cmd
);
13080 install_element(OSPF_NODE
, &ospf_area_nssa_translate_cmd
);
13081 install_element(OSPF_NODE
, &ospf_area_nssa_no_summary_cmd
);
13082 install_element(OSPF_NODE
, &no_ospf_area_nssa_no_summary_cmd
);
13083 install_element(OSPF_NODE
, &ospf_area_nssa_suppress_fa_cmd
);
13084 install_element(OSPF_NODE
, &no_ospf_area_nssa_suppress_fa_cmd
);
13085 install_element(OSPF_NODE
, &no_ospf_area_nssa_cmd
);
13087 install_element(OSPF_NODE
, &ospf_area_default_cost_cmd
);
13088 install_element(OSPF_NODE
, &no_ospf_area_default_cost_cmd
);
13090 install_element(OSPF_NODE
, &ospf_area_shortcut_cmd
);
13091 install_element(OSPF_NODE
, &no_ospf_area_shortcut_cmd
);
13093 install_element(OSPF_NODE
, &ospf_area_export_list_cmd
);
13094 install_element(OSPF_NODE
, &no_ospf_area_export_list_cmd
);
13096 install_element(OSPF_NODE
, &ospf_area_filter_list_cmd
);
13097 install_element(OSPF_NODE
, &no_ospf_area_filter_list_cmd
);
13099 install_element(OSPF_NODE
, &ospf_area_import_list_cmd
);
13100 install_element(OSPF_NODE
, &no_ospf_area_import_list_cmd
);
13102 /* SPF timer commands */
13103 install_element(OSPF_NODE
, &ospf_timers_throttle_spf_cmd
);
13104 install_element(OSPF_NODE
, &no_ospf_timers_throttle_spf_cmd
);
13106 /* LSA timers commands */
13107 install_element(OSPF_NODE
, &ospf_timers_min_ls_interval_cmd
);
13108 install_element(OSPF_NODE
, &no_ospf_timers_min_ls_interval_cmd
);
13109 install_element(OSPF_NODE
, &ospf_timers_lsa_min_arrival_cmd
);
13110 install_element(OSPF_NODE
, &no_ospf_timers_lsa_min_arrival_cmd
);
13112 /* refresh timer commands */
13113 install_element(OSPF_NODE
, &ospf_refresh_timer_cmd
);
13114 install_element(OSPF_NODE
, &no_ospf_refresh_timer_val_cmd
);
13116 /* max-metric commands */
13117 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_admin_cmd
);
13118 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_admin_cmd
);
13119 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_startup_cmd
);
13120 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_startup_cmd
);
13121 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_shutdown_cmd
);
13122 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_shutdown_cmd
);
13124 /* reference bandwidth commands */
13125 install_element(OSPF_NODE
, &ospf_auto_cost_reference_bandwidth_cmd
);
13126 install_element(OSPF_NODE
, &no_ospf_auto_cost_reference_bandwidth_cmd
);
13128 /* "neighbor" commands. */
13129 install_element(OSPF_NODE
, &ospf_neighbor_cmd
);
13130 install_element(OSPF_NODE
, &ospf_neighbor_poll_interval_cmd
);
13131 install_element(OSPF_NODE
, &no_ospf_neighbor_cmd
);
13132 install_element(OSPF_NODE
, &no_ospf_neighbor_poll_cmd
);
13134 /* write multiplier commands */
13135 install_element(OSPF_NODE
, &ospf_write_multiplier_cmd
);
13136 install_element(OSPF_NODE
, &write_multiplier_cmd
);
13137 install_element(OSPF_NODE
, &no_ospf_write_multiplier_cmd
);
13138 install_element(OSPF_NODE
, &no_write_multiplier_cmd
);
13140 /* "proactive-arp" commands. */
13141 install_element(OSPF_NODE
, &ospf_proactive_arp_cmd
);
13142 install_element(OSPF_NODE
, &no_ospf_proactive_arp_cmd
);
13144 /* TI-LFA commands */
13145 install_element(OSPF_NODE
, &ospf_ti_lfa_cmd
);
13146 install_element(OSPF_NODE
, &no_ospf_ti_lfa_cmd
);
13148 /* Max path configurations */
13149 install_element(OSPF_NODE
, &ospf_max_multipath_cmd
);
13150 install_element(OSPF_NODE
, &no_ospf_max_multipath_cmd
);
13152 vrf_cmd_init(NULL
);
13154 install_element(OSPF_NODE
, &ospf_lsa_refresh_timer_cmd
);
13155 install_element(OSPF_NODE
, &ospf_maxage_delay_timer_cmd
);
13157 /* Init interface related vty commands. */
13158 ospf_vty_if_init();
13160 /* Init zebra related vty commands. */
13161 ospf_vty_zebra_init();