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
;
3697 json_object
*json_interface_sub
= NULL
;
3701 json_vrf
= json_object_new_object();
3706 if (ospf
->instance
) {
3708 json_object_int_add(json
, "ospfInstance",
3711 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
3714 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3716 if (intf_name
== NULL
) {
3717 /* Show All Interfaces.*/
3718 FOR_ALL_INTERFACES (vrf
, ifp
) {
3719 if (ospf_oi_count(ifp
)) {
3721 json_interface_sub
=
3722 json_object_new_object();
3724 show_ip_ospf_interface_sub(vty
, ospf
, ifp
,
3729 json_object_object_add(
3730 json_vrf
, ifp
->name
,
3731 json_interface_sub
);
3735 /* Interface name is specified. */
3736 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
3739 json_object_boolean_true_add(json_vrf
,
3742 vty_out(vty
, "No such interface name\n");
3745 json_interface_sub
= json_object_new_object();
3747 show_ip_ospf_interface_sub(
3748 vty
, ospf
, ifp
, json_interface_sub
, use_json
);
3751 json_object_object_add(json_vrf
, ifp
->name
,
3752 json_interface_sub
);
3758 if (ospf
->vrf_id
== VRF_DEFAULT
)
3759 json_object_object_add(json
, "default",
3762 json_object_object_add(json
, ospf
->name
,
3771 static void show_ip_ospf_interface_traffic_sub(struct vty
*vty
,
3772 struct ospf_interface
*oi
,
3773 json_object
*json_interface_sub
,
3777 json_object_int_add(json_interface_sub
,
3780 json_object_int_add(json_interface_sub
,
3783 json_object_int_add(json_interface_sub
,
3786 json_object_int_add(json_interface_sub
,
3789 json_object_int_add(json_interface_sub
,
3792 json_object_int_add(json_interface_sub
,
3795 json_object_int_add(json_interface_sub
,
3798 json_object_int_add(json_interface_sub
,
3801 json_object_int_add(json_interface_sub
,
3804 json_object_int_add(json_interface_sub
,
3807 json_object_int_add(json_interface_sub
,
3812 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n",
3813 oi
->ifp
->name
, oi
->hello_in
,
3815 oi
->db_desc_in
, oi
->db_desc_out
,
3816 oi
->ls_req_in
, oi
->ls_req_out
,
3817 oi
->ls_upd_in
, oi
->ls_upd_out
,
3818 oi
->ls_ack_in
, oi
->ls_ack_out
);
3822 /* OSPFv2 Packet Counters */
3823 static int show_ip_ospf_interface_traffic_common(struct vty
*vty
,
3831 struct vrf
*vrf
= NULL
;
3832 struct interface
*ifp
= NULL
;
3833 json_object
*json_vrf
= NULL
;
3834 json_object
*json_interface_sub
= NULL
;
3836 if (!use_json
&& !display_once
) {
3838 vty_out(vty
, "%-12s%-17s%-17s%-17s%-17s%-17s\n",
3839 "Interface", " HELLO", " DB-Desc", " LS-Req",
3840 " LS-Update", " LS-Ack");
3841 vty_out(vty
, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "",
3842 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx");
3844 "--------------------------------------------------------------------------------------------\n");
3845 } else if (use_json
) {
3847 json_vrf
= json_object_new_object();
3852 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
3854 if (intf_name
== NULL
) {
3855 vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
3856 FOR_ALL_INTERFACES (vrf
, ifp
) {
3857 struct route_node
*rn
;
3858 struct ospf_interface
*oi
;
3860 if (ospf_oi_count(ifp
) == 0)
3863 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
3864 rn
= route_next(rn
)) {
3871 json_interface_sub
=
3872 json_object_new_object();
3875 show_ip_ospf_interface_traffic_sub(vty
, oi
,
3879 json_object_object_add(json_vrf
,
3881 json_interface_sub
);
3886 /* Interface name is specified. */
3887 ifp
= if_lookup_by_name(intf_name
, ospf
->vrf_id
);
3889 struct route_node
*rn
;
3890 struct ospf_interface
*oi
;
3892 if (ospf_oi_count(ifp
) == 0) {
3893 vty_out(vty
, " OSPF not enabled on this interface %s\n",
3898 for (rn
= route_top(IF_OIFS(ifp
)); rn
;
3899 rn
= route_next(rn
)) {
3903 json_interface_sub
=
3904 json_object_new_object();
3907 show_ip_ospf_interface_traffic_sub(vty
, oi
,
3911 json_object_object_add(json_vrf
,
3913 json_interface_sub
);
3921 if (ospf
->vrf_id
== VRF_DEFAULT
)
3922 json_object_object_add(json
, "default",
3925 json_object_object_add(json
, ospf
->name
,
3934 DEFUN (show_ip_ospf_interface
,
3935 show_ip_ospf_interface_cmd
,
3936 "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]",
3939 "OSPF information\n"
3942 "Interface information\n"
3947 u_char uj
= use_json(argc
, argv
);
3948 struct listnode
*node
= NULL
;
3949 char *vrf_name
= NULL
, *intf_name
= NULL
;
3950 bool all_vrf
= FALSE
;
3951 int ret
= CMD_SUCCESS
;
3953 int idx_vrf
= 0, idx_intf
= 0;
3955 json_object
*json
= NULL
;
3957 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
3959 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
3960 intf_name
= argv
[idx_intf
]->arg
;
3963 json
= json_object_new_object();
3965 /* vrf input is provided could be all or specific vrf*/
3969 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
3970 if (!ospf
->oi_running
)
3972 ret
= show_ip_ospf_interface_common(vty
,
3981 vty_out(vty
, "%s\n",
3982 json_object_to_json_string_ext(json
,
3983 JSON_C_TO_STRING_PRETTY
));
3984 json_object_free(json
);
3989 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
3990 if (ospf
== NULL
|| !ospf
->oi_running
) {
3992 json_object_free(json
);
3995 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
3999 /* Display default ospf (instance 0) info */
4000 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4001 if (ospf
== NULL
|| !ospf
->oi_running
) {
4003 json_object_free(json
);
4006 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
,
4011 vty_out(vty
, "%s\n", json_object_to_json_string_ext(json
,
4012 JSON_C_TO_STRING_PRETTY
));
4013 json_object_free(json
);
4019 DEFUN (show_ip_ospf_instance_interface
,
4020 show_ip_ospf_instance_interface_cmd
,
4021 "show ip ospf (1-65535) interface [INTERFACE] [json]",
4024 "OSPF information\n"
4026 "Interface information\n"
4033 u_short instance
= 0;
4034 u_char uj
= use_json(argc
, argv
);
4035 char *intf_name
= NULL
;
4036 int ret
= CMD_SUCCESS
;
4037 json_object
*json
= NULL
;
4039 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4040 ospf
= ospf_lookup_instance(instance
);
4042 return CMD_NOT_MY_INSTANCE
;
4044 if (!ospf
->oi_running
)
4048 json
= json_object_new_object();
4050 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4051 intf_name
= argv
[idx_intf
]->arg
;
4053 ret
= show_ip_ospf_interface_common(vty
, ospf
, intf_name
, 0, json
, uj
);
4056 vty_out(vty
, "%s\n", json_object_to_json_string_ext(json
,
4057 JSON_C_TO_STRING_PRETTY
));
4058 json_object_free(json
);
4064 DEFUN (show_ip_ospf_interface_traffic
,
4065 show_ip_ospf_interface_traffic_cmd
,
4066 "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]",
4069 "OSPF information\n"
4072 "Interface information\n"
4073 "Protocol Packet counters\n"
4077 struct ospf
*ospf
= NULL
;
4078 struct listnode
*node
= NULL
;
4079 char *vrf_name
= NULL
, *intf_name
= NULL
;
4080 bool all_vrf
= FALSE
;
4082 int idx_vrf
= 0, idx_intf
= 0;
4083 u_char uj
= use_json(argc
, argv
);
4084 json_object
*json
= NULL
;
4085 int ret
= CMD_SUCCESS
;
4086 int display_once
= 0;
4089 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4091 if (argv_find(argv
, argc
, "INTERFACE", &idx_intf
))
4092 intf_name
= argv
[idx_intf
]->arg
;
4095 json
= json_object_new_object();
4100 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4101 if (!ospf
->oi_running
)
4104 ret
= show_ip_ospf_interface_traffic_common(vty
,
4114 vty_out(vty
, "%s\n",
4115 json_object_to_json_string_ext(json
,
4116 JSON_C_TO_STRING_PRETTY
));
4117 json_object_free(json
);
4122 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4123 if (ospf
== NULL
|| !ospf
->oi_running
) {
4125 json_object_free(json
);
4129 ret
= show_ip_ospf_interface_traffic_common(vty
, ospf
,
4134 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4135 if (ospf
== NULL
|| !ospf
->oi_running
) {
4137 json_object_free(json
);
4141 ret
= show_ip_ospf_interface_traffic_common(vty
, ospf
,
4148 vty_out(vty
, "%s\n", json_object_to_json_string_ext(json
,
4149 JSON_C_TO_STRING_PRETTY
));
4150 json_object_free(json
);
4157 static void show_ip_ospf_neighbour_header(struct vty
*vty
)
4159 vty_out(vty
, "\n%-15s %3s %-15s %9s %-15s %-20s %5s %5s %5s\n",
4160 "Neighbor ID", "Pri", "State", "Dead Time", "Address",
4161 "Interface", "RXmtL", "RqstL", "DBsmL");
4164 static void show_ip_ospf_neighbor_sub(struct vty
*vty
,
4165 struct ospf_interface
*oi
,
4166 json_object
*json
, u_char use_json
)
4168 struct route_node
*rn
;
4169 struct ospf_neighbor
*nbr
, *prev_nbr
= NULL
;
4171 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4172 json_object
*json_neighbor
= NULL
, *json_neigh_array
= NULL
;
4174 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
4175 if ((nbr
= rn
->info
)) {
4176 /* Do not show myself. */
4177 if (nbr
== oi
->nbr_self
)
4179 /* Down state is not shown. */
4180 if (nbr
->state
== NSM_Down
)
4183 char neigh_str
[INET_ADDRSTRLEN
];
4186 !IPV4_ADDR_SAME(&prev_nbr
->src
, &nbr
->src
)) {
4187 /* Start new neigh list */
4188 json_neigh_array
= NULL
;
4191 if (nbr
->state
== NSM_Attempt
&&
4192 nbr
->router_id
.s_addr
== 0)
4193 strlcpy(neigh_str
, "neighbor",
4197 inet_ntoa(nbr
->router_id
),
4200 json_object_object_get_ex(json
, neigh_str
,
4203 if (!json_neigh_array
) {
4204 json_neigh_array
= json_object_new_array();
4205 json_object_object_add(json
, neigh_str
,
4210 json_object_new_object();
4212 ospf_nbr_state_message(nbr
, msgbuf
, 16);
4216 time_store
= monotime_until(
4217 &nbr
->t_inactivity
->u
.sands
,
4220 json_object_int_add(json_neighbor
,
4223 json_object_string_add(json_neighbor
, "state",
4225 json_object_int_add(json_neighbor
,
4228 json_object_string_add(json_neighbor
,
4230 inet_ntoa(nbr
->src
));
4231 json_object_string_add(json_neighbor
,
4234 json_object_int_add(json_neighbor
,
4235 "retransmitCounter",
4236 ospf_ls_retransmit_count(nbr
));
4237 json_object_int_add(json_neighbor
,
4239 ospf_ls_request_count(nbr
));
4240 json_object_int_add(json_neighbor
,
4242 ospf_db_summary_count(nbr
));
4244 json_object_array_add(json_neigh_array
,
4247 ospf_nbr_state_message(nbr
, msgbuf
, 16);
4249 if (nbr
->state
== NSM_Attempt
&&
4250 nbr
->router_id
.s_addr
== 0)
4259 inet_ntoa(nbr
->router_id
),
4263 vty_out(vty
, "%9s ",
4264 ospf_timer_dump(nbr
->t_inactivity
,
4267 vty_out(vty
, "%-15s ", inet_ntoa(nbr
->src
));
4269 "%-20s %5ld %5ld %5d\n",
4271 ospf_ls_retransmit_count(nbr
),
4272 ospf_ls_request_count(nbr
),
4273 ospf_db_summary_count(nbr
));
4280 static int show_ip_ospf_neighbor_common(struct vty
*vty
, struct ospf
*ospf
,
4281 json_object
*json
, u_char use_json
,
4284 struct ospf_interface
*oi
;
4285 struct listnode
*node
;
4286 json_object
*json_vrf
= NULL
;
4290 json_vrf
= json_object_new_object();
4295 if (ospf
->instance
) {
4297 json_object_int_add(json
, "ospfInstance",
4300 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4303 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4305 show_ip_ospf_neighbour_header(vty
);
4307 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
))
4308 show_ip_ospf_neighbor_sub(vty
, oi
, json_vrf
, use_json
);
4312 if (ospf
->vrf_id
== VRF_DEFAULT
)
4313 json_object_object_add(json
, "default",
4316 json_object_object_add(json
, ospf
->name
,
4325 DEFUN (show_ip_ospf_neighbor
,
4326 show_ip_ospf_neighbor_cmd
,
4327 "show ip ospf [vrf <NAME|all>] neighbor [json]",
4330 "OSPF information\n"
4337 u_char uj
= use_json(argc
, argv
);
4338 struct listnode
*node
= NULL
;
4339 char *vrf_name
= NULL
;
4340 bool all_vrf
= FALSE
;
4341 int ret
= CMD_SUCCESS
;
4345 json_object
*json
= NULL
;
4347 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4350 json
= json_object_new_object();
4352 /* vrf input is provided could be all or specific vrf*/
4356 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4357 if (!ospf
->oi_running
)
4359 ret
= show_ip_ospf_neighbor_common(vty
, ospf
,
4365 vty_out(vty
, "%s\n",
4366 json_object_to_json_string_ext(json
,
4367 JSON_C_TO_STRING_PRETTY
));
4368 json_object_free(json
);
4374 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4375 if (ospf
== NULL
|| !ospf
->oi_running
) {
4377 json_object_free(json
);
4381 /* Display default ospf (instance 0) info */
4382 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4383 if (ospf
== NULL
|| !ospf
->oi_running
) {
4385 json_object_free(json
);
4391 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
,
4395 vty_out(vty
, "%s\n",
4396 json_object_to_json_string_ext(json
,
4397 JSON_C_TO_STRING_PRETTY
));
4402 json_object_free(json
);
4408 DEFUN (show_ip_ospf_instance_neighbor
,
4409 show_ip_ospf_instance_neighbor_cmd
,
4410 "show ip ospf (1-65535) neighbor [json]",
4413 "OSPF information\n"
4420 u_short instance
= 0;
4421 u_char uj
= use_json(argc
, argv
);
4422 json_object
*json
= NULL
;
4423 int ret
= CMD_SUCCESS
;
4425 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4426 ospf
= ospf_lookup_instance(instance
);
4428 return CMD_NOT_MY_INSTANCE
;
4430 if (!ospf
->oi_running
)
4434 json
= json_object_new_object();
4436 ret
= show_ip_ospf_neighbor_common(vty
, ospf
, json
, uj
, 0);
4439 vty_out(vty
, "%s\n", json_object_to_json_string_ext(json
,
4440 JSON_C_TO_STRING_PRETTY
));
4441 json_object_free(json
);
4447 static int show_ip_ospf_neighbor_all_common(struct vty
*vty
, struct ospf
*ospf
,
4452 struct listnode
*node
;
4453 struct ospf_interface
*oi
;
4454 json_object
*json_vrf
= NULL
;
4455 json_object
*json_neighbor_sub
= NULL
;
4459 json_vrf
= json_object_new_object();
4462 json_neighbor_sub
= json_object_new_object();
4465 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
4467 show_ip_ospf_neighbour_header(vty
);
4469 if (ospf
->instance
) {
4471 json_object_int_add(json_vrf
, "ospfInstance",
4474 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4477 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
4478 struct listnode
*nbr_node
;
4479 struct ospf_nbr_nbma
*nbr_nbma
;
4481 show_ip_ospf_neighbor_sub(vty
, oi
, json_vrf
, use_json
);
4483 /* print Down neighbor status */
4484 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nbr_node
, nbr_nbma
)) {
4485 if (nbr_nbma
->nbr
== NULL
4486 || nbr_nbma
->nbr
->state
== NSM_Down
) {
4488 json_object_int_add(json_neighbor_sub
,
4490 nbr_nbma
->priority
);
4491 json_object_boolean_true_add(
4494 json_object_string_add(
4498 json_object_int_add(
4500 "nbrNbmaRetransmitCounter", 0);
4501 json_object_int_add(
4503 "nbrNbmaRequestCounter", 0);
4504 json_object_int_add(
4506 "nbrNbmaDbSummaryCounter", 0);
4507 json_object_object_add(
4509 inet_ntoa(nbr_nbma
->addr
),
4512 vty_out(vty
, "%-15s %3d %-15s %9s ",
4513 "-", nbr_nbma
->priority
, "Down",
4516 "%-15s %-20s %5d %5d %5d\n",
4517 inet_ntoa(nbr_nbma
->addr
),
4518 IF_NAME(oi
), 0, 0, 0);
4526 if (ospf
->vrf_id
== VRF_DEFAULT
)
4527 json_object_object_add(json
, "default",
4530 json_object_object_add(json
, ospf
->name
,
4539 DEFUN (show_ip_ospf_neighbor_all
,
4540 show_ip_ospf_neighbor_all_cmd
,
4541 "show ip ospf [vrf <NAME|all>] neighbor all [json]",
4544 "OSPF information\n"
4548 "include down status neighbor\n"
4552 u_char uj
= use_json(argc
, argv
);
4553 struct listnode
*node
= NULL
;
4554 char *vrf_name
= NULL
;
4555 bool all_vrf
= FALSE
;
4556 int ret
= CMD_SUCCESS
;
4560 json_object
*json
= NULL
;
4562 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
4565 json
= json_object_new_object();
4567 /* vrf input is provided could be all or specific vrf*/
4571 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4572 if (!ospf
->oi_running
)
4574 ret
= show_ip_ospf_neighbor_all_common(vty
,
4582 vty_out(vty
, "%s\n",
4583 json_object_to_json_string_ext(json
,
4584 JSON_C_TO_STRING_PRETTY
));
4585 json_object_free(json
);
4591 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
4592 if (ospf
== NULL
|| !ospf
->oi_running
) {
4594 json_object_free(json
);
4598 /* Display default ospf (instance 0) info */
4599 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
4600 if (ospf
== NULL
|| !ospf
->oi_running
) {
4602 json_object_free(json
);
4608 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
,
4611 vty_out(vty
, "%s\n",
4612 json_object_to_json_string_ext(json
,
4613 JSON_C_TO_STRING_PRETTY
));
4618 json_object_free(json
);
4623 DEFUN (show_ip_ospf_instance_neighbor_all
,
4624 show_ip_ospf_instance_neighbor_all_cmd
,
4625 "show ip ospf (1-65535) neighbor all [json]",
4628 "OSPF information\n"
4631 "include down status neighbor\n"
4636 u_short instance
= 0;
4637 u_char uj
= use_json(argc
, argv
);
4638 json_object
*json
= NULL
;
4639 int ret
= CMD_SUCCESS
;
4641 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4642 ospf
= ospf_lookup_instance(instance
);
4644 return CMD_NOT_MY_INSTANCE
;
4646 if (!ospf
->oi_running
)
4649 json
= json_object_new_object();
4651 ret
= show_ip_ospf_neighbor_all_common(vty
, ospf
, json
, uj
, 0);
4654 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4655 json
, JSON_C_TO_STRING_PRETTY
));
4656 json_object_free(json
);
4662 static int show_ip_ospf_neighbor_int_common(struct vty
*vty
, struct ospf
*ospf
,
4664 struct cmd_token
**argv
,
4665 u_char use_json
, u_char use_vrf
)
4667 struct interface
*ifp
;
4668 struct route_node
*rn
;
4669 json_object
*json
= NULL
;
4672 json
= json_object_new_object();
4674 if (ospf
->instance
) {
4676 json_object_int_add(json
, "ospfInstance",
4679 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
4682 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
4684 /*ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id);*/
4685 ifp
= if_lookup_by_name_all_vrf(argv
[arg_base
]->arg
);
4688 json_object_boolean_true_add(json
, "noSuchIface");
4690 vty_out(vty
, "No such interface.\n");
4694 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
4695 struct ospf_interface
*oi
= rn
->info
;
4700 show_ip_ospf_neighbor_sub(vty
, oi
, json
, use_json
);
4704 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4705 json
, JSON_C_TO_STRING_PRETTY
));
4706 json_object_free(json
);
4713 DEFUN (show_ip_ospf_neighbor_int
,
4714 show_ip_ospf_neighbor_int_cmd
,
4715 "show ip ospf neighbor IFNAME [json]",
4718 "OSPF information\n"
4725 u_char uj
= use_json(argc
, argv
);
4726 struct listnode
*node
= NULL
;
4727 int ret
= CMD_SUCCESS
;
4728 struct interface
*ifp
= NULL
;
4731 show_ip_ospf_neighbour_header(vty
);
4733 ifp
= if_lookup_by_name_all_vrf(argv
[idx_ifname
]->arg
);
4734 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
4735 if (!ospf
->oi_running
)
4737 if (!ifp
|| ifp
->vrf_id
!= ospf
->vrf_id
)
4739 ret
= show_ip_ospf_neighbor_int_common(vty
, ospf
,
4740 idx_ifname
, argv
, uj
, 0);
4746 DEFUN (show_ip_ospf_instance_neighbor_int
,
4747 show_ip_ospf_instance_neighbor_int_cmd
,
4748 "show ip ospf (1-65535) neighbor IFNAME [json]",
4751 "OSPF information\n"
4760 u_short instance
= 0;
4761 u_char uj
= use_json(argc
, argv
);
4764 show_ip_ospf_neighbour_header(vty
);
4766 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
4767 ospf
= ospf_lookup_instance(instance
);
4769 return CMD_NOT_MY_INSTANCE
;
4771 if (!ospf
->oi_running
)
4775 show_ip_ospf_neighbour_header(vty
);
4777 return show_ip_ospf_neighbor_int_common(vty
, ospf
, idx_ifname
,
4781 static void show_ip_ospf_nbr_nbma_detail_sub(struct vty
*vty
,
4782 struct ospf_interface
*oi
,
4783 struct ospf_nbr_nbma
*nbr_nbma
,
4784 u_char use_json
, json_object
*json
)
4786 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4787 json_object
*json_sub
= NULL
;
4790 json_sub
= json_object_new_object();
4791 else /* Show neighbor ID. */
4792 vty_out(vty
, " Neighbor %s,", "-");
4794 /* Show interface address. */
4796 json_object_string_add(json_sub
, "ifaceAddress",
4797 inet_ntoa(nbr_nbma
->addr
));
4799 vty_out(vty
, " interface address %s\n",
4800 inet_ntoa(nbr_nbma
->addr
));
4804 json_object_string_add(json_sub
, "areaId",
4805 ospf_area_desc_string(oi
->area
));
4806 json_object_string_add(json_sub
, "iface", IF_NAME(oi
));
4808 vty_out(vty
, " In the area %s via interface %s\n",
4809 ospf_area_desc_string(oi
->area
), IF_NAME(oi
));
4811 /* Show neighbor priority and state. */
4813 json_object_int_add(json_sub
, "nbrPriority",
4814 nbr_nbma
->priority
);
4815 json_object_string_add(json_sub
, "nbrState", "down");
4817 vty_out(vty
, " Neighbor priority is %d, State is %s,",
4818 nbr_nbma
->priority
, "Down");
4820 /* Show state changes. */
4822 json_object_int_add(json_sub
, "stateChangeCounter",
4823 nbr_nbma
->state_change
);
4825 vty_out(vty
, " %d state changes\n", nbr_nbma
->state_change
);
4827 /* Show PollInterval */
4829 json_object_int_add(json_sub
, "pollInterval", nbr_nbma
->v_poll
);
4831 vty_out(vty
, " Poll interval %d\n", nbr_nbma
->v_poll
);
4833 /* Show poll-interval timer. */
4836 time_store
= monotime_until(&nbr_nbma
->t_poll
->u
.sands
, NULL
)
4838 json_object_int_add(json_sub
, "pollIntervalTimerDueMsec",
4841 vty_out(vty
, " Poll timer due in %s\n",
4842 ospf_timer_dump(nbr_nbma
->t_poll
, timebuf
,
4845 /* Show poll-interval timer thread. */
4847 if (nbr_nbma
->t_poll
!= NULL
)
4848 json_object_string_add(json_sub
,
4849 "pollIntervalTimerThread", "on");
4851 vty_out(vty
, " Thread Poll Timer %s\n",
4852 nbr_nbma
->t_poll
!= NULL
? "on" : "off");
4855 json_object_object_add(json
, "noNbrId", json_sub
);
4858 static void show_ip_ospf_neighbor_detail_sub(struct vty
*vty
,
4859 struct ospf_interface
*oi
,
4860 struct ospf_neighbor
*nbr
,
4864 char timebuf
[OSPF_TIME_DUMP_SIZE
];
4865 json_object
*json_sub
= NULL
;
4868 json_sub
= json_object_new_object();
4870 /* Show neighbor ID. */
4871 if (nbr
->state
== NSM_Attempt
&& nbr
->router_id
.s_addr
== 0)
4872 vty_out(vty
, " Neighbor %s,", "-");
4874 vty_out(vty
, " Neighbor %s,",
4875 inet_ntoa(nbr
->router_id
));
4878 /* Show interface address. */
4880 json_object_string_add(json_sub
, "ifaceAddress",
4881 inet_ntoa(nbr
->address
.u
.prefix4
));
4883 vty_out(vty
, " interface address %s\n",
4884 inet_ntoa(nbr
->address
.u
.prefix4
));
4888 json_object_string_add(json_sub
, "areaId",
4889 ospf_area_desc_string(oi
->area
));
4890 json_object_string_add(json_sub
, "ifaceName", oi
->ifp
->name
);
4892 vty_out(vty
, " In the area %s via interface %s\n",
4893 ospf_area_desc_string(oi
->area
), oi
->ifp
->name
);
4895 /* Show neighbor priority and state. */
4897 json_object_int_add(json_sub
, "nbrPriority", nbr
->priority
);
4898 json_object_string_add(
4899 json_sub
, "nbrState",
4900 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
4902 vty_out(vty
, " Neighbor priority is %d, State is %s,",
4904 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
));
4906 /* Show state changes. */
4908 json_object_int_add(json_sub
, "stateChangeCounter",
4911 vty_out(vty
, " %d state changes\n", nbr
->state_change
);
4913 if (nbr
->ts_last_progress
.tv_sec
|| nbr
->ts_last_progress
.tv_usec
) {
4918 monotime_since(&nbr
->ts_last_progress
, &res
) / 1000LL;
4920 json_object_int_add(json_sub
, "lastPrgrsvChangeMsec",
4924 " Most recent state change statistics:\n");
4925 vty_out(vty
, " Progressive change %s ago\n",
4926 ospf_timeval_dump(&res
, timebuf
,
4931 if (nbr
->ts_last_regress
.tv_sec
|| nbr
->ts_last_regress
.tv_usec
) {
4936 monotime_since(&nbr
->ts_last_regress
, &res
) / 1000LL;
4938 json_object_int_add(json_sub
,
4939 "lastRegressiveChangeMsec",
4941 if (nbr
->last_regress_str
)
4942 json_object_string_add(
4943 json_sub
, "lastRegressiveChangeReason",
4944 nbr
->last_regress_str
);
4947 " Regressive change %s ago, due to %s\n",
4948 ospf_timeval_dump(&res
, timebuf
,
4950 (nbr
->last_regress_str
? nbr
->last_regress_str
4955 /* Show Designated Rotuer ID. */
4957 json_object_string_add(json_sub
, "routerDesignatedId",
4958 inet_ntoa(nbr
->d_router
));
4960 vty_out(vty
, " DR is %s,", inet_ntoa(nbr
->d_router
));
4962 /* Show Backup Designated Rotuer ID. */
4964 json_object_string_add(json_sub
, "routerDesignatedBackupId",
4965 inet_ntoa(nbr
->bd_router
));
4967 vty_out(vty
, " BDR is %s\n", inet_ntoa(nbr
->bd_router
));
4971 json_object_int_add(json_sub
, "optionsCounter", nbr
->options
);
4972 json_object_string_add(json_sub
, "optionsList",
4973 ospf_options_dump(nbr
->options
));
4975 vty_out(vty
, " Options %d %s\n", nbr
->options
,
4976 ospf_options_dump(nbr
->options
));
4978 /* Show Router Dead interval timer. */
4980 if (nbr
->t_inactivity
) {
4982 time_store
= monotime_until(&nbr
->t_inactivity
->u
.sands
,
4985 json_object_int_add(json_sub
,
4986 "routerDeadIntervalTimerDueMsec",
4989 json_object_int_add(
4990 json_sub
, "routerDeadIntervalTimerDueMsec", -1);
4992 vty_out(vty
, " Dead timer due in %s\n",
4993 ospf_timer_dump(nbr
->t_inactivity
, timebuf
,
4996 /* Show Database Summary list. */
4998 json_object_int_add(json_sub
, "databaseSummaryListCounter",
4999 ospf_db_summary_count(nbr
));
5001 vty_out(vty
, " Database Summary List %d\n",
5002 ospf_db_summary_count(nbr
));
5004 /* Show Link State Request list. */
5006 json_object_int_add(json_sub
, "linkStateRequestListCounter",
5007 ospf_ls_request_count(nbr
));
5009 vty_out(vty
, " Link State Request List %ld\n",
5010 ospf_ls_request_count(nbr
));
5012 /* Show Link State Retransmission list. */
5014 json_object_int_add(json_sub
,
5015 "linkStateRetransmissionListCounter",
5016 ospf_ls_retransmit_count(nbr
));
5018 vty_out(vty
, " Link State Retransmission List %ld\n",
5019 ospf_ls_retransmit_count(nbr
));
5021 /* Show inactivity timer thread. */
5023 if (nbr
->t_inactivity
!= NULL
)
5024 json_object_string_add(json_sub
,
5025 "threadInactivityTimer", "on");
5027 vty_out(vty
, " Thread Inactivity Timer %s\n",
5028 nbr
->t_inactivity
!= NULL
? "on" : "off");
5030 /* Show Database Description retransmission thread. */
5032 if (nbr
->t_db_desc
!= NULL
)
5033 json_object_string_add(
5035 "threadDatabaseDescriptionRetransmission",
5039 " Thread Database Description Retransmision %s\n",
5040 nbr
->t_db_desc
!= NULL
? "on" : "off");
5042 /* Show Link State Request Retransmission thread. */
5044 if (nbr
->t_ls_req
!= NULL
)
5045 json_object_string_add(
5047 "threadLinkStateRequestRetransmission", "on");
5050 " Thread Link State Request Retransmission %s\n",
5051 nbr
->t_ls_req
!= NULL
? "on" : "off");
5053 /* Show Link State Update Retransmission thread. */
5055 if (nbr
->t_ls_upd
!= NULL
)
5056 json_object_string_add(
5057 json_sub
, "threadLinkStateUpdateRetransmission",
5061 " Thread Link State Update Retransmission %s\n\n",
5062 nbr
->t_ls_upd
!= NULL
? "on" : "off");
5065 if (nbr
->state
== NSM_Attempt
&& nbr
->router_id
.s_addr
== 0)
5066 json_object_object_add(json
, "noNbrId", json_sub
);
5068 json_object_object_add(json
, inet_ntoa(nbr
->router_id
),
5072 ospf_bfd_show_info(vty
, nbr
->bfd_info
, json
, use_json
, 0);
5075 static int show_ip_ospf_neighbor_id_common(struct vty
*vty
, struct ospf
*ospf
,
5077 struct cmd_token
**argv
,
5081 struct listnode
*node
;
5082 struct ospf_neighbor
*nbr
;
5083 struct ospf_interface
*oi
;
5084 struct in_addr router_id
;
5086 json_object
*json
= NULL
;
5089 json
= json_object_new_object();
5091 if (ospf
->instance
) {
5093 json_object_int_add(json
, "ospfInstance",
5096 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5099 ospf_show_vrf_name(ospf
, vty
, json
, use_vrf
);
5101 ret
= inet_aton(argv
[arg_base
]->arg
, &router_id
);
5104 vty_out(vty
, "Please specify Neighbor ID by A.B.C.D\n");
5106 vty_out(vty
, "{}\n");
5107 json_object_free(json
);
5112 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5113 if ((nbr
= ospf_nbr_lookup_by_routerid(oi
->nbrs
, &router_id
))) {
5114 show_ip_ospf_neighbor_detail_sub(vty
, oi
, nbr
, json
,
5120 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5121 json
, JSON_C_TO_STRING_PRETTY
));
5122 json_object_free(json
);
5129 DEFUN (show_ip_ospf_neighbor_id
,
5130 show_ip_ospf_neighbor_id_cmd
,
5131 "show ip ospf neighbor A.B.C.D [json]",
5134 "OSPF information\n"
5140 u_char uj
= use_json(argc
, argv
);
5141 struct listnode
*node
= NULL
;
5142 int ret
= CMD_SUCCESS
;
5144 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5145 if (!ospf
->oi_running
)
5147 ret
= show_ip_ospf_neighbor_id_common(vty
, ospf
, 0,
5154 DEFUN (show_ip_ospf_instance_neighbor_id
,
5155 show_ip_ospf_instance_neighbor_id_cmd
,
5156 "show ip ospf (1-65535) neighbor A.B.C.D [json]",
5159 "OSPF information\n"
5166 int idx_router_id
= 5;
5168 u_short instance
= 0;
5169 u_char uj
= use_json(argc
, argv
);
5171 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5172 ospf
= ospf_lookup_instance(instance
);
5174 return CMD_NOT_MY_INSTANCE
;
5176 if (!ospf
->oi_running
)
5179 return show_ip_ospf_neighbor_id_common(vty
, ospf
, idx_router_id
, argv
,
5183 static int show_ip_ospf_neighbor_detail_common(struct vty
*vty
,
5189 struct ospf_interface
*oi
;
5190 struct listnode
*node
;
5191 json_object
*json_vrf
= NULL
;
5195 json_vrf
= json_object_new_object();
5199 if (ospf
->instance
) {
5201 json_object_int_add(json_vrf
, "ospfInstance",
5204 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5207 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5209 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5210 struct route_node
*rn
;
5211 struct ospf_neighbor
*nbr
;
5213 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
5214 if ((nbr
= rn
->info
)) {
5215 if (nbr
!= oi
->nbr_self
) {
5216 if (nbr
->state
!= NSM_Down
) {
5217 show_ip_ospf_neighbor_detail_sub(
5218 vty
, oi
, nbr
, json_vrf
,
5228 if (ospf
->vrf_id
== VRF_DEFAULT
)
5229 json_object_object_add(json
, "default",
5232 json_object_object_add(json
, ospf
->name
,
5241 DEFUN (show_ip_ospf_neighbor_detail
,
5242 show_ip_ospf_neighbor_detail_cmd
,
5243 "show ip ospf [vrf <NAME|all>] neighbor detail [json]",
5246 "OSPF information\n"
5250 "detail of all neighbors\n"
5254 u_char uj
= use_json(argc
, argv
);
5255 struct listnode
*node
= NULL
;
5256 char *vrf_name
= NULL
;
5257 bool all_vrf
= FALSE
;
5258 int ret
= CMD_SUCCESS
;
5262 json_object
*json
= NULL
;
5264 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5267 json
= json_object_new_object();
5269 /* vrf input is provided could be all or specific vrf*/
5273 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5274 if (!ospf
->oi_running
)
5276 ret
= show_ip_ospf_neighbor_detail_common(vty
,
5283 vty_out(vty
, "%s\n",
5284 json_object_to_json_string_ext(json
,
5285 JSON_C_TO_STRING_PRETTY
));
5286 json_object_free(json
);
5291 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5292 if (ospf
== NULL
|| !ospf
->oi_running
) {
5294 json_object_free(json
);
5298 /* Display default ospf (instance 0) info */
5299 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5300 if (ospf
== NULL
|| !ospf
->oi_running
) {
5302 json_object_free(json
);
5308 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
,
5311 vty_out(vty
, "%s\n",
5312 json_object_to_json_string_ext(json
,
5313 JSON_C_TO_STRING_PRETTY
));
5318 json_object_free(json
);
5323 DEFUN (show_ip_ospf_instance_neighbor_detail
,
5324 show_ip_ospf_instance_neighbor_detail_cmd
,
5325 "show ip ospf (1-65535) neighbor detail [json]",
5328 "OSPF information\n"
5331 "detail of all neighbors\n"
5336 u_short instance
= 0;
5337 u_char uj
= use_json(argc
, argv
);
5338 json_object
*json
= NULL
;
5339 int ret
= CMD_SUCCESS
;
5341 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5342 ospf
= ospf_lookup_instance(instance
);
5344 return CMD_NOT_MY_INSTANCE
;
5346 if (!ospf
->oi_running
)
5350 json
= json_object_new_object();
5352 ret
= show_ip_ospf_neighbor_detail_common(vty
, ospf
, json
, uj
, 0);
5355 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5356 json
, JSON_C_TO_STRING_PRETTY
));
5357 json_object_free(json
);
5363 static int show_ip_ospf_neighbor_detail_all_common(struct vty
*vty
,
5369 struct listnode
*node
;
5370 struct ospf_interface
*oi
;
5371 json_object
*json_vrf
= NULL
;
5375 json_vrf
= json_object_new_object();
5380 if (ospf
->instance
) {
5382 json_object_int_add(json
, "ospfInstance",
5385 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5388 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
5390 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
5391 struct route_node
*rn
;
5392 struct ospf_neighbor
*nbr
;
5393 struct ospf_nbr_nbma
*nbr_nbma
;
5395 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
5396 if ((nbr
= rn
->info
))
5397 if (nbr
!= oi
->nbr_self
)
5398 if (nbr
->state
!= NSM_Down
)
5399 show_ip_ospf_neighbor_detail_sub(
5401 json_vrf
, use_json
);
5403 if (oi
->type
== OSPF_IFTYPE_NBMA
) {
5404 struct listnode
*nd
;
5406 for (ALL_LIST_ELEMENTS_RO(oi
->nbr_nbma
, nd
, nbr_nbma
)) {
5407 if (nbr_nbma
->nbr
== NULL
5408 || nbr_nbma
->nbr
->state
== NSM_Down
)
5409 show_ip_ospf_nbr_nbma_detail_sub(
5410 vty
, oi
, nbr_nbma
, use_json
,
5418 if (ospf
->vrf_id
== VRF_DEFAULT
)
5419 json_object_object_add(json
, "default",
5422 json_object_object_add(json
, ospf
->name
,
5432 DEFUN (show_ip_ospf_neighbor_detail_all
,
5433 show_ip_ospf_neighbor_detail_all_cmd
,
5434 "show ip ospf [vrf <NAME|all>] neighbor detail all [json]",
5437 "OSPF information\n"
5441 "detail of all neighbors\n"
5442 "include down status neighbor\n"
5446 u_char uj
= use_json(argc
, argv
);
5447 struct listnode
*node
= NULL
;
5448 char *vrf_name
= NULL
;
5449 bool all_vrf
= FALSE
;
5450 int ret
= CMD_SUCCESS
;
5454 json_object
*json
= NULL
;
5456 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
5459 json
= json_object_new_object();
5461 /* vrf input is provided could be all or specific vrf*/
5465 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5466 if (!ospf
->oi_running
)
5468 ret
= show_ip_ospf_neighbor_detail_all_common(vty
,
5476 vty_out(vty
, "%s\n",
5477 json_object_to_json_string_ext(json
,
5478 JSON_C_TO_STRING_PRETTY
));
5479 json_object_free(json
);
5484 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
5485 if (ospf
== NULL
|| !ospf
->oi_running
) {
5487 json_object_free(json
);
5491 /* Display default ospf (instance 0) info */
5492 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
5493 if (ospf
== NULL
|| !ospf
->oi_running
) {
5495 json_object_free(json
);
5501 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
,
5504 vty_out(vty
, "%s\n",
5505 json_object_to_json_string_ext(json
,
5506 JSON_C_TO_STRING_PRETTY
));
5511 json_object_free(json
);
5516 DEFUN (show_ip_ospf_instance_neighbor_detail_all
,
5517 show_ip_ospf_instance_neighbor_detail_all_cmd
,
5518 "show ip ospf (1-65535) neighbor detail all [json]",
5521 "OSPF information\n"
5524 "detail of all neighbors\n"
5525 "include down status neighbor\n"
5530 u_short instance
= 0;
5531 u_char uj
= use_json(argc
, argv
);
5532 json_object
*json
= NULL
;
5533 int ret
= CMD_SUCCESS
;
5535 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5536 ospf
= ospf_lookup_instance(instance
);
5538 return CMD_NOT_MY_INSTANCE
;
5540 if (!ospf
->oi_running
)
5544 json
= json_object_new_object();
5546 ret
= show_ip_ospf_neighbor_detail_all_common(vty
, ospf
, json
, uj
, 0);
5549 vty_out(vty
, "%s\n", json_object_to_json_string_ext(json
,
5550 JSON_C_TO_STRING_PRETTY
));
5551 json_object_free(json
);
5557 static int show_ip_ospf_neighbor_int_detail_common(struct vty
*vty
,
5560 struct cmd_token
**argv
,
5563 struct ospf_interface
*oi
;
5564 struct interface
*ifp
;
5565 struct route_node
*rn
, *nrn
;
5566 struct ospf_neighbor
*nbr
;
5567 json_object
*json
= NULL
;
5570 json
= json_object_new_object();
5572 if (ospf
->instance
) {
5574 json_object_int_add(json
, "ospfInstance",
5577 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
5580 ifp
= if_lookup_by_name_all_vrf(argv
[arg_base
]->arg
);
5583 vty_out(vty
, "No such interface.\n");
5585 vty_out(vty
, "{}\n");
5586 json_object_free(json
);
5591 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
5592 if ((oi
= rn
->info
)) {
5593 for (nrn
= route_top(oi
->nbrs
); nrn
;
5594 nrn
= route_next(nrn
)) {
5595 if ((nbr
= nrn
->info
)) {
5596 if (nbr
!= oi
->nbr_self
) {
5597 if (nbr
->state
!= NSM_Down
)
5598 show_ip_ospf_neighbor_detail_sub(
5608 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
5609 json
, JSON_C_TO_STRING_PRETTY
));
5610 json_object_free(json
);
5617 DEFUN (show_ip_ospf_neighbor_int_detail
,
5618 show_ip_ospf_neighbor_int_detail_cmd
,
5619 "show ip ospf neighbor IFNAME detail [json]",
5622 "OSPF information\n"
5625 "detail of all neighbors\n"
5629 u_char uj
= use_json(argc
, argv
);
5630 struct listnode
*node
= NULL
;
5631 int ret
= CMD_SUCCESS
;
5633 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
5634 if (!ospf
->oi_running
)
5636 ret
= show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, 0,
5643 DEFUN (show_ip_ospf_instance_neighbor_int_detail
,
5644 show_ip_ospf_instance_neighbor_int_detail_cmd
,
5645 "show ip ospf (1-65535) neighbor IFNAME detail [json]",
5648 "OSPF information\n"
5652 "detail of all neighbors\n"
5658 u_short instance
= 0;
5659 u_char uj
= use_json(argc
, argv
);
5661 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
5662 ospf
= ospf_lookup_instance(instance
);
5664 return CMD_NOT_MY_INSTANCE
;
5666 if (!ospf
->oi_running
)
5669 return show_ip_ospf_neighbor_int_detail_common(vty
, ospf
, idx_ifname
, argv
, uj
);
5672 /* Show functions */
5673 static int show_lsa_summary(struct vty
*vty
, struct ospf_lsa
*lsa
, int self
)
5675 struct router_lsa
*rl
;
5676 struct summary_lsa
*sl
;
5677 struct as_external_lsa
*asel
;
5678 struct prefix_ipv4 p
;
5681 /* If self option is set, check LSA self flag. */
5682 if (self
== 0 || IS_LSA_SELF(lsa
)) {
5683 /* LSA common part show. */
5684 vty_out(vty
, "%-15s ", inet_ntoa(lsa
->data
->id
));
5685 vty_out(vty
, "%-15s %4d 0x%08lx 0x%04x",
5686 inet_ntoa(lsa
->data
->adv_router
), LS_AGE(lsa
),
5687 (u_long
)ntohl(lsa
->data
->ls_seqnum
),
5688 ntohs(lsa
->data
->checksum
));
5689 /* LSA specific part show. */
5690 switch (lsa
->data
->type
) {
5691 case OSPF_ROUTER_LSA
:
5692 rl
= (struct router_lsa
*)lsa
->data
;
5693 vty_out(vty
, " %-d", ntohs(rl
->links
));
5695 case OSPF_SUMMARY_LSA
:
5696 sl
= (struct summary_lsa
*)lsa
->data
;
5699 p
.prefix
= sl
->header
.id
;
5700 p
.prefixlen
= ip_masklen(sl
->mask
);
5701 apply_mask_ipv4(&p
);
5703 vty_out(vty
, " %s/%d", inet_ntoa(p
.prefix
),
5706 case OSPF_AS_EXTERNAL_LSA
:
5707 case OSPF_AS_NSSA_LSA
:
5708 asel
= (struct as_external_lsa
*)lsa
->data
;
5711 p
.prefix
= asel
->header
.id
;
5712 p
.prefixlen
= ip_masklen(asel
->mask
);
5713 apply_mask_ipv4(&p
);
5715 vty_out(vty
, " %s %s/%d [0x%lx]",
5716 IS_EXTERNAL_METRIC(asel
->e
[0].tos
)
5719 inet_ntoa(p
.prefix
), p
.prefixlen
,
5720 (u_long
)ntohl(asel
->e
[0].route_tag
));
5722 case OSPF_NETWORK_LSA
:
5723 case OSPF_ASBR_SUMMARY_LSA
:
5724 case OSPF_OPAQUE_LINK_LSA
:
5725 case OSPF_OPAQUE_AREA_LSA
:
5726 case OSPF_OPAQUE_AS_LSA
:
5736 static const char *show_database_desc
[] = {
5738 "Router Link States",
5740 "Summary Link States",
5741 "ASBR-Summary Link States",
5742 "AS External Link States",
5743 "Group Membership LSA",
5744 "NSSA-external Link States",
5746 "Link-Local Opaque-LSA",
5747 "Area-Local Opaque-LSA",
5748 "AS-external Opaque-LSA",
5751 static const char *show_database_header
[] = {
5753 "Link ID ADV Router Age Seq# CkSum Link count",
5754 "Link ID ADV Router Age Seq# CkSum",
5755 "Link ID ADV Router Age Seq# CkSum Route",
5756 "Link ID ADV Router Age Seq# CkSum",
5757 "Link ID ADV Router Age Seq# CkSum Route",
5758 " --- header for Group Member ----",
5759 "Link ID ADV Router Age Seq# CkSum Route",
5761 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5762 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5763 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5766 static void show_ip_ospf_database_header(struct vty
*vty
, struct ospf_lsa
*lsa
)
5768 struct router_lsa
*rlsa
= (struct router_lsa
*)lsa
->data
;
5770 vty_out(vty
, " LS age: %d\n", LS_AGE(lsa
));
5771 vty_out(vty
, " Options: 0x%-2x : %s\n", lsa
->data
->options
,
5772 ospf_options_dump(lsa
->data
->options
));
5773 vty_out(vty
, " LS Flags: 0x%-2x %s\n", lsa
->flags
,
5774 ((lsa
->flags
& OSPF_LSA_LOCAL_XLT
) ? "(Translated from Type-7)"
5777 if (lsa
->data
->type
== OSPF_ROUTER_LSA
) {
5778 vty_out(vty
, " Flags: 0x%x", rlsa
->flags
);
5781 vty_out(vty
, " :%s%s%s%s",
5782 IS_ROUTER_LSA_BORDER(rlsa
) ? " ABR" : "",
5783 IS_ROUTER_LSA_EXTERNAL(rlsa
) ? " ASBR" : "",
5784 IS_ROUTER_LSA_VIRTUAL(rlsa
) ? " VL-endpoint"
5786 IS_ROUTER_LSA_SHORTCUT(rlsa
) ? " Shortcut"
5791 vty_out(vty
, " LS Type: %s\n",
5792 lookup_msg(ospf_lsa_type_msg
, lsa
->data
->type
, NULL
));
5793 vty_out(vty
, " Link State ID: %s %s\n", inet_ntoa(lsa
->data
->id
),
5794 lookup_msg(ospf_link_state_id_type_msg
, lsa
->data
->type
, NULL
));
5795 vty_out(vty
, " Advertising Router: %s\n",
5796 inet_ntoa(lsa
->data
->adv_router
));
5797 vty_out(vty
, " LS Seq Number: %08lx\n",
5798 (u_long
)ntohl(lsa
->data
->ls_seqnum
));
5799 vty_out(vty
, " Checksum: 0x%04x\n", ntohs(lsa
->data
->checksum
));
5800 vty_out(vty
, " Length: %d\n\n", ntohs(lsa
->data
->length
));
5803 const char *link_type_desc
[] = {
5805 "another Router (point-to-point)",
5806 "a Transit Network",
5811 const char *link_id_desc
[] = {
5812 "(null)", "Neighboring Router ID", "Designated Router address",
5813 "Net", "Neighboring Router ID",
5816 const char *link_data_desc
[] = {
5817 "(null)", "Router Interface address", "Router Interface address",
5818 "Network Mask", "Router Interface address",
5821 /* Show router-LSA each Link information. */
5822 static void show_ip_ospf_database_router_links(struct vty
*vty
,
5823 struct router_lsa
*rl
)
5828 len
= ntohs(rl
->header
.length
) - 4;
5829 for (i
= 0; i
< ntohs(rl
->links
) && len
> 0; len
-= 12, i
++) {
5830 type
= rl
->link
[i
].type
;
5832 vty_out(vty
, " Link connected to: %s\n",
5833 link_type_desc
[type
]);
5834 vty_out(vty
, " (Link ID) %s: %s\n", link_id_desc
[type
],
5835 inet_ntoa(rl
->link
[i
].link_id
));
5836 vty_out(vty
, " (Link Data) %s: %s\n", link_data_desc
[type
],
5837 inet_ntoa(rl
->link
[i
].link_data
));
5838 vty_out(vty
, " Number of TOS metrics: 0\n");
5839 vty_out(vty
, " TOS 0 Metric: %d\n",
5840 ntohs(rl
->link
[i
].metric
));
5845 /* Show router-LSA detail information. */
5846 static int show_router_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5849 struct router_lsa
*rl
= (struct router_lsa
*)lsa
->data
;
5851 show_ip_ospf_database_header(vty
, lsa
);
5853 vty_out(vty
, " Number of Links: %d\n\n", ntohs(rl
->links
));
5855 show_ip_ospf_database_router_links(vty
, rl
);
5862 /* Show network-LSA detail information. */
5863 static int show_network_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5868 struct network_lsa
*nl
= (struct network_lsa
*)lsa
->data
;
5870 show_ip_ospf_database_header(vty
, lsa
);
5872 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(nl
->mask
));
5874 length
= ntohs(lsa
->data
->length
) - OSPF_LSA_HEADER_SIZE
- 4;
5876 for (i
= 0; length
> 0; i
++, length
-= 4)
5877 vty_out(vty
, " Attached Router: %s\n",
5878 inet_ntoa(nl
->routers
[i
]));
5886 /* Show summary-LSA detail information. */
5887 static int show_summary_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5890 struct summary_lsa
*sl
= (struct summary_lsa
*)lsa
->data
;
5892 show_ip_ospf_database_header(vty
, lsa
);
5894 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(sl
->mask
));
5895 vty_out(vty
, " TOS: 0 Metric: %d\n",
5896 GET_METRIC(sl
->metric
));
5903 /* Show summary-ASBR-LSA detail information. */
5904 static int show_summary_asbr_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 AS-external-LSA detail information. */
5921 static int show_as_external_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5924 struct as_external_lsa
*al
=
5925 (struct as_external_lsa
*)lsa
->data
;
5927 show_ip_ospf_database_header(vty
, lsa
);
5929 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(al
->mask
));
5930 vty_out(vty
, " Metric Type: %s\n",
5931 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
5932 ? "2 (Larger than any link state path)"
5934 vty_out(vty
, " TOS: 0\n");
5935 vty_out(vty
, " Metric: %d\n",
5936 GET_METRIC(al
->e
[0].metric
));
5937 vty_out(vty
, " Forward Address: %s\n",
5938 inet_ntoa(al
->e
[0].fwd_addr
));
5941 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
5942 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
5949 show_as_external_lsa_stdvty (struct ospf_lsa
*lsa
)
5951 struct as_external_lsa
*al
= (struct as_external_lsa
*) lsa
->data
;
5953 /* show_ip_ospf_database_header (vty, lsa); */
5955 zlog_debug( " Network Mask: /%d%s",
5956 ip_masklen (al
->mask
), "\n");
5957 zlog_debug( " Metric Type: %s%s",
5958 IS_EXTERNAL_METRIC (al
->e
[0].tos
) ?
5959 "2 (Larger than any link state path)" : "1", "\n");
5960 zlog_debug( " TOS: 0%s", "\n");
5961 zlog_debug( " Metric: %d%s",
5962 GET_METRIC (al
->e
[0].metric
), "\n");
5963 zlog_debug( " Forward Address: %s%s",
5964 inet_ntoa (al
->e
[0].fwd_addr
), "\n");
5966 zlog_debug( " External Route Tag: %"ROUTE_TAG_PRI
"%s%s",
5967 (route_tag_t
)ntohl (al
->e
[0].route_tag
), "\n", "\n");
5972 /* Show AS-NSSA-LSA detail information. */
5973 static int show_as_nssa_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
5976 struct as_external_lsa
*al
=
5977 (struct as_external_lsa
*)lsa
->data
;
5979 show_ip_ospf_database_header(vty
, lsa
);
5981 vty_out(vty
, " Network Mask: /%d\n", ip_masklen(al
->mask
));
5982 vty_out(vty
, " Metric Type: %s\n",
5983 IS_EXTERNAL_METRIC(al
->e
[0].tos
)
5984 ? "2 (Larger than any link state path)"
5986 vty_out(vty
, " TOS: 0\n");
5987 vty_out(vty
, " Metric: %d\n",
5988 GET_METRIC(al
->e
[0].metric
));
5989 vty_out(vty
, " NSSA: Forward Address: %s\n",
5990 inet_ntoa(al
->e
[0].fwd_addr
));
5993 " External Route Tag: %" ROUTE_TAG_PRI
"\n\n",
5994 (route_tag_t
)ntohl(al
->e
[0].route_tag
));
6000 static int show_func_dummy(struct vty
*vty
, struct ospf_lsa
*lsa
)
6005 static int show_opaque_lsa_detail(struct vty
*vty
, struct ospf_lsa
*lsa
)
6008 show_ip_ospf_database_header(vty
, lsa
);
6009 show_opaque_info_detail(vty
, lsa
);
6016 int (*show_function
[])(struct vty
*, struct ospf_lsa
*) = {
6018 show_router_lsa_detail
,
6019 show_network_lsa_detail
,
6020 show_summary_lsa_detail
,
6021 show_summary_asbr_lsa_detail
,
6022 show_as_external_lsa_detail
,
6024 show_as_nssa_lsa_detail
, /* almost same as external */
6026 show_opaque_lsa_detail
,
6027 show_opaque_lsa_detail
,
6028 show_opaque_lsa_detail
,
6031 static void show_lsa_prefix_set(struct vty
*vty
, struct prefix_ls
*lp
,
6032 struct in_addr
*id
, struct in_addr
*adv_router
)
6034 memset(lp
, 0, sizeof(struct prefix_ls
));
6038 else if (adv_router
== NULL
) {
6044 lp
->adv_router
= *adv_router
;
6048 static void show_lsa_detail_proc(struct vty
*vty
, struct route_table
*rt
,
6049 struct in_addr
*id
, struct in_addr
*adv_router
)
6051 struct prefix_ls lp
;
6052 struct route_node
*rn
, *start
;
6053 struct ospf_lsa
*lsa
;
6055 show_lsa_prefix_set(vty
, &lp
, id
, adv_router
);
6056 start
= route_node_get(rt
, (struct prefix
*)&lp
);
6058 route_lock_node(start
);
6059 for (rn
= start
; rn
; rn
= route_next_until(rn
, start
))
6060 if ((lsa
= rn
->info
)) {
6061 if (show_function
[lsa
->data
->type
] != NULL
)
6062 show_function
[lsa
->data
->type
](vty
,
6065 route_unlock_node(start
);
6069 /* Show detail LSA information
6070 -- if id is NULL then show all LSAs. */
6071 static void show_lsa_detail(struct vty
*vty
, struct ospf
*ospf
, int type
,
6072 struct in_addr
*id
, struct in_addr
*adv_router
)
6074 struct listnode
*node
;
6075 struct ospf_area
*area
;
6078 case OSPF_AS_EXTERNAL_LSA
:
6079 case OSPF_OPAQUE_AS_LSA
:
6080 vty_out(vty
, " %s \n\n",
6081 show_database_desc
[type
]);
6082 show_lsa_detail_proc(vty
, AS_LSDB(ospf
, type
), id
, adv_router
);
6085 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6086 vty_out(vty
, "\n %s (Area %s)\n\n",
6087 show_database_desc
[type
],
6088 ospf_area_desc_string(area
));
6089 show_lsa_detail_proc(vty
, AREA_LSDB(area
, type
), id
,
6096 static void show_lsa_detail_adv_router_proc(struct vty
*vty
,
6097 struct route_table
*rt
,
6098 struct in_addr
*adv_router
)
6100 struct route_node
*rn
;
6101 struct ospf_lsa
*lsa
;
6103 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
))
6104 if ((lsa
= rn
->info
))
6105 if (IPV4_ADDR_SAME(adv_router
,
6106 &lsa
->data
->adv_router
)) {
6107 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
6109 if (show_function
[lsa
->data
->type
] != NULL
)
6110 show_function
[lsa
->data
->type
](vty
,
6115 /* Show detail LSA information. */
6116 static void show_lsa_detail_adv_router(struct vty
*vty
, struct ospf
*ospf
,
6117 int type
, struct in_addr
*adv_router
)
6119 struct listnode
*node
;
6120 struct ospf_area
*area
;
6123 case OSPF_AS_EXTERNAL_LSA
:
6124 case OSPF_OPAQUE_AS_LSA
:
6125 vty_out(vty
, " %s \n\n",
6126 show_database_desc
[type
]);
6127 show_lsa_detail_adv_router_proc(vty
, AS_LSDB(ospf
, type
),
6131 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6132 vty_out(vty
, "\n %s (Area %s)\n\n",
6133 show_database_desc
[type
],
6134 ospf_area_desc_string(area
));
6135 show_lsa_detail_adv_router_proc(
6136 vty
, AREA_LSDB(area
, type
), adv_router
);
6142 static void show_ip_ospf_database_summary(struct vty
*vty
, struct ospf
*ospf
,
6145 struct ospf_lsa
*lsa
;
6146 struct route_node
*rn
;
6147 struct ospf_area
*area
;
6148 struct listnode
*node
;
6151 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
6152 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6154 case OSPF_AS_EXTERNAL_LSA
:
6155 case OSPF_OPAQUE_AS_LSA
:
6160 if (ospf_lsdb_count_self(area
->lsdb
, type
) > 0
6162 && ospf_lsdb_count(area
->lsdb
, type
) > 0)) {
6163 vty_out(vty
, " %s (Area %s)\n\n",
6164 show_database_desc
[type
],
6165 ospf_area_desc_string(area
));
6166 vty_out(vty
, "%s\n",
6167 show_database_header
[type
]);
6169 LSDB_LOOP(AREA_LSDB(area
, type
), rn
, lsa
)
6170 show_lsa_summary(vty
, lsa
, self
);
6177 for (type
= OSPF_MIN_LSA
; type
< OSPF_MAX_LSA
; type
++) {
6179 case OSPF_AS_EXTERNAL_LSA
:
6180 case OSPF_OPAQUE_AS_LSA
:
6185 if (ospf_lsdb_count_self(ospf
->lsdb
, type
)
6186 || (!self
&& ospf_lsdb_count(ospf
->lsdb
, type
))) {
6187 vty_out(vty
, " %s\n\n",
6188 show_database_desc
[type
]);
6189 vty_out(vty
, "%s\n", show_database_header
[type
]);
6191 LSDB_LOOP(AS_LSDB(ospf
, type
), rn
, lsa
)
6192 show_lsa_summary(vty
, lsa
, self
);
6201 static void show_ip_ospf_database_maxage(struct vty
*vty
, struct ospf
*ospf
)
6203 struct route_node
*rn
;
6205 vty_out(vty
, "\n MaxAge Link States:\n\n");
6207 for (rn
= route_top(ospf
->maxage_lsa
); rn
; rn
= route_next(rn
)) {
6208 struct ospf_lsa
*lsa
;
6210 if ((lsa
= rn
->info
) != NULL
) {
6211 vty_out(vty
, "Link type: %d\n", lsa
->data
->type
);
6212 vty_out(vty
, "Link State ID: %s\n",
6213 inet_ntoa(lsa
->data
->id
));
6214 vty_out(vty
, "Advertising Router: %s\n",
6215 inet_ntoa(lsa
->data
->adv_router
));
6216 vty_out(vty
, "LSA lock count: %d\n", lsa
->lock
);
6222 #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
6223 #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
6225 #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
6226 #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
6227 #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
6228 #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
6230 #define OSPF_LSA_TYPES_DESC \
6231 "ASBR summary link states\n" \
6232 "External link states\n" \
6233 "Network link states\n" \
6234 "Router link states\n" \
6235 "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \
6236 OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
6237 OSPF_LSA_TYPE_OPAQUE_AS_DESC
6239 static int show_ip_ospf_database_common(struct vty
*vty
, struct ospf
*ospf
,
6240 int arg_base
, int argc
,
6241 struct cmd_token
**argv
,
6246 struct in_addr id
, adv_router
;
6249 vty_out(vty
, "\nOSPF Instance: %d\n", ospf
->instance
);
6251 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
6253 vty_out(vty
, "\n OSPF Router with ID (%s)\n\n",
6254 inet_ntoa(ospf
->router_id
));
6257 if (argc
== arg_base
+ 4) {
6258 show_ip_ospf_database_summary(vty
, ospf
, 0);
6262 /* Set database type to show. */
6263 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
6264 type
= OSPF_ROUTER_LSA
;
6265 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
6266 type
= OSPF_NETWORK_LSA
;
6267 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
6268 type
= OSPF_AS_NSSA_LSA
;
6269 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "su", 2) == 0)
6270 type
= OSPF_SUMMARY_LSA
;
6271 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
6272 type
= OSPF_ASBR_SUMMARY_LSA
;
6273 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
6274 type
= OSPF_AS_EXTERNAL_LSA
;
6275 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "se", 2) == 0) {
6276 show_ip_ospf_database_summary(vty
, ospf
, 1);
6278 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "m", 1) == 0) {
6279 show_ip_ospf_database_maxage(vty
, ospf
);
6281 } else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
6282 type
= OSPF_OPAQUE_LINK_LSA
;
6283 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
6284 type
= OSPF_OPAQUE_AREA_LSA
;
6285 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
6286 type
= OSPF_OPAQUE_AS_LSA
;
6290 /* `show ip ospf database LSA'. */
6291 if (argc
== arg_base
+ 5)
6292 show_lsa_detail(vty
, ospf
, type
, NULL
, NULL
);
6293 else if (argc
>= arg_base
+ 6) {
6294 ret
= inet_aton(argv
[arg_base
+ 5]->arg
, &id
);
6298 /* `show ip ospf database LSA ID'. */
6299 if (argc
== arg_base
+ 6)
6300 show_lsa_detail(vty
, ospf
, type
, &id
, NULL
);
6301 /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */
6302 else if (argc
== arg_base
+ 7) {
6303 if (strncmp(argv
[arg_base
+ 6]->text
, "s", 1) == 0)
6304 adv_router
= ospf
->router_id
;
6306 ret
= inet_aton(argv
[arg_base
+ 7]->arg
,
6311 show_lsa_detail(vty
, ospf
, type
, &id
, &adv_router
);
6318 DEFUN (show_ip_ospf_database_max
,
6319 show_ip_ospf_database_max_cmd
,
6320 "show ip ospf [vrf <NAME|all>] database <max-age|self-originate>",
6323 "OSPF information\n"
6326 "Database summary\n"
6327 "LSAs in MaxAge list\n"
6328 "Self-originated link states\n")
6330 struct ospf
*ospf
= NULL
;
6331 struct listnode
*node
= NULL
;
6332 char *vrf_name
= NULL
;
6333 bool all_vrf
= FALSE
;
6334 int ret
= CMD_SUCCESS
;
6339 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
6344 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6345 if (!ospf
->oi_running
)
6347 ret
= show_ip_ospf_database_common(vty
, ospf
,
6354 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6355 if (ospf
== NULL
|| !ospf
->oi_running
)
6357 ret
= (show_ip_ospf_database_common(vty
, ospf
, idx_vrf
?
6362 /* Display default ospf (instance 0) info */
6363 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6364 if (ospf
== NULL
|| !ospf
->oi_running
)
6366 ret
= show_ip_ospf_database_common(vty
, ospf
, 0, argc
, argv
,
6373 DEFUN (show_ip_ospf_instance_database
,
6374 show_ip_ospf_instance_database_cmd
,
6375 "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>]]]",
6378 "OSPF information\n"
6381 "Database summary\n"
6383 "Link State ID (as an IP address)\n"
6384 "Self-originated link states\n"
6385 "Advertising Router link states\n"
6386 "Advertising Router (as an IP address)\n")
6389 u_short instance
= 0;
6390 struct listnode
*node
= NULL
;
6391 char *vrf_name
= NULL
;
6392 bool all_vrf
= FALSE
;
6393 int ret
= CMD_SUCCESS
;
6398 if (argv_find(argv
, argc
, "(1-65535)", &idx
)) {
6399 instance
= strtoul(argv
[idx
]->arg
, NULL
, 10);
6400 ospf
= ospf_lookup_instance(instance
);
6402 return CMD_NOT_MY_INSTANCE
;
6403 if (!ospf
->oi_running
)
6406 return (show_ip_ospf_database_common(vty
, ospf
, idx
? 1 : 0,
6407 argc
, argv
, use_vrf
));
6408 } else if (argv_find(argv
, argc
, "vrf", &idx
)) {
6409 vrf_name
= argv
[++idx
]->arg
;
6410 all_vrf
= strmatch(vrf_name
, "all");
6416 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6417 if (!ospf
->oi_running
)
6419 ret
= (show_ip_ospf_database_common(vty
, ospf
,
6425 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6426 if ((ospf
== NULL
) || !ospf
->oi_running
)
6428 ret
= (show_ip_ospf_database_common(vty
, ospf
, idx
? 2 :
6433 /* Display default ospf (instance 0) info */
6434 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6435 if (ospf
== NULL
|| !ospf
->oi_running
)
6437 ret
= (show_ip_ospf_database_common(vty
, ospf
, 0, argc
, argv
,
6444 DEFUN (show_ip_ospf_instance_database_max
,
6445 show_ip_ospf_instance_database_max_cmd
,
6446 "show ip ospf (1-65535) database <max-age|self-originate>",
6449 "OSPF information\n"
6451 "Database summary\n"
6452 "LSAs in MaxAge list\n"
6453 "Self-originated link states\n")
6457 u_short instance
= 0;
6459 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
6461 ospf
= ospf_lookup_instance(instance
);
6463 return CMD_NOT_MY_INSTANCE
;
6465 if (!ospf
->oi_running
)
6468 return show_ip_ospf_database_common(vty
, ospf
, 1, argc
, argv
, 0);
6472 static int show_ip_ospf_database_type_adv_router_common(struct vty
*vty
,
6474 int arg_base
, int argc
,
6475 struct cmd_token
**argv
,
6480 struct in_addr adv_router
;
6483 vty_out(vty
, "\nOSPF Instance: %d\n", ospf
->instance
);
6485 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
6487 vty_out(vty
, "\n OSPF Router with ID (%s)\n\n",
6488 inet_ntoa(ospf
->router_id
));
6490 /* Set database type to show. */
6491 if (strncmp(argv
[arg_base
+ idx_type
]->text
, "r", 1) == 0)
6492 type
= OSPF_ROUTER_LSA
;
6493 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ne", 2) == 0)
6494 type
= OSPF_NETWORK_LSA
;
6495 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "ns", 2) == 0)
6496 type
= OSPF_AS_NSSA_LSA
;
6497 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "s", 1) == 0)
6498 type
= OSPF_SUMMARY_LSA
;
6499 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "a", 1) == 0)
6500 type
= OSPF_ASBR_SUMMARY_LSA
;
6501 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "e", 1) == 0)
6502 type
= OSPF_AS_EXTERNAL_LSA
;
6503 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-l", 8) == 0)
6504 type
= OSPF_OPAQUE_LINK_LSA
;
6505 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-ar", 9) == 0)
6506 type
= OSPF_OPAQUE_AREA_LSA
;
6507 else if (strncmp(argv
[arg_base
+ idx_type
]->text
, "opaque-as", 9) == 0)
6508 type
= OSPF_OPAQUE_AS_LSA
;
6512 /* `show ip ospf database LSA adv-router ADV_ROUTER'. */
6513 if (strncmp(argv
[arg_base
+ 5]->text
, "s", 1) == 0)
6514 adv_router
= ospf
->router_id
;
6516 ret
= inet_aton(argv
[arg_base
+ 6]->arg
, &adv_router
);
6521 show_lsa_detail_adv_router(vty
, ospf
, type
, &adv_router
);
6526 DEFUN (show_ip_ospf_instance_database_type_adv_router
,
6527 show_ip_ospf_instance_database_type_adv_router_cmd
,
6528 "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>",
6531 "OSPF information\n"
6534 "Database summary\n"
6536 "Advertising Router link states\n"
6537 "Advertising Router (as an IP address)\n"
6538 "Self-originated link states\n")
6540 struct ospf
*ospf
= NULL
;
6541 u_short instance
= 0;
6542 struct listnode
*node
= NULL
;
6543 char *vrf_name
= NULL
;
6544 bool all_vrf
= FALSE
;
6545 int ret
= CMD_SUCCESS
;
6547 int idx
= 0, idx_vrf
= 0;
6550 if (argv_find(argv
, argc
, "(1-65535)", &idx
)) {
6551 instance
= strtoul(argv
[idx
]->arg
, NULL
, 10);
6552 ospf
= ospf_lookup_instance(instance
);
6554 return CMD_NOT_MY_INSTANCE
;
6555 if (!ospf
->oi_running
)
6557 return (show_ip_ospf_database_type_adv_router_common(vty
, ospf
,
6564 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
6569 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
6570 if (!ospf
->oi_running
)
6572 ret
= show_ip_ospf_database_type_adv_router_common(vty
,
6573 ospf
, idx
? 1 : 0, argc
, argv
,
6577 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
6578 if ((ospf
== NULL
) || !ospf
->oi_running
)
6580 ret
= show_ip_ospf_database_type_adv_router_common(vty
,
6581 ospf
, idx
? 1 : 0, argc
, argv
,
6585 /* Display default ospf (instance 0) info */
6586 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
6587 if (ospf
== NULL
|| !ospf
->oi_running
)
6589 ret
= show_ip_ospf_database_type_adv_router_common(vty
, ospf
,
6595 /*return (show_ip_ospf_database_type_adv_router_common(
6596 vty, ospf, idx ? 1 : 0, argc, argv));*/
6599 DEFUN (ip_ospf_authentication_args
,
6600 ip_ospf_authentication_args_addr_cmd
,
6601 "ip ospf authentication <null|message-digest> [A.B.C.D]",
6603 "OSPF interface commands\n"
6604 "Enable authentication on this interface\n"
6605 "Use null authentication\n"
6606 "Use message-digest authentication\n"
6607 "Address of interface\n")
6609 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6610 int idx_encryption
= 3;
6612 struct in_addr addr
;
6614 struct ospf_if_params
*params
;
6616 params
= IF_DEF_PARAMS(ifp
);
6619 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6622 "Please specify interface address by A.B.C.D\n");
6623 return CMD_WARNING_CONFIG_FAILED
;
6626 params
= ospf_get_if_params(ifp
, addr
);
6627 ospf_if_update_params(ifp
, addr
);
6630 /* Handle null authentication */
6631 if (argv
[idx_encryption
]->arg
[0] == 'n') {
6632 SET_IF_PARAM(params
, auth_type
);
6633 params
->auth_type
= OSPF_AUTH_NULL
;
6637 /* Handle message-digest authentication */
6638 if (argv
[idx_encryption
]->arg
[0] == 'm') {
6639 SET_IF_PARAM(params
, auth_type
);
6640 params
->auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
6644 vty_out(vty
, "You shouldn't get here!\n");
6645 return CMD_WARNING_CONFIG_FAILED
;
6648 DEFUN (ip_ospf_authentication
,
6649 ip_ospf_authentication_addr_cmd
,
6650 "ip ospf authentication [A.B.C.D]",
6652 "OSPF interface commands\n"
6653 "Enable authentication on this interface\n"
6654 "Address of interface\n")
6656 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6658 struct in_addr addr
;
6660 struct ospf_if_params
*params
;
6662 params
= IF_DEF_PARAMS(ifp
);
6665 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6668 "Please specify interface address by A.B.C.D\n");
6669 return CMD_WARNING_CONFIG_FAILED
;
6672 params
= ospf_get_if_params(ifp
, addr
);
6673 ospf_if_update_params(ifp
, addr
);
6676 SET_IF_PARAM(params
, auth_type
);
6677 params
->auth_type
= OSPF_AUTH_SIMPLE
;
6682 DEFUN (no_ip_ospf_authentication_args
,
6683 no_ip_ospf_authentication_args_addr_cmd
,
6684 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
6687 "OSPF interface commands\n"
6688 "Enable authentication on this interface\n"
6689 "Use null authentication\n"
6690 "Use message-digest authentication\n"
6691 "Address of interface\n")
6693 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6694 int idx_encryption
= 4;
6696 struct in_addr addr
;
6698 struct ospf_if_params
*params
;
6699 struct route_node
*rn
;
6702 params
= IF_DEF_PARAMS(ifp
);
6705 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6708 "Please specify interface address by A.B.C.D\n");
6709 return CMD_WARNING_CONFIG_FAILED
;
6712 params
= ospf_lookup_if_params(ifp
, addr
);
6713 if (params
== NULL
) {
6714 vty_out(vty
, "Ip Address specified is unknown\n");
6715 return CMD_WARNING_CONFIG_FAILED
;
6717 params
->auth_type
= OSPF_AUTH_NOTSET
;
6718 UNSET_IF_PARAM(params
, auth_type
);
6719 if (params
!= IF_DEF_PARAMS(ifp
)) {
6720 ospf_free_if_params(ifp
, addr
);
6721 ospf_if_update_params(ifp
, addr
);
6724 if (argv
[idx_encryption
]->arg
[0] == 'n') {
6725 auth_type
= OSPF_AUTH_NULL
;
6726 } else if (argv
[idx_encryption
]->arg
[0] == 'm') {
6727 auth_type
= OSPF_AUTH_CRYPTOGRAPHIC
;
6729 vty_out(vty
, "Unexpected input encountered\n");
6730 return CMD_WARNING_CONFIG_FAILED
;
6733 * Here we have a case where the user has entered
6734 * 'no ip ospf authentication (null | message_digest )'
6735 * we need to find if we have any ip addresses underneath it
6737 * correspond to the associated type.
6739 if (params
->auth_type
== auth_type
) {
6740 params
->auth_type
= OSPF_AUTH_NOTSET
;
6741 UNSET_IF_PARAM(params
, auth_type
);
6744 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
6745 rn
= route_next(rn
)) {
6746 if ((params
= rn
->info
)) {
6747 if (params
->auth_type
== auth_type
) {
6748 params
->auth_type
= OSPF_AUTH_NOTSET
;
6749 UNSET_IF_PARAM(params
, auth_type
);
6750 if (params
!= IF_DEF_PARAMS(ifp
)) {
6751 ospf_free_if_params(
6752 ifp
, rn
->p
.u
.prefix4
);
6753 ospf_if_update_params(
6754 ifp
, rn
->p
.u
.prefix4
);
6764 DEFUN (no_ip_ospf_authentication
,
6765 no_ip_ospf_authentication_addr_cmd
,
6766 "no ip ospf authentication [A.B.C.D]",
6769 "OSPF interface commands\n"
6770 "Enable authentication on this interface\n"
6771 "Address of interface\n")
6773 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6775 struct in_addr addr
;
6777 struct ospf_if_params
*params
;
6778 struct route_node
*rn
;
6780 params
= IF_DEF_PARAMS(ifp
);
6783 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
6786 "Please specify interface address by A.B.C.D\n");
6787 return CMD_WARNING_CONFIG_FAILED
;
6790 params
= ospf_lookup_if_params(ifp
, addr
);
6791 if (params
== NULL
) {
6792 vty_out(vty
, "Ip Address specified is unknown\n");
6793 return CMD_WARNING_CONFIG_FAILED
;
6796 params
->auth_type
= OSPF_AUTH_NOTSET
;
6797 UNSET_IF_PARAM(params
, auth_type
);
6798 if (params
!= IF_DEF_PARAMS(ifp
)) {
6799 ospf_free_if_params(ifp
, addr
);
6800 ospf_if_update_params(ifp
, addr
);
6804 * When a user enters 'no ip ospf authentication'
6805 * We should remove all authentication types from
6808 if ((params
->auth_type
== OSPF_AUTH_NULL
)
6809 || (params
->auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
)
6810 || (params
->auth_type
== OSPF_AUTH_SIMPLE
)) {
6811 params
->auth_type
= OSPF_AUTH_NOTSET
;
6812 UNSET_IF_PARAM(params
, auth_type
);
6815 for (rn
= route_top(IF_OIFS_PARAMS(ifp
)); rn
;
6816 rn
= route_next(rn
)) {
6817 if ((params
= rn
->info
)) {
6819 if ((params
->auth_type
== OSPF_AUTH_NULL
)
6820 || (params
->auth_type
6821 == OSPF_AUTH_CRYPTOGRAPHIC
)
6822 || (params
->auth_type
6823 == OSPF_AUTH_SIMPLE
)) {
6824 params
->auth_type
= OSPF_AUTH_NOTSET
;
6825 UNSET_IF_PARAM(params
, auth_type
);
6826 if (params
!= IF_DEF_PARAMS(ifp
)) {
6827 ospf_free_if_params(
6828 ifp
, rn
->p
.u
.prefix4
);
6829 ospf_if_update_params(
6830 ifp
, rn
->p
.u
.prefix4
);
6841 DEFUN (ip_ospf_authentication_key
,
6842 ip_ospf_authentication_key_addr_cmd
,
6843 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
6845 "OSPF interface commands\n"
6846 "Authentication password (key)\n"
6847 "The OSPF password (key)\n"
6848 "Address of interface\n")
6850 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6852 struct in_addr addr
;
6853 struct ospf_if_params
*params
;
6855 params
= IF_DEF_PARAMS(ifp
);
6857 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6858 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6860 "Please specify interface address by A.B.C.D\n");
6861 return CMD_WARNING_CONFIG_FAILED
;
6864 params
= ospf_get_if_params(ifp
, addr
);
6865 ospf_if_update_params(ifp
, addr
);
6868 memset(params
->auth_simple
, 0, OSPF_AUTH_SIMPLE_SIZE
+ 1);
6869 strncpy((char *)params
->auth_simple
, argv
[3]->arg
,
6870 OSPF_AUTH_SIMPLE_SIZE
);
6871 SET_IF_PARAM(params
, auth_simple
);
6876 DEFUN_HIDDEN (ospf_authentication_key
,
6877 ospf_authentication_key_cmd
,
6878 "ospf authentication-key AUTH_KEY [A.B.C.D]",
6879 "OSPF interface commands\n"
6880 VLINK_HELPSTR_AUTH_SIMPLE
6881 "Address of interface\n")
6883 return ip_ospf_authentication_key(self
, vty
, argc
, argv
);
6886 DEFUN (no_ip_ospf_authentication_key
,
6887 no_ip_ospf_authentication_key_authkey_addr_cmd
,
6888 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
6891 "OSPF interface commands\n"
6892 VLINK_HELPSTR_AUTH_SIMPLE
6893 "Address of interface\n")
6895 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6897 struct in_addr addr
;
6898 struct ospf_if_params
*params
;
6899 params
= IF_DEF_PARAMS(ifp
);
6901 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6902 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6904 "Please specify interface address by A.B.C.D\n");
6905 return CMD_WARNING_CONFIG_FAILED
;
6908 params
= ospf_lookup_if_params(ifp
, addr
);
6913 memset(params
->auth_simple
, 0, OSPF_AUTH_SIMPLE_SIZE
);
6914 UNSET_IF_PARAM(params
, auth_simple
);
6916 if (params
!= IF_DEF_PARAMS(ifp
)) {
6917 ospf_free_if_params(ifp
, addr
);
6918 ospf_if_update_params(ifp
, addr
);
6924 DEFUN_HIDDEN (no_ospf_authentication_key
,
6925 no_ospf_authentication_key_authkey_addr_cmd
,
6926 "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
6928 "OSPF interface commands\n"
6929 VLINK_HELPSTR_AUTH_SIMPLE
6930 "Address of interface\n")
6932 return no_ip_ospf_authentication_key(self
, vty
, argc
, argv
);
6935 DEFUN (ip_ospf_message_digest_key
,
6936 ip_ospf_message_digest_key_cmd
,
6937 "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
6939 "OSPF interface commands\n"
6940 "Message digest authentication password (key)\n"
6942 "Use MD5 algorithm\n"
6943 "The OSPF password (key)\n"
6944 "Address of interface\n")
6946 VTY_DECLVAR_CONTEXT(interface
, ifp
);
6947 struct crypt_key
*ck
;
6949 struct in_addr addr
;
6950 struct ospf_if_params
*params
;
6952 params
= IF_DEF_PARAMS(ifp
);
6955 argv_find(argv
, argc
, "(1-255)", &idx
);
6956 char *keyid
= argv
[idx
]->arg
;
6957 argv_find(argv
, argc
, "KEY", &idx
);
6958 char *cryptkey
= argv
[idx
]->arg
;
6960 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
6961 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
6963 "Please specify interface address by A.B.C.D\n");
6964 return CMD_WARNING_CONFIG_FAILED
;
6967 params
= ospf_get_if_params(ifp
, addr
);
6968 ospf_if_update_params(ifp
, addr
);
6971 key_id
= strtol(keyid
, NULL
, 10);
6972 if (ospf_crypt_key_lookup(params
->auth_crypt
, key_id
) != NULL
) {
6973 vty_out(vty
, "OSPF: Key %d already exists\n", key_id
);
6977 ck
= ospf_crypt_key_new();
6978 ck
->key_id
= (u_char
)key_id
;
6979 memset(ck
->auth_key
, 0, OSPF_AUTH_MD5_SIZE
+ 1);
6980 strncpy((char *)ck
->auth_key
, cryptkey
, OSPF_AUTH_MD5_SIZE
);
6982 ospf_crypt_key_add(params
->auth_crypt
, ck
);
6983 SET_IF_PARAM(params
, auth_crypt
);
6988 DEFUN_HIDDEN (ospf_message_digest_key
,
6989 ospf_message_digest_key_cmd
,
6990 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
6991 "OSPF interface commands\n"
6992 "Message digest authentication password (key)\n"
6994 "Use MD5 algorithm\n"
6995 "The OSPF password (key)\n"
6996 "Address of interface\n")
6998 return ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7001 DEFUN (no_ip_ospf_message_digest_key
,
7002 no_ip_ospf_message_digest_key_cmd
,
7003 "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7006 "OSPF interface commands\n"
7007 "Message digest authentication password (key)\n"
7009 "Use MD5 algorithm\n"
7010 "The OSPF password (key)\n"
7011 "Address of interface\n")
7013 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7015 struct crypt_key
*ck
;
7017 struct in_addr addr
;
7018 struct ospf_if_params
*params
;
7019 params
= IF_DEF_PARAMS(ifp
);
7021 argv_find(argv
, argc
, "(1-255)", &idx
);
7022 char *keyid
= argv
[idx
]->arg
;
7024 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7025 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7027 "Please specify interface address by A.B.C.D\n");
7028 return CMD_WARNING_CONFIG_FAILED
;
7031 params
= ospf_lookup_if_params(ifp
, addr
);
7036 key_id
= strtol(keyid
, NULL
, 10);
7037 ck
= ospf_crypt_key_lookup(params
->auth_crypt
, key_id
);
7039 vty_out(vty
, "OSPF: Key %d does not exist\n", key_id
);
7040 return CMD_WARNING_CONFIG_FAILED
;
7043 ospf_crypt_key_delete(params
->auth_crypt
, key_id
);
7045 if (params
!= IF_DEF_PARAMS(ifp
)) {
7046 ospf_free_if_params(ifp
, addr
);
7047 ospf_if_update_params(ifp
, addr
);
7053 DEFUN_HIDDEN (no_ospf_message_digest_key
,
7054 no_ospf_message_digest_key_cmd
,
7055 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7057 "OSPF interface commands\n"
7058 "Message digest authentication password (key)\n"
7060 "Use MD5 algorithm\n"
7061 "The OSPF password (key)\n"
7062 "Address of interface\n")
7064 return no_ip_ospf_message_digest_key(self
, vty
, argc
, argv
);
7067 DEFUN (ip_ospf_cost
,
7069 "ip ospf cost (1-65535) [A.B.C.D]",
7071 "OSPF interface commands\n"
7074 "Address of interface\n")
7076 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7078 u_int32_t cost
= OSPF_OUTPUT_COST_DEFAULT
;
7079 struct in_addr addr
;
7080 struct ospf_if_params
*params
;
7081 params
= IF_DEF_PARAMS(ifp
);
7084 char *coststr
= NULL
, *ifaddr
= NULL
;
7086 argv_find(argv
, argc
, "(1-65535)", &idx
);
7087 coststr
= argv
[idx
]->arg
;
7088 cost
= strtol(coststr
, NULL
, 10);
7090 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7092 if (!inet_aton(ifaddr
, &addr
)) {
7094 "Please specify interface address by A.B.C.D\n");
7095 return CMD_WARNING_CONFIG_FAILED
;
7098 params
= ospf_get_if_params(ifp
, addr
);
7099 ospf_if_update_params(ifp
, addr
);
7102 SET_IF_PARAM(params
, output_cost_cmd
);
7103 params
->output_cost_cmd
= cost
;
7105 ospf_if_recalculate_output_cost(ifp
);
7110 DEFUN_HIDDEN (ospf_cost
,
7112 "ospf cost (1-65535) [A.B.C.D]",
7113 "OSPF interface commands\n"
7116 "Address of interface\n")
7118 return ip_ospf_cost(self
, vty
, argc
, argv
);
7121 DEFUN (no_ip_ospf_cost
,
7122 no_ip_ospf_cost_cmd
,
7123 "no ip ospf cost [(1-65535)] [A.B.C.D]",
7126 "OSPF interface commands\n"
7129 "Address of interface\n")
7131 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7133 struct in_addr addr
;
7134 struct ospf_if_params
*params
;
7136 params
= IF_DEF_PARAMS(ifp
);
7139 char *ifaddr
= NULL
;
7140 ifaddr
= argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7142 /* According to the semantics we are mimicking "no ip ospf cost N" is
7143 * always treated as "no ip ospf cost" regardless of the actual value
7144 * of N already configured for the interface. Thus ignore cost. */
7147 if (!inet_aton(ifaddr
, &addr
)) {
7149 "Please specify interface address by A.B.C.D\n");
7150 return CMD_WARNING_CONFIG_FAILED
;
7153 params
= ospf_lookup_if_params(ifp
, addr
);
7158 UNSET_IF_PARAM(params
, output_cost_cmd
);
7160 if (params
!= IF_DEF_PARAMS(ifp
)) {
7161 ospf_free_if_params(ifp
, addr
);
7162 ospf_if_update_params(ifp
, addr
);
7165 ospf_if_recalculate_output_cost(ifp
);
7170 DEFUN_HIDDEN (no_ospf_cost
,
7172 "no ospf cost [(1-65535)] [A.B.C.D]",
7174 "OSPF interface commands\n"
7177 "Address of interface\n")
7179 return no_ip_ospf_cost(self
, vty
, argc
, argv
);
7182 static void ospf_nbr_timer_update(struct ospf_interface
*oi
)
7184 struct route_node
*rn
;
7185 struct ospf_neighbor
*nbr
;
7187 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
7188 if ((nbr
= rn
->info
)) {
7189 nbr
->v_inactivity
= OSPF_IF_PARAM(oi
, v_wait
);
7190 nbr
->v_db_desc
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7191 nbr
->v_ls_req
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7192 nbr
->v_ls_upd
= OSPF_IF_PARAM(oi
, retransmit_interval
);
7196 static int ospf_vty_dead_interval_set(struct vty
*vty
, const char *interval_str
,
7197 const char *nbr_str
,
7198 const char *fast_hello_str
)
7200 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7203 struct in_addr addr
;
7205 struct ospf_if_params
*params
;
7206 struct ospf_interface
*oi
;
7207 struct route_node
*rn
;
7209 params
= IF_DEF_PARAMS(ifp
);
7212 ret
= inet_aton(nbr_str
, &addr
);
7215 "Please specify interface address by A.B.C.D\n");
7216 return CMD_WARNING_CONFIG_FAILED
;
7219 params
= ospf_get_if_params(ifp
, addr
);
7220 ospf_if_update_params(ifp
, addr
);
7224 seconds
= strtoul(interval_str
, NULL
, 10);
7226 /* reset fast_hello too, just to be sure */
7227 UNSET_IF_PARAM(params
, fast_hello
);
7228 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
7229 } else if (fast_hello_str
) {
7230 hellomult
= strtoul(fast_hello_str
, NULL
, 10);
7231 /* 1s dead-interval with sub-second hellos desired */
7232 seconds
= OSPF_ROUTER_DEAD_INTERVAL_MINIMAL
;
7233 SET_IF_PARAM(params
, fast_hello
);
7234 params
->fast_hello
= hellomult
;
7237 "Please specify dead-interval or hello-multiplier\n");
7238 return CMD_WARNING_CONFIG_FAILED
;
7241 SET_IF_PARAM(params
, v_wait
);
7242 params
->v_wait
= seconds
;
7244 /* Update timer values in neighbor structure. */
7246 struct ospf
*ospf
= NULL
;
7248 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7250 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
7252 ospf_nbr_timer_update(oi
);
7255 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
7256 if ((oi
= rn
->info
))
7257 ospf_nbr_timer_update(oi
);
7263 DEFUN (ip_ospf_dead_interval
,
7264 ip_ospf_dead_interval_cmd
,
7265 "ip ospf dead-interval (1-65535) [A.B.C.D]",
7267 "OSPF interface commands\n"
7268 "Interval time after which a neighbor is declared down\n"
7270 "Address of interface\n")
7273 char *interval
= argv_find(argv
, argc
, "(1-65535)", &idx
)
7277 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
7278 return ospf_vty_dead_interval_set(vty
, interval
, ifaddr
, NULL
);
7282 DEFUN_HIDDEN (ospf_dead_interval
,
7283 ospf_dead_interval_cmd
,
7284 "ospf dead-interval (1-65535) [A.B.C.D]",
7285 "OSPF interface commands\n"
7286 "Interval time after which a neighbor is declared down\n"
7288 "Address of interface\n")
7290 return ip_ospf_dead_interval(self
, vty
, argc
, argv
);
7293 DEFUN (ip_ospf_dead_interval_minimal
,
7294 ip_ospf_dead_interval_minimal_addr_cmd
,
7295 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
7297 "OSPF interface commands\n"
7298 "Interval time after which a neighbor is declared down\n"
7299 "Minimal 1s dead-interval with fast sub-second hellos\n"
7300 "Hello multiplier factor\n"
7301 "Number of Hellos to send each second\n"
7302 "Address of interface\n")
7307 return ospf_vty_dead_interval_set(
7308 vty
, NULL
, argv
[idx_ipv4
]->arg
, argv
[idx_number
]->arg
);
7310 return ospf_vty_dead_interval_set(vty
, NULL
, NULL
,
7311 argv
[idx_number
]->arg
);
7314 DEFUN (no_ip_ospf_dead_interval
,
7315 no_ip_ospf_dead_interval_cmd
,
7316 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
7319 "OSPF interface commands\n"
7320 "Interval time after which a neighbor is declared down\n"
7322 "Minimal 1s dead-interval with fast sub-second hellos\n"
7323 "Hello multiplier factor\n"
7324 "Number of Hellos to send each second\n"
7325 "Address of interface\n")
7327 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7328 int idx_ipv4
= argc
- 1;
7329 struct in_addr addr
= {.s_addr
= 0L};
7331 struct ospf_if_params
*params
;
7332 struct ospf_interface
*oi
;
7333 struct route_node
*rn
;
7335 params
= IF_DEF_PARAMS(ifp
);
7337 if (argv
[idx_ipv4
]->type
== IPV4_TKN
) {
7338 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
7341 "Please specify interface address by A.B.C.D\n");
7342 return CMD_WARNING_CONFIG_FAILED
;
7345 params
= ospf_lookup_if_params(ifp
, addr
);
7350 UNSET_IF_PARAM(params
, v_wait
);
7351 params
->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
7353 UNSET_IF_PARAM(params
, fast_hello
);
7354 params
->fast_hello
= OSPF_FAST_HELLO_DEFAULT
;
7356 if (params
!= IF_DEF_PARAMS(ifp
)) {
7357 ospf_free_if_params(ifp
, addr
);
7358 ospf_if_update_params(ifp
, addr
);
7361 /* Update timer values in neighbor structure. */
7363 struct ospf
*ospf
= NULL
;
7365 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7367 oi
= ospf_if_lookup_by_local_addr(ospf
, ifp
, addr
);
7369 ospf_nbr_timer_update(oi
);
7372 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
))
7373 if ((oi
= rn
->info
))
7374 ospf_nbr_timer_update(oi
);
7380 DEFUN_HIDDEN (no_ospf_dead_interval
,
7381 no_ospf_dead_interval_cmd
,
7382 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
7384 "OSPF interface commands\n"
7385 "Interval time after which a neighbor is declared down\n"
7387 "Minimal 1s dead-interval with fast sub-second hellos\n"
7388 "Hello multiplier factor\n"
7389 "Number of Hellos to send each second\n"
7390 "Address of interface\n")
7392 return no_ip_ospf_dead_interval(self
, vty
, argc
, argv
);
7395 DEFUN (ip_ospf_hello_interval
,
7396 ip_ospf_hello_interval_cmd
,
7397 "ip ospf hello-interval (1-65535) [A.B.C.D]",
7399 "OSPF interface commands\n"
7400 "Time between HELLO packets\n"
7402 "Address of interface\n")
7404 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7406 struct in_addr addr
;
7407 struct ospf_if_params
*params
;
7408 params
= IF_DEF_PARAMS(ifp
);
7409 u_int32_t seconds
= 0;
7411 argv_find(argv
, argc
, "(1-65535)", &idx
);
7412 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7414 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7415 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7417 "Please specify interface address by A.B.C.D\n");
7418 return CMD_WARNING_CONFIG_FAILED
;
7421 params
= ospf_get_if_params(ifp
, addr
);
7422 ospf_if_update_params(ifp
, addr
);
7425 SET_IF_PARAM(params
, v_hello
);
7426 params
->v_hello
= seconds
;
7431 DEFUN_HIDDEN (ospf_hello_interval
,
7432 ospf_hello_interval_cmd
,
7433 "ospf hello-interval (1-65535) [A.B.C.D]",
7434 "OSPF interface commands\n"
7435 "Time between HELLO packets\n"
7437 "Address of interface\n")
7439 return ip_ospf_hello_interval(self
, vty
, argc
, argv
);
7442 DEFUN (no_ip_ospf_hello_interval
,
7443 no_ip_ospf_hello_interval_cmd
,
7444 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
7447 "OSPF interface commands\n"
7448 "Time between HELLO packets\n" // ignored
7450 "Address of interface\n")
7452 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7454 struct in_addr addr
;
7455 struct ospf_if_params
*params
;
7457 params
= IF_DEF_PARAMS(ifp
);
7459 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7460 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7462 "Please specify interface address by A.B.C.D\n");
7463 return CMD_WARNING_CONFIG_FAILED
;
7466 params
= ospf_lookup_if_params(ifp
, addr
);
7471 UNSET_IF_PARAM(params
, v_hello
);
7472 params
->v_hello
= OSPF_HELLO_INTERVAL_DEFAULT
;
7474 if (params
!= IF_DEF_PARAMS(ifp
)) {
7475 ospf_free_if_params(ifp
, addr
);
7476 ospf_if_update_params(ifp
, addr
);
7482 DEFUN_HIDDEN (no_ospf_hello_interval
,
7483 no_ospf_hello_interval_cmd
,
7484 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
7486 "OSPF interface commands\n"
7487 "Time between HELLO packets\n" // ignored
7489 "Address of interface\n")
7491 return no_ip_ospf_hello_interval(self
, vty
, argc
, argv
);
7494 DEFUN (ip_ospf_network
,
7495 ip_ospf_network_cmd
,
7496 "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
7498 "OSPF interface commands\n"
7500 "Specify OSPF broadcast multi-access network\n"
7501 "Specify OSPF NBMA network\n"
7502 "Specify OSPF point-to-multipoint network\n"
7503 "Specify OSPF point-to-point network\n")
7505 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7507 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
7508 struct route_node
*rn
;
7510 if (old_type
== OSPF_IFTYPE_LOOPBACK
) {
7512 "This is a loopback interface. Can't set network type.\n");
7513 return CMD_WARNING_CONFIG_FAILED
;
7516 if (argv_find(argv
, argc
, "broadcast", &idx
))
7517 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_BROADCAST
;
7518 else if (argv_find(argv
, argc
, "non-broadcast", &idx
))
7519 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_NBMA
;
7520 else if (argv_find(argv
, argc
, "point-to-multipoint", &idx
))
7521 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOMULTIPOINT
;
7522 else if (argv_find(argv
, argc
, "point-to-point", &idx
))
7523 IF_DEF_PARAMS(ifp
)->type
= OSPF_IFTYPE_POINTOPOINT
;
7525 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
7528 SET_IF_PARAM(IF_DEF_PARAMS(ifp
), type
);
7530 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7531 struct ospf_interface
*oi
= rn
->info
;
7536 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
7538 if (oi
->state
> ISM_Down
) {
7539 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
7540 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
7547 DEFUN_HIDDEN (ospf_network
,
7549 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
7550 "OSPF interface commands\n"
7552 "Specify OSPF broadcast multi-access network\n"
7553 "Specify OSPF NBMA network\n"
7554 "Specify OSPF point-to-multipoint network\n"
7555 "Specify OSPF point-to-point network\n")
7557 return ip_ospf_network(self
, vty
, argc
, argv
);
7560 DEFUN (no_ip_ospf_network
,
7561 no_ip_ospf_network_cmd
,
7562 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
7565 "OSPF interface commands\n"
7567 "Specify OSPF broadcast multi-access network\n"
7568 "Specify OSPF NBMA network\n"
7569 "Specify OSPF point-to-multipoint network\n"
7570 "Specify OSPF point-to-point network\n")
7572 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7573 int old_type
= IF_DEF_PARAMS(ifp
)->type
;
7574 struct route_node
*rn
;
7576 IF_DEF_PARAMS(ifp
)->type
= ospf_default_iftype(ifp
);
7578 if (IF_DEF_PARAMS(ifp
)->type
== old_type
)
7581 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7582 struct ospf_interface
*oi
= rn
->info
;
7587 oi
->type
= IF_DEF_PARAMS(ifp
)->type
;
7589 if (oi
->state
> ISM_Down
) {
7590 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceDown
);
7591 OSPF_ISM_EVENT_EXECUTE(oi
, ISM_InterfaceUp
);
7598 DEFUN_HIDDEN (no_ospf_network
,
7599 no_ospf_network_cmd
,
7600 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
7602 "OSPF interface commands\n"
7604 "Specify OSPF broadcast multi-access network\n"
7605 "Specify OSPF NBMA network\n"
7606 "Specify OSPF point-to-multipoint network\n"
7607 "Specify OSPF point-to-point network\n")
7609 return no_ip_ospf_network(self
, vty
, argc
, argv
);
7612 DEFUN (ip_ospf_priority
,
7613 ip_ospf_priority_cmd
,
7614 "ip ospf priority (0-255) [A.B.C.D]",
7616 "OSPF interface commands\n"
7619 "Address of interface\n")
7621 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7624 struct route_node
*rn
;
7625 struct in_addr addr
;
7626 struct ospf_if_params
*params
;
7627 params
= IF_DEF_PARAMS(ifp
);
7629 argv_find(argv
, argc
, "(0-255)", &idx
);
7630 priority
= strtol(argv
[idx
]->arg
, NULL
, 10);
7632 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7633 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7635 "Please specify interface address by A.B.C.D\n");
7636 return CMD_WARNING_CONFIG_FAILED
;
7639 params
= ospf_get_if_params(ifp
, addr
);
7640 ospf_if_update_params(ifp
, addr
);
7643 SET_IF_PARAM(params
, priority
);
7644 params
->priority
= priority
;
7646 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7647 struct ospf_interface
*oi
= rn
->info
;
7652 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
7653 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
7654 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
7661 DEFUN_HIDDEN (ospf_priority
,
7663 "ospf priority (0-255) [A.B.C.D]",
7664 "OSPF interface commands\n"
7667 "Address of interface\n")
7669 return ip_ospf_priority(self
, vty
, argc
, argv
);
7672 DEFUN (no_ip_ospf_priority
,
7673 no_ip_ospf_priority_cmd
,
7674 "no ip ospf priority [(0-255) [A.B.C.D]]",
7677 "OSPF interface commands\n"
7678 "Router priority\n" // ignored
7680 "Address of interface\n")
7682 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7684 struct route_node
*rn
;
7685 struct in_addr addr
;
7686 struct ospf_if_params
*params
;
7688 params
= IF_DEF_PARAMS(ifp
);
7690 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7691 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7693 "Please specify interface address by A.B.C.D\n");
7694 return CMD_WARNING_CONFIG_FAILED
;
7697 params
= ospf_lookup_if_params(ifp
, addr
);
7702 UNSET_IF_PARAM(params
, priority
);
7703 params
->priority
= OSPF_ROUTER_PRIORITY_DEFAULT
;
7705 if (params
!= IF_DEF_PARAMS(ifp
)) {
7706 ospf_free_if_params(ifp
, addr
);
7707 ospf_if_update_params(ifp
, addr
);
7710 for (rn
= route_top(IF_OIFS(ifp
)); rn
; rn
= route_next(rn
)) {
7711 struct ospf_interface
*oi
= rn
->info
;
7716 if (PRIORITY(oi
) != OSPF_IF_PARAM(oi
, priority
)) {
7717 PRIORITY(oi
) = OSPF_IF_PARAM(oi
, priority
);
7718 OSPF_ISM_EVENT_SCHEDULE(oi
, ISM_NeighborChange
);
7725 DEFUN_HIDDEN (no_ospf_priority
,
7726 no_ospf_priority_cmd
,
7727 "no ospf priority [(0-255) [A.B.C.D]]",
7729 "OSPF interface commands\n"
7732 "Address of interface\n")
7734 return no_ip_ospf_priority(self
, vty
, argc
, argv
);
7737 DEFUN (ip_ospf_retransmit_interval
,
7738 ip_ospf_retransmit_interval_addr_cmd
,
7739 "ip ospf retransmit-interval (3-65535) [A.B.C.D]",
7741 "OSPF interface commands\n"
7742 "Time between retransmitting lost link state advertisements\n"
7744 "Address of interface\n")
7746 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7749 struct in_addr addr
;
7750 struct ospf_if_params
*params
;
7751 params
= IF_DEF_PARAMS(ifp
);
7753 argv_find(argv
, argc
, "(3-65535)", &idx
);
7754 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7756 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7757 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7759 "Please specify interface address by A.B.C.D\n");
7760 return CMD_WARNING_CONFIG_FAILED
;
7763 params
= ospf_get_if_params(ifp
, addr
);
7764 ospf_if_update_params(ifp
, addr
);
7767 SET_IF_PARAM(params
, retransmit_interval
);
7768 params
->retransmit_interval
= seconds
;
7773 DEFUN_HIDDEN (ospf_retransmit_interval
,
7774 ospf_retransmit_interval_cmd
,
7775 "ospf retransmit-interval (3-65535) [A.B.C.D]",
7776 "OSPF interface commands\n"
7777 "Time between retransmitting lost link state advertisements\n"
7779 "Address of interface\n")
7781 return ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
7784 DEFUN (no_ip_ospf_retransmit_interval
,
7785 no_ip_ospf_retransmit_interval_addr_cmd
,
7786 "no ip ospf retransmit-interval [(3-65535)] [A.B.C.D]",
7789 "OSPF interface commands\n"
7790 "Time between retransmitting lost link state advertisements\n"
7792 "Address of interface\n")
7794 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7796 struct in_addr addr
;
7797 struct ospf_if_params
*params
;
7799 params
= IF_DEF_PARAMS(ifp
);
7801 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7802 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7804 "Please specify interface address by A.B.C.D\n");
7805 return CMD_WARNING_CONFIG_FAILED
;
7808 params
= ospf_lookup_if_params(ifp
, addr
);
7813 UNSET_IF_PARAM(params
, retransmit_interval
);
7814 params
->retransmit_interval
= OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
7816 if (params
!= IF_DEF_PARAMS(ifp
)) {
7817 ospf_free_if_params(ifp
, addr
);
7818 ospf_if_update_params(ifp
, addr
);
7824 DEFUN_HIDDEN (no_ospf_retransmit_interval
,
7825 no_ospf_retransmit_interval_cmd
,
7826 "no ospf retransmit-interval [(3-65535)] [A.B.C.D]",
7828 "OSPF interface commands\n"
7829 "Time between retransmitting lost link state advertisements\n"
7831 "Address of interface\n")
7833 return no_ip_ospf_retransmit_interval(self
, vty
, argc
, argv
);
7836 DEFUN (ip_ospf_transmit_delay
,
7837 ip_ospf_transmit_delay_addr_cmd
,
7838 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
7840 "OSPF interface commands\n"
7841 "Link state transmit delay\n"
7843 "Address of interface\n")
7845 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7848 struct in_addr addr
;
7849 struct ospf_if_params
*params
;
7851 params
= IF_DEF_PARAMS(ifp
);
7852 argv_find(argv
, argc
, "(1-65535)", &idx
);
7853 seconds
= strtol(argv
[idx
]->arg
, NULL
, 10);
7855 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7856 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7858 "Please specify interface address by A.B.C.D\n");
7859 return CMD_WARNING_CONFIG_FAILED
;
7862 params
= ospf_get_if_params(ifp
, addr
);
7863 ospf_if_update_params(ifp
, addr
);
7866 SET_IF_PARAM(params
, transmit_delay
);
7867 params
->transmit_delay
= seconds
;
7872 DEFUN_HIDDEN (ospf_transmit_delay
,
7873 ospf_transmit_delay_cmd
,
7874 "ospf transmit-delay (1-65535) [A.B.C.D]",
7875 "OSPF interface commands\n"
7876 "Link state transmit delay\n"
7878 "Address of interface\n")
7880 return ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
7883 DEFUN (no_ip_ospf_transmit_delay
,
7884 no_ip_ospf_transmit_delay_addr_cmd
,
7885 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
7888 "OSPF interface commands\n"
7889 "Link state transmit delay\n"
7891 "Address of interface\n")
7893 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7895 struct in_addr addr
;
7896 struct ospf_if_params
*params
;
7898 params
= IF_DEF_PARAMS(ifp
);
7900 if (argv_find(argv
, argc
, "A.B.C.D", &idx
)) {
7901 if (!inet_aton(argv
[idx
]->arg
, &addr
)) {
7903 "Please specify interface address by A.B.C.D\n");
7904 return CMD_WARNING_CONFIG_FAILED
;
7907 params
= ospf_lookup_if_params(ifp
, addr
);
7912 UNSET_IF_PARAM(params
, transmit_delay
);
7913 params
->transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
7915 if (params
!= IF_DEF_PARAMS(ifp
)) {
7916 ospf_free_if_params(ifp
, addr
);
7917 ospf_if_update_params(ifp
, addr
);
7924 DEFUN_HIDDEN (no_ospf_transmit_delay
,
7925 no_ospf_transmit_delay_cmd
,
7926 "no ospf transmit-delay [(1-65535) [A.B.C.D]]",
7928 "OSPF interface commands\n"
7929 "Link state transmit delay\n"
7931 "Address of interface\n")
7933 return no_ip_ospf_transmit_delay(self
, vty
, argc
, argv
);
7936 DEFUN (ip_ospf_area
,
7938 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]",
7940 "OSPF interface commands\n"
7942 "Enable OSPF on this interface\n"
7943 "OSPF area ID in IP address format\n"
7944 "OSPF area ID as a decimal value\n"
7945 "Address of interface\n")
7947 VTY_DECLVAR_CONTEXT(interface
, ifp
);
7950 struct in_addr area_id
;
7951 struct in_addr addr
;
7952 struct ospf_if_params
*params
= NULL
;
7953 struct route_node
*rn
;
7954 struct ospf
*ospf
= NULL
;
7955 u_short instance
= 0;
7958 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
7959 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
7961 argv_find(argv
, argc
, "area", &idx
);
7962 areaid
= argv
[idx
+ 1]->arg
;
7964 if (ifp
->vrf_id
&& !instance
)
7965 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
7967 ospf
= ospf_lookup_instance(instance
);
7969 if (instance
&& ospf
== NULL
) {
7970 params
= IF_DEF_PARAMS(ifp
);
7971 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
7972 UNSET_IF_PARAM(params
, if_area
);
7973 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
7974 ospf_interface_area_unset(ospf
, ifp
);
7975 ospf
->if_ospf_cli_count
--;
7977 return CMD_NOT_MY_INSTANCE
;
7980 ret
= str2area_id(areaid
, &area_id
, &format
);
7982 vty_out(vty
, "Please specify area by A.B.C.D|<0-4294967295>\n");
7983 return CMD_WARNING_CONFIG_FAILED
;
7985 if (memcmp(ifp
->name
, "VLINK", 5) == 0) {
7986 vty_out(vty
, "Cannot enable OSPF on a virtual link.\n");
7987 return CMD_WARNING_CONFIG_FAILED
;
7990 params
= IF_DEF_PARAMS(ifp
);
7991 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)
7992 && !IPV4_ADDR_SAME(¶ms
->if_area
, &area_id
)) {
7994 "Must remove previous area config before changing ospf area \n");
7995 return CMD_WARNING_CONFIG_FAILED
;
7998 // Check if we have an address arg and proccess it
7999 if (argc
== idx
+ 3) {
8000 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
8001 vty_out(vty
, "Please specify Intf Address by A.B.C.D\n");
8002 return CMD_WARNING_CONFIG_FAILED
;
8004 // update/create address-level params
8005 params
= ospf_get_if_params((ifp
), (addr
));
8006 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8008 "Must remove previous area/address config before changing ospf area");
8009 return CMD_WARNING_CONFIG_FAILED
;
8011 ospf_if_update_params((ifp
), (addr
));
8015 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
)) {
8016 if (rn
->info
!= NULL
) {
8018 "Please remove all network commands first.\n");
8019 return CMD_WARNING_CONFIG_FAILED
;
8024 /* enable ospf on this interface with area_id */
8026 SET_IF_PARAM(params
, if_area
);
8027 params
->if_area
= area_id
;
8028 params
->if_area_id_fmt
= format
;
8032 ospf_interface_area_set(ospf
, ifp
);
8033 ospf
->if_ospf_cli_count
++;
8039 DEFUN (no_ip_ospf_area
,
8040 no_ip_ospf_area_cmd
,
8041 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]",
8044 "OSPF interface commands\n"
8046 "Disable OSPF on this interface\n"
8047 "OSPF area ID in IP address format\n"
8048 "OSPF area ID as a decimal value\n"
8049 "Address of interface\n")
8051 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8054 struct ospf_if_params
*params
;
8055 u_short instance
= 0;
8056 struct in_addr addr
;
8058 if (argv_find(argv
, argc
, "(1-65535)", &idx
))
8059 instance
= strtol(argv
[idx
]->arg
, NULL
, 10);
8061 if (ifp
->vrf_id
&& !instance
)
8062 ospf
= ospf_lookup_by_vrf_id(ifp
->vrf_id
);
8064 ospf
= ospf_lookup_instance(instance
);
8067 return CMD_NOT_MY_INSTANCE
;
8069 argv_find(argv
, argc
, "area", &idx
);
8071 // Check if we have an address arg and proccess it
8072 if (argc
== idx
+ 3) {
8073 if (!inet_aton(argv
[idx
+ 2]->arg
, &addr
)) {
8074 vty_out(vty
, "Please specify Intf Address by A.B.C.D\n");
8075 return CMD_WARNING_CONFIG_FAILED
;
8077 params
= ospf_lookup_if_params(ifp
, addr
);
8078 if ((params
) == NULL
)
8081 params
= IF_DEF_PARAMS(ifp
);
8083 if (!OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
8085 "Can't find specified interface area configuration.\n");
8086 return CMD_WARNING_CONFIG_FAILED
;
8089 UNSET_IF_PARAM(params
, if_area
);
8090 if (params
!= IF_DEF_PARAMS((ifp
))) {
8091 ospf_free_if_params((ifp
), (addr
));
8092 ospf_if_update_params((ifp
), (addr
));
8095 ospf_interface_area_unset(ospf
, ifp
);
8096 ospf
->if_ospf_cli_count
--;
8100 DEFUN (ospf_redistribute_source
,
8101 ospf_redistribute_source_cmd
,
8102 "redistribute " FRR_REDIST_STR_OSPFD
" [<metric (0-16777214)|metric-type (1-2)|route-map WORD>]",
8104 FRR_REDIST_HELP_STR_OSPFD
8105 "Metric for redistributed routes\n"
8106 "OSPF default metric\n"
8107 "OSPF exterior metric type for redistributed routes\n"
8108 "Set OSPF External Type 1/2 metrics\n"
8109 "Route map reference\n"
8110 "Pointer to route-map entries\n")
8112 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8113 int idx_protocol
= 1;
8117 struct ospf_redist
*red
;
8123 /* Get distribute source. */
8124 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
8126 return CMD_WARNING_CONFIG_FAILED
;
8128 red
= ospf_redist_add(ospf
, source
, 0);
8130 /* Get metric value. */
8131 if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
8132 if (!str2metric(argv
[idx
]->arg
, &metric
))
8133 return CMD_WARNING_CONFIG_FAILED
;
8135 /* Get metric type. */
8136 else if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
8137 if (!str2metric_type(argv
[idx
]->arg
, &type
))
8138 return CMD_WARNING_CONFIG_FAILED
;
8141 else if (argv_find(argv
, argc
, "WORD", &idx
)) {
8142 ospf_routemap_set(red
, argv
[idx
]->arg
);
8144 ospf_routemap_unset(red
);
8146 return ospf_redistribute_set(ospf
, source
, 0, type
, metric
);
8149 DEFUN (no_ospf_redistribute_source
,
8150 no_ospf_redistribute_source_cmd
,
8151 "no redistribute " FRR_REDIST_STR_OSPFD
" [<metric (0-16777214)|metric-type (1-2)|route-map WORD>]",
8154 FRR_REDIST_HELP_STR_OSPFD
8155 "Metric for redistributed routes\n"
8156 "OSPF default metric\n"
8157 "OSPF exterior metric type for redistributed routes\n"
8158 "Set OSPF External Type 1/2 metrics\n"
8159 "Route map reference\n"
8160 "Pointer to route-map entries\n")
8162 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8163 int idx_protocol
= 2;
8165 struct ospf_redist
*red
;
8167 source
= proto_redistnum(AFI_IP
, argv
[idx_protocol
]->text
);
8169 return CMD_WARNING_CONFIG_FAILED
;
8171 red
= ospf_redist_lookup(ospf
, source
, 0);
8175 ospf_routemap_unset(red
);
8176 return ospf_redistribute_unset(ospf
, source
, 0);
8179 DEFUN (ospf_redistribute_instance_source
,
8180 ospf_redistribute_instance_source_cmd
,
8181 "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8183 "Open Shortest Path First\n"
8184 "Non-main Kernel Routing Table\n"
8185 "Instance ID/Table ID\n"
8186 "Metric for redistributed routes\n"
8187 "OSPF default metric\n"
8188 "OSPF exterior metric type for redistributed routes\n"
8189 "Set OSPF External Type 1/2 metrics\n"
8190 "Route map reference\n"
8191 "Pointer to route-map entries\n")
8193 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8194 int idx_ospf_table
= 1;
8201 struct ospf_redist
*red
;
8206 source
= proto_redistnum(AFI_IP
, argv
[idx_ospf_table
]->text
);
8208 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8213 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
8215 "Instance redistribution in non-instanced OSPF not allowed\n");
8216 return CMD_WARNING_CONFIG_FAILED
;
8219 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
8220 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
8221 return CMD_WARNING_CONFIG_FAILED
;
8224 /* Get metric value. */
8225 if (argv_find(argv
, argc
, "metric", &idx
))
8226 if (!str2metric(argv
[idx
+ 1]->arg
, &metric
))
8227 return CMD_WARNING_CONFIG_FAILED
;
8230 /* Get metric type. */
8231 if (argv_find(argv
, argc
, "metric-type", &idx
))
8232 if (!str2metric_type(argv
[idx
+ 1]->arg
, &type
))
8233 return CMD_WARNING_CONFIG_FAILED
;
8235 red
= ospf_redist_add(ospf
, source
, instance
);
8238 if (argv_find(argv
, argc
, "route-map", &idx
))
8239 ospf_routemap_set(red
, argv
[idx
+ 1]->arg
);
8241 ospf_routemap_unset(red
);
8243 return ospf_redistribute_set(ospf
, source
, instance
, type
, metric
);
8246 DEFUN (no_ospf_redistribute_instance_source
,
8247 no_ospf_redistribute_instance_source_cmd
,
8248 "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8251 "Open Shortest Path First\n"
8252 "Non-main Kernel Routing Table\n"
8253 "Instance ID/Table Id\n"
8254 "Metric for redistributed routes\n"
8255 "OSPF default metric\n"
8256 "OSPF exterior metric type for redistributed routes\n"
8257 "Set OSPF External Type 1/2 metrics\n"
8258 "Route map reference\n"
8259 "Pointer to route-map entries\n")
8261 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8262 int idx_ospf_table
= 2;
8265 struct ospf_redist
*red
;
8268 if (strncmp(argv
[idx_ospf_table
]->arg
, "o", 1) == 0)
8269 source
= ZEBRA_ROUTE_OSPF
;
8271 source
= ZEBRA_ROUTE_TABLE
;
8273 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8275 if ((source
== ZEBRA_ROUTE_OSPF
) && !ospf
->instance
) {
8277 "Instance redistribution in non-instanced OSPF not allowed\n");
8278 return CMD_WARNING_CONFIG_FAILED
;
8281 if ((source
== ZEBRA_ROUTE_OSPF
) && (ospf
->instance
== instance
)) {
8282 vty_out(vty
, "Same instance OSPF redistribution not allowed\n");
8283 return CMD_WARNING_CONFIG_FAILED
;
8286 red
= ospf_redist_lookup(ospf
, source
, instance
);
8290 ospf_routemap_unset(red
);
8291 return ospf_redistribute_unset(ospf
, source
, instance
);
8294 DEFUN (ospf_distribute_list_out
,
8295 ospf_distribute_list_out_cmd
,
8296 "distribute-list WORD out " FRR_REDIST_STR_OSPFD
,
8297 "Filter networks in routing updates\n"
8298 "Access-list name\n"
8300 FRR_REDIST_HELP_STR_OSPFD
)
8302 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8306 char *proto
= argv
[argc
- 1]->text
;
8308 /* Get distribute source. */
8309 source
= proto_redistnum(AFI_IP
, proto
);
8311 return CMD_WARNING_CONFIG_FAILED
;
8313 return ospf_distribute_list_out_set(ospf
, source
, argv
[idx_word
]->arg
);
8316 DEFUN (no_ospf_distribute_list_out
,
8317 no_ospf_distribute_list_out_cmd
,
8318 "no distribute-list WORD out " FRR_REDIST_STR_OSPFD
,
8320 "Filter networks in routing updates\n"
8321 "Access-list name\n"
8323 FRR_REDIST_HELP_STR_OSPFD
)
8325 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8329 char *proto
= argv
[argc
- 1]->text
;
8330 source
= proto_redistnum(AFI_IP
, proto
);
8332 return CMD_WARNING_CONFIG_FAILED
;
8334 return ospf_distribute_list_out_unset(ospf
, source
,
8335 argv
[idx_word
]->arg
);
8338 /* Default information originate. */
8339 DEFUN (ospf_default_information_originate
,
8340 ospf_default_information_originate_cmd
,
8341 "default-information originate [<always|metric (0-16777214)|metric-type (1-2)|route-map WORD>]",
8342 "Control distribution of default information\n"
8343 "Distribute a default route\n"
8344 "Always advertise default route\n"
8345 "OSPF default metric\n"
8347 "OSPF metric type for default routes\n"
8348 "Set OSPF External Type 1/2 metrics\n"
8349 "Route map reference\n"
8350 "Pointer to route-map entries\n")
8352 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8353 int default_originate
= DEFAULT_ORIGINATE_ZEBRA
;
8356 struct ospf_redist
*red
;
8359 red
= ospf_redist_add(ospf
, DEFAULT_ROUTE
, 0);
8361 /* Check whether "always" was specified */
8362 if (argv_find(argv
, argc
, "always", &idx
))
8363 default_originate
= DEFAULT_ORIGINATE_ALWAYS
;
8364 /* Get metric value */
8365 else if (argv_find(argv
, argc
, "(0-16777214)", &idx
)) {
8366 if (!str2metric(argv
[idx
]->arg
, &metric
))
8367 return CMD_WARNING_CONFIG_FAILED
;
8369 /* Get metric type. */
8370 else if (argv_find(argv
, argc
, "(1-2)", &idx
)) {
8371 if (!str2metric_type(argv
[idx
]->arg
, &type
))
8372 return CMD_WARNING_CONFIG_FAILED
;
8375 else if (argv_find(argv
, argc
, "WORD", &idx
))
8376 ospf_routemap_set(red
, argv
[idx
]->arg
);
8378 ospf_routemap_unset(red
);
8380 return ospf_redistribute_default_set(ospf
, default_originate
, type
,
8384 DEFUN (no_ospf_default_information_originate
,
8385 no_ospf_default_information_originate_cmd
,
8386 "no default-information originate [<always|metric (0-16777214)|metric-type (1-2)|route-map WORD>]",
8388 "Control distribution of default information\n"
8389 "Distribute a default route\n"
8390 "Always advertise default route\n"
8391 "OSPF default metric\n"
8393 "OSPF metric type for default routes\n"
8394 "Set OSPF External Type 1/2 metrics\n"
8395 "Route map reference\n"
8396 "Pointer to route-map entries\n")
8398 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8399 struct prefix_ipv4 p
;
8400 struct ospf_external
*ext
;
8401 struct ospf_redist
*red
;
8404 p
.prefix
.s_addr
= 0;
8407 ospf_external_lsa_flush(ospf
, DEFAULT_ROUTE
, &p
, 0);
8409 ext
= ospf_external_lookup(ospf
, DEFAULT_ROUTE
, 0);
8410 if (ext
&& EXTERNAL_INFO(ext
)) {
8411 ospf_external_info_delete(ospf
, DEFAULT_ROUTE
, 0, p
);
8412 ospf_external_del(ospf
, DEFAULT_ROUTE
, 0);
8415 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
8419 ospf_routemap_unset(red
);
8420 return ospf_redistribute_default_unset(ospf
);
8423 DEFUN (ospf_default_metric
,
8424 ospf_default_metric_cmd
,
8425 "default-metric (0-16777214)",
8426 "Set metric of redistributed routes\n"
8429 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8433 if (!str2metric(argv
[idx_number
]->arg
, &metric
))
8434 return CMD_WARNING_CONFIG_FAILED
;
8436 ospf
->default_metric
= metric
;
8441 DEFUN (no_ospf_default_metric
,
8442 no_ospf_default_metric_cmd
,
8443 "no default-metric [(0-16777214)]",
8445 "Set metric of redistributed routes\n"
8448 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8450 ospf
->default_metric
= -1;
8456 DEFUN (ospf_distance
,
8459 "Administrative distance\n"
8460 "OSPF Administrative distance\n")
8462 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8465 ospf
->distance_all
= atoi(argv
[idx_number
]->arg
);
8470 DEFUN (no_ospf_distance
,
8471 no_ospf_distance_cmd
,
8472 "no distance (1-255)",
8474 "Administrative distance\n"
8475 "OSPF Administrative distance\n")
8477 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8479 ospf
->distance_all
= 0;
8484 DEFUN (no_ospf_distance_ospf
,
8485 no_ospf_distance_ospf_cmd
,
8486 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
8488 "Administrative distance\n"
8489 "OSPF administrative distance\n"
8490 "Intra-area routes\n"
8491 "Distance for intra-area routes\n"
8492 "Inter-area routes\n"
8493 "Distance for inter-area routes\n"
8495 "Distance for external routes\n")
8497 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8503 if (argv_find(argv
, argc
, "intra-area", &idx
) || argc
== 3)
8504 idx
= ospf
->distance_intra
= 0;
8505 if (argv_find(argv
, argc
, "inter-area", &idx
) || argc
== 3)
8506 idx
= ospf
->distance_inter
= 0;
8507 if (argv_find(argv
, argc
, "external", &idx
) || argc
== 3)
8508 ospf
->distance_external
= 0;
8513 DEFUN (ospf_distance_ospf
,
8514 ospf_distance_ospf_cmd
,
8515 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
8516 "Administrative distance\n"
8517 "OSPF administrative distance\n"
8518 "Intra-area routes\n"
8519 "Distance for intra-area routes\n"
8520 "Inter-area routes\n"
8521 "Distance for inter-area routes\n"
8523 "Distance for external routes\n")
8525 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8528 if (argv_find(argv
, argc
, "intra-area", &idx
))
8529 ospf
->distance_intra
= atoi(argv
[idx
+ 1]->arg
);
8531 if (argv_find(argv
, argc
, "inter-area", &idx
))
8532 ospf
->distance_inter
= atoi(argv
[idx
+ 1]->arg
);
8534 if (argv_find(argv
, argc
, "external", &idx
))
8535 ospf
->distance_external
= atoi(argv
[idx
+ 1]->arg
);
8541 DEFUN (ospf_distance_source
,
8542 ospf_distance_source_cmd
,
8543 "distance (1-255) A.B.C.D/M",
8544 "Administrative distance\n"
8546 "IP source prefix\n")
8548 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8550 int idx_ipv4_prefixlen
= 2;
8555 ospf_distance_set (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
8560 DEFUN (no_ospf_distance_source
,
8561 no_ospf_distance_source_cmd
,
8562 "no distance (1-255) A.B.C.D/M",
8564 "Administrative distance\n"
8566 "IP source prefix\n")
8568 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8570 int idx_ipv4_prefixlen
= 3;
8575 ospf_distance_unset (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
);
8580 DEFUN (ospf_distance_source_access_list
,
8581 ospf_distance_source_access_list_cmd
,
8582 "distance (1-255) A.B.C.D/M WORD",
8583 "Administrative distance\n"
8585 "IP source prefix\n"
8586 "Access list name\n")
8588 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8590 int idx_ipv4_prefixlen
= 2;
8596 ospf_distance_set (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
8601 DEFUN (no_ospf_distance_source_access_list
,
8602 no_ospf_distance_source_access_list_cmd
,
8603 "no distance (1-255) A.B.C.D/M WORD",
8605 "Administrative distance\n"
8607 "IP source prefix\n"
8608 "Access list name\n")
8610 VTY_DECLVAR_CONTEXT(ospf
, ospf
);
8612 int idx_ipv4_prefixlen
= 3;
8618 ospf_distance_unset (vty
, ospf
, argv
[idx_number
]->arg
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_word
]->arg
);
8624 DEFUN (ip_ospf_mtu_ignore
,
8625 ip_ospf_mtu_ignore_addr_cmd
,
8626 "ip ospf mtu-ignore [A.B.C.D]",
8628 "OSPF interface commands\n"
8629 "Disable MTU mismatch detection on this interface\n"
8630 "Address of interface\n")
8632 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8634 struct in_addr addr
;
8637 struct ospf_if_params
*params
;
8638 params
= IF_DEF_PARAMS(ifp
);
8641 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8644 "Please specify interface address by A.B.C.D\n");
8645 return CMD_WARNING_CONFIG_FAILED
;
8647 params
= ospf_get_if_params(ifp
, addr
);
8648 ospf_if_update_params(ifp
, addr
);
8650 params
->mtu_ignore
= 1;
8651 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
8652 SET_IF_PARAM(params
, mtu_ignore
);
8654 UNSET_IF_PARAM(params
, mtu_ignore
);
8655 if (params
!= IF_DEF_PARAMS(ifp
)) {
8656 ospf_free_if_params(ifp
, addr
);
8657 ospf_if_update_params(ifp
, addr
);
8663 DEFUN (no_ip_ospf_mtu_ignore
,
8664 no_ip_ospf_mtu_ignore_addr_cmd
,
8665 "no ip ospf mtu-ignore [A.B.C.D]",
8668 "OSPF interface commands\n"
8669 "Disable MTU mismatch detection on this interface\n"
8670 "Address of interface\n")
8672 VTY_DECLVAR_CONTEXT(interface
, ifp
);
8674 struct in_addr addr
;
8677 struct ospf_if_params
*params
;
8678 params
= IF_DEF_PARAMS(ifp
);
8681 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &addr
);
8684 "Please specify interface address by A.B.C.D\n");
8685 return CMD_WARNING_CONFIG_FAILED
;
8687 params
= ospf_get_if_params(ifp
, addr
);
8688 ospf_if_update_params(ifp
, addr
);
8690 params
->mtu_ignore
= 0;
8691 if (params
->mtu_ignore
!= OSPF_MTU_IGNORE_DEFAULT
)
8692 SET_IF_PARAM(params
, mtu_ignore
);
8694 UNSET_IF_PARAM(params
, mtu_ignore
);
8695 if (params
!= IF_DEF_PARAMS(ifp
)) {
8696 ospf_free_if_params(ifp
, addr
);
8697 ospf_if_update_params(ifp
, addr
);
8704 DEFUN (ospf_max_metric_router_lsa_admin
,
8705 ospf_max_metric_router_lsa_admin_cmd
,
8706 "max-metric router-lsa administrative",
8707 "OSPF maximum / infinite-distance metric\n"
8708 "Advertise own Router-LSA with infinite distance (stub router)\n"
8709 "Administratively applied, for an indefinite period\n")
8711 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8712 struct listnode
*ln
;
8713 struct ospf_area
*area
;
8715 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8716 SET_FLAG(area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
);
8718 if (!CHECK_FLAG(area
->stub_router_state
,
8719 OSPF_AREA_IS_STUB_ROUTED
))
8720 ospf_router_lsa_update_area(area
);
8723 /* Allows for areas configured later to get the property */
8724 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_SET
;
8729 DEFUN (no_ospf_max_metric_router_lsa_admin
,
8730 no_ospf_max_metric_router_lsa_admin_cmd
,
8731 "no max-metric router-lsa administrative",
8733 "OSPF maximum / infinite-distance metric\n"
8734 "Advertise own Router-LSA with infinite distance (stub router)\n"
8735 "Administratively applied, for an indefinite period\n")
8737 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8738 struct listnode
*ln
;
8739 struct ospf_area
*area
;
8741 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8742 UNSET_FLAG(area
->stub_router_state
,
8743 OSPF_AREA_ADMIN_STUB_ROUTED
);
8745 /* Don't trample on the start-up stub timer */
8746 if (CHECK_FLAG(area
->stub_router_state
,
8747 OSPF_AREA_IS_STUB_ROUTED
)
8748 && !area
->t_stub_router
) {
8749 UNSET_FLAG(area
->stub_router_state
,
8750 OSPF_AREA_IS_STUB_ROUTED
);
8751 ospf_router_lsa_update_area(area
);
8754 ospf
->stub_router_admin_set
= OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET
;
8758 DEFUN (ospf_max_metric_router_lsa_startup
,
8759 ospf_max_metric_router_lsa_startup_cmd
,
8760 "max-metric router-lsa on-startup (5-86400)",
8761 "OSPF maximum / infinite-distance metric\n"
8762 "Advertise own Router-LSA with infinite distance (stub router)\n"
8763 "Automatically advertise stub Router-LSA on startup of OSPF\n"
8764 "Time (seconds) to advertise self as stub-router\n")
8766 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8768 unsigned int seconds
;
8771 vty_out(vty
, "%% Must supply stub-router period");
8772 return CMD_WARNING_CONFIG_FAILED
;
8775 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8777 ospf
->stub_router_startup_time
= seconds
;
8782 DEFUN (no_ospf_max_metric_router_lsa_startup
,
8783 no_ospf_max_metric_router_lsa_startup_cmd
,
8784 "no max-metric router-lsa on-startup [(5-86400)]",
8786 "OSPF maximum / infinite-distance metric\n"
8787 "Advertise own Router-LSA with infinite distance (stub router)\n"
8788 "Automatically advertise stub Router-LSA on startup of OSPF\n"
8789 "Time (seconds) to advertise self as stub-router\n")
8791 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8792 struct listnode
*ln
;
8793 struct ospf_area
*area
;
8795 ospf
->stub_router_startup_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
8797 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8798 SET_FLAG(area
->stub_router_state
,
8799 OSPF_AREA_WAS_START_STUB_ROUTED
);
8800 OSPF_TIMER_OFF(area
->t_stub_router
);
8802 /* Don't trample on admin stub routed */
8803 if (!CHECK_FLAG(area
->stub_router_state
,
8804 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
8805 UNSET_FLAG(area
->stub_router_state
,
8806 OSPF_AREA_IS_STUB_ROUTED
);
8807 ospf_router_lsa_update_area(area
);
8814 DEFUN (ospf_max_metric_router_lsa_shutdown
,
8815 ospf_max_metric_router_lsa_shutdown_cmd
,
8816 "max-metric router-lsa on-shutdown (5-100)",
8817 "OSPF maximum / infinite-distance metric\n"
8818 "Advertise own Router-LSA with infinite distance (stub router)\n"
8819 "Advertise stub-router prior to full shutdown of OSPF\n"
8820 "Time (seconds) to wait till full shutdown\n")
8822 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8824 unsigned int seconds
;
8827 vty_out(vty
, "%% Must supply stub-router shutdown period");
8828 return CMD_WARNING_CONFIG_FAILED
;
8831 seconds
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
8833 ospf
->stub_router_shutdown_time
= seconds
;
8838 DEFUN (no_ospf_max_metric_router_lsa_shutdown
,
8839 no_ospf_max_metric_router_lsa_shutdown_cmd
,
8840 "no max-metric router-lsa on-shutdown [(5-100)]",
8842 "OSPF maximum / infinite-distance metric\n"
8843 "Advertise own Router-LSA with infinite distance (stub router)\n"
8844 "Advertise stub-router prior to full shutdown of OSPF\n"
8845 "Time (seconds) to wait till full shutdown\n")
8847 VTY_DECLVAR_INSTANCE_CONTEXT(ospf
, ospf
);
8849 ospf
->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
8854 static void config_write_stub_router(struct vty
*vty
, struct ospf
*ospf
)
8856 struct listnode
*ln
;
8857 struct ospf_area
*area
;
8859 if (ospf
->stub_router_startup_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
8860 vty_out(vty
, " max-metric router-lsa on-startup %u\n",
8861 ospf
->stub_router_startup_time
);
8862 if (ospf
->stub_router_shutdown_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
8863 vty_out(vty
, " max-metric router-lsa on-shutdown %u\n",
8864 ospf
->stub_router_shutdown_time
);
8865 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, ln
, area
)) {
8866 if (CHECK_FLAG(area
->stub_router_state
,
8867 OSPF_AREA_ADMIN_STUB_ROUTED
)) {
8868 vty_out(vty
, " max-metric router-lsa administrative\n");
8875 static void show_ip_ospf_route_network(struct vty
*vty
, struct ospf
*ospf
,
8876 struct route_table
*rt
,
8879 struct route_node
*rn
;
8880 struct ospf_route
* or ;
8881 struct listnode
*pnode
, *pnnode
;
8882 struct ospf_path
*path
;
8883 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
8884 *json_nexthop
= NULL
;
8887 vty_out(vty
, "============ OSPF network routing table ============\n");
8889 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
8890 if ((or = rn
->info
) == NULL
)
8892 char buf1
[PREFIX2STR_BUFFER
];
8894 memset(buf1
, 0, sizeof(buf1
));
8895 prefix2str(&rn
->p
, buf1
, sizeof(buf1
));
8897 json_route
= json_object_new_object();
8899 json_object_object_add(json
, buf1
, json_route
);
8900 json_object_to_json_string_ext(json
,
8901 JSON_C_TO_STRING_NOSLASHESCAPE
);
8905 switch (or->path_type
) {
8906 case OSPF_PATH_INTER_AREA
:
8907 if (or->type
== OSPF_DESTINATION_NETWORK
) {
8909 json_object_string_add(json_route
,
8912 json_object_int_add(json_route
,
8915 json_object_string_add(
8919 or->u
.std
.area_id
));
8922 "N IA %-18s [%d] area: %s\n",
8924 inet_ntoa(or->u
.std
.area_id
));
8926 } else if (or->type
==
8927 OSPF_DESTINATION_DISCARD
) {
8929 json_object_string_add(json_route
,
8934 "D IA %-18s Discard entry\n",
8939 case OSPF_PATH_INTRA_AREA
:
8941 json_object_string_add(json_route
,
8943 json_object_int_add(json_route
, "cost",
8945 json_object_string_add(json_route
,
8946 "area", inet_ntoa(or->u
.std
.area_id
));
8948 vty_out(vty
, "N %-18s [%d] area: %s\n",
8950 inet_ntoa(or->u
.std
.area_id
));
8957 if (or->type
== OSPF_DESTINATION_NETWORK
) {
8959 json_nexthop_array
= json_object_new_array();
8960 json_object_object_add(json_route
, "nexthops",
8961 json_nexthop_array
);
8964 for (ALL_LIST_ELEMENTS(or->paths
, pnode
, pnnode
,
8968 json_object_new_object();
8969 json_object_array_add(json_nexthop_array
,
8972 if (if_lookup_by_index(path
->ifindex
,
8975 if (path
->nexthop
.s_addr
== 0) {
8977 json_object_string_add(
8981 json_object_string_add(
8983 "directly attached to",
8989 "%24s directly attached to %s\n",
8997 json_object_string_add(
9002 json_object_string_add(
9010 "%24s via %s, %s\n",
9023 json_object_free(json_route
);
9029 static void show_ip_ospf_route_router(struct vty
*vty
, struct ospf
*ospf
,
9030 struct route_table
*rtrs
,
9033 struct route_node
*rn
;
9034 struct ospf_route
* or ;
9035 struct listnode
*pnode
;
9036 struct listnode
*node
;
9037 struct ospf_path
*path
;
9038 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
9039 *json_nexthop
= NULL
;
9042 vty_out(vty
, "============ OSPF router routing table =============\n");
9044 for (rn
= route_top(rtrs
); rn
; rn
= route_next(rn
)) {
9045 if (rn
->info
== NULL
)
9049 json_route
= json_object_new_object();
9051 json_object_object_add(json
,
9052 inet_ntoa(rn
->p
.u
.prefix4
),
9054 json_object_string_add(json_route
, "routeType",
9057 vty_out(vty
, "R %-15s ",
9058 inet_ntoa(rn
->p
.u
.prefix4
));
9061 for (ALL_LIST_ELEMENTS_RO((struct list
*)rn
->info
, node
,
9065 vty_out(vty
, "%24s", "");
9070 json_object_int_add(json_route
, "cost",
9072 json_object_string_add(json_route
,
9074 inet_ntoa(or->u
.std
.area_id
));
9075 if (or->path_type
==
9076 OSPF_PATH_INTER_AREA
)
9077 json_object_boolean_true_add(
9080 if (or->u
.std
.flags
& ROUTER_LSA_BORDER
)
9081 json_object_string_add(
9085 else if (or->u
.std
.flags
&
9086 ROUTER_LSA_EXTERNAL
)
9087 json_object_string_add(
9092 vty_out(vty
, "%s [%d] area: %s",
9093 (or->path_type
== OSPF_PATH_INTER_AREA
9096 or->cost
, inet_ntoa(or->u
.std
.area_id
));
9098 vty_out(vty
, "%s%s\n",
9099 (or->u
.std
.flags
& ROUTER_LSA_BORDER
9102 (or->u
.std
.flags
& ROUTER_LSA_EXTERNAL
9108 json_nexthop_array
=
9109 json_object_new_array();
9110 json_object_object_add(json_route
, "nexthops",
9111 json_nexthop_array
);
9114 for (ALL_LIST_ELEMENTS_RO(or->paths
, pnode
,
9118 json_object_new_object();
9119 json_object_array_add(
9123 if (if_lookup_by_index(path
->ifindex
,
9125 if (path
->nexthop
.s_addr
== 0) {
9127 json_object_string_add(
9131 json_object_string_add(
9133 "directly attached to",
9139 "%24s directly attached to %s\n",
9147 json_object_string_add(
9150 inet_ntoa(path
->nexthop
));
9151 json_object_string_add(
9159 "%24s via %s, %s\n",
9172 json_object_free(json_route
);
9178 static void show_ip_ospf_route_external(struct vty
*vty
, struct ospf
*ospf
,
9179 struct route_table
*rt
,
9182 struct route_node
*rn
;
9183 struct ospf_route
*er
;
9184 struct listnode
*pnode
, *pnnode
;
9185 struct ospf_path
*path
;
9186 json_object
*json_route
= NULL
, *json_nexthop_array
= NULL
,
9187 *json_nexthop
= NULL
;
9190 vty_out(vty
, "============ OSPF external routing table ===========\n");
9192 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
9193 if ((er
= rn
->info
) == NULL
)
9198 snprintf(buf1
, 19, "%s/%d", inet_ntoa(rn
->p
.u
.prefix4
),
9200 json_route
= json_object_new_object();
9202 json_object_object_add(json
, buf1
, json_route
);
9203 json_object_to_json_string_ext(json
,
9204 JSON_C_TO_STRING_NOSLASHESCAPE
);
9208 switch (er
->path_type
) {
9209 case OSPF_PATH_TYPE1_EXTERNAL
:
9211 json_object_string_add(json_route
,
9214 json_object_int_add(json_route
, "cost",
9218 "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI
9220 buf1
, er
->cost
, er
->u
.ext
.tag
);
9223 case OSPF_PATH_TYPE2_EXTERNAL
:
9225 json_object_string_add(json_route
,
9228 json_object_int_add(json_route
, "cost",
9232 "N E2 %-18s [%d/%d] tag: %"
9234 "\n", buf1
, er
->cost
,
9235 er
->u
.ext
.type2_cost
,
9242 json_nexthop_array
= json_object_new_array();
9243 json_object_object_add(json_route
, "nexthops",
9244 json_nexthop_array
);
9247 for (ALL_LIST_ELEMENTS(er
->paths
, pnode
, pnnode
,
9250 json_nexthop
= json_object_new_object();
9251 json_object_array_add(json_nexthop_array
9255 if (if_lookup_by_index(path
->ifindex
,
9257 if (path
->nexthop
.s_addr
== 0) {
9259 json_object_string_add(
9263 json_object_string_add(
9265 "directly attached to",
9271 "%24s directly attached to %s\n",
9279 json_object_string_add(
9284 json_object_string_add(
9292 "%24s via %s, %s\n",
9304 json_object_free(json_route
);
9310 static int show_ip_ospf_border_routers_common(struct vty
*vty
,
9315 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
9317 ospf_show_vrf_name(ospf
, vty
, NULL
, use_vrf
);
9319 if (ospf
->new_table
== NULL
) {
9320 vty_out(vty
, "No OSPF routing information exist\n");
9324 /* Show Network routes.
9325 show_ip_ospf_route_network (vty, ospf->new_table); */
9327 /* Show Router routes. */
9328 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, NULL
);
9335 DEFUN (show_ip_ospf_border_routers
,
9336 show_ip_ospf_border_routers_cmd
,
9337 "show ip ospf [vrf <NAME|all>] border-routers",
9340 "OSPF information\n"
9343 "Show all the ABR's and ASBR's\n")
9345 struct ospf
*ospf
= NULL
;
9346 struct listnode
*node
= NULL
;
9347 char *vrf_name
= NULL
;
9348 bool all_vrf
= FALSE
;
9349 int ret
= CMD_SUCCESS
;
9354 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
9359 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9360 if (!ospf
->oi_running
)
9363 ret
= show_ip_ospf_border_routers_common(vty
,
9368 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
9369 if (ospf
== NULL
|| !ospf
->oi_running
)
9372 ret
= show_ip_ospf_border_routers_common(vty
, ospf
,
9376 /* Display default ospf (instance 0) info */
9377 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
9378 if (ospf
== NULL
|| !ospf
->oi_running
)
9380 ret
= show_ip_ospf_border_routers_common(vty
, ospf
, use_vrf
);
9386 DEFUN (show_ip_ospf_instance_border_routers
,
9387 show_ip_ospf_instance_border_routers_cmd
,
9388 "show ip ospf (1-65535) border-routers",
9391 "OSPF information\n"
9393 "Show all the ABR's and ASBR's\n")
9397 u_short instance
= 0;
9399 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9400 ospf
= ospf_lookup_instance(instance
);
9402 return CMD_NOT_MY_INSTANCE
;
9404 if (!ospf
->oi_running
)
9407 return show_ip_ospf_border_routers_common(vty
, ospf
, 0);
9410 static int show_ip_ospf_route_common(struct vty
*vty
, struct ospf
*ospf
,
9411 json_object
*json
, u_char use_vrf
)
9413 json_object
*json_vrf
= NULL
;
9416 vty_out(vty
, "\nOSPF Instance: %d\n\n", ospf
->instance
);
9421 json_vrf
= json_object_new_object();
9426 ospf_show_vrf_name(ospf
, vty
, json_vrf
, use_vrf
);
9428 if (ospf
->new_table
== NULL
) {
9429 vty_out(vty
, "No OSPF routing information exist\n");
9433 /* Show Network routes. */
9434 show_ip_ospf_route_network(vty
, ospf
, ospf
->new_table
, json_vrf
);
9436 /* Show Router routes. */
9437 show_ip_ospf_route_router(vty
, ospf
, ospf
->new_rtrs
, json_vrf
);
9439 /* Show AS External routes. */
9440 show_ip_ospf_route_external(vty
, ospf
, ospf
->old_external_route
,
9445 //json_object_object_add(json_vrf, "areas", json_areas);
9446 if (ospf
->vrf_id
== VRF_DEFAULT
)
9447 json_object_object_add(json
, "default",
9450 json_object_object_add(json
, ospf
->name
,
9460 DEFUN (show_ip_ospf_route
,
9461 show_ip_ospf_route_cmd
,
9462 "show ip ospf [vrf <NAME|all>] route [json]",
9465 "OSPF information\n"
9468 "OSPF routing table\n"
9471 struct ospf
*ospf
= NULL
;
9472 struct listnode
*node
= NULL
;
9473 char *vrf_name
= NULL
;
9474 bool all_vrf
= FALSE
;
9475 int ret
= CMD_SUCCESS
;
9479 u_char uj
= use_json(argc
, argv
);
9480 json_object
*json
= NULL
;
9483 json
= json_object_new_object();
9485 OSPF_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
9487 /* vrf input is provided could be all or specific vrf*/
9491 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9492 if (!ospf
->oi_running
)
9494 ret
= show_ip_ospf_route_common(vty
, ospf
, json
,
9499 vty_out(vty
, "%s\n",
9500 json_object_to_json_string_ext(json
,
9501 JSON_C_TO_STRING_PRETTY
));
9502 json_object_free(json
);
9507 ospf
= ospf_lookup_by_inst_name(inst
, vrf_name
);
9508 if (ospf
== NULL
|| !ospf
->oi_running
) {
9510 json_object_free(json
);
9514 /* Display default ospf (instance 0) info */
9515 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
9516 if (ospf
== NULL
|| !ospf
->oi_running
) {
9518 json_object_free(json
);
9524 ret
= show_ip_ospf_route_common(vty
, ospf
, json
, use_vrf
);
9526 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
9527 json
, JSON_C_TO_STRING_PRETTY
));
9531 json_object_free(json
);
9536 DEFUN (show_ip_ospf_instance_route
,
9537 show_ip_ospf_instance_route_cmd
,
9538 "show ip ospf (1-65535) route",
9541 "OSPF information\n"
9543 "OSPF routing table\n")
9547 u_short instance
= 0;
9549 instance
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
9550 ospf
= ospf_lookup_instance(instance
);
9552 return CMD_NOT_MY_INSTANCE
;
9554 if (!ospf
->oi_running
)
9557 return show_ip_ospf_route_common(vty
, ospf
, NULL
, 0);
9561 DEFUN (show_ip_ospf_vrfs
,
9562 show_ip_ospf_vrfs_cmd
,
9563 "show ip ospf vrfs [json]",
9566 "OSPF information\n"
9570 u_char uj
= use_json(argc
, argv
);
9571 json_object
*json
= NULL
;
9572 json_object
*json_vrfs
= NULL
;
9573 struct ospf
*ospf
= NULL
;
9574 struct listnode
*node
= NULL
;
9576 static char header
[] = "Name Id RouterId ";
9579 json
= json_object_new_object();
9580 json_vrfs
= json_object_new_object();
9583 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
9584 json_object
*json_vrf
= NULL
;
9585 const char *name
= NULL
;
9590 if (!uj
&& count
== 1)
9591 vty_out(vty
, "%s\n", header
);
9593 json_vrf
= json_object_new_object();
9595 if (ospf
->vrf_id
== 0)
9596 name
= VRF_DEFAULT_NAME
;
9600 vrf_id_ui
= (ospf
->vrf_id
== VRF_UNKNOWN
) ? -1 : ospf
->vrf_id
;
9603 json_object_int_add(json_vrf
, "vrfId", vrf_id_ui
);
9604 json_object_string_add(json_vrf
, "routerId",
9605 inet_ntoa(ospf
->router_id
));
9607 json_object_object_add(json_vrfs
, name
, json_vrf
);
9610 vty_out(vty
, "%-25s %-5d %-16s \n",
9611 name
, ospf
->vrf_id
, inet_ntoa(ospf
->router_id
));
9616 json_object_object_add(json
, "vrfs", json_vrfs
);
9617 json_object_int_add(json
, "totalVrfs", count
);
9619 vty_out(vty
, "%s\n", json_object_to_json_string_ext(json
,
9620 JSON_C_TO_STRING_PRETTY
));
9621 json_object_free(json
);
9624 vty_out(vty
, "\nTotal number of OSPF VRFs: %d\n",
9631 const char *ospf_abr_type_str
[] = {"unknown", "standard", "ibm", "cisco",
9634 const char *ospf_shortcut_mode_str
[] = {"default", "enable", "disable"};
9636 const char *ospf_int_type_str
[] = {"unknown", /* should never be used. */
9637 "point-to-point", "broadcast",
9638 "non-broadcast", "point-to-multipoint",
9639 "virtual-link", /* should never be used. */
9642 static int config_write_interface_one(struct vty
*vty
, struct vrf
*vrf
)
9644 struct listnode
*node
;
9645 struct interface
*ifp
;
9646 struct crypt_key
*ck
;
9647 struct route_node
*rn
= NULL
;
9648 struct ospf_if_params
*params
;
9650 struct ospf
*ospf
= vrf
->info
;
9652 FOR_ALL_INTERFACES (vrf
, ifp
) {
9654 if (memcmp(ifp
->name
, "VLINK", 5) == 0)
9657 vty_frame(vty
, "!\n");
9658 if (ifp
->vrf_id
== VRF_DEFAULT
)
9659 vty_frame(vty
, "interface %s\n", ifp
->name
);
9661 vty_frame(vty
, "interface %s vrf %s\n",
9662 ifp
->name
, vrf
->name
);
9664 vty_out(vty
, " description %s\n", ifp
->desc
);
9668 params
= IF_DEF_PARAMS(ifp
);
9671 /* Interface Network print. */
9672 if (OSPF_IF_PARAM_CONFIGURED(params
, type
)
9673 && params
->type
!= OSPF_IFTYPE_LOOPBACK
) {
9675 ospf_default_iftype(ifp
)) {
9676 vty_out(vty
, " ip ospf network %s",
9679 if (params
!= IF_DEF_PARAMS(ifp
))
9687 /* OSPF interface authentication print */
9688 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_type
)
9689 && params
->auth_type
!= OSPF_AUTH_NOTSET
) {
9690 const char *auth_str
;
9692 /* Translation tables are not that much help
9693 * here due to syntax
9694 * of the simple option */
9695 switch (params
->auth_type
) {
9697 case OSPF_AUTH_NULL
:
9701 case OSPF_AUTH_SIMPLE
:
9705 case OSPF_AUTH_CRYPTOGRAPHIC
:
9706 auth_str
= " message-digest";
9714 vty_out(vty
, " ip ospf authentication%s",
9716 if (params
!= IF_DEF_PARAMS(ifp
))
9718 inet_ntoa(rn
->p
.u
.prefix4
));
9722 /* Simple Authentication Password print. */
9723 if (OSPF_IF_PARAM_CONFIGURED(params
, auth_simple
)
9724 && params
->auth_simple
[0] != '\0') {
9725 vty_out(vty
, " ip ospf authentication-key %s",
9726 params
->auth_simple
);
9727 if (params
!= IF_DEF_PARAMS(ifp
))
9729 inet_ntoa(rn
->p
.u
.prefix4
));
9733 /* Cryptographic Authentication Key print. */
9734 if (params
&& params
->auth_crypt
) {
9735 for (ALL_LIST_ELEMENTS_RO(
9739 " ip ospf message-digest-key %d md5 %s",
9742 if (params
!= IF_DEF_PARAMS(ifp
))
9744 inet_ntoa(rn
->p
.u
.prefix4
));
9749 /* Interface Output Cost print. */
9750 if (OSPF_IF_PARAM_CONFIGURED(params
,
9752 vty_out(vty
, " ip ospf cost %u",
9753 params
->output_cost_cmd
);
9754 if (params
!= IF_DEF_PARAMS(ifp
))
9756 inet_ntoa(rn
->p
.u
.prefix4
));
9760 /* Hello Interval print. */
9761 if (OSPF_IF_PARAM_CONFIGURED(params
, v_hello
)
9762 && params
->v_hello
!=
9763 OSPF_HELLO_INTERVAL_DEFAULT
) {
9764 vty_out(vty
, " ip ospf hello-interval %u",
9766 if (params
!= IF_DEF_PARAMS(ifp
))
9768 inet_ntoa(rn
->p
.u
.prefix4
));
9773 /* Router Dead Interval print. */
9774 if (OSPF_IF_PARAM_CONFIGURED(params
, v_wait
)
9776 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
) {
9777 vty_out(vty
, " ip ospf dead-interval ");
9780 if (OSPF_IF_PARAM_CONFIGURED(params
,
9783 "minimal hello-multiplier %d",
9784 params
->fast_hello
);
9789 if (params
!= IF_DEF_PARAMS(ifp
))
9791 inet_ntoa(rn
->p
.u
.prefix4
));
9795 /* Router Priority print. */
9796 if (OSPF_IF_PARAM_CONFIGURED(params
, priority
)
9798 != OSPF_ROUTER_PRIORITY_DEFAULT
) {
9799 vty_out(vty
, " ip ospf priority %u",
9801 if (params
!= IF_DEF_PARAMS(ifp
))
9803 inet_ntoa(rn
->p
.u
.prefix4
));
9807 /* Retransmit Interval print. */
9808 if (OSPF_IF_PARAM_CONFIGURED(params
,
9809 retransmit_interval
)
9810 && params
->retransmit_interval
9811 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
) {
9812 vty_out(vty
, " ip ospf retransmit-interval %u",
9813 params
->retransmit_interval
);
9814 if (params
!= IF_DEF_PARAMS(ifp
))
9816 inet_ntoa(rn
->p
.u
.prefix4
));
9820 /* Transmit Delay print. */
9821 if (OSPF_IF_PARAM_CONFIGURED(params
,
9823 && params
->transmit_delay
9824 != OSPF_TRANSMIT_DELAY_DEFAULT
) {
9825 vty_out(vty
, " ip ospf transmit-delay %u",
9826 params
->transmit_delay
);
9827 if (params
!= IF_DEF_PARAMS(ifp
))
9829 inet_ntoa(rn
->p
.u
.prefix4
));
9834 if (OSPF_IF_PARAM_CONFIGURED(params
, if_area
)) {
9835 if (ospf
&& ospf
->instance
)
9836 vty_out(vty
, " ip ospf %d",
9839 vty_out(vty
, " ip ospf");
9842 size_t buflen
= MAX(strlen("4294967295"),
9843 strlen("255.255.255.255"));
9846 area_id2str(buf
, sizeof(buf
),
9848 params
->if_area_id_fmt
);
9849 vty_out(vty
, " area %s", buf
);
9850 if (params
!= IF_DEF_PARAMS(ifp
))
9852 inet_ntoa(rn
->p
.u
.prefix4
));
9857 if (params
->bfd_info
)
9858 ospf_bfd_write_config(vty
, params
);
9860 /* MTU ignore print. */
9861 if (OSPF_IF_PARAM_CONFIGURED(params
, mtu_ignore
)
9862 && params
->mtu_ignore
!=
9863 OSPF_MTU_IGNORE_DEFAULT
) {
9864 if (params
->mtu_ignore
== 0)
9865 vty_out(vty
, " no ip ospf mtu-ignore");
9867 vty_out(vty
, " ip ospf mtu-ignore");
9868 if (params
!= IF_DEF_PARAMS(ifp
))
9870 inet_ntoa(rn
->p
.u
.prefix4
));
9878 IF_OIFS_PARAMS(ifp
));
9880 rn
= route_next(rn
);
9890 ospf_opaque_config_write_if(vty
, ifp
);
9892 vty_endframe(vty
, NULL
);
9898 /* Configuration write function for ospfd. */
9899 static int config_write_interface(struct vty
*vty
)
9902 struct vrf
*vrf
= NULL
;
9904 /* Display all VRF aware OSPF interface configuration */
9905 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
9906 write
+= config_write_interface_one(vty
, vrf
);
9912 static int config_write_network_area(struct vty
*vty
, struct ospf
*ospf
)
9914 struct route_node
*rn
;
9915 u_char buf
[INET_ADDRSTRLEN
];
9917 /* `network area' print. */
9918 for (rn
= route_top(ospf
->networks
); rn
; rn
= route_next(rn
))
9920 struct ospf_network
*n
= rn
->info
;
9922 memset(buf
, 0, INET_ADDRSTRLEN
);
9924 /* Create Area ID string by specified Area ID format. */
9925 if (n
->area_id_fmt
== OSPF_AREA_ID_FMT_DOTTEDQUAD
)
9926 strncpy((char *)buf
, inet_ntoa(n
->area_id
),
9929 sprintf((char *)buf
, "%lu",
9930 (unsigned long int)ntohl(
9931 n
->area_id
.s_addr
));
9933 /* Network print. */
9934 vty_out(vty
, " network %s/%d area %s\n",
9935 inet_ntoa(rn
->p
.u
.prefix4
), rn
->p
.prefixlen
,
9942 static int config_write_ospf_area(struct vty
*vty
, struct ospf
*ospf
)
9944 struct listnode
*node
;
9945 struct ospf_area
*area
;
9946 u_char buf
[INET_ADDRSTRLEN
];
9948 /* Area configuration print. */
9949 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
9950 struct route_node
*rn1
;
9952 area_id2str((char *)buf
, INET_ADDRSTRLEN
, &area
->area_id
,
9955 if (area
->auth_type
!= OSPF_AUTH_NULL
) {
9956 if (area
->auth_type
== OSPF_AUTH_SIMPLE
)
9957 vty_out(vty
, " area %s authentication\n", buf
);
9960 " area %s authentication message-digest\n",
9964 if (area
->shortcut_configured
!= OSPF_SHORTCUT_DEFAULT
)
9965 vty_out(vty
, " area %s shortcut %s\n", buf
,
9966 ospf_shortcut_mode_str
9967 [area
->shortcut_configured
]);
9969 if ((area
->external_routing
== OSPF_AREA_STUB
)
9970 || (area
->external_routing
== OSPF_AREA_NSSA
)) {
9971 if (area
->external_routing
== OSPF_AREA_STUB
) {
9972 vty_out(vty
, " area %s stub", buf
);
9973 if (area
->no_summary
)
9974 vty_out(vty
, " no-summary\n");
9976 } else if (area
->external_routing
== OSPF_AREA_NSSA
) {
9977 switch (area
->NSSATranslatorRole
) {
9978 case OSPF_NSSA_ROLE_NEVER
:
9980 " area %s nssa translate-never\n",
9983 case OSPF_NSSA_ROLE_ALWAYS
:
9985 " area %s nssa translate-always\n",
9988 case OSPF_NSSA_ROLE_CANDIDATE
:
9989 vty_out(vty
, " area %s nssa \n", buf
);
9992 if (area
->no_summary
)
9994 " area %s nssa no-summary\n",
9998 if (area
->default_cost
!= 1)
9999 vty_out(vty
, " area %s default-cost %d\n", buf
,
10000 area
->default_cost
);
10003 for (rn1
= route_top(area
->ranges
); rn1
; rn1
= route_next(rn1
))
10005 struct ospf_area_range
*range
= rn1
->info
;
10007 vty_out(vty
, " area %s range %s/%d", buf
,
10008 inet_ntoa(rn1
->p
.u
.prefix4
),
10011 if (range
->cost_config
10012 != OSPF_AREA_RANGE_COST_UNSPEC
)
10013 vty_out(vty
, " cost %d",
10014 range
->cost_config
);
10016 if (!CHECK_FLAG(range
->flags
,
10017 OSPF_AREA_RANGE_ADVERTISE
))
10018 vty_out(vty
, " not-advertise");
10020 if (CHECK_FLAG(range
->flags
,
10021 OSPF_AREA_RANGE_SUBSTITUTE
))
10022 vty_out(vty
, " substitute %s/%d",
10023 inet_ntoa(range
->subst_addr
),
10024 range
->subst_masklen
);
10026 vty_out(vty
, "\n");
10029 if (EXPORT_NAME(area
))
10030 vty_out(vty
, " area %s export-list %s\n", buf
,
10031 EXPORT_NAME(area
));
10033 if (IMPORT_NAME(area
))
10034 vty_out(vty
, " area %s import-list %s\n", buf
,
10035 IMPORT_NAME(area
));
10037 if (PREFIX_NAME_IN(area
))
10038 vty_out(vty
, " area %s filter-list prefix %s in\n", buf
,
10039 PREFIX_NAME_IN(area
));
10041 if (PREFIX_NAME_OUT(area
))
10042 vty_out(vty
, " area %s filter-list prefix %s out\n",
10043 buf
, PREFIX_NAME_OUT(area
));
10049 static int config_write_ospf_nbr_nbma(struct vty
*vty
, struct ospf
*ospf
)
10051 struct ospf_nbr_nbma
*nbr_nbma
;
10052 struct route_node
*rn
;
10054 /* Static Neighbor configuration print. */
10055 for (rn
= route_top(ospf
->nbr_nbma
); rn
; rn
= route_next(rn
))
10056 if ((nbr_nbma
= rn
->info
)) {
10057 vty_out(vty
, " neighbor %s", inet_ntoa(nbr_nbma
->addr
));
10059 if (nbr_nbma
->priority
10060 != OSPF_NEIGHBOR_PRIORITY_DEFAULT
)
10061 vty_out(vty
, " priority %d",
10062 nbr_nbma
->priority
);
10064 if (nbr_nbma
->v_poll
!= OSPF_POLL_INTERVAL_DEFAULT
)
10065 vty_out(vty
, " poll-interval %d",
10068 vty_out(vty
, "\n");
10074 static int config_write_virtual_link(struct vty
*vty
, struct ospf
*ospf
)
10076 struct listnode
*node
;
10077 struct ospf_vl_data
*vl_data
;
10078 char buf
[INET_ADDRSTRLEN
];
10080 /* Virtual-Link print */
10081 for (ALL_LIST_ELEMENTS_RO(ospf
->vlinks
, node
, vl_data
)) {
10082 struct listnode
*n2
;
10083 struct crypt_key
*ck
;
10084 struct ospf_interface
*oi
;
10086 if (vl_data
!= NULL
) {
10087 memset(buf
, 0, INET_ADDRSTRLEN
);
10089 area_id2str(buf
, sizeof(buf
), &vl_data
->vl_area_id
,
10090 vl_data
->vl_area_id_fmt
);
10091 oi
= vl_data
->vl_oi
;
10094 if (OSPF_IF_PARAM(oi
, v_hello
)
10095 != OSPF_HELLO_INTERVAL_DEFAULT
10096 || OSPF_IF_PARAM(oi
, v_wait
)
10097 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
10098 || OSPF_IF_PARAM(oi
, retransmit_interval
)
10099 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
10100 || OSPF_IF_PARAM(oi
, transmit_delay
)
10101 != OSPF_TRANSMIT_DELAY_DEFAULT
)
10103 " area %s virtual-link %s hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n",
10104 buf
, inet_ntoa(vl_data
->vl_peer
),
10105 OSPF_IF_PARAM(oi
, v_hello
),
10106 OSPF_IF_PARAM(oi
, retransmit_interval
),
10107 OSPF_IF_PARAM(oi
, transmit_delay
),
10108 OSPF_IF_PARAM(oi
, v_wait
));
10110 vty_out(vty
, " area %s virtual-link %s\n", buf
,
10111 inet_ntoa(vl_data
->vl_peer
));
10113 if (IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)->auth_simple
[0]
10116 " area %s virtual-link %s authentication-key %s\n",
10117 buf
, inet_ntoa(vl_data
->vl_peer
),
10118 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
10121 for (ALL_LIST_ELEMENTS_RO(
10122 IF_DEF_PARAMS(vl_data
->vl_oi
->ifp
)
10126 " area %s virtual-link %s"
10127 " message-digest-key %d md5 %s\n",
10128 buf
, inet_ntoa(vl_data
->vl_peer
),
10129 ck
->key_id
, ck
->auth_key
);
10137 static int config_write_ospf_redistribute(struct vty
*vty
, struct ospf
*ospf
)
10141 /* redistribute print. */
10142 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
10143 struct list
*red_list
;
10144 struct listnode
*node
;
10145 struct ospf_redist
*red
;
10147 red_list
= ospf
->redist
[type
];
10151 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
10152 vty_out(vty
, " redistribute %s",
10153 zebra_route_string(type
));
10155 vty_out(vty
, " %d", red
->instance
);
10157 if (red
->dmetric
.value
>= 0)
10158 vty_out(vty
, " metric %d", red
->dmetric
.value
);
10160 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
10161 vty_out(vty
, " metric-type 1");
10163 if (ROUTEMAP_NAME(red
))
10164 vty_out(vty
, " route-map %s",
10165 ROUTEMAP_NAME(red
));
10167 vty_out(vty
, "\n");
10174 static int config_write_ospf_default_metric(struct vty
*vty
, struct ospf
*ospf
)
10176 if (ospf
->default_metric
!= -1)
10177 vty_out(vty
, " default-metric %d\n", ospf
->default_metric
);
10181 static int config_write_ospf_distribute(struct vty
*vty
, struct ospf
*ospf
)
10184 struct ospf_redist
*red
;
10187 /* distribute-list print. */
10188 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
10189 if (DISTRIBUTE_NAME(ospf
, type
))
10190 vty_out(vty
, " distribute-list %s out %s\n",
10191 DISTRIBUTE_NAME(ospf
, type
),
10192 zebra_route_string(type
));
10194 /* default-information print. */
10195 if (ospf
->default_originate
!= DEFAULT_ORIGINATE_NONE
) {
10196 vty_out(vty
, " default-information originate");
10197 if (ospf
->default_originate
== DEFAULT_ORIGINATE_ALWAYS
)
10198 vty_out(vty
, " always");
10200 red
= ospf_redist_lookup(ospf
, DEFAULT_ROUTE
, 0);
10202 if (red
->dmetric
.value
>= 0)
10203 vty_out(vty
, " metric %d",
10204 red
->dmetric
.value
);
10205 if (red
->dmetric
.type
== EXTERNAL_METRIC_TYPE_1
)
10206 vty_out(vty
, " metric-type 1");
10208 if (ROUTEMAP_NAME(red
))
10209 vty_out(vty
, " route-map %s",
10210 ROUTEMAP_NAME(red
));
10213 vty_out(vty
, "\n");
10220 static int config_write_ospf_distance(struct vty
*vty
, struct ospf
*ospf
)
10222 struct route_node
*rn
;
10223 struct ospf_distance
*odistance
;
10225 if (ospf
->distance_all
)
10226 vty_out(vty
, " distance %d\n", ospf
->distance_all
);
10228 if (ospf
->distance_intra
|| ospf
->distance_inter
10229 || ospf
->distance_external
) {
10230 vty_out(vty
, " distance ospf");
10232 if (ospf
->distance_intra
)
10233 vty_out(vty
, " intra-area %d", ospf
->distance_intra
);
10234 if (ospf
->distance_inter
)
10235 vty_out(vty
, " inter-area %d", ospf
->distance_inter
);
10236 if (ospf
->distance_external
)
10237 vty_out(vty
, " external %d", ospf
->distance_external
);
10239 vty_out(vty
, "\n");
10242 for (rn
= route_top(ospf
->distance_table
); rn
; rn
= route_next(rn
))
10243 if ((odistance
= rn
->info
) != NULL
) {
10244 vty_out(vty
, " distance %d %s/%d %s\n",
10245 odistance
->distance
, inet_ntoa(rn
->p
.u
.prefix4
),
10247 odistance
->access_list
? odistance
->access_list
10253 static int ospf_config_write_one(struct vty
*vty
, struct ospf
*ospf
)
10255 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
10256 struct interface
*ifp
;
10257 struct ospf_interface
*oi
;
10258 struct listnode
*node
= NULL
;
10261 /* `router ospf' print. */
10262 if (ospf
->instance
&& ospf
->name
) {
10263 vty_out(vty
, "router ospf %d vrf %s\n",
10264 ospf
->instance
, ospf
->name
);
10265 } else if (ospf
->instance
) {
10266 vty_out(vty
, "router ospf %d\n",
10268 } else if (ospf
->name
) {
10269 vty_out(vty
, "router ospf vrf %s\n",
10272 vty_out(vty
, "router ospf\n");
10274 if (!ospf
->networks
) {
10279 /* Router ID print. */
10280 if (ospf
->router_id_static
.s_addr
!= 0)
10281 vty_out(vty
, " ospf router-id %s\n",
10282 inet_ntoa(ospf
->router_id_static
));
10284 /* ABR type print. */
10285 if (ospf
->abr_type
!= OSPF_ABR_DEFAULT
)
10286 vty_out(vty
, " ospf abr-type %s\n",
10287 ospf_abr_type_str
[ospf
->abr_type
]);
10289 /* log-adjacency-changes flag print. */
10290 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_CHANGES
)) {
10291 if (CHECK_FLAG(ospf
->config
, OSPF_LOG_ADJACENCY_DETAIL
))
10292 vty_out(vty
, " log-adjacency-changes detail\n");
10293 else if (!DFLT_OSPF_LOG_ADJACENCY_CHANGES
)
10294 vty_out(vty
, " log-adjacency-changes\n");
10295 } else if (DFLT_OSPF_LOG_ADJACENCY_CHANGES
) {
10296 vty_out(vty
, " no log-adjacency-changes\n");
10299 /* RFC1583 compatibility flag print -- Compatible with CISCO
10301 if (CHECK_FLAG(ospf
->config
, OSPF_RFC1583_COMPATIBLE
))
10302 vty_out(vty
, " compatible rfc1583\n");
10304 /* auto-cost reference-bandwidth configuration. */
10305 if (ospf
->ref_bandwidth
!= OSPF_DEFAULT_REF_BANDWIDTH
) {
10307 "! Important: ensure reference bandwidth "
10308 "is consistent across all routers\n");
10309 vty_out(vty
, " auto-cost reference-bandwidth %d\n",
10310 ospf
->ref_bandwidth
);
10313 /* SPF timers print. */
10314 if (ospf
->spf_delay
!= OSPF_SPF_DELAY_DEFAULT
10315 || ospf
->spf_holdtime
!= OSPF_SPF_HOLDTIME_DEFAULT
10316 || ospf
->spf_max_holdtime
!= OSPF_SPF_MAX_HOLDTIME_DEFAULT
)
10317 vty_out(vty
, " timers throttle spf %d %d %d\n",
10318 ospf
->spf_delay
, ospf
->spf_holdtime
,
10319 ospf
->spf_max_holdtime
);
10321 /* LSA timers print. */
10322 if (ospf
->min_ls_interval
!= OSPF_MIN_LS_INTERVAL
)
10323 vty_out(vty
, " timers throttle lsa all %d\n",
10324 ospf
->min_ls_interval
);
10325 if (ospf
->min_ls_arrival
!= OSPF_MIN_LS_ARRIVAL
)
10326 vty_out(vty
, " timers lsa min-arrival %d\n",
10327 ospf
->min_ls_arrival
);
10329 /* Write multiplier print. */
10330 if (ospf
->write_oi_count
!= OSPF_WRITE_INTERFACE_COUNT_DEFAULT
)
10331 vty_out(vty
, " ospf write-multiplier %d\n",
10332 ospf
->write_oi_count
);
10334 /* Max-metric router-lsa print */
10335 config_write_stub_router(vty
, ospf
);
10337 /* SPF refresh parameters print. */
10338 if (ospf
->lsa_refresh_interval
10339 != OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
10340 vty_out(vty
, " refresh timer %d\n",
10341 ospf
->lsa_refresh_interval
);
10343 /* Redistribute information print. */
10344 config_write_ospf_redistribute(vty
, ospf
);
10346 /* passive-interface print. */
10347 if (ospf
->passive_interface_default
== OSPF_IF_PASSIVE
)
10348 vty_out(vty
, " passive-interface default\n");
10350 FOR_ALL_INTERFACES (vrf
, ifp
)
10351 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp
),
10353 && IF_DEF_PARAMS(ifp
)->passive_interface
10354 != ospf
->passive_interface_default
) {
10355 vty_out(vty
, " %spassive-interface %s\n",
10356 IF_DEF_PARAMS(ifp
)->passive_interface
10361 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
10362 if (!OSPF_IF_PARAM_CONFIGURED(oi
->params
,
10363 passive_interface
))
10365 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(oi
->ifp
),
10366 passive_interface
)) {
10367 if (oi
->params
->passive_interface
10368 == IF_DEF_PARAMS(oi
->ifp
)
10369 ->passive_interface
)
10371 } else if (oi
->params
->passive_interface
10372 == ospf
->passive_interface_default
)
10375 vty_out(vty
, " %spassive-interface %s %s\n",
10376 oi
->params
->passive_interface
? "" : "no ",
10378 inet_ntoa(oi
->address
->u
.prefix4
));
10381 /* Network area print. */
10382 config_write_network_area(vty
, ospf
);
10384 /* Area config print. */
10385 config_write_ospf_area(vty
, ospf
);
10387 /* static neighbor print. */
10388 config_write_ospf_nbr_nbma(vty
, ospf
);
10390 /* Virtual-Link print. */
10391 config_write_virtual_link(vty
, ospf
);
10393 /* Default metric configuration. */
10394 config_write_ospf_default_metric(vty
, ospf
);
10396 /* Distribute-list and default-information print. */
10397 config_write_ospf_distribute(vty
, ospf
);
10399 /* Distance configuration. */
10400 config_write_ospf_distance(vty
, ospf
);
10402 ospf_opaque_config_write_router(vty
, ospf
);
10408 /* OSPF configuration write function. */
10409 static int ospf_config_write(struct vty
*vty
)
10412 struct listnode
*ospf_node
= NULL
;
10415 if (listcount(om
->ospf
) == 0)
10418 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, ospf_node
, ospf
)) {
10419 /* VRF Default check if it is running.
10420 * Upon daemon start, there could be default instance
10421 * in absence of 'router ospf'/oi_running is disabled. */
10422 if (ospf
->vrf_id
== VRF_DEFAULT
&& ospf
->oi_running
)
10423 write
+= ospf_config_write_one(vty
, ospf
);
10424 /* For Non-Default VRF simply display the configuration,
10425 * even if it is not oi_running. */
10426 else if (ospf
->vrf_id
!= VRF_DEFAULT
)
10427 write
+= ospf_config_write_one(vty
, ospf
);
10432 void ospf_vty_show_init(void)
10434 /* "show ip ospf" commands. */
10435 install_element(VIEW_NODE
, &show_ip_ospf_cmd
);
10437 install_element(VIEW_NODE
, &show_ip_ospf_instance_cmd
);
10439 /* "show ip ospf database" commands. */
10440 install_element(VIEW_NODE
, &show_ip_ospf_database_max_cmd
);
10442 install_element(VIEW_NODE
,
10443 &show_ip_ospf_instance_database_type_adv_router_cmd
);
10444 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_cmd
);
10445 install_element(VIEW_NODE
, &show_ip_ospf_instance_database_max_cmd
);
10447 /* "show ip ospf interface" commands. */
10448 install_element(VIEW_NODE
, &show_ip_ospf_interface_cmd
);
10450 install_element(VIEW_NODE
, &show_ip_ospf_instance_interface_cmd
);
10451 /* "show ip ospf interface traffic */
10452 install_element(VIEW_NODE
, &show_ip_ospf_interface_traffic_cmd
);
10454 /* "show ip ospf neighbor" commands. */
10455 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_detail_cmd
);
10456 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_int_cmd
);
10457 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_id_cmd
);
10458 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_all_cmd
);
10459 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_detail_cmd
);
10460 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_cmd
);
10461 install_element(VIEW_NODE
, &show_ip_ospf_neighbor_all_cmd
);
10463 install_element(VIEW_NODE
,
10464 &show_ip_ospf_instance_neighbor_int_detail_cmd
);
10465 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_int_cmd
);
10466 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_id_cmd
);
10467 install_element(VIEW_NODE
,
10468 &show_ip_ospf_instance_neighbor_detail_all_cmd
);
10469 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_detail_cmd
);
10470 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_cmd
);
10471 install_element(VIEW_NODE
, &show_ip_ospf_instance_neighbor_all_cmd
);
10473 /* "show ip ospf route" commands. */
10474 install_element(VIEW_NODE
, &show_ip_ospf_route_cmd
);
10475 install_element(VIEW_NODE
, &show_ip_ospf_border_routers_cmd
);
10477 install_element(VIEW_NODE
, &show_ip_ospf_instance_route_cmd
);
10478 install_element(VIEW_NODE
, &show_ip_ospf_instance_border_routers_cmd
);
10480 /* "show ip ospf vrfs" commands. */
10481 install_element(VIEW_NODE
, &show_ip_ospf_vrfs_cmd
);
10485 /* ospfd's interface node. */
10486 static struct cmd_node interface_node
= {INTERFACE_NODE
, "%s(config-if)# ", 1};
10488 /* Initialization of OSPF interface. */
10489 static void ospf_vty_if_init(void)
10491 /* Install interface node. */
10492 install_node(&interface_node
, config_write_interface
);
10495 /* "ip ospf authentication" commands. */
10496 install_element(INTERFACE_NODE
, &ip_ospf_authentication_args_addr_cmd
);
10497 install_element(INTERFACE_NODE
, &ip_ospf_authentication_addr_cmd
);
10498 install_element(INTERFACE_NODE
,
10499 &no_ip_ospf_authentication_args_addr_cmd
);
10500 install_element(INTERFACE_NODE
, &no_ip_ospf_authentication_addr_cmd
);
10501 install_element(INTERFACE_NODE
, &ip_ospf_authentication_key_addr_cmd
);
10502 install_element(INTERFACE_NODE
,
10503 &no_ip_ospf_authentication_key_authkey_addr_cmd
);
10504 install_element(INTERFACE_NODE
,
10505 &no_ospf_authentication_key_authkey_addr_cmd
);
10507 /* "ip ospf message-digest-key" commands. */
10508 install_element(INTERFACE_NODE
, &ip_ospf_message_digest_key_cmd
);
10509 install_element(INTERFACE_NODE
, &no_ip_ospf_message_digest_key_cmd
);
10511 /* "ip ospf cost" commands. */
10512 install_element(INTERFACE_NODE
, &ip_ospf_cost_cmd
);
10513 install_element(INTERFACE_NODE
, &no_ip_ospf_cost_cmd
);
10515 /* "ip ospf mtu-ignore" commands. */
10516 install_element(INTERFACE_NODE
, &ip_ospf_mtu_ignore_addr_cmd
);
10517 install_element(INTERFACE_NODE
, &no_ip_ospf_mtu_ignore_addr_cmd
);
10519 /* "ip ospf dead-interval" commands. */
10520 install_element(INTERFACE_NODE
, &ip_ospf_dead_interval_cmd
);
10521 install_element(INTERFACE_NODE
,
10522 &ip_ospf_dead_interval_minimal_addr_cmd
);
10523 install_element(INTERFACE_NODE
, &no_ip_ospf_dead_interval_cmd
);
10525 /* "ip ospf hello-interval" commands. */
10526 install_element(INTERFACE_NODE
, &ip_ospf_hello_interval_cmd
);
10527 install_element(INTERFACE_NODE
, &no_ip_ospf_hello_interval_cmd
);
10529 /* "ip ospf network" commands. */
10530 install_element(INTERFACE_NODE
, &ip_ospf_network_cmd
);
10531 install_element(INTERFACE_NODE
, &no_ip_ospf_network_cmd
);
10533 /* "ip ospf priority" commands. */
10534 install_element(INTERFACE_NODE
, &ip_ospf_priority_cmd
);
10535 install_element(INTERFACE_NODE
, &no_ip_ospf_priority_cmd
);
10537 /* "ip ospf retransmit-interval" commands. */
10538 install_element(INTERFACE_NODE
, &ip_ospf_retransmit_interval_addr_cmd
);
10539 install_element(INTERFACE_NODE
,
10540 &no_ip_ospf_retransmit_interval_addr_cmd
);
10542 /* "ip ospf transmit-delay" commands. */
10543 install_element(INTERFACE_NODE
, &ip_ospf_transmit_delay_addr_cmd
);
10544 install_element(INTERFACE_NODE
, &no_ip_ospf_transmit_delay_addr_cmd
);
10546 /* "ip ospf area" commands. */
10547 install_element(INTERFACE_NODE
, &ip_ospf_area_cmd
);
10548 install_element(INTERFACE_NODE
, &no_ip_ospf_area_cmd
);
10550 /* These commands are compatibitliy for previous version. */
10551 install_element(INTERFACE_NODE
, &ospf_authentication_key_cmd
);
10552 install_element(INTERFACE_NODE
, &ospf_message_digest_key_cmd
);
10553 install_element(INTERFACE_NODE
, &no_ospf_message_digest_key_cmd
);
10554 install_element(INTERFACE_NODE
, &ospf_dead_interval_cmd
);
10555 install_element(INTERFACE_NODE
, &no_ospf_dead_interval_cmd
);
10556 install_element(INTERFACE_NODE
, &ospf_hello_interval_cmd
);
10557 install_element(INTERFACE_NODE
, &no_ospf_hello_interval_cmd
);
10558 install_element(INTERFACE_NODE
, &ospf_cost_cmd
);
10559 install_element(INTERFACE_NODE
, &no_ospf_cost_cmd
);
10560 install_element(INTERFACE_NODE
, &ospf_network_cmd
);
10561 install_element(INTERFACE_NODE
, &no_ospf_network_cmd
);
10562 install_element(INTERFACE_NODE
, &ospf_priority_cmd
);
10563 install_element(INTERFACE_NODE
, &no_ospf_priority_cmd
);
10564 install_element(INTERFACE_NODE
, &ospf_retransmit_interval_cmd
);
10565 install_element(INTERFACE_NODE
, &no_ospf_retransmit_interval_cmd
);
10566 install_element(INTERFACE_NODE
, &ospf_transmit_delay_cmd
);
10567 install_element(INTERFACE_NODE
, &no_ospf_transmit_delay_cmd
);
10570 static void ospf_vty_zebra_init(void)
10572 install_element(OSPF_NODE
, &ospf_redistribute_source_cmd
);
10573 install_element(OSPF_NODE
, &no_ospf_redistribute_source_cmd
);
10574 install_element(OSPF_NODE
, &ospf_redistribute_instance_source_cmd
);
10575 install_element(OSPF_NODE
, &no_ospf_redistribute_instance_source_cmd
);
10577 install_element(OSPF_NODE
, &ospf_distribute_list_out_cmd
);
10578 install_element(OSPF_NODE
, &no_ospf_distribute_list_out_cmd
);
10580 install_element(OSPF_NODE
, &ospf_default_information_originate_cmd
);
10581 install_element(OSPF_NODE
, &no_ospf_default_information_originate_cmd
);
10583 install_element(OSPF_NODE
, &ospf_default_metric_cmd
);
10584 install_element(OSPF_NODE
, &no_ospf_default_metric_cmd
);
10586 install_element(OSPF_NODE
, &ospf_distance_cmd
);
10587 install_element(OSPF_NODE
, &no_ospf_distance_cmd
);
10588 install_element(OSPF_NODE
, &no_ospf_distance_ospf_cmd
);
10589 install_element(OSPF_NODE
, &ospf_distance_ospf_cmd
);
10591 install_element (OSPF_NODE
, &ospf_distance_source_cmd
);
10592 install_element (OSPF_NODE
, &no_ospf_distance_source_cmd
);
10593 install_element (OSPF_NODE
, &ospf_distance_source_access_list_cmd
);
10594 install_element (OSPF_NODE
, &no_ospf_distance_source_access_list_cmd
);
10598 static struct cmd_node ospf_node
= {OSPF_NODE
, "%s(config-router)# ", 1};
10600 static void ospf_interface_clear(struct interface
*ifp
)
10602 if (!if_is_operative(ifp
))
10605 if (IS_DEBUG_OSPF(ism
, ISM_EVENTS
))
10606 zlog_debug("ISM[%s]: clear by reset", ifp
->name
);
10608 ospf_if_reset(ifp
);
10611 DEFUN (clear_ip_ospf_interface
,
10612 clear_ip_ospf_interface_cmd
,
10613 "clear ip ospf interface [IFNAME]",
10616 "OSPF information\n"
10617 "Interface information\n"
10618 "Interface name\n")
10620 int idx_ifname
= 4;
10621 struct interface
*ifp
;
10622 struct listnode
*node
;
10623 struct ospf
*ospf
= NULL
;
10625 if (argc
== 4) /* Clear all the ospfv2 interfaces. */
10627 for (ALL_LIST_ELEMENTS_RO(om
->ospf
, node
, ospf
)) {
10628 struct vrf
*vrf
= vrf_lookup_by_id(ospf
->vrf_id
);
10629 FOR_ALL_INTERFACES (vrf
, ifp
)
10630 ospf_interface_clear(ifp
);
10633 /* Interface name is specified. */
10634 ifp
= if_lookup_by_name_all_vrf(argv
[idx_ifname
]->arg
);
10636 vty_out(vty
, "No such interface name\n");
10638 ospf_interface_clear(ifp
);
10641 return CMD_SUCCESS
;
10644 void ospf_vty_clear_init(void)
10646 install_element(ENABLE_NODE
, &clear_ip_ospf_interface_cmd
);
10650 /* Install OSPF related vty commands. */
10651 void ospf_vty_init(void)
10653 /* Install ospf top node. */
10654 install_node(&ospf_node
, ospf_config_write
);
10656 /* "router ospf" commands. */
10657 install_element(CONFIG_NODE
, &router_ospf_cmd
);
10658 install_element(CONFIG_NODE
, &no_router_ospf_cmd
);
10661 install_default(OSPF_NODE
);
10663 /* "ospf router-id" commands. */
10664 install_element(OSPF_NODE
, &ospf_router_id_cmd
);
10665 install_element(OSPF_NODE
, &ospf_router_id_old_cmd
);
10666 install_element(OSPF_NODE
, &no_ospf_router_id_cmd
);
10668 /* "passive-interface" commands. */
10669 install_element(OSPF_NODE
, &ospf_passive_interface_addr_cmd
);
10670 install_element(OSPF_NODE
, &no_ospf_passive_interface_addr_cmd
);
10672 /* "ospf abr-type" commands. */
10673 install_element(OSPF_NODE
, &ospf_abr_type_cmd
);
10674 install_element(OSPF_NODE
, &no_ospf_abr_type_cmd
);
10676 /* "ospf log-adjacency-changes" commands. */
10677 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_cmd
);
10678 install_element(OSPF_NODE
, &ospf_log_adjacency_changes_detail_cmd
);
10679 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_cmd
);
10680 install_element(OSPF_NODE
, &no_ospf_log_adjacency_changes_detail_cmd
);
10682 /* "ospf rfc1583-compatible" commands. */
10683 install_element(OSPF_NODE
, &ospf_compatible_rfc1583_cmd
);
10684 install_element(OSPF_NODE
, &no_ospf_compatible_rfc1583_cmd
);
10685 install_element(OSPF_NODE
, &ospf_rfc1583_flag_cmd
);
10686 install_element(OSPF_NODE
, &no_ospf_rfc1583_flag_cmd
);
10688 /* "network area" commands. */
10689 install_element(OSPF_NODE
, &ospf_network_area_cmd
);
10690 install_element(OSPF_NODE
, &no_ospf_network_area_cmd
);
10692 /* "area authentication" commands. */
10693 install_element(OSPF_NODE
,
10694 &ospf_area_authentication_message_digest_cmd
);
10695 install_element(OSPF_NODE
, &ospf_area_authentication_cmd
);
10696 install_element(OSPF_NODE
, &no_ospf_area_authentication_cmd
);
10698 /* "area range" commands. */
10699 install_element(OSPF_NODE
, &ospf_area_range_cmd
);
10700 install_element(OSPF_NODE
, &ospf_area_range_cost_cmd
);
10701 install_element(OSPF_NODE
, &ospf_area_range_not_advertise_cmd
);
10702 install_element(OSPF_NODE
, &no_ospf_area_range_cmd
);
10703 install_element(OSPF_NODE
, &ospf_area_range_substitute_cmd
);
10704 install_element(OSPF_NODE
, &no_ospf_area_range_substitute_cmd
);
10706 /* "area virtual-link" commands. */
10707 install_element(OSPF_NODE
, &ospf_area_vlink_cmd
);
10708 install_element(OSPF_NODE
, &ospf_area_vlink_intervals_cmd
);
10709 install_element(OSPF_NODE
, &no_ospf_area_vlink_cmd
);
10710 install_element(OSPF_NODE
, &no_ospf_area_vlink_intervals_cmd
);
10713 /* "area stub" commands. */
10714 install_element(OSPF_NODE
, &ospf_area_stub_no_summary_cmd
);
10715 install_element(OSPF_NODE
, &ospf_area_stub_cmd
);
10716 install_element(OSPF_NODE
, &no_ospf_area_stub_no_summary_cmd
);
10717 install_element(OSPF_NODE
, &no_ospf_area_stub_cmd
);
10719 /* "area nssa" commands. */
10720 install_element(OSPF_NODE
, &ospf_area_nssa_cmd
);
10721 install_element(OSPF_NODE
, &ospf_area_nssa_translate_cmd
);
10722 install_element(OSPF_NODE
, &ospf_area_nssa_no_summary_cmd
);
10723 install_element(OSPF_NODE
, &no_ospf_area_nssa_no_summary_cmd
);
10724 install_element(OSPF_NODE
, &no_ospf_area_nssa_cmd
);
10726 install_element(OSPF_NODE
, &ospf_area_default_cost_cmd
);
10727 install_element(OSPF_NODE
, &no_ospf_area_default_cost_cmd
);
10729 install_element(OSPF_NODE
, &ospf_area_shortcut_cmd
);
10730 install_element(OSPF_NODE
, &no_ospf_area_shortcut_cmd
);
10732 install_element(OSPF_NODE
, &ospf_area_export_list_cmd
);
10733 install_element(OSPF_NODE
, &no_ospf_area_export_list_cmd
);
10735 install_element(OSPF_NODE
, &ospf_area_filter_list_cmd
);
10736 install_element(OSPF_NODE
, &no_ospf_area_filter_list_cmd
);
10738 install_element(OSPF_NODE
, &ospf_area_import_list_cmd
);
10739 install_element(OSPF_NODE
, &no_ospf_area_import_list_cmd
);
10741 /* SPF timer commands */
10742 install_element(OSPF_NODE
, &ospf_timers_throttle_spf_cmd
);
10743 install_element(OSPF_NODE
, &no_ospf_timers_throttle_spf_cmd
);
10745 /* LSA timers commands */
10746 install_element(OSPF_NODE
, &ospf_timers_min_ls_interval_cmd
);
10747 install_element(OSPF_NODE
, &no_ospf_timers_min_ls_interval_cmd
);
10748 install_element(OSPF_NODE
, &ospf_timers_lsa_min_arrival_cmd
);
10749 install_element(OSPF_NODE
, &no_ospf_timers_lsa_min_arrival_cmd
);
10750 install_element(OSPF_NODE
, &ospf_timers_lsa_arrival_cmd
);
10751 install_element(OSPF_NODE
, &no_ospf_timers_lsa_arrival_cmd
);
10753 /* refresh timer commands */
10754 install_element(OSPF_NODE
, &ospf_refresh_timer_cmd
);
10755 install_element(OSPF_NODE
, &no_ospf_refresh_timer_val_cmd
);
10757 /* max-metric commands */
10758 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_admin_cmd
);
10759 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_admin_cmd
);
10760 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_startup_cmd
);
10761 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_startup_cmd
);
10762 install_element(OSPF_NODE
, &ospf_max_metric_router_lsa_shutdown_cmd
);
10763 install_element(OSPF_NODE
, &no_ospf_max_metric_router_lsa_shutdown_cmd
);
10765 /* reference bandwidth commands */
10766 install_element(OSPF_NODE
, &ospf_auto_cost_reference_bandwidth_cmd
);
10767 install_element(OSPF_NODE
, &no_ospf_auto_cost_reference_bandwidth_cmd
);
10769 /* "neighbor" commands. */
10770 install_element(OSPF_NODE
, &ospf_neighbor_cmd
);
10771 install_element(OSPF_NODE
, &ospf_neighbor_poll_interval_cmd
);
10772 install_element(OSPF_NODE
, &no_ospf_neighbor_cmd
);
10773 install_element(OSPF_NODE
, &no_ospf_neighbor_poll_cmd
);
10775 /* write multiplier commands */
10776 install_element(OSPF_NODE
, &ospf_write_multiplier_cmd
);
10777 install_element(OSPF_NODE
, &write_multiplier_cmd
);
10778 install_element(OSPF_NODE
, &no_ospf_write_multiplier_cmd
);
10779 install_element(OSPF_NODE
, &no_write_multiplier_cmd
);
10781 /* Init interface related vty commands. */
10782 ospf_vty_if_init();
10784 /* Init zebra related vty commands. */
10785 ospf_vty_zebra_init();