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 if (!ospf_interface_area_is_already_set(ospf
,
250 ospf_interface_area_set(ospf
, ifp
);
251 ospf
->if_ospf_cli_count
++;
256 ospf_router_id_update(ospf
);
262 DEFUN (no_router_ospf
,
264 "no router ospf [{(1-65535)|vrf NAME}]",
266 "Enable a routing process\n"
267 "Start OSPF configuration\n"
272 unsigned short instance
= 0;
274 ospf
= ospf_cmd_lookup_ospf(vty
, argv
, argc
, 0, &instance
);
277 return CMD_NOT_MY_INSTANCE
;
287 DEFPY (ospf_router_id
,
289 "ospf router-id A.B.C.D",
290 "OSPF specific commands\n"
291 "router-id for the OSPF process\n"
292 "OSPF router-id in IP address format\n")
294 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
296 struct listnode
*node
;
297 struct ospf_area
*area
;
299 ospf
->router_id_static
= router_id
;
301 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
302 if (area
->full_nbrs
) {
304 "For this router-id change to take effect,"
305 " save config and restart ospfd\n");
309 ospf_router_id_update(ospf
);
314 DEFUN_HIDDEN (ospf_router_id_old
,
315 ospf_router_id_old_cmd
,
317 "router-id for the OSPF process\n"
318 "OSPF router-id in IP address format\n")
320 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
322 struct listnode
*node
;
323 struct ospf_area
*area
;
324 struct in_addr router_id
;
327 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &router_id
);
329 vty_out(vty
, "Please specify Router ID by A.B.C.D\n");
330 return CMD_WARNING_CONFIG_FAILED
;
333 ospf
->router_id_static
= router_id
;
335 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
336 if (area
->full_nbrs
) {
338 "For this router-id change to take effect,"
339 " save config and restart ospfd\n");
343 ospf_router_id_update(ospf
);
348 DEFPY (no_ospf_router_id
,
349 no_ospf_router_id_cmd
,
350 "no ospf router-id [A.B.C.D]",
352 "OSPF specific commands\n"
353 "router-id for the OSPF process\n"
354 "OSPF router-id in IP address format\n")
356 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
357 struct listnode
*node
;
358 struct ospf_area
*area
;
361 if (!IPV4_ADDR_SAME(&ospf
->router_id_static
, &router_id
)) {
362 vty_out(vty
, "%% OSPF router-id doesn't match\n");
363 return CMD_WARNING_CONFIG_FAILED
;
367 ospf
->router_id_static
.s_addr
= 0;
369 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
370 if (area
->full_nbrs
) {
372 "For this router-id change to take effect,"
373 " save config and restart ospfd\n");
377 ospf_router_id_update(ospf
);
383 static void ospf_passive_interface_default(struct ospf
*ospf
, uint8_t newval
)
385 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
387 struct interface
*ifp
;
388 struct ospf_interface
*oi
;
390 ospf
->passive_interface_default
= newval
;
392 FOR_ALL_INTERFACES (vrf
, ifp
) {
393 if (ifp
&& OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp
),
395 UNSET_IF_PARAM(IF_DEF_PARAMS(ifp
), passive_interface
);
397 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, ln
, oi
)) {
398 if (OSPF_IF_PARAM_CONFIGURED(oi
->params
, passive_interface
))
399 UNSET_IF_PARAM(oi
->params
, passive_interface
);
400 /* update multicast memberships */
401 ospf_if_set_multicast(oi
);
405 static void ospf_passive_interface_update_addr(struct ospf
*ospf
,
406 struct interface
*ifp
,
407 struct ospf_if_params
*params
,
413 params
->passive_interface
= value
;
414 if (params
!= IF_DEF_PARAMS(ifp
)) {
415 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp
),
417 dflt
= IF_DEF_PARAMS(ifp
)->passive_interface
;
419 dflt
= ospf
->passive_interface_default
;
422 SET_IF_PARAM(params
, passive_interface
);
424 UNSET_IF_PARAM(params
, passive_interface
);
426 ospf_free_if_params(ifp
, addr
);
427 ospf_if_update_params(ifp
, addr
);
431 static void ospf_passive_interface_update(struct ospf
*ospf
,
432 struct interface
*ifp
,
433 struct ospf_if_params
*params
,
436 params
->passive_interface
= value
;
437 if (params
== IF_DEF_PARAMS(ifp
)) {
438 if (value
!= ospf
->passive_interface_default
)
439 SET_IF_PARAM(params
, passive_interface
);
441 UNSET_IF_PARAM(params
, passive_interface
);
445 DEFUN (ospf_passive_interface
,
446 ospf_passive_interface_addr_cmd
,
447 "passive-interface <IFNAME [A.B.C.D]|default>",
448 "Suppress routing updates on an interface\n"
451 "Suppress routing updates on interfaces by default\n")
453 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
455 struct interface
*ifp
= NULL
;
456 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
458 struct ospf_if_params
*params
;
459 struct route_node
*rn
;
461 if (strmatch(argv
[1]->text
, "default")) {
462 ospf_passive_interface_default(ospf
, OSPF_IF_PASSIVE
);
465 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
466 ifp
= if_get_by_name(argv
[1]->arg
, ospf
->vrf_id
);
469 vty_out(vty
, "interface %s not found.\n", (char *)argv
[1]->arg
);
470 return CMD_WARNING_CONFIG_FAILED
;
473 params
= IF_DEF_PARAMS(ifp
);
476 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
479 "Please specify interface address by A.B.C.D\n");
480 return CMD_WARNING_CONFIG_FAILED
;
483 params
= ospf_get_if_params(ifp
, addr
);
484 ospf_if_update_params(ifp
, addr
);
485 ospf_passive_interface_update_addr(ospf
, ifp
, params
,
486 OSPF_IF_PASSIVE
, addr
);
489 ospf_passive_interface_update(ospf
, ifp
, params
, OSPF_IF_PASSIVE
);
491 /* XXX We should call ospf_if_set_multicast on exactly those
492 * interfaces for which the passive property changed. It is too much
493 * work to determine this set, so we do this for every interface.
494 * This is safe and reasonable because ospf_if_set_multicast uses a
495 * record of joined groups to avoid systems calls if the desired
496 * memberships match the current memership.
499 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
500 struct ospf_interface
*oi
= rn
->info
;
502 if (oi
&& (OSPF_IF_PARAM(oi
, passive_interface
)
504 ospf_if_set_multicast(oi
);
507 * XXX It is not clear what state transitions the interface needs to
508 * undergo when going from active to passive. Fixing this will
509 * require precise identification of interfaces having such a
516 DEFUN (no_ospf_passive_interface
,
517 no_ospf_passive_interface_addr_cmd
,
518 "no passive-interface <IFNAME [A.B.C.D]|default>",
520 "Allow routing updates on an interface\n"
523 "Allow routing updates on interfaces by default\n")
525 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
527 struct interface
*ifp
= NULL
;
528 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
529 struct ospf_if_params
*params
;
531 struct route_node
*rn
;
533 if (strmatch(argv
[2]->text
, "default")) {
534 ospf_passive_interface_default(ospf
, OSPF_IF_ACTIVE
);
538 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
539 ifp
= if_get_by_name(argv
[2]->arg
, ospf
->vrf_id
);
542 vty_out(vty
, "interface %s not found.\n", (char *)argv
[2]->arg
);
543 return CMD_WARNING_CONFIG_FAILED
;
546 params
= IF_DEF_PARAMS(ifp
);
549 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
552 "Please specify interface address by A.B.C.D\n");
553 return CMD_WARNING_CONFIG_FAILED
;
556 params
= ospf_lookup_if_params(ifp
, addr
);
559 ospf_passive_interface_update_addr(ospf
, ifp
, params
,
560 OSPF_IF_ACTIVE
, addr
);
562 ospf_passive_interface_update(ospf
, ifp
, params
, OSPF_IF_ACTIVE
);
564 /* XXX We should call ospf_if_set_multicast on exactly those
565 * interfaces for which the passive property changed. It is too much
566 * work to determine this set, so we do this for every interface.
567 * This is safe and reasonable because ospf_if_set_multicast uses a
568 * record of joined groups to avoid systems calls if the desired
569 * memberships match the current memership.
571 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
572 struct ospf_interface
*oi
= rn
->info
;
575 && (OSPF_IF_PARAM(oi
, passive_interface
) == OSPF_IF_ACTIVE
))
576 ospf_if_set_multicast(oi
);
583 DEFUN (ospf_network_area
,
584 ospf_network_area_cmd
,
585 "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
586 "Enable routing on an IP network\n"
587 "OSPF network prefix\n"
588 "Set the OSPF area ID\n"
589 "OSPF area ID in IP address format\n"
590 "OSPF area ID as a decimal value\n")
592 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
593 int idx_ipv4_prefixlen
= 1;
594 int idx_ipv4_number
= 3;
595 struct prefix_ipv4 p
;
596 struct in_addr area_id
;
599 if (ospf
->instance
) {
601 "The network command is not supported in multi-instance ospf\n");
602 return CMD_WARNING_CONFIG_FAILED
;
605 if (ospf
->if_ospf_cli_count
> 0) {
607 "Please remove all ip ospf area x.x.x.x commands first.\n");
608 if (IS_DEBUG_OSPF_EVENT
)
610 "%s ospf vrf %s num of %u ip osp area x config",
612 ospf
->name
? ospf
->name
: "NIL",
613 ospf
->if_ospf_cli_count
);
614 return CMD_WARNING_CONFIG_FAILED
;
617 /* Get network prefix and Area ID. */
618 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
619 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
621 ret
= ospf_network_set(ospf
, &p
, area_id
, format
);
623 vty_out(vty
, "There is already same network statement.\n");
624 return CMD_WARNING_CONFIG_FAILED
;
630 DEFUN (no_ospf_network_area
,
631 no_ospf_network_area_cmd
,
632 "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
634 "Enable routing on an IP network\n"
635 "OSPF network prefix\n"
636 "Set the OSPF area ID\n"
637 "OSPF area ID in IP address format\n"
638 "OSPF area ID as a decimal value\n")
640 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
641 int idx_ipv4_prefixlen
= 2;
642 int idx_ipv4_number
= 4;
643 struct prefix_ipv4 p
;
644 struct in_addr area_id
;
647 if (ospf
->instance
) {
649 "The network command is not supported in multi-instance ospf\n");
650 return CMD_WARNING_CONFIG_FAILED
;
653 /* Get network prefix and Area ID. */
654 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
655 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
657 ret
= ospf_network_unset(ospf
, &p
, area_id
);
660 "Can't find specified network area configuration.\n");
661 return CMD_WARNING_CONFIG_FAILED
;
667 DEFUN (ospf_area_range
,
669 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]",
670 "OSPF area parameters\n"
671 "OSPF area ID in IP address format\n"
672 "OSPF area ID as a decimal value\n"
673 "Summarize routes matching address/mask (border routers only)\n"
674 "Area range prefix\n"
675 "Advertise this range (default)\n"
676 "User specified metric for this range\n"
677 "Advertised metric for this range\n")
679 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
680 int idx_ipv4_number
= 1;
681 int idx_ipv4_prefixlen
= 3;
683 struct prefix_ipv4 p
;
684 struct in_addr area_id
;
688 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
689 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
691 ospf_area_range_set(ospf
, area_id
, &p
, OSPF_AREA_RANGE_ADVERTISE
);
693 cost
= strtoul(argv
[idx_cost
]->arg
, NULL
, 10);
694 ospf_area_range_cost_set(ospf
, area_id
, &p
, cost
);
700 DEFUN (ospf_area_range_cost
,
701 ospf_area_range_cost_cmd
,
702 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M cost (0-16777215)",
703 "OSPF area parameters\n"
704 "OSPF area ID in IP address format\n"
705 "OSPF area ID as a decimal value\n"
706 "Summarize routes matching address/mask (border routers only)\n"
707 "Area range prefix\n"
708 "User specified metric for this range\n"
709 "Advertised metric for this range\n")
711 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
712 int idx_ipv4_number
= 1;
713 int idx_ipv4_prefixlen
= 3;
715 struct prefix_ipv4 p
;
716 struct in_addr area_id
;
720 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
721 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
723 ospf_area_range_set(ospf
, area_id
, &p
, OSPF_AREA_RANGE_ADVERTISE
);
724 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
727 cost
= strtoul(argv
[idx_cost
]->arg
, NULL
, 10);
728 ospf_area_range_cost_set(ospf
, area_id
, &p
, cost
);
733 DEFUN (ospf_area_range_not_advertise
,
734 ospf_area_range_not_advertise_cmd
,
735 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise",
736 "OSPF area parameters\n"
737 "OSPF area ID in IP address format\n"
738 "OSPF area ID as a decimal value\n"
739 "Summarize routes matching address/mask (border routers only)\n"
740 "Area range prefix\n"
741 "DoNotAdvertise this range\n")
743 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
744 int idx_ipv4_number
= 1;
745 int idx_ipv4_prefixlen
= 3;
746 struct prefix_ipv4 p
;
747 struct in_addr area_id
;
750 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
751 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
753 ospf_area_range_set(ospf
, area_id
, &p
, 0);
754 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
756 ospf_area_range_substitute_unset(ospf
, area_id
, &p
);
761 DEFUN (no_ospf_area_range
,
762 no_ospf_area_range_cmd
,
763 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]",
765 "OSPF area parameters\n"
766 "OSPF area ID in IP address format\n"
767 "OSPF area ID as a decimal value\n"
768 "Summarize routes matching address/mask (border routers only)\n"
769 "Area range prefix\n"
770 "User specified metric for this range\n"
771 "Advertised metric for this range\n"
772 "Advertise this range (default)\n"
773 "User specified metric for this range\n"
774 "Advertised metric for this range\n"
775 "DoNotAdvertise this range\n")
777 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
778 int idx_ipv4_number
= 2;
779 int idx_ipv4_prefixlen
= 4;
780 struct prefix_ipv4 p
;
781 struct in_addr area_id
;
784 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
785 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
787 ospf_area_range_unset(ospf
, area_id
, &p
);
792 DEFUN (ospf_area_range_substitute
,
793 ospf_area_range_substitute_cmd
,
794 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
795 "OSPF area parameters\n"
796 "OSPF area ID in IP address format\n"
797 "OSPF area ID as a decimal value\n"
798 "Summarize routes matching address/mask (border routers only)\n"
799 "Area range prefix\n"
800 "Announce area range as another prefix\n"
801 "Network prefix to be announced instead of range\n")
803 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
804 int idx_ipv4_number
= 1;
805 int idx_ipv4_prefixlen
= 3;
806 int idx_ipv4_prefixlen_2
= 5;
807 struct prefix_ipv4 p
, s
;
808 struct in_addr area_id
;
811 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
812 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
813 str2prefix_ipv4(argv
[idx_ipv4_prefixlen_2
]->arg
, &s
);
815 ospf_area_range_substitute_set(ospf
, area_id
, &p
, &s
);
816 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
822 DEFUN (no_ospf_area_range_substitute
,
823 no_ospf_area_range_substitute_cmd
,
824 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
826 "OSPF area parameters\n"
827 "OSPF area ID in IP address format\n"
828 "OSPF area ID as a decimal value\n"
829 "Summarize routes matching address/mask (border routers only)\n"
830 "Area range prefix\n"
831 "Announce area range as another prefix\n"
832 "Network prefix to be announced instead of range\n")
834 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
835 int idx_ipv4_number
= 2;
836 int idx_ipv4_prefixlen
= 4;
837 int idx_ipv4_prefixlen_2
= 6;
838 struct prefix_ipv4 p
, s
;
839 struct in_addr area_id
;
842 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
843 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
844 str2prefix_ipv4(argv
[idx_ipv4_prefixlen_2
]->arg
, &s
);
846 ospf_area_range_substitute_unset(ospf
, area_id
, &p
);
852 /* Command Handler Logic in VLink stuff is delicate!!
854 ALTER AT YOUR OWN RISK!!!!
856 Various dummy values are used to represent 'NoChange' state for
857 VLink configuration NOT being changed by a VLink command, and
858 special syntax is used within the command strings so that the
859 typed in command verbs can be seen in the configuration command
860 bacckend handler. This is to drastically reduce the verbeage
861 required to coe up with a reasonably compatible Cisco VLink command
863 - Matthew Grant <grantma@anathoth.gen.nz>
864 Wed, 21 Feb 2001 15:13:52 +1300
867 /* Configuration data for virtual links
869 struct ospf_vl_config_data
{
870 struct vty
*vty
; /* vty stuff */
871 struct in_addr area_id
; /* area ID from command line */
872 int area_id_fmt
; /* command line area ID format */
873 struct in_addr vl_peer
; /* command line vl_peer */
874 int auth_type
; /* Authehntication type, if given */
875 char *auth_key
; /* simple password if present */
876 int crypto_key_id
; /* Cryptographic key ID */
877 char *md5_key
; /* MD5 authentication key */
878 int hello_interval
; /* Obvious what these are... */
879 int retransmit_interval
;
884 static void ospf_vl_config_data_init(struct ospf_vl_config_data
*vl_config
,
887 memset(vl_config
, 0, sizeof(struct ospf_vl_config_data
));
888 vl_config
->auth_type
= OSPF_AUTH_CMD_NOTSEEN
;
889 vl_config
->vty
= vty
;
892 static struct ospf_vl_data
*
893 ospf_find_vl_data(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
895 struct ospf_area
*area
;
896 struct ospf_vl_data
*vl_data
;
898 struct in_addr area_id
;
900 vty
= vl_config
->vty
;
901 area_id
= vl_config
->area_id
;
903 if (area_id
.s_addr
== OSPF_AREA_BACKBONE
) {
905 "Configuring VLs over the backbone is not allowed\n");
908 area
= ospf_area_get(ospf
, area_id
);
909 ospf_area_display_format_set(ospf
, area
, vl_config
->area_id_fmt
);
911 if (area
->external_routing
!= OSPF_AREA_DEFAULT
) {
912 if (vl_config
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
913 vty_out(vty
, "Area %s is %s\n", inet_ntoa(area_id
),
914 area
->external_routing
== OSPF_AREA_NSSA
918 vty_out(vty
, "Area %ld is %s\n",
919 (unsigned long)ntohl(area_id
.s_addr
),
920 area
->external_routing
== OSPF_AREA_NSSA
926 if ((vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
->vl_peer
))
928 vl_data
= ospf_vl_data_new(area
, vl_config
->vl_peer
);
929 if (vl_data
->vl_oi
== NULL
) {
930 vl_data
->vl_oi
= ospf_vl_new(ospf
, vl_data
);
931 ospf_vl_add(ospf
, vl_data
);
932 ospf_spf_calculate_schedule(ospf
,
933 SPF_FLAG_CONFIG_CHANGE
);
940 static int ospf_vl_set_security(struct ospf_vl_data
*vl_data
,
941 struct ospf_vl_config_data
*vl_config
)
943 struct crypt_key
*ck
;
945 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
947 vty
= vl_config
->vty
;
949 if (vl_config
->auth_type
!= OSPF_AUTH_CMD_NOTSEEN
) {
950 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), auth_type
);
951 IF_DEF_PARAMS(ifp
)->auth_type
= vl_config
->auth_type
;
954 if (vl_config
->auth_key
) {
955 memset(IF_DEF_PARAMS(ifp
)->auth_simple
, 0,
956 OSPF_AUTH_SIMPLE_SIZE
+ 1);
957 strncpy((char *)IF_DEF_PARAMS(ifp
)->auth_simple
,
958 vl_config
->auth_key
, OSPF_AUTH_SIMPLE_SIZE
);
959 } else if (vl_config
->md5_key
) {
960 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
961 vl_config
->crypto_key_id
)
963 vty_out(vty
, "OSPF: Key %d already exists\n",
964 vl_config
->crypto_key_id
);
967 ck
= ospf_crypt_key_new();
968 ck
->key_id
= vl_config
->crypto_key_id
;
969 memset(ck
->auth_key
, 0, OSPF_AUTH_MD5_SIZE
+ 1);
970 strncpy((char *)ck
->auth_key
, vl_config
->md5_key
,
973 ospf_crypt_key_add(IF_DEF_PARAMS(ifp
)->auth_crypt
, ck
);
974 } else if (vl_config
->crypto_key_id
!= 0) {
977 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
978 vl_config
->crypto_key_id
)
980 vty_out(vty
, "OSPF: Key %d does not exist\n",
981 vl_config
->crypto_key_id
);
982 return CMD_WARNING_CONFIG_FAILED
;
985 ospf_crypt_key_delete(IF_DEF_PARAMS(ifp
)->auth_crypt
,
986 vl_config
->crypto_key_id
);
992 static int ospf_vl_set_timers(struct ospf_vl_data
*vl_data
,
993 struct ospf_vl_config_data
*vl_config
)
995 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
996 /* Virtual Link data initialised to defaults, so only set
998 if (vl_config
->hello_interval
) {
999 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_hello
);
1000 IF_DEF_PARAMS(ifp
)->v_hello
= vl_config
->hello_interval
;
1003 if (vl_config
->dead_interval
) {
1004 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_wait
);
1005 IF_DEF_PARAMS(ifp
)->v_wait
= vl_config
->dead_interval
;
1008 if (vl_config
->retransmit_interval
) {
1009 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), retransmit_interval
);
1010 IF_DEF_PARAMS(ifp
)->retransmit_interval
=
1011 vl_config
->retransmit_interval
;
1014 if (vl_config
->transmit_delay
) {
1015 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), transmit_delay
);
1016 IF_DEF_PARAMS(ifp
)->transmit_delay
= vl_config
->transmit_delay
;
1023 /* The business end of all of the above */
1024 static int ospf_vl_set(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
1026 struct ospf_vl_data
*vl_data
;
1029 vl_data
= ospf_find_vl_data(ospf
, vl_config
);
1031 return CMD_WARNING_CONFIG_FAILED
;
1033 /* Process this one first as it can have a fatal result, which can
1034 only logically occur if the virtual link exists already
1035 Thus a command error does not result in a change to the
1036 running configuration such as unexpectedly altered timer
1038 ret
= ospf_vl_set_security(vl_data
, vl_config
);
1039 if (ret
!= CMD_SUCCESS
)
1042 /* Set any time based parameters, these area already range checked */
1044 ret
= ospf_vl_set_timers(vl_data
, vl_config
);
1045 if (ret
!= CMD_SUCCESS
)
1051 /* This stuff exists to make specifying all the alias commands A LOT simpler
1053 #define VLINK_HELPSTR_IPADDR \
1054 "OSPF area parameters\n" \
1055 "OSPF area ID in IP address format\n" \
1056 "OSPF area ID as a decimal value\n" \
1057 "Configure a virtual link\n" \
1058 "Router ID of the remote ABR\n"
1060 #define VLINK_HELPSTR_AUTHTYPE_SIMPLE \
1061 "Enable authentication on this virtual link\n" \
1064 #define VLINK_HELPSTR_AUTHTYPE_ALL \
1065 VLINK_HELPSTR_AUTHTYPE_SIMPLE \
1066 "Use null authentication\n" \
1067 "Use message-digest authentication\n"
1069 #define VLINK_HELPSTR_TIME_PARAM \
1070 "Time between HELLO packets\n" \
1072 "Time between retransmitting lost link state advertisements\n" \
1074 "Link state transmit delay\n" \
1076 "Interval time after which a neighbor is declared down\n" \
1079 #define VLINK_HELPSTR_AUTH_SIMPLE \
1080 "Authentication password (key)\n" \
1081 "The OSPF password (key)\n"
1083 #define VLINK_HELPSTR_AUTH_MD5 \
1084 "Message digest authentication password (key)\n" \
1086 "Use MD5 algorithm\n" \
1087 "The OSPF password (key)\n"
1089 DEFUN (ospf_area_vlink
,
1090 ospf_area_vlink_cmd
,
1091 "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>]",
1092 VLINK_HELPSTR_IPADDR
1093 "Enable authentication on this virtual link\n"
1094 "Use message-digest authentication\n"
1095 "Use null authentication\n"
1096 VLINK_HELPSTR_AUTH_MD5
1097 VLINK_HELPSTR_AUTH_SIMPLE
)
1099 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1100 int idx_ipv4_number
= 1;
1102 struct ospf_vl_config_data vl_config
;
1103 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1104 char md5_key
[OSPF_AUTH_MD5_SIZE
+ 1];
1108 ospf_vl_config_data_init(&vl_config
, vty
);
1110 /* Read off first 2 parameters and check them */
1111 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1112 &vl_config
.area_id_fmt
);
1114 vty_out(vty
, "OSPF area ID is invalid\n");
1115 return CMD_WARNING_CONFIG_FAILED
;
1118 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1120 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1121 return CMD_WARNING_CONFIG_FAILED
;
1125 /* Thats all folks! - BUGS B. strikes again!!!*/
1127 return ospf_vl_set(ospf
, &vl_config
);
1130 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1131 /* authentication - this option can only occur
1132 at start of command line */
1133 vl_config
.auth_type
= OSPF_AUTH_SIMPLE
;
1136 if (argv_find(argv
, argc
, "message-digest", &idx
)) {
1137 /* authentication message-digest */
1138 vl_config
.auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
1139 } else if (argv_find(argv
, argc
, "null", &idx
)) {
1140 /* "authentication null" */
1141 vl_config
.auth_type
= OSPF_AUTH_NULL
;
1144 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1145 vl_config
.md5_key
= NULL
;
1146 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1147 if (vl_config
.crypto_key_id
< 0)
1148 return CMD_WARNING_CONFIG_FAILED
;
1150 memset(md5_key
, 0, OSPF_AUTH_MD5_SIZE
+ 1);
1151 strncpy(md5_key
, argv
[idx
+ 3]->arg
, OSPF_AUTH_MD5_SIZE
);
1152 vl_config
.md5_key
= md5_key
;
1155 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1156 memset(auth_key
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
1157 strncpy(auth_key
, argv
[idx
+ 1]->arg
, OSPF_AUTH_SIMPLE_SIZE
);
1158 vl_config
.auth_key
= auth_key
;
1161 /* Action configuration */
1163 return ospf_vl_set(ospf
, &vl_config
);
1166 DEFUN (no_ospf_area_vlink
,
1167 no_ospf_area_vlink_cmd
,
1168 "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>]",
1170 VLINK_HELPSTR_IPADDR
1171 "Enable authentication on this virtual link\n" \
1172 "Use message-digest authentication\n" \
1173 "Use null authentication\n" \
1174 VLINK_HELPSTR_AUTH_MD5
1175 VLINK_HELPSTR_AUTH_SIMPLE
)
1177 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1178 int idx_ipv4_number
= 2;
1180 struct ospf_area
*area
;
1181 struct ospf_vl_config_data vl_config
;
1182 struct ospf_vl_data
*vl_data
= NULL
;
1183 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1187 ospf_vl_config_data_init(&vl_config
, vty
);
1189 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1192 vty_out(vty
, "OSPF area ID is invalid\n");
1193 return CMD_WARNING_CONFIG_FAILED
;
1196 area
= ospf_area_lookup_by_area_id(ospf
, vl_config
.area_id
);
1198 vty_out(vty
, "Area does not exist\n");
1199 return CMD_WARNING_CONFIG_FAILED
;
1202 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1204 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1205 return CMD_WARNING_CONFIG_FAILED
;
1209 /* Basic VLink no command */
1210 /* Thats all folks! - BUGS B. strikes again!!!*/
1211 if ((vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
.vl_peer
)))
1212 ospf_vl_delete(ospf
, vl_data
);
1214 ospf_area_check_free(ospf
, vl_config
.area_id
);
1219 /* If we are down here, we are reseting parameters */
1220 /* Deal with other parameters */
1222 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1223 /* authentication - this option can only occur
1224 at start of command line */
1225 vl_config
.auth_type
= OSPF_AUTH_NOTSET
;
1228 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1229 vl_config
.md5_key
= NULL
;
1230 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1231 if (vl_config
.crypto_key_id
< 0)
1232 return CMD_WARNING_CONFIG_FAILED
;
1235 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1236 /* Reset authentication-key to 0 */
1237 memset(auth_key
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
1238 vl_config
.auth_key
= auth_key
;
1241 /* Action configuration */
1243 return ospf_vl_set(ospf
, &vl_config
);
1246 DEFUN (ospf_area_vlink_intervals
,
1247 ospf_area_vlink_intervals_cmd
,
1248 "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)}",
1249 VLINK_HELPSTR_IPADDR
1250 VLINK_HELPSTR_TIME_PARAM
)
1252 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1253 struct ospf_vl_config_data vl_config
;
1256 ospf_vl_config_data_init(&vl_config
, vty
);
1258 char *area_id
= argv
[1]->arg
;
1259 char *router_id
= argv
[3]->arg
;
1261 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1263 vty_out(vty
, "OSPF area ID is invalid\n");
1264 return CMD_WARNING_CONFIG_FAILED
;
1267 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1269 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1270 return CMD_WARNING_CONFIG_FAILED
;
1273 for (int idx
= 4; idx
< argc
; idx
++) {
1274 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1275 vl_config
.hello_interval
=
1276 strtol(argv
[++idx
]->arg
, NULL
, 10);
1277 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1278 vl_config
.retransmit_interval
=
1279 strtol(argv
[++idx
]->arg
, NULL
, 10);
1280 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1281 vl_config
.transmit_delay
=
1282 strtol(argv
[++idx
]->arg
, NULL
, 10);
1283 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1284 vl_config
.dead_interval
=
1285 strtol(argv
[++idx
]->arg
, NULL
, 10);
1288 /* Action configuration */
1289 return ospf_vl_set(ospf
, &vl_config
);
1292 DEFUN (no_ospf_area_vlink_intervals
,
1293 no_ospf_area_vlink_intervals_cmd
,
1294 "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)}",
1296 VLINK_HELPSTR_IPADDR
1297 VLINK_HELPSTR_TIME_PARAM
)
1299 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1300 struct ospf_vl_config_data vl_config
;
1303 ospf_vl_config_data_init(&vl_config
, vty
);
1305 char *area_id
= argv
[2]->arg
;
1306 char *router_id
= argv
[4]->arg
;
1308 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1310 vty_out(vty
, "OSPF area ID is invalid\n");
1311 return CMD_WARNING_CONFIG_FAILED
;
1314 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1316 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1317 return CMD_WARNING_CONFIG_FAILED
;
1320 for (int idx
= 5; idx
< argc
; idx
++) {
1321 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1322 vl_config
.hello_interval
= OSPF_HELLO_INTERVAL_DEFAULT
;
1323 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1324 vl_config
.retransmit_interval
=
1325 OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
1326 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1327 vl_config
.transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
1328 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1329 vl_config
.dead_interval
=
1330 OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
1333 /* Action configuration */
1334 return ospf_vl_set(ospf
, &vl_config
);
1337 DEFUN (ospf_area_shortcut
,
1338 ospf_area_shortcut_cmd
,
1339 "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>",
1340 "OSPF area parameters\n"
1341 "OSPF area ID in IP address format\n"
1342 "OSPF area ID as a decimal value\n"
1343 "Configure the area's shortcutting mode\n"
1344 "Set default shortcutting behavior\n"
1345 "Enable shortcutting through the area\n"
1346 "Disable shortcutting through the area\n")
1348 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1349 int idx_ipv4_number
= 1;
1350 int idx_enable_disable
= 3;
1351 struct ospf_area
*area
;
1352 struct in_addr area_id
;
1356 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1357 argv
[idx_ipv4_number
]->arg
);
1359 area
= ospf_area_get(ospf
, area_id
);
1360 ospf_area_display_format_set(ospf
, area
, format
);
1362 if (strncmp(argv
[idx_enable_disable
]->arg
, "de", 2) == 0)
1363 mode
= OSPF_SHORTCUT_DEFAULT
;
1364 else if (strncmp(argv
[idx_enable_disable
]->arg
, "di", 2) == 0)
1365 mode
= OSPF_SHORTCUT_DISABLE
;
1366 else if (strncmp(argv
[idx_enable_disable
]->arg
, "e", 1) == 0)
1367 mode
= OSPF_SHORTCUT_ENABLE
;
1369 return CMD_WARNING_CONFIG_FAILED
;
1371 ospf_area_shortcut_set(ospf
, area
, mode
);
1373 if (ospf
->abr_type
!= OSPF_ABR_SHORTCUT
)
1375 "Shortcut area setting will take effect "
1376 "only when the router is configured as Shortcut ABR\n");
1381 DEFUN (no_ospf_area_shortcut
,
1382 no_ospf_area_shortcut_cmd
,
1383 "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>",
1385 "OSPF area parameters\n"
1386 "OSPF area ID in IP address format\n"
1387 "OSPF area ID as a decimal value\n"
1388 "Deconfigure the area's shortcutting mode\n"
1389 "Deconfigure enabled shortcutting through the area\n"
1390 "Deconfigure disabled shortcutting through the area\n")
1392 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1393 int idx_ipv4_number
= 2;
1394 struct ospf_area
*area
;
1395 struct in_addr area_id
;
1398 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1399 argv
[idx_ipv4_number
]->arg
);
1401 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1405 ospf_area_shortcut_unset(ospf
, area
);
1411 DEFUN (ospf_area_stub
,
1413 "area <A.B.C.D|(0-4294967295)> stub",
1414 "OSPF area parameters\n"
1415 "OSPF area ID in IP address format\n"
1416 "OSPF area ID as a decimal value\n"
1417 "Configure OSPF area as stub\n")
1419 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1420 int idx_ipv4_number
= 1;
1421 struct in_addr area_id
;
1424 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1425 argv
[idx_ipv4_number
]->arg
);
1427 ret
= ospf_area_stub_set(ospf
, area_id
);
1428 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1432 "First deconfigure all virtual link through this area\n");
1433 return CMD_WARNING_CONFIG_FAILED
;
1436 ospf_area_no_summary_unset(ospf
, area_id
);
1441 DEFUN (ospf_area_stub_no_summary
,
1442 ospf_area_stub_no_summary_cmd
,
1443 "area <A.B.C.D|(0-4294967295)> stub no-summary",
1444 "OSPF stub parameters\n"
1445 "OSPF area ID in IP address format\n"
1446 "OSPF area ID as a decimal value\n"
1447 "Configure OSPF area as stub\n"
1448 "Do not inject inter-area routes into stub\n")
1450 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1451 int idx_ipv4_number
= 1;
1452 struct in_addr area_id
;
1455 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1456 argv
[idx_ipv4_number
]->arg
);
1458 ret
= ospf_area_stub_set(ospf
, area_id
);
1459 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1463 "%% Area cannot be stub as it contains a virtual link\n");
1464 return CMD_WARNING_CONFIG_FAILED
;
1467 ospf_area_no_summary_set(ospf
, area_id
);
1472 DEFUN (no_ospf_area_stub
,
1473 no_ospf_area_stub_cmd
,
1474 "no area <A.B.C.D|(0-4294967295)> stub",
1476 "OSPF area parameters\n"
1477 "OSPF area ID in IP address format\n"
1478 "OSPF area ID as a decimal value\n"
1479 "Configure OSPF area as stub\n")
1481 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1482 int idx_ipv4_number
= 2;
1483 struct in_addr area_id
;
1486 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1487 argv
[idx_ipv4_number
]->arg
);
1489 ospf_area_stub_unset(ospf
, area_id
);
1490 ospf_area_no_summary_unset(ospf
, area_id
);
1495 DEFUN (no_ospf_area_stub_no_summary
,
1496 no_ospf_area_stub_no_summary_cmd
,
1497 "no area <A.B.C.D|(0-4294967295)> stub no-summary",
1499 "OSPF area parameters\n"
1500 "OSPF area ID in IP address format\n"
1501 "OSPF area ID as a decimal value\n"
1502 "Configure OSPF area as stub\n"
1503 "Do not inject inter-area routes into area\n")
1505 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1506 int idx_ipv4_number
= 2;
1507 struct in_addr area_id
;
1510 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1511 argv
[idx_ipv4_number
]->arg
);
1512 ospf_area_no_summary_unset(ospf
, area_id
);
1517 static int ospf_area_nssa_cmd_handler(struct vty
*vty
, int argc
,
1518 struct cmd_token
**argv
, int cfg_nosum
,
1521 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1522 struct in_addr area_id
;
1525 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
, argv
[1]->arg
);
1527 ret
= ospf_area_nssa_set(ospf
, area_id
);
1528 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1532 "%% Area cannot be nssa as it contains a virtual link\n");
1533 return CMD_WARNING_CONFIG_FAILED
;
1537 if (strncmp(argv
[3]->text
, "translate-c", 11) == 0)
1538 ospf_area_nssa_translator_role_set(
1539 ospf
, area_id
, OSPF_NSSA_ROLE_CANDIDATE
);
1540 else if (strncmp(argv
[3]->text
, "translate-n", 11) == 0)
1541 ospf_area_nssa_translator_role_set(
1542 ospf
, area_id
, OSPF_NSSA_ROLE_NEVER
);
1543 else if (strncmp(argv
[3]->text
, "translate-a", 11) == 0)
1544 ospf_area_nssa_translator_role_set(
1545 ospf
, area_id
, OSPF_NSSA_ROLE_ALWAYS
);
1547 ospf_area_nssa_translator_role_set(ospf
, area_id
,
1548 OSPF_NSSA_ROLE_CANDIDATE
);
1553 ospf_area_no_summary_set(ospf
, area_id
);
1555 ospf_area_no_summary_unset(ospf
, area_id
);
1558 ospf_schedule_abr_task(ospf
);
1564 DEFUN (ospf_area_nssa_translate
,
1565 ospf_area_nssa_translate_cmd
,
1566 "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always>",
1567 "OSPF area parameters\n"
1568 "OSPF area ID in IP address format\n"
1569 "OSPF area ID as a decimal value\n"
1570 "Configure OSPF area as nssa\n"
1571 "Configure NSSA-ABR for translate election (default)\n"
1572 "Configure NSSA-ABR to never translate\n"
1573 "Configure NSSA-ABR to always translate\n")
1575 return ospf_area_nssa_cmd_handler(vty
, argc
, argv
, 0, 0);
1578 DEFUN (ospf_area_nssa
,
1580 "area <A.B.C.D|(0-4294967295)> nssa",
1581 "OSPF area parameters\n"
1582 "OSPF area ID in IP address format\n"
1583 "OSPF area ID as a decimal value\n"
1584 "Configure OSPF area as nssa\n")
1586 return ospf_area_nssa_cmd_handler(vty
, argc
, argv
, 0, 0);
1589 DEFUN (ospf_area_nssa_no_summary
,
1590 ospf_area_nssa_no_summary_cmd
,
1591 "area <A.B.C.D|(0-4294967295)> nssa no-summary",
1592 "OSPF area parameters\n"
1593 "OSPF area ID in IP address format\n"
1594 "OSPF area ID as a decimal value\n"
1595 "Configure OSPF area as nssa\n"
1596 "Do not inject inter-area routes into nssa\n")
1598 int idx_ipv4_number
= 1;
1599 struct in_addr area_id
;
1602 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1603 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1604 argv
[idx_ipv4_number
]->arg
);
1606 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1608 ospf_area_nssa_no_summary_set(ospf
, area_id
);
1610 ospf_schedule_abr_task(ospf
);
1615 DEFUN (no_ospf_area_nssa_no_summary
,
1616 no_ospf_area_nssa_no_summary_cmd
,
1617 "no area <A.B.C.D|(0-4294967295)> nssa no-summary",
1619 "OSPF area parameters\n"
1620 "OSPF area ID in IP address format\n"
1621 "OSPF area ID as a decimal value\n"
1622 "Configure OSPF area as nssa\n"
1623 "Do not inject inter-area routes into nssa\n")
1625 int idx_ipv4_number
= 2;
1626 struct in_addr area_id
;
1629 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1631 VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id
, format
,
1632 argv
[idx_ipv4_number
]->arg
);
1634 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1636 ospf_area_no_summary_unset(ospf
, area_id
);
1638 ospf_schedule_abr_task(ospf
);
1643 DEFUN (no_ospf_area_nssa
,
1644 no_ospf_area_nssa_cmd
,
1645 "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always>]",
1647 "OSPF area parameters\n"
1648 "OSPF area ID in IP address format\n"
1649 "OSPF area ID as a decimal value\n"
1650 "Configure OSPF area as nssa\n"
1651 "Configure NSSA-ABR for translate election (default)\n"
1652 "Configure NSSA-ABR to never translate\n"
1653 "Configure NSSA-ABR to always translate\n")
1655 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1656 int idx_ipv4_number
= 2;
1657 struct in_addr area_id
;
1660 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1661 argv
[idx_ipv4_number
]->arg
);
1663 ospf_area_nssa_unset(ospf
, area_id
, argc
);
1665 ospf_schedule_abr_task(ospf
);
1671 DEFUN (ospf_area_default_cost
,
1672 ospf_area_default_cost_cmd
,
1673 "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1674 "OSPF area parameters\n"
1675 "OSPF area ID in IP address format\n"
1676 "OSPF area ID as a decimal value\n"
1677 "Set the summary-default cost of a NSSA or stub area\n"
1678 "Stub's advertised default summary cost\n")
1680 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1681 int idx_ipv4_number
= 1;
1683 struct ospf_area
*area
;
1684 struct in_addr area_id
;
1687 struct prefix_ipv4 p
;
1689 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1690 argv
[idx_ipv4_number
]->arg
);
1691 cost
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1693 area
= ospf_area_get(ospf
, area_id
);
1694 ospf_area_display_format_set(ospf
, area
, format
);
1696 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1697 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1698 return CMD_WARNING_CONFIG_FAILED
;
1701 area
->default_cost
= cost
;
1704 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1706 if (IS_DEBUG_OSPF_EVENT
)
1708 "ospf_abr_announce_stub_defaults(): "
1709 "announcing 0.0.0.0/0 to area %s",
1710 inet_ntoa(area
->area_id
));
1711 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1716 DEFUN (no_ospf_area_default_cost
,
1717 no_ospf_area_default_cost_cmd
,
1718 "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1720 "OSPF area parameters\n"
1721 "OSPF area ID in IP address format\n"
1722 "OSPF area ID as a decimal value\n"
1723 "Set the summary-default cost of a NSSA or stub area\n"
1724 "Stub's advertised default summary cost\n")
1726 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1727 int idx_ipv4_number
= 2;
1728 struct ospf_area
*area
;
1729 struct in_addr area_id
;
1731 struct prefix_ipv4 p
;
1733 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1734 argv
[idx_ipv4_number
]->arg
);
1736 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1740 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1741 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1742 return CMD_WARNING_CONFIG_FAILED
;
1745 area
->default_cost
= 1;
1748 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1750 if (IS_DEBUG_OSPF_EVENT
)
1752 "ospf_abr_announce_stub_defaults(): "
1753 "announcing 0.0.0.0/0 to area %s",
1754 inet_ntoa(area
->area_id
));
1755 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1758 ospf_area_check_free(ospf
, area_id
);
1763 DEFUN (ospf_area_export_list
,
1764 ospf_area_export_list_cmd
,
1765 "area <A.B.C.D|(0-4294967295)> export-list NAME",
1766 "OSPF area parameters\n"
1767 "OSPF area ID in IP address format\n"
1768 "OSPF area ID as a decimal value\n"
1769 "Set the filter for networks announced to other areas\n"
1770 "Name of the access-list\n")
1772 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1773 int idx_ipv4_number
= 1;
1774 struct ospf_area
*area
;
1775 struct in_addr area_id
;
1778 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1780 area
= ospf_area_get(ospf
, area_id
);
1781 ospf_area_display_format_set(ospf
, area
, format
);
1782 ospf_area_export_list_set(ospf
, area
, argv
[3]->arg
);
1787 DEFUN (no_ospf_area_export_list
,
1788 no_ospf_area_export_list_cmd
,
1789 "no area <A.B.C.D|(0-4294967295)> export-list NAME",
1791 "OSPF area parameters\n"
1792 "OSPF area ID in IP address format\n"
1793 "OSPF area ID as a decimal value\n"
1794 "Unset the filter for networks announced to other areas\n"
1795 "Name of the access-list\n")
1797 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1798 int idx_ipv4_number
= 2;
1799 struct ospf_area
*area
;
1800 struct in_addr area_id
;
1803 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1805 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1809 ospf_area_export_list_unset(ospf
, area
);
1815 DEFUN (ospf_area_import_list
,
1816 ospf_area_import_list_cmd
,
1817 "area <A.B.C.D|(0-4294967295)> import-list NAME",
1818 "OSPF area parameters\n"
1819 "OSPF area ID in IP address format\n"
1820 "OSPF area ID as a decimal value\n"
1821 "Set the filter for networks from other areas announced to the specified one\n"
1822 "Name of the access-list\n")
1824 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1825 int idx_ipv4_number
= 1;
1826 struct ospf_area
*area
;
1827 struct in_addr area_id
;
1830 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1832 area
= ospf_area_get(ospf
, area_id
);
1833 ospf_area_display_format_set(ospf
, area
, format
);
1834 ospf_area_import_list_set(ospf
, area
, argv
[3]->arg
);
1839 DEFUN (no_ospf_area_import_list
,
1840 no_ospf_area_import_list_cmd
,
1841 "no area <A.B.C.D|(0-4294967295)> import-list NAME",
1843 "OSPF area parameters\n"
1844 "OSPF area ID in IP address format\n"
1845 "OSPF area ID as a decimal value\n"
1846 "Unset the filter for networks announced to other areas\n"
1847 "Name of the access-list\n")
1849 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1850 int idx_ipv4_number
= 2;
1851 struct ospf_area
*area
;
1852 struct in_addr area_id
;
1855 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1857 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1861 ospf_area_import_list_unset(ospf
, area
);
1866 DEFUN (ospf_area_filter_list
,
1867 ospf_area_filter_list_cmd
,
1868 "area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>",
1869 "OSPF area parameters\n"
1870 "OSPF area ID in IP address format\n"
1871 "OSPF area ID as a decimal value\n"
1872 "Filter networks between OSPF areas\n"
1873 "Filter prefixes between OSPF areas\n"
1874 "Name of an IP prefix-list\n"
1875 "Filter networks sent to this area\n"
1876 "Filter networks sent from this area\n")
1878 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1879 int idx_ipv4_number
= 1;
1882 struct ospf_area
*area
;
1883 struct in_addr area_id
;
1884 struct prefix_list
*plist
;
1887 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1889 area
= ospf_area_get(ospf
, area_id
);
1890 ospf_area_display_format_set(ospf
, area
, format
);
1891 plist
= prefix_list_lookup(AFI_IP
, argv
[idx_word
]->arg
);
1892 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1893 PREFIX_LIST_IN(area
) = plist
;
1894 if (PREFIX_NAME_IN(area
))
1895 free(PREFIX_NAME_IN(area
));
1897 PREFIX_NAME_IN(area
) = strdup(argv
[idx_word
]->arg
);
1898 ospf_schedule_abr_task(ospf
);
1900 PREFIX_LIST_OUT(area
) = plist
;
1901 if (PREFIX_NAME_OUT(area
))
1902 free(PREFIX_NAME_OUT(area
));
1904 PREFIX_NAME_OUT(area
) = strdup(argv
[idx_word
]->arg
);
1905 ospf_schedule_abr_task(ospf
);
1911 DEFUN (no_ospf_area_filter_list
,
1912 no_ospf_area_filter_list_cmd
,
1913 "no area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>",
1915 "OSPF area parameters\n"
1916 "OSPF area ID in IP address format\n"
1917 "OSPF area ID as a decimal value\n"
1918 "Filter networks between OSPF areas\n"
1919 "Filter prefixes between OSPF areas\n"
1920 "Name of an IP prefix-list\n"
1921 "Filter networks sent to this area\n"
1922 "Filter networks sent from this area\n")
1924 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1925 int idx_ipv4_number
= 2;
1928 struct ospf_area
*area
;
1929 struct in_addr area_id
;
1932 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1934 if ((area
= ospf_area_lookup_by_area_id(ospf
, area_id
)) == NULL
)
1937 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1938 if (PREFIX_NAME_IN(area
))
1939 if (strcmp(PREFIX_NAME_IN(area
), argv
[idx_word
]->arg
)
1943 PREFIX_LIST_IN(area
) = NULL
;
1944 if (PREFIX_NAME_IN(area
))
1945 free(PREFIX_NAME_IN(area
));
1947 PREFIX_NAME_IN(area
) = NULL
;
1949 ospf_schedule_abr_task(ospf
);
1951 if (PREFIX_NAME_OUT(area
))
1952 if (strcmp(PREFIX_NAME_OUT(area
), argv
[idx_word
]->arg
)
1956 PREFIX_LIST_OUT(area
) = NULL
;
1957 if (PREFIX_NAME_OUT(area
))
1958 free(PREFIX_NAME_OUT(area
));
1960 PREFIX_NAME_OUT(area
) = NULL
;
1962 ospf_schedule_abr_task(ospf
);
1969 DEFUN (ospf_area_authentication_message_digest
,
1970 ospf_area_authentication_message_digest_cmd
,
1971 "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest",
1973 "OSPF area parameters\n"
1974 "OSPF area ID in IP address format\n"
1975 "OSPF area ID as a decimal value\n"
1976 "Enable authentication\n"
1977 "Use message-digest authentication\n")
1979 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1981 struct ospf_area
*area
;
1982 struct in_addr area_id
;
1985 argv_find(argv
, argc
, "area", &idx
);
1986 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx
+ 1]->arg
);
1988 area
= ospf_area_get(ospf
, area_id
);
1989 ospf_area_display_format_set(ospf
, area
, format
);
1990 area
->auth_type
= strmatch(argv
[0]->text
, "no")
1992 : OSPF_AUTH_CRYPTOGRAPHIC
;
1997 DEFUN (ospf_area_authentication
,
1998 ospf_area_authentication_cmd
,
1999 "area <A.B.C.D|(0-4294967295)> authentication",
2000 "OSPF area parameters\n"
2001 "OSPF area ID in IP address format\n"
2002 "OSPF area ID as a decimal value\n"
2003 "Enable authentication\n")
2005 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2006 int idx_ipv4_number
= 1;
2007 struct ospf_area
*area
;
2008 struct in_addr area_id
;
2011 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
2013 area
= ospf_area_get(ospf
, area_id
);
2014 ospf_area_display_format_set(ospf
, area
, format
);
2015 area
->auth_type
= OSPF_AUTH_SIMPLE
;
2020 DEFUN (no_ospf_area_authentication
,
2021 no_ospf_area_authentication_cmd
,
2022 "no area <A.B.C.D|(0-4294967295)> authentication",
2024 "OSPF area parameters\n"
2025 "OSPF area ID in IP address format\n"
2026 "OSPF area ID as a decimal value\n"
2027 "Enable authentication\n")
2029 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2030 int idx_ipv4_number
= 2;
2031 struct ospf_area
*area
;
2032 struct in_addr area_id
;
2035 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
2037 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
2041 area
->auth_type
= OSPF_AUTH_NULL
;
2043 ospf_area_check_free(ospf
, area_id
);
2049 DEFUN (ospf_abr_type
,
2051 "ospf abr-type <cisco|ibm|shortcut|standard>",
2052 "OSPF specific commands\n"
2053 "Set OSPF ABR type\n"
2054 "Alternative ABR, cisco implementation\n"
2055 "Alternative ABR, IBM implementation\n"
2057 "Standard behavior (RFC2328)\n")
2059 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2061 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2063 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2064 abr_type
= OSPF_ABR_CISCO
;
2065 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2066 abr_type
= OSPF_ABR_IBM
;
2067 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2068 abr_type
= OSPF_ABR_SHORTCUT
;
2069 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2070 abr_type
= OSPF_ABR_STAND
;
2072 return CMD_WARNING_CONFIG_FAILED
;
2074 /* If ABR type value is changed, schedule ABR task. */
2075 if (ospf
->abr_type
!= abr_type
) {
2076 ospf
->abr_type
= abr_type
;
2077 ospf_schedule_abr_task(ospf
);
2083 DEFUN (no_ospf_abr_type
,
2084 no_ospf_abr_type_cmd
,
2085 "no ospf abr-type <cisco|ibm|shortcut|standard>",
2087 "OSPF specific commands\n"
2088 "Set OSPF ABR type\n"
2089 "Alternative ABR, cisco implementation\n"
2090 "Alternative ABR, IBM implementation\n"
2094 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2096 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2098 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2099 abr_type
= OSPF_ABR_CISCO
;
2100 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2101 abr_type
= OSPF_ABR_IBM
;
2102 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2103 abr_type
= OSPF_ABR_SHORTCUT
;
2104 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2105 abr_type
= OSPF_ABR_STAND
;
2107 return CMD_WARNING_CONFIG_FAILED
;
2109 /* If ABR type value is changed, schedule ABR task. */
2110 if (ospf
->abr_type
== abr_type
) {
2111 ospf
->abr_type
= OSPF_ABR_DEFAULT
;
2112 ospf_schedule_abr_task(ospf
);
2118 DEFUN (ospf_log_adjacency_changes
,
2119 ospf_log_adjacency_changes_cmd
,
2120 "log-adjacency-changes",
2121 "Log changes in adjacency state\n")
2123 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2125 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2126 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2130 DEFUN (ospf_log_adjacency_changes_detail
,
2131 ospf_log_adjacency_changes_detail_cmd
,
2132 "log-adjacency-changes detail",
2133 "Log changes in adjacency state\n"
2134 "Log all state changes\n")
2136 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2138 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2139 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2143 DEFUN (no_ospf_log_adjacency_changes
,
2144 no_ospf_log_adjacency_changes_cmd
,
2145 "no log-adjacency-changes",
2147 "Log changes in adjacency state\n")
2149 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2151 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2152 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2156 DEFUN (no_ospf_log_adjacency_changes_detail
,
2157 no_ospf_log_adjacency_changes_detail_cmd
,
2158 "no log-adjacency-changes detail",
2160 "Log changes in adjacency state\n"
2161 "Log all state changes\n")
2163 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2165 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2169 DEFUN (ospf_compatible_rfc1583
,
2170 ospf_compatible_rfc1583_cmd
,
2171 "compatible rfc1583",
2172 "OSPF compatibility list\n"
2173 "compatible with RFC 1583\n")
2175 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2177 if (!CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2178 SET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2179 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2184 DEFUN (no_ospf_compatible_rfc1583
,
2185 no_ospf_compatible_rfc1583_cmd
,
2186 "no compatible rfc1583",
2188 "OSPF compatibility list\n"
2189 "compatible with RFC 1583\n")
2191 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2193 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2194 UNSET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2195 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2200 ALIAS(ospf_compatible_rfc1583
, ospf_rfc1583_flag_cmd
,
2201 "ospf rfc1583compatibility",
2202 "OSPF specific commands\n"
2203 "Enable the RFC1583Compatibility flag\n")
2205 ALIAS(no_ospf_compatible_rfc1583
, no_ospf_rfc1583_flag_cmd
,
2206 "no ospf rfc1583compatibility", NO_STR
2207 "OSPF specific commands\n"
2208 "Disable the RFC1583Compatibility flag\n")
2210 static int ospf_timers_spf_set(struct vty
*vty
, unsigned int delay
,
2211 unsigned int hold
, unsigned int max
)
2213 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2215 ospf
->spf_delay
= delay
;
2216 ospf
->spf_holdtime
= hold
;
2217 ospf
->spf_max_holdtime
= max
;
2222 DEFUN (ospf_timers_min_ls_interval
,
2223 ospf_timers_min_ls_interval_cmd
,
2224 "timers throttle lsa all (0-5000)",
2225 "Adjust routing timers\n"
2226 "Throttling adaptive timer\n"
2227 "LSA delay between transmissions\n"
2229 "Delay (msec) between sending LSAs\n")
2231 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2233 unsigned int interval
;
2236 vty_out(vty
, "Insufficient arguments\n");
2237 return CMD_WARNING_CONFIG_FAILED
;
2240 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2242 ospf
->min_ls_interval
= interval
;
2247 DEFUN (no_ospf_timers_min_ls_interval
,
2248 no_ospf_timers_min_ls_interval_cmd
,
2249 "no timers throttle lsa all [(0-5000)]",
2251 "Adjust routing timers\n"
2252 "Throttling adaptive timer\n"
2253 "LSA delay between transmissions\n"
2255 "Delay (msec) between sending LSAs\n")
2257 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2258 ospf
->min_ls_interval
= OSPF_MIN_LS_INTERVAL
;
2263 DEFUN (ospf_timers_throttle_spf
,
2264 ospf_timers_throttle_spf_cmd
,
2265 "timers throttle spf (0-600000) (0-600000) (0-600000)",
2266 "Adjust routing timers\n"
2267 "Throttling adaptive timer\n"
2269 "Delay (msec) from first change received till SPF calculation\n"
2270 "Initial hold time (msec) between consecutive SPF calculations\n"
2271 "Maximum hold time (msec)\n")
2274 int idx_number_2
= 4;
2275 int idx_number_3
= 5;
2276 unsigned int delay
, hold
, max
;
2279 vty_out(vty
, "Insufficient arguments\n");
2280 return CMD_WARNING_CONFIG_FAILED
;
2283 delay
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2284 hold
= strtoul(argv
[idx_number_2
]->arg
, NULL
, 10);
2285 max
= strtoul(argv
[idx_number_3
]->arg
, NULL
, 10);
2287 return ospf_timers_spf_set(vty
, delay
, hold
, max
);
2290 DEFUN (no_ospf_timers_throttle_spf
,
2291 no_ospf_timers_throttle_spf_cmd
,
2292 "no timers throttle spf [(0-600000)(0-600000)(0-600000)]",
2294 "Adjust routing timers\n"
2295 "Throttling adaptive timer\n"
2297 "Delay (msec) from first change received till SPF calculation\n"
2298 "Initial hold time (msec) between consecutive SPF calculations\n"
2299 "Maximum hold time (msec)\n")
2301 return ospf_timers_spf_set(vty
, OSPF_SPF_DELAY_DEFAULT
,
2302 OSPF_SPF_HOLDTIME_DEFAULT
,
2303 OSPF_SPF_MAX_HOLDTIME_DEFAULT
);
2307 DEFUN (ospf_timers_lsa_min_arrival
,
2308 ospf_timers_lsa_min_arrival_cmd
,
2309 "timers lsa min-arrival (0-600000)",
2310 "Adjust routing timers\n"
2312 "Minimum delay in receiving new version of a LSA\n"
2313 "Delay in milliseconds\n")
2315 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2316 ospf
->min_ls_arrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2320 DEFUN (no_ospf_timers_lsa_min_arrival
,
2321 no_ospf_timers_lsa_min_arrival_cmd
,
2322 "no timers lsa min-arrival [(0-600000)]",
2324 "Adjust routing timers\n"
2326 "Minimum delay in receiving new version of a LSA\n"
2327 "Delay in milliseconds\n")
2329 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2330 unsigned int minarrival
;
2333 minarrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2335 if (ospf
->min_ls_arrival
!= minarrival
2336 || minarrival
== OSPF_MIN_LS_ARRIVAL
)
2340 ospf
->min_ls_arrival
= OSPF_MIN_LS_ARRIVAL
;
2345 DEFUN (ospf_neighbor
,
2347 "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]",
2349 "Neighbor IP address\n"
2350 "Neighbor Priority\n"
2352 "Dead Neighbor Polling interval\n"
2355 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2359 struct in_addr nbr_addr
;
2360 unsigned int priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2361 unsigned int interval
= OSPF_POLL_INTERVAL_DEFAULT
;
2363 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2364 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2365 return CMD_WARNING_CONFIG_FAILED
;
2369 priority
= strtoul(argv
[idx_pri
]->arg
, NULL
, 10);
2372 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2374 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2377 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2380 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2385 DEFUN (ospf_neighbor_poll_interval
,
2386 ospf_neighbor_poll_interval_cmd
,
2387 "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2389 "Neighbor IP address\n"
2390 "Dead Neighbor Polling interval\n"
2392 "OSPF priority of non-broadcast neighbor\n"
2395 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2399 struct in_addr nbr_addr
;
2400 unsigned int priority
;
2401 unsigned int interval
;
2403 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2404 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2405 return CMD_WARNING_CONFIG_FAILED
;
2408 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2410 priority
= argc
> 4 ? strtoul(argv
[idx_pri
]->arg
, NULL
, 10)
2411 : OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2413 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2414 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2417 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2422 DEFUN (no_ospf_neighbor
,
2423 no_ospf_neighbor_cmd
,
2424 "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]",
2427 "Neighbor IP address\n"
2428 "Neighbor Priority\n"
2430 "Dead Neighbor Polling interval\n"
2433 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2435 struct in_addr nbr_addr
;
2437 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2438 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2439 return CMD_WARNING_CONFIG_FAILED
;
2442 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2447 DEFUN (no_ospf_neighbor_poll
,
2448 no_ospf_neighbor_poll_cmd
,
2449 "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2452 "Neighbor IP address\n"
2453 "Dead Neighbor Polling interval\n"
2455 "Neighbor Priority\n"
2458 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2460 struct in_addr nbr_addr
;
2462 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2463 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2464 return CMD_WARNING_CONFIG_FAILED
;
2467 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2472 DEFUN (ospf_refresh_timer
,
2473 ospf_refresh_timer_cmd
,
2474 "refresh timer (10-1800)",
2475 "Adjust refresh parameters\n"
2476 "Set refresh timer\n"
2477 "Timer value in seconds\n")
2479 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2481 unsigned int interval
;
2483 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2484 interval
= (interval
/ OSPF_LSA_REFRESHER_GRANULARITY
)
2485 * OSPF_LSA_REFRESHER_GRANULARITY
;
2487 ospf_timers_refresh_set(ospf
, interval
);
2492 DEFUN (no_ospf_refresh_timer
,
2493 no_ospf_refresh_timer_val_cmd
,
2494 "no refresh timer [(10-1800)]",
2496 "Adjust refresh parameters\n"
2497 "Unset refresh timer\n"
2498 "Timer value in seconds\n")
2500 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2502 unsigned int interval
;
2505 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2507 if (ospf
->lsa_refresh_interval
!= interval
2508 || interval
== OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
2512 ospf_timers_refresh_unset(ospf
);
2518 DEFUN (ospf_auto_cost_reference_bandwidth
,
2519 ospf_auto_cost_reference_bandwidth_cmd
,
2520 "auto-cost reference-bandwidth (1-4294967)",
2521 "Calculate OSPF interface cost according to bandwidth\n"
2522 "Use reference bandwidth method to assign OSPF cost\n"
2523 "The reference bandwidth in terms of Mbits per second\n")
2525 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2526 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2529 struct interface
*ifp
;
2531 refbw
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2532 if (refbw
< 1 || refbw
> 4294967) {
2533 vty_out(vty
, "reference-bandwidth value is invalid\n");
2534 return CMD_WARNING_CONFIG_FAILED
;
2537 /* If reference bandwidth is changed. */
2538 if ((refbw
) == ospf
->ref_bandwidth
)
2541 ospf
->ref_bandwidth
= refbw
;
2542 FOR_ALL_INTERFACES (vrf
, ifp
)
2543 ospf_if_recalculate_output_cost(ifp
);
2548 DEFUN (no_ospf_auto_cost_reference_bandwidth
,
2549 no_ospf_auto_cost_reference_bandwidth_cmd
,
2550 "no auto-cost reference-bandwidth [(1-4294967)]",
2552 "Calculate OSPF interface cost according to bandwidth\n"
2553 "Use reference bandwidth method to assign OSPF cost\n"
2554 "The reference bandwidth in terms of Mbits per second\n")
2556 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2557 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2558 struct interface
*ifp
;
2560 if (ospf
->ref_bandwidth
== OSPF_DEFAULT_REF_BANDWIDTH
)
2563 ospf
->ref_bandwidth
= OSPF_DEFAULT_REF_BANDWIDTH
;
2564 vty_out(vty
, "%% OSPF: Reference bandwidth is changed.\n");
2566 " Please ensure reference bandwidth is consistent across all routers\n");
2568 FOR_ALL_INTERFACES (vrf
, ifp
)
2569 ospf_if_recalculate_output_cost(ifp
);
2574 DEFUN (ospf_write_multiplier
,
2575 ospf_write_multiplier_cmd
,
2576 "ospf write-multiplier (1-100)",
2577 "OSPF specific commands\n"
2578 "Write multiplier\n"
2579 "Maximum number of interface serviced per write\n")
2581 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2583 uint32_t write_oi_count
;
2590 write_oi_count
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2591 if (write_oi_count
< 1 || write_oi_count
> 100) {
2592 vty_out(vty
, "write-multiplier value is invalid\n");
2593 return CMD_WARNING_CONFIG_FAILED
;
2596 ospf
->write_oi_count
= write_oi_count
;
2600 ALIAS(ospf_write_multiplier
, write_multiplier_cmd
, "write-multiplier (1-100)",
2601 "Write multiplier\n"
2602 "Maximum number of interface serviced per write\n")
2604 DEFUN (no_ospf_write_multiplier
,
2605 no_ospf_write_multiplier_cmd
,
2606 "no ospf write-multiplier (1-100)",
2608 "OSPF specific commands\n"
2609 "Write multiplier\n"
2610 "Maximum number of interface serviced per write\n")
2612 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2614 ospf
->write_oi_count
= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
;
2618 ALIAS(no_ospf_write_multiplier
, no_write_multiplier_cmd
,
2619 "no write-multiplier (1-100)", NO_STR
2620 "Write multiplier\n"
2621 "Maximum number of interface serviced per write\n")
2623 const char *ospf_abr_type_descr_str
[] = {"Unknown", "Standard (RFC2328)",
2624 "Alternative IBM", "Alternative Cisco",
2625 "Alternative Shortcut"};
2627 const char *ospf_shortcut_mode_descr_str
[] = {"Default", "Enabled", "Disabled"};
2629 static void show_ip_ospf_area(struct vty
*vty
, struct ospf_area
*area
,
2630 json_object
*json_areas
, bool use_json
)
2632 json_object
*json_area
= NULL
;
2635 json_area
= json_object_new_object();
2639 vty_out(vty
, " Area ID: %s", inet_ntoa(area
->area_id
));
2641 /* Show Area type/mode. */
2642 if (OSPF_IS_AREA_BACKBONE(area
)) {
2644 json_object_boolean_true_add(json_area
, "backbone");
2646 vty_out(vty
, " (Backbone)\n");
2649 if (area
->external_routing
== OSPF_AREA_STUB
) {
2650 if (area
->no_summary
)
2651 json_object_boolean_true_add(
2652 json_area
, "stubNoSummary");
2653 if (area
->shortcut_configured
)
2654 json_object_boolean_true_add(
2655 json_area
, "stubShortcut");
2656 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
2657 if (area
->no_summary
)
2658 json_object_boolean_true_add(
2659 json_area
, "nssaNoSummary");
2660 if (area
->shortcut_configured
)
2661 json_object_boolean_true_add(
2662 json_area
, "nssaShortcut");
2665 json_object_string_add(
2666 json_area
, "shortcuttingMode",
2667 ospf_shortcut_mode_descr_str
2668 [area
->shortcut_configured
]);
2669 if (area
->shortcut_capability
)
2670 json_object_boolean_true_add(json_area
,
2673 if (area
->external_routing
== OSPF_AREA_STUB
)
2674 vty_out(vty
, " (Stub%s%s)",
2675 area
->no_summary
? ", no summary" : "",
2676 area
->shortcut_configured
? "; " : "");
2677 else if (area
->external_routing
== OSPF_AREA_NSSA
)
2678 vty_out(vty
, " (NSSA%s%s)",
2679 area
->no_summary
? ", no summary" : "",
2680 area
->shortcut_configured
? "; " : "");
2683 vty_out(vty
, " Shortcutting mode: %s",
2684 ospf_shortcut_mode_descr_str
2685 [area
->shortcut_configured
]);
2686 vty_out(vty
, ", S-bit consensus: %s\n",
2687 area
->shortcut_capability
? "ok" : "no");
2691 /* Show number of interfaces */
2693 json_object_int_add(json_area
, "areaIfTotalCounter",
2694 listcount(area
->oiflist
));
2695 json_object_int_add(json_area
, "areaIfActiveCounter",
2699 " Number of interfaces in this area: Total: %d, "
2701 listcount(area
->oiflist
), area
->act_ints
);
2703 if (area
->external_routing
== OSPF_AREA_NSSA
) {
2705 json_object_boolean_true_add(json_area
, "nssa");
2706 if (!IS_OSPF_ABR(area
->ospf
))
2707 json_object_boolean_false_add(json_area
, "abr");
2708 else if (area
->NSSATranslatorState
) {
2709 json_object_boolean_true_add(json_area
, "abr");
2710 if (area
->NSSATranslatorRole
2711 == OSPF_NSSA_ROLE_CANDIDATE
)
2712 json_object_boolean_true_add(
2714 "nssaTranslatorElected");
2715 else if (area
->NSSATranslatorRole
2716 == OSPF_NSSA_ROLE_ALWAYS
)
2717 json_object_boolean_true_add(
2719 "nssaTranslatorAlways");
2721 json_object_boolean_true_add(json_area
, "abr");
2722 if (area
->NSSATranslatorRole
2723 == OSPF_NSSA_ROLE_CANDIDATE
)
2724 json_object_boolean_false_add(
2726 "nssaTranslatorElected");
2728 json_object_boolean_true_add(
2730 "nssaTranslatorNever");
2734 " It is an NSSA configuration. \n Elected NSSA/ABR performs type-7/type-5 LSA translation. \n");
2735 if (!IS_OSPF_ABR(area
->ospf
))
2737 " It is not ABR, therefore not Translator. \n");
2738 else if (area
->NSSATranslatorState
) {
2739 vty_out(vty
, " We are an ABR and ");
2740 if (area
->NSSATranslatorRole
2741 == OSPF_NSSA_ROLE_CANDIDATE
)
2743 "the NSSA Elected Translator. \n");
2744 else if (area
->NSSATranslatorRole
2745 == OSPF_NSSA_ROLE_ALWAYS
)
2747 "always an NSSA Translator. \n");
2749 vty_out(vty
, " We are an ABR, but ");
2750 if (area
->NSSATranslatorRole
2751 == OSPF_NSSA_ROLE_CANDIDATE
)
2753 "not the NSSA Elected Translator. \n");
2756 "never an NSSA Translator. \n");
2761 /* Stub-router state for this area */
2762 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
)) {
2763 char timebuf
[OSPF_TIME_DUMP_SIZE
];
2766 json_object_boolean_true_add(
2767 json_area
, "originStubMaxDistRouterLsa");
2768 if (CHECK_FLAG(area
->stub_router_state
,
2769 OSPF_AREA_ADMIN_STUB_ROUTED
))
2770 json_object_boolean_true_add(
2771 json_area
, "indefiniteActiveAdmin");
2772 if (area
->t_stub_router
) {
2776 &area
->t_stub_router
->u
.sands
,
2779 json_object_int_add(
2781 "activeStartupRemainderMsecs",
2786 " Originating stub / maximum-distance Router-LSA\n");
2787 if (CHECK_FLAG(area
->stub_router_state
,
2788 OSPF_AREA_ADMIN_STUB_ROUTED
))
2790 " Administratively activated (indefinitely)\n");
2791 if (area
->t_stub_router
)
2793 " Active from startup, %s remaining\n",
2794 ospf_timer_dump(area
->t_stub_router
,
2801 /* Show number of fully adjacent neighbors. */
2802 json_object_int_add(json_area
, "nbrFullAdjacentCounter",
2805 /* Show authentication type. */
2806 if (area
->auth_type
== OSPF_AUTH_NULL
)
2807 json_object_string_add(json_area
, "authentication",
2808 "authenticationNone");
2809 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2810 json_object_string_add(json_area
, "authentication",
2811 "authenticationSimplePassword");
2812 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2813 json_object_string_add(json_area
, "authentication",
2814 "authenticationMessageDigest");
2816 if (!OSPF_IS_AREA_BACKBONE(area
))
2817 json_object_int_add(json_area
,
2818 "virtualAdjacenciesPassingCounter",
2821 /* Show SPF calculation times. */
2822 json_object_int_add(json_area
, "spfExecutedCounter",
2823 area
->spf_calculation
);
2824 json_object_int_add(json_area
, "lsaNumber", area
->lsdb
->total
);
2825 json_object_int_add(
2826 json_area
, "lsaRouterNumber",
2827 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
));
2828 json_object_int_add(
2829 json_area
, "lsaRouterChecksum",
2830 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
2831 json_object_int_add(
2832 json_area
, "lsaNetworkNumber",
2833 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
));
2834 json_object_int_add(
2835 json_area
, "lsaNetworkChecksum",
2836 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
2837 json_object_int_add(
2838 json_area
, "lsaSummaryNumber",
2839 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
));
2840 json_object_int_add(
2841 json_area
, "lsaSummaryChecksum",
2842 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
2843 json_object_int_add(
2844 json_area
, "lsaAsbrNumber",
2845 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2846 json_object_int_add(
2847 json_area
, "lsaAsbrChecksum",
2848 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2849 json_object_int_add(
2850 json_area
, "lsaNssaNumber",
2851 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2852 json_object_int_add(
2853 json_area
, "lsaNssaChecksum",
2854 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2856 /* Show number of fully adjacent neighbors. */
2858 " Number of fully adjacent neighbors in this area:"
2862 /* Show authentication type. */
2863 vty_out(vty
, " Area has ");
2864 if (area
->auth_type
== OSPF_AUTH_NULL
)
2865 vty_out(vty
, "no authentication\n");
2866 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2867 vty_out(vty
, "simple password authentication\n");
2868 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2869 vty_out(vty
, "message digest authentication\n");
2871 if (!OSPF_IS_AREA_BACKBONE(area
))
2873 " Number of full virtual adjacencies going through"
2877 /* Show SPF calculation times. */
2878 vty_out(vty
, " SPF algorithm executed %d times\n",
2879 area
->spf_calculation
);
2881 /* Show number of LSA. */
2882 vty_out(vty
, " Number of LSA %ld\n", area
->lsdb
->total
);
2884 " Number of router LSA %ld. Checksum Sum 0x%08x\n",
2885 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
),
2886 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
2888 " Number of network LSA %ld. Checksum Sum 0x%08x\n",
2889 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
),
2890 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
2892 " Number of summary LSA %ld. Checksum Sum 0x%08x\n",
2893 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
),
2894 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
2896 " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n",
2897 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
),
2898 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2899 vty_out(vty
, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n",
2900 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
),
2901 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2905 json_object_int_add(
2906 json_area
, "lsaOpaqueLinkNumber",
2907 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
2908 json_object_int_add(
2909 json_area
, "lsaOpaqueLinkChecksum",
2910 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
2911 json_object_int_add(
2912 json_area
, "lsaOpaqueAreaNumber",
2913 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
2914 json_object_int_add(
2915 json_area
, "lsaOpaqueAreaChecksum",
2916 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
2919 " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n",
2920 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
),
2921 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
2923 " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n",
2924 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
),
2925 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
2929 json_object_object_add(json_areas
, inet_ntoa(area
->area_id
),
2935 static int show_ip_ospf_common(struct vty
*vty
, struct ospf
*ospf
,
2936 json_object
*json
, uint8_t use_vrf
)
2938 struct listnode
*node
, *nnode
;
2939 struct ospf_area
*area
;
2940 struct timeval result
;
2941 char timebuf
[OSPF_TIME_DUMP_SIZE
];
2942 json_object
*json_vrf
= NULL
;
2943 json_object
*json_areas
= NULL
;
2947 json_vrf
= json_object_new_object();
2950 json_areas
= json_object_new_object();
2953 if (ospf
->instance
) {
2955 json_object_int_add(json
, "ospfInstance",
2958 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
2962 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
2964 /* Show Router ID. */
2966 json_object_string_add(json_vrf
, "routerId",
2967 inet_ntoa(ospf
->router_id
));
2969 vty_out(vty
, " OSPF Routing Process, Router ID: %s\n",
2970 inet_ntoa(ospf
->router_id
));
2973 /* Graceful shutdown */
2974 if (ospf
->t_deferred_shutdown
) {
2979 &ospf
->t_deferred_shutdown
->u
.sands
,
2982 json_object_int_add(json_vrf
, "deferredShutdownMsecs",
2986 " Deferred shutdown in progress, %s remaining\n",
2987 ospf_timer_dump(ospf
->t_deferred_shutdown
,
2988 timebuf
, sizeof(timebuf
)));
2992 /* Show capability. */
2994 json_object_boolean_true_add(json_vrf
, "tosRoutesOnly");
2995 json_object_boolean_true_add(json_vrf
, "rfc2328Conform");
2996 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2997 json_object_boolean_true_add(json_vrf
,
2998 "rfc1583Compatibility");
3001 vty_out(vty
, " Supports only single TOS (TOS0) routes\n");
3002 vty_out(vty
, " This implementation conforms to RFC2328\n");
3003 vty_out(vty
, " RFC1583Compatibility flag is %s\n",
3004 CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)
3010 if (CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)) {
3011 json_object_boolean_true_add(json_vrf
, "opaqueCapable");
3014 vty_out(vty
, " OpaqueCapability flag is %s\n",
3015 CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)
3020 /* Show stub-router configuration */
3021 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
3022 || ospf
->stub_router_shutdown_time
3023 != OSPF_STUB_ROUTER_UNCONFIGURED
) {
3025 json_object_boolean_true_add(json_vrf
,
3026 "stubAdvertisement");
3027 if (ospf
->stub_router_startup_time
3028 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3029 json_object_int_add(
3030 json_vrf
, "postStartEnabledMsecs",
3031 ospf
->stub_router_startup_time
/ 1000);
3032 if (ospf
->stub_router_shutdown_time
3033 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3034 json_object_int_add(
3035 json_vrf
, "preShutdownEnabledMsecs",
3036 ospf
->stub_router_shutdown_time
/ 1000);
3039 " Stub router advertisement is configured\n");
3040 if (ospf
->stub_router_startup_time
3041 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3043 " Enabled for %us after start-up\n",
3044 ospf
->stub_router_startup_time
);
3045 if (ospf
->stub_router_shutdown_time
3046 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3048 " Enabled for %us prior to full shutdown\n",
3049 ospf
->stub_router_shutdown_time
);
3053 /* Show SPF timers. */
3055 json_object_int_add(json_vrf
, "spfScheduleDelayMsecs",
3057 json_object_int_add(json_vrf
, "holdtimeMinMsecs",
3058 ospf
->spf_holdtime
);
3059 json_object_int_add(json_vrf
, "holdtimeMaxMsecs",
3060 ospf
->spf_max_holdtime
);
3061 json_object_int_add(json_vrf
, "holdtimeMultplier",
3062 ospf
->spf_hold_multiplier
);
3065 " Initial SPF scheduling delay %d millisec(s)\n"
3066 " Minimum hold time between consecutive SPFs %d millisec(s)\n"
3067 " Maximum hold time between consecutive SPFs %d millisec(s)\n"
3068 " Hold time multiplier is currently %d\n",
3069 ospf
->spf_delay
, ospf
->spf_holdtime
,
3070 ospf
->spf_max_holdtime
, ospf
->spf_hold_multiplier
);
3074 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3075 long time_store
= 0;
3078 monotime_since(&ospf
->ts_spf
, NULL
) / 1000LL;
3079 json_object_int_add(json_vrf
, "spfLastExecutedMsecs",
3082 time_store
= (1000 * ospf
->ts_spf_duration
.tv_sec
)
3083 + (ospf
->ts_spf_duration
.tv_usec
/ 1000);
3084 json_object_int_add(json_vrf
, "spfLastDurationMsecs",
3087 json_object_boolean_true_add(json_vrf
, "spfHasNotRun");
3089 vty_out(vty
, " SPF algorithm ");
3090 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3091 monotime_since(&ospf
->ts_spf
, &result
);
3092 vty_out(vty
, "last executed %s ago\n",
3093 ospf_timeval_dump(&result
, timebuf
,
3095 vty_out(vty
, " Last SPF duration %s\n",
3096 ospf_timeval_dump(&ospf
->ts_spf_duration
,
3097 timebuf
, sizeof(timebuf
)));
3099 vty_out(vty
, "has not been run\n");
3103 if (ospf
->t_spf_calc
) {
3106 monotime_until(&ospf
->t_spf_calc
->u
.sands
, NULL
)
3108 json_object_int_add(json_vrf
, "spfTimerDueInMsecs",
3112 json_object_int_add(json_vrf
, "lsaMinIntervalMsecs",
3113 ospf
->min_ls_interval
);
3114 json_object_int_add(json_vrf
, "lsaMinArrivalMsecs",
3115 ospf
->min_ls_arrival
);
3116 /* Show write multiplier values */
3117 json_object_int_add(json_vrf
, "writeMultiplier",
3118 ospf
->write_oi_count
);
3119 /* Show refresh parameters. */
3120 json_object_int_add(json_vrf
, "refreshTimerMsecs",
3121 ospf
->lsa_refresh_interval
* 1000);
3123 vty_out(vty
, " SPF timer %s%s\n",
3124 (ospf
->t_spf_calc
? "due in " : "is "),
3125 ospf_timer_dump(ospf
->t_spf_calc
, timebuf
,
3128 vty_out(vty
, " LSA minimum interval %d msecs\n",
3129 ospf
->min_ls_interval
);
3130 vty_out(vty
, " LSA minimum arrival %d msecs\n",
3131 ospf
->min_ls_arrival
);
3133 /* Show write multiplier values */
3134 vty_out(vty
, " Write Multiplier set to %d \n",
3135 ospf
->write_oi_count
);
3137 /* Show refresh parameters. */
3138 vty_out(vty
, " Refresh timer %d secs\n",
3139 ospf
->lsa_refresh_interval
);
3142 /* Show ABR/ASBR flags. */
3143 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ABR
)) {
3145 json_object_string_add(
3146 json_vrf
, "abrType",
3147 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3150 " This router is an ABR, ABR type is: %s\n",
3151 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3153 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ASBR
)) {
3155 json_object_string_add(
3156 json_vrf
, "asbrRouter",
3157 "injectingExternalRoutingInformation");
3160 " This router is an ASBR "
3161 "(injecting external routing information)\n");
3164 /* Show Number of AS-external-LSAs. */
3166 json_object_int_add(
3167 json_vrf
, "lsaExternalCounter",
3168 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3169 json_object_int_add(
3170 json_vrf
, "lsaExternalChecksum",
3171 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3174 " Number of external LSA %ld. Checksum Sum 0x%08x\n",
3175 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
),
3176 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3180 json_object_int_add(
3181 json_vrf
, "lsaAsopaqueCounter",
3182 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3183 json_object_int_add(
3184 json_vrf
, "lsaAsOpaqueChecksum",
3185 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3188 " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n",
3189 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
),
3190 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3193 /* Show number of areas attached. */
3195 json_object_int_add(json_vrf
, "attachedAreaCounter",
3196 listcount(ospf
->areas
));
3198 vty_out(vty
, " Number of areas attached to this router: %d\n",
3199 listcount(ospf
->areas
));
3201 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
3202 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
)) {
3204 json_object_boolean_true_add(
3205 json_vrf
, "adjacencyChangesLoggedAll");
3208 " All adjacency changes are logged\n");
3211 json_object_boolean_true_add(
3212 json_vrf
, "adjacencyChangesLogged");
3214 vty_out(vty
, " Adjacency changes are logged\n");
3217 /* Show each area status. */
3218 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
3219 show_ip_ospf_area(vty
, area
, json_areas
, json
? 1 : 0);
3223 json_object_object_add(json_vrf
, "areas", json_areas
);
3224 if (ospf
->vrf_id
== VRF_DEFAULT
)
3225 json_object_object_add(json
, "default",
3228 json_object_object_add(json
, ospf
->name
,
3231 json_object_object_add(json
, "areas", json_areas
);
3239 DEFUN (show_ip_ospf
,
3241 "show ip ospf [vrf <NAME|all>] [json]",
3244 "OSPF information\n"
3250 bool uj
= use_json(argc
, argv
);
3251 struct listnode
*node
= NULL
;
3252 char *vrf_name
= NULL
;
3253 bool all_vrf
= FALSE
;
3254 int ret
= CMD_SUCCESS
;
3257 json_object
*json
= NULL
;
3258 uint8_t use_vrf
= 0;
3260 if (listcount(om
->ospf
) == 0)
3263 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
3266 json
= json_object_new_object();
3268 /* vrf input is provided could be all or specific vrf*/
3270 bool ospf_output
= FALSE
;
3275 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
3276 if (!ospf
->oi_running
)
3279 ret
= show_ip_ospf_common(vty
, ospf
, json
,
3283 vty_out(vty
, "%s\n",
3284 json_object_to_json_string_ext(
3285 json
, JSON_C_TO_STRING_PRETTY
));
3286 json_object_free(json
);
3287 } else if (!ospf_output
)
3288 vty_out(vty
, "%% OSPF instance not found\n");
3291 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
3292 if ((ospf
== NULL
) || !ospf
->oi_running
) {
3294 vty_out(vty
, "%s\n",
3295 json_object_to_json_string_ext(
3296 json
, JSON_C_TO_STRING_PRETTY
));
3297 json_object_free(json
);
3299 vty_out(vty
, "%% OSPF instance not found\n");
3304 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
3305 /* Display default ospf (instance 0) info */
3306 if (ospf
== NULL
|| !ospf
->oi_running
) {
3308 vty_out(vty
, "%s\n",
3309 json_object_to_json_string_ext(
3310 json
, JSON_C_TO_STRING_PRETTY
));
3311 json_object_free(json
);
3313 vty_out(vty
, "%% OSPF instance not found\n");
3320 show_ip_ospf_common(vty
, ospf
, json
, use_vrf
);
3322 vty_out(vty
, "%s\n",
3323 json_object_to_json_string_ext(
3324 json
, JSON_C_TO_STRING_PRETTY
));
3328 json_object_free(json
);
3333 DEFUN (show_ip_ospf_instance
,
3334 show_ip_ospf_instance_cmd
,
3335 "show ip ospf (1-65535) [json]",
3338 "OSPF information\n"
3344 unsigned short instance
= 0;
3345 bool uj
= use_json(argc
, argv
);
3346 int ret
= CMD_SUCCESS
;
3347 json_object
*json
= NULL
;
3349 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
3350 ospf
= ospf_lookup_instance(instance
);
3352 return CMD_NOT_MY_INSTANCE
;
3354 if (!ospf
->oi_running
)
3358 json
= json_object_new_object();
3360 ret
= show_ip_ospf_common(vty
, ospf
, json
, 0);
3363 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
3364 json
, JSON_C_TO_STRING_PRETTY
));
3365 json_object_free(json
);
3371 static void show_ip_ospf_interface_sub(struct vty
*vty
, struct ospf
*ospf
,
3372 struct interface
*ifp
,
3373 json_object
*json_interface_sub
,
3377 struct ospf_neighbor
*nbr
;
3378 struct route_node
*rn
;
3379 uint32_t bandwidth
= ifp
->bandwidth
? ifp
->bandwidth
: ifp
->speed
;
3381 /* Is interface up? */
3383 is_up
= if_is_operative(ifp
);
3385 json_object_boolean_true_add(json_interface_sub
,
3388 json_object_boolean_false_add(json_interface_sub
,
3391 json_object_int_add(json_interface_sub
, "ifIndex",
3393 json_object_int_add(json_interface_sub
, "mtuBytes", ifp
->mtu
);
3394 json_object_int_add(json_interface_sub
, "bandwidthMbit",
3396 json_object_string_add(json_interface_sub
, "ifFlags",
3397 if_flag_dump(ifp
->flags
));
3399 vty_out(vty
, "%s is %s\n", ifp
->name
,
3400 ((is_up
= if_is_operative(ifp
)) ? "up" : "down"));
3401 vty_out(vty
, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n",
3402 ifp
->ifindex
, ifp
->mtu
, bandwidth
,
3403 if_flag_dump(ifp
->flags
));
3406 /* Is interface OSPF enabled? */
3408 if (ospf_oi_count(ifp
) == 0) {
3409 json_object_boolean_false_add(json_interface_sub
,
3412 } else if (!is_up
) {
3413 json_object_boolean_false_add(json_interface_sub
,
3417 json_object_boolean_true_add(json_interface_sub
,
3420 if (ospf_oi_count(ifp
) == 0) {
3421 vty_out(vty
, " OSPF not enabled on this interface\n");
3423 } else if (!is_up
) {
3425 " OSPF is enabled, but not running on this interface\n");
3430 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
3431 struct ospf_interface
*oi
= rn
->info
;
3436 if (CHECK_FLAG(oi
->connected
->flags
, ZEBRA_IFA_UNNUMBERED
)) {
3438 json_object_boolean_true_add(json_interface_sub
,
3441 vty_out(vty
, " This interface is UNNUMBERED,");
3443 /* Show OSPF interface information. */
3445 json_object_string_add(
3446 json_interface_sub
, "ipAddress",
3447 inet_ntoa(oi
->address
->u
.prefix4
));
3448 json_object_int_add(json_interface_sub
,
3449 "ipAddressPrefixlen",
3450 oi
->address
->prefixlen
);
3452 vty_out(vty
, " Internet Address %s/%d,",
3453 inet_ntoa(oi
->address
->u
.prefix4
),
3454 oi
->address
->prefixlen
);
3456 if (oi
->connected
->destination
3457 || oi
->type
== OSPF_IFTYPE_VIRTUALLINK
) {
3458 struct in_addr
*dest
;
3461 if (CONNECTED_PEER(oi
->connected
)
3462 || oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3467 /* For Vlinks, showing the peer address is
3469 * * * * * informative than the local
3470 * interface that is being used
3472 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3473 dest
= &oi
->vl_data
->peer_addr
;
3475 dest
= &oi
->connected
->destination
->u
3479 json_object_string_add(
3481 "ospfIfType", dstr
);
3482 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3483 json_object_string_add(
3488 json_object_string_add(
3493 vty_out(vty
, " %s %s,", dstr
,
3498 json_object_string_add(json_interface_sub
, "area",
3499 ospf_area_desc_string(oi
->area
));
3500 if (OSPF_IF_PARAM(oi
, mtu_ignore
))
3501 json_object_boolean_true_add(
3503 "mtuMismatchDetect");
3504 json_object_string_add(json_interface_sub
, "routerId",
3505 inet_ntoa(ospf
->router_id
));
3506 json_object_string_add(json_interface_sub
,
3508 ospf_network_type_str
[oi
->type
]);
3509 json_object_int_add(json_interface_sub
, "cost",
3511 json_object_int_add(
3512 json_interface_sub
, "transmitDelayMsecs",
3513 1000 / OSPF_IF_PARAM(oi
, transmit_delay
));
3514 json_object_string_add(json_interface_sub
, "state",
3515 lookup_msg(ospf_ism_state_msg
,
3517 json_object_int_add(json_interface_sub
, "priority",
3520 vty_out(vty
, " Area %s\n",
3521 ospf_area_desc_string(oi
->area
));
3523 vty_out(vty
, " MTU mismatch detection: %s\n",
3524 OSPF_IF_PARAM(oi
, mtu_ignore
) ? "disabled"
3528 " Router ID %s, Network Type %s, Cost: %d\n",
3529 inet_ntoa(ospf
->router_id
),
3530 ospf_network_type_str
[oi
->type
],
3534 " Transmit Delay is %d sec, State %s, Priority %d\n",
3535 OSPF_IF_PARAM(oi
, transmit_delay
),
3536 lookup_msg(ospf_ism_state_msg
, oi
->state
, NULL
),
3540 /* Show DR information. */
3541 if (DR(oi
).s_addr
== 0) {
3544 " No backup designated router on this network\n");
3546 nbr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &BDR(oi
));
3550 " No backup designated router on this network\n");
3553 json_object_string_add(
3554 json_interface_sub
, "bdrId",
3555 inet_ntoa(nbr
->router_id
));
3556 json_object_string_add(
3559 inet_ntoa(nbr
->address
.u
3563 " Backup Designated Router (ID) %s,",
3564 inet_ntoa(nbr
->router_id
));
3565 vty_out(vty
, " Interface Address %s\n",
3566 inet_ntoa(nbr
->address
.u
3572 /* Next network-LSA sequence number we'll use, if we're elected
3575 && ntohl(oi
->params
->network_lsa_seqnum
)
3576 != OSPF_INITIAL_SEQUENCE_NUMBER
) {
3578 json_object_int_add(
3580 "networkLsaSequence",
3581 ntohl(oi
->params
->network_lsa_seqnum
));
3584 " Saved Network-LSA sequence number 0x%x\n",
3585 ntohl(oi
->params
->network_lsa_seqnum
));
3589 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3590 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3591 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3592 json_object_boolean_true_add(
3594 "mcastMemberOspfAllRouters");
3595 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3596 json_object_boolean_true_add(
3598 "mcastMemberOspfDesignatedRouters");
3601 vty_out(vty
, " Multicast group memberships:");
3602 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3603 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3604 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3605 vty_out(vty
, " OSPFAllRouters");
3606 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3607 vty_out(vty
, " OSPFDesignatedRouters");
3609 vty_out(vty
, " <None>");
3614 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3615 json_object_int_add(
3616 json_interface_sub
, "timerMsecs",
3617 1000 / OSPF_IF_PARAM(oi
, v_hello
));
3619 json_object_int_add(
3620 json_interface_sub
, "timerMsecs",
3621 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3622 json_object_int_add(json_interface_sub
,
3624 1000 / OSPF_IF_PARAM(oi
, v_wait
));
3625 json_object_int_add(json_interface_sub
,
3627 1000 / OSPF_IF_PARAM(oi
, v_wait
));
3628 json_object_int_add(
3629 json_interface_sub
, "timerRetransmit",
3630 1000 / OSPF_IF_PARAM(oi
, retransmit_interval
));
3632 vty_out(vty
, " Timer intervals configured,");
3633 vty_out(vty
, " Hello ");
3634 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3635 vty_out(vty
, "%ds,",
3636 OSPF_IF_PARAM(oi
, v_hello
));
3638 vty_out(vty
, "%dms,",
3639 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3640 vty_out(vty
, " Dead %ds, Wait %ds, Retransmit %d\n",
3641 OSPF_IF_PARAM(oi
, v_wait
),
3642 OSPF_IF_PARAM(oi
, v_wait
),
3643 OSPF_IF_PARAM(oi
, retransmit_interval
));
3646 if (OSPF_IF_PASSIVE_STATUS(oi
) == OSPF_IF_ACTIVE
) {
3647 char timebuf
[OSPF_TIME_DUMP_SIZE
];
3649 long time_store
= 0;
3653 &oi
->t_hello
->u
.sands
,
3656 json_object_int_add(json_interface_sub
,
3657 "timerHelloInMsecs",
3660 vty_out(vty
, " Hello due in %s\n",
3661 ospf_timer_dump(oi
->t_hello
, timebuf
,
3663 } else /* passive-interface is set */
3666 json_object_boolean_true_add(
3668 "timerPassiveIface");
3671 " No Hellos (Passive interface)\n");
3675 json_object_int_add(json_interface_sub
, "nbrCount",
3676 ospf_nbr_count(oi
, 0));
3677 json_object_int_add(json_interface_sub
,
3679 ospf_nbr_count(oi
, NSM_Full
));
3682 " Neighbor Count is %d, Adjacent neighbor count is %d\n",
3683 ospf_nbr_count(oi
, 0),
3684 ospf_nbr_count(oi
, NSM_Full
));
3685 ospf_bfd_interface_show(vty
, ifp
, json_interface_sub
, use_json
);
3689 static int show_ip_ospf_interface_common(struct vty
*vty
, struct ospf
*ospf
,
3690 char *intf_name
, uint8_t use_vrf
,
3691 json_object
*json
, bool use_json
)
3693 struct interface
*ifp
;
3694 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
3695 json_object
*json_vrf
= NULL
;
3696 json_object
*json_interface_sub
= NULL
, *json_interface
= NULL
;
3700 json_vrf
= json_object_new_object();
3703 json_interface
= json_object_new_object();
3706 if (ospf
->instance
) {
3708 json_object_int_add(json
, "ospfInstance",
3711 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
3714 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3716 if (intf_name
== NULL
) {
3717 /* Show All Interfaces.*/
3718 FOR_ALL_INTERFACES (vrf
, ifp
) {
3719 if (ospf_oi_count(ifp
)) {
3721 json_interface_sub
=
3722 json_object_new_object();
3724 show_ip_ospf_interface_sub(vty
, ospf
, ifp
,
3729 json_object_object_add(
3730 json_interface
, ifp
->name
,
3731 json_interface_sub
);
3736 json_object_object_add(json_vrf
, "interfaces",
3739 /* Interface name is specified. */
3740 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
3743 json_object_boolean_true_add(json_vrf
,
3746 vty_out(vty
, "No such interface name\n");
3749 json_interface_sub
= json_object_new_object();
3750 json_interface
= json_object_new_object();
3753 show_ip_ospf_interface_sub(
3754 vty
, ospf
, ifp
, json_interface_sub
, use_json
);
3757 json_object_object_add(json_interface
,
3759 json_interface_sub
);
3760 json_object_object_add(json_vrf
, "interfaces",
3768 if (ospf
->vrf_id
== VRF_DEFAULT
)
3769 json_object_object_add(json
, "default",
3772 json_object_object_add(json
, ospf
->name
,
3781 static void show_ip_ospf_interface_traffic_sub(struct vty
*vty
,
3782 struct ospf_interface
*oi
,
3783 json_object
*json_interface_sub
,
3787 json_object_int_add(json_interface_sub
, "ifIndex",
3789 json_object_int_add(json_interface_sub
, "helloIn",
3791 json_object_int_add(json_interface_sub
, "helloOut",
3793 json_object_int_add(json_interface_sub
, "dbDescIn",
3795 json_object_int_add(json_interface_sub
, "dbDescOut",
3797 json_object_int_add(json_interface_sub
, "lsReqIn",
3799 json_object_int_add(json_interface_sub
, "lsReqOut",
3801 json_object_int_add(json_interface_sub
, "lsUpdIn",
3803 json_object_int_add(json_interface_sub
, "lsUpdOut",
3805 json_object_int_add(json_interface_sub
, "lsAckIn",
3807 json_object_int_add(json_interface_sub
, "lsAckOut",
3811 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n",
3812 oi
->ifp
->name
, oi
->hello_in
, oi
->hello_out
,
3813 oi
->db_desc_in
, oi
->db_desc_out
, oi
->ls_req_in
,
3814 oi
->ls_req_out
, oi
->ls_upd_in
, oi
->ls_upd_out
,
3815 oi
->ls_ack_in
, oi
->ls_ack_out
);
3819 /* OSPFv2 Packet Counters */
3820 static int show_ip_ospf_interface_traffic_common(
3821 struct vty
*vty
, struct ospf
*ospf
, char *intf_name
, json_object
*json
,
3822 int display_once
, uint8_t use_vrf
, bool use_json
)
3824 struct vrf
*vrf
= NULL
;
3825 struct interface
*ifp
= NULL
;
3826 json_object
*json_vrf
= NULL
;
3827 json_object
*json_interface_sub
= NULL
;
3829 if (!use_json
&& !display_once
) {
3831 vty_out(vty
, "%-12s%-17s%-17s%-17s%-17s%-17s\n", "Interface",
3832 " HELLO", " DB-Desc", " LS-Req", " LS-Update",
3834 vty_out(vty
, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "",
3835 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
3838 "--------------------------------------------------------------------------------------------\n");
3839 } else if (use_json
) {
3841 json_vrf
= json_object_new_object();
3846 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3848 if (intf_name
== NULL
) {
3849 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
3850 FOR_ALL_INTERFACES (vrf
, ifp
) {
3851 struct route_node
*rn
;
3852 struct ospf_interface
*oi
;
3854 if (ospf_oi_count(ifp
) == 0)
3857 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
3858 rn
= route_next(rn
)) {
3865 json_interface_sub
=
3866 json_object_new_object();
3869 show_ip_ospf_interface_traffic_sub(
3870 vty
, oi
, json_interface_sub
, use_json
);
3872 json_object_object_add(
3873 json_vrf
, ifp
->name
,
3874 json_interface_sub
);
3879 /* Interface name is specified. */
3880 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
3882 struct route_node
*rn
;
3883 struct ospf_interface
*oi
;
3885 if (ospf_oi_count(ifp
) == 0) {
3887 " OSPF not enabled on this interface %s\n",
3892 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
3893 rn
= route_next(rn
)) {
3897 json_interface_sub
=
3898 json_object_new_object();
3901 show_ip_ospf_interface_traffic_sub(
3902 vty
, oi
, json_interface_sub
, use_json
);
3904 json_object_object_add(
3905 json_vrf
, ifp
->name
,
3906 json_interface_sub
);
3914 if (ospf
->vrf_id
== VRF_DEFAULT
)
3915 json_object_object_add(json
, "default",
3918 json_object_object_add(json
, ospf
->name
,
3927 DEFUN (show_ip_ospf_interface
,
3928 show_ip_ospf_interface_cmd
,
3929 "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]",
3932 "OSPF information\n"
3935 "Interface information\n"
3940 bool uj
= use_json(argc
, argv
);
3941 struct listnode
*node
= NULL
;
3942 char *vrf_name
= NULL
, *intf_name
= NULL
;
3943 bool all_vrf
= FALSE
;
3944 int ret
= CMD_SUCCESS
;
3946 int idx_vrf
= 0, idx_intf
= 0;
3947 uint8_t use_vrf
= 0;
3948 json_object
*json
= NULL
;
3950 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
3952 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
3953 intf_name
= argv
[idx_intf
]->arg
;
3956 json
= json_object_new_object();
3958 /* vrf input is provided could be all or specific vrf*/
3962 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
3963 if (!ospf
->oi_running
)
3965 ret
= show_ip_ospf_interface_common(
3966 vty
, ospf
, intf_name
, use_vrf
, json
,
3971 vty_out(vty
, "%s\n",
3972 json_object_to_json_string_ext(
3973 json
, JSON_C_TO_STRING_PRETTY
));
3974 json_object_free(json
);
3976 vty_out(vty
, "%% OSPF instance not found\n");
3980 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
3981 if (ospf
== NULL
|| !ospf
->oi_running
) {
3983 vty_out(vty
, "%s\n",
3984 json_object_to_json_string_ext(
3985 json
, JSON_C_TO_STRING_PRETTY
));
3986 json_object_free(json
);
3988 vty_out(vty
, "%% OSPF instance not found\n");
3992 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
3996 /* Display default ospf (instance 0) info */
3997 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
3998 if (ospf
== NULL
|| !ospf
->oi_running
) {
4000 vty_out(vty
, "%s\n",
4001 json_object_to_json_string_ext(
4002 json
, JSON_C_TO_STRING_PRETTY
));
4003 json_object_free(json
);
4005 vty_out(vty
, "%% OSPF instance not found\n");
4009 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
4014 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4015 json
, JSON_C_TO_STRING_PRETTY
));
4016 json_object_free(json
);
4022 DEFUN (show_ip_ospf_instance_interface
,
4023 show_ip_ospf_instance_interface_cmd
,
4024 "show ip ospf (1-65535) interface [INTERFACE] [json]",
4027 "OSPF information\n"
4029 "Interface information\n"
4036 unsigned short instance
= 0;
4037 bool uj
= use_json(argc
, argv
);
4038 char *intf_name
= NULL
;
4039 int ret
= CMD_SUCCESS
;
4040 json_object
*json
= NULL
;
4042 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4043 ospf
= ospf_lookup_instance(instance
);
4045 return CMD_NOT_MY_INSTANCE
;
4047 if (!ospf
->oi_running
)
4051 json
= json_object_new_object();
4053 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4054 intf_name
= argv
[idx_intf
]->arg
;
4056 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
, 0, json
, uj
);
4059 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4060 json
, JSON_C_TO_STRING_PRETTY
));
4061 json_object_free(json
);
4067 DEFUN (show_ip_ospf_interface_traffic
,
4068 show_ip_ospf_interface_traffic_cmd
,
4069 "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]",
4072 "OSPF information\n"
4075 "Interface information\n"
4076 "Protocol Packet counters\n"
4080 struct ospf
*ospf
= NULL
;
4081 struct listnode
*node
= NULL
;
4082 char *vrf_name
= NULL
, *intf_name
= NULL
;
4083 bool all_vrf
= FALSE
;
4085 int idx_vrf
= 0, idx_intf
= 0;
4086 bool uj
= use_json(argc
, argv
);
4087 json_object
*json
= NULL
;
4088 int ret
= CMD_SUCCESS
;
4089 int display_once
= 0;
4090 uint8_t use_vrf
= 0;
4092 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4094 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4095 intf_name
= argv
[idx_intf
]->arg
;
4098 json
= json_object_new_object();
4103 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4104 if (!ospf
->oi_running
)
4107 ret
= show_ip_ospf_interface_traffic_common(
4108 vty
, ospf
, intf_name
, json
,
4109 display_once
, use_vrf
, uj
);
4114 vty_out(vty
, "%s\n",
4115 json_object_to_json_string_ext(
4116 json
, JSON_C_TO_STRING_PRETTY
));
4117 json_object_free(json
);
4122 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4123 if (ospf
== NULL
|| !ospf
->oi_running
) {
4125 json_object_free(json
);
4129 ret
= show_ip_ospf_interface_traffic_common(
4130 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4132 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4133 if (ospf
== NULL
|| !ospf
->oi_running
) {
4135 json_object_free(json
);
4139 ret
= show_ip_ospf_interface_traffic_common(
4140 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4144 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4145 json
, JSON_C_TO_STRING_PRETTY
));
4146 json_object_free(json
);
4153 static void show_ip_ospf_neighbour_header(struct vty
*vty
)
4155 vty_out(vty
, "\n%-15s %3s %-15s %9s %-15s %-20s %5s %5s %5s\n",
4156 "Neighbor ID", "Pri", "State", "Dead Time", "Address",
4157 "Interface", "RXmtL", "RqstL", "DBsmL");
4160 static void show_ip_ospf_neighbor_sub(struct vty
*vty
,
4161 struct ospf_interface
*oi
,
4162 json_object
*json
, bool use_json
)
4164 struct route_node
*rn
;
4165 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
4167 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4168 json_object
*json_neighbor
= NULL
, *json_neigh_array
= NULL
;
4170 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
4171 if ((nbr
= rn
->info
)) {
4172 /* Do not show myself. */
4173 if (nbr
== oi
->nbr_self
)
4175 /* Down state is not shown. */
4176 if (nbr
->state
== NSM_Down
)
4179 char neigh_str
[INET_ADDRSTRLEN
];
4182 && !IPV4_ADDR_SAME(&prev_nbr
->src
,
4184 /* Start new neigh list */
4185 json_neigh_array
= NULL
;
4188 if (nbr
->state
== NSM_Attempt
4189 && nbr
->router_id
.s_addr
== 0)
4190 strlcpy(neigh_str
, "neighbor",
4194 inet_ntoa(nbr
->router_id
),
4197 json_object_object_get_ex(json
, neigh_str
,
4200 if (!json_neigh_array
) {
4202 json_object_new_array();
4203 json_object_object_add(
4208 json_neighbor
= json_object_new_object();
4210 ospf_nbr_state_message(nbr
, msgbuf
, 16);
4216 &nbr
->t_inactivity
->u
.sands
,
4220 json_object_int_add(json_neighbor
, "priority",
4222 json_object_string_add(json_neighbor
, "state",
4224 json_object_int_add(json_neighbor
,
4227 json_object_string_add(json_neighbor
, "address",
4228 inet_ntoa(nbr
->src
));
4229 json_object_string_add(json_neighbor
,
4232 json_object_int_add(
4233 json_neighbor
, "retransmitCounter",
4234 ospf_ls_retransmit_count(nbr
));
4235 json_object_int_add(json_neighbor
,
4237 ospf_ls_request_count(nbr
));
4238 json_object_int_add(json_neighbor
,
4240 ospf_db_summary_count(nbr
));
4242 json_object_array_add(json_neigh_array
,
4245 ospf_nbr_state_message(nbr
, msgbuf
, 16);
4247 if (nbr
->state
== NSM_Attempt
4248 && nbr
->router_id
.s_addr
== 0)
4249 vty_out(vty
, "%-15s %3d %-15s ", "-",
4250 nbr
->priority
, msgbuf
);
4252 vty_out(vty
, "%-15s %3d %-15s ",
4253 inet_ntoa(nbr
->router_id
),
4254 nbr
->priority
, msgbuf
);
4256 vty_out(vty
, "%9s ",
4257 ospf_timer_dump(nbr
->t_inactivity
,
4260 vty_out(vty
, "%-15s ", inet_ntoa(nbr
->src
));
4261 vty_out(vty
, "%-20s %5ld %5ld %5d\n",
4263 ospf_ls_retransmit_count(nbr
),
4264 ospf_ls_request_count(nbr
),
4265 ospf_db_summary_count(nbr
));
4272 static int show_ip_ospf_neighbor_common(struct vty
*vty
, struct ospf
*ospf
,
4273 json_object
*json
, bool use_json
,
4276 struct ospf_interface
*oi
;
4277 struct listnode
*node
;
4278 json_object
*json_vrf
= NULL
;
4279 json_object
*json_nbr_sub
= NULL
;
4283 json_vrf
= json_object_new_object();
4286 json_nbr_sub
= json_object_new_object();
4289 if (ospf
->instance
) {
4291 json_object_int_add(json
, "ospfInstance",
4294 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4297 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4299 show_ip_ospf_neighbour_header(vty
);
4301 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4302 if (ospf_interface_neighbor_count(oi
) == 0)
4304 show_ip_ospf_neighbor_sub(vty
, oi
, json_nbr_sub
, use_json
);
4308 json_object_object_add(json_vrf
, "neighbors", json_nbr_sub
);
4310 if (ospf
->vrf_id
== VRF_DEFAULT
)
4311 json_object_object_add(json
, "default",
4314 json_object_object_add(json
, ospf
->name
,
4323 DEFUN (show_ip_ospf_neighbor
,
4324 show_ip_ospf_neighbor_cmd
,
4325 "show ip ospf [vrf <NAME|all>] neighbor [json]",
4328 "OSPF information\n"
4335 bool uj
= use_json(argc
, argv
);
4336 struct listnode
*node
= NULL
;
4337 char *vrf_name
= NULL
;
4338 bool all_vrf
= FALSE
;
4339 int ret
= CMD_SUCCESS
;
4342 uint8_t use_vrf
= 0;
4343 json_object
*json
= NULL
;
4345 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4348 json
= json_object_new_object();
4350 /* vrf input is provided could be all or specific vrf*/
4354 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4355 if (!ospf
->oi_running
)
4357 ret
= show_ip_ospf_neighbor_common(
4358 vty
, ospf
, json
, uj
, use_vrf
);
4362 vty_out(vty
, "%s\n",
4363 json_object_to_json_string_ext(
4364 json
, JSON_C_TO_STRING_PRETTY
));
4365 json_object_free(json
);
4367 vty_out(vty
, "OSPF instance not found\n");
4372 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4373 if (ospf
== NULL
|| !ospf
->oi_running
) {
4375 vty_out(vty
, "%s\n",
4376 json_object_to_json_string_ext(
4377 json
, JSON_C_TO_STRING_PRETTY
));
4378 json_object_free(json
);
4380 vty_out(vty
, "%% OSPF instance not found\n");
4385 /* Display default ospf (instance 0) info */
4386 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4387 if (ospf
== NULL
|| !ospf
->oi_running
) {
4389 vty_out(vty
, "%s\n",
4390 json_object_to_json_string_ext(
4391 json
, JSON_C_TO_STRING_PRETTY
));
4392 json_object_free(json
);
4394 vty_out(vty
, "%% OSPF instance not found\n");
4401 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
,
4405 vty_out(vty
, "%s\n",
4406 json_object_to_json_string_ext(
4407 json
, JSON_C_TO_STRING_PRETTY
));
4412 json_object_free(json
);
4418 DEFUN (show_ip_ospf_instance_neighbor
,
4419 show_ip_ospf_instance_neighbor_cmd
,
4420 "show ip ospf (1-65535) neighbor [json]",
4423 "OSPF information\n"
4430 unsigned short instance
= 0;
4431 bool uj
= use_json(argc
, argv
);
4432 json_object
*json
= NULL
;
4433 int ret
= CMD_SUCCESS
;
4435 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4436 ospf
= ospf_lookup_instance(instance
);
4438 return CMD_NOT_MY_INSTANCE
;
4440 if (!ospf
->oi_running
)
4444 json
= json_object_new_object();
4446 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
, 0);
4449 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4450 json
, JSON_C_TO_STRING_PRETTY
));
4451 json_object_free(json
);
4457 static int show_ip_ospf_neighbor_all_common(struct vty
*vty
, struct ospf
*ospf
,
4458 json_object
*json
, bool use_json
,
4461 struct listnode
*node
;
4462 struct ospf_interface
*oi
;
4463 json_object
*json_vrf
= NULL
;
4464 json_object
*json_neighbor_sub
= NULL
;
4468 json_vrf
= json_object_new_object();
4471 json_neighbor_sub
= json_object_new_object();
4474 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4476 show_ip_ospf_neighbour_header(vty
);
4478 if (ospf
->instance
) {
4480 json_object_int_add(json_vrf
, "ospfInstance",
4483 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4486 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4487 struct listnode
*nbr_node
;
4488 struct ospf_nbr_nbma
*nbr_nbma
;
4490 show_ip_ospf_neighbor_sub(vty
, oi
, json_vrf
, use_json
);
4492 /* print Down neighbor status */
4493 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nbr_node
, nbr_nbma
)) {
4494 if (nbr_nbma
->nbr
== NULL
4495 || nbr_nbma
->nbr
->state
== NSM_Down
) {
4497 json_object_int_add(json_neighbor_sub
,
4499 nbr_nbma
->priority
);
4500 json_object_boolean_true_add(
4503 json_object_string_add(
4507 json_object_int_add(
4509 "nbrNbmaRetransmitCounter", 0);
4510 json_object_int_add(
4512 "nbrNbmaRequestCounter", 0);
4513 json_object_int_add(
4515 "nbrNbmaDbSummaryCounter", 0);
4516 json_object_object_add(
4518 inet_ntoa(nbr_nbma
->addr
),
4521 vty_out(vty
, "%-15s %3d %-15s %9s ",
4522 "-", nbr_nbma
->priority
, "Down",
4525 "%-15s %-20s %5d %5d %5d\n",
4526 inet_ntoa(nbr_nbma
->addr
),
4527 IF_NAME(oi
), 0, 0, 0);
4535 if (ospf
->vrf_id
== VRF_DEFAULT
)
4536 json_object_object_add(json
, "default",
4539 json_object_object_add(json
, ospf
->name
,
4548 DEFUN (show_ip_ospf_neighbor_all
,
4549 show_ip_ospf_neighbor_all_cmd
,
4550 "show ip ospf [vrf <NAME|all>] neighbor all [json]",
4553 "OSPF information\n"
4557 "include down status neighbor\n"
4561 bool uj
= use_json(argc
, argv
);
4562 struct listnode
*node
= NULL
;
4563 char *vrf_name
= NULL
;
4564 bool all_vrf
= FALSE
;
4565 int ret
= CMD_SUCCESS
;
4568 uint8_t use_vrf
= 0;
4569 json_object
*json
= NULL
;
4571 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4574 json
= json_object_new_object();
4576 /* vrf input is provided could be all or specific vrf*/
4580 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4581 if (!ospf
->oi_running
)
4583 ret
= show_ip_ospf_neighbor_all_common(
4584 vty
, ospf
, json
, uj
, use_vrf
);
4588 vty_out(vty
, "%s\n",
4589 json_object_to_json_string_ext(
4590 json
, JSON_C_TO_STRING_PRETTY
));
4591 json_object_free(json
);
4597 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4598 if (ospf
== NULL
|| !ospf
->oi_running
) {
4600 json_object_free(json
);
4604 /* Display default ospf (instance 0) info */
4605 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4606 if (ospf
== NULL
|| !ospf
->oi_running
) {
4608 json_object_free(json
);
4614 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
,
4617 vty_out(vty
, "%s\n",
4618 json_object_to_json_string_ext(
4619 json
, JSON_C_TO_STRING_PRETTY
));
4624 json_object_free(json
);
4629 DEFUN (show_ip_ospf_instance_neighbor_all
,
4630 show_ip_ospf_instance_neighbor_all_cmd
,
4631 "show ip ospf (1-65535) neighbor all [json]",
4634 "OSPF information\n"
4637 "include down status neighbor\n"
4642 unsigned short instance
= 0;
4643 bool uj
= use_json(argc
, argv
);
4644 json_object
*json
= NULL
;
4645 int ret
= CMD_SUCCESS
;
4647 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4648 ospf
= ospf_lookup_instance(instance
);
4650 return CMD_NOT_MY_INSTANCE
;
4652 if (!ospf
->oi_running
)
4655 json
= json_object_new_object();
4657 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
, 0);
4660 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4661 json
, JSON_C_TO_STRING_PRETTY
));
4662 json_object_free(json
);
4668 static int show_ip_ospf_neighbor_int_common(struct vty
*vty
, struct ospf
*ospf
,
4670 struct cmd_token
**argv
,
4671 bool use_json
, uint8_t use_vrf
)
4673 struct interface
*ifp
;
4674 struct route_node
*rn
;
4675 json_object
*json
= NULL
;
4678 json
= json_object_new_object();
4680 if (ospf
->instance
) {
4682 json_object_int_add(json
, "ospfInstance",
4685 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4688 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
4690 ifp
= if_lookup_by_name(argv
[arg_base
]->arg
, ospf
->vrf_id
);
4693 json_object_boolean_true_add(json
, "noSuchIface");
4695 vty_out(vty
, "No such interface.\n");
4699 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
4700 struct ospf_interface
*oi
= rn
->info
;
4705 show_ip_ospf_neighbor_sub(vty
, oi
, json
, use_json
);
4709 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4710 json
, JSON_C_TO_STRING_PRETTY
));
4711 json_object_free(json
);
4718 DEFUN (show_ip_ospf_neighbor_int
,
4719 show_ip_ospf_neighbor_int_cmd
,
4720 "show ip ospf [vrf <NAME>] neighbor IFNAME [json]",
4723 "OSPF information\n"
4732 bool uj
= use_json(argc
, argv
);
4733 int ret
= CMD_SUCCESS
;
4734 struct interface
*ifp
= NULL
;
4735 char *vrf_name
= NULL
;
4736 vrf_id_t vrf_id
= VRF_DEFAULT
;
4737 struct vrf
*vrf
= NULL
;
4739 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
4740 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
4741 if (vrf_name
&& strmatch(vrf_name
, VRF_DEFAULT_NAME
))
4744 vrf
= vrf_lookup_by_name(vrf_name
);
4746 vrf_id
= vrf
->vrf_id
;
4748 ospf
= ospf_lookup_by_vrf_id(vrf_id
);
4750 if (!ospf
|| !ospf
->oi_running
)
4754 show_ip_ospf_neighbour_header(vty
);
4756 argv_find(argv
, argc
, "IFNAME", &idx_ifname
);
4758 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf_id
);
4762 ret
= show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
,
4767 DEFUN (show_ip_ospf_instance_neighbor_int
,
4768 show_ip_ospf_instance_neighbor_int_cmd
,
4769 "show ip ospf (1-65535) neighbor IFNAME [json]",
4772 "OSPF information\n"
4781 unsigned short instance
= 0;
4782 bool uj
= use_json(argc
, argv
);
4785 show_ip_ospf_neighbour_header(vty
);
4787 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4788 ospf
= ospf_lookup_instance(instance
);
4790 return CMD_NOT_MY_INSTANCE
;
4792 if (!ospf
->oi_running
)
4796 show_ip_ospf_neighbour_header(vty
);
4798 return show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
, argv
, uj
,
4802 static void show_ip_ospf_nbr_nbma_detail_sub(struct vty
*vty
,
4803 struct ospf_interface
*oi
,
4804 struct ospf_nbr_nbma
*nbr_nbma
,
4805 bool use_json
, json_object
*json
)
4807 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4808 json_object
*json_sub
= NULL
;
4811 json_sub
= json_object_new_object();
4812 else /* Show neighbor ID. */
4813 vty_out(vty
, " Neighbor %s,", "-");
4815 /* Show interface address. */
4817 json_object_string_add(json_sub
, "ifaceAddress",
4818 inet_ntoa(nbr_nbma
->addr
));
4820 vty_out(vty
, " interface address %s\n",
4821 inet_ntoa(nbr_nbma
->addr
));
4825 json_object_string_add(json_sub
, "areaId",
4826 ospf_area_desc_string(oi
->area
));
4827 json_object_string_add(json_sub
, "iface", IF_NAME(oi
));
4829 vty_out(vty
, " In the area %s via interface %s\n",
4830 ospf_area_desc_string(oi
->area
), IF_NAME(oi
));
4832 /* Show neighbor priority and state. */
4834 json_object_int_add(json_sub
, "nbrPriority",
4835 nbr_nbma
->priority
);
4836 json_object_string_add(json_sub
, "nbrState", "down");
4838 vty_out(vty
, " Neighbor priority is %d, State is %s,",
4839 nbr_nbma
->priority
, "Down");
4841 /* Show state changes. */
4843 json_object_int_add(json_sub
, "stateChangeCounter",
4844 nbr_nbma
->state_change
);
4846 vty_out(vty
, " %d state changes\n", nbr_nbma
->state_change
);
4848 /* Show PollInterval */
4850 json_object_int_add(json_sub
, "pollInterval", nbr_nbma
->v_poll
);
4852 vty_out(vty
, " Poll interval %d\n", nbr_nbma
->v_poll
);
4854 /* Show poll-interval timer. */
4855 if (nbr_nbma
->t_poll
) {
4858 time_store
= monotime_until(&nbr_nbma
->t_poll
->u
.sands
,
4860 json_object_int_add(json_sub
,
4861 "pollIntervalTimerDueMsec",
4864 vty_out(vty
, " Poll timer due in %s\n",
4865 ospf_timer_dump(nbr_nbma
->t_poll
, timebuf
,
4869 /* Show poll-interval timer thread. */
4871 if (nbr_nbma
->t_poll
!= NULL
)
4872 json_object_string_add(json_sub
,
4873 "pollIntervalTimerThread", "on");
4875 vty_out(vty
, " Thread Poll Timer %s\n",
4876 nbr_nbma
->t_poll
!= NULL
? "on" : "off");
4879 json_object_object_add(json
, "noNbrId", json_sub
);
4882 static void show_ip_ospf_neighbor_detail_sub(struct vty
*vty
,
4883 struct ospf_interface
*oi
,
4884 struct ospf_neighbor
*nbr
,
4885 json_object
*json
, bool use_json
)
4887 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4888 json_object
*json_sub
= NULL
;
4891 json_sub
= json_object_new_object();
4893 /* Show neighbor ID. */
4894 if (nbr
->state
== NSM_Attempt
&& nbr
->router_id
.s_addr
== 0)
4895 vty_out(vty
, " Neighbor %s,", "-");
4897 vty_out(vty
, " Neighbor %s,",
4898 inet_ntoa(nbr
->router_id
));
4901 /* Show interface address. */
4903 json_object_string_add(json_sub
, "ifaceAddress",
4904 inet_ntoa(nbr
->address
.u
.prefix4
));
4906 vty_out(vty
, " interface address %s\n",
4907 inet_ntoa(nbr
->address
.u
.prefix4
));
4911 json_object_string_add(json_sub
, "areaId",
4912 ospf_area_desc_string(oi
->area
));
4913 json_object_string_add(json_sub
, "ifaceName", oi
->ifp
->name
);
4915 vty_out(vty
, " In the area %s via interface %s\n",
4916 ospf_area_desc_string(oi
->area
), oi
->ifp
->name
);
4918 /* Show neighbor priority and state. */
4920 json_object_int_add(json_sub
, "nbrPriority", nbr
->priority
);
4921 json_object_string_add(
4922 json_sub
, "nbrState",
4923 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
4925 vty_out(vty
, " Neighbor priority is %d, State is %s,",
4927 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
4929 /* Show state changes. */
4931 json_object_int_add(json_sub
, "stateChangeCounter",
4934 vty_out(vty
, " %d state changes\n", nbr
->state_change
);
4936 if (nbr
->ts_last_progress
.tv_sec
|| nbr
->ts_last_progress
.tv_usec
) {
4941 monotime_since(&nbr
->ts_last_progress
, &res
) / 1000LL;
4943 json_object_int_add(json_sub
, "lastPrgrsvChangeMsec",
4947 " Most recent state change statistics:\n");
4948 vty_out(vty
, " Progressive change %s ago\n",
4949 ospf_timeval_dump(&res
, timebuf
,
4954 if (nbr
->ts_last_regress
.tv_sec
|| nbr
->ts_last_regress
.tv_usec
) {
4959 monotime_since(&nbr
->ts_last_regress
, &res
) / 1000LL;
4961 json_object_int_add(json_sub
,
4962 "lastRegressiveChangeMsec",
4964 if (nbr
->last_regress_str
)
4965 json_object_string_add(
4966 json_sub
, "lastRegressiveChangeReason",
4967 nbr
->last_regress_str
);
4970 " Regressive change %s ago, due to %s\n",
4971 ospf_timeval_dump(&res
, timebuf
,
4973 (nbr
->last_regress_str
? nbr
->last_regress_str
4978 /* Show Designated Rotuer ID. */
4980 json_object_string_add(json_sub
, "routerDesignatedId",
4981 inet_ntoa(nbr
->d_router
));
4983 vty_out(vty
, " DR is %s,", inet_ntoa(nbr
->d_router
));
4985 /* Show Backup Designated Rotuer ID. */
4987 json_object_string_add(json_sub
, "routerDesignatedBackupId",
4988 inet_ntoa(nbr
->bd_router
));
4990 vty_out(vty
, " BDR is %s\n", inet_ntoa(nbr
->bd_router
));
4994 json_object_int_add(json_sub
, "optionsCounter", nbr
->options
);
4995 json_object_string_add(json_sub
, "optionsList",
4996 ospf_options_dump(nbr
->options
));
4998 vty_out(vty
, " Options %d %s\n", nbr
->options
,
4999 ospf_options_dump(nbr
->options
));
5001 /* Show Router Dead interval timer. */
5003 if (nbr
->t_inactivity
) {
5005 time_store
= monotime_until(&nbr
->t_inactivity
->u
.sands
,
5008 json_object_int_add(json_sub
,
5009 "routerDeadIntervalTimerDueMsec",
5012 json_object_int_add(
5013 json_sub
, "routerDeadIntervalTimerDueMsec", -1);
5015 vty_out(vty
, " Dead timer due in %s\n",
5016 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
5019 /* Show Database Summary list. */
5021 json_object_int_add(json_sub
, "databaseSummaryListCounter",
5022 ospf_db_summary_count(nbr
));
5024 vty_out(vty
, " Database Summary List %d\n",
5025 ospf_db_summary_count(nbr
));
5027 /* Show Link State Request list. */
5029 json_object_int_add(json_sub
, "linkStateRequestListCounter",
5030 ospf_ls_request_count(nbr
));
5032 vty_out(vty
, " Link State Request List %ld\n",
5033 ospf_ls_request_count(nbr
));
5035 /* Show Link State Retransmission list. */
5037 json_object_int_add(json_sub
,
5038 "linkStateRetransmissionListCounter",
5039 ospf_ls_retransmit_count(nbr
));
5041 vty_out(vty
, " Link State Retransmission List %ld\n",
5042 ospf_ls_retransmit_count(nbr
));
5044 /* Show inactivity timer thread. */
5046 if (nbr
->t_inactivity
!= NULL
)
5047 json_object_string_add(json_sub
,
5048 "threadInactivityTimer", "on");
5050 vty_out(vty
, " Thread Inactivity Timer %s\n",
5051 nbr
->t_inactivity
!= NULL
? "on" : "off");
5053 /* Show Database Description retransmission thread. */
5055 if (nbr
->t_db_desc
!= NULL
)
5056 json_object_string_add(
5058 "threadDatabaseDescriptionRetransmission",
5062 " Thread Database Description Retransmision %s\n",
5063 nbr
->t_db_desc
!= NULL
? "on" : "off");
5065 /* Show Link State Request Retransmission thread. */
5067 if (nbr
->t_ls_req
!= NULL
)
5068 json_object_string_add(
5070 "threadLinkStateRequestRetransmission", "on");
5073 " Thread Link State Request Retransmission %s\n",
5074 nbr
->t_ls_req
!= NULL
? "on" : "off");
5076 /* Show Link State Update Retransmission thread. */
5078 if (nbr
->t_ls_upd
!= NULL
)
5079 json_object_string_add(
5080 json_sub
, "threadLinkStateUpdateRetransmission",
5084 " Thread Link State Update Retransmission %s\n\n",
5085 nbr
->t_ls_upd
!= NULL
? "on" : "off");
5088 if (nbr
->state
== NSM_Attempt
&& nbr
->router_id
.s_addr
== 0)
5089 json_object_object_add(json
, "noNbrId", json_sub
);
5091 json_object_object_add(json
, inet_ntoa(nbr
->router_id
),
5095 ospf_bfd_show_info(vty
, nbr
->bfd_info
, json
, use_json
, 0);
5098 static int show_ip_ospf_neighbor_id_common(struct vty
*vty
, struct ospf
*ospf
,
5099 struct in_addr
*router_id
,
5100 bool use_json
, uint8_t use_vrf
)
5102 struct listnode
*node
;
5103 struct ospf_neighbor
*nbr
;
5104 struct ospf_interface
*oi
;
5105 json_object
*json
= NULL
;
5108 json
= json_object_new_object();
5110 if (ospf
->instance
) {
5112 json_object_int_add(json
, "ospfInstance",
5115 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5118 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
5120 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5121 if ((nbr
= ospf_nbr_lookup_by_routerid(oi
->nbrs
, router_id
))) {
5122 show_ip_ospf_neighbor_detail_sub(vty
, oi
, nbr
, json
,
5128 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5129 json
, JSON_C_TO_STRING_PRETTY
));
5130 json_object_free(json
);
5137 DEFPY (show_ip_ospf_neighbor_id
,
5138 show_ip_ospf_neighbor_id_cmd
,
5139 "show ip ospf neighbor A.B.C.D$router_id [json$json]",
5142 "OSPF information\n"
5148 struct listnode
*node
;
5149 int ret
= CMD_SUCCESS
;
5151 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5152 if (!ospf
->oi_running
)
5154 ret
= show_ip_ospf_neighbor_id_common(vty
, ospf
, &router_id
,
5161 DEFPY (show_ip_ospf_instance_neighbor_id
,
5162 show_ip_ospf_instance_neighbor_id_cmd
,
5163 "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [json$json]",
5166 "OSPF information\n"
5174 ospf
= ospf_lookup_instance(instance
);
5176 return CMD_NOT_MY_INSTANCE
;
5178 if (!ospf
->oi_running
)
5181 return show_ip_ospf_neighbor_id_common(vty
, ospf
, &router_id
, !!json
,
5185 static int show_ip_ospf_neighbor_detail_common(struct vty
*vty
,
5187 json_object
*json
, bool use_json
,
5190 struct ospf_interface
*oi
;
5191 struct listnode
*node
;
5192 json_object
*json_vrf
= NULL
;
5196 json_vrf
= json_object_new_object();
5200 if (ospf
->instance
) {
5202 json_object_int_add(json_vrf
, "ospfInstance",
5205 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5208 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5210 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5211 struct route_node
*rn
;
5212 struct ospf_neighbor
*nbr
;
5214 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5215 if ((nbr
= rn
->info
)) {
5216 if (nbr
!= oi
->nbr_self
) {
5217 if (nbr
->state
!= NSM_Down
) {
5218 show_ip_ospf_neighbor_detail_sub(
5219 vty
, oi
, nbr
, json_vrf
,
5229 if (ospf
->vrf_id
== VRF_DEFAULT
)
5230 json_object_object_add(json
, "default",
5233 json_object_object_add(json
, ospf
->name
,
5242 DEFUN (show_ip_ospf_neighbor_detail
,
5243 show_ip_ospf_neighbor_detail_cmd
,
5244 "show ip ospf [vrf <NAME|all>] neighbor detail [json]",
5247 "OSPF information\n"
5251 "detail of all neighbors\n"
5255 bool uj
= use_json(argc
, argv
);
5256 struct listnode
*node
= NULL
;
5257 char *vrf_name
= NULL
;
5258 bool all_vrf
= FALSE
;
5259 int ret
= CMD_SUCCESS
;
5262 uint8_t use_vrf
= 0;
5263 json_object
*json
= NULL
;
5265 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5268 json
= json_object_new_object();
5270 /* vrf input is provided could be all or specific vrf*/
5274 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5275 if (!ospf
->oi_running
)
5277 ret
= show_ip_ospf_neighbor_detail_common(
5278 vty
, ospf
, json
, uj
, use_vrf
);
5281 vty_out(vty
, "%s\n",
5282 json_object_to_json_string_ext(
5283 json
, JSON_C_TO_STRING_PRETTY
));
5284 json_object_free(json
);
5289 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5290 if (ospf
== NULL
|| !ospf
->oi_running
) {
5292 json_object_free(json
);
5296 /* Display default ospf (instance 0) info */
5297 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5298 if (ospf
== NULL
|| !ospf
->oi_running
) {
5300 json_object_free(json
);
5306 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
,
5309 vty_out(vty
, "%s\n",
5310 json_object_to_json_string_ext(
5311 json
, JSON_C_TO_STRING_PRETTY
));
5316 json_object_free(json
);
5321 DEFUN (show_ip_ospf_instance_neighbor_detail
,
5322 show_ip_ospf_instance_neighbor_detail_cmd
,
5323 "show ip ospf (1-65535) neighbor detail [json]",
5326 "OSPF information\n"
5329 "detail of all neighbors\n"
5334 unsigned short instance
= 0;
5335 bool uj
= use_json(argc
, argv
);
5336 json_object
*json
= NULL
;
5337 int ret
= CMD_SUCCESS
;
5339 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5340 ospf
= ospf_lookup_instance(instance
);
5342 return CMD_NOT_MY_INSTANCE
;
5344 if (!ospf
->oi_running
)
5348 json
= json_object_new_object();
5350 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
, 0);
5353 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5354 json
, JSON_C_TO_STRING_PRETTY
));
5355 json_object_free(json
);
5361 static int show_ip_ospf_neighbor_detail_all_common(struct vty
*vty
,
5367 struct listnode
*node
;
5368 struct ospf_interface
*oi
;
5369 json_object
*json_vrf
= NULL
;
5373 json_vrf
= json_object_new_object();
5378 if (ospf
->instance
) {
5380 json_object_int_add(json
, "ospfInstance",
5383 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5386 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5388 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5389 struct route_node
*rn
;
5390 struct ospf_neighbor
*nbr
;
5391 struct ospf_nbr_nbma
*nbr_nbma
;
5393 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
5394 if ((nbr
= rn
->info
))
5395 if (nbr
!= oi
->nbr_self
)
5396 if (nbr
->state
!= NSM_Down
)
5397 show_ip_ospf_neighbor_detail_sub(
5399 json_vrf
, use_json
);
5401 if (oi
->type
== OSPF_IFTYPE_NBMA
) {
5402 struct listnode
*nd
;
5404 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nd
, nbr_nbma
)) {
5405 if (nbr_nbma
->nbr
== NULL
5406 || nbr_nbma
->nbr
->state
== NSM_Down
)
5407 show_ip_ospf_nbr_nbma_detail_sub(
5408 vty
, oi
, nbr_nbma
, use_json
,
5416 if (ospf
->vrf_id
== VRF_DEFAULT
)
5417 json_object_object_add(json
, "default",
5420 json_object_object_add(json
, ospf
->name
,
5430 DEFUN (show_ip_ospf_neighbor_detail_all
,
5431 show_ip_ospf_neighbor_detail_all_cmd
,
5432 "show ip ospf [vrf <NAME|all>] neighbor detail all [json]",
5435 "OSPF information\n"
5439 "detail of all neighbors\n"
5440 "include down status neighbor\n"
5444 bool uj
= use_json(argc
, argv
);
5445 struct listnode
*node
= NULL
;
5446 char *vrf_name
= NULL
;
5447 bool all_vrf
= FALSE
;
5448 int ret
= CMD_SUCCESS
;
5451 uint8_t use_vrf
= 0;
5452 json_object
*json
= NULL
;
5454 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5457 json
= json_object_new_object();
5459 /* vrf input is provided could be all or specific vrf*/
5463 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5464 if (!ospf
->oi_running
)
5466 ret
= show_ip_ospf_neighbor_detail_all_common(
5467 vty
, ospf
, json
, uj
, use_vrf
);
5471 vty_out(vty
, "%s\n",
5472 json_object_to_json_string_ext(
5473 json
, JSON_C_TO_STRING_PRETTY
));
5474 json_object_free(json
);
5479 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5480 if (ospf
== NULL
|| !ospf
->oi_running
) {
5482 json_object_free(json
);
5486 /* Display default ospf (instance 0) info */
5487 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5488 if (ospf
== NULL
|| !ospf
->oi_running
) {
5490 json_object_free(json
);
5496 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
,
5499 vty_out(vty
, "%s\n",
5500 json_object_to_json_string_ext(
5501 json
, JSON_C_TO_STRING_PRETTY
));
5506 json_object_free(json
);
5511 DEFUN (show_ip_ospf_instance_neighbor_detail_all
,
5512 show_ip_ospf_instance_neighbor_detail_all_cmd
,
5513 "show ip ospf (1-65535) neighbor detail all [json]",
5516 "OSPF information\n"
5519 "detail of all neighbors\n"
5520 "include down status neighbor\n"
5525 unsigned short instance
= 0;
5526 bool uj
= use_json(argc
, argv
);
5527 json_object
*json
= NULL
;
5528 int ret
= CMD_SUCCESS
;
5530 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5531 ospf
= ospf_lookup_instance(instance
);
5533 return CMD_NOT_MY_INSTANCE
;
5535 if (!ospf
->oi_running
)
5539 json
= json_object_new_object();
5541 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
, uj
, 0);
5544 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5545 json
, JSON_C_TO_STRING_PRETTY
));
5546 json_object_free(json
);
5552 static int show_ip_ospf_neighbor_int_detail_common(struct vty
*vty
,
5555 struct cmd_token
**argv
,
5558 struct ospf_interface
*oi
;
5559 struct interface
*ifp
;
5560 struct route_node
*rn
, *nrn
;
5561 struct ospf_neighbor
*nbr
;
5562 json_object
*json
= NULL
;
5565 json
= json_object_new_object();
5567 if (ospf
->instance
) {
5569 json_object_int_add(json
, "ospfInstance",
5572 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5575 ifp
= if_lookup_by_name(argv
[arg_base
]->arg
, ospf
->vrf_id
);
5578 vty_out(vty
, "No such interface.\n");
5580 vty_out(vty
, "{}\n");
5581 json_object_free(json
);
5586 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
5587 if ((oi
= rn
->info
)) {
5588 for (nrn
= route_top(oi
->nbrs
); nrn
;
5589 nrn
= route_next(nrn
)) {
5590 if ((nbr
= nrn
->info
)) {
5591 if (nbr
!= oi
->nbr_self
) {
5592 if (nbr
->state
!= NSM_Down
)
5593 show_ip_ospf_neighbor_detail_sub(
5603 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5604 json
, JSON_C_TO_STRING_PRETTY
));
5605 json_object_free(json
);
5612 DEFUN (show_ip_ospf_neighbor_int_detail
,
5613 show_ip_ospf_neighbor_int_detail_cmd
,
5614 "show ip ospf neighbor IFNAME detail [json]",
5617 "OSPF information\n"
5620 "detail of all neighbors\n"
5624 bool uj
= use_json(argc
, argv
);
5625 struct listnode
*node
= NULL
;
5626 int ret
= CMD_SUCCESS
;
5627 bool ospf_output
= FALSE
;
5629 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5630 if (!ospf
->oi_running
)
5633 ret
= show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, 0,
5638 vty_out(vty
, "%% OSPF instance not found\n");
5643 DEFUN (show_ip_ospf_instance_neighbor_int_detail
,
5644 show_ip_ospf_instance_neighbor_int_detail_cmd
,
5645 "show ip ospf (1-65535) neighbor IFNAME detail [json]",
5648 "OSPF information\n"
5652 "detail of all neighbors\n"
5658 unsigned short instance
= 0;
5659 bool uj
= use_json(argc
, argv
);
5661 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5662 ospf
= ospf_lookup_instance(instance
);
5664 return CMD_NOT_MY_INSTANCE
;
5666 if (!ospf
->oi_running
)
5669 return show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, idx_ifname
,
5673 /* Show functions */
5674 static int show_lsa_summary(struct vty
*vty
, struct ospf_lsa
*lsa
, int self
)
5676 struct router_lsa
*rl
;
5677 struct summary_lsa
*sl
;
5678 struct as_external_lsa
*asel
;
5679 struct prefix_ipv4 p
;
5682 /* If self option is set, check LSA self flag. */
5683 if (self
== 0 || IS_LSA_SELF(lsa
)) {
5684 /* LSA common part show. */
5685 vty_out(vty
, "%-15s ", inet_ntoa(lsa
->data
->id
));
5686 vty_out(vty
, "%-15s %4d 0x%08lx 0x%04x",
5687 inet_ntoa(lsa
->data
->adv_router
), LS_AGE(lsa
),
5688 (unsigned long)ntohl(lsa
->data
->ls_seqnum
),
5689 ntohs(lsa
->data
->checksum
));
5690 /* LSA specific part show. */
5691 switch (lsa
->data
->type
) {
5692 case OSPF_ROUTER_LSA
:
5693 rl
= (struct router_lsa
*)lsa
->data
;
5694 vty_out(vty
, " %-d", ntohs(rl
->links
));
5696 case OSPF_SUMMARY_LSA
:
5697 sl
= (struct summary_lsa
*)lsa
->data
;
5700 p
.prefix
= sl
->header
.id
;
5701 p
.prefixlen
= ip_masklen(sl
->mask
);
5702 apply_mask_ipv4(&p
);
5704 vty_out(vty
, " %s/%d", inet_ntoa(p
.prefix
),
5707 case OSPF_AS_EXTERNAL_LSA
:
5708 case OSPF_AS_NSSA_LSA
:
5709 asel
= (struct as_external_lsa
*)lsa
->data
;
5712 p
.prefix
= asel
->header
.id
;
5713 p
.prefixlen
= ip_masklen(asel
->mask
);
5714 apply_mask_ipv4(&p
);
5716 vty_out(vty
, " %s %s/%d [0x%lx]",
5717 IS_EXTERNAL_METRIC(asel
->e
[0].tos
)
5720 inet_ntoa(p
.prefix
), p
.prefixlen
,
5721 (unsigned long)ntohl(
5722 asel
->e
[0].route_tag
));
5724 case OSPF_NETWORK_LSA
:
5725 case OSPF_ASBR_SUMMARY_LSA
:
5726 case OSPF_OPAQUE_LINK_LSA
:
5727 case OSPF_OPAQUE_AREA_LSA
:
5728 case OSPF_OPAQUE_AS_LSA
:
5738 static const char *show_database_desc
[] = {
5740 "Router Link States",
5742 "Summary Link States",
5743 "ASBR-Summary Link States",
5744 "AS External Link States",
5745 "Group Membership LSA",
5746 "NSSA-external Link States",
5748 "Link-Local Opaque-LSA",
5749 "Area-Local Opaque-LSA",
5750 "AS-external Opaque-LSA",
5753 static const char *show_database_header
[] = {
5755 "Link ID ADV Router Age Seq# CkSum Link count",
5756 "Link ID ADV Router Age Seq# CkSum",
5757 "Link ID ADV Router Age Seq# CkSum Route",
5758 "Link ID ADV Router Age Seq# CkSum",
5759 "Link ID ADV Router Age Seq# CkSum Route",
5760 " --- header for Group Member ----",
5761 "Link ID ADV Router Age Seq# CkSum Route",
5763 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5764 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5765 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5768 static void show_ip_ospf_database_header(struct vty
*vty
, struct ospf_lsa
*lsa
)
5770 struct router_lsa
*rlsa
= (struct router_lsa
*)lsa
->data
;
5772 vty_out(vty
, " LS age: %d\n", LS_AGE(lsa
));
5773 vty_out(vty
, " Options: 0x%-2x : %s\n", lsa
->data
->options
,
5774 ospf_options_dump(lsa
->data
->options
));
5775 vty_out(vty
, " LS Flags: 0x%-2x %s\n", lsa
->flags
,
5776 ((lsa
->flags
& OSPF_LSA_LOCAL_XLT
) ? "(Translated from Type-7)"
5779 if (lsa
->data
->type
== OSPF_ROUTER_LSA
) {
5780 vty_out(vty
, " Flags: 0x%x", rlsa
->flags
);
5783 vty_out(vty
, " :%s%s%s%s",
5784 IS_ROUTER_LSA_BORDER(rlsa
) ? " ABR" : "",
5785 IS_ROUTER_LSA_EXTERNAL(rlsa
) ? " ASBR" : "",
5786 IS_ROUTER_LSA_VIRTUAL(rlsa
) ? " VL-endpoint"
5788 IS_ROUTER_LSA_SHORTCUT(rlsa
) ? " Shortcut"
5793 vty_out(vty
, " LS Type: %s\n",
5794 lookup_msg(ospf_lsa_type_msg
, lsa
->data
->type
, NULL
));
5795 vty_out(vty
, " Link State ID: %s %s\n", inet_ntoa(lsa
->data
->id
),
5796 lookup_msg(ospf_link_state_id_type_msg
, lsa
->data
->type
, NULL
));
5797 vty_out(vty
, " Advertising Router: %s\n",
5798 inet_ntoa(lsa
->data
->adv_router
));
5799 vty_out(vty
, " LS Seq Number: %08lx\n",
5800 (unsigned long)ntohl(lsa
->data
->ls_seqnum
));
5801 vty_out(vty
, " Checksum: 0x%04x\n", ntohs(lsa
->data
->checksum
));
5802 vty_out(vty
, " Length: %d\n\n", ntohs(lsa
->data
->length
));
5805 const char *link_type_desc
[] = {
5807 "another Router (point-to-point)",
5808 "a Transit Network",
5813 const char *link_id_desc
[] = {
5814 "(null)", "Neighboring Router ID", "Designated Router address",
5815 "Net", "Neighboring Router ID",
5818 const char *link_data_desc
[] = {
5819 "(null)", "Router Interface address", "Router Interface address",
5820 "Network Mask", "Router Interface address",
5823 /* Show router-LSA each Link information. */
5824 static void show_ip_ospf_database_router_links(struct vty
*vty
,
5825 struct router_lsa
*rl
)
5830 len
= ntohs(rl
->header
.length
) - 4;
5831 for (i
= 0; i
< ntohs(rl
->links
) && len
> 0; len
-= 12, i
++) {
5832 type
= rl
->link
[i
].type
;
5834 vty_out(vty
, " Link connected to: %s\n",
5835 link_type_desc
[type
]);
5836 vty_out(vty
, " (Link ID) %s: %s\n", link_id_desc
[type
],
5837 inet_ntoa(rl
->link
[i
].link_id
));
5838 vty_out(vty
, " (Link Data) %s: %s\n", link_data_desc
[type
],
5839 inet_ntoa(rl
->link
[i
].link_data
));
5840 vty_out(vty
, " Number of TOS metrics: 0\n");
5841 vty_out(vty
, " TOS 0 Metric: %d\n",
5842 ntohs(rl
->link
[i
].metric
));
5847 /* Show router-LSA detail information. */
5848 static int show_router_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5851 struct router_lsa
*rl
= (struct router_lsa
*)lsa
->data
;
5853 show_ip_ospf_database_header(vty
, lsa
);
5855 vty_out(vty
, " Number of Links: %d\n\n", ntohs(rl
->links
));
5857 show_ip_ospf_database_router_links(vty
, rl
);
5864 /* Show network-LSA detail information. */
5865 static int show_network_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5870 struct network_lsa
*nl
= (struct network_lsa
*)lsa
->data
;
5872 show_ip_ospf_database_header(vty
, lsa
);
5874 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(nl
->mask
));
5876 length
= ntohs(lsa
->data
->length
) - OSPF_LSA_HEADER_SIZE
- 4;
5878 for (i
= 0; length
> 0; i
++, length
-= 4)
5879 vty_out(vty
, " Attached Router: %s\n",
5880 inet_ntoa(nl
->routers
[i
]));
5888 /* Show summary-LSA detail information. */
5889 static int show_summary_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5892 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
5894 show_ip_ospf_database_header(vty
, lsa
);
5896 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(sl
->mask
));
5897 vty_out(vty
, " TOS: 0 Metric: %d\n",
5898 GET_METRIC(sl
->metric
));
5905 /* Show summary-ASBR-LSA detail information. */
5906 static int show_summary_asbr_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5909 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
5911 show_ip_ospf_database_header(vty
, lsa
);
5913 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(sl
->mask
));
5914 vty_out(vty
, " TOS: 0 Metric: %d\n",
5915 GET_METRIC(sl
->metric
));
5922 /* Show AS-external-LSA detail information. */
5923 static int show_as_external_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5926 struct as_external_lsa
*al
=
5927 (struct as_external_lsa
*)lsa
->data
;
5929 show_ip_ospf_database_header(vty
, lsa
);
5931 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(al
->mask
));
5932 vty_out(vty
, " Metric Type: %s\n",
5933 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
5934 ? "2 (Larger than any link state path)"
5936 vty_out(vty
, " TOS: 0\n");
5937 vty_out(vty
, " Metric: %d\n",
5938 GET_METRIC(al
->e
[0].metric
));
5939 vty_out(vty
, " Forward Address: %s\n",
5940 inet_ntoa(al
->e
[0].fwd_addr
));
5943 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
5944 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
5951 show_as_external_lsa_stdvty (struct ospf_lsa
*lsa
)
5953 struct as_external_lsa
*al
= (struct as_external_lsa
*) lsa
->data
;
5955 /* show_ip_ospf_database_header (vty, lsa); */
5957 zlog_debug( " Network Mask: /%d%s",
5958 ip_masklen (al
->mask
), "\n");
5959 zlog_debug( " Metric Type: %s%s",
5960 IS_EXTERNAL_METRIC (al
->e
[0].tos
) ?
5961 "2 (Larger than any link state path)" : "1", "\n");
5962 zlog_debug( " TOS: 0%s", "\n");
5963 zlog_debug( " Metric: %d%s",
5964 GET_METRIC (al
->e
[0].metric
), "\n");
5965 zlog_debug( " Forward Address: %s%s",
5966 inet_ntoa (al
->e
[0].fwd_addr
), "\n");
5968 zlog_debug( " External Route Tag: %"ROUTE_TAG_PRI
"%s%s",
5969 (route_tag_t
)ntohl (al
->e
[0].route_tag
), "\n", "\n");
5974 /* Show AS-NSSA-LSA detail information. */
5975 static int show_as_nssa_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5978 struct as_external_lsa
*al
=
5979 (struct as_external_lsa
*)lsa
->data
;
5981 show_ip_ospf_database_header(vty
, lsa
);
5983 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(al
->mask
));
5984 vty_out(vty
, " Metric Type: %s\n",
5985 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
5986 ? "2 (Larger than any link state path)"
5988 vty_out(vty
, " TOS: 0\n");
5989 vty_out(vty
, " Metric: %d\n",
5990 GET_METRIC(al
->e
[0].metric
));
5991 vty_out(vty
, " NSSA: Forward Address: %s\n",
5992 inet_ntoa(al
->e
[0].fwd_addr
));
5995 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
5996 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6002 static int show_func_dummy(struct vty
*vty
, struct ospf_lsa
*lsa
)
6007 static int show_opaque_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
6010 show_ip_ospf_database_header(vty
, lsa
);
6011 show_opaque_info_detail(vty
, lsa
);
6018 int (*show_function
[])(struct vty
*, struct ospf_lsa
*) = {
6020 show_router_lsa_detail
,
6021 show_network_lsa_detail
,
6022 show_summary_lsa_detail
,
6023 show_summary_asbr_lsa_detail
,
6024 show_as_external_lsa_detail
,
6026 show_as_nssa_lsa_detail
, /* almost same as external */
6028 show_opaque_lsa_detail
,
6029 show_opaque_lsa_detail
,
6030 show_opaque_lsa_detail
,
6033 static void show_lsa_prefix_set(struct vty
*vty
, struct prefix_ls
*lp
,
6034 struct in_addr
*id
, struct in_addr
*adv_router
)
6036 memset(lp
, 0, sizeof(struct prefix_ls
));
6040 else if (adv_router
== NULL
) {
6046 lp
->adv_router
= *adv_router
;
6050 static void show_lsa_detail_proc(struct vty
*vty
, struct route_table
*rt
,
6051 struct in_addr
*id
, struct in_addr
*adv_router
)
6053 struct prefix_ls lp
;
6054 struct route_node
*rn
, *start
;
6055 struct ospf_lsa
*lsa
;
6057 show_lsa_prefix_set(vty
, &lp
, id
, adv_router
);
6058 start
= route_node_get(rt
, (struct prefix
*)&lp
);
6060 route_lock_node(start
);
6061 for (rn
= start
; rn
; rn
= route_next_until(rn
, start
))
6062 if ((lsa
= rn
->info
)) {
6063 if (show_function
[lsa
->data
->type
] != NULL
)
6064 show_function
[lsa
->data
->type
](vty
,
6067 route_unlock_node(start
);
6071 /* Show detail LSA information
6072 -- if id is NULL then show all LSAs. */
6073 static void show_lsa_detail(struct vty
*vty
, struct ospf
*ospf
, int type
,
6074 struct in_addr
*id
, struct in_addr
*adv_router
)
6076 struct listnode
*node
;
6077 struct ospf_area
*area
;
6080 case OSPF_AS_EXTERNAL_LSA
:
6081 case OSPF_OPAQUE_AS_LSA
:
6082 vty_out(vty
, " %s \n\n",
6083 show_database_desc
[type
]);
6084 show_lsa_detail_proc(vty
, AS_LSDB(ospf
, type
), id
, adv_router
);
6087 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6088 vty_out(vty
, "\n %s (Area %s)\n\n",
6089 show_database_desc
[type
],
6090 ospf_area_desc_string(area
));
6091 show_lsa_detail_proc(vty
, AREA_LSDB(area
, type
), id
,
6098 static void show_lsa_detail_adv_router_proc(struct vty
*vty
,
6099 struct route_table
*rt
,
6100 struct in_addr
*adv_router
)
6102 struct route_node
*rn
;
6103 struct ospf_lsa
*lsa
;
6105 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
))
6106 if ((lsa
= rn
->info
))
6107 if (IPV4_ADDR_SAME(adv_router
,
6108 &lsa
->data
->adv_router
)) {
6109 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
6111 if (show_function
[lsa
->data
->type
] != NULL
)
6112 show_function
[lsa
->data
->type
](vty
,
6117 /* Show detail LSA information. */
6118 static void show_lsa_detail_adv_router(struct vty
*vty
, struct ospf
*ospf
,
6119 int type
, struct in_addr
*adv_router
)
6121 struct listnode
*node
;
6122 struct ospf_area
*area
;
6125 case OSPF_AS_EXTERNAL_LSA
:
6126 case OSPF_OPAQUE_AS_LSA
:
6127 vty_out(vty
, " %s \n\n",
6128 show_database_desc
[type
]);
6129 show_lsa_detail_adv_router_proc(vty
, AS_LSDB(ospf
, type
),
6133 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6134 vty_out(vty
, "\n %s (Area %s)\n\n",
6135 show_database_desc
[type
],
6136 ospf_area_desc_string(area
));
6137 show_lsa_detail_adv_router_proc(
6138 vty
, AREA_LSDB(area
, type
), adv_router
);
6144 static void show_ip_ospf_database_summary(struct vty
*vty
, struct ospf
*ospf
,
6147 struct ospf_lsa
*lsa
;
6148 struct route_node
*rn
;
6149 struct ospf_area
*area
;
6150 struct listnode
*node
;
6153 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6154 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6156 case OSPF_AS_EXTERNAL_LSA
:
6157 case OSPF_OPAQUE_AS_LSA
:
6162 if (ospf_lsdb_count_self(area
->lsdb
, type
) > 0
6164 && ospf_lsdb_count(area
->lsdb
, type
) > 0)) {
6165 vty_out(vty
, " %s (Area %s)\n\n",
6166 show_database_desc
[type
],
6167 ospf_area_desc_string(area
));
6168 vty_out(vty
, "%s\n",
6169 show_database_header
[type
]);
6171 LSDB_LOOP (AREA_LSDB(area
, type
), rn
, lsa
)
6172 show_lsa_summary(vty
, lsa
, self
);
6179 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6181 case OSPF_AS_EXTERNAL_LSA
:
6182 case OSPF_OPAQUE_AS_LSA
:
6187 if (ospf_lsdb_count_self(ospf
->lsdb
, type
)
6188 || (!self
&& ospf_lsdb_count(ospf
->lsdb
, type
))) {
6189 vty_out(vty
, " %s\n\n",
6190 show_database_desc
[type
]);
6191 vty_out(vty
, "%s\n", show_database_header
[type
]);
6193 LSDB_LOOP (AS_LSDB(ospf
, type
), rn
, lsa
)
6194 show_lsa_summary(vty
, lsa
, self
);
6203 static void show_ip_ospf_database_maxage(struct vty
*vty
, struct ospf
*ospf
)
6205 struct route_node
*rn
;
6207 vty_out(vty
, "\n MaxAge Link States:\n\n");
6209 for (rn
= route_top(ospf
->maxage_lsa
); rn
; rn
= route_next(rn
)) {
6210 struct ospf_lsa
*lsa
;
6212 if ((lsa
= rn
->info
) != NULL
) {
6213 vty_out(vty
, "Link type: %d\n", lsa
->data
->type
);
6214 vty_out(vty
, "Link State ID: %s\n",
6215 inet_ntoa(lsa
->data
->id
));
6216 vty_out(vty
, "Advertising Router: %s\n",
6217 inet_ntoa(lsa
->data
->adv_router
));
6218 vty_out(vty
, "LSA lock count: %d\n", lsa
->lock
);
6224 #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
6225 #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
6227 #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
6228 #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
6229 #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
6230 #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
6232 #define OSPF_LSA_TYPES_DESC \
6233 "ASBR summary link states\n" \
6234 "External link states\n" \
6235 "Network link states\n" \
6236 "Router link states\n" \
6237 "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \
6238 OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
6239 OSPF_LSA_TYPE_OPAQUE_AS_DESC
6241 static int show_ip_ospf_database_common(struct vty
*vty
, struct ospf
*ospf
,
6242 int arg_base
, int argc
,
6243 struct cmd_token
**argv
,
6248 struct in_addr id
, adv_router
;
6251 vty_out(vty
, "\nOSPF Instance: %d\n", ospf
->instance
);
6253 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
6255 vty_out(vty
, "\n OSPF Router with ID (%s)\n\n",
6256 inet_ntoa(ospf
->router_id
));
6259 if (argc
== arg_base
+ 4) {
6260 show_ip_ospf_database_summary(vty
, ospf
, 0);
6264 /* Set database type to show. */
6265 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
6266 type
= OSPF_ROUTER_LSA
;
6267 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
6268 type
= OSPF_NETWORK_LSA
;
6269 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
6270 type
= OSPF_AS_NSSA_LSA
;
6271 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "su", 2) == 0)
6272 type
= OSPF_SUMMARY_LSA
;
6273 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
6274 type
= OSPF_ASBR_SUMMARY_LSA
;
6275 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
6276 type
= OSPF_AS_EXTERNAL_LSA
;
6277 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "se", 2) == 0) {
6278 show_ip_ospf_database_summary(vty
, ospf
, 1);
6280 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "m", 1) == 0) {
6281 show_ip_ospf_database_maxage(vty
, ospf
);
6283 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
6284 type
= OSPF_OPAQUE_LINK_LSA
;
6285 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
6286 type
= OSPF_OPAQUE_AREA_LSA
;
6287 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
6288 type
= OSPF_OPAQUE_AS_LSA
;
6292 /* `show ip ospf database LSA'. */
6293 if (argc
== arg_base
+ 5)
6294 show_lsa_detail(vty
, ospf
, type
, NULL
, NULL
);
6295 else if (argc
>= arg_base
+ 6) {
6296 ret
= inet_aton(argv
[arg_base
+ 5]->arg
, &id
);
6300 /* `show ip ospf database LSA ID'. */
6301 if (argc
== arg_base
+ 6)
6302 show_lsa_detail(vty
, ospf
, type
, &id
, NULL
);
6303 /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */
6304 else if (argc
== arg_base
+ 7) {
6305 if (strncmp(argv
[arg_base
+ 6]->text
, "s", 1) == 0)
6306 adv_router
= ospf
->router_id
;
6308 ret
= inet_aton(argv
[arg_base
+ 7]->arg
,
6313 show_lsa_detail(vty
, ospf
, type
, &id
, &adv_router
);
6320 DEFUN (show_ip_ospf_database_max
,
6321 show_ip_ospf_database_max_cmd
,
6322 "show ip ospf [vrf <NAME|all>] database <max-age|self-originate>",
6325 "OSPF information\n"
6328 "Database summary\n"
6329 "LSAs in MaxAge list\n"
6330 "Self-originated link states\n")
6332 struct ospf
*ospf
= NULL
;
6333 struct listnode
*node
= NULL
;
6334 char *vrf_name
= NULL
;
6335 bool all_vrf
= FALSE
;
6336 int ret
= CMD_SUCCESS
;
6339 uint8_t use_vrf
= 0;
6341 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
6344 bool ospf_output
= FALSE
;
6349 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6350 if (!ospf
->oi_running
)
6353 ret
= show_ip_ospf_database_common(
6354 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
,
6359 vty_out(vty
, "%% OSPF instance not found\n");
6361 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6362 if (ospf
== NULL
|| !ospf
->oi_running
) {
6363 vty_out(vty
, "%% OSPF instance not found\n");
6366 ret
= (show_ip_ospf_database_common(
6367 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
,
6371 /* Display default ospf (instance 0) info */
6372 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6373 if (ospf
== NULL
|| !ospf
->oi_running
) {
6374 vty_out(vty
, "%% OSPF instance not found\n");
6378 ret
= show_ip_ospf_database_common(vty
, ospf
, 0, argc
, argv
,
6385 DEFUN (show_ip_ospf_instance_database
,
6386 show_ip_ospf_instance_database_cmd
,
6387 "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>]]]",
6390 "OSPF information\n"
6393 "Database summary\n"
6395 "Link State ID (as an IP address)\n"
6396 "Self-originated link states\n"
6397 "Advertising Router link states\n"
6398 "Advertising Router (as an IP address)\n")
6401 unsigned short instance
= 0;
6402 struct listnode
*node
= NULL
;
6403 char *vrf_name
= NULL
;
6404 bool all_vrf
= FALSE
;
6405 int ret
= CMD_SUCCESS
;
6408 uint8_t use_vrf
= 0;
6410 if (argv_find(argv
, argc
, "(1-65535)", &idx
)) {
6411 instance
= strtoul(argv
[idx
]->arg
, NULL
, 10);
6412 ospf
= ospf_lookup_instance(instance
);
6414 return CMD_NOT_MY_INSTANCE
;
6415 if (!ospf
->oi_running
)
6418 return (show_ip_ospf_database_common(vty
, ospf
, idx
? 1 : 0,
6419 argc
, argv
, use_vrf
));
6420 } else if (argv_find(argv
, argc
, "vrf", &idx
)) {
6421 vrf_name
= argv
[++idx
]->arg
;
6422 all_vrf
= strmatch(vrf_name
, "all");
6428 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6429 if (!ospf
->oi_running
)
6431 ret
= (show_ip_ospf_database_common(
6432 vty
, ospf
, idx
? 2 : 0, argc
, argv
,
6436 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6437 if ((ospf
== NULL
) || !ospf
->oi_running
) {
6438 vty_out(vty
, "%% OSPF instance not found\n");
6442 ret
= (show_ip_ospf_database_common(
6443 vty
, ospf
, idx
? 2 : 0, argc
, argv
, use_vrf
));
6446 /* Display default ospf (instance 0) info */
6447 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6448 if (ospf
== NULL
|| !ospf
->oi_running
) {
6449 vty_out(vty
, "%% OSPF instance not found\n");
6453 ret
= (show_ip_ospf_database_common(vty
, ospf
, 0, argc
, argv
,
6460 DEFUN (show_ip_ospf_instance_database_max
,
6461 show_ip_ospf_instance_database_max_cmd
,
6462 "show ip ospf (1-65535) database <max-age|self-originate>",
6465 "OSPF information\n"
6467 "Database summary\n"
6468 "LSAs in MaxAge list\n"
6469 "Self-originated link states\n")
6473 unsigned short instance
= 0;
6475 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
6477 ospf
= ospf_lookup_instance(instance
);
6479 return CMD_NOT_MY_INSTANCE
;
6481 if (!ospf
->oi_running
) {
6482 vty_out(vty
, "%% OSPF instance not found\n");
6486 return show_ip_ospf_database_common(vty
, ospf
, 1, argc
, argv
, 0);
6490 static int show_ip_ospf_database_type_adv_router_common(struct vty
*vty
,
6492 int arg_base
, int argc
,
6493 struct cmd_token
**argv
,
6498 struct in_addr adv_router
;
6501 vty_out(vty
, "\nOSPF Instance: %d\n", ospf
->instance
);
6503 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
6505 vty_out(vty
, "\n OSPF Router with ID (%s)\n\n",
6506 inet_ntoa(ospf
->router_id
));
6508 /* Set database type to show. */
6509 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
6510 type
= OSPF_ROUTER_LSA
;
6511 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
6512 type
= OSPF_NETWORK_LSA
;
6513 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
6514 type
= OSPF_AS_NSSA_LSA
;
6515 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "s", 1) == 0)
6516 type
= OSPF_SUMMARY_LSA
;
6517 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
6518 type
= OSPF_ASBR_SUMMARY_LSA
;
6519 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
6520 type
= OSPF_AS_EXTERNAL_LSA
;
6521 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
6522 type
= OSPF_OPAQUE_LINK_LSA
;
6523 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
6524 type
= OSPF_OPAQUE_AREA_LSA
;
6525 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
6526 type
= OSPF_OPAQUE_AS_LSA
;
6530 /* `show ip ospf database LSA adv-router ADV_ROUTER'. */
6531 if (strncmp(argv
[arg_base
+ 5]->text
, "s", 1) == 0)
6532 adv_router
= ospf
->router_id
;
6534 ret
= inet_aton(argv
[arg_base
+ 6]->arg
, &adv_router
);
6539 show_lsa_detail_adv_router(vty
, ospf
, type
, &adv_router
);
6544 DEFUN (show_ip_ospf_instance_database_type_adv_router
,
6545 show_ip_ospf_instance_database_type_adv_router_cmd
,
6546 "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>",
6549 "OSPF information\n"
6552 "Database summary\n"
6554 "Advertising Router link states\n"
6555 "Advertising Router (as an IP address)\n"
6556 "Self-originated link states\n")
6558 struct ospf
*ospf
= NULL
;
6559 unsigned short instance
= 0;
6560 struct listnode
*node
= NULL
;
6561 char *vrf_name
= NULL
;
6562 bool all_vrf
= FALSE
;
6563 int ret
= CMD_SUCCESS
;
6565 int idx
= 0, idx_vrf
= 0;
6566 uint8_t use_vrf
= 0;
6568 if (argv_find(argv
, argc
, "(1-65535)", &idx
)) {
6569 instance
= strtoul(argv
[idx
]->arg
, NULL
, 10);
6570 ospf
= ospf_lookup_instance(instance
);
6572 return CMD_NOT_MY_INSTANCE
;
6573 if (!ospf
->oi_running
) {
6574 vty_out(vty
, "%% OSPF instance not found\n");
6578 return (show_ip_ospf_database_type_adv_router_common(
6579 vty
, ospf
, idx
? 1 : 0, argc
, argv
, use_vrf
));
6582 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
6585 bool ospf_output
= FALSE
;
6590 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6591 if (!ospf
->oi_running
)
6594 ret
= show_ip_ospf_database_type_adv_router_common(
6595 vty
, ospf
, idx
? 1 : 0, argc
, argv
,
6599 vty_out(vty
, "%% OSPF instance not found\n");
6601 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6602 if ((ospf
== NULL
) || !ospf
->oi_running
) {
6603 vty_out(vty
, "%% OSPF instance not found\n");
6607 ret
= show_ip_ospf_database_type_adv_router_common(
6608 vty
, ospf
, idx
? 1 : 0, argc
, argv
, use_vrf
);
6611 /* Display default ospf (instance 0) info */
6612 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6613 if (ospf
== NULL
|| !ospf
->oi_running
) {
6614 vty_out(vty
, "%% OSPF instance not found\n");
6618 ret
= show_ip_ospf_database_type_adv_router_common(
6619 vty
, ospf
, idx
? 1 : 0, argc
, argv
, use_vrf
);
6622 /*return (show_ip_ospf_database_type_adv_router_common(
6623 vty, ospf, idx ? 1 : 0, argc, argv));*/
6626 DEFUN (ip_ospf_authentication_args
,
6627 ip_ospf_authentication_args_addr_cmd
,
6628 "ip ospf authentication <null|message-digest> [A.B.C.D]",
6630 "OSPF interface commands\n"
6631 "Enable authentication on this interface\n"
6632 "Use null authentication\n"
6633 "Use message-digest authentication\n"
6634 "Address of interface\n")
6636 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6637 int idx_encryption
= 3;
6639 struct in_addr addr
;
6641 struct ospf_if_params
*params
;
6643 params
= IF_DEF_PARAMS(ifp
);
6646 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6649 "Please specify interface address by A.B.C.D\n");
6650 return CMD_WARNING_CONFIG_FAILED
;
6653 params
= ospf_get_if_params(ifp
, addr
);
6654 ospf_if_update_params(ifp
, addr
);
6657 /* Handle null authentication */
6658 if (argv
[idx_encryption
]->arg
[0] == 'n') {
6659 SET_IF_PARAM(params
, auth_type
);
6660 params
->auth_type
= OSPF_AUTH_NULL
;
6664 /* Handle message-digest authentication */
6665 if (argv
[idx_encryption
]->arg
[0] == 'm') {
6666 SET_IF_PARAM(params
, auth_type
);
6667 params
->auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
6671 vty_out(vty
, "You shouldn't get here!\n");
6672 return CMD_WARNING_CONFIG_FAILED
;
6675 DEFUN (ip_ospf_authentication
,
6676 ip_ospf_authentication_addr_cmd
,
6677 "ip ospf authentication [A.B.C.D]",
6679 "OSPF interface commands\n"
6680 "Enable authentication on this interface\n"
6681 "Address of interface\n")
6683 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6685 struct in_addr addr
;
6687 struct ospf_if_params
*params
;
6689 params
= IF_DEF_PARAMS(ifp
);
6692 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6695 "Please specify interface address by A.B.C.D\n");
6696 return CMD_WARNING_CONFIG_FAILED
;
6699 params
= ospf_get_if_params(ifp
, addr
);
6700 ospf_if_update_params(ifp
, addr
);
6703 SET_IF_PARAM(params
, auth_type
);
6704 params
->auth_type
= OSPF_AUTH_SIMPLE
;
6709 DEFUN (no_ip_ospf_authentication_args
,
6710 no_ip_ospf_authentication_args_addr_cmd
,
6711 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
6714 "OSPF interface commands\n"
6715 "Enable authentication on this interface\n"
6716 "Use null authentication\n"
6717 "Use message-digest authentication\n"
6718 "Address of interface\n")
6720 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6721 int idx_encryption
= 4;
6723 struct in_addr addr
;
6725 struct ospf_if_params
*params
;
6726 struct route_node
*rn
;
6729 params
= IF_DEF_PARAMS(ifp
);
6732 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6735 "Please specify interface address by A.B.C.D\n");
6736 return CMD_WARNING_CONFIG_FAILED
;
6739 params
= ospf_lookup_if_params(ifp
, addr
);
6740 if (params
== NULL
) {
6741 vty_out(vty
, "Ip Address specified is unknown\n");
6742 return CMD_WARNING_CONFIG_FAILED
;
6744 params
->auth_type
= OSPF_AUTH_NOTSET
;
6745 UNSET_IF_PARAM(params
, auth_type
);
6746 if (params
!= IF_DEF_PARAMS(ifp
)) {
6747 ospf_free_if_params(ifp
, addr
);
6748 ospf_if_update_params(ifp
, addr
);
6751 if (argv
[idx_encryption
]->arg
[0] == 'n') {
6752 auth_type
= OSPF_AUTH_NULL
;
6753 } else if (argv
[idx_encryption
]->arg
[0] == 'm') {
6754 auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
6756 vty_out(vty
, "Unexpected input encountered\n");
6757 return CMD_WARNING_CONFIG_FAILED
;
6760 * Here we have a case where the user has entered
6761 * 'no ip ospf authentication (null | message_digest )'
6762 * we need to find if we have any ip addresses underneath it
6764 * correspond to the associated type.
6766 if (params
->auth_type
== auth_type
) {
6767 params
->auth_type
= OSPF_AUTH_NOTSET
;
6768 UNSET_IF_PARAM(params
, auth_type
);
6771 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
6772 rn
= route_next(rn
)) {
6773 if ((params
= rn
->info
)) {
6774 if (params
->auth_type
== auth_type
) {
6775 params
->auth_type
= OSPF_AUTH_NOTSET
;
6776 UNSET_IF_PARAM(params
, auth_type
);
6777 if (params
!= IF_DEF_PARAMS(ifp
)) {
6778 ospf_free_if_params(
6779 ifp
, rn
->p
.u
.prefix4
);
6780 ospf_if_update_params(
6781 ifp
, rn
->p
.u
.prefix4
);
6791 DEFUN (no_ip_ospf_authentication
,
6792 no_ip_ospf_authentication_addr_cmd
,
6793 "no ip ospf authentication [A.B.C.D]",
6796 "OSPF interface commands\n"
6797 "Enable authentication on this interface\n"
6798 "Address of interface\n")
6800 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6802 struct in_addr addr
;
6804 struct ospf_if_params
*params
;
6805 struct route_node
*rn
;
6807 params
= IF_DEF_PARAMS(ifp
);
6810 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6813 "Please specify interface address by A.B.C.D\n");
6814 return CMD_WARNING_CONFIG_FAILED
;
6817 params
= ospf_lookup_if_params(ifp
, addr
);
6818 if (params
== NULL
) {
6819 vty_out(vty
, "Ip Address specified is unknown\n");
6820 return CMD_WARNING_CONFIG_FAILED
;
6823 params
->auth_type
= OSPF_AUTH_NOTSET
;
6824 UNSET_IF_PARAM(params
, auth_type
);
6825 if (params
!= IF_DEF_PARAMS(ifp
)) {
6826 ospf_free_if_params(ifp
, addr
);
6827 ospf_if_update_params(ifp
, addr
);
6831 * When a user enters 'no ip ospf authentication'
6832 * We should remove all authentication types from
6835 if ((params
->auth_type
== OSPF_AUTH_NULL
)
6836 || (params
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
6837 || (params
->auth_type
== OSPF_AUTH_SIMPLE
)) {
6838 params
->auth_type
= OSPF_AUTH_NOTSET
;
6839 UNSET_IF_PARAM(params
, auth_type
);
6842 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
6843 rn
= route_next(rn
)) {
6844 if ((params
= rn
->info
)) {
6846 if ((params
->auth_type
== OSPF_AUTH_NULL
)
6847 || (params
->auth_type
6848 == OSPF_AUTH_CRYPTOGRAPHIC
)
6849 || (params
->auth_type
6850 == OSPF_AUTH_SIMPLE
)) {
6851 params
->auth_type
= OSPF_AUTH_NOTSET
;
6852 UNSET_IF_PARAM(params
, auth_type
);
6853 if (params
!= IF_DEF_PARAMS(ifp
)) {
6854 ospf_free_if_params(
6855 ifp
, rn
->p
.u
.prefix4
);
6856 ospf_if_update_params(
6857 ifp
, rn
->p
.u
.prefix4
);
6868 DEFUN (ip_ospf_authentication_key
,
6869 ip_ospf_authentication_key_addr_cmd
,
6870 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
6872 "OSPF interface commands\n"
6873 "Authentication password (key)\n"
6874 "The OSPF password (key)\n"
6875 "Address of interface\n")
6877 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6879 struct in_addr addr
;
6880 struct ospf_if_params
*params
;
6882 params
= IF_DEF_PARAMS(ifp
);
6884 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6885 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6887 "Please specify interface address by A.B.C.D\n");
6888 return CMD_WARNING_CONFIG_FAILED
;
6891 params
= ospf_get_if_params(ifp
, addr
);
6892 ospf_if_update_params(ifp
, addr
);
6895 memset(params
->auth_simple
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
6896 strncpy((char *)params
->auth_simple
, argv
[3]->arg
,
6897 OSPF_AUTH_SIMPLE_SIZE
);
6898 SET_IF_PARAM(params
, auth_simple
);
6903 DEFUN_HIDDEN (ospf_authentication_key
,
6904 ospf_authentication_key_cmd
,
6905 "ospf authentication-key AUTH_KEY [A.B.C.D]",
6906 "OSPF interface commands\n"
6907 VLINK_HELPSTR_AUTH_SIMPLE
6908 "Address of interface\n")
6910 return ip_ospf_authentication_key(self
, vty
, argc
, argv
);
6913 DEFUN (no_ip_ospf_authentication_key
,
6914 no_ip_ospf_authentication_key_authkey_addr_cmd
,
6915 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
6918 "OSPF interface commands\n"
6919 VLINK_HELPSTR_AUTH_SIMPLE
6920 "Address of interface\n")
6922 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6924 struct in_addr addr
;
6925 struct ospf_if_params
*params
;
6926 params
= IF_DEF_PARAMS(ifp
);
6928 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6929 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6931 "Please specify interface address by A.B.C.D\n");
6932 return CMD_WARNING_CONFIG_FAILED
;
6935 params
= ospf_lookup_if_params(ifp
, addr
);
6940 memset(params
->auth_simple
, 0, OSPF_AUTH_SIMPLE_SIZE
);
6941 UNSET_IF_PARAM(params
, auth_simple
);
6943 if (params
!= IF_DEF_PARAMS(ifp
)) {
6944 ospf_free_if_params(ifp
, addr
);
6945 ospf_if_update_params(ifp
, addr
);
6951 DEFUN_HIDDEN (no_ospf_authentication_key
,
6952 no_ospf_authentication_key_authkey_addr_cmd
,
6953 "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
6955 "OSPF interface commands\n"
6956 VLINK_HELPSTR_AUTH_SIMPLE
6957 "Address of interface\n")
6959 return no_ip_ospf_authentication_key(self
, vty
, argc
, argv
);
6962 DEFUN (ip_ospf_message_digest_key
,
6963 ip_ospf_message_digest_key_cmd
,
6964 "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
6966 "OSPF interface commands\n"
6967 "Message digest authentication password (key)\n"
6969 "Use MD5 algorithm\n"
6970 "The OSPF password (key)\n"
6971 "Address of interface\n")
6973 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6974 struct crypt_key
*ck
;
6976 struct in_addr addr
;
6977 struct ospf_if_params
*params
;
6979 params
= IF_DEF_PARAMS(ifp
);
6982 argv_find(argv
, argc
, "(1-255)", &idx
);
6983 char *keyid
= argv
[idx
]->arg
;
6984 argv_find(argv
, argc
, "KEY", &idx
);
6985 char *cryptkey
= argv
[idx
]->arg
;
6987 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6988 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6990 "Please specify interface address by A.B.C.D\n");
6991 return CMD_WARNING_CONFIG_FAILED
;
6994 params
= ospf_get_if_params(ifp
, addr
);
6995 ospf_if_update_params(ifp
, addr
);
6998 key_id
= strtol(keyid
, NULL
, 10);
6999 if (ospf_crypt_key_lookup(params
->auth_crypt
, key_id
) != NULL
) {
7000 vty_out(vty
, "OSPF: Key %d already exists\n", key_id
);
7004 ck
= ospf_crypt_key_new();
7005 ck
->key_id
= (uint8_t)key_id
;
7006 memset(ck
->auth_key
, 0, OSPF_AUTH_MD5_SIZE
+ 1);
7007 strncpy((char *)ck
->auth_key
, cryptkey
, OSPF_AUTH_MD5_SIZE
);
7009 ospf_crypt_key_add(params
->auth_crypt
, ck
);
7010 SET_IF_PARAM(params
, auth_crypt
);
7015 DEFUN_HIDDEN (ospf_message_digest_key
,
7016 ospf_message_digest_key_cmd
,
7017 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7018 "OSPF interface commands\n"
7019 "Message digest authentication password (key)\n"
7021 "Use MD5 algorithm\n"
7022 "The OSPF password (key)\n"
7023 "Address of interface\n")
7025 return ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7028 DEFUN (no_ip_ospf_message_digest_key
,
7029 no_ip_ospf_message_digest_key_cmd
,
7030 "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7033 "OSPF interface commands\n"
7034 "Message digest authentication password (key)\n"
7036 "Use MD5 algorithm\n"
7037 "The OSPF password (key)\n"
7038 "Address of interface\n")
7040 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7042 struct crypt_key
*ck
;
7044 struct in_addr addr
;
7045 struct ospf_if_params
*params
;
7046 params
= IF_DEF_PARAMS(ifp
);
7048 argv_find(argv
, argc
, "(1-255)", &idx
);
7049 char *keyid
= argv
[idx
]->arg
;
7051 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7052 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7054 "Please specify interface address by A.B.C.D\n");
7055 return CMD_WARNING_CONFIG_FAILED
;
7058 params
= ospf_lookup_if_params(ifp
, addr
);
7063 key_id
= strtol(keyid
, NULL
, 10);
7064 ck
= ospf_crypt_key_lookup(params
->auth_crypt
, key_id
);
7066 vty_out(vty
, "OSPF: Key %d does not exist\n", key_id
);
7067 return CMD_WARNING_CONFIG_FAILED
;
7070 ospf_crypt_key_delete(params
->auth_crypt
, key_id
);
7072 if (params
!= IF_DEF_PARAMS(ifp
)) {
7073 ospf_free_if_params(ifp
, addr
);
7074 ospf_if_update_params(ifp
, addr
);
7080 DEFUN_HIDDEN (no_ospf_message_digest_key
,
7081 no_ospf_message_digest_key_cmd
,
7082 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7084 "OSPF interface commands\n"
7085 "Message digest authentication password (key)\n"
7087 "Use MD5 algorithm\n"
7088 "The OSPF password (key)\n"
7089 "Address of interface\n")
7091 return no_ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7094 DEFUN (ip_ospf_cost
,
7096 "ip ospf cost (1-65535) [A.B.C.D]",
7098 "OSPF interface commands\n"
7101 "Address of interface\n")
7103 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7105 uint32_t cost
= OSPF_OUTPUT_COST_DEFAULT
;
7106 struct in_addr addr
;
7107 struct ospf_if_params
*params
;
7108 params
= IF_DEF_PARAMS(ifp
);
7111 char *coststr
= NULL
, *ifaddr
= NULL
;
7113 argv_find(argv
, argc
, "(1-65535)", &idx
);
7114 coststr
= argv
[idx
]->arg
;
7115 cost
= strtol(coststr
, NULL
, 10);
7117 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7119 if (!inet_aton(ifaddr
, &addr
)) {
7121 "Please specify interface address by A.B.C.D\n");
7122 return CMD_WARNING_CONFIG_FAILED
;
7125 params
= ospf_get_if_params(ifp
, addr
);
7126 ospf_if_update_params(ifp
, addr
);
7129 SET_IF_PARAM(params
, output_cost_cmd
);
7130 params
->output_cost_cmd
= cost
;
7132 ospf_if_recalculate_output_cost(ifp
);
7137 DEFUN_HIDDEN (ospf_cost
,
7139 "ospf cost (1-65535) [A.B.C.D]",
7140 "OSPF interface commands\n"
7143 "Address of interface\n")
7145 return ip_ospf_cost(self
, vty
, argc
, argv
);
7148 DEFUN (no_ip_ospf_cost
,
7149 no_ip_ospf_cost_cmd
,
7150 "no ip ospf cost [(1-65535)] [A.B.C.D]",
7153 "OSPF interface commands\n"
7156 "Address of interface\n")
7158 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7160 struct in_addr addr
;
7161 struct ospf_if_params
*params
;
7163 params
= IF_DEF_PARAMS(ifp
);
7166 char *ifaddr
= NULL
;
7167 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7169 /* According to the semantics we are mimicking "no ip ospf cost N" is
7170 * always treated as "no ip ospf cost" regardless of the actual value
7171 * of N already configured for the interface. Thus ignore cost. */
7174 if (!inet_aton(ifaddr
, &addr
)) {
7176 "Please specify interface address by A.B.C.D\n");
7177 return CMD_WARNING_CONFIG_FAILED
;
7180 params
= ospf_lookup_if_params(ifp
, addr
);
7185 UNSET_IF_PARAM(params
, output_cost_cmd
);
7187 if (params
!= IF_DEF_PARAMS(ifp
)) {
7188 ospf_free_if_params(ifp
, addr
);
7189 ospf_if_update_params(ifp
, addr
);
7192 ospf_if_recalculate_output_cost(ifp
);
7197 DEFUN_HIDDEN (no_ospf_cost
,
7199 "no ospf cost [(1-65535)] [A.B.C.D]",
7201 "OSPF interface commands\n"
7204 "Address of interface\n")
7206 return no_ip_ospf_cost(self
, vty
, argc
, argv
);
7209 static void ospf_nbr_timer_update(struct ospf_interface
*oi
)
7211 struct route_node
*rn
;
7212 struct ospf_neighbor
*nbr
;
7214 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
7215 if ((nbr
= rn
->info
)) {
7216 nbr
->v_inactivity
= OSPF_IF_PARAM(oi
, v_wait
);
7217 nbr
->v_db_desc
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7218 nbr
->v_ls_req
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7219 nbr
->v_ls_upd
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7223 static int ospf_vty_dead_interval_set(struct vty
*vty
, const char *interval_str
,
7224 const char *nbr_str
,
7225 const char *fast_hello_str
)
7227 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7230 struct in_addr addr
;
7232 struct ospf_if_params
*params
;
7233 struct ospf_interface
*oi
;
7234 struct route_node
*rn
;
7236 params
= IF_DEF_PARAMS(ifp
);
7239 ret
= inet_aton(nbr_str
, &addr
);
7242 "Please specify interface address by A.B.C.D\n");
7243 return CMD_WARNING_CONFIG_FAILED
;
7246 params
= ospf_get_if_params(ifp
, addr
);
7247 ospf_if_update_params(ifp
, addr
);
7251 seconds
= strtoul(interval_str
, NULL
, 10);
7253 /* reset fast_hello too, just to be sure */
7254 UNSET_IF_PARAM(params
, fast_hello
);
7255 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
7256 } else if (fast_hello_str
) {
7257 hellomult
= strtoul(fast_hello_str
, NULL
, 10);
7258 /* 1s dead-interval with sub-second hellos desired */
7259 seconds
= OSPF_ROUTER_DEAD_INTERVAL_MINIMAL
;
7260 SET_IF_PARAM(params
, fast_hello
);
7261 params
->fast_hello
= hellomult
;
7264 "Please specify dead-interval or hello-multiplier\n");
7265 return CMD_WARNING_CONFIG_FAILED
;
7268 SET_IF_PARAM(params
, v_wait
);
7269 params
->v_wait
= seconds
;
7271 /* Update timer values in neighbor structure. */
7273 struct ospf
*ospf
= NULL
;
7275 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7277 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
7279 ospf_nbr_timer_update(oi
);
7282 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
7283 if ((oi
= rn
->info
))
7284 ospf_nbr_timer_update(oi
);
7290 DEFUN (ip_ospf_dead_interval
,
7291 ip_ospf_dead_interval_cmd
,
7292 "ip ospf dead-interval (1-65535) [A.B.C.D]",
7294 "OSPF interface commands\n"
7295 "Interval time after which a neighbor is declared down\n"
7297 "Address of interface\n")
7300 char *interval
= argv_find(argv
, argc
, "(1-65535)", &idx
)
7304 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7305 return ospf_vty_dead_interval_set(vty
, interval
, ifaddr
, NULL
);
7309 DEFUN_HIDDEN (ospf_dead_interval
,
7310 ospf_dead_interval_cmd
,
7311 "ospf dead-interval (1-65535) [A.B.C.D]",
7312 "OSPF interface commands\n"
7313 "Interval time after which a neighbor is declared down\n"
7315 "Address of interface\n")
7317 return ip_ospf_dead_interval(self
, vty
, argc
, argv
);
7320 DEFUN (ip_ospf_dead_interval_minimal
,
7321 ip_ospf_dead_interval_minimal_addr_cmd
,
7322 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
7324 "OSPF interface commands\n"
7325 "Interval time after which a neighbor is declared down\n"
7326 "Minimal 1s dead-interval with fast sub-second hellos\n"
7327 "Hello multiplier factor\n"
7328 "Number of Hellos to send each second\n"
7329 "Address of interface\n")
7334 return ospf_vty_dead_interval_set(
7335 vty
, NULL
, argv
[idx_ipv4
]->arg
, argv
[idx_number
]->arg
);
7337 return ospf_vty_dead_interval_set(vty
, NULL
, NULL
,
7338 argv
[idx_number
]->arg
);
7341 DEFUN (no_ip_ospf_dead_interval
,
7342 no_ip_ospf_dead_interval_cmd
,
7343 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
7346 "OSPF interface commands\n"
7347 "Interval time after which a neighbor is declared down\n"
7349 "Minimal 1s dead-interval with fast sub-second hellos\n"
7350 "Hello multiplier factor\n"
7351 "Number of Hellos to send each second\n"
7352 "Address of interface\n")
7354 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7355 int idx_ipv4
= argc
- 1;
7356 struct in_addr addr
= {.s_addr
= 0L};
7358 struct ospf_if_params
*params
;
7359 struct ospf_interface
*oi
;
7360 struct route_node
*rn
;
7362 params
= IF_DEF_PARAMS(ifp
);
7364 if (argv
[idx_ipv4
]->type
== IPV4_TKN
) {
7365 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7368 "Please specify interface address by A.B.C.D\n");
7369 return CMD_WARNING_CONFIG_FAILED
;
7372 params
= ospf_lookup_if_params(ifp
, addr
);
7377 UNSET_IF_PARAM(params
, v_wait
);
7378 params
->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
7380 UNSET_IF_PARAM(params
, fast_hello
);
7381 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
7383 if (params
!= IF_DEF_PARAMS(ifp
)) {
7384 ospf_free_if_params(ifp
, addr
);
7385 ospf_if_update_params(ifp
, addr
);
7388 /* Update timer values in neighbor structure. */
7390 struct ospf
*ospf
= NULL
;
7392 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7394 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
7396 ospf_nbr_timer_update(oi
);
7399 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
7400 if ((oi
= rn
->info
))
7401 ospf_nbr_timer_update(oi
);
7407 DEFUN_HIDDEN (no_ospf_dead_interval
,
7408 no_ospf_dead_interval_cmd
,
7409 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
7411 "OSPF interface commands\n"
7412 "Interval time after which a neighbor is declared down\n"
7414 "Minimal 1s dead-interval with fast sub-second hellos\n"
7415 "Hello multiplier factor\n"
7416 "Number of Hellos to send each second\n"
7417 "Address of interface\n")
7419 return no_ip_ospf_dead_interval(self
, vty
, argc
, argv
);
7422 DEFUN (ip_ospf_hello_interval
,
7423 ip_ospf_hello_interval_cmd
,
7424 "ip ospf hello-interval (1-65535) [A.B.C.D]",
7426 "OSPF interface commands\n"
7427 "Time between HELLO packets\n"
7429 "Address of interface\n")
7431 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7433 struct in_addr addr
;
7434 struct ospf_if_params
*params
;
7435 params
= IF_DEF_PARAMS(ifp
);
7436 uint32_t seconds
= 0;
7438 argv_find(argv
, argc
, "(1-65535)", &idx
);
7439 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7441 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7442 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7444 "Please specify interface address by A.B.C.D\n");
7445 return CMD_WARNING_CONFIG_FAILED
;
7448 params
= ospf_get_if_params(ifp
, addr
);
7449 ospf_if_update_params(ifp
, addr
);
7452 SET_IF_PARAM(params
, v_hello
);
7453 params
->v_hello
= seconds
;
7458 DEFUN_HIDDEN (ospf_hello_interval
,
7459 ospf_hello_interval_cmd
,
7460 "ospf hello-interval (1-65535) [A.B.C.D]",
7461 "OSPF interface commands\n"
7462 "Time between HELLO packets\n"
7464 "Address of interface\n")
7466 return ip_ospf_hello_interval(self
, vty
, argc
, argv
);
7469 DEFUN (no_ip_ospf_hello_interval
,
7470 no_ip_ospf_hello_interval_cmd
,
7471 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
7474 "OSPF interface commands\n"
7475 "Time between HELLO packets\n" // ignored
7477 "Address of interface\n")
7479 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7481 struct in_addr addr
;
7482 struct ospf_if_params
*params
;
7484 params
= IF_DEF_PARAMS(ifp
);
7486 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7487 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7489 "Please specify interface address by A.B.C.D\n");
7490 return CMD_WARNING_CONFIG_FAILED
;
7493 params
= ospf_lookup_if_params(ifp
, addr
);
7498 UNSET_IF_PARAM(params
, v_hello
);
7499 params
->v_hello
= OSPF_HELLO_INTERVAL_DEFAULT
;
7501 if (params
!= IF_DEF_PARAMS(ifp
)) {
7502 ospf_free_if_params(ifp
, addr
);
7503 ospf_if_update_params(ifp
, addr
);
7509 DEFUN_HIDDEN (no_ospf_hello_interval
,
7510 no_ospf_hello_interval_cmd
,
7511 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
7513 "OSPF interface commands\n"
7514 "Time between HELLO packets\n" // ignored
7516 "Address of interface\n")
7518 return no_ip_ospf_hello_interval(self
, vty
, argc
, argv
);
7521 DEFUN (ip_ospf_network
,
7522 ip_ospf_network_cmd
,
7523 "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
7525 "OSPF interface commands\n"
7527 "Specify OSPF broadcast multi-access network\n"
7528 "Specify OSPF NBMA network\n"
7529 "Specify OSPF point-to-multipoint network\n"
7530 "Specify OSPF point-to-point network\n")
7532 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7534 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
7535 struct route_node
*rn
;
7537 if (old_type
== OSPF_IFTYPE_LOOPBACK
) {
7539 "This is a loopback interface. Can't set network type.\n");
7540 return CMD_WARNING_CONFIG_FAILED
;
7543 if (argv_find(argv
, argc
, "broadcast", &idx
))
7544 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_BROADCAST
;
7545 else if (argv_find(argv
, argc
, "non-broadcast", &idx
))
7546 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_NBMA
;
7547 else if (argv_find(argv
, argc
, "point-to-multipoint", &idx
))
7548 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOMULTIPOINT
;
7549 else if (argv_find(argv
, argc
, "point-to-point", &idx
))
7550 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOPOINT
;
7552 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
7555 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), type
);
7557 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7558 struct ospf_interface
*oi
= rn
->info
;
7563 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
7565 if (oi
->state
> ISM_Down
) {
7566 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
7567 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
7574 DEFUN_HIDDEN (ospf_network
,
7576 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
7577 "OSPF interface commands\n"
7579 "Specify OSPF broadcast multi-access network\n"
7580 "Specify OSPF NBMA network\n"
7581 "Specify OSPF point-to-multipoint network\n"
7582 "Specify OSPF point-to-point network\n")
7584 return ip_ospf_network(self
, vty
, argc
, argv
);
7587 DEFUN (no_ip_ospf_network
,
7588 no_ip_ospf_network_cmd
,
7589 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
7592 "OSPF interface commands\n"
7594 "Specify OSPF broadcast multi-access network\n"
7595 "Specify OSPF NBMA network\n"
7596 "Specify OSPF point-to-multipoint network\n"
7597 "Specify OSPF point-to-point network\n")
7599 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7600 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
7601 struct route_node
*rn
;
7603 IF_DEF_PARAMS(ifp
)->type
= ospf_default_iftype(ifp
);
7605 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
7608 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7609 struct ospf_interface
*oi
= rn
->info
;
7614 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
7616 if (oi
->state
> ISM_Down
) {
7617 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
7618 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
7625 DEFUN_HIDDEN (no_ospf_network
,
7626 no_ospf_network_cmd
,
7627 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
7629 "OSPF interface commands\n"
7631 "Specify OSPF broadcast multi-access network\n"
7632 "Specify OSPF NBMA network\n"
7633 "Specify OSPF point-to-multipoint network\n"
7634 "Specify OSPF point-to-point network\n")
7636 return no_ip_ospf_network(self
, vty
, argc
, argv
);
7639 DEFUN (ip_ospf_priority
,
7640 ip_ospf_priority_cmd
,
7641 "ip ospf priority (0-255) [A.B.C.D]",
7643 "OSPF interface commands\n"
7646 "Address of interface\n")
7648 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7651 struct route_node
*rn
;
7652 struct in_addr addr
;
7653 struct ospf_if_params
*params
;
7654 params
= IF_DEF_PARAMS(ifp
);
7656 argv_find(argv
, argc
, "(0-255)", &idx
);
7657 priority
= strtol(argv
[idx
]->arg
, NULL
, 10);
7659 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7660 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7662 "Please specify interface address by A.B.C.D\n");
7663 return CMD_WARNING_CONFIG_FAILED
;
7666 params
= ospf_get_if_params(ifp
, addr
);
7667 ospf_if_update_params(ifp
, addr
);
7670 SET_IF_PARAM(params
, priority
);
7671 params
->priority
= priority
;
7673 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7674 struct ospf_interface
*oi
= rn
->info
;
7679 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
7680 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
7681 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
7688 DEFUN_HIDDEN (ospf_priority
,
7690 "ospf priority (0-255) [A.B.C.D]",
7691 "OSPF interface commands\n"
7694 "Address of interface\n")
7696 return ip_ospf_priority(self
, vty
, argc
, argv
);
7699 DEFUN (no_ip_ospf_priority
,
7700 no_ip_ospf_priority_cmd
,
7701 "no ip ospf priority [(0-255) [A.B.C.D]]",
7704 "OSPF interface commands\n"
7705 "Router priority\n" // ignored
7707 "Address of interface\n")
7709 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7711 struct route_node
*rn
;
7712 struct in_addr addr
;
7713 struct ospf_if_params
*params
;
7715 params
= IF_DEF_PARAMS(ifp
);
7717 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7718 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7720 "Please specify interface address by A.B.C.D\n");
7721 return CMD_WARNING_CONFIG_FAILED
;
7724 params
= ospf_lookup_if_params(ifp
, addr
);
7729 UNSET_IF_PARAM(params
, priority
);
7730 params
->priority
= OSPF_ROUTER_PRIORITY_DEFAULT
;
7732 if (params
!= IF_DEF_PARAMS(ifp
)) {
7733 ospf_free_if_params(ifp
, addr
);
7734 ospf_if_update_params(ifp
, addr
);
7737 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7738 struct ospf_interface
*oi
= rn
->info
;
7743 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
7744 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
7745 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
7752 DEFUN_HIDDEN (no_ospf_priority
,
7753 no_ospf_priority_cmd
,
7754 "no ospf priority [(0-255) [A.B.C.D]]",
7756 "OSPF interface commands\n"
7759 "Address of interface\n")
7761 return no_ip_ospf_priority(self
, vty
, argc
, argv
);
7764 DEFUN (ip_ospf_retransmit_interval
,
7765 ip_ospf_retransmit_interval_addr_cmd
,
7766 "ip ospf retransmit-interval (3-65535) [A.B.C.D]",
7768 "OSPF interface commands\n"
7769 "Time between retransmitting lost link state advertisements\n"
7771 "Address of interface\n")
7773 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7776 struct in_addr addr
;
7777 struct ospf_if_params
*params
;
7778 params
= IF_DEF_PARAMS(ifp
);
7780 argv_find(argv
, argc
, "(3-65535)", &idx
);
7781 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7783 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7784 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7786 "Please specify interface address by A.B.C.D\n");
7787 return CMD_WARNING_CONFIG_FAILED
;
7790 params
= ospf_get_if_params(ifp
, addr
);
7791 ospf_if_update_params(ifp
, addr
);
7794 SET_IF_PARAM(params
, retransmit_interval
);
7795 params
->retransmit_interval
= seconds
;
7800 DEFUN_HIDDEN (ospf_retransmit_interval
,
7801 ospf_retransmit_interval_cmd
,
7802 "ospf retransmit-interval (3-65535) [A.B.C.D]",
7803 "OSPF interface commands\n"
7804 "Time between retransmitting lost link state advertisements\n"
7806 "Address of interface\n")
7808 return ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
7811 DEFUN (no_ip_ospf_retransmit_interval
,
7812 no_ip_ospf_retransmit_interval_addr_cmd
,
7813 "no ip ospf retransmit-interval [(3-65535)] [A.B.C.D]",
7816 "OSPF interface commands\n"
7817 "Time between retransmitting lost link state advertisements\n"
7819 "Address of interface\n")
7821 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7823 struct in_addr addr
;
7824 struct ospf_if_params
*params
;
7826 params
= IF_DEF_PARAMS(ifp
);
7828 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7829 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7831 "Please specify interface address by A.B.C.D\n");
7832 return CMD_WARNING_CONFIG_FAILED
;
7835 params
= ospf_lookup_if_params(ifp
, addr
);
7840 UNSET_IF_PARAM(params
, retransmit_interval
);
7841 params
->retransmit_interval
= OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
7843 if (params
!= IF_DEF_PARAMS(ifp
)) {
7844 ospf_free_if_params(ifp
, addr
);
7845 ospf_if_update_params(ifp
, addr
);
7851 DEFUN_HIDDEN (no_ospf_retransmit_interval
,
7852 no_ospf_retransmit_interval_cmd
,
7853 "no ospf retransmit-interval [(3-65535)] [A.B.C.D]",
7855 "OSPF interface commands\n"
7856 "Time between retransmitting lost link state advertisements\n"
7858 "Address of interface\n")
7860 return no_ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
7863 DEFUN (ip_ospf_transmit_delay
,
7864 ip_ospf_transmit_delay_addr_cmd
,
7865 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
7867 "OSPF interface commands\n"
7868 "Link state transmit delay\n"
7870 "Address of interface\n")
7872 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7875 struct in_addr addr
;
7876 struct ospf_if_params
*params
;
7878 params
= IF_DEF_PARAMS(ifp
);
7879 argv_find(argv
, argc
, "(1-65535)", &idx
);
7880 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7882 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7883 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7885 "Please specify interface address by A.B.C.D\n");
7886 return CMD_WARNING_CONFIG_FAILED
;
7889 params
= ospf_get_if_params(ifp
, addr
);
7890 ospf_if_update_params(ifp
, addr
);
7893 SET_IF_PARAM(params
, transmit_delay
);
7894 params
->transmit_delay
= seconds
;
7899 DEFUN_HIDDEN (ospf_transmit_delay
,
7900 ospf_transmit_delay_cmd
,
7901 "ospf transmit-delay (1-65535) [A.B.C.D]",
7902 "OSPF interface commands\n"
7903 "Link state transmit delay\n"
7905 "Address of interface\n")
7907 return ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
7910 DEFUN (no_ip_ospf_transmit_delay
,
7911 no_ip_ospf_transmit_delay_addr_cmd
,
7912 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
7915 "OSPF interface commands\n"
7916 "Link state transmit delay\n"
7918 "Address of interface\n")
7920 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7922 struct in_addr addr
;
7923 struct ospf_if_params
*params
;
7925 params
= IF_DEF_PARAMS(ifp
);
7927 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7928 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7930 "Please specify interface address by A.B.C.D\n");
7931 return CMD_WARNING_CONFIG_FAILED
;
7934 params
= ospf_lookup_if_params(ifp
, addr
);
7939 UNSET_IF_PARAM(params
, transmit_delay
);
7940 params
->transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
7942 if (params
!= IF_DEF_PARAMS(ifp
)) {
7943 ospf_free_if_params(ifp
, addr
);
7944 ospf_if_update_params(ifp
, addr
);
7951 DEFUN_HIDDEN (no_ospf_transmit_delay
,
7952 no_ospf_transmit_delay_cmd
,
7953 "no ospf transmit-delay [(1-65535) [A.B.C.D]]",
7955 "OSPF interface commands\n"
7956 "Link state transmit delay\n"
7958 "Address of interface\n")
7960 return no_ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
7963 DEFUN (ip_ospf_area
,
7965 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]",
7967 "OSPF interface commands\n"
7969 "Enable OSPF on this interface\n"
7970 "OSPF area ID in IP address format\n"
7971 "OSPF area ID as a decimal value\n"
7972 "Address of interface\n")
7974 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7977 struct in_addr area_id
;
7978 struct in_addr addr
;
7979 struct ospf_if_params
*params
= NULL
;
7980 struct route_node
*rn
;
7981 struct ospf
*ospf
= NULL
;
7982 unsigned short instance
= 0;
7985 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
7986 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
7988 argv_find(argv
, argc
, "area", &idx
);
7989 areaid
= argv
[idx
+ 1]->arg
;
7991 if (ifp
->vrf_id
&& !instance
)
7992 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7994 ospf
= ospf_lookup_instance(instance
);
7996 if (instance
&& ospf
== NULL
) {
7997 params
= IF_DEF_PARAMS(ifp
);
7998 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
7999 UNSET_IF_PARAM(params
, if_area
);
8000 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
8001 ospf_interface_area_unset(ospf
, ifp
);
8002 ospf
->if_ospf_cli_count
--;
8004 return CMD_NOT_MY_INSTANCE
;
8007 ret
= str2area_id(areaid
, &area_id
, &format
);
8009 vty_out(vty
, "Please specify area by A.B.C.D|<0-4294967295>\n");
8010 return CMD_WARNING_CONFIG_FAILED
;
8012 if (memcmp(ifp
->name
, "VLINK", 5) == 0) {
8013 vty_out(vty
, "Cannot enable OSPF on a virtual link.\n");
8014 return CMD_WARNING_CONFIG_FAILED
;
8017 params
= IF_DEF_PARAMS(ifp
);
8018 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)
8019 && !IPV4_ADDR_SAME(¶ms
->if_area
, &area_id
)) {
8021 "Must remove previous area config before changing ospf area \n");
8022 return CMD_WARNING_CONFIG_FAILED
;
8025 // Check if we have an address arg and proccess it
8026 if (argc
== idx
+ 3) {
8027 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
8029 "Please specify Intf Address by A.B.C.D\n");
8030 return CMD_WARNING_CONFIG_FAILED
;
8032 // update/create address-level params
8033 params
= ospf_get_if_params((ifp
), (addr
));
8034 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8036 "Must remove previous area/address config before changing ospf area");
8037 return CMD_WARNING_CONFIG_FAILED
;
8039 ospf_if_update_params((ifp
), (addr
));
8043 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
)) {
8044 if (rn
->info
!= NULL
) {
8046 "Please remove all network commands first.\n");
8047 return CMD_WARNING_CONFIG_FAILED
;
8052 /* enable ospf on this interface with area_id */
8054 SET_IF_PARAM(params
, if_area
);
8055 params
->if_area
= area_id
;
8056 params
->if_area_id_fmt
= format
;
8060 ospf_interface_area_set(ospf
, ifp
);
8061 ospf
->if_ospf_cli_count
++;
8067 DEFUN (no_ip_ospf_area
,
8068 no_ip_ospf_area_cmd
,
8069 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]",
8072 "OSPF interface commands\n"
8074 "Disable OSPF on this interface\n"
8075 "OSPF area ID in IP address format\n"
8076 "OSPF area ID as a decimal value\n"
8077 "Address of interface\n")
8079 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8082 struct ospf_if_params
*params
;
8083 unsigned short instance
= 0;
8084 struct in_addr addr
;
8086 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
8087 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
8089 if (ifp
->vrf_id
&& !instance
)
8090 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
8092 ospf
= ospf_lookup_instance(instance
);
8095 return CMD_NOT_MY_INSTANCE
;
8097 argv_find(argv
, argc
, "area", &idx
);
8099 // Check if we have an address arg and proccess it
8100 if (argc
== idx
+ 3) {
8101 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
8103 "Please specify Intf Address by A.B.C.D\n");
8104 return CMD_WARNING_CONFIG_FAILED
;
8106 params
= ospf_lookup_if_params(ifp
, addr
);
8107 if ((params
) == NULL
)
8110 params
= IF_DEF_PARAMS(ifp
);
8112 if (!OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8114 "Can't find specified interface area configuration.\n");
8115 return CMD_WARNING_CONFIG_FAILED
;
8118 UNSET_IF_PARAM(params
, if_area
);
8119 if (params
!= IF_DEF_PARAMS((ifp
))) {
8120 ospf_free_if_params((ifp
), (addr
));
8121 ospf_if_update_params((ifp
), (addr
));
8124 ospf_interface_area_unset(ospf
, ifp
);
8125 ospf
->if_ospf_cli_count
--;
8129 DEFUN (ospf_redistribute_source
,
8130 ospf_redistribute_source_cmd
,
8131 "redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8133 FRR_REDIST_HELP_STR_OSPFD
8134 "Metric for redistributed routes\n"
8135 "OSPF default metric\n"
8136 "OSPF exterior metric type for redistributed routes\n"
8137 "Set OSPF External Type 1/2 metrics\n"
8138 "Route map reference\n"
8139 "Pointer to route-map entries\n")
8141 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8142 int idx_protocol
= 1;
8146 struct ospf_redist
*red
;
8149 /* Get distribute source. */
8150 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
8152 return CMD_WARNING_CONFIG_FAILED
;
8154 red
= ospf_redist_add(ospf
, source
, 0);
8156 /* Get metric value. */
8157 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
8158 if (!str2metric(argv
[idx
]->arg
, &metric
))
8159 return CMD_WARNING_CONFIG_FAILED
;
8162 /* Get metric type. */
8163 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
8164 if (!str2metric_type(argv
[idx
]->arg
, &type
))
8165 return CMD_WARNING_CONFIG_FAILED
;
8169 if (argv_find(argv
, argc
, "WORD", &idx
)) {
8170 ospf_routemap_set(red
, argv
[idx
]->arg
);
8172 ospf_routemap_unset(red
);
8174 return ospf_redistribute_set(ospf
, source
, 0, type
, metric
);
8177 DEFUN (no_ospf_redistribute_source
,
8178 no_ospf_redistribute_source_cmd
,
8179 "no redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8182 FRR_REDIST_HELP_STR_OSPFD
8183 "Metric for redistributed routes\n"
8184 "OSPF default metric\n"
8185 "OSPF exterior metric type for redistributed routes\n"
8186 "Set OSPF External Type 1/2 metrics\n"
8187 "Route map reference\n"
8188 "Pointer to route-map entries\n")
8190 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8191 int idx_protocol
= 2;
8193 struct ospf_redist
*red
;
8195 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
8197 return CMD_WARNING_CONFIG_FAILED
;
8199 red
= ospf_redist_lookup(ospf
, source
, 0);
8203 ospf_routemap_unset(red
);
8204 ospf_redist_del(ospf
, source
, 0);
8206 return ospf_redistribute_unset(ospf
, source
, 0);
8209 DEFUN (ospf_redistribute_instance_source
,
8210 ospf_redistribute_instance_source_cmd
,
8211 "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8213 "Open Shortest Path First\n"
8214 "Non-main Kernel Routing Table\n"
8215 "Instance ID/Table ID\n"
8216 "Metric for redistributed routes\n"
8217 "OSPF default metric\n"
8218 "OSPF exterior metric type for redistributed routes\n"
8219 "Set OSPF External Type 1/2 metrics\n"
8220 "Route map reference\n"
8221 "Pointer to route-map entries\n")
8223 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8224 int idx_ospf_table
= 1;
8230 unsigned short instance
;
8231 struct ospf_redist
*red
;
8233 source
= proto_redistnum(AFI_IP
, argv
[idx_ospf_table
]->text
);
8236 vty_out(vty
, "Unknown instance redistribution\n");
8237 return CMD_WARNING_CONFIG_FAILED
;
8240 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8242 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
8244 "Instance redistribution in non-instanced OSPF not allowed\n");
8245 return CMD_WARNING_CONFIG_FAILED
;
8248 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
8249 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
8250 return CMD_WARNING_CONFIG_FAILED
;
8253 /* Get metric value. */
8254 if (argv_find(argv
, argc
, "metric", &idx
))
8255 if (!str2metric(argv
[idx
+ 1]->arg
, &metric
))
8256 return CMD_WARNING_CONFIG_FAILED
;
8259 /* Get metric type. */
8260 if (argv_find(argv
, argc
, "metric-type", &idx
))
8261 if (!str2metric_type(argv
[idx
+ 1]->arg
, &type
))
8262 return CMD_WARNING_CONFIG_FAILED
;
8264 red
= ospf_redist_add(ospf
, source
, instance
);
8267 if (argv_find(argv
, argc
, "route-map", &idx
))
8268 ospf_routemap_set(red
, argv
[idx
+ 1]->arg
);
8270 ospf_routemap_unset(red
);
8272 return ospf_redistribute_set(ospf
, source
, instance
, type
, metric
);
8275 DEFUN (no_ospf_redistribute_instance_source
,
8276 no_ospf_redistribute_instance_source_cmd
,
8277 "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8280 "Open Shortest Path First\n"
8281 "Non-main Kernel Routing Table\n"
8282 "Instance ID/Table Id\n"
8283 "Metric for redistributed routes\n"
8284 "OSPF default metric\n"
8285 "OSPF exterior metric type for redistributed routes\n"
8286 "Set OSPF External Type 1/2 metrics\n"
8287 "Route map reference\n"
8288 "Pointer to route-map entries\n")
8290 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8291 int idx_ospf_table
= 2;
8293 unsigned int instance
;
8294 struct ospf_redist
*red
;
8297 if (strncmp(argv
[idx_ospf_table
]->arg
, "o", 1) == 0)
8298 source
= ZEBRA_ROUTE_OSPF
;
8300 source
= ZEBRA_ROUTE_TABLE
;
8302 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8304 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
8306 "Instance redistribution in non-instanced OSPF not allowed\n");
8307 return CMD_WARNING_CONFIG_FAILED
;
8310 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
8311 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
8312 return CMD_WARNING_CONFIG_FAILED
;
8315 red
= ospf_redist_lookup(ospf
, source
, instance
);
8319 ospf_routemap_unset(red
);
8320 ospf_redist_del(ospf
, source
, instance
);
8322 return ospf_redistribute_unset(ospf
, source
, instance
);
8325 DEFUN (ospf_distribute_list_out
,
8326 ospf_distribute_list_out_cmd
,
8327 "distribute-list WORD out " FRR_REDIST_STR_OSPFD
,
8328 "Filter networks in routing updates\n"
8329 "Access-list name\n"
8331 FRR_REDIST_HELP_STR_OSPFD
)
8333 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8337 char *proto
= argv
[argc
- 1]->text
;
8339 /* Get distribute source. */
8340 source
= proto_redistnum(AFI_IP
, proto
);
8342 return CMD_WARNING_CONFIG_FAILED
;
8344 return ospf_distribute_list_out_set(ospf
, source
, argv
[idx_word
]->arg
);
8347 DEFUN (no_ospf_distribute_list_out
,
8348 no_ospf_distribute_list_out_cmd
,
8349 "no distribute-list WORD out " FRR_REDIST_STR_OSPFD
,
8351 "Filter networks in routing updates\n"
8352 "Access-list name\n"
8354 FRR_REDIST_HELP_STR_OSPFD
)
8356 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8360 char *proto
= argv
[argc
- 1]->text
;
8361 source
= proto_redistnum(AFI_IP
, proto
);
8363 return CMD_WARNING_CONFIG_FAILED
;
8365 return ospf_distribute_list_out_unset(ospf
, source
,
8366 argv
[idx_word
]->arg
);
8369 /* Default information originate. */
8370 DEFUN (ospf_default_information_originate
,
8371 ospf_default_information_originate_cmd
,
8372 "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8373 "Control distribution of default information\n"
8374 "Distribute a default route\n"
8375 "Always advertise default route\n"
8376 "OSPF default metric\n"
8378 "OSPF metric type for default routes\n"
8379 "Set OSPF External Type 1/2 metrics\n"
8380 "Route map reference\n"
8381 "Pointer to route-map entries\n")
8383 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8384 int default_originate
= DEFAULT_ORIGINATE_ZEBRA
;
8387 struct ospf_redist
*red
;
8389 int cur_originate
= ospf
->default_originate
;
8393 red
= ospf_redist_add(ospf
, DEFAULT_ROUTE
, 0);
8395 /* Check whether "always" was specified */
8396 if (argv_find(argv
, argc
, "always", &idx
))
8397 default_originate
= DEFAULT_ORIGINATE_ALWAYS
;
8399 /* Get metric value */
8400 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
8401 if (!str2metric(argv
[idx
]->arg
, &metric
))
8402 return CMD_WARNING_CONFIG_FAILED
;
8405 /* Get metric type. */
8406 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
8407 if (!str2metric_type(argv
[idx
]->arg
, &type
))
8408 return CMD_WARNING_CONFIG_FAILED
;
8412 if (argv_find(argv
, argc
, "WORD", &idx
))
8413 rtmap
= argv
[idx
]->arg
;
8415 /* To check ,if user is providing same route map */
8416 if ((rtmap
== ROUTEMAP_NAME(red
)) ||
8417 (rtmap
&& ROUTEMAP_NAME(red
)
8418 && (strcmp(rtmap
, ROUTEMAP_NAME(red
)) == 0)))
8421 /* Don't allow if the same lsa is aleardy originated. */
8423 && (red
->dmetric
.type
== type
)
8424 && (red
->dmetric
.value
== metric
)
8425 && (cur_originate
== default_originate
))
8428 /* Updating Metric details */
8429 red
->dmetric
.type
= type
;
8430 red
->dmetric
.value
= metric
;
8432 /* updating route map details */
8434 ospf_routemap_set(red
, rtmap
);
8436 ospf_routemap_unset(red
);
8438 return ospf_redistribute_default_set(ospf
, default_originate
, type
,
8442 DEFUN (no_ospf_default_information_originate
,
8443 no_ospf_default_information_originate_cmd
,
8444 "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8446 "Control distribution of default information\n"
8447 "Distribute a default route\n"
8448 "Always advertise default route\n"
8449 "OSPF default metric\n"
8451 "OSPF metric type for default routes\n"
8452 "Set OSPF External Type 1/2 metrics\n"
8453 "Route map reference\n"
8454 "Pointer to route-map entries\n")
8456 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8457 struct prefix_ipv4 p
;
8458 struct ospf_external
*ext
;
8459 struct ospf_redist
*red
;
8462 p
.prefix
.s_addr
= 0;
8465 ospf_external_lsa_flush(ospf
, DEFAULT_ROUTE
, &p
, 0);
8467 ext
= ospf_external_lookup(ospf
, DEFAULT_ROUTE
, 0);
8468 if (ext
&& EXTERNAL_INFO(ext
)) {
8469 ospf_external_info_delete(ospf
, DEFAULT_ROUTE
, 0, p
);
8470 ospf_external_del(ospf
, DEFAULT_ROUTE
, 0);
8473 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
8477 ospf_routemap_unset(red
);
8478 ospf_redist_del(ospf
, DEFAULT_ROUTE
, 0);
8480 return ospf_redistribute_default_unset(ospf
);
8483 DEFUN (ospf_default_metric
,
8484 ospf_default_metric_cmd
,
8485 "default-metric (0-16777214)",
8486 "Set metric of redistributed routes\n"
8489 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8493 if (!str2metric(argv
[idx_number
]->arg
, &metric
))
8494 return CMD_WARNING_CONFIG_FAILED
;
8496 ospf
->default_metric
= metric
;
8501 DEFUN (no_ospf_default_metric
,
8502 no_ospf_default_metric_cmd
,
8503 "no default-metric [(0-16777214)]",
8505 "Set metric of redistributed routes\n"
8508 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8510 ospf
->default_metric
= -1;
8516 DEFUN (ospf_distance
,
8519 "Administrative distance\n"
8520 "OSPF Administrative distance\n")
8522 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8525 ospf
->distance_all
= atoi(argv
[idx_number
]->arg
);
8530 DEFUN (no_ospf_distance
,
8531 no_ospf_distance_cmd
,
8532 "no distance (1-255)",
8534 "Administrative distance\n"
8535 "OSPF Administrative distance\n")
8537 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8539 ospf
->distance_all
= 0;
8544 DEFUN (no_ospf_distance_ospf
,
8545 no_ospf_distance_ospf_cmd
,
8546 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
8548 "Administrative distance\n"
8549 "OSPF administrative distance\n"
8550 "Intra-area routes\n"
8551 "Distance for intra-area routes\n"
8552 "Inter-area routes\n"
8553 "Distance for inter-area routes\n"
8555 "Distance for external routes\n")
8557 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8560 if (argv_find(argv
, argc
, "intra-area", &idx
) || argc
== 3)
8561 idx
= ospf
->distance_intra
= 0;
8562 if (argv_find(argv
, argc
, "inter-area", &idx
) || argc
== 3)
8563 idx
= ospf
->distance_inter
= 0;
8564 if (argv_find(argv
, argc
, "external", &idx
) || argc
== 3)
8565 ospf
->distance_external
= 0;
8570 DEFUN (ospf_distance_ospf
,
8571 ospf_distance_ospf_cmd
,
8572 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
8573 "Administrative distance\n"
8574 "OSPF administrative distance\n"
8575 "Intra-area routes\n"
8576 "Distance for intra-area routes\n"
8577 "Inter-area routes\n"
8578 "Distance for inter-area routes\n"
8580 "Distance for external routes\n")
8582 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8585 ospf
->distance_intra
= 0;
8586 ospf
->distance_inter
= 0;
8587 ospf
->distance_external
= 0;
8589 if (argv_find(argv
, argc
, "intra-area", &idx
))
8590 ospf
->distance_intra
= atoi(argv
[idx
+ 1]->arg
);
8592 if (argv_find(argv
, argc
, "inter-area", &idx
))
8593 ospf
->distance_inter
= atoi(argv
[idx
+ 1]->arg
);
8595 if (argv_find(argv
, argc
, "external", &idx
))
8596 ospf
->distance_external
= atoi(argv
[idx
+ 1]->arg
);
8602 DEFUN (ospf_distance_source
,
8603 ospf_distance_source_cmd
,
8604 "distance (1-255) A.B.C.D/M",
8605 "Administrative distance\n"
8607 "IP source prefix\n")
8609 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8611 int idx_ipv4_prefixlen
= 2;
8613 ospf_distance_set (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
8618 DEFUN (no_ospf_distance_source
,
8619 no_ospf_distance_source_cmd
,
8620 "no distance (1-255) A.B.C.D/M",
8622 "Administrative distance\n"
8624 "IP source prefix\n")
8626 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8628 int idx_ipv4_prefixlen
= 3;
8630 ospf_distance_unset (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
8635 DEFUN (ospf_distance_source_access_list
,
8636 ospf_distance_source_access_list_cmd
,
8637 "distance (1-255) A.B.C.D/M WORD",
8638 "Administrative distance\n"
8640 "IP source prefix\n"
8641 "Access list name\n")
8643 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8645 int idx_ipv4_prefixlen
= 2;
8648 ospf_distance_set (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
8653 DEFUN (no_ospf_distance_source_access_list
,
8654 no_ospf_distance_source_access_list_cmd
,
8655 "no distance (1-255) A.B.C.D/M WORD",
8657 "Administrative distance\n"
8659 "IP source prefix\n"
8660 "Access list name\n")
8662 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8664 int idx_ipv4_prefixlen
= 3;
8667 ospf_distance_unset (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
8673 DEFUN (ip_ospf_mtu_ignore
,
8674 ip_ospf_mtu_ignore_addr_cmd
,
8675 "ip ospf mtu-ignore [A.B.C.D]",
8677 "OSPF interface commands\n"
8678 "Disable MTU mismatch detection on this interface\n"
8679 "Address of interface\n")
8681 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8683 struct in_addr addr
;
8686 struct ospf_if_params
*params
;
8687 params
= IF_DEF_PARAMS(ifp
);
8690 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8693 "Please specify interface address by A.B.C.D\n");
8694 return CMD_WARNING_CONFIG_FAILED
;
8696 params
= ospf_get_if_params(ifp
, addr
);
8697 ospf_if_update_params(ifp
, addr
);
8699 params
->mtu_ignore
= 1;
8700 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
8701 SET_IF_PARAM(params
, mtu_ignore
);
8703 UNSET_IF_PARAM(params
, mtu_ignore
);
8704 if (params
!= IF_DEF_PARAMS(ifp
)) {
8705 ospf_free_if_params(ifp
, addr
);
8706 ospf_if_update_params(ifp
, addr
);
8712 DEFUN (no_ip_ospf_mtu_ignore
,
8713 no_ip_ospf_mtu_ignore_addr_cmd
,
8714 "no ip ospf mtu-ignore [A.B.C.D]",
8717 "OSPF interface commands\n"
8718 "Disable MTU mismatch detection on this interface\n"
8719 "Address of interface\n")
8721 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8723 struct in_addr addr
;
8726 struct ospf_if_params
*params
;
8727 params
= IF_DEF_PARAMS(ifp
);
8730 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8733 "Please specify interface address by A.B.C.D\n");
8734 return CMD_WARNING_CONFIG_FAILED
;
8736 params
= ospf_get_if_params(ifp
, addr
);
8737 ospf_if_update_params(ifp
, addr
);
8739 params
->mtu_ignore
= 0;
8740 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
8741 SET_IF_PARAM(params
, mtu_ignore
);
8743 UNSET_IF_PARAM(params
, mtu_ignore
);
8744 if (params
!= IF_DEF_PARAMS(ifp
)) {
8745 ospf_free_if_params(ifp
, addr
);
8746 ospf_if_update_params(ifp
, addr
);
8753 DEFUN (ospf_max_metric_router_lsa_admin
,
8754 ospf_max_metric_router_lsa_admin_cmd
,
8755 "max-metric router-lsa administrative",
8756 "OSPF maximum / infinite-distance metric\n"
8757 "Advertise own Router-LSA with infinite distance (stub router)\n"
8758 "Administratively applied, for an indefinite period\n")
8760 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8761 struct listnode
*ln
;
8762 struct ospf_area
*area
;
8764 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8765 SET_FLAG(area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
);
8767 if (!CHECK_FLAG(area
->stub_router_state
,
8768 OSPF_AREA_IS_STUB_ROUTED
))
8769 ospf_router_lsa_update_area(area
);
8772 /* Allows for areas configured later to get the property */
8773 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
;
8778 DEFUN (no_ospf_max_metric_router_lsa_admin
,
8779 no_ospf_max_metric_router_lsa_admin_cmd
,
8780 "no max-metric router-lsa administrative",
8782 "OSPF maximum / infinite-distance metric\n"
8783 "Advertise own Router-LSA with infinite distance (stub router)\n"
8784 "Administratively applied, for an indefinite period\n")
8786 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8787 struct listnode
*ln
;
8788 struct ospf_area
*area
;
8790 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8791 UNSET_FLAG(area
->stub_router_state
,
8792 OSPF_AREA_ADMIN_STUB_ROUTED
);
8794 /* Don't trample on the start-up stub timer */
8795 if (CHECK_FLAG(area
->stub_router_state
,
8796 OSPF_AREA_IS_STUB_ROUTED
)
8797 && !area
->t_stub_router
) {
8798 UNSET_FLAG(area
->stub_router_state
,
8799 OSPF_AREA_IS_STUB_ROUTED
);
8800 ospf_router_lsa_update_area(area
);
8803 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET
;
8807 DEFUN (ospf_max_metric_router_lsa_startup
,
8808 ospf_max_metric_router_lsa_startup_cmd
,
8809 "max-metric router-lsa on-startup (5-86400)",
8810 "OSPF maximum / infinite-distance metric\n"
8811 "Advertise own Router-LSA with infinite distance (stub router)\n"
8812 "Automatically advertise stub Router-LSA on startup of OSPF\n"
8813 "Time (seconds) to advertise self as stub-router\n")
8815 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8817 unsigned int seconds
;
8820 vty_out(vty
, "%% Must supply stub-router period");
8821 return CMD_WARNING_CONFIG_FAILED
;
8824 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8826 ospf
->stub_router_startup_time
= seconds
;
8831 DEFUN (no_ospf_max_metric_router_lsa_startup
,
8832 no_ospf_max_metric_router_lsa_startup_cmd
,
8833 "no max-metric router-lsa on-startup [(5-86400)]",
8835 "OSPF maximum / infinite-distance metric\n"
8836 "Advertise own Router-LSA with infinite distance (stub router)\n"
8837 "Automatically advertise stub Router-LSA on startup of OSPF\n"
8838 "Time (seconds) to advertise self as stub-router\n")
8840 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8841 struct listnode
*ln
;
8842 struct ospf_area
*area
;
8844 ospf
->stub_router_startup_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
8846 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8847 SET_FLAG(area
->stub_router_state
,
8848 OSPF_AREA_WAS_START_STUB_ROUTED
);
8849 OSPF_TIMER_OFF(area
->t_stub_router
);
8851 /* Don't trample on admin stub routed */
8852 if (!CHECK_FLAG(area
->stub_router_state
,
8853 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
8854 UNSET_FLAG(area
->stub_router_state
,
8855 OSPF_AREA_IS_STUB_ROUTED
);
8856 ospf_router_lsa_update_area(area
);
8863 DEFUN (ospf_max_metric_router_lsa_shutdown
,
8864 ospf_max_metric_router_lsa_shutdown_cmd
,
8865 "max-metric router-lsa on-shutdown (5-100)",
8866 "OSPF maximum / infinite-distance metric\n"
8867 "Advertise own Router-LSA with infinite distance (stub router)\n"
8868 "Advertise stub-router prior to full shutdown of OSPF\n"
8869 "Time (seconds) to wait till full shutdown\n")
8871 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8873 unsigned int seconds
;
8876 vty_out(vty
, "%% Must supply stub-router shutdown period");
8877 return CMD_WARNING_CONFIG_FAILED
;
8880 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8882 ospf
->stub_router_shutdown_time
= seconds
;
8887 DEFUN (no_ospf_max_metric_router_lsa_shutdown
,
8888 no_ospf_max_metric_router_lsa_shutdown_cmd
,
8889 "no max-metric router-lsa on-shutdown [(5-100)]",
8891 "OSPF maximum / infinite-distance metric\n"
8892 "Advertise own Router-LSA with infinite distance (stub router)\n"
8893 "Advertise stub-router prior to full shutdown of OSPF\n"
8894 "Time (seconds) to wait till full shutdown\n")
8896 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8898 ospf
->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
8903 static void config_write_stub_router(struct vty
*vty
, struct ospf
*ospf
)
8905 struct listnode
*ln
;
8906 struct ospf_area
*area
;
8908 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
8909 vty_out(vty
, " max-metric router-lsa on-startup %u\n",
8910 ospf
->stub_router_startup_time
);
8911 if (ospf
->stub_router_shutdown_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
8912 vty_out(vty
, " max-metric router-lsa on-shutdown %u\n",
8913 ospf
->stub_router_shutdown_time
);
8914 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8915 if (CHECK_FLAG(area
->stub_router_state
,
8916 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
8917 vty_out(vty
, " max-metric router-lsa administrative\n");
8924 static void show_ip_ospf_route_network(struct vty
*vty
, struct ospf
*ospf
,
8925 struct route_table
*rt
,
8928 struct route_node
*rn
;
8929 struct ospf_route
* or ;
8930 struct listnode
*pnode
, *pnnode
;
8931 struct ospf_path
*path
;
8932 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
8933 *json_nexthop
= NULL
;
8937 "============ OSPF network routing table ============\n");
8939 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
8940 if ((or = rn
->info
) == NULL
)
8942 char buf1
[PREFIX2STR_BUFFER
];
8944 memset(buf1
, 0, sizeof(buf1
));
8945 prefix2str(&rn
->p
, buf1
, sizeof(buf1
));
8947 json_route
= json_object_new_object();
8949 json_object_object_add(json
, buf1
, json_route
);
8950 json_object_to_json_string_ext(
8951 json
, JSON_C_TO_STRING_NOSLASHESCAPE
);
8954 switch (or->path_type
) {
8955 case OSPF_PATH_INTER_AREA
:
8956 if (or->type
== OSPF_DESTINATION_NETWORK
) {
8958 json_object_string_add(json_route
,
8961 json_object_int_add(json_route
, "cost",
8963 json_object_string_add(
8965 inet_ntoa(or->u
.std
.area_id
));
8968 "N IA %-18s [%d] area: %s\n",
8970 inet_ntoa(or->u
.std
.area_id
));
8972 } else if (or->type
== OSPF_DESTINATION_DISCARD
) {
8974 json_object_string_add(json_route
,
8979 "D IA %-18s Discard entry\n",
8984 case OSPF_PATH_INTRA_AREA
:
8986 json_object_string_add(json_route
, "routeType",
8988 json_object_int_add(json_route
, "cost",
8990 json_object_string_add(
8992 inet_ntoa(or->u
.std
.area_id
));
8994 vty_out(vty
, "N %-18s [%d] area: %s\n",
8996 inet_ntoa(or->u
.std
.area_id
));
9003 if (or->type
== OSPF_DESTINATION_NETWORK
) {
9005 json_nexthop_array
= json_object_new_array();
9006 json_object_object_add(json_route
, "nexthops",
9007 json_nexthop_array
);
9010 for (ALL_LIST_ELEMENTS(or->paths
, pnode
, pnnode
,
9013 json_nexthop
= json_object_new_object();
9014 json_object_array_add(
9018 if (if_lookup_by_index(path
->ifindex
,
9021 if (path
->nexthop
.s_addr
== 0) {
9023 json_object_string_add(
9026 json_object_string_add(
9028 "directly attached to",
9034 "%24s directly attached to %s\n",
9042 json_object_string_add(
9047 json_object_string_add(
9055 "%24s via %s, %s\n",
9068 json_object_free(json_route
);
9074 static void show_ip_ospf_route_router(struct vty
*vty
, struct ospf
*ospf
,
9075 struct route_table
*rtrs
,
9078 struct route_node
*rn
;
9079 struct ospf_route
* or ;
9080 struct listnode
*pnode
;
9081 struct listnode
*node
;
9082 struct ospf_path
*path
;
9083 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
9084 *json_nexthop
= NULL
;
9088 "============ OSPF router routing table =============\n");
9090 for (rn
= route_top(rtrs
); rn
; rn
= route_next(rn
)) {
9091 if (rn
->info
== NULL
)
9095 json_route
= json_object_new_object();
9097 json_object_object_add(json
, inet_ntoa(rn
->p
.u
.prefix4
),
9099 json_object_string_add(json_route
, "routeType", "R ");
9101 vty_out(vty
, "R %-15s ",
9102 inet_ntoa(rn
->p
.u
.prefix4
));
9105 for (ALL_LIST_ELEMENTS_RO((struct list
*)rn
->info
, node
, or)) {
9108 vty_out(vty
, "%24s", "");
9113 json_object_int_add(json_route
, "cost",
9115 json_object_string_add(
9117 inet_ntoa(or->u
.std
.area_id
));
9118 if (or->path_type
== OSPF_PATH_INTER_AREA
)
9119 json_object_boolean_true_add(json_route
,
9121 if (or->u
.std
.flags
& ROUTER_LSA_BORDER
)
9122 json_object_string_add(json_route
,
9125 else if (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
)
9126 json_object_string_add(json_route
,
9130 vty_out(vty
, "%s [%d] area: %s",
9131 (or->path_type
== OSPF_PATH_INTER_AREA
9134 or->cost
, inet_ntoa(or->u
.std
.area_id
));
9136 vty_out(vty
, "%s%s\n",
9137 (or->u
.std
.flags
& ROUTER_LSA_BORDER
9140 (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
9146 json_nexthop_array
= json_object_new_array();
9147 json_object_object_add(json_route
, "nexthops",
9148 json_nexthop_array
);
9151 for (ALL_LIST_ELEMENTS_RO(or->paths
, pnode
, path
)) {
9153 json_nexthop
= json_object_new_object();
9154 json_object_array_add(
9158 if (if_lookup_by_index(path
->ifindex
,
9160 if (path
->nexthop
.s_addr
== 0) {
9162 json_object_string_add(
9165 json_object_string_add(
9167 "directly attached to",
9173 "%24s directly attached to %s\n",
9181 json_object_string_add(
9186 json_object_string_add(
9194 "%24s via %s, %s\n",
9207 json_object_free(json_route
);
9213 static void show_ip_ospf_route_external(struct vty
*vty
, struct ospf
*ospf
,
9214 struct route_table
*rt
,
9217 struct route_node
*rn
;
9218 struct ospf_route
*er
;
9219 struct listnode
*pnode
, *pnnode
;
9220 struct ospf_path
*path
;
9221 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
9222 *json_nexthop
= NULL
;
9226 "============ OSPF external routing table ===========\n");
9228 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
9229 if ((er
= rn
->info
) == NULL
)
9234 snprintf(buf1
, 19, "%s/%d", inet_ntoa(rn
->p
.u
.prefix4
),
9236 json_route
= json_object_new_object();
9238 json_object_object_add(json
, buf1
, json_route
);
9239 json_object_to_json_string_ext(
9240 json
, JSON_C_TO_STRING_NOSLASHESCAPE
);
9243 switch (er
->path_type
) {
9244 case OSPF_PATH_TYPE1_EXTERNAL
:
9246 json_object_string_add(json_route
, "routeType",
9248 json_object_int_add(json_route
, "cost",
9252 "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI
9254 buf1
, er
->cost
, er
->u
.ext
.tag
);
9257 case OSPF_PATH_TYPE2_EXTERNAL
:
9259 json_object_string_add(json_route
, "routeType",
9261 json_object_int_add(json_route
, "cost",
9265 "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI
9267 buf1
, er
->cost
, er
->u
.ext
.type2_cost
,
9274 json_nexthop_array
= json_object_new_array();
9275 json_object_object_add(json_route
, "nexthops",
9276 json_nexthop_array
);
9279 for (ALL_LIST_ELEMENTS(er
->paths
, pnode
, pnnode
, path
)) {
9281 json_nexthop
= json_object_new_object();
9282 json_object_array_add(json_nexthop_array
,
9286 if (if_lookup_by_index(path
->ifindex
, ospf
->vrf_id
)) {
9287 if (path
->nexthop
.s_addr
== 0) {
9289 json_object_string_add(
9292 json_object_string_add(
9294 "directly attached to",
9300 "%24s directly attached to %s\n",
9308 json_object_string_add(
9312 json_object_string_add(
9313 json_nexthop
, "via",
9319 "%24s via %s, %s\n",
9331 json_object_free(json_route
);
9337 static int show_ip_ospf_border_routers_common(struct vty
*vty
,
9342 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
9344 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
9346 if (ospf
->new_table
== NULL
) {
9347 vty_out(vty
, "No OSPF routing information exist\n");
9351 /* Show Network routes.
9352 show_ip_ospf_route_network (vty, ospf->new_table); */
9354 /* Show Router routes. */
9355 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, NULL
);
9362 DEFUN (show_ip_ospf_border_routers
,
9363 show_ip_ospf_border_routers_cmd
,
9364 "show ip ospf [vrf <NAME|all>] border-routers",
9367 "OSPF information\n"
9370 "Show all the ABR's and ASBR's\n")
9372 struct ospf
*ospf
= NULL
;
9373 struct listnode
*node
= NULL
;
9374 char *vrf_name
= NULL
;
9375 bool all_vrf
= FALSE
;
9376 int ret
= CMD_SUCCESS
;
9379 uint8_t use_vrf
= 0;
9381 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
9384 bool ospf_output
= FALSE
;
9389 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9390 if (!ospf
->oi_running
)
9394 ret
= show_ip_ospf_border_routers_common(
9395 vty
, ospf
, use_vrf
);
9399 vty_out(vty
, "%% OSPF instance not found\n");
9401 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
9402 if (ospf
== NULL
|| !ospf
->oi_running
) {
9403 vty_out(vty
, "%% OSPF instance not found\n");
9407 ret
= show_ip_ospf_border_routers_common(vty
, ospf
,
9411 /* Display default ospf (instance 0) info */
9412 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
9413 if (ospf
== NULL
|| !ospf
->oi_running
) {
9414 vty_out(vty
, "%% OSPF instance not found\n");
9418 ret
= show_ip_ospf_border_routers_common(vty
, ospf
, use_vrf
);
9424 DEFUN (show_ip_ospf_instance_border_routers
,
9425 show_ip_ospf_instance_border_routers_cmd
,
9426 "show ip ospf (1-65535) border-routers",
9429 "OSPF information\n"
9431 "Show all the ABR's and ASBR's\n")
9435 unsigned short instance
= 0;
9437 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9438 ospf
= ospf_lookup_instance(instance
);
9440 return CMD_NOT_MY_INSTANCE
;
9442 if (!ospf
->oi_running
)
9445 return show_ip_ospf_border_routers_common(vty
, ospf
, 0);
9448 static int show_ip_ospf_route_common(struct vty
*vty
, struct ospf
*ospf
,
9449 json_object
*json
, uint8_t use_vrf
)
9451 json_object
*json_vrf
= NULL
;
9454 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
9459 json_vrf
= json_object_new_object();
9464 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
9466 if (ospf
->new_table
== NULL
) {
9467 vty_out(vty
, "No OSPF routing information exist\n");
9471 /* Show Network routes. */
9472 show_ip_ospf_route_network(vty
, ospf
, ospf
->new_table
, json_vrf
);
9474 /* Show Router routes. */
9475 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, json_vrf
);
9477 /* Show AS External routes. */
9478 show_ip_ospf_route_external(vty
, ospf
, ospf
->old_external_route
,
9483 // json_object_object_add(json_vrf, "areas",
9485 if (ospf
->vrf_id
== VRF_DEFAULT
)
9486 json_object_object_add(json
, "default",
9489 json_object_object_add(json
, ospf
->name
,
9499 DEFUN (show_ip_ospf_route
,
9500 show_ip_ospf_route_cmd
,
9501 "show ip ospf [vrf <NAME|all>] route [json]",
9504 "OSPF information\n"
9507 "OSPF routing table\n"
9510 struct ospf
*ospf
= NULL
;
9511 struct listnode
*node
= NULL
;
9512 char *vrf_name
= NULL
;
9513 bool all_vrf
= FALSE
;
9514 int ret
= CMD_SUCCESS
;
9517 uint8_t use_vrf
= 0;
9518 bool uj
= use_json(argc
, argv
);
9519 json_object
*json
= NULL
;
9522 json
= json_object_new_object();
9524 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
9526 /* vrf input is provided could be all or specific vrf*/
9528 bool ospf_output
= FALSE
;
9533 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9534 if (!ospf
->oi_running
)
9537 ret
= show_ip_ospf_route_common(vty
, ospf
, json
,
9542 /* Keep Non-pretty format */
9543 vty_out(vty
, "%s\n",
9544 json_object_to_json_string(json
));
9545 json_object_free(json
);
9546 } else if (!ospf_output
)
9547 vty_out(vty
, "%% OSPF instance not found\n");
9551 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
9552 if (ospf
== NULL
|| !ospf
->oi_running
) {
9554 vty_out(vty
, "%s\n",
9555 json_object_to_json_string_ext(
9556 json
, JSON_C_TO_STRING_PRETTY
));
9557 json_object_free(json
);
9559 vty_out(vty
, "%% OSPF instance not found\n");
9564 /* Display default ospf (instance 0) info */
9565 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
9566 if (ospf
== NULL
|| !ospf
->oi_running
) {
9568 vty_out(vty
, "%s\n",
9569 json_object_to_json_string_ext(
9570 json
, JSON_C_TO_STRING_PRETTY
));
9571 json_object_free(json
);
9573 vty_out(vty
, "%% OSPF instance not found\n");
9580 ret
= show_ip_ospf_route_common(vty
, ospf
, json
, use_vrf
);
9581 /* Keep Non-pretty format */
9583 vty_out(vty
, "%s\n", json_object_to_json_string(json
));
9587 json_object_free(json
);
9592 DEFUN (show_ip_ospf_instance_route
,
9593 show_ip_ospf_instance_route_cmd
,
9594 "show ip ospf (1-65535) route",
9597 "OSPF information\n"
9599 "OSPF routing table\n")
9603 unsigned short instance
= 0;
9605 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9606 ospf
= ospf_lookup_instance(instance
);
9608 return CMD_NOT_MY_INSTANCE
;
9610 if (!ospf
->oi_running
)
9613 return show_ip_ospf_route_common(vty
, ospf
, NULL
, 0);
9617 DEFUN (show_ip_ospf_vrfs
,
9618 show_ip_ospf_vrfs_cmd
,
9619 "show ip ospf vrfs [json]",
9622 "OSPF information\n"
9626 bool uj
= use_json(argc
, argv
);
9627 json_object
*json
= NULL
;
9628 json_object
*json_vrfs
= NULL
;
9629 struct ospf
*ospf
= NULL
;
9630 struct listnode
*node
= NULL
;
9632 static char header
[] = "Name Id RouterId ";
9635 json
= json_object_new_object();
9636 json_vrfs
= json_object_new_object();
9639 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9640 json_object
*json_vrf
= NULL
;
9641 const char *name
= NULL
;
9642 int64_t vrf_id_ui
= 0;
9646 if (!uj
&& count
== 1)
9647 vty_out(vty
, "%s\n", header
);
9649 json_vrf
= json_object_new_object();
9651 if (ospf
->vrf_id
== 0)
9652 name
= VRF_DEFAULT_NAME
;
9656 vrf_id_ui
= (ospf
->vrf_id
== VRF_UNKNOWN
)
9658 : (int64_t)ospf
->vrf_id
;
9661 json_object_int_add(json_vrf
, "vrfId", vrf_id_ui
);
9662 json_object_string_add(json_vrf
, "routerId",
9663 inet_ntoa(ospf
->router_id
));
9665 json_object_object_add(json_vrfs
, name
, json_vrf
);
9668 vty_out(vty
, "%-25s %-5d %-16s \n", name
,
9669 ospf
->vrf_id
, inet_ntoa(ospf
->router_id
));
9674 json_object_object_add(json
, "vrfs", json_vrfs
);
9675 json_object_int_add(json
, "totalVrfs", count
);
9677 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
9678 json
, JSON_C_TO_STRING_PRETTY
));
9679 json_object_free(json
);
9682 vty_out(vty
, "\nTotal number of OSPF VRFs: %d\n",
9689 const char *ospf_abr_type_str
[] = {"unknown", "standard", "ibm", "cisco",
9692 const char *ospf_shortcut_mode_str
[] = {"default", "enable", "disable"};
9694 const char *ospf_int_type_str
[] = {"unknown", /* should never be used. */
9695 "point-to-point", "broadcast",
9696 "non-broadcast", "point-to-multipoint",
9697 "virtual-link", /* should never be used. */
9700 static int config_write_interface_one(struct vty
*vty
, struct vrf
*vrf
)
9702 struct listnode
*node
;
9703 struct interface
*ifp
;
9704 struct crypt_key
*ck
;
9705 struct route_node
*rn
= NULL
;
9706 struct ospf_if_params
*params
;
9708 struct ospf
*ospf
= vrf
->info
;
9710 FOR_ALL_INTERFACES (vrf
, ifp
) {
9712 if (memcmp(ifp
->name
, "VLINK", 5) == 0)
9715 vty_frame(vty
, "!\n");
9716 if (ifp
->vrf_id
== VRF_DEFAULT
)
9717 vty_frame(vty
, "interface %s\n", ifp
->name
);
9719 vty_frame(vty
, "interface %s vrf %s\n", ifp
->name
,
9722 vty_out(vty
, " description %s\n", ifp
->desc
);
9726 params
= IF_DEF_PARAMS(ifp
);
9729 /* Interface Network print. */
9730 if (OSPF_IF_PARAM_CONFIGURED(params
, type
)
9731 && params
->type
!= OSPF_IFTYPE_LOOPBACK
) {
9732 if (params
->type
!= ospf_default_iftype(ifp
)) {
9733 vty_out(vty
, " ip ospf network %s",
9736 if (params
!= IF_DEF_PARAMS(ifp
))
9744 /* OSPF interface authentication print */
9745 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_type
)
9746 && params
->auth_type
!= OSPF_AUTH_NOTSET
) {
9747 const char *auth_str
;
9749 /* Translation tables are not that much help
9750 * here due to syntax
9751 * of the simple option */
9752 switch (params
->auth_type
) {
9754 case OSPF_AUTH_NULL
:
9758 case OSPF_AUTH_SIMPLE
:
9762 case OSPF_AUTH_CRYPTOGRAPHIC
:
9763 auth_str
= " message-digest";
9771 vty_out(vty
, " ip ospf authentication%s",
9773 if (params
!= IF_DEF_PARAMS(ifp
))
9775 inet_ntoa(rn
->p
.u
.prefix4
));
9779 /* Simple Authentication Password print. */
9780 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_simple
)
9781 && params
->auth_simple
[0] != '\0') {
9782 vty_out(vty
, " ip ospf authentication-key %s",
9783 params
->auth_simple
);
9784 if (params
!= IF_DEF_PARAMS(ifp
))
9786 inet_ntoa(rn
->p
.u
.prefix4
));
9790 /* Cryptographic Authentication Key print. */
9791 if (params
&& params
->auth_crypt
) {
9792 for (ALL_LIST_ELEMENTS_RO(params
->auth_crypt
,
9795 " ip ospf message-digest-key %d md5 %s",
9796 ck
->key_id
, ck
->auth_key
);
9797 if (params
!= IF_DEF_PARAMS(ifp
))
9805 /* Interface Output Cost print. */
9806 if (OSPF_IF_PARAM_CONFIGURED(params
, output_cost_cmd
)) {
9807 vty_out(vty
, " ip ospf cost %u",
9808 params
->output_cost_cmd
);
9809 if (params
!= IF_DEF_PARAMS(ifp
))
9811 inet_ntoa(rn
->p
.u
.prefix4
));
9815 /* Hello Interval print. */
9816 if (OSPF_IF_PARAM_CONFIGURED(params
, v_hello
)
9817 && params
->v_hello
!= OSPF_HELLO_INTERVAL_DEFAULT
) {
9818 vty_out(vty
, " ip ospf hello-interval %u",
9820 if (params
!= IF_DEF_PARAMS(ifp
))
9822 inet_ntoa(rn
->p
.u
.prefix4
));
9827 /* Router Dead Interval print. */
9828 if (OSPF_IF_PARAM_CONFIGURED(params
, v_wait
)
9830 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
) {
9831 vty_out(vty
, " ip ospf dead-interval ");
9834 if (OSPF_IF_PARAM_CONFIGURED(params
,
9837 "minimal hello-multiplier %d",
9838 params
->fast_hello
);
9840 vty_out(vty
, "%u", params
->v_wait
);
9842 if (params
!= IF_DEF_PARAMS(ifp
))
9844 inet_ntoa(rn
->p
.u
.prefix4
));
9848 /* Router Priority print. */
9849 if (OSPF_IF_PARAM_CONFIGURED(params
, priority
)
9851 != OSPF_ROUTER_PRIORITY_DEFAULT
) {
9852 vty_out(vty
, " ip ospf priority %u",
9854 if (params
!= IF_DEF_PARAMS(ifp
))
9856 inet_ntoa(rn
->p
.u
.prefix4
));
9860 /* Retransmit Interval print. */
9861 if (OSPF_IF_PARAM_CONFIGURED(params
,
9862 retransmit_interval
)
9863 && params
->retransmit_interval
9864 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
) {
9865 vty_out(vty
, " ip ospf retransmit-interval %u",
9866 params
->retransmit_interval
);
9867 if (params
!= IF_DEF_PARAMS(ifp
))
9869 inet_ntoa(rn
->p
.u
.prefix4
));
9873 /* Transmit Delay print. */
9874 if (OSPF_IF_PARAM_CONFIGURED(params
, transmit_delay
)
9875 && params
->transmit_delay
9876 != OSPF_TRANSMIT_DELAY_DEFAULT
) {
9877 vty_out(vty
, " ip ospf transmit-delay %u",
9878 params
->transmit_delay
);
9879 if (params
!= IF_DEF_PARAMS(ifp
))
9881 inet_ntoa(rn
->p
.u
.prefix4
));
9886 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
9887 if (ospf
&& ospf
->instance
)
9888 vty_out(vty
, " ip ospf %d",
9891 vty_out(vty
, " ip ospf");
9893 char buf
[INET_ADDRSTRLEN
];
9895 area_id2str(buf
, sizeof(buf
), ¶ms
->if_area
,
9896 params
->if_area_id_fmt
);
9897 vty_out(vty
, " area %s", buf
);
9898 if (params
!= IF_DEF_PARAMS(ifp
))
9900 inet_ntoa(rn
->p
.u
.prefix4
));
9905 if (params
&& params
->bfd_info
)
9906 ospf_bfd_write_config(vty
, params
);
9908 /* MTU ignore print. */
9909 if (OSPF_IF_PARAM_CONFIGURED(params
, mtu_ignore
)
9910 && params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
) {
9911 if (params
->mtu_ignore
== 0)
9912 vty_out(vty
, " no ip ospf mtu-ignore");
9914 vty_out(vty
, " ip ospf mtu-ignore");
9915 if (params
!= IF_DEF_PARAMS(ifp
))
9917 inet_ntoa(rn
->p
.u
.prefix4
));
9924 rn
= route_top(IF_OIFS_PARAMS(ifp
));
9926 rn
= route_next(rn
);
9936 ospf_opaque_config_write_if(vty
, ifp
);
9938 vty_endframe(vty
, NULL
);
9944 /* Configuration write function for ospfd. */
9945 static int config_write_interface(struct vty
*vty
)
9948 struct vrf
*vrf
= NULL
;
9950 /* Display all VRF aware OSPF interface configuration */
9951 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
9952 write
+= config_write_interface_one(vty
, vrf
);
9958 static int config_write_network_area(struct vty
*vty
, struct ospf
*ospf
)
9960 struct route_node
*rn
;
9961 uint8_t buf
[INET_ADDRSTRLEN
];
9963 /* `network area' print. */
9964 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
))
9966 struct ospf_network
*n
= rn
->info
;
9968 /* Create Area ID string by specified Area ID format. */
9969 if (n
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
9970 inet_ntop(AF_INET
, &n
->area_id
, (char *)buf
,
9973 sprintf((char *)buf
, "%lu",
9974 (unsigned long int)ntohl(
9975 n
->area_id
.s_addr
));
9977 /* Network print. */
9978 vty_out(vty
, " network %s/%d area %s\n",
9979 inet_ntoa(rn
->p
.u
.prefix4
), rn
->p
.prefixlen
,
9986 static int config_write_ospf_area(struct vty
*vty
, struct ospf
*ospf
)
9988 struct listnode
*node
;
9989 struct ospf_area
*area
;
9990 uint8_t buf
[INET_ADDRSTRLEN
];
9992 /* Area configuration print. */
9993 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
9994 struct route_node
*rn1
;
9996 area_id2str((char *)buf
, sizeof(buf
), &area
->area_id
,
9999 if (area
->auth_type
!= OSPF_AUTH_NULL
) {
10000 if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
10001 vty_out(vty
, " area %s authentication\n", buf
);
10004 " area %s authentication message-digest\n",
10008 if (area
->shortcut_configured
!= OSPF_SHORTCUT_DEFAULT
)
10009 vty_out(vty
, " area %s shortcut %s\n", buf
,
10010 ospf_shortcut_mode_str
10011 [area
->shortcut_configured
]);
10013 if ((area
->external_routing
== OSPF_AREA_STUB
)
10014 || (area
->external_routing
== OSPF_AREA_NSSA
)) {
10015 if (area
->external_routing
== OSPF_AREA_STUB
) {
10016 vty_out(vty
, " area %s stub", buf
);
10017 if (area
->no_summary
)
10018 vty_out(vty
, " no-summary\n");
10019 vty_out(vty
, "\n");
10020 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
10021 switch (area
->NSSATranslatorRole
) {
10022 case OSPF_NSSA_ROLE_NEVER
:
10024 " area %s nssa translate-never\n",
10027 case OSPF_NSSA_ROLE_ALWAYS
:
10029 " area %s nssa translate-always\n",
10032 case OSPF_NSSA_ROLE_CANDIDATE
:
10033 vty_out(vty
, " area %s nssa \n", buf
);
10036 if (area
->no_summary
)
10038 " area %s nssa no-summary\n",
10042 if (area
->default_cost
!= 1)
10043 vty_out(vty
, " area %s default-cost %d\n", buf
,
10044 area
->default_cost
);
10047 for (rn1
= route_top(area
->ranges
); rn1
; rn1
= route_next(rn1
))
10049 struct ospf_area_range
*range
= rn1
->info
;
10051 vty_out(vty
, " area %s range %s/%d", buf
,
10052 inet_ntoa(rn1
->p
.u
.prefix4
),
10055 if (range
->cost_config
10056 != OSPF_AREA_RANGE_COST_UNSPEC
)
10057 vty_out(vty
, " cost %d",
10058 range
->cost_config
);
10060 if (!CHECK_FLAG(range
->flags
,
10061 OSPF_AREA_RANGE_ADVERTISE
))
10062 vty_out(vty
, " not-advertise");
10064 if (CHECK_FLAG(range
->flags
,
10065 OSPF_AREA_RANGE_SUBSTITUTE
))
10066 vty_out(vty
, " substitute %s/%d",
10067 inet_ntoa(range
->subst_addr
),
10068 range
->subst_masklen
);
10070 vty_out(vty
, "\n");
10073 if (EXPORT_NAME(area
))
10074 vty_out(vty
, " area %s export-list %s\n", buf
,
10075 EXPORT_NAME(area
));
10077 if (IMPORT_NAME(area
))
10078 vty_out(vty
, " area %s import-list %s\n", buf
,
10079 IMPORT_NAME(area
));
10081 if (PREFIX_NAME_IN(area
))
10082 vty_out(vty
, " area %s filter-list prefix %s in\n", buf
,
10083 PREFIX_NAME_IN(area
));
10085 if (PREFIX_NAME_OUT(area
))
10086 vty_out(vty
, " area %s filter-list prefix %s out\n",
10087 buf
, PREFIX_NAME_OUT(area
));
10093 static int config_write_ospf_nbr_nbma(struct vty
*vty
, struct ospf
*ospf
)
10095 struct ospf_nbr_nbma
*nbr_nbma
;
10096 struct route_node
*rn
;
10098 /* Static Neighbor configuration print. */
10099 for (rn
= route_top(ospf
->nbr_nbma
); rn
; rn
= route_next(rn
))
10100 if ((nbr_nbma
= rn
->info
)) {
10101 vty_out(vty
, " neighbor %s", inet_ntoa(nbr_nbma
->addr
));
10103 if (nbr_nbma
->priority
10104 != OSPF_NEIGHBOR_PRIORITY_DEFAULT
)
10105 vty_out(vty
, " priority %d",
10106 nbr_nbma
->priority
);
10108 if (nbr_nbma
->v_poll
!= OSPF_POLL_INTERVAL_DEFAULT
)
10109 vty_out(vty
, " poll-interval %d",
10112 vty_out(vty
, "\n");
10118 static int config_write_virtual_link(struct vty
*vty
, struct ospf
*ospf
)
10120 struct listnode
*node
;
10121 struct ospf_vl_data
*vl_data
;
10122 char buf
[INET_ADDRSTRLEN
];
10124 /* Virtual-Link print */
10125 for (ALL_LIST_ELEMENTS_RO(ospf
->vlinks
, node
, vl_data
)) {
10126 struct listnode
*n2
;
10127 struct crypt_key
*ck
;
10128 struct ospf_interface
*oi
;
10130 if (vl_data
!= NULL
) {
10131 area_id2str(buf
, sizeof(buf
), &vl_data
->vl_area_id
,
10132 vl_data
->vl_area_id_fmt
);
10133 oi
= vl_data
->vl_oi
;
10136 if (OSPF_IF_PARAM(oi
, v_hello
)
10137 != OSPF_HELLO_INTERVAL_DEFAULT
10138 || OSPF_IF_PARAM(oi
, v_wait
)
10139 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
10140 || OSPF_IF_PARAM(oi
, retransmit_interval
)
10141 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
10142 || OSPF_IF_PARAM(oi
, transmit_delay
)
10143 != OSPF_TRANSMIT_DELAY_DEFAULT
)
10145 " area %s virtual-link %s hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n",
10146 buf
, inet_ntoa(vl_data
->vl_peer
),
10147 OSPF_IF_PARAM(oi
, v_hello
),
10148 OSPF_IF_PARAM(oi
, retransmit_interval
),
10149 OSPF_IF_PARAM(oi
, transmit_delay
),
10150 OSPF_IF_PARAM(oi
, v_wait
));
10152 vty_out(vty
, " area %s virtual-link %s\n", buf
,
10153 inet_ntoa(vl_data
->vl_peer
));
10155 if (IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)->auth_simple
[0]
10158 " area %s virtual-link %s authentication-key %s\n",
10159 buf
, inet_ntoa(vl_data
->vl_peer
),
10160 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
10163 for (ALL_LIST_ELEMENTS_RO(
10164 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
10168 " area %s virtual-link %s"
10169 " message-digest-key %d md5 %s\n",
10170 buf
, inet_ntoa(vl_data
->vl_peer
),
10171 ck
->key_id
, ck
->auth_key
);
10179 static int config_write_ospf_redistribute(struct vty
*vty
, struct ospf
*ospf
)
10183 /* redistribute print. */
10184 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
10185 struct list
*red_list
;
10186 struct listnode
*node
;
10187 struct ospf_redist
*red
;
10189 red_list
= ospf
->redist
[type
];
10193 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
10194 vty_out(vty
, " redistribute %s",
10195 zebra_route_string(type
));
10197 vty_out(vty
, " %d", red
->instance
);
10199 if (red
->dmetric
.value
>= 0)
10200 vty_out(vty
, " metric %d", red
->dmetric
.value
);
10202 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
10203 vty_out(vty
, " metric-type 1");
10205 if (ROUTEMAP_NAME(red
))
10206 vty_out(vty
, " route-map %s",
10207 ROUTEMAP_NAME(red
));
10209 vty_out(vty
, "\n");
10216 static int config_write_ospf_default_metric(struct vty
*vty
, struct ospf
*ospf
)
10218 if (ospf
->default_metric
!= -1)
10219 vty_out(vty
, " default-metric %d\n", ospf
->default_metric
);
10223 static int config_write_ospf_distribute(struct vty
*vty
, struct ospf
*ospf
)
10226 struct ospf_redist
*red
;
10229 /* distribute-list print. */
10230 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
10231 if (DISTRIBUTE_NAME(ospf
, type
))
10232 vty_out(vty
, " distribute-list %s out %s\n",
10233 DISTRIBUTE_NAME(ospf
, type
),
10234 zebra_route_string(type
));
10236 /* default-information print. */
10237 if (ospf
->default_originate
!= DEFAULT_ORIGINATE_NONE
) {
10238 vty_out(vty
, " default-information originate");
10239 if (ospf
->default_originate
== DEFAULT_ORIGINATE_ALWAYS
)
10240 vty_out(vty
, " always");
10242 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
10244 if (red
->dmetric
.value
>= 0)
10245 vty_out(vty
, " metric %d",
10246 red
->dmetric
.value
);
10248 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
10249 vty_out(vty
, " metric-type 1");
10251 if (ROUTEMAP_NAME(red
))
10252 vty_out(vty
, " route-map %s",
10253 ROUTEMAP_NAME(red
));
10256 vty_out(vty
, "\n");
10263 static int config_write_ospf_distance(struct vty
*vty
, struct ospf
*ospf
)
10265 struct route_node
*rn
;
10266 struct ospf_distance
*odistance
;
10268 if (ospf
->distance_all
)
10269 vty_out(vty
, " distance %d\n", ospf
->distance_all
);
10271 if (ospf
->distance_intra
|| ospf
->distance_inter
10272 || ospf
->distance_external
) {
10273 vty_out(vty
, " distance ospf");
10275 if (ospf
->distance_intra
)
10276 vty_out(vty
, " intra-area %d", ospf
->distance_intra
);
10277 if (ospf
->distance_inter
)
10278 vty_out(vty
, " inter-area %d", ospf
->distance_inter
);
10279 if (ospf
->distance_external
)
10280 vty_out(vty
, " external %d", ospf
->distance_external
);
10282 vty_out(vty
, "\n");
10285 for (rn
= route_top(ospf
->distance_table
); rn
; rn
= route_next(rn
))
10286 if ((odistance
= rn
->info
) != NULL
) {
10287 vty_out(vty
, " distance %d %s/%d %s\n",
10288 odistance
->distance
, inet_ntoa(rn
->p
.u
.prefix4
),
10290 odistance
->access_list
? odistance
->access_list
10296 static int ospf_config_write_one(struct vty
*vty
, struct ospf
*ospf
)
10298 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
10299 struct interface
*ifp
;
10300 struct ospf_interface
*oi
;
10301 struct listnode
*node
= NULL
;
10304 /* `router ospf' print. */
10305 if (ospf
->instance
&& ospf
->name
) {
10306 vty_out(vty
, "router ospf %d vrf %s\n", ospf
->instance
,
10308 } else if (ospf
->instance
) {
10309 vty_out(vty
, "router ospf %d\n", ospf
->instance
);
10310 } else if (ospf
->name
) {
10311 vty_out(vty
, "router ospf vrf %s\n", ospf
->name
);
10313 vty_out(vty
, "router ospf\n");
10315 if (!ospf
->networks
) {
10320 /* Router ID print. */
10321 if (ospf
->router_id_static
.s_addr
!= 0)
10322 vty_out(vty
, " ospf router-id %s\n",
10323 inet_ntoa(ospf
->router_id_static
));
10325 /* ABR type print. */
10326 if (ospf
->abr_type
!= OSPF_ABR_DEFAULT
)
10327 vty_out(vty
, " ospf abr-type %s\n",
10328 ospf_abr_type_str
[ospf
->abr_type
]);
10330 /* log-adjacency-changes flag print. */
10331 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
10332 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
))
10333 vty_out(vty
, " log-adjacency-changes detail\n");
10334 else if (!DFLT_OSPF_LOG_ADJACENCY_CHANGES
)
10335 vty_out(vty
, " log-adjacency-changes\n");
10336 } else if (DFLT_OSPF_LOG_ADJACENCY_CHANGES
) {
10337 vty_out(vty
, " no log-adjacency-changes\n");
10340 /* RFC1583 compatibility flag print -- Compatible with CISCO
10342 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
))
10343 vty_out(vty
, " compatible rfc1583\n");
10345 /* auto-cost reference-bandwidth configuration. */
10346 if (ospf
->ref_bandwidth
!= OSPF_DEFAULT_REF_BANDWIDTH
) {
10348 "! Important: ensure reference bandwidth "
10349 "is consistent across all routers\n");
10350 vty_out(vty
, " auto-cost reference-bandwidth %d\n",
10351 ospf
->ref_bandwidth
);
10354 /* SPF timers print. */
10355 if (ospf
->spf_delay
!= OSPF_SPF_DELAY_DEFAULT
10356 || ospf
->spf_holdtime
!= OSPF_SPF_HOLDTIME_DEFAULT
10357 || ospf
->spf_max_holdtime
!= OSPF_SPF_MAX_HOLDTIME_DEFAULT
)
10358 vty_out(vty
, " timers throttle spf %d %d %d\n", ospf
->spf_delay
,
10359 ospf
->spf_holdtime
, ospf
->spf_max_holdtime
);
10361 /* LSA timers print. */
10362 if (ospf
->min_ls_interval
!= OSPF_MIN_LS_INTERVAL
)
10363 vty_out(vty
, " timers throttle lsa all %d\n",
10364 ospf
->min_ls_interval
);
10365 if (ospf
->min_ls_arrival
!= OSPF_MIN_LS_ARRIVAL
)
10366 vty_out(vty
, " timers lsa min-arrival %d\n",
10367 ospf
->min_ls_arrival
);
10369 /* Write multiplier print. */
10370 if (ospf
->write_oi_count
!= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
)
10371 vty_out(vty
, " ospf write-multiplier %d\n",
10372 ospf
->write_oi_count
);
10374 /* Max-metric router-lsa print */
10375 config_write_stub_router(vty
, ospf
);
10377 /* SPF refresh parameters print. */
10378 if (ospf
->lsa_refresh_interval
!= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
10379 vty_out(vty
, " refresh timer %d\n", ospf
->lsa_refresh_interval
);
10381 /* Redistribute information print. */
10382 config_write_ospf_redistribute(vty
, ospf
);
10384 /* passive-interface print. */
10385 if (ospf
->passive_interface_default
== OSPF_IF_PASSIVE
)
10386 vty_out(vty
, " passive-interface default\n");
10388 FOR_ALL_INTERFACES (vrf
, ifp
)
10389 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp
),
10391 && IF_DEF_PARAMS(ifp
)->passive_interface
10392 != ospf
->passive_interface_default
) {
10393 vty_out(vty
, " %spassive-interface %s\n",
10394 IF_DEF_PARAMS(ifp
)->passive_interface
? ""
10398 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
10399 if (!OSPF_IF_PARAM_CONFIGURED(oi
->params
, passive_interface
))
10401 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(oi
->ifp
),
10402 passive_interface
)) {
10403 if (oi
->params
->passive_interface
10404 == IF_DEF_PARAMS(oi
->ifp
)->passive_interface
)
10406 } else if (oi
->params
->passive_interface
10407 == ospf
->passive_interface_default
)
10410 vty_out(vty
, " %spassive-interface %s %s\n",
10411 oi
->params
->passive_interface
? "" : "no ",
10412 oi
->ifp
->name
, inet_ntoa(oi
->address
->u
.prefix4
));
10415 /* Network area print. */
10416 config_write_network_area(vty
, ospf
);
10418 /* Area config print. */
10419 config_write_ospf_area(vty
, ospf
);
10421 /* static neighbor print. */
10422 config_write_ospf_nbr_nbma(vty
, ospf
);
10424 /* Virtual-Link print. */
10425 config_write_virtual_link(vty
, ospf
);
10427 /* Default metric configuration. */
10428 config_write_ospf_default_metric(vty
, ospf
);
10430 /* Distribute-list and default-information print. */
10431 config_write_ospf_distribute(vty
, ospf
);
10433 /* Distance configuration. */
10434 config_write_ospf_distance(vty
, ospf
);
10436 ospf_opaque_config_write_router(vty
, ospf
);
10442 /* OSPF configuration write function. */
10443 static int ospf_config_write(struct vty
*vty
)
10446 struct listnode
*ospf_node
= NULL
;
10449 if (listcount(om
->ospf
) == 0)
10452 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, ospf_node
, ospf
)) {
10453 /* VRF Default check if it is running.
10454 * Upon daemon start, there could be default instance
10455 * in absence of 'router ospf'/oi_running is disabled. */
10456 if (ospf
->vrf_id
== VRF_DEFAULT
&& ospf
->oi_running
)
10457 write
+= ospf_config_write_one(vty
, ospf
);
10458 /* For Non-Default VRF simply display the configuration,
10459 * even if it is not oi_running. */
10460 else if (ospf
->vrf_id
!= VRF_DEFAULT
)
10461 write
+= ospf_config_write_one(vty
, ospf
);
10466 void ospf_vty_show_init(void)
10468 /* "show ip ospf" commands. */
10469 install_element(VIEW_NODE
, &show_ip_ospf_cmd
);
10471 install_element(VIEW_NODE
, &show_ip_ospf_instance_cmd
);
10473 /* "show ip ospf database" commands. */
10474 install_element(VIEW_NODE
, &show_ip_ospf_database_max_cmd
);
10476 install_element(VIEW_NODE
,
10477 &show_ip_ospf_instance_database_type_adv_router_cmd
);
10478 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_cmd
);
10479 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_max_cmd
);
10481 /* "show ip ospf interface" commands. */
10482 install_element(VIEW_NODE
, &show_ip_ospf_interface_cmd
);
10484 install_element(VIEW_NODE
, &show_ip_ospf_instance_interface_cmd
);
10485 /* "show ip ospf interface traffic */
10486 install_element(VIEW_NODE
, &show_ip_ospf_interface_traffic_cmd
);
10488 /* "show ip ospf neighbor" commands. */
10489 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_detail_cmd
);
10490 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_cmd
);
10491 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_id_cmd
);
10492 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_all_cmd
);
10493 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_cmd
);
10494 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_cmd
);
10495 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_all_cmd
);
10497 install_element(VIEW_NODE
,
10498 &show_ip_ospf_instance_neighbor_int_detail_cmd
);
10499 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_int_cmd
);
10500 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_id_cmd
);
10501 install_element(VIEW_NODE
,
10502 &show_ip_ospf_instance_neighbor_detail_all_cmd
);
10503 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_detail_cmd
);
10504 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_cmd
);
10505 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_all_cmd
);
10507 /* "show ip ospf route" commands. */
10508 install_element(VIEW_NODE
, &show_ip_ospf_route_cmd
);
10509 install_element(VIEW_NODE
, &show_ip_ospf_border_routers_cmd
);
10511 install_element(VIEW_NODE
, &show_ip_ospf_instance_route_cmd
);
10512 install_element(VIEW_NODE
, &show_ip_ospf_instance_border_routers_cmd
);
10514 /* "show ip ospf vrfs" commands. */
10515 install_element(VIEW_NODE
, &show_ip_ospf_vrfs_cmd
);
10519 /* ospfd's interface node. */
10520 static struct cmd_node interface_node
= {INTERFACE_NODE
, "%s(config-if)# ", 1};
10522 /* Initialization of OSPF interface. */
10523 static void ospf_vty_if_init(void)
10525 /* Install interface node. */
10526 install_node(&interface_node
, config_write_interface
);
10529 /* "ip ospf authentication" commands. */
10530 install_element(INTERFACE_NODE
, &ip_ospf_authentication_args_addr_cmd
);
10531 install_element(INTERFACE_NODE
, &ip_ospf_authentication_addr_cmd
);
10532 install_element(INTERFACE_NODE
,
10533 &no_ip_ospf_authentication_args_addr_cmd
);
10534 install_element(INTERFACE_NODE
, &no_ip_ospf_authentication_addr_cmd
);
10535 install_element(INTERFACE_NODE
, &ip_ospf_authentication_key_addr_cmd
);
10536 install_element(INTERFACE_NODE
,
10537 &no_ip_ospf_authentication_key_authkey_addr_cmd
);
10538 install_element(INTERFACE_NODE
,
10539 &no_ospf_authentication_key_authkey_addr_cmd
);
10541 /* "ip ospf message-digest-key" commands. */
10542 install_element(INTERFACE_NODE
, &ip_ospf_message_digest_key_cmd
);
10543 install_element(INTERFACE_NODE
, &no_ip_ospf_message_digest_key_cmd
);
10545 /* "ip ospf cost" commands. */
10546 install_element(INTERFACE_NODE
, &ip_ospf_cost_cmd
);
10547 install_element(INTERFACE_NODE
, &no_ip_ospf_cost_cmd
);
10549 /* "ip ospf mtu-ignore" commands. */
10550 install_element(INTERFACE_NODE
, &ip_ospf_mtu_ignore_addr_cmd
);
10551 install_element(INTERFACE_NODE
, &no_ip_ospf_mtu_ignore_addr_cmd
);
10553 /* "ip ospf dead-interval" commands. */
10554 install_element(INTERFACE_NODE
, &ip_ospf_dead_interval_cmd
);
10555 install_element(INTERFACE_NODE
,
10556 &ip_ospf_dead_interval_minimal_addr_cmd
);
10557 install_element(INTERFACE_NODE
, &no_ip_ospf_dead_interval_cmd
);
10559 /* "ip ospf hello-interval" commands. */
10560 install_element(INTERFACE_NODE
, &ip_ospf_hello_interval_cmd
);
10561 install_element(INTERFACE_NODE
, &no_ip_ospf_hello_interval_cmd
);
10563 /* "ip ospf network" commands. */
10564 install_element(INTERFACE_NODE
, &ip_ospf_network_cmd
);
10565 install_element(INTERFACE_NODE
, &no_ip_ospf_network_cmd
);
10567 /* "ip ospf priority" commands. */
10568 install_element(INTERFACE_NODE
, &ip_ospf_priority_cmd
);
10569 install_element(INTERFACE_NODE
, &no_ip_ospf_priority_cmd
);
10571 /* "ip ospf retransmit-interval" commands. */
10572 install_element(INTERFACE_NODE
, &ip_ospf_retransmit_interval_addr_cmd
);
10573 install_element(INTERFACE_NODE
,
10574 &no_ip_ospf_retransmit_interval_addr_cmd
);
10576 /* "ip ospf transmit-delay" commands. */
10577 install_element(INTERFACE_NODE
, &ip_ospf_transmit_delay_addr_cmd
);
10578 install_element(INTERFACE_NODE
, &no_ip_ospf_transmit_delay_addr_cmd
);
10580 /* "ip ospf area" commands. */
10581 install_element(INTERFACE_NODE
, &ip_ospf_area_cmd
);
10582 install_element(INTERFACE_NODE
, &no_ip_ospf_area_cmd
);
10584 /* These commands are compatibitliy for previous version. */
10585 install_element(INTERFACE_NODE
, &ospf_authentication_key_cmd
);
10586 install_element(INTERFACE_NODE
, &ospf_message_digest_key_cmd
);
10587 install_element(INTERFACE_NODE
, &no_ospf_message_digest_key_cmd
);
10588 install_element(INTERFACE_NODE
, &ospf_dead_interval_cmd
);
10589 install_element(INTERFACE_NODE
, &no_ospf_dead_interval_cmd
);
10590 install_element(INTERFACE_NODE
, &ospf_hello_interval_cmd
);
10591 install_element(INTERFACE_NODE
, &no_ospf_hello_interval_cmd
);
10592 install_element(INTERFACE_NODE
, &ospf_cost_cmd
);
10593 install_element(INTERFACE_NODE
, &no_ospf_cost_cmd
);
10594 install_element(INTERFACE_NODE
, &ospf_network_cmd
);
10595 install_element(INTERFACE_NODE
, &no_ospf_network_cmd
);
10596 install_element(INTERFACE_NODE
, &ospf_priority_cmd
);
10597 install_element(INTERFACE_NODE
, &no_ospf_priority_cmd
);
10598 install_element(INTERFACE_NODE
, &ospf_retransmit_interval_cmd
);
10599 install_element(INTERFACE_NODE
, &no_ospf_retransmit_interval_cmd
);
10600 install_element(INTERFACE_NODE
, &ospf_transmit_delay_cmd
);
10601 install_element(INTERFACE_NODE
, &no_ospf_transmit_delay_cmd
);
10604 static void ospf_vty_zebra_init(void)
10606 install_element(OSPF_NODE
, &ospf_redistribute_source_cmd
);
10607 install_element(OSPF_NODE
, &no_ospf_redistribute_source_cmd
);
10608 install_element(OSPF_NODE
, &ospf_redistribute_instance_source_cmd
);
10609 install_element(OSPF_NODE
, &no_ospf_redistribute_instance_source_cmd
);
10611 install_element(OSPF_NODE
, &ospf_distribute_list_out_cmd
);
10612 install_element(OSPF_NODE
, &no_ospf_distribute_list_out_cmd
);
10614 install_element(OSPF_NODE
, &ospf_default_information_originate_cmd
);
10615 install_element(OSPF_NODE
, &no_ospf_default_information_originate_cmd
);
10617 install_element(OSPF_NODE
, &ospf_default_metric_cmd
);
10618 install_element(OSPF_NODE
, &no_ospf_default_metric_cmd
);
10620 install_element(OSPF_NODE
, &ospf_distance_cmd
);
10621 install_element(OSPF_NODE
, &no_ospf_distance_cmd
);
10622 install_element(OSPF_NODE
, &no_ospf_distance_ospf_cmd
);
10623 install_element(OSPF_NODE
, &ospf_distance_ospf_cmd
);
10625 install_element (OSPF_NODE
, &ospf_distance_source_cmd
);
10626 install_element (OSPF_NODE
, &no_ospf_distance_source_cmd
);
10627 install_element (OSPF_NODE
, &ospf_distance_source_access_list_cmd
);
10628 install_element (OSPF_NODE
, &no_ospf_distance_source_access_list_cmd
);
10632 static struct cmd_node ospf_node
= {OSPF_NODE
, "%s(config-router)# ", 1};
10634 static void ospf_interface_clear(struct interface
*ifp
)
10636 if (!if_is_operative(ifp
))
10639 if (IS_DEBUG_OSPF(ism
, ISM_EVENTS
))
10640 zlog_debug("ISM[%s]: clear by reset", ifp
->name
);
10642 ospf_if_reset(ifp
);
10645 DEFUN (clear_ip_ospf_interface
,
10646 clear_ip_ospf_interface_cmd
,
10647 "clear ip ospf [vrf <NAME>] interface [IFNAME]",
10650 "OSPF information\n"
10652 "Interface information\n"
10653 "Interface name\n")
10655 int idx_ifname
= 0;
10657 struct interface
*ifp
;
10658 struct listnode
*node
;
10659 struct ospf
*ospf
= NULL
;
10660 char *vrf_name
= NULL
;
10661 vrf_id_t vrf_id
= VRF_DEFAULT
;
10662 struct vrf
*vrf
= NULL
;
10664 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
10665 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
10666 if (vrf_name
&& strmatch(vrf_name
, VRF_DEFAULT_NAME
))
10669 vrf
= vrf_lookup_by_name(vrf_name
);
10671 vrf_id
= vrf
->vrf_id
;
10673 if (!argv_find(argv
, argc
, "IFNAME", &idx_ifname
)) {
10674 /* Clear all the ospfv2 interfaces. */
10675 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
10676 if (vrf_id
!= ospf
->vrf_id
)
10679 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
10680 FOR_ALL_INTERFACES (vrf
, ifp
)
10681 ospf_interface_clear(ifp
);
10684 /* Interface name is specified. */
10685 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf_id
);
10687 vty_out(vty
, "No such interface name\n");
10689 ospf_interface_clear(ifp
);
10692 return CMD_SUCCESS
;
10695 void ospf_vty_clear_init(void)
10697 install_element(ENABLE_NODE
, &clear_ip_ospf_interface_cmd
);
10701 /* Install OSPF related vty commands. */
10702 void ospf_vty_init(void)
10704 /* Install ospf top node. */
10705 install_node(&ospf_node
, ospf_config_write
);
10707 /* "router ospf" commands. */
10708 install_element(CONFIG_NODE
, &router_ospf_cmd
);
10709 install_element(CONFIG_NODE
, &no_router_ospf_cmd
);
10712 install_default(OSPF_NODE
);
10714 /* "ospf router-id" commands. */
10715 install_element(OSPF_NODE
, &ospf_router_id_cmd
);
10716 install_element(OSPF_NODE
, &ospf_router_id_old_cmd
);
10717 install_element(OSPF_NODE
, &no_ospf_router_id_cmd
);
10719 /* "passive-interface" commands. */
10720 install_element(OSPF_NODE
, &ospf_passive_interface_addr_cmd
);
10721 install_element(OSPF_NODE
, &no_ospf_passive_interface_addr_cmd
);
10723 /* "ospf abr-type" commands. */
10724 install_element(OSPF_NODE
, &ospf_abr_type_cmd
);
10725 install_element(OSPF_NODE
, &no_ospf_abr_type_cmd
);
10727 /* "ospf log-adjacency-changes" commands. */
10728 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_cmd
);
10729 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_detail_cmd
);
10730 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_cmd
);
10731 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_detail_cmd
);
10733 /* "ospf rfc1583-compatible" commands. */
10734 install_element(OSPF_NODE
, &ospf_compatible_rfc1583_cmd
);
10735 install_element(OSPF_NODE
, &no_ospf_compatible_rfc1583_cmd
);
10736 install_element(OSPF_NODE
, &ospf_rfc1583_flag_cmd
);
10737 install_element(OSPF_NODE
, &no_ospf_rfc1583_flag_cmd
);
10739 /* "network area" commands. */
10740 install_element(OSPF_NODE
, &ospf_network_area_cmd
);
10741 install_element(OSPF_NODE
, &no_ospf_network_area_cmd
);
10743 /* "area authentication" commands. */
10744 install_element(OSPF_NODE
,
10745 &ospf_area_authentication_message_digest_cmd
);
10746 install_element(OSPF_NODE
, &ospf_area_authentication_cmd
);
10747 install_element(OSPF_NODE
, &no_ospf_area_authentication_cmd
);
10749 /* "area range" commands. */
10750 install_element(OSPF_NODE
, &ospf_area_range_cmd
);
10751 install_element(OSPF_NODE
, &ospf_area_range_cost_cmd
);
10752 install_element(OSPF_NODE
, &ospf_area_range_not_advertise_cmd
);
10753 install_element(OSPF_NODE
, &no_ospf_area_range_cmd
);
10754 install_element(OSPF_NODE
, &ospf_area_range_substitute_cmd
);
10755 install_element(OSPF_NODE
, &no_ospf_area_range_substitute_cmd
);
10757 /* "area virtual-link" commands. */
10758 install_element(OSPF_NODE
, &ospf_area_vlink_cmd
);
10759 install_element(OSPF_NODE
, &ospf_area_vlink_intervals_cmd
);
10760 install_element(OSPF_NODE
, &no_ospf_area_vlink_cmd
);
10761 install_element(OSPF_NODE
, &no_ospf_area_vlink_intervals_cmd
);
10764 /* "area stub" commands. */
10765 install_element(OSPF_NODE
, &ospf_area_stub_no_summary_cmd
);
10766 install_element(OSPF_NODE
, &ospf_area_stub_cmd
);
10767 install_element(OSPF_NODE
, &no_ospf_area_stub_no_summary_cmd
);
10768 install_element(OSPF_NODE
, &no_ospf_area_stub_cmd
);
10770 /* "area nssa" commands. */
10771 install_element(OSPF_NODE
, &ospf_area_nssa_cmd
);
10772 install_element(OSPF_NODE
, &ospf_area_nssa_translate_cmd
);
10773 install_element(OSPF_NODE
, &ospf_area_nssa_no_summary_cmd
);
10774 install_element(OSPF_NODE
, &no_ospf_area_nssa_no_summary_cmd
);
10775 install_element(OSPF_NODE
, &no_ospf_area_nssa_cmd
);
10777 install_element(OSPF_NODE
, &ospf_area_default_cost_cmd
);
10778 install_element(OSPF_NODE
, &no_ospf_area_default_cost_cmd
);
10780 install_element(OSPF_NODE
, &ospf_area_shortcut_cmd
);
10781 install_element(OSPF_NODE
, &no_ospf_area_shortcut_cmd
);
10783 install_element(OSPF_NODE
, &ospf_area_export_list_cmd
);
10784 install_element(OSPF_NODE
, &no_ospf_area_export_list_cmd
);
10786 install_element(OSPF_NODE
, &ospf_area_filter_list_cmd
);
10787 install_element(OSPF_NODE
, &no_ospf_area_filter_list_cmd
);
10789 install_element(OSPF_NODE
, &ospf_area_import_list_cmd
);
10790 install_element(OSPF_NODE
, &no_ospf_area_import_list_cmd
);
10792 /* SPF timer commands */
10793 install_element(OSPF_NODE
, &ospf_timers_throttle_spf_cmd
);
10794 install_element(OSPF_NODE
, &no_ospf_timers_throttle_spf_cmd
);
10796 /* LSA timers commands */
10797 install_element(OSPF_NODE
, &ospf_timers_min_ls_interval_cmd
);
10798 install_element(OSPF_NODE
, &no_ospf_timers_min_ls_interval_cmd
);
10799 install_element(OSPF_NODE
, &ospf_timers_lsa_min_arrival_cmd
);
10800 install_element(OSPF_NODE
, &no_ospf_timers_lsa_min_arrival_cmd
);
10802 /* refresh timer commands */
10803 install_element(OSPF_NODE
, &ospf_refresh_timer_cmd
);
10804 install_element(OSPF_NODE
, &no_ospf_refresh_timer_val_cmd
);
10806 /* max-metric commands */
10807 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_admin_cmd
);
10808 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_admin_cmd
);
10809 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_startup_cmd
);
10810 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_startup_cmd
);
10811 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_shutdown_cmd
);
10812 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_shutdown_cmd
);
10814 /* reference bandwidth commands */
10815 install_element(OSPF_NODE
, &ospf_auto_cost_reference_bandwidth_cmd
);
10816 install_element(OSPF_NODE
, &no_ospf_auto_cost_reference_bandwidth_cmd
);
10818 /* "neighbor" commands. */
10819 install_element(OSPF_NODE
, &ospf_neighbor_cmd
);
10820 install_element(OSPF_NODE
, &ospf_neighbor_poll_interval_cmd
);
10821 install_element(OSPF_NODE
, &no_ospf_neighbor_cmd
);
10822 install_element(OSPF_NODE
, &no_ospf_neighbor_poll_cmd
);
10824 /* write multiplier commands */
10825 install_element(OSPF_NODE
, &ospf_write_multiplier_cmd
);
10826 install_element(OSPF_NODE
, &write_multiplier_cmd
);
10827 install_element(OSPF_NODE
, &no_ospf_write_multiplier_cmd
);
10828 install_element(OSPF_NODE
, &no_write_multiplier_cmd
);
10830 /* Init interface related vty commands. */
10831 ospf_vty_if_init();
10833 /* Init zebra related vty commands. */
10834 ospf_vty_zebra_init();