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 static const char *ospf_network_type_str
[] = {
57 "Null", "POINTOPOINT", "BROADCAST", "NBMA", "POINTOMULTIPOINT",
58 "VIRTUALLINK", "LOOPBACK"};
60 /* Utility functions. */
61 int str2area_id(const char *str
, struct in_addr
*area_id
, int *area_id_fmt
)
65 area_id
->s_addr
= htonl(strtoul(str
, &ep
, 10));
66 if (*ep
&& !inet_aton(str
, area_id
))
70 *ep
? OSPF_AREA_ID_FMT_DOTTEDQUAD
: OSPF_AREA_ID_FMT_DECIMAL
;
75 static void area_id2str(char *buf
, int length
, struct in_addr
*area_id
,
78 if (area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
79 inet_ntop(AF_INET
, area_id
, buf
, length
);
81 sprintf(buf
, "%lu", (unsigned long)ntohl(area_id
->s_addr
));
84 static int str2metric(const char *str
, int *metric
)
90 *metric
= strtol(str
, NULL
, 10);
91 if (*metric
< 0 && *metric
> 16777214) {
92 /* vty_out (vty, "OSPF metric value is invalid\n"); */
99 static int str2metric_type(const char *str
, int *metric_type
)
105 if (strncmp(str
, "1", 1) == 0)
106 *metric_type
= EXTERNAL_METRIC_TYPE_1
;
107 else if (strncmp(str
, "2", 1) == 0)
108 *metric_type
= EXTERNAL_METRIC_TYPE_2
;
115 int ospf_oi_count(struct interface
*ifp
)
117 struct route_node
*rn
;
120 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
127 #define OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf) \
128 if (argv_find(argv, argc, "vrf", &idx_vrf)) { \
129 vrf_name = argv[idx_vrf + 1]->arg; \
130 all_vrf = strmatch(vrf_name, "all"); \
133 static struct ospf
*ospf_cmd_lookup_ospf(struct vty
*vty
,
134 struct cmd_token
*argv
[],
135 const int argc
, uint32_t enable
,
136 unsigned short *instance
)
138 struct ospf
*ospf
= NULL
;
139 int idx_vrf
= 0, idx_inst
= 0;
140 const char *vrf_name
= NULL
;
143 if (argv_find(argv
, argc
, "(1-65535)", &idx_inst
))
144 *instance
= strtoul(argv
[idx_inst
]->arg
, NULL
, 10);
146 if (argv_find(argv
, argc
, "vrf", &idx_vrf
)) {
147 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
148 if (vrf_name
== NULL
|| strmatch(vrf_name
, VRF_DEFAULT_NAME
))
151 /* Allocate VRF aware instance */
152 ospf
= ospf_get(*instance
, vrf_name
);
154 ospf
= ospf_lookup_by_inst_name(*instance
, vrf_name
);
158 ospf
= ospf_get(*instance
, NULL
);
160 ospf
= ospf_lookup_instance(*instance
);
167 static void ospf_show_vrf_name(struct ospf
*ospf
, struct vty
*vty
,
168 json_object
*json
, uint8_t use_vrf
)
172 if (ospf
->vrf_id
== VRF_DEFAULT
)
173 json_object_string_add(json
, "vrfName",
176 json_object_string_add(json
, "vrfName",
178 json_object_int_add(json
, "vrfId", ospf
->vrf_id
);
180 if (ospf
->vrf_id
== VRF_DEFAULT
)
181 vty_out(vty
, "VRF Name: %s\n", "default");
183 vty_out(vty
, "VRF Name: %s\n", ospf
->name
);
188 #ifndef VTYSH_EXTRACT_PL
189 #include "ospfd/ospf_vty_clippy.c"
192 DEFUN_NOSH (router_ospf
,
194 "router ospf [{(1-65535)|vrf NAME}]",
195 "Enable a routing process\n"
196 "Start OSPF configuration\n"
200 struct ospf
*ospf
= NULL
;
201 int ret
= CMD_SUCCESS
;
202 unsigned short instance
= 0;
203 struct vrf
*vrf
= NULL
;
204 struct route_node
*rn
;
205 struct interface
*ifp
;
207 ospf
= ospf_cmd_lookup_ospf(vty
, argv
, argc
, 1, &instance
);
209 return CMD_WARNING_CONFIG_FAILED
;
211 /* The following logic to set the vty qobj index is in place to be able
212 to ignore the commands which dont belong to this instance. */
213 if (ospf
->instance
!= instance
) {
214 VTY_PUSH_CONTEXT_NULL(OSPF_NODE
);
215 ret
= CMD_NOT_MY_INSTANCE
;
217 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
218 ospf
->oi_running
= 1;
219 if (IS_DEBUG_OSPF_EVENT
)
221 "Config command 'router ospf %d' received, vrf %s id %u oi_running %u",
222 instance
, ospf
->name
? ospf
->name
: "NIL",
223 ospf
->vrf_id
, ospf
->oi_running
);
224 VTY_PUSH_CONTEXT(OSPF_NODE
, ospf
);
226 /* Activate 'ip ospf area x' configured interfaces for given
227 * vrf. Activate area on vrf x aware interfaces.
228 * vrf_enable callback calls router_id_update which
229 * internally will call ospf_if_update to trigger
232 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
234 FOR_ALL_INTERFACES (vrf
, ifp
) {
235 struct ospf_if_params
*params
;
237 params
= IF_DEF_PARAMS(ifp
);
238 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
239 for (rn
= route_top(ospf
->networks
); rn
;
240 rn
= route_next(rn
)) {
241 if (rn
->info
!= NULL
) {
243 "Interface %s has area config but please remove all network commands first.\n",
248 ospf_interface_area_set(ospf
, ifp
);
249 ospf
->if_ospf_cli_count
++;
253 ospf_router_id_update(ospf
);
259 DEFUN (no_router_ospf
,
261 "no router ospf [{(1-65535)|vrf NAME}]",
263 "Enable a routing process\n"
264 "Start OSPF configuration\n"
269 unsigned short instance
= 0;
271 ospf
= ospf_cmd_lookup_ospf(vty
, argv
, argc
, 0, &instance
);
274 return CMD_NOT_MY_INSTANCE
;
284 DEFPY (ospf_router_id
,
286 "ospf router-id A.B.C.D",
287 "OSPF specific commands\n"
288 "router-id for the OSPF process\n"
289 "OSPF router-id in IP address format\n")
291 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
293 struct listnode
*node
;
294 struct ospf_area
*area
;
296 ospf
->router_id_static
= router_id
;
298 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
299 if (area
->full_nbrs
) {
301 "For this router-id change to take effect,"
302 " save config and restart ospfd\n");
306 ospf_router_id_update(ospf
);
311 DEFUN_HIDDEN (ospf_router_id_old
,
312 ospf_router_id_old_cmd
,
314 "router-id for the OSPF process\n"
315 "OSPF router-id in IP address format\n")
317 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
319 struct listnode
*node
;
320 struct ospf_area
*area
;
321 struct in_addr router_id
;
324 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &router_id
);
326 vty_out(vty
, "Please specify Router ID by A.B.C.D\n");
327 return CMD_WARNING_CONFIG_FAILED
;
330 ospf
->router_id_static
= router_id
;
332 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
333 if (area
->full_nbrs
) {
335 "For this router-id change to take effect,"
336 " save config and restart ospfd\n");
340 ospf_router_id_update(ospf
);
345 DEFPY (no_ospf_router_id
,
346 no_ospf_router_id_cmd
,
347 "no ospf router-id [A.B.C.D]",
349 "OSPF specific commands\n"
350 "router-id for the OSPF process\n"
351 "OSPF router-id in IP address format\n")
353 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
354 struct listnode
*node
;
355 struct ospf_area
*area
;
358 if (!IPV4_ADDR_SAME(&ospf
->router_id_static
, &router_id
)) {
359 vty_out(vty
, "%% OSPF router-id doesn't match\n");
360 return CMD_WARNING_CONFIG_FAILED
;
364 ospf
->router_id_static
.s_addr
= 0;
366 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
367 if (area
->full_nbrs
) {
369 "For this router-id change to take effect,"
370 " save config and restart ospfd\n");
374 ospf_router_id_update(ospf
);
380 static void ospf_passive_interface_default(struct ospf
*ospf
, uint8_t newval
)
382 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
384 struct interface
*ifp
;
385 struct ospf_interface
*oi
;
387 ospf
->passive_interface_default
= newval
;
389 FOR_ALL_INTERFACES (vrf
, ifp
) {
390 if (ifp
&& OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp
),
392 UNSET_IF_PARAM(IF_DEF_PARAMS(ifp
), passive_interface
);
394 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, ln
, oi
)) {
395 if (OSPF_IF_PARAM_CONFIGURED(oi
->params
, passive_interface
))
396 UNSET_IF_PARAM(oi
->params
, passive_interface
);
397 /* update multicast memberships */
398 ospf_if_set_multicast(oi
);
402 static void ospf_passive_interface_update_addr(struct ospf
*ospf
,
403 struct interface
*ifp
,
404 struct ospf_if_params
*params
,
410 params
->passive_interface
= value
;
411 if (params
!= IF_DEF_PARAMS(ifp
)) {
412 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp
),
414 dflt
= IF_DEF_PARAMS(ifp
)->passive_interface
;
416 dflt
= ospf
->passive_interface_default
;
419 SET_IF_PARAM(params
, passive_interface
);
421 UNSET_IF_PARAM(params
, passive_interface
);
423 ospf_free_if_params(ifp
, addr
);
424 ospf_if_update_params(ifp
, addr
);
428 static void ospf_passive_interface_update(struct ospf
*ospf
,
429 struct interface
*ifp
,
430 struct ospf_if_params
*params
,
433 params
->passive_interface
= value
;
434 if (params
== IF_DEF_PARAMS(ifp
)) {
435 if (value
!= ospf
->passive_interface_default
)
436 SET_IF_PARAM(params
, passive_interface
);
438 UNSET_IF_PARAM(params
, passive_interface
);
442 DEFUN (ospf_passive_interface
,
443 ospf_passive_interface_addr_cmd
,
444 "passive-interface <IFNAME [A.B.C.D]|default>",
445 "Suppress routing updates on an interface\n"
448 "Suppress routing updates on interfaces by default\n")
450 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
452 struct interface
*ifp
= NULL
;
453 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
455 struct ospf_if_params
*params
;
456 struct route_node
*rn
;
458 if (strmatch(argv
[1]->text
, "default")) {
459 ospf_passive_interface_default(ospf
, OSPF_IF_PASSIVE
);
462 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
463 ifp
= if_get_by_name(argv
[1]->arg
, ospf
->vrf_id
, 0);
466 vty_out(vty
, "interface %s not found.\n", (char *)argv
[1]->arg
);
467 return CMD_WARNING_CONFIG_FAILED
;
470 params
= IF_DEF_PARAMS(ifp
);
473 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
476 "Please specify interface address by A.B.C.D\n");
477 return CMD_WARNING_CONFIG_FAILED
;
480 params
= ospf_get_if_params(ifp
, addr
);
481 ospf_if_update_params(ifp
, addr
);
482 ospf_passive_interface_update_addr(ospf
, ifp
, params
,
483 OSPF_IF_PASSIVE
, addr
);
486 ospf_passive_interface_update(ospf
, ifp
, params
, OSPF_IF_PASSIVE
);
488 /* XXX We should call ospf_if_set_multicast on exactly those
489 * interfaces for which the passive property changed. It is too much
490 * work to determine this set, so we do this for every interface.
491 * This is safe and reasonable because ospf_if_set_multicast uses a
492 * record of joined groups to avoid systems calls if the desired
493 * memberships match the current memership.
496 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
497 struct ospf_interface
*oi
= rn
->info
;
499 if (oi
&& (OSPF_IF_PARAM(oi
, passive_interface
)
501 ospf_if_set_multicast(oi
);
504 * XXX It is not clear what state transitions the interface needs to
505 * undergo when going from active to passive. Fixing this will
506 * require precise identification of interfaces having such a
513 DEFUN (no_ospf_passive_interface
,
514 no_ospf_passive_interface_addr_cmd
,
515 "no passive-interface <IFNAME [A.B.C.D]|default>",
517 "Allow routing updates on an interface\n"
520 "Allow routing updates on interfaces by default\n")
522 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
524 struct interface
*ifp
= NULL
;
525 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
526 struct ospf_if_params
*params
;
528 struct route_node
*rn
;
530 if (strmatch(argv
[2]->text
, "default")) {
531 ospf_passive_interface_default(ospf
, OSPF_IF_ACTIVE
);
535 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
536 ifp
= if_get_by_name(argv
[2]->arg
, ospf
->vrf_id
, 0);
539 vty_out(vty
, "interface %s not found.\n", (char *)argv
[2]->arg
);
540 return CMD_WARNING_CONFIG_FAILED
;
543 params
= IF_DEF_PARAMS(ifp
);
546 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
549 "Please specify interface address by A.B.C.D\n");
550 return CMD_WARNING_CONFIG_FAILED
;
553 params
= ospf_lookup_if_params(ifp
, addr
);
556 ospf_passive_interface_update_addr(ospf
, ifp
, params
,
557 OSPF_IF_ACTIVE
, addr
);
559 ospf_passive_interface_update(ospf
, ifp
, params
, OSPF_IF_ACTIVE
);
561 /* XXX We should call ospf_if_set_multicast on exactly those
562 * interfaces for which the passive property changed. It is too much
563 * work to determine this set, so we do this for every interface.
564 * This is safe and reasonable because ospf_if_set_multicast uses a
565 * record of joined groups to avoid systems calls if the desired
566 * memberships match the current memership.
568 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
569 struct ospf_interface
*oi
= rn
->info
;
572 && (OSPF_IF_PARAM(oi
, passive_interface
) == OSPF_IF_ACTIVE
))
573 ospf_if_set_multicast(oi
);
580 DEFUN (ospf_network_area
,
581 ospf_network_area_cmd
,
582 "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
583 "Enable routing on an IP network\n"
584 "OSPF network prefix\n"
585 "Set the OSPF area ID\n"
586 "OSPF area ID in IP address format\n"
587 "OSPF area ID as a decimal value\n")
589 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
590 int idx_ipv4_prefixlen
= 1;
591 int idx_ipv4_number
= 3;
592 struct prefix_ipv4 p
;
593 struct in_addr area_id
;
596 if (ospf
->instance
) {
598 "The network command is not supported in multi-instance ospf\n");
599 return CMD_WARNING_CONFIG_FAILED
;
602 if (ospf
->if_ospf_cli_count
> 0) {
604 "Please remove all ip ospf area x.x.x.x commands first.\n");
605 if (IS_DEBUG_OSPF_EVENT
)
607 "%s ospf vrf %s num of %u ip osp area x config",
609 ospf
->name
? ospf
->name
: "NIL",
610 ospf
->if_ospf_cli_count
);
611 return CMD_WARNING_CONFIG_FAILED
;
614 /* Get network prefix and Area ID. */
615 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
616 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
618 ret
= ospf_network_set(ospf
, &p
, area_id
, format
);
620 vty_out(vty
, "There is already same network statement.\n");
621 return CMD_WARNING_CONFIG_FAILED
;
627 DEFUN (no_ospf_network_area
,
628 no_ospf_network_area_cmd
,
629 "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
631 "Enable routing on an IP network\n"
632 "OSPF network prefix\n"
633 "Set the OSPF area ID\n"
634 "OSPF area ID in IP address format\n"
635 "OSPF area ID as a decimal value\n")
637 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
638 int idx_ipv4_prefixlen
= 2;
639 int idx_ipv4_number
= 4;
640 struct prefix_ipv4 p
;
641 struct in_addr area_id
;
644 if (ospf
->instance
) {
646 "The network command is not supported in multi-instance ospf\n");
647 return CMD_WARNING_CONFIG_FAILED
;
650 /* Get network prefix and Area ID. */
651 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
652 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
654 ret
= ospf_network_unset(ospf
, &p
, area_id
);
657 "Can't find specified network area configuration.\n");
658 return CMD_WARNING_CONFIG_FAILED
;
664 DEFUN (ospf_area_range
,
666 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]",
667 "OSPF area parameters\n"
668 "OSPF area ID in IP address format\n"
669 "OSPF area ID as a decimal value\n"
670 "Summarize routes matching address/mask (border routers only)\n"
671 "Area range prefix\n"
672 "Advertise this range (default)\n"
673 "User specified metric for this range\n"
674 "Advertised metric for this range\n")
676 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
677 int idx_ipv4_number
= 1;
678 int idx_ipv4_prefixlen
= 3;
680 struct prefix_ipv4 p
;
681 struct in_addr area_id
;
685 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
686 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
688 ospf_area_range_set(ospf
, area_id
, &p
, OSPF_AREA_RANGE_ADVERTISE
);
690 cost
= strtoul(argv
[idx_cost
]->arg
, NULL
, 10);
691 ospf_area_range_cost_set(ospf
, area_id
, &p
, cost
);
697 DEFUN (ospf_area_range_cost
,
698 ospf_area_range_cost_cmd
,
699 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M cost (0-16777215)",
700 "OSPF area parameters\n"
701 "OSPF area ID in IP address format\n"
702 "OSPF area ID as a decimal value\n"
703 "Summarize routes matching address/mask (border routers only)\n"
704 "Area range prefix\n"
705 "User specified metric for this range\n"
706 "Advertised metric for this range\n")
708 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
709 int idx_ipv4_number
= 1;
710 int idx_ipv4_prefixlen
= 3;
712 struct prefix_ipv4 p
;
713 struct in_addr area_id
;
717 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
718 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
720 ospf_area_range_set(ospf
, area_id
, &p
, OSPF_AREA_RANGE_ADVERTISE
);
721 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
724 cost
= strtoul(argv
[idx_cost
]->arg
, NULL
, 10);
725 ospf_area_range_cost_set(ospf
, area_id
, &p
, cost
);
730 DEFUN (ospf_area_range_not_advertise
,
731 ospf_area_range_not_advertise_cmd
,
732 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise",
733 "OSPF area parameters\n"
734 "OSPF area ID in IP address format\n"
735 "OSPF area ID as a decimal value\n"
736 "Summarize routes matching address/mask (border routers only)\n"
737 "Area range prefix\n"
738 "DoNotAdvertise this range\n")
740 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
741 int idx_ipv4_number
= 1;
742 int idx_ipv4_prefixlen
= 3;
743 struct prefix_ipv4 p
;
744 struct in_addr area_id
;
747 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
748 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
750 ospf_area_range_set(ospf
, area_id
, &p
, 0);
751 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
753 ospf_area_range_substitute_unset(ospf
, area_id
, &p
);
758 DEFUN (no_ospf_area_range
,
759 no_ospf_area_range_cmd
,
760 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]",
762 "OSPF area parameters\n"
763 "OSPF area ID in IP address format\n"
764 "OSPF area ID as a decimal value\n"
765 "Summarize routes matching address/mask (border routers only)\n"
766 "Area range prefix\n"
767 "User specified metric for this range\n"
768 "Advertised metric for this range\n"
769 "Advertise this range (default)\n"
770 "User specified metric for this range\n"
771 "Advertised metric for this range\n"
772 "DoNotAdvertise this range\n")
774 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
775 int idx_ipv4_number
= 2;
776 int idx_ipv4_prefixlen
= 4;
777 struct prefix_ipv4 p
;
778 struct in_addr area_id
;
781 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
782 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
784 ospf_area_range_unset(ospf
, area_id
, &p
);
789 DEFUN (ospf_area_range_substitute
,
790 ospf_area_range_substitute_cmd
,
791 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
792 "OSPF area parameters\n"
793 "OSPF area ID in IP address format\n"
794 "OSPF area ID as a decimal value\n"
795 "Summarize routes matching address/mask (border routers only)\n"
796 "Area range prefix\n"
797 "Announce area range as another prefix\n"
798 "Network prefix to be announced instead of range\n")
800 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
801 int idx_ipv4_number
= 1;
802 int idx_ipv4_prefixlen
= 3;
803 int idx_ipv4_prefixlen_2
= 5;
804 struct prefix_ipv4 p
, s
;
805 struct in_addr area_id
;
808 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
809 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
810 str2prefix_ipv4(argv
[idx_ipv4_prefixlen_2
]->arg
, &s
);
812 ospf_area_range_substitute_set(ospf
, area_id
, &p
, &s
);
813 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
819 DEFUN (no_ospf_area_range_substitute
,
820 no_ospf_area_range_substitute_cmd
,
821 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
823 "OSPF area parameters\n"
824 "OSPF area ID in IP address format\n"
825 "OSPF area ID as a decimal value\n"
826 "Summarize routes matching address/mask (border routers only)\n"
827 "Area range prefix\n"
828 "Announce area range as another prefix\n"
829 "Network prefix to be announced instead of range\n")
831 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
832 int idx_ipv4_number
= 2;
833 int idx_ipv4_prefixlen
= 4;
834 int idx_ipv4_prefixlen_2
= 6;
835 struct prefix_ipv4 p
, s
;
836 struct in_addr area_id
;
839 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
840 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
841 str2prefix_ipv4(argv
[idx_ipv4_prefixlen_2
]->arg
, &s
);
843 ospf_area_range_substitute_unset(ospf
, area_id
, &p
);
849 /* Command Handler Logic in VLink stuff is delicate!!
851 ALTER AT YOUR OWN RISK!!!!
853 Various dummy values are used to represent 'NoChange' state for
854 VLink configuration NOT being changed by a VLink command, and
855 special syntax is used within the command strings so that the
856 typed in command verbs can be seen in the configuration command
857 bacckend handler. This is to drastically reduce the verbeage
858 required to coe up with a reasonably compatible Cisco VLink command
860 - Matthew Grant <grantma@anathoth.gen.nz>
861 Wed, 21 Feb 2001 15:13:52 +1300
864 /* Configuration data for virtual links
866 struct ospf_vl_config_data
{
867 struct vty
*vty
; /* vty stuff */
868 struct in_addr area_id
; /* area ID from command line */
869 int area_id_fmt
; /* command line area ID format */
870 struct in_addr vl_peer
; /* command line vl_peer */
871 int auth_type
; /* Authehntication type, if given */
872 char *auth_key
; /* simple password if present */
873 int crypto_key_id
; /* Cryptographic key ID */
874 char *md5_key
; /* MD5 authentication key */
875 int hello_interval
; /* Obvious what these are... */
876 int retransmit_interval
;
881 static void ospf_vl_config_data_init(struct ospf_vl_config_data
*vl_config
,
884 memset(vl_config
, 0, sizeof(struct ospf_vl_config_data
));
885 vl_config
->auth_type
= OSPF_AUTH_CMD_NOTSEEN
;
886 vl_config
->vty
= vty
;
889 static struct ospf_vl_data
*
890 ospf_find_vl_data(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
892 struct ospf_area
*area
;
893 struct ospf_vl_data
*vl_data
;
895 struct in_addr area_id
;
897 vty
= vl_config
->vty
;
898 area_id
= vl_config
->area_id
;
900 if (area_id
.s_addr
== OSPF_AREA_BACKBONE
) {
902 "Configuring VLs over the backbone is not allowed\n");
905 area
= ospf_area_get(ospf
, area_id
);
906 ospf_area_display_format_set(ospf
, area
, vl_config
->area_id_fmt
);
908 if (area
->external_routing
!= OSPF_AREA_DEFAULT
) {
909 if (vl_config
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
910 vty_out(vty
, "Area %s is %s\n", inet_ntoa(area_id
),
911 area
->external_routing
== OSPF_AREA_NSSA
915 vty_out(vty
, "Area %ld is %s\n",
916 (unsigned long)ntohl(area_id
.s_addr
),
917 area
->external_routing
== OSPF_AREA_NSSA
923 if ((vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
->vl_peer
))
925 vl_data
= ospf_vl_data_new(area
, vl_config
->vl_peer
);
926 if (vl_data
->vl_oi
== NULL
) {
927 vl_data
->vl_oi
= ospf_vl_new(ospf
, vl_data
);
928 ospf_vl_add(ospf
, vl_data
);
929 ospf_spf_calculate_schedule(ospf
,
930 SPF_FLAG_CONFIG_CHANGE
);
937 static int ospf_vl_set_security(struct ospf_vl_data
*vl_data
,
938 struct ospf_vl_config_data
*vl_config
)
940 struct crypt_key
*ck
;
942 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
944 vty
= vl_config
->vty
;
946 if (vl_config
->auth_type
!= OSPF_AUTH_CMD_NOTSEEN
) {
947 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), auth_type
);
948 IF_DEF_PARAMS(ifp
)->auth_type
= vl_config
->auth_type
;
951 if (vl_config
->auth_key
) {
952 memset(IF_DEF_PARAMS(ifp
)->auth_simple
, 0,
953 OSPF_AUTH_SIMPLE_SIZE
+ 1);
954 strncpy((char *)IF_DEF_PARAMS(ifp
)->auth_simple
,
955 vl_config
->auth_key
, OSPF_AUTH_SIMPLE_SIZE
);
956 } else if (vl_config
->md5_key
) {
957 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
958 vl_config
->crypto_key_id
)
960 vty_out(vty
, "OSPF: Key %d already exists\n",
961 vl_config
->crypto_key_id
);
964 ck
= ospf_crypt_key_new();
965 ck
->key_id
= vl_config
->crypto_key_id
;
966 memset(ck
->auth_key
, 0, OSPF_AUTH_MD5_SIZE
+ 1);
967 strncpy((char *)ck
->auth_key
, vl_config
->md5_key
,
970 ospf_crypt_key_add(IF_DEF_PARAMS(ifp
)->auth_crypt
, ck
);
971 } else if (vl_config
->crypto_key_id
!= 0) {
974 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
975 vl_config
->crypto_key_id
)
977 vty_out(vty
, "OSPF: Key %d does not exist\n",
978 vl_config
->crypto_key_id
);
979 return CMD_WARNING_CONFIG_FAILED
;
982 ospf_crypt_key_delete(IF_DEF_PARAMS(ifp
)->auth_crypt
,
983 vl_config
->crypto_key_id
);
989 static int ospf_vl_set_timers(struct ospf_vl_data
*vl_data
,
990 struct ospf_vl_config_data
*vl_config
)
992 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
993 /* Virtual Link data initialised to defaults, so only set
995 if (vl_config
->hello_interval
) {
996 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_hello
);
997 IF_DEF_PARAMS(ifp
)->v_hello
= vl_config
->hello_interval
;
1000 if (vl_config
->dead_interval
) {
1001 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_wait
);
1002 IF_DEF_PARAMS(ifp
)->v_wait
= vl_config
->dead_interval
;
1005 if (vl_config
->retransmit_interval
) {
1006 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), retransmit_interval
);
1007 IF_DEF_PARAMS(ifp
)->retransmit_interval
=
1008 vl_config
->retransmit_interval
;
1011 if (vl_config
->transmit_delay
) {
1012 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), transmit_delay
);
1013 IF_DEF_PARAMS(ifp
)->transmit_delay
= vl_config
->transmit_delay
;
1020 /* The business end of all of the above */
1021 static int ospf_vl_set(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
1023 struct ospf_vl_data
*vl_data
;
1026 vl_data
= ospf_find_vl_data(ospf
, vl_config
);
1028 return CMD_WARNING_CONFIG_FAILED
;
1030 /* Process this one first as it can have a fatal result, which can
1031 only logically occur if the virtual link exists already
1032 Thus a command error does not result in a change to the
1033 running configuration such as unexpectedly altered timer
1035 ret
= ospf_vl_set_security(vl_data
, vl_config
);
1036 if (ret
!= CMD_SUCCESS
)
1039 /* Set any time based parameters, these area already range checked */
1041 ret
= ospf_vl_set_timers(vl_data
, vl_config
);
1042 if (ret
!= CMD_SUCCESS
)
1048 /* This stuff exists to make specifying all the alias commands A LOT simpler
1050 #define VLINK_HELPSTR_IPADDR \
1051 "OSPF area parameters\n" \
1052 "OSPF area ID in IP address format\n" \
1053 "OSPF area ID as a decimal value\n" \
1054 "Configure a virtual link\n" \
1055 "Router ID of the remote ABR\n"
1057 #define VLINK_HELPSTR_AUTHTYPE_SIMPLE \
1058 "Enable authentication on this virtual link\n" \
1061 #define VLINK_HELPSTR_AUTHTYPE_ALL \
1062 VLINK_HELPSTR_AUTHTYPE_SIMPLE \
1063 "Use null authentication\n" \
1064 "Use message-digest authentication\n"
1066 #define VLINK_HELPSTR_TIME_PARAM \
1067 "Time between HELLO packets\n" \
1069 "Time between retransmitting lost link state advertisements\n" \
1071 "Link state transmit delay\n" \
1073 "Interval time after which a neighbor is declared down\n" \
1076 #define VLINK_HELPSTR_AUTH_SIMPLE \
1077 "Authentication password (key)\n" \
1078 "The OSPF password (key)\n"
1080 #define VLINK_HELPSTR_AUTH_MD5 \
1081 "Message digest authentication password (key)\n" \
1083 "Use MD5 algorithm\n" \
1084 "The OSPF password (key)\n"
1086 DEFUN (ospf_area_vlink
,
1087 ospf_area_vlink_cmd
,
1088 "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>]",
1089 VLINK_HELPSTR_IPADDR
1090 "Enable authentication on this virtual link\n"
1091 "Use message-digest authentication\n"
1092 "Use null authentication\n"
1093 VLINK_HELPSTR_AUTH_MD5
1094 VLINK_HELPSTR_AUTH_SIMPLE
)
1096 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1097 int idx_ipv4_number
= 1;
1099 struct ospf_vl_config_data vl_config
;
1100 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1101 char md5_key
[OSPF_AUTH_MD5_SIZE
+ 1];
1105 ospf_vl_config_data_init(&vl_config
, vty
);
1107 /* Read off first 2 parameters and check them */
1108 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1109 &vl_config
.area_id_fmt
);
1111 vty_out(vty
, "OSPF area ID is invalid\n");
1112 return CMD_WARNING_CONFIG_FAILED
;
1115 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1117 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1118 return CMD_WARNING_CONFIG_FAILED
;
1122 /* Thats all folks! - BUGS B. strikes again!!!*/
1124 return ospf_vl_set(ospf
, &vl_config
);
1127 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1128 /* authentication - this option can only occur
1129 at start of command line */
1130 vl_config
.auth_type
= OSPF_AUTH_SIMPLE
;
1133 if (argv_find(argv
, argc
, "message-digest", &idx
)) {
1134 /* authentication message-digest */
1135 vl_config
.auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
1136 } else if (argv_find(argv
, argc
, "null", &idx
)) {
1137 /* "authentication null" */
1138 vl_config
.auth_type
= OSPF_AUTH_NULL
;
1141 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1142 vl_config
.md5_key
= NULL
;
1143 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1144 if (vl_config
.crypto_key_id
< 0)
1145 return CMD_WARNING_CONFIG_FAILED
;
1147 memset(md5_key
, 0, OSPF_AUTH_MD5_SIZE
+ 1);
1148 strncpy(md5_key
, argv
[idx
+ 3]->arg
, OSPF_AUTH_MD5_SIZE
);
1149 vl_config
.md5_key
= md5_key
;
1152 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1153 memset(auth_key
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
1154 strncpy(auth_key
, argv
[idx
+ 1]->arg
, OSPF_AUTH_SIMPLE_SIZE
);
1155 vl_config
.auth_key
= auth_key
;
1158 /* Action configuration */
1160 return ospf_vl_set(ospf
, &vl_config
);
1163 DEFUN (no_ospf_area_vlink
,
1164 no_ospf_area_vlink_cmd
,
1165 "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>]",
1167 VLINK_HELPSTR_IPADDR
1168 "Enable authentication on this virtual link\n" \
1169 "Use message-digest authentication\n" \
1170 "Use null authentication\n" \
1171 VLINK_HELPSTR_AUTH_MD5
1172 VLINK_HELPSTR_AUTH_SIMPLE
)
1174 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1175 int idx_ipv4_number
= 2;
1177 struct ospf_area
*area
;
1178 struct ospf_vl_config_data vl_config
;
1179 struct ospf_vl_data
*vl_data
= NULL
;
1180 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1184 ospf_vl_config_data_init(&vl_config
, vty
);
1186 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1189 vty_out(vty
, "OSPF area ID is invalid\n");
1190 return CMD_WARNING_CONFIG_FAILED
;
1193 area
= ospf_area_lookup_by_area_id(ospf
, vl_config
.area_id
);
1195 vty_out(vty
, "Area does not exist\n");
1196 return CMD_WARNING_CONFIG_FAILED
;
1199 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1201 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1202 return CMD_WARNING_CONFIG_FAILED
;
1206 /* Basic VLink no command */
1207 /* Thats all folks! - BUGS B. strikes again!!!*/
1208 if ((vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
.vl_peer
)))
1209 ospf_vl_delete(ospf
, vl_data
);
1211 ospf_area_check_free(ospf
, vl_config
.area_id
);
1216 /* If we are down here, we are reseting parameters */
1217 /* Deal with other parameters */
1219 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1220 /* authentication - this option can only occur
1221 at start of command line */
1222 vl_config
.auth_type
= OSPF_AUTH_NOTSET
;
1225 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1226 vl_config
.md5_key
= NULL
;
1227 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1228 if (vl_config
.crypto_key_id
< 0)
1229 return CMD_WARNING_CONFIG_FAILED
;
1232 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1233 /* Reset authentication-key to 0 */
1234 memset(auth_key
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
1235 vl_config
.auth_key
= auth_key
;
1238 /* Action configuration */
1240 return ospf_vl_set(ospf
, &vl_config
);
1243 DEFUN (ospf_area_vlink_intervals
,
1244 ospf_area_vlink_intervals_cmd
,
1245 "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)}",
1246 VLINK_HELPSTR_IPADDR
1247 VLINK_HELPSTR_TIME_PARAM
)
1249 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1250 struct ospf_vl_config_data vl_config
;
1253 ospf_vl_config_data_init(&vl_config
, vty
);
1255 char *area_id
= argv
[1]->arg
;
1256 char *router_id
= argv
[3]->arg
;
1258 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1260 vty_out(vty
, "OSPF area ID is invalid\n");
1261 return CMD_WARNING_CONFIG_FAILED
;
1264 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1266 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1267 return CMD_WARNING_CONFIG_FAILED
;
1270 for (int idx
= 4; idx
< argc
; idx
++) {
1271 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1272 vl_config
.hello_interval
=
1273 strtol(argv
[++idx
]->arg
, NULL
, 10);
1274 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1275 vl_config
.retransmit_interval
=
1276 strtol(argv
[++idx
]->arg
, NULL
, 10);
1277 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1278 vl_config
.transmit_delay
=
1279 strtol(argv
[++idx
]->arg
, NULL
, 10);
1280 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1281 vl_config
.dead_interval
=
1282 strtol(argv
[++idx
]->arg
, NULL
, 10);
1285 /* Action configuration */
1286 return ospf_vl_set(ospf
, &vl_config
);
1289 DEFUN (no_ospf_area_vlink_intervals
,
1290 no_ospf_area_vlink_intervals_cmd
,
1291 "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)}",
1293 VLINK_HELPSTR_IPADDR
1294 VLINK_HELPSTR_TIME_PARAM
)
1296 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1297 struct ospf_vl_config_data vl_config
;
1300 ospf_vl_config_data_init(&vl_config
, vty
);
1302 char *area_id
= argv
[2]->arg
;
1303 char *router_id
= argv
[4]->arg
;
1305 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1307 vty_out(vty
, "OSPF area ID is invalid\n");
1308 return CMD_WARNING_CONFIG_FAILED
;
1311 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1313 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1314 return CMD_WARNING_CONFIG_FAILED
;
1317 for (int idx
= 5; idx
< argc
; idx
++) {
1318 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1319 vl_config
.hello_interval
= OSPF_HELLO_INTERVAL_DEFAULT
;
1320 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1321 vl_config
.retransmit_interval
=
1322 OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
1323 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1324 vl_config
.transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
1325 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1326 vl_config
.dead_interval
=
1327 OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
1330 /* Action configuration */
1331 return ospf_vl_set(ospf
, &vl_config
);
1334 DEFUN (ospf_area_shortcut
,
1335 ospf_area_shortcut_cmd
,
1336 "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>",
1337 "OSPF area parameters\n"
1338 "OSPF area ID in IP address format\n"
1339 "OSPF area ID as a decimal value\n"
1340 "Configure the area's shortcutting mode\n"
1341 "Set default shortcutting behavior\n"
1342 "Enable shortcutting through the area\n"
1343 "Disable shortcutting through the area\n")
1345 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1346 int idx_ipv4_number
= 1;
1347 int idx_enable_disable
= 3;
1348 struct ospf_area
*area
;
1349 struct in_addr area_id
;
1353 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1354 argv
[idx_ipv4_number
]->arg
);
1356 area
= ospf_area_get(ospf
, area_id
);
1357 ospf_area_display_format_set(ospf
, area
, format
);
1359 if (strncmp(argv
[idx_enable_disable
]->arg
, "de", 2) == 0)
1360 mode
= OSPF_SHORTCUT_DEFAULT
;
1361 else if (strncmp(argv
[idx_enable_disable
]->arg
, "di", 2) == 0)
1362 mode
= OSPF_SHORTCUT_DISABLE
;
1363 else if (strncmp(argv
[idx_enable_disable
]->arg
, "e", 1) == 0)
1364 mode
= OSPF_SHORTCUT_ENABLE
;
1366 return CMD_WARNING_CONFIG_FAILED
;
1368 ospf_area_shortcut_set(ospf
, area
, mode
);
1370 if (ospf
->abr_type
!= OSPF_ABR_SHORTCUT
)
1372 "Shortcut area setting will take effect "
1373 "only when the router is configured as Shortcut ABR\n");
1378 DEFUN (no_ospf_area_shortcut
,
1379 no_ospf_area_shortcut_cmd
,
1380 "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>",
1382 "OSPF area parameters\n"
1383 "OSPF area ID in IP address format\n"
1384 "OSPF area ID as a decimal value\n"
1385 "Deconfigure the area's shortcutting mode\n"
1386 "Deconfigure enabled shortcutting through the area\n"
1387 "Deconfigure disabled shortcutting through the area\n")
1389 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1390 int idx_ipv4_number
= 2;
1391 struct ospf_area
*area
;
1392 struct in_addr area_id
;
1395 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1396 argv
[idx_ipv4_number
]->arg
);
1398 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1402 ospf_area_shortcut_unset(ospf
, area
);
1408 DEFUN (ospf_area_stub
,
1410 "area <A.B.C.D|(0-4294967295)> stub",
1411 "OSPF area parameters\n"
1412 "OSPF area ID in IP address format\n"
1413 "OSPF area ID as a decimal value\n"
1414 "Configure OSPF area as stub\n")
1416 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1417 int idx_ipv4_number
= 1;
1418 struct in_addr area_id
;
1421 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1422 argv
[idx_ipv4_number
]->arg
);
1424 ret
= ospf_area_stub_set(ospf
, area_id
);
1425 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1429 "First deconfigure all virtual link through this area\n");
1430 return CMD_WARNING_CONFIG_FAILED
;
1433 ospf_area_no_summary_unset(ospf
, area_id
);
1438 DEFUN (ospf_area_stub_no_summary
,
1439 ospf_area_stub_no_summary_cmd
,
1440 "area <A.B.C.D|(0-4294967295)> stub no-summary",
1441 "OSPF stub parameters\n"
1442 "OSPF area ID in IP address format\n"
1443 "OSPF area ID as a decimal value\n"
1444 "Configure OSPF area as stub\n"
1445 "Do not inject inter-area routes into stub\n")
1447 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1448 int idx_ipv4_number
= 1;
1449 struct in_addr area_id
;
1452 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1453 argv
[idx_ipv4_number
]->arg
);
1455 ret
= ospf_area_stub_set(ospf
, area_id
);
1456 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1460 "%% Area cannot be stub as it contains a virtual link\n");
1461 return CMD_WARNING_CONFIG_FAILED
;
1464 ospf_area_no_summary_set(ospf
, area_id
);
1469 DEFUN (no_ospf_area_stub
,
1470 no_ospf_area_stub_cmd
,
1471 "no area <A.B.C.D|(0-4294967295)> stub",
1473 "OSPF area parameters\n"
1474 "OSPF area ID in IP address format\n"
1475 "OSPF area ID as a decimal value\n"
1476 "Configure OSPF area as stub\n")
1478 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1479 int idx_ipv4_number
= 2;
1480 struct in_addr area_id
;
1483 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1484 argv
[idx_ipv4_number
]->arg
);
1486 ospf_area_stub_unset(ospf
, area_id
);
1487 ospf_area_no_summary_unset(ospf
, area_id
);
1492 DEFUN (no_ospf_area_stub_no_summary
,
1493 no_ospf_area_stub_no_summary_cmd
,
1494 "no area <A.B.C.D|(0-4294967295)> stub no-summary",
1496 "OSPF area parameters\n"
1497 "OSPF area ID in IP address format\n"
1498 "OSPF area ID as a decimal value\n"
1499 "Configure OSPF area as stub\n"
1500 "Do not inject inter-area routes into area\n")
1502 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1503 int idx_ipv4_number
= 2;
1504 struct in_addr area_id
;
1507 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1508 argv
[idx_ipv4_number
]->arg
);
1509 ospf_area_no_summary_unset(ospf
, area_id
);
1514 static int ospf_area_nssa_cmd_handler(struct vty
*vty
, int argc
,
1515 struct cmd_token
**argv
, int cfg_nosum
,
1518 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1519 struct in_addr area_id
;
1522 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
, argv
[1]->arg
);
1524 ret
= ospf_area_nssa_set(ospf
, area_id
);
1525 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1529 "%% Area cannot be nssa as it contains a virtual link\n");
1530 return CMD_WARNING_CONFIG_FAILED
;
1534 if (strncmp(argv
[3]->text
, "translate-c", 11) == 0)
1535 ospf_area_nssa_translator_role_set(
1536 ospf
, area_id
, OSPF_NSSA_ROLE_CANDIDATE
);
1537 else if (strncmp(argv
[3]->text
, "translate-n", 11) == 0)
1538 ospf_area_nssa_translator_role_set(
1539 ospf
, area_id
, OSPF_NSSA_ROLE_NEVER
);
1540 else if (strncmp(argv
[3]->text
, "translate-a", 11) == 0)
1541 ospf_area_nssa_translator_role_set(
1542 ospf
, area_id
, OSPF_NSSA_ROLE_ALWAYS
);
1544 ospf_area_nssa_translator_role_set(ospf
, area_id
,
1545 OSPF_NSSA_ROLE_CANDIDATE
);
1550 ospf_area_no_summary_set(ospf
, area_id
);
1552 ospf_area_no_summary_unset(ospf
, area_id
);
1555 ospf_schedule_abr_task(ospf
);
1561 DEFUN (ospf_area_nssa_translate
,
1562 ospf_area_nssa_translate_cmd
,
1563 "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always>",
1564 "OSPF area parameters\n"
1565 "OSPF area ID in IP address format\n"
1566 "OSPF area ID as a decimal value\n"
1567 "Configure OSPF area as nssa\n"
1568 "Configure NSSA-ABR for translate election (default)\n"
1569 "Configure NSSA-ABR to never translate\n"
1570 "Configure NSSA-ABR to always translate\n")
1572 return ospf_area_nssa_cmd_handler(vty
, argc
, argv
, 0, 0);
1575 DEFUN (ospf_area_nssa
,
1577 "area <A.B.C.D|(0-4294967295)> nssa",
1578 "OSPF area parameters\n"
1579 "OSPF area ID in IP address format\n"
1580 "OSPF area ID as a decimal value\n"
1581 "Configure OSPF area as nssa\n")
1583 return ospf_area_nssa_cmd_handler(vty
, argc
, argv
, 0, 0);
1586 DEFUN (ospf_area_nssa_no_summary
,
1587 ospf_area_nssa_no_summary_cmd
,
1588 "area <A.B.C.D|(0-4294967295)> nssa no-summary",
1589 "OSPF area parameters\n"
1590 "OSPF area ID in IP address format\n"
1591 "OSPF area ID as a decimal value\n"
1592 "Configure OSPF area as nssa\n"
1593 "Do not inject inter-area routes into nssa\n")
1595 int idx_ipv4_number
= 1;
1596 struct in_addr area_id
;
1599 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1600 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1601 argv
[idx_ipv4_number
]->arg
);
1603 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1605 ospf_area_nssa_no_summary_set(ospf
, area_id
);
1607 ospf_schedule_abr_task(ospf
);
1612 DEFUN (no_ospf_area_nssa_no_summary
,
1613 no_ospf_area_nssa_no_summary_cmd
,
1614 "no area <A.B.C.D|(0-4294967295)> nssa no-summary",
1616 "OSPF area parameters\n"
1617 "OSPF area ID in IP address format\n"
1618 "OSPF area ID as a decimal value\n"
1619 "Configure OSPF area as nssa\n"
1620 "Do not inject inter-area routes into nssa\n")
1622 int idx_ipv4_number
= 2;
1623 struct in_addr area_id
;
1626 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1628 VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id
, format
,
1629 argv
[idx_ipv4_number
]->arg
);
1631 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1633 ospf_area_no_summary_unset(ospf
, area_id
);
1635 ospf_schedule_abr_task(ospf
);
1640 DEFUN (no_ospf_area_nssa
,
1641 no_ospf_area_nssa_cmd
,
1642 "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always>]",
1644 "OSPF area parameters\n"
1645 "OSPF area ID in IP address format\n"
1646 "OSPF area ID as a decimal value\n"
1647 "Configure OSPF area as nssa\n"
1648 "Configure NSSA-ABR for translate election (default)\n"
1649 "Configure NSSA-ABR to never translate\n"
1650 "Configure NSSA-ABR to always translate\n")
1652 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1653 int idx_ipv4_number
= 2;
1654 struct in_addr area_id
;
1657 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1658 argv
[idx_ipv4_number
]->arg
);
1660 ospf_area_nssa_unset(ospf
, area_id
, argc
);
1662 ospf_schedule_abr_task(ospf
);
1668 DEFUN (ospf_area_default_cost
,
1669 ospf_area_default_cost_cmd
,
1670 "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1671 "OSPF area parameters\n"
1672 "OSPF area ID in IP address format\n"
1673 "OSPF area ID as a decimal value\n"
1674 "Set the summary-default cost of a NSSA or stub area\n"
1675 "Stub's advertised default summary cost\n")
1677 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1678 int idx_ipv4_number
= 1;
1680 struct ospf_area
*area
;
1681 struct in_addr area_id
;
1684 struct prefix_ipv4 p
;
1686 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1687 argv
[idx_ipv4_number
]->arg
);
1688 cost
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1690 area
= ospf_area_get(ospf
, area_id
);
1691 ospf_area_display_format_set(ospf
, area
, format
);
1693 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1694 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1695 return CMD_WARNING_CONFIG_FAILED
;
1698 area
->default_cost
= cost
;
1701 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1703 if (IS_DEBUG_OSPF_EVENT
)
1705 "ospf_abr_announce_stub_defaults(): "
1706 "announcing 0.0.0.0/0 to area %s",
1707 inet_ntoa(area
->area_id
));
1708 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1713 DEFUN (no_ospf_area_default_cost
,
1714 no_ospf_area_default_cost_cmd
,
1715 "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1717 "OSPF area parameters\n"
1718 "OSPF area ID in IP address format\n"
1719 "OSPF area ID as a decimal value\n"
1720 "Set the summary-default cost of a NSSA or stub area\n"
1721 "Stub's advertised default summary cost\n")
1723 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1724 int idx_ipv4_number
= 2;
1725 struct ospf_area
*area
;
1726 struct in_addr area_id
;
1728 struct prefix_ipv4 p
;
1730 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1731 argv
[idx_ipv4_number
]->arg
);
1733 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1737 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1738 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1739 return CMD_WARNING_CONFIG_FAILED
;
1742 area
->default_cost
= 1;
1745 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1747 if (IS_DEBUG_OSPF_EVENT
)
1749 "ospf_abr_announce_stub_defaults(): "
1750 "announcing 0.0.0.0/0 to area %s",
1751 inet_ntoa(area
->area_id
));
1752 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1755 ospf_area_check_free(ospf
, area_id
);
1760 DEFUN (ospf_area_export_list
,
1761 ospf_area_export_list_cmd
,
1762 "area <A.B.C.D|(0-4294967295)> export-list NAME",
1763 "OSPF area parameters\n"
1764 "OSPF area ID in IP address format\n"
1765 "OSPF area ID as a decimal value\n"
1766 "Set the filter for networks announced to other areas\n"
1767 "Name of the access-list\n")
1769 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1770 int idx_ipv4_number
= 1;
1771 struct ospf_area
*area
;
1772 struct in_addr area_id
;
1775 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1777 area
= ospf_area_get(ospf
, area_id
);
1778 ospf_area_display_format_set(ospf
, area
, format
);
1779 ospf_area_export_list_set(ospf
, area
, argv
[3]->arg
);
1784 DEFUN (no_ospf_area_export_list
,
1785 no_ospf_area_export_list_cmd
,
1786 "no area <A.B.C.D|(0-4294967295)> export-list NAME",
1788 "OSPF area parameters\n"
1789 "OSPF area ID in IP address format\n"
1790 "OSPF area ID as a decimal value\n"
1791 "Unset the filter for networks announced to other areas\n"
1792 "Name of the access-list\n")
1794 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1795 int idx_ipv4_number
= 2;
1796 struct ospf_area
*area
;
1797 struct in_addr area_id
;
1800 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1802 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1806 ospf_area_export_list_unset(ospf
, area
);
1812 DEFUN (ospf_area_import_list
,
1813 ospf_area_import_list_cmd
,
1814 "area <A.B.C.D|(0-4294967295)> import-list NAME",
1815 "OSPF area parameters\n"
1816 "OSPF area ID in IP address format\n"
1817 "OSPF area ID as a decimal value\n"
1818 "Set the filter for networks from other areas announced to the specified one\n"
1819 "Name of the access-list\n")
1821 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1822 int idx_ipv4_number
= 1;
1823 struct ospf_area
*area
;
1824 struct in_addr area_id
;
1827 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1829 area
= ospf_area_get(ospf
, area_id
);
1830 ospf_area_display_format_set(ospf
, area
, format
);
1831 ospf_area_import_list_set(ospf
, area
, argv
[3]->arg
);
1836 DEFUN (no_ospf_area_import_list
,
1837 no_ospf_area_import_list_cmd
,
1838 "no area <A.B.C.D|(0-4294967295)> import-list NAME",
1840 "OSPF area parameters\n"
1841 "OSPF area ID in IP address format\n"
1842 "OSPF area ID as a decimal value\n"
1843 "Unset the filter for networks announced to other areas\n"
1844 "Name of the access-list\n")
1846 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1847 int idx_ipv4_number
= 2;
1848 struct ospf_area
*area
;
1849 struct in_addr area_id
;
1852 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1854 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1858 ospf_area_import_list_unset(ospf
, area
);
1863 DEFUN (ospf_area_filter_list
,
1864 ospf_area_filter_list_cmd
,
1865 "area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>",
1866 "OSPF area parameters\n"
1867 "OSPF area ID in IP address format\n"
1868 "OSPF area ID as a decimal value\n"
1869 "Filter networks between OSPF areas\n"
1870 "Filter prefixes between OSPF areas\n"
1871 "Name of an IP prefix-list\n"
1872 "Filter networks sent to this area\n"
1873 "Filter networks sent from this area\n")
1875 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1876 int idx_ipv4_number
= 1;
1879 struct ospf_area
*area
;
1880 struct in_addr area_id
;
1881 struct prefix_list
*plist
;
1884 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1886 area
= ospf_area_get(ospf
, area_id
);
1887 ospf_area_display_format_set(ospf
, area
, format
);
1888 plist
= prefix_list_lookup(AFI_IP
, argv
[idx_word
]->arg
);
1889 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1890 PREFIX_LIST_IN(area
) = plist
;
1891 if (PREFIX_NAME_IN(area
))
1892 free(PREFIX_NAME_IN(area
));
1894 PREFIX_NAME_IN(area
) = strdup(argv
[idx_word
]->arg
);
1895 ospf_schedule_abr_task(ospf
);
1897 PREFIX_LIST_OUT(area
) = plist
;
1898 if (PREFIX_NAME_OUT(area
))
1899 free(PREFIX_NAME_OUT(area
));
1901 PREFIX_NAME_OUT(area
) = strdup(argv
[idx_word
]->arg
);
1902 ospf_schedule_abr_task(ospf
);
1908 DEFUN (no_ospf_area_filter_list
,
1909 no_ospf_area_filter_list_cmd
,
1910 "no area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>",
1912 "OSPF area parameters\n"
1913 "OSPF area ID in IP address format\n"
1914 "OSPF area ID as a decimal value\n"
1915 "Filter networks between OSPF areas\n"
1916 "Filter prefixes between OSPF areas\n"
1917 "Name of an IP prefix-list\n"
1918 "Filter networks sent to this area\n"
1919 "Filter networks sent from this area\n")
1921 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1922 int idx_ipv4_number
= 2;
1925 struct ospf_area
*area
;
1926 struct in_addr area_id
;
1929 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1931 if ((area
= ospf_area_lookup_by_area_id(ospf
, area_id
)) == NULL
)
1934 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1935 if (PREFIX_NAME_IN(area
))
1936 if (strcmp(PREFIX_NAME_IN(area
), argv
[idx_word
]->arg
)
1940 PREFIX_LIST_IN(area
) = NULL
;
1941 if (PREFIX_NAME_IN(area
))
1942 free(PREFIX_NAME_IN(area
));
1944 PREFIX_NAME_IN(area
) = NULL
;
1946 ospf_schedule_abr_task(ospf
);
1948 if (PREFIX_NAME_OUT(area
))
1949 if (strcmp(PREFIX_NAME_OUT(area
), argv
[idx_word
]->arg
)
1953 PREFIX_LIST_OUT(area
) = NULL
;
1954 if (PREFIX_NAME_OUT(area
))
1955 free(PREFIX_NAME_OUT(area
));
1957 PREFIX_NAME_OUT(area
) = NULL
;
1959 ospf_schedule_abr_task(ospf
);
1966 DEFUN (ospf_area_authentication_message_digest
,
1967 ospf_area_authentication_message_digest_cmd
,
1968 "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest",
1970 "OSPF area parameters\n"
1971 "OSPF area ID in IP address format\n"
1972 "OSPF area ID as a decimal value\n"
1973 "Enable authentication\n"
1974 "Use message-digest authentication\n")
1976 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1978 struct ospf_area
*area
;
1979 struct in_addr area_id
;
1982 argv_find(argv
, argc
, "area", &idx
);
1983 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx
+ 1]->arg
);
1985 area
= ospf_area_get(ospf
, area_id
);
1986 ospf_area_display_format_set(ospf
, area
, format
);
1987 area
->auth_type
= strmatch(argv
[0]->text
, "no")
1989 : OSPF_AUTH_CRYPTOGRAPHIC
;
1994 DEFUN (ospf_area_authentication
,
1995 ospf_area_authentication_cmd
,
1996 "area <A.B.C.D|(0-4294967295)> authentication",
1997 "OSPF area parameters\n"
1998 "OSPF area ID in IP address format\n"
1999 "OSPF area ID as a decimal value\n"
2000 "Enable authentication\n")
2002 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2003 int idx_ipv4_number
= 1;
2004 struct ospf_area
*area
;
2005 struct in_addr area_id
;
2008 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
2010 area
= ospf_area_get(ospf
, area_id
);
2011 ospf_area_display_format_set(ospf
, area
, format
);
2012 area
->auth_type
= OSPF_AUTH_SIMPLE
;
2017 DEFUN (no_ospf_area_authentication
,
2018 no_ospf_area_authentication_cmd
,
2019 "no area <A.B.C.D|(0-4294967295)> authentication",
2021 "OSPF area parameters\n"
2022 "OSPF area ID in IP address format\n"
2023 "OSPF area ID as a decimal value\n"
2024 "Enable authentication\n")
2026 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2027 int idx_ipv4_number
= 2;
2028 struct ospf_area
*area
;
2029 struct in_addr area_id
;
2032 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
2034 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
2038 area
->auth_type
= OSPF_AUTH_NULL
;
2040 ospf_area_check_free(ospf
, area_id
);
2046 DEFUN (ospf_abr_type
,
2048 "ospf abr-type <cisco|ibm|shortcut|standard>",
2049 "OSPF specific commands\n"
2050 "Set OSPF ABR type\n"
2051 "Alternative ABR, cisco implementation\n"
2052 "Alternative ABR, IBM implementation\n"
2054 "Standard behavior (RFC2328)\n")
2056 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2058 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2060 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2061 abr_type
= OSPF_ABR_CISCO
;
2062 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2063 abr_type
= OSPF_ABR_IBM
;
2064 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2065 abr_type
= OSPF_ABR_SHORTCUT
;
2066 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2067 abr_type
= OSPF_ABR_STAND
;
2069 return CMD_WARNING_CONFIG_FAILED
;
2071 /* If ABR type value is changed, schedule ABR task. */
2072 if (ospf
->abr_type
!= abr_type
) {
2073 ospf
->abr_type
= abr_type
;
2074 ospf_schedule_abr_task(ospf
);
2080 DEFUN (no_ospf_abr_type
,
2081 no_ospf_abr_type_cmd
,
2082 "no ospf abr-type <cisco|ibm|shortcut|standard>",
2084 "OSPF specific commands\n"
2085 "Set OSPF ABR type\n"
2086 "Alternative ABR, cisco implementation\n"
2087 "Alternative ABR, IBM implementation\n"
2091 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2093 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2095 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2096 abr_type
= OSPF_ABR_CISCO
;
2097 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2098 abr_type
= OSPF_ABR_IBM
;
2099 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2100 abr_type
= OSPF_ABR_SHORTCUT
;
2101 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2102 abr_type
= OSPF_ABR_STAND
;
2104 return CMD_WARNING_CONFIG_FAILED
;
2106 /* If ABR type value is changed, schedule ABR task. */
2107 if (ospf
->abr_type
== abr_type
) {
2108 ospf
->abr_type
= OSPF_ABR_DEFAULT
;
2109 ospf_schedule_abr_task(ospf
);
2115 DEFUN (ospf_log_adjacency_changes
,
2116 ospf_log_adjacency_changes_cmd
,
2117 "log-adjacency-changes",
2118 "Log changes in adjacency state\n")
2120 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2122 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2123 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2127 DEFUN (ospf_log_adjacency_changes_detail
,
2128 ospf_log_adjacency_changes_detail_cmd
,
2129 "log-adjacency-changes detail",
2130 "Log changes in adjacency state\n"
2131 "Log all state changes\n")
2133 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2135 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2136 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2140 DEFUN (no_ospf_log_adjacency_changes
,
2141 no_ospf_log_adjacency_changes_cmd
,
2142 "no log-adjacency-changes",
2144 "Log changes in adjacency state\n")
2146 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2148 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2149 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2153 DEFUN (no_ospf_log_adjacency_changes_detail
,
2154 no_ospf_log_adjacency_changes_detail_cmd
,
2155 "no log-adjacency-changes detail",
2157 "Log changes in adjacency state\n"
2158 "Log all state changes\n")
2160 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2162 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2166 DEFUN (ospf_compatible_rfc1583
,
2167 ospf_compatible_rfc1583_cmd
,
2168 "compatible rfc1583",
2169 "OSPF compatibility list\n"
2170 "compatible with RFC 1583\n")
2172 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2174 if (!CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2175 SET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2176 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2181 DEFUN (no_ospf_compatible_rfc1583
,
2182 no_ospf_compatible_rfc1583_cmd
,
2183 "no compatible rfc1583",
2185 "OSPF compatibility list\n"
2186 "compatible with RFC 1583\n")
2188 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2190 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2191 UNSET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2192 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2197 ALIAS(ospf_compatible_rfc1583
, ospf_rfc1583_flag_cmd
,
2198 "ospf rfc1583compatibility",
2199 "OSPF specific commands\n"
2200 "Enable the RFC1583Compatibility flag\n")
2202 ALIAS(no_ospf_compatible_rfc1583
, no_ospf_rfc1583_flag_cmd
,
2203 "no ospf rfc1583compatibility", NO_STR
2204 "OSPF specific commands\n"
2205 "Disable the RFC1583Compatibility flag\n")
2207 static int ospf_timers_spf_set(struct vty
*vty
, unsigned int delay
,
2208 unsigned int hold
, unsigned int max
)
2210 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2212 ospf
->spf_delay
= delay
;
2213 ospf
->spf_holdtime
= hold
;
2214 ospf
->spf_max_holdtime
= max
;
2219 DEFUN (ospf_timers_min_ls_interval
,
2220 ospf_timers_min_ls_interval_cmd
,
2221 "timers throttle lsa all (0-5000)",
2222 "Adjust routing timers\n"
2223 "Throttling adaptive timer\n"
2224 "LSA delay between transmissions\n"
2226 "Delay (msec) between sending LSAs\n")
2228 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2230 unsigned int interval
;
2233 vty_out(vty
, "Insufficient arguments\n");
2234 return CMD_WARNING_CONFIG_FAILED
;
2237 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2239 ospf
->min_ls_interval
= interval
;
2244 DEFUN (no_ospf_timers_min_ls_interval
,
2245 no_ospf_timers_min_ls_interval_cmd
,
2246 "no timers throttle lsa all [(0-5000)]",
2248 "Adjust routing timers\n"
2249 "Throttling adaptive timer\n"
2250 "LSA delay between transmissions\n"
2252 "Delay (msec) between sending LSAs\n")
2254 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2255 ospf
->min_ls_interval
= OSPF_MIN_LS_INTERVAL
;
2260 DEFUN (ospf_timers_throttle_spf
,
2261 ospf_timers_throttle_spf_cmd
,
2262 "timers throttle spf (0-600000) (0-600000) (0-600000)",
2263 "Adjust routing timers\n"
2264 "Throttling adaptive timer\n"
2266 "Delay (msec) from first change received till SPF calculation\n"
2267 "Initial hold time (msec) between consecutive SPF calculations\n"
2268 "Maximum hold time (msec)\n")
2271 int idx_number_2
= 4;
2272 int idx_number_3
= 5;
2273 unsigned int delay
, hold
, max
;
2276 vty_out(vty
, "Insufficient arguments\n");
2277 return CMD_WARNING_CONFIG_FAILED
;
2280 delay
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2281 hold
= strtoul(argv
[idx_number_2
]->arg
, NULL
, 10);
2282 max
= strtoul(argv
[idx_number_3
]->arg
, NULL
, 10);
2284 return ospf_timers_spf_set(vty
, delay
, hold
, max
);
2287 DEFUN (no_ospf_timers_throttle_spf
,
2288 no_ospf_timers_throttle_spf_cmd
,
2289 "no timers throttle spf [(0-600000)(0-600000)(0-600000)]",
2291 "Adjust routing timers\n"
2292 "Throttling adaptive timer\n"
2294 "Delay (msec) from first change received till SPF calculation\n"
2295 "Initial hold time (msec) between consecutive SPF calculations\n"
2296 "Maximum hold time (msec)\n")
2298 return ospf_timers_spf_set(vty
, OSPF_SPF_DELAY_DEFAULT
,
2299 OSPF_SPF_HOLDTIME_DEFAULT
,
2300 OSPF_SPF_MAX_HOLDTIME_DEFAULT
);
2304 DEFUN (ospf_timers_lsa_min_arrival
,
2305 ospf_timers_lsa_min_arrival_cmd
,
2306 "timers lsa min-arrival (0-600000)",
2307 "Adjust routing timers\n"
2309 "Minimum delay in receiving new version of a LSA\n"
2310 "Delay in milliseconds\n")
2312 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2313 ospf
->min_ls_arrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2317 DEFUN (no_ospf_timers_lsa_min_arrival
,
2318 no_ospf_timers_lsa_min_arrival_cmd
,
2319 "no timers lsa min-arrival [(0-600000)]",
2321 "Adjust routing timers\n"
2323 "Minimum delay in receiving new version of a LSA\n"
2324 "Delay in milliseconds\n")
2326 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2327 unsigned int minarrival
;
2330 minarrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2332 if (ospf
->min_ls_arrival
!= minarrival
2333 || minarrival
== OSPF_MIN_LS_ARRIVAL
)
2337 ospf
->min_ls_arrival
= OSPF_MIN_LS_ARRIVAL
;
2342 DEFUN (ospf_neighbor
,
2344 "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]",
2346 "Neighbor IP address\n"
2347 "Neighbor Priority\n"
2349 "Dead Neighbor Polling interval\n"
2352 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2356 struct in_addr nbr_addr
;
2357 unsigned int priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2358 unsigned int interval
= OSPF_POLL_INTERVAL_DEFAULT
;
2360 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2361 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2362 return CMD_WARNING_CONFIG_FAILED
;
2366 priority
= strtoul(argv
[idx_pri
]->arg
, NULL
, 10);
2369 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2371 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2374 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2377 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2382 DEFUN (ospf_neighbor_poll_interval
,
2383 ospf_neighbor_poll_interval_cmd
,
2384 "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2386 "Neighbor IP address\n"
2387 "Dead Neighbor Polling interval\n"
2389 "OSPF priority of non-broadcast neighbor\n"
2392 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2396 struct in_addr nbr_addr
;
2397 unsigned int priority
;
2398 unsigned int interval
;
2400 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2401 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2402 return CMD_WARNING_CONFIG_FAILED
;
2405 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2407 priority
= argc
> 4 ? strtoul(argv
[idx_pri
]->arg
, NULL
, 10)
2408 : OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2410 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2411 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2414 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2419 DEFUN (no_ospf_neighbor
,
2420 no_ospf_neighbor_cmd
,
2421 "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]",
2424 "Neighbor IP address\n"
2425 "Neighbor Priority\n"
2427 "Dead Neighbor Polling interval\n"
2430 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2432 struct in_addr nbr_addr
;
2434 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2435 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2436 return CMD_WARNING_CONFIG_FAILED
;
2439 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2444 DEFUN (no_ospf_neighbor_poll
,
2445 no_ospf_neighbor_poll_cmd
,
2446 "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2449 "Neighbor IP address\n"
2450 "Dead Neighbor Polling interval\n"
2452 "Neighbor Priority\n"
2455 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2457 struct in_addr nbr_addr
;
2459 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2460 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2461 return CMD_WARNING_CONFIG_FAILED
;
2464 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2469 DEFUN (ospf_refresh_timer
,
2470 ospf_refresh_timer_cmd
,
2471 "refresh timer (10-1800)",
2472 "Adjust refresh parameters\n"
2473 "Set refresh timer\n"
2474 "Timer value in seconds\n")
2476 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2478 unsigned int interval
;
2480 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2481 interval
= (interval
/ OSPF_LSA_REFRESHER_GRANULARITY
)
2482 * OSPF_LSA_REFRESHER_GRANULARITY
;
2484 ospf_timers_refresh_set(ospf
, interval
);
2489 DEFUN (no_ospf_refresh_timer
,
2490 no_ospf_refresh_timer_val_cmd
,
2491 "no refresh timer [(10-1800)]",
2493 "Adjust refresh parameters\n"
2494 "Unset refresh timer\n"
2495 "Timer value in seconds\n")
2497 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2499 unsigned int interval
;
2502 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2504 if (ospf
->lsa_refresh_interval
!= interval
2505 || interval
== OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
2509 ospf_timers_refresh_unset(ospf
);
2515 DEFUN (ospf_auto_cost_reference_bandwidth
,
2516 ospf_auto_cost_reference_bandwidth_cmd
,
2517 "auto-cost reference-bandwidth (1-4294967)",
2518 "Calculate OSPF interface cost according to bandwidth\n"
2519 "Use reference bandwidth method to assign OSPF cost\n"
2520 "The reference bandwidth in terms of Mbits per second\n")
2522 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2523 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2526 struct interface
*ifp
;
2528 refbw
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2529 if (refbw
< 1 || refbw
> 4294967) {
2530 vty_out(vty
, "reference-bandwidth value is invalid\n");
2531 return CMD_WARNING_CONFIG_FAILED
;
2534 /* If reference bandwidth is changed. */
2535 if ((refbw
) == ospf
->ref_bandwidth
)
2538 ospf
->ref_bandwidth
= refbw
;
2539 FOR_ALL_INTERFACES (vrf
, ifp
)
2540 ospf_if_recalculate_output_cost(ifp
);
2545 DEFUN (no_ospf_auto_cost_reference_bandwidth
,
2546 no_ospf_auto_cost_reference_bandwidth_cmd
,
2547 "no auto-cost reference-bandwidth [(1-4294967)]",
2549 "Calculate OSPF interface cost according to bandwidth\n"
2550 "Use reference bandwidth method to assign OSPF cost\n"
2551 "The reference bandwidth in terms of Mbits per second\n")
2553 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2554 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2555 struct interface
*ifp
;
2557 if (ospf
->ref_bandwidth
== OSPF_DEFAULT_REF_BANDWIDTH
)
2560 ospf
->ref_bandwidth
= OSPF_DEFAULT_REF_BANDWIDTH
;
2561 vty_out(vty
, "%% OSPF: Reference bandwidth is changed.\n");
2563 " Please ensure reference bandwidth is consistent across all routers\n");
2565 FOR_ALL_INTERFACES (vrf
, ifp
)
2566 ospf_if_recalculate_output_cost(ifp
);
2571 DEFUN (ospf_write_multiplier
,
2572 ospf_write_multiplier_cmd
,
2573 "ospf write-multiplier (1-100)",
2574 "OSPF specific commands\n"
2575 "Write multiplier\n"
2576 "Maximum number of interface serviced per write\n")
2578 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2580 uint32_t write_oi_count
;
2587 write_oi_count
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2588 if (write_oi_count
< 1 || write_oi_count
> 100) {
2589 vty_out(vty
, "write-multiplier value is invalid\n");
2590 return CMD_WARNING_CONFIG_FAILED
;
2593 ospf
->write_oi_count
= write_oi_count
;
2597 ALIAS(ospf_write_multiplier
, write_multiplier_cmd
, "write-multiplier (1-100)",
2598 "Write multiplier\n"
2599 "Maximum number of interface serviced per write\n")
2601 DEFUN (no_ospf_write_multiplier
,
2602 no_ospf_write_multiplier_cmd
,
2603 "no ospf write-multiplier (1-100)",
2605 "OSPF specific commands\n"
2606 "Write multiplier\n"
2607 "Maximum number of interface serviced per write\n")
2609 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2611 ospf
->write_oi_count
= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
;
2615 ALIAS(no_ospf_write_multiplier
, no_write_multiplier_cmd
,
2616 "no write-multiplier (1-100)", NO_STR
2617 "Write multiplier\n"
2618 "Maximum number of interface serviced per write\n")
2620 const char *ospf_abr_type_descr_str
[] = {"Unknown", "Standard (RFC2328)",
2621 "Alternative IBM", "Alternative Cisco",
2622 "Alternative Shortcut"};
2624 const char *ospf_shortcut_mode_descr_str
[] = {"Default", "Enabled", "Disabled"};
2626 static void show_ip_ospf_area(struct vty
*vty
, struct ospf_area
*area
,
2627 json_object
*json_areas
, bool use_json
)
2629 json_object
*json_area
= NULL
;
2632 json_area
= json_object_new_object();
2636 vty_out(vty
, " Area ID: %s", inet_ntoa(area
->area_id
));
2638 /* Show Area type/mode. */
2639 if (OSPF_IS_AREA_BACKBONE(area
)) {
2641 json_object_boolean_true_add(json_area
, "backbone");
2643 vty_out(vty
, " (Backbone)\n");
2646 if (area
->external_routing
== OSPF_AREA_STUB
) {
2647 if (area
->no_summary
)
2648 json_object_boolean_true_add(
2649 json_area
, "stubNoSummary");
2650 if (area
->shortcut_configured
)
2651 json_object_boolean_true_add(
2652 json_area
, "stubShortcut");
2653 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
2654 if (area
->no_summary
)
2655 json_object_boolean_true_add(
2656 json_area
, "nssaNoSummary");
2657 if (area
->shortcut_configured
)
2658 json_object_boolean_true_add(
2659 json_area
, "nssaShortcut");
2662 json_object_string_add(
2663 json_area
, "shortcuttingMode",
2664 ospf_shortcut_mode_descr_str
2665 [area
->shortcut_configured
]);
2666 if (area
->shortcut_capability
)
2667 json_object_boolean_true_add(json_area
,
2670 if (area
->external_routing
== OSPF_AREA_STUB
)
2671 vty_out(vty
, " (Stub%s%s)",
2672 area
->no_summary
? ", no summary" : "",
2673 area
->shortcut_configured
? "; " : "");
2674 else if (area
->external_routing
== OSPF_AREA_NSSA
)
2675 vty_out(vty
, " (NSSA%s%s)",
2676 area
->no_summary
? ", no summary" : "",
2677 area
->shortcut_configured
? "; " : "");
2680 vty_out(vty
, " Shortcutting mode: %s",
2681 ospf_shortcut_mode_descr_str
2682 [area
->shortcut_configured
]);
2683 vty_out(vty
, ", S-bit consensus: %s\n",
2684 area
->shortcut_capability
? "ok" : "no");
2688 /* Show number of interfaces */
2690 json_object_int_add(json_area
, "areaIfTotalCounter",
2691 listcount(area
->oiflist
));
2692 json_object_int_add(json_area
, "areaIfActiveCounter",
2696 " Number of interfaces in this area: Total: %d, "
2698 listcount(area
->oiflist
), area
->act_ints
);
2700 if (area
->external_routing
== OSPF_AREA_NSSA
) {
2702 json_object_boolean_true_add(json_area
, "nssa");
2703 if (!IS_OSPF_ABR(area
->ospf
))
2704 json_object_boolean_false_add(json_area
, "abr");
2705 else if (area
->NSSATranslatorState
) {
2706 json_object_boolean_true_add(json_area
, "abr");
2707 if (area
->NSSATranslatorRole
2708 == OSPF_NSSA_ROLE_CANDIDATE
)
2709 json_object_boolean_true_add(
2711 "nssaTranslatorElected");
2712 else if (area
->NSSATranslatorRole
2713 == OSPF_NSSA_ROLE_ALWAYS
)
2714 json_object_boolean_true_add(
2716 "nssaTranslatorAlways");
2718 json_object_boolean_true_add(json_area
, "abr");
2719 if (area
->NSSATranslatorRole
2720 == OSPF_NSSA_ROLE_CANDIDATE
)
2721 json_object_boolean_false_add(
2723 "nssaTranslatorElected");
2725 json_object_boolean_true_add(
2727 "nssaTranslatorNever");
2731 " It is an NSSA configuration. \n Elected NSSA/ABR performs type-7/type-5 LSA translation. \n");
2732 if (!IS_OSPF_ABR(area
->ospf
))
2734 " It is not ABR, therefore not Translator. \n");
2735 else if (area
->NSSATranslatorState
) {
2736 vty_out(vty
, " We are an ABR and ");
2737 if (area
->NSSATranslatorRole
2738 == OSPF_NSSA_ROLE_CANDIDATE
)
2740 "the NSSA Elected Translator. \n");
2741 else if (area
->NSSATranslatorRole
2742 == OSPF_NSSA_ROLE_ALWAYS
)
2744 "always an NSSA Translator. \n");
2746 vty_out(vty
, " We are an ABR, but ");
2747 if (area
->NSSATranslatorRole
2748 == OSPF_NSSA_ROLE_CANDIDATE
)
2750 "not the NSSA Elected Translator. \n");
2753 "never an NSSA Translator. \n");
2758 /* Stub-router state for this area */
2759 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
)) {
2760 char timebuf
[OSPF_TIME_DUMP_SIZE
];
2763 json_object_boolean_true_add(
2764 json_area
, "originStubMaxDistRouterLsa");
2765 if (CHECK_FLAG(area
->stub_router_state
,
2766 OSPF_AREA_ADMIN_STUB_ROUTED
))
2767 json_object_boolean_true_add(
2768 json_area
, "indefiniteActiveAdmin");
2769 if (area
->t_stub_router
) {
2773 &area
->t_stub_router
->u
.sands
,
2776 json_object_int_add(
2778 "activeStartupRemainderMsecs",
2783 " Originating stub / maximum-distance Router-LSA\n");
2784 if (CHECK_FLAG(area
->stub_router_state
,
2785 OSPF_AREA_ADMIN_STUB_ROUTED
))
2787 " Administratively activated (indefinitely)\n");
2788 if (area
->t_stub_router
)
2790 " Active from startup, %s remaining\n",
2791 ospf_timer_dump(area
->t_stub_router
,
2798 /* Show number of fully adjacent neighbors. */
2799 json_object_int_add(json_area
, "nbrFullAdjacentCounter",
2802 /* Show authentication type. */
2803 if (area
->auth_type
== OSPF_AUTH_NULL
)
2804 json_object_string_add(json_area
, "authentication",
2805 "authenticationNone");
2806 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2807 json_object_string_add(json_area
, "authentication",
2808 "authenticationSimplePassword");
2809 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2810 json_object_string_add(json_area
, "authentication",
2811 "authenticationMessageDigest");
2813 if (!OSPF_IS_AREA_BACKBONE(area
))
2814 json_object_int_add(json_area
,
2815 "virtualAdjacenciesPassingCounter",
2818 /* Show SPF calculation times. */
2819 json_object_int_add(json_area
, "spfExecutedCounter",
2820 area
->spf_calculation
);
2821 json_object_int_add(json_area
, "lsaNumber", area
->lsdb
->total
);
2822 json_object_int_add(
2823 json_area
, "lsaRouterNumber",
2824 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
));
2825 json_object_int_add(
2826 json_area
, "lsaRouterChecksum",
2827 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
2828 json_object_int_add(
2829 json_area
, "lsaNetworkNumber",
2830 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
));
2831 json_object_int_add(
2832 json_area
, "lsaNetworkChecksum",
2833 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
2834 json_object_int_add(
2835 json_area
, "lsaSummaryNumber",
2836 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
));
2837 json_object_int_add(
2838 json_area
, "lsaSummaryChecksum",
2839 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
2840 json_object_int_add(
2841 json_area
, "lsaAsbrNumber",
2842 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2843 json_object_int_add(
2844 json_area
, "lsaAsbrChecksum",
2845 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2846 json_object_int_add(
2847 json_area
, "lsaNssaNumber",
2848 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2849 json_object_int_add(
2850 json_area
, "lsaNssaChecksum",
2851 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2853 /* Show number of fully adjacent neighbors. */
2855 " Number of fully adjacent neighbors in this area:"
2859 /* Show authentication type. */
2860 vty_out(vty
, " Area has ");
2861 if (area
->auth_type
== OSPF_AUTH_NULL
)
2862 vty_out(vty
, "no authentication\n");
2863 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2864 vty_out(vty
, "simple password authentication\n");
2865 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2866 vty_out(vty
, "message digest authentication\n");
2868 if (!OSPF_IS_AREA_BACKBONE(area
))
2870 " Number of full virtual adjacencies going through"
2874 /* Show SPF calculation times. */
2875 vty_out(vty
, " SPF algorithm executed %d times\n",
2876 area
->spf_calculation
);
2878 /* Show number of LSA. */
2879 vty_out(vty
, " Number of LSA %ld\n", area
->lsdb
->total
);
2881 " Number of router LSA %ld. Checksum Sum 0x%08x\n",
2882 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
),
2883 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
2885 " Number of network LSA %ld. Checksum Sum 0x%08x\n",
2886 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
),
2887 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
2889 " Number of summary LSA %ld. Checksum Sum 0x%08x\n",
2890 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
),
2891 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
2893 " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n",
2894 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
),
2895 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2896 vty_out(vty
, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n",
2897 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
),
2898 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2902 json_object_int_add(
2903 json_area
, "lsaOpaqueLinkNumber",
2904 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
2905 json_object_int_add(
2906 json_area
, "lsaOpaqueLinkChecksum",
2907 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
2908 json_object_int_add(
2909 json_area
, "lsaOpaqueAreaNumber",
2910 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
2911 json_object_int_add(
2912 json_area
, "lsaOpaqueAreaChecksum",
2913 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
2916 " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n",
2917 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
),
2918 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
2920 " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n",
2921 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
),
2922 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
2926 json_object_object_add(json_areas
, inet_ntoa(area
->area_id
),
2932 static int show_ip_ospf_common(struct vty
*vty
, struct ospf
*ospf
,
2933 json_object
*json
, uint8_t use_vrf
)
2935 struct listnode
*node
, *nnode
;
2936 struct ospf_area
*area
;
2937 struct timeval result
;
2938 char timebuf
[OSPF_TIME_DUMP_SIZE
];
2939 json_object
*json_vrf
= NULL
;
2940 json_object
*json_areas
= NULL
;
2944 json_vrf
= json_object_new_object();
2947 json_areas
= json_object_new_object();
2950 if (ospf
->instance
) {
2952 json_object_int_add(json
, "ospfInstance",
2955 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
2959 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
2961 /* Show Router ID. */
2963 json_object_string_add(json_vrf
, "routerId",
2964 inet_ntoa(ospf
->router_id
));
2966 vty_out(vty
, " OSPF Routing Process, Router ID: %s\n",
2967 inet_ntoa(ospf
->router_id
));
2970 /* Graceful shutdown */
2971 if (ospf
->t_deferred_shutdown
) {
2976 &ospf
->t_deferred_shutdown
->u
.sands
,
2979 json_object_int_add(json_vrf
, "deferredShutdownMsecs",
2983 " Deferred shutdown in progress, %s remaining\n",
2984 ospf_timer_dump(ospf
->t_deferred_shutdown
,
2985 timebuf
, sizeof(timebuf
)));
2989 /* Show capability. */
2991 json_object_boolean_true_add(json_vrf
, "tosRoutesOnly");
2992 json_object_boolean_true_add(json_vrf
, "rfc2328Conform");
2993 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2994 json_object_boolean_true_add(json_vrf
,
2995 "rfc1583Compatibility");
2998 vty_out(vty
, " Supports only single TOS (TOS0) routes\n");
2999 vty_out(vty
, " This implementation conforms to RFC2328\n");
3000 vty_out(vty
, " RFC1583Compatibility flag is %s\n",
3001 CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)
3007 if (CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)) {
3008 json_object_boolean_true_add(json_vrf
, "opaqueCapable");
3011 vty_out(vty
, " OpaqueCapability flag is %s\n",
3012 CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)
3017 /* Show stub-router configuration */
3018 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
3019 || ospf
->stub_router_shutdown_time
3020 != OSPF_STUB_ROUTER_UNCONFIGURED
) {
3022 json_object_boolean_true_add(json_vrf
,
3023 "stubAdvertisement");
3024 if (ospf
->stub_router_startup_time
3025 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3026 json_object_int_add(
3027 json_vrf
, "postStartEnabledMsecs",
3028 ospf
->stub_router_startup_time
/ 1000);
3029 if (ospf
->stub_router_shutdown_time
3030 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3031 json_object_int_add(
3032 json_vrf
, "preShutdownEnabledMsecs",
3033 ospf
->stub_router_shutdown_time
/ 1000);
3036 " Stub router advertisement is configured\n");
3037 if (ospf
->stub_router_startup_time
3038 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3040 " Enabled for %us after start-up\n",
3041 ospf
->stub_router_startup_time
);
3042 if (ospf
->stub_router_shutdown_time
3043 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3045 " Enabled for %us prior to full shutdown\n",
3046 ospf
->stub_router_shutdown_time
);
3050 /* Show SPF timers. */
3052 json_object_int_add(json_vrf
, "spfScheduleDelayMsecs",
3054 json_object_int_add(json_vrf
, "holdtimeMinMsecs",
3055 ospf
->spf_holdtime
);
3056 json_object_int_add(json_vrf
, "holdtimeMaxMsecs",
3057 ospf
->spf_max_holdtime
);
3058 json_object_int_add(json_vrf
, "holdtimeMultplier",
3059 ospf
->spf_hold_multiplier
);
3062 " Initial SPF scheduling delay %d millisec(s)\n"
3063 " Minimum hold time between consecutive SPFs %d millisec(s)\n"
3064 " Maximum hold time between consecutive SPFs %d millisec(s)\n"
3065 " Hold time multiplier is currently %d\n",
3066 ospf
->spf_delay
, ospf
->spf_holdtime
,
3067 ospf
->spf_max_holdtime
, ospf
->spf_hold_multiplier
);
3071 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3072 long time_store
= 0;
3075 monotime_since(&ospf
->ts_spf
, NULL
) / 1000LL;
3076 json_object_int_add(json_vrf
, "spfLastExecutedMsecs",
3079 time_store
= (1000 * ospf
->ts_spf_duration
.tv_sec
)
3080 + (ospf
->ts_spf_duration
.tv_usec
/ 1000);
3081 json_object_int_add(json_vrf
, "spfLastDurationMsecs",
3084 json_object_boolean_true_add(json_vrf
, "spfHasNotRun");
3086 vty_out(vty
, " SPF algorithm ");
3087 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3088 monotime_since(&ospf
->ts_spf
, &result
);
3089 vty_out(vty
, "last executed %s ago\n",
3090 ospf_timeval_dump(&result
, timebuf
,
3092 vty_out(vty
, " Last SPF duration %s\n",
3093 ospf_timeval_dump(&ospf
->ts_spf_duration
,
3094 timebuf
, sizeof(timebuf
)));
3096 vty_out(vty
, "has not been run\n");
3100 if (ospf
->t_spf_calc
) {
3103 monotime_until(&ospf
->t_spf_calc
->u
.sands
, NULL
)
3105 json_object_int_add(json_vrf
, "spfTimerDueInMsecs",
3109 json_object_int_add(json_vrf
, "lsaMinIntervalMsecs",
3110 ospf
->min_ls_interval
);
3111 json_object_int_add(json_vrf
, "lsaMinArrivalMsecs",
3112 ospf
->min_ls_arrival
);
3113 /* Show write multiplier values */
3114 json_object_int_add(json_vrf
, "writeMultiplier",
3115 ospf
->write_oi_count
);
3116 /* Show refresh parameters. */
3117 json_object_int_add(json_vrf
, "refreshTimerMsecs",
3118 ospf
->lsa_refresh_interval
* 1000);
3120 vty_out(vty
, " SPF timer %s%s\n",
3121 (ospf
->t_spf_calc
? "due in " : "is "),
3122 ospf_timer_dump(ospf
->t_spf_calc
, timebuf
,
3125 vty_out(vty
, " LSA minimum interval %d msecs\n",
3126 ospf
->min_ls_interval
);
3127 vty_out(vty
, " LSA minimum arrival %d msecs\n",
3128 ospf
->min_ls_arrival
);
3130 /* Show write multiplier values */
3131 vty_out(vty
, " Write Multiplier set to %d \n",
3132 ospf
->write_oi_count
);
3134 /* Show refresh parameters. */
3135 vty_out(vty
, " Refresh timer %d secs\n",
3136 ospf
->lsa_refresh_interval
);
3139 /* Show ABR/ASBR flags. */
3140 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ABR
)) {
3142 json_object_string_add(
3143 json_vrf
, "abrType",
3144 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3147 " This router is an ABR, ABR type is: %s\n",
3148 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3150 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ASBR
)) {
3152 json_object_string_add(
3153 json_vrf
, "asbrRouter",
3154 "injectingExternalRoutingInformation");
3157 " This router is an ASBR "
3158 "(injecting external routing information)\n");
3161 /* Show Number of AS-external-LSAs. */
3163 json_object_int_add(
3164 json_vrf
, "lsaExternalCounter",
3165 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3166 json_object_int_add(
3167 json_vrf
, "lsaExternalChecksum",
3168 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3171 " Number of external LSA %ld. Checksum Sum 0x%08x\n",
3172 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
),
3173 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3177 json_object_int_add(
3178 json_vrf
, "lsaAsopaqueCounter",
3179 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3180 json_object_int_add(
3181 json_vrf
, "lsaAsOpaqueChecksum",
3182 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3185 " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n",
3186 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
),
3187 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3190 /* Show number of areas attached. */
3192 json_object_int_add(json_vrf
, "attachedAreaCounter",
3193 listcount(ospf
->areas
));
3195 vty_out(vty
, " Number of areas attached to this router: %d\n",
3196 listcount(ospf
->areas
));
3198 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
3199 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
)) {
3201 json_object_boolean_true_add(
3202 json_vrf
, "adjacencyChangesLoggedAll");
3205 " All adjacency changes are logged\n");
3208 json_object_boolean_true_add(
3209 json_vrf
, "adjacencyChangesLogged");
3211 vty_out(vty
, " Adjacency changes are logged\n");
3214 /* Show each area status. */
3215 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
3216 show_ip_ospf_area(vty
, area
, json_areas
, json
? 1 : 0);
3220 json_object_object_add(json_vrf
, "areas", json_areas
);
3221 if (ospf
->vrf_id
== VRF_DEFAULT
)
3222 json_object_object_add(json
, "default",
3225 json_object_object_add(json
, ospf
->name
,
3228 json_object_object_add(json
, "areas", json_areas
);
3236 DEFUN (show_ip_ospf
,
3238 "show ip ospf [vrf <NAME|all>] [json]",
3241 "OSPF information\n"
3247 bool uj
= use_json(argc
, argv
);
3248 struct listnode
*node
= NULL
;
3249 char *vrf_name
= NULL
;
3250 bool all_vrf
= FALSE
;
3251 int ret
= CMD_SUCCESS
;
3254 json_object
*json
= NULL
;
3255 uint8_t use_vrf
= 0;
3257 if (listcount(om
->ospf
) == 0)
3260 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
3263 json
= json_object_new_object();
3265 /* vrf input is provided could be all or specific vrf*/
3267 bool ospf_output
= FALSE
;
3272 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
3273 if (!ospf
->oi_running
)
3276 ret
= show_ip_ospf_common(vty
, ospf
, json
,
3280 vty_out(vty
, "%s\n",
3281 json_object_to_json_string_ext(
3282 json
, JSON_C_TO_STRING_PRETTY
));
3283 json_object_free(json
);
3284 } else if (!ospf_output
)
3285 vty_out(vty
, "%% OSPF instance not found\n");
3288 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
3289 if ((ospf
== NULL
) || !ospf
->oi_running
) {
3291 vty_out(vty
, "%s\n",
3292 json_object_to_json_string_ext(
3293 json
, JSON_C_TO_STRING_PRETTY
));
3294 json_object_free(json
);
3296 vty_out(vty
, "%% OSPF instance not found\n");
3301 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
3302 /* Display default ospf (instance 0) info */
3303 if (ospf
== NULL
|| !ospf
->oi_running
) {
3305 vty_out(vty
, "%s\n",
3306 json_object_to_json_string_ext(
3307 json
, JSON_C_TO_STRING_PRETTY
));
3308 json_object_free(json
);
3310 vty_out(vty
, "%% OSPF instance not found\n");
3317 show_ip_ospf_common(vty
, ospf
, json
, use_vrf
);
3319 vty_out(vty
, "%s\n",
3320 json_object_to_json_string_ext(
3321 json
, JSON_C_TO_STRING_PRETTY
));
3325 json_object_free(json
);
3330 DEFUN (show_ip_ospf_instance
,
3331 show_ip_ospf_instance_cmd
,
3332 "show ip ospf (1-65535) [json]",
3335 "OSPF information\n"
3341 unsigned short instance
= 0;
3342 bool uj
= use_json(argc
, argv
);
3343 int ret
= CMD_SUCCESS
;
3344 json_object
*json
= NULL
;
3346 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
3347 ospf
= ospf_lookup_instance(instance
);
3349 return CMD_NOT_MY_INSTANCE
;
3351 if (!ospf
->oi_running
)
3355 json
= json_object_new_object();
3357 ret
= show_ip_ospf_common(vty
, ospf
, json
, 0);
3360 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
3361 json
, JSON_C_TO_STRING_PRETTY
));
3362 json_object_free(json
);
3368 static void show_ip_ospf_interface_sub(struct vty
*vty
, struct ospf
*ospf
,
3369 struct interface
*ifp
,
3370 json_object
*json_interface_sub
,
3374 struct ospf_neighbor
*nbr
;
3375 struct route_node
*rn
;
3376 uint32_t bandwidth
= ifp
->bandwidth
? ifp
->bandwidth
: ifp
->speed
;
3378 /* Is interface up? */
3380 is_up
= if_is_operative(ifp
);
3382 json_object_boolean_true_add(json_interface_sub
,
3385 json_object_boolean_false_add(json_interface_sub
,
3388 json_object_int_add(json_interface_sub
, "ifIndex",
3390 json_object_int_add(json_interface_sub
, "mtuBytes", ifp
->mtu
);
3391 json_object_int_add(json_interface_sub
, "bandwidthMbit",
3393 json_object_string_add(json_interface_sub
, "ifFlags",
3394 if_flag_dump(ifp
->flags
));
3396 vty_out(vty
, "%s is %s\n", ifp
->name
,
3397 ((is_up
= if_is_operative(ifp
)) ? "up" : "down"));
3398 vty_out(vty
, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n",
3399 ifp
->ifindex
, ifp
->mtu
, bandwidth
,
3400 if_flag_dump(ifp
->flags
));
3403 /* Is interface OSPF enabled? */
3405 if (ospf_oi_count(ifp
) == 0) {
3406 json_object_boolean_false_add(json_interface_sub
,
3409 } else if (!is_up
) {
3410 json_object_boolean_false_add(json_interface_sub
,
3414 json_object_boolean_true_add(json_interface_sub
,
3417 if (ospf_oi_count(ifp
) == 0) {
3418 vty_out(vty
, " OSPF not enabled on this interface\n");
3420 } else if (!is_up
) {
3422 " OSPF is enabled, but not running on this interface\n");
3427 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
3428 struct ospf_interface
*oi
= rn
->info
;
3433 if (CHECK_FLAG(oi
->connected
->flags
, ZEBRA_IFA_UNNUMBERED
)) {
3435 json_object_boolean_true_add(json_interface_sub
,
3438 vty_out(vty
, " This interface is UNNUMBERED,");
3440 /* Show OSPF interface information. */
3442 json_object_string_add(
3443 json_interface_sub
, "ipAddress",
3444 inet_ntoa(oi
->address
->u
.prefix4
));
3445 json_object_int_add(json_interface_sub
,
3446 "ipAddressPrefixlen",
3447 oi
->address
->prefixlen
);
3449 vty_out(vty
, " Internet Address %s/%d,",
3450 inet_ntoa(oi
->address
->u
.prefix4
),
3451 oi
->address
->prefixlen
);
3453 if (oi
->connected
->destination
3454 || oi
->type
== OSPF_IFTYPE_VIRTUALLINK
) {
3455 struct in_addr
*dest
;
3458 if (CONNECTED_PEER(oi
->connected
)
3459 || oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3464 /* For Vlinks, showing the peer address is
3466 * * * * * informative than the local
3467 * interface that is being used
3469 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3470 dest
= &oi
->vl_data
->peer_addr
;
3472 dest
= &oi
->connected
->destination
->u
3476 json_object_string_add(
3478 "ospfIfType", dstr
);
3479 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3480 json_object_string_add(
3485 json_object_string_add(
3490 vty_out(vty
, " %s %s,", dstr
,
3495 json_object_string_add(json_interface_sub
, "area",
3496 ospf_area_desc_string(oi
->area
));
3497 if (OSPF_IF_PARAM(oi
, mtu_ignore
))
3498 json_object_boolean_true_add(
3500 "mtuMismatchDetect");
3501 json_object_string_add(json_interface_sub
, "routerId",
3502 inet_ntoa(ospf
->router_id
));
3503 json_object_string_add(json_interface_sub
,
3505 ospf_network_type_str
[oi
->type
]);
3506 json_object_int_add(json_interface_sub
, "cost",
3508 json_object_int_add(
3509 json_interface_sub
, "transmitDelayMsecs",
3510 1000 / OSPF_IF_PARAM(oi
, transmit_delay
));
3511 json_object_string_add(json_interface_sub
, "state",
3512 lookup_msg(ospf_ism_state_msg
,
3514 json_object_int_add(json_interface_sub
, "priority",
3517 vty_out(vty
, " Area %s\n",
3518 ospf_area_desc_string(oi
->area
));
3520 vty_out(vty
, " MTU mismatch detection: %s\n",
3521 OSPF_IF_PARAM(oi
, mtu_ignore
) ? "disabled"
3525 " Router ID %s, Network Type %s, Cost: %d\n",
3526 inet_ntoa(ospf
->router_id
),
3527 ospf_network_type_str
[oi
->type
],
3531 " Transmit Delay is %d sec, State %s, Priority %d\n",
3532 OSPF_IF_PARAM(oi
, transmit_delay
),
3533 lookup_msg(ospf_ism_state_msg
, oi
->state
, NULL
),
3537 /* Show DR information. */
3538 if (DR(oi
).s_addr
== 0) {
3541 " No backup designated router on this network\n");
3543 nbr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &BDR(oi
));
3547 " No backup designated router on this network\n");
3550 json_object_string_add(
3551 json_interface_sub
, "bdrId",
3552 inet_ntoa(nbr
->router_id
));
3553 json_object_string_add(
3556 inet_ntoa(nbr
->address
.u
3560 " Backup Designated Router (ID) %s,",
3561 inet_ntoa(nbr
->router_id
));
3562 vty_out(vty
, " Interface Address %s\n",
3563 inet_ntoa(nbr
->address
.u
3569 /* Next network-LSA sequence number we'll use, if we're elected
3572 && ntohl(oi
->params
->network_lsa_seqnum
)
3573 != OSPF_INITIAL_SEQUENCE_NUMBER
) {
3575 json_object_int_add(
3577 "networkLsaSequence",
3578 ntohl(oi
->params
->network_lsa_seqnum
));
3581 " Saved Network-LSA sequence number 0x%x\n",
3582 ntohl(oi
->params
->network_lsa_seqnum
));
3586 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3587 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3588 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3589 json_object_boolean_true_add(
3591 "mcastMemberOspfAllRouters");
3592 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3593 json_object_boolean_true_add(
3595 "mcastMemberOspfDesignatedRouters");
3598 vty_out(vty
, " Multicast group memberships:");
3599 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3600 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3601 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3602 vty_out(vty
, " OSPFAllRouters");
3603 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3604 vty_out(vty
, " OSPFDesignatedRouters");
3606 vty_out(vty
, " <None>");
3611 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3612 json_object_int_add(
3613 json_interface_sub
, "timerMsecs",
3614 1000 / OSPF_IF_PARAM(oi
, v_hello
));
3616 json_object_int_add(
3617 json_interface_sub
, "timerMsecs",
3618 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3619 json_object_int_add(json_interface_sub
,
3621 1000 / OSPF_IF_PARAM(oi
, v_wait
));
3622 json_object_int_add(json_interface_sub
,
3624 1000 / OSPF_IF_PARAM(oi
, v_wait
));
3625 json_object_int_add(
3626 json_interface_sub
, "timerRetransmit",
3627 1000 / OSPF_IF_PARAM(oi
, retransmit_interval
));
3629 vty_out(vty
, " Timer intervals configured,");
3630 vty_out(vty
, " Hello ");
3631 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3632 vty_out(vty
, "%ds,",
3633 OSPF_IF_PARAM(oi
, v_hello
));
3635 vty_out(vty
, "%dms,",
3636 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3637 vty_out(vty
, " Dead %ds, Wait %ds, Retransmit %d\n",
3638 OSPF_IF_PARAM(oi
, v_wait
),
3639 OSPF_IF_PARAM(oi
, v_wait
),
3640 OSPF_IF_PARAM(oi
, retransmit_interval
));
3643 if (OSPF_IF_PASSIVE_STATUS(oi
) == OSPF_IF_ACTIVE
) {
3644 char timebuf
[OSPF_TIME_DUMP_SIZE
];
3646 long time_store
= 0;
3650 &oi
->t_hello
->u
.sands
,
3653 json_object_int_add(json_interface_sub
,
3654 "timerHelloInMsecs",
3657 vty_out(vty
, " Hello due in %s\n",
3658 ospf_timer_dump(oi
->t_hello
, timebuf
,
3660 } else /* passive-interface is set */
3663 json_object_boolean_true_add(
3665 "timerPassiveIface");
3668 " No Hellos (Passive interface)\n");
3672 json_object_int_add(json_interface_sub
, "nbrCount",
3673 ospf_nbr_count(oi
, 0));
3674 json_object_int_add(json_interface_sub
,
3676 ospf_nbr_count(oi
, NSM_Full
));
3679 " Neighbor Count is %d, Adjacent neighbor count is %d\n",
3680 ospf_nbr_count(oi
, 0),
3681 ospf_nbr_count(oi
, NSM_Full
));
3682 ospf_bfd_interface_show(vty
, ifp
, json_interface_sub
, use_json
);
3686 static int show_ip_ospf_interface_common(struct vty
*vty
, struct ospf
*ospf
,
3687 char *intf_name
, uint8_t use_vrf
,
3688 json_object
*json
, bool use_json
)
3690 struct interface
*ifp
;
3691 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
3692 json_object
*json_vrf
= NULL
;
3693 json_object
*json_interface_sub
= NULL
, *json_interface
= NULL
;
3697 json_vrf
= json_object_new_object();
3700 json_interface
= json_object_new_object();
3703 if (ospf
->instance
) {
3705 json_object_int_add(json
, "ospfInstance",
3708 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
3711 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3713 if (intf_name
== NULL
) {
3714 /* Show All Interfaces.*/
3715 FOR_ALL_INTERFACES (vrf
, ifp
) {
3716 if (ospf_oi_count(ifp
)) {
3718 json_interface_sub
=
3719 json_object_new_object();
3721 show_ip_ospf_interface_sub(vty
, ospf
, ifp
,
3726 json_object_object_add(
3727 json_interface
, ifp
->name
,
3728 json_interface_sub
);
3733 json_object_object_add(json_vrf
, "interfaces",
3736 /* Interface name is specified. */
3737 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
3740 json_object_boolean_true_add(json_vrf
,
3743 vty_out(vty
, "No such interface name\n");
3746 json_interface_sub
= json_object_new_object();
3747 json_interface
= json_object_new_object();
3750 show_ip_ospf_interface_sub(
3751 vty
, ospf
, ifp
, json_interface_sub
, use_json
);
3754 json_object_object_add(json_interface
,
3756 json_interface_sub
);
3757 json_object_object_add(json_vrf
, "interfaces",
3765 if (ospf
->vrf_id
== VRF_DEFAULT
)
3766 json_object_object_add(json
, "default",
3769 json_object_object_add(json
, ospf
->name
,
3778 static void show_ip_ospf_interface_traffic_sub(struct vty
*vty
,
3779 struct ospf_interface
*oi
,
3780 json_object
*json_interface_sub
,
3784 json_object_int_add(json_interface_sub
, "ifIndex",
3786 json_object_int_add(json_interface_sub
, "helloIn",
3788 json_object_int_add(json_interface_sub
, "helloOut",
3790 json_object_int_add(json_interface_sub
, "dbDescIn",
3792 json_object_int_add(json_interface_sub
, "dbDescOut",
3794 json_object_int_add(json_interface_sub
, "lsReqIn",
3796 json_object_int_add(json_interface_sub
, "lsReqOut",
3798 json_object_int_add(json_interface_sub
, "lsUpdIn",
3800 json_object_int_add(json_interface_sub
, "lsUpdOut",
3802 json_object_int_add(json_interface_sub
, "lsAckIn",
3804 json_object_int_add(json_interface_sub
, "lsAckOut",
3808 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n",
3809 oi
->ifp
->name
, oi
->hello_in
, oi
->hello_out
,
3810 oi
->db_desc_in
, oi
->db_desc_out
, oi
->ls_req_in
,
3811 oi
->ls_req_out
, oi
->ls_upd_in
, oi
->ls_upd_out
,
3812 oi
->ls_ack_in
, oi
->ls_ack_out
);
3816 /* OSPFv2 Packet Counters */
3817 static int show_ip_ospf_interface_traffic_common(
3818 struct vty
*vty
, struct ospf
*ospf
, char *intf_name
, json_object
*json
,
3819 int display_once
, uint8_t use_vrf
, bool use_json
)
3821 struct vrf
*vrf
= NULL
;
3822 struct interface
*ifp
= NULL
;
3823 json_object
*json_vrf
= NULL
;
3824 json_object
*json_interface_sub
= NULL
;
3826 if (!use_json
&& !display_once
) {
3828 vty_out(vty
, "%-12s%-17s%-17s%-17s%-17s%-17s\n", "Interface",
3829 " HELLO", " DB-Desc", " LS-Req", " LS-Update",
3831 vty_out(vty
, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "",
3832 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
3835 "--------------------------------------------------------------------------------------------\n");
3836 } else if (use_json
) {
3838 json_vrf
= json_object_new_object();
3843 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3845 if (intf_name
== NULL
) {
3846 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
3847 FOR_ALL_INTERFACES (vrf
, ifp
) {
3848 struct route_node
*rn
;
3849 struct ospf_interface
*oi
;
3851 if (ospf_oi_count(ifp
) == 0)
3854 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
3855 rn
= route_next(rn
)) {
3862 json_interface_sub
=
3863 json_object_new_object();
3866 show_ip_ospf_interface_traffic_sub(
3867 vty
, oi
, json_interface_sub
, use_json
);
3869 json_object_object_add(
3870 json_vrf
, ifp
->name
,
3871 json_interface_sub
);
3876 /* Interface name is specified. */
3877 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
3879 struct route_node
*rn
;
3880 struct ospf_interface
*oi
;
3882 if (ospf_oi_count(ifp
) == 0) {
3884 " OSPF not enabled on this interface %s\n",
3889 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
3890 rn
= route_next(rn
)) {
3894 json_interface_sub
=
3895 json_object_new_object();
3898 show_ip_ospf_interface_traffic_sub(
3899 vty
, oi
, json_interface_sub
, use_json
);
3901 json_object_object_add(
3902 json_vrf
, ifp
->name
,
3903 json_interface_sub
);
3911 if (ospf
->vrf_id
== VRF_DEFAULT
)
3912 json_object_object_add(json
, "default",
3915 json_object_object_add(json
, ospf
->name
,
3924 DEFUN (show_ip_ospf_interface
,
3925 show_ip_ospf_interface_cmd
,
3926 "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]",
3929 "OSPF information\n"
3932 "Interface information\n"
3937 bool uj
= use_json(argc
, argv
);
3938 struct listnode
*node
= NULL
;
3939 char *vrf_name
= NULL
, *intf_name
= NULL
;
3940 bool all_vrf
= FALSE
;
3941 int ret
= CMD_SUCCESS
;
3943 int idx_vrf
= 0, idx_intf
= 0;
3944 uint8_t use_vrf
= 0;
3945 json_object
*json
= NULL
;
3947 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
3949 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
3950 intf_name
= argv
[idx_intf
]->arg
;
3953 json
= json_object_new_object();
3955 /* vrf input is provided could be all or specific vrf*/
3959 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
3960 if (!ospf
->oi_running
)
3962 ret
= show_ip_ospf_interface_common(
3963 vty
, ospf
, intf_name
, use_vrf
, json
,
3968 vty_out(vty
, "%s\n",
3969 json_object_to_json_string_ext(
3970 json
, JSON_C_TO_STRING_PRETTY
));
3971 json_object_free(json
);
3973 vty_out(vty
, "%% OSPF instance not found\n");
3977 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
3978 if (ospf
== NULL
|| !ospf
->oi_running
) {
3980 vty_out(vty
, "%s\n",
3981 json_object_to_json_string_ext(
3982 json
, JSON_C_TO_STRING_PRETTY
));
3983 json_object_free(json
);
3985 vty_out(vty
, "%% OSPF instance not found\n");
3989 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
3993 /* Display default ospf (instance 0) info */
3994 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
3995 if (ospf
== NULL
|| !ospf
->oi_running
) {
3997 vty_out(vty
, "%s\n",
3998 json_object_to_json_string_ext(
3999 json
, JSON_C_TO_STRING_PRETTY
));
4000 json_object_free(json
);
4002 vty_out(vty
, "%% OSPF instance not found\n");
4006 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
4011 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4012 json
, JSON_C_TO_STRING_PRETTY
));
4013 json_object_free(json
);
4019 DEFUN (show_ip_ospf_instance_interface
,
4020 show_ip_ospf_instance_interface_cmd
,
4021 "show ip ospf (1-65535) interface [INTERFACE] [json]",
4024 "OSPF information\n"
4026 "Interface information\n"
4033 unsigned short instance
= 0;
4034 bool uj
= use_json(argc
, argv
);
4035 char *intf_name
= NULL
;
4036 int ret
= CMD_SUCCESS
;
4037 json_object
*json
= NULL
;
4039 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4040 ospf
= ospf_lookup_instance(instance
);
4042 return CMD_NOT_MY_INSTANCE
;
4044 if (!ospf
->oi_running
)
4048 json
= json_object_new_object();
4050 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4051 intf_name
= argv
[idx_intf
]->arg
;
4053 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
, 0, json
, uj
);
4056 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4057 json
, JSON_C_TO_STRING_PRETTY
));
4058 json_object_free(json
);
4064 DEFUN (show_ip_ospf_interface_traffic
,
4065 show_ip_ospf_interface_traffic_cmd
,
4066 "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]",
4069 "OSPF information\n"
4072 "Interface information\n"
4073 "Protocol Packet counters\n"
4077 struct ospf
*ospf
= NULL
;
4078 struct listnode
*node
= NULL
;
4079 char *vrf_name
= NULL
, *intf_name
= NULL
;
4080 bool all_vrf
= FALSE
;
4082 int idx_vrf
= 0, idx_intf
= 0;
4083 bool uj
= use_json(argc
, argv
);
4084 json_object
*json
= NULL
;
4085 int ret
= CMD_SUCCESS
;
4086 int display_once
= 0;
4087 uint8_t use_vrf
= 0;
4089 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4091 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4092 intf_name
= argv
[idx_intf
]->arg
;
4095 json
= json_object_new_object();
4100 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4101 if (!ospf
->oi_running
)
4104 ret
= show_ip_ospf_interface_traffic_common(
4105 vty
, ospf
, intf_name
, json
,
4106 display_once
, use_vrf
, uj
);
4111 vty_out(vty
, "%s\n",
4112 json_object_to_json_string_ext(
4113 json
, JSON_C_TO_STRING_PRETTY
));
4114 json_object_free(json
);
4119 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4120 if (ospf
== NULL
|| !ospf
->oi_running
) {
4122 json_object_free(json
);
4126 ret
= show_ip_ospf_interface_traffic_common(
4127 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4129 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4130 if (ospf
== NULL
|| !ospf
->oi_running
) {
4132 json_object_free(json
);
4136 ret
= show_ip_ospf_interface_traffic_common(
4137 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4141 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4142 json
, JSON_C_TO_STRING_PRETTY
));
4143 json_object_free(json
);
4150 static void show_ip_ospf_neighbour_header(struct vty
*vty
)
4152 vty_out(vty
, "\n%-15s %3s %-15s %9s %-15s %-20s %5s %5s %5s\n",
4153 "Neighbor ID", "Pri", "State", "Dead Time", "Address",
4154 "Interface", "RXmtL", "RqstL", "DBsmL");
4157 static void show_ip_ospf_neighbor_sub(struct vty
*vty
,
4158 struct ospf_interface
*oi
,
4159 json_object
*json
, bool use_json
)
4161 struct route_node
*rn
;
4162 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
4164 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4165 json_object
*json_neighbor
= NULL
, *json_neigh_array
= NULL
;
4167 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
4168 if ((nbr
= rn
->info
)) {
4169 /* Do not show myself. */
4170 if (nbr
== oi
->nbr_self
)
4172 /* Down state is not shown. */
4173 if (nbr
->state
== NSM_Down
)
4176 char neigh_str
[INET_ADDRSTRLEN
];
4179 && !IPV4_ADDR_SAME(&prev_nbr
->src
,
4181 /* Start new neigh list */
4182 json_neigh_array
= NULL
;
4185 if (nbr
->state
== NSM_Attempt
4186 && nbr
->router_id
.s_addr
== 0)
4187 strlcpy(neigh_str
, "neighbor",
4191 inet_ntoa(nbr
->router_id
),
4194 json_object_object_get_ex(json
, neigh_str
,
4197 if (!json_neigh_array
) {
4199 json_object_new_array();
4200 json_object_object_add(
4205 json_neighbor
= json_object_new_object();
4207 ospf_nbr_state_message(nbr
, msgbuf
, 16);
4213 &nbr
->t_inactivity
->u
.sands
,
4217 json_object_int_add(json_neighbor
, "priority",
4219 json_object_string_add(json_neighbor
, "state",
4221 json_object_int_add(json_neighbor
,
4224 json_object_string_add(json_neighbor
, "address",
4225 inet_ntoa(nbr
->src
));
4226 json_object_string_add(json_neighbor
,
4229 json_object_int_add(
4230 json_neighbor
, "retransmitCounter",
4231 ospf_ls_retransmit_count(nbr
));
4232 json_object_int_add(json_neighbor
,
4234 ospf_ls_request_count(nbr
));
4235 json_object_int_add(json_neighbor
,
4237 ospf_db_summary_count(nbr
));
4239 json_object_array_add(json_neigh_array
,
4242 ospf_nbr_state_message(nbr
, msgbuf
, 16);
4244 if (nbr
->state
== NSM_Attempt
4245 && nbr
->router_id
.s_addr
== 0)
4246 vty_out(vty
, "%-15s %3d %-15s ", "-",
4247 nbr
->priority
, msgbuf
);
4249 vty_out(vty
, "%-15s %3d %-15s ",
4250 inet_ntoa(nbr
->router_id
),
4251 nbr
->priority
, msgbuf
);
4253 vty_out(vty
, "%9s ",
4254 ospf_timer_dump(nbr
->t_inactivity
,
4257 vty_out(vty
, "%-15s ", inet_ntoa(nbr
->src
));
4258 vty_out(vty
, "%-20s %5ld %5ld %5d\n",
4260 ospf_ls_retransmit_count(nbr
),
4261 ospf_ls_request_count(nbr
),
4262 ospf_db_summary_count(nbr
));
4269 static int show_ip_ospf_neighbor_common(struct vty
*vty
, struct ospf
*ospf
,
4270 json_object
*json
, bool use_json
,
4273 struct ospf_interface
*oi
;
4274 struct listnode
*node
;
4275 json_object
*json_vrf
= NULL
;
4276 json_object
*json_nbr_sub
= NULL
;
4280 json_vrf
= json_object_new_object();
4283 json_nbr_sub
= json_object_new_object();
4286 if (ospf
->instance
) {
4288 json_object_int_add(json
, "ospfInstance",
4291 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4294 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4296 show_ip_ospf_neighbour_header(vty
);
4298 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4299 if (ospf_interface_neighbor_count(oi
) == 0)
4301 show_ip_ospf_neighbor_sub(vty
, oi
, json_nbr_sub
, use_json
);
4305 json_object_object_add(json_vrf
, "neighbors", json_nbr_sub
);
4307 if (ospf
->vrf_id
== VRF_DEFAULT
)
4308 json_object_object_add(json
, "default",
4311 json_object_object_add(json
, ospf
->name
,
4320 DEFUN (show_ip_ospf_neighbor
,
4321 show_ip_ospf_neighbor_cmd
,
4322 "show ip ospf [vrf <NAME|all>] neighbor [json]",
4325 "OSPF information\n"
4332 bool uj
= use_json(argc
, argv
);
4333 struct listnode
*node
= NULL
;
4334 char *vrf_name
= NULL
;
4335 bool all_vrf
= FALSE
;
4336 int ret
= CMD_SUCCESS
;
4339 uint8_t use_vrf
= 0;
4340 json_object
*json
= NULL
;
4342 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4345 json
= json_object_new_object();
4347 /* vrf input is provided could be all or specific vrf*/
4351 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4352 if (!ospf
->oi_running
)
4354 ret
= show_ip_ospf_neighbor_common(
4355 vty
, ospf
, json
, uj
, use_vrf
);
4359 vty_out(vty
, "%s\n",
4360 json_object_to_json_string_ext(
4361 json
, JSON_C_TO_STRING_PRETTY
));
4362 json_object_free(json
);
4364 vty_out(vty
, "OSPF instance not found\n");
4369 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4370 if (ospf
== NULL
|| !ospf
->oi_running
) {
4372 vty_out(vty
, "%s\n",
4373 json_object_to_json_string_ext(
4374 json
, JSON_C_TO_STRING_PRETTY
));
4375 json_object_free(json
);
4377 vty_out(vty
, "%% OSPF instance not found\n");
4382 /* Display default ospf (instance 0) info */
4383 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4384 if (ospf
== NULL
|| !ospf
->oi_running
) {
4386 vty_out(vty
, "%s\n",
4387 json_object_to_json_string_ext(
4388 json
, JSON_C_TO_STRING_PRETTY
));
4389 json_object_free(json
);
4391 vty_out(vty
, "%% OSPF instance not found\n");
4398 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
,
4402 vty_out(vty
, "%s\n",
4403 json_object_to_json_string_ext(
4404 json
, JSON_C_TO_STRING_PRETTY
));
4409 json_object_free(json
);
4415 DEFUN (show_ip_ospf_instance_neighbor
,
4416 show_ip_ospf_instance_neighbor_cmd
,
4417 "show ip ospf (1-65535) neighbor [json]",
4420 "OSPF information\n"
4427 unsigned short instance
= 0;
4428 bool uj
= use_json(argc
, argv
);
4429 json_object
*json
= NULL
;
4430 int ret
= CMD_SUCCESS
;
4432 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4433 ospf
= ospf_lookup_instance(instance
);
4435 return CMD_NOT_MY_INSTANCE
;
4437 if (!ospf
->oi_running
)
4441 json
= json_object_new_object();
4443 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
, 0);
4446 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4447 json
, JSON_C_TO_STRING_PRETTY
));
4448 json_object_free(json
);
4454 static int show_ip_ospf_neighbor_all_common(struct vty
*vty
, struct ospf
*ospf
,
4455 json_object
*json
, bool use_json
,
4458 struct listnode
*node
;
4459 struct ospf_interface
*oi
;
4460 json_object
*json_vrf
= NULL
;
4461 json_object
*json_neighbor_sub
= NULL
;
4465 json_vrf
= json_object_new_object();
4468 json_neighbor_sub
= json_object_new_object();
4471 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4473 show_ip_ospf_neighbour_header(vty
);
4475 if (ospf
->instance
) {
4477 json_object_int_add(json_vrf
, "ospfInstance",
4480 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4483 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4484 struct listnode
*nbr_node
;
4485 struct ospf_nbr_nbma
*nbr_nbma
;
4487 show_ip_ospf_neighbor_sub(vty
, oi
, json_vrf
, use_json
);
4489 /* print Down neighbor status */
4490 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nbr_node
, nbr_nbma
)) {
4491 if (nbr_nbma
->nbr
== NULL
4492 || nbr_nbma
->nbr
->state
== NSM_Down
) {
4494 json_object_int_add(json_neighbor_sub
,
4496 nbr_nbma
->priority
);
4497 json_object_boolean_true_add(
4500 json_object_string_add(
4504 json_object_int_add(
4506 "nbrNbmaRetransmitCounter", 0);
4507 json_object_int_add(
4509 "nbrNbmaRequestCounter", 0);
4510 json_object_int_add(
4512 "nbrNbmaDbSummaryCounter", 0);
4513 json_object_object_add(
4515 inet_ntoa(nbr_nbma
->addr
),
4518 vty_out(vty
, "%-15s %3d %-15s %9s ",
4519 "-", nbr_nbma
->priority
, "Down",
4522 "%-15s %-20s %5d %5d %5d\n",
4523 inet_ntoa(nbr_nbma
->addr
),
4524 IF_NAME(oi
), 0, 0, 0);
4532 if (ospf
->vrf_id
== VRF_DEFAULT
)
4533 json_object_object_add(json
, "default",
4536 json_object_object_add(json
, ospf
->name
,
4545 DEFUN (show_ip_ospf_neighbor_all
,
4546 show_ip_ospf_neighbor_all_cmd
,
4547 "show ip ospf [vrf <NAME|all>] neighbor all [json]",
4550 "OSPF information\n"
4554 "include down status neighbor\n"
4558 bool uj
= use_json(argc
, argv
);
4559 struct listnode
*node
= NULL
;
4560 char *vrf_name
= NULL
;
4561 bool all_vrf
= FALSE
;
4562 int ret
= CMD_SUCCESS
;
4565 uint8_t use_vrf
= 0;
4566 json_object
*json
= NULL
;
4568 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4571 json
= json_object_new_object();
4573 /* vrf input is provided could be all or specific vrf*/
4577 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4578 if (!ospf
->oi_running
)
4580 ret
= show_ip_ospf_neighbor_all_common(
4581 vty
, ospf
, json
, uj
, use_vrf
);
4585 vty_out(vty
, "%s\n",
4586 json_object_to_json_string_ext(
4587 json
, JSON_C_TO_STRING_PRETTY
));
4588 json_object_free(json
);
4594 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4595 if (ospf
== NULL
|| !ospf
->oi_running
) {
4597 json_object_free(json
);
4601 /* Display default ospf (instance 0) info */
4602 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4603 if (ospf
== NULL
|| !ospf
->oi_running
) {
4605 json_object_free(json
);
4611 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
,
4614 vty_out(vty
, "%s\n",
4615 json_object_to_json_string_ext(
4616 json
, JSON_C_TO_STRING_PRETTY
));
4621 json_object_free(json
);
4626 DEFUN (show_ip_ospf_instance_neighbor_all
,
4627 show_ip_ospf_instance_neighbor_all_cmd
,
4628 "show ip ospf (1-65535) neighbor all [json]",
4631 "OSPF information\n"
4634 "include down status neighbor\n"
4639 unsigned short instance
= 0;
4640 bool uj
= use_json(argc
, argv
);
4641 json_object
*json
= NULL
;
4642 int ret
= CMD_SUCCESS
;
4644 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4645 ospf
= ospf_lookup_instance(instance
);
4647 return CMD_NOT_MY_INSTANCE
;
4649 if (!ospf
->oi_running
)
4652 json
= json_object_new_object();
4654 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
, 0);
4657 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4658 json
, JSON_C_TO_STRING_PRETTY
));
4659 json_object_free(json
);
4665 static int show_ip_ospf_neighbor_int_common(struct vty
*vty
, struct ospf
*ospf
,
4667 struct cmd_token
**argv
,
4668 bool use_json
, uint8_t use_vrf
)
4670 struct interface
*ifp
;
4671 struct route_node
*rn
;
4672 json_object
*json
= NULL
;
4675 json
= json_object_new_object();
4677 if (ospf
->instance
) {
4679 json_object_int_add(json
, "ospfInstance",
4682 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4685 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
4687 ifp
= if_lookup_by_name_all_vrf(argv
[arg_base
]->arg
);
4690 json_object_boolean_true_add(json
, "noSuchIface");
4692 vty_out(vty
, "No such interface.\n");
4696 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
4697 struct ospf_interface
*oi
= rn
->info
;
4702 show_ip_ospf_neighbor_sub(vty
, oi
, json
, use_json
);
4706 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4707 json
, JSON_C_TO_STRING_PRETTY
));
4708 json_object_free(json
);
4715 DEFUN (show_ip_ospf_neighbor_int
,
4716 show_ip_ospf_neighbor_int_cmd
,
4717 "show ip ospf neighbor IFNAME [json]",
4720 "OSPF information\n"
4727 bool uj
= use_json(argc
, argv
);
4728 struct listnode
*node
= NULL
;
4729 int ret
= CMD_SUCCESS
;
4730 struct interface
*ifp
= NULL
;
4733 show_ip_ospf_neighbour_header(vty
);
4735 ifp
= if_lookup_by_name_all_vrf(argv
[idx_ifname
]->arg
);
4736 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4737 if (!ospf
->oi_running
)
4739 if (!ifp
|| ifp
->vrf_id
!= ospf
->vrf_id
)
4741 ret
= show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
,
4748 DEFUN (show_ip_ospf_instance_neighbor_int
,
4749 show_ip_ospf_instance_neighbor_int_cmd
,
4750 "show ip ospf (1-65535) neighbor IFNAME [json]",
4753 "OSPF information\n"
4762 unsigned short instance
= 0;
4763 bool uj
= use_json(argc
, argv
);
4766 show_ip_ospf_neighbour_header(vty
);
4768 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4769 ospf
= ospf_lookup_instance(instance
);
4771 return CMD_NOT_MY_INSTANCE
;
4773 if (!ospf
->oi_running
)
4777 show_ip_ospf_neighbour_header(vty
);
4779 return show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
, argv
, uj
,
4783 static void show_ip_ospf_nbr_nbma_detail_sub(struct vty
*vty
,
4784 struct ospf_interface
*oi
,
4785 struct ospf_nbr_nbma
*nbr_nbma
,
4786 bool use_json
, json_object
*json
)
4788 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4789 json_object
*json_sub
= NULL
;
4792 json_sub
= json_object_new_object();
4793 else /* Show neighbor ID. */
4794 vty_out(vty
, " Neighbor %s,", "-");
4796 /* Show interface address. */
4798 json_object_string_add(json_sub
, "ifaceAddress",
4799 inet_ntoa(nbr_nbma
->addr
));
4801 vty_out(vty
, " interface address %s\n",
4802 inet_ntoa(nbr_nbma
->addr
));
4806 json_object_string_add(json_sub
, "areaId",
4807 ospf_area_desc_string(oi
->area
));
4808 json_object_string_add(json_sub
, "iface", IF_NAME(oi
));
4810 vty_out(vty
, " In the area %s via interface %s\n",
4811 ospf_area_desc_string(oi
->area
), IF_NAME(oi
));
4813 /* Show neighbor priority and state. */
4815 json_object_int_add(json_sub
, "nbrPriority",
4816 nbr_nbma
->priority
);
4817 json_object_string_add(json_sub
, "nbrState", "down");
4819 vty_out(vty
, " Neighbor priority is %d, State is %s,",
4820 nbr_nbma
->priority
, "Down");
4822 /* Show state changes. */
4824 json_object_int_add(json_sub
, "stateChangeCounter",
4825 nbr_nbma
->state_change
);
4827 vty_out(vty
, " %d state changes\n", nbr_nbma
->state_change
);
4829 /* Show PollInterval */
4831 json_object_int_add(json_sub
, "pollInterval", nbr_nbma
->v_poll
);
4833 vty_out(vty
, " Poll interval %d\n", nbr_nbma
->v_poll
);
4835 /* Show poll-interval timer. */
4836 if (nbr_nbma
->t_poll
) {
4839 time_store
= monotime_until(&nbr_nbma
->t_poll
->u
.sands
,
4841 json_object_int_add(json_sub
,
4842 "pollIntervalTimerDueMsec",
4845 vty_out(vty
, " Poll timer due in %s\n",
4846 ospf_timer_dump(nbr_nbma
->t_poll
, timebuf
,
4850 /* Show poll-interval timer thread. */
4852 if (nbr_nbma
->t_poll
!= NULL
)
4853 json_object_string_add(json_sub
,
4854 "pollIntervalTimerThread", "on");
4856 vty_out(vty
, " Thread Poll Timer %s\n",
4857 nbr_nbma
->t_poll
!= NULL
? "on" : "off");
4860 json_object_object_add(json
, "noNbrId", json_sub
);
4863 static void show_ip_ospf_neighbor_detail_sub(struct vty
*vty
,
4864 struct ospf_interface
*oi
,
4865 struct ospf_neighbor
*nbr
,
4866 json_object
*json
, bool use_json
)
4868 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4869 json_object
*json_sub
= NULL
;
4872 json_sub
= json_object_new_object();
4874 /* Show neighbor ID. */
4875 if (nbr
->state
== NSM_Attempt
&& nbr
->router_id
.s_addr
== 0)
4876 vty_out(vty
, " Neighbor %s,", "-");
4878 vty_out(vty
, " Neighbor %s,",
4879 inet_ntoa(nbr
->router_id
));
4882 /* Show interface address. */
4884 json_object_string_add(json_sub
, "ifaceAddress",
4885 inet_ntoa(nbr
->address
.u
.prefix4
));
4887 vty_out(vty
, " interface address %s\n",
4888 inet_ntoa(nbr
->address
.u
.prefix4
));
4892 json_object_string_add(json_sub
, "areaId",
4893 ospf_area_desc_string(oi
->area
));
4894 json_object_string_add(json_sub
, "ifaceName", oi
->ifp
->name
);
4896 vty_out(vty
, " In the area %s via interface %s\n",
4897 ospf_area_desc_string(oi
->area
), oi
->ifp
->name
);
4899 /* Show neighbor priority and state. */
4901 json_object_int_add(json_sub
, "nbrPriority", nbr
->priority
);
4902 json_object_string_add(
4903 json_sub
, "nbrState",
4904 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
4906 vty_out(vty
, " Neighbor priority is %d, State is %s,",
4908 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
4910 /* Show state changes. */
4912 json_object_int_add(json_sub
, "stateChangeCounter",
4915 vty_out(vty
, " %d state changes\n", nbr
->state_change
);
4917 if (nbr
->ts_last_progress
.tv_sec
|| nbr
->ts_last_progress
.tv_usec
) {
4922 monotime_since(&nbr
->ts_last_progress
, &res
) / 1000LL;
4924 json_object_int_add(json_sub
, "lastPrgrsvChangeMsec",
4928 " Most recent state change statistics:\n");
4929 vty_out(vty
, " Progressive change %s ago\n",
4930 ospf_timeval_dump(&res
, timebuf
,
4935 if (nbr
->ts_last_regress
.tv_sec
|| nbr
->ts_last_regress
.tv_usec
) {
4940 monotime_since(&nbr
->ts_last_regress
, &res
) / 1000LL;
4942 json_object_int_add(json_sub
,
4943 "lastRegressiveChangeMsec",
4945 if (nbr
->last_regress_str
)
4946 json_object_string_add(
4947 json_sub
, "lastRegressiveChangeReason",
4948 nbr
->last_regress_str
);
4951 " Regressive change %s ago, due to %s\n",
4952 ospf_timeval_dump(&res
, timebuf
,
4954 (nbr
->last_regress_str
? nbr
->last_regress_str
4959 /* Show Designated Rotuer ID. */
4961 json_object_string_add(json_sub
, "routerDesignatedId",
4962 inet_ntoa(nbr
->d_router
));
4964 vty_out(vty
, " DR is %s,", inet_ntoa(nbr
->d_router
));
4966 /* Show Backup Designated Rotuer ID. */
4968 json_object_string_add(json_sub
, "routerDesignatedBackupId",
4969 inet_ntoa(nbr
->bd_router
));
4971 vty_out(vty
, " BDR is %s\n", inet_ntoa(nbr
->bd_router
));
4975 json_object_int_add(json_sub
, "optionsCounter", nbr
->options
);
4976 json_object_string_add(json_sub
, "optionsList",
4977 ospf_options_dump(nbr
->options
));
4979 vty_out(vty
, " Options %d %s\n", nbr
->options
,
4980 ospf_options_dump(nbr
->options
));
4982 /* Show Router Dead interval timer. */
4984 if (nbr
->t_inactivity
) {
4986 time_store
= monotime_until(&nbr
->t_inactivity
->u
.sands
,
4989 json_object_int_add(json_sub
,
4990 "routerDeadIntervalTimerDueMsec",
4993 json_object_int_add(
4994 json_sub
, "routerDeadIntervalTimerDueMsec", -1);
4996 vty_out(vty
, " Dead timer due in %s\n",
4997 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
5000 /* Show Database Summary list. */
5002 json_object_int_add(json_sub
, "databaseSummaryListCounter",
5003 ospf_db_summary_count(nbr
));
5005 vty_out(vty
, " Database Summary List %d\n",
5006 ospf_db_summary_count(nbr
));
5008 /* Show Link State Request list. */
5010 json_object_int_add(json_sub
, "linkStateRequestListCounter",
5011 ospf_ls_request_count(nbr
));
5013 vty_out(vty
, " Link State Request List %ld\n",
5014 ospf_ls_request_count(nbr
));
5016 /* Show Link State Retransmission list. */
5018 json_object_int_add(json_sub
,
5019 "linkStateRetransmissionListCounter",
5020 ospf_ls_retransmit_count(nbr
));
5022 vty_out(vty
, " Link State Retransmission List %ld\n",
5023 ospf_ls_retransmit_count(nbr
));
5025 /* Show inactivity timer thread. */
5027 if (nbr
->t_inactivity
!= NULL
)
5028 json_object_string_add(json_sub
,
5029 "threadInactivityTimer", "on");
5031 vty_out(vty
, " Thread Inactivity Timer %s\n",
5032 nbr
->t_inactivity
!= NULL
? "on" : "off");
5034 /* Show Database Description retransmission thread. */
5036 if (nbr
->t_db_desc
!= NULL
)
5037 json_object_string_add(
5039 "threadDatabaseDescriptionRetransmission",
5043 " Thread Database Description Retransmision %s\n",
5044 nbr
->t_db_desc
!= NULL
? "on" : "off");
5046 /* Show Link State Request Retransmission thread. */
5048 if (nbr
->t_ls_req
!= NULL
)
5049 json_object_string_add(
5051 "threadLinkStateRequestRetransmission", "on");
5054 " Thread Link State Request Retransmission %s\n",
5055 nbr
->t_ls_req
!= NULL
? "on" : "off");
5057 /* Show Link State Update Retransmission thread. */
5059 if (nbr
->t_ls_upd
!= NULL
)
5060 json_object_string_add(
5061 json_sub
, "threadLinkStateUpdateRetransmission",
5065 " Thread Link State Update Retransmission %s\n\n",
5066 nbr
->t_ls_upd
!= NULL
? "on" : "off");
5069 if (nbr
->state
== NSM_Attempt
&& nbr
->router_id
.s_addr
== 0)
5070 json_object_object_add(json
, "noNbrId", json_sub
);
5072 json_object_object_add(json
, inet_ntoa(nbr
->router_id
),
5076 ospf_bfd_show_info(vty
, nbr
->bfd_info
, json
, use_json
, 0);
5079 static int show_ip_ospf_neighbor_id_common(struct vty
*vty
, struct ospf
*ospf
,
5081 struct cmd_token
**argv
,
5082 bool use_json
, uint8_t use_vrf
)
5084 struct listnode
*node
;
5085 struct ospf_neighbor
*nbr
;
5086 struct ospf_interface
*oi
;
5087 struct in_addr router_id
;
5089 json_object
*json
= NULL
;
5092 json
= json_object_new_object();
5094 if (ospf
->instance
) {
5096 json_object_int_add(json
, "ospfInstance",
5099 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5102 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
5104 ret
= inet_aton(argv
[arg_base
]->arg
, &router_id
);
5107 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
5109 vty_out(vty
, "{}\n");
5110 json_object_free(json
);
5115 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5116 if ((nbr
= ospf_nbr_lookup_by_routerid(oi
->nbrs
, &router_id
))) {
5117 show_ip_ospf_neighbor_detail_sub(vty
, oi
, nbr
, json
,
5123 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5124 json
, JSON_C_TO_STRING_PRETTY
));
5125 json_object_free(json
);
5132 DEFUN (show_ip_ospf_neighbor_id
,
5133 show_ip_ospf_neighbor_id_cmd
,
5134 "show ip ospf neighbor A.B.C.D [json]",
5137 "OSPF information\n"
5143 bool uj
= use_json(argc
, argv
);
5144 struct listnode
*node
= NULL
;
5145 int ret
= CMD_SUCCESS
;
5147 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5148 if (!ospf
->oi_running
)
5150 ret
= show_ip_ospf_neighbor_id_common(vty
, ospf
, 0, argv
, uj
,
5157 DEFUN (show_ip_ospf_instance_neighbor_id
,
5158 show_ip_ospf_instance_neighbor_id_cmd
,
5159 "show ip ospf (1-65535) neighbor A.B.C.D [json]",
5162 "OSPF information\n"
5169 int idx_router_id
= 5;
5171 unsigned short instance
= 0;
5172 bool uj
= use_json(argc
, argv
);
5174 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5175 ospf
= ospf_lookup_instance(instance
);
5177 return CMD_NOT_MY_INSTANCE
;
5179 if (!ospf
->oi_running
)
5182 return show_ip_ospf_neighbor_id_common(vty
, ospf
, idx_router_id
, argv
,
5186 static int show_ip_ospf_neighbor_detail_common(struct vty
*vty
,
5188 json_object
*json
, bool use_json
,
5191 struct ospf_interface
*oi
;
5192 struct listnode
*node
;
5193 json_object
*json_vrf
= NULL
;
5197 json_vrf
= json_object_new_object();
5201 if (ospf
->instance
) {
5203 json_object_int_add(json_vrf
, "ospfInstance",
5206 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5209 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5211 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5212 struct route_node
*rn
;
5213 struct ospf_neighbor
*nbr
;
5215 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5216 if ((nbr
= rn
->info
)) {
5217 if (nbr
!= oi
->nbr_self
) {
5218 if (nbr
->state
!= NSM_Down
) {
5219 show_ip_ospf_neighbor_detail_sub(
5220 vty
, oi
, nbr
, json_vrf
,
5230 if (ospf
->vrf_id
== VRF_DEFAULT
)
5231 json_object_object_add(json
, "default",
5234 json_object_object_add(json
, ospf
->name
,
5243 DEFUN (show_ip_ospf_neighbor_detail
,
5244 show_ip_ospf_neighbor_detail_cmd
,
5245 "show ip ospf [vrf <NAME|all>] neighbor detail [json]",
5248 "OSPF information\n"
5252 "detail of all neighbors\n"
5256 bool uj
= use_json(argc
, argv
);
5257 struct listnode
*node
= NULL
;
5258 char *vrf_name
= NULL
;
5259 bool all_vrf
= FALSE
;
5260 int ret
= CMD_SUCCESS
;
5263 uint8_t use_vrf
= 0;
5264 json_object
*json
= NULL
;
5266 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5269 json
= json_object_new_object();
5271 /* vrf input is provided could be all or specific vrf*/
5275 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5276 if (!ospf
->oi_running
)
5278 ret
= show_ip_ospf_neighbor_detail_common(
5279 vty
, ospf
, json
, uj
, use_vrf
);
5282 vty_out(vty
, "%s\n",
5283 json_object_to_json_string_ext(
5284 json
, JSON_C_TO_STRING_PRETTY
));
5285 json_object_free(json
);
5290 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5291 if (ospf
== NULL
|| !ospf
->oi_running
) {
5293 json_object_free(json
);
5297 /* Display default ospf (instance 0) info */
5298 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5299 if (ospf
== NULL
|| !ospf
->oi_running
) {
5301 json_object_free(json
);
5307 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
,
5310 vty_out(vty
, "%s\n",
5311 json_object_to_json_string_ext(
5312 json
, JSON_C_TO_STRING_PRETTY
));
5317 json_object_free(json
);
5322 DEFUN (show_ip_ospf_instance_neighbor_detail
,
5323 show_ip_ospf_instance_neighbor_detail_cmd
,
5324 "show ip ospf (1-65535) neighbor detail [json]",
5327 "OSPF information\n"
5330 "detail of all neighbors\n"
5335 unsigned short instance
= 0;
5336 bool uj
= use_json(argc
, argv
);
5337 json_object
*json
= NULL
;
5338 int ret
= CMD_SUCCESS
;
5340 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5341 ospf
= ospf_lookup_instance(instance
);
5343 return CMD_NOT_MY_INSTANCE
;
5345 if (!ospf
->oi_running
)
5349 json
= json_object_new_object();
5351 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
, 0);
5354 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5355 json
, JSON_C_TO_STRING_PRETTY
));
5356 json_object_free(json
);
5362 static int show_ip_ospf_neighbor_detail_all_common(struct vty
*vty
,
5368 struct listnode
*node
;
5369 struct ospf_interface
*oi
;
5370 json_object
*json_vrf
= NULL
;
5374 json_vrf
= json_object_new_object();
5379 if (ospf
->instance
) {
5381 json_object_int_add(json
, "ospfInstance",
5384 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5387 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5389 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5390 struct route_node
*rn
;
5391 struct ospf_neighbor
*nbr
;
5392 struct ospf_nbr_nbma
*nbr_nbma
;
5394 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
5395 if ((nbr
= rn
->info
))
5396 if (nbr
!= oi
->nbr_self
)
5397 if (nbr
->state
!= NSM_Down
)
5398 show_ip_ospf_neighbor_detail_sub(
5400 json_vrf
, use_json
);
5402 if (oi
->type
== OSPF_IFTYPE_NBMA
) {
5403 struct listnode
*nd
;
5405 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nd
, nbr_nbma
)) {
5406 if (nbr_nbma
->nbr
== NULL
5407 || nbr_nbma
->nbr
->state
== NSM_Down
)
5408 show_ip_ospf_nbr_nbma_detail_sub(
5409 vty
, oi
, nbr_nbma
, use_json
,
5417 if (ospf
->vrf_id
== VRF_DEFAULT
)
5418 json_object_object_add(json
, "default",
5421 json_object_object_add(json
, ospf
->name
,
5431 DEFUN (show_ip_ospf_neighbor_detail_all
,
5432 show_ip_ospf_neighbor_detail_all_cmd
,
5433 "show ip ospf [vrf <NAME|all>] neighbor detail all [json]",
5436 "OSPF information\n"
5440 "detail of all neighbors\n"
5441 "include down status neighbor\n"
5445 bool uj
= use_json(argc
, argv
);
5446 struct listnode
*node
= NULL
;
5447 char *vrf_name
= NULL
;
5448 bool all_vrf
= FALSE
;
5449 int ret
= CMD_SUCCESS
;
5452 uint8_t use_vrf
= 0;
5453 json_object
*json
= NULL
;
5455 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5458 json
= json_object_new_object();
5460 /* vrf input is provided could be all or specific vrf*/
5464 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5465 if (!ospf
->oi_running
)
5467 ret
= show_ip_ospf_neighbor_detail_all_common(
5468 vty
, ospf
, json
, uj
, use_vrf
);
5472 vty_out(vty
, "%s\n",
5473 json_object_to_json_string_ext(
5474 json
, JSON_C_TO_STRING_PRETTY
));
5475 json_object_free(json
);
5480 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5481 if (ospf
== NULL
|| !ospf
->oi_running
) {
5483 json_object_free(json
);
5487 /* Display default ospf (instance 0) info */
5488 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5489 if (ospf
== NULL
|| !ospf
->oi_running
) {
5491 json_object_free(json
);
5497 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
,
5500 vty_out(vty
, "%s\n",
5501 json_object_to_json_string_ext(
5502 json
, JSON_C_TO_STRING_PRETTY
));
5507 json_object_free(json
);
5512 DEFUN (show_ip_ospf_instance_neighbor_detail_all
,
5513 show_ip_ospf_instance_neighbor_detail_all_cmd
,
5514 "show ip ospf (1-65535) neighbor detail all [json]",
5517 "OSPF information\n"
5520 "detail of all neighbors\n"
5521 "include down status neighbor\n"
5526 unsigned short instance
= 0;
5527 bool uj
= use_json(argc
, argv
);
5528 json_object
*json
= NULL
;
5529 int ret
= CMD_SUCCESS
;
5531 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5532 ospf
= ospf_lookup_instance(instance
);
5534 return CMD_NOT_MY_INSTANCE
;
5536 if (!ospf
->oi_running
)
5540 json
= json_object_new_object();
5542 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
, uj
, 0);
5545 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5546 json
, JSON_C_TO_STRING_PRETTY
));
5547 json_object_free(json
);
5553 static int show_ip_ospf_neighbor_int_detail_common(struct vty
*vty
,
5556 struct cmd_token
**argv
,
5559 struct ospf_interface
*oi
;
5560 struct interface
*ifp
;
5561 struct route_node
*rn
, *nrn
;
5562 struct ospf_neighbor
*nbr
;
5563 json_object
*json
= NULL
;
5566 json
= json_object_new_object();
5568 if (ospf
->instance
) {
5570 json_object_int_add(json
, "ospfInstance",
5573 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5576 ifp
= if_lookup_by_name_all_vrf(argv
[arg_base
]->arg
);
5579 vty_out(vty
, "No such interface.\n");
5581 vty_out(vty
, "{}\n");
5582 json_object_free(json
);
5587 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
5588 if ((oi
= rn
->info
)) {
5589 for (nrn
= route_top(oi
->nbrs
); nrn
;
5590 nrn
= route_next(nrn
)) {
5591 if ((nbr
= nrn
->info
)) {
5592 if (nbr
!= oi
->nbr_self
) {
5593 if (nbr
->state
!= NSM_Down
)
5594 show_ip_ospf_neighbor_detail_sub(
5604 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5605 json
, JSON_C_TO_STRING_PRETTY
));
5606 json_object_free(json
);
5613 DEFUN (show_ip_ospf_neighbor_int_detail
,
5614 show_ip_ospf_neighbor_int_detail_cmd
,
5615 "show ip ospf neighbor IFNAME detail [json]",
5618 "OSPF information\n"
5621 "detail of all neighbors\n"
5625 bool uj
= use_json(argc
, argv
);
5626 struct listnode
*node
= NULL
;
5627 int ret
= CMD_SUCCESS
;
5628 bool ospf_output
= FALSE
;
5630 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5631 if (!ospf
->oi_running
)
5634 ret
= show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, 0,
5639 vty_out(vty
, "%% OSPF instance not found\n");
5644 DEFUN (show_ip_ospf_instance_neighbor_int_detail
,
5645 show_ip_ospf_instance_neighbor_int_detail_cmd
,
5646 "show ip ospf (1-65535) neighbor IFNAME detail [json]",
5649 "OSPF information\n"
5653 "detail of all neighbors\n"
5659 unsigned short instance
= 0;
5660 bool uj
= use_json(argc
, argv
);
5662 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5663 ospf
= ospf_lookup_instance(instance
);
5665 return CMD_NOT_MY_INSTANCE
;
5667 if (!ospf
->oi_running
)
5670 return show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, idx_ifname
,
5674 /* Show functions */
5675 static int show_lsa_summary(struct vty
*vty
, struct ospf_lsa
*lsa
, int self
)
5677 struct router_lsa
*rl
;
5678 struct summary_lsa
*sl
;
5679 struct as_external_lsa
*asel
;
5680 struct prefix_ipv4 p
;
5683 /* If self option is set, check LSA self flag. */
5684 if (self
== 0 || IS_LSA_SELF(lsa
)) {
5685 /* LSA common part show. */
5686 vty_out(vty
, "%-15s ", inet_ntoa(lsa
->data
->id
));
5687 vty_out(vty
, "%-15s %4d 0x%08lx 0x%04x",
5688 inet_ntoa(lsa
->data
->adv_router
), LS_AGE(lsa
),
5689 (unsigned long)ntohl(lsa
->data
->ls_seqnum
),
5690 ntohs(lsa
->data
->checksum
));
5691 /* LSA specific part show. */
5692 switch (lsa
->data
->type
) {
5693 case OSPF_ROUTER_LSA
:
5694 rl
= (struct router_lsa
*)lsa
->data
;
5695 vty_out(vty
, " %-d", ntohs(rl
->links
));
5697 case OSPF_SUMMARY_LSA
:
5698 sl
= (struct summary_lsa
*)lsa
->data
;
5701 p
.prefix
= sl
->header
.id
;
5702 p
.prefixlen
= ip_masklen(sl
->mask
);
5703 apply_mask_ipv4(&p
);
5705 vty_out(vty
, " %s/%d", inet_ntoa(p
.prefix
),
5708 case OSPF_AS_EXTERNAL_LSA
:
5709 case OSPF_AS_NSSA_LSA
:
5710 asel
= (struct as_external_lsa
*)lsa
->data
;
5713 p
.prefix
= asel
->header
.id
;
5714 p
.prefixlen
= ip_masklen(asel
->mask
);
5715 apply_mask_ipv4(&p
);
5717 vty_out(vty
, " %s %s/%d [0x%lx]",
5718 IS_EXTERNAL_METRIC(asel
->e
[0].tos
)
5721 inet_ntoa(p
.prefix
), p
.prefixlen
,
5722 (unsigned long)ntohl(
5723 asel
->e
[0].route_tag
));
5725 case OSPF_NETWORK_LSA
:
5726 case OSPF_ASBR_SUMMARY_LSA
:
5727 case OSPF_OPAQUE_LINK_LSA
:
5728 case OSPF_OPAQUE_AREA_LSA
:
5729 case OSPF_OPAQUE_AS_LSA
:
5739 static const char *show_database_desc
[] = {
5741 "Router Link States",
5743 "Summary Link States",
5744 "ASBR-Summary Link States",
5745 "AS External Link States",
5746 "Group Membership LSA",
5747 "NSSA-external Link States",
5749 "Link-Local Opaque-LSA",
5750 "Area-Local Opaque-LSA",
5751 "AS-external Opaque-LSA",
5754 static const char *show_database_header
[] = {
5756 "Link ID ADV Router Age Seq# CkSum Link count",
5757 "Link ID ADV Router Age Seq# CkSum",
5758 "Link ID ADV Router Age Seq# CkSum Route",
5759 "Link ID ADV Router Age Seq# CkSum",
5760 "Link ID ADV Router Age Seq# CkSum Route",
5761 " --- header for Group Member ----",
5762 "Link ID ADV Router Age Seq# CkSum Route",
5764 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5765 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5766 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5769 static void show_ip_ospf_database_header(struct vty
*vty
, struct ospf_lsa
*lsa
)
5771 struct router_lsa
*rlsa
= (struct router_lsa
*)lsa
->data
;
5773 vty_out(vty
, " LS age: %d\n", LS_AGE(lsa
));
5774 vty_out(vty
, " Options: 0x%-2x : %s\n", lsa
->data
->options
,
5775 ospf_options_dump(lsa
->data
->options
));
5776 vty_out(vty
, " LS Flags: 0x%-2x %s\n", lsa
->flags
,
5777 ((lsa
->flags
& OSPF_LSA_LOCAL_XLT
) ? "(Translated from Type-7)"
5780 if (lsa
->data
->type
== OSPF_ROUTER_LSA
) {
5781 vty_out(vty
, " Flags: 0x%x", rlsa
->flags
);
5784 vty_out(vty
, " :%s%s%s%s",
5785 IS_ROUTER_LSA_BORDER(rlsa
) ? " ABR" : "",
5786 IS_ROUTER_LSA_EXTERNAL(rlsa
) ? " ASBR" : "",
5787 IS_ROUTER_LSA_VIRTUAL(rlsa
) ? " VL-endpoint"
5789 IS_ROUTER_LSA_SHORTCUT(rlsa
) ? " Shortcut"
5794 vty_out(vty
, " LS Type: %s\n",
5795 lookup_msg(ospf_lsa_type_msg
, lsa
->data
->type
, NULL
));
5796 vty_out(vty
, " Link State ID: %s %s\n", inet_ntoa(lsa
->data
->id
),
5797 lookup_msg(ospf_link_state_id_type_msg
, lsa
->data
->type
, NULL
));
5798 vty_out(vty
, " Advertising Router: %s\n",
5799 inet_ntoa(lsa
->data
->adv_router
));
5800 vty_out(vty
, " LS Seq Number: %08lx\n",
5801 (unsigned long)ntohl(lsa
->data
->ls_seqnum
));
5802 vty_out(vty
, " Checksum: 0x%04x\n", ntohs(lsa
->data
->checksum
));
5803 vty_out(vty
, " Length: %d\n\n", ntohs(lsa
->data
->length
));
5806 const char *link_type_desc
[] = {
5808 "another Router (point-to-point)",
5809 "a Transit Network",
5814 const char *link_id_desc
[] = {
5815 "(null)", "Neighboring Router ID", "Designated Router address",
5816 "Net", "Neighboring Router ID",
5819 const char *link_data_desc
[] = {
5820 "(null)", "Router Interface address", "Router Interface address",
5821 "Network Mask", "Router Interface address",
5824 /* Show router-LSA each Link information. */
5825 static void show_ip_ospf_database_router_links(struct vty
*vty
,
5826 struct router_lsa
*rl
)
5831 len
= ntohs(rl
->header
.length
) - 4;
5832 for (i
= 0; i
< ntohs(rl
->links
) && len
> 0; len
-= 12, i
++) {
5833 type
= rl
->link
[i
].type
;
5835 vty_out(vty
, " Link connected to: %s\n",
5836 link_type_desc
[type
]);
5837 vty_out(vty
, " (Link ID) %s: %s\n", link_id_desc
[type
],
5838 inet_ntoa(rl
->link
[i
].link_id
));
5839 vty_out(vty
, " (Link Data) %s: %s\n", link_data_desc
[type
],
5840 inet_ntoa(rl
->link
[i
].link_data
));
5841 vty_out(vty
, " Number of TOS metrics: 0\n");
5842 vty_out(vty
, " TOS 0 Metric: %d\n",
5843 ntohs(rl
->link
[i
].metric
));
5848 /* Show router-LSA detail information. */
5849 static int show_router_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5852 struct router_lsa
*rl
= (struct router_lsa
*)lsa
->data
;
5854 show_ip_ospf_database_header(vty
, lsa
);
5856 vty_out(vty
, " Number of Links: %d\n\n", ntohs(rl
->links
));
5858 show_ip_ospf_database_router_links(vty
, rl
);
5865 /* Show network-LSA detail information. */
5866 static int show_network_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5871 struct network_lsa
*nl
= (struct network_lsa
*)lsa
->data
;
5873 show_ip_ospf_database_header(vty
, lsa
);
5875 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(nl
->mask
));
5877 length
= ntohs(lsa
->data
->length
) - OSPF_LSA_HEADER_SIZE
- 4;
5879 for (i
= 0; length
> 0; i
++, length
-= 4)
5880 vty_out(vty
, " Attached Router: %s\n",
5881 inet_ntoa(nl
->routers
[i
]));
5889 /* Show summary-LSA detail information. */
5890 static int show_summary_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5893 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
5895 show_ip_ospf_database_header(vty
, lsa
);
5897 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(sl
->mask
));
5898 vty_out(vty
, " TOS: 0 Metric: %d\n",
5899 GET_METRIC(sl
->metric
));
5906 /* Show summary-ASBR-LSA detail information. */
5907 static int show_summary_asbr_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5910 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
5912 show_ip_ospf_database_header(vty
, lsa
);
5914 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(sl
->mask
));
5915 vty_out(vty
, " TOS: 0 Metric: %d\n",
5916 GET_METRIC(sl
->metric
));
5923 /* Show AS-external-LSA detail information. */
5924 static int show_as_external_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5927 struct as_external_lsa
*al
=
5928 (struct as_external_lsa
*)lsa
->data
;
5930 show_ip_ospf_database_header(vty
, lsa
);
5932 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(al
->mask
));
5933 vty_out(vty
, " Metric Type: %s\n",
5934 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
5935 ? "2 (Larger than any link state path)"
5937 vty_out(vty
, " TOS: 0\n");
5938 vty_out(vty
, " Metric: %d\n",
5939 GET_METRIC(al
->e
[0].metric
));
5940 vty_out(vty
, " Forward Address: %s\n",
5941 inet_ntoa(al
->e
[0].fwd_addr
));
5944 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
5945 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
5952 show_as_external_lsa_stdvty (struct ospf_lsa
*lsa
)
5954 struct as_external_lsa
*al
= (struct as_external_lsa
*) lsa
->data
;
5956 /* show_ip_ospf_database_header (vty, lsa); */
5958 zlog_debug( " Network Mask: /%d%s",
5959 ip_masklen (al
->mask
), "\n");
5960 zlog_debug( " Metric Type: %s%s",
5961 IS_EXTERNAL_METRIC (al
->e
[0].tos
) ?
5962 "2 (Larger than any link state path)" : "1", "\n");
5963 zlog_debug( " TOS: 0%s", "\n");
5964 zlog_debug( " Metric: %d%s",
5965 GET_METRIC (al
->e
[0].metric
), "\n");
5966 zlog_debug( " Forward Address: %s%s",
5967 inet_ntoa (al
->e
[0].fwd_addr
), "\n");
5969 zlog_debug( " External Route Tag: %"ROUTE_TAG_PRI
"%s%s",
5970 (route_tag_t
)ntohl (al
->e
[0].route_tag
), "\n", "\n");
5975 /* Show AS-NSSA-LSA detail information. */
5976 static int show_as_nssa_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5979 struct as_external_lsa
*al
=
5980 (struct as_external_lsa
*)lsa
->data
;
5982 show_ip_ospf_database_header(vty
, lsa
);
5984 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(al
->mask
));
5985 vty_out(vty
, " Metric Type: %s\n",
5986 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
5987 ? "2 (Larger than any link state path)"
5989 vty_out(vty
, " TOS: 0\n");
5990 vty_out(vty
, " Metric: %d\n",
5991 GET_METRIC(al
->e
[0].metric
));
5992 vty_out(vty
, " NSSA: Forward Address: %s\n",
5993 inet_ntoa(al
->e
[0].fwd_addr
));
5996 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
5997 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6003 static int show_func_dummy(struct vty
*vty
, struct ospf_lsa
*lsa
)
6008 static int show_opaque_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
6011 show_ip_ospf_database_header(vty
, lsa
);
6012 show_opaque_info_detail(vty
, lsa
);
6019 int (*show_function
[])(struct vty
*, struct ospf_lsa
*) = {
6021 show_router_lsa_detail
,
6022 show_network_lsa_detail
,
6023 show_summary_lsa_detail
,
6024 show_summary_asbr_lsa_detail
,
6025 show_as_external_lsa_detail
,
6027 show_as_nssa_lsa_detail
, /* almost same as external */
6029 show_opaque_lsa_detail
,
6030 show_opaque_lsa_detail
,
6031 show_opaque_lsa_detail
,
6034 static void show_lsa_prefix_set(struct vty
*vty
, struct prefix_ls
*lp
,
6035 struct in_addr
*id
, struct in_addr
*adv_router
)
6037 memset(lp
, 0, sizeof(struct prefix_ls
));
6041 else if (adv_router
== NULL
) {
6047 lp
->adv_router
= *adv_router
;
6051 static void show_lsa_detail_proc(struct vty
*vty
, struct route_table
*rt
,
6052 struct in_addr
*id
, struct in_addr
*adv_router
)
6054 struct prefix_ls lp
;
6055 struct route_node
*rn
, *start
;
6056 struct ospf_lsa
*lsa
;
6058 show_lsa_prefix_set(vty
, &lp
, id
, adv_router
);
6059 start
= route_node_get(rt
, (struct prefix
*)&lp
);
6061 route_lock_node(start
);
6062 for (rn
= start
; rn
; rn
= route_next_until(rn
, start
))
6063 if ((lsa
= rn
->info
)) {
6064 if (show_function
[lsa
->data
->type
] != NULL
)
6065 show_function
[lsa
->data
->type
](vty
,
6068 route_unlock_node(start
);
6072 /* Show detail LSA information
6073 -- if id is NULL then show all LSAs. */
6074 static void show_lsa_detail(struct vty
*vty
, struct ospf
*ospf
, int type
,
6075 struct in_addr
*id
, struct in_addr
*adv_router
)
6077 struct listnode
*node
;
6078 struct ospf_area
*area
;
6081 case OSPF_AS_EXTERNAL_LSA
:
6082 case OSPF_OPAQUE_AS_LSA
:
6083 vty_out(vty
, " %s \n\n",
6084 show_database_desc
[type
]);
6085 show_lsa_detail_proc(vty
, AS_LSDB(ospf
, type
), id
, adv_router
);
6088 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6089 vty_out(vty
, "\n %s (Area %s)\n\n",
6090 show_database_desc
[type
],
6091 ospf_area_desc_string(area
));
6092 show_lsa_detail_proc(vty
, AREA_LSDB(area
, type
), id
,
6099 static void show_lsa_detail_adv_router_proc(struct vty
*vty
,
6100 struct route_table
*rt
,
6101 struct in_addr
*adv_router
)
6103 struct route_node
*rn
;
6104 struct ospf_lsa
*lsa
;
6106 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
))
6107 if ((lsa
= rn
->info
))
6108 if (IPV4_ADDR_SAME(adv_router
,
6109 &lsa
->data
->adv_router
)) {
6110 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
6112 if (show_function
[lsa
->data
->type
] != NULL
)
6113 show_function
[lsa
->data
->type
](vty
,
6118 /* Show detail LSA information. */
6119 static void show_lsa_detail_adv_router(struct vty
*vty
, struct ospf
*ospf
,
6120 int type
, struct in_addr
*adv_router
)
6122 struct listnode
*node
;
6123 struct ospf_area
*area
;
6126 case OSPF_AS_EXTERNAL_LSA
:
6127 case OSPF_OPAQUE_AS_LSA
:
6128 vty_out(vty
, " %s \n\n",
6129 show_database_desc
[type
]);
6130 show_lsa_detail_adv_router_proc(vty
, AS_LSDB(ospf
, type
),
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_adv_router_proc(
6139 vty
, AREA_LSDB(area
, type
), adv_router
);
6145 static void show_ip_ospf_database_summary(struct vty
*vty
, struct ospf
*ospf
,
6148 struct ospf_lsa
*lsa
;
6149 struct route_node
*rn
;
6150 struct ospf_area
*area
;
6151 struct listnode
*node
;
6154 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6155 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6157 case OSPF_AS_EXTERNAL_LSA
:
6158 case OSPF_OPAQUE_AS_LSA
:
6163 if (ospf_lsdb_count_self(area
->lsdb
, type
) > 0
6165 && ospf_lsdb_count(area
->lsdb
, type
) > 0)) {
6166 vty_out(vty
, " %s (Area %s)\n\n",
6167 show_database_desc
[type
],
6168 ospf_area_desc_string(area
));
6169 vty_out(vty
, "%s\n",
6170 show_database_header
[type
]);
6172 LSDB_LOOP (AREA_LSDB(area
, type
), rn
, lsa
)
6173 show_lsa_summary(vty
, lsa
, self
);
6180 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6182 case OSPF_AS_EXTERNAL_LSA
:
6183 case OSPF_OPAQUE_AS_LSA
:
6188 if (ospf_lsdb_count_self(ospf
->lsdb
, type
)
6189 || (!self
&& ospf_lsdb_count(ospf
->lsdb
, type
))) {
6190 vty_out(vty
, " %s\n\n",
6191 show_database_desc
[type
]);
6192 vty_out(vty
, "%s\n", show_database_header
[type
]);
6194 LSDB_LOOP (AS_LSDB(ospf
, type
), rn
, lsa
)
6195 show_lsa_summary(vty
, lsa
, self
);
6204 static void show_ip_ospf_database_maxage(struct vty
*vty
, struct ospf
*ospf
)
6206 struct route_node
*rn
;
6208 vty_out(vty
, "\n MaxAge Link States:\n\n");
6210 for (rn
= route_top(ospf
->maxage_lsa
); rn
; rn
= route_next(rn
)) {
6211 struct ospf_lsa
*lsa
;
6213 if ((lsa
= rn
->info
) != NULL
) {
6214 vty_out(vty
, "Link type: %d\n", lsa
->data
->type
);
6215 vty_out(vty
, "Link State ID: %s\n",
6216 inet_ntoa(lsa
->data
->id
));
6217 vty_out(vty
, "Advertising Router: %s\n",
6218 inet_ntoa(lsa
->data
->adv_router
));
6219 vty_out(vty
, "LSA lock count: %d\n", lsa
->lock
);
6225 #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
6226 #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
6228 #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
6229 #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
6230 #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
6231 #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
6233 #define OSPF_LSA_TYPES_DESC \
6234 "ASBR summary link states\n" \
6235 "External link states\n" \
6236 "Network link states\n" \
6237 "Router link states\n" \
6238 "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \
6239 OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
6240 OSPF_LSA_TYPE_OPAQUE_AS_DESC
6242 static int show_ip_ospf_database_common(struct vty
*vty
, struct ospf
*ospf
,
6243 int arg_base
, int argc
,
6244 struct cmd_token
**argv
,
6249 struct in_addr id
, adv_router
;
6252 vty_out(vty
, "\nOSPF Instance: %d\n", ospf
->instance
);
6254 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
6256 vty_out(vty
, "\n OSPF Router with ID (%s)\n\n",
6257 inet_ntoa(ospf
->router_id
));
6260 if (argc
== arg_base
+ 4) {
6261 show_ip_ospf_database_summary(vty
, ospf
, 0);
6265 /* Set database type to show. */
6266 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
6267 type
= OSPF_ROUTER_LSA
;
6268 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
6269 type
= OSPF_NETWORK_LSA
;
6270 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
6271 type
= OSPF_AS_NSSA_LSA
;
6272 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "su", 2) == 0)
6273 type
= OSPF_SUMMARY_LSA
;
6274 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
6275 type
= OSPF_ASBR_SUMMARY_LSA
;
6276 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
6277 type
= OSPF_AS_EXTERNAL_LSA
;
6278 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "se", 2) == 0) {
6279 show_ip_ospf_database_summary(vty
, ospf
, 1);
6281 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "m", 1) == 0) {
6282 show_ip_ospf_database_maxage(vty
, ospf
);
6284 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
6285 type
= OSPF_OPAQUE_LINK_LSA
;
6286 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
6287 type
= OSPF_OPAQUE_AREA_LSA
;
6288 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
6289 type
= OSPF_OPAQUE_AS_LSA
;
6293 /* `show ip ospf database LSA'. */
6294 if (argc
== arg_base
+ 5)
6295 show_lsa_detail(vty
, ospf
, type
, NULL
, NULL
);
6296 else if (argc
>= arg_base
+ 6) {
6297 ret
= inet_aton(argv
[arg_base
+ 5]->arg
, &id
);
6301 /* `show ip ospf database LSA ID'. */
6302 if (argc
== arg_base
+ 6)
6303 show_lsa_detail(vty
, ospf
, type
, &id
, NULL
);
6304 /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */
6305 else if (argc
== arg_base
+ 7) {
6306 if (strncmp(argv
[arg_base
+ 6]->text
, "s", 1) == 0)
6307 adv_router
= ospf
->router_id
;
6309 ret
= inet_aton(argv
[arg_base
+ 7]->arg
,
6314 show_lsa_detail(vty
, ospf
, type
, &id
, &adv_router
);
6321 DEFUN (show_ip_ospf_database_max
,
6322 show_ip_ospf_database_max_cmd
,
6323 "show ip ospf [vrf <NAME|all>] database <max-age|self-originate>",
6326 "OSPF information\n"
6329 "Database summary\n"
6330 "LSAs in MaxAge list\n"
6331 "Self-originated link states\n")
6333 struct ospf
*ospf
= NULL
;
6334 struct listnode
*node
= NULL
;
6335 char *vrf_name
= NULL
;
6336 bool all_vrf
= FALSE
;
6337 int ret
= CMD_SUCCESS
;
6340 uint8_t use_vrf
= 0;
6342 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
6345 bool ospf_output
= FALSE
;
6350 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6351 if (!ospf
->oi_running
)
6354 ret
= show_ip_ospf_database_common(
6355 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
,
6360 vty_out(vty
, "%% OSPF instance not found\n");
6362 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6363 if (ospf
== NULL
|| !ospf
->oi_running
) {
6364 vty_out(vty
, "%% OSPF instance not found\n");
6367 ret
= (show_ip_ospf_database_common(
6368 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
,
6372 /* Display default ospf (instance 0) info */
6373 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6374 if (ospf
== NULL
|| !ospf
->oi_running
) {
6375 vty_out(vty
, "%% OSPF instance not found\n");
6379 ret
= show_ip_ospf_database_common(vty
, ospf
, 0, argc
, argv
,
6386 DEFUN (show_ip_ospf_instance_database
,
6387 show_ip_ospf_instance_database_cmd
,
6388 "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>]]]",
6391 "OSPF information\n"
6394 "Database summary\n"
6396 "Link State ID (as an IP address)\n"
6397 "Self-originated link states\n"
6398 "Advertising Router link states\n"
6399 "Advertising Router (as an IP address)\n")
6402 unsigned short instance
= 0;
6403 struct listnode
*node
= NULL
;
6404 char *vrf_name
= NULL
;
6405 bool all_vrf
= FALSE
;
6406 int ret
= CMD_SUCCESS
;
6409 uint8_t use_vrf
= 0;
6411 if (argv_find(argv
, argc
, "(1-65535)", &idx
)) {
6412 instance
= strtoul(argv
[idx
]->arg
, NULL
, 10);
6413 ospf
= ospf_lookup_instance(instance
);
6415 return CMD_NOT_MY_INSTANCE
;
6416 if (!ospf
->oi_running
)
6419 return (show_ip_ospf_database_common(vty
, ospf
, idx
? 1 : 0,
6420 argc
, argv
, use_vrf
));
6421 } else if (argv_find(argv
, argc
, "vrf", &idx
)) {
6422 vrf_name
= argv
[++idx
]->arg
;
6423 all_vrf
= strmatch(vrf_name
, "all");
6429 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6430 if (!ospf
->oi_running
)
6432 ret
= (show_ip_ospf_database_common(
6433 vty
, ospf
, idx
? 2 : 0, argc
, argv
,
6437 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6438 if ((ospf
== NULL
) || !ospf
->oi_running
) {
6439 vty_out(vty
, "%% OSPF instance not found\n");
6443 ret
= (show_ip_ospf_database_common(
6444 vty
, ospf
, idx
? 2 : 0, argc
, argv
, use_vrf
));
6447 /* Display default ospf (instance 0) info */
6448 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6449 if (ospf
== NULL
|| !ospf
->oi_running
) {
6450 vty_out(vty
, "%% OSPF instance not found\n");
6454 ret
= (show_ip_ospf_database_common(vty
, ospf
, 0, argc
, argv
,
6461 DEFUN (show_ip_ospf_instance_database_max
,
6462 show_ip_ospf_instance_database_max_cmd
,
6463 "show ip ospf (1-65535) database <max-age|self-originate>",
6466 "OSPF information\n"
6468 "Database summary\n"
6469 "LSAs in MaxAge list\n"
6470 "Self-originated link states\n")
6474 unsigned short instance
= 0;
6476 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
6478 ospf
= ospf_lookup_instance(instance
);
6480 return CMD_NOT_MY_INSTANCE
;
6482 if (!ospf
->oi_running
) {
6483 vty_out(vty
, "%% OSPF instance not found\n");
6487 return show_ip_ospf_database_common(vty
, ospf
, 1, argc
, argv
, 0);
6491 static int show_ip_ospf_database_type_adv_router_common(struct vty
*vty
,
6493 int arg_base
, int argc
,
6494 struct cmd_token
**argv
,
6499 struct in_addr adv_router
;
6502 vty_out(vty
, "\nOSPF Instance: %d\n", ospf
->instance
);
6504 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
6506 vty_out(vty
, "\n OSPF Router with ID (%s)\n\n",
6507 inet_ntoa(ospf
->router_id
));
6509 /* Set database type to show. */
6510 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
6511 type
= OSPF_ROUTER_LSA
;
6512 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
6513 type
= OSPF_NETWORK_LSA
;
6514 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
6515 type
= OSPF_AS_NSSA_LSA
;
6516 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "s", 1) == 0)
6517 type
= OSPF_SUMMARY_LSA
;
6518 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
6519 type
= OSPF_ASBR_SUMMARY_LSA
;
6520 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
6521 type
= OSPF_AS_EXTERNAL_LSA
;
6522 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
6523 type
= OSPF_OPAQUE_LINK_LSA
;
6524 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
6525 type
= OSPF_OPAQUE_AREA_LSA
;
6526 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
6527 type
= OSPF_OPAQUE_AS_LSA
;
6531 /* `show ip ospf database LSA adv-router ADV_ROUTER'. */
6532 if (strncmp(argv
[arg_base
+ 5]->text
, "s", 1) == 0)
6533 adv_router
= ospf
->router_id
;
6535 ret
= inet_aton(argv
[arg_base
+ 6]->arg
, &adv_router
);
6540 show_lsa_detail_adv_router(vty
, ospf
, type
, &adv_router
);
6545 DEFUN (show_ip_ospf_instance_database_type_adv_router
,
6546 show_ip_ospf_instance_database_type_adv_router_cmd
,
6547 "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>",
6550 "OSPF information\n"
6553 "Database summary\n"
6555 "Advertising Router link states\n"
6556 "Advertising Router (as an IP address)\n"
6557 "Self-originated link states\n")
6559 struct ospf
*ospf
= NULL
;
6560 unsigned short instance
= 0;
6561 struct listnode
*node
= NULL
;
6562 char *vrf_name
= NULL
;
6563 bool all_vrf
= FALSE
;
6564 int ret
= CMD_SUCCESS
;
6566 int idx
= 0, idx_vrf
= 0;
6567 uint8_t use_vrf
= 0;
6569 if (argv_find(argv
, argc
, "(1-65535)", &idx
)) {
6570 instance
= strtoul(argv
[idx
]->arg
, NULL
, 10);
6571 ospf
= ospf_lookup_instance(instance
);
6573 return CMD_NOT_MY_INSTANCE
;
6574 if (!ospf
->oi_running
) {
6575 vty_out(vty
, "%% OSPF instance not found\n");
6579 return (show_ip_ospf_database_type_adv_router_common(
6580 vty
, ospf
, idx
? 1 : 0, argc
, argv
, use_vrf
));
6583 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
6586 bool ospf_output
= FALSE
;
6591 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6592 if (!ospf
->oi_running
)
6595 ret
= show_ip_ospf_database_type_adv_router_common(
6596 vty
, ospf
, idx
? 1 : 0, argc
, argv
,
6600 vty_out(vty
, "%% OSPF instance not found\n");
6602 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6603 if ((ospf
== NULL
) || !ospf
->oi_running
) {
6604 vty_out(vty
, "%% OSPF instance not found\n");
6608 ret
= show_ip_ospf_database_type_adv_router_common(
6609 vty
, ospf
, idx
? 1 : 0, argc
, argv
, use_vrf
);
6612 /* Display default ospf (instance 0) info */
6613 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6614 if (ospf
== NULL
|| !ospf
->oi_running
) {
6615 vty_out(vty
, "%% OSPF instance not found\n");
6619 ret
= show_ip_ospf_database_type_adv_router_common(
6620 vty
, ospf
, idx
? 1 : 0, argc
, argv
, use_vrf
);
6623 /*return (show_ip_ospf_database_type_adv_router_common(
6624 vty, ospf, idx ? 1 : 0, argc, argv));*/
6627 DEFUN (ip_ospf_authentication_args
,
6628 ip_ospf_authentication_args_addr_cmd
,
6629 "ip ospf authentication <null|message-digest> [A.B.C.D]",
6631 "OSPF interface commands\n"
6632 "Enable authentication on this interface\n"
6633 "Use null authentication\n"
6634 "Use message-digest authentication\n"
6635 "Address of interface\n")
6637 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6638 int idx_encryption
= 3;
6640 struct in_addr addr
;
6642 struct ospf_if_params
*params
;
6644 params
= IF_DEF_PARAMS(ifp
);
6647 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6650 "Please specify interface address by A.B.C.D\n");
6651 return CMD_WARNING_CONFIG_FAILED
;
6654 params
= ospf_get_if_params(ifp
, addr
);
6655 ospf_if_update_params(ifp
, addr
);
6658 /* Handle null authentication */
6659 if (argv
[idx_encryption
]->arg
[0] == 'n') {
6660 SET_IF_PARAM(params
, auth_type
);
6661 params
->auth_type
= OSPF_AUTH_NULL
;
6665 /* Handle message-digest authentication */
6666 if (argv
[idx_encryption
]->arg
[0] == 'm') {
6667 SET_IF_PARAM(params
, auth_type
);
6668 params
->auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
6672 vty_out(vty
, "You shouldn't get here!\n");
6673 return CMD_WARNING_CONFIG_FAILED
;
6676 DEFUN (ip_ospf_authentication
,
6677 ip_ospf_authentication_addr_cmd
,
6678 "ip ospf authentication [A.B.C.D]",
6680 "OSPF interface commands\n"
6681 "Enable authentication on this interface\n"
6682 "Address of interface\n")
6684 VTY_DECLVAR_CONTEXT(interface
, ifp
);
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 SET_IF_PARAM(params
, auth_type
);
6705 params
->auth_type
= OSPF_AUTH_SIMPLE
;
6710 DEFUN (no_ip_ospf_authentication_args
,
6711 no_ip_ospf_authentication_args_addr_cmd
,
6712 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
6715 "OSPF interface commands\n"
6716 "Enable authentication on this interface\n"
6717 "Use null authentication\n"
6718 "Use message-digest authentication\n"
6719 "Address of interface\n")
6721 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6722 int idx_encryption
= 4;
6724 struct in_addr addr
;
6726 struct ospf_if_params
*params
;
6727 struct route_node
*rn
;
6730 params
= IF_DEF_PARAMS(ifp
);
6733 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6736 "Please specify interface address by A.B.C.D\n");
6737 return CMD_WARNING_CONFIG_FAILED
;
6740 params
= ospf_lookup_if_params(ifp
, addr
);
6741 if (params
== NULL
) {
6742 vty_out(vty
, "Ip Address specified is unknown\n");
6743 return CMD_WARNING_CONFIG_FAILED
;
6745 params
->auth_type
= OSPF_AUTH_NOTSET
;
6746 UNSET_IF_PARAM(params
, auth_type
);
6747 if (params
!= IF_DEF_PARAMS(ifp
)) {
6748 ospf_free_if_params(ifp
, addr
);
6749 ospf_if_update_params(ifp
, addr
);
6752 if (argv
[idx_encryption
]->arg
[0] == 'n') {
6753 auth_type
= OSPF_AUTH_NULL
;
6754 } else if (argv
[idx_encryption
]->arg
[0] == 'm') {
6755 auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
6757 vty_out(vty
, "Unexpected input encountered\n");
6758 return CMD_WARNING_CONFIG_FAILED
;
6761 * Here we have a case where the user has entered
6762 * 'no ip ospf authentication (null | message_digest )'
6763 * we need to find if we have any ip addresses underneath it
6765 * correspond to the associated type.
6767 if (params
->auth_type
== auth_type
) {
6768 params
->auth_type
= OSPF_AUTH_NOTSET
;
6769 UNSET_IF_PARAM(params
, auth_type
);
6772 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
6773 rn
= route_next(rn
)) {
6774 if ((params
= rn
->info
)) {
6775 if (params
->auth_type
== auth_type
) {
6776 params
->auth_type
= OSPF_AUTH_NOTSET
;
6777 UNSET_IF_PARAM(params
, auth_type
);
6778 if (params
!= IF_DEF_PARAMS(ifp
)) {
6779 ospf_free_if_params(
6780 ifp
, rn
->p
.u
.prefix4
);
6781 ospf_if_update_params(
6782 ifp
, rn
->p
.u
.prefix4
);
6792 DEFUN (no_ip_ospf_authentication
,
6793 no_ip_ospf_authentication_addr_cmd
,
6794 "no ip ospf authentication [A.B.C.D]",
6797 "OSPF interface commands\n"
6798 "Enable authentication on this interface\n"
6799 "Address of interface\n")
6801 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6803 struct in_addr addr
;
6805 struct ospf_if_params
*params
;
6806 struct route_node
*rn
;
6808 params
= IF_DEF_PARAMS(ifp
);
6811 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6814 "Please specify interface address by A.B.C.D\n");
6815 return CMD_WARNING_CONFIG_FAILED
;
6818 params
= ospf_lookup_if_params(ifp
, addr
);
6819 if (params
== NULL
) {
6820 vty_out(vty
, "Ip Address specified is unknown\n");
6821 return CMD_WARNING_CONFIG_FAILED
;
6824 params
->auth_type
= OSPF_AUTH_NOTSET
;
6825 UNSET_IF_PARAM(params
, auth_type
);
6826 if (params
!= IF_DEF_PARAMS(ifp
)) {
6827 ospf_free_if_params(ifp
, addr
);
6828 ospf_if_update_params(ifp
, addr
);
6832 * When a user enters 'no ip ospf authentication'
6833 * We should remove all authentication types from
6836 if ((params
->auth_type
== OSPF_AUTH_NULL
)
6837 || (params
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
6838 || (params
->auth_type
== OSPF_AUTH_SIMPLE
)) {
6839 params
->auth_type
= OSPF_AUTH_NOTSET
;
6840 UNSET_IF_PARAM(params
, auth_type
);
6843 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
6844 rn
= route_next(rn
)) {
6845 if ((params
= rn
->info
)) {
6847 if ((params
->auth_type
== OSPF_AUTH_NULL
)
6848 || (params
->auth_type
6849 == OSPF_AUTH_CRYPTOGRAPHIC
)
6850 || (params
->auth_type
6851 == OSPF_AUTH_SIMPLE
)) {
6852 params
->auth_type
= OSPF_AUTH_NOTSET
;
6853 UNSET_IF_PARAM(params
, auth_type
);
6854 if (params
!= IF_DEF_PARAMS(ifp
)) {
6855 ospf_free_if_params(
6856 ifp
, rn
->p
.u
.prefix4
);
6857 ospf_if_update_params(
6858 ifp
, rn
->p
.u
.prefix4
);
6869 DEFUN (ip_ospf_authentication_key
,
6870 ip_ospf_authentication_key_addr_cmd
,
6871 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
6873 "OSPF interface commands\n"
6874 "Authentication password (key)\n"
6875 "The OSPF password (key)\n"
6876 "Address of interface\n")
6878 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6880 struct in_addr addr
;
6881 struct ospf_if_params
*params
;
6883 params
= IF_DEF_PARAMS(ifp
);
6885 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6886 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6888 "Please specify interface address by A.B.C.D\n");
6889 return CMD_WARNING_CONFIG_FAILED
;
6892 params
= ospf_get_if_params(ifp
, addr
);
6893 ospf_if_update_params(ifp
, addr
);
6896 memset(params
->auth_simple
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
6897 strncpy((char *)params
->auth_simple
, argv
[3]->arg
,
6898 OSPF_AUTH_SIMPLE_SIZE
);
6899 SET_IF_PARAM(params
, auth_simple
);
6904 DEFUN_HIDDEN (ospf_authentication_key
,
6905 ospf_authentication_key_cmd
,
6906 "ospf authentication-key AUTH_KEY [A.B.C.D]",
6907 "OSPF interface commands\n"
6908 VLINK_HELPSTR_AUTH_SIMPLE
6909 "Address of interface\n")
6911 return ip_ospf_authentication_key(self
, vty
, argc
, argv
);
6914 DEFUN (no_ip_ospf_authentication_key
,
6915 no_ip_ospf_authentication_key_authkey_addr_cmd
,
6916 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
6919 "OSPF interface commands\n"
6920 VLINK_HELPSTR_AUTH_SIMPLE
6921 "Address of interface\n")
6923 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6925 struct in_addr addr
;
6926 struct ospf_if_params
*params
;
6927 params
= IF_DEF_PARAMS(ifp
);
6929 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6930 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6932 "Please specify interface address by A.B.C.D\n");
6933 return CMD_WARNING_CONFIG_FAILED
;
6936 params
= ospf_lookup_if_params(ifp
, addr
);
6941 memset(params
->auth_simple
, 0, OSPF_AUTH_SIMPLE_SIZE
);
6942 UNSET_IF_PARAM(params
, auth_simple
);
6944 if (params
!= IF_DEF_PARAMS(ifp
)) {
6945 ospf_free_if_params(ifp
, addr
);
6946 ospf_if_update_params(ifp
, addr
);
6952 DEFUN_HIDDEN (no_ospf_authentication_key
,
6953 no_ospf_authentication_key_authkey_addr_cmd
,
6954 "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
6956 "OSPF interface commands\n"
6957 VLINK_HELPSTR_AUTH_SIMPLE
6958 "Address of interface\n")
6960 return no_ip_ospf_authentication_key(self
, vty
, argc
, argv
);
6963 DEFUN (ip_ospf_message_digest_key
,
6964 ip_ospf_message_digest_key_cmd
,
6965 "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
6967 "OSPF interface commands\n"
6968 "Message digest authentication password (key)\n"
6970 "Use MD5 algorithm\n"
6971 "The OSPF password (key)\n"
6972 "Address of interface\n")
6974 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6975 struct crypt_key
*ck
;
6977 struct in_addr addr
;
6978 struct ospf_if_params
*params
;
6980 params
= IF_DEF_PARAMS(ifp
);
6983 argv_find(argv
, argc
, "(1-255)", &idx
);
6984 char *keyid
= argv
[idx
]->arg
;
6985 argv_find(argv
, argc
, "KEY", &idx
);
6986 char *cryptkey
= argv
[idx
]->arg
;
6988 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6989 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6991 "Please specify interface address by A.B.C.D\n");
6992 return CMD_WARNING_CONFIG_FAILED
;
6995 params
= ospf_get_if_params(ifp
, addr
);
6996 ospf_if_update_params(ifp
, addr
);
6999 key_id
= strtol(keyid
, NULL
, 10);
7000 if (ospf_crypt_key_lookup(params
->auth_crypt
, key_id
) != NULL
) {
7001 vty_out(vty
, "OSPF: Key %d already exists\n", key_id
);
7005 ck
= ospf_crypt_key_new();
7006 ck
->key_id
= (uint8_t)key_id
;
7007 memset(ck
->auth_key
, 0, OSPF_AUTH_MD5_SIZE
+ 1);
7008 strncpy((char *)ck
->auth_key
, cryptkey
, OSPF_AUTH_MD5_SIZE
);
7010 ospf_crypt_key_add(params
->auth_crypt
, ck
);
7011 SET_IF_PARAM(params
, auth_crypt
);
7016 DEFUN_HIDDEN (ospf_message_digest_key
,
7017 ospf_message_digest_key_cmd
,
7018 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7019 "OSPF interface commands\n"
7020 "Message digest authentication password (key)\n"
7022 "Use MD5 algorithm\n"
7023 "The OSPF password (key)\n"
7024 "Address of interface\n")
7026 return ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7029 DEFUN (no_ip_ospf_message_digest_key
,
7030 no_ip_ospf_message_digest_key_cmd
,
7031 "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7034 "OSPF interface commands\n"
7035 "Message digest authentication password (key)\n"
7037 "Use MD5 algorithm\n"
7038 "The OSPF password (key)\n"
7039 "Address of interface\n")
7041 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7043 struct crypt_key
*ck
;
7045 struct in_addr addr
;
7046 struct ospf_if_params
*params
;
7047 params
= IF_DEF_PARAMS(ifp
);
7049 argv_find(argv
, argc
, "(1-255)", &idx
);
7050 char *keyid
= argv
[idx
]->arg
;
7052 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7053 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7055 "Please specify interface address by A.B.C.D\n");
7056 return CMD_WARNING_CONFIG_FAILED
;
7059 params
= ospf_lookup_if_params(ifp
, addr
);
7064 key_id
= strtol(keyid
, NULL
, 10);
7065 ck
= ospf_crypt_key_lookup(params
->auth_crypt
, key_id
);
7067 vty_out(vty
, "OSPF: Key %d does not exist\n", key_id
);
7068 return CMD_WARNING_CONFIG_FAILED
;
7071 ospf_crypt_key_delete(params
->auth_crypt
, key_id
);
7073 if (params
!= IF_DEF_PARAMS(ifp
)) {
7074 ospf_free_if_params(ifp
, addr
);
7075 ospf_if_update_params(ifp
, addr
);
7081 DEFUN_HIDDEN (no_ospf_message_digest_key
,
7082 no_ospf_message_digest_key_cmd
,
7083 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7085 "OSPF interface commands\n"
7086 "Message digest authentication password (key)\n"
7088 "Use MD5 algorithm\n"
7089 "The OSPF password (key)\n"
7090 "Address of interface\n")
7092 return no_ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7095 DEFUN (ip_ospf_cost
,
7097 "ip ospf cost (1-65535) [A.B.C.D]",
7099 "OSPF interface commands\n"
7102 "Address of interface\n")
7104 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7106 uint32_t cost
= OSPF_OUTPUT_COST_DEFAULT
;
7107 struct in_addr addr
;
7108 struct ospf_if_params
*params
;
7109 params
= IF_DEF_PARAMS(ifp
);
7112 char *coststr
= NULL
, *ifaddr
= NULL
;
7114 argv_find(argv
, argc
, "(1-65535)", &idx
);
7115 coststr
= argv
[idx
]->arg
;
7116 cost
= strtol(coststr
, NULL
, 10);
7118 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7120 if (!inet_aton(ifaddr
, &addr
)) {
7122 "Please specify interface address by A.B.C.D\n");
7123 return CMD_WARNING_CONFIG_FAILED
;
7126 params
= ospf_get_if_params(ifp
, addr
);
7127 ospf_if_update_params(ifp
, addr
);
7130 SET_IF_PARAM(params
, output_cost_cmd
);
7131 params
->output_cost_cmd
= cost
;
7133 ospf_if_recalculate_output_cost(ifp
);
7138 DEFUN_HIDDEN (ospf_cost
,
7140 "ospf cost (1-65535) [A.B.C.D]",
7141 "OSPF interface commands\n"
7144 "Address of interface\n")
7146 return ip_ospf_cost(self
, vty
, argc
, argv
);
7149 DEFUN (no_ip_ospf_cost
,
7150 no_ip_ospf_cost_cmd
,
7151 "no ip ospf cost [(1-65535)] [A.B.C.D]",
7154 "OSPF interface commands\n"
7157 "Address of interface\n")
7159 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7161 struct in_addr addr
;
7162 struct ospf_if_params
*params
;
7164 params
= IF_DEF_PARAMS(ifp
);
7167 char *ifaddr
= NULL
;
7168 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7170 /* According to the semantics we are mimicking "no ip ospf cost N" is
7171 * always treated as "no ip ospf cost" regardless of the actual value
7172 * of N already configured for the interface. Thus ignore cost. */
7175 if (!inet_aton(ifaddr
, &addr
)) {
7177 "Please specify interface address by A.B.C.D\n");
7178 return CMD_WARNING_CONFIG_FAILED
;
7181 params
= ospf_lookup_if_params(ifp
, addr
);
7186 UNSET_IF_PARAM(params
, output_cost_cmd
);
7188 if (params
!= IF_DEF_PARAMS(ifp
)) {
7189 ospf_free_if_params(ifp
, addr
);
7190 ospf_if_update_params(ifp
, addr
);
7193 ospf_if_recalculate_output_cost(ifp
);
7198 DEFUN_HIDDEN (no_ospf_cost
,
7200 "no ospf cost [(1-65535)] [A.B.C.D]",
7202 "OSPF interface commands\n"
7205 "Address of interface\n")
7207 return no_ip_ospf_cost(self
, vty
, argc
, argv
);
7210 static void ospf_nbr_timer_update(struct ospf_interface
*oi
)
7212 struct route_node
*rn
;
7213 struct ospf_neighbor
*nbr
;
7215 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
7216 if ((nbr
= rn
->info
)) {
7217 nbr
->v_inactivity
= OSPF_IF_PARAM(oi
, v_wait
);
7218 nbr
->v_db_desc
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7219 nbr
->v_ls_req
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7220 nbr
->v_ls_upd
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7224 static int ospf_vty_dead_interval_set(struct vty
*vty
, const char *interval_str
,
7225 const char *nbr_str
,
7226 const char *fast_hello_str
)
7228 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7231 struct in_addr addr
;
7233 struct ospf_if_params
*params
;
7234 struct ospf_interface
*oi
;
7235 struct route_node
*rn
;
7237 params
= IF_DEF_PARAMS(ifp
);
7240 ret
= inet_aton(nbr_str
, &addr
);
7243 "Please specify interface address by A.B.C.D\n");
7244 return CMD_WARNING_CONFIG_FAILED
;
7247 params
= ospf_get_if_params(ifp
, addr
);
7248 ospf_if_update_params(ifp
, addr
);
7252 seconds
= strtoul(interval_str
, NULL
, 10);
7254 /* reset fast_hello too, just to be sure */
7255 UNSET_IF_PARAM(params
, fast_hello
);
7256 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
7257 } else if (fast_hello_str
) {
7258 hellomult
= strtoul(fast_hello_str
, NULL
, 10);
7259 /* 1s dead-interval with sub-second hellos desired */
7260 seconds
= OSPF_ROUTER_DEAD_INTERVAL_MINIMAL
;
7261 SET_IF_PARAM(params
, fast_hello
);
7262 params
->fast_hello
= hellomult
;
7265 "Please specify dead-interval or hello-multiplier\n");
7266 return CMD_WARNING_CONFIG_FAILED
;
7269 SET_IF_PARAM(params
, v_wait
);
7270 params
->v_wait
= seconds
;
7272 /* Update timer values in neighbor structure. */
7274 struct ospf
*ospf
= NULL
;
7276 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7278 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
7280 ospf_nbr_timer_update(oi
);
7283 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
7284 if ((oi
= rn
->info
))
7285 ospf_nbr_timer_update(oi
);
7291 DEFUN (ip_ospf_dead_interval
,
7292 ip_ospf_dead_interval_cmd
,
7293 "ip ospf dead-interval (1-65535) [A.B.C.D]",
7295 "OSPF interface commands\n"
7296 "Interval time after which a neighbor is declared down\n"
7298 "Address of interface\n")
7301 char *interval
= argv_find(argv
, argc
, "(1-65535)", &idx
)
7305 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7306 return ospf_vty_dead_interval_set(vty
, interval
, ifaddr
, NULL
);
7310 DEFUN_HIDDEN (ospf_dead_interval
,
7311 ospf_dead_interval_cmd
,
7312 "ospf dead-interval (1-65535) [A.B.C.D]",
7313 "OSPF interface commands\n"
7314 "Interval time after which a neighbor is declared down\n"
7316 "Address of interface\n")
7318 return ip_ospf_dead_interval(self
, vty
, argc
, argv
);
7321 DEFUN (ip_ospf_dead_interval_minimal
,
7322 ip_ospf_dead_interval_minimal_addr_cmd
,
7323 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
7325 "OSPF interface commands\n"
7326 "Interval time after which a neighbor is declared down\n"
7327 "Minimal 1s dead-interval with fast sub-second hellos\n"
7328 "Hello multiplier factor\n"
7329 "Number of Hellos to send each second\n"
7330 "Address of interface\n")
7335 return ospf_vty_dead_interval_set(
7336 vty
, NULL
, argv
[idx_ipv4
]->arg
, argv
[idx_number
]->arg
);
7338 return ospf_vty_dead_interval_set(vty
, NULL
, NULL
,
7339 argv
[idx_number
]->arg
);
7342 DEFUN (no_ip_ospf_dead_interval
,
7343 no_ip_ospf_dead_interval_cmd
,
7344 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
7347 "OSPF interface commands\n"
7348 "Interval time after which a neighbor is declared down\n"
7350 "Minimal 1s dead-interval with fast sub-second hellos\n"
7351 "Hello multiplier factor\n"
7352 "Number of Hellos to send each second\n"
7353 "Address of interface\n")
7355 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7356 int idx_ipv4
= argc
- 1;
7357 struct in_addr addr
= {.s_addr
= 0L};
7359 struct ospf_if_params
*params
;
7360 struct ospf_interface
*oi
;
7361 struct route_node
*rn
;
7363 params
= IF_DEF_PARAMS(ifp
);
7365 if (argv
[idx_ipv4
]->type
== IPV4_TKN
) {
7366 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7369 "Please specify interface address by A.B.C.D\n");
7370 return CMD_WARNING_CONFIG_FAILED
;
7373 params
= ospf_lookup_if_params(ifp
, addr
);
7378 UNSET_IF_PARAM(params
, v_wait
);
7379 params
->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
7381 UNSET_IF_PARAM(params
, fast_hello
);
7382 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
7384 if (params
!= IF_DEF_PARAMS(ifp
)) {
7385 ospf_free_if_params(ifp
, addr
);
7386 ospf_if_update_params(ifp
, addr
);
7389 /* Update timer values in neighbor structure. */
7391 struct ospf
*ospf
= NULL
;
7393 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7395 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
7397 ospf_nbr_timer_update(oi
);
7400 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
7401 if ((oi
= rn
->info
))
7402 ospf_nbr_timer_update(oi
);
7408 DEFUN_HIDDEN (no_ospf_dead_interval
,
7409 no_ospf_dead_interval_cmd
,
7410 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
7412 "OSPF interface commands\n"
7413 "Interval time after which a neighbor is declared down\n"
7415 "Minimal 1s dead-interval with fast sub-second hellos\n"
7416 "Hello multiplier factor\n"
7417 "Number of Hellos to send each second\n"
7418 "Address of interface\n")
7420 return no_ip_ospf_dead_interval(self
, vty
, argc
, argv
);
7423 DEFUN (ip_ospf_hello_interval
,
7424 ip_ospf_hello_interval_cmd
,
7425 "ip ospf hello-interval (1-65535) [A.B.C.D]",
7427 "OSPF interface commands\n"
7428 "Time between HELLO packets\n"
7430 "Address of interface\n")
7432 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7434 struct in_addr addr
;
7435 struct ospf_if_params
*params
;
7436 params
= IF_DEF_PARAMS(ifp
);
7437 uint32_t seconds
= 0;
7439 argv_find(argv
, argc
, "(1-65535)", &idx
);
7440 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7442 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7443 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7445 "Please specify interface address by A.B.C.D\n");
7446 return CMD_WARNING_CONFIG_FAILED
;
7449 params
= ospf_get_if_params(ifp
, addr
);
7450 ospf_if_update_params(ifp
, addr
);
7453 SET_IF_PARAM(params
, v_hello
);
7454 params
->v_hello
= seconds
;
7459 DEFUN_HIDDEN (ospf_hello_interval
,
7460 ospf_hello_interval_cmd
,
7461 "ospf hello-interval (1-65535) [A.B.C.D]",
7462 "OSPF interface commands\n"
7463 "Time between HELLO packets\n"
7465 "Address of interface\n")
7467 return ip_ospf_hello_interval(self
, vty
, argc
, argv
);
7470 DEFUN (no_ip_ospf_hello_interval
,
7471 no_ip_ospf_hello_interval_cmd
,
7472 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
7475 "OSPF interface commands\n"
7476 "Time between HELLO packets\n" // ignored
7478 "Address of interface\n")
7480 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7482 struct in_addr addr
;
7483 struct ospf_if_params
*params
;
7485 params
= IF_DEF_PARAMS(ifp
);
7487 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7488 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7490 "Please specify interface address by A.B.C.D\n");
7491 return CMD_WARNING_CONFIG_FAILED
;
7494 params
= ospf_lookup_if_params(ifp
, addr
);
7499 UNSET_IF_PARAM(params
, v_hello
);
7500 params
->v_hello
= OSPF_HELLO_INTERVAL_DEFAULT
;
7502 if (params
!= IF_DEF_PARAMS(ifp
)) {
7503 ospf_free_if_params(ifp
, addr
);
7504 ospf_if_update_params(ifp
, addr
);
7510 DEFUN_HIDDEN (no_ospf_hello_interval
,
7511 no_ospf_hello_interval_cmd
,
7512 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
7514 "OSPF interface commands\n"
7515 "Time between HELLO packets\n" // ignored
7517 "Address of interface\n")
7519 return no_ip_ospf_hello_interval(self
, vty
, argc
, argv
);
7522 DEFUN (ip_ospf_network
,
7523 ip_ospf_network_cmd
,
7524 "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
7526 "OSPF interface commands\n"
7528 "Specify OSPF broadcast multi-access network\n"
7529 "Specify OSPF NBMA network\n"
7530 "Specify OSPF point-to-multipoint network\n"
7531 "Specify OSPF point-to-point network\n")
7533 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7535 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
7536 struct route_node
*rn
;
7538 if (old_type
== OSPF_IFTYPE_LOOPBACK
) {
7540 "This is a loopback interface. Can't set network type.\n");
7541 return CMD_WARNING_CONFIG_FAILED
;
7544 if (argv_find(argv
, argc
, "broadcast", &idx
))
7545 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_BROADCAST
;
7546 else if (argv_find(argv
, argc
, "non-broadcast", &idx
))
7547 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_NBMA
;
7548 else if (argv_find(argv
, argc
, "point-to-multipoint", &idx
))
7549 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOMULTIPOINT
;
7550 else if (argv_find(argv
, argc
, "point-to-point", &idx
))
7551 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOPOINT
;
7553 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
7556 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), type
);
7558 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7559 struct ospf_interface
*oi
= rn
->info
;
7564 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
7566 if (oi
->state
> ISM_Down
) {
7567 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
7568 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
7575 DEFUN_HIDDEN (ospf_network
,
7577 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
7578 "OSPF interface commands\n"
7580 "Specify OSPF broadcast multi-access network\n"
7581 "Specify OSPF NBMA network\n"
7582 "Specify OSPF point-to-multipoint network\n"
7583 "Specify OSPF point-to-point network\n")
7585 return ip_ospf_network(self
, vty
, argc
, argv
);
7588 DEFUN (no_ip_ospf_network
,
7589 no_ip_ospf_network_cmd
,
7590 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
7593 "OSPF interface commands\n"
7595 "Specify OSPF broadcast multi-access network\n"
7596 "Specify OSPF NBMA network\n"
7597 "Specify OSPF point-to-multipoint network\n"
7598 "Specify OSPF point-to-point network\n")
7600 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7601 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
7602 struct route_node
*rn
;
7604 IF_DEF_PARAMS(ifp
)->type
= ospf_default_iftype(ifp
);
7606 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
7609 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7610 struct ospf_interface
*oi
= rn
->info
;
7615 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
7617 if (oi
->state
> ISM_Down
) {
7618 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
7619 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
7626 DEFUN_HIDDEN (no_ospf_network
,
7627 no_ospf_network_cmd
,
7628 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
7630 "OSPF interface commands\n"
7632 "Specify OSPF broadcast multi-access network\n"
7633 "Specify OSPF NBMA network\n"
7634 "Specify OSPF point-to-multipoint network\n"
7635 "Specify OSPF point-to-point network\n")
7637 return no_ip_ospf_network(self
, vty
, argc
, argv
);
7640 DEFUN (ip_ospf_priority
,
7641 ip_ospf_priority_cmd
,
7642 "ip ospf priority (0-255) [A.B.C.D]",
7644 "OSPF interface commands\n"
7647 "Address of interface\n")
7649 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7652 struct route_node
*rn
;
7653 struct in_addr addr
;
7654 struct ospf_if_params
*params
;
7655 params
= IF_DEF_PARAMS(ifp
);
7657 argv_find(argv
, argc
, "(0-255)", &idx
);
7658 priority
= strtol(argv
[idx
]->arg
, NULL
, 10);
7660 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7661 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7663 "Please specify interface address by A.B.C.D\n");
7664 return CMD_WARNING_CONFIG_FAILED
;
7667 params
= ospf_get_if_params(ifp
, addr
);
7668 ospf_if_update_params(ifp
, addr
);
7671 SET_IF_PARAM(params
, priority
);
7672 params
->priority
= priority
;
7674 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7675 struct ospf_interface
*oi
= rn
->info
;
7680 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
7681 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
7682 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
7689 DEFUN_HIDDEN (ospf_priority
,
7691 "ospf priority (0-255) [A.B.C.D]",
7692 "OSPF interface commands\n"
7695 "Address of interface\n")
7697 return ip_ospf_priority(self
, vty
, argc
, argv
);
7700 DEFUN (no_ip_ospf_priority
,
7701 no_ip_ospf_priority_cmd
,
7702 "no ip ospf priority [(0-255) [A.B.C.D]]",
7705 "OSPF interface commands\n"
7706 "Router priority\n" // ignored
7708 "Address of interface\n")
7710 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7712 struct route_node
*rn
;
7713 struct in_addr addr
;
7714 struct ospf_if_params
*params
;
7716 params
= IF_DEF_PARAMS(ifp
);
7718 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7719 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7721 "Please specify interface address by A.B.C.D\n");
7722 return CMD_WARNING_CONFIG_FAILED
;
7725 params
= ospf_lookup_if_params(ifp
, addr
);
7730 UNSET_IF_PARAM(params
, priority
);
7731 params
->priority
= OSPF_ROUTER_PRIORITY_DEFAULT
;
7733 if (params
!= IF_DEF_PARAMS(ifp
)) {
7734 ospf_free_if_params(ifp
, addr
);
7735 ospf_if_update_params(ifp
, addr
);
7738 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7739 struct ospf_interface
*oi
= rn
->info
;
7744 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
7745 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
7746 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
7753 DEFUN_HIDDEN (no_ospf_priority
,
7754 no_ospf_priority_cmd
,
7755 "no ospf priority [(0-255) [A.B.C.D]]",
7757 "OSPF interface commands\n"
7760 "Address of interface\n")
7762 return no_ip_ospf_priority(self
, vty
, argc
, argv
);
7765 DEFUN (ip_ospf_retransmit_interval
,
7766 ip_ospf_retransmit_interval_addr_cmd
,
7767 "ip ospf retransmit-interval (3-65535) [A.B.C.D]",
7769 "OSPF interface commands\n"
7770 "Time between retransmitting lost link state advertisements\n"
7772 "Address of interface\n")
7774 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7777 struct in_addr addr
;
7778 struct ospf_if_params
*params
;
7779 params
= IF_DEF_PARAMS(ifp
);
7781 argv_find(argv
, argc
, "(3-65535)", &idx
);
7782 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7784 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7785 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7787 "Please specify interface address by A.B.C.D\n");
7788 return CMD_WARNING_CONFIG_FAILED
;
7791 params
= ospf_get_if_params(ifp
, addr
);
7792 ospf_if_update_params(ifp
, addr
);
7795 SET_IF_PARAM(params
, retransmit_interval
);
7796 params
->retransmit_interval
= seconds
;
7801 DEFUN_HIDDEN (ospf_retransmit_interval
,
7802 ospf_retransmit_interval_cmd
,
7803 "ospf retransmit-interval (3-65535) [A.B.C.D]",
7804 "OSPF interface commands\n"
7805 "Time between retransmitting lost link state advertisements\n"
7807 "Address of interface\n")
7809 return ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
7812 DEFUN (no_ip_ospf_retransmit_interval
,
7813 no_ip_ospf_retransmit_interval_addr_cmd
,
7814 "no ip ospf retransmit-interval [(3-65535)] [A.B.C.D]",
7817 "OSPF interface commands\n"
7818 "Time between retransmitting lost link state advertisements\n"
7820 "Address of interface\n")
7822 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7824 struct in_addr addr
;
7825 struct ospf_if_params
*params
;
7827 params
= IF_DEF_PARAMS(ifp
);
7829 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7830 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7832 "Please specify interface address by A.B.C.D\n");
7833 return CMD_WARNING_CONFIG_FAILED
;
7836 params
= ospf_lookup_if_params(ifp
, addr
);
7841 UNSET_IF_PARAM(params
, retransmit_interval
);
7842 params
->retransmit_interval
= OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
7844 if (params
!= IF_DEF_PARAMS(ifp
)) {
7845 ospf_free_if_params(ifp
, addr
);
7846 ospf_if_update_params(ifp
, addr
);
7852 DEFUN_HIDDEN (no_ospf_retransmit_interval
,
7853 no_ospf_retransmit_interval_cmd
,
7854 "no ospf retransmit-interval [(3-65535)] [A.B.C.D]",
7856 "OSPF interface commands\n"
7857 "Time between retransmitting lost link state advertisements\n"
7859 "Address of interface\n")
7861 return no_ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
7864 DEFUN (ip_ospf_transmit_delay
,
7865 ip_ospf_transmit_delay_addr_cmd
,
7866 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
7868 "OSPF interface commands\n"
7869 "Link state transmit delay\n"
7871 "Address of interface\n")
7873 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7876 struct in_addr addr
;
7877 struct ospf_if_params
*params
;
7879 params
= IF_DEF_PARAMS(ifp
);
7880 argv_find(argv
, argc
, "(1-65535)", &idx
);
7881 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7883 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7884 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7886 "Please specify interface address by A.B.C.D\n");
7887 return CMD_WARNING_CONFIG_FAILED
;
7890 params
= ospf_get_if_params(ifp
, addr
);
7891 ospf_if_update_params(ifp
, addr
);
7894 SET_IF_PARAM(params
, transmit_delay
);
7895 params
->transmit_delay
= seconds
;
7900 DEFUN_HIDDEN (ospf_transmit_delay
,
7901 ospf_transmit_delay_cmd
,
7902 "ospf transmit-delay (1-65535) [A.B.C.D]",
7903 "OSPF interface commands\n"
7904 "Link state transmit delay\n"
7906 "Address of interface\n")
7908 return ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
7911 DEFUN (no_ip_ospf_transmit_delay
,
7912 no_ip_ospf_transmit_delay_addr_cmd
,
7913 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
7916 "OSPF interface commands\n"
7917 "Link state transmit delay\n"
7919 "Address of interface\n")
7921 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7923 struct in_addr addr
;
7924 struct ospf_if_params
*params
;
7926 params
= IF_DEF_PARAMS(ifp
);
7928 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7929 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7931 "Please specify interface address by A.B.C.D\n");
7932 return CMD_WARNING_CONFIG_FAILED
;
7935 params
= ospf_lookup_if_params(ifp
, addr
);
7940 UNSET_IF_PARAM(params
, transmit_delay
);
7941 params
->transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
7943 if (params
!= IF_DEF_PARAMS(ifp
)) {
7944 ospf_free_if_params(ifp
, addr
);
7945 ospf_if_update_params(ifp
, addr
);
7952 DEFUN_HIDDEN (no_ospf_transmit_delay
,
7953 no_ospf_transmit_delay_cmd
,
7954 "no ospf transmit-delay [(1-65535) [A.B.C.D]]",
7956 "OSPF interface commands\n"
7957 "Link state transmit delay\n"
7959 "Address of interface\n")
7961 return no_ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
7964 DEFUN (ip_ospf_area
,
7966 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]",
7968 "OSPF interface commands\n"
7970 "Enable OSPF on this interface\n"
7971 "OSPF area ID in IP address format\n"
7972 "OSPF area ID as a decimal value\n"
7973 "Address of interface\n")
7975 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7978 struct in_addr area_id
;
7979 struct in_addr addr
;
7980 struct ospf_if_params
*params
= NULL
;
7981 struct route_node
*rn
;
7982 struct ospf
*ospf
= NULL
;
7983 unsigned short instance
= 0;
7986 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
7987 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
7989 argv_find(argv
, argc
, "area", &idx
);
7990 areaid
= argv
[idx
+ 1]->arg
;
7992 if (ifp
->vrf_id
&& !instance
)
7993 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7995 ospf
= ospf_lookup_instance(instance
);
7997 if (instance
&& ospf
== NULL
) {
7998 params
= IF_DEF_PARAMS(ifp
);
7999 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8000 UNSET_IF_PARAM(params
, if_area
);
8001 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
8002 ospf_interface_area_unset(ospf
, ifp
);
8003 ospf
->if_ospf_cli_count
--;
8005 return CMD_NOT_MY_INSTANCE
;
8008 ret
= str2area_id(areaid
, &area_id
, &format
);
8010 vty_out(vty
, "Please specify area by A.B.C.D|<0-4294967295>\n");
8011 return CMD_WARNING_CONFIG_FAILED
;
8013 if (memcmp(ifp
->name
, "VLINK", 5) == 0) {
8014 vty_out(vty
, "Cannot enable OSPF on a virtual link.\n");
8015 return CMD_WARNING_CONFIG_FAILED
;
8018 params
= IF_DEF_PARAMS(ifp
);
8019 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)
8020 && !IPV4_ADDR_SAME(¶ms
->if_area
, &area_id
)) {
8022 "Must remove previous area config before changing ospf area \n");
8023 return CMD_WARNING_CONFIG_FAILED
;
8026 // Check if we have an address arg and proccess it
8027 if (argc
== idx
+ 3) {
8028 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
8030 "Please specify Intf Address by A.B.C.D\n");
8031 return CMD_WARNING_CONFIG_FAILED
;
8033 // update/create address-level params
8034 params
= ospf_get_if_params((ifp
), (addr
));
8035 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8037 "Must remove previous area/address config before changing ospf area");
8038 return CMD_WARNING_CONFIG_FAILED
;
8040 ospf_if_update_params((ifp
), (addr
));
8044 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
)) {
8045 if (rn
->info
!= NULL
) {
8047 "Please remove all network commands first.\n");
8048 return CMD_WARNING_CONFIG_FAILED
;
8053 /* enable ospf on this interface with area_id */
8055 SET_IF_PARAM(params
, if_area
);
8056 params
->if_area
= area_id
;
8057 params
->if_area_id_fmt
= format
;
8061 ospf_interface_area_set(ospf
, ifp
);
8062 ospf
->if_ospf_cli_count
++;
8068 DEFUN (no_ip_ospf_area
,
8069 no_ip_ospf_area_cmd
,
8070 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]",
8073 "OSPF interface commands\n"
8075 "Disable OSPF on this interface\n"
8076 "OSPF area ID in IP address format\n"
8077 "OSPF area ID as a decimal value\n"
8078 "Address of interface\n")
8080 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8083 struct ospf_if_params
*params
;
8084 unsigned short instance
= 0;
8085 struct in_addr addr
;
8087 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
8088 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
8090 if (ifp
->vrf_id
&& !instance
)
8091 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
8093 ospf
= ospf_lookup_instance(instance
);
8096 return CMD_NOT_MY_INSTANCE
;
8098 argv_find(argv
, argc
, "area", &idx
);
8100 // Check if we have an address arg and proccess it
8101 if (argc
== idx
+ 3) {
8102 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
8104 "Please specify Intf Address by A.B.C.D\n");
8105 return CMD_WARNING_CONFIG_FAILED
;
8107 params
= ospf_lookup_if_params(ifp
, addr
);
8108 if ((params
) == NULL
)
8111 params
= IF_DEF_PARAMS(ifp
);
8113 if (!OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8115 "Can't find specified interface area configuration.\n");
8116 return CMD_WARNING_CONFIG_FAILED
;
8119 UNSET_IF_PARAM(params
, if_area
);
8120 if (params
!= IF_DEF_PARAMS((ifp
))) {
8121 ospf_free_if_params((ifp
), (addr
));
8122 ospf_if_update_params((ifp
), (addr
));
8125 ospf_interface_area_unset(ospf
, ifp
);
8126 ospf
->if_ospf_cli_count
--;
8130 DEFUN (ospf_redistribute_source
,
8131 ospf_redistribute_source_cmd
,
8132 "redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8134 FRR_REDIST_HELP_STR_OSPFD
8135 "Metric for redistributed routes\n"
8136 "OSPF default metric\n"
8137 "OSPF exterior metric type for redistributed routes\n"
8138 "Set OSPF External Type 1/2 metrics\n"
8139 "Route map reference\n"
8140 "Pointer to route-map entries\n")
8142 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8143 int idx_protocol
= 1;
8147 struct ospf_redist
*red
;
8150 /* Get distribute source. */
8151 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
8153 return CMD_WARNING_CONFIG_FAILED
;
8155 red
= ospf_redist_add(ospf
, source
, 0);
8157 /* Get metric value. */
8158 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
8159 if (!str2metric(argv
[idx
]->arg
, &metric
))
8160 return CMD_WARNING_CONFIG_FAILED
;
8163 /* Get metric type. */
8164 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
8165 if (!str2metric_type(argv
[idx
]->arg
, &type
))
8166 return CMD_WARNING_CONFIG_FAILED
;
8170 if (argv_find(argv
, argc
, "WORD", &idx
)) {
8171 ospf_routemap_set(red
, argv
[idx
]->arg
);
8173 ospf_routemap_unset(red
);
8175 return ospf_redistribute_set(ospf
, source
, 0, type
, metric
);
8178 DEFUN (no_ospf_redistribute_source
,
8179 no_ospf_redistribute_source_cmd
,
8180 "no redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8183 FRR_REDIST_HELP_STR_OSPFD
8184 "Metric for redistributed routes\n"
8185 "OSPF default metric\n"
8186 "OSPF exterior metric type for redistributed routes\n"
8187 "Set OSPF External Type 1/2 metrics\n"
8188 "Route map reference\n"
8189 "Pointer to route-map entries\n")
8191 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8192 int idx_protocol
= 2;
8194 struct ospf_redist
*red
;
8196 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
8198 return CMD_WARNING_CONFIG_FAILED
;
8200 red
= ospf_redist_lookup(ospf
, source
, 0);
8204 ospf_routemap_unset(red
);
8205 ospf_redist_del(ospf
, source
, 0);
8207 return ospf_redistribute_unset(ospf
, source
, 0);
8210 DEFUN (ospf_redistribute_instance_source
,
8211 ospf_redistribute_instance_source_cmd
,
8212 "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8214 "Open Shortest Path First\n"
8215 "Non-main Kernel Routing Table\n"
8216 "Instance ID/Table ID\n"
8217 "Metric for redistributed routes\n"
8218 "OSPF default metric\n"
8219 "OSPF exterior metric type for redistributed routes\n"
8220 "Set OSPF External Type 1/2 metrics\n"
8221 "Route map reference\n"
8222 "Pointer to route-map entries\n")
8224 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8225 int idx_ospf_table
= 1;
8231 unsigned short instance
;
8232 struct ospf_redist
*red
;
8234 source
= proto_redistnum(AFI_IP
, argv
[idx_ospf_table
]->text
);
8237 vty_out(vty
, "Unknown instance redistribution\n");
8238 return CMD_WARNING_CONFIG_FAILED
;
8241 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8243 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
8245 "Instance redistribution in non-instanced OSPF not allowed\n");
8246 return CMD_WARNING_CONFIG_FAILED
;
8249 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
8250 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
8251 return CMD_WARNING_CONFIG_FAILED
;
8254 /* Get metric value. */
8255 if (argv_find(argv
, argc
, "metric", &idx
))
8256 if (!str2metric(argv
[idx
+ 1]->arg
, &metric
))
8257 return CMD_WARNING_CONFIG_FAILED
;
8260 /* Get metric type. */
8261 if (argv_find(argv
, argc
, "metric-type", &idx
))
8262 if (!str2metric_type(argv
[idx
+ 1]->arg
, &type
))
8263 return CMD_WARNING_CONFIG_FAILED
;
8265 red
= ospf_redist_add(ospf
, source
, instance
);
8268 if (argv_find(argv
, argc
, "route-map", &idx
))
8269 ospf_routemap_set(red
, argv
[idx
+ 1]->arg
);
8271 ospf_routemap_unset(red
);
8273 return ospf_redistribute_set(ospf
, source
, instance
, type
, metric
);
8276 DEFUN (no_ospf_redistribute_instance_source
,
8277 no_ospf_redistribute_instance_source_cmd
,
8278 "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8281 "Open Shortest Path First\n"
8282 "Non-main Kernel Routing Table\n"
8283 "Instance ID/Table Id\n"
8284 "Metric for redistributed routes\n"
8285 "OSPF default metric\n"
8286 "OSPF exterior metric type for redistributed routes\n"
8287 "Set OSPF External Type 1/2 metrics\n"
8288 "Route map reference\n"
8289 "Pointer to route-map entries\n")
8291 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8292 int idx_ospf_table
= 2;
8294 unsigned int instance
;
8295 struct ospf_redist
*red
;
8298 if (strncmp(argv
[idx_ospf_table
]->arg
, "o", 1) == 0)
8299 source
= ZEBRA_ROUTE_OSPF
;
8301 source
= ZEBRA_ROUTE_TABLE
;
8303 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8305 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
8307 "Instance redistribution in non-instanced OSPF not allowed\n");
8308 return CMD_WARNING_CONFIG_FAILED
;
8311 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
8312 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
8313 return CMD_WARNING_CONFIG_FAILED
;
8316 red
= ospf_redist_lookup(ospf
, source
, instance
);
8320 ospf_routemap_unset(red
);
8321 ospf_redist_del(ospf
, source
, instance
);
8323 return ospf_redistribute_unset(ospf
, source
, instance
);
8326 DEFUN (ospf_distribute_list_out
,
8327 ospf_distribute_list_out_cmd
,
8328 "distribute-list WORD out " FRR_REDIST_STR_OSPFD
,
8329 "Filter networks in routing updates\n"
8330 "Access-list name\n"
8332 FRR_REDIST_HELP_STR_OSPFD
)
8334 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8338 char *proto
= argv
[argc
- 1]->text
;
8340 /* Get distribute source. */
8341 source
= proto_redistnum(AFI_IP
, proto
);
8343 return CMD_WARNING_CONFIG_FAILED
;
8345 return ospf_distribute_list_out_set(ospf
, source
, argv
[idx_word
]->arg
);
8348 DEFUN (no_ospf_distribute_list_out
,
8349 no_ospf_distribute_list_out_cmd
,
8350 "no distribute-list WORD out " FRR_REDIST_STR_OSPFD
,
8352 "Filter networks in routing updates\n"
8353 "Access-list name\n"
8355 FRR_REDIST_HELP_STR_OSPFD
)
8357 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8361 char *proto
= argv
[argc
- 1]->text
;
8362 source
= proto_redistnum(AFI_IP
, proto
);
8364 return CMD_WARNING_CONFIG_FAILED
;
8366 return ospf_distribute_list_out_unset(ospf
, source
,
8367 argv
[idx_word
]->arg
);
8370 /* Default information originate. */
8371 DEFUN (ospf_default_information_originate
,
8372 ospf_default_information_originate_cmd
,
8373 "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8374 "Control distribution of default information\n"
8375 "Distribute a default route\n"
8376 "Always advertise default route\n"
8377 "OSPF default metric\n"
8379 "OSPF metric type for default routes\n"
8380 "Set OSPF External Type 1/2 metrics\n"
8381 "Route map reference\n"
8382 "Pointer to route-map entries\n")
8384 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8385 int default_originate
= DEFAULT_ORIGINATE_ZEBRA
;
8388 struct ospf_redist
*red
;
8391 red
= ospf_redist_add(ospf
, DEFAULT_ROUTE
, 0);
8393 /* Check whether "always" was specified */
8394 if (argv_find(argv
, argc
, "always", &idx
))
8395 default_originate
= DEFAULT_ORIGINATE_ALWAYS
;
8397 /* Get metric value */
8398 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
8399 if (!str2metric(argv
[idx
]->arg
, &metric
))
8400 return CMD_WARNING_CONFIG_FAILED
;
8403 /* Get metric type. */
8404 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
8405 if (!str2metric_type(argv
[idx
]->arg
, &type
))
8406 return CMD_WARNING_CONFIG_FAILED
;
8410 if (argv_find(argv
, argc
, "WORD", &idx
))
8411 ospf_routemap_set(red
, argv
[idx
]->arg
);
8413 ospf_routemap_unset(red
);
8415 return ospf_redistribute_default_set(ospf
, default_originate
, type
,
8419 DEFUN (no_ospf_default_information_originate
,
8420 no_ospf_default_information_originate_cmd
,
8421 "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8423 "Control distribution of default information\n"
8424 "Distribute a default route\n"
8425 "Always advertise default route\n"
8426 "OSPF default metric\n"
8428 "OSPF metric type for default routes\n"
8429 "Set OSPF External Type 1/2 metrics\n"
8430 "Route map reference\n"
8431 "Pointer to route-map entries\n")
8433 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8434 struct prefix_ipv4 p
;
8435 struct ospf_external
*ext
;
8436 struct ospf_redist
*red
;
8439 p
.prefix
.s_addr
= 0;
8442 ospf_external_lsa_flush(ospf
, DEFAULT_ROUTE
, &p
, 0);
8444 ext
= ospf_external_lookup(ospf
, DEFAULT_ROUTE
, 0);
8445 if (ext
&& EXTERNAL_INFO(ext
)) {
8446 ospf_external_info_delete(ospf
, DEFAULT_ROUTE
, 0, p
);
8447 ospf_external_del(ospf
, DEFAULT_ROUTE
, 0);
8450 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
8454 ospf_routemap_unset(red
);
8455 ospf_redist_del(ospf
, DEFAULT_ROUTE
, 0);
8457 return ospf_redistribute_default_unset(ospf
);
8460 DEFUN (ospf_default_metric
,
8461 ospf_default_metric_cmd
,
8462 "default-metric (0-16777214)",
8463 "Set metric of redistributed routes\n"
8466 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8470 if (!str2metric(argv
[idx_number
]->arg
, &metric
))
8471 return CMD_WARNING_CONFIG_FAILED
;
8473 ospf
->default_metric
= metric
;
8478 DEFUN (no_ospf_default_metric
,
8479 no_ospf_default_metric_cmd
,
8480 "no default-metric [(0-16777214)]",
8482 "Set metric of redistributed routes\n"
8485 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8487 ospf
->default_metric
= -1;
8493 DEFUN (ospf_distance
,
8496 "Administrative distance\n"
8497 "OSPF Administrative distance\n")
8499 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8502 ospf
->distance_all
= atoi(argv
[idx_number
]->arg
);
8507 DEFUN (no_ospf_distance
,
8508 no_ospf_distance_cmd
,
8509 "no distance (1-255)",
8511 "Administrative distance\n"
8512 "OSPF Administrative distance\n")
8514 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8516 ospf
->distance_all
= 0;
8521 DEFUN (no_ospf_distance_ospf
,
8522 no_ospf_distance_ospf_cmd
,
8523 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
8525 "Administrative distance\n"
8526 "OSPF administrative distance\n"
8527 "Intra-area routes\n"
8528 "Distance for intra-area routes\n"
8529 "Inter-area routes\n"
8530 "Distance for inter-area routes\n"
8532 "Distance for external routes\n")
8534 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8537 if (argv_find(argv
, argc
, "intra-area", &idx
) || argc
== 3)
8538 idx
= ospf
->distance_intra
= 0;
8539 if (argv_find(argv
, argc
, "inter-area", &idx
) || argc
== 3)
8540 idx
= ospf
->distance_inter
= 0;
8541 if (argv_find(argv
, argc
, "external", &idx
) || argc
== 3)
8542 ospf
->distance_external
= 0;
8547 DEFUN (ospf_distance_ospf
,
8548 ospf_distance_ospf_cmd
,
8549 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
8550 "Administrative distance\n"
8551 "OSPF administrative distance\n"
8552 "Intra-area routes\n"
8553 "Distance for intra-area routes\n"
8554 "Inter-area routes\n"
8555 "Distance for inter-area routes\n"
8557 "Distance for external routes\n")
8559 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8562 ospf
->distance_intra
= 0;
8563 ospf
->distance_inter
= 0;
8564 ospf
->distance_external
= 0;
8566 if (argv_find(argv
, argc
, "intra-area", &idx
))
8567 ospf
->distance_intra
= atoi(argv
[idx
+ 1]->arg
);
8569 if (argv_find(argv
, argc
, "inter-area", &idx
))
8570 ospf
->distance_inter
= atoi(argv
[idx
+ 1]->arg
);
8572 if (argv_find(argv
, argc
, "external", &idx
))
8573 ospf
->distance_external
= atoi(argv
[idx
+ 1]->arg
);
8579 DEFUN (ospf_distance_source
,
8580 ospf_distance_source_cmd
,
8581 "distance (1-255) A.B.C.D/M",
8582 "Administrative distance\n"
8584 "IP source prefix\n")
8586 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8588 int idx_ipv4_prefixlen
= 2;
8590 ospf_distance_set (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
8595 DEFUN (no_ospf_distance_source
,
8596 no_ospf_distance_source_cmd
,
8597 "no distance (1-255) A.B.C.D/M",
8599 "Administrative distance\n"
8601 "IP source prefix\n")
8603 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8605 int idx_ipv4_prefixlen
= 3;
8607 ospf_distance_unset (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
8612 DEFUN (ospf_distance_source_access_list
,
8613 ospf_distance_source_access_list_cmd
,
8614 "distance (1-255) A.B.C.D/M WORD",
8615 "Administrative distance\n"
8617 "IP source prefix\n"
8618 "Access list name\n")
8620 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8622 int idx_ipv4_prefixlen
= 2;
8625 ospf_distance_set (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
8630 DEFUN (no_ospf_distance_source_access_list
,
8631 no_ospf_distance_source_access_list_cmd
,
8632 "no distance (1-255) A.B.C.D/M WORD",
8634 "Administrative distance\n"
8636 "IP source prefix\n"
8637 "Access list name\n")
8639 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8641 int idx_ipv4_prefixlen
= 3;
8644 ospf_distance_unset (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
8650 DEFUN (ip_ospf_mtu_ignore
,
8651 ip_ospf_mtu_ignore_addr_cmd
,
8652 "ip ospf mtu-ignore [A.B.C.D]",
8654 "OSPF interface commands\n"
8655 "Disable MTU mismatch detection on this interface\n"
8656 "Address of interface\n")
8658 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8660 struct in_addr addr
;
8663 struct ospf_if_params
*params
;
8664 params
= IF_DEF_PARAMS(ifp
);
8667 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8670 "Please specify interface address by A.B.C.D\n");
8671 return CMD_WARNING_CONFIG_FAILED
;
8673 params
= ospf_get_if_params(ifp
, addr
);
8674 ospf_if_update_params(ifp
, addr
);
8676 params
->mtu_ignore
= 1;
8677 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
8678 SET_IF_PARAM(params
, mtu_ignore
);
8680 UNSET_IF_PARAM(params
, mtu_ignore
);
8681 if (params
!= IF_DEF_PARAMS(ifp
)) {
8682 ospf_free_if_params(ifp
, addr
);
8683 ospf_if_update_params(ifp
, addr
);
8689 DEFUN (no_ip_ospf_mtu_ignore
,
8690 no_ip_ospf_mtu_ignore_addr_cmd
,
8691 "no ip ospf mtu-ignore [A.B.C.D]",
8694 "OSPF interface commands\n"
8695 "Disable MTU mismatch detection on this interface\n"
8696 "Address of interface\n")
8698 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8700 struct in_addr addr
;
8703 struct ospf_if_params
*params
;
8704 params
= IF_DEF_PARAMS(ifp
);
8707 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8710 "Please specify interface address by A.B.C.D\n");
8711 return CMD_WARNING_CONFIG_FAILED
;
8713 params
= ospf_get_if_params(ifp
, addr
);
8714 ospf_if_update_params(ifp
, addr
);
8716 params
->mtu_ignore
= 0;
8717 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
8718 SET_IF_PARAM(params
, mtu_ignore
);
8720 UNSET_IF_PARAM(params
, mtu_ignore
);
8721 if (params
!= IF_DEF_PARAMS(ifp
)) {
8722 ospf_free_if_params(ifp
, addr
);
8723 ospf_if_update_params(ifp
, addr
);
8730 DEFUN (ospf_max_metric_router_lsa_admin
,
8731 ospf_max_metric_router_lsa_admin_cmd
,
8732 "max-metric router-lsa administrative",
8733 "OSPF maximum / infinite-distance metric\n"
8734 "Advertise own Router-LSA with infinite distance (stub router)\n"
8735 "Administratively applied, for an indefinite period\n")
8737 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8738 struct listnode
*ln
;
8739 struct ospf_area
*area
;
8741 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8742 SET_FLAG(area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
);
8744 if (!CHECK_FLAG(area
->stub_router_state
,
8745 OSPF_AREA_IS_STUB_ROUTED
))
8746 ospf_router_lsa_update_area(area
);
8749 /* Allows for areas configured later to get the property */
8750 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
;
8755 DEFUN (no_ospf_max_metric_router_lsa_admin
,
8756 no_ospf_max_metric_router_lsa_admin_cmd
,
8757 "no max-metric router-lsa administrative",
8759 "OSPF maximum / infinite-distance metric\n"
8760 "Advertise own Router-LSA with infinite distance (stub router)\n"
8761 "Administratively applied, for an indefinite period\n")
8763 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8764 struct listnode
*ln
;
8765 struct ospf_area
*area
;
8767 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8768 UNSET_FLAG(area
->stub_router_state
,
8769 OSPF_AREA_ADMIN_STUB_ROUTED
);
8771 /* Don't trample on the start-up stub timer */
8772 if (CHECK_FLAG(area
->stub_router_state
,
8773 OSPF_AREA_IS_STUB_ROUTED
)
8774 && !area
->t_stub_router
) {
8775 UNSET_FLAG(area
->stub_router_state
,
8776 OSPF_AREA_IS_STUB_ROUTED
);
8777 ospf_router_lsa_update_area(area
);
8780 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET
;
8784 DEFUN (ospf_max_metric_router_lsa_startup
,
8785 ospf_max_metric_router_lsa_startup_cmd
,
8786 "max-metric router-lsa on-startup (5-86400)",
8787 "OSPF maximum / infinite-distance metric\n"
8788 "Advertise own Router-LSA with infinite distance (stub router)\n"
8789 "Automatically advertise stub Router-LSA on startup of OSPF\n"
8790 "Time (seconds) to advertise self as stub-router\n")
8792 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8794 unsigned int seconds
;
8797 vty_out(vty
, "%% Must supply stub-router period");
8798 return CMD_WARNING_CONFIG_FAILED
;
8801 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8803 ospf
->stub_router_startup_time
= seconds
;
8808 DEFUN (no_ospf_max_metric_router_lsa_startup
,
8809 no_ospf_max_metric_router_lsa_startup_cmd
,
8810 "no max-metric router-lsa on-startup [(5-86400)]",
8812 "OSPF maximum / infinite-distance metric\n"
8813 "Advertise own Router-LSA with infinite distance (stub router)\n"
8814 "Automatically advertise stub Router-LSA on startup of OSPF\n"
8815 "Time (seconds) to advertise self as stub-router\n")
8817 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8818 struct listnode
*ln
;
8819 struct ospf_area
*area
;
8821 ospf
->stub_router_startup_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
8823 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8824 SET_FLAG(area
->stub_router_state
,
8825 OSPF_AREA_WAS_START_STUB_ROUTED
);
8826 OSPF_TIMER_OFF(area
->t_stub_router
);
8828 /* Don't trample on admin stub routed */
8829 if (!CHECK_FLAG(area
->stub_router_state
,
8830 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
8831 UNSET_FLAG(area
->stub_router_state
,
8832 OSPF_AREA_IS_STUB_ROUTED
);
8833 ospf_router_lsa_update_area(area
);
8840 DEFUN (ospf_max_metric_router_lsa_shutdown
,
8841 ospf_max_metric_router_lsa_shutdown_cmd
,
8842 "max-metric router-lsa on-shutdown (5-100)",
8843 "OSPF maximum / infinite-distance metric\n"
8844 "Advertise own Router-LSA with infinite distance (stub router)\n"
8845 "Advertise stub-router prior to full shutdown of OSPF\n"
8846 "Time (seconds) to wait till full shutdown\n")
8848 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8850 unsigned int seconds
;
8853 vty_out(vty
, "%% Must supply stub-router shutdown period");
8854 return CMD_WARNING_CONFIG_FAILED
;
8857 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8859 ospf
->stub_router_shutdown_time
= seconds
;
8864 DEFUN (no_ospf_max_metric_router_lsa_shutdown
,
8865 no_ospf_max_metric_router_lsa_shutdown_cmd
,
8866 "no max-metric router-lsa on-shutdown [(5-100)]",
8868 "OSPF maximum / infinite-distance metric\n"
8869 "Advertise own Router-LSA with infinite distance (stub router)\n"
8870 "Advertise stub-router prior to full shutdown of OSPF\n"
8871 "Time (seconds) to wait till full shutdown\n")
8873 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8875 ospf
->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
8880 static void config_write_stub_router(struct vty
*vty
, struct ospf
*ospf
)
8882 struct listnode
*ln
;
8883 struct ospf_area
*area
;
8885 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
8886 vty_out(vty
, " max-metric router-lsa on-startup %u\n",
8887 ospf
->stub_router_startup_time
);
8888 if (ospf
->stub_router_shutdown_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
8889 vty_out(vty
, " max-metric router-lsa on-shutdown %u\n",
8890 ospf
->stub_router_shutdown_time
);
8891 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8892 if (CHECK_FLAG(area
->stub_router_state
,
8893 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
8894 vty_out(vty
, " max-metric router-lsa administrative\n");
8901 static void show_ip_ospf_route_network(struct vty
*vty
, struct ospf
*ospf
,
8902 struct route_table
*rt
,
8905 struct route_node
*rn
;
8906 struct ospf_route
* or ;
8907 struct listnode
*pnode
, *pnnode
;
8908 struct ospf_path
*path
;
8909 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
8910 *json_nexthop
= NULL
;
8914 "============ OSPF network routing table ============\n");
8916 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
8917 if ((or = rn
->info
) == NULL
)
8919 char buf1
[PREFIX2STR_BUFFER
];
8921 memset(buf1
, 0, sizeof(buf1
));
8922 prefix2str(&rn
->p
, buf1
, sizeof(buf1
));
8924 json_route
= json_object_new_object();
8926 json_object_object_add(json
, buf1
, json_route
);
8927 json_object_to_json_string_ext(
8928 json
, JSON_C_TO_STRING_NOSLASHESCAPE
);
8931 switch (or->path_type
) {
8932 case OSPF_PATH_INTER_AREA
:
8933 if (or->type
== OSPF_DESTINATION_NETWORK
) {
8935 json_object_string_add(json_route
,
8938 json_object_int_add(json_route
, "cost",
8940 json_object_string_add(
8942 inet_ntoa(or->u
.std
.area_id
));
8945 "N IA %-18s [%d] area: %s\n",
8947 inet_ntoa(or->u
.std
.area_id
));
8949 } else if (or->type
== OSPF_DESTINATION_DISCARD
) {
8951 json_object_string_add(json_route
,
8956 "D IA %-18s Discard entry\n",
8961 case OSPF_PATH_INTRA_AREA
:
8963 json_object_string_add(json_route
, "routeType",
8965 json_object_int_add(json_route
, "cost",
8967 json_object_string_add(
8969 inet_ntoa(or->u
.std
.area_id
));
8971 vty_out(vty
, "N %-18s [%d] area: %s\n",
8973 inet_ntoa(or->u
.std
.area_id
));
8980 if (or->type
== OSPF_DESTINATION_NETWORK
) {
8982 json_nexthop_array
= json_object_new_array();
8983 json_object_object_add(json_route
, "nexthops",
8984 json_nexthop_array
);
8987 for (ALL_LIST_ELEMENTS(or->paths
, pnode
, pnnode
,
8990 json_nexthop
= json_object_new_object();
8991 json_object_array_add(
8995 if (if_lookup_by_index(path
->ifindex
,
8998 if (path
->nexthop
.s_addr
== 0) {
9000 json_object_string_add(
9003 json_object_string_add(
9005 "directly attached to",
9011 "%24s directly attached to %s\n",
9019 json_object_string_add(
9024 json_object_string_add(
9032 "%24s via %s, %s\n",
9045 json_object_free(json_route
);
9051 static void show_ip_ospf_route_router(struct vty
*vty
, struct ospf
*ospf
,
9052 struct route_table
*rtrs
,
9055 struct route_node
*rn
;
9056 struct ospf_route
* or ;
9057 struct listnode
*pnode
;
9058 struct listnode
*node
;
9059 struct ospf_path
*path
;
9060 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
9061 *json_nexthop
= NULL
;
9065 "============ OSPF router routing table =============\n");
9067 for (rn
= route_top(rtrs
); rn
; rn
= route_next(rn
)) {
9068 if (rn
->info
== NULL
)
9072 json_route
= json_object_new_object();
9074 json_object_object_add(json
, inet_ntoa(rn
->p
.u
.prefix4
),
9076 json_object_string_add(json_route
, "routeType", "R ");
9078 vty_out(vty
, "R %-15s ",
9079 inet_ntoa(rn
->p
.u
.prefix4
));
9082 for (ALL_LIST_ELEMENTS_RO((struct list
*)rn
->info
, node
, or)) {
9085 vty_out(vty
, "%24s", "");
9090 json_object_int_add(json_route
, "cost",
9092 json_object_string_add(
9094 inet_ntoa(or->u
.std
.area_id
));
9095 if (or->path_type
== OSPF_PATH_INTER_AREA
)
9096 json_object_boolean_true_add(json_route
,
9098 if (or->u
.std
.flags
& ROUTER_LSA_BORDER
)
9099 json_object_string_add(json_route
,
9102 else if (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
)
9103 json_object_string_add(json_route
,
9107 vty_out(vty
, "%s [%d] area: %s",
9108 (or->path_type
== OSPF_PATH_INTER_AREA
9111 or->cost
, inet_ntoa(or->u
.std
.area_id
));
9113 vty_out(vty
, "%s%s\n",
9114 (or->u
.std
.flags
& ROUTER_LSA_BORDER
9117 (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
9123 json_nexthop_array
= json_object_new_array();
9124 json_object_object_add(json_route
, "nexthops",
9125 json_nexthop_array
);
9128 for (ALL_LIST_ELEMENTS_RO(or->paths
, pnode
, path
)) {
9130 json_nexthop
= json_object_new_object();
9131 json_object_array_add(
9135 if (if_lookup_by_index(path
->ifindex
,
9137 if (path
->nexthop
.s_addr
== 0) {
9139 json_object_string_add(
9142 json_object_string_add(
9144 "directly attached to",
9150 "%24s directly attached to %s\n",
9158 json_object_string_add(
9163 json_object_string_add(
9171 "%24s via %s, %s\n",
9184 json_object_free(json_route
);
9190 static void show_ip_ospf_route_external(struct vty
*vty
, struct ospf
*ospf
,
9191 struct route_table
*rt
,
9194 struct route_node
*rn
;
9195 struct ospf_route
*er
;
9196 struct listnode
*pnode
, *pnnode
;
9197 struct ospf_path
*path
;
9198 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
9199 *json_nexthop
= NULL
;
9203 "============ OSPF external routing table ===========\n");
9205 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
9206 if ((er
= rn
->info
) == NULL
)
9211 snprintf(buf1
, 19, "%s/%d", inet_ntoa(rn
->p
.u
.prefix4
),
9213 json_route
= json_object_new_object();
9215 json_object_object_add(json
, buf1
, json_route
);
9216 json_object_to_json_string_ext(
9217 json
, JSON_C_TO_STRING_NOSLASHESCAPE
);
9220 switch (er
->path_type
) {
9221 case OSPF_PATH_TYPE1_EXTERNAL
:
9223 json_object_string_add(json_route
, "routeType",
9225 json_object_int_add(json_route
, "cost",
9229 "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI
9231 buf1
, er
->cost
, er
->u
.ext
.tag
);
9234 case OSPF_PATH_TYPE2_EXTERNAL
:
9236 json_object_string_add(json_route
, "routeType",
9238 json_object_int_add(json_route
, "cost",
9242 "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI
9244 buf1
, er
->cost
, er
->u
.ext
.type2_cost
,
9251 json_nexthop_array
= json_object_new_array();
9252 json_object_object_add(json_route
, "nexthops",
9253 json_nexthop_array
);
9256 for (ALL_LIST_ELEMENTS(er
->paths
, pnode
, pnnode
, path
)) {
9258 json_nexthop
= json_object_new_object();
9259 json_object_array_add(json_nexthop_array
,
9263 if (if_lookup_by_index(path
->ifindex
, ospf
->vrf_id
)) {
9264 if (path
->nexthop
.s_addr
== 0) {
9266 json_object_string_add(
9269 json_object_string_add(
9271 "directly attached to",
9277 "%24s directly attached to %s\n",
9285 json_object_string_add(
9289 json_object_string_add(
9290 json_nexthop
, "via",
9296 "%24s via %s, %s\n",
9308 json_object_free(json_route
);
9314 static int show_ip_ospf_border_routers_common(struct vty
*vty
,
9319 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
9321 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
9323 if (ospf
->new_table
== NULL
) {
9324 vty_out(vty
, "No OSPF routing information exist\n");
9328 /* Show Network routes.
9329 show_ip_ospf_route_network (vty, ospf->new_table); */
9331 /* Show Router routes. */
9332 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, NULL
);
9339 DEFUN (show_ip_ospf_border_routers
,
9340 show_ip_ospf_border_routers_cmd
,
9341 "show ip ospf [vrf <NAME|all>] border-routers",
9344 "OSPF information\n"
9347 "Show all the ABR's and ASBR's\n")
9349 struct ospf
*ospf
= NULL
;
9350 struct listnode
*node
= NULL
;
9351 char *vrf_name
= NULL
;
9352 bool all_vrf
= FALSE
;
9353 int ret
= CMD_SUCCESS
;
9356 uint8_t use_vrf
= 0;
9358 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
9361 bool ospf_output
= FALSE
;
9366 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9367 if (!ospf
->oi_running
)
9371 ret
= show_ip_ospf_border_routers_common(
9372 vty
, ospf
, use_vrf
);
9376 vty_out(vty
, "%% OSPF instance not found\n");
9378 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
9379 if (ospf
== NULL
|| !ospf
->oi_running
) {
9380 vty_out(vty
, "%% OSPF instance not found\n");
9384 ret
= show_ip_ospf_border_routers_common(vty
, ospf
,
9388 /* Display default ospf (instance 0) info */
9389 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
9390 if (ospf
== NULL
|| !ospf
->oi_running
) {
9391 vty_out(vty
, "%% OSPF instance not found\n");
9395 ret
= show_ip_ospf_border_routers_common(vty
, ospf
, use_vrf
);
9401 DEFUN (show_ip_ospf_instance_border_routers
,
9402 show_ip_ospf_instance_border_routers_cmd
,
9403 "show ip ospf (1-65535) border-routers",
9406 "OSPF information\n"
9408 "Show all the ABR's and ASBR's\n")
9412 unsigned short instance
= 0;
9414 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9415 ospf
= ospf_lookup_instance(instance
);
9417 return CMD_NOT_MY_INSTANCE
;
9419 if (!ospf
->oi_running
)
9422 return show_ip_ospf_border_routers_common(vty
, ospf
, 0);
9425 static int show_ip_ospf_route_common(struct vty
*vty
, struct ospf
*ospf
,
9426 json_object
*json
, uint8_t use_vrf
)
9428 json_object
*json_vrf
= NULL
;
9431 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
9436 json_vrf
= json_object_new_object();
9441 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
9443 if (ospf
->new_table
== NULL
) {
9444 vty_out(vty
, "No OSPF routing information exist\n");
9448 /* Show Network routes. */
9449 show_ip_ospf_route_network(vty
, ospf
, ospf
->new_table
, json_vrf
);
9451 /* Show Router routes. */
9452 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, json_vrf
);
9454 /* Show AS External routes. */
9455 show_ip_ospf_route_external(vty
, ospf
, ospf
->old_external_route
,
9460 // json_object_object_add(json_vrf, "areas",
9462 if (ospf
->vrf_id
== VRF_DEFAULT
)
9463 json_object_object_add(json
, "default",
9466 json_object_object_add(json
, ospf
->name
,
9476 DEFUN (show_ip_ospf_route
,
9477 show_ip_ospf_route_cmd
,
9478 "show ip ospf [vrf <NAME|all>] route [json]",
9481 "OSPF information\n"
9484 "OSPF routing table\n"
9487 struct ospf
*ospf
= NULL
;
9488 struct listnode
*node
= NULL
;
9489 char *vrf_name
= NULL
;
9490 bool all_vrf
= FALSE
;
9491 int ret
= CMD_SUCCESS
;
9494 uint8_t use_vrf
= 0;
9495 bool uj
= use_json(argc
, argv
);
9496 json_object
*json
= NULL
;
9499 json
= json_object_new_object();
9501 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
9503 /* vrf input is provided could be all or specific vrf*/
9505 bool ospf_output
= FALSE
;
9510 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9511 if (!ospf
->oi_running
)
9514 ret
= show_ip_ospf_route_common(vty
, ospf
, json
,
9519 /* Keep Non-pretty format */
9520 vty_out(vty
, "%s\n",
9521 json_object_to_json_string(json
));
9522 json_object_free(json
);
9523 } else if (!ospf_output
)
9524 vty_out(vty
, "%% OSPF instance not found\n");
9528 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
9529 if (ospf
== NULL
|| !ospf
->oi_running
) {
9531 vty_out(vty
, "%s\n",
9532 json_object_to_json_string_ext(
9533 json
, JSON_C_TO_STRING_PRETTY
));
9534 json_object_free(json
);
9536 vty_out(vty
, "%% OSPF instance not found\n");
9541 /* Display default ospf (instance 0) info */
9542 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
9543 if (ospf
== NULL
|| !ospf
->oi_running
) {
9545 vty_out(vty
, "%s\n",
9546 json_object_to_json_string_ext(
9547 json
, JSON_C_TO_STRING_PRETTY
));
9548 json_object_free(json
);
9550 vty_out(vty
, "%% OSPF instance not found\n");
9557 ret
= show_ip_ospf_route_common(vty
, ospf
, json
, use_vrf
);
9558 /* Keep Non-pretty format */
9560 vty_out(vty
, "%s\n", json_object_to_json_string(json
));
9564 json_object_free(json
);
9569 DEFUN (show_ip_ospf_instance_route
,
9570 show_ip_ospf_instance_route_cmd
,
9571 "show ip ospf (1-65535) route",
9574 "OSPF information\n"
9576 "OSPF routing table\n")
9580 unsigned short instance
= 0;
9582 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9583 ospf
= ospf_lookup_instance(instance
);
9585 return CMD_NOT_MY_INSTANCE
;
9587 if (!ospf
->oi_running
)
9590 return show_ip_ospf_route_common(vty
, ospf
, NULL
, 0);
9594 DEFUN (show_ip_ospf_vrfs
,
9595 show_ip_ospf_vrfs_cmd
,
9596 "show ip ospf vrfs [json]",
9599 "OSPF information\n"
9603 bool uj
= use_json(argc
, argv
);
9604 json_object
*json
= NULL
;
9605 json_object
*json_vrfs
= NULL
;
9606 struct ospf
*ospf
= NULL
;
9607 struct listnode
*node
= NULL
;
9609 static char header
[] = "Name Id RouterId ";
9612 json
= json_object_new_object();
9613 json_vrfs
= json_object_new_object();
9616 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9617 json_object
*json_vrf
= NULL
;
9618 const char *name
= NULL
;
9619 int64_t vrf_id_ui
= 0;
9623 if (!uj
&& count
== 1)
9624 vty_out(vty
, "%s\n", header
);
9626 json_vrf
= json_object_new_object();
9628 if (ospf
->vrf_id
== 0)
9629 name
= VRF_DEFAULT_NAME
;
9633 vrf_id_ui
= (ospf
->vrf_id
== VRF_UNKNOWN
)
9635 : (int64_t)ospf
->vrf_id
;
9638 json_object_int_add(json_vrf
, "vrfId", vrf_id_ui
);
9639 json_object_string_add(json_vrf
, "routerId",
9640 inet_ntoa(ospf
->router_id
));
9642 json_object_object_add(json_vrfs
, name
, json_vrf
);
9645 vty_out(vty
, "%-25s %-5d %-16s \n", name
,
9646 ospf
->vrf_id
, inet_ntoa(ospf
->router_id
));
9651 json_object_object_add(json
, "vrfs", json_vrfs
);
9652 json_object_int_add(json
, "totalVrfs", count
);
9654 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
9655 json
, JSON_C_TO_STRING_PRETTY
));
9656 json_object_free(json
);
9659 vty_out(vty
, "\nTotal number of OSPF VRFs: %d\n",
9666 const char *ospf_abr_type_str
[] = {"unknown", "standard", "ibm", "cisco",
9669 const char *ospf_shortcut_mode_str
[] = {"default", "enable", "disable"};
9671 const char *ospf_int_type_str
[] = {"unknown", /* should never be used. */
9672 "point-to-point", "broadcast",
9673 "non-broadcast", "point-to-multipoint",
9674 "virtual-link", /* should never be used. */
9677 static int config_write_interface_one(struct vty
*vty
, struct vrf
*vrf
)
9679 struct listnode
*node
;
9680 struct interface
*ifp
;
9681 struct crypt_key
*ck
;
9682 struct route_node
*rn
= NULL
;
9683 struct ospf_if_params
*params
;
9685 struct ospf
*ospf
= vrf
->info
;
9687 FOR_ALL_INTERFACES (vrf
, ifp
) {
9689 if (memcmp(ifp
->name
, "VLINK", 5) == 0)
9692 vty_frame(vty
, "!\n");
9693 if (ifp
->vrf_id
== VRF_DEFAULT
)
9694 vty_frame(vty
, "interface %s\n", ifp
->name
);
9696 vty_frame(vty
, "interface %s vrf %s\n", ifp
->name
,
9699 vty_out(vty
, " description %s\n", ifp
->desc
);
9703 params
= IF_DEF_PARAMS(ifp
);
9706 /* Interface Network print. */
9707 if (OSPF_IF_PARAM_CONFIGURED(params
, type
)
9708 && params
->type
!= OSPF_IFTYPE_LOOPBACK
) {
9709 if (params
->type
!= ospf_default_iftype(ifp
)) {
9710 vty_out(vty
, " ip ospf network %s",
9713 if (params
!= IF_DEF_PARAMS(ifp
))
9721 /* OSPF interface authentication print */
9722 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_type
)
9723 && params
->auth_type
!= OSPF_AUTH_NOTSET
) {
9724 const char *auth_str
;
9726 /* Translation tables are not that much help
9727 * here due to syntax
9728 * of the simple option */
9729 switch (params
->auth_type
) {
9731 case OSPF_AUTH_NULL
:
9735 case OSPF_AUTH_SIMPLE
:
9739 case OSPF_AUTH_CRYPTOGRAPHIC
:
9740 auth_str
= " message-digest";
9748 vty_out(vty
, " ip ospf authentication%s",
9750 if (params
!= IF_DEF_PARAMS(ifp
))
9752 inet_ntoa(rn
->p
.u
.prefix4
));
9756 /* Simple Authentication Password print. */
9757 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_simple
)
9758 && params
->auth_simple
[0] != '\0') {
9759 vty_out(vty
, " ip ospf authentication-key %s",
9760 params
->auth_simple
);
9761 if (params
!= IF_DEF_PARAMS(ifp
))
9763 inet_ntoa(rn
->p
.u
.prefix4
));
9767 /* Cryptographic Authentication Key print. */
9768 if (params
&& params
->auth_crypt
) {
9769 for (ALL_LIST_ELEMENTS_RO(params
->auth_crypt
,
9772 " ip ospf message-digest-key %d md5 %s",
9773 ck
->key_id
, ck
->auth_key
);
9774 if (params
!= IF_DEF_PARAMS(ifp
))
9782 /* Interface Output Cost print. */
9783 if (OSPF_IF_PARAM_CONFIGURED(params
, output_cost_cmd
)) {
9784 vty_out(vty
, " ip ospf cost %u",
9785 params
->output_cost_cmd
);
9786 if (params
!= IF_DEF_PARAMS(ifp
))
9788 inet_ntoa(rn
->p
.u
.prefix4
));
9792 /* Hello Interval print. */
9793 if (OSPF_IF_PARAM_CONFIGURED(params
, v_hello
)
9794 && params
->v_hello
!= OSPF_HELLO_INTERVAL_DEFAULT
) {
9795 vty_out(vty
, " ip ospf hello-interval %u",
9797 if (params
!= IF_DEF_PARAMS(ifp
))
9799 inet_ntoa(rn
->p
.u
.prefix4
));
9804 /* Router Dead Interval print. */
9805 if (OSPF_IF_PARAM_CONFIGURED(params
, v_wait
)
9807 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
) {
9808 vty_out(vty
, " ip ospf dead-interval ");
9811 if (OSPF_IF_PARAM_CONFIGURED(params
,
9814 "minimal hello-multiplier %d",
9815 params
->fast_hello
);
9817 vty_out(vty
, "%u", params
->v_wait
);
9819 if (params
!= IF_DEF_PARAMS(ifp
))
9821 inet_ntoa(rn
->p
.u
.prefix4
));
9825 /* Router Priority print. */
9826 if (OSPF_IF_PARAM_CONFIGURED(params
, priority
)
9828 != OSPF_ROUTER_PRIORITY_DEFAULT
) {
9829 vty_out(vty
, " ip ospf priority %u",
9831 if (params
!= IF_DEF_PARAMS(ifp
))
9833 inet_ntoa(rn
->p
.u
.prefix4
));
9837 /* Retransmit Interval print. */
9838 if (OSPF_IF_PARAM_CONFIGURED(params
,
9839 retransmit_interval
)
9840 && params
->retransmit_interval
9841 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
) {
9842 vty_out(vty
, " ip ospf retransmit-interval %u",
9843 params
->retransmit_interval
);
9844 if (params
!= IF_DEF_PARAMS(ifp
))
9846 inet_ntoa(rn
->p
.u
.prefix4
));
9850 /* Transmit Delay print. */
9851 if (OSPF_IF_PARAM_CONFIGURED(params
, transmit_delay
)
9852 && params
->transmit_delay
9853 != OSPF_TRANSMIT_DELAY_DEFAULT
) {
9854 vty_out(vty
, " ip ospf transmit-delay %u",
9855 params
->transmit_delay
);
9856 if (params
!= IF_DEF_PARAMS(ifp
))
9858 inet_ntoa(rn
->p
.u
.prefix4
));
9863 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
9864 if (ospf
&& ospf
->instance
)
9865 vty_out(vty
, " ip ospf %d",
9868 vty_out(vty
, " ip ospf");
9870 char buf
[INET_ADDRSTRLEN
];
9872 area_id2str(buf
, sizeof(buf
), ¶ms
->if_area
,
9873 params
->if_area_id_fmt
);
9874 vty_out(vty
, " area %s", buf
);
9875 if (params
!= IF_DEF_PARAMS(ifp
))
9877 inet_ntoa(rn
->p
.u
.prefix4
));
9882 if (params
&& params
->bfd_info
)
9883 ospf_bfd_write_config(vty
, params
);
9885 /* MTU ignore print. */
9886 if (OSPF_IF_PARAM_CONFIGURED(params
, mtu_ignore
)
9887 && params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
) {
9888 if (params
->mtu_ignore
== 0)
9889 vty_out(vty
, " no ip ospf mtu-ignore");
9891 vty_out(vty
, " ip ospf mtu-ignore");
9892 if (params
!= IF_DEF_PARAMS(ifp
))
9894 inet_ntoa(rn
->p
.u
.prefix4
));
9901 rn
= route_top(IF_OIFS_PARAMS(ifp
));
9903 rn
= route_next(rn
);
9913 ospf_opaque_config_write_if(vty
, ifp
);
9915 vty_endframe(vty
, NULL
);
9921 /* Configuration write function for ospfd. */
9922 static int config_write_interface(struct vty
*vty
)
9925 struct vrf
*vrf
= NULL
;
9927 /* Display all VRF aware OSPF interface configuration */
9928 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
9929 write
+= config_write_interface_one(vty
, vrf
);
9935 static int config_write_network_area(struct vty
*vty
, struct ospf
*ospf
)
9937 struct route_node
*rn
;
9938 uint8_t buf
[INET_ADDRSTRLEN
];
9940 /* `network area' print. */
9941 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
))
9943 struct ospf_network
*n
= rn
->info
;
9945 /* Create Area ID string by specified Area ID format. */
9946 if (n
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
9947 inet_ntop(AF_INET
, &n
->area_id
, (char *)buf
,
9950 sprintf((char *)buf
, "%lu",
9951 (unsigned long int)ntohl(
9952 n
->area_id
.s_addr
));
9954 /* Network print. */
9955 vty_out(vty
, " network %s/%d area %s\n",
9956 inet_ntoa(rn
->p
.u
.prefix4
), rn
->p
.prefixlen
,
9963 static int config_write_ospf_area(struct vty
*vty
, struct ospf
*ospf
)
9965 struct listnode
*node
;
9966 struct ospf_area
*area
;
9967 uint8_t buf
[INET_ADDRSTRLEN
];
9969 /* Area configuration print. */
9970 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
9971 struct route_node
*rn1
;
9973 area_id2str((char *)buf
, sizeof(buf
), &area
->area_id
,
9976 if (area
->auth_type
!= OSPF_AUTH_NULL
) {
9977 if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
9978 vty_out(vty
, " area %s authentication\n", buf
);
9981 " area %s authentication message-digest\n",
9985 if (area
->shortcut_configured
!= OSPF_SHORTCUT_DEFAULT
)
9986 vty_out(vty
, " area %s shortcut %s\n", buf
,
9987 ospf_shortcut_mode_str
9988 [area
->shortcut_configured
]);
9990 if ((area
->external_routing
== OSPF_AREA_STUB
)
9991 || (area
->external_routing
== OSPF_AREA_NSSA
)) {
9992 if (area
->external_routing
== OSPF_AREA_STUB
) {
9993 vty_out(vty
, " area %s stub", buf
);
9994 if (area
->no_summary
)
9995 vty_out(vty
, " no-summary\n");
9997 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
9998 switch (area
->NSSATranslatorRole
) {
9999 case OSPF_NSSA_ROLE_NEVER
:
10001 " area %s nssa translate-never\n",
10004 case OSPF_NSSA_ROLE_ALWAYS
:
10006 " area %s nssa translate-always\n",
10009 case OSPF_NSSA_ROLE_CANDIDATE
:
10010 vty_out(vty
, " area %s nssa \n", buf
);
10013 if (area
->no_summary
)
10015 " area %s nssa no-summary\n",
10019 if (area
->default_cost
!= 1)
10020 vty_out(vty
, " area %s default-cost %d\n", buf
,
10021 area
->default_cost
);
10024 for (rn1
= route_top(area
->ranges
); rn1
; rn1
= route_next(rn1
))
10026 struct ospf_area_range
*range
= rn1
->info
;
10028 vty_out(vty
, " area %s range %s/%d", buf
,
10029 inet_ntoa(rn1
->p
.u
.prefix4
),
10032 if (range
->cost_config
10033 != OSPF_AREA_RANGE_COST_UNSPEC
)
10034 vty_out(vty
, " cost %d",
10035 range
->cost_config
);
10037 if (!CHECK_FLAG(range
->flags
,
10038 OSPF_AREA_RANGE_ADVERTISE
))
10039 vty_out(vty
, " not-advertise");
10041 if (CHECK_FLAG(range
->flags
,
10042 OSPF_AREA_RANGE_SUBSTITUTE
))
10043 vty_out(vty
, " substitute %s/%d",
10044 inet_ntoa(range
->subst_addr
),
10045 range
->subst_masklen
);
10047 vty_out(vty
, "\n");
10050 if (EXPORT_NAME(area
))
10051 vty_out(vty
, " area %s export-list %s\n", buf
,
10052 EXPORT_NAME(area
));
10054 if (IMPORT_NAME(area
))
10055 vty_out(vty
, " area %s import-list %s\n", buf
,
10056 IMPORT_NAME(area
));
10058 if (PREFIX_NAME_IN(area
))
10059 vty_out(vty
, " area %s filter-list prefix %s in\n", buf
,
10060 PREFIX_NAME_IN(area
));
10062 if (PREFIX_NAME_OUT(area
))
10063 vty_out(vty
, " area %s filter-list prefix %s out\n",
10064 buf
, PREFIX_NAME_OUT(area
));
10070 static int config_write_ospf_nbr_nbma(struct vty
*vty
, struct ospf
*ospf
)
10072 struct ospf_nbr_nbma
*nbr_nbma
;
10073 struct route_node
*rn
;
10075 /* Static Neighbor configuration print. */
10076 for (rn
= route_top(ospf
->nbr_nbma
); rn
; rn
= route_next(rn
))
10077 if ((nbr_nbma
= rn
->info
)) {
10078 vty_out(vty
, " neighbor %s", inet_ntoa(nbr_nbma
->addr
));
10080 if (nbr_nbma
->priority
10081 != OSPF_NEIGHBOR_PRIORITY_DEFAULT
)
10082 vty_out(vty
, " priority %d",
10083 nbr_nbma
->priority
);
10085 if (nbr_nbma
->v_poll
!= OSPF_POLL_INTERVAL_DEFAULT
)
10086 vty_out(vty
, " poll-interval %d",
10089 vty_out(vty
, "\n");
10095 static int config_write_virtual_link(struct vty
*vty
, struct ospf
*ospf
)
10097 struct listnode
*node
;
10098 struct ospf_vl_data
*vl_data
;
10099 char buf
[INET_ADDRSTRLEN
];
10101 /* Virtual-Link print */
10102 for (ALL_LIST_ELEMENTS_RO(ospf
->vlinks
, node
, vl_data
)) {
10103 struct listnode
*n2
;
10104 struct crypt_key
*ck
;
10105 struct ospf_interface
*oi
;
10107 if (vl_data
!= NULL
) {
10108 area_id2str(buf
, sizeof(buf
), &vl_data
->vl_area_id
,
10109 vl_data
->vl_area_id_fmt
);
10110 oi
= vl_data
->vl_oi
;
10113 if (OSPF_IF_PARAM(oi
, v_hello
)
10114 != OSPF_HELLO_INTERVAL_DEFAULT
10115 || OSPF_IF_PARAM(oi
, v_wait
)
10116 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
10117 || OSPF_IF_PARAM(oi
, retransmit_interval
)
10118 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
10119 || OSPF_IF_PARAM(oi
, transmit_delay
)
10120 != OSPF_TRANSMIT_DELAY_DEFAULT
)
10122 " area %s virtual-link %s hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n",
10123 buf
, inet_ntoa(vl_data
->vl_peer
),
10124 OSPF_IF_PARAM(oi
, v_hello
),
10125 OSPF_IF_PARAM(oi
, retransmit_interval
),
10126 OSPF_IF_PARAM(oi
, transmit_delay
),
10127 OSPF_IF_PARAM(oi
, v_wait
));
10129 vty_out(vty
, " area %s virtual-link %s\n", buf
,
10130 inet_ntoa(vl_data
->vl_peer
));
10132 if (IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)->auth_simple
[0]
10135 " area %s virtual-link %s authentication-key %s\n",
10136 buf
, inet_ntoa(vl_data
->vl_peer
),
10137 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
10140 for (ALL_LIST_ELEMENTS_RO(
10141 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
10145 " area %s virtual-link %s"
10146 " message-digest-key %d md5 %s\n",
10147 buf
, inet_ntoa(vl_data
->vl_peer
),
10148 ck
->key_id
, ck
->auth_key
);
10156 static int config_write_ospf_redistribute(struct vty
*vty
, struct ospf
*ospf
)
10160 /* redistribute print. */
10161 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
10162 struct list
*red_list
;
10163 struct listnode
*node
;
10164 struct ospf_redist
*red
;
10166 red_list
= ospf
->redist
[type
];
10170 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
10171 vty_out(vty
, " redistribute %s",
10172 zebra_route_string(type
));
10174 vty_out(vty
, " %d", red
->instance
);
10176 if (red
->dmetric
.value
>= 0)
10177 vty_out(vty
, " metric %d", red
->dmetric
.value
);
10179 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
10180 vty_out(vty
, " metric-type 1");
10182 if (ROUTEMAP_NAME(red
))
10183 vty_out(vty
, " route-map %s",
10184 ROUTEMAP_NAME(red
));
10186 vty_out(vty
, "\n");
10193 static int config_write_ospf_default_metric(struct vty
*vty
, struct ospf
*ospf
)
10195 if (ospf
->default_metric
!= -1)
10196 vty_out(vty
, " default-metric %d\n", ospf
->default_metric
);
10200 static int config_write_ospf_distribute(struct vty
*vty
, struct ospf
*ospf
)
10203 struct ospf_redist
*red
;
10206 /* distribute-list print. */
10207 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
10208 if (DISTRIBUTE_NAME(ospf
, type
))
10209 vty_out(vty
, " distribute-list %s out %s\n",
10210 DISTRIBUTE_NAME(ospf
, type
),
10211 zebra_route_string(type
));
10213 /* default-information print. */
10214 if (ospf
->default_originate
!= DEFAULT_ORIGINATE_NONE
) {
10215 vty_out(vty
, " default-information originate");
10216 if (ospf
->default_originate
== DEFAULT_ORIGINATE_ALWAYS
)
10217 vty_out(vty
, " always");
10219 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
10221 if (red
->dmetric
.value
>= 0)
10222 vty_out(vty
, " metric %d",
10223 red
->dmetric
.value
);
10225 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
10226 vty_out(vty
, " metric-type 1");
10228 if (ROUTEMAP_NAME(red
))
10229 vty_out(vty
, " route-map %s",
10230 ROUTEMAP_NAME(red
));
10233 vty_out(vty
, "\n");
10240 static int config_write_ospf_distance(struct vty
*vty
, struct ospf
*ospf
)
10242 struct route_node
*rn
;
10243 struct ospf_distance
*odistance
;
10245 if (ospf
->distance_all
)
10246 vty_out(vty
, " distance %d\n", ospf
->distance_all
);
10248 if (ospf
->distance_intra
|| ospf
->distance_inter
10249 || ospf
->distance_external
) {
10250 vty_out(vty
, " distance ospf");
10252 if (ospf
->distance_intra
)
10253 vty_out(vty
, " intra-area %d", ospf
->distance_intra
);
10254 if (ospf
->distance_inter
)
10255 vty_out(vty
, " inter-area %d", ospf
->distance_inter
);
10256 if (ospf
->distance_external
)
10257 vty_out(vty
, " external %d", ospf
->distance_external
);
10259 vty_out(vty
, "\n");
10262 for (rn
= route_top(ospf
->distance_table
); rn
; rn
= route_next(rn
))
10263 if ((odistance
= rn
->info
) != NULL
) {
10264 vty_out(vty
, " distance %d %s/%d %s\n",
10265 odistance
->distance
, inet_ntoa(rn
->p
.u
.prefix4
),
10267 odistance
->access_list
? odistance
->access_list
10273 static int ospf_config_write_one(struct vty
*vty
, struct ospf
*ospf
)
10275 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
10276 struct interface
*ifp
;
10277 struct ospf_interface
*oi
;
10278 struct listnode
*node
= NULL
;
10281 /* `router ospf' print. */
10282 if (ospf
->instance
&& ospf
->name
) {
10283 vty_out(vty
, "router ospf %d vrf %s\n", ospf
->instance
,
10285 } else if (ospf
->instance
) {
10286 vty_out(vty
, "router ospf %d\n", ospf
->instance
);
10287 } else if (ospf
->name
) {
10288 vty_out(vty
, "router ospf vrf %s\n", ospf
->name
);
10290 vty_out(vty
, "router ospf\n");
10292 if (!ospf
->networks
) {
10297 /* Router ID print. */
10298 if (ospf
->router_id_static
.s_addr
!= 0)
10299 vty_out(vty
, " ospf router-id %s\n",
10300 inet_ntoa(ospf
->router_id_static
));
10302 /* ABR type print. */
10303 if (ospf
->abr_type
!= OSPF_ABR_DEFAULT
)
10304 vty_out(vty
, " ospf abr-type %s\n",
10305 ospf_abr_type_str
[ospf
->abr_type
]);
10307 /* log-adjacency-changes flag print. */
10308 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
10309 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
))
10310 vty_out(vty
, " log-adjacency-changes detail\n");
10311 else if (!DFLT_OSPF_LOG_ADJACENCY_CHANGES
)
10312 vty_out(vty
, " log-adjacency-changes\n");
10313 } else if (DFLT_OSPF_LOG_ADJACENCY_CHANGES
) {
10314 vty_out(vty
, " no log-adjacency-changes\n");
10317 /* RFC1583 compatibility flag print -- Compatible with CISCO
10319 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
))
10320 vty_out(vty
, " compatible rfc1583\n");
10322 /* auto-cost reference-bandwidth configuration. */
10323 if (ospf
->ref_bandwidth
!= OSPF_DEFAULT_REF_BANDWIDTH
) {
10325 "! Important: ensure reference bandwidth "
10326 "is consistent across all routers\n");
10327 vty_out(vty
, " auto-cost reference-bandwidth %d\n",
10328 ospf
->ref_bandwidth
);
10331 /* SPF timers print. */
10332 if (ospf
->spf_delay
!= OSPF_SPF_DELAY_DEFAULT
10333 || ospf
->spf_holdtime
!= OSPF_SPF_HOLDTIME_DEFAULT
10334 || ospf
->spf_max_holdtime
!= OSPF_SPF_MAX_HOLDTIME_DEFAULT
)
10335 vty_out(vty
, " timers throttle spf %d %d %d\n", ospf
->spf_delay
,
10336 ospf
->spf_holdtime
, ospf
->spf_max_holdtime
);
10338 /* LSA timers print. */
10339 if (ospf
->min_ls_interval
!= OSPF_MIN_LS_INTERVAL
)
10340 vty_out(vty
, " timers throttle lsa all %d\n",
10341 ospf
->min_ls_interval
);
10342 if (ospf
->min_ls_arrival
!= OSPF_MIN_LS_ARRIVAL
)
10343 vty_out(vty
, " timers lsa min-arrival %d\n",
10344 ospf
->min_ls_arrival
);
10346 /* Write multiplier print. */
10347 if (ospf
->write_oi_count
!= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
)
10348 vty_out(vty
, " ospf write-multiplier %d\n",
10349 ospf
->write_oi_count
);
10351 /* Max-metric router-lsa print */
10352 config_write_stub_router(vty
, ospf
);
10354 /* SPF refresh parameters print. */
10355 if (ospf
->lsa_refresh_interval
!= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
10356 vty_out(vty
, " refresh timer %d\n", ospf
->lsa_refresh_interval
);
10358 /* Redistribute information print. */
10359 config_write_ospf_redistribute(vty
, ospf
);
10361 /* passive-interface print. */
10362 if (ospf
->passive_interface_default
== OSPF_IF_PASSIVE
)
10363 vty_out(vty
, " passive-interface default\n");
10365 FOR_ALL_INTERFACES (vrf
, ifp
)
10366 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp
),
10368 && IF_DEF_PARAMS(ifp
)->passive_interface
10369 != ospf
->passive_interface_default
) {
10370 vty_out(vty
, " %spassive-interface %s\n",
10371 IF_DEF_PARAMS(ifp
)->passive_interface
? ""
10375 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
10376 if (!OSPF_IF_PARAM_CONFIGURED(oi
->params
, passive_interface
))
10378 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(oi
->ifp
),
10379 passive_interface
)) {
10380 if (oi
->params
->passive_interface
10381 == IF_DEF_PARAMS(oi
->ifp
)->passive_interface
)
10383 } else if (oi
->params
->passive_interface
10384 == ospf
->passive_interface_default
)
10387 vty_out(vty
, " %spassive-interface %s %s\n",
10388 oi
->params
->passive_interface
? "" : "no ",
10389 oi
->ifp
->name
, inet_ntoa(oi
->address
->u
.prefix4
));
10392 /* Network area print. */
10393 config_write_network_area(vty
, ospf
);
10395 /* Area config print. */
10396 config_write_ospf_area(vty
, ospf
);
10398 /* static neighbor print. */
10399 config_write_ospf_nbr_nbma(vty
, ospf
);
10401 /* Virtual-Link print. */
10402 config_write_virtual_link(vty
, ospf
);
10404 /* Default metric configuration. */
10405 config_write_ospf_default_metric(vty
, ospf
);
10407 /* Distribute-list and default-information print. */
10408 config_write_ospf_distribute(vty
, ospf
);
10410 /* Distance configuration. */
10411 config_write_ospf_distance(vty
, ospf
);
10413 ospf_opaque_config_write_router(vty
, ospf
);
10419 /* OSPF configuration write function. */
10420 static int ospf_config_write(struct vty
*vty
)
10423 struct listnode
*ospf_node
= NULL
;
10426 if (listcount(om
->ospf
) == 0)
10429 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, ospf_node
, ospf
)) {
10430 /* VRF Default check if it is running.
10431 * Upon daemon start, there could be default instance
10432 * in absence of 'router ospf'/oi_running is disabled. */
10433 if (ospf
->vrf_id
== VRF_DEFAULT
&& ospf
->oi_running
)
10434 write
+= ospf_config_write_one(vty
, ospf
);
10435 /* For Non-Default VRF simply display the configuration,
10436 * even if it is not oi_running. */
10437 else if (ospf
->vrf_id
!= VRF_DEFAULT
)
10438 write
+= ospf_config_write_one(vty
, ospf
);
10443 void ospf_vty_show_init(void)
10445 /* "show ip ospf" commands. */
10446 install_element(VIEW_NODE
, &show_ip_ospf_cmd
);
10448 install_element(VIEW_NODE
, &show_ip_ospf_instance_cmd
);
10450 /* "show ip ospf database" commands. */
10451 install_element(VIEW_NODE
, &show_ip_ospf_database_max_cmd
);
10453 install_element(VIEW_NODE
,
10454 &show_ip_ospf_instance_database_type_adv_router_cmd
);
10455 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_cmd
);
10456 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_max_cmd
);
10458 /* "show ip ospf interface" commands. */
10459 install_element(VIEW_NODE
, &show_ip_ospf_interface_cmd
);
10461 install_element(VIEW_NODE
, &show_ip_ospf_instance_interface_cmd
);
10462 /* "show ip ospf interface traffic */
10463 install_element(VIEW_NODE
, &show_ip_ospf_interface_traffic_cmd
);
10465 /* "show ip ospf neighbor" commands. */
10466 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_detail_cmd
);
10467 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_cmd
);
10468 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_id_cmd
);
10469 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_all_cmd
);
10470 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_cmd
);
10471 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_cmd
);
10472 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_all_cmd
);
10474 install_element(VIEW_NODE
,
10475 &show_ip_ospf_instance_neighbor_int_detail_cmd
);
10476 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_int_cmd
);
10477 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_id_cmd
);
10478 install_element(VIEW_NODE
,
10479 &show_ip_ospf_instance_neighbor_detail_all_cmd
);
10480 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_detail_cmd
);
10481 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_cmd
);
10482 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_all_cmd
);
10484 /* "show ip ospf route" commands. */
10485 install_element(VIEW_NODE
, &show_ip_ospf_route_cmd
);
10486 install_element(VIEW_NODE
, &show_ip_ospf_border_routers_cmd
);
10488 install_element(VIEW_NODE
, &show_ip_ospf_instance_route_cmd
);
10489 install_element(VIEW_NODE
, &show_ip_ospf_instance_border_routers_cmd
);
10491 /* "show ip ospf vrfs" commands. */
10492 install_element(VIEW_NODE
, &show_ip_ospf_vrfs_cmd
);
10496 /* ospfd's interface node. */
10497 static struct cmd_node interface_node
= {INTERFACE_NODE
, "%s(config-if)# ", 1};
10499 /* Initialization of OSPF interface. */
10500 static void ospf_vty_if_init(void)
10502 /* Install interface node. */
10503 install_node(&interface_node
, config_write_interface
);
10506 /* "ip ospf authentication" commands. */
10507 install_element(INTERFACE_NODE
, &ip_ospf_authentication_args_addr_cmd
);
10508 install_element(INTERFACE_NODE
, &ip_ospf_authentication_addr_cmd
);
10509 install_element(INTERFACE_NODE
,
10510 &no_ip_ospf_authentication_args_addr_cmd
);
10511 install_element(INTERFACE_NODE
, &no_ip_ospf_authentication_addr_cmd
);
10512 install_element(INTERFACE_NODE
, &ip_ospf_authentication_key_addr_cmd
);
10513 install_element(INTERFACE_NODE
,
10514 &no_ip_ospf_authentication_key_authkey_addr_cmd
);
10515 install_element(INTERFACE_NODE
,
10516 &no_ospf_authentication_key_authkey_addr_cmd
);
10518 /* "ip ospf message-digest-key" commands. */
10519 install_element(INTERFACE_NODE
, &ip_ospf_message_digest_key_cmd
);
10520 install_element(INTERFACE_NODE
, &no_ip_ospf_message_digest_key_cmd
);
10522 /* "ip ospf cost" commands. */
10523 install_element(INTERFACE_NODE
, &ip_ospf_cost_cmd
);
10524 install_element(INTERFACE_NODE
, &no_ip_ospf_cost_cmd
);
10526 /* "ip ospf mtu-ignore" commands. */
10527 install_element(INTERFACE_NODE
, &ip_ospf_mtu_ignore_addr_cmd
);
10528 install_element(INTERFACE_NODE
, &no_ip_ospf_mtu_ignore_addr_cmd
);
10530 /* "ip ospf dead-interval" commands. */
10531 install_element(INTERFACE_NODE
, &ip_ospf_dead_interval_cmd
);
10532 install_element(INTERFACE_NODE
,
10533 &ip_ospf_dead_interval_minimal_addr_cmd
);
10534 install_element(INTERFACE_NODE
, &no_ip_ospf_dead_interval_cmd
);
10536 /* "ip ospf hello-interval" commands. */
10537 install_element(INTERFACE_NODE
, &ip_ospf_hello_interval_cmd
);
10538 install_element(INTERFACE_NODE
, &no_ip_ospf_hello_interval_cmd
);
10540 /* "ip ospf network" commands. */
10541 install_element(INTERFACE_NODE
, &ip_ospf_network_cmd
);
10542 install_element(INTERFACE_NODE
, &no_ip_ospf_network_cmd
);
10544 /* "ip ospf priority" commands. */
10545 install_element(INTERFACE_NODE
, &ip_ospf_priority_cmd
);
10546 install_element(INTERFACE_NODE
, &no_ip_ospf_priority_cmd
);
10548 /* "ip ospf retransmit-interval" commands. */
10549 install_element(INTERFACE_NODE
, &ip_ospf_retransmit_interval_addr_cmd
);
10550 install_element(INTERFACE_NODE
,
10551 &no_ip_ospf_retransmit_interval_addr_cmd
);
10553 /* "ip ospf transmit-delay" commands. */
10554 install_element(INTERFACE_NODE
, &ip_ospf_transmit_delay_addr_cmd
);
10555 install_element(INTERFACE_NODE
, &no_ip_ospf_transmit_delay_addr_cmd
);
10557 /* "ip ospf area" commands. */
10558 install_element(INTERFACE_NODE
, &ip_ospf_area_cmd
);
10559 install_element(INTERFACE_NODE
, &no_ip_ospf_area_cmd
);
10561 /* These commands are compatibitliy for previous version. */
10562 install_element(INTERFACE_NODE
, &ospf_authentication_key_cmd
);
10563 install_element(INTERFACE_NODE
, &ospf_message_digest_key_cmd
);
10564 install_element(INTERFACE_NODE
, &no_ospf_message_digest_key_cmd
);
10565 install_element(INTERFACE_NODE
, &ospf_dead_interval_cmd
);
10566 install_element(INTERFACE_NODE
, &no_ospf_dead_interval_cmd
);
10567 install_element(INTERFACE_NODE
, &ospf_hello_interval_cmd
);
10568 install_element(INTERFACE_NODE
, &no_ospf_hello_interval_cmd
);
10569 install_element(INTERFACE_NODE
, &ospf_cost_cmd
);
10570 install_element(INTERFACE_NODE
, &no_ospf_cost_cmd
);
10571 install_element(INTERFACE_NODE
, &ospf_network_cmd
);
10572 install_element(INTERFACE_NODE
, &no_ospf_network_cmd
);
10573 install_element(INTERFACE_NODE
, &ospf_priority_cmd
);
10574 install_element(INTERFACE_NODE
, &no_ospf_priority_cmd
);
10575 install_element(INTERFACE_NODE
, &ospf_retransmit_interval_cmd
);
10576 install_element(INTERFACE_NODE
, &no_ospf_retransmit_interval_cmd
);
10577 install_element(INTERFACE_NODE
, &ospf_transmit_delay_cmd
);
10578 install_element(INTERFACE_NODE
, &no_ospf_transmit_delay_cmd
);
10581 static void ospf_vty_zebra_init(void)
10583 install_element(OSPF_NODE
, &ospf_redistribute_source_cmd
);
10584 install_element(OSPF_NODE
, &no_ospf_redistribute_source_cmd
);
10585 install_element(OSPF_NODE
, &ospf_redistribute_instance_source_cmd
);
10586 install_element(OSPF_NODE
, &no_ospf_redistribute_instance_source_cmd
);
10588 install_element(OSPF_NODE
, &ospf_distribute_list_out_cmd
);
10589 install_element(OSPF_NODE
, &no_ospf_distribute_list_out_cmd
);
10591 install_element(OSPF_NODE
, &ospf_default_information_originate_cmd
);
10592 install_element(OSPF_NODE
, &no_ospf_default_information_originate_cmd
);
10594 install_element(OSPF_NODE
, &ospf_default_metric_cmd
);
10595 install_element(OSPF_NODE
, &no_ospf_default_metric_cmd
);
10597 install_element(OSPF_NODE
, &ospf_distance_cmd
);
10598 install_element(OSPF_NODE
, &no_ospf_distance_cmd
);
10599 install_element(OSPF_NODE
, &no_ospf_distance_ospf_cmd
);
10600 install_element(OSPF_NODE
, &ospf_distance_ospf_cmd
);
10602 install_element (OSPF_NODE
, &ospf_distance_source_cmd
);
10603 install_element (OSPF_NODE
, &no_ospf_distance_source_cmd
);
10604 install_element (OSPF_NODE
, &ospf_distance_source_access_list_cmd
);
10605 install_element (OSPF_NODE
, &no_ospf_distance_source_access_list_cmd
);
10609 static struct cmd_node ospf_node
= {OSPF_NODE
, "%s(config-router)# ", 1};
10611 static void ospf_interface_clear(struct interface
*ifp
)
10613 if (!if_is_operative(ifp
))
10616 if (IS_DEBUG_OSPF(ism
, ISM_EVENTS
))
10617 zlog_debug("ISM[%s]: clear by reset", ifp
->name
);
10619 ospf_if_reset(ifp
);
10622 DEFUN (clear_ip_ospf_interface
,
10623 clear_ip_ospf_interface_cmd
,
10624 "clear ip ospf interface [IFNAME]",
10627 "OSPF information\n"
10628 "Interface information\n"
10629 "Interface name\n")
10631 int idx_ifname
= 4;
10632 struct interface
*ifp
;
10633 struct listnode
*node
;
10634 struct ospf
*ospf
= NULL
;
10636 if (argc
== 4) /* Clear all the ospfv2 interfaces. */
10638 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
10639 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
10640 FOR_ALL_INTERFACES (vrf
, ifp
)
10641 ospf_interface_clear(ifp
);
10644 /* Interface name is specified. */
10645 ifp
= if_lookup_by_name_all_vrf(argv
[idx_ifname
]->arg
);
10647 vty_out(vty
, "No such interface name\n");
10649 ospf_interface_clear(ifp
);
10652 return CMD_SUCCESS
;
10655 void ospf_vty_clear_init(void)
10657 install_element(ENABLE_NODE
, &clear_ip_ospf_interface_cmd
);
10661 /* Install OSPF related vty commands. */
10662 void ospf_vty_init(void)
10664 /* Install ospf top node. */
10665 install_node(&ospf_node
, ospf_config_write
);
10667 /* "router ospf" commands. */
10668 install_element(CONFIG_NODE
, &router_ospf_cmd
);
10669 install_element(CONFIG_NODE
, &no_router_ospf_cmd
);
10672 install_default(OSPF_NODE
);
10674 /* "ospf router-id" commands. */
10675 install_element(OSPF_NODE
, &ospf_router_id_cmd
);
10676 install_element(OSPF_NODE
, &ospf_router_id_old_cmd
);
10677 install_element(OSPF_NODE
, &no_ospf_router_id_cmd
);
10679 /* "passive-interface" commands. */
10680 install_element(OSPF_NODE
, &ospf_passive_interface_addr_cmd
);
10681 install_element(OSPF_NODE
, &no_ospf_passive_interface_addr_cmd
);
10683 /* "ospf abr-type" commands. */
10684 install_element(OSPF_NODE
, &ospf_abr_type_cmd
);
10685 install_element(OSPF_NODE
, &no_ospf_abr_type_cmd
);
10687 /* "ospf log-adjacency-changes" commands. */
10688 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_cmd
);
10689 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_detail_cmd
);
10690 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_cmd
);
10691 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_detail_cmd
);
10693 /* "ospf rfc1583-compatible" commands. */
10694 install_element(OSPF_NODE
, &ospf_compatible_rfc1583_cmd
);
10695 install_element(OSPF_NODE
, &no_ospf_compatible_rfc1583_cmd
);
10696 install_element(OSPF_NODE
, &ospf_rfc1583_flag_cmd
);
10697 install_element(OSPF_NODE
, &no_ospf_rfc1583_flag_cmd
);
10699 /* "network area" commands. */
10700 install_element(OSPF_NODE
, &ospf_network_area_cmd
);
10701 install_element(OSPF_NODE
, &no_ospf_network_area_cmd
);
10703 /* "area authentication" commands. */
10704 install_element(OSPF_NODE
,
10705 &ospf_area_authentication_message_digest_cmd
);
10706 install_element(OSPF_NODE
, &ospf_area_authentication_cmd
);
10707 install_element(OSPF_NODE
, &no_ospf_area_authentication_cmd
);
10709 /* "area range" commands. */
10710 install_element(OSPF_NODE
, &ospf_area_range_cmd
);
10711 install_element(OSPF_NODE
, &ospf_area_range_cost_cmd
);
10712 install_element(OSPF_NODE
, &ospf_area_range_not_advertise_cmd
);
10713 install_element(OSPF_NODE
, &no_ospf_area_range_cmd
);
10714 install_element(OSPF_NODE
, &ospf_area_range_substitute_cmd
);
10715 install_element(OSPF_NODE
, &no_ospf_area_range_substitute_cmd
);
10717 /* "area virtual-link" commands. */
10718 install_element(OSPF_NODE
, &ospf_area_vlink_cmd
);
10719 install_element(OSPF_NODE
, &ospf_area_vlink_intervals_cmd
);
10720 install_element(OSPF_NODE
, &no_ospf_area_vlink_cmd
);
10721 install_element(OSPF_NODE
, &no_ospf_area_vlink_intervals_cmd
);
10724 /* "area stub" commands. */
10725 install_element(OSPF_NODE
, &ospf_area_stub_no_summary_cmd
);
10726 install_element(OSPF_NODE
, &ospf_area_stub_cmd
);
10727 install_element(OSPF_NODE
, &no_ospf_area_stub_no_summary_cmd
);
10728 install_element(OSPF_NODE
, &no_ospf_area_stub_cmd
);
10730 /* "area nssa" commands. */
10731 install_element(OSPF_NODE
, &ospf_area_nssa_cmd
);
10732 install_element(OSPF_NODE
, &ospf_area_nssa_translate_cmd
);
10733 install_element(OSPF_NODE
, &ospf_area_nssa_no_summary_cmd
);
10734 install_element(OSPF_NODE
, &no_ospf_area_nssa_no_summary_cmd
);
10735 install_element(OSPF_NODE
, &no_ospf_area_nssa_cmd
);
10737 install_element(OSPF_NODE
, &ospf_area_default_cost_cmd
);
10738 install_element(OSPF_NODE
, &no_ospf_area_default_cost_cmd
);
10740 install_element(OSPF_NODE
, &ospf_area_shortcut_cmd
);
10741 install_element(OSPF_NODE
, &no_ospf_area_shortcut_cmd
);
10743 install_element(OSPF_NODE
, &ospf_area_export_list_cmd
);
10744 install_element(OSPF_NODE
, &no_ospf_area_export_list_cmd
);
10746 install_element(OSPF_NODE
, &ospf_area_filter_list_cmd
);
10747 install_element(OSPF_NODE
, &no_ospf_area_filter_list_cmd
);
10749 install_element(OSPF_NODE
, &ospf_area_import_list_cmd
);
10750 install_element(OSPF_NODE
, &no_ospf_area_import_list_cmd
);
10752 /* SPF timer commands */
10753 install_element(OSPF_NODE
, &ospf_timers_throttle_spf_cmd
);
10754 install_element(OSPF_NODE
, &no_ospf_timers_throttle_spf_cmd
);
10756 /* LSA timers commands */
10757 install_element(OSPF_NODE
, &ospf_timers_min_ls_interval_cmd
);
10758 install_element(OSPF_NODE
, &no_ospf_timers_min_ls_interval_cmd
);
10759 install_element(OSPF_NODE
, &ospf_timers_lsa_min_arrival_cmd
);
10760 install_element(OSPF_NODE
, &no_ospf_timers_lsa_min_arrival_cmd
);
10762 /* refresh timer commands */
10763 install_element(OSPF_NODE
, &ospf_refresh_timer_cmd
);
10764 install_element(OSPF_NODE
, &no_ospf_refresh_timer_val_cmd
);
10766 /* max-metric commands */
10767 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_admin_cmd
);
10768 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_admin_cmd
);
10769 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_startup_cmd
);
10770 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_startup_cmd
);
10771 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_shutdown_cmd
);
10772 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_shutdown_cmd
);
10774 /* reference bandwidth commands */
10775 install_element(OSPF_NODE
, &ospf_auto_cost_reference_bandwidth_cmd
);
10776 install_element(OSPF_NODE
, &no_ospf_auto_cost_reference_bandwidth_cmd
);
10778 /* "neighbor" commands. */
10779 install_element(OSPF_NODE
, &ospf_neighbor_cmd
);
10780 install_element(OSPF_NODE
, &ospf_neighbor_poll_interval_cmd
);
10781 install_element(OSPF_NODE
, &no_ospf_neighbor_cmd
);
10782 install_element(OSPF_NODE
, &no_ospf_neighbor_poll_cmd
);
10784 /* write multiplier commands */
10785 install_element(OSPF_NODE
, &ospf_write_multiplier_cmd
);
10786 install_element(OSPF_NODE
, &write_multiplier_cmd
);
10787 install_element(OSPF_NODE
, &no_ospf_write_multiplier_cmd
);
10788 install_element(OSPF_NODE
, &no_write_multiplier_cmd
);
10790 /* Init interface related vty commands. */
10791 ospf_vty_if_init();
10793 /* Init zebra related vty commands. */
10794 ospf_vty_zebra_init();