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 "ospfd/ospfd.h"
39 #include "ospfd/ospf_asbr.h"
40 #include "ospfd/ospf_lsa.h"
41 #include "ospfd/ospf_lsdb.h"
42 #include "ospfd/ospf_ism.h"
43 #include "ospfd/ospf_interface.h"
44 #include "ospfd/ospf_nsm.h"
45 #include "ospfd/ospf_neighbor.h"
46 #include "ospfd/ospf_flood.h"
47 #include "ospfd/ospf_abr.h"
48 #include "ospfd/ospf_spf.h"
49 #include "ospfd/ospf_route.h"
50 #include "ospfd/ospf_zebra.h"
51 /*#include "ospfd/ospf_routemap.h" */
52 #include "ospfd/ospf_vty.h"
53 #include "ospfd/ospf_dump.h"
54 #include "ospfd/ospf_bfd.h"
56 FRR_CFG_DEFAULT_BOOL(OSPF_LOG_ADJACENCY_CHANGES
,
57 { .val_long
= true, .match_profile
= "datacenter", },
58 { .val_long
= false },
61 static const char *const ospf_network_type_str
[] = {
62 "Null", "POINTOPOINT", "BROADCAST", "NBMA", "POINTOMULTIPOINT",
63 "VIRTUALLINK", "LOOPBACK"};
65 /* Utility functions. */
66 int str2area_id(const char *str
, struct in_addr
*area_id
, int *area_id_fmt
)
70 area_id
->s_addr
= htonl(strtoul(str
, &ep
, 10));
71 if (*ep
&& !inet_aton(str
, area_id
))
75 *ep
? OSPF_AREA_ID_FMT_DOTTEDQUAD
: OSPF_AREA_ID_FMT_DECIMAL
;
80 static void area_id2str(char *buf
, int length
, struct in_addr
*area_id
,
83 if (area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
84 inet_ntop(AF_INET
, area_id
, buf
, length
);
86 sprintf(buf
, "%lu", (unsigned long)ntohl(area_id
->s_addr
));
89 static int str2metric(const char *str
, int *metric
)
95 *metric
= strtol(str
, NULL
, 10);
96 if (*metric
< 0 && *metric
> 16777214) {
97 /* vty_out (vty, "OSPF metric value is invalid\n"); */
104 static int str2metric_type(const char *str
, int *metric_type
)
110 if (strncmp(str
, "1", 1) == 0)
111 *metric_type
= EXTERNAL_METRIC_TYPE_1
;
112 else if (strncmp(str
, "2", 1) == 0)
113 *metric_type
= EXTERNAL_METRIC_TYPE_2
;
120 int ospf_oi_count(struct interface
*ifp
)
122 struct route_node
*rn
;
125 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
132 #define OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf) \
133 if (argv_find(argv, argc, "vrf", &idx_vrf)) { \
134 vrf_name = argv[idx_vrf + 1]->arg; \
135 all_vrf = strmatch(vrf_name, "all"); \
138 static struct ospf
*ospf_cmd_lookup_ospf(struct vty
*vty
,
139 struct cmd_token
*argv
[],
140 const int argc
, uint32_t enable
,
141 unsigned short *instance
)
143 struct ospf
*ospf
= NULL
;
144 int idx_vrf
= 0, idx_inst
= 0;
145 const char *vrf_name
= NULL
;
146 bool created
= false;
149 if (argv_find(argv
, argc
, "(1-65535)", &idx_inst
))
150 *instance
= strtoul(argv
[idx_inst
]->arg
, NULL
, 10);
152 if (argv_find(argv
, argc
, "vrf", &idx_vrf
)) {
153 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
154 if (vrf_name
== NULL
|| strmatch(vrf_name
, VRF_DEFAULT_NAME
))
157 /* Allocate VRF aware instance */
158 ospf
= ospf_get(*instance
, vrf_name
, &created
);
160 ospf
= ospf_lookup_by_inst_name(*instance
, vrf_name
);
164 ospf
= ospf_get(*instance
, NULL
, &created
);
166 ospf
= ospf_lookup_instance(*instance
);
171 if (DFLT_OSPF_LOG_ADJACENCY_CHANGES
)
172 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
178 static void ospf_show_vrf_name(struct ospf
*ospf
, struct vty
*vty
,
179 json_object
*json
, uint8_t use_vrf
)
183 if (ospf
->vrf_id
== VRF_DEFAULT
)
184 json_object_string_add(json
, "vrfName",
187 json_object_string_add(json
, "vrfName",
189 json_object_int_add(json
, "vrfId", ospf
->vrf_id
);
191 if (ospf
->vrf_id
== VRF_DEFAULT
)
192 vty_out(vty
, "VRF Name: %s\n", "default");
194 vty_out(vty
, "VRF Name: %s\n", ospf
->name
);
199 #ifndef VTYSH_EXTRACT_PL
200 #include "ospfd/ospf_vty_clippy.c"
203 DEFUN_NOSH (router_ospf
,
205 "router ospf [{(1-65535)|vrf NAME}]",
206 "Enable a routing process\n"
207 "Start OSPF configuration\n"
211 struct ospf
*ospf
= NULL
;
212 int ret
= CMD_SUCCESS
;
213 unsigned short instance
= 0;
214 struct vrf
*vrf
= NULL
;
215 struct route_node
*rn
;
216 struct interface
*ifp
;
218 ospf
= ospf_cmd_lookup_ospf(vty
, argv
, argc
, 1, &instance
);
220 return CMD_WARNING_CONFIG_FAILED
;
222 /* The following logic to set the vty qobj index is in place to be able
223 to ignore the commands which dont belong to this instance. */
224 if (ospf
->instance
!= instance
) {
225 VTY_PUSH_CONTEXT_NULL(OSPF_NODE
);
226 ret
= CMD_NOT_MY_INSTANCE
;
228 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
229 ospf
->oi_running
= 1;
230 if (IS_DEBUG_OSPF_EVENT
)
232 "Config command 'router ospf %d' received, vrf %s id %u oi_running %u",
233 instance
, ospf
->name
? ospf
->name
: "NIL",
234 ospf
->vrf_id
, ospf
->oi_running
);
235 VTY_PUSH_CONTEXT(OSPF_NODE
, ospf
);
237 /* Activate 'ip ospf area x' configured interfaces for given
238 * vrf. Activate area on vrf x aware interfaces.
239 * vrf_enable callback calls router_id_update which
240 * internally will call ospf_if_update to trigger
243 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
245 FOR_ALL_INTERFACES (vrf
, ifp
) {
246 struct ospf_if_params
*params
;
248 params
= IF_DEF_PARAMS(ifp
);
249 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
250 for (rn
= route_top(ospf
->networks
); rn
;
251 rn
= route_next(rn
)) {
252 if (rn
->info
!= NULL
) {
254 "Interface %s has area config but please remove all network commands first.\n",
259 if (!ospf_interface_area_is_already_set(ospf
,
261 ospf_interface_area_set(ospf
, ifp
);
262 ospf
->if_ospf_cli_count
++;
267 ospf_router_id_update(ospf
);
273 DEFUN (no_router_ospf
,
275 "no router ospf [{(1-65535)|vrf NAME}]",
277 "Enable a routing process\n"
278 "Start OSPF configuration\n"
283 unsigned short instance
= 0;
285 ospf
= ospf_cmd_lookup_ospf(vty
, argv
, argc
, 0, &instance
);
288 return CMD_NOT_MY_INSTANCE
;
298 DEFPY (ospf_router_id
,
300 "ospf router-id A.B.C.D",
301 "OSPF specific commands\n"
302 "router-id for the OSPF process\n"
303 "OSPF router-id in IP address format\n")
305 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
307 struct listnode
*node
;
308 struct ospf_area
*area
;
310 ospf
->router_id_static
= router_id
;
312 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
313 if (area
->full_nbrs
) {
315 "For this router-id change to take effect,"
316 " save config and restart ospfd\n");
320 ospf_router_id_update(ospf
);
325 DEFUN_HIDDEN (ospf_router_id_old
,
326 ospf_router_id_old_cmd
,
328 "router-id for the OSPF process\n"
329 "OSPF router-id in IP address format\n")
331 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
333 struct listnode
*node
;
334 struct ospf_area
*area
;
335 struct in_addr router_id
;
338 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &router_id
);
340 vty_out(vty
, "Please specify Router ID by A.B.C.D\n");
341 return CMD_WARNING_CONFIG_FAILED
;
344 ospf
->router_id_static
= router_id
;
346 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
347 if (area
->full_nbrs
) {
349 "For this router-id change to take effect,"
350 " save config and restart ospfd\n");
354 ospf_router_id_update(ospf
);
359 DEFPY (no_ospf_router_id
,
360 no_ospf_router_id_cmd
,
361 "no ospf router-id [A.B.C.D]",
363 "OSPF specific commands\n"
364 "router-id for the OSPF process\n"
365 "OSPF router-id in IP address format\n")
367 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
368 struct listnode
*node
;
369 struct ospf_area
*area
;
372 if (!IPV4_ADDR_SAME(&ospf
->router_id_static
, &router_id
)) {
373 vty_out(vty
, "%% OSPF router-id doesn't match\n");
374 return CMD_WARNING_CONFIG_FAILED
;
378 ospf
->router_id_static
.s_addr
= 0;
380 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
381 if (area
->full_nbrs
) {
383 "For this router-id change to take effect,"
384 " save config and restart ospfd\n");
388 ospf_router_id_update(ospf
);
394 static void ospf_passive_interface_default(struct ospf
*ospf
, uint8_t newval
)
396 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
398 struct interface
*ifp
;
399 struct ospf_interface
*oi
;
401 ospf
->passive_interface_default
= newval
;
403 FOR_ALL_INTERFACES (vrf
, ifp
) {
404 if (ifp
&& OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp
),
406 UNSET_IF_PARAM(IF_DEF_PARAMS(ifp
), passive_interface
);
408 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, ln
, oi
)) {
409 if (OSPF_IF_PARAM_CONFIGURED(oi
->params
, passive_interface
))
410 UNSET_IF_PARAM(oi
->params
, passive_interface
);
411 /* update multicast memberships */
412 ospf_if_set_multicast(oi
);
416 static void ospf_passive_interface_update_addr(struct ospf
*ospf
,
417 struct interface
*ifp
,
418 struct ospf_if_params
*params
,
424 params
->passive_interface
= value
;
425 if (params
!= IF_DEF_PARAMS(ifp
)) {
426 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp
),
428 dflt
= IF_DEF_PARAMS(ifp
)->passive_interface
;
430 dflt
= ospf
->passive_interface_default
;
433 SET_IF_PARAM(params
, passive_interface
);
435 UNSET_IF_PARAM(params
, passive_interface
);
437 ospf_free_if_params(ifp
, addr
);
438 ospf_if_update_params(ifp
, addr
);
442 static void ospf_passive_interface_update(struct ospf
*ospf
,
443 struct interface
*ifp
,
444 struct ospf_if_params
*params
,
447 params
->passive_interface
= value
;
448 if (params
== IF_DEF_PARAMS(ifp
)) {
449 if (value
!= ospf
->passive_interface_default
)
450 SET_IF_PARAM(params
, passive_interface
);
452 UNSET_IF_PARAM(params
, passive_interface
);
456 DEFUN (ospf_passive_interface
,
457 ospf_passive_interface_addr_cmd
,
458 "passive-interface <IFNAME [A.B.C.D]|default>",
459 "Suppress routing updates on an interface\n"
462 "Suppress routing updates on interfaces by default\n")
464 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
466 struct interface
*ifp
= NULL
;
467 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
469 struct ospf_if_params
*params
;
470 struct route_node
*rn
;
472 if (strmatch(argv
[1]->text
, "default")) {
473 ospf_passive_interface_default(ospf
, OSPF_IF_PASSIVE
);
476 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
477 ifp
= if_get_by_name(argv
[1]->arg
, ospf
->vrf_id
);
480 vty_out(vty
, "interface %s not found.\n", (char *)argv
[1]->arg
);
481 return CMD_WARNING_CONFIG_FAILED
;
484 params
= IF_DEF_PARAMS(ifp
);
487 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
490 "Please specify interface address by A.B.C.D\n");
491 return CMD_WARNING_CONFIG_FAILED
;
494 params
= ospf_get_if_params(ifp
, addr
);
495 ospf_if_update_params(ifp
, addr
);
496 ospf_passive_interface_update_addr(ospf
, ifp
, params
,
497 OSPF_IF_PASSIVE
, addr
);
500 ospf_passive_interface_update(ospf
, ifp
, params
, OSPF_IF_PASSIVE
);
502 /* XXX We should call ospf_if_set_multicast on exactly those
503 * interfaces for which the passive property changed. It is too much
504 * work to determine this set, so we do this for every interface.
505 * This is safe and reasonable because ospf_if_set_multicast uses a
506 * record of joined groups to avoid systems calls if the desired
507 * memberships match the current memership.
510 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
511 struct ospf_interface
*oi
= rn
->info
;
513 if (oi
&& (OSPF_IF_PARAM(oi
, passive_interface
)
515 ospf_if_set_multicast(oi
);
518 * XXX It is not clear what state transitions the interface needs to
519 * undergo when going from active to passive. Fixing this will
520 * require precise identification of interfaces having such a
527 DEFUN (no_ospf_passive_interface
,
528 no_ospf_passive_interface_addr_cmd
,
529 "no passive-interface <IFNAME [A.B.C.D]|default>",
531 "Allow routing updates on an interface\n"
534 "Allow routing updates on interfaces by default\n")
536 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
538 struct interface
*ifp
= NULL
;
539 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
540 struct ospf_if_params
*params
;
542 struct route_node
*rn
;
544 if (strmatch(argv
[2]->text
, "default")) {
545 ospf_passive_interface_default(ospf
, OSPF_IF_ACTIVE
);
549 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
550 ifp
= if_get_by_name(argv
[2]->arg
, ospf
->vrf_id
);
553 vty_out(vty
, "interface %s not found.\n", (char *)argv
[2]->arg
);
554 return CMD_WARNING_CONFIG_FAILED
;
557 params
= IF_DEF_PARAMS(ifp
);
560 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
563 "Please specify interface address by A.B.C.D\n");
564 return CMD_WARNING_CONFIG_FAILED
;
567 params
= ospf_lookup_if_params(ifp
, addr
);
570 ospf_passive_interface_update_addr(ospf
, ifp
, params
,
571 OSPF_IF_ACTIVE
, addr
);
573 ospf_passive_interface_update(ospf
, ifp
, params
, OSPF_IF_ACTIVE
);
575 /* XXX We should call ospf_if_set_multicast on exactly those
576 * interfaces for which the passive property changed. It is too much
577 * work to determine this set, so we do this for every interface.
578 * This is safe and reasonable because ospf_if_set_multicast uses a
579 * record of joined groups to avoid systems calls if the desired
580 * memberships match the current memership.
582 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
583 struct ospf_interface
*oi
= rn
->info
;
586 && (OSPF_IF_PARAM(oi
, passive_interface
) == OSPF_IF_ACTIVE
))
587 ospf_if_set_multicast(oi
);
594 DEFUN (ospf_network_area
,
595 ospf_network_area_cmd
,
596 "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
597 "Enable routing on an IP network\n"
598 "OSPF network prefix\n"
599 "Set the OSPF area ID\n"
600 "OSPF area ID in IP address format\n"
601 "OSPF area ID as a decimal value\n")
603 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
604 int idx_ipv4_prefixlen
= 1;
605 int idx_ipv4_number
= 3;
606 struct prefix_ipv4 p
;
607 struct in_addr area_id
;
610 if (ospf
->instance
) {
612 "The network command is not supported in multi-instance ospf\n");
613 return CMD_WARNING_CONFIG_FAILED
;
616 if (ospf
->if_ospf_cli_count
> 0) {
618 "Please remove all ip ospf area x.x.x.x commands first.\n");
619 if (IS_DEBUG_OSPF_EVENT
)
621 "%s ospf vrf %s num of %u ip osp area x config",
622 __func__
, ospf
->name
? ospf
->name
: "NIL",
623 ospf
->if_ospf_cli_count
);
624 return CMD_WARNING_CONFIG_FAILED
;
627 /* Get network prefix and Area ID. */
628 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
629 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
631 ret
= ospf_network_set(ospf
, &p
, area_id
, format
);
633 vty_out(vty
, "There is already same network statement.\n");
634 return CMD_WARNING_CONFIG_FAILED
;
640 DEFUN (no_ospf_network_area
,
641 no_ospf_network_area_cmd
,
642 "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
644 "Enable routing on an IP network\n"
645 "OSPF network prefix\n"
646 "Set the OSPF area ID\n"
647 "OSPF area ID in IP address format\n"
648 "OSPF area ID as a decimal value\n")
650 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
651 int idx_ipv4_prefixlen
= 2;
652 int idx_ipv4_number
= 4;
653 struct prefix_ipv4 p
;
654 struct in_addr area_id
;
657 if (ospf
->instance
) {
659 "The network command is not supported in multi-instance ospf\n");
660 return CMD_WARNING_CONFIG_FAILED
;
663 /* Get network prefix and Area ID. */
664 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
665 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
667 ret
= ospf_network_unset(ospf
, &p
, area_id
);
670 "Can't find specified network area configuration.\n");
671 return CMD_WARNING_CONFIG_FAILED
;
677 DEFUN (ospf_area_range
,
679 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]",
680 "OSPF area parameters\n"
681 "OSPF area ID in IP address format\n"
682 "OSPF area ID as a decimal value\n"
683 "Summarize routes matching address/mask (border routers only)\n"
684 "Area range prefix\n"
685 "Advertise this range (default)\n"
686 "User specified metric for this range\n"
687 "Advertised metric for this range\n")
689 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
690 int idx_ipv4_number
= 1;
691 int idx_ipv4_prefixlen
= 3;
693 struct prefix_ipv4 p
;
694 struct in_addr area_id
;
698 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
699 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
701 ospf_area_range_set(ospf
, area_id
, &p
, OSPF_AREA_RANGE_ADVERTISE
);
703 cost
= strtoul(argv
[idx_cost
]->arg
, NULL
, 10);
704 ospf_area_range_cost_set(ospf
, area_id
, &p
, cost
);
710 DEFUN (ospf_area_range_cost
,
711 ospf_area_range_cost_cmd
,
712 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M cost (0-16777215)",
713 "OSPF area parameters\n"
714 "OSPF area ID in IP address format\n"
715 "OSPF area ID as a decimal value\n"
716 "Summarize routes matching address/mask (border routers only)\n"
717 "Area range prefix\n"
718 "User specified metric for this range\n"
719 "Advertised metric for this range\n")
721 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
722 int idx_ipv4_number
= 1;
723 int idx_ipv4_prefixlen
= 3;
725 struct prefix_ipv4 p
;
726 struct in_addr area_id
;
730 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
731 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
733 ospf_area_range_set(ospf
, area_id
, &p
, OSPF_AREA_RANGE_ADVERTISE
);
734 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
737 cost
= strtoul(argv
[idx_cost
]->arg
, NULL
, 10);
738 ospf_area_range_cost_set(ospf
, area_id
, &p
, cost
);
743 DEFUN (ospf_area_range_not_advertise
,
744 ospf_area_range_not_advertise_cmd
,
745 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise",
746 "OSPF area parameters\n"
747 "OSPF area ID in IP address format\n"
748 "OSPF area ID as a decimal value\n"
749 "Summarize routes matching address/mask (border routers only)\n"
750 "Area range prefix\n"
751 "DoNotAdvertise this range\n")
753 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
754 int idx_ipv4_number
= 1;
755 int idx_ipv4_prefixlen
= 3;
756 struct prefix_ipv4 p
;
757 struct in_addr area_id
;
760 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
761 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
763 ospf_area_range_set(ospf
, area_id
, &p
, 0);
764 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
766 ospf_area_range_substitute_unset(ospf
, area_id
, &p
);
771 DEFUN (no_ospf_area_range
,
772 no_ospf_area_range_cmd
,
773 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]",
775 "OSPF area parameters\n"
776 "OSPF area ID in IP address format\n"
777 "OSPF area ID as a decimal value\n"
778 "Summarize routes matching address/mask (border routers only)\n"
779 "Area range prefix\n"
780 "User specified metric for this range\n"
781 "Advertised metric for this range\n"
782 "Advertise this range (default)\n"
783 "User specified metric for this range\n"
784 "Advertised metric for this range\n"
785 "DoNotAdvertise this range\n")
787 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
788 int idx_ipv4_number
= 2;
789 int idx_ipv4_prefixlen
= 4;
790 struct prefix_ipv4 p
;
791 struct in_addr area_id
;
794 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
795 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
797 ospf_area_range_unset(ospf
, area_id
, &p
);
802 DEFUN (ospf_area_range_substitute
,
803 ospf_area_range_substitute_cmd
,
804 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
805 "OSPF area parameters\n"
806 "OSPF area ID in IP address format\n"
807 "OSPF area ID as a decimal value\n"
808 "Summarize routes matching address/mask (border routers only)\n"
809 "Area range prefix\n"
810 "Announce area range as another prefix\n"
811 "Network prefix to be announced instead of range\n")
813 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
814 int idx_ipv4_number
= 1;
815 int idx_ipv4_prefixlen
= 3;
816 int idx_ipv4_prefixlen_2
= 5;
817 struct prefix_ipv4 p
, s
;
818 struct in_addr area_id
;
821 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
822 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
823 str2prefix_ipv4(argv
[idx_ipv4_prefixlen_2
]->arg
, &s
);
825 ospf_area_range_substitute_set(ospf
, area_id
, &p
, &s
);
826 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
832 DEFUN (no_ospf_area_range_substitute
,
833 no_ospf_area_range_substitute_cmd
,
834 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
836 "OSPF area parameters\n"
837 "OSPF area ID in IP address format\n"
838 "OSPF area ID as a decimal value\n"
839 "Summarize routes matching address/mask (border routers only)\n"
840 "Area range prefix\n"
841 "Announce area range as another prefix\n"
842 "Network prefix to be announced instead of range\n")
844 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
845 int idx_ipv4_number
= 2;
846 int idx_ipv4_prefixlen
= 4;
847 int idx_ipv4_prefixlen_2
= 6;
848 struct prefix_ipv4 p
, s
;
849 struct in_addr area_id
;
852 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
853 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
854 str2prefix_ipv4(argv
[idx_ipv4_prefixlen_2
]->arg
, &s
);
856 ospf_area_range_substitute_unset(ospf
, area_id
, &p
);
862 /* Command Handler Logic in VLink stuff is delicate!!
864 ALTER AT YOUR OWN RISK!!!!
866 Various dummy values are used to represent 'NoChange' state for
867 VLink configuration NOT being changed by a VLink command, and
868 special syntax is used within the command strings so that the
869 typed in command verbs can be seen in the configuration command
870 bacckend handler. This is to drastically reduce the verbeage
871 required to coe up with a reasonably compatible Cisco VLink command
873 - Matthew Grant <grantma@anathoth.gen.nz>
874 Wed, 21 Feb 2001 15:13:52 +1300
877 /* Configuration data for virtual links
879 struct ospf_vl_config_data
{
880 struct vty
*vty
; /* vty stuff */
881 struct in_addr area_id
; /* area ID from command line */
882 int area_id_fmt
; /* command line area ID format */
883 struct in_addr vl_peer
; /* command line vl_peer */
884 int auth_type
; /* Authehntication type, if given */
885 char *auth_key
; /* simple password if present */
886 int crypto_key_id
; /* Cryptographic key ID */
887 char *md5_key
; /* MD5 authentication key */
888 int hello_interval
; /* Obvious what these are... */
889 int retransmit_interval
;
894 static void ospf_vl_config_data_init(struct ospf_vl_config_data
*vl_config
,
897 memset(vl_config
, 0, sizeof(struct ospf_vl_config_data
));
898 vl_config
->auth_type
= OSPF_AUTH_CMD_NOTSEEN
;
899 vl_config
->vty
= vty
;
902 static struct ospf_vl_data
*
903 ospf_find_vl_data(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
905 struct ospf_area
*area
;
906 struct ospf_vl_data
*vl_data
;
908 struct in_addr area_id
;
910 vty
= vl_config
->vty
;
911 area_id
= vl_config
->area_id
;
913 if (area_id
.s_addr
== OSPF_AREA_BACKBONE
) {
915 "Configuring VLs over the backbone is not allowed\n");
918 area
= ospf_area_get(ospf
, area_id
);
919 ospf_area_display_format_set(ospf
, area
, vl_config
->area_id_fmt
);
921 if (area
->external_routing
!= OSPF_AREA_DEFAULT
) {
922 if (vl_config
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
923 vty_out(vty
, "Area %s is %s\n", inet_ntoa(area_id
),
924 area
->external_routing
== OSPF_AREA_NSSA
928 vty_out(vty
, "Area %ld is %s\n",
929 (unsigned long)ntohl(area_id
.s_addr
),
930 area
->external_routing
== OSPF_AREA_NSSA
936 if ((vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
->vl_peer
))
938 vl_data
= ospf_vl_data_new(area
, vl_config
->vl_peer
);
939 if (vl_data
->vl_oi
== NULL
) {
940 vl_data
->vl_oi
= ospf_vl_new(ospf
, vl_data
);
941 ospf_vl_add(ospf
, vl_data
);
942 ospf_spf_calculate_schedule(ospf
,
943 SPF_FLAG_CONFIG_CHANGE
);
950 static int ospf_vl_set_security(struct ospf_vl_data
*vl_data
,
951 struct ospf_vl_config_data
*vl_config
)
953 struct crypt_key
*ck
;
955 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
957 vty
= vl_config
->vty
;
959 if (vl_config
->auth_type
!= OSPF_AUTH_CMD_NOTSEEN
) {
960 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), auth_type
);
961 IF_DEF_PARAMS(ifp
)->auth_type
= vl_config
->auth_type
;
964 if (vl_config
->auth_key
) {
965 memset(IF_DEF_PARAMS(ifp
)->auth_simple
, 0,
966 OSPF_AUTH_SIMPLE_SIZE
+ 1);
967 strlcpy((char *)IF_DEF_PARAMS(ifp
)->auth_simple
,
969 sizeof(IF_DEF_PARAMS(ifp
)->auth_simple
));
970 } else if (vl_config
->md5_key
) {
971 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
972 vl_config
->crypto_key_id
)
974 vty_out(vty
, "OSPF: Key %d already exists\n",
975 vl_config
->crypto_key_id
);
978 ck
= ospf_crypt_key_new();
979 ck
->key_id
= vl_config
->crypto_key_id
;
980 memset(ck
->auth_key
, 0, OSPF_AUTH_MD5_SIZE
+ 1);
981 strlcpy((char *)ck
->auth_key
, vl_config
->md5_key
,
982 sizeof(ck
->auth_key
));
984 ospf_crypt_key_add(IF_DEF_PARAMS(ifp
)->auth_crypt
, ck
);
985 } else if (vl_config
->crypto_key_id
!= 0) {
988 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
989 vl_config
->crypto_key_id
)
991 vty_out(vty
, "OSPF: Key %d does not exist\n",
992 vl_config
->crypto_key_id
);
993 return CMD_WARNING_CONFIG_FAILED
;
996 ospf_crypt_key_delete(IF_DEF_PARAMS(ifp
)->auth_crypt
,
997 vl_config
->crypto_key_id
);
1003 static int ospf_vl_set_timers(struct ospf_vl_data
*vl_data
,
1004 struct ospf_vl_config_data
*vl_config
)
1006 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
1007 /* Virtual Link data initialised to defaults, so only set
1009 if (vl_config
->hello_interval
) {
1010 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_hello
);
1011 IF_DEF_PARAMS(ifp
)->v_hello
= vl_config
->hello_interval
;
1014 if (vl_config
->dead_interval
) {
1015 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_wait
);
1016 IF_DEF_PARAMS(ifp
)->v_wait
= vl_config
->dead_interval
;
1019 if (vl_config
->retransmit_interval
) {
1020 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), retransmit_interval
);
1021 IF_DEF_PARAMS(ifp
)->retransmit_interval
=
1022 vl_config
->retransmit_interval
;
1025 if (vl_config
->transmit_delay
) {
1026 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), transmit_delay
);
1027 IF_DEF_PARAMS(ifp
)->transmit_delay
= vl_config
->transmit_delay
;
1034 /* The business end of all of the above */
1035 static int ospf_vl_set(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
1037 struct ospf_vl_data
*vl_data
;
1040 vl_data
= ospf_find_vl_data(ospf
, vl_config
);
1042 return CMD_WARNING_CONFIG_FAILED
;
1044 /* Process this one first as it can have a fatal result, which can
1045 only logically occur if the virtual link exists already
1046 Thus a command error does not result in a change to the
1047 running configuration such as unexpectedly altered timer
1049 ret
= ospf_vl_set_security(vl_data
, vl_config
);
1050 if (ret
!= CMD_SUCCESS
)
1053 /* Set any time based parameters, these area already range checked */
1055 ret
= ospf_vl_set_timers(vl_data
, vl_config
);
1056 if (ret
!= CMD_SUCCESS
)
1062 /* This stuff exists to make specifying all the alias commands A LOT simpler
1064 #define VLINK_HELPSTR_IPADDR \
1065 "OSPF area parameters\n" \
1066 "OSPF area ID in IP address format\n" \
1067 "OSPF area ID as a decimal value\n" \
1068 "Configure a virtual link\n" \
1069 "Router ID of the remote ABR\n"
1071 #define VLINK_HELPSTR_AUTHTYPE_SIMPLE \
1072 "Enable authentication on this virtual link\n" \
1075 #define VLINK_HELPSTR_AUTHTYPE_ALL \
1076 VLINK_HELPSTR_AUTHTYPE_SIMPLE \
1077 "Use null authentication\n" \
1078 "Use message-digest authentication\n"
1080 #define VLINK_HELPSTR_TIME_PARAM \
1081 "Time between HELLO packets\n" \
1083 "Time between retransmitting lost link state advertisements\n" \
1085 "Link state transmit delay\n" \
1087 "Interval time after which a neighbor is declared down\n" \
1090 #define VLINK_HELPSTR_AUTH_SIMPLE \
1091 "Authentication password (key)\n" \
1092 "The OSPF password (key)\n"
1094 #define VLINK_HELPSTR_AUTH_MD5 \
1095 "Message digest authentication password (key)\n" \
1097 "Use MD5 algorithm\n" \
1098 "The OSPF password (key)\n"
1100 DEFUN (ospf_area_vlink
,
1101 ospf_area_vlink_cmd
,
1102 "area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D [authentication [<message-digest|null>]] [<message-digest-key (1-255) md5 KEY|authentication-key AUTH_KEY>]",
1103 VLINK_HELPSTR_IPADDR
1104 "Enable authentication on this virtual link\n"
1105 "Use message-digest authentication\n"
1106 "Use null authentication\n"
1107 VLINK_HELPSTR_AUTH_MD5
1108 VLINK_HELPSTR_AUTH_SIMPLE
)
1110 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1111 int idx_ipv4_number
= 1;
1113 struct ospf_vl_config_data vl_config
;
1114 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1115 char md5_key
[OSPF_AUTH_MD5_SIZE
+ 1];
1119 ospf_vl_config_data_init(&vl_config
, vty
);
1121 /* Read off first 2 parameters and check them */
1122 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1123 &vl_config
.area_id_fmt
);
1125 vty_out(vty
, "OSPF area ID is invalid\n");
1126 return CMD_WARNING_CONFIG_FAILED
;
1129 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1131 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1132 return CMD_WARNING_CONFIG_FAILED
;
1136 /* Thats all folks! - BUGS B. strikes again!!!*/
1138 return ospf_vl_set(ospf
, &vl_config
);
1141 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1142 /* authentication - this option can only occur
1143 at start of command line */
1144 vl_config
.auth_type
= OSPF_AUTH_SIMPLE
;
1147 if (argv_find(argv
, argc
, "message-digest", &idx
)) {
1148 /* authentication message-digest */
1149 vl_config
.auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
1150 } else if (argv_find(argv
, argc
, "null", &idx
)) {
1151 /* "authentication null" */
1152 vl_config
.auth_type
= OSPF_AUTH_NULL
;
1155 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1156 vl_config
.md5_key
= NULL
;
1157 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1158 if (vl_config
.crypto_key_id
< 0)
1159 return CMD_WARNING_CONFIG_FAILED
;
1161 strlcpy(md5_key
, argv
[idx
+ 3]->arg
, sizeof(md5_key
));
1162 vl_config
.md5_key
= md5_key
;
1165 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1166 strlcpy(auth_key
, argv
[idx
+ 1]->arg
, sizeof(auth_key
));
1167 vl_config
.auth_key
= auth_key
;
1170 /* Action configuration */
1172 return ospf_vl_set(ospf
, &vl_config
);
1175 DEFUN (no_ospf_area_vlink
,
1176 no_ospf_area_vlink_cmd
,
1177 "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>]",
1179 VLINK_HELPSTR_IPADDR
1180 "Enable authentication on this virtual link\n" \
1181 "Use message-digest authentication\n" \
1182 "Use null authentication\n" \
1183 VLINK_HELPSTR_AUTH_MD5
1184 VLINK_HELPSTR_AUTH_SIMPLE
)
1186 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1187 int idx_ipv4_number
= 2;
1189 struct ospf_area
*area
;
1190 struct ospf_vl_config_data vl_config
;
1191 struct ospf_vl_data
*vl_data
= NULL
;
1192 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1196 ospf_vl_config_data_init(&vl_config
, vty
);
1198 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1201 vty_out(vty
, "OSPF area ID is invalid\n");
1202 return CMD_WARNING_CONFIG_FAILED
;
1205 area
= ospf_area_lookup_by_area_id(ospf
, vl_config
.area_id
);
1207 vty_out(vty
, "Area does not exist\n");
1208 return CMD_WARNING_CONFIG_FAILED
;
1211 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1213 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1214 return CMD_WARNING_CONFIG_FAILED
;
1217 vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
.vl_peer
);
1219 vty_out(vty
, "Virtual link does not exist\n");
1220 return CMD_WARNING_CONFIG_FAILED
;
1224 /* Basic VLink no command */
1225 /* Thats all folks! - BUGS B. strikes again!!!*/
1226 ospf_vl_delete(ospf
, vl_data
);
1227 ospf_area_check_free(ospf
, vl_config
.area_id
);
1231 /* If we are down here, we are reseting parameters */
1232 /* Deal with other parameters */
1234 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1235 /* authentication - this option can only occur
1236 at start of command line */
1237 vl_config
.auth_type
= OSPF_AUTH_NOTSET
;
1240 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1241 vl_config
.md5_key
= NULL
;
1242 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1243 if (vl_config
.crypto_key_id
< 0)
1244 return CMD_WARNING_CONFIG_FAILED
;
1247 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1248 /* Reset authentication-key to 0 */
1249 memset(auth_key
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
1250 vl_config
.auth_key
= auth_key
;
1253 /* Action configuration */
1255 return ospf_vl_set(ospf
, &vl_config
);
1258 DEFUN (ospf_area_vlink_intervals
,
1259 ospf_area_vlink_intervals_cmd
,
1260 "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)}",
1261 VLINK_HELPSTR_IPADDR
1262 VLINK_HELPSTR_TIME_PARAM
)
1264 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1265 struct ospf_vl_config_data vl_config
;
1268 ospf_vl_config_data_init(&vl_config
, vty
);
1270 char *area_id
= argv
[1]->arg
;
1271 char *router_id
= argv
[3]->arg
;
1273 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1275 vty_out(vty
, "OSPF area ID is invalid\n");
1276 return CMD_WARNING_CONFIG_FAILED
;
1279 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1281 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1282 return CMD_WARNING_CONFIG_FAILED
;
1285 for (int idx
= 4; idx
< argc
; idx
++) {
1286 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1287 vl_config
.hello_interval
=
1288 strtol(argv
[++idx
]->arg
, NULL
, 10);
1289 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1290 vl_config
.retransmit_interval
=
1291 strtol(argv
[++idx
]->arg
, NULL
, 10);
1292 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1293 vl_config
.transmit_delay
=
1294 strtol(argv
[++idx
]->arg
, NULL
, 10);
1295 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1296 vl_config
.dead_interval
=
1297 strtol(argv
[++idx
]->arg
, NULL
, 10);
1300 /* Action configuration */
1301 return ospf_vl_set(ospf
, &vl_config
);
1304 DEFUN (no_ospf_area_vlink_intervals
,
1305 no_ospf_area_vlink_intervals_cmd
,
1306 "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)}",
1308 VLINK_HELPSTR_IPADDR
1309 VLINK_HELPSTR_TIME_PARAM
)
1311 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1312 struct ospf_vl_config_data vl_config
;
1315 ospf_vl_config_data_init(&vl_config
, vty
);
1317 char *area_id
= argv
[2]->arg
;
1318 char *router_id
= argv
[4]->arg
;
1320 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1322 vty_out(vty
, "OSPF area ID is invalid\n");
1323 return CMD_WARNING_CONFIG_FAILED
;
1326 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1328 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1329 return CMD_WARNING_CONFIG_FAILED
;
1332 for (int idx
= 5; idx
< argc
; idx
++) {
1333 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1334 vl_config
.hello_interval
= OSPF_HELLO_INTERVAL_DEFAULT
;
1335 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1336 vl_config
.retransmit_interval
=
1337 OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
1338 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1339 vl_config
.transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
1340 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1341 vl_config
.dead_interval
=
1342 OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
1345 /* Action configuration */
1346 return ospf_vl_set(ospf
, &vl_config
);
1349 DEFUN (ospf_area_shortcut
,
1350 ospf_area_shortcut_cmd
,
1351 "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>",
1352 "OSPF area parameters\n"
1353 "OSPF area ID in IP address format\n"
1354 "OSPF area ID as a decimal value\n"
1355 "Configure the area's shortcutting mode\n"
1356 "Set default shortcutting behavior\n"
1357 "Enable shortcutting through the area\n"
1358 "Disable shortcutting through the area\n")
1360 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1361 int idx_ipv4_number
= 1;
1362 int idx_enable_disable
= 3;
1363 struct ospf_area
*area
;
1364 struct in_addr area_id
;
1368 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1369 argv
[idx_ipv4_number
]->arg
);
1371 area
= ospf_area_get(ospf
, area_id
);
1372 ospf_area_display_format_set(ospf
, area
, format
);
1374 if (strncmp(argv
[idx_enable_disable
]->arg
, "de", 2) == 0)
1375 mode
= OSPF_SHORTCUT_DEFAULT
;
1376 else if (strncmp(argv
[idx_enable_disable
]->arg
, "di", 2) == 0)
1377 mode
= OSPF_SHORTCUT_DISABLE
;
1378 else if (strncmp(argv
[idx_enable_disable
]->arg
, "e", 1) == 0)
1379 mode
= OSPF_SHORTCUT_ENABLE
;
1381 return CMD_WARNING_CONFIG_FAILED
;
1383 ospf_area_shortcut_set(ospf
, area
, mode
);
1385 if (ospf
->abr_type
!= OSPF_ABR_SHORTCUT
)
1387 "Shortcut area setting will take effect "
1388 "only when the router is configured as Shortcut ABR\n");
1393 DEFUN (no_ospf_area_shortcut
,
1394 no_ospf_area_shortcut_cmd
,
1395 "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>",
1397 "OSPF area parameters\n"
1398 "OSPF area ID in IP address format\n"
1399 "OSPF area ID as a decimal value\n"
1400 "Deconfigure the area's shortcutting mode\n"
1401 "Deconfigure enabled shortcutting through the area\n"
1402 "Deconfigure disabled shortcutting through the area\n")
1404 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1405 int idx_ipv4_number
= 2;
1406 struct ospf_area
*area
;
1407 struct in_addr area_id
;
1410 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1411 argv
[idx_ipv4_number
]->arg
);
1413 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1417 ospf_area_shortcut_unset(ospf
, area
);
1423 DEFUN (ospf_area_stub
,
1425 "area <A.B.C.D|(0-4294967295)> stub",
1426 "OSPF area parameters\n"
1427 "OSPF area ID in IP address format\n"
1428 "OSPF area ID as a decimal value\n"
1429 "Configure OSPF area as stub\n")
1431 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1432 int idx_ipv4_number
= 1;
1433 struct in_addr area_id
;
1436 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1437 argv
[idx_ipv4_number
]->arg
);
1439 ret
= ospf_area_stub_set(ospf
, area_id
);
1440 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1444 "First deconfigure all virtual link through this area\n");
1445 return CMD_WARNING_CONFIG_FAILED
;
1448 ospf_area_no_summary_unset(ospf
, area_id
);
1453 DEFUN (ospf_area_stub_no_summary
,
1454 ospf_area_stub_no_summary_cmd
,
1455 "area <A.B.C.D|(0-4294967295)> stub no-summary",
1456 "OSPF stub parameters\n"
1457 "OSPF area ID in IP address format\n"
1458 "OSPF area ID as a decimal value\n"
1459 "Configure OSPF area as stub\n"
1460 "Do not inject inter-area routes into stub\n")
1462 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1463 int idx_ipv4_number
= 1;
1464 struct in_addr area_id
;
1467 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1468 argv
[idx_ipv4_number
]->arg
);
1470 ret
= ospf_area_stub_set(ospf
, area_id
);
1471 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1475 "%% Area cannot be stub as it contains a virtual link\n");
1476 return CMD_WARNING_CONFIG_FAILED
;
1479 ospf_area_no_summary_set(ospf
, area_id
);
1484 DEFUN (no_ospf_area_stub
,
1485 no_ospf_area_stub_cmd
,
1486 "no area <A.B.C.D|(0-4294967295)> stub",
1488 "OSPF area parameters\n"
1489 "OSPF area ID in IP address format\n"
1490 "OSPF area ID as a decimal value\n"
1491 "Configure OSPF area as stub\n")
1493 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1494 int idx_ipv4_number
= 2;
1495 struct in_addr area_id
;
1498 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1499 argv
[idx_ipv4_number
]->arg
);
1501 ospf_area_stub_unset(ospf
, area_id
);
1502 ospf_area_no_summary_unset(ospf
, area_id
);
1507 DEFUN (no_ospf_area_stub_no_summary
,
1508 no_ospf_area_stub_no_summary_cmd
,
1509 "no area <A.B.C.D|(0-4294967295)> stub no-summary",
1511 "OSPF area parameters\n"
1512 "OSPF area ID in IP address format\n"
1513 "OSPF area ID as a decimal value\n"
1514 "Configure OSPF area as stub\n"
1515 "Do not inject inter-area routes into area\n")
1517 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1518 int idx_ipv4_number
= 2;
1519 struct in_addr area_id
;
1522 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1523 argv
[idx_ipv4_number
]->arg
);
1524 ospf_area_no_summary_unset(ospf
, area_id
);
1529 static int ospf_area_nssa_cmd_handler(struct vty
*vty
, int argc
,
1530 struct cmd_token
**argv
, int cfg_nosum
,
1533 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1534 struct in_addr area_id
;
1537 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
, argv
[1]->arg
);
1539 ret
= ospf_area_nssa_set(ospf
, area_id
);
1540 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1544 "%% Area cannot be nssa as it contains a virtual link\n");
1545 return CMD_WARNING_CONFIG_FAILED
;
1549 if (strncmp(argv
[3]->text
, "translate-c", 11) == 0)
1550 ospf_area_nssa_translator_role_set(
1551 ospf
, area_id
, OSPF_NSSA_ROLE_CANDIDATE
);
1552 else if (strncmp(argv
[3]->text
, "translate-n", 11) == 0)
1553 ospf_area_nssa_translator_role_set(
1554 ospf
, area_id
, OSPF_NSSA_ROLE_NEVER
);
1555 else if (strncmp(argv
[3]->text
, "translate-a", 11) == 0)
1556 ospf_area_nssa_translator_role_set(
1557 ospf
, area_id
, OSPF_NSSA_ROLE_ALWAYS
);
1559 ospf_area_nssa_translator_role_set(ospf
, area_id
,
1560 OSPF_NSSA_ROLE_CANDIDATE
);
1565 ospf_area_no_summary_set(ospf
, area_id
);
1567 ospf_area_no_summary_unset(ospf
, area_id
);
1570 ospf_schedule_abr_task(ospf
);
1576 DEFUN (ospf_area_nssa_translate
,
1577 ospf_area_nssa_translate_cmd
,
1578 "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always>",
1579 "OSPF area parameters\n"
1580 "OSPF area ID in IP address format\n"
1581 "OSPF area ID as a decimal value\n"
1582 "Configure OSPF area as nssa\n"
1583 "Configure NSSA-ABR for translate election (default)\n"
1584 "Configure NSSA-ABR to never translate\n"
1585 "Configure NSSA-ABR to always translate\n")
1587 return ospf_area_nssa_cmd_handler(vty
, argc
, argv
, 0, 0);
1590 DEFUN (ospf_area_nssa
,
1592 "area <A.B.C.D|(0-4294967295)> nssa",
1593 "OSPF area parameters\n"
1594 "OSPF area ID in IP address format\n"
1595 "OSPF area ID as a decimal value\n"
1596 "Configure OSPF area as nssa\n")
1598 return ospf_area_nssa_cmd_handler(vty
, argc
, argv
, 0, 0);
1601 DEFUN (ospf_area_nssa_no_summary
,
1602 ospf_area_nssa_no_summary_cmd
,
1603 "area <A.B.C.D|(0-4294967295)> nssa no-summary",
1604 "OSPF area parameters\n"
1605 "OSPF area ID in IP address format\n"
1606 "OSPF area ID as a decimal value\n"
1607 "Configure OSPF area as nssa\n"
1608 "Do not inject inter-area routes into nssa\n")
1610 int idx_ipv4_number
= 1;
1611 struct in_addr area_id
;
1614 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1615 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1616 argv
[idx_ipv4_number
]->arg
);
1618 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1620 ospf_area_nssa_no_summary_set(ospf
, area_id
);
1622 ospf_schedule_abr_task(ospf
);
1627 DEFUN (no_ospf_area_nssa_no_summary
,
1628 no_ospf_area_nssa_no_summary_cmd
,
1629 "no area <A.B.C.D|(0-4294967295)> nssa no-summary",
1631 "OSPF area parameters\n"
1632 "OSPF area ID in IP address format\n"
1633 "OSPF area ID as a decimal value\n"
1634 "Configure OSPF area as nssa\n"
1635 "Do not inject inter-area routes into nssa\n")
1637 int idx_ipv4_number
= 2;
1638 struct in_addr area_id
;
1641 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1643 VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id
, format
,
1644 argv
[idx_ipv4_number
]->arg
);
1646 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1648 ospf_area_no_summary_unset(ospf
, area_id
);
1650 ospf_schedule_abr_task(ospf
);
1655 DEFUN (no_ospf_area_nssa
,
1656 no_ospf_area_nssa_cmd
,
1657 "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always>]",
1659 "OSPF area parameters\n"
1660 "OSPF area ID in IP address format\n"
1661 "OSPF area ID as a decimal value\n"
1662 "Configure OSPF area as nssa\n"
1663 "Configure NSSA-ABR for translate election (default)\n"
1664 "Configure NSSA-ABR to never translate\n"
1665 "Configure NSSA-ABR to always translate\n")
1667 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1668 int idx_ipv4_number
= 2;
1669 struct in_addr area_id
;
1672 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1673 argv
[idx_ipv4_number
]->arg
);
1675 ospf_area_nssa_unset(ospf
, area_id
, argc
);
1677 ospf_schedule_abr_task(ospf
);
1683 DEFUN (ospf_area_default_cost
,
1684 ospf_area_default_cost_cmd
,
1685 "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1686 "OSPF area parameters\n"
1687 "OSPF area ID in IP address format\n"
1688 "OSPF area ID as a decimal value\n"
1689 "Set the summary-default cost of a NSSA or stub area\n"
1690 "Stub's advertised default summary cost\n")
1692 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1693 int idx_ipv4_number
= 1;
1695 struct ospf_area
*area
;
1696 struct in_addr area_id
;
1699 struct prefix_ipv4 p
;
1701 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1702 argv
[idx_ipv4_number
]->arg
);
1703 cost
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1705 area
= ospf_area_get(ospf
, area_id
);
1706 ospf_area_display_format_set(ospf
, area
, format
);
1708 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1709 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1710 return CMD_WARNING_CONFIG_FAILED
;
1713 area
->default_cost
= cost
;
1716 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1718 if (IS_DEBUG_OSPF_EVENT
)
1720 "ospf_abr_announce_stub_defaults(): "
1721 "announcing 0.0.0.0/0 to area %s",
1722 inet_ntoa(area
->area_id
));
1723 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1728 DEFUN (no_ospf_area_default_cost
,
1729 no_ospf_area_default_cost_cmd
,
1730 "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1732 "OSPF area parameters\n"
1733 "OSPF area ID in IP address format\n"
1734 "OSPF area ID as a decimal value\n"
1735 "Set the summary-default cost of a NSSA or stub area\n"
1736 "Stub's advertised default summary cost\n")
1738 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1739 int idx_ipv4_number
= 2;
1740 struct ospf_area
*area
;
1741 struct in_addr area_id
;
1743 struct prefix_ipv4 p
;
1745 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1746 argv
[idx_ipv4_number
]->arg
);
1748 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1752 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1753 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1754 return CMD_WARNING_CONFIG_FAILED
;
1757 area
->default_cost
= 1;
1760 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1762 if (IS_DEBUG_OSPF_EVENT
)
1764 "ospf_abr_announce_stub_defaults(): "
1765 "announcing 0.0.0.0/0 to area %s",
1766 inet_ntoa(area
->area_id
));
1767 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1770 ospf_area_check_free(ospf
, area_id
);
1775 DEFUN (ospf_area_export_list
,
1776 ospf_area_export_list_cmd
,
1777 "area <A.B.C.D|(0-4294967295)> export-list NAME",
1778 "OSPF area parameters\n"
1779 "OSPF area ID in IP address format\n"
1780 "OSPF area ID as a decimal value\n"
1781 "Set the filter for networks announced to other areas\n"
1782 "Name of the access-list\n")
1784 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1785 int idx_ipv4_number
= 1;
1786 struct ospf_area
*area
;
1787 struct in_addr area_id
;
1790 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1792 area
= ospf_area_get(ospf
, area_id
);
1793 ospf_area_display_format_set(ospf
, area
, format
);
1794 ospf_area_export_list_set(ospf
, area
, argv
[3]->arg
);
1799 DEFUN (no_ospf_area_export_list
,
1800 no_ospf_area_export_list_cmd
,
1801 "no area <A.B.C.D|(0-4294967295)> export-list NAME",
1803 "OSPF area parameters\n"
1804 "OSPF area ID in IP address format\n"
1805 "OSPF area ID as a decimal value\n"
1806 "Unset the filter for networks announced to other areas\n"
1807 "Name of the access-list\n")
1809 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1810 int idx_ipv4_number
= 2;
1811 struct ospf_area
*area
;
1812 struct in_addr area_id
;
1815 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1817 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1821 ospf_area_export_list_unset(ospf
, area
);
1827 DEFUN (ospf_area_import_list
,
1828 ospf_area_import_list_cmd
,
1829 "area <A.B.C.D|(0-4294967295)> import-list NAME",
1830 "OSPF area parameters\n"
1831 "OSPF area ID in IP address format\n"
1832 "OSPF area ID as a decimal value\n"
1833 "Set the filter for networks from other areas announced to the specified one\n"
1834 "Name of the access-list\n")
1836 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1837 int idx_ipv4_number
= 1;
1838 struct ospf_area
*area
;
1839 struct in_addr area_id
;
1842 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1844 area
= ospf_area_get(ospf
, area_id
);
1845 ospf_area_display_format_set(ospf
, area
, format
);
1846 ospf_area_import_list_set(ospf
, area
, argv
[3]->arg
);
1851 DEFUN (no_ospf_area_import_list
,
1852 no_ospf_area_import_list_cmd
,
1853 "no area <A.B.C.D|(0-4294967295)> import-list NAME",
1855 "OSPF area parameters\n"
1856 "OSPF area ID in IP address format\n"
1857 "OSPF area ID as a decimal value\n"
1858 "Unset the filter for networks announced to other areas\n"
1859 "Name of the access-list\n")
1861 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1862 int idx_ipv4_number
= 2;
1863 struct ospf_area
*area
;
1864 struct in_addr area_id
;
1867 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1869 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1873 ospf_area_import_list_unset(ospf
, area
);
1878 DEFUN (ospf_area_filter_list
,
1879 ospf_area_filter_list_cmd
,
1880 "area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>",
1881 "OSPF area parameters\n"
1882 "OSPF area ID in IP address format\n"
1883 "OSPF area ID as a decimal value\n"
1884 "Filter networks between OSPF areas\n"
1885 "Filter prefixes between OSPF areas\n"
1886 "Name of an IP prefix-list\n"
1887 "Filter networks sent to this area\n"
1888 "Filter networks sent from this area\n")
1890 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1891 int idx_ipv4_number
= 1;
1894 struct ospf_area
*area
;
1895 struct in_addr area_id
;
1896 struct prefix_list
*plist
;
1899 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1901 area
= ospf_area_get(ospf
, area_id
);
1902 ospf_area_display_format_set(ospf
, area
, format
);
1903 plist
= prefix_list_lookup(AFI_IP
, argv
[idx_word
]->arg
);
1904 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1905 PREFIX_LIST_IN(area
) = plist
;
1906 if (PREFIX_NAME_IN(area
))
1907 free(PREFIX_NAME_IN(area
));
1909 PREFIX_NAME_IN(area
) = strdup(argv
[idx_word
]->arg
);
1910 ospf_schedule_abr_task(ospf
);
1912 PREFIX_LIST_OUT(area
) = plist
;
1913 if (PREFIX_NAME_OUT(area
))
1914 free(PREFIX_NAME_OUT(area
));
1916 PREFIX_NAME_OUT(area
) = strdup(argv
[idx_word
]->arg
);
1917 ospf_schedule_abr_task(ospf
);
1923 DEFUN (no_ospf_area_filter_list
,
1924 no_ospf_area_filter_list_cmd
,
1925 "no area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>",
1927 "OSPF area parameters\n"
1928 "OSPF area ID in IP address format\n"
1929 "OSPF area ID as a decimal value\n"
1930 "Filter networks between OSPF areas\n"
1931 "Filter prefixes between OSPF areas\n"
1932 "Name of an IP prefix-list\n"
1933 "Filter networks sent to this area\n"
1934 "Filter networks sent from this area\n")
1936 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1937 int idx_ipv4_number
= 2;
1940 struct ospf_area
*area
;
1941 struct in_addr area_id
;
1944 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1946 if ((area
= ospf_area_lookup_by_area_id(ospf
, area_id
)) == NULL
)
1949 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1950 if (PREFIX_NAME_IN(area
))
1951 if (strcmp(PREFIX_NAME_IN(area
), argv
[idx_word
]->arg
)
1955 PREFIX_LIST_IN(area
) = NULL
;
1956 if (PREFIX_NAME_IN(area
))
1957 free(PREFIX_NAME_IN(area
));
1959 PREFIX_NAME_IN(area
) = NULL
;
1961 ospf_schedule_abr_task(ospf
);
1963 if (PREFIX_NAME_OUT(area
))
1964 if (strcmp(PREFIX_NAME_OUT(area
), argv
[idx_word
]->arg
)
1968 PREFIX_LIST_OUT(area
) = NULL
;
1969 if (PREFIX_NAME_OUT(area
))
1970 free(PREFIX_NAME_OUT(area
));
1972 PREFIX_NAME_OUT(area
) = NULL
;
1974 ospf_schedule_abr_task(ospf
);
1981 DEFUN (ospf_area_authentication_message_digest
,
1982 ospf_area_authentication_message_digest_cmd
,
1983 "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest",
1985 "OSPF area parameters\n"
1986 "OSPF area ID in IP address format\n"
1987 "OSPF area ID as a decimal value\n"
1988 "Enable authentication\n"
1989 "Use message-digest authentication\n")
1991 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1993 struct ospf_area
*area
;
1994 struct in_addr area_id
;
1997 argv_find(argv
, argc
, "area", &idx
);
1998 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx
+ 1]->arg
);
2000 area
= ospf_area_get(ospf
, area_id
);
2001 ospf_area_display_format_set(ospf
, area
, format
);
2002 area
->auth_type
= strmatch(argv
[0]->text
, "no")
2004 : OSPF_AUTH_CRYPTOGRAPHIC
;
2009 DEFUN (ospf_area_authentication
,
2010 ospf_area_authentication_cmd
,
2011 "area <A.B.C.D|(0-4294967295)> authentication",
2012 "OSPF area parameters\n"
2013 "OSPF area ID in IP address format\n"
2014 "OSPF area ID as a decimal value\n"
2015 "Enable authentication\n")
2017 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2018 int idx_ipv4_number
= 1;
2019 struct ospf_area
*area
;
2020 struct in_addr area_id
;
2023 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
2025 area
= ospf_area_get(ospf
, area_id
);
2026 ospf_area_display_format_set(ospf
, area
, format
);
2027 area
->auth_type
= OSPF_AUTH_SIMPLE
;
2032 DEFUN (no_ospf_area_authentication
,
2033 no_ospf_area_authentication_cmd
,
2034 "no area <A.B.C.D|(0-4294967295)> authentication",
2036 "OSPF area parameters\n"
2037 "OSPF area ID in IP address format\n"
2038 "OSPF area ID as a decimal value\n"
2039 "Enable authentication\n")
2041 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2042 int idx_ipv4_number
= 2;
2043 struct ospf_area
*area
;
2044 struct in_addr area_id
;
2047 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
2049 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
2053 area
->auth_type
= OSPF_AUTH_NULL
;
2055 ospf_area_check_free(ospf
, area_id
);
2061 DEFUN (ospf_abr_type
,
2063 "ospf abr-type <cisco|ibm|shortcut|standard>",
2064 "OSPF specific commands\n"
2065 "Set OSPF ABR type\n"
2066 "Alternative ABR, cisco implementation\n"
2067 "Alternative ABR, IBM implementation\n"
2069 "Standard behavior (RFC2328)\n")
2071 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2073 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2075 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2076 abr_type
= OSPF_ABR_CISCO
;
2077 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2078 abr_type
= OSPF_ABR_IBM
;
2079 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2080 abr_type
= OSPF_ABR_SHORTCUT
;
2081 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2082 abr_type
= OSPF_ABR_STAND
;
2084 return CMD_WARNING_CONFIG_FAILED
;
2086 /* If ABR type value is changed, schedule ABR task. */
2087 if (ospf
->abr_type
!= abr_type
) {
2088 ospf
->abr_type
= abr_type
;
2089 ospf_schedule_abr_task(ospf
);
2095 DEFUN (no_ospf_abr_type
,
2096 no_ospf_abr_type_cmd
,
2097 "no ospf abr-type <cisco|ibm|shortcut|standard>",
2099 "OSPF specific commands\n"
2100 "Set OSPF ABR type\n"
2101 "Alternative ABR, cisco implementation\n"
2102 "Alternative ABR, IBM implementation\n"
2106 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2108 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2110 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2111 abr_type
= OSPF_ABR_CISCO
;
2112 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2113 abr_type
= OSPF_ABR_IBM
;
2114 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2115 abr_type
= OSPF_ABR_SHORTCUT
;
2116 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2117 abr_type
= OSPF_ABR_STAND
;
2119 return CMD_WARNING_CONFIG_FAILED
;
2121 /* If ABR type value is changed, schedule ABR task. */
2122 if (ospf
->abr_type
== abr_type
) {
2123 ospf
->abr_type
= OSPF_ABR_DEFAULT
;
2124 ospf_schedule_abr_task(ospf
);
2130 DEFUN (ospf_log_adjacency_changes
,
2131 ospf_log_adjacency_changes_cmd
,
2132 "log-adjacency-changes",
2133 "Log changes in adjacency state\n")
2135 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2137 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2138 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2142 DEFUN (ospf_log_adjacency_changes_detail
,
2143 ospf_log_adjacency_changes_detail_cmd
,
2144 "log-adjacency-changes detail",
2145 "Log changes in adjacency state\n"
2146 "Log all state changes\n")
2148 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2150 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2151 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2155 DEFUN (no_ospf_log_adjacency_changes
,
2156 no_ospf_log_adjacency_changes_cmd
,
2157 "no log-adjacency-changes",
2159 "Log changes in adjacency state\n")
2161 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2163 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2164 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2168 DEFUN (no_ospf_log_adjacency_changes_detail
,
2169 no_ospf_log_adjacency_changes_detail_cmd
,
2170 "no log-adjacency-changes detail",
2172 "Log changes in adjacency state\n"
2173 "Log all state changes\n")
2175 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2177 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2181 DEFUN (ospf_compatible_rfc1583
,
2182 ospf_compatible_rfc1583_cmd
,
2183 "compatible rfc1583",
2184 "OSPF compatibility list\n"
2185 "compatible with RFC 1583\n")
2187 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2189 if (!CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2190 SET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2191 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2196 DEFUN (no_ospf_compatible_rfc1583
,
2197 no_ospf_compatible_rfc1583_cmd
,
2198 "no compatible rfc1583",
2200 "OSPF compatibility list\n"
2201 "compatible with RFC 1583\n")
2203 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2205 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2206 UNSET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2207 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2212 ALIAS(ospf_compatible_rfc1583
, ospf_rfc1583_flag_cmd
,
2213 "ospf rfc1583compatibility",
2214 "OSPF specific commands\n"
2215 "Enable the RFC1583Compatibility flag\n")
2217 ALIAS(no_ospf_compatible_rfc1583
, no_ospf_rfc1583_flag_cmd
,
2218 "no ospf rfc1583compatibility", NO_STR
2219 "OSPF specific commands\n"
2220 "Disable the RFC1583Compatibility flag\n")
2222 static int ospf_timers_spf_set(struct vty
*vty
, unsigned int delay
,
2223 unsigned int hold
, unsigned int max
)
2225 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2227 ospf
->spf_delay
= delay
;
2228 ospf
->spf_holdtime
= hold
;
2229 ospf
->spf_max_holdtime
= max
;
2234 DEFUN (ospf_timers_min_ls_interval
,
2235 ospf_timers_min_ls_interval_cmd
,
2236 "timers throttle lsa all (0-5000)",
2237 "Adjust routing timers\n"
2238 "Throttling adaptive timer\n"
2239 "LSA delay between transmissions\n"
2241 "Delay (msec) between sending LSAs\n")
2243 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2245 unsigned int interval
;
2248 vty_out(vty
, "Insufficient arguments\n");
2249 return CMD_WARNING_CONFIG_FAILED
;
2252 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2254 ospf
->min_ls_interval
= interval
;
2259 DEFUN (no_ospf_timers_min_ls_interval
,
2260 no_ospf_timers_min_ls_interval_cmd
,
2261 "no timers throttle lsa all [(0-5000)]",
2263 "Adjust routing timers\n"
2264 "Throttling adaptive timer\n"
2265 "LSA delay between transmissions\n"
2267 "Delay (msec) between sending LSAs\n")
2269 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2270 ospf
->min_ls_interval
= OSPF_MIN_LS_INTERVAL
;
2275 DEFUN (ospf_timers_throttle_spf
,
2276 ospf_timers_throttle_spf_cmd
,
2277 "timers throttle spf (0-600000) (0-600000) (0-600000)",
2278 "Adjust routing timers\n"
2279 "Throttling adaptive timer\n"
2281 "Delay (msec) from first change received till SPF calculation\n"
2282 "Initial hold time (msec) between consecutive SPF calculations\n"
2283 "Maximum hold time (msec)\n")
2286 int idx_number_2
= 4;
2287 int idx_number_3
= 5;
2288 unsigned int delay
, hold
, max
;
2291 vty_out(vty
, "Insufficient arguments\n");
2292 return CMD_WARNING_CONFIG_FAILED
;
2295 delay
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2296 hold
= strtoul(argv
[idx_number_2
]->arg
, NULL
, 10);
2297 max
= strtoul(argv
[idx_number_3
]->arg
, NULL
, 10);
2299 return ospf_timers_spf_set(vty
, delay
, hold
, max
);
2302 DEFUN (no_ospf_timers_throttle_spf
,
2303 no_ospf_timers_throttle_spf_cmd
,
2304 "no timers throttle spf [(0-600000)(0-600000)(0-600000)]",
2306 "Adjust routing timers\n"
2307 "Throttling adaptive timer\n"
2309 "Delay (msec) from first change received till SPF calculation\n"
2310 "Initial hold time (msec) between consecutive SPF calculations\n"
2311 "Maximum hold time (msec)\n")
2313 return ospf_timers_spf_set(vty
, OSPF_SPF_DELAY_DEFAULT
,
2314 OSPF_SPF_HOLDTIME_DEFAULT
,
2315 OSPF_SPF_MAX_HOLDTIME_DEFAULT
);
2319 DEFUN (ospf_timers_lsa_min_arrival
,
2320 ospf_timers_lsa_min_arrival_cmd
,
2321 "timers lsa min-arrival (0-600000)",
2322 "Adjust routing timers\n"
2324 "Minimum delay in receiving new version of a LSA\n"
2325 "Delay in milliseconds\n")
2327 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2328 ospf
->min_ls_arrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2332 DEFUN (no_ospf_timers_lsa_min_arrival
,
2333 no_ospf_timers_lsa_min_arrival_cmd
,
2334 "no timers lsa min-arrival [(0-600000)]",
2336 "Adjust routing timers\n"
2338 "Minimum delay in receiving new version of a LSA\n"
2339 "Delay in milliseconds\n")
2341 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2342 unsigned int minarrival
;
2345 minarrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2347 if (ospf
->min_ls_arrival
!= minarrival
2348 || minarrival
== OSPF_MIN_LS_ARRIVAL
)
2352 ospf
->min_ls_arrival
= OSPF_MIN_LS_ARRIVAL
;
2357 DEFUN (ospf_neighbor
,
2359 "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]",
2361 "Neighbor IP address\n"
2362 "Neighbor Priority\n"
2364 "Dead Neighbor Polling interval\n"
2367 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2371 struct in_addr nbr_addr
;
2372 unsigned int priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2373 unsigned int interval
= OSPF_POLL_INTERVAL_DEFAULT
;
2375 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2376 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2377 return CMD_WARNING_CONFIG_FAILED
;
2381 priority
= strtoul(argv
[idx_pri
]->arg
, NULL
, 10);
2384 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2386 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2389 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2392 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2397 DEFUN (ospf_neighbor_poll_interval
,
2398 ospf_neighbor_poll_interval_cmd
,
2399 "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2401 "Neighbor IP address\n"
2402 "Dead Neighbor Polling interval\n"
2404 "OSPF priority of non-broadcast neighbor\n"
2407 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2411 struct in_addr nbr_addr
;
2412 unsigned int priority
;
2413 unsigned int interval
;
2415 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2416 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2417 return CMD_WARNING_CONFIG_FAILED
;
2420 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2422 priority
= argc
> 4 ? strtoul(argv
[idx_pri
]->arg
, NULL
, 10)
2423 : OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2425 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2426 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2429 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2434 DEFUN (no_ospf_neighbor
,
2435 no_ospf_neighbor_cmd
,
2436 "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]",
2439 "Neighbor IP address\n"
2440 "Neighbor Priority\n"
2442 "Dead Neighbor Polling interval\n"
2445 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2447 struct in_addr nbr_addr
;
2449 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2450 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2451 return CMD_WARNING_CONFIG_FAILED
;
2454 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2459 DEFUN (no_ospf_neighbor_poll
,
2460 no_ospf_neighbor_poll_cmd
,
2461 "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2464 "Neighbor IP address\n"
2465 "Dead Neighbor Polling interval\n"
2467 "Neighbor Priority\n"
2470 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2472 struct in_addr nbr_addr
;
2474 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2475 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2476 return CMD_WARNING_CONFIG_FAILED
;
2479 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2484 DEFUN (ospf_refresh_timer
,
2485 ospf_refresh_timer_cmd
,
2486 "refresh timer (10-1800)",
2487 "Adjust refresh parameters\n"
2488 "Set refresh timer\n"
2489 "Timer value in seconds\n")
2491 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2493 unsigned int interval
;
2495 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2496 interval
= (interval
/ OSPF_LSA_REFRESHER_GRANULARITY
)
2497 * OSPF_LSA_REFRESHER_GRANULARITY
;
2499 ospf_timers_refresh_set(ospf
, interval
);
2504 DEFUN (no_ospf_refresh_timer
,
2505 no_ospf_refresh_timer_val_cmd
,
2506 "no refresh timer [(10-1800)]",
2508 "Adjust refresh parameters\n"
2509 "Unset refresh timer\n"
2510 "Timer value in seconds\n")
2512 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2514 unsigned int interval
;
2517 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2519 if (ospf
->lsa_refresh_interval
!= interval
2520 || interval
== OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
2524 ospf_timers_refresh_unset(ospf
);
2530 DEFUN (ospf_auto_cost_reference_bandwidth
,
2531 ospf_auto_cost_reference_bandwidth_cmd
,
2532 "auto-cost reference-bandwidth (1-4294967)",
2533 "Calculate OSPF interface cost according to bandwidth\n"
2534 "Use reference bandwidth method to assign OSPF cost\n"
2535 "The reference bandwidth in terms of Mbits per second\n")
2537 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2538 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2541 struct interface
*ifp
;
2543 refbw
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2544 if (refbw
< 1 || refbw
> 4294967) {
2545 vty_out(vty
, "reference-bandwidth value is invalid\n");
2546 return CMD_WARNING_CONFIG_FAILED
;
2549 /* If reference bandwidth is changed. */
2550 if ((refbw
) == ospf
->ref_bandwidth
)
2553 ospf
->ref_bandwidth
= refbw
;
2554 FOR_ALL_INTERFACES (vrf
, ifp
)
2555 ospf_if_recalculate_output_cost(ifp
);
2560 DEFUN (no_ospf_auto_cost_reference_bandwidth
,
2561 no_ospf_auto_cost_reference_bandwidth_cmd
,
2562 "no auto-cost reference-bandwidth [(1-4294967)]",
2564 "Calculate OSPF interface cost according to bandwidth\n"
2565 "Use reference bandwidth method to assign OSPF cost\n"
2566 "The reference bandwidth in terms of Mbits per second\n")
2568 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2569 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2570 struct interface
*ifp
;
2572 if (ospf
->ref_bandwidth
== OSPF_DEFAULT_REF_BANDWIDTH
)
2575 ospf
->ref_bandwidth
= OSPF_DEFAULT_REF_BANDWIDTH
;
2576 vty_out(vty
, "%% OSPF: Reference bandwidth is changed.\n");
2578 " Please ensure reference bandwidth is consistent across all routers\n");
2580 FOR_ALL_INTERFACES (vrf
, ifp
)
2581 ospf_if_recalculate_output_cost(ifp
);
2586 DEFUN (ospf_write_multiplier
,
2587 ospf_write_multiplier_cmd
,
2588 "ospf write-multiplier (1-100)",
2589 "OSPF specific commands\n"
2590 "Write multiplier\n"
2591 "Maximum number of interface serviced per write\n")
2593 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2595 uint32_t write_oi_count
;
2602 write_oi_count
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2603 if (write_oi_count
< 1 || write_oi_count
> 100) {
2604 vty_out(vty
, "write-multiplier value is invalid\n");
2605 return CMD_WARNING_CONFIG_FAILED
;
2608 ospf
->write_oi_count
= write_oi_count
;
2612 ALIAS(ospf_write_multiplier
, write_multiplier_cmd
, "write-multiplier (1-100)",
2613 "Write multiplier\n"
2614 "Maximum number of interface serviced per write\n")
2616 DEFUN (no_ospf_write_multiplier
,
2617 no_ospf_write_multiplier_cmd
,
2618 "no ospf write-multiplier (1-100)",
2620 "OSPF specific commands\n"
2621 "Write multiplier\n"
2622 "Maximum number of interface serviced per write\n")
2624 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2626 ospf
->write_oi_count
= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
;
2630 ALIAS(no_ospf_write_multiplier
, no_write_multiplier_cmd
,
2631 "no write-multiplier (1-100)", NO_STR
2632 "Write multiplier\n"
2633 "Maximum number of interface serviced per write\n")
2635 static const char *const ospf_abr_type_descr_str
[] = {
2636 "Unknown", "Standard (RFC2328)", "Alternative IBM",
2637 "Alternative Cisco", "Alternative Shortcut"
2640 static const char *const ospf_shortcut_mode_descr_str
[] = {
2641 "Default", "Enabled", "Disabled"
2644 static void show_ip_ospf_area(struct vty
*vty
, struct ospf_area
*area
,
2645 json_object
*json_areas
, bool use_json
)
2647 json_object
*json_area
= NULL
;
2650 json_area
= json_object_new_object();
2654 vty_out(vty
, " Area ID: %s", inet_ntoa(area
->area_id
));
2656 /* Show Area type/mode. */
2657 if (OSPF_IS_AREA_BACKBONE(area
)) {
2659 json_object_boolean_true_add(json_area
, "backbone");
2661 vty_out(vty
, " (Backbone)\n");
2664 if (area
->external_routing
== OSPF_AREA_STUB
) {
2665 if (area
->no_summary
)
2666 json_object_boolean_true_add(
2667 json_area
, "stubNoSummary");
2668 if (area
->shortcut_configured
)
2669 json_object_boolean_true_add(
2670 json_area
, "stubShortcut");
2671 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
2672 if (area
->no_summary
)
2673 json_object_boolean_true_add(
2674 json_area
, "nssaNoSummary");
2675 if (area
->shortcut_configured
)
2676 json_object_boolean_true_add(
2677 json_area
, "nssaShortcut");
2680 json_object_string_add(
2681 json_area
, "shortcuttingMode",
2682 ospf_shortcut_mode_descr_str
2683 [area
->shortcut_configured
]);
2684 if (area
->shortcut_capability
)
2685 json_object_boolean_true_add(json_area
,
2688 if (area
->external_routing
== OSPF_AREA_STUB
)
2689 vty_out(vty
, " (Stub%s%s)",
2690 area
->no_summary
? ", no summary" : "",
2691 area
->shortcut_configured
? "; " : "");
2692 else if (area
->external_routing
== OSPF_AREA_NSSA
)
2693 vty_out(vty
, " (NSSA%s%s)",
2694 area
->no_summary
? ", no summary" : "",
2695 area
->shortcut_configured
? "; " : "");
2698 vty_out(vty
, " Shortcutting mode: %s",
2699 ospf_shortcut_mode_descr_str
2700 [area
->shortcut_configured
]);
2701 vty_out(vty
, ", S-bit consensus: %s\n",
2702 area
->shortcut_capability
? "ok" : "no");
2706 /* Show number of interfaces */
2708 json_object_int_add(json_area
, "areaIfTotalCounter",
2709 listcount(area
->oiflist
));
2710 json_object_int_add(json_area
, "areaIfActiveCounter",
2714 " Number of interfaces in this area: Total: %d, "
2716 listcount(area
->oiflist
), area
->act_ints
);
2718 if (area
->external_routing
== OSPF_AREA_NSSA
) {
2720 json_object_boolean_true_add(json_area
, "nssa");
2721 if (!IS_OSPF_ABR(area
->ospf
))
2722 json_object_boolean_false_add(json_area
, "abr");
2723 else if (area
->NSSATranslatorState
) {
2724 json_object_boolean_true_add(json_area
, "abr");
2725 if (area
->NSSATranslatorRole
2726 == OSPF_NSSA_ROLE_CANDIDATE
)
2727 json_object_boolean_true_add(
2729 "nssaTranslatorElected");
2730 else if (area
->NSSATranslatorRole
2731 == OSPF_NSSA_ROLE_ALWAYS
)
2732 json_object_boolean_true_add(
2734 "nssaTranslatorAlways");
2736 json_object_boolean_true_add(json_area
, "abr");
2737 if (area
->NSSATranslatorRole
2738 == OSPF_NSSA_ROLE_CANDIDATE
)
2739 json_object_boolean_false_add(
2741 "nssaTranslatorElected");
2743 json_object_boolean_true_add(
2745 "nssaTranslatorNever");
2749 " It is an NSSA configuration. \n Elected NSSA/ABR performs type-7/type-5 LSA translation. \n");
2750 if (!IS_OSPF_ABR(area
->ospf
))
2752 " It is not ABR, therefore not Translator. \n");
2753 else if (area
->NSSATranslatorState
) {
2754 vty_out(vty
, " We are an ABR and ");
2755 if (area
->NSSATranslatorRole
2756 == OSPF_NSSA_ROLE_CANDIDATE
)
2758 "the NSSA Elected Translator. \n");
2759 else if (area
->NSSATranslatorRole
2760 == OSPF_NSSA_ROLE_ALWAYS
)
2762 "always an NSSA Translator. \n");
2764 vty_out(vty
, " We are an ABR, but ");
2765 if (area
->NSSATranslatorRole
2766 == OSPF_NSSA_ROLE_CANDIDATE
)
2768 "not the NSSA Elected Translator. \n");
2771 "never an NSSA Translator. \n");
2776 /* Stub-router state for this area */
2777 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
)) {
2778 char timebuf
[OSPF_TIME_DUMP_SIZE
];
2781 json_object_boolean_true_add(
2782 json_area
, "originStubMaxDistRouterLsa");
2783 if (CHECK_FLAG(area
->stub_router_state
,
2784 OSPF_AREA_ADMIN_STUB_ROUTED
))
2785 json_object_boolean_true_add(
2786 json_area
, "indefiniteActiveAdmin");
2787 if (area
->t_stub_router
) {
2791 &area
->t_stub_router
->u
.sands
,
2794 json_object_int_add(
2796 "activeStartupRemainderMsecs",
2801 " Originating stub / maximum-distance Router-LSA\n");
2802 if (CHECK_FLAG(area
->stub_router_state
,
2803 OSPF_AREA_ADMIN_STUB_ROUTED
))
2805 " Administratively activated (indefinitely)\n");
2806 if (area
->t_stub_router
)
2808 " Active from startup, %s remaining\n",
2809 ospf_timer_dump(area
->t_stub_router
,
2816 /* Show number of fully adjacent neighbors. */
2817 json_object_int_add(json_area
, "nbrFullAdjacentCounter",
2820 /* Show authentication type. */
2821 if (area
->auth_type
== OSPF_AUTH_NULL
)
2822 json_object_string_add(json_area
, "authentication",
2823 "authenticationNone");
2824 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2825 json_object_string_add(json_area
, "authentication",
2826 "authenticationSimplePassword");
2827 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2828 json_object_string_add(json_area
, "authentication",
2829 "authenticationMessageDigest");
2831 if (!OSPF_IS_AREA_BACKBONE(area
))
2832 json_object_int_add(json_area
,
2833 "virtualAdjacenciesPassingCounter",
2836 /* Show SPF calculation times. */
2837 json_object_int_add(json_area
, "spfExecutedCounter",
2838 area
->spf_calculation
);
2839 json_object_int_add(json_area
, "lsaNumber", area
->lsdb
->total
);
2840 json_object_int_add(
2841 json_area
, "lsaRouterNumber",
2842 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
));
2843 json_object_int_add(
2844 json_area
, "lsaRouterChecksum",
2845 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
2846 json_object_int_add(
2847 json_area
, "lsaNetworkNumber",
2848 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
));
2849 json_object_int_add(
2850 json_area
, "lsaNetworkChecksum",
2851 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
2852 json_object_int_add(
2853 json_area
, "lsaSummaryNumber",
2854 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
));
2855 json_object_int_add(
2856 json_area
, "lsaSummaryChecksum",
2857 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
2858 json_object_int_add(
2859 json_area
, "lsaAsbrNumber",
2860 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2861 json_object_int_add(
2862 json_area
, "lsaAsbrChecksum",
2863 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2864 json_object_int_add(
2865 json_area
, "lsaNssaNumber",
2866 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2867 json_object_int_add(
2868 json_area
, "lsaNssaChecksum",
2869 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2871 /* Show number of fully adjacent neighbors. */
2873 " Number of fully adjacent neighbors in this area:"
2877 /* Show authentication type. */
2878 vty_out(vty
, " Area has ");
2879 if (area
->auth_type
== OSPF_AUTH_NULL
)
2880 vty_out(vty
, "no authentication\n");
2881 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2882 vty_out(vty
, "simple password authentication\n");
2883 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2884 vty_out(vty
, "message digest authentication\n");
2886 if (!OSPF_IS_AREA_BACKBONE(area
))
2888 " Number of full virtual adjacencies going through"
2892 /* Show SPF calculation times. */
2893 vty_out(vty
, " SPF algorithm executed %d times\n",
2894 area
->spf_calculation
);
2896 /* Show number of LSA. */
2897 vty_out(vty
, " Number of LSA %ld\n", area
->lsdb
->total
);
2899 " Number of router LSA %ld. Checksum Sum 0x%08x\n",
2900 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
),
2901 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
2903 " Number of network LSA %ld. Checksum Sum 0x%08x\n",
2904 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
),
2905 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
2907 " Number of summary LSA %ld. Checksum Sum 0x%08x\n",
2908 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
),
2909 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
2911 " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n",
2912 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
),
2913 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2914 vty_out(vty
, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n",
2915 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
),
2916 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2920 json_object_int_add(
2921 json_area
, "lsaOpaqueLinkNumber",
2922 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
2923 json_object_int_add(
2924 json_area
, "lsaOpaqueLinkChecksum",
2925 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
2926 json_object_int_add(
2927 json_area
, "lsaOpaqueAreaNumber",
2928 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
2929 json_object_int_add(
2930 json_area
, "lsaOpaqueAreaChecksum",
2931 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
2934 " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n",
2935 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
),
2936 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
2938 " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n",
2939 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
),
2940 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
2944 json_object_object_add(json_areas
, inet_ntoa(area
->area_id
),
2950 static int show_ip_ospf_common(struct vty
*vty
, struct ospf
*ospf
,
2951 json_object
*json
, uint8_t use_vrf
)
2953 struct listnode
*node
, *nnode
;
2954 struct ospf_area
*area
;
2955 struct timeval result
;
2956 char timebuf
[OSPF_TIME_DUMP_SIZE
];
2957 json_object
*json_vrf
= NULL
;
2958 json_object
*json_areas
= NULL
;
2962 json_vrf
= json_object_new_object();
2965 json_areas
= json_object_new_object();
2968 if (ospf
->instance
) {
2970 json_object_int_add(json
, "ospfInstance",
2973 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
2977 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
2979 /* Show Router ID. */
2981 json_object_string_add(json_vrf
, "routerId",
2982 inet_ntoa(ospf
->router_id
));
2984 vty_out(vty
, " OSPF Routing Process, Router ID: %s\n",
2985 inet_ntoa(ospf
->router_id
));
2988 /* Graceful shutdown */
2989 if (ospf
->t_deferred_shutdown
) {
2994 &ospf
->t_deferred_shutdown
->u
.sands
,
2997 json_object_int_add(json_vrf
, "deferredShutdownMsecs",
3001 " Deferred shutdown in progress, %s remaining\n",
3002 ospf_timer_dump(ospf
->t_deferred_shutdown
,
3003 timebuf
, sizeof(timebuf
)));
3007 /* Show capability. */
3009 json_object_boolean_true_add(json_vrf
, "tosRoutesOnly");
3010 json_object_boolean_true_add(json_vrf
, "rfc2328Conform");
3011 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
3012 json_object_boolean_true_add(json_vrf
,
3013 "rfc1583Compatibility");
3016 vty_out(vty
, " Supports only single TOS (TOS0) routes\n");
3017 vty_out(vty
, " This implementation conforms to RFC2328\n");
3018 vty_out(vty
, " RFC1583Compatibility flag is %s\n",
3019 CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)
3025 if (CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)) {
3026 json_object_boolean_true_add(json_vrf
, "opaqueCapable");
3029 vty_out(vty
, " OpaqueCapability flag is %s\n",
3030 CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)
3035 /* Show stub-router configuration */
3036 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
3037 || ospf
->stub_router_shutdown_time
3038 != OSPF_STUB_ROUTER_UNCONFIGURED
) {
3040 json_object_boolean_true_add(json_vrf
,
3041 "stubAdvertisement");
3042 if (ospf
->stub_router_startup_time
3043 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3044 json_object_int_add(
3045 json_vrf
, "postStartEnabledSecs",
3046 ospf
->stub_router_startup_time
);
3047 if (ospf
->stub_router_shutdown_time
3048 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3049 json_object_int_add(
3050 json_vrf
, "preShutdownEnabledSecs",
3051 ospf
->stub_router_shutdown_time
);
3054 " Stub router advertisement is configured\n");
3055 if (ospf
->stub_router_startup_time
3056 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3058 " Enabled for %us after start-up\n",
3059 ospf
->stub_router_startup_time
);
3060 if (ospf
->stub_router_shutdown_time
3061 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3063 " Enabled for %us prior to full shutdown\n",
3064 ospf
->stub_router_shutdown_time
);
3068 /* Show SPF timers. */
3070 json_object_int_add(json_vrf
, "spfScheduleDelayMsecs",
3072 json_object_int_add(json_vrf
, "holdtimeMinMsecs",
3073 ospf
->spf_holdtime
);
3074 json_object_int_add(json_vrf
, "holdtimeMaxMsecs",
3075 ospf
->spf_max_holdtime
);
3076 json_object_int_add(json_vrf
, "holdtimeMultplier",
3077 ospf
->spf_hold_multiplier
);
3080 " Initial SPF scheduling delay %d millisec(s)\n"
3081 " Minimum hold time between consecutive SPFs %d millisec(s)\n"
3082 " Maximum hold time between consecutive SPFs %d millisec(s)\n"
3083 " Hold time multiplier is currently %d\n",
3084 ospf
->spf_delay
, ospf
->spf_holdtime
,
3085 ospf
->spf_max_holdtime
, ospf
->spf_hold_multiplier
);
3089 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3090 long time_store
= 0;
3093 monotime_since(&ospf
->ts_spf
, NULL
) / 1000LL;
3094 json_object_int_add(json_vrf
, "spfLastExecutedMsecs",
3097 time_store
= (1000 * ospf
->ts_spf_duration
.tv_sec
)
3098 + (ospf
->ts_spf_duration
.tv_usec
/ 1000);
3099 json_object_int_add(json_vrf
, "spfLastDurationMsecs",
3102 json_object_boolean_true_add(json_vrf
, "spfHasNotRun");
3104 vty_out(vty
, " SPF algorithm ");
3105 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3106 monotime_since(&ospf
->ts_spf
, &result
);
3107 vty_out(vty
, "last executed %s ago\n",
3108 ospf_timeval_dump(&result
, timebuf
,
3110 vty_out(vty
, " Last SPF duration %s\n",
3111 ospf_timeval_dump(&ospf
->ts_spf_duration
,
3112 timebuf
, sizeof(timebuf
)));
3114 vty_out(vty
, "has not been run\n");
3118 if (ospf
->t_spf_calc
) {
3121 monotime_until(&ospf
->t_spf_calc
->u
.sands
, NULL
)
3123 json_object_int_add(json_vrf
, "spfTimerDueInMsecs",
3127 json_object_int_add(json_vrf
, "lsaMinIntervalMsecs",
3128 ospf
->min_ls_interval
);
3129 json_object_int_add(json_vrf
, "lsaMinArrivalMsecs",
3130 ospf
->min_ls_arrival
);
3131 /* Show write multiplier values */
3132 json_object_int_add(json_vrf
, "writeMultiplier",
3133 ospf
->write_oi_count
);
3134 /* Show refresh parameters. */
3135 json_object_int_add(json_vrf
, "refreshTimerMsecs",
3136 ospf
->lsa_refresh_interval
* 1000);
3138 vty_out(vty
, " SPF timer %s%s\n",
3139 (ospf
->t_spf_calc
? "due in " : "is "),
3140 ospf_timer_dump(ospf
->t_spf_calc
, timebuf
,
3143 vty_out(vty
, " LSA minimum interval %d msecs\n",
3144 ospf
->min_ls_interval
);
3145 vty_out(vty
, " LSA minimum arrival %d msecs\n",
3146 ospf
->min_ls_arrival
);
3148 /* Show write multiplier values */
3149 vty_out(vty
, " Write Multiplier set to %d \n",
3150 ospf
->write_oi_count
);
3152 /* Show refresh parameters. */
3153 vty_out(vty
, " Refresh timer %d secs\n",
3154 ospf
->lsa_refresh_interval
);
3157 /* Show ABR/ASBR flags. */
3158 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ABR
)) {
3160 json_object_string_add(
3161 json_vrf
, "abrType",
3162 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3165 " This router is an ABR, ABR type is: %s\n",
3166 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3168 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ASBR
)) {
3170 json_object_string_add(
3171 json_vrf
, "asbrRouter",
3172 "injectingExternalRoutingInformation");
3175 " This router is an ASBR "
3176 "(injecting external routing information)\n");
3179 /* Show Number of AS-external-LSAs. */
3181 json_object_int_add(
3182 json_vrf
, "lsaExternalCounter",
3183 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3184 json_object_int_add(
3185 json_vrf
, "lsaExternalChecksum",
3186 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3189 " Number of external LSA %ld. Checksum Sum 0x%08x\n",
3190 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
),
3191 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3195 json_object_int_add(
3196 json_vrf
, "lsaAsopaqueCounter",
3197 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3198 json_object_int_add(
3199 json_vrf
, "lsaAsOpaqueChecksum",
3200 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3203 " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n",
3204 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
),
3205 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3208 /* Show number of areas attached. */
3210 json_object_int_add(json_vrf
, "attachedAreaCounter",
3211 listcount(ospf
->areas
));
3213 vty_out(vty
, " Number of areas attached to this router: %d\n",
3214 listcount(ospf
->areas
));
3216 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
3217 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
)) {
3219 json_object_boolean_true_add(
3220 json_vrf
, "adjacencyChangesLoggedAll");
3223 " All adjacency changes are logged\n");
3226 json_object_boolean_true_add(
3227 json_vrf
, "adjacencyChangesLogged");
3229 vty_out(vty
, " Adjacency changes are logged\n");
3232 /* Show each area status. */
3233 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
3234 show_ip_ospf_area(vty
, area
, json_areas
, json
? 1 : 0);
3238 json_object_object_add(json_vrf
, "areas", json_areas
);
3239 if (ospf
->vrf_id
== VRF_DEFAULT
)
3240 json_object_object_add(json
, "default",
3243 json_object_object_add(json
, ospf
->name
,
3246 json_object_object_add(json
, "areas", json_areas
);
3254 DEFUN (show_ip_ospf
,
3256 "show ip ospf [vrf <NAME|all>] [json]",
3259 "OSPF information\n"
3265 bool uj
= use_json(argc
, argv
);
3266 struct listnode
*node
= NULL
;
3267 char *vrf_name
= NULL
;
3268 bool all_vrf
= false;
3269 int ret
= CMD_SUCCESS
;
3272 json_object
*json
= NULL
;
3273 uint8_t use_vrf
= 0;
3275 if (listcount(om
->ospf
) == 0)
3278 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
3281 json
= json_object_new_object();
3283 /* vrf input is provided could be all or specific vrf*/
3285 bool ospf_output
= false;
3290 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
3291 if (!ospf
->oi_running
)
3294 ret
= show_ip_ospf_common(vty
, ospf
, json
,
3298 vty_out(vty
, "%s\n",
3299 json_object_to_json_string_ext(
3300 json
, JSON_C_TO_STRING_PRETTY
));
3301 json_object_free(json
);
3302 } else if (!ospf_output
)
3303 vty_out(vty
, "%% OSPF instance not found\n");
3306 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
3307 if ((ospf
== NULL
) || !ospf
->oi_running
) {
3309 vty_out(vty
, "%s\n",
3310 json_object_to_json_string_ext(
3311 json
, JSON_C_TO_STRING_PRETTY
));
3312 json_object_free(json
);
3314 vty_out(vty
, "%% OSPF instance not found\n");
3319 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
3320 /* Display default ospf (instance 0) info */
3321 if (ospf
== NULL
|| !ospf
->oi_running
) {
3323 vty_out(vty
, "%s\n",
3324 json_object_to_json_string_ext(
3325 json
, JSON_C_TO_STRING_PRETTY
));
3326 json_object_free(json
);
3328 vty_out(vty
, "%% OSPF instance not found\n");
3335 show_ip_ospf_common(vty
, ospf
, json
, use_vrf
);
3337 vty_out(vty
, "%s\n",
3338 json_object_to_json_string_ext(
3339 json
, JSON_C_TO_STRING_PRETTY
));
3343 json_object_free(json
);
3348 DEFUN (show_ip_ospf_instance
,
3349 show_ip_ospf_instance_cmd
,
3350 "show ip ospf (1-65535) [json]",
3353 "OSPF information\n"
3359 unsigned short instance
= 0;
3360 bool uj
= use_json(argc
, argv
);
3361 int ret
= CMD_SUCCESS
;
3362 json_object
*json
= NULL
;
3364 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
3365 ospf
= ospf_lookup_instance(instance
);
3367 return CMD_NOT_MY_INSTANCE
;
3369 if (!ospf
->oi_running
)
3373 json
= json_object_new_object();
3375 ret
= show_ip_ospf_common(vty
, ospf
, json
, 0);
3378 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
3379 json
, JSON_C_TO_STRING_PRETTY
));
3380 json_object_free(json
);
3386 static void show_ip_ospf_interface_sub(struct vty
*vty
, struct ospf
*ospf
,
3387 struct interface
*ifp
,
3388 json_object
*json_interface_sub
,
3392 struct ospf_neighbor
*nbr
;
3393 struct route_node
*rn
;
3394 uint32_t bandwidth
= ifp
->bandwidth
? ifp
->bandwidth
: ifp
->speed
;
3396 /* Is interface up? */
3398 is_up
= if_is_operative(ifp
);
3400 json_object_boolean_true_add(json_interface_sub
,
3403 json_object_boolean_false_add(json_interface_sub
,
3406 json_object_int_add(json_interface_sub
, "ifIndex",
3408 json_object_int_add(json_interface_sub
, "mtuBytes", ifp
->mtu
);
3409 json_object_int_add(json_interface_sub
, "bandwidthMbit",
3411 json_object_string_add(json_interface_sub
, "ifFlags",
3412 if_flag_dump(ifp
->flags
));
3414 vty_out(vty
, "%s is %s\n", ifp
->name
,
3415 ((is_up
= if_is_operative(ifp
)) ? "up" : "down"));
3416 vty_out(vty
, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n",
3417 ifp
->ifindex
, ifp
->mtu
, bandwidth
,
3418 if_flag_dump(ifp
->flags
));
3421 /* Is interface OSPF enabled? */
3423 if (ospf_oi_count(ifp
) == 0) {
3424 json_object_boolean_false_add(json_interface_sub
,
3427 } else if (!is_up
) {
3428 json_object_boolean_false_add(json_interface_sub
,
3432 json_object_boolean_true_add(json_interface_sub
,
3435 if (ospf_oi_count(ifp
) == 0) {
3436 vty_out(vty
, " OSPF not enabled on this interface\n");
3438 } else if (!is_up
) {
3440 " OSPF is enabled, but not running on this interface\n");
3445 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
3446 struct ospf_interface
*oi
= rn
->info
;
3451 if (CHECK_FLAG(oi
->connected
->flags
, ZEBRA_IFA_UNNUMBERED
)) {
3453 json_object_boolean_true_add(json_interface_sub
,
3456 vty_out(vty
, " This interface is UNNUMBERED,");
3458 struct in_addr dest
;
3461 /* Show OSPF interface information. */
3463 json_object_string_add(
3464 json_interface_sub
, "ipAddress",
3465 inet_ntoa(oi
->address
->u
.prefix4
));
3466 json_object_int_add(json_interface_sub
,
3467 "ipAddressPrefixlen",
3468 oi
->address
->prefixlen
);
3470 vty_out(vty
, " Internet Address %s/%d,",
3471 inet_ntoa(oi
->address
->u
.prefix4
),
3472 oi
->address
->prefixlen
);
3474 /* For Vlinks, showing the peer address is
3475 * probably more informative than the local
3476 * interface that is being used */
3477 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
) {
3479 dest
= oi
->vl_data
->peer_addr
;
3480 } else if (CONNECTED_PEER(oi
->connected
)
3481 && oi
->connected
->destination
) {
3483 dest
= oi
->connected
->destination
->u
.prefix4
;
3486 dest
.s_addr
= ipv4_broadcast_addr(
3487 oi
->connected
->address
->u
.prefix4
.s_addr
,
3488 oi
->connected
->address
->prefixlen
);
3492 json_object_string_add(
3494 "ospfIfType", dstr
);
3495 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3496 json_object_string_add(
3501 json_object_string_add(
3506 vty_out(vty
, " %s %s,", dstr
,
3510 json_object_string_add(json_interface_sub
, "area",
3511 ospf_area_desc_string(oi
->area
));
3512 if (OSPF_IF_PARAM(oi
, mtu_ignore
))
3513 json_object_boolean_true_add(
3515 "mtuMismatchDetect");
3516 json_object_string_add(json_interface_sub
, "routerId",
3517 inet_ntoa(ospf
->router_id
));
3518 json_object_string_add(json_interface_sub
,
3520 ospf_network_type_str
[oi
->type
]);
3521 json_object_int_add(json_interface_sub
, "cost",
3523 json_object_int_add(
3524 json_interface_sub
, "transmitDelaySecs",
3525 OSPF_IF_PARAM(oi
, transmit_delay
));
3526 json_object_string_add(json_interface_sub
, "state",
3527 lookup_msg(ospf_ism_state_msg
,
3529 json_object_int_add(json_interface_sub
, "priority",
3532 vty_out(vty
, " Area %s\n",
3533 ospf_area_desc_string(oi
->area
));
3535 vty_out(vty
, " MTU mismatch detection: %s\n",
3536 OSPF_IF_PARAM(oi
, mtu_ignore
) ? "disabled"
3540 " Router ID %s, Network Type %s, Cost: %d\n",
3541 inet_ntoa(ospf
->router_id
),
3542 ospf_network_type_str
[oi
->type
],
3546 " Transmit Delay is %d sec, State %s, Priority %d\n",
3547 OSPF_IF_PARAM(oi
, transmit_delay
),
3548 lookup_msg(ospf_ism_state_msg
, oi
->state
, NULL
),
3552 /* Show DR information. */
3553 if (DR(oi
).s_addr
== INADDR_ANY
) {
3556 " No backup designated router on this network\n");
3558 nbr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &BDR(oi
));
3562 " No backup designated router on this network\n");
3565 json_object_string_add(
3566 json_interface_sub
, "bdrId",
3567 inet_ntoa(nbr
->router_id
));
3568 json_object_string_add(
3571 inet_ntoa(nbr
->address
.u
3575 " Backup Designated Router (ID) %s,",
3576 inet_ntoa(nbr
->router_id
));
3577 vty_out(vty
, " Interface Address %s\n",
3578 inet_ntoa(nbr
->address
.u
3584 /* Next network-LSA sequence number we'll use, if we're elected
3587 && ntohl(oi
->params
->network_lsa_seqnum
)
3588 != OSPF_INITIAL_SEQUENCE_NUMBER
) {
3590 json_object_int_add(
3592 "networkLsaSequence",
3593 ntohl(oi
->params
->network_lsa_seqnum
));
3596 " Saved Network-LSA sequence number 0x%x\n",
3597 ntohl(oi
->params
->network_lsa_seqnum
));
3601 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3602 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3603 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3604 json_object_boolean_true_add(
3606 "mcastMemberOspfAllRouters");
3607 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3608 json_object_boolean_true_add(
3610 "mcastMemberOspfDesignatedRouters");
3613 vty_out(vty
, " Multicast group memberships:");
3614 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3615 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3616 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3617 vty_out(vty
, " OSPFAllRouters");
3618 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3619 vty_out(vty
, " OSPFDesignatedRouters");
3621 vty_out(vty
, " <None>");
3626 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3627 json_object_int_add(
3628 json_interface_sub
, "timerMsecs",
3629 OSPF_IF_PARAM(oi
, v_hello
) * 1000);
3631 json_object_int_add(
3632 json_interface_sub
, "timerMsecs",
3633 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3634 json_object_int_add(json_interface_sub
,
3636 OSPF_IF_PARAM(oi
, v_wait
));
3637 json_object_int_add(json_interface_sub
,
3639 OSPF_IF_PARAM(oi
, v_wait
));
3640 json_object_int_add(
3641 json_interface_sub
, "timerRetransmitSecs",
3642 OSPF_IF_PARAM(oi
, retransmit_interval
));
3644 vty_out(vty
, " Timer intervals configured,");
3645 vty_out(vty
, " Hello ");
3646 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3647 vty_out(vty
, "%ds,",
3648 OSPF_IF_PARAM(oi
, v_hello
));
3650 vty_out(vty
, "%dms,",
3651 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3652 vty_out(vty
, " Dead %ds, Wait %ds, Retransmit %d\n",
3653 OSPF_IF_PARAM(oi
, v_wait
),
3654 OSPF_IF_PARAM(oi
, v_wait
),
3655 OSPF_IF_PARAM(oi
, retransmit_interval
));
3658 if (OSPF_IF_PASSIVE_STATUS(oi
) == OSPF_IF_ACTIVE
) {
3659 char timebuf
[OSPF_TIME_DUMP_SIZE
];
3661 long time_store
= 0;
3665 &oi
->t_hello
->u
.sands
,
3668 json_object_int_add(json_interface_sub
,
3669 "timerHelloInMsecs",
3672 vty_out(vty
, " Hello due in %s\n",
3673 ospf_timer_dump(oi
->t_hello
, timebuf
,
3675 } else /* passive-interface is set */
3678 json_object_boolean_true_add(
3680 "timerPassiveIface");
3683 " No Hellos (Passive interface)\n");
3687 json_object_int_add(json_interface_sub
, "nbrCount",
3688 ospf_nbr_count(oi
, 0));
3689 json_object_int_add(json_interface_sub
,
3691 ospf_nbr_count(oi
, NSM_Full
));
3694 " Neighbor Count is %d, Adjacent neighbor count is %d\n",
3695 ospf_nbr_count(oi
, 0),
3696 ospf_nbr_count(oi
, NSM_Full
));
3697 ospf_bfd_interface_show(vty
, ifp
, json_interface_sub
, use_json
);
3701 static int show_ip_ospf_interface_common(struct vty
*vty
, struct ospf
*ospf
,
3702 char *intf_name
, uint8_t use_vrf
,
3703 json_object
*json
, bool use_json
)
3705 struct interface
*ifp
;
3706 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
3707 json_object
*json_vrf
= NULL
;
3708 json_object
*json_interface_sub
= NULL
, *json_interface
= NULL
;
3712 json_vrf
= json_object_new_object();
3715 json_interface
= json_object_new_object();
3718 if (ospf
->instance
) {
3720 json_object_int_add(json
, "ospfInstance",
3723 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
3726 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3728 if (intf_name
== NULL
) {
3729 /* Show All Interfaces.*/
3730 FOR_ALL_INTERFACES (vrf
, ifp
) {
3731 if (ospf_oi_count(ifp
)) {
3733 json_interface_sub
=
3734 json_object_new_object();
3736 show_ip_ospf_interface_sub(vty
, ospf
, ifp
,
3741 json_object_object_add(
3742 json_interface
, ifp
->name
,
3743 json_interface_sub
);
3748 json_object_object_add(json_vrf
, "interfaces",
3751 /* Interface name is specified. */
3752 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
3755 json_object_boolean_true_add(json_vrf
,
3758 vty_out(vty
, "No such interface name\n");
3761 json_interface_sub
= json_object_new_object();
3762 json_interface
= json_object_new_object();
3765 show_ip_ospf_interface_sub(
3766 vty
, ospf
, ifp
, json_interface_sub
, use_json
);
3769 json_object_object_add(json_interface
,
3771 json_interface_sub
);
3772 json_object_object_add(json_vrf
, "interfaces",
3780 if (ospf
->vrf_id
== VRF_DEFAULT
)
3781 json_object_object_add(json
, "default",
3784 json_object_object_add(json
, ospf
->name
,
3793 static void show_ip_ospf_interface_traffic_sub(struct vty
*vty
,
3794 struct ospf_interface
*oi
,
3795 json_object
*json_interface_sub
,
3799 json_object_int_add(json_interface_sub
, "ifIndex",
3801 json_object_int_add(json_interface_sub
, "helloIn",
3803 json_object_int_add(json_interface_sub
, "helloOut",
3805 json_object_int_add(json_interface_sub
, "dbDescIn",
3807 json_object_int_add(json_interface_sub
, "dbDescOut",
3809 json_object_int_add(json_interface_sub
, "lsReqIn",
3811 json_object_int_add(json_interface_sub
, "lsReqOut",
3813 json_object_int_add(json_interface_sub
, "lsUpdIn",
3815 json_object_int_add(json_interface_sub
, "lsUpdOut",
3817 json_object_int_add(json_interface_sub
, "lsAckIn",
3819 json_object_int_add(json_interface_sub
, "lsAckOut",
3823 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n",
3824 oi
->ifp
->name
, oi
->hello_in
, oi
->hello_out
,
3825 oi
->db_desc_in
, oi
->db_desc_out
, oi
->ls_req_in
,
3826 oi
->ls_req_out
, oi
->ls_upd_in
, oi
->ls_upd_out
,
3827 oi
->ls_ack_in
, oi
->ls_ack_out
);
3831 /* OSPFv2 Packet Counters */
3832 static int show_ip_ospf_interface_traffic_common(
3833 struct vty
*vty
, struct ospf
*ospf
, char *intf_name
, json_object
*json
,
3834 int display_once
, uint8_t use_vrf
, bool use_json
)
3836 struct vrf
*vrf
= NULL
;
3837 struct interface
*ifp
= NULL
;
3838 json_object
*json_vrf
= NULL
;
3839 json_object
*json_interface_sub
= NULL
;
3841 if (!use_json
&& !display_once
) {
3843 vty_out(vty
, "%-12s%-17s%-17s%-17s%-17s%-17s\n", "Interface",
3844 " HELLO", " DB-Desc", " LS-Req", " LS-Update",
3846 vty_out(vty
, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "",
3847 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
3850 "--------------------------------------------------------------------------------------------\n");
3851 } else if (use_json
) {
3853 json_vrf
= json_object_new_object();
3858 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3860 if (intf_name
== NULL
) {
3861 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
3862 FOR_ALL_INTERFACES (vrf
, ifp
) {
3863 struct route_node
*rn
;
3864 struct ospf_interface
*oi
;
3866 if (ospf_oi_count(ifp
) == 0)
3869 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
3870 rn
= route_next(rn
)) {
3877 json_interface_sub
=
3878 json_object_new_object();
3881 show_ip_ospf_interface_traffic_sub(
3882 vty
, oi
, json_interface_sub
, use_json
);
3884 json_object_object_add(
3885 json_vrf
, ifp
->name
,
3886 json_interface_sub
);
3891 /* Interface name is specified. */
3892 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
3894 struct route_node
*rn
;
3895 struct ospf_interface
*oi
;
3897 if (ospf_oi_count(ifp
) == 0) {
3899 " OSPF not enabled on this interface %s\n",
3904 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
3905 rn
= route_next(rn
)) {
3909 json_interface_sub
=
3910 json_object_new_object();
3913 show_ip_ospf_interface_traffic_sub(
3914 vty
, oi
, json_interface_sub
, use_json
);
3916 json_object_object_add(
3917 json_vrf
, ifp
->name
,
3918 json_interface_sub
);
3926 if (ospf
->vrf_id
== VRF_DEFAULT
)
3927 json_object_object_add(json
, "default",
3930 json_object_object_add(json
, ospf
->name
,
3939 DEFUN (show_ip_ospf_interface
,
3940 show_ip_ospf_interface_cmd
,
3941 "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]",
3944 "OSPF information\n"
3947 "Interface information\n"
3952 bool uj
= use_json(argc
, argv
);
3953 struct listnode
*node
= NULL
;
3954 char *vrf_name
= NULL
, *intf_name
= NULL
;
3955 bool all_vrf
= false;
3956 int ret
= CMD_SUCCESS
;
3958 int idx_vrf
= 0, idx_intf
= 0;
3959 uint8_t use_vrf
= 0;
3960 json_object
*json
= NULL
;
3962 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
3964 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
3965 intf_name
= argv
[idx_intf
]->arg
;
3968 json
= json_object_new_object();
3970 /* vrf input is provided could be all or specific vrf*/
3974 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
3975 if (!ospf
->oi_running
)
3977 ret
= show_ip_ospf_interface_common(
3978 vty
, ospf
, intf_name
, use_vrf
, json
,
3983 vty_out(vty
, "%s\n",
3984 json_object_to_json_string_ext(
3985 json
, JSON_C_TO_STRING_PRETTY
));
3986 json_object_free(json
);
3988 vty_out(vty
, "%% OSPF instance not found\n");
3992 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
3993 if (ospf
== NULL
|| !ospf
->oi_running
) {
3995 vty_out(vty
, "%s\n",
3996 json_object_to_json_string_ext(
3997 json
, JSON_C_TO_STRING_PRETTY
));
3998 json_object_free(json
);
4000 vty_out(vty
, "%% OSPF instance not found\n");
4004 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
4008 /* Display default ospf (instance 0) info */
4009 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4010 if (ospf
== NULL
|| !ospf
->oi_running
) {
4012 vty_out(vty
, "%s\n",
4013 json_object_to_json_string_ext(
4014 json
, JSON_C_TO_STRING_PRETTY
));
4015 json_object_free(json
);
4017 vty_out(vty
, "%% OSPF instance not found\n");
4021 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
4026 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4027 json
, JSON_C_TO_STRING_PRETTY
));
4028 json_object_free(json
);
4034 DEFUN (show_ip_ospf_instance_interface
,
4035 show_ip_ospf_instance_interface_cmd
,
4036 "show ip ospf (1-65535) interface [INTERFACE] [json]",
4039 "OSPF information\n"
4041 "Interface information\n"
4048 unsigned short instance
= 0;
4049 bool uj
= use_json(argc
, argv
);
4050 char *intf_name
= NULL
;
4051 int ret
= CMD_SUCCESS
;
4052 json_object
*json
= NULL
;
4054 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4055 ospf
= ospf_lookup_instance(instance
);
4057 return CMD_NOT_MY_INSTANCE
;
4059 if (!ospf
->oi_running
)
4063 json
= json_object_new_object();
4065 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4066 intf_name
= argv
[idx_intf
]->arg
;
4068 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
, 0, json
, uj
);
4071 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4072 json
, JSON_C_TO_STRING_PRETTY
));
4073 json_object_free(json
);
4079 DEFUN (show_ip_ospf_interface_traffic
,
4080 show_ip_ospf_interface_traffic_cmd
,
4081 "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]",
4084 "OSPF information\n"
4087 "Interface information\n"
4088 "Protocol Packet counters\n"
4092 struct ospf
*ospf
= NULL
;
4093 struct listnode
*node
= NULL
;
4094 char *vrf_name
= NULL
, *intf_name
= NULL
;
4095 bool all_vrf
= false;
4097 int idx_vrf
= 0, idx_intf
= 0;
4098 bool uj
= use_json(argc
, argv
);
4099 json_object
*json
= NULL
;
4100 int ret
= CMD_SUCCESS
;
4101 int display_once
= 0;
4102 uint8_t use_vrf
= 0;
4104 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4106 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4107 intf_name
= argv
[idx_intf
]->arg
;
4110 json
= json_object_new_object();
4115 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4116 if (!ospf
->oi_running
)
4119 ret
= show_ip_ospf_interface_traffic_common(
4120 vty
, ospf
, intf_name
, json
,
4121 display_once
, use_vrf
, uj
);
4126 vty_out(vty
, "%s\n",
4127 json_object_to_json_string_ext(
4128 json
, JSON_C_TO_STRING_PRETTY
));
4129 json_object_free(json
);
4134 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4135 if (ospf
== NULL
|| !ospf
->oi_running
) {
4137 json_object_free(json
);
4141 ret
= show_ip_ospf_interface_traffic_common(
4142 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4144 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4145 if (ospf
== NULL
|| !ospf
->oi_running
) {
4147 json_object_free(json
);
4151 ret
= show_ip_ospf_interface_traffic_common(
4152 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4156 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4157 json
, JSON_C_TO_STRING_PRETTY
));
4158 json_object_free(json
);
4165 static void show_ip_ospf_neighbour_header(struct vty
*vty
)
4167 vty_out(vty
, "\n%-15s %3s %-15s %9s %-15s %-32s %5s %5s %5s\n",
4168 "Neighbor ID", "Pri", "State", "Dead Time", "Address",
4169 "Interface", "RXmtL", "RqstL", "DBsmL");
4172 static void show_ip_ospf_neighbor_sub(struct vty
*vty
,
4173 struct ospf_interface
*oi
,
4174 json_object
*json
, bool use_json
)
4176 struct route_node
*rn
;
4177 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
4179 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4180 json_object
*json_neighbor
= NULL
, *json_neigh_array
= NULL
;
4182 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
4183 if ((nbr
= rn
->info
)) {
4184 /* Do not show myself. */
4185 if (nbr
== oi
->nbr_self
)
4187 /* Down state is not shown. */
4188 if (nbr
->state
== NSM_Down
)
4191 char neigh_str
[INET_ADDRSTRLEN
];
4194 && !IPV4_ADDR_SAME(&prev_nbr
->src
,
4196 /* Start new neigh list */
4197 json_neigh_array
= NULL
;
4200 if (nbr
->state
== NSM_Attempt
4201 && nbr
->router_id
.s_addr
== INADDR_ANY
)
4202 strlcpy(neigh_str
, "neighbor",
4206 inet_ntoa(nbr
->router_id
),
4209 json_object_object_get_ex(json
, neigh_str
,
4212 if (!json_neigh_array
) {
4214 json_object_new_array();
4215 json_object_object_add(
4220 json_neighbor
= json_object_new_object();
4222 ospf_nbr_state_message(nbr
, msgbuf
, 16);
4228 &nbr
->t_inactivity
->u
.sands
,
4232 json_object_int_add(json_neighbor
, "priority",
4234 json_object_string_add(json_neighbor
, "state",
4236 json_object_int_add(json_neighbor
,
4239 json_object_string_add(json_neighbor
, "address",
4240 inet_ntoa(nbr
->src
));
4241 json_object_string_add(json_neighbor
,
4244 json_object_int_add(
4245 json_neighbor
, "retransmitCounter",
4246 ospf_ls_retransmit_count(nbr
));
4247 json_object_int_add(json_neighbor
,
4249 ospf_ls_request_count(nbr
));
4250 json_object_int_add(json_neighbor
,
4252 ospf_db_summary_count(nbr
));
4254 json_object_array_add(json_neigh_array
,
4257 ospf_nbr_state_message(nbr
, msgbuf
, 16);
4259 if (nbr
->state
== NSM_Attempt
4260 && nbr
->router_id
.s_addr
== INADDR_ANY
)
4261 vty_out(vty
, "%-15s %3d %-15s ", "-",
4262 nbr
->priority
, msgbuf
);
4264 vty_out(vty
, "%-15s %3d %-15s ",
4265 inet_ntoa(nbr
->router_id
),
4266 nbr
->priority
, msgbuf
);
4268 vty_out(vty
, "%9s ",
4269 ospf_timer_dump(nbr
->t_inactivity
,
4272 vty_out(vty
, "%-15s ", inet_ntoa(nbr
->src
));
4273 vty_out(vty
, "%-32s %5ld %5ld %5d\n",
4275 ospf_ls_retransmit_count(nbr
),
4276 ospf_ls_request_count(nbr
),
4277 ospf_db_summary_count(nbr
));
4284 static int show_ip_ospf_neighbor_common(struct vty
*vty
, struct ospf
*ospf
,
4285 json_object
*json
, bool use_json
,
4288 struct ospf_interface
*oi
;
4289 struct listnode
*node
;
4290 json_object
*json_vrf
= NULL
;
4291 json_object
*json_nbr_sub
= NULL
;
4295 json_vrf
= json_object_new_object();
4298 json_nbr_sub
= json_object_new_object();
4301 if (ospf
->instance
) {
4303 json_object_int_add(json
, "ospfInstance",
4306 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4309 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4311 show_ip_ospf_neighbour_header(vty
);
4313 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4314 if (ospf_interface_neighbor_count(oi
) == 0)
4316 show_ip_ospf_neighbor_sub(vty
, oi
, json_nbr_sub
, use_json
);
4320 json_object_object_add(json_vrf
, "neighbors", json_nbr_sub
);
4322 if (ospf
->vrf_id
== VRF_DEFAULT
)
4323 json_object_object_add(json
, "default",
4326 json_object_object_add(json
, ospf
->name
,
4335 DEFUN (show_ip_ospf_neighbor
,
4336 show_ip_ospf_neighbor_cmd
,
4337 "show ip ospf [vrf <NAME|all>] neighbor [json]",
4340 "OSPF information\n"
4347 bool uj
= use_json(argc
, argv
);
4348 struct listnode
*node
= NULL
;
4349 char *vrf_name
= NULL
;
4350 bool all_vrf
= false;
4351 int ret
= CMD_SUCCESS
;
4354 uint8_t use_vrf
= 0;
4355 json_object
*json
= NULL
;
4357 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4360 json
= json_object_new_object();
4362 /* vrf input is provided could be all or specific vrf*/
4366 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4367 if (!ospf
->oi_running
)
4369 ret
= show_ip_ospf_neighbor_common(
4370 vty
, ospf
, json
, uj
, use_vrf
);
4374 vty_out(vty
, "%s\n",
4375 json_object_to_json_string_ext(
4376 json
, JSON_C_TO_STRING_PRETTY
));
4377 json_object_free(json
);
4379 vty_out(vty
, "OSPF instance not found\n");
4384 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4385 if (ospf
== NULL
|| !ospf
->oi_running
) {
4387 vty_out(vty
, "%s\n",
4388 json_object_to_json_string_ext(
4389 json
, JSON_C_TO_STRING_PRETTY
));
4390 json_object_free(json
);
4392 vty_out(vty
, "%% OSPF instance not found\n");
4397 /* Display default ospf (instance 0) info */
4398 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4399 if (ospf
== NULL
|| !ospf
->oi_running
) {
4401 vty_out(vty
, "%s\n",
4402 json_object_to_json_string_ext(
4403 json
, JSON_C_TO_STRING_PRETTY
));
4404 json_object_free(json
);
4406 vty_out(vty
, "%% OSPF instance not found\n");
4413 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
,
4417 vty_out(vty
, "%s\n",
4418 json_object_to_json_string_ext(
4419 json
, JSON_C_TO_STRING_PRETTY
));
4424 json_object_free(json
);
4430 DEFUN (show_ip_ospf_instance_neighbor
,
4431 show_ip_ospf_instance_neighbor_cmd
,
4432 "show ip ospf (1-65535) neighbor [json]",
4435 "OSPF information\n"
4442 unsigned short instance
= 0;
4443 bool uj
= use_json(argc
, argv
);
4444 json_object
*json
= NULL
;
4445 int ret
= CMD_SUCCESS
;
4447 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4448 ospf
= ospf_lookup_instance(instance
);
4450 return CMD_NOT_MY_INSTANCE
;
4452 if (!ospf
->oi_running
)
4456 json
= json_object_new_object();
4458 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
, 0);
4461 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4462 json
, JSON_C_TO_STRING_PRETTY
));
4463 json_object_free(json
);
4469 static int show_ip_ospf_neighbor_all_common(struct vty
*vty
, struct ospf
*ospf
,
4470 json_object
*json
, bool use_json
,
4473 struct listnode
*node
;
4474 struct ospf_interface
*oi
;
4475 json_object
*json_vrf
= NULL
;
4476 json_object
*json_neighbor_sub
= NULL
;
4480 json_vrf
= json_object_new_object();
4483 json_neighbor_sub
= json_object_new_object();
4486 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4488 show_ip_ospf_neighbour_header(vty
);
4490 if (ospf
->instance
) {
4492 json_object_int_add(json_vrf
, "ospfInstance",
4495 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4498 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4499 struct listnode
*nbr_node
;
4500 struct ospf_nbr_nbma
*nbr_nbma
;
4502 show_ip_ospf_neighbor_sub(vty
, oi
, json_vrf
, use_json
);
4504 /* print Down neighbor status */
4505 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nbr_node
, nbr_nbma
)) {
4506 if (nbr_nbma
->nbr
== NULL
4507 || nbr_nbma
->nbr
->state
== NSM_Down
) {
4509 json_object_int_add(json_neighbor_sub
,
4511 nbr_nbma
->priority
);
4512 json_object_boolean_true_add(
4515 json_object_string_add(
4519 json_object_int_add(
4521 "nbrNbmaRetransmitCounter", 0);
4522 json_object_int_add(
4524 "nbrNbmaRequestCounter", 0);
4525 json_object_int_add(
4527 "nbrNbmaDbSummaryCounter", 0);
4528 json_object_object_add(
4530 inet_ntoa(nbr_nbma
->addr
),
4533 vty_out(vty
, "%-15s %3d %-15s %9s ",
4534 "-", nbr_nbma
->priority
, "Down",
4537 "%-32s %-20s %5d %5d %5d\n",
4538 inet_ntoa(nbr_nbma
->addr
),
4539 IF_NAME(oi
), 0, 0, 0);
4547 if (ospf
->vrf_id
== VRF_DEFAULT
)
4548 json_object_object_add(json
, "default",
4551 json_object_object_add(json
, ospf
->name
,
4560 DEFUN (show_ip_ospf_neighbor_all
,
4561 show_ip_ospf_neighbor_all_cmd
,
4562 "show ip ospf [vrf <NAME|all>] neighbor all [json]",
4565 "OSPF information\n"
4569 "include down status neighbor\n"
4573 bool uj
= use_json(argc
, argv
);
4574 struct listnode
*node
= NULL
;
4575 char *vrf_name
= NULL
;
4576 bool all_vrf
= false;
4577 int ret
= CMD_SUCCESS
;
4580 uint8_t use_vrf
= 0;
4581 json_object
*json
= NULL
;
4583 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4586 json
= json_object_new_object();
4588 /* vrf input is provided could be all or specific vrf*/
4592 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4593 if (!ospf
->oi_running
)
4595 ret
= show_ip_ospf_neighbor_all_common(
4596 vty
, ospf
, json
, uj
, use_vrf
);
4600 vty_out(vty
, "%s\n",
4601 json_object_to_json_string_ext(
4602 json
, JSON_C_TO_STRING_PRETTY
));
4603 json_object_free(json
);
4609 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4610 if (ospf
== NULL
|| !ospf
->oi_running
) {
4612 json_object_free(json
);
4616 /* Display default ospf (instance 0) info */
4617 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4618 if (ospf
== NULL
|| !ospf
->oi_running
) {
4620 json_object_free(json
);
4626 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
,
4629 vty_out(vty
, "%s\n",
4630 json_object_to_json_string_ext(
4631 json
, JSON_C_TO_STRING_PRETTY
));
4636 json_object_free(json
);
4641 DEFUN (show_ip_ospf_instance_neighbor_all
,
4642 show_ip_ospf_instance_neighbor_all_cmd
,
4643 "show ip ospf (1-65535) neighbor all [json]",
4646 "OSPF information\n"
4649 "include down status neighbor\n"
4654 unsigned short instance
= 0;
4655 bool uj
= use_json(argc
, argv
);
4656 json_object
*json
= NULL
;
4657 int ret
= CMD_SUCCESS
;
4659 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4660 ospf
= ospf_lookup_instance(instance
);
4662 return CMD_NOT_MY_INSTANCE
;
4664 if (!ospf
->oi_running
)
4667 json
= json_object_new_object();
4669 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
, 0);
4672 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4673 json
, JSON_C_TO_STRING_PRETTY
));
4674 json_object_free(json
);
4680 static int show_ip_ospf_neighbor_int_common(struct vty
*vty
, struct ospf
*ospf
,
4682 struct cmd_token
**argv
,
4683 bool use_json
, uint8_t use_vrf
)
4685 struct interface
*ifp
;
4686 struct route_node
*rn
;
4687 json_object
*json
= NULL
;
4690 json
= json_object_new_object();
4692 if (ospf
->instance
) {
4694 json_object_int_add(json
, "ospfInstance",
4697 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4700 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
4702 ifp
= if_lookup_by_name(argv
[arg_base
]->arg
, ospf
->vrf_id
);
4705 json_object_boolean_true_add(json
, "noSuchIface");
4707 vty_out(vty
, "No such interface.\n");
4711 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
4712 struct ospf_interface
*oi
= rn
->info
;
4717 show_ip_ospf_neighbor_sub(vty
, oi
, json
, use_json
);
4721 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4722 json
, JSON_C_TO_STRING_PRETTY
));
4723 json_object_free(json
);
4730 DEFUN (show_ip_ospf_neighbor_int
,
4731 show_ip_ospf_neighbor_int_cmd
,
4732 "show ip ospf [vrf <NAME>] neighbor IFNAME [json]",
4735 "OSPF information\n"
4744 bool uj
= use_json(argc
, argv
);
4745 int ret
= CMD_SUCCESS
;
4746 struct interface
*ifp
= NULL
;
4747 char *vrf_name
= NULL
;
4748 vrf_id_t vrf_id
= VRF_DEFAULT
;
4749 struct vrf
*vrf
= NULL
;
4751 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
4752 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
4753 if (vrf_name
&& strmatch(vrf_name
, VRF_DEFAULT_NAME
))
4756 vrf
= vrf_lookup_by_name(vrf_name
);
4758 vrf_id
= vrf
->vrf_id
;
4760 ospf
= ospf_lookup_by_vrf_id(vrf_id
);
4762 if (!ospf
|| !ospf
->oi_running
)
4766 show_ip_ospf_neighbour_header(vty
);
4768 argv_find(argv
, argc
, "IFNAME", &idx_ifname
);
4770 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf_id
);
4774 ret
= show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
,
4779 DEFUN (show_ip_ospf_instance_neighbor_int
,
4780 show_ip_ospf_instance_neighbor_int_cmd
,
4781 "show ip ospf (1-65535) neighbor IFNAME [json]",
4784 "OSPF information\n"
4793 unsigned short instance
= 0;
4794 bool uj
= use_json(argc
, argv
);
4797 show_ip_ospf_neighbour_header(vty
);
4799 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4800 ospf
= ospf_lookup_instance(instance
);
4802 return CMD_NOT_MY_INSTANCE
;
4804 if (!ospf
->oi_running
)
4808 show_ip_ospf_neighbour_header(vty
);
4810 return show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
, argv
, uj
,
4814 static void show_ip_ospf_nbr_nbma_detail_sub(struct vty
*vty
,
4815 struct ospf_interface
*oi
,
4816 struct ospf_nbr_nbma
*nbr_nbma
,
4817 bool use_json
, json_object
*json
)
4819 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4820 json_object
*json_sub
= NULL
;
4823 json_sub
= json_object_new_object();
4824 else /* Show neighbor ID. */
4825 vty_out(vty
, " Neighbor %s,", "-");
4827 /* Show interface address. */
4829 json_object_string_add(json_sub
, "ifaceAddress",
4830 inet_ntoa(nbr_nbma
->addr
));
4832 vty_out(vty
, " interface address %s\n",
4833 inet_ntoa(nbr_nbma
->addr
));
4837 json_object_string_add(json_sub
, "areaId",
4838 ospf_area_desc_string(oi
->area
));
4839 json_object_string_add(json_sub
, "iface", IF_NAME(oi
));
4841 vty_out(vty
, " In the area %s via interface %s\n",
4842 ospf_area_desc_string(oi
->area
), IF_NAME(oi
));
4844 /* Show neighbor priority and state. */
4846 json_object_int_add(json_sub
, "nbrPriority",
4847 nbr_nbma
->priority
);
4848 json_object_string_add(json_sub
, "nbrState", "down");
4850 vty_out(vty
, " Neighbor priority is %d, State is %s,",
4851 nbr_nbma
->priority
, "Down");
4853 /* Show state changes. */
4855 json_object_int_add(json_sub
, "stateChangeCounter",
4856 nbr_nbma
->state_change
);
4858 vty_out(vty
, " %d state changes\n", nbr_nbma
->state_change
);
4860 /* Show PollInterval */
4862 json_object_int_add(json_sub
, "pollInterval", nbr_nbma
->v_poll
);
4864 vty_out(vty
, " Poll interval %d\n", nbr_nbma
->v_poll
);
4866 /* Show poll-interval timer. */
4867 if (nbr_nbma
->t_poll
) {
4870 time_store
= monotime_until(&nbr_nbma
->t_poll
->u
.sands
,
4872 json_object_int_add(json_sub
,
4873 "pollIntervalTimerDueMsec",
4876 vty_out(vty
, " Poll timer due in %s\n",
4877 ospf_timer_dump(nbr_nbma
->t_poll
, timebuf
,
4881 /* Show poll-interval timer thread. */
4883 if (nbr_nbma
->t_poll
!= NULL
)
4884 json_object_string_add(json_sub
,
4885 "pollIntervalTimerThread", "on");
4887 vty_out(vty
, " Thread Poll Timer %s\n",
4888 nbr_nbma
->t_poll
!= NULL
? "on" : "off");
4891 json_object_object_add(json
, "noNbrId", json_sub
);
4894 static void show_ip_ospf_neighbor_detail_sub(struct vty
*vty
,
4895 struct ospf_interface
*oi
,
4896 struct ospf_neighbor
*nbr
,
4897 struct ospf_neighbor
*prev_nbr
,
4898 json_object
*json
, bool use_json
)
4900 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4901 json_object
*json_neigh
= NULL
, *json_neigh_array
= NULL
;
4902 char neigh_str
[INET_ADDRSTRLEN
] = {0};
4906 !IPV4_ADDR_SAME(&prev_nbr
->src
, &nbr
->src
)) {
4907 json_neigh_array
= NULL
;
4910 if (nbr
->state
== NSM_Attempt
4911 && nbr
->router_id
.s_addr
== INADDR_ANY
)
4912 strlcpy(neigh_str
, "noNbrId", sizeof(neigh_str
));
4914 strlcpy(neigh_str
, inet_ntoa(nbr
->router_id
),
4917 json_object_object_get_ex(json
, neigh_str
, &json_neigh_array
);
4919 if (!json_neigh_array
) {
4920 json_neigh_array
= json_object_new_array();
4921 json_object_object_add(json
, neigh_str
,
4925 json_neigh
= json_object_new_object();
4928 /* Show neighbor ID. */
4929 if (nbr
->state
== NSM_Attempt
4930 && nbr
->router_id
.s_addr
== INADDR_ANY
)
4931 vty_out(vty
, " Neighbor %s,", "-");
4933 vty_out(vty
, " Neighbor %s,",
4934 inet_ntoa(nbr
->router_id
));
4937 /* Show interface address. */
4939 json_object_string_add(json_neigh
, "ifaceAddress",
4940 inet_ntoa(nbr
->address
.u
.prefix4
));
4942 vty_out(vty
, " interface address %s\n",
4943 inet_ntoa(nbr
->address
.u
.prefix4
));
4947 json_object_string_add(json_neigh
, "areaId",
4948 ospf_area_desc_string(oi
->area
));
4949 json_object_string_add(json_neigh
, "ifaceName", oi
->ifp
->name
);
4951 vty_out(vty
, " In the area %s via interface %s\n",
4952 ospf_area_desc_string(oi
->area
), oi
->ifp
->name
);
4954 /* Show neighbor priority and state. */
4956 json_object_int_add(json_neigh
, "nbrPriority", nbr
->priority
);
4957 json_object_string_add(
4958 json_neigh
, "nbrState",
4959 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
4961 vty_out(vty
, " Neighbor priority is %d, State is %s,",
4963 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
4965 /* Show state changes. */
4967 json_object_int_add(json_neigh
, "stateChangeCounter",
4970 vty_out(vty
, " %d state changes\n", nbr
->state_change
);
4972 if (nbr
->ts_last_progress
.tv_sec
|| nbr
->ts_last_progress
.tv_usec
) {
4977 monotime_since(&nbr
->ts_last_progress
, &res
) / 1000LL;
4979 json_object_int_add(json_neigh
, "lastPrgrsvChangeMsec",
4983 " Most recent state change statistics:\n");
4984 vty_out(vty
, " Progressive change %s ago\n",
4985 ospf_timeval_dump(&res
, timebuf
,
4990 if (nbr
->ts_last_regress
.tv_sec
|| nbr
->ts_last_regress
.tv_usec
) {
4995 monotime_since(&nbr
->ts_last_regress
, &res
) / 1000LL;
4997 json_object_int_add(json_neigh
,
4998 "lastRegressiveChangeMsec",
5000 if (nbr
->last_regress_str
)
5001 json_object_string_add(
5003 "lastRegressiveChangeReason",
5004 nbr
->last_regress_str
);
5007 " Regressive change %s ago, due to %s\n",
5008 ospf_timeval_dump(&res
, timebuf
,
5010 (nbr
->last_regress_str
? nbr
->last_regress_str
5015 /* Show Designated Rotuer ID. */
5017 json_object_string_add(json_neigh
, "routerDesignatedId",
5018 inet_ntoa(nbr
->d_router
));
5020 vty_out(vty
, " DR is %s,", inet_ntoa(nbr
->d_router
));
5022 /* Show Backup Designated Rotuer ID. */
5024 json_object_string_add(json_neigh
, "routerDesignatedBackupId",
5025 inet_ntoa(nbr
->bd_router
));
5027 vty_out(vty
, " BDR is %s\n", inet_ntoa(nbr
->bd_router
));
5031 json_object_int_add(json_neigh
, "optionsCounter", nbr
->options
);
5032 json_object_string_add(json_neigh
, "optionsList",
5033 ospf_options_dump(nbr
->options
));
5035 vty_out(vty
, " Options %d %s\n", nbr
->options
,
5036 ospf_options_dump(nbr
->options
));
5038 /* Show Router Dead interval timer. */
5040 if (nbr
->t_inactivity
) {
5042 time_store
= monotime_until(&nbr
->t_inactivity
->u
.sands
,
5045 json_object_int_add(json_neigh
,
5046 "routerDeadIntervalTimerDueMsec",
5049 json_object_int_add(
5051 "routerDeadIntervalTimerDueMsec", -1);
5053 vty_out(vty
, " Dead timer due in %s\n",
5054 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
5057 /* Show Database Summary list. */
5059 json_object_int_add(json_neigh
, "databaseSummaryListCounter",
5060 ospf_db_summary_count(nbr
));
5062 vty_out(vty
, " Database Summary List %d\n",
5063 ospf_db_summary_count(nbr
));
5065 /* Show Link State Request list. */
5067 json_object_int_add(json_neigh
, "linkStateRequestListCounter",
5068 ospf_ls_request_count(nbr
));
5070 vty_out(vty
, " Link State Request List %ld\n",
5071 ospf_ls_request_count(nbr
));
5073 /* Show Link State Retransmission list. */
5075 json_object_int_add(json_neigh
,
5076 "linkStateRetransmissionListCounter",
5077 ospf_ls_retransmit_count(nbr
));
5079 vty_out(vty
, " Link State Retransmission List %ld\n",
5080 ospf_ls_retransmit_count(nbr
));
5082 /* Show inactivity timer thread. */
5084 if (nbr
->t_inactivity
!= NULL
)
5085 json_object_string_add(json_neigh
,
5086 "threadInactivityTimer", "on");
5088 vty_out(vty
, " Thread Inactivity Timer %s\n",
5089 nbr
->t_inactivity
!= NULL
? "on" : "off");
5091 /* Show Database Description retransmission thread. */
5093 if (nbr
->t_db_desc
!= NULL
)
5094 json_object_string_add(
5096 "threadDatabaseDescriptionRetransmission",
5100 " Thread Database Description Retransmision %s\n",
5101 nbr
->t_db_desc
!= NULL
? "on" : "off");
5103 /* Show Link State Request Retransmission thread. */
5105 if (nbr
->t_ls_req
!= NULL
)
5106 json_object_string_add(
5108 "threadLinkStateRequestRetransmission", "on");
5111 " Thread Link State Request Retransmission %s\n",
5112 nbr
->t_ls_req
!= NULL
? "on" : "off");
5114 /* Show Link State Update Retransmission thread. */
5116 if (nbr
->t_ls_upd
!= NULL
)
5117 json_object_string_add(
5119 "threadLinkStateUpdateRetransmission",
5123 " Thread Link State Update Retransmission %s\n\n",
5124 nbr
->t_ls_upd
!= NULL
? "on" : "off");
5126 ospf_bfd_show_info(vty
, nbr
->bfd_info
, json_neigh
, use_json
, 0);
5129 json_object_array_add(json_neigh_array
, json_neigh
);
5133 static int show_ip_ospf_neighbor_id_common(struct vty
*vty
, struct ospf
*ospf
,
5134 struct in_addr
*router_id
,
5135 bool use_json
, uint8_t use_vrf
)
5137 struct listnode
*node
;
5138 struct ospf_neighbor
*nbr
;
5139 struct ospf_interface
*oi
;
5140 json_object
*json
= NULL
;
5143 json
= json_object_new_object();
5145 if (ospf
->instance
) {
5147 json_object_int_add(json
, "ospfInstance",
5150 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5153 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
5155 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5156 if ((nbr
= ospf_nbr_lookup_by_routerid(oi
->nbrs
, router_id
))) {
5157 show_ip_ospf_neighbor_detail_sub(vty
, oi
, nbr
, NULL
,
5163 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5164 json
, JSON_C_TO_STRING_PRETTY
));
5165 json_object_free(json
);
5172 DEFPY (show_ip_ospf_neighbor_id
,
5173 show_ip_ospf_neighbor_id_cmd
,
5174 "show ip ospf neighbor A.B.C.D$router_id [json$json]",
5177 "OSPF information\n"
5183 struct listnode
*node
;
5184 int ret
= CMD_SUCCESS
;
5186 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5187 if (!ospf
->oi_running
)
5189 ret
= show_ip_ospf_neighbor_id_common(vty
, ospf
, &router_id
,
5196 DEFPY (show_ip_ospf_instance_neighbor_id
,
5197 show_ip_ospf_instance_neighbor_id_cmd
,
5198 "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [json$json]",
5201 "OSPF information\n"
5209 ospf
= ospf_lookup_instance(instance
);
5211 return CMD_NOT_MY_INSTANCE
;
5213 if (!ospf
->oi_running
)
5216 return show_ip_ospf_neighbor_id_common(vty
, ospf
, &router_id
, !!json
,
5220 static int show_ip_ospf_neighbor_detail_common(struct vty
*vty
,
5222 json_object
*json
, bool use_json
,
5225 struct ospf_interface
*oi
;
5226 struct listnode
*node
;
5227 json_object
*json_vrf
= NULL
;
5228 json_object
*json_nbr_sub
= NULL
;
5232 json_vrf
= json_object_new_object();
5236 json_nbr_sub
= json_object_new_object();
5239 if (ospf
->instance
) {
5241 json_object_int_add(json
, "ospfInstance",
5244 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5247 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5249 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5250 struct route_node
*rn
;
5251 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
5253 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5254 if ((nbr
= rn
->info
)) {
5255 if (nbr
!= oi
->nbr_self
) {
5256 if (nbr
->state
!= NSM_Down
) {
5257 show_ip_ospf_neighbor_detail_sub(
5258 vty
, oi
, nbr
, prev_nbr
,
5259 json_nbr_sub
, use_json
);
5268 json_object_object_add(json_vrf
, "neighbors",
5271 if (ospf
->vrf_id
== VRF_DEFAULT
)
5272 json_object_object_add(json
, "default",
5275 json_object_object_add(json
, ospf
->name
,
5284 DEFUN (show_ip_ospf_neighbor_detail
,
5285 show_ip_ospf_neighbor_detail_cmd
,
5286 "show ip ospf [vrf <NAME|all>] neighbor detail [json]",
5289 "OSPF information\n"
5293 "detail of all neighbors\n"
5297 bool uj
= use_json(argc
, argv
);
5298 struct listnode
*node
= NULL
;
5299 char *vrf_name
= NULL
;
5300 bool all_vrf
= false;
5301 int ret
= CMD_SUCCESS
;
5304 uint8_t use_vrf
= 0;
5305 json_object
*json
= NULL
;
5307 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5310 json
= json_object_new_object();
5312 /* vrf input is provided could be all or specific vrf*/
5316 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5317 if (!ospf
->oi_running
)
5319 ret
= show_ip_ospf_neighbor_detail_common(
5320 vty
, ospf
, json
, uj
, use_vrf
);
5323 vty_out(vty
, "%s\n",
5324 json_object_to_json_string_ext(
5325 json
, JSON_C_TO_STRING_PRETTY
));
5326 json_object_free(json
);
5331 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5332 if (ospf
== NULL
|| !ospf
->oi_running
) {
5334 json_object_free(json
);
5338 /* Display default ospf (instance 0) info */
5339 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5340 if (ospf
== NULL
|| !ospf
->oi_running
) {
5342 json_object_free(json
);
5348 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
,
5351 vty_out(vty
, "%s\n",
5352 json_object_to_json_string_ext(
5353 json
, JSON_C_TO_STRING_PRETTY
));
5358 json_object_free(json
);
5363 DEFUN (show_ip_ospf_instance_neighbor_detail
,
5364 show_ip_ospf_instance_neighbor_detail_cmd
,
5365 "show ip ospf (1-65535) neighbor detail [json]",
5368 "OSPF information\n"
5371 "detail of all neighbors\n"
5376 unsigned short instance
= 0;
5377 bool uj
= use_json(argc
, argv
);
5378 json_object
*json
= NULL
;
5379 int ret
= CMD_SUCCESS
;
5381 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5382 ospf
= ospf_lookup_instance(instance
);
5384 return CMD_NOT_MY_INSTANCE
;
5386 if (!ospf
->oi_running
)
5390 json
= json_object_new_object();
5392 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
, 0);
5395 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5396 json
, JSON_C_TO_STRING_PRETTY
));
5397 json_object_free(json
);
5403 static int show_ip_ospf_neighbor_detail_all_common(struct vty
*vty
,
5409 struct listnode
*node
;
5410 struct ospf_interface
*oi
;
5411 json_object
*json_vrf
= NULL
;
5415 json_vrf
= json_object_new_object();
5420 if (ospf
->instance
) {
5422 json_object_int_add(json
, "ospfInstance",
5425 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5428 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5430 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5431 struct route_node
*rn
;
5432 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
5433 struct ospf_nbr_nbma
*nbr_nbma
;
5435 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5436 if ((nbr
= rn
->info
)) {
5437 if (nbr
!= oi
->nbr_self
)
5438 if (nbr
->state
!= NSM_Down
)
5439 show_ip_ospf_neighbor_detail_sub(
5442 json_vrf
, use_json
);
5447 if (oi
->type
== OSPF_IFTYPE_NBMA
) {
5448 struct listnode
*nd
;
5450 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nd
, nbr_nbma
)) {
5451 if (nbr_nbma
->nbr
== NULL
5452 || nbr_nbma
->nbr
->state
== NSM_Down
)
5453 show_ip_ospf_nbr_nbma_detail_sub(
5454 vty
, oi
, nbr_nbma
, use_json
,
5462 if (ospf
->vrf_id
== VRF_DEFAULT
)
5463 json_object_object_add(json
, "default",
5466 json_object_object_add(json
, ospf
->name
,
5476 DEFUN (show_ip_ospf_neighbor_detail_all
,
5477 show_ip_ospf_neighbor_detail_all_cmd
,
5478 "show ip ospf [vrf <NAME|all>] neighbor detail all [json]",
5481 "OSPF information\n"
5485 "detail of all neighbors\n"
5486 "include down status neighbor\n"
5490 bool uj
= use_json(argc
, argv
);
5491 struct listnode
*node
= NULL
;
5492 char *vrf_name
= NULL
;
5493 bool all_vrf
= false;
5494 int ret
= CMD_SUCCESS
;
5497 uint8_t use_vrf
= 0;
5498 json_object
*json
= NULL
;
5500 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5503 json
= json_object_new_object();
5505 /* vrf input is provided could be all or specific vrf*/
5509 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5510 if (!ospf
->oi_running
)
5512 ret
= show_ip_ospf_neighbor_detail_all_common(
5513 vty
, ospf
, json
, uj
, use_vrf
);
5517 vty_out(vty
, "%s\n",
5518 json_object_to_json_string_ext(
5519 json
, JSON_C_TO_STRING_PRETTY
));
5520 json_object_free(json
);
5525 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5526 if (ospf
== NULL
|| !ospf
->oi_running
) {
5528 json_object_free(json
);
5532 /* Display default ospf (instance 0) info */
5533 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5534 if (ospf
== NULL
|| !ospf
->oi_running
) {
5536 json_object_free(json
);
5542 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
,
5545 vty_out(vty
, "%s\n",
5546 json_object_to_json_string_ext(
5547 json
, JSON_C_TO_STRING_PRETTY
));
5552 json_object_free(json
);
5557 DEFUN (show_ip_ospf_instance_neighbor_detail_all
,
5558 show_ip_ospf_instance_neighbor_detail_all_cmd
,
5559 "show ip ospf (1-65535) neighbor detail all [json]",
5562 "OSPF information\n"
5565 "detail of all neighbors\n"
5566 "include down status neighbor\n"
5571 unsigned short instance
= 0;
5572 bool uj
= use_json(argc
, argv
);
5573 json_object
*json
= NULL
;
5574 int ret
= CMD_SUCCESS
;
5576 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5577 ospf
= ospf_lookup_instance(instance
);
5579 return CMD_NOT_MY_INSTANCE
;
5581 if (!ospf
->oi_running
)
5585 json
= json_object_new_object();
5587 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
, uj
, 0);
5590 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5591 json
, JSON_C_TO_STRING_PRETTY
));
5592 json_object_free(json
);
5598 static int show_ip_ospf_neighbor_int_detail_common(struct vty
*vty
,
5601 struct cmd_token
**argv
,
5604 struct ospf_interface
*oi
;
5605 struct interface
*ifp
;
5606 struct route_node
*rn
, *nrn
;
5607 struct ospf_neighbor
*nbr
;
5608 json_object
*json
= NULL
;
5611 json
= json_object_new_object();
5613 if (ospf
->instance
) {
5615 json_object_int_add(json
, "ospfInstance",
5618 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5621 ifp
= if_lookup_by_name(argv
[arg_base
]->arg
, ospf
->vrf_id
);
5624 vty_out(vty
, "No such interface.\n");
5626 vty_out(vty
, "{}\n");
5627 json_object_free(json
);
5632 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
5633 if ((oi
= rn
->info
)) {
5634 for (nrn
= route_top(oi
->nbrs
); nrn
;
5635 nrn
= route_next(nrn
)) {
5636 if ((nbr
= nrn
->info
)) {
5637 if (nbr
!= oi
->nbr_self
) {
5638 if (nbr
->state
!= NSM_Down
)
5639 show_ip_ospf_neighbor_detail_sub(
5650 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5651 json
, JSON_C_TO_STRING_PRETTY
));
5652 json_object_free(json
);
5659 DEFUN (show_ip_ospf_neighbor_int_detail
,
5660 show_ip_ospf_neighbor_int_detail_cmd
,
5661 "show ip ospf neighbor IFNAME detail [json]",
5664 "OSPF information\n"
5667 "detail of all neighbors\n"
5671 bool uj
= use_json(argc
, argv
);
5672 struct listnode
*node
= NULL
;
5673 int ret
= CMD_SUCCESS
;
5674 bool ospf_output
= false;
5676 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5677 if (!ospf
->oi_running
)
5680 ret
= show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, 4,
5685 vty_out(vty
, "%% OSPF instance not found\n");
5690 DEFUN (show_ip_ospf_instance_neighbor_int_detail
,
5691 show_ip_ospf_instance_neighbor_int_detail_cmd
,
5692 "show ip ospf (1-65535) neighbor IFNAME detail [json]",
5695 "OSPF information\n"
5699 "detail of all neighbors\n"
5705 unsigned short instance
= 0;
5706 bool uj
= use_json(argc
, argv
);
5708 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5709 ospf
= ospf_lookup_instance(instance
);
5711 return CMD_NOT_MY_INSTANCE
;
5713 if (!ospf
->oi_running
)
5716 return show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, idx_ifname
,
5720 /* Show functions */
5721 static int show_lsa_summary(struct vty
*vty
, struct ospf_lsa
*lsa
, int self
)
5723 struct router_lsa
*rl
;
5724 struct summary_lsa
*sl
;
5725 struct as_external_lsa
*asel
;
5726 struct prefix_ipv4 p
;
5729 /* If self option is set, check LSA self flag. */
5730 if (self
== 0 || IS_LSA_SELF(lsa
)) {
5731 /* LSA common part show. */
5732 vty_out(vty
, "%-15s ", inet_ntoa(lsa
->data
->id
));
5733 vty_out(vty
, "%-15s %4d 0x%08lx 0x%04x",
5734 inet_ntoa(lsa
->data
->adv_router
), LS_AGE(lsa
),
5735 (unsigned long)ntohl(lsa
->data
->ls_seqnum
),
5736 ntohs(lsa
->data
->checksum
));
5737 /* LSA specific part show. */
5738 switch (lsa
->data
->type
) {
5739 case OSPF_ROUTER_LSA
:
5740 rl
= (struct router_lsa
*)lsa
->data
;
5741 vty_out(vty
, " %-d", ntohs(rl
->links
));
5743 case OSPF_SUMMARY_LSA
:
5744 sl
= (struct summary_lsa
*)lsa
->data
;
5747 p
.prefix
= sl
->header
.id
;
5748 p
.prefixlen
= ip_masklen(sl
->mask
);
5749 apply_mask_ipv4(&p
);
5751 vty_out(vty
, " %s/%d", inet_ntoa(p
.prefix
),
5754 case OSPF_AS_EXTERNAL_LSA
:
5755 case OSPF_AS_NSSA_LSA
:
5756 asel
= (struct as_external_lsa
*)lsa
->data
;
5759 p
.prefix
= asel
->header
.id
;
5760 p
.prefixlen
= ip_masklen(asel
->mask
);
5761 apply_mask_ipv4(&p
);
5763 vty_out(vty
, " %s %s/%d [0x%lx]",
5764 IS_EXTERNAL_METRIC(asel
->e
[0].tos
)
5767 inet_ntoa(p
.prefix
), p
.prefixlen
,
5768 (unsigned long)ntohl(
5769 asel
->e
[0].route_tag
));
5771 case OSPF_NETWORK_LSA
:
5772 case OSPF_ASBR_SUMMARY_LSA
:
5773 case OSPF_OPAQUE_LINK_LSA
:
5774 case OSPF_OPAQUE_AREA_LSA
:
5775 case OSPF_OPAQUE_AS_LSA
:
5785 static const char *const show_database_desc
[] = {
5787 "Router Link States",
5789 "Summary Link States",
5790 "ASBR-Summary Link States",
5791 "AS External Link States",
5792 "Group Membership LSA",
5793 "NSSA-external Link States",
5795 "Link-Local Opaque-LSA",
5796 "Area-Local Opaque-LSA",
5797 "AS-external Opaque-LSA",
5800 static const char *const show_database_header
[] = {
5802 "Link ID ADV Router Age Seq# CkSum Link count",
5803 "Link ID ADV Router Age Seq# CkSum",
5804 "Link ID ADV Router Age Seq# CkSum Route",
5805 "Link ID ADV Router Age Seq# CkSum",
5806 "Link ID ADV Router Age Seq# CkSum Route",
5807 " --- header for Group Member ----",
5808 "Link ID ADV Router Age Seq# CkSum Route",
5810 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5811 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5812 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5815 static void show_ip_ospf_database_header(struct vty
*vty
, struct ospf_lsa
*lsa
)
5817 struct router_lsa
*rlsa
= (struct router_lsa
*)lsa
->data
;
5819 vty_out(vty
, " LS age: %d\n", LS_AGE(lsa
));
5820 vty_out(vty
, " Options: 0x%-2x : %s\n", lsa
->data
->options
,
5821 ospf_options_dump(lsa
->data
->options
));
5822 vty_out(vty
, " LS Flags: 0x%-2x %s\n", lsa
->flags
,
5823 ((lsa
->flags
& OSPF_LSA_LOCAL_XLT
) ? "(Translated from Type-7)"
5826 if (lsa
->data
->type
== OSPF_ROUTER_LSA
) {
5827 vty_out(vty
, " Flags: 0x%x", rlsa
->flags
);
5830 vty_out(vty
, " :%s%s%s%s",
5831 IS_ROUTER_LSA_BORDER(rlsa
) ? " ABR" : "",
5832 IS_ROUTER_LSA_EXTERNAL(rlsa
) ? " ASBR" : "",
5833 IS_ROUTER_LSA_VIRTUAL(rlsa
) ? " VL-endpoint"
5835 IS_ROUTER_LSA_SHORTCUT(rlsa
) ? " Shortcut"
5840 vty_out(vty
, " LS Type: %s\n",
5841 lookup_msg(ospf_lsa_type_msg
, lsa
->data
->type
, NULL
));
5842 vty_out(vty
, " Link State ID: %s %s\n", inet_ntoa(lsa
->data
->id
),
5843 lookup_msg(ospf_link_state_id_type_msg
, lsa
->data
->type
, NULL
));
5844 vty_out(vty
, " Advertising Router: %s\n",
5845 inet_ntoa(lsa
->data
->adv_router
));
5846 vty_out(vty
, " LS Seq Number: %08lx\n",
5847 (unsigned long)ntohl(lsa
->data
->ls_seqnum
));
5848 vty_out(vty
, " Checksum: 0x%04x\n", ntohs(lsa
->data
->checksum
));
5849 vty_out(vty
, " Length: %d\n\n", ntohs(lsa
->data
->length
));
5852 static const char *const link_type_desc
[] = {
5854 "another Router (point-to-point)",
5855 "a Transit Network",
5860 static const char *const link_id_desc
[] = {
5861 "(null)", "Neighboring Router ID", "Designated Router address",
5862 "Net", "Neighboring Router ID",
5865 static const char *const link_data_desc
[] = {
5866 "(null)", "Router Interface address", "Router Interface address",
5867 "Network Mask", "Router Interface address",
5870 /* Show router-LSA each Link information. */
5871 static void show_ip_ospf_database_router_links(struct vty
*vty
,
5872 struct router_lsa
*rl
)
5877 len
= ntohs(rl
->header
.length
) - 4;
5878 for (i
= 0; i
< ntohs(rl
->links
) && len
> 0; len
-= 12, i
++) {
5879 type
= rl
->link
[i
].type
;
5881 vty_out(vty
, " Link connected to: %s\n",
5882 link_type_desc
[type
]);
5883 vty_out(vty
, " (Link ID) %s: %s\n", link_id_desc
[type
],
5884 inet_ntoa(rl
->link
[i
].link_id
));
5885 vty_out(vty
, " (Link Data) %s: %s\n", link_data_desc
[type
],
5886 inet_ntoa(rl
->link
[i
].link_data
));
5887 vty_out(vty
, " Number of TOS metrics: 0\n");
5888 vty_out(vty
, " TOS 0 Metric: %d\n",
5889 ntohs(rl
->link
[i
].metric
));
5894 /* Show router-LSA detail information. */
5895 static int show_router_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5898 struct router_lsa
*rl
= (struct router_lsa
*)lsa
->data
;
5900 show_ip_ospf_database_header(vty
, lsa
);
5902 vty_out(vty
, " Number of Links: %d\n\n", ntohs(rl
->links
));
5904 show_ip_ospf_database_router_links(vty
, rl
);
5911 /* Show network-LSA detail information. */
5912 static int show_network_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5917 struct network_lsa
*nl
= (struct network_lsa
*)lsa
->data
;
5919 show_ip_ospf_database_header(vty
, lsa
);
5921 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(nl
->mask
));
5923 length
= ntohs(lsa
->data
->length
) - OSPF_LSA_HEADER_SIZE
- 4;
5925 for (i
= 0; length
> 0; i
++, length
-= 4)
5926 vty_out(vty
, " Attached Router: %s\n",
5927 inet_ntoa(nl
->routers
[i
]));
5935 /* Show summary-LSA detail information. */
5936 static int show_summary_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5939 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
5941 show_ip_ospf_database_header(vty
, lsa
);
5943 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(sl
->mask
));
5944 vty_out(vty
, " TOS: 0 Metric: %d\n",
5945 GET_METRIC(sl
->metric
));
5952 /* Show summary-ASBR-LSA detail information. */
5953 static int show_summary_asbr_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5956 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
5958 show_ip_ospf_database_header(vty
, lsa
);
5960 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(sl
->mask
));
5961 vty_out(vty
, " TOS: 0 Metric: %d\n",
5962 GET_METRIC(sl
->metric
));
5969 /* Show AS-external-LSA detail information. */
5970 static int show_as_external_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5973 struct as_external_lsa
*al
=
5974 (struct as_external_lsa
*)lsa
->data
;
5976 show_ip_ospf_database_header(vty
, lsa
);
5978 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(al
->mask
));
5979 vty_out(vty
, " Metric Type: %s\n",
5980 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
5981 ? "2 (Larger than any link state path)"
5983 vty_out(vty
, " TOS: 0\n");
5984 vty_out(vty
, " Metric: %d\n",
5985 GET_METRIC(al
->e
[0].metric
));
5986 vty_out(vty
, " Forward Address: %s\n",
5987 inet_ntoa(al
->e
[0].fwd_addr
));
5990 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
5991 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
5998 show_as_external_lsa_stdvty (struct ospf_lsa
*lsa
)
6000 struct as_external_lsa
*al
= (struct as_external_lsa
*) lsa
->data
;
6002 /* show_ip_ospf_database_header (vty, lsa); */
6004 zlog_debug( " Network Mask: /%d%s",
6005 ip_masklen (al
->mask
), "\n");
6006 zlog_debug( " Metric Type: %s%s",
6007 IS_EXTERNAL_METRIC (al
->e
[0].tos
) ?
6008 "2 (Larger than any link state path)" : "1", "\n");
6009 zlog_debug( " TOS: 0%s", "\n");
6010 zlog_debug( " Metric: %d%s",
6011 GET_METRIC (al
->e
[0].metric
), "\n");
6012 zlog_debug( " Forward Address: %s%s",
6013 inet_ntoa (al
->e
[0].fwd_addr
), "\n");
6015 zlog_debug( " External Route Tag: %"ROUTE_TAG_PRI
"%s%s",
6016 (route_tag_t
)ntohl (al
->e
[0].route_tag
), "\n", "\n");
6021 /* Show AS-NSSA-LSA detail information. */
6022 static int show_as_nssa_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
6025 struct as_external_lsa
*al
=
6026 (struct as_external_lsa
*)lsa
->data
;
6028 show_ip_ospf_database_header(vty
, lsa
);
6030 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(al
->mask
));
6031 vty_out(vty
, " Metric Type: %s\n",
6032 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6033 ? "2 (Larger than any link state path)"
6035 vty_out(vty
, " TOS: 0\n");
6036 vty_out(vty
, " Metric: %d\n",
6037 GET_METRIC(al
->e
[0].metric
));
6038 vty_out(vty
, " NSSA: Forward Address: %s\n",
6039 inet_ntoa(al
->e
[0].fwd_addr
));
6042 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
6043 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6049 static int show_func_dummy(struct vty
*vty
, struct ospf_lsa
*lsa
)
6054 static int show_opaque_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
6057 show_ip_ospf_database_header(vty
, lsa
);
6058 show_opaque_info_detail(vty
, lsa
);
6065 int (*const show_function
[])(struct vty
*, struct ospf_lsa
*) = {
6067 show_router_lsa_detail
,
6068 show_network_lsa_detail
,
6069 show_summary_lsa_detail
,
6070 show_summary_asbr_lsa_detail
,
6071 show_as_external_lsa_detail
,
6073 show_as_nssa_lsa_detail
, /* almost same as external */
6075 show_opaque_lsa_detail
,
6076 show_opaque_lsa_detail
,
6077 show_opaque_lsa_detail
,
6080 static void show_lsa_prefix_set(struct vty
*vty
, struct prefix_ls
*lp
,
6081 struct in_addr
*id
, struct in_addr
*adv_router
)
6083 memset(lp
, 0, sizeof(struct prefix_ls
));
6087 else if (adv_router
== NULL
) {
6093 lp
->adv_router
= *adv_router
;
6097 static void show_lsa_detail_proc(struct vty
*vty
, struct route_table
*rt
,
6098 struct in_addr
*id
, struct in_addr
*adv_router
)
6100 struct prefix_ls lp
;
6101 struct route_node
*rn
, *start
;
6102 struct ospf_lsa
*lsa
;
6104 show_lsa_prefix_set(vty
, &lp
, id
, adv_router
);
6105 start
= route_node_get(rt
, (struct prefix
*)&lp
);
6107 route_lock_node(start
);
6108 for (rn
= start
; rn
; rn
= route_next_until(rn
, start
))
6109 if ((lsa
= rn
->info
)) {
6110 if (show_function
[lsa
->data
->type
] != NULL
)
6111 show_function
[lsa
->data
->type
](vty
,
6114 route_unlock_node(start
);
6118 /* Show detail LSA information
6119 -- if id is NULL then show all LSAs. */
6120 static void show_lsa_detail(struct vty
*vty
, struct ospf
*ospf
, int type
,
6121 struct in_addr
*id
, struct in_addr
*adv_router
)
6123 struct listnode
*node
;
6124 struct ospf_area
*area
;
6127 case OSPF_AS_EXTERNAL_LSA
:
6128 case OSPF_OPAQUE_AS_LSA
:
6129 vty_out(vty
, " %s \n\n",
6130 show_database_desc
[type
]);
6131 show_lsa_detail_proc(vty
, AS_LSDB(ospf
, type
), id
, adv_router
);
6134 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6135 vty_out(vty
, "\n %s (Area %s)\n\n",
6136 show_database_desc
[type
],
6137 ospf_area_desc_string(area
));
6138 show_lsa_detail_proc(vty
, AREA_LSDB(area
, type
), id
,
6145 static void show_lsa_detail_adv_router_proc(struct vty
*vty
,
6146 struct route_table
*rt
,
6147 struct in_addr
*adv_router
)
6149 struct route_node
*rn
;
6150 struct ospf_lsa
*lsa
;
6152 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
))
6153 if ((lsa
= rn
->info
))
6154 if (IPV4_ADDR_SAME(adv_router
,
6155 &lsa
->data
->adv_router
)) {
6156 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
6158 if (show_function
[lsa
->data
->type
] != NULL
)
6159 show_function
[lsa
->data
->type
](vty
,
6164 /* Show detail LSA information. */
6165 static void show_lsa_detail_adv_router(struct vty
*vty
, struct ospf
*ospf
,
6166 int type
, struct in_addr
*adv_router
)
6168 struct listnode
*node
;
6169 struct ospf_area
*area
;
6172 case OSPF_AS_EXTERNAL_LSA
:
6173 case OSPF_OPAQUE_AS_LSA
:
6174 vty_out(vty
, " %s \n\n",
6175 show_database_desc
[type
]);
6176 show_lsa_detail_adv_router_proc(vty
, AS_LSDB(ospf
, type
),
6180 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6181 vty_out(vty
, "\n %s (Area %s)\n\n",
6182 show_database_desc
[type
],
6183 ospf_area_desc_string(area
));
6184 show_lsa_detail_adv_router_proc(
6185 vty
, AREA_LSDB(area
, type
), adv_router
);
6191 static void show_ip_ospf_database_summary(struct vty
*vty
, struct ospf
*ospf
,
6194 struct ospf_lsa
*lsa
;
6195 struct route_node
*rn
;
6196 struct ospf_area
*area
;
6197 struct listnode
*node
;
6200 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6201 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6203 case OSPF_AS_EXTERNAL_LSA
:
6204 case OSPF_OPAQUE_AS_LSA
:
6209 if (ospf_lsdb_count_self(area
->lsdb
, type
) > 0
6211 && ospf_lsdb_count(area
->lsdb
, type
) > 0)) {
6212 vty_out(vty
, " %s (Area %s)\n\n",
6213 show_database_desc
[type
],
6214 ospf_area_desc_string(area
));
6215 vty_out(vty
, "%s\n",
6216 show_database_header
[type
]);
6218 LSDB_LOOP (AREA_LSDB(area
, type
), rn
, lsa
)
6219 show_lsa_summary(vty
, lsa
, self
);
6226 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6228 case OSPF_AS_EXTERNAL_LSA
:
6229 case OSPF_OPAQUE_AS_LSA
:
6234 if (ospf_lsdb_count_self(ospf
->lsdb
, type
)
6235 || (!self
&& ospf_lsdb_count(ospf
->lsdb
, type
))) {
6236 vty_out(vty
, " %s\n\n",
6237 show_database_desc
[type
]);
6238 vty_out(vty
, "%s\n", show_database_header
[type
]);
6240 LSDB_LOOP (AS_LSDB(ospf
, type
), rn
, lsa
)
6241 show_lsa_summary(vty
, lsa
, self
);
6250 static void show_ip_ospf_database_maxage(struct vty
*vty
, struct ospf
*ospf
)
6252 struct route_node
*rn
;
6254 vty_out(vty
, "\n MaxAge Link States:\n\n");
6256 for (rn
= route_top(ospf
->maxage_lsa
); rn
; rn
= route_next(rn
)) {
6257 struct ospf_lsa
*lsa
;
6259 if ((lsa
= rn
->info
) != NULL
) {
6260 vty_out(vty
, "Link type: %d\n", lsa
->data
->type
);
6261 vty_out(vty
, "Link State ID: %s\n",
6262 inet_ntoa(lsa
->data
->id
));
6263 vty_out(vty
, "Advertising Router: %s\n",
6264 inet_ntoa(lsa
->data
->adv_router
));
6265 vty_out(vty
, "LSA lock count: %d\n", lsa
->lock
);
6271 #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
6272 #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
6274 #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
6275 #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
6276 #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
6277 #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
6279 #define OSPF_LSA_TYPES_DESC \
6280 "ASBR summary link states\n" \
6281 "External link states\n" \
6282 "Network link states\n" \
6283 "Router link states\n" \
6284 "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \
6285 OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
6286 OSPF_LSA_TYPE_OPAQUE_AS_DESC
6288 static int show_ip_ospf_database_common(struct vty
*vty
, struct ospf
*ospf
,
6289 int arg_base
, int argc
,
6290 struct cmd_token
**argv
,
6295 struct in_addr id
, adv_router
;
6298 vty_out(vty
, "\nOSPF Instance: %d\n", ospf
->instance
);
6300 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
6302 vty_out(vty
, "\n OSPF Router with ID (%s)\n\n",
6303 inet_ntoa(ospf
->router_id
));
6306 if (argc
== arg_base
+ 4) {
6307 show_ip_ospf_database_summary(vty
, ospf
, 0);
6311 /* Set database type to show. */
6312 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
6313 type
= OSPF_ROUTER_LSA
;
6314 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
6315 type
= OSPF_NETWORK_LSA
;
6316 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
6317 type
= OSPF_AS_NSSA_LSA
;
6318 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "su", 2) == 0)
6319 type
= OSPF_SUMMARY_LSA
;
6320 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
6321 type
= OSPF_ASBR_SUMMARY_LSA
;
6322 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
6323 type
= OSPF_AS_EXTERNAL_LSA
;
6324 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "se", 2) == 0) {
6325 show_ip_ospf_database_summary(vty
, ospf
, 1);
6327 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "m", 1) == 0) {
6328 show_ip_ospf_database_maxage(vty
, ospf
);
6330 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
6331 type
= OSPF_OPAQUE_LINK_LSA
;
6332 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
6333 type
= OSPF_OPAQUE_AREA_LSA
;
6334 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
6335 type
= OSPF_OPAQUE_AS_LSA
;
6339 /* `show ip ospf database LSA'. */
6340 if (argc
== arg_base
+ 5)
6341 show_lsa_detail(vty
, ospf
, type
, NULL
, NULL
);
6342 else if (argc
>= arg_base
+ 6) {
6343 ret
= inet_aton(argv
[arg_base
+ 5]->arg
, &id
);
6347 /* `show ip ospf database LSA ID'. */
6348 if (argc
== arg_base
+ 6)
6349 show_lsa_detail(vty
, ospf
, type
, &id
, NULL
);
6350 /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */
6351 else if (argc
== arg_base
+ 7) {
6352 if (strncmp(argv
[arg_base
+ 6]->text
, "s", 1) == 0)
6353 adv_router
= ospf
->router_id
;
6355 ret
= inet_aton(argv
[arg_base
+ 7]->arg
,
6360 show_lsa_detail(vty
, ospf
, type
, &id
, &adv_router
);
6367 DEFUN (show_ip_ospf_database_max
,
6368 show_ip_ospf_database_max_cmd
,
6369 "show ip ospf [vrf <NAME|all>] database <max-age|self-originate>",
6372 "OSPF information\n"
6375 "Database summary\n"
6376 "LSAs in MaxAge list\n"
6377 "Self-originated link states\n")
6379 struct ospf
*ospf
= NULL
;
6380 struct listnode
*node
= NULL
;
6381 char *vrf_name
= NULL
;
6382 bool all_vrf
= false;
6383 int ret
= CMD_SUCCESS
;
6386 uint8_t use_vrf
= 0;
6388 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
6391 bool ospf_output
= false;
6396 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6397 if (!ospf
->oi_running
)
6400 ret
= show_ip_ospf_database_common(
6401 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
,
6406 vty_out(vty
, "%% OSPF instance not found\n");
6408 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6409 if (ospf
== NULL
|| !ospf
->oi_running
) {
6410 vty_out(vty
, "%% OSPF instance not found\n");
6413 ret
= (show_ip_ospf_database_common(
6414 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
,
6418 /* Display default ospf (instance 0) info */
6419 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6420 if (ospf
== NULL
|| !ospf
->oi_running
) {
6421 vty_out(vty
, "%% OSPF instance not found\n");
6425 ret
= show_ip_ospf_database_common(vty
, ospf
, 0, argc
, argv
,
6432 DEFUN (show_ip_ospf_instance_database
,
6433 show_ip_ospf_instance_database_cmd
,
6434 "show ip ospf [{(1-65535)|vrf NAME}] 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>]]]",
6437 "OSPF information\n"
6440 "Database summary\n"
6442 "Link State ID (as an IP address)\n"
6443 "Self-originated link states\n"
6444 "Advertising Router link states\n"
6445 "Advertising Router (as an IP address)\n")
6448 unsigned short instance
= 0;
6449 struct listnode
*node
= NULL
;
6450 char *vrf_name
= NULL
;
6451 bool all_vrf
= false;
6452 int ret
= CMD_SUCCESS
;
6455 uint8_t use_vrf
= 0;
6457 if (argv_find(argv
, argc
, "(1-65535)", &idx
)) {
6458 instance
= strtoul(argv
[idx
]->arg
, NULL
, 10);
6459 ospf
= ospf_lookup_instance(instance
);
6461 return CMD_NOT_MY_INSTANCE
;
6462 if (!ospf
->oi_running
)
6465 return (show_ip_ospf_database_common(vty
, ospf
, idx
? 1 : 0,
6466 argc
, argv
, use_vrf
));
6467 } else if (argv_find(argv
, argc
, "vrf", &idx
)) {
6468 vrf_name
= argv
[++idx
]->arg
;
6469 all_vrf
= strmatch(vrf_name
, "all");
6475 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6476 if (!ospf
->oi_running
)
6478 ret
= (show_ip_ospf_database_common(
6479 vty
, ospf
, idx
? 2 : 0, argc
, argv
,
6483 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6484 if ((ospf
== NULL
) || !ospf
->oi_running
) {
6485 vty_out(vty
, "%% OSPF instance not found\n");
6489 ret
= (show_ip_ospf_database_common(
6490 vty
, ospf
, idx
? 2 : 0, argc
, argv
, use_vrf
));
6493 /* Display default ospf (instance 0) info */
6494 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6495 if (ospf
== NULL
|| !ospf
->oi_running
) {
6496 vty_out(vty
, "%% OSPF instance not found\n");
6500 ret
= (show_ip_ospf_database_common(vty
, ospf
, 0, argc
, argv
,
6507 DEFUN (show_ip_ospf_instance_database_max
,
6508 show_ip_ospf_instance_database_max_cmd
,
6509 "show ip ospf (1-65535) database <max-age|self-originate>",
6512 "OSPF information\n"
6514 "Database summary\n"
6515 "LSAs in MaxAge list\n"
6516 "Self-originated link states\n")
6520 unsigned short instance
= 0;
6522 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
6524 ospf
= ospf_lookup_instance(instance
);
6526 return CMD_NOT_MY_INSTANCE
;
6528 if (!ospf
->oi_running
) {
6529 vty_out(vty
, "%% OSPF instance not found\n");
6533 return show_ip_ospf_database_common(vty
, ospf
, 1, argc
, argv
, 0);
6537 static int show_ip_ospf_database_type_adv_router_common(struct vty
*vty
,
6539 int arg_base
, int argc
,
6540 struct cmd_token
**argv
,
6545 struct in_addr adv_router
;
6548 vty_out(vty
, "\nOSPF Instance: %d\n", ospf
->instance
);
6550 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
6552 vty_out(vty
, "\n OSPF Router with ID (%s)\n\n",
6553 inet_ntoa(ospf
->router_id
));
6555 /* Set database type to show. */
6556 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
6557 type
= OSPF_ROUTER_LSA
;
6558 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
6559 type
= OSPF_NETWORK_LSA
;
6560 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
6561 type
= OSPF_AS_NSSA_LSA
;
6562 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "s", 1) == 0)
6563 type
= OSPF_SUMMARY_LSA
;
6564 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
6565 type
= OSPF_ASBR_SUMMARY_LSA
;
6566 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
6567 type
= OSPF_AS_EXTERNAL_LSA
;
6568 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
6569 type
= OSPF_OPAQUE_LINK_LSA
;
6570 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
6571 type
= OSPF_OPAQUE_AREA_LSA
;
6572 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
6573 type
= OSPF_OPAQUE_AS_LSA
;
6577 /* `show ip ospf database LSA adv-router ADV_ROUTER'. */
6578 if (strncmp(argv
[arg_base
+ 5]->text
, "s", 1) == 0)
6579 adv_router
= ospf
->router_id
;
6581 ret
= inet_aton(argv
[arg_base
+ 6]->arg
, &adv_router
);
6586 show_lsa_detail_adv_router(vty
, ospf
, type
, &adv_router
);
6591 DEFUN (show_ip_ospf_instance_database_type_adv_router
,
6592 show_ip_ospf_instance_database_type_adv_router_cmd
,
6593 "show ip ospf [{(1-65535)|vrf NAME}] database <asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as> <adv-router A.B.C.D|self-originate>",
6596 "OSPF information\n"
6599 "Database summary\n"
6601 "Advertising Router link states\n"
6602 "Advertising Router (as an IP address)\n"
6603 "Self-originated link states\n")
6605 struct ospf
*ospf
= NULL
;
6606 unsigned short instance
= 0;
6607 struct listnode
*node
= NULL
;
6608 char *vrf_name
= NULL
;
6609 bool all_vrf
= false;
6610 int ret
= CMD_SUCCESS
;
6612 int idx
= 0, idx_vrf
= 0;
6613 uint8_t use_vrf
= 0;
6615 if (argv_find(argv
, argc
, "(1-65535)", &idx
)) {
6616 instance
= strtoul(argv
[idx
]->arg
, NULL
, 10);
6617 ospf
= ospf_lookup_instance(instance
);
6619 return CMD_NOT_MY_INSTANCE
;
6620 if (!ospf
->oi_running
) {
6621 vty_out(vty
, "%% OSPF instance not found\n");
6625 return (show_ip_ospf_database_type_adv_router_common(
6626 vty
, ospf
, idx
? 1 : 0, argc
, argv
, use_vrf
));
6629 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
6632 bool ospf_output
= false;
6637 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6638 if (!ospf
->oi_running
)
6641 ret
= show_ip_ospf_database_type_adv_router_common(
6642 vty
, ospf
, idx
? 1 : 0, argc
, argv
,
6646 vty_out(vty
, "%% OSPF instance not found\n");
6648 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6649 if ((ospf
== NULL
) || !ospf
->oi_running
) {
6650 vty_out(vty
, "%% OSPF instance not found\n");
6654 ret
= show_ip_ospf_database_type_adv_router_common(
6655 vty
, ospf
, idx
? 1 : 0, argc
, argv
, use_vrf
);
6658 /* Display default ospf (instance 0) info */
6659 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6660 if (ospf
== NULL
|| !ospf
->oi_running
) {
6661 vty_out(vty
, "%% OSPF instance not found\n");
6665 ret
= show_ip_ospf_database_type_adv_router_common(
6666 vty
, ospf
, idx
? 1 : 0, argc
, argv
, use_vrf
);
6669 /*return (show_ip_ospf_database_type_adv_router_common(
6670 vty, ospf, idx ? 1 : 0, argc, argv));*/
6673 DEFUN (ip_ospf_authentication_args
,
6674 ip_ospf_authentication_args_addr_cmd
,
6675 "ip ospf authentication <null|message-digest> [A.B.C.D]",
6677 "OSPF interface commands\n"
6678 "Enable authentication on this interface\n"
6679 "Use null authentication\n"
6680 "Use message-digest authentication\n"
6681 "Address of interface\n")
6683 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6684 int idx_encryption
= 3;
6686 struct in_addr addr
;
6688 struct ospf_if_params
*params
;
6690 params
= IF_DEF_PARAMS(ifp
);
6693 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6696 "Please specify interface address by A.B.C.D\n");
6697 return CMD_WARNING_CONFIG_FAILED
;
6700 params
= ospf_get_if_params(ifp
, addr
);
6701 ospf_if_update_params(ifp
, addr
);
6704 /* Handle null authentication */
6705 if (argv
[idx_encryption
]->arg
[0] == 'n') {
6706 SET_IF_PARAM(params
, auth_type
);
6707 params
->auth_type
= OSPF_AUTH_NULL
;
6711 /* Handle message-digest authentication */
6712 if (argv
[idx_encryption
]->arg
[0] == 'm') {
6713 SET_IF_PARAM(params
, auth_type
);
6714 params
->auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
6718 vty_out(vty
, "You shouldn't get here!\n");
6719 return CMD_WARNING_CONFIG_FAILED
;
6722 DEFUN (ip_ospf_authentication
,
6723 ip_ospf_authentication_addr_cmd
,
6724 "ip ospf authentication [A.B.C.D]",
6726 "OSPF interface commands\n"
6727 "Enable authentication on this interface\n"
6728 "Address of interface\n")
6730 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6732 struct in_addr addr
;
6734 struct ospf_if_params
*params
;
6736 params
= IF_DEF_PARAMS(ifp
);
6739 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6742 "Please specify interface address by A.B.C.D\n");
6743 return CMD_WARNING_CONFIG_FAILED
;
6746 params
= ospf_get_if_params(ifp
, addr
);
6747 ospf_if_update_params(ifp
, addr
);
6750 SET_IF_PARAM(params
, auth_type
);
6751 params
->auth_type
= OSPF_AUTH_SIMPLE
;
6756 DEFUN (no_ip_ospf_authentication_args
,
6757 no_ip_ospf_authentication_args_addr_cmd
,
6758 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
6761 "OSPF interface commands\n"
6762 "Enable authentication on this interface\n"
6763 "Use null authentication\n"
6764 "Use message-digest authentication\n"
6765 "Address of interface\n")
6767 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6768 int idx_encryption
= 4;
6770 struct in_addr addr
;
6772 struct ospf_if_params
*params
;
6773 struct route_node
*rn
;
6776 params
= IF_DEF_PARAMS(ifp
);
6779 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6782 "Please specify interface address by A.B.C.D\n");
6783 return CMD_WARNING_CONFIG_FAILED
;
6786 params
= ospf_lookup_if_params(ifp
, addr
);
6787 if (params
== NULL
) {
6788 vty_out(vty
, "Ip Address specified is unknown\n");
6789 return CMD_WARNING_CONFIG_FAILED
;
6791 params
->auth_type
= OSPF_AUTH_NOTSET
;
6792 UNSET_IF_PARAM(params
, auth_type
);
6793 if (params
!= IF_DEF_PARAMS(ifp
)) {
6794 ospf_free_if_params(ifp
, addr
);
6795 ospf_if_update_params(ifp
, addr
);
6798 if (argv
[idx_encryption
]->arg
[0] == 'n') {
6799 auth_type
= OSPF_AUTH_NULL
;
6800 } else if (argv
[idx_encryption
]->arg
[0] == 'm') {
6801 auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
6803 vty_out(vty
, "Unexpected input encountered\n");
6804 return CMD_WARNING_CONFIG_FAILED
;
6807 * Here we have a case where the user has entered
6808 * 'no ip ospf authentication (null | message_digest )'
6809 * we need to find if we have any ip addresses underneath it
6811 * correspond to the associated type.
6813 if (params
->auth_type
== auth_type
) {
6814 params
->auth_type
= OSPF_AUTH_NOTSET
;
6815 UNSET_IF_PARAM(params
, auth_type
);
6818 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
6819 rn
= route_next(rn
)) {
6820 if ((params
= rn
->info
)) {
6821 if (params
->auth_type
== auth_type
) {
6822 params
->auth_type
= OSPF_AUTH_NOTSET
;
6823 UNSET_IF_PARAM(params
, auth_type
);
6824 if (params
!= IF_DEF_PARAMS(ifp
)) {
6825 ospf_free_if_params(
6826 ifp
, rn
->p
.u
.prefix4
);
6827 ospf_if_update_params(
6828 ifp
, rn
->p
.u
.prefix4
);
6838 DEFUN (no_ip_ospf_authentication
,
6839 no_ip_ospf_authentication_addr_cmd
,
6840 "no ip ospf authentication [A.B.C.D]",
6843 "OSPF interface commands\n"
6844 "Enable authentication on this interface\n"
6845 "Address of interface\n")
6847 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6849 struct in_addr addr
;
6851 struct ospf_if_params
*params
;
6852 struct route_node
*rn
;
6854 params
= IF_DEF_PARAMS(ifp
);
6857 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6860 "Please specify interface address by A.B.C.D\n");
6861 return CMD_WARNING_CONFIG_FAILED
;
6864 params
= ospf_lookup_if_params(ifp
, addr
);
6865 if (params
== NULL
) {
6866 vty_out(vty
, "Ip Address specified is unknown\n");
6867 return CMD_WARNING_CONFIG_FAILED
;
6870 params
->auth_type
= OSPF_AUTH_NOTSET
;
6871 UNSET_IF_PARAM(params
, auth_type
);
6872 if (params
!= IF_DEF_PARAMS(ifp
)) {
6873 ospf_free_if_params(ifp
, addr
);
6874 ospf_if_update_params(ifp
, addr
);
6878 * When a user enters 'no ip ospf authentication'
6879 * We should remove all authentication types from
6882 if ((params
->auth_type
== OSPF_AUTH_NULL
)
6883 || (params
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
6884 || (params
->auth_type
== OSPF_AUTH_SIMPLE
)) {
6885 params
->auth_type
= OSPF_AUTH_NOTSET
;
6886 UNSET_IF_PARAM(params
, auth_type
);
6889 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
6890 rn
= route_next(rn
)) {
6891 if ((params
= rn
->info
)) {
6893 if ((params
->auth_type
== OSPF_AUTH_NULL
)
6894 || (params
->auth_type
6895 == OSPF_AUTH_CRYPTOGRAPHIC
)
6896 || (params
->auth_type
6897 == OSPF_AUTH_SIMPLE
)) {
6898 params
->auth_type
= OSPF_AUTH_NOTSET
;
6899 UNSET_IF_PARAM(params
, auth_type
);
6900 if (params
!= IF_DEF_PARAMS(ifp
)) {
6901 ospf_free_if_params(
6902 ifp
, rn
->p
.u
.prefix4
);
6903 ospf_if_update_params(
6904 ifp
, rn
->p
.u
.prefix4
);
6915 DEFUN (ip_ospf_authentication_key
,
6916 ip_ospf_authentication_key_addr_cmd
,
6917 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
6919 "OSPF interface commands\n"
6920 "Authentication password (key)\n"
6921 "The OSPF password (key)\n"
6922 "Address of interface\n")
6924 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6926 struct in_addr addr
;
6927 struct ospf_if_params
*params
;
6929 params
= IF_DEF_PARAMS(ifp
);
6931 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6932 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6934 "Please specify interface address by A.B.C.D\n");
6935 return CMD_WARNING_CONFIG_FAILED
;
6938 params
= ospf_get_if_params(ifp
, addr
);
6939 ospf_if_update_params(ifp
, addr
);
6942 strlcpy((char *)params
->auth_simple
, argv
[3]->arg
,
6943 sizeof(params
->auth_simple
));
6944 SET_IF_PARAM(params
, auth_simple
);
6949 DEFUN_HIDDEN (ospf_authentication_key
,
6950 ospf_authentication_key_cmd
,
6951 "ospf authentication-key AUTH_KEY [A.B.C.D]",
6952 "OSPF interface commands\n"
6953 VLINK_HELPSTR_AUTH_SIMPLE
6954 "Address of interface\n")
6956 return ip_ospf_authentication_key(self
, vty
, argc
, argv
);
6959 DEFUN (no_ip_ospf_authentication_key
,
6960 no_ip_ospf_authentication_key_authkey_addr_cmd
,
6961 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
6964 "OSPF interface commands\n"
6965 VLINK_HELPSTR_AUTH_SIMPLE
6966 "Address of interface\n")
6968 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6970 struct in_addr addr
;
6971 struct ospf_if_params
*params
;
6972 params
= IF_DEF_PARAMS(ifp
);
6974 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6975 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6977 "Please specify interface address by A.B.C.D\n");
6978 return CMD_WARNING_CONFIG_FAILED
;
6981 params
= ospf_lookup_if_params(ifp
, addr
);
6986 memset(params
->auth_simple
, 0, OSPF_AUTH_SIMPLE_SIZE
);
6987 UNSET_IF_PARAM(params
, auth_simple
);
6989 if (params
!= IF_DEF_PARAMS(ifp
)) {
6990 ospf_free_if_params(ifp
, addr
);
6991 ospf_if_update_params(ifp
, addr
);
6997 DEFUN_HIDDEN (no_ospf_authentication_key
,
6998 no_ospf_authentication_key_authkey_addr_cmd
,
6999 "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7001 "OSPF interface commands\n"
7002 VLINK_HELPSTR_AUTH_SIMPLE
7003 "Address of interface\n")
7005 return no_ip_ospf_authentication_key(self
, vty
, argc
, argv
);
7008 DEFUN (ip_ospf_message_digest_key
,
7009 ip_ospf_message_digest_key_cmd
,
7010 "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7012 "OSPF interface commands\n"
7013 "Message digest authentication password (key)\n"
7015 "Use MD5 algorithm\n"
7016 "The OSPF password (key)\n"
7017 "Address of interface\n")
7019 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7020 struct crypt_key
*ck
;
7022 struct in_addr addr
;
7023 struct ospf_if_params
*params
;
7025 params
= IF_DEF_PARAMS(ifp
);
7028 argv_find(argv
, argc
, "(1-255)", &idx
);
7029 char *keyid
= argv
[idx
]->arg
;
7030 argv_find(argv
, argc
, "KEY", &idx
);
7031 char *cryptkey
= argv
[idx
]->arg
;
7033 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7034 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7036 "Please specify interface address by A.B.C.D\n");
7037 return CMD_WARNING_CONFIG_FAILED
;
7040 params
= ospf_get_if_params(ifp
, addr
);
7041 ospf_if_update_params(ifp
, addr
);
7044 key_id
= strtol(keyid
, NULL
, 10);
7045 if (ospf_crypt_key_lookup(params
->auth_crypt
, key_id
) != NULL
) {
7046 vty_out(vty
, "OSPF: Key %d already exists\n", key_id
);
7050 ck
= ospf_crypt_key_new();
7051 ck
->key_id
= (uint8_t)key_id
;
7052 strlcpy((char *)ck
->auth_key
, cryptkey
, sizeof(ck
->auth_key
));
7054 ospf_crypt_key_add(params
->auth_crypt
, ck
);
7055 SET_IF_PARAM(params
, auth_crypt
);
7060 DEFUN_HIDDEN (ospf_message_digest_key
,
7061 ospf_message_digest_key_cmd
,
7062 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7063 "OSPF interface commands\n"
7064 "Message digest authentication password (key)\n"
7066 "Use MD5 algorithm\n"
7067 "The OSPF password (key)\n"
7068 "Address of interface\n")
7070 return ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7073 DEFUN (no_ip_ospf_message_digest_key
,
7074 no_ip_ospf_message_digest_key_cmd
,
7075 "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7078 "OSPF interface commands\n"
7079 "Message digest authentication password (key)\n"
7081 "Use MD5 algorithm\n"
7082 "The OSPF password (key)\n"
7083 "Address of interface\n")
7085 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7087 struct crypt_key
*ck
;
7089 struct in_addr addr
;
7090 struct ospf_if_params
*params
;
7091 params
= IF_DEF_PARAMS(ifp
);
7093 argv_find(argv
, argc
, "(1-255)", &idx
);
7094 char *keyid
= argv
[idx
]->arg
;
7096 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7097 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7099 "Please specify interface address by A.B.C.D\n");
7100 return CMD_WARNING_CONFIG_FAILED
;
7103 params
= ospf_lookup_if_params(ifp
, addr
);
7108 key_id
= strtol(keyid
, NULL
, 10);
7109 ck
= ospf_crypt_key_lookup(params
->auth_crypt
, key_id
);
7111 vty_out(vty
, "OSPF: Key %d does not exist\n", key_id
);
7112 return CMD_WARNING_CONFIG_FAILED
;
7115 ospf_crypt_key_delete(params
->auth_crypt
, key_id
);
7117 if (params
!= IF_DEF_PARAMS(ifp
)) {
7118 ospf_free_if_params(ifp
, addr
);
7119 ospf_if_update_params(ifp
, addr
);
7125 DEFUN_HIDDEN (no_ospf_message_digest_key
,
7126 no_ospf_message_digest_key_cmd
,
7127 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7129 "OSPF interface commands\n"
7130 "Message digest authentication password (key)\n"
7132 "Use MD5 algorithm\n"
7133 "The OSPF password (key)\n"
7134 "Address of interface\n")
7136 return no_ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7139 DEFUN (ip_ospf_cost
,
7141 "ip ospf cost (1-65535) [A.B.C.D]",
7143 "OSPF interface commands\n"
7146 "Address of interface\n")
7148 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7150 uint32_t cost
= OSPF_OUTPUT_COST_DEFAULT
;
7151 struct in_addr addr
;
7152 struct ospf_if_params
*params
;
7153 params
= IF_DEF_PARAMS(ifp
);
7156 char *coststr
= NULL
, *ifaddr
= NULL
;
7158 argv_find(argv
, argc
, "(1-65535)", &idx
);
7159 coststr
= argv
[idx
]->arg
;
7160 cost
= strtol(coststr
, NULL
, 10);
7162 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7164 if (!inet_aton(ifaddr
, &addr
)) {
7166 "Please specify interface address by A.B.C.D\n");
7167 return CMD_WARNING_CONFIG_FAILED
;
7170 params
= ospf_get_if_params(ifp
, addr
);
7171 ospf_if_update_params(ifp
, addr
);
7174 SET_IF_PARAM(params
, output_cost_cmd
);
7175 params
->output_cost_cmd
= cost
;
7177 ospf_if_recalculate_output_cost(ifp
);
7182 DEFUN_HIDDEN (ospf_cost
,
7184 "ospf cost (1-65535) [A.B.C.D]",
7185 "OSPF interface commands\n"
7188 "Address of interface\n")
7190 return ip_ospf_cost(self
, vty
, argc
, argv
);
7193 DEFUN (no_ip_ospf_cost
,
7194 no_ip_ospf_cost_cmd
,
7195 "no ip ospf cost [(1-65535)] [A.B.C.D]",
7198 "OSPF interface commands\n"
7201 "Address of interface\n")
7203 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7205 struct in_addr addr
;
7206 struct ospf_if_params
*params
;
7208 params
= IF_DEF_PARAMS(ifp
);
7211 char *ifaddr
= NULL
;
7212 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7214 /* According to the semantics we are mimicking "no ip ospf cost N" is
7215 * always treated as "no ip ospf cost" regardless of the actual value
7216 * of N already configured for the interface. Thus ignore cost. */
7219 if (!inet_aton(ifaddr
, &addr
)) {
7221 "Please specify interface address by A.B.C.D\n");
7222 return CMD_WARNING_CONFIG_FAILED
;
7225 params
= ospf_lookup_if_params(ifp
, addr
);
7230 UNSET_IF_PARAM(params
, output_cost_cmd
);
7232 if (params
!= IF_DEF_PARAMS(ifp
)) {
7233 ospf_free_if_params(ifp
, addr
);
7234 ospf_if_update_params(ifp
, addr
);
7237 ospf_if_recalculate_output_cost(ifp
);
7242 DEFUN_HIDDEN (no_ospf_cost
,
7244 "no ospf cost [(1-65535)] [A.B.C.D]",
7246 "OSPF interface commands\n"
7249 "Address of interface\n")
7251 return no_ip_ospf_cost(self
, vty
, argc
, argv
);
7254 static void ospf_nbr_timer_update(struct ospf_interface
*oi
)
7256 struct route_node
*rn
;
7257 struct ospf_neighbor
*nbr
;
7259 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
7260 if ((nbr
= rn
->info
)) {
7261 nbr
->v_inactivity
= OSPF_IF_PARAM(oi
, v_wait
);
7262 nbr
->v_db_desc
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7263 nbr
->v_ls_req
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7264 nbr
->v_ls_upd
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7268 static int ospf_vty_dead_interval_set(struct vty
*vty
, const char *interval_str
,
7269 const char *nbr_str
,
7270 const char *fast_hello_str
)
7272 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7275 struct in_addr addr
;
7277 struct ospf_if_params
*params
;
7278 struct ospf_interface
*oi
;
7279 struct route_node
*rn
;
7281 params
= IF_DEF_PARAMS(ifp
);
7284 ret
= inet_aton(nbr_str
, &addr
);
7287 "Please specify interface address by A.B.C.D\n");
7288 return CMD_WARNING_CONFIG_FAILED
;
7291 params
= ospf_get_if_params(ifp
, addr
);
7292 ospf_if_update_params(ifp
, addr
);
7296 seconds
= strtoul(interval_str
, NULL
, 10);
7298 /* reset fast_hello too, just to be sure */
7299 UNSET_IF_PARAM(params
, fast_hello
);
7300 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
7301 } else if (fast_hello_str
) {
7302 hellomult
= strtoul(fast_hello_str
, NULL
, 10);
7303 /* 1s dead-interval with sub-second hellos desired */
7304 seconds
= OSPF_ROUTER_DEAD_INTERVAL_MINIMAL
;
7305 SET_IF_PARAM(params
, fast_hello
);
7306 params
->fast_hello
= hellomult
;
7309 "Please specify dead-interval or hello-multiplier\n");
7310 return CMD_WARNING_CONFIG_FAILED
;
7313 SET_IF_PARAM(params
, v_wait
);
7314 params
->v_wait
= seconds
;
7316 /* Update timer values in neighbor structure. */
7318 struct ospf
*ospf
= NULL
;
7320 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7322 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
7324 ospf_nbr_timer_update(oi
);
7327 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
7328 if ((oi
= rn
->info
))
7329 ospf_nbr_timer_update(oi
);
7335 DEFUN (ip_ospf_dead_interval
,
7336 ip_ospf_dead_interval_cmd
,
7337 "ip ospf dead-interval (1-65535) [A.B.C.D]",
7339 "OSPF interface commands\n"
7340 "Interval time after which a neighbor is declared down\n"
7342 "Address of interface\n")
7345 char *interval
= argv_find(argv
, argc
, "(1-65535)", &idx
)
7349 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7350 return ospf_vty_dead_interval_set(vty
, interval
, ifaddr
, NULL
);
7354 DEFUN_HIDDEN (ospf_dead_interval
,
7355 ospf_dead_interval_cmd
,
7356 "ospf dead-interval (1-65535) [A.B.C.D]",
7357 "OSPF interface commands\n"
7358 "Interval time after which a neighbor is declared down\n"
7360 "Address of interface\n")
7362 return ip_ospf_dead_interval(self
, vty
, argc
, argv
);
7365 DEFUN (ip_ospf_dead_interval_minimal
,
7366 ip_ospf_dead_interval_minimal_addr_cmd
,
7367 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
7369 "OSPF interface commands\n"
7370 "Interval time after which a neighbor is declared down\n"
7371 "Minimal 1s dead-interval with fast sub-second hellos\n"
7372 "Hello multiplier factor\n"
7373 "Number of Hellos to send each second\n"
7374 "Address of interface\n")
7379 return ospf_vty_dead_interval_set(
7380 vty
, NULL
, argv
[idx_ipv4
]->arg
, argv
[idx_number
]->arg
);
7382 return ospf_vty_dead_interval_set(vty
, NULL
, NULL
,
7383 argv
[idx_number
]->arg
);
7386 DEFUN (no_ip_ospf_dead_interval
,
7387 no_ip_ospf_dead_interval_cmd
,
7388 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
7391 "OSPF interface commands\n"
7392 "Interval time after which a neighbor is declared down\n"
7394 "Minimal 1s dead-interval with fast sub-second hellos\n"
7395 "Hello multiplier factor\n"
7396 "Number of Hellos to send each second\n"
7397 "Address of interface\n")
7399 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7400 int idx_ipv4
= argc
- 1;
7401 struct in_addr addr
= {.s_addr
= 0L};
7403 struct ospf_if_params
*params
;
7404 struct ospf_interface
*oi
;
7405 struct route_node
*rn
;
7407 params
= IF_DEF_PARAMS(ifp
);
7409 if (argv
[idx_ipv4
]->type
== IPV4_TKN
) {
7410 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7413 "Please specify interface address by A.B.C.D\n");
7414 return CMD_WARNING_CONFIG_FAILED
;
7417 params
= ospf_lookup_if_params(ifp
, addr
);
7422 UNSET_IF_PARAM(params
, v_wait
);
7423 params
->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
7425 UNSET_IF_PARAM(params
, fast_hello
);
7426 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
7428 if (params
!= IF_DEF_PARAMS(ifp
)) {
7429 ospf_free_if_params(ifp
, addr
);
7430 ospf_if_update_params(ifp
, addr
);
7433 /* Update timer values in neighbor structure. */
7435 struct ospf
*ospf
= NULL
;
7437 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7439 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
7441 ospf_nbr_timer_update(oi
);
7444 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
7445 if ((oi
= rn
->info
))
7446 ospf_nbr_timer_update(oi
);
7452 DEFUN_HIDDEN (no_ospf_dead_interval
,
7453 no_ospf_dead_interval_cmd
,
7454 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
7456 "OSPF interface commands\n"
7457 "Interval time after which a neighbor is declared down\n"
7459 "Minimal 1s dead-interval with fast sub-second hellos\n"
7460 "Hello multiplier factor\n"
7461 "Number of Hellos to send each second\n"
7462 "Address of interface\n")
7464 return no_ip_ospf_dead_interval(self
, vty
, argc
, argv
);
7467 DEFUN (ip_ospf_hello_interval
,
7468 ip_ospf_hello_interval_cmd
,
7469 "ip ospf hello-interval (1-65535) [A.B.C.D]",
7471 "OSPF interface commands\n"
7472 "Time between HELLO packets\n"
7474 "Address of interface\n")
7476 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7478 struct in_addr addr
;
7479 struct ospf_if_params
*params
;
7480 params
= IF_DEF_PARAMS(ifp
);
7481 uint32_t seconds
= 0;
7483 argv_find(argv
, argc
, "(1-65535)", &idx
);
7484 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7486 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7487 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7489 "Please specify interface address by A.B.C.D\n");
7490 return CMD_WARNING_CONFIG_FAILED
;
7493 params
= ospf_get_if_params(ifp
, addr
);
7494 ospf_if_update_params(ifp
, addr
);
7497 SET_IF_PARAM(params
, v_hello
);
7498 params
->v_hello
= seconds
;
7503 DEFUN_HIDDEN (ospf_hello_interval
,
7504 ospf_hello_interval_cmd
,
7505 "ospf hello-interval (1-65535) [A.B.C.D]",
7506 "OSPF interface commands\n"
7507 "Time between HELLO packets\n"
7509 "Address of interface\n")
7511 return ip_ospf_hello_interval(self
, vty
, argc
, argv
);
7514 DEFUN (no_ip_ospf_hello_interval
,
7515 no_ip_ospf_hello_interval_cmd
,
7516 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
7519 "OSPF interface commands\n"
7520 "Time between HELLO packets\n" // ignored
7522 "Address of interface\n")
7524 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7526 struct in_addr addr
;
7527 struct ospf_if_params
*params
;
7529 params
= IF_DEF_PARAMS(ifp
);
7531 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7532 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7534 "Please specify interface address by A.B.C.D\n");
7535 return CMD_WARNING_CONFIG_FAILED
;
7538 params
= ospf_lookup_if_params(ifp
, addr
);
7543 UNSET_IF_PARAM(params
, v_hello
);
7544 params
->v_hello
= OSPF_HELLO_INTERVAL_DEFAULT
;
7546 if (params
!= IF_DEF_PARAMS(ifp
)) {
7547 ospf_free_if_params(ifp
, addr
);
7548 ospf_if_update_params(ifp
, addr
);
7554 DEFUN_HIDDEN (no_ospf_hello_interval
,
7555 no_ospf_hello_interval_cmd
,
7556 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
7558 "OSPF interface commands\n"
7559 "Time between HELLO packets\n" // ignored
7561 "Address of interface\n")
7563 return no_ip_ospf_hello_interval(self
, vty
, argc
, argv
);
7566 DEFUN (ip_ospf_network
,
7567 ip_ospf_network_cmd
,
7568 "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
7570 "OSPF interface commands\n"
7572 "Specify OSPF broadcast multi-access network\n"
7573 "Specify OSPF NBMA network\n"
7574 "Specify OSPF point-to-multipoint network\n"
7575 "Specify OSPF point-to-point network\n")
7577 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7579 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
7580 struct route_node
*rn
;
7582 if (old_type
== OSPF_IFTYPE_LOOPBACK
) {
7584 "This is a loopback interface. Can't set network type.\n");
7585 return CMD_WARNING_CONFIG_FAILED
;
7588 if (argv_find(argv
, argc
, "broadcast", &idx
))
7589 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_BROADCAST
;
7590 else if (argv_find(argv
, argc
, "non-broadcast", &idx
))
7591 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_NBMA
;
7592 else if (argv_find(argv
, argc
, "point-to-multipoint", &idx
))
7593 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOMULTIPOINT
;
7594 else if (argv_find(argv
, argc
, "point-to-point", &idx
))
7595 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOPOINT
;
7597 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
7600 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), type
);
7602 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7603 struct ospf_interface
*oi
= rn
->info
;
7608 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
7610 if (oi
->state
> ISM_Down
) {
7611 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
7612 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
7619 DEFUN_HIDDEN (ospf_network
,
7621 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
7622 "OSPF interface commands\n"
7624 "Specify OSPF broadcast multi-access network\n"
7625 "Specify OSPF NBMA network\n"
7626 "Specify OSPF point-to-multipoint network\n"
7627 "Specify OSPF point-to-point network\n")
7629 return ip_ospf_network(self
, vty
, argc
, argv
);
7632 DEFUN (no_ip_ospf_network
,
7633 no_ip_ospf_network_cmd
,
7634 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
7637 "OSPF interface commands\n"
7639 "Specify OSPF broadcast multi-access network\n"
7640 "Specify OSPF NBMA network\n"
7641 "Specify OSPF point-to-multipoint network\n"
7642 "Specify OSPF point-to-point network\n")
7644 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7645 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
7646 struct route_node
*rn
;
7648 IF_DEF_PARAMS(ifp
)->type
= ospf_default_iftype(ifp
);
7650 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
7653 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7654 struct ospf_interface
*oi
= rn
->info
;
7659 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
7661 if (oi
->state
> ISM_Down
) {
7662 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
7663 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
7670 DEFUN_HIDDEN (no_ospf_network
,
7671 no_ospf_network_cmd
,
7672 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
7674 "OSPF interface commands\n"
7676 "Specify OSPF broadcast multi-access network\n"
7677 "Specify OSPF NBMA network\n"
7678 "Specify OSPF point-to-multipoint network\n"
7679 "Specify OSPF point-to-point network\n")
7681 return no_ip_ospf_network(self
, vty
, argc
, argv
);
7684 DEFUN (ip_ospf_priority
,
7685 ip_ospf_priority_cmd
,
7686 "ip ospf priority (0-255) [A.B.C.D]",
7688 "OSPF interface commands\n"
7691 "Address of interface\n")
7693 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7696 struct route_node
*rn
;
7697 struct in_addr addr
;
7698 struct ospf_if_params
*params
;
7699 params
= IF_DEF_PARAMS(ifp
);
7701 argv_find(argv
, argc
, "(0-255)", &idx
);
7702 priority
= strtol(argv
[idx
]->arg
, NULL
, 10);
7704 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7705 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7707 "Please specify interface address by A.B.C.D\n");
7708 return CMD_WARNING_CONFIG_FAILED
;
7711 params
= ospf_get_if_params(ifp
, addr
);
7712 ospf_if_update_params(ifp
, addr
);
7715 SET_IF_PARAM(params
, priority
);
7716 params
->priority
= priority
;
7718 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7719 struct ospf_interface
*oi
= rn
->info
;
7724 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
7725 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
7726 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
7733 DEFUN_HIDDEN (ospf_priority
,
7735 "ospf priority (0-255) [A.B.C.D]",
7736 "OSPF interface commands\n"
7739 "Address of interface\n")
7741 return ip_ospf_priority(self
, vty
, argc
, argv
);
7744 DEFUN (no_ip_ospf_priority
,
7745 no_ip_ospf_priority_cmd
,
7746 "no ip ospf priority [(0-255) [A.B.C.D]]",
7749 "OSPF interface commands\n"
7750 "Router priority\n" // ignored
7752 "Address of interface\n")
7754 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7756 struct route_node
*rn
;
7757 struct in_addr addr
;
7758 struct ospf_if_params
*params
;
7760 params
= IF_DEF_PARAMS(ifp
);
7762 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7763 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7765 "Please specify interface address by A.B.C.D\n");
7766 return CMD_WARNING_CONFIG_FAILED
;
7769 params
= ospf_lookup_if_params(ifp
, addr
);
7774 UNSET_IF_PARAM(params
, priority
);
7775 params
->priority
= OSPF_ROUTER_PRIORITY_DEFAULT
;
7777 if (params
!= IF_DEF_PARAMS(ifp
)) {
7778 ospf_free_if_params(ifp
, addr
);
7779 ospf_if_update_params(ifp
, addr
);
7782 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7783 struct ospf_interface
*oi
= rn
->info
;
7788 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
7789 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
7790 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
7797 DEFUN_HIDDEN (no_ospf_priority
,
7798 no_ospf_priority_cmd
,
7799 "no ospf priority [(0-255) [A.B.C.D]]",
7801 "OSPF interface commands\n"
7804 "Address of interface\n")
7806 return no_ip_ospf_priority(self
, vty
, argc
, argv
);
7809 DEFUN (ip_ospf_retransmit_interval
,
7810 ip_ospf_retransmit_interval_addr_cmd
,
7811 "ip ospf retransmit-interval (3-65535) [A.B.C.D]",
7813 "OSPF interface commands\n"
7814 "Time between retransmitting lost link state advertisements\n"
7816 "Address of interface\n")
7818 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7821 struct in_addr addr
;
7822 struct ospf_if_params
*params
;
7823 params
= IF_DEF_PARAMS(ifp
);
7825 argv_find(argv
, argc
, "(3-65535)", &idx
);
7826 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7828 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7829 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7831 "Please specify interface address by A.B.C.D\n");
7832 return CMD_WARNING_CONFIG_FAILED
;
7835 params
= ospf_get_if_params(ifp
, addr
);
7836 ospf_if_update_params(ifp
, addr
);
7839 SET_IF_PARAM(params
, retransmit_interval
);
7840 params
->retransmit_interval
= seconds
;
7845 DEFUN_HIDDEN (ospf_retransmit_interval
,
7846 ospf_retransmit_interval_cmd
,
7847 "ospf retransmit-interval (3-65535) [A.B.C.D]",
7848 "OSPF interface commands\n"
7849 "Time between retransmitting lost link state advertisements\n"
7851 "Address of interface\n")
7853 return ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
7856 DEFUN (no_ip_ospf_retransmit_interval
,
7857 no_ip_ospf_retransmit_interval_addr_cmd
,
7858 "no ip ospf retransmit-interval [(3-65535)] [A.B.C.D]",
7861 "OSPF interface commands\n"
7862 "Time between retransmitting lost link state advertisements\n"
7864 "Address of interface\n")
7866 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7868 struct in_addr addr
;
7869 struct ospf_if_params
*params
;
7871 params
= IF_DEF_PARAMS(ifp
);
7873 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7874 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7876 "Please specify interface address by A.B.C.D\n");
7877 return CMD_WARNING_CONFIG_FAILED
;
7880 params
= ospf_lookup_if_params(ifp
, addr
);
7885 UNSET_IF_PARAM(params
, retransmit_interval
);
7886 params
->retransmit_interval
= OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
7888 if (params
!= IF_DEF_PARAMS(ifp
)) {
7889 ospf_free_if_params(ifp
, addr
);
7890 ospf_if_update_params(ifp
, addr
);
7896 DEFUN_HIDDEN (no_ospf_retransmit_interval
,
7897 no_ospf_retransmit_interval_cmd
,
7898 "no ospf retransmit-interval [(3-65535)] [A.B.C.D]",
7900 "OSPF interface commands\n"
7901 "Time between retransmitting lost link state advertisements\n"
7903 "Address of interface\n")
7905 return no_ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
7908 DEFUN (ip_ospf_transmit_delay
,
7909 ip_ospf_transmit_delay_addr_cmd
,
7910 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
7912 "OSPF interface commands\n"
7913 "Link state transmit delay\n"
7915 "Address of interface\n")
7917 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7920 struct in_addr addr
;
7921 struct ospf_if_params
*params
;
7923 params
= IF_DEF_PARAMS(ifp
);
7924 argv_find(argv
, argc
, "(1-65535)", &idx
);
7925 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7927 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7928 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7930 "Please specify interface address by A.B.C.D\n");
7931 return CMD_WARNING_CONFIG_FAILED
;
7934 params
= ospf_get_if_params(ifp
, addr
);
7935 ospf_if_update_params(ifp
, addr
);
7938 SET_IF_PARAM(params
, transmit_delay
);
7939 params
->transmit_delay
= seconds
;
7944 DEFUN_HIDDEN (ospf_transmit_delay
,
7945 ospf_transmit_delay_cmd
,
7946 "ospf transmit-delay (1-65535) [A.B.C.D]",
7947 "OSPF interface commands\n"
7948 "Link state transmit delay\n"
7950 "Address of interface\n")
7952 return ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
7955 DEFUN (no_ip_ospf_transmit_delay
,
7956 no_ip_ospf_transmit_delay_addr_cmd
,
7957 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
7960 "OSPF interface commands\n"
7961 "Link state transmit delay\n"
7963 "Address of interface\n")
7965 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7967 struct in_addr addr
;
7968 struct ospf_if_params
*params
;
7970 params
= IF_DEF_PARAMS(ifp
);
7972 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7973 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7975 "Please specify interface address by A.B.C.D\n");
7976 return CMD_WARNING_CONFIG_FAILED
;
7979 params
= ospf_lookup_if_params(ifp
, addr
);
7984 UNSET_IF_PARAM(params
, transmit_delay
);
7985 params
->transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
7987 if (params
!= IF_DEF_PARAMS(ifp
)) {
7988 ospf_free_if_params(ifp
, addr
);
7989 ospf_if_update_params(ifp
, addr
);
7996 DEFUN_HIDDEN (no_ospf_transmit_delay
,
7997 no_ospf_transmit_delay_cmd
,
7998 "no ospf transmit-delay [(1-65535) [A.B.C.D]]",
8000 "OSPF interface commands\n"
8001 "Link state transmit delay\n"
8003 "Address of interface\n")
8005 return no_ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
8008 DEFUN (ip_ospf_area
,
8010 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]",
8012 "OSPF interface commands\n"
8014 "Enable OSPF on this interface\n"
8015 "OSPF area ID in IP address format\n"
8016 "OSPF area ID as a decimal value\n"
8017 "Address of interface\n")
8019 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8022 struct in_addr area_id
;
8023 struct in_addr addr
;
8024 struct ospf_if_params
*params
= NULL
;
8025 struct route_node
*rn
;
8026 struct ospf
*ospf
= NULL
;
8027 unsigned short instance
= 0;
8030 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
8031 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
8033 argv_find(argv
, argc
, "area", &idx
);
8034 areaid
= argv
[idx
+ 1]->arg
;
8036 if (ifp
->vrf_id
&& !instance
)
8037 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
8039 ospf
= ospf_lookup_instance(instance
);
8041 if (instance
&& ospf
== NULL
) {
8042 params
= IF_DEF_PARAMS(ifp
);
8043 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8044 UNSET_IF_PARAM(params
, if_area
);
8045 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
8046 ospf_interface_area_unset(ospf
, ifp
);
8047 ospf
->if_ospf_cli_count
--;
8049 return CMD_NOT_MY_INSTANCE
;
8052 ret
= str2area_id(areaid
, &area_id
, &format
);
8054 vty_out(vty
, "Please specify area by A.B.C.D|<0-4294967295>\n");
8055 return CMD_WARNING_CONFIG_FAILED
;
8057 if (memcmp(ifp
->name
, "VLINK", 5) == 0) {
8058 vty_out(vty
, "Cannot enable OSPF on a virtual link.\n");
8059 return CMD_WARNING_CONFIG_FAILED
;
8062 params
= IF_DEF_PARAMS(ifp
);
8063 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)
8064 && !IPV4_ADDR_SAME(¶ms
->if_area
, &area_id
)) {
8066 "Must remove previous area config before changing ospf area \n");
8067 return CMD_WARNING_CONFIG_FAILED
;
8070 // Check if we have an address arg and proccess it
8071 if (argc
== idx
+ 3) {
8072 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
8074 "Please specify Intf Address by A.B.C.D\n");
8075 return CMD_WARNING_CONFIG_FAILED
;
8077 // update/create address-level params
8078 params
= ospf_get_if_params((ifp
), (addr
));
8079 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8081 "Must remove previous area/address config before changing ospf area");
8082 return CMD_WARNING_CONFIG_FAILED
;
8084 ospf_if_update_params((ifp
), (addr
));
8088 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
)) {
8089 if (rn
->info
!= NULL
) {
8091 "Please remove all network commands first.\n");
8092 return CMD_WARNING_CONFIG_FAILED
;
8097 /* enable ospf on this interface with area_id */
8099 SET_IF_PARAM(params
, if_area
);
8100 params
->if_area
= area_id
;
8101 params
->if_area_id_fmt
= format
;
8105 ospf_interface_area_set(ospf
, ifp
);
8106 ospf
->if_ospf_cli_count
++;
8112 DEFUN (no_ip_ospf_area
,
8113 no_ip_ospf_area_cmd
,
8114 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]",
8117 "OSPF interface commands\n"
8119 "Disable OSPF on this interface\n"
8120 "OSPF area ID in IP address format\n"
8121 "OSPF area ID as a decimal value\n"
8122 "Address of interface\n")
8124 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8127 struct ospf_if_params
*params
;
8128 unsigned short instance
= 0;
8129 struct in_addr addr
;
8131 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
8132 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
8134 if (ifp
->vrf_id
&& !instance
)
8135 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
8137 ospf
= ospf_lookup_instance(instance
);
8140 return CMD_NOT_MY_INSTANCE
;
8142 argv_find(argv
, argc
, "area", &idx
);
8144 // Check if we have an address arg and proccess it
8145 if (argc
== idx
+ 3) {
8146 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
8148 "Please specify Intf Address by A.B.C.D\n");
8149 return CMD_WARNING_CONFIG_FAILED
;
8151 params
= ospf_lookup_if_params(ifp
, addr
);
8152 if ((params
) == NULL
)
8155 params
= IF_DEF_PARAMS(ifp
);
8157 if (!OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8159 "Can't find specified interface area configuration.\n");
8160 return CMD_WARNING_CONFIG_FAILED
;
8163 UNSET_IF_PARAM(params
, if_area
);
8164 if (params
!= IF_DEF_PARAMS((ifp
))) {
8165 ospf_free_if_params((ifp
), (addr
));
8166 ospf_if_update_params((ifp
), (addr
));
8169 ospf_interface_area_unset(ospf
, ifp
);
8170 ospf
->if_ospf_cli_count
--;
8174 DEFUN (ospf_redistribute_source
,
8175 ospf_redistribute_source_cmd
,
8176 "redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8178 FRR_REDIST_HELP_STR_OSPFD
8179 "Metric for redistributed routes\n"
8180 "OSPF default metric\n"
8181 "OSPF exterior metric type for redistributed routes\n"
8182 "Set OSPF External Type 1/2 metrics\n"
8183 "Route map reference\n"
8184 "Pointer to route-map entries\n")
8186 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8187 int idx_protocol
= 1;
8191 struct ospf_redist
*red
;
8194 /* Get distribute source. */
8195 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
8197 return CMD_WARNING_CONFIG_FAILED
;
8199 red
= ospf_redist_add(ospf
, source
, 0);
8201 /* Get metric value. */
8202 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
8203 if (!str2metric(argv
[idx
]->arg
, &metric
))
8204 return CMD_WARNING_CONFIG_FAILED
;
8207 /* Get metric type. */
8208 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
8209 if (!str2metric_type(argv
[idx
]->arg
, &type
))
8210 return CMD_WARNING_CONFIG_FAILED
;
8214 if (argv_find(argv
, argc
, "WORD", &idx
)) {
8215 ospf_routemap_set(red
, argv
[idx
]->arg
);
8217 ospf_routemap_unset(red
);
8219 return ospf_redistribute_set(ospf
, source
, 0, type
, metric
);
8222 DEFUN (no_ospf_redistribute_source
,
8223 no_ospf_redistribute_source_cmd
,
8224 "no redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8227 FRR_REDIST_HELP_STR_OSPFD
8228 "Metric for redistributed routes\n"
8229 "OSPF default metric\n"
8230 "OSPF exterior metric type for redistributed routes\n"
8231 "Set OSPF External Type 1/2 metrics\n"
8232 "Route map reference\n"
8233 "Pointer to route-map entries\n")
8235 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8236 int idx_protocol
= 2;
8238 struct ospf_redist
*red
;
8240 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
8242 return CMD_WARNING_CONFIG_FAILED
;
8244 red
= ospf_redist_lookup(ospf
, source
, 0);
8248 ospf_routemap_unset(red
);
8249 ospf_redist_del(ospf
, source
, 0);
8251 return ospf_redistribute_unset(ospf
, source
, 0);
8254 DEFUN (ospf_redistribute_instance_source
,
8255 ospf_redistribute_instance_source_cmd
,
8256 "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8258 "Open Shortest Path First\n"
8259 "Non-main Kernel Routing Table\n"
8260 "Instance ID/Table ID\n"
8261 "Metric for redistributed routes\n"
8262 "OSPF default metric\n"
8263 "OSPF exterior metric type for redistributed routes\n"
8264 "Set OSPF External Type 1/2 metrics\n"
8265 "Route map reference\n"
8266 "Pointer to route-map entries\n")
8268 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8269 int idx_ospf_table
= 1;
8275 unsigned short instance
;
8276 struct ospf_redist
*red
;
8278 source
= proto_redistnum(AFI_IP
, argv
[idx_ospf_table
]->text
);
8281 vty_out(vty
, "Unknown instance redistribution\n");
8282 return CMD_WARNING_CONFIG_FAILED
;
8285 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8287 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
8289 "Instance redistribution in non-instanced OSPF not allowed\n");
8290 return CMD_WARNING_CONFIG_FAILED
;
8293 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
8294 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
8295 return CMD_WARNING_CONFIG_FAILED
;
8298 /* Get metric value. */
8299 if (argv_find(argv
, argc
, "metric", &idx
))
8300 if (!str2metric(argv
[idx
+ 1]->arg
, &metric
))
8301 return CMD_WARNING_CONFIG_FAILED
;
8304 /* Get metric type. */
8305 if (argv_find(argv
, argc
, "metric-type", &idx
))
8306 if (!str2metric_type(argv
[idx
+ 1]->arg
, &type
))
8307 return CMD_WARNING_CONFIG_FAILED
;
8309 red
= ospf_redist_add(ospf
, source
, instance
);
8312 if (argv_find(argv
, argc
, "route-map", &idx
))
8313 ospf_routemap_set(red
, argv
[idx
+ 1]->arg
);
8315 ospf_routemap_unset(red
);
8317 return ospf_redistribute_set(ospf
, source
, instance
, type
, metric
);
8320 DEFUN (no_ospf_redistribute_instance_source
,
8321 no_ospf_redistribute_instance_source_cmd
,
8322 "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8325 "Open Shortest Path First\n"
8326 "Non-main Kernel Routing Table\n"
8327 "Instance ID/Table Id\n"
8328 "Metric for redistributed routes\n"
8329 "OSPF default metric\n"
8330 "OSPF exterior metric type for redistributed routes\n"
8331 "Set OSPF External Type 1/2 metrics\n"
8332 "Route map reference\n"
8333 "Pointer to route-map entries\n")
8335 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8336 int idx_ospf_table
= 2;
8338 unsigned int instance
;
8339 struct ospf_redist
*red
;
8342 if (strncmp(argv
[idx_ospf_table
]->arg
, "o", 1) == 0)
8343 source
= ZEBRA_ROUTE_OSPF
;
8345 source
= ZEBRA_ROUTE_TABLE
;
8347 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8349 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
8351 "Instance redistribution in non-instanced OSPF not allowed\n");
8352 return CMD_WARNING_CONFIG_FAILED
;
8355 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
8356 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
8357 return CMD_WARNING_CONFIG_FAILED
;
8360 red
= ospf_redist_lookup(ospf
, source
, instance
);
8364 ospf_routemap_unset(red
);
8365 ospf_redist_del(ospf
, source
, instance
);
8367 return ospf_redistribute_unset(ospf
, source
, instance
);
8370 DEFUN (ospf_distribute_list_out
,
8371 ospf_distribute_list_out_cmd
,
8372 "distribute-list WORD out " FRR_REDIST_STR_OSPFD
,
8373 "Filter networks in routing updates\n"
8374 "Access-list name\n"
8376 FRR_REDIST_HELP_STR_OSPFD
)
8378 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8382 char *proto
= argv
[argc
- 1]->text
;
8384 /* Get distribute source. */
8385 source
= proto_redistnum(AFI_IP
, proto
);
8387 return CMD_WARNING_CONFIG_FAILED
;
8389 return ospf_distribute_list_out_set(ospf
, source
, argv
[idx_word
]->arg
);
8392 DEFUN (no_ospf_distribute_list_out
,
8393 no_ospf_distribute_list_out_cmd
,
8394 "no distribute-list WORD out " FRR_REDIST_STR_OSPFD
,
8396 "Filter networks in routing updates\n"
8397 "Access-list name\n"
8399 FRR_REDIST_HELP_STR_OSPFD
)
8401 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8405 char *proto
= argv
[argc
- 1]->text
;
8406 source
= proto_redistnum(AFI_IP
, proto
);
8408 return CMD_WARNING_CONFIG_FAILED
;
8410 return ospf_distribute_list_out_unset(ospf
, source
,
8411 argv
[idx_word
]->arg
);
8414 /* Default information originate. */
8415 DEFUN (ospf_default_information_originate
,
8416 ospf_default_information_originate_cmd
,
8417 "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8418 "Control distribution of default information\n"
8419 "Distribute a default route\n"
8420 "Always advertise default route\n"
8421 "OSPF default metric\n"
8423 "OSPF metric type for default routes\n"
8424 "Set OSPF External Type 1/2 metrics\n"
8425 "Route map reference\n"
8426 "Pointer to route-map entries\n")
8428 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8429 int default_originate
= DEFAULT_ORIGINATE_ZEBRA
;
8432 struct ospf_redist
*red
;
8434 int cur_originate
= ospf
->default_originate
;
8438 red
= ospf_redist_add(ospf
, DEFAULT_ROUTE
, 0);
8440 /* Check whether "always" was specified */
8441 if (argv_find(argv
, argc
, "always", &idx
))
8442 default_originate
= DEFAULT_ORIGINATE_ALWAYS
;
8444 /* Get metric value */
8445 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
8446 if (!str2metric(argv
[idx
]->arg
, &metric
))
8447 return CMD_WARNING_CONFIG_FAILED
;
8450 /* Get metric type. */
8451 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
8452 if (!str2metric_type(argv
[idx
]->arg
, &type
))
8453 return CMD_WARNING_CONFIG_FAILED
;
8457 if (argv_find(argv
, argc
, "WORD", &idx
))
8458 rtmap
= argv
[idx
]->arg
;
8460 /* To check ,if user is providing same route map */
8461 if ((rtmap
== ROUTEMAP_NAME(red
)) ||
8462 (rtmap
&& ROUTEMAP_NAME(red
)
8463 && (strcmp(rtmap
, ROUTEMAP_NAME(red
)) == 0)))
8466 /* Don't allow if the same lsa is aleardy originated. */
8468 && (red
->dmetric
.type
== type
)
8469 && (red
->dmetric
.value
== metric
)
8470 && (cur_originate
== default_originate
))
8473 /* Updating Metric details */
8474 red
->dmetric
.type
= type
;
8475 red
->dmetric
.value
= metric
;
8477 /* updating route map details */
8479 ospf_routemap_set(red
, rtmap
);
8481 ospf_routemap_unset(red
);
8483 return ospf_redistribute_default_set(ospf
, default_originate
, type
,
8487 DEFUN (no_ospf_default_information_originate
,
8488 no_ospf_default_information_originate_cmd
,
8489 "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8491 "Control distribution of default information\n"
8492 "Distribute a default route\n"
8493 "Always advertise default route\n"
8494 "OSPF default metric\n"
8496 "OSPF metric type for default routes\n"
8497 "Set OSPF External Type 1/2 metrics\n"
8498 "Route map reference\n"
8499 "Pointer to route-map entries\n")
8501 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8502 struct ospf_redist
*red
;
8504 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
8508 ospf_routemap_unset(red
);
8509 ospf_redist_del(ospf
, DEFAULT_ROUTE
, 0);
8511 return ospf_redistribute_default_set(ospf
, DEFAULT_ORIGINATE_NONE
,
8515 DEFUN (ospf_default_metric
,
8516 ospf_default_metric_cmd
,
8517 "default-metric (0-16777214)",
8518 "Set metric of redistributed routes\n"
8521 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8525 if (!str2metric(argv
[idx_number
]->arg
, &metric
))
8526 return CMD_WARNING_CONFIG_FAILED
;
8528 ospf
->default_metric
= metric
;
8533 DEFUN (no_ospf_default_metric
,
8534 no_ospf_default_metric_cmd
,
8535 "no default-metric [(0-16777214)]",
8537 "Set metric of redistributed routes\n"
8540 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8542 ospf
->default_metric
= -1;
8548 DEFUN (ospf_distance
,
8551 "Administrative distance\n"
8552 "OSPF Administrative distance\n")
8554 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8557 ospf
->distance_all
= atoi(argv
[idx_number
]->arg
);
8562 DEFUN (no_ospf_distance
,
8563 no_ospf_distance_cmd
,
8564 "no distance (1-255)",
8566 "Administrative distance\n"
8567 "OSPF Administrative distance\n")
8569 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8571 ospf
->distance_all
= 0;
8576 DEFUN (no_ospf_distance_ospf
,
8577 no_ospf_distance_ospf_cmd
,
8578 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
8580 "Administrative distance\n"
8581 "OSPF administrative distance\n"
8582 "Intra-area routes\n"
8583 "Distance for intra-area routes\n"
8584 "Inter-area routes\n"
8585 "Distance for inter-area routes\n"
8587 "Distance for external routes\n")
8589 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8592 if (argv_find(argv
, argc
, "intra-area", &idx
) || argc
== 3)
8593 idx
= ospf
->distance_intra
= 0;
8594 if (argv_find(argv
, argc
, "inter-area", &idx
) || argc
== 3)
8595 idx
= ospf
->distance_inter
= 0;
8596 if (argv_find(argv
, argc
, "external", &idx
) || argc
== 3)
8597 ospf
->distance_external
= 0;
8602 DEFUN (ospf_distance_ospf
,
8603 ospf_distance_ospf_cmd
,
8604 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
8605 "Administrative distance\n"
8606 "OSPF administrative distance\n"
8607 "Intra-area routes\n"
8608 "Distance for intra-area routes\n"
8609 "Inter-area routes\n"
8610 "Distance for inter-area routes\n"
8612 "Distance for external routes\n")
8614 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8617 ospf
->distance_intra
= 0;
8618 ospf
->distance_inter
= 0;
8619 ospf
->distance_external
= 0;
8621 if (argv_find(argv
, argc
, "intra-area", &idx
))
8622 ospf
->distance_intra
= atoi(argv
[idx
+ 1]->arg
);
8624 if (argv_find(argv
, argc
, "inter-area", &idx
))
8625 ospf
->distance_inter
= atoi(argv
[idx
+ 1]->arg
);
8627 if (argv_find(argv
, argc
, "external", &idx
))
8628 ospf
->distance_external
= atoi(argv
[idx
+ 1]->arg
);
8634 DEFUN (ospf_distance_source
,
8635 ospf_distance_source_cmd
,
8636 "distance (1-255) A.B.C.D/M",
8637 "Administrative distance\n"
8639 "IP source prefix\n")
8641 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8643 int idx_ipv4_prefixlen
= 2;
8645 ospf_distance_set (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
8650 DEFUN (no_ospf_distance_source
,
8651 no_ospf_distance_source_cmd
,
8652 "no distance (1-255) A.B.C.D/M",
8654 "Administrative distance\n"
8656 "IP source prefix\n")
8658 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8660 int idx_ipv4_prefixlen
= 3;
8662 ospf_distance_unset (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
8667 DEFUN (ospf_distance_source_access_list
,
8668 ospf_distance_source_access_list_cmd
,
8669 "distance (1-255) A.B.C.D/M WORD",
8670 "Administrative distance\n"
8672 "IP source prefix\n"
8673 "Access list name\n")
8675 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8677 int idx_ipv4_prefixlen
= 2;
8680 ospf_distance_set (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
8685 DEFUN (no_ospf_distance_source_access_list
,
8686 no_ospf_distance_source_access_list_cmd
,
8687 "no distance (1-255) A.B.C.D/M WORD",
8689 "Administrative distance\n"
8691 "IP source prefix\n"
8692 "Access list name\n")
8694 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8696 int idx_ipv4_prefixlen
= 3;
8699 ospf_distance_unset (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
8705 DEFUN (ip_ospf_mtu_ignore
,
8706 ip_ospf_mtu_ignore_addr_cmd
,
8707 "ip ospf mtu-ignore [A.B.C.D]",
8709 "OSPF interface commands\n"
8710 "Disable MTU mismatch detection on this interface\n"
8711 "Address of interface\n")
8713 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8715 struct in_addr addr
;
8718 struct ospf_if_params
*params
;
8719 params
= IF_DEF_PARAMS(ifp
);
8722 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8725 "Please specify interface address by A.B.C.D\n");
8726 return CMD_WARNING_CONFIG_FAILED
;
8728 params
= ospf_get_if_params(ifp
, addr
);
8729 ospf_if_update_params(ifp
, addr
);
8731 params
->mtu_ignore
= 1;
8732 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
8733 SET_IF_PARAM(params
, mtu_ignore
);
8735 UNSET_IF_PARAM(params
, mtu_ignore
);
8736 if (params
!= IF_DEF_PARAMS(ifp
)) {
8737 ospf_free_if_params(ifp
, addr
);
8738 ospf_if_update_params(ifp
, addr
);
8744 DEFUN (no_ip_ospf_mtu_ignore
,
8745 no_ip_ospf_mtu_ignore_addr_cmd
,
8746 "no ip ospf mtu-ignore [A.B.C.D]",
8749 "OSPF interface commands\n"
8750 "Disable MTU mismatch detection on this interface\n"
8751 "Address of interface\n")
8753 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8755 struct in_addr addr
;
8758 struct ospf_if_params
*params
;
8759 params
= IF_DEF_PARAMS(ifp
);
8762 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8765 "Please specify interface address by A.B.C.D\n");
8766 return CMD_WARNING_CONFIG_FAILED
;
8768 params
= ospf_get_if_params(ifp
, addr
);
8769 ospf_if_update_params(ifp
, addr
);
8771 params
->mtu_ignore
= 0;
8772 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
8773 SET_IF_PARAM(params
, mtu_ignore
);
8775 UNSET_IF_PARAM(params
, mtu_ignore
);
8776 if (params
!= IF_DEF_PARAMS(ifp
)) {
8777 ospf_free_if_params(ifp
, addr
);
8778 ospf_if_update_params(ifp
, addr
);
8785 DEFUN (ospf_max_metric_router_lsa_admin
,
8786 ospf_max_metric_router_lsa_admin_cmd
,
8787 "max-metric router-lsa administrative",
8788 "OSPF maximum / infinite-distance metric\n"
8789 "Advertise own Router-LSA with infinite distance (stub router)\n"
8790 "Administratively applied, for an indefinite period\n")
8792 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8793 struct listnode
*ln
;
8794 struct ospf_area
*area
;
8796 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8797 SET_FLAG(area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
);
8799 if (!CHECK_FLAG(area
->stub_router_state
,
8800 OSPF_AREA_IS_STUB_ROUTED
))
8801 ospf_router_lsa_update_area(area
);
8804 /* Allows for areas configured later to get the property */
8805 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
;
8810 DEFUN (no_ospf_max_metric_router_lsa_admin
,
8811 no_ospf_max_metric_router_lsa_admin_cmd
,
8812 "no max-metric router-lsa administrative",
8814 "OSPF maximum / infinite-distance metric\n"
8815 "Advertise own Router-LSA with infinite distance (stub router)\n"
8816 "Administratively applied, for an indefinite period\n")
8818 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8819 struct listnode
*ln
;
8820 struct ospf_area
*area
;
8822 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8823 UNSET_FLAG(area
->stub_router_state
,
8824 OSPF_AREA_ADMIN_STUB_ROUTED
);
8826 /* Don't trample on the start-up stub timer */
8827 if (CHECK_FLAG(area
->stub_router_state
,
8828 OSPF_AREA_IS_STUB_ROUTED
)
8829 && !area
->t_stub_router
) {
8830 UNSET_FLAG(area
->stub_router_state
,
8831 OSPF_AREA_IS_STUB_ROUTED
);
8832 ospf_router_lsa_update_area(area
);
8835 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET
;
8839 DEFUN (ospf_max_metric_router_lsa_startup
,
8840 ospf_max_metric_router_lsa_startup_cmd
,
8841 "max-metric router-lsa on-startup (5-86400)",
8842 "OSPF maximum / infinite-distance metric\n"
8843 "Advertise own Router-LSA with infinite distance (stub router)\n"
8844 "Automatically advertise stub Router-LSA on startup of OSPF\n"
8845 "Time (seconds) to advertise self as stub-router\n")
8847 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8849 unsigned int seconds
;
8852 vty_out(vty
, "%% Must supply stub-router period");
8853 return CMD_WARNING_CONFIG_FAILED
;
8856 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8858 ospf
->stub_router_startup_time
= seconds
;
8863 DEFUN (no_ospf_max_metric_router_lsa_startup
,
8864 no_ospf_max_metric_router_lsa_startup_cmd
,
8865 "no max-metric router-lsa on-startup [(5-86400)]",
8867 "OSPF maximum / infinite-distance metric\n"
8868 "Advertise own Router-LSA with infinite distance (stub router)\n"
8869 "Automatically advertise stub Router-LSA on startup of OSPF\n"
8870 "Time (seconds) to advertise self as stub-router\n")
8872 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8873 struct listnode
*ln
;
8874 struct ospf_area
*area
;
8876 ospf
->stub_router_startup_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
8878 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8879 SET_FLAG(area
->stub_router_state
,
8880 OSPF_AREA_WAS_START_STUB_ROUTED
);
8881 OSPF_TIMER_OFF(area
->t_stub_router
);
8883 /* Don't trample on admin stub routed */
8884 if (!CHECK_FLAG(area
->stub_router_state
,
8885 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
8886 UNSET_FLAG(area
->stub_router_state
,
8887 OSPF_AREA_IS_STUB_ROUTED
);
8888 ospf_router_lsa_update_area(area
);
8895 DEFUN (ospf_max_metric_router_lsa_shutdown
,
8896 ospf_max_metric_router_lsa_shutdown_cmd
,
8897 "max-metric router-lsa on-shutdown (5-100)",
8898 "OSPF maximum / infinite-distance metric\n"
8899 "Advertise own Router-LSA with infinite distance (stub router)\n"
8900 "Advertise stub-router prior to full shutdown of OSPF\n"
8901 "Time (seconds) to wait till full shutdown\n")
8903 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8905 unsigned int seconds
;
8908 vty_out(vty
, "%% Must supply stub-router shutdown period");
8909 return CMD_WARNING_CONFIG_FAILED
;
8912 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8914 ospf
->stub_router_shutdown_time
= seconds
;
8919 DEFUN (no_ospf_max_metric_router_lsa_shutdown
,
8920 no_ospf_max_metric_router_lsa_shutdown_cmd
,
8921 "no max-metric router-lsa on-shutdown [(5-100)]",
8923 "OSPF maximum / infinite-distance metric\n"
8924 "Advertise own Router-LSA with infinite distance (stub router)\n"
8925 "Advertise stub-router prior to full shutdown of OSPF\n"
8926 "Time (seconds) to wait till full shutdown\n")
8928 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8930 ospf
->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
8935 static void config_write_stub_router(struct vty
*vty
, struct ospf
*ospf
)
8937 struct listnode
*ln
;
8938 struct ospf_area
*area
;
8940 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
8941 vty_out(vty
, " max-metric router-lsa on-startup %u\n",
8942 ospf
->stub_router_startup_time
);
8943 if (ospf
->stub_router_shutdown_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
8944 vty_out(vty
, " max-metric router-lsa on-shutdown %u\n",
8945 ospf
->stub_router_shutdown_time
);
8946 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8947 if (CHECK_FLAG(area
->stub_router_state
,
8948 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
8949 vty_out(vty
, " max-metric router-lsa administrative\n");
8956 static void show_ip_ospf_route_network(struct vty
*vty
, struct ospf
*ospf
,
8957 struct route_table
*rt
,
8960 struct route_node
*rn
;
8961 struct ospf_route
* or ;
8962 struct listnode
*pnode
, *pnnode
;
8963 struct ospf_path
*path
;
8964 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
8965 *json_nexthop
= NULL
;
8969 "============ OSPF network routing table ============\n");
8971 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
8972 if ((or = rn
->info
) == NULL
)
8974 char buf1
[PREFIX2STR_BUFFER
];
8976 memset(buf1
, 0, sizeof(buf1
));
8977 prefix2str(&rn
->p
, buf1
, sizeof(buf1
));
8979 json_route
= json_object_new_object();
8981 json_object_object_add(json
, buf1
, json_route
);
8982 json_object_to_json_string_ext(
8983 json
, JSON_C_TO_STRING_NOSLASHESCAPE
);
8986 switch (or->path_type
) {
8987 case OSPF_PATH_INTER_AREA
:
8988 if (or->type
== OSPF_DESTINATION_NETWORK
) {
8990 json_object_string_add(json_route
,
8993 json_object_int_add(json_route
, "cost",
8995 json_object_string_add(
8997 inet_ntoa(or->u
.std
.area_id
));
9000 "N IA %-18s [%d] area: %s\n",
9002 inet_ntoa(or->u
.std
.area_id
));
9004 } else if (or->type
== OSPF_DESTINATION_DISCARD
) {
9006 json_object_string_add(json_route
,
9011 "D IA %-18s Discard entry\n",
9016 case OSPF_PATH_INTRA_AREA
:
9018 json_object_string_add(json_route
, "routeType",
9020 json_object_int_add(json_route
, "cost",
9022 json_object_string_add(
9024 inet_ntoa(or->u
.std
.area_id
));
9026 vty_out(vty
, "N %-18s [%d] area: %s\n",
9028 inet_ntoa(or->u
.std
.area_id
));
9035 if (or->type
== OSPF_DESTINATION_NETWORK
) {
9037 json_nexthop_array
= json_object_new_array();
9038 json_object_object_add(json_route
, "nexthops",
9039 json_nexthop_array
);
9042 for (ALL_LIST_ELEMENTS(or->paths
, pnode
, pnnode
,
9045 json_nexthop
= json_object_new_object();
9046 json_object_array_add(
9050 if (if_lookup_by_index(path
->ifindex
,
9053 if (path
->nexthop
.s_addr
== 0) {
9055 json_object_string_add(
9058 json_object_string_add(
9060 "directly attached to",
9066 "%24s directly attached to %s\n",
9074 json_object_string_add(
9079 json_object_string_add(
9087 "%24s via %s, %s\n",
9100 json_object_free(json_route
);
9106 static void show_ip_ospf_route_router(struct vty
*vty
, struct ospf
*ospf
,
9107 struct route_table
*rtrs
,
9110 struct route_node
*rn
;
9111 struct ospf_route
* or ;
9112 struct listnode
*pnode
;
9113 struct listnode
*node
;
9114 struct ospf_path
*path
;
9115 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
9116 *json_nexthop
= NULL
;
9120 "============ OSPF router routing table =============\n");
9122 for (rn
= route_top(rtrs
); rn
; rn
= route_next(rn
)) {
9123 if (rn
->info
== NULL
)
9127 json_route
= json_object_new_object();
9129 json_object_object_add(json
, inet_ntoa(rn
->p
.u
.prefix4
),
9131 json_object_string_add(json_route
, "routeType", "R ");
9133 vty_out(vty
, "R %-15s ",
9134 inet_ntoa(rn
->p
.u
.prefix4
));
9137 for (ALL_LIST_ELEMENTS_RO((struct list
*)rn
->info
, node
, or)) {
9140 vty_out(vty
, "%24s", "");
9145 json_object_int_add(json_route
, "cost",
9147 json_object_string_add(
9149 inet_ntoa(or->u
.std
.area_id
));
9150 if (or->path_type
== OSPF_PATH_INTER_AREA
)
9151 json_object_boolean_true_add(json_route
,
9153 if (or->u
.std
.flags
& ROUTER_LSA_BORDER
)
9154 json_object_string_add(json_route
,
9157 else if (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
)
9158 json_object_string_add(json_route
,
9162 vty_out(vty
, "%s [%d] area: %s",
9163 (or->path_type
== OSPF_PATH_INTER_AREA
9166 or->cost
, inet_ntoa(or->u
.std
.area_id
));
9168 vty_out(vty
, "%s%s\n",
9169 (or->u
.std
.flags
& ROUTER_LSA_BORDER
9172 (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
9178 json_nexthop_array
= json_object_new_array();
9179 json_object_object_add(json_route
, "nexthops",
9180 json_nexthop_array
);
9183 for (ALL_LIST_ELEMENTS_RO(or->paths
, pnode
, path
)) {
9185 json_nexthop
= json_object_new_object();
9186 json_object_array_add(
9190 if (if_lookup_by_index(path
->ifindex
,
9192 if (path
->nexthop
.s_addr
== 0) {
9194 json_object_string_add(
9197 json_object_string_add(
9199 "directly attached to",
9205 "%24s directly attached to %s\n",
9213 json_object_string_add(
9218 json_object_string_add(
9226 "%24s via %s, %s\n",
9239 json_object_free(json_route
);
9245 static void show_ip_ospf_route_external(struct vty
*vty
, struct ospf
*ospf
,
9246 struct route_table
*rt
,
9249 struct route_node
*rn
;
9250 struct ospf_route
*er
;
9251 struct listnode
*pnode
, *pnnode
;
9252 struct ospf_path
*path
;
9253 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
9254 *json_nexthop
= NULL
;
9258 "============ OSPF external routing table ===========\n");
9260 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
9261 if ((er
= rn
->info
) == NULL
)
9266 snprintf(buf1
, 19, "%s/%d", inet_ntoa(rn
->p
.u
.prefix4
),
9268 json_route
= json_object_new_object();
9270 json_object_object_add(json
, buf1
, json_route
);
9271 json_object_to_json_string_ext(
9272 json
, JSON_C_TO_STRING_NOSLASHESCAPE
);
9275 switch (er
->path_type
) {
9276 case OSPF_PATH_TYPE1_EXTERNAL
:
9278 json_object_string_add(json_route
, "routeType",
9280 json_object_int_add(json_route
, "cost",
9284 "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI
9286 buf1
, er
->cost
, er
->u
.ext
.tag
);
9289 case OSPF_PATH_TYPE2_EXTERNAL
:
9291 json_object_string_add(json_route
, "routeType",
9293 json_object_int_add(json_route
, "cost",
9297 "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI
9299 buf1
, er
->cost
, er
->u
.ext
.type2_cost
,
9306 json_nexthop_array
= json_object_new_array();
9307 json_object_object_add(json_route
, "nexthops",
9308 json_nexthop_array
);
9311 for (ALL_LIST_ELEMENTS(er
->paths
, pnode
, pnnode
, path
)) {
9313 json_nexthop
= json_object_new_object();
9314 json_object_array_add(json_nexthop_array
,
9318 if (if_lookup_by_index(path
->ifindex
, ospf
->vrf_id
)) {
9319 if (path
->nexthop
.s_addr
== 0) {
9321 json_object_string_add(
9324 json_object_string_add(
9326 "directly attached to",
9332 "%24s directly attached to %s\n",
9340 json_object_string_add(
9344 json_object_string_add(
9345 json_nexthop
, "via",
9351 "%24s via %s, %s\n",
9363 json_object_free(json_route
);
9369 static int show_ip_ospf_border_routers_common(struct vty
*vty
,
9374 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
9376 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
9378 if (ospf
->new_table
== NULL
) {
9379 vty_out(vty
, "No OSPF routing information exist\n");
9383 /* Show Network routes.
9384 show_ip_ospf_route_network (vty, ospf->new_table); */
9386 /* Show Router routes. */
9387 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, NULL
);
9394 DEFUN (show_ip_ospf_border_routers
,
9395 show_ip_ospf_border_routers_cmd
,
9396 "show ip ospf [vrf <NAME|all>] border-routers",
9399 "OSPF information\n"
9402 "Show all the ABR's and ASBR's\n")
9404 struct ospf
*ospf
= NULL
;
9405 struct listnode
*node
= NULL
;
9406 char *vrf_name
= NULL
;
9407 bool all_vrf
= false;
9408 int ret
= CMD_SUCCESS
;
9411 uint8_t use_vrf
= 0;
9413 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
9416 bool ospf_output
= false;
9421 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9422 if (!ospf
->oi_running
)
9426 ret
= show_ip_ospf_border_routers_common(
9427 vty
, ospf
, use_vrf
);
9431 vty_out(vty
, "%% OSPF instance not found\n");
9433 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
9434 if (ospf
== NULL
|| !ospf
->oi_running
) {
9435 vty_out(vty
, "%% OSPF instance not found\n");
9439 ret
= show_ip_ospf_border_routers_common(vty
, ospf
,
9443 /* Display default ospf (instance 0) info */
9444 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
9445 if (ospf
== NULL
|| !ospf
->oi_running
) {
9446 vty_out(vty
, "%% OSPF instance not found\n");
9450 ret
= show_ip_ospf_border_routers_common(vty
, ospf
, use_vrf
);
9456 DEFUN (show_ip_ospf_instance_border_routers
,
9457 show_ip_ospf_instance_border_routers_cmd
,
9458 "show ip ospf (1-65535) border-routers",
9461 "OSPF information\n"
9463 "Show all the ABR's and ASBR's\n")
9467 unsigned short instance
= 0;
9469 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9470 ospf
= ospf_lookup_instance(instance
);
9472 return CMD_NOT_MY_INSTANCE
;
9474 if (!ospf
->oi_running
)
9477 return show_ip_ospf_border_routers_common(vty
, ospf
, 0);
9480 static int show_ip_ospf_route_common(struct vty
*vty
, struct ospf
*ospf
,
9481 json_object
*json
, uint8_t use_vrf
)
9483 json_object
*json_vrf
= NULL
;
9486 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
9491 json_vrf
= json_object_new_object();
9496 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
9498 if (ospf
->new_table
== NULL
) {
9499 vty_out(vty
, "No OSPF routing information exist\n");
9503 /* Show Network routes. */
9504 show_ip_ospf_route_network(vty
, ospf
, ospf
->new_table
, json_vrf
);
9506 /* Show Router routes. */
9507 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, json_vrf
);
9509 /* Show AS External routes. */
9510 show_ip_ospf_route_external(vty
, ospf
, ospf
->old_external_route
,
9515 // json_object_object_add(json_vrf, "areas",
9517 if (ospf
->vrf_id
== VRF_DEFAULT
)
9518 json_object_object_add(json
, "default",
9521 json_object_object_add(json
, ospf
->name
,
9531 DEFUN (show_ip_ospf_route
,
9532 show_ip_ospf_route_cmd
,
9533 "show ip ospf [vrf <NAME|all>] route [json]",
9536 "OSPF information\n"
9539 "OSPF routing table\n"
9542 struct ospf
*ospf
= NULL
;
9543 struct listnode
*node
= NULL
;
9544 char *vrf_name
= NULL
;
9545 bool all_vrf
= false;
9546 int ret
= CMD_SUCCESS
;
9549 uint8_t use_vrf
= 0;
9550 bool uj
= use_json(argc
, argv
);
9551 json_object
*json
= NULL
;
9554 json
= json_object_new_object();
9556 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
9558 /* vrf input is provided could be all or specific vrf*/
9560 bool ospf_output
= false;
9565 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9566 if (!ospf
->oi_running
)
9569 ret
= show_ip_ospf_route_common(vty
, ospf
, json
,
9574 /* Keep Non-pretty format */
9575 vty_out(vty
, "%s\n",
9576 json_object_to_json_string(json
));
9577 json_object_free(json
);
9578 } else if (!ospf_output
)
9579 vty_out(vty
, "%% OSPF instance not found\n");
9583 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
9584 if (ospf
== NULL
|| !ospf
->oi_running
) {
9586 vty_out(vty
, "%s\n",
9587 json_object_to_json_string_ext(
9588 json
, JSON_C_TO_STRING_PRETTY
));
9589 json_object_free(json
);
9591 vty_out(vty
, "%% OSPF instance not found\n");
9596 /* Display default ospf (instance 0) info */
9597 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
9598 if (ospf
== NULL
|| !ospf
->oi_running
) {
9600 vty_out(vty
, "%s\n",
9601 json_object_to_json_string_ext(
9602 json
, JSON_C_TO_STRING_PRETTY
));
9603 json_object_free(json
);
9605 vty_out(vty
, "%% OSPF instance not found\n");
9612 ret
= show_ip_ospf_route_common(vty
, ospf
, json
, use_vrf
);
9613 /* Keep Non-pretty format */
9615 vty_out(vty
, "%s\n", json_object_to_json_string(json
));
9619 json_object_free(json
);
9624 DEFUN (show_ip_ospf_instance_route
,
9625 show_ip_ospf_instance_route_cmd
,
9626 "show ip ospf (1-65535) route",
9629 "OSPF information\n"
9631 "OSPF routing table\n")
9635 unsigned short instance
= 0;
9637 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9638 ospf
= ospf_lookup_instance(instance
);
9640 return CMD_NOT_MY_INSTANCE
;
9642 if (!ospf
->oi_running
)
9645 return show_ip_ospf_route_common(vty
, ospf
, NULL
, 0);
9649 DEFUN (show_ip_ospf_vrfs
,
9650 show_ip_ospf_vrfs_cmd
,
9651 "show ip ospf vrfs [json]",
9654 "OSPF information\n"
9658 bool uj
= use_json(argc
, argv
);
9659 json_object
*json
= NULL
;
9660 json_object
*json_vrfs
= NULL
;
9661 struct ospf
*ospf
= NULL
;
9662 struct listnode
*node
= NULL
;
9664 static const char header
[] = "Name Id RouterId ";
9667 json
= json_object_new_object();
9668 json_vrfs
= json_object_new_object();
9671 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9672 json_object
*json_vrf
= NULL
;
9673 const char *name
= NULL
;
9674 int64_t vrf_id_ui
= 0;
9678 if (!uj
&& count
== 1)
9679 vty_out(vty
, "%s\n", header
);
9681 json_vrf
= json_object_new_object();
9683 if (ospf
->vrf_id
== VRF_DEFAULT
)
9684 name
= VRF_DEFAULT_NAME
;
9688 vrf_id_ui
= (ospf
->vrf_id
== VRF_UNKNOWN
)
9690 : (int64_t)ospf
->vrf_id
;
9693 json_object_int_add(json_vrf
, "vrfId", vrf_id_ui
);
9694 json_object_string_add(json_vrf
, "routerId",
9695 inet_ntoa(ospf
->router_id
));
9697 json_object_object_add(json_vrfs
, name
, json_vrf
);
9700 vty_out(vty
, "%-25s %-5d %-16s \n", name
,
9701 ospf
->vrf_id
, inet_ntoa(ospf
->router_id
));
9706 json_object_object_add(json
, "vrfs", json_vrfs
);
9707 json_object_int_add(json
, "totalVrfs", count
);
9709 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
9710 json
, JSON_C_TO_STRING_PRETTY
));
9711 json_object_free(json
);
9714 vty_out(vty
, "\nTotal number of OSPF VRFs: %d\n",
9721 static const char *const ospf_abr_type_str
[] = {
9722 "unknown", "standard", "ibm", "cisco", "shortcut"
9725 static const char *const ospf_shortcut_mode_str
[] = {
9726 "default", "enable", "disable"
9729 static const char *const ospf_int_type_str
[] = {
9730 "unknown", /* should never be used. */
9734 "point-to-multipoint",
9735 "virtual-link", /* should never be used. */
9739 static int config_write_interface_one(struct vty
*vty
, struct vrf
*vrf
)
9741 struct listnode
*node
;
9742 struct interface
*ifp
;
9743 struct crypt_key
*ck
;
9744 struct route_node
*rn
= NULL
;
9745 struct ospf_if_params
*params
;
9747 struct ospf
*ospf
= vrf
->info
;
9749 FOR_ALL_INTERFACES (vrf
, ifp
) {
9751 if (memcmp(ifp
->name
, "VLINK", 5) == 0)
9754 vty_frame(vty
, "!\n");
9755 if (ifp
->vrf_id
== VRF_DEFAULT
)
9756 vty_frame(vty
, "interface %s\n", ifp
->name
);
9758 vty_frame(vty
, "interface %s vrf %s\n", ifp
->name
,
9761 vty_out(vty
, " description %s\n", ifp
->desc
);
9765 params
= IF_DEF_PARAMS(ifp
);
9768 /* Interface Network print. */
9769 if (OSPF_IF_PARAM_CONFIGURED(params
, type
)
9770 && params
->type
!= OSPF_IFTYPE_LOOPBACK
) {
9771 if (params
->type
!= ospf_default_iftype(ifp
)) {
9772 vty_out(vty
, " ip ospf network %s",
9775 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9783 /* OSPF interface authentication print */
9784 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_type
)
9785 && params
->auth_type
!= OSPF_AUTH_NOTSET
) {
9786 const char *auth_str
;
9788 /* Translation tables are not that much help
9789 * here due to syntax
9790 * of the simple option */
9791 switch (params
->auth_type
) {
9793 case OSPF_AUTH_NULL
:
9797 case OSPF_AUTH_SIMPLE
:
9801 case OSPF_AUTH_CRYPTOGRAPHIC
:
9802 auth_str
= " message-digest";
9810 vty_out(vty
, " ip ospf authentication%s",
9812 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9814 inet_ntoa(rn
->p
.u
.prefix4
));
9818 /* Simple Authentication Password print. */
9819 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_simple
)
9820 && params
->auth_simple
[0] != '\0') {
9821 vty_out(vty
, " ip ospf authentication-key %s",
9822 params
->auth_simple
);
9823 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9825 inet_ntoa(rn
->p
.u
.prefix4
));
9829 /* Cryptographic Authentication Key print. */
9830 if (params
&& params
->auth_crypt
) {
9831 for (ALL_LIST_ELEMENTS_RO(params
->auth_crypt
,
9834 " ip ospf message-digest-key %d md5 %s",
9835 ck
->key_id
, ck
->auth_key
);
9836 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9844 /* Interface Output Cost print. */
9845 if (OSPF_IF_PARAM_CONFIGURED(params
, output_cost_cmd
)) {
9846 vty_out(vty
, " ip ospf cost %u",
9847 params
->output_cost_cmd
);
9848 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9850 inet_ntoa(rn
->p
.u
.prefix4
));
9854 /* Hello Interval print. */
9855 if (OSPF_IF_PARAM_CONFIGURED(params
, v_hello
)
9856 && params
->v_hello
!= OSPF_HELLO_INTERVAL_DEFAULT
) {
9857 vty_out(vty
, " ip ospf hello-interval %u",
9859 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9861 inet_ntoa(rn
->p
.u
.prefix4
));
9866 /* Router Dead Interval print. */
9867 if (OSPF_IF_PARAM_CONFIGURED(params
, v_wait
)
9869 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
) {
9870 vty_out(vty
, " ip ospf dead-interval ");
9873 if (OSPF_IF_PARAM_CONFIGURED(params
,
9876 "minimal hello-multiplier %d",
9877 params
->fast_hello
);
9879 vty_out(vty
, "%u", params
->v_wait
);
9881 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9883 inet_ntoa(rn
->p
.u
.prefix4
));
9887 /* Router Priority print. */
9888 if (OSPF_IF_PARAM_CONFIGURED(params
, priority
)
9890 != OSPF_ROUTER_PRIORITY_DEFAULT
) {
9891 vty_out(vty
, " ip ospf priority %u",
9893 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9895 inet_ntoa(rn
->p
.u
.prefix4
));
9899 /* Retransmit Interval print. */
9900 if (OSPF_IF_PARAM_CONFIGURED(params
,
9901 retransmit_interval
)
9902 && params
->retransmit_interval
9903 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
) {
9904 vty_out(vty
, " ip ospf retransmit-interval %u",
9905 params
->retransmit_interval
);
9906 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9908 inet_ntoa(rn
->p
.u
.prefix4
));
9912 /* Transmit Delay print. */
9913 if (OSPF_IF_PARAM_CONFIGURED(params
, transmit_delay
)
9914 && params
->transmit_delay
9915 != OSPF_TRANSMIT_DELAY_DEFAULT
) {
9916 vty_out(vty
, " ip ospf transmit-delay %u",
9917 params
->transmit_delay
);
9918 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9920 inet_ntoa(rn
->p
.u
.prefix4
));
9925 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
9926 if (ospf
&& ospf
->instance
)
9927 vty_out(vty
, " ip ospf %d",
9930 vty_out(vty
, " ip ospf");
9932 char buf
[INET_ADDRSTRLEN
];
9934 area_id2str(buf
, sizeof(buf
), ¶ms
->if_area
,
9935 params
->if_area_id_fmt
);
9936 vty_out(vty
, " area %s", buf
);
9937 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9939 inet_ntoa(rn
->p
.u
.prefix4
));
9944 if (params
&& params
->bfd_info
)
9945 ospf_bfd_write_config(vty
, params
);
9947 /* MTU ignore print. */
9948 if (OSPF_IF_PARAM_CONFIGURED(params
, mtu_ignore
)
9949 && params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
) {
9950 if (params
->mtu_ignore
== 0)
9951 vty_out(vty
, " no ip ospf mtu-ignore");
9953 vty_out(vty
, " ip ospf mtu-ignore");
9954 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9956 inet_ntoa(rn
->p
.u
.prefix4
));
9963 rn
= route_top(IF_OIFS_PARAMS(ifp
));
9965 rn
= route_next(rn
);
9975 ospf_opaque_config_write_if(vty
, ifp
);
9977 vty_endframe(vty
, NULL
);
9983 /* Configuration write function for ospfd. */
9984 static int config_write_interface(struct vty
*vty
)
9987 struct vrf
*vrf
= NULL
;
9989 /* Display all VRF aware OSPF interface configuration */
9990 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
9991 write
+= config_write_interface_one(vty
, vrf
);
9997 static int config_write_network_area(struct vty
*vty
, struct ospf
*ospf
)
9999 struct route_node
*rn
;
10000 uint8_t buf
[INET_ADDRSTRLEN
];
10002 /* `network area' print. */
10003 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
))
10005 struct ospf_network
*n
= rn
->info
;
10007 /* Create Area ID string by specified Area ID format. */
10008 if (n
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
10009 inet_ntop(AF_INET
, &n
->area_id
, (char *)buf
,
10012 sprintf((char *)buf
, "%lu",
10013 (unsigned long int)ntohl(
10014 n
->area_id
.s_addr
));
10016 /* Network print. */
10017 vty_out(vty
, " network %s/%d area %s\n",
10018 inet_ntoa(rn
->p
.u
.prefix4
), rn
->p
.prefixlen
,
10025 static int config_write_ospf_area(struct vty
*vty
, struct ospf
*ospf
)
10027 struct listnode
*node
;
10028 struct ospf_area
*area
;
10029 uint8_t buf
[INET_ADDRSTRLEN
];
10031 /* Area configuration print. */
10032 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
10033 struct route_node
*rn1
;
10035 area_id2str((char *)buf
, sizeof(buf
), &area
->area_id
,
10036 area
->area_id_fmt
);
10038 if (area
->auth_type
!= OSPF_AUTH_NULL
) {
10039 if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
10040 vty_out(vty
, " area %s authentication\n", buf
);
10043 " area %s authentication message-digest\n",
10047 if (area
->shortcut_configured
!= OSPF_SHORTCUT_DEFAULT
)
10048 vty_out(vty
, " area %s shortcut %s\n", buf
,
10049 ospf_shortcut_mode_str
10050 [area
->shortcut_configured
]);
10052 if ((area
->external_routing
== OSPF_AREA_STUB
)
10053 || (area
->external_routing
== OSPF_AREA_NSSA
)) {
10054 if (area
->external_routing
== OSPF_AREA_STUB
) {
10055 vty_out(vty
, " area %s stub", buf
);
10056 if (area
->no_summary
)
10057 vty_out(vty
, " no-summary\n");
10058 vty_out(vty
, "\n");
10059 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
10060 switch (area
->NSSATranslatorRole
) {
10061 case OSPF_NSSA_ROLE_NEVER
:
10063 " area %s nssa translate-never\n",
10066 case OSPF_NSSA_ROLE_ALWAYS
:
10068 " area %s nssa translate-always\n",
10071 case OSPF_NSSA_ROLE_CANDIDATE
:
10072 vty_out(vty
, " area %s nssa \n", buf
);
10075 if (area
->no_summary
)
10077 " area %s nssa no-summary\n",
10081 if (area
->default_cost
!= 1)
10082 vty_out(vty
, " area %s default-cost %d\n", buf
,
10083 area
->default_cost
);
10086 for (rn1
= route_top(area
->ranges
); rn1
; rn1
= route_next(rn1
))
10088 struct ospf_area_range
*range
= rn1
->info
;
10090 vty_out(vty
, " area %s range %s/%d", buf
,
10091 inet_ntoa(rn1
->p
.u
.prefix4
),
10094 if (range
->cost_config
10095 != OSPF_AREA_RANGE_COST_UNSPEC
)
10096 vty_out(vty
, " cost %d",
10097 range
->cost_config
);
10099 if (!CHECK_FLAG(range
->flags
,
10100 OSPF_AREA_RANGE_ADVERTISE
))
10101 vty_out(vty
, " not-advertise");
10103 if (CHECK_FLAG(range
->flags
,
10104 OSPF_AREA_RANGE_SUBSTITUTE
))
10105 vty_out(vty
, " substitute %s/%d",
10106 inet_ntoa(range
->subst_addr
),
10107 range
->subst_masklen
);
10109 vty_out(vty
, "\n");
10112 if (EXPORT_NAME(area
))
10113 vty_out(vty
, " area %s export-list %s\n", buf
,
10114 EXPORT_NAME(area
));
10116 if (IMPORT_NAME(area
))
10117 vty_out(vty
, " area %s import-list %s\n", buf
,
10118 IMPORT_NAME(area
));
10120 if (PREFIX_NAME_IN(area
))
10121 vty_out(vty
, " area %s filter-list prefix %s in\n", buf
,
10122 PREFIX_NAME_IN(area
));
10124 if (PREFIX_NAME_OUT(area
))
10125 vty_out(vty
, " area %s filter-list prefix %s out\n",
10126 buf
, PREFIX_NAME_OUT(area
));
10132 static int config_write_ospf_nbr_nbma(struct vty
*vty
, struct ospf
*ospf
)
10134 struct ospf_nbr_nbma
*nbr_nbma
;
10135 struct route_node
*rn
;
10137 /* Static Neighbor configuration print. */
10138 for (rn
= route_top(ospf
->nbr_nbma
); rn
; rn
= route_next(rn
))
10139 if ((nbr_nbma
= rn
->info
)) {
10140 vty_out(vty
, " neighbor %s", inet_ntoa(nbr_nbma
->addr
));
10142 if (nbr_nbma
->priority
10143 != OSPF_NEIGHBOR_PRIORITY_DEFAULT
)
10144 vty_out(vty
, " priority %d",
10145 nbr_nbma
->priority
);
10147 if (nbr_nbma
->v_poll
!= OSPF_POLL_INTERVAL_DEFAULT
)
10148 vty_out(vty
, " poll-interval %d",
10151 vty_out(vty
, "\n");
10157 static int config_write_virtual_link(struct vty
*vty
, struct ospf
*ospf
)
10159 struct listnode
*node
;
10160 struct ospf_vl_data
*vl_data
;
10161 char buf
[INET_ADDRSTRLEN
];
10163 /* Virtual-Link print */
10164 for (ALL_LIST_ELEMENTS_RO(ospf
->vlinks
, node
, vl_data
)) {
10165 struct listnode
*n2
;
10166 struct crypt_key
*ck
;
10167 struct ospf_interface
*oi
;
10169 if (vl_data
!= NULL
) {
10170 area_id2str(buf
, sizeof(buf
), &vl_data
->vl_area_id
,
10171 vl_data
->vl_area_id_fmt
);
10172 oi
= vl_data
->vl_oi
;
10175 if (OSPF_IF_PARAM(oi
, v_hello
)
10176 != OSPF_HELLO_INTERVAL_DEFAULT
10177 || OSPF_IF_PARAM(oi
, v_wait
)
10178 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
10179 || OSPF_IF_PARAM(oi
, retransmit_interval
)
10180 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
10181 || OSPF_IF_PARAM(oi
, transmit_delay
)
10182 != OSPF_TRANSMIT_DELAY_DEFAULT
)
10184 " area %s virtual-link %s hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n",
10185 buf
, inet_ntoa(vl_data
->vl_peer
),
10186 OSPF_IF_PARAM(oi
, v_hello
),
10187 OSPF_IF_PARAM(oi
, retransmit_interval
),
10188 OSPF_IF_PARAM(oi
, transmit_delay
),
10189 OSPF_IF_PARAM(oi
, v_wait
));
10191 vty_out(vty
, " area %s virtual-link %s\n", buf
,
10192 inet_ntoa(vl_data
->vl_peer
));
10194 if (IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)->auth_simple
[0]
10197 " area %s virtual-link %s authentication-key %s\n",
10198 buf
, inet_ntoa(vl_data
->vl_peer
),
10199 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
10202 for (ALL_LIST_ELEMENTS_RO(
10203 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
10207 " area %s virtual-link %s"
10208 " message-digest-key %d md5 %s\n",
10209 buf
, inet_ntoa(vl_data
->vl_peer
),
10210 ck
->key_id
, ck
->auth_key
);
10218 static int config_write_ospf_redistribute(struct vty
*vty
, struct ospf
*ospf
)
10222 /* redistribute print. */
10223 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
10224 struct list
*red_list
;
10225 struct listnode
*node
;
10226 struct ospf_redist
*red
;
10228 red_list
= ospf
->redist
[type
];
10232 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
10233 vty_out(vty
, " redistribute %s",
10234 zebra_route_string(type
));
10236 vty_out(vty
, " %d", red
->instance
);
10238 if (red
->dmetric
.value
>= 0)
10239 vty_out(vty
, " metric %d", red
->dmetric
.value
);
10241 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
10242 vty_out(vty
, " metric-type 1");
10244 if (ROUTEMAP_NAME(red
))
10245 vty_out(vty
, " route-map %s",
10246 ROUTEMAP_NAME(red
));
10248 vty_out(vty
, "\n");
10255 static int config_write_ospf_default_metric(struct vty
*vty
, struct ospf
*ospf
)
10257 if (ospf
->default_metric
!= -1)
10258 vty_out(vty
, " default-metric %d\n", ospf
->default_metric
);
10262 static int config_write_ospf_distribute(struct vty
*vty
, struct ospf
*ospf
)
10265 struct ospf_redist
*red
;
10268 /* distribute-list print. */
10269 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
10270 if (DISTRIBUTE_NAME(ospf
, type
))
10271 vty_out(vty
, " distribute-list %s out %s\n",
10272 DISTRIBUTE_NAME(ospf
, type
),
10273 zebra_route_string(type
));
10275 /* default-information print. */
10276 if (ospf
->default_originate
!= DEFAULT_ORIGINATE_NONE
) {
10277 vty_out(vty
, " default-information originate");
10278 if (ospf
->default_originate
== DEFAULT_ORIGINATE_ALWAYS
)
10279 vty_out(vty
, " always");
10281 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
10283 if (red
->dmetric
.value
>= 0)
10284 vty_out(vty
, " metric %d",
10285 red
->dmetric
.value
);
10287 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
10288 vty_out(vty
, " metric-type 1");
10290 if (ROUTEMAP_NAME(red
))
10291 vty_out(vty
, " route-map %s",
10292 ROUTEMAP_NAME(red
));
10295 vty_out(vty
, "\n");
10302 static int config_write_ospf_distance(struct vty
*vty
, struct ospf
*ospf
)
10304 struct route_node
*rn
;
10305 struct ospf_distance
*odistance
;
10307 if (ospf
->distance_all
)
10308 vty_out(vty
, " distance %d\n", ospf
->distance_all
);
10310 if (ospf
->distance_intra
|| ospf
->distance_inter
10311 || ospf
->distance_external
) {
10312 vty_out(vty
, " distance ospf");
10314 if (ospf
->distance_intra
)
10315 vty_out(vty
, " intra-area %d", ospf
->distance_intra
);
10316 if (ospf
->distance_inter
)
10317 vty_out(vty
, " inter-area %d", ospf
->distance_inter
);
10318 if (ospf
->distance_external
)
10319 vty_out(vty
, " external %d", ospf
->distance_external
);
10321 vty_out(vty
, "\n");
10324 for (rn
= route_top(ospf
->distance_table
); rn
; rn
= route_next(rn
))
10325 if ((odistance
= rn
->info
) != NULL
) {
10326 vty_out(vty
, " distance %d %s/%d %s\n",
10327 odistance
->distance
, inet_ntoa(rn
->p
.u
.prefix4
),
10329 odistance
->access_list
? odistance
->access_list
10335 static int ospf_config_write_one(struct vty
*vty
, struct ospf
*ospf
)
10337 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
10338 struct interface
*ifp
;
10339 struct ospf_interface
*oi
;
10340 struct listnode
*node
= NULL
;
10343 /* `router ospf' print. */
10344 if (ospf
->instance
&& ospf
->name
) {
10345 vty_out(vty
, "router ospf %d vrf %s\n", ospf
->instance
,
10347 } else if (ospf
->instance
) {
10348 vty_out(vty
, "router ospf %d\n", ospf
->instance
);
10349 } else if (ospf
->name
) {
10350 vty_out(vty
, "router ospf vrf %s\n", ospf
->name
);
10352 vty_out(vty
, "router ospf\n");
10354 if (!ospf
->networks
) {
10359 /* Router ID print. */
10360 if (ospf
->router_id_static
.s_addr
!= 0)
10361 vty_out(vty
, " ospf router-id %s\n",
10362 inet_ntoa(ospf
->router_id_static
));
10364 /* ABR type print. */
10365 if (ospf
->abr_type
!= OSPF_ABR_DEFAULT
)
10366 vty_out(vty
, " ospf abr-type %s\n",
10367 ospf_abr_type_str
[ospf
->abr_type
]);
10369 /* log-adjacency-changes flag print. */
10370 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
10371 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
))
10372 vty_out(vty
, " log-adjacency-changes detail\n");
10373 else if (!SAVE_OSPF_LOG_ADJACENCY_CHANGES
)
10374 vty_out(vty
, " log-adjacency-changes\n");
10375 } else if (SAVE_OSPF_LOG_ADJACENCY_CHANGES
) {
10376 vty_out(vty
, " no log-adjacency-changes\n");
10379 /* RFC1583 compatibility flag print -- Compatible with CISCO
10381 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
))
10382 vty_out(vty
, " compatible rfc1583\n");
10384 /* auto-cost reference-bandwidth configuration. */
10385 if (ospf
->ref_bandwidth
!= OSPF_DEFAULT_REF_BANDWIDTH
) {
10387 "! Important: ensure reference bandwidth "
10388 "is consistent across all routers\n");
10389 vty_out(vty
, " auto-cost reference-bandwidth %d\n",
10390 ospf
->ref_bandwidth
);
10393 /* SPF timers print. */
10394 if (ospf
->spf_delay
!= OSPF_SPF_DELAY_DEFAULT
10395 || ospf
->spf_holdtime
!= OSPF_SPF_HOLDTIME_DEFAULT
10396 || ospf
->spf_max_holdtime
!= OSPF_SPF_MAX_HOLDTIME_DEFAULT
)
10397 vty_out(vty
, " timers throttle spf %d %d %d\n", ospf
->spf_delay
,
10398 ospf
->spf_holdtime
, ospf
->spf_max_holdtime
);
10400 /* LSA timers print. */
10401 if (ospf
->min_ls_interval
!= OSPF_MIN_LS_INTERVAL
)
10402 vty_out(vty
, " timers throttle lsa all %d\n",
10403 ospf
->min_ls_interval
);
10404 if (ospf
->min_ls_arrival
!= OSPF_MIN_LS_ARRIVAL
)
10405 vty_out(vty
, " timers lsa min-arrival %d\n",
10406 ospf
->min_ls_arrival
);
10408 /* Write multiplier print. */
10409 if (ospf
->write_oi_count
!= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
)
10410 vty_out(vty
, " ospf write-multiplier %d\n",
10411 ospf
->write_oi_count
);
10413 /* Max-metric router-lsa print */
10414 config_write_stub_router(vty
, ospf
);
10416 /* SPF refresh parameters print. */
10417 if (ospf
->lsa_refresh_interval
!= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
10418 vty_out(vty
, " refresh timer %d\n", ospf
->lsa_refresh_interval
);
10420 /* Redistribute information print. */
10421 config_write_ospf_redistribute(vty
, ospf
);
10423 /* passive-interface print. */
10424 if (ospf
->passive_interface_default
== OSPF_IF_PASSIVE
)
10425 vty_out(vty
, " passive-interface default\n");
10427 FOR_ALL_INTERFACES (vrf
, ifp
)
10428 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp
),
10430 && IF_DEF_PARAMS(ifp
)->passive_interface
10431 != ospf
->passive_interface_default
) {
10432 vty_out(vty
, " %spassive-interface %s\n",
10433 IF_DEF_PARAMS(ifp
)->passive_interface
? ""
10437 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
10438 if (!OSPF_IF_PARAM_CONFIGURED(oi
->params
, passive_interface
))
10440 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(oi
->ifp
),
10441 passive_interface
)) {
10442 if (oi
->params
->passive_interface
10443 == IF_DEF_PARAMS(oi
->ifp
)->passive_interface
)
10445 } else if (oi
->params
->passive_interface
10446 == ospf
->passive_interface_default
)
10449 vty_out(vty
, " %spassive-interface %s %s\n",
10450 oi
->params
->passive_interface
? "" : "no ",
10451 oi
->ifp
->name
, inet_ntoa(oi
->address
->u
.prefix4
));
10454 /* Network area print. */
10455 config_write_network_area(vty
, ospf
);
10457 /* Area config print. */
10458 config_write_ospf_area(vty
, ospf
);
10460 /* static neighbor print. */
10461 config_write_ospf_nbr_nbma(vty
, ospf
);
10463 /* Virtual-Link print. */
10464 config_write_virtual_link(vty
, ospf
);
10466 /* Default metric configuration. */
10467 config_write_ospf_default_metric(vty
, ospf
);
10469 /* Distribute-list and default-information print. */
10470 config_write_ospf_distribute(vty
, ospf
);
10472 /* Distance configuration. */
10473 config_write_ospf_distance(vty
, ospf
);
10475 ospf_opaque_config_write_router(vty
, ospf
);
10481 /* OSPF configuration write function. */
10482 static int ospf_config_write(struct vty
*vty
)
10485 struct listnode
*ospf_node
= NULL
;
10488 if (listcount(om
->ospf
) == 0)
10491 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, ospf_node
, ospf
)) {
10492 /* VRF Default check if it is running.
10493 * Upon daemon start, there could be default instance
10494 * in absence of 'router ospf'/oi_running is disabled. */
10495 if (ospf
->vrf_id
== VRF_DEFAULT
&& ospf
->oi_running
)
10496 write
+= ospf_config_write_one(vty
, ospf
);
10497 /* For Non-Default VRF simply display the configuration,
10498 * even if it is not oi_running. */
10499 else if (ospf
->vrf_id
!= VRF_DEFAULT
)
10500 write
+= ospf_config_write_one(vty
, ospf
);
10505 void ospf_vty_show_init(void)
10507 /* "show ip ospf" commands. */
10508 install_element(VIEW_NODE
, &show_ip_ospf_cmd
);
10510 install_element(VIEW_NODE
, &show_ip_ospf_instance_cmd
);
10512 /* "show ip ospf database" commands. */
10513 install_element(VIEW_NODE
, &show_ip_ospf_database_max_cmd
);
10515 install_element(VIEW_NODE
,
10516 &show_ip_ospf_instance_database_type_adv_router_cmd
);
10517 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_cmd
);
10518 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_max_cmd
);
10520 /* "show ip ospf interface" commands. */
10521 install_element(VIEW_NODE
, &show_ip_ospf_interface_cmd
);
10523 install_element(VIEW_NODE
, &show_ip_ospf_instance_interface_cmd
);
10524 /* "show ip ospf interface traffic */
10525 install_element(VIEW_NODE
, &show_ip_ospf_interface_traffic_cmd
);
10527 /* "show ip ospf neighbor" commands. */
10528 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_detail_cmd
);
10529 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_cmd
);
10530 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_id_cmd
);
10531 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_all_cmd
);
10532 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_cmd
);
10533 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_cmd
);
10534 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_all_cmd
);
10536 install_element(VIEW_NODE
,
10537 &show_ip_ospf_instance_neighbor_int_detail_cmd
);
10538 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_int_cmd
);
10539 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_id_cmd
);
10540 install_element(VIEW_NODE
,
10541 &show_ip_ospf_instance_neighbor_detail_all_cmd
);
10542 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_detail_cmd
);
10543 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_cmd
);
10544 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_all_cmd
);
10546 /* "show ip ospf route" commands. */
10547 install_element(VIEW_NODE
, &show_ip_ospf_route_cmd
);
10548 install_element(VIEW_NODE
, &show_ip_ospf_border_routers_cmd
);
10550 install_element(VIEW_NODE
, &show_ip_ospf_instance_route_cmd
);
10551 install_element(VIEW_NODE
, &show_ip_ospf_instance_border_routers_cmd
);
10553 /* "show ip ospf vrfs" commands. */
10554 install_element(VIEW_NODE
, &show_ip_ospf_vrfs_cmd
);
10558 /* ospfd's interface node. */
10559 static struct cmd_node interface_node
= {INTERFACE_NODE
, "%s(config-if)# ", 1};
10561 /* Initialization of OSPF interface. */
10562 static void ospf_vty_if_init(void)
10564 /* Install interface node. */
10565 install_node(&interface_node
, config_write_interface
);
10568 /* "ip ospf authentication" commands. */
10569 install_element(INTERFACE_NODE
, &ip_ospf_authentication_args_addr_cmd
);
10570 install_element(INTERFACE_NODE
, &ip_ospf_authentication_addr_cmd
);
10571 install_element(INTERFACE_NODE
,
10572 &no_ip_ospf_authentication_args_addr_cmd
);
10573 install_element(INTERFACE_NODE
, &no_ip_ospf_authentication_addr_cmd
);
10574 install_element(INTERFACE_NODE
, &ip_ospf_authentication_key_addr_cmd
);
10575 install_element(INTERFACE_NODE
,
10576 &no_ip_ospf_authentication_key_authkey_addr_cmd
);
10577 install_element(INTERFACE_NODE
,
10578 &no_ospf_authentication_key_authkey_addr_cmd
);
10580 /* "ip ospf message-digest-key" commands. */
10581 install_element(INTERFACE_NODE
, &ip_ospf_message_digest_key_cmd
);
10582 install_element(INTERFACE_NODE
, &no_ip_ospf_message_digest_key_cmd
);
10584 /* "ip ospf cost" commands. */
10585 install_element(INTERFACE_NODE
, &ip_ospf_cost_cmd
);
10586 install_element(INTERFACE_NODE
, &no_ip_ospf_cost_cmd
);
10588 /* "ip ospf mtu-ignore" commands. */
10589 install_element(INTERFACE_NODE
, &ip_ospf_mtu_ignore_addr_cmd
);
10590 install_element(INTERFACE_NODE
, &no_ip_ospf_mtu_ignore_addr_cmd
);
10592 /* "ip ospf dead-interval" commands. */
10593 install_element(INTERFACE_NODE
, &ip_ospf_dead_interval_cmd
);
10594 install_element(INTERFACE_NODE
,
10595 &ip_ospf_dead_interval_minimal_addr_cmd
);
10596 install_element(INTERFACE_NODE
, &no_ip_ospf_dead_interval_cmd
);
10598 /* "ip ospf hello-interval" commands. */
10599 install_element(INTERFACE_NODE
, &ip_ospf_hello_interval_cmd
);
10600 install_element(INTERFACE_NODE
, &no_ip_ospf_hello_interval_cmd
);
10602 /* "ip ospf network" commands. */
10603 install_element(INTERFACE_NODE
, &ip_ospf_network_cmd
);
10604 install_element(INTERFACE_NODE
, &no_ip_ospf_network_cmd
);
10606 /* "ip ospf priority" commands. */
10607 install_element(INTERFACE_NODE
, &ip_ospf_priority_cmd
);
10608 install_element(INTERFACE_NODE
, &no_ip_ospf_priority_cmd
);
10610 /* "ip ospf retransmit-interval" commands. */
10611 install_element(INTERFACE_NODE
, &ip_ospf_retransmit_interval_addr_cmd
);
10612 install_element(INTERFACE_NODE
,
10613 &no_ip_ospf_retransmit_interval_addr_cmd
);
10615 /* "ip ospf transmit-delay" commands. */
10616 install_element(INTERFACE_NODE
, &ip_ospf_transmit_delay_addr_cmd
);
10617 install_element(INTERFACE_NODE
, &no_ip_ospf_transmit_delay_addr_cmd
);
10619 /* "ip ospf area" commands. */
10620 install_element(INTERFACE_NODE
, &ip_ospf_area_cmd
);
10621 install_element(INTERFACE_NODE
, &no_ip_ospf_area_cmd
);
10623 /* These commands are compatibitliy for previous version. */
10624 install_element(INTERFACE_NODE
, &ospf_authentication_key_cmd
);
10625 install_element(INTERFACE_NODE
, &ospf_message_digest_key_cmd
);
10626 install_element(INTERFACE_NODE
, &no_ospf_message_digest_key_cmd
);
10627 install_element(INTERFACE_NODE
, &ospf_dead_interval_cmd
);
10628 install_element(INTERFACE_NODE
, &no_ospf_dead_interval_cmd
);
10629 install_element(INTERFACE_NODE
, &ospf_hello_interval_cmd
);
10630 install_element(INTERFACE_NODE
, &no_ospf_hello_interval_cmd
);
10631 install_element(INTERFACE_NODE
, &ospf_cost_cmd
);
10632 install_element(INTERFACE_NODE
, &no_ospf_cost_cmd
);
10633 install_element(INTERFACE_NODE
, &ospf_network_cmd
);
10634 install_element(INTERFACE_NODE
, &no_ospf_network_cmd
);
10635 install_element(INTERFACE_NODE
, &ospf_priority_cmd
);
10636 install_element(INTERFACE_NODE
, &no_ospf_priority_cmd
);
10637 install_element(INTERFACE_NODE
, &ospf_retransmit_interval_cmd
);
10638 install_element(INTERFACE_NODE
, &no_ospf_retransmit_interval_cmd
);
10639 install_element(INTERFACE_NODE
, &ospf_transmit_delay_cmd
);
10640 install_element(INTERFACE_NODE
, &no_ospf_transmit_delay_cmd
);
10643 static void ospf_vty_zebra_init(void)
10645 install_element(OSPF_NODE
, &ospf_redistribute_source_cmd
);
10646 install_element(OSPF_NODE
, &no_ospf_redistribute_source_cmd
);
10647 install_element(OSPF_NODE
, &ospf_redistribute_instance_source_cmd
);
10648 install_element(OSPF_NODE
, &no_ospf_redistribute_instance_source_cmd
);
10650 install_element(OSPF_NODE
, &ospf_distribute_list_out_cmd
);
10651 install_element(OSPF_NODE
, &no_ospf_distribute_list_out_cmd
);
10653 install_element(OSPF_NODE
, &ospf_default_information_originate_cmd
);
10654 install_element(OSPF_NODE
, &no_ospf_default_information_originate_cmd
);
10656 install_element(OSPF_NODE
, &ospf_default_metric_cmd
);
10657 install_element(OSPF_NODE
, &no_ospf_default_metric_cmd
);
10659 install_element(OSPF_NODE
, &ospf_distance_cmd
);
10660 install_element(OSPF_NODE
, &no_ospf_distance_cmd
);
10661 install_element(OSPF_NODE
, &no_ospf_distance_ospf_cmd
);
10662 install_element(OSPF_NODE
, &ospf_distance_ospf_cmd
);
10664 install_element (OSPF_NODE
, &ospf_distance_source_cmd
);
10665 install_element (OSPF_NODE
, &no_ospf_distance_source_cmd
);
10666 install_element (OSPF_NODE
, &ospf_distance_source_access_list_cmd
);
10667 install_element (OSPF_NODE
, &no_ospf_distance_source_access_list_cmd
);
10671 static struct cmd_node ospf_node
= {OSPF_NODE
, "%s(config-router)# ", 1};
10673 static void ospf_interface_clear(struct interface
*ifp
)
10675 if (!if_is_operative(ifp
))
10678 if (IS_DEBUG_OSPF(ism
, ISM_EVENTS
))
10679 zlog_debug("ISM[%s]: clear by reset", ifp
->name
);
10681 ospf_if_reset(ifp
);
10684 DEFUN (clear_ip_ospf_interface
,
10685 clear_ip_ospf_interface_cmd
,
10686 "clear ip ospf [vrf NAME] interface [IFNAME]",
10689 "OSPF information\n"
10691 "Interface information\n"
10692 "Interface name\n")
10694 int idx_ifname
= 0;
10696 struct interface
*ifp
;
10697 struct listnode
*node
;
10698 struct ospf
*ospf
= NULL
;
10699 char *vrf_name
= NULL
;
10700 vrf_id_t vrf_id
= VRF_DEFAULT
;
10701 struct vrf
*vrf
= NULL
;
10703 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
10704 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
10705 if (vrf_name
&& strmatch(vrf_name
, VRF_DEFAULT_NAME
))
10708 vrf
= vrf_lookup_by_name(vrf_name
);
10710 vrf_id
= vrf
->vrf_id
;
10712 if (!argv_find(argv
, argc
, "IFNAME", &idx_ifname
)) {
10713 /* Clear all the ospfv2 interfaces. */
10714 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
10715 if (vrf_id
!= ospf
->vrf_id
)
10718 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
10719 FOR_ALL_INTERFACES (vrf
, ifp
)
10720 ospf_interface_clear(ifp
);
10723 /* Interface name is specified. */
10724 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf_id
);
10726 vty_out(vty
, "No such interface name\n");
10728 ospf_interface_clear(ifp
);
10731 return CMD_SUCCESS
;
10734 void ospf_vty_clear_init(void)
10736 install_element(ENABLE_NODE
, &clear_ip_ospf_interface_cmd
);
10740 /* Install OSPF related vty commands. */
10741 void ospf_vty_init(void)
10743 /* Install ospf top node. */
10744 install_node(&ospf_node
, ospf_config_write
);
10746 /* "router ospf" commands. */
10747 install_element(CONFIG_NODE
, &router_ospf_cmd
);
10748 install_element(CONFIG_NODE
, &no_router_ospf_cmd
);
10751 install_default(OSPF_NODE
);
10753 /* "ospf router-id" commands. */
10754 install_element(OSPF_NODE
, &ospf_router_id_cmd
);
10755 install_element(OSPF_NODE
, &ospf_router_id_old_cmd
);
10756 install_element(OSPF_NODE
, &no_ospf_router_id_cmd
);
10758 /* "passive-interface" commands. */
10759 install_element(OSPF_NODE
, &ospf_passive_interface_addr_cmd
);
10760 install_element(OSPF_NODE
, &no_ospf_passive_interface_addr_cmd
);
10762 /* "ospf abr-type" commands. */
10763 install_element(OSPF_NODE
, &ospf_abr_type_cmd
);
10764 install_element(OSPF_NODE
, &no_ospf_abr_type_cmd
);
10766 /* "ospf log-adjacency-changes" commands. */
10767 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_cmd
);
10768 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_detail_cmd
);
10769 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_cmd
);
10770 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_detail_cmd
);
10772 /* "ospf rfc1583-compatible" commands. */
10773 install_element(OSPF_NODE
, &ospf_compatible_rfc1583_cmd
);
10774 install_element(OSPF_NODE
, &no_ospf_compatible_rfc1583_cmd
);
10775 install_element(OSPF_NODE
, &ospf_rfc1583_flag_cmd
);
10776 install_element(OSPF_NODE
, &no_ospf_rfc1583_flag_cmd
);
10778 /* "network area" commands. */
10779 install_element(OSPF_NODE
, &ospf_network_area_cmd
);
10780 install_element(OSPF_NODE
, &no_ospf_network_area_cmd
);
10782 /* "area authentication" commands. */
10783 install_element(OSPF_NODE
,
10784 &ospf_area_authentication_message_digest_cmd
);
10785 install_element(OSPF_NODE
, &ospf_area_authentication_cmd
);
10786 install_element(OSPF_NODE
, &no_ospf_area_authentication_cmd
);
10788 /* "area range" commands. */
10789 install_element(OSPF_NODE
, &ospf_area_range_cmd
);
10790 install_element(OSPF_NODE
, &ospf_area_range_cost_cmd
);
10791 install_element(OSPF_NODE
, &ospf_area_range_not_advertise_cmd
);
10792 install_element(OSPF_NODE
, &no_ospf_area_range_cmd
);
10793 install_element(OSPF_NODE
, &ospf_area_range_substitute_cmd
);
10794 install_element(OSPF_NODE
, &no_ospf_area_range_substitute_cmd
);
10796 /* "area virtual-link" commands. */
10797 install_element(OSPF_NODE
, &ospf_area_vlink_cmd
);
10798 install_element(OSPF_NODE
, &ospf_area_vlink_intervals_cmd
);
10799 install_element(OSPF_NODE
, &no_ospf_area_vlink_cmd
);
10800 install_element(OSPF_NODE
, &no_ospf_area_vlink_intervals_cmd
);
10803 /* "area stub" commands. */
10804 install_element(OSPF_NODE
, &ospf_area_stub_no_summary_cmd
);
10805 install_element(OSPF_NODE
, &ospf_area_stub_cmd
);
10806 install_element(OSPF_NODE
, &no_ospf_area_stub_no_summary_cmd
);
10807 install_element(OSPF_NODE
, &no_ospf_area_stub_cmd
);
10809 /* "area nssa" commands. */
10810 install_element(OSPF_NODE
, &ospf_area_nssa_cmd
);
10811 install_element(OSPF_NODE
, &ospf_area_nssa_translate_cmd
);
10812 install_element(OSPF_NODE
, &ospf_area_nssa_no_summary_cmd
);
10813 install_element(OSPF_NODE
, &no_ospf_area_nssa_no_summary_cmd
);
10814 install_element(OSPF_NODE
, &no_ospf_area_nssa_cmd
);
10816 install_element(OSPF_NODE
, &ospf_area_default_cost_cmd
);
10817 install_element(OSPF_NODE
, &no_ospf_area_default_cost_cmd
);
10819 install_element(OSPF_NODE
, &ospf_area_shortcut_cmd
);
10820 install_element(OSPF_NODE
, &no_ospf_area_shortcut_cmd
);
10822 install_element(OSPF_NODE
, &ospf_area_export_list_cmd
);
10823 install_element(OSPF_NODE
, &no_ospf_area_export_list_cmd
);
10825 install_element(OSPF_NODE
, &ospf_area_filter_list_cmd
);
10826 install_element(OSPF_NODE
, &no_ospf_area_filter_list_cmd
);
10828 install_element(OSPF_NODE
, &ospf_area_import_list_cmd
);
10829 install_element(OSPF_NODE
, &no_ospf_area_import_list_cmd
);
10831 /* SPF timer commands */
10832 install_element(OSPF_NODE
, &ospf_timers_throttle_spf_cmd
);
10833 install_element(OSPF_NODE
, &no_ospf_timers_throttle_spf_cmd
);
10835 /* LSA timers commands */
10836 install_element(OSPF_NODE
, &ospf_timers_min_ls_interval_cmd
);
10837 install_element(OSPF_NODE
, &no_ospf_timers_min_ls_interval_cmd
);
10838 install_element(OSPF_NODE
, &ospf_timers_lsa_min_arrival_cmd
);
10839 install_element(OSPF_NODE
, &no_ospf_timers_lsa_min_arrival_cmd
);
10841 /* refresh timer commands */
10842 install_element(OSPF_NODE
, &ospf_refresh_timer_cmd
);
10843 install_element(OSPF_NODE
, &no_ospf_refresh_timer_val_cmd
);
10845 /* max-metric commands */
10846 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_admin_cmd
);
10847 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_admin_cmd
);
10848 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_startup_cmd
);
10849 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_startup_cmd
);
10850 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_shutdown_cmd
);
10851 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_shutdown_cmd
);
10853 /* reference bandwidth commands */
10854 install_element(OSPF_NODE
, &ospf_auto_cost_reference_bandwidth_cmd
);
10855 install_element(OSPF_NODE
, &no_ospf_auto_cost_reference_bandwidth_cmd
);
10857 /* "neighbor" commands. */
10858 install_element(OSPF_NODE
, &ospf_neighbor_cmd
);
10859 install_element(OSPF_NODE
, &ospf_neighbor_poll_interval_cmd
);
10860 install_element(OSPF_NODE
, &no_ospf_neighbor_cmd
);
10861 install_element(OSPF_NODE
, &no_ospf_neighbor_poll_cmd
);
10863 /* write multiplier commands */
10864 install_element(OSPF_NODE
, &ospf_write_multiplier_cmd
);
10865 install_element(OSPF_NODE
, &write_multiplier_cmd
);
10866 install_element(OSPF_NODE
, &no_ospf_write_multiplier_cmd
);
10867 install_element(OSPF_NODE
, &no_write_multiplier_cmd
);
10869 /* Init interface related vty commands. */
10870 ospf_vty_if_init();
10872 /* Init zebra related vty commands. */
10873 ospf_vty_zebra_init();