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);
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
;
169 if (*vrf_name
&& strmatch(*vrf_name
, VRF_DEFAULT_NAME
))
176 static void ospf_show_vrf_name(struct ospf
*ospf
, struct vty
*vty
,
177 json_object
*json
, uint8_t use_vrf
)
181 if (ospf
->vrf_id
== VRF_DEFAULT
)
182 json_object_string_add(json
, "vrfName",
185 json_object_string_add(json
, "vrfName",
187 json_object_int_add(json
, "vrfId", ospf
->vrf_id
);
189 if (ospf
->vrf_id
== VRF_DEFAULT
)
190 vty_out(vty
, "VRF Name: %s\n", "default");
192 vty_out(vty
, "VRF Name: %s\n", ospf
->name
);
197 #ifndef VTYSH_EXTRACT_PL
198 #include "ospfd/ospf_vty_clippy.c"
201 DEFUN_NOSH (router_ospf
,
203 "router ospf [{(1-65535)|vrf NAME}]",
204 "Enable a routing process\n"
205 "Start OSPF configuration\n"
209 unsigned short instance
;
210 const char *vrf_name
;
211 bool created
= false;
215 ret
= ospf_router_cmd_parse(vty
, argv
, argc
, &instance
, &vrf_name
);
216 if (ret
!= CMD_SUCCESS
)
219 if (instance
!= ospf_instance
) {
220 VTY_PUSH_CONTEXT_NULL(OSPF_NODE
);
221 return CMD_NOT_MY_INSTANCE
;
224 ospf
= ospf_get(instance
, vrf_name
, &created
);
227 if (DFLT_OSPF_LOG_ADJACENCY_CHANGES
)
228 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
230 if (IS_DEBUG_OSPF_EVENT
)
232 "Config command 'router ospf %d' received, vrf %s id %u oi_running %u",
233 ospf
->instance
, ospf
->name
? ospf
->name
: "NIL",
234 ospf
->vrf_id
, ospf
->oi_running
);
236 VTY_PUSH_CONTEXT(OSPF_NODE
, ospf
);
241 DEFUN (no_router_ospf
,
243 "no router ospf [{(1-65535)|vrf NAME}]",
245 "Enable a routing process\n"
246 "Start OSPF configuration\n"
250 unsigned short instance
;
251 const char *vrf_name
;
255 ret
= ospf_router_cmd_parse(vty
, argv
, argc
, &instance
, &vrf_name
);
256 if (ret
!= CMD_SUCCESS
)
259 if (instance
!= ospf_instance
)
260 return CMD_NOT_MY_INSTANCE
;
262 ospf
= ospf_lookup(instance
, vrf_name
);
266 ret
= CMD_WARNING_CONFIG_FAILED
;
272 DEFPY (ospf_router_id
,
274 "ospf router-id A.B.C.D",
275 "OSPF specific commands\n"
276 "router-id for the OSPF process\n"
277 "OSPF router-id in IP address format\n")
279 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
281 struct listnode
*node
;
282 struct ospf_area
*area
;
284 ospf
->router_id_static
= router_id
;
286 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
287 if (area
->full_nbrs
) {
289 "For this router-id change to take effect, use \"clear ip ospf process\" command\n");
293 ospf_router_id_update(ospf
);
298 DEFUN_HIDDEN (ospf_router_id_old
,
299 ospf_router_id_old_cmd
,
301 "router-id for the OSPF process\n"
302 "OSPF router-id in IP address format\n")
304 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
306 struct listnode
*node
;
307 struct ospf_area
*area
;
308 struct in_addr router_id
;
311 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &router_id
);
313 vty_out(vty
, "Please specify Router ID by A.B.C.D\n");
314 return CMD_WARNING_CONFIG_FAILED
;
317 ospf
->router_id_static
= router_id
;
319 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
320 if (area
->full_nbrs
) {
322 "For this router-id change to take effect, use \"clear ip ospf process\" command\n");
326 ospf_router_id_update(ospf
);
331 DEFPY (no_ospf_router_id
,
332 no_ospf_router_id_cmd
,
333 "no ospf router-id [A.B.C.D]",
335 "OSPF specific commands\n"
336 "router-id for the OSPF process\n"
337 "OSPF router-id in IP address format\n")
339 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
340 struct listnode
*node
;
341 struct ospf_area
*area
;
344 if (!IPV4_ADDR_SAME(&ospf
->router_id_static
, &router_id
)) {
345 vty_out(vty
, "%% OSPF router-id doesn't match\n");
346 return CMD_WARNING_CONFIG_FAILED
;
350 ospf
->router_id_static
.s_addr
= 0;
352 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
353 if (area
->full_nbrs
) {
355 "For this router-id change to take effect, use \"clear ip ospf process\" command\n");
359 ospf_router_id_update(ospf
);
365 static void ospf_passive_interface_default_update(struct ospf
*ospf
,
369 struct ospf_interface
*oi
;
371 ospf
->passive_interface_default
= newval
;
373 /* update multicast memberships */
374 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, ln
, oi
))
375 ospf_if_set_multicast(oi
);
378 static void ospf_passive_interface_update(struct interface
*ifp
,
379 struct ospf_if_params
*params
,
380 struct in_addr addr
, uint8_t newval
)
382 struct route_node
*rn
;
384 if (OSPF_IF_PARAM_CONFIGURED(params
, passive_interface
)) {
385 if (params
->passive_interface
== newval
)
388 params
->passive_interface
= newval
;
389 UNSET_IF_PARAM(params
, passive_interface
);
390 if (params
!= IF_DEF_PARAMS(ifp
)) {
391 ospf_free_if_params(ifp
, addr
);
392 ospf_if_update_params(ifp
, addr
);
395 params
->passive_interface
= newval
;
396 SET_IF_PARAM(params
, passive_interface
);
400 * XXX We should call ospf_if_set_multicast on exactly those
401 * interfaces for which the passive property changed. It is too much
402 * work to determine this set, so we do this for every interface.
403 * This is safe and reasonable because ospf_if_set_multicast uses a
404 * record of joined groups to avoid systems calls if the desired
405 * memberships match the current memership.
408 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
409 struct ospf_interface
*oi
= rn
->info
;
412 ospf_if_set_multicast(oi
);
416 * XXX It is not clear what state transitions the interface needs to
417 * undergo when going from active to passive and vice versa. Fixing
418 * this will require precise identification of interfaces having such a
423 DEFUN (ospf_passive_interface_default
,
424 ospf_passive_interface_default_cmd
,
425 "passive-interface default",
426 "Suppress routing updates on an interface\n"
427 "Suppress routing updates on interfaces by default\n")
429 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
431 ospf_passive_interface_default_update(ospf
, OSPF_IF_PASSIVE
);
436 DEFUN_HIDDEN (ospf_passive_interface_addr
,
437 ospf_passive_interface_addr_cmd
,
438 "passive-interface IFNAME [A.B.C.D]",
439 "Suppress routing updates on an interface\n"
443 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
445 struct interface
*ifp
= NULL
;
446 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
447 struct ospf_if_params
*params
;
451 "This command is deprecated, because it is not VRF-aware.\n");
453 "Please, use \"ip ospf passive\" on an interface instead.\n");
455 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
456 ifp
= if_get_by_name(argv
[1]->arg
, ospf
->vrf_id
);
459 vty_out(vty
, "interface %s not found.\n", (char *)argv
[1]->arg
);
460 return CMD_WARNING_CONFIG_FAILED
;
464 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
467 "Please specify interface address by A.B.C.D\n");
468 return CMD_WARNING_CONFIG_FAILED
;
471 params
= ospf_get_if_params(ifp
, addr
);
472 ospf_if_update_params(ifp
, addr
);
474 params
= IF_DEF_PARAMS(ifp
);
477 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_PASSIVE
);
482 DEFUN (no_ospf_passive_interface_default
,
483 no_ospf_passive_interface_default_cmd
,
484 "no passive-interface default",
486 "Allow routing updates on an interface\n"
487 "Allow routing updates on interfaces by default\n")
489 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
491 ospf_passive_interface_default_update(ospf
, OSPF_IF_ACTIVE
);
496 DEFUN_HIDDEN (no_ospf_passive_interface
,
497 no_ospf_passive_interface_addr_cmd
,
498 "no passive-interface IFNAME [A.B.C.D]",
500 "Allow routing updates on an interface\n"
504 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
506 struct interface
*ifp
= NULL
;
507 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
508 struct ospf_if_params
*params
;
512 "This command is deprecated, because it is not VRF-aware.\n");
514 "Please, use \"no ip ospf passive\" on an interface instead.\n");
516 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
517 ifp
= if_get_by_name(argv
[2]->arg
, ospf
->vrf_id
);
520 vty_out(vty
, "interface %s not found.\n", (char *)argv
[2]->arg
);
521 return CMD_WARNING_CONFIG_FAILED
;
525 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
528 "Please specify interface address by A.B.C.D\n");
529 return CMD_WARNING_CONFIG_FAILED
;
531 params
= ospf_lookup_if_params(ifp
, addr
);
535 params
= IF_DEF_PARAMS(ifp
);
538 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_ACTIVE
);
544 DEFUN (ospf_network_area
,
545 ospf_network_area_cmd
,
546 "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
547 "Enable routing on an IP network\n"
548 "OSPF network prefix\n"
549 "Set the OSPF area ID\n"
550 "OSPF area ID in IP address format\n"
551 "OSPF area ID as a decimal value\n")
553 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
554 int idx_ipv4_prefixlen
= 1;
555 int idx_ipv4_number
= 3;
556 struct prefix_ipv4 p
;
557 struct in_addr area_id
;
561 if (ospf
->instance
) {
563 "The network command is not supported in multi-instance ospf\n");
564 return CMD_WARNING_CONFIG_FAILED
;
567 count
= ospf_count_area_params(ospf
);
570 "Please remove all ip ospf area x.x.x.x commands first.\n");
571 if (IS_DEBUG_OSPF_EVENT
)
573 "%s ospf vrf %s num of %u ip ospf area x config",
574 __func__
, ospf
->name
? ospf
->name
: "NIL",
576 return CMD_WARNING_CONFIG_FAILED
;
579 /* Get network prefix and Area ID. */
580 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
581 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
583 ret
= ospf_network_set(ospf
, &p
, area_id
, format
);
585 vty_out(vty
, "There is already same network statement.\n");
586 return CMD_WARNING_CONFIG_FAILED
;
592 DEFUN (no_ospf_network_area
,
593 no_ospf_network_area_cmd
,
594 "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
596 "Enable routing on an IP network\n"
597 "OSPF network prefix\n"
598 "Set the OSPF area ID\n"
599 "OSPF area ID in IP address format\n"
600 "OSPF area ID as a decimal value\n")
602 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
603 int idx_ipv4_prefixlen
= 2;
604 int idx_ipv4_number
= 4;
605 struct prefix_ipv4 p
;
606 struct in_addr area_id
;
609 if (ospf
->instance
) {
611 "The network command is not supported in multi-instance ospf\n");
612 return CMD_WARNING_CONFIG_FAILED
;
615 /* Get network prefix and Area ID. */
616 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
617 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
619 ret
= ospf_network_unset(ospf
, &p
, area_id
);
622 "Can't find specified network area configuration.\n");
623 return CMD_WARNING_CONFIG_FAILED
;
629 DEFUN (ospf_area_range
,
631 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]",
632 "OSPF area parameters\n"
633 "OSPF area ID in IP address format\n"
634 "OSPF area ID as a decimal value\n"
635 "Summarize routes matching address/mask (border routers only)\n"
636 "Area range prefix\n"
637 "Advertise this range (default)\n"
638 "User specified metric for this range\n"
639 "Advertised metric for this range\n")
641 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
642 int idx_ipv4_number
= 1;
643 int idx_ipv4_prefixlen
= 3;
645 struct prefix_ipv4 p
;
646 struct in_addr area_id
;
650 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
651 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
653 ospf_area_range_set(ospf
, area_id
, &p
, OSPF_AREA_RANGE_ADVERTISE
);
654 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
657 cost
= strtoul(argv
[idx_cost
]->arg
, NULL
, 10);
658 ospf_area_range_cost_set(ospf
, area_id
, &p
, cost
);
664 DEFUN (ospf_area_range_cost
,
665 ospf_area_range_cost_cmd
,
666 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M cost (0-16777215)",
667 "OSPF area parameters\n"
668 "OSPF area ID in IP address format\n"
669 "OSPF area ID as a decimal value\n"
670 "Summarize routes matching address/mask (border routers only)\n"
671 "Area range prefix\n"
672 "User specified metric for this range\n"
673 "Advertised metric for this range\n")
675 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
676 int idx_ipv4_number
= 1;
677 int idx_ipv4_prefixlen
= 3;
679 struct prefix_ipv4 p
;
680 struct in_addr area_id
;
684 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
685 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
687 ospf_area_range_set(ospf
, area_id
, &p
, OSPF_AREA_RANGE_ADVERTISE
);
688 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
691 cost
= strtoul(argv
[idx_cost
]->arg
, NULL
, 10);
692 ospf_area_range_cost_set(ospf
, area_id
, &p
, cost
);
697 DEFUN (ospf_area_range_not_advertise
,
698 ospf_area_range_not_advertise_cmd
,
699 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise",
700 "OSPF area parameters\n"
701 "OSPF area ID in IP address format\n"
702 "OSPF area ID as a decimal value\n"
703 "Summarize routes matching address/mask (border routers only)\n"
704 "Area range prefix\n"
705 "DoNotAdvertise this range\n")
707 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
708 int idx_ipv4_number
= 1;
709 int idx_ipv4_prefixlen
= 3;
710 struct prefix_ipv4 p
;
711 struct in_addr area_id
;
714 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
715 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
717 ospf_area_range_set(ospf
, area_id
, &p
, 0);
718 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
720 ospf_area_range_substitute_unset(ospf
, area_id
, &p
);
725 DEFUN (no_ospf_area_range
,
726 no_ospf_area_range_cmd
,
727 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]",
729 "OSPF area parameters\n"
730 "OSPF area ID in IP address format\n"
731 "OSPF area ID as a decimal value\n"
732 "Summarize routes matching address/mask (border routers only)\n"
733 "Area range prefix\n"
734 "User specified metric for this range\n"
735 "Advertised metric for this range\n"
736 "Advertise this range (default)\n"
737 "User specified metric for this range\n"
738 "Advertised metric for this range\n"
739 "DoNotAdvertise this range\n")
741 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
742 int idx_ipv4_number
= 2;
743 int idx_ipv4_prefixlen
= 4;
744 struct prefix_ipv4 p
;
745 struct in_addr area_id
;
748 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
749 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
751 ospf_area_range_unset(ospf
, area_id
, &p
);
756 DEFUN (ospf_area_range_substitute
,
757 ospf_area_range_substitute_cmd
,
758 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
759 "OSPF area parameters\n"
760 "OSPF area ID in IP address format\n"
761 "OSPF area ID as a decimal value\n"
762 "Summarize routes matching address/mask (border routers only)\n"
763 "Area range prefix\n"
764 "Announce area range as another prefix\n"
765 "Network prefix to be announced instead of range\n")
767 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
768 int idx_ipv4_number
= 1;
769 int idx_ipv4_prefixlen
= 3;
770 int idx_ipv4_prefixlen_2
= 5;
771 struct prefix_ipv4 p
, s
;
772 struct in_addr area_id
;
775 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
776 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
777 str2prefix_ipv4(argv
[idx_ipv4_prefixlen_2
]->arg
, &s
);
779 ospf_area_range_substitute_set(ospf
, area_id
, &p
, &s
);
780 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
786 DEFUN (no_ospf_area_range_substitute
,
787 no_ospf_area_range_substitute_cmd
,
788 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
790 "OSPF area parameters\n"
791 "OSPF area ID in IP address format\n"
792 "OSPF area ID as a decimal value\n"
793 "Summarize routes matching address/mask (border routers only)\n"
794 "Area range prefix\n"
795 "Announce area range as another prefix\n"
796 "Network prefix to be announced instead of range\n")
798 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
799 int idx_ipv4_number
= 2;
800 int idx_ipv4_prefixlen
= 4;
801 int idx_ipv4_prefixlen_2
= 6;
802 struct prefix_ipv4 p
, s
;
803 struct in_addr area_id
;
806 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
807 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
808 str2prefix_ipv4(argv
[idx_ipv4_prefixlen_2
]->arg
, &s
);
810 ospf_area_range_substitute_unset(ospf
, area_id
, &p
);
816 /* Command Handler Logic in VLink stuff is delicate!!
818 ALTER AT YOUR OWN RISK!!!!
820 Various dummy values are used to represent 'NoChange' state for
821 VLink configuration NOT being changed by a VLink command, and
822 special syntax is used within the command strings so that the
823 typed in command verbs can be seen in the configuration command
824 bacckend handler. This is to drastically reduce the verbeage
825 required to coe up with a reasonably compatible Cisco VLink command
827 - Matthew Grant <grantma@anathoth.gen.nz>
828 Wed, 21 Feb 2001 15:13:52 +1300
831 /* Configuration data for virtual links
833 struct ospf_vl_config_data
{
834 struct vty
*vty
; /* vty stuff */
835 struct in_addr area_id
; /* area ID from command line */
836 int area_id_fmt
; /* command line area ID format */
837 struct in_addr vl_peer
; /* command line vl_peer */
838 int auth_type
; /* Authehntication type, if given */
839 char *auth_key
; /* simple password if present */
840 int crypto_key_id
; /* Cryptographic key ID */
841 char *md5_key
; /* MD5 authentication key */
842 int hello_interval
; /* Obvious what these are... */
843 int retransmit_interval
;
848 static void ospf_vl_config_data_init(struct ospf_vl_config_data
*vl_config
,
851 memset(vl_config
, 0, sizeof(struct ospf_vl_config_data
));
852 vl_config
->auth_type
= OSPF_AUTH_CMD_NOTSEEN
;
853 vl_config
->vty
= vty
;
856 static struct ospf_vl_data
*
857 ospf_find_vl_data(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
859 struct ospf_area
*area
;
860 struct ospf_vl_data
*vl_data
;
862 struct in_addr area_id
;
864 vty
= vl_config
->vty
;
865 area_id
= vl_config
->area_id
;
867 if (area_id
.s_addr
== OSPF_AREA_BACKBONE
) {
869 "Configuring VLs over the backbone is not allowed\n");
872 area
= ospf_area_get(ospf
, area_id
);
873 ospf_area_display_format_set(ospf
, area
, vl_config
->area_id_fmt
);
875 if (area
->external_routing
!= OSPF_AREA_DEFAULT
) {
876 if (vl_config
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
877 vty_out(vty
, "Area %pI4 is %s\n", &area_id
,
878 area
->external_routing
== OSPF_AREA_NSSA
882 vty_out(vty
, "Area %ld is %s\n",
883 (unsigned long)ntohl(area_id
.s_addr
),
884 area
->external_routing
== OSPF_AREA_NSSA
890 if ((vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
->vl_peer
))
892 vl_data
= ospf_vl_data_new(area
, vl_config
->vl_peer
);
893 if (vl_data
->vl_oi
== NULL
) {
894 vl_data
->vl_oi
= ospf_vl_new(ospf
, vl_data
);
895 ospf_vl_add(ospf
, vl_data
);
896 ospf_spf_calculate_schedule(ospf
,
897 SPF_FLAG_CONFIG_CHANGE
);
904 static int ospf_vl_set_security(struct ospf_vl_data
*vl_data
,
905 struct ospf_vl_config_data
*vl_config
)
907 struct crypt_key
*ck
;
909 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
911 vty
= vl_config
->vty
;
913 if (vl_config
->auth_type
!= OSPF_AUTH_CMD_NOTSEEN
) {
914 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), auth_type
);
915 IF_DEF_PARAMS(ifp
)->auth_type
= vl_config
->auth_type
;
918 if (vl_config
->auth_key
) {
919 memset(IF_DEF_PARAMS(ifp
)->auth_simple
, 0,
920 OSPF_AUTH_SIMPLE_SIZE
+ 1);
921 strlcpy((char *)IF_DEF_PARAMS(ifp
)->auth_simple
,
923 sizeof(IF_DEF_PARAMS(ifp
)->auth_simple
));
924 } else if (vl_config
->md5_key
) {
925 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
926 vl_config
->crypto_key_id
)
928 vty_out(vty
, "OSPF: Key %d already exists\n",
929 vl_config
->crypto_key_id
);
932 ck
= ospf_crypt_key_new();
933 ck
->key_id
= vl_config
->crypto_key_id
;
934 memset(ck
->auth_key
, 0, OSPF_AUTH_MD5_SIZE
+ 1);
935 strlcpy((char *)ck
->auth_key
, vl_config
->md5_key
,
936 sizeof(ck
->auth_key
));
938 ospf_crypt_key_add(IF_DEF_PARAMS(ifp
)->auth_crypt
, ck
);
939 } else if (vl_config
->crypto_key_id
!= 0) {
942 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
943 vl_config
->crypto_key_id
)
945 vty_out(vty
, "OSPF: Key %d does not exist\n",
946 vl_config
->crypto_key_id
);
947 return CMD_WARNING_CONFIG_FAILED
;
950 ospf_crypt_key_delete(IF_DEF_PARAMS(ifp
)->auth_crypt
,
951 vl_config
->crypto_key_id
);
957 static int ospf_vl_set_timers(struct ospf_vl_data
*vl_data
,
958 struct ospf_vl_config_data
*vl_config
)
960 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
961 /* Virtual Link data initialised to defaults, so only set
963 if (vl_config
->hello_interval
) {
964 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_hello
);
965 IF_DEF_PARAMS(ifp
)->v_hello
= vl_config
->hello_interval
;
968 if (vl_config
->dead_interval
) {
969 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_wait
);
970 IF_DEF_PARAMS(ifp
)->v_wait
= vl_config
->dead_interval
;
973 if (vl_config
->retransmit_interval
) {
974 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), retransmit_interval
);
975 IF_DEF_PARAMS(ifp
)->retransmit_interval
=
976 vl_config
->retransmit_interval
;
979 if (vl_config
->transmit_delay
) {
980 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), transmit_delay
);
981 IF_DEF_PARAMS(ifp
)->transmit_delay
= vl_config
->transmit_delay
;
988 /* The business end of all of the above */
989 static int ospf_vl_set(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
991 struct ospf_vl_data
*vl_data
;
994 vl_data
= ospf_find_vl_data(ospf
, vl_config
);
996 return CMD_WARNING_CONFIG_FAILED
;
998 /* Process this one first as it can have a fatal result, which can
999 only logically occur if the virtual link exists already
1000 Thus a command error does not result in a change to the
1001 running configuration such as unexpectedly altered timer
1003 ret
= ospf_vl_set_security(vl_data
, vl_config
);
1004 if (ret
!= CMD_SUCCESS
)
1007 /* Set any time based parameters, these area already range checked */
1009 ret
= ospf_vl_set_timers(vl_data
, vl_config
);
1010 if (ret
!= CMD_SUCCESS
)
1016 /* This stuff exists to make specifying all the alias commands A LOT simpler
1018 #define VLINK_HELPSTR_IPADDR \
1019 "OSPF area parameters\n" \
1020 "OSPF area ID in IP address format\n" \
1021 "OSPF area ID as a decimal value\n" \
1022 "Configure a virtual link\n" \
1023 "Router ID of the remote ABR\n"
1025 #define VLINK_HELPSTR_AUTHTYPE_SIMPLE \
1026 "Enable authentication on this virtual link\n" \
1029 #define VLINK_HELPSTR_AUTHTYPE_ALL \
1030 VLINK_HELPSTR_AUTHTYPE_SIMPLE \
1031 "Use null authentication\n" \
1032 "Use message-digest authentication\n"
1034 #define VLINK_HELPSTR_TIME_PARAM \
1035 "Time between HELLO packets\n" \
1037 "Time between retransmitting lost link state advertisements\n" \
1039 "Link state transmit delay\n" \
1041 "Interval time after which a neighbor is declared down\n" \
1044 #define VLINK_HELPSTR_AUTH_SIMPLE \
1045 "Authentication password (key)\n" \
1046 "The OSPF password (key)\n"
1048 #define VLINK_HELPSTR_AUTH_MD5 \
1049 "Message digest authentication password (key)\n" \
1051 "Use MD5 algorithm\n" \
1052 "The OSPF password (key)\n"
1054 DEFUN (ospf_area_vlink
,
1055 ospf_area_vlink_cmd
,
1056 "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>]",
1057 VLINK_HELPSTR_IPADDR
1058 "Enable authentication on this virtual link\n"
1059 "Use message-digest authentication\n"
1060 "Use null authentication\n"
1061 VLINK_HELPSTR_AUTH_MD5
1062 VLINK_HELPSTR_AUTH_SIMPLE
)
1064 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1065 int idx_ipv4_number
= 1;
1067 struct ospf_vl_config_data vl_config
;
1068 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1069 char md5_key
[OSPF_AUTH_MD5_SIZE
+ 1];
1073 ospf_vl_config_data_init(&vl_config
, vty
);
1075 /* Read off first 2 parameters and check them */
1076 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1077 &vl_config
.area_id_fmt
);
1079 vty_out(vty
, "OSPF area ID is invalid\n");
1080 return CMD_WARNING_CONFIG_FAILED
;
1083 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1085 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1086 return CMD_WARNING_CONFIG_FAILED
;
1090 /* Thats all folks! - BUGS B. strikes again!!!*/
1092 return ospf_vl_set(ospf
, &vl_config
);
1095 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1096 /* authentication - this option can only occur
1097 at start of command line */
1098 vl_config
.auth_type
= OSPF_AUTH_SIMPLE
;
1101 if (argv_find(argv
, argc
, "message-digest", &idx
)) {
1102 /* authentication message-digest */
1103 vl_config
.auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
1104 } else if (argv_find(argv
, argc
, "null", &idx
)) {
1105 /* "authentication null" */
1106 vl_config
.auth_type
= OSPF_AUTH_NULL
;
1109 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1110 vl_config
.md5_key
= NULL
;
1111 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1112 if (vl_config
.crypto_key_id
< 0)
1113 return CMD_WARNING_CONFIG_FAILED
;
1115 strlcpy(md5_key
, argv
[idx
+ 3]->arg
, sizeof(md5_key
));
1116 vl_config
.md5_key
= md5_key
;
1119 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1120 strlcpy(auth_key
, argv
[idx
+ 1]->arg
, sizeof(auth_key
));
1121 vl_config
.auth_key
= auth_key
;
1124 /* Action configuration */
1126 return ospf_vl_set(ospf
, &vl_config
);
1129 DEFUN (no_ospf_area_vlink
,
1130 no_ospf_area_vlink_cmd
,
1131 "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>]",
1133 VLINK_HELPSTR_IPADDR
1134 "Enable authentication on this virtual link\n"
1135 "Use message-digest authentication\n"
1136 "Use null authentication\n"
1137 VLINK_HELPSTR_AUTH_MD5
1138 VLINK_HELPSTR_AUTH_SIMPLE
)
1140 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1141 int idx_ipv4_number
= 2;
1143 struct ospf_area
*area
;
1144 struct ospf_vl_config_data vl_config
;
1145 struct ospf_vl_data
*vl_data
= NULL
;
1146 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1150 ospf_vl_config_data_init(&vl_config
, vty
);
1152 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1155 vty_out(vty
, "OSPF area ID is invalid\n");
1156 return CMD_WARNING_CONFIG_FAILED
;
1159 area
= ospf_area_lookup_by_area_id(ospf
, vl_config
.area_id
);
1161 vty_out(vty
, "Area does not exist\n");
1162 return CMD_WARNING_CONFIG_FAILED
;
1165 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1167 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1168 return CMD_WARNING_CONFIG_FAILED
;
1171 vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
.vl_peer
);
1173 vty_out(vty
, "Virtual link does not exist\n");
1174 return CMD_WARNING_CONFIG_FAILED
;
1178 /* Basic VLink no command */
1179 /* Thats all folks! - BUGS B. strikes again!!!*/
1180 ospf_vl_delete(ospf
, vl_data
);
1181 ospf_area_check_free(ospf
, vl_config
.area_id
);
1185 /* If we are down here, we are reseting parameters */
1186 /* Deal with other parameters */
1188 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1189 /* authentication - this option can only occur
1190 at start of command line */
1191 vl_config
.auth_type
= OSPF_AUTH_NOTSET
;
1194 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1195 vl_config
.md5_key
= NULL
;
1196 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1197 if (vl_config
.crypto_key_id
< 0)
1198 return CMD_WARNING_CONFIG_FAILED
;
1201 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1202 /* Reset authentication-key to 0 */
1203 memset(auth_key
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
1204 vl_config
.auth_key
= auth_key
;
1207 /* Action configuration */
1209 return ospf_vl_set(ospf
, &vl_config
);
1212 DEFUN (ospf_area_vlink_intervals
,
1213 ospf_area_vlink_intervals_cmd
,
1214 "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)}",
1215 VLINK_HELPSTR_IPADDR
1216 VLINK_HELPSTR_TIME_PARAM
)
1218 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1219 struct ospf_vl_config_data vl_config
;
1222 ospf_vl_config_data_init(&vl_config
, vty
);
1224 char *area_id
= argv
[1]->arg
;
1225 char *router_id
= argv
[3]->arg
;
1227 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1229 vty_out(vty
, "OSPF area ID is invalid\n");
1230 return CMD_WARNING_CONFIG_FAILED
;
1233 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1235 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1236 return CMD_WARNING_CONFIG_FAILED
;
1239 for (int idx
= 4; idx
< argc
; idx
++) {
1240 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1241 vl_config
.hello_interval
=
1242 strtol(argv
[++idx
]->arg
, NULL
, 10);
1243 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1244 vl_config
.retransmit_interval
=
1245 strtol(argv
[++idx
]->arg
, NULL
, 10);
1246 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1247 vl_config
.transmit_delay
=
1248 strtol(argv
[++idx
]->arg
, NULL
, 10);
1249 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1250 vl_config
.dead_interval
=
1251 strtol(argv
[++idx
]->arg
, NULL
, 10);
1254 /* Action configuration */
1255 return ospf_vl_set(ospf
, &vl_config
);
1258 DEFUN (no_ospf_area_vlink_intervals
,
1259 no_ospf_area_vlink_intervals_cmd
,
1260 "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)}",
1262 VLINK_HELPSTR_IPADDR
1263 VLINK_HELPSTR_TIME_PARAM
)
1265 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1266 struct ospf_vl_config_data vl_config
;
1269 ospf_vl_config_data_init(&vl_config
, vty
);
1271 char *area_id
= argv
[2]->arg
;
1272 char *router_id
= argv
[4]->arg
;
1274 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1276 vty_out(vty
, "OSPF area ID is invalid\n");
1277 return CMD_WARNING_CONFIG_FAILED
;
1280 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1282 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1283 return CMD_WARNING_CONFIG_FAILED
;
1286 for (int idx
= 5; idx
< argc
; idx
++) {
1287 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1288 vl_config
.hello_interval
= OSPF_HELLO_INTERVAL_DEFAULT
;
1289 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1290 vl_config
.retransmit_interval
=
1291 OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
1292 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1293 vl_config
.transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
1294 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1295 vl_config
.dead_interval
=
1296 OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
1299 /* Action configuration */
1300 return ospf_vl_set(ospf
, &vl_config
);
1303 DEFUN (ospf_area_shortcut
,
1304 ospf_area_shortcut_cmd
,
1305 "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>",
1306 "OSPF area parameters\n"
1307 "OSPF area ID in IP address format\n"
1308 "OSPF area ID as a decimal value\n"
1309 "Configure the area's shortcutting mode\n"
1310 "Set default shortcutting behavior\n"
1311 "Enable shortcutting through the area\n"
1312 "Disable shortcutting through the area\n")
1314 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1315 int idx_ipv4_number
= 1;
1316 int idx_enable_disable
= 3;
1317 struct ospf_area
*area
;
1318 struct in_addr area_id
;
1322 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1323 argv
[idx_ipv4_number
]->arg
);
1325 area
= ospf_area_get(ospf
, area_id
);
1326 ospf_area_display_format_set(ospf
, area
, format
);
1328 if (strncmp(argv
[idx_enable_disable
]->arg
, "de", 2) == 0)
1329 mode
= OSPF_SHORTCUT_DEFAULT
;
1330 else if (strncmp(argv
[idx_enable_disable
]->arg
, "di", 2) == 0)
1331 mode
= OSPF_SHORTCUT_DISABLE
;
1332 else if (strncmp(argv
[idx_enable_disable
]->arg
, "e", 1) == 0)
1333 mode
= OSPF_SHORTCUT_ENABLE
;
1335 return CMD_WARNING_CONFIG_FAILED
;
1337 ospf_area_shortcut_set(ospf
, area
, mode
);
1339 if (ospf
->abr_type
!= OSPF_ABR_SHORTCUT
)
1341 "Shortcut area setting will take effect only when the router is configured as Shortcut ABR\n");
1346 DEFUN (no_ospf_area_shortcut
,
1347 no_ospf_area_shortcut_cmd
,
1348 "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>",
1350 "OSPF area parameters\n"
1351 "OSPF area ID in IP address format\n"
1352 "OSPF area ID as a decimal value\n"
1353 "Deconfigure the area's shortcutting mode\n"
1354 "Deconfigure enabled shortcutting through the area\n"
1355 "Deconfigure disabled shortcutting through the area\n")
1357 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1358 int idx_ipv4_number
= 2;
1359 struct ospf_area
*area
;
1360 struct in_addr area_id
;
1363 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1364 argv
[idx_ipv4_number
]->arg
);
1366 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1370 ospf_area_shortcut_unset(ospf
, area
);
1376 DEFUN (ospf_area_stub
,
1378 "area <A.B.C.D|(0-4294967295)> stub",
1379 "OSPF area parameters\n"
1380 "OSPF area ID in IP address format\n"
1381 "OSPF area ID as a decimal value\n"
1382 "Configure OSPF area as stub\n")
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 "First deconfigure all virtual link through this area\n");
1398 return CMD_WARNING_CONFIG_FAILED
;
1401 /* Flush the external LSAs from the specified area */
1402 ospf_flush_lsa_from_area(ospf
, area_id
, OSPF_AS_EXTERNAL_LSA
);
1403 ospf_area_no_summary_unset(ospf
, area_id
);
1408 DEFUN (ospf_area_stub_no_summary
,
1409 ospf_area_stub_no_summary_cmd
,
1410 "area <A.B.C.D|(0-4294967295)> stub no-summary",
1411 "OSPF stub parameters\n"
1412 "OSPF area ID in IP address format\n"
1413 "OSPF area ID as a decimal value\n"
1414 "Configure OSPF area as stub\n"
1415 "Do not inject inter-area routes into stub\n")
1417 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1418 int idx_ipv4_number
= 1;
1419 struct in_addr area_id
;
1422 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1423 argv
[idx_ipv4_number
]->arg
);
1425 ret
= ospf_area_stub_set(ospf
, area_id
);
1426 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1430 "%% Area cannot be stub as it contains a virtual link\n");
1431 return CMD_WARNING_CONFIG_FAILED
;
1434 ospf_area_no_summary_set(ospf
, area_id
);
1439 DEFUN (no_ospf_area_stub
,
1440 no_ospf_area_stub_cmd
,
1441 "no area <A.B.C.D|(0-4294967295)> stub",
1443 "OSPF area parameters\n"
1444 "OSPF area ID in IP address format\n"
1445 "OSPF area ID as a decimal value\n"
1446 "Configure OSPF area as stub\n")
1448 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1449 int idx_ipv4_number
= 2;
1450 struct in_addr area_id
;
1453 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1454 argv
[idx_ipv4_number
]->arg
);
1456 ospf_area_stub_unset(ospf
, area_id
);
1457 ospf_area_no_summary_unset(ospf
, area_id
);
1462 DEFUN (no_ospf_area_stub_no_summary
,
1463 no_ospf_area_stub_no_summary_cmd
,
1464 "no area <A.B.C.D|(0-4294967295)> stub no-summary",
1466 "OSPF area parameters\n"
1467 "OSPF area ID in IP address format\n"
1468 "OSPF area ID as a decimal value\n"
1469 "Configure OSPF area as stub\n"
1470 "Do not inject inter-area routes into area\n")
1472 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1473 int idx_ipv4_number
= 2;
1474 struct in_addr area_id
;
1477 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1478 argv
[idx_ipv4_number
]->arg
);
1479 ospf_area_no_summary_unset(ospf
, area_id
);
1484 static int ospf_area_nssa_cmd_handler(struct vty
*vty
, int argc
,
1485 struct cmd_token
**argv
, int cfg_nosum
,
1488 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1489 struct in_addr area_id
;
1492 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
, argv
[1]->arg
);
1494 ret
= ospf_area_nssa_set(ospf
, area_id
);
1495 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1499 "%% Area cannot be nssa as it contains a virtual link\n");
1500 return CMD_WARNING_CONFIG_FAILED
;
1504 if (strncmp(argv
[3]->text
, "translate-c", 11) == 0)
1505 ospf_area_nssa_translator_role_set(
1506 ospf
, area_id
, OSPF_NSSA_ROLE_CANDIDATE
);
1507 else if (strncmp(argv
[3]->text
, "translate-n", 11) == 0)
1508 ospf_area_nssa_translator_role_set(
1509 ospf
, area_id
, OSPF_NSSA_ROLE_NEVER
);
1510 else if (strncmp(argv
[3]->text
, "translate-a", 11) == 0)
1511 ospf_area_nssa_translator_role_set(
1512 ospf
, area_id
, OSPF_NSSA_ROLE_ALWAYS
);
1514 ospf_area_nssa_translator_role_set(ospf
, area_id
,
1515 OSPF_NSSA_ROLE_CANDIDATE
);
1520 ospf_area_no_summary_set(ospf
, area_id
);
1522 ospf_area_no_summary_unset(ospf
, area_id
);
1525 /* Flush the external LSA for the specified area */
1526 ospf_flush_lsa_from_area(ospf
, area_id
, OSPF_AS_EXTERNAL_LSA
);
1527 ospf_schedule_abr_task(ospf
);
1528 ospf_schedule_asbr_nssa_redist_update(ospf
);
1534 DEFUN (ospf_area_nssa_translate
,
1535 ospf_area_nssa_translate_cmd
,
1536 "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always>",
1537 "OSPF area parameters\n"
1538 "OSPF area ID in IP address format\n"
1539 "OSPF area ID as a decimal value\n"
1540 "Configure OSPF area as nssa\n"
1541 "Configure NSSA-ABR for translate election (default)\n"
1542 "Configure NSSA-ABR to never translate\n"
1543 "Configure NSSA-ABR to always translate\n")
1545 return ospf_area_nssa_cmd_handler(vty
, argc
, argv
, 0, 0);
1548 DEFUN (ospf_area_nssa
,
1550 "area <A.B.C.D|(0-4294967295)> nssa",
1551 "OSPF area parameters\n"
1552 "OSPF area ID in IP address format\n"
1553 "OSPF area ID as a decimal value\n"
1554 "Configure OSPF area as nssa\n")
1556 return ospf_area_nssa_cmd_handler(vty
, argc
, argv
, 0, 0);
1559 DEFUN(ospf_area_nssa_suppress_fa
, ospf_area_nssa_suppress_fa_cmd
,
1560 "area <A.B.C.D|(0-4294967295)> nssa suppress-fa",
1561 "OSPF area parameters\n"
1562 "OSPF area ID in IP address format\n"
1563 "OSPF area ID as a decimal value\n"
1564 "Configure OSPF area as nssa\n"
1565 "Suppress forwarding address\n")
1567 int idx_ipv4_number
= 1;
1568 struct in_addr area_id
;
1571 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1572 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1573 argv
[idx_ipv4_number
]->arg
);
1575 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1577 ospf_area_nssa_suppress_fa_set(ospf
, area_id
);
1579 ospf_schedule_abr_task(ospf
);
1584 DEFUN(no_ospf_area_nssa_suppress_fa
, no_ospf_area_nssa_suppress_fa_cmd
,
1585 "no area <A.B.C.D|(0-4294967295)> nssa suppress-fa",
1587 "OSPF area parameters\n"
1588 "OSPF area ID in IP address format\n"
1589 "OSPF area ID as a decimal value\n"
1590 "Configure OSPF area as nssa\n"
1591 "Suppress forwarding address\n")
1593 int idx_ipv4_number
= 2;
1594 struct in_addr area_id
;
1597 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1599 VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id
, format
,
1600 argv
[idx_ipv4_number
]->arg
);
1602 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1604 ospf_area_nssa_suppress_fa_unset(ospf
, area_id
);
1606 ospf_schedule_abr_task(ospf
);
1611 DEFUN (ospf_area_nssa_no_summary
,
1612 ospf_area_nssa_no_summary_cmd
,
1613 "area <A.B.C.D|(0-4294967295)> nssa no-summary",
1614 "OSPF area parameters\n"
1615 "OSPF area ID in IP address format\n"
1616 "OSPF area ID as a decimal value\n"
1617 "Configure OSPF area as nssa\n"
1618 "Do not inject inter-area routes into nssa\n")
1620 int idx_ipv4_number
= 1;
1621 struct in_addr area_id
;
1624 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1625 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1626 argv
[idx_ipv4_number
]->arg
);
1628 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1630 ospf_area_nssa_no_summary_set(ospf
, area_id
);
1632 ospf_schedule_abr_task(ospf
);
1637 DEFUN (no_ospf_area_nssa_no_summary
,
1638 no_ospf_area_nssa_no_summary_cmd
,
1639 "no area <A.B.C.D|(0-4294967295)> nssa no-summary",
1641 "OSPF area parameters\n"
1642 "OSPF area ID in IP address format\n"
1643 "OSPF area ID as a decimal value\n"
1644 "Configure OSPF area as nssa\n"
1645 "Do not inject inter-area routes into nssa\n")
1647 int idx_ipv4_number
= 2;
1648 struct in_addr area_id
;
1651 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1653 VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id
, format
,
1654 argv
[idx_ipv4_number
]->arg
);
1656 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1658 ospf_area_no_summary_unset(ospf
, area_id
);
1660 ospf_schedule_abr_task(ospf
);
1665 DEFUN (no_ospf_area_nssa
,
1666 no_ospf_area_nssa_cmd
,
1667 "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always>]",
1669 "OSPF area parameters\n"
1670 "OSPF area ID in IP address format\n"
1671 "OSPF area ID as a decimal value\n"
1672 "Configure OSPF area as nssa\n"
1673 "Configure NSSA-ABR for translate election (default)\n"
1674 "Configure NSSA-ABR to never translate\n"
1675 "Configure NSSA-ABR to always translate\n")
1677 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1678 int idx_ipv4_number
= 2;
1679 struct in_addr area_id
;
1682 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1683 argv
[idx_ipv4_number
]->arg
);
1685 /* Flush the NSSA LSA for the specified area */
1686 ospf_flush_lsa_from_area(ospf
, area_id
, OSPF_AS_NSSA_LSA
);
1687 ospf_area_nssa_unset(ospf
, area_id
, argc
);
1689 ospf_schedule_abr_task(ospf
);
1695 DEFUN (ospf_area_default_cost
,
1696 ospf_area_default_cost_cmd
,
1697 "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1698 "OSPF area parameters\n"
1699 "OSPF area ID in IP address format\n"
1700 "OSPF area ID as a decimal value\n"
1701 "Set the summary-default cost of a NSSA or stub area\n"
1702 "Stub's advertised default summary cost\n")
1704 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1705 int idx_ipv4_number
= 1;
1707 struct ospf_area
*area
;
1708 struct in_addr area_id
;
1711 struct prefix_ipv4 p
;
1713 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1714 argv
[idx_ipv4_number
]->arg
);
1715 cost
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1717 area
= ospf_area_get(ospf
, area_id
);
1718 ospf_area_display_format_set(ospf
, area
, format
);
1720 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1721 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1722 return CMD_WARNING_CONFIG_FAILED
;
1725 area
->default_cost
= cost
;
1728 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1730 if (IS_DEBUG_OSPF_EVENT
)
1732 "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4",
1734 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1739 DEFUN (no_ospf_area_default_cost
,
1740 no_ospf_area_default_cost_cmd
,
1741 "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1743 "OSPF area parameters\n"
1744 "OSPF area ID in IP address format\n"
1745 "OSPF area ID as a decimal value\n"
1746 "Set the summary-default cost of a NSSA or stub area\n"
1747 "Stub's advertised default summary cost\n")
1749 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1750 int idx_ipv4_number
= 2;
1751 struct ospf_area
*area
;
1752 struct in_addr area_id
;
1754 struct prefix_ipv4 p
;
1756 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1757 argv
[idx_ipv4_number
]->arg
);
1759 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1763 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1764 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1765 return CMD_WARNING_CONFIG_FAILED
;
1768 area
->default_cost
= 1;
1771 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1773 if (IS_DEBUG_OSPF_EVENT
)
1775 "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4",
1777 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1780 ospf_area_check_free(ospf
, area_id
);
1785 DEFUN (ospf_area_export_list
,
1786 ospf_area_export_list_cmd
,
1787 "area <A.B.C.D|(0-4294967295)> export-list NAME",
1788 "OSPF area parameters\n"
1789 "OSPF area ID in IP address format\n"
1790 "OSPF area ID as a decimal value\n"
1791 "Set the filter for networks announced to other areas\n"
1792 "Name of the access-list\n")
1794 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1795 int idx_ipv4_number
= 1;
1796 struct ospf_area
*area
;
1797 struct in_addr area_id
;
1800 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1802 area
= ospf_area_get(ospf
, area_id
);
1803 ospf_area_display_format_set(ospf
, area
, format
);
1804 ospf_area_export_list_set(ospf
, area
, argv
[3]->arg
);
1809 DEFUN (no_ospf_area_export_list
,
1810 no_ospf_area_export_list_cmd
,
1811 "no area <A.B.C.D|(0-4294967295)> export-list NAME",
1813 "OSPF area parameters\n"
1814 "OSPF area ID in IP address format\n"
1815 "OSPF area ID as a decimal value\n"
1816 "Unset the filter for networks announced to other areas\n"
1817 "Name of the access-list\n")
1819 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1820 int idx_ipv4_number
= 2;
1821 struct ospf_area
*area
;
1822 struct in_addr area_id
;
1825 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1827 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1831 ospf_area_export_list_unset(ospf
, area
);
1837 DEFUN (ospf_area_import_list
,
1838 ospf_area_import_list_cmd
,
1839 "area <A.B.C.D|(0-4294967295)> import-list NAME",
1840 "OSPF area parameters\n"
1841 "OSPF area ID in IP address format\n"
1842 "OSPF area ID as a decimal value\n"
1843 "Set the filter for networks from other areas announced to the specified one\n"
1844 "Name of the access-list\n")
1846 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1847 int idx_ipv4_number
= 1;
1848 struct ospf_area
*area
;
1849 struct in_addr area_id
;
1852 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1854 area
= ospf_area_get(ospf
, area_id
);
1855 ospf_area_display_format_set(ospf
, area
, format
);
1856 ospf_area_import_list_set(ospf
, area
, argv
[3]->arg
);
1861 DEFUN (no_ospf_area_import_list
,
1862 no_ospf_area_import_list_cmd
,
1863 "no area <A.B.C.D|(0-4294967295)> import-list NAME",
1865 "OSPF area parameters\n"
1866 "OSPF area ID in IP address format\n"
1867 "OSPF area ID as a decimal value\n"
1868 "Unset the filter for networks announced to other areas\n"
1869 "Name of the access-list\n")
1871 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1872 int idx_ipv4_number
= 2;
1873 struct ospf_area
*area
;
1874 struct in_addr area_id
;
1877 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1879 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1883 ospf_area_import_list_unset(ospf
, area
);
1888 DEFUN (ospf_area_filter_list
,
1889 ospf_area_filter_list_cmd
,
1890 "area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>",
1891 "OSPF area parameters\n"
1892 "OSPF area ID in IP address format\n"
1893 "OSPF area ID as a decimal value\n"
1894 "Filter networks between OSPF areas\n"
1895 "Filter prefixes between OSPF areas\n"
1896 "Name of an IP prefix-list\n"
1897 "Filter networks sent to this area\n"
1898 "Filter networks sent from this area\n")
1900 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1901 int idx_ipv4_number
= 1;
1904 struct ospf_area
*area
;
1905 struct in_addr area_id
;
1906 struct prefix_list
*plist
;
1909 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1911 area
= ospf_area_get(ospf
, area_id
);
1912 ospf_area_display_format_set(ospf
, area
, format
);
1913 plist
= prefix_list_lookup(AFI_IP
, argv
[idx_word
]->arg
);
1914 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1915 PREFIX_LIST_IN(area
) = plist
;
1916 if (PREFIX_NAME_IN(area
))
1917 free(PREFIX_NAME_IN(area
));
1919 PREFIX_NAME_IN(area
) = strdup(argv
[idx_word
]->arg
);
1920 ospf_schedule_abr_task(ospf
);
1922 PREFIX_LIST_OUT(area
) = plist
;
1923 if (PREFIX_NAME_OUT(area
))
1924 free(PREFIX_NAME_OUT(area
));
1926 PREFIX_NAME_OUT(area
) = strdup(argv
[idx_word
]->arg
);
1927 ospf_schedule_abr_task(ospf
);
1933 DEFUN (no_ospf_area_filter_list
,
1934 no_ospf_area_filter_list_cmd
,
1935 "no area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>",
1937 "OSPF area parameters\n"
1938 "OSPF area ID in IP address format\n"
1939 "OSPF area ID as a decimal value\n"
1940 "Filter networks between OSPF areas\n"
1941 "Filter prefixes between OSPF areas\n"
1942 "Name of an IP prefix-list\n"
1943 "Filter networks sent to this area\n"
1944 "Filter networks sent from this area\n")
1946 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1947 int idx_ipv4_number
= 2;
1950 struct ospf_area
*area
;
1951 struct in_addr area_id
;
1954 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1956 if ((area
= ospf_area_lookup_by_area_id(ospf
, area_id
)) == NULL
)
1959 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1960 if (PREFIX_NAME_IN(area
))
1961 if (strcmp(PREFIX_NAME_IN(area
), argv
[idx_word
]->arg
)
1965 PREFIX_LIST_IN(area
) = NULL
;
1966 if (PREFIX_NAME_IN(area
))
1967 free(PREFIX_NAME_IN(area
));
1969 PREFIX_NAME_IN(area
) = NULL
;
1971 ospf_schedule_abr_task(ospf
);
1973 if (PREFIX_NAME_OUT(area
))
1974 if (strcmp(PREFIX_NAME_OUT(area
), argv
[idx_word
]->arg
)
1978 PREFIX_LIST_OUT(area
) = NULL
;
1979 if (PREFIX_NAME_OUT(area
))
1980 free(PREFIX_NAME_OUT(area
));
1982 PREFIX_NAME_OUT(area
) = NULL
;
1984 ospf_schedule_abr_task(ospf
);
1991 DEFUN (ospf_area_authentication_message_digest
,
1992 ospf_area_authentication_message_digest_cmd
,
1993 "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest",
1995 "OSPF area parameters\n"
1996 "OSPF area ID in IP address format\n"
1997 "OSPF area ID as a decimal value\n"
1998 "Enable authentication\n"
1999 "Use message-digest authentication\n")
2001 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2003 struct ospf_area
*area
;
2004 struct in_addr area_id
;
2007 argv_find(argv
, argc
, "area", &idx
);
2008 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx
+ 1]->arg
);
2010 area
= ospf_area_get(ospf
, area_id
);
2011 ospf_area_display_format_set(ospf
, area
, format
);
2012 area
->auth_type
= strmatch(argv
[0]->text
, "no")
2014 : OSPF_AUTH_CRYPTOGRAPHIC
;
2019 DEFUN (ospf_area_authentication
,
2020 ospf_area_authentication_cmd
,
2021 "area <A.B.C.D|(0-4294967295)> authentication",
2022 "OSPF area parameters\n"
2023 "OSPF area ID in IP address format\n"
2024 "OSPF area ID as a decimal value\n"
2025 "Enable authentication\n")
2027 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2028 int idx_ipv4_number
= 1;
2029 struct ospf_area
*area
;
2030 struct in_addr area_id
;
2033 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
2035 area
= ospf_area_get(ospf
, area_id
);
2036 ospf_area_display_format_set(ospf
, area
, format
);
2037 area
->auth_type
= OSPF_AUTH_SIMPLE
;
2042 DEFUN (no_ospf_area_authentication
,
2043 no_ospf_area_authentication_cmd
,
2044 "no area <A.B.C.D|(0-4294967295)> authentication",
2046 "OSPF area parameters\n"
2047 "OSPF area ID in IP address format\n"
2048 "OSPF area ID as a decimal value\n"
2049 "Enable authentication\n")
2051 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2052 int idx_ipv4_number
= 2;
2053 struct ospf_area
*area
;
2054 struct in_addr area_id
;
2057 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
2059 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
2063 area
->auth_type
= OSPF_AUTH_NULL
;
2065 ospf_area_check_free(ospf
, area_id
);
2071 DEFUN (ospf_abr_type
,
2073 "ospf abr-type <cisco|ibm|shortcut|standard>",
2074 "OSPF specific commands\n"
2075 "Set OSPF ABR type\n"
2076 "Alternative ABR, cisco implementation\n"
2077 "Alternative ABR, IBM implementation\n"
2079 "Standard behavior (RFC2328)\n")
2081 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2083 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2085 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2086 abr_type
= OSPF_ABR_CISCO
;
2087 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2088 abr_type
= OSPF_ABR_IBM
;
2089 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2090 abr_type
= OSPF_ABR_SHORTCUT
;
2091 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2092 abr_type
= OSPF_ABR_STAND
;
2094 return CMD_WARNING_CONFIG_FAILED
;
2096 /* If ABR type value is changed, schedule ABR task. */
2097 if (ospf
->abr_type
!= abr_type
) {
2098 ospf
->abr_type
= abr_type
;
2099 ospf_schedule_abr_task(ospf
);
2105 DEFUN (no_ospf_abr_type
,
2106 no_ospf_abr_type_cmd
,
2107 "no ospf abr-type <cisco|ibm|shortcut|standard>",
2109 "OSPF specific commands\n"
2110 "Set OSPF ABR type\n"
2111 "Alternative ABR, cisco implementation\n"
2112 "Alternative ABR, IBM implementation\n"
2116 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2118 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2120 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2121 abr_type
= OSPF_ABR_CISCO
;
2122 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2123 abr_type
= OSPF_ABR_IBM
;
2124 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2125 abr_type
= OSPF_ABR_SHORTCUT
;
2126 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2127 abr_type
= OSPF_ABR_STAND
;
2129 return CMD_WARNING_CONFIG_FAILED
;
2131 /* If ABR type value is changed, schedule ABR task. */
2132 if (ospf
->abr_type
== abr_type
) {
2133 ospf
->abr_type
= OSPF_ABR_DEFAULT
;
2134 ospf_schedule_abr_task(ospf
);
2140 DEFUN (ospf_log_adjacency_changes
,
2141 ospf_log_adjacency_changes_cmd
,
2142 "log-adjacency-changes",
2143 "Log changes in adjacency state\n")
2145 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2147 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2148 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2152 DEFUN (ospf_log_adjacency_changes_detail
,
2153 ospf_log_adjacency_changes_detail_cmd
,
2154 "log-adjacency-changes detail",
2155 "Log changes in adjacency state\n"
2156 "Log all state changes\n")
2158 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2160 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2161 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2165 DEFUN (no_ospf_log_adjacency_changes
,
2166 no_ospf_log_adjacency_changes_cmd
,
2167 "no log-adjacency-changes",
2169 "Log changes in adjacency state\n")
2171 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2173 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2174 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2178 DEFUN (no_ospf_log_adjacency_changes_detail
,
2179 no_ospf_log_adjacency_changes_detail_cmd
,
2180 "no log-adjacency-changes detail",
2182 "Log changes in adjacency state\n"
2183 "Log all state changes\n")
2185 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2187 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2191 DEFUN (ospf_compatible_rfc1583
,
2192 ospf_compatible_rfc1583_cmd
,
2193 "compatible rfc1583",
2194 "OSPF compatibility list\n"
2195 "compatible with RFC 1583\n")
2197 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2199 if (!CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2200 SET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2201 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2206 DEFUN (no_ospf_compatible_rfc1583
,
2207 no_ospf_compatible_rfc1583_cmd
,
2208 "no compatible rfc1583",
2210 "OSPF compatibility list\n"
2211 "compatible with RFC 1583\n")
2213 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2215 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2216 UNSET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2217 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2222 ALIAS(ospf_compatible_rfc1583
, ospf_rfc1583_flag_cmd
,
2223 "ospf rfc1583compatibility",
2224 "OSPF specific commands\n"
2225 "Enable the RFC1583Compatibility flag\n")
2227 ALIAS(no_ospf_compatible_rfc1583
, no_ospf_rfc1583_flag_cmd
,
2228 "no ospf rfc1583compatibility", NO_STR
2229 "OSPF specific commands\n"
2230 "Disable the RFC1583Compatibility flag\n")
2232 static int ospf_timers_spf_set(struct vty
*vty
, unsigned int delay
,
2233 unsigned int hold
, unsigned int max
)
2235 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2237 ospf
->spf_delay
= delay
;
2238 ospf
->spf_holdtime
= hold
;
2239 ospf
->spf_max_holdtime
= max
;
2244 DEFUN (ospf_timers_min_ls_interval
,
2245 ospf_timers_min_ls_interval_cmd
,
2246 "timers throttle lsa all (0-5000)",
2247 "Adjust routing timers\n"
2248 "Throttling adaptive timer\n"
2249 "LSA delay between transmissions\n"
2251 "Delay (msec) between sending LSAs\n")
2253 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2255 unsigned int interval
;
2258 vty_out(vty
, "Insufficient arguments\n");
2259 return CMD_WARNING_CONFIG_FAILED
;
2262 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2264 ospf
->min_ls_interval
= interval
;
2269 DEFUN (no_ospf_timers_min_ls_interval
,
2270 no_ospf_timers_min_ls_interval_cmd
,
2271 "no timers throttle lsa all [(0-5000)]",
2273 "Adjust routing timers\n"
2274 "Throttling adaptive timer\n"
2275 "LSA delay between transmissions\n"
2277 "Delay (msec) between sending LSAs\n")
2279 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2280 ospf
->min_ls_interval
= OSPF_MIN_LS_INTERVAL
;
2285 DEFUN (ospf_timers_throttle_spf
,
2286 ospf_timers_throttle_spf_cmd
,
2287 "timers throttle spf (0-600000) (0-600000) (0-600000)",
2288 "Adjust routing timers\n"
2289 "Throttling adaptive timer\n"
2291 "Delay (msec) from first change received till SPF calculation\n"
2292 "Initial hold time (msec) between consecutive SPF calculations\n"
2293 "Maximum hold time (msec)\n")
2296 int idx_number_2
= 4;
2297 int idx_number_3
= 5;
2298 unsigned int delay
, hold
, max
;
2301 vty_out(vty
, "Insufficient arguments\n");
2302 return CMD_WARNING_CONFIG_FAILED
;
2305 delay
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2306 hold
= strtoul(argv
[idx_number_2
]->arg
, NULL
, 10);
2307 max
= strtoul(argv
[idx_number_3
]->arg
, NULL
, 10);
2309 return ospf_timers_spf_set(vty
, delay
, hold
, max
);
2312 DEFUN (no_ospf_timers_throttle_spf
,
2313 no_ospf_timers_throttle_spf_cmd
,
2314 "no timers throttle spf [(0-600000)(0-600000)(0-600000)]",
2316 "Adjust routing timers\n"
2317 "Throttling adaptive timer\n"
2319 "Delay (msec) from first change received till SPF calculation\n"
2320 "Initial hold time (msec) between consecutive SPF calculations\n"
2321 "Maximum hold time (msec)\n")
2323 return ospf_timers_spf_set(vty
, OSPF_SPF_DELAY_DEFAULT
,
2324 OSPF_SPF_HOLDTIME_DEFAULT
,
2325 OSPF_SPF_MAX_HOLDTIME_DEFAULT
);
2329 DEFUN (ospf_timers_lsa_min_arrival
,
2330 ospf_timers_lsa_min_arrival_cmd
,
2331 "timers lsa min-arrival (0-600000)",
2332 "Adjust routing timers\n"
2334 "Minimum delay in receiving new version of a LSA\n"
2335 "Delay in milliseconds\n")
2337 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2338 ospf
->min_ls_arrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2342 DEFUN (no_ospf_timers_lsa_min_arrival
,
2343 no_ospf_timers_lsa_min_arrival_cmd
,
2344 "no timers lsa min-arrival [(0-600000)]",
2346 "Adjust routing timers\n"
2348 "Minimum delay in receiving new version of a LSA\n"
2349 "Delay in milliseconds\n")
2351 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2352 unsigned int minarrival
;
2355 minarrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2357 if (ospf
->min_ls_arrival
!= minarrival
2358 || minarrival
== OSPF_MIN_LS_ARRIVAL
)
2362 ospf
->min_ls_arrival
= OSPF_MIN_LS_ARRIVAL
;
2367 DEFUN (ospf_neighbor
,
2369 "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]",
2371 "Neighbor IP address\n"
2372 "Neighbor Priority\n"
2374 "Dead Neighbor Polling interval\n"
2377 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2381 struct in_addr nbr_addr
;
2382 unsigned int priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2383 unsigned int interval
= OSPF_POLL_INTERVAL_DEFAULT
;
2385 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2386 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2387 return CMD_WARNING_CONFIG_FAILED
;
2391 priority
= strtoul(argv
[idx_pri
]->arg
, NULL
, 10);
2394 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2396 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2399 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2402 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2407 DEFUN (ospf_neighbor_poll_interval
,
2408 ospf_neighbor_poll_interval_cmd
,
2409 "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2411 "Neighbor IP address\n"
2412 "Dead Neighbor Polling interval\n"
2414 "OSPF priority of non-broadcast neighbor\n"
2417 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2421 struct in_addr nbr_addr
;
2422 unsigned int priority
;
2423 unsigned int interval
;
2425 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2426 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2427 return CMD_WARNING_CONFIG_FAILED
;
2430 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2432 priority
= argc
> 4 ? strtoul(argv
[idx_pri
]->arg
, NULL
, 10)
2433 : OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2435 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2436 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2439 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2444 DEFUN (no_ospf_neighbor
,
2445 no_ospf_neighbor_cmd
,
2446 "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]",
2449 "Neighbor IP address\n"
2450 "Neighbor Priority\n"
2452 "Dead Neighbor Polling interval\n"
2455 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2457 struct in_addr nbr_addr
;
2459 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2460 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2461 return CMD_WARNING_CONFIG_FAILED
;
2464 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2469 DEFUN (no_ospf_neighbor_poll
,
2470 no_ospf_neighbor_poll_cmd
,
2471 "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2474 "Neighbor IP address\n"
2475 "Dead Neighbor Polling interval\n"
2477 "Neighbor Priority\n"
2480 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2482 struct in_addr nbr_addr
;
2484 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2485 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2486 return CMD_WARNING_CONFIG_FAILED
;
2489 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2494 DEFUN (ospf_refresh_timer
,
2495 ospf_refresh_timer_cmd
,
2496 "refresh timer (10-1800)",
2497 "Adjust refresh parameters\n"
2498 "Set refresh timer\n"
2499 "Timer value in seconds\n")
2501 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2503 unsigned int interval
;
2505 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2506 interval
= (interval
/ OSPF_LSA_REFRESHER_GRANULARITY
)
2507 * OSPF_LSA_REFRESHER_GRANULARITY
;
2509 ospf_timers_refresh_set(ospf
, interval
);
2514 DEFUN (no_ospf_refresh_timer
,
2515 no_ospf_refresh_timer_val_cmd
,
2516 "no refresh timer [(10-1800)]",
2518 "Adjust refresh parameters\n"
2519 "Unset refresh timer\n"
2520 "Timer value in seconds\n")
2522 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2524 unsigned int interval
;
2527 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2529 if (ospf
->lsa_refresh_interval
!= interval
2530 || interval
== OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
2534 ospf_timers_refresh_unset(ospf
);
2540 DEFUN (ospf_auto_cost_reference_bandwidth
,
2541 ospf_auto_cost_reference_bandwidth_cmd
,
2542 "auto-cost reference-bandwidth (1-4294967)",
2543 "Calculate OSPF interface cost according to bandwidth\n"
2544 "Use reference bandwidth method to assign OSPF cost\n"
2545 "The reference bandwidth in terms of Mbits per second\n")
2547 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2548 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2551 struct interface
*ifp
;
2553 refbw
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2554 if (refbw
< 1 || refbw
> 4294967) {
2555 vty_out(vty
, "reference-bandwidth value is invalid\n");
2556 return CMD_WARNING_CONFIG_FAILED
;
2559 /* If reference bandwidth is changed. */
2560 if ((refbw
) == ospf
->ref_bandwidth
)
2563 ospf
->ref_bandwidth
= refbw
;
2564 FOR_ALL_INTERFACES (vrf
, ifp
)
2565 ospf_if_recalculate_output_cost(ifp
);
2570 DEFUN (no_ospf_auto_cost_reference_bandwidth
,
2571 no_ospf_auto_cost_reference_bandwidth_cmd
,
2572 "no auto-cost reference-bandwidth [(1-4294967)]",
2574 "Calculate OSPF interface cost according to bandwidth\n"
2575 "Use reference bandwidth method to assign OSPF cost\n"
2576 "The reference bandwidth in terms of Mbits per second\n")
2578 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2579 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2580 struct interface
*ifp
;
2582 if (ospf
->ref_bandwidth
== OSPF_DEFAULT_REF_BANDWIDTH
)
2585 ospf
->ref_bandwidth
= OSPF_DEFAULT_REF_BANDWIDTH
;
2586 vty_out(vty
, "%% OSPF: Reference bandwidth is changed.\n");
2588 " Please ensure reference bandwidth is consistent across all routers\n");
2590 FOR_ALL_INTERFACES (vrf
, ifp
)
2591 ospf_if_recalculate_output_cost(ifp
);
2596 DEFUN (ospf_write_multiplier
,
2597 ospf_write_multiplier_cmd
,
2598 "ospf write-multiplier (1-100)",
2599 "OSPF specific commands\n"
2600 "Write multiplier\n"
2601 "Maximum number of interface serviced per write\n")
2603 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2605 uint32_t write_oi_count
;
2612 write_oi_count
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2613 if (write_oi_count
< 1 || write_oi_count
> 100) {
2614 vty_out(vty
, "write-multiplier value is invalid\n");
2615 return CMD_WARNING_CONFIG_FAILED
;
2618 ospf
->write_oi_count
= write_oi_count
;
2622 ALIAS(ospf_write_multiplier
, write_multiplier_cmd
, "write-multiplier (1-100)",
2623 "Write multiplier\n"
2624 "Maximum number of interface serviced per write\n")
2626 DEFUN (no_ospf_write_multiplier
,
2627 no_ospf_write_multiplier_cmd
,
2628 "no ospf write-multiplier (1-100)",
2630 "OSPF specific commands\n"
2631 "Write multiplier\n"
2632 "Maximum number of interface serviced per write\n")
2634 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2636 ospf
->write_oi_count
= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
;
2640 ALIAS(no_ospf_write_multiplier
, no_write_multiplier_cmd
,
2641 "no write-multiplier (1-100)", NO_STR
2642 "Write multiplier\n"
2643 "Maximum number of interface serviced per write\n")
2645 DEFUN(ospf_ti_lfa
, ospf_ti_lfa_cmd
, "fast-reroute ti-lfa [node-protection]",
2646 "Fast Reroute for MPLS and IP resilience\n"
2647 "Topology Independent LFA (Loop-Free Alternate)\n"
2648 "TI-LFA node protection (default is link protection)\n")
2650 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2652 ospf
->ti_lfa_enabled
= true;
2655 ospf
->ti_lfa_protection_type
= OSPF_TI_LFA_NODE_PROTECTION
;
2657 ospf
->ti_lfa_protection_type
= OSPF_TI_LFA_LINK_PROTECTION
;
2659 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2664 DEFUN(no_ospf_ti_lfa
, no_ospf_ti_lfa_cmd
,
2665 "no fast-reroute ti-lfa [node-protection]",
2667 "Fast Reroute for MPLS and IP resilience\n"
2668 "Topology Independent LFA (Loop-Free Alternate)\n"
2669 "TI-LFA node protection (default is link protection)\n")
2671 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2673 ospf
->ti_lfa_enabled
= false;
2675 ospf
->ti_lfa_protection_type
= OSPF_TI_LFA_UNDEFINED_PROTECTION
;
2677 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2682 static void ospf_maxpath_set(struct vty
*vty
, struct ospf
*ospf
, uint16_t paths
)
2684 if (ospf
->max_multipath
== paths
)
2687 ospf
->max_multipath
= paths
;
2689 /* Send deletion notification to zebra to delete all
2690 * ospf specific routes and reinitiat SPF to reflect
2691 * the new max multipath.
2693 ospf_restart_spf(ospf
);
2696 /* Ospf Maximum multiple paths config support */
2697 DEFUN (ospf_max_multipath
,
2698 ospf_max_multipath_cmd
,
2699 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM
),
2700 "Max no of multiple paths for ECMP support\n"
2701 "Number of paths\n")
2703 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2707 maxpaths
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2709 ospf_maxpath_set(vty
, ospf
, maxpaths
);
2713 DEFUN (no_ospf_max_multipath
,
2714 no_ospf_max_multipath_cmd
,
2717 "Max no of multiple paths for ECMP support\n")
2719 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2720 uint16_t maxpaths
= MULTIPATH_NUM
;
2722 ospf_maxpath_set(vty
, ospf
, maxpaths
);
2726 static const char *const ospf_abr_type_descr_str
[] = {
2727 "Unknown", "Standard (RFC2328)", "Alternative IBM",
2728 "Alternative Cisco", "Alternative Shortcut"
2731 static const char *const ospf_shortcut_mode_descr_str
[] = {
2732 "Default", "Enabled", "Disabled"
2735 static void show_ip_ospf_area(struct vty
*vty
, struct ospf_area
*area
,
2736 json_object
*json_areas
, bool use_json
)
2738 json_object
*json_area
= NULL
;
2739 char buf
[PREFIX_STRLEN
];
2742 json_area
= json_object_new_object();
2746 vty_out(vty
, " Area ID: %pI4", &area
->area_id
);
2748 /* Show Area type/mode. */
2749 if (OSPF_IS_AREA_BACKBONE(area
)) {
2751 json_object_boolean_true_add(json_area
, "backbone");
2753 vty_out(vty
, " (Backbone)\n");
2756 if (area
->external_routing
== OSPF_AREA_STUB
) {
2757 if (area
->no_summary
)
2758 json_object_boolean_true_add(
2759 json_area
, "stubNoSummary");
2760 if (area
->shortcut_configured
)
2761 json_object_boolean_true_add(
2762 json_area
, "stubShortcut");
2763 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
2764 if (area
->no_summary
)
2765 json_object_boolean_true_add(
2766 json_area
, "nssaNoSummary");
2767 if (area
->shortcut_configured
)
2768 json_object_boolean_true_add(
2769 json_area
, "nssaShortcut");
2772 json_object_string_add(
2773 json_area
, "shortcuttingMode",
2774 ospf_shortcut_mode_descr_str
2775 [area
->shortcut_configured
]);
2776 if (area
->shortcut_capability
)
2777 json_object_boolean_true_add(json_area
,
2780 if (area
->external_routing
== OSPF_AREA_STUB
)
2781 vty_out(vty
, " (Stub%s%s)",
2782 area
->no_summary
? ", no summary" : "",
2783 area
->shortcut_configured
? "; " : "");
2784 else if (area
->external_routing
== OSPF_AREA_NSSA
)
2785 vty_out(vty
, " (NSSA%s%s)",
2786 area
->no_summary
? ", no summary" : "",
2787 area
->shortcut_configured
? "; " : "");
2790 vty_out(vty
, " Shortcutting mode: %s",
2791 ospf_shortcut_mode_descr_str
2792 [area
->shortcut_configured
]);
2793 vty_out(vty
, ", S-bit consensus: %s\n",
2794 area
->shortcut_capability
? "ok" : "no");
2798 /* Show number of interfaces */
2800 json_object_int_add(json_area
, "areaIfTotalCounter",
2801 listcount(area
->oiflist
));
2802 json_object_int_add(json_area
, "areaIfActiveCounter",
2806 " Number of interfaces in this area: Total: %d, Active: %d\n",
2807 listcount(area
->oiflist
), area
->act_ints
);
2809 if (area
->external_routing
== OSPF_AREA_NSSA
) {
2811 json_object_boolean_true_add(json_area
, "nssa");
2812 if (!IS_OSPF_ABR(area
->ospf
))
2813 json_object_boolean_false_add(json_area
, "abr");
2814 else if (area
->NSSATranslatorState
) {
2815 json_object_boolean_true_add(json_area
, "abr");
2816 if (area
->NSSATranslatorRole
2817 == OSPF_NSSA_ROLE_CANDIDATE
)
2818 json_object_boolean_true_add(
2820 "nssaTranslatorElected");
2821 else if (area
->NSSATranslatorRole
2822 == OSPF_NSSA_ROLE_ALWAYS
)
2823 json_object_boolean_true_add(
2825 "nssaTranslatorAlways");
2827 json_object_boolean_true_add(
2829 "nssaTranslatorNever");
2831 json_object_boolean_true_add(json_area
, "abr");
2832 if (area
->NSSATranslatorRole
2833 == OSPF_NSSA_ROLE_CANDIDATE
)
2834 json_object_boolean_false_add(
2836 "nssaTranslatorElected");
2838 json_object_boolean_true_add(
2840 "nssaTranslatorNever");
2844 " It is an NSSA configuration.\n Elected NSSA/ABR performs type-7/type-5 LSA translation.\n");
2845 if (!IS_OSPF_ABR(area
->ospf
))
2847 " It is not ABR, therefore not Translator.\n");
2848 else if (area
->NSSATranslatorState
) {
2849 vty_out(vty
, " We are an ABR and ");
2850 if (area
->NSSATranslatorRole
2851 == OSPF_NSSA_ROLE_CANDIDATE
)
2853 "the NSSA Elected Translator.\n");
2854 else if (area
->NSSATranslatorRole
2855 == OSPF_NSSA_ROLE_ALWAYS
)
2857 "always an NSSA Translator.\n");
2860 "never an NSSA Translator.\n");
2862 vty_out(vty
, " We are an ABR, but ");
2863 if (area
->NSSATranslatorRole
2864 == OSPF_NSSA_ROLE_CANDIDATE
)
2866 "not the NSSA Elected Translator.\n");
2869 "never an NSSA Translator.\n");
2874 /* Stub-router state for this area */
2875 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
)) {
2876 char timebuf
[OSPF_TIME_DUMP_SIZE
];
2879 json_object_boolean_true_add(
2880 json_area
, "originStubMaxDistRouterLsa");
2881 if (CHECK_FLAG(area
->stub_router_state
,
2882 OSPF_AREA_ADMIN_STUB_ROUTED
))
2883 json_object_boolean_true_add(
2884 json_area
, "indefiniteActiveAdmin");
2885 if (area
->t_stub_router
) {
2889 &area
->t_stub_router
->u
.sands
,
2892 json_object_int_add(
2894 "activeStartupRemainderMsecs",
2899 " Originating stub / maximum-distance Router-LSA\n");
2900 if (CHECK_FLAG(area
->stub_router_state
,
2901 OSPF_AREA_ADMIN_STUB_ROUTED
))
2903 " Administratively activated (indefinitely)\n");
2904 if (area
->t_stub_router
)
2906 " Active from startup, %s remaining\n",
2907 ospf_timer_dump(area
->t_stub_router
,
2914 /* Show number of fully adjacent neighbors. */
2915 json_object_int_add(json_area
, "nbrFullAdjacentCounter",
2918 /* Show authentication type. */
2919 if (area
->auth_type
== OSPF_AUTH_NULL
)
2920 json_object_string_add(json_area
, "authentication",
2921 "authenticationNone");
2922 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2923 json_object_string_add(json_area
, "authentication",
2924 "authenticationSimplePassword");
2925 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2926 json_object_string_add(json_area
, "authentication",
2927 "authenticationMessageDigest");
2929 if (!OSPF_IS_AREA_BACKBONE(area
))
2930 json_object_int_add(json_area
,
2931 "virtualAdjacenciesPassingCounter",
2934 /* Show SPF calculation times. */
2935 json_object_int_add(json_area
, "spfExecutedCounter",
2936 area
->spf_calculation
);
2937 json_object_int_add(json_area
, "lsaNumber", area
->lsdb
->total
);
2938 json_object_int_add(
2939 json_area
, "lsaRouterNumber",
2940 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
));
2941 json_object_int_add(
2942 json_area
, "lsaRouterChecksum",
2943 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
2944 json_object_int_add(
2945 json_area
, "lsaNetworkNumber",
2946 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
));
2947 json_object_int_add(
2948 json_area
, "lsaNetworkChecksum",
2949 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
2950 json_object_int_add(
2951 json_area
, "lsaSummaryNumber",
2952 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
));
2953 json_object_int_add(
2954 json_area
, "lsaSummaryChecksum",
2955 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
2956 json_object_int_add(
2957 json_area
, "lsaAsbrNumber",
2958 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2959 json_object_int_add(
2960 json_area
, "lsaAsbrChecksum",
2961 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2962 json_object_int_add(
2963 json_area
, "lsaNssaNumber",
2964 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2965 json_object_int_add(
2966 json_area
, "lsaNssaChecksum",
2967 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2969 /* Show number of fully adjacent neighbors. */
2971 " Number of fully adjacent neighbors in this area: %d\n",
2974 /* Show authentication type. */
2975 vty_out(vty
, " Area has ");
2976 if (area
->auth_type
== OSPF_AUTH_NULL
)
2977 vty_out(vty
, "no authentication\n");
2978 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2979 vty_out(vty
, "simple password authentication\n");
2980 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2981 vty_out(vty
, "message digest authentication\n");
2983 if (!OSPF_IS_AREA_BACKBONE(area
))
2985 " Number of full virtual adjacencies going through this area: %d\n",
2988 /* Show SPF calculation times. */
2989 vty_out(vty
, " SPF algorithm executed %d times\n",
2990 area
->spf_calculation
);
2992 /* Show number of LSA. */
2993 vty_out(vty
, " Number of LSA %ld\n", area
->lsdb
->total
);
2995 " Number of router LSA %ld. Checksum Sum 0x%08x\n",
2996 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
),
2997 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
2999 " Number of network LSA %ld. Checksum Sum 0x%08x\n",
3000 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
),
3001 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
3003 " Number of summary LSA %ld. Checksum Sum 0x%08x\n",
3004 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
),
3005 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
3007 " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n",
3008 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
),
3009 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
3010 vty_out(vty
, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n",
3011 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
),
3012 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
3016 json_object_int_add(
3017 json_area
, "lsaOpaqueLinkNumber",
3018 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
3019 json_object_int_add(
3020 json_area
, "lsaOpaqueLinkChecksum",
3021 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
3022 json_object_int_add(
3023 json_area
, "lsaOpaqueAreaNumber",
3024 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
3025 json_object_int_add(
3026 json_area
, "lsaOpaqueAreaChecksum",
3027 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
3030 " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n",
3031 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
),
3032 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
3034 " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n",
3035 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
),
3036 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
3040 json_object_object_add(json_areas
,
3041 inet_ntop(AF_INET
, &area
->area_id
,
3048 static int show_ip_ospf_common(struct vty
*vty
, struct ospf
*ospf
,
3049 json_object
*json
, uint8_t use_vrf
)
3051 struct listnode
*node
, *nnode
;
3052 struct ospf_area
*area
;
3053 struct timeval result
;
3054 char timebuf
[OSPF_TIME_DUMP_SIZE
];
3055 char buf
[PREFIX_STRLEN
];
3056 json_object
*json_vrf
= NULL
;
3057 json_object
*json_areas
= NULL
;
3061 json_vrf
= json_object_new_object();
3064 json_areas
= json_object_new_object();
3067 if (ospf
->instance
) {
3069 json_object_int_add(json
, "ospfInstance",
3072 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
3076 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3078 /* Show Router ID. */
3080 json_object_string_add(json_vrf
, "routerId",
3081 inet_ntop(AF_INET
, &ospf
->router_id
,
3084 vty_out(vty
, " OSPF Routing Process, Router ID: %pI4\n",
3088 /* Graceful shutdown */
3089 if (ospf
->t_deferred_shutdown
) {
3094 &ospf
->t_deferred_shutdown
->u
.sands
,
3097 json_object_int_add(json_vrf
, "deferredShutdownMsecs",
3101 " Deferred shutdown in progress, %s remaining\n",
3102 ospf_timer_dump(ospf
->t_deferred_shutdown
,
3103 timebuf
, sizeof(timebuf
)));
3107 /* Show capability. */
3109 json_object_boolean_true_add(json_vrf
, "tosRoutesOnly");
3110 json_object_boolean_true_add(json_vrf
, "rfc2328Conform");
3111 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
3112 json_object_boolean_true_add(json_vrf
,
3113 "rfc1583Compatibility");
3116 vty_out(vty
, " Supports only single TOS (TOS0) routes\n");
3117 vty_out(vty
, " This implementation conforms to RFC2328\n");
3118 vty_out(vty
, " RFC1583Compatibility flag is %s\n",
3119 CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)
3125 if (CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)) {
3126 json_object_boolean_true_add(json_vrf
, "opaqueCapable");
3129 vty_out(vty
, " OpaqueCapability flag is %s\n",
3130 CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)
3135 /* Show stub-router configuration */
3136 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
3137 || ospf
->stub_router_shutdown_time
3138 != OSPF_STUB_ROUTER_UNCONFIGURED
) {
3140 json_object_boolean_true_add(json_vrf
,
3141 "stubAdvertisement");
3142 if (ospf
->stub_router_startup_time
3143 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3144 json_object_int_add(
3145 json_vrf
, "postStartEnabledSecs",
3146 ospf
->stub_router_startup_time
);
3147 if (ospf
->stub_router_shutdown_time
3148 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3149 json_object_int_add(
3150 json_vrf
, "preShutdownEnabledSecs",
3151 ospf
->stub_router_shutdown_time
);
3154 " Stub router advertisement is configured\n");
3155 if (ospf
->stub_router_startup_time
3156 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3158 " Enabled for %us after start-up\n",
3159 ospf
->stub_router_startup_time
);
3160 if (ospf
->stub_router_shutdown_time
3161 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3163 " Enabled for %us prior to full shutdown\n",
3164 ospf
->stub_router_shutdown_time
);
3168 /* Show SPF timers. */
3170 json_object_int_add(json_vrf
, "spfScheduleDelayMsecs",
3172 json_object_int_add(json_vrf
, "holdtimeMinMsecs",
3173 ospf
->spf_holdtime
);
3174 json_object_int_add(json_vrf
, "holdtimeMaxMsecs",
3175 ospf
->spf_max_holdtime
);
3176 json_object_int_add(json_vrf
, "holdtimeMultplier",
3177 ospf
->spf_hold_multiplier
);
3180 " Initial SPF scheduling delay %d millisec(s)\n"
3181 " Minimum hold time between consecutive SPFs %d millisec(s)\n"
3182 " Maximum hold time between consecutive SPFs %d millisec(s)\n"
3183 " Hold time multiplier is currently %d\n",
3184 ospf
->spf_delay
, ospf
->spf_holdtime
,
3185 ospf
->spf_max_holdtime
, ospf
->spf_hold_multiplier
);
3189 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3190 long time_store
= 0;
3193 monotime_since(&ospf
->ts_spf
, NULL
) / 1000LL;
3194 json_object_int_add(json_vrf
, "spfLastExecutedMsecs",
3197 time_store
= (1000 * ospf
->ts_spf_duration
.tv_sec
)
3198 + (ospf
->ts_spf_duration
.tv_usec
/ 1000);
3199 json_object_int_add(json_vrf
, "spfLastDurationMsecs",
3202 json_object_boolean_true_add(json_vrf
, "spfHasNotRun");
3204 vty_out(vty
, " SPF algorithm ");
3205 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3206 monotime_since(&ospf
->ts_spf
, &result
);
3207 vty_out(vty
, "last executed %s ago\n",
3208 ospf_timeval_dump(&result
, timebuf
,
3210 vty_out(vty
, " Last SPF duration %s\n",
3211 ospf_timeval_dump(&ospf
->ts_spf_duration
,
3212 timebuf
, sizeof(timebuf
)));
3214 vty_out(vty
, "has not been run\n");
3218 if (ospf
->t_spf_calc
) {
3221 monotime_until(&ospf
->t_spf_calc
->u
.sands
, NULL
)
3223 json_object_int_add(json_vrf
, "spfTimerDueInMsecs",
3227 json_object_int_add(json_vrf
, "lsaMinIntervalMsecs",
3228 ospf
->min_ls_interval
);
3229 json_object_int_add(json_vrf
, "lsaMinArrivalMsecs",
3230 ospf
->min_ls_arrival
);
3231 /* Show write multiplier values */
3232 json_object_int_add(json_vrf
, "writeMultiplier",
3233 ospf
->write_oi_count
);
3234 /* Show refresh parameters. */
3235 json_object_int_add(json_vrf
, "refreshTimerMsecs",
3236 ospf
->lsa_refresh_interval
* 1000);
3238 vty_out(vty
, " SPF timer %s%s\n",
3239 (ospf
->t_spf_calc
? "due in " : "is "),
3240 ospf_timer_dump(ospf
->t_spf_calc
, timebuf
,
3243 vty_out(vty
, " LSA minimum interval %d msecs\n",
3244 ospf
->min_ls_interval
);
3245 vty_out(vty
, " LSA minimum arrival %d msecs\n",
3246 ospf
->min_ls_arrival
);
3248 /* Show write multiplier values */
3249 vty_out(vty
, " Write Multiplier set to %d \n",
3250 ospf
->write_oi_count
);
3252 /* Show refresh parameters. */
3253 vty_out(vty
, " Refresh timer %d secs\n",
3254 ospf
->lsa_refresh_interval
);
3256 /* show max multipath */
3257 vty_out(vty
, " Maximum multiple paths(ECMP) supported %d\n",
3258 ospf
->max_multipath
);
3261 /* Show ABR/ASBR flags. */
3262 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ABR
)) {
3264 json_object_string_add(
3265 json_vrf
, "abrType",
3266 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3269 " This router is an ABR, ABR type is: %s\n",
3270 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3272 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ASBR
)) {
3274 json_object_string_add(
3275 json_vrf
, "asbrRouter",
3276 "injectingExternalRoutingInformation");
3279 " This router is an ASBR (injecting external routing information)\n");
3282 /* Show Number of AS-external-LSAs. */
3284 json_object_int_add(
3285 json_vrf
, "lsaExternalCounter",
3286 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3287 json_object_int_add(
3288 json_vrf
, "lsaExternalChecksum",
3289 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3292 " Number of external LSA %ld. Checksum Sum 0x%08x\n",
3293 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
),
3294 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3298 json_object_int_add(
3299 json_vrf
, "lsaAsopaqueCounter",
3300 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3301 json_object_int_add(
3302 json_vrf
, "lsaAsOpaqueChecksum",
3303 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3306 " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n",
3307 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
),
3308 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3311 /* Show number of areas attached. */
3313 json_object_int_add(json_vrf
, "attachedAreaCounter",
3314 listcount(ospf
->areas
));
3316 vty_out(vty
, " Number of areas attached to this router: %d\n",
3317 listcount(ospf
->areas
));
3319 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
3320 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
)) {
3322 json_object_boolean_true_add(
3323 json_vrf
, "adjacencyChangesLoggedAll");
3326 " All adjacency changes are logged\n");
3329 json_object_boolean_true_add(
3330 json_vrf
, "adjacencyChangesLogged");
3332 vty_out(vty
, " Adjacency changes are logged\n");
3336 /* show LDP-Sync status */
3337 ospf_ldp_sync_show_info(vty
, ospf
, json_vrf
, json
? 1 : 0);
3339 /* Show each area status. */
3340 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
3341 show_ip_ospf_area(vty
, area
, json_areas
, json
? 1 : 0);
3345 json_object_object_add(json_vrf
, "areas", json_areas
);
3346 if (ospf
->vrf_id
== VRF_DEFAULT
)
3347 json_object_object_add(json
, "default",
3350 json_object_object_add(json
, ospf
->name
,
3353 json_object_object_add(json
, "areas", json_areas
);
3361 DEFUN (show_ip_ospf
,
3363 "show ip ospf [vrf <NAME|all>] [json]",
3366 "OSPF information\n"
3372 bool uj
= use_json(argc
, argv
);
3373 struct listnode
*node
= NULL
;
3374 char *vrf_name
= NULL
;
3375 bool all_vrf
= false;
3376 int ret
= CMD_SUCCESS
;
3379 json_object
*json
= NULL
;
3380 uint8_t use_vrf
= 0;
3382 if (listcount(om
->ospf
) == 0)
3385 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
3388 json
= json_object_new_object();
3390 /* vrf input is provided could be all or specific vrf*/
3392 bool ospf_output
= false;
3397 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
3398 if (!ospf
->oi_running
)
3401 ret
= show_ip_ospf_common(vty
, ospf
, json
,
3405 vty_out(vty
, "%s\n",
3406 json_object_to_json_string_ext(
3407 json
, JSON_C_TO_STRING_PRETTY
));
3408 json_object_free(json
);
3409 } else if (!ospf_output
)
3410 vty_out(vty
, "%% OSPF instance not found\n");
3413 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
3414 if ((ospf
== NULL
) || !ospf
->oi_running
) {
3416 vty_out(vty
, "%s\n",
3417 json_object_to_json_string_ext(
3418 json
, JSON_C_TO_STRING_PRETTY
));
3419 json_object_free(json
);
3421 vty_out(vty
, "%% OSPF instance not found\n");
3426 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
3427 /* Display default ospf (instance 0) info */
3428 if (ospf
== NULL
|| !ospf
->oi_running
) {
3430 vty_out(vty
, "%s\n",
3431 json_object_to_json_string_ext(
3432 json
, JSON_C_TO_STRING_PRETTY
));
3433 json_object_free(json
);
3435 vty_out(vty
, "%% OSPF instance not found\n");
3442 show_ip_ospf_common(vty
, ospf
, json
, use_vrf
);
3444 vty_out(vty
, "%s\n",
3445 json_object_to_json_string_ext(
3446 json
, JSON_C_TO_STRING_PRETTY
));
3450 json_object_free(json
);
3455 DEFUN (show_ip_ospf_instance
,
3456 show_ip_ospf_instance_cmd
,
3457 "show ip ospf (1-65535) [json]",
3460 "OSPF information\n"
3466 unsigned short instance
= 0;
3467 bool uj
= use_json(argc
, argv
);
3468 int ret
= CMD_SUCCESS
;
3469 json_object
*json
= NULL
;
3471 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
3472 if (instance
!= ospf_instance
)
3473 return CMD_NOT_MY_INSTANCE
;
3475 ospf
= ospf_lookup_instance(instance
);
3476 if (!ospf
|| !ospf
->oi_running
)
3480 json
= json_object_new_object();
3482 ret
= show_ip_ospf_common(vty
, ospf
, json
, 0);
3485 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
3486 json
, JSON_C_TO_STRING_PRETTY
));
3487 json_object_free(json
);
3493 static void ospf_interface_auth_show(struct vty
*vty
, struct ospf_interface
*oi
,
3494 json_object
*json
, bool use_json
)
3498 auth_type
= OSPF_IF_PARAM(oi
, auth_type
);
3500 switch (auth_type
) {
3501 case OSPF_AUTH_NULL
:
3503 json_object_string_add(json
, "authentication",
3504 "authenticationNone");
3506 vty_out(vty
, " Authentication NULL is enabled\n");
3508 case OSPF_AUTH_SIMPLE
: {
3510 json_object_string_add(json
, "authentication",
3511 "authenticationSimplePassword");
3514 " Simple password authentication enabled\n");
3517 case OSPF_AUTH_CRYPTOGRAPHIC
: {
3518 struct crypt_key
*ckey
;
3520 if (list_isempty(OSPF_IF_PARAM(oi
, auth_crypt
)))
3523 ckey
= listgetdata(listtail(OSPF_IF_PARAM(oi
, auth_crypt
)));
3526 json_object_string_add(json
, "authentication",
3527 "authenticationMessageDigest");
3530 " Cryptographic authentication enabled\n");
3531 vty_out(vty
, " Algorithm:MD5\n");
3541 static void show_ip_ospf_interface_sub(struct vty
*vty
, struct ospf
*ospf
,
3542 struct interface
*ifp
,
3543 json_object
*json_interface_sub
,
3547 struct ospf_neighbor
*nbr
;
3548 struct route_node
*rn
;
3549 char buf
[PREFIX_STRLEN
];
3550 uint32_t bandwidth
= ifp
->bandwidth
? ifp
->bandwidth
: ifp
->speed
;
3552 /* Is interface up? */
3554 is_up
= if_is_operative(ifp
);
3556 json_object_boolean_true_add(json_interface_sub
,
3559 json_object_boolean_false_add(json_interface_sub
,
3562 json_object_int_add(json_interface_sub
, "ifIndex",
3564 json_object_int_add(json_interface_sub
, "mtuBytes", ifp
->mtu
);
3565 json_object_int_add(json_interface_sub
, "bandwidthMbit",
3567 json_object_string_add(json_interface_sub
, "ifFlags",
3568 if_flag_dump(ifp
->flags
));
3570 vty_out(vty
, "%s is %s\n", ifp
->name
,
3571 ((is_up
= if_is_operative(ifp
)) ? "up" : "down"));
3572 vty_out(vty
, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n",
3573 ifp
->ifindex
, ifp
->mtu
, bandwidth
,
3574 if_flag_dump(ifp
->flags
));
3577 /* Is interface OSPF enabled? */
3579 if (ospf_oi_count(ifp
) == 0) {
3580 json_object_boolean_false_add(json_interface_sub
,
3583 } else if (!is_up
) {
3584 json_object_boolean_false_add(json_interface_sub
,
3588 json_object_boolean_true_add(json_interface_sub
,
3591 if (ospf_oi_count(ifp
) == 0) {
3592 vty_out(vty
, " OSPF not enabled on this interface\n");
3594 } else if (!is_up
) {
3596 " OSPF is enabled, but not running on this interface\n");
3601 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
3602 struct ospf_interface
*oi
= rn
->info
;
3607 if (CHECK_FLAG(oi
->connected
->flags
, ZEBRA_IFA_UNNUMBERED
)) {
3609 json_object_boolean_true_add(json_interface_sub
,
3612 vty_out(vty
, " This interface is UNNUMBERED,");
3614 struct in_addr dest
;
3617 /* Show OSPF interface information. */
3619 json_object_string_add(
3620 json_interface_sub
, "ipAddress",
3622 &oi
->address
->u
.prefix4
,
3624 json_object_int_add(json_interface_sub
,
3625 "ipAddressPrefixlen",
3626 oi
->address
->prefixlen
);
3628 vty_out(vty
, " Internet Address %pFX,",
3631 /* For Vlinks, showing the peer address is
3632 * probably more informative than the local
3633 * interface that is being used */
3634 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
) {
3636 dest
= oi
->vl_data
->peer_addr
;
3637 } else if (CONNECTED_PEER(oi
->connected
)
3638 && oi
->connected
->destination
) {
3640 dest
= oi
->connected
->destination
->u
.prefix4
;
3643 dest
.s_addr
= ipv4_broadcast_addr(
3644 oi
->connected
->address
->u
.prefix4
.s_addr
,
3645 oi
->connected
->address
->prefixlen
);
3649 json_object_string_add(
3651 "ospfIfType", dstr
);
3652 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3653 json_object_string_add(
3656 inet_ntop(AF_INET
, &dest
,
3659 json_object_string_add(
3662 inet_ntop(AF_INET
, &dest
,
3665 vty_out(vty
, " %s %pI4,", dstr
,
3669 json_object_string_add(json_interface_sub
, "area",
3670 ospf_area_desc_string(oi
->area
));
3671 if (OSPF_IF_PARAM(oi
, mtu_ignore
))
3672 json_object_boolean_true_add(
3674 "mtuMismatchDetect");
3675 json_object_string_add(
3676 json_interface_sub
, "routerId",
3677 inet_ntop(AF_INET
, &ospf
->router_id
,
3679 json_object_string_add(json_interface_sub
,
3681 ospf_network_type_str
[oi
->type
]);
3682 json_object_int_add(json_interface_sub
, "cost",
3684 json_object_int_add(
3685 json_interface_sub
, "transmitDelaySecs",
3686 OSPF_IF_PARAM(oi
, transmit_delay
));
3687 json_object_string_add(json_interface_sub
, "state",
3688 lookup_msg(ospf_ism_state_msg
,
3690 json_object_int_add(json_interface_sub
, "priority",
3693 vty_out(vty
, " Area %s\n",
3694 ospf_area_desc_string(oi
->area
));
3696 vty_out(vty
, " MTU mismatch detection: %s\n",
3697 OSPF_IF_PARAM(oi
, mtu_ignore
) ? "disabled"
3701 " Router ID %pI4, Network Type %s, Cost: %d\n",
3703 ospf_network_type_str
[oi
->type
],
3707 " Transmit Delay is %d sec, State %s, Priority %d\n",
3708 OSPF_IF_PARAM(oi
, transmit_delay
),
3709 lookup_msg(ospf_ism_state_msg
, oi
->state
, NULL
),
3713 /* Show DR information. */
3714 if (DR(oi
).s_addr
== INADDR_ANY
) {
3717 " No backup designated router on this network\n");
3719 nbr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &DR(oi
));
3722 json_object_string_add(
3723 json_interface_sub
, "drId",
3725 &nbr
->router_id
, buf
,
3727 json_object_string_add(
3728 json_interface_sub
, "drAddress",
3731 &nbr
->address
.u
.prefix4
,
3735 " Designated Router (ID) %pI4",
3738 " Interface Address %pFX\n",
3744 nbr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &BDR(oi
));
3748 " No backup designated router on this network\n");
3751 json_object_string_add(
3752 json_interface_sub
, "bdrId",
3756 json_object_string_add(
3765 " Backup Designated Router (ID) %pI4,",
3767 vty_out(vty
, " Interface Address %pI4\n",
3768 &nbr
->address
.u
.prefix4
);
3773 /* Next network-LSA sequence number we'll use, if we're elected
3776 && ntohl(oi
->params
->network_lsa_seqnum
)
3777 != OSPF_INITIAL_SEQUENCE_NUMBER
) {
3779 json_object_int_add(
3781 "networkLsaSequence",
3782 ntohl(oi
->params
->network_lsa_seqnum
));
3785 " Saved Network-LSA sequence number 0x%x\n",
3786 ntohl(oi
->params
->network_lsa_seqnum
));
3790 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3791 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3792 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3793 json_object_boolean_true_add(
3795 "mcastMemberOspfAllRouters");
3796 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3797 json_object_boolean_true_add(
3799 "mcastMemberOspfDesignatedRouters");
3802 vty_out(vty
, " Multicast group memberships:");
3803 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3804 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3805 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3806 vty_out(vty
, " OSPFAllRouters");
3807 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3808 vty_out(vty
, " OSPFDesignatedRouters");
3810 vty_out(vty
, " <None>");
3815 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3816 json_object_int_add(
3817 json_interface_sub
, "timerMsecs",
3818 OSPF_IF_PARAM(oi
, v_hello
) * 1000);
3820 json_object_int_add(
3821 json_interface_sub
, "timerMsecs",
3822 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3823 json_object_int_add(json_interface_sub
,
3825 OSPF_IF_PARAM(oi
, v_wait
));
3826 json_object_int_add(json_interface_sub
,
3828 OSPF_IF_PARAM(oi
, v_wait
));
3829 json_object_int_add(
3830 json_interface_sub
, "timerRetransmitSecs",
3831 OSPF_IF_PARAM(oi
, retransmit_interval
));
3833 vty_out(vty
, " Timer intervals configured,");
3834 vty_out(vty
, " Hello ");
3835 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3836 vty_out(vty
, "%ds,",
3837 OSPF_IF_PARAM(oi
, v_hello
));
3839 vty_out(vty
, "%dms,",
3840 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3841 vty_out(vty
, " Dead %ds, Wait %ds, Retransmit %d\n",
3842 OSPF_IF_PARAM(oi
, v_wait
),
3843 OSPF_IF_PARAM(oi
, v_wait
),
3844 OSPF_IF_PARAM(oi
, retransmit_interval
));
3847 if (OSPF_IF_PASSIVE_STATUS(oi
) == OSPF_IF_ACTIVE
) {
3848 char timebuf
[OSPF_TIME_DUMP_SIZE
];
3850 long time_store
= 0;
3854 &oi
->t_hello
->u
.sands
,
3857 json_object_int_add(json_interface_sub
,
3858 "timerHelloInMsecs",
3861 vty_out(vty
, " Hello due in %s\n",
3862 ospf_timer_dump(oi
->t_hello
, timebuf
,
3864 } else /* passive-interface is set */
3867 json_object_boolean_true_add(
3869 "timerPassiveIface");
3872 " No Hellos (Passive interface)\n");
3876 json_object_int_add(json_interface_sub
, "nbrCount",
3877 ospf_nbr_count(oi
, 0));
3878 json_object_int_add(json_interface_sub
,
3880 ospf_nbr_count(oi
, NSM_Full
));
3883 " Neighbor Count is %d, Adjacent neighbor count is %d\n",
3884 ospf_nbr_count(oi
, 0),
3885 ospf_nbr_count(oi
, NSM_Full
));
3887 ospf_interface_bfd_show(vty
, ifp
, json_interface_sub
);
3889 /* OSPF Authentication information */
3890 ospf_interface_auth_show(vty
, oi
, json_interface_sub
, use_json
);
3894 static int show_ip_ospf_interface_common(struct vty
*vty
, struct ospf
*ospf
,
3895 char *intf_name
, uint8_t use_vrf
,
3896 json_object
*json
, bool use_json
)
3898 struct interface
*ifp
;
3899 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
3900 json_object
*json_vrf
= NULL
;
3901 json_object
*json_interface_sub
= NULL
, *json_interface
= NULL
;
3905 json_vrf
= json_object_new_object();
3908 json_interface
= json_object_new_object();
3911 if (ospf
->instance
) {
3913 json_object_int_add(json
, "ospfInstance",
3916 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
3919 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3921 if (intf_name
== NULL
) {
3922 /* Show All Interfaces.*/
3923 FOR_ALL_INTERFACES (vrf
, ifp
) {
3924 if (ospf_oi_count(ifp
)) {
3926 json_interface_sub
=
3927 json_object_new_object();
3929 show_ip_ospf_interface_sub(vty
, ospf
, ifp
,
3934 json_object_object_add(
3935 json_interface
, ifp
->name
,
3936 json_interface_sub
);
3941 json_object_object_add(json_vrf
, "interfaces",
3944 /* Interface name is specified. */
3945 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
3948 json_object_boolean_true_add(json_vrf
,
3951 vty_out(vty
, "No such interface name\n");
3954 json_interface_sub
= json_object_new_object();
3955 json_interface
= json_object_new_object();
3958 show_ip_ospf_interface_sub(
3959 vty
, ospf
, ifp
, json_interface_sub
, use_json
);
3962 json_object_object_add(json_interface
,
3964 json_interface_sub
);
3965 json_object_object_add(json_vrf
, "interfaces",
3973 if (ospf
->vrf_id
== VRF_DEFAULT
)
3974 json_object_object_add(json
, "default",
3977 json_object_object_add(json
, ospf
->name
,
3986 static void show_ip_ospf_interface_traffic_sub(struct vty
*vty
,
3987 struct ospf_interface
*oi
,
3988 json_object
*json_interface_sub
,
3992 json_object_int_add(json_interface_sub
, "ifIndex",
3994 json_object_int_add(json_interface_sub
, "helloIn",
3996 json_object_int_add(json_interface_sub
, "helloOut",
3998 json_object_int_add(json_interface_sub
, "dbDescIn",
4000 json_object_int_add(json_interface_sub
, "dbDescOut",
4002 json_object_int_add(json_interface_sub
, "lsReqIn",
4004 json_object_int_add(json_interface_sub
, "lsReqOut",
4006 json_object_int_add(json_interface_sub
, "lsUpdIn",
4008 json_object_int_add(json_interface_sub
, "lsUpdOut",
4010 json_object_int_add(json_interface_sub
, "lsAckIn",
4012 json_object_int_add(json_interface_sub
, "lsAckOut",
4016 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n",
4017 oi
->ifp
->name
, oi
->hello_in
, oi
->hello_out
,
4018 oi
->db_desc_in
, oi
->db_desc_out
, oi
->ls_req_in
,
4019 oi
->ls_req_out
, oi
->ls_upd_in
, oi
->ls_upd_out
,
4020 oi
->ls_ack_in
, oi
->ls_ack_out
);
4024 /* OSPFv2 Packet Counters */
4025 static int show_ip_ospf_interface_traffic_common(
4026 struct vty
*vty
, struct ospf
*ospf
, char *intf_name
, json_object
*json
,
4027 int display_once
, uint8_t use_vrf
, bool use_json
)
4029 struct vrf
*vrf
= NULL
;
4030 struct interface
*ifp
= NULL
;
4031 json_object
*json_vrf
= NULL
;
4032 json_object
*json_interface_sub
= NULL
;
4034 if (!use_json
&& !display_once
) {
4036 vty_out(vty
, "%-12s%-17s%-17s%-17s%-17s%-17s\n", "Interface",
4037 " HELLO", " DB-Desc", " LS-Req", " LS-Update",
4039 vty_out(vty
, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "",
4040 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
4043 "--------------------------------------------------------------------------------------------\n");
4044 } else if (use_json
) {
4046 json_vrf
= json_object_new_object();
4051 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4053 if (intf_name
== NULL
) {
4054 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
4055 FOR_ALL_INTERFACES (vrf
, ifp
) {
4056 struct route_node
*rn
;
4057 struct ospf_interface
*oi
;
4059 if (ospf_oi_count(ifp
) == 0)
4062 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
4063 rn
= route_next(rn
)) {
4070 json_interface_sub
=
4071 json_object_new_object();
4074 show_ip_ospf_interface_traffic_sub(
4075 vty
, oi
, json_interface_sub
, use_json
);
4077 json_object_object_add(
4078 json_vrf
, ifp
->name
,
4079 json_interface_sub
);
4084 /* Interface name is specified. */
4085 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
4087 struct route_node
*rn
;
4088 struct ospf_interface
*oi
;
4090 if (ospf_oi_count(ifp
) == 0) {
4092 " OSPF not enabled on this interface %s\n",
4097 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
4098 rn
= route_next(rn
)) {
4102 json_interface_sub
=
4103 json_object_new_object();
4106 show_ip_ospf_interface_traffic_sub(
4107 vty
, oi
, json_interface_sub
, use_json
);
4109 json_object_object_add(
4110 json_vrf
, ifp
->name
,
4111 json_interface_sub
);
4119 if (ospf
->vrf_id
== VRF_DEFAULT
)
4120 json_object_object_add(json
, "default",
4123 json_object_object_add(json
, ospf
->name
,
4132 DEFUN (show_ip_ospf_interface
,
4133 show_ip_ospf_interface_cmd
,
4134 "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]",
4137 "OSPF information\n"
4140 "Interface information\n"
4145 bool uj
= use_json(argc
, argv
);
4146 struct listnode
*node
= NULL
;
4147 char *vrf_name
= NULL
, *intf_name
= NULL
;
4148 bool all_vrf
= false;
4149 int ret
= CMD_SUCCESS
;
4151 int idx_vrf
= 0, idx_intf
= 0;
4152 uint8_t use_vrf
= 0;
4153 json_object
*json
= NULL
;
4155 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4157 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4158 intf_name
= argv
[idx_intf
]->arg
;
4161 json
= json_object_new_object();
4163 /* vrf input is provided could be all or specific vrf*/
4167 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4168 if (!ospf
->oi_running
)
4170 ret
= show_ip_ospf_interface_common(
4171 vty
, ospf
, intf_name
, use_vrf
, json
,
4176 vty_out(vty
, "%s\n",
4177 json_object_to_json_string_ext(
4178 json
, JSON_C_TO_STRING_PRETTY
));
4179 json_object_free(json
);
4181 vty_out(vty
, "%% OSPF instance not found\n");
4185 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4186 if (ospf
== NULL
|| !ospf
->oi_running
) {
4188 vty_out(vty
, "%s\n",
4189 json_object_to_json_string_ext(
4190 json
, JSON_C_TO_STRING_PRETTY
));
4191 json_object_free(json
);
4193 vty_out(vty
, "%% OSPF instance not found\n");
4197 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
4201 /* Display default ospf (instance 0) info */
4202 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4203 if (ospf
== NULL
|| !ospf
->oi_running
) {
4205 vty_out(vty
, "%s\n",
4206 json_object_to_json_string_ext(
4207 json
, JSON_C_TO_STRING_PRETTY
));
4208 json_object_free(json
);
4210 vty_out(vty
, "%% OSPF instance not found\n");
4214 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
4219 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4220 json
, JSON_C_TO_STRING_PRETTY
));
4221 json_object_free(json
);
4227 DEFUN (show_ip_ospf_instance_interface
,
4228 show_ip_ospf_instance_interface_cmd
,
4229 "show ip ospf (1-65535) interface [INTERFACE] [json]",
4232 "OSPF information\n"
4234 "Interface information\n"
4241 unsigned short instance
= 0;
4242 bool uj
= use_json(argc
, argv
);
4243 char *intf_name
= NULL
;
4244 int ret
= CMD_SUCCESS
;
4245 json_object
*json
= NULL
;
4247 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4248 if (instance
!= ospf_instance
)
4249 return CMD_NOT_MY_INSTANCE
;
4251 ospf
= ospf_lookup_instance(instance
);
4252 if (!ospf
|| !ospf
->oi_running
)
4256 json
= json_object_new_object();
4258 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4259 intf_name
= argv
[idx_intf
]->arg
;
4261 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
, 0, json
, uj
);
4264 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4265 json
, JSON_C_TO_STRING_PRETTY
));
4266 json_object_free(json
);
4272 DEFUN (show_ip_ospf_interface_traffic
,
4273 show_ip_ospf_interface_traffic_cmd
,
4274 "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]",
4277 "OSPF information\n"
4280 "Interface information\n"
4281 "Protocol Packet counters\n"
4285 struct ospf
*ospf
= NULL
;
4286 struct listnode
*node
= NULL
;
4287 char *vrf_name
= NULL
, *intf_name
= NULL
;
4288 bool all_vrf
= false;
4290 int idx_vrf
= 0, idx_intf
= 0;
4291 bool uj
= use_json(argc
, argv
);
4292 json_object
*json
= NULL
;
4293 int ret
= CMD_SUCCESS
;
4294 int display_once
= 0;
4295 uint8_t use_vrf
= 0;
4297 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4299 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4300 intf_name
= argv
[idx_intf
]->arg
;
4303 json
= json_object_new_object();
4308 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4309 if (!ospf
->oi_running
)
4312 ret
= show_ip_ospf_interface_traffic_common(
4313 vty
, ospf
, intf_name
, json
,
4314 display_once
, use_vrf
, uj
);
4319 vty_out(vty
, "%s\n",
4320 json_object_to_json_string_ext(
4321 json
, JSON_C_TO_STRING_PRETTY
));
4322 json_object_free(json
);
4327 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4328 if (ospf
== NULL
|| !ospf
->oi_running
) {
4330 json_object_free(json
);
4334 ret
= show_ip_ospf_interface_traffic_common(
4335 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4337 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4338 if (ospf
== NULL
|| !ospf
->oi_running
) {
4340 json_object_free(json
);
4344 ret
= show_ip_ospf_interface_traffic_common(
4345 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4349 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4350 json
, JSON_C_TO_STRING_PRETTY
));
4351 json_object_free(json
);
4358 static void show_ip_ospf_neighbour_header(struct vty
*vty
)
4360 vty_out(vty
, "\n%-15s %3s %-15s %9s %-15s %-32s %5s %5s %5s\n",
4361 "Neighbor ID", "Pri", "State", "Dead Time", "Address",
4362 "Interface", "RXmtL", "RqstL", "DBsmL");
4365 static void show_ip_ospf_neighbor_sub(struct vty
*vty
,
4366 struct ospf_interface
*oi
,
4367 json_object
*json
, bool use_json
)
4369 struct route_node
*rn
;
4370 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
4372 char buf
[PREFIX_STRLEN
];
4373 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4374 json_object
*json_neighbor
= NULL
, *json_neigh_array
= NULL
;
4376 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
4377 if ((nbr
= rn
->info
)) {
4378 /* Do not show myself. */
4379 if (nbr
== oi
->nbr_self
)
4381 /* Down state is not shown. */
4382 if (nbr
->state
== NSM_Down
)
4385 char neigh_str
[INET_ADDRSTRLEN
];
4388 && !IPV4_ADDR_SAME(&prev_nbr
->src
,
4390 /* Start new neigh list */
4391 json_neigh_array
= NULL
;
4394 if (nbr
->state
== NSM_Attempt
4395 && nbr
->router_id
.s_addr
== INADDR_ANY
)
4396 strlcpy(neigh_str
, "neighbor",
4399 inet_ntop(AF_INET
, &nbr
->router_id
,
4400 neigh_str
, sizeof(neigh_str
));
4402 json_object_object_get_ex(json
, neigh_str
,
4405 if (!json_neigh_array
) {
4407 json_object_new_array();
4408 json_object_object_add(
4413 json_neighbor
= json_object_new_object();
4415 ospf_nbr_state_message(nbr
, msgbuf
, 16);
4417 json_object_int_add(json_neighbor
, "priority",
4419 json_object_string_add(json_neighbor
, "state",
4422 if (nbr
->t_inactivity
) {
4425 time_store
= monotime_until(
4430 json_object_int_add(json_neighbor
,
4434 json_object_string_add(json_neighbor
,
4438 json_object_string_add(
4439 json_neighbor
, "address",
4440 inet_ntop(AF_INET
, &nbr
->src
,
4442 json_object_string_add(json_neighbor
,
4445 json_object_int_add(
4446 json_neighbor
, "retransmitCounter",
4447 ospf_ls_retransmit_count(nbr
));
4448 json_object_int_add(json_neighbor
,
4450 ospf_ls_request_count(nbr
));
4451 json_object_int_add(json_neighbor
,
4453 ospf_db_summary_count(nbr
));
4455 json_object_array_add(json_neigh_array
,
4458 ospf_nbr_state_message(nbr
, msgbuf
, 16);
4460 if (nbr
->state
== NSM_Attempt
4461 && nbr
->router_id
.s_addr
== INADDR_ANY
)
4462 vty_out(vty
, "%-15s %3d %-15s ", "-",
4463 nbr
->priority
, msgbuf
);
4465 vty_out(vty
, "%-15pI4 %3d %-15s ",
4467 nbr
->priority
, msgbuf
);
4469 vty_out(vty
, "%9s ",
4470 ospf_timer_dump(nbr
->t_inactivity
,
4473 vty_out(vty
, "%-15pI4 ", &nbr
->src
);
4474 vty_out(vty
, "%-32s %5ld %5ld %5d\n",
4476 ospf_ls_retransmit_count(nbr
),
4477 ospf_ls_request_count(nbr
),
4478 ospf_db_summary_count(nbr
));
4485 static int show_ip_ospf_neighbor_common(struct vty
*vty
, struct ospf
*ospf
,
4486 json_object
*json
, bool use_json
,
4489 struct ospf_interface
*oi
;
4490 struct listnode
*node
;
4491 json_object
*json_vrf
= NULL
;
4492 json_object
*json_nbr_sub
= NULL
;
4496 json_vrf
= json_object_new_object();
4499 json_nbr_sub
= json_object_new_object();
4502 if (ospf
->instance
) {
4504 json_object_int_add(json
, "ospfInstance",
4507 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4510 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4512 show_ip_ospf_neighbour_header(vty
);
4514 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4515 if (ospf_interface_neighbor_count(oi
) == 0)
4517 show_ip_ospf_neighbor_sub(vty
, oi
, json_nbr_sub
, use_json
);
4521 json_object_object_add(json_vrf
, "neighbors", json_nbr_sub
);
4523 if (ospf
->vrf_id
== VRF_DEFAULT
)
4524 json_object_object_add(json
, "default",
4527 json_object_object_add(json
, ospf
->name
,
4536 DEFUN (show_ip_ospf_neighbor
,
4537 show_ip_ospf_neighbor_cmd
,
4538 "show ip ospf [vrf <NAME|all>] neighbor [json]",
4541 "OSPF information\n"
4548 bool uj
= use_json(argc
, argv
);
4549 struct listnode
*node
= NULL
;
4550 char *vrf_name
= NULL
;
4551 bool all_vrf
= false;
4552 int ret
= CMD_SUCCESS
;
4555 uint8_t use_vrf
= 0;
4556 json_object
*json
= NULL
;
4558 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4561 json
= json_object_new_object();
4563 /* vrf input is provided could be all or specific vrf*/
4567 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4568 if (!ospf
->oi_running
)
4570 ret
= show_ip_ospf_neighbor_common(
4571 vty
, ospf
, json
, uj
, use_vrf
);
4575 vty_out(vty
, "%s\n",
4576 json_object_to_json_string_ext(
4577 json
, JSON_C_TO_STRING_PRETTY
));
4578 json_object_free(json
);
4580 vty_out(vty
, "OSPF instance not found\n");
4585 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4586 if (ospf
== NULL
|| !ospf
->oi_running
) {
4588 vty_out(vty
, "%s\n",
4589 json_object_to_json_string_ext(
4590 json
, JSON_C_TO_STRING_PRETTY
));
4591 json_object_free(json
);
4593 vty_out(vty
, "%% OSPF instance not found\n");
4598 /* Display default ospf (instance 0) info */
4599 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4600 if (ospf
== NULL
|| !ospf
->oi_running
) {
4602 vty_out(vty
, "%s\n",
4603 json_object_to_json_string_ext(
4604 json
, JSON_C_TO_STRING_PRETTY
));
4605 json_object_free(json
);
4607 vty_out(vty
, "%% OSPF instance not found\n");
4614 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
,
4618 vty_out(vty
, "%s\n",
4619 json_object_to_json_string_ext(
4620 json
, JSON_C_TO_STRING_PRETTY
));
4625 json_object_free(json
);
4631 DEFUN (show_ip_ospf_instance_neighbor
,
4632 show_ip_ospf_instance_neighbor_cmd
,
4633 "show ip ospf (1-65535) neighbor [json]",
4636 "OSPF information\n"
4643 unsigned short instance
= 0;
4644 bool uj
= use_json(argc
, argv
);
4645 json_object
*json
= NULL
;
4646 int ret
= CMD_SUCCESS
;
4648 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4649 if (instance
!= ospf_instance
)
4650 return CMD_NOT_MY_INSTANCE
;
4652 ospf
= ospf_lookup_instance(instance
);
4653 if (!ospf
|| !ospf
->oi_running
)
4657 json
= json_object_new_object();
4659 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
, 0);
4662 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4663 json
, JSON_C_TO_STRING_PRETTY
));
4664 json_object_free(json
);
4670 static int show_ip_ospf_neighbor_all_common(struct vty
*vty
, struct ospf
*ospf
,
4671 json_object
*json
, bool use_json
,
4674 struct listnode
*node
;
4675 struct ospf_interface
*oi
;
4676 char buf
[PREFIX_STRLEN
];
4677 json_object
*json_vrf
= NULL
;
4678 json_object
*json_neighbor_sub
= NULL
;
4682 json_vrf
= json_object_new_object();
4687 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4689 show_ip_ospf_neighbour_header(vty
);
4691 if (ospf
->instance
) {
4693 json_object_int_add(json_vrf
, "ospfInstance",
4696 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4699 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4700 struct listnode
*nbr_node
;
4701 struct ospf_nbr_nbma
*nbr_nbma
;
4703 show_ip_ospf_neighbor_sub(vty
, oi
, json_vrf
, use_json
);
4705 /* print Down neighbor status */
4706 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nbr_node
, nbr_nbma
)) {
4707 if (nbr_nbma
->nbr
== NULL
4708 || nbr_nbma
->nbr
->state
== NSM_Down
) {
4711 json_object_new_object();
4712 json_object_int_add(json_neighbor_sub
,
4714 nbr_nbma
->priority
);
4715 json_object_boolean_true_add(
4718 json_object_string_add(
4722 json_object_int_add(
4724 "nbrNbmaRetransmitCounter", 0);
4725 json_object_int_add(
4727 "nbrNbmaRequestCounter", 0);
4728 json_object_int_add(
4730 "nbrNbmaDbSummaryCounter", 0);
4731 json_object_object_add(
4734 &nbr_nbma
->addr
, buf
,
4738 vty_out(vty
, "%-15s %3d %-15s %9s ",
4739 "-", nbr_nbma
->priority
, "Down",
4742 "%-32pI4 %-20s %5d %5d %5d\n",
4744 IF_NAME(oi
), 0, 0, 0);
4752 if (ospf
->vrf_id
== VRF_DEFAULT
)
4753 json_object_object_add(json
, "default",
4756 json_object_object_add(json
, ospf
->name
,
4765 DEFUN (show_ip_ospf_neighbor_all
,
4766 show_ip_ospf_neighbor_all_cmd
,
4767 "show ip ospf [vrf <NAME|all>] neighbor all [json]",
4770 "OSPF information\n"
4774 "include down status neighbor\n"
4778 bool uj
= use_json(argc
, argv
);
4779 struct listnode
*node
= NULL
;
4780 char *vrf_name
= NULL
;
4781 bool all_vrf
= false;
4782 int ret
= CMD_SUCCESS
;
4785 uint8_t use_vrf
= 0;
4786 json_object
*json
= NULL
;
4788 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4791 json
= json_object_new_object();
4793 /* vrf input is provided could be all or specific vrf*/
4797 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4798 if (!ospf
->oi_running
)
4800 ret
= show_ip_ospf_neighbor_all_common(
4801 vty
, ospf
, json
, uj
, use_vrf
);
4805 vty_out(vty
, "%s\n",
4806 json_object_to_json_string_ext(
4807 json
, JSON_C_TO_STRING_PRETTY
));
4808 json_object_free(json
);
4814 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4815 if (ospf
== NULL
|| !ospf
->oi_running
) {
4817 json_object_free(json
);
4821 /* Display default ospf (instance 0) info */
4822 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4823 if (ospf
== NULL
|| !ospf
->oi_running
) {
4825 json_object_free(json
);
4831 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
,
4834 vty_out(vty
, "%s\n",
4835 json_object_to_json_string_ext(
4836 json
, JSON_C_TO_STRING_PRETTY
));
4841 json_object_free(json
);
4846 DEFUN (show_ip_ospf_instance_neighbor_all
,
4847 show_ip_ospf_instance_neighbor_all_cmd
,
4848 "show ip ospf (1-65535) neighbor all [json]",
4851 "OSPF information\n"
4854 "include down status neighbor\n"
4859 unsigned short instance
= 0;
4860 bool uj
= use_json(argc
, argv
);
4861 json_object
*json
= NULL
;
4862 int ret
= CMD_SUCCESS
;
4864 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4865 if (instance
!= ospf_instance
)
4866 return CMD_NOT_MY_INSTANCE
;
4868 ospf
= ospf_lookup_instance(instance
);
4869 if (!ospf
|| !ospf
->oi_running
)
4872 json
= json_object_new_object();
4874 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
, 0);
4877 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4878 json
, JSON_C_TO_STRING_PRETTY
));
4879 json_object_free(json
);
4885 static int show_ip_ospf_neighbor_int_common(struct vty
*vty
, struct ospf
*ospf
,
4887 struct cmd_token
**argv
,
4888 bool use_json
, uint8_t use_vrf
)
4890 struct interface
*ifp
;
4891 struct route_node
*rn
;
4892 json_object
*json
= NULL
;
4895 json
= json_object_new_object();
4897 if (ospf
->instance
) {
4899 json_object_int_add(json
, "ospfInstance",
4902 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4905 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
4907 ifp
= if_lookup_by_name(argv
[arg_base
]->arg
, ospf
->vrf_id
);
4910 json_object_boolean_true_add(json
, "noSuchIface");
4912 vty_out(vty
, "No such interface.\n");
4916 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
4917 struct ospf_interface
*oi
= rn
->info
;
4922 show_ip_ospf_neighbor_sub(vty
, oi
, json
, use_json
);
4926 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4927 json
, JSON_C_TO_STRING_PRETTY
));
4928 json_object_free(json
);
4935 DEFUN (show_ip_ospf_neighbor_int
,
4936 show_ip_ospf_neighbor_int_cmd
,
4937 "show ip ospf [vrf <NAME>] neighbor IFNAME [json]",
4940 "OSPF information\n"
4949 bool uj
= use_json(argc
, argv
);
4950 int ret
= CMD_SUCCESS
;
4951 struct interface
*ifp
= NULL
;
4952 char *vrf_name
= NULL
;
4953 vrf_id_t vrf_id
= VRF_DEFAULT
;
4954 struct vrf
*vrf
= NULL
;
4956 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
4957 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
4958 if (vrf_name
&& strmatch(vrf_name
, VRF_DEFAULT_NAME
))
4961 vrf
= vrf_lookup_by_name(vrf_name
);
4963 vrf_id
= vrf
->vrf_id
;
4965 ospf
= ospf_lookup_by_vrf_id(vrf_id
);
4967 if (!ospf
|| !ospf
->oi_running
)
4971 show_ip_ospf_neighbour_header(vty
);
4973 argv_find(argv
, argc
, "IFNAME", &idx_ifname
);
4975 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf_id
);
4979 ret
= show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
,
4984 DEFUN (show_ip_ospf_instance_neighbor_int
,
4985 show_ip_ospf_instance_neighbor_int_cmd
,
4986 "show ip ospf (1-65535) neighbor IFNAME [json]",
4989 "OSPF information\n"
4998 unsigned short instance
= 0;
4999 bool uj
= use_json(argc
, argv
);
5002 show_ip_ospf_neighbour_header(vty
);
5004 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5005 if (instance
!= ospf_instance
)
5006 return CMD_NOT_MY_INSTANCE
;
5008 ospf
= ospf_lookup_instance(instance
);
5009 if (!ospf
|| !ospf
->oi_running
)
5013 show_ip_ospf_neighbour_header(vty
);
5015 return show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
, argv
, uj
,
5019 static void show_ip_ospf_nbr_nbma_detail_sub(struct vty
*vty
,
5020 struct ospf_interface
*oi
,
5021 struct ospf_nbr_nbma
*nbr_nbma
,
5022 bool use_json
, json_object
*json
)
5024 char timebuf
[OSPF_TIME_DUMP_SIZE
];
5025 char buf
[PREFIX_STRLEN
];
5026 json_object
*json_sub
= NULL
;
5029 json_sub
= json_object_new_object();
5030 else /* Show neighbor ID. */
5031 vty_out(vty
, " Neighbor %s,", "-");
5033 /* Show interface address. */
5035 json_object_string_add(json_sub
, "ifaceAddress",
5036 inet_ntop(AF_INET
, &nbr_nbma
->addr
,
5039 vty_out(vty
, " interface address %pI4\n",
5044 json_object_string_add(json_sub
, "areaId",
5045 ospf_area_desc_string(oi
->area
));
5046 json_object_string_add(json_sub
, "iface", IF_NAME(oi
));
5048 vty_out(vty
, " In the area %s via interface %s\n",
5049 ospf_area_desc_string(oi
->area
), IF_NAME(oi
));
5051 /* Show neighbor priority and state. */
5053 json_object_int_add(json_sub
, "nbrPriority",
5054 nbr_nbma
->priority
);
5055 json_object_string_add(json_sub
, "nbrState", "down");
5057 vty_out(vty
, " Neighbor priority is %d, State is %s,",
5058 nbr_nbma
->priority
, "Down");
5060 /* Show state changes. */
5062 json_object_int_add(json_sub
, "stateChangeCounter",
5063 nbr_nbma
->state_change
);
5065 vty_out(vty
, " %d state changes\n", nbr_nbma
->state_change
);
5067 /* Show PollInterval */
5069 json_object_int_add(json_sub
, "pollInterval", nbr_nbma
->v_poll
);
5071 vty_out(vty
, " Poll interval %d\n", nbr_nbma
->v_poll
);
5073 /* Show poll-interval timer. */
5074 if (nbr_nbma
->t_poll
) {
5077 time_store
= monotime_until(&nbr_nbma
->t_poll
->u
.sands
,
5079 json_object_int_add(json_sub
,
5080 "pollIntervalTimerDueMsec",
5083 vty_out(vty
, " Poll timer due in %s\n",
5084 ospf_timer_dump(nbr_nbma
->t_poll
, timebuf
,
5088 /* Show poll-interval timer thread. */
5090 if (nbr_nbma
->t_poll
!= NULL
)
5091 json_object_string_add(json_sub
,
5092 "pollIntervalTimerThread", "on");
5094 vty_out(vty
, " Thread Poll Timer %s\n",
5095 nbr_nbma
->t_poll
!= NULL
? "on" : "off");
5098 json_object_object_add(json
, "noNbrId", json_sub
);
5101 static void show_ip_ospf_neighbor_detail_sub(struct vty
*vty
,
5102 struct ospf_interface
*oi
,
5103 struct ospf_neighbor
*nbr
,
5104 struct ospf_neighbor
*prev_nbr
,
5105 json_object
*json
, bool use_json
)
5107 char timebuf
[OSPF_TIME_DUMP_SIZE
];
5108 json_object
*json_neigh
= NULL
, *json_neigh_array
= NULL
;
5109 char neigh_str
[INET_ADDRSTRLEN
] = {0};
5110 char buf
[PREFIX_STRLEN
];
5114 !IPV4_ADDR_SAME(&prev_nbr
->src
, &nbr
->src
)) {
5115 json_neigh_array
= NULL
;
5118 if (nbr
->state
== NSM_Attempt
5119 && nbr
->router_id
.s_addr
== INADDR_ANY
)
5120 strlcpy(neigh_str
, "noNbrId", sizeof(neigh_str
));
5122 inet_ntop(AF_INET
, &nbr
->router_id
,
5123 neigh_str
, sizeof(neigh_str
));
5125 json_object_object_get_ex(json
, neigh_str
, &json_neigh_array
);
5127 if (!json_neigh_array
) {
5128 json_neigh_array
= json_object_new_array();
5129 json_object_object_add(json
, neigh_str
,
5133 json_neigh
= json_object_new_object();
5136 /* Show neighbor ID. */
5137 if (nbr
->state
== NSM_Attempt
5138 && nbr
->router_id
.s_addr
== INADDR_ANY
)
5139 vty_out(vty
, " Neighbor %s,", "-");
5141 vty_out(vty
, " Neighbor %pI4,",
5145 /* Show interface address. */
5147 json_object_string_add(json_neigh
, "ifaceAddress",
5149 &nbr
->address
.u
.prefix4
,
5152 vty_out(vty
, " interface address %pI4\n",
5153 &nbr
->address
.u
.prefix4
);
5157 json_object_string_add(json_neigh
, "areaId",
5158 ospf_area_desc_string(oi
->area
));
5159 json_object_string_add(json_neigh
, "ifaceName", oi
->ifp
->name
);
5161 vty_out(vty
, " In the area %s via interface %s\n",
5162 ospf_area_desc_string(oi
->area
), oi
->ifp
->name
);
5164 /* Show neighbor priority and state. */
5166 json_object_int_add(json_neigh
, "nbrPriority", nbr
->priority
);
5167 json_object_string_add(
5168 json_neigh
, "nbrState",
5169 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
5171 vty_out(vty
, " Neighbor priority is %d, State is %s,",
5173 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
5175 /* Show state changes. */
5177 json_object_int_add(json_neigh
, "stateChangeCounter",
5180 vty_out(vty
, " %d state changes\n", nbr
->state_change
);
5182 if (nbr
->ts_last_progress
.tv_sec
|| nbr
->ts_last_progress
.tv_usec
) {
5187 monotime_since(&nbr
->ts_last_progress
, &res
) / 1000LL;
5189 json_object_int_add(json_neigh
, "lastPrgrsvChangeMsec",
5193 " Most recent state change statistics:\n");
5194 vty_out(vty
, " Progressive change %s ago\n",
5195 ospf_timeval_dump(&res
, timebuf
,
5200 if (nbr
->ts_last_regress
.tv_sec
|| nbr
->ts_last_regress
.tv_usec
) {
5205 monotime_since(&nbr
->ts_last_regress
, &res
) / 1000LL;
5207 json_object_int_add(json_neigh
,
5208 "lastRegressiveChangeMsec",
5210 if (nbr
->last_regress_str
)
5211 json_object_string_add(
5213 "lastRegressiveChangeReason",
5214 nbr
->last_regress_str
);
5217 " Regressive change %s ago, due to %s\n",
5218 ospf_timeval_dump(&res
, timebuf
,
5220 (nbr
->last_regress_str
? nbr
->last_regress_str
5225 /* Show Designated Rotuer ID. */
5227 json_object_string_add(json_neigh
, "routerDesignatedId",
5228 inet_ntop(AF_INET
, &nbr
->d_router
,
5231 vty_out(vty
, " DR is %pI4,", &nbr
->d_router
);
5233 /* Show Backup Designated Rotuer ID. */
5235 json_object_string_add(json_neigh
, "routerDesignatedBackupId",
5236 inet_ntop(AF_INET
, &nbr
->bd_router
,
5239 vty_out(vty
, " BDR is %pI4\n", &nbr
->bd_router
);
5243 json_object_int_add(json_neigh
, "optionsCounter", nbr
->options
);
5244 json_object_string_add(json_neigh
, "optionsList",
5245 ospf_options_dump(nbr
->options
));
5247 vty_out(vty
, " Options %d %s\n", nbr
->options
,
5248 ospf_options_dump(nbr
->options
));
5250 /* Show Router Dead interval timer. */
5252 if (nbr
->t_inactivity
) {
5254 time_store
= monotime_until(&nbr
->t_inactivity
->u
.sands
,
5257 json_object_int_add(json_neigh
,
5258 "routerDeadIntervalTimerDueMsec",
5261 json_object_int_add(
5263 "routerDeadIntervalTimerDueMsec", -1);
5265 vty_out(vty
, " Dead timer due in %s\n",
5266 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
5269 /* Show Database Summary list. */
5271 json_object_int_add(json_neigh
, "databaseSummaryListCounter",
5272 ospf_db_summary_count(nbr
));
5274 vty_out(vty
, " Database Summary List %d\n",
5275 ospf_db_summary_count(nbr
));
5277 /* Show Link State Request list. */
5279 json_object_int_add(json_neigh
, "linkStateRequestListCounter",
5280 ospf_ls_request_count(nbr
));
5282 vty_out(vty
, " Link State Request List %ld\n",
5283 ospf_ls_request_count(nbr
));
5285 /* Show Link State Retransmission list. */
5287 json_object_int_add(json_neigh
,
5288 "linkStateRetransmissionListCounter",
5289 ospf_ls_retransmit_count(nbr
));
5291 vty_out(vty
, " Link State Retransmission List %ld\n",
5292 ospf_ls_retransmit_count(nbr
));
5294 /* Show inactivity timer thread. */
5296 if (nbr
->t_inactivity
!= NULL
)
5297 json_object_string_add(json_neigh
,
5298 "threadInactivityTimer", "on");
5300 vty_out(vty
, " Thread Inactivity Timer %s\n",
5301 nbr
->t_inactivity
!= NULL
? "on" : "off");
5303 /* Show Database Description retransmission thread. */
5305 if (nbr
->t_db_desc
!= NULL
)
5306 json_object_string_add(
5308 "threadDatabaseDescriptionRetransmission",
5312 " Thread Database Description Retransmision %s\n",
5313 nbr
->t_db_desc
!= NULL
? "on" : "off");
5315 /* Show Link State Request Retransmission thread. */
5317 if (nbr
->t_ls_req
!= NULL
)
5318 json_object_string_add(
5320 "threadLinkStateRequestRetransmission", "on");
5323 " Thread Link State Request Retransmission %s\n",
5324 nbr
->t_ls_req
!= NULL
? "on" : "off");
5326 /* Show Link State Update Retransmission thread. */
5328 if (nbr
->t_ls_upd
!= NULL
)
5329 json_object_string_add(
5331 "threadLinkStateUpdateRetransmission",
5335 " Thread Link State Update Retransmission %s\n\n",
5336 nbr
->t_ls_upd
!= NULL
? "on" : "off");
5339 vty_out(vty
, " Graceful restart Helper info:\n");
5341 if (OSPF_GR_IS_ACTIVE_HELPER(nbr
)) {
5343 " Graceful Restart HELPER Status : Inprogress.\n");
5346 " Graceful Restart grace period time: %d (seconds).\n",
5347 nbr
->gr_helper_info
.recvd_grace_period
);
5348 vty_out(vty
, " Graceful Restart reason: %s.\n",
5349 ospf_restart_reason2str(
5350 nbr
->gr_helper_info
.gr_restart_reason
));
5353 " Graceful Restart HELPER Status : None\n");
5356 if (nbr
->gr_helper_info
.rejected_reason
5357 != OSPF_HELPER_REJECTED_NONE
)
5358 vty_out(vty
, " Helper rejected reason: %s.\n",
5359 ospf_rejected_reason2str(
5360 nbr
->gr_helper_info
.rejected_reason
));
5362 if (nbr
->gr_helper_info
.helper_exit_reason
5363 != OSPF_GR_HELPER_EXIT_NONE
)
5364 vty_out(vty
, " Last helper exit reason: %s.\n\n",
5365 ospf_exit_reason2str(
5366 nbr
->gr_helper_info
.helper_exit_reason
));
5370 json_object_string_add(json_neigh
, "grHelperStatus",
5371 OSPF_GR_IS_ACTIVE_HELPER(nbr
) ?
5374 if (OSPF_GR_IS_ACTIVE_HELPER(nbr
)) {
5375 json_object_int_add(
5376 json_neigh
, "graceInterval",
5377 nbr
->gr_helper_info
.recvd_grace_period
);
5378 json_object_string_add(
5379 json_neigh
, "grRestartReason",
5380 ospf_restart_reason2str(
5381 nbr
->gr_helper_info
.gr_restart_reason
));
5384 if (nbr
->gr_helper_info
.rejected_reason
5385 != OSPF_HELPER_REJECTED_NONE
)
5386 json_object_string_add(
5387 json_neigh
, "helperRejectReason",
5388 ospf_rejected_reason2str(
5389 nbr
->gr_helper_info
.rejected_reason
));
5391 if (nbr
->gr_helper_info
.helper_exit_reason
5392 != OSPF_GR_HELPER_EXIT_NONE
)
5393 json_object_string_add(
5394 json_neigh
, "helperExitReason",
5395 ospf_exit_reason2str(
5397 .helper_exit_reason
));
5400 bfd_sess_show(vty
, json_neigh
, nbr
->bfd_session
);
5403 json_object_array_add(json_neigh_array
, json_neigh
);
5407 static int show_ip_ospf_neighbor_id_common(struct vty
*vty
, struct ospf
*ospf
,
5408 struct in_addr
*router_id
,
5409 bool use_json
, uint8_t use_vrf
)
5411 struct listnode
*node
;
5412 struct ospf_neighbor
*nbr
;
5413 struct ospf_interface
*oi
;
5414 json_object
*json
= NULL
;
5417 json
= json_object_new_object();
5419 if (ospf
->instance
) {
5421 json_object_int_add(json
, "ospfInstance",
5424 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5427 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
5429 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5430 if ((nbr
= ospf_nbr_lookup_by_routerid(oi
->nbrs
, router_id
))) {
5431 show_ip_ospf_neighbor_detail_sub(vty
, oi
, nbr
, NULL
,
5437 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5438 json
, JSON_C_TO_STRING_PRETTY
));
5439 json_object_free(json
);
5446 DEFPY (show_ip_ospf_neighbor_id
,
5447 show_ip_ospf_neighbor_id_cmd
,
5448 "show ip ospf neighbor A.B.C.D$router_id [json$json]",
5451 "OSPF information\n"
5457 struct listnode
*node
;
5458 int ret
= CMD_SUCCESS
;
5460 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5461 if (!ospf
->oi_running
)
5463 ret
= show_ip_ospf_neighbor_id_common(vty
, ospf
, &router_id
,
5470 DEFPY (show_ip_ospf_instance_neighbor_id
,
5471 show_ip_ospf_instance_neighbor_id_cmd
,
5472 "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [json$json]",
5475 "OSPF information\n"
5483 if (instance
!= ospf_instance
)
5484 return CMD_NOT_MY_INSTANCE
;
5486 ospf
= ospf_lookup_instance(instance
);
5487 if (!ospf
|| !ospf
->oi_running
)
5490 return show_ip_ospf_neighbor_id_common(vty
, ospf
, &router_id
, !!json
,
5494 static int show_ip_ospf_neighbor_detail_common(struct vty
*vty
,
5496 json_object
*json
, bool use_json
,
5499 struct ospf_interface
*oi
;
5500 struct listnode
*node
;
5501 json_object
*json_vrf
= NULL
;
5502 json_object
*json_nbr_sub
= NULL
;
5506 json_vrf
= json_object_new_object();
5510 json_nbr_sub
= json_object_new_object();
5513 if (ospf
->instance
) {
5515 json_object_int_add(json
, "ospfInstance",
5518 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5521 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5523 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5524 struct route_node
*rn
;
5525 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
5527 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5528 if ((nbr
= rn
->info
)) {
5529 if (nbr
!= oi
->nbr_self
) {
5530 if (nbr
->state
!= NSM_Down
) {
5531 show_ip_ospf_neighbor_detail_sub(
5532 vty
, oi
, nbr
, prev_nbr
,
5533 json_nbr_sub
, use_json
);
5542 json_object_object_add(json_vrf
, "neighbors",
5545 if (ospf
->vrf_id
== VRF_DEFAULT
)
5546 json_object_object_add(json
, "default",
5549 json_object_object_add(json
, ospf
->name
,
5558 DEFUN (show_ip_ospf_neighbor_detail
,
5559 show_ip_ospf_neighbor_detail_cmd
,
5560 "show ip ospf [vrf <NAME|all>] neighbor detail [json]",
5563 "OSPF information\n"
5567 "detail of all neighbors\n"
5571 bool uj
= use_json(argc
, argv
);
5572 struct listnode
*node
= NULL
;
5573 char *vrf_name
= NULL
;
5574 bool all_vrf
= false;
5575 int ret
= CMD_SUCCESS
;
5578 uint8_t use_vrf
= 0;
5579 json_object
*json
= NULL
;
5581 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5584 json
= json_object_new_object();
5586 /* vrf input is provided could be all or specific vrf*/
5590 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5591 if (!ospf
->oi_running
)
5593 ret
= show_ip_ospf_neighbor_detail_common(
5594 vty
, ospf
, json
, uj
, use_vrf
);
5597 vty_out(vty
, "%s\n",
5598 json_object_to_json_string_ext(
5599 json
, JSON_C_TO_STRING_PRETTY
));
5600 json_object_free(json
);
5605 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5606 if (ospf
== NULL
|| !ospf
->oi_running
) {
5608 json_object_free(json
);
5612 /* Display default ospf (instance 0) info */
5613 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5614 if (ospf
== NULL
|| !ospf
->oi_running
) {
5616 json_object_free(json
);
5622 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
,
5625 vty_out(vty
, "%s\n",
5626 json_object_to_json_string_ext(
5627 json
, JSON_C_TO_STRING_PRETTY
));
5632 json_object_free(json
);
5637 DEFUN (show_ip_ospf_instance_neighbor_detail
,
5638 show_ip_ospf_instance_neighbor_detail_cmd
,
5639 "show ip ospf (1-65535) neighbor detail [json]",
5642 "OSPF information\n"
5645 "detail of all neighbors\n"
5650 unsigned short instance
= 0;
5651 bool uj
= use_json(argc
, argv
);
5652 json_object
*json
= NULL
;
5653 int ret
= CMD_SUCCESS
;
5655 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5656 if (instance
!= ospf_instance
)
5657 return CMD_NOT_MY_INSTANCE
;
5659 ospf
= ospf_lookup_instance(instance
);
5660 if (!ospf
|| !ospf
->oi_running
)
5664 json
= json_object_new_object();
5666 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
, 0);
5669 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5670 json
, JSON_C_TO_STRING_PRETTY
));
5671 json_object_free(json
);
5677 static int show_ip_ospf_neighbor_detail_all_common(struct vty
*vty
,
5683 struct listnode
*node
;
5684 struct ospf_interface
*oi
;
5685 json_object
*json_vrf
= NULL
;
5689 json_vrf
= json_object_new_object();
5694 if (ospf
->instance
) {
5696 json_object_int_add(json
, "ospfInstance",
5699 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5702 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5704 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5705 struct route_node
*rn
;
5706 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
5707 struct ospf_nbr_nbma
*nbr_nbma
;
5709 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5710 if ((nbr
= rn
->info
)) {
5711 if (nbr
!= oi
->nbr_self
)
5712 if (nbr
->state
!= NSM_Down
)
5713 show_ip_ospf_neighbor_detail_sub(
5716 json_vrf
, use_json
);
5721 if (oi
->type
== OSPF_IFTYPE_NBMA
) {
5722 struct listnode
*nd
;
5724 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nd
, nbr_nbma
)) {
5725 if (nbr_nbma
->nbr
== NULL
5726 || nbr_nbma
->nbr
->state
== NSM_Down
)
5727 show_ip_ospf_nbr_nbma_detail_sub(
5728 vty
, oi
, nbr_nbma
, use_json
,
5736 if (ospf
->vrf_id
== VRF_DEFAULT
)
5737 json_object_object_add(json
, "default",
5740 json_object_object_add(json
, ospf
->name
,
5750 DEFUN (show_ip_ospf_neighbor_detail_all
,
5751 show_ip_ospf_neighbor_detail_all_cmd
,
5752 "show ip ospf [vrf <NAME|all>] neighbor detail all [json]",
5755 "OSPF information\n"
5759 "detail of all neighbors\n"
5760 "include down status neighbor\n"
5764 bool uj
= use_json(argc
, argv
);
5765 struct listnode
*node
= NULL
;
5766 char *vrf_name
= NULL
;
5767 bool all_vrf
= false;
5768 int ret
= CMD_SUCCESS
;
5771 uint8_t use_vrf
= 0;
5772 json_object
*json
= NULL
;
5774 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5777 json
= json_object_new_object();
5779 /* vrf input is provided could be all or specific vrf*/
5783 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5784 if (!ospf
->oi_running
)
5786 ret
= show_ip_ospf_neighbor_detail_all_common(
5787 vty
, ospf
, json
, uj
, use_vrf
);
5791 vty_out(vty
, "%s\n",
5792 json_object_to_json_string_ext(
5793 json
, JSON_C_TO_STRING_PRETTY
));
5794 json_object_free(json
);
5799 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5800 if (ospf
== NULL
|| !ospf
->oi_running
) {
5802 json_object_free(json
);
5806 /* Display default ospf (instance 0) info */
5807 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5808 if (ospf
== NULL
|| !ospf
->oi_running
) {
5810 json_object_free(json
);
5816 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
,
5819 vty_out(vty
, "%s\n",
5820 json_object_to_json_string_ext(
5821 json
, JSON_C_TO_STRING_PRETTY
));
5826 json_object_free(json
);
5831 DEFUN (show_ip_ospf_instance_neighbor_detail_all
,
5832 show_ip_ospf_instance_neighbor_detail_all_cmd
,
5833 "show ip ospf (1-65535) neighbor detail all [json]",
5836 "OSPF information\n"
5839 "detail of all neighbors\n"
5840 "include down status neighbor\n"
5845 unsigned short instance
= 0;
5846 bool uj
= use_json(argc
, argv
);
5847 json_object
*json
= NULL
;
5848 int ret
= CMD_SUCCESS
;
5850 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5851 if (instance
!= ospf_instance
)
5852 return CMD_NOT_MY_INSTANCE
;
5854 ospf
= ospf_lookup_instance(instance
);
5855 if (!ospf
|| !ospf
->oi_running
)
5859 json
= json_object_new_object();
5861 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
, uj
, 0);
5864 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5865 json
, JSON_C_TO_STRING_PRETTY
));
5866 json_object_free(json
);
5872 static int show_ip_ospf_neighbor_int_detail_common(struct vty
*vty
,
5875 struct cmd_token
**argv
,
5878 struct ospf_interface
*oi
;
5879 struct interface
*ifp
;
5880 struct route_node
*rn
, *nrn
;
5881 struct ospf_neighbor
*nbr
;
5882 json_object
*json
= NULL
;
5885 json
= json_object_new_object();
5887 if (ospf
->instance
) {
5889 json_object_int_add(json
, "ospfInstance",
5892 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5895 ifp
= if_lookup_by_name(argv
[arg_base
]->arg
, ospf
->vrf_id
);
5898 vty_out(vty
, "No such interface.\n");
5900 vty_out(vty
, "{}\n");
5901 json_object_free(json
);
5906 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
5907 if ((oi
= rn
->info
)) {
5908 for (nrn
= route_top(oi
->nbrs
); nrn
;
5909 nrn
= route_next(nrn
)) {
5910 if ((nbr
= nrn
->info
)) {
5911 if (nbr
!= oi
->nbr_self
) {
5912 if (nbr
->state
!= NSM_Down
)
5913 show_ip_ospf_neighbor_detail_sub(
5924 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5925 json
, JSON_C_TO_STRING_PRETTY
));
5926 json_object_free(json
);
5933 DEFUN (show_ip_ospf_neighbor_int_detail
,
5934 show_ip_ospf_neighbor_int_detail_cmd
,
5935 "show ip ospf neighbor IFNAME detail [json]",
5938 "OSPF information\n"
5941 "detail of all neighbors\n"
5945 bool uj
= use_json(argc
, argv
);
5946 struct listnode
*node
= NULL
;
5947 int ret
= CMD_SUCCESS
;
5948 bool ospf_output
= false;
5950 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5951 if (!ospf
->oi_running
)
5954 ret
= show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, 4,
5959 vty_out(vty
, "%% OSPF instance not found\n");
5964 DEFUN (show_ip_ospf_instance_neighbor_int_detail
,
5965 show_ip_ospf_instance_neighbor_int_detail_cmd
,
5966 "show ip ospf (1-65535) neighbor IFNAME detail [json]",
5969 "OSPF information\n"
5973 "detail of all neighbors\n"
5979 unsigned short instance
= 0;
5980 bool uj
= use_json(argc
, argv
);
5982 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5983 if (instance
!= ospf_instance
)
5984 return CMD_NOT_MY_INSTANCE
;
5986 ospf
= ospf_lookup_instance(instance
);
5987 if (!ospf
|| !ospf
->oi_running
)
5990 return show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, idx_ifname
,
5994 /* Show functions */
5995 static int show_lsa_summary(struct vty
*vty
, struct ospf_lsa
*lsa
, int self
,
5996 json_object
*json_lsa
)
5998 struct router_lsa
*rl
;
5999 struct summary_lsa
*sl
;
6000 struct as_external_lsa
*asel
;
6001 struct prefix_ipv4 p
;
6002 char buf
[PREFIX2STR_BUFFER
];
6005 /* If self option is set, check LSA self flag. */
6006 if (self
== 0 || IS_LSA_SELF(lsa
)) {
6009 /* LSA common part show. */
6010 vty_out(vty
, "%-15pI4",
6012 vty_out(vty
, "%-15pI4 %4d 0x%08lx 0x%04x",
6013 &lsa
->data
->adv_router
, LS_AGE(lsa
),
6014 (unsigned long)ntohl(
6015 lsa
->data
->ls_seqnum
),
6016 ntohs(lsa
->data
->checksum
));
6021 snprintf(seqnum
, sizeof(seqnum
), "%x",
6022 ntohl(lsa
->data
->ls_seqnum
));
6023 snprintf(checksum
, sizeof(checksum
), "%x",
6024 ntohs(lsa
->data
->checksum
));
6025 json_object_string_add(
6027 inet_ntop(AF_INET
, &lsa
->data
->id
,
6029 json_object_string_add(
6030 json_lsa
, "advertisedRouter",
6032 &lsa
->data
->adv_router
,
6034 json_object_int_add(json_lsa
, "lsaAge",
6036 json_object_string_add(
6037 json_lsa
, "sequenceNumber", seqnum
);
6038 json_object_string_add(json_lsa
, "checksum",
6042 /* LSA specific part show. */
6043 switch (lsa
->data
->type
) {
6044 case OSPF_ROUTER_LSA
:
6045 rl
= (struct router_lsa
*)lsa
->data
;
6048 vty_out(vty
, " %-d", ntohs(rl
->links
));
6050 json_object_int_add(json_lsa
,
6054 case OSPF_SUMMARY_LSA
:
6055 sl
= (struct summary_lsa
*)lsa
->data
;
6058 p
.prefix
= sl
->header
.id
;
6059 p
.prefixlen
= ip_masklen(sl
->mask
);
6060 apply_mask_ipv4(&p
);
6063 vty_out(vty
, " %pFX", &p
);
6065 prefix2str(&p
, buf
, sizeof(buf
));
6066 json_object_string_add(json_lsa
,
6071 case OSPF_AS_EXTERNAL_LSA
:
6072 case OSPF_AS_NSSA_LSA
:
6073 asel
= (struct as_external_lsa
*)lsa
->data
;
6076 p
.prefix
= asel
->header
.id
;
6077 p
.prefixlen
= ip_masklen(asel
->mask
);
6078 apply_mask_ipv4(&p
);
6081 vty_out(vty
, " %s %pFX [0x%lx]",
6087 (unsigned long)ntohl(
6088 asel
->e
[0].route_tag
));
6090 prefix2str(&p
, buf
, sizeof(buf
));
6091 json_object_string_add(
6092 json_lsa
, "metricType",
6097 json_object_string_add(json_lsa
,
6099 json_object_int_add(
6101 (unsigned long)ntohl(
6102 asel
->e
[0].route_tag
));
6105 case OSPF_NETWORK_LSA
:
6106 case OSPF_ASBR_SUMMARY_LSA
:
6107 case OSPF_OPAQUE_LINK_LSA
:
6108 case OSPF_OPAQUE_AREA_LSA
:
6109 case OSPF_OPAQUE_AS_LSA
:
6121 static const char *const show_database_desc
[] = {
6123 "Router Link States",
6125 "Summary Link States",
6126 "ASBR-Summary Link States",
6127 "AS External Link States",
6128 "Group Membership LSA",
6129 "NSSA-external Link States",
6131 "Link-Local Opaque-LSA",
6132 "Area-Local Opaque-LSA",
6133 "AS-external Opaque-LSA",
6136 static const char * const show_database_desc_json
[] = {
6139 "networkLinkStates",
6140 "summaryLinkStates",
6141 "asbrSummaryLinkStates",
6142 "asExternalLinkStates",
6143 "groupMembershipLsa",
6144 "nssaExternalLinkStates",
6146 "linkLocalOpaqueLsa",
6147 "areaLocalOpaqueLsa",
6148 "asExternalOpaqueLsa",
6151 static const char *const show_database_header
[] = {
6153 "Link ID ADV Router Age Seq# CkSum Link count",
6154 "Link ID ADV Router Age Seq# CkSum",
6155 "Link ID ADV Router Age Seq# CkSum Route",
6156 "Link ID ADV Router Age Seq# CkSum",
6157 "Link ID ADV Router Age Seq# CkSum Route",
6158 " --- header for Group Member ----",
6159 "Link ID ADV Router Age Seq# CkSum Route",
6161 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6162 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6163 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6166 static void show_ip_ospf_database_header(struct vty
*vty
, struct ospf_lsa
*lsa
,
6169 char buf
[PREFIX_STRLEN
];
6170 struct router_lsa
*rlsa
= (struct router_lsa
*)lsa
->data
;
6173 vty_out(vty
, " LS age: %d\n", LS_AGE(lsa
));
6174 vty_out(vty
, " Options: 0x%-2x : %s\n", lsa
->data
->options
,
6175 ospf_options_dump(lsa
->data
->options
));
6176 vty_out(vty
, " LS Flags: 0x%-2x %s\n", lsa
->flags
,
6177 ((lsa
->flags
& OSPF_LSA_LOCAL_XLT
)
6178 ? "(Translated from Type-7)"
6181 if (lsa
->data
->type
== OSPF_ROUTER_LSA
) {
6182 vty_out(vty
, " Flags: 0x%x", rlsa
->flags
);
6185 vty_out(vty
, " :%s%s%s%s",
6186 IS_ROUTER_LSA_BORDER(rlsa
) ? " ABR"
6188 IS_ROUTER_LSA_EXTERNAL(rlsa
) ? " ASBR"
6190 IS_ROUTER_LSA_VIRTUAL(rlsa
)
6193 IS_ROUTER_LSA_SHORTCUT(rlsa
)
6199 vty_out(vty
, " LS Type: %s\n",
6200 lookup_msg(ospf_lsa_type_msg
, lsa
->data
->type
, NULL
));
6201 vty_out(vty
, " Link State ID: %pI4 %s\n",
6203 lookup_msg(ospf_link_state_id_type_msg
, lsa
->data
->type
,
6205 vty_out(vty
, " Advertising Router: %pI4\n",
6206 &lsa
->data
->adv_router
);
6207 vty_out(vty
, " LS Seq Number: %08lx\n",
6208 (unsigned long)ntohl(lsa
->data
->ls_seqnum
));
6209 vty_out(vty
, " Checksum: 0x%04x\n",
6210 ntohs(lsa
->data
->checksum
));
6211 vty_out(vty
, " Length: %d\n\n", ntohs(lsa
->data
->length
));
6216 snprintf(seqnum
, 10, "%x", ntohl(lsa
->data
->ls_seqnum
));
6217 snprintf(checksum
, 10, "%x", ntohs(lsa
->data
->checksum
));
6219 json_object_int_add(json
, "lsaAge", LS_AGE(lsa
));
6220 json_object_string_add(json
, "options",
6221 ospf_options_dump(lsa
->data
->options
));
6222 json_object_int_add(json
, "lsaFlags", lsa
->flags
);
6224 if (lsa
->flags
& OSPF_LSA_LOCAL_XLT
)
6225 json_object_boolean_true_add(json
,
6226 "translatedFromType7");
6228 if (lsa
->data
->type
== OSPF_ROUTER_LSA
) {
6229 json_object_int_add(json
, "flags", rlsa
->flags
);
6232 if (IS_ROUTER_LSA_BORDER(rlsa
))
6233 json_object_boolean_true_add(json
,
6235 if (IS_ROUTER_LSA_EXTERNAL(rlsa
))
6236 json_object_boolean_true_add(json
,
6238 if (IS_ROUTER_LSA_VIRTUAL(rlsa
))
6239 json_object_boolean_true_add(
6240 json
, "vlEndpoint");
6241 if (IS_ROUTER_LSA_SHORTCUT(rlsa
))
6242 json_object_boolean_true_add(
6247 json_object_string_add(
6249 lookup_msg(ospf_lsa_type_msg
, lsa
->data
->type
, NULL
));
6250 json_object_string_add(json
, "linkStateId",
6251 inet_ntop(AF_INET
, &lsa
->data
->id
,
6253 json_object_string_add(json
, "advertisingRouter",
6255 &lsa
->data
->adv_router
,
6257 json_object_string_add(json
, "lsaSeqNumber", seqnum
);
6258 json_object_string_add(json
, "checksum", checksum
);
6259 json_object_int_add(json
, "length", ntohs(lsa
->data
->length
));
6263 static const char *const link_type_desc
[] = {
6265 "another Router (point-to-point)",
6266 "a Transit Network",
6271 static const char *const link_id_desc
[] = {
6272 "(null)", "Neighboring Router ID", "Designated Router address",
6273 "Net", "Neighboring Router ID",
6276 static const char *const link_data_desc
[] = {
6277 "(null)", "Router Interface address", "Router Interface address",
6278 "Network Mask", "Router Interface address",
6281 static const char *const link_id_desc_json
[] = {
6282 "null", "neighborRouterId", "designatedRouterAddress",
6283 "networkAddress", "neighborRouterId",
6286 static const char *const link_data_desc_json
[] = {
6287 "null", "routerInterfaceAddress", "routerInterfaceAddress",
6288 "networkMask", "routerInterfaceAddress",
6291 /* Show router-LSA each Link information. */
6292 static void show_ip_ospf_database_router_links(struct vty
*vty
,
6293 struct router_lsa
*rl
,
6298 json_object
*json_links
= NULL
;
6299 json_object
*json_link
= NULL
;
6301 char buf
[PREFIX_STRLEN
];
6304 json_links
= json_object_new_object();
6306 len
= ntohs(rl
->header
.length
) - 4;
6307 for (i
= 0; i
< ntohs(rl
->links
) && len
> 0; len
-= 12, i
++) {
6308 type
= rl
->link
[i
].type
;
6313 snprintf(link
, sizeof(link
), "link%u", i
);
6314 json_link
= json_object_new_object();
6315 json_object_string_add(json_link
, "linkType",
6316 link_type_desc
[type
]);
6317 json_object_string_add(json_link
,
6318 link_id_desc_json
[type
],
6320 &rl
->link
[i
].link_id
,
6322 json_object_string_add(
6323 json_link
, link_data_desc_json
[type
],
6324 inet_ntop(AF_INET
, &rl
->link
[i
].link_data
,
6326 json_object_int_add(json_link
, "numOfTosMetrics",
6328 json_object_int_add(json_link
, "tos0Metric",
6329 ntohs(rl
->link
[i
].metric
));
6330 json_object_object_add(json_links
, link
, json_link
);
6332 vty_out(vty
, " Link connected to: %s\n",
6333 link_type_desc
[type
]);
6334 vty_out(vty
, " (Link ID) %s: %pI4\n",
6336 &rl
->link
[i
].link_id
);
6337 vty_out(vty
, " (Link Data) %s: %pI4\n",
6338 link_data_desc
[type
],
6339 &rl
->link
[i
].link_data
);
6340 vty_out(vty
, " Number of TOS metrics: 0\n");
6341 vty_out(vty
, " TOS 0 Metric: %d\n",
6342 ntohs(rl
->link
[i
].metric
));
6347 json_object_object_add(json
, "routerLinks", json_links
);
6350 /* Show router-LSA detail information. */
6351 static int show_router_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6355 struct router_lsa
*rl
= (struct router_lsa
*)lsa
->data
;
6357 show_ip_ospf_database_header(vty
, lsa
, json
);
6360 vty_out(vty
, " Number of Links: %d\n\n",
6363 json_object_int_add(json
, "numOfLinks",
6366 show_ip_ospf_database_router_links(vty
, rl
, json
);
6375 /* Show network-LSA detail information. */
6376 static int show_network_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6380 char buf
[PREFIX_STRLEN
];
6381 json_object
*json_attached_rt
= NULL
;
6382 json_object
*json_router
= NULL
;
6385 json_attached_rt
= json_object_new_object();
6388 struct network_lsa
*nl
= (struct network_lsa
*)lsa
->data
;
6389 struct in_addr
*addr
;
6391 show_ip_ospf_database_header(vty
, lsa
, json
);
6394 vty_out(vty
, " Network Mask: /%d\n",
6395 ip_masklen(nl
->mask
));
6397 json_object_int_add(json
, "networkMask",
6398 ip_masklen(nl
->mask
));
6400 length
= lsa
->size
- OSPF_LSA_HEADER_SIZE
- 4;
6401 addr
= &nl
->routers
[0];
6402 for (i
= 0; length
> 0 && addr
;
6403 length
-= 4, addr
= &nl
->routers
[++i
])
6405 vty_out(vty
, " Attached Router: %pI4\n",
6409 json_router
= json_object_new_object();
6410 json_object_string_add(
6411 json_router
, "attachedRouterId",
6412 inet_ntop(AF_INET
, addr
, buf
,
6414 json_object_object_add(json_attached_rt
,
6415 inet_ntop(AF_INET
, addr
,
6423 json_object_object_add(json
, "attchedRouters",
6429 /* Show summary-LSA detail information. */
6430 static int show_summary_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6434 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
6436 show_ip_ospf_database_header(vty
, lsa
, json
);
6439 vty_out(vty
, " Network Mask: /%d\n",
6440 ip_masklen(sl
->mask
));
6441 vty_out(vty
, " TOS: 0 Metric: %d\n",
6442 GET_METRIC(sl
->metric
));
6445 json_object_int_add(json
, "networkMask",
6446 ip_masklen(sl
->mask
));
6447 json_object_int_add(json
, "tos0Metric",
6448 GET_METRIC(sl
->metric
));
6455 /* Show summary-ASBR-LSA detail information. */
6456 static int show_summary_asbr_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6460 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
6462 show_ip_ospf_database_header(vty
, lsa
, json
);
6465 vty_out(vty
, " Network Mask: /%d\n",
6466 ip_masklen(sl
->mask
));
6467 vty_out(vty
, " TOS: 0 Metric: %d\n",
6468 GET_METRIC(sl
->metric
));
6471 json_object_int_add(json
, "networkMask",
6472 ip_masklen(sl
->mask
));
6473 json_object_int_add(json
, "tos0Metric",
6474 GET_METRIC(sl
->metric
));
6481 /* Show AS-external-LSA detail information. */
6482 static int show_as_external_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6485 char buf
[PREFIX_STRLEN
];
6489 struct as_external_lsa
*al
=
6490 (struct as_external_lsa
*)lsa
->data
;
6492 show_ip_ospf_database_header(vty
, lsa
, json
);
6495 vty_out(vty
, " Network Mask: /%d\n",
6496 ip_masklen(al
->mask
));
6497 vty_out(vty
, " Metric Type: %s\n",
6498 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6499 ? "2 (Larger than any link state path)"
6501 vty_out(vty
, " TOS: 0\n");
6502 vty_out(vty
, " Metric: %d\n",
6503 GET_METRIC(al
->e
[0].metric
));
6504 vty_out(vty
, " Forward Address: %pI4\n",
6505 &al
->e
[0].fwd_addr
);
6507 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
6508 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6510 json_object_int_add(json
, "networkMask",
6511 ip_masklen(al
->mask
));
6512 json_object_string_add(
6514 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6515 ? "E2 (Larger than any link state path)"
6517 json_object_int_add(json
, "tos", tos
);
6518 json_object_int_add(json
, "metric",
6519 GET_METRIC(al
->e
[0].metric
));
6520 json_object_string_add(json
, "forwardAddress",
6522 &(al
->e
[0].fwd_addr
),
6524 json_object_int_add(
6525 json
, "externalRouteTag",
6526 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6533 /* Show AS-NSSA-LSA detail information. */
6534 static int show_as_nssa_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6537 char buf
[PREFIX_STRLEN
];
6541 struct as_external_lsa
*al
=
6542 (struct as_external_lsa
*)lsa
->data
;
6544 show_ip_ospf_database_header(vty
, lsa
, json
);
6547 vty_out(vty
, " Network Mask: /%d\n",
6548 ip_masklen(al
->mask
));
6549 vty_out(vty
, " Metric Type: %s\n",
6550 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6551 ? "2 (Larger than any link state path)"
6553 vty_out(vty
, " TOS: 0\n");
6554 vty_out(vty
, " Metric: %d\n",
6555 GET_METRIC(al
->e
[0].metric
));
6556 vty_out(vty
, " NSSA: Forward Address: %pI4\n",
6557 &al
->e
[0].fwd_addr
);
6559 " External Route Tag: %" ROUTE_TAG_PRI
6561 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6563 json_object_int_add(json
, "networkMask",
6564 ip_masklen(al
->mask
));
6565 json_object_string_add(
6567 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6568 ? "E2 (Larger than any link state path)"
6570 json_object_int_add(json
, "tos", tos
);
6571 json_object_int_add(json
, "metric",
6572 GET_METRIC(al
->e
[0].metric
));
6573 json_object_string_add(json
, "nssaForwardAddress",
6577 json_object_int_add(
6578 json
, "externalRouteTag",
6579 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6586 static int show_func_dummy(struct vty
*vty
, struct ospf_lsa
*lsa
,
6592 static int show_opaque_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6596 show_ip_ospf_database_header(vty
, lsa
, json
);
6597 show_opaque_info_detail(vty
, lsa
, json
);
6604 int (*show_function
[])(struct vty
*, struct ospf_lsa
*, json_object
*) = {
6606 show_router_lsa_detail
,
6607 show_network_lsa_detail
,
6608 show_summary_lsa_detail
,
6609 show_summary_asbr_lsa_detail
,
6610 show_as_external_lsa_detail
,
6612 show_as_nssa_lsa_detail
, /* almost same as external */
6614 show_opaque_lsa_detail
,
6615 show_opaque_lsa_detail
,
6616 show_opaque_lsa_detail
,
6619 static void show_lsa_prefix_set(struct vty
*vty
, struct prefix_ls
*lp
,
6620 struct in_addr
*id
, struct in_addr
*adv_router
)
6622 memset(lp
, 0, sizeof(struct prefix_ls
));
6626 else if (adv_router
== NULL
) {
6627 lp
->prefixlen
= IPV4_MAX_BITLEN
;
6632 lp
->adv_router
= *adv_router
;
6636 static void show_lsa_detail_proc(struct vty
*vty
, struct route_table
*rt
,
6637 struct in_addr
*id
, struct in_addr
*adv_router
,
6640 struct prefix_ls lp
;
6641 struct route_node
*rn
, *start
;
6642 struct ospf_lsa
*lsa
;
6643 json_object
*json_lsa
= NULL
;
6645 show_lsa_prefix_set(vty
, &lp
, id
, adv_router
);
6646 start
= route_node_get(rt
, (struct prefix
*)&lp
);
6648 route_lock_node(start
);
6649 for (rn
= start
; rn
; rn
= route_next_until(rn
, start
))
6650 if ((lsa
= rn
->info
)) {
6652 json_lsa
= json_object_new_object();
6653 json_object_array_add(json
, json_lsa
);
6656 if (show_function
[lsa
->data
->type
] != NULL
)
6657 show_function
[lsa
->data
->type
](
6658 vty
, lsa
, json_lsa
);
6660 route_unlock_node(start
);
6664 /* Show detail LSA information
6665 -- if id is NULL then show all LSAs. */
6666 static void show_lsa_detail(struct vty
*vty
, struct ospf
*ospf
, int type
,
6667 struct in_addr
*id
, struct in_addr
*adv_router
,
6670 struct listnode
*node
;
6671 struct ospf_area
*area
;
6672 char buf
[PREFIX_STRLEN
];
6673 json_object
*json_lsa_type
= NULL
;
6674 json_object
*json_areas
= NULL
;
6675 json_object
*json_lsa_array
= NULL
;
6678 json_lsa_type
= json_object_new_object();
6681 case OSPF_AS_EXTERNAL_LSA
:
6682 case OSPF_OPAQUE_AS_LSA
:
6684 vty_out(vty
, " %s \n\n",
6685 show_database_desc
[type
]);
6687 json_lsa_array
= json_object_new_array();
6689 show_lsa_detail_proc(vty
, AS_LSDB(ospf
, type
), id
, adv_router
,
6692 json_object_object_add(json
,
6693 show_database_desc_json
[type
],
6699 json_areas
= json_object_new_object();
6701 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6704 "\n %s (Area %s)\n\n",
6705 show_database_desc
[type
],
6706 ospf_area_desc_string(area
));
6708 json_lsa_array
= json_object_new_array();
6709 json_object_object_add(json_areas
,
6717 show_lsa_detail_proc(vty
, AREA_LSDB(area
, type
), id
,
6718 adv_router
, json_lsa_array
);
6722 json_object_object_add(json_lsa_type
, "areas",
6724 json_object_object_add(json
,
6725 show_database_desc_json
[type
],
6732 static void show_lsa_detail_adv_router_proc(struct vty
*vty
,
6733 struct route_table
*rt
,
6734 struct in_addr
*adv_router
,
6737 char buf
[PREFIX_STRLEN
];
6738 struct route_node
*rn
;
6739 struct ospf_lsa
*lsa
;
6741 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
))
6742 if ((lsa
= rn
->info
)) {
6743 json_object
*json_lsa
= NULL
;
6745 if (IPV4_ADDR_SAME(adv_router
,
6746 &lsa
->data
->adv_router
)) {
6747 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
6750 json_lsa
= json_object_new_object();
6752 if (show_function
[lsa
->data
->type
] != NULL
)
6753 show_function
[lsa
->data
->type
](
6754 vty
, lsa
, json_lsa
);
6756 json_object_object_add(
6766 /* Show detail LSA information. */
6767 static void show_lsa_detail_adv_router(struct vty
*vty
, struct ospf
*ospf
,
6768 int type
, struct in_addr
*adv_router
,
6771 struct listnode
*node
;
6772 struct ospf_area
*area
;
6773 char buf
[PREFIX_STRLEN
];
6774 json_object
*json_lstype
= NULL
;
6775 json_object
*json_area
= NULL
;
6778 json_lstype
= json_object_new_object();
6781 case OSPF_AS_EXTERNAL_LSA
:
6782 case OSPF_OPAQUE_AS_LSA
:
6784 vty_out(vty
, " %s \n\n",
6785 show_database_desc
[type
]);
6787 show_lsa_detail_adv_router_proc(vty
, AS_LSDB(ospf
, type
),
6788 adv_router
, json_lstype
);
6792 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6794 json_area
= json_object_new_object();
6797 "\n %s (Area %s)\n\n",
6798 show_database_desc
[type
],
6799 ospf_area_desc_string(area
));
6800 show_lsa_detail_adv_router_proc(vty
,
6801 AREA_LSDB(area
, type
),
6802 adv_router
, json_area
);
6805 json_object_object_add(json_lstype
,
6816 json_object_object_add(json
, show_database_desc
[type
],
6820 void show_ip_ospf_database_summary(struct vty
*vty
, struct ospf
*ospf
, int self
,
6823 struct ospf_lsa
*lsa
;
6824 struct route_node
*rn
;
6825 struct ospf_area
*area
;
6826 struct listnode
*node
;
6827 char buf
[PREFIX_STRLEN
];
6828 json_object
*json_areas
= NULL
;
6829 json_object
*json_area
= NULL
;
6830 json_object
*json_lsa
= NULL
;
6832 json_object
*json_lsa_array
= NULL
;
6835 json_areas
= json_object_new_object();
6837 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6839 json_area
= json_object_new_object();
6841 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6843 case OSPF_AS_EXTERNAL_LSA
:
6844 case OSPF_OPAQUE_AS_LSA
:
6849 if (ospf_lsdb_count_self(area
->lsdb
, type
) > 0
6851 && ospf_lsdb_count(area
->lsdb
, type
) > 0)) {
6855 " %s (Area %s)\n\n",
6856 show_database_desc
[type
],
6857 ospf_area_desc_string(area
));
6858 vty_out(vty
, "%s\n",
6859 show_database_header
[type
]);
6862 json_object_new_array();
6863 json_object_object_add(
6865 show_database_desc_json
[type
],
6869 LSDB_LOOP (AREA_LSDB(area
, type
), rn
, lsa
) {
6872 json_object_new_object();
6873 json_object_array_add(
6878 show_lsa_summary(vty
, lsa
, self
,
6887 json_object_object_add(json_areas
,
6895 json_object_object_add(json
, "areas", json_areas
);
6897 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6899 case OSPF_AS_EXTERNAL_LSA
:
6900 case OSPF_OPAQUE_AS_LSA
:
6905 if (ospf_lsdb_count_self(ospf
->lsdb
, type
)
6906 || (!self
&& ospf_lsdb_count(ospf
->lsdb
, type
))) {
6908 vty_out(vty
, " %s\n\n",
6909 show_database_desc
[type
]);
6910 vty_out(vty
, "%s\n",
6911 show_database_header
[type
]);
6913 json_lsa_array
= json_object_new_array();
6914 json_object_object_add(
6915 json
, show_database_desc_json
[type
],
6919 LSDB_LOOP (AS_LSDB(ospf
, type
), rn
, lsa
) {
6921 json_lsa
= json_object_new_object();
6922 json_object_array_add(json_lsa_array
,
6926 show_lsa_summary(vty
, lsa
, self
, json_lsa
);
6938 static void show_ip_ospf_database_maxage(struct vty
*vty
, struct ospf
*ospf
,
6941 struct route_node
*rn
;
6942 char buf
[PREFIX_STRLEN
];
6943 json_object
*json_maxage
= NULL
;
6946 vty_out(vty
, "\n MaxAge Link States:\n\n");
6948 json_maxage
= json_object_new_object();
6950 for (rn
= route_top(ospf
->maxage_lsa
); rn
; rn
= route_next(rn
)) {
6951 struct ospf_lsa
*lsa
;
6952 json_object
*json_lsa
= NULL
;
6954 if ((lsa
= rn
->info
) != NULL
) {
6956 vty_out(vty
, "Link type: %d\n",
6958 vty_out(vty
, "Link State ID: %pI4\n",
6960 vty_out(vty
, "Advertising Router: %pI4\n",
6961 &lsa
->data
->adv_router
);
6962 vty_out(vty
, "LSA lock count: %d\n", lsa
->lock
);
6965 json_lsa
= json_object_new_object();
6966 json_object_int_add(json_lsa
, "linkType",
6968 json_object_string_add(
6969 json_lsa
, "linkStateId",
6970 inet_ntop(AF_INET
, &lsa
->data
->id
,
6972 json_object_string_add(
6973 json_lsa
, "advertisingRouter",
6975 &lsa
->data
->adv_router
,
6977 json_object_int_add(json_lsa
, "lsaLockCount",
6979 json_object_object_add(
6989 json_object_object_add(json
, "maxAgeLinkStates", json_maxage
);
6992 #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
6993 #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
6995 #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
6996 #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
6997 #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
6998 #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
7000 #define OSPF_LSA_TYPES_DESC \
7001 "ASBR summary link states\n" \
7002 "External link states\n" \
7003 "Network link states\n" \
7004 "Router link states\n" \
7005 "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \
7006 OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
7007 OSPF_LSA_TYPE_OPAQUE_AS_DESC
7009 static int show_ip_ospf_database_common(struct vty
*vty
, struct ospf
*ospf
,
7010 int arg_base
, int argc
,
7011 struct cmd_token
**argv
,
7012 uint8_t use_vrf
, json_object
*json
,
7017 struct in_addr id
, adv_router
;
7018 char buf
[PREFIX_STRLEN
];
7019 json_object
*json_vrf
= NULL
;
7023 json_vrf
= json_object_new_object();
7028 if (ospf
->instance
) {
7030 json_object_int_add(json_vrf
, "ospfInstance",
7033 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
7036 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
7038 /* Show Router ID. */
7040 json_object_string_add(json_vrf
, "routerId",
7041 inet_ntop(AF_INET
, &ospf
->router_id
,
7044 vty_out(vty
, "\n OSPF Router with ID (%pI4)\n\n",
7049 if ((argc
== arg_base
+ 4) || (uj
&& (argc
== arg_base
+ 5))) {
7050 show_ip_ospf_database_summary(vty
, ospf
, 0, json_vrf
);
7053 if (ospf
->vrf_id
== VRF_DEFAULT
)
7054 json_object_object_add(json
, "default",
7057 json_object_object_add(json
, ospf
->name
,
7064 /* Set database type to show. */
7065 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
7066 type
= OSPF_ROUTER_LSA
;
7067 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
7068 type
= OSPF_NETWORK_LSA
;
7069 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
7070 type
= OSPF_AS_NSSA_LSA
;
7071 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "su", 2) == 0)
7072 type
= OSPF_SUMMARY_LSA
;
7073 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
7074 type
= OSPF_ASBR_SUMMARY_LSA
;
7075 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
7076 type
= OSPF_AS_EXTERNAL_LSA
;
7077 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "se", 2) == 0) {
7078 show_ip_ospf_database_summary(vty
, ospf
, 1, json_vrf
);
7081 if (ospf
->vrf_id
== VRF_DEFAULT
)
7082 json_object_object_add(json
, "default",
7085 json_object_object_add(json
, ospf
->name
,
7090 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "m", 1) == 0) {
7091 show_ip_ospf_database_maxage(vty
, ospf
, json_vrf
);
7094 if (ospf
->vrf_id
== VRF_DEFAULT
)
7095 json_object_object_add(json
, "default",
7098 json_object_object_add(json
, ospf
->name
,
7103 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
7104 type
= OSPF_OPAQUE_LINK_LSA
;
7105 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
7106 type
= OSPF_OPAQUE_AREA_LSA
;
7107 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
7108 type
= OSPF_OPAQUE_AS_LSA
;
7112 /* `show ip ospf database LSA'. */
7113 if ((argc
== arg_base
+ 5) || (uj
&& (argc
== arg_base
+ 6)))
7114 show_lsa_detail(vty
, ospf
, type
, NULL
, NULL
, json_vrf
);
7115 else if (argc
>= arg_base
+ 6) {
7116 ret
= inet_aton(argv
[arg_base
+ 5]->arg
, &id
);
7120 /* `show ip ospf database LSA ID'. */
7121 if ((argc
== arg_base
+ 6) || (uj
&& (argc
== arg_base
+ 7)))
7122 show_lsa_detail(vty
, ospf
, type
, &id
, NULL
, json_vrf
);
7123 /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */
7124 else if ((argc
== arg_base
+ 7)
7125 || (uj
&& (argc
== arg_base
+ 8))) {
7126 if (strncmp(argv
[arg_base
+ 6]->text
, "s", 1) == 0)
7127 adv_router
= ospf
->router_id
;
7129 ret
= inet_aton(argv
[arg_base
+ 7]->arg
,
7134 show_lsa_detail(vty
, ospf
, type
, &id
, &adv_router
,
7141 if (ospf
->vrf_id
== VRF_DEFAULT
)
7142 json_object_object_add(json
, "default",
7145 json_object_object_add(json
, ospf
->name
,
7153 DEFUN (show_ip_ospf_database_max
,
7154 show_ip_ospf_database_max_cmd
,
7155 "show ip ospf [vrf <NAME|all>] database <max-age|self-originate> [json]",
7158 "OSPF information\n"
7161 "Database summary\n"
7162 "LSAs in MaxAge list\n"
7163 "Self-originated link states\n"
7166 struct ospf
*ospf
= NULL
;
7167 struct listnode
*node
= NULL
;
7168 char *vrf_name
= NULL
;
7169 bool all_vrf
= false;
7170 int ret
= CMD_SUCCESS
;
7173 uint8_t use_vrf
= 0;
7174 bool uj
= use_json(argc
, argv
);
7175 json_object
*json
= NULL
;
7178 json
= json_object_new_object();
7180 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
7183 bool ospf_output
= false;
7188 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
7189 if (!ospf
->oi_running
)
7192 ret
= show_ip_ospf_database_common(
7193 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
,
7198 vty_out(vty
, "%% OSPF instance not found\n");
7200 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
7201 if (ospf
== NULL
|| !ospf
->oi_running
) {
7202 vty_out(vty
, "%% OSPF instance not found\n");
7205 ret
= (show_ip_ospf_database_common(
7206 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
, use_vrf
,
7210 /* Display default ospf (instance 0) info */
7211 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
7212 if (ospf
== NULL
|| !ospf
->oi_running
) {
7213 vty_out(vty
, "%% OSPF instance not found\n");
7217 ret
= show_ip_ospf_database_common(vty
, ospf
, 0, argc
, argv
,
7222 vty_out(vty
, "%s\n", json_object_to_json_string(json
));
7223 json_object_free(json
);
7229 ALIAS (show_ip_ospf_database_max
,
7230 show_ip_ospf_database_cmd
,
7231 "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]",
7234 "OSPF information\n"
7237 "Database summary\n"
7239 "Link State ID (as an IP address)\n"
7240 "Self-originated link states\n"
7241 "Advertising Router link states\n"
7242 "Advertising Router (as an IP address)\n"
7245 DEFUN (show_ip_ospf_instance_database_max
,
7246 show_ip_ospf_instance_database_max_cmd
,
7247 "show ip ospf (1-65535) database <max-age|self-originate> [json]",
7250 "OSPF information\n"
7252 "Database summary\n"
7253 "LSAs in MaxAge list\n"
7254 "Self-originated link states\n"
7259 unsigned short instance
= 0;
7260 bool uj
= use_json(argc
, argv
);
7261 json_object
*json
= NULL
;
7264 json
= json_object_new_object();
7266 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
7267 if (instance
!= ospf_instance
)
7268 return CMD_NOT_MY_INSTANCE
;
7270 ospf
= ospf_lookup_instance(instance
);
7271 if (!ospf
|| !ospf
->oi_running
)
7274 show_ip_ospf_database_common(vty
, ospf
, 1, argc
, argv
, 0, json
, uj
);
7277 vty_out(vty
, "%s\n",
7278 json_object_to_json_string_ext(
7279 json
, JSON_C_TO_STRING_PRETTY
));
7280 json_object_free(json
);
7286 ALIAS (show_ip_ospf_instance_database_max
,
7287 show_ip_ospf_instance_database_cmd
,
7288 "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]",
7291 "OSPF information\n"
7293 "Database summary\n"
7295 "Link State ID (as an IP address)\n"
7296 "Self-originated link states\n"
7297 "Advertising Router link states\n"
7298 "Advertising Router (as an IP address)\n"
7301 static int show_ip_ospf_database_type_adv_router_common(struct vty
*vty
,
7303 int arg_base
, int argc
,
7304 struct cmd_token
**argv
,
7311 struct in_addr adv_router
;
7312 char buf
[PREFIX_STRLEN
];
7313 json_object
*json_vrf
= NULL
;
7317 json_vrf
= json_object_new_object();
7322 if (ospf
->instance
) {
7324 json_object_int_add(json
, "ospfInstance",
7327 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
7330 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
7332 /* Show Router ID. */
7334 json_object_string_add(json_vrf
, "routerId",
7335 inet_ntop(AF_INET
, &ospf
->router_id
,
7338 vty_out(vty
, "\n OSPF Router with ID (%pI4)\n\n",
7342 /* Set database type to show. */
7343 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
7344 type
= OSPF_ROUTER_LSA
;
7345 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
7346 type
= OSPF_NETWORK_LSA
;
7347 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
7348 type
= OSPF_AS_NSSA_LSA
;
7349 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "s", 1) == 0)
7350 type
= OSPF_SUMMARY_LSA
;
7351 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
7352 type
= OSPF_ASBR_SUMMARY_LSA
;
7353 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
7354 type
= OSPF_AS_EXTERNAL_LSA
;
7355 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
7356 type
= OSPF_OPAQUE_LINK_LSA
;
7357 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
7358 type
= OSPF_OPAQUE_AREA_LSA
;
7359 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
7360 type
= OSPF_OPAQUE_AS_LSA
;
7364 /* `show ip ospf database LSA adv-router ADV_ROUTER'. */
7365 if (strncmp(argv
[arg_base
+ 5]->text
, "s", 1) == 0)
7366 adv_router
= ospf
->router_id
;
7368 ret
= inet_aton(argv
[arg_base
+ 6]->arg
, &adv_router
);
7373 show_lsa_detail_adv_router(vty
, ospf
, type
, &adv_router
, json_vrf
);
7377 if (ospf
->vrf_id
== VRF_DEFAULT
)
7378 json_object_object_add(json
, "default",
7381 json_object_object_add(json
, ospf
->name
,
7389 DEFUN (show_ip_ospf_database_type_adv_router
,
7390 show_ip_ospf_database_type_adv_router_cmd
,
7391 "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]",
7394 "OSPF information\n"
7397 "Database summary\n"
7399 "Advertising Router link states\n"
7400 "Advertising Router (as an IP address)\n"
7401 "Self-originated link states\n"
7404 struct ospf
*ospf
= NULL
;
7405 struct listnode
*node
= NULL
;
7406 char *vrf_name
= NULL
;
7407 bool all_vrf
= false;
7408 int ret
= CMD_SUCCESS
;
7411 uint8_t use_vrf
= 0;
7412 bool uj
= use_json(argc
, argv
);
7413 json_object
*json
= NULL
;
7416 json
= json_object_new_object();
7418 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
7421 bool ospf_output
= false;
7426 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
7427 if (!ospf
->oi_running
)
7430 ret
= show_ip_ospf_database_type_adv_router_common(
7431 vty
, ospf
, 2, argc
, argv
, use_vrf
, json
,
7435 vty_out(vty
, "%% OSPF instance not found\n");
7437 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
7438 if ((ospf
== NULL
) || !ospf
->oi_running
) {
7439 vty_out(vty
, "%% OSPF instance not found\n");
7443 ret
= show_ip_ospf_database_type_adv_router_common(
7444 vty
, ospf
, 2, argc
, argv
, use_vrf
, json
, uj
);
7447 /* Display default ospf (instance 0) info */
7448 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
7449 if (ospf
== NULL
|| !ospf
->oi_running
) {
7450 vty_out(vty
, "%% OSPF instance not found\n");
7454 ret
= show_ip_ospf_database_type_adv_router_common(
7455 vty
, ospf
, 0, argc
, argv
, use_vrf
, json
, uj
);
7459 vty_out(vty
, "%s\n", json_object_to_json_string(json
));
7460 json_object_free(json
);
7466 DEFUN (show_ip_ospf_instance_database_type_adv_router
,
7467 show_ip_ospf_instance_database_type_adv_router_cmd
,
7468 "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]",
7471 "OSPF information\n"
7473 "Database summary\n"
7475 "Advertising Router link states\n"
7476 "Advertising Router (as an IP address)\n"
7477 "Self-originated link states\n"
7482 unsigned short instance
= 0;
7483 bool uj
= use_json(argc
, argv
);
7484 json_object
*json
= NULL
;
7487 json
= json_object_new_object();
7489 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
7490 if (instance
!= ospf_instance
)
7491 return CMD_NOT_MY_INSTANCE
;
7493 ospf
= ospf_lookup_instance(instance
);
7494 if (!ospf
|| !ospf
->oi_running
)
7497 show_ip_ospf_database_type_adv_router_common(vty
, ospf
, 1, argc
, argv
,
7501 vty_out(vty
, "%s\n",
7502 json_object_to_json_string_ext(
7503 json
, JSON_C_TO_STRING_PRETTY
));
7504 json_object_free(json
);
7510 DEFUN (ip_ospf_authentication_args
,
7511 ip_ospf_authentication_args_addr_cmd
,
7512 "ip ospf authentication <null|message-digest> [A.B.C.D]",
7514 "OSPF interface commands\n"
7515 "Enable authentication on this interface\n"
7516 "Use null authentication\n"
7517 "Use message-digest authentication\n"
7518 "Address of interface\n")
7520 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7521 int idx_encryption
= 3;
7523 struct in_addr addr
;
7525 struct ospf_if_params
*params
;
7527 params
= IF_DEF_PARAMS(ifp
);
7530 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7533 "Please specify interface address by A.B.C.D\n");
7534 return CMD_WARNING_CONFIG_FAILED
;
7537 params
= ospf_get_if_params(ifp
, addr
);
7538 ospf_if_update_params(ifp
, addr
);
7541 /* Handle null authentication */
7542 if (argv
[idx_encryption
]->arg
[0] == 'n') {
7543 SET_IF_PARAM(params
, auth_type
);
7544 params
->auth_type
= OSPF_AUTH_NULL
;
7548 /* Handle message-digest authentication */
7549 if (argv
[idx_encryption
]->arg
[0] == 'm') {
7550 SET_IF_PARAM(params
, auth_type
);
7551 params
->auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
7555 vty_out(vty
, "You shouldn't get here!\n");
7556 return CMD_WARNING_CONFIG_FAILED
;
7559 DEFUN (ip_ospf_authentication
,
7560 ip_ospf_authentication_addr_cmd
,
7561 "ip ospf authentication [A.B.C.D]",
7563 "OSPF interface commands\n"
7564 "Enable authentication on this interface\n"
7565 "Address of interface\n")
7567 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7569 struct in_addr addr
;
7571 struct ospf_if_params
*params
;
7573 params
= IF_DEF_PARAMS(ifp
);
7576 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7579 "Please specify interface address by A.B.C.D\n");
7580 return CMD_WARNING_CONFIG_FAILED
;
7583 params
= ospf_get_if_params(ifp
, addr
);
7584 ospf_if_update_params(ifp
, addr
);
7587 SET_IF_PARAM(params
, auth_type
);
7588 params
->auth_type
= OSPF_AUTH_SIMPLE
;
7593 DEFUN (no_ip_ospf_authentication_args
,
7594 no_ip_ospf_authentication_args_addr_cmd
,
7595 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
7598 "OSPF interface commands\n"
7599 "Enable authentication on this interface\n"
7600 "Use null authentication\n"
7601 "Use message-digest authentication\n"
7602 "Address of interface\n")
7604 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7605 int idx_encryption
= 4;
7607 struct in_addr addr
;
7609 struct ospf_if_params
*params
;
7610 struct route_node
*rn
;
7613 params
= IF_DEF_PARAMS(ifp
);
7616 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7619 "Please specify interface address by A.B.C.D\n");
7620 return CMD_WARNING_CONFIG_FAILED
;
7623 params
= ospf_lookup_if_params(ifp
, addr
);
7624 if (params
== NULL
) {
7625 vty_out(vty
, "Ip Address specified is unknown\n");
7626 return CMD_WARNING_CONFIG_FAILED
;
7628 params
->auth_type
= OSPF_AUTH_NOTSET
;
7629 UNSET_IF_PARAM(params
, auth_type
);
7630 if (params
!= IF_DEF_PARAMS(ifp
)) {
7631 ospf_free_if_params(ifp
, addr
);
7632 ospf_if_update_params(ifp
, addr
);
7635 if (argv
[idx_encryption
]->arg
[0] == 'n') {
7636 auth_type
= OSPF_AUTH_NULL
;
7637 } else if (argv
[idx_encryption
]->arg
[0] == 'm') {
7638 auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
7640 vty_out(vty
, "Unexpected input encountered\n");
7641 return CMD_WARNING_CONFIG_FAILED
;
7644 * Here we have a case where the user has entered
7645 * 'no ip ospf authentication (null | message_digest )'
7646 * we need to find if we have any ip addresses underneath it
7648 * correspond to the associated type.
7650 if (params
->auth_type
== auth_type
) {
7651 params
->auth_type
= OSPF_AUTH_NOTSET
;
7652 UNSET_IF_PARAM(params
, auth_type
);
7655 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
7656 rn
= route_next(rn
)) {
7657 if ((params
= rn
->info
)) {
7658 if (params
->auth_type
== auth_type
) {
7659 params
->auth_type
= OSPF_AUTH_NOTSET
;
7660 UNSET_IF_PARAM(params
, auth_type
);
7661 if (params
!= IF_DEF_PARAMS(ifp
)) {
7662 ospf_free_if_params(
7663 ifp
, rn
->p
.u
.prefix4
);
7664 ospf_if_update_params(
7665 ifp
, rn
->p
.u
.prefix4
);
7675 DEFUN (no_ip_ospf_authentication
,
7676 no_ip_ospf_authentication_addr_cmd
,
7677 "no ip ospf authentication [A.B.C.D]",
7680 "OSPF interface commands\n"
7681 "Enable authentication on this interface\n"
7682 "Address of interface\n")
7684 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7686 struct in_addr addr
;
7688 struct ospf_if_params
*params
;
7689 struct route_node
*rn
;
7691 params
= IF_DEF_PARAMS(ifp
);
7694 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7697 "Please specify interface address by A.B.C.D\n");
7698 return CMD_WARNING_CONFIG_FAILED
;
7701 params
= ospf_lookup_if_params(ifp
, addr
);
7702 if (params
== NULL
) {
7703 vty_out(vty
, "Ip Address specified is unknown\n");
7704 return CMD_WARNING_CONFIG_FAILED
;
7707 params
->auth_type
= OSPF_AUTH_NOTSET
;
7708 UNSET_IF_PARAM(params
, auth_type
);
7709 if (params
!= IF_DEF_PARAMS(ifp
)) {
7710 ospf_free_if_params(ifp
, addr
);
7711 ospf_if_update_params(ifp
, addr
);
7715 * When a user enters 'no ip ospf authentication'
7716 * We should remove all authentication types from
7719 if ((params
->auth_type
== OSPF_AUTH_NULL
)
7720 || (params
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
7721 || (params
->auth_type
== OSPF_AUTH_SIMPLE
)) {
7722 params
->auth_type
= OSPF_AUTH_NOTSET
;
7723 UNSET_IF_PARAM(params
, auth_type
);
7726 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
7727 rn
= route_next(rn
)) {
7728 if ((params
= rn
->info
)) {
7730 if ((params
->auth_type
== OSPF_AUTH_NULL
)
7731 || (params
->auth_type
7732 == OSPF_AUTH_CRYPTOGRAPHIC
)
7733 || (params
->auth_type
7734 == OSPF_AUTH_SIMPLE
)) {
7735 params
->auth_type
= OSPF_AUTH_NOTSET
;
7736 UNSET_IF_PARAM(params
, auth_type
);
7737 if (params
!= IF_DEF_PARAMS(ifp
)) {
7738 ospf_free_if_params(
7739 ifp
, rn
->p
.u
.prefix4
);
7740 ospf_if_update_params(
7741 ifp
, rn
->p
.u
.prefix4
);
7752 DEFUN (ip_ospf_authentication_key
,
7753 ip_ospf_authentication_key_addr_cmd
,
7754 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
7756 "OSPF interface commands\n"
7757 "Authentication password (key)\n"
7758 "The OSPF password (key)\n"
7759 "Address of interface\n")
7761 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7763 struct in_addr addr
;
7764 struct ospf_if_params
*params
;
7766 params
= IF_DEF_PARAMS(ifp
);
7768 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7769 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7771 "Please specify interface address by A.B.C.D\n");
7772 return CMD_WARNING_CONFIG_FAILED
;
7775 params
= ospf_get_if_params(ifp
, addr
);
7776 ospf_if_update_params(ifp
, addr
);
7779 strlcpy((char *)params
->auth_simple
, argv
[3]->arg
,
7780 sizeof(params
->auth_simple
));
7781 SET_IF_PARAM(params
, auth_simple
);
7786 DEFUN_HIDDEN (ospf_authentication_key
,
7787 ospf_authentication_key_cmd
,
7788 "ospf authentication-key AUTH_KEY [A.B.C.D]",
7789 "OSPF interface commands\n"
7790 VLINK_HELPSTR_AUTH_SIMPLE
7791 "Address of interface\n")
7793 return ip_ospf_authentication_key(self
, vty
, argc
, argv
);
7796 DEFUN (no_ip_ospf_authentication_key
,
7797 no_ip_ospf_authentication_key_authkey_addr_cmd
,
7798 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7801 "OSPF interface commands\n"
7802 VLINK_HELPSTR_AUTH_SIMPLE
7803 "Address of interface\n")
7805 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7807 struct in_addr addr
;
7808 struct ospf_if_params
*params
;
7809 params
= IF_DEF_PARAMS(ifp
);
7811 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7812 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7814 "Please specify interface address by A.B.C.D\n");
7815 return CMD_WARNING_CONFIG_FAILED
;
7818 params
= ospf_lookup_if_params(ifp
, addr
);
7823 memset(params
->auth_simple
, 0, OSPF_AUTH_SIMPLE_SIZE
);
7824 UNSET_IF_PARAM(params
, auth_simple
);
7826 if (params
!= IF_DEF_PARAMS(ifp
)) {
7827 ospf_free_if_params(ifp
, addr
);
7828 ospf_if_update_params(ifp
, addr
);
7834 DEFUN_HIDDEN (no_ospf_authentication_key
,
7835 no_ospf_authentication_key_authkey_addr_cmd
,
7836 "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7838 "OSPF interface commands\n"
7839 VLINK_HELPSTR_AUTH_SIMPLE
7840 "Address of interface\n")
7842 return no_ip_ospf_authentication_key(self
, vty
, argc
, argv
);
7845 DEFUN (ip_ospf_message_digest_key
,
7846 ip_ospf_message_digest_key_cmd
,
7847 "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7849 "OSPF interface commands\n"
7850 "Message digest authentication password (key)\n"
7852 "Use MD5 algorithm\n"
7853 "The OSPF password (key)\n"
7854 "Address of interface\n")
7856 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7857 struct crypt_key
*ck
;
7859 struct in_addr addr
;
7860 struct ospf_if_params
*params
;
7862 params
= IF_DEF_PARAMS(ifp
);
7865 argv_find(argv
, argc
, "(1-255)", &idx
);
7866 char *keyid
= argv
[idx
]->arg
;
7867 argv_find(argv
, argc
, "KEY", &idx
);
7868 char *cryptkey
= argv
[idx
]->arg
;
7870 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7871 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7873 "Please specify interface address by A.B.C.D\n");
7874 return CMD_WARNING_CONFIG_FAILED
;
7877 params
= ospf_get_if_params(ifp
, addr
);
7878 ospf_if_update_params(ifp
, addr
);
7881 key_id
= strtol(keyid
, NULL
, 10);
7883 /* Remove existing key, if any */
7884 ospf_crypt_key_delete(params
->auth_crypt
, key_id
);
7886 ck
= ospf_crypt_key_new();
7887 ck
->key_id
= (uint8_t)key_id
;
7888 strlcpy((char *)ck
->auth_key
, cryptkey
, sizeof(ck
->auth_key
));
7890 ospf_crypt_key_add(params
->auth_crypt
, ck
);
7891 SET_IF_PARAM(params
, auth_crypt
);
7896 DEFUN_HIDDEN (ospf_message_digest_key
,
7897 ospf_message_digest_key_cmd
,
7898 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7899 "OSPF interface commands\n"
7900 "Message digest authentication password (key)\n"
7902 "Use MD5 algorithm\n"
7903 "The OSPF password (key)\n"
7904 "Address of interface\n")
7906 return ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7909 DEFUN (no_ip_ospf_message_digest_key
,
7910 no_ip_ospf_message_digest_key_cmd
,
7911 "no ip 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 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7923 struct crypt_key
*ck
;
7925 struct in_addr addr
;
7926 struct ospf_if_params
*params
;
7927 params
= IF_DEF_PARAMS(ifp
);
7929 argv_find(argv
, argc
, "(1-255)", &idx
);
7930 char *keyid
= argv
[idx
]->arg
;
7932 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7933 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7935 "Please specify interface address by A.B.C.D\n");
7936 return CMD_WARNING_CONFIG_FAILED
;
7939 params
= ospf_lookup_if_params(ifp
, addr
);
7944 key_id
= strtol(keyid
, NULL
, 10);
7945 ck
= ospf_crypt_key_lookup(params
->auth_crypt
, key_id
);
7947 vty_out(vty
, "OSPF: Key %d does not exist\n", key_id
);
7948 return CMD_WARNING_CONFIG_FAILED
;
7951 ospf_crypt_key_delete(params
->auth_crypt
, key_id
);
7953 if (params
!= IF_DEF_PARAMS(ifp
)) {
7954 ospf_free_if_params(ifp
, addr
);
7955 ospf_if_update_params(ifp
, addr
);
7961 DEFUN_HIDDEN (no_ospf_message_digest_key
,
7962 no_ospf_message_digest_key_cmd
,
7963 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7965 "OSPF interface commands\n"
7966 "Message digest authentication password (key)\n"
7968 "Use MD5 algorithm\n"
7969 "The OSPF password (key)\n"
7970 "Address of interface\n")
7972 return no_ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7975 DEFUN (ip_ospf_cost
,
7977 "ip ospf cost (1-65535) [A.B.C.D]",
7979 "OSPF interface commands\n"
7982 "Address of interface\n")
7984 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7986 uint32_t cost
= OSPF_OUTPUT_COST_DEFAULT
;
7987 struct in_addr addr
;
7988 struct ospf_if_params
*params
;
7989 params
= IF_DEF_PARAMS(ifp
);
7992 char *coststr
= NULL
, *ifaddr
= NULL
;
7994 argv_find(argv
, argc
, "(1-65535)", &idx
);
7995 coststr
= argv
[idx
]->arg
;
7996 cost
= strtol(coststr
, NULL
, 10);
7998 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
8000 if (!inet_aton(ifaddr
, &addr
)) {
8002 "Please specify interface address by A.B.C.D\n");
8003 return CMD_WARNING_CONFIG_FAILED
;
8006 params
= ospf_get_if_params(ifp
, addr
);
8007 ospf_if_update_params(ifp
, addr
);
8010 SET_IF_PARAM(params
, output_cost_cmd
);
8011 params
->output_cost_cmd
= cost
;
8013 ospf_if_recalculate_output_cost(ifp
);
8018 DEFUN_HIDDEN (ospf_cost
,
8020 "ospf cost (1-65535) [A.B.C.D]",
8021 "OSPF interface commands\n"
8024 "Address of interface\n")
8026 return ip_ospf_cost(self
, vty
, argc
, argv
);
8029 DEFUN (no_ip_ospf_cost
,
8030 no_ip_ospf_cost_cmd
,
8031 "no ip ospf cost [(1-65535)] [A.B.C.D]",
8034 "OSPF interface commands\n"
8037 "Address of interface\n")
8039 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8041 struct in_addr addr
;
8042 struct ospf_if_params
*params
;
8044 params
= IF_DEF_PARAMS(ifp
);
8047 char *ifaddr
= NULL
;
8048 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
8050 /* According to the semantics we are mimicking "no ip ospf cost N" is
8051 * always treated as "no ip ospf cost" regardless of the actual value
8052 * of N already configured for the interface. Thus ignore cost. */
8055 if (!inet_aton(ifaddr
, &addr
)) {
8057 "Please specify interface address by A.B.C.D\n");
8058 return CMD_WARNING_CONFIG_FAILED
;
8061 params
= ospf_lookup_if_params(ifp
, addr
);
8066 UNSET_IF_PARAM(params
, output_cost_cmd
);
8068 if (params
!= IF_DEF_PARAMS(ifp
)) {
8069 ospf_free_if_params(ifp
, addr
);
8070 ospf_if_update_params(ifp
, addr
);
8073 ospf_if_recalculate_output_cost(ifp
);
8078 DEFUN_HIDDEN (no_ospf_cost
,
8080 "no ospf cost [(1-65535)] [A.B.C.D]",
8082 "OSPF interface commands\n"
8085 "Address of interface\n")
8087 return no_ip_ospf_cost(self
, vty
, argc
, argv
);
8090 static void ospf_nbr_timer_update(struct ospf_interface
*oi
)
8092 struct route_node
*rn
;
8093 struct ospf_neighbor
*nbr
;
8095 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
8096 if ((nbr
= rn
->info
)) {
8097 nbr
->v_inactivity
= OSPF_IF_PARAM(oi
, v_wait
);
8098 nbr
->v_db_desc
= OSPF_IF_PARAM(oi
, retransmit_interval
);
8099 nbr
->v_ls_req
= OSPF_IF_PARAM(oi
, retransmit_interval
);
8100 nbr
->v_ls_upd
= OSPF_IF_PARAM(oi
, retransmit_interval
);
8104 static int ospf_vty_dead_interval_set(struct vty
*vty
, const char *interval_str
,
8105 const char *nbr_str
,
8106 const char *fast_hello_str
)
8108 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8111 struct in_addr addr
;
8113 struct ospf_if_params
*params
;
8114 struct ospf_interface
*oi
;
8115 struct route_node
*rn
;
8117 params
= IF_DEF_PARAMS(ifp
);
8120 ret
= inet_aton(nbr_str
, &addr
);
8123 "Please specify interface address by A.B.C.D\n");
8124 return CMD_WARNING_CONFIG_FAILED
;
8127 params
= ospf_get_if_params(ifp
, addr
);
8128 ospf_if_update_params(ifp
, addr
);
8132 seconds
= strtoul(interval_str
, NULL
, 10);
8134 /* reset fast_hello too, just to be sure */
8135 UNSET_IF_PARAM(params
, fast_hello
);
8136 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
8137 } else if (fast_hello_str
) {
8138 hellomult
= strtoul(fast_hello_str
, NULL
, 10);
8139 /* 1s dead-interval with sub-second hellos desired */
8140 seconds
= OSPF_ROUTER_DEAD_INTERVAL_MINIMAL
;
8141 SET_IF_PARAM(params
, fast_hello
);
8142 params
->fast_hello
= hellomult
;
8145 "Please specify dead-interval or hello-multiplier\n");
8146 return CMD_WARNING_CONFIG_FAILED
;
8149 SET_IF_PARAM(params
, v_wait
);
8150 params
->v_wait
= seconds
;
8151 params
->is_v_wait_set
= true;
8153 /* Update timer values in neighbor structure. */
8155 struct ospf
*ospf
= NULL
;
8157 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
8159 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
8161 ospf_nbr_timer_update(oi
);
8164 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
8165 if ((oi
= rn
->info
))
8166 ospf_nbr_timer_update(oi
);
8172 DEFUN (ip_ospf_dead_interval
,
8173 ip_ospf_dead_interval_cmd
,
8174 "ip ospf dead-interval (1-65535) [A.B.C.D]",
8176 "OSPF interface commands\n"
8177 "Interval time after which a neighbor is declared down\n"
8179 "Address of interface\n")
8182 char *interval
= argv_find(argv
, argc
, "(1-65535)", &idx
)
8186 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
8187 return ospf_vty_dead_interval_set(vty
, interval
, ifaddr
, NULL
);
8191 DEFUN_HIDDEN (ospf_dead_interval
,
8192 ospf_dead_interval_cmd
,
8193 "ospf dead-interval (1-65535) [A.B.C.D]",
8194 "OSPF interface commands\n"
8195 "Interval time after which a neighbor is declared down\n"
8197 "Address of interface\n")
8199 return ip_ospf_dead_interval(self
, vty
, argc
, argv
);
8202 DEFUN (ip_ospf_dead_interval_minimal
,
8203 ip_ospf_dead_interval_minimal_addr_cmd
,
8204 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
8206 "OSPF interface commands\n"
8207 "Interval time after which a neighbor is declared down\n"
8208 "Minimal 1s dead-interval with fast sub-second hellos\n"
8209 "Hello multiplier factor\n"
8210 "Number of Hellos to send each second\n"
8211 "Address of interface\n")
8216 return ospf_vty_dead_interval_set(
8217 vty
, NULL
, argv
[idx_ipv4
]->arg
, argv
[idx_number
]->arg
);
8219 return ospf_vty_dead_interval_set(vty
, NULL
, NULL
,
8220 argv
[idx_number
]->arg
);
8223 DEFUN (no_ip_ospf_dead_interval
,
8224 no_ip_ospf_dead_interval_cmd
,
8225 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8228 "OSPF interface commands\n"
8229 "Interval time after which a neighbor is declared down\n"
8231 "Minimal 1s dead-interval with fast sub-second hellos\n"
8232 "Hello multiplier factor\n"
8233 "Number of Hellos to send each second\n"
8234 "Address of interface\n")
8236 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8237 int idx_ipv4
= argc
- 1;
8238 struct in_addr addr
= {.s_addr
= 0L};
8240 struct ospf_if_params
*params
;
8241 struct ospf_interface
*oi
;
8242 struct route_node
*rn
;
8244 params
= IF_DEF_PARAMS(ifp
);
8246 if (argv
[idx_ipv4
]->type
== IPV4_TKN
) {
8247 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8250 "Please specify interface address by A.B.C.D\n");
8251 return CMD_WARNING_CONFIG_FAILED
;
8254 params
= ospf_lookup_if_params(ifp
, addr
);
8259 UNSET_IF_PARAM(params
, v_wait
);
8260 params
->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
8261 params
->is_v_wait_set
= false;
8263 UNSET_IF_PARAM(params
, fast_hello
);
8264 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
8266 if (params
!= IF_DEF_PARAMS(ifp
)) {
8267 ospf_free_if_params(ifp
, addr
);
8268 ospf_if_update_params(ifp
, addr
);
8271 /* Update timer values in neighbor structure. */
8273 struct ospf
*ospf
= NULL
;
8275 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
8277 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
8279 ospf_nbr_timer_update(oi
);
8282 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
8283 if ((oi
= rn
->info
))
8284 ospf_nbr_timer_update(oi
);
8290 DEFUN_HIDDEN (no_ospf_dead_interval
,
8291 no_ospf_dead_interval_cmd
,
8292 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8294 "OSPF interface commands\n"
8295 "Interval time after which a neighbor is declared down\n"
8297 "Minimal 1s dead-interval with fast sub-second hellos\n"
8298 "Hello multiplier factor\n"
8299 "Number of Hellos to send each second\n"
8300 "Address of interface\n")
8302 return no_ip_ospf_dead_interval(self
, vty
, argc
, argv
);
8305 DEFUN (ip_ospf_hello_interval
,
8306 ip_ospf_hello_interval_cmd
,
8307 "ip ospf hello-interval (1-65535) [A.B.C.D]",
8309 "OSPF interface commands\n"
8310 "Time between HELLO packets\n"
8312 "Address of interface\n")
8314 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8316 struct in_addr addr
= {.s_addr
= 0L};
8317 struct ospf_if_params
*params
;
8318 params
= IF_DEF_PARAMS(ifp
);
8319 uint32_t seconds
= 0;
8320 bool is_addr
= false;
8321 uint32_t old_interval
= 0;
8323 argv_find(argv
, argc
, "(1-65535)", &idx
);
8324 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
8326 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8327 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8329 "Please specify interface address by A.B.C.D\n");
8330 return CMD_WARNING_CONFIG_FAILED
;
8333 params
= ospf_get_if_params(ifp
, addr
);
8334 ospf_if_update_params(ifp
, addr
);
8338 old_interval
= params
->v_hello
;
8340 /* Return, if same interval is configured. */
8341 if (old_interval
== seconds
)
8344 SET_IF_PARAM(params
, v_hello
);
8345 params
->v_hello
= seconds
;
8347 if (!params
->is_v_wait_set
) {
8348 SET_IF_PARAM(params
, v_wait
);
8350 * The router dead interval should
8351 * be some multiple of the HelloInterval (perhaps 4 times the
8352 * hello interval) and must be the same for all routers
8353 * attached to a common network.
8355 params
->v_wait
= 4 * seconds
;
8358 ospf_reset_hello_timer(ifp
, addr
, is_addr
);
8363 DEFUN_HIDDEN (ospf_hello_interval
,
8364 ospf_hello_interval_cmd
,
8365 "ospf hello-interval (1-65535) [A.B.C.D]",
8366 "OSPF interface commands\n"
8367 "Time between HELLO packets\n"
8369 "Address of interface\n")
8371 return ip_ospf_hello_interval(self
, vty
, argc
, argv
);
8374 DEFUN (no_ip_ospf_hello_interval
,
8375 no_ip_ospf_hello_interval_cmd
,
8376 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
8379 "OSPF interface commands\n"
8380 "Time between HELLO packets\n" // ignored
8382 "Address of interface\n")
8384 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8386 struct in_addr addr
= {.s_addr
= 0L};
8387 struct ospf_if_params
*params
;
8388 struct route_node
*rn
;
8390 params
= IF_DEF_PARAMS(ifp
);
8392 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8393 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8395 "Please specify interface address by A.B.C.D\n");
8396 return CMD_WARNING_CONFIG_FAILED
;
8399 params
= ospf_lookup_if_params(ifp
, addr
);
8404 UNSET_IF_PARAM(params
, v_hello
);
8405 params
->v_hello
= OSPF_HELLO_INTERVAL_DEFAULT
;
8407 if (!params
->is_v_wait_set
) {
8408 UNSET_IF_PARAM(params
, v_wait
);
8409 params
->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
8412 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8413 struct ospf_interface
*oi
= rn
->info
;
8418 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
8419 oi
->ptp_dmvpn
= IF_DEF_PARAMS(ifp
)->ptp_dmvpn
;
8421 if (oi
->state
> ISM_Down
) {
8422 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
8423 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
8427 if (params
!= IF_DEF_PARAMS(ifp
)) {
8428 ospf_free_if_params(ifp
, addr
);
8429 ospf_if_update_params(ifp
, addr
);
8435 DEFUN_HIDDEN (no_ospf_hello_interval
,
8436 no_ospf_hello_interval_cmd
,
8437 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
8439 "OSPF interface commands\n"
8440 "Time between HELLO packets\n" // ignored
8442 "Address of interface\n")
8444 return no_ip_ospf_hello_interval(self
, vty
, argc
, argv
);
8447 DEFUN(ip_ospf_network
, ip_ospf_network_cmd
,
8448 "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point [dmvpn]>",
8450 "OSPF interface commands\n"
8452 "Specify OSPF broadcast multi-access network\n"
8453 "Specify OSPF NBMA network\n"
8454 "Specify OSPF point-to-multipoint network\n"
8455 "Specify OSPF point-to-point network\n"
8456 "Specify OSPF point-to-point DMVPN network\n")
8458 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8460 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
8461 uint8_t old_ptp_dmvpn
= IF_DEF_PARAMS(ifp
)->ptp_dmvpn
;
8462 struct route_node
*rn
;
8464 if (old_type
== OSPF_IFTYPE_LOOPBACK
) {
8466 "This is a loopback interface. Can't set network type.\n");
8467 return CMD_WARNING_CONFIG_FAILED
;
8470 IF_DEF_PARAMS(ifp
)->ptp_dmvpn
= 0;
8472 if (argv_find(argv
, argc
, "broadcast", &idx
))
8473 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_BROADCAST
;
8474 else if (argv_find(argv
, argc
, "non-broadcast", &idx
))
8475 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_NBMA
;
8476 else if (argv_find(argv
, argc
, "point-to-multipoint", &idx
))
8477 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOMULTIPOINT
;
8478 else if (argv_find(argv
, argc
, "point-to-point", &idx
)) {
8479 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOPOINT
;
8480 if (argv_find(argv
, argc
, "dmvpn", &idx
))
8481 IF_DEF_PARAMS(ifp
)->ptp_dmvpn
= 1;
8484 if (IF_DEF_PARAMS(ifp
)->type
== old_type
8485 && IF_DEF_PARAMS(ifp
)->ptp_dmvpn
== old_ptp_dmvpn
)
8488 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), type
);
8490 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8491 struct ospf_interface
*oi
= rn
->info
;
8496 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
8498 if (oi
->state
> ISM_Down
) {
8499 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
8500 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
8507 DEFUN_HIDDEN (ospf_network
,
8509 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
8510 "OSPF interface commands\n"
8512 "Specify OSPF broadcast multi-access network\n"
8513 "Specify OSPF NBMA network\n"
8514 "Specify OSPF point-to-multipoint network\n"
8515 "Specify OSPF point-to-point network\n")
8517 return ip_ospf_network(self
, vty
, argc
, argv
);
8520 DEFUN (no_ip_ospf_network
,
8521 no_ip_ospf_network_cmd
,
8522 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8525 "OSPF interface commands\n"
8527 "Specify OSPF broadcast multi-access network\n"
8528 "Specify OSPF NBMA network\n"
8529 "Specify OSPF point-to-multipoint network\n"
8530 "Specify OSPF point-to-point network\n")
8532 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8533 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
8534 struct route_node
*rn
;
8536 IF_DEF_PARAMS(ifp
)->type
= ospf_default_iftype(ifp
);
8537 IF_DEF_PARAMS(ifp
)->ptp_dmvpn
= 0;
8539 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
8542 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8543 struct ospf_interface
*oi
= rn
->info
;
8548 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
8550 if (oi
->state
> ISM_Down
) {
8551 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
8552 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
8559 DEFUN_HIDDEN (no_ospf_network
,
8560 no_ospf_network_cmd
,
8561 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8563 "OSPF interface commands\n"
8565 "Specify OSPF broadcast multi-access network\n"
8566 "Specify OSPF NBMA network\n"
8567 "Specify OSPF point-to-multipoint network\n"
8568 "Specify OSPF point-to-point network\n")
8570 return no_ip_ospf_network(self
, vty
, argc
, argv
);
8573 DEFUN (ip_ospf_priority
,
8574 ip_ospf_priority_cmd
,
8575 "ip ospf priority (0-255) [A.B.C.D]",
8577 "OSPF interface commands\n"
8580 "Address of interface\n")
8582 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8585 struct route_node
*rn
;
8586 struct in_addr addr
;
8587 struct ospf_if_params
*params
;
8588 params
= IF_DEF_PARAMS(ifp
);
8590 argv_find(argv
, argc
, "(0-255)", &idx
);
8591 priority
= strtol(argv
[idx
]->arg
, NULL
, 10);
8593 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8594 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8596 "Please specify interface address by A.B.C.D\n");
8597 return CMD_WARNING_CONFIG_FAILED
;
8600 params
= ospf_get_if_params(ifp
, addr
);
8601 ospf_if_update_params(ifp
, addr
);
8604 SET_IF_PARAM(params
, priority
);
8605 params
->priority
= priority
;
8607 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8608 struct ospf_interface
*oi
= rn
->info
;
8613 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
8614 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
8615 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
8622 DEFUN_HIDDEN (ospf_priority
,
8624 "ospf priority (0-255) [A.B.C.D]",
8625 "OSPF interface commands\n"
8628 "Address of interface\n")
8630 return ip_ospf_priority(self
, vty
, argc
, argv
);
8633 DEFUN (no_ip_ospf_priority
,
8634 no_ip_ospf_priority_cmd
,
8635 "no ip ospf priority [(0-255) [A.B.C.D]]",
8638 "OSPF interface commands\n"
8639 "Router priority\n" // ignored
8641 "Address of interface\n")
8643 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8645 struct route_node
*rn
;
8646 struct in_addr addr
;
8647 struct ospf_if_params
*params
;
8649 params
= IF_DEF_PARAMS(ifp
);
8651 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8652 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8654 "Please specify interface address by A.B.C.D\n");
8655 return CMD_WARNING_CONFIG_FAILED
;
8658 params
= ospf_lookup_if_params(ifp
, addr
);
8663 UNSET_IF_PARAM(params
, priority
);
8664 params
->priority
= OSPF_ROUTER_PRIORITY_DEFAULT
;
8666 if (params
!= IF_DEF_PARAMS(ifp
)) {
8667 ospf_free_if_params(ifp
, addr
);
8668 ospf_if_update_params(ifp
, addr
);
8671 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8672 struct ospf_interface
*oi
= rn
->info
;
8677 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
8678 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
8679 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
8686 DEFUN_HIDDEN (no_ospf_priority
,
8687 no_ospf_priority_cmd
,
8688 "no ospf priority [(0-255) [A.B.C.D]]",
8690 "OSPF interface commands\n"
8693 "Address of interface\n")
8695 return no_ip_ospf_priority(self
, vty
, argc
, argv
);
8698 DEFUN (ip_ospf_retransmit_interval
,
8699 ip_ospf_retransmit_interval_addr_cmd
,
8700 "ip ospf retransmit-interval (1-65535) [A.B.C.D]",
8702 "OSPF interface commands\n"
8703 "Time between retransmitting lost link state advertisements\n"
8705 "Address of interface\n")
8707 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8710 struct in_addr addr
;
8711 struct ospf_if_params
*params
;
8712 params
= IF_DEF_PARAMS(ifp
);
8714 argv_find(argv
, argc
, "(1-65535)", &idx
);
8715 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
8717 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8718 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8720 "Please specify interface address by A.B.C.D\n");
8721 return CMD_WARNING_CONFIG_FAILED
;
8724 params
= ospf_get_if_params(ifp
, addr
);
8725 ospf_if_update_params(ifp
, addr
);
8728 SET_IF_PARAM(params
, retransmit_interval
);
8729 params
->retransmit_interval
= seconds
;
8734 DEFUN_HIDDEN (ospf_retransmit_interval
,
8735 ospf_retransmit_interval_cmd
,
8736 "ospf retransmit-interval (1-65535) [A.B.C.D]",
8737 "OSPF interface commands\n"
8738 "Time between retransmitting lost link state advertisements\n"
8740 "Address of interface\n")
8742 return ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
8745 DEFUN (no_ip_ospf_retransmit_interval
,
8746 no_ip_ospf_retransmit_interval_addr_cmd
,
8747 "no ip ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8750 "OSPF interface commands\n"
8751 "Time between retransmitting lost link state advertisements\n"
8753 "Address of interface\n")
8755 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8757 struct in_addr addr
;
8758 struct ospf_if_params
*params
;
8760 params
= IF_DEF_PARAMS(ifp
);
8762 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8763 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8765 "Please specify interface address by A.B.C.D\n");
8766 return CMD_WARNING_CONFIG_FAILED
;
8769 params
= ospf_lookup_if_params(ifp
, addr
);
8774 UNSET_IF_PARAM(params
, retransmit_interval
);
8775 params
->retransmit_interval
= OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
8777 if (params
!= IF_DEF_PARAMS(ifp
)) {
8778 ospf_free_if_params(ifp
, addr
);
8779 ospf_if_update_params(ifp
, addr
);
8785 DEFUN_HIDDEN (no_ospf_retransmit_interval
,
8786 no_ospf_retransmit_interval_cmd
,
8787 "no ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8789 "OSPF interface commands\n"
8790 "Time between retransmitting lost link state advertisements\n"
8792 "Address of interface\n")
8794 return no_ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
8797 DEFUN (ip_ospf_transmit_delay
,
8798 ip_ospf_transmit_delay_addr_cmd
,
8799 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
8801 "OSPF interface commands\n"
8802 "Link state transmit delay\n"
8804 "Address of interface\n")
8806 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8809 struct in_addr addr
;
8810 struct ospf_if_params
*params
;
8812 params
= IF_DEF_PARAMS(ifp
);
8813 argv_find(argv
, argc
, "(1-65535)", &idx
);
8814 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
8816 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8817 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8819 "Please specify interface address by A.B.C.D\n");
8820 return CMD_WARNING_CONFIG_FAILED
;
8823 params
= ospf_get_if_params(ifp
, addr
);
8824 ospf_if_update_params(ifp
, addr
);
8827 SET_IF_PARAM(params
, transmit_delay
);
8828 params
->transmit_delay
= seconds
;
8833 DEFUN_HIDDEN (ospf_transmit_delay
,
8834 ospf_transmit_delay_cmd
,
8835 "ospf transmit-delay (1-65535) [A.B.C.D]",
8836 "OSPF interface commands\n"
8837 "Link state transmit delay\n"
8839 "Address of interface\n")
8841 return ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
8844 DEFUN (no_ip_ospf_transmit_delay
,
8845 no_ip_ospf_transmit_delay_addr_cmd
,
8846 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
8849 "OSPF interface commands\n"
8850 "Link state transmit delay\n"
8852 "Address of interface\n")
8854 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8856 struct in_addr addr
;
8857 struct ospf_if_params
*params
;
8859 params
= IF_DEF_PARAMS(ifp
);
8861 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8862 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8864 "Please specify interface address by A.B.C.D\n");
8865 return CMD_WARNING_CONFIG_FAILED
;
8868 params
= ospf_lookup_if_params(ifp
, addr
);
8873 UNSET_IF_PARAM(params
, transmit_delay
);
8874 params
->transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
8876 if (params
!= IF_DEF_PARAMS(ifp
)) {
8877 ospf_free_if_params(ifp
, addr
);
8878 ospf_if_update_params(ifp
, addr
);
8885 DEFUN_HIDDEN (no_ospf_transmit_delay
,
8886 no_ospf_transmit_delay_cmd
,
8887 "no ospf transmit-delay [(1-65535) [A.B.C.D]]",
8889 "OSPF interface commands\n"
8890 "Link state transmit delay\n"
8892 "Address of interface\n")
8894 return no_ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
8897 DEFUN (ip_ospf_area
,
8899 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]",
8901 "OSPF interface commands\n"
8903 "Enable OSPF on this interface\n"
8904 "OSPF area ID in IP address format\n"
8905 "OSPF area ID as a decimal value\n"
8906 "Address of interface\n")
8908 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8911 struct in_addr area_id
;
8912 struct in_addr addr
;
8913 struct ospf_if_params
*params
= NULL
;
8914 struct route_node
*rn
;
8915 struct ospf
*ospf
= NULL
;
8916 unsigned short instance
= 0;
8920 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
8921 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
8923 argv_find(argv
, argc
, "area", &idx
);
8924 areaid
= argv
[idx
+ 1]->arg
;
8927 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
8929 ospf
= ospf_lookup_instance(instance
);
8931 if (instance
&& instance
!= ospf_instance
) {
8933 * At this point we know we have received
8934 * an instance and there is no ospf instance
8935 * associated with it. This means we are
8936 * in a situation where we have an
8937 * ospf command that is setup for a different
8938 * process(instance). We need to safely
8939 * remove the command from ourselves and
8940 * allow the other instance(process) handle
8941 * the configuration command.
8945 params
= IF_DEF_PARAMS(ifp
);
8946 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8947 UNSET_IF_PARAM(params
, if_area
);
8951 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
; rn
= route_next(rn
))
8952 if ((params
= rn
->info
) && OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8953 UNSET_IF_PARAM(params
, if_area
);
8958 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
8960 ospf_interface_area_unset(ospf
, ifp
);
8963 return CMD_NOT_MY_INSTANCE
;
8966 ret
= str2area_id(areaid
, &area_id
, &format
);
8968 vty_out(vty
, "Please specify area by A.B.C.D|<0-4294967295>\n");
8969 return CMD_WARNING_CONFIG_FAILED
;
8971 if (memcmp(ifp
->name
, "VLINK", 5) == 0) {
8972 vty_out(vty
, "Cannot enable OSPF on a virtual link.\n");
8973 return CMD_WARNING_CONFIG_FAILED
;
8977 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
)) {
8978 if (rn
->info
!= NULL
) {
8980 "Please remove all network commands first.\n");
8981 return CMD_WARNING_CONFIG_FAILED
;
8986 params
= IF_DEF_PARAMS(ifp
);
8987 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)
8988 && !IPV4_ADDR_SAME(¶ms
->if_area
, &area_id
)) {
8990 "Must remove previous area config before changing ospf area \n");
8991 return CMD_WARNING_CONFIG_FAILED
;
8994 // Check if we have an address arg and proccess it
8995 if (argc
== idx
+ 3) {
8996 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
8998 "Please specify Intf Address by A.B.C.D\n");
8999 return CMD_WARNING_CONFIG_FAILED
;
9001 // update/create address-level params
9002 params
= ospf_get_if_params((ifp
), (addr
));
9003 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
9004 if (!IPV4_ADDR_SAME(¶ms
->if_area
, &area_id
)) {
9006 "Must remove previous area/address config before changing ospf area\n");
9007 return CMD_WARNING_CONFIG_FAILED
;
9011 ospf_if_update_params((ifp
), (addr
));
9014 /* enable ospf on this interface with area_id */
9016 SET_IF_PARAM(params
, if_area
);
9017 params
->if_area
= area_id
;
9018 params
->if_area_id_fmt
= format
;
9022 ospf_interface_area_set(ospf
, ifp
);
9027 DEFUN (no_ip_ospf_area
,
9028 no_ip_ospf_area_cmd
,
9029 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]",
9032 "OSPF interface commands\n"
9034 "Disable OSPF on this interface\n"
9035 "OSPF area ID in IP address format\n"
9036 "OSPF area ID as a decimal value\n"
9037 "Address of interface\n")
9039 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9042 struct ospf_if_params
*params
;
9043 unsigned short instance
= 0;
9044 struct in_addr addr
;
9045 struct in_addr area_id
;
9047 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
9048 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
9051 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
9053 ospf
= ospf_lookup_instance(instance
);
9055 if (instance
&& instance
!= ospf_instance
)
9056 return CMD_NOT_MY_INSTANCE
;
9058 argv_find(argv
, argc
, "area", &idx
);
9060 // Check if we have an address arg and proccess it
9061 if (argc
== idx
+ 3) {
9062 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
9064 "Please specify Intf Address by A.B.C.D\n");
9065 return CMD_WARNING_CONFIG_FAILED
;
9067 params
= ospf_lookup_if_params(ifp
, addr
);
9068 if ((params
) == NULL
)
9071 params
= IF_DEF_PARAMS(ifp
);
9073 area_id
= params
->if_area
;
9074 if (!OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
9076 "Can't find specified interface area configuration.\n");
9077 return CMD_WARNING_CONFIG_FAILED
;
9080 UNSET_IF_PARAM(params
, if_area
);
9081 if (params
!= IF_DEF_PARAMS((ifp
))) {
9082 ospf_free_if_params((ifp
), (addr
));
9083 ospf_if_update_params((ifp
), (addr
));
9087 ospf_interface_area_unset(ospf
, ifp
);
9088 ospf_area_check_free(ospf
, area_id
);
9094 DEFUN (ip_ospf_passive
,
9095 ip_ospf_passive_cmd
,
9096 "ip ospf passive [A.B.C.D]",
9098 "OSPF interface commands\n"
9099 "Suppress routing updates on an interface\n"
9100 "Address of interface\n")
9102 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9104 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
9105 struct ospf_if_params
*params
;
9109 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9112 "Please specify interface address by A.B.C.D\n");
9113 return CMD_WARNING_CONFIG_FAILED
;
9115 params
= ospf_get_if_params(ifp
, addr
);
9116 ospf_if_update_params(ifp
, addr
);
9118 params
= IF_DEF_PARAMS(ifp
);
9121 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_PASSIVE
);
9126 DEFUN (no_ip_ospf_passive
,
9127 no_ip_ospf_passive_cmd
,
9128 "no ip ospf passive [A.B.C.D]",
9131 "OSPF interface commands\n"
9132 "Enable routing updates on an interface\n"
9133 "Address of interface\n")
9135 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9137 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
9138 struct ospf_if_params
*params
;
9142 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9145 "Please specify interface address by A.B.C.D\n");
9146 return CMD_WARNING_CONFIG_FAILED
;
9148 params
= ospf_lookup_if_params(ifp
, addr
);
9152 params
= IF_DEF_PARAMS(ifp
);
9155 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_ACTIVE
);
9160 DEFUN (ospf_redistribute_source
,
9161 ospf_redistribute_source_cmd
,
9162 "redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
9164 FRR_REDIST_HELP_STR_OSPFD
9165 "Metric for redistributed routes\n"
9166 "OSPF default metric\n"
9167 "OSPF exterior metric type for redistributed routes\n"
9168 "Set OSPF External Type 1/2 metrics\n"
9169 "Route map reference\n"
9170 "Pointer to route-map entries\n")
9172 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9173 int idx_protocol
= 1;
9177 struct ospf_redist
*red
;
9179 bool update
= false;
9181 /* Get distribute source. */
9182 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
9184 return CMD_WARNING_CONFIG_FAILED
;
9186 /* Get metric value. */
9187 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
9188 if (!str2metric(argv
[idx
]->arg
, &metric
))
9189 return CMD_WARNING_CONFIG_FAILED
;
9192 /* Get metric type. */
9193 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
9194 if (!str2metric_type(argv
[idx
]->arg
, &type
))
9195 return CMD_WARNING_CONFIG_FAILED
;
9199 red
= ospf_redist_lookup(ospf
, source
, 0);
9201 red
= ospf_redist_add(ospf
, source
, 0);
9206 if (argv_find(argv
, argc
, "WORD", &idx
)) {
9207 ospf_routemap_set(red
, argv
[idx
]->arg
);
9209 ospf_routemap_unset(red
);
9212 return ospf_redistribute_update(ospf
, red
, source
, 0, type
,
9215 return ospf_redistribute_set(ospf
, red
, source
, 0, type
,
9219 DEFUN (no_ospf_redistribute_source
,
9220 no_ospf_redistribute_source_cmd
,
9221 "no redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
9224 FRR_REDIST_HELP_STR_OSPFD
9225 "Metric for redistributed routes\n"
9226 "OSPF default metric\n"
9227 "OSPF exterior metric type for redistributed routes\n"
9228 "Set OSPF External Type 1/2 metrics\n"
9229 "Route map reference\n"
9230 "Pointer to route-map entries\n")
9232 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9233 int idx_protocol
= 2;
9235 struct ospf_redist
*red
;
9237 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
9239 return CMD_WARNING_CONFIG_FAILED
;
9241 red
= ospf_redist_lookup(ospf
, source
, 0);
9245 ospf_routemap_unset(red
);
9246 ospf_redist_del(ospf
, source
, 0);
9248 return ospf_redistribute_unset(ospf
, source
, 0);
9251 DEFUN (ospf_redistribute_instance_source
,
9252 ospf_redistribute_instance_source_cmd
,
9253 "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
9255 "Open Shortest Path First\n"
9256 "Non-main Kernel Routing Table\n"
9257 "Instance ID/Table ID\n"
9258 "Metric for redistributed routes\n"
9259 "OSPF default metric\n"
9260 "OSPF exterior metric type for redistributed routes\n"
9261 "Set OSPF External Type 1/2 metrics\n"
9262 "Route map reference\n"
9263 "Pointer to route-map entries\n")
9265 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9266 int idx_ospf_table
= 1;
9272 unsigned short instance
;
9273 struct ospf_redist
*red
;
9274 bool update
= false;
9276 source
= proto_redistnum(AFI_IP
, argv
[idx_ospf_table
]->text
);
9279 vty_out(vty
, "Unknown instance redistribution\n");
9280 return CMD_WARNING_CONFIG_FAILED
;
9283 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9285 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
9287 "Instance redistribution in non-instanced OSPF not allowed\n");
9288 return CMD_WARNING_CONFIG_FAILED
;
9291 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
9292 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
9293 return CMD_WARNING_CONFIG_FAILED
;
9296 /* Get metric value. */
9297 if (argv_find(argv
, argc
, "metric", &idx
))
9298 if (!str2metric(argv
[idx
+ 1]->arg
, &metric
))
9299 return CMD_WARNING_CONFIG_FAILED
;
9302 /* Get metric type. */
9303 if (argv_find(argv
, argc
, "metric-type", &idx
))
9304 if (!str2metric_type(argv
[idx
+ 1]->arg
, &type
))
9305 return CMD_WARNING_CONFIG_FAILED
;
9307 red
= ospf_redist_lookup(ospf
, source
, instance
);
9309 red
= ospf_redist_add(ospf
, source
, instance
);
9314 if (argv_find(argv
, argc
, "route-map", &idx
))
9315 ospf_routemap_set(red
, argv
[idx
+ 1]->arg
);
9317 ospf_routemap_unset(red
);
9320 return ospf_redistribute_update(ospf
, red
, source
, instance
,
9323 return ospf_redistribute_set(ospf
, red
, source
, instance
, type
,
9327 DEFUN (no_ospf_redistribute_instance_source
,
9328 no_ospf_redistribute_instance_source_cmd
,
9329 "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
9332 "Open Shortest Path First\n"
9333 "Non-main Kernel Routing Table\n"
9334 "Instance ID/Table Id\n"
9335 "Metric for redistributed routes\n"
9336 "OSPF default metric\n"
9337 "OSPF exterior metric type for redistributed routes\n"
9338 "Set OSPF External Type 1/2 metrics\n"
9339 "Route map reference\n"
9340 "Pointer to route-map entries\n")
9342 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9343 int idx_ospf_table
= 2;
9345 unsigned int instance
;
9346 struct ospf_redist
*red
;
9349 if (strncmp(argv
[idx_ospf_table
]->arg
, "o", 1) == 0)
9350 source
= ZEBRA_ROUTE_OSPF
;
9352 source
= ZEBRA_ROUTE_TABLE
;
9354 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9356 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
9358 "Instance redistribution in non-instanced OSPF not allowed\n");
9359 return CMD_WARNING_CONFIG_FAILED
;
9362 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
9363 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
9364 return CMD_WARNING_CONFIG_FAILED
;
9367 red
= ospf_redist_lookup(ospf
, source
, instance
);
9371 ospf_routemap_unset(red
);
9372 ospf_redist_del(ospf
, source
, instance
);
9374 return ospf_redistribute_unset(ospf
, source
, instance
);
9377 DEFUN (ospf_distribute_list_out
,
9378 ospf_distribute_list_out_cmd
,
9379 "distribute-list WORD out " FRR_REDIST_STR_OSPFD
,
9380 "Filter networks in routing updates\n"
9381 "Access-list name\n"
9383 FRR_REDIST_HELP_STR_OSPFD
)
9385 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9389 char *proto
= argv
[argc
- 1]->text
;
9391 /* Get distribute source. */
9392 source
= proto_redistnum(AFI_IP
, proto
);
9394 return CMD_WARNING_CONFIG_FAILED
;
9396 return ospf_distribute_list_out_set(ospf
, source
, argv
[idx_word
]->arg
);
9399 DEFUN (no_ospf_distribute_list_out
,
9400 no_ospf_distribute_list_out_cmd
,
9401 "no distribute-list WORD out " FRR_REDIST_STR_OSPFD
,
9403 "Filter networks in routing updates\n"
9404 "Access-list name\n"
9406 FRR_REDIST_HELP_STR_OSPFD
)
9408 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9412 char *proto
= argv
[argc
- 1]->text
;
9413 source
= proto_redistnum(AFI_IP
, proto
);
9415 return CMD_WARNING_CONFIG_FAILED
;
9417 return ospf_distribute_list_out_unset(ospf
, source
,
9418 argv
[idx_word
]->arg
);
9421 /* Default information originate. */
9422 DEFUN (ospf_default_information_originate
,
9423 ospf_default_information_originate_cmd
,
9424 "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
9425 "Control distribution of default information\n"
9426 "Distribute a default route\n"
9427 "Always advertise default route\n"
9428 "OSPF default metric\n"
9430 "OSPF metric type for default routes\n"
9431 "Set OSPF External Type 1/2 metrics\n"
9432 "Route map reference\n"
9433 "Pointer to route-map entries\n")
9435 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9436 int default_originate
= DEFAULT_ORIGINATE_ZEBRA
;
9439 struct ospf_redist
*red
;
9441 int cur_originate
= ospf
->default_originate
;
9445 red
= ospf_redist_add(ospf
, DEFAULT_ROUTE
, 0);
9447 /* Check whether "always" was specified */
9448 if (argv_find(argv
, argc
, "always", &idx
))
9449 default_originate
= DEFAULT_ORIGINATE_ALWAYS
;
9451 /* Get metric value */
9452 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
9453 if (!str2metric(argv
[idx
]->arg
, &metric
))
9454 return CMD_WARNING_CONFIG_FAILED
;
9457 /* Get metric type. */
9458 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
9459 if (!str2metric_type(argv
[idx
]->arg
, &type
))
9460 return CMD_WARNING_CONFIG_FAILED
;
9464 if (argv_find(argv
, argc
, "WORD", &idx
))
9465 rtmap
= argv
[idx
]->arg
;
9467 /* To check ,if user is providing same route map */
9468 if ((rtmap
== ROUTEMAP_NAME(red
)) ||
9469 (rtmap
&& ROUTEMAP_NAME(red
)
9470 && (strcmp(rtmap
, ROUTEMAP_NAME(red
)) == 0)))
9473 /* Don't allow if the same lsa is aleardy originated. */
9475 && (red
->dmetric
.type
== type
)
9476 && (red
->dmetric
.value
== metric
)
9477 && (cur_originate
== default_originate
))
9480 /* Updating Metric details */
9481 red
->dmetric
.type
= type
;
9482 red
->dmetric
.value
= metric
;
9484 /* updating route map details */
9486 ospf_routemap_set(red
, rtmap
);
9488 ospf_routemap_unset(red
);
9490 return ospf_redistribute_default_set(ospf
, default_originate
, type
,
9494 DEFUN (no_ospf_default_information_originate
,
9495 no_ospf_default_information_originate_cmd
,
9496 "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
9498 "Control distribution of default information\n"
9499 "Distribute a default route\n"
9500 "Always advertise default route\n"
9501 "OSPF default metric\n"
9503 "OSPF metric type for default routes\n"
9504 "Set OSPF External Type 1/2 metrics\n"
9505 "Route map reference\n"
9506 "Pointer to route-map entries\n")
9508 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9509 struct ospf_redist
*red
;
9511 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
9515 ospf_routemap_unset(red
);
9516 ospf_redist_del(ospf
, DEFAULT_ROUTE
, 0);
9518 return ospf_redistribute_default_set(ospf
, DEFAULT_ORIGINATE_NONE
,
9522 DEFUN (ospf_default_metric
,
9523 ospf_default_metric_cmd
,
9524 "default-metric (0-16777214)",
9525 "Set metric of redistributed routes\n"
9528 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9532 if (!str2metric(argv
[idx_number
]->arg
, &metric
))
9533 return CMD_WARNING_CONFIG_FAILED
;
9535 ospf
->default_metric
= metric
;
9540 DEFUN (no_ospf_default_metric
,
9541 no_ospf_default_metric_cmd
,
9542 "no default-metric [(0-16777214)]",
9544 "Set metric of redistributed routes\n"
9547 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9549 ospf
->default_metric
= -1;
9555 DEFUN (ospf_distance
,
9558 "Administrative distance\n"
9559 "OSPF Administrative distance\n")
9561 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9564 ospf
->distance_all
= atoi(argv
[idx_number
]->arg
);
9569 DEFUN (no_ospf_distance
,
9570 no_ospf_distance_cmd
,
9571 "no distance (1-255)",
9573 "Administrative distance\n"
9574 "OSPF Administrative distance\n")
9576 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9578 ospf
->distance_all
= 0;
9583 DEFUN (no_ospf_distance_ospf
,
9584 no_ospf_distance_ospf_cmd
,
9585 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
9587 "Administrative distance\n"
9588 "OSPF administrative distance\n"
9589 "Intra-area routes\n"
9590 "Distance for intra-area routes\n"
9591 "Inter-area routes\n"
9592 "Distance for inter-area routes\n"
9594 "Distance for external routes\n")
9596 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9599 if (argv_find(argv
, argc
, "intra-area", &idx
) || argc
== 3)
9600 idx
= ospf
->distance_intra
= 0;
9601 if (argv_find(argv
, argc
, "inter-area", &idx
) || argc
== 3)
9602 idx
= ospf
->distance_inter
= 0;
9603 if (argv_find(argv
, argc
, "external", &idx
) || argc
== 3)
9604 ospf
->distance_external
= 0;
9609 DEFUN (ospf_distance_ospf
,
9610 ospf_distance_ospf_cmd
,
9611 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
9612 "Administrative distance\n"
9613 "OSPF administrative distance\n"
9614 "Intra-area routes\n"
9615 "Distance for intra-area routes\n"
9616 "Inter-area routes\n"
9617 "Distance for inter-area routes\n"
9619 "Distance for external routes\n")
9621 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9624 ospf
->distance_intra
= 0;
9625 ospf
->distance_inter
= 0;
9626 ospf
->distance_external
= 0;
9628 if (argv_find(argv
, argc
, "intra-area", &idx
))
9629 ospf
->distance_intra
= atoi(argv
[idx
+ 1]->arg
);
9631 if (argv_find(argv
, argc
, "inter-area", &idx
))
9632 ospf
->distance_inter
= atoi(argv
[idx
+ 1]->arg
);
9634 if (argv_find(argv
, argc
, "external", &idx
))
9635 ospf
->distance_external
= atoi(argv
[idx
+ 1]->arg
);
9640 DEFUN (ip_ospf_mtu_ignore
,
9641 ip_ospf_mtu_ignore_addr_cmd
,
9642 "ip ospf mtu-ignore [A.B.C.D]",
9644 "OSPF interface commands\n"
9645 "Disable MTU mismatch detection on this interface\n"
9646 "Address of interface\n")
9648 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9650 struct in_addr addr
;
9653 struct ospf_if_params
*params
;
9654 params
= IF_DEF_PARAMS(ifp
);
9657 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9660 "Please specify interface address by A.B.C.D\n");
9661 return CMD_WARNING_CONFIG_FAILED
;
9663 params
= ospf_get_if_params(ifp
, addr
);
9664 ospf_if_update_params(ifp
, addr
);
9666 params
->mtu_ignore
= 1;
9667 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
9668 SET_IF_PARAM(params
, mtu_ignore
);
9670 UNSET_IF_PARAM(params
, mtu_ignore
);
9671 if (params
!= IF_DEF_PARAMS(ifp
)) {
9672 ospf_free_if_params(ifp
, addr
);
9673 ospf_if_update_params(ifp
, addr
);
9679 DEFUN (no_ip_ospf_mtu_ignore
,
9680 no_ip_ospf_mtu_ignore_addr_cmd
,
9681 "no ip ospf mtu-ignore [A.B.C.D]",
9684 "OSPF interface commands\n"
9685 "Disable MTU mismatch detection on this interface\n"
9686 "Address of interface\n")
9688 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9690 struct in_addr addr
;
9693 struct ospf_if_params
*params
;
9694 params
= IF_DEF_PARAMS(ifp
);
9697 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9700 "Please specify interface address by A.B.C.D\n");
9701 return CMD_WARNING_CONFIG_FAILED
;
9703 params
= ospf_get_if_params(ifp
, addr
);
9704 ospf_if_update_params(ifp
, addr
);
9706 params
->mtu_ignore
= 0;
9707 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
9708 SET_IF_PARAM(params
, mtu_ignore
);
9710 UNSET_IF_PARAM(params
, mtu_ignore
);
9711 if (params
!= IF_DEF_PARAMS(ifp
)) {
9712 ospf_free_if_params(ifp
, addr
);
9713 ospf_if_update_params(ifp
, addr
);
9720 DEFUN (ospf_max_metric_router_lsa_admin
,
9721 ospf_max_metric_router_lsa_admin_cmd
,
9722 "max-metric router-lsa administrative",
9723 "OSPF maximum / infinite-distance metric\n"
9724 "Advertise own Router-LSA with infinite distance (stub router)\n"
9725 "Administratively applied, for an indefinite period\n")
9727 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9728 struct listnode
*ln
;
9729 struct ospf_area
*area
;
9731 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
9732 SET_FLAG(area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
);
9734 if (!CHECK_FLAG(area
->stub_router_state
,
9735 OSPF_AREA_IS_STUB_ROUTED
))
9736 ospf_router_lsa_update_area(area
);
9739 /* Allows for areas configured later to get the property */
9740 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
;
9745 DEFUN (no_ospf_max_metric_router_lsa_admin
,
9746 no_ospf_max_metric_router_lsa_admin_cmd
,
9747 "no max-metric router-lsa administrative",
9749 "OSPF maximum / infinite-distance metric\n"
9750 "Advertise own Router-LSA with infinite distance (stub router)\n"
9751 "Administratively applied, for an indefinite period\n")
9753 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9754 struct listnode
*ln
;
9755 struct ospf_area
*area
;
9757 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
9758 UNSET_FLAG(area
->stub_router_state
,
9759 OSPF_AREA_ADMIN_STUB_ROUTED
);
9761 /* Don't trample on the start-up stub timer */
9762 if (CHECK_FLAG(area
->stub_router_state
,
9763 OSPF_AREA_IS_STUB_ROUTED
)
9764 && !area
->t_stub_router
) {
9765 UNSET_FLAG(area
->stub_router_state
,
9766 OSPF_AREA_IS_STUB_ROUTED
);
9767 ospf_router_lsa_update_area(area
);
9770 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET
;
9774 DEFUN (ospf_max_metric_router_lsa_startup
,
9775 ospf_max_metric_router_lsa_startup_cmd
,
9776 "max-metric router-lsa on-startup (5-86400)",
9777 "OSPF maximum / infinite-distance metric\n"
9778 "Advertise own Router-LSA with infinite distance (stub router)\n"
9779 "Automatically advertise stub Router-LSA on startup of OSPF\n"
9780 "Time (seconds) to advertise self as stub-router\n")
9782 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9784 unsigned int seconds
;
9787 vty_out(vty
, "%% Must supply stub-router period");
9788 return CMD_WARNING_CONFIG_FAILED
;
9791 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9793 ospf
->stub_router_startup_time
= seconds
;
9798 DEFUN (no_ospf_max_metric_router_lsa_startup
,
9799 no_ospf_max_metric_router_lsa_startup_cmd
,
9800 "no max-metric router-lsa on-startup [(5-86400)]",
9802 "OSPF maximum / infinite-distance metric\n"
9803 "Advertise own Router-LSA with infinite distance (stub router)\n"
9804 "Automatically advertise stub Router-LSA on startup of OSPF\n"
9805 "Time (seconds) to advertise self as stub-router\n")
9807 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9808 struct listnode
*ln
;
9809 struct ospf_area
*area
;
9811 ospf
->stub_router_startup_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
9813 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
9814 SET_FLAG(area
->stub_router_state
,
9815 OSPF_AREA_WAS_START_STUB_ROUTED
);
9816 OSPF_TIMER_OFF(area
->t_stub_router
);
9818 /* Don't trample on admin stub routed */
9819 if (!CHECK_FLAG(area
->stub_router_state
,
9820 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
9821 UNSET_FLAG(area
->stub_router_state
,
9822 OSPF_AREA_IS_STUB_ROUTED
);
9823 ospf_router_lsa_update_area(area
);
9830 DEFUN (ospf_max_metric_router_lsa_shutdown
,
9831 ospf_max_metric_router_lsa_shutdown_cmd
,
9832 "max-metric router-lsa on-shutdown (5-100)",
9833 "OSPF maximum / infinite-distance metric\n"
9834 "Advertise own Router-LSA with infinite distance (stub router)\n"
9835 "Advertise stub-router prior to full shutdown of OSPF\n"
9836 "Time (seconds) to wait till full shutdown\n")
9838 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9840 unsigned int seconds
;
9843 vty_out(vty
, "%% Must supply stub-router shutdown period");
9844 return CMD_WARNING_CONFIG_FAILED
;
9847 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9849 ospf
->stub_router_shutdown_time
= seconds
;
9854 DEFUN (no_ospf_max_metric_router_lsa_shutdown
,
9855 no_ospf_max_metric_router_lsa_shutdown_cmd
,
9856 "no max-metric router-lsa on-shutdown [(5-100)]",
9858 "OSPF maximum / infinite-distance metric\n"
9859 "Advertise own Router-LSA with infinite distance (stub router)\n"
9860 "Advertise stub-router prior to full shutdown of OSPF\n"
9861 "Time (seconds) to wait till full shutdown\n")
9863 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9865 ospf
->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
9870 DEFUN (ospf_proactive_arp
,
9871 ospf_proactive_arp_cmd
,
9873 "Allow sending ARP requests proactively\n")
9875 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9877 ospf
->proactive_arp
= true;
9882 DEFUN (no_ospf_proactive_arp
,
9883 no_ospf_proactive_arp_cmd
,
9886 "Disallow sending ARP requests proactively\n")
9888 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9890 ospf
->proactive_arp
= false;
9895 /* Graceful Restart HELPER Commands */
9896 DEFPY(ospf_gr_helper_enable
, ospf_gr_helper_enable_cmd
,
9897 "graceful-restart helper-only [A.B.C.D]",
9898 "OSPF Graceful Restart\n"
9899 "Enable Helper support\n"
9900 "Advertising router id\n")
9902 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9903 struct in_addr addr
;
9907 ret
= inet_aton(argv
[2]->arg
, &addr
);
9910 "Please specify the valid routerid address.\n");
9911 return CMD_WARNING_CONFIG_FAILED
;
9914 ospf_gr_helper_support_set_per_routerid(ospf
, &addr
, OSPF_GR_TRUE
);
9918 ospf_gr_helper_support_set(ospf
, OSPF_GR_TRUE
);
9923 DEFPY(no_ospf_gr_helper_enable
,
9924 no_ospf_gr_helper_enable_cmd
,
9925 "no graceful-restart helper-only [A.B.C.D]",
9927 "OSPF Graceful Restart\n"
9928 "Disable Helper support\n"
9929 "Advertising router id\n")
9931 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9932 struct in_addr addr
;
9936 ret
= inet_aton(argv
[3]->arg
, &addr
);
9939 "Please specify the valid routerid address.\n");
9940 return CMD_WARNING_CONFIG_FAILED
;
9943 ospf_gr_helper_support_set_per_routerid(ospf
, &addr
,
9948 ospf_gr_helper_support_set(ospf
, OSPF_GR_FALSE
);
9952 DEFPY(ospf_gr_helper_enable_lsacheck
,
9953 ospf_gr_helper_enable_lsacheck_cmd
,
9954 "graceful-restart helper strict-lsa-checking",
9955 "OSPF Graceful Restart\n"
9957 "Enable strict LSA check\n")
9959 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9961 ospf_gr_helper_lsa_check_set(ospf
, OSPF_GR_TRUE
);
9965 DEFPY(no_ospf_gr_helper_enable_lsacheck
,
9966 no_ospf_gr_helper_enable_lsacheck_cmd
,
9967 "no graceful-restart helper strict-lsa-checking",
9969 "OSPF Graceful Restart\n"
9971 "Disable strict LSA check\n")
9973 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9975 ospf_gr_helper_lsa_check_set(ospf
, OSPF_GR_FALSE
);
9979 DEFPY(ospf_gr_helper_supported_grace_time
,
9980 ospf_gr_helper_supported_grace_time_cmd
,
9981 "graceful-restart helper supported-grace-time (10-1800)$interval",
9982 "OSPF Graceful Restart\n"
9984 "Supported grace timer\n"
9985 "Grace interval(in seconds)\n")
9987 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9989 ospf_gr_helper_supported_gracetime_set(ospf
, interval
);
9993 DEFPY(no_ospf_gr_helper_supported_grace_time
,
9994 no_ospf_gr_helper_supported_grace_time_cmd
,
9995 "no graceful-restart helper supported-grace-time (10-1800)$interval",
9997 "OSPF Graceful Restart\n"
9999 "Supported grace timer\n"
10000 "Grace interval(in seconds)\n")
10002 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10004 ospf_gr_helper_supported_gracetime_set(ospf
, OSPF_MAX_GRACE_INTERVAL
);
10005 return CMD_SUCCESS
;
10008 DEFPY(ospf_gr_helper_planned_only
,
10009 ospf_gr_helper_planned_only_cmd
,
10010 "graceful-restart helper planned-only",
10011 "OSPF Graceful Restart\n"
10013 "Supported only planned restart\n")
10015 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10017 ospf_gr_helper_set_supported_planned_only_restart(ospf
, OSPF_GR_TRUE
);
10019 return CMD_SUCCESS
;
10022 /* External Route Aggregation */
10023 DEFUN (ospf_external_route_aggregation
,
10024 ospf_external_route_aggregation_cmd
,
10025 "summary-address A.B.C.D/M [tag (1-4294967295)]",
10026 "External summary address\n"
10027 "Summary address prefix (a.b.c.d/m) \n"
10029 "Router tag value\n")
10031 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10032 struct prefix_ipv4 p
;
10034 route_tag_t tag
= 0;
10035 int ret
= OSPF_SUCCESS
;
10037 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
10039 if (is_default_prefix4(&p
)) {
10041 "Default address shouldn't be configured as summary address.\n");
10042 return CMD_SUCCESS
;
10045 /* Apply mask for given prefix. */
10046 apply_mask((struct prefix
*)&p
);
10048 if (!is_valid_summary_addr(&p
)) {
10049 vty_out(vty
, "Not a valid summary address.\n");
10050 return CMD_WARNING_CONFIG_FAILED
;
10054 tag
= strtoul(argv
[idx
+ 2]->arg
, NULL
, 10);
10056 ret
= ospf_asbr_external_aggregator_set(ospf
, &p
, tag
);
10057 if (ret
== OSPF_INVALID
)
10058 vty_out(vty
, "Inavlid configuration!!\n");
10060 return CMD_SUCCESS
;
10063 DEFUN (no_ospf_external_route_aggregation
,
10064 no_ospf_external_route_aggregation_cmd
,
10065 "no summary-address A.B.C.D/M [tag (1-4294967295)]",
10067 "External summary address\n"
10068 "Summary address prefix (a.b.c.d/m)\n"
10070 "Router tag value\n")
10072 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10073 struct prefix_ipv4 p
;
10075 route_tag_t tag
= 0;
10076 int ret
= OSPF_SUCCESS
;
10078 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
10080 if (is_default_prefix4(&p
)) {
10082 "Default address shouldn't be configured as summary address.\n");
10083 return CMD_SUCCESS
;
10086 /* Apply mask for given prefix. */
10087 apply_mask((struct prefix
*)&p
);
10089 if (!is_valid_summary_addr(&p
)) {
10090 vty_out(vty
, "Not a valid summary address.\n");
10091 return CMD_WARNING_CONFIG_FAILED
;
10095 tag
= strtoul(argv
[idx
+ 2]->arg
, NULL
, 10);
10097 ret
= ospf_asbr_external_aggregator_unset(ospf
, &p
, tag
);
10098 if (ret
== OSPF_INVALID
)
10099 vty_out(vty
, "Inavlid configuration!!\n");
10101 return CMD_SUCCESS
;
10104 DEFPY(no_ospf_gr_helper_planned_only
,
10105 no_ospf_gr_helper_planned_only_cmd
,
10106 "no graceful-restart helper planned-only",
10108 "OSPF Graceful Restart\n"
10110 "Supported only for planned restart\n")
10112 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10114 ospf_gr_helper_set_supported_planned_only_restart(ospf
, OSPF_GR_FALSE
);
10116 return CMD_SUCCESS
;
10119 static int ospf_print_vty_helper_dis_rtr_walkcb(struct hash_bucket
*bucket
,
10122 struct advRtr
*rtr
= bucket
->data
;
10123 struct vty
*vty
= (struct vty
*)arg
;
10124 static unsigned int count
;
10126 vty_out(vty
, "%-6pI4,", &rtr
->advRtrAddr
);
10129 if (count
% 5 == 0)
10130 vty_out(vty
, "\n");
10132 return HASHWALK_CONTINUE
;
10135 static int ospf_show_gr_helper_details(struct vty
*vty
, struct ospf
*ospf
,
10136 uint8_t use_vrf
, json_object
*json
,
10137 bool uj
, bool detail
)
10139 struct listnode
*node
;
10140 struct ospf_interface
*oi
;
10141 char buf
[PREFIX_STRLEN
];
10142 json_object
*json_vrf
= NULL
;
10146 json_vrf
= json_object_new_object();
10151 if (ospf
->instance
) {
10153 json_object_int_add(json
, "ospfInstance",
10156 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
10159 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
10163 if (ospf
->vrf_id
== VRF_DEFAULT
)
10164 json_object_object_add(json
, "default",
10167 json_object_object_add(json
, ospf
->name
,
10171 vty_out(vty
, "\n");
10173 /* Show Router ID. */
10175 json_object_string_add(json_vrf
, "routerId",
10176 inet_ntop(AF_INET
, &ospf
->router_id
,
10177 buf
, sizeof(buf
)));
10179 vty_out(vty
, "\n OSPF Router with ID (%pI4)\n\n",
10185 if (ospf
->is_helper_supported
)
10187 " Graceful restart helper support enabled.\n");
10190 " Graceful restart helper support disabled.\n");
10192 if (ospf
->strict_lsa_check
)
10193 vty_out(vty
, " Strict LSA check is enabled.\n");
10195 vty_out(vty
, " Strict LSA check is disabled.\n");
10197 if (ospf
->only_planned_restart
)
10199 " Helper supported for planned restarts only.\n");
10202 " Helper supported for Planned and Unplanned Restarts.\n");
10205 " Supported Graceful restart interval: %d(in seconds).\n",
10206 ospf
->supported_grace_time
);
10208 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf
)) {
10209 vty_out(vty
, " Enable Router list:\n");
10211 hash_walk(ospf
->enable_rtr_list
,
10212 ospf_print_vty_helper_dis_rtr_walkcb
, vty
);
10213 vty_out(vty
, "\n\n");
10216 if (ospf
->last_exit_reason
!= OSPF_GR_HELPER_EXIT_NONE
) {
10217 vty_out(vty
, " Last Helper exit Reason :%s\n",
10218 ospf_exit_reason2str(ospf
->last_exit_reason
));
10221 if (ospf
->active_restarter_cnt
)
10223 " Number of Active neighbours in graceful restart: %d\n",
10224 ospf
->active_restarter_cnt
);
10226 vty_out(vty
, "\n");
10229 json_object_string_add(
10230 json_vrf
, "helperSupport",
10231 (ospf
->is_helper_supported
) ? "Enabled" : "Disabled");
10232 json_object_string_add(json_vrf
, "strictLsaCheck",
10233 (ospf
->strict_lsa_check
) ? "Enabled"
10235 json_object_string_add(
10236 json_vrf
, "restartSupoort",
10237 (ospf
->only_planned_restart
)
10238 ? "Planned Restart only"
10239 : "Planned and Unplanned Restarts");
10241 json_object_int_add(json_vrf
, "supportedGracePeriod",
10242 ospf
->supported_grace_time
);
10244 if (ospf
->last_exit_reason
!= OSPF_GR_HELPER_EXIT_NONE
)
10245 json_object_string_add(
10246 json_vrf
, "LastExitReason",
10247 ospf_exit_reason2str(ospf
->last_exit_reason
));
10249 if (ospf
->active_restarter_cnt
)
10250 json_object_int_add(json_vrf
, "activeRestarterCnt",
10251 ospf
->active_restarter_cnt
);
10257 json_object
*json_neighbors
= NULL
;
10259 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
10260 struct route_node
*rn
;
10261 struct ospf_neighbor
*nbr
;
10262 json_object
*json_neigh
;
10264 if (ospf_interface_neighbor_count(oi
) == 0)
10268 json_object_object_get_ex(json_vrf
, "Neighbors",
10270 if (!json_neighbors
) {
10272 json_object_new_object();
10273 json_object_object_add(json_vrf
,
10279 for (rn
= route_top(oi
->nbrs
); rn
;
10280 rn
= route_next(rn
)) {
10287 if (!OSPF_GR_IS_ACTIVE_HELPER(nbr
))
10291 vty_out(vty
, " Neighbour %d :\n", cnt
);
10292 vty_out(vty
, " Address : %pI4\n",
10293 &nbr
->address
.u
.prefix4
);
10294 vty_out(vty
, " Routerid : %pI4\n",
10297 " Received Grace period : %d(in seconds).\n",
10298 nbr
->gr_helper_info
10299 .recvd_grace_period
);
10301 " Actual Grace period : %d(in seconds)\n",
10302 nbr
->gr_helper_info
10303 .actual_grace_period
);
10305 " Remaining GraceTime:%ld(in seconds).\n",
10306 thread_timer_remain_second(
10307 nbr
->gr_helper_info
10310 " Graceful Restart reason: %s.\n\n",
10311 ospf_restart_reason2str(
10312 nbr
->gr_helper_info
10313 .gr_restart_reason
));
10316 json_neigh
= json_object_new_object();
10317 json_object_string_add(
10318 json_neigh
, "srcAddr",
10319 inet_ntop(AF_INET
, &nbr
->src
,
10320 buf
, sizeof(buf
)));
10322 json_object_string_add(
10323 json_neigh
, "routerid",
10326 buf
, sizeof(buf
)));
10327 json_object_int_add(
10329 "recvdGraceInterval",
10330 nbr
->gr_helper_info
10331 .recvd_grace_period
);
10332 json_object_int_add(
10334 "actualGraceInterval",
10335 nbr
->gr_helper_info
10336 .actual_grace_period
);
10337 json_object_int_add(
10338 json_neigh
, "remainGracetime",
10339 thread_timer_remain_second(
10340 nbr
->gr_helper_info
10342 json_object_string_add(
10343 json_neigh
, "restartReason",
10344 ospf_restart_reason2str(
10345 nbr
->gr_helper_info
10346 .gr_restart_reason
));
10347 json_object_object_add(
10349 inet_ntop(AF_INET
, &nbr
->src
,
10356 return CMD_SUCCESS
;
10359 DEFUN (ospf_external_route_aggregation_no_adrvertise
,
10360 ospf_external_route_aggregation_no_adrvertise_cmd
,
10361 "summary-address A.B.C.D/M no-advertise",
10362 "External summary address\n"
10363 "Summary address prefix (a.b.c.d/m) \n"
10364 "Don't advertise summary route \n")
10366 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10367 struct prefix_ipv4 p
;
10369 int ret
= OSPF_SUCCESS
;
10371 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
10373 if (is_default_prefix4(&p
)) {
10375 "Default address shouldn't be configured as summary address.\n");
10376 return CMD_SUCCESS
;
10379 /* Apply mask for given prefix. */
10380 apply_mask((struct prefix
*)&p
);
10382 if (!is_valid_summary_addr(&p
)) {
10383 vty_out(vty
, "Not a valid summary address.\n");
10384 return CMD_WARNING_CONFIG_FAILED
;
10387 ret
= ospf_asbr_external_rt_no_advertise(ospf
, &p
);
10388 if (ret
== OSPF_INVALID
)
10389 vty_out(vty
, "Inavlid configuration!!\n");
10391 return CMD_SUCCESS
;
10394 DEFUN (no_ospf_external_route_aggregation_no_adrvertise
,
10395 no_ospf_external_route_aggregation_no_adrvertise_cmd
,
10396 "no summary-address A.B.C.D/M no-advertise",
10398 "External summary address\n"
10399 "Summary address prefix (a.b.c.d/m)\n"
10400 "Advertise summary route to the AS \n")
10402 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10403 struct prefix_ipv4 p
;
10405 int ret
= OSPF_SUCCESS
;
10407 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
10409 if (is_default_prefix4(&p
)) {
10411 "Default address shouldn't be configured as summary address.\n");
10412 return CMD_SUCCESS
;
10415 /* Apply mask for given prefix. */
10416 apply_mask((struct prefix
*)&p
);
10418 if (!is_valid_summary_addr(&p
)) {
10419 vty_out(vty
, "Not a valid summary address.\n");
10420 return CMD_WARNING_CONFIG_FAILED
;
10423 ret
= ospf_asbr_external_rt_advertise(ospf
, &p
);
10424 if (ret
== OSPF_INVALID
)
10425 vty_out(vty
, "Inavlid configuration!!\n");
10427 return CMD_SUCCESS
;
10430 DEFUN (ospf_route_aggregation_timer
,
10431 ospf_route_aggregation_timer_cmd
,
10432 "aggregation timer (5-1800)",
10433 "External route aggregation\n"
10434 "Delay timer (in seconds)\n"
10435 "Timer interval(in seconds)\n")
10437 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10438 unsigned int interval
= 0;
10440 interval
= strtoul(argv
[2]->arg
, NULL
, 10);
10442 ospf_external_aggregator_timer_set(ospf
, interval
);
10444 return CMD_SUCCESS
;
10447 DEFPY (show_ip_ospf_gr_helper
,
10448 show_ip_ospf_gr_helper_cmd
,
10449 "show ip ospf [vrf <NAME|all>] graceful-restart helper [detail] [json]",
10452 "OSPF information\n"
10455 "OSPF Graceful Restart\n"
10456 "Helper details in the router\n"
10457 "Detailed informtion\n"
10460 char *vrf_name
= NULL
;
10461 bool all_vrf
= false;
10462 int ret
= CMD_SUCCESS
;
10465 uint8_t use_vrf
= 0;
10466 bool uj
= use_json(argc
, argv
);
10467 struct ospf
*ospf
= NULL
;
10468 json_object
*json
= NULL
;
10469 struct listnode
*node
= NULL
;
10471 bool detail
= false;
10473 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
10475 if (argv_find(argv
, argc
, "detail", &idx
))
10479 json
= json_object_new_object();
10481 /* vrf input is provided */
10486 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
10487 if (!ospf
->oi_running
)
10490 ret
= ospf_show_gr_helper_details(
10491 vty
, ospf
, use_vrf
, json
, uj
, detail
);
10495 vty_out(vty
, "%s\n",
10496 json_object_to_json_string_ext(
10497 json
, JSON_C_TO_STRING_PRETTY
));
10498 json_object_free(json
);
10504 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
10506 if (ospf
== NULL
|| !ospf
->oi_running
) {
10509 vty_out(vty
, "%s\n",
10510 json_object_to_json_string_ext(
10511 json
, JSON_C_TO_STRING_PRETTY
));
10512 json_object_free(json
);
10514 vty_out(vty
, "%% OSPF instance not found\n");
10516 return CMD_SUCCESS
;
10521 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
10523 if (ospf
== NULL
|| !ospf
->oi_running
) {
10526 vty_out(vty
, "%s\n",
10527 json_object_to_json_string_ext(
10528 json
, JSON_C_TO_STRING_PRETTY
));
10529 json_object_free(json
);
10531 vty_out(vty
, "%% OSPF instance not found\n");
10533 return CMD_SUCCESS
;
10536 ospf_show_gr_helper_details(vty
, ospf
, use_vrf
, json
, uj
,
10541 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
10542 json
, JSON_C_TO_STRING_PRETTY
));
10543 json_object_free(json
);
10546 return CMD_SUCCESS
;
10548 /* Graceful Restart HELPER commands end */
10549 DEFUN (no_ospf_route_aggregation_timer
,
10550 no_ospf_route_aggregation_timer_cmd
,
10551 "no aggregation timer",
10553 "External route aggregation\n"
10556 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10558 ospf_external_aggregator_timer_set(ospf
, OSPF_EXTL_AGGR_DEFAULT_DELAY
);
10560 return CMD_SUCCESS
;
10563 /* External Route Aggregation End */
10565 static void config_write_stub_router(struct vty
*vty
, struct ospf
*ospf
)
10567 struct listnode
*ln
;
10568 struct ospf_area
*area
;
10570 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
10571 vty_out(vty
, " max-metric router-lsa on-startup %u\n",
10572 ospf
->stub_router_startup_time
);
10573 if (ospf
->stub_router_shutdown_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
10574 vty_out(vty
, " max-metric router-lsa on-shutdown %u\n",
10575 ospf
->stub_router_shutdown_time
);
10576 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
10577 if (CHECK_FLAG(area
->stub_router_state
,
10578 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
10579 vty_out(vty
, " max-metric router-lsa administrative\n");
10586 static void show_ip_ospf_route_network(struct vty
*vty
, struct ospf
*ospf
,
10587 struct route_table
*rt
,
10590 struct route_node
*rn
;
10591 struct ospf_route
* or ;
10592 struct listnode
*pnode
, *pnnode
;
10593 struct ospf_path
*path
;
10594 char buf
[PREFIX_STRLEN
];
10595 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
10596 *json_nexthop
= NULL
;
10600 "============ OSPF network routing table ============\n");
10602 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
10603 char buf1
[PREFIX2STR_BUFFER
];
10605 if ((or = rn
->info
) == NULL
)
10608 prefix2str(&rn
->p
, buf1
, sizeof(buf1
));
10610 json_route
= json_object_new_object();
10612 json_object_object_add(json
, buf1
, json_route
);
10613 json_object_to_json_string_ext(
10614 json
, JSON_C_TO_STRING_NOSLASHESCAPE
);
10617 switch (or->path_type
) {
10618 case OSPF_PATH_INTER_AREA
:
10619 if (or->type
== OSPF_DESTINATION_NETWORK
) {
10621 json_object_string_add(json_route
,
10624 json_object_int_add(json_route
, "cost",
10626 json_object_string_add(
10627 json_route
, "area",
10629 &or->u
.std
.area_id
,
10630 buf1
, sizeof(buf1
)));
10633 "N IA %-18s [%d] area: %pI4\n",
10635 &or->u
.std
.area_id
);
10637 } else if (or->type
== OSPF_DESTINATION_DISCARD
) {
10639 json_object_string_add(json_route
,
10644 "D IA %-18s Discard entry\n",
10649 case OSPF_PATH_INTRA_AREA
:
10651 json_object_string_add(json_route
, "routeType",
10653 json_object_int_add(json_route
, "cost",
10655 json_object_string_add(
10656 json_route
, "area",
10657 inet_ntop(AF_INET
, &or->u
.std
.area_id
,
10658 buf1
, sizeof(buf1
)));
10660 vty_out(vty
, "N %-18s [%d] area: %pI4\n",
10662 &or->u
.std
.area_id
);
10669 if (or->type
== OSPF_DESTINATION_NETWORK
) {
10671 json_nexthop_array
= json_object_new_array();
10672 json_object_object_add(json_route
, "nexthops",
10673 json_nexthop_array
);
10676 for (ALL_LIST_ELEMENTS(or->paths
, pnode
, pnnode
,
10679 json_nexthop
= json_object_new_object();
10680 json_object_array_add(
10681 json_nexthop_array
,
10684 if (if_lookup_by_index(path
->ifindex
,
10687 if (path
->nexthop
.s_addr
10690 json_object_string_add(
10693 json_object_string_add(
10695 "directly attached to",
10701 "%24s directly attached to %s\n",
10709 json_object_string_add(
10717 json_object_string_add(
10725 "%24s via %pI4, %s\n",
10737 json_object_free(json_route
);
10740 vty_out(vty
, "\n");
10743 static void show_ip_ospf_route_router(struct vty
*vty
, struct ospf
*ospf
,
10744 struct route_table
*rtrs
,
10747 struct route_node
*rn
;
10748 struct ospf_route
* or ;
10749 struct listnode
*pnode
;
10750 struct listnode
*node
;
10751 struct ospf_path
*path
;
10752 char buf
[PREFIX_STRLEN
];
10753 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
10754 *json_nexthop
= NULL
;
10758 "============ OSPF router routing table =============\n");
10760 for (rn
= route_top(rtrs
); rn
; rn
= route_next(rn
)) {
10761 if (rn
->info
== NULL
)
10765 json_route
= json_object_new_object();
10767 json_object_object_add(
10768 json
, inet_ntop(AF_INET
, &rn
->p
.u
.prefix4
,
10771 json_object_string_add(json_route
, "routeType", "R ");
10773 vty_out(vty
, "R %-15pI4 ",
10777 for (ALL_LIST_ELEMENTS_RO((struct list
*)rn
->info
, node
, or)) {
10780 vty_out(vty
, "%24s", "");
10785 json_object_int_add(json_route
, "cost",
10787 json_object_string_add(
10788 json_route
, "area",
10789 inet_ntop(AF_INET
, &or->u
.std
.area_id
,
10790 buf
, sizeof(buf
)));
10791 if (or->path_type
== OSPF_PATH_INTER_AREA
)
10792 json_object_boolean_true_add(json_route
,
10794 if (or->u
.std
.flags
& ROUTER_LSA_BORDER
)
10795 json_object_string_add(json_route
,
10798 else if (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
)
10799 json_object_string_add(json_route
,
10803 vty_out(vty
, "%s [%d] area: %pI4",
10804 (or->path_type
== OSPF_PATH_INTER_AREA
10807 or->cost
, &or->u
.std
.area_id
);
10809 vty_out(vty
, "%s%s\n",
10810 (or->u
.std
.flags
& ROUTER_LSA_BORDER
10813 (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
10819 json_nexthop_array
= json_object_new_array();
10820 json_object_object_add(json_route
, "nexthops",
10821 json_nexthop_array
);
10824 for (ALL_LIST_ELEMENTS_RO(or->paths
, pnode
, path
)) {
10826 json_nexthop
= json_object_new_object();
10827 json_object_array_add(
10828 json_nexthop_array
,
10831 if (if_lookup_by_index(path
->ifindex
,
10833 if (path
->nexthop
.s_addr
10836 json_object_string_add(
10839 json_object_string_add(
10841 "directly attached to",
10847 "%24s directly attached to %s\n",
10855 json_object_string_add(
10861 buf
, sizeof(buf
)));
10862 json_object_string_add(
10870 "%24s via %pI4, %s\n",
10882 json_object_free(json_route
);
10885 vty_out(vty
, "\n");
10888 static void show_ip_ospf_route_external(struct vty
*vty
, struct ospf
*ospf
,
10889 struct route_table
*rt
,
10892 struct route_node
*rn
;
10893 struct ospf_route
*er
;
10894 struct listnode
*pnode
, *pnnode
;
10895 struct ospf_path
*path
;
10896 char buf
[PREFIX_STRLEN
];
10897 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
10898 *json_nexthop
= NULL
;
10902 "============ OSPF external routing table ===========\n");
10904 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
10905 if ((er
= rn
->info
) == NULL
)
10910 snprintfrr(buf1
, sizeof(buf1
), "%pFX", &rn
->p
);
10911 json_route
= json_object_new_object();
10913 json_object_object_add(json
, buf1
, json_route
);
10914 json_object_to_json_string_ext(
10915 json
, JSON_C_TO_STRING_NOSLASHESCAPE
);
10918 switch (er
->path_type
) {
10919 case OSPF_PATH_TYPE1_EXTERNAL
:
10921 json_object_string_add(json_route
, "routeType",
10923 json_object_int_add(json_route
, "cost",
10925 json_object_int_add(json_route
, "tag",
10929 "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI
10931 buf1
, er
->cost
, er
->u
.ext
.tag
);
10934 case OSPF_PATH_TYPE2_EXTERNAL
:
10936 json_object_string_add(json_route
, "routeType",
10938 json_object_int_add(json_route
, "cost",
10940 json_object_int_add(json_route
, "type2cost",
10941 er
->u
.ext
.type2_cost
);
10942 json_object_int_add(json_route
, "tag",
10946 "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI
10948 buf1
, er
->cost
, er
->u
.ext
.type2_cost
,
10955 json_nexthop_array
= json_object_new_array();
10956 json_object_object_add(json_route
, "nexthops",
10957 json_nexthop_array
);
10960 for (ALL_LIST_ELEMENTS(er
->paths
, pnode
, pnnode
, path
)) {
10962 json_nexthop
= json_object_new_object();
10963 json_object_array_add(json_nexthop_array
,
10967 if (if_lookup_by_index(path
->ifindex
, ospf
->vrf_id
)) {
10968 if (path
->nexthop
.s_addr
== INADDR_ANY
) {
10970 json_object_string_add(
10971 json_nexthop
, "ip",
10973 json_object_string_add(
10975 "directly attached to",
10981 "%24s directly attached to %s\n",
10989 json_object_string_add(
10990 json_nexthop
, "ip",
10996 json_object_string_add(
10997 json_nexthop
, "via",
11003 "%24s via %pI4, %s\n",
11014 json_object_free(json_route
);
11017 vty_out(vty
, "\n");
11020 static int show_ip_ospf_border_routers_common(struct vty
*vty
,
11024 if (ospf
->instance
)
11025 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
11027 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
11029 if (ospf
->new_table
== NULL
) {
11030 vty_out(vty
, "No OSPF routing information exist\n");
11031 return CMD_SUCCESS
;
11034 /* Show Network routes.
11035 show_ip_ospf_route_network (vty, ospf->new_table); */
11037 /* Show Router routes. */
11038 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, NULL
);
11040 vty_out(vty
, "\n");
11042 return CMD_SUCCESS
;
11045 DEFUN (show_ip_ospf_border_routers
,
11046 show_ip_ospf_border_routers_cmd
,
11047 "show ip ospf [vrf <NAME|all>] border-routers",
11050 "OSPF information\n"
11053 "Show all the ABR's and ASBR's\n")
11055 struct ospf
*ospf
= NULL
;
11056 struct listnode
*node
= NULL
;
11057 char *vrf_name
= NULL
;
11058 bool all_vrf
= false;
11059 int ret
= CMD_SUCCESS
;
11062 uint8_t use_vrf
= 0;
11064 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11067 bool ospf_output
= false;
11072 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11073 if (!ospf
->oi_running
)
11076 ospf_output
= true;
11077 ret
= show_ip_ospf_border_routers_common(
11078 vty
, ospf
, use_vrf
);
11082 vty_out(vty
, "%% OSPF instance not found\n");
11084 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11085 if (ospf
== NULL
|| !ospf
->oi_running
) {
11086 vty_out(vty
, "%% OSPF instance not found\n");
11087 return CMD_SUCCESS
;
11090 ret
= show_ip_ospf_border_routers_common(vty
, ospf
,
11094 /* Display default ospf (instance 0) info */
11095 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11096 if (ospf
== NULL
|| !ospf
->oi_running
) {
11097 vty_out(vty
, "%% OSPF instance not found\n");
11098 return CMD_SUCCESS
;
11101 ret
= show_ip_ospf_border_routers_common(vty
, ospf
, use_vrf
);
11107 DEFUN (show_ip_ospf_instance_border_routers
,
11108 show_ip_ospf_instance_border_routers_cmd
,
11109 "show ip ospf (1-65535) border-routers",
11112 "OSPF information\n"
11114 "Show all the ABR's and ASBR's\n")
11116 int idx_number
= 3;
11118 unsigned short instance
= 0;
11120 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
11121 if (instance
!= ospf_instance
)
11122 return CMD_NOT_MY_INSTANCE
;
11124 ospf
= ospf_lookup_instance(instance
);
11125 if (!ospf
|| !ospf
->oi_running
)
11126 return CMD_SUCCESS
;
11128 return show_ip_ospf_border_routers_common(vty
, ospf
, 0);
11131 static int show_ip_ospf_route_common(struct vty
*vty
, struct ospf
*ospf
,
11132 json_object
*json
, uint8_t use_vrf
)
11134 json_object
*json_vrf
= NULL
;
11136 if (ospf
->instance
)
11137 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
11142 json_vrf
= json_object_new_object();
11147 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
11149 if (ospf
->new_table
== NULL
) {
11150 vty_out(vty
, "No OSPF routing information exist\n");
11151 return CMD_SUCCESS
;
11154 /* Show Network routes. */
11155 show_ip_ospf_route_network(vty
, ospf
, ospf
->new_table
, json_vrf
);
11157 /* Show Router routes. */
11158 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, json_vrf
);
11160 /* Show AS External routes. */
11161 show_ip_ospf_route_external(vty
, ospf
, ospf
->old_external_route
,
11166 // json_object_object_add(json_vrf, "areas",
11168 if (ospf
->vrf_id
== VRF_DEFAULT
)
11169 json_object_object_add(json
, "default",
11172 json_object_object_add(json
, ospf
->name
,
11176 vty_out(vty
, "\n");
11179 return CMD_SUCCESS
;
11182 DEFUN (show_ip_ospf_route
,
11183 show_ip_ospf_route_cmd
,
11184 "show ip ospf [vrf <NAME|all>] route [json]",
11187 "OSPF information\n"
11190 "OSPF routing table\n"
11193 struct ospf
*ospf
= NULL
;
11194 struct listnode
*node
= NULL
;
11195 char *vrf_name
= NULL
;
11196 bool all_vrf
= false;
11197 int ret
= CMD_SUCCESS
;
11200 uint8_t use_vrf
= 0;
11201 bool uj
= use_json(argc
, argv
);
11202 json_object
*json
= NULL
;
11205 json
= json_object_new_object();
11207 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11209 /* vrf input is provided could be all or specific vrf*/
11211 bool ospf_output
= false;
11216 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11217 if (!ospf
->oi_running
)
11219 ospf_output
= true;
11220 ret
= show_ip_ospf_route_common(vty
, ospf
, json
,
11225 /* Keep Non-pretty format */
11226 vty_out(vty
, "%s\n",
11227 json_object_to_json_string(json
));
11228 json_object_free(json
);
11229 } else if (!ospf_output
)
11230 vty_out(vty
, "%% OSPF instance not found\n");
11234 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11235 if (ospf
== NULL
|| !ospf
->oi_running
) {
11237 vty_out(vty
, "%s\n",
11238 json_object_to_json_string_ext(
11239 json
, JSON_C_TO_STRING_PRETTY
));
11240 json_object_free(json
);
11242 vty_out(vty
, "%% OSPF instance not found\n");
11244 return CMD_SUCCESS
;
11247 /* Display default ospf (instance 0) info */
11248 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11249 if (ospf
== NULL
|| !ospf
->oi_running
) {
11251 vty_out(vty
, "%s\n",
11252 json_object_to_json_string_ext(
11253 json
, JSON_C_TO_STRING_PRETTY
));
11254 json_object_free(json
);
11256 vty_out(vty
, "%% OSPF instance not found\n");
11258 return CMD_SUCCESS
;
11263 ret
= show_ip_ospf_route_common(vty
, ospf
, json
, use_vrf
);
11264 /* Keep Non-pretty format */
11266 vty_out(vty
, "%s\n", json_object_to_json_string(json
));
11270 json_object_free(json
);
11275 DEFUN (show_ip_ospf_instance_route
,
11276 show_ip_ospf_instance_route_cmd
,
11277 "show ip ospf (1-65535) route",
11280 "OSPF information\n"
11282 "OSPF routing table\n")
11284 int idx_number
= 3;
11286 unsigned short instance
= 0;
11288 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
11289 if (instance
!= ospf_instance
)
11290 return CMD_NOT_MY_INSTANCE
;
11292 ospf
= ospf_lookup_instance(instance
);
11293 if (!ospf
|| !ospf
->oi_running
)
11294 return CMD_SUCCESS
;
11296 return show_ip_ospf_route_common(vty
, ospf
, NULL
, 0);
11300 DEFUN (show_ip_ospf_vrfs
,
11301 show_ip_ospf_vrfs_cmd
,
11302 "show ip ospf vrfs [json]",
11305 "OSPF information\n"
11306 "Show OSPF VRFs \n"
11309 bool uj
= use_json(argc
, argv
);
11310 json_object
*json
= NULL
;
11311 json_object
*json_vrfs
= NULL
;
11312 struct ospf
*ospf
= NULL
;
11313 struct listnode
*node
= NULL
;
11315 char buf
[PREFIX_STRLEN
];
11316 static const char header
[] = "Name Id RouterId ";
11319 json
= json_object_new_object();
11320 json_vrfs
= json_object_new_object();
11323 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11324 json_object
*json_vrf
= NULL
;
11325 const char *name
= NULL
;
11326 int64_t vrf_id_ui
= 0;
11330 if (!uj
&& count
== 1)
11331 vty_out(vty
, "%s\n", header
);
11333 json_vrf
= json_object_new_object();
11335 if (ospf
->vrf_id
== VRF_DEFAULT
)
11336 name
= VRF_DEFAULT_NAME
;
11340 vrf_id_ui
= (ospf
->vrf_id
== VRF_UNKNOWN
)
11342 : (int64_t)ospf
->vrf_id
;
11345 json_object_int_add(json_vrf
, "vrfId", vrf_id_ui
);
11346 json_object_string_add(
11347 json_vrf
, "routerId",
11348 inet_ntop(AF_INET
, &ospf
->router_id
,
11349 buf
, sizeof(buf
)));
11351 json_object_object_add(json_vrfs
, name
, json_vrf
);
11354 vty_out(vty
, "%-25s %-5d %-16pI4 \n", name
,
11355 ospf
->vrf_id
, &ospf
->router_id
);
11360 json_object_object_add(json
, "vrfs", json_vrfs
);
11361 json_object_int_add(json
, "totalVrfs", count
);
11363 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
11364 json
, JSON_C_TO_STRING_PRETTY
));
11365 json_object_free(json
);
11368 vty_out(vty
, "\nTotal number of OSPF VRFs: %d\n",
11372 return CMD_SUCCESS
;
11374 DEFPY (clear_ip_ospf_neighbor
,
11375 clear_ip_ospf_neighbor_cmd
,
11376 "clear ip ospf [(1-65535)]$instance neighbor [A.B.C.D$nbr_id]",
11379 "OSPF information\n"
11381 "Reset OSPF Neighbor\n"
11384 struct listnode
*node
;
11385 struct ospf
*ospf
= NULL
;
11387 /* If user does not specify the arguments,
11388 * instance = 0 and nbr_id = 0.0.0.0
11390 if (instance
!= 0) {
11391 /* This means clear only the particular ospf process */
11392 if (instance
!= ospf_instance
)
11393 return CMD_NOT_MY_INSTANCE
;
11396 /* Clear all the ospf processes */
11397 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11398 if (!ospf
->oi_running
)
11401 if (nbr_id_str
&& IPV4_ADDR_SAME(&ospf
->router_id
, &nbr_id
)) {
11402 vty_out(vty
, "Self router-id is not allowed.\r\n ");
11403 return CMD_SUCCESS
;
11406 ospf_neighbor_reset(ospf
, nbr_id
, nbr_id_str
);
11409 return CMD_SUCCESS
;
11412 DEFPY (clear_ip_ospf_process
,
11413 clear_ip_ospf_process_cmd
,
11414 "clear ip ospf [(1-65535)]$instance process",
11417 "OSPF information\n"
11419 "Reset OSPF Process\n")
11421 struct listnode
*node
;
11422 struct ospf
*ospf
= NULL
;
11424 /* Check if instance is not passed as an argument */
11425 if (instance
!= 0) {
11426 /* This means clear only the particular ospf process */
11427 if (instance
!= ospf_instance
)
11428 return CMD_NOT_MY_INSTANCE
;
11431 /* Clear all the ospf processes */
11432 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11433 if (!ospf
->oi_running
)
11436 ospf_process_reset(ospf
);
11439 return CMD_SUCCESS
;
11442 static const char *const ospf_abr_type_str
[] = {
11443 "unknown", "standard", "ibm", "cisco", "shortcut"
11446 static const char *const ospf_shortcut_mode_str
[] = {
11447 "default", "enable", "disable"
11449 static int ospf_vty_external_rt_walkcb(struct hash_bucket
*bucket
,
11452 struct external_info
*ei
= bucket
->data
;
11453 struct vty
*vty
= (struct vty
*)arg
;
11454 static unsigned int count
;
11456 vty_out(vty
, "%-4pI4/%d, ", &ei
->p
.prefix
, ei
->p
.prefixlen
);
11459 if (count
% 5 == 0)
11460 vty_out(vty
, "\n");
11462 if (OSPF_EXTERNAL_RT_COUNT(ei
->aggr_route
) == count
)
11465 return HASHWALK_CONTINUE
;
11468 static int ospf_json_external_rt_walkcb(struct hash_bucket
*bucket
,
11471 struct external_info
*ei
= bucket
->data
;
11472 struct json_object
*json
= (struct json_object
*)arg
;
11473 char buf
[PREFIX2STR_BUFFER
];
11475 static unsigned int count
;
11477 prefix2str(&ei
->p
, buf
, sizeof(buf
));
11479 snprintf(exnalbuf
, 20, "Exnl Addr-%d", count
);
11481 json_object_string_add(json
, exnalbuf
, buf
);
11485 if (OSPF_EXTERNAL_RT_COUNT(ei
->aggr_route
) == count
)
11488 return HASHWALK_CONTINUE
;
11491 static int ospf_show_summary_address(struct vty
*vty
, struct ospf
*ospf
,
11492 uint8_t use_vrf
, json_object
*json
,
11493 bool uj
, bool detail
)
11495 struct route_node
*rn
;
11496 json_object
*json_vrf
= NULL
;
11499 static char header
[] =
11500 "Summary-address Metric-type Metric Tag External_Rt_count\n";
11502 mtype
= metric_type(ospf
, 0, ospf
->instance
);
11503 mval
= metric_value(ospf
, 0, ospf
->instance
);
11506 vty_out(vty
, "%s\n", header
);
11510 json_vrf
= json_object_new_object();
11515 if (ospf
->instance
) {
11517 json_object_int_add(json
, "ospfInstance",
11520 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
11523 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
11526 vty_out(vty
, "aggregation delay interval :%d(in seconds)\n\n",
11527 ospf
->aggr_delay_interval
);
11529 json_object_int_add(json_vrf
, "aggregation delay interval",
11530 ospf
->aggr_delay_interval
);
11532 for (rn
= route_top(ospf
->rt_aggr_tbl
); rn
; rn
= route_next(rn
))
11534 struct ospf_external_aggr_rt
*aggr
= rn
->info
;
11535 json_object
*json_aggr
= NULL
;
11536 char buf
[PREFIX2STR_BUFFER
];
11538 prefix2str(&aggr
->p
, buf
, sizeof(buf
));
11542 json_aggr
= json_object_new_object();
11544 json_object_object_add(json_vrf
, buf
,
11547 json_object_string_add(json_aggr
,
11548 "Summary address", buf
);
11550 json_object_string_add(
11551 json_aggr
, "Metric-type",
11552 (mtype
== EXTERNAL_METRIC_TYPE_1
)
11556 json_object_int_add(json_aggr
, "Metric", mval
);
11558 json_object_int_add(json_aggr
, "Tag",
11561 json_object_int_add(
11562 json_aggr
, "External route count",
11563 OSPF_EXTERNAL_RT_COUNT(aggr
));
11565 if (OSPF_EXTERNAL_RT_COUNT(aggr
) && detail
) {
11567 aggr
->match_extnl_hash
,
11568 ospf_json_external_rt_walkcb
,
11573 vty_out(vty
, "%-20s", buf
);
11575 (mtype
== EXTERNAL_METRIC_TYPE_1
)
11576 ? vty_out(vty
, "%-16s", "E1")
11577 : vty_out(vty
, "%-16s", "E2");
11578 vty_out(vty
, "%-11d", mval
);
11580 vty_out(vty
, "%-12u", aggr
->tag
);
11582 vty_out(vty
, "%-5ld\n",
11583 OSPF_EXTERNAL_RT_COUNT(aggr
));
11585 if (OSPF_EXTERNAL_RT_COUNT(aggr
) && detail
) {
11587 "Matched External routes:\n");
11589 aggr
->match_extnl_hash
,
11590 ospf_vty_external_rt_walkcb
,
11592 vty_out(vty
, "\n");
11595 vty_out(vty
, "\n");
11601 if (ospf
->vrf_id
== VRF_DEFAULT
)
11602 json_object_object_add(json
, "default",
11605 json_object_object_add(json
, ospf
->name
,
11609 vty_out(vty
, "\n");
11611 return CMD_SUCCESS
;
11614 DEFUN (show_ip_ospf_external_aggregator
,
11615 show_ip_ospf_external_aggregator_cmd
,
11616 "show ip ospf [vrf <NAME|all>] summary-address [detail] [json]",
11618 "OSPF information\n"
11621 "Show external summary addresses\n"
11622 "Detailed informtion\n"
11625 char *vrf_name
= NULL
;
11626 bool all_vrf
= false;
11627 int ret
= CMD_SUCCESS
;
11630 uint8_t use_vrf
= 0;
11631 bool uj
= use_json(argc
, argv
);
11632 struct ospf
*ospf
= NULL
;
11633 json_object
*json
= NULL
;
11634 struct listnode
*node
= NULL
;
11636 bool detail
= false;
11638 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11640 if (argv_find(argv
, argc
, "detail", &idx
))
11644 json
= json_object_new_object();
11646 /* vrf input is provided */
11650 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11651 if (!ospf
->oi_running
)
11653 ret
= ospf_show_summary_address(
11654 vty
, ospf
, use_vrf
, json
, uj
, detail
);
11658 vty_out(vty
, "%s\n",
11659 json_object_to_json_string_ext(
11660 json
, JSON_C_TO_STRING_PRETTY
));
11661 json_object_free(json
);
11667 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11669 if (ospf
== NULL
|| !ospf
->oi_running
) {
11671 vty_out(vty
, "%s\n",
11672 json_object_to_json_string_ext(
11673 json
, JSON_C_TO_STRING_PRETTY
));
11674 json_object_free(json
);
11676 vty_out(vty
, "%% OSPF instance not found\n");
11678 return CMD_SUCCESS
;
11680 ospf_show_summary_address(vty
, ospf
, use_vrf
, json
, uj
, detail
);
11684 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11685 if (ospf
== NULL
|| !ospf
->oi_running
) {
11687 vty_out(vty
, "%s\n",
11688 json_object_to_json_string_ext(
11689 json
, JSON_C_TO_STRING_PRETTY
));
11690 json_object_free(json
);
11692 vty_out(vty
, "%% OSPF instance not found\n");
11694 return CMD_SUCCESS
;
11697 ospf_show_summary_address(vty
, ospf
, use_vrf
, json
, uj
, detail
);
11701 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
11702 json
, JSON_C_TO_STRING_PRETTY
));
11703 json_object_free(json
);
11705 return CMD_SUCCESS
;
11708 static const char *const ospf_int_type_str
[] = {
11709 "unknown", /* should never be used. */
11713 "point-to-multipoint",
11714 "virtual-link", /* should never be used. */
11718 static const char *interface_config_auth_str(struct ospf_if_params
*params
)
11720 if (!OSPF_IF_PARAM_CONFIGURED(params
, auth_type
)
11721 || params
->auth_type
== OSPF_AUTH_NOTSET
)
11724 /* Translation tables are not that much help
11725 * here due to syntax
11726 * of the simple option */
11727 switch (params
->auth_type
) {
11729 case OSPF_AUTH_NULL
:
11732 case OSPF_AUTH_SIMPLE
:
11735 case OSPF_AUTH_CRYPTOGRAPHIC
:
11736 return " message-digest";
11742 static int config_write_interface_one(struct vty
*vty
, struct vrf
*vrf
)
11744 struct listnode
*node
;
11745 struct interface
*ifp
;
11746 struct crypt_key
*ck
;
11747 struct route_node
*rn
= NULL
;
11748 struct ospf_if_params
*params
;
11749 const char *auth_str
;
11752 FOR_ALL_INTERFACES (vrf
, ifp
) {
11754 if (memcmp(ifp
->name
, "VLINK", 5) == 0)
11757 vty_frame(vty
, "!\n");
11758 if (ifp
->vrf_id
== VRF_DEFAULT
)
11759 vty_frame(vty
, "interface %s\n", ifp
->name
);
11761 vty_frame(vty
, "interface %s vrf %s\n", ifp
->name
,
11764 vty_out(vty
, " description %s\n", ifp
->desc
);
11768 params
= IF_DEF_PARAMS(ifp
);
11771 /* Interface Network print. */
11772 if (OSPF_IF_PARAM_CONFIGURED(params
, type
)
11773 && params
->type
!= OSPF_IFTYPE_LOOPBACK
) {
11774 if (params
->type
!= ospf_default_iftype(ifp
)) {
11775 vty_out(vty
, " ip ospf network %s",
11779 == OSPF_IFTYPE_POINTOPOINT
11780 && params
->ptp_dmvpn
)
11781 vty_out(vty
, " dmvpn");
11782 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11783 vty_out(vty
, " %pI4",
11785 vty_out(vty
, "\n");
11789 /* OSPF interface authentication print */
11790 auth_str
= interface_config_auth_str(params
);
11792 vty_out(vty
, " ip ospf authentication%s",
11794 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11795 vty_out(vty
, " %pI4",
11797 vty_out(vty
, "\n");
11800 /* Simple Authentication Password print. */
11801 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_simple
)
11802 && params
->auth_simple
[0] != '\0') {
11803 vty_out(vty
, " ip ospf authentication-key %s",
11804 params
->auth_simple
);
11805 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11806 vty_out(vty
, " %pI4",
11808 vty_out(vty
, "\n");
11811 /* Cryptographic Authentication Key print. */
11812 if (params
&& params
->auth_crypt
) {
11813 for (ALL_LIST_ELEMENTS_RO(params
->auth_crypt
,
11816 " ip ospf message-digest-key %d md5 %s",
11817 ck
->key_id
, ck
->auth_key
);
11818 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11819 vty_out(vty
, " %pI4",
11821 vty_out(vty
, "\n");
11825 /* Interface Output Cost print. */
11826 if (OSPF_IF_PARAM_CONFIGURED(params
, output_cost_cmd
)) {
11827 vty_out(vty
, " ip ospf cost %u",
11828 params
->output_cost_cmd
);
11829 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11830 vty_out(vty
, " %pI4",
11832 vty_out(vty
, "\n");
11835 /* Hello Interval print. */
11836 if (OSPF_IF_PARAM_CONFIGURED(params
, v_hello
)
11837 && params
->v_hello
!= OSPF_HELLO_INTERVAL_DEFAULT
) {
11838 vty_out(vty
, " ip ospf hello-interval %u",
11840 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11841 vty_out(vty
, " %pI4",
11843 vty_out(vty
, "\n");
11847 /* Router Dead Interval print. */
11848 if (OSPF_IF_PARAM_CONFIGURED(params
, v_wait
)
11849 && params
->is_v_wait_set
) {
11850 vty_out(vty
, " ip ospf dead-interval ");
11853 if (OSPF_IF_PARAM_CONFIGURED(params
,
11856 "minimal hello-multiplier %d",
11857 params
->fast_hello
);
11859 vty_out(vty
, "%u", params
->v_wait
);
11861 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11862 vty_out(vty
, " %pI4",
11864 vty_out(vty
, "\n");
11867 /* Router Priority print. */
11868 if (OSPF_IF_PARAM_CONFIGURED(params
, priority
)
11869 && params
->priority
11870 != OSPF_ROUTER_PRIORITY_DEFAULT
) {
11871 vty_out(vty
, " ip ospf priority %u",
11873 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11874 vty_out(vty
, " %pI4",
11876 vty_out(vty
, "\n");
11879 /* Retransmit Interval print. */
11880 if (OSPF_IF_PARAM_CONFIGURED(params
,
11881 retransmit_interval
)
11882 && params
->retransmit_interval
11883 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
) {
11884 vty_out(vty
, " ip ospf retransmit-interval %u",
11885 params
->retransmit_interval
);
11886 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11887 vty_out(vty
, " %pI4",
11889 vty_out(vty
, "\n");
11892 /* Transmit Delay print. */
11893 if (OSPF_IF_PARAM_CONFIGURED(params
, transmit_delay
)
11894 && params
->transmit_delay
11895 != OSPF_TRANSMIT_DELAY_DEFAULT
) {
11896 vty_out(vty
, " ip ospf transmit-delay %u",
11897 params
->transmit_delay
);
11898 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11899 vty_out(vty
, " %pI4",
11901 vty_out(vty
, "\n");
11905 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
11907 vty_out(vty
, " ip ospf %d",
11910 vty_out(vty
, " ip ospf");
11912 char buf
[INET_ADDRSTRLEN
];
11914 area_id2str(buf
, sizeof(buf
), ¶ms
->if_area
,
11915 params
->if_area_id_fmt
);
11916 vty_out(vty
, " area %s", buf
);
11917 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11918 vty_out(vty
, " %pI4",
11920 vty_out(vty
, "\n");
11924 if (params
&& params
->bfd_config
)
11925 ospf_bfd_write_config(vty
, params
);
11927 /* MTU ignore print. */
11928 if (OSPF_IF_PARAM_CONFIGURED(params
, mtu_ignore
)
11929 && params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
) {
11930 if (params
->mtu_ignore
== 0)
11931 vty_out(vty
, " no ip ospf mtu-ignore");
11933 vty_out(vty
, " ip ospf mtu-ignore");
11934 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11935 vty_out(vty
, " %pI4",
11937 vty_out(vty
, "\n");
11940 if (OSPF_IF_PARAM_CONFIGURED(params
,
11941 passive_interface
)) {
11942 vty_out(vty
, " %sip ospf passive",
11943 params
->passive_interface
11947 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11948 vty_out(vty
, " %pI4", &rn
->p
.u
.prefix4
);
11949 vty_out(vty
, "\n");
11952 /* LDP-Sync print */
11953 if (params
&& params
->ldp_sync_info
)
11954 ospf_ldp_sync_if_write_config(vty
, params
);
11958 rn
= route_top(IF_OIFS_PARAMS(ifp
));
11960 rn
= route_next(rn
);
11965 if (params
!= NULL
)
11970 ospf_opaque_config_write_if(vty
, ifp
);
11972 vty_endframe(vty
, "exit\n!\n");
11978 /* Configuration write function for ospfd. */
11979 static int config_write_interface(struct vty
*vty
)
11982 struct vrf
*vrf
= NULL
;
11984 /* Display all VRF aware OSPF interface configuration */
11985 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
11986 write
+= config_write_interface_one(vty
, vrf
);
11992 static int config_write_network_area(struct vty
*vty
, struct ospf
*ospf
)
11994 struct route_node
*rn
;
11995 char buf
[INET_ADDRSTRLEN
];
11997 /* `network area' print. */
11998 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
))
12000 struct ospf_network
*n
= rn
->info
;
12002 /* Create Area ID string by specified Area ID format. */
12003 if (n
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
12004 inet_ntop(AF_INET
, &n
->area_id
, buf
,
12007 snprintf(buf
, sizeof(buf
), "%lu",
12008 (unsigned long int)ntohl(
12009 n
->area_id
.s_addr
));
12011 /* Network print. */
12012 vty_out(vty
, " network %pFX area %s\n", &rn
->p
, buf
);
12018 static int config_write_ospf_area(struct vty
*vty
, struct ospf
*ospf
)
12020 struct listnode
*node
;
12021 struct ospf_area
*area
;
12022 char buf
[INET_ADDRSTRLEN
];
12024 /* Area configuration print. */
12025 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
12026 struct route_node
*rn1
;
12028 area_id2str(buf
, sizeof(buf
), &area
->area_id
,
12029 area
->area_id_fmt
);
12031 if (area
->auth_type
!= OSPF_AUTH_NULL
) {
12032 if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
12033 vty_out(vty
, " area %s authentication\n", buf
);
12036 " area %s authentication message-digest\n",
12040 if (area
->shortcut_configured
!= OSPF_SHORTCUT_DEFAULT
)
12041 vty_out(vty
, " area %s shortcut %s\n", buf
,
12042 ospf_shortcut_mode_str
12043 [area
->shortcut_configured
]);
12045 if ((area
->external_routing
== OSPF_AREA_STUB
)
12046 || (area
->external_routing
== OSPF_AREA_NSSA
)) {
12047 if (area
->external_routing
== OSPF_AREA_STUB
) {
12048 vty_out(vty
, " area %s stub", buf
);
12049 if (area
->no_summary
)
12050 vty_out(vty
, " no-summary\n");
12051 vty_out(vty
, "\n");
12052 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
12053 switch (area
->NSSATranslatorRole
) {
12054 case OSPF_NSSA_ROLE_NEVER
:
12056 " area %s nssa translate-never\n",
12059 case OSPF_NSSA_ROLE_ALWAYS
:
12061 " area %s nssa translate-always\n",
12064 case OSPF_NSSA_ROLE_CANDIDATE
:
12065 vty_out(vty
, " area %s nssa \n", buf
);
12068 if (area
->no_summary
)
12070 " area %s nssa no-summary\n",
12072 if (area
->suppress_fa
)
12074 " area %s nssa suppress-fa\n",
12078 if (area
->default_cost
!= 1)
12079 vty_out(vty
, " area %s default-cost %d\n", buf
,
12080 area
->default_cost
);
12083 for (rn1
= route_top(area
->ranges
); rn1
; rn1
= route_next(rn1
))
12085 struct ospf_area_range
*range
= rn1
->info
;
12087 vty_out(vty
, " area %s range %pFX", buf
,
12090 if (range
->cost_config
12091 != OSPF_AREA_RANGE_COST_UNSPEC
)
12092 vty_out(vty
, " cost %d",
12093 range
->cost_config
);
12095 if (!CHECK_FLAG(range
->flags
,
12096 OSPF_AREA_RANGE_ADVERTISE
))
12097 vty_out(vty
, " not-advertise");
12099 if (CHECK_FLAG(range
->flags
,
12100 OSPF_AREA_RANGE_SUBSTITUTE
))
12101 vty_out(vty
, " substitute %pI4/%d",
12102 &range
->subst_addr
,
12103 range
->subst_masklen
);
12105 vty_out(vty
, "\n");
12108 if (EXPORT_NAME(area
))
12109 vty_out(vty
, " area %s export-list %s\n", buf
,
12110 EXPORT_NAME(area
));
12112 if (IMPORT_NAME(area
))
12113 vty_out(vty
, " area %s import-list %s\n", buf
,
12114 IMPORT_NAME(area
));
12116 if (PREFIX_NAME_IN(area
))
12117 vty_out(vty
, " area %s filter-list prefix %s in\n", buf
,
12118 PREFIX_NAME_IN(area
));
12120 if (PREFIX_NAME_OUT(area
))
12121 vty_out(vty
, " area %s filter-list prefix %s out\n",
12122 buf
, PREFIX_NAME_OUT(area
));
12128 static int config_write_ospf_nbr_nbma(struct vty
*vty
, struct ospf
*ospf
)
12130 struct ospf_nbr_nbma
*nbr_nbma
;
12131 struct route_node
*rn
;
12133 /* Static Neighbor configuration print. */
12134 for (rn
= route_top(ospf
->nbr_nbma
); rn
; rn
= route_next(rn
))
12135 if ((nbr_nbma
= rn
->info
)) {
12136 vty_out(vty
, " neighbor %pI4", &nbr_nbma
->addr
);
12138 if (nbr_nbma
->priority
12139 != OSPF_NEIGHBOR_PRIORITY_DEFAULT
)
12140 vty_out(vty
, " priority %d",
12141 nbr_nbma
->priority
);
12143 if (nbr_nbma
->v_poll
!= OSPF_POLL_INTERVAL_DEFAULT
)
12144 vty_out(vty
, " poll-interval %d",
12147 vty_out(vty
, "\n");
12153 static int config_write_virtual_link(struct vty
*vty
, struct ospf
*ospf
)
12155 struct listnode
*node
;
12156 struct ospf_vl_data
*vl_data
;
12157 const char *auth_str
;
12158 char buf
[INET_ADDRSTRLEN
];
12160 /* Virtual-Link print */
12161 for (ALL_LIST_ELEMENTS_RO(ospf
->vlinks
, node
, vl_data
)) {
12162 struct listnode
*n2
;
12163 struct crypt_key
*ck
;
12164 struct ospf_interface
*oi
;
12166 if (vl_data
!= NULL
) {
12167 area_id2str(buf
, sizeof(buf
), &vl_data
->vl_area_id
,
12168 vl_data
->vl_area_id_fmt
);
12169 oi
= vl_data
->vl_oi
;
12172 if (OSPF_IF_PARAM(oi
, v_hello
)
12173 != OSPF_HELLO_INTERVAL_DEFAULT
12174 || OSPF_IF_PARAM(oi
, v_wait
)
12175 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
12176 || OSPF_IF_PARAM(oi
, retransmit_interval
)
12177 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
12178 || OSPF_IF_PARAM(oi
, transmit_delay
)
12179 != OSPF_TRANSMIT_DELAY_DEFAULT
)
12181 " area %s virtual-link %pI4 hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n",
12182 buf
, &vl_data
->vl_peer
,
12183 OSPF_IF_PARAM(oi
, v_hello
),
12184 OSPF_IF_PARAM(oi
, retransmit_interval
),
12185 OSPF_IF_PARAM(oi
, transmit_delay
),
12186 OSPF_IF_PARAM(oi
, v_wait
));
12188 vty_out(vty
, " area %s virtual-link %pI4\n", buf
,
12189 &vl_data
->vl_peer
);
12191 auth_str
= interface_config_auth_str(
12192 IF_DEF_PARAMS(oi
->ifp
));
12195 " area %s virtual-link %pI4 authentication%s\n",
12196 buf
, &vl_data
->vl_peer
, auth_str
);
12198 if (IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)->auth_simple
[0]
12201 " area %s virtual-link %pI4 authentication-key %s\n",
12202 buf
, &vl_data
->vl_peer
,
12203 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
12206 for (ALL_LIST_ELEMENTS_RO(
12207 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
12211 " area %s virtual-link %pI4 message-digest-key %d md5 %s\n",
12212 buf
, &vl_data
->vl_peer
,
12213 ck
->key_id
, ck
->auth_key
);
12221 static int config_write_ospf_redistribute(struct vty
*vty
, struct ospf
*ospf
)
12225 /* redistribute print. */
12226 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
12227 struct list
*red_list
;
12228 struct listnode
*node
;
12229 struct ospf_redist
*red
;
12231 red_list
= ospf
->redist
[type
];
12235 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
12236 vty_out(vty
, " redistribute %s",
12237 zebra_route_string(type
));
12239 vty_out(vty
, " %d", red
->instance
);
12241 if (red
->dmetric
.value
>= 0)
12242 vty_out(vty
, " metric %d", red
->dmetric
.value
);
12244 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
12245 vty_out(vty
, " metric-type 1");
12247 if (ROUTEMAP_NAME(red
))
12248 vty_out(vty
, " route-map %s",
12249 ROUTEMAP_NAME(red
));
12251 vty_out(vty
, "\n");
12258 static int ospf_cfg_write_helper_dis_rtr_walkcb(struct hash_bucket
*bucket
,
12261 struct advRtr
*rtr
= bucket
->data
;
12262 struct vty
*vty
= (struct vty
*)arg
;
12264 vty_out(vty
, " graceful-restart helper-only %pI4\n",
12266 return HASHWALK_CONTINUE
;
12269 static void config_write_ospf_gr(struct vty
*vty
, struct ospf
*ospf
)
12271 if (!ospf
->gr_info
.restart_support
)
12274 if (ospf
->gr_info
.grace_period
== OSPF_DFLT_GRACE_INTERVAL
)
12275 vty_out(vty
, " graceful-restart\n");
12277 vty_out(vty
, " graceful-restart grace-period %u\n",
12278 ospf
->gr_info
.grace_period
);
12281 static int config_write_ospf_gr_helper(struct vty
*vty
, struct ospf
*ospf
)
12283 if (ospf
->is_helper_supported
)
12284 vty_out(vty
, " graceful-restart helper-only\n");
12286 if (!ospf
->strict_lsa_check
)
12288 " no graceful-restart helper strict-lsa-checking\n");
12290 if (ospf
->only_planned_restart
)
12291 vty_out(vty
, " graceful-restart helper planned-only\n");
12293 if (ospf
->supported_grace_time
!= OSPF_MAX_GRACE_INTERVAL
)
12295 " graceful-restart helper supported-grace-time %d\n",
12296 ospf
->supported_grace_time
);
12298 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf
)) {
12299 hash_walk(ospf
->enable_rtr_list
,
12300 ospf_cfg_write_helper_dis_rtr_walkcb
, vty
);
12305 static int config_write_ospf_external_aggregator(struct vty
*vty
,
12308 struct route_node
*rn
;
12310 /* print 'summary-address A.B.C.D/M' */
12311 for (rn
= route_top(ospf
->rt_aggr_tbl
); rn
; rn
= route_next(rn
))
12313 struct ospf_external_aggr_rt
*aggr
= rn
->info
;
12315 vty_out(vty
, " summary-address %pI4/%d ",
12316 &aggr
->p
.prefix
, aggr
->p
.prefixlen
);
12318 vty_out(vty
, " tag %u ", aggr
->tag
);
12320 if (CHECK_FLAG(aggr
->flags
,
12321 OSPF_EXTERNAL_AGGRT_NO_ADVERTISE
))
12322 vty_out(vty
, " no-advertise");
12324 vty_out(vty
, "\n");
12330 static int config_write_ospf_default_metric(struct vty
*vty
, struct ospf
*ospf
)
12332 if (ospf
->default_metric
!= -1)
12333 vty_out(vty
, " default-metric %d\n", ospf
->default_metric
);
12337 static int config_write_ospf_distribute(struct vty
*vty
, struct ospf
*ospf
)
12340 struct ospf_redist
*red
;
12343 /* distribute-list print. */
12344 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
12345 if (DISTRIBUTE_NAME(ospf
, type
))
12346 vty_out(vty
, " distribute-list %s out %s\n",
12347 DISTRIBUTE_NAME(ospf
, type
),
12348 zebra_route_string(type
));
12350 /* default-information print. */
12351 if (ospf
->default_originate
!= DEFAULT_ORIGINATE_NONE
) {
12352 vty_out(vty
, " default-information originate");
12353 if (ospf
->default_originate
== DEFAULT_ORIGINATE_ALWAYS
)
12354 vty_out(vty
, " always");
12356 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
12358 if (red
->dmetric
.value
>= 0)
12359 vty_out(vty
, " metric %d",
12360 red
->dmetric
.value
);
12362 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
12363 vty_out(vty
, " metric-type 1");
12365 if (ROUTEMAP_NAME(red
))
12366 vty_out(vty
, " route-map %s",
12367 ROUTEMAP_NAME(red
));
12370 vty_out(vty
, "\n");
12377 static int config_write_ospf_distance(struct vty
*vty
, struct ospf
*ospf
)
12379 struct route_node
*rn
;
12380 struct ospf_distance
*odistance
;
12382 if (ospf
->distance_all
)
12383 vty_out(vty
, " distance %d\n", ospf
->distance_all
);
12385 if (ospf
->distance_intra
|| ospf
->distance_inter
12386 || ospf
->distance_external
) {
12387 vty_out(vty
, " distance ospf");
12389 if (ospf
->distance_intra
)
12390 vty_out(vty
, " intra-area %d", ospf
->distance_intra
);
12391 if (ospf
->distance_inter
)
12392 vty_out(vty
, " inter-area %d", ospf
->distance_inter
);
12393 if (ospf
->distance_external
)
12394 vty_out(vty
, " external %d", ospf
->distance_external
);
12396 vty_out(vty
, "\n");
12399 for (rn
= route_top(ospf
->distance_table
); rn
; rn
= route_next(rn
))
12400 if ((odistance
= rn
->info
) != NULL
) {
12401 vty_out(vty
, " distance %d %pFX %s\n",
12402 odistance
->distance
, &rn
->p
,
12403 odistance
->access_list
? odistance
->access_list
12409 static int ospf_config_write_one(struct vty
*vty
, struct ospf
*ospf
)
12413 /* `router ospf' print. */
12414 if (ospf
->instance
&& ospf
->name
) {
12415 vty_out(vty
, "router ospf %d vrf %s\n", ospf
->instance
,
12417 } else if (ospf
->instance
) {
12418 vty_out(vty
, "router ospf %d\n", ospf
->instance
);
12419 } else if (ospf
->name
) {
12420 vty_out(vty
, "router ospf vrf %s\n", ospf
->name
);
12422 vty_out(vty
, "router ospf\n");
12424 if (!ospf
->networks
) {
12429 /* Router ID print. */
12430 if (ospf
->router_id_static
.s_addr
!= INADDR_ANY
)
12431 vty_out(vty
, " ospf router-id %pI4\n",
12432 &ospf
->router_id_static
);
12434 /* ABR type print. */
12435 if (ospf
->abr_type
!= OSPF_ABR_DEFAULT
)
12436 vty_out(vty
, " ospf abr-type %s\n",
12437 ospf_abr_type_str
[ospf
->abr_type
]);
12439 /* log-adjacency-changes flag print. */
12440 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
12441 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
))
12442 vty_out(vty
, " log-adjacency-changes detail\n");
12443 else if (!SAVE_OSPF_LOG_ADJACENCY_CHANGES
)
12444 vty_out(vty
, " log-adjacency-changes\n");
12445 } else if (SAVE_OSPF_LOG_ADJACENCY_CHANGES
) {
12446 vty_out(vty
, " no log-adjacency-changes\n");
12449 /* RFC1583 compatibility flag print -- Compatible with CISCO
12451 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
))
12452 vty_out(vty
, " compatible rfc1583\n");
12454 /* auto-cost reference-bandwidth configuration. */
12455 if (ospf
->ref_bandwidth
!= OSPF_DEFAULT_REF_BANDWIDTH
) {
12457 "! Important: ensure reference bandwidth is consistent across all routers\n");
12458 vty_out(vty
, " auto-cost reference-bandwidth %d\n",
12459 ospf
->ref_bandwidth
);
12462 /* SPF timers print. */
12463 if (ospf
->spf_delay
!= OSPF_SPF_DELAY_DEFAULT
12464 || ospf
->spf_holdtime
!= OSPF_SPF_HOLDTIME_DEFAULT
12465 || ospf
->spf_max_holdtime
!= OSPF_SPF_MAX_HOLDTIME_DEFAULT
)
12466 vty_out(vty
, " timers throttle spf %d %d %d\n", ospf
->spf_delay
,
12467 ospf
->spf_holdtime
, ospf
->spf_max_holdtime
);
12469 /* LSA timers print. */
12470 if (ospf
->min_ls_interval
!= OSPF_MIN_LS_INTERVAL
)
12471 vty_out(vty
, " timers throttle lsa all %d\n",
12472 ospf
->min_ls_interval
);
12473 if (ospf
->min_ls_arrival
!= OSPF_MIN_LS_ARRIVAL
)
12474 vty_out(vty
, " timers lsa min-arrival %d\n",
12475 ospf
->min_ls_arrival
);
12477 /* Write multiplier print. */
12478 if (ospf
->write_oi_count
!= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
)
12479 vty_out(vty
, " ospf write-multiplier %d\n",
12480 ospf
->write_oi_count
);
12482 if (ospf
->max_multipath
!= MULTIPATH_NUM
)
12483 vty_out(vty
, " maximum-paths %d\n", ospf
->max_multipath
);
12485 /* Max-metric router-lsa print */
12486 config_write_stub_router(vty
, ospf
);
12488 /* SPF refresh parameters print. */
12489 if (ospf
->lsa_refresh_interval
!= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
12490 vty_out(vty
, " refresh timer %d\n", ospf
->lsa_refresh_interval
);
12492 /* Redistribute information print. */
12493 config_write_ospf_redistribute(vty
, ospf
);
12495 /* Graceful Restart print */
12496 config_write_ospf_gr(vty
, ospf
);
12497 config_write_ospf_gr_helper(vty
, ospf
);
12499 /* Print external route aggregation. */
12500 config_write_ospf_external_aggregator(vty
, ospf
);
12502 /* passive-interface print. */
12503 if (ospf
->passive_interface_default
== OSPF_IF_PASSIVE
)
12504 vty_out(vty
, " passive-interface default\n");
12506 /* proactive-arp print. */
12507 if (ospf
->proactive_arp
!= OSPF_PROACTIVE_ARP_DEFAULT
) {
12508 if (ospf
->proactive_arp
)
12509 vty_out(vty
, " proactive-arp\n");
12511 vty_out(vty
, " no proactive-arp\n");
12514 /* TI-LFA print. */
12515 if (ospf
->ti_lfa_enabled
) {
12516 if (ospf
->ti_lfa_protection_type
== OSPF_TI_LFA_NODE_PROTECTION
)
12517 vty_out(vty
, " fast-reroute ti-lfa node-protection\n");
12519 vty_out(vty
, " fast-reroute ti-lfa\n");
12522 /* Network area print. */
12523 config_write_network_area(vty
, ospf
);
12525 /* Area config print. */
12526 config_write_ospf_area(vty
, ospf
);
12528 /* static neighbor print. */
12529 config_write_ospf_nbr_nbma(vty
, ospf
);
12531 /* Virtual-Link print. */
12532 config_write_virtual_link(vty
, ospf
);
12534 /* Default metric configuration. */
12535 config_write_ospf_default_metric(vty
, ospf
);
12537 /* Distribute-list and default-information print. */
12538 config_write_ospf_distribute(vty
, ospf
);
12540 /* Distance configuration. */
12541 config_write_ospf_distance(vty
, ospf
);
12543 ospf_opaque_config_write_router(vty
, ospf
);
12545 /* LDP-Sync print */
12546 ospf_ldp_sync_write_config(vty
, ospf
);
12548 vty_out(vty
, "exit\n");
12554 /* OSPF configuration write function. */
12555 static int ospf_config_write(struct vty
*vty
)
12558 struct listnode
*ospf_node
= NULL
;
12561 if (listcount(om
->ospf
) == 0)
12564 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, ospf_node
, ospf
)) {
12565 /* VRF Default check if it is running.
12566 * Upon daemon start, there could be default instance
12567 * in absence of 'router ospf'/oi_running is disabled. */
12568 if (ospf
->vrf_id
== VRF_DEFAULT
&& ospf
->oi_running
)
12569 write
+= ospf_config_write_one(vty
, ospf
);
12570 /* For Non-Default VRF simply display the configuration,
12571 * even if it is not oi_running. */
12572 else if (ospf
->vrf_id
!= VRF_DEFAULT
)
12573 write
+= ospf_config_write_one(vty
, ospf
);
12578 void ospf_vty_show_init(void)
12580 /* "show ip ospf" commands. */
12581 install_element(VIEW_NODE
, &show_ip_ospf_cmd
);
12583 install_element(VIEW_NODE
, &show_ip_ospf_instance_cmd
);
12585 /* "show ip ospf database" commands. */
12586 install_element(VIEW_NODE
, &show_ip_ospf_database_cmd
);
12587 install_element(VIEW_NODE
, &show_ip_ospf_database_max_cmd
);
12588 install_element(VIEW_NODE
,
12589 &show_ip_ospf_database_type_adv_router_cmd
);
12590 install_element(VIEW_NODE
,
12591 &show_ip_ospf_instance_database_type_adv_router_cmd
);
12592 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_cmd
);
12593 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_max_cmd
);
12595 /* "show ip ospf interface" commands. */
12596 install_element(VIEW_NODE
, &show_ip_ospf_interface_cmd
);
12598 install_element(VIEW_NODE
, &show_ip_ospf_instance_interface_cmd
);
12599 /* "show ip ospf interface traffic */
12600 install_element(VIEW_NODE
, &show_ip_ospf_interface_traffic_cmd
);
12602 /* "show ip ospf neighbor" commands. */
12603 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_detail_cmd
);
12604 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_cmd
);
12605 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_id_cmd
);
12606 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_all_cmd
);
12607 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_cmd
);
12608 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_cmd
);
12609 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_all_cmd
);
12611 install_element(VIEW_NODE
,
12612 &show_ip_ospf_instance_neighbor_int_detail_cmd
);
12613 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_int_cmd
);
12614 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_id_cmd
);
12615 install_element(VIEW_NODE
,
12616 &show_ip_ospf_instance_neighbor_detail_all_cmd
);
12617 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_detail_cmd
);
12618 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_cmd
);
12619 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_all_cmd
);
12621 /* "show ip ospf route" commands. */
12622 install_element(VIEW_NODE
, &show_ip_ospf_route_cmd
);
12623 install_element(VIEW_NODE
, &show_ip_ospf_border_routers_cmd
);
12625 install_element(VIEW_NODE
, &show_ip_ospf_instance_route_cmd
);
12626 install_element(VIEW_NODE
, &show_ip_ospf_instance_border_routers_cmd
);
12628 /* "show ip ospf vrfs" commands. */
12629 install_element(VIEW_NODE
, &show_ip_ospf_vrfs_cmd
);
12631 /* "show ip ospf gr-helper details" command */
12632 install_element(VIEW_NODE
, &show_ip_ospf_gr_helper_cmd
);
12634 /* "show ip ospf summary-address" command */
12635 install_element(VIEW_NODE
, &show_ip_ospf_external_aggregator_cmd
);
12638 /* Initialization of OSPF interface. */
12639 static void ospf_vty_if_init(void)
12641 /* Install interface node. */
12642 if_cmd_init(config_write_interface
);
12644 /* "ip ospf authentication" commands. */
12645 install_element(INTERFACE_NODE
, &ip_ospf_authentication_args_addr_cmd
);
12646 install_element(INTERFACE_NODE
, &ip_ospf_authentication_addr_cmd
);
12647 install_element(INTERFACE_NODE
,
12648 &no_ip_ospf_authentication_args_addr_cmd
);
12649 install_element(INTERFACE_NODE
, &no_ip_ospf_authentication_addr_cmd
);
12650 install_element(INTERFACE_NODE
, &ip_ospf_authentication_key_addr_cmd
);
12651 install_element(INTERFACE_NODE
,
12652 &no_ip_ospf_authentication_key_authkey_addr_cmd
);
12653 install_element(INTERFACE_NODE
,
12654 &no_ospf_authentication_key_authkey_addr_cmd
);
12656 /* "ip ospf message-digest-key" commands. */
12657 install_element(INTERFACE_NODE
, &ip_ospf_message_digest_key_cmd
);
12658 install_element(INTERFACE_NODE
, &no_ip_ospf_message_digest_key_cmd
);
12660 /* "ip ospf cost" commands. */
12661 install_element(INTERFACE_NODE
, &ip_ospf_cost_cmd
);
12662 install_element(INTERFACE_NODE
, &no_ip_ospf_cost_cmd
);
12664 /* "ip ospf mtu-ignore" commands. */
12665 install_element(INTERFACE_NODE
, &ip_ospf_mtu_ignore_addr_cmd
);
12666 install_element(INTERFACE_NODE
, &no_ip_ospf_mtu_ignore_addr_cmd
);
12668 /* "ip ospf dead-interval" commands. */
12669 install_element(INTERFACE_NODE
, &ip_ospf_dead_interval_cmd
);
12670 install_element(INTERFACE_NODE
,
12671 &ip_ospf_dead_interval_minimal_addr_cmd
);
12672 install_element(INTERFACE_NODE
, &no_ip_ospf_dead_interval_cmd
);
12674 /* "ip ospf hello-interval" commands. */
12675 install_element(INTERFACE_NODE
, &ip_ospf_hello_interval_cmd
);
12676 install_element(INTERFACE_NODE
, &no_ip_ospf_hello_interval_cmd
);
12678 /* "ip ospf network" commands. */
12679 install_element(INTERFACE_NODE
, &ip_ospf_network_cmd
);
12680 install_element(INTERFACE_NODE
, &no_ip_ospf_network_cmd
);
12682 /* "ip ospf priority" commands. */
12683 install_element(INTERFACE_NODE
, &ip_ospf_priority_cmd
);
12684 install_element(INTERFACE_NODE
, &no_ip_ospf_priority_cmd
);
12686 /* "ip ospf retransmit-interval" commands. */
12687 install_element(INTERFACE_NODE
, &ip_ospf_retransmit_interval_addr_cmd
);
12688 install_element(INTERFACE_NODE
,
12689 &no_ip_ospf_retransmit_interval_addr_cmd
);
12691 /* "ip ospf transmit-delay" commands. */
12692 install_element(INTERFACE_NODE
, &ip_ospf_transmit_delay_addr_cmd
);
12693 install_element(INTERFACE_NODE
, &no_ip_ospf_transmit_delay_addr_cmd
);
12695 /* "ip ospf area" commands. */
12696 install_element(INTERFACE_NODE
, &ip_ospf_area_cmd
);
12697 install_element(INTERFACE_NODE
, &no_ip_ospf_area_cmd
);
12699 /* "ip ospf passive" commands. */
12700 install_element(INTERFACE_NODE
, &ip_ospf_passive_cmd
);
12701 install_element(INTERFACE_NODE
, &no_ip_ospf_passive_cmd
);
12703 /* These commands are compatibitliy for previous version. */
12704 install_element(INTERFACE_NODE
, &ospf_authentication_key_cmd
);
12705 install_element(INTERFACE_NODE
, &ospf_message_digest_key_cmd
);
12706 install_element(INTERFACE_NODE
, &no_ospf_message_digest_key_cmd
);
12707 install_element(INTERFACE_NODE
, &ospf_dead_interval_cmd
);
12708 install_element(INTERFACE_NODE
, &no_ospf_dead_interval_cmd
);
12709 install_element(INTERFACE_NODE
, &ospf_hello_interval_cmd
);
12710 install_element(INTERFACE_NODE
, &no_ospf_hello_interval_cmd
);
12711 install_element(INTERFACE_NODE
, &ospf_cost_cmd
);
12712 install_element(INTERFACE_NODE
, &no_ospf_cost_cmd
);
12713 install_element(INTERFACE_NODE
, &ospf_network_cmd
);
12714 install_element(INTERFACE_NODE
, &no_ospf_network_cmd
);
12715 install_element(INTERFACE_NODE
, &ospf_priority_cmd
);
12716 install_element(INTERFACE_NODE
, &no_ospf_priority_cmd
);
12717 install_element(INTERFACE_NODE
, &ospf_retransmit_interval_cmd
);
12718 install_element(INTERFACE_NODE
, &no_ospf_retransmit_interval_cmd
);
12719 install_element(INTERFACE_NODE
, &ospf_transmit_delay_cmd
);
12720 install_element(INTERFACE_NODE
, &no_ospf_transmit_delay_cmd
);
12723 static void ospf_vty_zebra_init(void)
12725 install_element(OSPF_NODE
, &ospf_redistribute_source_cmd
);
12726 install_element(OSPF_NODE
, &no_ospf_redistribute_source_cmd
);
12727 install_element(OSPF_NODE
, &ospf_redistribute_instance_source_cmd
);
12728 install_element(OSPF_NODE
, &no_ospf_redistribute_instance_source_cmd
);
12730 install_element(OSPF_NODE
, &ospf_distribute_list_out_cmd
);
12731 install_element(OSPF_NODE
, &no_ospf_distribute_list_out_cmd
);
12733 install_element(OSPF_NODE
, &ospf_default_information_originate_cmd
);
12734 install_element(OSPF_NODE
, &no_ospf_default_information_originate_cmd
);
12736 install_element(OSPF_NODE
, &ospf_default_metric_cmd
);
12737 install_element(OSPF_NODE
, &no_ospf_default_metric_cmd
);
12739 install_element(OSPF_NODE
, &ospf_distance_cmd
);
12740 install_element(OSPF_NODE
, &no_ospf_distance_cmd
);
12741 install_element(OSPF_NODE
, &no_ospf_distance_ospf_cmd
);
12742 install_element(OSPF_NODE
, &ospf_distance_ospf_cmd
);
12744 /*Ospf garcefull restart helper configurations */
12745 install_element(OSPF_NODE
, &ospf_gr_helper_enable_cmd
);
12746 install_element(OSPF_NODE
, &no_ospf_gr_helper_enable_cmd
);
12747 install_element(OSPF_NODE
, &ospf_gr_helper_enable_lsacheck_cmd
);
12748 install_element(OSPF_NODE
, &no_ospf_gr_helper_enable_lsacheck_cmd
);
12749 install_element(OSPF_NODE
, &ospf_gr_helper_supported_grace_time_cmd
);
12750 install_element(OSPF_NODE
, &no_ospf_gr_helper_supported_grace_time_cmd
);
12751 install_element(OSPF_NODE
, &ospf_gr_helper_planned_only_cmd
);
12752 install_element(OSPF_NODE
, &no_ospf_gr_helper_planned_only_cmd
);
12754 /* External LSA summarisation config commands.*/
12755 install_element(OSPF_NODE
, &ospf_external_route_aggregation_cmd
);
12756 install_element(OSPF_NODE
, &no_ospf_external_route_aggregation_cmd
);
12757 install_element(OSPF_NODE
,
12758 &ospf_external_route_aggregation_no_adrvertise_cmd
);
12759 install_element(OSPF_NODE
,
12760 &no_ospf_external_route_aggregation_no_adrvertise_cmd
);
12761 install_element(OSPF_NODE
, &ospf_route_aggregation_timer_cmd
);
12762 install_element(OSPF_NODE
, &no_ospf_route_aggregation_timer_cmd
);
12765 static int ospf_config_write(struct vty
*vty
);
12766 static struct cmd_node ospf_node
= {
12769 .parent_node
= CONFIG_NODE
,
12770 .prompt
= "%s(config-router)# ",
12771 .config_write
= ospf_config_write
,
12774 static void ospf_interface_clear(struct interface
*ifp
)
12776 if (!if_is_operative(ifp
))
12779 if (IS_DEBUG_OSPF(ism
, ISM_EVENTS
))
12780 zlog_debug("ISM[%s]: clear by reset", ifp
->name
);
12782 ospf_if_reset(ifp
);
12785 DEFUN (clear_ip_ospf_interface
,
12786 clear_ip_ospf_interface_cmd
,
12787 "clear ip ospf [vrf NAME] interface [IFNAME]",
12790 "OSPF information\n"
12792 "Interface information\n"
12793 "Interface name\n")
12795 int idx_ifname
= 0;
12797 struct interface
*ifp
;
12798 struct listnode
*node
;
12799 struct ospf
*ospf
= NULL
;
12800 char *vrf_name
= NULL
;
12801 vrf_id_t vrf_id
= VRF_DEFAULT
;
12802 struct vrf
*vrf
= NULL
;
12804 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
12805 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
12806 if (vrf_name
&& strmatch(vrf_name
, VRF_DEFAULT_NAME
))
12809 vrf
= vrf_lookup_by_name(vrf_name
);
12811 vrf_id
= vrf
->vrf_id
;
12813 if (!argv_find(argv
, argc
, "IFNAME", &idx_ifname
)) {
12814 /* Clear all the ospfv2 interfaces. */
12815 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
12816 if (vrf_id
!= ospf
->vrf_id
)
12819 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
12820 FOR_ALL_INTERFACES (vrf
, ifp
)
12821 ospf_interface_clear(ifp
);
12824 /* Interface name is specified. */
12825 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf_id
);
12827 vty_out(vty
, "No such interface name\n");
12829 ospf_interface_clear(ifp
);
12832 return CMD_SUCCESS
;
12835 void ospf_vty_clear_init(void)
12837 install_element(ENABLE_NODE
, &clear_ip_ospf_interface_cmd
);
12838 install_element(ENABLE_NODE
, &clear_ip_ospf_process_cmd
);
12839 install_element(ENABLE_NODE
, &clear_ip_ospf_neighbor_cmd
);
12843 /* Install OSPF related vty commands. */
12844 void ospf_vty_init(void)
12846 /* Install ospf top node. */
12847 install_node(&ospf_node
);
12849 /* "router ospf" commands. */
12850 install_element(CONFIG_NODE
, &router_ospf_cmd
);
12851 install_element(CONFIG_NODE
, &no_router_ospf_cmd
);
12854 install_default(OSPF_NODE
);
12856 /* "ospf router-id" commands. */
12857 install_element(OSPF_NODE
, &ospf_router_id_cmd
);
12858 install_element(OSPF_NODE
, &ospf_router_id_old_cmd
);
12859 install_element(OSPF_NODE
, &no_ospf_router_id_cmd
);
12861 /* "passive-interface" commands. */
12862 install_element(OSPF_NODE
, &ospf_passive_interface_default_cmd
);
12863 install_element(OSPF_NODE
, &ospf_passive_interface_addr_cmd
);
12864 install_element(OSPF_NODE
, &no_ospf_passive_interface_default_cmd
);
12865 install_element(OSPF_NODE
, &no_ospf_passive_interface_addr_cmd
);
12867 /* "ospf abr-type" commands. */
12868 install_element(OSPF_NODE
, &ospf_abr_type_cmd
);
12869 install_element(OSPF_NODE
, &no_ospf_abr_type_cmd
);
12871 /* "ospf log-adjacency-changes" commands. */
12872 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_cmd
);
12873 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_detail_cmd
);
12874 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_cmd
);
12875 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_detail_cmd
);
12877 /* "ospf rfc1583-compatible" commands. */
12878 install_element(OSPF_NODE
, &ospf_compatible_rfc1583_cmd
);
12879 install_element(OSPF_NODE
, &no_ospf_compatible_rfc1583_cmd
);
12880 install_element(OSPF_NODE
, &ospf_rfc1583_flag_cmd
);
12881 install_element(OSPF_NODE
, &no_ospf_rfc1583_flag_cmd
);
12883 /* "network area" commands. */
12884 install_element(OSPF_NODE
, &ospf_network_area_cmd
);
12885 install_element(OSPF_NODE
, &no_ospf_network_area_cmd
);
12887 /* "area authentication" commands. */
12888 install_element(OSPF_NODE
,
12889 &ospf_area_authentication_message_digest_cmd
);
12890 install_element(OSPF_NODE
, &ospf_area_authentication_cmd
);
12891 install_element(OSPF_NODE
, &no_ospf_area_authentication_cmd
);
12893 /* "area range" commands. */
12894 install_element(OSPF_NODE
, &ospf_area_range_cmd
);
12895 install_element(OSPF_NODE
, &ospf_area_range_cost_cmd
);
12896 install_element(OSPF_NODE
, &ospf_area_range_not_advertise_cmd
);
12897 install_element(OSPF_NODE
, &no_ospf_area_range_cmd
);
12898 install_element(OSPF_NODE
, &ospf_area_range_substitute_cmd
);
12899 install_element(OSPF_NODE
, &no_ospf_area_range_substitute_cmd
);
12901 /* "area virtual-link" commands. */
12902 install_element(OSPF_NODE
, &ospf_area_vlink_cmd
);
12903 install_element(OSPF_NODE
, &ospf_area_vlink_intervals_cmd
);
12904 install_element(OSPF_NODE
, &no_ospf_area_vlink_cmd
);
12905 install_element(OSPF_NODE
, &no_ospf_area_vlink_intervals_cmd
);
12908 /* "area stub" commands. */
12909 install_element(OSPF_NODE
, &ospf_area_stub_no_summary_cmd
);
12910 install_element(OSPF_NODE
, &ospf_area_stub_cmd
);
12911 install_element(OSPF_NODE
, &no_ospf_area_stub_no_summary_cmd
);
12912 install_element(OSPF_NODE
, &no_ospf_area_stub_cmd
);
12914 /* "area nssa" commands. */
12915 install_element(OSPF_NODE
, &ospf_area_nssa_cmd
);
12916 install_element(OSPF_NODE
, &ospf_area_nssa_translate_cmd
);
12917 install_element(OSPF_NODE
, &ospf_area_nssa_no_summary_cmd
);
12918 install_element(OSPF_NODE
, &no_ospf_area_nssa_no_summary_cmd
);
12919 install_element(OSPF_NODE
, &ospf_area_nssa_suppress_fa_cmd
);
12920 install_element(OSPF_NODE
, &no_ospf_area_nssa_suppress_fa_cmd
);
12921 install_element(OSPF_NODE
, &no_ospf_area_nssa_cmd
);
12923 install_element(OSPF_NODE
, &ospf_area_default_cost_cmd
);
12924 install_element(OSPF_NODE
, &no_ospf_area_default_cost_cmd
);
12926 install_element(OSPF_NODE
, &ospf_area_shortcut_cmd
);
12927 install_element(OSPF_NODE
, &no_ospf_area_shortcut_cmd
);
12929 install_element(OSPF_NODE
, &ospf_area_export_list_cmd
);
12930 install_element(OSPF_NODE
, &no_ospf_area_export_list_cmd
);
12932 install_element(OSPF_NODE
, &ospf_area_filter_list_cmd
);
12933 install_element(OSPF_NODE
, &no_ospf_area_filter_list_cmd
);
12935 install_element(OSPF_NODE
, &ospf_area_import_list_cmd
);
12936 install_element(OSPF_NODE
, &no_ospf_area_import_list_cmd
);
12938 /* SPF timer commands */
12939 install_element(OSPF_NODE
, &ospf_timers_throttle_spf_cmd
);
12940 install_element(OSPF_NODE
, &no_ospf_timers_throttle_spf_cmd
);
12942 /* LSA timers commands */
12943 install_element(OSPF_NODE
, &ospf_timers_min_ls_interval_cmd
);
12944 install_element(OSPF_NODE
, &no_ospf_timers_min_ls_interval_cmd
);
12945 install_element(OSPF_NODE
, &ospf_timers_lsa_min_arrival_cmd
);
12946 install_element(OSPF_NODE
, &no_ospf_timers_lsa_min_arrival_cmd
);
12948 /* refresh timer commands */
12949 install_element(OSPF_NODE
, &ospf_refresh_timer_cmd
);
12950 install_element(OSPF_NODE
, &no_ospf_refresh_timer_val_cmd
);
12952 /* max-metric commands */
12953 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_admin_cmd
);
12954 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_admin_cmd
);
12955 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_startup_cmd
);
12956 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_startup_cmd
);
12957 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_shutdown_cmd
);
12958 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_shutdown_cmd
);
12960 /* reference bandwidth commands */
12961 install_element(OSPF_NODE
, &ospf_auto_cost_reference_bandwidth_cmd
);
12962 install_element(OSPF_NODE
, &no_ospf_auto_cost_reference_bandwidth_cmd
);
12964 /* "neighbor" commands. */
12965 install_element(OSPF_NODE
, &ospf_neighbor_cmd
);
12966 install_element(OSPF_NODE
, &ospf_neighbor_poll_interval_cmd
);
12967 install_element(OSPF_NODE
, &no_ospf_neighbor_cmd
);
12968 install_element(OSPF_NODE
, &no_ospf_neighbor_poll_cmd
);
12970 /* write multiplier commands */
12971 install_element(OSPF_NODE
, &ospf_write_multiplier_cmd
);
12972 install_element(OSPF_NODE
, &write_multiplier_cmd
);
12973 install_element(OSPF_NODE
, &no_ospf_write_multiplier_cmd
);
12974 install_element(OSPF_NODE
, &no_write_multiplier_cmd
);
12976 /* "proactive-arp" commands. */
12977 install_element(OSPF_NODE
, &ospf_proactive_arp_cmd
);
12978 install_element(OSPF_NODE
, &no_ospf_proactive_arp_cmd
);
12980 /* TI-LFA commands */
12981 install_element(OSPF_NODE
, &ospf_ti_lfa_cmd
);
12982 install_element(OSPF_NODE
, &no_ospf_ti_lfa_cmd
);
12984 /* Max path configurations */
12985 install_element(OSPF_NODE
, &ospf_max_multipath_cmd
);
12986 install_element(OSPF_NODE
, &no_ospf_max_multipath_cmd
);
12988 vrf_cmd_init(NULL
);
12990 /* Init interface related vty commands. */
12991 ospf_vty_if_init();
12993 /* Init zebra related vty commands. */
12994 ospf_vty_zebra_init();