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
;
1208 vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
.vl_peer
);
1210 vty_out(vty
, "Virtual link does not exist\n");
1211 return CMD_WARNING_CONFIG_FAILED
;
1215 /* Basic VLink no command */
1216 /* Thats all folks! - BUGS B. strikes again!!!*/
1217 ospf_vl_delete(ospf
, vl_data
);
1218 ospf_area_check_free(ospf
, vl_config
.area_id
);
1222 /* If we are down here, we are reseting parameters */
1223 /* Deal with other parameters */
1225 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1226 /* authentication - this option can only occur
1227 at start of command line */
1228 vl_config
.auth_type
= OSPF_AUTH_NOTSET
;
1231 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1232 vl_config
.md5_key
= NULL
;
1233 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1234 if (vl_config
.crypto_key_id
< 0)
1235 return CMD_WARNING_CONFIG_FAILED
;
1238 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1239 /* Reset authentication-key to 0 */
1240 memset(auth_key
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
1241 vl_config
.auth_key
= auth_key
;
1244 /* Action configuration */
1246 return ospf_vl_set(ospf
, &vl_config
);
1249 DEFUN (ospf_area_vlink_intervals
,
1250 ospf_area_vlink_intervals_cmd
,
1251 "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)}",
1252 VLINK_HELPSTR_IPADDR
1253 VLINK_HELPSTR_TIME_PARAM
)
1255 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1256 struct ospf_vl_config_data vl_config
;
1259 ospf_vl_config_data_init(&vl_config
, vty
);
1261 char *area_id
= argv
[1]->arg
;
1262 char *router_id
= argv
[3]->arg
;
1264 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1266 vty_out(vty
, "OSPF area ID is invalid\n");
1267 return CMD_WARNING_CONFIG_FAILED
;
1270 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1272 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1273 return CMD_WARNING_CONFIG_FAILED
;
1276 for (int idx
= 4; idx
< argc
; idx
++) {
1277 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1278 vl_config
.hello_interval
=
1279 strtol(argv
[++idx
]->arg
, NULL
, 10);
1280 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1281 vl_config
.retransmit_interval
=
1282 strtol(argv
[++idx
]->arg
, NULL
, 10);
1283 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1284 vl_config
.transmit_delay
=
1285 strtol(argv
[++idx
]->arg
, NULL
, 10);
1286 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1287 vl_config
.dead_interval
=
1288 strtol(argv
[++idx
]->arg
, NULL
, 10);
1291 /* Action configuration */
1292 return ospf_vl_set(ospf
, &vl_config
);
1295 DEFUN (no_ospf_area_vlink_intervals
,
1296 no_ospf_area_vlink_intervals_cmd
,
1297 "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)}",
1299 VLINK_HELPSTR_IPADDR
1300 VLINK_HELPSTR_TIME_PARAM
)
1302 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1303 struct ospf_vl_config_data vl_config
;
1306 ospf_vl_config_data_init(&vl_config
, vty
);
1308 char *area_id
= argv
[2]->arg
;
1309 char *router_id
= argv
[4]->arg
;
1311 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1313 vty_out(vty
, "OSPF area ID is invalid\n");
1314 return CMD_WARNING_CONFIG_FAILED
;
1317 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1319 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1320 return CMD_WARNING_CONFIG_FAILED
;
1323 for (int idx
= 5; idx
< argc
; idx
++) {
1324 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1325 vl_config
.hello_interval
= OSPF_HELLO_INTERVAL_DEFAULT
;
1326 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1327 vl_config
.retransmit_interval
=
1328 OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
1329 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1330 vl_config
.transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
1331 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1332 vl_config
.dead_interval
=
1333 OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
1336 /* Action configuration */
1337 return ospf_vl_set(ospf
, &vl_config
);
1340 DEFUN (ospf_area_shortcut
,
1341 ospf_area_shortcut_cmd
,
1342 "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>",
1343 "OSPF area parameters\n"
1344 "OSPF area ID in IP address format\n"
1345 "OSPF area ID as a decimal value\n"
1346 "Configure the area's shortcutting mode\n"
1347 "Set default shortcutting behavior\n"
1348 "Enable shortcutting through the area\n"
1349 "Disable shortcutting through the area\n")
1351 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1352 int idx_ipv4_number
= 1;
1353 int idx_enable_disable
= 3;
1354 struct ospf_area
*area
;
1355 struct in_addr area_id
;
1359 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1360 argv
[idx_ipv4_number
]->arg
);
1362 area
= ospf_area_get(ospf
, area_id
);
1363 ospf_area_display_format_set(ospf
, area
, format
);
1365 if (strncmp(argv
[idx_enable_disable
]->arg
, "de", 2) == 0)
1366 mode
= OSPF_SHORTCUT_DEFAULT
;
1367 else if (strncmp(argv
[idx_enable_disable
]->arg
, "di", 2) == 0)
1368 mode
= OSPF_SHORTCUT_DISABLE
;
1369 else if (strncmp(argv
[idx_enable_disable
]->arg
, "e", 1) == 0)
1370 mode
= OSPF_SHORTCUT_ENABLE
;
1372 return CMD_WARNING_CONFIG_FAILED
;
1374 ospf_area_shortcut_set(ospf
, area
, mode
);
1376 if (ospf
->abr_type
!= OSPF_ABR_SHORTCUT
)
1378 "Shortcut area setting will take effect "
1379 "only when the router is configured as Shortcut ABR\n");
1384 DEFUN (no_ospf_area_shortcut
,
1385 no_ospf_area_shortcut_cmd
,
1386 "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>",
1388 "OSPF area parameters\n"
1389 "OSPF area ID in IP address format\n"
1390 "OSPF area ID as a decimal value\n"
1391 "Deconfigure the area's shortcutting mode\n"
1392 "Deconfigure enabled shortcutting through the area\n"
1393 "Deconfigure disabled shortcutting through the area\n")
1395 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1396 int idx_ipv4_number
= 2;
1397 struct ospf_area
*area
;
1398 struct in_addr area_id
;
1401 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1402 argv
[idx_ipv4_number
]->arg
);
1404 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1408 ospf_area_shortcut_unset(ospf
, area
);
1414 DEFUN (ospf_area_stub
,
1416 "area <A.B.C.D|(0-4294967295)> stub",
1417 "OSPF area parameters\n"
1418 "OSPF area ID in IP address format\n"
1419 "OSPF area ID as a decimal value\n"
1420 "Configure OSPF area as stub\n")
1422 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1423 int idx_ipv4_number
= 1;
1424 struct in_addr area_id
;
1427 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1428 argv
[idx_ipv4_number
]->arg
);
1430 ret
= ospf_area_stub_set(ospf
, area_id
);
1431 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1435 "First deconfigure all virtual link through this area\n");
1436 return CMD_WARNING_CONFIG_FAILED
;
1439 ospf_area_no_summary_unset(ospf
, area_id
);
1444 DEFUN (ospf_area_stub_no_summary
,
1445 ospf_area_stub_no_summary_cmd
,
1446 "area <A.B.C.D|(0-4294967295)> stub no-summary",
1447 "OSPF stub parameters\n"
1448 "OSPF area ID in IP address format\n"
1449 "OSPF area ID as a decimal value\n"
1450 "Configure OSPF area as stub\n"
1451 "Do not inject inter-area routes into stub\n")
1453 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1454 int idx_ipv4_number
= 1;
1455 struct in_addr area_id
;
1458 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1459 argv
[idx_ipv4_number
]->arg
);
1461 ret
= ospf_area_stub_set(ospf
, area_id
);
1462 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1466 "%% Area cannot be stub as it contains a virtual link\n");
1467 return CMD_WARNING_CONFIG_FAILED
;
1470 ospf_area_no_summary_set(ospf
, area_id
);
1475 DEFUN (no_ospf_area_stub
,
1476 no_ospf_area_stub_cmd
,
1477 "no area <A.B.C.D|(0-4294967295)> stub",
1479 "OSPF area parameters\n"
1480 "OSPF area ID in IP address format\n"
1481 "OSPF area ID as a decimal value\n"
1482 "Configure OSPF area as stub\n")
1484 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1485 int idx_ipv4_number
= 2;
1486 struct in_addr area_id
;
1489 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1490 argv
[idx_ipv4_number
]->arg
);
1492 ospf_area_stub_unset(ospf
, area_id
);
1493 ospf_area_no_summary_unset(ospf
, area_id
);
1498 DEFUN (no_ospf_area_stub_no_summary
,
1499 no_ospf_area_stub_no_summary_cmd
,
1500 "no area <A.B.C.D|(0-4294967295)> stub no-summary",
1502 "OSPF area parameters\n"
1503 "OSPF area ID in IP address format\n"
1504 "OSPF area ID as a decimal value\n"
1505 "Configure OSPF area as stub\n"
1506 "Do not inject inter-area routes into area\n")
1508 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1509 int idx_ipv4_number
= 2;
1510 struct in_addr area_id
;
1513 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1514 argv
[idx_ipv4_number
]->arg
);
1515 ospf_area_no_summary_unset(ospf
, area_id
);
1520 static int ospf_area_nssa_cmd_handler(struct vty
*vty
, int argc
,
1521 struct cmd_token
**argv
, int cfg_nosum
,
1524 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1525 struct in_addr area_id
;
1528 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
, argv
[1]->arg
);
1530 ret
= ospf_area_nssa_set(ospf
, area_id
);
1531 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1535 "%% Area cannot be nssa as it contains a virtual link\n");
1536 return CMD_WARNING_CONFIG_FAILED
;
1540 if (strncmp(argv
[3]->text
, "translate-c", 11) == 0)
1541 ospf_area_nssa_translator_role_set(
1542 ospf
, area_id
, OSPF_NSSA_ROLE_CANDIDATE
);
1543 else if (strncmp(argv
[3]->text
, "translate-n", 11) == 0)
1544 ospf_area_nssa_translator_role_set(
1545 ospf
, area_id
, OSPF_NSSA_ROLE_NEVER
);
1546 else if (strncmp(argv
[3]->text
, "translate-a", 11) == 0)
1547 ospf_area_nssa_translator_role_set(
1548 ospf
, area_id
, OSPF_NSSA_ROLE_ALWAYS
);
1550 ospf_area_nssa_translator_role_set(ospf
, area_id
,
1551 OSPF_NSSA_ROLE_CANDIDATE
);
1556 ospf_area_no_summary_set(ospf
, area_id
);
1558 ospf_area_no_summary_unset(ospf
, area_id
);
1561 ospf_schedule_abr_task(ospf
);
1567 DEFUN (ospf_area_nssa_translate
,
1568 ospf_area_nssa_translate_cmd
,
1569 "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always>",
1570 "OSPF area parameters\n"
1571 "OSPF area ID in IP address format\n"
1572 "OSPF area ID as a decimal value\n"
1573 "Configure OSPF area as nssa\n"
1574 "Configure NSSA-ABR for translate election (default)\n"
1575 "Configure NSSA-ABR to never translate\n"
1576 "Configure NSSA-ABR to always translate\n")
1578 return ospf_area_nssa_cmd_handler(vty
, argc
, argv
, 0, 0);
1581 DEFUN (ospf_area_nssa
,
1583 "area <A.B.C.D|(0-4294967295)> nssa",
1584 "OSPF area parameters\n"
1585 "OSPF area ID in IP address format\n"
1586 "OSPF area ID as a decimal value\n"
1587 "Configure OSPF area as nssa\n")
1589 return ospf_area_nssa_cmd_handler(vty
, argc
, argv
, 0, 0);
1592 DEFUN (ospf_area_nssa_no_summary
,
1593 ospf_area_nssa_no_summary_cmd
,
1594 "area <A.B.C.D|(0-4294967295)> nssa no-summary",
1595 "OSPF area parameters\n"
1596 "OSPF area ID in IP address format\n"
1597 "OSPF area ID as a decimal value\n"
1598 "Configure OSPF area as nssa\n"
1599 "Do not inject inter-area routes into nssa\n")
1601 int idx_ipv4_number
= 1;
1602 struct in_addr area_id
;
1605 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1606 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1607 argv
[idx_ipv4_number
]->arg
);
1609 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1611 ospf_area_nssa_no_summary_set(ospf
, area_id
);
1613 ospf_schedule_abr_task(ospf
);
1618 DEFUN (no_ospf_area_nssa_no_summary
,
1619 no_ospf_area_nssa_no_summary_cmd
,
1620 "no area <A.B.C.D|(0-4294967295)> nssa no-summary",
1622 "OSPF area parameters\n"
1623 "OSPF area ID in IP address format\n"
1624 "OSPF area ID as a decimal value\n"
1625 "Configure OSPF area as nssa\n"
1626 "Do not inject inter-area routes into nssa\n")
1628 int idx_ipv4_number
= 2;
1629 struct in_addr area_id
;
1632 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1634 VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id
, format
,
1635 argv
[idx_ipv4_number
]->arg
);
1637 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1639 ospf_area_no_summary_unset(ospf
, area_id
);
1641 ospf_schedule_abr_task(ospf
);
1646 DEFUN (no_ospf_area_nssa
,
1647 no_ospf_area_nssa_cmd
,
1648 "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always>]",
1650 "OSPF area parameters\n"
1651 "OSPF area ID in IP address format\n"
1652 "OSPF area ID as a decimal value\n"
1653 "Configure OSPF area as nssa\n"
1654 "Configure NSSA-ABR for translate election (default)\n"
1655 "Configure NSSA-ABR to never translate\n"
1656 "Configure NSSA-ABR to always translate\n")
1658 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1659 int idx_ipv4_number
= 2;
1660 struct in_addr area_id
;
1663 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1664 argv
[idx_ipv4_number
]->arg
);
1666 ospf_area_nssa_unset(ospf
, area_id
, argc
);
1668 ospf_schedule_abr_task(ospf
);
1674 DEFUN (ospf_area_default_cost
,
1675 ospf_area_default_cost_cmd
,
1676 "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1677 "OSPF area parameters\n"
1678 "OSPF area ID in IP address format\n"
1679 "OSPF area ID as a decimal value\n"
1680 "Set the summary-default cost of a NSSA or stub area\n"
1681 "Stub's advertised default summary cost\n")
1683 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1684 int idx_ipv4_number
= 1;
1686 struct ospf_area
*area
;
1687 struct in_addr area_id
;
1690 struct prefix_ipv4 p
;
1692 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1693 argv
[idx_ipv4_number
]->arg
);
1694 cost
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1696 area
= ospf_area_get(ospf
, area_id
);
1697 ospf_area_display_format_set(ospf
, area
, format
);
1699 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1700 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1701 return CMD_WARNING_CONFIG_FAILED
;
1704 area
->default_cost
= cost
;
1707 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1709 if (IS_DEBUG_OSPF_EVENT
)
1711 "ospf_abr_announce_stub_defaults(): "
1712 "announcing 0.0.0.0/0 to area %s",
1713 inet_ntoa(area
->area_id
));
1714 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1719 DEFUN (no_ospf_area_default_cost
,
1720 no_ospf_area_default_cost_cmd
,
1721 "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1723 "OSPF area parameters\n"
1724 "OSPF area ID in IP address format\n"
1725 "OSPF area ID as a decimal value\n"
1726 "Set the summary-default cost of a NSSA or stub area\n"
1727 "Stub's advertised default summary cost\n")
1729 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1730 int idx_ipv4_number
= 2;
1731 struct ospf_area
*area
;
1732 struct in_addr area_id
;
1734 struct prefix_ipv4 p
;
1736 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1737 argv
[idx_ipv4_number
]->arg
);
1739 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1743 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1744 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1745 return CMD_WARNING_CONFIG_FAILED
;
1748 area
->default_cost
= 1;
1751 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1753 if (IS_DEBUG_OSPF_EVENT
)
1755 "ospf_abr_announce_stub_defaults(): "
1756 "announcing 0.0.0.0/0 to area %s",
1757 inet_ntoa(area
->area_id
));
1758 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1761 ospf_area_check_free(ospf
, area_id
);
1766 DEFUN (ospf_area_export_list
,
1767 ospf_area_export_list_cmd
,
1768 "area <A.B.C.D|(0-4294967295)> export-list NAME",
1769 "OSPF area parameters\n"
1770 "OSPF area ID in IP address format\n"
1771 "OSPF area ID as a decimal value\n"
1772 "Set the filter for networks announced to other areas\n"
1773 "Name of the access-list\n")
1775 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1776 int idx_ipv4_number
= 1;
1777 struct ospf_area
*area
;
1778 struct in_addr area_id
;
1781 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1783 area
= ospf_area_get(ospf
, area_id
);
1784 ospf_area_display_format_set(ospf
, area
, format
);
1785 ospf_area_export_list_set(ospf
, area
, argv
[3]->arg
);
1790 DEFUN (no_ospf_area_export_list
,
1791 no_ospf_area_export_list_cmd
,
1792 "no area <A.B.C.D|(0-4294967295)> export-list NAME",
1794 "OSPF area parameters\n"
1795 "OSPF area ID in IP address format\n"
1796 "OSPF area ID as a decimal value\n"
1797 "Unset the filter for networks announced to other areas\n"
1798 "Name of the access-list\n")
1800 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1801 int idx_ipv4_number
= 2;
1802 struct ospf_area
*area
;
1803 struct in_addr area_id
;
1806 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1808 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1812 ospf_area_export_list_unset(ospf
, area
);
1818 DEFUN (ospf_area_import_list
,
1819 ospf_area_import_list_cmd
,
1820 "area <A.B.C.D|(0-4294967295)> import-list NAME",
1821 "OSPF area parameters\n"
1822 "OSPF area ID in IP address format\n"
1823 "OSPF area ID as a decimal value\n"
1824 "Set the filter for networks from other areas announced to the specified one\n"
1825 "Name of the access-list\n")
1827 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1828 int idx_ipv4_number
= 1;
1829 struct ospf_area
*area
;
1830 struct in_addr area_id
;
1833 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1835 area
= ospf_area_get(ospf
, area_id
);
1836 ospf_area_display_format_set(ospf
, area
, format
);
1837 ospf_area_import_list_set(ospf
, area
, argv
[3]->arg
);
1842 DEFUN (no_ospf_area_import_list
,
1843 no_ospf_area_import_list_cmd
,
1844 "no area <A.B.C.D|(0-4294967295)> import-list NAME",
1846 "OSPF area parameters\n"
1847 "OSPF area ID in IP address format\n"
1848 "OSPF area ID as a decimal value\n"
1849 "Unset the filter for networks announced to other areas\n"
1850 "Name of the access-list\n")
1852 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1853 int idx_ipv4_number
= 2;
1854 struct ospf_area
*area
;
1855 struct in_addr area_id
;
1858 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1860 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1864 ospf_area_import_list_unset(ospf
, area
);
1869 DEFUN (ospf_area_filter_list
,
1870 ospf_area_filter_list_cmd
,
1871 "area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>",
1872 "OSPF area parameters\n"
1873 "OSPF area ID in IP address format\n"
1874 "OSPF area ID as a decimal value\n"
1875 "Filter networks between OSPF areas\n"
1876 "Filter prefixes between OSPF areas\n"
1877 "Name of an IP prefix-list\n"
1878 "Filter networks sent to this area\n"
1879 "Filter networks sent from this area\n")
1881 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1882 int idx_ipv4_number
= 1;
1885 struct ospf_area
*area
;
1886 struct in_addr area_id
;
1887 struct prefix_list
*plist
;
1890 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1892 area
= ospf_area_get(ospf
, area_id
);
1893 ospf_area_display_format_set(ospf
, area
, format
);
1894 plist
= prefix_list_lookup(AFI_IP
, argv
[idx_word
]->arg
);
1895 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1896 PREFIX_LIST_IN(area
) = plist
;
1897 if (PREFIX_NAME_IN(area
))
1898 free(PREFIX_NAME_IN(area
));
1900 PREFIX_NAME_IN(area
) = strdup(argv
[idx_word
]->arg
);
1901 ospf_schedule_abr_task(ospf
);
1903 PREFIX_LIST_OUT(area
) = plist
;
1904 if (PREFIX_NAME_OUT(area
))
1905 free(PREFIX_NAME_OUT(area
));
1907 PREFIX_NAME_OUT(area
) = strdup(argv
[idx_word
]->arg
);
1908 ospf_schedule_abr_task(ospf
);
1914 DEFUN (no_ospf_area_filter_list
,
1915 no_ospf_area_filter_list_cmd
,
1916 "no area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>",
1918 "OSPF area parameters\n"
1919 "OSPF area ID in IP address format\n"
1920 "OSPF area ID as a decimal value\n"
1921 "Filter networks between OSPF areas\n"
1922 "Filter prefixes between OSPF areas\n"
1923 "Name of an IP prefix-list\n"
1924 "Filter networks sent to this area\n"
1925 "Filter networks sent from this area\n")
1927 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1928 int idx_ipv4_number
= 2;
1931 struct ospf_area
*area
;
1932 struct in_addr area_id
;
1935 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1937 if ((area
= ospf_area_lookup_by_area_id(ospf
, area_id
)) == NULL
)
1940 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1941 if (PREFIX_NAME_IN(area
))
1942 if (strcmp(PREFIX_NAME_IN(area
), argv
[idx_word
]->arg
)
1946 PREFIX_LIST_IN(area
) = NULL
;
1947 if (PREFIX_NAME_IN(area
))
1948 free(PREFIX_NAME_IN(area
));
1950 PREFIX_NAME_IN(area
) = NULL
;
1952 ospf_schedule_abr_task(ospf
);
1954 if (PREFIX_NAME_OUT(area
))
1955 if (strcmp(PREFIX_NAME_OUT(area
), argv
[idx_word
]->arg
)
1959 PREFIX_LIST_OUT(area
) = NULL
;
1960 if (PREFIX_NAME_OUT(area
))
1961 free(PREFIX_NAME_OUT(area
));
1963 PREFIX_NAME_OUT(area
) = NULL
;
1965 ospf_schedule_abr_task(ospf
);
1972 DEFUN (ospf_area_authentication_message_digest
,
1973 ospf_area_authentication_message_digest_cmd
,
1974 "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest",
1976 "OSPF area parameters\n"
1977 "OSPF area ID in IP address format\n"
1978 "OSPF area ID as a decimal value\n"
1979 "Enable authentication\n"
1980 "Use message-digest authentication\n")
1982 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1984 struct ospf_area
*area
;
1985 struct in_addr area_id
;
1988 argv_find(argv
, argc
, "area", &idx
);
1989 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx
+ 1]->arg
);
1991 area
= ospf_area_get(ospf
, area_id
);
1992 ospf_area_display_format_set(ospf
, area
, format
);
1993 area
->auth_type
= strmatch(argv
[0]->text
, "no")
1995 : OSPF_AUTH_CRYPTOGRAPHIC
;
2000 DEFUN (ospf_area_authentication
,
2001 ospf_area_authentication_cmd
,
2002 "area <A.B.C.D|(0-4294967295)> authentication",
2003 "OSPF area parameters\n"
2004 "OSPF area ID in IP address format\n"
2005 "OSPF area ID as a decimal value\n"
2006 "Enable authentication\n")
2008 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2009 int idx_ipv4_number
= 1;
2010 struct ospf_area
*area
;
2011 struct in_addr area_id
;
2014 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
2016 area
= ospf_area_get(ospf
, area_id
);
2017 ospf_area_display_format_set(ospf
, area
, format
);
2018 area
->auth_type
= OSPF_AUTH_SIMPLE
;
2023 DEFUN (no_ospf_area_authentication
,
2024 no_ospf_area_authentication_cmd
,
2025 "no area <A.B.C.D|(0-4294967295)> authentication",
2027 "OSPF area parameters\n"
2028 "OSPF area ID in IP address format\n"
2029 "OSPF area ID as a decimal value\n"
2030 "Enable authentication\n")
2032 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2033 int idx_ipv4_number
= 2;
2034 struct ospf_area
*area
;
2035 struct in_addr area_id
;
2038 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
2040 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
2044 area
->auth_type
= OSPF_AUTH_NULL
;
2046 ospf_area_check_free(ospf
, area_id
);
2052 DEFUN (ospf_abr_type
,
2054 "ospf abr-type <cisco|ibm|shortcut|standard>",
2055 "OSPF specific commands\n"
2056 "Set OSPF ABR type\n"
2057 "Alternative ABR, cisco implementation\n"
2058 "Alternative ABR, IBM implementation\n"
2060 "Standard behavior (RFC2328)\n")
2062 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2064 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2066 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2067 abr_type
= OSPF_ABR_CISCO
;
2068 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2069 abr_type
= OSPF_ABR_IBM
;
2070 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2071 abr_type
= OSPF_ABR_SHORTCUT
;
2072 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2073 abr_type
= OSPF_ABR_STAND
;
2075 return CMD_WARNING_CONFIG_FAILED
;
2077 /* If ABR type value is changed, schedule ABR task. */
2078 if (ospf
->abr_type
!= abr_type
) {
2079 ospf
->abr_type
= abr_type
;
2080 ospf_schedule_abr_task(ospf
);
2086 DEFUN (no_ospf_abr_type
,
2087 no_ospf_abr_type_cmd
,
2088 "no ospf abr-type <cisco|ibm|shortcut|standard>",
2090 "OSPF specific commands\n"
2091 "Set OSPF ABR type\n"
2092 "Alternative ABR, cisco implementation\n"
2093 "Alternative ABR, IBM implementation\n"
2097 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2099 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2101 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2102 abr_type
= OSPF_ABR_CISCO
;
2103 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2104 abr_type
= OSPF_ABR_IBM
;
2105 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2106 abr_type
= OSPF_ABR_SHORTCUT
;
2107 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2108 abr_type
= OSPF_ABR_STAND
;
2110 return CMD_WARNING_CONFIG_FAILED
;
2112 /* If ABR type value is changed, schedule ABR task. */
2113 if (ospf
->abr_type
== abr_type
) {
2114 ospf
->abr_type
= OSPF_ABR_DEFAULT
;
2115 ospf_schedule_abr_task(ospf
);
2121 DEFUN (ospf_log_adjacency_changes
,
2122 ospf_log_adjacency_changes_cmd
,
2123 "log-adjacency-changes",
2124 "Log changes in adjacency state\n")
2126 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2128 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2129 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2133 DEFUN (ospf_log_adjacency_changes_detail
,
2134 ospf_log_adjacency_changes_detail_cmd
,
2135 "log-adjacency-changes detail",
2136 "Log changes in adjacency state\n"
2137 "Log all state changes\n")
2139 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2141 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2142 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2146 DEFUN (no_ospf_log_adjacency_changes
,
2147 no_ospf_log_adjacency_changes_cmd
,
2148 "no log-adjacency-changes",
2150 "Log changes in adjacency state\n")
2152 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2154 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2155 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2159 DEFUN (no_ospf_log_adjacency_changes_detail
,
2160 no_ospf_log_adjacency_changes_detail_cmd
,
2161 "no log-adjacency-changes detail",
2163 "Log changes in adjacency state\n"
2164 "Log all state changes\n")
2166 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2168 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2172 DEFUN (ospf_compatible_rfc1583
,
2173 ospf_compatible_rfc1583_cmd
,
2174 "compatible rfc1583",
2175 "OSPF compatibility list\n"
2176 "compatible with RFC 1583\n")
2178 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2180 if (!CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2181 SET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2182 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2187 DEFUN (no_ospf_compatible_rfc1583
,
2188 no_ospf_compatible_rfc1583_cmd
,
2189 "no compatible rfc1583",
2191 "OSPF compatibility list\n"
2192 "compatible with RFC 1583\n")
2194 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2196 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2197 UNSET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2198 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2203 ALIAS(ospf_compatible_rfc1583
, ospf_rfc1583_flag_cmd
,
2204 "ospf rfc1583compatibility",
2205 "OSPF specific commands\n"
2206 "Enable the RFC1583Compatibility flag\n")
2208 ALIAS(no_ospf_compatible_rfc1583
, no_ospf_rfc1583_flag_cmd
,
2209 "no ospf rfc1583compatibility", NO_STR
2210 "OSPF specific commands\n"
2211 "Disable the RFC1583Compatibility flag\n")
2213 static int ospf_timers_spf_set(struct vty
*vty
, unsigned int delay
,
2214 unsigned int hold
, unsigned int max
)
2216 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2218 ospf
->spf_delay
= delay
;
2219 ospf
->spf_holdtime
= hold
;
2220 ospf
->spf_max_holdtime
= max
;
2225 DEFUN (ospf_timers_min_ls_interval
,
2226 ospf_timers_min_ls_interval_cmd
,
2227 "timers throttle lsa all (0-5000)",
2228 "Adjust routing timers\n"
2229 "Throttling adaptive timer\n"
2230 "LSA delay between transmissions\n"
2232 "Delay (msec) between sending LSAs\n")
2234 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2236 unsigned int interval
;
2239 vty_out(vty
, "Insufficient arguments\n");
2240 return CMD_WARNING_CONFIG_FAILED
;
2243 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2245 ospf
->min_ls_interval
= interval
;
2250 DEFUN (no_ospf_timers_min_ls_interval
,
2251 no_ospf_timers_min_ls_interval_cmd
,
2252 "no timers throttle lsa all [(0-5000)]",
2254 "Adjust routing timers\n"
2255 "Throttling adaptive timer\n"
2256 "LSA delay between transmissions\n"
2258 "Delay (msec) between sending LSAs\n")
2260 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2261 ospf
->min_ls_interval
= OSPF_MIN_LS_INTERVAL
;
2266 DEFUN (ospf_timers_throttle_spf
,
2267 ospf_timers_throttle_spf_cmd
,
2268 "timers throttle spf (0-600000) (0-600000) (0-600000)",
2269 "Adjust routing timers\n"
2270 "Throttling adaptive timer\n"
2272 "Delay (msec) from first change received till SPF calculation\n"
2273 "Initial hold time (msec) between consecutive SPF calculations\n"
2274 "Maximum hold time (msec)\n")
2277 int idx_number_2
= 4;
2278 int idx_number_3
= 5;
2279 unsigned int delay
, hold
, max
;
2282 vty_out(vty
, "Insufficient arguments\n");
2283 return CMD_WARNING_CONFIG_FAILED
;
2286 delay
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2287 hold
= strtoul(argv
[idx_number_2
]->arg
, NULL
, 10);
2288 max
= strtoul(argv
[idx_number_3
]->arg
, NULL
, 10);
2290 return ospf_timers_spf_set(vty
, delay
, hold
, max
);
2293 DEFUN (no_ospf_timers_throttle_spf
,
2294 no_ospf_timers_throttle_spf_cmd
,
2295 "no timers throttle spf [(0-600000)(0-600000)(0-600000)]",
2297 "Adjust routing timers\n"
2298 "Throttling adaptive timer\n"
2300 "Delay (msec) from first change received till SPF calculation\n"
2301 "Initial hold time (msec) between consecutive SPF calculations\n"
2302 "Maximum hold time (msec)\n")
2304 return ospf_timers_spf_set(vty
, OSPF_SPF_DELAY_DEFAULT
,
2305 OSPF_SPF_HOLDTIME_DEFAULT
,
2306 OSPF_SPF_MAX_HOLDTIME_DEFAULT
);
2310 DEFUN (ospf_timers_lsa_min_arrival
,
2311 ospf_timers_lsa_min_arrival_cmd
,
2312 "timers lsa min-arrival (0-600000)",
2313 "Adjust routing timers\n"
2315 "Minimum delay in receiving new version of a LSA\n"
2316 "Delay in milliseconds\n")
2318 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2319 ospf
->min_ls_arrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2323 DEFUN (no_ospf_timers_lsa_min_arrival
,
2324 no_ospf_timers_lsa_min_arrival_cmd
,
2325 "no timers lsa min-arrival [(0-600000)]",
2327 "Adjust routing timers\n"
2329 "Minimum delay in receiving new version of a LSA\n"
2330 "Delay in milliseconds\n")
2332 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2333 unsigned int minarrival
;
2336 minarrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2338 if (ospf
->min_ls_arrival
!= minarrival
2339 || minarrival
== OSPF_MIN_LS_ARRIVAL
)
2343 ospf
->min_ls_arrival
= OSPF_MIN_LS_ARRIVAL
;
2348 DEFUN (ospf_neighbor
,
2350 "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]",
2352 "Neighbor IP address\n"
2353 "Neighbor Priority\n"
2355 "Dead Neighbor Polling interval\n"
2358 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2362 struct in_addr nbr_addr
;
2363 unsigned int priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2364 unsigned int interval
= OSPF_POLL_INTERVAL_DEFAULT
;
2366 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2367 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2368 return CMD_WARNING_CONFIG_FAILED
;
2372 priority
= strtoul(argv
[idx_pri
]->arg
, NULL
, 10);
2375 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2377 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2380 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2383 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2388 DEFUN (ospf_neighbor_poll_interval
,
2389 ospf_neighbor_poll_interval_cmd
,
2390 "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2392 "Neighbor IP address\n"
2393 "Dead Neighbor Polling interval\n"
2395 "OSPF priority of non-broadcast neighbor\n"
2398 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2402 struct in_addr nbr_addr
;
2403 unsigned int priority
;
2404 unsigned int interval
;
2406 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2407 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2408 return CMD_WARNING_CONFIG_FAILED
;
2411 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2413 priority
= argc
> 4 ? strtoul(argv
[idx_pri
]->arg
, NULL
, 10)
2414 : OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2416 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2417 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2420 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2425 DEFUN (no_ospf_neighbor
,
2426 no_ospf_neighbor_cmd
,
2427 "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]",
2430 "Neighbor IP address\n"
2431 "Neighbor Priority\n"
2433 "Dead Neighbor Polling interval\n"
2436 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2438 struct in_addr nbr_addr
;
2440 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2441 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2442 return CMD_WARNING_CONFIG_FAILED
;
2445 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2450 DEFUN (no_ospf_neighbor_poll
,
2451 no_ospf_neighbor_poll_cmd
,
2452 "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2455 "Neighbor IP address\n"
2456 "Dead Neighbor Polling interval\n"
2458 "Neighbor Priority\n"
2461 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2463 struct in_addr nbr_addr
;
2465 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2466 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2467 return CMD_WARNING_CONFIG_FAILED
;
2470 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2475 DEFUN (ospf_refresh_timer
,
2476 ospf_refresh_timer_cmd
,
2477 "refresh timer (10-1800)",
2478 "Adjust refresh parameters\n"
2479 "Set refresh timer\n"
2480 "Timer value in seconds\n")
2482 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2484 unsigned int interval
;
2486 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2487 interval
= (interval
/ OSPF_LSA_REFRESHER_GRANULARITY
)
2488 * OSPF_LSA_REFRESHER_GRANULARITY
;
2490 ospf_timers_refresh_set(ospf
, interval
);
2495 DEFUN (no_ospf_refresh_timer
,
2496 no_ospf_refresh_timer_val_cmd
,
2497 "no refresh timer [(10-1800)]",
2499 "Adjust refresh parameters\n"
2500 "Unset refresh timer\n"
2501 "Timer value in seconds\n")
2503 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2505 unsigned int interval
;
2508 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2510 if (ospf
->lsa_refresh_interval
!= interval
2511 || interval
== OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
2515 ospf_timers_refresh_unset(ospf
);
2521 DEFUN (ospf_auto_cost_reference_bandwidth
,
2522 ospf_auto_cost_reference_bandwidth_cmd
,
2523 "auto-cost reference-bandwidth (1-4294967)",
2524 "Calculate OSPF interface cost according to bandwidth\n"
2525 "Use reference bandwidth method to assign OSPF cost\n"
2526 "The reference bandwidth in terms of Mbits per second\n")
2528 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2529 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2532 struct interface
*ifp
;
2534 refbw
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2535 if (refbw
< 1 || refbw
> 4294967) {
2536 vty_out(vty
, "reference-bandwidth value is invalid\n");
2537 return CMD_WARNING_CONFIG_FAILED
;
2540 /* If reference bandwidth is changed. */
2541 if ((refbw
) == ospf
->ref_bandwidth
)
2544 ospf
->ref_bandwidth
= refbw
;
2545 FOR_ALL_INTERFACES (vrf
, ifp
)
2546 ospf_if_recalculate_output_cost(ifp
);
2551 DEFUN (no_ospf_auto_cost_reference_bandwidth
,
2552 no_ospf_auto_cost_reference_bandwidth_cmd
,
2553 "no auto-cost reference-bandwidth [(1-4294967)]",
2555 "Calculate OSPF interface cost according to bandwidth\n"
2556 "Use reference bandwidth method to assign OSPF cost\n"
2557 "The reference bandwidth in terms of Mbits per second\n")
2559 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2560 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2561 struct interface
*ifp
;
2563 if (ospf
->ref_bandwidth
== OSPF_DEFAULT_REF_BANDWIDTH
)
2566 ospf
->ref_bandwidth
= OSPF_DEFAULT_REF_BANDWIDTH
;
2567 vty_out(vty
, "%% OSPF: Reference bandwidth is changed.\n");
2569 " Please ensure reference bandwidth is consistent across all routers\n");
2571 FOR_ALL_INTERFACES (vrf
, ifp
)
2572 ospf_if_recalculate_output_cost(ifp
);
2577 DEFUN (ospf_write_multiplier
,
2578 ospf_write_multiplier_cmd
,
2579 "ospf write-multiplier (1-100)",
2580 "OSPF specific commands\n"
2581 "Write multiplier\n"
2582 "Maximum number of interface serviced per write\n")
2584 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2586 uint32_t write_oi_count
;
2593 write_oi_count
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2594 if (write_oi_count
< 1 || write_oi_count
> 100) {
2595 vty_out(vty
, "write-multiplier value is invalid\n");
2596 return CMD_WARNING_CONFIG_FAILED
;
2599 ospf
->write_oi_count
= write_oi_count
;
2603 ALIAS(ospf_write_multiplier
, write_multiplier_cmd
, "write-multiplier (1-100)",
2604 "Write multiplier\n"
2605 "Maximum number of interface serviced per write\n")
2607 DEFUN (no_ospf_write_multiplier
,
2608 no_ospf_write_multiplier_cmd
,
2609 "no ospf write-multiplier (1-100)",
2611 "OSPF specific commands\n"
2612 "Write multiplier\n"
2613 "Maximum number of interface serviced per write\n")
2615 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2617 ospf
->write_oi_count
= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
;
2621 ALIAS(no_ospf_write_multiplier
, no_write_multiplier_cmd
,
2622 "no write-multiplier (1-100)", NO_STR
2623 "Write multiplier\n"
2624 "Maximum number of interface serviced per write\n")
2626 const char *ospf_abr_type_descr_str
[] = {"Unknown", "Standard (RFC2328)",
2627 "Alternative IBM", "Alternative Cisco",
2628 "Alternative Shortcut"};
2630 const char *ospf_shortcut_mode_descr_str
[] = {"Default", "Enabled", "Disabled"};
2632 static void show_ip_ospf_area(struct vty
*vty
, struct ospf_area
*area
,
2633 json_object
*json_areas
, bool use_json
)
2635 json_object
*json_area
= NULL
;
2638 json_area
= json_object_new_object();
2642 vty_out(vty
, " Area ID: %s", inet_ntoa(area
->area_id
));
2644 /* Show Area type/mode. */
2645 if (OSPF_IS_AREA_BACKBONE(area
)) {
2647 json_object_boolean_true_add(json_area
, "backbone");
2649 vty_out(vty
, " (Backbone)\n");
2652 if (area
->external_routing
== OSPF_AREA_STUB
) {
2653 if (area
->no_summary
)
2654 json_object_boolean_true_add(
2655 json_area
, "stubNoSummary");
2656 if (area
->shortcut_configured
)
2657 json_object_boolean_true_add(
2658 json_area
, "stubShortcut");
2659 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
2660 if (area
->no_summary
)
2661 json_object_boolean_true_add(
2662 json_area
, "nssaNoSummary");
2663 if (area
->shortcut_configured
)
2664 json_object_boolean_true_add(
2665 json_area
, "nssaShortcut");
2668 json_object_string_add(
2669 json_area
, "shortcuttingMode",
2670 ospf_shortcut_mode_descr_str
2671 [area
->shortcut_configured
]);
2672 if (area
->shortcut_capability
)
2673 json_object_boolean_true_add(json_area
,
2676 if (area
->external_routing
== OSPF_AREA_STUB
)
2677 vty_out(vty
, " (Stub%s%s)",
2678 area
->no_summary
? ", no summary" : "",
2679 area
->shortcut_configured
? "; " : "");
2680 else if (area
->external_routing
== OSPF_AREA_NSSA
)
2681 vty_out(vty
, " (NSSA%s%s)",
2682 area
->no_summary
? ", no summary" : "",
2683 area
->shortcut_configured
? "; " : "");
2686 vty_out(vty
, " Shortcutting mode: %s",
2687 ospf_shortcut_mode_descr_str
2688 [area
->shortcut_configured
]);
2689 vty_out(vty
, ", S-bit consensus: %s\n",
2690 area
->shortcut_capability
? "ok" : "no");
2694 /* Show number of interfaces */
2696 json_object_int_add(json_area
, "areaIfTotalCounter",
2697 listcount(area
->oiflist
));
2698 json_object_int_add(json_area
, "areaIfActiveCounter",
2702 " Number of interfaces in this area: Total: %d, "
2704 listcount(area
->oiflist
), area
->act_ints
);
2706 if (area
->external_routing
== OSPF_AREA_NSSA
) {
2708 json_object_boolean_true_add(json_area
, "nssa");
2709 if (!IS_OSPF_ABR(area
->ospf
))
2710 json_object_boolean_false_add(json_area
, "abr");
2711 else if (area
->NSSATranslatorState
) {
2712 json_object_boolean_true_add(json_area
, "abr");
2713 if (area
->NSSATranslatorRole
2714 == OSPF_NSSA_ROLE_CANDIDATE
)
2715 json_object_boolean_true_add(
2717 "nssaTranslatorElected");
2718 else if (area
->NSSATranslatorRole
2719 == OSPF_NSSA_ROLE_ALWAYS
)
2720 json_object_boolean_true_add(
2722 "nssaTranslatorAlways");
2724 json_object_boolean_true_add(json_area
, "abr");
2725 if (area
->NSSATranslatorRole
2726 == OSPF_NSSA_ROLE_CANDIDATE
)
2727 json_object_boolean_false_add(
2729 "nssaTranslatorElected");
2731 json_object_boolean_true_add(
2733 "nssaTranslatorNever");
2737 " It is an NSSA configuration. \n Elected NSSA/ABR performs type-7/type-5 LSA translation. \n");
2738 if (!IS_OSPF_ABR(area
->ospf
))
2740 " It is not ABR, therefore not Translator. \n");
2741 else if (area
->NSSATranslatorState
) {
2742 vty_out(vty
, " We are an ABR and ");
2743 if (area
->NSSATranslatorRole
2744 == OSPF_NSSA_ROLE_CANDIDATE
)
2746 "the NSSA Elected Translator. \n");
2747 else if (area
->NSSATranslatorRole
2748 == OSPF_NSSA_ROLE_ALWAYS
)
2750 "always an NSSA Translator. \n");
2752 vty_out(vty
, " We are an ABR, but ");
2753 if (area
->NSSATranslatorRole
2754 == OSPF_NSSA_ROLE_CANDIDATE
)
2756 "not the NSSA Elected Translator. \n");
2759 "never an NSSA Translator. \n");
2764 /* Stub-router state for this area */
2765 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
)) {
2766 char timebuf
[OSPF_TIME_DUMP_SIZE
];
2769 json_object_boolean_true_add(
2770 json_area
, "originStubMaxDistRouterLsa");
2771 if (CHECK_FLAG(area
->stub_router_state
,
2772 OSPF_AREA_ADMIN_STUB_ROUTED
))
2773 json_object_boolean_true_add(
2774 json_area
, "indefiniteActiveAdmin");
2775 if (area
->t_stub_router
) {
2779 &area
->t_stub_router
->u
.sands
,
2782 json_object_int_add(
2784 "activeStartupRemainderMsecs",
2789 " Originating stub / maximum-distance Router-LSA\n");
2790 if (CHECK_FLAG(area
->stub_router_state
,
2791 OSPF_AREA_ADMIN_STUB_ROUTED
))
2793 " Administratively activated (indefinitely)\n");
2794 if (area
->t_stub_router
)
2796 " Active from startup, %s remaining\n",
2797 ospf_timer_dump(area
->t_stub_router
,
2804 /* Show number of fully adjacent neighbors. */
2805 json_object_int_add(json_area
, "nbrFullAdjacentCounter",
2808 /* Show authentication type. */
2809 if (area
->auth_type
== OSPF_AUTH_NULL
)
2810 json_object_string_add(json_area
, "authentication",
2811 "authenticationNone");
2812 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2813 json_object_string_add(json_area
, "authentication",
2814 "authenticationSimplePassword");
2815 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2816 json_object_string_add(json_area
, "authentication",
2817 "authenticationMessageDigest");
2819 if (!OSPF_IS_AREA_BACKBONE(area
))
2820 json_object_int_add(json_area
,
2821 "virtualAdjacenciesPassingCounter",
2824 /* Show SPF calculation times. */
2825 json_object_int_add(json_area
, "spfExecutedCounter",
2826 area
->spf_calculation
);
2827 json_object_int_add(json_area
, "lsaNumber", area
->lsdb
->total
);
2828 json_object_int_add(
2829 json_area
, "lsaRouterNumber",
2830 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
));
2831 json_object_int_add(
2832 json_area
, "lsaRouterChecksum",
2833 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
2834 json_object_int_add(
2835 json_area
, "lsaNetworkNumber",
2836 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
));
2837 json_object_int_add(
2838 json_area
, "lsaNetworkChecksum",
2839 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
2840 json_object_int_add(
2841 json_area
, "lsaSummaryNumber",
2842 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
));
2843 json_object_int_add(
2844 json_area
, "lsaSummaryChecksum",
2845 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
2846 json_object_int_add(
2847 json_area
, "lsaAsbrNumber",
2848 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2849 json_object_int_add(
2850 json_area
, "lsaAsbrChecksum",
2851 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2852 json_object_int_add(
2853 json_area
, "lsaNssaNumber",
2854 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2855 json_object_int_add(
2856 json_area
, "lsaNssaChecksum",
2857 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2859 /* Show number of fully adjacent neighbors. */
2861 " Number of fully adjacent neighbors in this area:"
2865 /* Show authentication type. */
2866 vty_out(vty
, " Area has ");
2867 if (area
->auth_type
== OSPF_AUTH_NULL
)
2868 vty_out(vty
, "no authentication\n");
2869 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2870 vty_out(vty
, "simple password authentication\n");
2871 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2872 vty_out(vty
, "message digest authentication\n");
2874 if (!OSPF_IS_AREA_BACKBONE(area
))
2876 " Number of full virtual adjacencies going through"
2880 /* Show SPF calculation times. */
2881 vty_out(vty
, " SPF algorithm executed %d times\n",
2882 area
->spf_calculation
);
2884 /* Show number of LSA. */
2885 vty_out(vty
, " Number of LSA %ld\n", area
->lsdb
->total
);
2887 " Number of router LSA %ld. Checksum Sum 0x%08x\n",
2888 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
),
2889 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
2891 " Number of network LSA %ld. Checksum Sum 0x%08x\n",
2892 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
),
2893 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
2895 " Number of summary LSA %ld. Checksum Sum 0x%08x\n",
2896 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
),
2897 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
2899 " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n",
2900 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
),
2901 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2902 vty_out(vty
, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n",
2903 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
),
2904 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2908 json_object_int_add(
2909 json_area
, "lsaOpaqueLinkNumber",
2910 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
2911 json_object_int_add(
2912 json_area
, "lsaOpaqueLinkChecksum",
2913 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
2914 json_object_int_add(
2915 json_area
, "lsaOpaqueAreaNumber",
2916 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
2917 json_object_int_add(
2918 json_area
, "lsaOpaqueAreaChecksum",
2919 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
2922 " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n",
2923 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
),
2924 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
2926 " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n",
2927 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
),
2928 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
2932 json_object_object_add(json_areas
, inet_ntoa(area
->area_id
),
2938 static int show_ip_ospf_common(struct vty
*vty
, struct ospf
*ospf
,
2939 json_object
*json
, uint8_t use_vrf
)
2941 struct listnode
*node
, *nnode
;
2942 struct ospf_area
*area
;
2943 struct timeval result
;
2944 char timebuf
[OSPF_TIME_DUMP_SIZE
];
2945 json_object
*json_vrf
= NULL
;
2946 json_object
*json_areas
= NULL
;
2950 json_vrf
= json_object_new_object();
2953 json_areas
= json_object_new_object();
2956 if (ospf
->instance
) {
2958 json_object_int_add(json
, "ospfInstance",
2961 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
2965 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
2967 /* Show Router ID. */
2969 json_object_string_add(json_vrf
, "routerId",
2970 inet_ntoa(ospf
->router_id
));
2972 vty_out(vty
, " OSPF Routing Process, Router ID: %s\n",
2973 inet_ntoa(ospf
->router_id
));
2976 /* Graceful shutdown */
2977 if (ospf
->t_deferred_shutdown
) {
2982 &ospf
->t_deferred_shutdown
->u
.sands
,
2985 json_object_int_add(json_vrf
, "deferredShutdownMsecs",
2989 " Deferred shutdown in progress, %s remaining\n",
2990 ospf_timer_dump(ospf
->t_deferred_shutdown
,
2991 timebuf
, sizeof(timebuf
)));
2995 /* Show capability. */
2997 json_object_boolean_true_add(json_vrf
, "tosRoutesOnly");
2998 json_object_boolean_true_add(json_vrf
, "rfc2328Conform");
2999 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
3000 json_object_boolean_true_add(json_vrf
,
3001 "rfc1583Compatibility");
3004 vty_out(vty
, " Supports only single TOS (TOS0) routes\n");
3005 vty_out(vty
, " This implementation conforms to RFC2328\n");
3006 vty_out(vty
, " RFC1583Compatibility flag is %s\n",
3007 CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)
3013 if (CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)) {
3014 json_object_boolean_true_add(json_vrf
, "opaqueCapable");
3017 vty_out(vty
, " OpaqueCapability flag is %s\n",
3018 CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)
3023 /* Show stub-router configuration */
3024 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
3025 || ospf
->stub_router_shutdown_time
3026 != OSPF_STUB_ROUTER_UNCONFIGURED
) {
3028 json_object_boolean_true_add(json_vrf
,
3029 "stubAdvertisement");
3030 if (ospf
->stub_router_startup_time
3031 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3032 json_object_int_add(
3033 json_vrf
, "postStartEnabledMsecs",
3034 ospf
->stub_router_startup_time
/ 1000);
3035 if (ospf
->stub_router_shutdown_time
3036 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3037 json_object_int_add(
3038 json_vrf
, "preShutdownEnabledMsecs",
3039 ospf
->stub_router_shutdown_time
/ 1000);
3042 " Stub router advertisement is configured\n");
3043 if (ospf
->stub_router_startup_time
3044 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3046 " Enabled for %us after start-up\n",
3047 ospf
->stub_router_startup_time
);
3048 if (ospf
->stub_router_shutdown_time
3049 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3051 " Enabled for %us prior to full shutdown\n",
3052 ospf
->stub_router_shutdown_time
);
3056 /* Show SPF timers. */
3058 json_object_int_add(json_vrf
, "spfScheduleDelayMsecs",
3060 json_object_int_add(json_vrf
, "holdtimeMinMsecs",
3061 ospf
->spf_holdtime
);
3062 json_object_int_add(json_vrf
, "holdtimeMaxMsecs",
3063 ospf
->spf_max_holdtime
);
3064 json_object_int_add(json_vrf
, "holdtimeMultplier",
3065 ospf
->spf_hold_multiplier
);
3068 " Initial SPF scheduling delay %d millisec(s)\n"
3069 " Minimum hold time between consecutive SPFs %d millisec(s)\n"
3070 " Maximum hold time between consecutive SPFs %d millisec(s)\n"
3071 " Hold time multiplier is currently %d\n",
3072 ospf
->spf_delay
, ospf
->spf_holdtime
,
3073 ospf
->spf_max_holdtime
, ospf
->spf_hold_multiplier
);
3077 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3078 long time_store
= 0;
3081 monotime_since(&ospf
->ts_spf
, NULL
) / 1000LL;
3082 json_object_int_add(json_vrf
, "spfLastExecutedMsecs",
3085 time_store
= (1000 * ospf
->ts_spf_duration
.tv_sec
)
3086 + (ospf
->ts_spf_duration
.tv_usec
/ 1000);
3087 json_object_int_add(json_vrf
, "spfLastDurationMsecs",
3090 json_object_boolean_true_add(json_vrf
, "spfHasNotRun");
3092 vty_out(vty
, " SPF algorithm ");
3093 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3094 monotime_since(&ospf
->ts_spf
, &result
);
3095 vty_out(vty
, "last executed %s ago\n",
3096 ospf_timeval_dump(&result
, timebuf
,
3098 vty_out(vty
, " Last SPF duration %s\n",
3099 ospf_timeval_dump(&ospf
->ts_spf_duration
,
3100 timebuf
, sizeof(timebuf
)));
3102 vty_out(vty
, "has not been run\n");
3106 if (ospf
->t_spf_calc
) {
3109 monotime_until(&ospf
->t_spf_calc
->u
.sands
, NULL
)
3111 json_object_int_add(json_vrf
, "spfTimerDueInMsecs",
3115 json_object_int_add(json_vrf
, "lsaMinIntervalMsecs",
3116 ospf
->min_ls_interval
);
3117 json_object_int_add(json_vrf
, "lsaMinArrivalMsecs",
3118 ospf
->min_ls_arrival
);
3119 /* Show write multiplier values */
3120 json_object_int_add(json_vrf
, "writeMultiplier",
3121 ospf
->write_oi_count
);
3122 /* Show refresh parameters. */
3123 json_object_int_add(json_vrf
, "refreshTimerMsecs",
3124 ospf
->lsa_refresh_interval
* 1000);
3126 vty_out(vty
, " SPF timer %s%s\n",
3127 (ospf
->t_spf_calc
? "due in " : "is "),
3128 ospf_timer_dump(ospf
->t_spf_calc
, timebuf
,
3131 vty_out(vty
, " LSA minimum interval %d msecs\n",
3132 ospf
->min_ls_interval
);
3133 vty_out(vty
, " LSA minimum arrival %d msecs\n",
3134 ospf
->min_ls_arrival
);
3136 /* Show write multiplier values */
3137 vty_out(vty
, " Write Multiplier set to %d \n",
3138 ospf
->write_oi_count
);
3140 /* Show refresh parameters. */
3141 vty_out(vty
, " Refresh timer %d secs\n",
3142 ospf
->lsa_refresh_interval
);
3145 /* Show ABR/ASBR flags. */
3146 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ABR
)) {
3148 json_object_string_add(
3149 json_vrf
, "abrType",
3150 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3153 " This router is an ABR, ABR type is: %s\n",
3154 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3156 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ASBR
)) {
3158 json_object_string_add(
3159 json_vrf
, "asbrRouter",
3160 "injectingExternalRoutingInformation");
3163 " This router is an ASBR "
3164 "(injecting external routing information)\n");
3167 /* Show Number of AS-external-LSAs. */
3169 json_object_int_add(
3170 json_vrf
, "lsaExternalCounter",
3171 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3172 json_object_int_add(
3173 json_vrf
, "lsaExternalChecksum",
3174 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3177 " Number of external LSA %ld. Checksum Sum 0x%08x\n",
3178 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
),
3179 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3183 json_object_int_add(
3184 json_vrf
, "lsaAsopaqueCounter",
3185 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3186 json_object_int_add(
3187 json_vrf
, "lsaAsOpaqueChecksum",
3188 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3191 " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n",
3192 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
),
3193 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3196 /* Show number of areas attached. */
3198 json_object_int_add(json_vrf
, "attachedAreaCounter",
3199 listcount(ospf
->areas
));
3201 vty_out(vty
, " Number of areas attached to this router: %d\n",
3202 listcount(ospf
->areas
));
3204 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
3205 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
)) {
3207 json_object_boolean_true_add(
3208 json_vrf
, "adjacencyChangesLoggedAll");
3211 " All adjacency changes are logged\n");
3214 json_object_boolean_true_add(
3215 json_vrf
, "adjacencyChangesLogged");
3217 vty_out(vty
, " Adjacency changes are logged\n");
3220 /* Show each area status. */
3221 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
3222 show_ip_ospf_area(vty
, area
, json_areas
, json
? 1 : 0);
3226 json_object_object_add(json_vrf
, "areas", json_areas
);
3227 if (ospf
->vrf_id
== VRF_DEFAULT
)
3228 json_object_object_add(json
, "default",
3231 json_object_object_add(json
, ospf
->name
,
3234 json_object_object_add(json
, "areas", json_areas
);
3242 DEFUN (show_ip_ospf
,
3244 "show ip ospf [vrf <NAME|all>] [json]",
3247 "OSPF information\n"
3253 bool uj
= use_json(argc
, argv
);
3254 struct listnode
*node
= NULL
;
3255 char *vrf_name
= NULL
;
3256 bool all_vrf
= FALSE
;
3257 int ret
= CMD_SUCCESS
;
3260 json_object
*json
= NULL
;
3261 uint8_t use_vrf
= 0;
3263 if (listcount(om
->ospf
) == 0)
3266 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
3269 json
= json_object_new_object();
3271 /* vrf input is provided could be all or specific vrf*/
3273 bool ospf_output
= FALSE
;
3278 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
3279 if (!ospf
->oi_running
)
3282 ret
= show_ip_ospf_common(vty
, ospf
, json
,
3286 vty_out(vty
, "%s\n",
3287 json_object_to_json_string_ext(
3288 json
, JSON_C_TO_STRING_PRETTY
));
3289 json_object_free(json
);
3290 } else if (!ospf_output
)
3291 vty_out(vty
, "%% OSPF instance not found\n");
3294 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
3295 if ((ospf
== NULL
) || !ospf
->oi_running
) {
3297 vty_out(vty
, "%s\n",
3298 json_object_to_json_string_ext(
3299 json
, JSON_C_TO_STRING_PRETTY
));
3300 json_object_free(json
);
3302 vty_out(vty
, "%% OSPF instance not found\n");
3307 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
3308 /* Display default ospf (instance 0) info */
3309 if (ospf
== NULL
|| !ospf
->oi_running
) {
3311 vty_out(vty
, "%s\n",
3312 json_object_to_json_string_ext(
3313 json
, JSON_C_TO_STRING_PRETTY
));
3314 json_object_free(json
);
3316 vty_out(vty
, "%% OSPF instance not found\n");
3323 show_ip_ospf_common(vty
, ospf
, json
, use_vrf
);
3325 vty_out(vty
, "%s\n",
3326 json_object_to_json_string_ext(
3327 json
, JSON_C_TO_STRING_PRETTY
));
3331 json_object_free(json
);
3336 DEFUN (show_ip_ospf_instance
,
3337 show_ip_ospf_instance_cmd
,
3338 "show ip ospf (1-65535) [json]",
3341 "OSPF information\n"
3347 unsigned short instance
= 0;
3348 bool uj
= use_json(argc
, argv
);
3349 int ret
= CMD_SUCCESS
;
3350 json_object
*json
= NULL
;
3352 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
3353 ospf
= ospf_lookup_instance(instance
);
3355 return CMD_NOT_MY_INSTANCE
;
3357 if (!ospf
->oi_running
)
3361 json
= json_object_new_object();
3363 ret
= show_ip_ospf_common(vty
, ospf
, json
, 0);
3366 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
3367 json
, JSON_C_TO_STRING_PRETTY
));
3368 json_object_free(json
);
3374 static void show_ip_ospf_interface_sub(struct vty
*vty
, struct ospf
*ospf
,
3375 struct interface
*ifp
,
3376 json_object
*json_interface_sub
,
3380 struct ospf_neighbor
*nbr
;
3381 struct route_node
*rn
;
3382 uint32_t bandwidth
= ifp
->bandwidth
? ifp
->bandwidth
: ifp
->speed
;
3384 /* Is interface up? */
3386 is_up
= if_is_operative(ifp
);
3388 json_object_boolean_true_add(json_interface_sub
,
3391 json_object_boolean_false_add(json_interface_sub
,
3394 json_object_int_add(json_interface_sub
, "ifIndex",
3396 json_object_int_add(json_interface_sub
, "mtuBytes", ifp
->mtu
);
3397 json_object_int_add(json_interface_sub
, "bandwidthMbit",
3399 json_object_string_add(json_interface_sub
, "ifFlags",
3400 if_flag_dump(ifp
->flags
));
3402 vty_out(vty
, "%s is %s\n", ifp
->name
,
3403 ((is_up
= if_is_operative(ifp
)) ? "up" : "down"));
3404 vty_out(vty
, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n",
3405 ifp
->ifindex
, ifp
->mtu
, bandwidth
,
3406 if_flag_dump(ifp
->flags
));
3409 /* Is interface OSPF enabled? */
3411 if (ospf_oi_count(ifp
) == 0) {
3412 json_object_boolean_false_add(json_interface_sub
,
3415 } else if (!is_up
) {
3416 json_object_boolean_false_add(json_interface_sub
,
3420 json_object_boolean_true_add(json_interface_sub
,
3423 if (ospf_oi_count(ifp
) == 0) {
3424 vty_out(vty
, " OSPF not enabled on this interface\n");
3426 } else if (!is_up
) {
3428 " OSPF is enabled, but not running on this interface\n");
3433 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
3434 struct ospf_interface
*oi
= rn
->info
;
3439 if (CHECK_FLAG(oi
->connected
->flags
, ZEBRA_IFA_UNNUMBERED
)) {
3441 json_object_boolean_true_add(json_interface_sub
,
3444 vty_out(vty
, " This interface is UNNUMBERED,");
3446 /* Show OSPF interface information. */
3448 json_object_string_add(
3449 json_interface_sub
, "ipAddress",
3450 inet_ntoa(oi
->address
->u
.prefix4
));
3451 json_object_int_add(json_interface_sub
,
3452 "ipAddressPrefixlen",
3453 oi
->address
->prefixlen
);
3455 vty_out(vty
, " Internet Address %s/%d,",
3456 inet_ntoa(oi
->address
->u
.prefix4
),
3457 oi
->address
->prefixlen
);
3459 if (oi
->connected
->destination
3460 || oi
->type
== OSPF_IFTYPE_VIRTUALLINK
) {
3461 struct in_addr
*dest
;
3464 if (CONNECTED_PEER(oi
->connected
)
3465 || oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3470 /* For Vlinks, showing the peer address is
3472 * * * * * informative than the local
3473 * interface that is being used
3475 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3476 dest
= &oi
->vl_data
->peer_addr
;
3478 dest
= &oi
->connected
->destination
->u
3482 json_object_string_add(
3484 "ospfIfType", dstr
);
3485 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3486 json_object_string_add(
3491 json_object_string_add(
3496 vty_out(vty
, " %s %s,", dstr
,
3501 json_object_string_add(json_interface_sub
, "area",
3502 ospf_area_desc_string(oi
->area
));
3503 if (OSPF_IF_PARAM(oi
, mtu_ignore
))
3504 json_object_boolean_true_add(
3506 "mtuMismatchDetect");
3507 json_object_string_add(json_interface_sub
, "routerId",
3508 inet_ntoa(ospf
->router_id
));
3509 json_object_string_add(json_interface_sub
,
3511 ospf_network_type_str
[oi
->type
]);
3512 json_object_int_add(json_interface_sub
, "cost",
3514 json_object_int_add(
3515 json_interface_sub
, "transmitDelayMsecs",
3516 1000 / OSPF_IF_PARAM(oi
, transmit_delay
));
3517 json_object_string_add(json_interface_sub
, "state",
3518 lookup_msg(ospf_ism_state_msg
,
3520 json_object_int_add(json_interface_sub
, "priority",
3523 vty_out(vty
, " Area %s\n",
3524 ospf_area_desc_string(oi
->area
));
3526 vty_out(vty
, " MTU mismatch detection: %s\n",
3527 OSPF_IF_PARAM(oi
, mtu_ignore
) ? "disabled"
3531 " Router ID %s, Network Type %s, Cost: %d\n",
3532 inet_ntoa(ospf
->router_id
),
3533 ospf_network_type_str
[oi
->type
],
3537 " Transmit Delay is %d sec, State %s, Priority %d\n",
3538 OSPF_IF_PARAM(oi
, transmit_delay
),
3539 lookup_msg(ospf_ism_state_msg
, oi
->state
, NULL
),
3543 /* Show DR information. */
3544 if (DR(oi
).s_addr
== 0) {
3547 " No backup designated router on this network\n");
3549 nbr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &BDR(oi
));
3553 " No backup designated router on this network\n");
3556 json_object_string_add(
3557 json_interface_sub
, "bdrId",
3558 inet_ntoa(nbr
->router_id
));
3559 json_object_string_add(
3562 inet_ntoa(nbr
->address
.u
3566 " Backup Designated Router (ID) %s,",
3567 inet_ntoa(nbr
->router_id
));
3568 vty_out(vty
, " Interface Address %s\n",
3569 inet_ntoa(nbr
->address
.u
3575 /* Next network-LSA sequence number we'll use, if we're elected
3578 && ntohl(oi
->params
->network_lsa_seqnum
)
3579 != OSPF_INITIAL_SEQUENCE_NUMBER
) {
3581 json_object_int_add(
3583 "networkLsaSequence",
3584 ntohl(oi
->params
->network_lsa_seqnum
));
3587 " Saved Network-LSA sequence number 0x%x\n",
3588 ntohl(oi
->params
->network_lsa_seqnum
));
3592 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3593 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3594 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3595 json_object_boolean_true_add(
3597 "mcastMemberOspfAllRouters");
3598 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3599 json_object_boolean_true_add(
3601 "mcastMemberOspfDesignatedRouters");
3604 vty_out(vty
, " Multicast group memberships:");
3605 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3606 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3607 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3608 vty_out(vty
, " OSPFAllRouters");
3609 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3610 vty_out(vty
, " OSPFDesignatedRouters");
3612 vty_out(vty
, " <None>");
3617 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3618 json_object_int_add(
3619 json_interface_sub
, "timerMsecs",
3620 1000 / OSPF_IF_PARAM(oi
, v_hello
));
3622 json_object_int_add(
3623 json_interface_sub
, "timerMsecs",
3624 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3625 json_object_int_add(json_interface_sub
,
3627 1000 / OSPF_IF_PARAM(oi
, v_wait
));
3628 json_object_int_add(json_interface_sub
,
3630 1000 / OSPF_IF_PARAM(oi
, v_wait
));
3631 json_object_int_add(
3632 json_interface_sub
, "timerRetransmit",
3633 1000 / OSPF_IF_PARAM(oi
, retransmit_interval
));
3635 vty_out(vty
, " Timer intervals configured,");
3636 vty_out(vty
, " Hello ");
3637 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3638 vty_out(vty
, "%ds,",
3639 OSPF_IF_PARAM(oi
, v_hello
));
3641 vty_out(vty
, "%dms,",
3642 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3643 vty_out(vty
, " Dead %ds, Wait %ds, Retransmit %d\n",
3644 OSPF_IF_PARAM(oi
, v_wait
),
3645 OSPF_IF_PARAM(oi
, v_wait
),
3646 OSPF_IF_PARAM(oi
, retransmit_interval
));
3649 if (OSPF_IF_PASSIVE_STATUS(oi
) == OSPF_IF_ACTIVE
) {
3650 char timebuf
[OSPF_TIME_DUMP_SIZE
];
3652 long time_store
= 0;
3656 &oi
->t_hello
->u
.sands
,
3659 json_object_int_add(json_interface_sub
,
3660 "timerHelloInMsecs",
3663 vty_out(vty
, " Hello due in %s\n",
3664 ospf_timer_dump(oi
->t_hello
, timebuf
,
3666 } else /* passive-interface is set */
3669 json_object_boolean_true_add(
3671 "timerPassiveIface");
3674 " No Hellos (Passive interface)\n");
3678 json_object_int_add(json_interface_sub
, "nbrCount",
3679 ospf_nbr_count(oi
, 0));
3680 json_object_int_add(json_interface_sub
,
3682 ospf_nbr_count(oi
, NSM_Full
));
3685 " Neighbor Count is %d, Adjacent neighbor count is %d\n",
3686 ospf_nbr_count(oi
, 0),
3687 ospf_nbr_count(oi
, NSM_Full
));
3688 ospf_bfd_interface_show(vty
, ifp
, json_interface_sub
, use_json
);
3692 static int show_ip_ospf_interface_common(struct vty
*vty
, struct ospf
*ospf
,
3693 char *intf_name
, uint8_t use_vrf
,
3694 json_object
*json
, bool use_json
)
3696 struct interface
*ifp
;
3697 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
3698 json_object
*json_vrf
= NULL
;
3699 json_object
*json_interface_sub
= NULL
, *json_interface
= NULL
;
3703 json_vrf
= json_object_new_object();
3706 json_interface
= json_object_new_object();
3709 if (ospf
->instance
) {
3711 json_object_int_add(json
, "ospfInstance",
3714 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
3717 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3719 if (intf_name
== NULL
) {
3720 /* Show All Interfaces.*/
3721 FOR_ALL_INTERFACES (vrf
, ifp
) {
3722 if (ospf_oi_count(ifp
)) {
3724 json_interface_sub
=
3725 json_object_new_object();
3727 show_ip_ospf_interface_sub(vty
, ospf
, ifp
,
3732 json_object_object_add(
3733 json_interface
, ifp
->name
,
3734 json_interface_sub
);
3739 json_object_object_add(json_vrf
, "interfaces",
3742 /* Interface name is specified. */
3743 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
3746 json_object_boolean_true_add(json_vrf
,
3749 vty_out(vty
, "No such interface name\n");
3752 json_interface_sub
= json_object_new_object();
3753 json_interface
= json_object_new_object();
3756 show_ip_ospf_interface_sub(
3757 vty
, ospf
, ifp
, json_interface_sub
, use_json
);
3760 json_object_object_add(json_interface
,
3762 json_interface_sub
);
3763 json_object_object_add(json_vrf
, "interfaces",
3771 if (ospf
->vrf_id
== VRF_DEFAULT
)
3772 json_object_object_add(json
, "default",
3775 json_object_object_add(json
, ospf
->name
,
3784 static void show_ip_ospf_interface_traffic_sub(struct vty
*vty
,
3785 struct ospf_interface
*oi
,
3786 json_object
*json_interface_sub
,
3790 json_object_int_add(json_interface_sub
, "ifIndex",
3792 json_object_int_add(json_interface_sub
, "helloIn",
3794 json_object_int_add(json_interface_sub
, "helloOut",
3796 json_object_int_add(json_interface_sub
, "dbDescIn",
3798 json_object_int_add(json_interface_sub
, "dbDescOut",
3800 json_object_int_add(json_interface_sub
, "lsReqIn",
3802 json_object_int_add(json_interface_sub
, "lsReqOut",
3804 json_object_int_add(json_interface_sub
, "lsUpdIn",
3806 json_object_int_add(json_interface_sub
, "lsUpdOut",
3808 json_object_int_add(json_interface_sub
, "lsAckIn",
3810 json_object_int_add(json_interface_sub
, "lsAckOut",
3814 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n",
3815 oi
->ifp
->name
, oi
->hello_in
, oi
->hello_out
,
3816 oi
->db_desc_in
, oi
->db_desc_out
, oi
->ls_req_in
,
3817 oi
->ls_req_out
, oi
->ls_upd_in
, oi
->ls_upd_out
,
3818 oi
->ls_ack_in
, oi
->ls_ack_out
);
3822 /* OSPFv2 Packet Counters */
3823 static int show_ip_ospf_interface_traffic_common(
3824 struct vty
*vty
, struct ospf
*ospf
, char *intf_name
, json_object
*json
,
3825 int display_once
, uint8_t use_vrf
, bool use_json
)
3827 struct vrf
*vrf
= NULL
;
3828 struct interface
*ifp
= NULL
;
3829 json_object
*json_vrf
= NULL
;
3830 json_object
*json_interface_sub
= NULL
;
3832 if (!use_json
&& !display_once
) {
3834 vty_out(vty
, "%-12s%-17s%-17s%-17s%-17s%-17s\n", "Interface",
3835 " HELLO", " DB-Desc", " LS-Req", " LS-Update",
3837 vty_out(vty
, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "",
3838 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
3841 "--------------------------------------------------------------------------------------------\n");
3842 } else if (use_json
) {
3844 json_vrf
= json_object_new_object();
3849 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3851 if (intf_name
== NULL
) {
3852 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
3853 FOR_ALL_INTERFACES (vrf
, ifp
) {
3854 struct route_node
*rn
;
3855 struct ospf_interface
*oi
;
3857 if (ospf_oi_count(ifp
) == 0)
3860 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
3861 rn
= route_next(rn
)) {
3868 json_interface_sub
=
3869 json_object_new_object();
3872 show_ip_ospf_interface_traffic_sub(
3873 vty
, oi
, json_interface_sub
, use_json
);
3875 json_object_object_add(
3876 json_vrf
, ifp
->name
,
3877 json_interface_sub
);
3882 /* Interface name is specified. */
3883 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
3885 struct route_node
*rn
;
3886 struct ospf_interface
*oi
;
3888 if (ospf_oi_count(ifp
) == 0) {
3890 " OSPF not enabled on this interface %s\n",
3895 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
3896 rn
= route_next(rn
)) {
3900 json_interface_sub
=
3901 json_object_new_object();
3904 show_ip_ospf_interface_traffic_sub(
3905 vty
, oi
, json_interface_sub
, use_json
);
3907 json_object_object_add(
3908 json_vrf
, ifp
->name
,
3909 json_interface_sub
);
3917 if (ospf
->vrf_id
== VRF_DEFAULT
)
3918 json_object_object_add(json
, "default",
3921 json_object_object_add(json
, ospf
->name
,
3930 DEFUN (show_ip_ospf_interface
,
3931 show_ip_ospf_interface_cmd
,
3932 "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]",
3935 "OSPF information\n"
3938 "Interface information\n"
3943 bool uj
= use_json(argc
, argv
);
3944 struct listnode
*node
= NULL
;
3945 char *vrf_name
= NULL
, *intf_name
= NULL
;
3946 bool all_vrf
= FALSE
;
3947 int ret
= CMD_SUCCESS
;
3949 int idx_vrf
= 0, idx_intf
= 0;
3950 uint8_t use_vrf
= 0;
3951 json_object
*json
= NULL
;
3953 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
3955 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
3956 intf_name
= argv
[idx_intf
]->arg
;
3959 json
= json_object_new_object();
3961 /* vrf input is provided could be all or specific vrf*/
3965 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
3966 if (!ospf
->oi_running
)
3968 ret
= show_ip_ospf_interface_common(
3969 vty
, ospf
, intf_name
, use_vrf
, json
,
3974 vty_out(vty
, "%s\n",
3975 json_object_to_json_string_ext(
3976 json
, JSON_C_TO_STRING_PRETTY
));
3977 json_object_free(json
);
3979 vty_out(vty
, "%% OSPF instance not found\n");
3983 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
3984 if (ospf
== NULL
|| !ospf
->oi_running
) {
3986 vty_out(vty
, "%s\n",
3987 json_object_to_json_string_ext(
3988 json
, JSON_C_TO_STRING_PRETTY
));
3989 json_object_free(json
);
3991 vty_out(vty
, "%% OSPF instance not found\n");
3995 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
3999 /* Display default ospf (instance 0) info */
4000 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4001 if (ospf
== NULL
|| !ospf
->oi_running
) {
4003 vty_out(vty
, "%s\n",
4004 json_object_to_json_string_ext(
4005 json
, JSON_C_TO_STRING_PRETTY
));
4006 json_object_free(json
);
4008 vty_out(vty
, "%% OSPF instance not found\n");
4012 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
4017 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4018 json
, JSON_C_TO_STRING_PRETTY
));
4019 json_object_free(json
);
4025 DEFUN (show_ip_ospf_instance_interface
,
4026 show_ip_ospf_instance_interface_cmd
,
4027 "show ip ospf (1-65535) interface [INTERFACE] [json]",
4030 "OSPF information\n"
4032 "Interface information\n"
4039 unsigned short instance
= 0;
4040 bool uj
= use_json(argc
, argv
);
4041 char *intf_name
= NULL
;
4042 int ret
= CMD_SUCCESS
;
4043 json_object
*json
= NULL
;
4045 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4046 ospf
= ospf_lookup_instance(instance
);
4048 return CMD_NOT_MY_INSTANCE
;
4050 if (!ospf
->oi_running
)
4054 json
= json_object_new_object();
4056 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4057 intf_name
= argv
[idx_intf
]->arg
;
4059 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
, 0, json
, uj
);
4062 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4063 json
, JSON_C_TO_STRING_PRETTY
));
4064 json_object_free(json
);
4070 DEFUN (show_ip_ospf_interface_traffic
,
4071 show_ip_ospf_interface_traffic_cmd
,
4072 "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]",
4075 "OSPF information\n"
4078 "Interface information\n"
4079 "Protocol Packet counters\n"
4083 struct ospf
*ospf
= NULL
;
4084 struct listnode
*node
= NULL
;
4085 char *vrf_name
= NULL
, *intf_name
= NULL
;
4086 bool all_vrf
= FALSE
;
4088 int idx_vrf
= 0, idx_intf
= 0;
4089 bool uj
= use_json(argc
, argv
);
4090 json_object
*json
= NULL
;
4091 int ret
= CMD_SUCCESS
;
4092 int display_once
= 0;
4093 uint8_t use_vrf
= 0;
4095 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4097 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4098 intf_name
= argv
[idx_intf
]->arg
;
4101 json
= json_object_new_object();
4106 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4107 if (!ospf
->oi_running
)
4110 ret
= show_ip_ospf_interface_traffic_common(
4111 vty
, ospf
, intf_name
, json
,
4112 display_once
, use_vrf
, uj
);
4117 vty_out(vty
, "%s\n",
4118 json_object_to_json_string_ext(
4119 json
, JSON_C_TO_STRING_PRETTY
));
4120 json_object_free(json
);
4125 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4126 if (ospf
== NULL
|| !ospf
->oi_running
) {
4128 json_object_free(json
);
4132 ret
= show_ip_ospf_interface_traffic_common(
4133 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4135 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4136 if (ospf
== NULL
|| !ospf
->oi_running
) {
4138 json_object_free(json
);
4142 ret
= show_ip_ospf_interface_traffic_common(
4143 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4147 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4148 json
, JSON_C_TO_STRING_PRETTY
));
4149 json_object_free(json
);
4156 static void show_ip_ospf_neighbour_header(struct vty
*vty
)
4158 vty_out(vty
, "\n%-15s %3s %-15s %9s %-15s %-20s %5s %5s %5s\n",
4159 "Neighbor ID", "Pri", "State", "Dead Time", "Address",
4160 "Interface", "RXmtL", "RqstL", "DBsmL");
4163 static void show_ip_ospf_neighbor_sub(struct vty
*vty
,
4164 struct ospf_interface
*oi
,
4165 json_object
*json
, bool use_json
)
4167 struct route_node
*rn
;
4168 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
4170 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4171 json_object
*json_neighbor
= NULL
, *json_neigh_array
= NULL
;
4173 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
4174 if ((nbr
= rn
->info
)) {
4175 /* Do not show myself. */
4176 if (nbr
== oi
->nbr_self
)
4178 /* Down state is not shown. */
4179 if (nbr
->state
== NSM_Down
)
4182 char neigh_str
[INET_ADDRSTRLEN
];
4185 && !IPV4_ADDR_SAME(&prev_nbr
->src
,
4187 /* Start new neigh list */
4188 json_neigh_array
= NULL
;
4191 if (nbr
->state
== NSM_Attempt
4192 && nbr
->router_id
.s_addr
== 0)
4193 strlcpy(neigh_str
, "neighbor",
4197 inet_ntoa(nbr
->router_id
),
4200 json_object_object_get_ex(json
, neigh_str
,
4203 if (!json_neigh_array
) {
4205 json_object_new_array();
4206 json_object_object_add(
4211 json_neighbor
= json_object_new_object();
4213 ospf_nbr_state_message(nbr
, msgbuf
, 16);
4219 &nbr
->t_inactivity
->u
.sands
,
4223 json_object_int_add(json_neighbor
, "priority",
4225 json_object_string_add(json_neighbor
, "state",
4227 json_object_int_add(json_neighbor
,
4230 json_object_string_add(json_neighbor
, "address",
4231 inet_ntoa(nbr
->src
));
4232 json_object_string_add(json_neighbor
,
4235 json_object_int_add(
4236 json_neighbor
, "retransmitCounter",
4237 ospf_ls_retransmit_count(nbr
));
4238 json_object_int_add(json_neighbor
,
4240 ospf_ls_request_count(nbr
));
4241 json_object_int_add(json_neighbor
,
4243 ospf_db_summary_count(nbr
));
4245 json_object_array_add(json_neigh_array
,
4248 ospf_nbr_state_message(nbr
, msgbuf
, 16);
4250 if (nbr
->state
== NSM_Attempt
4251 && nbr
->router_id
.s_addr
== 0)
4252 vty_out(vty
, "%-15s %3d %-15s ", "-",
4253 nbr
->priority
, msgbuf
);
4255 vty_out(vty
, "%-15s %3d %-15s ",
4256 inet_ntoa(nbr
->router_id
),
4257 nbr
->priority
, msgbuf
);
4259 vty_out(vty
, "%9s ",
4260 ospf_timer_dump(nbr
->t_inactivity
,
4263 vty_out(vty
, "%-15s ", inet_ntoa(nbr
->src
));
4264 vty_out(vty
, "%-20s %5ld %5ld %5d\n",
4266 ospf_ls_retransmit_count(nbr
),
4267 ospf_ls_request_count(nbr
),
4268 ospf_db_summary_count(nbr
));
4275 static int show_ip_ospf_neighbor_common(struct vty
*vty
, struct ospf
*ospf
,
4276 json_object
*json
, bool use_json
,
4279 struct ospf_interface
*oi
;
4280 struct listnode
*node
;
4281 json_object
*json_vrf
= NULL
;
4282 json_object
*json_nbr_sub
= NULL
;
4286 json_vrf
= json_object_new_object();
4289 json_nbr_sub
= json_object_new_object();
4292 if (ospf
->instance
) {
4294 json_object_int_add(json
, "ospfInstance",
4297 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4300 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4302 show_ip_ospf_neighbour_header(vty
);
4304 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4305 if (ospf_interface_neighbor_count(oi
) == 0)
4307 show_ip_ospf_neighbor_sub(vty
, oi
, json_nbr_sub
, use_json
);
4311 json_object_object_add(json_vrf
, "neighbors", json_nbr_sub
);
4313 if (ospf
->vrf_id
== VRF_DEFAULT
)
4314 json_object_object_add(json
, "default",
4317 json_object_object_add(json
, ospf
->name
,
4326 DEFUN (show_ip_ospf_neighbor
,
4327 show_ip_ospf_neighbor_cmd
,
4328 "show ip ospf [vrf <NAME|all>] neighbor [json]",
4331 "OSPF information\n"
4338 bool uj
= use_json(argc
, argv
);
4339 struct listnode
*node
= NULL
;
4340 char *vrf_name
= NULL
;
4341 bool all_vrf
= FALSE
;
4342 int ret
= CMD_SUCCESS
;
4345 uint8_t use_vrf
= 0;
4346 json_object
*json
= NULL
;
4348 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4351 json
= json_object_new_object();
4353 /* vrf input is provided could be all or specific vrf*/
4357 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4358 if (!ospf
->oi_running
)
4360 ret
= show_ip_ospf_neighbor_common(
4361 vty
, ospf
, json
, uj
, use_vrf
);
4365 vty_out(vty
, "%s\n",
4366 json_object_to_json_string_ext(
4367 json
, JSON_C_TO_STRING_PRETTY
));
4368 json_object_free(json
);
4370 vty_out(vty
, "OSPF instance not found\n");
4375 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4376 if (ospf
== NULL
|| !ospf
->oi_running
) {
4378 vty_out(vty
, "%s\n",
4379 json_object_to_json_string_ext(
4380 json
, JSON_C_TO_STRING_PRETTY
));
4381 json_object_free(json
);
4383 vty_out(vty
, "%% OSPF instance not found\n");
4388 /* Display default ospf (instance 0) info */
4389 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4390 if (ospf
== NULL
|| !ospf
->oi_running
) {
4392 vty_out(vty
, "%s\n",
4393 json_object_to_json_string_ext(
4394 json
, JSON_C_TO_STRING_PRETTY
));
4395 json_object_free(json
);
4397 vty_out(vty
, "%% OSPF instance not found\n");
4404 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
,
4408 vty_out(vty
, "%s\n",
4409 json_object_to_json_string_ext(
4410 json
, JSON_C_TO_STRING_PRETTY
));
4415 json_object_free(json
);
4421 DEFUN (show_ip_ospf_instance_neighbor
,
4422 show_ip_ospf_instance_neighbor_cmd
,
4423 "show ip ospf (1-65535) neighbor [json]",
4426 "OSPF information\n"
4433 unsigned short instance
= 0;
4434 bool uj
= use_json(argc
, argv
);
4435 json_object
*json
= NULL
;
4436 int ret
= CMD_SUCCESS
;
4438 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4439 ospf
= ospf_lookup_instance(instance
);
4441 return CMD_NOT_MY_INSTANCE
;
4443 if (!ospf
->oi_running
)
4447 json
= json_object_new_object();
4449 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
, 0);
4452 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4453 json
, JSON_C_TO_STRING_PRETTY
));
4454 json_object_free(json
);
4460 static int show_ip_ospf_neighbor_all_common(struct vty
*vty
, struct ospf
*ospf
,
4461 json_object
*json
, bool use_json
,
4464 struct listnode
*node
;
4465 struct ospf_interface
*oi
;
4466 json_object
*json_vrf
= NULL
;
4467 json_object
*json_neighbor_sub
= NULL
;
4471 json_vrf
= json_object_new_object();
4474 json_neighbor_sub
= json_object_new_object();
4477 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4479 show_ip_ospf_neighbour_header(vty
);
4481 if (ospf
->instance
) {
4483 json_object_int_add(json_vrf
, "ospfInstance",
4486 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4489 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4490 struct listnode
*nbr_node
;
4491 struct ospf_nbr_nbma
*nbr_nbma
;
4493 show_ip_ospf_neighbor_sub(vty
, oi
, json_vrf
, use_json
);
4495 /* print Down neighbor status */
4496 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nbr_node
, nbr_nbma
)) {
4497 if (nbr_nbma
->nbr
== NULL
4498 || nbr_nbma
->nbr
->state
== NSM_Down
) {
4500 json_object_int_add(json_neighbor_sub
,
4502 nbr_nbma
->priority
);
4503 json_object_boolean_true_add(
4506 json_object_string_add(
4510 json_object_int_add(
4512 "nbrNbmaRetransmitCounter", 0);
4513 json_object_int_add(
4515 "nbrNbmaRequestCounter", 0);
4516 json_object_int_add(
4518 "nbrNbmaDbSummaryCounter", 0);
4519 json_object_object_add(
4521 inet_ntoa(nbr_nbma
->addr
),
4524 vty_out(vty
, "%-15s %3d %-15s %9s ",
4525 "-", nbr_nbma
->priority
, "Down",
4528 "%-15s %-20s %5d %5d %5d\n",
4529 inet_ntoa(nbr_nbma
->addr
),
4530 IF_NAME(oi
), 0, 0, 0);
4538 if (ospf
->vrf_id
== VRF_DEFAULT
)
4539 json_object_object_add(json
, "default",
4542 json_object_object_add(json
, ospf
->name
,
4551 DEFUN (show_ip_ospf_neighbor_all
,
4552 show_ip_ospf_neighbor_all_cmd
,
4553 "show ip ospf [vrf <NAME|all>] neighbor all [json]",
4556 "OSPF information\n"
4560 "include down status neighbor\n"
4564 bool uj
= use_json(argc
, argv
);
4565 struct listnode
*node
= NULL
;
4566 char *vrf_name
= NULL
;
4567 bool all_vrf
= FALSE
;
4568 int ret
= CMD_SUCCESS
;
4571 uint8_t use_vrf
= 0;
4572 json_object
*json
= NULL
;
4574 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4577 json
= json_object_new_object();
4579 /* vrf input is provided could be all or specific vrf*/
4583 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4584 if (!ospf
->oi_running
)
4586 ret
= show_ip_ospf_neighbor_all_common(
4587 vty
, ospf
, json
, uj
, use_vrf
);
4591 vty_out(vty
, "%s\n",
4592 json_object_to_json_string_ext(
4593 json
, JSON_C_TO_STRING_PRETTY
));
4594 json_object_free(json
);
4600 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4601 if (ospf
== NULL
|| !ospf
->oi_running
) {
4603 json_object_free(json
);
4607 /* Display default ospf (instance 0) info */
4608 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4609 if (ospf
== NULL
|| !ospf
->oi_running
) {
4611 json_object_free(json
);
4617 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
,
4620 vty_out(vty
, "%s\n",
4621 json_object_to_json_string_ext(
4622 json
, JSON_C_TO_STRING_PRETTY
));
4627 json_object_free(json
);
4632 DEFUN (show_ip_ospf_instance_neighbor_all
,
4633 show_ip_ospf_instance_neighbor_all_cmd
,
4634 "show ip ospf (1-65535) neighbor all [json]",
4637 "OSPF information\n"
4640 "include down status neighbor\n"
4645 unsigned short instance
= 0;
4646 bool uj
= use_json(argc
, argv
);
4647 json_object
*json
= NULL
;
4648 int ret
= CMD_SUCCESS
;
4650 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4651 ospf
= ospf_lookup_instance(instance
);
4653 return CMD_NOT_MY_INSTANCE
;
4655 if (!ospf
->oi_running
)
4658 json
= json_object_new_object();
4660 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
, 0);
4663 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4664 json
, JSON_C_TO_STRING_PRETTY
));
4665 json_object_free(json
);
4671 static int show_ip_ospf_neighbor_int_common(struct vty
*vty
, struct ospf
*ospf
,
4673 struct cmd_token
**argv
,
4674 bool use_json
, uint8_t use_vrf
)
4676 struct interface
*ifp
;
4677 struct route_node
*rn
;
4678 json_object
*json
= NULL
;
4681 json
= json_object_new_object();
4683 if (ospf
->instance
) {
4685 json_object_int_add(json
, "ospfInstance",
4688 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4691 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
4693 ifp
= if_lookup_by_name(argv
[arg_base
]->arg
, ospf
->vrf_id
);
4696 json_object_boolean_true_add(json
, "noSuchIface");
4698 vty_out(vty
, "No such interface.\n");
4702 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
4703 struct ospf_interface
*oi
= rn
->info
;
4708 show_ip_ospf_neighbor_sub(vty
, oi
, json
, use_json
);
4712 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4713 json
, JSON_C_TO_STRING_PRETTY
));
4714 json_object_free(json
);
4721 DEFUN (show_ip_ospf_neighbor_int
,
4722 show_ip_ospf_neighbor_int_cmd
,
4723 "show ip ospf [vrf <NAME>] neighbor IFNAME [json]",
4726 "OSPF information\n"
4735 bool uj
= use_json(argc
, argv
);
4736 int ret
= CMD_SUCCESS
;
4737 struct interface
*ifp
= NULL
;
4738 char *vrf_name
= NULL
;
4739 vrf_id_t vrf_id
= VRF_DEFAULT
;
4740 struct vrf
*vrf
= NULL
;
4742 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
4743 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
4744 if (vrf_name
&& strmatch(vrf_name
, VRF_DEFAULT_NAME
))
4747 vrf
= vrf_lookup_by_name(vrf_name
);
4749 vrf_id
= vrf
->vrf_id
;
4751 ospf
= ospf_lookup_by_vrf_id(vrf_id
);
4753 if (!ospf
|| !ospf
->oi_running
)
4757 show_ip_ospf_neighbour_header(vty
);
4759 argv_find(argv
, argc
, "IFNAME", &idx_ifname
);
4761 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf_id
);
4765 ret
= show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
,
4770 DEFUN (show_ip_ospf_instance_neighbor_int
,
4771 show_ip_ospf_instance_neighbor_int_cmd
,
4772 "show ip ospf (1-65535) neighbor IFNAME [json]",
4775 "OSPF information\n"
4784 unsigned short instance
= 0;
4785 bool uj
= use_json(argc
, argv
);
4788 show_ip_ospf_neighbour_header(vty
);
4790 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4791 ospf
= ospf_lookup_instance(instance
);
4793 return CMD_NOT_MY_INSTANCE
;
4795 if (!ospf
->oi_running
)
4799 show_ip_ospf_neighbour_header(vty
);
4801 return show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
, argv
, uj
,
4805 static void show_ip_ospf_nbr_nbma_detail_sub(struct vty
*vty
,
4806 struct ospf_interface
*oi
,
4807 struct ospf_nbr_nbma
*nbr_nbma
,
4808 bool use_json
, json_object
*json
)
4810 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4811 json_object
*json_sub
= NULL
;
4814 json_sub
= json_object_new_object();
4815 else /* Show neighbor ID. */
4816 vty_out(vty
, " Neighbor %s,", "-");
4818 /* Show interface address. */
4820 json_object_string_add(json_sub
, "ifaceAddress",
4821 inet_ntoa(nbr_nbma
->addr
));
4823 vty_out(vty
, " interface address %s\n",
4824 inet_ntoa(nbr_nbma
->addr
));
4828 json_object_string_add(json_sub
, "areaId",
4829 ospf_area_desc_string(oi
->area
));
4830 json_object_string_add(json_sub
, "iface", IF_NAME(oi
));
4832 vty_out(vty
, " In the area %s via interface %s\n",
4833 ospf_area_desc_string(oi
->area
), IF_NAME(oi
));
4835 /* Show neighbor priority and state. */
4837 json_object_int_add(json_sub
, "nbrPriority",
4838 nbr_nbma
->priority
);
4839 json_object_string_add(json_sub
, "nbrState", "down");
4841 vty_out(vty
, " Neighbor priority is %d, State is %s,",
4842 nbr_nbma
->priority
, "Down");
4844 /* Show state changes. */
4846 json_object_int_add(json_sub
, "stateChangeCounter",
4847 nbr_nbma
->state_change
);
4849 vty_out(vty
, " %d state changes\n", nbr_nbma
->state_change
);
4851 /* Show PollInterval */
4853 json_object_int_add(json_sub
, "pollInterval", nbr_nbma
->v_poll
);
4855 vty_out(vty
, " Poll interval %d\n", nbr_nbma
->v_poll
);
4857 /* Show poll-interval timer. */
4858 if (nbr_nbma
->t_poll
) {
4861 time_store
= monotime_until(&nbr_nbma
->t_poll
->u
.sands
,
4863 json_object_int_add(json_sub
,
4864 "pollIntervalTimerDueMsec",
4867 vty_out(vty
, " Poll timer due in %s\n",
4868 ospf_timer_dump(nbr_nbma
->t_poll
, timebuf
,
4872 /* Show poll-interval timer thread. */
4874 if (nbr_nbma
->t_poll
!= NULL
)
4875 json_object_string_add(json_sub
,
4876 "pollIntervalTimerThread", "on");
4878 vty_out(vty
, " Thread Poll Timer %s\n",
4879 nbr_nbma
->t_poll
!= NULL
? "on" : "off");
4882 json_object_object_add(json
, "noNbrId", json_sub
);
4885 static void show_ip_ospf_neighbor_detail_sub(struct vty
*vty
,
4886 struct ospf_interface
*oi
,
4887 struct ospf_neighbor
*nbr
,
4888 json_object
*json
, bool use_json
)
4890 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4891 json_object
*json_sub
= NULL
;
4894 json_sub
= json_object_new_object();
4896 /* Show neighbor ID. */
4897 if (nbr
->state
== NSM_Attempt
&& nbr
->router_id
.s_addr
== 0)
4898 vty_out(vty
, " Neighbor %s,", "-");
4900 vty_out(vty
, " Neighbor %s,",
4901 inet_ntoa(nbr
->router_id
));
4904 /* Show interface address. */
4906 json_object_string_add(json_sub
, "ifaceAddress",
4907 inet_ntoa(nbr
->address
.u
.prefix4
));
4909 vty_out(vty
, " interface address %s\n",
4910 inet_ntoa(nbr
->address
.u
.prefix4
));
4914 json_object_string_add(json_sub
, "areaId",
4915 ospf_area_desc_string(oi
->area
));
4916 json_object_string_add(json_sub
, "ifaceName", oi
->ifp
->name
);
4918 vty_out(vty
, " In the area %s via interface %s\n",
4919 ospf_area_desc_string(oi
->area
), oi
->ifp
->name
);
4921 /* Show neighbor priority and state. */
4923 json_object_int_add(json_sub
, "nbrPriority", nbr
->priority
);
4924 json_object_string_add(
4925 json_sub
, "nbrState",
4926 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
4928 vty_out(vty
, " Neighbor priority is %d, State is %s,",
4930 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
4932 /* Show state changes. */
4934 json_object_int_add(json_sub
, "stateChangeCounter",
4937 vty_out(vty
, " %d state changes\n", nbr
->state_change
);
4939 if (nbr
->ts_last_progress
.tv_sec
|| nbr
->ts_last_progress
.tv_usec
) {
4944 monotime_since(&nbr
->ts_last_progress
, &res
) / 1000LL;
4946 json_object_int_add(json_sub
, "lastPrgrsvChangeMsec",
4950 " Most recent state change statistics:\n");
4951 vty_out(vty
, " Progressive change %s ago\n",
4952 ospf_timeval_dump(&res
, timebuf
,
4957 if (nbr
->ts_last_regress
.tv_sec
|| nbr
->ts_last_regress
.tv_usec
) {
4962 monotime_since(&nbr
->ts_last_regress
, &res
) / 1000LL;
4964 json_object_int_add(json_sub
,
4965 "lastRegressiveChangeMsec",
4967 if (nbr
->last_regress_str
)
4968 json_object_string_add(
4969 json_sub
, "lastRegressiveChangeReason",
4970 nbr
->last_regress_str
);
4973 " Regressive change %s ago, due to %s\n",
4974 ospf_timeval_dump(&res
, timebuf
,
4976 (nbr
->last_regress_str
? nbr
->last_regress_str
4981 /* Show Designated Rotuer ID. */
4983 json_object_string_add(json_sub
, "routerDesignatedId",
4984 inet_ntoa(nbr
->d_router
));
4986 vty_out(vty
, " DR is %s,", inet_ntoa(nbr
->d_router
));
4988 /* Show Backup Designated Rotuer ID. */
4990 json_object_string_add(json_sub
, "routerDesignatedBackupId",
4991 inet_ntoa(nbr
->bd_router
));
4993 vty_out(vty
, " BDR is %s\n", inet_ntoa(nbr
->bd_router
));
4997 json_object_int_add(json_sub
, "optionsCounter", nbr
->options
);
4998 json_object_string_add(json_sub
, "optionsList",
4999 ospf_options_dump(nbr
->options
));
5001 vty_out(vty
, " Options %d %s\n", nbr
->options
,
5002 ospf_options_dump(nbr
->options
));
5004 /* Show Router Dead interval timer. */
5006 if (nbr
->t_inactivity
) {
5008 time_store
= monotime_until(&nbr
->t_inactivity
->u
.sands
,
5011 json_object_int_add(json_sub
,
5012 "routerDeadIntervalTimerDueMsec",
5015 json_object_int_add(
5016 json_sub
, "routerDeadIntervalTimerDueMsec", -1);
5018 vty_out(vty
, " Dead timer due in %s\n",
5019 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
5022 /* Show Database Summary list. */
5024 json_object_int_add(json_sub
, "databaseSummaryListCounter",
5025 ospf_db_summary_count(nbr
));
5027 vty_out(vty
, " Database Summary List %d\n",
5028 ospf_db_summary_count(nbr
));
5030 /* Show Link State Request list. */
5032 json_object_int_add(json_sub
, "linkStateRequestListCounter",
5033 ospf_ls_request_count(nbr
));
5035 vty_out(vty
, " Link State Request List %ld\n",
5036 ospf_ls_request_count(nbr
));
5038 /* Show Link State Retransmission list. */
5040 json_object_int_add(json_sub
,
5041 "linkStateRetransmissionListCounter",
5042 ospf_ls_retransmit_count(nbr
));
5044 vty_out(vty
, " Link State Retransmission List %ld\n",
5045 ospf_ls_retransmit_count(nbr
));
5047 /* Show inactivity timer thread. */
5049 if (nbr
->t_inactivity
!= NULL
)
5050 json_object_string_add(json_sub
,
5051 "threadInactivityTimer", "on");
5053 vty_out(vty
, " Thread Inactivity Timer %s\n",
5054 nbr
->t_inactivity
!= NULL
? "on" : "off");
5056 /* Show Database Description retransmission thread. */
5058 if (nbr
->t_db_desc
!= NULL
)
5059 json_object_string_add(
5061 "threadDatabaseDescriptionRetransmission",
5065 " Thread Database Description Retransmision %s\n",
5066 nbr
->t_db_desc
!= NULL
? "on" : "off");
5068 /* Show Link State Request Retransmission thread. */
5070 if (nbr
->t_ls_req
!= NULL
)
5071 json_object_string_add(
5073 "threadLinkStateRequestRetransmission", "on");
5076 " Thread Link State Request Retransmission %s\n",
5077 nbr
->t_ls_req
!= NULL
? "on" : "off");
5079 /* Show Link State Update Retransmission thread. */
5081 if (nbr
->t_ls_upd
!= NULL
)
5082 json_object_string_add(
5083 json_sub
, "threadLinkStateUpdateRetransmission",
5087 " Thread Link State Update Retransmission %s\n\n",
5088 nbr
->t_ls_upd
!= NULL
? "on" : "off");
5091 if (nbr
->state
== NSM_Attempt
&& nbr
->router_id
.s_addr
== 0)
5092 json_object_object_add(json
, "noNbrId", json_sub
);
5094 json_object_object_add(json
, inet_ntoa(nbr
->router_id
),
5098 ospf_bfd_show_info(vty
, nbr
->bfd_info
, json
, use_json
, 0);
5101 static int show_ip_ospf_neighbor_id_common(struct vty
*vty
, struct ospf
*ospf
,
5102 struct in_addr
*router_id
,
5103 bool use_json
, uint8_t use_vrf
)
5105 struct listnode
*node
;
5106 struct ospf_neighbor
*nbr
;
5107 struct ospf_interface
*oi
;
5108 json_object
*json
= NULL
;
5111 json
= json_object_new_object();
5113 if (ospf
->instance
) {
5115 json_object_int_add(json
, "ospfInstance",
5118 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5121 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
5123 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5124 if ((nbr
= ospf_nbr_lookup_by_routerid(oi
->nbrs
, router_id
))) {
5125 show_ip_ospf_neighbor_detail_sub(vty
, oi
, nbr
, json
,
5131 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5132 json
, JSON_C_TO_STRING_PRETTY
));
5133 json_object_free(json
);
5140 DEFPY (show_ip_ospf_neighbor_id
,
5141 show_ip_ospf_neighbor_id_cmd
,
5142 "show ip ospf neighbor A.B.C.D$router_id [json$json]",
5145 "OSPF information\n"
5151 struct listnode
*node
;
5152 int ret
= CMD_SUCCESS
;
5154 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5155 if (!ospf
->oi_running
)
5157 ret
= show_ip_ospf_neighbor_id_common(vty
, ospf
, &router_id
,
5164 DEFPY (show_ip_ospf_instance_neighbor_id
,
5165 show_ip_ospf_instance_neighbor_id_cmd
,
5166 "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [json$json]",
5169 "OSPF information\n"
5177 ospf
= ospf_lookup_instance(instance
);
5179 return CMD_NOT_MY_INSTANCE
;
5181 if (!ospf
->oi_running
)
5184 return show_ip_ospf_neighbor_id_common(vty
, ospf
, &router_id
, !!json
,
5188 static int show_ip_ospf_neighbor_detail_common(struct vty
*vty
,
5190 json_object
*json
, bool use_json
,
5193 struct ospf_interface
*oi
;
5194 struct listnode
*node
;
5195 json_object
*json_vrf
= NULL
;
5199 json_vrf
= json_object_new_object();
5203 if (ospf
->instance
) {
5205 json_object_int_add(json_vrf
, "ospfInstance",
5208 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5211 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5213 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5214 struct route_node
*rn
;
5215 struct ospf_neighbor
*nbr
;
5217 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5218 if ((nbr
= rn
->info
)) {
5219 if (nbr
!= oi
->nbr_self
) {
5220 if (nbr
->state
!= NSM_Down
) {
5221 show_ip_ospf_neighbor_detail_sub(
5222 vty
, oi
, nbr
, json_vrf
,
5232 if (ospf
->vrf_id
== VRF_DEFAULT
)
5233 json_object_object_add(json
, "default",
5236 json_object_object_add(json
, ospf
->name
,
5245 DEFUN (show_ip_ospf_neighbor_detail
,
5246 show_ip_ospf_neighbor_detail_cmd
,
5247 "show ip ospf [vrf <NAME|all>] neighbor detail [json]",
5250 "OSPF information\n"
5254 "detail of all neighbors\n"
5258 bool uj
= use_json(argc
, argv
);
5259 struct listnode
*node
= NULL
;
5260 char *vrf_name
= NULL
;
5261 bool all_vrf
= FALSE
;
5262 int ret
= CMD_SUCCESS
;
5265 uint8_t use_vrf
= 0;
5266 json_object
*json
= NULL
;
5268 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5271 json
= json_object_new_object();
5273 /* vrf input is provided could be all or specific vrf*/
5277 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5278 if (!ospf
->oi_running
)
5280 ret
= show_ip_ospf_neighbor_detail_common(
5281 vty
, ospf
, json
, uj
, use_vrf
);
5284 vty_out(vty
, "%s\n",
5285 json_object_to_json_string_ext(
5286 json
, JSON_C_TO_STRING_PRETTY
));
5287 json_object_free(json
);
5292 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5293 if (ospf
== NULL
|| !ospf
->oi_running
) {
5295 json_object_free(json
);
5299 /* Display default ospf (instance 0) info */
5300 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5301 if (ospf
== NULL
|| !ospf
->oi_running
) {
5303 json_object_free(json
);
5309 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
,
5312 vty_out(vty
, "%s\n",
5313 json_object_to_json_string_ext(
5314 json
, JSON_C_TO_STRING_PRETTY
));
5319 json_object_free(json
);
5324 DEFUN (show_ip_ospf_instance_neighbor_detail
,
5325 show_ip_ospf_instance_neighbor_detail_cmd
,
5326 "show ip ospf (1-65535) neighbor detail [json]",
5329 "OSPF information\n"
5332 "detail of all neighbors\n"
5337 unsigned short instance
= 0;
5338 bool uj
= use_json(argc
, argv
);
5339 json_object
*json
= NULL
;
5340 int ret
= CMD_SUCCESS
;
5342 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5343 ospf
= ospf_lookup_instance(instance
);
5345 return CMD_NOT_MY_INSTANCE
;
5347 if (!ospf
->oi_running
)
5351 json
= json_object_new_object();
5353 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
, 0);
5356 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5357 json
, JSON_C_TO_STRING_PRETTY
));
5358 json_object_free(json
);
5364 static int show_ip_ospf_neighbor_detail_all_common(struct vty
*vty
,
5370 struct listnode
*node
;
5371 struct ospf_interface
*oi
;
5372 json_object
*json_vrf
= NULL
;
5376 json_vrf
= json_object_new_object();
5381 if (ospf
->instance
) {
5383 json_object_int_add(json
, "ospfInstance",
5386 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5389 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5391 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5392 struct route_node
*rn
;
5393 struct ospf_neighbor
*nbr
;
5394 struct ospf_nbr_nbma
*nbr_nbma
;
5396 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
5397 if ((nbr
= rn
->info
))
5398 if (nbr
!= oi
->nbr_self
)
5399 if (nbr
->state
!= NSM_Down
)
5400 show_ip_ospf_neighbor_detail_sub(
5402 json_vrf
, use_json
);
5404 if (oi
->type
== OSPF_IFTYPE_NBMA
) {
5405 struct listnode
*nd
;
5407 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nd
, nbr_nbma
)) {
5408 if (nbr_nbma
->nbr
== NULL
5409 || nbr_nbma
->nbr
->state
== NSM_Down
)
5410 show_ip_ospf_nbr_nbma_detail_sub(
5411 vty
, oi
, nbr_nbma
, use_json
,
5419 if (ospf
->vrf_id
== VRF_DEFAULT
)
5420 json_object_object_add(json
, "default",
5423 json_object_object_add(json
, ospf
->name
,
5433 DEFUN (show_ip_ospf_neighbor_detail_all
,
5434 show_ip_ospf_neighbor_detail_all_cmd
,
5435 "show ip ospf [vrf <NAME|all>] neighbor detail all [json]",
5438 "OSPF information\n"
5442 "detail of all neighbors\n"
5443 "include down status neighbor\n"
5447 bool uj
= use_json(argc
, argv
);
5448 struct listnode
*node
= NULL
;
5449 char *vrf_name
= NULL
;
5450 bool all_vrf
= FALSE
;
5451 int ret
= CMD_SUCCESS
;
5454 uint8_t use_vrf
= 0;
5455 json_object
*json
= NULL
;
5457 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5460 json
= json_object_new_object();
5462 /* vrf input is provided could be all or specific vrf*/
5466 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5467 if (!ospf
->oi_running
)
5469 ret
= show_ip_ospf_neighbor_detail_all_common(
5470 vty
, ospf
, json
, uj
, use_vrf
);
5474 vty_out(vty
, "%s\n",
5475 json_object_to_json_string_ext(
5476 json
, JSON_C_TO_STRING_PRETTY
));
5477 json_object_free(json
);
5482 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5483 if (ospf
== NULL
|| !ospf
->oi_running
) {
5485 json_object_free(json
);
5489 /* Display default ospf (instance 0) info */
5490 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5491 if (ospf
== NULL
|| !ospf
->oi_running
) {
5493 json_object_free(json
);
5499 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
,
5502 vty_out(vty
, "%s\n",
5503 json_object_to_json_string_ext(
5504 json
, JSON_C_TO_STRING_PRETTY
));
5509 json_object_free(json
);
5514 DEFUN (show_ip_ospf_instance_neighbor_detail_all
,
5515 show_ip_ospf_instance_neighbor_detail_all_cmd
,
5516 "show ip ospf (1-65535) neighbor detail all [json]",
5519 "OSPF information\n"
5522 "detail of all neighbors\n"
5523 "include down status neighbor\n"
5528 unsigned short instance
= 0;
5529 bool uj
= use_json(argc
, argv
);
5530 json_object
*json
= NULL
;
5531 int ret
= CMD_SUCCESS
;
5533 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5534 ospf
= ospf_lookup_instance(instance
);
5536 return CMD_NOT_MY_INSTANCE
;
5538 if (!ospf
->oi_running
)
5542 json
= json_object_new_object();
5544 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
, uj
, 0);
5547 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5548 json
, JSON_C_TO_STRING_PRETTY
));
5549 json_object_free(json
);
5555 static int show_ip_ospf_neighbor_int_detail_common(struct vty
*vty
,
5558 struct cmd_token
**argv
,
5561 struct ospf_interface
*oi
;
5562 struct interface
*ifp
;
5563 struct route_node
*rn
, *nrn
;
5564 struct ospf_neighbor
*nbr
;
5565 json_object
*json
= NULL
;
5568 json
= json_object_new_object();
5570 if (ospf
->instance
) {
5572 json_object_int_add(json
, "ospfInstance",
5575 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5578 ifp
= if_lookup_by_name(argv
[arg_base
]->arg
, ospf
->vrf_id
);
5581 vty_out(vty
, "No such interface.\n");
5583 vty_out(vty
, "{}\n");
5584 json_object_free(json
);
5589 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
5590 if ((oi
= rn
->info
)) {
5591 for (nrn
= route_top(oi
->nbrs
); nrn
;
5592 nrn
= route_next(nrn
)) {
5593 if ((nbr
= nrn
->info
)) {
5594 if (nbr
!= oi
->nbr_self
) {
5595 if (nbr
->state
!= NSM_Down
)
5596 show_ip_ospf_neighbor_detail_sub(
5606 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5607 json
, JSON_C_TO_STRING_PRETTY
));
5608 json_object_free(json
);
5615 DEFUN (show_ip_ospf_neighbor_int_detail
,
5616 show_ip_ospf_neighbor_int_detail_cmd
,
5617 "show ip ospf neighbor IFNAME detail [json]",
5620 "OSPF information\n"
5623 "detail of all neighbors\n"
5627 bool uj
= use_json(argc
, argv
);
5628 struct listnode
*node
= NULL
;
5629 int ret
= CMD_SUCCESS
;
5630 bool ospf_output
= FALSE
;
5632 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5633 if (!ospf
->oi_running
)
5636 ret
= show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, 0,
5641 vty_out(vty
, "%% OSPF instance not found\n");
5646 DEFUN (show_ip_ospf_instance_neighbor_int_detail
,
5647 show_ip_ospf_instance_neighbor_int_detail_cmd
,
5648 "show ip ospf (1-65535) neighbor IFNAME detail [json]",
5651 "OSPF information\n"
5655 "detail of all neighbors\n"
5661 unsigned short instance
= 0;
5662 bool uj
= use_json(argc
, argv
);
5664 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5665 ospf
= ospf_lookup_instance(instance
);
5667 return CMD_NOT_MY_INSTANCE
;
5669 if (!ospf
->oi_running
)
5672 return show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, idx_ifname
,
5676 /* Show functions */
5677 static int show_lsa_summary(struct vty
*vty
, struct ospf_lsa
*lsa
, int self
)
5679 struct router_lsa
*rl
;
5680 struct summary_lsa
*sl
;
5681 struct as_external_lsa
*asel
;
5682 struct prefix_ipv4 p
;
5685 /* If self option is set, check LSA self flag. */
5686 if (self
== 0 || IS_LSA_SELF(lsa
)) {
5687 /* LSA common part show. */
5688 vty_out(vty
, "%-15s ", inet_ntoa(lsa
->data
->id
));
5689 vty_out(vty
, "%-15s %4d 0x%08lx 0x%04x",
5690 inet_ntoa(lsa
->data
->adv_router
), LS_AGE(lsa
),
5691 (unsigned long)ntohl(lsa
->data
->ls_seqnum
),
5692 ntohs(lsa
->data
->checksum
));
5693 /* LSA specific part show. */
5694 switch (lsa
->data
->type
) {
5695 case OSPF_ROUTER_LSA
:
5696 rl
= (struct router_lsa
*)lsa
->data
;
5697 vty_out(vty
, " %-d", ntohs(rl
->links
));
5699 case OSPF_SUMMARY_LSA
:
5700 sl
= (struct summary_lsa
*)lsa
->data
;
5703 p
.prefix
= sl
->header
.id
;
5704 p
.prefixlen
= ip_masklen(sl
->mask
);
5705 apply_mask_ipv4(&p
);
5707 vty_out(vty
, " %s/%d", inet_ntoa(p
.prefix
),
5710 case OSPF_AS_EXTERNAL_LSA
:
5711 case OSPF_AS_NSSA_LSA
:
5712 asel
= (struct as_external_lsa
*)lsa
->data
;
5715 p
.prefix
= asel
->header
.id
;
5716 p
.prefixlen
= ip_masklen(asel
->mask
);
5717 apply_mask_ipv4(&p
);
5719 vty_out(vty
, " %s %s/%d [0x%lx]",
5720 IS_EXTERNAL_METRIC(asel
->e
[0].tos
)
5723 inet_ntoa(p
.prefix
), p
.prefixlen
,
5724 (unsigned long)ntohl(
5725 asel
->e
[0].route_tag
));
5727 case OSPF_NETWORK_LSA
:
5728 case OSPF_ASBR_SUMMARY_LSA
:
5729 case OSPF_OPAQUE_LINK_LSA
:
5730 case OSPF_OPAQUE_AREA_LSA
:
5731 case OSPF_OPAQUE_AS_LSA
:
5741 static const char *show_database_desc
[] = {
5743 "Router Link States",
5745 "Summary Link States",
5746 "ASBR-Summary Link States",
5747 "AS External Link States",
5748 "Group Membership LSA",
5749 "NSSA-external Link States",
5751 "Link-Local Opaque-LSA",
5752 "Area-Local Opaque-LSA",
5753 "AS-external Opaque-LSA",
5756 static const char *show_database_header
[] = {
5758 "Link ID ADV Router Age Seq# CkSum Link count",
5759 "Link ID ADV Router Age Seq# CkSum",
5760 "Link ID ADV Router Age Seq# CkSum Route",
5761 "Link ID ADV Router Age Seq# CkSum",
5762 "Link ID ADV Router Age Seq# CkSum Route",
5763 " --- header for Group Member ----",
5764 "Link ID ADV Router Age Seq# CkSum Route",
5766 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5767 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5768 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5771 static void show_ip_ospf_database_header(struct vty
*vty
, struct ospf_lsa
*lsa
)
5773 struct router_lsa
*rlsa
= (struct router_lsa
*)lsa
->data
;
5775 vty_out(vty
, " LS age: %d\n", LS_AGE(lsa
));
5776 vty_out(vty
, " Options: 0x%-2x : %s\n", lsa
->data
->options
,
5777 ospf_options_dump(lsa
->data
->options
));
5778 vty_out(vty
, " LS Flags: 0x%-2x %s\n", lsa
->flags
,
5779 ((lsa
->flags
& OSPF_LSA_LOCAL_XLT
) ? "(Translated from Type-7)"
5782 if (lsa
->data
->type
== OSPF_ROUTER_LSA
) {
5783 vty_out(vty
, " Flags: 0x%x", rlsa
->flags
);
5786 vty_out(vty
, " :%s%s%s%s",
5787 IS_ROUTER_LSA_BORDER(rlsa
) ? " ABR" : "",
5788 IS_ROUTER_LSA_EXTERNAL(rlsa
) ? " ASBR" : "",
5789 IS_ROUTER_LSA_VIRTUAL(rlsa
) ? " VL-endpoint"
5791 IS_ROUTER_LSA_SHORTCUT(rlsa
) ? " Shortcut"
5796 vty_out(vty
, " LS Type: %s\n",
5797 lookup_msg(ospf_lsa_type_msg
, lsa
->data
->type
, NULL
));
5798 vty_out(vty
, " Link State ID: %s %s\n", inet_ntoa(lsa
->data
->id
),
5799 lookup_msg(ospf_link_state_id_type_msg
, lsa
->data
->type
, NULL
));
5800 vty_out(vty
, " Advertising Router: %s\n",
5801 inet_ntoa(lsa
->data
->adv_router
));
5802 vty_out(vty
, " LS Seq Number: %08lx\n",
5803 (unsigned long)ntohl(lsa
->data
->ls_seqnum
));
5804 vty_out(vty
, " Checksum: 0x%04x\n", ntohs(lsa
->data
->checksum
));
5805 vty_out(vty
, " Length: %d\n\n", ntohs(lsa
->data
->length
));
5808 const char *link_type_desc
[] = {
5810 "another Router (point-to-point)",
5811 "a Transit Network",
5816 const char *link_id_desc
[] = {
5817 "(null)", "Neighboring Router ID", "Designated Router address",
5818 "Net", "Neighboring Router ID",
5821 const char *link_data_desc
[] = {
5822 "(null)", "Router Interface address", "Router Interface address",
5823 "Network Mask", "Router Interface address",
5826 /* Show router-LSA each Link information. */
5827 static void show_ip_ospf_database_router_links(struct vty
*vty
,
5828 struct router_lsa
*rl
)
5833 len
= ntohs(rl
->header
.length
) - 4;
5834 for (i
= 0; i
< ntohs(rl
->links
) && len
> 0; len
-= 12, i
++) {
5835 type
= rl
->link
[i
].type
;
5837 vty_out(vty
, " Link connected to: %s\n",
5838 link_type_desc
[type
]);
5839 vty_out(vty
, " (Link ID) %s: %s\n", link_id_desc
[type
],
5840 inet_ntoa(rl
->link
[i
].link_id
));
5841 vty_out(vty
, " (Link Data) %s: %s\n", link_data_desc
[type
],
5842 inet_ntoa(rl
->link
[i
].link_data
));
5843 vty_out(vty
, " Number of TOS metrics: 0\n");
5844 vty_out(vty
, " TOS 0 Metric: %d\n",
5845 ntohs(rl
->link
[i
].metric
));
5850 /* Show router-LSA detail information. */
5851 static int show_router_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5854 struct router_lsa
*rl
= (struct router_lsa
*)lsa
->data
;
5856 show_ip_ospf_database_header(vty
, lsa
);
5858 vty_out(vty
, " Number of Links: %d\n\n", ntohs(rl
->links
));
5860 show_ip_ospf_database_router_links(vty
, rl
);
5867 /* Show network-LSA detail information. */
5868 static int show_network_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5873 struct network_lsa
*nl
= (struct network_lsa
*)lsa
->data
;
5875 show_ip_ospf_database_header(vty
, lsa
);
5877 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(nl
->mask
));
5879 length
= ntohs(lsa
->data
->length
) - OSPF_LSA_HEADER_SIZE
- 4;
5881 for (i
= 0; length
> 0; i
++, length
-= 4)
5882 vty_out(vty
, " Attached Router: %s\n",
5883 inet_ntoa(nl
->routers
[i
]));
5891 /* Show summary-LSA detail information. */
5892 static int show_summary_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5895 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
5897 show_ip_ospf_database_header(vty
, lsa
);
5899 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(sl
->mask
));
5900 vty_out(vty
, " TOS: 0 Metric: %d\n",
5901 GET_METRIC(sl
->metric
));
5908 /* Show summary-ASBR-LSA detail information. */
5909 static int show_summary_asbr_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5912 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
5914 show_ip_ospf_database_header(vty
, lsa
);
5916 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(sl
->mask
));
5917 vty_out(vty
, " TOS: 0 Metric: %d\n",
5918 GET_METRIC(sl
->metric
));
5925 /* Show AS-external-LSA detail information. */
5926 static int show_as_external_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5929 struct as_external_lsa
*al
=
5930 (struct as_external_lsa
*)lsa
->data
;
5932 show_ip_ospf_database_header(vty
, lsa
);
5934 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(al
->mask
));
5935 vty_out(vty
, " Metric Type: %s\n",
5936 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
5937 ? "2 (Larger than any link state path)"
5939 vty_out(vty
, " TOS: 0\n");
5940 vty_out(vty
, " Metric: %d\n",
5941 GET_METRIC(al
->e
[0].metric
));
5942 vty_out(vty
, " Forward Address: %s\n",
5943 inet_ntoa(al
->e
[0].fwd_addr
));
5946 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
5947 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
5954 show_as_external_lsa_stdvty (struct ospf_lsa
*lsa
)
5956 struct as_external_lsa
*al
= (struct as_external_lsa
*) lsa
->data
;
5958 /* show_ip_ospf_database_header (vty, lsa); */
5960 zlog_debug( " Network Mask: /%d%s",
5961 ip_masklen (al
->mask
), "\n");
5962 zlog_debug( " Metric Type: %s%s",
5963 IS_EXTERNAL_METRIC (al
->e
[0].tos
) ?
5964 "2 (Larger than any link state path)" : "1", "\n");
5965 zlog_debug( " TOS: 0%s", "\n");
5966 zlog_debug( " Metric: %d%s",
5967 GET_METRIC (al
->e
[0].metric
), "\n");
5968 zlog_debug( " Forward Address: %s%s",
5969 inet_ntoa (al
->e
[0].fwd_addr
), "\n");
5971 zlog_debug( " External Route Tag: %"ROUTE_TAG_PRI
"%s%s",
5972 (route_tag_t
)ntohl (al
->e
[0].route_tag
), "\n", "\n");
5977 /* Show AS-NSSA-LSA detail information. */
5978 static int show_as_nssa_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5981 struct as_external_lsa
*al
=
5982 (struct as_external_lsa
*)lsa
->data
;
5984 show_ip_ospf_database_header(vty
, lsa
);
5986 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(al
->mask
));
5987 vty_out(vty
, " Metric Type: %s\n",
5988 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
5989 ? "2 (Larger than any link state path)"
5991 vty_out(vty
, " TOS: 0\n");
5992 vty_out(vty
, " Metric: %d\n",
5993 GET_METRIC(al
->e
[0].metric
));
5994 vty_out(vty
, " NSSA: Forward Address: %s\n",
5995 inet_ntoa(al
->e
[0].fwd_addr
));
5998 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
5999 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6005 static int show_func_dummy(struct vty
*vty
, struct ospf_lsa
*lsa
)
6010 static int show_opaque_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
6013 show_ip_ospf_database_header(vty
, lsa
);
6014 show_opaque_info_detail(vty
, lsa
);
6021 int (*show_function
[])(struct vty
*, struct ospf_lsa
*) = {
6023 show_router_lsa_detail
,
6024 show_network_lsa_detail
,
6025 show_summary_lsa_detail
,
6026 show_summary_asbr_lsa_detail
,
6027 show_as_external_lsa_detail
,
6029 show_as_nssa_lsa_detail
, /* almost same as external */
6031 show_opaque_lsa_detail
,
6032 show_opaque_lsa_detail
,
6033 show_opaque_lsa_detail
,
6036 static void show_lsa_prefix_set(struct vty
*vty
, struct prefix_ls
*lp
,
6037 struct in_addr
*id
, struct in_addr
*adv_router
)
6039 memset(lp
, 0, sizeof(struct prefix_ls
));
6043 else if (adv_router
== NULL
) {
6049 lp
->adv_router
= *adv_router
;
6053 static void show_lsa_detail_proc(struct vty
*vty
, struct route_table
*rt
,
6054 struct in_addr
*id
, struct in_addr
*adv_router
)
6056 struct prefix_ls lp
;
6057 struct route_node
*rn
, *start
;
6058 struct ospf_lsa
*lsa
;
6060 show_lsa_prefix_set(vty
, &lp
, id
, adv_router
);
6061 start
= route_node_get(rt
, (struct prefix
*)&lp
);
6063 route_lock_node(start
);
6064 for (rn
= start
; rn
; rn
= route_next_until(rn
, start
))
6065 if ((lsa
= rn
->info
)) {
6066 if (show_function
[lsa
->data
->type
] != NULL
)
6067 show_function
[lsa
->data
->type
](vty
,
6070 route_unlock_node(start
);
6074 /* Show detail LSA information
6075 -- if id is NULL then show all LSAs. */
6076 static void show_lsa_detail(struct vty
*vty
, struct ospf
*ospf
, int type
,
6077 struct in_addr
*id
, struct in_addr
*adv_router
)
6079 struct listnode
*node
;
6080 struct ospf_area
*area
;
6083 case OSPF_AS_EXTERNAL_LSA
:
6084 case OSPF_OPAQUE_AS_LSA
:
6085 vty_out(vty
, " %s \n\n",
6086 show_database_desc
[type
]);
6087 show_lsa_detail_proc(vty
, AS_LSDB(ospf
, type
), id
, adv_router
);
6090 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6091 vty_out(vty
, "\n %s (Area %s)\n\n",
6092 show_database_desc
[type
],
6093 ospf_area_desc_string(area
));
6094 show_lsa_detail_proc(vty
, AREA_LSDB(area
, type
), id
,
6101 static void show_lsa_detail_adv_router_proc(struct vty
*vty
,
6102 struct route_table
*rt
,
6103 struct in_addr
*adv_router
)
6105 struct route_node
*rn
;
6106 struct ospf_lsa
*lsa
;
6108 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
))
6109 if ((lsa
= rn
->info
))
6110 if (IPV4_ADDR_SAME(adv_router
,
6111 &lsa
->data
->adv_router
)) {
6112 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
6114 if (show_function
[lsa
->data
->type
] != NULL
)
6115 show_function
[lsa
->data
->type
](vty
,
6120 /* Show detail LSA information. */
6121 static void show_lsa_detail_adv_router(struct vty
*vty
, struct ospf
*ospf
,
6122 int type
, struct in_addr
*adv_router
)
6124 struct listnode
*node
;
6125 struct ospf_area
*area
;
6128 case OSPF_AS_EXTERNAL_LSA
:
6129 case OSPF_OPAQUE_AS_LSA
:
6130 vty_out(vty
, " %s \n\n",
6131 show_database_desc
[type
]);
6132 show_lsa_detail_adv_router_proc(vty
, AS_LSDB(ospf
, type
),
6136 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6137 vty_out(vty
, "\n %s (Area %s)\n\n",
6138 show_database_desc
[type
],
6139 ospf_area_desc_string(area
));
6140 show_lsa_detail_adv_router_proc(
6141 vty
, AREA_LSDB(area
, type
), adv_router
);
6147 static void show_ip_ospf_database_summary(struct vty
*vty
, struct ospf
*ospf
,
6150 struct ospf_lsa
*lsa
;
6151 struct route_node
*rn
;
6152 struct ospf_area
*area
;
6153 struct listnode
*node
;
6156 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6157 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6159 case OSPF_AS_EXTERNAL_LSA
:
6160 case OSPF_OPAQUE_AS_LSA
:
6165 if (ospf_lsdb_count_self(area
->lsdb
, type
) > 0
6167 && ospf_lsdb_count(area
->lsdb
, type
) > 0)) {
6168 vty_out(vty
, " %s (Area %s)\n\n",
6169 show_database_desc
[type
],
6170 ospf_area_desc_string(area
));
6171 vty_out(vty
, "%s\n",
6172 show_database_header
[type
]);
6174 LSDB_LOOP (AREA_LSDB(area
, type
), rn
, lsa
)
6175 show_lsa_summary(vty
, lsa
, self
);
6182 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6184 case OSPF_AS_EXTERNAL_LSA
:
6185 case OSPF_OPAQUE_AS_LSA
:
6190 if (ospf_lsdb_count_self(ospf
->lsdb
, type
)
6191 || (!self
&& ospf_lsdb_count(ospf
->lsdb
, type
))) {
6192 vty_out(vty
, " %s\n\n",
6193 show_database_desc
[type
]);
6194 vty_out(vty
, "%s\n", show_database_header
[type
]);
6196 LSDB_LOOP (AS_LSDB(ospf
, type
), rn
, lsa
)
6197 show_lsa_summary(vty
, lsa
, self
);
6206 static void show_ip_ospf_database_maxage(struct vty
*vty
, struct ospf
*ospf
)
6208 struct route_node
*rn
;
6210 vty_out(vty
, "\n MaxAge Link States:\n\n");
6212 for (rn
= route_top(ospf
->maxage_lsa
); rn
; rn
= route_next(rn
)) {
6213 struct ospf_lsa
*lsa
;
6215 if ((lsa
= rn
->info
) != NULL
) {
6216 vty_out(vty
, "Link type: %d\n", lsa
->data
->type
);
6217 vty_out(vty
, "Link State ID: %s\n",
6218 inet_ntoa(lsa
->data
->id
));
6219 vty_out(vty
, "Advertising Router: %s\n",
6220 inet_ntoa(lsa
->data
->adv_router
));
6221 vty_out(vty
, "LSA lock count: %d\n", lsa
->lock
);
6227 #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
6228 #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
6230 #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
6231 #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
6232 #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
6233 #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
6235 #define OSPF_LSA_TYPES_DESC \
6236 "ASBR summary link states\n" \
6237 "External link states\n" \
6238 "Network link states\n" \
6239 "Router link states\n" \
6240 "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \
6241 OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
6242 OSPF_LSA_TYPE_OPAQUE_AS_DESC
6244 static int show_ip_ospf_database_common(struct vty
*vty
, struct ospf
*ospf
,
6245 int arg_base
, int argc
,
6246 struct cmd_token
**argv
,
6251 struct in_addr id
, adv_router
;
6254 vty_out(vty
, "\nOSPF Instance: %d\n", ospf
->instance
);
6256 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
6258 vty_out(vty
, "\n OSPF Router with ID (%s)\n\n",
6259 inet_ntoa(ospf
->router_id
));
6262 if (argc
== arg_base
+ 4) {
6263 show_ip_ospf_database_summary(vty
, ospf
, 0);
6267 /* Set database type to show. */
6268 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
6269 type
= OSPF_ROUTER_LSA
;
6270 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
6271 type
= OSPF_NETWORK_LSA
;
6272 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
6273 type
= OSPF_AS_NSSA_LSA
;
6274 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "su", 2) == 0)
6275 type
= OSPF_SUMMARY_LSA
;
6276 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
6277 type
= OSPF_ASBR_SUMMARY_LSA
;
6278 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
6279 type
= OSPF_AS_EXTERNAL_LSA
;
6280 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "se", 2) == 0) {
6281 show_ip_ospf_database_summary(vty
, ospf
, 1);
6283 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "m", 1) == 0) {
6284 show_ip_ospf_database_maxage(vty
, ospf
);
6286 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
6287 type
= OSPF_OPAQUE_LINK_LSA
;
6288 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
6289 type
= OSPF_OPAQUE_AREA_LSA
;
6290 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
6291 type
= OSPF_OPAQUE_AS_LSA
;
6295 /* `show ip ospf database LSA'. */
6296 if (argc
== arg_base
+ 5)
6297 show_lsa_detail(vty
, ospf
, type
, NULL
, NULL
);
6298 else if (argc
>= arg_base
+ 6) {
6299 ret
= inet_aton(argv
[arg_base
+ 5]->arg
, &id
);
6303 /* `show ip ospf database LSA ID'. */
6304 if (argc
== arg_base
+ 6)
6305 show_lsa_detail(vty
, ospf
, type
, &id
, NULL
);
6306 /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */
6307 else if (argc
== arg_base
+ 7) {
6308 if (strncmp(argv
[arg_base
+ 6]->text
, "s", 1) == 0)
6309 adv_router
= ospf
->router_id
;
6311 ret
= inet_aton(argv
[arg_base
+ 7]->arg
,
6316 show_lsa_detail(vty
, ospf
, type
, &id
, &adv_router
);
6323 DEFUN (show_ip_ospf_database_max
,
6324 show_ip_ospf_database_max_cmd
,
6325 "show ip ospf [vrf <NAME|all>] database <max-age|self-originate>",
6328 "OSPF information\n"
6331 "Database summary\n"
6332 "LSAs in MaxAge list\n"
6333 "Self-originated link states\n")
6335 struct ospf
*ospf
= NULL
;
6336 struct listnode
*node
= NULL
;
6337 char *vrf_name
= NULL
;
6338 bool all_vrf
= FALSE
;
6339 int ret
= CMD_SUCCESS
;
6342 uint8_t use_vrf
= 0;
6344 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
6347 bool ospf_output
= FALSE
;
6352 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6353 if (!ospf
->oi_running
)
6356 ret
= show_ip_ospf_database_common(
6357 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
,
6362 vty_out(vty
, "%% OSPF instance not found\n");
6364 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6365 if (ospf
== NULL
|| !ospf
->oi_running
) {
6366 vty_out(vty
, "%% OSPF instance not found\n");
6369 ret
= (show_ip_ospf_database_common(
6370 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
,
6374 /* Display default ospf (instance 0) info */
6375 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6376 if (ospf
== NULL
|| !ospf
->oi_running
) {
6377 vty_out(vty
, "%% OSPF instance not found\n");
6381 ret
= show_ip_ospf_database_common(vty
, ospf
, 0, argc
, argv
,
6388 DEFUN (show_ip_ospf_instance_database
,
6389 show_ip_ospf_instance_database_cmd
,
6390 "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>]]]",
6393 "OSPF information\n"
6396 "Database summary\n"
6398 "Link State ID (as an IP address)\n"
6399 "Self-originated link states\n"
6400 "Advertising Router link states\n"
6401 "Advertising Router (as an IP address)\n")
6404 unsigned short instance
= 0;
6405 struct listnode
*node
= NULL
;
6406 char *vrf_name
= NULL
;
6407 bool all_vrf
= FALSE
;
6408 int ret
= CMD_SUCCESS
;
6411 uint8_t use_vrf
= 0;
6413 if (argv_find(argv
, argc
, "(1-65535)", &idx
)) {
6414 instance
= strtoul(argv
[idx
]->arg
, NULL
, 10);
6415 ospf
= ospf_lookup_instance(instance
);
6417 return CMD_NOT_MY_INSTANCE
;
6418 if (!ospf
->oi_running
)
6421 return (show_ip_ospf_database_common(vty
, ospf
, idx
? 1 : 0,
6422 argc
, argv
, use_vrf
));
6423 } else if (argv_find(argv
, argc
, "vrf", &idx
)) {
6424 vrf_name
= argv
[++idx
]->arg
;
6425 all_vrf
= strmatch(vrf_name
, "all");
6431 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6432 if (!ospf
->oi_running
)
6434 ret
= (show_ip_ospf_database_common(
6435 vty
, ospf
, idx
? 2 : 0, argc
, argv
,
6439 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6440 if ((ospf
== NULL
) || !ospf
->oi_running
) {
6441 vty_out(vty
, "%% OSPF instance not found\n");
6445 ret
= (show_ip_ospf_database_common(
6446 vty
, ospf
, idx
? 2 : 0, argc
, argv
, use_vrf
));
6449 /* Display default ospf (instance 0) info */
6450 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6451 if (ospf
== NULL
|| !ospf
->oi_running
) {
6452 vty_out(vty
, "%% OSPF instance not found\n");
6456 ret
= (show_ip_ospf_database_common(vty
, ospf
, 0, argc
, argv
,
6463 DEFUN (show_ip_ospf_instance_database_max
,
6464 show_ip_ospf_instance_database_max_cmd
,
6465 "show ip ospf (1-65535) database <max-age|self-originate>",
6468 "OSPF information\n"
6470 "Database summary\n"
6471 "LSAs in MaxAge list\n"
6472 "Self-originated link states\n")
6476 unsigned short instance
= 0;
6478 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
6480 ospf
= ospf_lookup_instance(instance
);
6482 return CMD_NOT_MY_INSTANCE
;
6484 if (!ospf
->oi_running
) {
6485 vty_out(vty
, "%% OSPF instance not found\n");
6489 return show_ip_ospf_database_common(vty
, ospf
, 1, argc
, argv
, 0);
6493 static int show_ip_ospf_database_type_adv_router_common(struct vty
*vty
,
6495 int arg_base
, int argc
,
6496 struct cmd_token
**argv
,
6501 struct in_addr adv_router
;
6504 vty_out(vty
, "\nOSPF Instance: %d\n", ospf
->instance
);
6506 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
6508 vty_out(vty
, "\n OSPF Router with ID (%s)\n\n",
6509 inet_ntoa(ospf
->router_id
));
6511 /* Set database type to show. */
6512 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
6513 type
= OSPF_ROUTER_LSA
;
6514 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
6515 type
= OSPF_NETWORK_LSA
;
6516 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
6517 type
= OSPF_AS_NSSA_LSA
;
6518 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "s", 1) == 0)
6519 type
= OSPF_SUMMARY_LSA
;
6520 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
6521 type
= OSPF_ASBR_SUMMARY_LSA
;
6522 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
6523 type
= OSPF_AS_EXTERNAL_LSA
;
6524 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
6525 type
= OSPF_OPAQUE_LINK_LSA
;
6526 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
6527 type
= OSPF_OPAQUE_AREA_LSA
;
6528 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
6529 type
= OSPF_OPAQUE_AS_LSA
;
6533 /* `show ip ospf database LSA adv-router ADV_ROUTER'. */
6534 if (strncmp(argv
[arg_base
+ 5]->text
, "s", 1) == 0)
6535 adv_router
= ospf
->router_id
;
6537 ret
= inet_aton(argv
[arg_base
+ 6]->arg
, &adv_router
);
6542 show_lsa_detail_adv_router(vty
, ospf
, type
, &adv_router
);
6547 DEFUN (show_ip_ospf_instance_database_type_adv_router
,
6548 show_ip_ospf_instance_database_type_adv_router_cmd
,
6549 "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>",
6552 "OSPF information\n"
6555 "Database summary\n"
6557 "Advertising Router link states\n"
6558 "Advertising Router (as an IP address)\n"
6559 "Self-originated link states\n")
6561 struct ospf
*ospf
= NULL
;
6562 unsigned short instance
= 0;
6563 struct listnode
*node
= NULL
;
6564 char *vrf_name
= NULL
;
6565 bool all_vrf
= FALSE
;
6566 int ret
= CMD_SUCCESS
;
6568 int idx
= 0, idx_vrf
= 0;
6569 uint8_t use_vrf
= 0;
6571 if (argv_find(argv
, argc
, "(1-65535)", &idx
)) {
6572 instance
= strtoul(argv
[idx
]->arg
, NULL
, 10);
6573 ospf
= ospf_lookup_instance(instance
);
6575 return CMD_NOT_MY_INSTANCE
;
6576 if (!ospf
->oi_running
) {
6577 vty_out(vty
, "%% OSPF instance not found\n");
6581 return (show_ip_ospf_database_type_adv_router_common(
6582 vty
, ospf
, idx
? 1 : 0, argc
, argv
, use_vrf
));
6585 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
6588 bool ospf_output
= FALSE
;
6593 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6594 if (!ospf
->oi_running
)
6597 ret
= show_ip_ospf_database_type_adv_router_common(
6598 vty
, ospf
, idx
? 1 : 0, argc
, argv
,
6602 vty_out(vty
, "%% OSPF instance not found\n");
6604 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6605 if ((ospf
== NULL
) || !ospf
->oi_running
) {
6606 vty_out(vty
, "%% OSPF instance not found\n");
6610 ret
= show_ip_ospf_database_type_adv_router_common(
6611 vty
, ospf
, idx
? 1 : 0, argc
, argv
, use_vrf
);
6614 /* Display default ospf (instance 0) info */
6615 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6616 if (ospf
== NULL
|| !ospf
->oi_running
) {
6617 vty_out(vty
, "%% OSPF instance not found\n");
6621 ret
= show_ip_ospf_database_type_adv_router_common(
6622 vty
, ospf
, idx
? 1 : 0, argc
, argv
, use_vrf
);
6625 /*return (show_ip_ospf_database_type_adv_router_common(
6626 vty, ospf, idx ? 1 : 0, argc, argv));*/
6629 DEFUN (ip_ospf_authentication_args
,
6630 ip_ospf_authentication_args_addr_cmd
,
6631 "ip ospf authentication <null|message-digest> [A.B.C.D]",
6633 "OSPF interface commands\n"
6634 "Enable authentication on this interface\n"
6635 "Use null authentication\n"
6636 "Use message-digest authentication\n"
6637 "Address of interface\n")
6639 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6640 int idx_encryption
= 3;
6642 struct in_addr addr
;
6644 struct ospf_if_params
*params
;
6646 params
= IF_DEF_PARAMS(ifp
);
6649 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6652 "Please specify interface address by A.B.C.D\n");
6653 return CMD_WARNING_CONFIG_FAILED
;
6656 params
= ospf_get_if_params(ifp
, addr
);
6657 ospf_if_update_params(ifp
, addr
);
6660 /* Handle null authentication */
6661 if (argv
[idx_encryption
]->arg
[0] == 'n') {
6662 SET_IF_PARAM(params
, auth_type
);
6663 params
->auth_type
= OSPF_AUTH_NULL
;
6667 /* Handle message-digest authentication */
6668 if (argv
[idx_encryption
]->arg
[0] == 'm') {
6669 SET_IF_PARAM(params
, auth_type
);
6670 params
->auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
6674 vty_out(vty
, "You shouldn't get here!\n");
6675 return CMD_WARNING_CONFIG_FAILED
;
6678 DEFUN (ip_ospf_authentication
,
6679 ip_ospf_authentication_addr_cmd
,
6680 "ip ospf authentication [A.B.C.D]",
6682 "OSPF interface commands\n"
6683 "Enable authentication on this interface\n"
6684 "Address of interface\n")
6686 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6688 struct in_addr addr
;
6690 struct ospf_if_params
*params
;
6692 params
= IF_DEF_PARAMS(ifp
);
6695 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6698 "Please specify interface address by A.B.C.D\n");
6699 return CMD_WARNING_CONFIG_FAILED
;
6702 params
= ospf_get_if_params(ifp
, addr
);
6703 ospf_if_update_params(ifp
, addr
);
6706 SET_IF_PARAM(params
, auth_type
);
6707 params
->auth_type
= OSPF_AUTH_SIMPLE
;
6712 DEFUN (no_ip_ospf_authentication_args
,
6713 no_ip_ospf_authentication_args_addr_cmd
,
6714 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
6717 "OSPF interface commands\n"
6718 "Enable authentication on this interface\n"
6719 "Use null authentication\n"
6720 "Use message-digest authentication\n"
6721 "Address of interface\n")
6723 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6724 int idx_encryption
= 4;
6726 struct in_addr addr
;
6728 struct ospf_if_params
*params
;
6729 struct route_node
*rn
;
6732 params
= IF_DEF_PARAMS(ifp
);
6735 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6738 "Please specify interface address by A.B.C.D\n");
6739 return CMD_WARNING_CONFIG_FAILED
;
6742 params
= ospf_lookup_if_params(ifp
, addr
);
6743 if (params
== NULL
) {
6744 vty_out(vty
, "Ip Address specified is unknown\n");
6745 return CMD_WARNING_CONFIG_FAILED
;
6747 params
->auth_type
= OSPF_AUTH_NOTSET
;
6748 UNSET_IF_PARAM(params
, auth_type
);
6749 if (params
!= IF_DEF_PARAMS(ifp
)) {
6750 ospf_free_if_params(ifp
, addr
);
6751 ospf_if_update_params(ifp
, addr
);
6754 if (argv
[idx_encryption
]->arg
[0] == 'n') {
6755 auth_type
= OSPF_AUTH_NULL
;
6756 } else if (argv
[idx_encryption
]->arg
[0] == 'm') {
6757 auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
6759 vty_out(vty
, "Unexpected input encountered\n");
6760 return CMD_WARNING_CONFIG_FAILED
;
6763 * Here we have a case where the user has entered
6764 * 'no ip ospf authentication (null | message_digest )'
6765 * we need to find if we have any ip addresses underneath it
6767 * correspond to the associated type.
6769 if (params
->auth_type
== auth_type
) {
6770 params
->auth_type
= OSPF_AUTH_NOTSET
;
6771 UNSET_IF_PARAM(params
, auth_type
);
6774 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
6775 rn
= route_next(rn
)) {
6776 if ((params
= rn
->info
)) {
6777 if (params
->auth_type
== auth_type
) {
6778 params
->auth_type
= OSPF_AUTH_NOTSET
;
6779 UNSET_IF_PARAM(params
, auth_type
);
6780 if (params
!= IF_DEF_PARAMS(ifp
)) {
6781 ospf_free_if_params(
6782 ifp
, rn
->p
.u
.prefix4
);
6783 ospf_if_update_params(
6784 ifp
, rn
->p
.u
.prefix4
);
6794 DEFUN (no_ip_ospf_authentication
,
6795 no_ip_ospf_authentication_addr_cmd
,
6796 "no ip ospf authentication [A.B.C.D]",
6799 "OSPF interface commands\n"
6800 "Enable authentication on this interface\n"
6801 "Address of interface\n")
6803 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6805 struct in_addr addr
;
6807 struct ospf_if_params
*params
;
6808 struct route_node
*rn
;
6810 params
= IF_DEF_PARAMS(ifp
);
6813 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6816 "Please specify interface address by A.B.C.D\n");
6817 return CMD_WARNING_CONFIG_FAILED
;
6820 params
= ospf_lookup_if_params(ifp
, addr
);
6821 if (params
== NULL
) {
6822 vty_out(vty
, "Ip Address specified is unknown\n");
6823 return CMD_WARNING_CONFIG_FAILED
;
6826 params
->auth_type
= OSPF_AUTH_NOTSET
;
6827 UNSET_IF_PARAM(params
, auth_type
);
6828 if (params
!= IF_DEF_PARAMS(ifp
)) {
6829 ospf_free_if_params(ifp
, addr
);
6830 ospf_if_update_params(ifp
, addr
);
6834 * When a user enters 'no ip ospf authentication'
6835 * We should remove all authentication types from
6838 if ((params
->auth_type
== OSPF_AUTH_NULL
)
6839 || (params
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
6840 || (params
->auth_type
== OSPF_AUTH_SIMPLE
)) {
6841 params
->auth_type
= OSPF_AUTH_NOTSET
;
6842 UNSET_IF_PARAM(params
, auth_type
);
6845 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
6846 rn
= route_next(rn
)) {
6847 if ((params
= rn
->info
)) {
6849 if ((params
->auth_type
== OSPF_AUTH_NULL
)
6850 || (params
->auth_type
6851 == OSPF_AUTH_CRYPTOGRAPHIC
)
6852 || (params
->auth_type
6853 == OSPF_AUTH_SIMPLE
)) {
6854 params
->auth_type
= OSPF_AUTH_NOTSET
;
6855 UNSET_IF_PARAM(params
, auth_type
);
6856 if (params
!= IF_DEF_PARAMS(ifp
)) {
6857 ospf_free_if_params(
6858 ifp
, rn
->p
.u
.prefix4
);
6859 ospf_if_update_params(
6860 ifp
, rn
->p
.u
.prefix4
);
6871 DEFUN (ip_ospf_authentication_key
,
6872 ip_ospf_authentication_key_addr_cmd
,
6873 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
6875 "OSPF interface commands\n"
6876 "Authentication password (key)\n"
6877 "The OSPF password (key)\n"
6878 "Address of interface\n")
6880 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6882 struct in_addr addr
;
6883 struct ospf_if_params
*params
;
6885 params
= IF_DEF_PARAMS(ifp
);
6887 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6888 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6890 "Please specify interface address by A.B.C.D\n");
6891 return CMD_WARNING_CONFIG_FAILED
;
6894 params
= ospf_get_if_params(ifp
, addr
);
6895 ospf_if_update_params(ifp
, addr
);
6898 memset(params
->auth_simple
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
6899 strncpy((char *)params
->auth_simple
, argv
[3]->arg
,
6900 OSPF_AUTH_SIMPLE_SIZE
);
6901 SET_IF_PARAM(params
, auth_simple
);
6906 DEFUN_HIDDEN (ospf_authentication_key
,
6907 ospf_authentication_key_cmd
,
6908 "ospf authentication-key AUTH_KEY [A.B.C.D]",
6909 "OSPF interface commands\n"
6910 VLINK_HELPSTR_AUTH_SIMPLE
6911 "Address of interface\n")
6913 return ip_ospf_authentication_key(self
, vty
, argc
, argv
);
6916 DEFUN (no_ip_ospf_authentication_key
,
6917 no_ip_ospf_authentication_key_authkey_addr_cmd
,
6918 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
6921 "OSPF interface commands\n"
6922 VLINK_HELPSTR_AUTH_SIMPLE
6923 "Address of interface\n")
6925 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6927 struct in_addr addr
;
6928 struct ospf_if_params
*params
;
6929 params
= IF_DEF_PARAMS(ifp
);
6931 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6932 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6934 "Please specify interface address by A.B.C.D\n");
6935 return CMD_WARNING_CONFIG_FAILED
;
6938 params
= ospf_lookup_if_params(ifp
, addr
);
6943 memset(params
->auth_simple
, 0, OSPF_AUTH_SIMPLE_SIZE
);
6944 UNSET_IF_PARAM(params
, auth_simple
);
6946 if (params
!= IF_DEF_PARAMS(ifp
)) {
6947 ospf_free_if_params(ifp
, addr
);
6948 ospf_if_update_params(ifp
, addr
);
6954 DEFUN_HIDDEN (no_ospf_authentication_key
,
6955 no_ospf_authentication_key_authkey_addr_cmd
,
6956 "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
6958 "OSPF interface commands\n"
6959 VLINK_HELPSTR_AUTH_SIMPLE
6960 "Address of interface\n")
6962 return no_ip_ospf_authentication_key(self
, vty
, argc
, argv
);
6965 DEFUN (ip_ospf_message_digest_key
,
6966 ip_ospf_message_digest_key_cmd
,
6967 "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
6969 "OSPF interface commands\n"
6970 "Message digest authentication password (key)\n"
6972 "Use MD5 algorithm\n"
6973 "The OSPF password (key)\n"
6974 "Address of interface\n")
6976 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6977 struct crypt_key
*ck
;
6979 struct in_addr addr
;
6980 struct ospf_if_params
*params
;
6982 params
= IF_DEF_PARAMS(ifp
);
6985 argv_find(argv
, argc
, "(1-255)", &idx
);
6986 char *keyid
= argv
[idx
]->arg
;
6987 argv_find(argv
, argc
, "KEY", &idx
);
6988 char *cryptkey
= argv
[idx
]->arg
;
6990 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6991 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6993 "Please specify interface address by A.B.C.D\n");
6994 return CMD_WARNING_CONFIG_FAILED
;
6997 params
= ospf_get_if_params(ifp
, addr
);
6998 ospf_if_update_params(ifp
, addr
);
7001 key_id
= strtol(keyid
, NULL
, 10);
7002 if (ospf_crypt_key_lookup(params
->auth_crypt
, key_id
) != NULL
) {
7003 vty_out(vty
, "OSPF: Key %d already exists\n", key_id
);
7007 ck
= ospf_crypt_key_new();
7008 ck
->key_id
= (uint8_t)key_id
;
7009 memset(ck
->auth_key
, 0, OSPF_AUTH_MD5_SIZE
+ 1);
7010 strncpy((char *)ck
->auth_key
, cryptkey
, OSPF_AUTH_MD5_SIZE
);
7012 ospf_crypt_key_add(params
->auth_crypt
, ck
);
7013 SET_IF_PARAM(params
, auth_crypt
);
7018 DEFUN_HIDDEN (ospf_message_digest_key
,
7019 ospf_message_digest_key_cmd
,
7020 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7021 "OSPF interface commands\n"
7022 "Message digest authentication password (key)\n"
7024 "Use MD5 algorithm\n"
7025 "The OSPF password (key)\n"
7026 "Address of interface\n")
7028 return ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7031 DEFUN (no_ip_ospf_message_digest_key
,
7032 no_ip_ospf_message_digest_key_cmd
,
7033 "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7036 "OSPF interface commands\n"
7037 "Message digest authentication password (key)\n"
7039 "Use MD5 algorithm\n"
7040 "The OSPF password (key)\n"
7041 "Address of interface\n")
7043 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7045 struct crypt_key
*ck
;
7047 struct in_addr addr
;
7048 struct ospf_if_params
*params
;
7049 params
= IF_DEF_PARAMS(ifp
);
7051 argv_find(argv
, argc
, "(1-255)", &idx
);
7052 char *keyid
= argv
[idx
]->arg
;
7054 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7055 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7057 "Please specify interface address by A.B.C.D\n");
7058 return CMD_WARNING_CONFIG_FAILED
;
7061 params
= ospf_lookup_if_params(ifp
, addr
);
7066 key_id
= strtol(keyid
, NULL
, 10);
7067 ck
= ospf_crypt_key_lookup(params
->auth_crypt
, key_id
);
7069 vty_out(vty
, "OSPF: Key %d does not exist\n", key_id
);
7070 return CMD_WARNING_CONFIG_FAILED
;
7073 ospf_crypt_key_delete(params
->auth_crypt
, key_id
);
7075 if (params
!= IF_DEF_PARAMS(ifp
)) {
7076 ospf_free_if_params(ifp
, addr
);
7077 ospf_if_update_params(ifp
, addr
);
7083 DEFUN_HIDDEN (no_ospf_message_digest_key
,
7084 no_ospf_message_digest_key_cmd
,
7085 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7087 "OSPF interface commands\n"
7088 "Message digest authentication password (key)\n"
7090 "Use MD5 algorithm\n"
7091 "The OSPF password (key)\n"
7092 "Address of interface\n")
7094 return no_ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7097 DEFUN (ip_ospf_cost
,
7099 "ip ospf cost (1-65535) [A.B.C.D]",
7101 "OSPF interface commands\n"
7104 "Address of interface\n")
7106 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7108 uint32_t cost
= OSPF_OUTPUT_COST_DEFAULT
;
7109 struct in_addr addr
;
7110 struct ospf_if_params
*params
;
7111 params
= IF_DEF_PARAMS(ifp
);
7114 char *coststr
= NULL
, *ifaddr
= NULL
;
7116 argv_find(argv
, argc
, "(1-65535)", &idx
);
7117 coststr
= argv
[idx
]->arg
;
7118 cost
= strtol(coststr
, NULL
, 10);
7120 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7122 if (!inet_aton(ifaddr
, &addr
)) {
7124 "Please specify interface address by A.B.C.D\n");
7125 return CMD_WARNING_CONFIG_FAILED
;
7128 params
= ospf_get_if_params(ifp
, addr
);
7129 ospf_if_update_params(ifp
, addr
);
7132 SET_IF_PARAM(params
, output_cost_cmd
);
7133 params
->output_cost_cmd
= cost
;
7135 ospf_if_recalculate_output_cost(ifp
);
7140 DEFUN_HIDDEN (ospf_cost
,
7142 "ospf cost (1-65535) [A.B.C.D]",
7143 "OSPF interface commands\n"
7146 "Address of interface\n")
7148 return ip_ospf_cost(self
, vty
, argc
, argv
);
7151 DEFUN (no_ip_ospf_cost
,
7152 no_ip_ospf_cost_cmd
,
7153 "no ip ospf cost [(1-65535)] [A.B.C.D]",
7156 "OSPF interface commands\n"
7159 "Address of interface\n")
7161 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7163 struct in_addr addr
;
7164 struct ospf_if_params
*params
;
7166 params
= IF_DEF_PARAMS(ifp
);
7169 char *ifaddr
= NULL
;
7170 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7172 /* According to the semantics we are mimicking "no ip ospf cost N" is
7173 * always treated as "no ip ospf cost" regardless of the actual value
7174 * of N already configured for the interface. Thus ignore cost. */
7177 if (!inet_aton(ifaddr
, &addr
)) {
7179 "Please specify interface address by A.B.C.D\n");
7180 return CMD_WARNING_CONFIG_FAILED
;
7183 params
= ospf_lookup_if_params(ifp
, addr
);
7188 UNSET_IF_PARAM(params
, output_cost_cmd
);
7190 if (params
!= IF_DEF_PARAMS(ifp
)) {
7191 ospf_free_if_params(ifp
, addr
);
7192 ospf_if_update_params(ifp
, addr
);
7195 ospf_if_recalculate_output_cost(ifp
);
7200 DEFUN_HIDDEN (no_ospf_cost
,
7202 "no ospf cost [(1-65535)] [A.B.C.D]",
7204 "OSPF interface commands\n"
7207 "Address of interface\n")
7209 return no_ip_ospf_cost(self
, vty
, argc
, argv
);
7212 static void ospf_nbr_timer_update(struct ospf_interface
*oi
)
7214 struct route_node
*rn
;
7215 struct ospf_neighbor
*nbr
;
7217 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
7218 if ((nbr
= rn
->info
)) {
7219 nbr
->v_inactivity
= OSPF_IF_PARAM(oi
, v_wait
);
7220 nbr
->v_db_desc
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7221 nbr
->v_ls_req
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7222 nbr
->v_ls_upd
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7226 static int ospf_vty_dead_interval_set(struct vty
*vty
, const char *interval_str
,
7227 const char *nbr_str
,
7228 const char *fast_hello_str
)
7230 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7233 struct in_addr addr
;
7235 struct ospf_if_params
*params
;
7236 struct ospf_interface
*oi
;
7237 struct route_node
*rn
;
7239 params
= IF_DEF_PARAMS(ifp
);
7242 ret
= inet_aton(nbr_str
, &addr
);
7245 "Please specify interface address by A.B.C.D\n");
7246 return CMD_WARNING_CONFIG_FAILED
;
7249 params
= ospf_get_if_params(ifp
, addr
);
7250 ospf_if_update_params(ifp
, addr
);
7254 seconds
= strtoul(interval_str
, NULL
, 10);
7256 /* reset fast_hello too, just to be sure */
7257 UNSET_IF_PARAM(params
, fast_hello
);
7258 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
7259 } else if (fast_hello_str
) {
7260 hellomult
= strtoul(fast_hello_str
, NULL
, 10);
7261 /* 1s dead-interval with sub-second hellos desired */
7262 seconds
= OSPF_ROUTER_DEAD_INTERVAL_MINIMAL
;
7263 SET_IF_PARAM(params
, fast_hello
);
7264 params
->fast_hello
= hellomult
;
7267 "Please specify dead-interval or hello-multiplier\n");
7268 return CMD_WARNING_CONFIG_FAILED
;
7271 SET_IF_PARAM(params
, v_wait
);
7272 params
->v_wait
= seconds
;
7274 /* Update timer values in neighbor structure. */
7276 struct ospf
*ospf
= NULL
;
7278 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7280 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
7282 ospf_nbr_timer_update(oi
);
7285 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
7286 if ((oi
= rn
->info
))
7287 ospf_nbr_timer_update(oi
);
7293 DEFUN (ip_ospf_dead_interval
,
7294 ip_ospf_dead_interval_cmd
,
7295 "ip ospf dead-interval (1-65535) [A.B.C.D]",
7297 "OSPF interface commands\n"
7298 "Interval time after which a neighbor is declared down\n"
7300 "Address of interface\n")
7303 char *interval
= argv_find(argv
, argc
, "(1-65535)", &idx
)
7307 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7308 return ospf_vty_dead_interval_set(vty
, interval
, ifaddr
, NULL
);
7312 DEFUN_HIDDEN (ospf_dead_interval
,
7313 ospf_dead_interval_cmd
,
7314 "ospf dead-interval (1-65535) [A.B.C.D]",
7315 "OSPF interface commands\n"
7316 "Interval time after which a neighbor is declared down\n"
7318 "Address of interface\n")
7320 return ip_ospf_dead_interval(self
, vty
, argc
, argv
);
7323 DEFUN (ip_ospf_dead_interval_minimal
,
7324 ip_ospf_dead_interval_minimal_addr_cmd
,
7325 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
7327 "OSPF interface commands\n"
7328 "Interval time after which a neighbor is declared down\n"
7329 "Minimal 1s dead-interval with fast sub-second hellos\n"
7330 "Hello multiplier factor\n"
7331 "Number of Hellos to send each second\n"
7332 "Address of interface\n")
7337 return ospf_vty_dead_interval_set(
7338 vty
, NULL
, argv
[idx_ipv4
]->arg
, argv
[idx_number
]->arg
);
7340 return ospf_vty_dead_interval_set(vty
, NULL
, NULL
,
7341 argv
[idx_number
]->arg
);
7344 DEFUN (no_ip_ospf_dead_interval
,
7345 no_ip_ospf_dead_interval_cmd
,
7346 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
7349 "OSPF interface commands\n"
7350 "Interval time after which a neighbor is declared down\n"
7352 "Minimal 1s dead-interval with fast sub-second hellos\n"
7353 "Hello multiplier factor\n"
7354 "Number of Hellos to send each second\n"
7355 "Address of interface\n")
7357 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7358 int idx_ipv4
= argc
- 1;
7359 struct in_addr addr
= {.s_addr
= 0L};
7361 struct ospf_if_params
*params
;
7362 struct ospf_interface
*oi
;
7363 struct route_node
*rn
;
7365 params
= IF_DEF_PARAMS(ifp
);
7367 if (argv
[idx_ipv4
]->type
== IPV4_TKN
) {
7368 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7371 "Please specify interface address by A.B.C.D\n");
7372 return CMD_WARNING_CONFIG_FAILED
;
7375 params
= ospf_lookup_if_params(ifp
, addr
);
7380 UNSET_IF_PARAM(params
, v_wait
);
7381 params
->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
7383 UNSET_IF_PARAM(params
, fast_hello
);
7384 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
7386 if (params
!= IF_DEF_PARAMS(ifp
)) {
7387 ospf_free_if_params(ifp
, addr
);
7388 ospf_if_update_params(ifp
, addr
);
7391 /* Update timer values in neighbor structure. */
7393 struct ospf
*ospf
= NULL
;
7395 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7397 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
7399 ospf_nbr_timer_update(oi
);
7402 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
7403 if ((oi
= rn
->info
))
7404 ospf_nbr_timer_update(oi
);
7410 DEFUN_HIDDEN (no_ospf_dead_interval
,
7411 no_ospf_dead_interval_cmd
,
7412 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
7414 "OSPF interface commands\n"
7415 "Interval time after which a neighbor is declared down\n"
7417 "Minimal 1s dead-interval with fast sub-second hellos\n"
7418 "Hello multiplier factor\n"
7419 "Number of Hellos to send each second\n"
7420 "Address of interface\n")
7422 return no_ip_ospf_dead_interval(self
, vty
, argc
, argv
);
7425 DEFUN (ip_ospf_hello_interval
,
7426 ip_ospf_hello_interval_cmd
,
7427 "ip ospf hello-interval (1-65535) [A.B.C.D]",
7429 "OSPF interface commands\n"
7430 "Time between HELLO packets\n"
7432 "Address of interface\n")
7434 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7436 struct in_addr addr
;
7437 struct ospf_if_params
*params
;
7438 params
= IF_DEF_PARAMS(ifp
);
7439 uint32_t seconds
= 0;
7441 argv_find(argv
, argc
, "(1-65535)", &idx
);
7442 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7444 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7445 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7447 "Please specify interface address by A.B.C.D\n");
7448 return CMD_WARNING_CONFIG_FAILED
;
7451 params
= ospf_get_if_params(ifp
, addr
);
7452 ospf_if_update_params(ifp
, addr
);
7455 SET_IF_PARAM(params
, v_hello
);
7456 params
->v_hello
= seconds
;
7461 DEFUN_HIDDEN (ospf_hello_interval
,
7462 ospf_hello_interval_cmd
,
7463 "ospf hello-interval (1-65535) [A.B.C.D]",
7464 "OSPF interface commands\n"
7465 "Time between HELLO packets\n"
7467 "Address of interface\n")
7469 return ip_ospf_hello_interval(self
, vty
, argc
, argv
);
7472 DEFUN (no_ip_ospf_hello_interval
,
7473 no_ip_ospf_hello_interval_cmd
,
7474 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
7477 "OSPF interface commands\n"
7478 "Time between HELLO packets\n" // ignored
7480 "Address of interface\n")
7482 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7484 struct in_addr addr
;
7485 struct ospf_if_params
*params
;
7487 params
= IF_DEF_PARAMS(ifp
);
7489 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7490 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7492 "Please specify interface address by A.B.C.D\n");
7493 return CMD_WARNING_CONFIG_FAILED
;
7496 params
= ospf_lookup_if_params(ifp
, addr
);
7501 UNSET_IF_PARAM(params
, v_hello
);
7502 params
->v_hello
= OSPF_HELLO_INTERVAL_DEFAULT
;
7504 if (params
!= IF_DEF_PARAMS(ifp
)) {
7505 ospf_free_if_params(ifp
, addr
);
7506 ospf_if_update_params(ifp
, addr
);
7512 DEFUN_HIDDEN (no_ospf_hello_interval
,
7513 no_ospf_hello_interval_cmd
,
7514 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
7516 "OSPF interface commands\n"
7517 "Time between HELLO packets\n" // ignored
7519 "Address of interface\n")
7521 return no_ip_ospf_hello_interval(self
, vty
, argc
, argv
);
7524 DEFUN (ip_ospf_network
,
7525 ip_ospf_network_cmd
,
7526 "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
7528 "OSPF interface commands\n"
7530 "Specify OSPF broadcast multi-access network\n"
7531 "Specify OSPF NBMA network\n"
7532 "Specify OSPF point-to-multipoint network\n"
7533 "Specify OSPF point-to-point network\n")
7535 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7537 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
7538 struct route_node
*rn
;
7540 if (old_type
== OSPF_IFTYPE_LOOPBACK
) {
7542 "This is a loopback interface. Can't set network type.\n");
7543 return CMD_WARNING_CONFIG_FAILED
;
7546 if (argv_find(argv
, argc
, "broadcast", &idx
))
7547 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_BROADCAST
;
7548 else if (argv_find(argv
, argc
, "non-broadcast", &idx
))
7549 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_NBMA
;
7550 else if (argv_find(argv
, argc
, "point-to-multipoint", &idx
))
7551 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOMULTIPOINT
;
7552 else if (argv_find(argv
, argc
, "point-to-point", &idx
))
7553 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOPOINT
;
7555 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
7558 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), type
);
7560 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7561 struct ospf_interface
*oi
= rn
->info
;
7566 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
7568 if (oi
->state
> ISM_Down
) {
7569 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
7570 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
7577 DEFUN_HIDDEN (ospf_network
,
7579 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
7580 "OSPF interface commands\n"
7582 "Specify OSPF broadcast multi-access network\n"
7583 "Specify OSPF NBMA network\n"
7584 "Specify OSPF point-to-multipoint network\n"
7585 "Specify OSPF point-to-point network\n")
7587 return ip_ospf_network(self
, vty
, argc
, argv
);
7590 DEFUN (no_ip_ospf_network
,
7591 no_ip_ospf_network_cmd
,
7592 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
7595 "OSPF interface commands\n"
7597 "Specify OSPF broadcast multi-access network\n"
7598 "Specify OSPF NBMA network\n"
7599 "Specify OSPF point-to-multipoint network\n"
7600 "Specify OSPF point-to-point network\n")
7602 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7603 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
7604 struct route_node
*rn
;
7606 IF_DEF_PARAMS(ifp
)->type
= ospf_default_iftype(ifp
);
7608 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
7611 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7612 struct ospf_interface
*oi
= rn
->info
;
7617 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
7619 if (oi
->state
> ISM_Down
) {
7620 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
7621 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
7628 DEFUN_HIDDEN (no_ospf_network
,
7629 no_ospf_network_cmd
,
7630 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
7632 "OSPF interface commands\n"
7634 "Specify OSPF broadcast multi-access network\n"
7635 "Specify OSPF NBMA network\n"
7636 "Specify OSPF point-to-multipoint network\n"
7637 "Specify OSPF point-to-point network\n")
7639 return no_ip_ospf_network(self
, vty
, argc
, argv
);
7642 DEFUN (ip_ospf_priority
,
7643 ip_ospf_priority_cmd
,
7644 "ip ospf priority (0-255) [A.B.C.D]",
7646 "OSPF interface commands\n"
7649 "Address of interface\n")
7651 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7654 struct route_node
*rn
;
7655 struct in_addr addr
;
7656 struct ospf_if_params
*params
;
7657 params
= IF_DEF_PARAMS(ifp
);
7659 argv_find(argv
, argc
, "(0-255)", &idx
);
7660 priority
= strtol(argv
[idx
]->arg
, NULL
, 10);
7662 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7663 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7665 "Please specify interface address by A.B.C.D\n");
7666 return CMD_WARNING_CONFIG_FAILED
;
7669 params
= ospf_get_if_params(ifp
, addr
);
7670 ospf_if_update_params(ifp
, addr
);
7673 SET_IF_PARAM(params
, priority
);
7674 params
->priority
= priority
;
7676 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7677 struct ospf_interface
*oi
= rn
->info
;
7682 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
7683 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
7684 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
7691 DEFUN_HIDDEN (ospf_priority
,
7693 "ospf priority (0-255) [A.B.C.D]",
7694 "OSPF interface commands\n"
7697 "Address of interface\n")
7699 return ip_ospf_priority(self
, vty
, argc
, argv
);
7702 DEFUN (no_ip_ospf_priority
,
7703 no_ip_ospf_priority_cmd
,
7704 "no ip ospf priority [(0-255) [A.B.C.D]]",
7707 "OSPF interface commands\n"
7708 "Router priority\n" // ignored
7710 "Address of interface\n")
7712 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7714 struct route_node
*rn
;
7715 struct in_addr addr
;
7716 struct ospf_if_params
*params
;
7718 params
= IF_DEF_PARAMS(ifp
);
7720 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7721 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7723 "Please specify interface address by A.B.C.D\n");
7724 return CMD_WARNING_CONFIG_FAILED
;
7727 params
= ospf_lookup_if_params(ifp
, addr
);
7732 UNSET_IF_PARAM(params
, priority
);
7733 params
->priority
= OSPF_ROUTER_PRIORITY_DEFAULT
;
7735 if (params
!= IF_DEF_PARAMS(ifp
)) {
7736 ospf_free_if_params(ifp
, addr
);
7737 ospf_if_update_params(ifp
, addr
);
7740 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7741 struct ospf_interface
*oi
= rn
->info
;
7746 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
7747 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
7748 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
7755 DEFUN_HIDDEN (no_ospf_priority
,
7756 no_ospf_priority_cmd
,
7757 "no ospf priority [(0-255) [A.B.C.D]]",
7759 "OSPF interface commands\n"
7762 "Address of interface\n")
7764 return no_ip_ospf_priority(self
, vty
, argc
, argv
);
7767 DEFUN (ip_ospf_retransmit_interval
,
7768 ip_ospf_retransmit_interval_addr_cmd
,
7769 "ip ospf retransmit-interval (3-65535) [A.B.C.D]",
7771 "OSPF interface commands\n"
7772 "Time between retransmitting lost link state advertisements\n"
7774 "Address of interface\n")
7776 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7779 struct in_addr addr
;
7780 struct ospf_if_params
*params
;
7781 params
= IF_DEF_PARAMS(ifp
);
7783 argv_find(argv
, argc
, "(3-65535)", &idx
);
7784 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7786 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7787 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7789 "Please specify interface address by A.B.C.D\n");
7790 return CMD_WARNING_CONFIG_FAILED
;
7793 params
= ospf_get_if_params(ifp
, addr
);
7794 ospf_if_update_params(ifp
, addr
);
7797 SET_IF_PARAM(params
, retransmit_interval
);
7798 params
->retransmit_interval
= seconds
;
7803 DEFUN_HIDDEN (ospf_retransmit_interval
,
7804 ospf_retransmit_interval_cmd
,
7805 "ospf retransmit-interval (3-65535) [A.B.C.D]",
7806 "OSPF interface commands\n"
7807 "Time between retransmitting lost link state advertisements\n"
7809 "Address of interface\n")
7811 return ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
7814 DEFUN (no_ip_ospf_retransmit_interval
,
7815 no_ip_ospf_retransmit_interval_addr_cmd
,
7816 "no ip ospf retransmit-interval [(3-65535)] [A.B.C.D]",
7819 "OSPF interface commands\n"
7820 "Time between retransmitting lost link state advertisements\n"
7822 "Address of interface\n")
7824 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7826 struct in_addr addr
;
7827 struct ospf_if_params
*params
;
7829 params
= IF_DEF_PARAMS(ifp
);
7831 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7832 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7834 "Please specify interface address by A.B.C.D\n");
7835 return CMD_WARNING_CONFIG_FAILED
;
7838 params
= ospf_lookup_if_params(ifp
, addr
);
7843 UNSET_IF_PARAM(params
, retransmit_interval
);
7844 params
->retransmit_interval
= OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
7846 if (params
!= IF_DEF_PARAMS(ifp
)) {
7847 ospf_free_if_params(ifp
, addr
);
7848 ospf_if_update_params(ifp
, addr
);
7854 DEFUN_HIDDEN (no_ospf_retransmit_interval
,
7855 no_ospf_retransmit_interval_cmd
,
7856 "no ospf retransmit-interval [(3-65535)] [A.B.C.D]",
7858 "OSPF interface commands\n"
7859 "Time between retransmitting lost link state advertisements\n"
7861 "Address of interface\n")
7863 return no_ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
7866 DEFUN (ip_ospf_transmit_delay
,
7867 ip_ospf_transmit_delay_addr_cmd
,
7868 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
7870 "OSPF interface commands\n"
7871 "Link state transmit delay\n"
7873 "Address of interface\n")
7875 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7878 struct in_addr addr
;
7879 struct ospf_if_params
*params
;
7881 params
= IF_DEF_PARAMS(ifp
);
7882 argv_find(argv
, argc
, "(1-65535)", &idx
);
7883 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7885 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7886 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7888 "Please specify interface address by A.B.C.D\n");
7889 return CMD_WARNING_CONFIG_FAILED
;
7892 params
= ospf_get_if_params(ifp
, addr
);
7893 ospf_if_update_params(ifp
, addr
);
7896 SET_IF_PARAM(params
, transmit_delay
);
7897 params
->transmit_delay
= seconds
;
7902 DEFUN_HIDDEN (ospf_transmit_delay
,
7903 ospf_transmit_delay_cmd
,
7904 "ospf transmit-delay (1-65535) [A.B.C.D]",
7905 "OSPF interface commands\n"
7906 "Link state transmit delay\n"
7908 "Address of interface\n")
7910 return ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
7913 DEFUN (no_ip_ospf_transmit_delay
,
7914 no_ip_ospf_transmit_delay_addr_cmd
,
7915 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
7918 "OSPF interface commands\n"
7919 "Link state transmit delay\n"
7921 "Address of interface\n")
7923 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7925 struct in_addr addr
;
7926 struct ospf_if_params
*params
;
7928 params
= IF_DEF_PARAMS(ifp
);
7930 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7931 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7933 "Please specify interface address by A.B.C.D\n");
7934 return CMD_WARNING_CONFIG_FAILED
;
7937 params
= ospf_lookup_if_params(ifp
, addr
);
7942 UNSET_IF_PARAM(params
, transmit_delay
);
7943 params
->transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
7945 if (params
!= IF_DEF_PARAMS(ifp
)) {
7946 ospf_free_if_params(ifp
, addr
);
7947 ospf_if_update_params(ifp
, addr
);
7954 DEFUN_HIDDEN (no_ospf_transmit_delay
,
7955 no_ospf_transmit_delay_cmd
,
7956 "no ospf transmit-delay [(1-65535) [A.B.C.D]]",
7958 "OSPF interface commands\n"
7959 "Link state transmit delay\n"
7961 "Address of interface\n")
7963 return no_ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
7966 DEFUN (ip_ospf_area
,
7968 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]",
7970 "OSPF interface commands\n"
7972 "Enable OSPF on this interface\n"
7973 "OSPF area ID in IP address format\n"
7974 "OSPF area ID as a decimal value\n"
7975 "Address of interface\n")
7977 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7980 struct in_addr area_id
;
7981 struct in_addr addr
;
7982 struct ospf_if_params
*params
= NULL
;
7983 struct route_node
*rn
;
7984 struct ospf
*ospf
= NULL
;
7985 unsigned short instance
= 0;
7988 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
7989 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
7991 argv_find(argv
, argc
, "area", &idx
);
7992 areaid
= argv
[idx
+ 1]->arg
;
7994 if (ifp
->vrf_id
&& !instance
)
7995 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7997 ospf
= ospf_lookup_instance(instance
);
7999 if (instance
&& ospf
== NULL
) {
8000 params
= IF_DEF_PARAMS(ifp
);
8001 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8002 UNSET_IF_PARAM(params
, if_area
);
8003 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
8004 ospf_interface_area_unset(ospf
, ifp
);
8005 ospf
->if_ospf_cli_count
--;
8007 return CMD_NOT_MY_INSTANCE
;
8010 ret
= str2area_id(areaid
, &area_id
, &format
);
8012 vty_out(vty
, "Please specify area by A.B.C.D|<0-4294967295>\n");
8013 return CMD_WARNING_CONFIG_FAILED
;
8015 if (memcmp(ifp
->name
, "VLINK", 5) == 0) {
8016 vty_out(vty
, "Cannot enable OSPF on a virtual link.\n");
8017 return CMD_WARNING_CONFIG_FAILED
;
8020 params
= IF_DEF_PARAMS(ifp
);
8021 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)
8022 && !IPV4_ADDR_SAME(¶ms
->if_area
, &area_id
)) {
8024 "Must remove previous area config before changing ospf area \n");
8025 return CMD_WARNING_CONFIG_FAILED
;
8028 // Check if we have an address arg and proccess it
8029 if (argc
== idx
+ 3) {
8030 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
8032 "Please specify Intf Address by A.B.C.D\n");
8033 return CMD_WARNING_CONFIG_FAILED
;
8035 // update/create address-level params
8036 params
= ospf_get_if_params((ifp
), (addr
));
8037 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8039 "Must remove previous area/address config before changing ospf area");
8040 return CMD_WARNING_CONFIG_FAILED
;
8042 ospf_if_update_params((ifp
), (addr
));
8046 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
)) {
8047 if (rn
->info
!= NULL
) {
8049 "Please remove all network commands first.\n");
8050 return CMD_WARNING_CONFIG_FAILED
;
8055 /* enable ospf on this interface with area_id */
8057 SET_IF_PARAM(params
, if_area
);
8058 params
->if_area
= area_id
;
8059 params
->if_area_id_fmt
= format
;
8063 ospf_interface_area_set(ospf
, ifp
);
8064 ospf
->if_ospf_cli_count
++;
8070 DEFUN (no_ip_ospf_area
,
8071 no_ip_ospf_area_cmd
,
8072 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]",
8075 "OSPF interface commands\n"
8077 "Disable OSPF on this interface\n"
8078 "OSPF area ID in IP address format\n"
8079 "OSPF area ID as a decimal value\n"
8080 "Address of interface\n")
8082 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8085 struct ospf_if_params
*params
;
8086 unsigned short instance
= 0;
8087 struct in_addr addr
;
8089 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
8090 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
8092 if (ifp
->vrf_id
&& !instance
)
8093 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
8095 ospf
= ospf_lookup_instance(instance
);
8098 return CMD_NOT_MY_INSTANCE
;
8100 argv_find(argv
, argc
, "area", &idx
);
8102 // Check if we have an address arg and proccess it
8103 if (argc
== idx
+ 3) {
8104 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
8106 "Please specify Intf Address by A.B.C.D\n");
8107 return CMD_WARNING_CONFIG_FAILED
;
8109 params
= ospf_lookup_if_params(ifp
, addr
);
8110 if ((params
) == NULL
)
8113 params
= IF_DEF_PARAMS(ifp
);
8115 if (!OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8117 "Can't find specified interface area configuration.\n");
8118 return CMD_WARNING_CONFIG_FAILED
;
8121 UNSET_IF_PARAM(params
, if_area
);
8122 if (params
!= IF_DEF_PARAMS((ifp
))) {
8123 ospf_free_if_params((ifp
), (addr
));
8124 ospf_if_update_params((ifp
), (addr
));
8127 ospf_interface_area_unset(ospf
, ifp
);
8128 ospf
->if_ospf_cli_count
--;
8132 DEFUN (ospf_redistribute_source
,
8133 ospf_redistribute_source_cmd
,
8134 "redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8136 FRR_REDIST_HELP_STR_OSPFD
8137 "Metric for redistributed routes\n"
8138 "OSPF default metric\n"
8139 "OSPF exterior metric type for redistributed routes\n"
8140 "Set OSPF External Type 1/2 metrics\n"
8141 "Route map reference\n"
8142 "Pointer to route-map entries\n")
8144 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8145 int idx_protocol
= 1;
8149 struct ospf_redist
*red
;
8152 /* Get distribute source. */
8153 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
8155 return CMD_WARNING_CONFIG_FAILED
;
8157 red
= ospf_redist_add(ospf
, source
, 0);
8159 /* Get metric value. */
8160 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
8161 if (!str2metric(argv
[idx
]->arg
, &metric
))
8162 return CMD_WARNING_CONFIG_FAILED
;
8165 /* Get metric type. */
8166 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
8167 if (!str2metric_type(argv
[idx
]->arg
, &type
))
8168 return CMD_WARNING_CONFIG_FAILED
;
8172 if (argv_find(argv
, argc
, "WORD", &idx
)) {
8173 ospf_routemap_set(red
, argv
[idx
]->arg
);
8175 ospf_routemap_unset(red
);
8177 return ospf_redistribute_set(ospf
, source
, 0, type
, metric
);
8180 DEFUN (no_ospf_redistribute_source
,
8181 no_ospf_redistribute_source_cmd
,
8182 "no redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8185 FRR_REDIST_HELP_STR_OSPFD
8186 "Metric for redistributed routes\n"
8187 "OSPF default metric\n"
8188 "OSPF exterior metric type for redistributed routes\n"
8189 "Set OSPF External Type 1/2 metrics\n"
8190 "Route map reference\n"
8191 "Pointer to route-map entries\n")
8193 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8194 int idx_protocol
= 2;
8196 struct ospf_redist
*red
;
8198 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
8200 return CMD_WARNING_CONFIG_FAILED
;
8202 red
= ospf_redist_lookup(ospf
, source
, 0);
8206 ospf_routemap_unset(red
);
8207 ospf_redist_del(ospf
, source
, 0);
8209 return ospf_redistribute_unset(ospf
, source
, 0);
8212 DEFUN (ospf_redistribute_instance_source
,
8213 ospf_redistribute_instance_source_cmd
,
8214 "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8216 "Open Shortest Path First\n"
8217 "Non-main Kernel Routing Table\n"
8218 "Instance ID/Table ID\n"
8219 "Metric for redistributed routes\n"
8220 "OSPF default metric\n"
8221 "OSPF exterior metric type for redistributed routes\n"
8222 "Set OSPF External Type 1/2 metrics\n"
8223 "Route map reference\n"
8224 "Pointer to route-map entries\n")
8226 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8227 int idx_ospf_table
= 1;
8233 unsigned short instance
;
8234 struct ospf_redist
*red
;
8236 source
= proto_redistnum(AFI_IP
, argv
[idx_ospf_table
]->text
);
8239 vty_out(vty
, "Unknown instance redistribution\n");
8240 return CMD_WARNING_CONFIG_FAILED
;
8243 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8245 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
8247 "Instance redistribution in non-instanced OSPF not allowed\n");
8248 return CMD_WARNING_CONFIG_FAILED
;
8251 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
8252 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
8253 return CMD_WARNING_CONFIG_FAILED
;
8256 /* Get metric value. */
8257 if (argv_find(argv
, argc
, "metric", &idx
))
8258 if (!str2metric(argv
[idx
+ 1]->arg
, &metric
))
8259 return CMD_WARNING_CONFIG_FAILED
;
8262 /* Get metric type. */
8263 if (argv_find(argv
, argc
, "metric-type", &idx
))
8264 if (!str2metric_type(argv
[idx
+ 1]->arg
, &type
))
8265 return CMD_WARNING_CONFIG_FAILED
;
8267 red
= ospf_redist_add(ospf
, source
, instance
);
8270 if (argv_find(argv
, argc
, "route-map", &idx
))
8271 ospf_routemap_set(red
, argv
[idx
+ 1]->arg
);
8273 ospf_routemap_unset(red
);
8275 return ospf_redistribute_set(ospf
, source
, instance
, type
, metric
);
8278 DEFUN (no_ospf_redistribute_instance_source
,
8279 no_ospf_redistribute_instance_source_cmd
,
8280 "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8283 "Open Shortest Path First\n"
8284 "Non-main Kernel Routing Table\n"
8285 "Instance ID/Table Id\n"
8286 "Metric for redistributed routes\n"
8287 "OSPF default metric\n"
8288 "OSPF exterior metric type for redistributed routes\n"
8289 "Set OSPF External Type 1/2 metrics\n"
8290 "Route map reference\n"
8291 "Pointer to route-map entries\n")
8293 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8294 int idx_ospf_table
= 2;
8296 unsigned int instance
;
8297 struct ospf_redist
*red
;
8300 if (strncmp(argv
[idx_ospf_table
]->arg
, "o", 1) == 0)
8301 source
= ZEBRA_ROUTE_OSPF
;
8303 source
= ZEBRA_ROUTE_TABLE
;
8305 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8307 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
8309 "Instance redistribution in non-instanced OSPF not allowed\n");
8310 return CMD_WARNING_CONFIG_FAILED
;
8313 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
8314 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
8315 return CMD_WARNING_CONFIG_FAILED
;
8318 red
= ospf_redist_lookup(ospf
, source
, instance
);
8322 ospf_routemap_unset(red
);
8323 ospf_redist_del(ospf
, source
, instance
);
8325 return ospf_redistribute_unset(ospf
, source
, instance
);
8328 DEFUN (ospf_distribute_list_out
,
8329 ospf_distribute_list_out_cmd
,
8330 "distribute-list WORD out " FRR_REDIST_STR_OSPFD
,
8331 "Filter networks in routing updates\n"
8332 "Access-list name\n"
8334 FRR_REDIST_HELP_STR_OSPFD
)
8336 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8340 char *proto
= argv
[argc
- 1]->text
;
8342 /* Get distribute source. */
8343 source
= proto_redistnum(AFI_IP
, proto
);
8345 return CMD_WARNING_CONFIG_FAILED
;
8347 return ospf_distribute_list_out_set(ospf
, source
, argv
[idx_word
]->arg
);
8350 DEFUN (no_ospf_distribute_list_out
,
8351 no_ospf_distribute_list_out_cmd
,
8352 "no distribute-list WORD out " FRR_REDIST_STR_OSPFD
,
8354 "Filter networks in routing updates\n"
8355 "Access-list name\n"
8357 FRR_REDIST_HELP_STR_OSPFD
)
8359 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8363 char *proto
= argv
[argc
- 1]->text
;
8364 source
= proto_redistnum(AFI_IP
, proto
);
8366 return CMD_WARNING_CONFIG_FAILED
;
8368 return ospf_distribute_list_out_unset(ospf
, source
,
8369 argv
[idx_word
]->arg
);
8372 /* Default information originate. */
8373 DEFUN (ospf_default_information_originate
,
8374 ospf_default_information_originate_cmd
,
8375 "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8376 "Control distribution of default information\n"
8377 "Distribute a default route\n"
8378 "Always advertise default route\n"
8379 "OSPF default metric\n"
8381 "OSPF metric type for default routes\n"
8382 "Set OSPF External Type 1/2 metrics\n"
8383 "Route map reference\n"
8384 "Pointer to route-map entries\n")
8386 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8387 int default_originate
= DEFAULT_ORIGINATE_ZEBRA
;
8390 struct ospf_redist
*red
;
8392 int cur_originate
= ospf
->default_originate
;
8396 red
= ospf_redist_add(ospf
, DEFAULT_ROUTE
, 0);
8398 /* Check whether "always" was specified */
8399 if (argv_find(argv
, argc
, "always", &idx
))
8400 default_originate
= DEFAULT_ORIGINATE_ALWAYS
;
8402 /* Get metric value */
8403 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
8404 if (!str2metric(argv
[idx
]->arg
, &metric
))
8405 return CMD_WARNING_CONFIG_FAILED
;
8408 /* Get metric type. */
8409 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
8410 if (!str2metric_type(argv
[idx
]->arg
, &type
))
8411 return CMD_WARNING_CONFIG_FAILED
;
8415 if (argv_find(argv
, argc
, "WORD", &idx
))
8416 rtmap
= argv
[idx
]->arg
;
8418 /* To check ,if user is providing same route map */
8419 if ((rtmap
== ROUTEMAP_NAME(red
)) ||
8420 (rtmap
&& ROUTEMAP_NAME(red
)
8421 && (strcmp(rtmap
, ROUTEMAP_NAME(red
)) == 0)))
8424 /* Don't allow if the same lsa is aleardy originated. */
8426 && (red
->dmetric
.type
== type
)
8427 && (red
->dmetric
.value
== metric
)
8428 && (cur_originate
== default_originate
))
8431 /* Updating Metric details */
8432 red
->dmetric
.type
= type
;
8433 red
->dmetric
.value
= metric
;
8435 /* updating route map details */
8437 ospf_routemap_set(red
, rtmap
);
8439 ospf_routemap_unset(red
);
8441 return ospf_redistribute_default_set(ospf
, default_originate
, type
,
8445 DEFUN (no_ospf_default_information_originate
,
8446 no_ospf_default_information_originate_cmd
,
8447 "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8449 "Control distribution of default information\n"
8450 "Distribute a default route\n"
8451 "Always advertise default route\n"
8452 "OSPF default metric\n"
8454 "OSPF metric type for default routes\n"
8455 "Set OSPF External Type 1/2 metrics\n"
8456 "Route map reference\n"
8457 "Pointer to route-map entries\n")
8459 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8460 struct prefix_ipv4 p
;
8461 struct ospf_external
*ext
;
8462 struct ospf_redist
*red
;
8465 p
.prefix
.s_addr
= 0;
8468 ospf_external_lsa_flush(ospf
, DEFAULT_ROUTE
, &p
, 0);
8470 ext
= ospf_external_lookup(ospf
, DEFAULT_ROUTE
, 0);
8471 if (ext
&& EXTERNAL_INFO(ext
)) {
8472 ospf_external_info_delete(ospf
, DEFAULT_ROUTE
, 0, p
);
8473 ospf_external_del(ospf
, DEFAULT_ROUTE
, 0);
8476 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
8480 ospf_routemap_unset(red
);
8481 ospf_redist_del(ospf
, DEFAULT_ROUTE
, 0);
8483 return ospf_redistribute_default_unset(ospf
);
8486 DEFUN (ospf_default_metric
,
8487 ospf_default_metric_cmd
,
8488 "default-metric (0-16777214)",
8489 "Set metric of redistributed routes\n"
8492 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8496 if (!str2metric(argv
[idx_number
]->arg
, &metric
))
8497 return CMD_WARNING_CONFIG_FAILED
;
8499 ospf
->default_metric
= metric
;
8504 DEFUN (no_ospf_default_metric
,
8505 no_ospf_default_metric_cmd
,
8506 "no default-metric [(0-16777214)]",
8508 "Set metric of redistributed routes\n"
8511 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8513 ospf
->default_metric
= -1;
8519 DEFUN (ospf_distance
,
8522 "Administrative distance\n"
8523 "OSPF Administrative distance\n")
8525 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8528 ospf
->distance_all
= atoi(argv
[idx_number
]->arg
);
8533 DEFUN (no_ospf_distance
,
8534 no_ospf_distance_cmd
,
8535 "no distance (1-255)",
8537 "Administrative distance\n"
8538 "OSPF Administrative distance\n")
8540 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8542 ospf
->distance_all
= 0;
8547 DEFUN (no_ospf_distance_ospf
,
8548 no_ospf_distance_ospf_cmd
,
8549 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
8551 "Administrative distance\n"
8552 "OSPF administrative distance\n"
8553 "Intra-area routes\n"
8554 "Distance for intra-area routes\n"
8555 "Inter-area routes\n"
8556 "Distance for inter-area routes\n"
8558 "Distance for external routes\n")
8560 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8563 if (argv_find(argv
, argc
, "intra-area", &idx
) || argc
== 3)
8564 idx
= ospf
->distance_intra
= 0;
8565 if (argv_find(argv
, argc
, "inter-area", &idx
) || argc
== 3)
8566 idx
= ospf
->distance_inter
= 0;
8567 if (argv_find(argv
, argc
, "external", &idx
) || argc
== 3)
8568 ospf
->distance_external
= 0;
8573 DEFUN (ospf_distance_ospf
,
8574 ospf_distance_ospf_cmd
,
8575 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
8576 "Administrative distance\n"
8577 "OSPF administrative distance\n"
8578 "Intra-area routes\n"
8579 "Distance for intra-area routes\n"
8580 "Inter-area routes\n"
8581 "Distance for inter-area routes\n"
8583 "Distance for external routes\n")
8585 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8588 ospf
->distance_intra
= 0;
8589 ospf
->distance_inter
= 0;
8590 ospf
->distance_external
= 0;
8592 if (argv_find(argv
, argc
, "intra-area", &idx
))
8593 ospf
->distance_intra
= atoi(argv
[idx
+ 1]->arg
);
8595 if (argv_find(argv
, argc
, "inter-area", &idx
))
8596 ospf
->distance_inter
= atoi(argv
[idx
+ 1]->arg
);
8598 if (argv_find(argv
, argc
, "external", &idx
))
8599 ospf
->distance_external
= atoi(argv
[idx
+ 1]->arg
);
8605 DEFUN (ospf_distance_source
,
8606 ospf_distance_source_cmd
,
8607 "distance (1-255) A.B.C.D/M",
8608 "Administrative distance\n"
8610 "IP source prefix\n")
8612 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8614 int idx_ipv4_prefixlen
= 2;
8616 ospf_distance_set (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
8621 DEFUN (no_ospf_distance_source
,
8622 no_ospf_distance_source_cmd
,
8623 "no distance (1-255) A.B.C.D/M",
8625 "Administrative distance\n"
8627 "IP source prefix\n")
8629 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8631 int idx_ipv4_prefixlen
= 3;
8633 ospf_distance_unset (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
8638 DEFUN (ospf_distance_source_access_list
,
8639 ospf_distance_source_access_list_cmd
,
8640 "distance (1-255) A.B.C.D/M WORD",
8641 "Administrative distance\n"
8643 "IP source prefix\n"
8644 "Access list name\n")
8646 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8648 int idx_ipv4_prefixlen
= 2;
8651 ospf_distance_set (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
8656 DEFUN (no_ospf_distance_source_access_list
,
8657 no_ospf_distance_source_access_list_cmd
,
8658 "no distance (1-255) A.B.C.D/M WORD",
8660 "Administrative distance\n"
8662 "IP source prefix\n"
8663 "Access list name\n")
8665 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8667 int idx_ipv4_prefixlen
= 3;
8670 ospf_distance_unset (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
8676 DEFUN (ip_ospf_mtu_ignore
,
8677 ip_ospf_mtu_ignore_addr_cmd
,
8678 "ip ospf mtu-ignore [A.B.C.D]",
8680 "OSPF interface commands\n"
8681 "Disable MTU mismatch detection on this interface\n"
8682 "Address of interface\n")
8684 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8686 struct in_addr addr
;
8689 struct ospf_if_params
*params
;
8690 params
= IF_DEF_PARAMS(ifp
);
8693 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8696 "Please specify interface address by A.B.C.D\n");
8697 return CMD_WARNING_CONFIG_FAILED
;
8699 params
= ospf_get_if_params(ifp
, addr
);
8700 ospf_if_update_params(ifp
, addr
);
8702 params
->mtu_ignore
= 1;
8703 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
8704 SET_IF_PARAM(params
, mtu_ignore
);
8706 UNSET_IF_PARAM(params
, mtu_ignore
);
8707 if (params
!= IF_DEF_PARAMS(ifp
)) {
8708 ospf_free_if_params(ifp
, addr
);
8709 ospf_if_update_params(ifp
, addr
);
8715 DEFUN (no_ip_ospf_mtu_ignore
,
8716 no_ip_ospf_mtu_ignore_addr_cmd
,
8717 "no ip ospf mtu-ignore [A.B.C.D]",
8720 "OSPF interface commands\n"
8721 "Disable MTU mismatch detection on this interface\n"
8722 "Address of interface\n")
8724 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8726 struct in_addr addr
;
8729 struct ospf_if_params
*params
;
8730 params
= IF_DEF_PARAMS(ifp
);
8733 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8736 "Please specify interface address by A.B.C.D\n");
8737 return CMD_WARNING_CONFIG_FAILED
;
8739 params
= ospf_get_if_params(ifp
, addr
);
8740 ospf_if_update_params(ifp
, addr
);
8742 params
->mtu_ignore
= 0;
8743 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
8744 SET_IF_PARAM(params
, mtu_ignore
);
8746 UNSET_IF_PARAM(params
, mtu_ignore
);
8747 if (params
!= IF_DEF_PARAMS(ifp
)) {
8748 ospf_free_if_params(ifp
, addr
);
8749 ospf_if_update_params(ifp
, addr
);
8756 DEFUN (ospf_max_metric_router_lsa_admin
,
8757 ospf_max_metric_router_lsa_admin_cmd
,
8758 "max-metric router-lsa administrative",
8759 "OSPF maximum / infinite-distance metric\n"
8760 "Advertise own Router-LSA with infinite distance (stub router)\n"
8761 "Administratively applied, for an indefinite period\n")
8763 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8764 struct listnode
*ln
;
8765 struct ospf_area
*area
;
8767 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8768 SET_FLAG(area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
);
8770 if (!CHECK_FLAG(area
->stub_router_state
,
8771 OSPF_AREA_IS_STUB_ROUTED
))
8772 ospf_router_lsa_update_area(area
);
8775 /* Allows for areas configured later to get the property */
8776 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
;
8781 DEFUN (no_ospf_max_metric_router_lsa_admin
,
8782 no_ospf_max_metric_router_lsa_admin_cmd
,
8783 "no max-metric router-lsa administrative",
8785 "OSPF maximum / infinite-distance metric\n"
8786 "Advertise own Router-LSA with infinite distance (stub router)\n"
8787 "Administratively applied, for an indefinite period\n")
8789 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8790 struct listnode
*ln
;
8791 struct ospf_area
*area
;
8793 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8794 UNSET_FLAG(area
->stub_router_state
,
8795 OSPF_AREA_ADMIN_STUB_ROUTED
);
8797 /* Don't trample on the start-up stub timer */
8798 if (CHECK_FLAG(area
->stub_router_state
,
8799 OSPF_AREA_IS_STUB_ROUTED
)
8800 && !area
->t_stub_router
) {
8801 UNSET_FLAG(area
->stub_router_state
,
8802 OSPF_AREA_IS_STUB_ROUTED
);
8803 ospf_router_lsa_update_area(area
);
8806 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET
;
8810 DEFUN (ospf_max_metric_router_lsa_startup
,
8811 ospf_max_metric_router_lsa_startup_cmd
,
8812 "max-metric router-lsa on-startup (5-86400)",
8813 "OSPF maximum / infinite-distance metric\n"
8814 "Advertise own Router-LSA with infinite distance (stub router)\n"
8815 "Automatically advertise stub Router-LSA on startup of OSPF\n"
8816 "Time (seconds) to advertise self as stub-router\n")
8818 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8820 unsigned int seconds
;
8823 vty_out(vty
, "%% Must supply stub-router period");
8824 return CMD_WARNING_CONFIG_FAILED
;
8827 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8829 ospf
->stub_router_startup_time
= seconds
;
8834 DEFUN (no_ospf_max_metric_router_lsa_startup
,
8835 no_ospf_max_metric_router_lsa_startup_cmd
,
8836 "no max-metric router-lsa on-startup [(5-86400)]",
8838 "OSPF maximum / infinite-distance metric\n"
8839 "Advertise own Router-LSA with infinite distance (stub router)\n"
8840 "Automatically advertise stub Router-LSA on startup of OSPF\n"
8841 "Time (seconds) to advertise self as stub-router\n")
8843 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8844 struct listnode
*ln
;
8845 struct ospf_area
*area
;
8847 ospf
->stub_router_startup_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
8849 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8850 SET_FLAG(area
->stub_router_state
,
8851 OSPF_AREA_WAS_START_STUB_ROUTED
);
8852 OSPF_TIMER_OFF(area
->t_stub_router
);
8854 /* Don't trample on admin stub routed */
8855 if (!CHECK_FLAG(area
->stub_router_state
,
8856 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
8857 UNSET_FLAG(area
->stub_router_state
,
8858 OSPF_AREA_IS_STUB_ROUTED
);
8859 ospf_router_lsa_update_area(area
);
8866 DEFUN (ospf_max_metric_router_lsa_shutdown
,
8867 ospf_max_metric_router_lsa_shutdown_cmd
,
8868 "max-metric router-lsa on-shutdown (5-100)",
8869 "OSPF maximum / infinite-distance metric\n"
8870 "Advertise own Router-LSA with infinite distance (stub router)\n"
8871 "Advertise stub-router prior to full shutdown of OSPF\n"
8872 "Time (seconds) to wait till full shutdown\n")
8874 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8876 unsigned int seconds
;
8879 vty_out(vty
, "%% Must supply stub-router shutdown period");
8880 return CMD_WARNING_CONFIG_FAILED
;
8883 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8885 ospf
->stub_router_shutdown_time
= seconds
;
8890 DEFUN (no_ospf_max_metric_router_lsa_shutdown
,
8891 no_ospf_max_metric_router_lsa_shutdown_cmd
,
8892 "no max-metric router-lsa on-shutdown [(5-100)]",
8894 "OSPF maximum / infinite-distance metric\n"
8895 "Advertise own Router-LSA with infinite distance (stub router)\n"
8896 "Advertise stub-router prior to full shutdown of OSPF\n"
8897 "Time (seconds) to wait till full shutdown\n")
8899 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8901 ospf
->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
8906 static void config_write_stub_router(struct vty
*vty
, struct ospf
*ospf
)
8908 struct listnode
*ln
;
8909 struct ospf_area
*area
;
8911 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
8912 vty_out(vty
, " max-metric router-lsa on-startup %u\n",
8913 ospf
->stub_router_startup_time
);
8914 if (ospf
->stub_router_shutdown_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
8915 vty_out(vty
, " max-metric router-lsa on-shutdown %u\n",
8916 ospf
->stub_router_shutdown_time
);
8917 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8918 if (CHECK_FLAG(area
->stub_router_state
,
8919 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
8920 vty_out(vty
, " max-metric router-lsa administrative\n");
8927 static void show_ip_ospf_route_network(struct vty
*vty
, struct ospf
*ospf
,
8928 struct route_table
*rt
,
8931 struct route_node
*rn
;
8932 struct ospf_route
* or ;
8933 struct listnode
*pnode
, *pnnode
;
8934 struct ospf_path
*path
;
8935 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
8936 *json_nexthop
= NULL
;
8940 "============ OSPF network routing table ============\n");
8942 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
8943 if ((or = rn
->info
) == NULL
)
8945 char buf1
[PREFIX2STR_BUFFER
];
8947 memset(buf1
, 0, sizeof(buf1
));
8948 prefix2str(&rn
->p
, buf1
, sizeof(buf1
));
8950 json_route
= json_object_new_object();
8952 json_object_object_add(json
, buf1
, json_route
);
8953 json_object_to_json_string_ext(
8954 json
, JSON_C_TO_STRING_NOSLASHESCAPE
);
8957 switch (or->path_type
) {
8958 case OSPF_PATH_INTER_AREA
:
8959 if (or->type
== OSPF_DESTINATION_NETWORK
) {
8961 json_object_string_add(json_route
,
8964 json_object_int_add(json_route
, "cost",
8966 json_object_string_add(
8968 inet_ntoa(or->u
.std
.area_id
));
8971 "N IA %-18s [%d] area: %s\n",
8973 inet_ntoa(or->u
.std
.area_id
));
8975 } else if (or->type
== OSPF_DESTINATION_DISCARD
) {
8977 json_object_string_add(json_route
,
8982 "D IA %-18s Discard entry\n",
8987 case OSPF_PATH_INTRA_AREA
:
8989 json_object_string_add(json_route
, "routeType",
8991 json_object_int_add(json_route
, "cost",
8993 json_object_string_add(
8995 inet_ntoa(or->u
.std
.area_id
));
8997 vty_out(vty
, "N %-18s [%d] area: %s\n",
8999 inet_ntoa(or->u
.std
.area_id
));
9006 if (or->type
== OSPF_DESTINATION_NETWORK
) {
9008 json_nexthop_array
= json_object_new_array();
9009 json_object_object_add(json_route
, "nexthops",
9010 json_nexthop_array
);
9013 for (ALL_LIST_ELEMENTS(or->paths
, pnode
, pnnode
,
9016 json_nexthop
= json_object_new_object();
9017 json_object_array_add(
9021 if (if_lookup_by_index(path
->ifindex
,
9024 if (path
->nexthop
.s_addr
== 0) {
9026 json_object_string_add(
9029 json_object_string_add(
9031 "directly attached to",
9037 "%24s directly attached to %s\n",
9045 json_object_string_add(
9050 json_object_string_add(
9058 "%24s via %s, %s\n",
9071 json_object_free(json_route
);
9077 static void show_ip_ospf_route_router(struct vty
*vty
, struct ospf
*ospf
,
9078 struct route_table
*rtrs
,
9081 struct route_node
*rn
;
9082 struct ospf_route
* or ;
9083 struct listnode
*pnode
;
9084 struct listnode
*node
;
9085 struct ospf_path
*path
;
9086 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
9087 *json_nexthop
= NULL
;
9091 "============ OSPF router routing table =============\n");
9093 for (rn
= route_top(rtrs
); rn
; rn
= route_next(rn
)) {
9094 if (rn
->info
== NULL
)
9098 json_route
= json_object_new_object();
9100 json_object_object_add(json
, inet_ntoa(rn
->p
.u
.prefix4
),
9102 json_object_string_add(json_route
, "routeType", "R ");
9104 vty_out(vty
, "R %-15s ",
9105 inet_ntoa(rn
->p
.u
.prefix4
));
9108 for (ALL_LIST_ELEMENTS_RO((struct list
*)rn
->info
, node
, or)) {
9111 vty_out(vty
, "%24s", "");
9116 json_object_int_add(json_route
, "cost",
9118 json_object_string_add(
9120 inet_ntoa(or->u
.std
.area_id
));
9121 if (or->path_type
== OSPF_PATH_INTER_AREA
)
9122 json_object_boolean_true_add(json_route
,
9124 if (or->u
.std
.flags
& ROUTER_LSA_BORDER
)
9125 json_object_string_add(json_route
,
9128 else if (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
)
9129 json_object_string_add(json_route
,
9133 vty_out(vty
, "%s [%d] area: %s",
9134 (or->path_type
== OSPF_PATH_INTER_AREA
9137 or->cost
, inet_ntoa(or->u
.std
.area_id
));
9139 vty_out(vty
, "%s%s\n",
9140 (or->u
.std
.flags
& ROUTER_LSA_BORDER
9143 (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
9149 json_nexthop_array
= json_object_new_array();
9150 json_object_object_add(json_route
, "nexthops",
9151 json_nexthop_array
);
9154 for (ALL_LIST_ELEMENTS_RO(or->paths
, pnode
, path
)) {
9156 json_nexthop
= json_object_new_object();
9157 json_object_array_add(
9161 if (if_lookup_by_index(path
->ifindex
,
9163 if (path
->nexthop
.s_addr
== 0) {
9165 json_object_string_add(
9168 json_object_string_add(
9170 "directly attached to",
9176 "%24s directly attached to %s\n",
9184 json_object_string_add(
9189 json_object_string_add(
9197 "%24s via %s, %s\n",
9210 json_object_free(json_route
);
9216 static void show_ip_ospf_route_external(struct vty
*vty
, struct ospf
*ospf
,
9217 struct route_table
*rt
,
9220 struct route_node
*rn
;
9221 struct ospf_route
*er
;
9222 struct listnode
*pnode
, *pnnode
;
9223 struct ospf_path
*path
;
9224 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
9225 *json_nexthop
= NULL
;
9229 "============ OSPF external routing table ===========\n");
9231 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
9232 if ((er
= rn
->info
) == NULL
)
9237 snprintf(buf1
, 19, "%s/%d", inet_ntoa(rn
->p
.u
.prefix4
),
9239 json_route
= json_object_new_object();
9241 json_object_object_add(json
, buf1
, json_route
);
9242 json_object_to_json_string_ext(
9243 json
, JSON_C_TO_STRING_NOSLASHESCAPE
);
9246 switch (er
->path_type
) {
9247 case OSPF_PATH_TYPE1_EXTERNAL
:
9249 json_object_string_add(json_route
, "routeType",
9251 json_object_int_add(json_route
, "cost",
9255 "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI
9257 buf1
, er
->cost
, er
->u
.ext
.tag
);
9260 case OSPF_PATH_TYPE2_EXTERNAL
:
9262 json_object_string_add(json_route
, "routeType",
9264 json_object_int_add(json_route
, "cost",
9268 "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI
9270 buf1
, er
->cost
, er
->u
.ext
.type2_cost
,
9277 json_nexthop_array
= json_object_new_array();
9278 json_object_object_add(json_route
, "nexthops",
9279 json_nexthop_array
);
9282 for (ALL_LIST_ELEMENTS(er
->paths
, pnode
, pnnode
, path
)) {
9284 json_nexthop
= json_object_new_object();
9285 json_object_array_add(json_nexthop_array
,
9289 if (if_lookup_by_index(path
->ifindex
, ospf
->vrf_id
)) {
9290 if (path
->nexthop
.s_addr
== 0) {
9292 json_object_string_add(
9295 json_object_string_add(
9297 "directly attached to",
9303 "%24s directly attached to %s\n",
9311 json_object_string_add(
9315 json_object_string_add(
9316 json_nexthop
, "via",
9322 "%24s via %s, %s\n",
9334 json_object_free(json_route
);
9340 static int show_ip_ospf_border_routers_common(struct vty
*vty
,
9345 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
9347 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
9349 if (ospf
->new_table
== NULL
) {
9350 vty_out(vty
, "No OSPF routing information exist\n");
9354 /* Show Network routes.
9355 show_ip_ospf_route_network (vty, ospf->new_table); */
9357 /* Show Router routes. */
9358 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, NULL
);
9365 DEFUN (show_ip_ospf_border_routers
,
9366 show_ip_ospf_border_routers_cmd
,
9367 "show ip ospf [vrf <NAME|all>] border-routers",
9370 "OSPF information\n"
9373 "Show all the ABR's and ASBR's\n")
9375 struct ospf
*ospf
= NULL
;
9376 struct listnode
*node
= NULL
;
9377 char *vrf_name
= NULL
;
9378 bool all_vrf
= FALSE
;
9379 int ret
= CMD_SUCCESS
;
9382 uint8_t use_vrf
= 0;
9384 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
9387 bool ospf_output
= FALSE
;
9392 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9393 if (!ospf
->oi_running
)
9397 ret
= show_ip_ospf_border_routers_common(
9398 vty
, ospf
, use_vrf
);
9402 vty_out(vty
, "%% OSPF instance not found\n");
9404 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
9405 if (ospf
== NULL
|| !ospf
->oi_running
) {
9406 vty_out(vty
, "%% OSPF instance not found\n");
9410 ret
= show_ip_ospf_border_routers_common(vty
, ospf
,
9414 /* Display default ospf (instance 0) info */
9415 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
9416 if (ospf
== NULL
|| !ospf
->oi_running
) {
9417 vty_out(vty
, "%% OSPF instance not found\n");
9421 ret
= show_ip_ospf_border_routers_common(vty
, ospf
, use_vrf
);
9427 DEFUN (show_ip_ospf_instance_border_routers
,
9428 show_ip_ospf_instance_border_routers_cmd
,
9429 "show ip ospf (1-65535) border-routers",
9432 "OSPF information\n"
9434 "Show all the ABR's and ASBR's\n")
9438 unsigned short instance
= 0;
9440 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9441 ospf
= ospf_lookup_instance(instance
);
9443 return CMD_NOT_MY_INSTANCE
;
9445 if (!ospf
->oi_running
)
9448 return show_ip_ospf_border_routers_common(vty
, ospf
, 0);
9451 static int show_ip_ospf_route_common(struct vty
*vty
, struct ospf
*ospf
,
9452 json_object
*json
, uint8_t use_vrf
)
9454 json_object
*json_vrf
= NULL
;
9457 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
9462 json_vrf
= json_object_new_object();
9467 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
9469 if (ospf
->new_table
== NULL
) {
9470 vty_out(vty
, "No OSPF routing information exist\n");
9474 /* Show Network routes. */
9475 show_ip_ospf_route_network(vty
, ospf
, ospf
->new_table
, json_vrf
);
9477 /* Show Router routes. */
9478 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, json_vrf
);
9480 /* Show AS External routes. */
9481 show_ip_ospf_route_external(vty
, ospf
, ospf
->old_external_route
,
9486 // json_object_object_add(json_vrf, "areas",
9488 if (ospf
->vrf_id
== VRF_DEFAULT
)
9489 json_object_object_add(json
, "default",
9492 json_object_object_add(json
, ospf
->name
,
9502 DEFUN (show_ip_ospf_route
,
9503 show_ip_ospf_route_cmd
,
9504 "show ip ospf [vrf <NAME|all>] route [json]",
9507 "OSPF information\n"
9510 "OSPF routing table\n"
9513 struct ospf
*ospf
= NULL
;
9514 struct listnode
*node
= NULL
;
9515 char *vrf_name
= NULL
;
9516 bool all_vrf
= FALSE
;
9517 int ret
= CMD_SUCCESS
;
9520 uint8_t use_vrf
= 0;
9521 bool uj
= use_json(argc
, argv
);
9522 json_object
*json
= NULL
;
9525 json
= json_object_new_object();
9527 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
9529 /* vrf input is provided could be all or specific vrf*/
9531 bool ospf_output
= FALSE
;
9536 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9537 if (!ospf
->oi_running
)
9540 ret
= show_ip_ospf_route_common(vty
, ospf
, json
,
9545 /* Keep Non-pretty format */
9546 vty_out(vty
, "%s\n",
9547 json_object_to_json_string(json
));
9548 json_object_free(json
);
9549 } else if (!ospf_output
)
9550 vty_out(vty
, "%% OSPF instance not found\n");
9554 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
9555 if (ospf
== NULL
|| !ospf
->oi_running
) {
9557 vty_out(vty
, "%s\n",
9558 json_object_to_json_string_ext(
9559 json
, JSON_C_TO_STRING_PRETTY
));
9560 json_object_free(json
);
9562 vty_out(vty
, "%% OSPF instance not found\n");
9567 /* Display default ospf (instance 0) info */
9568 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
9569 if (ospf
== NULL
|| !ospf
->oi_running
) {
9571 vty_out(vty
, "%s\n",
9572 json_object_to_json_string_ext(
9573 json
, JSON_C_TO_STRING_PRETTY
));
9574 json_object_free(json
);
9576 vty_out(vty
, "%% OSPF instance not found\n");
9583 ret
= show_ip_ospf_route_common(vty
, ospf
, json
, use_vrf
);
9584 /* Keep Non-pretty format */
9586 vty_out(vty
, "%s\n", json_object_to_json_string(json
));
9590 json_object_free(json
);
9595 DEFUN (show_ip_ospf_instance_route
,
9596 show_ip_ospf_instance_route_cmd
,
9597 "show ip ospf (1-65535) route",
9600 "OSPF information\n"
9602 "OSPF routing table\n")
9606 unsigned short instance
= 0;
9608 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9609 ospf
= ospf_lookup_instance(instance
);
9611 return CMD_NOT_MY_INSTANCE
;
9613 if (!ospf
->oi_running
)
9616 return show_ip_ospf_route_common(vty
, ospf
, NULL
, 0);
9620 DEFUN (show_ip_ospf_vrfs
,
9621 show_ip_ospf_vrfs_cmd
,
9622 "show ip ospf vrfs [json]",
9625 "OSPF information\n"
9629 bool uj
= use_json(argc
, argv
);
9630 json_object
*json
= NULL
;
9631 json_object
*json_vrfs
= NULL
;
9632 struct ospf
*ospf
= NULL
;
9633 struct listnode
*node
= NULL
;
9635 static char header
[] = "Name Id RouterId ";
9638 json
= json_object_new_object();
9639 json_vrfs
= json_object_new_object();
9642 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9643 json_object
*json_vrf
= NULL
;
9644 const char *name
= NULL
;
9645 int64_t vrf_id_ui
= 0;
9649 if (!uj
&& count
== 1)
9650 vty_out(vty
, "%s\n", header
);
9652 json_vrf
= json_object_new_object();
9654 if (ospf
->vrf_id
== 0)
9655 name
= VRF_DEFAULT_NAME
;
9659 vrf_id_ui
= (ospf
->vrf_id
== VRF_UNKNOWN
)
9661 : (int64_t)ospf
->vrf_id
;
9664 json_object_int_add(json_vrf
, "vrfId", vrf_id_ui
);
9665 json_object_string_add(json_vrf
, "routerId",
9666 inet_ntoa(ospf
->router_id
));
9668 json_object_object_add(json_vrfs
, name
, json_vrf
);
9671 vty_out(vty
, "%-25s %-5d %-16s \n", name
,
9672 ospf
->vrf_id
, inet_ntoa(ospf
->router_id
));
9677 json_object_object_add(json
, "vrfs", json_vrfs
);
9678 json_object_int_add(json
, "totalVrfs", count
);
9680 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
9681 json
, JSON_C_TO_STRING_PRETTY
));
9682 json_object_free(json
);
9685 vty_out(vty
, "\nTotal number of OSPF VRFs: %d\n",
9692 const char *ospf_abr_type_str
[] = {"unknown", "standard", "ibm", "cisco",
9695 const char *ospf_shortcut_mode_str
[] = {"default", "enable", "disable"};
9697 const char *ospf_int_type_str
[] = {"unknown", /* should never be used. */
9698 "point-to-point", "broadcast",
9699 "non-broadcast", "point-to-multipoint",
9700 "virtual-link", /* should never be used. */
9703 static int config_write_interface_one(struct vty
*vty
, struct vrf
*vrf
)
9705 struct listnode
*node
;
9706 struct interface
*ifp
;
9707 struct crypt_key
*ck
;
9708 struct route_node
*rn
= NULL
;
9709 struct ospf_if_params
*params
;
9711 struct ospf
*ospf
= vrf
->info
;
9713 FOR_ALL_INTERFACES (vrf
, ifp
) {
9715 if (memcmp(ifp
->name
, "VLINK", 5) == 0)
9718 vty_frame(vty
, "!\n");
9719 if (ifp
->vrf_id
== VRF_DEFAULT
)
9720 vty_frame(vty
, "interface %s\n", ifp
->name
);
9722 vty_frame(vty
, "interface %s vrf %s\n", ifp
->name
,
9725 vty_out(vty
, " description %s\n", ifp
->desc
);
9729 params
= IF_DEF_PARAMS(ifp
);
9732 /* Interface Network print. */
9733 if (OSPF_IF_PARAM_CONFIGURED(params
, type
)
9734 && params
->type
!= OSPF_IFTYPE_LOOPBACK
) {
9735 if (params
->type
!= ospf_default_iftype(ifp
)) {
9736 vty_out(vty
, " ip ospf network %s",
9739 if (params
!= IF_DEF_PARAMS(ifp
))
9747 /* OSPF interface authentication print */
9748 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_type
)
9749 && params
->auth_type
!= OSPF_AUTH_NOTSET
) {
9750 const char *auth_str
;
9752 /* Translation tables are not that much help
9753 * here due to syntax
9754 * of the simple option */
9755 switch (params
->auth_type
) {
9757 case OSPF_AUTH_NULL
:
9761 case OSPF_AUTH_SIMPLE
:
9765 case OSPF_AUTH_CRYPTOGRAPHIC
:
9766 auth_str
= " message-digest";
9774 vty_out(vty
, " ip ospf authentication%s",
9776 if (params
!= IF_DEF_PARAMS(ifp
))
9778 inet_ntoa(rn
->p
.u
.prefix4
));
9782 /* Simple Authentication Password print. */
9783 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_simple
)
9784 && params
->auth_simple
[0] != '\0') {
9785 vty_out(vty
, " ip ospf authentication-key %s",
9786 params
->auth_simple
);
9787 if (params
!= IF_DEF_PARAMS(ifp
))
9789 inet_ntoa(rn
->p
.u
.prefix4
));
9793 /* Cryptographic Authentication Key print. */
9794 if (params
&& params
->auth_crypt
) {
9795 for (ALL_LIST_ELEMENTS_RO(params
->auth_crypt
,
9798 " ip ospf message-digest-key %d md5 %s",
9799 ck
->key_id
, ck
->auth_key
);
9800 if (params
!= IF_DEF_PARAMS(ifp
))
9808 /* Interface Output Cost print. */
9809 if (OSPF_IF_PARAM_CONFIGURED(params
, output_cost_cmd
)) {
9810 vty_out(vty
, " ip ospf cost %u",
9811 params
->output_cost_cmd
);
9812 if (params
!= IF_DEF_PARAMS(ifp
))
9814 inet_ntoa(rn
->p
.u
.prefix4
));
9818 /* Hello Interval print. */
9819 if (OSPF_IF_PARAM_CONFIGURED(params
, v_hello
)
9820 && params
->v_hello
!= OSPF_HELLO_INTERVAL_DEFAULT
) {
9821 vty_out(vty
, " ip ospf hello-interval %u",
9823 if (params
!= IF_DEF_PARAMS(ifp
))
9825 inet_ntoa(rn
->p
.u
.prefix4
));
9830 /* Router Dead Interval print. */
9831 if (OSPF_IF_PARAM_CONFIGURED(params
, v_wait
)
9833 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
) {
9834 vty_out(vty
, " ip ospf dead-interval ");
9837 if (OSPF_IF_PARAM_CONFIGURED(params
,
9840 "minimal hello-multiplier %d",
9841 params
->fast_hello
);
9843 vty_out(vty
, "%u", params
->v_wait
);
9845 if (params
!= IF_DEF_PARAMS(ifp
))
9847 inet_ntoa(rn
->p
.u
.prefix4
));
9851 /* Router Priority print. */
9852 if (OSPF_IF_PARAM_CONFIGURED(params
, priority
)
9854 != OSPF_ROUTER_PRIORITY_DEFAULT
) {
9855 vty_out(vty
, " ip ospf priority %u",
9857 if (params
!= IF_DEF_PARAMS(ifp
))
9859 inet_ntoa(rn
->p
.u
.prefix4
));
9863 /* Retransmit Interval print. */
9864 if (OSPF_IF_PARAM_CONFIGURED(params
,
9865 retransmit_interval
)
9866 && params
->retransmit_interval
9867 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
) {
9868 vty_out(vty
, " ip ospf retransmit-interval %u",
9869 params
->retransmit_interval
);
9870 if (params
!= IF_DEF_PARAMS(ifp
))
9872 inet_ntoa(rn
->p
.u
.prefix4
));
9876 /* Transmit Delay print. */
9877 if (OSPF_IF_PARAM_CONFIGURED(params
, transmit_delay
)
9878 && params
->transmit_delay
9879 != OSPF_TRANSMIT_DELAY_DEFAULT
) {
9880 vty_out(vty
, " ip ospf transmit-delay %u",
9881 params
->transmit_delay
);
9882 if (params
!= IF_DEF_PARAMS(ifp
))
9884 inet_ntoa(rn
->p
.u
.prefix4
));
9889 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
9890 if (ospf
&& ospf
->instance
)
9891 vty_out(vty
, " ip ospf %d",
9894 vty_out(vty
, " ip ospf");
9896 char buf
[INET_ADDRSTRLEN
];
9898 area_id2str(buf
, sizeof(buf
), ¶ms
->if_area
,
9899 params
->if_area_id_fmt
);
9900 vty_out(vty
, " area %s", buf
);
9901 if (params
!= IF_DEF_PARAMS(ifp
))
9903 inet_ntoa(rn
->p
.u
.prefix4
));
9908 if (params
&& params
->bfd_info
)
9909 ospf_bfd_write_config(vty
, params
);
9911 /* MTU ignore print. */
9912 if (OSPF_IF_PARAM_CONFIGURED(params
, mtu_ignore
)
9913 && params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
) {
9914 if (params
->mtu_ignore
== 0)
9915 vty_out(vty
, " no ip ospf mtu-ignore");
9917 vty_out(vty
, " ip ospf mtu-ignore");
9918 if (params
!= IF_DEF_PARAMS(ifp
))
9920 inet_ntoa(rn
->p
.u
.prefix4
));
9927 rn
= route_top(IF_OIFS_PARAMS(ifp
));
9929 rn
= route_next(rn
);
9939 ospf_opaque_config_write_if(vty
, ifp
);
9941 vty_endframe(vty
, NULL
);
9947 /* Configuration write function for ospfd. */
9948 static int config_write_interface(struct vty
*vty
)
9951 struct vrf
*vrf
= NULL
;
9953 /* Display all VRF aware OSPF interface configuration */
9954 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
9955 write
+= config_write_interface_one(vty
, vrf
);
9961 static int config_write_network_area(struct vty
*vty
, struct ospf
*ospf
)
9963 struct route_node
*rn
;
9964 uint8_t buf
[INET_ADDRSTRLEN
];
9966 /* `network area' print. */
9967 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
))
9969 struct ospf_network
*n
= rn
->info
;
9971 /* Create Area ID string by specified Area ID format. */
9972 if (n
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
9973 inet_ntop(AF_INET
, &n
->area_id
, (char *)buf
,
9976 sprintf((char *)buf
, "%lu",
9977 (unsigned long int)ntohl(
9978 n
->area_id
.s_addr
));
9980 /* Network print. */
9981 vty_out(vty
, " network %s/%d area %s\n",
9982 inet_ntoa(rn
->p
.u
.prefix4
), rn
->p
.prefixlen
,
9989 static int config_write_ospf_area(struct vty
*vty
, struct ospf
*ospf
)
9991 struct listnode
*node
;
9992 struct ospf_area
*area
;
9993 uint8_t buf
[INET_ADDRSTRLEN
];
9995 /* Area configuration print. */
9996 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
9997 struct route_node
*rn1
;
9999 area_id2str((char *)buf
, sizeof(buf
), &area
->area_id
,
10000 area
->area_id_fmt
);
10002 if (area
->auth_type
!= OSPF_AUTH_NULL
) {
10003 if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
10004 vty_out(vty
, " area %s authentication\n", buf
);
10007 " area %s authentication message-digest\n",
10011 if (area
->shortcut_configured
!= OSPF_SHORTCUT_DEFAULT
)
10012 vty_out(vty
, " area %s shortcut %s\n", buf
,
10013 ospf_shortcut_mode_str
10014 [area
->shortcut_configured
]);
10016 if ((area
->external_routing
== OSPF_AREA_STUB
)
10017 || (area
->external_routing
== OSPF_AREA_NSSA
)) {
10018 if (area
->external_routing
== OSPF_AREA_STUB
) {
10019 vty_out(vty
, " area %s stub", buf
);
10020 if (area
->no_summary
)
10021 vty_out(vty
, " no-summary\n");
10022 vty_out(vty
, "\n");
10023 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
10024 switch (area
->NSSATranslatorRole
) {
10025 case OSPF_NSSA_ROLE_NEVER
:
10027 " area %s nssa translate-never\n",
10030 case OSPF_NSSA_ROLE_ALWAYS
:
10032 " area %s nssa translate-always\n",
10035 case OSPF_NSSA_ROLE_CANDIDATE
:
10036 vty_out(vty
, " area %s nssa \n", buf
);
10039 if (area
->no_summary
)
10041 " area %s nssa no-summary\n",
10045 if (area
->default_cost
!= 1)
10046 vty_out(vty
, " area %s default-cost %d\n", buf
,
10047 area
->default_cost
);
10050 for (rn1
= route_top(area
->ranges
); rn1
; rn1
= route_next(rn1
))
10052 struct ospf_area_range
*range
= rn1
->info
;
10054 vty_out(vty
, " area %s range %s/%d", buf
,
10055 inet_ntoa(rn1
->p
.u
.prefix4
),
10058 if (range
->cost_config
10059 != OSPF_AREA_RANGE_COST_UNSPEC
)
10060 vty_out(vty
, " cost %d",
10061 range
->cost_config
);
10063 if (!CHECK_FLAG(range
->flags
,
10064 OSPF_AREA_RANGE_ADVERTISE
))
10065 vty_out(vty
, " not-advertise");
10067 if (CHECK_FLAG(range
->flags
,
10068 OSPF_AREA_RANGE_SUBSTITUTE
))
10069 vty_out(vty
, " substitute %s/%d",
10070 inet_ntoa(range
->subst_addr
),
10071 range
->subst_masklen
);
10073 vty_out(vty
, "\n");
10076 if (EXPORT_NAME(area
))
10077 vty_out(vty
, " area %s export-list %s\n", buf
,
10078 EXPORT_NAME(area
));
10080 if (IMPORT_NAME(area
))
10081 vty_out(vty
, " area %s import-list %s\n", buf
,
10082 IMPORT_NAME(area
));
10084 if (PREFIX_NAME_IN(area
))
10085 vty_out(vty
, " area %s filter-list prefix %s in\n", buf
,
10086 PREFIX_NAME_IN(area
));
10088 if (PREFIX_NAME_OUT(area
))
10089 vty_out(vty
, " area %s filter-list prefix %s out\n",
10090 buf
, PREFIX_NAME_OUT(area
));
10096 static int config_write_ospf_nbr_nbma(struct vty
*vty
, struct ospf
*ospf
)
10098 struct ospf_nbr_nbma
*nbr_nbma
;
10099 struct route_node
*rn
;
10101 /* Static Neighbor configuration print. */
10102 for (rn
= route_top(ospf
->nbr_nbma
); rn
; rn
= route_next(rn
))
10103 if ((nbr_nbma
= rn
->info
)) {
10104 vty_out(vty
, " neighbor %s", inet_ntoa(nbr_nbma
->addr
));
10106 if (nbr_nbma
->priority
10107 != OSPF_NEIGHBOR_PRIORITY_DEFAULT
)
10108 vty_out(vty
, " priority %d",
10109 nbr_nbma
->priority
);
10111 if (nbr_nbma
->v_poll
!= OSPF_POLL_INTERVAL_DEFAULT
)
10112 vty_out(vty
, " poll-interval %d",
10115 vty_out(vty
, "\n");
10121 static int config_write_virtual_link(struct vty
*vty
, struct ospf
*ospf
)
10123 struct listnode
*node
;
10124 struct ospf_vl_data
*vl_data
;
10125 char buf
[INET_ADDRSTRLEN
];
10127 /* Virtual-Link print */
10128 for (ALL_LIST_ELEMENTS_RO(ospf
->vlinks
, node
, vl_data
)) {
10129 struct listnode
*n2
;
10130 struct crypt_key
*ck
;
10131 struct ospf_interface
*oi
;
10133 if (vl_data
!= NULL
) {
10134 area_id2str(buf
, sizeof(buf
), &vl_data
->vl_area_id
,
10135 vl_data
->vl_area_id_fmt
);
10136 oi
= vl_data
->vl_oi
;
10139 if (OSPF_IF_PARAM(oi
, v_hello
)
10140 != OSPF_HELLO_INTERVAL_DEFAULT
10141 || OSPF_IF_PARAM(oi
, v_wait
)
10142 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
10143 || OSPF_IF_PARAM(oi
, retransmit_interval
)
10144 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
10145 || OSPF_IF_PARAM(oi
, transmit_delay
)
10146 != OSPF_TRANSMIT_DELAY_DEFAULT
)
10148 " area %s virtual-link %s hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n",
10149 buf
, inet_ntoa(vl_data
->vl_peer
),
10150 OSPF_IF_PARAM(oi
, v_hello
),
10151 OSPF_IF_PARAM(oi
, retransmit_interval
),
10152 OSPF_IF_PARAM(oi
, transmit_delay
),
10153 OSPF_IF_PARAM(oi
, v_wait
));
10155 vty_out(vty
, " area %s virtual-link %s\n", buf
,
10156 inet_ntoa(vl_data
->vl_peer
));
10158 if (IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)->auth_simple
[0]
10161 " area %s virtual-link %s authentication-key %s\n",
10162 buf
, inet_ntoa(vl_data
->vl_peer
),
10163 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
10166 for (ALL_LIST_ELEMENTS_RO(
10167 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
10171 " area %s virtual-link %s"
10172 " message-digest-key %d md5 %s\n",
10173 buf
, inet_ntoa(vl_data
->vl_peer
),
10174 ck
->key_id
, ck
->auth_key
);
10182 static int config_write_ospf_redistribute(struct vty
*vty
, struct ospf
*ospf
)
10186 /* redistribute print. */
10187 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
10188 struct list
*red_list
;
10189 struct listnode
*node
;
10190 struct ospf_redist
*red
;
10192 red_list
= ospf
->redist
[type
];
10196 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
10197 vty_out(vty
, " redistribute %s",
10198 zebra_route_string(type
));
10200 vty_out(vty
, " %d", red
->instance
);
10202 if (red
->dmetric
.value
>= 0)
10203 vty_out(vty
, " metric %d", red
->dmetric
.value
);
10205 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
10206 vty_out(vty
, " metric-type 1");
10208 if (ROUTEMAP_NAME(red
))
10209 vty_out(vty
, " route-map %s",
10210 ROUTEMAP_NAME(red
));
10212 vty_out(vty
, "\n");
10219 static int config_write_ospf_default_metric(struct vty
*vty
, struct ospf
*ospf
)
10221 if (ospf
->default_metric
!= -1)
10222 vty_out(vty
, " default-metric %d\n", ospf
->default_metric
);
10226 static int config_write_ospf_distribute(struct vty
*vty
, struct ospf
*ospf
)
10229 struct ospf_redist
*red
;
10232 /* distribute-list print. */
10233 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
10234 if (DISTRIBUTE_NAME(ospf
, type
))
10235 vty_out(vty
, " distribute-list %s out %s\n",
10236 DISTRIBUTE_NAME(ospf
, type
),
10237 zebra_route_string(type
));
10239 /* default-information print. */
10240 if (ospf
->default_originate
!= DEFAULT_ORIGINATE_NONE
) {
10241 vty_out(vty
, " default-information originate");
10242 if (ospf
->default_originate
== DEFAULT_ORIGINATE_ALWAYS
)
10243 vty_out(vty
, " always");
10245 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
10247 if (red
->dmetric
.value
>= 0)
10248 vty_out(vty
, " metric %d",
10249 red
->dmetric
.value
);
10251 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
10252 vty_out(vty
, " metric-type 1");
10254 if (ROUTEMAP_NAME(red
))
10255 vty_out(vty
, " route-map %s",
10256 ROUTEMAP_NAME(red
));
10259 vty_out(vty
, "\n");
10266 static int config_write_ospf_distance(struct vty
*vty
, struct ospf
*ospf
)
10268 struct route_node
*rn
;
10269 struct ospf_distance
*odistance
;
10271 if (ospf
->distance_all
)
10272 vty_out(vty
, " distance %d\n", ospf
->distance_all
);
10274 if (ospf
->distance_intra
|| ospf
->distance_inter
10275 || ospf
->distance_external
) {
10276 vty_out(vty
, " distance ospf");
10278 if (ospf
->distance_intra
)
10279 vty_out(vty
, " intra-area %d", ospf
->distance_intra
);
10280 if (ospf
->distance_inter
)
10281 vty_out(vty
, " inter-area %d", ospf
->distance_inter
);
10282 if (ospf
->distance_external
)
10283 vty_out(vty
, " external %d", ospf
->distance_external
);
10285 vty_out(vty
, "\n");
10288 for (rn
= route_top(ospf
->distance_table
); rn
; rn
= route_next(rn
))
10289 if ((odistance
= rn
->info
) != NULL
) {
10290 vty_out(vty
, " distance %d %s/%d %s\n",
10291 odistance
->distance
, inet_ntoa(rn
->p
.u
.prefix4
),
10293 odistance
->access_list
? odistance
->access_list
10299 static int ospf_config_write_one(struct vty
*vty
, struct ospf
*ospf
)
10301 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
10302 struct interface
*ifp
;
10303 struct ospf_interface
*oi
;
10304 struct listnode
*node
= NULL
;
10307 /* `router ospf' print. */
10308 if (ospf
->instance
&& ospf
->name
) {
10309 vty_out(vty
, "router ospf %d vrf %s\n", ospf
->instance
,
10311 } else if (ospf
->instance
) {
10312 vty_out(vty
, "router ospf %d\n", ospf
->instance
);
10313 } else if (ospf
->name
) {
10314 vty_out(vty
, "router ospf vrf %s\n", ospf
->name
);
10316 vty_out(vty
, "router ospf\n");
10318 if (!ospf
->networks
) {
10323 /* Router ID print. */
10324 if (ospf
->router_id_static
.s_addr
!= 0)
10325 vty_out(vty
, " ospf router-id %s\n",
10326 inet_ntoa(ospf
->router_id_static
));
10328 /* ABR type print. */
10329 if (ospf
->abr_type
!= OSPF_ABR_DEFAULT
)
10330 vty_out(vty
, " ospf abr-type %s\n",
10331 ospf_abr_type_str
[ospf
->abr_type
]);
10333 /* log-adjacency-changes flag print. */
10334 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
10335 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
))
10336 vty_out(vty
, " log-adjacency-changes detail\n");
10337 else if (!DFLT_OSPF_LOG_ADJACENCY_CHANGES
)
10338 vty_out(vty
, " log-adjacency-changes\n");
10339 } else if (DFLT_OSPF_LOG_ADJACENCY_CHANGES
) {
10340 vty_out(vty
, " no log-adjacency-changes\n");
10343 /* RFC1583 compatibility flag print -- Compatible with CISCO
10345 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
))
10346 vty_out(vty
, " compatible rfc1583\n");
10348 /* auto-cost reference-bandwidth configuration. */
10349 if (ospf
->ref_bandwidth
!= OSPF_DEFAULT_REF_BANDWIDTH
) {
10351 "! Important: ensure reference bandwidth "
10352 "is consistent across all routers\n");
10353 vty_out(vty
, " auto-cost reference-bandwidth %d\n",
10354 ospf
->ref_bandwidth
);
10357 /* SPF timers print. */
10358 if (ospf
->spf_delay
!= OSPF_SPF_DELAY_DEFAULT
10359 || ospf
->spf_holdtime
!= OSPF_SPF_HOLDTIME_DEFAULT
10360 || ospf
->spf_max_holdtime
!= OSPF_SPF_MAX_HOLDTIME_DEFAULT
)
10361 vty_out(vty
, " timers throttle spf %d %d %d\n", ospf
->spf_delay
,
10362 ospf
->spf_holdtime
, ospf
->spf_max_holdtime
);
10364 /* LSA timers print. */
10365 if (ospf
->min_ls_interval
!= OSPF_MIN_LS_INTERVAL
)
10366 vty_out(vty
, " timers throttle lsa all %d\n",
10367 ospf
->min_ls_interval
);
10368 if (ospf
->min_ls_arrival
!= OSPF_MIN_LS_ARRIVAL
)
10369 vty_out(vty
, " timers lsa min-arrival %d\n",
10370 ospf
->min_ls_arrival
);
10372 /* Write multiplier print. */
10373 if (ospf
->write_oi_count
!= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
)
10374 vty_out(vty
, " ospf write-multiplier %d\n",
10375 ospf
->write_oi_count
);
10377 /* Max-metric router-lsa print */
10378 config_write_stub_router(vty
, ospf
);
10380 /* SPF refresh parameters print. */
10381 if (ospf
->lsa_refresh_interval
!= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
10382 vty_out(vty
, " refresh timer %d\n", ospf
->lsa_refresh_interval
);
10384 /* Redistribute information print. */
10385 config_write_ospf_redistribute(vty
, ospf
);
10387 /* passive-interface print. */
10388 if (ospf
->passive_interface_default
== OSPF_IF_PASSIVE
)
10389 vty_out(vty
, " passive-interface default\n");
10391 FOR_ALL_INTERFACES (vrf
, ifp
)
10392 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp
),
10394 && IF_DEF_PARAMS(ifp
)->passive_interface
10395 != ospf
->passive_interface_default
) {
10396 vty_out(vty
, " %spassive-interface %s\n",
10397 IF_DEF_PARAMS(ifp
)->passive_interface
? ""
10401 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
10402 if (!OSPF_IF_PARAM_CONFIGURED(oi
->params
, passive_interface
))
10404 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(oi
->ifp
),
10405 passive_interface
)) {
10406 if (oi
->params
->passive_interface
10407 == IF_DEF_PARAMS(oi
->ifp
)->passive_interface
)
10409 } else if (oi
->params
->passive_interface
10410 == ospf
->passive_interface_default
)
10413 vty_out(vty
, " %spassive-interface %s %s\n",
10414 oi
->params
->passive_interface
? "" : "no ",
10415 oi
->ifp
->name
, inet_ntoa(oi
->address
->u
.prefix4
));
10418 /* Network area print. */
10419 config_write_network_area(vty
, ospf
);
10421 /* Area config print. */
10422 config_write_ospf_area(vty
, ospf
);
10424 /* static neighbor print. */
10425 config_write_ospf_nbr_nbma(vty
, ospf
);
10427 /* Virtual-Link print. */
10428 config_write_virtual_link(vty
, ospf
);
10430 /* Default metric configuration. */
10431 config_write_ospf_default_metric(vty
, ospf
);
10433 /* Distribute-list and default-information print. */
10434 config_write_ospf_distribute(vty
, ospf
);
10436 /* Distance configuration. */
10437 config_write_ospf_distance(vty
, ospf
);
10439 ospf_opaque_config_write_router(vty
, ospf
);
10445 /* OSPF configuration write function. */
10446 static int ospf_config_write(struct vty
*vty
)
10449 struct listnode
*ospf_node
= NULL
;
10452 if (listcount(om
->ospf
) == 0)
10455 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, ospf_node
, ospf
)) {
10456 /* VRF Default check if it is running.
10457 * Upon daemon start, there could be default instance
10458 * in absence of 'router ospf'/oi_running is disabled. */
10459 if (ospf
->vrf_id
== VRF_DEFAULT
&& ospf
->oi_running
)
10460 write
+= ospf_config_write_one(vty
, ospf
);
10461 /* For Non-Default VRF simply display the configuration,
10462 * even if it is not oi_running. */
10463 else if (ospf
->vrf_id
!= VRF_DEFAULT
)
10464 write
+= ospf_config_write_one(vty
, ospf
);
10469 void ospf_vty_show_init(void)
10471 /* "show ip ospf" commands. */
10472 install_element(VIEW_NODE
, &show_ip_ospf_cmd
);
10474 install_element(VIEW_NODE
, &show_ip_ospf_instance_cmd
);
10476 /* "show ip ospf database" commands. */
10477 install_element(VIEW_NODE
, &show_ip_ospf_database_max_cmd
);
10479 install_element(VIEW_NODE
,
10480 &show_ip_ospf_instance_database_type_adv_router_cmd
);
10481 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_cmd
);
10482 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_max_cmd
);
10484 /* "show ip ospf interface" commands. */
10485 install_element(VIEW_NODE
, &show_ip_ospf_interface_cmd
);
10487 install_element(VIEW_NODE
, &show_ip_ospf_instance_interface_cmd
);
10488 /* "show ip ospf interface traffic */
10489 install_element(VIEW_NODE
, &show_ip_ospf_interface_traffic_cmd
);
10491 /* "show ip ospf neighbor" commands. */
10492 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_detail_cmd
);
10493 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_cmd
);
10494 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_id_cmd
);
10495 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_all_cmd
);
10496 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_cmd
);
10497 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_cmd
);
10498 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_all_cmd
);
10500 install_element(VIEW_NODE
,
10501 &show_ip_ospf_instance_neighbor_int_detail_cmd
);
10502 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_int_cmd
);
10503 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_id_cmd
);
10504 install_element(VIEW_NODE
,
10505 &show_ip_ospf_instance_neighbor_detail_all_cmd
);
10506 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_detail_cmd
);
10507 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_cmd
);
10508 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_all_cmd
);
10510 /* "show ip ospf route" commands. */
10511 install_element(VIEW_NODE
, &show_ip_ospf_route_cmd
);
10512 install_element(VIEW_NODE
, &show_ip_ospf_border_routers_cmd
);
10514 install_element(VIEW_NODE
, &show_ip_ospf_instance_route_cmd
);
10515 install_element(VIEW_NODE
, &show_ip_ospf_instance_border_routers_cmd
);
10517 /* "show ip ospf vrfs" commands. */
10518 install_element(VIEW_NODE
, &show_ip_ospf_vrfs_cmd
);
10522 /* ospfd's interface node. */
10523 static struct cmd_node interface_node
= {INTERFACE_NODE
, "%s(config-if)# ", 1};
10525 /* Initialization of OSPF interface. */
10526 static void ospf_vty_if_init(void)
10528 /* Install interface node. */
10529 install_node(&interface_node
, config_write_interface
);
10532 /* "ip ospf authentication" commands. */
10533 install_element(INTERFACE_NODE
, &ip_ospf_authentication_args_addr_cmd
);
10534 install_element(INTERFACE_NODE
, &ip_ospf_authentication_addr_cmd
);
10535 install_element(INTERFACE_NODE
,
10536 &no_ip_ospf_authentication_args_addr_cmd
);
10537 install_element(INTERFACE_NODE
, &no_ip_ospf_authentication_addr_cmd
);
10538 install_element(INTERFACE_NODE
, &ip_ospf_authentication_key_addr_cmd
);
10539 install_element(INTERFACE_NODE
,
10540 &no_ip_ospf_authentication_key_authkey_addr_cmd
);
10541 install_element(INTERFACE_NODE
,
10542 &no_ospf_authentication_key_authkey_addr_cmd
);
10544 /* "ip ospf message-digest-key" commands. */
10545 install_element(INTERFACE_NODE
, &ip_ospf_message_digest_key_cmd
);
10546 install_element(INTERFACE_NODE
, &no_ip_ospf_message_digest_key_cmd
);
10548 /* "ip ospf cost" commands. */
10549 install_element(INTERFACE_NODE
, &ip_ospf_cost_cmd
);
10550 install_element(INTERFACE_NODE
, &no_ip_ospf_cost_cmd
);
10552 /* "ip ospf mtu-ignore" commands. */
10553 install_element(INTERFACE_NODE
, &ip_ospf_mtu_ignore_addr_cmd
);
10554 install_element(INTERFACE_NODE
, &no_ip_ospf_mtu_ignore_addr_cmd
);
10556 /* "ip ospf dead-interval" commands. */
10557 install_element(INTERFACE_NODE
, &ip_ospf_dead_interval_cmd
);
10558 install_element(INTERFACE_NODE
,
10559 &ip_ospf_dead_interval_minimal_addr_cmd
);
10560 install_element(INTERFACE_NODE
, &no_ip_ospf_dead_interval_cmd
);
10562 /* "ip ospf hello-interval" commands. */
10563 install_element(INTERFACE_NODE
, &ip_ospf_hello_interval_cmd
);
10564 install_element(INTERFACE_NODE
, &no_ip_ospf_hello_interval_cmd
);
10566 /* "ip ospf network" commands. */
10567 install_element(INTERFACE_NODE
, &ip_ospf_network_cmd
);
10568 install_element(INTERFACE_NODE
, &no_ip_ospf_network_cmd
);
10570 /* "ip ospf priority" commands. */
10571 install_element(INTERFACE_NODE
, &ip_ospf_priority_cmd
);
10572 install_element(INTERFACE_NODE
, &no_ip_ospf_priority_cmd
);
10574 /* "ip ospf retransmit-interval" commands. */
10575 install_element(INTERFACE_NODE
, &ip_ospf_retransmit_interval_addr_cmd
);
10576 install_element(INTERFACE_NODE
,
10577 &no_ip_ospf_retransmit_interval_addr_cmd
);
10579 /* "ip ospf transmit-delay" commands. */
10580 install_element(INTERFACE_NODE
, &ip_ospf_transmit_delay_addr_cmd
);
10581 install_element(INTERFACE_NODE
, &no_ip_ospf_transmit_delay_addr_cmd
);
10583 /* "ip ospf area" commands. */
10584 install_element(INTERFACE_NODE
, &ip_ospf_area_cmd
);
10585 install_element(INTERFACE_NODE
, &no_ip_ospf_area_cmd
);
10587 /* These commands are compatibitliy for previous version. */
10588 install_element(INTERFACE_NODE
, &ospf_authentication_key_cmd
);
10589 install_element(INTERFACE_NODE
, &ospf_message_digest_key_cmd
);
10590 install_element(INTERFACE_NODE
, &no_ospf_message_digest_key_cmd
);
10591 install_element(INTERFACE_NODE
, &ospf_dead_interval_cmd
);
10592 install_element(INTERFACE_NODE
, &no_ospf_dead_interval_cmd
);
10593 install_element(INTERFACE_NODE
, &ospf_hello_interval_cmd
);
10594 install_element(INTERFACE_NODE
, &no_ospf_hello_interval_cmd
);
10595 install_element(INTERFACE_NODE
, &ospf_cost_cmd
);
10596 install_element(INTERFACE_NODE
, &no_ospf_cost_cmd
);
10597 install_element(INTERFACE_NODE
, &ospf_network_cmd
);
10598 install_element(INTERFACE_NODE
, &no_ospf_network_cmd
);
10599 install_element(INTERFACE_NODE
, &ospf_priority_cmd
);
10600 install_element(INTERFACE_NODE
, &no_ospf_priority_cmd
);
10601 install_element(INTERFACE_NODE
, &ospf_retransmit_interval_cmd
);
10602 install_element(INTERFACE_NODE
, &no_ospf_retransmit_interval_cmd
);
10603 install_element(INTERFACE_NODE
, &ospf_transmit_delay_cmd
);
10604 install_element(INTERFACE_NODE
, &no_ospf_transmit_delay_cmd
);
10607 static void ospf_vty_zebra_init(void)
10609 install_element(OSPF_NODE
, &ospf_redistribute_source_cmd
);
10610 install_element(OSPF_NODE
, &no_ospf_redistribute_source_cmd
);
10611 install_element(OSPF_NODE
, &ospf_redistribute_instance_source_cmd
);
10612 install_element(OSPF_NODE
, &no_ospf_redistribute_instance_source_cmd
);
10614 install_element(OSPF_NODE
, &ospf_distribute_list_out_cmd
);
10615 install_element(OSPF_NODE
, &no_ospf_distribute_list_out_cmd
);
10617 install_element(OSPF_NODE
, &ospf_default_information_originate_cmd
);
10618 install_element(OSPF_NODE
, &no_ospf_default_information_originate_cmd
);
10620 install_element(OSPF_NODE
, &ospf_default_metric_cmd
);
10621 install_element(OSPF_NODE
, &no_ospf_default_metric_cmd
);
10623 install_element(OSPF_NODE
, &ospf_distance_cmd
);
10624 install_element(OSPF_NODE
, &no_ospf_distance_cmd
);
10625 install_element(OSPF_NODE
, &no_ospf_distance_ospf_cmd
);
10626 install_element(OSPF_NODE
, &ospf_distance_ospf_cmd
);
10628 install_element (OSPF_NODE
, &ospf_distance_source_cmd
);
10629 install_element (OSPF_NODE
, &no_ospf_distance_source_cmd
);
10630 install_element (OSPF_NODE
, &ospf_distance_source_access_list_cmd
);
10631 install_element (OSPF_NODE
, &no_ospf_distance_source_access_list_cmd
);
10635 static struct cmd_node ospf_node
= {OSPF_NODE
, "%s(config-router)# ", 1};
10637 static void ospf_interface_clear(struct interface
*ifp
)
10639 if (!if_is_operative(ifp
))
10642 if (IS_DEBUG_OSPF(ism
, ISM_EVENTS
))
10643 zlog_debug("ISM[%s]: clear by reset", ifp
->name
);
10645 ospf_if_reset(ifp
);
10648 DEFUN (clear_ip_ospf_interface
,
10649 clear_ip_ospf_interface_cmd
,
10650 "clear ip ospf [vrf <NAME>] interface [IFNAME]",
10653 "OSPF information\n"
10655 "Interface information\n"
10656 "Interface name\n")
10658 int idx_ifname
= 0;
10660 struct interface
*ifp
;
10661 struct listnode
*node
;
10662 struct ospf
*ospf
= NULL
;
10663 char *vrf_name
= NULL
;
10664 vrf_id_t vrf_id
= VRF_DEFAULT
;
10665 struct vrf
*vrf
= NULL
;
10667 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
10668 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
10669 if (vrf_name
&& strmatch(vrf_name
, VRF_DEFAULT_NAME
))
10672 vrf
= vrf_lookup_by_name(vrf_name
);
10674 vrf_id
= vrf
->vrf_id
;
10676 if (!argv_find(argv
, argc
, "IFNAME", &idx_ifname
)) {
10677 /* Clear all the ospfv2 interfaces. */
10678 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
10679 if (vrf_id
!= ospf
->vrf_id
)
10682 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
10683 FOR_ALL_INTERFACES (vrf
, ifp
)
10684 ospf_interface_clear(ifp
);
10687 /* Interface name is specified. */
10688 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf_id
);
10690 vty_out(vty
, "No such interface name\n");
10692 ospf_interface_clear(ifp
);
10695 return CMD_SUCCESS
;
10698 void ospf_vty_clear_init(void)
10700 install_element(ENABLE_NODE
, &clear_ip_ospf_interface_cmd
);
10704 /* Install OSPF related vty commands. */
10705 void ospf_vty_init(void)
10707 /* Install ospf top node. */
10708 install_node(&ospf_node
, ospf_config_write
);
10710 /* "router ospf" commands. */
10711 install_element(CONFIG_NODE
, &router_ospf_cmd
);
10712 install_element(CONFIG_NODE
, &no_router_ospf_cmd
);
10715 install_default(OSPF_NODE
);
10717 /* "ospf router-id" commands. */
10718 install_element(OSPF_NODE
, &ospf_router_id_cmd
);
10719 install_element(OSPF_NODE
, &ospf_router_id_old_cmd
);
10720 install_element(OSPF_NODE
, &no_ospf_router_id_cmd
);
10722 /* "passive-interface" commands. */
10723 install_element(OSPF_NODE
, &ospf_passive_interface_addr_cmd
);
10724 install_element(OSPF_NODE
, &no_ospf_passive_interface_addr_cmd
);
10726 /* "ospf abr-type" commands. */
10727 install_element(OSPF_NODE
, &ospf_abr_type_cmd
);
10728 install_element(OSPF_NODE
, &no_ospf_abr_type_cmd
);
10730 /* "ospf log-adjacency-changes" commands. */
10731 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_cmd
);
10732 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_detail_cmd
);
10733 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_cmd
);
10734 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_detail_cmd
);
10736 /* "ospf rfc1583-compatible" commands. */
10737 install_element(OSPF_NODE
, &ospf_compatible_rfc1583_cmd
);
10738 install_element(OSPF_NODE
, &no_ospf_compatible_rfc1583_cmd
);
10739 install_element(OSPF_NODE
, &ospf_rfc1583_flag_cmd
);
10740 install_element(OSPF_NODE
, &no_ospf_rfc1583_flag_cmd
);
10742 /* "network area" commands. */
10743 install_element(OSPF_NODE
, &ospf_network_area_cmd
);
10744 install_element(OSPF_NODE
, &no_ospf_network_area_cmd
);
10746 /* "area authentication" commands. */
10747 install_element(OSPF_NODE
,
10748 &ospf_area_authentication_message_digest_cmd
);
10749 install_element(OSPF_NODE
, &ospf_area_authentication_cmd
);
10750 install_element(OSPF_NODE
, &no_ospf_area_authentication_cmd
);
10752 /* "area range" commands. */
10753 install_element(OSPF_NODE
, &ospf_area_range_cmd
);
10754 install_element(OSPF_NODE
, &ospf_area_range_cost_cmd
);
10755 install_element(OSPF_NODE
, &ospf_area_range_not_advertise_cmd
);
10756 install_element(OSPF_NODE
, &no_ospf_area_range_cmd
);
10757 install_element(OSPF_NODE
, &ospf_area_range_substitute_cmd
);
10758 install_element(OSPF_NODE
, &no_ospf_area_range_substitute_cmd
);
10760 /* "area virtual-link" commands. */
10761 install_element(OSPF_NODE
, &ospf_area_vlink_cmd
);
10762 install_element(OSPF_NODE
, &ospf_area_vlink_intervals_cmd
);
10763 install_element(OSPF_NODE
, &no_ospf_area_vlink_cmd
);
10764 install_element(OSPF_NODE
, &no_ospf_area_vlink_intervals_cmd
);
10767 /* "area stub" commands. */
10768 install_element(OSPF_NODE
, &ospf_area_stub_no_summary_cmd
);
10769 install_element(OSPF_NODE
, &ospf_area_stub_cmd
);
10770 install_element(OSPF_NODE
, &no_ospf_area_stub_no_summary_cmd
);
10771 install_element(OSPF_NODE
, &no_ospf_area_stub_cmd
);
10773 /* "area nssa" commands. */
10774 install_element(OSPF_NODE
, &ospf_area_nssa_cmd
);
10775 install_element(OSPF_NODE
, &ospf_area_nssa_translate_cmd
);
10776 install_element(OSPF_NODE
, &ospf_area_nssa_no_summary_cmd
);
10777 install_element(OSPF_NODE
, &no_ospf_area_nssa_no_summary_cmd
);
10778 install_element(OSPF_NODE
, &no_ospf_area_nssa_cmd
);
10780 install_element(OSPF_NODE
, &ospf_area_default_cost_cmd
);
10781 install_element(OSPF_NODE
, &no_ospf_area_default_cost_cmd
);
10783 install_element(OSPF_NODE
, &ospf_area_shortcut_cmd
);
10784 install_element(OSPF_NODE
, &no_ospf_area_shortcut_cmd
);
10786 install_element(OSPF_NODE
, &ospf_area_export_list_cmd
);
10787 install_element(OSPF_NODE
, &no_ospf_area_export_list_cmd
);
10789 install_element(OSPF_NODE
, &ospf_area_filter_list_cmd
);
10790 install_element(OSPF_NODE
, &no_ospf_area_filter_list_cmd
);
10792 install_element(OSPF_NODE
, &ospf_area_import_list_cmd
);
10793 install_element(OSPF_NODE
, &no_ospf_area_import_list_cmd
);
10795 /* SPF timer commands */
10796 install_element(OSPF_NODE
, &ospf_timers_throttle_spf_cmd
);
10797 install_element(OSPF_NODE
, &no_ospf_timers_throttle_spf_cmd
);
10799 /* LSA timers commands */
10800 install_element(OSPF_NODE
, &ospf_timers_min_ls_interval_cmd
);
10801 install_element(OSPF_NODE
, &no_ospf_timers_min_ls_interval_cmd
);
10802 install_element(OSPF_NODE
, &ospf_timers_lsa_min_arrival_cmd
);
10803 install_element(OSPF_NODE
, &no_ospf_timers_lsa_min_arrival_cmd
);
10805 /* refresh timer commands */
10806 install_element(OSPF_NODE
, &ospf_refresh_timer_cmd
);
10807 install_element(OSPF_NODE
, &no_ospf_refresh_timer_val_cmd
);
10809 /* max-metric commands */
10810 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_admin_cmd
);
10811 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_admin_cmd
);
10812 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_startup_cmd
);
10813 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_startup_cmd
);
10814 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_shutdown_cmd
);
10815 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_shutdown_cmd
);
10817 /* reference bandwidth commands */
10818 install_element(OSPF_NODE
, &ospf_auto_cost_reference_bandwidth_cmd
);
10819 install_element(OSPF_NODE
, &no_ospf_auto_cost_reference_bandwidth_cmd
);
10821 /* "neighbor" commands. */
10822 install_element(OSPF_NODE
, &ospf_neighbor_cmd
);
10823 install_element(OSPF_NODE
, &ospf_neighbor_poll_interval_cmd
);
10824 install_element(OSPF_NODE
, &no_ospf_neighbor_cmd
);
10825 install_element(OSPF_NODE
, &no_ospf_neighbor_poll_cmd
);
10827 /* write multiplier commands */
10828 install_element(OSPF_NODE
, &ospf_write_multiplier_cmd
);
10829 install_element(OSPF_NODE
, &write_multiplier_cmd
);
10830 install_element(OSPF_NODE
, &no_ospf_write_multiplier_cmd
);
10831 install_element(OSPF_NODE
, &no_write_multiplier_cmd
);
10833 /* Init interface related vty commands. */
10834 ospf_vty_if_init();
10836 /* Init zebra related vty commands. */
10837 ospf_vty_zebra_init();