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
,
3745 vrf_lookup_by_id(ospf
->vrf_id
));
3748 json_object_boolean_true_add(json_vrf
,
3751 vty_out(vty
, "No such interface name\n");
3754 json_interface_sub
= json_object_new_object();
3755 json_interface
= json_object_new_object();
3758 show_ip_ospf_interface_sub(
3759 vty
, ospf
, ifp
, json_interface_sub
, use_json
);
3762 json_object_object_add(json_interface
,
3764 json_interface_sub
);
3765 json_object_object_add(json_vrf
, "interfaces",
3773 if (ospf
->vrf_id
== VRF_DEFAULT
)
3774 json_object_object_add(json
, "default",
3777 json_object_object_add(json
, ospf
->name
,
3786 static void show_ip_ospf_interface_traffic_sub(struct vty
*vty
,
3787 struct ospf_interface
*oi
,
3788 json_object
*json_interface_sub
,
3792 json_object_int_add(json_interface_sub
, "ifIndex",
3794 json_object_int_add(json_interface_sub
, "helloIn",
3796 json_object_int_add(json_interface_sub
, "helloOut",
3798 json_object_int_add(json_interface_sub
, "dbDescIn",
3800 json_object_int_add(json_interface_sub
, "dbDescOut",
3802 json_object_int_add(json_interface_sub
, "lsReqIn",
3804 json_object_int_add(json_interface_sub
, "lsReqOut",
3806 json_object_int_add(json_interface_sub
, "lsUpdIn",
3808 json_object_int_add(json_interface_sub
, "lsUpdOut",
3810 json_object_int_add(json_interface_sub
, "lsAckIn",
3812 json_object_int_add(json_interface_sub
, "lsAckOut",
3816 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n",
3817 oi
->ifp
->name
, oi
->hello_in
, oi
->hello_out
,
3818 oi
->db_desc_in
, oi
->db_desc_out
, oi
->ls_req_in
,
3819 oi
->ls_req_out
, oi
->ls_upd_in
, oi
->ls_upd_out
,
3820 oi
->ls_ack_in
, oi
->ls_ack_out
);
3824 /* OSPFv2 Packet Counters */
3825 static int show_ip_ospf_interface_traffic_common(
3826 struct vty
*vty
, struct ospf
*ospf
, char *intf_name
, json_object
*json
,
3827 int display_once
, uint8_t use_vrf
, bool use_json
)
3829 struct vrf
*vrf
= NULL
;
3830 struct interface
*ifp
= NULL
;
3831 json_object
*json_vrf
= NULL
;
3832 json_object
*json_interface_sub
= NULL
;
3834 if (!use_json
&& !display_once
) {
3836 vty_out(vty
, "%-12s%-17s%-17s%-17s%-17s%-17s\n", "Interface",
3837 " HELLO", " DB-Desc", " LS-Req", " LS-Update",
3839 vty_out(vty
, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "",
3840 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
3843 "--------------------------------------------------------------------------------------------\n");
3844 } else if (use_json
) {
3846 json_vrf
= json_object_new_object();
3851 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3853 if (intf_name
== NULL
) {
3854 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
3855 FOR_ALL_INTERFACES (vrf
, ifp
) {
3856 struct route_node
*rn
;
3857 struct ospf_interface
*oi
;
3859 if (ospf_oi_count(ifp
) == 0)
3862 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
3863 rn
= route_next(rn
)) {
3870 json_interface_sub
=
3871 json_object_new_object();
3874 show_ip_ospf_interface_traffic_sub(
3875 vty
, oi
, json_interface_sub
, use_json
);
3877 json_object_object_add(
3878 json_vrf
, ifp
->name
,
3879 json_interface_sub
);
3884 /* Interface name is specified. */
3885 ifp
= if_lookup_by_name(intf_name
,
3886 vrf_lookup_by_id(ospf
->vrf_id
));
3888 struct route_node
*rn
;
3889 struct ospf_interface
*oi
;
3891 if (ospf_oi_count(ifp
) == 0) {
3893 " OSPF not enabled on this interface %s\n",
3898 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
3899 rn
= route_next(rn
)) {
3903 json_interface_sub
=
3904 json_object_new_object();
3907 show_ip_ospf_interface_traffic_sub(
3908 vty
, oi
, json_interface_sub
, use_json
);
3910 json_object_object_add(
3911 json_vrf
, ifp
->name
,
3912 json_interface_sub
);
3920 if (ospf
->vrf_id
== VRF_DEFAULT
)
3921 json_object_object_add(json
, "default",
3924 json_object_object_add(json
, ospf
->name
,
3933 DEFUN (show_ip_ospf_interface
,
3934 show_ip_ospf_interface_cmd
,
3935 "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]",
3938 "OSPF information\n"
3941 "Interface information\n"
3946 bool uj
= use_json(argc
, argv
);
3947 struct listnode
*node
= NULL
;
3948 char *vrf_name
= NULL
, *intf_name
= NULL
;
3949 bool all_vrf
= FALSE
;
3950 int ret
= CMD_SUCCESS
;
3952 int idx_vrf
= 0, idx_intf
= 0;
3953 uint8_t use_vrf
= 0;
3954 json_object
*json
= NULL
;
3956 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
3958 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
3959 intf_name
= argv
[idx_intf
]->arg
;
3962 json
= json_object_new_object();
3964 /* vrf input is provided could be all or specific vrf*/
3968 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
3969 if (!ospf
->oi_running
)
3971 ret
= show_ip_ospf_interface_common(
3972 vty
, ospf
, intf_name
, use_vrf
, json
,
3977 vty_out(vty
, "%s\n",
3978 json_object_to_json_string_ext(
3979 json
, JSON_C_TO_STRING_PRETTY
));
3980 json_object_free(json
);
3982 vty_out(vty
, "%% OSPF instance not found\n");
3986 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
3987 if (ospf
== NULL
|| !ospf
->oi_running
) {
3989 vty_out(vty
, "%s\n",
3990 json_object_to_json_string_ext(
3991 json
, JSON_C_TO_STRING_PRETTY
));
3992 json_object_free(json
);
3994 vty_out(vty
, "%% OSPF instance not found\n");
3998 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
4002 /* Display default ospf (instance 0) info */
4003 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4004 if (ospf
== NULL
|| !ospf
->oi_running
) {
4006 vty_out(vty
, "%s\n",
4007 json_object_to_json_string_ext(
4008 json
, JSON_C_TO_STRING_PRETTY
));
4009 json_object_free(json
);
4011 vty_out(vty
, "%% OSPF instance not found\n");
4015 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
4020 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4021 json
, JSON_C_TO_STRING_PRETTY
));
4022 json_object_free(json
);
4028 DEFUN (show_ip_ospf_instance_interface
,
4029 show_ip_ospf_instance_interface_cmd
,
4030 "show ip ospf (1-65535) interface [INTERFACE] [json]",
4033 "OSPF information\n"
4035 "Interface information\n"
4042 unsigned short instance
= 0;
4043 bool uj
= use_json(argc
, argv
);
4044 char *intf_name
= NULL
;
4045 int ret
= CMD_SUCCESS
;
4046 json_object
*json
= NULL
;
4048 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4049 ospf
= ospf_lookup_instance(instance
);
4051 return CMD_NOT_MY_INSTANCE
;
4053 if (!ospf
->oi_running
)
4057 json
= json_object_new_object();
4059 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4060 intf_name
= argv
[idx_intf
]->arg
;
4062 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
, 0, json
, uj
);
4065 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4066 json
, JSON_C_TO_STRING_PRETTY
));
4067 json_object_free(json
);
4073 DEFUN (show_ip_ospf_interface_traffic
,
4074 show_ip_ospf_interface_traffic_cmd
,
4075 "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]",
4078 "OSPF information\n"
4081 "Interface information\n"
4082 "Protocol Packet counters\n"
4086 struct ospf
*ospf
= NULL
;
4087 struct listnode
*node
= NULL
;
4088 char *vrf_name
= NULL
, *intf_name
= NULL
;
4089 bool all_vrf
= FALSE
;
4091 int idx_vrf
= 0, idx_intf
= 0;
4092 bool uj
= use_json(argc
, argv
);
4093 json_object
*json
= NULL
;
4094 int ret
= CMD_SUCCESS
;
4095 int display_once
= 0;
4096 uint8_t use_vrf
= 0;
4098 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4100 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4101 intf_name
= argv
[idx_intf
]->arg
;
4104 json
= json_object_new_object();
4109 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4110 if (!ospf
->oi_running
)
4113 ret
= show_ip_ospf_interface_traffic_common(
4114 vty
, ospf
, intf_name
, json
,
4115 display_once
, use_vrf
, uj
);
4120 vty_out(vty
, "%s\n",
4121 json_object_to_json_string_ext(
4122 json
, JSON_C_TO_STRING_PRETTY
));
4123 json_object_free(json
);
4128 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4129 if (ospf
== NULL
|| !ospf
->oi_running
) {
4131 json_object_free(json
);
4135 ret
= show_ip_ospf_interface_traffic_common(
4136 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4138 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4139 if (ospf
== NULL
|| !ospf
->oi_running
) {
4141 json_object_free(json
);
4145 ret
= show_ip_ospf_interface_traffic_common(
4146 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4150 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4151 json
, JSON_C_TO_STRING_PRETTY
));
4152 json_object_free(json
);
4159 static void show_ip_ospf_neighbour_header(struct vty
*vty
)
4161 vty_out(vty
, "\n%-15s %3s %-15s %9s %-15s %-20s %5s %5s %5s\n",
4162 "Neighbor ID", "Pri", "State", "Dead Time", "Address",
4163 "Interface", "RXmtL", "RqstL", "DBsmL");
4166 static void show_ip_ospf_neighbor_sub(struct vty
*vty
,
4167 struct ospf_interface
*oi
,
4168 json_object
*json
, bool use_json
)
4170 struct route_node
*rn
;
4171 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
4173 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4174 json_object
*json_neighbor
= NULL
, *json_neigh_array
= NULL
;
4176 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
4177 if ((nbr
= rn
->info
)) {
4178 /* Do not show myself. */
4179 if (nbr
== oi
->nbr_self
)
4181 /* Down state is not shown. */
4182 if (nbr
->state
== NSM_Down
)
4185 char neigh_str
[INET_ADDRSTRLEN
];
4188 && !IPV4_ADDR_SAME(&prev_nbr
->src
,
4190 /* Start new neigh list */
4191 json_neigh_array
= NULL
;
4194 if (nbr
->state
== NSM_Attempt
4195 && nbr
->router_id
.s_addr
== 0)
4196 strlcpy(neigh_str
, "neighbor",
4200 inet_ntoa(nbr
->router_id
),
4203 json_object_object_get_ex(json
, neigh_str
,
4206 if (!json_neigh_array
) {
4208 json_object_new_array();
4209 json_object_object_add(
4214 json_neighbor
= json_object_new_object();
4216 ospf_nbr_state_message(nbr
, msgbuf
, 16);
4222 &nbr
->t_inactivity
->u
.sands
,
4226 json_object_int_add(json_neighbor
, "priority",
4228 json_object_string_add(json_neighbor
, "state",
4230 json_object_int_add(json_neighbor
,
4233 json_object_string_add(json_neighbor
, "address",
4234 inet_ntoa(nbr
->src
));
4235 json_object_string_add(json_neighbor
,
4238 json_object_int_add(
4239 json_neighbor
, "retransmitCounter",
4240 ospf_ls_retransmit_count(nbr
));
4241 json_object_int_add(json_neighbor
,
4243 ospf_ls_request_count(nbr
));
4244 json_object_int_add(json_neighbor
,
4246 ospf_db_summary_count(nbr
));
4248 json_object_array_add(json_neigh_array
,
4251 ospf_nbr_state_message(nbr
, msgbuf
, 16);
4253 if (nbr
->state
== NSM_Attempt
4254 && nbr
->router_id
.s_addr
== 0)
4255 vty_out(vty
, "%-15s %3d %-15s ", "-",
4256 nbr
->priority
, msgbuf
);
4258 vty_out(vty
, "%-15s %3d %-15s ",
4259 inet_ntoa(nbr
->router_id
),
4260 nbr
->priority
, msgbuf
);
4262 vty_out(vty
, "%9s ",
4263 ospf_timer_dump(nbr
->t_inactivity
,
4266 vty_out(vty
, "%-15s ", inet_ntoa(nbr
->src
));
4267 vty_out(vty
, "%-20s %5ld %5ld %5d\n",
4269 ospf_ls_retransmit_count(nbr
),
4270 ospf_ls_request_count(nbr
),
4271 ospf_db_summary_count(nbr
));
4278 static int show_ip_ospf_neighbor_common(struct vty
*vty
, struct ospf
*ospf
,
4279 json_object
*json
, bool use_json
,
4282 struct ospf_interface
*oi
;
4283 struct listnode
*node
;
4284 json_object
*json_vrf
= NULL
;
4285 json_object
*json_nbr_sub
= NULL
;
4289 json_vrf
= json_object_new_object();
4292 json_nbr_sub
= json_object_new_object();
4295 if (ospf
->instance
) {
4297 json_object_int_add(json
, "ospfInstance",
4300 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4303 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4305 show_ip_ospf_neighbour_header(vty
);
4307 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4308 if (ospf_interface_neighbor_count(oi
) == 0)
4310 show_ip_ospf_neighbor_sub(vty
, oi
, json_nbr_sub
, use_json
);
4314 json_object_object_add(json_vrf
, "neighbors", json_nbr_sub
);
4316 if (ospf
->vrf_id
== VRF_DEFAULT
)
4317 json_object_object_add(json
, "default",
4320 json_object_object_add(json
, ospf
->name
,
4329 DEFUN (show_ip_ospf_neighbor
,
4330 show_ip_ospf_neighbor_cmd
,
4331 "show ip ospf [vrf <NAME|all>] neighbor [json]",
4334 "OSPF information\n"
4341 bool uj
= use_json(argc
, argv
);
4342 struct listnode
*node
= NULL
;
4343 char *vrf_name
= NULL
;
4344 bool all_vrf
= FALSE
;
4345 int ret
= CMD_SUCCESS
;
4348 uint8_t use_vrf
= 0;
4349 json_object
*json
= NULL
;
4351 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4354 json
= json_object_new_object();
4356 /* vrf input is provided could be all or specific vrf*/
4360 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4361 if (!ospf
->oi_running
)
4363 ret
= show_ip_ospf_neighbor_common(
4364 vty
, ospf
, json
, uj
, use_vrf
);
4368 vty_out(vty
, "%s\n",
4369 json_object_to_json_string_ext(
4370 json
, JSON_C_TO_STRING_PRETTY
));
4371 json_object_free(json
);
4373 vty_out(vty
, "OSPF instance not found\n");
4378 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4379 if (ospf
== NULL
|| !ospf
->oi_running
) {
4381 vty_out(vty
, "%s\n",
4382 json_object_to_json_string_ext(
4383 json
, JSON_C_TO_STRING_PRETTY
));
4384 json_object_free(json
);
4386 vty_out(vty
, "%% OSPF instance not found\n");
4391 /* Display default ospf (instance 0) info */
4392 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4393 if (ospf
== NULL
|| !ospf
->oi_running
) {
4395 vty_out(vty
, "%s\n",
4396 json_object_to_json_string_ext(
4397 json
, JSON_C_TO_STRING_PRETTY
));
4398 json_object_free(json
);
4400 vty_out(vty
, "%% OSPF instance not found\n");
4407 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
,
4411 vty_out(vty
, "%s\n",
4412 json_object_to_json_string_ext(
4413 json
, JSON_C_TO_STRING_PRETTY
));
4418 json_object_free(json
);
4424 DEFUN (show_ip_ospf_instance_neighbor
,
4425 show_ip_ospf_instance_neighbor_cmd
,
4426 "show ip ospf (1-65535) neighbor [json]",
4429 "OSPF information\n"
4436 unsigned short instance
= 0;
4437 bool uj
= use_json(argc
, argv
);
4438 json_object
*json
= NULL
;
4439 int ret
= CMD_SUCCESS
;
4441 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4442 ospf
= ospf_lookup_instance(instance
);
4444 return CMD_NOT_MY_INSTANCE
;
4446 if (!ospf
->oi_running
)
4450 json
= json_object_new_object();
4452 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
, 0);
4455 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4456 json
, JSON_C_TO_STRING_PRETTY
));
4457 json_object_free(json
);
4463 static int show_ip_ospf_neighbor_all_common(struct vty
*vty
, struct ospf
*ospf
,
4464 json_object
*json
, bool use_json
,
4467 struct listnode
*node
;
4468 struct ospf_interface
*oi
;
4469 json_object
*json_vrf
= NULL
;
4470 json_object
*json_neighbor_sub
= NULL
;
4474 json_vrf
= json_object_new_object();
4477 json_neighbor_sub
= json_object_new_object();
4480 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4482 show_ip_ospf_neighbour_header(vty
);
4484 if (ospf
->instance
) {
4486 json_object_int_add(json_vrf
, "ospfInstance",
4489 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4492 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4493 struct listnode
*nbr_node
;
4494 struct ospf_nbr_nbma
*nbr_nbma
;
4496 show_ip_ospf_neighbor_sub(vty
, oi
, json_vrf
, use_json
);
4498 /* print Down neighbor status */
4499 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nbr_node
, nbr_nbma
)) {
4500 if (nbr_nbma
->nbr
== NULL
4501 || nbr_nbma
->nbr
->state
== NSM_Down
) {
4503 json_object_int_add(json_neighbor_sub
,
4505 nbr_nbma
->priority
);
4506 json_object_boolean_true_add(
4509 json_object_string_add(
4513 json_object_int_add(
4515 "nbrNbmaRetransmitCounter", 0);
4516 json_object_int_add(
4518 "nbrNbmaRequestCounter", 0);
4519 json_object_int_add(
4521 "nbrNbmaDbSummaryCounter", 0);
4522 json_object_object_add(
4524 inet_ntoa(nbr_nbma
->addr
),
4527 vty_out(vty
, "%-15s %3d %-15s %9s ",
4528 "-", nbr_nbma
->priority
, "Down",
4531 "%-15s %-20s %5d %5d %5d\n",
4532 inet_ntoa(nbr_nbma
->addr
),
4533 IF_NAME(oi
), 0, 0, 0);
4541 if (ospf
->vrf_id
== VRF_DEFAULT
)
4542 json_object_object_add(json
, "default",
4545 json_object_object_add(json
, ospf
->name
,
4554 DEFUN (show_ip_ospf_neighbor_all
,
4555 show_ip_ospf_neighbor_all_cmd
,
4556 "show ip ospf [vrf <NAME|all>] neighbor all [json]",
4559 "OSPF information\n"
4563 "include down status neighbor\n"
4567 bool uj
= use_json(argc
, argv
);
4568 struct listnode
*node
= NULL
;
4569 char *vrf_name
= NULL
;
4570 bool all_vrf
= FALSE
;
4571 int ret
= CMD_SUCCESS
;
4574 uint8_t use_vrf
= 0;
4575 json_object
*json
= NULL
;
4577 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4580 json
= json_object_new_object();
4582 /* vrf input is provided could be all or specific vrf*/
4586 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4587 if (!ospf
->oi_running
)
4589 ret
= show_ip_ospf_neighbor_all_common(
4590 vty
, ospf
, json
, uj
, use_vrf
);
4594 vty_out(vty
, "%s\n",
4595 json_object_to_json_string_ext(
4596 json
, JSON_C_TO_STRING_PRETTY
));
4597 json_object_free(json
);
4603 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4604 if (ospf
== NULL
|| !ospf
->oi_running
) {
4606 json_object_free(json
);
4610 /* Display default ospf (instance 0) info */
4611 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4612 if (ospf
== NULL
|| !ospf
->oi_running
) {
4614 json_object_free(json
);
4620 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
,
4623 vty_out(vty
, "%s\n",
4624 json_object_to_json_string_ext(
4625 json
, JSON_C_TO_STRING_PRETTY
));
4630 json_object_free(json
);
4635 DEFUN (show_ip_ospf_instance_neighbor_all
,
4636 show_ip_ospf_instance_neighbor_all_cmd
,
4637 "show ip ospf (1-65535) neighbor all [json]",
4640 "OSPF information\n"
4643 "include down status neighbor\n"
4648 unsigned short instance
= 0;
4649 bool uj
= use_json(argc
, argv
);
4650 json_object
*json
= NULL
;
4651 int ret
= CMD_SUCCESS
;
4653 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4654 ospf
= ospf_lookup_instance(instance
);
4656 return CMD_NOT_MY_INSTANCE
;
4658 if (!ospf
->oi_running
)
4661 json
= json_object_new_object();
4663 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
, 0);
4666 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4667 json
, JSON_C_TO_STRING_PRETTY
));
4668 json_object_free(json
);
4674 static int show_ip_ospf_neighbor_int_common(struct vty
*vty
, struct ospf
*ospf
,
4676 struct cmd_token
**argv
,
4677 bool use_json
, uint8_t use_vrf
)
4679 struct interface
*ifp
;
4680 struct route_node
*rn
;
4681 json_object
*json
= NULL
;
4684 json
= json_object_new_object();
4686 if (ospf
->instance
) {
4688 json_object_int_add(json
, "ospfInstance",
4691 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4694 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
4696 ifp
= if_lookup_by_name(argv
[arg_base
]->arg
,
4697 vrf_lookup_by_id(ospf
->vrf_id
));
4700 json_object_boolean_true_add(json
, "noSuchIface");
4702 vty_out(vty
, "No such interface.\n");
4706 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
4707 struct ospf_interface
*oi
= rn
->info
;
4712 show_ip_ospf_neighbor_sub(vty
, oi
, json
, use_json
);
4716 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4717 json
, JSON_C_TO_STRING_PRETTY
));
4718 json_object_free(json
);
4725 DEFUN (show_ip_ospf_neighbor_int
,
4726 show_ip_ospf_neighbor_int_cmd
,
4727 "show ip ospf [vrf <NAME>] neighbor IFNAME [json]",
4730 "OSPF information\n"
4739 bool uj
= use_json(argc
, argv
);
4740 int ret
= CMD_SUCCESS
;
4741 struct interface
*ifp
= NULL
;
4742 char *vrf_name
= NULL
;
4743 vrf_id_t vrf_id
= VRF_DEFAULT
;
4744 struct vrf
*vrf
= NULL
;
4746 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
4747 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
4748 if (vrf_name
&& strmatch(vrf_name
, VRF_DEFAULT_NAME
))
4751 vrf
= vrf_lookup_by_name(vrf_name
);
4753 vrf_id
= vrf
->vrf_id
;
4755 ospf
= ospf_lookup_by_vrf_id(vrf_id
);
4757 if (!ospf
|| !ospf
->oi_running
)
4761 show_ip_ospf_neighbour_header(vty
);
4763 argv_find(argv
, argc
, "IFNAME", &idx_ifname
);
4765 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
,
4766 vrf_lookup_by_id(vrf_id
));
4770 ret
= show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
,
4775 DEFUN (show_ip_ospf_instance_neighbor_int
,
4776 show_ip_ospf_instance_neighbor_int_cmd
,
4777 "show ip ospf (1-65535) neighbor IFNAME [json]",
4780 "OSPF information\n"
4789 unsigned short instance
= 0;
4790 bool uj
= use_json(argc
, argv
);
4793 show_ip_ospf_neighbour_header(vty
);
4795 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4796 ospf
= ospf_lookup_instance(instance
);
4798 return CMD_NOT_MY_INSTANCE
;
4800 if (!ospf
->oi_running
)
4804 show_ip_ospf_neighbour_header(vty
);
4806 return show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
, argv
, uj
,
4810 static void show_ip_ospf_nbr_nbma_detail_sub(struct vty
*vty
,
4811 struct ospf_interface
*oi
,
4812 struct ospf_nbr_nbma
*nbr_nbma
,
4813 bool use_json
, json_object
*json
)
4815 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4816 json_object
*json_sub
= NULL
;
4819 json_sub
= json_object_new_object();
4820 else /* Show neighbor ID. */
4821 vty_out(vty
, " Neighbor %s,", "-");
4823 /* Show interface address. */
4825 json_object_string_add(json_sub
, "ifaceAddress",
4826 inet_ntoa(nbr_nbma
->addr
));
4828 vty_out(vty
, " interface address %s\n",
4829 inet_ntoa(nbr_nbma
->addr
));
4833 json_object_string_add(json_sub
, "areaId",
4834 ospf_area_desc_string(oi
->area
));
4835 json_object_string_add(json_sub
, "iface", IF_NAME(oi
));
4837 vty_out(vty
, " In the area %s via interface %s\n",
4838 ospf_area_desc_string(oi
->area
), IF_NAME(oi
));
4840 /* Show neighbor priority and state. */
4842 json_object_int_add(json_sub
, "nbrPriority",
4843 nbr_nbma
->priority
);
4844 json_object_string_add(json_sub
, "nbrState", "down");
4846 vty_out(vty
, " Neighbor priority is %d, State is %s,",
4847 nbr_nbma
->priority
, "Down");
4849 /* Show state changes. */
4851 json_object_int_add(json_sub
, "stateChangeCounter",
4852 nbr_nbma
->state_change
);
4854 vty_out(vty
, " %d state changes\n", nbr_nbma
->state_change
);
4856 /* Show PollInterval */
4858 json_object_int_add(json_sub
, "pollInterval", nbr_nbma
->v_poll
);
4860 vty_out(vty
, " Poll interval %d\n", nbr_nbma
->v_poll
);
4862 /* Show poll-interval timer. */
4863 if (nbr_nbma
->t_poll
) {
4866 time_store
= monotime_until(&nbr_nbma
->t_poll
->u
.sands
,
4868 json_object_int_add(json_sub
,
4869 "pollIntervalTimerDueMsec",
4872 vty_out(vty
, " Poll timer due in %s\n",
4873 ospf_timer_dump(nbr_nbma
->t_poll
, timebuf
,
4877 /* Show poll-interval timer thread. */
4879 if (nbr_nbma
->t_poll
!= NULL
)
4880 json_object_string_add(json_sub
,
4881 "pollIntervalTimerThread", "on");
4883 vty_out(vty
, " Thread Poll Timer %s\n",
4884 nbr_nbma
->t_poll
!= NULL
? "on" : "off");
4887 json_object_object_add(json
, "noNbrId", json_sub
);
4890 static void show_ip_ospf_neighbor_detail_sub(struct vty
*vty
,
4891 struct ospf_interface
*oi
,
4892 struct ospf_neighbor
*nbr
,
4893 json_object
*json
, bool use_json
)
4895 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4896 json_object
*json_sub
= NULL
;
4899 json_sub
= json_object_new_object();
4901 /* Show neighbor ID. */
4902 if (nbr
->state
== NSM_Attempt
&& nbr
->router_id
.s_addr
== 0)
4903 vty_out(vty
, " Neighbor %s,", "-");
4905 vty_out(vty
, " Neighbor %s,",
4906 inet_ntoa(nbr
->router_id
));
4909 /* Show interface address. */
4911 json_object_string_add(json_sub
, "ifaceAddress",
4912 inet_ntoa(nbr
->address
.u
.prefix4
));
4914 vty_out(vty
, " interface address %s\n",
4915 inet_ntoa(nbr
->address
.u
.prefix4
));
4919 json_object_string_add(json_sub
, "areaId",
4920 ospf_area_desc_string(oi
->area
));
4921 json_object_string_add(json_sub
, "ifaceName", oi
->ifp
->name
);
4923 vty_out(vty
, " In the area %s via interface %s\n",
4924 ospf_area_desc_string(oi
->area
), oi
->ifp
->name
);
4926 /* Show neighbor priority and state. */
4928 json_object_int_add(json_sub
, "nbrPriority", nbr
->priority
);
4929 json_object_string_add(
4930 json_sub
, "nbrState",
4931 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
4933 vty_out(vty
, " Neighbor priority is %d, State is %s,",
4935 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
4937 /* Show state changes. */
4939 json_object_int_add(json_sub
, "stateChangeCounter",
4942 vty_out(vty
, " %d state changes\n", nbr
->state_change
);
4944 if (nbr
->ts_last_progress
.tv_sec
|| nbr
->ts_last_progress
.tv_usec
) {
4949 monotime_since(&nbr
->ts_last_progress
, &res
) / 1000LL;
4951 json_object_int_add(json_sub
, "lastPrgrsvChangeMsec",
4955 " Most recent state change statistics:\n");
4956 vty_out(vty
, " Progressive change %s ago\n",
4957 ospf_timeval_dump(&res
, timebuf
,
4962 if (nbr
->ts_last_regress
.tv_sec
|| nbr
->ts_last_regress
.tv_usec
) {
4967 monotime_since(&nbr
->ts_last_regress
, &res
) / 1000LL;
4969 json_object_int_add(json_sub
,
4970 "lastRegressiveChangeMsec",
4972 if (nbr
->last_regress_str
)
4973 json_object_string_add(
4974 json_sub
, "lastRegressiveChangeReason",
4975 nbr
->last_regress_str
);
4978 " Regressive change %s ago, due to %s\n",
4979 ospf_timeval_dump(&res
, timebuf
,
4981 (nbr
->last_regress_str
? nbr
->last_regress_str
4986 /* Show Designated Rotuer ID. */
4988 json_object_string_add(json_sub
, "routerDesignatedId",
4989 inet_ntoa(nbr
->d_router
));
4991 vty_out(vty
, " DR is %s,", inet_ntoa(nbr
->d_router
));
4993 /* Show Backup Designated Rotuer ID. */
4995 json_object_string_add(json_sub
, "routerDesignatedBackupId",
4996 inet_ntoa(nbr
->bd_router
));
4998 vty_out(vty
, " BDR is %s\n", inet_ntoa(nbr
->bd_router
));
5002 json_object_int_add(json_sub
, "optionsCounter", nbr
->options
);
5003 json_object_string_add(json_sub
, "optionsList",
5004 ospf_options_dump(nbr
->options
));
5006 vty_out(vty
, " Options %d %s\n", nbr
->options
,
5007 ospf_options_dump(nbr
->options
));
5009 /* Show Router Dead interval timer. */
5011 if (nbr
->t_inactivity
) {
5013 time_store
= monotime_until(&nbr
->t_inactivity
->u
.sands
,
5016 json_object_int_add(json_sub
,
5017 "routerDeadIntervalTimerDueMsec",
5020 json_object_int_add(
5021 json_sub
, "routerDeadIntervalTimerDueMsec", -1);
5023 vty_out(vty
, " Dead timer due in %s\n",
5024 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
5027 /* Show Database Summary list. */
5029 json_object_int_add(json_sub
, "databaseSummaryListCounter",
5030 ospf_db_summary_count(nbr
));
5032 vty_out(vty
, " Database Summary List %d\n",
5033 ospf_db_summary_count(nbr
));
5035 /* Show Link State Request list. */
5037 json_object_int_add(json_sub
, "linkStateRequestListCounter",
5038 ospf_ls_request_count(nbr
));
5040 vty_out(vty
, " Link State Request List %ld\n",
5041 ospf_ls_request_count(nbr
));
5043 /* Show Link State Retransmission list. */
5045 json_object_int_add(json_sub
,
5046 "linkStateRetransmissionListCounter",
5047 ospf_ls_retransmit_count(nbr
));
5049 vty_out(vty
, " Link State Retransmission List %ld\n",
5050 ospf_ls_retransmit_count(nbr
));
5052 /* Show inactivity timer thread. */
5054 if (nbr
->t_inactivity
!= NULL
)
5055 json_object_string_add(json_sub
,
5056 "threadInactivityTimer", "on");
5058 vty_out(vty
, " Thread Inactivity Timer %s\n",
5059 nbr
->t_inactivity
!= NULL
? "on" : "off");
5061 /* Show Database Description retransmission thread. */
5063 if (nbr
->t_db_desc
!= NULL
)
5064 json_object_string_add(
5066 "threadDatabaseDescriptionRetransmission",
5070 " Thread Database Description Retransmision %s\n",
5071 nbr
->t_db_desc
!= NULL
? "on" : "off");
5073 /* Show Link State Request Retransmission thread. */
5075 if (nbr
->t_ls_req
!= NULL
)
5076 json_object_string_add(
5078 "threadLinkStateRequestRetransmission", "on");
5081 " Thread Link State Request Retransmission %s\n",
5082 nbr
->t_ls_req
!= NULL
? "on" : "off");
5084 /* Show Link State Update Retransmission thread. */
5086 if (nbr
->t_ls_upd
!= NULL
)
5087 json_object_string_add(
5088 json_sub
, "threadLinkStateUpdateRetransmission",
5092 " Thread Link State Update Retransmission %s\n\n",
5093 nbr
->t_ls_upd
!= NULL
? "on" : "off");
5096 if (nbr
->state
== NSM_Attempt
&& nbr
->router_id
.s_addr
== 0)
5097 json_object_object_add(json
, "noNbrId", json_sub
);
5099 json_object_object_add(json
, inet_ntoa(nbr
->router_id
),
5103 ospf_bfd_show_info(vty
, nbr
->bfd_info
, json
, use_json
, 0);
5106 static int show_ip_ospf_neighbor_id_common(struct vty
*vty
, struct ospf
*ospf
,
5107 struct in_addr
*router_id
,
5108 bool use_json
, uint8_t use_vrf
)
5110 struct listnode
*node
;
5111 struct ospf_neighbor
*nbr
;
5112 struct ospf_interface
*oi
;
5113 json_object
*json
= NULL
;
5116 json
= json_object_new_object();
5118 if (ospf
->instance
) {
5120 json_object_int_add(json
, "ospfInstance",
5123 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5126 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
5128 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5129 if ((nbr
= ospf_nbr_lookup_by_routerid(oi
->nbrs
, router_id
))) {
5130 show_ip_ospf_neighbor_detail_sub(vty
, oi
, nbr
, json
,
5136 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5137 json
, JSON_C_TO_STRING_PRETTY
));
5138 json_object_free(json
);
5145 DEFPY (show_ip_ospf_neighbor_id
,
5146 show_ip_ospf_neighbor_id_cmd
,
5147 "show ip ospf neighbor A.B.C.D$router_id [json$json]",
5150 "OSPF information\n"
5156 struct listnode
*node
;
5157 int ret
= CMD_SUCCESS
;
5159 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5160 if (!ospf
->oi_running
)
5162 ret
= show_ip_ospf_neighbor_id_common(vty
, ospf
, &router_id
,
5169 DEFPY (show_ip_ospf_instance_neighbor_id
,
5170 show_ip_ospf_instance_neighbor_id_cmd
,
5171 "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [json$json]",
5174 "OSPF information\n"
5182 ospf
= ospf_lookup_instance(instance
);
5184 return CMD_NOT_MY_INSTANCE
;
5186 if (!ospf
->oi_running
)
5189 return show_ip_ospf_neighbor_id_common(vty
, ospf
, &router_id
, !!json
,
5193 static int show_ip_ospf_neighbor_detail_common(struct vty
*vty
,
5195 json_object
*json
, bool use_json
,
5198 struct ospf_interface
*oi
;
5199 struct listnode
*node
;
5200 json_object
*json_vrf
= NULL
;
5204 json_vrf
= json_object_new_object();
5208 if (ospf
->instance
) {
5210 json_object_int_add(json_vrf
, "ospfInstance",
5213 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5216 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5218 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5219 struct route_node
*rn
;
5220 struct ospf_neighbor
*nbr
;
5222 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5223 if ((nbr
= rn
->info
)) {
5224 if (nbr
!= oi
->nbr_self
) {
5225 if (nbr
->state
!= NSM_Down
) {
5226 show_ip_ospf_neighbor_detail_sub(
5227 vty
, oi
, nbr
, json_vrf
,
5237 if (ospf
->vrf_id
== VRF_DEFAULT
)
5238 json_object_object_add(json
, "default",
5241 json_object_object_add(json
, ospf
->name
,
5250 DEFUN (show_ip_ospf_neighbor_detail
,
5251 show_ip_ospf_neighbor_detail_cmd
,
5252 "show ip ospf [vrf <NAME|all>] neighbor detail [json]",
5255 "OSPF information\n"
5259 "detail of all neighbors\n"
5263 bool uj
= use_json(argc
, argv
);
5264 struct listnode
*node
= NULL
;
5265 char *vrf_name
= NULL
;
5266 bool all_vrf
= FALSE
;
5267 int ret
= CMD_SUCCESS
;
5270 uint8_t use_vrf
= 0;
5271 json_object
*json
= NULL
;
5273 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5276 json
= json_object_new_object();
5278 /* vrf input is provided could be all or specific vrf*/
5282 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5283 if (!ospf
->oi_running
)
5285 ret
= show_ip_ospf_neighbor_detail_common(
5286 vty
, ospf
, json
, uj
, use_vrf
);
5289 vty_out(vty
, "%s\n",
5290 json_object_to_json_string_ext(
5291 json
, JSON_C_TO_STRING_PRETTY
));
5292 json_object_free(json
);
5297 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5298 if (ospf
== NULL
|| !ospf
->oi_running
) {
5300 json_object_free(json
);
5304 /* Display default ospf (instance 0) info */
5305 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5306 if (ospf
== NULL
|| !ospf
->oi_running
) {
5308 json_object_free(json
);
5314 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
,
5317 vty_out(vty
, "%s\n",
5318 json_object_to_json_string_ext(
5319 json
, JSON_C_TO_STRING_PRETTY
));
5324 json_object_free(json
);
5329 DEFUN (show_ip_ospf_instance_neighbor_detail
,
5330 show_ip_ospf_instance_neighbor_detail_cmd
,
5331 "show ip ospf (1-65535) neighbor detail [json]",
5334 "OSPF information\n"
5337 "detail of all neighbors\n"
5342 unsigned short instance
= 0;
5343 bool uj
= use_json(argc
, argv
);
5344 json_object
*json
= NULL
;
5345 int ret
= CMD_SUCCESS
;
5347 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5348 ospf
= ospf_lookup_instance(instance
);
5350 return CMD_NOT_MY_INSTANCE
;
5352 if (!ospf
->oi_running
)
5356 json
= json_object_new_object();
5358 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
, 0);
5361 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5362 json
, JSON_C_TO_STRING_PRETTY
));
5363 json_object_free(json
);
5369 static int show_ip_ospf_neighbor_detail_all_common(struct vty
*vty
,
5375 struct listnode
*node
;
5376 struct ospf_interface
*oi
;
5377 json_object
*json_vrf
= NULL
;
5381 json_vrf
= json_object_new_object();
5386 if (ospf
->instance
) {
5388 json_object_int_add(json
, "ospfInstance",
5391 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5394 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5396 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5397 struct route_node
*rn
;
5398 struct ospf_neighbor
*nbr
;
5399 struct ospf_nbr_nbma
*nbr_nbma
;
5401 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
5402 if ((nbr
= rn
->info
))
5403 if (nbr
!= oi
->nbr_self
)
5404 if (nbr
->state
!= NSM_Down
)
5405 show_ip_ospf_neighbor_detail_sub(
5407 json_vrf
, use_json
);
5409 if (oi
->type
== OSPF_IFTYPE_NBMA
) {
5410 struct listnode
*nd
;
5412 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nd
, nbr_nbma
)) {
5413 if (nbr_nbma
->nbr
== NULL
5414 || nbr_nbma
->nbr
->state
== NSM_Down
)
5415 show_ip_ospf_nbr_nbma_detail_sub(
5416 vty
, oi
, nbr_nbma
, use_json
,
5424 if (ospf
->vrf_id
== VRF_DEFAULT
)
5425 json_object_object_add(json
, "default",
5428 json_object_object_add(json
, ospf
->name
,
5438 DEFUN (show_ip_ospf_neighbor_detail_all
,
5439 show_ip_ospf_neighbor_detail_all_cmd
,
5440 "show ip ospf [vrf <NAME|all>] neighbor detail all [json]",
5443 "OSPF information\n"
5447 "detail of all neighbors\n"
5448 "include down status neighbor\n"
5452 bool uj
= use_json(argc
, argv
);
5453 struct listnode
*node
= NULL
;
5454 char *vrf_name
= NULL
;
5455 bool all_vrf
= FALSE
;
5456 int ret
= CMD_SUCCESS
;
5459 uint8_t use_vrf
= 0;
5460 json_object
*json
= NULL
;
5462 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5465 json
= json_object_new_object();
5467 /* vrf input is provided could be all or specific vrf*/
5471 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5472 if (!ospf
->oi_running
)
5474 ret
= show_ip_ospf_neighbor_detail_all_common(
5475 vty
, ospf
, json
, uj
, use_vrf
);
5479 vty_out(vty
, "%s\n",
5480 json_object_to_json_string_ext(
5481 json
, JSON_C_TO_STRING_PRETTY
));
5482 json_object_free(json
);
5487 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5488 if (ospf
== NULL
|| !ospf
->oi_running
) {
5490 json_object_free(json
);
5494 /* Display default ospf (instance 0) info */
5495 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5496 if (ospf
== NULL
|| !ospf
->oi_running
) {
5498 json_object_free(json
);
5504 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
,
5507 vty_out(vty
, "%s\n",
5508 json_object_to_json_string_ext(
5509 json
, JSON_C_TO_STRING_PRETTY
));
5514 json_object_free(json
);
5519 DEFUN (show_ip_ospf_instance_neighbor_detail_all
,
5520 show_ip_ospf_instance_neighbor_detail_all_cmd
,
5521 "show ip ospf (1-65535) neighbor detail all [json]",
5524 "OSPF information\n"
5527 "detail of all neighbors\n"
5528 "include down status neighbor\n"
5533 unsigned short instance
= 0;
5534 bool uj
= use_json(argc
, argv
);
5535 json_object
*json
= NULL
;
5536 int ret
= CMD_SUCCESS
;
5538 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5539 ospf
= ospf_lookup_instance(instance
);
5541 return CMD_NOT_MY_INSTANCE
;
5543 if (!ospf
->oi_running
)
5547 json
= json_object_new_object();
5549 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
, uj
, 0);
5552 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5553 json
, JSON_C_TO_STRING_PRETTY
));
5554 json_object_free(json
);
5560 static int show_ip_ospf_neighbor_int_detail_common(struct vty
*vty
,
5563 struct cmd_token
**argv
,
5566 struct ospf_interface
*oi
;
5567 struct interface
*ifp
;
5568 struct route_node
*rn
, *nrn
;
5569 struct ospf_neighbor
*nbr
;
5570 json_object
*json
= NULL
;
5573 json
= json_object_new_object();
5575 if (ospf
->instance
) {
5577 json_object_int_add(json
, "ospfInstance",
5580 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5583 ifp
= if_lookup_by_name(argv
[arg_base
]->arg
,
5584 vrf_lookup_by_id(ospf
->vrf_id
));
5587 vty_out(vty
, "No such interface.\n");
5589 vty_out(vty
, "{}\n");
5590 json_object_free(json
);
5595 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
5596 if ((oi
= rn
->info
)) {
5597 for (nrn
= route_top(oi
->nbrs
); nrn
;
5598 nrn
= route_next(nrn
)) {
5599 if ((nbr
= nrn
->info
)) {
5600 if (nbr
!= oi
->nbr_self
) {
5601 if (nbr
->state
!= NSM_Down
)
5602 show_ip_ospf_neighbor_detail_sub(
5612 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5613 json
, JSON_C_TO_STRING_PRETTY
));
5614 json_object_free(json
);
5621 DEFUN (show_ip_ospf_neighbor_int_detail
,
5622 show_ip_ospf_neighbor_int_detail_cmd
,
5623 "show ip ospf neighbor IFNAME detail [json]",
5626 "OSPF information\n"
5629 "detail of all neighbors\n"
5633 bool uj
= use_json(argc
, argv
);
5634 struct listnode
*node
= NULL
;
5635 int ret
= CMD_SUCCESS
;
5636 bool ospf_output
= FALSE
;
5638 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5639 if (!ospf
->oi_running
)
5642 ret
= show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, 0,
5647 vty_out(vty
, "%% OSPF instance not found\n");
5652 DEFUN (show_ip_ospf_instance_neighbor_int_detail
,
5653 show_ip_ospf_instance_neighbor_int_detail_cmd
,
5654 "show ip ospf (1-65535) neighbor IFNAME detail [json]",
5657 "OSPF information\n"
5661 "detail of all neighbors\n"
5667 unsigned short instance
= 0;
5668 bool uj
= use_json(argc
, argv
);
5670 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5671 ospf
= ospf_lookup_instance(instance
);
5673 return CMD_NOT_MY_INSTANCE
;
5675 if (!ospf
->oi_running
)
5678 return show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, idx_ifname
,
5682 /* Show functions */
5683 static int show_lsa_summary(struct vty
*vty
, struct ospf_lsa
*lsa
, int self
)
5685 struct router_lsa
*rl
;
5686 struct summary_lsa
*sl
;
5687 struct as_external_lsa
*asel
;
5688 struct prefix_ipv4 p
;
5691 /* If self option is set, check LSA self flag. */
5692 if (self
== 0 || IS_LSA_SELF(lsa
)) {
5693 /* LSA common part show. */
5694 vty_out(vty
, "%-15s ", inet_ntoa(lsa
->data
->id
));
5695 vty_out(vty
, "%-15s %4d 0x%08lx 0x%04x",
5696 inet_ntoa(lsa
->data
->adv_router
), LS_AGE(lsa
),
5697 (unsigned long)ntohl(lsa
->data
->ls_seqnum
),
5698 ntohs(lsa
->data
->checksum
));
5699 /* LSA specific part show. */
5700 switch (lsa
->data
->type
) {
5701 case OSPF_ROUTER_LSA
:
5702 rl
= (struct router_lsa
*)lsa
->data
;
5703 vty_out(vty
, " %-d", ntohs(rl
->links
));
5705 case OSPF_SUMMARY_LSA
:
5706 sl
= (struct summary_lsa
*)lsa
->data
;
5709 p
.prefix
= sl
->header
.id
;
5710 p
.prefixlen
= ip_masklen(sl
->mask
);
5711 apply_mask_ipv4(&p
);
5713 vty_out(vty
, " %s/%d", inet_ntoa(p
.prefix
),
5716 case OSPF_AS_EXTERNAL_LSA
:
5717 case OSPF_AS_NSSA_LSA
:
5718 asel
= (struct as_external_lsa
*)lsa
->data
;
5721 p
.prefix
= asel
->header
.id
;
5722 p
.prefixlen
= ip_masklen(asel
->mask
);
5723 apply_mask_ipv4(&p
);
5725 vty_out(vty
, " %s %s/%d [0x%lx]",
5726 IS_EXTERNAL_METRIC(asel
->e
[0].tos
)
5729 inet_ntoa(p
.prefix
), p
.prefixlen
,
5730 (unsigned long)ntohl(
5731 asel
->e
[0].route_tag
));
5733 case OSPF_NETWORK_LSA
:
5734 case OSPF_ASBR_SUMMARY_LSA
:
5735 case OSPF_OPAQUE_LINK_LSA
:
5736 case OSPF_OPAQUE_AREA_LSA
:
5737 case OSPF_OPAQUE_AS_LSA
:
5747 static const char *show_database_desc
[] = {
5749 "Router Link States",
5751 "Summary Link States",
5752 "ASBR-Summary Link States",
5753 "AS External Link States",
5754 "Group Membership LSA",
5755 "NSSA-external Link States",
5757 "Link-Local Opaque-LSA",
5758 "Area-Local Opaque-LSA",
5759 "AS-external Opaque-LSA",
5762 static const char *show_database_header
[] = {
5764 "Link ID ADV Router Age Seq# CkSum Link count",
5765 "Link ID ADV Router Age Seq# CkSum",
5766 "Link ID ADV Router Age Seq# CkSum Route",
5767 "Link ID ADV Router Age Seq# CkSum",
5768 "Link ID ADV Router Age Seq# CkSum Route",
5769 " --- header for Group Member ----",
5770 "Link ID ADV Router Age Seq# CkSum Route",
5772 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5773 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5774 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5777 static void show_ip_ospf_database_header(struct vty
*vty
, struct ospf_lsa
*lsa
)
5779 struct router_lsa
*rlsa
= (struct router_lsa
*)lsa
->data
;
5781 vty_out(vty
, " LS age: %d\n", LS_AGE(lsa
));
5782 vty_out(vty
, " Options: 0x%-2x : %s\n", lsa
->data
->options
,
5783 ospf_options_dump(lsa
->data
->options
));
5784 vty_out(vty
, " LS Flags: 0x%-2x %s\n", lsa
->flags
,
5785 ((lsa
->flags
& OSPF_LSA_LOCAL_XLT
) ? "(Translated from Type-7)"
5788 if (lsa
->data
->type
== OSPF_ROUTER_LSA
) {
5789 vty_out(vty
, " Flags: 0x%x", rlsa
->flags
);
5792 vty_out(vty
, " :%s%s%s%s",
5793 IS_ROUTER_LSA_BORDER(rlsa
) ? " ABR" : "",
5794 IS_ROUTER_LSA_EXTERNAL(rlsa
) ? " ASBR" : "",
5795 IS_ROUTER_LSA_VIRTUAL(rlsa
) ? " VL-endpoint"
5797 IS_ROUTER_LSA_SHORTCUT(rlsa
) ? " Shortcut"
5802 vty_out(vty
, " LS Type: %s\n",
5803 lookup_msg(ospf_lsa_type_msg
, lsa
->data
->type
, NULL
));
5804 vty_out(vty
, " Link State ID: %s %s\n", inet_ntoa(lsa
->data
->id
),
5805 lookup_msg(ospf_link_state_id_type_msg
, lsa
->data
->type
, NULL
));
5806 vty_out(vty
, " Advertising Router: %s\n",
5807 inet_ntoa(lsa
->data
->adv_router
));
5808 vty_out(vty
, " LS Seq Number: %08lx\n",
5809 (unsigned long)ntohl(lsa
->data
->ls_seqnum
));
5810 vty_out(vty
, " Checksum: 0x%04x\n", ntohs(lsa
->data
->checksum
));
5811 vty_out(vty
, " Length: %d\n\n", ntohs(lsa
->data
->length
));
5814 const char *link_type_desc
[] = {
5816 "another Router (point-to-point)",
5817 "a Transit Network",
5822 const char *link_id_desc
[] = {
5823 "(null)", "Neighboring Router ID", "Designated Router address",
5824 "Net", "Neighboring Router ID",
5827 const char *link_data_desc
[] = {
5828 "(null)", "Router Interface address", "Router Interface address",
5829 "Network Mask", "Router Interface address",
5832 /* Show router-LSA each Link information. */
5833 static void show_ip_ospf_database_router_links(struct vty
*vty
,
5834 struct router_lsa
*rl
)
5839 len
= ntohs(rl
->header
.length
) - 4;
5840 for (i
= 0; i
< ntohs(rl
->links
) && len
> 0; len
-= 12, i
++) {
5841 type
= rl
->link
[i
].type
;
5843 vty_out(vty
, " Link connected to: %s\n",
5844 link_type_desc
[type
]);
5845 vty_out(vty
, " (Link ID) %s: %s\n", link_id_desc
[type
],
5846 inet_ntoa(rl
->link
[i
].link_id
));
5847 vty_out(vty
, " (Link Data) %s: %s\n", link_data_desc
[type
],
5848 inet_ntoa(rl
->link
[i
].link_data
));
5849 vty_out(vty
, " Number of TOS metrics: 0\n");
5850 vty_out(vty
, " TOS 0 Metric: %d\n",
5851 ntohs(rl
->link
[i
].metric
));
5856 /* Show router-LSA detail information. */
5857 static int show_router_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5860 struct router_lsa
*rl
= (struct router_lsa
*)lsa
->data
;
5862 show_ip_ospf_database_header(vty
, lsa
);
5864 vty_out(vty
, " Number of Links: %d\n\n", ntohs(rl
->links
));
5866 show_ip_ospf_database_router_links(vty
, rl
);
5873 /* Show network-LSA detail information. */
5874 static int show_network_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5879 struct network_lsa
*nl
= (struct network_lsa
*)lsa
->data
;
5881 show_ip_ospf_database_header(vty
, lsa
);
5883 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(nl
->mask
));
5885 length
= ntohs(lsa
->data
->length
) - OSPF_LSA_HEADER_SIZE
- 4;
5887 for (i
= 0; length
> 0; i
++, length
-= 4)
5888 vty_out(vty
, " Attached Router: %s\n",
5889 inet_ntoa(nl
->routers
[i
]));
5897 /* Show summary-LSA detail information. */
5898 static int show_summary_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5901 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
5903 show_ip_ospf_database_header(vty
, lsa
);
5905 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(sl
->mask
));
5906 vty_out(vty
, " TOS: 0 Metric: %d\n",
5907 GET_METRIC(sl
->metric
));
5914 /* Show summary-ASBR-LSA detail information. */
5915 static int show_summary_asbr_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5918 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
5920 show_ip_ospf_database_header(vty
, lsa
);
5922 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(sl
->mask
));
5923 vty_out(vty
, " TOS: 0 Metric: %d\n",
5924 GET_METRIC(sl
->metric
));
5931 /* Show AS-external-LSA detail information. */
5932 static int show_as_external_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5935 struct as_external_lsa
*al
=
5936 (struct as_external_lsa
*)lsa
->data
;
5938 show_ip_ospf_database_header(vty
, lsa
);
5940 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(al
->mask
));
5941 vty_out(vty
, " Metric Type: %s\n",
5942 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
5943 ? "2 (Larger than any link state path)"
5945 vty_out(vty
, " TOS: 0\n");
5946 vty_out(vty
, " Metric: %d\n",
5947 GET_METRIC(al
->e
[0].metric
));
5948 vty_out(vty
, " Forward Address: %s\n",
5949 inet_ntoa(al
->e
[0].fwd_addr
));
5952 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
5953 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
5960 show_as_external_lsa_stdvty (struct ospf_lsa
*lsa
)
5962 struct as_external_lsa
*al
= (struct as_external_lsa
*) lsa
->data
;
5964 /* show_ip_ospf_database_header (vty, lsa); */
5966 zlog_debug( " Network Mask: /%d%s",
5967 ip_masklen (al
->mask
), "\n");
5968 zlog_debug( " Metric Type: %s%s",
5969 IS_EXTERNAL_METRIC (al
->e
[0].tos
) ?
5970 "2 (Larger than any link state path)" : "1", "\n");
5971 zlog_debug( " TOS: 0%s", "\n");
5972 zlog_debug( " Metric: %d%s",
5973 GET_METRIC (al
->e
[0].metric
), "\n");
5974 zlog_debug( " Forward Address: %s%s",
5975 inet_ntoa (al
->e
[0].fwd_addr
), "\n");
5977 zlog_debug( " External Route Tag: %"ROUTE_TAG_PRI
"%s%s",
5978 (route_tag_t
)ntohl (al
->e
[0].route_tag
), "\n", "\n");
5983 /* Show AS-NSSA-LSA detail information. */
5984 static int show_as_nssa_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5987 struct as_external_lsa
*al
=
5988 (struct as_external_lsa
*)lsa
->data
;
5990 show_ip_ospf_database_header(vty
, lsa
);
5992 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(al
->mask
));
5993 vty_out(vty
, " Metric Type: %s\n",
5994 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
5995 ? "2 (Larger than any link state path)"
5997 vty_out(vty
, " TOS: 0\n");
5998 vty_out(vty
, " Metric: %d\n",
5999 GET_METRIC(al
->e
[0].metric
));
6000 vty_out(vty
, " NSSA: Forward Address: %s\n",
6001 inet_ntoa(al
->e
[0].fwd_addr
));
6004 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
6005 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6011 static int show_func_dummy(struct vty
*vty
, struct ospf_lsa
*lsa
)
6016 static int show_opaque_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
6019 show_ip_ospf_database_header(vty
, lsa
);
6020 show_opaque_info_detail(vty
, lsa
);
6027 int (*show_function
[])(struct vty
*, struct ospf_lsa
*) = {
6029 show_router_lsa_detail
,
6030 show_network_lsa_detail
,
6031 show_summary_lsa_detail
,
6032 show_summary_asbr_lsa_detail
,
6033 show_as_external_lsa_detail
,
6035 show_as_nssa_lsa_detail
, /* almost same as external */
6037 show_opaque_lsa_detail
,
6038 show_opaque_lsa_detail
,
6039 show_opaque_lsa_detail
,
6042 static void show_lsa_prefix_set(struct vty
*vty
, struct prefix_ls
*lp
,
6043 struct in_addr
*id
, struct in_addr
*adv_router
)
6045 memset(lp
, 0, sizeof(struct prefix_ls
));
6049 else if (adv_router
== NULL
) {
6055 lp
->adv_router
= *adv_router
;
6059 static void show_lsa_detail_proc(struct vty
*vty
, struct route_table
*rt
,
6060 struct in_addr
*id
, struct in_addr
*adv_router
)
6062 struct prefix_ls lp
;
6063 struct route_node
*rn
, *start
;
6064 struct ospf_lsa
*lsa
;
6066 show_lsa_prefix_set(vty
, &lp
, id
, adv_router
);
6067 start
= route_node_get(rt
, (struct prefix
*)&lp
);
6069 route_lock_node(start
);
6070 for (rn
= start
; rn
; rn
= route_next_until(rn
, start
))
6071 if ((lsa
= rn
->info
)) {
6072 if (show_function
[lsa
->data
->type
] != NULL
)
6073 show_function
[lsa
->data
->type
](vty
,
6076 route_unlock_node(start
);
6080 /* Show detail LSA information
6081 -- if id is NULL then show all LSAs. */
6082 static void show_lsa_detail(struct vty
*vty
, struct ospf
*ospf
, int type
,
6083 struct in_addr
*id
, struct in_addr
*adv_router
)
6085 struct listnode
*node
;
6086 struct ospf_area
*area
;
6089 case OSPF_AS_EXTERNAL_LSA
:
6090 case OSPF_OPAQUE_AS_LSA
:
6091 vty_out(vty
, " %s \n\n",
6092 show_database_desc
[type
]);
6093 show_lsa_detail_proc(vty
, AS_LSDB(ospf
, type
), id
, adv_router
);
6096 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6097 vty_out(vty
, "\n %s (Area %s)\n\n",
6098 show_database_desc
[type
],
6099 ospf_area_desc_string(area
));
6100 show_lsa_detail_proc(vty
, AREA_LSDB(area
, type
), id
,
6107 static void show_lsa_detail_adv_router_proc(struct vty
*vty
,
6108 struct route_table
*rt
,
6109 struct in_addr
*adv_router
)
6111 struct route_node
*rn
;
6112 struct ospf_lsa
*lsa
;
6114 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
))
6115 if ((lsa
= rn
->info
))
6116 if (IPV4_ADDR_SAME(adv_router
,
6117 &lsa
->data
->adv_router
)) {
6118 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
6120 if (show_function
[lsa
->data
->type
] != NULL
)
6121 show_function
[lsa
->data
->type
](vty
,
6126 /* Show detail LSA information. */
6127 static void show_lsa_detail_adv_router(struct vty
*vty
, struct ospf
*ospf
,
6128 int type
, struct in_addr
*adv_router
)
6130 struct listnode
*node
;
6131 struct ospf_area
*area
;
6134 case OSPF_AS_EXTERNAL_LSA
:
6135 case OSPF_OPAQUE_AS_LSA
:
6136 vty_out(vty
, " %s \n\n",
6137 show_database_desc
[type
]);
6138 show_lsa_detail_adv_router_proc(vty
, AS_LSDB(ospf
, type
),
6142 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6143 vty_out(vty
, "\n %s (Area %s)\n\n",
6144 show_database_desc
[type
],
6145 ospf_area_desc_string(area
));
6146 show_lsa_detail_adv_router_proc(
6147 vty
, AREA_LSDB(area
, type
), adv_router
);
6153 static void show_ip_ospf_database_summary(struct vty
*vty
, struct ospf
*ospf
,
6156 struct ospf_lsa
*lsa
;
6157 struct route_node
*rn
;
6158 struct ospf_area
*area
;
6159 struct listnode
*node
;
6162 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6163 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6165 case OSPF_AS_EXTERNAL_LSA
:
6166 case OSPF_OPAQUE_AS_LSA
:
6171 if (ospf_lsdb_count_self(area
->lsdb
, type
) > 0
6173 && ospf_lsdb_count(area
->lsdb
, type
) > 0)) {
6174 vty_out(vty
, " %s (Area %s)\n\n",
6175 show_database_desc
[type
],
6176 ospf_area_desc_string(area
));
6177 vty_out(vty
, "%s\n",
6178 show_database_header
[type
]);
6180 LSDB_LOOP (AREA_LSDB(area
, type
), rn
, lsa
)
6181 show_lsa_summary(vty
, lsa
, self
);
6188 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6190 case OSPF_AS_EXTERNAL_LSA
:
6191 case OSPF_OPAQUE_AS_LSA
:
6196 if (ospf_lsdb_count_self(ospf
->lsdb
, type
)
6197 || (!self
&& ospf_lsdb_count(ospf
->lsdb
, type
))) {
6198 vty_out(vty
, " %s\n\n",
6199 show_database_desc
[type
]);
6200 vty_out(vty
, "%s\n", show_database_header
[type
]);
6202 LSDB_LOOP (AS_LSDB(ospf
, type
), rn
, lsa
)
6203 show_lsa_summary(vty
, lsa
, self
);
6212 static void show_ip_ospf_database_maxage(struct vty
*vty
, struct ospf
*ospf
)
6214 struct route_node
*rn
;
6216 vty_out(vty
, "\n MaxAge Link States:\n\n");
6218 for (rn
= route_top(ospf
->maxage_lsa
); rn
; rn
= route_next(rn
)) {
6219 struct ospf_lsa
*lsa
;
6221 if ((lsa
= rn
->info
) != NULL
) {
6222 vty_out(vty
, "Link type: %d\n", lsa
->data
->type
);
6223 vty_out(vty
, "Link State ID: %s\n",
6224 inet_ntoa(lsa
->data
->id
));
6225 vty_out(vty
, "Advertising Router: %s\n",
6226 inet_ntoa(lsa
->data
->adv_router
));
6227 vty_out(vty
, "LSA lock count: %d\n", lsa
->lock
);
6233 #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
6234 #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
6236 #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
6237 #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
6238 #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
6239 #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
6241 #define OSPF_LSA_TYPES_DESC \
6242 "ASBR summary link states\n" \
6243 "External link states\n" \
6244 "Network link states\n" \
6245 "Router link states\n" \
6246 "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \
6247 OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
6248 OSPF_LSA_TYPE_OPAQUE_AS_DESC
6250 static int show_ip_ospf_database_common(struct vty
*vty
, struct ospf
*ospf
,
6251 int arg_base
, int argc
,
6252 struct cmd_token
**argv
,
6257 struct in_addr id
, adv_router
;
6260 vty_out(vty
, "\nOSPF Instance: %d\n", ospf
->instance
);
6262 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
6264 vty_out(vty
, "\n OSPF Router with ID (%s)\n\n",
6265 inet_ntoa(ospf
->router_id
));
6268 if (argc
== arg_base
+ 4) {
6269 show_ip_ospf_database_summary(vty
, ospf
, 0);
6273 /* Set database type to show. */
6274 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
6275 type
= OSPF_ROUTER_LSA
;
6276 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
6277 type
= OSPF_NETWORK_LSA
;
6278 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
6279 type
= OSPF_AS_NSSA_LSA
;
6280 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "su", 2) == 0)
6281 type
= OSPF_SUMMARY_LSA
;
6282 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
6283 type
= OSPF_ASBR_SUMMARY_LSA
;
6284 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
6285 type
= OSPF_AS_EXTERNAL_LSA
;
6286 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "se", 2) == 0) {
6287 show_ip_ospf_database_summary(vty
, ospf
, 1);
6289 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "m", 1) == 0) {
6290 show_ip_ospf_database_maxage(vty
, ospf
);
6292 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
6293 type
= OSPF_OPAQUE_LINK_LSA
;
6294 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
6295 type
= OSPF_OPAQUE_AREA_LSA
;
6296 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
6297 type
= OSPF_OPAQUE_AS_LSA
;
6301 /* `show ip ospf database LSA'. */
6302 if (argc
== arg_base
+ 5)
6303 show_lsa_detail(vty
, ospf
, type
, NULL
, NULL
);
6304 else if (argc
>= arg_base
+ 6) {
6305 ret
= inet_aton(argv
[arg_base
+ 5]->arg
, &id
);
6309 /* `show ip ospf database LSA ID'. */
6310 if (argc
== arg_base
+ 6)
6311 show_lsa_detail(vty
, ospf
, type
, &id
, NULL
);
6312 /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */
6313 else if (argc
== arg_base
+ 7) {
6314 if (strncmp(argv
[arg_base
+ 6]->text
, "s", 1) == 0)
6315 adv_router
= ospf
->router_id
;
6317 ret
= inet_aton(argv
[arg_base
+ 7]->arg
,
6322 show_lsa_detail(vty
, ospf
, type
, &id
, &adv_router
);
6329 DEFUN (show_ip_ospf_database_max
,
6330 show_ip_ospf_database_max_cmd
,
6331 "show ip ospf [vrf <NAME|all>] database <max-age|self-originate>",
6334 "OSPF information\n"
6337 "Database summary\n"
6338 "LSAs in MaxAge list\n"
6339 "Self-originated link states\n")
6341 struct ospf
*ospf
= NULL
;
6342 struct listnode
*node
= NULL
;
6343 char *vrf_name
= NULL
;
6344 bool all_vrf
= FALSE
;
6345 int ret
= CMD_SUCCESS
;
6348 uint8_t use_vrf
= 0;
6350 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
6353 bool ospf_output
= FALSE
;
6358 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6359 if (!ospf
->oi_running
)
6362 ret
= show_ip_ospf_database_common(
6363 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
,
6368 vty_out(vty
, "%% OSPF instance not found\n");
6370 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6371 if (ospf
== NULL
|| !ospf
->oi_running
) {
6372 vty_out(vty
, "%% OSPF instance not found\n");
6375 ret
= (show_ip_ospf_database_common(
6376 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
,
6380 /* Display default ospf (instance 0) info */
6381 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6382 if (ospf
== NULL
|| !ospf
->oi_running
) {
6383 vty_out(vty
, "%% OSPF instance not found\n");
6387 ret
= show_ip_ospf_database_common(vty
, ospf
, 0, argc
, argv
,
6394 DEFUN (show_ip_ospf_instance_database
,
6395 show_ip_ospf_instance_database_cmd
,
6396 "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>]]]",
6399 "OSPF information\n"
6402 "Database summary\n"
6404 "Link State ID (as an IP address)\n"
6405 "Self-originated link states\n"
6406 "Advertising Router link states\n"
6407 "Advertising Router (as an IP address)\n")
6410 unsigned short instance
= 0;
6411 struct listnode
*node
= NULL
;
6412 char *vrf_name
= NULL
;
6413 bool all_vrf
= FALSE
;
6414 int ret
= CMD_SUCCESS
;
6417 uint8_t use_vrf
= 0;
6419 if (argv_find(argv
, argc
, "(1-65535)", &idx
)) {
6420 instance
= strtoul(argv
[idx
]->arg
, NULL
, 10);
6421 ospf
= ospf_lookup_instance(instance
);
6423 return CMD_NOT_MY_INSTANCE
;
6424 if (!ospf
->oi_running
)
6427 return (show_ip_ospf_database_common(vty
, ospf
, idx
? 1 : 0,
6428 argc
, argv
, use_vrf
));
6429 } else if (argv_find(argv
, argc
, "vrf", &idx
)) {
6430 vrf_name
= argv
[++idx
]->arg
;
6431 all_vrf
= strmatch(vrf_name
, "all");
6437 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6438 if (!ospf
->oi_running
)
6440 ret
= (show_ip_ospf_database_common(
6441 vty
, ospf
, idx
? 2 : 0, argc
, argv
,
6445 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6446 if ((ospf
== NULL
) || !ospf
->oi_running
) {
6447 vty_out(vty
, "%% OSPF instance not found\n");
6451 ret
= (show_ip_ospf_database_common(
6452 vty
, ospf
, idx
? 2 : 0, argc
, argv
, use_vrf
));
6455 /* Display default ospf (instance 0) info */
6456 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6457 if (ospf
== NULL
|| !ospf
->oi_running
) {
6458 vty_out(vty
, "%% OSPF instance not found\n");
6462 ret
= (show_ip_ospf_database_common(vty
, ospf
, 0, argc
, argv
,
6469 DEFUN (show_ip_ospf_instance_database_max
,
6470 show_ip_ospf_instance_database_max_cmd
,
6471 "show ip ospf (1-65535) database <max-age|self-originate>",
6474 "OSPF information\n"
6476 "Database summary\n"
6477 "LSAs in MaxAge list\n"
6478 "Self-originated link states\n")
6482 unsigned short instance
= 0;
6484 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
6486 ospf
= ospf_lookup_instance(instance
);
6488 return CMD_NOT_MY_INSTANCE
;
6490 if (!ospf
->oi_running
) {
6491 vty_out(vty
, "%% OSPF instance not found\n");
6495 return show_ip_ospf_database_common(vty
, ospf
, 1, argc
, argv
, 0);
6499 static int show_ip_ospf_database_type_adv_router_common(struct vty
*vty
,
6501 int arg_base
, int argc
,
6502 struct cmd_token
**argv
,
6507 struct in_addr adv_router
;
6510 vty_out(vty
, "\nOSPF Instance: %d\n", ospf
->instance
);
6512 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
6514 vty_out(vty
, "\n OSPF Router with ID (%s)\n\n",
6515 inet_ntoa(ospf
->router_id
));
6517 /* Set database type to show. */
6518 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
6519 type
= OSPF_ROUTER_LSA
;
6520 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
6521 type
= OSPF_NETWORK_LSA
;
6522 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
6523 type
= OSPF_AS_NSSA_LSA
;
6524 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "s", 1) == 0)
6525 type
= OSPF_SUMMARY_LSA
;
6526 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
6527 type
= OSPF_ASBR_SUMMARY_LSA
;
6528 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
6529 type
= OSPF_AS_EXTERNAL_LSA
;
6530 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
6531 type
= OSPF_OPAQUE_LINK_LSA
;
6532 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
6533 type
= OSPF_OPAQUE_AREA_LSA
;
6534 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
6535 type
= OSPF_OPAQUE_AS_LSA
;
6539 /* `show ip ospf database LSA adv-router ADV_ROUTER'. */
6540 if (strncmp(argv
[arg_base
+ 5]->text
, "s", 1) == 0)
6541 adv_router
= ospf
->router_id
;
6543 ret
= inet_aton(argv
[arg_base
+ 6]->arg
, &adv_router
);
6548 show_lsa_detail_adv_router(vty
, ospf
, type
, &adv_router
);
6553 DEFUN (show_ip_ospf_instance_database_type_adv_router
,
6554 show_ip_ospf_instance_database_type_adv_router_cmd
,
6555 "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>",
6558 "OSPF information\n"
6561 "Database summary\n"
6563 "Advertising Router link states\n"
6564 "Advertising Router (as an IP address)\n"
6565 "Self-originated link states\n")
6567 struct ospf
*ospf
= NULL
;
6568 unsigned short instance
= 0;
6569 struct listnode
*node
= NULL
;
6570 char *vrf_name
= NULL
;
6571 bool all_vrf
= FALSE
;
6572 int ret
= CMD_SUCCESS
;
6574 int idx
= 0, idx_vrf
= 0;
6575 uint8_t use_vrf
= 0;
6577 if (argv_find(argv
, argc
, "(1-65535)", &idx
)) {
6578 instance
= strtoul(argv
[idx
]->arg
, NULL
, 10);
6579 ospf
= ospf_lookup_instance(instance
);
6581 return CMD_NOT_MY_INSTANCE
;
6582 if (!ospf
->oi_running
) {
6583 vty_out(vty
, "%% OSPF instance not found\n");
6587 return (show_ip_ospf_database_type_adv_router_common(
6588 vty
, ospf
, idx
? 1 : 0, argc
, argv
, use_vrf
));
6591 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
6594 bool ospf_output
= FALSE
;
6599 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6600 if (!ospf
->oi_running
)
6603 ret
= show_ip_ospf_database_type_adv_router_common(
6604 vty
, ospf
, idx
? 1 : 0, argc
, argv
,
6608 vty_out(vty
, "%% OSPF instance not found\n");
6610 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6611 if ((ospf
== NULL
) || !ospf
->oi_running
) {
6612 vty_out(vty
, "%% OSPF instance not found\n");
6616 ret
= show_ip_ospf_database_type_adv_router_common(
6617 vty
, ospf
, idx
? 1 : 0, argc
, argv
, use_vrf
);
6620 /* Display default ospf (instance 0) info */
6621 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6622 if (ospf
== NULL
|| !ospf
->oi_running
) {
6623 vty_out(vty
, "%% OSPF instance not found\n");
6627 ret
= show_ip_ospf_database_type_adv_router_common(
6628 vty
, ospf
, idx
? 1 : 0, argc
, argv
, use_vrf
);
6631 /*return (show_ip_ospf_database_type_adv_router_common(
6632 vty, ospf, idx ? 1 : 0, argc, argv));*/
6635 DEFUN (ip_ospf_authentication_args
,
6636 ip_ospf_authentication_args_addr_cmd
,
6637 "ip ospf authentication <null|message-digest> [A.B.C.D]",
6639 "OSPF interface commands\n"
6640 "Enable authentication on this interface\n"
6641 "Use null authentication\n"
6642 "Use message-digest authentication\n"
6643 "Address of interface\n")
6645 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6646 int idx_encryption
= 3;
6648 struct in_addr addr
;
6650 struct ospf_if_params
*params
;
6652 params
= IF_DEF_PARAMS(ifp
);
6655 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6658 "Please specify interface address by A.B.C.D\n");
6659 return CMD_WARNING_CONFIG_FAILED
;
6662 params
= ospf_get_if_params(ifp
, addr
);
6663 ospf_if_update_params(ifp
, addr
);
6666 /* Handle null authentication */
6667 if (argv
[idx_encryption
]->arg
[0] == 'n') {
6668 SET_IF_PARAM(params
, auth_type
);
6669 params
->auth_type
= OSPF_AUTH_NULL
;
6673 /* Handle message-digest authentication */
6674 if (argv
[idx_encryption
]->arg
[0] == 'm') {
6675 SET_IF_PARAM(params
, auth_type
);
6676 params
->auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
6680 vty_out(vty
, "You shouldn't get here!\n");
6681 return CMD_WARNING_CONFIG_FAILED
;
6684 DEFUN (ip_ospf_authentication
,
6685 ip_ospf_authentication_addr_cmd
,
6686 "ip ospf authentication [A.B.C.D]",
6688 "OSPF interface commands\n"
6689 "Enable authentication on this interface\n"
6690 "Address of interface\n")
6692 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6694 struct in_addr addr
;
6696 struct ospf_if_params
*params
;
6698 params
= IF_DEF_PARAMS(ifp
);
6701 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6704 "Please specify interface address by A.B.C.D\n");
6705 return CMD_WARNING_CONFIG_FAILED
;
6708 params
= ospf_get_if_params(ifp
, addr
);
6709 ospf_if_update_params(ifp
, addr
);
6712 SET_IF_PARAM(params
, auth_type
);
6713 params
->auth_type
= OSPF_AUTH_SIMPLE
;
6718 DEFUN (no_ip_ospf_authentication_args
,
6719 no_ip_ospf_authentication_args_addr_cmd
,
6720 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
6723 "OSPF interface commands\n"
6724 "Enable authentication on this interface\n"
6725 "Use null authentication\n"
6726 "Use message-digest authentication\n"
6727 "Address of interface\n")
6729 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6730 int idx_encryption
= 4;
6732 struct in_addr addr
;
6734 struct ospf_if_params
*params
;
6735 struct route_node
*rn
;
6738 params
= IF_DEF_PARAMS(ifp
);
6741 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6744 "Please specify interface address by A.B.C.D\n");
6745 return CMD_WARNING_CONFIG_FAILED
;
6748 params
= ospf_lookup_if_params(ifp
, addr
);
6749 if (params
== NULL
) {
6750 vty_out(vty
, "Ip Address specified is unknown\n");
6751 return CMD_WARNING_CONFIG_FAILED
;
6753 params
->auth_type
= OSPF_AUTH_NOTSET
;
6754 UNSET_IF_PARAM(params
, auth_type
);
6755 if (params
!= IF_DEF_PARAMS(ifp
)) {
6756 ospf_free_if_params(ifp
, addr
);
6757 ospf_if_update_params(ifp
, addr
);
6760 if (argv
[idx_encryption
]->arg
[0] == 'n') {
6761 auth_type
= OSPF_AUTH_NULL
;
6762 } else if (argv
[idx_encryption
]->arg
[0] == 'm') {
6763 auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
6765 vty_out(vty
, "Unexpected input encountered\n");
6766 return CMD_WARNING_CONFIG_FAILED
;
6769 * Here we have a case where the user has entered
6770 * 'no ip ospf authentication (null | message_digest )'
6771 * we need to find if we have any ip addresses underneath it
6773 * correspond to the associated type.
6775 if (params
->auth_type
== auth_type
) {
6776 params
->auth_type
= OSPF_AUTH_NOTSET
;
6777 UNSET_IF_PARAM(params
, auth_type
);
6780 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
6781 rn
= route_next(rn
)) {
6782 if ((params
= rn
->info
)) {
6783 if (params
->auth_type
== auth_type
) {
6784 params
->auth_type
= OSPF_AUTH_NOTSET
;
6785 UNSET_IF_PARAM(params
, auth_type
);
6786 if (params
!= IF_DEF_PARAMS(ifp
)) {
6787 ospf_free_if_params(
6788 ifp
, rn
->p
.u
.prefix4
);
6789 ospf_if_update_params(
6790 ifp
, rn
->p
.u
.prefix4
);
6800 DEFUN (no_ip_ospf_authentication
,
6801 no_ip_ospf_authentication_addr_cmd
,
6802 "no ip ospf authentication [A.B.C.D]",
6805 "OSPF interface commands\n"
6806 "Enable authentication on this interface\n"
6807 "Address of interface\n")
6809 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6811 struct in_addr addr
;
6813 struct ospf_if_params
*params
;
6814 struct route_node
*rn
;
6816 params
= IF_DEF_PARAMS(ifp
);
6819 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6822 "Please specify interface address by A.B.C.D\n");
6823 return CMD_WARNING_CONFIG_FAILED
;
6826 params
= ospf_lookup_if_params(ifp
, addr
);
6827 if (params
== NULL
) {
6828 vty_out(vty
, "Ip Address specified is unknown\n");
6829 return CMD_WARNING_CONFIG_FAILED
;
6832 params
->auth_type
= OSPF_AUTH_NOTSET
;
6833 UNSET_IF_PARAM(params
, auth_type
);
6834 if (params
!= IF_DEF_PARAMS(ifp
)) {
6835 ospf_free_if_params(ifp
, addr
);
6836 ospf_if_update_params(ifp
, addr
);
6840 * When a user enters 'no ip ospf authentication'
6841 * We should remove all authentication types from
6844 if ((params
->auth_type
== OSPF_AUTH_NULL
)
6845 || (params
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
6846 || (params
->auth_type
== OSPF_AUTH_SIMPLE
)) {
6847 params
->auth_type
= OSPF_AUTH_NOTSET
;
6848 UNSET_IF_PARAM(params
, auth_type
);
6851 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
6852 rn
= route_next(rn
)) {
6853 if ((params
= rn
->info
)) {
6855 if ((params
->auth_type
== OSPF_AUTH_NULL
)
6856 || (params
->auth_type
6857 == OSPF_AUTH_CRYPTOGRAPHIC
)
6858 || (params
->auth_type
6859 == OSPF_AUTH_SIMPLE
)) {
6860 params
->auth_type
= OSPF_AUTH_NOTSET
;
6861 UNSET_IF_PARAM(params
, auth_type
);
6862 if (params
!= IF_DEF_PARAMS(ifp
)) {
6863 ospf_free_if_params(
6864 ifp
, rn
->p
.u
.prefix4
);
6865 ospf_if_update_params(
6866 ifp
, rn
->p
.u
.prefix4
);
6877 DEFUN (ip_ospf_authentication_key
,
6878 ip_ospf_authentication_key_addr_cmd
,
6879 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
6881 "OSPF interface commands\n"
6882 "Authentication password (key)\n"
6883 "The OSPF password (key)\n"
6884 "Address of interface\n")
6886 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6888 struct in_addr addr
;
6889 struct ospf_if_params
*params
;
6891 params
= IF_DEF_PARAMS(ifp
);
6893 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6894 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6896 "Please specify interface address by A.B.C.D\n");
6897 return CMD_WARNING_CONFIG_FAILED
;
6900 params
= ospf_get_if_params(ifp
, addr
);
6901 ospf_if_update_params(ifp
, addr
);
6904 strlcpy((char *)params
->auth_simple
, argv
[3]->arg
,
6905 sizeof(params
->auth_simple
));
6906 SET_IF_PARAM(params
, auth_simple
);
6911 DEFUN_HIDDEN (ospf_authentication_key
,
6912 ospf_authentication_key_cmd
,
6913 "ospf authentication-key AUTH_KEY [A.B.C.D]",
6914 "OSPF interface commands\n"
6915 VLINK_HELPSTR_AUTH_SIMPLE
6916 "Address of interface\n")
6918 return ip_ospf_authentication_key(self
, vty
, argc
, argv
);
6921 DEFUN (no_ip_ospf_authentication_key
,
6922 no_ip_ospf_authentication_key_authkey_addr_cmd
,
6923 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
6926 "OSPF interface commands\n"
6927 VLINK_HELPSTR_AUTH_SIMPLE
6928 "Address of interface\n")
6930 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6932 struct in_addr addr
;
6933 struct ospf_if_params
*params
;
6934 params
= IF_DEF_PARAMS(ifp
);
6936 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6937 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6939 "Please specify interface address by A.B.C.D\n");
6940 return CMD_WARNING_CONFIG_FAILED
;
6943 params
= ospf_lookup_if_params(ifp
, addr
);
6948 memset(params
->auth_simple
, 0, OSPF_AUTH_SIMPLE_SIZE
);
6949 UNSET_IF_PARAM(params
, auth_simple
);
6951 if (params
!= IF_DEF_PARAMS(ifp
)) {
6952 ospf_free_if_params(ifp
, addr
);
6953 ospf_if_update_params(ifp
, addr
);
6959 DEFUN_HIDDEN (no_ospf_authentication_key
,
6960 no_ospf_authentication_key_authkey_addr_cmd
,
6961 "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
6963 "OSPF interface commands\n"
6964 VLINK_HELPSTR_AUTH_SIMPLE
6965 "Address of interface\n")
6967 return no_ip_ospf_authentication_key(self
, vty
, argc
, argv
);
6970 DEFUN (ip_ospf_message_digest_key
,
6971 ip_ospf_message_digest_key_cmd
,
6972 "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
6974 "OSPF interface commands\n"
6975 "Message digest authentication password (key)\n"
6977 "Use MD5 algorithm\n"
6978 "The OSPF password (key)\n"
6979 "Address of interface\n")
6981 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6982 struct crypt_key
*ck
;
6984 struct in_addr addr
;
6985 struct ospf_if_params
*params
;
6987 params
= IF_DEF_PARAMS(ifp
);
6990 argv_find(argv
, argc
, "(1-255)", &idx
);
6991 char *keyid
= argv
[idx
]->arg
;
6992 argv_find(argv
, argc
, "KEY", &idx
);
6993 char *cryptkey
= argv
[idx
]->arg
;
6995 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6996 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6998 "Please specify interface address by A.B.C.D\n");
6999 return CMD_WARNING_CONFIG_FAILED
;
7002 params
= ospf_get_if_params(ifp
, addr
);
7003 ospf_if_update_params(ifp
, addr
);
7006 key_id
= strtol(keyid
, NULL
, 10);
7007 if (ospf_crypt_key_lookup(params
->auth_crypt
, key_id
) != NULL
) {
7008 vty_out(vty
, "OSPF: Key %d already exists\n", key_id
);
7012 ck
= ospf_crypt_key_new();
7013 ck
->key_id
= (uint8_t)key_id
;
7014 strlcpy((char *)ck
->auth_key
, cryptkey
, sizeof(ck
->auth_key
));
7016 ospf_crypt_key_add(params
->auth_crypt
, ck
);
7017 SET_IF_PARAM(params
, auth_crypt
);
7022 DEFUN_HIDDEN (ospf_message_digest_key
,
7023 ospf_message_digest_key_cmd
,
7024 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7025 "OSPF interface commands\n"
7026 "Message digest authentication password (key)\n"
7028 "Use MD5 algorithm\n"
7029 "The OSPF password (key)\n"
7030 "Address of interface\n")
7032 return ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7035 DEFUN (no_ip_ospf_message_digest_key
,
7036 no_ip_ospf_message_digest_key_cmd
,
7037 "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7040 "OSPF interface commands\n"
7041 "Message digest authentication password (key)\n"
7043 "Use MD5 algorithm\n"
7044 "The OSPF password (key)\n"
7045 "Address of interface\n")
7047 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7049 struct crypt_key
*ck
;
7051 struct in_addr addr
;
7052 struct ospf_if_params
*params
;
7053 params
= IF_DEF_PARAMS(ifp
);
7055 argv_find(argv
, argc
, "(1-255)", &idx
);
7056 char *keyid
= argv
[idx
]->arg
;
7058 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7059 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7061 "Please specify interface address by A.B.C.D\n");
7062 return CMD_WARNING_CONFIG_FAILED
;
7065 params
= ospf_lookup_if_params(ifp
, addr
);
7070 key_id
= strtol(keyid
, NULL
, 10);
7071 ck
= ospf_crypt_key_lookup(params
->auth_crypt
, key_id
);
7073 vty_out(vty
, "OSPF: Key %d does not exist\n", key_id
);
7074 return CMD_WARNING_CONFIG_FAILED
;
7077 ospf_crypt_key_delete(params
->auth_crypt
, key_id
);
7079 if (params
!= IF_DEF_PARAMS(ifp
)) {
7080 ospf_free_if_params(ifp
, addr
);
7081 ospf_if_update_params(ifp
, addr
);
7087 DEFUN_HIDDEN (no_ospf_message_digest_key
,
7088 no_ospf_message_digest_key_cmd
,
7089 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7091 "OSPF interface commands\n"
7092 "Message digest authentication password (key)\n"
7094 "Use MD5 algorithm\n"
7095 "The OSPF password (key)\n"
7096 "Address of interface\n")
7098 return no_ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7101 DEFUN (ip_ospf_cost
,
7103 "ip ospf cost (1-65535) [A.B.C.D]",
7105 "OSPF interface commands\n"
7108 "Address of interface\n")
7110 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7112 uint32_t cost
= OSPF_OUTPUT_COST_DEFAULT
;
7113 struct in_addr addr
;
7114 struct ospf_if_params
*params
;
7115 params
= IF_DEF_PARAMS(ifp
);
7118 char *coststr
= NULL
, *ifaddr
= NULL
;
7120 argv_find(argv
, argc
, "(1-65535)", &idx
);
7121 coststr
= argv
[idx
]->arg
;
7122 cost
= strtol(coststr
, NULL
, 10);
7124 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7126 if (!inet_aton(ifaddr
, &addr
)) {
7128 "Please specify interface address by A.B.C.D\n");
7129 return CMD_WARNING_CONFIG_FAILED
;
7132 params
= ospf_get_if_params(ifp
, addr
);
7133 ospf_if_update_params(ifp
, addr
);
7136 SET_IF_PARAM(params
, output_cost_cmd
);
7137 params
->output_cost_cmd
= cost
;
7139 ospf_if_recalculate_output_cost(ifp
);
7144 DEFUN_HIDDEN (ospf_cost
,
7146 "ospf cost (1-65535) [A.B.C.D]",
7147 "OSPF interface commands\n"
7150 "Address of interface\n")
7152 return ip_ospf_cost(self
, vty
, argc
, argv
);
7155 DEFUN (no_ip_ospf_cost
,
7156 no_ip_ospf_cost_cmd
,
7157 "no ip ospf cost [(1-65535)] [A.B.C.D]",
7160 "OSPF interface commands\n"
7163 "Address of interface\n")
7165 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7167 struct in_addr addr
;
7168 struct ospf_if_params
*params
;
7170 params
= IF_DEF_PARAMS(ifp
);
7173 char *ifaddr
= NULL
;
7174 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7176 /* According to the semantics we are mimicking "no ip ospf cost N" is
7177 * always treated as "no ip ospf cost" regardless of the actual value
7178 * of N already configured for the interface. Thus ignore cost. */
7181 if (!inet_aton(ifaddr
, &addr
)) {
7183 "Please specify interface address by A.B.C.D\n");
7184 return CMD_WARNING_CONFIG_FAILED
;
7187 params
= ospf_lookup_if_params(ifp
, addr
);
7192 UNSET_IF_PARAM(params
, output_cost_cmd
);
7194 if (params
!= IF_DEF_PARAMS(ifp
)) {
7195 ospf_free_if_params(ifp
, addr
);
7196 ospf_if_update_params(ifp
, addr
);
7199 ospf_if_recalculate_output_cost(ifp
);
7204 DEFUN_HIDDEN (no_ospf_cost
,
7206 "no ospf cost [(1-65535)] [A.B.C.D]",
7208 "OSPF interface commands\n"
7211 "Address of interface\n")
7213 return no_ip_ospf_cost(self
, vty
, argc
, argv
);
7216 static void ospf_nbr_timer_update(struct ospf_interface
*oi
)
7218 struct route_node
*rn
;
7219 struct ospf_neighbor
*nbr
;
7221 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
7222 if ((nbr
= rn
->info
)) {
7223 nbr
->v_inactivity
= OSPF_IF_PARAM(oi
, v_wait
);
7224 nbr
->v_db_desc
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7225 nbr
->v_ls_req
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7226 nbr
->v_ls_upd
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7230 static int ospf_vty_dead_interval_set(struct vty
*vty
, const char *interval_str
,
7231 const char *nbr_str
,
7232 const char *fast_hello_str
)
7234 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7237 struct in_addr addr
;
7239 struct ospf_if_params
*params
;
7240 struct ospf_interface
*oi
;
7241 struct route_node
*rn
;
7243 params
= IF_DEF_PARAMS(ifp
);
7246 ret
= inet_aton(nbr_str
, &addr
);
7249 "Please specify interface address by A.B.C.D\n");
7250 return CMD_WARNING_CONFIG_FAILED
;
7253 params
= ospf_get_if_params(ifp
, addr
);
7254 ospf_if_update_params(ifp
, addr
);
7258 seconds
= strtoul(interval_str
, NULL
, 10);
7260 /* reset fast_hello too, just to be sure */
7261 UNSET_IF_PARAM(params
, fast_hello
);
7262 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
7263 } else if (fast_hello_str
) {
7264 hellomult
= strtoul(fast_hello_str
, NULL
, 10);
7265 /* 1s dead-interval with sub-second hellos desired */
7266 seconds
= OSPF_ROUTER_DEAD_INTERVAL_MINIMAL
;
7267 SET_IF_PARAM(params
, fast_hello
);
7268 params
->fast_hello
= hellomult
;
7271 "Please specify dead-interval or hello-multiplier\n");
7272 return CMD_WARNING_CONFIG_FAILED
;
7275 SET_IF_PARAM(params
, v_wait
);
7276 params
->v_wait
= seconds
;
7278 /* Update timer values in neighbor structure. */
7280 struct ospf
*ospf
= NULL
;
7282 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7284 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
7286 ospf_nbr_timer_update(oi
);
7289 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
7290 if ((oi
= rn
->info
))
7291 ospf_nbr_timer_update(oi
);
7297 DEFUN (ip_ospf_dead_interval
,
7298 ip_ospf_dead_interval_cmd
,
7299 "ip ospf dead-interval (1-65535) [A.B.C.D]",
7301 "OSPF interface commands\n"
7302 "Interval time after which a neighbor is declared down\n"
7304 "Address of interface\n")
7307 char *interval
= argv_find(argv
, argc
, "(1-65535)", &idx
)
7311 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7312 return ospf_vty_dead_interval_set(vty
, interval
, ifaddr
, NULL
);
7316 DEFUN_HIDDEN (ospf_dead_interval
,
7317 ospf_dead_interval_cmd
,
7318 "ospf dead-interval (1-65535) [A.B.C.D]",
7319 "OSPF interface commands\n"
7320 "Interval time after which a neighbor is declared down\n"
7322 "Address of interface\n")
7324 return ip_ospf_dead_interval(self
, vty
, argc
, argv
);
7327 DEFUN (ip_ospf_dead_interval_minimal
,
7328 ip_ospf_dead_interval_minimal_addr_cmd
,
7329 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
7331 "OSPF interface commands\n"
7332 "Interval time after which a neighbor is declared down\n"
7333 "Minimal 1s dead-interval with fast sub-second hellos\n"
7334 "Hello multiplier factor\n"
7335 "Number of Hellos to send each second\n"
7336 "Address of interface\n")
7341 return ospf_vty_dead_interval_set(
7342 vty
, NULL
, argv
[idx_ipv4
]->arg
, argv
[idx_number
]->arg
);
7344 return ospf_vty_dead_interval_set(vty
, NULL
, NULL
,
7345 argv
[idx_number
]->arg
);
7348 DEFUN (no_ip_ospf_dead_interval
,
7349 no_ip_ospf_dead_interval_cmd
,
7350 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
7353 "OSPF interface commands\n"
7354 "Interval time after which a neighbor is declared down\n"
7356 "Minimal 1s dead-interval with fast sub-second hellos\n"
7357 "Hello multiplier factor\n"
7358 "Number of Hellos to send each second\n"
7359 "Address of interface\n")
7361 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7362 int idx_ipv4
= argc
- 1;
7363 struct in_addr addr
= {.s_addr
= 0L};
7365 struct ospf_if_params
*params
;
7366 struct ospf_interface
*oi
;
7367 struct route_node
*rn
;
7369 params
= IF_DEF_PARAMS(ifp
);
7371 if (argv
[idx_ipv4
]->type
== IPV4_TKN
) {
7372 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7375 "Please specify interface address by A.B.C.D\n");
7376 return CMD_WARNING_CONFIG_FAILED
;
7379 params
= ospf_lookup_if_params(ifp
, addr
);
7384 UNSET_IF_PARAM(params
, v_wait
);
7385 params
->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
7387 UNSET_IF_PARAM(params
, fast_hello
);
7388 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
7390 if (params
!= IF_DEF_PARAMS(ifp
)) {
7391 ospf_free_if_params(ifp
, addr
);
7392 ospf_if_update_params(ifp
, addr
);
7395 /* Update timer values in neighbor structure. */
7397 struct ospf
*ospf
= NULL
;
7399 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7401 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
7403 ospf_nbr_timer_update(oi
);
7406 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
7407 if ((oi
= rn
->info
))
7408 ospf_nbr_timer_update(oi
);
7414 DEFUN_HIDDEN (no_ospf_dead_interval
,
7415 no_ospf_dead_interval_cmd
,
7416 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
7418 "OSPF interface commands\n"
7419 "Interval time after which a neighbor is declared down\n"
7421 "Minimal 1s dead-interval with fast sub-second hellos\n"
7422 "Hello multiplier factor\n"
7423 "Number of Hellos to send each second\n"
7424 "Address of interface\n")
7426 return no_ip_ospf_dead_interval(self
, vty
, argc
, argv
);
7429 DEFUN (ip_ospf_hello_interval
,
7430 ip_ospf_hello_interval_cmd
,
7431 "ip ospf hello-interval (1-65535) [A.B.C.D]",
7433 "OSPF interface commands\n"
7434 "Time between HELLO packets\n"
7436 "Address of interface\n")
7438 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7440 struct in_addr addr
;
7441 struct ospf_if_params
*params
;
7442 params
= IF_DEF_PARAMS(ifp
);
7443 uint32_t seconds
= 0;
7445 argv_find(argv
, argc
, "(1-65535)", &idx
);
7446 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7448 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7449 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7451 "Please specify interface address by A.B.C.D\n");
7452 return CMD_WARNING_CONFIG_FAILED
;
7455 params
= ospf_get_if_params(ifp
, addr
);
7456 ospf_if_update_params(ifp
, addr
);
7459 SET_IF_PARAM(params
, v_hello
);
7460 params
->v_hello
= seconds
;
7465 DEFUN_HIDDEN (ospf_hello_interval
,
7466 ospf_hello_interval_cmd
,
7467 "ospf hello-interval (1-65535) [A.B.C.D]",
7468 "OSPF interface commands\n"
7469 "Time between HELLO packets\n"
7471 "Address of interface\n")
7473 return ip_ospf_hello_interval(self
, vty
, argc
, argv
);
7476 DEFUN (no_ip_ospf_hello_interval
,
7477 no_ip_ospf_hello_interval_cmd
,
7478 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
7481 "OSPF interface commands\n"
7482 "Time between HELLO packets\n" // ignored
7484 "Address of interface\n")
7486 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7488 struct in_addr addr
;
7489 struct ospf_if_params
*params
;
7491 params
= IF_DEF_PARAMS(ifp
);
7493 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7494 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7496 "Please specify interface address by A.B.C.D\n");
7497 return CMD_WARNING_CONFIG_FAILED
;
7500 params
= ospf_lookup_if_params(ifp
, addr
);
7505 UNSET_IF_PARAM(params
, v_hello
);
7506 params
->v_hello
= OSPF_HELLO_INTERVAL_DEFAULT
;
7508 if (params
!= IF_DEF_PARAMS(ifp
)) {
7509 ospf_free_if_params(ifp
, addr
);
7510 ospf_if_update_params(ifp
, addr
);
7516 DEFUN_HIDDEN (no_ospf_hello_interval
,
7517 no_ospf_hello_interval_cmd
,
7518 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
7520 "OSPF interface commands\n"
7521 "Time between HELLO packets\n" // ignored
7523 "Address of interface\n")
7525 return no_ip_ospf_hello_interval(self
, vty
, argc
, argv
);
7528 DEFUN (ip_ospf_network
,
7529 ip_ospf_network_cmd
,
7530 "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
7532 "OSPF interface commands\n"
7534 "Specify OSPF broadcast multi-access network\n"
7535 "Specify OSPF NBMA network\n"
7536 "Specify OSPF point-to-multipoint network\n"
7537 "Specify OSPF point-to-point network\n")
7539 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7541 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
7542 struct route_node
*rn
;
7544 if (old_type
== OSPF_IFTYPE_LOOPBACK
) {
7546 "This is a loopback interface. Can't set network type.\n");
7547 return CMD_WARNING_CONFIG_FAILED
;
7550 if (argv_find(argv
, argc
, "broadcast", &idx
))
7551 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_BROADCAST
;
7552 else if (argv_find(argv
, argc
, "non-broadcast", &idx
))
7553 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_NBMA
;
7554 else if (argv_find(argv
, argc
, "point-to-multipoint", &idx
))
7555 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOMULTIPOINT
;
7556 else if (argv_find(argv
, argc
, "point-to-point", &idx
))
7557 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOPOINT
;
7559 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
7562 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), type
);
7564 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7565 struct ospf_interface
*oi
= rn
->info
;
7570 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
7572 if (oi
->state
> ISM_Down
) {
7573 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
7574 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
7581 DEFUN_HIDDEN (ospf_network
,
7583 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
7584 "OSPF interface commands\n"
7586 "Specify OSPF broadcast multi-access network\n"
7587 "Specify OSPF NBMA network\n"
7588 "Specify OSPF point-to-multipoint network\n"
7589 "Specify OSPF point-to-point network\n")
7591 return ip_ospf_network(self
, vty
, argc
, argv
);
7594 DEFUN (no_ip_ospf_network
,
7595 no_ip_ospf_network_cmd
,
7596 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
7599 "OSPF interface commands\n"
7601 "Specify OSPF broadcast multi-access network\n"
7602 "Specify OSPF NBMA network\n"
7603 "Specify OSPF point-to-multipoint network\n"
7604 "Specify OSPF point-to-point network\n")
7606 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7607 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
7608 struct route_node
*rn
;
7610 IF_DEF_PARAMS(ifp
)->type
= ospf_default_iftype(ifp
);
7612 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
7615 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7616 struct ospf_interface
*oi
= rn
->info
;
7621 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
7623 if (oi
->state
> ISM_Down
) {
7624 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
7625 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
7632 DEFUN_HIDDEN (no_ospf_network
,
7633 no_ospf_network_cmd
,
7634 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
7636 "OSPF interface commands\n"
7638 "Specify OSPF broadcast multi-access network\n"
7639 "Specify OSPF NBMA network\n"
7640 "Specify OSPF point-to-multipoint network\n"
7641 "Specify OSPF point-to-point network\n")
7643 return no_ip_ospf_network(self
, vty
, argc
, argv
);
7646 DEFUN (ip_ospf_priority
,
7647 ip_ospf_priority_cmd
,
7648 "ip ospf priority (0-255) [A.B.C.D]",
7650 "OSPF interface commands\n"
7653 "Address of interface\n")
7655 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7658 struct route_node
*rn
;
7659 struct in_addr addr
;
7660 struct ospf_if_params
*params
;
7661 params
= IF_DEF_PARAMS(ifp
);
7663 argv_find(argv
, argc
, "(0-255)", &idx
);
7664 priority
= strtol(argv
[idx
]->arg
, NULL
, 10);
7666 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7667 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7669 "Please specify interface address by A.B.C.D\n");
7670 return CMD_WARNING_CONFIG_FAILED
;
7673 params
= ospf_get_if_params(ifp
, addr
);
7674 ospf_if_update_params(ifp
, addr
);
7677 SET_IF_PARAM(params
, priority
);
7678 params
->priority
= priority
;
7680 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7681 struct ospf_interface
*oi
= rn
->info
;
7686 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
7687 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
7688 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
7695 DEFUN_HIDDEN (ospf_priority
,
7697 "ospf priority (0-255) [A.B.C.D]",
7698 "OSPF interface commands\n"
7701 "Address of interface\n")
7703 return ip_ospf_priority(self
, vty
, argc
, argv
);
7706 DEFUN (no_ip_ospf_priority
,
7707 no_ip_ospf_priority_cmd
,
7708 "no ip ospf priority [(0-255) [A.B.C.D]]",
7711 "OSPF interface commands\n"
7712 "Router priority\n" // ignored
7714 "Address of interface\n")
7716 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7718 struct route_node
*rn
;
7719 struct in_addr addr
;
7720 struct ospf_if_params
*params
;
7722 params
= IF_DEF_PARAMS(ifp
);
7724 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7725 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7727 "Please specify interface address by A.B.C.D\n");
7728 return CMD_WARNING_CONFIG_FAILED
;
7731 params
= ospf_lookup_if_params(ifp
, addr
);
7736 UNSET_IF_PARAM(params
, priority
);
7737 params
->priority
= OSPF_ROUTER_PRIORITY_DEFAULT
;
7739 if (params
!= IF_DEF_PARAMS(ifp
)) {
7740 ospf_free_if_params(ifp
, addr
);
7741 ospf_if_update_params(ifp
, addr
);
7744 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7745 struct ospf_interface
*oi
= rn
->info
;
7750 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
7751 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
7752 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
7759 DEFUN_HIDDEN (no_ospf_priority
,
7760 no_ospf_priority_cmd
,
7761 "no ospf priority [(0-255) [A.B.C.D]]",
7763 "OSPF interface commands\n"
7766 "Address of interface\n")
7768 return no_ip_ospf_priority(self
, vty
, argc
, argv
);
7771 DEFUN (ip_ospf_retransmit_interval
,
7772 ip_ospf_retransmit_interval_addr_cmd
,
7773 "ip ospf retransmit-interval (3-65535) [A.B.C.D]",
7775 "OSPF interface commands\n"
7776 "Time between retransmitting lost link state advertisements\n"
7778 "Address of interface\n")
7780 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7783 struct in_addr addr
;
7784 struct ospf_if_params
*params
;
7785 params
= IF_DEF_PARAMS(ifp
);
7787 argv_find(argv
, argc
, "(3-65535)", &idx
);
7788 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7790 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7791 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7793 "Please specify interface address by A.B.C.D\n");
7794 return CMD_WARNING_CONFIG_FAILED
;
7797 params
= ospf_get_if_params(ifp
, addr
);
7798 ospf_if_update_params(ifp
, addr
);
7801 SET_IF_PARAM(params
, retransmit_interval
);
7802 params
->retransmit_interval
= seconds
;
7807 DEFUN_HIDDEN (ospf_retransmit_interval
,
7808 ospf_retransmit_interval_cmd
,
7809 "ospf retransmit-interval (3-65535) [A.B.C.D]",
7810 "OSPF interface commands\n"
7811 "Time between retransmitting lost link state advertisements\n"
7813 "Address of interface\n")
7815 return ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
7818 DEFUN (no_ip_ospf_retransmit_interval
,
7819 no_ip_ospf_retransmit_interval_addr_cmd
,
7820 "no ip ospf retransmit-interval [(3-65535)] [A.B.C.D]",
7823 "OSPF interface commands\n"
7824 "Time between retransmitting lost link state advertisements\n"
7826 "Address of interface\n")
7828 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7830 struct in_addr addr
;
7831 struct ospf_if_params
*params
;
7833 params
= IF_DEF_PARAMS(ifp
);
7835 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7836 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7838 "Please specify interface address by A.B.C.D\n");
7839 return CMD_WARNING_CONFIG_FAILED
;
7842 params
= ospf_lookup_if_params(ifp
, addr
);
7847 UNSET_IF_PARAM(params
, retransmit_interval
);
7848 params
->retransmit_interval
= OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
7850 if (params
!= IF_DEF_PARAMS(ifp
)) {
7851 ospf_free_if_params(ifp
, addr
);
7852 ospf_if_update_params(ifp
, addr
);
7858 DEFUN_HIDDEN (no_ospf_retransmit_interval
,
7859 no_ospf_retransmit_interval_cmd
,
7860 "no ospf retransmit-interval [(3-65535)] [A.B.C.D]",
7862 "OSPF interface commands\n"
7863 "Time between retransmitting lost link state advertisements\n"
7865 "Address of interface\n")
7867 return no_ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
7870 DEFUN (ip_ospf_transmit_delay
,
7871 ip_ospf_transmit_delay_addr_cmd
,
7872 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
7874 "OSPF interface commands\n"
7875 "Link state transmit delay\n"
7877 "Address of interface\n")
7879 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7882 struct in_addr addr
;
7883 struct ospf_if_params
*params
;
7885 params
= IF_DEF_PARAMS(ifp
);
7886 argv_find(argv
, argc
, "(1-65535)", &idx
);
7887 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7889 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7890 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7892 "Please specify interface address by A.B.C.D\n");
7893 return CMD_WARNING_CONFIG_FAILED
;
7896 params
= ospf_get_if_params(ifp
, addr
);
7897 ospf_if_update_params(ifp
, addr
);
7900 SET_IF_PARAM(params
, transmit_delay
);
7901 params
->transmit_delay
= seconds
;
7906 DEFUN_HIDDEN (ospf_transmit_delay
,
7907 ospf_transmit_delay_cmd
,
7908 "ospf transmit-delay (1-65535) [A.B.C.D]",
7909 "OSPF interface commands\n"
7910 "Link state transmit delay\n"
7912 "Address of interface\n")
7914 return ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
7917 DEFUN (no_ip_ospf_transmit_delay
,
7918 no_ip_ospf_transmit_delay_addr_cmd
,
7919 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
7922 "OSPF interface commands\n"
7923 "Link state transmit delay\n"
7925 "Address of interface\n")
7927 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7929 struct in_addr addr
;
7930 struct ospf_if_params
*params
;
7932 params
= IF_DEF_PARAMS(ifp
);
7934 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7935 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7937 "Please specify interface address by A.B.C.D\n");
7938 return CMD_WARNING_CONFIG_FAILED
;
7941 params
= ospf_lookup_if_params(ifp
, addr
);
7946 UNSET_IF_PARAM(params
, transmit_delay
);
7947 params
->transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
7949 if (params
!= IF_DEF_PARAMS(ifp
)) {
7950 ospf_free_if_params(ifp
, addr
);
7951 ospf_if_update_params(ifp
, addr
);
7958 DEFUN_HIDDEN (no_ospf_transmit_delay
,
7959 no_ospf_transmit_delay_cmd
,
7960 "no ospf transmit-delay [(1-65535) [A.B.C.D]]",
7962 "OSPF interface commands\n"
7963 "Link state transmit delay\n"
7965 "Address of interface\n")
7967 return no_ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
7970 DEFUN (ip_ospf_area
,
7972 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]",
7974 "OSPF interface commands\n"
7976 "Enable OSPF on this interface\n"
7977 "OSPF area ID in IP address format\n"
7978 "OSPF area ID as a decimal value\n"
7979 "Address of interface\n")
7981 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7984 struct in_addr area_id
;
7985 struct in_addr addr
;
7986 struct ospf_if_params
*params
= NULL
;
7987 struct route_node
*rn
;
7988 struct ospf
*ospf
= NULL
;
7989 unsigned short instance
= 0;
7992 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
7993 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
7995 argv_find(argv
, argc
, "area", &idx
);
7996 areaid
= argv
[idx
+ 1]->arg
;
7998 if (ifp
->vrf_id
&& !instance
)
7999 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
8001 ospf
= ospf_lookup_instance(instance
);
8003 if (instance
&& ospf
== NULL
) {
8004 params
= IF_DEF_PARAMS(ifp
);
8005 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8006 UNSET_IF_PARAM(params
, if_area
);
8007 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
8008 ospf_interface_area_unset(ospf
, ifp
);
8009 ospf
->if_ospf_cli_count
--;
8011 return CMD_NOT_MY_INSTANCE
;
8014 ret
= str2area_id(areaid
, &area_id
, &format
);
8016 vty_out(vty
, "Please specify area by A.B.C.D|<0-4294967295>\n");
8017 return CMD_WARNING_CONFIG_FAILED
;
8019 if (memcmp(ifp
->name
, "VLINK", 5) == 0) {
8020 vty_out(vty
, "Cannot enable OSPF on a virtual link.\n");
8021 return CMD_WARNING_CONFIG_FAILED
;
8024 params
= IF_DEF_PARAMS(ifp
);
8025 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)
8026 && !IPV4_ADDR_SAME(¶ms
->if_area
, &area_id
)) {
8028 "Must remove previous area config before changing ospf area \n");
8029 return CMD_WARNING_CONFIG_FAILED
;
8032 // Check if we have an address arg and proccess it
8033 if (argc
== idx
+ 3) {
8034 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
8036 "Please specify Intf Address by A.B.C.D\n");
8037 return CMD_WARNING_CONFIG_FAILED
;
8039 // update/create address-level params
8040 params
= ospf_get_if_params((ifp
), (addr
));
8041 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8043 "Must remove previous area/address config before changing ospf area");
8044 return CMD_WARNING_CONFIG_FAILED
;
8046 ospf_if_update_params((ifp
), (addr
));
8050 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
)) {
8051 if (rn
->info
!= NULL
) {
8053 "Please remove all network commands first.\n");
8054 return CMD_WARNING_CONFIG_FAILED
;
8059 /* enable ospf on this interface with area_id */
8061 SET_IF_PARAM(params
, if_area
);
8062 params
->if_area
= area_id
;
8063 params
->if_area_id_fmt
= format
;
8067 ospf_interface_area_set(ospf
, ifp
);
8068 ospf
->if_ospf_cli_count
++;
8074 DEFUN (no_ip_ospf_area
,
8075 no_ip_ospf_area_cmd
,
8076 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]",
8079 "OSPF interface commands\n"
8081 "Disable OSPF on this interface\n"
8082 "OSPF area ID in IP address format\n"
8083 "OSPF area ID as a decimal value\n"
8084 "Address of interface\n")
8086 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8089 struct ospf_if_params
*params
;
8090 unsigned short instance
= 0;
8091 struct in_addr addr
;
8093 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
8094 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
8096 if (ifp
->vrf_id
&& !instance
)
8097 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
8099 ospf
= ospf_lookup_instance(instance
);
8102 return CMD_NOT_MY_INSTANCE
;
8104 argv_find(argv
, argc
, "area", &idx
);
8106 // Check if we have an address arg and proccess it
8107 if (argc
== idx
+ 3) {
8108 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
8110 "Please specify Intf Address by A.B.C.D\n");
8111 return CMD_WARNING_CONFIG_FAILED
;
8113 params
= ospf_lookup_if_params(ifp
, addr
);
8114 if ((params
) == NULL
)
8117 params
= IF_DEF_PARAMS(ifp
);
8119 if (!OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8121 "Can't find specified interface area configuration.\n");
8122 return CMD_WARNING_CONFIG_FAILED
;
8125 UNSET_IF_PARAM(params
, if_area
);
8126 if (params
!= IF_DEF_PARAMS((ifp
))) {
8127 ospf_free_if_params((ifp
), (addr
));
8128 ospf_if_update_params((ifp
), (addr
));
8131 ospf_interface_area_unset(ospf
, ifp
);
8132 ospf
->if_ospf_cli_count
--;
8136 DEFUN (ospf_redistribute_source
,
8137 ospf_redistribute_source_cmd
,
8138 "redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8140 FRR_REDIST_HELP_STR_OSPFD
8141 "Metric for redistributed routes\n"
8142 "OSPF default metric\n"
8143 "OSPF exterior metric type for redistributed routes\n"
8144 "Set OSPF External Type 1/2 metrics\n"
8145 "Route map reference\n"
8146 "Pointer to route-map entries\n")
8148 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8149 int idx_protocol
= 1;
8153 struct ospf_redist
*red
;
8156 /* Get distribute source. */
8157 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
8159 return CMD_WARNING_CONFIG_FAILED
;
8161 red
= ospf_redist_add(ospf
, source
, 0);
8163 /* Get metric value. */
8164 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
8165 if (!str2metric(argv
[idx
]->arg
, &metric
))
8166 return CMD_WARNING_CONFIG_FAILED
;
8169 /* Get metric type. */
8170 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
8171 if (!str2metric_type(argv
[idx
]->arg
, &type
))
8172 return CMD_WARNING_CONFIG_FAILED
;
8176 if (argv_find(argv
, argc
, "WORD", &idx
)) {
8177 ospf_routemap_set(red
, argv
[idx
]->arg
);
8179 ospf_routemap_unset(red
);
8181 return ospf_redistribute_set(ospf
, source
, 0, type
, metric
);
8184 DEFUN (no_ospf_redistribute_source
,
8185 no_ospf_redistribute_source_cmd
,
8186 "no redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8189 FRR_REDIST_HELP_STR_OSPFD
8190 "Metric for redistributed routes\n"
8191 "OSPF default metric\n"
8192 "OSPF exterior metric type for redistributed routes\n"
8193 "Set OSPF External Type 1/2 metrics\n"
8194 "Route map reference\n"
8195 "Pointer to route-map entries\n")
8197 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8198 int idx_protocol
= 2;
8200 struct ospf_redist
*red
;
8202 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
8204 return CMD_WARNING_CONFIG_FAILED
;
8206 red
= ospf_redist_lookup(ospf
, source
, 0);
8210 ospf_routemap_unset(red
);
8211 ospf_redist_del(ospf
, source
, 0);
8213 return ospf_redistribute_unset(ospf
, source
, 0);
8216 DEFUN (ospf_redistribute_instance_source
,
8217 ospf_redistribute_instance_source_cmd
,
8218 "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8220 "Open Shortest Path First\n"
8221 "Non-main Kernel Routing Table\n"
8222 "Instance ID/Table ID\n"
8223 "Metric for redistributed routes\n"
8224 "OSPF default metric\n"
8225 "OSPF exterior metric type for redistributed routes\n"
8226 "Set OSPF External Type 1/2 metrics\n"
8227 "Route map reference\n"
8228 "Pointer to route-map entries\n")
8230 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8231 int idx_ospf_table
= 1;
8237 unsigned short instance
;
8238 struct ospf_redist
*red
;
8240 source
= proto_redistnum(AFI_IP
, argv
[idx_ospf_table
]->text
);
8243 vty_out(vty
, "Unknown instance redistribution\n");
8244 return CMD_WARNING_CONFIG_FAILED
;
8247 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8249 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
8251 "Instance redistribution in non-instanced OSPF not allowed\n");
8252 return CMD_WARNING_CONFIG_FAILED
;
8255 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
8256 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
8257 return CMD_WARNING_CONFIG_FAILED
;
8260 /* Get metric value. */
8261 if (argv_find(argv
, argc
, "metric", &idx
))
8262 if (!str2metric(argv
[idx
+ 1]->arg
, &metric
))
8263 return CMD_WARNING_CONFIG_FAILED
;
8266 /* Get metric type. */
8267 if (argv_find(argv
, argc
, "metric-type", &idx
))
8268 if (!str2metric_type(argv
[idx
+ 1]->arg
, &type
))
8269 return CMD_WARNING_CONFIG_FAILED
;
8271 red
= ospf_redist_add(ospf
, source
, instance
);
8274 if (argv_find(argv
, argc
, "route-map", &idx
))
8275 ospf_routemap_set(red
, argv
[idx
+ 1]->arg
);
8277 ospf_routemap_unset(red
);
8279 return ospf_redistribute_set(ospf
, source
, instance
, type
, metric
);
8282 DEFUN (no_ospf_redistribute_instance_source
,
8283 no_ospf_redistribute_instance_source_cmd
,
8284 "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8287 "Open Shortest Path First\n"
8288 "Non-main Kernel Routing Table\n"
8289 "Instance ID/Table Id\n"
8290 "Metric for redistributed routes\n"
8291 "OSPF default metric\n"
8292 "OSPF exterior metric type for redistributed routes\n"
8293 "Set OSPF External Type 1/2 metrics\n"
8294 "Route map reference\n"
8295 "Pointer to route-map entries\n")
8297 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8298 int idx_ospf_table
= 2;
8300 unsigned int instance
;
8301 struct ospf_redist
*red
;
8304 if (strncmp(argv
[idx_ospf_table
]->arg
, "o", 1) == 0)
8305 source
= ZEBRA_ROUTE_OSPF
;
8307 source
= ZEBRA_ROUTE_TABLE
;
8309 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8311 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
8313 "Instance redistribution in non-instanced OSPF not allowed\n");
8314 return CMD_WARNING_CONFIG_FAILED
;
8317 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
8318 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
8319 return CMD_WARNING_CONFIG_FAILED
;
8322 red
= ospf_redist_lookup(ospf
, source
, instance
);
8326 ospf_routemap_unset(red
);
8327 ospf_redist_del(ospf
, source
, instance
);
8329 return ospf_redistribute_unset(ospf
, source
, instance
);
8332 DEFUN (ospf_distribute_list_out
,
8333 ospf_distribute_list_out_cmd
,
8334 "distribute-list WORD out " FRR_REDIST_STR_OSPFD
,
8335 "Filter networks in routing updates\n"
8336 "Access-list name\n"
8338 FRR_REDIST_HELP_STR_OSPFD
)
8340 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8344 char *proto
= argv
[argc
- 1]->text
;
8346 /* Get distribute source. */
8347 source
= proto_redistnum(AFI_IP
, proto
);
8349 return CMD_WARNING_CONFIG_FAILED
;
8351 return ospf_distribute_list_out_set(ospf
, source
, argv
[idx_word
]->arg
);
8354 DEFUN (no_ospf_distribute_list_out
,
8355 no_ospf_distribute_list_out_cmd
,
8356 "no distribute-list WORD out " FRR_REDIST_STR_OSPFD
,
8358 "Filter networks in routing updates\n"
8359 "Access-list name\n"
8361 FRR_REDIST_HELP_STR_OSPFD
)
8363 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8367 char *proto
= argv
[argc
- 1]->text
;
8368 source
= proto_redistnum(AFI_IP
, proto
);
8370 return CMD_WARNING_CONFIG_FAILED
;
8372 return ospf_distribute_list_out_unset(ospf
, source
,
8373 argv
[idx_word
]->arg
);
8376 /* Default information originate. */
8377 DEFUN (ospf_default_information_originate
,
8378 ospf_default_information_originate_cmd
,
8379 "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8380 "Control distribution of default information\n"
8381 "Distribute a default route\n"
8382 "Always advertise default route\n"
8383 "OSPF default metric\n"
8385 "OSPF metric type for default routes\n"
8386 "Set OSPF External Type 1/2 metrics\n"
8387 "Route map reference\n"
8388 "Pointer to route-map entries\n")
8390 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8391 int default_originate
= DEFAULT_ORIGINATE_ZEBRA
;
8394 struct ospf_redist
*red
;
8396 int cur_originate
= ospf
->default_originate
;
8400 red
= ospf_redist_add(ospf
, DEFAULT_ROUTE
, 0);
8402 /* Check whether "always" was specified */
8403 if (argv_find(argv
, argc
, "always", &idx
))
8404 default_originate
= DEFAULT_ORIGINATE_ALWAYS
;
8406 /* Get metric value */
8407 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
8408 if (!str2metric(argv
[idx
]->arg
, &metric
))
8409 return CMD_WARNING_CONFIG_FAILED
;
8412 /* Get metric type. */
8413 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
8414 if (!str2metric_type(argv
[idx
]->arg
, &type
))
8415 return CMD_WARNING_CONFIG_FAILED
;
8419 if (argv_find(argv
, argc
, "WORD", &idx
))
8420 rtmap
= argv
[idx
]->arg
;
8422 /* To check ,if user is providing same route map */
8423 if ((rtmap
== ROUTEMAP_NAME(red
)) ||
8424 (rtmap
&& ROUTEMAP_NAME(red
)
8425 && (strcmp(rtmap
, ROUTEMAP_NAME(red
)) == 0)))
8428 /* Don't allow if the same lsa is aleardy originated. */
8430 && (red
->dmetric
.type
== type
)
8431 && (red
->dmetric
.value
== metric
)
8432 && (cur_originate
== default_originate
))
8435 /* Updating Metric details */
8436 red
->dmetric
.type
= type
;
8437 red
->dmetric
.value
= metric
;
8439 /* updating route map details */
8441 ospf_routemap_set(red
, rtmap
);
8443 ospf_routemap_unset(red
);
8445 return ospf_redistribute_default_set(ospf
, default_originate
, type
,
8449 DEFUN (no_ospf_default_information_originate
,
8450 no_ospf_default_information_originate_cmd
,
8451 "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8453 "Control distribution of default information\n"
8454 "Distribute a default route\n"
8455 "Always advertise default route\n"
8456 "OSPF default metric\n"
8458 "OSPF metric type for default routes\n"
8459 "Set OSPF External Type 1/2 metrics\n"
8460 "Route map reference\n"
8461 "Pointer to route-map entries\n")
8463 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8464 struct prefix_ipv4 p
;
8465 struct ospf_external
*ext
;
8466 struct ospf_redist
*red
;
8469 p
.prefix
.s_addr
= 0;
8472 ospf_external_lsa_flush(ospf
, DEFAULT_ROUTE
, &p
, 0);
8474 ext
= ospf_external_lookup(ospf
, DEFAULT_ROUTE
, 0);
8475 if (ext
&& EXTERNAL_INFO(ext
)) {
8476 ospf_external_info_delete(ospf
, DEFAULT_ROUTE
, 0, p
);
8477 ospf_external_del(ospf
, DEFAULT_ROUTE
, 0);
8480 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
8484 ospf_routemap_unset(red
);
8485 ospf_redist_del(ospf
, DEFAULT_ROUTE
, 0);
8487 return ospf_redistribute_default_unset(ospf
);
8490 DEFUN (ospf_default_metric
,
8491 ospf_default_metric_cmd
,
8492 "default-metric (0-16777214)",
8493 "Set metric of redistributed routes\n"
8496 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8500 if (!str2metric(argv
[idx_number
]->arg
, &metric
))
8501 return CMD_WARNING_CONFIG_FAILED
;
8503 ospf
->default_metric
= metric
;
8508 DEFUN (no_ospf_default_metric
,
8509 no_ospf_default_metric_cmd
,
8510 "no default-metric [(0-16777214)]",
8512 "Set metric of redistributed routes\n"
8515 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8517 ospf
->default_metric
= -1;
8523 DEFUN (ospf_distance
,
8526 "Administrative distance\n"
8527 "OSPF Administrative distance\n")
8529 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8532 ospf
->distance_all
= atoi(argv
[idx_number
]->arg
);
8537 DEFUN (no_ospf_distance
,
8538 no_ospf_distance_cmd
,
8539 "no distance (1-255)",
8541 "Administrative distance\n"
8542 "OSPF Administrative distance\n")
8544 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8546 ospf
->distance_all
= 0;
8551 DEFUN (no_ospf_distance_ospf
,
8552 no_ospf_distance_ospf_cmd
,
8553 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
8555 "Administrative distance\n"
8556 "OSPF administrative distance\n"
8557 "Intra-area routes\n"
8558 "Distance for intra-area routes\n"
8559 "Inter-area routes\n"
8560 "Distance for inter-area routes\n"
8562 "Distance for external routes\n")
8564 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8567 if (argv_find(argv
, argc
, "intra-area", &idx
) || argc
== 3)
8568 idx
= ospf
->distance_intra
= 0;
8569 if (argv_find(argv
, argc
, "inter-area", &idx
) || argc
== 3)
8570 idx
= ospf
->distance_inter
= 0;
8571 if (argv_find(argv
, argc
, "external", &idx
) || argc
== 3)
8572 ospf
->distance_external
= 0;
8577 DEFUN (ospf_distance_ospf
,
8578 ospf_distance_ospf_cmd
,
8579 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
8580 "Administrative distance\n"
8581 "OSPF administrative distance\n"
8582 "Intra-area routes\n"
8583 "Distance for intra-area routes\n"
8584 "Inter-area routes\n"
8585 "Distance for inter-area routes\n"
8587 "Distance for external routes\n")
8589 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8592 ospf
->distance_intra
= 0;
8593 ospf
->distance_inter
= 0;
8594 ospf
->distance_external
= 0;
8596 if (argv_find(argv
, argc
, "intra-area", &idx
))
8597 ospf
->distance_intra
= atoi(argv
[idx
+ 1]->arg
);
8599 if (argv_find(argv
, argc
, "inter-area", &idx
))
8600 ospf
->distance_inter
= atoi(argv
[idx
+ 1]->arg
);
8602 if (argv_find(argv
, argc
, "external", &idx
))
8603 ospf
->distance_external
= atoi(argv
[idx
+ 1]->arg
);
8609 DEFUN (ospf_distance_source
,
8610 ospf_distance_source_cmd
,
8611 "distance (1-255) A.B.C.D/M",
8612 "Administrative distance\n"
8614 "IP source prefix\n")
8616 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8618 int idx_ipv4_prefixlen
= 2;
8620 ospf_distance_set (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
8625 DEFUN (no_ospf_distance_source
,
8626 no_ospf_distance_source_cmd
,
8627 "no distance (1-255) A.B.C.D/M",
8629 "Administrative distance\n"
8631 "IP source prefix\n")
8633 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8635 int idx_ipv4_prefixlen
= 3;
8637 ospf_distance_unset (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
8642 DEFUN (ospf_distance_source_access_list
,
8643 ospf_distance_source_access_list_cmd
,
8644 "distance (1-255) A.B.C.D/M WORD",
8645 "Administrative distance\n"
8647 "IP source prefix\n"
8648 "Access list name\n")
8650 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8652 int idx_ipv4_prefixlen
= 2;
8655 ospf_distance_set (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
8660 DEFUN (no_ospf_distance_source_access_list
,
8661 no_ospf_distance_source_access_list_cmd
,
8662 "no distance (1-255) A.B.C.D/M WORD",
8664 "Administrative distance\n"
8666 "IP source prefix\n"
8667 "Access list name\n")
8669 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8671 int idx_ipv4_prefixlen
= 3;
8674 ospf_distance_unset (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
8680 DEFUN (ip_ospf_mtu_ignore
,
8681 ip_ospf_mtu_ignore_addr_cmd
,
8682 "ip ospf mtu-ignore [A.B.C.D]",
8684 "OSPF interface commands\n"
8685 "Disable MTU mismatch detection on this interface\n"
8686 "Address of interface\n")
8688 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8690 struct in_addr addr
;
8693 struct ospf_if_params
*params
;
8694 params
= IF_DEF_PARAMS(ifp
);
8697 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8700 "Please specify interface address by A.B.C.D\n");
8701 return CMD_WARNING_CONFIG_FAILED
;
8703 params
= ospf_get_if_params(ifp
, addr
);
8704 ospf_if_update_params(ifp
, addr
);
8706 params
->mtu_ignore
= 1;
8707 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
8708 SET_IF_PARAM(params
, mtu_ignore
);
8710 UNSET_IF_PARAM(params
, mtu_ignore
);
8711 if (params
!= IF_DEF_PARAMS(ifp
)) {
8712 ospf_free_if_params(ifp
, addr
);
8713 ospf_if_update_params(ifp
, addr
);
8719 DEFUN (no_ip_ospf_mtu_ignore
,
8720 no_ip_ospf_mtu_ignore_addr_cmd
,
8721 "no ip ospf mtu-ignore [A.B.C.D]",
8724 "OSPF interface commands\n"
8725 "Disable MTU mismatch detection on this interface\n"
8726 "Address of interface\n")
8728 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8730 struct in_addr addr
;
8733 struct ospf_if_params
*params
;
8734 params
= IF_DEF_PARAMS(ifp
);
8737 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8740 "Please specify interface address by A.B.C.D\n");
8741 return CMD_WARNING_CONFIG_FAILED
;
8743 params
= ospf_get_if_params(ifp
, addr
);
8744 ospf_if_update_params(ifp
, addr
);
8746 params
->mtu_ignore
= 0;
8747 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
8748 SET_IF_PARAM(params
, mtu_ignore
);
8750 UNSET_IF_PARAM(params
, mtu_ignore
);
8751 if (params
!= IF_DEF_PARAMS(ifp
)) {
8752 ospf_free_if_params(ifp
, addr
);
8753 ospf_if_update_params(ifp
, addr
);
8760 DEFUN (ospf_max_metric_router_lsa_admin
,
8761 ospf_max_metric_router_lsa_admin_cmd
,
8762 "max-metric router-lsa administrative",
8763 "OSPF maximum / infinite-distance metric\n"
8764 "Advertise own Router-LSA with infinite distance (stub router)\n"
8765 "Administratively applied, for an indefinite period\n")
8767 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8768 struct listnode
*ln
;
8769 struct ospf_area
*area
;
8771 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8772 SET_FLAG(area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
);
8774 if (!CHECK_FLAG(area
->stub_router_state
,
8775 OSPF_AREA_IS_STUB_ROUTED
))
8776 ospf_router_lsa_update_area(area
);
8779 /* Allows for areas configured later to get the property */
8780 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
;
8785 DEFUN (no_ospf_max_metric_router_lsa_admin
,
8786 no_ospf_max_metric_router_lsa_admin_cmd
,
8787 "no max-metric router-lsa administrative",
8789 "OSPF maximum / infinite-distance metric\n"
8790 "Advertise own Router-LSA with infinite distance (stub router)\n"
8791 "Administratively applied, for an indefinite period\n")
8793 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8794 struct listnode
*ln
;
8795 struct ospf_area
*area
;
8797 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8798 UNSET_FLAG(area
->stub_router_state
,
8799 OSPF_AREA_ADMIN_STUB_ROUTED
);
8801 /* Don't trample on the start-up stub timer */
8802 if (CHECK_FLAG(area
->stub_router_state
,
8803 OSPF_AREA_IS_STUB_ROUTED
)
8804 && !area
->t_stub_router
) {
8805 UNSET_FLAG(area
->stub_router_state
,
8806 OSPF_AREA_IS_STUB_ROUTED
);
8807 ospf_router_lsa_update_area(area
);
8810 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET
;
8814 DEFUN (ospf_max_metric_router_lsa_startup
,
8815 ospf_max_metric_router_lsa_startup_cmd
,
8816 "max-metric router-lsa on-startup (5-86400)",
8817 "OSPF maximum / infinite-distance metric\n"
8818 "Advertise own Router-LSA with infinite distance (stub router)\n"
8819 "Automatically advertise stub Router-LSA on startup of OSPF\n"
8820 "Time (seconds) to advertise self as stub-router\n")
8822 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8824 unsigned int seconds
;
8827 vty_out(vty
, "%% Must supply stub-router period");
8828 return CMD_WARNING_CONFIG_FAILED
;
8831 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8833 ospf
->stub_router_startup_time
= seconds
;
8838 DEFUN (no_ospf_max_metric_router_lsa_startup
,
8839 no_ospf_max_metric_router_lsa_startup_cmd
,
8840 "no max-metric router-lsa on-startup [(5-86400)]",
8842 "OSPF maximum / infinite-distance metric\n"
8843 "Advertise own Router-LSA with infinite distance (stub router)\n"
8844 "Automatically advertise stub Router-LSA on startup of OSPF\n"
8845 "Time (seconds) to advertise self as stub-router\n")
8847 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8848 struct listnode
*ln
;
8849 struct ospf_area
*area
;
8851 ospf
->stub_router_startup_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
8853 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8854 SET_FLAG(area
->stub_router_state
,
8855 OSPF_AREA_WAS_START_STUB_ROUTED
);
8856 OSPF_TIMER_OFF(area
->t_stub_router
);
8858 /* Don't trample on admin stub routed */
8859 if (!CHECK_FLAG(area
->stub_router_state
,
8860 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
8861 UNSET_FLAG(area
->stub_router_state
,
8862 OSPF_AREA_IS_STUB_ROUTED
);
8863 ospf_router_lsa_update_area(area
);
8870 DEFUN (ospf_max_metric_router_lsa_shutdown
,
8871 ospf_max_metric_router_lsa_shutdown_cmd
,
8872 "max-metric router-lsa on-shutdown (5-100)",
8873 "OSPF maximum / infinite-distance metric\n"
8874 "Advertise own Router-LSA with infinite distance (stub router)\n"
8875 "Advertise stub-router prior to full shutdown of OSPF\n"
8876 "Time (seconds) to wait till full shutdown\n")
8878 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8880 unsigned int seconds
;
8883 vty_out(vty
, "%% Must supply stub-router shutdown period");
8884 return CMD_WARNING_CONFIG_FAILED
;
8887 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8889 ospf
->stub_router_shutdown_time
= seconds
;
8894 DEFUN (no_ospf_max_metric_router_lsa_shutdown
,
8895 no_ospf_max_metric_router_lsa_shutdown_cmd
,
8896 "no max-metric router-lsa on-shutdown [(5-100)]",
8898 "OSPF maximum / infinite-distance metric\n"
8899 "Advertise own Router-LSA with infinite distance (stub router)\n"
8900 "Advertise stub-router prior to full shutdown of OSPF\n"
8901 "Time (seconds) to wait till full shutdown\n")
8903 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8905 ospf
->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
8910 static void config_write_stub_router(struct vty
*vty
, struct ospf
*ospf
)
8912 struct listnode
*ln
;
8913 struct ospf_area
*area
;
8915 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
8916 vty_out(vty
, " max-metric router-lsa on-startup %u\n",
8917 ospf
->stub_router_startup_time
);
8918 if (ospf
->stub_router_shutdown_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
8919 vty_out(vty
, " max-metric router-lsa on-shutdown %u\n",
8920 ospf
->stub_router_shutdown_time
);
8921 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8922 if (CHECK_FLAG(area
->stub_router_state
,
8923 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
8924 vty_out(vty
, " max-metric router-lsa administrative\n");
8931 static void show_ip_ospf_route_network(struct vty
*vty
, struct ospf
*ospf
,
8932 struct route_table
*rt
,
8935 struct route_node
*rn
;
8936 struct ospf_route
* or ;
8937 struct listnode
*pnode
, *pnnode
;
8938 struct ospf_path
*path
;
8939 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
8940 *json_nexthop
= NULL
;
8944 "============ OSPF network routing table ============\n");
8946 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
8947 if ((or = rn
->info
) == NULL
)
8949 char buf1
[PREFIX2STR_BUFFER
];
8951 memset(buf1
, 0, sizeof(buf1
));
8952 prefix2str(&rn
->p
, buf1
, sizeof(buf1
));
8954 json_route
= json_object_new_object();
8956 json_object_object_add(json
, buf1
, json_route
);
8957 json_object_to_json_string_ext(
8958 json
, JSON_C_TO_STRING_NOSLASHESCAPE
);
8961 switch (or->path_type
) {
8962 case OSPF_PATH_INTER_AREA
:
8963 if (or->type
== OSPF_DESTINATION_NETWORK
) {
8965 json_object_string_add(json_route
,
8968 json_object_int_add(json_route
, "cost",
8970 json_object_string_add(
8972 inet_ntoa(or->u
.std
.area_id
));
8975 "N IA %-18s [%d] area: %s\n",
8977 inet_ntoa(or->u
.std
.area_id
));
8979 } else if (or->type
== OSPF_DESTINATION_DISCARD
) {
8981 json_object_string_add(json_route
,
8986 "D IA %-18s Discard entry\n",
8991 case OSPF_PATH_INTRA_AREA
:
8993 json_object_string_add(json_route
, "routeType",
8995 json_object_int_add(json_route
, "cost",
8997 json_object_string_add(
8999 inet_ntoa(or->u
.std
.area_id
));
9001 vty_out(vty
, "N %-18s [%d] area: %s\n",
9003 inet_ntoa(or->u
.std
.area_id
));
9010 if (or->type
== OSPF_DESTINATION_NETWORK
) {
9012 json_nexthop_array
= json_object_new_array();
9013 json_object_object_add(json_route
, "nexthops",
9014 json_nexthop_array
);
9017 for (ALL_LIST_ELEMENTS(or->paths
, pnode
, pnnode
,
9020 json_nexthop
= json_object_new_object();
9021 json_object_array_add(
9025 if (if_lookup_by_index(path
->ifindex
,
9028 if (path
->nexthop
.s_addr
== 0) {
9030 json_object_string_add(
9033 json_object_string_add(
9035 "directly attached to",
9041 "%24s directly attached to %s\n",
9049 json_object_string_add(
9054 json_object_string_add(
9062 "%24s via %s, %s\n",
9075 json_object_free(json_route
);
9081 static void show_ip_ospf_route_router(struct vty
*vty
, struct ospf
*ospf
,
9082 struct route_table
*rtrs
,
9085 struct route_node
*rn
;
9086 struct ospf_route
* or ;
9087 struct listnode
*pnode
;
9088 struct listnode
*node
;
9089 struct ospf_path
*path
;
9090 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
9091 *json_nexthop
= NULL
;
9095 "============ OSPF router routing table =============\n");
9097 for (rn
= route_top(rtrs
); rn
; rn
= route_next(rn
)) {
9098 if (rn
->info
== NULL
)
9102 json_route
= json_object_new_object();
9104 json_object_object_add(json
, inet_ntoa(rn
->p
.u
.prefix4
),
9106 json_object_string_add(json_route
, "routeType", "R ");
9108 vty_out(vty
, "R %-15s ",
9109 inet_ntoa(rn
->p
.u
.prefix4
));
9112 for (ALL_LIST_ELEMENTS_RO((struct list
*)rn
->info
, node
, or)) {
9115 vty_out(vty
, "%24s", "");
9120 json_object_int_add(json_route
, "cost",
9122 json_object_string_add(
9124 inet_ntoa(or->u
.std
.area_id
));
9125 if (or->path_type
== OSPF_PATH_INTER_AREA
)
9126 json_object_boolean_true_add(json_route
,
9128 if (or->u
.std
.flags
& ROUTER_LSA_BORDER
)
9129 json_object_string_add(json_route
,
9132 else if (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
)
9133 json_object_string_add(json_route
,
9137 vty_out(vty
, "%s [%d] area: %s",
9138 (or->path_type
== OSPF_PATH_INTER_AREA
9141 or->cost
, inet_ntoa(or->u
.std
.area_id
));
9143 vty_out(vty
, "%s%s\n",
9144 (or->u
.std
.flags
& ROUTER_LSA_BORDER
9147 (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
9153 json_nexthop_array
= json_object_new_array();
9154 json_object_object_add(json_route
, "nexthops",
9155 json_nexthop_array
);
9158 for (ALL_LIST_ELEMENTS_RO(or->paths
, pnode
, path
)) {
9160 json_nexthop
= json_object_new_object();
9161 json_object_array_add(
9165 if (if_lookup_by_index(path
->ifindex
,
9167 if (path
->nexthop
.s_addr
== 0) {
9169 json_object_string_add(
9172 json_object_string_add(
9174 "directly attached to",
9180 "%24s directly attached to %s\n",
9188 json_object_string_add(
9193 json_object_string_add(
9201 "%24s via %s, %s\n",
9214 json_object_free(json_route
);
9220 static void show_ip_ospf_route_external(struct vty
*vty
, struct ospf
*ospf
,
9221 struct route_table
*rt
,
9224 struct route_node
*rn
;
9225 struct ospf_route
*er
;
9226 struct listnode
*pnode
, *pnnode
;
9227 struct ospf_path
*path
;
9228 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
9229 *json_nexthop
= NULL
;
9233 "============ OSPF external routing table ===========\n");
9235 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
9236 if ((er
= rn
->info
) == NULL
)
9241 snprintf(buf1
, 19, "%s/%d", inet_ntoa(rn
->p
.u
.prefix4
),
9243 json_route
= json_object_new_object();
9245 json_object_object_add(json
, buf1
, json_route
);
9246 json_object_to_json_string_ext(
9247 json
, JSON_C_TO_STRING_NOSLASHESCAPE
);
9250 switch (er
->path_type
) {
9251 case OSPF_PATH_TYPE1_EXTERNAL
:
9253 json_object_string_add(json_route
, "routeType",
9255 json_object_int_add(json_route
, "cost",
9259 "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI
9261 buf1
, er
->cost
, er
->u
.ext
.tag
);
9264 case OSPF_PATH_TYPE2_EXTERNAL
:
9266 json_object_string_add(json_route
, "routeType",
9268 json_object_int_add(json_route
, "cost",
9272 "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI
9274 buf1
, er
->cost
, er
->u
.ext
.type2_cost
,
9281 json_nexthop_array
= json_object_new_array();
9282 json_object_object_add(json_route
, "nexthops",
9283 json_nexthop_array
);
9286 for (ALL_LIST_ELEMENTS(er
->paths
, pnode
, pnnode
, path
)) {
9288 json_nexthop
= json_object_new_object();
9289 json_object_array_add(json_nexthop_array
,
9293 if (if_lookup_by_index(path
->ifindex
, ospf
->vrf_id
)) {
9294 if (path
->nexthop
.s_addr
== 0) {
9296 json_object_string_add(
9299 json_object_string_add(
9301 "directly attached to",
9307 "%24s directly attached to %s\n",
9315 json_object_string_add(
9319 json_object_string_add(
9320 json_nexthop
, "via",
9326 "%24s via %s, %s\n",
9338 json_object_free(json_route
);
9344 static int show_ip_ospf_border_routers_common(struct vty
*vty
,
9349 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
9351 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
9353 if (ospf
->new_table
== NULL
) {
9354 vty_out(vty
, "No OSPF routing information exist\n");
9358 /* Show Network routes.
9359 show_ip_ospf_route_network (vty, ospf->new_table); */
9361 /* Show Router routes. */
9362 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, NULL
);
9369 DEFUN (show_ip_ospf_border_routers
,
9370 show_ip_ospf_border_routers_cmd
,
9371 "show ip ospf [vrf <NAME|all>] border-routers",
9374 "OSPF information\n"
9377 "Show all the ABR's and ASBR's\n")
9379 struct ospf
*ospf
= NULL
;
9380 struct listnode
*node
= NULL
;
9381 char *vrf_name
= NULL
;
9382 bool all_vrf
= FALSE
;
9383 int ret
= CMD_SUCCESS
;
9386 uint8_t use_vrf
= 0;
9388 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
9391 bool ospf_output
= FALSE
;
9396 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9397 if (!ospf
->oi_running
)
9401 ret
= show_ip_ospf_border_routers_common(
9402 vty
, ospf
, use_vrf
);
9406 vty_out(vty
, "%% OSPF instance not found\n");
9408 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
9409 if (ospf
== NULL
|| !ospf
->oi_running
) {
9410 vty_out(vty
, "%% OSPF instance not found\n");
9414 ret
= show_ip_ospf_border_routers_common(vty
, ospf
,
9418 /* Display default ospf (instance 0) info */
9419 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
9420 if (ospf
== NULL
|| !ospf
->oi_running
) {
9421 vty_out(vty
, "%% OSPF instance not found\n");
9425 ret
= show_ip_ospf_border_routers_common(vty
, ospf
, use_vrf
);
9431 DEFUN (show_ip_ospf_instance_border_routers
,
9432 show_ip_ospf_instance_border_routers_cmd
,
9433 "show ip ospf (1-65535) border-routers",
9436 "OSPF information\n"
9438 "Show all the ABR's and ASBR's\n")
9442 unsigned short instance
= 0;
9444 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9445 ospf
= ospf_lookup_instance(instance
);
9447 return CMD_NOT_MY_INSTANCE
;
9449 if (!ospf
->oi_running
)
9452 return show_ip_ospf_border_routers_common(vty
, ospf
, 0);
9455 static int show_ip_ospf_route_common(struct vty
*vty
, struct ospf
*ospf
,
9456 json_object
*json
, uint8_t use_vrf
)
9458 json_object
*json_vrf
= NULL
;
9461 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
9466 json_vrf
= json_object_new_object();
9471 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
9473 if (ospf
->new_table
== NULL
) {
9474 vty_out(vty
, "No OSPF routing information exist\n");
9478 /* Show Network routes. */
9479 show_ip_ospf_route_network(vty
, ospf
, ospf
->new_table
, json_vrf
);
9481 /* Show Router routes. */
9482 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, json_vrf
);
9484 /* Show AS External routes. */
9485 show_ip_ospf_route_external(vty
, ospf
, ospf
->old_external_route
,
9490 // json_object_object_add(json_vrf, "areas",
9492 if (ospf
->vrf_id
== VRF_DEFAULT
)
9493 json_object_object_add(json
, "default",
9496 json_object_object_add(json
, ospf
->name
,
9506 DEFUN (show_ip_ospf_route
,
9507 show_ip_ospf_route_cmd
,
9508 "show ip ospf [vrf <NAME|all>] route [json]",
9511 "OSPF information\n"
9514 "OSPF routing table\n"
9517 struct ospf
*ospf
= NULL
;
9518 struct listnode
*node
= NULL
;
9519 char *vrf_name
= NULL
;
9520 bool all_vrf
= FALSE
;
9521 int ret
= CMD_SUCCESS
;
9524 uint8_t use_vrf
= 0;
9525 bool uj
= use_json(argc
, argv
);
9526 json_object
*json
= NULL
;
9529 json
= json_object_new_object();
9531 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
9533 /* vrf input is provided could be all or specific vrf*/
9535 bool ospf_output
= FALSE
;
9540 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9541 if (!ospf
->oi_running
)
9544 ret
= show_ip_ospf_route_common(vty
, ospf
, json
,
9549 /* Keep Non-pretty format */
9550 vty_out(vty
, "%s\n",
9551 json_object_to_json_string(json
));
9552 json_object_free(json
);
9553 } else if (!ospf_output
)
9554 vty_out(vty
, "%% OSPF instance not found\n");
9558 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
9559 if (ospf
== NULL
|| !ospf
->oi_running
) {
9561 vty_out(vty
, "%s\n",
9562 json_object_to_json_string_ext(
9563 json
, JSON_C_TO_STRING_PRETTY
));
9564 json_object_free(json
);
9566 vty_out(vty
, "%% OSPF instance not found\n");
9571 /* Display default ospf (instance 0) info */
9572 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
9573 if (ospf
== NULL
|| !ospf
->oi_running
) {
9575 vty_out(vty
, "%s\n",
9576 json_object_to_json_string_ext(
9577 json
, JSON_C_TO_STRING_PRETTY
));
9578 json_object_free(json
);
9580 vty_out(vty
, "%% OSPF instance not found\n");
9587 ret
= show_ip_ospf_route_common(vty
, ospf
, json
, use_vrf
);
9588 /* Keep Non-pretty format */
9590 vty_out(vty
, "%s\n", json_object_to_json_string(json
));
9594 json_object_free(json
);
9599 DEFUN (show_ip_ospf_instance_route
,
9600 show_ip_ospf_instance_route_cmd
,
9601 "show ip ospf (1-65535) route",
9604 "OSPF information\n"
9606 "OSPF routing table\n")
9610 unsigned short instance
= 0;
9612 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9613 ospf
= ospf_lookup_instance(instance
);
9615 return CMD_NOT_MY_INSTANCE
;
9617 if (!ospf
->oi_running
)
9620 return show_ip_ospf_route_common(vty
, ospf
, NULL
, 0);
9624 DEFUN (show_ip_ospf_vrfs
,
9625 show_ip_ospf_vrfs_cmd
,
9626 "show ip ospf vrfs [json]",
9629 "OSPF information\n"
9633 bool uj
= use_json(argc
, argv
);
9634 json_object
*json
= NULL
;
9635 json_object
*json_vrfs
= NULL
;
9636 struct ospf
*ospf
= NULL
;
9637 struct listnode
*node
= NULL
;
9639 static char header
[] = "Name Id RouterId ";
9642 json
= json_object_new_object();
9643 json_vrfs
= json_object_new_object();
9646 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9647 json_object
*json_vrf
= NULL
;
9648 const char *name
= NULL
;
9649 int64_t vrf_id_ui
= 0;
9653 if (!uj
&& count
== 1)
9654 vty_out(vty
, "%s\n", header
);
9656 json_vrf
= json_object_new_object();
9658 if (ospf
->vrf_id
== 0)
9659 name
= VRF_DEFAULT_NAME
;
9663 vrf_id_ui
= (ospf
->vrf_id
== VRF_UNKNOWN
)
9665 : (int64_t)ospf
->vrf_id
;
9668 json_object_int_add(json_vrf
, "vrfId", vrf_id_ui
);
9669 json_object_string_add(json_vrf
, "routerId",
9670 inet_ntoa(ospf
->router_id
));
9672 json_object_object_add(json_vrfs
, name
, json_vrf
);
9675 vty_out(vty
, "%-25s %-5d %-16s \n", name
,
9676 ospf
->vrf_id
, inet_ntoa(ospf
->router_id
));
9681 json_object_object_add(json
, "vrfs", json_vrfs
);
9682 json_object_int_add(json
, "totalVrfs", count
);
9684 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
9685 json
, JSON_C_TO_STRING_PRETTY
));
9686 json_object_free(json
);
9689 vty_out(vty
, "\nTotal number of OSPF VRFs: %d\n",
9696 const char *ospf_abr_type_str
[] = {"unknown", "standard", "ibm", "cisco",
9699 const char *ospf_shortcut_mode_str
[] = {"default", "enable", "disable"};
9701 const char *ospf_int_type_str
[] = {"unknown", /* should never be used. */
9702 "point-to-point", "broadcast",
9703 "non-broadcast", "point-to-multipoint",
9704 "virtual-link", /* should never be used. */
9707 static int config_write_interface_one(struct vty
*vty
, struct vrf
*vrf
)
9709 struct listnode
*node
;
9710 struct interface
*ifp
;
9711 struct crypt_key
*ck
;
9712 struct route_node
*rn
= NULL
;
9713 struct ospf_if_params
*params
;
9715 struct ospf
*ospf
= vrf
->info
;
9717 FOR_ALL_INTERFACES (vrf
, ifp
) {
9719 if (memcmp(ifp
->name
, "VLINK", 5) == 0)
9722 vty_frame(vty
, "!\n");
9723 if (ifp
->vrf_id
== VRF_DEFAULT
)
9724 vty_frame(vty
, "interface %s\n", ifp
->name
);
9726 vty_frame(vty
, "interface %s vrf %s\n", ifp
->name
,
9729 vty_out(vty
, " description %s\n", ifp
->desc
);
9733 params
= IF_DEF_PARAMS(ifp
);
9736 /* Interface Network print. */
9737 if (OSPF_IF_PARAM_CONFIGURED(params
, type
)
9738 && params
->type
!= OSPF_IFTYPE_LOOPBACK
) {
9739 if (params
->type
!= ospf_default_iftype(ifp
)) {
9740 vty_out(vty
, " ip ospf network %s",
9743 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9751 /* OSPF interface authentication print */
9752 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_type
)
9753 && params
->auth_type
!= OSPF_AUTH_NOTSET
) {
9754 const char *auth_str
;
9756 /* Translation tables are not that much help
9757 * here due to syntax
9758 * of the simple option */
9759 switch (params
->auth_type
) {
9761 case OSPF_AUTH_NULL
:
9765 case OSPF_AUTH_SIMPLE
:
9769 case OSPF_AUTH_CRYPTOGRAPHIC
:
9770 auth_str
= " message-digest";
9778 vty_out(vty
, " ip ospf authentication%s",
9780 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9782 inet_ntoa(rn
->p
.u
.prefix4
));
9786 /* Simple Authentication Password print. */
9787 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_simple
)
9788 && params
->auth_simple
[0] != '\0') {
9789 vty_out(vty
, " ip ospf authentication-key %s",
9790 params
->auth_simple
);
9791 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9793 inet_ntoa(rn
->p
.u
.prefix4
));
9797 /* Cryptographic Authentication Key print. */
9798 if (params
&& params
->auth_crypt
) {
9799 for (ALL_LIST_ELEMENTS_RO(params
->auth_crypt
,
9802 " ip ospf message-digest-key %d md5 %s",
9803 ck
->key_id
, ck
->auth_key
);
9804 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9812 /* Interface Output Cost print. */
9813 if (OSPF_IF_PARAM_CONFIGURED(params
, output_cost_cmd
)) {
9814 vty_out(vty
, " ip ospf cost %u",
9815 params
->output_cost_cmd
);
9816 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9818 inet_ntoa(rn
->p
.u
.prefix4
));
9822 /* Hello Interval print. */
9823 if (OSPF_IF_PARAM_CONFIGURED(params
, v_hello
)
9824 && params
->v_hello
!= OSPF_HELLO_INTERVAL_DEFAULT
) {
9825 vty_out(vty
, " ip ospf hello-interval %u",
9827 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9829 inet_ntoa(rn
->p
.u
.prefix4
));
9834 /* Router Dead Interval print. */
9835 if (OSPF_IF_PARAM_CONFIGURED(params
, v_wait
)
9837 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
) {
9838 vty_out(vty
, " ip ospf dead-interval ");
9841 if (OSPF_IF_PARAM_CONFIGURED(params
,
9844 "minimal hello-multiplier %d",
9845 params
->fast_hello
);
9847 vty_out(vty
, "%u", params
->v_wait
);
9849 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9851 inet_ntoa(rn
->p
.u
.prefix4
));
9855 /* Router Priority print. */
9856 if (OSPF_IF_PARAM_CONFIGURED(params
, priority
)
9858 != OSPF_ROUTER_PRIORITY_DEFAULT
) {
9859 vty_out(vty
, " ip ospf priority %u",
9861 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9863 inet_ntoa(rn
->p
.u
.prefix4
));
9867 /* Retransmit Interval print. */
9868 if (OSPF_IF_PARAM_CONFIGURED(params
,
9869 retransmit_interval
)
9870 && params
->retransmit_interval
9871 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
) {
9872 vty_out(vty
, " ip ospf retransmit-interval %u",
9873 params
->retransmit_interval
);
9874 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9876 inet_ntoa(rn
->p
.u
.prefix4
));
9880 /* Transmit Delay print. */
9881 if (OSPF_IF_PARAM_CONFIGURED(params
, transmit_delay
)
9882 && params
->transmit_delay
9883 != OSPF_TRANSMIT_DELAY_DEFAULT
) {
9884 vty_out(vty
, " ip ospf transmit-delay %u",
9885 params
->transmit_delay
);
9886 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9888 inet_ntoa(rn
->p
.u
.prefix4
));
9893 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
9894 if (ospf
&& ospf
->instance
)
9895 vty_out(vty
, " ip ospf %d",
9898 vty_out(vty
, " ip ospf");
9900 char buf
[INET_ADDRSTRLEN
];
9902 area_id2str(buf
, sizeof(buf
), ¶ms
->if_area
,
9903 params
->if_area_id_fmt
);
9904 vty_out(vty
, " area %s", buf
);
9905 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9907 inet_ntoa(rn
->p
.u
.prefix4
));
9912 if (params
&& params
->bfd_info
)
9913 ospf_bfd_write_config(vty
, params
);
9915 /* MTU ignore print. */
9916 if (OSPF_IF_PARAM_CONFIGURED(params
, mtu_ignore
)
9917 && params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
) {
9918 if (params
->mtu_ignore
== 0)
9919 vty_out(vty
, " no ip ospf mtu-ignore");
9921 vty_out(vty
, " ip ospf mtu-ignore");
9922 if (params
!= IF_DEF_PARAMS(ifp
) && rn
)
9924 inet_ntoa(rn
->p
.u
.prefix4
));
9931 rn
= route_top(IF_OIFS_PARAMS(ifp
));
9933 rn
= route_next(rn
);
9943 ospf_opaque_config_write_if(vty
, ifp
);
9945 vty_endframe(vty
, NULL
);
9951 /* Configuration write function for ospfd. */
9952 static int config_write_interface(struct vty
*vty
)
9955 struct vrf
*vrf
= NULL
;
9957 /* Display all VRF aware OSPF interface configuration */
9958 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
9959 write
+= config_write_interface_one(vty
, vrf
);
9965 static int config_write_network_area(struct vty
*vty
, struct ospf
*ospf
)
9967 struct route_node
*rn
;
9968 uint8_t buf
[INET_ADDRSTRLEN
];
9970 /* `network area' print. */
9971 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
))
9973 struct ospf_network
*n
= rn
->info
;
9975 /* Create Area ID string by specified Area ID format. */
9976 if (n
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
9977 inet_ntop(AF_INET
, &n
->area_id
, (char *)buf
,
9980 sprintf((char *)buf
, "%lu",
9981 (unsigned long int)ntohl(
9982 n
->area_id
.s_addr
));
9984 /* Network print. */
9985 vty_out(vty
, " network %s/%d area %s\n",
9986 inet_ntoa(rn
->p
.u
.prefix4
), rn
->p
.prefixlen
,
9993 static int config_write_ospf_area(struct vty
*vty
, struct ospf
*ospf
)
9995 struct listnode
*node
;
9996 struct ospf_area
*area
;
9997 uint8_t buf
[INET_ADDRSTRLEN
];
9999 /* Area configuration print. */
10000 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
10001 struct route_node
*rn1
;
10003 area_id2str((char *)buf
, sizeof(buf
), &area
->area_id
,
10004 area
->area_id_fmt
);
10006 if (area
->auth_type
!= OSPF_AUTH_NULL
) {
10007 if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
10008 vty_out(vty
, " area %s authentication\n", buf
);
10011 " area %s authentication message-digest\n",
10015 if (area
->shortcut_configured
!= OSPF_SHORTCUT_DEFAULT
)
10016 vty_out(vty
, " area %s shortcut %s\n", buf
,
10017 ospf_shortcut_mode_str
10018 [area
->shortcut_configured
]);
10020 if ((area
->external_routing
== OSPF_AREA_STUB
)
10021 || (area
->external_routing
== OSPF_AREA_NSSA
)) {
10022 if (area
->external_routing
== OSPF_AREA_STUB
) {
10023 vty_out(vty
, " area %s stub", buf
);
10024 if (area
->no_summary
)
10025 vty_out(vty
, " no-summary\n");
10026 vty_out(vty
, "\n");
10027 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
10028 switch (area
->NSSATranslatorRole
) {
10029 case OSPF_NSSA_ROLE_NEVER
:
10031 " area %s nssa translate-never\n",
10034 case OSPF_NSSA_ROLE_ALWAYS
:
10036 " area %s nssa translate-always\n",
10039 case OSPF_NSSA_ROLE_CANDIDATE
:
10040 vty_out(vty
, " area %s nssa \n", buf
);
10043 if (area
->no_summary
)
10045 " area %s nssa no-summary\n",
10049 if (area
->default_cost
!= 1)
10050 vty_out(vty
, " area %s default-cost %d\n", buf
,
10051 area
->default_cost
);
10054 for (rn1
= route_top(area
->ranges
); rn1
; rn1
= route_next(rn1
))
10056 struct ospf_area_range
*range
= rn1
->info
;
10058 vty_out(vty
, " area %s range %s/%d", buf
,
10059 inet_ntoa(rn1
->p
.u
.prefix4
),
10062 if (range
->cost_config
10063 != OSPF_AREA_RANGE_COST_UNSPEC
)
10064 vty_out(vty
, " cost %d",
10065 range
->cost_config
);
10067 if (!CHECK_FLAG(range
->flags
,
10068 OSPF_AREA_RANGE_ADVERTISE
))
10069 vty_out(vty
, " not-advertise");
10071 if (CHECK_FLAG(range
->flags
,
10072 OSPF_AREA_RANGE_SUBSTITUTE
))
10073 vty_out(vty
, " substitute %s/%d",
10074 inet_ntoa(range
->subst_addr
),
10075 range
->subst_masklen
);
10077 vty_out(vty
, "\n");
10080 if (EXPORT_NAME(area
))
10081 vty_out(vty
, " area %s export-list %s\n", buf
,
10082 EXPORT_NAME(area
));
10084 if (IMPORT_NAME(area
))
10085 vty_out(vty
, " area %s import-list %s\n", buf
,
10086 IMPORT_NAME(area
));
10088 if (PREFIX_NAME_IN(area
))
10089 vty_out(vty
, " area %s filter-list prefix %s in\n", buf
,
10090 PREFIX_NAME_IN(area
));
10092 if (PREFIX_NAME_OUT(area
))
10093 vty_out(vty
, " area %s filter-list prefix %s out\n",
10094 buf
, PREFIX_NAME_OUT(area
));
10100 static int config_write_ospf_nbr_nbma(struct vty
*vty
, struct ospf
*ospf
)
10102 struct ospf_nbr_nbma
*nbr_nbma
;
10103 struct route_node
*rn
;
10105 /* Static Neighbor configuration print. */
10106 for (rn
= route_top(ospf
->nbr_nbma
); rn
; rn
= route_next(rn
))
10107 if ((nbr_nbma
= rn
->info
)) {
10108 vty_out(vty
, " neighbor %s", inet_ntoa(nbr_nbma
->addr
));
10110 if (nbr_nbma
->priority
10111 != OSPF_NEIGHBOR_PRIORITY_DEFAULT
)
10112 vty_out(vty
, " priority %d",
10113 nbr_nbma
->priority
);
10115 if (nbr_nbma
->v_poll
!= OSPF_POLL_INTERVAL_DEFAULT
)
10116 vty_out(vty
, " poll-interval %d",
10119 vty_out(vty
, "\n");
10125 static int config_write_virtual_link(struct vty
*vty
, struct ospf
*ospf
)
10127 struct listnode
*node
;
10128 struct ospf_vl_data
*vl_data
;
10129 char buf
[INET_ADDRSTRLEN
];
10131 /* Virtual-Link print */
10132 for (ALL_LIST_ELEMENTS_RO(ospf
->vlinks
, node
, vl_data
)) {
10133 struct listnode
*n2
;
10134 struct crypt_key
*ck
;
10135 struct ospf_interface
*oi
;
10137 if (vl_data
!= NULL
) {
10138 area_id2str(buf
, sizeof(buf
), &vl_data
->vl_area_id
,
10139 vl_data
->vl_area_id_fmt
);
10140 oi
= vl_data
->vl_oi
;
10143 if (OSPF_IF_PARAM(oi
, v_hello
)
10144 != OSPF_HELLO_INTERVAL_DEFAULT
10145 || OSPF_IF_PARAM(oi
, v_wait
)
10146 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
10147 || OSPF_IF_PARAM(oi
, retransmit_interval
)
10148 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
10149 || OSPF_IF_PARAM(oi
, transmit_delay
)
10150 != OSPF_TRANSMIT_DELAY_DEFAULT
)
10152 " area %s virtual-link %s hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n",
10153 buf
, inet_ntoa(vl_data
->vl_peer
),
10154 OSPF_IF_PARAM(oi
, v_hello
),
10155 OSPF_IF_PARAM(oi
, retransmit_interval
),
10156 OSPF_IF_PARAM(oi
, transmit_delay
),
10157 OSPF_IF_PARAM(oi
, v_wait
));
10159 vty_out(vty
, " area %s virtual-link %s\n", buf
,
10160 inet_ntoa(vl_data
->vl_peer
));
10162 if (IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)->auth_simple
[0]
10165 " area %s virtual-link %s authentication-key %s\n",
10166 buf
, inet_ntoa(vl_data
->vl_peer
),
10167 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
10170 for (ALL_LIST_ELEMENTS_RO(
10171 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
10175 " area %s virtual-link %s"
10176 " message-digest-key %d md5 %s\n",
10177 buf
, inet_ntoa(vl_data
->vl_peer
),
10178 ck
->key_id
, ck
->auth_key
);
10186 static int config_write_ospf_redistribute(struct vty
*vty
, struct ospf
*ospf
)
10190 /* redistribute print. */
10191 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
10192 struct list
*red_list
;
10193 struct listnode
*node
;
10194 struct ospf_redist
*red
;
10196 red_list
= ospf
->redist
[type
];
10200 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
10201 vty_out(vty
, " redistribute %s",
10202 zebra_route_string(type
));
10204 vty_out(vty
, " %d", red
->instance
);
10206 if (red
->dmetric
.value
>= 0)
10207 vty_out(vty
, " metric %d", red
->dmetric
.value
);
10209 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
10210 vty_out(vty
, " metric-type 1");
10212 if (ROUTEMAP_NAME(red
))
10213 vty_out(vty
, " route-map %s",
10214 ROUTEMAP_NAME(red
));
10216 vty_out(vty
, "\n");
10223 static int config_write_ospf_default_metric(struct vty
*vty
, struct ospf
*ospf
)
10225 if (ospf
->default_metric
!= -1)
10226 vty_out(vty
, " default-metric %d\n", ospf
->default_metric
);
10230 static int config_write_ospf_distribute(struct vty
*vty
, struct ospf
*ospf
)
10233 struct ospf_redist
*red
;
10236 /* distribute-list print. */
10237 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
10238 if (DISTRIBUTE_NAME(ospf
, type
))
10239 vty_out(vty
, " distribute-list %s out %s\n",
10240 DISTRIBUTE_NAME(ospf
, type
),
10241 zebra_route_string(type
));
10243 /* default-information print. */
10244 if (ospf
->default_originate
!= DEFAULT_ORIGINATE_NONE
) {
10245 vty_out(vty
, " default-information originate");
10246 if (ospf
->default_originate
== DEFAULT_ORIGINATE_ALWAYS
)
10247 vty_out(vty
, " always");
10249 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
10251 if (red
->dmetric
.value
>= 0)
10252 vty_out(vty
, " metric %d",
10253 red
->dmetric
.value
);
10255 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
10256 vty_out(vty
, " metric-type 1");
10258 if (ROUTEMAP_NAME(red
))
10259 vty_out(vty
, " route-map %s",
10260 ROUTEMAP_NAME(red
));
10263 vty_out(vty
, "\n");
10270 static int config_write_ospf_distance(struct vty
*vty
, struct ospf
*ospf
)
10272 struct route_node
*rn
;
10273 struct ospf_distance
*odistance
;
10275 if (ospf
->distance_all
)
10276 vty_out(vty
, " distance %d\n", ospf
->distance_all
);
10278 if (ospf
->distance_intra
|| ospf
->distance_inter
10279 || ospf
->distance_external
) {
10280 vty_out(vty
, " distance ospf");
10282 if (ospf
->distance_intra
)
10283 vty_out(vty
, " intra-area %d", ospf
->distance_intra
);
10284 if (ospf
->distance_inter
)
10285 vty_out(vty
, " inter-area %d", ospf
->distance_inter
);
10286 if (ospf
->distance_external
)
10287 vty_out(vty
, " external %d", ospf
->distance_external
);
10289 vty_out(vty
, "\n");
10292 for (rn
= route_top(ospf
->distance_table
); rn
; rn
= route_next(rn
))
10293 if ((odistance
= rn
->info
) != NULL
) {
10294 vty_out(vty
, " distance %d %s/%d %s\n",
10295 odistance
->distance
, inet_ntoa(rn
->p
.u
.prefix4
),
10297 odistance
->access_list
? odistance
->access_list
10303 static int ospf_config_write_one(struct vty
*vty
, struct ospf
*ospf
)
10305 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
10306 struct interface
*ifp
;
10307 struct ospf_interface
*oi
;
10308 struct listnode
*node
= NULL
;
10311 /* `router ospf' print. */
10312 if (ospf
->instance
&& ospf
->name
) {
10313 vty_out(vty
, "router ospf %d vrf %s\n", ospf
->instance
,
10315 } else if (ospf
->instance
) {
10316 vty_out(vty
, "router ospf %d\n", ospf
->instance
);
10317 } else if (ospf
->name
) {
10318 vty_out(vty
, "router ospf vrf %s\n", ospf
->name
);
10320 vty_out(vty
, "router ospf\n");
10322 if (!ospf
->networks
) {
10327 /* Router ID print. */
10328 if (ospf
->router_id_static
.s_addr
!= 0)
10329 vty_out(vty
, " ospf router-id %s\n",
10330 inet_ntoa(ospf
->router_id_static
));
10332 /* ABR type print. */
10333 if (ospf
->abr_type
!= OSPF_ABR_DEFAULT
)
10334 vty_out(vty
, " ospf abr-type %s\n",
10335 ospf_abr_type_str
[ospf
->abr_type
]);
10337 /* log-adjacency-changes flag print. */
10338 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
10339 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
))
10340 vty_out(vty
, " log-adjacency-changes detail\n");
10341 else if (!DFLT_OSPF_LOG_ADJACENCY_CHANGES
)
10342 vty_out(vty
, " log-adjacency-changes\n");
10343 } else if (DFLT_OSPF_LOG_ADJACENCY_CHANGES
) {
10344 vty_out(vty
, " no log-adjacency-changes\n");
10347 /* RFC1583 compatibility flag print -- Compatible with CISCO
10349 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
))
10350 vty_out(vty
, " compatible rfc1583\n");
10352 /* auto-cost reference-bandwidth configuration. */
10353 if (ospf
->ref_bandwidth
!= OSPF_DEFAULT_REF_BANDWIDTH
) {
10355 "! Important: ensure reference bandwidth "
10356 "is consistent across all routers\n");
10357 vty_out(vty
, " auto-cost reference-bandwidth %d\n",
10358 ospf
->ref_bandwidth
);
10361 /* SPF timers print. */
10362 if (ospf
->spf_delay
!= OSPF_SPF_DELAY_DEFAULT
10363 || ospf
->spf_holdtime
!= OSPF_SPF_HOLDTIME_DEFAULT
10364 || ospf
->spf_max_holdtime
!= OSPF_SPF_MAX_HOLDTIME_DEFAULT
)
10365 vty_out(vty
, " timers throttle spf %d %d %d\n", ospf
->spf_delay
,
10366 ospf
->spf_holdtime
, ospf
->spf_max_holdtime
);
10368 /* LSA timers print. */
10369 if (ospf
->min_ls_interval
!= OSPF_MIN_LS_INTERVAL
)
10370 vty_out(vty
, " timers throttle lsa all %d\n",
10371 ospf
->min_ls_interval
);
10372 if (ospf
->min_ls_arrival
!= OSPF_MIN_LS_ARRIVAL
)
10373 vty_out(vty
, " timers lsa min-arrival %d\n",
10374 ospf
->min_ls_arrival
);
10376 /* Write multiplier print. */
10377 if (ospf
->write_oi_count
!= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
)
10378 vty_out(vty
, " ospf write-multiplier %d\n",
10379 ospf
->write_oi_count
);
10381 /* Max-metric router-lsa print */
10382 config_write_stub_router(vty
, ospf
);
10384 /* SPF refresh parameters print. */
10385 if (ospf
->lsa_refresh_interval
!= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
10386 vty_out(vty
, " refresh timer %d\n", ospf
->lsa_refresh_interval
);
10388 /* Redistribute information print. */
10389 config_write_ospf_redistribute(vty
, ospf
);
10391 /* passive-interface print. */
10392 if (ospf
->passive_interface_default
== OSPF_IF_PASSIVE
)
10393 vty_out(vty
, " passive-interface default\n");
10395 FOR_ALL_INTERFACES (vrf
, ifp
)
10396 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp
),
10398 && IF_DEF_PARAMS(ifp
)->passive_interface
10399 != ospf
->passive_interface_default
) {
10400 vty_out(vty
, " %spassive-interface %s\n",
10401 IF_DEF_PARAMS(ifp
)->passive_interface
? ""
10405 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
10406 if (!OSPF_IF_PARAM_CONFIGURED(oi
->params
, passive_interface
))
10408 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(oi
->ifp
),
10409 passive_interface
)) {
10410 if (oi
->params
->passive_interface
10411 == IF_DEF_PARAMS(oi
->ifp
)->passive_interface
)
10413 } else if (oi
->params
->passive_interface
10414 == ospf
->passive_interface_default
)
10417 vty_out(vty
, " %spassive-interface %s %s\n",
10418 oi
->params
->passive_interface
? "" : "no ",
10419 oi
->ifp
->name
, inet_ntoa(oi
->address
->u
.prefix4
));
10422 /* Network area print. */
10423 config_write_network_area(vty
, ospf
);
10425 /* Area config print. */
10426 config_write_ospf_area(vty
, ospf
);
10428 /* static neighbor print. */
10429 config_write_ospf_nbr_nbma(vty
, ospf
);
10431 /* Virtual-Link print. */
10432 config_write_virtual_link(vty
, ospf
);
10434 /* Default metric configuration. */
10435 config_write_ospf_default_metric(vty
, ospf
);
10437 /* Distribute-list and default-information print. */
10438 config_write_ospf_distribute(vty
, ospf
);
10440 /* Distance configuration. */
10441 config_write_ospf_distance(vty
, ospf
);
10443 ospf_opaque_config_write_router(vty
, ospf
);
10449 /* OSPF configuration write function. */
10450 static int ospf_config_write(struct vty
*vty
)
10453 struct listnode
*ospf_node
= NULL
;
10456 if (listcount(om
->ospf
) == 0)
10459 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, ospf_node
, ospf
)) {
10460 /* VRF Default check if it is running.
10461 * Upon daemon start, there could be default instance
10462 * in absence of 'router ospf'/oi_running is disabled. */
10463 if (ospf
->vrf_id
== VRF_DEFAULT
&& ospf
->oi_running
)
10464 write
+= ospf_config_write_one(vty
, ospf
);
10465 /* For Non-Default VRF simply display the configuration,
10466 * even if it is not oi_running. */
10467 else if (ospf
->vrf_id
!= VRF_DEFAULT
)
10468 write
+= ospf_config_write_one(vty
, ospf
);
10473 void ospf_vty_show_init(void)
10475 /* "show ip ospf" commands. */
10476 install_element(VIEW_NODE
, &show_ip_ospf_cmd
);
10478 install_element(VIEW_NODE
, &show_ip_ospf_instance_cmd
);
10480 /* "show ip ospf database" commands. */
10481 install_element(VIEW_NODE
, &show_ip_ospf_database_max_cmd
);
10483 install_element(VIEW_NODE
,
10484 &show_ip_ospf_instance_database_type_adv_router_cmd
);
10485 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_cmd
);
10486 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_max_cmd
);
10488 /* "show ip ospf interface" commands. */
10489 install_element(VIEW_NODE
, &show_ip_ospf_interface_cmd
);
10491 install_element(VIEW_NODE
, &show_ip_ospf_instance_interface_cmd
);
10492 /* "show ip ospf interface traffic */
10493 install_element(VIEW_NODE
, &show_ip_ospf_interface_traffic_cmd
);
10495 /* "show ip ospf neighbor" commands. */
10496 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_detail_cmd
);
10497 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_cmd
);
10498 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_id_cmd
);
10499 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_all_cmd
);
10500 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_cmd
);
10501 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_cmd
);
10502 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_all_cmd
);
10504 install_element(VIEW_NODE
,
10505 &show_ip_ospf_instance_neighbor_int_detail_cmd
);
10506 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_int_cmd
);
10507 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_id_cmd
);
10508 install_element(VIEW_NODE
,
10509 &show_ip_ospf_instance_neighbor_detail_all_cmd
);
10510 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_detail_cmd
);
10511 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_cmd
);
10512 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_all_cmd
);
10514 /* "show ip ospf route" commands. */
10515 install_element(VIEW_NODE
, &show_ip_ospf_route_cmd
);
10516 install_element(VIEW_NODE
, &show_ip_ospf_border_routers_cmd
);
10518 install_element(VIEW_NODE
, &show_ip_ospf_instance_route_cmd
);
10519 install_element(VIEW_NODE
, &show_ip_ospf_instance_border_routers_cmd
);
10521 /* "show ip ospf vrfs" commands. */
10522 install_element(VIEW_NODE
, &show_ip_ospf_vrfs_cmd
);
10526 /* ospfd's interface node. */
10527 static struct cmd_node interface_node
= {INTERFACE_NODE
, "%s(config-if)# ", 1};
10529 /* Initialization of OSPF interface. */
10530 static void ospf_vty_if_init(void)
10532 /* Install interface node. */
10533 install_node(&interface_node
, config_write_interface
);
10536 /* "ip ospf authentication" commands. */
10537 install_element(INTERFACE_NODE
, &ip_ospf_authentication_args_addr_cmd
);
10538 install_element(INTERFACE_NODE
, &ip_ospf_authentication_addr_cmd
);
10539 install_element(INTERFACE_NODE
,
10540 &no_ip_ospf_authentication_args_addr_cmd
);
10541 install_element(INTERFACE_NODE
, &no_ip_ospf_authentication_addr_cmd
);
10542 install_element(INTERFACE_NODE
, &ip_ospf_authentication_key_addr_cmd
);
10543 install_element(INTERFACE_NODE
,
10544 &no_ip_ospf_authentication_key_authkey_addr_cmd
);
10545 install_element(INTERFACE_NODE
,
10546 &no_ospf_authentication_key_authkey_addr_cmd
);
10548 /* "ip ospf message-digest-key" commands. */
10549 install_element(INTERFACE_NODE
, &ip_ospf_message_digest_key_cmd
);
10550 install_element(INTERFACE_NODE
, &no_ip_ospf_message_digest_key_cmd
);
10552 /* "ip ospf cost" commands. */
10553 install_element(INTERFACE_NODE
, &ip_ospf_cost_cmd
);
10554 install_element(INTERFACE_NODE
, &no_ip_ospf_cost_cmd
);
10556 /* "ip ospf mtu-ignore" commands. */
10557 install_element(INTERFACE_NODE
, &ip_ospf_mtu_ignore_addr_cmd
);
10558 install_element(INTERFACE_NODE
, &no_ip_ospf_mtu_ignore_addr_cmd
);
10560 /* "ip ospf dead-interval" commands. */
10561 install_element(INTERFACE_NODE
, &ip_ospf_dead_interval_cmd
);
10562 install_element(INTERFACE_NODE
,
10563 &ip_ospf_dead_interval_minimal_addr_cmd
);
10564 install_element(INTERFACE_NODE
, &no_ip_ospf_dead_interval_cmd
);
10566 /* "ip ospf hello-interval" commands. */
10567 install_element(INTERFACE_NODE
, &ip_ospf_hello_interval_cmd
);
10568 install_element(INTERFACE_NODE
, &no_ip_ospf_hello_interval_cmd
);
10570 /* "ip ospf network" commands. */
10571 install_element(INTERFACE_NODE
, &ip_ospf_network_cmd
);
10572 install_element(INTERFACE_NODE
, &no_ip_ospf_network_cmd
);
10574 /* "ip ospf priority" commands. */
10575 install_element(INTERFACE_NODE
, &ip_ospf_priority_cmd
);
10576 install_element(INTERFACE_NODE
, &no_ip_ospf_priority_cmd
);
10578 /* "ip ospf retransmit-interval" commands. */
10579 install_element(INTERFACE_NODE
, &ip_ospf_retransmit_interval_addr_cmd
);
10580 install_element(INTERFACE_NODE
,
10581 &no_ip_ospf_retransmit_interval_addr_cmd
);
10583 /* "ip ospf transmit-delay" commands. */
10584 install_element(INTERFACE_NODE
, &ip_ospf_transmit_delay_addr_cmd
);
10585 install_element(INTERFACE_NODE
, &no_ip_ospf_transmit_delay_addr_cmd
);
10587 /* "ip ospf area" commands. */
10588 install_element(INTERFACE_NODE
, &ip_ospf_area_cmd
);
10589 install_element(INTERFACE_NODE
, &no_ip_ospf_area_cmd
);
10591 /* These commands are compatibitliy for previous version. */
10592 install_element(INTERFACE_NODE
, &ospf_authentication_key_cmd
);
10593 install_element(INTERFACE_NODE
, &ospf_message_digest_key_cmd
);
10594 install_element(INTERFACE_NODE
, &no_ospf_message_digest_key_cmd
);
10595 install_element(INTERFACE_NODE
, &ospf_dead_interval_cmd
);
10596 install_element(INTERFACE_NODE
, &no_ospf_dead_interval_cmd
);
10597 install_element(INTERFACE_NODE
, &ospf_hello_interval_cmd
);
10598 install_element(INTERFACE_NODE
, &no_ospf_hello_interval_cmd
);
10599 install_element(INTERFACE_NODE
, &ospf_cost_cmd
);
10600 install_element(INTERFACE_NODE
, &no_ospf_cost_cmd
);
10601 install_element(INTERFACE_NODE
, &ospf_network_cmd
);
10602 install_element(INTERFACE_NODE
, &no_ospf_network_cmd
);
10603 install_element(INTERFACE_NODE
, &ospf_priority_cmd
);
10604 install_element(INTERFACE_NODE
, &no_ospf_priority_cmd
);
10605 install_element(INTERFACE_NODE
, &ospf_retransmit_interval_cmd
);
10606 install_element(INTERFACE_NODE
, &no_ospf_retransmit_interval_cmd
);
10607 install_element(INTERFACE_NODE
, &ospf_transmit_delay_cmd
);
10608 install_element(INTERFACE_NODE
, &no_ospf_transmit_delay_cmd
);
10611 static void ospf_vty_zebra_init(void)
10613 install_element(OSPF_NODE
, &ospf_redistribute_source_cmd
);
10614 install_element(OSPF_NODE
, &no_ospf_redistribute_source_cmd
);
10615 install_element(OSPF_NODE
, &ospf_redistribute_instance_source_cmd
);
10616 install_element(OSPF_NODE
, &no_ospf_redistribute_instance_source_cmd
);
10618 install_element(OSPF_NODE
, &ospf_distribute_list_out_cmd
);
10619 install_element(OSPF_NODE
, &no_ospf_distribute_list_out_cmd
);
10621 install_element(OSPF_NODE
, &ospf_default_information_originate_cmd
);
10622 install_element(OSPF_NODE
, &no_ospf_default_information_originate_cmd
);
10624 install_element(OSPF_NODE
, &ospf_default_metric_cmd
);
10625 install_element(OSPF_NODE
, &no_ospf_default_metric_cmd
);
10627 install_element(OSPF_NODE
, &ospf_distance_cmd
);
10628 install_element(OSPF_NODE
, &no_ospf_distance_cmd
);
10629 install_element(OSPF_NODE
, &no_ospf_distance_ospf_cmd
);
10630 install_element(OSPF_NODE
, &ospf_distance_ospf_cmd
);
10632 install_element (OSPF_NODE
, &ospf_distance_source_cmd
);
10633 install_element (OSPF_NODE
, &no_ospf_distance_source_cmd
);
10634 install_element (OSPF_NODE
, &ospf_distance_source_access_list_cmd
);
10635 install_element (OSPF_NODE
, &no_ospf_distance_source_access_list_cmd
);
10639 static struct cmd_node ospf_node
= {OSPF_NODE
, "%s(config-router)# ", 1};
10641 static void ospf_interface_clear(struct interface
*ifp
)
10643 if (!if_is_operative(ifp
))
10646 if (IS_DEBUG_OSPF(ism
, ISM_EVENTS
))
10647 zlog_debug("ISM[%s]: clear by reset", ifp
->name
);
10649 ospf_if_reset(ifp
);
10652 DEFUN (clear_ip_ospf_interface
,
10653 clear_ip_ospf_interface_cmd
,
10654 "clear ip ospf [vrf <NAME>] interface [IFNAME]",
10657 "OSPF information\n"
10659 "Interface information\n"
10660 "Interface name\n")
10662 int idx_ifname
= 0;
10664 struct interface
*ifp
;
10665 struct listnode
*node
;
10666 struct ospf
*ospf
= NULL
;
10667 char *vrf_name
= NULL
;
10668 vrf_id_t vrf_id
= VRF_DEFAULT
;
10669 struct vrf
*vrf
= NULL
;
10671 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
10672 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
10673 if (vrf_name
&& strmatch(vrf_name
, VRF_DEFAULT_NAME
))
10676 vrf
= vrf_lookup_by_name(vrf_name
);
10678 vrf_id
= vrf
->vrf_id
;
10680 if (!argv_find(argv
, argc
, "IFNAME", &idx_ifname
)) {
10681 /* Clear all the ospfv2 interfaces. */
10682 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
10683 if (vrf_id
!= ospf
->vrf_id
)
10686 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
10687 FOR_ALL_INTERFACES (vrf
, ifp
)
10688 ospf_interface_clear(ifp
);
10691 /* Interface name is specified. */
10692 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
,
10693 vrf_lookup_by_id(vrf_id
));
10695 vty_out(vty
, "No such interface name\n");
10697 ospf_interface_clear(ifp
);
10700 return CMD_SUCCESS
;
10703 void ospf_vty_clear_init(void)
10705 install_element(ENABLE_NODE
, &clear_ip_ospf_interface_cmd
);
10709 /* Install OSPF related vty commands. */
10710 void ospf_vty_init(void)
10712 /* Install ospf top node. */
10713 install_node(&ospf_node
, ospf_config_write
);
10715 /* "router ospf" commands. */
10716 install_element(CONFIG_NODE
, &router_ospf_cmd
);
10717 install_element(CONFIG_NODE
, &no_router_ospf_cmd
);
10720 install_default(OSPF_NODE
);
10722 /* "ospf router-id" commands. */
10723 install_element(OSPF_NODE
, &ospf_router_id_cmd
);
10724 install_element(OSPF_NODE
, &ospf_router_id_old_cmd
);
10725 install_element(OSPF_NODE
, &no_ospf_router_id_cmd
);
10727 /* "passive-interface" commands. */
10728 install_element(OSPF_NODE
, &ospf_passive_interface_addr_cmd
);
10729 install_element(OSPF_NODE
, &no_ospf_passive_interface_addr_cmd
);
10731 /* "ospf abr-type" commands. */
10732 install_element(OSPF_NODE
, &ospf_abr_type_cmd
);
10733 install_element(OSPF_NODE
, &no_ospf_abr_type_cmd
);
10735 /* "ospf log-adjacency-changes" commands. */
10736 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_cmd
);
10737 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_detail_cmd
);
10738 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_cmd
);
10739 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_detail_cmd
);
10741 /* "ospf rfc1583-compatible" commands. */
10742 install_element(OSPF_NODE
, &ospf_compatible_rfc1583_cmd
);
10743 install_element(OSPF_NODE
, &no_ospf_compatible_rfc1583_cmd
);
10744 install_element(OSPF_NODE
, &ospf_rfc1583_flag_cmd
);
10745 install_element(OSPF_NODE
, &no_ospf_rfc1583_flag_cmd
);
10747 /* "network area" commands. */
10748 install_element(OSPF_NODE
, &ospf_network_area_cmd
);
10749 install_element(OSPF_NODE
, &no_ospf_network_area_cmd
);
10751 /* "area authentication" commands. */
10752 install_element(OSPF_NODE
,
10753 &ospf_area_authentication_message_digest_cmd
);
10754 install_element(OSPF_NODE
, &ospf_area_authentication_cmd
);
10755 install_element(OSPF_NODE
, &no_ospf_area_authentication_cmd
);
10757 /* "area range" commands. */
10758 install_element(OSPF_NODE
, &ospf_area_range_cmd
);
10759 install_element(OSPF_NODE
, &ospf_area_range_cost_cmd
);
10760 install_element(OSPF_NODE
, &ospf_area_range_not_advertise_cmd
);
10761 install_element(OSPF_NODE
, &no_ospf_area_range_cmd
);
10762 install_element(OSPF_NODE
, &ospf_area_range_substitute_cmd
);
10763 install_element(OSPF_NODE
, &no_ospf_area_range_substitute_cmd
);
10765 /* "area virtual-link" commands. */
10766 install_element(OSPF_NODE
, &ospf_area_vlink_cmd
);
10767 install_element(OSPF_NODE
, &ospf_area_vlink_intervals_cmd
);
10768 install_element(OSPF_NODE
, &no_ospf_area_vlink_cmd
);
10769 install_element(OSPF_NODE
, &no_ospf_area_vlink_intervals_cmd
);
10772 /* "area stub" commands. */
10773 install_element(OSPF_NODE
, &ospf_area_stub_no_summary_cmd
);
10774 install_element(OSPF_NODE
, &ospf_area_stub_cmd
);
10775 install_element(OSPF_NODE
, &no_ospf_area_stub_no_summary_cmd
);
10776 install_element(OSPF_NODE
, &no_ospf_area_stub_cmd
);
10778 /* "area nssa" commands. */
10779 install_element(OSPF_NODE
, &ospf_area_nssa_cmd
);
10780 install_element(OSPF_NODE
, &ospf_area_nssa_translate_cmd
);
10781 install_element(OSPF_NODE
, &ospf_area_nssa_no_summary_cmd
);
10782 install_element(OSPF_NODE
, &no_ospf_area_nssa_no_summary_cmd
);
10783 install_element(OSPF_NODE
, &no_ospf_area_nssa_cmd
);
10785 install_element(OSPF_NODE
, &ospf_area_default_cost_cmd
);
10786 install_element(OSPF_NODE
, &no_ospf_area_default_cost_cmd
);
10788 install_element(OSPF_NODE
, &ospf_area_shortcut_cmd
);
10789 install_element(OSPF_NODE
, &no_ospf_area_shortcut_cmd
);
10791 install_element(OSPF_NODE
, &ospf_area_export_list_cmd
);
10792 install_element(OSPF_NODE
, &no_ospf_area_export_list_cmd
);
10794 install_element(OSPF_NODE
, &ospf_area_filter_list_cmd
);
10795 install_element(OSPF_NODE
, &no_ospf_area_filter_list_cmd
);
10797 install_element(OSPF_NODE
, &ospf_area_import_list_cmd
);
10798 install_element(OSPF_NODE
, &no_ospf_area_import_list_cmd
);
10800 /* SPF timer commands */
10801 install_element(OSPF_NODE
, &ospf_timers_throttle_spf_cmd
);
10802 install_element(OSPF_NODE
, &no_ospf_timers_throttle_spf_cmd
);
10804 /* LSA timers commands */
10805 install_element(OSPF_NODE
, &ospf_timers_min_ls_interval_cmd
);
10806 install_element(OSPF_NODE
, &no_ospf_timers_min_ls_interval_cmd
);
10807 install_element(OSPF_NODE
, &ospf_timers_lsa_min_arrival_cmd
);
10808 install_element(OSPF_NODE
, &no_ospf_timers_lsa_min_arrival_cmd
);
10810 /* refresh timer commands */
10811 install_element(OSPF_NODE
, &ospf_refresh_timer_cmd
);
10812 install_element(OSPF_NODE
, &no_ospf_refresh_timer_val_cmd
);
10814 /* max-metric commands */
10815 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_admin_cmd
);
10816 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_admin_cmd
);
10817 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_startup_cmd
);
10818 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_startup_cmd
);
10819 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_shutdown_cmd
);
10820 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_shutdown_cmd
);
10822 /* reference bandwidth commands */
10823 install_element(OSPF_NODE
, &ospf_auto_cost_reference_bandwidth_cmd
);
10824 install_element(OSPF_NODE
, &no_ospf_auto_cost_reference_bandwidth_cmd
);
10826 /* "neighbor" commands. */
10827 install_element(OSPF_NODE
, &ospf_neighbor_cmd
);
10828 install_element(OSPF_NODE
, &ospf_neighbor_poll_interval_cmd
);
10829 install_element(OSPF_NODE
, &no_ospf_neighbor_cmd
);
10830 install_element(OSPF_NODE
, &no_ospf_neighbor_poll_cmd
);
10832 /* write multiplier commands */
10833 install_element(OSPF_NODE
, &ospf_write_multiplier_cmd
);
10834 install_element(OSPF_NODE
, &write_multiplier_cmd
);
10835 install_element(OSPF_NODE
, &no_ospf_write_multiplier_cmd
);
10836 install_element(OSPF_NODE
, &no_write_multiplier_cmd
);
10838 /* Init interface related vty commands. */
10839 ospf_vty_if_init();
10841 /* Init zebra related vty commands. */
10842 ospf_vty_zebra_init();