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
[],
141 struct ospf
*ospf
= NULL
;
142 int idx_vrf
= 0, idx_inst
= 0;
143 const char *vrf_name
= NULL
;
146 if (argv_find(argv
, argc
, "(1-65535)", &idx_inst
))
147 *instance
= strtoul(argv
[idx_inst
]->arg
, NULL
, 10);
149 if (argv_find(argv
, argc
, "vrf", &idx_vrf
)) {
150 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
152 /* Allocate VRF aware instance */
153 ospf
= ospf_get(*instance
, vrf_name
);
155 ospf
= ospf_lookup_by_inst_name(*instance
, vrf_name
);
159 ospf
= ospf_get(*instance
, NULL
);
161 ospf
= ospf_lookup_instance(*instance
);
168 static void ospf_show_vrf_name(struct ospf
*ospf
, struct vty
*vty
,
169 json_object
*json
, u_char use_vrf
)
173 if (ospf
->vrf_id
== VRF_DEFAULT
)
174 json_object_string_add(json
, "vrfName",
177 json_object_string_add(json
, "vrfName",
179 json_object_int_add(json
, "vrfId", ospf
->vrf_id
);
181 if (ospf
->vrf_id
== VRF_DEFAULT
)
182 vty_out(vty
, "VRF Name: %s\n", "default");
184 vty_out(vty
, "VRF Name: %s\n", ospf
->name
);
189 #ifndef VTYSH_EXTRACT_PL
190 #include "ospfd/ospf_vty_clippy.c"
193 DEFUN_NOSH (router_ospf
,
195 "router ospf [{(1-65535)|vrf NAME}]",
196 "Enable a routing process\n"
197 "Start OSPF configuration\n"
201 struct ospf
*ospf
= NULL
;
202 int ret
= CMD_SUCCESS
;
203 u_short instance
= 0;
204 struct vrf
*vrf
= NULL
;
205 struct route_node
*rn
;
206 struct interface
*ifp
;
208 ospf
= ospf_cmd_lookup_ospf(vty
, argv
, argc
, 1, &instance
);
210 return CMD_WARNING_CONFIG_FAILED
;
212 /* The following logic to set the vty qobj index is in place to be able
213 to ignore the commands which dont belong to this instance. */
214 if (ospf
->instance
!= instance
) {
215 VTY_PUSH_CONTEXT_NULL(OSPF_NODE
);
216 ret
= CMD_NOT_MY_INSTANCE
;
218 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
219 ospf
->oi_running
= 1;
220 if (IS_DEBUG_OSPF_EVENT
)
221 zlog_debug("Config command 'router ospf %d' received, vrf %s id %d 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 u_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
, u_char 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",
467 (char *)argv
[1]->arg
);
468 return CMD_WARNING_CONFIG_FAILED
;
471 params
= IF_DEF_PARAMS(ifp
);
474 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
477 "Please specify interface address by A.B.C.D\n");
478 return CMD_WARNING_CONFIG_FAILED
;
481 params
= ospf_get_if_params(ifp
, addr
);
482 ospf_if_update_params(ifp
, addr
);
483 ospf_passive_interface_update_addr(ospf
, ifp
, params
,
484 OSPF_IF_PASSIVE
, addr
);
487 ospf_passive_interface_update(ospf
, ifp
, params
, OSPF_IF_PASSIVE
);
489 /* XXX We should call ospf_if_set_multicast on exactly those
490 * interfaces for which the passive property changed. It is too much
491 * work to determine this set, so we do this for every interface.
492 * This is safe and reasonable because ospf_if_set_multicast uses a
493 * record of joined groups to avoid systems calls if the desired
494 * memberships match the current memership.
497 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
498 struct ospf_interface
*oi
= rn
->info
;
500 if (oi
&& (OSPF_IF_PARAM(oi
, passive_interface
)
502 ospf_if_set_multicast(oi
);
505 * XXX It is not clear what state transitions the interface needs to
506 * undergo when going from active to passive. Fixing this will
507 * require precise identification of interfaces having such a
514 DEFUN (no_ospf_passive_interface
,
515 no_ospf_passive_interface_addr_cmd
,
516 "no passive-interface <IFNAME [A.B.C.D]|default>",
518 "Allow routing updates on an interface\n"
521 "Allow routing updates on interfaces by default\n")
523 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
525 struct interface
*ifp
= NULL
;
526 struct in_addr addr
= {.s_addr
= INADDR_ANY
};
527 struct ospf_if_params
*params
;
529 struct route_node
*rn
;
531 if (strmatch(argv
[2]->text
, "default")) {
532 ospf_passive_interface_default(ospf
, OSPF_IF_ACTIVE
);
536 if (ospf
->vrf_id
!= VRF_UNKNOWN
)
537 ifp
= if_get_by_name(argv
[2]->arg
, ospf
->vrf_id
, 0);
540 vty_out(vty
, "interface %s not found.\n",
541 (char *)argv
[2]->arg
);
542 return CMD_WARNING_CONFIG_FAILED
;
545 params
= IF_DEF_PARAMS(ifp
);
548 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
551 "Please specify interface address by A.B.C.D\n");
552 return CMD_WARNING_CONFIG_FAILED
;
555 params
= ospf_lookup_if_params(ifp
, addr
);
558 ospf_passive_interface_update_addr(ospf
, ifp
, params
,
559 OSPF_IF_ACTIVE
, addr
);
561 ospf_passive_interface_update(ospf
, ifp
, params
, OSPF_IF_ACTIVE
);
563 /* XXX We should call ospf_if_set_multicast on exactly those
564 * interfaces for which the passive property changed. It is too much
565 * work to determine this set, so we do this for every interface.
566 * This is safe and reasonable because ospf_if_set_multicast uses a
567 * record of joined groups to avoid systems calls if the desired
568 * memberships match the current memership.
570 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
571 struct ospf_interface
*oi
= rn
->info
;
574 && (OSPF_IF_PARAM(oi
, passive_interface
) == OSPF_IF_ACTIVE
))
575 ospf_if_set_multicast(oi
);
582 DEFUN (ospf_network_area
,
583 ospf_network_area_cmd
,
584 "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
585 "Enable routing on an IP network\n"
586 "OSPF network prefix\n"
587 "Set the OSPF area ID\n"
588 "OSPF area ID in IP address format\n"
589 "OSPF area ID as a decimal value\n")
591 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
592 int idx_ipv4_prefixlen
= 1;
593 int idx_ipv4_number
= 3;
594 struct prefix_ipv4 p
;
595 struct in_addr area_id
;
598 if (ospf
->instance
) {
600 "The network command is not supported in multi-instance ospf\n");
601 return CMD_WARNING_CONFIG_FAILED
;
604 if (ospf
->if_ospf_cli_count
> 0) {
606 "Please remove all ip ospf area x.x.x.x commands first.\n");
607 if (IS_DEBUG_OSPF_EVENT
)
608 zlog_debug("%s ospf vrf %s num of %u ip osp area x config",
610 ospf
->name
? ospf
->name
: "NIL",
611 ospf
->if_ospf_cli_count
);
612 return CMD_WARNING_CONFIG_FAILED
;
615 /* Get network prefix and Area ID. */
616 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
617 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
619 ret
= ospf_network_set(ospf
, &p
, area_id
, format
);
621 vty_out(vty
, "There is already same network statement.\n");
622 return CMD_WARNING_CONFIG_FAILED
;
628 DEFUN (no_ospf_network_area
,
629 no_ospf_network_area_cmd
,
630 "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
632 "Enable routing on an IP network\n"
633 "OSPF network prefix\n"
634 "Set the OSPF area ID\n"
635 "OSPF area ID in IP address format\n"
636 "OSPF area ID as a decimal value\n")
638 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
639 int idx_ipv4_prefixlen
= 2;
640 int idx_ipv4_number
= 4;
641 struct prefix_ipv4 p
;
642 struct in_addr area_id
;
645 if (ospf
->instance
) {
647 "The network command is not supported in multi-instance ospf\n");
648 return CMD_WARNING_CONFIG_FAILED
;
651 /* Get network prefix and Area ID. */
652 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
653 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
655 ret
= ospf_network_unset(ospf
, &p
, area_id
);
658 "Can't find specified network area configuration.\n");
659 return CMD_WARNING_CONFIG_FAILED
;
665 DEFUN (ospf_area_range
,
667 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]",
668 "OSPF area parameters\n"
669 "OSPF area ID in IP address format\n"
670 "OSPF area ID as a decimal value\n"
671 "Summarize routes matching address/mask (border routers only)\n"
672 "Area range prefix\n"
673 "Advertise this range (default)\n"
674 "User specified metric for this range\n"
675 "Advertised metric for this range\n")
677 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
678 int idx_ipv4_number
= 1;
679 int idx_ipv4_prefixlen
= 3;
681 struct prefix_ipv4 p
;
682 struct in_addr area_id
;
686 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
687 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
689 ospf_area_range_set(ospf
, area_id
, &p
, OSPF_AREA_RANGE_ADVERTISE
);
691 cost
= strtoul(argv
[idx_cost
]->arg
, NULL
, 10);
692 ospf_area_range_cost_set(ospf
, area_id
, &p
, cost
);
698 DEFUN (ospf_area_range_cost
,
699 ospf_area_range_cost_cmd
,
700 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M cost (0-16777215)",
701 "OSPF area parameters\n"
702 "OSPF area ID in IP address format\n"
703 "OSPF area ID as a decimal value\n"
704 "Summarize routes matching address/mask (border routers only)\n"
705 "Area range prefix\n"
706 "User specified metric for this range\n"
707 "Advertised metric for this range\n")
709 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
710 int idx_ipv4_number
= 1;
711 int idx_ipv4_prefixlen
= 3;
713 struct prefix_ipv4 p
;
714 struct in_addr area_id
;
718 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
719 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
721 ospf_area_range_set(ospf
, area_id
, &p
, OSPF_AREA_RANGE_ADVERTISE
);
722 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
725 cost
= strtoul(argv
[idx_cost
]->arg
, NULL
, 10);
726 ospf_area_range_cost_set(ospf
, area_id
, &p
, cost
);
731 DEFUN (ospf_area_range_not_advertise
,
732 ospf_area_range_not_advertise_cmd
,
733 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise",
734 "OSPF area parameters\n"
735 "OSPF area ID in IP address format\n"
736 "OSPF area ID as a decimal value\n"
737 "Summarize routes matching address/mask (border routers only)\n"
738 "Area range prefix\n"
739 "DoNotAdvertise this range\n")
741 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
742 int idx_ipv4_number
= 1;
743 int idx_ipv4_prefixlen
= 3;
744 struct prefix_ipv4 p
;
745 struct in_addr area_id
;
748 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
749 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
751 ospf_area_range_set(ospf
, area_id
, &p
, 0);
752 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
758 DEFUN (no_ospf_area_range
,
759 no_ospf_area_range_cmd
,
760 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]",
762 "OSPF area parameters\n"
763 "OSPF area ID in IP address format\n"
764 "OSPF area ID as a decimal value\n"
765 "Summarize routes matching address/mask (border routers only)\n"
766 "Area range prefix\n"
767 "User specified metric for this range\n"
768 "Advertised metric for this range\n"
769 "Advertise this range (default)\n"
770 "User specified metric for this range\n"
771 "Advertised metric for this range\n"
772 "DoNotAdvertise this range\n")
774 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
775 int idx_ipv4_number
= 2;
776 int idx_ipv4_prefixlen
= 4;
777 struct prefix_ipv4 p
;
778 struct in_addr area_id
;
781 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
782 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
784 ospf_area_range_unset(ospf
, area_id
, &p
);
789 DEFUN (ospf_area_range_substitute
,
790 ospf_area_range_substitute_cmd
,
791 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
792 "OSPF area parameters\n"
793 "OSPF area ID in IP address format\n"
794 "OSPF area ID as a decimal value\n"
795 "Summarize routes matching address/mask (border routers only)\n"
796 "Area range prefix\n"
797 "Announce area range as another prefix\n"
798 "Network prefix to be announced instead of range\n")
800 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
801 int idx_ipv4_number
= 1;
802 int idx_ipv4_prefixlen
= 3;
803 int idx_ipv4_prefixlen_2
= 5;
804 struct prefix_ipv4 p
, s
;
805 struct in_addr area_id
;
808 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
809 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
810 str2prefix_ipv4(argv
[idx_ipv4_prefixlen_2
]->arg
, &s
);
812 ospf_area_range_substitute_set(ospf
, area_id
, &p
, &s
);
813 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
819 DEFUN (no_ospf_area_range_substitute
,
820 no_ospf_area_range_substitute_cmd
,
821 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
823 "OSPF area parameters\n"
824 "OSPF area ID in IP address format\n"
825 "OSPF area ID as a decimal value\n"
826 "Summarize routes matching address/mask (border routers only)\n"
827 "Area range prefix\n"
828 "Announce area range as another prefix\n"
829 "Network prefix to be announced instead of range\n")
831 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
832 int idx_ipv4_number
= 2;
833 int idx_ipv4_prefixlen
= 4;
834 int idx_ipv4_prefixlen_2
= 6;
835 struct prefix_ipv4 p
, s
;
836 struct in_addr area_id
;
839 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
840 str2prefix_ipv4(argv
[idx_ipv4_prefixlen
]->arg
, &p
);
841 str2prefix_ipv4(argv
[idx_ipv4_prefixlen_2
]->arg
, &s
);
843 ospf_area_range_substitute_unset(ospf
, area_id
, &p
);
849 /* Command Handler Logic in VLink stuff is delicate!!
851 ALTER AT YOUR OWN RISK!!!!
853 Various dummy values are used to represent 'NoChange' state for
854 VLink configuration NOT being changed by a VLink command, and
855 special syntax is used within the command strings so that the
856 typed in command verbs can be seen in the configuration command
857 bacckend handler. This is to drastically reduce the verbeage
858 required to coe up with a reasonably compatible Cisco VLink command
860 - Matthew Grant <grantma@anathoth.gen.nz>
861 Wed, 21 Feb 2001 15:13:52 +1300
864 /* Configuration data for virtual links
866 struct ospf_vl_config_data
{
867 struct vty
*vty
; /* vty stuff */
868 struct in_addr area_id
; /* area ID from command line */
869 int area_id_fmt
; /* command line area ID format */
870 struct in_addr vl_peer
; /* command line vl_peer */
871 int auth_type
; /* Authehntication type, if given */
872 char *auth_key
; /* simple password if present */
873 int crypto_key_id
; /* Cryptographic key ID */
874 char *md5_key
; /* MD5 authentication key */
875 int hello_interval
; /* Obvious what these are... */
876 int retransmit_interval
;
881 static void ospf_vl_config_data_init(struct ospf_vl_config_data
*vl_config
,
884 memset(vl_config
, 0, sizeof(struct ospf_vl_config_data
));
885 vl_config
->auth_type
= OSPF_AUTH_CMD_NOTSEEN
;
886 vl_config
->vty
= vty
;
889 static struct ospf_vl_data
*
890 ospf_find_vl_data(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
892 struct ospf_area
*area
;
893 struct ospf_vl_data
*vl_data
;
895 struct in_addr area_id
;
897 vty
= vl_config
->vty
;
898 area_id
= vl_config
->area_id
;
900 if (area_id
.s_addr
== OSPF_AREA_BACKBONE
) {
902 "Configuring VLs over the backbone is not allowed\n");
905 area
= ospf_area_get(ospf
, area_id
);
906 ospf_area_display_format_set(ospf
, area
, vl_config
->area_id_fmt
);
908 if (area
->external_routing
!= OSPF_AREA_DEFAULT
) {
909 if (vl_config
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
910 vty_out(vty
, "Area %s is %s\n", inet_ntoa(area_id
),
911 area
->external_routing
== OSPF_AREA_NSSA
915 vty_out(vty
, "Area %ld is %s\n",
916 (u_long
)ntohl(area_id
.s_addr
),
917 area
->external_routing
== OSPF_AREA_NSSA
923 if ((vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
->vl_peer
))
925 vl_data
= ospf_vl_data_new(area
, vl_config
->vl_peer
);
926 if (vl_data
->vl_oi
== NULL
) {
927 vl_data
->vl_oi
= ospf_vl_new(ospf
, vl_data
);
928 ospf_vl_add(ospf
, vl_data
);
929 ospf_spf_calculate_schedule(ospf
,
930 SPF_FLAG_CONFIG_CHANGE
);
937 static int ospf_vl_set_security(struct ospf_vl_data
*vl_data
,
938 struct ospf_vl_config_data
*vl_config
)
940 struct crypt_key
*ck
;
942 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
944 vty
= vl_config
->vty
;
946 if (vl_config
->auth_type
!= OSPF_AUTH_CMD_NOTSEEN
) {
947 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), auth_type
);
948 IF_DEF_PARAMS(ifp
)->auth_type
= vl_config
->auth_type
;
951 if (vl_config
->auth_key
) {
952 memset(IF_DEF_PARAMS(ifp
)->auth_simple
, 0,
953 OSPF_AUTH_SIMPLE_SIZE
+ 1);
954 strncpy((char *)IF_DEF_PARAMS(ifp
)->auth_simple
,
955 vl_config
->auth_key
, OSPF_AUTH_SIMPLE_SIZE
);
956 } else if (vl_config
->md5_key
) {
957 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
958 vl_config
->crypto_key_id
)
960 vty_out(vty
, "OSPF: Key %d already exists\n",
961 vl_config
->crypto_key_id
);
964 ck
= ospf_crypt_key_new();
965 ck
->key_id
= vl_config
->crypto_key_id
;
966 memset(ck
->auth_key
, 0, OSPF_AUTH_MD5_SIZE
+ 1);
967 strncpy((char *)ck
->auth_key
, vl_config
->md5_key
,
970 ospf_crypt_key_add(IF_DEF_PARAMS(ifp
)->auth_crypt
, ck
);
971 } else if (vl_config
->crypto_key_id
!= 0) {
974 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp
)->auth_crypt
,
975 vl_config
->crypto_key_id
)
977 vty_out(vty
, "OSPF: Key %d does not exist\n",
978 vl_config
->crypto_key_id
);
979 return CMD_WARNING_CONFIG_FAILED
;
982 ospf_crypt_key_delete(IF_DEF_PARAMS(ifp
)->auth_crypt
,
983 vl_config
->crypto_key_id
);
989 static int ospf_vl_set_timers(struct ospf_vl_data
*vl_data
,
990 struct ospf_vl_config_data
*vl_config
)
992 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
993 /* Virtual Link data initialised to defaults, so only set
995 if (vl_config
->hello_interval
) {
996 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_hello
);
997 IF_DEF_PARAMS(ifp
)->v_hello
= vl_config
->hello_interval
;
1000 if (vl_config
->dead_interval
) {
1001 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), v_wait
);
1002 IF_DEF_PARAMS(ifp
)->v_wait
= vl_config
->dead_interval
;
1005 if (vl_config
->retransmit_interval
) {
1006 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), retransmit_interval
);
1007 IF_DEF_PARAMS(ifp
)->retransmit_interval
=
1008 vl_config
->retransmit_interval
;
1011 if (vl_config
->transmit_delay
) {
1012 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), transmit_delay
);
1013 IF_DEF_PARAMS(ifp
)->transmit_delay
= vl_config
->transmit_delay
;
1020 /* The business end of all of the above */
1021 static int ospf_vl_set(struct ospf
*ospf
, struct ospf_vl_config_data
*vl_config
)
1023 struct ospf_vl_data
*vl_data
;
1026 vl_data
= ospf_find_vl_data(ospf
, vl_config
);
1028 return CMD_WARNING_CONFIG_FAILED
;
1030 /* Process this one first as it can have a fatal result, which can
1031 only logically occur if the virtual link exists already
1032 Thus a command error does not result in a change to the
1033 running configuration such as unexpectedly altered timer
1035 ret
= ospf_vl_set_security(vl_data
, vl_config
);
1036 if (ret
!= CMD_SUCCESS
)
1039 /* Set any time based parameters, these area already range checked */
1041 ret
= ospf_vl_set_timers(vl_data
, vl_config
);
1042 if (ret
!= CMD_SUCCESS
)
1048 /* This stuff exists to make specifying all the alias commands A LOT simpler
1050 #define VLINK_HELPSTR_IPADDR \
1051 "OSPF area parameters\n" \
1052 "OSPF area ID in IP address format\n" \
1053 "OSPF area ID as a decimal value\n" \
1054 "Configure a virtual link\n" \
1055 "Router ID of the remote ABR\n"
1057 #define VLINK_HELPSTR_AUTHTYPE_SIMPLE \
1058 "Enable authentication on this virtual link\n" \
1061 #define VLINK_HELPSTR_AUTHTYPE_ALL \
1062 VLINK_HELPSTR_AUTHTYPE_SIMPLE \
1063 "Use null authentication\n" \
1064 "Use message-digest authentication\n"
1066 #define VLINK_HELPSTR_TIME_PARAM \
1067 "Time between HELLO packets\n" \
1069 "Time between retransmitting lost link state advertisements\n" \
1071 "Link state transmit delay\n" \
1073 "Interval time after which a neighbor is declared down\n" \
1076 #define VLINK_HELPSTR_AUTH_SIMPLE \
1077 "Authentication password (key)\n" \
1078 "The OSPF password (key)\n"
1080 #define VLINK_HELPSTR_AUTH_MD5 \
1081 "Message digest authentication password (key)\n" \
1083 "Use MD5 algorithm\n" \
1084 "The OSPF password (key)\n"
1086 DEFUN (ospf_area_vlink
,
1087 ospf_area_vlink_cmd
,
1088 "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>]",
1089 VLINK_HELPSTR_IPADDR
1090 "Enable authentication on this virtual link\n"
1091 "Use message-digest authentication\n"
1092 "Use null authentication\n"
1093 VLINK_HELPSTR_AUTH_MD5
1094 VLINK_HELPSTR_AUTH_SIMPLE
)
1096 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1097 int idx_ipv4_number
= 1;
1099 struct ospf_vl_config_data vl_config
;
1100 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1101 char md5_key
[OSPF_AUTH_MD5_SIZE
+ 1];
1105 ospf_vl_config_data_init(&vl_config
, vty
);
1107 /* Read off first 2 parameters and check them */
1108 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1109 &vl_config
.area_id_fmt
);
1111 vty_out(vty
, "OSPF area ID is invalid\n");
1112 return CMD_WARNING_CONFIG_FAILED
;
1115 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1117 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1118 return CMD_WARNING_CONFIG_FAILED
;
1122 /* Thats all folks! - BUGS B. strikes again!!!*/
1124 return ospf_vl_set(ospf
, &vl_config
);
1127 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1128 /* authentication - this option can only occur
1129 at start of command line */
1130 vl_config
.auth_type
= OSPF_AUTH_SIMPLE
;
1133 if (argv_find(argv
, argc
, "message-digest", &idx
)) {
1134 /* authentication message-digest */
1135 vl_config
.auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
1136 } else if (argv_find(argv
, argc
, "null", &idx
)) {
1137 /* "authentication null" */
1138 vl_config
.auth_type
= OSPF_AUTH_NULL
;
1141 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1142 vl_config
.md5_key
= NULL
;
1143 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1144 if (vl_config
.crypto_key_id
< 0)
1145 return CMD_WARNING_CONFIG_FAILED
;
1147 memset(md5_key
, 0, OSPF_AUTH_MD5_SIZE
+ 1);
1148 strncpy(md5_key
, argv
[idx
+ 3]->arg
, OSPF_AUTH_MD5_SIZE
);
1149 vl_config
.md5_key
= md5_key
;
1152 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1153 memset(auth_key
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
1154 strncpy(auth_key
, argv
[idx
+ 1]->arg
, OSPF_AUTH_SIMPLE_SIZE
);
1155 vl_config
.auth_key
= auth_key
;
1158 /* Action configuration */
1160 return ospf_vl_set(ospf
, &vl_config
);
1163 DEFUN (no_ospf_area_vlink
,
1164 no_ospf_area_vlink_cmd
,
1165 "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>]",
1167 VLINK_HELPSTR_IPADDR
1168 "Enable authentication on this virtual link\n" \
1169 "Use message-digest authentication\n" \
1170 "Use null authentication\n" \
1171 VLINK_HELPSTR_AUTH_MD5
1172 VLINK_HELPSTR_AUTH_SIMPLE
)
1174 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1175 int idx_ipv4_number
= 2;
1177 struct ospf_area
*area
;
1178 struct ospf_vl_config_data vl_config
;
1179 struct ospf_vl_data
*vl_data
= NULL
;
1180 char auth_key
[OSPF_AUTH_SIMPLE_SIZE
+ 1];
1184 ospf_vl_config_data_init(&vl_config
, vty
);
1186 ret
= str2area_id(argv
[idx_ipv4_number
]->arg
, &vl_config
.area_id
,
1189 vty_out(vty
, "OSPF area ID is invalid\n");
1190 return CMD_WARNING_CONFIG_FAILED
;
1193 area
= ospf_area_lookup_by_area_id(ospf
, vl_config
.area_id
);
1195 vty_out(vty
, "Area does not exist\n");
1196 return CMD_WARNING_CONFIG_FAILED
;
1199 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &vl_config
.vl_peer
);
1201 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1202 return CMD_WARNING_CONFIG_FAILED
;
1206 /* Basic VLink no command */
1207 /* Thats all folks! - BUGS B. strikes again!!!*/
1208 if ((vl_data
= ospf_vl_lookup(ospf
, area
, vl_config
.vl_peer
)))
1209 ospf_vl_delete(ospf
, vl_data
);
1211 ospf_area_check_free(ospf
, vl_config
.area_id
);
1216 /* If we are down here, we are reseting parameters */
1217 /* Deal with other parameters */
1219 if (argv_find(argv
, argc
, "authentication", &idx
)) {
1220 /* authentication - this option can only occur
1221 at start of command line */
1222 vl_config
.auth_type
= OSPF_AUTH_NOTSET
;
1225 if (argv_find(argv
, argc
, "message-digest-key", &idx
)) {
1226 vl_config
.md5_key
= NULL
;
1227 vl_config
.crypto_key_id
= strtol(argv
[idx
+ 1]->arg
, NULL
, 10);
1228 if (vl_config
.crypto_key_id
< 0)
1229 return CMD_WARNING_CONFIG_FAILED
;
1232 if (argv_find(argv
, argc
, "authentication-key", &idx
)) {
1233 /* Reset authentication-key to 0 */
1234 memset(auth_key
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
1235 vl_config
.auth_key
= auth_key
;
1238 /* Action configuration */
1240 return ospf_vl_set(ospf
, &vl_config
);
1243 DEFUN (ospf_area_vlink_intervals
,
1244 ospf_area_vlink_intervals_cmd
,
1245 "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)}",
1246 VLINK_HELPSTR_IPADDR
1247 VLINK_HELPSTR_TIME_PARAM
)
1249 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1250 struct ospf_vl_config_data vl_config
;
1253 ospf_vl_config_data_init(&vl_config
, vty
);
1255 char *area_id
= argv
[1]->arg
;
1256 char *router_id
= argv
[3]->arg
;
1258 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1260 vty_out(vty
, "OSPF area ID is invalid\n");
1261 return CMD_WARNING_CONFIG_FAILED
;
1264 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1266 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1267 return CMD_WARNING_CONFIG_FAILED
;
1270 for (int idx
= 4; idx
< argc
; idx
++) {
1271 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1272 vl_config
.hello_interval
=
1273 strtol(argv
[++idx
]->arg
, NULL
, 10);
1274 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1275 vl_config
.retransmit_interval
=
1276 strtol(argv
[++idx
]->arg
, NULL
, 10);
1277 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1278 vl_config
.transmit_delay
=
1279 strtol(argv
[++idx
]->arg
, NULL
, 10);
1280 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1281 vl_config
.dead_interval
=
1282 strtol(argv
[++idx
]->arg
, NULL
, 10);
1285 /* Action configuration */
1286 return ospf_vl_set(ospf
, &vl_config
);
1289 DEFUN (no_ospf_area_vlink_intervals
,
1290 no_ospf_area_vlink_intervals_cmd
,
1291 "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)}",
1293 VLINK_HELPSTR_IPADDR
1294 VLINK_HELPSTR_TIME_PARAM
)
1296 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1297 struct ospf_vl_config_data vl_config
;
1300 ospf_vl_config_data_init(&vl_config
, vty
);
1302 char *area_id
= argv
[2]->arg
;
1303 char *router_id
= argv
[4]->arg
;
1305 ret
= str2area_id(area_id
, &vl_config
.area_id
, &vl_config
.area_id_fmt
);
1307 vty_out(vty
, "OSPF area ID is invalid\n");
1308 return CMD_WARNING_CONFIG_FAILED
;
1311 ret
= inet_aton(router_id
, &vl_config
.vl_peer
);
1313 vty_out(vty
, "Please specify valid Router ID as a.b.c.d\n");
1314 return CMD_WARNING_CONFIG_FAILED
;
1317 for (int idx
= 5; idx
< argc
; idx
++) {
1318 if (strmatch(argv
[idx
]->text
, "hello-interval"))
1319 vl_config
.hello_interval
= OSPF_HELLO_INTERVAL_DEFAULT
;
1320 else if (strmatch(argv
[idx
]->text
, "retransmit-interval"))
1321 vl_config
.retransmit_interval
=
1322 OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
1323 else if (strmatch(argv
[idx
]->text
, "transmit-delay"))
1324 vl_config
.transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
1325 else if (strmatch(argv
[idx
]->text
, "dead-interval"))
1326 vl_config
.dead_interval
=
1327 OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
1330 /* Action configuration */
1331 return ospf_vl_set(ospf
, &vl_config
);
1334 DEFUN (ospf_area_shortcut
,
1335 ospf_area_shortcut_cmd
,
1336 "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>",
1337 "OSPF area parameters\n"
1338 "OSPF area ID in IP address format\n"
1339 "OSPF area ID as a decimal value\n"
1340 "Configure the area's shortcutting mode\n"
1341 "Set default shortcutting behavior\n"
1342 "Enable shortcutting through the area\n"
1343 "Disable shortcutting through the area\n")
1345 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1346 int idx_ipv4_number
= 1;
1347 int idx_enable_disable
= 3;
1348 struct ospf_area
*area
;
1349 struct in_addr area_id
;
1353 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1354 argv
[idx_ipv4_number
]->arg
);
1356 area
= ospf_area_get(ospf
, area_id
);
1357 ospf_area_display_format_set(ospf
, area
, format
);
1359 if (strncmp(argv
[idx_enable_disable
]->arg
, "de", 2) == 0)
1360 mode
= OSPF_SHORTCUT_DEFAULT
;
1361 else if (strncmp(argv
[idx_enable_disable
]->arg
, "di", 2) == 0)
1362 mode
= OSPF_SHORTCUT_DISABLE
;
1363 else if (strncmp(argv
[idx_enable_disable
]->arg
, "e", 1) == 0)
1364 mode
= OSPF_SHORTCUT_ENABLE
;
1366 return CMD_WARNING_CONFIG_FAILED
;
1368 ospf_area_shortcut_set(ospf
, area
, mode
);
1370 if (ospf
->abr_type
!= OSPF_ABR_SHORTCUT
)
1372 "Shortcut area setting will take effect "
1373 "only when the router is configured as Shortcut ABR\n");
1378 DEFUN (no_ospf_area_shortcut
,
1379 no_ospf_area_shortcut_cmd
,
1380 "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>",
1382 "OSPF area parameters\n"
1383 "OSPF area ID in IP address format\n"
1384 "OSPF area ID as a decimal value\n"
1385 "Deconfigure the area's shortcutting mode\n"
1386 "Deconfigure enabled shortcutting through the area\n"
1387 "Deconfigure disabled shortcutting through the area\n")
1389 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1390 int idx_ipv4_number
= 2;
1391 struct ospf_area
*area
;
1392 struct in_addr area_id
;
1395 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id
, format
,
1396 argv
[idx_ipv4_number
]->arg
);
1398 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1402 ospf_area_shortcut_unset(ospf
, area
);
1408 DEFUN (ospf_area_stub
,
1410 "area <A.B.C.D|(0-4294967295)> stub",
1411 "OSPF area parameters\n"
1412 "OSPF area ID in IP address format\n"
1413 "OSPF area ID as a decimal value\n"
1414 "Configure OSPF area as stub\n")
1416 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1417 int idx_ipv4_number
= 1;
1418 struct in_addr area_id
;
1421 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1422 argv
[idx_ipv4_number
]->arg
);
1424 ret
= ospf_area_stub_set(ospf
, area_id
);
1425 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1429 "First deconfigure all virtual link through this area\n");
1430 return CMD_WARNING_CONFIG_FAILED
;
1433 ospf_area_no_summary_unset(ospf
, area_id
);
1438 DEFUN (ospf_area_stub_no_summary
,
1439 ospf_area_stub_no_summary_cmd
,
1440 "area <A.B.C.D|(0-4294967295)> stub no-summary",
1441 "OSPF stub parameters\n"
1442 "OSPF area ID in IP address format\n"
1443 "OSPF area ID as a decimal value\n"
1444 "Configure OSPF area as stub\n"
1445 "Do not inject inter-area routes into stub\n")
1447 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1448 int idx_ipv4_number
= 1;
1449 struct in_addr area_id
;
1452 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1453 argv
[idx_ipv4_number
]->arg
);
1455 ret
= ospf_area_stub_set(ospf
, area_id
);
1456 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1460 "%% Area cannot be stub as it contains a virtual link\n");
1461 return CMD_WARNING_CONFIG_FAILED
;
1464 ospf_area_no_summary_set(ospf
, area_id
);
1469 DEFUN (no_ospf_area_stub
,
1470 no_ospf_area_stub_cmd
,
1471 "no area <A.B.C.D|(0-4294967295)> stub",
1473 "OSPF area parameters\n"
1474 "OSPF area ID in IP address format\n"
1475 "OSPF area ID as a decimal value\n"
1476 "Configure OSPF area as stub\n")
1478 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1479 int idx_ipv4_number
= 2;
1480 struct in_addr area_id
;
1483 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1484 argv
[idx_ipv4_number
]->arg
);
1486 ospf_area_stub_unset(ospf
, area_id
);
1487 ospf_area_no_summary_unset(ospf
, area_id
);
1492 DEFUN (no_ospf_area_stub_no_summary
,
1493 no_ospf_area_stub_no_summary_cmd
,
1494 "no area <A.B.C.D|(0-4294967295)> stub no-summary",
1496 "OSPF area parameters\n"
1497 "OSPF area ID in IP address format\n"
1498 "OSPF area ID as a decimal value\n"
1499 "Configure OSPF area as stub\n"
1500 "Do not inject inter-area routes into area\n")
1502 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1503 int idx_ipv4_number
= 2;
1504 struct in_addr area_id
;
1507 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id
, format
,
1508 argv
[idx_ipv4_number
]->arg
);
1509 ospf_area_no_summary_unset(ospf
, area_id
);
1514 static int ospf_area_nssa_cmd_handler(struct vty
*vty
, int argc
,
1515 struct cmd_token
**argv
, int cfg_nosum
,
1518 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1519 struct in_addr area_id
;
1522 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
, argv
[1]->arg
);
1524 ret
= ospf_area_nssa_set(ospf
, area_id
);
1525 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1529 "%% Area cannot be nssa as it contains a virtual link\n");
1530 return CMD_WARNING_CONFIG_FAILED
;
1534 if (strncmp(argv
[3]->text
, "translate-c", 11) == 0)
1535 ospf_area_nssa_translator_role_set(
1536 ospf
, area_id
, OSPF_NSSA_ROLE_CANDIDATE
);
1537 else if (strncmp(argv
[3]->text
, "translate-n", 11) == 0)
1538 ospf_area_nssa_translator_role_set(
1539 ospf
, area_id
, OSPF_NSSA_ROLE_NEVER
);
1540 else if (strncmp(argv
[3]->text
, "translate-a", 11) == 0)
1541 ospf_area_nssa_translator_role_set(
1542 ospf
, area_id
, OSPF_NSSA_ROLE_ALWAYS
);
1544 ospf_area_nssa_translator_role_set(ospf
, area_id
,
1545 OSPF_NSSA_ROLE_CANDIDATE
);
1550 ospf_area_no_summary_set(ospf
, area_id
);
1552 ospf_area_no_summary_unset(ospf
, area_id
);
1555 ospf_schedule_abr_task(ospf
);
1561 DEFUN (ospf_area_nssa_translate
,
1562 ospf_area_nssa_translate_cmd
,
1563 "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always>",
1564 "OSPF area parameters\n"
1565 "OSPF area ID in IP address format\n"
1566 "OSPF area ID as a decimal value\n"
1567 "Configure OSPF area as nssa\n"
1568 "Configure NSSA-ABR for translate election (default)\n"
1569 "Configure NSSA-ABR to never translate\n"
1570 "Configure NSSA-ABR to always translate\n")
1572 return ospf_area_nssa_cmd_handler(vty
, argc
, argv
, 0, 0);
1575 DEFUN (ospf_area_nssa
,
1577 "area <A.B.C.D|(0-4294967295)> nssa",
1578 "OSPF area parameters\n"
1579 "OSPF area ID in IP address format\n"
1580 "OSPF area ID as a decimal value\n"
1581 "Configure OSPF area as nssa\n")
1583 return ospf_area_nssa_cmd_handler(vty
, argc
, argv
, 0, 0);
1586 DEFUN (ospf_area_nssa_no_summary
,
1587 ospf_area_nssa_no_summary_cmd
,
1588 "area <A.B.C.D|(0-4294967295)> nssa no-summary",
1589 "OSPF area parameters\n"
1590 "OSPF area ID in IP address format\n"
1591 "OSPF area ID as a decimal value\n"
1592 "Configure OSPF area as nssa\n"
1593 "Do not inject inter-area routes into nssa\n")
1595 int idx_ipv4_number
= 1;
1596 struct in_addr area_id
;
1599 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1600 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1601 argv
[idx_ipv4_number
]->arg
);
1603 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1605 ospf_area_nssa_no_summary_set(ospf
, area_id
);
1607 ospf_schedule_abr_task(ospf
);
1612 DEFUN (no_ospf_area_nssa_no_summary
,
1613 no_ospf_area_nssa_no_summary_cmd
,
1614 "no area <A.B.C.D|(0-4294967295)> nssa no-summary",
1616 "OSPF area parameters\n"
1617 "OSPF area ID in IP address format\n"
1618 "OSPF area ID as a decimal value\n"
1619 "Configure OSPF area as nssa\n"
1620 "Do not inject inter-area routes into nssa\n")
1622 int idx_ipv4_number
= 2;
1623 struct in_addr area_id
;
1626 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1628 VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id
, format
,
1629 argv
[idx_ipv4_number
]->arg
);
1631 ospf_area_display_format_set(ospf
, ospf_area_get(ospf
, area_id
),
1633 ospf_area_no_summary_unset(ospf
, area_id
);
1635 ospf_schedule_abr_task(ospf
);
1640 DEFUN (no_ospf_area_nssa
,
1641 no_ospf_area_nssa_cmd
,
1642 "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always>]",
1644 "OSPF area parameters\n"
1645 "OSPF area ID in IP address format\n"
1646 "OSPF area ID as a decimal value\n"
1647 "Configure OSPF area as nssa\n"
1648 "Configure NSSA-ABR for translate election (default)\n"
1649 "Configure NSSA-ABR to never translate\n"
1650 "Configure NSSA-ABR to always translate\n")
1652 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1653 int idx_ipv4_number
= 2;
1654 struct in_addr area_id
;
1657 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id
, format
,
1658 argv
[idx_ipv4_number
]->arg
);
1660 ospf_area_nssa_unset(ospf
, area_id
, argc
);
1662 ospf_schedule_abr_task(ospf
);
1668 DEFUN (ospf_area_default_cost
,
1669 ospf_area_default_cost_cmd
,
1670 "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1671 "OSPF area parameters\n"
1672 "OSPF area ID in IP address format\n"
1673 "OSPF area ID as a decimal value\n"
1674 "Set the summary-default cost of a NSSA or stub area\n"
1675 "Stub's advertised default summary cost\n")
1677 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1678 int idx_ipv4_number
= 1;
1680 struct ospf_area
*area
;
1681 struct in_addr area_id
;
1684 struct prefix_ipv4 p
;
1686 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1687 argv
[idx_ipv4_number
]->arg
);
1688 cost
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1690 area
= ospf_area_get(ospf
, area_id
);
1691 ospf_area_display_format_set(ospf
, area
, format
);
1693 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1694 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1695 return CMD_WARNING_CONFIG_FAILED
;
1698 area
->default_cost
= cost
;
1701 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1703 if (IS_DEBUG_OSPF_EVENT
)
1705 "ospf_abr_announce_stub_defaults(): "
1706 "announcing 0.0.0.0/0 to area %s",
1707 inet_ntoa(area
->area_id
));
1708 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1713 DEFUN (no_ospf_area_default_cost
,
1714 no_ospf_area_default_cost_cmd
,
1715 "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1717 "OSPF area parameters\n"
1718 "OSPF area ID in IP address format\n"
1719 "OSPF area ID as a decimal value\n"
1720 "Set the summary-default cost of a NSSA or stub area\n"
1721 "Stub's advertised default summary cost\n")
1723 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1724 int idx_ipv4_number
= 2;
1725 struct ospf_area
*area
;
1726 struct in_addr area_id
;
1728 struct prefix_ipv4 p
;
1730 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id
, format
,
1731 argv
[idx_ipv4_number
]->arg
);
1733 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1737 if (area
->external_routing
== OSPF_AREA_DEFAULT
) {
1738 vty_out(vty
, "The area is neither stub, nor NSSA\n");
1739 return CMD_WARNING_CONFIG_FAILED
;
1742 area
->default_cost
= 1;
1745 p
.prefix
.s_addr
= OSPF_DEFAULT_DESTINATION
;
1747 if (IS_DEBUG_OSPF_EVENT
)
1749 "ospf_abr_announce_stub_defaults(): "
1750 "announcing 0.0.0.0/0 to area %s",
1751 inet_ntoa(area
->area_id
));
1752 ospf_abr_announce_network_to_area(&p
, area
->default_cost
, area
);
1755 ospf_area_check_free(ospf
, area_id
);
1760 DEFUN (ospf_area_export_list
,
1761 ospf_area_export_list_cmd
,
1762 "area <A.B.C.D|(0-4294967295)> export-list NAME",
1763 "OSPF area parameters\n"
1764 "OSPF area ID in IP address format\n"
1765 "OSPF area ID as a decimal value\n"
1766 "Set the filter for networks announced to other areas\n"
1767 "Name of the access-list\n")
1769 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1770 int idx_ipv4_number
= 1;
1771 struct ospf_area
*area
;
1772 struct in_addr area_id
;
1775 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1777 area
= ospf_area_get(ospf
, area_id
);
1778 ospf_area_display_format_set(ospf
, area
, format
);
1779 ospf_area_export_list_set(ospf
, area
, argv
[3]->arg
);
1784 DEFUN (no_ospf_area_export_list
,
1785 no_ospf_area_export_list_cmd
,
1786 "no area <A.B.C.D|(0-4294967295)> export-list NAME",
1788 "OSPF area parameters\n"
1789 "OSPF area ID in IP address format\n"
1790 "OSPF area ID as a decimal value\n"
1791 "Unset the filter for networks announced to other areas\n"
1792 "Name of the access-list\n")
1794 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1795 int idx_ipv4_number
= 2;
1796 struct ospf_area
*area
;
1797 struct in_addr area_id
;
1800 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1802 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1806 ospf_area_export_list_unset(ospf
, area
);
1812 DEFUN (ospf_area_import_list
,
1813 ospf_area_import_list_cmd
,
1814 "area <A.B.C.D|(0-4294967295)> import-list NAME",
1815 "OSPF area parameters\n"
1816 "OSPF area ID in IP address format\n"
1817 "OSPF area ID as a decimal value\n"
1818 "Set the filter for networks from other areas announced to the specified one\n"
1819 "Name of the access-list\n")
1821 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1822 int idx_ipv4_number
= 1;
1823 struct ospf_area
*area
;
1824 struct in_addr area_id
;
1827 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1829 area
= ospf_area_get(ospf
, area_id
);
1830 ospf_area_display_format_set(ospf
, area
, format
);
1831 ospf_area_import_list_set(ospf
, area
, argv
[3]->arg
);
1836 DEFUN (no_ospf_area_import_list
,
1837 no_ospf_area_import_list_cmd
,
1838 "no area <A.B.C.D|(0-4294967295)> import-list NAME",
1840 "OSPF area parameters\n"
1841 "OSPF area ID in IP address format\n"
1842 "OSPF area ID as a decimal value\n"
1843 "Unset the filter for networks announced to other areas\n"
1844 "Name of the access-list\n")
1846 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1847 int idx_ipv4_number
= 2;
1848 struct ospf_area
*area
;
1849 struct in_addr area_id
;
1852 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1854 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
1858 ospf_area_import_list_unset(ospf
, area
);
1863 DEFUN (ospf_area_filter_list
,
1864 ospf_area_filter_list_cmd
,
1865 "area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>",
1866 "OSPF area parameters\n"
1867 "OSPF area ID in IP address format\n"
1868 "OSPF area ID as a decimal value\n"
1869 "Filter networks between OSPF areas\n"
1870 "Filter prefixes between OSPF areas\n"
1871 "Name of an IP prefix-list\n"
1872 "Filter networks sent to this area\n"
1873 "Filter networks sent from this area\n")
1875 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1876 int idx_ipv4_number
= 1;
1879 struct ospf_area
*area
;
1880 struct in_addr area_id
;
1881 struct prefix_list
*plist
;
1884 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1886 area
= ospf_area_get(ospf
, area_id
);
1887 ospf_area_display_format_set(ospf
, area
, format
);
1888 plist
= prefix_list_lookup(AFI_IP
, argv
[idx_word
]->arg
);
1889 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1890 PREFIX_LIST_IN(area
) = plist
;
1891 if (PREFIX_NAME_IN(area
))
1892 free(PREFIX_NAME_IN(area
));
1894 PREFIX_NAME_IN(area
) = strdup(argv
[idx_word
]->arg
);
1895 ospf_schedule_abr_task(ospf
);
1897 PREFIX_LIST_OUT(area
) = plist
;
1898 if (PREFIX_NAME_OUT(area
))
1899 free(PREFIX_NAME_OUT(area
));
1901 PREFIX_NAME_OUT(area
) = strdup(argv
[idx_word
]->arg
);
1902 ospf_schedule_abr_task(ospf
);
1908 DEFUN (no_ospf_area_filter_list
,
1909 no_ospf_area_filter_list_cmd
,
1910 "no area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>",
1912 "OSPF area parameters\n"
1913 "OSPF area ID in IP address format\n"
1914 "OSPF area ID as a decimal value\n"
1915 "Filter networks between OSPF areas\n"
1916 "Filter prefixes between OSPF areas\n"
1917 "Name of an IP prefix-list\n"
1918 "Filter networks sent to this area\n"
1919 "Filter networks sent from this area\n")
1921 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1922 int idx_ipv4_number
= 2;
1925 struct ospf_area
*area
;
1926 struct in_addr area_id
;
1929 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
1931 if ((area
= ospf_area_lookup_by_area_id(ospf
, area_id
)) == NULL
)
1934 if (strncmp(argv
[idx_in_out
]->arg
, "in", 2) == 0) {
1935 if (PREFIX_NAME_IN(area
))
1936 if (strcmp(PREFIX_NAME_IN(area
), argv
[idx_word
]->arg
)
1940 PREFIX_LIST_IN(area
) = NULL
;
1941 if (PREFIX_NAME_IN(area
))
1942 free(PREFIX_NAME_IN(area
));
1944 PREFIX_NAME_IN(area
) = NULL
;
1946 ospf_schedule_abr_task(ospf
);
1948 if (PREFIX_NAME_OUT(area
))
1949 if (strcmp(PREFIX_NAME_OUT(area
), argv
[idx_word
]->arg
)
1953 PREFIX_LIST_OUT(area
) = NULL
;
1954 if (PREFIX_NAME_OUT(area
))
1955 free(PREFIX_NAME_OUT(area
));
1957 PREFIX_NAME_OUT(area
) = NULL
;
1959 ospf_schedule_abr_task(ospf
);
1966 DEFUN (ospf_area_authentication_message_digest
,
1967 ospf_area_authentication_message_digest_cmd
,
1968 "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest",
1970 "OSPF area parameters\n"
1971 "OSPF area ID in IP address format\n"
1972 "OSPF area ID as a decimal value\n"
1973 "Enable authentication\n"
1974 "Use message-digest authentication\n")
1976 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
1978 struct ospf_area
*area
;
1979 struct in_addr area_id
;
1982 argv_find(argv
, argc
, "area", &idx
);
1983 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx
+ 1]->arg
);
1985 area
= ospf_area_get(ospf
, area_id
);
1986 ospf_area_display_format_set(ospf
, area
, format
);
1987 area
->auth_type
= strmatch(argv
[0]->text
, "no") ? OSPF_AUTH_NULL
: OSPF_AUTH_CRYPTOGRAPHIC
;
1992 DEFUN (ospf_area_authentication
,
1993 ospf_area_authentication_cmd
,
1994 "area <A.B.C.D|(0-4294967295)> authentication",
1995 "OSPF area parameters\n"
1996 "OSPF area ID in IP address format\n"
1997 "OSPF area ID as a decimal value\n"
1998 "Enable authentication\n")
2000 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2001 int idx_ipv4_number
= 1;
2002 struct ospf_area
*area
;
2003 struct in_addr area_id
;
2006 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
2008 area
= ospf_area_get(ospf
, area_id
);
2009 ospf_area_display_format_set(ospf
, area
, format
);
2010 area
->auth_type
= OSPF_AUTH_SIMPLE
;
2015 DEFUN (no_ospf_area_authentication
,
2016 no_ospf_area_authentication_cmd
,
2017 "no area <A.B.C.D|(0-4294967295)> authentication",
2019 "OSPF area parameters\n"
2020 "OSPF area ID in IP address format\n"
2021 "OSPF area ID as a decimal value\n"
2022 "Enable authentication\n")
2024 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2025 int idx_ipv4_number
= 2;
2026 struct ospf_area
*area
;
2027 struct in_addr area_id
;
2030 VTY_GET_OSPF_AREA_ID(area_id
, format
, argv
[idx_ipv4_number
]->arg
);
2032 area
= ospf_area_lookup_by_area_id(ospf
, area_id
);
2036 area
->auth_type
= OSPF_AUTH_NULL
;
2038 ospf_area_check_free(ospf
, area_id
);
2044 DEFUN (ospf_abr_type
,
2046 "ospf abr-type <cisco|ibm|shortcut|standard>",
2047 "OSPF specific commands\n"
2048 "Set OSPF ABR type\n"
2049 "Alternative ABR, cisco implementation\n"
2050 "Alternative ABR, IBM implementation\n"
2052 "Standard behavior (RFC2328)\n")
2054 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2056 u_char abr_type
= OSPF_ABR_UNKNOWN
;
2058 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2059 abr_type
= OSPF_ABR_CISCO
;
2060 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2061 abr_type
= OSPF_ABR_IBM
;
2062 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2063 abr_type
= OSPF_ABR_SHORTCUT
;
2064 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2065 abr_type
= OSPF_ABR_STAND
;
2067 return CMD_WARNING_CONFIG_FAILED
;
2069 /* If ABR type value is changed, schedule ABR task. */
2070 if (ospf
->abr_type
!= abr_type
) {
2071 ospf
->abr_type
= abr_type
;
2072 ospf_schedule_abr_task(ospf
);
2078 DEFUN (no_ospf_abr_type
,
2079 no_ospf_abr_type_cmd
,
2080 "no ospf abr-type <cisco|ibm|shortcut|standard>",
2082 "OSPF specific commands\n"
2083 "Set OSPF ABR type\n"
2084 "Alternative ABR, cisco implementation\n"
2085 "Alternative ABR, IBM implementation\n"
2089 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2091 u_char abr_type
= OSPF_ABR_UNKNOWN
;
2093 if (strncmp(argv
[idx_vendor
]->arg
, "c", 1) == 0)
2094 abr_type
= OSPF_ABR_CISCO
;
2095 else if (strncmp(argv
[idx_vendor
]->arg
, "i", 1) == 0)
2096 abr_type
= OSPF_ABR_IBM
;
2097 else if (strncmp(argv
[idx_vendor
]->arg
, "sh", 2) == 0)
2098 abr_type
= OSPF_ABR_SHORTCUT
;
2099 else if (strncmp(argv
[idx_vendor
]->arg
, "st", 2) == 0)
2100 abr_type
= OSPF_ABR_STAND
;
2102 return CMD_WARNING_CONFIG_FAILED
;
2104 /* If ABR type value is changed, schedule ABR task. */
2105 if (ospf
->abr_type
== abr_type
) {
2106 ospf
->abr_type
= OSPF_ABR_DEFAULT
;
2107 ospf_schedule_abr_task(ospf
);
2113 DEFUN (ospf_log_adjacency_changes
,
2114 ospf_log_adjacency_changes_cmd
,
2115 "log-adjacency-changes",
2116 "Log changes in adjacency state\n")
2118 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2120 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2121 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2125 DEFUN (ospf_log_adjacency_changes_detail
,
2126 ospf_log_adjacency_changes_detail_cmd
,
2127 "log-adjacency-changes detail",
2128 "Log changes in adjacency state\n"
2129 "Log all state changes\n")
2131 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2133 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2134 SET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2138 DEFUN (no_ospf_log_adjacency_changes
,
2139 no_ospf_log_adjacency_changes_cmd
,
2140 "no log-adjacency-changes",
2142 "Log changes in adjacency state\n")
2144 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2146 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2147 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
);
2151 DEFUN (no_ospf_log_adjacency_changes_detail
,
2152 no_ospf_log_adjacency_changes_detail_cmd
,
2153 "no log-adjacency-changes detail",
2155 "Log changes in adjacency state\n"
2156 "Log all state changes\n")
2158 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2160 UNSET_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
);
2164 DEFUN (ospf_compatible_rfc1583
,
2165 ospf_compatible_rfc1583_cmd
,
2166 "compatible rfc1583",
2167 "OSPF compatibility list\n"
2168 "compatible with RFC 1583\n")
2170 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2172 if (!CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2173 SET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2174 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2179 DEFUN (no_ospf_compatible_rfc1583
,
2180 no_ospf_compatible_rfc1583_cmd
,
2181 "no compatible rfc1583",
2183 "OSPF compatibility list\n"
2184 "compatible with RFC 1583\n")
2186 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2188 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
2189 UNSET_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
);
2190 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_CONFIG_CHANGE
);
2195 ALIAS(ospf_compatible_rfc1583
, ospf_rfc1583_flag_cmd
,
2196 "ospf rfc1583compatibility",
2197 "OSPF specific commands\n"
2198 "Enable the RFC1583Compatibility flag\n")
2200 ALIAS(no_ospf_compatible_rfc1583
, no_ospf_rfc1583_flag_cmd
,
2201 "no ospf rfc1583compatibility", NO_STR
2202 "OSPF specific commands\n"
2203 "Disable the RFC1583Compatibility flag\n")
2205 static int ospf_timers_spf_set(struct vty
*vty
, unsigned int delay
,
2206 unsigned int hold
, unsigned int max
)
2208 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2210 ospf
->spf_delay
= delay
;
2211 ospf
->spf_holdtime
= hold
;
2212 ospf
->spf_max_holdtime
= max
;
2217 DEFUN (ospf_timers_min_ls_interval
,
2218 ospf_timers_min_ls_interval_cmd
,
2219 "timers throttle lsa all (0-5000)",
2220 "Adjust routing timers\n"
2221 "Throttling adaptive timer\n"
2222 "LSA delay between transmissions\n"
2224 "Delay (msec) between sending LSAs\n")
2226 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2228 unsigned int interval
;
2231 vty_out(vty
, "Insufficient arguments\n");
2232 return CMD_WARNING_CONFIG_FAILED
;
2235 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2237 ospf
->min_ls_interval
= interval
;
2242 DEFUN (no_ospf_timers_min_ls_interval
,
2243 no_ospf_timers_min_ls_interval_cmd
,
2244 "no timers throttle lsa all [(0-5000)]",
2246 "Adjust routing timers\n"
2247 "Throttling adaptive timer\n"
2248 "LSA delay between transmissions\n"
2250 "Delay (msec) between sending LSAs\n")
2252 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2253 ospf
->min_ls_interval
= OSPF_MIN_LS_INTERVAL
;
2258 DEFUN (ospf_timers_throttle_spf
,
2259 ospf_timers_throttle_spf_cmd
,
2260 "timers throttle spf (0-600000) (0-600000) (0-600000)",
2261 "Adjust routing timers\n"
2262 "Throttling adaptive timer\n"
2264 "Delay (msec) from first change received till SPF calculation\n"
2265 "Initial hold time (msec) between consecutive SPF calculations\n"
2266 "Maximum hold time (msec)\n")
2269 int idx_number_2
= 4;
2270 int idx_number_3
= 5;
2271 unsigned int delay
, hold
, max
;
2274 vty_out(vty
, "Insufficient arguments\n");
2275 return CMD_WARNING_CONFIG_FAILED
;
2278 delay
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2279 hold
= strtoul(argv
[idx_number_2
]->arg
, NULL
, 10);
2280 max
= strtoul(argv
[idx_number_3
]->arg
, NULL
, 10);
2282 return ospf_timers_spf_set(vty
, delay
, hold
, max
);
2285 DEFUN (no_ospf_timers_throttle_spf
,
2286 no_ospf_timers_throttle_spf_cmd
,
2287 "no timers throttle spf [(0-600000)(0-600000)(0-600000)]",
2289 "Adjust routing timers\n"
2290 "Throttling adaptive timer\n"
2292 "Delay (msec) from first change received till SPF calculation\n"
2293 "Initial hold time (msec) between consecutive SPF calculations\n"
2294 "Maximum hold time (msec)\n")
2296 return ospf_timers_spf_set(vty
, OSPF_SPF_DELAY_DEFAULT
,
2297 OSPF_SPF_HOLDTIME_DEFAULT
,
2298 OSPF_SPF_MAX_HOLDTIME_DEFAULT
);
2302 DEFUN (ospf_timers_lsa_min_arrival
,
2303 ospf_timers_lsa_min_arrival_cmd
,
2304 "timers lsa min-arrival (0-600000)",
2305 "Adjust routing timers\n"
2307 "Minimum delay in receiving new version of a LSA\n"
2308 "Delay in milliseconds\n")
2310 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2311 ospf
->min_ls_arrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2315 DEFUN (no_ospf_timers_lsa_min_arrival
,
2316 no_ospf_timers_lsa_min_arrival_cmd
,
2317 "no timers lsa min-arrival [(0-600000)]",
2319 "Adjust routing timers\n"
2321 "Minimum delay in receiving new version of a LSA\n"
2322 "Delay in milliseconds\n")
2324 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2325 unsigned int minarrival
;
2328 minarrival
= strtoul(argv
[argc
- 1]->arg
, NULL
, 10);
2330 if (ospf
->min_ls_arrival
!= minarrival
2331 || minarrival
== OSPF_MIN_LS_ARRIVAL
)
2335 ospf
->min_ls_arrival
= OSPF_MIN_LS_ARRIVAL
;
2340 #if CONFDATE > 20180708
2341 CPP_NOTICE("ospf: `timers lsa arrival (0-1000)` deprecated 2017/07/08")
2343 ALIAS_HIDDEN (ospf_timers_lsa_min_arrival
,
2344 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 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
,
2355 no_ospf_timers_lsa_arrival_cmd
,
2356 "no timers lsa arrival (0-1000)",
2358 "adjust routing timers\n"
2359 "throttling link state advertisement delays\n"
2360 "ospf minimum arrival interval delay\n"
2361 "delay (msec) between accepted lsas\n");
2364 DEFUN (ospf_neighbor
,
2366 "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]",
2368 "Neighbor IP address\n"
2369 "Neighbor Priority\n"
2371 "Dead Neighbor Polling interval\n"
2374 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2378 struct in_addr nbr_addr
;
2379 unsigned int priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2380 unsigned int interval
= OSPF_POLL_INTERVAL_DEFAULT
;
2382 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2383 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2384 return CMD_WARNING_CONFIG_FAILED
;
2388 priority
= strtoul(argv
[idx_pri
]->arg
, NULL
, 10);
2391 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2393 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2396 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2399 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2404 DEFUN (ospf_neighbor_poll_interval
,
2405 ospf_neighbor_poll_interval_cmd
,
2406 "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2408 "Neighbor IP address\n"
2409 "Dead Neighbor Polling interval\n"
2411 "OSPF priority of non-broadcast neighbor\n"
2414 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2418 struct in_addr nbr_addr
;
2419 unsigned int priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
2420 unsigned int interval
= OSPF_POLL_INTERVAL_DEFAULT
;
2422 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2423 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2424 return CMD_WARNING_CONFIG_FAILED
;
2427 interval
= strtoul(argv
[idx_poll
]->arg
, NULL
, 10);
2430 priority
= strtoul(argv
[idx_pri
]->arg
, NULL
, 10);
2432 ospf_nbr_nbma_set(ospf
, nbr_addr
);
2433 ospf_nbr_nbma_poll_interval_set(ospf
, nbr_addr
, interval
);
2436 ospf_nbr_nbma_priority_set(ospf
, nbr_addr
, priority
);
2441 DEFUN (no_ospf_neighbor
,
2442 no_ospf_neighbor_cmd
,
2443 "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]",
2446 "Neighbor IP address\n"
2447 "Neighbor Priority\n"
2449 "Dead Neighbor Polling interval\n"
2452 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2454 struct in_addr nbr_addr
;
2456 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2457 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2458 return CMD_WARNING_CONFIG_FAILED
;
2461 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2466 DEFUN (no_ospf_neighbor_poll
,
2467 no_ospf_neighbor_poll_cmd
,
2468 "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2471 "Neighbor IP address\n"
2472 "Dead Neighbor Polling interval\n"
2474 "Neighbor Priority\n"
2477 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2479 struct in_addr nbr_addr
;
2481 if (!inet_aton(argv
[idx_ipv4
]->arg
, &nbr_addr
)) {
2482 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
2483 return CMD_WARNING_CONFIG_FAILED
;
2486 (void)ospf_nbr_nbma_unset(ospf
, nbr_addr
);
2491 DEFUN (ospf_refresh_timer
,
2492 ospf_refresh_timer_cmd
,
2493 "refresh timer (10-1800)",
2494 "Adjust refresh parameters\n"
2495 "Set refresh timer\n"
2496 "Timer value in seconds\n")
2498 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2500 unsigned int interval
;
2502 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2503 interval
= (interval
/ OSPF_LSA_REFRESHER_GRANULARITY
)
2504 * OSPF_LSA_REFRESHER_GRANULARITY
;
2506 ospf_timers_refresh_set(ospf
, interval
);
2511 DEFUN (no_ospf_refresh_timer
,
2512 no_ospf_refresh_timer_val_cmd
,
2513 "no refresh timer [(10-1800)]",
2515 "Adjust refresh parameters\n"
2516 "Unset refresh timer\n"
2517 "Timer value in seconds\n")
2519 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2521 unsigned int interval
;
2524 interval
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2526 if (ospf
->lsa_refresh_interval
!= interval
2527 || interval
== OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
2531 ospf_timers_refresh_unset(ospf
);
2537 DEFUN (ospf_auto_cost_reference_bandwidth
,
2538 ospf_auto_cost_reference_bandwidth_cmd
,
2539 "auto-cost reference-bandwidth (1-4294967)",
2540 "Calculate OSPF interface cost according to bandwidth\n"
2541 "Use reference bandwidth method to assign OSPF cost\n"
2542 "The reference bandwidth in terms of Mbits per second\n")
2544 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2545 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2548 struct interface
*ifp
;
2550 refbw
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2551 if (refbw
< 1 || refbw
> 4294967) {
2552 vty_out(vty
, "reference-bandwidth value is invalid\n");
2553 return CMD_WARNING_CONFIG_FAILED
;
2556 /* If reference bandwidth is changed. */
2557 if ((refbw
) == ospf
->ref_bandwidth
)
2560 ospf
->ref_bandwidth
= refbw
;
2561 FOR_ALL_INTERFACES (vrf
, ifp
)
2562 ospf_if_recalculate_output_cost(ifp
);
2567 DEFUN (no_ospf_auto_cost_reference_bandwidth
,
2568 no_ospf_auto_cost_reference_bandwidth_cmd
,
2569 "no auto-cost reference-bandwidth [(1-4294967)]",
2571 "Calculate OSPF interface cost according to bandwidth\n"
2572 "Use reference bandwidth method to assign OSPF cost\n"
2573 "The reference bandwidth in terms of Mbits per second\n")
2575 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2576 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
2577 struct interface
*ifp
;
2579 if (ospf
->ref_bandwidth
== OSPF_DEFAULT_REF_BANDWIDTH
)
2582 ospf
->ref_bandwidth
= OSPF_DEFAULT_REF_BANDWIDTH
;
2583 vty_out(vty
, "%% OSPF: Reference bandwidth is changed.\n");
2585 " Please ensure reference bandwidth is consistent across all routers\n");
2587 FOR_ALL_INTERFACES (vrf
, ifp
)
2588 ospf_if_recalculate_output_cost(ifp
);
2593 DEFUN (ospf_write_multiplier
,
2594 ospf_write_multiplier_cmd
,
2595 "ospf write-multiplier (1-100)",
2596 "OSPF specific commands\n"
2597 "Write multiplier\n"
2598 "Maximum number of interface serviced per write\n")
2600 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2602 u_int32_t write_oi_count
;
2609 write_oi_count
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2610 if (write_oi_count
< 1 || write_oi_count
> 100) {
2611 vty_out(vty
, "write-multiplier value is invalid\n");
2612 return CMD_WARNING_CONFIG_FAILED
;
2615 ospf
->write_oi_count
= write_oi_count
;
2619 ALIAS(ospf_write_multiplier
, write_multiplier_cmd
, "write-multiplier (1-100)",
2620 "Write multiplier\n"
2621 "Maximum number of interface serviced per write\n")
2623 DEFUN (no_ospf_write_multiplier
,
2624 no_ospf_write_multiplier_cmd
,
2625 "no ospf write-multiplier (1-100)",
2627 "OSPF specific commands\n"
2628 "Write multiplier\n"
2629 "Maximum number of interface serviced per write\n")
2631 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
2633 ospf
->write_oi_count
= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
;
2637 ALIAS(no_ospf_write_multiplier
, no_write_multiplier_cmd
,
2638 "no write-multiplier (1-100)", NO_STR
2639 "Write multiplier\n"
2640 "Maximum number of interface serviced per write\n")
2642 const char *ospf_abr_type_descr_str
[] = {"Unknown", "Standard (RFC2328)",
2643 "Alternative IBM", "Alternative Cisco",
2644 "Alternative Shortcut"};
2646 const char *ospf_shortcut_mode_descr_str
[] = {"Default", "Enabled", "Disabled"};
2648 static void show_ip_ospf_area(struct vty
*vty
, struct ospf_area
*area
,
2649 json_object
*json_areas
, u_char use_json
)
2651 json_object
*json_area
= NULL
;
2654 json_area
= json_object_new_object();
2658 vty_out(vty
, " Area ID: %s", inet_ntoa(area
->area_id
));
2660 /* Show Area type/mode. */
2661 if (OSPF_IS_AREA_BACKBONE(area
)) {
2663 json_object_boolean_true_add(json_area
, "backbone");
2665 vty_out(vty
, " (Backbone)\n");
2668 if (area
->external_routing
== OSPF_AREA_STUB
) {
2669 if (area
->no_summary
)
2670 json_object_boolean_true_add(
2671 json_area
, "stubNoSummary");
2672 if (area
->shortcut_configured
)
2673 json_object_boolean_true_add(
2674 json_area
, "stubShortcut");
2675 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
2676 if (area
->no_summary
)
2677 json_object_boolean_true_add(
2678 json_area
, "nssaNoSummary");
2679 if (area
->shortcut_configured
)
2680 json_object_boolean_true_add(
2681 json_area
, "nssaShortcut");
2684 json_object_string_add(
2685 json_area
, "shortcuttingMode",
2686 ospf_shortcut_mode_descr_str
2687 [area
->shortcut_configured
]);
2688 if (area
->shortcut_capability
)
2689 json_object_boolean_true_add(json_area
,
2692 if (area
->external_routing
== OSPF_AREA_STUB
)
2693 vty_out(vty
, " (Stub%s%s)",
2694 area
->no_summary
? ", no summary" : "",
2695 area
->shortcut_configured
? "; " : "");
2696 else if (area
->external_routing
== OSPF_AREA_NSSA
)
2697 vty_out(vty
, " (NSSA%s%s)",
2698 area
->no_summary
? ", no summary" : "",
2699 area
->shortcut_configured
? "; " : "");
2702 vty_out(vty
, " Shortcutting mode: %s",
2703 ospf_shortcut_mode_descr_str
2704 [area
->shortcut_configured
]);
2705 vty_out(vty
, ", S-bit consensus: %s\n",
2706 area
->shortcut_capability
? "ok" : "no");
2710 /* Show number of interfaces */
2712 json_object_int_add(json_area
, "areaIfTotalCounter",
2713 listcount(area
->oiflist
));
2714 json_object_int_add(json_area
, "areaIfActiveCounter",
2718 " Number of interfaces in this area: Total: %d, "
2720 listcount(area
->oiflist
), area
->act_ints
);
2722 if (area
->external_routing
== OSPF_AREA_NSSA
) {
2724 json_object_boolean_true_add(json_area
, "nssa");
2725 if (!IS_OSPF_ABR(area
->ospf
))
2726 json_object_boolean_false_add(json_area
, "abr");
2727 else if (area
->NSSATranslatorState
) {
2728 json_object_boolean_true_add(json_area
, "abr");
2729 if (area
->NSSATranslatorRole
2730 == OSPF_NSSA_ROLE_CANDIDATE
)
2731 json_object_boolean_true_add(
2733 "nssaTranslatorElected");
2734 else if (area
->NSSATranslatorRole
2735 == OSPF_NSSA_ROLE_ALWAYS
)
2736 json_object_boolean_true_add(
2738 "nssaTranslatorAlways");
2740 json_object_boolean_true_add(json_area
, "abr");
2741 if (area
->NSSATranslatorRole
2742 == OSPF_NSSA_ROLE_CANDIDATE
)
2743 json_object_boolean_false_add(
2745 "nssaTranslatorElected");
2747 json_object_boolean_true_add(
2749 "nssaTranslatorNever");
2753 " It is an NSSA configuration. \n Elected NSSA/ABR performs type-7/type-5 LSA translation. \n");
2754 if (!IS_OSPF_ABR(area
->ospf
))
2756 " It is not ABR, therefore not Translator. \n");
2757 else if (area
->NSSATranslatorState
) {
2758 vty_out(vty
, " We are an ABR and ");
2759 if (area
->NSSATranslatorRole
2760 == OSPF_NSSA_ROLE_CANDIDATE
)
2762 "the NSSA Elected Translator. \n");
2763 else if (area
->NSSATranslatorRole
2764 == OSPF_NSSA_ROLE_ALWAYS
)
2766 "always an NSSA Translator. \n");
2768 vty_out(vty
, " We are an ABR, but ");
2769 if (area
->NSSATranslatorRole
2770 == OSPF_NSSA_ROLE_CANDIDATE
)
2772 "not the NSSA Elected Translator. \n");
2775 "never an NSSA Translator. \n");
2780 /* Stub-router state for this area */
2781 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
)) {
2782 char timebuf
[OSPF_TIME_DUMP_SIZE
];
2785 json_object_boolean_true_add(
2786 json_area
, "originStubMaxDistRouterLsa");
2787 if (CHECK_FLAG(area
->stub_router_state
,
2788 OSPF_AREA_ADMIN_STUB_ROUTED
))
2789 json_object_boolean_true_add(
2790 json_area
, "indefiniteActiveAdmin");
2791 if (area
->t_stub_router
) {
2795 &area
->t_stub_router
->u
.sands
,
2798 json_object_int_add(
2800 "activeStartupRemainderMsecs",
2805 " Originating stub / maximum-distance Router-LSA\n");
2806 if (CHECK_FLAG(area
->stub_router_state
,
2807 OSPF_AREA_ADMIN_STUB_ROUTED
))
2809 " Administratively activated (indefinitely)\n");
2810 if (area
->t_stub_router
)
2812 " Active from startup, %s remaining\n",
2813 ospf_timer_dump(area
->t_stub_router
,
2820 /* Show number of fully adjacent neighbors. */
2821 json_object_int_add(json_area
, "nbrFullAdjacentCounter",
2824 /* Show authentication type. */
2825 if (area
->auth_type
== OSPF_AUTH_NULL
)
2826 json_object_string_add(json_area
, "authentication",
2827 "authenticationNone");
2828 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2829 json_object_string_add(json_area
, "authentication",
2830 "authenticationSimplePassword");
2831 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2832 json_object_string_add(json_area
, "authentication",
2833 "authenticationMessageDigest");
2835 if (!OSPF_IS_AREA_BACKBONE(area
))
2836 json_object_int_add(json_area
,
2837 "virtualAdjacenciesPassingCounter",
2840 /* Show SPF calculation times. */
2841 json_object_int_add(json_area
, "spfExecutedCounter",
2842 area
->spf_calculation
);
2843 json_object_int_add(json_area
, "lsaNumber", area
->lsdb
->total
);
2844 json_object_int_add(
2845 json_area
, "lsaRouterNumber",
2846 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
));
2847 json_object_int_add(
2848 json_area
, "lsaRouterChecksum",
2849 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
2850 json_object_int_add(
2851 json_area
, "lsaNetworkNumber",
2852 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
));
2853 json_object_int_add(
2854 json_area
, "lsaNetworkChecksum",
2855 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
2856 json_object_int_add(
2857 json_area
, "lsaSummaryNumber",
2858 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
));
2859 json_object_int_add(
2860 json_area
, "lsaSummaryChecksum",
2861 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
2862 json_object_int_add(
2863 json_area
, "lsaAsbrNumber",
2864 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2865 json_object_int_add(
2866 json_area
, "lsaAsbrChecksum",
2867 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2868 json_object_int_add(
2869 json_area
, "lsaNssaNumber",
2870 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2871 json_object_int_add(
2872 json_area
, "lsaNssaChecksum",
2873 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2875 /* Show number of fully adjacent neighbors. */
2877 " Number of fully adjacent neighbors in this area:"
2881 /* Show authentication type. */
2882 vty_out(vty
, " Area has ");
2883 if (area
->auth_type
== OSPF_AUTH_NULL
)
2884 vty_out(vty
, "no authentication\n");
2885 else if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
2886 vty_out(vty
, "simple password authentication\n");
2887 else if (area
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
2888 vty_out(vty
, "message digest authentication\n");
2890 if (!OSPF_IS_AREA_BACKBONE(area
))
2892 " Number of full virtual adjacencies going through"
2896 /* Show SPF calculation times. */
2897 vty_out(vty
, " SPF algorithm executed %d times\n",
2898 area
->spf_calculation
);
2900 /* Show number of LSA. */
2901 vty_out(vty
, " Number of LSA %ld\n", area
->lsdb
->total
);
2903 " Number of router LSA %ld. Checksum Sum 0x%08x\n",
2904 ospf_lsdb_count(area
->lsdb
, OSPF_ROUTER_LSA
),
2905 ospf_lsdb_checksum(area
->lsdb
, OSPF_ROUTER_LSA
));
2907 " Number of network LSA %ld. Checksum Sum 0x%08x\n",
2908 ospf_lsdb_count(area
->lsdb
, OSPF_NETWORK_LSA
),
2909 ospf_lsdb_checksum(area
->lsdb
, OSPF_NETWORK_LSA
));
2911 " Number of summary LSA %ld. Checksum Sum 0x%08x\n",
2912 ospf_lsdb_count(area
->lsdb
, OSPF_SUMMARY_LSA
),
2913 ospf_lsdb_checksum(area
->lsdb
, OSPF_SUMMARY_LSA
));
2915 " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n",
2916 ospf_lsdb_count(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
),
2917 ospf_lsdb_checksum(area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
));
2918 vty_out(vty
, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n",
2919 ospf_lsdb_count(area
->lsdb
, OSPF_AS_NSSA_LSA
),
2920 ospf_lsdb_checksum(area
->lsdb
, OSPF_AS_NSSA_LSA
));
2924 json_object_int_add(
2925 json_area
, "lsaOpaqueLinkNumber",
2926 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
2927 json_object_int_add(
2928 json_area
, "lsaOpaqueLinkChecksum",
2929 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
2930 json_object_int_add(
2931 json_area
, "lsaOpaqueAreaNumber",
2932 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
2933 json_object_int_add(
2934 json_area
, "lsaOpaqueAreaChecksum",
2935 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
2938 " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n",
2939 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
),
2940 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_LINK_LSA
));
2942 " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n",
2943 ospf_lsdb_count(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
),
2944 ospf_lsdb_checksum(area
->lsdb
, OSPF_OPAQUE_AREA_LSA
));
2948 json_object_object_add(json_areas
, inet_ntoa(area
->area_id
),
2954 static int show_ip_ospf_common(struct vty
*vty
, struct ospf
*ospf
,
2955 json_object
*json
, u_char use_vrf
)
2957 struct listnode
*node
, *nnode
;
2958 struct ospf_area
*area
;
2959 struct timeval result
;
2960 char timebuf
[OSPF_TIME_DUMP_SIZE
];
2961 json_object
*json_vrf
= NULL
;
2962 json_object
*json_areas
= NULL
;
2966 json_vrf
= json_object_new_object();
2969 json_areas
= json_object_new_object();
2972 if (ospf
->instance
) {
2974 json_object_int_add(json
, "ospfInstance",
2977 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
2981 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
2983 /* Show Router ID. */
2985 json_object_string_add(json_vrf
, "routerId",
2986 inet_ntoa(ospf
->router_id
));
2988 vty_out(vty
, " OSPF Routing Process, Router ID: %s\n",
2989 inet_ntoa(ospf
->router_id
));
2992 /* Graceful shutdown */
2993 if (ospf
->t_deferred_shutdown
) {
2998 &ospf
->t_deferred_shutdown
->u
.sands
,
3001 json_object_int_add(json_vrf
, "deferredShutdownMsecs",
3005 " Deferred shutdown in progress, %s remaining\n",
3006 ospf_timer_dump(ospf
->t_deferred_shutdown
,
3007 timebuf
, sizeof(timebuf
)));
3011 /* Show capability. */
3013 json_object_boolean_true_add(json_vrf
, "tosRoutesOnly");
3014 json_object_boolean_true_add(json_vrf
, "rfc2328Conform");
3015 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)) {
3016 json_object_boolean_true_add(json_vrf
,
3017 "rfc1583Compatibility");
3020 vty_out(vty
, " Supports only single TOS (TOS0) routes\n");
3021 vty_out(vty
, " This implementation conforms to RFC2328\n");
3022 vty_out(vty
, " RFC1583Compatibility flag is %s\n",
3023 CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
)
3029 if (CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)) {
3030 json_object_boolean_true_add(json_vrf
, "opaqueCapable");
3033 vty_out(vty
, " OpaqueCapability flag is %s\n",
3034 CHECK_FLAG(ospf
->config
, OSPF_OPAQUE_CAPABLE
)
3039 /* Show stub-router configuration */
3040 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
3041 || ospf
->stub_router_shutdown_time
3042 != OSPF_STUB_ROUTER_UNCONFIGURED
) {
3044 json_object_boolean_true_add(json_vrf
,
3045 "stubAdvertisement");
3046 if (ospf
->stub_router_startup_time
3047 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3048 json_object_int_add(
3049 json_vrf
, "postStartEnabledMsecs",
3050 ospf
->stub_router_startup_time
/ 1000);
3051 if (ospf
->stub_router_shutdown_time
3052 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3053 json_object_int_add(
3054 json_vrf
, "preShutdownEnabledMsecs",
3055 ospf
->stub_router_shutdown_time
/ 1000);
3058 " Stub router advertisement is configured\n");
3059 if (ospf
->stub_router_startup_time
3060 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3062 " Enabled for %us after start-up\n",
3063 ospf
->stub_router_startup_time
);
3064 if (ospf
->stub_router_shutdown_time
3065 != OSPF_STUB_ROUTER_UNCONFIGURED
)
3067 " Enabled for %us prior to full shutdown\n",
3068 ospf
->stub_router_shutdown_time
);
3072 /* Show SPF timers. */
3074 json_object_int_add(json_vrf
, "spfScheduleDelayMsecs",
3076 json_object_int_add(json_vrf
, "holdtimeMinMsecs",
3077 ospf
->spf_holdtime
);
3078 json_object_int_add(json_vrf
, "holdtimeMaxMsecs",
3079 ospf
->spf_max_holdtime
);
3080 json_object_int_add(json_vrf
, "holdtimeMultplier",
3081 ospf
->spf_hold_multiplier
);
3084 " Initial SPF scheduling delay %d millisec(s)\n"
3085 " Minimum hold time between consecutive SPFs %d millisec(s)\n"
3086 " Maximum hold time between consecutive SPFs %d millisec(s)\n"
3087 " Hold time multiplier is currently %d\n",
3088 ospf
->spf_delay
, ospf
->spf_holdtime
,
3089 ospf
->spf_max_holdtime
, ospf
->spf_hold_multiplier
);
3093 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3094 long time_store
= 0;
3097 monotime_since(&ospf
->ts_spf
, NULL
) / 1000LL;
3098 json_object_int_add(json_vrf
, "spfLastExecutedMsecs",
3101 time_store
= (1000 * ospf
->ts_spf_duration
.tv_sec
)
3102 + (ospf
->ts_spf_duration
.tv_usec
/ 1000);
3103 json_object_int_add(json_vrf
, "spfLastDurationMsecs",
3106 json_object_boolean_true_add(json_vrf
, "spfHasNotRun");
3108 vty_out(vty
, " SPF algorithm ");
3109 if (ospf
->ts_spf
.tv_sec
|| ospf
->ts_spf
.tv_usec
) {
3110 monotime_since(&ospf
->ts_spf
, &result
);
3111 vty_out(vty
, "last executed %s ago\n",
3112 ospf_timeval_dump(&result
, timebuf
,
3114 vty_out(vty
, " Last SPF duration %s\n",
3115 ospf_timeval_dump(&ospf
->ts_spf_duration
,
3116 timebuf
, sizeof(timebuf
)));
3118 vty_out(vty
, "has not been run\n");
3122 if (ospf
->t_spf_calc
) {
3125 monotime_until(&ospf
->t_spf_calc
->u
.sands
, NULL
)
3127 json_object_int_add(json_vrf
, "spfTimerDueInMsecs",
3131 json_object_int_add(json_vrf
, "lsaMinIntervalMsecs",
3132 ospf
->min_ls_interval
);
3133 json_object_int_add(json_vrf
, "lsaMinArrivalMsecs",
3134 ospf
->min_ls_arrival
);
3135 /* Show write multiplier values */
3136 json_object_int_add(json_vrf
, "writeMultiplier",
3137 ospf
->write_oi_count
);
3138 /* Show refresh parameters. */
3139 json_object_int_add(json_vrf
, "refreshTimerMsecs",
3140 ospf
->lsa_refresh_interval
* 1000);
3142 vty_out(vty
, " SPF timer %s%s\n",
3143 (ospf
->t_spf_calc
? "due in " : "is "),
3144 ospf_timer_dump(ospf
->t_spf_calc
, timebuf
,
3147 vty_out(vty
, " LSA minimum interval %d msecs\n",
3148 ospf
->min_ls_interval
);
3149 vty_out(vty
, " LSA minimum arrival %d msecs\n",
3150 ospf
->min_ls_arrival
);
3152 /* Show write multiplier values */
3153 vty_out(vty
, " Write Multiplier set to %d \n",
3154 ospf
->write_oi_count
);
3156 /* Show refresh parameters. */
3157 vty_out(vty
, " Refresh timer %d secs\n",
3158 ospf
->lsa_refresh_interval
);
3161 /* Show ABR/ASBR flags. */
3162 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ABR
)) {
3164 json_object_string_add(
3165 json_vrf
, "abrType",
3166 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3169 " This router is an ABR, ABR type is: %s\n",
3170 ospf_abr_type_descr_str
[ospf
->abr_type
]);
3172 if (CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ASBR
)) {
3174 json_object_string_add(
3175 json_vrf
, "asbrRouter",
3176 "injectingExternalRoutingInformation");
3179 " This router is an ASBR "
3180 "(injecting external routing information)\n");
3183 /* Show Number of AS-external-LSAs. */
3185 json_object_int_add(
3186 json_vrf
, "lsaExternalCounter",
3187 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3188 json_object_int_add(
3189 json_vrf
, "lsaExternalChecksum",
3190 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3193 " Number of external LSA %ld. Checksum Sum 0x%08x\n",
3194 ospf_lsdb_count(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
),
3195 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
));
3199 json_object_int_add(
3200 json_vrf
, "lsaAsopaqueCounter",
3201 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3202 json_object_int_add(
3203 json_vrf
, "lsaAsOpaqueChecksum",
3204 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3207 " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n",
3208 ospf_lsdb_count(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
),
3209 ospf_lsdb_checksum(ospf
->lsdb
, OSPF_OPAQUE_AS_LSA
));
3212 /* Show number of areas attached. */
3214 json_object_int_add(json_vrf
, "attachedAreaCounter",
3215 listcount(ospf
->areas
));
3217 vty_out(vty
, " Number of areas attached to this router: %d\n",
3218 listcount(ospf
->areas
));
3220 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
3221 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
)) {
3223 json_object_boolean_true_add(
3224 json_vrf
, "adjacencyChangesLoggedAll");
3227 " All adjacency changes are logged\n");
3230 json_object_boolean_true_add(
3231 json_vrf
, "adjacencyChangesLogged");
3233 vty_out(vty
, " Adjacency changes are logged\n");
3236 /* Show each area status. */
3237 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
3238 show_ip_ospf_area(vty
, area
, json_areas
, json
? 1 : 0);
3242 json_object_object_add(json_vrf
, "areas", json_areas
);
3243 if (ospf
->vrf_id
== VRF_DEFAULT
)
3244 json_object_object_add(json
, "default",
3247 json_object_object_add(json
, ospf
->name
,
3250 json_object_object_add(json
, "areas", json_areas
);
3258 DEFUN (show_ip_ospf
,
3260 "show ip ospf [vrf <NAME|all>] [json]",
3263 "OSPF information\n"
3269 u_char uj
= use_json(argc
, argv
);
3270 struct listnode
*node
= NULL
;
3271 char *vrf_name
= NULL
;
3272 bool all_vrf
= FALSE
;
3273 int ret
= CMD_SUCCESS
;
3276 json_object
*json
= NULL
;
3279 if (listcount(om
->ospf
) == 0)
3282 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
3285 json
= json_object_new_object();
3287 /* vrf input is provided could be all or specific vrf*/
3291 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
3292 if (!ospf
->oi_running
)
3294 ret
= show_ip_ospf_common(vty
, ospf
, json
,
3298 vty_out(vty
, "%s\n",
3299 json_object_to_json_string_ext(json
,
3300 JSON_C_TO_STRING_PRETTY
));
3301 json_object_free(json
);
3305 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
3306 if ((ospf
== NULL
) || !ospf
->oi_running
) {
3308 json_object_free(json
);
3312 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
3313 /* Display default ospf (instance 0) info */
3314 if (ospf
== NULL
|| !ospf
->oi_running
) {
3316 json_object_free(json
);
3322 show_ip_ospf_common(vty
, ospf
, json
, use_vrf
);
3324 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
3325 json
, JSON_C_TO_STRING_PRETTY
));
3329 json_object_free(json
);
3334 DEFUN (show_ip_ospf_instance
,
3335 show_ip_ospf_instance_cmd
,
3336 "show ip ospf (1-65535) [json]",
3339 "OSPF information\n"
3345 u_short instance
= 0;
3346 u_char uj
= use_json(argc
, argv
);
3347 int ret
= CMD_SUCCESS
;
3348 json_object
*json
= NULL
;
3350 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
3351 ospf
= ospf_lookup_instance(instance
);
3353 return CMD_NOT_MY_INSTANCE
;
3355 if (!ospf
->oi_running
)
3359 json
= json_object_new_object();
3361 ret
= show_ip_ospf_common(vty
, ospf
, json
, 0);
3364 vty_out(vty
, "%s\n", json_object_to_json_string_ext(json
,
3365 JSON_C_TO_STRING_PRETTY
));
3366 json_object_free(json
);
3372 static void show_ip_ospf_interface_sub(struct vty
*vty
, struct ospf
*ospf
,
3373 struct interface
*ifp
,
3374 json_object
*json_interface_sub
,
3378 struct ospf_neighbor
*nbr
;
3379 struct route_node
*rn
;
3380 uint32_t bandwidth
= ifp
->bandwidth
? ifp
->bandwidth
: ifp
->speed
;
3382 /* Is interface up? */
3384 is_up
= if_is_operative(ifp
);
3386 json_object_boolean_true_add(json_interface_sub
,
3389 json_object_boolean_false_add(json_interface_sub
,
3392 json_object_int_add(json_interface_sub
, "ifIndex",
3394 json_object_int_add(json_interface_sub
, "mtuBytes", ifp
->mtu
);
3395 json_object_int_add(json_interface_sub
, "bandwidthMbit",
3397 json_object_string_add(json_interface_sub
, "ifFlags",
3398 if_flag_dump(ifp
->flags
));
3400 vty_out(vty
, "%s is %s\n", ifp
->name
,
3401 ((is_up
= if_is_operative(ifp
)) ? "up" : "down"));
3402 vty_out(vty
, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n",
3403 ifp
->ifindex
, ifp
->mtu
, bandwidth
,
3404 if_flag_dump(ifp
->flags
));
3407 /* Is interface OSPF enabled? */
3409 if (ospf_oi_count(ifp
) == 0) {
3410 json_object_boolean_false_add(json_interface_sub
,
3413 } else if (!is_up
) {
3414 json_object_boolean_false_add(json_interface_sub
,
3418 json_object_boolean_true_add(json_interface_sub
,
3421 if (ospf_oi_count(ifp
) == 0) {
3422 vty_out(vty
, " OSPF not enabled on this interface\n");
3424 } else if (!is_up
) {
3426 " OSPF is enabled, but not running on this interface\n");
3431 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
3432 struct ospf_interface
*oi
= rn
->info
;
3437 if (CHECK_FLAG(oi
->connected
->flags
, ZEBRA_IFA_UNNUMBERED
)) {
3439 json_object_boolean_true_add(json_interface_sub
,
3442 vty_out(vty
, " This interface is UNNUMBERED,");
3444 /* Show OSPF interface information. */
3446 json_object_string_add(
3447 json_interface_sub
, "ipAddress",
3448 inet_ntoa(oi
->address
->u
.prefix4
));
3449 json_object_int_add(json_interface_sub
,
3450 "ipAddressPrefixlen",
3451 oi
->address
->prefixlen
);
3453 vty_out(vty
, " Internet Address %s/%d,",
3454 inet_ntoa(oi
->address
->u
.prefix4
),
3455 oi
->address
->prefixlen
);
3457 if (oi
->connected
->destination
3458 || oi
->type
== OSPF_IFTYPE_VIRTUALLINK
) {
3459 struct in_addr
*dest
;
3462 if (CONNECTED_PEER(oi
->connected
)
3463 || oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3468 /* For Vlinks, showing the peer address is
3470 * * * * * informative than the local
3471 * interface that is being used
3473 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3474 dest
= &oi
->vl_data
->peer_addr
;
3476 dest
= &oi
->connected
->destination
->u
3480 json_object_string_add(
3482 "ospfIfType", dstr
);
3483 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3484 json_object_string_add(
3489 json_object_string_add(
3494 vty_out(vty
, " %s %s,", dstr
,
3499 json_object_string_add(json_interface_sub
, "area",
3500 ospf_area_desc_string(oi
->area
));
3501 if (OSPF_IF_PARAM(oi
, mtu_ignore
))
3502 json_object_boolean_true_add(
3504 "mtuMismatchDetect");
3505 json_object_string_add(json_interface_sub
, "routerId",
3506 inet_ntoa(ospf
->router_id
));
3507 json_object_string_add(json_interface_sub
,
3509 ospf_network_type_str
[oi
->type
]);
3510 json_object_int_add(json_interface_sub
, "cost",
3512 json_object_int_add(
3513 json_interface_sub
, "transmitDelayMsecs",
3514 1000 / OSPF_IF_PARAM(oi
, transmit_delay
));
3515 json_object_string_add(json_interface_sub
, "state",
3516 lookup_msg(ospf_ism_state_msg
,
3518 json_object_int_add(json_interface_sub
, "priority",
3521 vty_out(vty
, " Area %s\n",
3522 ospf_area_desc_string(oi
->area
));
3524 vty_out(vty
, " MTU mismatch detection: %s\n",
3525 OSPF_IF_PARAM(oi
, mtu_ignore
) ? "disabled"
3529 " Router ID %s, Network Type %s, Cost: %d\n",
3530 inet_ntoa(ospf
->router_id
),
3531 ospf_network_type_str
[oi
->type
],
3535 " Transmit Delay is %d sec, State %s, Priority %d\n",
3536 OSPF_IF_PARAM(oi
, transmit_delay
),
3537 lookup_msg(ospf_ism_state_msg
, oi
->state
, NULL
),
3541 /* Show DR information. */
3542 if (DR(oi
).s_addr
== 0) {
3545 " No backup designated router on this network\n");
3547 nbr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &BDR(oi
));
3551 " No backup designated router on this network\n");
3554 json_object_string_add(
3555 json_interface_sub
, "bdrId",
3556 inet_ntoa(nbr
->router_id
));
3557 json_object_string_add(
3560 inet_ntoa(nbr
->address
.u
3564 " Backup Designated Router (ID) %s,",
3565 inet_ntoa(nbr
->router_id
));
3566 vty_out(vty
, " Interface Address %s\n",
3567 inet_ntoa(nbr
->address
.u
3573 /* Next network-LSA sequence number we'll use, if we're elected
3576 && ntohl(oi
->params
->network_lsa_seqnum
)
3577 != OSPF_INITIAL_SEQUENCE_NUMBER
) {
3579 json_object_int_add(
3581 "networkLsaSequence",
3582 ntohl(oi
->params
->network_lsa_seqnum
));
3585 " Saved Network-LSA sequence number 0x%x\n",
3586 ntohl(oi
->params
->network_lsa_seqnum
));
3590 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3591 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3592 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3593 json_object_boolean_true_add(
3595 "mcastMemberOspfAllRouters");
3596 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3597 json_object_boolean_true_add(
3599 "mcastMemberOspfDesignatedRouters");
3602 vty_out(vty
, " Multicast group memberships:");
3603 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
)
3604 || OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
)) {
3605 if (OI_MEMBER_CHECK(oi
, MEMBER_ALLROUTERS
))
3606 vty_out(vty
, " OSPFAllRouters");
3607 if (OI_MEMBER_CHECK(oi
, MEMBER_DROUTERS
))
3608 vty_out(vty
, " OSPFDesignatedRouters");
3610 vty_out(vty
, " <None>");
3615 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3616 json_object_int_add(
3617 json_interface_sub
, "timerMsecs",
3618 1000 / OSPF_IF_PARAM(oi
, v_hello
));
3620 json_object_int_add(
3621 json_interface_sub
, "timerMsecs",
3622 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3623 json_object_int_add(json_interface_sub
,
3625 1000 / OSPF_IF_PARAM(oi
, v_wait
));
3626 json_object_int_add(json_interface_sub
,
3628 1000 / OSPF_IF_PARAM(oi
, v_wait
));
3629 json_object_int_add(
3630 json_interface_sub
, "timerRetransmit",
3631 1000 / OSPF_IF_PARAM(oi
, retransmit_interval
));
3633 vty_out(vty
, " Timer intervals configured,");
3634 vty_out(vty
, " Hello ");
3635 if (OSPF_IF_PARAM(oi
, fast_hello
) == 0)
3636 vty_out(vty
, "%ds,",
3637 OSPF_IF_PARAM(oi
, v_hello
));
3639 vty_out(vty
, "%dms,",
3640 1000 / OSPF_IF_PARAM(oi
, fast_hello
));
3641 vty_out(vty
, " Dead %ds, Wait %ds, Retransmit %d\n",
3642 OSPF_IF_PARAM(oi
, v_wait
),
3643 OSPF_IF_PARAM(oi
, v_wait
),
3644 OSPF_IF_PARAM(oi
, retransmit_interval
));
3647 if (OSPF_IF_PASSIVE_STATUS(oi
) == OSPF_IF_ACTIVE
) {
3648 char timebuf
[OSPF_TIME_DUMP_SIZE
];
3650 long time_store
= 0;
3654 &oi
->t_hello
->u
.sands
,
3657 json_object_int_add(json_interface_sub
,
3658 "timerHelloInMsecs",
3661 vty_out(vty
, " Hello due in %s\n",
3662 ospf_timer_dump(oi
->t_hello
, timebuf
,
3664 } else /* passive-interface is set */
3667 json_object_boolean_true_add(
3669 "timerPassiveIface");
3672 " No Hellos (Passive interface)\n");
3676 json_object_int_add(json_interface_sub
, "nbrCount",
3677 ospf_nbr_count(oi
, 0));
3678 json_object_int_add(json_interface_sub
,
3680 ospf_nbr_count(oi
, NSM_Full
));
3683 " Neighbor Count is %d, Adjacent neighbor count is %d\n",
3684 ospf_nbr_count(oi
, 0),
3685 ospf_nbr_count(oi
, NSM_Full
));
3686 ospf_bfd_interface_show(vty
, ifp
, json_interface_sub
, use_json
);
3690 static int show_ip_ospf_interface_common(struct vty
*vty
, struct ospf
*ospf
,
3691 char *intf_name
, u_char use_vrf
,
3692 json_object
*json
, u_char use_json
)
3694 struct interface
*ifp
;
3695 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
3696 json_object
*json_vrf
= NULL
, *json_intf_array
= NULL
;
3697 json_object
*json_interface_sub
= NULL
, *json_interface
= NULL
;
3701 json_vrf
= json_object_new_object();
3704 json_intf_array
= json_object_new_array();
3707 if (ospf
->instance
) {
3709 json_object_int_add(json
, "ospfInstance",
3712 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
3715 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3717 if (intf_name
== NULL
) {
3719 json_object_object_add(json_vrf
, "interfaces",
3721 /* Show All Interfaces.*/
3722 FOR_ALL_INTERFACES (vrf
, ifp
) {
3723 if (ospf_oi_count(ifp
)) {
3726 json_object_new_object();
3727 json_interface_sub
=
3728 json_object_new_object();
3730 show_ip_ospf_interface_sub(vty
, ospf
, ifp
,
3735 json_object_array_add(json_intf_array
,
3737 json_object_object_add(
3738 json_interface
, ifp
->name
,
3739 json_interface_sub
);
3744 /* Interface name is specified. */
3745 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
3748 json_object_boolean_true_add(json_vrf
,
3751 vty_out(vty
, "No such interface name\n");
3754 json_interface_sub
= json_object_new_object();
3755 json_interface
= json_object_new_object();
3756 json_object_object_add(json_vrf
, "interfaces",
3760 show_ip_ospf_interface_sub(
3761 vty
, ospf
, ifp
, json_interface_sub
, use_json
);
3764 json_object_array_add(json_intf_array
,
3766 json_object_object_add(json_interface
,
3768 json_interface_sub
);
3775 if (ospf
->vrf_id
== VRF_DEFAULT
)
3776 json_object_object_add(json
, "default",
3779 json_object_object_add(json
, ospf
->name
,
3788 static void show_ip_ospf_interface_traffic_sub(struct vty
*vty
,
3789 struct ospf_interface
*oi
,
3790 json_object
*json_interface_sub
,
3794 json_object_int_add(json_interface_sub
,
3797 json_object_int_add(json_interface_sub
,
3800 json_object_int_add(json_interface_sub
,
3803 json_object_int_add(json_interface_sub
,
3806 json_object_int_add(json_interface_sub
,
3809 json_object_int_add(json_interface_sub
,
3812 json_object_int_add(json_interface_sub
,
3815 json_object_int_add(json_interface_sub
,
3818 json_object_int_add(json_interface_sub
,
3821 json_object_int_add(json_interface_sub
,
3824 json_object_int_add(json_interface_sub
,
3829 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n",
3830 oi
->ifp
->name
, oi
->hello_in
,
3832 oi
->db_desc_in
, oi
->db_desc_out
,
3833 oi
->ls_req_in
, oi
->ls_req_out
,
3834 oi
->ls_upd_in
, oi
->ls_upd_out
,
3835 oi
->ls_ack_in
, oi
->ls_ack_out
);
3839 /* OSPFv2 Packet Counters */
3840 static int show_ip_ospf_interface_traffic_common(struct vty
*vty
,
3848 struct vrf
*vrf
= NULL
;
3849 struct interface
*ifp
= NULL
;
3850 json_object
*json_vrf
= NULL
;
3851 json_object
*json_interface_sub
= NULL
;
3853 if (!use_json
&& !display_once
) {
3855 vty_out(vty
, "%-12s%-17s%-17s%-17s%-17s%-17s\n",
3856 "Interface", " HELLO", " DB-Desc", " LS-Req",
3857 " LS-Update", " LS-Ack");
3858 vty_out(vty
, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "",
3859 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx");
3861 "--------------------------------------------------------------------------------------------\n");
3862 } else if (use_json
) {
3864 json_vrf
= json_object_new_object();
3869 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3871 if (intf_name
== NULL
) {
3872 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
3873 FOR_ALL_INTERFACES (vrf
, ifp
) {
3874 struct route_node
*rn
;
3875 struct ospf_interface
*oi
;
3877 if (ospf_oi_count(ifp
) == 0)
3880 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
3881 rn
= route_next(rn
)) {
3888 json_interface_sub
=
3889 json_object_new_object();
3892 show_ip_ospf_interface_traffic_sub(vty
, oi
,
3896 json_object_object_add(json_vrf
,
3898 json_interface_sub
);
3903 /* Interface name is specified. */
3904 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
3906 struct route_node
*rn
;
3907 struct ospf_interface
*oi
;
3909 if (ospf_oi_count(ifp
) == 0) {
3910 vty_out(vty
, " OSPF not enabled on this interface %s\n",
3915 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
3916 rn
= route_next(rn
)) {
3920 json_interface_sub
=
3921 json_object_new_object();
3924 show_ip_ospf_interface_traffic_sub(vty
, oi
,
3928 json_object_object_add(json_vrf
,
3930 json_interface_sub
);
3938 if (ospf
->vrf_id
== VRF_DEFAULT
)
3939 json_object_object_add(json
, "default",
3942 json_object_object_add(json
, ospf
->name
,
3951 DEFUN (show_ip_ospf_interface
,
3952 show_ip_ospf_interface_cmd
,
3953 "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]",
3956 "OSPF information\n"
3959 "Interface information\n"
3964 u_char uj
= use_json(argc
, argv
);
3965 struct listnode
*node
= NULL
;
3966 char *vrf_name
= NULL
, *intf_name
= NULL
;
3967 bool all_vrf
= FALSE
;
3968 int ret
= CMD_SUCCESS
;
3970 int idx_vrf
= 0, idx_intf
= 0;
3972 json_object
*json
= NULL
;
3974 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
3976 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
3977 intf_name
= argv
[idx_intf
]->arg
;
3980 json
= json_object_new_object();
3982 /* vrf input is provided could be all or specific vrf*/
3986 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
3987 if (!ospf
->oi_running
)
3989 ret
= show_ip_ospf_interface_common(vty
,
3998 vty_out(vty
, "%s\n",
3999 json_object_to_json_string_ext(json
,
4000 JSON_C_TO_STRING_PRETTY
));
4001 json_object_free(json
);
4006 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4007 if (ospf
== NULL
|| !ospf
->oi_running
) {
4009 json_object_free(json
);
4012 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
4016 /* Display default ospf (instance 0) info */
4017 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4018 if (ospf
== NULL
|| !ospf
->oi_running
) {
4020 json_object_free(json
);
4023 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
4028 vty_out(vty
, "%s\n", json_object_to_json_string_ext(json
,
4029 JSON_C_TO_STRING_PRETTY
));
4030 json_object_free(json
);
4036 DEFUN (show_ip_ospf_instance_interface
,
4037 show_ip_ospf_instance_interface_cmd
,
4038 "show ip ospf (1-65535) interface [INTERFACE] [json]",
4041 "OSPF information\n"
4043 "Interface information\n"
4050 u_short instance
= 0;
4051 u_char uj
= use_json(argc
, argv
);
4052 char *intf_name
= NULL
;
4053 int ret
= CMD_SUCCESS
;
4054 json_object
*json
= NULL
;
4056 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4057 ospf
= ospf_lookup_instance(instance
);
4059 return CMD_NOT_MY_INSTANCE
;
4061 if (!ospf
->oi_running
)
4065 json
= json_object_new_object();
4067 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4068 intf_name
= argv
[idx_intf
]->arg
;
4070 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
, 0, json
, uj
);
4073 vty_out(vty
, "%s\n", json_object_to_json_string_ext(json
,
4074 JSON_C_TO_STRING_PRETTY
));
4075 json_object_free(json
);
4081 DEFUN (show_ip_ospf_interface_traffic
,
4082 show_ip_ospf_interface_traffic_cmd
,
4083 "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]",
4086 "OSPF information\n"
4089 "Interface information\n"
4090 "Protocol Packet counters\n"
4094 struct ospf
*ospf
= NULL
;
4095 struct listnode
*node
= NULL
;
4096 char *vrf_name
= NULL
, *intf_name
= NULL
;
4097 bool all_vrf
= FALSE
;
4099 int idx_vrf
= 0, idx_intf
= 0;
4100 u_char uj
= use_json(argc
, argv
);
4101 json_object
*json
= NULL
;
4102 int ret
= CMD_SUCCESS
;
4103 int display_once
= 0;
4106 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4108 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4109 intf_name
= argv
[idx_intf
]->arg
;
4112 json
= json_object_new_object();
4117 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4118 if (!ospf
->oi_running
)
4121 ret
= show_ip_ospf_interface_traffic_common(vty
,
4131 vty_out(vty
, "%s\n",
4132 json_object_to_json_string_ext(json
,
4133 JSON_C_TO_STRING_PRETTY
));
4134 json_object_free(json
);
4139 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4140 if (ospf
== NULL
|| !ospf
->oi_running
) {
4142 json_object_free(json
);
4146 ret
= show_ip_ospf_interface_traffic_common(vty
, ospf
,
4151 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4152 if (ospf
== NULL
|| !ospf
->oi_running
) {
4154 json_object_free(json
);
4158 ret
= show_ip_ospf_interface_traffic_common(vty
, ospf
,
4165 vty_out(vty
, "%s\n", json_object_to_json_string_ext(json
,
4166 JSON_C_TO_STRING_PRETTY
));
4167 json_object_free(json
);
4174 static void show_ip_ospf_neighbour_header(struct vty
*vty
)
4176 vty_out(vty
, "\n%-15s %3s %-15s %9s %-15s %-20s %5s %5s %5s\n",
4177 "Neighbor ID", "Pri", "State", "Dead Time", "Address",
4178 "Interface", "RXmtL", "RqstL", "DBsmL");
4181 static void show_ip_ospf_neighbor_sub(struct vty
*vty
,
4182 struct ospf_interface
*oi
,
4183 json_object
*json
, u_char use_json
)
4185 struct route_node
*rn
;
4186 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
4188 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4189 json_object
*json_neighbor
= NULL
, *json_neigh_array
= NULL
;
4191 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
4192 if ((nbr
= rn
->info
)) {
4193 /* Do not show myself. */
4194 if (nbr
== oi
->nbr_self
)
4196 /* Down state is not shown. */
4197 if (nbr
->state
== NSM_Down
)
4200 char neigh_str
[INET_ADDRSTRLEN
];
4203 !IPV4_ADDR_SAME(&prev_nbr
->src
, &nbr
->src
)) {
4204 /* Start new neigh list */
4205 json_neigh_array
= NULL
;
4208 if (nbr
->state
== NSM_Attempt
&&
4209 nbr
->router_id
.s_addr
== 0)
4210 strlcpy(neigh_str
, "neighbor",
4214 inet_ntoa(nbr
->router_id
),
4217 json_object_object_get_ex(json
, neigh_str
,
4220 if (!json_neigh_array
) {
4221 json_neigh_array
= json_object_new_array();
4222 json_object_object_add(json
, neigh_str
,
4227 json_object_new_object();
4229 ospf_nbr_state_message(nbr
, msgbuf
, 16);
4233 time_store
= monotime_until(
4234 &nbr
->t_inactivity
->u
.sands
,
4237 json_object_int_add(json_neighbor
,
4240 json_object_string_add(json_neighbor
, "state",
4242 json_object_int_add(json_neighbor
,
4245 json_object_string_add(json_neighbor
,
4247 inet_ntoa(nbr
->src
));
4248 json_object_string_add(json_neighbor
,
4251 json_object_int_add(json_neighbor
,
4252 "retransmitCounter",
4253 ospf_ls_retransmit_count(nbr
));
4254 json_object_int_add(json_neighbor
,
4256 ospf_ls_request_count(nbr
));
4257 json_object_int_add(json_neighbor
,
4259 ospf_db_summary_count(nbr
));
4261 json_object_array_add(json_neigh_array
,
4264 ospf_nbr_state_message(nbr
, msgbuf
, 16);
4266 if (nbr
->state
== NSM_Attempt
&&
4267 nbr
->router_id
.s_addr
== 0)
4276 inet_ntoa(nbr
->router_id
),
4280 vty_out(vty
, "%9s ",
4281 ospf_timer_dump(nbr
->t_inactivity
,
4284 vty_out(vty
, "%-15s ", inet_ntoa(nbr
->src
));
4286 "%-20s %5ld %5ld %5d\n",
4288 ospf_ls_retransmit_count(nbr
),
4289 ospf_ls_request_count(nbr
),
4290 ospf_db_summary_count(nbr
));
4297 static int show_ip_ospf_neighbor_common(struct vty
*vty
, struct ospf
*ospf
,
4298 json_object
*json
, u_char use_json
,
4301 struct ospf_interface
*oi
;
4302 struct listnode
*node
;
4303 json_object
*json_vrf
= NULL
;
4307 json_vrf
= json_object_new_object();
4312 if (ospf
->instance
) {
4314 json_object_int_add(json
, "ospfInstance",
4317 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4320 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4322 show_ip_ospf_neighbour_header(vty
);
4324 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
))
4325 show_ip_ospf_neighbor_sub(vty
, oi
, json_vrf
, use_json
);
4329 if (ospf
->vrf_id
== VRF_DEFAULT
)
4330 json_object_object_add(json
, "default",
4333 json_object_object_add(json
, ospf
->name
,
4342 DEFUN (show_ip_ospf_neighbor
,
4343 show_ip_ospf_neighbor_cmd
,
4344 "show ip ospf [vrf <NAME|all>] neighbor [json]",
4347 "OSPF information\n"
4354 u_char uj
= use_json(argc
, argv
);
4355 struct listnode
*node
= NULL
;
4356 char *vrf_name
= NULL
;
4357 bool all_vrf
= FALSE
;
4358 int ret
= CMD_SUCCESS
;
4362 json_object
*json
= NULL
;
4364 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4367 json
= json_object_new_object();
4369 /* vrf input is provided could be all or specific vrf*/
4373 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4374 if (!ospf
->oi_running
)
4376 ret
= show_ip_ospf_neighbor_common(vty
, ospf
,
4382 vty_out(vty
, "%s\n",
4383 json_object_to_json_string_ext(json
,
4384 JSON_C_TO_STRING_PRETTY
));
4385 json_object_free(json
);
4391 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4392 if (ospf
== NULL
|| !ospf
->oi_running
) {
4394 json_object_free(json
);
4398 /* Display default ospf (instance 0) info */
4399 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4400 if (ospf
== NULL
|| !ospf
->oi_running
) {
4402 json_object_free(json
);
4408 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
,
4412 vty_out(vty
, "%s\n",
4413 json_object_to_json_string_ext(json
,
4414 JSON_C_TO_STRING_PRETTY
));
4419 json_object_free(json
);
4425 DEFUN (show_ip_ospf_instance_neighbor
,
4426 show_ip_ospf_instance_neighbor_cmd
,
4427 "show ip ospf (1-65535) neighbor [json]",
4430 "OSPF information\n"
4437 u_short instance
= 0;
4438 u_char uj
= use_json(argc
, argv
);
4439 json_object
*json
= NULL
;
4440 int ret
= CMD_SUCCESS
;
4442 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4443 ospf
= ospf_lookup_instance(instance
);
4445 return CMD_NOT_MY_INSTANCE
;
4447 if (!ospf
->oi_running
)
4451 json
= json_object_new_object();
4453 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
, 0);
4456 vty_out(vty
, "%s\n", json_object_to_json_string_ext(json
,
4457 JSON_C_TO_STRING_PRETTY
));
4458 json_object_free(json
);
4464 static int show_ip_ospf_neighbor_all_common(struct vty
*vty
, struct ospf
*ospf
,
4469 struct listnode
*node
;
4470 struct ospf_interface
*oi
;
4471 json_object
*json_vrf
= NULL
;
4472 json_object
*json_neighbor_sub
= NULL
;
4476 json_vrf
= json_object_new_object();
4479 json_neighbor_sub
= json_object_new_object();
4482 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4484 show_ip_ospf_neighbour_header(vty
);
4486 if (ospf
->instance
) {
4488 json_object_int_add(json_vrf
, "ospfInstance",
4491 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4494 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4495 struct listnode
*nbr_node
;
4496 struct ospf_nbr_nbma
*nbr_nbma
;
4498 show_ip_ospf_neighbor_sub(vty
, oi
, json_vrf
, use_json
);
4500 /* print Down neighbor status */
4501 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nbr_node
, nbr_nbma
)) {
4502 if (nbr_nbma
->nbr
== NULL
4503 || nbr_nbma
->nbr
->state
== NSM_Down
) {
4505 json_object_int_add(json_neighbor_sub
,
4507 nbr_nbma
->priority
);
4508 json_object_boolean_true_add(
4511 json_object_string_add(
4515 json_object_int_add(
4517 "nbrNbmaRetransmitCounter", 0);
4518 json_object_int_add(
4520 "nbrNbmaRequestCounter", 0);
4521 json_object_int_add(
4523 "nbrNbmaDbSummaryCounter", 0);
4524 json_object_object_add(
4526 inet_ntoa(nbr_nbma
->addr
),
4529 vty_out(vty
, "%-15s %3d %-15s %9s ",
4530 "-", nbr_nbma
->priority
, "Down",
4533 "%-15s %-20s %5d %5d %5d\n",
4534 inet_ntoa(nbr_nbma
->addr
),
4535 IF_NAME(oi
), 0, 0, 0);
4543 if (ospf
->vrf_id
== VRF_DEFAULT
)
4544 json_object_object_add(json
, "default",
4547 json_object_object_add(json
, ospf
->name
,
4556 DEFUN (show_ip_ospf_neighbor_all
,
4557 show_ip_ospf_neighbor_all_cmd
,
4558 "show ip ospf [vrf <NAME|all>] neighbor all [json]",
4561 "OSPF information\n"
4565 "include down status neighbor\n"
4569 u_char uj
= use_json(argc
, argv
);
4570 struct listnode
*node
= NULL
;
4571 char *vrf_name
= NULL
;
4572 bool all_vrf
= FALSE
;
4573 int ret
= CMD_SUCCESS
;
4577 json_object
*json
= NULL
;
4579 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4582 json
= json_object_new_object();
4584 /* vrf input is provided could be all or specific vrf*/
4588 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4589 if (!ospf
->oi_running
)
4591 ret
= show_ip_ospf_neighbor_all_common(vty
,
4599 vty_out(vty
, "%s\n",
4600 json_object_to_json_string_ext(json
,
4601 JSON_C_TO_STRING_PRETTY
));
4602 json_object_free(json
);
4608 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4609 if (ospf
== NULL
|| !ospf
->oi_running
) {
4611 json_object_free(json
);
4615 /* Display default ospf (instance 0) info */
4616 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4617 if (ospf
== NULL
|| !ospf
->oi_running
) {
4619 json_object_free(json
);
4625 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
,
4628 vty_out(vty
, "%s\n",
4629 json_object_to_json_string_ext(json
,
4630 JSON_C_TO_STRING_PRETTY
));
4635 json_object_free(json
);
4640 DEFUN (show_ip_ospf_instance_neighbor_all
,
4641 show_ip_ospf_instance_neighbor_all_cmd
,
4642 "show ip ospf (1-65535) neighbor all [json]",
4645 "OSPF information\n"
4648 "include down status neighbor\n"
4653 u_short instance
= 0;
4654 u_char uj
= use_json(argc
, argv
);
4655 json_object
*json
= NULL
;
4656 int ret
= CMD_SUCCESS
;
4658 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4659 ospf
= ospf_lookup_instance(instance
);
4661 return CMD_NOT_MY_INSTANCE
;
4663 if (!ospf
->oi_running
)
4666 json
= json_object_new_object();
4668 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
, 0);
4671 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4672 json
, JSON_C_TO_STRING_PRETTY
));
4673 json_object_free(json
);
4679 static int show_ip_ospf_neighbor_int_common(struct vty
*vty
, struct ospf
*ospf
,
4681 struct cmd_token
**argv
,
4682 u_char use_json
, u_char use_vrf
)
4684 struct interface
*ifp
;
4685 struct route_node
*rn
;
4686 json_object
*json
= NULL
;
4689 json
= json_object_new_object();
4691 if (ospf
->instance
) {
4693 json_object_int_add(json
, "ospfInstance",
4696 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4699 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
4701 /*ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id);*/
4702 ifp
= if_lookup_by_name_all_vrf(argv
[arg_base
]->arg
);
4705 json_object_boolean_true_add(json
, "noSuchIface");
4707 vty_out(vty
, "No such interface.\n");
4711 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
4712 struct ospf_interface
*oi
= rn
->info
;
4717 show_ip_ospf_neighbor_sub(vty
, oi
, json
, use_json
);
4721 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4722 json
, JSON_C_TO_STRING_PRETTY
));
4723 json_object_free(json
);
4730 DEFUN (show_ip_ospf_neighbor_int
,
4731 show_ip_ospf_neighbor_int_cmd
,
4732 "show ip ospf neighbor IFNAME [json]",
4735 "OSPF information\n"
4742 u_char uj
= use_json(argc
, argv
);
4743 struct listnode
*node
= NULL
;
4744 int ret
= CMD_SUCCESS
;
4745 struct interface
*ifp
= NULL
;
4748 show_ip_ospf_neighbour_header(vty
);
4750 ifp
= if_lookup_by_name_all_vrf(argv
[idx_ifname
]->arg
);
4751 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4752 if (!ospf
->oi_running
)
4754 if (!ifp
|| ifp
->vrf_id
!= ospf
->vrf_id
)
4756 ret
= show_ip_ospf_neighbor_int_common(vty
, ospf
,
4757 idx_ifname
, argv
, uj
, 0);
4763 DEFUN (show_ip_ospf_instance_neighbor_int
,
4764 show_ip_ospf_instance_neighbor_int_cmd
,
4765 "show ip ospf (1-65535) neighbor IFNAME [json]",
4768 "OSPF information\n"
4777 u_short instance
= 0;
4778 u_char uj
= use_json(argc
, argv
);
4781 show_ip_ospf_neighbour_header(vty
);
4783 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4784 ospf
= ospf_lookup_instance(instance
);
4786 return CMD_NOT_MY_INSTANCE
;
4788 if (!ospf
->oi_running
)
4792 show_ip_ospf_neighbour_header(vty
);
4794 return show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
,
4798 static void show_ip_ospf_nbr_nbma_detail_sub(struct vty
*vty
,
4799 struct ospf_interface
*oi
,
4800 struct ospf_nbr_nbma
*nbr_nbma
,
4801 u_char use_json
, json_object
*json
)
4803 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4804 json_object
*json_sub
= NULL
;
4807 json_sub
= json_object_new_object();
4808 else /* Show neighbor ID. */
4809 vty_out(vty
, " Neighbor %s,", "-");
4811 /* Show interface address. */
4813 json_object_string_add(json_sub
, "ifaceAddress",
4814 inet_ntoa(nbr_nbma
->addr
));
4816 vty_out(vty
, " interface address %s\n",
4817 inet_ntoa(nbr_nbma
->addr
));
4821 json_object_string_add(json_sub
, "areaId",
4822 ospf_area_desc_string(oi
->area
));
4823 json_object_string_add(json_sub
, "iface", IF_NAME(oi
));
4825 vty_out(vty
, " In the area %s via interface %s\n",
4826 ospf_area_desc_string(oi
->area
), IF_NAME(oi
));
4828 /* Show neighbor priority and state. */
4830 json_object_int_add(json_sub
, "nbrPriority",
4831 nbr_nbma
->priority
);
4832 json_object_string_add(json_sub
, "nbrState", "down");
4834 vty_out(vty
, " Neighbor priority is %d, State is %s,",
4835 nbr_nbma
->priority
, "Down");
4837 /* Show state changes. */
4839 json_object_int_add(json_sub
, "stateChangeCounter",
4840 nbr_nbma
->state_change
);
4842 vty_out(vty
, " %d state changes\n", nbr_nbma
->state_change
);
4844 /* Show PollInterval */
4846 json_object_int_add(json_sub
, "pollInterval", nbr_nbma
->v_poll
);
4848 vty_out(vty
, " Poll interval %d\n", nbr_nbma
->v_poll
);
4850 /* Show poll-interval timer. */
4853 time_store
= monotime_until(&nbr_nbma
->t_poll
->u
.sands
, NULL
)
4855 json_object_int_add(json_sub
, "pollIntervalTimerDueMsec",
4858 vty_out(vty
, " Poll timer due in %s\n",
4859 ospf_timer_dump(nbr_nbma
->t_poll
, timebuf
,
4862 /* Show poll-interval timer thread. */
4864 if (nbr_nbma
->t_poll
!= NULL
)
4865 json_object_string_add(json_sub
,
4866 "pollIntervalTimerThread", "on");
4868 vty_out(vty
, " Thread Poll Timer %s\n",
4869 nbr_nbma
->t_poll
!= NULL
? "on" : "off");
4872 json_object_object_add(json
, "noNbrId", json_sub
);
4875 static void show_ip_ospf_neighbor_detail_sub(struct vty
*vty
,
4876 struct ospf_interface
*oi
,
4877 struct ospf_neighbor
*nbr
,
4881 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4882 json_object
*json_sub
= NULL
;
4885 json_sub
= json_object_new_object();
4887 /* Show neighbor ID. */
4888 if (nbr
->state
== NSM_Attempt
&& nbr
->router_id
.s_addr
== 0)
4889 vty_out(vty
, " Neighbor %s,", "-");
4891 vty_out(vty
, " Neighbor %s,",
4892 inet_ntoa(nbr
->router_id
));
4895 /* Show interface address. */
4897 json_object_string_add(json_sub
, "ifaceAddress",
4898 inet_ntoa(nbr
->address
.u
.prefix4
));
4900 vty_out(vty
, " interface address %s\n",
4901 inet_ntoa(nbr
->address
.u
.prefix4
));
4905 json_object_string_add(json_sub
, "areaId",
4906 ospf_area_desc_string(oi
->area
));
4907 json_object_string_add(json_sub
, "ifaceName", oi
->ifp
->name
);
4909 vty_out(vty
, " In the area %s via interface %s\n",
4910 ospf_area_desc_string(oi
->area
), oi
->ifp
->name
);
4912 /* Show neighbor priority and state. */
4914 json_object_int_add(json_sub
, "nbrPriority", nbr
->priority
);
4915 json_object_string_add(
4916 json_sub
, "nbrState",
4917 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
4919 vty_out(vty
, " Neighbor priority is %d, State is %s,",
4921 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
4923 /* Show state changes. */
4925 json_object_int_add(json_sub
, "stateChangeCounter",
4928 vty_out(vty
, " %d state changes\n", nbr
->state_change
);
4930 if (nbr
->ts_last_progress
.tv_sec
|| nbr
->ts_last_progress
.tv_usec
) {
4935 monotime_since(&nbr
->ts_last_progress
, &res
) / 1000LL;
4937 json_object_int_add(json_sub
, "lastPrgrsvChangeMsec",
4941 " Most recent state change statistics:\n");
4942 vty_out(vty
, " Progressive change %s ago\n",
4943 ospf_timeval_dump(&res
, timebuf
,
4948 if (nbr
->ts_last_regress
.tv_sec
|| nbr
->ts_last_regress
.tv_usec
) {
4953 monotime_since(&nbr
->ts_last_regress
, &res
) / 1000LL;
4955 json_object_int_add(json_sub
,
4956 "lastRegressiveChangeMsec",
4958 if (nbr
->last_regress_str
)
4959 json_object_string_add(
4960 json_sub
, "lastRegressiveChangeReason",
4961 nbr
->last_regress_str
);
4964 " Regressive change %s ago, due to %s\n",
4965 ospf_timeval_dump(&res
, timebuf
,
4967 (nbr
->last_regress_str
? nbr
->last_regress_str
4972 /* Show Designated Rotuer ID. */
4974 json_object_string_add(json_sub
, "routerDesignatedId",
4975 inet_ntoa(nbr
->d_router
));
4977 vty_out(vty
, " DR is %s,", inet_ntoa(nbr
->d_router
));
4979 /* Show Backup Designated Rotuer ID. */
4981 json_object_string_add(json_sub
, "routerDesignatedBackupId",
4982 inet_ntoa(nbr
->bd_router
));
4984 vty_out(vty
, " BDR is %s\n", inet_ntoa(nbr
->bd_router
));
4988 json_object_int_add(json_sub
, "optionsCounter", nbr
->options
);
4989 json_object_string_add(json_sub
, "optionsList",
4990 ospf_options_dump(nbr
->options
));
4992 vty_out(vty
, " Options %d %s\n", nbr
->options
,
4993 ospf_options_dump(nbr
->options
));
4995 /* Show Router Dead interval timer. */
4997 if (nbr
->t_inactivity
) {
4999 time_store
= monotime_until(&nbr
->t_inactivity
->u
.sands
,
5002 json_object_int_add(json_sub
,
5003 "routerDeadIntervalTimerDueMsec",
5006 json_object_int_add(
5007 json_sub
, "routerDeadIntervalTimerDueMsec", -1);
5009 vty_out(vty
, " Dead timer due in %s\n",
5010 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
5013 /* Show Database Summary list. */
5015 json_object_int_add(json_sub
, "databaseSummaryListCounter",
5016 ospf_db_summary_count(nbr
));
5018 vty_out(vty
, " Database Summary List %d\n",
5019 ospf_db_summary_count(nbr
));
5021 /* Show Link State Request list. */
5023 json_object_int_add(json_sub
, "linkStateRequestListCounter",
5024 ospf_ls_request_count(nbr
));
5026 vty_out(vty
, " Link State Request List %ld\n",
5027 ospf_ls_request_count(nbr
));
5029 /* Show Link State Retransmission list. */
5031 json_object_int_add(json_sub
,
5032 "linkStateRetransmissionListCounter",
5033 ospf_ls_retransmit_count(nbr
));
5035 vty_out(vty
, " Link State Retransmission List %ld\n",
5036 ospf_ls_retransmit_count(nbr
));
5038 /* Show inactivity timer thread. */
5040 if (nbr
->t_inactivity
!= NULL
)
5041 json_object_string_add(json_sub
,
5042 "threadInactivityTimer", "on");
5044 vty_out(vty
, " Thread Inactivity Timer %s\n",
5045 nbr
->t_inactivity
!= NULL
? "on" : "off");
5047 /* Show Database Description retransmission thread. */
5049 if (nbr
->t_db_desc
!= NULL
)
5050 json_object_string_add(
5052 "threadDatabaseDescriptionRetransmission",
5056 " Thread Database Description Retransmision %s\n",
5057 nbr
->t_db_desc
!= NULL
? "on" : "off");
5059 /* Show Link State Request Retransmission thread. */
5061 if (nbr
->t_ls_req
!= NULL
)
5062 json_object_string_add(
5064 "threadLinkStateRequestRetransmission", "on");
5067 " Thread Link State Request Retransmission %s\n",
5068 nbr
->t_ls_req
!= NULL
? "on" : "off");
5070 /* Show Link State Update Retransmission thread. */
5072 if (nbr
->t_ls_upd
!= NULL
)
5073 json_object_string_add(
5074 json_sub
, "threadLinkStateUpdateRetransmission",
5078 " Thread Link State Update Retransmission %s\n\n",
5079 nbr
->t_ls_upd
!= NULL
? "on" : "off");
5082 if (nbr
->state
== NSM_Attempt
&& nbr
->router_id
.s_addr
== 0)
5083 json_object_object_add(json
, "noNbrId", json_sub
);
5085 json_object_object_add(json
, inet_ntoa(nbr
->router_id
),
5089 ospf_bfd_show_info(vty
, nbr
->bfd_info
, json
, use_json
, 0);
5092 static int show_ip_ospf_neighbor_id_common(struct vty
*vty
, struct ospf
*ospf
,
5094 struct cmd_token
**argv
,
5098 struct listnode
*node
;
5099 struct ospf_neighbor
*nbr
;
5100 struct ospf_interface
*oi
;
5101 struct in_addr router_id
;
5103 json_object
*json
= NULL
;
5106 json
= json_object_new_object();
5108 if (ospf
->instance
) {
5110 json_object_int_add(json
, "ospfInstance",
5113 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5116 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
5118 ret
= inet_aton(argv
[arg_base
]->arg
, &router_id
);
5121 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
5123 vty_out(vty
, "{}\n");
5124 json_object_free(json
);
5129 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5130 if ((nbr
= ospf_nbr_lookup_by_routerid(oi
->nbrs
, &router_id
))) {
5131 show_ip_ospf_neighbor_detail_sub(vty
, oi
, nbr
, json
,
5137 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5138 json
, JSON_C_TO_STRING_PRETTY
));
5139 json_object_free(json
);
5146 DEFUN (show_ip_ospf_neighbor_id
,
5147 show_ip_ospf_neighbor_id_cmd
,
5148 "show ip ospf neighbor A.B.C.D [json]",
5151 "OSPF information\n"
5157 u_char uj
= use_json(argc
, argv
);
5158 struct listnode
*node
= NULL
;
5159 int ret
= CMD_SUCCESS
;
5161 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5162 if (!ospf
->oi_running
)
5164 ret
= show_ip_ospf_neighbor_id_common(vty
, ospf
, 0,
5171 DEFUN (show_ip_ospf_instance_neighbor_id
,
5172 show_ip_ospf_instance_neighbor_id_cmd
,
5173 "show ip ospf (1-65535) neighbor A.B.C.D [json]",
5176 "OSPF information\n"
5183 int idx_router_id
= 5;
5185 u_short instance
= 0;
5186 u_char uj
= use_json(argc
, argv
);
5188 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5189 ospf
= ospf_lookup_instance(instance
);
5191 return CMD_NOT_MY_INSTANCE
;
5193 if (!ospf
->oi_running
)
5196 return show_ip_ospf_neighbor_id_common(vty
, ospf
, idx_router_id
, argv
,
5200 static int show_ip_ospf_neighbor_detail_common(struct vty
*vty
,
5206 struct ospf_interface
*oi
;
5207 struct listnode
*node
;
5208 json_object
*json_vrf
= NULL
;
5212 json_vrf
= json_object_new_object();
5216 if (ospf
->instance
) {
5218 json_object_int_add(json_vrf
, "ospfInstance",
5221 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5224 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5226 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5227 struct route_node
*rn
;
5228 struct ospf_neighbor
*nbr
;
5230 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5231 if ((nbr
= rn
->info
)) {
5232 if (nbr
!= oi
->nbr_self
) {
5233 if (nbr
->state
!= NSM_Down
) {
5234 show_ip_ospf_neighbor_detail_sub(
5235 vty
, oi
, nbr
, json_vrf
,
5245 if (ospf
->vrf_id
== VRF_DEFAULT
)
5246 json_object_object_add(json
, "default",
5249 json_object_object_add(json
, ospf
->name
,
5258 DEFUN (show_ip_ospf_neighbor_detail
,
5259 show_ip_ospf_neighbor_detail_cmd
,
5260 "show ip ospf [vrf <NAME|all>] neighbor detail [json]",
5263 "OSPF information\n"
5267 "detail of all neighbors\n"
5271 u_char uj
= use_json(argc
, argv
);
5272 struct listnode
*node
= NULL
;
5273 char *vrf_name
= NULL
;
5274 bool all_vrf
= FALSE
;
5275 int ret
= CMD_SUCCESS
;
5279 json_object
*json
= NULL
;
5281 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5284 json
= json_object_new_object();
5286 /* vrf input is provided could be all or specific vrf*/
5290 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5291 if (!ospf
->oi_running
)
5293 ret
= show_ip_ospf_neighbor_detail_common(vty
,
5300 vty_out(vty
, "%s\n",
5301 json_object_to_json_string_ext(json
,
5302 JSON_C_TO_STRING_PRETTY
));
5303 json_object_free(json
);
5308 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5309 if (ospf
== NULL
|| !ospf
->oi_running
) {
5311 json_object_free(json
);
5315 /* Display default ospf (instance 0) info */
5316 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5317 if (ospf
== NULL
|| !ospf
->oi_running
) {
5319 json_object_free(json
);
5325 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
,
5328 vty_out(vty
, "%s\n",
5329 json_object_to_json_string_ext(json
,
5330 JSON_C_TO_STRING_PRETTY
));
5335 json_object_free(json
);
5340 DEFUN (show_ip_ospf_instance_neighbor_detail
,
5341 show_ip_ospf_instance_neighbor_detail_cmd
,
5342 "show ip ospf (1-65535) neighbor detail [json]",
5345 "OSPF information\n"
5348 "detail of all neighbors\n"
5353 u_short instance
= 0;
5354 u_char uj
= use_json(argc
, argv
);
5355 json_object
*json
= NULL
;
5356 int ret
= CMD_SUCCESS
;
5358 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5359 ospf
= ospf_lookup_instance(instance
);
5361 return CMD_NOT_MY_INSTANCE
;
5363 if (!ospf
->oi_running
)
5367 json
= json_object_new_object();
5369 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
, 0);
5372 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5373 json
, JSON_C_TO_STRING_PRETTY
));
5374 json_object_free(json
);
5380 static int show_ip_ospf_neighbor_detail_all_common(struct vty
*vty
,
5386 struct listnode
*node
;
5387 struct ospf_interface
*oi
;
5388 json_object
*json_vrf
= NULL
;
5392 json_vrf
= json_object_new_object();
5397 if (ospf
->instance
) {
5399 json_object_int_add(json
, "ospfInstance",
5402 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5405 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5407 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5408 struct route_node
*rn
;
5409 struct ospf_neighbor
*nbr
;
5410 struct ospf_nbr_nbma
*nbr_nbma
;
5412 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
5413 if ((nbr
= rn
->info
))
5414 if (nbr
!= oi
->nbr_self
)
5415 if (nbr
->state
!= NSM_Down
)
5416 show_ip_ospf_neighbor_detail_sub(
5418 json_vrf
, use_json
);
5420 if (oi
->type
== OSPF_IFTYPE_NBMA
) {
5421 struct listnode
*nd
;
5423 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nd
, nbr_nbma
)) {
5424 if (nbr_nbma
->nbr
== NULL
5425 || nbr_nbma
->nbr
->state
== NSM_Down
)
5426 show_ip_ospf_nbr_nbma_detail_sub(
5427 vty
, oi
, nbr_nbma
, use_json
,
5435 if (ospf
->vrf_id
== VRF_DEFAULT
)
5436 json_object_object_add(json
, "default",
5439 json_object_object_add(json
, ospf
->name
,
5449 DEFUN (show_ip_ospf_neighbor_detail_all
,
5450 show_ip_ospf_neighbor_detail_all_cmd
,
5451 "show ip ospf [vrf <NAME|all>] neighbor detail all [json]",
5454 "OSPF information\n"
5458 "detail of all neighbors\n"
5459 "include down status neighbor\n"
5463 u_char uj
= use_json(argc
, argv
);
5464 struct listnode
*node
= NULL
;
5465 char *vrf_name
= NULL
;
5466 bool all_vrf
= FALSE
;
5467 int ret
= CMD_SUCCESS
;
5471 json_object
*json
= NULL
;
5473 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5476 json
= json_object_new_object();
5478 /* vrf input is provided could be all or specific vrf*/
5482 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5483 if (!ospf
->oi_running
)
5485 ret
= show_ip_ospf_neighbor_detail_all_common(vty
,
5493 vty_out(vty
, "%s\n",
5494 json_object_to_json_string_ext(json
,
5495 JSON_C_TO_STRING_PRETTY
));
5496 json_object_free(json
);
5501 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5502 if (ospf
== NULL
|| !ospf
->oi_running
) {
5504 json_object_free(json
);
5508 /* Display default ospf (instance 0) info */
5509 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5510 if (ospf
== NULL
|| !ospf
->oi_running
) {
5512 json_object_free(json
);
5518 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
,
5521 vty_out(vty
, "%s\n",
5522 json_object_to_json_string_ext(json
,
5523 JSON_C_TO_STRING_PRETTY
));
5528 json_object_free(json
);
5533 DEFUN (show_ip_ospf_instance_neighbor_detail_all
,
5534 show_ip_ospf_instance_neighbor_detail_all_cmd
,
5535 "show ip ospf (1-65535) neighbor detail all [json]",
5538 "OSPF information\n"
5541 "detail of all neighbors\n"
5542 "include down status neighbor\n"
5547 u_short instance
= 0;
5548 u_char uj
= use_json(argc
, argv
);
5549 json_object
*json
= NULL
;
5550 int ret
= CMD_SUCCESS
;
5552 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5553 ospf
= ospf_lookup_instance(instance
);
5555 return CMD_NOT_MY_INSTANCE
;
5557 if (!ospf
->oi_running
)
5561 json
= json_object_new_object();
5563 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
, uj
, 0);
5566 vty_out(vty
, "%s\n", json_object_to_json_string_ext(json
,
5567 JSON_C_TO_STRING_PRETTY
));
5568 json_object_free(json
);
5574 static int show_ip_ospf_neighbor_int_detail_common(struct vty
*vty
,
5577 struct cmd_token
**argv
,
5580 struct ospf_interface
*oi
;
5581 struct interface
*ifp
;
5582 struct route_node
*rn
, *nrn
;
5583 struct ospf_neighbor
*nbr
;
5584 json_object
*json
= NULL
;
5587 json
= json_object_new_object();
5589 if (ospf
->instance
) {
5591 json_object_int_add(json
, "ospfInstance",
5594 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5597 ifp
= if_lookup_by_name_all_vrf(argv
[arg_base
]->arg
);
5600 vty_out(vty
, "No such interface.\n");
5602 vty_out(vty
, "{}\n");
5603 json_object_free(json
);
5608 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
5609 if ((oi
= rn
->info
)) {
5610 for (nrn
= route_top(oi
->nbrs
); nrn
;
5611 nrn
= route_next(nrn
)) {
5612 if ((nbr
= nrn
->info
)) {
5613 if (nbr
!= oi
->nbr_self
) {
5614 if (nbr
->state
!= NSM_Down
)
5615 show_ip_ospf_neighbor_detail_sub(
5625 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5626 json
, JSON_C_TO_STRING_PRETTY
));
5627 json_object_free(json
);
5634 DEFUN (show_ip_ospf_neighbor_int_detail
,
5635 show_ip_ospf_neighbor_int_detail_cmd
,
5636 "show ip ospf neighbor IFNAME detail [json]",
5639 "OSPF information\n"
5642 "detail of all neighbors\n"
5646 u_char uj
= use_json(argc
, argv
);
5647 struct listnode
*node
= NULL
;
5648 int ret
= CMD_SUCCESS
;
5650 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5651 if (!ospf
->oi_running
)
5653 ret
= show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, 0,
5660 DEFUN (show_ip_ospf_instance_neighbor_int_detail
,
5661 show_ip_ospf_instance_neighbor_int_detail_cmd
,
5662 "show ip ospf (1-65535) neighbor IFNAME detail [json]",
5665 "OSPF information\n"
5669 "detail of all neighbors\n"
5675 u_short instance
= 0;
5676 u_char uj
= use_json(argc
, argv
);
5678 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5679 ospf
= ospf_lookup_instance(instance
);
5681 return CMD_NOT_MY_INSTANCE
;
5683 if (!ospf
->oi_running
)
5686 return show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, idx_ifname
, argv
, uj
);
5689 /* Show functions */
5690 static int show_lsa_summary(struct vty
*vty
, struct ospf_lsa
*lsa
, int self
)
5692 struct router_lsa
*rl
;
5693 struct summary_lsa
*sl
;
5694 struct as_external_lsa
*asel
;
5695 struct prefix_ipv4 p
;
5698 /* If self option is set, check LSA self flag. */
5699 if (self
== 0 || IS_LSA_SELF(lsa
)) {
5700 /* LSA common part show. */
5701 vty_out(vty
, "%-15s ", inet_ntoa(lsa
->data
->id
));
5702 vty_out(vty
, "%-15s %4d 0x%08lx 0x%04x",
5703 inet_ntoa(lsa
->data
->adv_router
), LS_AGE(lsa
),
5704 (u_long
)ntohl(lsa
->data
->ls_seqnum
),
5705 ntohs(lsa
->data
->checksum
));
5706 /* LSA specific part show. */
5707 switch (lsa
->data
->type
) {
5708 case OSPF_ROUTER_LSA
:
5709 rl
= (struct router_lsa
*)lsa
->data
;
5710 vty_out(vty
, " %-d", ntohs(rl
->links
));
5712 case OSPF_SUMMARY_LSA
:
5713 sl
= (struct summary_lsa
*)lsa
->data
;
5716 p
.prefix
= sl
->header
.id
;
5717 p
.prefixlen
= ip_masklen(sl
->mask
);
5718 apply_mask_ipv4(&p
);
5720 vty_out(vty
, " %s/%d", inet_ntoa(p
.prefix
),
5723 case OSPF_AS_EXTERNAL_LSA
:
5724 case OSPF_AS_NSSA_LSA
:
5725 asel
= (struct as_external_lsa
*)lsa
->data
;
5728 p
.prefix
= asel
->header
.id
;
5729 p
.prefixlen
= ip_masklen(asel
->mask
);
5730 apply_mask_ipv4(&p
);
5732 vty_out(vty
, " %s %s/%d [0x%lx]",
5733 IS_EXTERNAL_METRIC(asel
->e
[0].tos
)
5736 inet_ntoa(p
.prefix
), p
.prefixlen
,
5737 (u_long
)ntohl(asel
->e
[0].route_tag
));
5739 case OSPF_NETWORK_LSA
:
5740 case OSPF_ASBR_SUMMARY_LSA
:
5741 case OSPF_OPAQUE_LINK_LSA
:
5742 case OSPF_OPAQUE_AREA_LSA
:
5743 case OSPF_OPAQUE_AS_LSA
:
5753 static const char *show_database_desc
[] = {
5755 "Router Link States",
5757 "Summary Link States",
5758 "ASBR-Summary Link States",
5759 "AS External Link States",
5760 "Group Membership LSA",
5761 "NSSA-external Link States",
5763 "Link-Local Opaque-LSA",
5764 "Area-Local Opaque-LSA",
5765 "AS-external Opaque-LSA",
5768 static const char *show_database_header
[] = {
5770 "Link ID ADV Router Age Seq# CkSum Link count",
5771 "Link ID ADV Router Age Seq# CkSum",
5772 "Link ID ADV Router Age Seq# CkSum Route",
5773 "Link ID ADV Router Age Seq# CkSum",
5774 "Link ID ADV Router Age Seq# CkSum Route",
5775 " --- header for Group Member ----",
5776 "Link ID ADV Router Age Seq# CkSum Route",
5778 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5779 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5780 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5783 static void show_ip_ospf_database_header(struct vty
*vty
, struct ospf_lsa
*lsa
)
5785 struct router_lsa
*rlsa
= (struct router_lsa
*)lsa
->data
;
5787 vty_out(vty
, " LS age: %d\n", LS_AGE(lsa
));
5788 vty_out(vty
, " Options: 0x%-2x : %s\n", lsa
->data
->options
,
5789 ospf_options_dump(lsa
->data
->options
));
5790 vty_out(vty
, " LS Flags: 0x%-2x %s\n", lsa
->flags
,
5791 ((lsa
->flags
& OSPF_LSA_LOCAL_XLT
) ? "(Translated from Type-7)"
5794 if (lsa
->data
->type
== OSPF_ROUTER_LSA
) {
5795 vty_out(vty
, " Flags: 0x%x", rlsa
->flags
);
5798 vty_out(vty
, " :%s%s%s%s",
5799 IS_ROUTER_LSA_BORDER(rlsa
) ? " ABR" : "",
5800 IS_ROUTER_LSA_EXTERNAL(rlsa
) ? " ASBR" : "",
5801 IS_ROUTER_LSA_VIRTUAL(rlsa
) ? " VL-endpoint"
5803 IS_ROUTER_LSA_SHORTCUT(rlsa
) ? " Shortcut"
5808 vty_out(vty
, " LS Type: %s\n",
5809 lookup_msg(ospf_lsa_type_msg
, lsa
->data
->type
, NULL
));
5810 vty_out(vty
, " Link State ID: %s %s\n", inet_ntoa(lsa
->data
->id
),
5811 lookup_msg(ospf_link_state_id_type_msg
, lsa
->data
->type
, NULL
));
5812 vty_out(vty
, " Advertising Router: %s\n",
5813 inet_ntoa(lsa
->data
->adv_router
));
5814 vty_out(vty
, " LS Seq Number: %08lx\n",
5815 (u_long
)ntohl(lsa
->data
->ls_seqnum
));
5816 vty_out(vty
, " Checksum: 0x%04x\n", ntohs(lsa
->data
->checksum
));
5817 vty_out(vty
, " Length: %d\n\n", ntohs(lsa
->data
->length
));
5820 const char *link_type_desc
[] = {
5822 "another Router (point-to-point)",
5823 "a Transit Network",
5828 const char *link_id_desc
[] = {
5829 "(null)", "Neighboring Router ID", "Designated Router address",
5830 "Net", "Neighboring Router ID",
5833 const char *link_data_desc
[] = {
5834 "(null)", "Router Interface address", "Router Interface address",
5835 "Network Mask", "Router Interface address",
5838 /* Show router-LSA each Link information. */
5839 static void show_ip_ospf_database_router_links(struct vty
*vty
,
5840 struct router_lsa
*rl
)
5845 len
= ntohs(rl
->header
.length
) - 4;
5846 for (i
= 0; i
< ntohs(rl
->links
) && len
> 0; len
-= 12, i
++) {
5847 type
= rl
->link
[i
].type
;
5849 vty_out(vty
, " Link connected to: %s\n",
5850 link_type_desc
[type
]);
5851 vty_out(vty
, " (Link ID) %s: %s\n", link_id_desc
[type
],
5852 inet_ntoa(rl
->link
[i
].link_id
));
5853 vty_out(vty
, " (Link Data) %s: %s\n", link_data_desc
[type
],
5854 inet_ntoa(rl
->link
[i
].link_data
));
5855 vty_out(vty
, " Number of TOS metrics: 0\n");
5856 vty_out(vty
, " TOS 0 Metric: %d\n",
5857 ntohs(rl
->link
[i
].metric
));
5862 /* Show router-LSA detail information. */
5863 static int show_router_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5866 struct router_lsa
*rl
= (struct router_lsa
*)lsa
->data
;
5868 show_ip_ospf_database_header(vty
, lsa
);
5870 vty_out(vty
, " Number of Links: %d\n\n", ntohs(rl
->links
));
5872 show_ip_ospf_database_router_links(vty
, rl
);
5879 /* Show network-LSA detail information. */
5880 static int show_network_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5885 struct network_lsa
*nl
= (struct network_lsa
*)lsa
->data
;
5887 show_ip_ospf_database_header(vty
, lsa
);
5889 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(nl
->mask
));
5891 length
= ntohs(lsa
->data
->length
) - OSPF_LSA_HEADER_SIZE
- 4;
5893 for (i
= 0; length
> 0; i
++, length
-= 4)
5894 vty_out(vty
, " Attached Router: %s\n",
5895 inet_ntoa(nl
->routers
[i
]));
5903 /* Show summary-LSA detail information. */
5904 static int show_summary_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5907 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
5909 show_ip_ospf_database_header(vty
, lsa
);
5911 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(sl
->mask
));
5912 vty_out(vty
, " TOS: 0 Metric: %d\n",
5913 GET_METRIC(sl
->metric
));
5920 /* Show summary-ASBR-LSA detail information. */
5921 static int show_summary_asbr_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5924 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
5926 show_ip_ospf_database_header(vty
, lsa
);
5928 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(sl
->mask
));
5929 vty_out(vty
, " TOS: 0 Metric: %d\n",
5930 GET_METRIC(sl
->metric
));
5937 /* Show AS-external-LSA detail information. */
5938 static int show_as_external_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5941 struct as_external_lsa
*al
=
5942 (struct as_external_lsa
*)lsa
->data
;
5944 show_ip_ospf_database_header(vty
, lsa
);
5946 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(al
->mask
));
5947 vty_out(vty
, " Metric Type: %s\n",
5948 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
5949 ? "2 (Larger than any link state path)"
5951 vty_out(vty
, " TOS: 0\n");
5952 vty_out(vty
, " Metric: %d\n",
5953 GET_METRIC(al
->e
[0].metric
));
5954 vty_out(vty
, " Forward Address: %s\n",
5955 inet_ntoa(al
->e
[0].fwd_addr
));
5958 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
5959 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
5966 show_as_external_lsa_stdvty (struct ospf_lsa
*lsa
)
5968 struct as_external_lsa
*al
= (struct as_external_lsa
*) lsa
->data
;
5970 /* show_ip_ospf_database_header (vty, lsa); */
5972 zlog_debug( " Network Mask: /%d%s",
5973 ip_masklen (al
->mask
), "\n");
5974 zlog_debug( " Metric Type: %s%s",
5975 IS_EXTERNAL_METRIC (al
->e
[0].tos
) ?
5976 "2 (Larger than any link state path)" : "1", "\n");
5977 zlog_debug( " TOS: 0%s", "\n");
5978 zlog_debug( " Metric: %d%s",
5979 GET_METRIC (al
->e
[0].metric
), "\n");
5980 zlog_debug( " Forward Address: %s%s",
5981 inet_ntoa (al
->e
[0].fwd_addr
), "\n");
5983 zlog_debug( " External Route Tag: %"ROUTE_TAG_PRI
"%s%s",
5984 (route_tag_t
)ntohl (al
->e
[0].route_tag
), "\n", "\n");
5989 /* Show AS-NSSA-LSA detail information. */
5990 static int show_as_nssa_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5993 struct as_external_lsa
*al
=
5994 (struct as_external_lsa
*)lsa
->data
;
5996 show_ip_ospf_database_header(vty
, lsa
);
5998 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(al
->mask
));
5999 vty_out(vty
, " Metric Type: %s\n",
6000 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
6001 ? "2 (Larger than any link state path)"
6003 vty_out(vty
, " TOS: 0\n");
6004 vty_out(vty
, " Metric: %d\n",
6005 GET_METRIC(al
->e
[0].metric
));
6006 vty_out(vty
, " NSSA: Forward Address: %s\n",
6007 inet_ntoa(al
->e
[0].fwd_addr
));
6010 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
6011 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6017 static int show_func_dummy(struct vty
*vty
, struct ospf_lsa
*lsa
)
6022 static int show_opaque_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
6025 show_ip_ospf_database_header(vty
, lsa
);
6026 show_opaque_info_detail(vty
, lsa
);
6033 int (*show_function
[])(struct vty
*, struct ospf_lsa
*) = {
6035 show_router_lsa_detail
,
6036 show_network_lsa_detail
,
6037 show_summary_lsa_detail
,
6038 show_summary_asbr_lsa_detail
,
6039 show_as_external_lsa_detail
,
6041 show_as_nssa_lsa_detail
, /* almost same as external */
6043 show_opaque_lsa_detail
,
6044 show_opaque_lsa_detail
,
6045 show_opaque_lsa_detail
,
6048 static void show_lsa_prefix_set(struct vty
*vty
, struct prefix_ls
*lp
,
6049 struct in_addr
*id
, struct in_addr
*adv_router
)
6051 memset(lp
, 0, sizeof(struct prefix_ls
));
6055 else if (adv_router
== NULL
) {
6061 lp
->adv_router
= *adv_router
;
6065 static void show_lsa_detail_proc(struct vty
*vty
, struct route_table
*rt
,
6066 struct in_addr
*id
, struct in_addr
*adv_router
)
6068 struct prefix_ls lp
;
6069 struct route_node
*rn
, *start
;
6070 struct ospf_lsa
*lsa
;
6072 show_lsa_prefix_set(vty
, &lp
, id
, adv_router
);
6073 start
= route_node_get(rt
, (struct prefix
*)&lp
);
6075 route_lock_node(start
);
6076 for (rn
= start
; rn
; rn
= route_next_until(rn
, start
))
6077 if ((lsa
= rn
->info
)) {
6078 if (show_function
[lsa
->data
->type
] != NULL
)
6079 show_function
[lsa
->data
->type
](vty
,
6082 route_unlock_node(start
);
6086 /* Show detail LSA information
6087 -- if id is NULL then show all LSAs. */
6088 static void show_lsa_detail(struct vty
*vty
, struct ospf
*ospf
, int type
,
6089 struct in_addr
*id
, struct in_addr
*adv_router
)
6091 struct listnode
*node
;
6092 struct ospf_area
*area
;
6095 case OSPF_AS_EXTERNAL_LSA
:
6096 case OSPF_OPAQUE_AS_LSA
:
6097 vty_out(vty
, " %s \n\n",
6098 show_database_desc
[type
]);
6099 show_lsa_detail_proc(vty
, AS_LSDB(ospf
, type
), id
, adv_router
);
6102 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6103 vty_out(vty
, "\n %s (Area %s)\n\n",
6104 show_database_desc
[type
],
6105 ospf_area_desc_string(area
));
6106 show_lsa_detail_proc(vty
, AREA_LSDB(area
, type
), id
,
6113 static void show_lsa_detail_adv_router_proc(struct vty
*vty
,
6114 struct route_table
*rt
,
6115 struct in_addr
*adv_router
)
6117 struct route_node
*rn
;
6118 struct ospf_lsa
*lsa
;
6120 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
))
6121 if ((lsa
= rn
->info
))
6122 if (IPV4_ADDR_SAME(adv_router
,
6123 &lsa
->data
->adv_router
)) {
6124 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
6126 if (show_function
[lsa
->data
->type
] != NULL
)
6127 show_function
[lsa
->data
->type
](vty
,
6132 /* Show detail LSA information. */
6133 static void show_lsa_detail_adv_router(struct vty
*vty
, struct ospf
*ospf
,
6134 int type
, struct in_addr
*adv_router
)
6136 struct listnode
*node
;
6137 struct ospf_area
*area
;
6140 case OSPF_AS_EXTERNAL_LSA
:
6141 case OSPF_OPAQUE_AS_LSA
:
6142 vty_out(vty
, " %s \n\n",
6143 show_database_desc
[type
]);
6144 show_lsa_detail_adv_router_proc(vty
, AS_LSDB(ospf
, type
),
6148 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6149 vty_out(vty
, "\n %s (Area %s)\n\n",
6150 show_database_desc
[type
],
6151 ospf_area_desc_string(area
));
6152 show_lsa_detail_adv_router_proc(
6153 vty
, AREA_LSDB(area
, type
), adv_router
);
6159 static void show_ip_ospf_database_summary(struct vty
*vty
, struct ospf
*ospf
,
6162 struct ospf_lsa
*lsa
;
6163 struct route_node
*rn
;
6164 struct ospf_area
*area
;
6165 struct listnode
*node
;
6168 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6169 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6171 case OSPF_AS_EXTERNAL_LSA
:
6172 case OSPF_OPAQUE_AS_LSA
:
6177 if (ospf_lsdb_count_self(area
->lsdb
, type
) > 0
6179 && ospf_lsdb_count(area
->lsdb
, type
) > 0)) {
6180 vty_out(vty
, " %s (Area %s)\n\n",
6181 show_database_desc
[type
],
6182 ospf_area_desc_string(area
));
6183 vty_out(vty
, "%s\n",
6184 show_database_header
[type
]);
6186 LSDB_LOOP(AREA_LSDB(area
, type
), rn
, lsa
)
6187 show_lsa_summary(vty
, lsa
, self
);
6194 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6196 case OSPF_AS_EXTERNAL_LSA
:
6197 case OSPF_OPAQUE_AS_LSA
:
6202 if (ospf_lsdb_count_self(ospf
->lsdb
, type
)
6203 || (!self
&& ospf_lsdb_count(ospf
->lsdb
, type
))) {
6204 vty_out(vty
, " %s\n\n",
6205 show_database_desc
[type
]);
6206 vty_out(vty
, "%s\n", show_database_header
[type
]);
6208 LSDB_LOOP(AS_LSDB(ospf
, type
), rn
, lsa
)
6209 show_lsa_summary(vty
, lsa
, self
);
6218 static void show_ip_ospf_database_maxage(struct vty
*vty
, struct ospf
*ospf
)
6220 struct route_node
*rn
;
6222 vty_out(vty
, "\n MaxAge Link States:\n\n");
6224 for (rn
= route_top(ospf
->maxage_lsa
); rn
; rn
= route_next(rn
)) {
6225 struct ospf_lsa
*lsa
;
6227 if ((lsa
= rn
->info
) != NULL
) {
6228 vty_out(vty
, "Link type: %d\n", lsa
->data
->type
);
6229 vty_out(vty
, "Link State ID: %s\n",
6230 inet_ntoa(lsa
->data
->id
));
6231 vty_out(vty
, "Advertising Router: %s\n",
6232 inet_ntoa(lsa
->data
->adv_router
));
6233 vty_out(vty
, "LSA lock count: %d\n", lsa
->lock
);
6239 #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
6240 #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
6242 #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
6243 #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
6244 #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
6245 #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
6247 #define OSPF_LSA_TYPES_DESC \
6248 "ASBR summary link states\n" \
6249 "External link states\n" \
6250 "Network link states\n" \
6251 "Router link states\n" \
6252 "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \
6253 OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
6254 OSPF_LSA_TYPE_OPAQUE_AS_DESC
6256 static int show_ip_ospf_database_common(struct vty
*vty
, struct ospf
*ospf
,
6257 int arg_base
, int argc
,
6258 struct cmd_token
**argv
,
6263 struct in_addr id
, adv_router
;
6266 vty_out(vty
, "\nOSPF Instance: %d\n", ospf
->instance
);
6268 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
6270 vty_out(vty
, "\n OSPF Router with ID (%s)\n\n",
6271 inet_ntoa(ospf
->router_id
));
6274 if (argc
== arg_base
+ 4) {
6275 show_ip_ospf_database_summary(vty
, ospf
, 0);
6279 /* Set database type to show. */
6280 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
6281 type
= OSPF_ROUTER_LSA
;
6282 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
6283 type
= OSPF_NETWORK_LSA
;
6284 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
6285 type
= OSPF_AS_NSSA_LSA
;
6286 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "su", 2) == 0)
6287 type
= OSPF_SUMMARY_LSA
;
6288 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
6289 type
= OSPF_ASBR_SUMMARY_LSA
;
6290 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
6291 type
= OSPF_AS_EXTERNAL_LSA
;
6292 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "se", 2) == 0) {
6293 show_ip_ospf_database_summary(vty
, ospf
, 1);
6295 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "m", 1) == 0) {
6296 show_ip_ospf_database_maxage(vty
, ospf
);
6298 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
6299 type
= OSPF_OPAQUE_LINK_LSA
;
6300 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
6301 type
= OSPF_OPAQUE_AREA_LSA
;
6302 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
6303 type
= OSPF_OPAQUE_AS_LSA
;
6307 /* `show ip ospf database LSA'. */
6308 if (argc
== arg_base
+ 5)
6309 show_lsa_detail(vty
, ospf
, type
, NULL
, NULL
);
6310 else if (argc
>= arg_base
+ 6) {
6311 ret
= inet_aton(argv
[arg_base
+ 5]->arg
, &id
);
6315 /* `show ip ospf database LSA ID'. */
6316 if (argc
== arg_base
+ 6)
6317 show_lsa_detail(vty
, ospf
, type
, &id
, NULL
);
6318 /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */
6319 else if (argc
== arg_base
+ 7) {
6320 if (strncmp(argv
[arg_base
+ 6]->text
, "s", 1) == 0)
6321 adv_router
= ospf
->router_id
;
6323 ret
= inet_aton(argv
[arg_base
+ 7]->arg
,
6328 show_lsa_detail(vty
, ospf
, type
, &id
, &adv_router
);
6335 DEFUN (show_ip_ospf_database_max
,
6336 show_ip_ospf_database_max_cmd
,
6337 "show ip ospf [vrf <NAME|all>] database <max-age|self-originate>",
6340 "OSPF information\n"
6343 "Database summary\n"
6344 "LSAs in MaxAge list\n"
6345 "Self-originated link states\n")
6347 struct ospf
*ospf
= NULL
;
6348 struct listnode
*node
= NULL
;
6349 char *vrf_name
= NULL
;
6350 bool all_vrf
= FALSE
;
6351 int ret
= CMD_SUCCESS
;
6356 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
6361 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6362 if (!ospf
->oi_running
)
6364 ret
= show_ip_ospf_database_common(vty
, ospf
,
6371 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6372 if (ospf
== NULL
|| !ospf
->oi_running
)
6374 ret
= (show_ip_ospf_database_common(vty
, ospf
, idx_vrf
?
6379 /* Display default ospf (instance 0) info */
6380 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6381 if (ospf
== NULL
|| !ospf
->oi_running
)
6383 ret
= show_ip_ospf_database_common(vty
, ospf
, 0, argc
, argv
,
6390 DEFUN (show_ip_ospf_instance_database
,
6391 show_ip_ospf_instance_database_cmd
,
6392 "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>]]]",
6395 "OSPF information\n"
6398 "Database summary\n"
6400 "Link State ID (as an IP address)\n"
6401 "Self-originated link states\n"
6402 "Advertising Router link states\n"
6403 "Advertising Router (as an IP address)\n")
6406 u_short instance
= 0;
6407 struct listnode
*node
= NULL
;
6408 char *vrf_name
= NULL
;
6409 bool all_vrf
= FALSE
;
6410 int ret
= CMD_SUCCESS
;
6415 if (argv_find(argv
, argc
, "(1-65535)", &idx
)) {
6416 instance
= strtoul(argv
[idx
]->arg
, NULL
, 10);
6417 ospf
= ospf_lookup_instance(instance
);
6419 return CMD_NOT_MY_INSTANCE
;
6420 if (!ospf
->oi_running
)
6423 return (show_ip_ospf_database_common(vty
, ospf
, idx
? 1 : 0,
6424 argc
, argv
, use_vrf
));
6425 } else if (argv_find(argv
, argc
, "vrf", &idx
)) {
6426 vrf_name
= argv
[++idx
]->arg
;
6427 all_vrf
= strmatch(vrf_name
, "all");
6433 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6434 if (!ospf
->oi_running
)
6436 ret
= (show_ip_ospf_database_common(vty
, ospf
,
6442 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6443 if ((ospf
== NULL
) || !ospf
->oi_running
)
6445 ret
= (show_ip_ospf_database_common(vty
, ospf
, idx
? 2 :
6450 /* Display default ospf (instance 0) info */
6451 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6452 if (ospf
== NULL
|| !ospf
->oi_running
)
6454 ret
= (show_ip_ospf_database_common(vty
, ospf
, 0, argc
, argv
,
6461 DEFUN (show_ip_ospf_instance_database_max
,
6462 show_ip_ospf_instance_database_max_cmd
,
6463 "show ip ospf (1-65535) database <max-age|self-originate>",
6466 "OSPF information\n"
6468 "Database summary\n"
6469 "LSAs in MaxAge list\n"
6470 "Self-originated link states\n")
6474 u_short instance
= 0;
6476 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
6478 ospf
= ospf_lookup_instance(instance
);
6480 return CMD_NOT_MY_INSTANCE
;
6482 if (!ospf
->oi_running
)
6485 return show_ip_ospf_database_common(vty
, ospf
, 1, argc
, argv
, 0);
6489 static int show_ip_ospf_database_type_adv_router_common(struct vty
*vty
,
6491 int arg_base
, int argc
,
6492 struct cmd_token
**argv
,
6497 struct in_addr adv_router
;
6500 vty_out(vty
, "\nOSPF Instance: %d\n", ospf
->instance
);
6502 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
6504 vty_out(vty
, "\n OSPF Router with ID (%s)\n\n",
6505 inet_ntoa(ospf
->router_id
));
6507 /* Set database type to show. */
6508 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
6509 type
= OSPF_ROUTER_LSA
;
6510 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
6511 type
= OSPF_NETWORK_LSA
;
6512 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
6513 type
= OSPF_AS_NSSA_LSA
;
6514 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "s", 1) == 0)
6515 type
= OSPF_SUMMARY_LSA
;
6516 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
6517 type
= OSPF_ASBR_SUMMARY_LSA
;
6518 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
6519 type
= OSPF_AS_EXTERNAL_LSA
;
6520 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
6521 type
= OSPF_OPAQUE_LINK_LSA
;
6522 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
6523 type
= OSPF_OPAQUE_AREA_LSA
;
6524 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
6525 type
= OSPF_OPAQUE_AS_LSA
;
6529 /* `show ip ospf database LSA adv-router ADV_ROUTER'. */
6530 if (strncmp(argv
[arg_base
+ 5]->text
, "s", 1) == 0)
6531 adv_router
= ospf
->router_id
;
6533 ret
= inet_aton(argv
[arg_base
+ 6]->arg
, &adv_router
);
6538 show_lsa_detail_adv_router(vty
, ospf
, type
, &adv_router
);
6543 DEFUN (show_ip_ospf_instance_database_type_adv_router
,
6544 show_ip_ospf_instance_database_type_adv_router_cmd
,
6545 "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>",
6548 "OSPF information\n"
6551 "Database summary\n"
6553 "Advertising Router link states\n"
6554 "Advertising Router (as an IP address)\n"
6555 "Self-originated link states\n")
6557 struct ospf
*ospf
= NULL
;
6558 u_short instance
= 0;
6559 struct listnode
*node
= NULL
;
6560 char *vrf_name
= NULL
;
6561 bool all_vrf
= FALSE
;
6562 int ret
= CMD_SUCCESS
;
6564 int idx
= 0, idx_vrf
= 0;
6567 if (argv_find(argv
, argc
, "(1-65535)", &idx
)) {
6568 instance
= strtoul(argv
[idx
]->arg
, NULL
, 10);
6569 ospf
= ospf_lookup_instance(instance
);
6571 return CMD_NOT_MY_INSTANCE
;
6572 if (!ospf
->oi_running
)
6574 return (show_ip_ospf_database_type_adv_router_common(vty
, ospf
,
6581 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
6586 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6587 if (!ospf
->oi_running
)
6589 ret
= show_ip_ospf_database_type_adv_router_common(vty
,
6590 ospf
, idx
? 1 : 0, argc
, argv
,
6594 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6595 if ((ospf
== NULL
) || !ospf
->oi_running
)
6597 ret
= show_ip_ospf_database_type_adv_router_common(vty
,
6598 ospf
, idx
? 1 : 0, argc
, argv
,
6602 /* Display default ospf (instance 0) info */
6603 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6604 if (ospf
== NULL
|| !ospf
->oi_running
)
6606 ret
= show_ip_ospf_database_type_adv_router_common(vty
, ospf
,
6612 /*return (show_ip_ospf_database_type_adv_router_common(
6613 vty, ospf, idx ? 1 : 0, argc, argv));*/
6616 DEFUN (ip_ospf_authentication_args
,
6617 ip_ospf_authentication_args_addr_cmd
,
6618 "ip ospf authentication <null|message-digest> [A.B.C.D]",
6620 "OSPF interface commands\n"
6621 "Enable authentication on this interface\n"
6622 "Use null authentication\n"
6623 "Use message-digest authentication\n"
6624 "Address of interface\n")
6626 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6627 int idx_encryption
= 3;
6629 struct in_addr addr
;
6631 struct ospf_if_params
*params
;
6633 params
= IF_DEF_PARAMS(ifp
);
6636 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6639 "Please specify interface address by A.B.C.D\n");
6640 return CMD_WARNING_CONFIG_FAILED
;
6643 params
= ospf_get_if_params(ifp
, addr
);
6644 ospf_if_update_params(ifp
, addr
);
6647 /* Handle null authentication */
6648 if (argv
[idx_encryption
]->arg
[0] == 'n') {
6649 SET_IF_PARAM(params
, auth_type
);
6650 params
->auth_type
= OSPF_AUTH_NULL
;
6654 /* Handle message-digest authentication */
6655 if (argv
[idx_encryption
]->arg
[0] == 'm') {
6656 SET_IF_PARAM(params
, auth_type
);
6657 params
->auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
6661 vty_out(vty
, "You shouldn't get here!\n");
6662 return CMD_WARNING_CONFIG_FAILED
;
6665 DEFUN (ip_ospf_authentication
,
6666 ip_ospf_authentication_addr_cmd
,
6667 "ip ospf authentication [A.B.C.D]",
6669 "OSPF interface commands\n"
6670 "Enable authentication on this interface\n"
6671 "Address of interface\n")
6673 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6675 struct in_addr addr
;
6677 struct ospf_if_params
*params
;
6679 params
= IF_DEF_PARAMS(ifp
);
6682 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6685 "Please specify interface address by A.B.C.D\n");
6686 return CMD_WARNING_CONFIG_FAILED
;
6689 params
= ospf_get_if_params(ifp
, addr
);
6690 ospf_if_update_params(ifp
, addr
);
6693 SET_IF_PARAM(params
, auth_type
);
6694 params
->auth_type
= OSPF_AUTH_SIMPLE
;
6699 DEFUN (no_ip_ospf_authentication_args
,
6700 no_ip_ospf_authentication_args_addr_cmd
,
6701 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
6704 "OSPF interface commands\n"
6705 "Enable authentication on this interface\n"
6706 "Use null authentication\n"
6707 "Use message-digest authentication\n"
6708 "Address of interface\n")
6710 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6711 int idx_encryption
= 4;
6713 struct in_addr addr
;
6715 struct ospf_if_params
*params
;
6716 struct route_node
*rn
;
6719 params
= IF_DEF_PARAMS(ifp
);
6722 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6725 "Please specify interface address by A.B.C.D\n");
6726 return CMD_WARNING_CONFIG_FAILED
;
6729 params
= ospf_lookup_if_params(ifp
, addr
);
6730 if (params
== NULL
) {
6731 vty_out(vty
, "Ip Address specified is unknown\n");
6732 return CMD_WARNING_CONFIG_FAILED
;
6734 params
->auth_type
= OSPF_AUTH_NOTSET
;
6735 UNSET_IF_PARAM(params
, auth_type
);
6736 if (params
!= IF_DEF_PARAMS(ifp
)) {
6737 ospf_free_if_params(ifp
, addr
);
6738 ospf_if_update_params(ifp
, addr
);
6741 if (argv
[idx_encryption
]->arg
[0] == 'n') {
6742 auth_type
= OSPF_AUTH_NULL
;
6743 } else if (argv
[idx_encryption
]->arg
[0] == 'm') {
6744 auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
6746 vty_out(vty
, "Unexpected input encountered\n");
6747 return CMD_WARNING_CONFIG_FAILED
;
6750 * Here we have a case where the user has entered
6751 * 'no ip ospf authentication (null | message_digest )'
6752 * we need to find if we have any ip addresses underneath it
6754 * correspond to the associated type.
6756 if (params
->auth_type
== auth_type
) {
6757 params
->auth_type
= OSPF_AUTH_NOTSET
;
6758 UNSET_IF_PARAM(params
, auth_type
);
6761 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
6762 rn
= route_next(rn
)) {
6763 if ((params
= rn
->info
)) {
6764 if (params
->auth_type
== auth_type
) {
6765 params
->auth_type
= OSPF_AUTH_NOTSET
;
6766 UNSET_IF_PARAM(params
, auth_type
);
6767 if (params
!= IF_DEF_PARAMS(ifp
)) {
6768 ospf_free_if_params(
6769 ifp
, rn
->p
.u
.prefix4
);
6770 ospf_if_update_params(
6771 ifp
, rn
->p
.u
.prefix4
);
6781 DEFUN (no_ip_ospf_authentication
,
6782 no_ip_ospf_authentication_addr_cmd
,
6783 "no ip ospf authentication [A.B.C.D]",
6786 "OSPF interface commands\n"
6787 "Enable authentication on this interface\n"
6788 "Address of interface\n")
6790 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6792 struct in_addr addr
;
6794 struct ospf_if_params
*params
;
6795 struct route_node
*rn
;
6797 params
= IF_DEF_PARAMS(ifp
);
6800 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6803 "Please specify interface address by A.B.C.D\n");
6804 return CMD_WARNING_CONFIG_FAILED
;
6807 params
= ospf_lookup_if_params(ifp
, addr
);
6808 if (params
== NULL
) {
6809 vty_out(vty
, "Ip Address specified is unknown\n");
6810 return CMD_WARNING_CONFIG_FAILED
;
6813 params
->auth_type
= OSPF_AUTH_NOTSET
;
6814 UNSET_IF_PARAM(params
, auth_type
);
6815 if (params
!= IF_DEF_PARAMS(ifp
)) {
6816 ospf_free_if_params(ifp
, addr
);
6817 ospf_if_update_params(ifp
, addr
);
6821 * When a user enters 'no ip ospf authentication'
6822 * We should remove all authentication types from
6825 if ((params
->auth_type
== OSPF_AUTH_NULL
)
6826 || (params
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
6827 || (params
->auth_type
== OSPF_AUTH_SIMPLE
)) {
6828 params
->auth_type
= OSPF_AUTH_NOTSET
;
6829 UNSET_IF_PARAM(params
, auth_type
);
6832 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
6833 rn
= route_next(rn
)) {
6834 if ((params
= rn
->info
)) {
6836 if ((params
->auth_type
== OSPF_AUTH_NULL
)
6837 || (params
->auth_type
6838 == OSPF_AUTH_CRYPTOGRAPHIC
)
6839 || (params
->auth_type
6840 == OSPF_AUTH_SIMPLE
)) {
6841 params
->auth_type
= OSPF_AUTH_NOTSET
;
6842 UNSET_IF_PARAM(params
, auth_type
);
6843 if (params
!= IF_DEF_PARAMS(ifp
)) {
6844 ospf_free_if_params(
6845 ifp
, rn
->p
.u
.prefix4
);
6846 ospf_if_update_params(
6847 ifp
, rn
->p
.u
.prefix4
);
6858 DEFUN (ip_ospf_authentication_key
,
6859 ip_ospf_authentication_key_addr_cmd
,
6860 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
6862 "OSPF interface commands\n"
6863 "Authentication password (key)\n"
6864 "The OSPF password (key)\n"
6865 "Address of interface\n")
6867 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6869 struct in_addr addr
;
6870 struct ospf_if_params
*params
;
6872 params
= IF_DEF_PARAMS(ifp
);
6874 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6875 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6877 "Please specify interface address by A.B.C.D\n");
6878 return CMD_WARNING_CONFIG_FAILED
;
6881 params
= ospf_get_if_params(ifp
, addr
);
6882 ospf_if_update_params(ifp
, addr
);
6885 memset(params
->auth_simple
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
6886 strncpy((char *)params
->auth_simple
, argv
[3]->arg
,
6887 OSPF_AUTH_SIMPLE_SIZE
);
6888 SET_IF_PARAM(params
, auth_simple
);
6893 DEFUN_HIDDEN (ospf_authentication_key
,
6894 ospf_authentication_key_cmd
,
6895 "ospf authentication-key AUTH_KEY [A.B.C.D]",
6896 "OSPF interface commands\n"
6897 VLINK_HELPSTR_AUTH_SIMPLE
6898 "Address of interface\n")
6900 return ip_ospf_authentication_key(self
, vty
, argc
, argv
);
6903 DEFUN (no_ip_ospf_authentication_key
,
6904 no_ip_ospf_authentication_key_authkey_addr_cmd
,
6905 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
6908 "OSPF interface commands\n"
6909 VLINK_HELPSTR_AUTH_SIMPLE
6910 "Address of interface\n")
6912 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6914 struct in_addr addr
;
6915 struct ospf_if_params
*params
;
6916 params
= IF_DEF_PARAMS(ifp
);
6918 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6919 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6921 "Please specify interface address by A.B.C.D\n");
6922 return CMD_WARNING_CONFIG_FAILED
;
6925 params
= ospf_lookup_if_params(ifp
, addr
);
6930 memset(params
->auth_simple
, 0, OSPF_AUTH_SIMPLE_SIZE
);
6931 UNSET_IF_PARAM(params
, auth_simple
);
6933 if (params
!= IF_DEF_PARAMS(ifp
)) {
6934 ospf_free_if_params(ifp
, addr
);
6935 ospf_if_update_params(ifp
, addr
);
6941 DEFUN_HIDDEN (no_ospf_authentication_key
,
6942 no_ospf_authentication_key_authkey_addr_cmd
,
6943 "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
6945 "OSPF interface commands\n"
6946 VLINK_HELPSTR_AUTH_SIMPLE
6947 "Address of interface\n")
6949 return no_ip_ospf_authentication_key(self
, vty
, argc
, argv
);
6952 DEFUN (ip_ospf_message_digest_key
,
6953 ip_ospf_message_digest_key_cmd
,
6954 "ip 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 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6964 struct crypt_key
*ck
;
6966 struct in_addr addr
;
6967 struct ospf_if_params
*params
;
6969 params
= IF_DEF_PARAMS(ifp
);
6972 argv_find(argv
, argc
, "(1-255)", &idx
);
6973 char *keyid
= argv
[idx
]->arg
;
6974 argv_find(argv
, argc
, "KEY", &idx
);
6975 char *cryptkey
= argv
[idx
]->arg
;
6977 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6978 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6980 "Please specify interface address by A.B.C.D\n");
6981 return CMD_WARNING_CONFIG_FAILED
;
6984 params
= ospf_get_if_params(ifp
, addr
);
6985 ospf_if_update_params(ifp
, addr
);
6988 key_id
= strtol(keyid
, NULL
, 10);
6989 if (ospf_crypt_key_lookup(params
->auth_crypt
, key_id
) != NULL
) {
6990 vty_out(vty
, "OSPF: Key %d already exists\n", key_id
);
6994 ck
= ospf_crypt_key_new();
6995 ck
->key_id
= (u_char
)key_id
;
6996 memset(ck
->auth_key
, 0, OSPF_AUTH_MD5_SIZE
+ 1);
6997 strncpy((char *)ck
->auth_key
, cryptkey
, OSPF_AUTH_MD5_SIZE
);
6999 ospf_crypt_key_add(params
->auth_crypt
, ck
);
7000 SET_IF_PARAM(params
, auth_crypt
);
7005 DEFUN_HIDDEN (ospf_message_digest_key
,
7006 ospf_message_digest_key_cmd
,
7007 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7008 "OSPF interface commands\n"
7009 "Message digest authentication password (key)\n"
7011 "Use MD5 algorithm\n"
7012 "The OSPF password (key)\n"
7013 "Address of interface\n")
7015 return ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7018 DEFUN (no_ip_ospf_message_digest_key
,
7019 no_ip_ospf_message_digest_key_cmd
,
7020 "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7023 "OSPF interface commands\n"
7024 "Message digest authentication password (key)\n"
7026 "Use MD5 algorithm\n"
7027 "The OSPF password (key)\n"
7028 "Address of interface\n")
7030 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7032 struct crypt_key
*ck
;
7034 struct in_addr addr
;
7035 struct ospf_if_params
*params
;
7036 params
= IF_DEF_PARAMS(ifp
);
7038 argv_find(argv
, argc
, "(1-255)", &idx
);
7039 char *keyid
= argv
[idx
]->arg
;
7041 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7042 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7044 "Please specify interface address by A.B.C.D\n");
7045 return CMD_WARNING_CONFIG_FAILED
;
7048 params
= ospf_lookup_if_params(ifp
, addr
);
7053 key_id
= strtol(keyid
, NULL
, 10);
7054 ck
= ospf_crypt_key_lookup(params
->auth_crypt
, key_id
);
7056 vty_out(vty
, "OSPF: Key %d does not exist\n", key_id
);
7057 return CMD_WARNING_CONFIG_FAILED
;
7060 ospf_crypt_key_delete(params
->auth_crypt
, key_id
);
7062 if (params
!= IF_DEF_PARAMS(ifp
)) {
7063 ospf_free_if_params(ifp
, addr
);
7064 ospf_if_update_params(ifp
, addr
);
7070 DEFUN_HIDDEN (no_ospf_message_digest_key
,
7071 no_ospf_message_digest_key_cmd
,
7072 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7074 "OSPF interface commands\n"
7075 "Message digest authentication password (key)\n"
7077 "Use MD5 algorithm\n"
7078 "The OSPF password (key)\n"
7079 "Address of interface\n")
7081 return no_ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7084 DEFUN (ip_ospf_cost
,
7086 "ip ospf cost (1-65535) [A.B.C.D]",
7088 "OSPF interface commands\n"
7091 "Address of interface\n")
7093 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7095 u_int32_t cost
= OSPF_OUTPUT_COST_DEFAULT
;
7096 struct in_addr addr
;
7097 struct ospf_if_params
*params
;
7098 params
= IF_DEF_PARAMS(ifp
);
7101 char *coststr
= NULL
, *ifaddr
= NULL
;
7103 argv_find(argv
, argc
, "(1-65535)", &idx
);
7104 coststr
= argv
[idx
]->arg
;
7105 cost
= strtol(coststr
, NULL
, 10);
7107 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7109 if (!inet_aton(ifaddr
, &addr
)) {
7111 "Please specify interface address by A.B.C.D\n");
7112 return CMD_WARNING_CONFIG_FAILED
;
7115 params
= ospf_get_if_params(ifp
, addr
);
7116 ospf_if_update_params(ifp
, addr
);
7119 SET_IF_PARAM(params
, output_cost_cmd
);
7120 params
->output_cost_cmd
= cost
;
7122 ospf_if_recalculate_output_cost(ifp
);
7127 DEFUN_HIDDEN (ospf_cost
,
7129 "ospf cost (1-65535) [A.B.C.D]",
7130 "OSPF interface commands\n"
7133 "Address of interface\n")
7135 return ip_ospf_cost(self
, vty
, argc
, argv
);
7138 DEFUN (no_ip_ospf_cost
,
7139 no_ip_ospf_cost_cmd
,
7140 "no ip ospf cost [(1-65535)] [A.B.C.D]",
7143 "OSPF interface commands\n"
7146 "Address of interface\n")
7148 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7150 struct in_addr addr
;
7151 struct ospf_if_params
*params
;
7153 params
= IF_DEF_PARAMS(ifp
);
7156 char *ifaddr
= NULL
;
7157 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7159 /* According to the semantics we are mimicking "no ip ospf cost N" is
7160 * always treated as "no ip ospf cost" regardless of the actual value
7161 * of N already configured for the interface. Thus ignore cost. */
7164 if (!inet_aton(ifaddr
, &addr
)) {
7166 "Please specify interface address by A.B.C.D\n");
7167 return CMD_WARNING_CONFIG_FAILED
;
7170 params
= ospf_lookup_if_params(ifp
, addr
);
7175 UNSET_IF_PARAM(params
, output_cost_cmd
);
7177 if (params
!= IF_DEF_PARAMS(ifp
)) {
7178 ospf_free_if_params(ifp
, addr
);
7179 ospf_if_update_params(ifp
, addr
);
7182 ospf_if_recalculate_output_cost(ifp
);
7187 DEFUN_HIDDEN (no_ospf_cost
,
7189 "no ospf cost [(1-65535)] [A.B.C.D]",
7191 "OSPF interface commands\n"
7194 "Address of interface\n")
7196 return no_ip_ospf_cost(self
, vty
, argc
, argv
);
7199 static void ospf_nbr_timer_update(struct ospf_interface
*oi
)
7201 struct route_node
*rn
;
7202 struct ospf_neighbor
*nbr
;
7204 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
7205 if ((nbr
= rn
->info
)) {
7206 nbr
->v_inactivity
= OSPF_IF_PARAM(oi
, v_wait
);
7207 nbr
->v_db_desc
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7208 nbr
->v_ls_req
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7209 nbr
->v_ls_upd
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7213 static int ospf_vty_dead_interval_set(struct vty
*vty
, const char *interval_str
,
7214 const char *nbr_str
,
7215 const char *fast_hello_str
)
7217 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7220 struct in_addr addr
;
7222 struct ospf_if_params
*params
;
7223 struct ospf_interface
*oi
;
7224 struct route_node
*rn
;
7226 params
= IF_DEF_PARAMS(ifp
);
7229 ret
= inet_aton(nbr_str
, &addr
);
7232 "Please specify interface address by A.B.C.D\n");
7233 return CMD_WARNING_CONFIG_FAILED
;
7236 params
= ospf_get_if_params(ifp
, addr
);
7237 ospf_if_update_params(ifp
, addr
);
7241 seconds
= strtoul(interval_str
, NULL
, 10);
7243 /* reset fast_hello too, just to be sure */
7244 UNSET_IF_PARAM(params
, fast_hello
);
7245 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
7246 } else if (fast_hello_str
) {
7247 hellomult
= strtoul(fast_hello_str
, NULL
, 10);
7248 /* 1s dead-interval with sub-second hellos desired */
7249 seconds
= OSPF_ROUTER_DEAD_INTERVAL_MINIMAL
;
7250 SET_IF_PARAM(params
, fast_hello
);
7251 params
->fast_hello
= hellomult
;
7254 "Please specify dead-interval or hello-multiplier\n");
7255 return CMD_WARNING_CONFIG_FAILED
;
7258 SET_IF_PARAM(params
, v_wait
);
7259 params
->v_wait
= seconds
;
7261 /* Update timer values in neighbor structure. */
7263 struct ospf
*ospf
= NULL
;
7265 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7267 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
7269 ospf_nbr_timer_update(oi
);
7272 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
7273 if ((oi
= rn
->info
))
7274 ospf_nbr_timer_update(oi
);
7280 DEFUN (ip_ospf_dead_interval
,
7281 ip_ospf_dead_interval_cmd
,
7282 "ip ospf dead-interval (1-65535) [A.B.C.D]",
7284 "OSPF interface commands\n"
7285 "Interval time after which a neighbor is declared down\n"
7287 "Address of interface\n")
7290 char *interval
= argv_find(argv
, argc
, "(1-65535)", &idx
)
7294 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7295 return ospf_vty_dead_interval_set(vty
, interval
, ifaddr
, NULL
);
7299 DEFUN_HIDDEN (ospf_dead_interval
,
7300 ospf_dead_interval_cmd
,
7301 "ospf dead-interval (1-65535) [A.B.C.D]",
7302 "OSPF interface commands\n"
7303 "Interval time after which a neighbor is declared down\n"
7305 "Address of interface\n")
7307 return ip_ospf_dead_interval(self
, vty
, argc
, argv
);
7310 DEFUN (ip_ospf_dead_interval_minimal
,
7311 ip_ospf_dead_interval_minimal_addr_cmd
,
7312 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
7314 "OSPF interface commands\n"
7315 "Interval time after which a neighbor is declared down\n"
7316 "Minimal 1s dead-interval with fast sub-second hellos\n"
7317 "Hello multiplier factor\n"
7318 "Number of Hellos to send each second\n"
7319 "Address of interface\n")
7324 return ospf_vty_dead_interval_set(
7325 vty
, NULL
, argv
[idx_ipv4
]->arg
, argv
[idx_number
]->arg
);
7327 return ospf_vty_dead_interval_set(vty
, NULL
, NULL
,
7328 argv
[idx_number
]->arg
);
7331 DEFUN (no_ip_ospf_dead_interval
,
7332 no_ip_ospf_dead_interval_cmd
,
7333 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
7336 "OSPF interface commands\n"
7337 "Interval time after which a neighbor is declared down\n"
7339 "Minimal 1s dead-interval with fast sub-second hellos\n"
7340 "Hello multiplier factor\n"
7341 "Number of Hellos to send each second\n"
7342 "Address of interface\n")
7344 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7345 int idx_ipv4
= argc
- 1;
7346 struct in_addr addr
= {.s_addr
= 0L};
7348 struct ospf_if_params
*params
;
7349 struct ospf_interface
*oi
;
7350 struct route_node
*rn
;
7352 params
= IF_DEF_PARAMS(ifp
);
7354 if (argv
[idx_ipv4
]->type
== IPV4_TKN
) {
7355 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7358 "Please specify interface address by A.B.C.D\n");
7359 return CMD_WARNING_CONFIG_FAILED
;
7362 params
= ospf_lookup_if_params(ifp
, addr
);
7367 UNSET_IF_PARAM(params
, v_wait
);
7368 params
->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
7370 UNSET_IF_PARAM(params
, fast_hello
);
7371 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
7373 if (params
!= IF_DEF_PARAMS(ifp
)) {
7374 ospf_free_if_params(ifp
, addr
);
7375 ospf_if_update_params(ifp
, addr
);
7378 /* Update timer values in neighbor structure. */
7380 struct ospf
*ospf
= NULL
;
7382 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7384 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
7386 ospf_nbr_timer_update(oi
);
7389 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
7390 if ((oi
= rn
->info
))
7391 ospf_nbr_timer_update(oi
);
7397 DEFUN_HIDDEN (no_ospf_dead_interval
,
7398 no_ospf_dead_interval_cmd
,
7399 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
7401 "OSPF interface commands\n"
7402 "Interval time after which a neighbor is declared down\n"
7404 "Minimal 1s dead-interval with fast sub-second hellos\n"
7405 "Hello multiplier factor\n"
7406 "Number of Hellos to send each second\n"
7407 "Address of interface\n")
7409 return no_ip_ospf_dead_interval(self
, vty
, argc
, argv
);
7412 DEFUN (ip_ospf_hello_interval
,
7413 ip_ospf_hello_interval_cmd
,
7414 "ip ospf hello-interval (1-65535) [A.B.C.D]",
7416 "OSPF interface commands\n"
7417 "Time between HELLO packets\n"
7419 "Address of interface\n")
7421 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7423 struct in_addr addr
;
7424 struct ospf_if_params
*params
;
7425 params
= IF_DEF_PARAMS(ifp
);
7426 u_int32_t seconds
= 0;
7428 argv_find(argv
, argc
, "(1-65535)", &idx
);
7429 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7431 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7432 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7434 "Please specify interface address by A.B.C.D\n");
7435 return CMD_WARNING_CONFIG_FAILED
;
7438 params
= ospf_get_if_params(ifp
, addr
);
7439 ospf_if_update_params(ifp
, addr
);
7442 SET_IF_PARAM(params
, v_hello
);
7443 params
->v_hello
= seconds
;
7448 DEFUN_HIDDEN (ospf_hello_interval
,
7449 ospf_hello_interval_cmd
,
7450 "ospf hello-interval (1-65535) [A.B.C.D]",
7451 "OSPF interface commands\n"
7452 "Time between HELLO packets\n"
7454 "Address of interface\n")
7456 return ip_ospf_hello_interval(self
, vty
, argc
, argv
);
7459 DEFUN (no_ip_ospf_hello_interval
,
7460 no_ip_ospf_hello_interval_cmd
,
7461 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
7464 "OSPF interface commands\n"
7465 "Time between HELLO packets\n" // ignored
7467 "Address of interface\n")
7469 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7471 struct in_addr addr
;
7472 struct ospf_if_params
*params
;
7474 params
= IF_DEF_PARAMS(ifp
);
7476 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7477 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7479 "Please specify interface address by A.B.C.D\n");
7480 return CMD_WARNING_CONFIG_FAILED
;
7483 params
= ospf_lookup_if_params(ifp
, addr
);
7488 UNSET_IF_PARAM(params
, v_hello
);
7489 params
->v_hello
= OSPF_HELLO_INTERVAL_DEFAULT
;
7491 if (params
!= IF_DEF_PARAMS(ifp
)) {
7492 ospf_free_if_params(ifp
, addr
);
7493 ospf_if_update_params(ifp
, addr
);
7499 DEFUN_HIDDEN (no_ospf_hello_interval
,
7500 no_ospf_hello_interval_cmd
,
7501 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
7503 "OSPF interface commands\n"
7504 "Time between HELLO packets\n" // ignored
7506 "Address of interface\n")
7508 return no_ip_ospf_hello_interval(self
, vty
, argc
, argv
);
7511 DEFUN (ip_ospf_network
,
7512 ip_ospf_network_cmd
,
7513 "ip 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 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7524 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
7525 struct route_node
*rn
;
7527 if (old_type
== OSPF_IFTYPE_LOOPBACK
) {
7529 "This is a loopback interface. Can't set network type.\n");
7530 return CMD_WARNING_CONFIG_FAILED
;
7533 if (argv_find(argv
, argc
, "broadcast", &idx
))
7534 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_BROADCAST
;
7535 else if (argv_find(argv
, argc
, "non-broadcast", &idx
))
7536 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_NBMA
;
7537 else if (argv_find(argv
, argc
, "point-to-multipoint", &idx
))
7538 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOMULTIPOINT
;
7539 else if (argv_find(argv
, argc
, "point-to-point", &idx
))
7540 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOPOINT
;
7542 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
7545 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), type
);
7547 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7548 struct ospf_interface
*oi
= rn
->info
;
7553 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
7555 if (oi
->state
> ISM_Down
) {
7556 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
7557 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
7564 DEFUN_HIDDEN (ospf_network
,
7566 "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 ip_ospf_network(self
, vty
, argc
, argv
);
7577 DEFUN (no_ip_ospf_network
,
7578 no_ip_ospf_network_cmd
,
7579 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
7582 "OSPF interface commands\n"
7584 "Specify OSPF broadcast multi-access network\n"
7585 "Specify OSPF NBMA network\n"
7586 "Specify OSPF point-to-multipoint network\n"
7587 "Specify OSPF point-to-point network\n")
7589 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7590 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
7591 struct route_node
*rn
;
7593 IF_DEF_PARAMS(ifp
)->type
= ospf_default_iftype(ifp
);
7595 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
7598 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7599 struct ospf_interface
*oi
= rn
->info
;
7604 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
7606 if (oi
->state
> ISM_Down
) {
7607 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
7608 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
7615 DEFUN_HIDDEN (no_ospf_network
,
7616 no_ospf_network_cmd
,
7617 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
7619 "OSPF interface commands\n"
7621 "Specify OSPF broadcast multi-access network\n"
7622 "Specify OSPF NBMA network\n"
7623 "Specify OSPF point-to-multipoint network\n"
7624 "Specify OSPF point-to-point network\n")
7626 return no_ip_ospf_network(self
, vty
, argc
, argv
);
7629 DEFUN (ip_ospf_priority
,
7630 ip_ospf_priority_cmd
,
7631 "ip ospf priority (0-255) [A.B.C.D]",
7633 "OSPF interface commands\n"
7636 "Address of interface\n")
7638 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7641 struct route_node
*rn
;
7642 struct in_addr addr
;
7643 struct ospf_if_params
*params
;
7644 params
= IF_DEF_PARAMS(ifp
);
7646 argv_find(argv
, argc
, "(0-255)", &idx
);
7647 priority
= strtol(argv
[idx
]->arg
, NULL
, 10);
7649 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7650 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7652 "Please specify interface address by A.B.C.D\n");
7653 return CMD_WARNING_CONFIG_FAILED
;
7656 params
= ospf_get_if_params(ifp
, addr
);
7657 ospf_if_update_params(ifp
, addr
);
7660 SET_IF_PARAM(params
, priority
);
7661 params
->priority
= priority
;
7663 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7664 struct ospf_interface
*oi
= rn
->info
;
7669 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
7670 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
7671 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
7678 DEFUN_HIDDEN (ospf_priority
,
7680 "ospf priority (0-255) [A.B.C.D]",
7681 "OSPF interface commands\n"
7684 "Address of interface\n")
7686 return ip_ospf_priority(self
, vty
, argc
, argv
);
7689 DEFUN (no_ip_ospf_priority
,
7690 no_ip_ospf_priority_cmd
,
7691 "no ip ospf priority [(0-255) [A.B.C.D]]",
7694 "OSPF interface commands\n"
7695 "Router priority\n" // ignored
7697 "Address of interface\n")
7699 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7701 struct route_node
*rn
;
7702 struct in_addr addr
;
7703 struct ospf_if_params
*params
;
7705 params
= IF_DEF_PARAMS(ifp
);
7707 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7708 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7710 "Please specify interface address by A.B.C.D\n");
7711 return CMD_WARNING_CONFIG_FAILED
;
7714 params
= ospf_lookup_if_params(ifp
, addr
);
7719 UNSET_IF_PARAM(params
, priority
);
7720 params
->priority
= OSPF_ROUTER_PRIORITY_DEFAULT
;
7722 if (params
!= IF_DEF_PARAMS(ifp
)) {
7723 ospf_free_if_params(ifp
, addr
);
7724 ospf_if_update_params(ifp
, addr
);
7727 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7728 struct ospf_interface
*oi
= rn
->info
;
7733 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
7734 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
7735 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
7742 DEFUN_HIDDEN (no_ospf_priority
,
7743 no_ospf_priority_cmd
,
7744 "no ospf priority [(0-255) [A.B.C.D]]",
7746 "OSPF interface commands\n"
7749 "Address of interface\n")
7751 return no_ip_ospf_priority(self
, vty
, argc
, argv
);
7754 DEFUN (ip_ospf_retransmit_interval
,
7755 ip_ospf_retransmit_interval_addr_cmd
,
7756 "ip ospf retransmit-interval (3-65535) [A.B.C.D]",
7758 "OSPF interface commands\n"
7759 "Time between retransmitting lost link state advertisements\n"
7761 "Address of interface\n")
7763 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7766 struct in_addr addr
;
7767 struct ospf_if_params
*params
;
7768 params
= IF_DEF_PARAMS(ifp
);
7770 argv_find(argv
, argc
, "(3-65535)", &idx
);
7771 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7773 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7774 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7776 "Please specify interface address by A.B.C.D\n");
7777 return CMD_WARNING_CONFIG_FAILED
;
7780 params
= ospf_get_if_params(ifp
, addr
);
7781 ospf_if_update_params(ifp
, addr
);
7784 SET_IF_PARAM(params
, retransmit_interval
);
7785 params
->retransmit_interval
= seconds
;
7790 DEFUN_HIDDEN (ospf_retransmit_interval
,
7791 ospf_retransmit_interval_cmd
,
7792 "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 ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
7801 DEFUN (no_ip_ospf_retransmit_interval
,
7802 no_ip_ospf_retransmit_interval_addr_cmd
,
7803 "no ip ospf retransmit-interval [(3-65535)] [A.B.C.D]",
7806 "OSPF interface commands\n"
7807 "Time between retransmitting lost link state advertisements\n"
7809 "Address of interface\n")
7811 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7813 struct in_addr addr
;
7814 struct ospf_if_params
*params
;
7816 params
= IF_DEF_PARAMS(ifp
);
7818 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7819 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7821 "Please specify interface address by A.B.C.D\n");
7822 return CMD_WARNING_CONFIG_FAILED
;
7825 params
= ospf_lookup_if_params(ifp
, addr
);
7830 UNSET_IF_PARAM(params
, retransmit_interval
);
7831 params
->retransmit_interval
= OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
7833 if (params
!= IF_DEF_PARAMS(ifp
)) {
7834 ospf_free_if_params(ifp
, addr
);
7835 ospf_if_update_params(ifp
, addr
);
7841 DEFUN_HIDDEN (no_ospf_retransmit_interval
,
7842 no_ospf_retransmit_interval_cmd
,
7843 "no ospf retransmit-interval [(3-65535)] [A.B.C.D]",
7845 "OSPF interface commands\n"
7846 "Time between retransmitting lost link state advertisements\n"
7848 "Address of interface\n")
7850 return no_ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
7853 DEFUN (ip_ospf_transmit_delay
,
7854 ip_ospf_transmit_delay_addr_cmd
,
7855 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
7857 "OSPF interface commands\n"
7858 "Link state transmit delay\n"
7860 "Address of interface\n")
7862 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7865 struct in_addr addr
;
7866 struct ospf_if_params
*params
;
7868 params
= IF_DEF_PARAMS(ifp
);
7869 argv_find(argv
, argc
, "(1-65535)", &idx
);
7870 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7872 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7873 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7875 "Please specify interface address by A.B.C.D\n");
7876 return CMD_WARNING_CONFIG_FAILED
;
7879 params
= ospf_get_if_params(ifp
, addr
);
7880 ospf_if_update_params(ifp
, addr
);
7883 SET_IF_PARAM(params
, transmit_delay
);
7884 params
->transmit_delay
= seconds
;
7889 DEFUN_HIDDEN (ospf_transmit_delay
,
7890 ospf_transmit_delay_cmd
,
7891 "ospf transmit-delay (1-65535) [A.B.C.D]",
7892 "OSPF interface commands\n"
7893 "Link state transmit delay\n"
7895 "Address of interface\n")
7897 return ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
7900 DEFUN (no_ip_ospf_transmit_delay
,
7901 no_ip_ospf_transmit_delay_addr_cmd
,
7902 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
7905 "OSPF interface commands\n"
7906 "Link state transmit delay\n"
7908 "Address of interface\n")
7910 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7912 struct in_addr addr
;
7913 struct ospf_if_params
*params
;
7915 params
= IF_DEF_PARAMS(ifp
);
7917 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7918 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7920 "Please specify interface address by A.B.C.D\n");
7921 return CMD_WARNING_CONFIG_FAILED
;
7924 params
= ospf_lookup_if_params(ifp
, addr
);
7929 UNSET_IF_PARAM(params
, transmit_delay
);
7930 params
->transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
7932 if (params
!= IF_DEF_PARAMS(ifp
)) {
7933 ospf_free_if_params(ifp
, addr
);
7934 ospf_if_update_params(ifp
, addr
);
7941 DEFUN_HIDDEN (no_ospf_transmit_delay
,
7942 no_ospf_transmit_delay_cmd
,
7943 "no ospf transmit-delay [(1-65535) [A.B.C.D]]",
7945 "OSPF interface commands\n"
7946 "Link state transmit delay\n"
7948 "Address of interface\n")
7950 return no_ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
7953 DEFUN (ip_ospf_area
,
7955 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]",
7957 "OSPF interface commands\n"
7959 "Enable OSPF on this interface\n"
7960 "OSPF area ID in IP address format\n"
7961 "OSPF area ID as a decimal value\n"
7962 "Address of interface\n")
7964 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7967 struct in_addr area_id
;
7968 struct in_addr addr
;
7969 struct ospf_if_params
*params
= NULL
;
7970 struct route_node
*rn
;
7971 struct ospf
*ospf
= NULL
;
7972 u_short instance
= 0;
7975 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
7976 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
7978 argv_find(argv
, argc
, "area", &idx
);
7979 areaid
= argv
[idx
+ 1]->arg
;
7981 if (ifp
->vrf_id
&& !instance
)
7982 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7984 ospf
= ospf_lookup_instance(instance
);
7986 if (instance
&& ospf
== NULL
) {
7987 params
= IF_DEF_PARAMS(ifp
);
7988 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
7989 UNSET_IF_PARAM(params
, if_area
);
7990 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
7991 ospf_interface_area_unset(ospf
, ifp
);
7992 ospf
->if_ospf_cli_count
--;
7994 return CMD_NOT_MY_INSTANCE
;
7997 ret
= str2area_id(areaid
, &area_id
, &format
);
7999 vty_out(vty
, "Please specify area by A.B.C.D|<0-4294967295>\n");
8000 return CMD_WARNING_CONFIG_FAILED
;
8002 if (memcmp(ifp
->name
, "VLINK", 5) == 0) {
8003 vty_out(vty
, "Cannot enable OSPF on a virtual link.\n");
8004 return CMD_WARNING_CONFIG_FAILED
;
8007 params
= IF_DEF_PARAMS(ifp
);
8008 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)
8009 && !IPV4_ADDR_SAME(¶ms
->if_area
, &area_id
)) {
8011 "Must remove previous area config before changing ospf area \n");
8012 return CMD_WARNING_CONFIG_FAILED
;
8015 // Check if we have an address arg and proccess it
8016 if (argc
== idx
+ 3) {
8017 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
8018 vty_out(vty
, "Please specify Intf Address by A.B.C.D\n");
8019 return CMD_WARNING_CONFIG_FAILED
;
8021 // update/create address-level params
8022 params
= ospf_get_if_params((ifp
), (addr
));
8023 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8025 "Must remove previous area/address config before changing ospf area");
8026 return CMD_WARNING_CONFIG_FAILED
;
8028 ospf_if_update_params((ifp
), (addr
));
8032 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
)) {
8033 if (rn
->info
!= NULL
) {
8035 "Please remove all network commands first.\n");
8036 return CMD_WARNING_CONFIG_FAILED
;
8041 /* enable ospf on this interface with area_id */
8043 SET_IF_PARAM(params
, if_area
);
8044 params
->if_area
= area_id
;
8045 params
->if_area_id_fmt
= format
;
8049 ospf_interface_area_set(ospf
, ifp
);
8050 ospf
->if_ospf_cli_count
++;
8056 DEFUN (no_ip_ospf_area
,
8057 no_ip_ospf_area_cmd
,
8058 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]",
8061 "OSPF interface commands\n"
8063 "Disable OSPF on this interface\n"
8064 "OSPF area ID in IP address format\n"
8065 "OSPF area ID as a decimal value\n"
8066 "Address of interface\n")
8068 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8071 struct ospf_if_params
*params
;
8072 u_short instance
= 0;
8073 struct in_addr addr
;
8075 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
8076 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
8078 if (ifp
->vrf_id
&& !instance
)
8079 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
8081 ospf
= ospf_lookup_instance(instance
);
8084 return CMD_NOT_MY_INSTANCE
;
8086 argv_find(argv
, argc
, "area", &idx
);
8088 // Check if we have an address arg and proccess it
8089 if (argc
== idx
+ 3) {
8090 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
8091 vty_out(vty
, "Please specify Intf Address by A.B.C.D\n");
8092 return CMD_WARNING_CONFIG_FAILED
;
8094 params
= ospf_lookup_if_params(ifp
, addr
);
8095 if ((params
) == NULL
)
8098 params
= IF_DEF_PARAMS(ifp
);
8100 if (!OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8102 "Can't find specified interface area configuration.\n");
8103 return CMD_WARNING_CONFIG_FAILED
;
8106 UNSET_IF_PARAM(params
, if_area
);
8107 if (params
!= IF_DEF_PARAMS((ifp
))) {
8108 ospf_free_if_params((ifp
), (addr
));
8109 ospf_if_update_params((ifp
), (addr
));
8112 ospf_interface_area_unset(ospf
, ifp
);
8113 ospf
->if_ospf_cli_count
--;
8117 DEFUN (ospf_redistribute_source
,
8118 ospf_redistribute_source_cmd
,
8119 "redistribute " FRR_REDIST_STR_OSPFD
" [<metric (0-16777214)|metric-type (1-2)|route-map WORD>]",
8121 FRR_REDIST_HELP_STR_OSPFD
8122 "Metric for redistributed routes\n"
8123 "OSPF default metric\n"
8124 "OSPF exterior metric type for redistributed routes\n"
8125 "Set OSPF External Type 1/2 metrics\n"
8126 "Route map reference\n"
8127 "Pointer to route-map entries\n")
8129 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8130 int idx_protocol
= 1;
8134 struct ospf_redist
*red
;
8140 /* Get distribute source. */
8141 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
8143 return CMD_WARNING_CONFIG_FAILED
;
8145 red
= ospf_redist_add(ospf
, source
, 0);
8147 /* Get metric value. */
8148 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
8149 if (!str2metric(argv
[idx
]->arg
, &metric
))
8150 return CMD_WARNING_CONFIG_FAILED
;
8152 /* Get metric type. */
8153 else if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
8154 if (!str2metric_type(argv
[idx
]->arg
, &type
))
8155 return CMD_WARNING_CONFIG_FAILED
;
8158 else if (argv_find(argv
, argc
, "WORD", &idx
)) {
8159 ospf_routemap_set(red
, argv
[idx
]->arg
);
8161 ospf_routemap_unset(red
);
8163 return ospf_redistribute_set(ospf
, source
, 0, type
, metric
);
8166 DEFUN (no_ospf_redistribute_source
,
8167 no_ospf_redistribute_source_cmd
,
8168 "no redistribute " FRR_REDIST_STR_OSPFD
" [<metric (0-16777214)|metric-type (1-2)|route-map WORD>]",
8171 FRR_REDIST_HELP_STR_OSPFD
8172 "Metric for redistributed routes\n"
8173 "OSPF default metric\n"
8174 "OSPF exterior metric type for redistributed routes\n"
8175 "Set OSPF External Type 1/2 metrics\n"
8176 "Route map reference\n"
8177 "Pointer to route-map entries\n")
8179 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8180 int idx_protocol
= 2;
8182 struct ospf_redist
*red
;
8184 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
8186 return CMD_WARNING_CONFIG_FAILED
;
8188 red
= ospf_redist_lookup(ospf
, source
, 0);
8192 ospf_routemap_unset(red
);
8193 return ospf_redistribute_unset(ospf
, source
, 0);
8196 DEFUN (ospf_redistribute_instance_source
,
8197 ospf_redistribute_instance_source_cmd
,
8198 "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8200 "Open Shortest Path First\n"
8201 "Non-main Kernel Routing Table\n"
8202 "Instance ID/Table ID\n"
8203 "Metric for redistributed routes\n"
8204 "OSPF default metric\n"
8205 "OSPF exterior metric type for redistributed routes\n"
8206 "Set OSPF External Type 1/2 metrics\n"
8207 "Route map reference\n"
8208 "Pointer to route-map entries\n")
8210 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8211 int idx_ospf_table
= 1;
8218 struct ospf_redist
*red
;
8223 source
= proto_redistnum(AFI_IP
, argv
[idx_ospf_table
]->text
);
8225 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8230 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
8232 "Instance redistribution in non-instanced OSPF not allowed\n");
8233 return CMD_WARNING_CONFIG_FAILED
;
8236 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
8237 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
8238 return CMD_WARNING_CONFIG_FAILED
;
8241 /* Get metric value. */
8242 if (argv_find(argv
, argc
, "metric", &idx
))
8243 if (!str2metric(argv
[idx
+ 1]->arg
, &metric
))
8244 return CMD_WARNING_CONFIG_FAILED
;
8247 /* Get metric type. */
8248 if (argv_find(argv
, argc
, "metric-type", &idx
))
8249 if (!str2metric_type(argv
[idx
+ 1]->arg
, &type
))
8250 return CMD_WARNING_CONFIG_FAILED
;
8252 red
= ospf_redist_add(ospf
, source
, instance
);
8255 if (argv_find(argv
, argc
, "route-map", &idx
))
8256 ospf_routemap_set(red
, argv
[idx
+ 1]->arg
);
8258 ospf_routemap_unset(red
);
8260 return ospf_redistribute_set(ospf
, source
, instance
, type
, metric
);
8263 DEFUN (no_ospf_redistribute_instance_source
,
8264 no_ospf_redistribute_instance_source_cmd
,
8265 "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8268 "Open Shortest Path First\n"
8269 "Non-main Kernel Routing Table\n"
8270 "Instance ID/Table Id\n"
8271 "Metric for redistributed routes\n"
8272 "OSPF default metric\n"
8273 "OSPF exterior metric type for redistributed routes\n"
8274 "Set OSPF External Type 1/2 metrics\n"
8275 "Route map reference\n"
8276 "Pointer to route-map entries\n")
8278 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8279 int idx_ospf_table
= 2;
8282 struct ospf_redist
*red
;
8285 if (strncmp(argv
[idx_ospf_table
]->arg
, "o", 1) == 0)
8286 source
= ZEBRA_ROUTE_OSPF
;
8288 source
= ZEBRA_ROUTE_TABLE
;
8290 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8292 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
8294 "Instance redistribution in non-instanced OSPF not allowed\n");
8295 return CMD_WARNING_CONFIG_FAILED
;
8298 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
8299 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
8300 return CMD_WARNING_CONFIG_FAILED
;
8303 red
= ospf_redist_lookup(ospf
, source
, instance
);
8307 ospf_routemap_unset(red
);
8308 return ospf_redistribute_unset(ospf
, source
, instance
);
8311 DEFUN (ospf_distribute_list_out
,
8312 ospf_distribute_list_out_cmd
,
8313 "distribute-list WORD out " FRR_REDIST_STR_OSPFD
,
8314 "Filter networks in routing updates\n"
8315 "Access-list name\n"
8317 FRR_REDIST_HELP_STR_OSPFD
)
8319 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8323 char *proto
= argv
[argc
- 1]->text
;
8325 /* Get distribute source. */
8326 source
= proto_redistnum(AFI_IP
, proto
);
8328 return CMD_WARNING_CONFIG_FAILED
;
8330 return ospf_distribute_list_out_set(ospf
, source
, argv
[idx_word
]->arg
);
8333 DEFUN (no_ospf_distribute_list_out
,
8334 no_ospf_distribute_list_out_cmd
,
8335 "no distribute-list WORD out " FRR_REDIST_STR_OSPFD
,
8337 "Filter networks in routing updates\n"
8338 "Access-list name\n"
8340 FRR_REDIST_HELP_STR_OSPFD
)
8342 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8346 char *proto
= argv
[argc
- 1]->text
;
8347 source
= proto_redistnum(AFI_IP
, proto
);
8349 return CMD_WARNING_CONFIG_FAILED
;
8351 return ospf_distribute_list_out_unset(ospf
, source
,
8352 argv
[idx_word
]->arg
);
8355 /* Default information originate. */
8356 DEFUN (ospf_default_information_originate
,
8357 ospf_default_information_originate_cmd
,
8358 "default-information originate [<always|metric (0-16777214)|metric-type (1-2)|route-map WORD>]",
8359 "Control distribution of default information\n"
8360 "Distribute a default route\n"
8361 "Always advertise default route\n"
8362 "OSPF default metric\n"
8364 "OSPF metric type for default routes\n"
8365 "Set OSPF External Type 1/2 metrics\n"
8366 "Route map reference\n"
8367 "Pointer to route-map entries\n")
8369 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8370 int default_originate
= DEFAULT_ORIGINATE_ZEBRA
;
8373 struct ospf_redist
*red
;
8376 red
= ospf_redist_add(ospf
, DEFAULT_ROUTE
, 0);
8378 /* Check whether "always" was specified */
8379 if (argv_find(argv
, argc
, "always", &idx
))
8380 default_originate
= DEFAULT_ORIGINATE_ALWAYS
;
8381 /* Get metric value */
8382 else if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
8383 if (!str2metric(argv
[idx
]->arg
, &metric
))
8384 return CMD_WARNING_CONFIG_FAILED
;
8386 /* Get metric type. */
8387 else if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
8388 if (!str2metric_type(argv
[idx
]->arg
, &type
))
8389 return CMD_WARNING_CONFIG_FAILED
;
8392 else if (argv_find(argv
, argc
, "WORD", &idx
))
8393 ospf_routemap_set(red
, argv
[idx
]->arg
);
8395 ospf_routemap_unset(red
);
8397 return ospf_redistribute_default_set(ospf
, default_originate
, type
,
8401 DEFUN (no_ospf_default_information_originate
,
8402 no_ospf_default_information_originate_cmd
,
8403 "no default-information originate [<always|metric (0-16777214)|metric-type (1-2)|route-map WORD>]",
8405 "Control distribution of default information\n"
8406 "Distribute a default route\n"
8407 "Always advertise default route\n"
8408 "OSPF default metric\n"
8410 "OSPF metric type for default routes\n"
8411 "Set OSPF External Type 1/2 metrics\n"
8412 "Route map reference\n"
8413 "Pointer to route-map entries\n")
8415 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8416 struct prefix_ipv4 p
;
8417 struct ospf_external
*ext
;
8418 struct ospf_redist
*red
;
8421 p
.prefix
.s_addr
= 0;
8424 ospf_external_lsa_flush(ospf
, DEFAULT_ROUTE
, &p
, 0);
8426 ext
= ospf_external_lookup(ospf
, DEFAULT_ROUTE
, 0);
8427 if (ext
&& EXTERNAL_INFO(ext
)) {
8428 ospf_external_info_delete(ospf
, DEFAULT_ROUTE
, 0, p
);
8429 ospf_external_del(ospf
, DEFAULT_ROUTE
, 0);
8432 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
8436 ospf_routemap_unset(red
);
8437 return ospf_redistribute_default_unset(ospf
);
8440 DEFUN (ospf_default_metric
,
8441 ospf_default_metric_cmd
,
8442 "default-metric (0-16777214)",
8443 "Set metric of redistributed routes\n"
8446 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8450 if (!str2metric(argv
[idx_number
]->arg
, &metric
))
8451 return CMD_WARNING_CONFIG_FAILED
;
8453 ospf
->default_metric
= metric
;
8458 DEFUN (no_ospf_default_metric
,
8459 no_ospf_default_metric_cmd
,
8460 "no default-metric [(0-16777214)]",
8462 "Set metric of redistributed routes\n"
8465 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8467 ospf
->default_metric
= -1;
8473 DEFUN (ospf_distance
,
8476 "Administrative distance\n"
8477 "OSPF Administrative distance\n")
8479 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8482 ospf
->distance_all
= atoi(argv
[idx_number
]->arg
);
8487 DEFUN (no_ospf_distance
,
8488 no_ospf_distance_cmd
,
8489 "no distance (1-255)",
8491 "Administrative distance\n"
8492 "OSPF Administrative distance\n")
8494 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8496 ospf
->distance_all
= 0;
8501 DEFUN (no_ospf_distance_ospf
,
8502 no_ospf_distance_ospf_cmd
,
8503 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
8505 "Administrative distance\n"
8506 "OSPF administrative distance\n"
8507 "Intra-area routes\n"
8508 "Distance for intra-area routes\n"
8509 "Inter-area routes\n"
8510 "Distance for inter-area routes\n"
8512 "Distance for external routes\n")
8514 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8520 if (argv_find(argv
, argc
, "intra-area", &idx
) || argc
== 3)
8521 idx
= ospf
->distance_intra
= 0;
8522 if (argv_find(argv
, argc
, "inter-area", &idx
) || argc
== 3)
8523 idx
= ospf
->distance_inter
= 0;
8524 if (argv_find(argv
, argc
, "external", &idx
) || argc
== 3)
8525 ospf
->distance_external
= 0;
8530 DEFUN (ospf_distance_ospf
,
8531 ospf_distance_ospf_cmd
,
8532 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
8533 "Administrative distance\n"
8534 "OSPF administrative distance\n"
8535 "Intra-area routes\n"
8536 "Distance for intra-area routes\n"
8537 "Inter-area routes\n"
8538 "Distance for inter-area routes\n"
8540 "Distance for external routes\n")
8542 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8545 if (argv_find(argv
, argc
, "intra-area", &idx
))
8546 ospf
->distance_intra
= atoi(argv
[idx
+ 1]->arg
);
8548 if (argv_find(argv
, argc
, "inter-area", &idx
))
8549 ospf
->distance_inter
= atoi(argv
[idx
+ 1]->arg
);
8551 if (argv_find(argv
, argc
, "external", &idx
))
8552 ospf
->distance_external
= atoi(argv
[idx
+ 1]->arg
);
8558 DEFUN (ospf_distance_source
,
8559 ospf_distance_source_cmd
,
8560 "distance (1-255) A.B.C.D/M",
8561 "Administrative distance\n"
8563 "IP source prefix\n")
8565 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8567 int idx_ipv4_prefixlen
= 2;
8572 ospf_distance_set (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
8577 DEFUN (no_ospf_distance_source
,
8578 no_ospf_distance_source_cmd
,
8579 "no distance (1-255) A.B.C.D/M",
8581 "Administrative distance\n"
8583 "IP source prefix\n")
8585 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8587 int idx_ipv4_prefixlen
= 3;
8592 ospf_distance_unset (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
8597 DEFUN (ospf_distance_source_access_list
,
8598 ospf_distance_source_access_list_cmd
,
8599 "distance (1-255) A.B.C.D/M WORD",
8600 "Administrative distance\n"
8602 "IP source prefix\n"
8603 "Access list name\n")
8605 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8607 int idx_ipv4_prefixlen
= 2;
8613 ospf_distance_set (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
8618 DEFUN (no_ospf_distance_source_access_list
,
8619 no_ospf_distance_source_access_list_cmd
,
8620 "no distance (1-255) A.B.C.D/M WORD",
8622 "Administrative distance\n"
8624 "IP source prefix\n"
8625 "Access list name\n")
8627 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8629 int idx_ipv4_prefixlen
= 3;
8635 ospf_distance_unset (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
8641 DEFUN (ip_ospf_mtu_ignore
,
8642 ip_ospf_mtu_ignore_addr_cmd
,
8643 "ip ospf mtu-ignore [A.B.C.D]",
8645 "OSPF interface commands\n"
8646 "Disable MTU mismatch detection on this interface\n"
8647 "Address of interface\n")
8649 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8651 struct in_addr addr
;
8654 struct ospf_if_params
*params
;
8655 params
= IF_DEF_PARAMS(ifp
);
8658 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8661 "Please specify interface address by A.B.C.D\n");
8662 return CMD_WARNING_CONFIG_FAILED
;
8664 params
= ospf_get_if_params(ifp
, addr
);
8665 ospf_if_update_params(ifp
, addr
);
8667 params
->mtu_ignore
= 1;
8668 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
8669 SET_IF_PARAM(params
, mtu_ignore
);
8671 UNSET_IF_PARAM(params
, mtu_ignore
);
8672 if (params
!= IF_DEF_PARAMS(ifp
)) {
8673 ospf_free_if_params(ifp
, addr
);
8674 ospf_if_update_params(ifp
, addr
);
8680 DEFUN (no_ip_ospf_mtu_ignore
,
8681 no_ip_ospf_mtu_ignore_addr_cmd
,
8682 "no ip ospf mtu-ignore [A.B.C.D]",
8685 "OSPF interface commands\n"
8686 "Disable MTU mismatch detection on this interface\n"
8687 "Address of interface\n")
8689 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8691 struct in_addr addr
;
8694 struct ospf_if_params
*params
;
8695 params
= IF_DEF_PARAMS(ifp
);
8698 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8701 "Please specify interface address by A.B.C.D\n");
8702 return CMD_WARNING_CONFIG_FAILED
;
8704 params
= ospf_get_if_params(ifp
, addr
);
8705 ospf_if_update_params(ifp
, addr
);
8707 params
->mtu_ignore
= 0;
8708 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
8709 SET_IF_PARAM(params
, mtu_ignore
);
8711 UNSET_IF_PARAM(params
, mtu_ignore
);
8712 if (params
!= IF_DEF_PARAMS(ifp
)) {
8713 ospf_free_if_params(ifp
, addr
);
8714 ospf_if_update_params(ifp
, addr
);
8721 DEFUN (ospf_max_metric_router_lsa_admin
,
8722 ospf_max_metric_router_lsa_admin_cmd
,
8723 "max-metric router-lsa administrative",
8724 "OSPF maximum / infinite-distance metric\n"
8725 "Advertise own Router-LSA with infinite distance (stub router)\n"
8726 "Administratively applied, for an indefinite period\n")
8728 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8729 struct listnode
*ln
;
8730 struct ospf_area
*area
;
8732 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8733 SET_FLAG(area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
);
8735 if (!CHECK_FLAG(area
->stub_router_state
,
8736 OSPF_AREA_IS_STUB_ROUTED
))
8737 ospf_router_lsa_update_area(area
);
8740 /* Allows for areas configured later to get the property */
8741 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
;
8746 DEFUN (no_ospf_max_metric_router_lsa_admin
,
8747 no_ospf_max_metric_router_lsa_admin_cmd
,
8748 "no max-metric router-lsa administrative",
8750 "OSPF maximum / infinite-distance metric\n"
8751 "Advertise own Router-LSA with infinite distance (stub router)\n"
8752 "Administratively applied, for an indefinite period\n")
8754 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8755 struct listnode
*ln
;
8756 struct ospf_area
*area
;
8758 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8759 UNSET_FLAG(area
->stub_router_state
,
8760 OSPF_AREA_ADMIN_STUB_ROUTED
);
8762 /* Don't trample on the start-up stub timer */
8763 if (CHECK_FLAG(area
->stub_router_state
,
8764 OSPF_AREA_IS_STUB_ROUTED
)
8765 && !area
->t_stub_router
) {
8766 UNSET_FLAG(area
->stub_router_state
,
8767 OSPF_AREA_IS_STUB_ROUTED
);
8768 ospf_router_lsa_update_area(area
);
8771 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET
;
8775 DEFUN (ospf_max_metric_router_lsa_startup
,
8776 ospf_max_metric_router_lsa_startup_cmd
,
8777 "max-metric router-lsa on-startup (5-86400)",
8778 "OSPF maximum / infinite-distance metric\n"
8779 "Advertise own Router-LSA with infinite distance (stub router)\n"
8780 "Automatically advertise stub Router-LSA on startup of OSPF\n"
8781 "Time (seconds) to advertise self as stub-router\n")
8783 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8785 unsigned int seconds
;
8788 vty_out(vty
, "%% Must supply stub-router period");
8789 return CMD_WARNING_CONFIG_FAILED
;
8792 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8794 ospf
->stub_router_startup_time
= seconds
;
8799 DEFUN (no_ospf_max_metric_router_lsa_startup
,
8800 no_ospf_max_metric_router_lsa_startup_cmd
,
8801 "no max-metric router-lsa on-startup [(5-86400)]",
8803 "OSPF maximum / infinite-distance metric\n"
8804 "Advertise own Router-LSA with infinite distance (stub router)\n"
8805 "Automatically advertise stub Router-LSA on startup of OSPF\n"
8806 "Time (seconds) to advertise self as stub-router\n")
8808 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8809 struct listnode
*ln
;
8810 struct ospf_area
*area
;
8812 ospf
->stub_router_startup_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
8814 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8815 SET_FLAG(area
->stub_router_state
,
8816 OSPF_AREA_WAS_START_STUB_ROUTED
);
8817 OSPF_TIMER_OFF(area
->t_stub_router
);
8819 /* Don't trample on admin stub routed */
8820 if (!CHECK_FLAG(area
->stub_router_state
,
8821 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
8822 UNSET_FLAG(area
->stub_router_state
,
8823 OSPF_AREA_IS_STUB_ROUTED
);
8824 ospf_router_lsa_update_area(area
);
8831 DEFUN (ospf_max_metric_router_lsa_shutdown
,
8832 ospf_max_metric_router_lsa_shutdown_cmd
,
8833 "max-metric router-lsa on-shutdown (5-100)",
8834 "OSPF maximum / infinite-distance metric\n"
8835 "Advertise own Router-LSA with infinite distance (stub router)\n"
8836 "Advertise stub-router prior to full shutdown of OSPF\n"
8837 "Time (seconds) to wait till full shutdown\n")
8839 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8841 unsigned int seconds
;
8844 vty_out(vty
, "%% Must supply stub-router shutdown period");
8845 return CMD_WARNING_CONFIG_FAILED
;
8848 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8850 ospf
->stub_router_shutdown_time
= seconds
;
8855 DEFUN (no_ospf_max_metric_router_lsa_shutdown
,
8856 no_ospf_max_metric_router_lsa_shutdown_cmd
,
8857 "no max-metric router-lsa on-shutdown [(5-100)]",
8859 "OSPF maximum / infinite-distance metric\n"
8860 "Advertise own Router-LSA with infinite distance (stub router)\n"
8861 "Advertise stub-router prior to full shutdown of OSPF\n"
8862 "Time (seconds) to wait till full shutdown\n")
8864 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8866 ospf
->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
8871 static void config_write_stub_router(struct vty
*vty
, struct ospf
*ospf
)
8873 struct listnode
*ln
;
8874 struct ospf_area
*area
;
8876 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
8877 vty_out(vty
, " max-metric router-lsa on-startup %u\n",
8878 ospf
->stub_router_startup_time
);
8879 if (ospf
->stub_router_shutdown_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
8880 vty_out(vty
, " max-metric router-lsa on-shutdown %u\n",
8881 ospf
->stub_router_shutdown_time
);
8882 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8883 if (CHECK_FLAG(area
->stub_router_state
,
8884 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
8885 vty_out(vty
, " max-metric router-lsa administrative\n");
8892 static void show_ip_ospf_route_network(struct vty
*vty
, struct ospf
*ospf
,
8893 struct route_table
*rt
,
8896 struct route_node
*rn
;
8897 struct ospf_route
* or ;
8898 struct listnode
*pnode
, *pnnode
;
8899 struct ospf_path
*path
;
8900 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
8901 *json_nexthop
= NULL
;
8904 vty_out(vty
, "============ OSPF network routing table ============\n");
8906 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
8907 if ((or = rn
->info
) == NULL
)
8909 char buf1
[PREFIX2STR_BUFFER
];
8911 memset(buf1
, 0, sizeof(buf1
));
8912 prefix2str(&rn
->p
, buf1
, sizeof(buf1
));
8914 json_route
= json_object_new_object();
8916 json_object_object_add(json
, buf1
, json_route
);
8917 json_object_to_json_string_ext(json
,
8918 JSON_C_TO_STRING_NOSLASHESCAPE
);
8922 switch (or->path_type
) {
8923 case OSPF_PATH_INTER_AREA
:
8924 if (or->type
== OSPF_DESTINATION_NETWORK
) {
8926 json_object_string_add(json_route
,
8929 json_object_int_add(json_route
,
8932 json_object_string_add(
8936 or->u
.std
.area_id
));
8939 "N IA %-18s [%d] area: %s\n",
8941 inet_ntoa(or->u
.std
.area_id
));
8943 } else if (or->type
==
8944 OSPF_DESTINATION_DISCARD
) {
8946 json_object_string_add(json_route
,
8951 "D IA %-18s Discard entry\n",
8956 case OSPF_PATH_INTRA_AREA
:
8958 json_object_string_add(json_route
,
8960 json_object_int_add(json_route
, "cost",
8962 json_object_string_add(json_route
,
8963 "area", inet_ntoa(or->u
.std
.area_id
));
8965 vty_out(vty
, "N %-18s [%d] area: %s\n",
8967 inet_ntoa(or->u
.std
.area_id
));
8974 if (or->type
== OSPF_DESTINATION_NETWORK
) {
8976 json_nexthop_array
= json_object_new_array();
8977 json_object_object_add(json_route
, "nexthops",
8978 json_nexthop_array
);
8981 for (ALL_LIST_ELEMENTS(or->paths
, pnode
, pnnode
,
8985 json_object_new_object();
8986 json_object_array_add(json_nexthop_array
,
8989 if (if_lookup_by_index(path
->ifindex
,
8992 if (path
->nexthop
.s_addr
== 0) {
8994 json_object_string_add(
8998 json_object_string_add(
9000 "directly attached to",
9006 "%24s directly attached to %s\n",
9014 json_object_string_add(
9019 json_object_string_add(
9027 "%24s via %s, %s\n",
9040 json_object_free(json_route
);
9046 static void show_ip_ospf_route_router(struct vty
*vty
, struct ospf
*ospf
,
9047 struct route_table
*rtrs
,
9050 struct route_node
*rn
;
9051 struct ospf_route
* or ;
9052 struct listnode
*pnode
;
9053 struct listnode
*node
;
9054 struct ospf_path
*path
;
9055 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
9056 *json_nexthop
= NULL
;
9059 vty_out(vty
, "============ OSPF router routing table =============\n");
9061 for (rn
= route_top(rtrs
); rn
; rn
= route_next(rn
)) {
9062 if (rn
->info
== NULL
)
9066 json_route
= json_object_new_object();
9068 json_object_object_add(json
,
9069 inet_ntoa(rn
->p
.u
.prefix4
),
9071 json_object_string_add(json_route
, "routeType",
9074 vty_out(vty
, "R %-15s ",
9075 inet_ntoa(rn
->p
.u
.prefix4
));
9078 for (ALL_LIST_ELEMENTS_RO((struct list
*)rn
->info
, node
,
9082 vty_out(vty
, "%24s", "");
9087 json_object_int_add(json_route
, "cost",
9089 json_object_string_add(json_route
,
9091 inet_ntoa(or->u
.std
.area_id
));
9092 if (or->path_type
==
9093 OSPF_PATH_INTER_AREA
)
9094 json_object_boolean_true_add(
9097 if (or->u
.std
.flags
& ROUTER_LSA_BORDER
)
9098 json_object_string_add(
9102 else if (or->u
.std
.flags
&
9103 ROUTER_LSA_EXTERNAL
)
9104 json_object_string_add(
9109 vty_out(vty
, "%s [%d] area: %s",
9110 (or->path_type
== OSPF_PATH_INTER_AREA
9113 or->cost
, inet_ntoa(or->u
.std
.area_id
));
9115 vty_out(vty
, "%s%s\n",
9116 (or->u
.std
.flags
& ROUTER_LSA_BORDER
9119 (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
9125 json_nexthop_array
=
9126 json_object_new_array();
9127 json_object_object_add(json_route
, "nexthops",
9128 json_nexthop_array
);
9131 for (ALL_LIST_ELEMENTS_RO(or->paths
, pnode
,
9135 json_object_new_object();
9136 json_object_array_add(
9140 if (if_lookup_by_index(path
->ifindex
,
9142 if (path
->nexthop
.s_addr
== 0) {
9144 json_object_string_add(
9148 json_object_string_add(
9150 "directly attached to",
9156 "%24s directly attached to %s\n",
9164 json_object_string_add(
9167 inet_ntoa(path
->nexthop
));
9168 json_object_string_add(
9176 "%24s via %s, %s\n",
9189 json_object_free(json_route
);
9195 static void show_ip_ospf_route_external(struct vty
*vty
, struct ospf
*ospf
,
9196 struct route_table
*rt
,
9199 struct route_node
*rn
;
9200 struct ospf_route
*er
;
9201 struct listnode
*pnode
, *pnnode
;
9202 struct ospf_path
*path
;
9203 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
9204 *json_nexthop
= NULL
;
9207 vty_out(vty
, "============ OSPF external routing table ===========\n");
9209 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
9210 if ((er
= rn
->info
) == NULL
)
9215 snprintf(buf1
, 19, "%s/%d", inet_ntoa(rn
->p
.u
.prefix4
),
9217 json_route
= json_object_new_object();
9219 json_object_object_add(json
, buf1
, json_route
);
9220 json_object_to_json_string_ext(json
,
9221 JSON_C_TO_STRING_NOSLASHESCAPE
);
9225 switch (er
->path_type
) {
9226 case OSPF_PATH_TYPE1_EXTERNAL
:
9228 json_object_string_add(json_route
,
9231 json_object_int_add(json_route
, "cost",
9235 "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI
9237 buf1
, er
->cost
, er
->u
.ext
.tag
);
9240 case OSPF_PATH_TYPE2_EXTERNAL
:
9242 json_object_string_add(json_route
,
9245 json_object_int_add(json_route
, "cost",
9249 "N E2 %-18s [%d/%d] tag: %"
9251 "\n", buf1
, er
->cost
,
9252 er
->u
.ext
.type2_cost
,
9259 json_nexthop_array
= json_object_new_array();
9260 json_object_object_add(json_route
, "nexthops",
9261 json_nexthop_array
);
9264 for (ALL_LIST_ELEMENTS(er
->paths
, pnode
, pnnode
,
9267 json_nexthop
= json_object_new_object();
9268 json_object_array_add(json_nexthop_array
9272 if (if_lookup_by_index(path
->ifindex
,
9274 if (path
->nexthop
.s_addr
== 0) {
9276 json_object_string_add(
9280 json_object_string_add(
9282 "directly attached to",
9288 "%24s directly attached to %s\n",
9296 json_object_string_add(
9301 json_object_string_add(
9309 "%24s via %s, %s\n",
9321 json_object_free(json_route
);
9327 static int show_ip_ospf_border_routers_common(struct vty
*vty
,
9332 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
9334 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
9336 if (ospf
->new_table
== NULL
) {
9337 vty_out(vty
, "No OSPF routing information exist\n");
9341 /* Show Network routes.
9342 show_ip_ospf_route_network (vty, ospf->new_table); */
9344 /* Show Router routes. */
9345 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, NULL
);
9352 DEFUN (show_ip_ospf_border_routers
,
9353 show_ip_ospf_border_routers_cmd
,
9354 "show ip ospf [vrf <NAME|all>] border-routers",
9357 "OSPF information\n"
9360 "Show all the ABR's and ASBR's\n")
9362 struct ospf
*ospf
= NULL
;
9363 struct listnode
*node
= NULL
;
9364 char *vrf_name
= NULL
;
9365 bool all_vrf
= FALSE
;
9366 int ret
= CMD_SUCCESS
;
9371 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
9376 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9377 if (!ospf
->oi_running
)
9380 ret
= show_ip_ospf_border_routers_common(vty
,
9385 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
9386 if (ospf
== NULL
|| !ospf
->oi_running
)
9389 ret
= show_ip_ospf_border_routers_common(vty
, ospf
,
9393 /* Display default ospf (instance 0) info */
9394 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
9395 if (ospf
== NULL
|| !ospf
->oi_running
)
9397 ret
= show_ip_ospf_border_routers_common(vty
, ospf
, use_vrf
);
9403 DEFUN (show_ip_ospf_instance_border_routers
,
9404 show_ip_ospf_instance_border_routers_cmd
,
9405 "show ip ospf (1-65535) border-routers",
9408 "OSPF information\n"
9410 "Show all the ABR's and ASBR's\n")
9414 u_short instance
= 0;
9416 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9417 ospf
= ospf_lookup_instance(instance
);
9419 return CMD_NOT_MY_INSTANCE
;
9421 if (!ospf
->oi_running
)
9424 return show_ip_ospf_border_routers_common(vty
, ospf
, 0);
9427 static int show_ip_ospf_route_common(struct vty
*vty
, struct ospf
*ospf
,
9428 json_object
*json
, u_char use_vrf
)
9430 json_object
*json_vrf
= NULL
;
9433 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
9438 json_vrf
= json_object_new_object();
9443 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
9445 if (ospf
->new_table
== NULL
) {
9446 vty_out(vty
, "No OSPF routing information exist\n");
9450 /* Show Network routes. */
9451 show_ip_ospf_route_network(vty
, ospf
, ospf
->new_table
, json_vrf
);
9453 /* Show Router routes. */
9454 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, json_vrf
);
9456 /* Show AS External routes. */
9457 show_ip_ospf_route_external(vty
, ospf
, ospf
->old_external_route
,
9462 //json_object_object_add(json_vrf, "areas", json_areas);
9463 if (ospf
->vrf_id
== VRF_DEFAULT
)
9464 json_object_object_add(json
, "default",
9467 json_object_object_add(json
, ospf
->name
,
9477 DEFUN (show_ip_ospf_route
,
9478 show_ip_ospf_route_cmd
,
9479 "show ip ospf [vrf <NAME|all>] route [json]",
9482 "OSPF information\n"
9485 "OSPF routing table\n"
9488 struct ospf
*ospf
= NULL
;
9489 struct listnode
*node
= NULL
;
9490 char *vrf_name
= NULL
;
9491 bool all_vrf
= FALSE
;
9492 int ret
= CMD_SUCCESS
;
9496 u_char uj
= use_json(argc
, argv
);
9497 json_object
*json
= NULL
;
9500 json
= json_object_new_object();
9502 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
9504 /* vrf input is provided could be all or specific vrf*/
9508 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9509 if (!ospf
->oi_running
)
9511 ret
= show_ip_ospf_route_common(vty
, ospf
, json
,
9516 /* Keep Non-pretty format */
9517 vty_out(vty
, "%s\n",
9518 json_object_to_json_string(json
));
9519 json_object_free(json
);
9524 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
9525 if (ospf
== NULL
|| !ospf
->oi_running
) {
9527 json_object_free(json
);
9531 /* Display default ospf (instance 0) info */
9532 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
9533 if (ospf
== NULL
|| !ospf
->oi_running
) {
9535 json_object_free(json
);
9541 ret
= show_ip_ospf_route_common(vty
, ospf
, json
, use_vrf
);
9542 /* Keep Non-pretty format */
9544 vty_out(vty
, "%s\n", json_object_to_json_string(json
));
9548 json_object_free(json
);
9553 DEFUN (show_ip_ospf_instance_route
,
9554 show_ip_ospf_instance_route_cmd
,
9555 "show ip ospf (1-65535) route",
9558 "OSPF information\n"
9560 "OSPF routing table\n")
9564 u_short instance
= 0;
9566 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9567 ospf
= ospf_lookup_instance(instance
);
9569 return CMD_NOT_MY_INSTANCE
;
9571 if (!ospf
->oi_running
)
9574 return show_ip_ospf_route_common(vty
, ospf
, NULL
, 0);
9578 DEFUN (show_ip_ospf_vrfs
,
9579 show_ip_ospf_vrfs_cmd
,
9580 "show ip ospf vrfs [json]",
9583 "OSPF information\n"
9587 u_char uj
= use_json(argc
, argv
);
9588 json_object
*json
= NULL
;
9589 json_object
*json_vrfs
= NULL
;
9590 struct ospf
*ospf
= NULL
;
9591 struct listnode
*node
= NULL
;
9593 static char header
[] = "Name Id RouterId ";
9596 json
= json_object_new_object();
9597 json_vrfs
= json_object_new_object();
9600 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9601 json_object
*json_vrf
= NULL
;
9602 const char *name
= NULL
;
9607 if (!uj
&& count
== 1)
9608 vty_out(vty
, "%s\n", header
);
9610 json_vrf
= json_object_new_object();
9612 if (ospf
->vrf_id
== 0)
9613 name
= VRF_DEFAULT_NAME
;
9617 vrf_id_ui
= (ospf
->vrf_id
== VRF_UNKNOWN
) ? -1 : ospf
->vrf_id
;
9620 json_object_int_add(json_vrf
, "vrfId", vrf_id_ui
);
9621 json_object_string_add(json_vrf
, "routerId",
9622 inet_ntoa(ospf
->router_id
));
9624 json_object_object_add(json_vrfs
, name
, json_vrf
);
9627 vty_out(vty
, "%-25s %-5d %-16s \n",
9628 name
, ospf
->vrf_id
, inet_ntoa(ospf
->router_id
));
9633 json_object_object_add(json
, "vrfs", json_vrfs
);
9634 json_object_int_add(json
, "totalVrfs", count
);
9636 vty_out(vty
, "%s\n", json_object_to_json_string_ext(json
,
9637 JSON_C_TO_STRING_PRETTY
));
9638 json_object_free(json
);
9641 vty_out(vty
, "\nTotal number of OSPF VRFs: %d\n",
9648 const char *ospf_abr_type_str
[] = {"unknown", "standard", "ibm", "cisco",
9651 const char *ospf_shortcut_mode_str
[] = {"default", "enable", "disable"};
9653 const char *ospf_int_type_str
[] = {"unknown", /* should never be used. */
9654 "point-to-point", "broadcast",
9655 "non-broadcast", "point-to-multipoint",
9656 "virtual-link", /* should never be used. */
9659 static int config_write_interface_one(struct vty
*vty
, struct vrf
*vrf
)
9661 struct listnode
*node
;
9662 struct interface
*ifp
;
9663 struct crypt_key
*ck
;
9664 struct route_node
*rn
= NULL
;
9665 struct ospf_if_params
*params
;
9667 struct ospf
*ospf
= vrf
->info
;
9669 FOR_ALL_INTERFACES (vrf
, ifp
) {
9671 if (memcmp(ifp
->name
, "VLINK", 5) == 0)
9674 vty_frame(vty
, "!\n");
9675 if (ifp
->vrf_id
== VRF_DEFAULT
)
9676 vty_frame(vty
, "interface %s\n", ifp
->name
);
9678 vty_frame(vty
, "interface %s vrf %s\n",
9679 ifp
->name
, vrf
->name
);
9681 vty_out(vty
, " description %s\n", ifp
->desc
);
9685 params
= IF_DEF_PARAMS(ifp
);
9688 /* Interface Network print. */
9689 if (OSPF_IF_PARAM_CONFIGURED(params
, type
)
9690 && params
->type
!= OSPF_IFTYPE_LOOPBACK
) {
9692 ospf_default_iftype(ifp
)) {
9693 vty_out(vty
, " ip ospf network %s",
9696 if (params
!= IF_DEF_PARAMS(ifp
))
9704 /* OSPF interface authentication print */
9705 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_type
)
9706 && params
->auth_type
!= OSPF_AUTH_NOTSET
) {
9707 const char *auth_str
;
9709 /* Translation tables are not that much help
9710 * here due to syntax
9711 * of the simple option */
9712 switch (params
->auth_type
) {
9714 case OSPF_AUTH_NULL
:
9718 case OSPF_AUTH_SIMPLE
:
9722 case OSPF_AUTH_CRYPTOGRAPHIC
:
9723 auth_str
= " message-digest";
9731 vty_out(vty
, " ip ospf authentication%s",
9733 if (params
!= IF_DEF_PARAMS(ifp
))
9735 inet_ntoa(rn
->p
.u
.prefix4
));
9739 /* Simple Authentication Password print. */
9740 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_simple
)
9741 && params
->auth_simple
[0] != '\0') {
9742 vty_out(vty
, " ip ospf authentication-key %s",
9743 params
->auth_simple
);
9744 if (params
!= IF_DEF_PARAMS(ifp
))
9746 inet_ntoa(rn
->p
.u
.prefix4
));
9750 /* Cryptographic Authentication Key print. */
9751 if (params
&& params
->auth_crypt
) {
9752 for (ALL_LIST_ELEMENTS_RO(
9756 " ip ospf message-digest-key %d md5 %s",
9759 if (params
!= IF_DEF_PARAMS(ifp
))
9761 inet_ntoa(rn
->p
.u
.prefix4
));
9766 /* Interface Output Cost print. */
9767 if (OSPF_IF_PARAM_CONFIGURED(params
,
9769 vty_out(vty
, " ip ospf cost %u",
9770 params
->output_cost_cmd
);
9771 if (params
!= IF_DEF_PARAMS(ifp
))
9773 inet_ntoa(rn
->p
.u
.prefix4
));
9777 /* Hello Interval print. */
9778 if (OSPF_IF_PARAM_CONFIGURED(params
, v_hello
)
9779 && params
->v_hello
!=
9780 OSPF_HELLO_INTERVAL_DEFAULT
) {
9781 vty_out(vty
, " ip ospf hello-interval %u",
9783 if (params
!= IF_DEF_PARAMS(ifp
))
9785 inet_ntoa(rn
->p
.u
.prefix4
));
9790 /* Router Dead Interval print. */
9791 if (OSPF_IF_PARAM_CONFIGURED(params
, v_wait
)
9793 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
) {
9794 vty_out(vty
, " ip ospf dead-interval ");
9797 if (OSPF_IF_PARAM_CONFIGURED(params
,
9800 "minimal hello-multiplier %d",
9801 params
->fast_hello
);
9806 if (params
!= IF_DEF_PARAMS(ifp
))
9808 inet_ntoa(rn
->p
.u
.prefix4
));
9812 /* Router Priority print. */
9813 if (OSPF_IF_PARAM_CONFIGURED(params
, priority
)
9815 != OSPF_ROUTER_PRIORITY_DEFAULT
) {
9816 vty_out(vty
, " ip ospf priority %u",
9818 if (params
!= IF_DEF_PARAMS(ifp
))
9820 inet_ntoa(rn
->p
.u
.prefix4
));
9824 /* Retransmit Interval print. */
9825 if (OSPF_IF_PARAM_CONFIGURED(params
,
9826 retransmit_interval
)
9827 && params
->retransmit_interval
9828 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
) {
9829 vty_out(vty
, " ip ospf retransmit-interval %u",
9830 params
->retransmit_interval
);
9831 if (params
!= IF_DEF_PARAMS(ifp
))
9833 inet_ntoa(rn
->p
.u
.prefix4
));
9837 /* Transmit Delay print. */
9838 if (OSPF_IF_PARAM_CONFIGURED(params
,
9840 && params
->transmit_delay
9841 != OSPF_TRANSMIT_DELAY_DEFAULT
) {
9842 vty_out(vty
, " ip ospf transmit-delay %u",
9843 params
->transmit_delay
);
9844 if (params
!= IF_DEF_PARAMS(ifp
))
9846 inet_ntoa(rn
->p
.u
.prefix4
));
9851 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
9852 if (ospf
&& ospf
->instance
)
9853 vty_out(vty
, " ip ospf %d",
9856 vty_out(vty
, " ip ospf");
9859 size_t buflen
= MAX(strlen("4294967295"),
9860 strlen("255.255.255.255"));
9863 area_id2str(buf
, sizeof(buf
),
9865 params
->if_area_id_fmt
);
9866 vty_out(vty
, " area %s", buf
);
9867 if (params
!= IF_DEF_PARAMS(ifp
))
9869 inet_ntoa(rn
->p
.u
.prefix4
));
9874 if (params
->bfd_info
)
9875 ospf_bfd_write_config(vty
, params
);
9877 /* MTU ignore print. */
9878 if (OSPF_IF_PARAM_CONFIGURED(params
, mtu_ignore
)
9879 && params
->mtu_ignore
!=
9880 OSPF_MTU_IGNORE_DEFAULT
) {
9881 if (params
->mtu_ignore
== 0)
9882 vty_out(vty
, " no ip ospf mtu-ignore");
9884 vty_out(vty
, " ip ospf mtu-ignore");
9885 if (params
!= IF_DEF_PARAMS(ifp
))
9887 inet_ntoa(rn
->p
.u
.prefix4
));
9895 IF_OIFS_PARAMS(ifp
));
9897 rn
= route_next(rn
);
9907 ospf_opaque_config_write_if(vty
, ifp
);
9909 vty_endframe(vty
, NULL
);
9915 /* Configuration write function for ospfd. */
9916 static int config_write_interface(struct vty
*vty
)
9919 struct vrf
*vrf
= NULL
;
9921 /* Display all VRF aware OSPF interface configuration */
9922 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
9923 write
+= config_write_interface_one(vty
, vrf
);
9929 static int config_write_network_area(struct vty
*vty
, struct ospf
*ospf
)
9931 struct route_node
*rn
;
9932 u_char buf
[INET_ADDRSTRLEN
];
9934 /* `network area' print. */
9935 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
))
9937 struct ospf_network
*n
= rn
->info
;
9939 memset(buf
, 0, INET_ADDRSTRLEN
);
9941 /* Create Area ID string by specified Area ID format. */
9942 if (n
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
9943 strncpy((char *)buf
, inet_ntoa(n
->area_id
),
9946 sprintf((char *)buf
, "%lu",
9947 (unsigned long int)ntohl(
9948 n
->area_id
.s_addr
));
9950 /* Network print. */
9951 vty_out(vty
, " network %s/%d area %s\n",
9952 inet_ntoa(rn
->p
.u
.prefix4
), rn
->p
.prefixlen
,
9959 static int config_write_ospf_area(struct vty
*vty
, struct ospf
*ospf
)
9961 struct listnode
*node
;
9962 struct ospf_area
*area
;
9963 u_char buf
[INET_ADDRSTRLEN
];
9965 /* Area configuration print. */
9966 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
9967 struct route_node
*rn1
;
9969 area_id2str((char *)buf
, INET_ADDRSTRLEN
, &area
->area_id
,
9972 if (area
->auth_type
!= OSPF_AUTH_NULL
) {
9973 if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
9974 vty_out(vty
, " area %s authentication\n", buf
);
9977 " area %s authentication message-digest\n",
9981 if (area
->shortcut_configured
!= OSPF_SHORTCUT_DEFAULT
)
9982 vty_out(vty
, " area %s shortcut %s\n", buf
,
9983 ospf_shortcut_mode_str
9984 [area
->shortcut_configured
]);
9986 if ((area
->external_routing
== OSPF_AREA_STUB
)
9987 || (area
->external_routing
== OSPF_AREA_NSSA
)) {
9988 if (area
->external_routing
== OSPF_AREA_STUB
) {
9989 vty_out(vty
, " area %s stub", buf
);
9990 if (area
->no_summary
)
9991 vty_out(vty
, " no-summary\n");
9993 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
9994 switch (area
->NSSATranslatorRole
) {
9995 case OSPF_NSSA_ROLE_NEVER
:
9997 " area %s nssa translate-never\n",
10000 case OSPF_NSSA_ROLE_ALWAYS
:
10002 " area %s nssa translate-always\n",
10005 case OSPF_NSSA_ROLE_CANDIDATE
:
10006 vty_out(vty
, " area %s nssa \n", buf
);
10009 if (area
->no_summary
)
10011 " area %s nssa no-summary\n",
10015 if (area
->default_cost
!= 1)
10016 vty_out(vty
, " area %s default-cost %d\n", buf
,
10017 area
->default_cost
);
10020 for (rn1
= route_top(area
->ranges
); rn1
; rn1
= route_next(rn1
))
10022 struct ospf_area_range
*range
= rn1
->info
;
10024 vty_out(vty
, " area %s range %s/%d", buf
,
10025 inet_ntoa(rn1
->p
.u
.prefix4
),
10028 if (range
->cost_config
10029 != OSPF_AREA_RANGE_COST_UNSPEC
)
10030 vty_out(vty
, " cost %d",
10031 range
->cost_config
);
10033 if (!CHECK_FLAG(range
->flags
,
10034 OSPF_AREA_RANGE_ADVERTISE
))
10035 vty_out(vty
, " not-advertise");
10037 if (CHECK_FLAG(range
->flags
,
10038 OSPF_AREA_RANGE_SUBSTITUTE
))
10039 vty_out(vty
, " substitute %s/%d",
10040 inet_ntoa(range
->subst_addr
),
10041 range
->subst_masklen
);
10043 vty_out(vty
, "\n");
10046 if (EXPORT_NAME(area
))
10047 vty_out(vty
, " area %s export-list %s\n", buf
,
10048 EXPORT_NAME(area
));
10050 if (IMPORT_NAME(area
))
10051 vty_out(vty
, " area %s import-list %s\n", buf
,
10052 IMPORT_NAME(area
));
10054 if (PREFIX_NAME_IN(area
))
10055 vty_out(vty
, " area %s filter-list prefix %s in\n", buf
,
10056 PREFIX_NAME_IN(area
));
10058 if (PREFIX_NAME_OUT(area
))
10059 vty_out(vty
, " area %s filter-list prefix %s out\n",
10060 buf
, PREFIX_NAME_OUT(area
));
10066 static int config_write_ospf_nbr_nbma(struct vty
*vty
, struct ospf
*ospf
)
10068 struct ospf_nbr_nbma
*nbr_nbma
;
10069 struct route_node
*rn
;
10071 /* Static Neighbor configuration print. */
10072 for (rn
= route_top(ospf
->nbr_nbma
); rn
; rn
= route_next(rn
))
10073 if ((nbr_nbma
= rn
->info
)) {
10074 vty_out(vty
, " neighbor %s", inet_ntoa(nbr_nbma
->addr
));
10076 if (nbr_nbma
->priority
10077 != OSPF_NEIGHBOR_PRIORITY_DEFAULT
)
10078 vty_out(vty
, " priority %d",
10079 nbr_nbma
->priority
);
10081 if (nbr_nbma
->v_poll
!= OSPF_POLL_INTERVAL_DEFAULT
)
10082 vty_out(vty
, " poll-interval %d",
10085 vty_out(vty
, "\n");
10091 static int config_write_virtual_link(struct vty
*vty
, struct ospf
*ospf
)
10093 struct listnode
*node
;
10094 struct ospf_vl_data
*vl_data
;
10095 char buf
[INET_ADDRSTRLEN
];
10097 /* Virtual-Link print */
10098 for (ALL_LIST_ELEMENTS_RO(ospf
->vlinks
, node
, vl_data
)) {
10099 struct listnode
*n2
;
10100 struct crypt_key
*ck
;
10101 struct ospf_interface
*oi
;
10103 if (vl_data
!= NULL
) {
10104 memset(buf
, 0, INET_ADDRSTRLEN
);
10106 area_id2str(buf
, sizeof(buf
), &vl_data
->vl_area_id
,
10107 vl_data
->vl_area_id_fmt
);
10108 oi
= vl_data
->vl_oi
;
10111 if (OSPF_IF_PARAM(oi
, v_hello
)
10112 != OSPF_HELLO_INTERVAL_DEFAULT
10113 || OSPF_IF_PARAM(oi
, v_wait
)
10114 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
10115 || OSPF_IF_PARAM(oi
, retransmit_interval
)
10116 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
10117 || OSPF_IF_PARAM(oi
, transmit_delay
)
10118 != OSPF_TRANSMIT_DELAY_DEFAULT
)
10120 " area %s virtual-link %s hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n",
10121 buf
, inet_ntoa(vl_data
->vl_peer
),
10122 OSPF_IF_PARAM(oi
, v_hello
),
10123 OSPF_IF_PARAM(oi
, retransmit_interval
),
10124 OSPF_IF_PARAM(oi
, transmit_delay
),
10125 OSPF_IF_PARAM(oi
, v_wait
));
10127 vty_out(vty
, " area %s virtual-link %s\n", buf
,
10128 inet_ntoa(vl_data
->vl_peer
));
10130 if (IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)->auth_simple
[0]
10133 " area %s virtual-link %s authentication-key %s\n",
10134 buf
, inet_ntoa(vl_data
->vl_peer
),
10135 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
10138 for (ALL_LIST_ELEMENTS_RO(
10139 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
10143 " area %s virtual-link %s"
10144 " message-digest-key %d md5 %s\n",
10145 buf
, inet_ntoa(vl_data
->vl_peer
),
10146 ck
->key_id
, ck
->auth_key
);
10154 static int config_write_ospf_redistribute(struct vty
*vty
, struct ospf
*ospf
)
10158 /* redistribute print. */
10159 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
10160 struct list
*red_list
;
10161 struct listnode
*node
;
10162 struct ospf_redist
*red
;
10164 red_list
= ospf
->redist
[type
];
10168 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
10169 vty_out(vty
, " redistribute %s",
10170 zebra_route_string(type
));
10172 vty_out(vty
, " %d", red
->instance
);
10174 if (red
->dmetric
.value
>= 0)
10175 vty_out(vty
, " metric %d", red
->dmetric
.value
);
10177 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
10178 vty_out(vty
, " metric-type 1");
10180 if (ROUTEMAP_NAME(red
))
10181 vty_out(vty
, " route-map %s",
10182 ROUTEMAP_NAME(red
));
10184 vty_out(vty
, "\n");
10191 static int config_write_ospf_default_metric(struct vty
*vty
, struct ospf
*ospf
)
10193 if (ospf
->default_metric
!= -1)
10194 vty_out(vty
, " default-metric %d\n", ospf
->default_metric
);
10198 static int config_write_ospf_distribute(struct vty
*vty
, struct ospf
*ospf
)
10201 struct ospf_redist
*red
;
10204 /* distribute-list print. */
10205 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
10206 if (DISTRIBUTE_NAME(ospf
, type
))
10207 vty_out(vty
, " distribute-list %s out %s\n",
10208 DISTRIBUTE_NAME(ospf
, type
),
10209 zebra_route_string(type
));
10211 /* default-information print. */
10212 if (ospf
->default_originate
!= DEFAULT_ORIGINATE_NONE
) {
10213 vty_out(vty
, " default-information originate");
10214 if (ospf
->default_originate
== DEFAULT_ORIGINATE_ALWAYS
)
10215 vty_out(vty
, " always");
10217 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
10219 if (red
->dmetric
.value
>= 0)
10220 vty_out(vty
, " metric %d",
10221 red
->dmetric
.value
);
10222 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
10223 vty_out(vty
, " metric-type 1");
10225 if (ROUTEMAP_NAME(red
))
10226 vty_out(vty
, " route-map %s",
10227 ROUTEMAP_NAME(red
));
10230 vty_out(vty
, "\n");
10237 static int config_write_ospf_distance(struct vty
*vty
, struct ospf
*ospf
)
10239 struct route_node
*rn
;
10240 struct ospf_distance
*odistance
;
10242 if (ospf
->distance_all
)
10243 vty_out(vty
, " distance %d\n", ospf
->distance_all
);
10245 if (ospf
->distance_intra
|| ospf
->distance_inter
10246 || ospf
->distance_external
) {
10247 vty_out(vty
, " distance ospf");
10249 if (ospf
->distance_intra
)
10250 vty_out(vty
, " intra-area %d", ospf
->distance_intra
);
10251 if (ospf
->distance_inter
)
10252 vty_out(vty
, " inter-area %d", ospf
->distance_inter
);
10253 if (ospf
->distance_external
)
10254 vty_out(vty
, " external %d", ospf
->distance_external
);
10256 vty_out(vty
, "\n");
10259 for (rn
= route_top(ospf
->distance_table
); rn
; rn
= route_next(rn
))
10260 if ((odistance
= rn
->info
) != NULL
) {
10261 vty_out(vty
, " distance %d %s/%d %s\n",
10262 odistance
->distance
, inet_ntoa(rn
->p
.u
.prefix4
),
10264 odistance
->access_list
? odistance
->access_list
10270 static int ospf_config_write_one(struct vty
*vty
, struct ospf
*ospf
)
10272 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
10273 struct interface
*ifp
;
10274 struct ospf_interface
*oi
;
10275 struct listnode
*node
= NULL
;
10278 /* `router ospf' print. */
10279 if (ospf
->instance
&& ospf
->name
) {
10280 vty_out(vty
, "router ospf %d vrf %s\n",
10281 ospf
->instance
, ospf
->name
);
10282 } else if (ospf
->instance
) {
10283 vty_out(vty
, "router ospf %d\n",
10285 } else if (ospf
->name
) {
10286 vty_out(vty
, "router ospf vrf %s\n",
10289 vty_out(vty
, "router ospf\n");
10291 if (!ospf
->networks
) {
10296 /* Router ID print. */
10297 if (ospf
->router_id_static
.s_addr
!= 0)
10298 vty_out(vty
, " ospf router-id %s\n",
10299 inet_ntoa(ospf
->router_id_static
));
10301 /* ABR type print. */
10302 if (ospf
->abr_type
!= OSPF_ABR_DEFAULT
)
10303 vty_out(vty
, " ospf abr-type %s\n",
10304 ospf_abr_type_str
[ospf
->abr_type
]);
10306 /* log-adjacency-changes flag print. */
10307 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
10308 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
))
10309 vty_out(vty
, " log-adjacency-changes detail\n");
10310 else if (!DFLT_OSPF_LOG_ADJACENCY_CHANGES
)
10311 vty_out(vty
, " log-adjacency-changes\n");
10312 } else if (DFLT_OSPF_LOG_ADJACENCY_CHANGES
) {
10313 vty_out(vty
, " no log-adjacency-changes\n");
10316 /* RFC1583 compatibility flag print -- Compatible with CISCO
10318 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
))
10319 vty_out(vty
, " compatible rfc1583\n");
10321 /* auto-cost reference-bandwidth configuration. */
10322 if (ospf
->ref_bandwidth
!= OSPF_DEFAULT_REF_BANDWIDTH
) {
10324 "! Important: ensure reference bandwidth "
10325 "is consistent across all routers\n");
10326 vty_out(vty
, " auto-cost reference-bandwidth %d\n",
10327 ospf
->ref_bandwidth
);
10330 /* SPF timers print. */
10331 if (ospf
->spf_delay
!= OSPF_SPF_DELAY_DEFAULT
10332 || ospf
->spf_holdtime
!= OSPF_SPF_HOLDTIME_DEFAULT
10333 || ospf
->spf_max_holdtime
!= OSPF_SPF_MAX_HOLDTIME_DEFAULT
)
10334 vty_out(vty
, " timers throttle spf %d %d %d\n",
10335 ospf
->spf_delay
, ospf
->spf_holdtime
,
10336 ospf
->spf_max_holdtime
);
10338 /* LSA timers print. */
10339 if (ospf
->min_ls_interval
!= OSPF_MIN_LS_INTERVAL
)
10340 vty_out(vty
, " timers throttle lsa all %d\n",
10341 ospf
->min_ls_interval
);
10342 if (ospf
->min_ls_arrival
!= OSPF_MIN_LS_ARRIVAL
)
10343 vty_out(vty
, " timers lsa min-arrival %d\n",
10344 ospf
->min_ls_arrival
);
10346 /* Write multiplier print. */
10347 if (ospf
->write_oi_count
!= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
)
10348 vty_out(vty
, " ospf write-multiplier %d\n",
10349 ospf
->write_oi_count
);
10351 /* Max-metric router-lsa print */
10352 config_write_stub_router(vty
, ospf
);
10354 /* SPF refresh parameters print. */
10355 if (ospf
->lsa_refresh_interval
10356 != OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
10357 vty_out(vty
, " refresh timer %d\n",
10358 ospf
->lsa_refresh_interval
);
10360 /* Redistribute information print. */
10361 config_write_ospf_redistribute(vty
, ospf
);
10363 /* passive-interface print. */
10364 if (ospf
->passive_interface_default
== OSPF_IF_PASSIVE
)
10365 vty_out(vty
, " passive-interface default\n");
10367 FOR_ALL_INTERFACES (vrf
, ifp
)
10368 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp
),
10370 && IF_DEF_PARAMS(ifp
)->passive_interface
10371 != ospf
->passive_interface_default
) {
10372 vty_out(vty
, " %spassive-interface %s\n",
10373 IF_DEF_PARAMS(ifp
)->passive_interface
10378 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
10379 if (!OSPF_IF_PARAM_CONFIGURED(oi
->params
,
10380 passive_interface
))
10382 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(oi
->ifp
),
10383 passive_interface
)) {
10384 if (oi
->params
->passive_interface
10385 == IF_DEF_PARAMS(oi
->ifp
)
10386 ->passive_interface
)
10388 } else if (oi
->params
->passive_interface
10389 == ospf
->passive_interface_default
)
10392 vty_out(vty
, " %spassive-interface %s %s\n",
10393 oi
->params
->passive_interface
? "" : "no ",
10395 inet_ntoa(oi
->address
->u
.prefix4
));
10398 /* Network area print. */
10399 config_write_network_area(vty
, ospf
);
10401 /* Area config print. */
10402 config_write_ospf_area(vty
, ospf
);
10404 /* static neighbor print. */
10405 config_write_ospf_nbr_nbma(vty
, ospf
);
10407 /* Virtual-Link print. */
10408 config_write_virtual_link(vty
, ospf
);
10410 /* Default metric configuration. */
10411 config_write_ospf_default_metric(vty
, ospf
);
10413 /* Distribute-list and default-information print. */
10414 config_write_ospf_distribute(vty
, ospf
);
10416 /* Distance configuration. */
10417 config_write_ospf_distance(vty
, ospf
);
10419 ospf_opaque_config_write_router(vty
, ospf
);
10425 /* OSPF configuration write function. */
10426 static int ospf_config_write(struct vty
*vty
)
10429 struct listnode
*ospf_node
= NULL
;
10432 if (listcount(om
->ospf
) == 0)
10435 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, ospf_node
, ospf
)) {
10436 /* VRF Default check if it is running.
10437 * Upon daemon start, there could be default instance
10438 * in absence of 'router ospf'/oi_running is disabled. */
10439 if (ospf
->vrf_id
== VRF_DEFAULT
&& ospf
->oi_running
)
10440 write
+= ospf_config_write_one(vty
, ospf
);
10441 /* For Non-Default VRF simply display the configuration,
10442 * even if it is not oi_running. */
10443 else if (ospf
->vrf_id
!= VRF_DEFAULT
)
10444 write
+= ospf_config_write_one(vty
, ospf
);
10449 void ospf_vty_show_init(void)
10451 /* "show ip ospf" commands. */
10452 install_element(VIEW_NODE
, &show_ip_ospf_cmd
);
10454 install_element(VIEW_NODE
, &show_ip_ospf_instance_cmd
);
10456 /* "show ip ospf database" commands. */
10457 install_element(VIEW_NODE
, &show_ip_ospf_database_max_cmd
);
10459 install_element(VIEW_NODE
,
10460 &show_ip_ospf_instance_database_type_adv_router_cmd
);
10461 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_cmd
);
10462 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_max_cmd
);
10464 /* "show ip ospf interface" commands. */
10465 install_element(VIEW_NODE
, &show_ip_ospf_interface_cmd
);
10467 install_element(VIEW_NODE
, &show_ip_ospf_instance_interface_cmd
);
10468 /* "show ip ospf interface traffic */
10469 install_element(VIEW_NODE
, &show_ip_ospf_interface_traffic_cmd
);
10471 /* "show ip ospf neighbor" commands. */
10472 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_detail_cmd
);
10473 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_cmd
);
10474 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_id_cmd
);
10475 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_all_cmd
);
10476 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_cmd
);
10477 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_cmd
);
10478 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_all_cmd
);
10480 install_element(VIEW_NODE
,
10481 &show_ip_ospf_instance_neighbor_int_detail_cmd
);
10482 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_int_cmd
);
10483 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_id_cmd
);
10484 install_element(VIEW_NODE
,
10485 &show_ip_ospf_instance_neighbor_detail_all_cmd
);
10486 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_detail_cmd
);
10487 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_cmd
);
10488 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_all_cmd
);
10490 /* "show ip ospf route" commands. */
10491 install_element(VIEW_NODE
, &show_ip_ospf_route_cmd
);
10492 install_element(VIEW_NODE
, &show_ip_ospf_border_routers_cmd
);
10494 install_element(VIEW_NODE
, &show_ip_ospf_instance_route_cmd
);
10495 install_element(VIEW_NODE
, &show_ip_ospf_instance_border_routers_cmd
);
10497 /* "show ip ospf vrfs" commands. */
10498 install_element(VIEW_NODE
, &show_ip_ospf_vrfs_cmd
);
10502 /* ospfd's interface node. */
10503 static struct cmd_node interface_node
= {INTERFACE_NODE
, "%s(config-if)# ", 1};
10505 /* Initialization of OSPF interface. */
10506 static void ospf_vty_if_init(void)
10508 /* Install interface node. */
10509 install_node(&interface_node
, config_write_interface
);
10512 /* "ip ospf authentication" commands. */
10513 install_element(INTERFACE_NODE
, &ip_ospf_authentication_args_addr_cmd
);
10514 install_element(INTERFACE_NODE
, &ip_ospf_authentication_addr_cmd
);
10515 install_element(INTERFACE_NODE
,
10516 &no_ip_ospf_authentication_args_addr_cmd
);
10517 install_element(INTERFACE_NODE
, &no_ip_ospf_authentication_addr_cmd
);
10518 install_element(INTERFACE_NODE
, &ip_ospf_authentication_key_addr_cmd
);
10519 install_element(INTERFACE_NODE
,
10520 &no_ip_ospf_authentication_key_authkey_addr_cmd
);
10521 install_element(INTERFACE_NODE
,
10522 &no_ospf_authentication_key_authkey_addr_cmd
);
10524 /* "ip ospf message-digest-key" commands. */
10525 install_element(INTERFACE_NODE
, &ip_ospf_message_digest_key_cmd
);
10526 install_element(INTERFACE_NODE
, &no_ip_ospf_message_digest_key_cmd
);
10528 /* "ip ospf cost" commands. */
10529 install_element(INTERFACE_NODE
, &ip_ospf_cost_cmd
);
10530 install_element(INTERFACE_NODE
, &no_ip_ospf_cost_cmd
);
10532 /* "ip ospf mtu-ignore" commands. */
10533 install_element(INTERFACE_NODE
, &ip_ospf_mtu_ignore_addr_cmd
);
10534 install_element(INTERFACE_NODE
, &no_ip_ospf_mtu_ignore_addr_cmd
);
10536 /* "ip ospf dead-interval" commands. */
10537 install_element(INTERFACE_NODE
, &ip_ospf_dead_interval_cmd
);
10538 install_element(INTERFACE_NODE
,
10539 &ip_ospf_dead_interval_minimal_addr_cmd
);
10540 install_element(INTERFACE_NODE
, &no_ip_ospf_dead_interval_cmd
);
10542 /* "ip ospf hello-interval" commands. */
10543 install_element(INTERFACE_NODE
, &ip_ospf_hello_interval_cmd
);
10544 install_element(INTERFACE_NODE
, &no_ip_ospf_hello_interval_cmd
);
10546 /* "ip ospf network" commands. */
10547 install_element(INTERFACE_NODE
, &ip_ospf_network_cmd
);
10548 install_element(INTERFACE_NODE
, &no_ip_ospf_network_cmd
);
10550 /* "ip ospf priority" commands. */
10551 install_element(INTERFACE_NODE
, &ip_ospf_priority_cmd
);
10552 install_element(INTERFACE_NODE
, &no_ip_ospf_priority_cmd
);
10554 /* "ip ospf retransmit-interval" commands. */
10555 install_element(INTERFACE_NODE
, &ip_ospf_retransmit_interval_addr_cmd
);
10556 install_element(INTERFACE_NODE
,
10557 &no_ip_ospf_retransmit_interval_addr_cmd
);
10559 /* "ip ospf transmit-delay" commands. */
10560 install_element(INTERFACE_NODE
, &ip_ospf_transmit_delay_addr_cmd
);
10561 install_element(INTERFACE_NODE
, &no_ip_ospf_transmit_delay_addr_cmd
);
10563 /* "ip ospf area" commands. */
10564 install_element(INTERFACE_NODE
, &ip_ospf_area_cmd
);
10565 install_element(INTERFACE_NODE
, &no_ip_ospf_area_cmd
);
10567 /* These commands are compatibitliy for previous version. */
10568 install_element(INTERFACE_NODE
, &ospf_authentication_key_cmd
);
10569 install_element(INTERFACE_NODE
, &ospf_message_digest_key_cmd
);
10570 install_element(INTERFACE_NODE
, &no_ospf_message_digest_key_cmd
);
10571 install_element(INTERFACE_NODE
, &ospf_dead_interval_cmd
);
10572 install_element(INTERFACE_NODE
, &no_ospf_dead_interval_cmd
);
10573 install_element(INTERFACE_NODE
, &ospf_hello_interval_cmd
);
10574 install_element(INTERFACE_NODE
, &no_ospf_hello_interval_cmd
);
10575 install_element(INTERFACE_NODE
, &ospf_cost_cmd
);
10576 install_element(INTERFACE_NODE
, &no_ospf_cost_cmd
);
10577 install_element(INTERFACE_NODE
, &ospf_network_cmd
);
10578 install_element(INTERFACE_NODE
, &no_ospf_network_cmd
);
10579 install_element(INTERFACE_NODE
, &ospf_priority_cmd
);
10580 install_element(INTERFACE_NODE
, &no_ospf_priority_cmd
);
10581 install_element(INTERFACE_NODE
, &ospf_retransmit_interval_cmd
);
10582 install_element(INTERFACE_NODE
, &no_ospf_retransmit_interval_cmd
);
10583 install_element(INTERFACE_NODE
, &ospf_transmit_delay_cmd
);
10584 install_element(INTERFACE_NODE
, &no_ospf_transmit_delay_cmd
);
10587 static void ospf_vty_zebra_init(void)
10589 install_element(OSPF_NODE
, &ospf_redistribute_source_cmd
);
10590 install_element(OSPF_NODE
, &no_ospf_redistribute_source_cmd
);
10591 install_element(OSPF_NODE
, &ospf_redistribute_instance_source_cmd
);
10592 install_element(OSPF_NODE
, &no_ospf_redistribute_instance_source_cmd
);
10594 install_element(OSPF_NODE
, &ospf_distribute_list_out_cmd
);
10595 install_element(OSPF_NODE
, &no_ospf_distribute_list_out_cmd
);
10597 install_element(OSPF_NODE
, &ospf_default_information_originate_cmd
);
10598 install_element(OSPF_NODE
, &no_ospf_default_information_originate_cmd
);
10600 install_element(OSPF_NODE
, &ospf_default_metric_cmd
);
10601 install_element(OSPF_NODE
, &no_ospf_default_metric_cmd
);
10603 install_element(OSPF_NODE
, &ospf_distance_cmd
);
10604 install_element(OSPF_NODE
, &no_ospf_distance_cmd
);
10605 install_element(OSPF_NODE
, &no_ospf_distance_ospf_cmd
);
10606 install_element(OSPF_NODE
, &ospf_distance_ospf_cmd
);
10608 install_element (OSPF_NODE
, &ospf_distance_source_cmd
);
10609 install_element (OSPF_NODE
, &no_ospf_distance_source_cmd
);
10610 install_element (OSPF_NODE
, &ospf_distance_source_access_list_cmd
);
10611 install_element (OSPF_NODE
, &no_ospf_distance_source_access_list_cmd
);
10615 static struct cmd_node ospf_node
= {OSPF_NODE
, "%s(config-router)# ", 1};
10617 static void ospf_interface_clear(struct interface
*ifp
)
10619 if (!if_is_operative(ifp
))
10622 if (IS_DEBUG_OSPF(ism
, ISM_EVENTS
))
10623 zlog_debug("ISM[%s]: clear by reset", ifp
->name
);
10625 ospf_if_reset(ifp
);
10628 DEFUN (clear_ip_ospf_interface
,
10629 clear_ip_ospf_interface_cmd
,
10630 "clear ip ospf interface [IFNAME]",
10633 "OSPF information\n"
10634 "Interface information\n"
10635 "Interface name\n")
10637 int idx_ifname
= 4;
10638 struct interface
*ifp
;
10639 struct listnode
*node
;
10640 struct ospf
*ospf
= NULL
;
10642 if (argc
== 4) /* Clear all the ospfv2 interfaces. */
10644 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
10645 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
10646 FOR_ALL_INTERFACES (vrf
, ifp
)
10647 ospf_interface_clear(ifp
);
10650 /* Interface name is specified. */
10651 ifp
= if_lookup_by_name_all_vrf(argv
[idx_ifname
]->arg
);
10653 vty_out(vty
, "No such interface name\n");
10655 ospf_interface_clear(ifp
);
10658 return CMD_SUCCESS
;
10661 void ospf_vty_clear_init(void)
10663 install_element(ENABLE_NODE
, &clear_ip_ospf_interface_cmd
);
10667 /* Install OSPF related vty commands. */
10668 void ospf_vty_init(void)
10670 /* Install ospf top node. */
10671 install_node(&ospf_node
, ospf_config_write
);
10673 /* "router ospf" commands. */
10674 install_element(CONFIG_NODE
, &router_ospf_cmd
);
10675 install_element(CONFIG_NODE
, &no_router_ospf_cmd
);
10678 install_default(OSPF_NODE
);
10680 /* "ospf router-id" commands. */
10681 install_element(OSPF_NODE
, &ospf_router_id_cmd
);
10682 install_element(OSPF_NODE
, &ospf_router_id_old_cmd
);
10683 install_element(OSPF_NODE
, &no_ospf_router_id_cmd
);
10685 /* "passive-interface" commands. */
10686 install_element(OSPF_NODE
, &ospf_passive_interface_addr_cmd
);
10687 install_element(OSPF_NODE
, &no_ospf_passive_interface_addr_cmd
);
10689 /* "ospf abr-type" commands. */
10690 install_element(OSPF_NODE
, &ospf_abr_type_cmd
);
10691 install_element(OSPF_NODE
, &no_ospf_abr_type_cmd
);
10693 /* "ospf log-adjacency-changes" commands. */
10694 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_cmd
);
10695 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_detail_cmd
);
10696 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_cmd
);
10697 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_detail_cmd
);
10699 /* "ospf rfc1583-compatible" commands. */
10700 install_element(OSPF_NODE
, &ospf_compatible_rfc1583_cmd
);
10701 install_element(OSPF_NODE
, &no_ospf_compatible_rfc1583_cmd
);
10702 install_element(OSPF_NODE
, &ospf_rfc1583_flag_cmd
);
10703 install_element(OSPF_NODE
, &no_ospf_rfc1583_flag_cmd
);
10705 /* "network area" commands. */
10706 install_element(OSPF_NODE
, &ospf_network_area_cmd
);
10707 install_element(OSPF_NODE
, &no_ospf_network_area_cmd
);
10709 /* "area authentication" commands. */
10710 install_element(OSPF_NODE
,
10711 &ospf_area_authentication_message_digest_cmd
);
10712 install_element(OSPF_NODE
, &ospf_area_authentication_cmd
);
10713 install_element(OSPF_NODE
, &no_ospf_area_authentication_cmd
);
10715 /* "area range" commands. */
10716 install_element(OSPF_NODE
, &ospf_area_range_cmd
);
10717 install_element(OSPF_NODE
, &ospf_area_range_cost_cmd
);
10718 install_element(OSPF_NODE
, &ospf_area_range_not_advertise_cmd
);
10719 install_element(OSPF_NODE
, &no_ospf_area_range_cmd
);
10720 install_element(OSPF_NODE
, &ospf_area_range_substitute_cmd
);
10721 install_element(OSPF_NODE
, &no_ospf_area_range_substitute_cmd
);
10723 /* "area virtual-link" commands. */
10724 install_element(OSPF_NODE
, &ospf_area_vlink_cmd
);
10725 install_element(OSPF_NODE
, &ospf_area_vlink_intervals_cmd
);
10726 install_element(OSPF_NODE
, &no_ospf_area_vlink_cmd
);
10727 install_element(OSPF_NODE
, &no_ospf_area_vlink_intervals_cmd
);
10730 /* "area stub" commands. */
10731 install_element(OSPF_NODE
, &ospf_area_stub_no_summary_cmd
);
10732 install_element(OSPF_NODE
, &ospf_area_stub_cmd
);
10733 install_element(OSPF_NODE
, &no_ospf_area_stub_no_summary_cmd
);
10734 install_element(OSPF_NODE
, &no_ospf_area_stub_cmd
);
10736 /* "area nssa" commands. */
10737 install_element(OSPF_NODE
, &ospf_area_nssa_cmd
);
10738 install_element(OSPF_NODE
, &ospf_area_nssa_translate_cmd
);
10739 install_element(OSPF_NODE
, &ospf_area_nssa_no_summary_cmd
);
10740 install_element(OSPF_NODE
, &no_ospf_area_nssa_no_summary_cmd
);
10741 install_element(OSPF_NODE
, &no_ospf_area_nssa_cmd
);
10743 install_element(OSPF_NODE
, &ospf_area_default_cost_cmd
);
10744 install_element(OSPF_NODE
, &no_ospf_area_default_cost_cmd
);
10746 install_element(OSPF_NODE
, &ospf_area_shortcut_cmd
);
10747 install_element(OSPF_NODE
, &no_ospf_area_shortcut_cmd
);
10749 install_element(OSPF_NODE
, &ospf_area_export_list_cmd
);
10750 install_element(OSPF_NODE
, &no_ospf_area_export_list_cmd
);
10752 install_element(OSPF_NODE
, &ospf_area_filter_list_cmd
);
10753 install_element(OSPF_NODE
, &no_ospf_area_filter_list_cmd
);
10755 install_element(OSPF_NODE
, &ospf_area_import_list_cmd
);
10756 install_element(OSPF_NODE
, &no_ospf_area_import_list_cmd
);
10758 /* SPF timer commands */
10759 install_element(OSPF_NODE
, &ospf_timers_throttle_spf_cmd
);
10760 install_element(OSPF_NODE
, &no_ospf_timers_throttle_spf_cmd
);
10762 /* LSA timers commands */
10763 install_element(OSPF_NODE
, &ospf_timers_min_ls_interval_cmd
);
10764 install_element(OSPF_NODE
, &no_ospf_timers_min_ls_interval_cmd
);
10765 install_element(OSPF_NODE
, &ospf_timers_lsa_min_arrival_cmd
);
10766 install_element(OSPF_NODE
, &no_ospf_timers_lsa_min_arrival_cmd
);
10767 install_element(OSPF_NODE
, &ospf_timers_lsa_arrival_cmd
);
10768 install_element(OSPF_NODE
, &no_ospf_timers_lsa_arrival_cmd
);
10770 /* refresh timer commands */
10771 install_element(OSPF_NODE
, &ospf_refresh_timer_cmd
);
10772 install_element(OSPF_NODE
, &no_ospf_refresh_timer_val_cmd
);
10774 /* max-metric commands */
10775 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_admin_cmd
);
10776 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_admin_cmd
);
10777 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_startup_cmd
);
10778 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_startup_cmd
);
10779 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_shutdown_cmd
);
10780 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_shutdown_cmd
);
10782 /* reference bandwidth commands */
10783 install_element(OSPF_NODE
, &ospf_auto_cost_reference_bandwidth_cmd
);
10784 install_element(OSPF_NODE
, &no_ospf_auto_cost_reference_bandwidth_cmd
);
10786 /* "neighbor" commands. */
10787 install_element(OSPF_NODE
, &ospf_neighbor_cmd
);
10788 install_element(OSPF_NODE
, &ospf_neighbor_poll_interval_cmd
);
10789 install_element(OSPF_NODE
, &no_ospf_neighbor_cmd
);
10790 install_element(OSPF_NODE
, &no_ospf_neighbor_poll_cmd
);
10792 /* write multiplier commands */
10793 install_element(OSPF_NODE
, &ospf_write_multiplier_cmd
);
10794 install_element(OSPF_NODE
, &write_multiplier_cmd
);
10795 install_element(OSPF_NODE
, &no_ospf_write_multiplier_cmd
);
10796 install_element(OSPF_NODE
, &no_write_multiplier_cmd
);
10798 /* Init interface related vty commands. */
10799 ospf_vty_if_init();
10801 /* Init zebra related vty commands. */
10802 ospf_vty_zebra_init();