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();
4685 json_neighbor_sub
= json_object_new_object();
4688 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4690 show_ip_ospf_neighbour_header(vty
);
4692 if (ospf
->instance
) {
4694 json_object_int_add(json_vrf
, "ospfInstance",
4697 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4700 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4701 struct listnode
*nbr_node
;
4702 struct ospf_nbr_nbma
*nbr_nbma
;
4704 show_ip_ospf_neighbor_sub(vty
, oi
, json_vrf
, use_json
);
4706 /* print Down neighbor status */
4707 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nbr_node
, nbr_nbma
)) {
4708 if (nbr_nbma
->nbr
== NULL
4709 || nbr_nbma
->nbr
->state
== NSM_Down
) {
4711 json_object_int_add(json_neighbor_sub
,
4713 nbr_nbma
->priority
);
4714 json_object_boolean_true_add(
4717 json_object_string_add(
4721 json_object_int_add(
4723 "nbrNbmaRetransmitCounter", 0);
4724 json_object_int_add(
4726 "nbrNbmaRequestCounter", 0);
4727 json_object_int_add(
4729 "nbrNbmaDbSummaryCounter", 0);
4730 json_object_object_add(
4733 &nbr_nbma
->addr
, buf
,
4737 vty_out(vty
, "%-15s %3d %-15s %9s ",
4738 "-", nbr_nbma
->priority
, "Down",
4741 "%-32pI4 %-20s %5d %5d %5d\n",
4743 IF_NAME(oi
), 0, 0, 0);
4751 if (ospf
->vrf_id
== VRF_DEFAULT
)
4752 json_object_object_add(json
, "default",
4755 json_object_object_add(json
, ospf
->name
,
4764 DEFUN (show_ip_ospf_neighbor_all
,
4765 show_ip_ospf_neighbor_all_cmd
,
4766 "show ip ospf [vrf <NAME|all>] neighbor all [json]",
4769 "OSPF information\n"
4773 "include down status neighbor\n"
4777 bool uj
= use_json(argc
, argv
);
4778 struct listnode
*node
= NULL
;
4779 char *vrf_name
= NULL
;
4780 bool all_vrf
= false;
4781 int ret
= CMD_SUCCESS
;
4784 uint8_t use_vrf
= 0;
4785 json_object
*json
= NULL
;
4787 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4790 json
= json_object_new_object();
4792 /* vrf input is provided could be all or specific vrf*/
4796 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4797 if (!ospf
->oi_running
)
4799 ret
= show_ip_ospf_neighbor_all_common(
4800 vty
, ospf
, json
, uj
, use_vrf
);
4804 vty_out(vty
, "%s\n",
4805 json_object_to_json_string_ext(
4806 json
, JSON_C_TO_STRING_PRETTY
));
4807 json_object_free(json
);
4813 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4814 if (ospf
== NULL
|| !ospf
->oi_running
) {
4816 json_object_free(json
);
4820 /* Display default ospf (instance 0) info */
4821 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4822 if (ospf
== NULL
|| !ospf
->oi_running
) {
4824 json_object_free(json
);
4830 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
,
4833 vty_out(vty
, "%s\n",
4834 json_object_to_json_string_ext(
4835 json
, JSON_C_TO_STRING_PRETTY
));
4840 json_object_free(json
);
4845 DEFUN (show_ip_ospf_instance_neighbor_all
,
4846 show_ip_ospf_instance_neighbor_all_cmd
,
4847 "show ip ospf (1-65535) neighbor all [json]",
4850 "OSPF information\n"
4853 "include down status neighbor\n"
4858 unsigned short instance
= 0;
4859 bool uj
= use_json(argc
, argv
);
4860 json_object
*json
= NULL
;
4861 int ret
= CMD_SUCCESS
;
4863 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4864 if (instance
!= ospf_instance
)
4865 return CMD_NOT_MY_INSTANCE
;
4867 ospf
= ospf_lookup_instance(instance
);
4868 if (!ospf
|| !ospf
->oi_running
)
4871 json
= json_object_new_object();
4873 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
, 0);
4876 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4877 json
, JSON_C_TO_STRING_PRETTY
));
4878 json_object_free(json
);
4884 static int show_ip_ospf_neighbor_int_common(struct vty
*vty
, struct ospf
*ospf
,
4886 struct cmd_token
**argv
,
4887 bool use_json
, uint8_t use_vrf
)
4889 struct interface
*ifp
;
4890 struct route_node
*rn
;
4891 json_object
*json
= NULL
;
4894 json
= json_object_new_object();
4896 if (ospf
->instance
) {
4898 json_object_int_add(json
, "ospfInstance",
4901 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4904 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
4906 ifp
= if_lookup_by_name(argv
[arg_base
]->arg
, ospf
->vrf_id
);
4909 json_object_boolean_true_add(json
, "noSuchIface");
4911 vty_out(vty
, "No such interface.\n");
4915 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
4916 struct ospf_interface
*oi
= rn
->info
;
4921 show_ip_ospf_neighbor_sub(vty
, oi
, json
, use_json
);
4925 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4926 json
, JSON_C_TO_STRING_PRETTY
));
4927 json_object_free(json
);
4934 DEFUN (show_ip_ospf_neighbor_int
,
4935 show_ip_ospf_neighbor_int_cmd
,
4936 "show ip ospf [vrf <NAME>] neighbor IFNAME [json]",
4939 "OSPF information\n"
4948 bool uj
= use_json(argc
, argv
);
4949 int ret
= CMD_SUCCESS
;
4950 struct interface
*ifp
= NULL
;
4951 char *vrf_name
= NULL
;
4952 vrf_id_t vrf_id
= VRF_DEFAULT
;
4953 struct vrf
*vrf
= NULL
;
4955 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
4956 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
4957 if (vrf_name
&& strmatch(vrf_name
, VRF_DEFAULT_NAME
))
4960 vrf
= vrf_lookup_by_name(vrf_name
);
4962 vrf_id
= vrf
->vrf_id
;
4964 ospf
= ospf_lookup_by_vrf_id(vrf_id
);
4966 if (!ospf
|| !ospf
->oi_running
)
4970 show_ip_ospf_neighbour_header(vty
);
4972 argv_find(argv
, argc
, "IFNAME", &idx_ifname
);
4974 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf_id
);
4978 ret
= show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
,
4983 DEFUN (show_ip_ospf_instance_neighbor_int
,
4984 show_ip_ospf_instance_neighbor_int_cmd
,
4985 "show ip ospf (1-65535) neighbor IFNAME [json]",
4988 "OSPF information\n"
4997 unsigned short instance
= 0;
4998 bool uj
= use_json(argc
, argv
);
5001 show_ip_ospf_neighbour_header(vty
);
5003 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5004 if (instance
!= ospf_instance
)
5005 return CMD_NOT_MY_INSTANCE
;
5007 ospf
= ospf_lookup_instance(instance
);
5008 if (!ospf
|| !ospf
->oi_running
)
5012 show_ip_ospf_neighbour_header(vty
);
5014 return show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
, argv
, uj
,
5018 static void show_ip_ospf_nbr_nbma_detail_sub(struct vty
*vty
,
5019 struct ospf_interface
*oi
,
5020 struct ospf_nbr_nbma
*nbr_nbma
,
5021 bool use_json
, json_object
*json
)
5023 char timebuf
[OSPF_TIME_DUMP_SIZE
];
5024 char buf
[PREFIX_STRLEN
];
5025 json_object
*json_sub
= NULL
;
5028 json_sub
= json_object_new_object();
5029 else /* Show neighbor ID. */
5030 vty_out(vty
, " Neighbor %s,", "-");
5032 /* Show interface address. */
5034 json_object_string_add(json_sub
, "ifaceAddress",
5035 inet_ntop(AF_INET
, &nbr_nbma
->addr
,
5038 vty_out(vty
, " interface address %pI4\n",
5043 json_object_string_add(json_sub
, "areaId",
5044 ospf_area_desc_string(oi
->area
));
5045 json_object_string_add(json_sub
, "iface", IF_NAME(oi
));
5047 vty_out(vty
, " In the area %s via interface %s\n",
5048 ospf_area_desc_string(oi
->area
), IF_NAME(oi
));
5050 /* Show neighbor priority and state. */
5052 json_object_int_add(json_sub
, "nbrPriority",
5053 nbr_nbma
->priority
);
5054 json_object_string_add(json_sub
, "nbrState", "down");
5056 vty_out(vty
, " Neighbor priority is %d, State is %s,",
5057 nbr_nbma
->priority
, "Down");
5059 /* Show state changes. */
5061 json_object_int_add(json_sub
, "stateChangeCounter",
5062 nbr_nbma
->state_change
);
5064 vty_out(vty
, " %d state changes\n", nbr_nbma
->state_change
);
5066 /* Show PollInterval */
5068 json_object_int_add(json_sub
, "pollInterval", nbr_nbma
->v_poll
);
5070 vty_out(vty
, " Poll interval %d\n", nbr_nbma
->v_poll
);
5072 /* Show poll-interval timer. */
5073 if (nbr_nbma
->t_poll
) {
5076 time_store
= monotime_until(&nbr_nbma
->t_poll
->u
.sands
,
5078 json_object_int_add(json_sub
,
5079 "pollIntervalTimerDueMsec",
5082 vty_out(vty
, " Poll timer due in %s\n",
5083 ospf_timer_dump(nbr_nbma
->t_poll
, timebuf
,
5087 /* Show poll-interval timer thread. */
5089 if (nbr_nbma
->t_poll
!= NULL
)
5090 json_object_string_add(json_sub
,
5091 "pollIntervalTimerThread", "on");
5093 vty_out(vty
, " Thread Poll Timer %s\n",
5094 nbr_nbma
->t_poll
!= NULL
? "on" : "off");
5097 json_object_object_add(json
, "noNbrId", json_sub
);
5100 static void show_ip_ospf_neighbor_detail_sub(struct vty
*vty
,
5101 struct ospf_interface
*oi
,
5102 struct ospf_neighbor
*nbr
,
5103 struct ospf_neighbor
*prev_nbr
,
5104 json_object
*json
, bool use_json
)
5106 char timebuf
[OSPF_TIME_DUMP_SIZE
];
5107 json_object
*json_neigh
= NULL
, *json_neigh_array
= NULL
;
5108 char neigh_str
[INET_ADDRSTRLEN
] = {0};
5109 char buf
[PREFIX_STRLEN
];
5113 !IPV4_ADDR_SAME(&prev_nbr
->src
, &nbr
->src
)) {
5114 json_neigh_array
= NULL
;
5117 if (nbr
->state
== NSM_Attempt
5118 && nbr
->router_id
.s_addr
== INADDR_ANY
)
5119 strlcpy(neigh_str
, "noNbrId", sizeof(neigh_str
));
5121 inet_ntop(AF_INET
, &nbr
->router_id
,
5122 neigh_str
, sizeof(neigh_str
));
5124 json_object_object_get_ex(json
, neigh_str
, &json_neigh_array
);
5126 if (!json_neigh_array
) {
5127 json_neigh_array
= json_object_new_array();
5128 json_object_object_add(json
, neigh_str
,
5132 json_neigh
= json_object_new_object();
5135 /* Show neighbor ID. */
5136 if (nbr
->state
== NSM_Attempt
5137 && nbr
->router_id
.s_addr
== INADDR_ANY
)
5138 vty_out(vty
, " Neighbor %s,", "-");
5140 vty_out(vty
, " Neighbor %pI4,",
5144 /* Show interface address. */
5146 json_object_string_add(json_neigh
, "ifaceAddress",
5148 &nbr
->address
.u
.prefix4
,
5151 vty_out(vty
, " interface address %pI4\n",
5152 &nbr
->address
.u
.prefix4
);
5156 json_object_string_add(json_neigh
, "areaId",
5157 ospf_area_desc_string(oi
->area
));
5158 json_object_string_add(json_neigh
, "ifaceName", oi
->ifp
->name
);
5160 vty_out(vty
, " In the area %s via interface %s\n",
5161 ospf_area_desc_string(oi
->area
), oi
->ifp
->name
);
5163 /* Show neighbor priority and state. */
5165 json_object_int_add(json_neigh
, "nbrPriority", nbr
->priority
);
5166 json_object_string_add(
5167 json_neigh
, "nbrState",
5168 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
5170 vty_out(vty
, " Neighbor priority is %d, State is %s,",
5172 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
5174 /* Show state changes. */
5176 json_object_int_add(json_neigh
, "stateChangeCounter",
5179 vty_out(vty
, " %d state changes\n", nbr
->state_change
);
5181 if (nbr
->ts_last_progress
.tv_sec
|| nbr
->ts_last_progress
.tv_usec
) {
5186 monotime_since(&nbr
->ts_last_progress
, &res
) / 1000LL;
5188 json_object_int_add(json_neigh
, "lastPrgrsvChangeMsec",
5192 " Most recent state change statistics:\n");
5193 vty_out(vty
, " Progressive change %s ago\n",
5194 ospf_timeval_dump(&res
, timebuf
,
5199 if (nbr
->ts_last_regress
.tv_sec
|| nbr
->ts_last_regress
.tv_usec
) {
5204 monotime_since(&nbr
->ts_last_regress
, &res
) / 1000LL;
5206 json_object_int_add(json_neigh
,
5207 "lastRegressiveChangeMsec",
5209 if (nbr
->last_regress_str
)
5210 json_object_string_add(
5212 "lastRegressiveChangeReason",
5213 nbr
->last_regress_str
);
5216 " Regressive change %s ago, due to %s\n",
5217 ospf_timeval_dump(&res
, timebuf
,
5219 (nbr
->last_regress_str
? nbr
->last_regress_str
5224 /* Show Designated Rotuer ID. */
5226 json_object_string_add(json_neigh
, "routerDesignatedId",
5227 inet_ntop(AF_INET
, &nbr
->d_router
,
5230 vty_out(vty
, " DR is %pI4,", &nbr
->d_router
);
5232 /* Show Backup Designated Rotuer ID. */
5234 json_object_string_add(json_neigh
, "routerDesignatedBackupId",
5235 inet_ntop(AF_INET
, &nbr
->bd_router
,
5238 vty_out(vty
, " BDR is %pI4\n", &nbr
->bd_router
);
5242 json_object_int_add(json_neigh
, "optionsCounter", nbr
->options
);
5243 json_object_string_add(json_neigh
, "optionsList",
5244 ospf_options_dump(nbr
->options
));
5246 vty_out(vty
, " Options %d %s\n", nbr
->options
,
5247 ospf_options_dump(nbr
->options
));
5249 /* Show Router Dead interval timer. */
5251 if (nbr
->t_inactivity
) {
5253 time_store
= monotime_until(&nbr
->t_inactivity
->u
.sands
,
5256 json_object_int_add(json_neigh
,
5257 "routerDeadIntervalTimerDueMsec",
5260 json_object_int_add(
5262 "routerDeadIntervalTimerDueMsec", -1);
5264 vty_out(vty
, " Dead timer due in %s\n",
5265 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
5268 /* Show Database Summary list. */
5270 json_object_int_add(json_neigh
, "databaseSummaryListCounter",
5271 ospf_db_summary_count(nbr
));
5273 vty_out(vty
, " Database Summary List %d\n",
5274 ospf_db_summary_count(nbr
));
5276 /* Show Link State Request list. */
5278 json_object_int_add(json_neigh
, "linkStateRequestListCounter",
5279 ospf_ls_request_count(nbr
));
5281 vty_out(vty
, " Link State Request List %ld\n",
5282 ospf_ls_request_count(nbr
));
5284 /* Show Link State Retransmission list. */
5286 json_object_int_add(json_neigh
,
5287 "linkStateRetransmissionListCounter",
5288 ospf_ls_retransmit_count(nbr
));
5290 vty_out(vty
, " Link State Retransmission List %ld\n",
5291 ospf_ls_retransmit_count(nbr
));
5293 /* Show inactivity timer thread. */
5295 if (nbr
->t_inactivity
!= NULL
)
5296 json_object_string_add(json_neigh
,
5297 "threadInactivityTimer", "on");
5299 vty_out(vty
, " Thread Inactivity Timer %s\n",
5300 nbr
->t_inactivity
!= NULL
? "on" : "off");
5302 /* Show Database Description retransmission thread. */
5304 if (nbr
->t_db_desc
!= NULL
)
5305 json_object_string_add(
5307 "threadDatabaseDescriptionRetransmission",
5311 " Thread Database Description Retransmision %s\n",
5312 nbr
->t_db_desc
!= NULL
? "on" : "off");
5314 /* Show Link State Request Retransmission thread. */
5316 if (nbr
->t_ls_req
!= NULL
)
5317 json_object_string_add(
5319 "threadLinkStateRequestRetransmission", "on");
5322 " Thread Link State Request Retransmission %s\n",
5323 nbr
->t_ls_req
!= NULL
? "on" : "off");
5325 /* Show Link State Update Retransmission thread. */
5327 if (nbr
->t_ls_upd
!= NULL
)
5328 json_object_string_add(
5330 "threadLinkStateUpdateRetransmission",
5334 " Thread Link State Update Retransmission %s\n\n",
5335 nbr
->t_ls_upd
!= NULL
? "on" : "off");
5338 vty_out(vty
, " Graceful restart Helper info:\n");
5340 if (OSPF_GR_IS_ACTIVE_HELPER(nbr
)) {
5342 " Graceful Restart HELPER Status : Inprogress.\n");
5345 " Graceful Restart grace period time: %d (seconds).\n",
5346 nbr
->gr_helper_info
.recvd_grace_period
);
5347 vty_out(vty
, " Graceful Restart reason: %s.\n",
5348 ospf_restart_reason2str(
5349 nbr
->gr_helper_info
.gr_restart_reason
));
5352 " Graceful Restart HELPER Status : None\n");
5355 if (nbr
->gr_helper_info
.rejected_reason
5356 != OSPF_HELPER_REJECTED_NONE
)
5357 vty_out(vty
, " Helper rejected reason: %s.\n",
5358 ospf_rejected_reason2str(
5359 nbr
->gr_helper_info
.rejected_reason
));
5361 if (nbr
->gr_helper_info
.helper_exit_reason
5362 != OSPF_GR_HELPER_EXIT_NONE
)
5363 vty_out(vty
, " Last helper exit reason: %s.\n\n",
5364 ospf_exit_reason2str(
5365 nbr
->gr_helper_info
.helper_exit_reason
));
5369 json_object_string_add(json_neigh
, "grHelperStatus",
5370 OSPF_GR_IS_ACTIVE_HELPER(nbr
) ?
5373 if (OSPF_GR_IS_ACTIVE_HELPER(nbr
)) {
5374 json_object_int_add(
5375 json_neigh
, "graceInterval",
5376 nbr
->gr_helper_info
.recvd_grace_period
);
5377 json_object_string_add(
5378 json_neigh
, "grRestartReason",
5379 ospf_restart_reason2str(
5380 nbr
->gr_helper_info
.gr_restart_reason
));
5383 if (nbr
->gr_helper_info
.rejected_reason
5384 != OSPF_HELPER_REJECTED_NONE
)
5385 json_object_string_add(
5386 json_neigh
, "helperRejectReason",
5387 ospf_rejected_reason2str(
5388 nbr
->gr_helper_info
.rejected_reason
));
5390 if (nbr
->gr_helper_info
.helper_exit_reason
5391 != OSPF_GR_HELPER_EXIT_NONE
)
5392 json_object_string_add(
5393 json_neigh
, "helperExitReason",
5394 ospf_exit_reason2str(
5396 .helper_exit_reason
));
5399 bfd_sess_show(vty
, json_neigh
, nbr
->bfd_session
);
5402 json_object_array_add(json_neigh_array
, json_neigh
);
5406 static int show_ip_ospf_neighbor_id_common(struct vty
*vty
, struct ospf
*ospf
,
5407 struct in_addr
*router_id
,
5408 bool use_json
, uint8_t use_vrf
)
5410 struct listnode
*node
;
5411 struct ospf_neighbor
*nbr
;
5412 struct ospf_interface
*oi
;
5413 json_object
*json
= NULL
;
5416 json
= json_object_new_object();
5418 if (ospf
->instance
) {
5420 json_object_int_add(json
, "ospfInstance",
5423 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5426 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
5428 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5429 if ((nbr
= ospf_nbr_lookup_by_routerid(oi
->nbrs
, router_id
))) {
5430 show_ip_ospf_neighbor_detail_sub(vty
, oi
, nbr
, NULL
,
5436 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5437 json
, JSON_C_TO_STRING_PRETTY
));
5438 json_object_free(json
);
5445 DEFPY (show_ip_ospf_neighbor_id
,
5446 show_ip_ospf_neighbor_id_cmd
,
5447 "show ip ospf neighbor A.B.C.D$router_id [json$json]",
5450 "OSPF information\n"
5456 struct listnode
*node
;
5457 int ret
= CMD_SUCCESS
;
5459 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5460 if (!ospf
->oi_running
)
5462 ret
= show_ip_ospf_neighbor_id_common(vty
, ospf
, &router_id
,
5469 DEFPY (show_ip_ospf_instance_neighbor_id
,
5470 show_ip_ospf_instance_neighbor_id_cmd
,
5471 "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [json$json]",
5474 "OSPF information\n"
5482 if (instance
!= ospf_instance
)
5483 return CMD_NOT_MY_INSTANCE
;
5485 ospf
= ospf_lookup_instance(instance
);
5486 if (!ospf
|| !ospf
->oi_running
)
5489 return show_ip_ospf_neighbor_id_common(vty
, ospf
, &router_id
, !!json
,
5493 static int show_ip_ospf_neighbor_detail_common(struct vty
*vty
,
5495 json_object
*json
, bool use_json
,
5498 struct ospf_interface
*oi
;
5499 struct listnode
*node
;
5500 json_object
*json_vrf
= NULL
;
5501 json_object
*json_nbr_sub
= NULL
;
5505 json_vrf
= json_object_new_object();
5509 json_nbr_sub
= json_object_new_object();
5512 if (ospf
->instance
) {
5514 json_object_int_add(json
, "ospfInstance",
5517 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5520 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5522 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5523 struct route_node
*rn
;
5524 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
5526 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5527 if ((nbr
= rn
->info
)) {
5528 if (nbr
!= oi
->nbr_self
) {
5529 if (nbr
->state
!= NSM_Down
) {
5530 show_ip_ospf_neighbor_detail_sub(
5531 vty
, oi
, nbr
, prev_nbr
,
5532 json_nbr_sub
, use_json
);
5541 json_object_object_add(json_vrf
, "neighbors",
5544 if (ospf
->vrf_id
== VRF_DEFAULT
)
5545 json_object_object_add(json
, "default",
5548 json_object_object_add(json
, ospf
->name
,
5557 DEFUN (show_ip_ospf_neighbor_detail
,
5558 show_ip_ospf_neighbor_detail_cmd
,
5559 "show ip ospf [vrf <NAME|all>] neighbor detail [json]",
5562 "OSPF information\n"
5566 "detail of all neighbors\n"
5570 bool uj
= use_json(argc
, argv
);
5571 struct listnode
*node
= NULL
;
5572 char *vrf_name
= NULL
;
5573 bool all_vrf
= false;
5574 int ret
= CMD_SUCCESS
;
5577 uint8_t use_vrf
= 0;
5578 json_object
*json
= NULL
;
5580 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5583 json
= json_object_new_object();
5585 /* vrf input is provided could be all or specific vrf*/
5589 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5590 if (!ospf
->oi_running
)
5592 ret
= show_ip_ospf_neighbor_detail_common(
5593 vty
, ospf
, json
, uj
, use_vrf
);
5596 vty_out(vty
, "%s\n",
5597 json_object_to_json_string_ext(
5598 json
, JSON_C_TO_STRING_PRETTY
));
5599 json_object_free(json
);
5604 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5605 if (ospf
== NULL
|| !ospf
->oi_running
) {
5607 json_object_free(json
);
5611 /* Display default ospf (instance 0) info */
5612 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5613 if (ospf
== NULL
|| !ospf
->oi_running
) {
5615 json_object_free(json
);
5621 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
,
5624 vty_out(vty
, "%s\n",
5625 json_object_to_json_string_ext(
5626 json
, JSON_C_TO_STRING_PRETTY
));
5631 json_object_free(json
);
5636 DEFUN (show_ip_ospf_instance_neighbor_detail
,
5637 show_ip_ospf_instance_neighbor_detail_cmd
,
5638 "show ip ospf (1-65535) neighbor detail [json]",
5641 "OSPF information\n"
5644 "detail of all neighbors\n"
5649 unsigned short instance
= 0;
5650 bool uj
= use_json(argc
, argv
);
5651 json_object
*json
= NULL
;
5652 int ret
= CMD_SUCCESS
;
5654 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5655 if (instance
!= ospf_instance
)
5656 return CMD_NOT_MY_INSTANCE
;
5658 ospf
= ospf_lookup_instance(instance
);
5659 if (!ospf
|| !ospf
->oi_running
)
5663 json
= json_object_new_object();
5665 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
, 0);
5668 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5669 json
, JSON_C_TO_STRING_PRETTY
));
5670 json_object_free(json
);
5676 static int show_ip_ospf_neighbor_detail_all_common(struct vty
*vty
,
5682 struct listnode
*node
;
5683 struct ospf_interface
*oi
;
5684 json_object
*json_vrf
= NULL
;
5688 json_vrf
= json_object_new_object();
5693 if (ospf
->instance
) {
5695 json_object_int_add(json
, "ospfInstance",
5698 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5701 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5703 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5704 struct route_node
*rn
;
5705 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
5706 struct ospf_nbr_nbma
*nbr_nbma
;
5708 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5709 if ((nbr
= rn
->info
)) {
5710 if (nbr
!= oi
->nbr_self
)
5711 if (nbr
->state
!= NSM_Down
)
5712 show_ip_ospf_neighbor_detail_sub(
5715 json_vrf
, use_json
);
5720 if (oi
->type
== OSPF_IFTYPE_NBMA
) {
5721 struct listnode
*nd
;
5723 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nd
, nbr_nbma
)) {
5724 if (nbr_nbma
->nbr
== NULL
5725 || nbr_nbma
->nbr
->state
== NSM_Down
)
5726 show_ip_ospf_nbr_nbma_detail_sub(
5727 vty
, oi
, nbr_nbma
, use_json
,
5735 if (ospf
->vrf_id
== VRF_DEFAULT
)
5736 json_object_object_add(json
, "default",
5739 json_object_object_add(json
, ospf
->name
,
5749 DEFUN (show_ip_ospf_neighbor_detail_all
,
5750 show_ip_ospf_neighbor_detail_all_cmd
,
5751 "show ip ospf [vrf <NAME|all>] neighbor detail all [json]",
5754 "OSPF information\n"
5758 "detail of all neighbors\n"
5759 "include down status neighbor\n"
5763 bool uj
= use_json(argc
, argv
);
5764 struct listnode
*node
= NULL
;
5765 char *vrf_name
= NULL
;
5766 bool all_vrf
= false;
5767 int ret
= CMD_SUCCESS
;
5770 uint8_t use_vrf
= 0;
5771 json_object
*json
= NULL
;
5773 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5776 json
= json_object_new_object();
5778 /* vrf input is provided could be all or specific vrf*/
5782 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5783 if (!ospf
->oi_running
)
5785 ret
= show_ip_ospf_neighbor_detail_all_common(
5786 vty
, ospf
, json
, uj
, use_vrf
);
5790 vty_out(vty
, "%s\n",
5791 json_object_to_json_string_ext(
5792 json
, JSON_C_TO_STRING_PRETTY
));
5793 json_object_free(json
);
5798 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5799 if (ospf
== NULL
|| !ospf
->oi_running
) {
5801 json_object_free(json
);
5805 /* Display default ospf (instance 0) info */
5806 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5807 if (ospf
== NULL
|| !ospf
->oi_running
) {
5809 json_object_free(json
);
5815 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
,
5818 vty_out(vty
, "%s\n",
5819 json_object_to_json_string_ext(
5820 json
, JSON_C_TO_STRING_PRETTY
));
5825 json_object_free(json
);
5830 DEFUN (show_ip_ospf_instance_neighbor_detail_all
,
5831 show_ip_ospf_instance_neighbor_detail_all_cmd
,
5832 "show ip ospf (1-65535) neighbor detail all [json]",
5835 "OSPF information\n"
5838 "detail of all neighbors\n"
5839 "include down status neighbor\n"
5844 unsigned short instance
= 0;
5845 bool uj
= use_json(argc
, argv
);
5846 json_object
*json
= NULL
;
5847 int ret
= CMD_SUCCESS
;
5849 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5850 if (instance
!= ospf_instance
)
5851 return CMD_NOT_MY_INSTANCE
;
5853 ospf
= ospf_lookup_instance(instance
);
5854 if (!ospf
|| !ospf
->oi_running
)
5858 json
= json_object_new_object();
5860 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
, uj
, 0);
5863 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5864 json
, JSON_C_TO_STRING_PRETTY
));
5865 json_object_free(json
);
5871 static int show_ip_ospf_neighbor_int_detail_common(struct vty
*vty
,
5874 struct cmd_token
**argv
,
5877 struct ospf_interface
*oi
;
5878 struct interface
*ifp
;
5879 struct route_node
*rn
, *nrn
;
5880 struct ospf_neighbor
*nbr
;
5881 json_object
*json
= NULL
;
5884 json
= json_object_new_object();
5886 if (ospf
->instance
) {
5888 json_object_int_add(json
, "ospfInstance",
5891 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5894 ifp
= if_lookup_by_name(argv
[arg_base
]->arg
, ospf
->vrf_id
);
5897 vty_out(vty
, "No such interface.\n");
5899 vty_out(vty
, "{}\n");
5900 json_object_free(json
);
5905 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
5906 if ((oi
= rn
->info
)) {
5907 for (nrn
= route_top(oi
->nbrs
); nrn
;
5908 nrn
= route_next(nrn
)) {
5909 if ((nbr
= nrn
->info
)) {
5910 if (nbr
!= oi
->nbr_self
) {
5911 if (nbr
->state
!= NSM_Down
)
5912 show_ip_ospf_neighbor_detail_sub(
5923 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5924 json
, JSON_C_TO_STRING_PRETTY
));
5925 json_object_free(json
);
5932 DEFUN (show_ip_ospf_neighbor_int_detail
,
5933 show_ip_ospf_neighbor_int_detail_cmd
,
5934 "show ip ospf neighbor IFNAME detail [json]",
5937 "OSPF information\n"
5940 "detail of all neighbors\n"
5944 bool uj
= use_json(argc
, argv
);
5945 struct listnode
*node
= NULL
;
5946 int ret
= CMD_SUCCESS
;
5947 bool ospf_output
= false;
5949 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5950 if (!ospf
->oi_running
)
5953 ret
= show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, 4,
5958 vty_out(vty
, "%% OSPF instance not found\n");
5963 DEFUN (show_ip_ospf_instance_neighbor_int_detail
,
5964 show_ip_ospf_instance_neighbor_int_detail_cmd
,
5965 "show ip ospf (1-65535) neighbor IFNAME detail [json]",
5968 "OSPF information\n"
5972 "detail of all neighbors\n"
5978 unsigned short instance
= 0;
5979 bool uj
= use_json(argc
, argv
);
5981 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5982 if (instance
!= ospf_instance
)
5983 return CMD_NOT_MY_INSTANCE
;
5985 ospf
= ospf_lookup_instance(instance
);
5986 if (!ospf
|| !ospf
->oi_running
)
5989 return show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, idx_ifname
,
5993 /* Show functions */
5994 static int show_lsa_summary(struct vty
*vty
, struct ospf_lsa
*lsa
, int self
,
5995 json_object
*json_lsa
)
5997 struct router_lsa
*rl
;
5998 struct summary_lsa
*sl
;
5999 struct as_external_lsa
*asel
;
6000 struct prefix_ipv4 p
;
6001 char buf
[PREFIX2STR_BUFFER
];
6004 /* If self option is set, check LSA self flag. */
6005 if (self
== 0 || IS_LSA_SELF(lsa
)) {
6008 /* LSA common part show. */
6009 vty_out(vty
, "%-15pI4",
6011 vty_out(vty
, "%-15pI4 %4d 0x%08lx 0x%04x",
6012 &lsa
->data
->adv_router
, LS_AGE(lsa
),
6013 (unsigned long)ntohl(
6014 lsa
->data
->ls_seqnum
),
6015 ntohs(lsa
->data
->checksum
));
6020 snprintf(seqnum
, sizeof(seqnum
), "%x",
6021 ntohl(lsa
->data
->ls_seqnum
));
6022 snprintf(checksum
, sizeof(checksum
), "%x",
6023 ntohs(lsa
->data
->checksum
));
6024 json_object_string_add(
6026 inet_ntop(AF_INET
, &lsa
->data
->id
,
6028 json_object_string_add(
6029 json_lsa
, "advertisedRouter",
6031 &lsa
->data
->adv_router
,
6033 json_object_int_add(json_lsa
, "lsaAge",
6035 json_object_string_add(
6036 json_lsa
, "sequenceNumber", seqnum
);
6037 json_object_string_add(json_lsa
, "checksum",
6041 /* LSA specific part show. */
6042 switch (lsa
->data
->type
) {
6043 case OSPF_ROUTER_LSA
:
6044 rl
= (struct router_lsa
*)lsa
->data
;
6047 vty_out(vty
, " %-d", ntohs(rl
->links
));
6049 json_object_int_add(json_lsa
,
6053 case OSPF_SUMMARY_LSA
:
6054 sl
= (struct summary_lsa
*)lsa
->data
;
6057 p
.prefix
= sl
->header
.id
;
6058 p
.prefixlen
= ip_masklen(sl
->mask
);
6059 apply_mask_ipv4(&p
);
6062 vty_out(vty
, " %pFX", &p
);
6064 prefix2str(&p
, buf
, sizeof(buf
));
6065 json_object_string_add(json_lsa
,
6070 case OSPF_AS_EXTERNAL_LSA
:
6071 case OSPF_AS_NSSA_LSA
:
6072 asel
= (struct as_external_lsa
*)lsa
->data
;
6075 p
.prefix
= asel
->header
.id
;
6076 p
.prefixlen
= ip_masklen(asel
->mask
);
6077 apply_mask_ipv4(&p
);
6080 vty_out(vty
, " %s %pFX [0x%lx]",
6086 (unsigned long)ntohl(
6087 asel
->e
[0].route_tag
));
6089 prefix2str(&p
, buf
, sizeof(buf
));
6090 json_object_string_add(
6091 json_lsa
, "metricType",
6096 json_object_string_add(json_lsa
,
6098 json_object_int_add(
6100 (unsigned long)ntohl(
6101 asel
->e
[0].route_tag
));
6104 case OSPF_NETWORK_LSA
:
6105 case OSPF_ASBR_SUMMARY_LSA
:
6106 case OSPF_OPAQUE_LINK_LSA
:
6107 case OSPF_OPAQUE_AREA_LSA
:
6108 case OSPF_OPAQUE_AS_LSA
:
6120 static const char *const show_database_desc
[] = {
6122 "Router Link States",
6124 "Summary Link States",
6125 "ASBR-Summary Link States",
6126 "AS External Link States",
6127 "Group Membership LSA",
6128 "NSSA-external Link States",
6130 "Link-Local Opaque-LSA",
6131 "Area-Local Opaque-LSA",
6132 "AS-external Opaque-LSA",
6135 static const char * const show_database_desc_json
[] = {
6138 "networkLinkStates",
6139 "summaryLinkStates",
6140 "asbrSummaryLinkStates",
6141 "asExternalLinkStates",
6142 "groupMembershipLsa",
6143 "nssaExternalLinkStates",
6145 "linkLocalOpaqueLsa",
6146 "areaLocalOpaqueLsa",
6147 "asExternalOpaqueLsa",
6150 static const char *const show_database_header
[] = {
6152 "Link ID ADV Router Age Seq# CkSum Link count",
6153 "Link ID ADV Router Age Seq# CkSum",
6154 "Link ID ADV Router Age Seq# CkSum Route",
6155 "Link ID ADV Router Age Seq# CkSum",
6156 "Link ID ADV Router Age Seq# CkSum Route",
6157 " --- header for Group Member ----",
6158 "Link ID ADV Router Age Seq# CkSum Route",
6160 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6161 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6162 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6165 static void show_ip_ospf_database_header(struct vty
*vty
, struct ospf_lsa
*lsa
,
6168 char buf
[PREFIX_STRLEN
];
6169 struct router_lsa
*rlsa
= (struct router_lsa
*)lsa
->data
;
6172 vty_out(vty
, " LS age: %d\n", LS_AGE(lsa
));
6173 vty_out(vty
, " Options: 0x%-2x : %s\n", lsa
->data
->options
,
6174 ospf_options_dump(lsa
->data
->options
));
6175 vty_out(vty
, " LS Flags: 0x%-2x %s\n", lsa
->flags
,
6176 ((lsa
->flags
& OSPF_LSA_LOCAL_XLT
)
6177 ? "(Translated from Type-7)"
6180 if (lsa
->data
->type
== OSPF_ROUTER_LSA
) {
6181 vty_out(vty
, " Flags: 0x%x", rlsa
->flags
);
6184 vty_out(vty
, " :%s%s%s%s",
6185 IS_ROUTER_LSA_BORDER(rlsa
) ? " ABR"
6187 IS_ROUTER_LSA_EXTERNAL(rlsa
) ? " ASBR"
6189 IS_ROUTER_LSA_VIRTUAL(rlsa
)
6192 IS_ROUTER_LSA_SHORTCUT(rlsa
)
6198 vty_out(vty
, " LS Type: %s\n",
6199 lookup_msg(ospf_lsa_type_msg
, lsa
->data
->type
, NULL
));
6200 vty_out(vty
, " Link State ID: %pI4 %s\n",
6202 lookup_msg(ospf_link_state_id_type_msg
, lsa
->data
->type
,
6204 vty_out(vty
, " Advertising Router: %pI4\n",
6205 &lsa
->data
->adv_router
);
6206 vty_out(vty
, " LS Seq Number: %08lx\n",
6207 (unsigned long)ntohl(lsa
->data
->ls_seqnum
));
6208 vty_out(vty
, " Checksum: 0x%04x\n",
6209 ntohs(lsa
->data
->checksum
));
6210 vty_out(vty
, " Length: %d\n\n", ntohs(lsa
->data
->length
));
6215 snprintf(seqnum
, 10, "%x", ntohl(lsa
->data
->ls_seqnum
));
6216 snprintf(checksum
, 10, "%x", ntohs(lsa
->data
->checksum
));
6218 json_object_int_add(json
, "lsaAge", LS_AGE(lsa
));
6219 json_object_string_add(json
, "options",
6220 ospf_options_dump(lsa
->data
->options
));
6221 json_object_int_add(json
, "lsaFlags", lsa
->flags
);
6223 if (lsa
->flags
& OSPF_LSA_LOCAL_XLT
)
6224 json_object_boolean_true_add(json
,
6225 "translatedFromType7");
6227 if (lsa
->data
->type
== OSPF_ROUTER_LSA
) {
6228 json_object_int_add(json
, "flags", rlsa
->flags
);
6231 if (IS_ROUTER_LSA_BORDER(rlsa
))
6232 json_object_boolean_true_add(json
,
6234 if (IS_ROUTER_LSA_EXTERNAL(rlsa
))
6235 json_object_boolean_true_add(json
,
6237 if (IS_ROUTER_LSA_VIRTUAL(rlsa
))
6238 json_object_boolean_true_add(
6239 json
, "vlEndpoint");
6240 if (IS_ROUTER_LSA_SHORTCUT(rlsa
))
6241 json_object_boolean_true_add(
6246 json_object_string_add(
6248 lookup_msg(ospf_lsa_type_msg
, lsa
->data
->type
, NULL
));
6249 json_object_string_add(json
, "linkStateId",
6250 inet_ntop(AF_INET
, &lsa
->data
->id
,
6252 json_object_string_add(json
, "advertisingRouter",
6254 &lsa
->data
->adv_router
,
6256 json_object_string_add(json
, "lsaSeqNumber", seqnum
);
6257 json_object_string_add(json
, "checksum", checksum
);
6258 json_object_int_add(json
, "length", ntohs(lsa
->data
->length
));
6262 static const char *const link_type_desc
[] = {
6264 "another Router (point-to-point)",
6265 "a Transit Network",
6270 static const char *const link_id_desc
[] = {
6271 "(null)", "Neighboring Router ID", "Designated Router address",
6272 "Net", "Neighboring Router ID",
6275 static const char *const link_data_desc
[] = {
6276 "(null)", "Router Interface address", "Router Interface address",
6277 "Network Mask", "Router Interface address",
6280 static const char *const link_id_desc_json
[] = {
6281 "null", "neighborRouterId", "designatedRouterAddress",
6282 "networkAddress", "neighborRouterId",
6285 static const char *const link_data_desc_json
[] = {
6286 "null", "routerInterfaceAddress", "routerInterfaceAddress",
6287 "networkMask", "routerInterfaceAddress",
6290 /* Show router-LSA each Link information. */
6291 static void show_ip_ospf_database_router_links(struct vty
*vty
,
6292 struct router_lsa
*rl
,
6297 json_object
*json_links
= NULL
;
6298 json_object
*json_link
= NULL
;
6300 char buf
[PREFIX_STRLEN
];
6303 json_links
= json_object_new_object();
6305 len
= ntohs(rl
->header
.length
) - 4;
6306 for (i
= 0; i
< ntohs(rl
->links
) && len
> 0; len
-= 12, i
++) {
6307 type
= rl
->link
[i
].type
;
6312 snprintf(link
, sizeof(link
), "link%u", i
);
6313 json_link
= json_object_new_object();
6314 json_object_string_add(json_link
, "linkType",
6315 link_type_desc
[type
]);
6316 json_object_string_add(json_link
,
6317 link_id_desc_json
[type
],
6319 &rl
->link
[i
].link_id
,
6321 json_object_string_add(
6322 json_link
, link_data_desc_json
[type
],
6323 inet_ntop(AF_INET
, &rl
->link
[i
].link_data
,
6325 json_object_int_add(json_link
, "numOfTosMetrics",
6327 json_object_int_add(json_link
, "tos0Metric",
6328 ntohs(rl
->link
[i
].metric
));
6329 json_object_object_add(json_links
, link
, json_link
);
6331 vty_out(vty
, " Link connected to: %s\n",
6332 link_type_desc
[type
]);
6333 vty_out(vty
, " (Link ID) %s: %pI4\n",
6335 &rl
->link
[i
].link_id
);
6336 vty_out(vty
, " (Link Data) %s: %pI4\n",
6337 link_data_desc
[type
],
6338 &rl
->link
[i
].link_data
);
6339 vty_out(vty
, " Number of TOS metrics: 0\n");
6340 vty_out(vty
, " TOS 0 Metric: %d\n",
6341 ntohs(rl
->link
[i
].metric
));
6346 json_object_object_add(json
, "routerLinks", json_links
);
6349 /* Show router-LSA detail information. */
6350 static int show_router_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6354 struct router_lsa
*rl
= (struct router_lsa
*)lsa
->data
;
6356 show_ip_ospf_database_header(vty
, lsa
, json
);
6359 vty_out(vty
, " Number of Links: %d\n\n",
6362 json_object_int_add(json
, "numOfLinks",
6365 show_ip_ospf_database_router_links(vty
, rl
, json
);
6374 /* Show network-LSA detail information. */
6375 static int show_network_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6379 char buf
[PREFIX_STRLEN
];
6380 json_object
*json_attached_rt
= NULL
;
6381 json_object
*json_router
= NULL
;
6384 json_attached_rt
= json_object_new_object();
6387 struct network_lsa
*nl
= (struct network_lsa
*)lsa
->data
;
6388 struct in_addr
*addr
;
6390 show_ip_ospf_database_header(vty
, lsa
, json
);
6393 vty_out(vty
, " Network Mask: /%d\n",
6394 ip_masklen(nl
->mask
));
6396 json_object_int_add(json
, "networkMask",
6397 ip_masklen(nl
->mask
));
6399 length
= lsa
->size
- OSPF_LSA_HEADER_SIZE
- 4;
6400 addr
= &nl
->routers
[0];
6401 for (i
= 0; length
> 0 && addr
;
6402 length
-= 4, addr
= &nl
->routers
[++i
])
6404 vty_out(vty
, " Attached Router: %pI4\n",
6408 json_router
= json_object_new_object();
6409 json_object_string_add(
6410 json_router
, "attachedRouterId",
6411 inet_ntop(AF_INET
, addr
, buf
,
6413 json_object_object_add(json_attached_rt
,
6414 inet_ntop(AF_INET
, addr
,
6422 json_object_object_add(json
, "attchedRouters",
6428 /* Show summary-LSA detail information. */
6429 static int show_summary_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6433 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
6435 show_ip_ospf_database_header(vty
, lsa
, json
);
6438 vty_out(vty
, " Network Mask: /%d\n",
6439 ip_masklen(sl
->mask
));
6440 vty_out(vty
, " TOS: 0 Metric: %d\n",
6441 GET_METRIC(sl
->metric
));
6444 json_object_int_add(json
, "networkMask",
6445 ip_masklen(sl
->mask
));
6446 json_object_int_add(json
, "tos0Metric",
6447 GET_METRIC(sl
->metric
));
6454 /* Show summary-ASBR-LSA detail information. */
6455 static int show_summary_asbr_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6459 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
6461 show_ip_ospf_database_header(vty
, lsa
, json
);
6464 vty_out(vty
, " Network Mask: /%d\n",
6465 ip_masklen(sl
->mask
));
6466 vty_out(vty
, " TOS: 0 Metric: %d\n",
6467 GET_METRIC(sl
->metric
));
6470 json_object_int_add(json
, "networkMask",
6471 ip_masklen(sl
->mask
));
6472 json_object_int_add(json
, "tos0Metric",
6473 GET_METRIC(sl
->metric
));
6480 /* Show AS-external-LSA detail information. */
6481 static int show_as_external_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6484 char buf
[PREFIX_STRLEN
];
6488 struct as_external_lsa
*al
=
6489 (struct as_external_lsa
*)lsa
->data
;
6491 show_ip_ospf_database_header(vty
, lsa
, json
);
6494 vty_out(vty
, " Network Mask: /%d\n",
6495 ip_masklen(al
->mask
));
6496 vty_out(vty
, " Metric Type: %s\n",
6497 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6498 ? "2 (Larger than any link state path)"
6500 vty_out(vty
, " TOS: 0\n");
6501 vty_out(vty
, " Metric: %d\n",
6502 GET_METRIC(al
->e
[0].metric
));
6503 vty_out(vty
, " Forward Address: %pI4\n",
6504 &al
->e
[0].fwd_addr
);
6506 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
6507 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6509 json_object_int_add(json
, "networkMask",
6510 ip_masklen(al
->mask
));
6511 json_object_string_add(
6513 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6514 ? "E2 (Larger than any link state path)"
6516 json_object_int_add(json
, "tos", tos
);
6517 json_object_int_add(json
, "metric",
6518 GET_METRIC(al
->e
[0].metric
));
6519 json_object_string_add(json
, "forwardAddress",
6521 &(al
->e
[0].fwd_addr
),
6523 json_object_int_add(
6524 json
, "externalRouteTag",
6525 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6532 /* Show AS-NSSA-LSA detail information. */
6533 static int show_as_nssa_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6536 char buf
[PREFIX_STRLEN
];
6540 struct as_external_lsa
*al
=
6541 (struct as_external_lsa
*)lsa
->data
;
6543 show_ip_ospf_database_header(vty
, lsa
, json
);
6546 vty_out(vty
, " Network Mask: /%d\n",
6547 ip_masklen(al
->mask
));
6548 vty_out(vty
, " Metric Type: %s\n",
6549 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6550 ? "2 (Larger than any link state path)"
6552 vty_out(vty
, " TOS: 0\n");
6553 vty_out(vty
, " Metric: %d\n",
6554 GET_METRIC(al
->e
[0].metric
));
6555 vty_out(vty
, " NSSA: Forward Address: %pI4\n",
6556 &al
->e
[0].fwd_addr
);
6558 " External Route Tag: %" ROUTE_TAG_PRI
6560 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6562 json_object_int_add(json
, "networkMask",
6563 ip_masklen(al
->mask
));
6564 json_object_string_add(
6566 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6567 ? "E2 (Larger than any link state path)"
6569 json_object_int_add(json
, "tos", tos
);
6570 json_object_int_add(json
, "metric",
6571 GET_METRIC(al
->e
[0].metric
));
6572 json_object_string_add(json
, "nssaForwardAddress",
6576 json_object_int_add(
6577 json
, "externalRouteTag",
6578 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6585 static int show_func_dummy(struct vty
*vty
, struct ospf_lsa
*lsa
,
6591 static int show_opaque_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
,
6595 show_ip_ospf_database_header(vty
, lsa
, json
);
6596 show_opaque_info_detail(vty
, lsa
, json
);
6603 int (*show_function
[])(struct vty
*, struct ospf_lsa
*, json_object
*) = {
6605 show_router_lsa_detail
,
6606 show_network_lsa_detail
,
6607 show_summary_lsa_detail
,
6608 show_summary_asbr_lsa_detail
,
6609 show_as_external_lsa_detail
,
6611 show_as_nssa_lsa_detail
, /* almost same as external */
6613 show_opaque_lsa_detail
,
6614 show_opaque_lsa_detail
,
6615 show_opaque_lsa_detail
,
6618 static void show_lsa_prefix_set(struct vty
*vty
, struct prefix_ls
*lp
,
6619 struct in_addr
*id
, struct in_addr
*adv_router
)
6621 memset(lp
, 0, sizeof(struct prefix_ls
));
6625 else if (adv_router
== NULL
) {
6626 lp
->prefixlen
= IPV4_MAX_BITLEN
;
6631 lp
->adv_router
= *adv_router
;
6635 static void show_lsa_detail_proc(struct vty
*vty
, struct route_table
*rt
,
6636 struct in_addr
*id
, struct in_addr
*adv_router
,
6639 struct prefix_ls lp
;
6640 struct route_node
*rn
, *start
;
6641 struct ospf_lsa
*lsa
;
6642 json_object
*json_lsa
= NULL
;
6644 show_lsa_prefix_set(vty
, &lp
, id
, adv_router
);
6645 start
= route_node_get(rt
, (struct prefix
*)&lp
);
6647 route_lock_node(start
);
6648 for (rn
= start
; rn
; rn
= route_next_until(rn
, start
))
6649 if ((lsa
= rn
->info
)) {
6651 json_lsa
= json_object_new_object();
6652 json_object_array_add(json
, json_lsa
);
6655 if (show_function
[lsa
->data
->type
] != NULL
)
6656 show_function
[lsa
->data
->type
](
6657 vty
, lsa
, json_lsa
);
6659 route_unlock_node(start
);
6663 /* Show detail LSA information
6664 -- if id is NULL then show all LSAs. */
6665 static void show_lsa_detail(struct vty
*vty
, struct ospf
*ospf
, int type
,
6666 struct in_addr
*id
, struct in_addr
*adv_router
,
6669 struct listnode
*node
;
6670 struct ospf_area
*area
;
6671 char buf
[PREFIX_STRLEN
];
6672 json_object
*json_lsa_type
= NULL
;
6673 json_object
*json_areas
= NULL
;
6674 json_object
*json_lsa_array
= NULL
;
6677 json_lsa_type
= json_object_new_object();
6680 case OSPF_AS_EXTERNAL_LSA
:
6681 case OSPF_OPAQUE_AS_LSA
:
6683 vty_out(vty
, " %s \n\n",
6684 show_database_desc
[type
]);
6686 json_lsa_array
= json_object_new_array();
6688 show_lsa_detail_proc(vty
, AS_LSDB(ospf
, type
), id
, adv_router
,
6691 json_object_object_add(json
,
6692 show_database_desc_json
[type
],
6698 json_areas
= json_object_new_object();
6700 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6703 "\n %s (Area %s)\n\n",
6704 show_database_desc
[type
],
6705 ospf_area_desc_string(area
));
6707 json_lsa_array
= json_object_new_array();
6708 json_object_object_add(json_areas
,
6716 show_lsa_detail_proc(vty
, AREA_LSDB(area
, type
), id
,
6717 adv_router
, json_lsa_array
);
6721 json_object_object_add(json_lsa_type
, "areas",
6723 json_object_object_add(json
,
6724 show_database_desc_json
[type
],
6731 static void show_lsa_detail_adv_router_proc(struct vty
*vty
,
6732 struct route_table
*rt
,
6733 struct in_addr
*adv_router
,
6736 char buf
[PREFIX_STRLEN
];
6737 struct route_node
*rn
;
6738 struct ospf_lsa
*lsa
;
6740 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
))
6741 if ((lsa
= rn
->info
)) {
6742 json_object
*json_lsa
= NULL
;
6744 if (IPV4_ADDR_SAME(adv_router
,
6745 &lsa
->data
->adv_router
)) {
6746 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
6749 json_lsa
= json_object_new_object();
6751 if (show_function
[lsa
->data
->type
] != NULL
)
6752 show_function
[lsa
->data
->type
](
6753 vty
, lsa
, json_lsa
);
6755 json_object_object_add(
6765 /* Show detail LSA information. */
6766 static void show_lsa_detail_adv_router(struct vty
*vty
, struct ospf
*ospf
,
6767 int type
, struct in_addr
*adv_router
,
6770 struct listnode
*node
;
6771 struct ospf_area
*area
;
6772 char buf
[PREFIX_STRLEN
];
6773 json_object
*json_lstype
= NULL
;
6774 json_object
*json_area
= NULL
;
6777 json_lstype
= json_object_new_object();
6780 case OSPF_AS_EXTERNAL_LSA
:
6781 case OSPF_OPAQUE_AS_LSA
:
6783 vty_out(vty
, " %s \n\n",
6784 show_database_desc
[type
]);
6786 show_lsa_detail_adv_router_proc(vty
, AS_LSDB(ospf
, type
),
6787 adv_router
, json_lstype
);
6791 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6793 json_area
= json_object_new_object();
6796 "\n %s (Area %s)\n\n",
6797 show_database_desc
[type
],
6798 ospf_area_desc_string(area
));
6799 show_lsa_detail_adv_router_proc(vty
,
6800 AREA_LSDB(area
, type
),
6801 adv_router
, json_area
);
6804 json_object_object_add(json_lstype
,
6815 json_object_object_add(json
, show_database_desc
[type
],
6819 void show_ip_ospf_database_summary(struct vty
*vty
, struct ospf
*ospf
, int self
,
6822 struct ospf_lsa
*lsa
;
6823 struct route_node
*rn
;
6824 struct ospf_area
*area
;
6825 struct listnode
*node
;
6826 char buf
[PREFIX_STRLEN
];
6827 json_object
*json_areas
= NULL
;
6828 json_object
*json_area
= NULL
;
6829 json_object
*json_lsa
= NULL
;
6831 json_object
*json_lsa_array
= NULL
;
6834 json_areas
= json_object_new_object();
6836 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6838 json_area
= json_object_new_object();
6840 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6842 case OSPF_AS_EXTERNAL_LSA
:
6843 case OSPF_OPAQUE_AS_LSA
:
6848 if (ospf_lsdb_count_self(area
->lsdb
, type
) > 0
6850 && ospf_lsdb_count(area
->lsdb
, type
) > 0)) {
6854 " %s (Area %s)\n\n",
6855 show_database_desc
[type
],
6856 ospf_area_desc_string(area
));
6857 vty_out(vty
, "%s\n",
6858 show_database_header
[type
]);
6861 json_object_new_array();
6862 json_object_object_add(
6864 show_database_desc_json
[type
],
6868 LSDB_LOOP (AREA_LSDB(area
, type
), rn
, lsa
) {
6871 json_object_new_object();
6872 json_object_array_add(
6877 show_lsa_summary(vty
, lsa
, self
,
6886 json_object_object_add(json_areas
,
6894 json_object_object_add(json
, "areas", json_areas
);
6896 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6898 case OSPF_AS_EXTERNAL_LSA
:
6899 case OSPF_OPAQUE_AS_LSA
:
6904 if (ospf_lsdb_count_self(ospf
->lsdb
, type
)
6905 || (!self
&& ospf_lsdb_count(ospf
->lsdb
, type
))) {
6907 vty_out(vty
, " %s\n\n",
6908 show_database_desc
[type
]);
6909 vty_out(vty
, "%s\n",
6910 show_database_header
[type
]);
6912 json_lsa_array
= json_object_new_array();
6913 json_object_object_add(
6914 json
, show_database_desc_json
[type
],
6918 LSDB_LOOP (AS_LSDB(ospf
, type
), rn
, lsa
) {
6920 json_lsa
= json_object_new_object();
6921 json_object_array_add(json_lsa_array
,
6925 show_lsa_summary(vty
, lsa
, self
, json_lsa
);
6937 static void show_ip_ospf_database_maxage(struct vty
*vty
, struct ospf
*ospf
,
6940 struct route_node
*rn
;
6941 char buf
[PREFIX_STRLEN
];
6942 json_object
*json_maxage
= NULL
;
6945 vty_out(vty
, "\n MaxAge Link States:\n\n");
6947 json_maxage
= json_object_new_object();
6949 for (rn
= route_top(ospf
->maxage_lsa
); rn
; rn
= route_next(rn
)) {
6950 struct ospf_lsa
*lsa
;
6951 json_object
*json_lsa
= NULL
;
6953 if ((lsa
= rn
->info
) != NULL
) {
6955 vty_out(vty
, "Link type: %d\n",
6957 vty_out(vty
, "Link State ID: %pI4\n",
6959 vty_out(vty
, "Advertising Router: %pI4\n",
6960 &lsa
->data
->adv_router
);
6961 vty_out(vty
, "LSA lock count: %d\n", lsa
->lock
);
6964 json_lsa
= json_object_new_object();
6965 json_object_int_add(json_lsa
, "linkType",
6967 json_object_string_add(
6968 json_lsa
, "linkStateId",
6969 inet_ntop(AF_INET
, &lsa
->data
->id
,
6971 json_object_string_add(
6972 json_lsa
, "advertisingRouter",
6974 &lsa
->data
->adv_router
,
6976 json_object_int_add(json_lsa
, "lsaLockCount",
6978 json_object_object_add(
6988 json_object_object_add(json
, "maxAgeLinkStates", json_maxage
);
6991 #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
6992 #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
6994 #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
6995 #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
6996 #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
6997 #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
6999 #define OSPF_LSA_TYPES_DESC \
7000 "ASBR summary link states\n" \
7001 "External link states\n" \
7002 "Network link states\n" \
7003 "Router link states\n" \
7004 "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \
7005 OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
7006 OSPF_LSA_TYPE_OPAQUE_AS_DESC
7008 static int show_ip_ospf_database_common(struct vty
*vty
, struct ospf
*ospf
,
7009 int arg_base
, int argc
,
7010 struct cmd_token
**argv
,
7011 uint8_t use_vrf
, json_object
*json
,
7016 struct in_addr id
, adv_router
;
7017 char buf
[PREFIX_STRLEN
];
7018 json_object
*json_vrf
= NULL
;
7022 json_vrf
= json_object_new_object();
7027 if (ospf
->instance
) {
7029 json_object_int_add(json_vrf
, "ospfInstance",
7032 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
7035 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
7037 /* Show Router ID. */
7039 json_object_string_add(json_vrf
, "routerId",
7040 inet_ntop(AF_INET
, &ospf
->router_id
,
7043 vty_out(vty
, "\n OSPF Router with ID (%pI4)\n\n",
7048 if ((argc
== arg_base
+ 4) || (uj
&& (argc
== arg_base
+ 5))) {
7049 show_ip_ospf_database_summary(vty
, ospf
, 0, json_vrf
);
7052 if (ospf
->vrf_id
== VRF_DEFAULT
)
7053 json_object_object_add(json
, "default",
7056 json_object_object_add(json
, ospf
->name
,
7063 /* Set database type to show. */
7064 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
7065 type
= OSPF_ROUTER_LSA
;
7066 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
7067 type
= OSPF_NETWORK_LSA
;
7068 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
7069 type
= OSPF_AS_NSSA_LSA
;
7070 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "su", 2) == 0)
7071 type
= OSPF_SUMMARY_LSA
;
7072 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
7073 type
= OSPF_ASBR_SUMMARY_LSA
;
7074 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
7075 type
= OSPF_AS_EXTERNAL_LSA
;
7076 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "se", 2) == 0) {
7077 show_ip_ospf_database_summary(vty
, ospf
, 1, json_vrf
);
7080 if (ospf
->vrf_id
== VRF_DEFAULT
)
7081 json_object_object_add(json
, "default",
7084 json_object_object_add(json
, ospf
->name
,
7089 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "m", 1) == 0) {
7090 show_ip_ospf_database_maxage(vty
, ospf
, json_vrf
);
7093 if (ospf
->vrf_id
== VRF_DEFAULT
)
7094 json_object_object_add(json
, "default",
7097 json_object_object_add(json
, ospf
->name
,
7102 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
7103 type
= OSPF_OPAQUE_LINK_LSA
;
7104 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
7105 type
= OSPF_OPAQUE_AREA_LSA
;
7106 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
7107 type
= OSPF_OPAQUE_AS_LSA
;
7111 /* `show ip ospf database LSA'. */
7112 if ((argc
== arg_base
+ 5) || (uj
&& (argc
== arg_base
+ 6)))
7113 show_lsa_detail(vty
, ospf
, type
, NULL
, NULL
, json_vrf
);
7114 else if (argc
>= arg_base
+ 6) {
7115 ret
= inet_aton(argv
[arg_base
+ 5]->arg
, &id
);
7119 /* `show ip ospf database LSA ID'. */
7120 if ((argc
== arg_base
+ 6) || (uj
&& (argc
== arg_base
+ 7)))
7121 show_lsa_detail(vty
, ospf
, type
, &id
, NULL
, json_vrf
);
7122 /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */
7123 else if ((argc
== arg_base
+ 7)
7124 || (uj
&& (argc
== arg_base
+ 8))) {
7125 if (strncmp(argv
[arg_base
+ 6]->text
, "s", 1) == 0)
7126 adv_router
= ospf
->router_id
;
7128 ret
= inet_aton(argv
[arg_base
+ 7]->arg
,
7133 show_lsa_detail(vty
, ospf
, type
, &id
, &adv_router
,
7140 if (ospf
->vrf_id
== VRF_DEFAULT
)
7141 json_object_object_add(json
, "default",
7144 json_object_object_add(json
, ospf
->name
,
7152 DEFUN (show_ip_ospf_database_max
,
7153 show_ip_ospf_database_max_cmd
,
7154 "show ip ospf [vrf <NAME|all>] database <max-age|self-originate> [json]",
7157 "OSPF information\n"
7160 "Database summary\n"
7161 "LSAs in MaxAge list\n"
7162 "Self-originated link states\n"
7165 struct ospf
*ospf
= NULL
;
7166 struct listnode
*node
= NULL
;
7167 char *vrf_name
= NULL
;
7168 bool all_vrf
= false;
7169 int ret
= CMD_SUCCESS
;
7172 uint8_t use_vrf
= 0;
7173 bool uj
= use_json(argc
, argv
);
7174 json_object
*json
= NULL
;
7177 json
= json_object_new_object();
7179 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
7182 bool ospf_output
= false;
7187 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
7188 if (!ospf
->oi_running
)
7191 ret
= show_ip_ospf_database_common(
7192 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
,
7197 vty_out(vty
, "%% OSPF instance not found\n");
7199 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
7200 if (ospf
== NULL
|| !ospf
->oi_running
) {
7201 vty_out(vty
, "%% OSPF instance not found\n");
7204 ret
= (show_ip_ospf_database_common(
7205 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
, use_vrf
,
7209 /* Display default ospf (instance 0) info */
7210 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
7211 if (ospf
== NULL
|| !ospf
->oi_running
) {
7212 vty_out(vty
, "%% OSPF instance not found\n");
7216 ret
= show_ip_ospf_database_common(vty
, ospf
, 0, argc
, argv
,
7221 vty_out(vty
, "%s\n", json_object_to_json_string(json
));
7222 json_object_free(json
);
7228 ALIAS (show_ip_ospf_database_max
,
7229 show_ip_ospf_database_cmd
,
7230 "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]",
7233 "OSPF information\n"
7236 "Database summary\n"
7238 "Link State ID (as an IP address)\n"
7239 "Self-originated link states\n"
7240 "Advertising Router link states\n"
7241 "Advertising Router (as an IP address)\n"
7244 DEFUN (show_ip_ospf_instance_database_max
,
7245 show_ip_ospf_instance_database_max_cmd
,
7246 "show ip ospf (1-65535) database <max-age|self-originate> [json]",
7249 "OSPF information\n"
7251 "Database summary\n"
7252 "LSAs in MaxAge list\n"
7253 "Self-originated link states\n"
7258 unsigned short instance
= 0;
7259 bool uj
= use_json(argc
, argv
);
7260 json_object
*json
= NULL
;
7263 json
= json_object_new_object();
7265 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
7266 if (instance
!= ospf_instance
)
7267 return CMD_NOT_MY_INSTANCE
;
7269 ospf
= ospf_lookup_instance(instance
);
7270 if (!ospf
|| !ospf
->oi_running
)
7273 show_ip_ospf_database_common(vty
, ospf
, 1, argc
, argv
, 0, json
, uj
);
7276 vty_out(vty
, "%s\n",
7277 json_object_to_json_string_ext(
7278 json
, JSON_C_TO_STRING_PRETTY
));
7279 json_object_free(json
);
7285 ALIAS (show_ip_ospf_instance_database_max
,
7286 show_ip_ospf_instance_database_cmd
,
7287 "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]",
7290 "OSPF information\n"
7292 "Database summary\n"
7294 "Link State ID (as an IP address)\n"
7295 "Self-originated link states\n"
7296 "Advertising Router link states\n"
7297 "Advertising Router (as an IP address)\n"
7300 static int show_ip_ospf_database_type_adv_router_common(struct vty
*vty
,
7302 int arg_base
, int argc
,
7303 struct cmd_token
**argv
,
7310 struct in_addr adv_router
;
7311 char buf
[PREFIX_STRLEN
];
7312 json_object
*json_vrf
= NULL
;
7316 json_vrf
= json_object_new_object();
7321 if (ospf
->instance
) {
7323 json_object_int_add(json
, "ospfInstance",
7326 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
7329 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
7331 /* Show Router ID. */
7333 json_object_string_add(json_vrf
, "routerId",
7334 inet_ntop(AF_INET
, &ospf
->router_id
,
7337 vty_out(vty
, "\n OSPF Router with ID (%pI4)\n\n",
7341 /* Set database type to show. */
7342 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
7343 type
= OSPF_ROUTER_LSA
;
7344 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
7345 type
= OSPF_NETWORK_LSA
;
7346 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
7347 type
= OSPF_AS_NSSA_LSA
;
7348 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "s", 1) == 0)
7349 type
= OSPF_SUMMARY_LSA
;
7350 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
7351 type
= OSPF_ASBR_SUMMARY_LSA
;
7352 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
7353 type
= OSPF_AS_EXTERNAL_LSA
;
7354 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
7355 type
= OSPF_OPAQUE_LINK_LSA
;
7356 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
7357 type
= OSPF_OPAQUE_AREA_LSA
;
7358 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
7359 type
= OSPF_OPAQUE_AS_LSA
;
7363 /* `show ip ospf database LSA adv-router ADV_ROUTER'. */
7364 if (strncmp(argv
[arg_base
+ 5]->text
, "s", 1) == 0)
7365 adv_router
= ospf
->router_id
;
7367 ret
= inet_aton(argv
[arg_base
+ 6]->arg
, &adv_router
);
7372 show_lsa_detail_adv_router(vty
, ospf
, type
, &adv_router
, json_vrf
);
7376 if (ospf
->vrf_id
== VRF_DEFAULT
)
7377 json_object_object_add(json
, "default",
7380 json_object_object_add(json
, ospf
->name
,
7388 DEFUN (show_ip_ospf_database_type_adv_router
,
7389 show_ip_ospf_database_type_adv_router_cmd
,
7390 "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]",
7393 "OSPF information\n"
7396 "Database summary\n"
7398 "Advertising Router link states\n"
7399 "Advertising Router (as an IP address)\n"
7400 "Self-originated link states\n"
7403 struct ospf
*ospf
= NULL
;
7404 struct listnode
*node
= NULL
;
7405 char *vrf_name
= NULL
;
7406 bool all_vrf
= false;
7407 int ret
= CMD_SUCCESS
;
7410 uint8_t use_vrf
= 0;
7411 bool uj
= use_json(argc
, argv
);
7412 json_object
*json
= NULL
;
7415 json
= json_object_new_object();
7417 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
7420 bool ospf_output
= false;
7425 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
7426 if (!ospf
->oi_running
)
7429 ret
= show_ip_ospf_database_type_adv_router_common(
7430 vty
, ospf
, 2, argc
, argv
, use_vrf
, json
,
7434 vty_out(vty
, "%% OSPF instance not found\n");
7436 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
7437 if ((ospf
== NULL
) || !ospf
->oi_running
) {
7438 vty_out(vty
, "%% OSPF instance not found\n");
7442 ret
= show_ip_ospf_database_type_adv_router_common(
7443 vty
, ospf
, 2, argc
, argv
, use_vrf
, json
, uj
);
7446 /* Display default ospf (instance 0) info */
7447 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
7448 if (ospf
== NULL
|| !ospf
->oi_running
) {
7449 vty_out(vty
, "%% OSPF instance not found\n");
7453 ret
= show_ip_ospf_database_type_adv_router_common(
7454 vty
, ospf
, 0, argc
, argv
, use_vrf
, json
, uj
);
7458 vty_out(vty
, "%s\n", json_object_to_json_string(json
));
7459 json_object_free(json
);
7465 DEFUN (show_ip_ospf_instance_database_type_adv_router
,
7466 show_ip_ospf_instance_database_type_adv_router_cmd
,
7467 "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]",
7470 "OSPF information\n"
7472 "Database summary\n"
7474 "Advertising Router link states\n"
7475 "Advertising Router (as an IP address)\n"
7476 "Self-originated link states\n"
7481 unsigned short instance
= 0;
7482 bool uj
= use_json(argc
, argv
);
7483 json_object
*json
= NULL
;
7486 json
= json_object_new_object();
7488 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
7489 if (instance
!= ospf_instance
)
7490 return CMD_NOT_MY_INSTANCE
;
7492 ospf
= ospf_lookup_instance(instance
);
7493 if (!ospf
|| !ospf
->oi_running
)
7496 show_ip_ospf_database_type_adv_router_common(vty
, ospf
, 1, argc
, argv
,
7500 vty_out(vty
, "%s\n",
7501 json_object_to_json_string_ext(
7502 json
, JSON_C_TO_STRING_PRETTY
));
7503 json_object_free(json
);
7509 DEFUN (ip_ospf_authentication_args
,
7510 ip_ospf_authentication_args_addr_cmd
,
7511 "ip ospf authentication <null|message-digest> [A.B.C.D]",
7513 "OSPF interface commands\n"
7514 "Enable authentication on this interface\n"
7515 "Use null authentication\n"
7516 "Use message-digest authentication\n"
7517 "Address of interface\n")
7519 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7520 int idx_encryption
= 3;
7522 struct in_addr addr
;
7524 struct ospf_if_params
*params
;
7526 params
= IF_DEF_PARAMS(ifp
);
7529 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7532 "Please specify interface address by A.B.C.D\n");
7533 return CMD_WARNING_CONFIG_FAILED
;
7536 params
= ospf_get_if_params(ifp
, addr
);
7537 ospf_if_update_params(ifp
, addr
);
7540 /* Handle null authentication */
7541 if (argv
[idx_encryption
]->arg
[0] == 'n') {
7542 SET_IF_PARAM(params
, auth_type
);
7543 params
->auth_type
= OSPF_AUTH_NULL
;
7547 /* Handle message-digest authentication */
7548 if (argv
[idx_encryption
]->arg
[0] == 'm') {
7549 SET_IF_PARAM(params
, auth_type
);
7550 params
->auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
7554 vty_out(vty
, "You shouldn't get here!\n");
7555 return CMD_WARNING_CONFIG_FAILED
;
7558 DEFUN (ip_ospf_authentication
,
7559 ip_ospf_authentication_addr_cmd
,
7560 "ip ospf authentication [A.B.C.D]",
7562 "OSPF interface commands\n"
7563 "Enable authentication on this interface\n"
7564 "Address of interface\n")
7566 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7568 struct in_addr addr
;
7570 struct ospf_if_params
*params
;
7572 params
= IF_DEF_PARAMS(ifp
);
7575 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7578 "Please specify interface address by A.B.C.D\n");
7579 return CMD_WARNING_CONFIG_FAILED
;
7582 params
= ospf_get_if_params(ifp
, addr
);
7583 ospf_if_update_params(ifp
, addr
);
7586 SET_IF_PARAM(params
, auth_type
);
7587 params
->auth_type
= OSPF_AUTH_SIMPLE
;
7592 DEFUN (no_ip_ospf_authentication_args
,
7593 no_ip_ospf_authentication_args_addr_cmd
,
7594 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
7597 "OSPF interface commands\n"
7598 "Enable authentication on this interface\n"
7599 "Use null authentication\n"
7600 "Use message-digest authentication\n"
7601 "Address of interface\n")
7603 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7604 int idx_encryption
= 4;
7606 struct in_addr addr
;
7608 struct ospf_if_params
*params
;
7609 struct route_node
*rn
;
7612 params
= IF_DEF_PARAMS(ifp
);
7615 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7618 "Please specify interface address by A.B.C.D\n");
7619 return CMD_WARNING_CONFIG_FAILED
;
7622 params
= ospf_lookup_if_params(ifp
, addr
);
7623 if (params
== NULL
) {
7624 vty_out(vty
, "Ip Address specified is unknown\n");
7625 return CMD_WARNING_CONFIG_FAILED
;
7627 params
->auth_type
= OSPF_AUTH_NOTSET
;
7628 UNSET_IF_PARAM(params
, auth_type
);
7629 if (params
!= IF_DEF_PARAMS(ifp
)) {
7630 ospf_free_if_params(ifp
, addr
);
7631 ospf_if_update_params(ifp
, addr
);
7634 if (argv
[idx_encryption
]->arg
[0] == 'n') {
7635 auth_type
= OSPF_AUTH_NULL
;
7636 } else if (argv
[idx_encryption
]->arg
[0] == 'm') {
7637 auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
7639 vty_out(vty
, "Unexpected input encountered\n");
7640 return CMD_WARNING_CONFIG_FAILED
;
7643 * Here we have a case where the user has entered
7644 * 'no ip ospf authentication (null | message_digest )'
7645 * we need to find if we have any ip addresses underneath it
7647 * correspond to the associated type.
7649 if (params
->auth_type
== auth_type
) {
7650 params
->auth_type
= OSPF_AUTH_NOTSET
;
7651 UNSET_IF_PARAM(params
, auth_type
);
7654 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
7655 rn
= route_next(rn
)) {
7656 if ((params
= rn
->info
)) {
7657 if (params
->auth_type
== auth_type
) {
7658 params
->auth_type
= OSPF_AUTH_NOTSET
;
7659 UNSET_IF_PARAM(params
, auth_type
);
7660 if (params
!= IF_DEF_PARAMS(ifp
)) {
7661 ospf_free_if_params(
7662 ifp
, rn
->p
.u
.prefix4
);
7663 ospf_if_update_params(
7664 ifp
, rn
->p
.u
.prefix4
);
7674 DEFUN (no_ip_ospf_authentication
,
7675 no_ip_ospf_authentication_addr_cmd
,
7676 "no ip ospf authentication [A.B.C.D]",
7679 "OSPF interface commands\n"
7680 "Enable authentication on this interface\n"
7681 "Address of interface\n")
7683 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7685 struct in_addr addr
;
7687 struct ospf_if_params
*params
;
7688 struct route_node
*rn
;
7690 params
= IF_DEF_PARAMS(ifp
);
7693 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7696 "Please specify interface address by A.B.C.D\n");
7697 return CMD_WARNING_CONFIG_FAILED
;
7700 params
= ospf_lookup_if_params(ifp
, addr
);
7701 if (params
== NULL
) {
7702 vty_out(vty
, "Ip Address specified is unknown\n");
7703 return CMD_WARNING_CONFIG_FAILED
;
7706 params
->auth_type
= OSPF_AUTH_NOTSET
;
7707 UNSET_IF_PARAM(params
, auth_type
);
7708 if (params
!= IF_DEF_PARAMS(ifp
)) {
7709 ospf_free_if_params(ifp
, addr
);
7710 ospf_if_update_params(ifp
, addr
);
7714 * When a user enters 'no ip ospf authentication'
7715 * We should remove all authentication types from
7718 if ((params
->auth_type
== OSPF_AUTH_NULL
)
7719 || (params
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
7720 || (params
->auth_type
== OSPF_AUTH_SIMPLE
)) {
7721 params
->auth_type
= OSPF_AUTH_NOTSET
;
7722 UNSET_IF_PARAM(params
, auth_type
);
7725 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
7726 rn
= route_next(rn
)) {
7727 if ((params
= rn
->info
)) {
7729 if ((params
->auth_type
== OSPF_AUTH_NULL
)
7730 || (params
->auth_type
7731 == OSPF_AUTH_CRYPTOGRAPHIC
)
7732 || (params
->auth_type
7733 == OSPF_AUTH_SIMPLE
)) {
7734 params
->auth_type
= OSPF_AUTH_NOTSET
;
7735 UNSET_IF_PARAM(params
, auth_type
);
7736 if (params
!= IF_DEF_PARAMS(ifp
)) {
7737 ospf_free_if_params(
7738 ifp
, rn
->p
.u
.prefix4
);
7739 ospf_if_update_params(
7740 ifp
, rn
->p
.u
.prefix4
);
7751 DEFUN (ip_ospf_authentication_key
,
7752 ip_ospf_authentication_key_addr_cmd
,
7753 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
7755 "OSPF interface commands\n"
7756 "Authentication password (key)\n"
7757 "The OSPF password (key)\n"
7758 "Address of interface\n")
7760 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7762 struct in_addr addr
;
7763 struct ospf_if_params
*params
;
7765 params
= IF_DEF_PARAMS(ifp
);
7767 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7768 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7770 "Please specify interface address by A.B.C.D\n");
7771 return CMD_WARNING_CONFIG_FAILED
;
7774 params
= ospf_get_if_params(ifp
, addr
);
7775 ospf_if_update_params(ifp
, addr
);
7778 strlcpy((char *)params
->auth_simple
, argv
[3]->arg
,
7779 sizeof(params
->auth_simple
));
7780 SET_IF_PARAM(params
, auth_simple
);
7785 DEFUN_HIDDEN (ospf_authentication_key
,
7786 ospf_authentication_key_cmd
,
7787 "ospf authentication-key AUTH_KEY [A.B.C.D]",
7788 "OSPF interface commands\n"
7789 VLINK_HELPSTR_AUTH_SIMPLE
7790 "Address of interface\n")
7792 return ip_ospf_authentication_key(self
, vty
, argc
, argv
);
7795 DEFUN (no_ip_ospf_authentication_key
,
7796 no_ip_ospf_authentication_key_authkey_addr_cmd
,
7797 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7800 "OSPF interface commands\n"
7801 VLINK_HELPSTR_AUTH_SIMPLE
7802 "Address of interface\n")
7804 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7806 struct in_addr addr
;
7807 struct ospf_if_params
*params
;
7808 params
= IF_DEF_PARAMS(ifp
);
7810 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7811 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7813 "Please specify interface address by A.B.C.D\n");
7814 return CMD_WARNING_CONFIG_FAILED
;
7817 params
= ospf_lookup_if_params(ifp
, addr
);
7822 memset(params
->auth_simple
, 0, OSPF_AUTH_SIMPLE_SIZE
);
7823 UNSET_IF_PARAM(params
, auth_simple
);
7825 if (params
!= IF_DEF_PARAMS(ifp
)) {
7826 ospf_free_if_params(ifp
, addr
);
7827 ospf_if_update_params(ifp
, addr
);
7833 DEFUN_HIDDEN (no_ospf_authentication_key
,
7834 no_ospf_authentication_key_authkey_addr_cmd
,
7835 "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7837 "OSPF interface commands\n"
7838 VLINK_HELPSTR_AUTH_SIMPLE
7839 "Address of interface\n")
7841 return no_ip_ospf_authentication_key(self
, vty
, argc
, argv
);
7844 DEFUN (ip_ospf_message_digest_key
,
7845 ip_ospf_message_digest_key_cmd
,
7846 "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7848 "OSPF interface commands\n"
7849 "Message digest authentication password (key)\n"
7851 "Use MD5 algorithm\n"
7852 "The OSPF password (key)\n"
7853 "Address of interface\n")
7855 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7856 struct crypt_key
*ck
;
7858 struct in_addr addr
;
7859 struct ospf_if_params
*params
;
7861 params
= IF_DEF_PARAMS(ifp
);
7864 argv_find(argv
, argc
, "(1-255)", &idx
);
7865 char *keyid
= argv
[idx
]->arg
;
7866 argv_find(argv
, argc
, "KEY", &idx
);
7867 char *cryptkey
= argv
[idx
]->arg
;
7869 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7870 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7872 "Please specify interface address by A.B.C.D\n");
7873 return CMD_WARNING_CONFIG_FAILED
;
7876 params
= ospf_get_if_params(ifp
, addr
);
7877 ospf_if_update_params(ifp
, addr
);
7880 key_id
= strtol(keyid
, NULL
, 10);
7882 /* Remove existing key, if any */
7883 ospf_crypt_key_delete(params
->auth_crypt
, key_id
);
7885 ck
= ospf_crypt_key_new();
7886 ck
->key_id
= (uint8_t)key_id
;
7887 strlcpy((char *)ck
->auth_key
, cryptkey
, sizeof(ck
->auth_key
));
7889 ospf_crypt_key_add(params
->auth_crypt
, ck
);
7890 SET_IF_PARAM(params
, auth_crypt
);
7895 DEFUN_HIDDEN (ospf_message_digest_key
,
7896 ospf_message_digest_key_cmd
,
7897 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7898 "OSPF interface commands\n"
7899 "Message digest authentication password (key)\n"
7901 "Use MD5 algorithm\n"
7902 "The OSPF password (key)\n"
7903 "Address of interface\n")
7905 return ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7908 DEFUN (no_ip_ospf_message_digest_key
,
7909 no_ip_ospf_message_digest_key_cmd
,
7910 "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7913 "OSPF interface commands\n"
7914 "Message digest authentication password (key)\n"
7916 "Use MD5 algorithm\n"
7917 "The OSPF password (key)\n"
7918 "Address of interface\n")
7920 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7922 struct crypt_key
*ck
;
7924 struct in_addr addr
;
7925 struct ospf_if_params
*params
;
7926 params
= IF_DEF_PARAMS(ifp
);
7928 argv_find(argv
, argc
, "(1-255)", &idx
);
7929 char *keyid
= argv
[idx
]->arg
;
7931 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7932 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7934 "Please specify interface address by A.B.C.D\n");
7935 return CMD_WARNING_CONFIG_FAILED
;
7938 params
= ospf_lookup_if_params(ifp
, addr
);
7943 key_id
= strtol(keyid
, NULL
, 10);
7944 ck
= ospf_crypt_key_lookup(params
->auth_crypt
, key_id
);
7946 vty_out(vty
, "OSPF: Key %d does not exist\n", key_id
);
7947 return CMD_WARNING_CONFIG_FAILED
;
7950 ospf_crypt_key_delete(params
->auth_crypt
, key_id
);
7952 if (params
!= IF_DEF_PARAMS(ifp
)) {
7953 ospf_free_if_params(ifp
, addr
);
7954 ospf_if_update_params(ifp
, addr
);
7960 DEFUN_HIDDEN (no_ospf_message_digest_key
,
7961 no_ospf_message_digest_key_cmd
,
7962 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7964 "OSPF interface commands\n"
7965 "Message digest authentication password (key)\n"
7967 "Use MD5 algorithm\n"
7968 "The OSPF password (key)\n"
7969 "Address of interface\n")
7971 return no_ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7974 DEFUN (ip_ospf_cost
,
7976 "ip ospf cost (1-65535) [A.B.C.D]",
7978 "OSPF interface commands\n"
7981 "Address of interface\n")
7983 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7985 uint32_t cost
= OSPF_OUTPUT_COST_DEFAULT
;
7986 struct in_addr addr
;
7987 struct ospf_if_params
*params
;
7988 params
= IF_DEF_PARAMS(ifp
);
7991 char *coststr
= NULL
, *ifaddr
= NULL
;
7993 argv_find(argv
, argc
, "(1-65535)", &idx
);
7994 coststr
= argv
[idx
]->arg
;
7995 cost
= strtol(coststr
, NULL
, 10);
7997 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7999 if (!inet_aton(ifaddr
, &addr
)) {
8001 "Please specify interface address by A.B.C.D\n");
8002 return CMD_WARNING_CONFIG_FAILED
;
8005 params
= ospf_get_if_params(ifp
, addr
);
8006 ospf_if_update_params(ifp
, addr
);
8009 SET_IF_PARAM(params
, output_cost_cmd
);
8010 params
->output_cost_cmd
= cost
;
8012 ospf_if_recalculate_output_cost(ifp
);
8017 DEFUN_HIDDEN (ospf_cost
,
8019 "ospf cost (1-65535) [A.B.C.D]",
8020 "OSPF interface commands\n"
8023 "Address of interface\n")
8025 return ip_ospf_cost(self
, vty
, argc
, argv
);
8028 DEFUN (no_ip_ospf_cost
,
8029 no_ip_ospf_cost_cmd
,
8030 "no ip ospf cost [(1-65535)] [A.B.C.D]",
8033 "OSPF interface commands\n"
8036 "Address of interface\n")
8038 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8040 struct in_addr addr
;
8041 struct ospf_if_params
*params
;
8043 params
= IF_DEF_PARAMS(ifp
);
8046 char *ifaddr
= NULL
;
8047 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
8049 /* According to the semantics we are mimicking "no ip ospf cost N" is
8050 * always treated as "no ip ospf cost" regardless of the actual value
8051 * of N already configured for the interface. Thus ignore cost. */
8054 if (!inet_aton(ifaddr
, &addr
)) {
8056 "Please specify interface address by A.B.C.D\n");
8057 return CMD_WARNING_CONFIG_FAILED
;
8060 params
= ospf_lookup_if_params(ifp
, addr
);
8065 UNSET_IF_PARAM(params
, output_cost_cmd
);
8067 if (params
!= IF_DEF_PARAMS(ifp
)) {
8068 ospf_free_if_params(ifp
, addr
);
8069 ospf_if_update_params(ifp
, addr
);
8072 ospf_if_recalculate_output_cost(ifp
);
8077 DEFUN_HIDDEN (no_ospf_cost
,
8079 "no ospf cost [(1-65535)] [A.B.C.D]",
8081 "OSPF interface commands\n"
8084 "Address of interface\n")
8086 return no_ip_ospf_cost(self
, vty
, argc
, argv
);
8089 static void ospf_nbr_timer_update(struct ospf_interface
*oi
)
8091 struct route_node
*rn
;
8092 struct ospf_neighbor
*nbr
;
8094 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
8095 if ((nbr
= rn
->info
)) {
8096 nbr
->v_inactivity
= OSPF_IF_PARAM(oi
, v_wait
);
8097 nbr
->v_db_desc
= OSPF_IF_PARAM(oi
, retransmit_interval
);
8098 nbr
->v_ls_req
= OSPF_IF_PARAM(oi
, retransmit_interval
);
8099 nbr
->v_ls_upd
= OSPF_IF_PARAM(oi
, retransmit_interval
);
8103 static int ospf_vty_dead_interval_set(struct vty
*vty
, const char *interval_str
,
8104 const char *nbr_str
,
8105 const char *fast_hello_str
)
8107 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8110 struct in_addr addr
;
8112 struct ospf_if_params
*params
;
8113 struct ospf_interface
*oi
;
8114 struct route_node
*rn
;
8116 params
= IF_DEF_PARAMS(ifp
);
8119 ret
= inet_aton(nbr_str
, &addr
);
8122 "Please specify interface address by A.B.C.D\n");
8123 return CMD_WARNING_CONFIG_FAILED
;
8126 params
= ospf_get_if_params(ifp
, addr
);
8127 ospf_if_update_params(ifp
, addr
);
8131 seconds
= strtoul(interval_str
, NULL
, 10);
8133 /* reset fast_hello too, just to be sure */
8134 UNSET_IF_PARAM(params
, fast_hello
);
8135 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
8136 } else if (fast_hello_str
) {
8137 hellomult
= strtoul(fast_hello_str
, NULL
, 10);
8138 /* 1s dead-interval with sub-second hellos desired */
8139 seconds
= OSPF_ROUTER_DEAD_INTERVAL_MINIMAL
;
8140 SET_IF_PARAM(params
, fast_hello
);
8141 params
->fast_hello
= hellomult
;
8144 "Please specify dead-interval or hello-multiplier\n");
8145 return CMD_WARNING_CONFIG_FAILED
;
8148 SET_IF_PARAM(params
, v_wait
);
8149 params
->v_wait
= seconds
;
8150 params
->is_v_wait_set
= true;
8152 /* Update timer values in neighbor structure. */
8154 struct ospf
*ospf
= NULL
;
8156 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
8158 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
8160 ospf_nbr_timer_update(oi
);
8163 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
8164 if ((oi
= rn
->info
))
8165 ospf_nbr_timer_update(oi
);
8171 DEFUN (ip_ospf_dead_interval
,
8172 ip_ospf_dead_interval_cmd
,
8173 "ip ospf dead-interval (1-65535) [A.B.C.D]",
8175 "OSPF interface commands\n"
8176 "Interval time after which a neighbor is declared down\n"
8178 "Address of interface\n")
8181 char *interval
= argv_find(argv
, argc
, "(1-65535)", &idx
)
8185 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
8186 return ospf_vty_dead_interval_set(vty
, interval
, ifaddr
, NULL
);
8190 DEFUN_HIDDEN (ospf_dead_interval
,
8191 ospf_dead_interval_cmd
,
8192 "ospf dead-interval (1-65535) [A.B.C.D]",
8193 "OSPF interface commands\n"
8194 "Interval time after which a neighbor is declared down\n"
8196 "Address of interface\n")
8198 return ip_ospf_dead_interval(self
, vty
, argc
, argv
);
8201 DEFUN (ip_ospf_dead_interval_minimal
,
8202 ip_ospf_dead_interval_minimal_addr_cmd
,
8203 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
8205 "OSPF interface commands\n"
8206 "Interval time after which a neighbor is declared down\n"
8207 "Minimal 1s dead-interval with fast sub-second hellos\n"
8208 "Hello multiplier factor\n"
8209 "Number of Hellos to send each second\n"
8210 "Address of interface\n")
8215 return ospf_vty_dead_interval_set(
8216 vty
, NULL
, argv
[idx_ipv4
]->arg
, argv
[idx_number
]->arg
);
8218 return ospf_vty_dead_interval_set(vty
, NULL
, NULL
,
8219 argv
[idx_number
]->arg
);
8222 DEFUN (no_ip_ospf_dead_interval
,
8223 no_ip_ospf_dead_interval_cmd
,
8224 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8227 "OSPF interface commands\n"
8228 "Interval time after which a neighbor is declared down\n"
8230 "Minimal 1s dead-interval with fast sub-second hellos\n"
8231 "Hello multiplier factor\n"
8232 "Number of Hellos to send each second\n"
8233 "Address of interface\n")
8235 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8236 int idx_ipv4
= argc
- 1;
8237 struct in_addr addr
= {.s_addr
= 0L};
8239 struct ospf_if_params
*params
;
8240 struct ospf_interface
*oi
;
8241 struct route_node
*rn
;
8243 params
= IF_DEF_PARAMS(ifp
);
8245 if (argv
[idx_ipv4
]->type
== IPV4_TKN
) {
8246 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8249 "Please specify interface address by A.B.C.D\n");
8250 return CMD_WARNING_CONFIG_FAILED
;
8253 params
= ospf_lookup_if_params(ifp
, addr
);
8258 UNSET_IF_PARAM(params
, v_wait
);
8259 params
->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
8260 params
->is_v_wait_set
= false;
8262 UNSET_IF_PARAM(params
, fast_hello
);
8263 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
8265 if (params
!= IF_DEF_PARAMS(ifp
)) {
8266 ospf_free_if_params(ifp
, addr
);
8267 ospf_if_update_params(ifp
, addr
);
8270 /* Update timer values in neighbor structure. */
8272 struct ospf
*ospf
= NULL
;
8274 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
8276 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
8278 ospf_nbr_timer_update(oi
);
8281 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
8282 if ((oi
= rn
->info
))
8283 ospf_nbr_timer_update(oi
);
8289 DEFUN_HIDDEN (no_ospf_dead_interval
,
8290 no_ospf_dead_interval_cmd
,
8291 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8293 "OSPF interface commands\n"
8294 "Interval time after which a neighbor is declared down\n"
8296 "Minimal 1s dead-interval with fast sub-second hellos\n"
8297 "Hello multiplier factor\n"
8298 "Number of Hellos to send each second\n"
8299 "Address of interface\n")
8301 return no_ip_ospf_dead_interval(self
, vty
, argc
, argv
);
8304 DEFUN (ip_ospf_hello_interval
,
8305 ip_ospf_hello_interval_cmd
,
8306 "ip ospf hello-interval (1-65535) [A.B.C.D]",
8308 "OSPF interface commands\n"
8309 "Time between HELLO packets\n"
8311 "Address of interface\n")
8313 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8315 struct in_addr addr
= {.s_addr
= 0L};
8316 struct ospf_if_params
*params
;
8317 params
= IF_DEF_PARAMS(ifp
);
8318 uint32_t seconds
= 0;
8319 bool is_addr
= false;
8320 uint32_t old_interval
= 0;
8322 argv_find(argv
, argc
, "(1-65535)", &idx
);
8323 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
8325 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8326 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8328 "Please specify interface address by A.B.C.D\n");
8329 return CMD_WARNING_CONFIG_FAILED
;
8332 params
= ospf_get_if_params(ifp
, addr
);
8333 ospf_if_update_params(ifp
, addr
);
8337 old_interval
= params
->v_hello
;
8339 /* Return, if same interval is configured. */
8340 if (old_interval
== seconds
)
8343 SET_IF_PARAM(params
, v_hello
);
8344 params
->v_hello
= seconds
;
8346 if (!params
->is_v_wait_set
) {
8347 SET_IF_PARAM(params
, v_wait
);
8349 * The router dead interval should
8350 * be some multiple of the HelloInterval (perhaps 4 times the
8351 * hello interval) and must be the same for all routers
8352 * attached to a common network.
8354 params
->v_wait
= 4 * seconds
;
8357 ospf_reset_hello_timer(ifp
, addr
, is_addr
);
8362 DEFUN_HIDDEN (ospf_hello_interval
,
8363 ospf_hello_interval_cmd
,
8364 "ospf hello-interval (1-65535) [A.B.C.D]",
8365 "OSPF interface commands\n"
8366 "Time between HELLO packets\n"
8368 "Address of interface\n")
8370 return ip_ospf_hello_interval(self
, vty
, argc
, argv
);
8373 DEFUN (no_ip_ospf_hello_interval
,
8374 no_ip_ospf_hello_interval_cmd
,
8375 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
8378 "OSPF interface commands\n"
8379 "Time between HELLO packets\n" // ignored
8381 "Address of interface\n")
8383 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8385 struct in_addr addr
= {.s_addr
= 0L};
8386 struct ospf_if_params
*params
;
8387 struct route_node
*rn
;
8389 params
= IF_DEF_PARAMS(ifp
);
8391 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8392 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8394 "Please specify interface address by A.B.C.D\n");
8395 return CMD_WARNING_CONFIG_FAILED
;
8398 params
= ospf_lookup_if_params(ifp
, addr
);
8403 UNSET_IF_PARAM(params
, v_hello
);
8404 params
->v_hello
= OSPF_HELLO_INTERVAL_DEFAULT
;
8406 if (!params
->is_v_wait_set
) {
8407 UNSET_IF_PARAM(params
, v_wait
);
8408 params
->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
8411 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8412 struct ospf_interface
*oi
= rn
->info
;
8417 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
8418 oi
->ptp_dmvpn
= IF_DEF_PARAMS(ifp
)->ptp_dmvpn
;
8420 if (oi
->state
> ISM_Down
) {
8421 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
8422 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
8426 if (params
!= IF_DEF_PARAMS(ifp
)) {
8427 ospf_free_if_params(ifp
, addr
);
8428 ospf_if_update_params(ifp
, addr
);
8434 DEFUN_HIDDEN (no_ospf_hello_interval
,
8435 no_ospf_hello_interval_cmd
,
8436 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
8438 "OSPF interface commands\n"
8439 "Time between HELLO packets\n" // ignored
8441 "Address of interface\n")
8443 return no_ip_ospf_hello_interval(self
, vty
, argc
, argv
);
8446 DEFUN(ip_ospf_network
, ip_ospf_network_cmd
,
8447 "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point [dmvpn]>",
8449 "OSPF interface commands\n"
8451 "Specify OSPF broadcast multi-access network\n"
8452 "Specify OSPF NBMA network\n"
8453 "Specify OSPF point-to-multipoint network\n"
8454 "Specify OSPF point-to-point network\n"
8455 "Specify OSPF point-to-point DMVPN network\n")
8457 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8459 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
8460 uint8_t old_ptp_dmvpn
= IF_DEF_PARAMS(ifp
)->ptp_dmvpn
;
8461 struct route_node
*rn
;
8463 if (old_type
== OSPF_IFTYPE_LOOPBACK
) {
8465 "This is a loopback interface. Can't set network type.\n");
8466 return CMD_WARNING_CONFIG_FAILED
;
8469 IF_DEF_PARAMS(ifp
)->ptp_dmvpn
= 0;
8471 if (argv_find(argv
, argc
, "broadcast", &idx
))
8472 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_BROADCAST
;
8473 else if (argv_find(argv
, argc
, "non-broadcast", &idx
))
8474 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_NBMA
;
8475 else if (argv_find(argv
, argc
, "point-to-multipoint", &idx
))
8476 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOMULTIPOINT
;
8477 else if (argv_find(argv
, argc
, "point-to-point", &idx
)) {
8478 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOPOINT
;
8479 if (argv_find(argv
, argc
, "dmvpn", &idx
))
8480 IF_DEF_PARAMS(ifp
)->ptp_dmvpn
= 1;
8483 if (IF_DEF_PARAMS(ifp
)->type
== old_type
8484 && IF_DEF_PARAMS(ifp
)->ptp_dmvpn
== old_ptp_dmvpn
)
8487 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), type
);
8489 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8490 struct ospf_interface
*oi
= rn
->info
;
8495 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
8497 if (oi
->state
> ISM_Down
) {
8498 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
8499 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
8506 DEFUN_HIDDEN (ospf_network
,
8508 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
8509 "OSPF interface commands\n"
8511 "Specify OSPF broadcast multi-access network\n"
8512 "Specify OSPF NBMA network\n"
8513 "Specify OSPF point-to-multipoint network\n"
8514 "Specify OSPF point-to-point network\n")
8516 return ip_ospf_network(self
, vty
, argc
, argv
);
8519 DEFUN (no_ip_ospf_network
,
8520 no_ip_ospf_network_cmd
,
8521 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8524 "OSPF interface commands\n"
8526 "Specify OSPF broadcast multi-access network\n"
8527 "Specify OSPF NBMA network\n"
8528 "Specify OSPF point-to-multipoint network\n"
8529 "Specify OSPF point-to-point network\n")
8531 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8532 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
8533 struct route_node
*rn
;
8535 IF_DEF_PARAMS(ifp
)->type
= ospf_default_iftype(ifp
);
8536 IF_DEF_PARAMS(ifp
)->ptp_dmvpn
= 0;
8538 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
8541 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8542 struct ospf_interface
*oi
= rn
->info
;
8547 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
8549 if (oi
->state
> ISM_Down
) {
8550 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
8551 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
8558 DEFUN_HIDDEN (no_ospf_network
,
8559 no_ospf_network_cmd
,
8560 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8562 "OSPF interface commands\n"
8564 "Specify OSPF broadcast multi-access network\n"
8565 "Specify OSPF NBMA network\n"
8566 "Specify OSPF point-to-multipoint network\n"
8567 "Specify OSPF point-to-point network\n")
8569 return no_ip_ospf_network(self
, vty
, argc
, argv
);
8572 DEFUN (ip_ospf_priority
,
8573 ip_ospf_priority_cmd
,
8574 "ip ospf priority (0-255) [A.B.C.D]",
8576 "OSPF interface commands\n"
8579 "Address of interface\n")
8581 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8584 struct route_node
*rn
;
8585 struct in_addr addr
;
8586 struct ospf_if_params
*params
;
8587 params
= IF_DEF_PARAMS(ifp
);
8589 argv_find(argv
, argc
, "(0-255)", &idx
);
8590 priority
= strtol(argv
[idx
]->arg
, NULL
, 10);
8592 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8593 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8595 "Please specify interface address by A.B.C.D\n");
8596 return CMD_WARNING_CONFIG_FAILED
;
8599 params
= ospf_get_if_params(ifp
, addr
);
8600 ospf_if_update_params(ifp
, addr
);
8603 SET_IF_PARAM(params
, priority
);
8604 params
->priority
= priority
;
8606 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8607 struct ospf_interface
*oi
= rn
->info
;
8612 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
8613 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
8614 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
8621 DEFUN_HIDDEN (ospf_priority
,
8623 "ospf priority (0-255) [A.B.C.D]",
8624 "OSPF interface commands\n"
8627 "Address of interface\n")
8629 return ip_ospf_priority(self
, vty
, argc
, argv
);
8632 DEFUN (no_ip_ospf_priority
,
8633 no_ip_ospf_priority_cmd
,
8634 "no ip ospf priority [(0-255) [A.B.C.D]]",
8637 "OSPF interface commands\n"
8638 "Router priority\n" // ignored
8640 "Address of interface\n")
8642 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8644 struct route_node
*rn
;
8645 struct in_addr addr
;
8646 struct ospf_if_params
*params
;
8648 params
= IF_DEF_PARAMS(ifp
);
8650 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8651 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8653 "Please specify interface address by A.B.C.D\n");
8654 return CMD_WARNING_CONFIG_FAILED
;
8657 params
= ospf_lookup_if_params(ifp
, addr
);
8662 UNSET_IF_PARAM(params
, priority
);
8663 params
->priority
= OSPF_ROUTER_PRIORITY_DEFAULT
;
8665 if (params
!= IF_DEF_PARAMS(ifp
)) {
8666 ospf_free_if_params(ifp
, addr
);
8667 ospf_if_update_params(ifp
, addr
);
8670 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
8671 struct ospf_interface
*oi
= rn
->info
;
8676 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
8677 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
8678 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
8685 DEFUN_HIDDEN (no_ospf_priority
,
8686 no_ospf_priority_cmd
,
8687 "no ospf priority [(0-255) [A.B.C.D]]",
8689 "OSPF interface commands\n"
8692 "Address of interface\n")
8694 return no_ip_ospf_priority(self
, vty
, argc
, argv
);
8697 DEFUN (ip_ospf_retransmit_interval
,
8698 ip_ospf_retransmit_interval_addr_cmd
,
8699 "ip ospf retransmit-interval (1-65535) [A.B.C.D]",
8701 "OSPF interface commands\n"
8702 "Time between retransmitting lost link state advertisements\n"
8704 "Address of interface\n")
8706 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8709 struct in_addr addr
;
8710 struct ospf_if_params
*params
;
8711 params
= IF_DEF_PARAMS(ifp
);
8713 argv_find(argv
, argc
, "(1-65535)", &idx
);
8714 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
8716 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8717 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8719 "Please specify interface address by A.B.C.D\n");
8720 return CMD_WARNING_CONFIG_FAILED
;
8723 params
= ospf_get_if_params(ifp
, addr
);
8724 ospf_if_update_params(ifp
, addr
);
8727 SET_IF_PARAM(params
, retransmit_interval
);
8728 params
->retransmit_interval
= seconds
;
8733 DEFUN_HIDDEN (ospf_retransmit_interval
,
8734 ospf_retransmit_interval_cmd
,
8735 "ospf retransmit-interval (1-65535) [A.B.C.D]",
8736 "OSPF interface commands\n"
8737 "Time between retransmitting lost link state advertisements\n"
8739 "Address of interface\n")
8741 return ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
8744 DEFUN (no_ip_ospf_retransmit_interval
,
8745 no_ip_ospf_retransmit_interval_addr_cmd
,
8746 "no ip ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8749 "OSPF interface commands\n"
8750 "Time between retransmitting lost link state advertisements\n"
8752 "Address of interface\n")
8754 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8756 struct in_addr addr
;
8757 struct ospf_if_params
*params
;
8759 params
= IF_DEF_PARAMS(ifp
);
8761 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8762 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8764 "Please specify interface address by A.B.C.D\n");
8765 return CMD_WARNING_CONFIG_FAILED
;
8768 params
= ospf_lookup_if_params(ifp
, addr
);
8773 UNSET_IF_PARAM(params
, retransmit_interval
);
8774 params
->retransmit_interval
= OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
8776 if (params
!= IF_DEF_PARAMS(ifp
)) {
8777 ospf_free_if_params(ifp
, addr
);
8778 ospf_if_update_params(ifp
, addr
);
8784 DEFUN_HIDDEN (no_ospf_retransmit_interval
,
8785 no_ospf_retransmit_interval_cmd
,
8786 "no ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8788 "OSPF interface commands\n"
8789 "Time between retransmitting lost link state advertisements\n"
8791 "Address of interface\n")
8793 return no_ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
8796 DEFUN (ip_ospf_transmit_delay
,
8797 ip_ospf_transmit_delay_addr_cmd
,
8798 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
8800 "OSPF interface commands\n"
8801 "Link state transmit delay\n"
8803 "Address of interface\n")
8805 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8808 struct in_addr addr
;
8809 struct ospf_if_params
*params
;
8811 params
= IF_DEF_PARAMS(ifp
);
8812 argv_find(argv
, argc
, "(1-65535)", &idx
);
8813 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
8815 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8816 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8818 "Please specify interface address by A.B.C.D\n");
8819 return CMD_WARNING_CONFIG_FAILED
;
8822 params
= ospf_get_if_params(ifp
, addr
);
8823 ospf_if_update_params(ifp
, addr
);
8826 SET_IF_PARAM(params
, transmit_delay
);
8827 params
->transmit_delay
= seconds
;
8832 DEFUN_HIDDEN (ospf_transmit_delay
,
8833 ospf_transmit_delay_cmd
,
8834 "ospf transmit-delay (1-65535) [A.B.C.D]",
8835 "OSPF interface commands\n"
8836 "Link state transmit delay\n"
8838 "Address of interface\n")
8840 return ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
8843 DEFUN (no_ip_ospf_transmit_delay
,
8844 no_ip_ospf_transmit_delay_addr_cmd
,
8845 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
8848 "OSPF interface commands\n"
8849 "Link state transmit delay\n"
8851 "Address of interface\n")
8853 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8855 struct in_addr addr
;
8856 struct ospf_if_params
*params
;
8858 params
= IF_DEF_PARAMS(ifp
);
8860 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
8861 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
8863 "Please specify interface address by A.B.C.D\n");
8864 return CMD_WARNING_CONFIG_FAILED
;
8867 params
= ospf_lookup_if_params(ifp
, addr
);
8872 UNSET_IF_PARAM(params
, transmit_delay
);
8873 params
->transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
8875 if (params
!= IF_DEF_PARAMS(ifp
)) {
8876 ospf_free_if_params(ifp
, addr
);
8877 ospf_if_update_params(ifp
, addr
);
8884 DEFUN_HIDDEN (no_ospf_transmit_delay
,
8885 no_ospf_transmit_delay_cmd
,
8886 "no ospf transmit-delay [(1-65535) [A.B.C.D]]",
8888 "OSPF interface commands\n"
8889 "Link state transmit delay\n"
8891 "Address of interface\n")
8893 return no_ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
8896 DEFUN (ip_ospf_area
,
8898 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]",
8900 "OSPF interface commands\n"
8902 "Enable OSPF on this interface\n"
8903 "OSPF area ID in IP address format\n"
8904 "OSPF area ID as a decimal value\n"
8905 "Address of interface\n")
8907 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8910 struct in_addr area_id
;
8911 struct in_addr addr
;
8912 struct ospf_if_params
*params
= NULL
;
8913 struct route_node
*rn
;
8914 struct ospf
*ospf
= NULL
;
8915 unsigned short instance
= 0;
8919 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
8920 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
8922 argv_find(argv
, argc
, "area", &idx
);
8923 areaid
= argv
[idx
+ 1]->arg
;
8926 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
8928 ospf
= ospf_lookup_instance(instance
);
8930 if (instance
&& instance
!= ospf_instance
) {
8932 * At this point we know we have received
8933 * an instance and there is no ospf instance
8934 * associated with it. This means we are
8935 * in a situation where we have an
8936 * ospf command that is setup for a different
8937 * process(instance). We need to safely
8938 * remove the command from ourselves and
8939 * allow the other instance(process) handle
8940 * the configuration command.
8944 params
= IF_DEF_PARAMS(ifp
);
8945 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8946 UNSET_IF_PARAM(params
, if_area
);
8950 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
; rn
= route_next(rn
))
8951 if ((params
= rn
->info
) && OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8952 UNSET_IF_PARAM(params
, if_area
);
8957 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
8959 ospf_interface_area_unset(ospf
, ifp
);
8962 return CMD_NOT_MY_INSTANCE
;
8965 ret
= str2area_id(areaid
, &area_id
, &format
);
8967 vty_out(vty
, "Please specify area by A.B.C.D|<0-4294967295>\n");
8968 return CMD_WARNING_CONFIG_FAILED
;
8970 if (memcmp(ifp
->name
, "VLINK", 5) == 0) {
8971 vty_out(vty
, "Cannot enable OSPF on a virtual link.\n");
8972 return CMD_WARNING_CONFIG_FAILED
;
8976 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
)) {
8977 if (rn
->info
!= NULL
) {
8979 "Please remove all network commands first.\n");
8980 return CMD_WARNING_CONFIG_FAILED
;
8985 params
= IF_DEF_PARAMS(ifp
);
8986 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)
8987 && !IPV4_ADDR_SAME(¶ms
->if_area
, &area_id
)) {
8989 "Must remove previous area config before changing ospf area \n");
8990 return CMD_WARNING_CONFIG_FAILED
;
8993 // Check if we have an address arg and proccess it
8994 if (argc
== idx
+ 3) {
8995 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
8997 "Please specify Intf Address by A.B.C.D\n");
8998 return CMD_WARNING_CONFIG_FAILED
;
9000 // update/create address-level params
9001 params
= ospf_get_if_params((ifp
), (addr
));
9002 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
9003 if (!IPV4_ADDR_SAME(¶ms
->if_area
, &area_id
)) {
9005 "Must remove previous area/address config before changing ospf area\n");
9006 return CMD_WARNING_CONFIG_FAILED
;
9010 ospf_if_update_params((ifp
), (addr
));
9013 /* enable ospf on this interface with area_id */
9015 SET_IF_PARAM(params
, if_area
);
9016 params
->if_area
= area_id
;
9017 params
->if_area_id_fmt
= format
;
9021 ospf_interface_area_set(ospf
, ifp
);
9026 DEFUN (no_ip_ospf_area
,
9027 no_ip_ospf_area_cmd
,
9028 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]",
9031 "OSPF interface commands\n"
9033 "Disable OSPF on this interface\n"
9034 "OSPF area ID in IP address format\n"
9035 "OSPF area ID as a decimal value\n"
9036 "Address of interface\n")
9038 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9041 struct ospf_if_params
*params
;
9042 unsigned short instance
= 0;
9043 struct in_addr addr
;
9044 struct in_addr area_id
;
9046 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
9047 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
9050 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
9052 ospf
= ospf_lookup_instance(instance
);
9054 if (instance
&& instance
!= ospf_instance
)
9055 return CMD_NOT_MY_INSTANCE
;
9057 argv_find(argv
, argc
, "area", &idx
);
9059 // Check if we have an address arg and proccess it
9060 if (argc
== idx
+ 3) {
9061 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
9063 "Please specify Intf Address by A.B.C.D\n");
9064 return CMD_WARNING_CONFIG_FAILED
;
9066 params
= ospf_lookup_if_params(ifp
, addr
);
9067 if ((params
) == NULL
)
9070 params
= IF_DEF_PARAMS(ifp
);
9072 area_id
= params
->if_area
;
9073 if (!OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
9075 "Can't find specified interface area configuration.\n");
9076 return CMD_WARNING_CONFIG_FAILED
;
9079 UNSET_IF_PARAM(params
, if_area
);
9080 if (params
!= IF_DEF_PARAMS((ifp
))) {
9081 ospf_free_if_params((ifp
), (addr
));
9082 ospf_if_update_params((ifp
), (addr
));
9086 ospf_interface_area_unset(ospf
, ifp
);
9087 ospf_area_check_free(ospf
, area_id
);
9093 DEFUN (ip_ospf_passive
,
9094 ip_ospf_passive_cmd
,
9095 "ip ospf passive [A.B.C.D]",
9097 "OSPF interface commands\n"
9098 "Suppress routing updates on an interface\n"
9099 "Address of interface\n")
9101 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9103 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
9104 struct ospf_if_params
*params
;
9108 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9111 "Please specify interface address by A.B.C.D\n");
9112 return CMD_WARNING_CONFIG_FAILED
;
9114 params
= ospf_get_if_params(ifp
, addr
);
9115 ospf_if_update_params(ifp
, addr
);
9117 params
= IF_DEF_PARAMS(ifp
);
9120 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_PASSIVE
);
9125 DEFUN (no_ip_ospf_passive
,
9126 no_ip_ospf_passive_cmd
,
9127 "no ip ospf passive [A.B.C.D]",
9130 "OSPF interface commands\n"
9131 "Enable routing updates on an interface\n"
9132 "Address of interface\n")
9134 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9136 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
9137 struct ospf_if_params
*params
;
9141 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9144 "Please specify interface address by A.B.C.D\n");
9145 return CMD_WARNING_CONFIG_FAILED
;
9147 params
= ospf_lookup_if_params(ifp
, addr
);
9151 params
= IF_DEF_PARAMS(ifp
);
9154 ospf_passive_interface_update(ifp
, params
, addr
, OSPF_IF_ACTIVE
);
9159 DEFUN (ospf_redistribute_source
,
9160 ospf_redistribute_source_cmd
,
9161 "redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
9163 FRR_REDIST_HELP_STR_OSPFD
9164 "Metric for redistributed routes\n"
9165 "OSPF default metric\n"
9166 "OSPF exterior metric type for redistributed routes\n"
9167 "Set OSPF External Type 1/2 metrics\n"
9168 "Route map reference\n"
9169 "Pointer to route-map entries\n")
9171 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9172 int idx_protocol
= 1;
9176 struct ospf_redist
*red
;
9178 bool update
= false;
9180 /* Get distribute source. */
9181 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
9183 return CMD_WARNING_CONFIG_FAILED
;
9185 /* Get metric value. */
9186 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
9187 if (!str2metric(argv
[idx
]->arg
, &metric
))
9188 return CMD_WARNING_CONFIG_FAILED
;
9191 /* Get metric type. */
9192 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
9193 if (!str2metric_type(argv
[idx
]->arg
, &type
))
9194 return CMD_WARNING_CONFIG_FAILED
;
9198 red
= ospf_redist_lookup(ospf
, source
, 0);
9200 red
= ospf_redist_add(ospf
, source
, 0);
9205 if (argv_find(argv
, argc
, "WORD", &idx
)) {
9206 ospf_routemap_set(red
, argv
[idx
]->arg
);
9208 ospf_routemap_unset(red
);
9211 return ospf_redistribute_update(ospf
, red
, source
, 0, type
,
9214 return ospf_redistribute_set(ospf
, red
, source
, 0, type
,
9218 DEFUN (no_ospf_redistribute_source
,
9219 no_ospf_redistribute_source_cmd
,
9220 "no redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
9223 FRR_REDIST_HELP_STR_OSPFD
9224 "Metric for redistributed routes\n"
9225 "OSPF default metric\n"
9226 "OSPF exterior metric type for redistributed routes\n"
9227 "Set OSPF External Type 1/2 metrics\n"
9228 "Route map reference\n"
9229 "Pointer to route-map entries\n")
9231 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9232 int idx_protocol
= 2;
9234 struct ospf_redist
*red
;
9236 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
9238 return CMD_WARNING_CONFIG_FAILED
;
9240 red
= ospf_redist_lookup(ospf
, source
, 0);
9244 ospf_routemap_unset(red
);
9245 ospf_redist_del(ospf
, source
, 0);
9247 return ospf_redistribute_unset(ospf
, source
, 0);
9250 DEFUN (ospf_redistribute_instance_source
,
9251 ospf_redistribute_instance_source_cmd
,
9252 "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
9254 "Open Shortest Path First\n"
9255 "Non-main Kernel Routing Table\n"
9256 "Instance ID/Table ID\n"
9257 "Metric for redistributed routes\n"
9258 "OSPF default metric\n"
9259 "OSPF exterior metric type for redistributed routes\n"
9260 "Set OSPF External Type 1/2 metrics\n"
9261 "Route map reference\n"
9262 "Pointer to route-map entries\n")
9264 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9265 int idx_ospf_table
= 1;
9271 unsigned short instance
;
9272 struct ospf_redist
*red
;
9273 bool update
= false;
9275 source
= proto_redistnum(AFI_IP
, argv
[idx_ospf_table
]->text
);
9278 vty_out(vty
, "Unknown instance redistribution\n");
9279 return CMD_WARNING_CONFIG_FAILED
;
9282 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9284 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
9286 "Instance redistribution in non-instanced OSPF not allowed\n");
9287 return CMD_WARNING_CONFIG_FAILED
;
9290 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
9291 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
9292 return CMD_WARNING_CONFIG_FAILED
;
9295 /* Get metric value. */
9296 if (argv_find(argv
, argc
, "metric", &idx
))
9297 if (!str2metric(argv
[idx
+ 1]->arg
, &metric
))
9298 return CMD_WARNING_CONFIG_FAILED
;
9301 /* Get metric type. */
9302 if (argv_find(argv
, argc
, "metric-type", &idx
))
9303 if (!str2metric_type(argv
[idx
+ 1]->arg
, &type
))
9304 return CMD_WARNING_CONFIG_FAILED
;
9306 red
= ospf_redist_lookup(ospf
, source
, instance
);
9308 red
= ospf_redist_add(ospf
, source
, instance
);
9313 if (argv_find(argv
, argc
, "route-map", &idx
))
9314 ospf_routemap_set(red
, argv
[idx
+ 1]->arg
);
9316 ospf_routemap_unset(red
);
9319 return ospf_redistribute_update(ospf
, red
, source
, instance
,
9322 return ospf_redistribute_set(ospf
, red
, source
, instance
, type
,
9326 DEFUN (no_ospf_redistribute_instance_source
,
9327 no_ospf_redistribute_instance_source_cmd
,
9328 "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
9331 "Open Shortest Path First\n"
9332 "Non-main Kernel Routing Table\n"
9333 "Instance ID/Table Id\n"
9334 "Metric for redistributed routes\n"
9335 "OSPF default metric\n"
9336 "OSPF exterior metric type for redistributed routes\n"
9337 "Set OSPF External Type 1/2 metrics\n"
9338 "Route map reference\n"
9339 "Pointer to route-map entries\n")
9341 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9342 int idx_ospf_table
= 2;
9344 unsigned int instance
;
9345 struct ospf_redist
*red
;
9348 if (strncmp(argv
[idx_ospf_table
]->arg
, "o", 1) == 0)
9349 source
= ZEBRA_ROUTE_OSPF
;
9351 source
= ZEBRA_ROUTE_TABLE
;
9353 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9355 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
9357 "Instance redistribution in non-instanced OSPF not allowed\n");
9358 return CMD_WARNING_CONFIG_FAILED
;
9361 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
9362 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
9363 return CMD_WARNING_CONFIG_FAILED
;
9366 red
= ospf_redist_lookup(ospf
, source
, instance
);
9370 ospf_routemap_unset(red
);
9371 ospf_redist_del(ospf
, source
, instance
);
9373 return ospf_redistribute_unset(ospf
, source
, instance
);
9376 DEFUN (ospf_distribute_list_out
,
9377 ospf_distribute_list_out_cmd
,
9378 "distribute-list WORD out " FRR_REDIST_STR_OSPFD
,
9379 "Filter networks in routing updates\n"
9380 "Access-list name\n"
9382 FRR_REDIST_HELP_STR_OSPFD
)
9384 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9388 char *proto
= argv
[argc
- 1]->text
;
9390 /* Get distribute source. */
9391 source
= proto_redistnum(AFI_IP
, proto
);
9393 return CMD_WARNING_CONFIG_FAILED
;
9395 return ospf_distribute_list_out_set(ospf
, source
, argv
[idx_word
]->arg
);
9398 DEFUN (no_ospf_distribute_list_out
,
9399 no_ospf_distribute_list_out_cmd
,
9400 "no distribute-list WORD out " FRR_REDIST_STR_OSPFD
,
9402 "Filter networks in routing updates\n"
9403 "Access-list name\n"
9405 FRR_REDIST_HELP_STR_OSPFD
)
9407 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9411 char *proto
= argv
[argc
- 1]->text
;
9412 source
= proto_redistnum(AFI_IP
, proto
);
9414 return CMD_WARNING_CONFIG_FAILED
;
9416 return ospf_distribute_list_out_unset(ospf
, source
,
9417 argv
[idx_word
]->arg
);
9420 /* Default information originate. */
9421 DEFUN (ospf_default_information_originate
,
9422 ospf_default_information_originate_cmd
,
9423 "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
9424 "Control distribution of default information\n"
9425 "Distribute a default route\n"
9426 "Always advertise default route\n"
9427 "OSPF default metric\n"
9429 "OSPF metric type for default routes\n"
9430 "Set OSPF External Type 1/2 metrics\n"
9431 "Route map reference\n"
9432 "Pointer to route-map entries\n")
9434 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9435 int default_originate
= DEFAULT_ORIGINATE_ZEBRA
;
9438 struct ospf_redist
*red
;
9440 int cur_originate
= ospf
->default_originate
;
9444 red
= ospf_redist_add(ospf
, DEFAULT_ROUTE
, 0);
9446 /* Check whether "always" was specified */
9447 if (argv_find(argv
, argc
, "always", &idx
))
9448 default_originate
= DEFAULT_ORIGINATE_ALWAYS
;
9450 /* Get metric value */
9451 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
9452 if (!str2metric(argv
[idx
]->arg
, &metric
))
9453 return CMD_WARNING_CONFIG_FAILED
;
9456 /* Get metric type. */
9457 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
9458 if (!str2metric_type(argv
[idx
]->arg
, &type
))
9459 return CMD_WARNING_CONFIG_FAILED
;
9463 if (argv_find(argv
, argc
, "WORD", &idx
))
9464 rtmap
= argv
[idx
]->arg
;
9466 /* To check ,if user is providing same route map */
9467 if ((rtmap
== ROUTEMAP_NAME(red
)) ||
9468 (rtmap
&& ROUTEMAP_NAME(red
)
9469 && (strcmp(rtmap
, ROUTEMAP_NAME(red
)) == 0)))
9472 /* Don't allow if the same lsa is aleardy originated. */
9474 && (red
->dmetric
.type
== type
)
9475 && (red
->dmetric
.value
== metric
)
9476 && (cur_originate
== default_originate
))
9479 /* Updating Metric details */
9480 red
->dmetric
.type
= type
;
9481 red
->dmetric
.value
= metric
;
9483 /* updating route map details */
9485 ospf_routemap_set(red
, rtmap
);
9487 ospf_routemap_unset(red
);
9489 return ospf_redistribute_default_set(ospf
, default_originate
, type
,
9493 DEFUN (no_ospf_default_information_originate
,
9494 no_ospf_default_information_originate_cmd
,
9495 "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
9497 "Control distribution of default information\n"
9498 "Distribute a default route\n"
9499 "Always advertise default route\n"
9500 "OSPF default metric\n"
9502 "OSPF metric type for default routes\n"
9503 "Set OSPF External Type 1/2 metrics\n"
9504 "Route map reference\n"
9505 "Pointer to route-map entries\n")
9507 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9508 struct ospf_redist
*red
;
9510 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
9514 ospf_routemap_unset(red
);
9515 ospf_redist_del(ospf
, DEFAULT_ROUTE
, 0);
9517 return ospf_redistribute_default_set(ospf
, DEFAULT_ORIGINATE_NONE
,
9521 DEFUN (ospf_default_metric
,
9522 ospf_default_metric_cmd
,
9523 "default-metric (0-16777214)",
9524 "Set metric of redistributed routes\n"
9527 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9531 if (!str2metric(argv
[idx_number
]->arg
, &metric
))
9532 return CMD_WARNING_CONFIG_FAILED
;
9534 ospf
->default_metric
= metric
;
9539 DEFUN (no_ospf_default_metric
,
9540 no_ospf_default_metric_cmd
,
9541 "no default-metric [(0-16777214)]",
9543 "Set metric of redistributed routes\n"
9546 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9548 ospf
->default_metric
= -1;
9554 DEFUN (ospf_distance
,
9557 "Administrative distance\n"
9558 "OSPF Administrative distance\n")
9560 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9563 ospf
->distance_all
= atoi(argv
[idx_number
]->arg
);
9568 DEFUN (no_ospf_distance
,
9569 no_ospf_distance_cmd
,
9570 "no distance (1-255)",
9572 "Administrative distance\n"
9573 "OSPF Administrative distance\n")
9575 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9577 ospf
->distance_all
= 0;
9582 DEFUN (no_ospf_distance_ospf
,
9583 no_ospf_distance_ospf_cmd
,
9584 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
9586 "Administrative distance\n"
9587 "OSPF administrative distance\n"
9588 "Intra-area routes\n"
9589 "Distance for intra-area routes\n"
9590 "Inter-area routes\n"
9591 "Distance for inter-area routes\n"
9593 "Distance for external routes\n")
9595 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9598 if (argv_find(argv
, argc
, "intra-area", &idx
) || argc
== 3)
9599 idx
= ospf
->distance_intra
= 0;
9600 if (argv_find(argv
, argc
, "inter-area", &idx
) || argc
== 3)
9601 idx
= ospf
->distance_inter
= 0;
9602 if (argv_find(argv
, argc
, "external", &idx
) || argc
== 3)
9603 ospf
->distance_external
= 0;
9608 DEFUN (ospf_distance_ospf
,
9609 ospf_distance_ospf_cmd
,
9610 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
9611 "Administrative distance\n"
9612 "OSPF administrative distance\n"
9613 "Intra-area routes\n"
9614 "Distance for intra-area routes\n"
9615 "Inter-area routes\n"
9616 "Distance for inter-area routes\n"
9618 "Distance for external routes\n")
9620 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9623 ospf
->distance_intra
= 0;
9624 ospf
->distance_inter
= 0;
9625 ospf
->distance_external
= 0;
9627 if (argv_find(argv
, argc
, "intra-area", &idx
))
9628 ospf
->distance_intra
= atoi(argv
[idx
+ 1]->arg
);
9630 if (argv_find(argv
, argc
, "inter-area", &idx
))
9631 ospf
->distance_inter
= atoi(argv
[idx
+ 1]->arg
);
9633 if (argv_find(argv
, argc
, "external", &idx
))
9634 ospf
->distance_external
= atoi(argv
[idx
+ 1]->arg
);
9639 DEFUN (ip_ospf_mtu_ignore
,
9640 ip_ospf_mtu_ignore_addr_cmd
,
9641 "ip ospf mtu-ignore [A.B.C.D]",
9643 "OSPF interface commands\n"
9644 "Disable MTU mismatch detection on this interface\n"
9645 "Address of interface\n")
9647 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9649 struct in_addr addr
;
9652 struct ospf_if_params
*params
;
9653 params
= IF_DEF_PARAMS(ifp
);
9656 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9659 "Please specify interface address by A.B.C.D\n");
9660 return CMD_WARNING_CONFIG_FAILED
;
9662 params
= ospf_get_if_params(ifp
, addr
);
9663 ospf_if_update_params(ifp
, addr
);
9665 params
->mtu_ignore
= 1;
9666 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
9667 SET_IF_PARAM(params
, mtu_ignore
);
9669 UNSET_IF_PARAM(params
, mtu_ignore
);
9670 if (params
!= IF_DEF_PARAMS(ifp
)) {
9671 ospf_free_if_params(ifp
, addr
);
9672 ospf_if_update_params(ifp
, addr
);
9678 DEFUN (no_ip_ospf_mtu_ignore
,
9679 no_ip_ospf_mtu_ignore_addr_cmd
,
9680 "no ip ospf mtu-ignore [A.B.C.D]",
9683 "OSPF interface commands\n"
9684 "Disable MTU mismatch detection on this interface\n"
9685 "Address of interface\n")
9687 VTY_DECLVAR_CONTEXT(interface
, ifp
);
9689 struct in_addr addr
;
9692 struct ospf_if_params
*params
;
9693 params
= IF_DEF_PARAMS(ifp
);
9696 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
9699 "Please specify interface address by A.B.C.D\n");
9700 return CMD_WARNING_CONFIG_FAILED
;
9702 params
= ospf_get_if_params(ifp
, addr
);
9703 ospf_if_update_params(ifp
, addr
);
9705 params
->mtu_ignore
= 0;
9706 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
9707 SET_IF_PARAM(params
, mtu_ignore
);
9709 UNSET_IF_PARAM(params
, mtu_ignore
);
9710 if (params
!= IF_DEF_PARAMS(ifp
)) {
9711 ospf_free_if_params(ifp
, addr
);
9712 ospf_if_update_params(ifp
, addr
);
9719 DEFUN (ospf_max_metric_router_lsa_admin
,
9720 ospf_max_metric_router_lsa_admin_cmd
,
9721 "max-metric router-lsa administrative",
9722 "OSPF maximum / infinite-distance metric\n"
9723 "Advertise own Router-LSA with infinite distance (stub router)\n"
9724 "Administratively applied, for an indefinite period\n")
9726 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9727 struct listnode
*ln
;
9728 struct ospf_area
*area
;
9730 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
9731 SET_FLAG(area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
);
9733 if (!CHECK_FLAG(area
->stub_router_state
,
9734 OSPF_AREA_IS_STUB_ROUTED
))
9735 ospf_router_lsa_update_area(area
);
9738 /* Allows for areas configured later to get the property */
9739 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
;
9744 DEFUN (no_ospf_max_metric_router_lsa_admin
,
9745 no_ospf_max_metric_router_lsa_admin_cmd
,
9746 "no max-metric router-lsa administrative",
9748 "OSPF maximum / infinite-distance metric\n"
9749 "Advertise own Router-LSA with infinite distance (stub router)\n"
9750 "Administratively applied, for an indefinite period\n")
9752 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9753 struct listnode
*ln
;
9754 struct ospf_area
*area
;
9756 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
9757 UNSET_FLAG(area
->stub_router_state
,
9758 OSPF_AREA_ADMIN_STUB_ROUTED
);
9760 /* Don't trample on the start-up stub timer */
9761 if (CHECK_FLAG(area
->stub_router_state
,
9762 OSPF_AREA_IS_STUB_ROUTED
)
9763 && !area
->t_stub_router
) {
9764 UNSET_FLAG(area
->stub_router_state
,
9765 OSPF_AREA_IS_STUB_ROUTED
);
9766 ospf_router_lsa_update_area(area
);
9769 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET
;
9773 DEFUN (ospf_max_metric_router_lsa_startup
,
9774 ospf_max_metric_router_lsa_startup_cmd
,
9775 "max-metric router-lsa on-startup (5-86400)",
9776 "OSPF maximum / infinite-distance metric\n"
9777 "Advertise own Router-LSA with infinite distance (stub router)\n"
9778 "Automatically advertise stub Router-LSA on startup of OSPF\n"
9779 "Time (seconds) to advertise self as stub-router\n")
9781 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9783 unsigned int seconds
;
9786 vty_out(vty
, "%% Must supply stub-router period");
9787 return CMD_WARNING_CONFIG_FAILED
;
9790 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9792 ospf
->stub_router_startup_time
= seconds
;
9797 DEFUN (no_ospf_max_metric_router_lsa_startup
,
9798 no_ospf_max_metric_router_lsa_startup_cmd
,
9799 "no max-metric router-lsa on-startup [(5-86400)]",
9801 "OSPF maximum / infinite-distance metric\n"
9802 "Advertise own Router-LSA with infinite distance (stub router)\n"
9803 "Automatically advertise stub Router-LSA on startup of OSPF\n"
9804 "Time (seconds) to advertise self as stub-router\n")
9806 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9807 struct listnode
*ln
;
9808 struct ospf_area
*area
;
9810 ospf
->stub_router_startup_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
9812 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
9813 SET_FLAG(area
->stub_router_state
,
9814 OSPF_AREA_WAS_START_STUB_ROUTED
);
9815 OSPF_TIMER_OFF(area
->t_stub_router
);
9817 /* Don't trample on admin stub routed */
9818 if (!CHECK_FLAG(area
->stub_router_state
,
9819 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
9820 UNSET_FLAG(area
->stub_router_state
,
9821 OSPF_AREA_IS_STUB_ROUTED
);
9822 ospf_router_lsa_update_area(area
);
9829 DEFUN (ospf_max_metric_router_lsa_shutdown
,
9830 ospf_max_metric_router_lsa_shutdown_cmd
,
9831 "max-metric router-lsa on-shutdown (5-100)",
9832 "OSPF maximum / infinite-distance metric\n"
9833 "Advertise own Router-LSA with infinite distance (stub router)\n"
9834 "Advertise stub-router prior to full shutdown of OSPF\n"
9835 "Time (seconds) to wait till full shutdown\n")
9837 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9839 unsigned int seconds
;
9842 vty_out(vty
, "%% Must supply stub-router shutdown period");
9843 return CMD_WARNING_CONFIG_FAILED
;
9846 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9848 ospf
->stub_router_shutdown_time
= seconds
;
9853 DEFUN (no_ospf_max_metric_router_lsa_shutdown
,
9854 no_ospf_max_metric_router_lsa_shutdown_cmd
,
9855 "no max-metric router-lsa on-shutdown [(5-100)]",
9857 "OSPF maximum / infinite-distance metric\n"
9858 "Advertise own Router-LSA with infinite distance (stub router)\n"
9859 "Advertise stub-router prior to full shutdown of OSPF\n"
9860 "Time (seconds) to wait till full shutdown\n")
9862 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9864 ospf
->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
9869 DEFUN (ospf_proactive_arp
,
9870 ospf_proactive_arp_cmd
,
9872 "Allow sending ARP requests proactively\n")
9874 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9876 ospf
->proactive_arp
= true;
9881 DEFUN (no_ospf_proactive_arp
,
9882 no_ospf_proactive_arp_cmd
,
9885 "Disallow sending ARP requests proactively\n")
9887 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9889 ospf
->proactive_arp
= false;
9894 /* Graceful Restart HELPER Commands */
9895 DEFPY(ospf_gr_helper_enable
, ospf_gr_helper_enable_cmd
,
9896 "graceful-restart helper-only [A.B.C.D]",
9897 "OSPF Graceful Restart\n"
9898 "Enable Helper support\n"
9899 "Advertising router id\n")
9901 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9902 struct in_addr addr
;
9906 ret
= inet_aton(argv
[2]->arg
, &addr
);
9909 "Please specify the valid routerid address.\n");
9910 return CMD_WARNING_CONFIG_FAILED
;
9913 ospf_gr_helper_support_set_per_routerid(ospf
, &addr
, OSPF_GR_TRUE
);
9917 ospf_gr_helper_support_set(ospf
, OSPF_GR_TRUE
);
9922 DEFPY(no_ospf_gr_helper_enable
,
9923 no_ospf_gr_helper_enable_cmd
,
9924 "no graceful-restart helper-only [A.B.C.D]",
9926 "OSPF Graceful Restart\n"
9927 "Disable Helper support\n"
9928 "Advertising router id\n")
9930 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9931 struct in_addr addr
;
9935 ret
= inet_aton(argv
[3]->arg
, &addr
);
9938 "Please specify the valid routerid address.\n");
9939 return CMD_WARNING_CONFIG_FAILED
;
9942 ospf_gr_helper_support_set_per_routerid(ospf
, &addr
,
9947 ospf_gr_helper_support_set(ospf
, OSPF_GR_FALSE
);
9951 DEFPY(ospf_gr_helper_enable_lsacheck
,
9952 ospf_gr_helper_enable_lsacheck_cmd
,
9953 "graceful-restart helper strict-lsa-checking",
9954 "OSPF Graceful Restart\n"
9956 "Enable strict LSA check\n")
9958 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9960 ospf_gr_helper_lsa_check_set(ospf
, OSPF_GR_TRUE
);
9964 DEFPY(no_ospf_gr_helper_enable_lsacheck
,
9965 no_ospf_gr_helper_enable_lsacheck_cmd
,
9966 "no graceful-restart helper strict-lsa-checking",
9968 "OSPF Graceful Restart\n"
9970 "Disable strict LSA check\n")
9972 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9974 ospf_gr_helper_lsa_check_set(ospf
, OSPF_GR_FALSE
);
9978 DEFPY(ospf_gr_helper_supported_grace_time
,
9979 ospf_gr_helper_supported_grace_time_cmd
,
9980 "graceful-restart helper supported-grace-time (10-1800)$interval",
9981 "OSPF Graceful Restart\n"
9983 "Supported grace timer\n"
9984 "Grace interval(in seconds)\n")
9986 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
9988 ospf_gr_helper_supported_gracetime_set(ospf
, interval
);
9992 DEFPY(no_ospf_gr_helper_supported_grace_time
,
9993 no_ospf_gr_helper_supported_grace_time_cmd
,
9994 "no graceful-restart helper supported-grace-time (10-1800)$interval",
9996 "OSPF Graceful Restart\n"
9998 "Supported grace timer\n"
9999 "Grace interval(in seconds)\n")
10001 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10003 ospf_gr_helper_supported_gracetime_set(ospf
, OSPF_MAX_GRACE_INTERVAL
);
10004 return CMD_SUCCESS
;
10007 DEFPY(ospf_gr_helper_planned_only
,
10008 ospf_gr_helper_planned_only_cmd
,
10009 "graceful-restart helper planned-only",
10010 "OSPF Graceful Restart\n"
10012 "Supported only planned restart\n")
10014 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10016 ospf_gr_helper_set_supported_planned_only_restart(ospf
, OSPF_GR_TRUE
);
10018 return CMD_SUCCESS
;
10021 /* External Route Aggregation */
10022 DEFUN (ospf_external_route_aggregation
,
10023 ospf_external_route_aggregation_cmd
,
10024 "summary-address A.B.C.D/M [tag (1-4294967295)]",
10025 "External summary address\n"
10026 "Summary address prefix (a.b.c.d/m) \n"
10028 "Router tag value\n")
10030 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10031 struct prefix_ipv4 p
;
10033 route_tag_t tag
= 0;
10034 int ret
= OSPF_SUCCESS
;
10036 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
10038 if (is_default_prefix4(&p
)) {
10040 "Default address shouldn't be configured as summary address.\n");
10041 return CMD_SUCCESS
;
10044 /* Apply mask for given prefix. */
10045 apply_mask((struct prefix
*)&p
);
10047 if (!is_valid_summary_addr(&p
)) {
10048 vty_out(vty
, "Not a valid summary address.\n");
10049 return CMD_WARNING_CONFIG_FAILED
;
10053 tag
= strtoul(argv
[idx
+ 2]->arg
, NULL
, 10);
10055 ret
= ospf_asbr_external_aggregator_set(ospf
, &p
, tag
);
10056 if (ret
== OSPF_INVALID
)
10057 vty_out(vty
, "Inavlid configuration!!\n");
10059 return CMD_SUCCESS
;
10062 DEFUN (no_ospf_external_route_aggregation
,
10063 no_ospf_external_route_aggregation_cmd
,
10064 "no summary-address A.B.C.D/M [tag (1-4294967295)]",
10066 "External summary address\n"
10067 "Summary address prefix (a.b.c.d/m)\n"
10069 "Router tag value\n")
10071 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10072 struct prefix_ipv4 p
;
10074 route_tag_t tag
= 0;
10075 int ret
= OSPF_SUCCESS
;
10077 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
10079 if (is_default_prefix4(&p
)) {
10081 "Default address shouldn't be configured as summary address.\n");
10082 return CMD_SUCCESS
;
10085 /* Apply mask for given prefix. */
10086 apply_mask((struct prefix
*)&p
);
10088 if (!is_valid_summary_addr(&p
)) {
10089 vty_out(vty
, "Not a valid summary address.\n");
10090 return CMD_WARNING_CONFIG_FAILED
;
10094 tag
= strtoul(argv
[idx
+ 2]->arg
, NULL
, 10);
10096 ret
= ospf_asbr_external_aggregator_unset(ospf
, &p
, tag
);
10097 if (ret
== OSPF_INVALID
)
10098 vty_out(vty
, "Inavlid configuration!!\n");
10100 return CMD_SUCCESS
;
10103 DEFPY(no_ospf_gr_helper_planned_only
,
10104 no_ospf_gr_helper_planned_only_cmd
,
10105 "no graceful-restart helper planned-only",
10107 "OSPF Graceful Restart\n"
10109 "Supported only for planned restart\n")
10111 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10113 ospf_gr_helper_set_supported_planned_only_restart(ospf
, OSPF_GR_FALSE
);
10115 return CMD_SUCCESS
;
10118 static int ospf_print_vty_helper_dis_rtr_walkcb(struct hash_bucket
*bucket
,
10121 struct advRtr
*rtr
= bucket
->data
;
10122 struct vty
*vty
= (struct vty
*)arg
;
10123 static unsigned int count
;
10125 vty_out(vty
, "%-6pI4,", &rtr
->advRtrAddr
);
10128 if (count
% 5 == 0)
10129 vty_out(vty
, "\n");
10131 return HASHWALK_CONTINUE
;
10134 static int ospf_show_gr_helper_details(struct vty
*vty
, struct ospf
*ospf
,
10135 uint8_t use_vrf
, json_object
*json
,
10136 bool uj
, bool detail
)
10138 struct listnode
*node
;
10139 struct ospf_interface
*oi
;
10140 char buf
[PREFIX_STRLEN
];
10141 json_object
*json_vrf
= NULL
;
10145 json_vrf
= json_object_new_object();
10150 if (ospf
->instance
) {
10152 json_object_int_add(json
, "ospfInstance",
10155 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
10158 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
10162 if (ospf
->vrf_id
== VRF_DEFAULT
)
10163 json_object_object_add(json
, "default",
10166 json_object_object_add(json
, ospf
->name
,
10170 vty_out(vty
, "\n");
10172 /* Show Router ID. */
10174 json_object_string_add(json_vrf
, "routerId",
10175 inet_ntop(AF_INET
, &ospf
->router_id
,
10176 buf
, sizeof(buf
)));
10178 vty_out(vty
, "\n OSPF Router with ID (%pI4)\n\n",
10184 if (ospf
->is_helper_supported
)
10186 " Graceful restart helper support enabled.\n");
10189 " Graceful restart helper support disabled.\n");
10191 if (ospf
->strict_lsa_check
)
10192 vty_out(vty
, " Strict LSA check is enabled.\n");
10194 vty_out(vty
, " Strict LSA check is disabled.\n");
10196 if (ospf
->only_planned_restart
)
10198 " Helper supported for planned restarts only.\n");
10201 " Helper supported for Planned and Unplanned Restarts.\n");
10204 " Supported Graceful restart interval: %d(in seconds).\n",
10205 ospf
->supported_grace_time
);
10207 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf
)) {
10208 vty_out(vty
, " Enable Router list:\n");
10210 hash_walk(ospf
->enable_rtr_list
,
10211 ospf_print_vty_helper_dis_rtr_walkcb
, vty
);
10212 vty_out(vty
, "\n\n");
10215 if (ospf
->last_exit_reason
!= OSPF_GR_HELPER_EXIT_NONE
) {
10216 vty_out(vty
, " Last Helper exit Reason :%s\n",
10217 ospf_exit_reason2str(ospf
->last_exit_reason
));
10220 if (ospf
->active_restarter_cnt
)
10222 " Number of Active neighbours in graceful restart: %d\n",
10223 ospf
->active_restarter_cnt
);
10225 vty_out(vty
, "\n");
10228 json_object_string_add(
10229 json_vrf
, "helperSupport",
10230 (ospf
->is_helper_supported
) ? "Enabled" : "Disabled");
10231 json_object_string_add(json_vrf
, "strictLsaCheck",
10232 (ospf
->strict_lsa_check
) ? "Enabled"
10234 json_object_string_add(
10235 json_vrf
, "restartSupoort",
10236 (ospf
->only_planned_restart
)
10237 ? "Planned Restart only"
10238 : "Planned and Unplanned Restarts");
10240 json_object_int_add(json_vrf
, "supportedGracePeriod",
10241 ospf
->supported_grace_time
);
10243 if (ospf
->last_exit_reason
!= OSPF_GR_HELPER_EXIT_NONE
)
10244 json_object_string_add(
10245 json_vrf
, "LastExitReason",
10246 ospf_exit_reason2str(ospf
->last_exit_reason
));
10248 if (ospf
->active_restarter_cnt
)
10249 json_object_int_add(json_vrf
, "activeRestarterCnt",
10250 ospf
->active_restarter_cnt
);
10256 json_object
*json_neighbors
= NULL
;
10258 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
10259 struct route_node
*rn
;
10260 struct ospf_neighbor
*nbr
;
10261 json_object
*json_neigh
;
10263 if (ospf_interface_neighbor_count(oi
) == 0)
10267 json_object_object_get_ex(json_vrf
, "Neighbors",
10269 if (!json_neighbors
) {
10271 json_object_new_object();
10272 json_object_object_add(json_vrf
,
10278 for (rn
= route_top(oi
->nbrs
); rn
;
10279 rn
= route_next(rn
)) {
10286 if (!OSPF_GR_IS_ACTIVE_HELPER(nbr
))
10290 vty_out(vty
, " Neighbour %d :\n", cnt
);
10291 vty_out(vty
, " Address : %pI4\n",
10292 &nbr
->address
.u
.prefix4
);
10293 vty_out(vty
, " Routerid : %pI4\n",
10296 " Received Grace period : %d(in seconds).\n",
10297 nbr
->gr_helper_info
10298 .recvd_grace_period
);
10300 " Actual Grace period : %d(in seconds)\n",
10301 nbr
->gr_helper_info
10302 .actual_grace_period
);
10304 " Remaining GraceTime:%ld(in seconds).\n",
10305 thread_timer_remain_second(
10306 nbr
->gr_helper_info
10309 " Graceful Restart reason: %s.\n\n",
10310 ospf_restart_reason2str(
10311 nbr
->gr_helper_info
10312 .gr_restart_reason
));
10315 json_neigh
= json_object_new_object();
10316 json_object_string_add(
10317 json_neigh
, "srcAddr",
10318 inet_ntop(AF_INET
, &nbr
->src
,
10319 buf
, sizeof(buf
)));
10321 json_object_string_add(
10322 json_neigh
, "routerid",
10325 buf
, sizeof(buf
)));
10326 json_object_int_add(
10328 "recvdGraceInterval",
10329 nbr
->gr_helper_info
10330 .recvd_grace_period
);
10331 json_object_int_add(
10333 "actualGraceInterval",
10334 nbr
->gr_helper_info
10335 .actual_grace_period
);
10336 json_object_int_add(
10337 json_neigh
, "remainGracetime",
10338 thread_timer_remain_second(
10339 nbr
->gr_helper_info
10341 json_object_string_add(
10342 json_neigh
, "restartReason",
10343 ospf_restart_reason2str(
10344 nbr
->gr_helper_info
10345 .gr_restart_reason
));
10346 json_object_object_add(
10348 inet_ntop(AF_INET
, &nbr
->src
,
10355 return CMD_SUCCESS
;
10358 DEFUN (ospf_external_route_aggregation_no_adrvertise
,
10359 ospf_external_route_aggregation_no_adrvertise_cmd
,
10360 "summary-address A.B.C.D/M no-advertise",
10361 "External summary address\n"
10362 "Summary address prefix (a.b.c.d/m) \n"
10363 "Don't advertise summary route \n")
10365 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10366 struct prefix_ipv4 p
;
10368 int ret
= OSPF_SUCCESS
;
10370 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
10372 if (is_default_prefix4(&p
)) {
10374 "Default address shouldn't be configured as summary address.\n");
10375 return CMD_SUCCESS
;
10378 /* Apply mask for given prefix. */
10379 apply_mask((struct prefix
*)&p
);
10381 if (!is_valid_summary_addr(&p
)) {
10382 vty_out(vty
, "Not a valid summary address.\n");
10383 return CMD_WARNING_CONFIG_FAILED
;
10386 ret
= ospf_asbr_external_rt_no_advertise(ospf
, &p
);
10387 if (ret
== OSPF_INVALID
)
10388 vty_out(vty
, "Inavlid configuration!!\n");
10390 return CMD_SUCCESS
;
10393 DEFUN (no_ospf_external_route_aggregation_no_adrvertise
,
10394 no_ospf_external_route_aggregation_no_adrvertise_cmd
,
10395 "no summary-address A.B.C.D/M no-advertise",
10397 "External summary address\n"
10398 "Summary address prefix (a.b.c.d/m)\n"
10399 "Advertise summary route to the AS \n")
10401 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10402 struct prefix_ipv4 p
;
10404 int ret
= OSPF_SUCCESS
;
10406 str2prefix_ipv4(argv
[idx
]->arg
, &p
);
10408 if (is_default_prefix4(&p
)) {
10410 "Default address shouldn't be configured as summary address.\n");
10411 return CMD_SUCCESS
;
10414 /* Apply mask for given prefix. */
10415 apply_mask((struct prefix
*)&p
);
10417 if (!is_valid_summary_addr(&p
)) {
10418 vty_out(vty
, "Not a valid summary address.\n");
10419 return CMD_WARNING_CONFIG_FAILED
;
10422 ret
= ospf_asbr_external_rt_advertise(ospf
, &p
);
10423 if (ret
== OSPF_INVALID
)
10424 vty_out(vty
, "Inavlid configuration!!\n");
10426 return CMD_SUCCESS
;
10429 DEFUN (ospf_route_aggregation_timer
,
10430 ospf_route_aggregation_timer_cmd
,
10431 "aggregation timer (5-1800)",
10432 "External route aggregation\n"
10433 "Delay timer (in seconds)\n"
10434 "Timer interval(in seconds)\n")
10436 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10437 unsigned int interval
= 0;
10439 interval
= strtoul(argv
[2]->arg
, NULL
, 10);
10441 ospf_external_aggregator_timer_set(ospf
, interval
);
10443 return CMD_SUCCESS
;
10446 DEFPY (show_ip_ospf_gr_helper
,
10447 show_ip_ospf_gr_helper_cmd
,
10448 "show ip ospf [vrf <NAME|all>] graceful-restart helper [detail] [json]",
10451 "OSPF information\n"
10454 "OSPF Graceful Restart\n"
10455 "Helper details in the router\n"
10456 "Detailed informtion\n"
10459 char *vrf_name
= NULL
;
10460 bool all_vrf
= false;
10461 int ret
= CMD_SUCCESS
;
10464 uint8_t use_vrf
= 0;
10465 bool uj
= use_json(argc
, argv
);
10466 struct ospf
*ospf
= NULL
;
10467 json_object
*json
= NULL
;
10468 struct listnode
*node
= NULL
;
10470 bool detail
= false;
10472 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
10474 if (argv_find(argv
, argc
, "detail", &idx
))
10478 json
= json_object_new_object();
10480 /* vrf input is provided */
10485 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
10486 if (!ospf
->oi_running
)
10489 ret
= ospf_show_gr_helper_details(
10490 vty
, ospf
, use_vrf
, json
, uj
, detail
);
10494 vty_out(vty
, "%s\n",
10495 json_object_to_json_string_ext(
10496 json
, JSON_C_TO_STRING_PRETTY
));
10497 json_object_free(json
);
10503 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
10505 if (ospf
== NULL
|| !ospf
->oi_running
) {
10508 vty_out(vty
, "%s\n",
10509 json_object_to_json_string_ext(
10510 json
, JSON_C_TO_STRING_PRETTY
));
10511 json_object_free(json
);
10513 vty_out(vty
, "%% OSPF instance not found\n");
10515 return CMD_SUCCESS
;
10520 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
10522 if (ospf
== NULL
|| !ospf
->oi_running
) {
10525 vty_out(vty
, "%s\n",
10526 json_object_to_json_string_ext(
10527 json
, JSON_C_TO_STRING_PRETTY
));
10528 json_object_free(json
);
10530 vty_out(vty
, "%% OSPF instance not found\n");
10532 return CMD_SUCCESS
;
10535 ospf_show_gr_helper_details(vty
, ospf
, use_vrf
, json
, uj
,
10540 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
10541 json
, JSON_C_TO_STRING_PRETTY
));
10542 json_object_free(json
);
10545 return CMD_SUCCESS
;
10547 /* Graceful Restart HELPER commands end */
10548 DEFUN (no_ospf_route_aggregation_timer
,
10549 no_ospf_route_aggregation_timer_cmd
,
10550 "no aggregation timer",
10552 "External route aggregation\n"
10555 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
10557 ospf_external_aggregator_timer_set(ospf
, OSPF_EXTL_AGGR_DEFAULT_DELAY
);
10559 return CMD_SUCCESS
;
10562 /* External Route Aggregation End */
10564 static void config_write_stub_router(struct vty
*vty
, struct ospf
*ospf
)
10566 struct listnode
*ln
;
10567 struct ospf_area
*area
;
10569 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
10570 vty_out(vty
, " max-metric router-lsa on-startup %u\n",
10571 ospf
->stub_router_startup_time
);
10572 if (ospf
->stub_router_shutdown_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
10573 vty_out(vty
, " max-metric router-lsa on-shutdown %u\n",
10574 ospf
->stub_router_shutdown_time
);
10575 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
10576 if (CHECK_FLAG(area
->stub_router_state
,
10577 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
10578 vty_out(vty
, " max-metric router-lsa administrative\n");
10585 static void show_ip_ospf_route_network(struct vty
*vty
, struct ospf
*ospf
,
10586 struct route_table
*rt
,
10589 struct route_node
*rn
;
10590 struct ospf_route
* or ;
10591 struct listnode
*pnode
, *pnnode
;
10592 struct ospf_path
*path
;
10593 char buf
[PREFIX_STRLEN
];
10594 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
10595 *json_nexthop
= NULL
;
10599 "============ OSPF network routing table ============\n");
10601 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
10602 char buf1
[PREFIX2STR_BUFFER
];
10604 if ((or = rn
->info
) == NULL
)
10607 prefix2str(&rn
->p
, buf1
, sizeof(buf1
));
10609 json_route
= json_object_new_object();
10611 json_object_object_add(json
, buf1
, json_route
);
10612 json_object_to_json_string_ext(
10613 json
, JSON_C_TO_STRING_NOSLASHESCAPE
);
10616 switch (or->path_type
) {
10617 case OSPF_PATH_INTER_AREA
:
10618 if (or->type
== OSPF_DESTINATION_NETWORK
) {
10620 json_object_string_add(json_route
,
10623 json_object_int_add(json_route
, "cost",
10625 json_object_string_add(
10626 json_route
, "area",
10628 &or->u
.std
.area_id
,
10629 buf1
, sizeof(buf1
)));
10632 "N IA %-18s [%d] area: %pI4\n",
10634 &or->u
.std
.area_id
);
10636 } else if (or->type
== OSPF_DESTINATION_DISCARD
) {
10638 json_object_string_add(json_route
,
10643 "D IA %-18s Discard entry\n",
10648 case OSPF_PATH_INTRA_AREA
:
10650 json_object_string_add(json_route
, "routeType",
10652 json_object_int_add(json_route
, "cost",
10654 json_object_string_add(
10655 json_route
, "area",
10656 inet_ntop(AF_INET
, &or->u
.std
.area_id
,
10657 buf1
, sizeof(buf1
)));
10659 vty_out(vty
, "N %-18s [%d] area: %pI4\n",
10661 &or->u
.std
.area_id
);
10668 if (or->type
== OSPF_DESTINATION_NETWORK
) {
10670 json_nexthop_array
= json_object_new_array();
10671 json_object_object_add(json_route
, "nexthops",
10672 json_nexthop_array
);
10675 for (ALL_LIST_ELEMENTS(or->paths
, pnode
, pnnode
,
10678 json_nexthop
= json_object_new_object();
10679 json_object_array_add(
10680 json_nexthop_array
,
10683 if (if_lookup_by_index(path
->ifindex
,
10686 if (path
->nexthop
.s_addr
10689 json_object_string_add(
10692 json_object_string_add(
10694 "directly attached to",
10700 "%24s directly attached to %s\n",
10708 json_object_string_add(
10716 json_object_string_add(
10724 "%24s via %pI4, %s\n",
10736 json_object_free(json_route
);
10739 vty_out(vty
, "\n");
10742 static void show_ip_ospf_route_router(struct vty
*vty
, struct ospf
*ospf
,
10743 struct route_table
*rtrs
,
10746 struct route_node
*rn
;
10747 struct ospf_route
* or ;
10748 struct listnode
*pnode
;
10749 struct listnode
*node
;
10750 struct ospf_path
*path
;
10751 char buf
[PREFIX_STRLEN
];
10752 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
10753 *json_nexthop
= NULL
;
10757 "============ OSPF router routing table =============\n");
10759 for (rn
= route_top(rtrs
); rn
; rn
= route_next(rn
)) {
10760 if (rn
->info
== NULL
)
10764 json_route
= json_object_new_object();
10766 json_object_object_add(
10767 json
, inet_ntop(AF_INET
, &rn
->p
.u
.prefix4
,
10770 json_object_string_add(json_route
, "routeType", "R ");
10772 vty_out(vty
, "R %-15pI4 ",
10776 for (ALL_LIST_ELEMENTS_RO((struct list
*)rn
->info
, node
, or)) {
10779 vty_out(vty
, "%24s", "");
10784 json_object_int_add(json_route
, "cost",
10786 json_object_string_add(
10787 json_route
, "area",
10788 inet_ntop(AF_INET
, &or->u
.std
.area_id
,
10789 buf
, sizeof(buf
)));
10790 if (or->path_type
== OSPF_PATH_INTER_AREA
)
10791 json_object_boolean_true_add(json_route
,
10793 if (or->u
.std
.flags
& ROUTER_LSA_BORDER
)
10794 json_object_string_add(json_route
,
10797 else if (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
)
10798 json_object_string_add(json_route
,
10802 vty_out(vty
, "%s [%d] area: %pI4",
10803 (or->path_type
== OSPF_PATH_INTER_AREA
10806 or->cost
, &or->u
.std
.area_id
);
10808 vty_out(vty
, "%s%s\n",
10809 (or->u
.std
.flags
& ROUTER_LSA_BORDER
10812 (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
10818 json_nexthop_array
= json_object_new_array();
10819 json_object_object_add(json_route
, "nexthops",
10820 json_nexthop_array
);
10823 for (ALL_LIST_ELEMENTS_RO(or->paths
, pnode
, path
)) {
10825 json_nexthop
= json_object_new_object();
10826 json_object_array_add(
10827 json_nexthop_array
,
10830 if (if_lookup_by_index(path
->ifindex
,
10832 if (path
->nexthop
.s_addr
10835 json_object_string_add(
10838 json_object_string_add(
10840 "directly attached to",
10846 "%24s directly attached to %s\n",
10854 json_object_string_add(
10860 buf
, sizeof(buf
)));
10861 json_object_string_add(
10869 "%24s via %pI4, %s\n",
10881 json_object_free(json_route
);
10884 vty_out(vty
, "\n");
10887 static void show_ip_ospf_route_external(struct vty
*vty
, struct ospf
*ospf
,
10888 struct route_table
*rt
,
10891 struct route_node
*rn
;
10892 struct ospf_route
*er
;
10893 struct listnode
*pnode
, *pnnode
;
10894 struct ospf_path
*path
;
10895 char buf
[PREFIX_STRLEN
];
10896 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
10897 *json_nexthop
= NULL
;
10901 "============ OSPF external routing table ===========\n");
10903 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
10904 if ((er
= rn
->info
) == NULL
)
10909 snprintfrr(buf1
, sizeof(buf1
), "%pFX", &rn
->p
);
10910 json_route
= json_object_new_object();
10912 json_object_object_add(json
, buf1
, json_route
);
10913 json_object_to_json_string_ext(
10914 json
, JSON_C_TO_STRING_NOSLASHESCAPE
);
10917 switch (er
->path_type
) {
10918 case OSPF_PATH_TYPE1_EXTERNAL
:
10920 json_object_string_add(json_route
, "routeType",
10922 json_object_int_add(json_route
, "cost",
10924 json_object_int_add(json_route
, "tag",
10928 "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI
10930 buf1
, er
->cost
, er
->u
.ext
.tag
);
10933 case OSPF_PATH_TYPE2_EXTERNAL
:
10935 json_object_string_add(json_route
, "routeType",
10937 json_object_int_add(json_route
, "cost",
10939 json_object_int_add(json_route
, "type2cost",
10940 er
->u
.ext
.type2_cost
);
10941 json_object_int_add(json_route
, "tag",
10945 "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI
10947 buf1
, er
->cost
, er
->u
.ext
.type2_cost
,
10954 json_nexthop_array
= json_object_new_array();
10955 json_object_object_add(json_route
, "nexthops",
10956 json_nexthop_array
);
10959 for (ALL_LIST_ELEMENTS(er
->paths
, pnode
, pnnode
, path
)) {
10961 json_nexthop
= json_object_new_object();
10962 json_object_array_add(json_nexthop_array
,
10966 if (if_lookup_by_index(path
->ifindex
, ospf
->vrf_id
)) {
10967 if (path
->nexthop
.s_addr
== INADDR_ANY
) {
10969 json_object_string_add(
10970 json_nexthop
, "ip",
10972 json_object_string_add(
10974 "directly attached to",
10980 "%24s directly attached to %s\n",
10988 json_object_string_add(
10989 json_nexthop
, "ip",
10995 json_object_string_add(
10996 json_nexthop
, "via",
11002 "%24s via %pI4, %s\n",
11013 json_object_free(json_route
);
11016 vty_out(vty
, "\n");
11019 static int show_ip_ospf_border_routers_common(struct vty
*vty
,
11023 if (ospf
->instance
)
11024 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
11026 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
11028 if (ospf
->new_table
== NULL
) {
11029 vty_out(vty
, "No OSPF routing information exist\n");
11030 return CMD_SUCCESS
;
11033 /* Show Network routes.
11034 show_ip_ospf_route_network (vty, ospf->new_table); */
11036 /* Show Router routes. */
11037 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, NULL
);
11039 vty_out(vty
, "\n");
11041 return CMD_SUCCESS
;
11044 DEFUN (show_ip_ospf_border_routers
,
11045 show_ip_ospf_border_routers_cmd
,
11046 "show ip ospf [vrf <NAME|all>] border-routers",
11049 "OSPF information\n"
11052 "Show all the ABR's and ASBR's\n")
11054 struct ospf
*ospf
= NULL
;
11055 struct listnode
*node
= NULL
;
11056 char *vrf_name
= NULL
;
11057 bool all_vrf
= false;
11058 int ret
= CMD_SUCCESS
;
11061 uint8_t use_vrf
= 0;
11063 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11066 bool ospf_output
= false;
11071 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11072 if (!ospf
->oi_running
)
11075 ospf_output
= true;
11076 ret
= show_ip_ospf_border_routers_common(
11077 vty
, ospf
, use_vrf
);
11081 vty_out(vty
, "%% OSPF instance not found\n");
11083 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11084 if (ospf
== NULL
|| !ospf
->oi_running
) {
11085 vty_out(vty
, "%% OSPF instance not found\n");
11086 return CMD_SUCCESS
;
11089 ret
= show_ip_ospf_border_routers_common(vty
, ospf
,
11093 /* Display default ospf (instance 0) info */
11094 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11095 if (ospf
== NULL
|| !ospf
->oi_running
) {
11096 vty_out(vty
, "%% OSPF instance not found\n");
11097 return CMD_SUCCESS
;
11100 ret
= show_ip_ospf_border_routers_common(vty
, ospf
, use_vrf
);
11106 DEFUN (show_ip_ospf_instance_border_routers
,
11107 show_ip_ospf_instance_border_routers_cmd
,
11108 "show ip ospf (1-65535) border-routers",
11111 "OSPF information\n"
11113 "Show all the ABR's and ASBR's\n")
11115 int idx_number
= 3;
11117 unsigned short instance
= 0;
11119 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
11120 if (instance
!= ospf_instance
)
11121 return CMD_NOT_MY_INSTANCE
;
11123 ospf
= ospf_lookup_instance(instance
);
11124 if (!ospf
|| !ospf
->oi_running
)
11125 return CMD_SUCCESS
;
11127 return show_ip_ospf_border_routers_common(vty
, ospf
, 0);
11130 static int show_ip_ospf_route_common(struct vty
*vty
, struct ospf
*ospf
,
11131 json_object
*json
, uint8_t use_vrf
)
11133 json_object
*json_vrf
= NULL
;
11135 if (ospf
->instance
)
11136 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
11141 json_vrf
= json_object_new_object();
11146 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
11148 if (ospf
->new_table
== NULL
) {
11149 vty_out(vty
, "No OSPF routing information exist\n");
11150 return CMD_SUCCESS
;
11153 /* Show Network routes. */
11154 show_ip_ospf_route_network(vty
, ospf
, ospf
->new_table
, json_vrf
);
11156 /* Show Router routes. */
11157 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, json_vrf
);
11159 /* Show AS External routes. */
11160 show_ip_ospf_route_external(vty
, ospf
, ospf
->old_external_route
,
11165 // json_object_object_add(json_vrf, "areas",
11167 if (ospf
->vrf_id
== VRF_DEFAULT
)
11168 json_object_object_add(json
, "default",
11171 json_object_object_add(json
, ospf
->name
,
11175 vty_out(vty
, "\n");
11178 return CMD_SUCCESS
;
11181 DEFUN (show_ip_ospf_route
,
11182 show_ip_ospf_route_cmd
,
11183 "show ip ospf [vrf <NAME|all>] route [json]",
11186 "OSPF information\n"
11189 "OSPF routing table\n"
11192 struct ospf
*ospf
= NULL
;
11193 struct listnode
*node
= NULL
;
11194 char *vrf_name
= NULL
;
11195 bool all_vrf
= false;
11196 int ret
= CMD_SUCCESS
;
11199 uint8_t use_vrf
= 0;
11200 bool uj
= use_json(argc
, argv
);
11201 json_object
*json
= NULL
;
11204 json
= json_object_new_object();
11206 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11208 /* vrf input is provided could be all or specific vrf*/
11210 bool ospf_output
= false;
11215 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11216 if (!ospf
->oi_running
)
11218 ospf_output
= true;
11219 ret
= show_ip_ospf_route_common(vty
, ospf
, json
,
11224 /* Keep Non-pretty format */
11225 vty_out(vty
, "%s\n",
11226 json_object_to_json_string(json
));
11227 json_object_free(json
);
11228 } else if (!ospf_output
)
11229 vty_out(vty
, "%% OSPF instance not found\n");
11233 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11234 if (ospf
== NULL
|| !ospf
->oi_running
) {
11236 vty_out(vty
, "%s\n",
11237 json_object_to_json_string_ext(
11238 json
, JSON_C_TO_STRING_PRETTY
));
11239 json_object_free(json
);
11241 vty_out(vty
, "%% OSPF instance not found\n");
11243 return CMD_SUCCESS
;
11246 /* Display default ospf (instance 0) info */
11247 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11248 if (ospf
== NULL
|| !ospf
->oi_running
) {
11250 vty_out(vty
, "%s\n",
11251 json_object_to_json_string_ext(
11252 json
, JSON_C_TO_STRING_PRETTY
));
11253 json_object_free(json
);
11255 vty_out(vty
, "%% OSPF instance not found\n");
11257 return CMD_SUCCESS
;
11262 ret
= show_ip_ospf_route_common(vty
, ospf
, json
, use_vrf
);
11263 /* Keep Non-pretty format */
11265 vty_out(vty
, "%s\n", json_object_to_json_string(json
));
11269 json_object_free(json
);
11274 DEFUN (show_ip_ospf_instance_route
,
11275 show_ip_ospf_instance_route_cmd
,
11276 "show ip ospf (1-65535) route",
11279 "OSPF information\n"
11281 "OSPF routing table\n")
11283 int idx_number
= 3;
11285 unsigned short instance
= 0;
11287 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
11288 if (instance
!= ospf_instance
)
11289 return CMD_NOT_MY_INSTANCE
;
11291 ospf
= ospf_lookup_instance(instance
);
11292 if (!ospf
|| !ospf
->oi_running
)
11293 return CMD_SUCCESS
;
11295 return show_ip_ospf_route_common(vty
, ospf
, NULL
, 0);
11299 DEFUN (show_ip_ospf_vrfs
,
11300 show_ip_ospf_vrfs_cmd
,
11301 "show ip ospf vrfs [json]",
11304 "OSPF information\n"
11305 "Show OSPF VRFs \n"
11308 bool uj
= use_json(argc
, argv
);
11309 json_object
*json
= NULL
;
11310 json_object
*json_vrfs
= NULL
;
11311 struct ospf
*ospf
= NULL
;
11312 struct listnode
*node
= NULL
;
11314 char buf
[PREFIX_STRLEN
];
11315 static const char header
[] = "Name Id RouterId ";
11318 json
= json_object_new_object();
11319 json_vrfs
= json_object_new_object();
11322 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11323 json_object
*json_vrf
= NULL
;
11324 const char *name
= NULL
;
11325 int64_t vrf_id_ui
= 0;
11329 if (!uj
&& count
== 1)
11330 vty_out(vty
, "%s\n", header
);
11332 json_vrf
= json_object_new_object();
11334 if (ospf
->vrf_id
== VRF_DEFAULT
)
11335 name
= VRF_DEFAULT_NAME
;
11339 vrf_id_ui
= (ospf
->vrf_id
== VRF_UNKNOWN
)
11341 : (int64_t)ospf
->vrf_id
;
11344 json_object_int_add(json_vrf
, "vrfId", vrf_id_ui
);
11345 json_object_string_add(
11346 json_vrf
, "routerId",
11347 inet_ntop(AF_INET
, &ospf
->router_id
,
11348 buf
, sizeof(buf
)));
11350 json_object_object_add(json_vrfs
, name
, json_vrf
);
11353 vty_out(vty
, "%-25s %-5d %-16pI4 \n", name
,
11354 ospf
->vrf_id
, &ospf
->router_id
);
11359 json_object_object_add(json
, "vrfs", json_vrfs
);
11360 json_object_int_add(json
, "totalVrfs", count
);
11362 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
11363 json
, JSON_C_TO_STRING_PRETTY
));
11364 json_object_free(json
);
11367 vty_out(vty
, "\nTotal number of OSPF VRFs: %d\n",
11371 return CMD_SUCCESS
;
11373 DEFPY (clear_ip_ospf_neighbor
,
11374 clear_ip_ospf_neighbor_cmd
,
11375 "clear ip ospf [(1-65535)]$instance neighbor [A.B.C.D$nbr_id]",
11378 "OSPF information\n"
11380 "Reset OSPF Neighbor\n"
11383 struct listnode
*node
;
11384 struct ospf
*ospf
= NULL
;
11386 /* If user does not specify the arguments,
11387 * instance = 0 and nbr_id = 0.0.0.0
11389 if (instance
!= 0) {
11390 /* This means clear only the particular ospf process */
11391 if (instance
!= ospf_instance
)
11392 return CMD_NOT_MY_INSTANCE
;
11395 /* Clear all the ospf processes */
11396 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11397 if (!ospf
->oi_running
)
11400 if (nbr_id_str
&& IPV4_ADDR_SAME(&ospf
->router_id
, &nbr_id
)) {
11401 vty_out(vty
, "Self router-id is not allowed.\r\n ");
11402 return CMD_SUCCESS
;
11405 ospf_neighbor_reset(ospf
, nbr_id
, nbr_id_str
);
11408 return CMD_SUCCESS
;
11411 DEFPY (clear_ip_ospf_process
,
11412 clear_ip_ospf_process_cmd
,
11413 "clear ip ospf [(1-65535)]$instance process",
11416 "OSPF information\n"
11418 "Reset OSPF Process\n")
11420 struct listnode
*node
;
11421 struct ospf
*ospf
= NULL
;
11423 /* Check if instance is not passed as an argument */
11424 if (instance
!= 0) {
11425 /* This means clear only the particular ospf process */
11426 if (instance
!= ospf_instance
)
11427 return CMD_NOT_MY_INSTANCE
;
11430 /* Clear all the ospf processes */
11431 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11432 if (!ospf
->oi_running
)
11435 ospf_process_reset(ospf
);
11438 return CMD_SUCCESS
;
11441 static const char *const ospf_abr_type_str
[] = {
11442 "unknown", "standard", "ibm", "cisco", "shortcut"
11445 static const char *const ospf_shortcut_mode_str
[] = {
11446 "default", "enable", "disable"
11448 static int ospf_vty_external_rt_walkcb(struct hash_bucket
*bucket
,
11451 struct external_info
*ei
= bucket
->data
;
11452 struct vty
*vty
= (struct vty
*)arg
;
11453 static unsigned int count
;
11455 vty_out(vty
, "%-4pI4/%d, ", &ei
->p
.prefix
, ei
->p
.prefixlen
);
11458 if (count
% 5 == 0)
11459 vty_out(vty
, "\n");
11461 if (OSPF_EXTERNAL_RT_COUNT(ei
->aggr_route
) == count
)
11464 return HASHWALK_CONTINUE
;
11467 static int ospf_json_external_rt_walkcb(struct hash_bucket
*bucket
,
11470 struct external_info
*ei
= bucket
->data
;
11471 struct json_object
*json
= (struct json_object
*)arg
;
11472 char buf
[PREFIX2STR_BUFFER
];
11474 static unsigned int count
;
11476 prefix2str(&ei
->p
, buf
, sizeof(buf
));
11478 snprintf(exnalbuf
, 20, "Exnl Addr-%d", count
);
11480 json_object_string_add(json
, exnalbuf
, buf
);
11484 if (OSPF_EXTERNAL_RT_COUNT(ei
->aggr_route
) == count
)
11487 return HASHWALK_CONTINUE
;
11490 static int ospf_show_summary_address(struct vty
*vty
, struct ospf
*ospf
,
11491 uint8_t use_vrf
, json_object
*json
,
11492 bool uj
, bool detail
)
11494 struct route_node
*rn
;
11495 json_object
*json_vrf
= NULL
;
11498 static char header
[] =
11499 "Summary-address Metric-type Metric Tag External_Rt_count\n";
11501 mtype
= metric_type(ospf
, 0, ospf
->instance
);
11502 mval
= metric_value(ospf
, 0, ospf
->instance
);
11505 vty_out(vty
, "%s\n", header
);
11509 json_vrf
= json_object_new_object();
11514 if (ospf
->instance
) {
11516 json_object_int_add(json
, "ospfInstance",
11519 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
11522 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
11525 vty_out(vty
, "aggregation delay interval :%d(in seconds)\n\n",
11526 ospf
->aggr_delay_interval
);
11528 json_object_int_add(json_vrf
, "aggregation delay interval",
11529 ospf
->aggr_delay_interval
);
11531 for (rn
= route_top(ospf
->rt_aggr_tbl
); rn
; rn
= route_next(rn
))
11533 struct ospf_external_aggr_rt
*aggr
= rn
->info
;
11534 json_object
*json_aggr
= NULL
;
11535 char buf
[PREFIX2STR_BUFFER
];
11537 prefix2str(&aggr
->p
, buf
, sizeof(buf
));
11541 json_aggr
= json_object_new_object();
11543 json_object_object_add(json_vrf
, buf
,
11546 json_object_string_add(json_aggr
,
11547 "Summary address", buf
);
11549 json_object_string_add(
11550 json_aggr
, "Metric-type",
11551 (mtype
== EXTERNAL_METRIC_TYPE_1
)
11555 json_object_int_add(json_aggr
, "Metric", mval
);
11557 json_object_int_add(json_aggr
, "Tag",
11560 json_object_int_add(
11561 json_aggr
, "External route count",
11562 OSPF_EXTERNAL_RT_COUNT(aggr
));
11564 if (OSPF_EXTERNAL_RT_COUNT(aggr
) && detail
) {
11566 aggr
->match_extnl_hash
,
11567 ospf_json_external_rt_walkcb
,
11572 vty_out(vty
, "%-20s", buf
);
11574 (mtype
== EXTERNAL_METRIC_TYPE_1
)
11575 ? vty_out(vty
, "%-16s", "E1")
11576 : vty_out(vty
, "%-16s", "E2");
11577 vty_out(vty
, "%-11d", mval
);
11579 vty_out(vty
, "%-12u", aggr
->tag
);
11581 vty_out(vty
, "%-5ld\n",
11582 OSPF_EXTERNAL_RT_COUNT(aggr
));
11584 if (OSPF_EXTERNAL_RT_COUNT(aggr
) && detail
) {
11586 "Matched External routes:\n");
11588 aggr
->match_extnl_hash
,
11589 ospf_vty_external_rt_walkcb
,
11591 vty_out(vty
, "\n");
11594 vty_out(vty
, "\n");
11600 if (ospf
->vrf_id
== VRF_DEFAULT
)
11601 json_object_object_add(json
, "default",
11604 json_object_object_add(json
, ospf
->name
,
11608 vty_out(vty
, "\n");
11610 return CMD_SUCCESS
;
11613 DEFUN (show_ip_ospf_external_aggregator
,
11614 show_ip_ospf_external_aggregator_cmd
,
11615 "show ip ospf [vrf <NAME|all>] summary-address [detail] [json]",
11617 "OSPF information\n"
11620 "Show external summary addresses\n"
11621 "Detailed informtion\n"
11624 char *vrf_name
= NULL
;
11625 bool all_vrf
= false;
11626 int ret
= CMD_SUCCESS
;
11629 uint8_t use_vrf
= 0;
11630 bool uj
= use_json(argc
, argv
);
11631 struct ospf
*ospf
= NULL
;
11632 json_object
*json
= NULL
;
11633 struct listnode
*node
= NULL
;
11635 bool detail
= false;
11637 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
11639 if (argv_find(argv
, argc
, "detail", &idx
))
11643 json
= json_object_new_object();
11645 /* vrf input is provided */
11649 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
11650 if (!ospf
->oi_running
)
11652 ret
= ospf_show_summary_address(
11653 vty
, ospf
, use_vrf
, json
, uj
, detail
);
11657 vty_out(vty
, "%s\n",
11658 json_object_to_json_string_ext(
11659 json
, JSON_C_TO_STRING_PRETTY
));
11660 json_object_free(json
);
11666 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
11668 if (ospf
== NULL
|| !ospf
->oi_running
) {
11670 vty_out(vty
, "%s\n",
11671 json_object_to_json_string_ext(
11672 json
, JSON_C_TO_STRING_PRETTY
));
11673 json_object_free(json
);
11675 vty_out(vty
, "%% OSPF instance not found\n");
11677 return CMD_SUCCESS
;
11679 ospf_show_summary_address(vty
, ospf
, use_vrf
, json
, uj
, detail
);
11683 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
11684 if (ospf
== NULL
|| !ospf
->oi_running
) {
11686 vty_out(vty
, "%s\n",
11687 json_object_to_json_string_ext(
11688 json
, JSON_C_TO_STRING_PRETTY
));
11689 json_object_free(json
);
11691 vty_out(vty
, "%% OSPF instance not found\n");
11693 return CMD_SUCCESS
;
11696 ospf_show_summary_address(vty
, ospf
, use_vrf
, json
, uj
, detail
);
11700 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
11701 json
, JSON_C_TO_STRING_PRETTY
));
11702 json_object_free(json
);
11704 return CMD_SUCCESS
;
11707 static const char *const ospf_int_type_str
[] = {
11708 "unknown", /* should never be used. */
11712 "point-to-multipoint",
11713 "virtual-link", /* should never be used. */
11717 static const char *interface_config_auth_str(struct ospf_if_params
*params
)
11719 if (!OSPF_IF_PARAM_CONFIGURED(params
, auth_type
)
11720 || params
->auth_type
== OSPF_AUTH_NOTSET
)
11723 /* Translation tables are not that much help
11724 * here due to syntax
11725 * of the simple option */
11726 switch (params
->auth_type
) {
11728 case OSPF_AUTH_NULL
:
11731 case OSPF_AUTH_SIMPLE
:
11734 case OSPF_AUTH_CRYPTOGRAPHIC
:
11735 return " message-digest";
11741 static int config_write_interface_one(struct vty
*vty
, struct vrf
*vrf
)
11743 struct listnode
*node
;
11744 struct interface
*ifp
;
11745 struct crypt_key
*ck
;
11746 struct route_node
*rn
= NULL
;
11747 struct ospf_if_params
*params
;
11748 const char *auth_str
;
11751 FOR_ALL_INTERFACES (vrf
, ifp
) {
11753 if (memcmp(ifp
->name
, "VLINK", 5) == 0)
11756 vty_frame(vty
, "!\n");
11757 if (ifp
->vrf_id
== VRF_DEFAULT
)
11758 vty_frame(vty
, "interface %s\n", ifp
->name
);
11760 vty_frame(vty
, "interface %s vrf %s\n", ifp
->name
,
11763 vty_out(vty
, " description %s\n", ifp
->desc
);
11767 params
= IF_DEF_PARAMS(ifp
);
11770 /* Interface Network print. */
11771 if (OSPF_IF_PARAM_CONFIGURED(params
, type
)
11772 && params
->type
!= OSPF_IFTYPE_LOOPBACK
) {
11773 if (params
->type
!= ospf_default_iftype(ifp
)) {
11774 vty_out(vty
, " ip ospf network %s",
11778 == OSPF_IFTYPE_POINTOPOINT
11779 && params
->ptp_dmvpn
)
11780 vty_out(vty
, " dmvpn");
11781 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11782 vty_out(vty
, " %pI4",
11784 vty_out(vty
, "\n");
11788 /* OSPF interface authentication print */
11789 auth_str
= interface_config_auth_str(params
);
11791 vty_out(vty
, " ip ospf authentication%s",
11793 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11794 vty_out(vty
, " %pI4",
11796 vty_out(vty
, "\n");
11799 /* Simple Authentication Password print. */
11800 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_simple
)
11801 && params
->auth_simple
[0] != '\0') {
11802 vty_out(vty
, " ip ospf authentication-key %s",
11803 params
->auth_simple
);
11804 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11805 vty_out(vty
, " %pI4",
11807 vty_out(vty
, "\n");
11810 /* Cryptographic Authentication Key print. */
11811 if (params
&& params
->auth_crypt
) {
11812 for (ALL_LIST_ELEMENTS_RO(params
->auth_crypt
,
11815 " ip ospf message-digest-key %d md5 %s",
11816 ck
->key_id
, ck
->auth_key
);
11817 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11818 vty_out(vty
, " %pI4",
11820 vty_out(vty
, "\n");
11824 /* Interface Output Cost print. */
11825 if (OSPF_IF_PARAM_CONFIGURED(params
, output_cost_cmd
)) {
11826 vty_out(vty
, " ip ospf cost %u",
11827 params
->output_cost_cmd
);
11828 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11829 vty_out(vty
, " %pI4",
11831 vty_out(vty
, "\n");
11834 /* Hello Interval print. */
11835 if (OSPF_IF_PARAM_CONFIGURED(params
, v_hello
)
11836 && params
->v_hello
!= OSPF_HELLO_INTERVAL_DEFAULT
) {
11837 vty_out(vty
, " ip ospf hello-interval %u",
11839 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11840 vty_out(vty
, " %pI4",
11842 vty_out(vty
, "\n");
11846 /* Router Dead Interval print. */
11847 if (OSPF_IF_PARAM_CONFIGURED(params
, v_wait
)
11848 && params
->is_v_wait_set
11850 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
) {
11851 vty_out(vty
, " ip ospf dead-interval ");
11854 if (OSPF_IF_PARAM_CONFIGURED(params
,
11857 "minimal hello-multiplier %d",
11858 params
->fast_hello
);
11860 vty_out(vty
, "%u", params
->v_wait
);
11862 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11863 vty_out(vty
, " %pI4",
11865 vty_out(vty
, "\n");
11868 /* Router Priority print. */
11869 if (OSPF_IF_PARAM_CONFIGURED(params
, priority
)
11870 && params
->priority
11871 != OSPF_ROUTER_PRIORITY_DEFAULT
) {
11872 vty_out(vty
, " ip ospf priority %u",
11874 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11875 vty_out(vty
, " %pI4",
11877 vty_out(vty
, "\n");
11880 /* Retransmit Interval print. */
11881 if (OSPF_IF_PARAM_CONFIGURED(params
,
11882 retransmit_interval
)
11883 && params
->retransmit_interval
11884 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
) {
11885 vty_out(vty
, " ip ospf retransmit-interval %u",
11886 params
->retransmit_interval
);
11887 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11888 vty_out(vty
, " %pI4",
11890 vty_out(vty
, "\n");
11893 /* Transmit Delay print. */
11894 if (OSPF_IF_PARAM_CONFIGURED(params
, transmit_delay
)
11895 && params
->transmit_delay
11896 != OSPF_TRANSMIT_DELAY_DEFAULT
) {
11897 vty_out(vty
, " ip ospf transmit-delay %u",
11898 params
->transmit_delay
);
11899 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11900 vty_out(vty
, " %pI4",
11902 vty_out(vty
, "\n");
11906 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
11908 vty_out(vty
, " ip ospf %d",
11911 vty_out(vty
, " ip ospf");
11913 char buf
[INET_ADDRSTRLEN
];
11915 area_id2str(buf
, sizeof(buf
), ¶ms
->if_area
,
11916 params
->if_area_id_fmt
);
11917 vty_out(vty
, " area %s", buf
);
11918 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11919 vty_out(vty
, " %pI4",
11921 vty_out(vty
, "\n");
11925 if (params
&& params
->bfd_config
)
11926 ospf_bfd_write_config(vty
, params
);
11928 /* MTU ignore print. */
11929 if (OSPF_IF_PARAM_CONFIGURED(params
, mtu_ignore
)
11930 && params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
) {
11931 if (params
->mtu_ignore
== 0)
11932 vty_out(vty
, " no ip ospf mtu-ignore");
11934 vty_out(vty
, " ip ospf mtu-ignore");
11935 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11936 vty_out(vty
, " %pI4",
11938 vty_out(vty
, "\n");
11941 if (OSPF_IF_PARAM_CONFIGURED(params
,
11942 passive_interface
)) {
11943 vty_out(vty
, " %sip ospf passive",
11944 params
->passive_interface
11948 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
11949 vty_out(vty
, " %pI4", &rn
->p
.u
.prefix4
);
11950 vty_out(vty
, "\n");
11953 /* LDP-Sync print */
11954 if (params
&& params
->ldp_sync_info
)
11955 ospf_ldp_sync_if_write_config(vty
, params
);
11959 rn
= route_top(IF_OIFS_PARAMS(ifp
));
11961 rn
= route_next(rn
);
11966 if (params
!= NULL
)
11971 ospf_opaque_config_write_if(vty
, ifp
);
11973 vty_endframe(vty
, NULL
);
11979 /* Configuration write function for ospfd. */
11980 static int config_write_interface(struct vty
*vty
)
11983 struct vrf
*vrf
= NULL
;
11985 /* Display all VRF aware OSPF interface configuration */
11986 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
11987 write
+= config_write_interface_one(vty
, vrf
);
11993 static int config_write_network_area(struct vty
*vty
, struct ospf
*ospf
)
11995 struct route_node
*rn
;
11996 char buf
[INET_ADDRSTRLEN
];
11998 /* `network area' print. */
11999 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
))
12001 struct ospf_network
*n
= rn
->info
;
12003 /* Create Area ID string by specified Area ID format. */
12004 if (n
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
12005 inet_ntop(AF_INET
, &n
->area_id
, buf
,
12008 snprintf(buf
, sizeof(buf
), "%lu",
12009 (unsigned long int)ntohl(
12010 n
->area_id
.s_addr
));
12012 /* Network print. */
12013 vty_out(vty
, " network %pFX area %s\n", &rn
->p
, buf
);
12019 static int config_write_ospf_area(struct vty
*vty
, struct ospf
*ospf
)
12021 struct listnode
*node
;
12022 struct ospf_area
*area
;
12023 char buf
[INET_ADDRSTRLEN
];
12025 /* Area configuration print. */
12026 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
12027 struct route_node
*rn1
;
12029 area_id2str(buf
, sizeof(buf
), &area
->area_id
,
12030 area
->area_id_fmt
);
12032 if (area
->auth_type
!= OSPF_AUTH_NULL
) {
12033 if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
12034 vty_out(vty
, " area %s authentication\n", buf
);
12037 " area %s authentication message-digest\n",
12041 if (area
->shortcut_configured
!= OSPF_SHORTCUT_DEFAULT
)
12042 vty_out(vty
, " area %s shortcut %s\n", buf
,
12043 ospf_shortcut_mode_str
12044 [area
->shortcut_configured
]);
12046 if ((area
->external_routing
== OSPF_AREA_STUB
)
12047 || (area
->external_routing
== OSPF_AREA_NSSA
)) {
12048 if (area
->external_routing
== OSPF_AREA_STUB
) {
12049 vty_out(vty
, " area %s stub", buf
);
12050 if (area
->no_summary
)
12051 vty_out(vty
, " no-summary\n");
12052 vty_out(vty
, "\n");
12053 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
12054 switch (area
->NSSATranslatorRole
) {
12055 case OSPF_NSSA_ROLE_NEVER
:
12057 " area %s nssa translate-never\n",
12060 case OSPF_NSSA_ROLE_ALWAYS
:
12062 " area %s nssa translate-always\n",
12065 case OSPF_NSSA_ROLE_CANDIDATE
:
12066 vty_out(vty
, " area %s nssa \n", buf
);
12069 if (area
->no_summary
)
12071 " area %s nssa no-summary\n",
12073 if (area
->suppress_fa
)
12075 " area %s nssa suppress-fa\n",
12079 if (area
->default_cost
!= 1)
12080 vty_out(vty
, " area %s default-cost %d\n", buf
,
12081 area
->default_cost
);
12084 for (rn1
= route_top(area
->ranges
); rn1
; rn1
= route_next(rn1
))
12086 struct ospf_area_range
*range
= rn1
->info
;
12088 vty_out(vty
, " area %s range %pFX", buf
,
12091 if (range
->cost_config
12092 != OSPF_AREA_RANGE_COST_UNSPEC
)
12093 vty_out(vty
, " cost %d",
12094 range
->cost_config
);
12096 if (!CHECK_FLAG(range
->flags
,
12097 OSPF_AREA_RANGE_ADVERTISE
))
12098 vty_out(vty
, " not-advertise");
12100 if (CHECK_FLAG(range
->flags
,
12101 OSPF_AREA_RANGE_SUBSTITUTE
))
12102 vty_out(vty
, " substitute %pI4/%d",
12103 &range
->subst_addr
,
12104 range
->subst_masklen
);
12106 vty_out(vty
, "\n");
12109 if (EXPORT_NAME(area
))
12110 vty_out(vty
, " area %s export-list %s\n", buf
,
12111 EXPORT_NAME(area
));
12113 if (IMPORT_NAME(area
))
12114 vty_out(vty
, " area %s import-list %s\n", buf
,
12115 IMPORT_NAME(area
));
12117 if (PREFIX_NAME_IN(area
))
12118 vty_out(vty
, " area %s filter-list prefix %s in\n", buf
,
12119 PREFIX_NAME_IN(area
));
12121 if (PREFIX_NAME_OUT(area
))
12122 vty_out(vty
, " area %s filter-list prefix %s out\n",
12123 buf
, PREFIX_NAME_OUT(area
));
12129 static int config_write_ospf_nbr_nbma(struct vty
*vty
, struct ospf
*ospf
)
12131 struct ospf_nbr_nbma
*nbr_nbma
;
12132 struct route_node
*rn
;
12134 /* Static Neighbor configuration print. */
12135 for (rn
= route_top(ospf
->nbr_nbma
); rn
; rn
= route_next(rn
))
12136 if ((nbr_nbma
= rn
->info
)) {
12137 vty_out(vty
, " neighbor %pI4", &nbr_nbma
->addr
);
12139 if (nbr_nbma
->priority
12140 != OSPF_NEIGHBOR_PRIORITY_DEFAULT
)
12141 vty_out(vty
, " priority %d",
12142 nbr_nbma
->priority
);
12144 if (nbr_nbma
->v_poll
!= OSPF_POLL_INTERVAL_DEFAULT
)
12145 vty_out(vty
, " poll-interval %d",
12148 vty_out(vty
, "\n");
12154 static int config_write_virtual_link(struct vty
*vty
, struct ospf
*ospf
)
12156 struct listnode
*node
;
12157 struct ospf_vl_data
*vl_data
;
12158 const char *auth_str
;
12159 char buf
[INET_ADDRSTRLEN
];
12161 /* Virtual-Link print */
12162 for (ALL_LIST_ELEMENTS_RO(ospf
->vlinks
, node
, vl_data
)) {
12163 struct listnode
*n2
;
12164 struct crypt_key
*ck
;
12165 struct ospf_interface
*oi
;
12167 if (vl_data
!= NULL
) {
12168 area_id2str(buf
, sizeof(buf
), &vl_data
->vl_area_id
,
12169 vl_data
->vl_area_id_fmt
);
12170 oi
= vl_data
->vl_oi
;
12173 if (OSPF_IF_PARAM(oi
, v_hello
)
12174 != OSPF_HELLO_INTERVAL_DEFAULT
12175 || OSPF_IF_PARAM(oi
, v_wait
)
12176 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
12177 || OSPF_IF_PARAM(oi
, retransmit_interval
)
12178 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
12179 || OSPF_IF_PARAM(oi
, transmit_delay
)
12180 != OSPF_TRANSMIT_DELAY_DEFAULT
)
12182 " area %s virtual-link %pI4 hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n",
12183 buf
, &vl_data
->vl_peer
,
12184 OSPF_IF_PARAM(oi
, v_hello
),
12185 OSPF_IF_PARAM(oi
, retransmit_interval
),
12186 OSPF_IF_PARAM(oi
, transmit_delay
),
12187 OSPF_IF_PARAM(oi
, v_wait
));
12189 vty_out(vty
, " area %s virtual-link %pI4\n", buf
,
12190 &vl_data
->vl_peer
);
12192 auth_str
= interface_config_auth_str(
12193 IF_DEF_PARAMS(oi
->ifp
));
12196 " area %s virtual-link %pI4 authentication%s\n",
12197 buf
, &vl_data
->vl_peer
, auth_str
);
12199 if (IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)->auth_simple
[0]
12202 " area %s virtual-link %pI4 authentication-key %s\n",
12203 buf
, &vl_data
->vl_peer
,
12204 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
12207 for (ALL_LIST_ELEMENTS_RO(
12208 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
12212 " area %s virtual-link %pI4 message-digest-key %d md5 %s\n",
12213 buf
, &vl_data
->vl_peer
,
12214 ck
->key_id
, ck
->auth_key
);
12222 static int config_write_ospf_redistribute(struct vty
*vty
, struct ospf
*ospf
)
12226 /* redistribute print. */
12227 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
12228 struct list
*red_list
;
12229 struct listnode
*node
;
12230 struct ospf_redist
*red
;
12232 red_list
= ospf
->redist
[type
];
12236 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
12237 vty_out(vty
, " redistribute %s",
12238 zebra_route_string(type
));
12240 vty_out(vty
, " %d", red
->instance
);
12242 if (red
->dmetric
.value
>= 0)
12243 vty_out(vty
, " metric %d", red
->dmetric
.value
);
12245 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
12246 vty_out(vty
, " metric-type 1");
12248 if (ROUTEMAP_NAME(red
))
12249 vty_out(vty
, " route-map %s",
12250 ROUTEMAP_NAME(red
));
12252 vty_out(vty
, "\n");
12259 static int ospf_cfg_write_helper_dis_rtr_walkcb(struct hash_bucket
*bucket
,
12262 struct advRtr
*rtr
= bucket
->data
;
12263 struct vty
*vty
= (struct vty
*)arg
;
12265 vty_out(vty
, " graceful-restart helper-only %pI4\n",
12267 return HASHWALK_CONTINUE
;
12270 static void config_write_ospf_gr(struct vty
*vty
, struct ospf
*ospf
)
12272 if (!ospf
->gr_info
.restart_support
)
12275 if (ospf
->gr_info
.grace_period
== OSPF_DFLT_GRACE_INTERVAL
)
12276 vty_out(vty
, " graceful-restart\n");
12278 vty_out(vty
, " graceful-restart grace-period %u\n",
12279 ospf
->gr_info
.grace_period
);
12282 static int config_write_ospf_gr_helper(struct vty
*vty
, struct ospf
*ospf
)
12284 if (ospf
->is_helper_supported
)
12285 vty_out(vty
, " graceful-restart helper-only\n");
12287 if (!ospf
->strict_lsa_check
)
12289 " no graceful-restart helper strict-lsa-checking\n");
12291 if (ospf
->only_planned_restart
)
12292 vty_out(vty
, " graceful-restart helper planned-only\n");
12294 if (ospf
->supported_grace_time
!= OSPF_MAX_GRACE_INTERVAL
)
12296 " graceful-restart helper supported-grace-time %d\n",
12297 ospf
->supported_grace_time
);
12299 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf
)) {
12300 hash_walk(ospf
->enable_rtr_list
,
12301 ospf_cfg_write_helper_dis_rtr_walkcb
, vty
);
12306 static int config_write_ospf_external_aggregator(struct vty
*vty
,
12309 struct route_node
*rn
;
12311 /* print 'summary-address A.B.C.D/M' */
12312 for (rn
= route_top(ospf
->rt_aggr_tbl
); rn
; rn
= route_next(rn
))
12314 struct ospf_external_aggr_rt
*aggr
= rn
->info
;
12316 vty_out(vty
, " summary-address %pI4/%d ",
12317 &aggr
->p
.prefix
, aggr
->p
.prefixlen
);
12319 vty_out(vty
, " tag %u ", aggr
->tag
);
12321 if (CHECK_FLAG(aggr
->flags
,
12322 OSPF_EXTERNAL_AGGRT_NO_ADVERTISE
))
12323 vty_out(vty
, " no-advertise");
12325 vty_out(vty
, "\n");
12331 static int config_write_ospf_default_metric(struct vty
*vty
, struct ospf
*ospf
)
12333 if (ospf
->default_metric
!= -1)
12334 vty_out(vty
, " default-metric %d\n", ospf
->default_metric
);
12338 static int config_write_ospf_distribute(struct vty
*vty
, struct ospf
*ospf
)
12341 struct ospf_redist
*red
;
12344 /* distribute-list print. */
12345 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
12346 if (DISTRIBUTE_NAME(ospf
, type
))
12347 vty_out(vty
, " distribute-list %s out %s\n",
12348 DISTRIBUTE_NAME(ospf
, type
),
12349 zebra_route_string(type
));
12351 /* default-information print. */
12352 if (ospf
->default_originate
!= DEFAULT_ORIGINATE_NONE
) {
12353 vty_out(vty
, " default-information originate");
12354 if (ospf
->default_originate
== DEFAULT_ORIGINATE_ALWAYS
)
12355 vty_out(vty
, " always");
12357 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
12359 if (red
->dmetric
.value
>= 0)
12360 vty_out(vty
, " metric %d",
12361 red
->dmetric
.value
);
12363 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
12364 vty_out(vty
, " metric-type 1");
12366 if (ROUTEMAP_NAME(red
))
12367 vty_out(vty
, " route-map %s",
12368 ROUTEMAP_NAME(red
));
12371 vty_out(vty
, "\n");
12378 static int config_write_ospf_distance(struct vty
*vty
, struct ospf
*ospf
)
12380 struct route_node
*rn
;
12381 struct ospf_distance
*odistance
;
12383 if (ospf
->distance_all
)
12384 vty_out(vty
, " distance %d\n", ospf
->distance_all
);
12386 if (ospf
->distance_intra
|| ospf
->distance_inter
12387 || ospf
->distance_external
) {
12388 vty_out(vty
, " distance ospf");
12390 if (ospf
->distance_intra
)
12391 vty_out(vty
, " intra-area %d", ospf
->distance_intra
);
12392 if (ospf
->distance_inter
)
12393 vty_out(vty
, " inter-area %d", ospf
->distance_inter
);
12394 if (ospf
->distance_external
)
12395 vty_out(vty
, " external %d", ospf
->distance_external
);
12397 vty_out(vty
, "\n");
12400 for (rn
= route_top(ospf
->distance_table
); rn
; rn
= route_next(rn
))
12401 if ((odistance
= rn
->info
) != NULL
) {
12402 vty_out(vty
, " distance %d %pFX %s\n",
12403 odistance
->distance
, &rn
->p
,
12404 odistance
->access_list
? odistance
->access_list
12410 static int ospf_config_write_one(struct vty
*vty
, struct ospf
*ospf
)
12414 /* `router ospf' print. */
12415 if (ospf
->instance
&& ospf
->name
) {
12416 vty_out(vty
, "router ospf %d vrf %s\n", ospf
->instance
,
12418 } else if (ospf
->instance
) {
12419 vty_out(vty
, "router ospf %d\n", ospf
->instance
);
12420 } else if (ospf
->name
) {
12421 vty_out(vty
, "router ospf vrf %s\n", ospf
->name
);
12423 vty_out(vty
, "router ospf\n");
12425 if (!ospf
->networks
) {
12430 /* Router ID print. */
12431 if (ospf
->router_id_static
.s_addr
!= INADDR_ANY
)
12432 vty_out(vty
, " ospf router-id %pI4\n",
12433 &ospf
->router_id_static
);
12435 /* ABR type print. */
12436 if (ospf
->abr_type
!= OSPF_ABR_DEFAULT
)
12437 vty_out(vty
, " ospf abr-type %s\n",
12438 ospf_abr_type_str
[ospf
->abr_type
]);
12440 /* log-adjacency-changes flag print. */
12441 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
12442 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
))
12443 vty_out(vty
, " log-adjacency-changes detail\n");
12444 else if (!SAVE_OSPF_LOG_ADJACENCY_CHANGES
)
12445 vty_out(vty
, " log-adjacency-changes\n");
12446 } else if (SAVE_OSPF_LOG_ADJACENCY_CHANGES
) {
12447 vty_out(vty
, " no log-adjacency-changes\n");
12450 /* RFC1583 compatibility flag print -- Compatible with CISCO
12452 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
))
12453 vty_out(vty
, " compatible rfc1583\n");
12455 /* auto-cost reference-bandwidth configuration. */
12456 if (ospf
->ref_bandwidth
!= OSPF_DEFAULT_REF_BANDWIDTH
) {
12458 "! Important: ensure reference bandwidth is consistent across all routers\n");
12459 vty_out(vty
, " auto-cost reference-bandwidth %d\n",
12460 ospf
->ref_bandwidth
);
12463 /* SPF timers print. */
12464 if (ospf
->spf_delay
!= OSPF_SPF_DELAY_DEFAULT
12465 || ospf
->spf_holdtime
!= OSPF_SPF_HOLDTIME_DEFAULT
12466 || ospf
->spf_max_holdtime
!= OSPF_SPF_MAX_HOLDTIME_DEFAULT
)
12467 vty_out(vty
, " timers throttle spf %d %d %d\n", ospf
->spf_delay
,
12468 ospf
->spf_holdtime
, ospf
->spf_max_holdtime
);
12470 /* LSA timers print. */
12471 if (ospf
->min_ls_interval
!= OSPF_MIN_LS_INTERVAL
)
12472 vty_out(vty
, " timers throttle lsa all %d\n",
12473 ospf
->min_ls_interval
);
12474 if (ospf
->min_ls_arrival
!= OSPF_MIN_LS_ARRIVAL
)
12475 vty_out(vty
, " timers lsa min-arrival %d\n",
12476 ospf
->min_ls_arrival
);
12478 /* Write multiplier print. */
12479 if (ospf
->write_oi_count
!= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
)
12480 vty_out(vty
, " ospf write-multiplier %d\n",
12481 ospf
->write_oi_count
);
12483 if (ospf
->max_multipath
!= MULTIPATH_NUM
)
12484 vty_out(vty
, " maximum-paths %d\n", ospf
->max_multipath
);
12486 /* Max-metric router-lsa print */
12487 config_write_stub_router(vty
, ospf
);
12489 /* SPF refresh parameters print. */
12490 if (ospf
->lsa_refresh_interval
!= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
12491 vty_out(vty
, " refresh timer %d\n", ospf
->lsa_refresh_interval
);
12493 /* Redistribute information print. */
12494 config_write_ospf_redistribute(vty
, ospf
);
12496 /* Graceful Restart print */
12497 config_write_ospf_gr(vty
, ospf
);
12498 config_write_ospf_gr_helper(vty
, ospf
);
12500 /* Print external route aggregation. */
12501 config_write_ospf_external_aggregator(vty
, ospf
);
12503 /* passive-interface print. */
12504 if (ospf
->passive_interface_default
== OSPF_IF_PASSIVE
)
12505 vty_out(vty
, " passive-interface default\n");
12507 /* proactive-arp print. */
12508 if (ospf
->proactive_arp
!= OSPF_PROACTIVE_ARP_DEFAULT
) {
12509 if (ospf
->proactive_arp
)
12510 vty_out(vty
, " proactive-arp\n");
12512 vty_out(vty
, " no proactive-arp\n");
12515 /* TI-LFA print. */
12516 if (ospf
->ti_lfa_enabled
) {
12517 if (ospf
->ti_lfa_protection_type
== OSPF_TI_LFA_NODE_PROTECTION
)
12518 vty_out(vty
, " fast-reroute ti-lfa node-protection\n");
12520 vty_out(vty
, " fast-reroute ti-lfa\n");
12523 /* Network area print. */
12524 config_write_network_area(vty
, ospf
);
12526 /* Area config print. */
12527 config_write_ospf_area(vty
, ospf
);
12529 /* static neighbor print. */
12530 config_write_ospf_nbr_nbma(vty
, ospf
);
12532 /* Virtual-Link print. */
12533 config_write_virtual_link(vty
, ospf
);
12535 /* Default metric configuration. */
12536 config_write_ospf_default_metric(vty
, ospf
);
12538 /* Distribute-list and default-information print. */
12539 config_write_ospf_distribute(vty
, ospf
);
12541 /* Distance configuration. */
12542 config_write_ospf_distance(vty
, ospf
);
12544 ospf_opaque_config_write_router(vty
, ospf
);
12546 /* LDP-Sync print */
12547 ospf_ldp_sync_write_config(vty
, ospf
);
12553 /* OSPF configuration write function. */
12554 static int ospf_config_write(struct vty
*vty
)
12557 struct listnode
*ospf_node
= NULL
;
12560 if (listcount(om
->ospf
) == 0)
12563 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, ospf_node
, ospf
)) {
12564 /* VRF Default check if it is running.
12565 * Upon daemon start, there could be default instance
12566 * in absence of 'router ospf'/oi_running is disabled. */
12567 if (ospf
->vrf_id
== VRF_DEFAULT
&& ospf
->oi_running
)
12568 write
+= ospf_config_write_one(vty
, ospf
);
12569 /* For Non-Default VRF simply display the configuration,
12570 * even if it is not oi_running. */
12571 else if (ospf
->vrf_id
!= VRF_DEFAULT
)
12572 write
+= ospf_config_write_one(vty
, ospf
);
12577 void ospf_vty_show_init(void)
12579 /* "show ip ospf" commands. */
12580 install_element(VIEW_NODE
, &show_ip_ospf_cmd
);
12582 install_element(VIEW_NODE
, &show_ip_ospf_instance_cmd
);
12584 /* "show ip ospf database" commands. */
12585 install_element(VIEW_NODE
, &show_ip_ospf_database_cmd
);
12586 install_element(VIEW_NODE
, &show_ip_ospf_database_max_cmd
);
12587 install_element(VIEW_NODE
,
12588 &show_ip_ospf_database_type_adv_router_cmd
);
12589 install_element(VIEW_NODE
,
12590 &show_ip_ospf_instance_database_type_adv_router_cmd
);
12591 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_cmd
);
12592 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_max_cmd
);
12594 /* "show ip ospf interface" commands. */
12595 install_element(VIEW_NODE
, &show_ip_ospf_interface_cmd
);
12597 install_element(VIEW_NODE
, &show_ip_ospf_instance_interface_cmd
);
12598 /* "show ip ospf interface traffic */
12599 install_element(VIEW_NODE
, &show_ip_ospf_interface_traffic_cmd
);
12601 /* "show ip ospf neighbor" commands. */
12602 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_detail_cmd
);
12603 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_cmd
);
12604 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_id_cmd
);
12605 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_all_cmd
);
12606 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_cmd
);
12607 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_cmd
);
12608 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_all_cmd
);
12610 install_element(VIEW_NODE
,
12611 &show_ip_ospf_instance_neighbor_int_detail_cmd
);
12612 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_int_cmd
);
12613 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_id_cmd
);
12614 install_element(VIEW_NODE
,
12615 &show_ip_ospf_instance_neighbor_detail_all_cmd
);
12616 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_detail_cmd
);
12617 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_cmd
);
12618 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_all_cmd
);
12620 /* "show ip ospf route" commands. */
12621 install_element(VIEW_NODE
, &show_ip_ospf_route_cmd
);
12622 install_element(VIEW_NODE
, &show_ip_ospf_border_routers_cmd
);
12624 install_element(VIEW_NODE
, &show_ip_ospf_instance_route_cmd
);
12625 install_element(VIEW_NODE
, &show_ip_ospf_instance_border_routers_cmd
);
12627 /* "show ip ospf vrfs" commands. */
12628 install_element(VIEW_NODE
, &show_ip_ospf_vrfs_cmd
);
12630 /* "show ip ospf gr-helper details" command */
12631 install_element(VIEW_NODE
, &show_ip_ospf_gr_helper_cmd
);
12633 /* "show ip ospf summary-address" command */
12634 install_element(VIEW_NODE
, &show_ip_ospf_external_aggregator_cmd
);
12637 /* Initialization of OSPF interface. */
12638 static void ospf_vty_if_init(void)
12640 /* Install interface node. */
12641 if_cmd_init(config_write_interface
);
12643 /* "ip ospf authentication" commands. */
12644 install_element(INTERFACE_NODE
, &ip_ospf_authentication_args_addr_cmd
);
12645 install_element(INTERFACE_NODE
, &ip_ospf_authentication_addr_cmd
);
12646 install_element(INTERFACE_NODE
,
12647 &no_ip_ospf_authentication_args_addr_cmd
);
12648 install_element(INTERFACE_NODE
, &no_ip_ospf_authentication_addr_cmd
);
12649 install_element(INTERFACE_NODE
, &ip_ospf_authentication_key_addr_cmd
);
12650 install_element(INTERFACE_NODE
,
12651 &no_ip_ospf_authentication_key_authkey_addr_cmd
);
12652 install_element(INTERFACE_NODE
,
12653 &no_ospf_authentication_key_authkey_addr_cmd
);
12655 /* "ip ospf message-digest-key" commands. */
12656 install_element(INTERFACE_NODE
, &ip_ospf_message_digest_key_cmd
);
12657 install_element(INTERFACE_NODE
, &no_ip_ospf_message_digest_key_cmd
);
12659 /* "ip ospf cost" commands. */
12660 install_element(INTERFACE_NODE
, &ip_ospf_cost_cmd
);
12661 install_element(INTERFACE_NODE
, &no_ip_ospf_cost_cmd
);
12663 /* "ip ospf mtu-ignore" commands. */
12664 install_element(INTERFACE_NODE
, &ip_ospf_mtu_ignore_addr_cmd
);
12665 install_element(INTERFACE_NODE
, &no_ip_ospf_mtu_ignore_addr_cmd
);
12667 /* "ip ospf dead-interval" commands. */
12668 install_element(INTERFACE_NODE
, &ip_ospf_dead_interval_cmd
);
12669 install_element(INTERFACE_NODE
,
12670 &ip_ospf_dead_interval_minimal_addr_cmd
);
12671 install_element(INTERFACE_NODE
, &no_ip_ospf_dead_interval_cmd
);
12673 /* "ip ospf hello-interval" commands. */
12674 install_element(INTERFACE_NODE
, &ip_ospf_hello_interval_cmd
);
12675 install_element(INTERFACE_NODE
, &no_ip_ospf_hello_interval_cmd
);
12677 /* "ip ospf network" commands. */
12678 install_element(INTERFACE_NODE
, &ip_ospf_network_cmd
);
12679 install_element(INTERFACE_NODE
, &no_ip_ospf_network_cmd
);
12681 /* "ip ospf priority" commands. */
12682 install_element(INTERFACE_NODE
, &ip_ospf_priority_cmd
);
12683 install_element(INTERFACE_NODE
, &no_ip_ospf_priority_cmd
);
12685 /* "ip ospf retransmit-interval" commands. */
12686 install_element(INTERFACE_NODE
, &ip_ospf_retransmit_interval_addr_cmd
);
12687 install_element(INTERFACE_NODE
,
12688 &no_ip_ospf_retransmit_interval_addr_cmd
);
12690 /* "ip ospf transmit-delay" commands. */
12691 install_element(INTERFACE_NODE
, &ip_ospf_transmit_delay_addr_cmd
);
12692 install_element(INTERFACE_NODE
, &no_ip_ospf_transmit_delay_addr_cmd
);
12694 /* "ip ospf area" commands. */
12695 install_element(INTERFACE_NODE
, &ip_ospf_area_cmd
);
12696 install_element(INTERFACE_NODE
, &no_ip_ospf_area_cmd
);
12698 /* "ip ospf passive" commands. */
12699 install_element(INTERFACE_NODE
, &ip_ospf_passive_cmd
);
12700 install_element(INTERFACE_NODE
, &no_ip_ospf_passive_cmd
);
12702 /* These commands are compatibitliy for previous version. */
12703 install_element(INTERFACE_NODE
, &ospf_authentication_key_cmd
);
12704 install_element(INTERFACE_NODE
, &ospf_message_digest_key_cmd
);
12705 install_element(INTERFACE_NODE
, &no_ospf_message_digest_key_cmd
);
12706 install_element(INTERFACE_NODE
, &ospf_dead_interval_cmd
);
12707 install_element(INTERFACE_NODE
, &no_ospf_dead_interval_cmd
);
12708 install_element(INTERFACE_NODE
, &ospf_hello_interval_cmd
);
12709 install_element(INTERFACE_NODE
, &no_ospf_hello_interval_cmd
);
12710 install_element(INTERFACE_NODE
, &ospf_cost_cmd
);
12711 install_element(INTERFACE_NODE
, &no_ospf_cost_cmd
);
12712 install_element(INTERFACE_NODE
, &ospf_network_cmd
);
12713 install_element(INTERFACE_NODE
, &no_ospf_network_cmd
);
12714 install_element(INTERFACE_NODE
, &ospf_priority_cmd
);
12715 install_element(INTERFACE_NODE
, &no_ospf_priority_cmd
);
12716 install_element(INTERFACE_NODE
, &ospf_retransmit_interval_cmd
);
12717 install_element(INTERFACE_NODE
, &no_ospf_retransmit_interval_cmd
);
12718 install_element(INTERFACE_NODE
, &ospf_transmit_delay_cmd
);
12719 install_element(INTERFACE_NODE
, &no_ospf_transmit_delay_cmd
);
12722 static void ospf_vty_zebra_init(void)
12724 install_element(OSPF_NODE
, &ospf_redistribute_source_cmd
);
12725 install_element(OSPF_NODE
, &no_ospf_redistribute_source_cmd
);
12726 install_element(OSPF_NODE
, &ospf_redistribute_instance_source_cmd
);
12727 install_element(OSPF_NODE
, &no_ospf_redistribute_instance_source_cmd
);
12729 install_element(OSPF_NODE
, &ospf_distribute_list_out_cmd
);
12730 install_element(OSPF_NODE
, &no_ospf_distribute_list_out_cmd
);
12732 install_element(OSPF_NODE
, &ospf_default_information_originate_cmd
);
12733 install_element(OSPF_NODE
, &no_ospf_default_information_originate_cmd
);
12735 install_element(OSPF_NODE
, &ospf_default_metric_cmd
);
12736 install_element(OSPF_NODE
, &no_ospf_default_metric_cmd
);
12738 install_element(OSPF_NODE
, &ospf_distance_cmd
);
12739 install_element(OSPF_NODE
, &no_ospf_distance_cmd
);
12740 install_element(OSPF_NODE
, &no_ospf_distance_ospf_cmd
);
12741 install_element(OSPF_NODE
, &ospf_distance_ospf_cmd
);
12743 /*Ospf garcefull restart helper configurations */
12744 install_element(OSPF_NODE
, &ospf_gr_helper_enable_cmd
);
12745 install_element(OSPF_NODE
, &no_ospf_gr_helper_enable_cmd
);
12746 install_element(OSPF_NODE
, &ospf_gr_helper_enable_lsacheck_cmd
);
12747 install_element(OSPF_NODE
, &no_ospf_gr_helper_enable_lsacheck_cmd
);
12748 install_element(OSPF_NODE
, &ospf_gr_helper_supported_grace_time_cmd
);
12749 install_element(OSPF_NODE
, &no_ospf_gr_helper_supported_grace_time_cmd
);
12750 install_element(OSPF_NODE
, &ospf_gr_helper_planned_only_cmd
);
12751 install_element(OSPF_NODE
, &no_ospf_gr_helper_planned_only_cmd
);
12753 /* External LSA summarisation config commands.*/
12754 install_element(OSPF_NODE
, &ospf_external_route_aggregation_cmd
);
12755 install_element(OSPF_NODE
, &no_ospf_external_route_aggregation_cmd
);
12756 install_element(OSPF_NODE
,
12757 &ospf_external_route_aggregation_no_adrvertise_cmd
);
12758 install_element(OSPF_NODE
,
12759 &no_ospf_external_route_aggregation_no_adrvertise_cmd
);
12760 install_element(OSPF_NODE
, &ospf_route_aggregation_timer_cmd
);
12761 install_element(OSPF_NODE
, &no_ospf_route_aggregation_timer_cmd
);
12764 static int ospf_config_write(struct vty
*vty
);
12765 static struct cmd_node ospf_node
= {
12768 .parent_node
= CONFIG_NODE
,
12769 .prompt
= "%s(config-router)# ",
12770 .config_write
= ospf_config_write
,
12773 static void ospf_interface_clear(struct interface
*ifp
)
12775 if (!if_is_operative(ifp
))
12778 if (IS_DEBUG_OSPF(ism
, ISM_EVENTS
))
12779 zlog_debug("ISM[%s]: clear by reset", ifp
->name
);
12781 ospf_if_reset(ifp
);
12784 DEFUN (clear_ip_ospf_interface
,
12785 clear_ip_ospf_interface_cmd
,
12786 "clear ip ospf [vrf NAME] interface [IFNAME]",
12789 "OSPF information\n"
12791 "Interface information\n"
12792 "Interface name\n")
12794 int idx_ifname
= 0;
12796 struct interface
*ifp
;
12797 struct listnode
*node
;
12798 struct ospf
*ospf
= NULL
;
12799 char *vrf_name
= NULL
;
12800 vrf_id_t vrf_id
= VRF_DEFAULT
;
12801 struct vrf
*vrf
= NULL
;
12803 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
12804 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
12805 if (vrf_name
&& strmatch(vrf_name
, VRF_DEFAULT_NAME
))
12808 vrf
= vrf_lookup_by_name(vrf_name
);
12810 vrf_id
= vrf
->vrf_id
;
12812 if (!argv_find(argv
, argc
, "IFNAME", &idx_ifname
)) {
12813 /* Clear all the ospfv2 interfaces. */
12814 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
12815 if (vrf_id
!= ospf
->vrf_id
)
12818 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
12819 FOR_ALL_INTERFACES (vrf
, ifp
)
12820 ospf_interface_clear(ifp
);
12823 /* Interface name is specified. */
12824 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf_id
);
12826 vty_out(vty
, "No such interface name\n");
12828 ospf_interface_clear(ifp
);
12831 return CMD_SUCCESS
;
12834 void ospf_vty_clear_init(void)
12836 install_element(ENABLE_NODE
, &clear_ip_ospf_interface_cmd
);
12837 install_element(ENABLE_NODE
, &clear_ip_ospf_process_cmd
);
12838 install_element(ENABLE_NODE
, &clear_ip_ospf_neighbor_cmd
);
12842 /* Install OSPF related vty commands. */
12843 void ospf_vty_init(void)
12845 /* Install ospf top node. */
12846 install_node(&ospf_node
);
12848 /* "router ospf" commands. */
12849 install_element(CONFIG_NODE
, &router_ospf_cmd
);
12850 install_element(CONFIG_NODE
, &no_router_ospf_cmd
);
12853 install_default(OSPF_NODE
);
12855 /* "ospf router-id" commands. */
12856 install_element(OSPF_NODE
, &ospf_router_id_cmd
);
12857 install_element(OSPF_NODE
, &ospf_router_id_old_cmd
);
12858 install_element(OSPF_NODE
, &no_ospf_router_id_cmd
);
12860 /* "passive-interface" commands. */
12861 install_element(OSPF_NODE
, &ospf_passive_interface_default_cmd
);
12862 install_element(OSPF_NODE
, &ospf_passive_interface_addr_cmd
);
12863 install_element(OSPF_NODE
, &no_ospf_passive_interface_default_cmd
);
12864 install_element(OSPF_NODE
, &no_ospf_passive_interface_addr_cmd
);
12866 /* "ospf abr-type" commands. */
12867 install_element(OSPF_NODE
, &ospf_abr_type_cmd
);
12868 install_element(OSPF_NODE
, &no_ospf_abr_type_cmd
);
12870 /* "ospf log-adjacency-changes" commands. */
12871 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_cmd
);
12872 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_detail_cmd
);
12873 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_cmd
);
12874 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_detail_cmd
);
12876 /* "ospf rfc1583-compatible" commands. */
12877 install_element(OSPF_NODE
, &ospf_compatible_rfc1583_cmd
);
12878 install_element(OSPF_NODE
, &no_ospf_compatible_rfc1583_cmd
);
12879 install_element(OSPF_NODE
, &ospf_rfc1583_flag_cmd
);
12880 install_element(OSPF_NODE
, &no_ospf_rfc1583_flag_cmd
);
12882 /* "network area" commands. */
12883 install_element(OSPF_NODE
, &ospf_network_area_cmd
);
12884 install_element(OSPF_NODE
, &no_ospf_network_area_cmd
);
12886 /* "area authentication" commands. */
12887 install_element(OSPF_NODE
,
12888 &ospf_area_authentication_message_digest_cmd
);
12889 install_element(OSPF_NODE
, &ospf_area_authentication_cmd
);
12890 install_element(OSPF_NODE
, &no_ospf_area_authentication_cmd
);
12892 /* "area range" commands. */
12893 install_element(OSPF_NODE
, &ospf_area_range_cmd
);
12894 install_element(OSPF_NODE
, &ospf_area_range_cost_cmd
);
12895 install_element(OSPF_NODE
, &ospf_area_range_not_advertise_cmd
);
12896 install_element(OSPF_NODE
, &no_ospf_area_range_cmd
);
12897 install_element(OSPF_NODE
, &ospf_area_range_substitute_cmd
);
12898 install_element(OSPF_NODE
, &no_ospf_area_range_substitute_cmd
);
12900 /* "area virtual-link" commands. */
12901 install_element(OSPF_NODE
, &ospf_area_vlink_cmd
);
12902 install_element(OSPF_NODE
, &ospf_area_vlink_intervals_cmd
);
12903 install_element(OSPF_NODE
, &no_ospf_area_vlink_cmd
);
12904 install_element(OSPF_NODE
, &no_ospf_area_vlink_intervals_cmd
);
12907 /* "area stub" commands. */
12908 install_element(OSPF_NODE
, &ospf_area_stub_no_summary_cmd
);
12909 install_element(OSPF_NODE
, &ospf_area_stub_cmd
);
12910 install_element(OSPF_NODE
, &no_ospf_area_stub_no_summary_cmd
);
12911 install_element(OSPF_NODE
, &no_ospf_area_stub_cmd
);
12913 /* "area nssa" commands. */
12914 install_element(OSPF_NODE
, &ospf_area_nssa_cmd
);
12915 install_element(OSPF_NODE
, &ospf_area_nssa_translate_cmd
);
12916 install_element(OSPF_NODE
, &ospf_area_nssa_no_summary_cmd
);
12917 install_element(OSPF_NODE
, &no_ospf_area_nssa_no_summary_cmd
);
12918 install_element(OSPF_NODE
, &ospf_area_nssa_suppress_fa_cmd
);
12919 install_element(OSPF_NODE
, &no_ospf_area_nssa_suppress_fa_cmd
);
12920 install_element(OSPF_NODE
, &no_ospf_area_nssa_cmd
);
12922 install_element(OSPF_NODE
, &ospf_area_default_cost_cmd
);
12923 install_element(OSPF_NODE
, &no_ospf_area_default_cost_cmd
);
12925 install_element(OSPF_NODE
, &ospf_area_shortcut_cmd
);
12926 install_element(OSPF_NODE
, &no_ospf_area_shortcut_cmd
);
12928 install_element(OSPF_NODE
, &ospf_area_export_list_cmd
);
12929 install_element(OSPF_NODE
, &no_ospf_area_export_list_cmd
);
12931 install_element(OSPF_NODE
, &ospf_area_filter_list_cmd
);
12932 install_element(OSPF_NODE
, &no_ospf_area_filter_list_cmd
);
12934 install_element(OSPF_NODE
, &ospf_area_import_list_cmd
);
12935 install_element(OSPF_NODE
, &no_ospf_area_import_list_cmd
);
12937 /* SPF timer commands */
12938 install_element(OSPF_NODE
, &ospf_timers_throttle_spf_cmd
);
12939 install_element(OSPF_NODE
, &no_ospf_timers_throttle_spf_cmd
);
12941 /* LSA timers commands */
12942 install_element(OSPF_NODE
, &ospf_timers_min_ls_interval_cmd
);
12943 install_element(OSPF_NODE
, &no_ospf_timers_min_ls_interval_cmd
);
12944 install_element(OSPF_NODE
, &ospf_timers_lsa_min_arrival_cmd
);
12945 install_element(OSPF_NODE
, &no_ospf_timers_lsa_min_arrival_cmd
);
12947 /* refresh timer commands */
12948 install_element(OSPF_NODE
, &ospf_refresh_timer_cmd
);
12949 install_element(OSPF_NODE
, &no_ospf_refresh_timer_val_cmd
);
12951 /* max-metric commands */
12952 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_admin_cmd
);
12953 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_admin_cmd
);
12954 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_startup_cmd
);
12955 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_startup_cmd
);
12956 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_shutdown_cmd
);
12957 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_shutdown_cmd
);
12959 /* reference bandwidth commands */
12960 install_element(OSPF_NODE
, &ospf_auto_cost_reference_bandwidth_cmd
);
12961 install_element(OSPF_NODE
, &no_ospf_auto_cost_reference_bandwidth_cmd
);
12963 /* "neighbor" commands. */
12964 install_element(OSPF_NODE
, &ospf_neighbor_cmd
);
12965 install_element(OSPF_NODE
, &ospf_neighbor_poll_interval_cmd
);
12966 install_element(OSPF_NODE
, &no_ospf_neighbor_cmd
);
12967 install_element(OSPF_NODE
, &no_ospf_neighbor_poll_cmd
);
12969 /* write multiplier commands */
12970 install_element(OSPF_NODE
, &ospf_write_multiplier_cmd
);
12971 install_element(OSPF_NODE
, &write_multiplier_cmd
);
12972 install_element(OSPF_NODE
, &no_ospf_write_multiplier_cmd
);
12973 install_element(OSPF_NODE
, &no_write_multiplier_cmd
);
12975 /* "proactive-arp" commands. */
12976 install_element(OSPF_NODE
, &ospf_proactive_arp_cmd
);
12977 install_element(OSPF_NODE
, &no_ospf_proactive_arp_cmd
);
12979 /* TI-LFA commands */
12980 install_element(OSPF_NODE
, &ospf_ti_lfa_cmd
);
12981 install_element(OSPF_NODE
, &no_ospf_ti_lfa_cmd
);
12983 /* Max path configurations */
12984 install_element(OSPF_NODE
, &ospf_max_multipath_cmd
);
12985 install_element(OSPF_NODE
, &no_ospf_max_multipath_cmd
);
12987 vrf_cmd_init(NULL
, &ospfd_privs
);
12989 /* Init interface related vty commands. */
12990 ospf_vty_if_init();
12992 /* Init zebra related vty commands. */
12993 ospf_vty_zebra_init();