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
;
460 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
462 if (strmatch(argv
[1]->text
, "default")) {
463 ospf_passive_interface_default(ospf
, OSPF_IF_PASSIVE
);
466 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
467 ifp
= if_get_by_name(argv
[1]->arg
, vrf
);
470 vty_out(vty
, "interface %s not found.\n", (char *)argv
[1]->arg
);
471 return CMD_WARNING_CONFIG_FAILED
;
474 params
= IF_DEF_PARAMS(ifp
);
477 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
480 "Please specify interface address by A.B.C.D\n");
481 return CMD_WARNING_CONFIG_FAILED
;
484 params
= ospf_get_if_params(ifp
, addr
);
485 ospf_if_update_params(ifp
, addr
);
486 ospf_passive_interface_update_addr(ospf
, ifp
, params
,
487 OSPF_IF_PASSIVE
, addr
);
490 ospf_passive_interface_update(ospf
, ifp
, params
, OSPF_IF_PASSIVE
);
492 /* XXX We should call ospf_if_set_multicast on exactly those
493 * interfaces for which the passive property changed. It is too much
494 * work to determine this set, so we do this for every interface.
495 * This is safe and reasonable because ospf_if_set_multicast uses a
496 * record of joined groups to avoid systems calls if the desired
497 * memberships match the current memership.
500 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
501 struct ospf_interface
*oi
= rn
->info
;
503 if (oi
&& (OSPF_IF_PARAM(oi
, passive_interface
)
505 ospf_if_set_multicast(oi
);
508 * XXX It is not clear what state transitions the interface needs to
509 * undergo when going from active to passive. Fixing this will
510 * require precise identification of interfaces having such a
517 DEFUN (no_ospf_passive_interface
,
518 no_ospf_passive_interface_addr_cmd
,
519 "no passive-interface <IFNAME [A.B.C.D]|default>",
521 "Allow routing updates on an interface\n"
524 "Allow routing updates on interfaces by default\n")
526 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
528 struct interface
*ifp
= NULL
;
529 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
530 struct ospf_if_params
*params
;
532 struct route_node
*rn
;
533 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
535 if (strmatch(argv
[2]->text
, "default")) {
536 ospf_passive_interface_default(ospf
, OSPF_IF_ACTIVE
);
540 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
541 ifp
= if_get_by_name(argv
[2]->arg
, vrf
);
544 vty_out(vty
, "interface %s not found.\n", (char *)argv
[2]->arg
);
545 return CMD_WARNING_CONFIG_FAILED
;
548 params
= IF_DEF_PARAMS(ifp
);
551 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
554 "Please specify interface address by A.B.C.D\n");
555 return CMD_WARNING_CONFIG_FAILED
;
558 params
= ospf_lookup_if_params(ifp
, addr
);
561 ospf_passive_interface_update_addr(ospf
, ifp
, params
,
562 OSPF_IF_ACTIVE
, addr
);
564 ospf_passive_interface_update(ospf
, ifp
, params
, OSPF_IF_ACTIVE
);
566 /* XXX We should call ospf_if_set_multicast on exactly those
567 * interfaces for which the passive property changed. It is too much
568 * work to determine this set, so we do this for every interface.
569 * This is safe and reasonable because ospf_if_set_multicast uses a
570 * record of joined groups to avoid systems calls if the desired
571 * memberships match the current memership.
573 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
574 struct ospf_interface
*oi
= rn
->info
;
577 && (OSPF_IF_PARAM(oi
, passive_interface
) == OSPF_IF_ACTIVE
))
578 ospf_if_set_multicast(oi
);
585 DEFUN (ospf_network_area
,
586 ospf_network_area_cmd
,
587 "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
588 "Enable routing on an IP network\n"
589 "OSPF network prefix\n"
590 "Set the OSPF area ID\n"
591 "OSPF area ID in IP address format\n"
592 "OSPF area ID as a decimal value\n")
594 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
595 int idx_ipv4_prefixlen
= 1;
596 int idx_ipv4_number
= 3;
597 struct prefix_ipv4 p
;
598 struct in_addr area_id
;
601 if (ospf
->instance
) {
603 "The network command is not supported in multi-instance ospf\n");
604 return CMD_WARNING_CONFIG_FAILED
;
607 if (ospf
->if_ospf_cli_count
> 0) {
609 "Please remove all ip ospf area x.x.x.x commands first.\n");
610 if (IS_DEBUG_OSPF_EVENT
)
612 "%s ospf vrf %s num of %u ip osp area x config",
614 ospf
->name
? ospf
->name
: "NIL",
615 ospf
->if_ospf_cli_count
);
616 return CMD_WARNING_CONFIG_FAILED
;
619 /* Get network prefix and Area ID. */
620 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
621 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
623 ret
= ospf_network_set(ospf
, &p
, area_id
, format
);
625 vty_out(vty
, "There is already same network statement.\n");
626 return CMD_WARNING_CONFIG_FAILED
;
632 DEFUN (no_ospf_network_area
,
633 no_ospf_network_area_cmd
,
634 "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
636 "Enable routing on an IP network\n"
637 "OSPF network prefix\n"
638 "Set the OSPF area ID\n"
639 "OSPF area ID in IP address format\n"
640 "OSPF area ID as a decimal value\n")
642 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
643 int idx_ipv4_prefixlen
= 2;
644 int idx_ipv4_number
= 4;
645 struct prefix_ipv4 p
;
646 struct in_addr area_id
;
649 if (ospf
->instance
) {
651 "The network command is not supported in multi-instance ospf\n");
652 return CMD_WARNING_CONFIG_FAILED
;
655 /* Get network prefix and Area ID. */
656 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
657 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
659 ret
= ospf_network_unset(ospf
, &p
, area_id
);
662 "Can't find specified network area configuration.\n");
663 return CMD_WARNING_CONFIG_FAILED
;
669 DEFUN (ospf_area_range
,
671 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]",
672 "OSPF area parameters\n"
673 "OSPF area ID in IP address format\n"
674 "OSPF area ID as a decimal value\n"
675 "Summarize routes matching address/mask (border routers only)\n"
676 "Area range prefix\n"
677 "Advertise this range (default)\n"
678 "User specified metric for this range\n"
679 "Advertised metric for this range\n")
681 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
682 int idx_ipv4_number
= 1;
683 int idx_ipv4_prefixlen
= 3;
685 struct prefix_ipv4 p
;
686 struct in_addr area_id
;
690 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
691 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
693 ospf_area_range_set(ospf
, area_id
, &p
, OSPF_AREA_RANGE_ADVERTISE
);
695 cost
= strtoul(argv
[idx_cost
]->arg
, NULL
, 10);
696 ospf_area_range_cost_set(ospf
, area_id
, &p
, cost
);
702 DEFUN (ospf_area_range_cost
,
703 ospf_area_range_cost_cmd
,
704 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M cost (0-16777215)",
705 "OSPF area parameters\n"
706 "OSPF area ID in IP address format\n"
707 "OSPF area ID as a decimal value\n"
708 "Summarize routes matching address/mask (border routers only)\n"
709 "Area range prefix\n"
710 "User specified metric for this range\n"
711 "Advertised metric for this range\n")
713 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
714 int idx_ipv4_number
= 1;
715 int idx_ipv4_prefixlen
= 3;
717 struct prefix_ipv4 p
;
718 struct in_addr area_id
;
722 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
723 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
725 ospf_area_range_set(ospf
, area_id
, &p
, OSPF_AREA_RANGE_ADVERTISE
);
726 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
729 cost
= strtoul(argv
[idx_cost
]->arg
, NULL
, 10);
730 ospf_area_range_cost_set(ospf
, area_id
, &p
, cost
);
735 DEFUN (ospf_area_range_not_advertise
,
736 ospf_area_range_not_advertise_cmd
,
737 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise",
738 "OSPF area parameters\n"
739 "OSPF area ID in IP address format\n"
740 "OSPF area ID as a decimal value\n"
741 "Summarize routes matching address/mask (border routers only)\n"
742 "Area range prefix\n"
743 "DoNotAdvertise this range\n")
745 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
746 int idx_ipv4_number
= 1;
747 int idx_ipv4_prefixlen
= 3;
748 struct prefix_ipv4 p
;
749 struct in_addr area_id
;
752 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
753 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
755 ospf_area_range_set(ospf
, area_id
, &p
, 0);
756 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
758 ospf_area_range_substitute_unset(ospf
, area_id
, &p
);
763 DEFUN (no_ospf_area_range
,
764 no_ospf_area_range_cmd
,
765 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]",
767 "OSPF area parameters\n"
768 "OSPF area ID in IP address format\n"
769 "OSPF area ID as a decimal value\n"
770 "Summarize routes matching address/mask (border routers only)\n"
771 "Area range prefix\n"
772 "User specified metric for this range\n"
773 "Advertised metric for this range\n"
774 "Advertise this range (default)\n"
775 "User specified metric for this range\n"
776 "Advertised metric for this range\n"
777 "DoNotAdvertise this range\n")
779 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
780 int idx_ipv4_number
= 2;
781 int idx_ipv4_prefixlen
= 4;
782 struct prefix_ipv4 p
;
783 struct in_addr area_id
;
786 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
787 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
789 ospf_area_range_unset(ospf
, area_id
, &p
);
794 DEFUN (ospf_area_range_substitute
,
795 ospf_area_range_substitute_cmd
,
796 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
797 "OSPF area parameters\n"
798 "OSPF area ID in IP address format\n"
799 "OSPF area ID as a decimal value\n"
800 "Summarize routes matching address/mask (border routers only)\n"
801 "Area range prefix\n"
802 "Announce area range as another prefix\n"
803 "Network prefix to be announced instead of range\n")
805 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
806 int idx_ipv4_number
= 1;
807 int idx_ipv4_prefixlen
= 3;
808 int idx_ipv4_prefixlen_2
= 5;
809 struct prefix_ipv4 p
, s
;
810 struct in_addr area_id
;
813 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
814 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
815 str2prefix_ipv4(argv
[idx_ipv4_prefixlen_2
]->arg
, &s
);
817 ospf_area_range_substitute_set(ospf
, area_id
, &p
, &s
);
818 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
824 DEFUN (no_ospf_area_range_substitute
,
825 no_ospf_area_range_substitute_cmd
,
826 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
828 "OSPF area parameters\n"
829 "OSPF area ID in IP address format\n"
830 "OSPF area ID as a decimal value\n"
831 "Summarize routes matching address/mask (border routers only)\n"
832 "Area range prefix\n"
833 "Announce area range as another prefix\n"
834 "Network prefix to be announced instead of range\n")
836 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
837 int idx_ipv4_number
= 2;
838 int idx_ipv4_prefixlen
= 4;
839 int idx_ipv4_prefixlen_2
= 6;
840 struct prefix_ipv4 p
, s
;
841 struct in_addr area_id
;
844 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
845 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
846 str2prefix_ipv4(argv
[idx_ipv4_prefixlen_2
]->arg
, &s
);
848 ospf_area_range_substitute_unset(ospf
, area_id
, &p
);
854 /* Command Handler Logic in VLink stuff is delicate!!
856 ALTER AT YOUR OWN RISK!!!!
858 Various dummy values are used to represent 'NoChange' state for
859 VLink configuration NOT being changed by a VLink command, and
860 special syntax is used within the command strings so that the
861 typed in command verbs can be seen in the configuration command
862 bacckend handler. This is to drastically reduce the verbeage
863 required to coe up with a reasonably compatible Cisco VLink command
865 - Matthew Grant <grantma@anathoth.gen.nz>
866 Wed, 21 Feb 2001 15:13:52 +1300
869 /* Configuration data for virtual links
871 struct ospf_vl_config_data
{
872 struct vty
*vty
; /* vty stuff */
873 struct in_addr area_id
; /* area ID from command line */
874 int area_id_fmt
; /* command line area ID format */
875 struct in_addr vl_peer
; /* command line vl_peer */
876 int auth_type
; /* Authehntication type, if given */
877 char *auth_key
; /* simple password if present */
878 int crypto_key_id
; /* Cryptographic key ID */
879 char *md5_key
; /* MD5 authentication key */
880 int hello_interval
; /* Obvious what these are... */
881 int retransmit_interval
;
886 static void ospf_vl_config_data_init(struct ospf_vl_config_data
*vl_config
,
889 memset(vl_config
, 0, sizeof(struct ospf_vl_config_data
));
890 vl_config
->auth_type
= OSPF_AUTH_CMD_NOTSEEN
;
891 vl_config
->vty
= vty
;
894 static struct ospf_vl_data
*
895 ospf_find_vl_data(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
897 struct ospf_area
*area
;
898 struct ospf_vl_data
*vl_data
;
900 struct in_addr area_id
;
902 vty
= vl_config
->vty
;
903 area_id
= vl_config
->area_id
;
905 if (area_id
.s_addr
== OSPF_AREA_BACKBONE
) {
907 "Configuring VLs over the backbone is not allowed\n");
910 area
= ospf_area_get(ospf
, area_id
);
911 ospf_area_display_format_set(ospf
, area
, vl_config
->area_id_fmt
);
913 if (area
->external_routing
!= OSPF_AREA_DEFAULT
) {
914 if (vl_config
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
915 vty_out(vty
, "Area %s is %s\n", inet_ntoa(area_id
),
916 area
->external_routing
== OSPF_AREA_NSSA
920 vty_out(vty
, "Area %ld is %s\n",
921 (unsigned long)ntohl(area_id
.s_addr
),
922 area
->external_routing
== OSPF_AREA_NSSA
928 if ((vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
->vl_peer
))
930 vl_data
= ospf_vl_data_new(area
, vl_config
->vl_peer
);
931 if (vl_data
->vl_oi
== NULL
) {
932 vl_data
->vl_oi
= ospf_vl_new(ospf
, vl_data
);
933 ospf_vl_add(ospf
, vl_data
);
934 ospf_spf_calculate_schedule(ospf
,
935 SPF_FLAG_CONFIG_CHANGE
);
942 static int ospf_vl_set_security(struct ospf_vl_data
*vl_data
,
943 struct ospf_vl_config_data
*vl_config
)
945 struct crypt_key
*ck
;
947 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
949 vty
= vl_config
->vty
;
951 if (vl_config
->auth_type
!= OSPF_AUTH_CMD_NOTSEEN
) {
952 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), auth_type
);
953 IF_DEF_PARAMS(ifp
)->auth_type
= vl_config
->auth_type
;
956 if (vl_config
->auth_key
) {
957 memset(IF_DEF_PARAMS(ifp
)->auth_simple
, 0,
958 OSPF_AUTH_SIMPLE_SIZE
+ 1);
959 strlcpy((char *)IF_DEF_PARAMS(ifp
)->auth_simple
,
961 sizeof(IF_DEF_PARAMS(ifp
)->auth_simple
));
962 } else if (vl_config
->md5_key
) {
963 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
964 vl_config
->crypto_key_id
)
966 vty_out(vty
, "OSPF: Key %d already exists\n",
967 vl_config
->crypto_key_id
);
970 ck
= ospf_crypt_key_new();
971 ck
->key_id
= vl_config
->crypto_key_id
;
972 memset(ck
->auth_key
, 0, OSPF_AUTH_MD5_SIZE
+ 1);
973 strlcpy((char *)ck
->auth_key
, vl_config
->md5_key
,
974 sizeof(ck
->auth_key
));
976 ospf_crypt_key_add(IF_DEF_PARAMS(ifp
)->auth_crypt
, ck
);
977 } else if (vl_config
->crypto_key_id
!= 0) {
980 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
981 vl_config
->crypto_key_id
)
983 vty_out(vty
, "OSPF: Key %d does not exist\n",
984 vl_config
->crypto_key_id
);
985 return CMD_WARNING_CONFIG_FAILED
;
988 ospf_crypt_key_delete(IF_DEF_PARAMS(ifp
)->auth_crypt
,
989 vl_config
->crypto_key_id
);
995 static int ospf_vl_set_timers(struct ospf_vl_data
*vl_data
,
996 struct ospf_vl_config_data
*vl_config
)
998 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
999 /* Virtual Link data initialised to defaults, so only set
1001 if (vl_config
->hello_interval
) {
1002 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_hello
);
1003 IF_DEF_PARAMS(ifp
)->v_hello
= vl_config
->hello_interval
;
1006 if (vl_config
->dead_interval
) {
1007 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_wait
);
1008 IF_DEF_PARAMS(ifp
)->v_wait
= vl_config
->dead_interval
;
1011 if (vl_config
->retransmit_interval
) {
1012 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), retransmit_interval
);
1013 IF_DEF_PARAMS(ifp
)->retransmit_interval
=
1014 vl_config
->retransmit_interval
;
1017 if (vl_config
->transmit_delay
) {
1018 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), transmit_delay
);
1019 IF_DEF_PARAMS(ifp
)->transmit_delay
= vl_config
->transmit_delay
;
1026 /* The business end of all of the above */
1027 static int ospf_vl_set(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
1029 struct ospf_vl_data
*vl_data
;
1032 vl_data
= ospf_find_vl_data(ospf
, vl_config
);
1034 return CMD_WARNING_CONFIG_FAILED
;
1036 /* Process this one first as it can have a fatal result, which can
1037 only logically occur if the virtual link exists already
1038 Thus a command error does not result in a change to the
1039 running configuration such as unexpectedly altered timer
1041 ret
= ospf_vl_set_security(vl_data
, vl_config
);
1042 if (ret
!= CMD_SUCCESS
)
1045 /* Set any time based parameters, these area already range checked */
1047 ret
= ospf_vl_set_timers(vl_data
, vl_config
);
1048 if (ret
!= CMD_SUCCESS
)
1054 /* This stuff exists to make specifying all the alias commands A LOT simpler
1056 #define VLINK_HELPSTR_IPADDR \
1057 "OSPF area parameters\n" \
1058 "OSPF area ID in IP address format\n" \
1059 "OSPF area ID as a decimal value\n" \
1060 "Configure a virtual link\n" \
1061 "Router ID of the remote ABR\n"
1063 #define VLINK_HELPSTR_AUTHTYPE_SIMPLE \
1064 "Enable authentication on this virtual link\n" \
1067 #define VLINK_HELPSTR_AUTHTYPE_ALL \
1068 VLINK_HELPSTR_AUTHTYPE_SIMPLE \
1069 "Use null authentication\n" \
1070 "Use message-digest authentication\n"
1072 #define VLINK_HELPSTR_TIME_PARAM \
1073 "Time between HELLO packets\n" \
1075 "Time between retransmitting lost link state advertisements\n" \
1077 "Link state transmit delay\n" \
1079 "Interval time after which a neighbor is declared down\n" \
1082 #define VLINK_HELPSTR_AUTH_SIMPLE \
1083 "Authentication password (key)\n" \
1084 "The OSPF password (key)\n"
1086 #define VLINK_HELPSTR_AUTH_MD5 \
1087 "Message digest authentication password (key)\n" \
1089 "Use MD5 algorithm\n" \
1090 "The OSPF password (key)\n"
1092 DEFUN (ospf_area_vlink
,
1093 ospf_area_vlink_cmd
,
1094 "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>]",
1095 VLINK_HELPSTR_IPADDR
1096 "Enable authentication on this virtual link\n"
1097 "Use message-digest authentication\n"
1098 "Use null authentication\n"
1099 VLINK_HELPSTR_AUTH_MD5
1100 VLINK_HELPSTR_AUTH_SIMPLE
)
1102 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1103 int idx_ipv4_number
= 1;
1105 struct ospf_vl_config_data vl_config
;
1106 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1107 char md5_key
[OSPF_AUTH_MD5_SIZE
+ 1];
1111 ospf_vl_config_data_init(&vl_config
, vty
);
1113 /* Read off first 2 parameters and check them */
1114 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1115 &vl_config
.area_id_fmt
);
1117 vty_out(vty
, "OSPF area ID is invalid\n");
1118 return CMD_WARNING_CONFIG_FAILED
;
1121 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1123 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1124 return CMD_WARNING_CONFIG_FAILED
;
1128 /* Thats all folks! - BUGS B. strikes again!!!*/
1130 return ospf_vl_set(ospf
, &vl_config
);
1133 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1134 /* authentication - this option can only occur
1135 at start of command line */
1136 vl_config
.auth_type
= OSPF_AUTH_SIMPLE
;
1139 if (argv_find(argv
, argc
, "message-digest", &idx
)) {
1140 /* authentication message-digest */
1141 vl_config
.auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
1142 } else if (argv_find(argv
, argc
, "null", &idx
)) {
1143 /* "authentication null" */
1144 vl_config
.auth_type
= OSPF_AUTH_NULL
;
1147 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1148 vl_config
.md5_key
= NULL
;
1149 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1150 if (vl_config
.crypto_key_id
< 0)
1151 return CMD_WARNING_CONFIG_FAILED
;
1153 strlcpy(md5_key
, argv
[idx
+ 3]->arg
, sizeof(md5_key
));
1154 vl_config
.md5_key
= md5_key
;
1157 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1158 strlcpy(auth_key
, argv
[idx
+ 1]->arg
, sizeof(auth_key
));
1159 vl_config
.auth_key
= auth_key
;
1162 /* Action configuration */
1164 return ospf_vl_set(ospf
, &vl_config
);
1167 DEFUN (no_ospf_area_vlink
,
1168 no_ospf_area_vlink_cmd
,
1169 "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>]",
1171 VLINK_HELPSTR_IPADDR
1172 "Enable authentication on this virtual link\n" \
1173 "Use message-digest authentication\n" \
1174 "Use null authentication\n" \
1175 VLINK_HELPSTR_AUTH_MD5
1176 VLINK_HELPSTR_AUTH_SIMPLE
)
1178 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1179 int idx_ipv4_number
= 2;
1181 struct ospf_area
*area
;
1182 struct ospf_vl_config_data vl_config
;
1183 struct ospf_vl_data
*vl_data
= NULL
;
1184 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1188 ospf_vl_config_data_init(&vl_config
, vty
);
1190 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1193 vty_out(vty
, "OSPF area ID is invalid\n");
1194 return CMD_WARNING_CONFIG_FAILED
;
1197 area
= ospf_area_lookup_by_area_id(ospf
, vl_config
.area_id
);
1199 vty_out(vty
, "Area does not exist\n");
1200 return CMD_WARNING_CONFIG_FAILED
;
1203 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1205 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1206 return CMD_WARNING_CONFIG_FAILED
;
1209 vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
.vl_peer
);
1211 vty_out(vty
, "Virtual link does not exist\n");
1212 return CMD_WARNING_CONFIG_FAILED
;
1216 /* Basic VLink no command */
1217 /* Thats all folks! - BUGS B. strikes again!!!*/
1218 ospf_vl_delete(ospf
, vl_data
);
1219 ospf_area_check_free(ospf
, vl_config
.area_id
);
1223 /* If we are down here, we are reseting parameters */
1224 /* Deal with other parameters */
1226 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1227 /* authentication - this option can only occur
1228 at start of command line */
1229 vl_config
.auth_type
= OSPF_AUTH_NOTSET
;
1232 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1233 vl_config
.md5_key
= NULL
;
1234 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1235 if (vl_config
.crypto_key_id
< 0)
1236 return CMD_WARNING_CONFIG_FAILED
;
1239 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1240 /* Reset authentication-key to 0 */
1241 memset(auth_key
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
1242 vl_config
.auth_key
= auth_key
;
1245 /* Action configuration */
1247 return ospf_vl_set(ospf
, &vl_config
);
1250 DEFUN (ospf_area_vlink_intervals
,
1251 ospf_area_vlink_intervals_cmd
,
1252 "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)}",
1253 VLINK_HELPSTR_IPADDR
1254 VLINK_HELPSTR_TIME_PARAM
)
1256 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1257 struct ospf_vl_config_data vl_config
;
1260 ospf_vl_config_data_init(&vl_config
, vty
);
1262 char *area_id
= argv
[1]->arg
;
1263 char *router_id
= argv
[3]->arg
;
1265 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1267 vty_out(vty
, "OSPF area ID is invalid\n");
1268 return CMD_WARNING_CONFIG_FAILED
;
1271 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1273 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1274 return CMD_WARNING_CONFIG_FAILED
;
1277 for (int idx
= 4; idx
< argc
; idx
++) {
1278 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1279 vl_config
.hello_interval
=
1280 strtol(argv
[++idx
]->arg
, NULL
, 10);
1281 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1282 vl_config
.retransmit_interval
=
1283 strtol(argv
[++idx
]->arg
, NULL
, 10);
1284 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1285 vl_config
.transmit_delay
=
1286 strtol(argv
[++idx
]->arg
, NULL
, 10);
1287 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1288 vl_config
.dead_interval
=
1289 strtol(argv
[++idx
]->arg
, NULL
, 10);
1292 /* Action configuration */
1293 return ospf_vl_set(ospf
, &vl_config
);
1296 DEFUN (no_ospf_area_vlink_intervals
,
1297 no_ospf_area_vlink_intervals_cmd
,
1298 "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)}",
1300 VLINK_HELPSTR_IPADDR
1301 VLINK_HELPSTR_TIME_PARAM
)
1303 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1304 struct ospf_vl_config_data vl_config
;
1307 ospf_vl_config_data_init(&vl_config
, vty
);
1309 char *area_id
= argv
[2]->arg
;
1310 char *router_id
= argv
[4]->arg
;
1312 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1314 vty_out(vty
, "OSPF area ID is invalid\n");
1315 return CMD_WARNING_CONFIG_FAILED
;
1318 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1320 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1321 return CMD_WARNING_CONFIG_FAILED
;
1324 for (int idx
= 5; idx
< argc
; idx
++) {
1325 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1326 vl_config
.hello_interval
= OSPF_HELLO_INTERVAL_DEFAULT
;
1327 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1328 vl_config
.retransmit_interval
=
1329 OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
1330 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1331 vl_config
.transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
1332 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1333 vl_config
.dead_interval
=
1334 OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
1337 /* Action configuration */
1338 return ospf_vl_set(ospf
, &vl_config
);
1341 DEFUN (ospf_area_shortcut
,
1342 ospf_area_shortcut_cmd
,
1343 "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>",
1344 "OSPF area parameters\n"
1345 "OSPF area ID in IP address format\n"
1346 "OSPF area ID as a decimal value\n"
1347 "Configure the area's shortcutting mode\n"
1348 "Set default shortcutting behavior\n"
1349 "Enable shortcutting through the area\n"
1350 "Disable shortcutting through the area\n")
1352 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1353 int idx_ipv4_number
= 1;
1354 int idx_enable_disable
= 3;
1355 struct ospf_area
*area
;
1356 struct in_addr area_id
;
1360 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1361 argv
[idx_ipv4_number
]->arg
);
1363 area
= ospf_area_get(ospf
, area_id
);
1364 ospf_area_display_format_set(ospf
, area
, format
);
1366 if (strncmp(argv
[idx_enable_disable
]->arg
, "de", 2) == 0)
1367 mode
= OSPF_SHORTCUT_DEFAULT
;
1368 else if (strncmp(argv
[idx_enable_disable
]->arg
, "di", 2) == 0)
1369 mode
= OSPF_SHORTCUT_DISABLE
;
1370 else if (strncmp(argv
[idx_enable_disable
]->arg
, "e", 1) == 0)
1371 mode
= OSPF_SHORTCUT_ENABLE
;
1373 return CMD_WARNING_CONFIG_FAILED
;
1375 ospf_area_shortcut_set(ospf
, area
, mode
);
1377 if (ospf
->abr_type
!= OSPF_ABR_SHORTCUT
)
1379 "Shortcut area setting will take effect "
1380 "only when the router is configured as Shortcut ABR\n");
1385 DEFUN (no_ospf_area_shortcut
,
1386 no_ospf_area_shortcut_cmd
,
1387 "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>",
1389 "OSPF area parameters\n"
1390 "OSPF area ID in IP address format\n"
1391 "OSPF area ID as a decimal value\n"
1392 "Deconfigure the area's shortcutting mode\n"
1393 "Deconfigure enabled shortcutting through the area\n"
1394 "Deconfigure disabled shortcutting through the area\n")
1396 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1397 int idx_ipv4_number
= 2;
1398 struct ospf_area
*area
;
1399 struct in_addr area_id
;
1402 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1403 argv
[idx_ipv4_number
]->arg
);
1405 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1409 ospf_area_shortcut_unset(ospf
, area
);
1415 DEFUN (ospf_area_stub
,
1417 "area <A.B.C.D|(0-4294967295)> stub",
1418 "OSPF area parameters\n"
1419 "OSPF area ID in IP address format\n"
1420 "OSPF area ID as a decimal value\n"
1421 "Configure OSPF area as stub\n")
1423 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1424 int idx_ipv4_number
= 1;
1425 struct in_addr area_id
;
1428 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1429 argv
[idx_ipv4_number
]->arg
);
1431 ret
= ospf_area_stub_set(ospf
, area_id
);
1432 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1436 "First deconfigure all virtual link through this area\n");
1437 return CMD_WARNING_CONFIG_FAILED
;
1440 ospf_area_no_summary_unset(ospf
, area_id
);
1445 DEFUN (ospf_area_stub_no_summary
,
1446 ospf_area_stub_no_summary_cmd
,
1447 "area <A.B.C.D|(0-4294967295)> stub no-summary",
1448 "OSPF stub parameters\n"
1449 "OSPF area ID in IP address format\n"
1450 "OSPF area ID as a decimal value\n"
1451 "Configure OSPF area as stub\n"
1452 "Do not inject inter-area routes into stub\n")
1454 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1455 int idx_ipv4_number
= 1;
1456 struct in_addr area_id
;
1459 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1460 argv
[idx_ipv4_number
]->arg
);
1462 ret
= ospf_area_stub_set(ospf
, area_id
);
1463 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1467 "%% Area cannot be stub as it contains a virtual link\n");
1468 return CMD_WARNING_CONFIG_FAILED
;
1471 ospf_area_no_summary_set(ospf
, area_id
);
1476 DEFUN (no_ospf_area_stub
,
1477 no_ospf_area_stub_cmd
,
1478 "no area <A.B.C.D|(0-4294967295)> stub",
1480 "OSPF area parameters\n"
1481 "OSPF area ID in IP address format\n"
1482 "OSPF area ID as a decimal value\n"
1483 "Configure OSPF area as stub\n")
1485 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1486 int idx_ipv4_number
= 2;
1487 struct in_addr area_id
;
1490 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1491 argv
[idx_ipv4_number
]->arg
);
1493 ospf_area_stub_unset(ospf
, area_id
);
1494 ospf_area_no_summary_unset(ospf
, area_id
);
1499 DEFUN (no_ospf_area_stub_no_summary
,
1500 no_ospf_area_stub_no_summary_cmd
,
1501 "no area <A.B.C.D|(0-4294967295)> stub no-summary",
1503 "OSPF area parameters\n"
1504 "OSPF area ID in IP address format\n"
1505 "OSPF area ID as a decimal value\n"
1506 "Configure OSPF area as stub\n"
1507 "Do not inject inter-area routes into area\n")
1509 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1510 int idx_ipv4_number
= 2;
1511 struct in_addr area_id
;
1514 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1515 argv
[idx_ipv4_number
]->arg
);
1516 ospf_area_no_summary_unset(ospf
, area_id
);
1521 static int ospf_area_nssa_cmd_handler(struct vty
*vty
, int argc
,
1522 struct cmd_token
**argv
, int cfg_nosum
,
1525 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1526 struct in_addr area_id
;
1529 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
, argv
[1]->arg
);
1531 ret
= ospf_area_nssa_set(ospf
, area_id
);
1532 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1536 "%% Area cannot be nssa as it contains a virtual link\n");
1537 return CMD_WARNING_CONFIG_FAILED
;
1541 if (strncmp(argv
[3]->text
, "translate-c", 11) == 0)
1542 ospf_area_nssa_translator_role_set(
1543 ospf
, area_id
, OSPF_NSSA_ROLE_CANDIDATE
);
1544 else if (strncmp(argv
[3]->text
, "translate-n", 11) == 0)
1545 ospf_area_nssa_translator_role_set(
1546 ospf
, area_id
, OSPF_NSSA_ROLE_NEVER
);
1547 else if (strncmp(argv
[3]->text
, "translate-a", 11) == 0)
1548 ospf_area_nssa_translator_role_set(
1549 ospf
, area_id
, OSPF_NSSA_ROLE_ALWAYS
);
1551 ospf_area_nssa_translator_role_set(ospf
, area_id
,
1552 OSPF_NSSA_ROLE_CANDIDATE
);
1557 ospf_area_no_summary_set(ospf
, area_id
);
1559 ospf_area_no_summary_unset(ospf
, area_id
);
1562 ospf_schedule_abr_task(ospf
);
1568 DEFUN (ospf_area_nssa_translate
,
1569 ospf_area_nssa_translate_cmd
,
1570 "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always>",
1571 "OSPF area parameters\n"
1572 "OSPF area ID in IP address format\n"
1573 "OSPF area ID as a decimal value\n"
1574 "Configure OSPF area as nssa\n"
1575 "Configure NSSA-ABR for translate election (default)\n"
1576 "Configure NSSA-ABR to never translate\n"
1577 "Configure NSSA-ABR to always translate\n")
1579 return ospf_area_nssa_cmd_handler(vty
, argc
, argv
, 0, 0);
1582 DEFUN (ospf_area_nssa
,
1584 "area <A.B.C.D|(0-4294967295)> nssa",
1585 "OSPF area parameters\n"
1586 "OSPF area ID in IP address format\n"
1587 "OSPF area ID as a decimal value\n"
1588 "Configure OSPF area as nssa\n")
1590 return ospf_area_nssa_cmd_handler(vty
, argc
, argv
, 0, 0);
1593 DEFUN (ospf_area_nssa_no_summary
,
1594 ospf_area_nssa_no_summary_cmd
,
1595 "area <A.B.C.D|(0-4294967295)> nssa no-summary",
1596 "OSPF area parameters\n"
1597 "OSPF area ID in IP address format\n"
1598 "OSPF area ID as a decimal value\n"
1599 "Configure OSPF area as nssa\n"
1600 "Do not inject inter-area routes into nssa\n")
1602 int idx_ipv4_number
= 1;
1603 struct in_addr area_id
;
1606 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1607 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1608 argv
[idx_ipv4_number
]->arg
);
1610 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1612 ospf_area_nssa_no_summary_set(ospf
, area_id
);
1614 ospf_schedule_abr_task(ospf
);
1619 DEFUN (no_ospf_area_nssa_no_summary
,
1620 no_ospf_area_nssa_no_summary_cmd
,
1621 "no area <A.B.C.D|(0-4294967295)> nssa no-summary",
1623 "OSPF area parameters\n"
1624 "OSPF area ID in IP address format\n"
1625 "OSPF area ID as a decimal value\n"
1626 "Configure OSPF area as nssa\n"
1627 "Do not inject inter-area routes into nssa\n")
1629 int idx_ipv4_number
= 2;
1630 struct in_addr area_id
;
1633 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1635 VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id
, format
,
1636 argv
[idx_ipv4_number
]->arg
);
1638 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1640 ospf_area_no_summary_unset(ospf
, area_id
);
1642 ospf_schedule_abr_task(ospf
);
1647 DEFUN (no_ospf_area_nssa
,
1648 no_ospf_area_nssa_cmd
,
1649 "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always>]",
1651 "OSPF area parameters\n"
1652 "OSPF area ID in IP address format\n"
1653 "OSPF area ID as a decimal value\n"
1654 "Configure OSPF area as nssa\n"
1655 "Configure NSSA-ABR for translate election (default)\n"
1656 "Configure NSSA-ABR to never translate\n"
1657 "Configure NSSA-ABR to always translate\n")
1659 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1660 int idx_ipv4_number
= 2;
1661 struct in_addr area_id
;
1664 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1665 argv
[idx_ipv4_number
]->arg
);
1667 ospf_area_nssa_unset(ospf
, area_id
, argc
);
1669 ospf_schedule_abr_task(ospf
);
1675 DEFUN (ospf_area_default_cost
,
1676 ospf_area_default_cost_cmd
,
1677 "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1678 "OSPF area parameters\n"
1679 "OSPF area ID in IP address format\n"
1680 "OSPF area ID as a decimal value\n"
1681 "Set the summary-default cost of a NSSA or stub area\n"
1682 "Stub's advertised default summary cost\n")
1684 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1685 int idx_ipv4_number
= 1;
1687 struct ospf_area
*area
;
1688 struct in_addr area_id
;
1691 struct prefix_ipv4 p
;
1693 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1694 argv
[idx_ipv4_number
]->arg
);
1695 cost
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1697 area
= ospf_area_get(ospf
, area_id
);
1698 ospf_area_display_format_set(ospf
, area
, format
);
1700 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1701 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1702 return CMD_WARNING_CONFIG_FAILED
;
1705 area
->default_cost
= cost
;
1708 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1710 if (IS_DEBUG_OSPF_EVENT
)
1712 "ospf_abr_announce_stub_defaults(): "
1713 "announcing 0.0.0.0/0 to area %s",
1714 inet_ntoa(area
->area_id
));
1715 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1720 DEFUN (no_ospf_area_default_cost
,
1721 no_ospf_area_default_cost_cmd
,
1722 "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1724 "OSPF area parameters\n"
1725 "OSPF area ID in IP address format\n"
1726 "OSPF area ID as a decimal value\n"
1727 "Set the summary-default cost of a NSSA or stub area\n"
1728 "Stub's advertised default summary cost\n")
1730 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1731 int idx_ipv4_number
= 2;
1732 struct ospf_area
*area
;
1733 struct in_addr area_id
;
1735 struct prefix_ipv4 p
;
1737 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1738 argv
[idx_ipv4_number
]->arg
);
1740 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1744 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1745 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1746 return CMD_WARNING_CONFIG_FAILED
;
1749 area
->default_cost
= 1;
1752 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1754 if (IS_DEBUG_OSPF_EVENT
)
1756 "ospf_abr_announce_stub_defaults(): "
1757 "announcing 0.0.0.0/0 to area %s",
1758 inet_ntoa(area
->area_id
));
1759 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1762 ospf_area_check_free(ospf
, area_id
);
1767 DEFUN (ospf_area_export_list
,
1768 ospf_area_export_list_cmd
,
1769 "area <A.B.C.D|(0-4294967295)> export-list NAME",
1770 "OSPF area parameters\n"
1771 "OSPF area ID in IP address format\n"
1772 "OSPF area ID as a decimal value\n"
1773 "Set the filter for networks announced to other areas\n"
1774 "Name of the access-list\n")
1776 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1777 int idx_ipv4_number
= 1;
1778 struct ospf_area
*area
;
1779 struct in_addr area_id
;
1782 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1784 area
= ospf_area_get(ospf
, area_id
);
1785 ospf_area_display_format_set(ospf
, area
, format
);
1786 ospf_area_export_list_set(ospf
, area
, argv
[3]->arg
);
1791 DEFUN (no_ospf_area_export_list
,
1792 no_ospf_area_export_list_cmd
,
1793 "no area <A.B.C.D|(0-4294967295)> export-list NAME",
1795 "OSPF area parameters\n"
1796 "OSPF area ID in IP address format\n"
1797 "OSPF area ID as a decimal value\n"
1798 "Unset the filter for networks announced to other areas\n"
1799 "Name of the access-list\n")
1801 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1802 int idx_ipv4_number
= 2;
1803 struct ospf_area
*area
;
1804 struct in_addr area_id
;
1807 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1809 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1813 ospf_area_export_list_unset(ospf
, area
);
1819 DEFUN (ospf_area_import_list
,
1820 ospf_area_import_list_cmd
,
1821 "area <A.B.C.D|(0-4294967295)> import-list NAME",
1822 "OSPF area parameters\n"
1823 "OSPF area ID in IP address format\n"
1824 "OSPF area ID as a decimal value\n"
1825 "Set the filter for networks from other areas announced to the specified one\n"
1826 "Name of the access-list\n")
1828 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1829 int idx_ipv4_number
= 1;
1830 struct ospf_area
*area
;
1831 struct in_addr area_id
;
1834 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1836 area
= ospf_area_get(ospf
, area_id
);
1837 ospf_area_display_format_set(ospf
, area
, format
);
1838 ospf_area_import_list_set(ospf
, area
, argv
[3]->arg
);
1843 DEFUN (no_ospf_area_import_list
,
1844 no_ospf_area_import_list_cmd
,
1845 "no area <A.B.C.D|(0-4294967295)> import-list NAME",
1847 "OSPF area parameters\n"
1848 "OSPF area ID in IP address format\n"
1849 "OSPF area ID as a decimal value\n"
1850 "Unset the filter for networks announced to other areas\n"
1851 "Name of the access-list\n")
1853 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1854 int idx_ipv4_number
= 2;
1855 struct ospf_area
*area
;
1856 struct in_addr area_id
;
1859 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1861 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1865 ospf_area_import_list_unset(ospf
, area
);
1870 DEFUN (ospf_area_filter_list
,
1871 ospf_area_filter_list_cmd
,
1872 "area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>",
1873 "OSPF area parameters\n"
1874 "OSPF area ID in IP address format\n"
1875 "OSPF area ID as a decimal value\n"
1876 "Filter networks between OSPF areas\n"
1877 "Filter prefixes between OSPF areas\n"
1878 "Name of an IP prefix-list\n"
1879 "Filter networks sent to this area\n"
1880 "Filter networks sent from this area\n")
1882 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1883 int idx_ipv4_number
= 1;
1886 struct ospf_area
*area
;
1887 struct in_addr area_id
;
1888 struct prefix_list
*plist
;
1891 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1893 area
= ospf_area_get(ospf
, area_id
);
1894 ospf_area_display_format_set(ospf
, area
, format
);
1895 plist
= prefix_list_lookup(AFI_IP
, argv
[idx_word
]->arg
);
1896 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1897 PREFIX_LIST_IN(area
) = plist
;
1898 if (PREFIX_NAME_IN(area
))
1899 free(PREFIX_NAME_IN(area
));
1901 PREFIX_NAME_IN(area
) = strdup(argv
[idx_word
]->arg
);
1902 ospf_schedule_abr_task(ospf
);
1904 PREFIX_LIST_OUT(area
) = plist
;
1905 if (PREFIX_NAME_OUT(area
))
1906 free(PREFIX_NAME_OUT(area
));
1908 PREFIX_NAME_OUT(area
) = strdup(argv
[idx_word
]->arg
);
1909 ospf_schedule_abr_task(ospf
);
1915 DEFUN (no_ospf_area_filter_list
,
1916 no_ospf_area_filter_list_cmd
,
1917 "no area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>",
1919 "OSPF area parameters\n"
1920 "OSPF area ID in IP address format\n"
1921 "OSPF area ID as a decimal value\n"
1922 "Filter networks between OSPF areas\n"
1923 "Filter prefixes between OSPF areas\n"
1924 "Name of an IP prefix-list\n"
1925 "Filter networks sent to this area\n"
1926 "Filter networks sent from this area\n")
1928 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1929 int idx_ipv4_number
= 2;
1932 struct ospf_area
*area
;
1933 struct in_addr area_id
;
1936 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1938 if ((area
= ospf_area_lookup_by_area_id(ospf
, area_id
)) == NULL
)
1941 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1942 if (PREFIX_NAME_IN(area
))
1943 if (strcmp(PREFIX_NAME_IN(area
), argv
[idx_word
]->arg
)
1947 PREFIX_LIST_IN(area
) = NULL
;
1948 if (PREFIX_NAME_IN(area
))
1949 free(PREFIX_NAME_IN(area
));
1951 PREFIX_NAME_IN(area
) = NULL
;
1953 ospf_schedule_abr_task(ospf
);
1955 if (PREFIX_NAME_OUT(area
))
1956 if (strcmp(PREFIX_NAME_OUT(area
), argv
[idx_word
]->arg
)
1960 PREFIX_LIST_OUT(area
) = NULL
;
1961 if (PREFIX_NAME_OUT(area
))
1962 free(PREFIX_NAME_OUT(area
));
1964 PREFIX_NAME_OUT(area
) = NULL
;
1966 ospf_schedule_abr_task(ospf
);
1973 DEFUN (ospf_area_authentication_message_digest
,
1974 ospf_area_authentication_message_digest_cmd
,
1975 "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest",
1977 "OSPF area parameters\n"
1978 "OSPF area ID in IP address format\n"
1979 "OSPF area ID as a decimal value\n"
1980 "Enable authentication\n"
1981 "Use message-digest authentication\n")
1983 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1985 struct ospf_area
*area
;
1986 struct in_addr area_id
;
1989 argv_find(argv
, argc
, "area", &idx
);
1990 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx
+ 1]->arg
);
1992 area
= ospf_area_get(ospf
, area_id
);
1993 ospf_area_display_format_set(ospf
, area
, format
);
1994 area
->auth_type
= strmatch(argv
[0]->text
, "no")
1996 : OSPF_AUTH_CRYPTOGRAPHIC
;
2001 DEFUN (ospf_area_authentication
,
2002 ospf_area_authentication_cmd
,
2003 "area <A.B.C.D|(0-4294967295)> authentication",
2004 "OSPF area parameters\n"
2005 "OSPF area ID in IP address format\n"
2006 "OSPF area ID as a decimal value\n"
2007 "Enable authentication\n")
2009 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2010 int idx_ipv4_number
= 1;
2011 struct ospf_area
*area
;
2012 struct in_addr area_id
;
2015 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
2017 area
= ospf_area_get(ospf
, area_id
);
2018 ospf_area_display_format_set(ospf
, area
, format
);
2019 area
->auth_type
= OSPF_AUTH_SIMPLE
;
2024 DEFUN (no_ospf_area_authentication
,
2025 no_ospf_area_authentication_cmd
,
2026 "no area <A.B.C.D|(0-4294967295)> authentication",
2028 "OSPF area parameters\n"
2029 "OSPF area ID in IP address format\n"
2030 "OSPF area ID as a decimal value\n"
2031 "Enable authentication\n")
2033 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2034 int idx_ipv4_number
= 2;
2035 struct ospf_area
*area
;
2036 struct in_addr area_id
;
2039 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
2041 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
2045 area
->auth_type
= OSPF_AUTH_NULL
;
2047 ospf_area_check_free(ospf
, area_id
);
2053 DEFUN (ospf_abr_type
,
2055 "ospf abr-type <cisco|ibm|shortcut|standard>",
2056 "OSPF specific commands\n"
2057 "Set OSPF ABR type\n"
2058 "Alternative ABR, cisco implementation\n"
2059 "Alternative ABR, IBM implementation\n"
2061 "Standard behavior (RFC2328)\n")
2063 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2065 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2067 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2068 abr_type
= OSPF_ABR_CISCO
;
2069 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2070 abr_type
= OSPF_ABR_IBM
;
2071 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2072 abr_type
= OSPF_ABR_SHORTCUT
;
2073 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2074 abr_type
= OSPF_ABR_STAND
;
2076 return CMD_WARNING_CONFIG_FAILED
;
2078 /* If ABR type value is changed, schedule ABR task. */
2079 if (ospf
->abr_type
!= abr_type
) {
2080 ospf
->abr_type
= abr_type
;
2081 ospf_schedule_abr_task(ospf
);
2087 DEFUN (no_ospf_abr_type
,
2088 no_ospf_abr_type_cmd
,
2089 "no ospf abr-type <cisco|ibm|shortcut|standard>",
2091 "OSPF specific commands\n"
2092 "Set OSPF ABR type\n"
2093 "Alternative ABR, cisco implementation\n"
2094 "Alternative ABR, IBM implementation\n"
2098 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2100 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2102 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2103 abr_type
= OSPF_ABR_CISCO
;
2104 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2105 abr_type
= OSPF_ABR_IBM
;
2106 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2107 abr_type
= OSPF_ABR_SHORTCUT
;
2108 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2109 abr_type
= OSPF_ABR_STAND
;
2111 return CMD_WARNING_CONFIG_FAILED
;
2113 /* If ABR type value is changed, schedule ABR task. */
2114 if (ospf
->abr_type
== abr_type
) {
2115 ospf
->abr_type
= OSPF_ABR_DEFAULT
;
2116 ospf_schedule_abr_task(ospf
);
2122 DEFUN (ospf_log_adjacency_changes
,
2123 ospf_log_adjacency_changes_cmd
,
2124 "log-adjacency-changes",
2125 "Log changes in adjacency state\n")
2127 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2129 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2130 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2134 DEFUN (ospf_log_adjacency_changes_detail
,
2135 ospf_log_adjacency_changes_detail_cmd
,
2136 "log-adjacency-changes detail",
2137 "Log changes in adjacency state\n"
2138 "Log all state changes\n")
2140 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2142 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2143 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2147 DEFUN (no_ospf_log_adjacency_changes
,
2148 no_ospf_log_adjacency_changes_cmd
,
2149 "no log-adjacency-changes",
2151 "Log changes in adjacency state\n")
2153 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2155 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2156 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2160 DEFUN (no_ospf_log_adjacency_changes_detail
,
2161 no_ospf_log_adjacency_changes_detail_cmd
,
2162 "no log-adjacency-changes detail",
2164 "Log changes in adjacency state\n"
2165 "Log all state changes\n")
2167 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2169 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2173 DEFUN (ospf_compatible_rfc1583
,
2174 ospf_compatible_rfc1583_cmd
,
2175 "compatible rfc1583",
2176 "OSPF compatibility list\n"
2177 "compatible with RFC 1583\n")
2179 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2181 if (!CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2182 SET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2183 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2188 DEFUN (no_ospf_compatible_rfc1583
,
2189 no_ospf_compatible_rfc1583_cmd
,
2190 "no compatible rfc1583",
2192 "OSPF compatibility list\n"
2193 "compatible with RFC 1583\n")
2195 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2197 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2198 UNSET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2199 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2204 ALIAS(ospf_compatible_rfc1583
, ospf_rfc1583_flag_cmd
,
2205 "ospf rfc1583compatibility",
2206 "OSPF specific commands\n"
2207 "Enable the RFC1583Compatibility flag\n")
2209 ALIAS(no_ospf_compatible_rfc1583
, no_ospf_rfc1583_flag_cmd
,
2210 "no ospf rfc1583compatibility", NO_STR
2211 "OSPF specific commands\n"
2212 "Disable the RFC1583Compatibility flag\n")
2214 static int ospf_timers_spf_set(struct vty
*vty
, unsigned int delay
,
2215 unsigned int hold
, unsigned int max
)
2217 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2219 ospf
->spf_delay
= delay
;
2220 ospf
->spf_holdtime
= hold
;
2221 ospf
->spf_max_holdtime
= max
;
2226 DEFUN (ospf_timers_min_ls_interval
,
2227 ospf_timers_min_ls_interval_cmd
,
2228 "timers throttle lsa all (0-5000)",
2229 "Adjust routing timers\n"
2230 "Throttling adaptive timer\n"
2231 "LSA delay between transmissions\n"
2233 "Delay (msec) between sending LSAs\n")
2235 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2237 unsigned int interval
;
2240 vty_out(vty
, "Insufficient arguments\n");
2241 return CMD_WARNING_CONFIG_FAILED
;
2244 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2246 ospf
->min_ls_interval
= interval
;
2251 DEFUN (no_ospf_timers_min_ls_interval
,
2252 no_ospf_timers_min_ls_interval_cmd
,
2253 "no timers throttle lsa all [(0-5000)]",
2255 "Adjust routing timers\n"
2256 "Throttling adaptive timer\n"
2257 "LSA delay between transmissions\n"
2259 "Delay (msec) between sending LSAs\n")
2261 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2262 ospf
->min_ls_interval
= OSPF_MIN_LS_INTERVAL
;
2267 DEFUN (ospf_timers_throttle_spf
,
2268 ospf_timers_throttle_spf_cmd
,
2269 "timers throttle spf (0-600000) (0-600000) (0-600000)",
2270 "Adjust routing timers\n"
2271 "Throttling adaptive timer\n"
2273 "Delay (msec) from first change received till SPF calculation\n"
2274 "Initial hold time (msec) between consecutive SPF calculations\n"
2275 "Maximum hold time (msec)\n")
2278 int idx_number_2
= 4;
2279 int idx_number_3
= 5;
2280 unsigned int delay
, hold
, max
;
2283 vty_out(vty
, "Insufficient arguments\n");
2284 return CMD_WARNING_CONFIG_FAILED
;
2287 delay
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2288 hold
= strtoul(argv
[idx_number_2
]->arg
, NULL
, 10);
2289 max
= strtoul(argv
[idx_number_3
]->arg
, NULL
, 10);
2291 return ospf_timers_spf_set(vty
, delay
, hold
, max
);
2294 DEFUN (no_ospf_timers_throttle_spf
,
2295 no_ospf_timers_throttle_spf_cmd
,
2296 "no timers throttle spf [(0-600000)(0-600000)(0-600000)]",
2298 "Adjust routing timers\n"
2299 "Throttling adaptive timer\n"
2301 "Delay (msec) from first change received till SPF calculation\n"
2302 "Initial hold time (msec) between consecutive SPF calculations\n"
2303 "Maximum hold time (msec)\n")
2305 return ospf_timers_spf_set(vty
, OSPF_SPF_DELAY_DEFAULT
,
2306 OSPF_SPF_HOLDTIME_DEFAULT
,
2307 OSPF_SPF_MAX_HOLDTIME_DEFAULT
);
2311 DEFUN (ospf_timers_lsa_min_arrival
,
2312 ospf_timers_lsa_min_arrival_cmd
,
2313 "timers lsa min-arrival (0-600000)",
2314 "Adjust routing timers\n"
2316 "Minimum delay in receiving new version of a LSA\n"
2317 "Delay in milliseconds\n")
2319 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2320 ospf
->min_ls_arrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2324 DEFUN (no_ospf_timers_lsa_min_arrival
,
2325 no_ospf_timers_lsa_min_arrival_cmd
,
2326 "no timers lsa min-arrival [(0-600000)]",
2328 "Adjust routing timers\n"
2330 "Minimum delay in receiving new version of a LSA\n"
2331 "Delay in milliseconds\n")
2333 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2334 unsigned int minarrival
;
2337 minarrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2339 if (ospf
->min_ls_arrival
!= minarrival
2340 || minarrival
== OSPF_MIN_LS_ARRIVAL
)
2344 ospf
->min_ls_arrival
= OSPF_MIN_LS_ARRIVAL
;
2349 DEFUN (ospf_neighbor
,
2351 "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]",
2353 "Neighbor IP address\n"
2354 "Neighbor Priority\n"
2356 "Dead Neighbor Polling interval\n"
2359 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2363 struct in_addr nbr_addr
;
2364 unsigned int priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2365 unsigned int interval
= OSPF_POLL_INTERVAL_DEFAULT
;
2367 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2368 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2369 return CMD_WARNING_CONFIG_FAILED
;
2373 priority
= strtoul(argv
[idx_pri
]->arg
, NULL
, 10);
2376 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2378 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2381 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2384 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2389 DEFUN (ospf_neighbor_poll_interval
,
2390 ospf_neighbor_poll_interval_cmd
,
2391 "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2393 "Neighbor IP address\n"
2394 "Dead Neighbor Polling interval\n"
2396 "OSPF priority of non-broadcast neighbor\n"
2399 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2403 struct in_addr nbr_addr
;
2404 unsigned int priority
;
2405 unsigned int interval
;
2407 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2408 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2409 return CMD_WARNING_CONFIG_FAILED
;
2412 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2414 priority
= argc
> 4 ? strtoul(argv
[idx_pri
]->arg
, NULL
, 10)
2415 : OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2417 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2418 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2421 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2426 DEFUN (no_ospf_neighbor
,
2427 no_ospf_neighbor_cmd
,
2428 "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]",
2431 "Neighbor IP address\n"
2432 "Neighbor Priority\n"
2434 "Dead Neighbor Polling interval\n"
2437 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2439 struct in_addr nbr_addr
;
2441 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2442 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2443 return CMD_WARNING_CONFIG_FAILED
;
2446 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2451 DEFUN (no_ospf_neighbor_poll
,
2452 no_ospf_neighbor_poll_cmd
,
2453 "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2456 "Neighbor IP address\n"
2457 "Dead Neighbor Polling interval\n"
2459 "Neighbor Priority\n"
2462 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2464 struct in_addr nbr_addr
;
2466 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2467 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2468 return CMD_WARNING_CONFIG_FAILED
;
2471 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2476 DEFUN (ospf_refresh_timer
,
2477 ospf_refresh_timer_cmd
,
2478 "refresh timer (10-1800)",
2479 "Adjust refresh parameters\n"
2480 "Set refresh timer\n"
2481 "Timer value in seconds\n")
2483 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2485 unsigned int interval
;
2487 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2488 interval
= (interval
/ OSPF_LSA_REFRESHER_GRANULARITY
)
2489 * OSPF_LSA_REFRESHER_GRANULARITY
;
2491 ospf_timers_refresh_set(ospf
, interval
);
2496 DEFUN (no_ospf_refresh_timer
,
2497 no_ospf_refresh_timer_val_cmd
,
2498 "no refresh timer [(10-1800)]",
2500 "Adjust refresh parameters\n"
2501 "Unset refresh timer\n"
2502 "Timer value in seconds\n")
2504 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2506 unsigned int interval
;
2509 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2511 if (ospf
->lsa_refresh_interval
!= interval
2512 || interval
== OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
2516 ospf_timers_refresh_unset(ospf
);
2522 DEFUN (ospf_auto_cost_reference_bandwidth
,
2523 ospf_auto_cost_reference_bandwidth_cmd
,
2524 "auto-cost reference-bandwidth (1-4294967)",
2525 "Calculate OSPF interface cost according to bandwidth\n"
2526 "Use reference bandwidth method to assign OSPF cost\n"
2527 "The reference bandwidth in terms of Mbits per second\n")
2529 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2530 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2533 struct interface
*ifp
;
2535 refbw
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2536 if (refbw
< 1 || refbw
> 4294967) {
2537 vty_out(vty
, "reference-bandwidth value is invalid\n");
2538 return CMD_WARNING_CONFIG_FAILED
;
2541 /* If reference bandwidth is changed. */
2542 if ((refbw
) == ospf
->ref_bandwidth
)
2545 ospf
->ref_bandwidth
= refbw
;
2546 FOR_ALL_INTERFACES (vrf
, ifp
)
2547 ospf_if_recalculate_output_cost(ifp
);
2552 DEFUN (no_ospf_auto_cost_reference_bandwidth
,
2553 no_ospf_auto_cost_reference_bandwidth_cmd
,
2554 "no auto-cost reference-bandwidth [(1-4294967)]",
2556 "Calculate OSPF interface cost according to bandwidth\n"
2557 "Use reference bandwidth method to assign OSPF cost\n"
2558 "The reference bandwidth in terms of Mbits per second\n")
2560 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2561 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2562 struct interface
*ifp
;
2564 if (ospf
->ref_bandwidth
== OSPF_DEFAULT_REF_BANDWIDTH
)
2567 ospf
->ref_bandwidth
= OSPF_DEFAULT_REF_BANDWIDTH
;
2568 vty_out(vty
, "%% OSPF: Reference bandwidth is changed.\n");
2570 " Please ensure reference bandwidth is consistent across all routers\n");
2572 FOR_ALL_INTERFACES (vrf
, ifp
)
2573 ospf_if_recalculate_output_cost(ifp
);
2578 DEFUN (ospf_write_multiplier
,
2579 ospf_write_multiplier_cmd
,
2580 "ospf write-multiplier (1-100)",
2581 "OSPF specific commands\n"
2582 "Write multiplier\n"
2583 "Maximum number of interface serviced per write\n")
2585 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2587 uint32_t write_oi_count
;
2594 write_oi_count
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2595 if (write_oi_count
< 1 || write_oi_count
> 100) {
2596 vty_out(vty
, "write-multiplier value is invalid\n");
2597 return CMD_WARNING_CONFIG_FAILED
;
2600 ospf
->write_oi_count
= write_oi_count
;
2604 ALIAS(ospf_write_multiplier
, write_multiplier_cmd
, "write-multiplier (1-100)",
2605 "Write multiplier\n"
2606 "Maximum number of interface serviced per write\n")
2608 DEFUN (no_ospf_write_multiplier
,
2609 no_ospf_write_multiplier_cmd
,
2610 "no ospf write-multiplier (1-100)",
2612 "OSPF specific commands\n"
2613 "Write multiplier\n"
2614 "Maximum number of interface serviced per write\n")
2616 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2618 ospf
->write_oi_count
= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
;
2622 ALIAS(no_ospf_write_multiplier
, no_write_multiplier_cmd
,
2623 "no write-multiplier (1-100)", NO_STR
2624 "Write multiplier\n"
2625 "Maximum number of interface serviced per write\n")
2627 const char *ospf_abr_type_descr_str
[] = {"Unknown", "Standard (RFC2328)",
2628 "Alternative IBM", "Alternative Cisco",
2629 "Alternative Shortcut"};
2631 const char *ospf_shortcut_mode_descr_str
[] = {"Default", "Enabled", "Disabled"};
2633 static void show_ip_ospf_area(struct vty
*vty
, struct ospf_area
*area
,
2634 json_object
*json_areas
, bool use_json
)
2636 json_object
*json_area
= NULL
;
2639 json_area
= json_object_new_object();
2643 vty_out(vty
, " Area ID: %s", inet_ntoa(area
->area_id
));
2645 /* Show Area type/mode. */
2646 if (OSPF_IS_AREA_BACKBONE(area
)) {
2648 json_object_boolean_true_add(json_area
, "backbone");
2650 vty_out(vty
, " (Backbone)\n");
2653 if (area
->external_routing
== OSPF_AREA_STUB
) {
2654 if (area
->no_summary
)
2655 json_object_boolean_true_add(
2656 json_area
, "stubNoSummary");
2657 if (area
->shortcut_configured
)
2658 json_object_boolean_true_add(
2659 json_area
, "stubShortcut");
2660 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
2661 if (area
->no_summary
)
2662 json_object_boolean_true_add(
2663 json_area
, "nssaNoSummary");
2664 if (area
->shortcut_configured
)
2665 json_object_boolean_true_add(
2666 json_area
, "nssaShortcut");
2669 json_object_string_add(
2670 json_area
, "shortcuttingMode",
2671 ospf_shortcut_mode_descr_str
2672 [area
->shortcut_configured
]);
2673 if (area
->shortcut_capability
)
2674 json_object_boolean_true_add(json_area
,
2677 if (area
->external_routing
== OSPF_AREA_STUB
)
2678 vty_out(vty
, " (Stub%s%s)",
2679 area
->no_summary
? ", no summary" : "",
2680 area
->shortcut_configured
? "; " : "");
2681 else if (area
->external_routing
== OSPF_AREA_NSSA
)
2682 vty_out(vty
, " (NSSA%s%s)",
2683 area
->no_summary
? ", no summary" : "",
2684 area
->shortcut_configured
? "; " : "");
2687 vty_out(vty
, " Shortcutting mode: %s",
2688 ospf_shortcut_mode_descr_str
2689 [area
->shortcut_configured
]);
2690 vty_out(vty
, ", S-bit consensus: %s\n",
2691 area
->shortcut_capability
? "ok" : "no");
2695 /* Show number of interfaces */
2697 json_object_int_add(json_area
, "areaIfTotalCounter",
2698 listcount(area
->oiflist
));
2699 json_object_int_add(json_area
, "areaIfActiveCounter",
2703 " Number of interfaces in this area: Total: %d, "
2705 listcount(area
->oiflist
), area
->act_ints
);
2707 if (area
->external_routing
== OSPF_AREA_NSSA
) {
2709 json_object_boolean_true_add(json_area
, "nssa");
2710 if (!IS_OSPF_ABR(area
->ospf
))
2711 json_object_boolean_false_add(json_area
, "abr");
2712 else if (area
->NSSATranslatorState
) {
2713 json_object_boolean_true_add(json_area
, "abr");
2714 if (area
->NSSATranslatorRole
2715 == OSPF_NSSA_ROLE_CANDIDATE
)
2716 json_object_boolean_true_add(
2718 "nssaTranslatorElected");
2719 else if (area
->NSSATranslatorRole
2720 == OSPF_NSSA_ROLE_ALWAYS
)
2721 json_object_boolean_true_add(
2723 "nssaTranslatorAlways");
2725 json_object_boolean_true_add(json_area
, "abr");
2726 if (area
->NSSATranslatorRole
2727 == OSPF_NSSA_ROLE_CANDIDATE
)
2728 json_object_boolean_false_add(
2730 "nssaTranslatorElected");
2732 json_object_boolean_true_add(
2734 "nssaTranslatorNever");
2738 " It is an NSSA configuration. \n Elected NSSA/ABR performs type-7/type-5 LSA translation. \n");
2739 if (!IS_OSPF_ABR(area
->ospf
))
2741 " It is not ABR, therefore not Translator. \n");
2742 else if (area
->NSSATranslatorState
) {
2743 vty_out(vty
, " We are an ABR and ");
2744 if (area
->NSSATranslatorRole
2745 == OSPF_NSSA_ROLE_CANDIDATE
)
2747 "the NSSA Elected Translator. \n");
2748 else if (area
->NSSATranslatorRole
2749 == OSPF_NSSA_ROLE_ALWAYS
)
2751 "always an NSSA Translator. \n");
2753 vty_out(vty
, " We are an ABR, but ");
2754 if (area
->NSSATranslatorRole
2755 == OSPF_NSSA_ROLE_CANDIDATE
)
2757 "not the NSSA Elected Translator. \n");
2760 "never an NSSA Translator. \n");
2765 /* Stub-router state for this area */
2766 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
)) {
2767 char timebuf
[OSPF_TIME_DUMP_SIZE
];
2770 json_object_boolean_true_add(
2771 json_area
, "originStubMaxDistRouterLsa");
2772 if (CHECK_FLAG(area
->stub_router_state
,
2773 OSPF_AREA_ADMIN_STUB_ROUTED
))
2774 json_object_boolean_true_add(
2775 json_area
, "indefiniteActiveAdmin");
2776 if (area
->t_stub_router
) {
2780 &area
->t_stub_router
->u
.sands
,
2783 json_object_int_add(
2785 "activeStartupRemainderMsecs",
2790 " Originating stub / maximum-distance Router-LSA\n");
2791 if (CHECK_FLAG(area
->stub_router_state
,
2792 OSPF_AREA_ADMIN_STUB_ROUTED
))
2794 " Administratively activated (indefinitely)\n");
2795 if (area
->t_stub_router
)
2797 " Active from startup, %s remaining\n",
2798 ospf_timer_dump(area
->t_stub_router
,
2805 /* Show number of fully adjacent neighbors. */
2806 json_object_int_add(json_area
, "nbrFullAdjacentCounter",
2809 /* Show authentication type. */
2810 if (area
->auth_type
== OSPF_AUTH_NULL
)
2811 json_object_string_add(json_area
, "authentication",
2812 "authenticationNone");
2813 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2814 json_object_string_add(json_area
, "authentication",
2815 "authenticationSimplePassword");
2816 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2817 json_object_string_add(json_area
, "authentication",
2818 "authenticationMessageDigest");
2820 if (!OSPF_IS_AREA_BACKBONE(area
))
2821 json_object_int_add(json_area
,
2822 "virtualAdjacenciesPassingCounter",
2825 /* Show SPF calculation times. */
2826 json_object_int_add(json_area
, "spfExecutedCounter",
2827 area
->spf_calculation
);
2828 json_object_int_add(json_area
, "lsaNumber", area
->lsdb
->total
);
2829 json_object_int_add(
2830 json_area
, "lsaRouterNumber",
2831 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
));
2832 json_object_int_add(
2833 json_area
, "lsaRouterChecksum",
2834 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
2835 json_object_int_add(
2836 json_area
, "lsaNetworkNumber",
2837 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
));
2838 json_object_int_add(
2839 json_area
, "lsaNetworkChecksum",
2840 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
2841 json_object_int_add(
2842 json_area
, "lsaSummaryNumber",
2843 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
));
2844 json_object_int_add(
2845 json_area
, "lsaSummaryChecksum",
2846 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
2847 json_object_int_add(
2848 json_area
, "lsaAsbrNumber",
2849 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2850 json_object_int_add(
2851 json_area
, "lsaAsbrChecksum",
2852 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2853 json_object_int_add(
2854 json_area
, "lsaNssaNumber",
2855 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2856 json_object_int_add(
2857 json_area
, "lsaNssaChecksum",
2858 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2860 /* Show number of fully adjacent neighbors. */
2862 " Number of fully adjacent neighbors in this area:"
2866 /* Show authentication type. */
2867 vty_out(vty
, " Area has ");
2868 if (area
->auth_type
== OSPF_AUTH_NULL
)
2869 vty_out(vty
, "no authentication\n");
2870 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2871 vty_out(vty
, "simple password authentication\n");
2872 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2873 vty_out(vty
, "message digest authentication\n");
2875 if (!OSPF_IS_AREA_BACKBONE(area
))
2877 " Number of full virtual adjacencies going through"
2881 /* Show SPF calculation times. */
2882 vty_out(vty
, " SPF algorithm executed %d times\n",
2883 area
->spf_calculation
);
2885 /* Show number of LSA. */
2886 vty_out(vty
, " Number of LSA %ld\n", area
->lsdb
->total
);
2888 " Number of router LSA %ld. Checksum Sum 0x%08x\n",
2889 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
),
2890 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
2892 " Number of network LSA %ld. Checksum Sum 0x%08x\n",
2893 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
),
2894 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
2896 " Number of summary LSA %ld. Checksum Sum 0x%08x\n",
2897 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
),
2898 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
2900 " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n",
2901 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
),
2902 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2903 vty_out(vty
, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n",
2904 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
),
2905 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2909 json_object_int_add(
2910 json_area
, "lsaOpaqueLinkNumber",
2911 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
2912 json_object_int_add(
2913 json_area
, "lsaOpaqueLinkChecksum",
2914 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
2915 json_object_int_add(
2916 json_area
, "lsaOpaqueAreaNumber",
2917 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
2918 json_object_int_add(
2919 json_area
, "lsaOpaqueAreaChecksum",
2920 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
2923 " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n",
2924 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
),
2925 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
2927 " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n",
2928 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
),
2929 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
2933 json_object_object_add(json_areas
, inet_ntoa(area
->area_id
),
2939 static int show_ip_ospf_common(struct vty
*vty
, struct ospf
*ospf
,
2940 json_object
*json
, uint8_t use_vrf
)
2942 struct listnode
*node
, *nnode
;
2943 struct ospf_area
*area
;
2944 struct timeval result
;
2945 char timebuf
[OSPF_TIME_DUMP_SIZE
];
2946 json_object
*json_vrf
= NULL
;
2947 json_object
*json_areas
= NULL
;
2951 json_vrf
= json_object_new_object();
2954 json_areas
= json_object_new_object();
2957 if (ospf
->instance
) {
2959 json_object_int_add(json
, "ospfInstance",
2962 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
2966 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
2968 /* Show Router ID. */
2970 json_object_string_add(json_vrf
, "routerId",
2971 inet_ntoa(ospf
->router_id
));
2973 vty_out(vty
, " OSPF Routing Process, Router ID: %s\n",
2974 inet_ntoa(ospf
->router_id
));
2977 /* Graceful shutdown */
2978 if (ospf
->t_deferred_shutdown
) {
2983 &ospf
->t_deferred_shutdown
->u
.sands
,
2986 json_object_int_add(json_vrf
, "deferredShutdownMsecs",
2990 " Deferred shutdown in progress, %s remaining\n",
2991 ospf_timer_dump(ospf
->t_deferred_shutdown
,
2992 timebuf
, sizeof(timebuf
)));
2996 /* Show capability. */
2998 json_object_boolean_true_add(json_vrf
, "tosRoutesOnly");
2999 json_object_boolean_true_add(json_vrf
, "rfc2328Conform");
3000 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
3001 json_object_boolean_true_add(json_vrf
,
3002 "rfc1583Compatibility");
3005 vty_out(vty
, " Supports only single TOS (TOS0) routes\n");
3006 vty_out(vty
, " This implementation conforms to RFC2328\n");
3007 vty_out(vty
, " RFC1583Compatibility flag is %s\n",
3008 CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)
3014 if (CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)) {
3015 json_object_boolean_true_add(json_vrf
, "opaqueCapable");
3018 vty_out(vty
, " OpaqueCapability flag is %s\n",
3019 CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)
3024 /* Show stub-router configuration */
3025 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
3026 || ospf
->stub_router_shutdown_time
3027 != OSPF_STUB_ROUTER_UNCONFIGURED
) {
3029 json_object_boolean_true_add(json_vrf
,
3030 "stubAdvertisement");
3031 if (ospf
->stub_router_startup_time
3032 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3033 json_object_int_add(
3034 json_vrf
, "postStartEnabledSecs",
3035 ospf
->stub_router_startup_time
);
3036 if (ospf
->stub_router_shutdown_time
3037 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3038 json_object_int_add(
3039 json_vrf
, "preShutdownEnabledSecs",
3040 ospf
->stub_router_shutdown_time
);
3043 " Stub router advertisement is configured\n");
3044 if (ospf
->stub_router_startup_time
3045 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3047 " Enabled for %us after start-up\n",
3048 ospf
->stub_router_startup_time
);
3049 if (ospf
->stub_router_shutdown_time
3050 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3052 " Enabled for %us prior to full shutdown\n",
3053 ospf
->stub_router_shutdown_time
);
3057 /* Show SPF timers. */
3059 json_object_int_add(json_vrf
, "spfScheduleDelayMsecs",
3061 json_object_int_add(json_vrf
, "holdtimeMinMsecs",
3062 ospf
->spf_holdtime
);
3063 json_object_int_add(json_vrf
, "holdtimeMaxMsecs",
3064 ospf
->spf_max_holdtime
);
3065 json_object_int_add(json_vrf
, "holdtimeMultplier",
3066 ospf
->spf_hold_multiplier
);
3069 " Initial SPF scheduling delay %d millisec(s)\n"
3070 " Minimum hold time between consecutive SPFs %d millisec(s)\n"
3071 " Maximum hold time between consecutive SPFs %d millisec(s)\n"
3072 " Hold time multiplier is currently %d\n",
3073 ospf
->spf_delay
, ospf
->spf_holdtime
,
3074 ospf
->spf_max_holdtime
, ospf
->spf_hold_multiplier
);
3078 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3079 long time_store
= 0;
3082 monotime_since(&ospf
->ts_spf
, NULL
) / 1000LL;
3083 json_object_int_add(json_vrf
, "spfLastExecutedMsecs",
3086 time_store
= (1000 * ospf
->ts_spf_duration
.tv_sec
)
3087 + (ospf
->ts_spf_duration
.tv_usec
/ 1000);
3088 json_object_int_add(json_vrf
, "spfLastDurationMsecs",
3091 json_object_boolean_true_add(json_vrf
, "spfHasNotRun");
3093 vty_out(vty
, " SPF algorithm ");
3094 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3095 monotime_since(&ospf
->ts_spf
, &result
);
3096 vty_out(vty
, "last executed %s ago\n",
3097 ospf_timeval_dump(&result
, timebuf
,
3099 vty_out(vty
, " Last SPF duration %s\n",
3100 ospf_timeval_dump(&ospf
->ts_spf_duration
,
3101 timebuf
, sizeof(timebuf
)));
3103 vty_out(vty
, "has not been run\n");
3107 if (ospf
->t_spf_calc
) {
3110 monotime_until(&ospf
->t_spf_calc
->u
.sands
, NULL
)
3112 json_object_int_add(json_vrf
, "spfTimerDueInMsecs",
3116 json_object_int_add(json_vrf
, "lsaMinIntervalMsecs",
3117 ospf
->min_ls_interval
);
3118 json_object_int_add(json_vrf
, "lsaMinArrivalMsecs",
3119 ospf
->min_ls_arrival
);
3120 /* Show write multiplier values */
3121 json_object_int_add(json_vrf
, "writeMultiplier",
3122 ospf
->write_oi_count
);
3123 /* Show refresh parameters. */
3124 json_object_int_add(json_vrf
, "refreshTimerMsecs",
3125 ospf
->lsa_refresh_interval
* 1000);
3127 vty_out(vty
, " SPF timer %s%s\n",
3128 (ospf
->t_spf_calc
? "due in " : "is "),
3129 ospf_timer_dump(ospf
->t_spf_calc
, timebuf
,
3132 vty_out(vty
, " LSA minimum interval %d msecs\n",
3133 ospf
->min_ls_interval
);
3134 vty_out(vty
, " LSA minimum arrival %d msecs\n",
3135 ospf
->min_ls_arrival
);
3137 /* Show write multiplier values */
3138 vty_out(vty
, " Write Multiplier set to %d \n",
3139 ospf
->write_oi_count
);
3141 /* Show refresh parameters. */
3142 vty_out(vty
, " Refresh timer %d secs\n",
3143 ospf
->lsa_refresh_interval
);
3146 /* Show ABR/ASBR flags. */
3147 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ABR
)) {
3149 json_object_string_add(
3150 json_vrf
, "abrType",
3151 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3154 " This router is an ABR, ABR type is: %s\n",
3155 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3157 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ASBR
)) {
3159 json_object_string_add(
3160 json_vrf
, "asbrRouter",
3161 "injectingExternalRoutingInformation");
3164 " This router is an ASBR "
3165 "(injecting external routing information)\n");
3168 /* Show Number of AS-external-LSAs. */
3170 json_object_int_add(
3171 json_vrf
, "lsaExternalCounter",
3172 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3173 json_object_int_add(
3174 json_vrf
, "lsaExternalChecksum",
3175 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3178 " Number of external LSA %ld. Checksum Sum 0x%08x\n",
3179 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
),
3180 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3184 json_object_int_add(
3185 json_vrf
, "lsaAsopaqueCounter",
3186 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3187 json_object_int_add(
3188 json_vrf
, "lsaAsOpaqueChecksum",
3189 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3192 " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n",
3193 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
),
3194 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3197 /* Show number of areas attached. */
3199 json_object_int_add(json_vrf
, "attachedAreaCounter",
3200 listcount(ospf
->areas
));
3202 vty_out(vty
, " Number of areas attached to this router: %d\n",
3203 listcount(ospf
->areas
));
3205 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
3206 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
)) {
3208 json_object_boolean_true_add(
3209 json_vrf
, "adjacencyChangesLoggedAll");
3212 " All adjacency changes are logged\n");
3215 json_object_boolean_true_add(
3216 json_vrf
, "adjacencyChangesLogged");
3218 vty_out(vty
, " Adjacency changes are logged\n");
3221 /* Show each area status. */
3222 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
3223 show_ip_ospf_area(vty
, area
, json_areas
, json
? 1 : 0);
3227 json_object_object_add(json_vrf
, "areas", json_areas
);
3228 if (ospf
->vrf_id
== VRF_DEFAULT
)
3229 json_object_object_add(json
, "default",
3232 json_object_object_add(json
, ospf
->name
,
3235 json_object_object_add(json
, "areas", json_areas
);
3243 DEFUN (show_ip_ospf
,
3245 "show ip ospf [vrf <NAME|all>] [json]",
3248 "OSPF information\n"
3254 bool uj
= use_json(argc
, argv
);
3255 struct listnode
*node
= NULL
;
3256 char *vrf_name
= NULL
;
3257 bool all_vrf
= FALSE
;
3258 int ret
= CMD_SUCCESS
;
3261 json_object
*json
= NULL
;
3262 uint8_t use_vrf
= 0;
3264 if (listcount(om
->ospf
) == 0)
3267 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
3270 json
= json_object_new_object();
3272 /* vrf input is provided could be all or specific vrf*/
3274 bool ospf_output
= FALSE
;
3279 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
3280 if (!ospf
->oi_running
)
3283 ret
= show_ip_ospf_common(vty
, ospf
, json
,
3287 vty_out(vty
, "%s\n",
3288 json_object_to_json_string_ext(
3289 json
, JSON_C_TO_STRING_PRETTY
));
3290 json_object_free(json
);
3291 } else if (!ospf_output
)
3292 vty_out(vty
, "%% OSPF instance not found\n");
3295 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
3296 if ((ospf
== NULL
) || !ospf
->oi_running
) {
3298 vty_out(vty
, "%s\n",
3299 json_object_to_json_string_ext(
3300 json
, JSON_C_TO_STRING_PRETTY
));
3301 json_object_free(json
);
3303 vty_out(vty
, "%% OSPF instance not found\n");
3308 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
3309 /* Display default ospf (instance 0) info */
3310 if (ospf
== NULL
|| !ospf
->oi_running
) {
3312 vty_out(vty
, "%s\n",
3313 json_object_to_json_string_ext(
3314 json
, JSON_C_TO_STRING_PRETTY
));
3315 json_object_free(json
);
3317 vty_out(vty
, "%% OSPF instance not found\n");
3324 show_ip_ospf_common(vty
, ospf
, json
, use_vrf
);
3326 vty_out(vty
, "%s\n",
3327 json_object_to_json_string_ext(
3328 json
, JSON_C_TO_STRING_PRETTY
));
3332 json_object_free(json
);
3337 DEFUN (show_ip_ospf_instance
,
3338 show_ip_ospf_instance_cmd
,
3339 "show ip ospf (1-65535) [json]",
3342 "OSPF information\n"
3348 unsigned short instance
= 0;
3349 bool uj
= use_json(argc
, argv
);
3350 int ret
= CMD_SUCCESS
;
3351 json_object
*json
= NULL
;
3353 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
3354 ospf
= ospf_lookup_instance(instance
);
3356 return CMD_NOT_MY_INSTANCE
;
3358 if (!ospf
->oi_running
)
3362 json
= json_object_new_object();
3364 ret
= show_ip_ospf_common(vty
, ospf
, json
, 0);
3367 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
3368 json
, JSON_C_TO_STRING_PRETTY
));
3369 json_object_free(json
);
3375 static void show_ip_ospf_interface_sub(struct vty
*vty
, struct ospf
*ospf
,
3376 struct interface
*ifp
,
3377 json_object
*json_interface_sub
,
3381 struct ospf_neighbor
*nbr
;
3382 struct route_node
*rn
;
3383 uint32_t bandwidth
= ifp
->bandwidth
? ifp
->bandwidth
: ifp
->speed
;
3385 /* Is interface up? */
3387 is_up
= if_is_operative(ifp
);
3389 json_object_boolean_true_add(json_interface_sub
,
3392 json_object_boolean_false_add(json_interface_sub
,
3395 json_object_int_add(json_interface_sub
, "ifIndex",
3397 json_object_int_add(json_interface_sub
, "mtuBytes", ifp
->mtu
);
3398 json_object_int_add(json_interface_sub
, "bandwidthMbit",
3400 json_object_string_add(json_interface_sub
, "ifFlags",
3401 if_flag_dump(ifp
->flags
));
3403 vty_out(vty
, "%s is %s\n", ifp
->name
,
3404 ((is_up
= if_is_operative(ifp
)) ? "up" : "down"));
3405 vty_out(vty
, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n",
3406 ifp
->ifindex
, ifp
->mtu
, bandwidth
,
3407 if_flag_dump(ifp
->flags
));
3410 /* Is interface OSPF enabled? */
3412 if (ospf_oi_count(ifp
) == 0) {
3413 json_object_boolean_false_add(json_interface_sub
,
3416 } else if (!is_up
) {
3417 json_object_boolean_false_add(json_interface_sub
,
3421 json_object_boolean_true_add(json_interface_sub
,
3424 if (ospf_oi_count(ifp
) == 0) {
3425 vty_out(vty
, " OSPF not enabled on this interface\n");
3427 } else if (!is_up
) {
3429 " OSPF is enabled, but not running on this interface\n");
3434 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
3435 struct ospf_interface
*oi
= rn
->info
;
3440 if (CHECK_FLAG(oi
->connected
->flags
, ZEBRA_IFA_UNNUMBERED
)) {
3442 json_object_boolean_true_add(json_interface_sub
,
3445 vty_out(vty
, " This interface is UNNUMBERED,");
3447 /* Show OSPF interface information. */
3449 json_object_string_add(
3450 json_interface_sub
, "ipAddress",
3451 inet_ntoa(oi
->address
->u
.prefix4
));
3452 json_object_int_add(json_interface_sub
,
3453 "ipAddressPrefixlen",
3454 oi
->address
->prefixlen
);
3456 vty_out(vty
, " Internet Address %s/%d,",
3457 inet_ntoa(oi
->address
->u
.prefix4
),
3458 oi
->address
->prefixlen
);
3460 if (oi
->connected
->destination
3461 || oi
->type
== OSPF_IFTYPE_VIRTUALLINK
) {
3462 struct in_addr
*dest
;
3465 if (CONNECTED_PEER(oi
->connected
)
3466 || oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3471 /* For Vlinks, showing the peer address is
3473 * * * * * informative than the local
3474 * interface that is being used
3476 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3477 dest
= &oi
->vl_data
->peer_addr
;
3479 dest
= &oi
->connected
->destination
->u
3483 json_object_string_add(
3485 "ospfIfType", dstr
);
3486 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3487 json_object_string_add(
3492 json_object_string_add(
3497 vty_out(vty
, " %s %s,", dstr
,
3502 json_object_string_add(json_interface_sub
, "area",
3503 ospf_area_desc_string(oi
->area
));
3504 if (OSPF_IF_PARAM(oi
, mtu_ignore
))
3505 json_object_boolean_true_add(
3507 "mtuMismatchDetect");
3508 json_object_string_add(json_interface_sub
, "routerId",
3509 inet_ntoa(ospf
->router_id
));
3510 json_object_string_add(json_interface_sub
,
3512 ospf_network_type_str
[oi
->type
]);
3513 json_object_int_add(json_interface_sub
, "cost",
3515 json_object_int_add(
3516 json_interface_sub
, "transmitDelaySecs",
3517 OSPF_IF_PARAM(oi
, transmit_delay
));
3518 json_object_string_add(json_interface_sub
, "state",
3519 lookup_msg(ospf_ism_state_msg
,
3521 json_object_int_add(json_interface_sub
, "priority",
3524 vty_out(vty
, " Area %s\n",
3525 ospf_area_desc_string(oi
->area
));
3527 vty_out(vty
, " MTU mismatch detection: %s\n",
3528 OSPF_IF_PARAM(oi
, mtu_ignore
) ? "disabled"
3532 " Router ID %s, Network Type %s, Cost: %d\n",
3533 inet_ntoa(ospf
->router_id
),
3534 ospf_network_type_str
[oi
->type
],
3538 " Transmit Delay is %d sec, State %s, Priority %d\n",
3539 OSPF_IF_PARAM(oi
, transmit_delay
),
3540 lookup_msg(ospf_ism_state_msg
, oi
->state
, NULL
),
3544 /* Show DR information. */
3545 if (DR(oi
).s_addr
== 0) {
3548 " No backup designated router on this network\n");
3550 nbr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &BDR(oi
));
3554 " No backup designated router on this network\n");
3557 json_object_string_add(
3558 json_interface_sub
, "bdrId",
3559 inet_ntoa(nbr
->router_id
));
3560 json_object_string_add(
3563 inet_ntoa(nbr
->address
.u
3567 " Backup Designated Router (ID) %s,",
3568 inet_ntoa(nbr
->router_id
));
3569 vty_out(vty
, " Interface Address %s\n",
3570 inet_ntoa(nbr
->address
.u
3576 /* Next network-LSA sequence number we'll use, if we're elected
3579 && ntohl(oi
->params
->network_lsa_seqnum
)
3580 != OSPF_INITIAL_SEQUENCE_NUMBER
) {
3582 json_object_int_add(
3584 "networkLsaSequence",
3585 ntohl(oi
->params
->network_lsa_seqnum
));
3588 " Saved Network-LSA sequence number 0x%x\n",
3589 ntohl(oi
->params
->network_lsa_seqnum
));
3593 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3594 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3595 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3596 json_object_boolean_true_add(
3598 "mcastMemberOspfAllRouters");
3599 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3600 json_object_boolean_true_add(
3602 "mcastMemberOspfDesignatedRouters");
3605 vty_out(vty
, " Multicast group memberships:");
3606 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3607 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3608 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3609 vty_out(vty
, " OSPFAllRouters");
3610 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3611 vty_out(vty
, " OSPFDesignatedRouters");
3613 vty_out(vty
, " <None>");
3618 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3619 json_object_int_add(
3620 json_interface_sub
, "timerMsecs",
3621 OSPF_IF_PARAM(oi
, v_hello
) * 1000);
3623 json_object_int_add(
3624 json_interface_sub
, "timerMsecs",
3625 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3626 json_object_int_add(json_interface_sub
,
3628 OSPF_IF_PARAM(oi
, v_wait
));
3629 json_object_int_add(json_interface_sub
,
3631 OSPF_IF_PARAM(oi
, v_wait
));
3632 json_object_int_add(
3633 json_interface_sub
, "timerRetransmitSecs",
3634 OSPF_IF_PARAM(oi
, retransmit_interval
));
3636 vty_out(vty
, " Timer intervals configured,");
3637 vty_out(vty
, " Hello ");
3638 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3639 vty_out(vty
, "%ds,",
3640 OSPF_IF_PARAM(oi
, v_hello
));
3642 vty_out(vty
, "%dms,",
3643 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3644 vty_out(vty
, " Dead %ds, Wait %ds, Retransmit %d\n",
3645 OSPF_IF_PARAM(oi
, v_wait
),
3646 OSPF_IF_PARAM(oi
, v_wait
),
3647 OSPF_IF_PARAM(oi
, retransmit_interval
));
3650 if (OSPF_IF_PASSIVE_STATUS(oi
) == OSPF_IF_ACTIVE
) {
3651 char timebuf
[OSPF_TIME_DUMP_SIZE
];
3653 long time_store
= 0;
3657 &oi
->t_hello
->u
.sands
,
3660 json_object_int_add(json_interface_sub
,
3661 "timerHelloInMsecs",
3664 vty_out(vty
, " Hello due in %s\n",
3665 ospf_timer_dump(oi
->t_hello
, timebuf
,
3667 } else /* passive-interface is set */
3670 json_object_boolean_true_add(
3672 "timerPassiveIface");
3675 " No Hellos (Passive interface)\n");
3679 json_object_int_add(json_interface_sub
, "nbrCount",
3680 ospf_nbr_count(oi
, 0));
3681 json_object_int_add(json_interface_sub
,
3683 ospf_nbr_count(oi
, NSM_Full
));
3686 " Neighbor Count is %d, Adjacent neighbor count is %d\n",
3687 ospf_nbr_count(oi
, 0),
3688 ospf_nbr_count(oi
, NSM_Full
));
3689 ospf_bfd_interface_show(vty
, ifp
, json_interface_sub
, use_json
);
3693 static int show_ip_ospf_interface_common(struct vty
*vty
, struct ospf
*ospf
,
3694 char *intf_name
, uint8_t use_vrf
,
3695 json_object
*json
, bool use_json
)
3697 struct interface
*ifp
;
3698 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
3699 json_object
*json_vrf
= NULL
;
3700 json_object
*json_interface_sub
= NULL
, *json_interface
= NULL
;
3704 json_vrf
= json_object_new_object();
3707 json_interface
= json_object_new_object();
3710 if (ospf
->instance
) {
3712 json_object_int_add(json
, "ospfInstance",
3715 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
3718 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3720 if (intf_name
== NULL
) {
3721 /* Show All Interfaces.*/
3722 FOR_ALL_INTERFACES (vrf
, ifp
) {
3723 if (ospf_oi_count(ifp
)) {
3725 json_interface_sub
=
3726 json_object_new_object();
3728 show_ip_ospf_interface_sub(vty
, ospf
, ifp
,
3733 json_object_object_add(
3734 json_interface
, ifp
->name
,
3735 json_interface_sub
);
3740 json_object_object_add(json_vrf
, "interfaces",
3743 /* Interface name is specified. */
3744 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
3747 json_object_boolean_true_add(json_vrf
,
3750 vty_out(vty
, "No such interface name\n");
3753 json_interface_sub
= json_object_new_object();
3754 json_interface
= json_object_new_object();
3757 show_ip_ospf_interface_sub(
3758 vty
, ospf
, ifp
, json_interface_sub
, use_json
);
3761 json_object_object_add(json_interface
,
3763 json_interface_sub
);
3764 json_object_object_add(json_vrf
, "interfaces",
3772 if (ospf
->vrf_id
== VRF_DEFAULT
)
3773 json_object_object_add(json
, "default",
3776 json_object_object_add(json
, ospf
->name
,
3785 static void show_ip_ospf_interface_traffic_sub(struct vty
*vty
,
3786 struct ospf_interface
*oi
,
3787 json_object
*json_interface_sub
,
3791 json_object_int_add(json_interface_sub
, "ifIndex",
3793 json_object_int_add(json_interface_sub
, "helloIn",
3795 json_object_int_add(json_interface_sub
, "helloOut",
3797 json_object_int_add(json_interface_sub
, "dbDescIn",
3799 json_object_int_add(json_interface_sub
, "dbDescOut",
3801 json_object_int_add(json_interface_sub
, "lsReqIn",
3803 json_object_int_add(json_interface_sub
, "lsReqOut",
3805 json_object_int_add(json_interface_sub
, "lsUpdIn",
3807 json_object_int_add(json_interface_sub
, "lsUpdOut",
3809 json_object_int_add(json_interface_sub
, "lsAckIn",
3811 json_object_int_add(json_interface_sub
, "lsAckOut",
3815 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n",
3816 oi
->ifp
->name
, oi
->hello_in
, oi
->hello_out
,
3817 oi
->db_desc_in
, oi
->db_desc_out
, oi
->ls_req_in
,
3818 oi
->ls_req_out
, oi
->ls_upd_in
, oi
->ls_upd_out
,
3819 oi
->ls_ack_in
, oi
->ls_ack_out
);
3823 /* OSPFv2 Packet Counters */
3824 static int show_ip_ospf_interface_traffic_common(
3825 struct vty
*vty
, struct ospf
*ospf
, char *intf_name
, json_object
*json
,
3826 int display_once
, uint8_t use_vrf
, bool use_json
)
3828 struct vrf
*vrf
= NULL
;
3829 struct interface
*ifp
= NULL
;
3830 json_object
*json_vrf
= NULL
;
3831 json_object
*json_interface_sub
= NULL
;
3833 if (!use_json
&& !display_once
) {
3835 vty_out(vty
, "%-12s%-17s%-17s%-17s%-17s%-17s\n", "Interface",
3836 " HELLO", " DB-Desc", " LS-Req", " LS-Update",
3838 vty_out(vty
, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "",
3839 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
3842 "--------------------------------------------------------------------------------------------\n");
3843 } else if (use_json
) {
3845 json_vrf
= json_object_new_object();
3850 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3852 if (intf_name
== NULL
) {
3853 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
3854 FOR_ALL_INTERFACES (vrf
, ifp
) {
3855 struct route_node
*rn
;
3856 struct ospf_interface
*oi
;
3858 if (ospf_oi_count(ifp
) == 0)
3861 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
3862 rn
= route_next(rn
)) {
3869 json_interface_sub
=
3870 json_object_new_object();
3873 show_ip_ospf_interface_traffic_sub(
3874 vty
, oi
, json_interface_sub
, use_json
);
3876 json_object_object_add(
3877 json_vrf
, ifp
->name
,
3878 json_interface_sub
);
3883 /* Interface name is specified. */
3884 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
3886 struct route_node
*rn
;
3887 struct ospf_interface
*oi
;
3889 if (ospf_oi_count(ifp
) == 0) {
3891 " OSPF not enabled on this interface %s\n",
3896 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
3897 rn
= route_next(rn
)) {
3901 json_interface_sub
=
3902 json_object_new_object();
3905 show_ip_ospf_interface_traffic_sub(
3906 vty
, oi
, json_interface_sub
, use_json
);
3908 json_object_object_add(
3909 json_vrf
, ifp
->name
,
3910 json_interface_sub
);
3918 if (ospf
->vrf_id
== VRF_DEFAULT
)
3919 json_object_object_add(json
, "default",
3922 json_object_object_add(json
, ospf
->name
,
3931 DEFUN (show_ip_ospf_interface
,
3932 show_ip_ospf_interface_cmd
,
3933 "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]",
3936 "OSPF information\n"
3939 "Interface information\n"
3944 bool uj
= use_json(argc
, argv
);
3945 struct listnode
*node
= NULL
;
3946 char *vrf_name
= NULL
, *intf_name
= NULL
;
3947 bool all_vrf
= FALSE
;
3948 int ret
= CMD_SUCCESS
;
3950 int idx_vrf
= 0, idx_intf
= 0;
3951 uint8_t use_vrf
= 0;
3952 json_object
*json
= NULL
;
3954 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
3956 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
3957 intf_name
= argv
[idx_intf
]->arg
;
3960 json
= json_object_new_object();
3962 /* vrf input is provided could be all or specific vrf*/
3966 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
3967 if (!ospf
->oi_running
)
3969 ret
= show_ip_ospf_interface_common(
3970 vty
, ospf
, intf_name
, use_vrf
, json
,
3975 vty_out(vty
, "%s\n",
3976 json_object_to_json_string_ext(
3977 json
, JSON_C_TO_STRING_PRETTY
));
3978 json_object_free(json
);
3980 vty_out(vty
, "%% OSPF instance not found\n");
3984 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
3985 if (ospf
== NULL
|| !ospf
->oi_running
) {
3987 vty_out(vty
, "%s\n",
3988 json_object_to_json_string_ext(
3989 json
, JSON_C_TO_STRING_PRETTY
));
3990 json_object_free(json
);
3992 vty_out(vty
, "%% OSPF instance not found\n");
3996 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
4000 /* Display default ospf (instance 0) info */
4001 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4002 if (ospf
== NULL
|| !ospf
->oi_running
) {
4004 vty_out(vty
, "%s\n",
4005 json_object_to_json_string_ext(
4006 json
, JSON_C_TO_STRING_PRETTY
));
4007 json_object_free(json
);
4009 vty_out(vty
, "%% OSPF instance not found\n");
4013 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
4018 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4019 json
, JSON_C_TO_STRING_PRETTY
));
4020 json_object_free(json
);
4026 DEFUN (show_ip_ospf_instance_interface
,
4027 show_ip_ospf_instance_interface_cmd
,
4028 "show ip ospf (1-65535) interface [INTERFACE] [json]",
4031 "OSPF information\n"
4033 "Interface information\n"
4040 unsigned short instance
= 0;
4041 bool uj
= use_json(argc
, argv
);
4042 char *intf_name
= NULL
;
4043 int ret
= CMD_SUCCESS
;
4044 json_object
*json
= NULL
;
4046 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4047 ospf
= ospf_lookup_instance(instance
);
4049 return CMD_NOT_MY_INSTANCE
;
4051 if (!ospf
->oi_running
)
4055 json
= json_object_new_object();
4057 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4058 intf_name
= argv
[idx_intf
]->arg
;
4060 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
, 0, json
, uj
);
4063 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4064 json
, JSON_C_TO_STRING_PRETTY
));
4065 json_object_free(json
);
4071 DEFUN (show_ip_ospf_interface_traffic
,
4072 show_ip_ospf_interface_traffic_cmd
,
4073 "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]",
4076 "OSPF information\n"
4079 "Interface information\n"
4080 "Protocol Packet counters\n"
4084 struct ospf
*ospf
= NULL
;
4085 struct listnode
*node
= NULL
;
4086 char *vrf_name
= NULL
, *intf_name
= NULL
;
4087 bool all_vrf
= FALSE
;
4089 int idx_vrf
= 0, idx_intf
= 0;
4090 bool uj
= use_json(argc
, argv
);
4091 json_object
*json
= NULL
;
4092 int ret
= CMD_SUCCESS
;
4093 int display_once
= 0;
4094 uint8_t use_vrf
= 0;
4096 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4098 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4099 intf_name
= argv
[idx_intf
]->arg
;
4102 json
= json_object_new_object();
4107 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4108 if (!ospf
->oi_running
)
4111 ret
= show_ip_ospf_interface_traffic_common(
4112 vty
, ospf
, intf_name
, json
,
4113 display_once
, use_vrf
, uj
);
4118 vty_out(vty
, "%s\n",
4119 json_object_to_json_string_ext(
4120 json
, JSON_C_TO_STRING_PRETTY
));
4121 json_object_free(json
);
4126 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4127 if (ospf
== NULL
|| !ospf
->oi_running
) {
4129 json_object_free(json
);
4133 ret
= show_ip_ospf_interface_traffic_common(
4134 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4136 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4137 if (ospf
== NULL
|| !ospf
->oi_running
) {
4139 json_object_free(json
);
4143 ret
= show_ip_ospf_interface_traffic_common(
4144 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4148 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4149 json
, JSON_C_TO_STRING_PRETTY
));
4150 json_object_free(json
);
4157 static void show_ip_ospf_neighbour_header(struct vty
*vty
)
4159 vty_out(vty
, "\n%-15s %3s %-15s %9s %-15s %-20s %5s %5s %5s\n",
4160 "Neighbor ID", "Pri", "State", "Dead Time", "Address",
4161 "Interface", "RXmtL", "RqstL", "DBsmL");
4164 static void show_ip_ospf_neighbor_sub(struct vty
*vty
,
4165 struct ospf_interface
*oi
,
4166 json_object
*json
, bool use_json
)
4168 struct route_node
*rn
;
4169 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
4171 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4172 json_object
*json_neighbor
= NULL
, *json_neigh_array
= NULL
;
4174 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
4175 if ((nbr
= rn
->info
)) {
4176 /* Do not show myself. */
4177 if (nbr
== oi
->nbr_self
)
4179 /* Down state is not shown. */
4180 if (nbr
->state
== NSM_Down
)
4183 char neigh_str
[INET_ADDRSTRLEN
];
4186 && !IPV4_ADDR_SAME(&prev_nbr
->src
,
4188 /* Start new neigh list */
4189 json_neigh_array
= NULL
;
4192 if (nbr
->state
== NSM_Attempt
4193 && nbr
->router_id
.s_addr
== 0)
4194 strlcpy(neigh_str
, "neighbor",
4198 inet_ntoa(nbr
->router_id
),
4201 json_object_object_get_ex(json
, neigh_str
,
4204 if (!json_neigh_array
) {
4206 json_object_new_array();
4207 json_object_object_add(
4212 json_neighbor
= json_object_new_object();
4214 ospf_nbr_state_message(nbr
, msgbuf
, 16);
4220 &nbr
->t_inactivity
->u
.sands
,
4224 json_object_int_add(json_neighbor
, "priority",
4226 json_object_string_add(json_neighbor
, "state",
4228 json_object_int_add(json_neighbor
,
4231 json_object_string_add(json_neighbor
, "address",
4232 inet_ntoa(nbr
->src
));
4233 json_object_string_add(json_neighbor
,
4236 json_object_int_add(
4237 json_neighbor
, "retransmitCounter",
4238 ospf_ls_retransmit_count(nbr
));
4239 json_object_int_add(json_neighbor
,
4241 ospf_ls_request_count(nbr
));
4242 json_object_int_add(json_neighbor
,
4244 ospf_db_summary_count(nbr
));
4246 json_object_array_add(json_neigh_array
,
4249 ospf_nbr_state_message(nbr
, msgbuf
, 16);
4251 if (nbr
->state
== NSM_Attempt
4252 && nbr
->router_id
.s_addr
== 0)
4253 vty_out(vty
, "%-15s %3d %-15s ", "-",
4254 nbr
->priority
, msgbuf
);
4256 vty_out(vty
, "%-15s %3d %-15s ",
4257 inet_ntoa(nbr
->router_id
),
4258 nbr
->priority
, msgbuf
);
4260 vty_out(vty
, "%9s ",
4261 ospf_timer_dump(nbr
->t_inactivity
,
4264 vty_out(vty
, "%-15s ", inet_ntoa(nbr
->src
));
4265 vty_out(vty
, "%-20s %5ld %5ld %5d\n",
4267 ospf_ls_retransmit_count(nbr
),
4268 ospf_ls_request_count(nbr
),
4269 ospf_db_summary_count(nbr
));
4276 static int show_ip_ospf_neighbor_common(struct vty
*vty
, struct ospf
*ospf
,
4277 json_object
*json
, bool use_json
,
4280 struct ospf_interface
*oi
;
4281 struct listnode
*node
;
4282 json_object
*json_vrf
= NULL
;
4283 json_object
*json_nbr_sub
= NULL
;
4287 json_vrf
= json_object_new_object();
4290 json_nbr_sub
= json_object_new_object();
4293 if (ospf
->instance
) {
4295 json_object_int_add(json
, "ospfInstance",
4298 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4301 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4303 show_ip_ospf_neighbour_header(vty
);
4305 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4306 if (ospf_interface_neighbor_count(oi
) == 0)
4308 show_ip_ospf_neighbor_sub(vty
, oi
, json_nbr_sub
, use_json
);
4312 json_object_object_add(json_vrf
, "neighbors", json_nbr_sub
);
4314 if (ospf
->vrf_id
== VRF_DEFAULT
)
4315 json_object_object_add(json
, "default",
4318 json_object_object_add(json
, ospf
->name
,
4327 DEFUN (show_ip_ospf_neighbor
,
4328 show_ip_ospf_neighbor_cmd
,
4329 "show ip ospf [vrf <NAME|all>] neighbor [json]",
4332 "OSPF information\n"
4339 bool uj
= use_json(argc
, argv
);
4340 struct listnode
*node
= NULL
;
4341 char *vrf_name
= NULL
;
4342 bool all_vrf
= FALSE
;
4343 int ret
= CMD_SUCCESS
;
4346 uint8_t use_vrf
= 0;
4347 json_object
*json
= NULL
;
4349 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4352 json
= json_object_new_object();
4354 /* vrf input is provided could be all or specific vrf*/
4358 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4359 if (!ospf
->oi_running
)
4361 ret
= show_ip_ospf_neighbor_common(
4362 vty
, ospf
, json
, uj
, use_vrf
);
4366 vty_out(vty
, "%s\n",
4367 json_object_to_json_string_ext(
4368 json
, JSON_C_TO_STRING_PRETTY
));
4369 json_object_free(json
);
4371 vty_out(vty
, "OSPF instance not found\n");
4376 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4377 if (ospf
== NULL
|| !ospf
->oi_running
) {
4379 vty_out(vty
, "%s\n",
4380 json_object_to_json_string_ext(
4381 json
, JSON_C_TO_STRING_PRETTY
));
4382 json_object_free(json
);
4384 vty_out(vty
, "%% OSPF instance not found\n");
4389 /* Display default ospf (instance 0) info */
4390 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4391 if (ospf
== NULL
|| !ospf
->oi_running
) {
4393 vty_out(vty
, "%s\n",
4394 json_object_to_json_string_ext(
4395 json
, JSON_C_TO_STRING_PRETTY
));
4396 json_object_free(json
);
4398 vty_out(vty
, "%% OSPF instance not found\n");
4405 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
,
4409 vty_out(vty
, "%s\n",
4410 json_object_to_json_string_ext(
4411 json
, JSON_C_TO_STRING_PRETTY
));
4416 json_object_free(json
);
4422 DEFUN (show_ip_ospf_instance_neighbor
,
4423 show_ip_ospf_instance_neighbor_cmd
,
4424 "show ip ospf (1-65535) neighbor [json]",
4427 "OSPF information\n"
4434 unsigned short instance
= 0;
4435 bool uj
= use_json(argc
, argv
);
4436 json_object
*json
= NULL
;
4437 int ret
= CMD_SUCCESS
;
4439 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4440 ospf
= ospf_lookup_instance(instance
);
4442 return CMD_NOT_MY_INSTANCE
;
4444 if (!ospf
->oi_running
)
4448 json
= json_object_new_object();
4450 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
, 0);
4453 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4454 json
, JSON_C_TO_STRING_PRETTY
));
4455 json_object_free(json
);
4461 static int show_ip_ospf_neighbor_all_common(struct vty
*vty
, struct ospf
*ospf
,
4462 json_object
*json
, bool use_json
,
4465 struct listnode
*node
;
4466 struct ospf_interface
*oi
;
4467 json_object
*json_vrf
= NULL
;
4468 json_object
*json_neighbor_sub
= NULL
;
4472 json_vrf
= json_object_new_object();
4475 json_neighbor_sub
= json_object_new_object();
4478 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4480 show_ip_ospf_neighbour_header(vty
);
4482 if (ospf
->instance
) {
4484 json_object_int_add(json_vrf
, "ospfInstance",
4487 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4490 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4491 struct listnode
*nbr_node
;
4492 struct ospf_nbr_nbma
*nbr_nbma
;
4494 show_ip_ospf_neighbor_sub(vty
, oi
, json_vrf
, use_json
);
4496 /* print Down neighbor status */
4497 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nbr_node
, nbr_nbma
)) {
4498 if (nbr_nbma
->nbr
== NULL
4499 || nbr_nbma
->nbr
->state
== NSM_Down
) {
4501 json_object_int_add(json_neighbor_sub
,
4503 nbr_nbma
->priority
);
4504 json_object_boolean_true_add(
4507 json_object_string_add(
4511 json_object_int_add(
4513 "nbrNbmaRetransmitCounter", 0);
4514 json_object_int_add(
4516 "nbrNbmaRequestCounter", 0);
4517 json_object_int_add(
4519 "nbrNbmaDbSummaryCounter", 0);
4520 json_object_object_add(
4522 inet_ntoa(nbr_nbma
->addr
),
4525 vty_out(vty
, "%-15s %3d %-15s %9s ",
4526 "-", nbr_nbma
->priority
, "Down",
4529 "%-15s %-20s %5d %5d %5d\n",
4530 inet_ntoa(nbr_nbma
->addr
),
4531 IF_NAME(oi
), 0, 0, 0);
4539 if (ospf
->vrf_id
== VRF_DEFAULT
)
4540 json_object_object_add(json
, "default",
4543 json_object_object_add(json
, ospf
->name
,
4552 DEFUN (show_ip_ospf_neighbor_all
,
4553 show_ip_ospf_neighbor_all_cmd
,
4554 "show ip ospf [vrf <NAME|all>] neighbor all [json]",
4557 "OSPF information\n"
4561 "include down status neighbor\n"
4565 bool uj
= use_json(argc
, argv
);
4566 struct listnode
*node
= NULL
;
4567 char *vrf_name
= NULL
;
4568 bool all_vrf
= FALSE
;
4569 int ret
= CMD_SUCCESS
;
4572 uint8_t use_vrf
= 0;
4573 json_object
*json
= NULL
;
4575 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4578 json
= json_object_new_object();
4580 /* vrf input is provided could be all or specific vrf*/
4584 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4585 if (!ospf
->oi_running
)
4587 ret
= show_ip_ospf_neighbor_all_common(
4588 vty
, ospf
, json
, uj
, use_vrf
);
4592 vty_out(vty
, "%s\n",
4593 json_object_to_json_string_ext(
4594 json
, JSON_C_TO_STRING_PRETTY
));
4595 json_object_free(json
);
4601 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4602 if (ospf
== NULL
|| !ospf
->oi_running
) {
4604 json_object_free(json
);
4608 /* Display default ospf (instance 0) info */
4609 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4610 if (ospf
== NULL
|| !ospf
->oi_running
) {
4612 json_object_free(json
);
4618 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
,
4621 vty_out(vty
, "%s\n",
4622 json_object_to_json_string_ext(
4623 json
, JSON_C_TO_STRING_PRETTY
));
4628 json_object_free(json
);
4633 DEFUN (show_ip_ospf_instance_neighbor_all
,
4634 show_ip_ospf_instance_neighbor_all_cmd
,
4635 "show ip ospf (1-65535) neighbor all [json]",
4638 "OSPF information\n"
4641 "include down status neighbor\n"
4646 unsigned short instance
= 0;
4647 bool uj
= use_json(argc
, argv
);
4648 json_object
*json
= NULL
;
4649 int ret
= CMD_SUCCESS
;
4651 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4652 ospf
= ospf_lookup_instance(instance
);
4654 return CMD_NOT_MY_INSTANCE
;
4656 if (!ospf
->oi_running
)
4659 json
= json_object_new_object();
4661 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
, 0);
4664 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4665 json
, JSON_C_TO_STRING_PRETTY
));
4666 json_object_free(json
);
4672 static int show_ip_ospf_neighbor_int_common(struct vty
*vty
, struct ospf
*ospf
,
4674 struct cmd_token
**argv
,
4675 bool use_json
, uint8_t use_vrf
)
4677 struct interface
*ifp
;
4678 struct route_node
*rn
;
4679 json_object
*json
= NULL
;
4682 json
= json_object_new_object();
4684 if (ospf
->instance
) {
4686 json_object_int_add(json
, "ospfInstance",
4689 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4692 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
4694 ifp
= if_lookup_by_name(argv
[arg_base
]->arg
, ospf
->vrf_id
);
4697 json_object_boolean_true_add(json
, "noSuchIface");
4699 vty_out(vty
, "No such interface.\n");
4703 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
4704 struct ospf_interface
*oi
= rn
->info
;
4709 show_ip_ospf_neighbor_sub(vty
, oi
, json
, use_json
);
4713 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4714 json
, JSON_C_TO_STRING_PRETTY
));
4715 json_object_free(json
);
4722 DEFUN (show_ip_ospf_neighbor_int
,
4723 show_ip_ospf_neighbor_int_cmd
,
4724 "show ip ospf [vrf <NAME>] neighbor IFNAME [json]",
4727 "OSPF information\n"
4736 bool uj
= use_json(argc
, argv
);
4737 int ret
= CMD_SUCCESS
;
4738 struct interface
*ifp
= NULL
;
4739 char *vrf_name
= NULL
;
4740 vrf_id_t vrf_id
= VRF_DEFAULT
;
4741 struct vrf
*vrf
= NULL
;
4743 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
4744 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
4745 if (vrf_name
&& strmatch(vrf_name
, VRF_DEFAULT_NAME
))
4748 vrf
= vrf_lookup_by_name(vrf_name
);
4750 vrf_id
= vrf
->vrf_id
;
4752 ospf
= ospf_lookup_by_vrf_id(vrf_id
);
4754 if (!ospf
|| !ospf
->oi_running
)
4758 show_ip_ospf_neighbour_header(vty
);
4760 argv_find(argv
, argc
, "IFNAME", &idx_ifname
);
4762 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf_id
);
4766 ret
= show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
,
4771 DEFUN (show_ip_ospf_instance_neighbor_int
,
4772 show_ip_ospf_instance_neighbor_int_cmd
,
4773 "show ip ospf (1-65535) neighbor IFNAME [json]",
4776 "OSPF information\n"
4785 unsigned short instance
= 0;
4786 bool uj
= use_json(argc
, argv
);
4789 show_ip_ospf_neighbour_header(vty
);
4791 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4792 ospf
= ospf_lookup_instance(instance
);
4794 return CMD_NOT_MY_INSTANCE
;
4796 if (!ospf
->oi_running
)
4800 show_ip_ospf_neighbour_header(vty
);
4802 return show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
, argv
, uj
,
4806 static void show_ip_ospf_nbr_nbma_detail_sub(struct vty
*vty
,
4807 struct ospf_interface
*oi
,
4808 struct ospf_nbr_nbma
*nbr_nbma
,
4809 bool use_json
, json_object
*json
)
4811 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4812 json_object
*json_sub
= NULL
;
4815 json_sub
= json_object_new_object();
4816 else /* Show neighbor ID. */
4817 vty_out(vty
, " Neighbor %s,", "-");
4819 /* Show interface address. */
4821 json_object_string_add(json_sub
, "ifaceAddress",
4822 inet_ntoa(nbr_nbma
->addr
));
4824 vty_out(vty
, " interface address %s\n",
4825 inet_ntoa(nbr_nbma
->addr
));
4829 json_object_string_add(json_sub
, "areaId",
4830 ospf_area_desc_string(oi
->area
));
4831 json_object_string_add(json_sub
, "iface", IF_NAME(oi
));
4833 vty_out(vty
, " In the area %s via interface %s\n",
4834 ospf_area_desc_string(oi
->area
), IF_NAME(oi
));
4836 /* Show neighbor priority and state. */
4838 json_object_int_add(json_sub
, "nbrPriority",
4839 nbr_nbma
->priority
);
4840 json_object_string_add(json_sub
, "nbrState", "down");
4842 vty_out(vty
, " Neighbor priority is %d, State is %s,",
4843 nbr_nbma
->priority
, "Down");
4845 /* Show state changes. */
4847 json_object_int_add(json_sub
, "stateChangeCounter",
4848 nbr_nbma
->state_change
);
4850 vty_out(vty
, " %d state changes\n", nbr_nbma
->state_change
);
4852 /* Show PollInterval */
4854 json_object_int_add(json_sub
, "pollInterval", nbr_nbma
->v_poll
);
4856 vty_out(vty
, " Poll interval %d\n", nbr_nbma
->v_poll
);
4858 /* Show poll-interval timer. */
4859 if (nbr_nbma
->t_poll
) {
4862 time_store
= monotime_until(&nbr_nbma
->t_poll
->u
.sands
,
4864 json_object_int_add(json_sub
,
4865 "pollIntervalTimerDueMsec",
4868 vty_out(vty
, " Poll timer due in %s\n",
4869 ospf_timer_dump(nbr_nbma
->t_poll
, timebuf
,
4873 /* Show poll-interval timer thread. */
4875 if (nbr_nbma
->t_poll
!= NULL
)
4876 json_object_string_add(json_sub
,
4877 "pollIntervalTimerThread", "on");
4879 vty_out(vty
, " Thread Poll Timer %s\n",
4880 nbr_nbma
->t_poll
!= NULL
? "on" : "off");
4883 json_object_object_add(json
, "noNbrId", json_sub
);
4886 static void show_ip_ospf_neighbor_detail_sub(struct vty
*vty
,
4887 struct ospf_interface
*oi
,
4888 struct ospf_neighbor
*nbr
,
4889 json_object
*json
, bool use_json
)
4891 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4892 json_object
*json_sub
= NULL
;
4895 json_sub
= json_object_new_object();
4897 /* Show neighbor ID. */
4898 if (nbr
->state
== NSM_Attempt
&& nbr
->router_id
.s_addr
== 0)
4899 vty_out(vty
, " Neighbor %s,", "-");
4901 vty_out(vty
, " Neighbor %s,",
4902 inet_ntoa(nbr
->router_id
));
4905 /* Show interface address. */
4907 json_object_string_add(json_sub
, "ifaceAddress",
4908 inet_ntoa(nbr
->address
.u
.prefix4
));
4910 vty_out(vty
, " interface address %s\n",
4911 inet_ntoa(nbr
->address
.u
.prefix4
));
4915 json_object_string_add(json_sub
, "areaId",
4916 ospf_area_desc_string(oi
->area
));
4917 json_object_string_add(json_sub
, "ifaceName", oi
->ifp
->name
);
4919 vty_out(vty
, " In the area %s via interface %s\n",
4920 ospf_area_desc_string(oi
->area
), oi
->ifp
->name
);
4922 /* Show neighbor priority and state. */
4924 json_object_int_add(json_sub
, "nbrPriority", nbr
->priority
);
4925 json_object_string_add(
4926 json_sub
, "nbrState",
4927 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
4929 vty_out(vty
, " Neighbor priority is %d, State is %s,",
4931 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
4933 /* Show state changes. */
4935 json_object_int_add(json_sub
, "stateChangeCounter",
4938 vty_out(vty
, " %d state changes\n", nbr
->state_change
);
4940 if (nbr
->ts_last_progress
.tv_sec
|| nbr
->ts_last_progress
.tv_usec
) {
4945 monotime_since(&nbr
->ts_last_progress
, &res
) / 1000LL;
4947 json_object_int_add(json_sub
, "lastPrgrsvChangeMsec",
4951 " Most recent state change statistics:\n");
4952 vty_out(vty
, " Progressive change %s ago\n",
4953 ospf_timeval_dump(&res
, timebuf
,
4958 if (nbr
->ts_last_regress
.tv_sec
|| nbr
->ts_last_regress
.tv_usec
) {
4963 monotime_since(&nbr
->ts_last_regress
, &res
) / 1000LL;
4965 json_object_int_add(json_sub
,
4966 "lastRegressiveChangeMsec",
4968 if (nbr
->last_regress_str
)
4969 json_object_string_add(
4970 json_sub
, "lastRegressiveChangeReason",
4971 nbr
->last_regress_str
);
4974 " Regressive change %s ago, due to %s\n",
4975 ospf_timeval_dump(&res
, timebuf
,
4977 (nbr
->last_regress_str
? nbr
->last_regress_str
4982 /* Show Designated Rotuer ID. */
4984 json_object_string_add(json_sub
, "routerDesignatedId",
4985 inet_ntoa(nbr
->d_router
));
4987 vty_out(vty
, " DR is %s,", inet_ntoa(nbr
->d_router
));
4989 /* Show Backup Designated Rotuer ID. */
4991 json_object_string_add(json_sub
, "routerDesignatedBackupId",
4992 inet_ntoa(nbr
->bd_router
));
4994 vty_out(vty
, " BDR is %s\n", inet_ntoa(nbr
->bd_router
));
4998 json_object_int_add(json_sub
, "optionsCounter", nbr
->options
);
4999 json_object_string_add(json_sub
, "optionsList",
5000 ospf_options_dump(nbr
->options
));
5002 vty_out(vty
, " Options %d %s\n", nbr
->options
,
5003 ospf_options_dump(nbr
->options
));
5005 /* Show Router Dead interval timer. */
5007 if (nbr
->t_inactivity
) {
5009 time_store
= monotime_until(&nbr
->t_inactivity
->u
.sands
,
5012 json_object_int_add(json_sub
,
5013 "routerDeadIntervalTimerDueMsec",
5016 json_object_int_add(
5017 json_sub
, "routerDeadIntervalTimerDueMsec", -1);
5019 vty_out(vty
, " Dead timer due in %s\n",
5020 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
5023 /* Show Database Summary list. */
5025 json_object_int_add(json_sub
, "databaseSummaryListCounter",
5026 ospf_db_summary_count(nbr
));
5028 vty_out(vty
, " Database Summary List %d\n",
5029 ospf_db_summary_count(nbr
));
5031 /* Show Link State Request list. */
5033 json_object_int_add(json_sub
, "linkStateRequestListCounter",
5034 ospf_ls_request_count(nbr
));
5036 vty_out(vty
, " Link State Request List %ld\n",
5037 ospf_ls_request_count(nbr
));
5039 /* Show Link State Retransmission list. */
5041 json_object_int_add(json_sub
,
5042 "linkStateRetransmissionListCounter",
5043 ospf_ls_retransmit_count(nbr
));
5045 vty_out(vty
, " Link State Retransmission List %ld\n",
5046 ospf_ls_retransmit_count(nbr
));
5048 /* Show inactivity timer thread. */
5050 if (nbr
->t_inactivity
!= NULL
)
5051 json_object_string_add(json_sub
,
5052 "threadInactivityTimer", "on");
5054 vty_out(vty
, " Thread Inactivity Timer %s\n",
5055 nbr
->t_inactivity
!= NULL
? "on" : "off");
5057 /* Show Database Description retransmission thread. */
5059 if (nbr
->t_db_desc
!= NULL
)
5060 json_object_string_add(
5062 "threadDatabaseDescriptionRetransmission",
5066 " Thread Database Description Retransmision %s\n",
5067 nbr
->t_db_desc
!= NULL
? "on" : "off");
5069 /* Show Link State Request Retransmission thread. */
5071 if (nbr
->t_ls_req
!= NULL
)
5072 json_object_string_add(
5074 "threadLinkStateRequestRetransmission", "on");
5077 " Thread Link State Request Retransmission %s\n",
5078 nbr
->t_ls_req
!= NULL
? "on" : "off");
5080 /* Show Link State Update Retransmission thread. */
5082 if (nbr
->t_ls_upd
!= NULL
)
5083 json_object_string_add(
5084 json_sub
, "threadLinkStateUpdateRetransmission",
5088 " Thread Link State Update Retransmission %s\n\n",
5089 nbr
->t_ls_upd
!= NULL
? "on" : "off");
5092 if (nbr
->state
== NSM_Attempt
&& nbr
->router_id
.s_addr
== 0)
5093 json_object_object_add(json
, "noNbrId", json_sub
);
5095 json_object_object_add(json
, inet_ntoa(nbr
->router_id
),
5099 ospf_bfd_show_info(vty
, nbr
->bfd_info
, json
, use_json
, 0);
5102 static int show_ip_ospf_neighbor_id_common(struct vty
*vty
, struct ospf
*ospf
,
5103 struct in_addr
*router_id
,
5104 bool use_json
, uint8_t use_vrf
)
5106 struct listnode
*node
;
5107 struct ospf_neighbor
*nbr
;
5108 struct ospf_interface
*oi
;
5109 json_object
*json
= NULL
;
5112 json
= json_object_new_object();
5114 if (ospf
->instance
) {
5116 json_object_int_add(json
, "ospfInstance",
5119 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5122 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
5124 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5125 if ((nbr
= ospf_nbr_lookup_by_routerid(oi
->nbrs
, router_id
))) {
5126 show_ip_ospf_neighbor_detail_sub(vty
, oi
, nbr
, json
,
5132 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5133 json
, JSON_C_TO_STRING_PRETTY
));
5134 json_object_free(json
);
5141 DEFPY (show_ip_ospf_neighbor_id
,
5142 show_ip_ospf_neighbor_id_cmd
,
5143 "show ip ospf neighbor A.B.C.D$router_id [json$json]",
5146 "OSPF information\n"
5152 struct listnode
*node
;
5153 int ret
= CMD_SUCCESS
;
5155 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5156 if (!ospf
->oi_running
)
5158 ret
= show_ip_ospf_neighbor_id_common(vty
, ospf
, &router_id
,
5165 DEFPY (show_ip_ospf_instance_neighbor_id
,
5166 show_ip_ospf_instance_neighbor_id_cmd
,
5167 "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [json$json]",
5170 "OSPF information\n"
5178 ospf
= ospf_lookup_instance(instance
);
5180 return CMD_NOT_MY_INSTANCE
;
5182 if (!ospf
->oi_running
)
5185 return show_ip_ospf_neighbor_id_common(vty
, ospf
, &router_id
, !!json
,
5189 static int show_ip_ospf_neighbor_detail_common(struct vty
*vty
,
5191 json_object
*json
, bool use_json
,
5194 struct ospf_interface
*oi
;
5195 struct listnode
*node
;
5196 json_object
*json_vrf
= NULL
;
5200 json_vrf
= json_object_new_object();
5204 if (ospf
->instance
) {
5206 json_object_int_add(json_vrf
, "ospfInstance",
5209 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5212 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5214 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5215 struct route_node
*rn
;
5216 struct ospf_neighbor
*nbr
;
5218 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5219 if ((nbr
= rn
->info
)) {
5220 if (nbr
!= oi
->nbr_self
) {
5221 if (nbr
->state
!= NSM_Down
) {
5222 show_ip_ospf_neighbor_detail_sub(
5223 vty
, oi
, nbr
, json_vrf
,
5233 if (ospf
->vrf_id
== VRF_DEFAULT
)
5234 json_object_object_add(json
, "default",
5237 json_object_object_add(json
, ospf
->name
,
5246 DEFUN (show_ip_ospf_neighbor_detail
,
5247 show_ip_ospf_neighbor_detail_cmd
,
5248 "show ip ospf [vrf <NAME|all>] neighbor detail [json]",
5251 "OSPF information\n"
5255 "detail of all neighbors\n"
5259 bool uj
= use_json(argc
, argv
);
5260 struct listnode
*node
= NULL
;
5261 char *vrf_name
= NULL
;
5262 bool all_vrf
= FALSE
;
5263 int ret
= CMD_SUCCESS
;
5266 uint8_t use_vrf
= 0;
5267 json_object
*json
= NULL
;
5269 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5272 json
= json_object_new_object();
5274 /* vrf input is provided could be all or specific vrf*/
5278 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5279 if (!ospf
->oi_running
)
5281 ret
= show_ip_ospf_neighbor_detail_common(
5282 vty
, ospf
, json
, uj
, use_vrf
);
5285 vty_out(vty
, "%s\n",
5286 json_object_to_json_string_ext(
5287 json
, JSON_C_TO_STRING_PRETTY
));
5288 json_object_free(json
);
5293 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5294 if (ospf
== NULL
|| !ospf
->oi_running
) {
5296 json_object_free(json
);
5300 /* Display default ospf (instance 0) info */
5301 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5302 if (ospf
== NULL
|| !ospf
->oi_running
) {
5304 json_object_free(json
);
5310 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
,
5313 vty_out(vty
, "%s\n",
5314 json_object_to_json_string_ext(
5315 json
, JSON_C_TO_STRING_PRETTY
));
5320 json_object_free(json
);
5325 DEFUN (show_ip_ospf_instance_neighbor_detail
,
5326 show_ip_ospf_instance_neighbor_detail_cmd
,
5327 "show ip ospf (1-65535) neighbor detail [json]",
5330 "OSPF information\n"
5333 "detail of all neighbors\n"
5338 unsigned short instance
= 0;
5339 bool uj
= use_json(argc
, argv
);
5340 json_object
*json
= NULL
;
5341 int ret
= CMD_SUCCESS
;
5343 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5344 ospf
= ospf_lookup_instance(instance
);
5346 return CMD_NOT_MY_INSTANCE
;
5348 if (!ospf
->oi_running
)
5352 json
= json_object_new_object();
5354 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
, 0);
5357 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5358 json
, JSON_C_TO_STRING_PRETTY
));
5359 json_object_free(json
);
5365 static int show_ip_ospf_neighbor_detail_all_common(struct vty
*vty
,
5371 struct listnode
*node
;
5372 struct ospf_interface
*oi
;
5373 json_object
*json_vrf
= NULL
;
5377 json_vrf
= json_object_new_object();
5382 if (ospf
->instance
) {
5384 json_object_int_add(json
, "ospfInstance",
5387 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5390 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5392 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5393 struct route_node
*rn
;
5394 struct ospf_neighbor
*nbr
;
5395 struct ospf_nbr_nbma
*nbr_nbma
;
5397 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
5398 if ((nbr
= rn
->info
))
5399 if (nbr
!= oi
->nbr_self
)
5400 if (nbr
->state
!= NSM_Down
)
5401 show_ip_ospf_neighbor_detail_sub(
5403 json_vrf
, use_json
);
5405 if (oi
->type
== OSPF_IFTYPE_NBMA
) {
5406 struct listnode
*nd
;
5408 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nd
, nbr_nbma
)) {
5409 if (nbr_nbma
->nbr
== NULL
5410 || nbr_nbma
->nbr
->state
== NSM_Down
)
5411 show_ip_ospf_nbr_nbma_detail_sub(
5412 vty
, oi
, nbr_nbma
, use_json
,
5420 if (ospf
->vrf_id
== VRF_DEFAULT
)
5421 json_object_object_add(json
, "default",
5424 json_object_object_add(json
, ospf
->name
,
5434 DEFUN (show_ip_ospf_neighbor_detail_all
,
5435 show_ip_ospf_neighbor_detail_all_cmd
,
5436 "show ip ospf [vrf <NAME|all>] neighbor detail all [json]",
5439 "OSPF information\n"
5443 "detail of all neighbors\n"
5444 "include down status neighbor\n"
5448 bool uj
= use_json(argc
, argv
);
5449 struct listnode
*node
= NULL
;
5450 char *vrf_name
= NULL
;
5451 bool all_vrf
= FALSE
;
5452 int ret
= CMD_SUCCESS
;
5455 uint8_t use_vrf
= 0;
5456 json_object
*json
= NULL
;
5458 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5461 json
= json_object_new_object();
5463 /* vrf input is provided could be all or specific vrf*/
5467 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5468 if (!ospf
->oi_running
)
5470 ret
= show_ip_ospf_neighbor_detail_all_common(
5471 vty
, ospf
, json
, uj
, use_vrf
);
5475 vty_out(vty
, "%s\n",
5476 json_object_to_json_string_ext(
5477 json
, JSON_C_TO_STRING_PRETTY
));
5478 json_object_free(json
);
5483 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5484 if (ospf
== NULL
|| !ospf
->oi_running
) {
5486 json_object_free(json
);
5490 /* Display default ospf (instance 0) info */
5491 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5492 if (ospf
== NULL
|| !ospf
->oi_running
) {
5494 json_object_free(json
);
5500 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
,
5503 vty_out(vty
, "%s\n",
5504 json_object_to_json_string_ext(
5505 json
, JSON_C_TO_STRING_PRETTY
));
5510 json_object_free(json
);
5515 DEFUN (show_ip_ospf_instance_neighbor_detail_all
,
5516 show_ip_ospf_instance_neighbor_detail_all_cmd
,
5517 "show ip ospf (1-65535) neighbor detail all [json]",
5520 "OSPF information\n"
5523 "detail of all neighbors\n"
5524 "include down status neighbor\n"
5529 unsigned short instance
= 0;
5530 bool uj
= use_json(argc
, argv
);
5531 json_object
*json
= NULL
;
5532 int ret
= CMD_SUCCESS
;
5534 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5535 ospf
= ospf_lookup_instance(instance
);
5537 return CMD_NOT_MY_INSTANCE
;
5539 if (!ospf
->oi_running
)
5543 json
= json_object_new_object();
5545 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
, uj
, 0);
5548 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5549 json
, JSON_C_TO_STRING_PRETTY
));
5550 json_object_free(json
);
5556 static int show_ip_ospf_neighbor_int_detail_common(struct vty
*vty
,
5559 struct cmd_token
**argv
,
5562 struct ospf_interface
*oi
;
5563 struct interface
*ifp
;
5564 struct route_node
*rn
, *nrn
;
5565 struct ospf_neighbor
*nbr
;
5566 json_object
*json
= NULL
;
5569 json
= json_object_new_object();
5571 if (ospf
->instance
) {
5573 json_object_int_add(json
, "ospfInstance",
5576 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5579 ifp
= if_lookup_by_name(argv
[arg_base
]->arg
, ospf
->vrf_id
);
5582 vty_out(vty
, "No such interface.\n");
5584 vty_out(vty
, "{}\n");
5585 json_object_free(json
);
5590 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
5591 if ((oi
= rn
->info
)) {
5592 for (nrn
= route_top(oi
->nbrs
); nrn
;
5593 nrn
= route_next(nrn
)) {
5594 if ((nbr
= nrn
->info
)) {
5595 if (nbr
!= oi
->nbr_self
) {
5596 if (nbr
->state
!= NSM_Down
)
5597 show_ip_ospf_neighbor_detail_sub(
5607 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5608 json
, JSON_C_TO_STRING_PRETTY
));
5609 json_object_free(json
);
5616 DEFUN (show_ip_ospf_neighbor_int_detail
,
5617 show_ip_ospf_neighbor_int_detail_cmd
,
5618 "show ip ospf neighbor IFNAME detail [json]",
5621 "OSPF information\n"
5624 "detail of all neighbors\n"
5628 bool uj
= use_json(argc
, argv
);
5629 struct listnode
*node
= NULL
;
5630 int ret
= CMD_SUCCESS
;
5631 bool ospf_output
= FALSE
;
5633 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5634 if (!ospf
->oi_running
)
5637 ret
= show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, 0,
5642 vty_out(vty
, "%% OSPF instance not found\n");
5647 DEFUN (show_ip_ospf_instance_neighbor_int_detail
,
5648 show_ip_ospf_instance_neighbor_int_detail_cmd
,
5649 "show ip ospf (1-65535) neighbor IFNAME detail [json]",
5652 "OSPF information\n"
5656 "detail of all neighbors\n"
5662 unsigned short instance
= 0;
5663 bool uj
= use_json(argc
, argv
);
5665 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5666 ospf
= ospf_lookup_instance(instance
);
5668 return CMD_NOT_MY_INSTANCE
;
5670 if (!ospf
->oi_running
)
5673 return show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, idx_ifname
,
5677 /* Show functions */
5678 static int show_lsa_summary(struct vty
*vty
, struct ospf_lsa
*lsa
, int self
)
5680 struct router_lsa
*rl
;
5681 struct summary_lsa
*sl
;
5682 struct as_external_lsa
*asel
;
5683 struct prefix_ipv4 p
;
5686 /* If self option is set, check LSA self flag. */
5687 if (self
== 0 || IS_LSA_SELF(lsa
)) {
5688 /* LSA common part show. */
5689 vty_out(vty
, "%-15s ", inet_ntoa(lsa
->data
->id
));
5690 vty_out(vty
, "%-15s %4d 0x%08lx 0x%04x",
5691 inet_ntoa(lsa
->data
->adv_router
), LS_AGE(lsa
),
5692 (unsigned long)ntohl(lsa
->data
->ls_seqnum
),
5693 ntohs(lsa
->data
->checksum
));
5694 /* LSA specific part show. */
5695 switch (lsa
->data
->type
) {
5696 case OSPF_ROUTER_LSA
:
5697 rl
= (struct router_lsa
*)lsa
->data
;
5698 vty_out(vty
, " %-d", ntohs(rl
->links
));
5700 case OSPF_SUMMARY_LSA
:
5701 sl
= (struct summary_lsa
*)lsa
->data
;
5704 p
.prefix
= sl
->header
.id
;
5705 p
.prefixlen
= ip_masklen(sl
->mask
);
5706 apply_mask_ipv4(&p
);
5708 vty_out(vty
, " %s/%d", inet_ntoa(p
.prefix
),
5711 case OSPF_AS_EXTERNAL_LSA
:
5712 case OSPF_AS_NSSA_LSA
:
5713 asel
= (struct as_external_lsa
*)lsa
->data
;
5716 p
.prefix
= asel
->header
.id
;
5717 p
.prefixlen
= ip_masklen(asel
->mask
);
5718 apply_mask_ipv4(&p
);
5720 vty_out(vty
, " %s %s/%d [0x%lx]",
5721 IS_EXTERNAL_METRIC(asel
->e
[0].tos
)
5724 inet_ntoa(p
.prefix
), p
.prefixlen
,
5725 (unsigned long)ntohl(
5726 asel
->e
[0].route_tag
));
5728 case OSPF_NETWORK_LSA
:
5729 case OSPF_ASBR_SUMMARY_LSA
:
5730 case OSPF_OPAQUE_LINK_LSA
:
5731 case OSPF_OPAQUE_AREA_LSA
:
5732 case OSPF_OPAQUE_AS_LSA
:
5742 static const char *show_database_desc
[] = {
5744 "Router Link States",
5746 "Summary Link States",
5747 "ASBR-Summary Link States",
5748 "AS External Link States",
5749 "Group Membership LSA",
5750 "NSSA-external Link States",
5752 "Link-Local Opaque-LSA",
5753 "Area-Local Opaque-LSA",
5754 "AS-external Opaque-LSA",
5757 static const char *show_database_header
[] = {
5759 "Link ID ADV Router Age Seq# CkSum Link count",
5760 "Link ID ADV Router Age Seq# CkSum",
5761 "Link ID ADV Router Age Seq# CkSum Route",
5762 "Link ID ADV Router Age Seq# CkSum",
5763 "Link ID ADV Router Age Seq# CkSum Route",
5764 " --- header for Group Member ----",
5765 "Link ID ADV Router Age Seq# CkSum Route",
5767 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5768 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5769 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5772 static void show_ip_ospf_database_header(struct vty
*vty
, struct ospf_lsa
*lsa
)
5774 struct router_lsa
*rlsa
= (struct router_lsa
*)lsa
->data
;
5776 vty_out(vty
, " LS age: %d\n", LS_AGE(lsa
));
5777 vty_out(vty
, " Options: 0x%-2x : %s\n", lsa
->data
->options
,
5778 ospf_options_dump(lsa
->data
->options
));
5779 vty_out(vty
, " LS Flags: 0x%-2x %s\n", lsa
->flags
,
5780 ((lsa
->flags
& OSPF_LSA_LOCAL_XLT
) ? "(Translated from Type-7)"
5783 if (lsa
->data
->type
== OSPF_ROUTER_LSA
) {
5784 vty_out(vty
, " Flags: 0x%x", rlsa
->flags
);
5787 vty_out(vty
, " :%s%s%s%s",
5788 IS_ROUTER_LSA_BORDER(rlsa
) ? " ABR" : "",
5789 IS_ROUTER_LSA_EXTERNAL(rlsa
) ? " ASBR" : "",
5790 IS_ROUTER_LSA_VIRTUAL(rlsa
) ? " VL-endpoint"
5792 IS_ROUTER_LSA_SHORTCUT(rlsa
) ? " Shortcut"
5797 vty_out(vty
, " LS Type: %s\n",
5798 lookup_msg(ospf_lsa_type_msg
, lsa
->data
->type
, NULL
));
5799 vty_out(vty
, " Link State ID: %s %s\n", inet_ntoa(lsa
->data
->id
),
5800 lookup_msg(ospf_link_state_id_type_msg
, lsa
->data
->type
, NULL
));
5801 vty_out(vty
, " Advertising Router: %s\n",
5802 inet_ntoa(lsa
->data
->adv_router
));
5803 vty_out(vty
, " LS Seq Number: %08lx\n",
5804 (unsigned long)ntohl(lsa
->data
->ls_seqnum
));
5805 vty_out(vty
, " Checksum: 0x%04x\n", ntohs(lsa
->data
->checksum
));
5806 vty_out(vty
, " Length: %d\n\n", ntohs(lsa
->data
->length
));
5809 const char *link_type_desc
[] = {
5811 "another Router (point-to-point)",
5812 "a Transit Network",
5817 const char *link_id_desc
[] = {
5818 "(null)", "Neighboring Router ID", "Designated Router address",
5819 "Net", "Neighboring Router ID",
5822 const char *link_data_desc
[] = {
5823 "(null)", "Router Interface address", "Router Interface address",
5824 "Network Mask", "Router Interface address",
5827 /* Show router-LSA each Link information. */
5828 static void show_ip_ospf_database_router_links(struct vty
*vty
,
5829 struct router_lsa
*rl
)
5834 len
= ntohs(rl
->header
.length
) - 4;
5835 for (i
= 0; i
< ntohs(rl
->links
) && len
> 0; len
-= 12, i
++) {
5836 type
= rl
->link
[i
].type
;
5838 vty_out(vty
, " Link connected to: %s\n",
5839 link_type_desc
[type
]);
5840 vty_out(vty
, " (Link ID) %s: %s\n", link_id_desc
[type
],
5841 inet_ntoa(rl
->link
[i
].link_id
));
5842 vty_out(vty
, " (Link Data) %s: %s\n", link_data_desc
[type
],
5843 inet_ntoa(rl
->link
[i
].link_data
));
5844 vty_out(vty
, " Number of TOS metrics: 0\n");
5845 vty_out(vty
, " TOS 0 Metric: %d\n",
5846 ntohs(rl
->link
[i
].metric
));
5851 /* Show router-LSA detail information. */
5852 static int show_router_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5855 struct router_lsa
*rl
= (struct router_lsa
*)lsa
->data
;
5857 show_ip_ospf_database_header(vty
, lsa
);
5859 vty_out(vty
, " Number of Links: %d\n\n", ntohs(rl
->links
));
5861 show_ip_ospf_database_router_links(vty
, rl
);
5868 /* Show network-LSA detail information. */
5869 static int show_network_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5874 struct network_lsa
*nl
= (struct network_lsa
*)lsa
->data
;
5876 show_ip_ospf_database_header(vty
, lsa
);
5878 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(nl
->mask
));
5880 length
= ntohs(lsa
->data
->length
) - OSPF_LSA_HEADER_SIZE
- 4;
5882 for (i
= 0; length
> 0; i
++, length
-= 4)
5883 vty_out(vty
, " Attached Router: %s\n",
5884 inet_ntoa(nl
->routers
[i
]));
5892 /* Show summary-LSA detail information. */
5893 static int show_summary_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5896 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
5898 show_ip_ospf_database_header(vty
, lsa
);
5900 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(sl
->mask
));
5901 vty_out(vty
, " TOS: 0 Metric: %d\n",
5902 GET_METRIC(sl
->metric
));
5909 /* Show summary-ASBR-LSA detail information. */
5910 static int show_summary_asbr_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5913 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
5915 show_ip_ospf_database_header(vty
, lsa
);
5917 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(sl
->mask
));
5918 vty_out(vty
, " TOS: 0 Metric: %d\n",
5919 GET_METRIC(sl
->metric
));
5926 /* Show AS-external-LSA detail information. */
5927 static int show_as_external_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5930 struct as_external_lsa
*al
=
5931 (struct as_external_lsa
*)lsa
->data
;
5933 show_ip_ospf_database_header(vty
, lsa
);
5935 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(al
->mask
));
5936 vty_out(vty
, " Metric Type: %s\n",
5937 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
5938 ? "2 (Larger than any link state path)"
5940 vty_out(vty
, " TOS: 0\n");
5941 vty_out(vty
, " Metric: %d\n",
5942 GET_METRIC(al
->e
[0].metric
));
5943 vty_out(vty
, " Forward Address: %s\n",
5944 inet_ntoa(al
->e
[0].fwd_addr
));
5947 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
5948 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
5955 show_as_external_lsa_stdvty (struct ospf_lsa
*lsa
)
5957 struct as_external_lsa
*al
= (struct as_external_lsa
*) lsa
->data
;
5959 /* show_ip_ospf_database_header (vty, lsa); */
5961 zlog_debug( " Network Mask: /%d%s",
5962 ip_masklen (al
->mask
), "\n");
5963 zlog_debug( " Metric Type: %s%s",
5964 IS_EXTERNAL_METRIC (al
->e
[0].tos
) ?
5965 "2 (Larger than any link state path)" : "1", "\n");
5966 zlog_debug( " TOS: 0%s", "\n");
5967 zlog_debug( " Metric: %d%s",
5968 GET_METRIC (al
->e
[0].metric
), "\n");
5969 zlog_debug( " Forward Address: %s%s",
5970 inet_ntoa (al
->e
[0].fwd_addr
), "\n");
5972 zlog_debug( " External Route Tag: %"ROUTE_TAG_PRI
"%s%s",
5973 (route_tag_t
)ntohl (al
->e
[0].route_tag
), "\n", "\n");
5978 /* Show AS-NSSA-LSA detail information. */
5979 static int show_as_nssa_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5982 struct as_external_lsa
*al
=
5983 (struct as_external_lsa
*)lsa
->data
;
5985 show_ip_ospf_database_header(vty
, lsa
);
5987 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(al
->mask
));
5988 vty_out(vty
, " Metric Type: %s\n",
5989 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
5990 ? "2 (Larger than any link state path)"
5992 vty_out(vty
, " TOS: 0\n");
5993 vty_out(vty
, " Metric: %d\n",
5994 GET_METRIC(al
->e
[0].metric
));
5995 vty_out(vty
, " NSSA: Forward Address: %s\n",
5996 inet_ntoa(al
->e
[0].fwd_addr
));
5999 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
6000 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6006 static int show_func_dummy(struct vty
*vty
, struct ospf_lsa
*lsa
)
6011 static int show_opaque_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
6014 show_ip_ospf_database_header(vty
, lsa
);
6015 show_opaque_info_detail(vty
, lsa
);
6022 int (*show_function
[])(struct vty
*, struct ospf_lsa
*) = {
6024 show_router_lsa_detail
,
6025 show_network_lsa_detail
,
6026 show_summary_lsa_detail
,
6027 show_summary_asbr_lsa_detail
,
6028 show_as_external_lsa_detail
,
6030 show_as_nssa_lsa_detail
, /* almost same as external */
6032 show_opaque_lsa_detail
,
6033 show_opaque_lsa_detail
,
6034 show_opaque_lsa_detail
,
6037 static void show_lsa_prefix_set(struct vty
*vty
, struct prefix_ls
*lp
,
6038 struct in_addr
*id
, struct in_addr
*adv_router
)
6040 memset(lp
, 0, sizeof(struct prefix_ls
));
6044 else if (adv_router
== NULL
) {
6050 lp
->adv_router
= *adv_router
;
6054 static void show_lsa_detail_proc(struct vty
*vty
, struct route_table
*rt
,
6055 struct in_addr
*id
, struct in_addr
*adv_router
)
6057 struct prefix_ls lp
;
6058 struct route_node
*rn
, *start
;
6059 struct ospf_lsa
*lsa
;
6061 show_lsa_prefix_set(vty
, &lp
, id
, adv_router
);
6062 start
= route_node_get(rt
, (struct prefix
*)&lp
);
6064 route_lock_node(start
);
6065 for (rn
= start
; rn
; rn
= route_next_until(rn
, start
))
6066 if ((lsa
= rn
->info
)) {
6067 if (show_function
[lsa
->data
->type
] != NULL
)
6068 show_function
[lsa
->data
->type
](vty
,
6071 route_unlock_node(start
);
6075 /* Show detail LSA information
6076 -- if id is NULL then show all LSAs. */
6077 static void show_lsa_detail(struct vty
*vty
, struct ospf
*ospf
, int type
,
6078 struct in_addr
*id
, struct in_addr
*adv_router
)
6080 struct listnode
*node
;
6081 struct ospf_area
*area
;
6084 case OSPF_AS_EXTERNAL_LSA
:
6085 case OSPF_OPAQUE_AS_LSA
:
6086 vty_out(vty
, " %s \n\n",
6087 show_database_desc
[type
]);
6088 show_lsa_detail_proc(vty
, AS_LSDB(ospf
, type
), id
, adv_router
);
6091 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6092 vty_out(vty
, "\n %s (Area %s)\n\n",
6093 show_database_desc
[type
],
6094 ospf_area_desc_string(area
));
6095 show_lsa_detail_proc(vty
, AREA_LSDB(area
, type
), id
,
6102 static void show_lsa_detail_adv_router_proc(struct vty
*vty
,
6103 struct route_table
*rt
,
6104 struct in_addr
*adv_router
)
6106 struct route_node
*rn
;
6107 struct ospf_lsa
*lsa
;
6109 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
))
6110 if ((lsa
= rn
->info
))
6111 if (IPV4_ADDR_SAME(adv_router
,
6112 &lsa
->data
->adv_router
)) {
6113 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
6115 if (show_function
[lsa
->data
->type
] != NULL
)
6116 show_function
[lsa
->data
->type
](vty
,
6121 /* Show detail LSA information. */
6122 static void show_lsa_detail_adv_router(struct vty
*vty
, struct ospf
*ospf
,
6123 int type
, struct in_addr
*adv_router
)
6125 struct listnode
*node
;
6126 struct ospf_area
*area
;
6129 case OSPF_AS_EXTERNAL_LSA
:
6130 case OSPF_OPAQUE_AS_LSA
:
6131 vty_out(vty
, " %s \n\n",
6132 show_database_desc
[type
]);
6133 show_lsa_detail_adv_router_proc(vty
, AS_LSDB(ospf
, type
),
6137 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6138 vty_out(vty
, "\n %s (Area %s)\n\n",
6139 show_database_desc
[type
],
6140 ospf_area_desc_string(area
));
6141 show_lsa_detail_adv_router_proc(
6142 vty
, AREA_LSDB(area
, type
), adv_router
);
6148 static void show_ip_ospf_database_summary(struct vty
*vty
, struct ospf
*ospf
,
6151 struct ospf_lsa
*lsa
;
6152 struct route_node
*rn
;
6153 struct ospf_area
*area
;
6154 struct listnode
*node
;
6157 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6158 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6160 case OSPF_AS_EXTERNAL_LSA
:
6161 case OSPF_OPAQUE_AS_LSA
:
6166 if (ospf_lsdb_count_self(area
->lsdb
, type
) > 0
6168 && ospf_lsdb_count(area
->lsdb
, type
) > 0)) {
6169 vty_out(vty
, " %s (Area %s)\n\n",
6170 show_database_desc
[type
],
6171 ospf_area_desc_string(area
));
6172 vty_out(vty
, "%s\n",
6173 show_database_header
[type
]);
6175 LSDB_LOOP (AREA_LSDB(area
, type
), rn
, lsa
)
6176 show_lsa_summary(vty
, lsa
, self
);
6183 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6185 case OSPF_AS_EXTERNAL_LSA
:
6186 case OSPF_OPAQUE_AS_LSA
:
6191 if (ospf_lsdb_count_self(ospf
->lsdb
, type
)
6192 || (!self
&& ospf_lsdb_count(ospf
->lsdb
, type
))) {
6193 vty_out(vty
, " %s\n\n",
6194 show_database_desc
[type
]);
6195 vty_out(vty
, "%s\n", show_database_header
[type
]);
6197 LSDB_LOOP (AS_LSDB(ospf
, type
), rn
, lsa
)
6198 show_lsa_summary(vty
, lsa
, self
);
6207 static void show_ip_ospf_database_maxage(struct vty
*vty
, struct ospf
*ospf
)
6209 struct route_node
*rn
;
6211 vty_out(vty
, "\n MaxAge Link States:\n\n");
6213 for (rn
= route_top(ospf
->maxage_lsa
); rn
; rn
= route_next(rn
)) {
6214 struct ospf_lsa
*lsa
;
6216 if ((lsa
= rn
->info
) != NULL
) {
6217 vty_out(vty
, "Link type: %d\n", lsa
->data
->type
);
6218 vty_out(vty
, "Link State ID: %s\n",
6219 inet_ntoa(lsa
->data
->id
));
6220 vty_out(vty
, "Advertising Router: %s\n",
6221 inet_ntoa(lsa
->data
->adv_router
));
6222 vty_out(vty
, "LSA lock count: %d\n", lsa
->lock
);
6228 #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
6229 #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
6231 #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
6232 #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
6233 #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
6234 #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
6236 #define OSPF_LSA_TYPES_DESC \
6237 "ASBR summary link states\n" \
6238 "External link states\n" \
6239 "Network link states\n" \
6240 "Router link states\n" \
6241 "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \
6242 OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
6243 OSPF_LSA_TYPE_OPAQUE_AS_DESC
6245 static int show_ip_ospf_database_common(struct vty
*vty
, struct ospf
*ospf
,
6246 int arg_base
, int argc
,
6247 struct cmd_token
**argv
,
6252 struct in_addr id
, adv_router
;
6255 vty_out(vty
, "\nOSPF Instance: %d\n", ospf
->instance
);
6257 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
6259 vty_out(vty
, "\n OSPF Router with ID (%s)\n\n",
6260 inet_ntoa(ospf
->router_id
));
6263 if (argc
== arg_base
+ 4) {
6264 show_ip_ospf_database_summary(vty
, ospf
, 0);
6268 /* Set database type to show. */
6269 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
6270 type
= OSPF_ROUTER_LSA
;
6271 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
6272 type
= OSPF_NETWORK_LSA
;
6273 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
6274 type
= OSPF_AS_NSSA_LSA
;
6275 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "su", 2) == 0)
6276 type
= OSPF_SUMMARY_LSA
;
6277 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
6278 type
= OSPF_ASBR_SUMMARY_LSA
;
6279 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
6280 type
= OSPF_AS_EXTERNAL_LSA
;
6281 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "se", 2) == 0) {
6282 show_ip_ospf_database_summary(vty
, ospf
, 1);
6284 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "m", 1) == 0) {
6285 show_ip_ospf_database_maxage(vty
, ospf
);
6287 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
6288 type
= OSPF_OPAQUE_LINK_LSA
;
6289 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
6290 type
= OSPF_OPAQUE_AREA_LSA
;
6291 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
6292 type
= OSPF_OPAQUE_AS_LSA
;
6296 /* `show ip ospf database LSA'. */
6297 if (argc
== arg_base
+ 5)
6298 show_lsa_detail(vty
, ospf
, type
, NULL
, NULL
);
6299 else if (argc
>= arg_base
+ 6) {
6300 ret
= inet_aton(argv
[arg_base
+ 5]->arg
, &id
);
6304 /* `show ip ospf database LSA ID'. */
6305 if (argc
== arg_base
+ 6)
6306 show_lsa_detail(vty
, ospf
, type
, &id
, NULL
);
6307 /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */
6308 else if (argc
== arg_base
+ 7) {
6309 if (strncmp(argv
[arg_base
+ 6]->text
, "s", 1) == 0)
6310 adv_router
= ospf
->router_id
;
6312 ret
= inet_aton(argv
[arg_base
+ 7]->arg
,
6317 show_lsa_detail(vty
, ospf
, type
, &id
, &adv_router
);
6324 DEFUN (show_ip_ospf_database_max
,
6325 show_ip_ospf_database_max_cmd
,
6326 "show ip ospf [vrf <NAME|all>] database <max-age|self-originate>",
6329 "OSPF information\n"
6332 "Database summary\n"
6333 "LSAs in MaxAge list\n"
6334 "Self-originated link states\n")
6336 struct ospf
*ospf
= NULL
;
6337 struct listnode
*node
= NULL
;
6338 char *vrf_name
= NULL
;
6339 bool all_vrf
= FALSE
;
6340 int ret
= CMD_SUCCESS
;
6343 uint8_t use_vrf
= 0;
6345 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
6348 bool ospf_output
= FALSE
;
6353 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6354 if (!ospf
->oi_running
)
6357 ret
= show_ip_ospf_database_common(
6358 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
,
6363 vty_out(vty
, "%% OSPF instance not found\n");
6365 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6366 if (ospf
== NULL
|| !ospf
->oi_running
) {
6367 vty_out(vty
, "%% OSPF instance not found\n");
6370 ret
= (show_ip_ospf_database_common(
6371 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
,
6375 /* Display default ospf (instance 0) info */
6376 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6377 if (ospf
== NULL
|| !ospf
->oi_running
) {
6378 vty_out(vty
, "%% OSPF instance not found\n");
6382 ret
= show_ip_ospf_database_common(vty
, ospf
, 0, argc
, argv
,
6389 DEFUN (show_ip_ospf_instance_database
,
6390 show_ip_ospf_instance_database_cmd
,
6391 "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>]]]",
6394 "OSPF information\n"
6397 "Database summary\n"
6399 "Link State ID (as an IP address)\n"
6400 "Self-originated link states\n"
6401 "Advertising Router link states\n"
6402 "Advertising Router (as an IP address)\n")
6405 unsigned short instance
= 0;
6406 struct listnode
*node
= NULL
;
6407 char *vrf_name
= NULL
;
6408 bool all_vrf
= FALSE
;
6409 int ret
= CMD_SUCCESS
;
6412 uint8_t use_vrf
= 0;
6414 if (argv_find(argv
, argc
, "(1-65535)", &idx
)) {
6415 instance
= strtoul(argv
[idx
]->arg
, NULL
, 10);
6416 ospf
= ospf_lookup_instance(instance
);
6418 return CMD_NOT_MY_INSTANCE
;
6419 if (!ospf
->oi_running
)
6422 return (show_ip_ospf_database_common(vty
, ospf
, idx
? 1 : 0,
6423 argc
, argv
, use_vrf
));
6424 } else if (argv_find(argv
, argc
, "vrf", &idx
)) {
6425 vrf_name
= argv
[++idx
]->arg
;
6426 all_vrf
= strmatch(vrf_name
, "all");
6432 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6433 if (!ospf
->oi_running
)
6435 ret
= (show_ip_ospf_database_common(
6436 vty
, ospf
, idx
? 2 : 0, argc
, argv
,
6440 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6441 if ((ospf
== NULL
) || !ospf
->oi_running
) {
6442 vty_out(vty
, "%% OSPF instance not found\n");
6446 ret
= (show_ip_ospf_database_common(
6447 vty
, ospf
, idx
? 2 : 0, argc
, argv
, use_vrf
));
6450 /* Display default ospf (instance 0) info */
6451 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6452 if (ospf
== NULL
|| !ospf
->oi_running
) {
6453 vty_out(vty
, "%% OSPF instance not found\n");
6457 ret
= (show_ip_ospf_database_common(vty
, ospf
, 0, argc
, argv
,
6464 DEFUN (show_ip_ospf_instance_database_max
,
6465 show_ip_ospf_instance_database_max_cmd
,
6466 "show ip ospf (1-65535) database <max-age|self-originate>",
6469 "OSPF information\n"
6471 "Database summary\n"
6472 "LSAs in MaxAge list\n"
6473 "Self-originated link states\n")
6477 unsigned short instance
= 0;
6479 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
6481 ospf
= ospf_lookup_instance(instance
);
6483 return CMD_NOT_MY_INSTANCE
;
6485 if (!ospf
->oi_running
) {
6486 vty_out(vty
, "%% OSPF instance not found\n");
6490 return show_ip_ospf_database_common(vty
, ospf
, 1, argc
, argv
, 0);
6494 static int show_ip_ospf_database_type_adv_router_common(struct vty
*vty
,
6496 int arg_base
, int argc
,
6497 struct cmd_token
**argv
,
6502 struct in_addr adv_router
;
6505 vty_out(vty
, "\nOSPF Instance: %d\n", ospf
->instance
);
6507 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
6509 vty_out(vty
, "\n OSPF Router with ID (%s)\n\n",
6510 inet_ntoa(ospf
->router_id
));
6512 /* Set database type to show. */
6513 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
6514 type
= OSPF_ROUTER_LSA
;
6515 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
6516 type
= OSPF_NETWORK_LSA
;
6517 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
6518 type
= OSPF_AS_NSSA_LSA
;
6519 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "s", 1) == 0)
6520 type
= OSPF_SUMMARY_LSA
;
6521 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
6522 type
= OSPF_ASBR_SUMMARY_LSA
;
6523 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
6524 type
= OSPF_AS_EXTERNAL_LSA
;
6525 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
6526 type
= OSPF_OPAQUE_LINK_LSA
;
6527 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
6528 type
= OSPF_OPAQUE_AREA_LSA
;
6529 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
6530 type
= OSPF_OPAQUE_AS_LSA
;
6534 /* `show ip ospf database LSA adv-router ADV_ROUTER'. */
6535 if (strncmp(argv
[arg_base
+ 5]->text
, "s", 1) == 0)
6536 adv_router
= ospf
->router_id
;
6538 ret
= inet_aton(argv
[arg_base
+ 6]->arg
, &adv_router
);
6543 show_lsa_detail_adv_router(vty
, ospf
, type
, &adv_router
);
6548 DEFUN (show_ip_ospf_instance_database_type_adv_router
,
6549 show_ip_ospf_instance_database_type_adv_router_cmd
,
6550 "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>",
6553 "OSPF information\n"
6556 "Database summary\n"
6558 "Advertising Router link states\n"
6559 "Advertising Router (as an IP address)\n"
6560 "Self-originated link states\n")
6562 struct ospf
*ospf
= NULL
;
6563 unsigned short instance
= 0;
6564 struct listnode
*node
= NULL
;
6565 char *vrf_name
= NULL
;
6566 bool all_vrf
= FALSE
;
6567 int ret
= CMD_SUCCESS
;
6569 int idx
= 0, idx_vrf
= 0;
6570 uint8_t use_vrf
= 0;
6572 if (argv_find(argv
, argc
, "(1-65535)", &idx
)) {
6573 instance
= strtoul(argv
[idx
]->arg
, NULL
, 10);
6574 ospf
= ospf_lookup_instance(instance
);
6576 return CMD_NOT_MY_INSTANCE
;
6577 if (!ospf
->oi_running
) {
6578 vty_out(vty
, "%% OSPF instance not found\n");
6582 return (show_ip_ospf_database_type_adv_router_common(
6583 vty
, ospf
, idx
? 1 : 0, argc
, argv
, use_vrf
));
6586 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
6589 bool ospf_output
= FALSE
;
6594 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6595 if (!ospf
->oi_running
)
6598 ret
= show_ip_ospf_database_type_adv_router_common(
6599 vty
, ospf
, idx
? 1 : 0, argc
, argv
,
6603 vty_out(vty
, "%% OSPF instance not found\n");
6605 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6606 if ((ospf
== NULL
) || !ospf
->oi_running
) {
6607 vty_out(vty
, "%% OSPF instance not found\n");
6611 ret
= show_ip_ospf_database_type_adv_router_common(
6612 vty
, ospf
, idx
? 1 : 0, argc
, argv
, use_vrf
);
6615 /* Display default ospf (instance 0) info */
6616 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6617 if (ospf
== NULL
|| !ospf
->oi_running
) {
6618 vty_out(vty
, "%% OSPF instance not found\n");
6622 ret
= show_ip_ospf_database_type_adv_router_common(
6623 vty
, ospf
, idx
? 1 : 0, argc
, argv
, use_vrf
);
6626 /*return (show_ip_ospf_database_type_adv_router_common(
6627 vty, ospf, idx ? 1 : 0, argc, argv));*/
6630 DEFUN (ip_ospf_authentication_args
,
6631 ip_ospf_authentication_args_addr_cmd
,
6632 "ip ospf authentication <null|message-digest> [A.B.C.D]",
6634 "OSPF interface commands\n"
6635 "Enable authentication on this interface\n"
6636 "Use null authentication\n"
6637 "Use message-digest authentication\n"
6638 "Address of interface\n")
6640 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6641 int idx_encryption
= 3;
6643 struct in_addr addr
;
6645 struct ospf_if_params
*params
;
6647 params
= IF_DEF_PARAMS(ifp
);
6650 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6653 "Please specify interface address by A.B.C.D\n");
6654 return CMD_WARNING_CONFIG_FAILED
;
6657 params
= ospf_get_if_params(ifp
, addr
);
6658 ospf_if_update_params(ifp
, addr
);
6661 /* Handle null authentication */
6662 if (argv
[idx_encryption
]->arg
[0] == 'n') {
6663 SET_IF_PARAM(params
, auth_type
);
6664 params
->auth_type
= OSPF_AUTH_NULL
;
6668 /* Handle message-digest authentication */
6669 if (argv
[idx_encryption
]->arg
[0] == 'm') {
6670 SET_IF_PARAM(params
, auth_type
);
6671 params
->auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
6675 vty_out(vty
, "You shouldn't get here!\n");
6676 return CMD_WARNING_CONFIG_FAILED
;
6679 DEFUN (ip_ospf_authentication
,
6680 ip_ospf_authentication_addr_cmd
,
6681 "ip ospf authentication [A.B.C.D]",
6683 "OSPF interface commands\n"
6684 "Enable authentication on this interface\n"
6685 "Address of interface\n")
6687 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6689 struct in_addr addr
;
6691 struct ospf_if_params
*params
;
6693 params
= IF_DEF_PARAMS(ifp
);
6696 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6699 "Please specify interface address by A.B.C.D\n");
6700 return CMD_WARNING_CONFIG_FAILED
;
6703 params
= ospf_get_if_params(ifp
, addr
);
6704 ospf_if_update_params(ifp
, addr
);
6707 SET_IF_PARAM(params
, auth_type
);
6708 params
->auth_type
= OSPF_AUTH_SIMPLE
;
6713 DEFUN (no_ip_ospf_authentication_args
,
6714 no_ip_ospf_authentication_args_addr_cmd
,
6715 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
6718 "OSPF interface commands\n"
6719 "Enable authentication on this interface\n"
6720 "Use null authentication\n"
6721 "Use message-digest authentication\n"
6722 "Address of interface\n")
6724 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6725 int idx_encryption
= 4;
6727 struct in_addr addr
;
6729 struct ospf_if_params
*params
;
6730 struct route_node
*rn
;
6733 params
= IF_DEF_PARAMS(ifp
);
6736 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6739 "Please specify interface address by A.B.C.D\n");
6740 return CMD_WARNING_CONFIG_FAILED
;
6743 params
= ospf_lookup_if_params(ifp
, addr
);
6744 if (params
== NULL
) {
6745 vty_out(vty
, "Ip Address specified is unknown\n");
6746 return CMD_WARNING_CONFIG_FAILED
;
6748 params
->auth_type
= OSPF_AUTH_NOTSET
;
6749 UNSET_IF_PARAM(params
, auth_type
);
6750 if (params
!= IF_DEF_PARAMS(ifp
)) {
6751 ospf_free_if_params(ifp
, addr
);
6752 ospf_if_update_params(ifp
, addr
);
6755 if (argv
[idx_encryption
]->arg
[0] == 'n') {
6756 auth_type
= OSPF_AUTH_NULL
;
6757 } else if (argv
[idx_encryption
]->arg
[0] == 'm') {
6758 auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
6760 vty_out(vty
, "Unexpected input encountered\n");
6761 return CMD_WARNING_CONFIG_FAILED
;
6764 * Here we have a case where the user has entered
6765 * 'no ip ospf authentication (null | message_digest )'
6766 * we need to find if we have any ip addresses underneath it
6768 * correspond to the associated type.
6770 if (params
->auth_type
== auth_type
) {
6771 params
->auth_type
= OSPF_AUTH_NOTSET
;
6772 UNSET_IF_PARAM(params
, auth_type
);
6775 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
6776 rn
= route_next(rn
)) {
6777 if ((params
= rn
->info
)) {
6778 if (params
->auth_type
== auth_type
) {
6779 params
->auth_type
= OSPF_AUTH_NOTSET
;
6780 UNSET_IF_PARAM(params
, auth_type
);
6781 if (params
!= IF_DEF_PARAMS(ifp
)) {
6782 ospf_free_if_params(
6783 ifp
, rn
->p
.u
.prefix4
);
6784 ospf_if_update_params(
6785 ifp
, rn
->p
.u
.prefix4
);
6795 DEFUN (no_ip_ospf_authentication
,
6796 no_ip_ospf_authentication_addr_cmd
,
6797 "no ip ospf authentication [A.B.C.D]",
6800 "OSPF interface commands\n"
6801 "Enable authentication on this interface\n"
6802 "Address of interface\n")
6804 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6806 struct in_addr addr
;
6808 struct ospf_if_params
*params
;
6809 struct route_node
*rn
;
6811 params
= IF_DEF_PARAMS(ifp
);
6814 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6817 "Please specify interface address by A.B.C.D\n");
6818 return CMD_WARNING_CONFIG_FAILED
;
6821 params
= ospf_lookup_if_params(ifp
, addr
);
6822 if (params
== NULL
) {
6823 vty_out(vty
, "Ip Address specified is unknown\n");
6824 return CMD_WARNING_CONFIG_FAILED
;
6827 params
->auth_type
= OSPF_AUTH_NOTSET
;
6828 UNSET_IF_PARAM(params
, auth_type
);
6829 if (params
!= IF_DEF_PARAMS(ifp
)) {
6830 ospf_free_if_params(ifp
, addr
);
6831 ospf_if_update_params(ifp
, addr
);
6835 * When a user enters 'no ip ospf authentication'
6836 * We should remove all authentication types from
6839 if ((params
->auth_type
== OSPF_AUTH_NULL
)
6840 || (params
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
6841 || (params
->auth_type
== OSPF_AUTH_SIMPLE
)) {
6842 params
->auth_type
= OSPF_AUTH_NOTSET
;
6843 UNSET_IF_PARAM(params
, auth_type
);
6846 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
6847 rn
= route_next(rn
)) {
6848 if ((params
= rn
->info
)) {
6850 if ((params
->auth_type
== OSPF_AUTH_NULL
)
6851 || (params
->auth_type
6852 == OSPF_AUTH_CRYPTOGRAPHIC
)
6853 || (params
->auth_type
6854 == OSPF_AUTH_SIMPLE
)) {
6855 params
->auth_type
= OSPF_AUTH_NOTSET
;
6856 UNSET_IF_PARAM(params
, auth_type
);
6857 if (params
!= IF_DEF_PARAMS(ifp
)) {
6858 ospf_free_if_params(
6859 ifp
, rn
->p
.u
.prefix4
);
6860 ospf_if_update_params(
6861 ifp
, rn
->p
.u
.prefix4
);
6872 DEFUN (ip_ospf_authentication_key
,
6873 ip_ospf_authentication_key_addr_cmd
,
6874 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
6876 "OSPF interface commands\n"
6877 "Authentication password (key)\n"
6878 "The OSPF password (key)\n"
6879 "Address of interface\n")
6881 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6883 struct in_addr addr
;
6884 struct ospf_if_params
*params
;
6886 params
= IF_DEF_PARAMS(ifp
);
6888 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6889 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6891 "Please specify interface address by A.B.C.D\n");
6892 return CMD_WARNING_CONFIG_FAILED
;
6895 params
= ospf_get_if_params(ifp
, addr
);
6896 ospf_if_update_params(ifp
, addr
);
6899 strlcpy((char *)params
->auth_simple
, argv
[3]->arg
,
6900 sizeof(params
->auth_simple
));
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 strlcpy((char *)ck
->auth_key
, cryptkey
, sizeof(ck
->auth_key
));
7011 ospf_crypt_key_add(params
->auth_crypt
, ck
);
7012 SET_IF_PARAM(params
, auth_crypt
);
7017 DEFUN_HIDDEN (ospf_message_digest_key
,
7018 ospf_message_digest_key_cmd
,
7019 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7020 "OSPF interface commands\n"
7021 "Message digest authentication password (key)\n"
7023 "Use MD5 algorithm\n"
7024 "The OSPF password (key)\n"
7025 "Address of interface\n")
7027 return ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7030 DEFUN (no_ip_ospf_message_digest_key
,
7031 no_ip_ospf_message_digest_key_cmd
,
7032 "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7035 "OSPF interface commands\n"
7036 "Message digest authentication password (key)\n"
7038 "Use MD5 algorithm\n"
7039 "The OSPF password (key)\n"
7040 "Address of interface\n")
7042 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7044 struct crypt_key
*ck
;
7046 struct in_addr addr
;
7047 struct ospf_if_params
*params
;
7048 params
= IF_DEF_PARAMS(ifp
);
7050 argv_find(argv
, argc
, "(1-255)", &idx
);
7051 char *keyid
= argv
[idx
]->arg
;
7053 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7054 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7056 "Please specify interface address by A.B.C.D\n");
7057 return CMD_WARNING_CONFIG_FAILED
;
7060 params
= ospf_lookup_if_params(ifp
, addr
);
7065 key_id
= strtol(keyid
, NULL
, 10);
7066 ck
= ospf_crypt_key_lookup(params
->auth_crypt
, key_id
);
7068 vty_out(vty
, "OSPF: Key %d does not exist\n", key_id
);
7069 return CMD_WARNING_CONFIG_FAILED
;
7072 ospf_crypt_key_delete(params
->auth_crypt
, key_id
);
7074 if (params
!= IF_DEF_PARAMS(ifp
)) {
7075 ospf_free_if_params(ifp
, addr
);
7076 ospf_if_update_params(ifp
, addr
);
7082 DEFUN_HIDDEN (no_ospf_message_digest_key
,
7083 no_ospf_message_digest_key_cmd
,
7084 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7086 "OSPF interface commands\n"
7087 "Message digest authentication password (key)\n"
7089 "Use MD5 algorithm\n"
7090 "The OSPF password (key)\n"
7091 "Address of interface\n")
7093 return no_ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7096 DEFUN (ip_ospf_cost
,
7098 "ip ospf cost (1-65535) [A.B.C.D]",
7100 "OSPF interface commands\n"
7103 "Address of interface\n")
7105 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7107 uint32_t cost
= OSPF_OUTPUT_COST_DEFAULT
;
7108 struct in_addr addr
;
7109 struct ospf_if_params
*params
;
7110 params
= IF_DEF_PARAMS(ifp
);
7113 char *coststr
= NULL
, *ifaddr
= NULL
;
7115 argv_find(argv
, argc
, "(1-65535)", &idx
);
7116 coststr
= argv
[idx
]->arg
;
7117 cost
= strtol(coststr
, NULL
, 10);
7119 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7121 if (!inet_aton(ifaddr
, &addr
)) {
7123 "Please specify interface address by A.B.C.D\n");
7124 return CMD_WARNING_CONFIG_FAILED
;
7127 params
= ospf_get_if_params(ifp
, addr
);
7128 ospf_if_update_params(ifp
, addr
);
7131 SET_IF_PARAM(params
, output_cost_cmd
);
7132 params
->output_cost_cmd
= cost
;
7134 ospf_if_recalculate_output_cost(ifp
);
7139 DEFUN_HIDDEN (ospf_cost
,
7141 "ospf cost (1-65535) [A.B.C.D]",
7142 "OSPF interface commands\n"
7145 "Address of interface\n")
7147 return ip_ospf_cost(self
, vty
, argc
, argv
);
7150 DEFUN (no_ip_ospf_cost
,
7151 no_ip_ospf_cost_cmd
,
7152 "no ip ospf cost [(1-65535)] [A.B.C.D]",
7155 "OSPF interface commands\n"
7158 "Address of interface\n")
7160 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7162 struct in_addr addr
;
7163 struct ospf_if_params
*params
;
7165 params
= IF_DEF_PARAMS(ifp
);
7168 char *ifaddr
= NULL
;
7169 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7171 /* According to the semantics we are mimicking "no ip ospf cost N" is
7172 * always treated as "no ip ospf cost" regardless of the actual value
7173 * of N already configured for the interface. Thus ignore cost. */
7176 if (!inet_aton(ifaddr
, &addr
)) {
7178 "Please specify interface address by A.B.C.D\n");
7179 return CMD_WARNING_CONFIG_FAILED
;
7182 params
= ospf_lookup_if_params(ifp
, addr
);
7187 UNSET_IF_PARAM(params
, output_cost_cmd
);
7189 if (params
!= IF_DEF_PARAMS(ifp
)) {
7190 ospf_free_if_params(ifp
, addr
);
7191 ospf_if_update_params(ifp
, addr
);
7194 ospf_if_recalculate_output_cost(ifp
);
7199 DEFUN_HIDDEN (no_ospf_cost
,
7201 "no ospf cost [(1-65535)] [A.B.C.D]",
7203 "OSPF interface commands\n"
7206 "Address of interface\n")
7208 return no_ip_ospf_cost(self
, vty
, argc
, argv
);
7211 static void ospf_nbr_timer_update(struct ospf_interface
*oi
)
7213 struct route_node
*rn
;
7214 struct ospf_neighbor
*nbr
;
7216 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
7217 if ((nbr
= rn
->info
)) {
7218 nbr
->v_inactivity
= OSPF_IF_PARAM(oi
, v_wait
);
7219 nbr
->v_db_desc
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7220 nbr
->v_ls_req
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7221 nbr
->v_ls_upd
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7225 static int ospf_vty_dead_interval_set(struct vty
*vty
, const char *interval_str
,
7226 const char *nbr_str
,
7227 const char *fast_hello_str
)
7229 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7232 struct in_addr addr
;
7234 struct ospf_if_params
*params
;
7235 struct ospf_interface
*oi
;
7236 struct route_node
*rn
;
7238 params
= IF_DEF_PARAMS(ifp
);
7241 ret
= inet_aton(nbr_str
, &addr
);
7244 "Please specify interface address by A.B.C.D\n");
7245 return CMD_WARNING_CONFIG_FAILED
;
7248 params
= ospf_get_if_params(ifp
, addr
);
7249 ospf_if_update_params(ifp
, addr
);
7253 seconds
= strtoul(interval_str
, NULL
, 10);
7255 /* reset fast_hello too, just to be sure */
7256 UNSET_IF_PARAM(params
, fast_hello
);
7257 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
7258 } else if (fast_hello_str
) {
7259 hellomult
= strtoul(fast_hello_str
, NULL
, 10);
7260 /* 1s dead-interval with sub-second hellos desired */
7261 seconds
= OSPF_ROUTER_DEAD_INTERVAL_MINIMAL
;
7262 SET_IF_PARAM(params
, fast_hello
);
7263 params
->fast_hello
= hellomult
;
7266 "Please specify dead-interval or hello-multiplier\n");
7267 return CMD_WARNING_CONFIG_FAILED
;
7270 SET_IF_PARAM(params
, v_wait
);
7271 params
->v_wait
= seconds
;
7273 /* Update timer values in neighbor structure. */
7275 struct ospf
*ospf
= NULL
;
7277 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7279 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
7281 ospf_nbr_timer_update(oi
);
7284 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
7285 if ((oi
= rn
->info
))
7286 ospf_nbr_timer_update(oi
);
7292 DEFUN (ip_ospf_dead_interval
,
7293 ip_ospf_dead_interval_cmd
,
7294 "ip ospf dead-interval (1-65535) [A.B.C.D]",
7296 "OSPF interface commands\n"
7297 "Interval time after which a neighbor is declared down\n"
7299 "Address of interface\n")
7302 char *interval
= argv_find(argv
, argc
, "(1-65535)", &idx
)
7306 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7307 return ospf_vty_dead_interval_set(vty
, interval
, ifaddr
, NULL
);
7311 DEFUN_HIDDEN (ospf_dead_interval
,
7312 ospf_dead_interval_cmd
,
7313 "ospf dead-interval (1-65535) [A.B.C.D]",
7314 "OSPF interface commands\n"
7315 "Interval time after which a neighbor is declared down\n"
7317 "Address of interface\n")
7319 return ip_ospf_dead_interval(self
, vty
, argc
, argv
);
7322 DEFUN (ip_ospf_dead_interval_minimal
,
7323 ip_ospf_dead_interval_minimal_addr_cmd
,
7324 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
7326 "OSPF interface commands\n"
7327 "Interval time after which a neighbor is declared down\n"
7328 "Minimal 1s dead-interval with fast sub-second hellos\n"
7329 "Hello multiplier factor\n"
7330 "Number of Hellos to send each second\n"
7331 "Address of interface\n")
7336 return ospf_vty_dead_interval_set(
7337 vty
, NULL
, argv
[idx_ipv4
]->arg
, argv
[idx_number
]->arg
);
7339 return ospf_vty_dead_interval_set(vty
, NULL
, NULL
,
7340 argv
[idx_number
]->arg
);
7343 DEFUN (no_ip_ospf_dead_interval
,
7344 no_ip_ospf_dead_interval_cmd
,
7345 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
7348 "OSPF interface commands\n"
7349 "Interval time after which a neighbor is declared down\n"
7351 "Minimal 1s dead-interval with fast sub-second hellos\n"
7352 "Hello multiplier factor\n"
7353 "Number of Hellos to send each second\n"
7354 "Address of interface\n")
7356 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7357 int idx_ipv4
= argc
- 1;
7358 struct in_addr addr
= {.s_addr
= 0L};
7360 struct ospf_if_params
*params
;
7361 struct ospf_interface
*oi
;
7362 struct route_node
*rn
;
7364 params
= IF_DEF_PARAMS(ifp
);
7366 if (argv
[idx_ipv4
]->type
== IPV4_TKN
) {
7367 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7370 "Please specify interface address by A.B.C.D\n");
7371 return CMD_WARNING_CONFIG_FAILED
;
7374 params
= ospf_lookup_if_params(ifp
, addr
);
7379 UNSET_IF_PARAM(params
, v_wait
);
7380 params
->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
7382 UNSET_IF_PARAM(params
, fast_hello
);
7383 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
7385 if (params
!= IF_DEF_PARAMS(ifp
)) {
7386 ospf_free_if_params(ifp
, addr
);
7387 ospf_if_update_params(ifp
, addr
);
7390 /* Update timer values in neighbor structure. */
7392 struct ospf
*ospf
= NULL
;
7394 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7396 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
7398 ospf_nbr_timer_update(oi
);
7401 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
7402 if ((oi
= rn
->info
))
7403 ospf_nbr_timer_update(oi
);
7409 DEFUN_HIDDEN (no_ospf_dead_interval
,
7410 no_ospf_dead_interval_cmd
,
7411 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
7413 "OSPF interface commands\n"
7414 "Interval time after which a neighbor is declared down\n"
7416 "Minimal 1s dead-interval with fast sub-second hellos\n"
7417 "Hello multiplier factor\n"
7418 "Number of Hellos to send each second\n"
7419 "Address of interface\n")
7421 return no_ip_ospf_dead_interval(self
, vty
, argc
, argv
);
7424 DEFUN (ip_ospf_hello_interval
,
7425 ip_ospf_hello_interval_cmd
,
7426 "ip ospf hello-interval (1-65535) [A.B.C.D]",
7428 "OSPF interface commands\n"
7429 "Time between HELLO packets\n"
7431 "Address of interface\n")
7433 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7435 struct in_addr addr
;
7436 struct ospf_if_params
*params
;
7437 params
= IF_DEF_PARAMS(ifp
);
7438 uint32_t seconds
= 0;
7440 argv_find(argv
, argc
, "(1-65535)", &idx
);
7441 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7443 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7444 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7446 "Please specify interface address by A.B.C.D\n");
7447 return CMD_WARNING_CONFIG_FAILED
;
7450 params
= ospf_get_if_params(ifp
, addr
);
7451 ospf_if_update_params(ifp
, addr
);
7454 SET_IF_PARAM(params
, v_hello
);
7455 params
->v_hello
= seconds
;
7460 DEFUN_HIDDEN (ospf_hello_interval
,
7461 ospf_hello_interval_cmd
,
7462 "ospf hello-interval (1-65535) [A.B.C.D]",
7463 "OSPF interface commands\n"
7464 "Time between HELLO packets\n"
7466 "Address of interface\n")
7468 return ip_ospf_hello_interval(self
, vty
, argc
, argv
);
7471 DEFUN (no_ip_ospf_hello_interval
,
7472 no_ip_ospf_hello_interval_cmd
,
7473 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
7476 "OSPF interface commands\n"
7477 "Time between HELLO packets\n" // ignored
7479 "Address of interface\n")
7481 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7483 struct in_addr addr
;
7484 struct ospf_if_params
*params
;
7486 params
= IF_DEF_PARAMS(ifp
);
7488 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7489 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7491 "Please specify interface address by A.B.C.D\n");
7492 return CMD_WARNING_CONFIG_FAILED
;
7495 params
= ospf_lookup_if_params(ifp
, addr
);
7500 UNSET_IF_PARAM(params
, v_hello
);
7501 params
->v_hello
= OSPF_HELLO_INTERVAL_DEFAULT
;
7503 if (params
!= IF_DEF_PARAMS(ifp
)) {
7504 ospf_free_if_params(ifp
, addr
);
7505 ospf_if_update_params(ifp
, addr
);
7511 DEFUN_HIDDEN (no_ospf_hello_interval
,
7512 no_ospf_hello_interval_cmd
,
7513 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
7515 "OSPF interface commands\n"
7516 "Time between HELLO packets\n" // ignored
7518 "Address of interface\n")
7520 return no_ip_ospf_hello_interval(self
, vty
, argc
, argv
);
7523 DEFUN (ip_ospf_network
,
7524 ip_ospf_network_cmd
,
7525 "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
7527 "OSPF interface commands\n"
7529 "Specify OSPF broadcast multi-access network\n"
7530 "Specify OSPF NBMA network\n"
7531 "Specify OSPF point-to-multipoint network\n"
7532 "Specify OSPF point-to-point network\n")
7534 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7536 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
7537 struct route_node
*rn
;
7539 if (old_type
== OSPF_IFTYPE_LOOPBACK
) {
7541 "This is a loopback interface. Can't set network type.\n");
7542 return CMD_WARNING_CONFIG_FAILED
;
7545 if (argv_find(argv
, argc
, "broadcast", &idx
))
7546 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_BROADCAST
;
7547 else if (argv_find(argv
, argc
, "non-broadcast", &idx
))
7548 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_NBMA
;
7549 else if (argv_find(argv
, argc
, "point-to-multipoint", &idx
))
7550 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOMULTIPOINT
;
7551 else if (argv_find(argv
, argc
, "point-to-point", &idx
))
7552 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOPOINT
;
7554 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
7557 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), type
);
7559 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7560 struct ospf_interface
*oi
= rn
->info
;
7565 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
7567 if (oi
->state
> ISM_Down
) {
7568 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
7569 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
7576 DEFUN_HIDDEN (ospf_network
,
7578 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
7579 "OSPF interface commands\n"
7581 "Specify OSPF broadcast multi-access network\n"
7582 "Specify OSPF NBMA network\n"
7583 "Specify OSPF point-to-multipoint network\n"
7584 "Specify OSPF point-to-point network\n")
7586 return ip_ospf_network(self
, vty
, argc
, argv
);
7589 DEFUN (no_ip_ospf_network
,
7590 no_ip_ospf_network_cmd
,
7591 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
7594 "OSPF interface commands\n"
7596 "Specify OSPF broadcast multi-access network\n"
7597 "Specify OSPF NBMA network\n"
7598 "Specify OSPF point-to-multipoint network\n"
7599 "Specify OSPF point-to-point network\n")
7601 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7602 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
7603 struct route_node
*rn
;
7605 IF_DEF_PARAMS(ifp
)->type
= ospf_default_iftype(ifp
);
7607 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
7610 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7611 struct ospf_interface
*oi
= rn
->info
;
7616 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
7618 if (oi
->state
> ISM_Down
) {
7619 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
7620 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
7627 DEFUN_HIDDEN (no_ospf_network
,
7628 no_ospf_network_cmd
,
7629 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
7631 "OSPF interface commands\n"
7633 "Specify OSPF broadcast multi-access network\n"
7634 "Specify OSPF NBMA network\n"
7635 "Specify OSPF point-to-multipoint network\n"
7636 "Specify OSPF point-to-point network\n")
7638 return no_ip_ospf_network(self
, vty
, argc
, argv
);
7641 DEFUN (ip_ospf_priority
,
7642 ip_ospf_priority_cmd
,
7643 "ip ospf priority (0-255) [A.B.C.D]",
7645 "OSPF interface commands\n"
7648 "Address of interface\n")
7650 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7653 struct route_node
*rn
;
7654 struct in_addr addr
;
7655 struct ospf_if_params
*params
;
7656 params
= IF_DEF_PARAMS(ifp
);
7658 argv_find(argv
, argc
, "(0-255)", &idx
);
7659 priority
= strtol(argv
[idx
]->arg
, NULL
, 10);
7661 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7662 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7664 "Please specify interface address by A.B.C.D\n");
7665 return CMD_WARNING_CONFIG_FAILED
;
7668 params
= ospf_get_if_params(ifp
, addr
);
7669 ospf_if_update_params(ifp
, addr
);
7672 SET_IF_PARAM(params
, priority
);
7673 params
->priority
= priority
;
7675 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7676 struct ospf_interface
*oi
= rn
->info
;
7681 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
7682 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
7683 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
7690 DEFUN_HIDDEN (ospf_priority
,
7692 "ospf priority (0-255) [A.B.C.D]",
7693 "OSPF interface commands\n"
7696 "Address of interface\n")
7698 return ip_ospf_priority(self
, vty
, argc
, argv
);
7701 DEFUN (no_ip_ospf_priority
,
7702 no_ip_ospf_priority_cmd
,
7703 "no ip ospf priority [(0-255) [A.B.C.D]]",
7706 "OSPF interface commands\n"
7707 "Router priority\n" // ignored
7709 "Address of interface\n")
7711 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7713 struct route_node
*rn
;
7714 struct in_addr addr
;
7715 struct ospf_if_params
*params
;
7717 params
= IF_DEF_PARAMS(ifp
);
7719 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7720 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7722 "Please specify interface address by A.B.C.D\n");
7723 return CMD_WARNING_CONFIG_FAILED
;
7726 params
= ospf_lookup_if_params(ifp
, addr
);
7731 UNSET_IF_PARAM(params
, priority
);
7732 params
->priority
= OSPF_ROUTER_PRIORITY_DEFAULT
;
7734 if (params
!= IF_DEF_PARAMS(ifp
)) {
7735 ospf_free_if_params(ifp
, addr
);
7736 ospf_if_update_params(ifp
, addr
);
7739 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7740 struct ospf_interface
*oi
= rn
->info
;
7745 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
7746 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
7747 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
7754 DEFUN_HIDDEN (no_ospf_priority
,
7755 no_ospf_priority_cmd
,
7756 "no ospf priority [(0-255) [A.B.C.D]]",
7758 "OSPF interface commands\n"
7761 "Address of interface\n")
7763 return no_ip_ospf_priority(self
, vty
, argc
, argv
);
7766 DEFUN (ip_ospf_retransmit_interval
,
7767 ip_ospf_retransmit_interval_addr_cmd
,
7768 "ip ospf retransmit-interval (3-65535) [A.B.C.D]",
7770 "OSPF interface commands\n"
7771 "Time between retransmitting lost link state advertisements\n"
7773 "Address of interface\n")
7775 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7778 struct in_addr addr
;
7779 struct ospf_if_params
*params
;
7780 params
= IF_DEF_PARAMS(ifp
);
7782 argv_find(argv
, argc
, "(3-65535)", &idx
);
7783 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7785 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7786 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7788 "Please specify interface address by A.B.C.D\n");
7789 return CMD_WARNING_CONFIG_FAILED
;
7792 params
= ospf_get_if_params(ifp
, addr
);
7793 ospf_if_update_params(ifp
, addr
);
7796 SET_IF_PARAM(params
, retransmit_interval
);
7797 params
->retransmit_interval
= seconds
;
7802 DEFUN_HIDDEN (ospf_retransmit_interval
,
7803 ospf_retransmit_interval_cmd
,
7804 "ospf retransmit-interval (3-65535) [A.B.C.D]",
7805 "OSPF interface commands\n"
7806 "Time between retransmitting lost link state advertisements\n"
7808 "Address of interface\n")
7810 return ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
7813 DEFUN (no_ip_ospf_retransmit_interval
,
7814 no_ip_ospf_retransmit_interval_addr_cmd
,
7815 "no ip ospf retransmit-interval [(3-65535)] [A.B.C.D]",
7818 "OSPF interface commands\n"
7819 "Time between retransmitting lost link state advertisements\n"
7821 "Address of interface\n")
7823 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7825 struct in_addr addr
;
7826 struct ospf_if_params
*params
;
7828 params
= IF_DEF_PARAMS(ifp
);
7830 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7831 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7833 "Please specify interface address by A.B.C.D\n");
7834 return CMD_WARNING_CONFIG_FAILED
;
7837 params
= ospf_lookup_if_params(ifp
, addr
);
7842 UNSET_IF_PARAM(params
, retransmit_interval
);
7843 params
->retransmit_interval
= OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
7845 if (params
!= IF_DEF_PARAMS(ifp
)) {
7846 ospf_free_if_params(ifp
, addr
);
7847 ospf_if_update_params(ifp
, addr
);
7853 DEFUN_HIDDEN (no_ospf_retransmit_interval
,
7854 no_ospf_retransmit_interval_cmd
,
7855 "no ospf retransmit-interval [(3-65535)] [A.B.C.D]",
7857 "OSPF interface commands\n"
7858 "Time between retransmitting lost link state advertisements\n"
7860 "Address of interface\n")
7862 return no_ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
7865 DEFUN (ip_ospf_transmit_delay
,
7866 ip_ospf_transmit_delay_addr_cmd
,
7867 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
7869 "OSPF interface commands\n"
7870 "Link state transmit delay\n"
7872 "Address of interface\n")
7874 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7877 struct in_addr addr
;
7878 struct ospf_if_params
*params
;
7880 params
= IF_DEF_PARAMS(ifp
);
7881 argv_find(argv
, argc
, "(1-65535)", &idx
);
7882 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7884 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7885 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7887 "Please specify interface address by A.B.C.D\n");
7888 return CMD_WARNING_CONFIG_FAILED
;
7891 params
= ospf_get_if_params(ifp
, addr
);
7892 ospf_if_update_params(ifp
, addr
);
7895 SET_IF_PARAM(params
, transmit_delay
);
7896 params
->transmit_delay
= seconds
;
7901 DEFUN_HIDDEN (ospf_transmit_delay
,
7902 ospf_transmit_delay_cmd
,
7903 "ospf transmit-delay (1-65535) [A.B.C.D]",
7904 "OSPF interface commands\n"
7905 "Link state transmit delay\n"
7907 "Address of interface\n")
7909 return ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
7912 DEFUN (no_ip_ospf_transmit_delay
,
7913 no_ip_ospf_transmit_delay_addr_cmd
,
7914 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
7917 "OSPF interface commands\n"
7918 "Link state transmit delay\n"
7920 "Address of interface\n")
7922 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7924 struct in_addr addr
;
7925 struct ospf_if_params
*params
;
7927 params
= IF_DEF_PARAMS(ifp
);
7929 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7930 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7932 "Please specify interface address by A.B.C.D\n");
7933 return CMD_WARNING_CONFIG_FAILED
;
7936 params
= ospf_lookup_if_params(ifp
, addr
);
7941 UNSET_IF_PARAM(params
, transmit_delay
);
7942 params
->transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
7944 if (params
!= IF_DEF_PARAMS(ifp
)) {
7945 ospf_free_if_params(ifp
, addr
);
7946 ospf_if_update_params(ifp
, addr
);
7953 DEFUN_HIDDEN (no_ospf_transmit_delay
,
7954 no_ospf_transmit_delay_cmd
,
7955 "no ospf transmit-delay [(1-65535) [A.B.C.D]]",
7957 "OSPF interface commands\n"
7958 "Link state transmit delay\n"
7960 "Address of interface\n")
7962 return no_ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
7965 DEFUN (ip_ospf_area
,
7967 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]",
7969 "OSPF interface commands\n"
7971 "Enable OSPF on this interface\n"
7972 "OSPF area ID in IP address format\n"
7973 "OSPF area ID as a decimal value\n"
7974 "Address of interface\n")
7976 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7979 struct in_addr area_id
;
7980 struct in_addr addr
;
7981 struct ospf_if_params
*params
= NULL
;
7982 struct route_node
*rn
;
7983 struct ospf
*ospf
= NULL
;
7984 unsigned short instance
= 0;
7987 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
7988 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
7990 argv_find(argv
, argc
, "area", &idx
);
7991 areaid
= argv
[idx
+ 1]->arg
;
7993 if (ifp
->vrf_id
&& !instance
)
7994 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7996 ospf
= ospf_lookup_instance(instance
);
7998 if (instance
&& ospf
== NULL
) {
7999 params
= IF_DEF_PARAMS(ifp
);
8000 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8001 UNSET_IF_PARAM(params
, if_area
);
8002 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
8003 ospf_interface_area_unset(ospf
, ifp
);
8004 ospf
->if_ospf_cli_count
--;
8006 return CMD_NOT_MY_INSTANCE
;
8009 ret
= str2area_id(areaid
, &area_id
, &format
);
8011 vty_out(vty
, "Please specify area by A.B.C.D|<0-4294967295>\n");
8012 return CMD_WARNING_CONFIG_FAILED
;
8014 if (memcmp(ifp
->name
, "VLINK", 5) == 0) {
8015 vty_out(vty
, "Cannot enable OSPF on a virtual link.\n");
8016 return CMD_WARNING_CONFIG_FAILED
;
8019 params
= IF_DEF_PARAMS(ifp
);
8020 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)
8021 && !IPV4_ADDR_SAME(¶ms
->if_area
, &area_id
)) {
8023 "Must remove previous area config before changing ospf area \n");
8024 return CMD_WARNING_CONFIG_FAILED
;
8027 // Check if we have an address arg and proccess it
8028 if (argc
== idx
+ 3) {
8029 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
8031 "Please specify Intf Address by A.B.C.D\n");
8032 return CMD_WARNING_CONFIG_FAILED
;
8034 // update/create address-level params
8035 params
= ospf_get_if_params((ifp
), (addr
));
8036 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8038 "Must remove previous area/address config before changing ospf area");
8039 return CMD_WARNING_CONFIG_FAILED
;
8041 ospf_if_update_params((ifp
), (addr
));
8045 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
)) {
8046 if (rn
->info
!= NULL
) {
8048 "Please remove all network commands first.\n");
8049 return CMD_WARNING_CONFIG_FAILED
;
8054 /* enable ospf on this interface with area_id */
8056 SET_IF_PARAM(params
, if_area
);
8057 params
->if_area
= area_id
;
8058 params
->if_area_id_fmt
= format
;
8062 ospf_interface_area_set(ospf
, ifp
);
8063 ospf
->if_ospf_cli_count
++;
8069 DEFUN (no_ip_ospf_area
,
8070 no_ip_ospf_area_cmd
,
8071 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]",
8074 "OSPF interface commands\n"
8076 "Disable OSPF on this interface\n"
8077 "OSPF area ID in IP address format\n"
8078 "OSPF area ID as a decimal value\n"
8079 "Address of interface\n")
8081 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8084 struct ospf_if_params
*params
;
8085 unsigned short instance
= 0;
8086 struct in_addr addr
;
8088 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
8089 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
8091 if (ifp
->vrf_id
&& !instance
)
8092 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
8094 ospf
= ospf_lookup_instance(instance
);
8097 return CMD_NOT_MY_INSTANCE
;
8099 argv_find(argv
, argc
, "area", &idx
);
8101 // Check if we have an address arg and proccess it
8102 if (argc
== idx
+ 3) {
8103 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
8105 "Please specify Intf Address by A.B.C.D\n");
8106 return CMD_WARNING_CONFIG_FAILED
;
8108 params
= ospf_lookup_if_params(ifp
, addr
);
8109 if ((params
) == NULL
)
8112 params
= IF_DEF_PARAMS(ifp
);
8114 if (!OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8116 "Can't find specified interface area configuration.\n");
8117 return CMD_WARNING_CONFIG_FAILED
;
8120 UNSET_IF_PARAM(params
, if_area
);
8121 if (params
!= IF_DEF_PARAMS((ifp
))) {
8122 ospf_free_if_params((ifp
), (addr
));
8123 ospf_if_update_params((ifp
), (addr
));
8126 ospf_interface_area_unset(ospf
, ifp
);
8127 ospf
->if_ospf_cli_count
--;
8131 DEFUN (ospf_redistribute_source
,
8132 ospf_redistribute_source_cmd
,
8133 "redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8135 FRR_REDIST_HELP_STR_OSPFD
8136 "Metric for redistributed routes\n"
8137 "OSPF default metric\n"
8138 "OSPF exterior metric type for redistributed routes\n"
8139 "Set OSPF External Type 1/2 metrics\n"
8140 "Route map reference\n"
8141 "Pointer to route-map entries\n")
8143 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8144 int idx_protocol
= 1;
8148 struct ospf_redist
*red
;
8151 /* Get distribute source. */
8152 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
8154 return CMD_WARNING_CONFIG_FAILED
;
8156 red
= ospf_redist_add(ospf
, source
, 0);
8158 /* Get metric value. */
8159 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
8160 if (!str2metric(argv
[idx
]->arg
, &metric
))
8161 return CMD_WARNING_CONFIG_FAILED
;
8164 /* Get metric type. */
8165 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
8166 if (!str2metric_type(argv
[idx
]->arg
, &type
))
8167 return CMD_WARNING_CONFIG_FAILED
;
8171 if (argv_find(argv
, argc
, "WORD", &idx
)) {
8172 ospf_routemap_set(red
, argv
[idx
]->arg
);
8174 ospf_routemap_unset(red
);
8176 return ospf_redistribute_set(ospf
, source
, 0, type
, metric
);
8179 DEFUN (no_ospf_redistribute_source
,
8180 no_ospf_redistribute_source_cmd
,
8181 "no redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8184 FRR_REDIST_HELP_STR_OSPFD
8185 "Metric for redistributed routes\n"
8186 "OSPF default metric\n"
8187 "OSPF exterior metric type for redistributed routes\n"
8188 "Set OSPF External Type 1/2 metrics\n"
8189 "Route map reference\n"
8190 "Pointer to route-map entries\n")
8192 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8193 int idx_protocol
= 2;
8195 struct ospf_redist
*red
;
8197 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
8199 return CMD_WARNING_CONFIG_FAILED
;
8201 red
= ospf_redist_lookup(ospf
, source
, 0);
8205 ospf_routemap_unset(red
);
8206 ospf_redist_del(ospf
, source
, 0);
8208 return ospf_redistribute_unset(ospf
, source
, 0);
8211 DEFUN (ospf_redistribute_instance_source
,
8212 ospf_redistribute_instance_source_cmd
,
8213 "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8215 "Open Shortest Path First\n"
8216 "Non-main Kernel Routing Table\n"
8217 "Instance ID/Table ID\n"
8218 "Metric for redistributed routes\n"
8219 "OSPF default metric\n"
8220 "OSPF exterior metric type for redistributed routes\n"
8221 "Set OSPF External Type 1/2 metrics\n"
8222 "Route map reference\n"
8223 "Pointer to route-map entries\n")
8225 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8226 int idx_ospf_table
= 1;
8232 unsigned short instance
;
8233 struct ospf_redist
*red
;
8235 source
= proto_redistnum(AFI_IP
, argv
[idx_ospf_table
]->text
);
8238 vty_out(vty
, "Unknown instance redistribution\n");
8239 return CMD_WARNING_CONFIG_FAILED
;
8242 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8244 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
8246 "Instance redistribution in non-instanced OSPF not allowed\n");
8247 return CMD_WARNING_CONFIG_FAILED
;
8250 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
8251 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
8252 return CMD_WARNING_CONFIG_FAILED
;
8255 /* Get metric value. */
8256 if (argv_find(argv
, argc
, "metric", &idx
))
8257 if (!str2metric(argv
[idx
+ 1]->arg
, &metric
))
8258 return CMD_WARNING_CONFIG_FAILED
;
8261 /* Get metric type. */
8262 if (argv_find(argv
, argc
, "metric-type", &idx
))
8263 if (!str2metric_type(argv
[idx
+ 1]->arg
, &type
))
8264 return CMD_WARNING_CONFIG_FAILED
;
8266 red
= ospf_redist_add(ospf
, source
, instance
);
8269 if (argv_find(argv
, argc
, "route-map", &idx
))
8270 ospf_routemap_set(red
, argv
[idx
+ 1]->arg
);
8272 ospf_routemap_unset(red
);
8274 return ospf_redistribute_set(ospf
, source
, instance
, type
, metric
);
8277 DEFUN (no_ospf_redistribute_instance_source
,
8278 no_ospf_redistribute_instance_source_cmd
,
8279 "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8282 "Open Shortest Path First\n"
8283 "Non-main Kernel Routing Table\n"
8284 "Instance ID/Table Id\n"
8285 "Metric for redistributed routes\n"
8286 "OSPF default metric\n"
8287 "OSPF exterior metric type for redistributed routes\n"
8288 "Set OSPF External Type 1/2 metrics\n"
8289 "Route map reference\n"
8290 "Pointer to route-map entries\n")
8292 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8293 int idx_ospf_table
= 2;
8295 unsigned int instance
;
8296 struct ospf_redist
*red
;
8299 if (strncmp(argv
[idx_ospf_table
]->arg
, "o", 1) == 0)
8300 source
= ZEBRA_ROUTE_OSPF
;
8302 source
= ZEBRA_ROUTE_TABLE
;
8304 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8306 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
8308 "Instance redistribution in non-instanced OSPF not allowed\n");
8309 return CMD_WARNING_CONFIG_FAILED
;
8312 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
8313 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
8314 return CMD_WARNING_CONFIG_FAILED
;
8317 red
= ospf_redist_lookup(ospf
, source
, instance
);
8321 ospf_routemap_unset(red
);
8322 ospf_redist_del(ospf
, source
, instance
);
8324 return ospf_redistribute_unset(ospf
, source
, instance
);
8327 DEFUN (ospf_distribute_list_out
,
8328 ospf_distribute_list_out_cmd
,
8329 "distribute-list WORD out " FRR_REDIST_STR_OSPFD
,
8330 "Filter networks in routing updates\n"
8331 "Access-list name\n"
8333 FRR_REDIST_HELP_STR_OSPFD
)
8335 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8339 char *proto
= argv
[argc
- 1]->text
;
8341 /* Get distribute source. */
8342 source
= proto_redistnum(AFI_IP
, proto
);
8344 return CMD_WARNING_CONFIG_FAILED
;
8346 return ospf_distribute_list_out_set(ospf
, source
, argv
[idx_word
]->arg
);
8349 DEFUN (no_ospf_distribute_list_out
,
8350 no_ospf_distribute_list_out_cmd
,
8351 "no distribute-list WORD out " FRR_REDIST_STR_OSPFD
,
8353 "Filter networks in routing updates\n"
8354 "Access-list name\n"
8356 FRR_REDIST_HELP_STR_OSPFD
)
8358 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8362 char *proto
= argv
[argc
- 1]->text
;
8363 source
= proto_redistnum(AFI_IP
, proto
);
8365 return CMD_WARNING_CONFIG_FAILED
;
8367 return ospf_distribute_list_out_unset(ospf
, source
,
8368 argv
[idx_word
]->arg
);
8371 /* Default information originate. */
8372 DEFUN (ospf_default_information_originate
,
8373 ospf_default_information_originate_cmd
,
8374 "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8375 "Control distribution of default information\n"
8376 "Distribute a default route\n"
8377 "Always advertise default route\n"
8378 "OSPF default metric\n"
8380 "OSPF metric type for default routes\n"
8381 "Set OSPF External Type 1/2 metrics\n"
8382 "Route map reference\n"
8383 "Pointer to route-map entries\n")
8385 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8386 int default_originate
= DEFAULT_ORIGINATE_ZEBRA
;
8389 struct ospf_redist
*red
;
8391 int cur_originate
= ospf
->default_originate
;
8395 red
= ospf_redist_add(ospf
, DEFAULT_ROUTE
, 0);
8397 /* Check whether "always" was specified */
8398 if (argv_find(argv
, argc
, "always", &idx
))
8399 default_originate
= DEFAULT_ORIGINATE_ALWAYS
;
8401 /* Get metric value */
8402 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
8403 if (!str2metric(argv
[idx
]->arg
, &metric
))
8404 return CMD_WARNING_CONFIG_FAILED
;
8407 /* Get metric type. */
8408 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
8409 if (!str2metric_type(argv
[idx
]->arg
, &type
))
8410 return CMD_WARNING_CONFIG_FAILED
;
8414 if (argv_find(argv
, argc
, "WORD", &idx
))
8415 rtmap
= argv
[idx
]->arg
;
8417 /* To check ,if user is providing same route map */
8418 if ((rtmap
== ROUTEMAP_NAME(red
)) ||
8419 (rtmap
&& ROUTEMAP_NAME(red
)
8420 && (strcmp(rtmap
, ROUTEMAP_NAME(red
)) == 0)))
8423 /* Don't allow if the same lsa is aleardy originated. */
8425 && (red
->dmetric
.type
== type
)
8426 && (red
->dmetric
.value
== metric
)
8427 && (cur_originate
== default_originate
))
8430 /* Updating Metric details */
8431 red
->dmetric
.type
= type
;
8432 red
->dmetric
.value
= metric
;
8434 /* updating route map details */
8436 ospf_routemap_set(red
, rtmap
);
8438 ospf_routemap_unset(red
);
8440 return ospf_redistribute_default_set(ospf
, default_originate
, type
,
8444 DEFUN (no_ospf_default_information_originate
,
8445 no_ospf_default_information_originate_cmd
,
8446 "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8448 "Control distribution of default information\n"
8449 "Distribute a default route\n"
8450 "Always advertise default route\n"
8451 "OSPF default metric\n"
8453 "OSPF metric type for default routes\n"
8454 "Set OSPF External Type 1/2 metrics\n"
8455 "Route map reference\n"
8456 "Pointer to route-map entries\n")
8458 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8459 struct prefix_ipv4 p
;
8460 struct ospf_external
*ext
;
8461 struct ospf_redist
*red
;
8464 p
.prefix
.s_addr
= 0;
8467 ospf_external_lsa_flush(ospf
, DEFAULT_ROUTE
, &p
, 0);
8469 ext
= ospf_external_lookup(ospf
, DEFAULT_ROUTE
, 0);
8470 if (ext
&& EXTERNAL_INFO(ext
)) {
8471 ospf_external_info_delete(ospf
, DEFAULT_ROUTE
, 0, p
);
8472 ospf_external_del(ospf
, DEFAULT_ROUTE
, 0);
8475 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
8479 ospf_routemap_unset(red
);
8480 ospf_redist_del(ospf
, DEFAULT_ROUTE
, 0);
8482 return ospf_redistribute_default_unset(ospf
);
8485 DEFUN (ospf_default_metric
,
8486 ospf_default_metric_cmd
,
8487 "default-metric (0-16777214)",
8488 "Set metric of redistributed routes\n"
8491 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8495 if (!str2metric(argv
[idx_number
]->arg
, &metric
))
8496 return CMD_WARNING_CONFIG_FAILED
;
8498 ospf
->default_metric
= metric
;
8503 DEFUN (no_ospf_default_metric
,
8504 no_ospf_default_metric_cmd
,
8505 "no default-metric [(0-16777214)]",
8507 "Set metric of redistributed routes\n"
8510 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8512 ospf
->default_metric
= -1;
8518 DEFUN (ospf_distance
,
8521 "Administrative distance\n"
8522 "OSPF Administrative distance\n")
8524 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8527 ospf
->distance_all
= atoi(argv
[idx_number
]->arg
);
8532 DEFUN (no_ospf_distance
,
8533 no_ospf_distance_cmd
,
8534 "no distance (1-255)",
8536 "Administrative distance\n"
8537 "OSPF Administrative distance\n")
8539 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8541 ospf
->distance_all
= 0;
8546 DEFUN (no_ospf_distance_ospf
,
8547 no_ospf_distance_ospf_cmd
,
8548 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
8550 "Administrative distance\n"
8551 "OSPF administrative distance\n"
8552 "Intra-area routes\n"
8553 "Distance for intra-area routes\n"
8554 "Inter-area routes\n"
8555 "Distance for inter-area routes\n"
8557 "Distance for external routes\n")
8559 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8562 if (argv_find(argv
, argc
, "intra-area", &idx
) || argc
== 3)
8563 idx
= ospf
->distance_intra
= 0;
8564 if (argv_find(argv
, argc
, "inter-area", &idx
) || argc
== 3)
8565 idx
= ospf
->distance_inter
= 0;
8566 if (argv_find(argv
, argc
, "external", &idx
) || argc
== 3)
8567 ospf
->distance_external
= 0;
8572 DEFUN (ospf_distance_ospf
,
8573 ospf_distance_ospf_cmd
,
8574 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
8575 "Administrative distance\n"
8576 "OSPF administrative distance\n"
8577 "Intra-area routes\n"
8578 "Distance for intra-area routes\n"
8579 "Inter-area routes\n"
8580 "Distance for inter-area routes\n"
8582 "Distance for external routes\n")
8584 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8587 ospf
->distance_intra
= 0;
8588 ospf
->distance_inter
= 0;
8589 ospf
->distance_external
= 0;
8591 if (argv_find(argv
, argc
, "intra-area", &idx
))
8592 ospf
->distance_intra
= atoi(argv
[idx
+ 1]->arg
);
8594 if (argv_find(argv
, argc
, "inter-area", &idx
))
8595 ospf
->distance_inter
= atoi(argv
[idx
+ 1]->arg
);
8597 if (argv_find(argv
, argc
, "external", &idx
))
8598 ospf
->distance_external
= atoi(argv
[idx
+ 1]->arg
);
8604 DEFUN (ospf_distance_source
,
8605 ospf_distance_source_cmd
,
8606 "distance (1-255) A.B.C.D/M",
8607 "Administrative distance\n"
8609 "IP source prefix\n")
8611 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8613 int idx_ipv4_prefixlen
= 2;
8615 ospf_distance_set (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
8620 DEFUN (no_ospf_distance_source
,
8621 no_ospf_distance_source_cmd
,
8622 "no distance (1-255) A.B.C.D/M",
8624 "Administrative distance\n"
8626 "IP source prefix\n")
8628 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8630 int idx_ipv4_prefixlen
= 3;
8632 ospf_distance_unset (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
8637 DEFUN (ospf_distance_source_access_list
,
8638 ospf_distance_source_access_list_cmd
,
8639 "distance (1-255) A.B.C.D/M WORD",
8640 "Administrative distance\n"
8642 "IP source prefix\n"
8643 "Access list name\n")
8645 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8647 int idx_ipv4_prefixlen
= 2;
8650 ospf_distance_set (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
8655 DEFUN (no_ospf_distance_source_access_list
,
8656 no_ospf_distance_source_access_list_cmd
,
8657 "no distance (1-255) A.B.C.D/M WORD",
8659 "Administrative distance\n"
8661 "IP source prefix\n"
8662 "Access list name\n")
8664 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8666 int idx_ipv4_prefixlen
= 3;
8669 ospf_distance_unset (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
8675 DEFUN (ip_ospf_mtu_ignore
,
8676 ip_ospf_mtu_ignore_addr_cmd
,
8677 "ip ospf mtu-ignore [A.B.C.D]",
8679 "OSPF interface commands\n"
8680 "Disable MTU mismatch detection on this interface\n"
8681 "Address of interface\n")
8683 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8685 struct in_addr addr
;
8688 struct ospf_if_params
*params
;
8689 params
= IF_DEF_PARAMS(ifp
);
8692 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8695 "Please specify interface address by A.B.C.D\n");
8696 return CMD_WARNING_CONFIG_FAILED
;
8698 params
= ospf_get_if_params(ifp
, addr
);
8699 ospf_if_update_params(ifp
, addr
);
8701 params
->mtu_ignore
= 1;
8702 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
8703 SET_IF_PARAM(params
, mtu_ignore
);
8705 UNSET_IF_PARAM(params
, mtu_ignore
);
8706 if (params
!= IF_DEF_PARAMS(ifp
)) {
8707 ospf_free_if_params(ifp
, addr
);
8708 ospf_if_update_params(ifp
, addr
);
8714 DEFUN (no_ip_ospf_mtu_ignore
,
8715 no_ip_ospf_mtu_ignore_addr_cmd
,
8716 "no ip ospf mtu-ignore [A.B.C.D]",
8719 "OSPF interface commands\n"
8720 "Disable MTU mismatch detection on this interface\n"
8721 "Address of interface\n")
8723 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8725 struct in_addr addr
;
8728 struct ospf_if_params
*params
;
8729 params
= IF_DEF_PARAMS(ifp
);
8732 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8735 "Please specify interface address by A.B.C.D\n");
8736 return CMD_WARNING_CONFIG_FAILED
;
8738 params
= ospf_get_if_params(ifp
, addr
);
8739 ospf_if_update_params(ifp
, addr
);
8741 params
->mtu_ignore
= 0;
8742 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
8743 SET_IF_PARAM(params
, mtu_ignore
);
8745 UNSET_IF_PARAM(params
, mtu_ignore
);
8746 if (params
!= IF_DEF_PARAMS(ifp
)) {
8747 ospf_free_if_params(ifp
, addr
);
8748 ospf_if_update_params(ifp
, addr
);
8755 DEFUN (ospf_max_metric_router_lsa_admin
,
8756 ospf_max_metric_router_lsa_admin_cmd
,
8757 "max-metric router-lsa administrative",
8758 "OSPF maximum / infinite-distance metric\n"
8759 "Advertise own Router-LSA with infinite distance (stub router)\n"
8760 "Administratively applied, for an indefinite period\n")
8762 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8763 struct listnode
*ln
;
8764 struct ospf_area
*area
;
8766 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8767 SET_FLAG(area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
);
8769 if (!CHECK_FLAG(area
->stub_router_state
,
8770 OSPF_AREA_IS_STUB_ROUTED
))
8771 ospf_router_lsa_update_area(area
);
8774 /* Allows for areas configured later to get the property */
8775 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
;
8780 DEFUN (no_ospf_max_metric_router_lsa_admin
,
8781 no_ospf_max_metric_router_lsa_admin_cmd
,
8782 "no max-metric router-lsa administrative",
8784 "OSPF maximum / infinite-distance metric\n"
8785 "Advertise own Router-LSA with infinite distance (stub router)\n"
8786 "Administratively applied, for an indefinite period\n")
8788 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8789 struct listnode
*ln
;
8790 struct ospf_area
*area
;
8792 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8793 UNSET_FLAG(area
->stub_router_state
,
8794 OSPF_AREA_ADMIN_STUB_ROUTED
);
8796 /* Don't trample on the start-up stub timer */
8797 if (CHECK_FLAG(area
->stub_router_state
,
8798 OSPF_AREA_IS_STUB_ROUTED
)
8799 && !area
->t_stub_router
) {
8800 UNSET_FLAG(area
->stub_router_state
,
8801 OSPF_AREA_IS_STUB_ROUTED
);
8802 ospf_router_lsa_update_area(area
);
8805 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET
;
8809 DEFUN (ospf_max_metric_router_lsa_startup
,
8810 ospf_max_metric_router_lsa_startup_cmd
,
8811 "max-metric router-lsa on-startup (5-86400)",
8812 "OSPF maximum / infinite-distance metric\n"
8813 "Advertise own Router-LSA with infinite distance (stub router)\n"
8814 "Automatically advertise stub Router-LSA on startup of OSPF\n"
8815 "Time (seconds) to advertise self as stub-router\n")
8817 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8819 unsigned int seconds
;
8822 vty_out(vty
, "%% Must supply stub-router period");
8823 return CMD_WARNING_CONFIG_FAILED
;
8826 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8828 ospf
->stub_router_startup_time
= seconds
;
8833 DEFUN (no_ospf_max_metric_router_lsa_startup
,
8834 no_ospf_max_metric_router_lsa_startup_cmd
,
8835 "no max-metric router-lsa on-startup [(5-86400)]",
8837 "OSPF maximum / infinite-distance metric\n"
8838 "Advertise own Router-LSA with infinite distance (stub router)\n"
8839 "Automatically advertise stub Router-LSA on startup of OSPF\n"
8840 "Time (seconds) to advertise self as stub-router\n")
8842 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8843 struct listnode
*ln
;
8844 struct ospf_area
*area
;
8846 ospf
->stub_router_startup_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
8848 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8849 SET_FLAG(area
->stub_router_state
,
8850 OSPF_AREA_WAS_START_STUB_ROUTED
);
8851 OSPF_TIMER_OFF(area
->t_stub_router
);
8853 /* Don't trample on admin stub routed */
8854 if (!CHECK_FLAG(area
->stub_router_state
,
8855 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
8856 UNSET_FLAG(area
->stub_router_state
,
8857 OSPF_AREA_IS_STUB_ROUTED
);
8858 ospf_router_lsa_update_area(area
);
8865 DEFUN (ospf_max_metric_router_lsa_shutdown
,
8866 ospf_max_metric_router_lsa_shutdown_cmd
,
8867 "max-metric router-lsa on-shutdown (5-100)",
8868 "OSPF maximum / infinite-distance metric\n"
8869 "Advertise own Router-LSA with infinite distance (stub router)\n"
8870 "Advertise stub-router prior to full shutdown of OSPF\n"
8871 "Time (seconds) to wait till full shutdown\n")
8873 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8875 unsigned int seconds
;
8878 vty_out(vty
, "%% Must supply stub-router shutdown period");
8879 return CMD_WARNING_CONFIG_FAILED
;
8882 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8884 ospf
->stub_router_shutdown_time
= seconds
;
8889 DEFUN (no_ospf_max_metric_router_lsa_shutdown
,
8890 no_ospf_max_metric_router_lsa_shutdown_cmd
,
8891 "no max-metric router-lsa on-shutdown [(5-100)]",
8893 "OSPF maximum / infinite-distance metric\n"
8894 "Advertise own Router-LSA with infinite distance (stub router)\n"
8895 "Advertise stub-router prior to full shutdown of OSPF\n"
8896 "Time (seconds) to wait till full shutdown\n")
8898 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8900 ospf
->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
8905 static void config_write_stub_router(struct vty
*vty
, struct ospf
*ospf
)
8907 struct listnode
*ln
;
8908 struct ospf_area
*area
;
8910 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
8911 vty_out(vty
, " max-metric router-lsa on-startup %u\n",
8912 ospf
->stub_router_startup_time
);
8913 if (ospf
->stub_router_shutdown_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
8914 vty_out(vty
, " max-metric router-lsa on-shutdown %u\n",
8915 ospf
->stub_router_shutdown_time
);
8916 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8917 if (CHECK_FLAG(area
->stub_router_state
,
8918 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
8919 vty_out(vty
, " max-metric router-lsa administrative\n");
8926 static void show_ip_ospf_route_network(struct vty
*vty
, struct ospf
*ospf
,
8927 struct route_table
*rt
,
8930 struct route_node
*rn
;
8931 struct ospf_route
* or ;
8932 struct listnode
*pnode
, *pnnode
;
8933 struct ospf_path
*path
;
8934 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
8935 *json_nexthop
= NULL
;
8939 "============ OSPF network routing table ============\n");
8941 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
8942 if ((or = rn
->info
) == NULL
)
8944 char buf1
[PREFIX2STR_BUFFER
];
8946 memset(buf1
, 0, sizeof(buf1
));
8947 prefix2str(&rn
->p
, buf1
, sizeof(buf1
));
8949 json_route
= json_object_new_object();
8951 json_object_object_add(json
, buf1
, json_route
);
8952 json_object_to_json_string_ext(
8953 json
, JSON_C_TO_STRING_NOSLASHESCAPE
);
8956 switch (or->path_type
) {
8957 case OSPF_PATH_INTER_AREA
:
8958 if (or->type
== OSPF_DESTINATION_NETWORK
) {
8960 json_object_string_add(json_route
,
8963 json_object_int_add(json_route
, "cost",
8965 json_object_string_add(
8967 inet_ntoa(or->u
.std
.area_id
));
8970 "N IA %-18s [%d] area: %s\n",
8972 inet_ntoa(or->u
.std
.area_id
));
8974 } else if (or->type
== OSPF_DESTINATION_DISCARD
) {
8976 json_object_string_add(json_route
,
8981 "D IA %-18s Discard entry\n",
8986 case OSPF_PATH_INTRA_AREA
:
8988 json_object_string_add(json_route
, "routeType",
8990 json_object_int_add(json_route
, "cost",
8992 json_object_string_add(
8994 inet_ntoa(or->u
.std
.area_id
));
8996 vty_out(vty
, "N %-18s [%d] area: %s\n",
8998 inet_ntoa(or->u
.std
.area_id
));
9005 if (or->type
== OSPF_DESTINATION_NETWORK
) {
9007 json_nexthop_array
= json_object_new_array();
9008 json_object_object_add(json_route
, "nexthops",
9009 json_nexthop_array
);
9012 for (ALL_LIST_ELEMENTS(or->paths
, pnode
, pnnode
,
9015 json_nexthop
= json_object_new_object();
9016 json_object_array_add(
9020 if (if_lookup_by_index(path
->ifindex
,
9023 if (path
->nexthop
.s_addr
== 0) {
9025 json_object_string_add(
9028 json_object_string_add(
9030 "directly attached to",
9036 "%24s directly attached to %s\n",
9044 json_object_string_add(
9049 json_object_string_add(
9057 "%24s via %s, %s\n",
9070 json_object_free(json_route
);
9076 static void show_ip_ospf_route_router(struct vty
*vty
, struct ospf
*ospf
,
9077 struct route_table
*rtrs
,
9080 struct route_node
*rn
;
9081 struct ospf_route
* or ;
9082 struct listnode
*pnode
;
9083 struct listnode
*node
;
9084 struct ospf_path
*path
;
9085 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
9086 *json_nexthop
= NULL
;
9090 "============ OSPF router routing table =============\n");
9092 for (rn
= route_top(rtrs
); rn
; rn
= route_next(rn
)) {
9093 if (rn
->info
== NULL
)
9097 json_route
= json_object_new_object();
9099 json_object_object_add(json
, inet_ntoa(rn
->p
.u
.prefix4
),
9101 json_object_string_add(json_route
, "routeType", "R ");
9103 vty_out(vty
, "R %-15s ",
9104 inet_ntoa(rn
->p
.u
.prefix4
));
9107 for (ALL_LIST_ELEMENTS_RO((struct list
*)rn
->info
, node
, or)) {
9110 vty_out(vty
, "%24s", "");
9115 json_object_int_add(json_route
, "cost",
9117 json_object_string_add(
9119 inet_ntoa(or->u
.std
.area_id
));
9120 if (or->path_type
== OSPF_PATH_INTER_AREA
)
9121 json_object_boolean_true_add(json_route
,
9123 if (or->u
.std
.flags
& ROUTER_LSA_BORDER
)
9124 json_object_string_add(json_route
,
9127 else if (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
)
9128 json_object_string_add(json_route
,
9132 vty_out(vty
, "%s [%d] area: %s",
9133 (or->path_type
== OSPF_PATH_INTER_AREA
9136 or->cost
, inet_ntoa(or->u
.std
.area_id
));
9138 vty_out(vty
, "%s%s\n",
9139 (or->u
.std
.flags
& ROUTER_LSA_BORDER
9142 (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
9148 json_nexthop_array
= json_object_new_array();
9149 json_object_object_add(json_route
, "nexthops",
9150 json_nexthop_array
);
9153 for (ALL_LIST_ELEMENTS_RO(or->paths
, pnode
, path
)) {
9155 json_nexthop
= json_object_new_object();
9156 json_object_array_add(
9160 if (if_lookup_by_index(path
->ifindex
,
9162 if (path
->nexthop
.s_addr
== 0) {
9164 json_object_string_add(
9167 json_object_string_add(
9169 "directly attached to",
9175 "%24s directly attached to %s\n",
9183 json_object_string_add(
9188 json_object_string_add(
9196 "%24s via %s, %s\n",
9209 json_object_free(json_route
);
9215 static void show_ip_ospf_route_external(struct vty
*vty
, struct ospf
*ospf
,
9216 struct route_table
*rt
,
9219 struct route_node
*rn
;
9220 struct ospf_route
*er
;
9221 struct listnode
*pnode
, *pnnode
;
9222 struct ospf_path
*path
;
9223 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
9224 *json_nexthop
= NULL
;
9228 "============ OSPF external routing table ===========\n");
9230 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
9231 if ((er
= rn
->info
) == NULL
)
9236 snprintf(buf1
, 19, "%s/%d", inet_ntoa(rn
->p
.u
.prefix4
),
9238 json_route
= json_object_new_object();
9240 json_object_object_add(json
, buf1
, json_route
);
9241 json_object_to_json_string_ext(
9242 json
, JSON_C_TO_STRING_NOSLASHESCAPE
);
9245 switch (er
->path_type
) {
9246 case OSPF_PATH_TYPE1_EXTERNAL
:
9248 json_object_string_add(json_route
, "routeType",
9250 json_object_int_add(json_route
, "cost",
9254 "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI
9256 buf1
, er
->cost
, er
->u
.ext
.tag
);
9259 case OSPF_PATH_TYPE2_EXTERNAL
:
9261 json_object_string_add(json_route
, "routeType",
9263 json_object_int_add(json_route
, "cost",
9267 "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI
9269 buf1
, er
->cost
, er
->u
.ext
.type2_cost
,
9276 json_nexthop_array
= json_object_new_array();
9277 json_object_object_add(json_route
, "nexthops",
9278 json_nexthop_array
);
9281 for (ALL_LIST_ELEMENTS(er
->paths
, pnode
, pnnode
, path
)) {
9283 json_nexthop
= json_object_new_object();
9284 json_object_array_add(json_nexthop_array
,
9288 if (if_lookup_by_index(path
->ifindex
, ospf
->vrf_id
)) {
9289 if (path
->nexthop
.s_addr
== 0) {
9291 json_object_string_add(
9294 json_object_string_add(
9296 "directly attached to",
9302 "%24s directly attached to %s\n",
9310 json_object_string_add(
9314 json_object_string_add(
9315 json_nexthop
, "via",
9321 "%24s via %s, %s\n",
9333 json_object_free(json_route
);
9339 static int show_ip_ospf_border_routers_common(struct vty
*vty
,
9344 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
9346 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
9348 if (ospf
->new_table
== NULL
) {
9349 vty_out(vty
, "No OSPF routing information exist\n");
9353 /* Show Network routes.
9354 show_ip_ospf_route_network (vty, ospf->new_table); */
9356 /* Show Router routes. */
9357 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, NULL
);
9364 DEFUN (show_ip_ospf_border_routers
,
9365 show_ip_ospf_border_routers_cmd
,
9366 "show ip ospf [vrf <NAME|all>] border-routers",
9369 "OSPF information\n"
9372 "Show all the ABR's and ASBR's\n")
9374 struct ospf
*ospf
= NULL
;
9375 struct listnode
*node
= NULL
;
9376 char *vrf_name
= NULL
;
9377 bool all_vrf
= FALSE
;
9378 int ret
= CMD_SUCCESS
;
9381 uint8_t use_vrf
= 0;
9383 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
9386 bool ospf_output
= FALSE
;
9391 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9392 if (!ospf
->oi_running
)
9396 ret
= show_ip_ospf_border_routers_common(
9397 vty
, ospf
, use_vrf
);
9401 vty_out(vty
, "%% OSPF instance not found\n");
9403 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
9404 if (ospf
== NULL
|| !ospf
->oi_running
) {
9405 vty_out(vty
, "%% OSPF instance not found\n");
9409 ret
= show_ip_ospf_border_routers_common(vty
, ospf
,
9413 /* Display default ospf (instance 0) info */
9414 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
9415 if (ospf
== NULL
|| !ospf
->oi_running
) {
9416 vty_out(vty
, "%% OSPF instance not found\n");
9420 ret
= show_ip_ospf_border_routers_common(vty
, ospf
, use_vrf
);
9426 DEFUN (show_ip_ospf_instance_border_routers
,
9427 show_ip_ospf_instance_border_routers_cmd
,
9428 "show ip ospf (1-65535) border-routers",
9431 "OSPF information\n"
9433 "Show all the ABR's and ASBR's\n")
9437 unsigned short instance
= 0;
9439 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9440 ospf
= ospf_lookup_instance(instance
);
9442 return CMD_NOT_MY_INSTANCE
;
9444 if (!ospf
->oi_running
)
9447 return show_ip_ospf_border_routers_common(vty
, ospf
, 0);
9450 static int show_ip_ospf_route_common(struct vty
*vty
, struct ospf
*ospf
,
9451 json_object
*json
, uint8_t use_vrf
)
9453 json_object
*json_vrf
= NULL
;
9456 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
9461 json_vrf
= json_object_new_object();
9466 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
9468 if (ospf
->new_table
== NULL
) {
9469 vty_out(vty
, "No OSPF routing information exist\n");
9473 /* Show Network routes. */
9474 show_ip_ospf_route_network(vty
, ospf
, ospf
->new_table
, json_vrf
);
9476 /* Show Router routes. */
9477 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, json_vrf
);
9479 /* Show AS External routes. */
9480 show_ip_ospf_route_external(vty
, ospf
, ospf
->old_external_route
,
9485 // json_object_object_add(json_vrf, "areas",
9487 if (ospf
->vrf_id
== VRF_DEFAULT
)
9488 json_object_object_add(json
, "default",
9491 json_object_object_add(json
, ospf
->name
,
9501 DEFUN (show_ip_ospf_route
,
9502 show_ip_ospf_route_cmd
,
9503 "show ip ospf [vrf <NAME|all>] route [json]",
9506 "OSPF information\n"
9509 "OSPF routing table\n"
9512 struct ospf
*ospf
= NULL
;
9513 struct listnode
*node
= NULL
;
9514 char *vrf_name
= NULL
;
9515 bool all_vrf
= FALSE
;
9516 int ret
= CMD_SUCCESS
;
9519 uint8_t use_vrf
= 0;
9520 bool uj
= use_json(argc
, argv
);
9521 json_object
*json
= NULL
;
9524 json
= json_object_new_object();
9526 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
9528 /* vrf input is provided could be all or specific vrf*/
9530 bool ospf_output
= FALSE
;
9535 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9536 if (!ospf
->oi_running
)
9539 ret
= show_ip_ospf_route_common(vty
, ospf
, json
,
9544 /* Keep Non-pretty format */
9545 vty_out(vty
, "%s\n",
9546 json_object_to_json_string(json
));
9547 json_object_free(json
);
9548 } else if (!ospf_output
)
9549 vty_out(vty
, "%% OSPF instance not found\n");
9553 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
9554 if (ospf
== NULL
|| !ospf
->oi_running
) {
9556 vty_out(vty
, "%s\n",
9557 json_object_to_json_string_ext(
9558 json
, JSON_C_TO_STRING_PRETTY
));
9559 json_object_free(json
);
9561 vty_out(vty
, "%% OSPF instance not found\n");
9566 /* Display default ospf (instance 0) info */
9567 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
9568 if (ospf
== NULL
|| !ospf
->oi_running
) {
9570 vty_out(vty
, "%s\n",
9571 json_object_to_json_string_ext(
9572 json
, JSON_C_TO_STRING_PRETTY
));
9573 json_object_free(json
);
9575 vty_out(vty
, "%% OSPF instance not found\n");
9582 ret
= show_ip_ospf_route_common(vty
, ospf
, json
, use_vrf
);
9583 /* Keep Non-pretty format */
9585 vty_out(vty
, "%s\n", json_object_to_json_string(json
));
9589 json_object_free(json
);
9594 DEFUN (show_ip_ospf_instance_route
,
9595 show_ip_ospf_instance_route_cmd
,
9596 "show ip ospf (1-65535) route",
9599 "OSPF information\n"
9601 "OSPF routing table\n")
9605 unsigned short instance
= 0;
9607 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9608 ospf
= ospf_lookup_instance(instance
);
9610 return CMD_NOT_MY_INSTANCE
;
9612 if (!ospf
->oi_running
)
9615 return show_ip_ospf_route_common(vty
, ospf
, NULL
, 0);
9619 DEFUN (show_ip_ospf_vrfs
,
9620 show_ip_ospf_vrfs_cmd
,
9621 "show ip ospf vrfs [json]",
9624 "OSPF information\n"
9628 bool uj
= use_json(argc
, argv
);
9629 json_object
*json
= NULL
;
9630 json_object
*json_vrfs
= NULL
;
9631 struct ospf
*ospf
= NULL
;
9632 struct listnode
*node
= NULL
;
9634 static char header
[] = "Name Id RouterId ";
9637 json
= json_object_new_object();
9638 json_vrfs
= json_object_new_object();
9641 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9642 json_object
*json_vrf
= NULL
;
9643 const char *name
= NULL
;
9644 int64_t vrf_id_ui
= 0;
9648 if (!uj
&& count
== 1)
9649 vty_out(vty
, "%s\n", header
);
9651 json_vrf
= json_object_new_object();
9653 if (ospf
->vrf_id
== 0)
9654 name
= VRF_DEFAULT_NAME
;
9658 vrf_id_ui
= (ospf
->vrf_id
== VRF_UNKNOWN
)
9660 : (int64_t)ospf
->vrf_id
;
9663 json_object_int_add(json_vrf
, "vrfId", vrf_id_ui
);
9664 json_object_string_add(json_vrf
, "routerId",
9665 inet_ntoa(ospf
->router_id
));
9667 json_object_object_add(json_vrfs
, name
, json_vrf
);
9670 vty_out(vty
, "%-25s %-5d %-16s \n", name
,
9671 ospf
->vrf_id
, inet_ntoa(ospf
->router_id
));
9676 json_object_object_add(json
, "vrfs", json_vrfs
);
9677 json_object_int_add(json
, "totalVrfs", count
);
9679 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
9680 json
, JSON_C_TO_STRING_PRETTY
));
9681 json_object_free(json
);
9684 vty_out(vty
, "\nTotal number of OSPF VRFs: %d\n",
9691 const char *ospf_abr_type_str
[] = {"unknown", "standard", "ibm", "cisco",
9694 const char *ospf_shortcut_mode_str
[] = {"default", "enable", "disable"};
9696 const char *ospf_int_type_str
[] = {"unknown", /* should never be used. */
9697 "point-to-point", "broadcast",
9698 "non-broadcast", "point-to-multipoint",
9699 "virtual-link", /* should never be used. */
9702 static int config_write_interface_one(struct vty
*vty
, struct vrf
*vrf
)
9704 struct listnode
*node
;
9705 struct interface
*ifp
;
9706 struct crypt_key
*ck
;
9707 struct route_node
*rn
= NULL
;
9708 struct ospf_if_params
*params
;
9710 struct ospf
*ospf
= vrf
->info
;
9712 FOR_ALL_INTERFACES (vrf
, ifp
) {
9714 if (memcmp(ifp
->name
, "VLINK", 5) == 0)
9717 vty_frame(vty
, "!\n");
9718 if (ifp
->vrf_id
== VRF_DEFAULT
)
9719 vty_frame(vty
, "interface %s\n", ifp
->name
);
9721 vty_frame(vty
, "interface %s vrf %s\n", ifp
->name
,
9724 vty_out(vty
, " description %s\n", ifp
->desc
);
9728 params
= IF_DEF_PARAMS(ifp
);
9731 /* Interface Network print. */
9732 if (OSPF_IF_PARAM_CONFIGURED(params
, type
)
9733 && params
->type
!= OSPF_IFTYPE_LOOPBACK
) {
9734 if (params
->type
!= ospf_default_iftype(ifp
)) {
9735 vty_out(vty
, " ip ospf network %s",
9738 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9746 /* OSPF interface authentication print */
9747 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_type
)
9748 && params
->auth_type
!= OSPF_AUTH_NOTSET
) {
9749 const char *auth_str
;
9751 /* Translation tables are not that much help
9752 * here due to syntax
9753 * of the simple option */
9754 switch (params
->auth_type
) {
9756 case OSPF_AUTH_NULL
:
9760 case OSPF_AUTH_SIMPLE
:
9764 case OSPF_AUTH_CRYPTOGRAPHIC
:
9765 auth_str
= " message-digest";
9773 vty_out(vty
, " ip ospf authentication%s",
9775 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9777 inet_ntoa(rn
->p
.u
.prefix4
));
9781 /* Simple Authentication Password print. */
9782 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_simple
)
9783 && params
->auth_simple
[0] != '\0') {
9784 vty_out(vty
, " ip ospf authentication-key %s",
9785 params
->auth_simple
);
9786 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9788 inet_ntoa(rn
->p
.u
.prefix4
));
9792 /* Cryptographic Authentication Key print. */
9793 if (params
&& params
->auth_crypt
) {
9794 for (ALL_LIST_ELEMENTS_RO(params
->auth_crypt
,
9797 " ip ospf message-digest-key %d md5 %s",
9798 ck
->key_id
, ck
->auth_key
);
9799 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9807 /* Interface Output Cost print. */
9808 if (OSPF_IF_PARAM_CONFIGURED(params
, output_cost_cmd
)) {
9809 vty_out(vty
, " ip ospf cost %u",
9810 params
->output_cost_cmd
);
9811 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9813 inet_ntoa(rn
->p
.u
.prefix4
));
9817 /* Hello Interval print. */
9818 if (OSPF_IF_PARAM_CONFIGURED(params
, v_hello
)
9819 && params
->v_hello
!= OSPF_HELLO_INTERVAL_DEFAULT
) {
9820 vty_out(vty
, " ip ospf hello-interval %u",
9822 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9824 inet_ntoa(rn
->p
.u
.prefix4
));
9829 /* Router Dead Interval print. */
9830 if (OSPF_IF_PARAM_CONFIGURED(params
, v_wait
)
9832 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
) {
9833 vty_out(vty
, " ip ospf dead-interval ");
9836 if (OSPF_IF_PARAM_CONFIGURED(params
,
9839 "minimal hello-multiplier %d",
9840 params
->fast_hello
);
9842 vty_out(vty
, "%u", params
->v_wait
);
9844 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9846 inet_ntoa(rn
->p
.u
.prefix4
));
9850 /* Router Priority print. */
9851 if (OSPF_IF_PARAM_CONFIGURED(params
, priority
)
9853 != OSPF_ROUTER_PRIORITY_DEFAULT
) {
9854 vty_out(vty
, " ip ospf priority %u",
9856 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9858 inet_ntoa(rn
->p
.u
.prefix4
));
9862 /* Retransmit Interval print. */
9863 if (OSPF_IF_PARAM_CONFIGURED(params
,
9864 retransmit_interval
)
9865 && params
->retransmit_interval
9866 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
) {
9867 vty_out(vty
, " ip ospf retransmit-interval %u",
9868 params
->retransmit_interval
);
9869 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9871 inet_ntoa(rn
->p
.u
.prefix4
));
9875 /* Transmit Delay print. */
9876 if (OSPF_IF_PARAM_CONFIGURED(params
, transmit_delay
)
9877 && params
->transmit_delay
9878 != OSPF_TRANSMIT_DELAY_DEFAULT
) {
9879 vty_out(vty
, " ip ospf transmit-delay %u",
9880 params
->transmit_delay
);
9881 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9883 inet_ntoa(rn
->p
.u
.prefix4
));
9888 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
9889 if (ospf
&& ospf
->instance
)
9890 vty_out(vty
, " ip ospf %d",
9893 vty_out(vty
, " ip ospf");
9895 char buf
[INET_ADDRSTRLEN
];
9897 area_id2str(buf
, sizeof(buf
), ¶ms
->if_area
,
9898 params
->if_area_id_fmt
);
9899 vty_out(vty
, " area %s", buf
);
9900 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9902 inet_ntoa(rn
->p
.u
.prefix4
));
9907 if (params
&& params
->bfd_info
)
9908 ospf_bfd_write_config(vty
, params
);
9910 /* MTU ignore print. */
9911 if (OSPF_IF_PARAM_CONFIGURED(params
, mtu_ignore
)
9912 && params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
) {
9913 if (params
->mtu_ignore
== 0)
9914 vty_out(vty
, " no ip ospf mtu-ignore");
9916 vty_out(vty
, " ip ospf mtu-ignore");
9917 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9919 inet_ntoa(rn
->p
.u
.prefix4
));
9926 rn
= route_top(IF_OIFS_PARAMS(ifp
));
9928 rn
= route_next(rn
);
9938 ospf_opaque_config_write_if(vty
, ifp
);
9940 vty_endframe(vty
, NULL
);
9946 /* Configuration write function for ospfd. */
9947 static int config_write_interface(struct vty
*vty
)
9950 struct vrf
*vrf
= NULL
;
9952 /* Display all VRF aware OSPF interface configuration */
9953 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
9954 write
+= config_write_interface_one(vty
, vrf
);
9960 static int config_write_network_area(struct vty
*vty
, struct ospf
*ospf
)
9962 struct route_node
*rn
;
9963 uint8_t buf
[INET_ADDRSTRLEN
];
9965 /* `network area' print. */
9966 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
))
9968 struct ospf_network
*n
= rn
->info
;
9970 /* Create Area ID string by specified Area ID format. */
9971 if (n
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
9972 inet_ntop(AF_INET
, &n
->area_id
, (char *)buf
,
9975 sprintf((char *)buf
, "%lu",
9976 (unsigned long int)ntohl(
9977 n
->area_id
.s_addr
));
9979 /* Network print. */
9980 vty_out(vty
, " network %s/%d area %s\n",
9981 inet_ntoa(rn
->p
.u
.prefix4
), rn
->p
.prefixlen
,
9988 static int config_write_ospf_area(struct vty
*vty
, struct ospf
*ospf
)
9990 struct listnode
*node
;
9991 struct ospf_area
*area
;
9992 uint8_t buf
[INET_ADDRSTRLEN
];
9994 /* Area configuration print. */
9995 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
9996 struct route_node
*rn1
;
9998 area_id2str((char *)buf
, sizeof(buf
), &area
->area_id
,
10001 if (area
->auth_type
!= OSPF_AUTH_NULL
) {
10002 if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
10003 vty_out(vty
, " area %s authentication\n", buf
);
10006 " area %s authentication message-digest\n",
10010 if (area
->shortcut_configured
!= OSPF_SHORTCUT_DEFAULT
)
10011 vty_out(vty
, " area %s shortcut %s\n", buf
,
10012 ospf_shortcut_mode_str
10013 [area
->shortcut_configured
]);
10015 if ((area
->external_routing
== OSPF_AREA_STUB
)
10016 || (area
->external_routing
== OSPF_AREA_NSSA
)) {
10017 if (area
->external_routing
== OSPF_AREA_STUB
) {
10018 vty_out(vty
, " area %s stub", buf
);
10019 if (area
->no_summary
)
10020 vty_out(vty
, " no-summary\n");
10021 vty_out(vty
, "\n");
10022 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
10023 switch (area
->NSSATranslatorRole
) {
10024 case OSPF_NSSA_ROLE_NEVER
:
10026 " area %s nssa translate-never\n",
10029 case OSPF_NSSA_ROLE_ALWAYS
:
10031 " area %s nssa translate-always\n",
10034 case OSPF_NSSA_ROLE_CANDIDATE
:
10035 vty_out(vty
, " area %s nssa \n", buf
);
10038 if (area
->no_summary
)
10040 " area %s nssa no-summary\n",
10044 if (area
->default_cost
!= 1)
10045 vty_out(vty
, " area %s default-cost %d\n", buf
,
10046 area
->default_cost
);
10049 for (rn1
= route_top(area
->ranges
); rn1
; rn1
= route_next(rn1
))
10051 struct ospf_area_range
*range
= rn1
->info
;
10053 vty_out(vty
, " area %s range %s/%d", buf
,
10054 inet_ntoa(rn1
->p
.u
.prefix4
),
10057 if (range
->cost_config
10058 != OSPF_AREA_RANGE_COST_UNSPEC
)
10059 vty_out(vty
, " cost %d",
10060 range
->cost_config
);
10062 if (!CHECK_FLAG(range
->flags
,
10063 OSPF_AREA_RANGE_ADVERTISE
))
10064 vty_out(vty
, " not-advertise");
10066 if (CHECK_FLAG(range
->flags
,
10067 OSPF_AREA_RANGE_SUBSTITUTE
))
10068 vty_out(vty
, " substitute %s/%d",
10069 inet_ntoa(range
->subst_addr
),
10070 range
->subst_masklen
);
10072 vty_out(vty
, "\n");
10075 if (EXPORT_NAME(area
))
10076 vty_out(vty
, " area %s export-list %s\n", buf
,
10077 EXPORT_NAME(area
));
10079 if (IMPORT_NAME(area
))
10080 vty_out(vty
, " area %s import-list %s\n", buf
,
10081 IMPORT_NAME(area
));
10083 if (PREFIX_NAME_IN(area
))
10084 vty_out(vty
, " area %s filter-list prefix %s in\n", buf
,
10085 PREFIX_NAME_IN(area
));
10087 if (PREFIX_NAME_OUT(area
))
10088 vty_out(vty
, " area %s filter-list prefix %s out\n",
10089 buf
, PREFIX_NAME_OUT(area
));
10095 static int config_write_ospf_nbr_nbma(struct vty
*vty
, struct ospf
*ospf
)
10097 struct ospf_nbr_nbma
*nbr_nbma
;
10098 struct route_node
*rn
;
10100 /* Static Neighbor configuration print. */
10101 for (rn
= route_top(ospf
->nbr_nbma
); rn
; rn
= route_next(rn
))
10102 if ((nbr_nbma
= rn
->info
)) {
10103 vty_out(vty
, " neighbor %s", inet_ntoa(nbr_nbma
->addr
));
10105 if (nbr_nbma
->priority
10106 != OSPF_NEIGHBOR_PRIORITY_DEFAULT
)
10107 vty_out(vty
, " priority %d",
10108 nbr_nbma
->priority
);
10110 if (nbr_nbma
->v_poll
!= OSPF_POLL_INTERVAL_DEFAULT
)
10111 vty_out(vty
, " poll-interval %d",
10114 vty_out(vty
, "\n");
10120 static int config_write_virtual_link(struct vty
*vty
, struct ospf
*ospf
)
10122 struct listnode
*node
;
10123 struct ospf_vl_data
*vl_data
;
10124 char buf
[INET_ADDRSTRLEN
];
10126 /* Virtual-Link print */
10127 for (ALL_LIST_ELEMENTS_RO(ospf
->vlinks
, node
, vl_data
)) {
10128 struct listnode
*n2
;
10129 struct crypt_key
*ck
;
10130 struct ospf_interface
*oi
;
10132 if (vl_data
!= NULL
) {
10133 area_id2str(buf
, sizeof(buf
), &vl_data
->vl_area_id
,
10134 vl_data
->vl_area_id_fmt
);
10135 oi
= vl_data
->vl_oi
;
10138 if (OSPF_IF_PARAM(oi
, v_hello
)
10139 != OSPF_HELLO_INTERVAL_DEFAULT
10140 || OSPF_IF_PARAM(oi
, v_wait
)
10141 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
10142 || OSPF_IF_PARAM(oi
, retransmit_interval
)
10143 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
10144 || OSPF_IF_PARAM(oi
, transmit_delay
)
10145 != OSPF_TRANSMIT_DELAY_DEFAULT
)
10147 " area %s virtual-link %s hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n",
10148 buf
, inet_ntoa(vl_data
->vl_peer
),
10149 OSPF_IF_PARAM(oi
, v_hello
),
10150 OSPF_IF_PARAM(oi
, retransmit_interval
),
10151 OSPF_IF_PARAM(oi
, transmit_delay
),
10152 OSPF_IF_PARAM(oi
, v_wait
));
10154 vty_out(vty
, " area %s virtual-link %s\n", buf
,
10155 inet_ntoa(vl_data
->vl_peer
));
10157 if (IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)->auth_simple
[0]
10160 " area %s virtual-link %s authentication-key %s\n",
10161 buf
, inet_ntoa(vl_data
->vl_peer
),
10162 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
10165 for (ALL_LIST_ELEMENTS_RO(
10166 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
10170 " area %s virtual-link %s"
10171 " message-digest-key %d md5 %s\n",
10172 buf
, inet_ntoa(vl_data
->vl_peer
),
10173 ck
->key_id
, ck
->auth_key
);
10181 static int config_write_ospf_redistribute(struct vty
*vty
, struct ospf
*ospf
)
10185 /* redistribute print. */
10186 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
10187 struct list
*red_list
;
10188 struct listnode
*node
;
10189 struct ospf_redist
*red
;
10191 red_list
= ospf
->redist
[type
];
10195 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
10196 vty_out(vty
, " redistribute %s",
10197 zebra_route_string(type
));
10199 vty_out(vty
, " %d", red
->instance
);
10201 if (red
->dmetric
.value
>= 0)
10202 vty_out(vty
, " metric %d", red
->dmetric
.value
);
10204 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
10205 vty_out(vty
, " metric-type 1");
10207 if (ROUTEMAP_NAME(red
))
10208 vty_out(vty
, " route-map %s",
10209 ROUTEMAP_NAME(red
));
10211 vty_out(vty
, "\n");
10218 static int config_write_ospf_default_metric(struct vty
*vty
, struct ospf
*ospf
)
10220 if (ospf
->default_metric
!= -1)
10221 vty_out(vty
, " default-metric %d\n", ospf
->default_metric
);
10225 static int config_write_ospf_distribute(struct vty
*vty
, struct ospf
*ospf
)
10228 struct ospf_redist
*red
;
10231 /* distribute-list print. */
10232 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
10233 if (DISTRIBUTE_NAME(ospf
, type
))
10234 vty_out(vty
, " distribute-list %s out %s\n",
10235 DISTRIBUTE_NAME(ospf
, type
),
10236 zebra_route_string(type
));
10238 /* default-information print. */
10239 if (ospf
->default_originate
!= DEFAULT_ORIGINATE_NONE
) {
10240 vty_out(vty
, " default-information originate");
10241 if (ospf
->default_originate
== DEFAULT_ORIGINATE_ALWAYS
)
10242 vty_out(vty
, " always");
10244 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
10246 if (red
->dmetric
.value
>= 0)
10247 vty_out(vty
, " metric %d",
10248 red
->dmetric
.value
);
10250 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
10251 vty_out(vty
, " metric-type 1");
10253 if (ROUTEMAP_NAME(red
))
10254 vty_out(vty
, " route-map %s",
10255 ROUTEMAP_NAME(red
));
10258 vty_out(vty
, "\n");
10265 static int config_write_ospf_distance(struct vty
*vty
, struct ospf
*ospf
)
10267 struct route_node
*rn
;
10268 struct ospf_distance
*odistance
;
10270 if (ospf
->distance_all
)
10271 vty_out(vty
, " distance %d\n", ospf
->distance_all
);
10273 if (ospf
->distance_intra
|| ospf
->distance_inter
10274 || ospf
->distance_external
) {
10275 vty_out(vty
, " distance ospf");
10277 if (ospf
->distance_intra
)
10278 vty_out(vty
, " intra-area %d", ospf
->distance_intra
);
10279 if (ospf
->distance_inter
)
10280 vty_out(vty
, " inter-area %d", ospf
->distance_inter
);
10281 if (ospf
->distance_external
)
10282 vty_out(vty
, " external %d", ospf
->distance_external
);
10284 vty_out(vty
, "\n");
10287 for (rn
= route_top(ospf
->distance_table
); rn
; rn
= route_next(rn
))
10288 if ((odistance
= rn
->info
) != NULL
) {
10289 vty_out(vty
, " distance %d %s/%d %s\n",
10290 odistance
->distance
, inet_ntoa(rn
->p
.u
.prefix4
),
10292 odistance
->access_list
? odistance
->access_list
10298 static int ospf_config_write_one(struct vty
*vty
, struct ospf
*ospf
)
10300 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
10301 struct interface
*ifp
;
10302 struct ospf_interface
*oi
;
10303 struct listnode
*node
= NULL
;
10306 /* `router ospf' print. */
10307 if (ospf
->instance
&& ospf
->name
) {
10308 vty_out(vty
, "router ospf %d vrf %s\n", ospf
->instance
,
10310 } else if (ospf
->instance
) {
10311 vty_out(vty
, "router ospf %d\n", ospf
->instance
);
10312 } else if (ospf
->name
) {
10313 vty_out(vty
, "router ospf vrf %s\n", ospf
->name
);
10315 vty_out(vty
, "router ospf\n");
10317 if (!ospf
->networks
) {
10322 /* Router ID print. */
10323 if (ospf
->router_id_static
.s_addr
!= 0)
10324 vty_out(vty
, " ospf router-id %s\n",
10325 inet_ntoa(ospf
->router_id_static
));
10327 /* ABR type print. */
10328 if (ospf
->abr_type
!= OSPF_ABR_DEFAULT
)
10329 vty_out(vty
, " ospf abr-type %s\n",
10330 ospf_abr_type_str
[ospf
->abr_type
]);
10332 /* log-adjacency-changes flag print. */
10333 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
10334 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
))
10335 vty_out(vty
, " log-adjacency-changes detail\n");
10336 else if (!DFLT_OSPF_LOG_ADJACENCY_CHANGES
)
10337 vty_out(vty
, " log-adjacency-changes\n");
10338 } else if (DFLT_OSPF_LOG_ADJACENCY_CHANGES
) {
10339 vty_out(vty
, " no log-adjacency-changes\n");
10342 /* RFC1583 compatibility flag print -- Compatible with CISCO
10344 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
))
10345 vty_out(vty
, " compatible rfc1583\n");
10347 /* auto-cost reference-bandwidth configuration. */
10348 if (ospf
->ref_bandwidth
!= OSPF_DEFAULT_REF_BANDWIDTH
) {
10350 "! Important: ensure reference bandwidth "
10351 "is consistent across all routers\n");
10352 vty_out(vty
, " auto-cost reference-bandwidth %d\n",
10353 ospf
->ref_bandwidth
);
10356 /* SPF timers print. */
10357 if (ospf
->spf_delay
!= OSPF_SPF_DELAY_DEFAULT
10358 || ospf
->spf_holdtime
!= OSPF_SPF_HOLDTIME_DEFAULT
10359 || ospf
->spf_max_holdtime
!= OSPF_SPF_MAX_HOLDTIME_DEFAULT
)
10360 vty_out(vty
, " timers throttle spf %d %d %d\n", ospf
->spf_delay
,
10361 ospf
->spf_holdtime
, ospf
->spf_max_holdtime
);
10363 /* LSA timers print. */
10364 if (ospf
->min_ls_interval
!= OSPF_MIN_LS_INTERVAL
)
10365 vty_out(vty
, " timers throttle lsa all %d\n",
10366 ospf
->min_ls_interval
);
10367 if (ospf
->min_ls_arrival
!= OSPF_MIN_LS_ARRIVAL
)
10368 vty_out(vty
, " timers lsa min-arrival %d\n",
10369 ospf
->min_ls_arrival
);
10371 /* Write multiplier print. */
10372 if (ospf
->write_oi_count
!= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
)
10373 vty_out(vty
, " ospf write-multiplier %d\n",
10374 ospf
->write_oi_count
);
10376 /* Max-metric router-lsa print */
10377 config_write_stub_router(vty
, ospf
);
10379 /* SPF refresh parameters print. */
10380 if (ospf
->lsa_refresh_interval
!= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
10381 vty_out(vty
, " refresh timer %d\n", ospf
->lsa_refresh_interval
);
10383 /* Redistribute information print. */
10384 config_write_ospf_redistribute(vty
, ospf
);
10386 /* passive-interface print. */
10387 if (ospf
->passive_interface_default
== OSPF_IF_PASSIVE
)
10388 vty_out(vty
, " passive-interface default\n");
10390 FOR_ALL_INTERFACES (vrf
, ifp
)
10391 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp
),
10393 && IF_DEF_PARAMS(ifp
)->passive_interface
10394 != ospf
->passive_interface_default
) {
10395 vty_out(vty
, " %spassive-interface %s\n",
10396 IF_DEF_PARAMS(ifp
)->passive_interface
? ""
10400 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
10401 if (!OSPF_IF_PARAM_CONFIGURED(oi
->params
, passive_interface
))
10403 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(oi
->ifp
),
10404 passive_interface
)) {
10405 if (oi
->params
->passive_interface
10406 == IF_DEF_PARAMS(oi
->ifp
)->passive_interface
)
10408 } else if (oi
->params
->passive_interface
10409 == ospf
->passive_interface_default
)
10412 vty_out(vty
, " %spassive-interface %s %s\n",
10413 oi
->params
->passive_interface
? "" : "no ",
10414 oi
->ifp
->name
, inet_ntoa(oi
->address
->u
.prefix4
));
10417 /* Network area print. */
10418 config_write_network_area(vty
, ospf
);
10420 /* Area config print. */
10421 config_write_ospf_area(vty
, ospf
);
10423 /* static neighbor print. */
10424 config_write_ospf_nbr_nbma(vty
, ospf
);
10426 /* Virtual-Link print. */
10427 config_write_virtual_link(vty
, ospf
);
10429 /* Default metric configuration. */
10430 config_write_ospf_default_metric(vty
, ospf
);
10432 /* Distribute-list and default-information print. */
10433 config_write_ospf_distribute(vty
, ospf
);
10435 /* Distance configuration. */
10436 config_write_ospf_distance(vty
, ospf
);
10438 ospf_opaque_config_write_router(vty
, ospf
);
10444 /* OSPF configuration write function. */
10445 static int ospf_config_write(struct vty
*vty
)
10448 struct listnode
*ospf_node
= NULL
;
10451 if (listcount(om
->ospf
) == 0)
10454 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, ospf_node
, ospf
)) {
10455 /* VRF Default check if it is running.
10456 * Upon daemon start, there could be default instance
10457 * in absence of 'router ospf'/oi_running is disabled. */
10458 if (ospf
->vrf_id
== VRF_DEFAULT
&& ospf
->oi_running
)
10459 write
+= ospf_config_write_one(vty
, ospf
);
10460 /* For Non-Default VRF simply display the configuration,
10461 * even if it is not oi_running. */
10462 else if (ospf
->vrf_id
!= VRF_DEFAULT
)
10463 write
+= ospf_config_write_one(vty
, ospf
);
10468 void ospf_vty_show_init(void)
10470 /* "show ip ospf" commands. */
10471 install_element(VIEW_NODE
, &show_ip_ospf_cmd
);
10473 install_element(VIEW_NODE
, &show_ip_ospf_instance_cmd
);
10475 /* "show ip ospf database" commands. */
10476 install_element(VIEW_NODE
, &show_ip_ospf_database_max_cmd
);
10478 install_element(VIEW_NODE
,
10479 &show_ip_ospf_instance_database_type_adv_router_cmd
);
10480 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_cmd
);
10481 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_max_cmd
);
10483 /* "show ip ospf interface" commands. */
10484 install_element(VIEW_NODE
, &show_ip_ospf_interface_cmd
);
10486 install_element(VIEW_NODE
, &show_ip_ospf_instance_interface_cmd
);
10487 /* "show ip ospf interface traffic */
10488 install_element(VIEW_NODE
, &show_ip_ospf_interface_traffic_cmd
);
10490 /* "show ip ospf neighbor" commands. */
10491 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_detail_cmd
);
10492 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_cmd
);
10493 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_id_cmd
);
10494 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_all_cmd
);
10495 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_cmd
);
10496 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_cmd
);
10497 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_all_cmd
);
10499 install_element(VIEW_NODE
,
10500 &show_ip_ospf_instance_neighbor_int_detail_cmd
);
10501 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_int_cmd
);
10502 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_id_cmd
);
10503 install_element(VIEW_NODE
,
10504 &show_ip_ospf_instance_neighbor_detail_all_cmd
);
10505 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_detail_cmd
);
10506 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_cmd
);
10507 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_all_cmd
);
10509 /* "show ip ospf route" commands. */
10510 install_element(VIEW_NODE
, &show_ip_ospf_route_cmd
);
10511 install_element(VIEW_NODE
, &show_ip_ospf_border_routers_cmd
);
10513 install_element(VIEW_NODE
, &show_ip_ospf_instance_route_cmd
);
10514 install_element(VIEW_NODE
, &show_ip_ospf_instance_border_routers_cmd
);
10516 /* "show ip ospf vrfs" commands. */
10517 install_element(VIEW_NODE
, &show_ip_ospf_vrfs_cmd
);
10521 /* ospfd's interface node. */
10522 static struct cmd_node interface_node
= {INTERFACE_NODE
, "%s(config-if)# ", 1};
10524 /* Initialization of OSPF interface. */
10525 static void ospf_vty_if_init(void)
10527 /* Install interface node. */
10528 install_node(&interface_node
, config_write_interface
);
10531 /* "ip ospf authentication" commands. */
10532 install_element(INTERFACE_NODE
, &ip_ospf_authentication_args_addr_cmd
);
10533 install_element(INTERFACE_NODE
, &ip_ospf_authentication_addr_cmd
);
10534 install_element(INTERFACE_NODE
,
10535 &no_ip_ospf_authentication_args_addr_cmd
);
10536 install_element(INTERFACE_NODE
, &no_ip_ospf_authentication_addr_cmd
);
10537 install_element(INTERFACE_NODE
, &ip_ospf_authentication_key_addr_cmd
);
10538 install_element(INTERFACE_NODE
,
10539 &no_ip_ospf_authentication_key_authkey_addr_cmd
);
10540 install_element(INTERFACE_NODE
,
10541 &no_ospf_authentication_key_authkey_addr_cmd
);
10543 /* "ip ospf message-digest-key" commands. */
10544 install_element(INTERFACE_NODE
, &ip_ospf_message_digest_key_cmd
);
10545 install_element(INTERFACE_NODE
, &no_ip_ospf_message_digest_key_cmd
);
10547 /* "ip ospf cost" commands. */
10548 install_element(INTERFACE_NODE
, &ip_ospf_cost_cmd
);
10549 install_element(INTERFACE_NODE
, &no_ip_ospf_cost_cmd
);
10551 /* "ip ospf mtu-ignore" commands. */
10552 install_element(INTERFACE_NODE
, &ip_ospf_mtu_ignore_addr_cmd
);
10553 install_element(INTERFACE_NODE
, &no_ip_ospf_mtu_ignore_addr_cmd
);
10555 /* "ip ospf dead-interval" commands. */
10556 install_element(INTERFACE_NODE
, &ip_ospf_dead_interval_cmd
);
10557 install_element(INTERFACE_NODE
,
10558 &ip_ospf_dead_interval_minimal_addr_cmd
);
10559 install_element(INTERFACE_NODE
, &no_ip_ospf_dead_interval_cmd
);
10561 /* "ip ospf hello-interval" commands. */
10562 install_element(INTERFACE_NODE
, &ip_ospf_hello_interval_cmd
);
10563 install_element(INTERFACE_NODE
, &no_ip_ospf_hello_interval_cmd
);
10565 /* "ip ospf network" commands. */
10566 install_element(INTERFACE_NODE
, &ip_ospf_network_cmd
);
10567 install_element(INTERFACE_NODE
, &no_ip_ospf_network_cmd
);
10569 /* "ip ospf priority" commands. */
10570 install_element(INTERFACE_NODE
, &ip_ospf_priority_cmd
);
10571 install_element(INTERFACE_NODE
, &no_ip_ospf_priority_cmd
);
10573 /* "ip ospf retransmit-interval" commands. */
10574 install_element(INTERFACE_NODE
, &ip_ospf_retransmit_interval_addr_cmd
);
10575 install_element(INTERFACE_NODE
,
10576 &no_ip_ospf_retransmit_interval_addr_cmd
);
10578 /* "ip ospf transmit-delay" commands. */
10579 install_element(INTERFACE_NODE
, &ip_ospf_transmit_delay_addr_cmd
);
10580 install_element(INTERFACE_NODE
, &no_ip_ospf_transmit_delay_addr_cmd
);
10582 /* "ip ospf area" commands. */
10583 install_element(INTERFACE_NODE
, &ip_ospf_area_cmd
);
10584 install_element(INTERFACE_NODE
, &no_ip_ospf_area_cmd
);
10586 /* These commands are compatibitliy for previous version. */
10587 install_element(INTERFACE_NODE
, &ospf_authentication_key_cmd
);
10588 install_element(INTERFACE_NODE
, &ospf_message_digest_key_cmd
);
10589 install_element(INTERFACE_NODE
, &no_ospf_message_digest_key_cmd
);
10590 install_element(INTERFACE_NODE
, &ospf_dead_interval_cmd
);
10591 install_element(INTERFACE_NODE
, &no_ospf_dead_interval_cmd
);
10592 install_element(INTERFACE_NODE
, &ospf_hello_interval_cmd
);
10593 install_element(INTERFACE_NODE
, &no_ospf_hello_interval_cmd
);
10594 install_element(INTERFACE_NODE
, &ospf_cost_cmd
);
10595 install_element(INTERFACE_NODE
, &no_ospf_cost_cmd
);
10596 install_element(INTERFACE_NODE
, &ospf_network_cmd
);
10597 install_element(INTERFACE_NODE
, &no_ospf_network_cmd
);
10598 install_element(INTERFACE_NODE
, &ospf_priority_cmd
);
10599 install_element(INTERFACE_NODE
, &no_ospf_priority_cmd
);
10600 install_element(INTERFACE_NODE
, &ospf_retransmit_interval_cmd
);
10601 install_element(INTERFACE_NODE
, &no_ospf_retransmit_interval_cmd
);
10602 install_element(INTERFACE_NODE
, &ospf_transmit_delay_cmd
);
10603 install_element(INTERFACE_NODE
, &no_ospf_transmit_delay_cmd
);
10606 static void ospf_vty_zebra_init(void)
10608 install_element(OSPF_NODE
, &ospf_redistribute_source_cmd
);
10609 install_element(OSPF_NODE
, &no_ospf_redistribute_source_cmd
);
10610 install_element(OSPF_NODE
, &ospf_redistribute_instance_source_cmd
);
10611 install_element(OSPF_NODE
, &no_ospf_redistribute_instance_source_cmd
);
10613 install_element(OSPF_NODE
, &ospf_distribute_list_out_cmd
);
10614 install_element(OSPF_NODE
, &no_ospf_distribute_list_out_cmd
);
10616 install_element(OSPF_NODE
, &ospf_default_information_originate_cmd
);
10617 install_element(OSPF_NODE
, &no_ospf_default_information_originate_cmd
);
10619 install_element(OSPF_NODE
, &ospf_default_metric_cmd
);
10620 install_element(OSPF_NODE
, &no_ospf_default_metric_cmd
);
10622 install_element(OSPF_NODE
, &ospf_distance_cmd
);
10623 install_element(OSPF_NODE
, &no_ospf_distance_cmd
);
10624 install_element(OSPF_NODE
, &no_ospf_distance_ospf_cmd
);
10625 install_element(OSPF_NODE
, &ospf_distance_ospf_cmd
);
10627 install_element (OSPF_NODE
, &ospf_distance_source_cmd
);
10628 install_element (OSPF_NODE
, &no_ospf_distance_source_cmd
);
10629 install_element (OSPF_NODE
, &ospf_distance_source_access_list_cmd
);
10630 install_element (OSPF_NODE
, &no_ospf_distance_source_access_list_cmd
);
10634 static struct cmd_node ospf_node
= {OSPF_NODE
, "%s(config-router)# ", 1};
10636 static void ospf_interface_clear(struct interface
*ifp
)
10638 if (!if_is_operative(ifp
))
10641 if (IS_DEBUG_OSPF(ism
, ISM_EVENTS
))
10642 zlog_debug("ISM[%s]: clear by reset", ifp
->name
);
10644 ospf_if_reset(ifp
);
10647 DEFUN (clear_ip_ospf_interface
,
10648 clear_ip_ospf_interface_cmd
,
10649 "clear ip ospf [vrf <NAME>] interface [IFNAME]",
10652 "OSPF information\n"
10654 "Interface information\n"
10655 "Interface name\n")
10657 int idx_ifname
= 0;
10659 struct interface
*ifp
;
10660 struct listnode
*node
;
10661 struct ospf
*ospf
= NULL
;
10662 char *vrf_name
= NULL
;
10663 vrf_id_t vrf_id
= VRF_DEFAULT
;
10664 struct vrf
*vrf
= NULL
;
10666 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
10667 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
10668 if (vrf_name
&& strmatch(vrf_name
, VRF_DEFAULT_NAME
))
10671 vrf
= vrf_lookup_by_name(vrf_name
);
10673 vrf_id
= vrf
->vrf_id
;
10675 if (!argv_find(argv
, argc
, "IFNAME", &idx_ifname
)) {
10676 /* Clear all the ospfv2 interfaces. */
10677 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
10678 if (vrf_id
!= ospf
->vrf_id
)
10681 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
10682 FOR_ALL_INTERFACES (vrf
, ifp
)
10683 ospf_interface_clear(ifp
);
10686 /* Interface name is specified. */
10687 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf_id
);
10689 vty_out(vty
, "No such interface name\n");
10691 ospf_interface_clear(ifp
);
10694 return CMD_SUCCESS
;
10697 void ospf_vty_clear_init(void)
10699 install_element(ENABLE_NODE
, &clear_ip_ospf_interface_cmd
);
10703 /* Install OSPF related vty commands. */
10704 void ospf_vty_init(void)
10706 /* Install ospf top node. */
10707 install_node(&ospf_node
, ospf_config_write
);
10709 /* "router ospf" commands. */
10710 install_element(CONFIG_NODE
, &router_ospf_cmd
);
10711 install_element(CONFIG_NODE
, &no_router_ospf_cmd
);
10714 install_default(OSPF_NODE
);
10716 /* "ospf router-id" commands. */
10717 install_element(OSPF_NODE
, &ospf_router_id_cmd
);
10718 install_element(OSPF_NODE
, &ospf_router_id_old_cmd
);
10719 install_element(OSPF_NODE
, &no_ospf_router_id_cmd
);
10721 /* "passive-interface" commands. */
10722 install_element(OSPF_NODE
, &ospf_passive_interface_addr_cmd
);
10723 install_element(OSPF_NODE
, &no_ospf_passive_interface_addr_cmd
);
10725 /* "ospf abr-type" commands. */
10726 install_element(OSPF_NODE
, &ospf_abr_type_cmd
);
10727 install_element(OSPF_NODE
, &no_ospf_abr_type_cmd
);
10729 /* "ospf log-adjacency-changes" commands. */
10730 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_cmd
);
10731 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_detail_cmd
);
10732 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_cmd
);
10733 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_detail_cmd
);
10735 /* "ospf rfc1583-compatible" commands. */
10736 install_element(OSPF_NODE
, &ospf_compatible_rfc1583_cmd
);
10737 install_element(OSPF_NODE
, &no_ospf_compatible_rfc1583_cmd
);
10738 install_element(OSPF_NODE
, &ospf_rfc1583_flag_cmd
);
10739 install_element(OSPF_NODE
, &no_ospf_rfc1583_flag_cmd
);
10741 /* "network area" commands. */
10742 install_element(OSPF_NODE
, &ospf_network_area_cmd
);
10743 install_element(OSPF_NODE
, &no_ospf_network_area_cmd
);
10745 /* "area authentication" commands. */
10746 install_element(OSPF_NODE
,
10747 &ospf_area_authentication_message_digest_cmd
);
10748 install_element(OSPF_NODE
, &ospf_area_authentication_cmd
);
10749 install_element(OSPF_NODE
, &no_ospf_area_authentication_cmd
);
10751 /* "area range" commands. */
10752 install_element(OSPF_NODE
, &ospf_area_range_cmd
);
10753 install_element(OSPF_NODE
, &ospf_area_range_cost_cmd
);
10754 install_element(OSPF_NODE
, &ospf_area_range_not_advertise_cmd
);
10755 install_element(OSPF_NODE
, &no_ospf_area_range_cmd
);
10756 install_element(OSPF_NODE
, &ospf_area_range_substitute_cmd
);
10757 install_element(OSPF_NODE
, &no_ospf_area_range_substitute_cmd
);
10759 /* "area virtual-link" commands. */
10760 install_element(OSPF_NODE
, &ospf_area_vlink_cmd
);
10761 install_element(OSPF_NODE
, &ospf_area_vlink_intervals_cmd
);
10762 install_element(OSPF_NODE
, &no_ospf_area_vlink_cmd
);
10763 install_element(OSPF_NODE
, &no_ospf_area_vlink_intervals_cmd
);
10766 /* "area stub" commands. */
10767 install_element(OSPF_NODE
, &ospf_area_stub_no_summary_cmd
);
10768 install_element(OSPF_NODE
, &ospf_area_stub_cmd
);
10769 install_element(OSPF_NODE
, &no_ospf_area_stub_no_summary_cmd
);
10770 install_element(OSPF_NODE
, &no_ospf_area_stub_cmd
);
10772 /* "area nssa" commands. */
10773 install_element(OSPF_NODE
, &ospf_area_nssa_cmd
);
10774 install_element(OSPF_NODE
, &ospf_area_nssa_translate_cmd
);
10775 install_element(OSPF_NODE
, &ospf_area_nssa_no_summary_cmd
);
10776 install_element(OSPF_NODE
, &no_ospf_area_nssa_no_summary_cmd
);
10777 install_element(OSPF_NODE
, &no_ospf_area_nssa_cmd
);
10779 install_element(OSPF_NODE
, &ospf_area_default_cost_cmd
);
10780 install_element(OSPF_NODE
, &no_ospf_area_default_cost_cmd
);
10782 install_element(OSPF_NODE
, &ospf_area_shortcut_cmd
);
10783 install_element(OSPF_NODE
, &no_ospf_area_shortcut_cmd
);
10785 install_element(OSPF_NODE
, &ospf_area_export_list_cmd
);
10786 install_element(OSPF_NODE
, &no_ospf_area_export_list_cmd
);
10788 install_element(OSPF_NODE
, &ospf_area_filter_list_cmd
);
10789 install_element(OSPF_NODE
, &no_ospf_area_filter_list_cmd
);
10791 install_element(OSPF_NODE
, &ospf_area_import_list_cmd
);
10792 install_element(OSPF_NODE
, &no_ospf_area_import_list_cmd
);
10794 /* SPF timer commands */
10795 install_element(OSPF_NODE
, &ospf_timers_throttle_spf_cmd
);
10796 install_element(OSPF_NODE
, &no_ospf_timers_throttle_spf_cmd
);
10798 /* LSA timers commands */
10799 install_element(OSPF_NODE
, &ospf_timers_min_ls_interval_cmd
);
10800 install_element(OSPF_NODE
, &no_ospf_timers_min_ls_interval_cmd
);
10801 install_element(OSPF_NODE
, &ospf_timers_lsa_min_arrival_cmd
);
10802 install_element(OSPF_NODE
, &no_ospf_timers_lsa_min_arrival_cmd
);
10804 /* refresh timer commands */
10805 install_element(OSPF_NODE
, &ospf_refresh_timer_cmd
);
10806 install_element(OSPF_NODE
, &no_ospf_refresh_timer_val_cmd
);
10808 /* max-metric commands */
10809 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_admin_cmd
);
10810 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_admin_cmd
);
10811 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_startup_cmd
);
10812 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_startup_cmd
);
10813 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_shutdown_cmd
);
10814 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_shutdown_cmd
);
10816 /* reference bandwidth commands */
10817 install_element(OSPF_NODE
, &ospf_auto_cost_reference_bandwidth_cmd
);
10818 install_element(OSPF_NODE
, &no_ospf_auto_cost_reference_bandwidth_cmd
);
10820 /* "neighbor" commands. */
10821 install_element(OSPF_NODE
, &ospf_neighbor_cmd
);
10822 install_element(OSPF_NODE
, &ospf_neighbor_poll_interval_cmd
);
10823 install_element(OSPF_NODE
, &no_ospf_neighbor_cmd
);
10824 install_element(OSPF_NODE
, &no_ospf_neighbor_poll_cmd
);
10826 /* write multiplier commands */
10827 install_element(OSPF_NODE
, &ospf_write_multiplier_cmd
);
10828 install_element(OSPF_NODE
, &write_multiplier_cmd
);
10829 install_element(OSPF_NODE
, &no_ospf_write_multiplier_cmd
);
10830 install_element(OSPF_NODE
, &no_write_multiplier_cmd
);
10832 /* Init interface related vty commands. */
10833 ospf_vty_if_init();
10835 /* Init zebra related vty commands. */
10836 ospf_vty_zebra_init();