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 void area_id2str(char *buf
, int length
, struct in_addr
*area_id
,
78 memset(buf
, 0, length
);
80 if (area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
81 strncpy(buf
, inet_ntoa(*area_id
), length
);
83 sprintf(buf
, "%lu", (unsigned long)ntohl(area_id
->s_addr
));
86 static int str2metric(const char *str
, int *metric
)
92 *metric
= strtol(str
, NULL
, 10);
93 if (*metric
< 0 && *metric
> 16777214) {
94 /* vty_out (vty, "OSPF metric value is invalid\n"); */
101 static int str2metric_type(const char *str
, int *metric_type
)
107 if (strncmp(str
, "1", 1) == 0)
108 *metric_type
= EXTERNAL_METRIC_TYPE_1
;
109 else if (strncmp(str
, "2", 1) == 0)
110 *metric_type
= EXTERNAL_METRIC_TYPE_2
;
117 int ospf_oi_count(struct interface
*ifp
)
119 struct route_node
*rn
;
122 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
129 #define OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf) \
130 if (argv_find(argv, argc, "vrf", &idx_vrf)) { \
131 vrf_name = argv[idx_vrf + 1]->arg; \
132 all_vrf = strmatch(vrf_name, "all"); \
135 static struct ospf
*ospf_cmd_lookup_ospf(struct vty
*vty
,
136 struct cmd_token
*argv
[],
137 const int argc
, uint32_t enable
,
138 unsigned short *instance
)
140 struct ospf
*ospf
= NULL
;
141 int idx_vrf
= 0, idx_inst
= 0;
142 const char *vrf_name
= NULL
;
145 if (argv_find(argv
, argc
, "(1-65535)", &idx_inst
))
146 *instance
= strtoul(argv
[idx_inst
]->arg
, NULL
, 10);
148 if (argv_find(argv
, argc
, "vrf", &idx_vrf
)) {
149 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
151 /* Allocate VRF aware instance */
152 ospf
= ospf_get(*instance
, vrf_name
);
154 ospf
= ospf_lookup_by_inst_name(*instance
, vrf_name
);
158 ospf
= ospf_get(*instance
, NULL
);
160 ospf
= ospf_lookup_instance(*instance
);
167 static void ospf_show_vrf_name(struct ospf
*ospf
, struct vty
*vty
,
168 json_object
*json
, uint8_t use_vrf
)
172 if (ospf
->vrf_id
== VRF_DEFAULT
)
173 json_object_string_add(json
, "vrfName",
176 json_object_string_add(json
, "vrfName",
178 json_object_int_add(json
, "vrfId", ospf
->vrf_id
);
180 if (ospf
->vrf_id
== VRF_DEFAULT
)
181 vty_out(vty
, "VRF Name: %s\n", "default");
183 vty_out(vty
, "VRF Name: %s\n", ospf
->name
);
188 #ifndef VTYSH_EXTRACT_PL
189 #include "ospfd/ospf_vty_clippy.c"
192 DEFUN_NOSH (router_ospf
,
194 "router ospf [{(1-65535)|vrf NAME}]",
195 "Enable a routing process\n"
196 "Start OSPF configuration\n"
200 struct ospf
*ospf
= NULL
;
201 int ret
= CMD_SUCCESS
;
202 unsigned short instance
= 0;
203 struct vrf
*vrf
= NULL
;
204 struct route_node
*rn
;
205 struct interface
*ifp
;
207 ospf
= ospf_cmd_lookup_ospf(vty
, argv
, argc
, 1, &instance
);
209 return CMD_WARNING_CONFIG_FAILED
;
211 /* The following logic to set the vty qobj index is in place to be able
212 to ignore the commands which dont belong to this instance. */
213 if (ospf
->instance
!= instance
) {
214 VTY_PUSH_CONTEXT_NULL(OSPF_NODE
);
215 ret
= CMD_NOT_MY_INSTANCE
;
217 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
218 ospf
->oi_running
= 1;
219 if (IS_DEBUG_OSPF_EVENT
)
221 "Config command 'router ospf %d' received, vrf %s id %u oi_running %u",
222 instance
, ospf
->name
? ospf
->name
: "NIL",
223 ospf
->vrf_id
, ospf
->oi_running
);
224 VTY_PUSH_CONTEXT(OSPF_NODE
, ospf
);
226 /* Activate 'ip ospf area x' configured interfaces for given
227 * vrf. Activate area on vrf x aware interfaces.
228 * vrf_enable callback calls router_id_update which
229 * internally will call ospf_if_update to trigger
232 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
234 FOR_ALL_INTERFACES (vrf
, ifp
) {
235 struct ospf_if_params
*params
;
237 params
= IF_DEF_PARAMS(ifp
);
238 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
239 for (rn
= route_top(ospf
->networks
); rn
;
240 rn
= route_next(rn
)) {
241 if (rn
->info
!= NULL
) {
243 "Interface %s has area config but please remove all network commands first.\n",
248 ospf_interface_area_set(ospf
, ifp
);
249 ospf
->if_ospf_cli_count
++;
253 ospf_router_id_update(ospf
);
259 DEFUN (no_router_ospf
,
261 "no router ospf [{(1-65535)|vrf NAME}]",
263 "Enable a routing process\n"
264 "Start OSPF configuration\n"
269 unsigned short instance
= 0;
271 ospf
= ospf_cmd_lookup_ospf(vty
, argv
, argc
, 0, &instance
);
274 return CMD_NOT_MY_INSTANCE
;
284 DEFPY (ospf_router_id
,
286 "ospf router-id A.B.C.D",
287 "OSPF specific commands\n"
288 "router-id for the OSPF process\n"
289 "OSPF router-id in IP address format\n")
291 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
293 struct listnode
*node
;
294 struct ospf_area
*area
;
296 ospf
->router_id_static
= router_id
;
298 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
299 if (area
->full_nbrs
) {
301 "For this router-id change to take effect,"
302 " save config and restart ospfd\n");
306 ospf_router_id_update(ospf
);
311 DEFUN_HIDDEN (ospf_router_id_old
,
312 ospf_router_id_old_cmd
,
314 "router-id for the OSPF process\n"
315 "OSPF router-id in IP address format\n")
317 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
319 struct listnode
*node
;
320 struct ospf_area
*area
;
321 struct in_addr router_id
;
324 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &router_id
);
326 vty_out(vty
, "Please specify Router ID by A.B.C.D\n");
327 return CMD_WARNING_CONFIG_FAILED
;
330 ospf
->router_id_static
= router_id
;
332 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
333 if (area
->full_nbrs
) {
335 "For this router-id change to take effect,"
336 " save config and restart ospfd\n");
340 ospf_router_id_update(ospf
);
345 DEFPY (no_ospf_router_id
,
346 no_ospf_router_id_cmd
,
347 "no ospf router-id [A.B.C.D]",
349 "OSPF specific commands\n"
350 "router-id for the OSPF process\n"
351 "OSPF router-id in IP address format\n")
353 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
354 struct listnode
*node
;
355 struct ospf_area
*area
;
358 if (!IPV4_ADDR_SAME(&ospf
->router_id_static
, &router_id
)) {
359 vty_out(vty
, "%% OSPF router-id doesn't match\n");
360 return CMD_WARNING_CONFIG_FAILED
;
364 ospf
->router_id_static
.s_addr
= 0;
366 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
))
367 if (area
->full_nbrs
) {
369 "For this router-id change to take effect,"
370 " save config and restart ospfd\n");
374 ospf_router_id_update(ospf
);
380 static void ospf_passive_interface_default(struct ospf
*ospf
, uint8_t newval
)
382 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
384 struct interface
*ifp
;
385 struct ospf_interface
*oi
;
387 ospf
->passive_interface_default
= newval
;
389 FOR_ALL_INTERFACES (vrf
, ifp
) {
390 if (ifp
&& OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp
),
392 UNSET_IF_PARAM(IF_DEF_PARAMS(ifp
), passive_interface
);
394 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, ln
, oi
)) {
395 if (OSPF_IF_PARAM_CONFIGURED(oi
->params
, passive_interface
))
396 UNSET_IF_PARAM(oi
->params
, passive_interface
);
397 /* update multicast memberships */
398 ospf_if_set_multicast(oi
);
402 static void ospf_passive_interface_update_addr(struct ospf
*ospf
,
403 struct interface
*ifp
,
404 struct ospf_if_params
*params
,
410 params
->passive_interface
= value
;
411 if (params
!= IF_DEF_PARAMS(ifp
)) {
412 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp
),
414 dflt
= IF_DEF_PARAMS(ifp
)->passive_interface
;
416 dflt
= ospf
->passive_interface_default
;
419 SET_IF_PARAM(params
, passive_interface
);
421 UNSET_IF_PARAM(params
, passive_interface
);
423 ospf_free_if_params(ifp
, addr
);
424 ospf_if_update_params(ifp
, addr
);
428 static void ospf_passive_interface_update(struct ospf
*ospf
,
429 struct interface
*ifp
,
430 struct ospf_if_params
*params
,
433 params
->passive_interface
= value
;
434 if (params
== IF_DEF_PARAMS(ifp
)) {
435 if (value
!= ospf
->passive_interface_default
)
436 SET_IF_PARAM(params
, passive_interface
);
438 UNSET_IF_PARAM(params
, passive_interface
);
442 DEFUN (ospf_passive_interface
,
443 ospf_passive_interface_addr_cmd
,
444 "passive-interface <IFNAME [A.B.C.D]|default>",
445 "Suppress routing updates on an interface\n"
448 "Suppress routing updates on interfaces by default\n")
450 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
452 struct interface
*ifp
= NULL
;
453 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
455 struct ospf_if_params
*params
;
456 struct route_node
*rn
;
458 if (strmatch(argv
[1]->text
, "default")) {
459 ospf_passive_interface_default(ospf
, OSPF_IF_PASSIVE
);
462 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
463 ifp
= if_get_by_name(argv
[1]->arg
, ospf
->vrf_id
, 0);
466 vty_out(vty
, "interface %s not found.\n", (char *)argv
[1]->arg
);
467 return CMD_WARNING_CONFIG_FAILED
;
470 params
= IF_DEF_PARAMS(ifp
);
473 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
476 "Please specify interface address by A.B.C.D\n");
477 return CMD_WARNING_CONFIG_FAILED
;
480 params
= ospf_get_if_params(ifp
, addr
);
481 ospf_if_update_params(ifp
, addr
);
482 ospf_passive_interface_update_addr(ospf
, ifp
, params
,
483 OSPF_IF_PASSIVE
, addr
);
486 ospf_passive_interface_update(ospf
, ifp
, params
, OSPF_IF_PASSIVE
);
488 /* XXX We should call ospf_if_set_multicast on exactly those
489 * interfaces for which the passive property changed. It is too much
490 * work to determine this set, so we do this for every interface.
491 * This is safe and reasonable because ospf_if_set_multicast uses a
492 * record of joined groups to avoid systems calls if the desired
493 * memberships match the current memership.
496 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
497 struct ospf_interface
*oi
= rn
->info
;
499 if (oi
&& (OSPF_IF_PARAM(oi
, passive_interface
)
501 ospf_if_set_multicast(oi
);
504 * XXX It is not clear what state transitions the interface needs to
505 * undergo when going from active to passive. Fixing this will
506 * require precise identification of interfaces having such a
513 DEFUN (no_ospf_passive_interface
,
514 no_ospf_passive_interface_addr_cmd
,
515 "no passive-interface <IFNAME [A.B.C.D]|default>",
517 "Allow routing updates on an interface\n"
520 "Allow routing updates on interfaces by default\n")
522 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
524 struct interface
*ifp
= NULL
;
525 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
526 struct ospf_if_params
*params
;
528 struct route_node
*rn
;
530 if (strmatch(argv
[2]->text
, "default")) {
531 ospf_passive_interface_default(ospf
, OSPF_IF_ACTIVE
);
535 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
536 ifp
= if_get_by_name(argv
[2]->arg
, ospf
->vrf_id
, 0);
539 vty_out(vty
, "interface %s not found.\n", (char *)argv
[2]->arg
);
540 return CMD_WARNING_CONFIG_FAILED
;
543 params
= IF_DEF_PARAMS(ifp
);
546 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
549 "Please specify interface address by A.B.C.D\n");
550 return CMD_WARNING_CONFIG_FAILED
;
553 params
= ospf_lookup_if_params(ifp
, addr
);
556 ospf_passive_interface_update_addr(ospf
, ifp
, params
,
557 OSPF_IF_ACTIVE
, addr
);
559 ospf_passive_interface_update(ospf
, ifp
, params
, OSPF_IF_ACTIVE
);
561 /* XXX We should call ospf_if_set_multicast on exactly those
562 * interfaces for which the passive property changed. It is too much
563 * work to determine this set, so we do this for every interface.
564 * This is safe and reasonable because ospf_if_set_multicast uses a
565 * record of joined groups to avoid systems calls if the desired
566 * memberships match the current memership.
568 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
569 struct ospf_interface
*oi
= rn
->info
;
572 && (OSPF_IF_PARAM(oi
, passive_interface
) == OSPF_IF_ACTIVE
))
573 ospf_if_set_multicast(oi
);
580 DEFUN (ospf_network_area
,
581 ospf_network_area_cmd
,
582 "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
583 "Enable routing on an IP network\n"
584 "OSPF network prefix\n"
585 "Set the OSPF area ID\n"
586 "OSPF area ID in IP address format\n"
587 "OSPF area ID as a decimal value\n")
589 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
590 int idx_ipv4_prefixlen
= 1;
591 int idx_ipv4_number
= 3;
592 struct prefix_ipv4 p
;
593 struct in_addr area_id
;
596 if (ospf
->instance
) {
598 "The network command is not supported in multi-instance ospf\n");
599 return CMD_WARNING_CONFIG_FAILED
;
602 if (ospf
->if_ospf_cli_count
> 0) {
604 "Please remove all ip ospf area x.x.x.x commands first.\n");
605 if (IS_DEBUG_OSPF_EVENT
)
607 "%s ospf vrf %s num of %u ip osp area x config",
609 ospf
->name
? ospf
->name
: "NIL",
610 ospf
->if_ospf_cli_count
);
611 return CMD_WARNING_CONFIG_FAILED
;
614 /* Get network prefix and Area ID. */
615 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
616 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
618 ret
= ospf_network_set(ospf
, &p
, area_id
, format
);
620 vty_out(vty
, "There is already same network statement.\n");
621 return CMD_WARNING_CONFIG_FAILED
;
627 DEFUN (no_ospf_network_area
,
628 no_ospf_network_area_cmd
,
629 "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
631 "Enable routing on an IP network\n"
632 "OSPF network prefix\n"
633 "Set the OSPF area ID\n"
634 "OSPF area ID in IP address format\n"
635 "OSPF area ID as a decimal value\n")
637 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
638 int idx_ipv4_prefixlen
= 2;
639 int idx_ipv4_number
= 4;
640 struct prefix_ipv4 p
;
641 struct in_addr area_id
;
644 if (ospf
->instance
) {
646 "The network command is not supported in multi-instance ospf\n");
647 return CMD_WARNING_CONFIG_FAILED
;
650 /* Get network prefix and Area ID. */
651 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
652 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
654 ret
= ospf_network_unset(ospf
, &p
, area_id
);
657 "Can't find specified network area configuration.\n");
658 return CMD_WARNING_CONFIG_FAILED
;
664 DEFUN (ospf_area_range
,
666 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]",
667 "OSPF area parameters\n"
668 "OSPF area ID in IP address format\n"
669 "OSPF area ID as a decimal value\n"
670 "Summarize routes matching address/mask (border routers only)\n"
671 "Area range prefix\n"
672 "Advertise this range (default)\n"
673 "User specified metric for this range\n"
674 "Advertised metric for this range\n")
676 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
677 int idx_ipv4_number
= 1;
678 int idx_ipv4_prefixlen
= 3;
680 struct prefix_ipv4 p
;
681 struct in_addr area_id
;
685 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
686 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
688 ospf_area_range_set(ospf
, area_id
, &p
, OSPF_AREA_RANGE_ADVERTISE
);
690 cost
= strtoul(argv
[idx_cost
]->arg
, NULL
, 10);
691 ospf_area_range_cost_set(ospf
, area_id
, &p
, cost
);
697 DEFUN (ospf_area_range_cost
,
698 ospf_area_range_cost_cmd
,
699 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M cost (0-16777215)",
700 "OSPF area parameters\n"
701 "OSPF area ID in IP address format\n"
702 "OSPF area ID as a decimal value\n"
703 "Summarize routes matching address/mask (border routers only)\n"
704 "Area range prefix\n"
705 "User specified metric for this range\n"
706 "Advertised metric for this range\n")
708 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
709 int idx_ipv4_number
= 1;
710 int idx_ipv4_prefixlen
= 3;
712 struct prefix_ipv4 p
;
713 struct in_addr area_id
;
717 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
718 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
720 ospf_area_range_set(ospf
, area_id
, &p
, OSPF_AREA_RANGE_ADVERTISE
);
721 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
724 cost
= strtoul(argv
[idx_cost
]->arg
, NULL
, 10);
725 ospf_area_range_cost_set(ospf
, area_id
, &p
, cost
);
730 DEFUN (ospf_area_range_not_advertise
,
731 ospf_area_range_not_advertise_cmd
,
732 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise",
733 "OSPF area parameters\n"
734 "OSPF area ID in IP address format\n"
735 "OSPF area ID as a decimal value\n"
736 "Summarize routes matching address/mask (border routers only)\n"
737 "Area range prefix\n"
738 "DoNotAdvertise this range\n")
740 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
741 int idx_ipv4_number
= 1;
742 int idx_ipv4_prefixlen
= 3;
743 struct prefix_ipv4 p
;
744 struct in_addr area_id
;
747 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
748 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
750 ospf_area_range_set(ospf
, area_id
, &p
, 0);
751 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
757 DEFUN (no_ospf_area_range
,
758 no_ospf_area_range_cmd
,
759 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]",
761 "OSPF area parameters\n"
762 "OSPF area ID in IP address format\n"
763 "OSPF area ID as a decimal value\n"
764 "Summarize routes matching address/mask (border routers only)\n"
765 "Area range prefix\n"
766 "User specified metric for this range\n"
767 "Advertised metric for this range\n"
768 "Advertise this range (default)\n"
769 "User specified metric for this range\n"
770 "Advertised metric for this range\n"
771 "DoNotAdvertise this range\n")
773 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
774 int idx_ipv4_number
= 2;
775 int idx_ipv4_prefixlen
= 4;
776 struct prefix_ipv4 p
;
777 struct in_addr area_id
;
780 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
781 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
783 ospf_area_range_unset(ospf
, area_id
, &p
);
788 DEFUN (ospf_area_range_substitute
,
789 ospf_area_range_substitute_cmd
,
790 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
791 "OSPF area parameters\n"
792 "OSPF area ID in IP address format\n"
793 "OSPF area ID as a decimal value\n"
794 "Summarize routes matching address/mask (border routers only)\n"
795 "Area range prefix\n"
796 "Announce area range as another prefix\n"
797 "Network prefix to be announced instead of range\n")
799 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
800 int idx_ipv4_number
= 1;
801 int idx_ipv4_prefixlen
= 3;
802 int idx_ipv4_prefixlen_2
= 5;
803 struct prefix_ipv4 p
, s
;
804 struct in_addr area_id
;
807 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
808 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
809 str2prefix_ipv4(argv
[idx_ipv4_prefixlen_2
]->arg
, &s
);
811 ospf_area_range_substitute_set(ospf
, area_id
, &p
, &s
);
812 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
818 DEFUN (no_ospf_area_range_substitute
,
819 no_ospf_area_range_substitute_cmd
,
820 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
822 "OSPF area parameters\n"
823 "OSPF area ID in IP address format\n"
824 "OSPF area ID as a decimal value\n"
825 "Summarize routes matching address/mask (border routers only)\n"
826 "Area range prefix\n"
827 "Announce area range as another prefix\n"
828 "Network prefix to be announced instead of range\n")
830 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
831 int idx_ipv4_number
= 2;
832 int idx_ipv4_prefixlen
= 4;
833 int idx_ipv4_prefixlen_2
= 6;
834 struct prefix_ipv4 p
, s
;
835 struct in_addr area_id
;
838 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
839 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
840 str2prefix_ipv4(argv
[idx_ipv4_prefixlen_2
]->arg
, &s
);
842 ospf_area_range_substitute_unset(ospf
, area_id
, &p
);
848 /* Command Handler Logic in VLink stuff is delicate!!
850 ALTER AT YOUR OWN RISK!!!!
852 Various dummy values are used to represent 'NoChange' state for
853 VLink configuration NOT being changed by a VLink command, and
854 special syntax is used within the command strings so that the
855 typed in command verbs can be seen in the configuration command
856 bacckend handler. This is to drastically reduce the verbeage
857 required to coe up with a reasonably compatible Cisco VLink command
859 - Matthew Grant <grantma@anathoth.gen.nz>
860 Wed, 21 Feb 2001 15:13:52 +1300
863 /* Configuration data for virtual links
865 struct ospf_vl_config_data
{
866 struct vty
*vty
; /* vty stuff */
867 struct in_addr area_id
; /* area ID from command line */
868 int area_id_fmt
; /* command line area ID format */
869 struct in_addr vl_peer
; /* command line vl_peer */
870 int auth_type
; /* Authehntication type, if given */
871 char *auth_key
; /* simple password if present */
872 int crypto_key_id
; /* Cryptographic key ID */
873 char *md5_key
; /* MD5 authentication key */
874 int hello_interval
; /* Obvious what these are... */
875 int retransmit_interval
;
880 static void ospf_vl_config_data_init(struct ospf_vl_config_data
*vl_config
,
883 memset(vl_config
, 0, sizeof(struct ospf_vl_config_data
));
884 vl_config
->auth_type
= OSPF_AUTH_CMD_NOTSEEN
;
885 vl_config
->vty
= vty
;
888 static struct ospf_vl_data
*
889 ospf_find_vl_data(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
891 struct ospf_area
*area
;
892 struct ospf_vl_data
*vl_data
;
894 struct in_addr area_id
;
896 vty
= vl_config
->vty
;
897 area_id
= vl_config
->area_id
;
899 if (area_id
.s_addr
== OSPF_AREA_BACKBONE
) {
901 "Configuring VLs over the backbone is not allowed\n");
904 area
= ospf_area_get(ospf
, area_id
);
905 ospf_area_display_format_set(ospf
, area
, vl_config
->area_id_fmt
);
907 if (area
->external_routing
!= OSPF_AREA_DEFAULT
) {
908 if (vl_config
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
909 vty_out(vty
, "Area %s is %s\n", inet_ntoa(area_id
),
910 area
->external_routing
== OSPF_AREA_NSSA
914 vty_out(vty
, "Area %ld is %s\n",
915 (unsigned long)ntohl(area_id
.s_addr
),
916 area
->external_routing
== OSPF_AREA_NSSA
922 if ((vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
->vl_peer
))
924 vl_data
= ospf_vl_data_new(area
, vl_config
->vl_peer
);
925 if (vl_data
->vl_oi
== NULL
) {
926 vl_data
->vl_oi
= ospf_vl_new(ospf
, vl_data
);
927 ospf_vl_add(ospf
, vl_data
);
928 ospf_spf_calculate_schedule(ospf
,
929 SPF_FLAG_CONFIG_CHANGE
);
936 static int ospf_vl_set_security(struct ospf_vl_data
*vl_data
,
937 struct ospf_vl_config_data
*vl_config
)
939 struct crypt_key
*ck
;
941 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
943 vty
= vl_config
->vty
;
945 if (vl_config
->auth_type
!= OSPF_AUTH_CMD_NOTSEEN
) {
946 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), auth_type
);
947 IF_DEF_PARAMS(ifp
)->auth_type
= vl_config
->auth_type
;
950 if (vl_config
->auth_key
) {
951 memset(IF_DEF_PARAMS(ifp
)->auth_simple
, 0,
952 OSPF_AUTH_SIMPLE_SIZE
+ 1);
953 strncpy((char *)IF_DEF_PARAMS(ifp
)->auth_simple
,
954 vl_config
->auth_key
, OSPF_AUTH_SIMPLE_SIZE
);
955 } else if (vl_config
->md5_key
) {
956 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
957 vl_config
->crypto_key_id
)
959 vty_out(vty
, "OSPF: Key %d already exists\n",
960 vl_config
->crypto_key_id
);
963 ck
= ospf_crypt_key_new();
964 ck
->key_id
= vl_config
->crypto_key_id
;
965 memset(ck
->auth_key
, 0, OSPF_AUTH_MD5_SIZE
+ 1);
966 strncpy((char *)ck
->auth_key
, vl_config
->md5_key
,
969 ospf_crypt_key_add(IF_DEF_PARAMS(ifp
)->auth_crypt
, ck
);
970 } else if (vl_config
->crypto_key_id
!= 0) {
973 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
974 vl_config
->crypto_key_id
)
976 vty_out(vty
, "OSPF: Key %d does not exist\n",
977 vl_config
->crypto_key_id
);
978 return CMD_WARNING_CONFIG_FAILED
;
981 ospf_crypt_key_delete(IF_DEF_PARAMS(ifp
)->auth_crypt
,
982 vl_config
->crypto_key_id
);
988 static int ospf_vl_set_timers(struct ospf_vl_data
*vl_data
,
989 struct ospf_vl_config_data
*vl_config
)
991 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
992 /* Virtual Link data initialised to defaults, so only set
994 if (vl_config
->hello_interval
) {
995 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_hello
);
996 IF_DEF_PARAMS(ifp
)->v_hello
= vl_config
->hello_interval
;
999 if (vl_config
->dead_interval
) {
1000 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_wait
);
1001 IF_DEF_PARAMS(ifp
)->v_wait
= vl_config
->dead_interval
;
1004 if (vl_config
->retransmit_interval
) {
1005 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), retransmit_interval
);
1006 IF_DEF_PARAMS(ifp
)->retransmit_interval
=
1007 vl_config
->retransmit_interval
;
1010 if (vl_config
->transmit_delay
) {
1011 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), transmit_delay
);
1012 IF_DEF_PARAMS(ifp
)->transmit_delay
= vl_config
->transmit_delay
;
1019 /* The business end of all of the above */
1020 static int ospf_vl_set(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
1022 struct ospf_vl_data
*vl_data
;
1025 vl_data
= ospf_find_vl_data(ospf
, vl_config
);
1027 return CMD_WARNING_CONFIG_FAILED
;
1029 /* Process this one first as it can have a fatal result, which can
1030 only logically occur if the virtual link exists already
1031 Thus a command error does not result in a change to the
1032 running configuration such as unexpectedly altered timer
1034 ret
= ospf_vl_set_security(vl_data
, vl_config
);
1035 if (ret
!= CMD_SUCCESS
)
1038 /* Set any time based parameters, these area already range checked */
1040 ret
= ospf_vl_set_timers(vl_data
, vl_config
);
1041 if (ret
!= CMD_SUCCESS
)
1047 /* This stuff exists to make specifying all the alias commands A LOT simpler
1049 #define VLINK_HELPSTR_IPADDR \
1050 "OSPF area parameters\n" \
1051 "OSPF area ID in IP address format\n" \
1052 "OSPF area ID as a decimal value\n" \
1053 "Configure a virtual link\n" \
1054 "Router ID of the remote ABR\n"
1056 #define VLINK_HELPSTR_AUTHTYPE_SIMPLE \
1057 "Enable authentication on this virtual link\n" \
1060 #define VLINK_HELPSTR_AUTHTYPE_ALL \
1061 VLINK_HELPSTR_AUTHTYPE_SIMPLE \
1062 "Use null authentication\n" \
1063 "Use message-digest authentication\n"
1065 #define VLINK_HELPSTR_TIME_PARAM \
1066 "Time between HELLO packets\n" \
1068 "Time between retransmitting lost link state advertisements\n" \
1070 "Link state transmit delay\n" \
1072 "Interval time after which a neighbor is declared down\n" \
1075 #define VLINK_HELPSTR_AUTH_SIMPLE \
1076 "Authentication password (key)\n" \
1077 "The OSPF password (key)\n"
1079 #define VLINK_HELPSTR_AUTH_MD5 \
1080 "Message digest authentication password (key)\n" \
1082 "Use MD5 algorithm\n" \
1083 "The OSPF password (key)\n"
1085 DEFUN (ospf_area_vlink
,
1086 ospf_area_vlink_cmd
,
1087 "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>]",
1088 VLINK_HELPSTR_IPADDR
1089 "Enable authentication on this virtual link\n"
1090 "Use message-digest authentication\n"
1091 "Use null authentication\n"
1092 VLINK_HELPSTR_AUTH_MD5
1093 VLINK_HELPSTR_AUTH_SIMPLE
)
1095 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1096 int idx_ipv4_number
= 1;
1098 struct ospf_vl_config_data vl_config
;
1099 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1100 char md5_key
[OSPF_AUTH_MD5_SIZE
+ 1];
1104 ospf_vl_config_data_init(&vl_config
, vty
);
1106 /* Read off first 2 parameters and check them */
1107 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1108 &vl_config
.area_id_fmt
);
1110 vty_out(vty
, "OSPF area ID is invalid\n");
1111 return CMD_WARNING_CONFIG_FAILED
;
1114 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1116 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1117 return CMD_WARNING_CONFIG_FAILED
;
1121 /* Thats all folks! - BUGS B. strikes again!!!*/
1123 return ospf_vl_set(ospf
, &vl_config
);
1126 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1127 /* authentication - this option can only occur
1128 at start of command line */
1129 vl_config
.auth_type
= OSPF_AUTH_SIMPLE
;
1132 if (argv_find(argv
, argc
, "message-digest", &idx
)) {
1133 /* authentication message-digest */
1134 vl_config
.auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
1135 } else if (argv_find(argv
, argc
, "null", &idx
)) {
1136 /* "authentication null" */
1137 vl_config
.auth_type
= OSPF_AUTH_NULL
;
1140 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1141 vl_config
.md5_key
= NULL
;
1142 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1143 if (vl_config
.crypto_key_id
< 0)
1144 return CMD_WARNING_CONFIG_FAILED
;
1146 memset(md5_key
, 0, OSPF_AUTH_MD5_SIZE
+ 1);
1147 strncpy(md5_key
, argv
[idx
+ 3]->arg
, OSPF_AUTH_MD5_SIZE
);
1148 vl_config
.md5_key
= md5_key
;
1151 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1152 memset(auth_key
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
1153 strncpy(auth_key
, argv
[idx
+ 1]->arg
, OSPF_AUTH_SIMPLE_SIZE
);
1154 vl_config
.auth_key
= auth_key
;
1157 /* Action configuration */
1159 return ospf_vl_set(ospf
, &vl_config
);
1162 DEFUN (no_ospf_area_vlink
,
1163 no_ospf_area_vlink_cmd
,
1164 "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>]",
1166 VLINK_HELPSTR_IPADDR
1167 "Enable authentication on this virtual link\n" \
1168 "Use message-digest authentication\n" \
1169 "Use null authentication\n" \
1170 VLINK_HELPSTR_AUTH_MD5
1171 VLINK_HELPSTR_AUTH_SIMPLE
)
1173 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1174 int idx_ipv4_number
= 2;
1176 struct ospf_area
*area
;
1177 struct ospf_vl_config_data vl_config
;
1178 struct ospf_vl_data
*vl_data
= NULL
;
1179 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1183 ospf_vl_config_data_init(&vl_config
, vty
);
1185 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1188 vty_out(vty
, "OSPF area ID is invalid\n");
1189 return CMD_WARNING_CONFIG_FAILED
;
1192 area
= ospf_area_lookup_by_area_id(ospf
, vl_config
.area_id
);
1194 vty_out(vty
, "Area does not exist\n");
1195 return CMD_WARNING_CONFIG_FAILED
;
1198 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1200 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1201 return CMD_WARNING_CONFIG_FAILED
;
1205 /* Basic VLink no command */
1206 /* Thats all folks! - BUGS B. strikes again!!!*/
1207 if ((vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
.vl_peer
)))
1208 ospf_vl_delete(ospf
, vl_data
);
1210 ospf_area_check_free(ospf
, vl_config
.area_id
);
1215 /* If we are down here, we are reseting parameters */
1216 /* Deal with other parameters */
1218 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1219 /* authentication - this option can only occur
1220 at start of command line */
1221 vl_config
.auth_type
= OSPF_AUTH_NOTSET
;
1224 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1225 vl_config
.md5_key
= NULL
;
1226 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1227 if (vl_config
.crypto_key_id
< 0)
1228 return CMD_WARNING_CONFIG_FAILED
;
1231 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1232 /* Reset authentication-key to 0 */
1233 memset(auth_key
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
1234 vl_config
.auth_key
= auth_key
;
1237 /* Action configuration */
1239 return ospf_vl_set(ospf
, &vl_config
);
1242 DEFUN (ospf_area_vlink_intervals
,
1243 ospf_area_vlink_intervals_cmd
,
1244 "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)}",
1245 VLINK_HELPSTR_IPADDR
1246 VLINK_HELPSTR_TIME_PARAM
)
1248 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1249 struct ospf_vl_config_data vl_config
;
1252 ospf_vl_config_data_init(&vl_config
, vty
);
1254 char *area_id
= argv
[1]->arg
;
1255 char *router_id
= argv
[3]->arg
;
1257 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1259 vty_out(vty
, "OSPF area ID is invalid\n");
1260 return CMD_WARNING_CONFIG_FAILED
;
1263 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1265 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1266 return CMD_WARNING_CONFIG_FAILED
;
1269 for (int idx
= 4; idx
< argc
; idx
++) {
1270 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1271 vl_config
.hello_interval
=
1272 strtol(argv
[++idx
]->arg
, NULL
, 10);
1273 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1274 vl_config
.retransmit_interval
=
1275 strtol(argv
[++idx
]->arg
, NULL
, 10);
1276 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1277 vl_config
.transmit_delay
=
1278 strtol(argv
[++idx
]->arg
, NULL
, 10);
1279 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1280 vl_config
.dead_interval
=
1281 strtol(argv
[++idx
]->arg
, NULL
, 10);
1284 /* Action configuration */
1285 return ospf_vl_set(ospf
, &vl_config
);
1288 DEFUN (no_ospf_area_vlink_intervals
,
1289 no_ospf_area_vlink_intervals_cmd
,
1290 "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)}",
1292 VLINK_HELPSTR_IPADDR
1293 VLINK_HELPSTR_TIME_PARAM
)
1295 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1296 struct ospf_vl_config_data vl_config
;
1299 ospf_vl_config_data_init(&vl_config
, vty
);
1301 char *area_id
= argv
[2]->arg
;
1302 char *router_id
= argv
[4]->arg
;
1304 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1306 vty_out(vty
, "OSPF area ID is invalid\n");
1307 return CMD_WARNING_CONFIG_FAILED
;
1310 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1312 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1313 return CMD_WARNING_CONFIG_FAILED
;
1316 for (int idx
= 5; idx
< argc
; idx
++) {
1317 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1318 vl_config
.hello_interval
= OSPF_HELLO_INTERVAL_DEFAULT
;
1319 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1320 vl_config
.retransmit_interval
=
1321 OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
1322 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1323 vl_config
.transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
1324 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1325 vl_config
.dead_interval
=
1326 OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
1329 /* Action configuration */
1330 return ospf_vl_set(ospf
, &vl_config
);
1333 DEFUN (ospf_area_shortcut
,
1334 ospf_area_shortcut_cmd
,
1335 "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>",
1336 "OSPF area parameters\n"
1337 "OSPF area ID in IP address format\n"
1338 "OSPF area ID as a decimal value\n"
1339 "Configure the area's shortcutting mode\n"
1340 "Set default shortcutting behavior\n"
1341 "Enable shortcutting through the area\n"
1342 "Disable shortcutting through the area\n")
1344 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1345 int idx_ipv4_number
= 1;
1346 int idx_enable_disable
= 3;
1347 struct ospf_area
*area
;
1348 struct in_addr area_id
;
1352 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1353 argv
[idx_ipv4_number
]->arg
);
1355 area
= ospf_area_get(ospf
, area_id
);
1356 ospf_area_display_format_set(ospf
, area
, format
);
1358 if (strncmp(argv
[idx_enable_disable
]->arg
, "de", 2) == 0)
1359 mode
= OSPF_SHORTCUT_DEFAULT
;
1360 else if (strncmp(argv
[idx_enable_disable
]->arg
, "di", 2) == 0)
1361 mode
= OSPF_SHORTCUT_DISABLE
;
1362 else if (strncmp(argv
[idx_enable_disable
]->arg
, "e", 1) == 0)
1363 mode
= OSPF_SHORTCUT_ENABLE
;
1365 return CMD_WARNING_CONFIG_FAILED
;
1367 ospf_area_shortcut_set(ospf
, area
, mode
);
1369 if (ospf
->abr_type
!= OSPF_ABR_SHORTCUT
)
1371 "Shortcut area setting will take effect "
1372 "only when the router is configured as Shortcut ABR\n");
1377 DEFUN (no_ospf_area_shortcut
,
1378 no_ospf_area_shortcut_cmd
,
1379 "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>",
1381 "OSPF area parameters\n"
1382 "OSPF area ID in IP address format\n"
1383 "OSPF area ID as a decimal value\n"
1384 "Deconfigure the area's shortcutting mode\n"
1385 "Deconfigure enabled shortcutting through the area\n"
1386 "Deconfigure disabled shortcutting through the area\n")
1388 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1389 int idx_ipv4_number
= 2;
1390 struct ospf_area
*area
;
1391 struct in_addr area_id
;
1394 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1395 argv
[idx_ipv4_number
]->arg
);
1397 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1401 ospf_area_shortcut_unset(ospf
, area
);
1407 DEFUN (ospf_area_stub
,
1409 "area <A.B.C.D|(0-4294967295)> stub",
1410 "OSPF area parameters\n"
1411 "OSPF area ID in IP address format\n"
1412 "OSPF area ID as a decimal value\n"
1413 "Configure OSPF area as stub\n")
1415 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1416 int idx_ipv4_number
= 1;
1417 struct in_addr area_id
;
1420 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1421 argv
[idx_ipv4_number
]->arg
);
1423 ret
= ospf_area_stub_set(ospf
, area_id
);
1424 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1428 "First deconfigure all virtual link through this area\n");
1429 return CMD_WARNING_CONFIG_FAILED
;
1432 ospf_area_no_summary_unset(ospf
, area_id
);
1437 DEFUN (ospf_area_stub_no_summary
,
1438 ospf_area_stub_no_summary_cmd
,
1439 "area <A.B.C.D|(0-4294967295)> stub no-summary",
1440 "OSPF stub parameters\n"
1441 "OSPF area ID in IP address format\n"
1442 "OSPF area ID as a decimal value\n"
1443 "Configure OSPF area as stub\n"
1444 "Do not inject inter-area routes into stub\n")
1446 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1447 int idx_ipv4_number
= 1;
1448 struct in_addr area_id
;
1451 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1452 argv
[idx_ipv4_number
]->arg
);
1454 ret
= ospf_area_stub_set(ospf
, area_id
);
1455 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1459 "%% Area cannot be stub as it contains a virtual link\n");
1460 return CMD_WARNING_CONFIG_FAILED
;
1463 ospf_area_no_summary_set(ospf
, area_id
);
1468 DEFUN (no_ospf_area_stub
,
1469 no_ospf_area_stub_cmd
,
1470 "no area <A.B.C.D|(0-4294967295)> stub",
1472 "OSPF area parameters\n"
1473 "OSPF area ID in IP address format\n"
1474 "OSPF area ID as a decimal value\n"
1475 "Configure OSPF area as stub\n")
1477 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1478 int idx_ipv4_number
= 2;
1479 struct in_addr area_id
;
1482 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1483 argv
[idx_ipv4_number
]->arg
);
1485 ospf_area_stub_unset(ospf
, area_id
);
1486 ospf_area_no_summary_unset(ospf
, area_id
);
1491 DEFUN (no_ospf_area_stub_no_summary
,
1492 no_ospf_area_stub_no_summary_cmd
,
1493 "no area <A.B.C.D|(0-4294967295)> stub no-summary",
1495 "OSPF area parameters\n"
1496 "OSPF area ID in IP address format\n"
1497 "OSPF area ID as a decimal value\n"
1498 "Configure OSPF area as stub\n"
1499 "Do not inject inter-area routes into area\n")
1501 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1502 int idx_ipv4_number
= 2;
1503 struct in_addr area_id
;
1506 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1507 argv
[idx_ipv4_number
]->arg
);
1508 ospf_area_no_summary_unset(ospf
, area_id
);
1513 static int ospf_area_nssa_cmd_handler(struct vty
*vty
, int argc
,
1514 struct cmd_token
**argv
, int cfg_nosum
,
1517 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1518 struct in_addr area_id
;
1521 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
, argv
[1]->arg
);
1523 ret
= ospf_area_nssa_set(ospf
, area_id
);
1524 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1528 "%% Area cannot be nssa as it contains a virtual link\n");
1529 return CMD_WARNING_CONFIG_FAILED
;
1533 if (strncmp(argv
[3]->text
, "translate-c", 11) == 0)
1534 ospf_area_nssa_translator_role_set(
1535 ospf
, area_id
, OSPF_NSSA_ROLE_CANDIDATE
);
1536 else if (strncmp(argv
[3]->text
, "translate-n", 11) == 0)
1537 ospf_area_nssa_translator_role_set(
1538 ospf
, area_id
, OSPF_NSSA_ROLE_NEVER
);
1539 else if (strncmp(argv
[3]->text
, "translate-a", 11) == 0)
1540 ospf_area_nssa_translator_role_set(
1541 ospf
, area_id
, OSPF_NSSA_ROLE_ALWAYS
);
1543 ospf_area_nssa_translator_role_set(ospf
, area_id
,
1544 OSPF_NSSA_ROLE_CANDIDATE
);
1549 ospf_area_no_summary_set(ospf
, area_id
);
1551 ospf_area_no_summary_unset(ospf
, area_id
);
1554 ospf_schedule_abr_task(ospf
);
1560 DEFUN (ospf_area_nssa_translate
,
1561 ospf_area_nssa_translate_cmd
,
1562 "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always>",
1563 "OSPF area parameters\n"
1564 "OSPF area ID in IP address format\n"
1565 "OSPF area ID as a decimal value\n"
1566 "Configure OSPF area as nssa\n"
1567 "Configure NSSA-ABR for translate election (default)\n"
1568 "Configure NSSA-ABR to never translate\n"
1569 "Configure NSSA-ABR to always translate\n")
1571 return ospf_area_nssa_cmd_handler(vty
, argc
, argv
, 0, 0);
1574 DEFUN (ospf_area_nssa
,
1576 "area <A.B.C.D|(0-4294967295)> nssa",
1577 "OSPF area parameters\n"
1578 "OSPF area ID in IP address format\n"
1579 "OSPF area ID as a decimal value\n"
1580 "Configure OSPF area as nssa\n")
1582 return ospf_area_nssa_cmd_handler(vty
, argc
, argv
, 0, 0);
1585 DEFUN (ospf_area_nssa_no_summary
,
1586 ospf_area_nssa_no_summary_cmd
,
1587 "area <A.B.C.D|(0-4294967295)> nssa no-summary",
1588 "OSPF area parameters\n"
1589 "OSPF area ID in IP address format\n"
1590 "OSPF area ID as a decimal value\n"
1591 "Configure OSPF area as nssa\n"
1592 "Do not inject inter-area routes into nssa\n")
1594 int idx_ipv4_number
= 1;
1595 struct in_addr area_id
;
1598 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1599 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1600 argv
[idx_ipv4_number
]->arg
);
1602 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1604 ospf_area_nssa_no_summary_set(ospf
, area_id
);
1606 ospf_schedule_abr_task(ospf
);
1611 DEFUN (no_ospf_area_nssa_no_summary
,
1612 no_ospf_area_nssa_no_summary_cmd
,
1613 "no area <A.B.C.D|(0-4294967295)> nssa no-summary",
1615 "OSPF area parameters\n"
1616 "OSPF area ID in IP address format\n"
1617 "OSPF area ID as a decimal value\n"
1618 "Configure OSPF area as nssa\n"
1619 "Do not inject inter-area routes into nssa\n")
1621 int idx_ipv4_number
= 2;
1622 struct in_addr area_id
;
1625 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1627 VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id
, format
,
1628 argv
[idx_ipv4_number
]->arg
);
1630 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1632 ospf_area_no_summary_unset(ospf
, area_id
);
1634 ospf_schedule_abr_task(ospf
);
1639 DEFUN (no_ospf_area_nssa
,
1640 no_ospf_area_nssa_cmd
,
1641 "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always>]",
1643 "OSPF area parameters\n"
1644 "OSPF area ID in IP address format\n"
1645 "OSPF area ID as a decimal value\n"
1646 "Configure OSPF area as nssa\n"
1647 "Configure NSSA-ABR for translate election (default)\n"
1648 "Configure NSSA-ABR to never translate\n"
1649 "Configure NSSA-ABR to always translate\n")
1651 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1652 int idx_ipv4_number
= 2;
1653 struct in_addr area_id
;
1656 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1657 argv
[idx_ipv4_number
]->arg
);
1659 ospf_area_nssa_unset(ospf
, area_id
, argc
);
1661 ospf_schedule_abr_task(ospf
);
1667 DEFUN (ospf_area_default_cost
,
1668 ospf_area_default_cost_cmd
,
1669 "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1670 "OSPF area parameters\n"
1671 "OSPF area ID in IP address format\n"
1672 "OSPF area ID as a decimal value\n"
1673 "Set the summary-default cost of a NSSA or stub area\n"
1674 "Stub's advertised default summary cost\n")
1676 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1677 int idx_ipv4_number
= 1;
1679 struct ospf_area
*area
;
1680 struct in_addr area_id
;
1683 struct prefix_ipv4 p
;
1685 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1686 argv
[idx_ipv4_number
]->arg
);
1687 cost
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1689 area
= ospf_area_get(ospf
, area_id
);
1690 ospf_area_display_format_set(ospf
, area
, format
);
1692 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1693 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1694 return CMD_WARNING_CONFIG_FAILED
;
1697 area
->default_cost
= cost
;
1700 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1702 if (IS_DEBUG_OSPF_EVENT
)
1704 "ospf_abr_announce_stub_defaults(): "
1705 "announcing 0.0.0.0/0 to area %s",
1706 inet_ntoa(area
->area_id
));
1707 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1712 DEFUN (no_ospf_area_default_cost
,
1713 no_ospf_area_default_cost_cmd
,
1714 "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1716 "OSPF area parameters\n"
1717 "OSPF area ID in IP address format\n"
1718 "OSPF area ID as a decimal value\n"
1719 "Set the summary-default cost of a NSSA or stub area\n"
1720 "Stub's advertised default summary cost\n")
1722 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1723 int idx_ipv4_number
= 2;
1724 struct ospf_area
*area
;
1725 struct in_addr area_id
;
1727 struct prefix_ipv4 p
;
1729 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1730 argv
[idx_ipv4_number
]->arg
);
1732 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1736 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1737 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1738 return CMD_WARNING_CONFIG_FAILED
;
1741 area
->default_cost
= 1;
1744 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1746 if (IS_DEBUG_OSPF_EVENT
)
1748 "ospf_abr_announce_stub_defaults(): "
1749 "announcing 0.0.0.0/0 to area %s",
1750 inet_ntoa(area
->area_id
));
1751 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1754 ospf_area_check_free(ospf
, area_id
);
1759 DEFUN (ospf_area_export_list
,
1760 ospf_area_export_list_cmd
,
1761 "area <A.B.C.D|(0-4294967295)> export-list NAME",
1762 "OSPF area parameters\n"
1763 "OSPF area ID in IP address format\n"
1764 "OSPF area ID as a decimal value\n"
1765 "Set the filter for networks announced to other areas\n"
1766 "Name of the access-list\n")
1768 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1769 int idx_ipv4_number
= 1;
1770 struct ospf_area
*area
;
1771 struct in_addr area_id
;
1774 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1776 area
= ospf_area_get(ospf
, area_id
);
1777 ospf_area_display_format_set(ospf
, area
, format
);
1778 ospf_area_export_list_set(ospf
, area
, argv
[3]->arg
);
1783 DEFUN (no_ospf_area_export_list
,
1784 no_ospf_area_export_list_cmd
,
1785 "no area <A.B.C.D|(0-4294967295)> export-list NAME",
1787 "OSPF area parameters\n"
1788 "OSPF area ID in IP address format\n"
1789 "OSPF area ID as a decimal value\n"
1790 "Unset the filter for networks announced to other areas\n"
1791 "Name of the access-list\n")
1793 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1794 int idx_ipv4_number
= 2;
1795 struct ospf_area
*area
;
1796 struct in_addr area_id
;
1799 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1801 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1805 ospf_area_export_list_unset(ospf
, area
);
1811 DEFUN (ospf_area_import_list
,
1812 ospf_area_import_list_cmd
,
1813 "area <A.B.C.D|(0-4294967295)> import-list NAME",
1814 "OSPF area parameters\n"
1815 "OSPF area ID in IP address format\n"
1816 "OSPF area ID as a decimal value\n"
1817 "Set the filter for networks from other areas announced to the specified one\n"
1818 "Name of the access-list\n")
1820 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1821 int idx_ipv4_number
= 1;
1822 struct ospf_area
*area
;
1823 struct in_addr area_id
;
1826 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1828 area
= ospf_area_get(ospf
, area_id
);
1829 ospf_area_display_format_set(ospf
, area
, format
);
1830 ospf_area_import_list_set(ospf
, area
, argv
[3]->arg
);
1835 DEFUN (no_ospf_area_import_list
,
1836 no_ospf_area_import_list_cmd
,
1837 "no area <A.B.C.D|(0-4294967295)> import-list NAME",
1839 "OSPF area parameters\n"
1840 "OSPF area ID in IP address format\n"
1841 "OSPF area ID as a decimal value\n"
1842 "Unset the filter for networks announced to other areas\n"
1843 "Name of the access-list\n")
1845 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1846 int idx_ipv4_number
= 2;
1847 struct ospf_area
*area
;
1848 struct in_addr area_id
;
1851 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1853 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1857 ospf_area_import_list_unset(ospf
, area
);
1862 DEFUN (ospf_area_filter_list
,
1863 ospf_area_filter_list_cmd
,
1864 "area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>",
1865 "OSPF area parameters\n"
1866 "OSPF area ID in IP address format\n"
1867 "OSPF area ID as a decimal value\n"
1868 "Filter networks between OSPF areas\n"
1869 "Filter prefixes between OSPF areas\n"
1870 "Name of an IP prefix-list\n"
1871 "Filter networks sent to this area\n"
1872 "Filter networks sent from this area\n")
1874 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1875 int idx_ipv4_number
= 1;
1878 struct ospf_area
*area
;
1879 struct in_addr area_id
;
1880 struct prefix_list
*plist
;
1883 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1885 area
= ospf_area_get(ospf
, area_id
);
1886 ospf_area_display_format_set(ospf
, area
, format
);
1887 plist
= prefix_list_lookup(AFI_IP
, argv
[idx_word
]->arg
);
1888 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1889 PREFIX_LIST_IN(area
) = plist
;
1890 if (PREFIX_NAME_IN(area
))
1891 free(PREFIX_NAME_IN(area
));
1893 PREFIX_NAME_IN(area
) = strdup(argv
[idx_word
]->arg
);
1894 ospf_schedule_abr_task(ospf
);
1896 PREFIX_LIST_OUT(area
) = plist
;
1897 if (PREFIX_NAME_OUT(area
))
1898 free(PREFIX_NAME_OUT(area
));
1900 PREFIX_NAME_OUT(area
) = strdup(argv
[idx_word
]->arg
);
1901 ospf_schedule_abr_task(ospf
);
1907 DEFUN (no_ospf_area_filter_list
,
1908 no_ospf_area_filter_list_cmd
,
1909 "no area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>",
1911 "OSPF area parameters\n"
1912 "OSPF area ID in IP address format\n"
1913 "OSPF area ID as a decimal value\n"
1914 "Filter networks between OSPF areas\n"
1915 "Filter prefixes between OSPF areas\n"
1916 "Name of an IP prefix-list\n"
1917 "Filter networks sent to this area\n"
1918 "Filter networks sent from this area\n")
1920 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1921 int idx_ipv4_number
= 2;
1924 struct ospf_area
*area
;
1925 struct in_addr area_id
;
1928 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1930 if ((area
= ospf_area_lookup_by_area_id(ospf
, area_id
)) == NULL
)
1933 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1934 if (PREFIX_NAME_IN(area
))
1935 if (strcmp(PREFIX_NAME_IN(area
), argv
[idx_word
]->arg
)
1939 PREFIX_LIST_IN(area
) = NULL
;
1940 if (PREFIX_NAME_IN(area
))
1941 free(PREFIX_NAME_IN(area
));
1943 PREFIX_NAME_IN(area
) = NULL
;
1945 ospf_schedule_abr_task(ospf
);
1947 if (PREFIX_NAME_OUT(area
))
1948 if (strcmp(PREFIX_NAME_OUT(area
), argv
[idx_word
]->arg
)
1952 PREFIX_LIST_OUT(area
) = NULL
;
1953 if (PREFIX_NAME_OUT(area
))
1954 free(PREFIX_NAME_OUT(area
));
1956 PREFIX_NAME_OUT(area
) = NULL
;
1958 ospf_schedule_abr_task(ospf
);
1965 DEFUN (ospf_area_authentication_message_digest
,
1966 ospf_area_authentication_message_digest_cmd
,
1967 "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest",
1969 "OSPF area parameters\n"
1970 "OSPF area ID in IP address format\n"
1971 "OSPF area ID as a decimal value\n"
1972 "Enable authentication\n"
1973 "Use message-digest authentication\n")
1975 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1977 struct ospf_area
*area
;
1978 struct in_addr area_id
;
1981 argv_find(argv
, argc
, "area", &idx
);
1982 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx
+ 1]->arg
);
1984 area
= ospf_area_get(ospf
, area_id
);
1985 ospf_area_display_format_set(ospf
, area
, format
);
1986 area
->auth_type
= strmatch(argv
[0]->text
, "no")
1988 : OSPF_AUTH_CRYPTOGRAPHIC
;
1993 DEFUN (ospf_area_authentication
,
1994 ospf_area_authentication_cmd
,
1995 "area <A.B.C.D|(0-4294967295)> authentication",
1996 "OSPF area parameters\n"
1997 "OSPF area ID in IP address format\n"
1998 "OSPF area ID as a decimal value\n"
1999 "Enable authentication\n")
2001 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2002 int idx_ipv4_number
= 1;
2003 struct ospf_area
*area
;
2004 struct in_addr area_id
;
2007 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
2009 area
= ospf_area_get(ospf
, area_id
);
2010 ospf_area_display_format_set(ospf
, area
, format
);
2011 area
->auth_type
= OSPF_AUTH_SIMPLE
;
2016 DEFUN (no_ospf_area_authentication
,
2017 no_ospf_area_authentication_cmd
,
2018 "no area <A.B.C.D|(0-4294967295)> authentication",
2020 "OSPF area parameters\n"
2021 "OSPF area ID in IP address format\n"
2022 "OSPF area ID as a decimal value\n"
2023 "Enable authentication\n")
2025 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2026 int idx_ipv4_number
= 2;
2027 struct ospf_area
*area
;
2028 struct in_addr area_id
;
2031 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
2033 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
2037 area
->auth_type
= OSPF_AUTH_NULL
;
2039 ospf_area_check_free(ospf
, area_id
);
2045 DEFUN (ospf_abr_type
,
2047 "ospf abr-type <cisco|ibm|shortcut|standard>",
2048 "OSPF specific commands\n"
2049 "Set OSPF ABR type\n"
2050 "Alternative ABR, cisco implementation\n"
2051 "Alternative ABR, IBM implementation\n"
2053 "Standard behavior (RFC2328)\n")
2055 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2057 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2059 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2060 abr_type
= OSPF_ABR_CISCO
;
2061 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2062 abr_type
= OSPF_ABR_IBM
;
2063 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2064 abr_type
= OSPF_ABR_SHORTCUT
;
2065 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2066 abr_type
= OSPF_ABR_STAND
;
2068 return CMD_WARNING_CONFIG_FAILED
;
2070 /* If ABR type value is changed, schedule ABR task. */
2071 if (ospf
->abr_type
!= abr_type
) {
2072 ospf
->abr_type
= abr_type
;
2073 ospf_schedule_abr_task(ospf
);
2079 DEFUN (no_ospf_abr_type
,
2080 no_ospf_abr_type_cmd
,
2081 "no ospf abr-type <cisco|ibm|shortcut|standard>",
2083 "OSPF specific commands\n"
2084 "Set OSPF ABR type\n"
2085 "Alternative ABR, cisco implementation\n"
2086 "Alternative ABR, IBM implementation\n"
2090 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2092 uint8_t abr_type
= OSPF_ABR_UNKNOWN
;
2094 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2095 abr_type
= OSPF_ABR_CISCO
;
2096 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2097 abr_type
= OSPF_ABR_IBM
;
2098 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2099 abr_type
= OSPF_ABR_SHORTCUT
;
2100 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2101 abr_type
= OSPF_ABR_STAND
;
2103 return CMD_WARNING_CONFIG_FAILED
;
2105 /* If ABR type value is changed, schedule ABR task. */
2106 if (ospf
->abr_type
== abr_type
) {
2107 ospf
->abr_type
= OSPF_ABR_DEFAULT
;
2108 ospf_schedule_abr_task(ospf
);
2114 DEFUN (ospf_log_adjacency_changes
,
2115 ospf_log_adjacency_changes_cmd
,
2116 "log-adjacency-changes",
2117 "Log changes in adjacency state\n")
2119 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2121 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2122 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2126 DEFUN (ospf_log_adjacency_changes_detail
,
2127 ospf_log_adjacency_changes_detail_cmd
,
2128 "log-adjacency-changes detail",
2129 "Log changes in adjacency state\n"
2130 "Log all state changes\n")
2132 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2134 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2135 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2139 DEFUN (no_ospf_log_adjacency_changes
,
2140 no_ospf_log_adjacency_changes_cmd
,
2141 "no log-adjacency-changes",
2143 "Log changes in adjacency state\n")
2145 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2147 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2148 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2152 DEFUN (no_ospf_log_adjacency_changes_detail
,
2153 no_ospf_log_adjacency_changes_detail_cmd
,
2154 "no log-adjacency-changes detail",
2156 "Log changes in adjacency state\n"
2157 "Log all state changes\n")
2159 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2161 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2165 DEFUN (ospf_compatible_rfc1583
,
2166 ospf_compatible_rfc1583_cmd
,
2167 "compatible rfc1583",
2168 "OSPF compatibility list\n"
2169 "compatible with RFC 1583\n")
2171 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2173 if (!CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2174 SET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2175 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2180 DEFUN (no_ospf_compatible_rfc1583
,
2181 no_ospf_compatible_rfc1583_cmd
,
2182 "no compatible rfc1583",
2184 "OSPF compatibility list\n"
2185 "compatible with RFC 1583\n")
2187 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2189 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2190 UNSET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2191 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2196 ALIAS(ospf_compatible_rfc1583
, ospf_rfc1583_flag_cmd
,
2197 "ospf rfc1583compatibility",
2198 "OSPF specific commands\n"
2199 "Enable the RFC1583Compatibility flag\n")
2201 ALIAS(no_ospf_compatible_rfc1583
, no_ospf_rfc1583_flag_cmd
,
2202 "no ospf rfc1583compatibility", NO_STR
2203 "OSPF specific commands\n"
2204 "Disable the RFC1583Compatibility flag\n")
2206 static int ospf_timers_spf_set(struct vty
*vty
, unsigned int delay
,
2207 unsigned int hold
, unsigned int max
)
2209 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2211 ospf
->spf_delay
= delay
;
2212 ospf
->spf_holdtime
= hold
;
2213 ospf
->spf_max_holdtime
= max
;
2218 DEFUN (ospf_timers_min_ls_interval
,
2219 ospf_timers_min_ls_interval_cmd
,
2220 "timers throttle lsa all (0-5000)",
2221 "Adjust routing timers\n"
2222 "Throttling adaptive timer\n"
2223 "LSA delay between transmissions\n"
2225 "Delay (msec) between sending LSAs\n")
2227 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2229 unsigned int interval
;
2232 vty_out(vty
, "Insufficient arguments\n");
2233 return CMD_WARNING_CONFIG_FAILED
;
2236 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2238 ospf
->min_ls_interval
= interval
;
2243 DEFUN (no_ospf_timers_min_ls_interval
,
2244 no_ospf_timers_min_ls_interval_cmd
,
2245 "no timers throttle lsa all [(0-5000)]",
2247 "Adjust routing timers\n"
2248 "Throttling adaptive timer\n"
2249 "LSA delay between transmissions\n"
2251 "Delay (msec) between sending LSAs\n")
2253 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2254 ospf
->min_ls_interval
= OSPF_MIN_LS_INTERVAL
;
2259 DEFUN (ospf_timers_throttle_spf
,
2260 ospf_timers_throttle_spf_cmd
,
2261 "timers throttle spf (0-600000) (0-600000) (0-600000)",
2262 "Adjust routing timers\n"
2263 "Throttling adaptive timer\n"
2265 "Delay (msec) from first change received till SPF calculation\n"
2266 "Initial hold time (msec) between consecutive SPF calculations\n"
2267 "Maximum hold time (msec)\n")
2270 int idx_number_2
= 4;
2271 int idx_number_3
= 5;
2272 unsigned int delay
, hold
, max
;
2275 vty_out(vty
, "Insufficient arguments\n");
2276 return CMD_WARNING_CONFIG_FAILED
;
2279 delay
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2280 hold
= strtoul(argv
[idx_number_2
]->arg
, NULL
, 10);
2281 max
= strtoul(argv
[idx_number_3
]->arg
, NULL
, 10);
2283 return ospf_timers_spf_set(vty
, delay
, hold
, max
);
2286 DEFUN (no_ospf_timers_throttle_spf
,
2287 no_ospf_timers_throttle_spf_cmd
,
2288 "no timers throttle spf [(0-600000)(0-600000)(0-600000)]",
2290 "Adjust routing timers\n"
2291 "Throttling adaptive timer\n"
2293 "Delay (msec) from first change received till SPF calculation\n"
2294 "Initial hold time (msec) between consecutive SPF calculations\n"
2295 "Maximum hold time (msec)\n")
2297 return ospf_timers_spf_set(vty
, OSPF_SPF_DELAY_DEFAULT
,
2298 OSPF_SPF_HOLDTIME_DEFAULT
,
2299 OSPF_SPF_MAX_HOLDTIME_DEFAULT
);
2303 DEFUN (ospf_timers_lsa_min_arrival
,
2304 ospf_timers_lsa_min_arrival_cmd
,
2305 "timers lsa min-arrival (0-600000)",
2306 "Adjust routing timers\n"
2308 "Minimum delay in receiving new version of a LSA\n"
2309 "Delay in milliseconds\n")
2311 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2312 ospf
->min_ls_arrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2316 DEFUN (no_ospf_timers_lsa_min_arrival
,
2317 no_ospf_timers_lsa_min_arrival_cmd
,
2318 "no timers lsa min-arrival [(0-600000)]",
2320 "Adjust routing timers\n"
2322 "Minimum delay in receiving new version of a LSA\n"
2323 "Delay in milliseconds\n")
2325 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2326 unsigned int minarrival
;
2329 minarrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2331 if (ospf
->min_ls_arrival
!= minarrival
2332 || minarrival
== OSPF_MIN_LS_ARRIVAL
)
2336 ospf
->min_ls_arrival
= OSPF_MIN_LS_ARRIVAL
;
2341 #if defined(VERSION_TYPE_DEV) && CONFDATE > 20180708
2342 CPP_NOTICE("ospf: `timers lsa arrival (0-1000)` deprecated 2017/07/08")
2344 ALIAS_HIDDEN(ospf_timers_lsa_min_arrival
, ospf_timers_lsa_arrival_cmd
,
2345 "timers lsa arrival (0-1000)",
2346 "adjust routing timers\n"
2347 "throttling link state advertisement delays\n"
2348 "ospf minimum arrival interval delay\n"
2349 "delay (msec) between accepted lsas\n");
2351 #if defined(VERSION_TYPE_DEV) && CONFDATE > 20180708
2352 CPP_NOTICE("ospf: `no timers lsa arrival (0-1000)` deprecated 2017/07/08")
2354 ALIAS_HIDDEN(no_ospf_timers_lsa_min_arrival
, no_ospf_timers_lsa_arrival_cmd
,
2355 "no timers lsa arrival (0-1000)", NO_STR
2356 "adjust routing timers\n"
2357 "throttling link state advertisement delays\n"
2358 "ospf minimum arrival interval delay\n"
2359 "delay (msec) between accepted lsas\n");
2362 DEFUN (ospf_neighbor
,
2364 "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]",
2366 "Neighbor IP address\n"
2367 "Neighbor Priority\n"
2369 "Dead Neighbor Polling interval\n"
2372 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2376 struct in_addr nbr_addr
;
2377 unsigned int priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2378 unsigned int interval
= OSPF_POLL_INTERVAL_DEFAULT
;
2380 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2381 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2382 return CMD_WARNING_CONFIG_FAILED
;
2386 priority
= strtoul(argv
[idx_pri
]->arg
, NULL
, 10);
2389 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2391 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2394 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2397 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2402 DEFUN (ospf_neighbor_poll_interval
,
2403 ospf_neighbor_poll_interval_cmd
,
2404 "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2406 "Neighbor IP address\n"
2407 "Dead Neighbor Polling interval\n"
2409 "OSPF priority of non-broadcast neighbor\n"
2412 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2416 struct in_addr nbr_addr
;
2417 unsigned int priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2418 unsigned int interval
= OSPF_POLL_INTERVAL_DEFAULT
;
2420 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2421 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2422 return CMD_WARNING_CONFIG_FAILED
;
2425 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2428 priority
= strtoul(argv
[idx_pri
]->arg
, NULL
, 10);
2430 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2431 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2434 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2439 DEFUN (no_ospf_neighbor
,
2440 no_ospf_neighbor_cmd
,
2441 "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]",
2444 "Neighbor IP address\n"
2445 "Neighbor Priority\n"
2447 "Dead Neighbor Polling interval\n"
2450 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2452 struct in_addr nbr_addr
;
2454 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2455 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2456 return CMD_WARNING_CONFIG_FAILED
;
2459 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2464 DEFUN (no_ospf_neighbor_poll
,
2465 no_ospf_neighbor_poll_cmd
,
2466 "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2469 "Neighbor IP address\n"
2470 "Dead Neighbor Polling interval\n"
2472 "Neighbor Priority\n"
2475 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2477 struct in_addr nbr_addr
;
2479 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2480 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2481 return CMD_WARNING_CONFIG_FAILED
;
2484 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2489 DEFUN (ospf_refresh_timer
,
2490 ospf_refresh_timer_cmd
,
2491 "refresh timer (10-1800)",
2492 "Adjust refresh parameters\n"
2493 "Set refresh timer\n"
2494 "Timer value in seconds\n")
2496 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2498 unsigned int interval
;
2500 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2501 interval
= (interval
/ OSPF_LSA_REFRESHER_GRANULARITY
)
2502 * OSPF_LSA_REFRESHER_GRANULARITY
;
2504 ospf_timers_refresh_set(ospf
, interval
);
2509 DEFUN (no_ospf_refresh_timer
,
2510 no_ospf_refresh_timer_val_cmd
,
2511 "no refresh timer [(10-1800)]",
2513 "Adjust refresh parameters\n"
2514 "Unset refresh timer\n"
2515 "Timer value in seconds\n")
2517 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2519 unsigned int interval
;
2522 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2524 if (ospf
->lsa_refresh_interval
!= interval
2525 || interval
== OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
2529 ospf_timers_refresh_unset(ospf
);
2535 DEFUN (ospf_auto_cost_reference_bandwidth
,
2536 ospf_auto_cost_reference_bandwidth_cmd
,
2537 "auto-cost reference-bandwidth (1-4294967)",
2538 "Calculate OSPF interface cost according to bandwidth\n"
2539 "Use reference bandwidth method to assign OSPF cost\n"
2540 "The reference bandwidth in terms of Mbits per second\n")
2542 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2543 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2546 struct interface
*ifp
;
2548 refbw
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2549 if (refbw
< 1 || refbw
> 4294967) {
2550 vty_out(vty
, "reference-bandwidth value is invalid\n");
2551 return CMD_WARNING_CONFIG_FAILED
;
2554 /* If reference bandwidth is changed. */
2555 if ((refbw
) == ospf
->ref_bandwidth
)
2558 ospf
->ref_bandwidth
= refbw
;
2559 FOR_ALL_INTERFACES (vrf
, ifp
)
2560 ospf_if_recalculate_output_cost(ifp
);
2565 DEFUN (no_ospf_auto_cost_reference_bandwidth
,
2566 no_ospf_auto_cost_reference_bandwidth_cmd
,
2567 "no auto-cost reference-bandwidth [(1-4294967)]",
2569 "Calculate OSPF interface cost according to bandwidth\n"
2570 "Use reference bandwidth method to assign OSPF cost\n"
2571 "The reference bandwidth in terms of Mbits per second\n")
2573 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2574 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2575 struct interface
*ifp
;
2577 if (ospf
->ref_bandwidth
== OSPF_DEFAULT_REF_BANDWIDTH
)
2580 ospf
->ref_bandwidth
= OSPF_DEFAULT_REF_BANDWIDTH
;
2581 vty_out(vty
, "%% OSPF: Reference bandwidth is changed.\n");
2583 " Please ensure reference bandwidth is consistent across all routers\n");
2585 FOR_ALL_INTERFACES (vrf
, ifp
)
2586 ospf_if_recalculate_output_cost(ifp
);
2591 DEFUN (ospf_write_multiplier
,
2592 ospf_write_multiplier_cmd
,
2593 "ospf write-multiplier (1-100)",
2594 "OSPF specific commands\n"
2595 "Write multiplier\n"
2596 "Maximum number of interface serviced per write\n")
2598 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2600 uint32_t write_oi_count
;
2607 write_oi_count
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2608 if (write_oi_count
< 1 || write_oi_count
> 100) {
2609 vty_out(vty
, "write-multiplier value is invalid\n");
2610 return CMD_WARNING_CONFIG_FAILED
;
2613 ospf
->write_oi_count
= write_oi_count
;
2617 ALIAS(ospf_write_multiplier
, write_multiplier_cmd
, "write-multiplier (1-100)",
2618 "Write multiplier\n"
2619 "Maximum number of interface serviced per write\n")
2621 DEFUN (no_ospf_write_multiplier
,
2622 no_ospf_write_multiplier_cmd
,
2623 "no ospf write-multiplier (1-100)",
2625 "OSPF specific commands\n"
2626 "Write multiplier\n"
2627 "Maximum number of interface serviced per write\n")
2629 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2631 ospf
->write_oi_count
= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
;
2635 ALIAS(no_ospf_write_multiplier
, no_write_multiplier_cmd
,
2636 "no write-multiplier (1-100)", NO_STR
2637 "Write multiplier\n"
2638 "Maximum number of interface serviced per write\n")
2640 const char *ospf_abr_type_descr_str
[] = {"Unknown", "Standard (RFC2328)",
2641 "Alternative IBM", "Alternative Cisco",
2642 "Alternative Shortcut"};
2644 const char *ospf_shortcut_mode_descr_str
[] = {"Default", "Enabled", "Disabled"};
2646 static void show_ip_ospf_area(struct vty
*vty
, struct ospf_area
*area
,
2647 json_object
*json_areas
, uint8_t use_json
)
2649 json_object
*json_area
= NULL
;
2652 json_area
= json_object_new_object();
2656 vty_out(vty
, " Area ID: %s", inet_ntoa(area
->area_id
));
2658 /* Show Area type/mode. */
2659 if (OSPF_IS_AREA_BACKBONE(area
)) {
2661 json_object_boolean_true_add(json_area
, "backbone");
2663 vty_out(vty
, " (Backbone)\n");
2666 if (area
->external_routing
== OSPF_AREA_STUB
) {
2667 if (area
->no_summary
)
2668 json_object_boolean_true_add(
2669 json_area
, "stubNoSummary");
2670 if (area
->shortcut_configured
)
2671 json_object_boolean_true_add(
2672 json_area
, "stubShortcut");
2673 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
2674 if (area
->no_summary
)
2675 json_object_boolean_true_add(
2676 json_area
, "nssaNoSummary");
2677 if (area
->shortcut_configured
)
2678 json_object_boolean_true_add(
2679 json_area
, "nssaShortcut");
2682 json_object_string_add(
2683 json_area
, "shortcuttingMode",
2684 ospf_shortcut_mode_descr_str
2685 [area
->shortcut_configured
]);
2686 if (area
->shortcut_capability
)
2687 json_object_boolean_true_add(json_area
,
2690 if (area
->external_routing
== OSPF_AREA_STUB
)
2691 vty_out(vty
, " (Stub%s%s)",
2692 area
->no_summary
? ", no summary" : "",
2693 area
->shortcut_configured
? "; " : "");
2694 else if (area
->external_routing
== OSPF_AREA_NSSA
)
2695 vty_out(vty
, " (NSSA%s%s)",
2696 area
->no_summary
? ", no summary" : "",
2697 area
->shortcut_configured
? "; " : "");
2700 vty_out(vty
, " Shortcutting mode: %s",
2701 ospf_shortcut_mode_descr_str
2702 [area
->shortcut_configured
]);
2703 vty_out(vty
, ", S-bit consensus: %s\n",
2704 area
->shortcut_capability
? "ok" : "no");
2708 /* Show number of interfaces */
2710 json_object_int_add(json_area
, "areaIfTotalCounter",
2711 listcount(area
->oiflist
));
2712 json_object_int_add(json_area
, "areaIfActiveCounter",
2716 " Number of interfaces in this area: Total: %d, "
2718 listcount(area
->oiflist
), area
->act_ints
);
2720 if (area
->external_routing
== OSPF_AREA_NSSA
) {
2722 json_object_boolean_true_add(json_area
, "nssa");
2723 if (!IS_OSPF_ABR(area
->ospf
))
2724 json_object_boolean_false_add(json_area
, "abr");
2725 else if (area
->NSSATranslatorState
) {
2726 json_object_boolean_true_add(json_area
, "abr");
2727 if (area
->NSSATranslatorRole
2728 == OSPF_NSSA_ROLE_CANDIDATE
)
2729 json_object_boolean_true_add(
2731 "nssaTranslatorElected");
2732 else if (area
->NSSATranslatorRole
2733 == OSPF_NSSA_ROLE_ALWAYS
)
2734 json_object_boolean_true_add(
2736 "nssaTranslatorAlways");
2738 json_object_boolean_true_add(json_area
, "abr");
2739 if (area
->NSSATranslatorRole
2740 == OSPF_NSSA_ROLE_CANDIDATE
)
2741 json_object_boolean_false_add(
2743 "nssaTranslatorElected");
2745 json_object_boolean_true_add(
2747 "nssaTranslatorNever");
2751 " It is an NSSA configuration. \n Elected NSSA/ABR performs type-7/type-5 LSA translation. \n");
2752 if (!IS_OSPF_ABR(area
->ospf
))
2754 " It is not ABR, therefore not Translator. \n");
2755 else if (area
->NSSATranslatorState
) {
2756 vty_out(vty
, " We are an ABR and ");
2757 if (area
->NSSATranslatorRole
2758 == OSPF_NSSA_ROLE_CANDIDATE
)
2760 "the NSSA Elected Translator. \n");
2761 else if (area
->NSSATranslatorRole
2762 == OSPF_NSSA_ROLE_ALWAYS
)
2764 "always an NSSA Translator. \n");
2766 vty_out(vty
, " We are an ABR, but ");
2767 if (area
->NSSATranslatorRole
2768 == OSPF_NSSA_ROLE_CANDIDATE
)
2770 "not the NSSA Elected Translator. \n");
2773 "never an NSSA Translator. \n");
2778 /* Stub-router state for this area */
2779 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
)) {
2780 char timebuf
[OSPF_TIME_DUMP_SIZE
];
2783 json_object_boolean_true_add(
2784 json_area
, "originStubMaxDistRouterLsa");
2785 if (CHECK_FLAG(area
->stub_router_state
,
2786 OSPF_AREA_ADMIN_STUB_ROUTED
))
2787 json_object_boolean_true_add(
2788 json_area
, "indefiniteActiveAdmin");
2789 if (area
->t_stub_router
) {
2793 &area
->t_stub_router
->u
.sands
,
2796 json_object_int_add(
2798 "activeStartupRemainderMsecs",
2803 " Originating stub / maximum-distance Router-LSA\n");
2804 if (CHECK_FLAG(area
->stub_router_state
,
2805 OSPF_AREA_ADMIN_STUB_ROUTED
))
2807 " Administratively activated (indefinitely)\n");
2808 if (area
->t_stub_router
)
2810 " Active from startup, %s remaining\n",
2811 ospf_timer_dump(area
->t_stub_router
,
2818 /* Show number of fully adjacent neighbors. */
2819 json_object_int_add(json_area
, "nbrFullAdjacentCounter",
2822 /* Show authentication type. */
2823 if (area
->auth_type
== OSPF_AUTH_NULL
)
2824 json_object_string_add(json_area
, "authentication",
2825 "authenticationNone");
2826 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2827 json_object_string_add(json_area
, "authentication",
2828 "authenticationSimplePassword");
2829 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2830 json_object_string_add(json_area
, "authentication",
2831 "authenticationMessageDigest");
2833 if (!OSPF_IS_AREA_BACKBONE(area
))
2834 json_object_int_add(json_area
,
2835 "virtualAdjacenciesPassingCounter",
2838 /* Show SPF calculation times. */
2839 json_object_int_add(json_area
, "spfExecutedCounter",
2840 area
->spf_calculation
);
2841 json_object_int_add(json_area
, "lsaNumber", area
->lsdb
->total
);
2842 json_object_int_add(
2843 json_area
, "lsaRouterNumber",
2844 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
));
2845 json_object_int_add(
2846 json_area
, "lsaRouterChecksum",
2847 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
2848 json_object_int_add(
2849 json_area
, "lsaNetworkNumber",
2850 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
));
2851 json_object_int_add(
2852 json_area
, "lsaNetworkChecksum",
2853 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
2854 json_object_int_add(
2855 json_area
, "lsaSummaryNumber",
2856 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
));
2857 json_object_int_add(
2858 json_area
, "lsaSummaryChecksum",
2859 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
2860 json_object_int_add(
2861 json_area
, "lsaAsbrNumber",
2862 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2863 json_object_int_add(
2864 json_area
, "lsaAsbrChecksum",
2865 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2866 json_object_int_add(
2867 json_area
, "lsaNssaNumber",
2868 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2869 json_object_int_add(
2870 json_area
, "lsaNssaChecksum",
2871 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2873 /* Show number of fully adjacent neighbors. */
2875 " Number of fully adjacent neighbors in this area:"
2879 /* Show authentication type. */
2880 vty_out(vty
, " Area has ");
2881 if (area
->auth_type
== OSPF_AUTH_NULL
)
2882 vty_out(vty
, "no authentication\n");
2883 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2884 vty_out(vty
, "simple password authentication\n");
2885 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2886 vty_out(vty
, "message digest authentication\n");
2888 if (!OSPF_IS_AREA_BACKBONE(area
))
2890 " Number of full virtual adjacencies going through"
2894 /* Show SPF calculation times. */
2895 vty_out(vty
, " SPF algorithm executed %d times\n",
2896 area
->spf_calculation
);
2898 /* Show number of LSA. */
2899 vty_out(vty
, " Number of LSA %ld\n", area
->lsdb
->total
);
2901 " Number of router LSA %ld. Checksum Sum 0x%08x\n",
2902 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
),
2903 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
2905 " Number of network LSA %ld. Checksum Sum 0x%08x\n",
2906 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
),
2907 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
2909 " Number of summary LSA %ld. Checksum Sum 0x%08x\n",
2910 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
),
2911 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
2913 " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n",
2914 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
),
2915 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2916 vty_out(vty
, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n",
2917 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
),
2918 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2922 json_object_int_add(
2923 json_area
, "lsaOpaqueLinkNumber",
2924 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
2925 json_object_int_add(
2926 json_area
, "lsaOpaqueLinkChecksum",
2927 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
2928 json_object_int_add(
2929 json_area
, "lsaOpaqueAreaNumber",
2930 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
2931 json_object_int_add(
2932 json_area
, "lsaOpaqueAreaChecksum",
2933 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
2936 " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n",
2937 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
),
2938 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
2940 " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n",
2941 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
),
2942 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
2946 json_object_object_add(json_areas
, inet_ntoa(area
->area_id
),
2952 static int show_ip_ospf_common(struct vty
*vty
, struct ospf
*ospf
,
2953 json_object
*json
, uint8_t use_vrf
)
2955 struct listnode
*node
, *nnode
;
2956 struct ospf_area
*area
;
2957 struct timeval result
;
2958 char timebuf
[OSPF_TIME_DUMP_SIZE
];
2959 json_object
*json_vrf
= NULL
;
2960 json_object
*json_areas
= NULL
;
2964 json_vrf
= json_object_new_object();
2967 json_areas
= json_object_new_object();
2970 if (ospf
->instance
) {
2972 json_object_int_add(json
, "ospfInstance",
2975 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
2979 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
2981 /* Show Router ID. */
2983 json_object_string_add(json_vrf
, "routerId",
2984 inet_ntoa(ospf
->router_id
));
2986 vty_out(vty
, " OSPF Routing Process, Router ID: %s\n",
2987 inet_ntoa(ospf
->router_id
));
2990 /* Graceful shutdown */
2991 if (ospf
->t_deferred_shutdown
) {
2996 &ospf
->t_deferred_shutdown
->u
.sands
,
2999 json_object_int_add(json_vrf
, "deferredShutdownMsecs",
3003 " Deferred shutdown in progress, %s remaining\n",
3004 ospf_timer_dump(ospf
->t_deferred_shutdown
,
3005 timebuf
, sizeof(timebuf
)));
3009 /* Show capability. */
3011 json_object_boolean_true_add(json_vrf
, "tosRoutesOnly");
3012 json_object_boolean_true_add(json_vrf
, "rfc2328Conform");
3013 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
3014 json_object_boolean_true_add(json_vrf
,
3015 "rfc1583Compatibility");
3018 vty_out(vty
, " Supports only single TOS (TOS0) routes\n");
3019 vty_out(vty
, " This implementation conforms to RFC2328\n");
3020 vty_out(vty
, " RFC1583Compatibility flag is %s\n",
3021 CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)
3027 if (CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)) {
3028 json_object_boolean_true_add(json_vrf
, "opaqueCapable");
3031 vty_out(vty
, " OpaqueCapability flag is %s\n",
3032 CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)
3037 /* Show stub-router configuration */
3038 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
3039 || ospf
->stub_router_shutdown_time
3040 != OSPF_STUB_ROUTER_UNCONFIGURED
) {
3042 json_object_boolean_true_add(json_vrf
,
3043 "stubAdvertisement");
3044 if (ospf
->stub_router_startup_time
3045 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3046 json_object_int_add(
3047 json_vrf
, "postStartEnabledMsecs",
3048 ospf
->stub_router_startup_time
/ 1000);
3049 if (ospf
->stub_router_shutdown_time
3050 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3051 json_object_int_add(
3052 json_vrf
, "preShutdownEnabledMsecs",
3053 ospf
->stub_router_shutdown_time
/ 1000);
3056 " Stub router advertisement is configured\n");
3057 if (ospf
->stub_router_startup_time
3058 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3060 " Enabled for %us after start-up\n",
3061 ospf
->stub_router_startup_time
);
3062 if (ospf
->stub_router_shutdown_time
3063 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3065 " Enabled for %us prior to full shutdown\n",
3066 ospf
->stub_router_shutdown_time
);
3070 /* Show SPF timers. */
3072 json_object_int_add(json_vrf
, "spfScheduleDelayMsecs",
3074 json_object_int_add(json_vrf
, "holdtimeMinMsecs",
3075 ospf
->spf_holdtime
);
3076 json_object_int_add(json_vrf
, "holdtimeMaxMsecs",
3077 ospf
->spf_max_holdtime
);
3078 json_object_int_add(json_vrf
, "holdtimeMultplier",
3079 ospf
->spf_hold_multiplier
);
3082 " Initial SPF scheduling delay %d millisec(s)\n"
3083 " Minimum hold time between consecutive SPFs %d millisec(s)\n"
3084 " Maximum hold time between consecutive SPFs %d millisec(s)\n"
3085 " Hold time multiplier is currently %d\n",
3086 ospf
->spf_delay
, ospf
->spf_holdtime
,
3087 ospf
->spf_max_holdtime
, ospf
->spf_hold_multiplier
);
3091 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3092 long time_store
= 0;
3095 monotime_since(&ospf
->ts_spf
, NULL
) / 1000LL;
3096 json_object_int_add(json_vrf
, "spfLastExecutedMsecs",
3099 time_store
= (1000 * ospf
->ts_spf_duration
.tv_sec
)
3100 + (ospf
->ts_spf_duration
.tv_usec
/ 1000);
3101 json_object_int_add(json_vrf
, "spfLastDurationMsecs",
3104 json_object_boolean_true_add(json_vrf
, "spfHasNotRun");
3106 vty_out(vty
, " SPF algorithm ");
3107 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3108 monotime_since(&ospf
->ts_spf
, &result
);
3109 vty_out(vty
, "last executed %s ago\n",
3110 ospf_timeval_dump(&result
, timebuf
,
3112 vty_out(vty
, " Last SPF duration %s\n",
3113 ospf_timeval_dump(&ospf
->ts_spf_duration
,
3114 timebuf
, sizeof(timebuf
)));
3116 vty_out(vty
, "has not been run\n");
3120 if (ospf
->t_spf_calc
) {
3123 monotime_until(&ospf
->t_spf_calc
->u
.sands
, NULL
)
3125 json_object_int_add(json_vrf
, "spfTimerDueInMsecs",
3129 json_object_int_add(json_vrf
, "lsaMinIntervalMsecs",
3130 ospf
->min_ls_interval
);
3131 json_object_int_add(json_vrf
, "lsaMinArrivalMsecs",
3132 ospf
->min_ls_arrival
);
3133 /* Show write multiplier values */
3134 json_object_int_add(json_vrf
, "writeMultiplier",
3135 ospf
->write_oi_count
);
3136 /* Show refresh parameters. */
3137 json_object_int_add(json_vrf
, "refreshTimerMsecs",
3138 ospf
->lsa_refresh_interval
* 1000);
3140 vty_out(vty
, " SPF timer %s%s\n",
3141 (ospf
->t_spf_calc
? "due in " : "is "),
3142 ospf_timer_dump(ospf
->t_spf_calc
, timebuf
,
3145 vty_out(vty
, " LSA minimum interval %d msecs\n",
3146 ospf
->min_ls_interval
);
3147 vty_out(vty
, " LSA minimum arrival %d msecs\n",
3148 ospf
->min_ls_arrival
);
3150 /* Show write multiplier values */
3151 vty_out(vty
, " Write Multiplier set to %d \n",
3152 ospf
->write_oi_count
);
3154 /* Show refresh parameters. */
3155 vty_out(vty
, " Refresh timer %d secs\n",
3156 ospf
->lsa_refresh_interval
);
3159 /* Show ABR/ASBR flags. */
3160 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ABR
)) {
3162 json_object_string_add(
3163 json_vrf
, "abrType",
3164 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3167 " This router is an ABR, ABR type is: %s\n",
3168 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3170 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ASBR
)) {
3172 json_object_string_add(
3173 json_vrf
, "asbrRouter",
3174 "injectingExternalRoutingInformation");
3177 " This router is an ASBR "
3178 "(injecting external routing information)\n");
3181 /* Show Number of AS-external-LSAs. */
3183 json_object_int_add(
3184 json_vrf
, "lsaExternalCounter",
3185 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3186 json_object_int_add(
3187 json_vrf
, "lsaExternalChecksum",
3188 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3191 " Number of external LSA %ld. Checksum Sum 0x%08x\n",
3192 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
),
3193 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3197 json_object_int_add(
3198 json_vrf
, "lsaAsopaqueCounter",
3199 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3200 json_object_int_add(
3201 json_vrf
, "lsaAsOpaqueChecksum",
3202 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3205 " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n",
3206 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
),
3207 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3210 /* Show number of areas attached. */
3212 json_object_int_add(json_vrf
, "attachedAreaCounter",
3213 listcount(ospf
->areas
));
3215 vty_out(vty
, " Number of areas attached to this router: %d\n",
3216 listcount(ospf
->areas
));
3218 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
3219 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
)) {
3221 json_object_boolean_true_add(
3222 json_vrf
, "adjacencyChangesLoggedAll");
3225 " All adjacency changes are logged\n");
3228 json_object_boolean_true_add(
3229 json_vrf
, "adjacencyChangesLogged");
3231 vty_out(vty
, " Adjacency changes are logged\n");
3234 /* Show each area status. */
3235 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
3236 show_ip_ospf_area(vty
, area
, json_areas
, json
? 1 : 0);
3240 json_object_object_add(json_vrf
, "areas", json_areas
);
3241 if (ospf
->vrf_id
== VRF_DEFAULT
)
3242 json_object_object_add(json
, "default",
3245 json_object_object_add(json
, ospf
->name
,
3248 json_object_object_add(json
, "areas", json_areas
);
3256 DEFUN (show_ip_ospf
,
3258 "show ip ospf [vrf <NAME|all>] [json]",
3261 "OSPF information\n"
3267 uint8_t uj
= use_json(argc
, argv
);
3268 struct listnode
*node
= NULL
;
3269 char *vrf_name
= NULL
;
3270 bool all_vrf
= FALSE
;
3271 int ret
= CMD_SUCCESS
;
3274 json_object
*json
= NULL
;
3275 uint8_t use_vrf
= 0;
3277 if (listcount(om
->ospf
) == 0)
3280 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
3283 json
= json_object_new_object();
3285 /* vrf input is provided could be all or specific vrf*/
3289 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
3290 if (!ospf
->oi_running
)
3292 ret
= show_ip_ospf_common(vty
, ospf
, json
,
3296 vty_out(vty
, "%s\n",
3297 json_object_to_json_string_ext(
3298 json
, JSON_C_TO_STRING_PRETTY
));
3299 json_object_free(json
);
3303 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
3304 if ((ospf
== NULL
) || !ospf
->oi_running
) {
3306 json_object_free(json
);
3310 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
3311 /* Display default ospf (instance 0) info */
3312 if (ospf
== NULL
|| !ospf
->oi_running
) {
3314 json_object_free(json
);
3320 show_ip_ospf_common(vty
, ospf
, json
, use_vrf
);
3322 vty_out(vty
, "%s\n",
3323 json_object_to_json_string_ext(
3324 json
, JSON_C_TO_STRING_PRETTY
));
3328 json_object_free(json
);
3333 DEFUN (show_ip_ospf_instance
,
3334 show_ip_ospf_instance_cmd
,
3335 "show ip ospf (1-65535) [json]",
3338 "OSPF information\n"
3344 unsigned short instance
= 0;
3345 uint8_t uj
= use_json(argc
, argv
);
3346 int ret
= CMD_SUCCESS
;
3347 json_object
*json
= NULL
;
3349 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
3350 ospf
= ospf_lookup_instance(instance
);
3352 return CMD_NOT_MY_INSTANCE
;
3354 if (!ospf
->oi_running
)
3358 json
= json_object_new_object();
3360 ret
= show_ip_ospf_common(vty
, ospf
, json
, 0);
3363 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
3364 json
, JSON_C_TO_STRING_PRETTY
));
3365 json_object_free(json
);
3371 static void show_ip_ospf_interface_sub(struct vty
*vty
, struct ospf
*ospf
,
3372 struct interface
*ifp
,
3373 json_object
*json_interface_sub
,
3377 struct ospf_neighbor
*nbr
;
3378 struct route_node
*rn
;
3379 uint32_t bandwidth
= ifp
->bandwidth
? ifp
->bandwidth
: ifp
->speed
;
3381 /* Is interface up? */
3383 is_up
= if_is_operative(ifp
);
3385 json_object_boolean_true_add(json_interface_sub
,
3388 json_object_boolean_false_add(json_interface_sub
,
3391 json_object_int_add(json_interface_sub
, "ifIndex",
3393 json_object_int_add(json_interface_sub
, "mtuBytes", ifp
->mtu
);
3394 json_object_int_add(json_interface_sub
, "bandwidthMbit",
3396 json_object_string_add(json_interface_sub
, "ifFlags",
3397 if_flag_dump(ifp
->flags
));
3399 vty_out(vty
, "%s is %s\n", ifp
->name
,
3400 ((is_up
= if_is_operative(ifp
)) ? "up" : "down"));
3401 vty_out(vty
, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n",
3402 ifp
->ifindex
, ifp
->mtu
, bandwidth
,
3403 if_flag_dump(ifp
->flags
));
3406 /* Is interface OSPF enabled? */
3408 if (ospf_oi_count(ifp
) == 0) {
3409 json_object_boolean_false_add(json_interface_sub
,
3412 } else if (!is_up
) {
3413 json_object_boolean_false_add(json_interface_sub
,
3417 json_object_boolean_true_add(json_interface_sub
,
3420 if (ospf_oi_count(ifp
) == 0) {
3421 vty_out(vty
, " OSPF not enabled on this interface\n");
3423 } else if (!is_up
) {
3425 " OSPF is enabled, but not running on this interface\n");
3430 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
3431 struct ospf_interface
*oi
= rn
->info
;
3436 if (CHECK_FLAG(oi
->connected
->flags
, ZEBRA_IFA_UNNUMBERED
)) {
3438 json_object_boolean_true_add(json_interface_sub
,
3441 vty_out(vty
, " This interface is UNNUMBERED,");
3443 /* Show OSPF interface information. */
3445 json_object_string_add(
3446 json_interface_sub
, "ipAddress",
3447 inet_ntoa(oi
->address
->u
.prefix4
));
3448 json_object_int_add(json_interface_sub
,
3449 "ipAddressPrefixlen",
3450 oi
->address
->prefixlen
);
3452 vty_out(vty
, " Internet Address %s/%d,",
3453 inet_ntoa(oi
->address
->u
.prefix4
),
3454 oi
->address
->prefixlen
);
3456 if (oi
->connected
->destination
3457 || oi
->type
== OSPF_IFTYPE_VIRTUALLINK
) {
3458 struct in_addr
*dest
;
3461 if (CONNECTED_PEER(oi
->connected
)
3462 || oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3467 /* For Vlinks, showing the peer address is
3469 * * * * * informative than the local
3470 * interface that is being used
3472 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3473 dest
= &oi
->vl_data
->peer_addr
;
3475 dest
= &oi
->connected
->destination
->u
3479 json_object_string_add(
3481 "ospfIfType", dstr
);
3482 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3483 json_object_string_add(
3488 json_object_string_add(
3493 vty_out(vty
, " %s %s,", dstr
,
3498 json_object_string_add(json_interface_sub
, "area",
3499 ospf_area_desc_string(oi
->area
));
3500 if (OSPF_IF_PARAM(oi
, mtu_ignore
))
3501 json_object_boolean_true_add(
3503 "mtuMismatchDetect");
3504 json_object_string_add(json_interface_sub
, "routerId",
3505 inet_ntoa(ospf
->router_id
));
3506 json_object_string_add(json_interface_sub
,
3508 ospf_network_type_str
[oi
->type
]);
3509 json_object_int_add(json_interface_sub
, "cost",
3511 json_object_int_add(
3512 json_interface_sub
, "transmitDelayMsecs",
3513 1000 / OSPF_IF_PARAM(oi
, transmit_delay
));
3514 json_object_string_add(json_interface_sub
, "state",
3515 lookup_msg(ospf_ism_state_msg
,
3517 json_object_int_add(json_interface_sub
, "priority",
3520 vty_out(vty
, " Area %s\n",
3521 ospf_area_desc_string(oi
->area
));
3523 vty_out(vty
, " MTU mismatch detection: %s\n",
3524 OSPF_IF_PARAM(oi
, mtu_ignore
) ? "disabled"
3528 " Router ID %s, Network Type %s, Cost: %d\n",
3529 inet_ntoa(ospf
->router_id
),
3530 ospf_network_type_str
[oi
->type
],
3534 " Transmit Delay is %d sec, State %s, Priority %d\n",
3535 OSPF_IF_PARAM(oi
, transmit_delay
),
3536 lookup_msg(ospf_ism_state_msg
, oi
->state
, NULL
),
3540 /* Show DR information. */
3541 if (DR(oi
).s_addr
== 0) {
3544 " No backup designated router on this network\n");
3546 nbr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &BDR(oi
));
3550 " No backup designated router on this network\n");
3553 json_object_string_add(
3554 json_interface_sub
, "bdrId",
3555 inet_ntoa(nbr
->router_id
));
3556 json_object_string_add(
3559 inet_ntoa(nbr
->address
.u
3563 " Backup Designated Router (ID) %s,",
3564 inet_ntoa(nbr
->router_id
));
3565 vty_out(vty
, " Interface Address %s\n",
3566 inet_ntoa(nbr
->address
.u
3572 /* Next network-LSA sequence number we'll use, if we're elected
3575 && ntohl(oi
->params
->network_lsa_seqnum
)
3576 != OSPF_INITIAL_SEQUENCE_NUMBER
) {
3578 json_object_int_add(
3580 "networkLsaSequence",
3581 ntohl(oi
->params
->network_lsa_seqnum
));
3584 " Saved Network-LSA sequence number 0x%x\n",
3585 ntohl(oi
->params
->network_lsa_seqnum
));
3589 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3590 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3591 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3592 json_object_boolean_true_add(
3594 "mcastMemberOspfAllRouters");
3595 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3596 json_object_boolean_true_add(
3598 "mcastMemberOspfDesignatedRouters");
3601 vty_out(vty
, " Multicast group memberships:");
3602 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3603 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3604 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3605 vty_out(vty
, " OSPFAllRouters");
3606 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3607 vty_out(vty
, " OSPFDesignatedRouters");
3609 vty_out(vty
, " <None>");
3614 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3615 json_object_int_add(
3616 json_interface_sub
, "timerMsecs",
3617 1000 / OSPF_IF_PARAM(oi
, v_hello
));
3619 json_object_int_add(
3620 json_interface_sub
, "timerMsecs",
3621 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3622 json_object_int_add(json_interface_sub
,
3624 1000 / OSPF_IF_PARAM(oi
, v_wait
));
3625 json_object_int_add(json_interface_sub
,
3627 1000 / OSPF_IF_PARAM(oi
, v_wait
));
3628 json_object_int_add(
3629 json_interface_sub
, "timerRetransmit",
3630 1000 / OSPF_IF_PARAM(oi
, retransmit_interval
));
3632 vty_out(vty
, " Timer intervals configured,");
3633 vty_out(vty
, " Hello ");
3634 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3635 vty_out(vty
, "%ds,",
3636 OSPF_IF_PARAM(oi
, v_hello
));
3638 vty_out(vty
, "%dms,",
3639 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3640 vty_out(vty
, " Dead %ds, Wait %ds, Retransmit %d\n",
3641 OSPF_IF_PARAM(oi
, v_wait
),
3642 OSPF_IF_PARAM(oi
, v_wait
),
3643 OSPF_IF_PARAM(oi
, retransmit_interval
));
3646 if (OSPF_IF_PASSIVE_STATUS(oi
) == OSPF_IF_ACTIVE
) {
3647 char timebuf
[OSPF_TIME_DUMP_SIZE
];
3649 long time_store
= 0;
3653 &oi
->t_hello
->u
.sands
,
3656 json_object_int_add(json_interface_sub
,
3657 "timerHelloInMsecs",
3660 vty_out(vty
, " Hello due in %s\n",
3661 ospf_timer_dump(oi
->t_hello
, timebuf
,
3663 } else /* passive-interface is set */
3666 json_object_boolean_true_add(
3668 "timerPassiveIface");
3671 " No Hellos (Passive interface)\n");
3675 json_object_int_add(json_interface_sub
, "nbrCount",
3676 ospf_nbr_count(oi
, 0));
3677 json_object_int_add(json_interface_sub
,
3679 ospf_nbr_count(oi
, NSM_Full
));
3682 " Neighbor Count is %d, Adjacent neighbor count is %d\n",
3683 ospf_nbr_count(oi
, 0),
3684 ospf_nbr_count(oi
, NSM_Full
));
3685 ospf_bfd_interface_show(vty
, ifp
, json_interface_sub
, use_json
);
3689 static int show_ip_ospf_interface_common(struct vty
*vty
, struct ospf
*ospf
,
3690 char *intf_name
, uint8_t use_vrf
,
3691 json_object
*json
, uint8_t use_json
)
3693 struct interface
*ifp
;
3694 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
3695 json_object
*json_vrf
= NULL
;
3696 json_object
*json_interface_sub
= NULL
, *json_interface
= NULL
;
3700 json_vrf
= json_object_new_object();
3703 json_interface
= json_object_new_object();
3706 if (ospf
->instance
) {
3708 json_object_int_add(json
, "ospfInstance",
3711 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
3714 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3716 if (intf_name
== NULL
) {
3717 /* Show All Interfaces.*/
3718 FOR_ALL_INTERFACES (vrf
, ifp
) {
3719 if (ospf_oi_count(ifp
)) {
3721 json_interface_sub
=
3722 json_object_new_object();
3724 show_ip_ospf_interface_sub(vty
, ospf
, ifp
,
3729 json_object_object_add(
3730 json_interface
, ifp
->name
,
3731 json_interface_sub
);
3736 json_object_object_add(json_vrf
, "interfaces",
3739 /* Interface name is specified. */
3740 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
3743 json_object_boolean_true_add(json_vrf
,
3746 vty_out(vty
, "No such interface name\n");
3749 json_interface_sub
= json_object_new_object();
3750 json_interface
= json_object_new_object();
3753 show_ip_ospf_interface_sub(
3754 vty
, ospf
, ifp
, json_interface_sub
, use_json
);
3757 json_object_object_add(json_interface
,
3759 json_interface_sub
);
3760 json_object_object_add(json_vrf
, "interfaces",
3768 if (ospf
->vrf_id
== VRF_DEFAULT
)
3769 json_object_object_add(json
, "default",
3772 json_object_object_add(json
, ospf
->name
,
3781 static void show_ip_ospf_interface_traffic_sub(struct vty
*vty
,
3782 struct ospf_interface
*oi
,
3783 json_object
*json_interface_sub
,
3787 json_object_int_add(json_interface_sub
, "ifIndex",
3789 json_object_int_add(json_interface_sub
, "helloIn",
3791 json_object_int_add(json_interface_sub
, "helloOut",
3793 json_object_int_add(json_interface_sub
, "dbDescIn",
3795 json_object_int_add(json_interface_sub
, "dbDescOut",
3797 json_object_int_add(json_interface_sub
, "lsReqIn",
3799 json_object_int_add(json_interface_sub
, "lsReqOut",
3801 json_object_int_add(json_interface_sub
, "lsUpdIn",
3803 json_object_int_add(json_interface_sub
, "lsUpdOut",
3805 json_object_int_add(json_interface_sub
, "lsAckIn",
3807 json_object_int_add(json_interface_sub
, "lsAckOut",
3811 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n",
3812 oi
->ifp
->name
, oi
->hello_in
, oi
->hello_out
,
3813 oi
->db_desc_in
, oi
->db_desc_out
, oi
->ls_req_in
,
3814 oi
->ls_req_out
, oi
->ls_upd_in
, oi
->ls_upd_out
,
3815 oi
->ls_ack_in
, oi
->ls_ack_out
);
3819 /* OSPFv2 Packet Counters */
3820 static int show_ip_ospf_interface_traffic_common(
3821 struct vty
*vty
, struct ospf
*ospf
, char *intf_name
, json_object
*json
,
3822 int display_once
, uint8_t use_vrf
, uint8_t use_json
)
3824 struct vrf
*vrf
= NULL
;
3825 struct interface
*ifp
= NULL
;
3826 json_object
*json_vrf
= NULL
;
3827 json_object
*json_interface_sub
= NULL
;
3829 if (!use_json
&& !display_once
) {
3831 vty_out(vty
, "%-12s%-17s%-17s%-17s%-17s%-17s\n", "Interface",
3832 " HELLO", " DB-Desc", " LS-Req", " LS-Update",
3834 vty_out(vty
, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "",
3835 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
3838 "--------------------------------------------------------------------------------------------\n");
3839 } else if (use_json
) {
3841 json_vrf
= json_object_new_object();
3846 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3848 if (intf_name
== NULL
) {
3849 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
3850 FOR_ALL_INTERFACES (vrf
, ifp
) {
3851 struct route_node
*rn
;
3852 struct ospf_interface
*oi
;
3854 if (ospf_oi_count(ifp
) == 0)
3857 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
3858 rn
= route_next(rn
)) {
3865 json_interface_sub
=
3866 json_object_new_object();
3869 show_ip_ospf_interface_traffic_sub(
3870 vty
, oi
, json_interface_sub
, use_json
);
3872 json_object_object_add(
3873 json_vrf
, ifp
->name
,
3874 json_interface_sub
);
3879 /* Interface name is specified. */
3880 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
3882 struct route_node
*rn
;
3883 struct ospf_interface
*oi
;
3885 if (ospf_oi_count(ifp
) == 0) {
3887 " OSPF not enabled on this interface %s\n",
3892 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
3893 rn
= route_next(rn
)) {
3897 json_interface_sub
=
3898 json_object_new_object();
3901 show_ip_ospf_interface_traffic_sub(
3902 vty
, oi
, json_interface_sub
, use_json
);
3904 json_object_object_add(
3905 json_vrf
, ifp
->name
,
3906 json_interface_sub
);
3914 if (ospf
->vrf_id
== VRF_DEFAULT
)
3915 json_object_object_add(json
, "default",
3918 json_object_object_add(json
, ospf
->name
,
3927 DEFUN (show_ip_ospf_interface
,
3928 show_ip_ospf_interface_cmd
,
3929 "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]",
3932 "OSPF information\n"
3935 "Interface information\n"
3940 uint8_t uj
= use_json(argc
, argv
);
3941 struct listnode
*node
= NULL
;
3942 char *vrf_name
= NULL
, *intf_name
= NULL
;
3943 bool all_vrf
= FALSE
;
3944 int ret
= CMD_SUCCESS
;
3946 int idx_vrf
= 0, idx_intf
= 0;
3947 uint8_t use_vrf
= 0;
3948 json_object
*json
= NULL
;
3950 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
3952 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
3953 intf_name
= argv
[idx_intf
]->arg
;
3956 json
= json_object_new_object();
3958 /* vrf input is provided could be all or specific vrf*/
3962 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
3963 if (!ospf
->oi_running
)
3965 ret
= show_ip_ospf_interface_common(
3966 vty
, ospf
, intf_name
, use_vrf
, json
,
3971 vty_out(vty
, "%s\n",
3972 json_object_to_json_string_ext(
3973 json
, JSON_C_TO_STRING_PRETTY
));
3974 json_object_free(json
);
3979 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
3980 if (ospf
== NULL
|| !ospf
->oi_running
) {
3982 json_object_free(json
);
3985 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
3989 /* Display default ospf (instance 0) info */
3990 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
3991 if (ospf
== NULL
|| !ospf
->oi_running
) {
3993 json_object_free(json
);
3996 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
4001 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4002 json
, JSON_C_TO_STRING_PRETTY
));
4003 json_object_free(json
);
4009 DEFUN (show_ip_ospf_instance_interface
,
4010 show_ip_ospf_instance_interface_cmd
,
4011 "show ip ospf (1-65535) interface [INTERFACE] [json]",
4014 "OSPF information\n"
4016 "Interface information\n"
4023 unsigned short instance
= 0;
4024 uint8_t uj
= use_json(argc
, argv
);
4025 char *intf_name
= NULL
;
4026 int ret
= CMD_SUCCESS
;
4027 json_object
*json
= NULL
;
4029 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4030 ospf
= ospf_lookup_instance(instance
);
4032 return CMD_NOT_MY_INSTANCE
;
4034 if (!ospf
->oi_running
)
4038 json
= json_object_new_object();
4040 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4041 intf_name
= argv
[idx_intf
]->arg
;
4043 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
, 0, json
, uj
);
4046 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4047 json
, JSON_C_TO_STRING_PRETTY
));
4048 json_object_free(json
);
4054 DEFUN (show_ip_ospf_interface_traffic
,
4055 show_ip_ospf_interface_traffic_cmd
,
4056 "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]",
4059 "OSPF information\n"
4062 "Interface information\n"
4063 "Protocol Packet counters\n"
4067 struct ospf
*ospf
= NULL
;
4068 struct listnode
*node
= NULL
;
4069 char *vrf_name
= NULL
, *intf_name
= NULL
;
4070 bool all_vrf
= FALSE
;
4072 int idx_vrf
= 0, idx_intf
= 0;
4073 uint8_t uj
= use_json(argc
, argv
);
4074 json_object
*json
= NULL
;
4075 int ret
= CMD_SUCCESS
;
4076 int display_once
= 0;
4077 uint8_t use_vrf
= 0;
4079 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4081 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4082 intf_name
= argv
[idx_intf
]->arg
;
4085 json
= json_object_new_object();
4090 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4091 if (!ospf
->oi_running
)
4094 ret
= show_ip_ospf_interface_traffic_common(
4095 vty
, ospf
, intf_name
, json
,
4096 display_once
, use_vrf
, uj
);
4101 vty_out(vty
, "%s\n",
4102 json_object_to_json_string_ext(
4103 json
, JSON_C_TO_STRING_PRETTY
));
4104 json_object_free(json
);
4109 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4110 if (ospf
== NULL
|| !ospf
->oi_running
) {
4112 json_object_free(json
);
4116 ret
= show_ip_ospf_interface_traffic_common(
4117 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4119 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4120 if (ospf
== NULL
|| !ospf
->oi_running
) {
4122 json_object_free(json
);
4126 ret
= show_ip_ospf_interface_traffic_common(
4127 vty
, ospf
, intf_name
, json
, display_once
, use_vrf
, uj
);
4131 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4132 json
, JSON_C_TO_STRING_PRETTY
));
4133 json_object_free(json
);
4140 static void show_ip_ospf_neighbour_header(struct vty
*vty
)
4142 vty_out(vty
, "\n%-15s %3s %-15s %9s %-15s %-20s %5s %5s %5s\n",
4143 "Neighbor ID", "Pri", "State", "Dead Time", "Address",
4144 "Interface", "RXmtL", "RqstL", "DBsmL");
4147 static void show_ip_ospf_neighbor_sub(struct vty
*vty
,
4148 struct ospf_interface
*oi
,
4149 json_object
*json
, uint8_t use_json
)
4151 struct route_node
*rn
;
4152 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
4154 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4155 json_object
*json_neighbor
= NULL
, *json_neigh_array
= NULL
;
4157 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
4158 if ((nbr
= rn
->info
)) {
4159 /* Do not show myself. */
4160 if (nbr
== oi
->nbr_self
)
4162 /* Down state is not shown. */
4163 if (nbr
->state
== NSM_Down
)
4166 char neigh_str
[INET_ADDRSTRLEN
];
4169 && !IPV4_ADDR_SAME(&prev_nbr
->src
,
4171 /* Start new neigh list */
4172 json_neigh_array
= NULL
;
4175 if (nbr
->state
== NSM_Attempt
4176 && nbr
->router_id
.s_addr
== 0)
4177 strlcpy(neigh_str
, "neighbor",
4181 inet_ntoa(nbr
->router_id
),
4184 json_object_object_get_ex(json
, neigh_str
,
4187 if (!json_neigh_array
) {
4189 json_object_new_array();
4190 json_object_object_add(
4195 json_neighbor
= json_object_new_object();
4197 ospf_nbr_state_message(nbr
, msgbuf
, 16);
4203 &nbr
->t_inactivity
->u
.sands
,
4207 json_object_int_add(json_neighbor
, "priority",
4209 json_object_string_add(json_neighbor
, "state",
4211 json_object_int_add(json_neighbor
,
4214 json_object_string_add(json_neighbor
, "address",
4215 inet_ntoa(nbr
->src
));
4216 json_object_string_add(json_neighbor
,
4219 json_object_int_add(
4220 json_neighbor
, "retransmitCounter",
4221 ospf_ls_retransmit_count(nbr
));
4222 json_object_int_add(json_neighbor
,
4224 ospf_ls_request_count(nbr
));
4225 json_object_int_add(json_neighbor
,
4227 ospf_db_summary_count(nbr
));
4229 json_object_array_add(json_neigh_array
,
4232 ospf_nbr_state_message(nbr
, msgbuf
, 16);
4234 if (nbr
->state
== NSM_Attempt
4235 && nbr
->router_id
.s_addr
== 0)
4236 vty_out(vty
, "%-15s %3d %-15s ", "-",
4237 nbr
->priority
, msgbuf
);
4239 vty_out(vty
, "%-15s %3d %-15s ",
4240 inet_ntoa(nbr
->router_id
),
4241 nbr
->priority
, msgbuf
);
4243 vty_out(vty
, "%9s ",
4244 ospf_timer_dump(nbr
->t_inactivity
,
4247 vty_out(vty
, "%-15s ", inet_ntoa(nbr
->src
));
4248 vty_out(vty
, "%-20s %5ld %5ld %5d\n",
4250 ospf_ls_retransmit_count(nbr
),
4251 ospf_ls_request_count(nbr
),
4252 ospf_db_summary_count(nbr
));
4259 static int show_ip_ospf_neighbor_common(struct vty
*vty
, struct ospf
*ospf
,
4260 json_object
*json
, uint8_t use_json
,
4263 struct ospf_interface
*oi
;
4264 struct listnode
*node
;
4265 json_object
*json_vrf
= NULL
;
4266 json_object
*json_nbr_sub
= NULL
;
4270 json_vrf
= json_object_new_object();
4273 json_nbr_sub
= json_object_new_object();
4276 if (ospf
->instance
) {
4278 json_object_int_add(json
, "ospfInstance",
4281 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4284 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4286 show_ip_ospf_neighbour_header(vty
);
4288 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4289 if (ospf_interface_neighbor_count(oi
) == 0)
4291 show_ip_ospf_neighbor_sub(vty
, oi
, json_nbr_sub
, use_json
);
4295 json_object_object_add(json_vrf
, "neighbors", json_nbr_sub
);
4297 if (ospf
->vrf_id
== VRF_DEFAULT
)
4298 json_object_object_add(json
, "default",
4301 json_object_object_add(json
, ospf
->name
,
4310 DEFUN (show_ip_ospf_neighbor
,
4311 show_ip_ospf_neighbor_cmd
,
4312 "show ip ospf [vrf <NAME|all>] neighbor [json]",
4315 "OSPF information\n"
4322 uint8_t uj
= use_json(argc
, argv
);
4323 struct listnode
*node
= NULL
;
4324 char *vrf_name
= NULL
;
4325 bool all_vrf
= FALSE
;
4326 int ret
= CMD_SUCCESS
;
4329 uint8_t use_vrf
= 0;
4330 json_object
*json
= NULL
;
4332 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4335 json
= json_object_new_object();
4337 /* vrf input is provided could be all or specific vrf*/
4341 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4342 if (!ospf
->oi_running
)
4344 ret
= show_ip_ospf_neighbor_common(
4345 vty
, ospf
, json
, uj
, use_vrf
);
4349 vty_out(vty
, "%s\n",
4350 json_object_to_json_string_ext(
4351 json
, JSON_C_TO_STRING_PRETTY
));
4352 json_object_free(json
);
4358 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4359 if (ospf
== NULL
|| !ospf
->oi_running
) {
4361 json_object_free(json
);
4365 /* Display default ospf (instance 0) info */
4366 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4367 if (ospf
== NULL
|| !ospf
->oi_running
) {
4369 json_object_free(json
);
4375 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
,
4379 vty_out(vty
, "%s\n",
4380 json_object_to_json_string_ext(
4381 json
, JSON_C_TO_STRING_PRETTY
));
4386 json_object_free(json
);
4392 DEFUN (show_ip_ospf_instance_neighbor
,
4393 show_ip_ospf_instance_neighbor_cmd
,
4394 "show ip ospf (1-65535) neighbor [json]",
4397 "OSPF information\n"
4404 unsigned short instance
= 0;
4405 uint8_t uj
= use_json(argc
, argv
);
4406 json_object
*json
= NULL
;
4407 int ret
= CMD_SUCCESS
;
4409 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4410 ospf
= ospf_lookup_instance(instance
);
4412 return CMD_NOT_MY_INSTANCE
;
4414 if (!ospf
->oi_running
)
4418 json
= json_object_new_object();
4420 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
, 0);
4423 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4424 json
, JSON_C_TO_STRING_PRETTY
));
4425 json_object_free(json
);
4431 static int show_ip_ospf_neighbor_all_common(struct vty
*vty
, struct ospf
*ospf
,
4432 json_object
*json
, uint8_t use_json
,
4435 struct listnode
*node
;
4436 struct ospf_interface
*oi
;
4437 json_object
*json_vrf
= NULL
;
4438 json_object
*json_neighbor_sub
= NULL
;
4442 json_vrf
= json_object_new_object();
4445 json_neighbor_sub
= json_object_new_object();
4448 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4450 show_ip_ospf_neighbour_header(vty
);
4452 if (ospf
->instance
) {
4454 json_object_int_add(json_vrf
, "ospfInstance",
4457 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4460 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4461 struct listnode
*nbr_node
;
4462 struct ospf_nbr_nbma
*nbr_nbma
;
4464 show_ip_ospf_neighbor_sub(vty
, oi
, json_vrf
, use_json
);
4466 /* print Down neighbor status */
4467 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nbr_node
, nbr_nbma
)) {
4468 if (nbr_nbma
->nbr
== NULL
4469 || nbr_nbma
->nbr
->state
== NSM_Down
) {
4471 json_object_int_add(json_neighbor_sub
,
4473 nbr_nbma
->priority
);
4474 json_object_boolean_true_add(
4477 json_object_string_add(
4481 json_object_int_add(
4483 "nbrNbmaRetransmitCounter", 0);
4484 json_object_int_add(
4486 "nbrNbmaRequestCounter", 0);
4487 json_object_int_add(
4489 "nbrNbmaDbSummaryCounter", 0);
4490 json_object_object_add(
4492 inet_ntoa(nbr_nbma
->addr
),
4495 vty_out(vty
, "%-15s %3d %-15s %9s ",
4496 "-", nbr_nbma
->priority
, "Down",
4499 "%-15s %-20s %5d %5d %5d\n",
4500 inet_ntoa(nbr_nbma
->addr
),
4501 IF_NAME(oi
), 0, 0, 0);
4509 if (ospf
->vrf_id
== VRF_DEFAULT
)
4510 json_object_object_add(json
, "default",
4513 json_object_object_add(json
, ospf
->name
,
4522 DEFUN (show_ip_ospf_neighbor_all
,
4523 show_ip_ospf_neighbor_all_cmd
,
4524 "show ip ospf [vrf <NAME|all>] neighbor all [json]",
4527 "OSPF information\n"
4531 "include down status neighbor\n"
4535 uint8_t uj
= use_json(argc
, argv
);
4536 struct listnode
*node
= NULL
;
4537 char *vrf_name
= NULL
;
4538 bool all_vrf
= FALSE
;
4539 int ret
= CMD_SUCCESS
;
4542 uint8_t use_vrf
= 0;
4543 json_object
*json
= NULL
;
4545 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4548 json
= json_object_new_object();
4550 /* vrf input is provided could be all or specific vrf*/
4554 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4555 if (!ospf
->oi_running
)
4557 ret
= show_ip_ospf_neighbor_all_common(
4558 vty
, ospf
, json
, uj
, use_vrf
);
4562 vty_out(vty
, "%s\n",
4563 json_object_to_json_string_ext(
4564 json
, JSON_C_TO_STRING_PRETTY
));
4565 json_object_free(json
);
4571 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4572 if (ospf
== NULL
|| !ospf
->oi_running
) {
4574 json_object_free(json
);
4578 /* Display default ospf (instance 0) info */
4579 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4580 if (ospf
== NULL
|| !ospf
->oi_running
) {
4582 json_object_free(json
);
4588 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
,
4591 vty_out(vty
, "%s\n",
4592 json_object_to_json_string_ext(
4593 json
, JSON_C_TO_STRING_PRETTY
));
4598 json_object_free(json
);
4603 DEFUN (show_ip_ospf_instance_neighbor_all
,
4604 show_ip_ospf_instance_neighbor_all_cmd
,
4605 "show ip ospf (1-65535) neighbor all [json]",
4608 "OSPF information\n"
4611 "include down status neighbor\n"
4616 unsigned short instance
= 0;
4617 uint8_t uj
= use_json(argc
, argv
);
4618 json_object
*json
= NULL
;
4619 int ret
= CMD_SUCCESS
;
4621 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4622 ospf
= ospf_lookup_instance(instance
);
4624 return CMD_NOT_MY_INSTANCE
;
4626 if (!ospf
->oi_running
)
4629 json
= json_object_new_object();
4631 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
, 0);
4634 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4635 json
, JSON_C_TO_STRING_PRETTY
));
4636 json_object_free(json
);
4642 static int show_ip_ospf_neighbor_int_common(struct vty
*vty
, struct ospf
*ospf
,
4644 struct cmd_token
**argv
,
4645 uint8_t use_json
, uint8_t use_vrf
)
4647 struct interface
*ifp
;
4648 struct route_node
*rn
;
4649 json_object
*json
= NULL
;
4652 json
= json_object_new_object();
4654 if (ospf
->instance
) {
4656 json_object_int_add(json
, "ospfInstance",
4659 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4662 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
4664 ifp
= if_lookup_by_name_all_vrf(argv
[arg_base
]->arg
);
4667 json_object_boolean_true_add(json
, "noSuchIface");
4669 vty_out(vty
, "No such interface.\n");
4673 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
4674 struct ospf_interface
*oi
= rn
->info
;
4679 show_ip_ospf_neighbor_sub(vty
, oi
, json
, use_json
);
4683 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4684 json
, JSON_C_TO_STRING_PRETTY
));
4685 json_object_free(json
);
4692 DEFUN (show_ip_ospf_neighbor_int
,
4693 show_ip_ospf_neighbor_int_cmd
,
4694 "show ip ospf neighbor IFNAME [json]",
4697 "OSPF information\n"
4704 uint8_t uj
= use_json(argc
, argv
);
4705 struct listnode
*node
= NULL
;
4706 int ret
= CMD_SUCCESS
;
4707 struct interface
*ifp
= NULL
;
4710 show_ip_ospf_neighbour_header(vty
);
4712 ifp
= if_lookup_by_name_all_vrf(argv
[idx_ifname
]->arg
);
4713 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4714 if (!ospf
->oi_running
)
4716 if (!ifp
|| ifp
->vrf_id
!= ospf
->vrf_id
)
4718 ret
= show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
,
4725 DEFUN (show_ip_ospf_instance_neighbor_int
,
4726 show_ip_ospf_instance_neighbor_int_cmd
,
4727 "show ip ospf (1-65535) neighbor IFNAME [json]",
4730 "OSPF information\n"
4739 unsigned short instance
= 0;
4740 uint8_t uj
= use_json(argc
, argv
);
4743 show_ip_ospf_neighbour_header(vty
);
4745 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4746 ospf
= ospf_lookup_instance(instance
);
4748 return CMD_NOT_MY_INSTANCE
;
4750 if (!ospf
->oi_running
)
4754 show_ip_ospf_neighbour_header(vty
);
4756 return show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
, argv
, uj
,
4760 static void show_ip_ospf_nbr_nbma_detail_sub(struct vty
*vty
,
4761 struct ospf_interface
*oi
,
4762 struct ospf_nbr_nbma
*nbr_nbma
,
4766 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4767 json_object
*json_sub
= NULL
;
4770 json_sub
= json_object_new_object();
4771 else /* Show neighbor ID. */
4772 vty_out(vty
, " Neighbor %s,", "-");
4774 /* Show interface address. */
4776 json_object_string_add(json_sub
, "ifaceAddress",
4777 inet_ntoa(nbr_nbma
->addr
));
4779 vty_out(vty
, " interface address %s\n",
4780 inet_ntoa(nbr_nbma
->addr
));
4784 json_object_string_add(json_sub
, "areaId",
4785 ospf_area_desc_string(oi
->area
));
4786 json_object_string_add(json_sub
, "iface", IF_NAME(oi
));
4788 vty_out(vty
, " In the area %s via interface %s\n",
4789 ospf_area_desc_string(oi
->area
), IF_NAME(oi
));
4791 /* Show neighbor priority and state. */
4793 json_object_int_add(json_sub
, "nbrPriority",
4794 nbr_nbma
->priority
);
4795 json_object_string_add(json_sub
, "nbrState", "down");
4797 vty_out(vty
, " Neighbor priority is %d, State is %s,",
4798 nbr_nbma
->priority
, "Down");
4800 /* Show state changes. */
4802 json_object_int_add(json_sub
, "stateChangeCounter",
4803 nbr_nbma
->state_change
);
4805 vty_out(vty
, " %d state changes\n", nbr_nbma
->state_change
);
4807 /* Show PollInterval */
4809 json_object_int_add(json_sub
, "pollInterval", nbr_nbma
->v_poll
);
4811 vty_out(vty
, " Poll interval %d\n", nbr_nbma
->v_poll
);
4813 /* Show poll-interval timer. */
4816 time_store
= monotime_until(&nbr_nbma
->t_poll
->u
.sands
, NULL
)
4818 json_object_int_add(json_sub
, "pollIntervalTimerDueMsec",
4821 vty_out(vty
, " Poll timer due in %s\n",
4822 ospf_timer_dump(nbr_nbma
->t_poll
, timebuf
,
4825 /* Show poll-interval timer thread. */
4827 if (nbr_nbma
->t_poll
!= NULL
)
4828 json_object_string_add(json_sub
,
4829 "pollIntervalTimerThread", "on");
4831 vty_out(vty
, " Thread Poll Timer %s\n",
4832 nbr_nbma
->t_poll
!= NULL
? "on" : "off");
4835 json_object_object_add(json
, "noNbrId", json_sub
);
4838 static void show_ip_ospf_neighbor_detail_sub(struct vty
*vty
,
4839 struct ospf_interface
*oi
,
4840 struct ospf_neighbor
*nbr
,
4844 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4845 json_object
*json_sub
= NULL
;
4848 json_sub
= json_object_new_object();
4850 /* Show neighbor ID. */
4851 if (nbr
->state
== NSM_Attempt
&& nbr
->router_id
.s_addr
== 0)
4852 vty_out(vty
, " Neighbor %s,", "-");
4854 vty_out(vty
, " Neighbor %s,",
4855 inet_ntoa(nbr
->router_id
));
4858 /* Show interface address. */
4860 json_object_string_add(json_sub
, "ifaceAddress",
4861 inet_ntoa(nbr
->address
.u
.prefix4
));
4863 vty_out(vty
, " interface address %s\n",
4864 inet_ntoa(nbr
->address
.u
.prefix4
));
4868 json_object_string_add(json_sub
, "areaId",
4869 ospf_area_desc_string(oi
->area
));
4870 json_object_string_add(json_sub
, "ifaceName", oi
->ifp
->name
);
4872 vty_out(vty
, " In the area %s via interface %s\n",
4873 ospf_area_desc_string(oi
->area
), oi
->ifp
->name
);
4875 /* Show neighbor priority and state. */
4877 json_object_int_add(json_sub
, "nbrPriority", nbr
->priority
);
4878 json_object_string_add(
4879 json_sub
, "nbrState",
4880 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
4882 vty_out(vty
, " Neighbor priority is %d, State is %s,",
4884 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
4886 /* Show state changes. */
4888 json_object_int_add(json_sub
, "stateChangeCounter",
4891 vty_out(vty
, " %d state changes\n", nbr
->state_change
);
4893 if (nbr
->ts_last_progress
.tv_sec
|| nbr
->ts_last_progress
.tv_usec
) {
4898 monotime_since(&nbr
->ts_last_progress
, &res
) / 1000LL;
4900 json_object_int_add(json_sub
, "lastPrgrsvChangeMsec",
4904 " Most recent state change statistics:\n");
4905 vty_out(vty
, " Progressive change %s ago\n",
4906 ospf_timeval_dump(&res
, timebuf
,
4911 if (nbr
->ts_last_regress
.tv_sec
|| nbr
->ts_last_regress
.tv_usec
) {
4916 monotime_since(&nbr
->ts_last_regress
, &res
) / 1000LL;
4918 json_object_int_add(json_sub
,
4919 "lastRegressiveChangeMsec",
4921 if (nbr
->last_regress_str
)
4922 json_object_string_add(
4923 json_sub
, "lastRegressiveChangeReason",
4924 nbr
->last_regress_str
);
4927 " Regressive change %s ago, due to %s\n",
4928 ospf_timeval_dump(&res
, timebuf
,
4930 (nbr
->last_regress_str
? nbr
->last_regress_str
4935 /* Show Designated Rotuer ID. */
4937 json_object_string_add(json_sub
, "routerDesignatedId",
4938 inet_ntoa(nbr
->d_router
));
4940 vty_out(vty
, " DR is %s,", inet_ntoa(nbr
->d_router
));
4942 /* Show Backup Designated Rotuer ID. */
4944 json_object_string_add(json_sub
, "routerDesignatedBackupId",
4945 inet_ntoa(nbr
->bd_router
));
4947 vty_out(vty
, " BDR is %s\n", inet_ntoa(nbr
->bd_router
));
4951 json_object_int_add(json_sub
, "optionsCounter", nbr
->options
);
4952 json_object_string_add(json_sub
, "optionsList",
4953 ospf_options_dump(nbr
->options
));
4955 vty_out(vty
, " Options %d %s\n", nbr
->options
,
4956 ospf_options_dump(nbr
->options
));
4958 /* Show Router Dead interval timer. */
4960 if (nbr
->t_inactivity
) {
4962 time_store
= monotime_until(&nbr
->t_inactivity
->u
.sands
,
4965 json_object_int_add(json_sub
,
4966 "routerDeadIntervalTimerDueMsec",
4969 json_object_int_add(
4970 json_sub
, "routerDeadIntervalTimerDueMsec", -1);
4972 vty_out(vty
, " Dead timer due in %s\n",
4973 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
4976 /* Show Database Summary list. */
4978 json_object_int_add(json_sub
, "databaseSummaryListCounter",
4979 ospf_db_summary_count(nbr
));
4981 vty_out(vty
, " Database Summary List %d\n",
4982 ospf_db_summary_count(nbr
));
4984 /* Show Link State Request list. */
4986 json_object_int_add(json_sub
, "linkStateRequestListCounter",
4987 ospf_ls_request_count(nbr
));
4989 vty_out(vty
, " Link State Request List %ld\n",
4990 ospf_ls_request_count(nbr
));
4992 /* Show Link State Retransmission list. */
4994 json_object_int_add(json_sub
,
4995 "linkStateRetransmissionListCounter",
4996 ospf_ls_retransmit_count(nbr
));
4998 vty_out(vty
, " Link State Retransmission List %ld\n",
4999 ospf_ls_retransmit_count(nbr
));
5001 /* Show inactivity timer thread. */
5003 if (nbr
->t_inactivity
!= NULL
)
5004 json_object_string_add(json_sub
,
5005 "threadInactivityTimer", "on");
5007 vty_out(vty
, " Thread Inactivity Timer %s\n",
5008 nbr
->t_inactivity
!= NULL
? "on" : "off");
5010 /* Show Database Description retransmission thread. */
5012 if (nbr
->t_db_desc
!= NULL
)
5013 json_object_string_add(
5015 "threadDatabaseDescriptionRetransmission",
5019 " Thread Database Description Retransmision %s\n",
5020 nbr
->t_db_desc
!= NULL
? "on" : "off");
5022 /* Show Link State Request Retransmission thread. */
5024 if (nbr
->t_ls_req
!= NULL
)
5025 json_object_string_add(
5027 "threadLinkStateRequestRetransmission", "on");
5030 " Thread Link State Request Retransmission %s\n",
5031 nbr
->t_ls_req
!= NULL
? "on" : "off");
5033 /* Show Link State Update Retransmission thread. */
5035 if (nbr
->t_ls_upd
!= NULL
)
5036 json_object_string_add(
5037 json_sub
, "threadLinkStateUpdateRetransmission",
5041 " Thread Link State Update Retransmission %s\n\n",
5042 nbr
->t_ls_upd
!= NULL
? "on" : "off");
5045 if (nbr
->state
== NSM_Attempt
&& nbr
->router_id
.s_addr
== 0)
5046 json_object_object_add(json
, "noNbrId", json_sub
);
5048 json_object_object_add(json
, inet_ntoa(nbr
->router_id
),
5052 ospf_bfd_show_info(vty
, nbr
->bfd_info
, json
, use_json
, 0);
5055 static int show_ip_ospf_neighbor_id_common(struct vty
*vty
, struct ospf
*ospf
,
5057 struct cmd_token
**argv
,
5058 uint8_t use_json
, uint8_t use_vrf
)
5060 struct listnode
*node
;
5061 struct ospf_neighbor
*nbr
;
5062 struct ospf_interface
*oi
;
5063 struct in_addr router_id
;
5065 json_object
*json
= NULL
;
5068 json
= json_object_new_object();
5070 if (ospf
->instance
) {
5072 json_object_int_add(json
, "ospfInstance",
5075 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5078 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
5080 ret
= inet_aton(argv
[arg_base
]->arg
, &router_id
);
5083 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
5085 vty_out(vty
, "{}\n");
5086 json_object_free(json
);
5091 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5092 if ((nbr
= ospf_nbr_lookup_by_routerid(oi
->nbrs
, &router_id
))) {
5093 show_ip_ospf_neighbor_detail_sub(vty
, oi
, nbr
, json
,
5099 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5100 json
, JSON_C_TO_STRING_PRETTY
));
5101 json_object_free(json
);
5108 DEFUN (show_ip_ospf_neighbor_id
,
5109 show_ip_ospf_neighbor_id_cmd
,
5110 "show ip ospf neighbor A.B.C.D [json]",
5113 "OSPF information\n"
5119 uint8_t uj
= use_json(argc
, argv
);
5120 struct listnode
*node
= NULL
;
5121 int ret
= CMD_SUCCESS
;
5123 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5124 if (!ospf
->oi_running
)
5126 ret
= show_ip_ospf_neighbor_id_common(vty
, ospf
, 0, argv
, uj
,
5133 DEFUN (show_ip_ospf_instance_neighbor_id
,
5134 show_ip_ospf_instance_neighbor_id_cmd
,
5135 "show ip ospf (1-65535) neighbor A.B.C.D [json]",
5138 "OSPF information\n"
5145 int idx_router_id
= 5;
5147 unsigned short instance
= 0;
5148 uint8_t uj
= use_json(argc
, argv
);
5150 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5151 ospf
= ospf_lookup_instance(instance
);
5153 return CMD_NOT_MY_INSTANCE
;
5155 if (!ospf
->oi_running
)
5158 return show_ip_ospf_neighbor_id_common(vty
, ospf
, idx_router_id
, argv
,
5162 static int show_ip_ospf_neighbor_detail_common(struct vty
*vty
,
5168 struct ospf_interface
*oi
;
5169 struct listnode
*node
;
5170 json_object
*json_vrf
= NULL
;
5174 json_vrf
= json_object_new_object();
5178 if (ospf
->instance
) {
5180 json_object_int_add(json_vrf
, "ospfInstance",
5183 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5186 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5188 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5189 struct route_node
*rn
;
5190 struct ospf_neighbor
*nbr
;
5192 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5193 if ((nbr
= rn
->info
)) {
5194 if (nbr
!= oi
->nbr_self
) {
5195 if (nbr
->state
!= NSM_Down
) {
5196 show_ip_ospf_neighbor_detail_sub(
5197 vty
, oi
, nbr
, json_vrf
,
5207 if (ospf
->vrf_id
== VRF_DEFAULT
)
5208 json_object_object_add(json
, "default",
5211 json_object_object_add(json
, ospf
->name
,
5220 DEFUN (show_ip_ospf_neighbor_detail
,
5221 show_ip_ospf_neighbor_detail_cmd
,
5222 "show ip ospf [vrf <NAME|all>] neighbor detail [json]",
5225 "OSPF information\n"
5229 "detail of all neighbors\n"
5233 uint8_t uj
= use_json(argc
, argv
);
5234 struct listnode
*node
= NULL
;
5235 char *vrf_name
= NULL
;
5236 bool all_vrf
= FALSE
;
5237 int ret
= CMD_SUCCESS
;
5240 uint8_t use_vrf
= 0;
5241 json_object
*json
= NULL
;
5243 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5246 json
= json_object_new_object();
5248 /* vrf input is provided could be all or specific vrf*/
5252 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5253 if (!ospf
->oi_running
)
5255 ret
= show_ip_ospf_neighbor_detail_common(
5256 vty
, ospf
, json
, uj
, use_vrf
);
5259 vty_out(vty
, "%s\n",
5260 json_object_to_json_string_ext(
5261 json
, JSON_C_TO_STRING_PRETTY
));
5262 json_object_free(json
);
5267 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5268 if (ospf
== NULL
|| !ospf
->oi_running
) {
5270 json_object_free(json
);
5274 /* Display default ospf (instance 0) info */
5275 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5276 if (ospf
== NULL
|| !ospf
->oi_running
) {
5278 json_object_free(json
);
5284 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
,
5287 vty_out(vty
, "%s\n",
5288 json_object_to_json_string_ext(
5289 json
, JSON_C_TO_STRING_PRETTY
));
5294 json_object_free(json
);
5299 DEFUN (show_ip_ospf_instance_neighbor_detail
,
5300 show_ip_ospf_instance_neighbor_detail_cmd
,
5301 "show ip ospf (1-65535) neighbor detail [json]",
5304 "OSPF information\n"
5307 "detail of all neighbors\n"
5312 unsigned short instance
= 0;
5313 uint8_t uj
= use_json(argc
, argv
);
5314 json_object
*json
= NULL
;
5315 int ret
= CMD_SUCCESS
;
5317 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5318 ospf
= ospf_lookup_instance(instance
);
5320 return CMD_NOT_MY_INSTANCE
;
5322 if (!ospf
->oi_running
)
5326 json
= json_object_new_object();
5328 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
, 0);
5331 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5332 json
, JSON_C_TO_STRING_PRETTY
));
5333 json_object_free(json
);
5339 static int show_ip_ospf_neighbor_detail_all_common(struct vty
*vty
,
5345 struct listnode
*node
;
5346 struct ospf_interface
*oi
;
5347 json_object
*json_vrf
= NULL
;
5351 json_vrf
= json_object_new_object();
5356 if (ospf
->instance
) {
5358 json_object_int_add(json
, "ospfInstance",
5361 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5364 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5366 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5367 struct route_node
*rn
;
5368 struct ospf_neighbor
*nbr
;
5369 struct ospf_nbr_nbma
*nbr_nbma
;
5371 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
5372 if ((nbr
= rn
->info
))
5373 if (nbr
!= oi
->nbr_self
)
5374 if (nbr
->state
!= NSM_Down
)
5375 show_ip_ospf_neighbor_detail_sub(
5377 json_vrf
, use_json
);
5379 if (oi
->type
== OSPF_IFTYPE_NBMA
) {
5380 struct listnode
*nd
;
5382 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nd
, nbr_nbma
)) {
5383 if (nbr_nbma
->nbr
== NULL
5384 || nbr_nbma
->nbr
->state
== NSM_Down
)
5385 show_ip_ospf_nbr_nbma_detail_sub(
5386 vty
, oi
, nbr_nbma
, use_json
,
5394 if (ospf
->vrf_id
== VRF_DEFAULT
)
5395 json_object_object_add(json
, "default",
5398 json_object_object_add(json
, ospf
->name
,
5408 DEFUN (show_ip_ospf_neighbor_detail_all
,
5409 show_ip_ospf_neighbor_detail_all_cmd
,
5410 "show ip ospf [vrf <NAME|all>] neighbor detail all [json]",
5413 "OSPF information\n"
5417 "detail of all neighbors\n"
5418 "include down status neighbor\n"
5422 uint8_t uj
= use_json(argc
, argv
);
5423 struct listnode
*node
= NULL
;
5424 char *vrf_name
= NULL
;
5425 bool all_vrf
= FALSE
;
5426 int ret
= CMD_SUCCESS
;
5429 uint8_t use_vrf
= 0;
5430 json_object
*json
= NULL
;
5432 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5435 json
= json_object_new_object();
5437 /* vrf input is provided could be all or specific vrf*/
5441 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5442 if (!ospf
->oi_running
)
5444 ret
= show_ip_ospf_neighbor_detail_all_common(
5445 vty
, ospf
, json
, uj
, use_vrf
);
5449 vty_out(vty
, "%s\n",
5450 json_object_to_json_string_ext(
5451 json
, JSON_C_TO_STRING_PRETTY
));
5452 json_object_free(json
);
5457 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5458 if (ospf
== NULL
|| !ospf
->oi_running
) {
5460 json_object_free(json
);
5464 /* Display default ospf (instance 0) info */
5465 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5466 if (ospf
== NULL
|| !ospf
->oi_running
) {
5468 json_object_free(json
);
5474 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
,
5477 vty_out(vty
, "%s\n",
5478 json_object_to_json_string_ext(
5479 json
, JSON_C_TO_STRING_PRETTY
));
5484 json_object_free(json
);
5489 DEFUN (show_ip_ospf_instance_neighbor_detail_all
,
5490 show_ip_ospf_instance_neighbor_detail_all_cmd
,
5491 "show ip ospf (1-65535) neighbor detail all [json]",
5494 "OSPF information\n"
5497 "detail of all neighbors\n"
5498 "include down status neighbor\n"
5503 unsigned short instance
= 0;
5504 uint8_t uj
= use_json(argc
, argv
);
5505 json_object
*json
= NULL
;
5506 int ret
= CMD_SUCCESS
;
5508 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5509 ospf
= ospf_lookup_instance(instance
);
5511 return CMD_NOT_MY_INSTANCE
;
5513 if (!ospf
->oi_running
)
5517 json
= json_object_new_object();
5519 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
, uj
, 0);
5522 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5523 json
, JSON_C_TO_STRING_PRETTY
));
5524 json_object_free(json
);
5530 static int show_ip_ospf_neighbor_int_detail_common(struct vty
*vty
,
5533 struct cmd_token
**argv
,
5536 struct ospf_interface
*oi
;
5537 struct interface
*ifp
;
5538 struct route_node
*rn
, *nrn
;
5539 struct ospf_neighbor
*nbr
;
5540 json_object
*json
= NULL
;
5543 json
= json_object_new_object();
5545 if (ospf
->instance
) {
5547 json_object_int_add(json
, "ospfInstance",
5550 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5553 ifp
= if_lookup_by_name_all_vrf(argv
[arg_base
]->arg
);
5556 vty_out(vty
, "No such interface.\n");
5558 vty_out(vty
, "{}\n");
5559 json_object_free(json
);
5564 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
5565 if ((oi
= rn
->info
)) {
5566 for (nrn
= route_top(oi
->nbrs
); nrn
;
5567 nrn
= route_next(nrn
)) {
5568 if ((nbr
= nrn
->info
)) {
5569 if (nbr
!= oi
->nbr_self
) {
5570 if (nbr
->state
!= NSM_Down
)
5571 show_ip_ospf_neighbor_detail_sub(
5581 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5582 json
, JSON_C_TO_STRING_PRETTY
));
5583 json_object_free(json
);
5590 DEFUN (show_ip_ospf_neighbor_int_detail
,
5591 show_ip_ospf_neighbor_int_detail_cmd
,
5592 "show ip ospf neighbor IFNAME detail [json]",
5595 "OSPF information\n"
5598 "detail of all neighbors\n"
5602 uint8_t uj
= use_json(argc
, argv
);
5603 struct listnode
*node
= NULL
;
5604 int ret
= CMD_SUCCESS
;
5606 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5607 if (!ospf
->oi_running
)
5609 ret
= show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, 0,
5616 DEFUN (show_ip_ospf_instance_neighbor_int_detail
,
5617 show_ip_ospf_instance_neighbor_int_detail_cmd
,
5618 "show ip ospf (1-65535) neighbor IFNAME detail [json]",
5621 "OSPF information\n"
5625 "detail of all neighbors\n"
5631 unsigned short instance
= 0;
5632 uint8_t uj
= use_json(argc
, argv
);
5634 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5635 ospf
= ospf_lookup_instance(instance
);
5637 return CMD_NOT_MY_INSTANCE
;
5639 if (!ospf
->oi_running
)
5642 return show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, idx_ifname
,
5646 /* Show functions */
5647 static int show_lsa_summary(struct vty
*vty
, struct ospf_lsa
*lsa
, int self
)
5649 struct router_lsa
*rl
;
5650 struct summary_lsa
*sl
;
5651 struct as_external_lsa
*asel
;
5652 struct prefix_ipv4 p
;
5655 /* If self option is set, check LSA self flag. */
5656 if (self
== 0 || IS_LSA_SELF(lsa
)) {
5657 /* LSA common part show. */
5658 vty_out(vty
, "%-15s ", inet_ntoa(lsa
->data
->id
));
5659 vty_out(vty
, "%-15s %4d 0x%08lx 0x%04x",
5660 inet_ntoa(lsa
->data
->adv_router
), LS_AGE(lsa
),
5661 (unsigned long)ntohl(lsa
->data
->ls_seqnum
),
5662 ntohs(lsa
->data
->checksum
));
5663 /* LSA specific part show. */
5664 switch (lsa
->data
->type
) {
5665 case OSPF_ROUTER_LSA
:
5666 rl
= (struct router_lsa
*)lsa
->data
;
5667 vty_out(vty
, " %-d", ntohs(rl
->links
));
5669 case OSPF_SUMMARY_LSA
:
5670 sl
= (struct summary_lsa
*)lsa
->data
;
5673 p
.prefix
= sl
->header
.id
;
5674 p
.prefixlen
= ip_masklen(sl
->mask
);
5675 apply_mask_ipv4(&p
);
5677 vty_out(vty
, " %s/%d", inet_ntoa(p
.prefix
),
5680 case OSPF_AS_EXTERNAL_LSA
:
5681 case OSPF_AS_NSSA_LSA
:
5682 asel
= (struct as_external_lsa
*)lsa
->data
;
5685 p
.prefix
= asel
->header
.id
;
5686 p
.prefixlen
= ip_masklen(asel
->mask
);
5687 apply_mask_ipv4(&p
);
5689 vty_out(vty
, " %s %s/%d [0x%lx]",
5690 IS_EXTERNAL_METRIC(asel
->e
[0].tos
)
5693 inet_ntoa(p
.prefix
), p
.prefixlen
,
5694 (unsigned long)ntohl(
5695 asel
->e
[0].route_tag
));
5697 case OSPF_NETWORK_LSA
:
5698 case OSPF_ASBR_SUMMARY_LSA
:
5699 case OSPF_OPAQUE_LINK_LSA
:
5700 case OSPF_OPAQUE_AREA_LSA
:
5701 case OSPF_OPAQUE_AS_LSA
:
5711 static const char *show_database_desc
[] = {
5713 "Router Link States",
5715 "Summary Link States",
5716 "ASBR-Summary Link States",
5717 "AS External Link States",
5718 "Group Membership LSA",
5719 "NSSA-external Link States",
5721 "Link-Local Opaque-LSA",
5722 "Area-Local Opaque-LSA",
5723 "AS-external Opaque-LSA",
5726 static const char *show_database_header
[] = {
5728 "Link ID ADV Router Age Seq# CkSum Link count",
5729 "Link ID ADV Router Age Seq# CkSum",
5730 "Link ID ADV Router Age Seq# CkSum Route",
5731 "Link ID ADV Router Age Seq# CkSum",
5732 "Link ID ADV Router Age Seq# CkSum Route",
5733 " --- header for Group Member ----",
5734 "Link ID ADV Router Age Seq# CkSum Route",
5736 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5737 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5738 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5741 static void show_ip_ospf_database_header(struct vty
*vty
, struct ospf_lsa
*lsa
)
5743 struct router_lsa
*rlsa
= (struct router_lsa
*)lsa
->data
;
5745 vty_out(vty
, " LS age: %d\n", LS_AGE(lsa
));
5746 vty_out(vty
, " Options: 0x%-2x : %s\n", lsa
->data
->options
,
5747 ospf_options_dump(lsa
->data
->options
));
5748 vty_out(vty
, " LS Flags: 0x%-2x %s\n", lsa
->flags
,
5749 ((lsa
->flags
& OSPF_LSA_LOCAL_XLT
) ? "(Translated from Type-7)"
5752 if (lsa
->data
->type
== OSPF_ROUTER_LSA
) {
5753 vty_out(vty
, " Flags: 0x%x", rlsa
->flags
);
5756 vty_out(vty
, " :%s%s%s%s",
5757 IS_ROUTER_LSA_BORDER(rlsa
) ? " ABR" : "",
5758 IS_ROUTER_LSA_EXTERNAL(rlsa
) ? " ASBR" : "",
5759 IS_ROUTER_LSA_VIRTUAL(rlsa
) ? " VL-endpoint"
5761 IS_ROUTER_LSA_SHORTCUT(rlsa
) ? " Shortcut"
5766 vty_out(vty
, " LS Type: %s\n",
5767 lookup_msg(ospf_lsa_type_msg
, lsa
->data
->type
, NULL
));
5768 vty_out(vty
, " Link State ID: %s %s\n", inet_ntoa(lsa
->data
->id
),
5769 lookup_msg(ospf_link_state_id_type_msg
, lsa
->data
->type
, NULL
));
5770 vty_out(vty
, " Advertising Router: %s\n",
5771 inet_ntoa(lsa
->data
->adv_router
));
5772 vty_out(vty
, " LS Seq Number: %08lx\n",
5773 (unsigned long)ntohl(lsa
->data
->ls_seqnum
));
5774 vty_out(vty
, " Checksum: 0x%04x\n", ntohs(lsa
->data
->checksum
));
5775 vty_out(vty
, " Length: %d\n\n", ntohs(lsa
->data
->length
));
5778 const char *link_type_desc
[] = {
5780 "another Router (point-to-point)",
5781 "a Transit Network",
5786 const char *link_id_desc
[] = {
5787 "(null)", "Neighboring Router ID", "Designated Router address",
5788 "Net", "Neighboring Router ID",
5791 const char *link_data_desc
[] = {
5792 "(null)", "Router Interface address", "Router Interface address",
5793 "Network Mask", "Router Interface address",
5796 /* Show router-LSA each Link information. */
5797 static void show_ip_ospf_database_router_links(struct vty
*vty
,
5798 struct router_lsa
*rl
)
5803 len
= ntohs(rl
->header
.length
) - 4;
5804 for (i
= 0; i
< ntohs(rl
->links
) && len
> 0; len
-= 12, i
++) {
5805 type
= rl
->link
[i
].type
;
5807 vty_out(vty
, " Link connected to: %s\n",
5808 link_type_desc
[type
]);
5809 vty_out(vty
, " (Link ID) %s: %s\n", link_id_desc
[type
],
5810 inet_ntoa(rl
->link
[i
].link_id
));
5811 vty_out(vty
, " (Link Data) %s: %s\n", link_data_desc
[type
],
5812 inet_ntoa(rl
->link
[i
].link_data
));
5813 vty_out(vty
, " Number of TOS metrics: 0\n");
5814 vty_out(vty
, " TOS 0 Metric: %d\n",
5815 ntohs(rl
->link
[i
].metric
));
5820 /* Show router-LSA detail information. */
5821 static int show_router_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5824 struct router_lsa
*rl
= (struct router_lsa
*)lsa
->data
;
5826 show_ip_ospf_database_header(vty
, lsa
);
5828 vty_out(vty
, " Number of Links: %d\n\n", ntohs(rl
->links
));
5830 show_ip_ospf_database_router_links(vty
, rl
);
5837 /* Show network-LSA detail information. */
5838 static int show_network_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5843 struct network_lsa
*nl
= (struct network_lsa
*)lsa
->data
;
5845 show_ip_ospf_database_header(vty
, lsa
);
5847 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(nl
->mask
));
5849 length
= ntohs(lsa
->data
->length
) - OSPF_LSA_HEADER_SIZE
- 4;
5851 for (i
= 0; length
> 0; i
++, length
-= 4)
5852 vty_out(vty
, " Attached Router: %s\n",
5853 inet_ntoa(nl
->routers
[i
]));
5861 /* Show summary-LSA detail information. */
5862 static int show_summary_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5865 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
5867 show_ip_ospf_database_header(vty
, lsa
);
5869 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(sl
->mask
));
5870 vty_out(vty
, " TOS: 0 Metric: %d\n",
5871 GET_METRIC(sl
->metric
));
5878 /* Show summary-ASBR-LSA detail information. */
5879 static int show_summary_asbr_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5882 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
5884 show_ip_ospf_database_header(vty
, lsa
);
5886 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(sl
->mask
));
5887 vty_out(vty
, " TOS: 0 Metric: %d\n",
5888 GET_METRIC(sl
->metric
));
5895 /* Show AS-external-LSA detail information. */
5896 static int show_as_external_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5899 struct as_external_lsa
*al
=
5900 (struct as_external_lsa
*)lsa
->data
;
5902 show_ip_ospf_database_header(vty
, lsa
);
5904 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(al
->mask
));
5905 vty_out(vty
, " Metric Type: %s\n",
5906 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
5907 ? "2 (Larger than any link state path)"
5909 vty_out(vty
, " TOS: 0\n");
5910 vty_out(vty
, " Metric: %d\n",
5911 GET_METRIC(al
->e
[0].metric
));
5912 vty_out(vty
, " Forward Address: %s\n",
5913 inet_ntoa(al
->e
[0].fwd_addr
));
5916 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
5917 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
5924 show_as_external_lsa_stdvty (struct ospf_lsa
*lsa
)
5926 struct as_external_lsa
*al
= (struct as_external_lsa
*) lsa
->data
;
5928 /* show_ip_ospf_database_header (vty, lsa); */
5930 zlog_debug( " Network Mask: /%d%s",
5931 ip_masklen (al
->mask
), "\n");
5932 zlog_debug( " Metric Type: %s%s",
5933 IS_EXTERNAL_METRIC (al
->e
[0].tos
) ?
5934 "2 (Larger than any link state path)" : "1", "\n");
5935 zlog_debug( " TOS: 0%s", "\n");
5936 zlog_debug( " Metric: %d%s",
5937 GET_METRIC (al
->e
[0].metric
), "\n");
5938 zlog_debug( " Forward Address: %s%s",
5939 inet_ntoa (al
->e
[0].fwd_addr
), "\n");
5941 zlog_debug( " External Route Tag: %"ROUTE_TAG_PRI
"%s%s",
5942 (route_tag_t
)ntohl (al
->e
[0].route_tag
), "\n", "\n");
5947 /* Show AS-NSSA-LSA detail information. */
5948 static int show_as_nssa_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5951 struct as_external_lsa
*al
=
5952 (struct as_external_lsa
*)lsa
->data
;
5954 show_ip_ospf_database_header(vty
, lsa
);
5956 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(al
->mask
));
5957 vty_out(vty
, " Metric Type: %s\n",
5958 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
5959 ? "2 (Larger than any link state path)"
5961 vty_out(vty
, " TOS: 0\n");
5962 vty_out(vty
, " Metric: %d\n",
5963 GET_METRIC(al
->e
[0].metric
));
5964 vty_out(vty
, " NSSA: Forward Address: %s\n",
5965 inet_ntoa(al
->e
[0].fwd_addr
));
5968 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
5969 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
5975 static int show_func_dummy(struct vty
*vty
, struct ospf_lsa
*lsa
)
5980 static int show_opaque_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5983 show_ip_ospf_database_header(vty
, lsa
);
5984 show_opaque_info_detail(vty
, lsa
);
5991 int (*show_function
[])(struct vty
*, struct ospf_lsa
*) = {
5993 show_router_lsa_detail
,
5994 show_network_lsa_detail
,
5995 show_summary_lsa_detail
,
5996 show_summary_asbr_lsa_detail
,
5997 show_as_external_lsa_detail
,
5999 show_as_nssa_lsa_detail
, /* almost same as external */
6001 show_opaque_lsa_detail
,
6002 show_opaque_lsa_detail
,
6003 show_opaque_lsa_detail
,
6006 static void show_lsa_prefix_set(struct vty
*vty
, struct prefix_ls
*lp
,
6007 struct in_addr
*id
, struct in_addr
*adv_router
)
6009 memset(lp
, 0, sizeof(struct prefix_ls
));
6013 else if (adv_router
== NULL
) {
6019 lp
->adv_router
= *adv_router
;
6023 static void show_lsa_detail_proc(struct vty
*vty
, struct route_table
*rt
,
6024 struct in_addr
*id
, struct in_addr
*adv_router
)
6026 struct prefix_ls lp
;
6027 struct route_node
*rn
, *start
;
6028 struct ospf_lsa
*lsa
;
6030 show_lsa_prefix_set(vty
, &lp
, id
, adv_router
);
6031 start
= route_node_get(rt
, (struct prefix
*)&lp
);
6033 route_lock_node(start
);
6034 for (rn
= start
; rn
; rn
= route_next_until(rn
, start
))
6035 if ((lsa
= rn
->info
)) {
6036 if (show_function
[lsa
->data
->type
] != NULL
)
6037 show_function
[lsa
->data
->type
](vty
,
6040 route_unlock_node(start
);
6044 /* Show detail LSA information
6045 -- if id is NULL then show all LSAs. */
6046 static void show_lsa_detail(struct vty
*vty
, struct ospf
*ospf
, int type
,
6047 struct in_addr
*id
, struct in_addr
*adv_router
)
6049 struct listnode
*node
;
6050 struct ospf_area
*area
;
6053 case OSPF_AS_EXTERNAL_LSA
:
6054 case OSPF_OPAQUE_AS_LSA
:
6055 vty_out(vty
, " %s \n\n",
6056 show_database_desc
[type
]);
6057 show_lsa_detail_proc(vty
, AS_LSDB(ospf
, type
), id
, adv_router
);
6060 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6061 vty_out(vty
, "\n %s (Area %s)\n\n",
6062 show_database_desc
[type
],
6063 ospf_area_desc_string(area
));
6064 show_lsa_detail_proc(vty
, AREA_LSDB(area
, type
), id
,
6071 static void show_lsa_detail_adv_router_proc(struct vty
*vty
,
6072 struct route_table
*rt
,
6073 struct in_addr
*adv_router
)
6075 struct route_node
*rn
;
6076 struct ospf_lsa
*lsa
;
6078 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
))
6079 if ((lsa
= rn
->info
))
6080 if (IPV4_ADDR_SAME(adv_router
,
6081 &lsa
->data
->adv_router
)) {
6082 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
6084 if (show_function
[lsa
->data
->type
] != NULL
)
6085 show_function
[lsa
->data
->type
](vty
,
6090 /* Show detail LSA information. */
6091 static void show_lsa_detail_adv_router(struct vty
*vty
, struct ospf
*ospf
,
6092 int type
, struct in_addr
*adv_router
)
6094 struct listnode
*node
;
6095 struct ospf_area
*area
;
6098 case OSPF_AS_EXTERNAL_LSA
:
6099 case OSPF_OPAQUE_AS_LSA
:
6100 vty_out(vty
, " %s \n\n",
6101 show_database_desc
[type
]);
6102 show_lsa_detail_adv_router_proc(vty
, AS_LSDB(ospf
, type
),
6106 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6107 vty_out(vty
, "\n %s (Area %s)\n\n",
6108 show_database_desc
[type
],
6109 ospf_area_desc_string(area
));
6110 show_lsa_detail_adv_router_proc(
6111 vty
, AREA_LSDB(area
, type
), adv_router
);
6117 static void show_ip_ospf_database_summary(struct vty
*vty
, struct ospf
*ospf
,
6120 struct ospf_lsa
*lsa
;
6121 struct route_node
*rn
;
6122 struct ospf_area
*area
;
6123 struct listnode
*node
;
6126 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6127 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6129 case OSPF_AS_EXTERNAL_LSA
:
6130 case OSPF_OPAQUE_AS_LSA
:
6135 if (ospf_lsdb_count_self(area
->lsdb
, type
) > 0
6137 && ospf_lsdb_count(area
->lsdb
, type
) > 0)) {
6138 vty_out(vty
, " %s (Area %s)\n\n",
6139 show_database_desc
[type
],
6140 ospf_area_desc_string(area
));
6141 vty_out(vty
, "%s\n",
6142 show_database_header
[type
]);
6144 LSDB_LOOP (AREA_LSDB(area
, type
), rn
, lsa
)
6145 show_lsa_summary(vty
, lsa
, self
);
6152 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6154 case OSPF_AS_EXTERNAL_LSA
:
6155 case OSPF_OPAQUE_AS_LSA
:
6160 if (ospf_lsdb_count_self(ospf
->lsdb
, type
)
6161 || (!self
&& ospf_lsdb_count(ospf
->lsdb
, type
))) {
6162 vty_out(vty
, " %s\n\n",
6163 show_database_desc
[type
]);
6164 vty_out(vty
, "%s\n", show_database_header
[type
]);
6166 LSDB_LOOP (AS_LSDB(ospf
, type
), rn
, lsa
)
6167 show_lsa_summary(vty
, lsa
, self
);
6176 static void show_ip_ospf_database_maxage(struct vty
*vty
, struct ospf
*ospf
)
6178 struct route_node
*rn
;
6180 vty_out(vty
, "\n MaxAge Link States:\n\n");
6182 for (rn
= route_top(ospf
->maxage_lsa
); rn
; rn
= route_next(rn
)) {
6183 struct ospf_lsa
*lsa
;
6185 if ((lsa
= rn
->info
) != NULL
) {
6186 vty_out(vty
, "Link type: %d\n", lsa
->data
->type
);
6187 vty_out(vty
, "Link State ID: %s\n",
6188 inet_ntoa(lsa
->data
->id
));
6189 vty_out(vty
, "Advertising Router: %s\n",
6190 inet_ntoa(lsa
->data
->adv_router
));
6191 vty_out(vty
, "LSA lock count: %d\n", lsa
->lock
);
6197 #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
6198 #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
6200 #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
6201 #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
6202 #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
6203 #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
6205 #define OSPF_LSA_TYPES_DESC \
6206 "ASBR summary link states\n" \
6207 "External link states\n" \
6208 "Network link states\n" \
6209 "Router link states\n" \
6210 "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \
6211 OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
6212 OSPF_LSA_TYPE_OPAQUE_AS_DESC
6214 static int show_ip_ospf_database_common(struct vty
*vty
, struct ospf
*ospf
,
6215 int arg_base
, int argc
,
6216 struct cmd_token
**argv
,
6221 struct in_addr id
, adv_router
;
6224 vty_out(vty
, "\nOSPF Instance: %d\n", ospf
->instance
);
6226 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
6228 vty_out(vty
, "\n OSPF Router with ID (%s)\n\n",
6229 inet_ntoa(ospf
->router_id
));
6232 if (argc
== arg_base
+ 4) {
6233 show_ip_ospf_database_summary(vty
, ospf
, 0);
6237 /* Set database type to show. */
6238 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
6239 type
= OSPF_ROUTER_LSA
;
6240 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
6241 type
= OSPF_NETWORK_LSA
;
6242 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
6243 type
= OSPF_AS_NSSA_LSA
;
6244 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "su", 2) == 0)
6245 type
= OSPF_SUMMARY_LSA
;
6246 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
6247 type
= OSPF_ASBR_SUMMARY_LSA
;
6248 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
6249 type
= OSPF_AS_EXTERNAL_LSA
;
6250 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "se", 2) == 0) {
6251 show_ip_ospf_database_summary(vty
, ospf
, 1);
6253 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "m", 1) == 0) {
6254 show_ip_ospf_database_maxage(vty
, ospf
);
6256 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
6257 type
= OSPF_OPAQUE_LINK_LSA
;
6258 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
6259 type
= OSPF_OPAQUE_AREA_LSA
;
6260 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
6261 type
= OSPF_OPAQUE_AS_LSA
;
6265 /* `show ip ospf database LSA'. */
6266 if (argc
== arg_base
+ 5)
6267 show_lsa_detail(vty
, ospf
, type
, NULL
, NULL
);
6268 else if (argc
>= arg_base
+ 6) {
6269 ret
= inet_aton(argv
[arg_base
+ 5]->arg
, &id
);
6273 /* `show ip ospf database LSA ID'. */
6274 if (argc
== arg_base
+ 6)
6275 show_lsa_detail(vty
, ospf
, type
, &id
, NULL
);
6276 /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */
6277 else if (argc
== arg_base
+ 7) {
6278 if (strncmp(argv
[arg_base
+ 6]->text
, "s", 1) == 0)
6279 adv_router
= ospf
->router_id
;
6281 ret
= inet_aton(argv
[arg_base
+ 7]->arg
,
6286 show_lsa_detail(vty
, ospf
, type
, &id
, &adv_router
);
6293 DEFUN (show_ip_ospf_database_max
,
6294 show_ip_ospf_database_max_cmd
,
6295 "show ip ospf [vrf <NAME|all>] database <max-age|self-originate>",
6298 "OSPF information\n"
6301 "Database summary\n"
6302 "LSAs in MaxAge list\n"
6303 "Self-originated link states\n")
6305 struct ospf
*ospf
= NULL
;
6306 struct listnode
*node
= NULL
;
6307 char *vrf_name
= NULL
;
6308 bool all_vrf
= FALSE
;
6309 int ret
= CMD_SUCCESS
;
6312 uint8_t use_vrf
= 0;
6314 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
6319 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6320 if (!ospf
->oi_running
)
6322 ret
= show_ip_ospf_database_common(
6323 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
,
6327 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6328 if (ospf
== NULL
|| !ospf
->oi_running
)
6330 ret
= (show_ip_ospf_database_common(
6331 vty
, ospf
, idx_vrf
? 2 : 0, argc
, argv
,
6335 /* Display default ospf (instance 0) info */
6336 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6337 if (ospf
== NULL
|| !ospf
->oi_running
)
6339 ret
= show_ip_ospf_database_common(vty
, ospf
, 0, argc
, argv
,
6346 DEFUN (show_ip_ospf_instance_database
,
6347 show_ip_ospf_instance_database_cmd
,
6348 "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>]]]",
6351 "OSPF information\n"
6354 "Database summary\n"
6356 "Link State ID (as an IP address)\n"
6357 "Self-originated link states\n"
6358 "Advertising Router link states\n"
6359 "Advertising Router (as an IP address)\n")
6362 unsigned short instance
= 0;
6363 struct listnode
*node
= NULL
;
6364 char *vrf_name
= NULL
;
6365 bool all_vrf
= FALSE
;
6366 int ret
= CMD_SUCCESS
;
6369 uint8_t use_vrf
= 0;
6371 if (argv_find(argv
, argc
, "(1-65535)", &idx
)) {
6372 instance
= strtoul(argv
[idx
]->arg
, NULL
, 10);
6373 ospf
= ospf_lookup_instance(instance
);
6375 return CMD_NOT_MY_INSTANCE
;
6376 if (!ospf
->oi_running
)
6379 return (show_ip_ospf_database_common(vty
, ospf
, idx
? 1 : 0,
6380 argc
, argv
, use_vrf
));
6381 } else if (argv_find(argv
, argc
, "vrf", &idx
)) {
6382 vrf_name
= argv
[++idx
]->arg
;
6383 all_vrf
= strmatch(vrf_name
, "all");
6389 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6390 if (!ospf
->oi_running
)
6392 ret
= (show_ip_ospf_database_common(
6393 vty
, ospf
, idx
? 2 : 0, argc
, argv
,
6397 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6398 if ((ospf
== NULL
) || !ospf
->oi_running
)
6400 ret
= (show_ip_ospf_database_common(
6401 vty
, ospf
, idx
? 2 : 0, argc
, argv
, use_vrf
));
6404 /* Display default ospf (instance 0) info */
6405 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6406 if (ospf
== NULL
|| !ospf
->oi_running
)
6408 ret
= (show_ip_ospf_database_common(vty
, ospf
, 0, argc
, argv
,
6415 DEFUN (show_ip_ospf_instance_database_max
,
6416 show_ip_ospf_instance_database_max_cmd
,
6417 "show ip ospf (1-65535) database <max-age|self-originate>",
6420 "OSPF information\n"
6422 "Database summary\n"
6423 "LSAs in MaxAge list\n"
6424 "Self-originated link states\n")
6428 unsigned short instance
= 0;
6430 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
6432 ospf
= ospf_lookup_instance(instance
);
6434 return CMD_NOT_MY_INSTANCE
;
6436 if (!ospf
->oi_running
)
6439 return show_ip_ospf_database_common(vty
, ospf
, 1, argc
, argv
, 0);
6443 static int show_ip_ospf_database_type_adv_router_common(struct vty
*vty
,
6445 int arg_base
, int argc
,
6446 struct cmd_token
**argv
,
6451 struct in_addr adv_router
;
6454 vty_out(vty
, "\nOSPF Instance: %d\n", ospf
->instance
);
6456 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
6458 vty_out(vty
, "\n OSPF Router with ID (%s)\n\n",
6459 inet_ntoa(ospf
->router_id
));
6461 /* Set database type to show. */
6462 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
6463 type
= OSPF_ROUTER_LSA
;
6464 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
6465 type
= OSPF_NETWORK_LSA
;
6466 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
6467 type
= OSPF_AS_NSSA_LSA
;
6468 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "s", 1) == 0)
6469 type
= OSPF_SUMMARY_LSA
;
6470 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
6471 type
= OSPF_ASBR_SUMMARY_LSA
;
6472 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
6473 type
= OSPF_AS_EXTERNAL_LSA
;
6474 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
6475 type
= OSPF_OPAQUE_LINK_LSA
;
6476 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
6477 type
= OSPF_OPAQUE_AREA_LSA
;
6478 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
6479 type
= OSPF_OPAQUE_AS_LSA
;
6483 /* `show ip ospf database LSA adv-router ADV_ROUTER'. */
6484 if (strncmp(argv
[arg_base
+ 5]->text
, "s", 1) == 0)
6485 adv_router
= ospf
->router_id
;
6487 ret
= inet_aton(argv
[arg_base
+ 6]->arg
, &adv_router
);
6492 show_lsa_detail_adv_router(vty
, ospf
, type
, &adv_router
);
6497 DEFUN (show_ip_ospf_instance_database_type_adv_router
,
6498 show_ip_ospf_instance_database_type_adv_router_cmd
,
6499 "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>",
6502 "OSPF information\n"
6505 "Database summary\n"
6507 "Advertising Router link states\n"
6508 "Advertising Router (as an IP address)\n"
6509 "Self-originated link states\n")
6511 struct ospf
*ospf
= NULL
;
6512 unsigned short instance
= 0;
6513 struct listnode
*node
= NULL
;
6514 char *vrf_name
= NULL
;
6515 bool all_vrf
= FALSE
;
6516 int ret
= CMD_SUCCESS
;
6518 int idx
= 0, idx_vrf
= 0;
6519 uint8_t use_vrf
= 0;
6521 if (argv_find(argv
, argc
, "(1-65535)", &idx
)) {
6522 instance
= strtoul(argv
[idx
]->arg
, NULL
, 10);
6523 ospf
= ospf_lookup_instance(instance
);
6525 return CMD_NOT_MY_INSTANCE
;
6526 if (!ospf
->oi_running
)
6528 return (show_ip_ospf_database_type_adv_router_common(
6529 vty
, ospf
, idx
? 1 : 0, argc
, argv
, use_vrf
));
6532 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
6537 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6538 if (!ospf
->oi_running
)
6540 ret
= show_ip_ospf_database_type_adv_router_common(
6541 vty
, ospf
, idx
? 1 : 0, argc
, argv
,
6545 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6546 if ((ospf
== NULL
) || !ospf
->oi_running
)
6548 ret
= show_ip_ospf_database_type_adv_router_common(
6549 vty
, ospf
, idx
? 1 : 0, argc
, argv
, use_vrf
);
6552 /* Display default ospf (instance 0) info */
6553 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6554 if (ospf
== NULL
|| !ospf
->oi_running
)
6556 ret
= show_ip_ospf_database_type_adv_router_common(
6557 vty
, ospf
, idx
? 1 : 0, argc
, argv
, use_vrf
);
6560 /*return (show_ip_ospf_database_type_adv_router_common(
6561 vty, ospf, idx ? 1 : 0, argc, argv));*/
6564 DEFUN (ip_ospf_authentication_args
,
6565 ip_ospf_authentication_args_addr_cmd
,
6566 "ip ospf authentication <null|message-digest> [A.B.C.D]",
6568 "OSPF interface commands\n"
6569 "Enable authentication on this interface\n"
6570 "Use null authentication\n"
6571 "Use message-digest authentication\n"
6572 "Address of interface\n")
6574 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6575 int idx_encryption
= 3;
6577 struct in_addr addr
;
6579 struct ospf_if_params
*params
;
6581 params
= IF_DEF_PARAMS(ifp
);
6584 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6587 "Please specify interface address by A.B.C.D\n");
6588 return CMD_WARNING_CONFIG_FAILED
;
6591 params
= ospf_get_if_params(ifp
, addr
);
6592 ospf_if_update_params(ifp
, addr
);
6595 /* Handle null authentication */
6596 if (argv
[idx_encryption
]->arg
[0] == 'n') {
6597 SET_IF_PARAM(params
, auth_type
);
6598 params
->auth_type
= OSPF_AUTH_NULL
;
6602 /* Handle message-digest authentication */
6603 if (argv
[idx_encryption
]->arg
[0] == 'm') {
6604 SET_IF_PARAM(params
, auth_type
);
6605 params
->auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
6609 vty_out(vty
, "You shouldn't get here!\n");
6610 return CMD_WARNING_CONFIG_FAILED
;
6613 DEFUN (ip_ospf_authentication
,
6614 ip_ospf_authentication_addr_cmd
,
6615 "ip ospf authentication [A.B.C.D]",
6617 "OSPF interface commands\n"
6618 "Enable authentication on this interface\n"
6619 "Address of interface\n")
6621 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6623 struct in_addr addr
;
6625 struct ospf_if_params
*params
;
6627 params
= IF_DEF_PARAMS(ifp
);
6630 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6633 "Please specify interface address by A.B.C.D\n");
6634 return CMD_WARNING_CONFIG_FAILED
;
6637 params
= ospf_get_if_params(ifp
, addr
);
6638 ospf_if_update_params(ifp
, addr
);
6641 SET_IF_PARAM(params
, auth_type
);
6642 params
->auth_type
= OSPF_AUTH_SIMPLE
;
6647 DEFUN (no_ip_ospf_authentication_args
,
6648 no_ip_ospf_authentication_args_addr_cmd
,
6649 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
6652 "OSPF interface commands\n"
6653 "Enable authentication on this interface\n"
6654 "Use null authentication\n"
6655 "Use message-digest authentication\n"
6656 "Address of interface\n")
6658 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6659 int idx_encryption
= 4;
6661 struct in_addr addr
;
6663 struct ospf_if_params
*params
;
6664 struct route_node
*rn
;
6667 params
= IF_DEF_PARAMS(ifp
);
6670 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6673 "Please specify interface address by A.B.C.D\n");
6674 return CMD_WARNING_CONFIG_FAILED
;
6677 params
= ospf_lookup_if_params(ifp
, addr
);
6678 if (params
== NULL
) {
6679 vty_out(vty
, "Ip Address specified is unknown\n");
6680 return CMD_WARNING_CONFIG_FAILED
;
6682 params
->auth_type
= OSPF_AUTH_NOTSET
;
6683 UNSET_IF_PARAM(params
, auth_type
);
6684 if (params
!= IF_DEF_PARAMS(ifp
)) {
6685 ospf_free_if_params(ifp
, addr
);
6686 ospf_if_update_params(ifp
, addr
);
6689 if (argv
[idx_encryption
]->arg
[0] == 'n') {
6690 auth_type
= OSPF_AUTH_NULL
;
6691 } else if (argv
[idx_encryption
]->arg
[0] == 'm') {
6692 auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
6694 vty_out(vty
, "Unexpected input encountered\n");
6695 return CMD_WARNING_CONFIG_FAILED
;
6698 * Here we have a case where the user has entered
6699 * 'no ip ospf authentication (null | message_digest )'
6700 * we need to find if we have any ip addresses underneath it
6702 * correspond to the associated type.
6704 if (params
->auth_type
== auth_type
) {
6705 params
->auth_type
= OSPF_AUTH_NOTSET
;
6706 UNSET_IF_PARAM(params
, auth_type
);
6709 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
6710 rn
= route_next(rn
)) {
6711 if ((params
= rn
->info
)) {
6712 if (params
->auth_type
== auth_type
) {
6713 params
->auth_type
= OSPF_AUTH_NOTSET
;
6714 UNSET_IF_PARAM(params
, auth_type
);
6715 if (params
!= IF_DEF_PARAMS(ifp
)) {
6716 ospf_free_if_params(
6717 ifp
, rn
->p
.u
.prefix4
);
6718 ospf_if_update_params(
6719 ifp
, rn
->p
.u
.prefix4
);
6729 DEFUN (no_ip_ospf_authentication
,
6730 no_ip_ospf_authentication_addr_cmd
,
6731 "no ip ospf authentication [A.B.C.D]",
6734 "OSPF interface commands\n"
6735 "Enable authentication on this interface\n"
6736 "Address of interface\n")
6738 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6740 struct in_addr addr
;
6742 struct ospf_if_params
*params
;
6743 struct route_node
*rn
;
6745 params
= IF_DEF_PARAMS(ifp
);
6748 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6751 "Please specify interface address by A.B.C.D\n");
6752 return CMD_WARNING_CONFIG_FAILED
;
6755 params
= ospf_lookup_if_params(ifp
, addr
);
6756 if (params
== NULL
) {
6757 vty_out(vty
, "Ip Address specified is unknown\n");
6758 return CMD_WARNING_CONFIG_FAILED
;
6761 params
->auth_type
= OSPF_AUTH_NOTSET
;
6762 UNSET_IF_PARAM(params
, auth_type
);
6763 if (params
!= IF_DEF_PARAMS(ifp
)) {
6764 ospf_free_if_params(ifp
, addr
);
6765 ospf_if_update_params(ifp
, addr
);
6769 * When a user enters 'no ip ospf authentication'
6770 * We should remove all authentication types from
6773 if ((params
->auth_type
== OSPF_AUTH_NULL
)
6774 || (params
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
6775 || (params
->auth_type
== OSPF_AUTH_SIMPLE
)) {
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
)) {
6784 if ((params
->auth_type
== OSPF_AUTH_NULL
)
6785 || (params
->auth_type
6786 == OSPF_AUTH_CRYPTOGRAPHIC
)
6787 || (params
->auth_type
6788 == OSPF_AUTH_SIMPLE
)) {
6789 params
->auth_type
= OSPF_AUTH_NOTSET
;
6790 UNSET_IF_PARAM(params
, auth_type
);
6791 if (params
!= IF_DEF_PARAMS(ifp
)) {
6792 ospf_free_if_params(
6793 ifp
, rn
->p
.u
.prefix4
);
6794 ospf_if_update_params(
6795 ifp
, rn
->p
.u
.prefix4
);
6806 DEFUN (ip_ospf_authentication_key
,
6807 ip_ospf_authentication_key_addr_cmd
,
6808 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
6810 "OSPF interface commands\n"
6811 "Authentication password (key)\n"
6812 "The OSPF password (key)\n"
6813 "Address of interface\n")
6815 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6817 struct in_addr addr
;
6818 struct ospf_if_params
*params
;
6820 params
= IF_DEF_PARAMS(ifp
);
6822 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6823 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6825 "Please specify interface address by A.B.C.D\n");
6826 return CMD_WARNING_CONFIG_FAILED
;
6829 params
= ospf_get_if_params(ifp
, addr
);
6830 ospf_if_update_params(ifp
, addr
);
6833 memset(params
->auth_simple
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
6834 strncpy((char *)params
->auth_simple
, argv
[3]->arg
,
6835 OSPF_AUTH_SIMPLE_SIZE
);
6836 SET_IF_PARAM(params
, auth_simple
);
6841 DEFUN_HIDDEN (ospf_authentication_key
,
6842 ospf_authentication_key_cmd
,
6843 "ospf authentication-key AUTH_KEY [A.B.C.D]",
6844 "OSPF interface commands\n"
6845 VLINK_HELPSTR_AUTH_SIMPLE
6846 "Address of interface\n")
6848 return ip_ospf_authentication_key(self
, vty
, argc
, argv
);
6851 DEFUN (no_ip_ospf_authentication_key
,
6852 no_ip_ospf_authentication_key_authkey_addr_cmd
,
6853 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
6856 "OSPF interface commands\n"
6857 VLINK_HELPSTR_AUTH_SIMPLE
6858 "Address of interface\n")
6860 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6862 struct in_addr addr
;
6863 struct ospf_if_params
*params
;
6864 params
= IF_DEF_PARAMS(ifp
);
6866 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6867 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6869 "Please specify interface address by A.B.C.D\n");
6870 return CMD_WARNING_CONFIG_FAILED
;
6873 params
= ospf_lookup_if_params(ifp
, addr
);
6878 memset(params
->auth_simple
, 0, OSPF_AUTH_SIMPLE_SIZE
);
6879 UNSET_IF_PARAM(params
, auth_simple
);
6881 if (params
!= IF_DEF_PARAMS(ifp
)) {
6882 ospf_free_if_params(ifp
, addr
);
6883 ospf_if_update_params(ifp
, addr
);
6889 DEFUN_HIDDEN (no_ospf_authentication_key
,
6890 no_ospf_authentication_key_authkey_addr_cmd
,
6891 "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
6893 "OSPF interface commands\n"
6894 VLINK_HELPSTR_AUTH_SIMPLE
6895 "Address of interface\n")
6897 return no_ip_ospf_authentication_key(self
, vty
, argc
, argv
);
6900 DEFUN (ip_ospf_message_digest_key
,
6901 ip_ospf_message_digest_key_cmd
,
6902 "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
6904 "OSPF interface commands\n"
6905 "Message digest authentication password (key)\n"
6907 "Use MD5 algorithm\n"
6908 "The OSPF password (key)\n"
6909 "Address of interface\n")
6911 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6912 struct crypt_key
*ck
;
6914 struct in_addr addr
;
6915 struct ospf_if_params
*params
;
6917 params
= IF_DEF_PARAMS(ifp
);
6920 argv_find(argv
, argc
, "(1-255)", &idx
);
6921 char *keyid
= argv
[idx
]->arg
;
6922 argv_find(argv
, argc
, "KEY", &idx
);
6923 char *cryptkey
= argv
[idx
]->arg
;
6925 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6926 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6928 "Please specify interface address by A.B.C.D\n");
6929 return CMD_WARNING_CONFIG_FAILED
;
6932 params
= ospf_get_if_params(ifp
, addr
);
6933 ospf_if_update_params(ifp
, addr
);
6936 key_id
= strtol(keyid
, NULL
, 10);
6937 if (ospf_crypt_key_lookup(params
->auth_crypt
, key_id
) != NULL
) {
6938 vty_out(vty
, "OSPF: Key %d already exists\n", key_id
);
6942 ck
= ospf_crypt_key_new();
6943 ck
->key_id
= (uint8_t)key_id
;
6944 memset(ck
->auth_key
, 0, OSPF_AUTH_MD5_SIZE
+ 1);
6945 strncpy((char *)ck
->auth_key
, cryptkey
, OSPF_AUTH_MD5_SIZE
);
6947 ospf_crypt_key_add(params
->auth_crypt
, ck
);
6948 SET_IF_PARAM(params
, auth_crypt
);
6953 DEFUN_HIDDEN (ospf_message_digest_key
,
6954 ospf_message_digest_key_cmd
,
6955 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
6956 "OSPF interface commands\n"
6957 "Message digest authentication password (key)\n"
6959 "Use MD5 algorithm\n"
6960 "The OSPF password (key)\n"
6961 "Address of interface\n")
6963 return ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
6966 DEFUN (no_ip_ospf_message_digest_key
,
6967 no_ip_ospf_message_digest_key_cmd
,
6968 "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
6971 "OSPF interface commands\n"
6972 "Message digest authentication password (key)\n"
6974 "Use MD5 algorithm\n"
6975 "The OSPF password (key)\n"
6976 "Address of interface\n")
6978 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6980 struct crypt_key
*ck
;
6982 struct in_addr addr
;
6983 struct ospf_if_params
*params
;
6984 params
= IF_DEF_PARAMS(ifp
);
6986 argv_find(argv
, argc
, "(1-255)", &idx
);
6987 char *keyid
= argv
[idx
]->arg
;
6989 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6990 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6992 "Please specify interface address by A.B.C.D\n");
6993 return CMD_WARNING_CONFIG_FAILED
;
6996 params
= ospf_lookup_if_params(ifp
, addr
);
7001 key_id
= strtol(keyid
, NULL
, 10);
7002 ck
= ospf_crypt_key_lookup(params
->auth_crypt
, key_id
);
7004 vty_out(vty
, "OSPF: Key %d does not exist\n", key_id
);
7005 return CMD_WARNING_CONFIG_FAILED
;
7008 ospf_crypt_key_delete(params
->auth_crypt
, key_id
);
7010 if (params
!= IF_DEF_PARAMS(ifp
)) {
7011 ospf_free_if_params(ifp
, addr
);
7012 ospf_if_update_params(ifp
, addr
);
7018 DEFUN_HIDDEN (no_ospf_message_digest_key
,
7019 no_ospf_message_digest_key_cmd
,
7020 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7022 "OSPF interface commands\n"
7023 "Message digest authentication password (key)\n"
7025 "Use MD5 algorithm\n"
7026 "The OSPF password (key)\n"
7027 "Address of interface\n")
7029 return no_ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7032 DEFUN (ip_ospf_cost
,
7034 "ip ospf cost (1-65535) [A.B.C.D]",
7036 "OSPF interface commands\n"
7039 "Address of interface\n")
7041 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7043 uint32_t cost
= OSPF_OUTPUT_COST_DEFAULT
;
7044 struct in_addr addr
;
7045 struct ospf_if_params
*params
;
7046 params
= IF_DEF_PARAMS(ifp
);
7049 char *coststr
= NULL
, *ifaddr
= NULL
;
7051 argv_find(argv
, argc
, "(1-65535)", &idx
);
7052 coststr
= argv
[idx
]->arg
;
7053 cost
= strtol(coststr
, NULL
, 10);
7055 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7057 if (!inet_aton(ifaddr
, &addr
)) {
7059 "Please specify interface address by A.B.C.D\n");
7060 return CMD_WARNING_CONFIG_FAILED
;
7063 params
= ospf_get_if_params(ifp
, addr
);
7064 ospf_if_update_params(ifp
, addr
);
7067 SET_IF_PARAM(params
, output_cost_cmd
);
7068 params
->output_cost_cmd
= cost
;
7070 ospf_if_recalculate_output_cost(ifp
);
7075 DEFUN_HIDDEN (ospf_cost
,
7077 "ospf cost (1-65535) [A.B.C.D]",
7078 "OSPF interface commands\n"
7081 "Address of interface\n")
7083 return ip_ospf_cost(self
, vty
, argc
, argv
);
7086 DEFUN (no_ip_ospf_cost
,
7087 no_ip_ospf_cost_cmd
,
7088 "no ip ospf cost [(1-65535)] [A.B.C.D]",
7091 "OSPF interface commands\n"
7094 "Address of interface\n")
7096 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7098 struct in_addr addr
;
7099 struct ospf_if_params
*params
;
7101 params
= IF_DEF_PARAMS(ifp
);
7104 char *ifaddr
= NULL
;
7105 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7107 /* According to the semantics we are mimicking "no ip ospf cost N" is
7108 * always treated as "no ip ospf cost" regardless of the actual value
7109 * of N already configured for the interface. Thus ignore cost. */
7112 if (!inet_aton(ifaddr
, &addr
)) {
7114 "Please specify interface address by A.B.C.D\n");
7115 return CMD_WARNING_CONFIG_FAILED
;
7118 params
= ospf_lookup_if_params(ifp
, addr
);
7123 UNSET_IF_PARAM(params
, output_cost_cmd
);
7125 if (params
!= IF_DEF_PARAMS(ifp
)) {
7126 ospf_free_if_params(ifp
, addr
);
7127 ospf_if_update_params(ifp
, addr
);
7130 ospf_if_recalculate_output_cost(ifp
);
7135 DEFUN_HIDDEN (no_ospf_cost
,
7137 "no ospf cost [(1-65535)] [A.B.C.D]",
7139 "OSPF interface commands\n"
7142 "Address of interface\n")
7144 return no_ip_ospf_cost(self
, vty
, argc
, argv
);
7147 static void ospf_nbr_timer_update(struct ospf_interface
*oi
)
7149 struct route_node
*rn
;
7150 struct ospf_neighbor
*nbr
;
7152 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
7153 if ((nbr
= rn
->info
)) {
7154 nbr
->v_inactivity
= OSPF_IF_PARAM(oi
, v_wait
);
7155 nbr
->v_db_desc
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7156 nbr
->v_ls_req
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7157 nbr
->v_ls_upd
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7161 static int ospf_vty_dead_interval_set(struct vty
*vty
, const char *interval_str
,
7162 const char *nbr_str
,
7163 const char *fast_hello_str
)
7165 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7168 struct in_addr addr
;
7170 struct ospf_if_params
*params
;
7171 struct ospf_interface
*oi
;
7172 struct route_node
*rn
;
7174 params
= IF_DEF_PARAMS(ifp
);
7177 ret
= inet_aton(nbr_str
, &addr
);
7180 "Please specify interface address by A.B.C.D\n");
7181 return CMD_WARNING_CONFIG_FAILED
;
7184 params
= ospf_get_if_params(ifp
, addr
);
7185 ospf_if_update_params(ifp
, addr
);
7189 seconds
= strtoul(interval_str
, NULL
, 10);
7191 /* reset fast_hello too, just to be sure */
7192 UNSET_IF_PARAM(params
, fast_hello
);
7193 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
7194 } else if (fast_hello_str
) {
7195 hellomult
= strtoul(fast_hello_str
, NULL
, 10);
7196 /* 1s dead-interval with sub-second hellos desired */
7197 seconds
= OSPF_ROUTER_DEAD_INTERVAL_MINIMAL
;
7198 SET_IF_PARAM(params
, fast_hello
);
7199 params
->fast_hello
= hellomult
;
7202 "Please specify dead-interval or hello-multiplier\n");
7203 return CMD_WARNING_CONFIG_FAILED
;
7206 SET_IF_PARAM(params
, v_wait
);
7207 params
->v_wait
= seconds
;
7209 /* Update timer values in neighbor structure. */
7211 struct ospf
*ospf
= NULL
;
7213 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7215 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
7217 ospf_nbr_timer_update(oi
);
7220 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
7221 if ((oi
= rn
->info
))
7222 ospf_nbr_timer_update(oi
);
7228 DEFUN (ip_ospf_dead_interval
,
7229 ip_ospf_dead_interval_cmd
,
7230 "ip ospf dead-interval (1-65535) [A.B.C.D]",
7232 "OSPF interface commands\n"
7233 "Interval time after which a neighbor is declared down\n"
7235 "Address of interface\n")
7238 char *interval
= argv_find(argv
, argc
, "(1-65535)", &idx
)
7242 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7243 return ospf_vty_dead_interval_set(vty
, interval
, ifaddr
, NULL
);
7247 DEFUN_HIDDEN (ospf_dead_interval
,
7248 ospf_dead_interval_cmd
,
7249 "ospf dead-interval (1-65535) [A.B.C.D]",
7250 "OSPF interface commands\n"
7251 "Interval time after which a neighbor is declared down\n"
7253 "Address of interface\n")
7255 return ip_ospf_dead_interval(self
, vty
, argc
, argv
);
7258 DEFUN (ip_ospf_dead_interval_minimal
,
7259 ip_ospf_dead_interval_minimal_addr_cmd
,
7260 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
7262 "OSPF interface commands\n"
7263 "Interval time after which a neighbor is declared down\n"
7264 "Minimal 1s dead-interval with fast sub-second hellos\n"
7265 "Hello multiplier factor\n"
7266 "Number of Hellos to send each second\n"
7267 "Address of interface\n")
7272 return ospf_vty_dead_interval_set(
7273 vty
, NULL
, argv
[idx_ipv4
]->arg
, argv
[idx_number
]->arg
);
7275 return ospf_vty_dead_interval_set(vty
, NULL
, NULL
,
7276 argv
[idx_number
]->arg
);
7279 DEFUN (no_ip_ospf_dead_interval
,
7280 no_ip_ospf_dead_interval_cmd
,
7281 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
7284 "OSPF interface commands\n"
7285 "Interval time after which a neighbor is declared down\n"
7287 "Minimal 1s dead-interval with fast sub-second hellos\n"
7288 "Hello multiplier factor\n"
7289 "Number of Hellos to send each second\n"
7290 "Address of interface\n")
7292 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7293 int idx_ipv4
= argc
- 1;
7294 struct in_addr addr
= {.s_addr
= 0L};
7296 struct ospf_if_params
*params
;
7297 struct ospf_interface
*oi
;
7298 struct route_node
*rn
;
7300 params
= IF_DEF_PARAMS(ifp
);
7302 if (argv
[idx_ipv4
]->type
== IPV4_TKN
) {
7303 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7306 "Please specify interface address by A.B.C.D\n");
7307 return CMD_WARNING_CONFIG_FAILED
;
7310 params
= ospf_lookup_if_params(ifp
, addr
);
7315 UNSET_IF_PARAM(params
, v_wait
);
7316 params
->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
7318 UNSET_IF_PARAM(params
, fast_hello
);
7319 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
7321 if (params
!= IF_DEF_PARAMS(ifp
)) {
7322 ospf_free_if_params(ifp
, addr
);
7323 ospf_if_update_params(ifp
, addr
);
7326 /* Update timer values in neighbor structure. */
7328 struct ospf
*ospf
= NULL
;
7330 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7332 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
7334 ospf_nbr_timer_update(oi
);
7337 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
7338 if ((oi
= rn
->info
))
7339 ospf_nbr_timer_update(oi
);
7345 DEFUN_HIDDEN (no_ospf_dead_interval
,
7346 no_ospf_dead_interval_cmd
,
7347 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
7349 "OSPF interface commands\n"
7350 "Interval time after which a neighbor is declared down\n"
7352 "Minimal 1s dead-interval with fast sub-second hellos\n"
7353 "Hello multiplier factor\n"
7354 "Number of Hellos to send each second\n"
7355 "Address of interface\n")
7357 return no_ip_ospf_dead_interval(self
, vty
, argc
, argv
);
7360 DEFUN (ip_ospf_hello_interval
,
7361 ip_ospf_hello_interval_cmd
,
7362 "ip ospf hello-interval (1-65535) [A.B.C.D]",
7364 "OSPF interface commands\n"
7365 "Time between HELLO packets\n"
7367 "Address of interface\n")
7369 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7371 struct in_addr addr
;
7372 struct ospf_if_params
*params
;
7373 params
= IF_DEF_PARAMS(ifp
);
7374 uint32_t seconds
= 0;
7376 argv_find(argv
, argc
, "(1-65535)", &idx
);
7377 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7379 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7380 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7382 "Please specify interface address by A.B.C.D\n");
7383 return CMD_WARNING_CONFIG_FAILED
;
7386 params
= ospf_get_if_params(ifp
, addr
);
7387 ospf_if_update_params(ifp
, addr
);
7390 SET_IF_PARAM(params
, v_hello
);
7391 params
->v_hello
= seconds
;
7396 DEFUN_HIDDEN (ospf_hello_interval
,
7397 ospf_hello_interval_cmd
,
7398 "ospf hello-interval (1-65535) [A.B.C.D]",
7399 "OSPF interface commands\n"
7400 "Time between HELLO packets\n"
7402 "Address of interface\n")
7404 return ip_ospf_hello_interval(self
, vty
, argc
, argv
);
7407 DEFUN (no_ip_ospf_hello_interval
,
7408 no_ip_ospf_hello_interval_cmd
,
7409 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
7412 "OSPF interface commands\n"
7413 "Time between HELLO packets\n" // ignored
7415 "Address of interface\n")
7417 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7419 struct in_addr addr
;
7420 struct ospf_if_params
*params
;
7422 params
= IF_DEF_PARAMS(ifp
);
7424 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7425 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7427 "Please specify interface address by A.B.C.D\n");
7428 return CMD_WARNING_CONFIG_FAILED
;
7431 params
= ospf_lookup_if_params(ifp
, addr
);
7436 UNSET_IF_PARAM(params
, v_hello
);
7437 params
->v_hello
= OSPF_HELLO_INTERVAL_DEFAULT
;
7439 if (params
!= IF_DEF_PARAMS(ifp
)) {
7440 ospf_free_if_params(ifp
, addr
);
7441 ospf_if_update_params(ifp
, addr
);
7447 DEFUN_HIDDEN (no_ospf_hello_interval
,
7448 no_ospf_hello_interval_cmd
,
7449 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
7451 "OSPF interface commands\n"
7452 "Time between HELLO packets\n" // ignored
7454 "Address of interface\n")
7456 return no_ip_ospf_hello_interval(self
, vty
, argc
, argv
);
7459 DEFUN (ip_ospf_network
,
7460 ip_ospf_network_cmd
,
7461 "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
7463 "OSPF interface commands\n"
7465 "Specify OSPF broadcast multi-access network\n"
7466 "Specify OSPF NBMA network\n"
7467 "Specify OSPF point-to-multipoint network\n"
7468 "Specify OSPF point-to-point network\n")
7470 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7472 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
7473 struct route_node
*rn
;
7475 if (old_type
== OSPF_IFTYPE_LOOPBACK
) {
7477 "This is a loopback interface. Can't set network type.\n");
7478 return CMD_WARNING_CONFIG_FAILED
;
7481 if (argv_find(argv
, argc
, "broadcast", &idx
))
7482 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_BROADCAST
;
7483 else if (argv_find(argv
, argc
, "non-broadcast", &idx
))
7484 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_NBMA
;
7485 else if (argv_find(argv
, argc
, "point-to-multipoint", &idx
))
7486 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOMULTIPOINT
;
7487 else if (argv_find(argv
, argc
, "point-to-point", &idx
))
7488 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOPOINT
;
7490 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
7493 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), type
);
7495 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7496 struct ospf_interface
*oi
= rn
->info
;
7501 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
7503 if (oi
->state
> ISM_Down
) {
7504 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
7505 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
7512 DEFUN_HIDDEN (ospf_network
,
7514 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
7515 "OSPF interface commands\n"
7517 "Specify OSPF broadcast multi-access network\n"
7518 "Specify OSPF NBMA network\n"
7519 "Specify OSPF point-to-multipoint network\n"
7520 "Specify OSPF point-to-point network\n")
7522 return ip_ospf_network(self
, vty
, argc
, argv
);
7525 DEFUN (no_ip_ospf_network
,
7526 no_ip_ospf_network_cmd
,
7527 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
7530 "OSPF interface commands\n"
7532 "Specify OSPF broadcast multi-access network\n"
7533 "Specify OSPF NBMA network\n"
7534 "Specify OSPF point-to-multipoint network\n"
7535 "Specify OSPF point-to-point network\n")
7537 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7538 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
7539 struct route_node
*rn
;
7541 IF_DEF_PARAMS(ifp
)->type
= ospf_default_iftype(ifp
);
7543 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
7546 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7547 struct ospf_interface
*oi
= rn
->info
;
7552 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
7554 if (oi
->state
> ISM_Down
) {
7555 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
7556 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
7563 DEFUN_HIDDEN (no_ospf_network
,
7564 no_ospf_network_cmd
,
7565 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
7567 "OSPF interface commands\n"
7569 "Specify OSPF broadcast multi-access network\n"
7570 "Specify OSPF NBMA network\n"
7571 "Specify OSPF point-to-multipoint network\n"
7572 "Specify OSPF point-to-point network\n")
7574 return no_ip_ospf_network(self
, vty
, argc
, argv
);
7577 DEFUN (ip_ospf_priority
,
7578 ip_ospf_priority_cmd
,
7579 "ip ospf priority (0-255) [A.B.C.D]",
7581 "OSPF interface commands\n"
7584 "Address of interface\n")
7586 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7589 struct route_node
*rn
;
7590 struct in_addr addr
;
7591 struct ospf_if_params
*params
;
7592 params
= IF_DEF_PARAMS(ifp
);
7594 argv_find(argv
, argc
, "(0-255)", &idx
);
7595 priority
= strtol(argv
[idx
]->arg
, NULL
, 10);
7597 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7598 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7600 "Please specify interface address by A.B.C.D\n");
7601 return CMD_WARNING_CONFIG_FAILED
;
7604 params
= ospf_get_if_params(ifp
, addr
);
7605 ospf_if_update_params(ifp
, addr
);
7608 SET_IF_PARAM(params
, priority
);
7609 params
->priority
= priority
;
7611 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7612 struct ospf_interface
*oi
= rn
->info
;
7617 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
7618 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
7619 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
7626 DEFUN_HIDDEN (ospf_priority
,
7628 "ospf priority (0-255) [A.B.C.D]",
7629 "OSPF interface commands\n"
7632 "Address of interface\n")
7634 return ip_ospf_priority(self
, vty
, argc
, argv
);
7637 DEFUN (no_ip_ospf_priority
,
7638 no_ip_ospf_priority_cmd
,
7639 "no ip ospf priority [(0-255) [A.B.C.D]]",
7642 "OSPF interface commands\n"
7643 "Router priority\n" // ignored
7645 "Address of interface\n")
7647 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7649 struct route_node
*rn
;
7650 struct in_addr addr
;
7651 struct ospf_if_params
*params
;
7653 params
= IF_DEF_PARAMS(ifp
);
7655 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7656 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7658 "Please specify interface address by A.B.C.D\n");
7659 return CMD_WARNING_CONFIG_FAILED
;
7662 params
= ospf_lookup_if_params(ifp
, addr
);
7667 UNSET_IF_PARAM(params
, priority
);
7668 params
->priority
= OSPF_ROUTER_PRIORITY_DEFAULT
;
7670 if (params
!= IF_DEF_PARAMS(ifp
)) {
7671 ospf_free_if_params(ifp
, addr
);
7672 ospf_if_update_params(ifp
, addr
);
7675 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7676 struct ospf_interface
*oi
= rn
->info
;
7681 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
7682 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
7683 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
7690 DEFUN_HIDDEN (no_ospf_priority
,
7691 no_ospf_priority_cmd
,
7692 "no ospf priority [(0-255) [A.B.C.D]]",
7694 "OSPF interface commands\n"
7697 "Address of interface\n")
7699 return no_ip_ospf_priority(self
, vty
, argc
, argv
);
7702 DEFUN (ip_ospf_retransmit_interval
,
7703 ip_ospf_retransmit_interval_addr_cmd
,
7704 "ip ospf retransmit-interval (3-65535) [A.B.C.D]",
7706 "OSPF interface commands\n"
7707 "Time between retransmitting lost link state advertisements\n"
7709 "Address of interface\n")
7711 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7714 struct in_addr addr
;
7715 struct ospf_if_params
*params
;
7716 params
= IF_DEF_PARAMS(ifp
);
7718 argv_find(argv
, argc
, "(3-65535)", &idx
);
7719 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7721 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7722 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7724 "Please specify interface address by A.B.C.D\n");
7725 return CMD_WARNING_CONFIG_FAILED
;
7728 params
= ospf_get_if_params(ifp
, addr
);
7729 ospf_if_update_params(ifp
, addr
);
7732 SET_IF_PARAM(params
, retransmit_interval
);
7733 params
->retransmit_interval
= seconds
;
7738 DEFUN_HIDDEN (ospf_retransmit_interval
,
7739 ospf_retransmit_interval_cmd
,
7740 "ospf retransmit-interval (3-65535) [A.B.C.D]",
7741 "OSPF interface commands\n"
7742 "Time between retransmitting lost link state advertisements\n"
7744 "Address of interface\n")
7746 return ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
7749 DEFUN (no_ip_ospf_retransmit_interval
,
7750 no_ip_ospf_retransmit_interval_addr_cmd
,
7751 "no ip ospf retransmit-interval [(3-65535)] [A.B.C.D]",
7754 "OSPF interface commands\n"
7755 "Time between retransmitting lost link state advertisements\n"
7757 "Address of interface\n")
7759 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7761 struct in_addr addr
;
7762 struct ospf_if_params
*params
;
7764 params
= IF_DEF_PARAMS(ifp
);
7766 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7767 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7769 "Please specify interface address by A.B.C.D\n");
7770 return CMD_WARNING_CONFIG_FAILED
;
7773 params
= ospf_lookup_if_params(ifp
, addr
);
7778 UNSET_IF_PARAM(params
, retransmit_interval
);
7779 params
->retransmit_interval
= OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
7781 if (params
!= IF_DEF_PARAMS(ifp
)) {
7782 ospf_free_if_params(ifp
, addr
);
7783 ospf_if_update_params(ifp
, addr
);
7789 DEFUN_HIDDEN (no_ospf_retransmit_interval
,
7790 no_ospf_retransmit_interval_cmd
,
7791 "no ospf retransmit-interval [(3-65535)] [A.B.C.D]",
7793 "OSPF interface commands\n"
7794 "Time between retransmitting lost link state advertisements\n"
7796 "Address of interface\n")
7798 return no_ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
7801 DEFUN (ip_ospf_transmit_delay
,
7802 ip_ospf_transmit_delay_addr_cmd
,
7803 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
7805 "OSPF interface commands\n"
7806 "Link state transmit delay\n"
7808 "Address of interface\n")
7810 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7813 struct in_addr addr
;
7814 struct ospf_if_params
*params
;
7816 params
= IF_DEF_PARAMS(ifp
);
7817 argv_find(argv
, argc
, "(1-65535)", &idx
);
7818 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7820 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7821 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7823 "Please specify interface address by A.B.C.D\n");
7824 return CMD_WARNING_CONFIG_FAILED
;
7827 params
= ospf_get_if_params(ifp
, addr
);
7828 ospf_if_update_params(ifp
, addr
);
7831 SET_IF_PARAM(params
, transmit_delay
);
7832 params
->transmit_delay
= seconds
;
7837 DEFUN_HIDDEN (ospf_transmit_delay
,
7838 ospf_transmit_delay_cmd
,
7839 "ospf transmit-delay (1-65535) [A.B.C.D]",
7840 "OSPF interface commands\n"
7841 "Link state transmit delay\n"
7843 "Address of interface\n")
7845 return ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
7848 DEFUN (no_ip_ospf_transmit_delay
,
7849 no_ip_ospf_transmit_delay_addr_cmd
,
7850 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
7853 "OSPF interface commands\n"
7854 "Link state transmit delay\n"
7856 "Address of interface\n")
7858 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7860 struct in_addr addr
;
7861 struct ospf_if_params
*params
;
7863 params
= IF_DEF_PARAMS(ifp
);
7865 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7866 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7868 "Please specify interface address by A.B.C.D\n");
7869 return CMD_WARNING_CONFIG_FAILED
;
7872 params
= ospf_lookup_if_params(ifp
, addr
);
7877 UNSET_IF_PARAM(params
, transmit_delay
);
7878 params
->transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
7880 if (params
!= IF_DEF_PARAMS(ifp
)) {
7881 ospf_free_if_params(ifp
, addr
);
7882 ospf_if_update_params(ifp
, addr
);
7889 DEFUN_HIDDEN (no_ospf_transmit_delay
,
7890 no_ospf_transmit_delay_cmd
,
7891 "no ospf transmit-delay [(1-65535) [A.B.C.D]]",
7893 "OSPF interface commands\n"
7894 "Link state transmit delay\n"
7896 "Address of interface\n")
7898 return no_ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
7901 DEFUN (ip_ospf_area
,
7903 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]",
7905 "OSPF interface commands\n"
7907 "Enable OSPF on this interface\n"
7908 "OSPF area ID in IP address format\n"
7909 "OSPF area ID as a decimal value\n"
7910 "Address of interface\n")
7912 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7915 struct in_addr area_id
;
7916 struct in_addr addr
;
7917 struct ospf_if_params
*params
= NULL
;
7918 struct route_node
*rn
;
7919 struct ospf
*ospf
= NULL
;
7920 unsigned short instance
= 0;
7923 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
7924 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
7926 argv_find(argv
, argc
, "area", &idx
);
7927 areaid
= argv
[idx
+ 1]->arg
;
7929 if (ifp
->vrf_id
&& !instance
)
7930 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7932 ospf
= ospf_lookup_instance(instance
);
7934 if (instance
&& ospf
== NULL
) {
7935 params
= IF_DEF_PARAMS(ifp
);
7936 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
7937 UNSET_IF_PARAM(params
, if_area
);
7938 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
7939 ospf_interface_area_unset(ospf
, ifp
);
7940 ospf
->if_ospf_cli_count
--;
7942 return CMD_NOT_MY_INSTANCE
;
7945 ret
= str2area_id(areaid
, &area_id
, &format
);
7947 vty_out(vty
, "Please specify area by A.B.C.D|<0-4294967295>\n");
7948 return CMD_WARNING_CONFIG_FAILED
;
7950 if (memcmp(ifp
->name
, "VLINK", 5) == 0) {
7951 vty_out(vty
, "Cannot enable OSPF on a virtual link.\n");
7952 return CMD_WARNING_CONFIG_FAILED
;
7955 params
= IF_DEF_PARAMS(ifp
);
7956 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)
7957 && !IPV4_ADDR_SAME(¶ms
->if_area
, &area_id
)) {
7959 "Must remove previous area config before changing ospf area \n");
7960 return CMD_WARNING_CONFIG_FAILED
;
7963 // Check if we have an address arg and proccess it
7964 if (argc
== idx
+ 3) {
7965 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
7967 "Please specify Intf Address by A.B.C.D\n");
7968 return CMD_WARNING_CONFIG_FAILED
;
7970 // update/create address-level params
7971 params
= ospf_get_if_params((ifp
), (addr
));
7972 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
7974 "Must remove previous area/address config before changing ospf area");
7975 return CMD_WARNING_CONFIG_FAILED
;
7977 ospf_if_update_params((ifp
), (addr
));
7981 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
)) {
7982 if (rn
->info
!= NULL
) {
7984 "Please remove all network commands first.\n");
7985 return CMD_WARNING_CONFIG_FAILED
;
7990 /* enable ospf on this interface with area_id */
7992 SET_IF_PARAM(params
, if_area
);
7993 params
->if_area
= area_id
;
7994 params
->if_area_id_fmt
= format
;
7998 ospf_interface_area_set(ospf
, ifp
);
7999 ospf
->if_ospf_cli_count
++;
8005 DEFUN (no_ip_ospf_area
,
8006 no_ip_ospf_area_cmd
,
8007 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]",
8010 "OSPF interface commands\n"
8012 "Disable OSPF on this interface\n"
8013 "OSPF area ID in IP address format\n"
8014 "OSPF area ID as a decimal value\n"
8015 "Address of interface\n")
8017 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8020 struct ospf_if_params
*params
;
8021 unsigned short instance
= 0;
8022 struct in_addr addr
;
8024 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
8025 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
8027 if (ifp
->vrf_id
&& !instance
)
8028 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
8030 ospf
= ospf_lookup_instance(instance
);
8033 return CMD_NOT_MY_INSTANCE
;
8035 argv_find(argv
, argc
, "area", &idx
);
8037 // Check if we have an address arg and proccess it
8038 if (argc
== idx
+ 3) {
8039 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
8041 "Please specify Intf Address by A.B.C.D\n");
8042 return CMD_WARNING_CONFIG_FAILED
;
8044 params
= ospf_lookup_if_params(ifp
, addr
);
8045 if ((params
) == NULL
)
8048 params
= IF_DEF_PARAMS(ifp
);
8050 if (!OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8052 "Can't find specified interface area configuration.\n");
8053 return CMD_WARNING_CONFIG_FAILED
;
8056 UNSET_IF_PARAM(params
, if_area
);
8057 if (params
!= IF_DEF_PARAMS((ifp
))) {
8058 ospf_free_if_params((ifp
), (addr
));
8059 ospf_if_update_params((ifp
), (addr
));
8062 ospf_interface_area_unset(ospf
, ifp
);
8063 ospf
->if_ospf_cli_count
--;
8067 DEFUN (ospf_redistribute_source
,
8068 ospf_redistribute_source_cmd
,
8069 "redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8071 FRR_REDIST_HELP_STR_OSPFD
8072 "Metric for redistributed routes\n"
8073 "OSPF default metric\n"
8074 "OSPF exterior metric type for redistributed routes\n"
8075 "Set OSPF External Type 1/2 metrics\n"
8076 "Route map reference\n"
8077 "Pointer to route-map entries\n")
8079 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8080 int idx_protocol
= 1;
8084 struct ospf_redist
*red
;
8090 /* Get distribute source. */
8091 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
8093 return CMD_WARNING_CONFIG_FAILED
;
8095 red
= ospf_redist_add(ospf
, source
, 0);
8097 /* Get metric value. */
8098 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
8099 if (!str2metric(argv
[idx
]->arg
, &metric
))
8100 return CMD_WARNING_CONFIG_FAILED
;
8103 /* Get metric type. */
8104 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
8105 if (!str2metric_type(argv
[idx
]->arg
, &type
))
8106 return CMD_WARNING_CONFIG_FAILED
;
8110 if (argv_find(argv
, argc
, "WORD", &idx
)) {
8111 ospf_routemap_set(red
, argv
[idx
]->arg
);
8113 ospf_routemap_unset(red
);
8115 return ospf_redistribute_set(ospf
, source
, 0, type
, metric
);
8118 DEFUN (no_ospf_redistribute_source
,
8119 no_ospf_redistribute_source_cmd
,
8120 "no redistribute " FRR_REDIST_STR_OSPFD
" [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8123 FRR_REDIST_HELP_STR_OSPFD
8124 "Metric for redistributed routes\n"
8125 "OSPF default metric\n"
8126 "OSPF exterior metric type for redistributed routes\n"
8127 "Set OSPF External Type 1/2 metrics\n"
8128 "Route map reference\n"
8129 "Pointer to route-map entries\n")
8131 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8132 int idx_protocol
= 2;
8134 struct ospf_redist
*red
;
8136 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
8138 return CMD_WARNING_CONFIG_FAILED
;
8140 red
= ospf_redist_lookup(ospf
, source
, 0);
8144 ospf_routemap_unset(red
);
8145 return ospf_redistribute_unset(ospf
, source
, 0);
8148 DEFUN (ospf_redistribute_instance_source
,
8149 ospf_redistribute_instance_source_cmd
,
8150 "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8152 "Open Shortest Path First\n"
8153 "Non-main Kernel Routing Table\n"
8154 "Instance ID/Table ID\n"
8155 "Metric for redistributed routes\n"
8156 "OSPF default metric\n"
8157 "OSPF exterior metric type for redistributed routes\n"
8158 "Set OSPF External Type 1/2 metrics\n"
8159 "Route map reference\n"
8160 "Pointer to route-map entries\n")
8162 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8163 int idx_ospf_table
= 1;
8169 unsigned short instance
;
8170 struct ospf_redist
*red
;
8175 source
= proto_redistnum(AFI_IP
, argv
[idx_ospf_table
]->text
);
8177 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8182 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
8184 "Instance redistribution in non-instanced OSPF not allowed\n");
8185 return CMD_WARNING_CONFIG_FAILED
;
8188 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
8189 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
8190 return CMD_WARNING_CONFIG_FAILED
;
8193 /* Get metric value. */
8194 if (argv_find(argv
, argc
, "metric", &idx
))
8195 if (!str2metric(argv
[idx
+ 1]->arg
, &metric
))
8196 return CMD_WARNING_CONFIG_FAILED
;
8199 /* Get metric type. */
8200 if (argv_find(argv
, argc
, "metric-type", &idx
))
8201 if (!str2metric_type(argv
[idx
+ 1]->arg
, &type
))
8202 return CMD_WARNING_CONFIG_FAILED
;
8204 red
= ospf_redist_add(ospf
, source
, instance
);
8207 if (argv_find(argv
, argc
, "route-map", &idx
))
8208 ospf_routemap_set(red
, argv
[idx
+ 1]->arg
);
8210 ospf_routemap_unset(red
);
8212 return ospf_redistribute_set(ospf
, source
, instance
, type
, metric
);
8215 DEFUN (no_ospf_redistribute_instance_source
,
8216 no_ospf_redistribute_instance_source_cmd
,
8217 "no 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
= 2;
8233 unsigned int instance
;
8234 struct ospf_redist
*red
;
8237 if (strncmp(argv
[idx_ospf_table
]->arg
, "o", 1) == 0)
8238 source
= ZEBRA_ROUTE_OSPF
;
8240 source
= ZEBRA_ROUTE_TABLE
;
8242 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8244 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
8246 "Instance redistribution in non-instanced OSPF not allowed\n");
8247 return CMD_WARNING_CONFIG_FAILED
;
8250 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
8251 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
8252 return CMD_WARNING_CONFIG_FAILED
;
8255 red
= ospf_redist_lookup(ospf
, source
, instance
);
8259 ospf_routemap_unset(red
);
8260 return ospf_redistribute_unset(ospf
, source
, instance
);
8263 DEFUN (ospf_distribute_list_out
,
8264 ospf_distribute_list_out_cmd
,
8265 "distribute-list WORD out " FRR_REDIST_STR_OSPFD
,
8266 "Filter networks in routing updates\n"
8267 "Access-list name\n"
8269 FRR_REDIST_HELP_STR_OSPFD
)
8271 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8275 char *proto
= argv
[argc
- 1]->text
;
8277 /* Get distribute source. */
8278 source
= proto_redistnum(AFI_IP
, proto
);
8280 return CMD_WARNING_CONFIG_FAILED
;
8282 return ospf_distribute_list_out_set(ospf
, source
, argv
[idx_word
]->arg
);
8285 DEFUN (no_ospf_distribute_list_out
,
8286 no_ospf_distribute_list_out_cmd
,
8287 "no distribute-list WORD out " FRR_REDIST_STR_OSPFD
,
8289 "Filter networks in routing updates\n"
8290 "Access-list name\n"
8292 FRR_REDIST_HELP_STR_OSPFD
)
8294 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8298 char *proto
= argv
[argc
- 1]->text
;
8299 source
= proto_redistnum(AFI_IP
, proto
);
8301 return CMD_WARNING_CONFIG_FAILED
;
8303 return ospf_distribute_list_out_unset(ospf
, source
,
8304 argv
[idx_word
]->arg
);
8307 /* Default information originate. */
8308 DEFUN (ospf_default_information_originate
,
8309 ospf_default_information_originate_cmd
,
8310 "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8311 "Control distribution of default information\n"
8312 "Distribute a default route\n"
8313 "Always advertise default route\n"
8314 "OSPF default metric\n"
8316 "OSPF metric type for default routes\n"
8317 "Set OSPF External Type 1/2 metrics\n"
8318 "Route map reference\n"
8319 "Pointer to route-map entries\n")
8321 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8322 int default_originate
= DEFAULT_ORIGINATE_ZEBRA
;
8325 struct ospf_redist
*red
;
8328 red
= ospf_redist_add(ospf
, DEFAULT_ROUTE
, 0);
8330 /* Check whether "always" was specified */
8331 if (argv_find(argv
, argc
, "always", &idx
))
8332 default_originate
= DEFAULT_ORIGINATE_ALWAYS
;
8334 /* Get metric value */
8335 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
8336 if (!str2metric(argv
[idx
]->arg
, &metric
))
8337 return CMD_WARNING_CONFIG_FAILED
;
8340 /* Get metric type. */
8341 if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
8342 if (!str2metric_type(argv
[idx
]->arg
, &type
))
8343 return CMD_WARNING_CONFIG_FAILED
;
8347 if (argv_find(argv
, argc
, "WORD", &idx
))
8348 ospf_routemap_set(red
, argv
[idx
]->arg
);
8350 ospf_routemap_unset(red
);
8352 return ospf_redistribute_default_set(ospf
, default_originate
, type
,
8356 DEFUN (no_ospf_default_information_originate
,
8357 no_ospf_default_information_originate_cmd
,
8358 "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8360 "Control distribution of default information\n"
8361 "Distribute a default route\n"
8362 "Always advertise default route\n"
8363 "OSPF default metric\n"
8365 "OSPF metric type for default routes\n"
8366 "Set OSPF External Type 1/2 metrics\n"
8367 "Route map reference\n"
8368 "Pointer to route-map entries\n")
8370 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8371 struct prefix_ipv4 p
;
8372 struct ospf_external
*ext
;
8373 struct ospf_redist
*red
;
8376 p
.prefix
.s_addr
= 0;
8379 ospf_external_lsa_flush(ospf
, DEFAULT_ROUTE
, &p
, 0);
8381 ext
= ospf_external_lookup(ospf
, DEFAULT_ROUTE
, 0);
8382 if (ext
&& EXTERNAL_INFO(ext
)) {
8383 ospf_external_info_delete(ospf
, DEFAULT_ROUTE
, 0, p
);
8384 ospf_external_del(ospf
, DEFAULT_ROUTE
, 0);
8387 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
8391 ospf_routemap_unset(red
);
8392 return ospf_redistribute_default_unset(ospf
);
8395 DEFUN (ospf_default_metric
,
8396 ospf_default_metric_cmd
,
8397 "default-metric (0-16777214)",
8398 "Set metric of redistributed routes\n"
8401 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8405 if (!str2metric(argv
[idx_number
]->arg
, &metric
))
8406 return CMD_WARNING_CONFIG_FAILED
;
8408 ospf
->default_metric
= metric
;
8413 DEFUN (no_ospf_default_metric
,
8414 no_ospf_default_metric_cmd
,
8415 "no default-metric [(0-16777214)]",
8417 "Set metric of redistributed routes\n"
8420 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8422 ospf
->default_metric
= -1;
8428 DEFUN (ospf_distance
,
8431 "Administrative distance\n"
8432 "OSPF Administrative distance\n")
8434 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8437 ospf
->distance_all
= atoi(argv
[idx_number
]->arg
);
8442 DEFUN (no_ospf_distance
,
8443 no_ospf_distance_cmd
,
8444 "no distance (1-255)",
8446 "Administrative distance\n"
8447 "OSPF Administrative distance\n")
8449 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8451 ospf
->distance_all
= 0;
8456 DEFUN (no_ospf_distance_ospf
,
8457 no_ospf_distance_ospf_cmd
,
8458 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
8460 "Administrative distance\n"
8461 "OSPF administrative distance\n"
8462 "Intra-area routes\n"
8463 "Distance for intra-area routes\n"
8464 "Inter-area routes\n"
8465 "Distance for inter-area routes\n"
8467 "Distance for external routes\n")
8469 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8475 if (argv_find(argv
, argc
, "intra-area", &idx
) || argc
== 3)
8476 idx
= ospf
->distance_intra
= 0;
8477 if (argv_find(argv
, argc
, "inter-area", &idx
) || argc
== 3)
8478 idx
= ospf
->distance_inter
= 0;
8479 if (argv_find(argv
, argc
, "external", &idx
) || argc
== 3)
8480 ospf
->distance_external
= 0;
8485 DEFUN (ospf_distance_ospf
,
8486 ospf_distance_ospf_cmd
,
8487 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
8488 "Administrative distance\n"
8489 "OSPF administrative distance\n"
8490 "Intra-area routes\n"
8491 "Distance for intra-area routes\n"
8492 "Inter-area routes\n"
8493 "Distance for inter-area routes\n"
8495 "Distance for external routes\n")
8497 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8500 ospf
->distance_intra
= 0;
8501 ospf
->distance_inter
= 0;
8502 ospf
->distance_external
= 0;
8504 if (argv_find(argv
, argc
, "intra-area", &idx
))
8505 ospf
->distance_intra
= atoi(argv
[idx
+ 1]->arg
);
8507 if (argv_find(argv
, argc
, "inter-area", &idx
))
8508 ospf
->distance_inter
= atoi(argv
[idx
+ 1]->arg
);
8510 if (argv_find(argv
, argc
, "external", &idx
))
8511 ospf
->distance_external
= atoi(argv
[idx
+ 1]->arg
);
8517 DEFUN (ospf_distance_source
,
8518 ospf_distance_source_cmd
,
8519 "distance (1-255) A.B.C.D/M",
8520 "Administrative distance\n"
8522 "IP source prefix\n")
8524 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8526 int idx_ipv4_prefixlen
= 2;
8531 ospf_distance_set (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
8536 DEFUN (no_ospf_distance_source
,
8537 no_ospf_distance_source_cmd
,
8538 "no distance (1-255) A.B.C.D/M",
8540 "Administrative distance\n"
8542 "IP source prefix\n")
8544 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8546 int idx_ipv4_prefixlen
= 3;
8551 ospf_distance_unset (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
8556 DEFUN (ospf_distance_source_access_list
,
8557 ospf_distance_source_access_list_cmd
,
8558 "distance (1-255) A.B.C.D/M WORD",
8559 "Administrative distance\n"
8561 "IP source prefix\n"
8562 "Access list name\n")
8564 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8566 int idx_ipv4_prefixlen
= 2;
8572 ospf_distance_set (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
8577 DEFUN (no_ospf_distance_source_access_list
,
8578 no_ospf_distance_source_access_list_cmd
,
8579 "no distance (1-255) A.B.C.D/M WORD",
8581 "Administrative distance\n"
8583 "IP source prefix\n"
8584 "Access list name\n")
8586 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8588 int idx_ipv4_prefixlen
= 3;
8594 ospf_distance_unset (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
8600 DEFUN (ip_ospf_mtu_ignore
,
8601 ip_ospf_mtu_ignore_addr_cmd
,
8602 "ip ospf mtu-ignore [A.B.C.D]",
8604 "OSPF interface commands\n"
8605 "Disable MTU mismatch detection on this interface\n"
8606 "Address of interface\n")
8608 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8610 struct in_addr addr
;
8613 struct ospf_if_params
*params
;
8614 params
= IF_DEF_PARAMS(ifp
);
8617 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8620 "Please specify interface address by A.B.C.D\n");
8621 return CMD_WARNING_CONFIG_FAILED
;
8623 params
= ospf_get_if_params(ifp
, addr
);
8624 ospf_if_update_params(ifp
, addr
);
8626 params
->mtu_ignore
= 1;
8627 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
8628 SET_IF_PARAM(params
, mtu_ignore
);
8630 UNSET_IF_PARAM(params
, mtu_ignore
);
8631 if (params
!= IF_DEF_PARAMS(ifp
)) {
8632 ospf_free_if_params(ifp
, addr
);
8633 ospf_if_update_params(ifp
, addr
);
8639 DEFUN (no_ip_ospf_mtu_ignore
,
8640 no_ip_ospf_mtu_ignore_addr_cmd
,
8641 "no ip ospf mtu-ignore [A.B.C.D]",
8644 "OSPF interface commands\n"
8645 "Disable MTU mismatch detection on this interface\n"
8646 "Address of interface\n")
8648 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8650 struct in_addr addr
;
8653 struct ospf_if_params
*params
;
8654 params
= IF_DEF_PARAMS(ifp
);
8657 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8660 "Please specify interface address by A.B.C.D\n");
8661 return CMD_WARNING_CONFIG_FAILED
;
8663 params
= ospf_get_if_params(ifp
, addr
);
8664 ospf_if_update_params(ifp
, addr
);
8666 params
->mtu_ignore
= 0;
8667 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
8668 SET_IF_PARAM(params
, mtu_ignore
);
8670 UNSET_IF_PARAM(params
, mtu_ignore
);
8671 if (params
!= IF_DEF_PARAMS(ifp
)) {
8672 ospf_free_if_params(ifp
, addr
);
8673 ospf_if_update_params(ifp
, addr
);
8680 DEFUN (ospf_max_metric_router_lsa_admin
,
8681 ospf_max_metric_router_lsa_admin_cmd
,
8682 "max-metric router-lsa administrative",
8683 "OSPF maximum / infinite-distance metric\n"
8684 "Advertise own Router-LSA with infinite distance (stub router)\n"
8685 "Administratively applied, for an indefinite period\n")
8687 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8688 struct listnode
*ln
;
8689 struct ospf_area
*area
;
8691 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8692 SET_FLAG(area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
);
8694 if (!CHECK_FLAG(area
->stub_router_state
,
8695 OSPF_AREA_IS_STUB_ROUTED
))
8696 ospf_router_lsa_update_area(area
);
8699 /* Allows for areas configured later to get the property */
8700 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
;
8705 DEFUN (no_ospf_max_metric_router_lsa_admin
,
8706 no_ospf_max_metric_router_lsa_admin_cmd
,
8707 "no max-metric router-lsa administrative",
8709 "OSPF maximum / infinite-distance metric\n"
8710 "Advertise own Router-LSA with infinite distance (stub router)\n"
8711 "Administratively applied, for an indefinite period\n")
8713 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8714 struct listnode
*ln
;
8715 struct ospf_area
*area
;
8717 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8718 UNSET_FLAG(area
->stub_router_state
,
8719 OSPF_AREA_ADMIN_STUB_ROUTED
);
8721 /* Don't trample on the start-up stub timer */
8722 if (CHECK_FLAG(area
->stub_router_state
,
8723 OSPF_AREA_IS_STUB_ROUTED
)
8724 && !area
->t_stub_router
) {
8725 UNSET_FLAG(area
->stub_router_state
,
8726 OSPF_AREA_IS_STUB_ROUTED
);
8727 ospf_router_lsa_update_area(area
);
8730 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET
;
8734 DEFUN (ospf_max_metric_router_lsa_startup
,
8735 ospf_max_metric_router_lsa_startup_cmd
,
8736 "max-metric router-lsa on-startup (5-86400)",
8737 "OSPF maximum / infinite-distance metric\n"
8738 "Advertise own Router-LSA with infinite distance (stub router)\n"
8739 "Automatically advertise stub Router-LSA on startup of OSPF\n"
8740 "Time (seconds) to advertise self as stub-router\n")
8742 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8744 unsigned int seconds
;
8747 vty_out(vty
, "%% Must supply stub-router period");
8748 return CMD_WARNING_CONFIG_FAILED
;
8751 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8753 ospf
->stub_router_startup_time
= seconds
;
8758 DEFUN (no_ospf_max_metric_router_lsa_startup
,
8759 no_ospf_max_metric_router_lsa_startup_cmd
,
8760 "no max-metric router-lsa on-startup [(5-86400)]",
8762 "OSPF maximum / infinite-distance metric\n"
8763 "Advertise own Router-LSA with infinite distance (stub router)\n"
8764 "Automatically advertise stub Router-LSA on startup of OSPF\n"
8765 "Time (seconds) to advertise self as stub-router\n")
8767 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8768 struct listnode
*ln
;
8769 struct ospf_area
*area
;
8771 ospf
->stub_router_startup_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
8773 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8774 SET_FLAG(area
->stub_router_state
,
8775 OSPF_AREA_WAS_START_STUB_ROUTED
);
8776 OSPF_TIMER_OFF(area
->t_stub_router
);
8778 /* Don't trample on admin stub routed */
8779 if (!CHECK_FLAG(area
->stub_router_state
,
8780 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
8781 UNSET_FLAG(area
->stub_router_state
,
8782 OSPF_AREA_IS_STUB_ROUTED
);
8783 ospf_router_lsa_update_area(area
);
8790 DEFUN (ospf_max_metric_router_lsa_shutdown
,
8791 ospf_max_metric_router_lsa_shutdown_cmd
,
8792 "max-metric router-lsa on-shutdown (5-100)",
8793 "OSPF maximum / infinite-distance metric\n"
8794 "Advertise own Router-LSA with infinite distance (stub router)\n"
8795 "Advertise stub-router prior to full shutdown of OSPF\n"
8796 "Time (seconds) to wait till full shutdown\n")
8798 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8800 unsigned int seconds
;
8803 vty_out(vty
, "%% Must supply stub-router shutdown period");
8804 return CMD_WARNING_CONFIG_FAILED
;
8807 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8809 ospf
->stub_router_shutdown_time
= seconds
;
8814 DEFUN (no_ospf_max_metric_router_lsa_shutdown
,
8815 no_ospf_max_metric_router_lsa_shutdown_cmd
,
8816 "no max-metric router-lsa on-shutdown [(5-100)]",
8818 "OSPF maximum / infinite-distance metric\n"
8819 "Advertise own Router-LSA with infinite distance (stub router)\n"
8820 "Advertise stub-router prior to full shutdown of OSPF\n"
8821 "Time (seconds) to wait till full shutdown\n")
8823 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8825 ospf
->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
8830 static void config_write_stub_router(struct vty
*vty
, struct ospf
*ospf
)
8832 struct listnode
*ln
;
8833 struct ospf_area
*area
;
8835 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
8836 vty_out(vty
, " max-metric router-lsa on-startup %u\n",
8837 ospf
->stub_router_startup_time
);
8838 if (ospf
->stub_router_shutdown_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
8839 vty_out(vty
, " max-metric router-lsa on-shutdown %u\n",
8840 ospf
->stub_router_shutdown_time
);
8841 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8842 if (CHECK_FLAG(area
->stub_router_state
,
8843 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
8844 vty_out(vty
, " max-metric router-lsa administrative\n");
8851 static void show_ip_ospf_route_network(struct vty
*vty
, struct ospf
*ospf
,
8852 struct route_table
*rt
,
8855 struct route_node
*rn
;
8856 struct ospf_route
* or ;
8857 struct listnode
*pnode
, *pnnode
;
8858 struct ospf_path
*path
;
8859 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
8860 *json_nexthop
= NULL
;
8864 "============ OSPF network routing table ============\n");
8866 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
8867 if ((or = rn
->info
) == NULL
)
8869 char buf1
[PREFIX2STR_BUFFER
];
8871 memset(buf1
, 0, sizeof(buf1
));
8872 prefix2str(&rn
->p
, buf1
, sizeof(buf1
));
8874 json_route
= json_object_new_object();
8876 json_object_object_add(json
, buf1
, json_route
);
8877 json_object_to_json_string_ext(
8878 json
, JSON_C_TO_STRING_NOSLASHESCAPE
);
8881 switch (or->path_type
) {
8882 case OSPF_PATH_INTER_AREA
:
8883 if (or->type
== OSPF_DESTINATION_NETWORK
) {
8885 json_object_string_add(json_route
,
8888 json_object_int_add(json_route
, "cost",
8890 json_object_string_add(
8892 inet_ntoa(or->u
.std
.area_id
));
8895 "N IA %-18s [%d] area: %s\n",
8897 inet_ntoa(or->u
.std
.area_id
));
8899 } else if (or->type
== OSPF_DESTINATION_DISCARD
) {
8901 json_object_string_add(json_route
,
8906 "D IA %-18s Discard entry\n",
8911 case OSPF_PATH_INTRA_AREA
:
8913 json_object_string_add(json_route
, "routeType",
8915 json_object_int_add(json_route
, "cost",
8917 json_object_string_add(
8919 inet_ntoa(or->u
.std
.area_id
));
8921 vty_out(vty
, "N %-18s [%d] area: %s\n",
8923 inet_ntoa(or->u
.std
.area_id
));
8930 if (or->type
== OSPF_DESTINATION_NETWORK
) {
8932 json_nexthop_array
= json_object_new_array();
8933 json_object_object_add(json_route
, "nexthops",
8934 json_nexthop_array
);
8937 for (ALL_LIST_ELEMENTS(or->paths
, pnode
, pnnode
,
8940 json_nexthop
= json_object_new_object();
8941 json_object_array_add(
8945 if (if_lookup_by_index(path
->ifindex
,
8948 if (path
->nexthop
.s_addr
== 0) {
8950 json_object_string_add(
8953 json_object_string_add(
8955 "directly attached to",
8961 "%24s directly attached to %s\n",
8969 json_object_string_add(
8974 json_object_string_add(
8982 "%24s via %s, %s\n",
8995 json_object_free(json_route
);
9001 static void show_ip_ospf_route_router(struct vty
*vty
, struct ospf
*ospf
,
9002 struct route_table
*rtrs
,
9005 struct route_node
*rn
;
9006 struct ospf_route
* or ;
9007 struct listnode
*pnode
;
9008 struct listnode
*node
;
9009 struct ospf_path
*path
;
9010 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
9011 *json_nexthop
= NULL
;
9015 "============ OSPF router routing table =============\n");
9017 for (rn
= route_top(rtrs
); rn
; rn
= route_next(rn
)) {
9018 if (rn
->info
== NULL
)
9022 json_route
= json_object_new_object();
9024 json_object_object_add(json
, inet_ntoa(rn
->p
.u
.prefix4
),
9026 json_object_string_add(json_route
, "routeType", "R ");
9028 vty_out(vty
, "R %-15s ",
9029 inet_ntoa(rn
->p
.u
.prefix4
));
9032 for (ALL_LIST_ELEMENTS_RO((struct list
*)rn
->info
, node
, or)) {
9035 vty_out(vty
, "%24s", "");
9040 json_object_int_add(json_route
, "cost",
9042 json_object_string_add(
9044 inet_ntoa(or->u
.std
.area_id
));
9045 if (or->path_type
== OSPF_PATH_INTER_AREA
)
9046 json_object_boolean_true_add(json_route
,
9048 if (or->u
.std
.flags
& ROUTER_LSA_BORDER
)
9049 json_object_string_add(json_route
,
9052 else if (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
)
9053 json_object_string_add(json_route
,
9057 vty_out(vty
, "%s [%d] area: %s",
9058 (or->path_type
== OSPF_PATH_INTER_AREA
9061 or->cost
, inet_ntoa(or->u
.std
.area_id
));
9063 vty_out(vty
, "%s%s\n",
9064 (or->u
.std
.flags
& ROUTER_LSA_BORDER
9067 (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
9073 json_nexthop_array
= json_object_new_array();
9074 json_object_object_add(json_route
, "nexthops",
9075 json_nexthop_array
);
9078 for (ALL_LIST_ELEMENTS_RO(or->paths
, pnode
, path
)) {
9080 json_nexthop
= json_object_new_object();
9081 json_object_array_add(
9085 if (if_lookup_by_index(path
->ifindex
,
9087 if (path
->nexthop
.s_addr
== 0) {
9089 json_object_string_add(
9092 json_object_string_add(
9094 "directly attached to",
9100 "%24s directly attached to %s\n",
9108 json_object_string_add(
9113 json_object_string_add(
9121 "%24s via %s, %s\n",
9134 json_object_free(json_route
);
9140 static void show_ip_ospf_route_external(struct vty
*vty
, struct ospf
*ospf
,
9141 struct route_table
*rt
,
9144 struct route_node
*rn
;
9145 struct ospf_route
*er
;
9146 struct listnode
*pnode
, *pnnode
;
9147 struct ospf_path
*path
;
9148 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
9149 *json_nexthop
= NULL
;
9153 "============ OSPF external routing table ===========\n");
9155 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
9156 if ((er
= rn
->info
) == NULL
)
9161 snprintf(buf1
, 19, "%s/%d", inet_ntoa(rn
->p
.u
.prefix4
),
9163 json_route
= json_object_new_object();
9165 json_object_object_add(json
, buf1
, json_route
);
9166 json_object_to_json_string_ext(
9167 json
, JSON_C_TO_STRING_NOSLASHESCAPE
);
9170 switch (er
->path_type
) {
9171 case OSPF_PATH_TYPE1_EXTERNAL
:
9173 json_object_string_add(json_route
, "routeType",
9175 json_object_int_add(json_route
, "cost",
9179 "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI
9181 buf1
, er
->cost
, er
->u
.ext
.tag
);
9184 case OSPF_PATH_TYPE2_EXTERNAL
:
9186 json_object_string_add(json_route
, "routeType",
9188 json_object_int_add(json_route
, "cost",
9192 "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI
9194 buf1
, er
->cost
, er
->u
.ext
.type2_cost
,
9201 json_nexthop_array
= json_object_new_array();
9202 json_object_object_add(json_route
, "nexthops",
9203 json_nexthop_array
);
9206 for (ALL_LIST_ELEMENTS(er
->paths
, pnode
, pnnode
, path
)) {
9208 json_nexthop
= json_object_new_object();
9209 json_object_array_add(json_nexthop_array
,
9213 if (if_lookup_by_index(path
->ifindex
, ospf
->vrf_id
)) {
9214 if (path
->nexthop
.s_addr
== 0) {
9216 json_object_string_add(
9219 json_object_string_add(
9221 "directly attached to",
9227 "%24s directly attached to %s\n",
9235 json_object_string_add(
9239 json_object_string_add(
9240 json_nexthop
, "via",
9246 "%24s via %s, %s\n",
9258 json_object_free(json_route
);
9264 static int show_ip_ospf_border_routers_common(struct vty
*vty
,
9269 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
9271 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
9273 if (ospf
->new_table
== NULL
) {
9274 vty_out(vty
, "No OSPF routing information exist\n");
9278 /* Show Network routes.
9279 show_ip_ospf_route_network (vty, ospf->new_table); */
9281 /* Show Router routes. */
9282 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, NULL
);
9289 DEFUN (show_ip_ospf_border_routers
,
9290 show_ip_ospf_border_routers_cmd
,
9291 "show ip ospf [vrf <NAME|all>] border-routers",
9294 "OSPF information\n"
9297 "Show all the ABR's and ASBR's\n")
9299 struct ospf
*ospf
= NULL
;
9300 struct listnode
*node
= NULL
;
9301 char *vrf_name
= NULL
;
9302 bool all_vrf
= FALSE
;
9303 int ret
= CMD_SUCCESS
;
9306 uint8_t use_vrf
= 0;
9308 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
9313 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9314 if (!ospf
->oi_running
)
9317 ret
= show_ip_ospf_border_routers_common(
9318 vty
, ospf
, use_vrf
);
9321 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
9322 if (ospf
== NULL
|| !ospf
->oi_running
)
9325 ret
= show_ip_ospf_border_routers_common(vty
, ospf
,
9329 /* Display default ospf (instance 0) info */
9330 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
9331 if (ospf
== NULL
|| !ospf
->oi_running
)
9333 ret
= show_ip_ospf_border_routers_common(vty
, ospf
, use_vrf
);
9339 DEFUN (show_ip_ospf_instance_border_routers
,
9340 show_ip_ospf_instance_border_routers_cmd
,
9341 "show ip ospf (1-65535) border-routers",
9344 "OSPF information\n"
9346 "Show all the ABR's and ASBR's\n")
9350 unsigned short instance
= 0;
9352 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9353 ospf
= ospf_lookup_instance(instance
);
9355 return CMD_NOT_MY_INSTANCE
;
9357 if (!ospf
->oi_running
)
9360 return show_ip_ospf_border_routers_common(vty
, ospf
, 0);
9363 static int show_ip_ospf_route_common(struct vty
*vty
, struct ospf
*ospf
,
9364 json_object
*json
, uint8_t use_vrf
)
9366 json_object
*json_vrf
= NULL
;
9369 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
9374 json_vrf
= json_object_new_object();
9379 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
9381 if (ospf
->new_table
== NULL
) {
9382 vty_out(vty
, "No OSPF routing information exist\n");
9386 /* Show Network routes. */
9387 show_ip_ospf_route_network(vty
, ospf
, ospf
->new_table
, json_vrf
);
9389 /* Show Router routes. */
9390 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, json_vrf
);
9392 /* Show AS External routes. */
9393 show_ip_ospf_route_external(vty
, ospf
, ospf
->old_external_route
,
9398 // json_object_object_add(json_vrf, "areas",
9400 if (ospf
->vrf_id
== VRF_DEFAULT
)
9401 json_object_object_add(json
, "default",
9404 json_object_object_add(json
, ospf
->name
,
9414 DEFUN (show_ip_ospf_route
,
9415 show_ip_ospf_route_cmd
,
9416 "show ip ospf [vrf <NAME|all>] route [json]",
9419 "OSPF information\n"
9422 "OSPF routing table\n"
9425 struct ospf
*ospf
= NULL
;
9426 struct listnode
*node
= NULL
;
9427 char *vrf_name
= NULL
;
9428 bool all_vrf
= FALSE
;
9429 int ret
= CMD_SUCCESS
;
9432 uint8_t use_vrf
= 0;
9433 uint8_t uj
= use_json(argc
, argv
);
9434 json_object
*json
= NULL
;
9437 json
= json_object_new_object();
9439 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
9441 /* vrf input is provided could be all or specific vrf*/
9445 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9446 if (!ospf
->oi_running
)
9448 ret
= show_ip_ospf_route_common(vty
, ospf
, json
,
9453 /* Keep Non-pretty format */
9454 vty_out(vty
, "%s\n",
9455 json_object_to_json_string(json
));
9456 json_object_free(json
);
9461 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
9462 if (ospf
== NULL
|| !ospf
->oi_running
) {
9464 json_object_free(json
);
9468 /* Display default ospf (instance 0) info */
9469 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
9470 if (ospf
== NULL
|| !ospf
->oi_running
) {
9472 json_object_free(json
);
9478 ret
= show_ip_ospf_route_common(vty
, ospf
, json
, use_vrf
);
9479 /* Keep Non-pretty format */
9481 vty_out(vty
, "%s\n", json_object_to_json_string(json
));
9485 json_object_free(json
);
9490 DEFUN (show_ip_ospf_instance_route
,
9491 show_ip_ospf_instance_route_cmd
,
9492 "show ip ospf (1-65535) route",
9495 "OSPF information\n"
9497 "OSPF routing table\n")
9501 unsigned short instance
= 0;
9503 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9504 ospf
= ospf_lookup_instance(instance
);
9506 return CMD_NOT_MY_INSTANCE
;
9508 if (!ospf
->oi_running
)
9511 return show_ip_ospf_route_common(vty
, ospf
, NULL
, 0);
9515 DEFUN (show_ip_ospf_vrfs
,
9516 show_ip_ospf_vrfs_cmd
,
9517 "show ip ospf vrfs [json]",
9520 "OSPF information\n"
9524 uint8_t uj
= use_json(argc
, argv
);
9525 json_object
*json
= NULL
;
9526 json_object
*json_vrfs
= NULL
;
9527 struct ospf
*ospf
= NULL
;
9528 struct listnode
*node
= NULL
;
9530 static char header
[] = "Name Id RouterId ";
9533 json
= json_object_new_object();
9534 json_vrfs
= json_object_new_object();
9537 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9538 json_object
*json_vrf
= NULL
;
9539 const char *name
= NULL
;
9540 int64_t vrf_id_ui
= 0;
9544 if (!uj
&& count
== 1)
9545 vty_out(vty
, "%s\n", header
);
9547 json_vrf
= json_object_new_object();
9549 if (ospf
->vrf_id
== 0)
9550 name
= VRF_DEFAULT_NAME
;
9554 vrf_id_ui
= (ospf
->vrf_id
== VRF_UNKNOWN
)
9556 : (int64_t)ospf
->vrf_id
;
9559 json_object_int_add(json_vrf
, "vrfId", vrf_id_ui
);
9560 json_object_string_add(json_vrf
, "routerId",
9561 inet_ntoa(ospf
->router_id
));
9563 json_object_object_add(json_vrfs
, name
, json_vrf
);
9566 vty_out(vty
, "%-25s %-5d %-16s \n", name
,
9567 ospf
->vrf_id
, inet_ntoa(ospf
->router_id
));
9572 json_object_object_add(json
, "vrfs", json_vrfs
);
9573 json_object_int_add(json
, "totalVrfs", count
);
9575 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
9576 json
, JSON_C_TO_STRING_PRETTY
));
9577 json_object_free(json
);
9580 vty_out(vty
, "\nTotal number of OSPF VRFs: %d\n",
9587 const char *ospf_abr_type_str
[] = {"unknown", "standard", "ibm", "cisco",
9590 const char *ospf_shortcut_mode_str
[] = {"default", "enable", "disable"};
9592 const char *ospf_int_type_str
[] = {"unknown", /* should never be used. */
9593 "point-to-point", "broadcast",
9594 "non-broadcast", "point-to-multipoint",
9595 "virtual-link", /* should never be used. */
9598 static int config_write_interface_one(struct vty
*vty
, struct vrf
*vrf
)
9600 struct listnode
*node
;
9601 struct interface
*ifp
;
9602 struct crypt_key
*ck
;
9603 struct route_node
*rn
= NULL
;
9604 struct ospf_if_params
*params
;
9606 struct ospf
*ospf
= vrf
->info
;
9608 FOR_ALL_INTERFACES (vrf
, ifp
) {
9610 if (memcmp(ifp
->name
, "VLINK", 5) == 0)
9613 vty_frame(vty
, "!\n");
9614 if (ifp
->vrf_id
== VRF_DEFAULT
)
9615 vty_frame(vty
, "interface %s\n", ifp
->name
);
9617 vty_frame(vty
, "interface %s vrf %s\n", ifp
->name
,
9620 vty_out(vty
, " description %s\n", ifp
->desc
);
9624 params
= IF_DEF_PARAMS(ifp
);
9627 /* Interface Network print. */
9628 if (OSPF_IF_PARAM_CONFIGURED(params
, type
)
9629 && params
->type
!= OSPF_IFTYPE_LOOPBACK
) {
9630 if (params
->type
!= ospf_default_iftype(ifp
)) {
9631 vty_out(vty
, " ip ospf network %s",
9634 if (params
!= IF_DEF_PARAMS(ifp
))
9642 /* OSPF interface authentication print */
9643 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_type
)
9644 && params
->auth_type
!= OSPF_AUTH_NOTSET
) {
9645 const char *auth_str
;
9647 /* Translation tables are not that much help
9648 * here due to syntax
9649 * of the simple option */
9650 switch (params
->auth_type
) {
9652 case OSPF_AUTH_NULL
:
9656 case OSPF_AUTH_SIMPLE
:
9660 case OSPF_AUTH_CRYPTOGRAPHIC
:
9661 auth_str
= " message-digest";
9669 vty_out(vty
, " ip ospf authentication%s",
9671 if (params
!= IF_DEF_PARAMS(ifp
))
9673 inet_ntoa(rn
->p
.u
.prefix4
));
9677 /* Simple Authentication Password print. */
9678 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_simple
)
9679 && params
->auth_simple
[0] != '\0') {
9680 vty_out(vty
, " ip ospf authentication-key %s",
9681 params
->auth_simple
);
9682 if (params
!= IF_DEF_PARAMS(ifp
))
9684 inet_ntoa(rn
->p
.u
.prefix4
));
9688 /* Cryptographic Authentication Key print. */
9689 if (params
&& params
->auth_crypt
) {
9690 for (ALL_LIST_ELEMENTS_RO(params
->auth_crypt
,
9693 " ip ospf message-digest-key %d md5 %s",
9694 ck
->key_id
, ck
->auth_key
);
9695 if (params
!= IF_DEF_PARAMS(ifp
))
9703 /* Interface Output Cost print. */
9704 if (OSPF_IF_PARAM_CONFIGURED(params
, output_cost_cmd
)) {
9705 vty_out(vty
, " ip ospf cost %u",
9706 params
->output_cost_cmd
);
9707 if (params
!= IF_DEF_PARAMS(ifp
))
9709 inet_ntoa(rn
->p
.u
.prefix4
));
9713 /* Hello Interval print. */
9714 if (OSPF_IF_PARAM_CONFIGURED(params
, v_hello
)
9715 && params
->v_hello
!= OSPF_HELLO_INTERVAL_DEFAULT
) {
9716 vty_out(vty
, " ip ospf hello-interval %u",
9718 if (params
!= IF_DEF_PARAMS(ifp
))
9720 inet_ntoa(rn
->p
.u
.prefix4
));
9725 /* Router Dead Interval print. */
9726 if (OSPF_IF_PARAM_CONFIGURED(params
, v_wait
)
9728 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
) {
9729 vty_out(vty
, " ip ospf dead-interval ");
9732 if (OSPF_IF_PARAM_CONFIGURED(params
,
9735 "minimal hello-multiplier %d",
9736 params
->fast_hello
);
9738 vty_out(vty
, "%u", params
->v_wait
);
9740 if (params
!= IF_DEF_PARAMS(ifp
))
9742 inet_ntoa(rn
->p
.u
.prefix4
));
9746 /* Router Priority print. */
9747 if (OSPF_IF_PARAM_CONFIGURED(params
, priority
)
9749 != OSPF_ROUTER_PRIORITY_DEFAULT
) {
9750 vty_out(vty
, " ip ospf priority %u",
9752 if (params
!= IF_DEF_PARAMS(ifp
))
9754 inet_ntoa(rn
->p
.u
.prefix4
));
9758 /* Retransmit Interval print. */
9759 if (OSPF_IF_PARAM_CONFIGURED(params
,
9760 retransmit_interval
)
9761 && params
->retransmit_interval
9762 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
) {
9763 vty_out(vty
, " ip ospf retransmit-interval %u",
9764 params
->retransmit_interval
);
9765 if (params
!= IF_DEF_PARAMS(ifp
))
9767 inet_ntoa(rn
->p
.u
.prefix4
));
9771 /* Transmit Delay print. */
9772 if (OSPF_IF_PARAM_CONFIGURED(params
, transmit_delay
)
9773 && params
->transmit_delay
9774 != OSPF_TRANSMIT_DELAY_DEFAULT
) {
9775 vty_out(vty
, " ip ospf transmit-delay %u",
9776 params
->transmit_delay
);
9777 if (params
!= IF_DEF_PARAMS(ifp
))
9779 inet_ntoa(rn
->p
.u
.prefix4
));
9784 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
9785 if (ospf
&& ospf
->instance
)
9786 vty_out(vty
, " ip ospf %d",
9789 vty_out(vty
, " ip ospf");
9792 size_t buflen
= MAX(strlen("4294967295"),
9793 strlen("255.255.255.255"));
9796 area_id2str(buf
, sizeof(buf
), ¶ms
->if_area
,
9797 params
->if_area_id_fmt
);
9798 vty_out(vty
, " area %s", buf
);
9799 if (params
!= IF_DEF_PARAMS(ifp
))
9801 inet_ntoa(rn
->p
.u
.prefix4
));
9806 if (params
->bfd_info
)
9807 ospf_bfd_write_config(vty
, params
);
9809 /* MTU ignore print. */
9810 if (OSPF_IF_PARAM_CONFIGURED(params
, mtu_ignore
)
9811 && params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
) {
9812 if (params
->mtu_ignore
== 0)
9813 vty_out(vty
, " no ip ospf mtu-ignore");
9815 vty_out(vty
, " ip ospf mtu-ignore");
9816 if (params
!= IF_DEF_PARAMS(ifp
))
9818 inet_ntoa(rn
->p
.u
.prefix4
));
9825 rn
= route_top(IF_OIFS_PARAMS(ifp
));
9827 rn
= route_next(rn
);
9837 ospf_opaque_config_write_if(vty
, ifp
);
9839 vty_endframe(vty
, NULL
);
9845 /* Configuration write function for ospfd. */
9846 static int config_write_interface(struct vty
*vty
)
9849 struct vrf
*vrf
= NULL
;
9851 /* Display all VRF aware OSPF interface configuration */
9852 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
9853 write
+= config_write_interface_one(vty
, vrf
);
9859 static int config_write_network_area(struct vty
*vty
, struct ospf
*ospf
)
9861 struct route_node
*rn
;
9862 uint8_t buf
[INET_ADDRSTRLEN
];
9864 /* `network area' print. */
9865 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
))
9867 struct ospf_network
*n
= rn
->info
;
9869 memset(buf
, 0, INET_ADDRSTRLEN
);
9871 /* Create Area ID string by specified Area ID format. */
9872 if (n
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
9873 strncpy((char *)buf
, inet_ntoa(n
->area_id
),
9876 sprintf((char *)buf
, "%lu",
9877 (unsigned long int)ntohl(
9878 n
->area_id
.s_addr
));
9880 /* Network print. */
9881 vty_out(vty
, " network %s/%d area %s\n",
9882 inet_ntoa(rn
->p
.u
.prefix4
), rn
->p
.prefixlen
,
9889 static int config_write_ospf_area(struct vty
*vty
, struct ospf
*ospf
)
9891 struct listnode
*node
;
9892 struct ospf_area
*area
;
9893 uint8_t buf
[INET_ADDRSTRLEN
];
9895 /* Area configuration print. */
9896 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
9897 struct route_node
*rn1
;
9899 area_id2str((char *)buf
, INET_ADDRSTRLEN
, &area
->area_id
,
9902 if (area
->auth_type
!= OSPF_AUTH_NULL
) {
9903 if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
9904 vty_out(vty
, " area %s authentication\n", buf
);
9907 " area %s authentication message-digest\n",
9911 if (area
->shortcut_configured
!= OSPF_SHORTCUT_DEFAULT
)
9912 vty_out(vty
, " area %s shortcut %s\n", buf
,
9913 ospf_shortcut_mode_str
9914 [area
->shortcut_configured
]);
9916 if ((area
->external_routing
== OSPF_AREA_STUB
)
9917 || (area
->external_routing
== OSPF_AREA_NSSA
)) {
9918 if (area
->external_routing
== OSPF_AREA_STUB
) {
9919 vty_out(vty
, " area %s stub", buf
);
9920 if (area
->no_summary
)
9921 vty_out(vty
, " no-summary\n");
9923 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
9924 switch (area
->NSSATranslatorRole
) {
9925 case OSPF_NSSA_ROLE_NEVER
:
9927 " area %s nssa translate-never\n",
9930 case OSPF_NSSA_ROLE_ALWAYS
:
9932 " area %s nssa translate-always\n",
9935 case OSPF_NSSA_ROLE_CANDIDATE
:
9936 vty_out(vty
, " area %s nssa \n", buf
);
9939 if (area
->no_summary
)
9941 " area %s nssa no-summary\n",
9945 if (area
->default_cost
!= 1)
9946 vty_out(vty
, " area %s default-cost %d\n", buf
,
9947 area
->default_cost
);
9950 for (rn1
= route_top(area
->ranges
); rn1
; rn1
= route_next(rn1
))
9952 struct ospf_area_range
*range
= rn1
->info
;
9954 vty_out(vty
, " area %s range %s/%d", buf
,
9955 inet_ntoa(rn1
->p
.u
.prefix4
),
9958 if (range
->cost_config
9959 != OSPF_AREA_RANGE_COST_UNSPEC
)
9960 vty_out(vty
, " cost %d",
9961 range
->cost_config
);
9963 if (!CHECK_FLAG(range
->flags
,
9964 OSPF_AREA_RANGE_ADVERTISE
))
9965 vty_out(vty
, " not-advertise");
9967 if (CHECK_FLAG(range
->flags
,
9968 OSPF_AREA_RANGE_SUBSTITUTE
))
9969 vty_out(vty
, " substitute %s/%d",
9970 inet_ntoa(range
->subst_addr
),
9971 range
->subst_masklen
);
9976 if (EXPORT_NAME(area
))
9977 vty_out(vty
, " area %s export-list %s\n", buf
,
9980 if (IMPORT_NAME(area
))
9981 vty_out(vty
, " area %s import-list %s\n", buf
,
9984 if (PREFIX_NAME_IN(area
))
9985 vty_out(vty
, " area %s filter-list prefix %s in\n", buf
,
9986 PREFIX_NAME_IN(area
));
9988 if (PREFIX_NAME_OUT(area
))
9989 vty_out(vty
, " area %s filter-list prefix %s out\n",
9990 buf
, PREFIX_NAME_OUT(area
));
9996 static int config_write_ospf_nbr_nbma(struct vty
*vty
, struct ospf
*ospf
)
9998 struct ospf_nbr_nbma
*nbr_nbma
;
9999 struct route_node
*rn
;
10001 /* Static Neighbor configuration print. */
10002 for (rn
= route_top(ospf
->nbr_nbma
); rn
; rn
= route_next(rn
))
10003 if ((nbr_nbma
= rn
->info
)) {
10004 vty_out(vty
, " neighbor %s", inet_ntoa(nbr_nbma
->addr
));
10006 if (nbr_nbma
->priority
10007 != OSPF_NEIGHBOR_PRIORITY_DEFAULT
)
10008 vty_out(vty
, " priority %d",
10009 nbr_nbma
->priority
);
10011 if (nbr_nbma
->v_poll
!= OSPF_POLL_INTERVAL_DEFAULT
)
10012 vty_out(vty
, " poll-interval %d",
10015 vty_out(vty
, "\n");
10021 static int config_write_virtual_link(struct vty
*vty
, struct ospf
*ospf
)
10023 struct listnode
*node
;
10024 struct ospf_vl_data
*vl_data
;
10025 char buf
[INET_ADDRSTRLEN
];
10027 /* Virtual-Link print */
10028 for (ALL_LIST_ELEMENTS_RO(ospf
->vlinks
, node
, vl_data
)) {
10029 struct listnode
*n2
;
10030 struct crypt_key
*ck
;
10031 struct ospf_interface
*oi
;
10033 if (vl_data
!= NULL
) {
10034 memset(buf
, 0, INET_ADDRSTRLEN
);
10036 area_id2str(buf
, sizeof(buf
), &vl_data
->vl_area_id
,
10037 vl_data
->vl_area_id_fmt
);
10038 oi
= vl_data
->vl_oi
;
10041 if (OSPF_IF_PARAM(oi
, v_hello
)
10042 != OSPF_HELLO_INTERVAL_DEFAULT
10043 || OSPF_IF_PARAM(oi
, v_wait
)
10044 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
10045 || OSPF_IF_PARAM(oi
, retransmit_interval
)
10046 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
10047 || OSPF_IF_PARAM(oi
, transmit_delay
)
10048 != OSPF_TRANSMIT_DELAY_DEFAULT
)
10050 " area %s virtual-link %s hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n",
10051 buf
, inet_ntoa(vl_data
->vl_peer
),
10052 OSPF_IF_PARAM(oi
, v_hello
),
10053 OSPF_IF_PARAM(oi
, retransmit_interval
),
10054 OSPF_IF_PARAM(oi
, transmit_delay
),
10055 OSPF_IF_PARAM(oi
, v_wait
));
10057 vty_out(vty
, " area %s virtual-link %s\n", buf
,
10058 inet_ntoa(vl_data
->vl_peer
));
10060 if (IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)->auth_simple
[0]
10063 " area %s virtual-link %s authentication-key %s\n",
10064 buf
, inet_ntoa(vl_data
->vl_peer
),
10065 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
10068 for (ALL_LIST_ELEMENTS_RO(
10069 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
10073 " area %s virtual-link %s"
10074 " message-digest-key %d md5 %s\n",
10075 buf
, inet_ntoa(vl_data
->vl_peer
),
10076 ck
->key_id
, ck
->auth_key
);
10084 static int config_write_ospf_redistribute(struct vty
*vty
, struct ospf
*ospf
)
10088 /* redistribute print. */
10089 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
10090 struct list
*red_list
;
10091 struct listnode
*node
;
10092 struct ospf_redist
*red
;
10094 red_list
= ospf
->redist
[type
];
10098 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
10099 vty_out(vty
, " redistribute %s",
10100 zebra_route_string(type
));
10102 vty_out(vty
, " %d", red
->instance
);
10104 if (red
->dmetric
.value
>= 0)
10105 vty_out(vty
, " metric %d", red
->dmetric
.value
);
10107 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
10108 vty_out(vty
, " metric-type 1");
10110 if (ROUTEMAP_NAME(red
))
10111 vty_out(vty
, " route-map %s",
10112 ROUTEMAP_NAME(red
));
10114 vty_out(vty
, "\n");
10121 static int config_write_ospf_default_metric(struct vty
*vty
, struct ospf
*ospf
)
10123 if (ospf
->default_metric
!= -1)
10124 vty_out(vty
, " default-metric %d\n", ospf
->default_metric
);
10128 static int config_write_ospf_distribute(struct vty
*vty
, struct ospf
*ospf
)
10131 struct ospf_redist
*red
;
10134 /* distribute-list print. */
10135 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
10136 if (DISTRIBUTE_NAME(ospf
, type
))
10137 vty_out(vty
, " distribute-list %s out %s\n",
10138 DISTRIBUTE_NAME(ospf
, type
),
10139 zebra_route_string(type
));
10141 /* default-information print. */
10142 if (ospf
->default_originate
!= DEFAULT_ORIGINATE_NONE
) {
10143 vty_out(vty
, " default-information originate");
10144 if (ospf
->default_originate
== DEFAULT_ORIGINATE_ALWAYS
)
10145 vty_out(vty
, " always");
10147 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
10149 if (red
->dmetric
.value
>= 0)
10150 vty_out(vty
, " metric %d",
10151 red
->dmetric
.value
);
10153 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
10154 vty_out(vty
, " metric-type 1");
10156 if (ROUTEMAP_NAME(red
))
10157 vty_out(vty
, " route-map %s",
10158 ROUTEMAP_NAME(red
));
10161 vty_out(vty
, "\n");
10168 static int config_write_ospf_distance(struct vty
*vty
, struct ospf
*ospf
)
10170 struct route_node
*rn
;
10171 struct ospf_distance
*odistance
;
10173 if (ospf
->distance_all
)
10174 vty_out(vty
, " distance %d\n", ospf
->distance_all
);
10176 if (ospf
->distance_intra
|| ospf
->distance_inter
10177 || ospf
->distance_external
) {
10178 vty_out(vty
, " distance ospf");
10180 if (ospf
->distance_intra
)
10181 vty_out(vty
, " intra-area %d", ospf
->distance_intra
);
10182 if (ospf
->distance_inter
)
10183 vty_out(vty
, " inter-area %d", ospf
->distance_inter
);
10184 if (ospf
->distance_external
)
10185 vty_out(vty
, " external %d", ospf
->distance_external
);
10187 vty_out(vty
, "\n");
10190 for (rn
= route_top(ospf
->distance_table
); rn
; rn
= route_next(rn
))
10191 if ((odistance
= rn
->info
) != NULL
) {
10192 vty_out(vty
, " distance %d %s/%d %s\n",
10193 odistance
->distance
, inet_ntoa(rn
->p
.u
.prefix4
),
10195 odistance
->access_list
? odistance
->access_list
10201 static int ospf_config_write_one(struct vty
*vty
, struct ospf
*ospf
)
10203 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
10204 struct interface
*ifp
;
10205 struct ospf_interface
*oi
;
10206 struct listnode
*node
= NULL
;
10209 /* `router ospf' print. */
10210 if (ospf
->instance
&& ospf
->name
) {
10211 vty_out(vty
, "router ospf %d vrf %s\n", ospf
->instance
,
10213 } else if (ospf
->instance
) {
10214 vty_out(vty
, "router ospf %d\n", ospf
->instance
);
10215 } else if (ospf
->name
) {
10216 vty_out(vty
, "router ospf vrf %s\n", ospf
->name
);
10218 vty_out(vty
, "router ospf\n");
10220 if (!ospf
->networks
) {
10225 /* Router ID print. */
10226 if (ospf
->router_id_static
.s_addr
!= 0)
10227 vty_out(vty
, " ospf router-id %s\n",
10228 inet_ntoa(ospf
->router_id_static
));
10230 /* ABR type print. */
10231 if (ospf
->abr_type
!= OSPF_ABR_DEFAULT
)
10232 vty_out(vty
, " ospf abr-type %s\n",
10233 ospf_abr_type_str
[ospf
->abr_type
]);
10235 /* log-adjacency-changes flag print. */
10236 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
10237 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
))
10238 vty_out(vty
, " log-adjacency-changes detail\n");
10239 else if (!DFLT_OSPF_LOG_ADJACENCY_CHANGES
)
10240 vty_out(vty
, " log-adjacency-changes\n");
10241 } else if (DFLT_OSPF_LOG_ADJACENCY_CHANGES
) {
10242 vty_out(vty
, " no log-adjacency-changes\n");
10245 /* RFC1583 compatibility flag print -- Compatible with CISCO
10247 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
))
10248 vty_out(vty
, " compatible rfc1583\n");
10250 /* auto-cost reference-bandwidth configuration. */
10251 if (ospf
->ref_bandwidth
!= OSPF_DEFAULT_REF_BANDWIDTH
) {
10253 "! Important: ensure reference bandwidth "
10254 "is consistent across all routers\n");
10255 vty_out(vty
, " auto-cost reference-bandwidth %d\n",
10256 ospf
->ref_bandwidth
);
10259 /* SPF timers print. */
10260 if (ospf
->spf_delay
!= OSPF_SPF_DELAY_DEFAULT
10261 || ospf
->spf_holdtime
!= OSPF_SPF_HOLDTIME_DEFAULT
10262 || ospf
->spf_max_holdtime
!= OSPF_SPF_MAX_HOLDTIME_DEFAULT
)
10263 vty_out(vty
, " timers throttle spf %d %d %d\n", ospf
->spf_delay
,
10264 ospf
->spf_holdtime
, ospf
->spf_max_holdtime
);
10266 /* LSA timers print. */
10267 if (ospf
->min_ls_interval
!= OSPF_MIN_LS_INTERVAL
)
10268 vty_out(vty
, " timers throttle lsa all %d\n",
10269 ospf
->min_ls_interval
);
10270 if (ospf
->min_ls_arrival
!= OSPF_MIN_LS_ARRIVAL
)
10271 vty_out(vty
, " timers lsa min-arrival %d\n",
10272 ospf
->min_ls_arrival
);
10274 /* Write multiplier print. */
10275 if (ospf
->write_oi_count
!= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
)
10276 vty_out(vty
, " ospf write-multiplier %d\n",
10277 ospf
->write_oi_count
);
10279 /* Max-metric router-lsa print */
10280 config_write_stub_router(vty
, ospf
);
10282 /* SPF refresh parameters print. */
10283 if (ospf
->lsa_refresh_interval
!= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
10284 vty_out(vty
, " refresh timer %d\n", ospf
->lsa_refresh_interval
);
10286 /* Redistribute information print. */
10287 config_write_ospf_redistribute(vty
, ospf
);
10289 /* passive-interface print. */
10290 if (ospf
->passive_interface_default
== OSPF_IF_PASSIVE
)
10291 vty_out(vty
, " passive-interface default\n");
10293 FOR_ALL_INTERFACES (vrf
, ifp
)
10294 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp
),
10296 && IF_DEF_PARAMS(ifp
)->passive_interface
10297 != ospf
->passive_interface_default
) {
10298 vty_out(vty
, " %spassive-interface %s\n",
10299 IF_DEF_PARAMS(ifp
)->passive_interface
? ""
10303 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
10304 if (!OSPF_IF_PARAM_CONFIGURED(oi
->params
, passive_interface
))
10306 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(oi
->ifp
),
10307 passive_interface
)) {
10308 if (oi
->params
->passive_interface
10309 == IF_DEF_PARAMS(oi
->ifp
)->passive_interface
)
10311 } else if (oi
->params
->passive_interface
10312 == ospf
->passive_interface_default
)
10315 vty_out(vty
, " %spassive-interface %s %s\n",
10316 oi
->params
->passive_interface
? "" : "no ",
10317 oi
->ifp
->name
, inet_ntoa(oi
->address
->u
.prefix4
));
10320 /* Network area print. */
10321 config_write_network_area(vty
, ospf
);
10323 /* Area config print. */
10324 config_write_ospf_area(vty
, ospf
);
10326 /* static neighbor print. */
10327 config_write_ospf_nbr_nbma(vty
, ospf
);
10329 /* Virtual-Link print. */
10330 config_write_virtual_link(vty
, ospf
);
10332 /* Default metric configuration. */
10333 config_write_ospf_default_metric(vty
, ospf
);
10335 /* Distribute-list and default-information print. */
10336 config_write_ospf_distribute(vty
, ospf
);
10338 /* Distance configuration. */
10339 config_write_ospf_distance(vty
, ospf
);
10341 ospf_opaque_config_write_router(vty
, ospf
);
10347 /* OSPF configuration write function. */
10348 static int ospf_config_write(struct vty
*vty
)
10351 struct listnode
*ospf_node
= NULL
;
10354 if (listcount(om
->ospf
) == 0)
10357 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, ospf_node
, ospf
)) {
10358 /* VRF Default check if it is running.
10359 * Upon daemon start, there could be default instance
10360 * in absence of 'router ospf'/oi_running is disabled. */
10361 if (ospf
->vrf_id
== VRF_DEFAULT
&& ospf
->oi_running
)
10362 write
+= ospf_config_write_one(vty
, ospf
);
10363 /* For Non-Default VRF simply display the configuration,
10364 * even if it is not oi_running. */
10365 else if (ospf
->vrf_id
!= VRF_DEFAULT
)
10366 write
+= ospf_config_write_one(vty
, ospf
);
10371 void ospf_vty_show_init(void)
10373 /* "show ip ospf" commands. */
10374 install_element(VIEW_NODE
, &show_ip_ospf_cmd
);
10376 install_element(VIEW_NODE
, &show_ip_ospf_instance_cmd
);
10378 /* "show ip ospf database" commands. */
10379 install_element(VIEW_NODE
, &show_ip_ospf_database_max_cmd
);
10381 install_element(VIEW_NODE
,
10382 &show_ip_ospf_instance_database_type_adv_router_cmd
);
10383 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_cmd
);
10384 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_max_cmd
);
10386 /* "show ip ospf interface" commands. */
10387 install_element(VIEW_NODE
, &show_ip_ospf_interface_cmd
);
10389 install_element(VIEW_NODE
, &show_ip_ospf_instance_interface_cmd
);
10390 /* "show ip ospf interface traffic */
10391 install_element(VIEW_NODE
, &show_ip_ospf_interface_traffic_cmd
);
10393 /* "show ip ospf neighbor" commands. */
10394 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_detail_cmd
);
10395 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_cmd
);
10396 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_id_cmd
);
10397 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_all_cmd
);
10398 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_cmd
);
10399 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_cmd
);
10400 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_all_cmd
);
10402 install_element(VIEW_NODE
,
10403 &show_ip_ospf_instance_neighbor_int_detail_cmd
);
10404 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_int_cmd
);
10405 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_id_cmd
);
10406 install_element(VIEW_NODE
,
10407 &show_ip_ospf_instance_neighbor_detail_all_cmd
);
10408 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_detail_cmd
);
10409 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_cmd
);
10410 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_all_cmd
);
10412 /* "show ip ospf route" commands. */
10413 install_element(VIEW_NODE
, &show_ip_ospf_route_cmd
);
10414 install_element(VIEW_NODE
, &show_ip_ospf_border_routers_cmd
);
10416 install_element(VIEW_NODE
, &show_ip_ospf_instance_route_cmd
);
10417 install_element(VIEW_NODE
, &show_ip_ospf_instance_border_routers_cmd
);
10419 /* "show ip ospf vrfs" commands. */
10420 install_element(VIEW_NODE
, &show_ip_ospf_vrfs_cmd
);
10424 /* ospfd's interface node. */
10425 static struct cmd_node interface_node
= {INTERFACE_NODE
, "%s(config-if)# ", 1};
10427 /* Initialization of OSPF interface. */
10428 static void ospf_vty_if_init(void)
10430 /* Install interface node. */
10431 install_node(&interface_node
, config_write_interface
);
10434 /* "ip ospf authentication" commands. */
10435 install_element(INTERFACE_NODE
, &ip_ospf_authentication_args_addr_cmd
);
10436 install_element(INTERFACE_NODE
, &ip_ospf_authentication_addr_cmd
);
10437 install_element(INTERFACE_NODE
,
10438 &no_ip_ospf_authentication_args_addr_cmd
);
10439 install_element(INTERFACE_NODE
, &no_ip_ospf_authentication_addr_cmd
);
10440 install_element(INTERFACE_NODE
, &ip_ospf_authentication_key_addr_cmd
);
10441 install_element(INTERFACE_NODE
,
10442 &no_ip_ospf_authentication_key_authkey_addr_cmd
);
10443 install_element(INTERFACE_NODE
,
10444 &no_ospf_authentication_key_authkey_addr_cmd
);
10446 /* "ip ospf message-digest-key" commands. */
10447 install_element(INTERFACE_NODE
, &ip_ospf_message_digest_key_cmd
);
10448 install_element(INTERFACE_NODE
, &no_ip_ospf_message_digest_key_cmd
);
10450 /* "ip ospf cost" commands. */
10451 install_element(INTERFACE_NODE
, &ip_ospf_cost_cmd
);
10452 install_element(INTERFACE_NODE
, &no_ip_ospf_cost_cmd
);
10454 /* "ip ospf mtu-ignore" commands. */
10455 install_element(INTERFACE_NODE
, &ip_ospf_mtu_ignore_addr_cmd
);
10456 install_element(INTERFACE_NODE
, &no_ip_ospf_mtu_ignore_addr_cmd
);
10458 /* "ip ospf dead-interval" commands. */
10459 install_element(INTERFACE_NODE
, &ip_ospf_dead_interval_cmd
);
10460 install_element(INTERFACE_NODE
,
10461 &ip_ospf_dead_interval_minimal_addr_cmd
);
10462 install_element(INTERFACE_NODE
, &no_ip_ospf_dead_interval_cmd
);
10464 /* "ip ospf hello-interval" commands. */
10465 install_element(INTERFACE_NODE
, &ip_ospf_hello_interval_cmd
);
10466 install_element(INTERFACE_NODE
, &no_ip_ospf_hello_interval_cmd
);
10468 /* "ip ospf network" commands. */
10469 install_element(INTERFACE_NODE
, &ip_ospf_network_cmd
);
10470 install_element(INTERFACE_NODE
, &no_ip_ospf_network_cmd
);
10472 /* "ip ospf priority" commands. */
10473 install_element(INTERFACE_NODE
, &ip_ospf_priority_cmd
);
10474 install_element(INTERFACE_NODE
, &no_ip_ospf_priority_cmd
);
10476 /* "ip ospf retransmit-interval" commands. */
10477 install_element(INTERFACE_NODE
, &ip_ospf_retransmit_interval_addr_cmd
);
10478 install_element(INTERFACE_NODE
,
10479 &no_ip_ospf_retransmit_interval_addr_cmd
);
10481 /* "ip ospf transmit-delay" commands. */
10482 install_element(INTERFACE_NODE
, &ip_ospf_transmit_delay_addr_cmd
);
10483 install_element(INTERFACE_NODE
, &no_ip_ospf_transmit_delay_addr_cmd
);
10485 /* "ip ospf area" commands. */
10486 install_element(INTERFACE_NODE
, &ip_ospf_area_cmd
);
10487 install_element(INTERFACE_NODE
, &no_ip_ospf_area_cmd
);
10489 /* These commands are compatibitliy for previous version. */
10490 install_element(INTERFACE_NODE
, &ospf_authentication_key_cmd
);
10491 install_element(INTERFACE_NODE
, &ospf_message_digest_key_cmd
);
10492 install_element(INTERFACE_NODE
, &no_ospf_message_digest_key_cmd
);
10493 install_element(INTERFACE_NODE
, &ospf_dead_interval_cmd
);
10494 install_element(INTERFACE_NODE
, &no_ospf_dead_interval_cmd
);
10495 install_element(INTERFACE_NODE
, &ospf_hello_interval_cmd
);
10496 install_element(INTERFACE_NODE
, &no_ospf_hello_interval_cmd
);
10497 install_element(INTERFACE_NODE
, &ospf_cost_cmd
);
10498 install_element(INTERFACE_NODE
, &no_ospf_cost_cmd
);
10499 install_element(INTERFACE_NODE
, &ospf_network_cmd
);
10500 install_element(INTERFACE_NODE
, &no_ospf_network_cmd
);
10501 install_element(INTERFACE_NODE
, &ospf_priority_cmd
);
10502 install_element(INTERFACE_NODE
, &no_ospf_priority_cmd
);
10503 install_element(INTERFACE_NODE
, &ospf_retransmit_interval_cmd
);
10504 install_element(INTERFACE_NODE
, &no_ospf_retransmit_interval_cmd
);
10505 install_element(INTERFACE_NODE
, &ospf_transmit_delay_cmd
);
10506 install_element(INTERFACE_NODE
, &no_ospf_transmit_delay_cmd
);
10509 static void ospf_vty_zebra_init(void)
10511 install_element(OSPF_NODE
, &ospf_redistribute_source_cmd
);
10512 install_element(OSPF_NODE
, &no_ospf_redistribute_source_cmd
);
10513 install_element(OSPF_NODE
, &ospf_redistribute_instance_source_cmd
);
10514 install_element(OSPF_NODE
, &no_ospf_redistribute_instance_source_cmd
);
10516 install_element(OSPF_NODE
, &ospf_distribute_list_out_cmd
);
10517 install_element(OSPF_NODE
, &no_ospf_distribute_list_out_cmd
);
10519 install_element(OSPF_NODE
, &ospf_default_information_originate_cmd
);
10520 install_element(OSPF_NODE
, &no_ospf_default_information_originate_cmd
);
10522 install_element(OSPF_NODE
, &ospf_default_metric_cmd
);
10523 install_element(OSPF_NODE
, &no_ospf_default_metric_cmd
);
10525 install_element(OSPF_NODE
, &ospf_distance_cmd
);
10526 install_element(OSPF_NODE
, &no_ospf_distance_cmd
);
10527 install_element(OSPF_NODE
, &no_ospf_distance_ospf_cmd
);
10528 install_element(OSPF_NODE
, &ospf_distance_ospf_cmd
);
10530 install_element (OSPF_NODE
, &ospf_distance_source_cmd
);
10531 install_element (OSPF_NODE
, &no_ospf_distance_source_cmd
);
10532 install_element (OSPF_NODE
, &ospf_distance_source_access_list_cmd
);
10533 install_element (OSPF_NODE
, &no_ospf_distance_source_access_list_cmd
);
10537 static struct cmd_node ospf_node
= {OSPF_NODE
, "%s(config-router)# ", 1};
10539 static void ospf_interface_clear(struct interface
*ifp
)
10541 if (!if_is_operative(ifp
))
10544 if (IS_DEBUG_OSPF(ism
, ISM_EVENTS
))
10545 zlog_debug("ISM[%s]: clear by reset", ifp
->name
);
10547 ospf_if_reset(ifp
);
10550 DEFUN (clear_ip_ospf_interface
,
10551 clear_ip_ospf_interface_cmd
,
10552 "clear ip ospf interface [IFNAME]",
10555 "OSPF information\n"
10556 "Interface information\n"
10557 "Interface name\n")
10559 int idx_ifname
= 4;
10560 struct interface
*ifp
;
10561 struct listnode
*node
;
10562 struct ospf
*ospf
= NULL
;
10564 if (argc
== 4) /* Clear all the ospfv2 interfaces. */
10566 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
10567 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
10568 FOR_ALL_INTERFACES (vrf
, ifp
)
10569 ospf_interface_clear(ifp
);
10572 /* Interface name is specified. */
10573 ifp
= if_lookup_by_name_all_vrf(argv
[idx_ifname
]->arg
);
10575 vty_out(vty
, "No such interface name\n");
10577 ospf_interface_clear(ifp
);
10580 return CMD_SUCCESS
;
10583 void ospf_vty_clear_init(void)
10585 install_element(ENABLE_NODE
, &clear_ip_ospf_interface_cmd
);
10589 /* Install OSPF related vty commands. */
10590 void ospf_vty_init(void)
10592 /* Install ospf top node. */
10593 install_node(&ospf_node
, ospf_config_write
);
10595 /* "router ospf" commands. */
10596 install_element(CONFIG_NODE
, &router_ospf_cmd
);
10597 install_element(CONFIG_NODE
, &no_router_ospf_cmd
);
10600 install_default(OSPF_NODE
);
10602 /* "ospf router-id" commands. */
10603 install_element(OSPF_NODE
, &ospf_router_id_cmd
);
10604 install_element(OSPF_NODE
, &ospf_router_id_old_cmd
);
10605 install_element(OSPF_NODE
, &no_ospf_router_id_cmd
);
10607 /* "passive-interface" commands. */
10608 install_element(OSPF_NODE
, &ospf_passive_interface_addr_cmd
);
10609 install_element(OSPF_NODE
, &no_ospf_passive_interface_addr_cmd
);
10611 /* "ospf abr-type" commands. */
10612 install_element(OSPF_NODE
, &ospf_abr_type_cmd
);
10613 install_element(OSPF_NODE
, &no_ospf_abr_type_cmd
);
10615 /* "ospf log-adjacency-changes" commands. */
10616 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_cmd
);
10617 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_detail_cmd
);
10618 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_cmd
);
10619 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_detail_cmd
);
10621 /* "ospf rfc1583-compatible" commands. */
10622 install_element(OSPF_NODE
, &ospf_compatible_rfc1583_cmd
);
10623 install_element(OSPF_NODE
, &no_ospf_compatible_rfc1583_cmd
);
10624 install_element(OSPF_NODE
, &ospf_rfc1583_flag_cmd
);
10625 install_element(OSPF_NODE
, &no_ospf_rfc1583_flag_cmd
);
10627 /* "network area" commands. */
10628 install_element(OSPF_NODE
, &ospf_network_area_cmd
);
10629 install_element(OSPF_NODE
, &no_ospf_network_area_cmd
);
10631 /* "area authentication" commands. */
10632 install_element(OSPF_NODE
,
10633 &ospf_area_authentication_message_digest_cmd
);
10634 install_element(OSPF_NODE
, &ospf_area_authentication_cmd
);
10635 install_element(OSPF_NODE
, &no_ospf_area_authentication_cmd
);
10637 /* "area range" commands. */
10638 install_element(OSPF_NODE
, &ospf_area_range_cmd
);
10639 install_element(OSPF_NODE
, &ospf_area_range_cost_cmd
);
10640 install_element(OSPF_NODE
, &ospf_area_range_not_advertise_cmd
);
10641 install_element(OSPF_NODE
, &no_ospf_area_range_cmd
);
10642 install_element(OSPF_NODE
, &ospf_area_range_substitute_cmd
);
10643 install_element(OSPF_NODE
, &no_ospf_area_range_substitute_cmd
);
10645 /* "area virtual-link" commands. */
10646 install_element(OSPF_NODE
, &ospf_area_vlink_cmd
);
10647 install_element(OSPF_NODE
, &ospf_area_vlink_intervals_cmd
);
10648 install_element(OSPF_NODE
, &no_ospf_area_vlink_cmd
);
10649 install_element(OSPF_NODE
, &no_ospf_area_vlink_intervals_cmd
);
10652 /* "area stub" commands. */
10653 install_element(OSPF_NODE
, &ospf_area_stub_no_summary_cmd
);
10654 install_element(OSPF_NODE
, &ospf_area_stub_cmd
);
10655 install_element(OSPF_NODE
, &no_ospf_area_stub_no_summary_cmd
);
10656 install_element(OSPF_NODE
, &no_ospf_area_stub_cmd
);
10658 /* "area nssa" commands. */
10659 install_element(OSPF_NODE
, &ospf_area_nssa_cmd
);
10660 install_element(OSPF_NODE
, &ospf_area_nssa_translate_cmd
);
10661 install_element(OSPF_NODE
, &ospf_area_nssa_no_summary_cmd
);
10662 install_element(OSPF_NODE
, &no_ospf_area_nssa_no_summary_cmd
);
10663 install_element(OSPF_NODE
, &no_ospf_area_nssa_cmd
);
10665 install_element(OSPF_NODE
, &ospf_area_default_cost_cmd
);
10666 install_element(OSPF_NODE
, &no_ospf_area_default_cost_cmd
);
10668 install_element(OSPF_NODE
, &ospf_area_shortcut_cmd
);
10669 install_element(OSPF_NODE
, &no_ospf_area_shortcut_cmd
);
10671 install_element(OSPF_NODE
, &ospf_area_export_list_cmd
);
10672 install_element(OSPF_NODE
, &no_ospf_area_export_list_cmd
);
10674 install_element(OSPF_NODE
, &ospf_area_filter_list_cmd
);
10675 install_element(OSPF_NODE
, &no_ospf_area_filter_list_cmd
);
10677 install_element(OSPF_NODE
, &ospf_area_import_list_cmd
);
10678 install_element(OSPF_NODE
, &no_ospf_area_import_list_cmd
);
10680 /* SPF timer commands */
10681 install_element(OSPF_NODE
, &ospf_timers_throttle_spf_cmd
);
10682 install_element(OSPF_NODE
, &no_ospf_timers_throttle_spf_cmd
);
10684 /* LSA timers commands */
10685 install_element(OSPF_NODE
, &ospf_timers_min_ls_interval_cmd
);
10686 install_element(OSPF_NODE
, &no_ospf_timers_min_ls_interval_cmd
);
10687 install_element(OSPF_NODE
, &ospf_timers_lsa_min_arrival_cmd
);
10688 install_element(OSPF_NODE
, &no_ospf_timers_lsa_min_arrival_cmd
);
10689 install_element(OSPF_NODE
, &ospf_timers_lsa_arrival_cmd
);
10690 install_element(OSPF_NODE
, &no_ospf_timers_lsa_arrival_cmd
);
10692 /* refresh timer commands */
10693 install_element(OSPF_NODE
, &ospf_refresh_timer_cmd
);
10694 install_element(OSPF_NODE
, &no_ospf_refresh_timer_val_cmd
);
10696 /* max-metric commands */
10697 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_admin_cmd
);
10698 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_admin_cmd
);
10699 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_startup_cmd
);
10700 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_startup_cmd
);
10701 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_shutdown_cmd
);
10702 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_shutdown_cmd
);
10704 /* reference bandwidth commands */
10705 install_element(OSPF_NODE
, &ospf_auto_cost_reference_bandwidth_cmd
);
10706 install_element(OSPF_NODE
, &no_ospf_auto_cost_reference_bandwidth_cmd
);
10708 /* "neighbor" commands. */
10709 install_element(OSPF_NODE
, &ospf_neighbor_cmd
);
10710 install_element(OSPF_NODE
, &ospf_neighbor_poll_interval_cmd
);
10711 install_element(OSPF_NODE
, &no_ospf_neighbor_cmd
);
10712 install_element(OSPF_NODE
, &no_ospf_neighbor_poll_cmd
);
10714 /* write multiplier commands */
10715 install_element(OSPF_NODE
, &ospf_write_multiplier_cmd
);
10716 install_element(OSPF_NODE
, &write_multiplier_cmd
);
10717 install_element(OSPF_NODE
, &no_ospf_write_multiplier_cmd
);
10718 install_element(OSPF_NODE
, &no_write_multiplier_cmd
);
10720 /* Init interface related vty commands. */
10721 ospf_vty_if_init();
10723 /* Init zebra related vty commands. */
10724 ospf_vty_zebra_init();